react-native-audio-api 0.8.3 → 0.9.0
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 +40 -39
- package/RNAudioAPI.podspec +17 -12
- package/android/build.gradle +44 -4
- package/android/src/main/cpp/audioapi/CMakeLists.txt +65 -0
- package/android/src/main/cpp/audioapi/android/AudioAPIModule.cpp +29 -1
- package/android/src/main/cpp/audioapi/android/AudioAPIModule.h +14 -0
- package/android/src/main/cpp/audioapi/android/core/AndroidAudioRecorder.cpp +7 -1
- package/android/src/main/cpp/audioapi/android/core/AndroidAudioRecorder.h +6 -1
- package/android/src/main/cpp/audioapi/android/core/AudioPlayer.cpp +1 -1
- package/android/src/main/cpp/audioapi/android/core/NativeAudioRecorder.hpp +36 -0
- package/android/src/main/java/com/swmansion/audioapi/AudioAPIModule.kt +11 -1
- package/android/src/main/java/com/swmansion/audioapi/core/NativeAudioRecorder.kt +24 -0
- package/android/src/main/java/com/swmansion/audioapi/system/MediaSessionManager.kt +15 -2
- package/common/cpp/audioapi/AudioAPIModuleInstaller.h +53 -18
- package/common/cpp/audioapi/HostObjects/AudioContextHostObject.cpp +57 -0
- package/common/cpp/audioapi/HostObjects/AudioContextHostObject.h +6 -46
- package/common/cpp/audioapi/HostObjects/AudioNodeHostObject.cpp +70 -6
- package/common/cpp/audioapi/HostObjects/AudioNodeHostObject.h +10 -66
- package/common/cpp/audioapi/HostObjects/AudioParamHostObject.cpp +105 -0
- package/common/cpp/audioapi/HostObjects/AudioParamHostObject.h +17 -91
- package/common/cpp/audioapi/HostObjects/BaseAudioContextHostObject.cpp +362 -6
- package/common/cpp/audioapi/HostObjects/BaseAudioContextHostObject.h +29 -241
- package/common/cpp/audioapi/HostObjects/OfflineAudioContextHostObject.cpp +70 -0
- package/common/cpp/audioapi/HostObjects/OfflineAudioContextHostObject.h +6 -50
- package/common/cpp/audioapi/HostObjects/WorkletNodeHostObject.h +18 -0
- package/common/cpp/audioapi/HostObjects/WorkletProcessingNodeHostObject.h +18 -0
- package/common/cpp/audioapi/HostObjects/analysis/AnalyserNodeHostObject.cpp +148 -0
- package/common/cpp/audioapi/HostObjects/analysis/AnalyserNodeHostObject.h +37 -0
- package/common/cpp/audioapi/HostObjects/effects/BiquadFilterNodeHostObject.cpp +92 -0
- package/common/cpp/audioapi/HostObjects/effects/BiquadFilterNodeHostObject.h +29 -0
- package/common/cpp/audioapi/HostObjects/effects/GainNodeHostObject.cpp +20 -0
- package/common/cpp/audioapi/HostObjects/effects/GainNodeHostObject.h +19 -0
- package/common/cpp/audioapi/HostObjects/effects/StereoPannerNodeHostObject.cpp +21 -0
- package/common/cpp/audioapi/HostObjects/effects/StereoPannerNodeHostObject.h +21 -0
- package/common/cpp/audioapi/HostObjects/events/AudioEventHandlerRegistryHostObject.cpp +41 -0
- package/common/cpp/audioapi/HostObjects/events/AudioEventHandlerRegistryHostObject.h +28 -0
- package/common/cpp/audioapi/HostObjects/inputs/AudioRecorderHostObject.cpp +69 -0
- package/common/cpp/audioapi/HostObjects/inputs/AudioRecorderHostObject.h +33 -0
- package/common/cpp/audioapi/HostObjects/sources/AudioBufferBaseSourceNodeHostObject.cpp +73 -0
- package/common/cpp/audioapi/HostObjects/sources/AudioBufferBaseSourceNodeHostObject.h +29 -0
- package/common/cpp/audioapi/HostObjects/sources/AudioBufferHostObject.cpp +94 -0
- package/common/cpp/audioapi/HostObjects/sources/AudioBufferHostObject.h +46 -0
- package/common/cpp/audioapi/HostObjects/sources/AudioBufferQueueSourceNodeHostObject.cpp +60 -0
- package/common/cpp/audioapi/HostObjects/sources/AudioBufferQueueSourceNodeHostObject.h +25 -0
- package/common/cpp/audioapi/HostObjects/sources/AudioBufferSourceNodeHostObject.cpp +152 -0
- package/common/cpp/audioapi/HostObjects/sources/AudioBufferSourceNodeHostObject.h +37 -0
- package/common/cpp/audioapi/HostObjects/sources/AudioScheduledSourceNodeHostObject.cpp +52 -0
- package/common/cpp/audioapi/HostObjects/sources/AudioScheduledSourceNodeHostObject.h +25 -0
- package/common/cpp/audioapi/HostObjects/sources/ConstantSourceNodeHostObject.cpp +19 -0
- package/common/cpp/audioapi/HostObjects/sources/ConstantSourceNodeHostObject.h +21 -0
- package/common/cpp/audioapi/HostObjects/sources/OscillatorNodeHostObject.cpp +55 -0
- package/common/cpp/audioapi/HostObjects/sources/OscillatorNodeHostObject.h +27 -0
- package/common/cpp/audioapi/HostObjects/{RecorderAdapterNodeHostObject.h → sources/RecorderAdapterNodeHostObject.h} +1 -2
- package/common/cpp/audioapi/HostObjects/sources/StreamerNodeHostObject.cpp +22 -0
- package/common/cpp/audioapi/HostObjects/sources/StreamerNodeHostObject.h +28 -0
- package/common/cpp/audioapi/HostObjects/sources/WorkletSourceNodeHostObject.h +18 -0
- package/common/cpp/audioapi/core/AudioContext.cpp +3 -2
- package/common/cpp/audioapi/core/AudioContext.h +2 -1
- package/common/cpp/audioapi/core/AudioNode.cpp +3 -3
- package/common/cpp/audioapi/core/AudioNode.h +2 -2
- package/common/cpp/audioapi/core/AudioParam.cpp +2 -2
- package/common/cpp/audioapi/core/AudioParam.h +1 -1
- package/common/cpp/audioapi/core/BaseAudioContext.cpp +47 -3
- package/common/cpp/audioapi/core/BaseAudioContext.h +13 -4
- package/common/cpp/audioapi/core/OfflineAudioContext.cpp +4 -3
- package/common/cpp/audioapi/core/OfflineAudioContext.h +2 -1
- package/common/cpp/audioapi/core/analysis/AnalyserNode.cpp +3 -1
- package/common/cpp/audioapi/core/analysis/AnalyserNode.h +1 -1
- package/common/cpp/audioapi/core/destinations/AudioDestinationNode.h +1 -1
- package/common/cpp/audioapi/core/effects/BiquadFilterNode.cpp +3 -1
- package/common/cpp/audioapi/core/effects/BiquadFilterNode.h +1 -1
- package/common/cpp/audioapi/core/effects/GainNode.cpp +3 -1
- package/common/cpp/audioapi/core/effects/GainNode.h +1 -1
- package/common/cpp/audioapi/core/effects/PeriodicWave.cpp +1 -1
- package/common/cpp/audioapi/core/effects/StereoPannerNode.cpp +18 -13
- package/common/cpp/audioapi/core/effects/StereoPannerNode.h +1 -1
- package/common/cpp/audioapi/core/effects/WorkletNode.cpp +89 -0
- package/common/cpp/audioapi/core/effects/WorkletNode.h +65 -0
- package/common/cpp/audioapi/core/effects/WorkletProcessingNode.cpp +91 -0
- package/common/cpp/audioapi/core/effects/WorkletProcessingNode.h +52 -0
- 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 +47 -10
- package/common/cpp/audioapi/core/sources/AudioBufferBaseSourceNode.h +18 -3
- package/common/cpp/audioapi/core/sources/AudioBufferQueueSourceNode.cpp +98 -14
- package/common/cpp/audioapi/core/sources/AudioBufferQueueSourceNode.h +9 -3
- package/common/cpp/audioapi/core/sources/AudioBufferSourceNode.cpp +37 -44
- package/common/cpp/audioapi/core/sources/AudioBufferSourceNode.h +7 -9
- package/common/cpp/audioapi/core/sources/AudioScheduledSourceNode.cpp +1 -6
- package/common/cpp/audioapi/core/sources/AudioScheduledSourceNode.h +1 -1
- package/common/cpp/audioapi/core/sources/ConstantSourceNode.cpp +53 -0
- package/common/cpp/audioapi/core/sources/ConstantSourceNode.h +26 -0
- package/common/cpp/audioapi/core/sources/OscillatorNode.cpp +7 -2
- package/common/cpp/audioapi/core/sources/OscillatorNode.h +1 -1
- package/common/cpp/audioapi/core/sources/RecorderAdapterNode.cpp +3 -1
- package/common/cpp/audioapi/core/sources/RecorderAdapterNode.h +1 -1
- package/common/cpp/audioapi/core/sources/StreamerNode.cpp +9 -1
- package/common/cpp/audioapi/core/sources/StreamerNode.h +1 -9
- package/common/cpp/audioapi/core/sources/WorkletSourceNode.cpp +84 -0
- package/common/cpp/audioapi/core/sources/WorkletSourceNode.h +47 -0
- package/common/cpp/audioapi/core/{AudioParamEventQueue.cpp → utils/AudioParamEventQueue.cpp} +13 -7
- package/common/cpp/audioapi/core/{Constants.h → utils/Constants.h} +5 -0
- package/common/cpp/audioapi/core/utils/worklets/SafeIncludes.h +52 -0
- package/common/cpp/audioapi/core/utils/worklets/WorkletsRunner.cpp +9 -0
- package/common/cpp/audioapi/core/utils/worklets/WorkletsRunner.h +73 -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 +2 -1
- package/common/cpp/audioapi/jsi/AudioArrayBuffer.h +14 -1
- package/common/cpp/audioapi/jsi/JsiHostObject.h +6 -12
- package/common/cpp/audioapi/jsi/JsiPromise.cpp +49 -0
- package/common/cpp/audioapi/jsi/JsiPromise.h +29 -1
- package/common/cpp/audioapi/utils/AudioBus.cpp +1 -1
- package/common/cpp/audioapi/utils/ThreadPool.hpp +104 -0
- package/common/cpp/test/AudioParamTest.cpp +204 -0
- package/common/cpp/test/CMakeLists.txt +12 -3
- package/common/cpp/test/GainTest.cpp +11 -10
- package/common/cpp/test/OscillatorTest.cpp +2 -1
- package/common/cpp/test/StereoPannerTest.cpp +129 -0
- package/ios/audioapi/ios/AudioAPIModule.mm +32 -5
- package/ios/audioapi/ios/core/IOSAudioPlayer.mm +1 -1
- package/ios/audioapi/ios/core/IOSAudioRecorder.mm +1 -1
- package/lib/commonjs/api.js +36 -2
- package/lib/commonjs/api.js.map +1 -1
- package/lib/commonjs/api.web.js +8 -0
- 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 +1 -6
- package/lib/commonjs/core/AudioBufferQueueSourceNode.js.map +1 -1
- package/lib/commonjs/core/AudioBufferSourceNode.js +15 -0
- package/lib/commonjs/core/AudioBufferSourceNode.js.map +1 -1
- package/lib/commonjs/core/AudioContext.js +10 -1
- 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 +66 -11
- package/lib/commonjs/core/BaseAudioContext.js.map +1 -1
- package/lib/commonjs/core/ConstantSourceNode.js +17 -0
- package/lib/commonjs/core/ConstantSourceNode.js.map +1 -0
- package/lib/commonjs/core/OfflineAudioContext.js +11 -2
- package/lib/commonjs/core/OfflineAudioContext.js.map +1 -1
- package/lib/commonjs/core/OscillatorNode.js +6 -0
- package/lib/commonjs/core/OscillatorNode.js.map +1 -1
- package/lib/commonjs/core/WorkletNode.js +11 -0
- package/lib/commonjs/core/WorkletNode.js.map +1 -0
- package/lib/commonjs/core/WorkletProcessingNode.js +11 -0
- package/lib/commonjs/core/WorkletProcessingNode.js.map +1 -0
- package/lib/commonjs/core/WorkletSourceNode.js +11 -0
- package/lib/commonjs/core/WorkletSourceNode.js.map +1 -0
- package/lib/commonjs/hooks/{useSytemVolume.js → useSystemVolume.js} +1 -1
- package/lib/commonjs/hooks/useSystemVolume.js.map +1 -0
- package/lib/commonjs/utils/index.js +9 -0
- package/lib/commonjs/utils/index.js.map +1 -1
- package/lib/commonjs/web-core/AudioContext.js +4 -0
- 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/ConstantSourceNode.js +17 -0
- package/lib/commonjs/web-core/ConstantSourceNode.js.map +1 -0
- package/lib/commonjs/web-core/OfflineAudioContext.js +4 -0
- package/lib/commonjs/web-core/OfflineAudioContext.js.map +1 -1
- package/lib/module/api.js +6 -2
- package/lib/module/api.js.map +1 -1
- package/lib/module/api.web.js +1 -0
- 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 +1 -6
- package/lib/module/core/AudioBufferQueueSourceNode.js.map +1 -1
- package/lib/module/core/AudioBufferSourceNode.js +15 -0
- package/lib/module/core/AudioBufferSourceNode.js.map +1 -1
- package/lib/module/core/AudioContext.js +10 -1
- 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 +66 -11
- package/lib/module/core/BaseAudioContext.js.map +1 -1
- package/lib/module/core/ConstantSourceNode.js +11 -0
- package/lib/module/core/ConstantSourceNode.js.map +1 -0
- package/lib/module/core/OfflineAudioContext.js +11 -2
- package/lib/module/core/OfflineAudioContext.js.map +1 -1
- package/lib/module/core/OscillatorNode.js +6 -0
- package/lib/module/core/OscillatorNode.js.map +1 -1
- package/lib/module/core/WorkletNode.js +5 -0
- package/lib/module/core/WorkletNode.js.map +1 -0
- package/lib/module/core/WorkletProcessingNode.js +5 -0
- package/lib/module/core/WorkletProcessingNode.js.map +1 -0
- package/lib/module/core/WorkletSourceNode.js +5 -0
- package/lib/module/core/WorkletSourceNode.js.map +1 -0
- package/lib/module/hooks/{useSytemVolume.js → useSystemVolume.js} +1 -1
- package/lib/module/hooks/useSystemVolume.js.map +1 -0
- package/lib/module/utils/index.js +8 -0
- package/lib/module/utils/index.js.map +1 -1
- package/lib/module/web-core/AudioContext.js +4 -0
- 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/ConstantSourceNode.js +11 -0
- package/lib/module/web-core/ConstantSourceNode.js.map +1 -0
- package/lib/module/web-core/OfflineAudioContext.js +4 -0
- package/lib/module/web-core/OfflineAudioContext.js.map +1 -1
- package/lib/typescript/api.d.ts +8 -4
- package/lib/typescript/api.d.ts.map +1 -1
- package/lib/typescript/api.web.d.ts +1 -0
- 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 +4 -0
- package/lib/typescript/core/AudioBufferSourceNode.d.ts.map +1 -1
- package/lib/typescript/core/AudioContext.d.ts +1 -0
- 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 +19 -11
- package/lib/typescript/core/BaseAudioContext.d.ts.map +1 -1
- package/lib/typescript/core/ConstantSourceNode.d.ts +9 -0
- package/lib/typescript/core/ConstantSourceNode.d.ts.map +1 -0
- package/lib/typescript/core/OfflineAudioContext.d.ts +1 -0
- package/lib/typescript/core/OfflineAudioContext.d.ts.map +1 -1
- package/lib/typescript/core/OscillatorNode.d.ts +3 -0
- package/lib/typescript/core/OscillatorNode.d.ts.map +1 -1
- package/lib/typescript/core/WorkletNode.d.ts +4 -0
- package/lib/typescript/core/WorkletNode.d.ts.map +1 -0
- package/lib/typescript/core/WorkletProcessingNode.d.ts +4 -0
- package/lib/typescript/core/WorkletProcessingNode.d.ts.map +1 -0
- package/lib/typescript/core/WorkletSourceNode.d.ts +4 -0
- package/lib/typescript/core/WorkletSourceNode.d.ts.map +1 -0
- package/lib/typescript/events/types.d.ts +2 -0
- package/lib/typescript/events/types.d.ts.map +1 -1
- package/lib/typescript/hooks/{useSytemVolume.d.ts → useSystemVolume.d.ts} +1 -1
- package/lib/typescript/hooks/useSystemVolume.d.ts.map +1 -0
- package/lib/typescript/interfaces.d.ts +21 -3
- package/lib/typescript/interfaces.d.ts.map +1 -1
- package/lib/typescript/types.d.ts +2 -1
- package/lib/typescript/types.d.ts.map +1 -1
- package/lib/typescript/utils/index.d.ts +8 -0
- 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 +4 -2
- 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 +2 -0
- package/lib/typescript/web-core/BaseAudioContext.d.ts.map +1 -1
- package/lib/typescript/web-core/ConstantSourceNode.d.ts +8 -0
- package/lib/typescript/web-core/ConstantSourceNode.d.ts.map +1 -0
- package/lib/typescript/web-core/OfflineAudioContext.d.ts +4 -2
- package/lib/typescript/web-core/OfflineAudioContext.d.ts.map +1 -1
- package/package.json +3 -2
- package/src/api.ts +12 -3
- package/src/api.web.ts +1 -0
- package/src/core/AudioBufferBaseSourceNode.ts +9 -9
- package/src/core/AudioBufferQueueSourceNode.ts +1 -9
- package/src/core/AudioBufferSourceNode.ts +28 -0
- package/src/core/AudioContext.ts +12 -1
- package/src/core/AudioScheduledSourceNode.ts +5 -5
- package/src/core/BaseAudioContext.ts +149 -13
- package/src/core/ConstantSourceNode.ts +13 -0
- package/src/core/OfflineAudioContext.ts +18 -2
- package/src/core/OscillatorNode.ts +11 -0
- package/src/core/WorkletNode.ts +3 -0
- package/src/core/WorkletProcessingNode.ts +3 -0
- package/src/core/WorkletSourceNode.ts +3 -0
- package/src/events/types.ts +2 -0
- package/src/interfaces.ts +59 -5
- package/src/types.ts +3 -1
- package/src/utils/index.ts +21 -0
- package/src/web-core/AudioBufferSourceNode.tsx +1 -1
- package/src/web-core/AudioContext.tsx +7 -2
- package/src/web-core/AudioScheduledSourceNode.tsx +1 -1
- package/src/web-core/BaseAudioContext.tsx +2 -0
- package/src/web-core/ConstantSourceNode.tsx +12 -0
- package/src/web-core/OfflineAudioContext.tsx +7 -2
- package/common/cpp/audioapi/HostObjects/AnalyserNodeHostObject.h +0 -149
- package/common/cpp/audioapi/HostObjects/AudioBufferBaseSourceNodeHostObject.h +0 -76
- package/common/cpp/audioapi/HostObjects/AudioBufferHostObject.h +0 -120
- package/common/cpp/audioapi/HostObjects/AudioBufferQueueSourceNodeHostObject.h +0 -67
- package/common/cpp/audioapi/HostObjects/AudioBufferSourceNodeHostObject.h +0 -142
- package/common/cpp/audioapi/HostObjects/AudioRecorderHostObject.h +0 -86
- package/common/cpp/audioapi/HostObjects/AudioScheduledSourceNodeHostObject.h +0 -56
- package/common/cpp/audioapi/HostObjects/BiquadFilterNodeHostObject.h +0 -89
- package/common/cpp/audioapi/HostObjects/GainNodeHostObject.h +0 -27
- package/common/cpp/audioapi/HostObjects/OscillatorNodeHostObject.h +0 -65
- package/common/cpp/audioapi/HostObjects/StereoPannerNodeHostObject.h +0 -29
- package/common/cpp/audioapi/HostObjects/StreamerNodeHostObject.h +0 -30
- package/common/cpp/audioapi/events/AudioEventHandlerRegistryHostObject.h +0 -48
- package/ios/audioapi/ios/events/IOSAudioEventHandlerRegistry.h +0 -7
- package/ios/audioapi/ios/events/IOSAudioEventHandlerRegistry.mm +0 -12
- package/lib/commonjs/hooks/useSytemVolume.js.map +0 -1
- package/lib/module/hooks/useSytemVolume.js.map +0 -1
- package/lib/typescript/hooks/useSytemVolume.d.ts.map +0 -1
- /package/common/cpp/audioapi/HostObjects/{AudioDestinationNodeHostObject.h → destinations/AudioDestinationNodeHostObject.h} +0 -0
- /package/common/cpp/audioapi/HostObjects/{PeriodicWaveHostObject.h → effects/PeriodicWaveHostObject.h} +0 -0
- /package/common/cpp/audioapi/core/{AudioParamEventQueue.h → utils/AudioParamEventQueue.h} +0 -0
- /package/src/hooks/{useSytemVolume.ts → useSystemVolume.ts} +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#include <audioapi/core/AudioParam.h>
|
|
2
2
|
#include <audioapi/core/BaseAudioContext.h>
|
|
3
|
-
#include <audioapi/core/Constants.h>
|
|
4
3
|
#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,8 +11,9 @@
|
|
|
11
11
|
namespace audioapi {
|
|
12
12
|
|
|
13
13
|
AudioBufferQueueSourceNode::AudioBufferQueueSourceNode(
|
|
14
|
-
BaseAudioContext *context
|
|
15
|
-
|
|
14
|
+
BaseAudioContext *context,
|
|
15
|
+
bool pitchCorrection)
|
|
16
|
+
: AudioBufferBaseSourceNode(context, pitchCorrection) {
|
|
16
17
|
buffers_ = {};
|
|
17
18
|
stretch_->presetDefault(channelCount_, context_->getSampleRate());
|
|
18
19
|
|
|
@@ -86,22 +87,28 @@ void AudioBufferQueueSourceNode::disable() {
|
|
|
86
87
|
buffers_ = {};
|
|
87
88
|
}
|
|
88
89
|
|
|
89
|
-
|
|
90
|
+
std::shared_ptr<AudioBus> AudioBufferQueueSourceNode::processNode(
|
|
90
91
|
const std::shared_ptr<AudioBus> &processingBus,
|
|
91
92
|
int framesToProcess) {
|
|
92
93
|
if (auto locker = Locker::tryLock(getBufferLock())) {
|
|
93
|
-
//
|
|
94
|
+
// no audio data to fill, zero the output and return.
|
|
94
95
|
if (buffers_.empty()) {
|
|
95
96
|
processingBus->zero();
|
|
96
|
-
return;
|
|
97
|
+
return processingBus;
|
|
97
98
|
}
|
|
98
99
|
|
|
99
|
-
|
|
100
|
+
if (!pitchCorrection_) {
|
|
101
|
+
processWithoutPitchCorrection(processingBus, framesToProcess);
|
|
102
|
+
} else {
|
|
103
|
+
processWithPitchCorrection(processingBus, framesToProcess);
|
|
104
|
+
}
|
|
100
105
|
|
|
101
106
|
handleStopScheduled();
|
|
102
107
|
} else {
|
|
103
108
|
processingBus->zero();
|
|
104
109
|
}
|
|
110
|
+
|
|
111
|
+
return processingBus;
|
|
105
112
|
}
|
|
106
113
|
|
|
107
114
|
double AudioBufferQueueSourceNode::getCurrentPosition() const {
|
|
@@ -135,6 +142,7 @@ void AudioBufferQueueSourceNode::processWithoutInterpolation(
|
|
|
135
142
|
|
|
136
143
|
assert(readIndex >= 0);
|
|
137
144
|
assert(writeIndex >= 0);
|
|
145
|
+
assert(readIndex + framesToCopy <= buffer->getLength());
|
|
138
146
|
assert(writeIndex + framesToCopy <= processingBus->getSize());
|
|
139
147
|
|
|
140
148
|
processingBus->copy(
|
|
@@ -149,7 +157,7 @@ void AudioBufferQueueSourceNode::processWithoutInterpolation(
|
|
|
149
157
|
buffers_.pop();
|
|
150
158
|
|
|
151
159
|
std::unordered_map<std::string, EventValue> body = {
|
|
152
|
-
{"bufferId", std::to_string(bufferId)}};
|
|
160
|
+
{"bufferId", std::to_string(bufferId)}, {"isLast", buffers_.empty()}};
|
|
153
161
|
context_->audioEventHandlerRegistry_->invokeHandlerWithEventBody(
|
|
154
162
|
"ended", onEndedCallbackId_, body);
|
|
155
163
|
|
|
@@ -158,13 +166,12 @@ void AudioBufferQueueSourceNode::processWithoutInterpolation(
|
|
|
158
166
|
readIndex = 0;
|
|
159
167
|
|
|
160
168
|
break;
|
|
161
|
-
} else {
|
|
162
|
-
data = buffers_.front();
|
|
163
|
-
bufferId = data.first;
|
|
164
|
-
buffer = data.second;
|
|
165
|
-
|
|
166
|
-
readIndex = 0;
|
|
167
169
|
}
|
|
170
|
+
|
|
171
|
+
data = buffers_.front();
|
|
172
|
+
bufferId = data.first;
|
|
173
|
+
buffer = data.second;
|
|
174
|
+
readIndex = 0;
|
|
168
175
|
}
|
|
169
176
|
}
|
|
170
177
|
|
|
@@ -172,4 +179,81 @@ void AudioBufferQueueSourceNode::processWithoutInterpolation(
|
|
|
172
179
|
vReadIndex_ = static_cast<double>(readIndex);
|
|
173
180
|
}
|
|
174
181
|
|
|
182
|
+
void AudioBufferQueueSourceNode::processWithInterpolation(
|
|
183
|
+
const std::shared_ptr<AudioBus> &processingBus,
|
|
184
|
+
size_t startOffset,
|
|
185
|
+
size_t offsetLength,
|
|
186
|
+
float playbackRate) {
|
|
187
|
+
size_t writeIndex = startOffset;
|
|
188
|
+
size_t framesLeft = offsetLength;
|
|
189
|
+
|
|
190
|
+
auto data = buffers_.front();
|
|
191
|
+
auto bufferId = data.first;
|
|
192
|
+
auto buffer = data.second;
|
|
193
|
+
|
|
194
|
+
while (framesLeft > 0) {
|
|
195
|
+
auto readIndex = static_cast<size_t>(vReadIndex_);
|
|
196
|
+
size_t nextReadIndex = readIndex + 1;
|
|
197
|
+
auto factor =
|
|
198
|
+
static_cast<float>(vReadIndex_ - static_cast<double>(readIndex));
|
|
199
|
+
|
|
200
|
+
bool crossBufferInterpolation = false;
|
|
201
|
+
std::shared_ptr<AudioBuffer> nextBuffer = nullptr;
|
|
202
|
+
|
|
203
|
+
if (nextReadIndex >= buffer->getLength()) {
|
|
204
|
+
if (buffers_.size() > 1) {
|
|
205
|
+
auto tempQueue = buffers_;
|
|
206
|
+
tempQueue.pop();
|
|
207
|
+
nextBuffer = tempQueue.front().second;
|
|
208
|
+
nextReadIndex = 0;
|
|
209
|
+
crossBufferInterpolation = true;
|
|
210
|
+
} else {
|
|
211
|
+
nextReadIndex = readIndex;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
for (int i = 0; i < processingBus->getNumberOfChannels(); i += 1) {
|
|
216
|
+
float *destination = processingBus->getChannel(i)->getData();
|
|
217
|
+
const float *currentSource = buffer->bus_->getChannel(i)->getData();
|
|
218
|
+
|
|
219
|
+
if (crossBufferInterpolation) {
|
|
220
|
+
const float *nextSource = nextBuffer->bus_->getChannel(i)->getData();
|
|
221
|
+
float currentSample = currentSource[readIndex];
|
|
222
|
+
float nextSample = nextSource[nextReadIndex];
|
|
223
|
+
destination[writeIndex] =
|
|
224
|
+
currentSample + factor * (nextSample - currentSample);
|
|
225
|
+
} else {
|
|
226
|
+
destination[writeIndex] = dsp::linearInterpolate(
|
|
227
|
+
currentSource, readIndex, nextReadIndex, factor);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
writeIndex += 1;
|
|
232
|
+
// queue source node always use positive playbackRate
|
|
233
|
+
vReadIndex_ += std::abs(playbackRate);
|
|
234
|
+
framesLeft -= 1;
|
|
235
|
+
|
|
236
|
+
if (vReadIndex_ >= static_cast<double>(buffer->getLength())) {
|
|
237
|
+
playedBuffersDuration_ += buffer->getDuration();
|
|
238
|
+
buffers_.pop();
|
|
239
|
+
|
|
240
|
+
std::unordered_map<std::string, EventValue> body = {
|
|
241
|
+
{"bufferId", std::to_string(bufferId)}};
|
|
242
|
+
context_->audioEventHandlerRegistry_->invokeHandlerWithEventBody(
|
|
243
|
+
"ended", onEndedCallbackId_, body);
|
|
244
|
+
|
|
245
|
+
if (buffers_.empty()) {
|
|
246
|
+
processingBus->zero(writeIndex, framesLeft);
|
|
247
|
+
vReadIndex_ = 0.0;
|
|
248
|
+
break;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
vReadIndex_ = vReadIndex_ - buffer->getLength();
|
|
252
|
+
data = buffers_.front();
|
|
253
|
+
bufferId = data.first;
|
|
254
|
+
buffer = data.second;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
175
259
|
} // namespace audioapi
|
|
@@ -17,19 +17,19 @@ class AudioParam;
|
|
|
17
17
|
|
|
18
18
|
class AudioBufferQueueSourceNode : public AudioBufferBaseSourceNode {
|
|
19
19
|
public:
|
|
20
|
-
explicit AudioBufferQueueSourceNode(BaseAudioContext *context);
|
|
20
|
+
explicit AudioBufferQueueSourceNode(BaseAudioContext *context, bool pitchCorrection);
|
|
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(
|
|
27
|
+
void dequeueBuffer(size_t bufferId);
|
|
28
28
|
void clearBuffers();
|
|
29
29
|
void disable() override;
|
|
30
30
|
|
|
31
31
|
protected:
|
|
32
|
-
|
|
32
|
+
std::shared_ptr<AudioBus> processNode(const std::shared_ptr<AudioBus>& processingBus, int framesToProcess) override;
|
|
33
33
|
double getCurrentPosition() const override;
|
|
34
34
|
|
|
35
35
|
private:
|
|
@@ -46,6 +46,12 @@ 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;
|
|
49
55
|
};
|
|
50
56
|
|
|
51
57
|
} // 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>
|
|
4
3
|
#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,12 +13,11 @@ namespace audioapi {
|
|
|
13
13
|
AudioBufferSourceNode::AudioBufferSourceNode(
|
|
14
14
|
BaseAudioContext *context,
|
|
15
15
|
bool pitchCorrection)
|
|
16
|
-
: AudioBufferBaseSourceNode(context),
|
|
16
|
+
: AudioBufferBaseSourceNode(context, pitchCorrection),
|
|
17
17
|
loop_(false),
|
|
18
18
|
loopSkip_(false),
|
|
19
19
|
loopStart_(0),
|
|
20
|
-
loopEnd_(0)
|
|
21
|
-
pitchCorrection_(pitchCorrection) {
|
|
20
|
+
loopEnd_(0) {
|
|
22
21
|
buffer_ = std::shared_ptr<AudioBuffer>(nullptr);
|
|
23
22
|
alignedBus_ = std::shared_ptr<AudioBus>(nullptr);
|
|
24
23
|
|
|
@@ -30,6 +29,8 @@ AudioBufferSourceNode::~AudioBufferSourceNode() {
|
|
|
30
29
|
|
|
31
30
|
buffer_.reset();
|
|
32
31
|
alignedBus_.reset();
|
|
32
|
+
|
|
33
|
+
clearOnLoopEndedCallback();
|
|
33
34
|
}
|
|
34
35
|
|
|
35
36
|
bool AudioBufferSourceNode::getLoop() const {
|
|
@@ -124,14 +125,29 @@ void AudioBufferSourceNode::disable() {
|
|
|
124
125
|
alignedBus_.reset();
|
|
125
126
|
}
|
|
126
127
|
|
|
127
|
-
void AudioBufferSourceNode::
|
|
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
|
+
std::shared_ptr<AudioBus> AudioBufferSourceNode::processNode(
|
|
128
144
|
const std::shared_ptr<AudioBus> &processingBus,
|
|
129
145
|
int framesToProcess) {
|
|
130
146
|
if (auto locker = Locker::tryLock(getBufferLock())) {
|
|
131
147
|
// No audio data to fill, zero the output and return.
|
|
132
148
|
if (!alignedBus_) {
|
|
133
149
|
processingBus->zero();
|
|
134
|
-
return;
|
|
150
|
+
return processingBus;
|
|
135
151
|
}
|
|
136
152
|
|
|
137
153
|
if (!pitchCorrection_) {
|
|
@@ -144,6 +160,8 @@ void AudioBufferSourceNode::processNode(
|
|
|
144
160
|
} else {
|
|
145
161
|
processingBus->zero();
|
|
146
162
|
}
|
|
163
|
+
|
|
164
|
+
return processingBus;
|
|
147
165
|
}
|
|
148
166
|
|
|
149
167
|
double AudioBufferSourceNode::getCurrentPosition() const {
|
|
@@ -151,35 +169,19 @@ double AudioBufferSourceNode::getCurrentPosition() const {
|
|
|
151
169
|
static_cast<int>(vReadIndex_), buffer_->getSampleRate());
|
|
152
170
|
}
|
|
153
171
|
|
|
172
|
+
void AudioBufferSourceNode::sendOnLoopEndedEvent() {
|
|
173
|
+
auto onLoopEndedCallbackId =
|
|
174
|
+
onLoopEndedCallbackId_.load(std::memory_order_acquire);
|
|
175
|
+
if (onLoopEndedCallbackId != 0) {
|
|
176
|
+
context_->audioEventHandlerRegistry_->invokeHandlerWithEventBody(
|
|
177
|
+
"loopEnded", onLoopEndedCallbackId_, {});
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
154
181
|
/**
|
|
155
182
|
* Helper functions
|
|
156
183
|
*/
|
|
157
184
|
|
|
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
185
|
void AudioBufferSourceNode::processWithoutInterpolation(
|
|
184
186
|
const std::shared_ptr<AudioBus> &processingBus,
|
|
185
187
|
size_t startOffset,
|
|
@@ -243,6 +245,8 @@ void AudioBufferSourceNode::processWithoutInterpolation(
|
|
|
243
245
|
playbackState_ = PlaybackState::STOP_SCHEDULED;
|
|
244
246
|
break;
|
|
245
247
|
}
|
|
248
|
+
|
|
249
|
+
sendOnLoopEndedEvent();
|
|
246
250
|
}
|
|
247
251
|
}
|
|
248
252
|
|
|
@@ -304,23 +308,12 @@ void AudioBufferSourceNode::processWithInterpolation(
|
|
|
304
308
|
playbackState_ = PlaybackState::STOP_SCHEDULED;
|
|
305
309
|
break;
|
|
306
310
|
}
|
|
311
|
+
|
|
312
|
+
sendOnLoopEndedEvent();
|
|
307
313
|
}
|
|
308
314
|
}
|
|
309
315
|
}
|
|
310
316
|
|
|
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
|
-
|
|
324
317
|
double AudioBufferSourceNode::getVirtualStartFrame() {
|
|
325
318
|
auto loopStartFrame = loopStart_ * context_->getSampleRate();
|
|
326
319
|
|
|
@@ -34,8 +34,11 @@ 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
|
+
|
|
37
40
|
protected:
|
|
38
|
-
|
|
41
|
+
std::shared_ptr<AudioBus> processNode(const std::shared_ptr<AudioBus>& processingBus, int framesToProcess) override;
|
|
39
42
|
double getCurrentPosition() const override;
|
|
40
43
|
|
|
41
44
|
private:
|
|
@@ -45,15 +48,12 @@ class AudioBufferSourceNode : public AudioBufferBaseSourceNode {
|
|
|
45
48
|
double loopStart_;
|
|
46
49
|
double loopEnd_;
|
|
47
50
|
|
|
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
|
-
|
|
56
|
-
|
|
55
|
+
std::atomic<uint64_t> onLoopEndedCallbackId_ = 0; // 0 means no callback
|
|
56
|
+
void sendOnLoopEndedEvent();
|
|
57
57
|
|
|
58
58
|
void processWithoutInterpolation(
|
|
59
59
|
const std::shared_ptr<AudioBus>& processingBus,
|
|
@@ -65,9 +65,7 @@ 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);
|
|
69
|
-
|
|
70
|
-
float getComputedPlaybackRateValue(int framesToProcess);
|
|
68
|
+
float playbackRate) override;
|
|
71
69
|
|
|
72
70
|
double getVirtualStartFrame();
|
|
73
71
|
double getVirtualEndFrame();
|
|
@@ -17,12 +17,7 @@ AudioScheduledSourceNode::AudioScheduledSourceNode(BaseAudioContext *context)
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
AudioScheduledSourceNode::~AudioScheduledSourceNode() {
|
|
20
|
-
|
|
21
|
-
context_->audioEventHandlerRegistry_ != nullptr) {
|
|
22
|
-
context_->audioEventHandlerRegistry_->unregisterHandler(
|
|
23
|
-
"ended", onEndedCallbackId_);
|
|
24
|
-
onEndedCallbackId_ = 0;
|
|
25
|
-
}
|
|
20
|
+
clearOnEndedCallback();
|
|
26
21
|
}
|
|
27
22
|
|
|
28
23
|
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
|
-
|
|
30
|
+
~AudioScheduledSourceNode() override;
|
|
31
31
|
|
|
32
32
|
void start(double when);
|
|
33
33
|
virtual void stop(double when);
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
#include <audioapi/core/BaseAudioContext.h>
|
|
2
|
+
#include <audioapi/core/sources/ConstantSourceNode.h>
|
|
3
|
+
#include <audioapi/dsp/AudioUtils.h>
|
|
4
|
+
#include <audioapi/utils/AudioArray.h>
|
|
5
|
+
#include <audioapi/utils/AudioBus.h>
|
|
6
|
+
|
|
7
|
+
namespace audioapi {
|
|
8
|
+
ConstantSourceNode::ConstantSourceNode(BaseAudioContext *context)
|
|
9
|
+
: AudioScheduledSourceNode(context) {
|
|
10
|
+
offsetParam_ = std::make_shared<AudioParam>(
|
|
11
|
+
1.0, MOST_NEGATIVE_SINGLE_FLOAT, MOST_POSITIVE_SINGLE_FLOAT, context);
|
|
12
|
+
isInitialized_ = true;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
std::shared_ptr<AudioParam> ConstantSourceNode::getOffsetParam() const {
|
|
16
|
+
return offsetParam_;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
std::shared_ptr<AudioBus> ConstantSourceNode::processNode(
|
|
20
|
+
const std::shared_ptr<AudioBus> &processingBus,
|
|
21
|
+
int framesToProcess) {
|
|
22
|
+
size_t startOffset = 0;
|
|
23
|
+
size_t offsetLength = 0;
|
|
24
|
+
|
|
25
|
+
updatePlaybackInfo(processingBus, framesToProcess, startOffset, offsetLength);
|
|
26
|
+
|
|
27
|
+
if (!isPlaying() && !isStopScheduled()) {
|
|
28
|
+
processingBus->zero();
|
|
29
|
+
return processingBus;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
auto offsetBus = offsetParam_->processARateParam(
|
|
33
|
+
framesToProcess, context_->getCurrentTime());
|
|
34
|
+
|
|
35
|
+
auto offsetChannelData = offsetBus->getChannel(0)->getData();
|
|
36
|
+
|
|
37
|
+
for (int channel = 0; channel < processingBus->getNumberOfChannels();
|
|
38
|
+
++channel) {
|
|
39
|
+
auto outputChannelData = processingBus->getChannel(channel)->getData();
|
|
40
|
+
|
|
41
|
+
std::copy(
|
|
42
|
+
offsetChannelData + startOffset,
|
|
43
|
+
offsetChannelData + startOffset + offsetLength,
|
|
44
|
+
outputChannelData + startOffset);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (isStopScheduled()) {
|
|
48
|
+
handleStopScheduled();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return processingBus;
|
|
52
|
+
}
|
|
53
|
+
} // namespace audioapi
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <audioapi/core/AudioParam.h>
|
|
4
|
+
#include <audioapi/core/sources/AudioScheduledSourceNode.h>
|
|
5
|
+
|
|
6
|
+
#include <cmath>
|
|
7
|
+
#include <memory>
|
|
8
|
+
#include <string>
|
|
9
|
+
|
|
10
|
+
namespace audioapi {
|
|
11
|
+
|
|
12
|
+
class AudioBus;
|
|
13
|
+
|
|
14
|
+
class ConstantSourceNode : public AudioScheduledSourceNode {
|
|
15
|
+
public:
|
|
16
|
+
explicit ConstantSourceNode(BaseAudioContext *context);
|
|
17
|
+
|
|
18
|
+
[[nodiscard]] std::shared_ptr<AudioParam> getOffsetParam() const;
|
|
19
|
+
|
|
20
|
+
protected:
|
|
21
|
+
std::shared_ptr<AudioBus> processNode(const std::shared_ptr<AudioBus>& processingBus, int framesToProcess) override;
|
|
22
|
+
|
|
23
|
+
private:
|
|
24
|
+
std::shared_ptr<AudioParam> offsetParam_;
|
|
25
|
+
};
|
|
26
|
+
} // namespace audioapi
|
|
@@ -21,6 +21,9 @@ OscillatorNode::OscillatorNode(BaseAudioContext *context)
|
|
|
21
21
|
type_ = OscillatorType::SINE;
|
|
22
22
|
periodicWave_ = context_->getBasicWaveForm(type_);
|
|
23
23
|
|
|
24
|
+
audioBus_ = std::make_shared<AudioBus>(
|
|
25
|
+
RENDER_QUANTUM_SIZE, 1, context_->getSampleRate());
|
|
26
|
+
|
|
24
27
|
isInitialized_ = true;
|
|
25
28
|
}
|
|
26
29
|
|
|
@@ -47,7 +50,7 @@ void OscillatorNode::setPeriodicWave(
|
|
|
47
50
|
type_ = OscillatorType::CUSTOM;
|
|
48
51
|
}
|
|
49
52
|
|
|
50
|
-
|
|
53
|
+
std::shared_ptr<AudioBus> OscillatorNode::processNode(
|
|
51
54
|
const std::shared_ptr<AudioBus> &processingBus,
|
|
52
55
|
int framesToProcess) {
|
|
53
56
|
size_t startOffset = 0;
|
|
@@ -57,7 +60,7 @@ void OscillatorNode::processNode(
|
|
|
57
60
|
|
|
58
61
|
if (!isPlaying() && !isStopScheduled()) {
|
|
59
62
|
processingBus->zero();
|
|
60
|
-
return;
|
|
63
|
+
return processingBus;
|
|
61
64
|
}
|
|
62
65
|
|
|
63
66
|
auto time = context_->getCurrentTime() +
|
|
@@ -89,6 +92,8 @@ void OscillatorNode::processNode(
|
|
|
89
92
|
}
|
|
90
93
|
|
|
91
94
|
handleStopScheduled();
|
|
95
|
+
|
|
96
|
+
return processingBus;
|
|
92
97
|
}
|
|
93
98
|
|
|
94
99
|
} // namespace audioapi
|
|
@@ -24,7 +24,7 @@ class OscillatorNode : public AudioScheduledSourceNode {
|
|
|
24
24
|
void setPeriodicWave(const std::shared_ptr<PeriodicWave> &periodicWave);
|
|
25
25
|
|
|
26
26
|
protected:
|
|
27
|
-
|
|
27
|
+
std::shared_ptr<AudioBus> processNode(const std::shared_ptr<AudioBus>& processingBus, int framesToProcess) override;
|
|
28
28
|
|
|
29
29
|
private:
|
|
30
30
|
std::shared_ptr<AudioParam> frequencyParam_;
|
|
@@ -23,7 +23,7 @@ void RecorderAdapterNode::init(size_t bufferSize) {
|
|
|
23
23
|
buff_ = std::make_shared<CircularOverflowableAudioArray>(bufferSize);
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
std::shared_ptr<AudioBus> RecorderAdapterNode::processNode(
|
|
27
27
|
const std::shared_ptr<AudioBus> &processingBus,
|
|
28
28
|
int framesToProcess) {
|
|
29
29
|
float *outputChannel = processingBus->getChannel(0)->getData();
|
|
@@ -33,6 +33,8 @@ void RecorderAdapterNode::processNode(
|
|
|
33
33
|
processingBus->getChannel(i)->copy(
|
|
34
34
|
processingBus->getChannel(0), 0, framesToProcess);
|
|
35
35
|
}
|
|
36
|
+
|
|
37
|
+
return processingBus;
|
|
36
38
|
}
|
|
37
39
|
|
|
38
40
|
void RecorderAdapterNode::readFrames(float *output, const size_t framesToRead) {
|
|
@@ -27,7 +27,7 @@ class RecorderAdapterNode : public AudioNode {
|
|
|
27
27
|
void init(size_t bufferSize);
|
|
28
28
|
|
|
29
29
|
protected:
|
|
30
|
-
|
|
30
|
+
std::shared_ptr<AudioBus> processNode(const std::shared_ptr<AudioBus>& processingBus, int framesToProcess) override;
|
|
31
31
|
std::shared_ptr<CircularOverflowableAudioArray> buff_;
|
|
32
32
|
|
|
33
33
|
private:
|
|
@@ -147,12 +147,18 @@ void StreamerNode::streamAudio() {
|
|
|
147
147
|
}
|
|
148
148
|
}
|
|
149
149
|
|
|
150
|
-
|
|
150
|
+
std::shared_ptr<AudioBus> StreamerNode::processNode(
|
|
151
151
|
const std::shared_ptr<AudioBus> &processingBus,
|
|
152
152
|
int framesToProcess) {
|
|
153
153
|
size_t startOffset = 0;
|
|
154
154
|
size_t offsetLength = 0;
|
|
155
155
|
updatePlaybackInfo(processingBus, framesToProcess, startOffset, offsetLength);
|
|
156
|
+
|
|
157
|
+
if (!isPlaying() && !isStopScheduled()) {
|
|
158
|
+
processingBus->zero();
|
|
159
|
+
return processingBus;
|
|
160
|
+
}
|
|
161
|
+
|
|
156
162
|
// If we have enough buffered data, copy to output bus
|
|
157
163
|
if (bufferedBusIndex_ >= framesToProcess) {
|
|
158
164
|
Locker locker(mutex_);
|
|
@@ -169,6 +175,8 @@ void StreamerNode::processNode(
|
|
|
169
175
|
}
|
|
170
176
|
bufferedBusIndex_ -= offsetLength;
|
|
171
177
|
}
|
|
178
|
+
|
|
179
|
+
return processingBus;
|
|
172
180
|
}
|
|
173
181
|
|
|
174
182
|
bool StreamerNode::processFrameWithResampler(AVFrame *frame) {
|
|
@@ -43,16 +43,8 @@ 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
|
-
|
|
54
46
|
protected:
|
|
55
|
-
|
|
47
|
+
std::shared_ptr<AudioBus> processNode(const std::shared_ptr<AudioBus>& processingBus, int framesToProcess) override;
|
|
56
48
|
|
|
57
49
|
private:
|
|
58
50
|
#ifndef AUDIO_API_TEST_SUITE
|