react-native-audio-api 0.8.3 → 0.9.0-nightly-96a5bcd-20251007
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/cpp/audioapi/android/core/{AudioDecoder.cpp → utils/AudioDecoder.cpp} +79 -75
- 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 +129 -38
- 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 +262 -6
- package/common/cpp/audioapi/HostObjects/BaseAudioContextHostObject.h +26 -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/HostObjects/utils/AudioDecoderHostObject.cpp +107 -0
- package/common/cpp/audioapi/HostObjects/utils/AudioDecoderHostObject.h +28 -0
- package/common/cpp/audioapi/core/AudioContext.cpp +3 -4
- 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 -38
- package/common/cpp/audioapi/core/BaseAudioContext.h +17 -16
- package/common/cpp/audioapi/core/OfflineAudioContext.cpp +4 -5
- 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/types/AudioFormat.h +16 -0
- package/common/cpp/audioapi/core/utils/AudioDecoder.h +36 -90
- 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/libs/ffmpeg/FFmpegDecoding.cpp +241 -282
- package/common/cpp/audioapi/libs/ffmpeg/FFmpegDecoding.h +57 -19
- 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 +13 -4
- 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/ios/audioapi/ios/core/utils/AudioDecoder.mm +160 -0
- package/lib/commonjs/api.js +50 -3
- 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/AudioDecoder.js +48 -0
- package/lib/commonjs/core/AudioDecoder.js.map +1 -0
- package/lib/commonjs/core/AudioScheduledSourceNode.js +4 -4
- package/lib/commonjs/core/AudioScheduledSourceNode.js.map +1 -1
- package/lib/commonjs/core/BaseAudioContext.js +76 -28
- 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 +8 -3
- 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/AudioDecoder.js +42 -0
- package/lib/module/core/AudioDecoder.js.map +1 -0
- package/lib/module/core/AudioScheduledSourceNode.js +4 -4
- package/lib/module/core/AudioScheduledSourceNode.js.map +1 -1
- package/lib/module/core/BaseAudioContext.js +76 -28
- 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 +11 -5
- 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/AudioDecoder.d.ts +4 -0
- package/lib/typescript/core/AudioDecoder.d.ts.map +1 -0
- package/lib/typescript/core/AudioScheduledSourceNode.d.ts +1 -1
- package/lib/typescript/core/BaseAudioContext.d.ts +21 -16
- 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 +27 -6
- 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 +17 -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/AudioDecoder.ts +78 -0
- package/src/core/AudioScheduledSourceNode.ts +5 -5
- package/src/core/BaseAudioContext.ts +174 -41
- 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 +77 -11
- 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/core/AudioDecoder.mm +0 -156
- 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
package/android/src/main/cpp/audioapi/android/core/{AudioDecoder.cpp → utils/AudioDecoder.cpp}
RENAMED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
#include <audioapi/core/sources/AudioBuffer.h>
|
|
1
2
|
#include <audioapi/core/utils/AudioDecoder.h>
|
|
2
3
|
#include <audioapi/dsp/VectorMath.h>
|
|
3
4
|
#include <audioapi/libs/base64/base64.h>
|
|
@@ -5,28 +6,28 @@
|
|
|
5
6
|
#include <audioapi/utils/AudioBus.h>
|
|
6
7
|
|
|
7
8
|
#define MINIAUDIO_IMPLEMENTATION
|
|
9
|
+
#include <audioapi/libs/miniaudio/decoders/libopus/miniaudio_libopus.h>
|
|
10
|
+
#include <audioapi/libs/miniaudio/decoders/libvorbis/miniaudio_libvorbis.h>
|
|
8
11
|
#include <audioapi/libs/miniaudio/miniaudio.h>
|
|
9
12
|
|
|
10
13
|
#ifndef AUDIO_API_TEST_SUITE
|
|
11
14
|
#include <android/log.h>
|
|
12
15
|
#include <audioapi/libs/ffmpeg/FFmpegDecoding.h>
|
|
13
16
|
#endif
|
|
14
|
-
#include <audioapi/libs/miniaudio/decoders/libopus/miniaudio_libopus.h>
|
|
15
|
-
#include <audioapi/libs/miniaudio/decoders/libvorbis/miniaudio_libvorbis.h>
|
|
16
17
|
|
|
17
18
|
namespace audioapi {
|
|
18
19
|
|
|
19
20
|
// Decoding audio in fixed-size chunks because total frame count can't be
|
|
20
21
|
// determined in advance. Note: ma_decoder_get_length_in_pcm_frames() always
|
|
21
22
|
// returns 0 for Vorbis decoders.
|
|
22
|
-
std::vector<
|
|
23
|
+
std::vector<float> AudioDecoder::readAllPcmFrames(
|
|
23
24
|
ma_decoder &decoder,
|
|
24
|
-
int
|
|
25
|
-
|
|
26
|
-
std::vector<
|
|
27
|
-
|
|
28
|
-
outFramesRead = 0;
|
|
25
|
+
int outputChannels) {
|
|
26
|
+
std::vector<float> buffer;
|
|
27
|
+
std::vector<float> temp(CHUNK_SIZE * outputChannels);
|
|
28
|
+
ma_uint64 outFramesRead = 0;
|
|
29
29
|
|
|
30
|
+
#ifndef AUDIO_API_TEST_SUITE
|
|
30
31
|
while (true) {
|
|
31
32
|
ma_uint64 tempFramesDecoded = 0;
|
|
32
33
|
ma_decoder_read_pcm_frames(
|
|
@@ -38,38 +39,46 @@ std::vector<int16_t> AudioDecoder::readAllPcmFrames(
|
|
|
38
39
|
buffer.insert(
|
|
39
40
|
buffer.end(),
|
|
40
41
|
temp.data(),
|
|
41
|
-
temp.data() + tempFramesDecoded *
|
|
42
|
+
temp.data() + tempFramesDecoded * outputChannels);
|
|
42
43
|
outFramesRead += tempFramesDecoded;
|
|
43
44
|
}
|
|
44
45
|
|
|
46
|
+
if (outFramesRead == 0) {
|
|
47
|
+
__android_log_print(ANDROID_LOG_ERROR, "AudioDecoder", "Failed to decode");
|
|
48
|
+
}
|
|
49
|
+
#endif
|
|
45
50
|
return buffer;
|
|
46
51
|
}
|
|
47
52
|
|
|
48
|
-
std::shared_ptr<
|
|
49
|
-
const std::vector<
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
std::shared_ptr<AudioBuffer> AudioDecoder::makeAudioBufferFromFloatBuffer(
|
|
54
|
+
const std::vector<float> &buffer,
|
|
55
|
+
float outputSampleRate,
|
|
56
|
+
int outputChannels) {
|
|
57
|
+
if (buffer.empty()) {
|
|
58
|
+
return nullptr;
|
|
59
|
+
}
|
|
55
60
|
|
|
56
|
-
|
|
61
|
+
auto outputFrames = buffer.size() / outputChannels;
|
|
62
|
+
auto audioBus = std::make_shared<AudioBus>(
|
|
63
|
+
outputFrames, outputChannels, outputSampleRate);
|
|
64
|
+
|
|
65
|
+
for (int ch = 0; ch < outputChannels; ++ch) {
|
|
57
66
|
auto channelData = audioBus->getChannel(ch)->getData();
|
|
58
67
|
for (int i = 0; i < outputFrames; ++i) {
|
|
59
|
-
channelData[i] =
|
|
68
|
+
channelData[i] = buffer[i * outputChannels + ch];
|
|
60
69
|
}
|
|
61
70
|
}
|
|
62
|
-
return audioBus;
|
|
71
|
+
return std::make_shared<AudioBuffer>(audioBus);
|
|
63
72
|
}
|
|
64
73
|
|
|
65
|
-
std::shared_ptr<
|
|
66
|
-
const std::string &path
|
|
74
|
+
std::shared_ptr<AudioBuffer> AudioDecoder::decodeWithFilePath(
|
|
75
|
+
const std::string &path,
|
|
76
|
+
float sampleRate) {
|
|
67
77
|
#ifndef AUDIO_API_TEST_SUITE
|
|
68
|
-
std::vector<int16_t> buffer;
|
|
69
78
|
if (AudioDecoder::pathHasExtension(path, {".mp4", ".m4a", ".aac"})) {
|
|
70
|
-
buffer =
|
|
71
|
-
path,
|
|
72
|
-
if (buffer
|
|
79
|
+
auto buffer =
|
|
80
|
+
ffmpegdecoder::decodeWithFilePath(path, static_cast<int>(sampleRate));
|
|
81
|
+
if (buffer == nullptr) {
|
|
73
82
|
__android_log_print(
|
|
74
83
|
ANDROID_LOG_ERROR,
|
|
75
84
|
"AudioDecoder",
|
|
@@ -77,11 +86,11 @@ std::shared_ptr<AudioBus> AudioDecoder::decodeWithFilePath(
|
|
|
77
86
|
path.c_str());
|
|
78
87
|
return nullptr;
|
|
79
88
|
}
|
|
80
|
-
return
|
|
89
|
+
return buffer;
|
|
81
90
|
}
|
|
82
91
|
ma_decoder decoder;
|
|
83
|
-
ma_decoder_config config =
|
|
84
|
-
|
|
92
|
+
ma_decoder_config config =
|
|
93
|
+
ma_decoder_config_init(ma_format_f32, 0, static_cast<int>(sampleRate));
|
|
85
94
|
ma_decoding_backend_vtable *customBackends[] = {
|
|
86
95
|
ma_decoding_backend_libvorbis, ma_decoding_backend_libopus};
|
|
87
96
|
|
|
@@ -99,41 +108,38 @@ std::shared_ptr<AudioBus> AudioDecoder::decodeWithFilePath(
|
|
|
99
108
|
return nullptr;
|
|
100
109
|
}
|
|
101
110
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
if (framesRead == 0) {
|
|
105
|
-
__android_log_print(ANDROID_LOG_ERROR, "AudioDecoder", "Failed to decode");
|
|
106
|
-
ma_decoder_uninit(&decoder);
|
|
107
|
-
return nullptr;
|
|
108
|
-
}
|
|
111
|
+
auto outputSampleRate = static_cast<float>(decoder.outputSampleRate);
|
|
112
|
+
auto outputChannels = static_cast<int>(decoder.outputChannels);
|
|
109
113
|
|
|
114
|
+
std::vector<float> buffer = readAllPcmFrames(decoder, outputChannels);
|
|
110
115
|
ma_decoder_uninit(&decoder);
|
|
111
|
-
return
|
|
116
|
+
return makeAudioBufferFromFloatBuffer(
|
|
117
|
+
buffer, outputSampleRate, outputChannels);
|
|
112
118
|
#else
|
|
113
119
|
return nullptr;
|
|
114
120
|
#endif
|
|
115
121
|
}
|
|
116
122
|
|
|
117
|
-
std::shared_ptr<
|
|
123
|
+
std::shared_ptr<AudioBuffer> AudioDecoder::decodeWithMemoryBlock(
|
|
118
124
|
const void *data,
|
|
119
|
-
size_t size
|
|
125
|
+
size_t size,
|
|
126
|
+
float sampleRate) {
|
|
120
127
|
#ifndef AUDIO_API_TEST_SUITE
|
|
121
|
-
std::vector<int16_t> buffer;
|
|
122
128
|
const AudioFormat format = AudioDecoder::detectAudioFormat(data, size);
|
|
123
129
|
if (format == AudioFormat::MP4 || format == AudioFormat::M4A ||
|
|
124
130
|
format == AudioFormat::AAC) {
|
|
125
|
-
buffer =
|
|
126
|
-
data, size,
|
|
127
|
-
if (buffer
|
|
131
|
+
auto buffer = ffmpegdecoder::decodeWithMemoryBlock(
|
|
132
|
+
data, size, static_cast<int>(sampleRate));
|
|
133
|
+
if (buffer == nullptr) {
|
|
128
134
|
__android_log_print(
|
|
129
135
|
ANDROID_LOG_ERROR, "AudioDecoder", "Failed to decode with FFmpeg");
|
|
130
136
|
return nullptr;
|
|
131
137
|
}
|
|
132
|
-
return
|
|
138
|
+
return buffer;
|
|
133
139
|
}
|
|
134
140
|
ma_decoder decoder;
|
|
135
|
-
ma_decoder_config config =
|
|
136
|
-
|
|
141
|
+
ma_decoder_config config =
|
|
142
|
+
ma_decoder_config_init(ma_format_f32, 0, static_cast<int>(sampleRate));
|
|
137
143
|
|
|
138
144
|
ma_decoding_backend_vtable *customBackends[] = {
|
|
139
145
|
ma_decoding_backend_libvorbis, ma_decoding_backend_libopus};
|
|
@@ -151,50 +157,48 @@ std::shared_ptr<AudioBus> AudioDecoder::decodeWithMemoryBlock(
|
|
|
151
157
|
return nullptr;
|
|
152
158
|
}
|
|
153
159
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
if (framesRead == 0) {
|
|
157
|
-
__android_log_print(ANDROID_LOG_ERROR, "AudioDecoder", "Failed to decode");
|
|
158
|
-
ma_decoder_uninit(&decoder);
|
|
159
|
-
return nullptr;
|
|
160
|
-
}
|
|
160
|
+
auto outputSampleRate = static_cast<float>(decoder.outputSampleRate);
|
|
161
|
+
auto outputChannels = static_cast<int>(decoder.outputChannels);
|
|
161
162
|
|
|
163
|
+
std::vector<float> buffer = readAllPcmFrames(decoder, outputChannels);
|
|
162
164
|
ma_decoder_uninit(&decoder);
|
|
163
|
-
return
|
|
165
|
+
return makeAudioBufferFromFloatBuffer(
|
|
166
|
+
buffer, outputSampleRate, outputChannels);
|
|
164
167
|
#else
|
|
165
168
|
return nullptr;
|
|
166
169
|
#endif
|
|
167
170
|
}
|
|
168
171
|
|
|
169
|
-
std::shared_ptr<
|
|
172
|
+
std::shared_ptr<AudioBuffer> AudioDecoder::decodeWithPCMInBase64(
|
|
170
173
|
const std::string &data,
|
|
171
|
-
float
|
|
174
|
+
float inputSampleRate,
|
|
175
|
+
int inputChannelCount,
|
|
176
|
+
bool interleaved) {
|
|
172
177
|
auto decodedData = base64_decode(data, false);
|
|
173
|
-
|
|
174
178
|
const auto uint8Data = reinterpret_cast<uint8_t *>(decodedData.data());
|
|
175
|
-
size_t
|
|
176
|
-
|
|
177
|
-
std::vector<int16_t> buffer(framesDecoded);
|
|
178
|
-
for (size_t i = 0; i < framesDecoded; ++i) {
|
|
179
|
-
buffer[i] =
|
|
180
|
-
static_cast<int16_t>((uint8Data[i * 2 + 1] << 8) | uint8Data[i * 2]);
|
|
181
|
-
}
|
|
179
|
+
size_t numFramesDecoded =
|
|
180
|
+
decodedData.size() / (inputChannelCount * sizeof(int16_t));
|
|
182
181
|
|
|
183
|
-
|
|
184
|
-
|
|
182
|
+
auto audioBus = std::make_shared<AudioBus>(
|
|
183
|
+
numFramesDecoded, inputChannelCount, inputSampleRate);
|
|
185
184
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
auto leftChannelData = audioBus->getChannel(0)->getData();
|
|
189
|
-
auto rightChannelData = audioBus->getChannel(1)->getData();
|
|
185
|
+
for (int ch = 0; ch < inputChannelCount; ++ch) {
|
|
186
|
+
auto channelData = audioBus->getChannel(ch)->getData();
|
|
190
187
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
188
|
+
for (size_t i = 0; i < numFramesDecoded; ++i) {
|
|
189
|
+
size_t offset;
|
|
190
|
+
if (interleaved) {
|
|
191
|
+
// Ch1, Ch2, Ch1, Ch2, ...
|
|
192
|
+
offset = (i * inputChannelCount + ch) * sizeof(int16_t);
|
|
193
|
+
} else {
|
|
194
|
+
// Ch1, Ch1, Ch1, ..., Ch2, Ch2, Ch2, ...
|
|
195
|
+
offset = (ch * numFramesDecoded + i) * sizeof(int16_t);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
channelData[i] = uint8ToFloat(uint8Data[offset], uint8Data[offset + 1]);
|
|
199
|
+
}
|
|
195
200
|
}
|
|
196
|
-
|
|
197
|
-
return audioBus;
|
|
201
|
+
return std::make_shared<AudioBuffer>(audioBus);
|
|
198
202
|
}
|
|
199
203
|
|
|
200
204
|
} // namespace audioapi
|
|
@@ -26,6 +26,7 @@ class AudioAPIModule(
|
|
|
26
26
|
private val mHybridData: HybridData
|
|
27
27
|
|
|
28
28
|
external fun initHybrid(
|
|
29
|
+
workletsModule: Any?,
|
|
29
30
|
jsContext: Long,
|
|
30
31
|
callInvoker: CallInvokerHolderImpl,
|
|
31
32
|
): HybridData
|
|
@@ -41,7 +42,16 @@ class AudioAPIModule(
|
|
|
41
42
|
try {
|
|
42
43
|
System.loadLibrary("react-native-audio-api")
|
|
43
44
|
val jsCallInvokerHolder = reactContext.jsCallInvokerHolder as CallInvokerHolderImpl
|
|
44
|
-
|
|
45
|
+
|
|
46
|
+
var workletsModule: Any? = null
|
|
47
|
+
if (BuildConfig.RN_AUDIO_API_ENABLE_WORKLETS) {
|
|
48
|
+
try {
|
|
49
|
+
workletsModule = reactContext.getNativeModule("WorkletsModule")
|
|
50
|
+
} catch (ex: Exception) {
|
|
51
|
+
throw RuntimeException("WorkletsModule not found - make sure react-native-worklets is properly installed")
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
mHybridData = initHybrid(workletsModule, reactContext.javaScriptContextHolder!!.get(), jsCallInvokerHolder)
|
|
45
55
|
} catch (exception: UnsatisfiedLinkError) {
|
|
46
56
|
throw RuntimeException("Could not load native module AudioAPIModule", exception)
|
|
47
57
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
package com.swmansion.audioapi.core
|
|
2
|
+
|
|
3
|
+
import com.facebook.common.internal.DoNotStrip
|
|
4
|
+
import com.swmansion.audioapi.system.MediaSessionManager
|
|
5
|
+
|
|
6
|
+
@DoNotStrip
|
|
7
|
+
class NativeAudioRecorder {
|
|
8
|
+
private var inputNodeId: String? = null
|
|
9
|
+
|
|
10
|
+
@DoNotStrip
|
|
11
|
+
fun start() {
|
|
12
|
+
this.inputNodeId = MediaSessionManager.attachAudioRecorder(this)
|
|
13
|
+
MediaSessionManager.startForegroundServiceIfNecessary()
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
@DoNotStrip
|
|
17
|
+
fun stop() {
|
|
18
|
+
this.inputNodeId?.let {
|
|
19
|
+
MediaSessionManager.detachAudioRecorder(it)
|
|
20
|
+
this.inputNodeId = null
|
|
21
|
+
}
|
|
22
|
+
MediaSessionManager.stopForegroundServiceIfNecessary()
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -21,6 +21,7 @@ import com.facebook.react.modules.core.PermissionAwareActivity
|
|
|
21
21
|
import com.facebook.react.modules.core.PermissionListener
|
|
22
22
|
import com.swmansion.audioapi.AudioAPIModule
|
|
23
23
|
import com.swmansion.audioapi.core.NativeAudioPlayer
|
|
24
|
+
import com.swmansion.audioapi.core.NativeAudioRecorder
|
|
24
25
|
import com.swmansion.audioapi.system.PermissionRequestListener.Companion.RECORDING_REQUEST_CODE
|
|
25
26
|
import java.lang.ref.WeakReference
|
|
26
27
|
import java.util.UUID
|
|
@@ -42,6 +43,7 @@ object MediaSessionManager {
|
|
|
42
43
|
private var isServiceRunning = false
|
|
43
44
|
private val serviceStateLock = Any()
|
|
44
45
|
private val nativeAudioPlayers = mutableMapOf<String, NativeAudioPlayer>()
|
|
46
|
+
private val nativeAudioRecorders = mutableMapOf<String, NativeAudioRecorder>()
|
|
45
47
|
|
|
46
48
|
fun initialize(
|
|
47
49
|
audioAPIModule: WeakReference<AudioAPIModule>,
|
|
@@ -95,14 +97,25 @@ object MediaSessionManager {
|
|
|
95
97
|
nativeAudioPlayers.remove(uuid)
|
|
96
98
|
}
|
|
97
99
|
|
|
100
|
+
fun attachAudioRecorder(recorder: NativeAudioRecorder): String {
|
|
101
|
+
val uuid = UUID.randomUUID().toString()
|
|
102
|
+
nativeAudioRecorders[uuid] = recorder
|
|
103
|
+
|
|
104
|
+
return uuid
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
fun detachAudioRecorder(uuid: String) {
|
|
108
|
+
nativeAudioRecorders.remove(uuid)
|
|
109
|
+
}
|
|
110
|
+
|
|
98
111
|
fun startForegroundServiceIfNecessary() {
|
|
99
|
-
if (nativeAudioPlayers.isNotEmpty()) {
|
|
112
|
+
if (nativeAudioPlayers.isNotEmpty() || nativeAudioRecorders.isNotEmpty()) {
|
|
100
113
|
startForegroundService()
|
|
101
114
|
}
|
|
102
115
|
}
|
|
103
116
|
|
|
104
117
|
fun stopForegroundServiceIfNecessary() {
|
|
105
|
-
if (nativeAudioPlayers.isEmpty()) {
|
|
118
|
+
if (nativeAudioPlayers.isEmpty() && nativeAudioRecorders.isEmpty()) {
|
|
106
119
|
stopForegroundService()
|
|
107
120
|
}
|
|
108
121
|
}
|
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
#pragma once
|
|
2
2
|
|
|
3
|
-
#include <audioapi/
|
|
3
|
+
#include <audioapi/HostObjects/AudioContextHostObject.h>
|
|
4
|
+
#include <audioapi/HostObjects/OfflineAudioContextHostObject.h>
|
|
5
|
+
#include <audioapi/HostObjects/inputs/AudioRecorderHostObject.h>
|
|
6
|
+
#include <audioapi/HostObjects/utils/AudioDecoderHostObject.h>
|
|
4
7
|
#include <audioapi/core/AudioContext.h>
|
|
5
8
|
#include <audioapi/core/OfflineAudioContext.h>
|
|
6
9
|
#include <audioapi/core/inputs/AudioRecorder.h>
|
|
7
|
-
#include <audioapi/
|
|
8
|
-
#include <audioapi/HostObjects/OfflineAudioContextHostObject.h>
|
|
9
|
-
#include <audioapi/HostObjects/AudioRecorderHostObject.h>
|
|
10
|
+
#include <audioapi/jsi/JsiPromise.h>
|
|
10
11
|
|
|
12
|
+
#include <audioapi/HostObjects/events/AudioEventHandlerRegistryHostObject.h>
|
|
11
13
|
#include <audioapi/events/AudioEventHandlerRegistry.h>
|
|
12
|
-
|
|
14
|
+
|
|
15
|
+
#include <audioapi/core/utils/worklets/SafeIncludes.h>
|
|
13
16
|
|
|
14
17
|
#include <memory>
|
|
15
18
|
|
|
@@ -19,26 +22,52 @@ using namespace facebook;
|
|
|
19
22
|
|
|
20
23
|
class AudioAPIModuleInstaller {
|
|
21
24
|
public:
|
|
22
|
-
static void injectJSIBindings(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
25
|
+
static void injectJSIBindings(
|
|
26
|
+
jsi::Runtime *jsiRuntime,
|
|
27
|
+
const std::shared_ptr<react::CallInvoker> &jsCallInvoker,
|
|
28
|
+
const std::shared_ptr<AudioEventHandlerRegistry>
|
|
29
|
+
&audioEventHandlerRegistry,
|
|
30
|
+
std::shared_ptr<worklets::WorkletRuntime> uiRuntime = nullptr) {
|
|
31
|
+
auto createAudioContext = getCreateAudioContextFunction(
|
|
32
|
+
jsiRuntime, jsCallInvoker, audioEventHandlerRegistry, uiRuntime);
|
|
33
|
+
auto createAudioRecorder =
|
|
34
|
+
getCreateAudioRecorderFunction(jsiRuntime, audioEventHandlerRegistry);
|
|
35
|
+
auto createOfflineAudioContext = getCreateOfflineAudioContextFunction(
|
|
36
|
+
jsiRuntime, jsCallInvoker, audioEventHandlerRegistry, uiRuntime);
|
|
37
|
+
auto createAudioDecoder =
|
|
38
|
+
getCreateAudioDecoderFunction(jsiRuntime, jsCallInvoker);
|
|
39
|
+
|
|
40
|
+
jsiRuntime->global().setProperty(
|
|
41
|
+
*jsiRuntime, "createAudioContext", createAudioContext);
|
|
42
|
+
jsiRuntime->global().setProperty(
|
|
43
|
+
*jsiRuntime, "createAudioRecorder", createAudioRecorder);
|
|
44
|
+
jsiRuntime->global().setProperty(
|
|
45
|
+
*jsiRuntime, "createOfflineAudioContext", createOfflineAudioContext);
|
|
46
|
+
jsiRuntime->global().setProperty(
|
|
47
|
+
*jsiRuntime, "createAudioDecoder", createAudioDecoder);
|
|
48
|
+
|
|
49
|
+
auto audioEventHandlerRegistryHostObject =
|
|
50
|
+
std::make_shared<AudioEventHandlerRegistryHostObject>(
|
|
51
|
+
audioEventHandlerRegistry);
|
|
52
|
+
jsiRuntime->global().setProperty(
|
|
53
|
+
*jsiRuntime,
|
|
54
|
+
"AudioEventEmitter",
|
|
55
|
+
jsi::Object::createFromHostObject(
|
|
56
|
+
*jsiRuntime, audioEventHandlerRegistryHostObject));
|
|
33
57
|
}
|
|
34
58
|
|
|
35
59
|
private:
|
|
36
|
-
static jsi::Function getCreateAudioContextFunction(
|
|
60
|
+
static jsi::Function getCreateAudioContextFunction(
|
|
61
|
+
jsi::Runtime *jsiRuntime,
|
|
62
|
+
const std::shared_ptr<react::CallInvoker> &jsCallInvoker,
|
|
63
|
+
const std::shared_ptr<AudioEventHandlerRegistry>
|
|
64
|
+
&audioEventHandlerRegistry,
|
|
65
|
+
const std::weak_ptr<worklets::WorkletRuntime> &uiRuntime) {
|
|
37
66
|
return jsi::Function::createFromHostFunction(
|
|
38
67
|
*jsiRuntime,
|
|
39
68
|
jsi::PropNameID::forAscii(*jsiRuntime, "createAudioContext"),
|
|
40
69
|
0,
|
|
41
|
-
[jsCallInvoker, audioEventHandlerRegistry](
|
|
70
|
+
[jsCallInvoker, audioEventHandlerRegistry, uiRuntime](
|
|
42
71
|
jsi::Runtime &runtime,
|
|
43
72
|
const jsi::Value &thisValue,
|
|
44
73
|
const jsi::Value *args,
|
|
@@ -46,40 +75,77 @@ class AudioAPIModuleInstaller {
|
|
|
46
75
|
std::shared_ptr<AudioContext> audioContext;
|
|
47
76
|
auto sampleRate = static_cast<float>(args[0].getNumber());
|
|
48
77
|
auto initSuspended = args[1].getBool();
|
|
49
|
-
audioContext = std::make_shared<AudioContext>(sampleRate, initSuspended, audioEventHandlerRegistry);
|
|
50
78
|
|
|
51
|
-
|
|
52
|
-
|
|
79
|
+
#if RN_AUDIO_API_ENABLE_WORKLETS
|
|
80
|
+
auto runtimeRegistry = RuntimeRegistry{
|
|
81
|
+
.uiRuntime = uiRuntime,
|
|
82
|
+
.audioRuntime = worklets::extractWorkletRuntime(runtime, args[2])
|
|
83
|
+
};
|
|
84
|
+
#else
|
|
85
|
+
auto runtimeRegistry = RuntimeRegistry{};
|
|
86
|
+
#endif
|
|
87
|
+
|
|
88
|
+
audioContext = std::make_shared<AudioContext>(
|
|
89
|
+
sampleRate,
|
|
90
|
+
initSuspended,
|
|
91
|
+
audioEventHandlerRegistry,
|
|
92
|
+
runtimeRegistry);
|
|
93
|
+
auto audioContextHostObject =
|
|
94
|
+
std::make_shared<AudioContextHostObject>(
|
|
95
|
+
audioContext, &runtime, jsCallInvoker);
|
|
53
96
|
|
|
54
97
|
return jsi::Object::createFromHostObject(
|
|
55
98
|
runtime, audioContextHostObject);
|
|
56
99
|
});
|
|
57
100
|
}
|
|
58
101
|
|
|
59
|
-
static jsi::Function getCreateOfflineAudioContextFunction(
|
|
102
|
+
static jsi::Function getCreateOfflineAudioContextFunction(
|
|
103
|
+
jsi::Runtime *jsiRuntime,
|
|
104
|
+
const std::shared_ptr<react::CallInvoker> &jsCallInvoker,
|
|
105
|
+
const std::shared_ptr<AudioEventHandlerRegistry>
|
|
106
|
+
&audioEventHandlerRegistry,
|
|
107
|
+
const std::weak_ptr<worklets::WorkletRuntime> &uiRuntime) {
|
|
60
108
|
return jsi::Function::createFromHostFunction(
|
|
61
109
|
*jsiRuntime,
|
|
62
110
|
jsi::PropNameID::forAscii(*jsiRuntime, "createOfflineAudioContext"),
|
|
63
111
|
0,
|
|
64
|
-
[jsCallInvoker, audioEventHandlerRegistry](
|
|
112
|
+
[jsCallInvoker, audioEventHandlerRegistry, uiRuntime](
|
|
65
113
|
jsi::Runtime &runtime,
|
|
66
114
|
const jsi::Value &thisValue,
|
|
67
115
|
const jsi::Value *args,
|
|
68
116
|
size_t count) -> jsi::Value {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
117
|
+
auto numberOfChannels = static_cast<int>(args[0].getNumber());
|
|
118
|
+
auto length = static_cast<size_t>(args[1].getNumber());
|
|
119
|
+
auto sampleRate = static_cast<float>(args[2].getNumber());
|
|
120
|
+
|
|
121
|
+
#if RN_AUDIO_API_ENABLE_WORKLETS
|
|
122
|
+
auto runtimeRegistry = RuntimeRegistry{
|
|
123
|
+
.uiRuntime = uiRuntime,
|
|
124
|
+
.audioRuntime = worklets::extractWorkletRuntime(runtime, args[3])
|
|
125
|
+
};
|
|
126
|
+
#else
|
|
127
|
+
auto runtimeRegistry = RuntimeRegistry{};
|
|
128
|
+
#endif
|
|
129
|
+
|
|
130
|
+
auto offlineAudioContext = std::make_shared<OfflineAudioContext>(
|
|
131
|
+
numberOfChannels,
|
|
132
|
+
length,
|
|
133
|
+
sampleRate,
|
|
134
|
+
audioEventHandlerRegistry,
|
|
135
|
+
runtimeRegistry);
|
|
136
|
+
auto audioContextHostObject =
|
|
137
|
+
std::make_shared<OfflineAudioContextHostObject>(
|
|
138
|
+
offlineAudioContext, &runtime, jsCallInvoker);
|
|
139
|
+
|
|
140
|
+
return jsi::Object::createFromHostObject(
|
|
141
|
+
runtime, audioContextHostObject);
|
|
79
142
|
});
|
|
80
143
|
}
|
|
81
144
|
|
|
82
|
-
static jsi::Function getCreateAudioRecorderFunction(
|
|
145
|
+
static jsi::Function getCreateAudioRecorderFunction(
|
|
146
|
+
jsi::Runtime *jsiRuntime,
|
|
147
|
+
const std::shared_ptr<AudioEventHandlerRegistry>
|
|
148
|
+
&audioEventHandlerRegistry) {
|
|
83
149
|
return jsi::Function::createFromHostFunction(
|
|
84
150
|
*jsiRuntime,
|
|
85
151
|
jsi::PropNameID::forAscii(*jsiRuntime, "createAudioRecorder"),
|
|
@@ -91,12 +157,37 @@ class AudioAPIModuleInstaller {
|
|
|
91
157
|
size_t count) -> jsi::Value {
|
|
92
158
|
auto options = args[0].getObject(runtime);
|
|
93
159
|
|
|
94
|
-
auto sampleRate = static_cast<float>(
|
|
95
|
-
|
|
160
|
+
auto sampleRate = static_cast<float>(
|
|
161
|
+
options.getProperty(runtime, "sampleRate").getNumber());
|
|
162
|
+
auto bufferLength = static_cast<int>(
|
|
163
|
+
options.getProperty(runtime, "bufferLengthInSamples")
|
|
164
|
+
.getNumber());
|
|
96
165
|
|
|
97
|
-
auto audioRecorderHostObject =
|
|
166
|
+
auto audioRecorderHostObject =
|
|
167
|
+
std::make_shared<AudioRecorderHostObject>(
|
|
168
|
+
audioEventHandlerRegistry, sampleRate, bufferLength);
|
|
98
169
|
|
|
99
|
-
return jsi::Object::createFromHostObject(
|
|
170
|
+
return jsi::Object::createFromHostObject(
|
|
171
|
+
runtime, audioRecorderHostObject);
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
static jsi::Function getCreateAudioDecoderFunction(
|
|
176
|
+
jsi::Runtime *jsiRuntime,
|
|
177
|
+
const std::shared_ptr<react::CallInvoker> &jsCallInvoker) {
|
|
178
|
+
return jsi::Function::createFromHostFunction(
|
|
179
|
+
*jsiRuntime,
|
|
180
|
+
jsi::PropNameID::forAscii(*jsiRuntime, "createAudioDecoder"),
|
|
181
|
+
0,
|
|
182
|
+
[jsCallInvoker](
|
|
183
|
+
jsi::Runtime &runtime,
|
|
184
|
+
const jsi::Value &thisValue,
|
|
185
|
+
const jsi::Value *args,
|
|
186
|
+
size_t count) -> jsi::Value {
|
|
187
|
+
auto audioDecoderHostObject =
|
|
188
|
+
std::make_shared<AudioDecoderHostObject>(&runtime, jsCallInvoker);
|
|
189
|
+
return jsi::Object::createFromHostObject(
|
|
190
|
+
runtime, audioDecoderHostObject);
|
|
100
191
|
});
|
|
101
192
|
}
|
|
102
193
|
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
#include <audioapi/HostObjects/AudioContextHostObject.h>
|
|
2
|
+
|
|
3
|
+
#include <audioapi/core/AudioContext.h>
|
|
4
|
+
|
|
5
|
+
namespace audioapi {
|
|
6
|
+
|
|
7
|
+
AudioContextHostObject::AudioContextHostObject(
|
|
8
|
+
const std::shared_ptr<AudioContext> &audioContext,
|
|
9
|
+
jsi::Runtime *runtime,
|
|
10
|
+
const std::shared_ptr<react::CallInvoker> &callInvoker)
|
|
11
|
+
: BaseAudioContextHostObject(audioContext, runtime, callInvoker) {
|
|
12
|
+
addFunctions(
|
|
13
|
+
JSI_EXPORT_FUNCTION(AudioContextHostObject, close),
|
|
14
|
+
JSI_EXPORT_FUNCTION(AudioContextHostObject, resume),
|
|
15
|
+
JSI_EXPORT_FUNCTION(AudioContextHostObject, suspend));
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
JSI_HOST_FUNCTION_IMPL(AudioContextHostObject, close) {
|
|
19
|
+
auto audioContext = std::static_pointer_cast<AudioContext>(context_);
|
|
20
|
+
auto promise = promiseVendor_->createPromise(
|
|
21
|
+
[audioContext](const std::shared_ptr<Promise> &promise) {
|
|
22
|
+
audioContext->close();
|
|
23
|
+
|
|
24
|
+
promise->resolve(
|
|
25
|
+
[](jsi::Runtime &runtime) { return jsi::Value::undefined(); });
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
return promise;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
JSI_HOST_FUNCTION_IMPL(AudioContextHostObject, resume) {
|
|
32
|
+
auto audioContext = std::static_pointer_cast<AudioContext>(context_);
|
|
33
|
+
auto promise = promiseVendor_->createPromise(
|
|
34
|
+
[audioContext](const std::shared_ptr<Promise> &promise) {
|
|
35
|
+
auto result = audioContext->resume();
|
|
36
|
+
|
|
37
|
+
promise->resolve(
|
|
38
|
+
[result](jsi::Runtime &runtime) { return jsi::Value(result); });
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
return promise;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
JSI_HOST_FUNCTION_IMPL(AudioContextHostObject, suspend) {
|
|
45
|
+
auto audioContext = std::static_pointer_cast<AudioContext>(context_);
|
|
46
|
+
auto promise = promiseVendor_->createPromise(
|
|
47
|
+
[audioContext](const std::shared_ptr<Promise> &promise) {
|
|
48
|
+
auto result = audioContext->suspend();
|
|
49
|
+
|
|
50
|
+
promise->resolve(
|
|
51
|
+
[result](jsi::Runtime &runtime) { return jsi::Value(result); });
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
return promise;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
} // namespace audioapi
|