react-native-audio-api 0.8.3-nightly-ea268f4-20251006 → 0.8.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +39 -40
- package/RNAudioAPI.podspec +12 -17
- package/android/build.gradle +4 -44
- package/android/src/main/cpp/audioapi/CMakeLists.txt +0 -65
- package/android/src/main/cpp/audioapi/android/AudioAPIModule.cpp +1 -29
- package/android/src/main/cpp/audioapi/android/AudioAPIModule.h +0 -14
- package/android/src/main/cpp/audioapi/android/core/AndroidAudioRecorder.cpp +1 -7
- package/android/src/main/cpp/audioapi/android/core/AndroidAudioRecorder.h +1 -6
- package/android/src/main/cpp/audioapi/android/core/AudioPlayer.cpp +1 -1
- package/android/src/main/java/com/swmansion/audioapi/AudioAPIModule.kt +1 -11
- package/android/src/main/java/com/swmansion/audioapi/system/MediaSessionManager.kt +2 -15
- package/common/cpp/audioapi/AudioAPIModuleInstaller.h +18 -53
- package/common/cpp/audioapi/HostObjects/AnalyserNodeHostObject.h +149 -0
- package/common/cpp/audioapi/HostObjects/AudioBufferBaseSourceNodeHostObject.h +76 -0
- package/common/cpp/audioapi/HostObjects/AudioBufferHostObject.h +120 -0
- package/common/cpp/audioapi/HostObjects/AudioBufferQueueSourceNodeHostObject.h +67 -0
- package/common/cpp/audioapi/HostObjects/AudioBufferSourceNodeHostObject.h +142 -0
- package/common/cpp/audioapi/HostObjects/AudioContextHostObject.h +46 -6
- package/common/cpp/audioapi/HostObjects/AudioNodeHostObject.cpp +6 -70
- package/common/cpp/audioapi/HostObjects/AudioNodeHostObject.h +66 -10
- package/common/cpp/audioapi/HostObjects/AudioParamHostObject.h +91 -17
- package/common/cpp/audioapi/HostObjects/AudioRecorderHostObject.h +86 -0
- package/common/cpp/audioapi/HostObjects/AudioScheduledSourceNodeHostObject.h +56 -0
- package/common/cpp/audioapi/HostObjects/BaseAudioContextHostObject.cpp +6 -362
- package/common/cpp/audioapi/HostObjects/BaseAudioContextHostObject.h +241 -29
- package/common/cpp/audioapi/HostObjects/BiquadFilterNodeHostObject.h +89 -0
- package/common/cpp/audioapi/HostObjects/GainNodeHostObject.h +27 -0
- package/common/cpp/audioapi/HostObjects/OfflineAudioContextHostObject.h +50 -6
- package/common/cpp/audioapi/HostObjects/OscillatorNodeHostObject.h +65 -0
- package/common/cpp/audioapi/HostObjects/{sources/RecorderAdapterNodeHostObject.h → RecorderAdapterNodeHostObject.h} +2 -1
- package/common/cpp/audioapi/HostObjects/StereoPannerNodeHostObject.h +29 -0
- package/common/cpp/audioapi/HostObjects/StreamerNodeHostObject.h +30 -0
- package/common/cpp/audioapi/core/AudioContext.cpp +2 -3
- package/common/cpp/audioapi/core/AudioContext.h +1 -2
- package/common/cpp/audioapi/core/AudioNode.h +1 -1
- package/common/cpp/audioapi/core/AudioParam.cpp +2 -2
- package/common/cpp/audioapi/core/AudioParam.h +1 -1
- package/common/cpp/audioapi/core/{utils/AudioParamEventQueue.cpp → AudioParamEventQueue.cpp} +7 -13
- package/common/cpp/audioapi/core/BaseAudioContext.cpp +3 -47
- package/common/cpp/audioapi/core/BaseAudioContext.h +4 -13
- package/common/cpp/audioapi/core/{utils/Constants.h → Constants.h} +0 -5
- package/common/cpp/audioapi/core/OfflineAudioContext.cpp +3 -4
- package/common/cpp/audioapi/core/OfflineAudioContext.h +1 -2
- package/common/cpp/audioapi/core/effects/PeriodicWave.cpp +1 -1
- package/common/cpp/audioapi/core/effects/StereoPannerNode.cpp +1 -1
- package/common/cpp/audioapi/core/inputs/AudioRecorder.cpp +1 -1
- package/common/cpp/audioapi/core/inputs/AudioRecorder.h +2 -2
- package/common/cpp/audioapi/core/sources/AudioBufferBaseSourceNode.cpp +10 -47
- package/common/cpp/audioapi/core/sources/AudioBufferBaseSourceNode.h +3 -18
- package/common/cpp/audioapi/core/sources/AudioBufferQueueSourceNode.cpp +12 -94
- package/common/cpp/audioapi/core/sources/AudioBufferQueueSourceNode.h +2 -8
- package/common/cpp/audioapi/core/sources/AudioBufferSourceNode.cpp +42 -33
- package/common/cpp/audioapi/core/sources/AudioBufferSourceNode.h +8 -6
- package/common/cpp/audioapi/core/sources/AudioScheduledSourceNode.cpp +6 -1
- package/common/cpp/audioapi/core/sources/AudioScheduledSourceNode.h +1 -1
- package/common/cpp/audioapi/core/sources/StreamerNode.h +8 -0
- package/common/cpp/audioapi/dsp/Windows.cpp +1 -1
- package/common/cpp/audioapi/events/AudioEventHandlerRegistry.cpp +1 -1
- package/common/cpp/audioapi/events/AudioEventHandlerRegistry.h +1 -2
- package/common/cpp/audioapi/events/AudioEventHandlerRegistryHostObject.h +48 -0
- package/common/cpp/audioapi/jsi/AudioArrayBuffer.h +1 -14
- package/common/cpp/audioapi/jsi/JsiHostObject.h +12 -6
- package/common/cpp/audioapi/jsi/JsiPromise.cpp +0 -49
- package/common/cpp/audioapi/jsi/JsiPromise.h +1 -29
- package/common/cpp/audioapi/utils/AudioBus.cpp +1 -1
- package/common/cpp/test/CMakeLists.txt +3 -11
- package/common/cpp/test/GainTest.cpp +1 -2
- package/common/cpp/test/OscillatorTest.cpp +1 -2
- package/ios/audioapi/ios/AudioAPIModule.mm +5 -32
- package/ios/audioapi/ios/core/IOSAudioPlayer.mm +1 -1
- package/ios/audioapi/ios/core/IOSAudioRecorder.h +1 -2
- package/ios/audioapi/ios/core/IOSAudioRecorder.mm +1 -1
- package/ios/audioapi/ios/events/IOSAudioEventHandlerRegistry.h +7 -0
- package/ios/audioapi/ios/events/IOSAudioEventHandlerRegistry.mm +12 -0
- package/lib/commonjs/api.js +2 -36
- package/lib/commonjs/api.js.map +1 -1
- package/lib/commonjs/api.web.js +0 -8
- package/lib/commonjs/api.web.js.map +1 -1
- package/lib/commonjs/core/AudioBufferBaseSourceNode.js +7 -7
- package/lib/commonjs/core/AudioBufferBaseSourceNode.js.map +1 -1
- package/lib/commonjs/core/AudioBufferQueueSourceNode.js +6 -1
- package/lib/commonjs/core/AudioBufferQueueSourceNode.js.map +1 -1
- package/lib/commonjs/core/AudioBufferSourceNode.js +0 -15
- package/lib/commonjs/core/AudioBufferSourceNode.js.map +1 -1
- package/lib/commonjs/core/AudioContext.js +1 -10
- package/lib/commonjs/core/AudioContext.js.map +1 -1
- package/lib/commonjs/core/AudioScheduledSourceNode.js +4 -4
- package/lib/commonjs/core/AudioScheduledSourceNode.js.map +1 -1
- package/lib/commonjs/core/BaseAudioContext.js +11 -66
- package/lib/commonjs/core/BaseAudioContext.js.map +1 -1
- package/lib/commonjs/core/OfflineAudioContext.js +2 -11
- package/lib/commonjs/core/OfflineAudioContext.js.map +1 -1
- package/lib/commonjs/core/OscillatorNode.js +0 -6
- package/lib/commonjs/core/OscillatorNode.js.map +1 -1
- package/lib/commonjs/hooks/{useSystemVolume.js → useSytemVolume.js} +1 -1
- package/lib/commonjs/hooks/useSytemVolume.js.map +1 -0
- package/lib/commonjs/utils/index.js +0 -9
- package/lib/commonjs/utils/index.js.map +1 -1
- package/lib/commonjs/web-core/AudioContext.js +0 -4
- package/lib/commonjs/web-core/AudioContext.js.map +1 -1
- package/lib/commonjs/web-core/AudioScheduledSourceNode.js +1 -1
- package/lib/commonjs/web-core/AudioScheduledSourceNode.js.map +1 -1
- package/lib/commonjs/web-core/OfflineAudioContext.js +0 -4
- package/lib/commonjs/web-core/OfflineAudioContext.js.map +1 -1
- package/lib/module/api.js +2 -6
- package/lib/module/api.js.map +1 -1
- package/lib/module/api.web.js +0 -1
- package/lib/module/api.web.js.map +1 -1
- package/lib/module/core/AudioBufferBaseSourceNode.js +7 -7
- package/lib/module/core/AudioBufferBaseSourceNode.js.map +1 -1
- package/lib/module/core/AudioBufferQueueSourceNode.js +6 -1
- package/lib/module/core/AudioBufferQueueSourceNode.js.map +1 -1
- package/lib/module/core/AudioBufferSourceNode.js +0 -15
- package/lib/module/core/AudioBufferSourceNode.js.map +1 -1
- package/lib/module/core/AudioContext.js +1 -10
- package/lib/module/core/AudioContext.js.map +1 -1
- package/lib/module/core/AudioScheduledSourceNode.js +4 -4
- package/lib/module/core/AudioScheduledSourceNode.js.map +1 -1
- package/lib/module/core/BaseAudioContext.js +11 -66
- package/lib/module/core/BaseAudioContext.js.map +1 -1
- package/lib/module/core/OfflineAudioContext.js +2 -11
- package/lib/module/core/OfflineAudioContext.js.map +1 -1
- package/lib/module/core/OscillatorNode.js +0 -6
- package/lib/module/core/OscillatorNode.js.map +1 -1
- package/lib/module/hooks/{useSystemVolume.js → useSytemVolume.js} +1 -1
- package/lib/module/hooks/useSytemVolume.js.map +1 -0
- package/lib/module/utils/index.js +0 -8
- package/lib/module/utils/index.js.map +1 -1
- package/lib/module/web-core/AudioContext.js +0 -4
- package/lib/module/web-core/AudioContext.js.map +1 -1
- package/lib/module/web-core/AudioScheduledSourceNode.js +1 -1
- package/lib/module/web-core/AudioScheduledSourceNode.js.map +1 -1
- package/lib/module/web-core/OfflineAudioContext.js +0 -4
- package/lib/module/web-core/OfflineAudioContext.js.map +1 -1
- package/lib/typescript/api.d.ts +4 -8
- package/lib/typescript/api.d.ts.map +1 -1
- package/lib/typescript/api.web.d.ts +0 -1
- package/lib/typescript/api.web.d.ts.map +1 -1
- package/lib/typescript/core/AudioBufferBaseSourceNode.d.ts +2 -2
- package/lib/typescript/core/AudioBufferBaseSourceNode.d.ts.map +1 -1
- package/lib/typescript/core/AudioBufferQueueSourceNode.d.ts +1 -1
- package/lib/typescript/core/AudioBufferQueueSourceNode.d.ts.map +1 -1
- package/lib/typescript/core/AudioBufferSourceNode.d.ts +0 -4
- package/lib/typescript/core/AudioBufferSourceNode.d.ts.map +1 -1
- package/lib/typescript/core/AudioContext.d.ts +0 -1
- package/lib/typescript/core/AudioContext.d.ts.map +1 -1
- package/lib/typescript/core/AudioScheduledSourceNode.d.ts +1 -1
- package/lib/typescript/core/BaseAudioContext.d.ts +11 -19
- package/lib/typescript/core/BaseAudioContext.d.ts.map +1 -1
- package/lib/typescript/core/OfflineAudioContext.d.ts +0 -1
- package/lib/typescript/core/OfflineAudioContext.d.ts.map +1 -1
- package/lib/typescript/core/OscillatorNode.d.ts +0 -3
- package/lib/typescript/core/OscillatorNode.d.ts.map +1 -1
- package/lib/typescript/events/types.d.ts +0 -2
- package/lib/typescript/events/types.d.ts.map +1 -1
- package/lib/typescript/hooks/{useSystemVolume.d.ts → useSytemVolume.d.ts} +1 -1
- package/lib/typescript/hooks/useSytemVolume.d.ts.map +1 -0
- package/lib/typescript/interfaces.d.ts +3 -21
- package/lib/typescript/interfaces.d.ts.map +1 -1
- package/lib/typescript/types.d.ts +1 -2
- package/lib/typescript/types.d.ts.map +1 -1
- package/lib/typescript/utils/index.d.ts +0 -8
- package/lib/typescript/utils/index.d.ts.map +1 -1
- package/lib/typescript/web-core/AudioBufferSourceNode.d.ts +1 -1
- package/lib/typescript/web-core/AudioContext.d.ts +2 -4
- package/lib/typescript/web-core/AudioContext.d.ts.map +1 -1
- package/lib/typescript/web-core/AudioScheduledSourceNode.d.ts +1 -1
- package/lib/typescript/web-core/BaseAudioContext.d.ts +0 -2
- package/lib/typescript/web-core/BaseAudioContext.d.ts.map +1 -1
- package/lib/typescript/web-core/OfflineAudioContext.d.ts +2 -4
- package/lib/typescript/web-core/OfflineAudioContext.d.ts.map +1 -1
- package/package.json +2 -3
- package/src/api.ts +3 -12
- package/src/api.web.ts +0 -1
- package/src/core/AudioBufferBaseSourceNode.ts +9 -9
- package/src/core/AudioBufferQueueSourceNode.ts +9 -1
- package/src/core/AudioBufferSourceNode.ts +0 -28
- package/src/core/AudioContext.ts +1 -12
- package/src/core/AudioScheduledSourceNode.ts +5 -5
- package/src/core/BaseAudioContext.ts +13 -149
- package/src/core/OfflineAudioContext.ts +2 -18
- package/src/core/OscillatorNode.ts +0 -11
- package/src/events/types.ts +0 -2
- package/src/interfaces.ts +5 -59
- package/src/types.ts +1 -3
- package/src/utils/index.ts +0 -21
- package/src/web-core/AudioBufferSourceNode.tsx +1 -1
- package/src/web-core/AudioContext.tsx +2 -7
- package/src/web-core/AudioScheduledSourceNode.tsx +1 -1
- package/src/web-core/BaseAudioContext.tsx +0 -2
- package/src/web-core/OfflineAudioContext.tsx +2 -7
- package/android/src/main/cpp/audioapi/android/core/NativeAudioRecorder.hpp +0 -36
- package/android/src/main/java/com/swmansion/audioapi/core/NativeAudioRecorder.kt +0 -24
- package/common/cpp/audioapi/HostObjects/AudioContextHostObject.cpp +0 -57
- package/common/cpp/audioapi/HostObjects/AudioParamHostObject.cpp +0 -105
- package/common/cpp/audioapi/HostObjects/OfflineAudioContextHostObject.cpp +0 -70
- package/common/cpp/audioapi/HostObjects/WorkletNodeHostObject.h +0 -18
- package/common/cpp/audioapi/HostObjects/WorkletProcessingNodeHostObject.h +0 -18
- package/common/cpp/audioapi/HostObjects/analysis/AnalyserNodeHostObject.cpp +0 -148
- package/common/cpp/audioapi/HostObjects/analysis/AnalyserNodeHostObject.h +0 -37
- package/common/cpp/audioapi/HostObjects/effects/BiquadFilterNodeHostObject.cpp +0 -92
- package/common/cpp/audioapi/HostObjects/effects/BiquadFilterNodeHostObject.h +0 -29
- package/common/cpp/audioapi/HostObjects/effects/GainNodeHostObject.cpp +0 -20
- package/common/cpp/audioapi/HostObjects/effects/GainNodeHostObject.h +0 -19
- package/common/cpp/audioapi/HostObjects/effects/StereoPannerNodeHostObject.cpp +0 -21
- package/common/cpp/audioapi/HostObjects/effects/StereoPannerNodeHostObject.h +0 -21
- package/common/cpp/audioapi/HostObjects/events/AudioEventHandlerRegistryHostObject.cpp +0 -41
- package/common/cpp/audioapi/HostObjects/events/AudioEventHandlerRegistryHostObject.h +0 -28
- package/common/cpp/audioapi/HostObjects/inputs/AudioRecorderHostObject.cpp +0 -69
- package/common/cpp/audioapi/HostObjects/inputs/AudioRecorderHostObject.h +0 -33
- package/common/cpp/audioapi/HostObjects/sources/AudioBufferBaseSourceNodeHostObject.cpp +0 -73
- package/common/cpp/audioapi/HostObjects/sources/AudioBufferBaseSourceNodeHostObject.h +0 -29
- package/common/cpp/audioapi/HostObjects/sources/AudioBufferHostObject.cpp +0 -94
- package/common/cpp/audioapi/HostObjects/sources/AudioBufferHostObject.h +0 -46
- package/common/cpp/audioapi/HostObjects/sources/AudioBufferQueueSourceNodeHostObject.cpp +0 -60
- package/common/cpp/audioapi/HostObjects/sources/AudioBufferQueueSourceNodeHostObject.h +0 -25
- package/common/cpp/audioapi/HostObjects/sources/AudioBufferSourceNodeHostObject.cpp +0 -152
- package/common/cpp/audioapi/HostObjects/sources/AudioBufferSourceNodeHostObject.h +0 -37
- package/common/cpp/audioapi/HostObjects/sources/AudioScheduledSourceNodeHostObject.cpp +0 -52
- package/common/cpp/audioapi/HostObjects/sources/AudioScheduledSourceNodeHostObject.h +0 -25
- package/common/cpp/audioapi/HostObjects/sources/ConstantSourceNodeHostObject.cpp +0 -19
- package/common/cpp/audioapi/HostObjects/sources/ConstantSourceNodeHostObject.h +0 -21
- package/common/cpp/audioapi/HostObjects/sources/OscillatorNodeHostObject.cpp +0 -55
- package/common/cpp/audioapi/HostObjects/sources/OscillatorNodeHostObject.h +0 -27
- package/common/cpp/audioapi/HostObjects/sources/StreamerNodeHostObject.cpp +0 -22
- package/common/cpp/audioapi/HostObjects/sources/StreamerNodeHostObject.h +0 -28
- package/common/cpp/audioapi/HostObjects/sources/WorkletSourceNodeHostObject.h +0 -18
- package/common/cpp/audioapi/core/effects/WorkletNode.cpp +0 -87
- package/common/cpp/audioapi/core/effects/WorkletNode.h +0 -65
- package/common/cpp/audioapi/core/effects/WorkletProcessingNode.cpp +0 -89
- package/common/cpp/audioapi/core/effects/WorkletProcessingNode.h +0 -52
- package/common/cpp/audioapi/core/sources/ConstantSourceNode.cpp +0 -51
- package/common/cpp/audioapi/core/sources/ConstantSourceNode.h +0 -26
- package/common/cpp/audioapi/core/sources/WorkletSourceNode.cpp +0 -82
- package/common/cpp/audioapi/core/sources/WorkletSourceNode.h +0 -47
- package/common/cpp/audioapi/core/utils/worklets/SafeIncludes.h +0 -52
- package/common/cpp/audioapi/core/utils/worklets/WorkletsRunner.cpp +0 -9
- package/common/cpp/audioapi/core/utils/worklets/WorkletsRunner.h +0 -73
- package/common/cpp/audioapi/utils/ThreadPool.hpp +0 -104
- package/common/cpp/test/AudioParamTest.cpp +0 -204
- package/lib/commonjs/core/ConstantSourceNode.js +0 -17
- package/lib/commonjs/core/ConstantSourceNode.js.map +0 -1
- package/lib/commonjs/core/WorkletNode.js +0 -11
- package/lib/commonjs/core/WorkletNode.js.map +0 -1
- package/lib/commonjs/core/WorkletProcessingNode.js +0 -11
- package/lib/commonjs/core/WorkletProcessingNode.js.map +0 -1
- package/lib/commonjs/core/WorkletSourceNode.js +0 -11
- package/lib/commonjs/core/WorkletSourceNode.js.map +0 -1
- package/lib/commonjs/hooks/useSystemVolume.js.map +0 -1
- package/lib/commonjs/web-core/ConstantSourceNode.js +0 -17
- package/lib/commonjs/web-core/ConstantSourceNode.js.map +0 -1
- package/lib/module/core/ConstantSourceNode.js +0 -11
- package/lib/module/core/ConstantSourceNode.js.map +0 -1
- package/lib/module/core/WorkletNode.js +0 -5
- package/lib/module/core/WorkletNode.js.map +0 -1
- package/lib/module/core/WorkletProcessingNode.js +0 -5
- package/lib/module/core/WorkletProcessingNode.js.map +0 -1
- package/lib/module/core/WorkletSourceNode.js +0 -5
- package/lib/module/core/WorkletSourceNode.js.map +0 -1
- package/lib/module/hooks/useSystemVolume.js.map +0 -1
- package/lib/module/web-core/ConstantSourceNode.js +0 -11
- package/lib/module/web-core/ConstantSourceNode.js.map +0 -1
- package/lib/typescript/core/ConstantSourceNode.d.ts +0 -9
- package/lib/typescript/core/ConstantSourceNode.d.ts.map +0 -1
- package/lib/typescript/core/WorkletNode.d.ts +0 -4
- package/lib/typescript/core/WorkletNode.d.ts.map +0 -1
- package/lib/typescript/core/WorkletProcessingNode.d.ts +0 -4
- package/lib/typescript/core/WorkletProcessingNode.d.ts.map +0 -1
- package/lib/typescript/core/WorkletSourceNode.d.ts +0 -4
- package/lib/typescript/core/WorkletSourceNode.d.ts.map +0 -1
- package/lib/typescript/hooks/useSystemVolume.d.ts.map +0 -1
- package/lib/typescript/web-core/ConstantSourceNode.d.ts +0 -8
- package/lib/typescript/web-core/ConstantSourceNode.d.ts.map +0 -1
- package/src/core/ConstantSourceNode.ts +0 -13
- package/src/core/WorkletNode.ts +0 -3
- package/src/core/WorkletProcessingNode.ts +0 -3
- package/src/core/WorkletSourceNode.ts +0 -3
- package/src/web-core/ConstantSourceNode.tsx +0 -12
- /package/common/cpp/audioapi/HostObjects/{destinations/AudioDestinationNodeHostObject.h → AudioDestinationNodeHostObject.h} +0 -0
- /package/common/cpp/audioapi/HostObjects/{effects/PeriodicWaveHostObject.h → PeriodicWaveHostObject.h} +0 -0
- /package/common/cpp/audioapi/core/{utils/AudioParamEventQueue.h → AudioParamEventQueue.h} +0 -0
- /package/src/hooks/{useSystemVolume.ts → useSytemVolume.ts} +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#include <audioapi/HostObjects/
|
|
1
|
+
#include <audioapi/HostObjects/AudioBufferHostObject.h>
|
|
2
2
|
#include <audioapi/core/inputs/AudioRecorder.h>
|
|
3
3
|
#include <audioapi/core/sources/AudioBuffer.h>
|
|
4
4
|
#include <audioapi/core/sources/RecorderAdapterNode.h>
|
|
@@ -1,18 +1,14 @@
|
|
|
1
1
|
#include <audioapi/core/AudioParam.h>
|
|
2
2
|
#include <audioapi/core/BaseAudioContext.h>
|
|
3
|
+
#include <audioapi/core/Constants.h>
|
|
3
4
|
#include <audioapi/core/sources/AudioBufferBaseSourceNode.h>
|
|
4
|
-
#include <audioapi/core/utils/Constants.h>
|
|
5
5
|
#include <audioapi/events/AudioEventHandlerRegistry.h>
|
|
6
6
|
#include <audioapi/utils/AudioArray.h>
|
|
7
7
|
#include <audioapi/utils/AudioBus.h>
|
|
8
8
|
|
|
9
9
|
namespace audioapi {
|
|
10
|
-
AudioBufferBaseSourceNode::AudioBufferBaseSourceNode(
|
|
11
|
-
|
|
12
|
-
bool pitchCorrection)
|
|
13
|
-
: AudioScheduledSourceNode(context),
|
|
14
|
-
pitchCorrection_(pitchCorrection),
|
|
15
|
-
vReadIndex_(0.0) {
|
|
10
|
+
AudioBufferBaseSourceNode::AudioBufferBaseSourceNode(BaseAudioContext *context)
|
|
11
|
+
: AudioScheduledSourceNode(context), vReadIndex_(0.0) {
|
|
16
12
|
onPositionChangedInterval_ = static_cast<int>(context->getSampleRate() * 0.1);
|
|
17
13
|
|
|
18
14
|
detuneParam_ = std::make_shared<AudioParam>(
|
|
@@ -28,7 +24,12 @@ AudioBufferBaseSourceNode::AudioBufferBaseSourceNode(
|
|
|
28
24
|
}
|
|
29
25
|
|
|
30
26
|
AudioBufferBaseSourceNode::~AudioBufferBaseSourceNode() {
|
|
31
|
-
|
|
27
|
+
if (onPositionChangedCallbackId_ != 0 &&
|
|
28
|
+
context_->audioEventHandlerRegistry_ != nullptr) {
|
|
29
|
+
context_->audioEventHandlerRegistry_->unregisterHandler(
|
|
30
|
+
"positionChanged", onPositionChangedCallbackId_);
|
|
31
|
+
onPositionChangedCallbackId_ = 0;
|
|
32
|
+
}
|
|
32
33
|
}
|
|
33
34
|
|
|
34
35
|
std::shared_ptr<AudioParam> AudioBufferBaseSourceNode::getDetuneParam() const {
|
|
@@ -61,7 +62,7 @@ void AudioBufferBaseSourceNode::setOnPositionChangedInterval(int interval) {
|
|
|
61
62
|
context_->getSampleRate() * static_cast<float>(interval) / 1000);
|
|
62
63
|
}
|
|
63
64
|
|
|
64
|
-
int AudioBufferBaseSourceNode::getOnPositionChangedInterval()
|
|
65
|
+
int AudioBufferBaseSourceNode::getOnPositionChangedInterval() {
|
|
65
66
|
return onPositionChangedInterval_;
|
|
66
67
|
}
|
|
67
68
|
|
|
@@ -124,45 +125,7 @@ void AudioBufferBaseSourceNode::processWithPitchCorrection(
|
|
|
124
125
|
if (detune != 0.0f) {
|
|
125
126
|
stretch_->setTransposeSemitones(detune);
|
|
126
127
|
}
|
|
127
|
-
|
|
128
128
|
sendOnPositionChangedEvent();
|
|
129
129
|
}
|
|
130
130
|
|
|
131
|
-
void AudioBufferBaseSourceNode::processWithoutPitchCorrection(
|
|
132
|
-
const std::shared_ptr<AudioBus> &processingBus,
|
|
133
|
-
int framesToProcess) {
|
|
134
|
-
size_t startOffset = 0;
|
|
135
|
-
size_t offsetLength = 0;
|
|
136
|
-
|
|
137
|
-
auto computedPlaybackRate = getComputedPlaybackRateValue(framesToProcess);
|
|
138
|
-
updatePlaybackInfo(processingBus, framesToProcess, startOffset, offsetLength);
|
|
139
|
-
|
|
140
|
-
if (computedPlaybackRate == 0.0f || (!isPlaying() && !isStopScheduled())) {
|
|
141
|
-
processingBus->zero();
|
|
142
|
-
return;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
if (std::fabs(computedPlaybackRate) == 1.0) {
|
|
146
|
-
processWithoutInterpolation(
|
|
147
|
-
processingBus, startOffset, offsetLength, computedPlaybackRate);
|
|
148
|
-
} else {
|
|
149
|
-
processWithInterpolation(
|
|
150
|
-
processingBus, startOffset, offsetLength, computedPlaybackRate);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
sendOnPositionChangedEvent();
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
float AudioBufferBaseSourceNode::getComputedPlaybackRateValue(
|
|
157
|
-
int framesToProcess) {
|
|
158
|
-
auto time = context_->getCurrentTime();
|
|
159
|
-
|
|
160
|
-
auto playbackRate =
|
|
161
|
-
playbackRateParam_->processKRateParam(framesToProcess, time);
|
|
162
|
-
auto detune = std::pow(
|
|
163
|
-
2.0f, detuneParam_->processKRateParam(framesToProcess, time) / 1200.0f);
|
|
164
|
-
|
|
165
|
-
return playbackRate * detune;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
131
|
} // namespace audioapi
|
|
@@ -14,8 +14,8 @@ class AudioParam;
|
|
|
14
14
|
|
|
15
15
|
class AudioBufferBaseSourceNode : public AudioScheduledSourceNode {
|
|
16
16
|
public:
|
|
17
|
-
explicit AudioBufferBaseSourceNode(BaseAudioContext *context
|
|
18
|
-
~AudioBufferBaseSourceNode()
|
|
17
|
+
explicit AudioBufferBaseSourceNode(BaseAudioContext *context);
|
|
18
|
+
virtual ~AudioBufferBaseSourceNode();
|
|
19
19
|
|
|
20
20
|
[[nodiscard]] std::shared_ptr<AudioParam> getDetuneParam() const;
|
|
21
21
|
[[nodiscard]] std::shared_ptr<AudioParam> getPlaybackRateParam() const;
|
|
@@ -23,12 +23,9 @@ class AudioBufferBaseSourceNode : public AudioScheduledSourceNode {
|
|
|
23
23
|
void clearOnPositionChangedCallback();
|
|
24
24
|
void setOnPositionChangedCallbackId(uint64_t callbackId);
|
|
25
25
|
void setOnPositionChangedInterval(int interval);
|
|
26
|
-
[[nodiscard]] int getOnPositionChangedInterval()
|
|
26
|
+
[[nodiscard]] int getOnPositionChangedInterval();
|
|
27
27
|
|
|
28
28
|
protected:
|
|
29
|
-
// pitch correction
|
|
30
|
-
bool pitchCorrection_;
|
|
31
|
-
|
|
32
29
|
std::mutex bufferLock_;
|
|
33
30
|
|
|
34
31
|
// pitch correction
|
|
@@ -50,25 +47,13 @@ class AudioBufferBaseSourceNode : public AudioScheduledSourceNode {
|
|
|
50
47
|
virtual double getCurrentPosition() const = 0;
|
|
51
48
|
|
|
52
49
|
void sendOnPositionChangedEvent();
|
|
53
|
-
|
|
54
50
|
void processWithPitchCorrection(const std::shared_ptr<AudioBus> &processingBus,
|
|
55
51
|
int framesToProcess);
|
|
56
|
-
void processWithoutPitchCorrection(const std::shared_ptr<AudioBus> &processingBus,
|
|
57
|
-
int framesToProcess);
|
|
58
|
-
|
|
59
|
-
float getComputedPlaybackRateValue(int framesToProcess);
|
|
60
|
-
|
|
61
52
|
virtual void processWithoutInterpolation(
|
|
62
53
|
const std::shared_ptr<AudioBus>& processingBus,
|
|
63
54
|
size_t startOffset,
|
|
64
55
|
size_t offsetLength,
|
|
65
56
|
float playbackRate) = 0;
|
|
66
|
-
|
|
67
|
-
virtual void processWithInterpolation(
|
|
68
|
-
const std::shared_ptr<AudioBus>& processingBus,
|
|
69
|
-
size_t startOffset,
|
|
70
|
-
size_t offsetLength,
|
|
71
|
-
float playbackRate) = 0;
|
|
72
57
|
};
|
|
73
58
|
|
|
74
59
|
} // namespace audioapi
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#include <audioapi/core/AudioParam.h>
|
|
2
2
|
#include <audioapi/core/BaseAudioContext.h>
|
|
3
|
+
#include <audioapi/core/Constants.h>
|
|
3
4
|
#include <audioapi/core/sources/AudioBufferQueueSourceNode.h>
|
|
4
|
-
#include <audioapi/core/utils/Constants.h>
|
|
5
5
|
#include <audioapi/core/utils/Locker.h>
|
|
6
6
|
#include <audioapi/dsp/AudioUtils.h>
|
|
7
7
|
#include <audioapi/events/AudioEventHandlerRegistry.h>
|
|
@@ -11,9 +11,8 @@
|
|
|
11
11
|
namespace audioapi {
|
|
12
12
|
|
|
13
13
|
AudioBufferQueueSourceNode::AudioBufferQueueSourceNode(
|
|
14
|
-
BaseAudioContext *context
|
|
15
|
-
|
|
16
|
-
: AudioBufferBaseSourceNode(context, pitchCorrection) {
|
|
14
|
+
BaseAudioContext *context)
|
|
15
|
+
: AudioBufferBaseSourceNode(context) {
|
|
17
16
|
buffers_ = {};
|
|
18
17
|
stretch_->presetDefault(channelCount_, context_->getSampleRate());
|
|
19
18
|
|
|
@@ -91,17 +90,13 @@ void AudioBufferQueueSourceNode::processNode(
|
|
|
91
90
|
const std::shared_ptr<AudioBus> &processingBus,
|
|
92
91
|
int framesToProcess) {
|
|
93
92
|
if (auto locker = Locker::tryLock(getBufferLock())) {
|
|
94
|
-
//
|
|
93
|
+
// No audio data to fill, zero the output and return.
|
|
95
94
|
if (buffers_.empty()) {
|
|
96
95
|
processingBus->zero();
|
|
97
96
|
return;
|
|
98
97
|
}
|
|
99
98
|
|
|
100
|
-
|
|
101
|
-
processWithoutPitchCorrection(processingBus, framesToProcess);
|
|
102
|
-
} else {
|
|
103
|
-
processWithPitchCorrection(processingBus, framesToProcess);
|
|
104
|
-
}
|
|
99
|
+
processWithPitchCorrection(processingBus, framesToProcess);
|
|
105
100
|
|
|
106
101
|
handleStopScheduled();
|
|
107
102
|
} else {
|
|
@@ -140,7 +135,6 @@ void AudioBufferQueueSourceNode::processWithoutInterpolation(
|
|
|
140
135
|
|
|
141
136
|
assert(readIndex >= 0);
|
|
142
137
|
assert(writeIndex >= 0);
|
|
143
|
-
assert(readIndex + framesToCopy <= buffer->getLength());
|
|
144
138
|
assert(writeIndex + framesToCopy <= processingBus->getSize());
|
|
145
139
|
|
|
146
140
|
processingBus->copy(
|
|
@@ -155,7 +149,7 @@ void AudioBufferQueueSourceNode::processWithoutInterpolation(
|
|
|
155
149
|
buffers_.pop();
|
|
156
150
|
|
|
157
151
|
std::unordered_map<std::string, EventValue> body = {
|
|
158
|
-
{"bufferId", std::to_string(bufferId)}
|
|
152
|
+
{"bufferId", std::to_string(bufferId)}};
|
|
159
153
|
context_->audioEventHandlerRegistry_->invokeHandlerWithEventBody(
|
|
160
154
|
"ended", onEndedCallbackId_, body);
|
|
161
155
|
|
|
@@ -164,12 +158,13 @@ void AudioBufferQueueSourceNode::processWithoutInterpolation(
|
|
|
164
158
|
readIndex = 0;
|
|
165
159
|
|
|
166
160
|
break;
|
|
167
|
-
}
|
|
161
|
+
} else {
|
|
162
|
+
data = buffers_.front();
|
|
163
|
+
bufferId = data.first;
|
|
164
|
+
buffer = data.second;
|
|
168
165
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
buffer = data.second;
|
|
172
|
-
readIndex = 0;
|
|
166
|
+
readIndex = 0;
|
|
167
|
+
}
|
|
173
168
|
}
|
|
174
169
|
}
|
|
175
170
|
|
|
@@ -177,81 +172,4 @@ void AudioBufferQueueSourceNode::processWithoutInterpolation(
|
|
|
177
172
|
vReadIndex_ = static_cast<double>(readIndex);
|
|
178
173
|
}
|
|
179
174
|
|
|
180
|
-
void AudioBufferQueueSourceNode::processWithInterpolation(
|
|
181
|
-
const std::shared_ptr<AudioBus> &processingBus,
|
|
182
|
-
size_t startOffset,
|
|
183
|
-
size_t offsetLength,
|
|
184
|
-
float playbackRate) {
|
|
185
|
-
size_t writeIndex = startOffset;
|
|
186
|
-
size_t framesLeft = offsetLength;
|
|
187
|
-
|
|
188
|
-
auto data = buffers_.front();
|
|
189
|
-
auto bufferId = data.first;
|
|
190
|
-
auto buffer = data.second;
|
|
191
|
-
|
|
192
|
-
while (framesLeft > 0) {
|
|
193
|
-
auto readIndex = static_cast<size_t>(vReadIndex_);
|
|
194
|
-
size_t nextReadIndex = readIndex + 1;
|
|
195
|
-
auto factor =
|
|
196
|
-
static_cast<float>(vReadIndex_ - static_cast<double>(readIndex));
|
|
197
|
-
|
|
198
|
-
bool crossBufferInterpolation = false;
|
|
199
|
-
std::shared_ptr<AudioBuffer> nextBuffer = nullptr;
|
|
200
|
-
|
|
201
|
-
if (nextReadIndex >= buffer->getLength()) {
|
|
202
|
-
if (buffers_.size() > 1) {
|
|
203
|
-
auto tempQueue = buffers_;
|
|
204
|
-
tempQueue.pop();
|
|
205
|
-
nextBuffer = tempQueue.front().second;
|
|
206
|
-
nextReadIndex = 0;
|
|
207
|
-
crossBufferInterpolation = true;
|
|
208
|
-
} else {
|
|
209
|
-
nextReadIndex = readIndex;
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
for (int i = 0; i < processingBus->getNumberOfChannels(); i += 1) {
|
|
214
|
-
float *destination = processingBus->getChannel(i)->getData();
|
|
215
|
-
const float *currentSource = buffer->bus_->getChannel(i)->getData();
|
|
216
|
-
|
|
217
|
-
if (crossBufferInterpolation) {
|
|
218
|
-
const float *nextSource = nextBuffer->bus_->getChannel(i)->getData();
|
|
219
|
-
float currentSample = currentSource[readIndex];
|
|
220
|
-
float nextSample = nextSource[nextReadIndex];
|
|
221
|
-
destination[writeIndex] =
|
|
222
|
-
currentSample + factor * (nextSample - currentSample);
|
|
223
|
-
} else {
|
|
224
|
-
destination[writeIndex] = dsp::linearInterpolate(
|
|
225
|
-
currentSource, readIndex, nextReadIndex, factor);
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
writeIndex += 1;
|
|
230
|
-
// queue source node always use positive playbackRate
|
|
231
|
-
vReadIndex_ += std::abs(playbackRate);
|
|
232
|
-
framesLeft -= 1;
|
|
233
|
-
|
|
234
|
-
if (vReadIndex_ >= static_cast<double>(buffer->getLength())) {
|
|
235
|
-
playedBuffersDuration_ += buffer->getDuration();
|
|
236
|
-
buffers_.pop();
|
|
237
|
-
|
|
238
|
-
std::unordered_map<std::string, EventValue> body = {
|
|
239
|
-
{"bufferId", std::to_string(bufferId)}};
|
|
240
|
-
context_->audioEventHandlerRegistry_->invokeHandlerWithEventBody(
|
|
241
|
-
"ended", onEndedCallbackId_, body);
|
|
242
|
-
|
|
243
|
-
if (buffers_.empty()) {
|
|
244
|
-
processingBus->zero(writeIndex, framesLeft);
|
|
245
|
-
vReadIndex_ = 0.0;
|
|
246
|
-
break;
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
vReadIndex_ = vReadIndex_ - buffer->getLength();
|
|
250
|
-
data = buffers_.front();
|
|
251
|
-
bufferId = data.first;
|
|
252
|
-
buffer = data.second;
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
|
|
257
175
|
} // namespace audioapi
|
|
@@ -17,14 +17,14 @@ class AudioParam;
|
|
|
17
17
|
|
|
18
18
|
class AudioBufferQueueSourceNode : public AudioBufferBaseSourceNode {
|
|
19
19
|
public:
|
|
20
|
-
explicit AudioBufferQueueSourceNode(BaseAudioContext *context
|
|
20
|
+
explicit AudioBufferQueueSourceNode(BaseAudioContext *context);
|
|
21
21
|
~AudioBufferQueueSourceNode() override;
|
|
22
22
|
|
|
23
23
|
void stop(double when) override;
|
|
24
24
|
void pause();
|
|
25
25
|
|
|
26
26
|
std::string enqueueBuffer(const std::shared_ptr<AudioBuffer> &buffer);
|
|
27
|
-
void dequeueBuffer(size_t bufferId);
|
|
27
|
+
void dequeueBuffer(const size_t bufferId);
|
|
28
28
|
void clearBuffers();
|
|
29
29
|
void disable() override;
|
|
30
30
|
|
|
@@ -46,12 +46,6 @@ class AudioBufferQueueSourceNode : public AudioBufferBaseSourceNode {
|
|
|
46
46
|
size_t startOffset,
|
|
47
47
|
size_t offsetLength,
|
|
48
48
|
float playbackRate) override;
|
|
49
|
-
|
|
50
|
-
void processWithInterpolation(
|
|
51
|
-
const std::shared_ptr<AudioBus>& processingBus,
|
|
52
|
-
size_t startOffset,
|
|
53
|
-
size_t offsetLength,
|
|
54
|
-
float playbackRate) override;
|
|
55
49
|
};
|
|
56
50
|
|
|
57
51
|
} // namespace audioapi
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#include <audioapi/core/AudioParam.h>
|
|
2
2
|
#include <audioapi/core/BaseAudioContext.h>
|
|
3
|
+
#include <audioapi/core/Constants.h>
|
|
3
4
|
#include <audioapi/core/sources/AudioBufferSourceNode.h>
|
|
4
|
-
#include <audioapi/core/utils/Constants.h>
|
|
5
5
|
#include <audioapi/core/utils/Locker.h>
|
|
6
6
|
#include <audioapi/dsp/AudioUtils.h>
|
|
7
7
|
#include <audioapi/events/AudioEventHandlerRegistry.h>
|
|
@@ -13,11 +13,12 @@ namespace audioapi {
|
|
|
13
13
|
AudioBufferSourceNode::AudioBufferSourceNode(
|
|
14
14
|
BaseAudioContext *context,
|
|
15
15
|
bool pitchCorrection)
|
|
16
|
-
: AudioBufferBaseSourceNode(context
|
|
16
|
+
: AudioBufferBaseSourceNode(context),
|
|
17
17
|
loop_(false),
|
|
18
18
|
loopSkip_(false),
|
|
19
19
|
loopStart_(0),
|
|
20
|
-
loopEnd_(0)
|
|
20
|
+
loopEnd_(0),
|
|
21
|
+
pitchCorrection_(pitchCorrection) {
|
|
21
22
|
buffer_ = std::shared_ptr<AudioBuffer>(nullptr);
|
|
22
23
|
alignedBus_ = std::shared_ptr<AudioBus>(nullptr);
|
|
23
24
|
|
|
@@ -29,8 +30,6 @@ AudioBufferSourceNode::~AudioBufferSourceNode() {
|
|
|
29
30
|
|
|
30
31
|
buffer_.reset();
|
|
31
32
|
alignedBus_.reset();
|
|
32
|
-
|
|
33
|
-
clearOnLoopEndedCallback();
|
|
34
33
|
}
|
|
35
34
|
|
|
36
35
|
bool AudioBufferSourceNode::getLoop() const {
|
|
@@ -125,21 +124,6 @@ void AudioBufferSourceNode::disable() {
|
|
|
125
124
|
alignedBus_.reset();
|
|
126
125
|
}
|
|
127
126
|
|
|
128
|
-
void AudioBufferSourceNode::clearOnLoopEndedCallback() {
|
|
129
|
-
if (onLoopEndedCallbackId_ == 0 || context_ == nullptr ||
|
|
130
|
-
context_->audioEventHandlerRegistry_ == nullptr) {
|
|
131
|
-
return;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
context_->audioEventHandlerRegistry_->unregisterHandler(
|
|
135
|
-
"loopEnded", onLoopEndedCallbackId_);
|
|
136
|
-
onLoopEndedCallbackId_ = 0;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
void AudioBufferSourceNode::setOnLoopEndedCallbackId(uint64_t callbackId) {
|
|
140
|
-
onLoopEndedCallbackId_ = callbackId;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
127
|
void AudioBufferSourceNode::processNode(
|
|
144
128
|
const std::shared_ptr<AudioBus> &processingBus,
|
|
145
129
|
int framesToProcess) {
|
|
@@ -167,19 +151,35 @@ double AudioBufferSourceNode::getCurrentPosition() const {
|
|
|
167
151
|
static_cast<int>(vReadIndex_), buffer_->getSampleRate());
|
|
168
152
|
}
|
|
169
153
|
|
|
170
|
-
void AudioBufferSourceNode::sendOnLoopEndedEvent() {
|
|
171
|
-
auto onLoopEndedCallbackId =
|
|
172
|
-
onLoopEndedCallbackId_.load(std::memory_order_acquire);
|
|
173
|
-
if (onLoopEndedCallbackId != 0) {
|
|
174
|
-
context_->audioEventHandlerRegistry_->invokeHandlerWithEventBody(
|
|
175
|
-
"loopEnded", onLoopEndedCallbackId_, {});
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
154
|
/**
|
|
180
155
|
* Helper functions
|
|
181
156
|
*/
|
|
182
157
|
|
|
158
|
+
void AudioBufferSourceNode::processWithoutPitchCorrection(
|
|
159
|
+
const std::shared_ptr<AudioBus> &processingBus,
|
|
160
|
+
int framesToProcess) {
|
|
161
|
+
size_t startOffset = 0;
|
|
162
|
+
size_t offsetLength = 0;
|
|
163
|
+
|
|
164
|
+
auto computedPlaybackRate = getComputedPlaybackRateValue(framesToProcess);
|
|
165
|
+
updatePlaybackInfo(processingBus, framesToProcess, startOffset, offsetLength);
|
|
166
|
+
|
|
167
|
+
if (computedPlaybackRate == 0.0f || (!isPlaying() && !isStopScheduled())) {
|
|
168
|
+
processingBus->zero();
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
if (std::fabs(computedPlaybackRate) == 1.0) {
|
|
173
|
+
processWithoutInterpolation(
|
|
174
|
+
processingBus, startOffset, offsetLength, computedPlaybackRate);
|
|
175
|
+
} else {
|
|
176
|
+
processWithInterpolation(
|
|
177
|
+
processingBus, startOffset, offsetLength, computedPlaybackRate);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
sendOnPositionChangedEvent();
|
|
181
|
+
}
|
|
182
|
+
|
|
183
183
|
void AudioBufferSourceNode::processWithoutInterpolation(
|
|
184
184
|
const std::shared_ptr<AudioBus> &processingBus,
|
|
185
185
|
size_t startOffset,
|
|
@@ -243,8 +243,6 @@ void AudioBufferSourceNode::processWithoutInterpolation(
|
|
|
243
243
|
playbackState_ = PlaybackState::STOP_SCHEDULED;
|
|
244
244
|
break;
|
|
245
245
|
}
|
|
246
|
-
|
|
247
|
-
sendOnLoopEndedEvent();
|
|
248
246
|
}
|
|
249
247
|
}
|
|
250
248
|
|
|
@@ -306,12 +304,23 @@ void AudioBufferSourceNode::processWithInterpolation(
|
|
|
306
304
|
playbackState_ = PlaybackState::STOP_SCHEDULED;
|
|
307
305
|
break;
|
|
308
306
|
}
|
|
309
|
-
|
|
310
|
-
sendOnLoopEndedEvent();
|
|
311
307
|
}
|
|
312
308
|
}
|
|
313
309
|
}
|
|
314
310
|
|
|
311
|
+
float AudioBufferSourceNode::getComputedPlaybackRateValue(int framesToProcess) {
|
|
312
|
+
auto time = context_->getCurrentTime();
|
|
313
|
+
|
|
314
|
+
auto sampleRateFactor =
|
|
315
|
+
alignedBus_->getSampleRate() / context_->getSampleRate();
|
|
316
|
+
auto playbackRate =
|
|
317
|
+
playbackRateParam_->processKRateParam(framesToProcess, time);
|
|
318
|
+
auto detune = std::pow(
|
|
319
|
+
2.0f, detuneParam_->processKRateParam(framesToProcess, time) / 1200.0f);
|
|
320
|
+
|
|
321
|
+
return playbackRate * sampleRateFactor * detune;
|
|
322
|
+
}
|
|
323
|
+
|
|
315
324
|
double AudioBufferSourceNode::getVirtualStartFrame() {
|
|
316
325
|
auto loopStartFrame = loopStart_ * context_->getSampleRate();
|
|
317
326
|
|
|
@@ -34,9 +34,6 @@ class AudioBufferSourceNode : public AudioBufferBaseSourceNode {
|
|
|
34
34
|
void start(double when, double offset, double duration = -1);
|
|
35
35
|
void disable() override;
|
|
36
36
|
|
|
37
|
-
void clearOnLoopEndedCallback();
|
|
38
|
-
void setOnLoopEndedCallbackId(uint64_t callbackId);
|
|
39
|
-
|
|
40
37
|
protected:
|
|
41
38
|
void processNode(const std::shared_ptr<AudioBus>& processingBus, int framesToProcess) override;
|
|
42
39
|
double getCurrentPosition() const override;
|
|
@@ -48,12 +45,15 @@ class AudioBufferSourceNode : public AudioBufferBaseSourceNode {
|
|
|
48
45
|
double loopStart_;
|
|
49
46
|
double loopEnd_;
|
|
50
47
|
|
|
48
|
+
// pitch correction
|
|
49
|
+
bool pitchCorrection_;
|
|
50
|
+
|
|
51
51
|
// User provided buffer
|
|
52
52
|
std::shared_ptr<AudioBuffer> buffer_;
|
|
53
53
|
std::shared_ptr<AudioBus> alignedBus_;
|
|
54
54
|
|
|
55
|
-
std::
|
|
56
|
-
|
|
55
|
+
void processWithoutPitchCorrection(const std::shared_ptr<AudioBus> &processingBus,
|
|
56
|
+
int framesToProcess);
|
|
57
57
|
|
|
58
58
|
void processWithoutInterpolation(
|
|
59
59
|
const std::shared_ptr<AudioBus>& processingBus,
|
|
@@ -65,7 +65,9 @@ class AudioBufferSourceNode : public AudioBufferBaseSourceNode {
|
|
|
65
65
|
const std::shared_ptr<AudioBus>& processingBus,
|
|
66
66
|
size_t startOffset,
|
|
67
67
|
size_t offsetLength,
|
|
68
|
-
float playbackRate)
|
|
68
|
+
float playbackRate);
|
|
69
|
+
|
|
70
|
+
float getComputedPlaybackRateValue(int framesToProcess);
|
|
69
71
|
|
|
70
72
|
double getVirtualStartFrame();
|
|
71
73
|
double getVirtualEndFrame();
|
|
@@ -17,7 +17,12 @@ AudioScheduledSourceNode::AudioScheduledSourceNode(BaseAudioContext *context)
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
AudioScheduledSourceNode::~AudioScheduledSourceNode() {
|
|
20
|
-
|
|
20
|
+
if (onEndedCallbackId_ != 0 &&
|
|
21
|
+
context_->audioEventHandlerRegistry_ != nullptr) {
|
|
22
|
+
context_->audioEventHandlerRegistry_->unregisterHandler(
|
|
23
|
+
"ended", onEndedCallbackId_);
|
|
24
|
+
onEndedCallbackId_ = 0;
|
|
25
|
+
}
|
|
21
26
|
}
|
|
22
27
|
|
|
23
28
|
void AudioScheduledSourceNode::start(double when) {
|
|
@@ -27,7 +27,7 @@ class AudioScheduledSourceNode : public AudioNode {
|
|
|
27
27
|
// FINISHED: The node has finished playing.
|
|
28
28
|
enum class PlaybackState { UNSCHEDULED, SCHEDULED, PLAYING, STOP_SCHEDULED, FINISHED };
|
|
29
29
|
explicit AudioScheduledSourceNode(BaseAudioContext *context);
|
|
30
|
-
~AudioScheduledSourceNode()
|
|
30
|
+
virtual ~AudioScheduledSourceNode();
|
|
31
31
|
|
|
32
32
|
void start(double when);
|
|
33
33
|
virtual void stop(double when);
|
|
@@ -43,6 +43,14 @@ class StreamerNode : public AudioScheduledSourceNode {
|
|
|
43
43
|
bool initialize(const std::string& inputUrl);
|
|
44
44
|
void stop(double when) override;
|
|
45
45
|
|
|
46
|
+
private:
|
|
47
|
+
static constexpr int SIZE = 4'000'000; // 4MB
|
|
48
|
+
|
|
49
|
+
public:
|
|
50
|
+
static constexpr int getEstimatedSize() {
|
|
51
|
+
return StreamerNode::SIZE;
|
|
52
|
+
} // in bytes
|
|
53
|
+
|
|
46
54
|
protected:
|
|
47
55
|
void processNode(const std::shared_ptr<AudioBus>& processingBus, int framesToProcess) override;
|
|
48
56
|
|
|
@@ -53,9 +53,8 @@ class AudioEventHandlerRegistry : public IAudioEventHandlerRegistry {
|
|
|
53
53
|
"volumeChange",
|
|
54
54
|
};
|
|
55
55
|
|
|
56
|
-
static constexpr std::array<std::string_view,
|
|
56
|
+
static constexpr std::array<std::string_view, 5> AUDIO_API_EVENT_NAMES = {
|
|
57
57
|
"ended",
|
|
58
|
-
"loopEnded",
|
|
59
58
|
"audioReady",
|
|
60
59
|
"positionChanged",
|
|
61
60
|
"audioError",
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <audioapi/jsi/JsiHostObject.h>
|
|
4
|
+
#include <audioapi/events/AudioEventHandlerRegistry.h>
|
|
5
|
+
|
|
6
|
+
#include <jsi/jsi.h>
|
|
7
|
+
#include <ReactCommon/CallInvoker.h>
|
|
8
|
+
#include <memory>
|
|
9
|
+
#include <unordered_map>
|
|
10
|
+
#include <vector>
|
|
11
|
+
#include <string>
|
|
12
|
+
|
|
13
|
+
namespace audioapi {
|
|
14
|
+
using namespace facebook;
|
|
15
|
+
|
|
16
|
+
class AudioEventHandlerRegistryHostObject : public JsiHostObject {
|
|
17
|
+
public:
|
|
18
|
+
explicit AudioEventHandlerRegistryHostObject(const std::shared_ptr<AudioEventHandlerRegistry>& eventHandlerRegistry) {
|
|
19
|
+
eventHandlerRegistry_ = eventHandlerRegistry;
|
|
20
|
+
|
|
21
|
+
addFunctions(
|
|
22
|
+
JSI_EXPORT_FUNCTION(AudioEventHandlerRegistryHostObject, addAudioEventListener),
|
|
23
|
+
JSI_EXPORT_FUNCTION(AudioEventHandlerRegistryHostObject, removeAudioEventListener));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
JSI_HOST_FUNCTION(addAudioEventListener) {
|
|
27
|
+
auto eventName = args[0].getString(runtime).utf8(runtime);
|
|
28
|
+
auto callback = std::make_shared<jsi::Function>(args[1].getObject(runtime).getFunction(runtime));
|
|
29
|
+
|
|
30
|
+
auto listenerId = eventHandlerRegistry_->registerHandler(eventName, callback);
|
|
31
|
+
|
|
32
|
+
return jsi::String::createFromUtf8(runtime, std::to_string(listenerId));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
JSI_HOST_FUNCTION(removeAudioEventListener) {
|
|
36
|
+
auto eventName = args[0].getString(runtime).utf8(runtime);
|
|
37
|
+
uint64_t listenerId = std::stoull(args[1].getString(runtime).utf8(runtime));
|
|
38
|
+
|
|
39
|
+
eventHandlerRegistry_->unregisterHandler(eventName, listenerId);
|
|
40
|
+
|
|
41
|
+
return jsi::Value::undefined();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
private:
|
|
45
|
+
std::shared_ptr<AudioEventHandlerRegistry> eventHandlerRegistry_;
|
|
46
|
+
};
|
|
47
|
+
} // namespace audioapi
|
|
48
|
+
|
|
@@ -9,20 +9,7 @@ using namespace facebook;
|
|
|
9
9
|
class AudioArrayBuffer : public jsi::MutableBuffer {
|
|
10
10
|
public:
|
|
11
11
|
AudioArrayBuffer(uint8_t *data, size_t size): data_(data), size_(size) {}
|
|
12
|
-
~AudioArrayBuffer() override
|
|
13
|
-
if (data_ == nullptr) {
|
|
14
|
-
return;
|
|
15
|
-
}
|
|
16
|
-
delete[] data_;
|
|
17
|
-
}
|
|
18
|
-
AudioArrayBuffer(AudioArrayBuffer &&other) noexcept
|
|
19
|
-
: data_(other.data_), size_(other.size_) {
|
|
20
|
-
other.data_ = nullptr;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
AudioArrayBuffer(const AudioArrayBuffer &) = delete;
|
|
24
|
-
AudioArrayBuffer &operator=(const AudioArrayBuffer &) = delete;
|
|
25
|
-
AudioArrayBuffer &operator=(AudioArrayBuffer &&other) = delete;
|
|
12
|
+
~AudioArrayBuffer() override = default;
|
|
26
13
|
|
|
27
14
|
[[nodiscard]] size_t size() const override;
|
|
28
15
|
uint8_t *data() override;
|