react-native-audio-api 0.8.3 → 0.9.0-nightly-7ecb495-20251008
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 +154 -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 +133 -0
- package/common/cpp/audioapi/HostObjects/utils/AudioDecoderHostObject.h +28 -0
- package/common/cpp/audioapi/HostObjects/utils/AudioStretcherHostObject.cpp +58 -0
- package/common/cpp/audioapi/HostObjects/utils/AudioStretcherHostObject.h +26 -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 -91
- package/common/cpp/audioapi/core/{AudioParamEventQueue.cpp → utils/AudioParamEventQueue.cpp} +13 -7
- package/common/cpp/audioapi/core/utils/AudioStretcher.cpp +75 -0
- package/common/cpp/audioapi/core/utils/AudioStretcher.h +30 -0
- package/common/cpp/audioapi/core/{Constants.h → utils/Constants.h} +9 -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 +57 -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/AudioStretcher.js +31 -0
- package/lib/commonjs/core/AudioStretcher.js.map +1 -0
- 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 +9 -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/AudioStretcher.js +26 -0
- package/lib/module/core/AudioStretcher.js.map +1 -0
- 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 +13 -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/AudioStretcher.d.ts +3 -0
- package/lib/typescript/core/AudioStretcher.d.ts.map +1 -0
- 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 +31 -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 +22 -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/AudioStretcher.ts +43 -0
- 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 +85 -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
|
@@ -10,7 +10,7 @@ export default class AudioScheduledSourceNode extends AudioNode {
|
|
|
10
10
|
global.AudioEventEmitter
|
|
11
11
|
);
|
|
12
12
|
|
|
13
|
-
private
|
|
13
|
+
private onEndedSubscription?: AudioEventSubscription;
|
|
14
14
|
private onEndedCallback?: (event: OnEndedEventType) => void;
|
|
15
15
|
|
|
16
16
|
public start(when: number = 0): void {
|
|
@@ -51,19 +51,19 @@ export default class AudioScheduledSourceNode extends AudioNode {
|
|
|
51
51
|
public set onEnded(callback: ((event: OnEndedEventType) => void) | null) {
|
|
52
52
|
if (!callback) {
|
|
53
53
|
(this.node as IAudioScheduledSourceNode).onEnded = '0';
|
|
54
|
-
this.
|
|
55
|
-
this.
|
|
54
|
+
this.onEndedSubscription?.remove();
|
|
55
|
+
this.onEndedSubscription = undefined;
|
|
56
56
|
this.onEndedCallback = undefined;
|
|
57
57
|
return;
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
this.onEndedCallback = callback;
|
|
61
|
-
this.
|
|
61
|
+
this.onEndedSubscription = this.audioEventEmitter.addAudioEventListener(
|
|
62
62
|
'ended',
|
|
63
63
|
callback
|
|
64
64
|
);
|
|
65
65
|
|
|
66
66
|
(this.node as IAudioScheduledSourceNode).onEnded =
|
|
67
|
-
this.
|
|
67
|
+
this.onEndedSubscription.subscriptionId;
|
|
68
68
|
}
|
|
69
69
|
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { IAudioStretcher } from '../interfaces';
|
|
2
|
+
import AudioBuffer from './AudioBuffer';
|
|
3
|
+
|
|
4
|
+
class AudioStretcher {
|
|
5
|
+
private static instance: AudioStretcher | null = null;
|
|
6
|
+
protected readonly stretcher: IAudioStretcher;
|
|
7
|
+
|
|
8
|
+
private constructor() {
|
|
9
|
+
this.stretcher = global.createAudioStretcher();
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
public static getInstance(): AudioStretcher {
|
|
13
|
+
if (!AudioStretcher.instance) {
|
|
14
|
+
AudioStretcher.instance = new AudioStretcher();
|
|
15
|
+
}
|
|
16
|
+
return AudioStretcher.instance;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public async changePlaybackSpeedInstance(
|
|
20
|
+
input: AudioBuffer,
|
|
21
|
+
playbackSpeed: number
|
|
22
|
+
): Promise<AudioBuffer> {
|
|
23
|
+
const buffer = await this.stretcher.changePlaybackSpeed(
|
|
24
|
+
input.buffer,
|
|
25
|
+
playbackSpeed
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
if (!buffer) {
|
|
29
|
+
throw new Error('Failed to change playback speed');
|
|
30
|
+
}
|
|
31
|
+
return new AudioBuffer(buffer);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export default async function changePlaybackSpeed(
|
|
36
|
+
input: AudioBuffer,
|
|
37
|
+
playbackSpeed: number
|
|
38
|
+
): Promise<AudioBuffer> {
|
|
39
|
+
return AudioStretcher.getInstance().changePlaybackSpeedInstance(
|
|
40
|
+
input,
|
|
41
|
+
playbackSpeed
|
|
42
|
+
);
|
|
43
|
+
}
|
|
@@ -1,22 +1,29 @@
|
|
|
1
|
+
import { InvalidAccessError, NotSupportedError } from '../errors';
|
|
1
2
|
import { IBaseAudioContext } from '../interfaces';
|
|
2
3
|
import {
|
|
4
|
+
AudioBufferBaseSourceNodeOptions,
|
|
3
5
|
ContextState,
|
|
4
6
|
PeriodicWaveConstraints,
|
|
5
|
-
|
|
7
|
+
AudioWorkletRuntime,
|
|
6
8
|
} from '../types';
|
|
9
|
+
import { isWorkletsAvailable, workletsModule } from '../utils';
|
|
10
|
+
import WorkletSourceNode from './WorkletSourceNode';
|
|
11
|
+
import WorkletProcessingNode from './WorkletProcessingNode';
|
|
12
|
+
import AnalyserNode from './AnalyserNode';
|
|
13
|
+
import AudioBuffer from './AudioBuffer';
|
|
14
|
+
import AudioBufferQueueSourceNode from './AudioBufferQueueSourceNode';
|
|
15
|
+
import AudioBufferSourceNode from './AudioBufferSourceNode';
|
|
7
16
|
import AudioDestinationNode from './AudioDestinationNode';
|
|
8
|
-
import OscillatorNode from './OscillatorNode';
|
|
9
|
-
import GainNode from './GainNode';
|
|
10
|
-
import StereoPannerNode from './StereoPannerNode';
|
|
11
17
|
import BiquadFilterNode from './BiquadFilterNode';
|
|
12
|
-
import
|
|
13
|
-
import
|
|
18
|
+
import ConstantSourceNode from './ConstantSourceNode';
|
|
19
|
+
import GainNode from './GainNode';
|
|
20
|
+
import OscillatorNode from './OscillatorNode';
|
|
14
21
|
import PeriodicWave from './PeriodicWave';
|
|
15
|
-
import AnalyserNode from './AnalyserNode';
|
|
16
|
-
import AudioBufferQueueSourceNode from './AudioBufferQueueSourceNode';
|
|
17
|
-
import StreamerNode from './StreamerNode';
|
|
18
|
-
import { InvalidAccessError, NotSupportedError } from '../errors';
|
|
19
22
|
import RecorderAdapterNode from './RecorderAdapterNode';
|
|
23
|
+
import StereoPannerNode from './StereoPannerNode';
|
|
24
|
+
import StreamerNode from './StreamerNode';
|
|
25
|
+
import WorkletNode from './WorkletNode';
|
|
26
|
+
import { decodeAudioData, decodePCMInBase64 } from './AudioDecoder';
|
|
20
27
|
|
|
21
28
|
export default class BaseAudioContext {
|
|
22
29
|
readonly destination: AudioDestinationNode;
|
|
@@ -37,6 +44,152 @@ export default class BaseAudioContext {
|
|
|
37
44
|
return this.context.state;
|
|
38
45
|
}
|
|
39
46
|
|
|
47
|
+
public async decodeAudioData(
|
|
48
|
+
input: string | ArrayBuffer,
|
|
49
|
+
sampleRate?: number
|
|
50
|
+
): Promise<AudioBuffer> {
|
|
51
|
+
if (!(typeof input === 'string' || input instanceof ArrayBuffer)) {
|
|
52
|
+
throw new TypeError('Input must be a string or ArrayBuffer');
|
|
53
|
+
}
|
|
54
|
+
return await decodeAudioData(input, sampleRate ?? this.sampleRate);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
public async decodePCMInBase64(
|
|
58
|
+
base64String: string,
|
|
59
|
+
inputSampleRate: number,
|
|
60
|
+
inputChannelCount: number,
|
|
61
|
+
isInterleaved: boolean = true
|
|
62
|
+
): Promise<AudioBuffer> {
|
|
63
|
+
return await decodePCMInBase64(
|
|
64
|
+
base64String,
|
|
65
|
+
inputSampleRate,
|
|
66
|
+
inputChannelCount,
|
|
67
|
+
isInterleaved
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
createWorkletNode(
|
|
72
|
+
callback: (audioData: Array<Float32Array>, channelCount: number) => void,
|
|
73
|
+
bufferLength: number,
|
|
74
|
+
inputChannelCount: number,
|
|
75
|
+
workletRuntime: AudioWorkletRuntime = 'AudioRuntime'
|
|
76
|
+
): WorkletNode {
|
|
77
|
+
if (inputChannelCount < 1 || inputChannelCount > 32) {
|
|
78
|
+
throw new NotSupportedError(
|
|
79
|
+
`The number of input channels provided (${inputChannelCount}) can not be less than 1 or greater than 32`
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
if (bufferLength < 1) {
|
|
83
|
+
throw new NotSupportedError(
|
|
84
|
+
`The buffer length provided (${bufferLength}) can not be less than 1`
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (isWorkletsAvailable) {
|
|
89
|
+
const shareableWorklet = workletsModule.makeShareableCloneRecursive(
|
|
90
|
+
(audioBuffers: Array<ArrayBuffer>, channelCount: number) => {
|
|
91
|
+
'worklet';
|
|
92
|
+
const floatAudioData: Array<Float32Array> = audioBuffers.map(
|
|
93
|
+
(buffer) => new Float32Array(buffer)
|
|
94
|
+
);
|
|
95
|
+
callback(floatAudioData, channelCount);
|
|
96
|
+
}
|
|
97
|
+
);
|
|
98
|
+
return new WorkletNode(
|
|
99
|
+
this,
|
|
100
|
+
this.context.createWorkletNode(
|
|
101
|
+
shareableWorklet,
|
|
102
|
+
workletRuntime === 'UIRuntime',
|
|
103
|
+
bufferLength,
|
|
104
|
+
inputChannelCount
|
|
105
|
+
)
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
/// User does not have worklets as a dependency so he cannot use the worklet API.
|
|
109
|
+
throw new Error(
|
|
110
|
+
'[RnAudioApi] Worklets are not available, please install react-native-worklets as a dependency. Refer to documentation for more details.'
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
createWorkletProcessingNode(
|
|
115
|
+
callback: (
|
|
116
|
+
inputData: Array<Float32Array>,
|
|
117
|
+
outputData: Array<Float32Array>,
|
|
118
|
+
framesToProcess: number,
|
|
119
|
+
currentTime: number
|
|
120
|
+
) => void,
|
|
121
|
+
workletRuntime: AudioWorkletRuntime = 'AudioRuntime'
|
|
122
|
+
): WorkletProcessingNode {
|
|
123
|
+
if (isWorkletsAvailable) {
|
|
124
|
+
const shareableWorklet = workletsModule.makeShareableCloneRecursive(
|
|
125
|
+
(
|
|
126
|
+
inputBuffers: Array<ArrayBuffer>,
|
|
127
|
+
outputBuffers: Array<ArrayBuffer>,
|
|
128
|
+
framesToProcess: number,
|
|
129
|
+
currentTime: number
|
|
130
|
+
) => {
|
|
131
|
+
'worklet';
|
|
132
|
+
const inputData: Array<Float32Array> = inputBuffers.map(
|
|
133
|
+
(buffer) => new Float32Array(buffer, 0, framesToProcess)
|
|
134
|
+
);
|
|
135
|
+
const outputData: Array<Float32Array> = outputBuffers.map(
|
|
136
|
+
(buffer) => new Float32Array(buffer, 0, framesToProcess)
|
|
137
|
+
);
|
|
138
|
+
callback(inputData, outputData, framesToProcess, currentTime);
|
|
139
|
+
}
|
|
140
|
+
);
|
|
141
|
+
return new WorkletProcessingNode(
|
|
142
|
+
this,
|
|
143
|
+
this.context.createWorkletProcessingNode(
|
|
144
|
+
shareableWorklet,
|
|
145
|
+
workletRuntime === 'UIRuntime'
|
|
146
|
+
)
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
/// User does not have worklets as a dependency so he cannot use the worklet API.
|
|
150
|
+
throw new Error(
|
|
151
|
+
'[RnAudioApi] Worklets are not available, please install react-native-worklets as a dependency. Refer to documentation for more details.'
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
createWorkletSourceNode(
|
|
156
|
+
callback: (
|
|
157
|
+
audioData: Array<Float32Array>,
|
|
158
|
+
framesToProcess: number,
|
|
159
|
+
currentTime: number,
|
|
160
|
+
startOffset: number
|
|
161
|
+
) => void,
|
|
162
|
+
workletRuntime: AudioWorkletRuntime = 'AudioRuntime'
|
|
163
|
+
): WorkletSourceNode {
|
|
164
|
+
if (!isWorkletsAvailable) {
|
|
165
|
+
/// User does not have worklets as a dependency so he cannot use the worklet API.
|
|
166
|
+
throw new Error(
|
|
167
|
+
'[RnAudioApi] Worklets are not available, please install react-native-worklets as a dependency. Refer to documentation for more details.'
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
const shareableWorklet = workletsModule.makeShareableCloneRecursive(
|
|
171
|
+
(
|
|
172
|
+
audioBuffers: Array<ArrayBuffer>,
|
|
173
|
+
framesToProcess: number,
|
|
174
|
+
currentTime: number,
|
|
175
|
+
startOffset: number
|
|
176
|
+
) => {
|
|
177
|
+
'worklet';
|
|
178
|
+
const floatAudioData: Array<Float32Array> = audioBuffers.map(
|
|
179
|
+
(buffer) => new Float32Array(buffer)
|
|
180
|
+
);
|
|
181
|
+
callback(floatAudioData, framesToProcess, currentTime, startOffset);
|
|
182
|
+
}
|
|
183
|
+
);
|
|
184
|
+
return new WorkletSourceNode(
|
|
185
|
+
this,
|
|
186
|
+
this.context.createWorkletSourceNode(
|
|
187
|
+
shareableWorklet,
|
|
188
|
+
workletRuntime === 'UIRuntime'
|
|
189
|
+
)
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
|
|
40
193
|
createRecorderAdapter(): RecorderAdapterNode {
|
|
41
194
|
return new RecorderAdapterNode(this, this.context.createRecorderAdapter());
|
|
42
195
|
}
|
|
@@ -49,6 +202,10 @@ export default class BaseAudioContext {
|
|
|
49
202
|
return new StreamerNode(this, this.context.createStreamer());
|
|
50
203
|
}
|
|
51
204
|
|
|
205
|
+
createConstantSource(): ConstantSourceNode {
|
|
206
|
+
return new ConstantSourceNode(this, this.context.createConstantSource());
|
|
207
|
+
}
|
|
208
|
+
|
|
52
209
|
createGain(): GainNode {
|
|
53
210
|
return new GainNode(this, this.context.createGain());
|
|
54
211
|
}
|
|
@@ -62,7 +219,7 @@ export default class BaseAudioContext {
|
|
|
62
219
|
}
|
|
63
220
|
|
|
64
221
|
createBufferSource(
|
|
65
|
-
options?:
|
|
222
|
+
options?: AudioBufferBaseSourceNodeOptions
|
|
66
223
|
): AudioBufferSourceNode {
|
|
67
224
|
const pitchCorrection = options?.pitchCorrection ?? false;
|
|
68
225
|
|
|
@@ -72,10 +229,14 @@ export default class BaseAudioContext {
|
|
|
72
229
|
);
|
|
73
230
|
}
|
|
74
231
|
|
|
75
|
-
createBufferQueueSource(
|
|
232
|
+
createBufferQueueSource(
|
|
233
|
+
options?: AudioBufferBaseSourceNodeOptions
|
|
234
|
+
): AudioBufferQueueSourceNode {
|
|
235
|
+
const pitchCorrection = options?.pitchCorrection ?? false;
|
|
236
|
+
|
|
76
237
|
return new AudioBufferQueueSourceNode(
|
|
77
238
|
this,
|
|
78
|
-
this.context.createBufferQueueSource()
|
|
239
|
+
this.context.createBufferQueueSource(pitchCorrection)
|
|
79
240
|
);
|
|
80
241
|
}
|
|
81
242
|
|
|
@@ -128,32 +289,4 @@ export default class BaseAudioContext {
|
|
|
128
289
|
createAnalyser(): AnalyserNode {
|
|
129
290
|
return new AnalyserNode(this, this.context.createAnalyser());
|
|
130
291
|
}
|
|
131
|
-
|
|
132
|
-
/** Decodes audio data from a local file path. */
|
|
133
|
-
async decodeAudioDataSource(sourcePath: string): Promise<AudioBuffer> {
|
|
134
|
-
// Remove the file:// prefix if it exists
|
|
135
|
-
if (sourcePath.startsWith('file://')) {
|
|
136
|
-
sourcePath = sourcePath.replace('file://', '');
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
return new AudioBuffer(
|
|
140
|
-
await this.context.decodeAudioDataSource(sourcePath)
|
|
141
|
-
);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
/** Decodes audio data from an ArrayBuffer. */
|
|
145
|
-
async decodeAudioData(data: ArrayBuffer): Promise<AudioBuffer> {
|
|
146
|
-
return new AudioBuffer(
|
|
147
|
-
await this.context.decodeAudioData(new Uint8Array(data))
|
|
148
|
-
);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
async decodePCMInBase64Data(
|
|
152
|
-
base64: string,
|
|
153
|
-
playbackRate: number = 1.0
|
|
154
|
-
): Promise<AudioBuffer> {
|
|
155
|
-
return new AudioBuffer(
|
|
156
|
-
await this.context.decodePCMAudioDataInBase64(base64, playbackRate)
|
|
157
|
-
);
|
|
158
|
-
}
|
|
159
292
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { IConstantSourceNode } from '../interfaces';
|
|
2
|
+
import AudioParam from './AudioParam';
|
|
3
|
+
import AudioScheduledSourceNode from './AudioScheduledSourceNode';
|
|
4
|
+
import BaseAudioContext from './BaseAudioContext';
|
|
5
|
+
|
|
6
|
+
export default class ConstantSourceNode extends AudioScheduledSourceNode {
|
|
7
|
+
readonly offset: AudioParam;
|
|
8
|
+
|
|
9
|
+
constructor(context: BaseAudioContext, node: IConstantSourceNode) {
|
|
10
|
+
super(context, node);
|
|
11
|
+
this.offset = new AudioParam(node.offset, context);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -3,12 +3,17 @@ import BaseAudioContext from './BaseAudioContext';
|
|
|
3
3
|
import { OfflineAudioContextOptions } from '../types';
|
|
4
4
|
import { InvalidStateError, NotSupportedError } from '../errors';
|
|
5
5
|
import AudioBuffer from './AudioBuffer';
|
|
6
|
+
import { isWorkletsAvailable, workletsModule } from '../utils';
|
|
6
7
|
|
|
7
8
|
export default class OfflineAudioContext extends BaseAudioContext {
|
|
8
9
|
private isSuspended: boolean;
|
|
9
10
|
private isRendering: boolean;
|
|
10
11
|
private duration: number;
|
|
11
12
|
|
|
13
|
+
// We need to keep here a reference to this runtime to better manage its lifecycle
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any
|
|
15
|
+
private _audioRuntime: any;
|
|
16
|
+
|
|
12
17
|
constructor(options: OfflineAudioContextOptions);
|
|
13
18
|
constructor(numberOfChannels: number, length: number, sampleRate: number);
|
|
14
19
|
constructor(
|
|
@@ -16,10 +21,20 @@ export default class OfflineAudioContext extends BaseAudioContext {
|
|
|
16
21
|
arg1?: number,
|
|
17
22
|
arg2?: number
|
|
18
23
|
) {
|
|
24
|
+
let audioRuntime = null;
|
|
25
|
+
if (isWorkletsAvailable) {
|
|
26
|
+
audioRuntime = workletsModule.createWorkletRuntime('AudioWorkletRuntime');
|
|
27
|
+
}
|
|
28
|
+
|
|
19
29
|
if (typeof arg0 === 'object') {
|
|
20
30
|
const { numberOfChannels, length, sampleRate } = arg0;
|
|
21
31
|
super(
|
|
22
|
-
global.createOfflineAudioContext(
|
|
32
|
+
global.createOfflineAudioContext(
|
|
33
|
+
numberOfChannels,
|
|
34
|
+
length,
|
|
35
|
+
sampleRate,
|
|
36
|
+
audioRuntime
|
|
37
|
+
)
|
|
23
38
|
);
|
|
24
39
|
|
|
25
40
|
this.duration = length / sampleRate;
|
|
@@ -28,7 +43,7 @@ export default class OfflineAudioContext extends BaseAudioContext {
|
|
|
28
43
|
typeof arg1 === 'number' &&
|
|
29
44
|
typeof arg2 === 'number'
|
|
30
45
|
) {
|
|
31
|
-
super(global.createOfflineAudioContext(arg0, arg1, arg2));
|
|
46
|
+
super(global.createOfflineAudioContext(arg0, arg1, arg2, audioRuntime));
|
|
32
47
|
this.duration = arg1 / arg2;
|
|
33
48
|
} else {
|
|
34
49
|
throw new NotSupportedError('Invalid constructor arguments');
|
|
@@ -36,6 +51,7 @@ export default class OfflineAudioContext extends BaseAudioContext {
|
|
|
36
51
|
|
|
37
52
|
this.isSuspended = false;
|
|
38
53
|
this.isRendering = false;
|
|
54
|
+
this._audioRuntime = audioRuntime;
|
|
39
55
|
}
|
|
40
56
|
|
|
41
57
|
async resume(): Promise<undefined> {
|
|
@@ -5,6 +5,7 @@ import AudioParam from './AudioParam';
|
|
|
5
5
|
import BaseAudioContext from './BaseAudioContext';
|
|
6
6
|
import PeriodicWave from './PeriodicWave';
|
|
7
7
|
import { InvalidStateError } from '../errors';
|
|
8
|
+
import { EventEmptyType } from '../events/types';
|
|
8
9
|
|
|
9
10
|
export default class OscillatorNode extends AudioScheduledSourceNode {
|
|
10
11
|
readonly frequency: AudioParam;
|
|
@@ -34,4 +35,14 @@ export default class OscillatorNode extends AudioScheduledSourceNode {
|
|
|
34
35
|
public setPeriodicWave(wave: PeriodicWave): void {
|
|
35
36
|
(this.node as IOscillatorNode).setPeriodicWave(wave.periodicWave);
|
|
36
37
|
}
|
|
38
|
+
|
|
39
|
+
public override get onEnded(): ((event: EventEmptyType) => void) | undefined {
|
|
40
|
+
return super.onEnded as ((event: EventEmptyType) => void) | undefined;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
public override set onEnded(
|
|
44
|
+
callback: ((event: EventEmptyType) => void) | null
|
|
45
|
+
) {
|
|
46
|
+
super.onEnded = callback;
|
|
47
|
+
}
|
|
37
48
|
}
|
package/src/events/types.ts
CHANGED
|
@@ -46,6 +46,7 @@ type SystemEvents = RemoteCommandEvents & {
|
|
|
46
46
|
|
|
47
47
|
export interface OnEndedEventType extends EventEmptyType {
|
|
48
48
|
bufferId: string | undefined;
|
|
49
|
+
isLast: boolean | undefined;
|
|
49
50
|
}
|
|
50
51
|
|
|
51
52
|
export interface OnAudioReadyEventType {
|
|
@@ -56,6 +57,7 @@ export interface OnAudioReadyEventType {
|
|
|
56
57
|
|
|
57
58
|
interface AudioAPIEvents {
|
|
58
59
|
ended: OnEndedEventType;
|
|
60
|
+
loopEnded: EventEmptyType;
|
|
59
61
|
audioReady: OnAudioReadyEventType;
|
|
60
62
|
positionChanged: EventTypeWithValue;
|
|
61
63
|
audioError: EventEmptyType; // to change
|
package/src/interfaces.ts
CHANGED
|
@@ -1,26 +1,69 @@
|
|
|
1
|
+
import { AudioEventCallback, AudioEventName } from './events/types';
|
|
1
2
|
import {
|
|
2
|
-
WindowType,
|
|
3
|
-
ContextState,
|
|
4
|
-
OscillatorType,
|
|
5
3
|
BiquadFilterType,
|
|
6
4
|
ChannelCountMode,
|
|
7
5
|
ChannelInterpretation,
|
|
6
|
+
ContextState,
|
|
7
|
+
OscillatorType,
|
|
8
|
+
WindowType,
|
|
8
9
|
} from './types';
|
|
9
|
-
|
|
10
|
+
|
|
11
|
+
export type WorkletNodeCallback = (
|
|
12
|
+
audioData: Array<ArrayBuffer>,
|
|
13
|
+
channelCount: number
|
|
14
|
+
) => void;
|
|
15
|
+
|
|
16
|
+
export type WorkletSourceNodeCallback = (
|
|
17
|
+
audioData: Array<ArrayBuffer>,
|
|
18
|
+
framesToProcess: number,
|
|
19
|
+
currentTime: number,
|
|
20
|
+
startOffset: number
|
|
21
|
+
) => void;
|
|
22
|
+
|
|
23
|
+
export type WorkletProcessingNodeCallback = (
|
|
24
|
+
inputData: Array<ArrayBuffer>,
|
|
25
|
+
outputData: Array<ArrayBuffer>,
|
|
26
|
+
framesToProcess: number,
|
|
27
|
+
currentTime: number
|
|
28
|
+
) => void;
|
|
29
|
+
|
|
30
|
+
export type ShareableWorkletCallback =
|
|
31
|
+
| WorkletNodeCallback
|
|
32
|
+
| WorkletSourceNodeCallback
|
|
33
|
+
| WorkletProcessingNodeCallback;
|
|
10
34
|
|
|
11
35
|
export interface IBaseAudioContext {
|
|
12
36
|
readonly destination: IAudioDestinationNode;
|
|
13
37
|
readonly state: ContextState;
|
|
14
38
|
readonly sampleRate: number;
|
|
15
39
|
readonly currentTime: number;
|
|
40
|
+
readonly decoder: IAudioDecoder;
|
|
41
|
+
readonly stretcher: IAudioStretcher;
|
|
16
42
|
|
|
17
43
|
createRecorderAdapter(): IRecorderAdapterNode;
|
|
44
|
+
createWorkletSourceNode(
|
|
45
|
+
shareableWorklet: ShareableWorkletCallback,
|
|
46
|
+
shouldUseUiRuntime: boolean
|
|
47
|
+
): IWorkletSourceNode;
|
|
48
|
+
createWorkletNode(
|
|
49
|
+
shareableWorklet: ShareableWorkletCallback,
|
|
50
|
+
shouldUseUiRuntime: boolean,
|
|
51
|
+
bufferLength: number,
|
|
52
|
+
inputChannelCount: number
|
|
53
|
+
): IWorkletNode;
|
|
54
|
+
createWorkletProcessingNode(
|
|
55
|
+
shareableWorklet: ShareableWorkletCallback,
|
|
56
|
+
shouldUseUiRuntime: boolean
|
|
57
|
+
): IWorkletProcessingNode;
|
|
18
58
|
createOscillator(): IOscillatorNode;
|
|
59
|
+
createConstantSource(): IConstantSourceNode;
|
|
19
60
|
createGain(): IGainNode;
|
|
20
61
|
createStereoPanner(): IStereoPannerNode;
|
|
21
62
|
createBiquadFilter: () => IBiquadFilterNode;
|
|
22
63
|
createBufferSource: (pitchCorrection: boolean) => IAudioBufferSourceNode;
|
|
23
|
-
createBufferQueueSource: (
|
|
64
|
+
createBufferQueueSource: (
|
|
65
|
+
pitchCorrection: boolean
|
|
66
|
+
) => IAudioBufferQueueSourceNode;
|
|
24
67
|
createBuffer: (
|
|
25
68
|
channels: number,
|
|
26
69
|
length: number,
|
|
@@ -32,12 +75,6 @@ export interface IBaseAudioContext {
|
|
|
32
75
|
disableNormalization: boolean
|
|
33
76
|
) => IPeriodicWave;
|
|
34
77
|
createAnalyser: () => IAnalyserNode;
|
|
35
|
-
decodeAudioDataSource: (sourcePath: string) => Promise<IAudioBuffer>;
|
|
36
|
-
decodeAudioData: (arrayBuffer: ArrayBuffer) => Promise<IAudioBuffer>;
|
|
37
|
-
decodePCMAudioDataInBase64: (
|
|
38
|
-
b64: string,
|
|
39
|
-
playbackRate: number
|
|
40
|
-
) => Promise<IAudioBuffer>;
|
|
41
78
|
createStreamer: () => IStreamerNode;
|
|
42
79
|
}
|
|
43
80
|
|
|
@@ -119,6 +156,10 @@ export interface IStreamerNode extends IAudioNode {
|
|
|
119
156
|
initialize(streamPath: string): boolean;
|
|
120
157
|
}
|
|
121
158
|
|
|
159
|
+
export interface IConstantSourceNode extends IAudioScheduledSourceNode {
|
|
160
|
+
readonly offset: IAudioParam;
|
|
161
|
+
}
|
|
162
|
+
|
|
122
163
|
export interface IAudioBufferSourceNode extends IAudioBufferBaseSourceNode {
|
|
123
164
|
buffer: IAudioBuffer | null;
|
|
124
165
|
loop: boolean;
|
|
@@ -128,6 +169,9 @@ export interface IAudioBufferSourceNode extends IAudioBufferBaseSourceNode {
|
|
|
128
169
|
|
|
129
170
|
start: (when?: number, offset?: number, duration?: number) => void;
|
|
130
171
|
setBuffer: (audioBuffer: IAudioBuffer | null) => void;
|
|
172
|
+
|
|
173
|
+
// passing subscriptionId(uint_64 in cpp, string in js) to the cpp
|
|
174
|
+
onLoopEnded: string;
|
|
131
175
|
}
|
|
132
176
|
|
|
133
177
|
export interface IAudioBufferQueueSourceNode
|
|
@@ -200,6 +244,12 @@ export interface IAnalyserNode extends IAudioNode {
|
|
|
200
244
|
|
|
201
245
|
export interface IRecorderAdapterNode extends IAudioNode {}
|
|
202
246
|
|
|
247
|
+
export interface IWorkletNode extends IAudioNode {}
|
|
248
|
+
|
|
249
|
+
export interface IWorkletSourceNode extends IAudioScheduledSourceNode {}
|
|
250
|
+
|
|
251
|
+
export interface IWorkletProcessingNode extends IAudioNode {}
|
|
252
|
+
|
|
203
253
|
export interface IAudioRecorder {
|
|
204
254
|
start: () => void;
|
|
205
255
|
stop: () => void;
|
|
@@ -210,6 +260,30 @@ export interface IAudioRecorder {
|
|
|
210
260
|
onAudioReady: string;
|
|
211
261
|
}
|
|
212
262
|
|
|
263
|
+
export interface IAudioDecoder {
|
|
264
|
+
decodeWithMemoryBlock: (
|
|
265
|
+
arrayBuffer: ArrayBuffer,
|
|
266
|
+
sampleRate?: number
|
|
267
|
+
) => Promise<IAudioBuffer>;
|
|
268
|
+
decodeWithFilePath: (
|
|
269
|
+
sourcePath: string,
|
|
270
|
+
sampleRate?: number
|
|
271
|
+
) => Promise<IAudioBuffer>;
|
|
272
|
+
decodeWithPCMInBase64: (
|
|
273
|
+
b64: string,
|
|
274
|
+
inputSampleRate: number,
|
|
275
|
+
inputChannelCount: number,
|
|
276
|
+
interleaved?: boolean
|
|
277
|
+
) => Promise<IAudioBuffer>;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
export interface IAudioStretcher {
|
|
281
|
+
changePlaybackSpeed: (
|
|
282
|
+
arrayBuffer: AudioBuffer,
|
|
283
|
+
playbackSpeed: number
|
|
284
|
+
) => Promise<IAudioBuffer>;
|
|
285
|
+
}
|
|
286
|
+
|
|
213
287
|
export interface IAudioEventEmitter {
|
|
214
288
|
addAudioEventListener<Name extends AudioEventName>(
|
|
215
289
|
name: Name,
|
package/src/types.ts
CHANGED
|
@@ -14,6 +14,8 @@ export type BiquadFilterType =
|
|
|
14
14
|
|
|
15
15
|
export type ContextState = 'running' | 'closed' | `suspended`;
|
|
16
16
|
|
|
17
|
+
export type AudioWorkletRuntime = 'AudioRuntime' | 'UIRuntime';
|
|
18
|
+
|
|
17
19
|
export type OscillatorType =
|
|
18
20
|
| 'sine'
|
|
19
21
|
| 'square'
|
|
@@ -43,7 +45,7 @@ export interface AudioRecorderOptions {
|
|
|
43
45
|
|
|
44
46
|
export type WindowType = 'blackman' | 'hann';
|
|
45
47
|
|
|
46
|
-
export interface
|
|
48
|
+
export interface AudioBufferBaseSourceNodeOptions {
|
|
47
49
|
pitchCorrection: boolean;
|
|
48
50
|
}
|
|
49
51
|
|
package/src/utils/index.ts
CHANGED
|
@@ -1,3 +1,24 @@
|
|
|
1
|
+
import type { ShareableWorkletCallback } from '../interfaces';
|
|
2
|
+
|
|
3
|
+
interface SimplifiedWorkletModule {
|
|
4
|
+
makeShareableCloneRecursive: (
|
|
5
|
+
workletCallback: ShareableWorkletCallback
|
|
6
|
+
) => ShareableWorkletCallback;
|
|
7
|
+
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
9
|
+
createWorkletRuntime: (options?: any) => any;
|
|
10
|
+
}
|
|
11
|
+
|
|
1
12
|
export function clamp(value: number, min: number, max: number): number {
|
|
2
13
|
return Math.min(Math.max(value, min), max);
|
|
3
14
|
}
|
|
15
|
+
|
|
16
|
+
export let isWorkletsAvailable = false;
|
|
17
|
+
export let workletsModule: SimplifiedWorkletModule;
|
|
18
|
+
|
|
19
|
+
try {
|
|
20
|
+
workletsModule = require('react-native-worklets');
|
|
21
|
+
isWorkletsAvailable = true;
|
|
22
|
+
} catch (error) {
|
|
23
|
+
isWorkletsAvailable = false;
|
|
24
|
+
}
|