react-native-audio-api 0.11.0-alpha.1 → 0.11.0-nightly-9f40b78-20251108
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 +13 -11
- package/RNAudioAPI.podspec +20 -15
- package/android/build.gradle +33 -3
- package/android/src/main/cpp/audioapi/CMakeLists.txt +6 -3
- package/android/src/main/cpp/audioapi/android/AudioAPIModule.cpp +5 -0
- package/android/src/main/cpp/audioapi/android/AudioAPIModule.h +1 -0
- package/android/src/main/cpp/audioapi/android/core/AndroidAudioRecorder.cpp +30 -142
- package/android/src/main/cpp/audioapi/android/core/AndroidAudioRecorder.h +13 -40
- package/android/src/main/cpp/audioapi/android/core/AudioPlayer.cpp +4 -2
- package/android/src/main/cpp/audioapi/android/core/NativeAudioRecorder.hpp +9 -9
- package/android/src/main/cpp/audioapi/android/core/utils/AudioDecoder.cpp +6 -0
- package/android/src/main/java/com/swmansion/audioapi/AudioAPIModule.kt +31 -3
- package/android/src/main/java/com/swmansion/audioapi/system/AudioFocusListener.kt +21 -9
- package/android/src/main/java/com/swmansion/audioapi/system/LockScreenManager.kt +27 -6
- package/android/src/main/java/com/swmansion/audioapi/system/MediaNotificationManager.kt +11 -0
- package/android/src/oldarch/NativeAudioAPIModuleSpec.java +4 -0
- package/common/cpp/audioapi/AudioAPIModuleInstaller.h +30 -2
- package/common/cpp/audioapi/HostObjects/AudioContextHostObject.cpp +12 -17
- package/common/cpp/audioapi/HostObjects/BaseAudioContextHostObject.cpp +18 -0
- package/common/cpp/audioapi/HostObjects/BaseAudioContextHostObject.h +1 -0
- package/common/cpp/audioapi/HostObjects/OfflineAudioContextHostObject.cpp +26 -30
- package/common/cpp/audioapi/HostObjects/effects/BiquadFilterNodeHostObject.cpp +1 -1
- package/common/cpp/audioapi/HostObjects/effects/ConvolverNodeHostObject.cpp +47 -0
- package/common/cpp/audioapi/HostObjects/effects/ConvolverNodeHostObject.h +20 -0
- package/common/cpp/audioapi/HostObjects/inputs/AudioRecorderHostObject.cpp +18 -97
- package/common/cpp/audioapi/HostObjects/inputs/AudioRecorderHostObject.h +6 -18
- package/common/cpp/audioapi/HostObjects/sources/AudioBufferBaseSourceNodeHostObject.cpp +1 -1
- package/common/cpp/audioapi/HostObjects/sources/AudioBufferSourceNodeHostObject.cpp +1 -1
- package/common/cpp/audioapi/HostObjects/sources/AudioScheduledSourceNodeHostObject.cpp +1 -1
- package/common/cpp/audioapi/HostObjects/utils/AudioStretcherHostObject.cpp +15 -26
- package/common/cpp/audioapi/core/AudioNode.h +3 -2
- package/common/cpp/audioapi/core/AudioParam.cpp +2 -2
- package/common/cpp/audioapi/core/BaseAudioContext.cpp +10 -0
- package/common/cpp/audioapi/core/BaseAudioContext.h +2 -0
- package/common/cpp/audioapi/core/effects/BiquadFilterNode.cpp +69 -32
- package/common/cpp/audioapi/core/effects/BiquadFilterNode.h +37 -1
- package/common/cpp/audioapi/core/effects/ConvolverNode.cpp +210 -0
- package/common/cpp/audioapi/core/effects/ConvolverNode.h +55 -0
- package/common/cpp/audioapi/core/inputs/AudioRecorder.cpp +82 -36
- package/common/cpp/audioapi/core/inputs/AudioRecorder.h +31 -52
- package/common/cpp/audioapi/core/sources/AudioBufferBaseSourceNode.cpp +14 -17
- package/common/cpp/audioapi/core/sources/AudioBufferBaseSourceNode.h +0 -1
- package/common/cpp/audioapi/core/sources/AudioBufferQueueSourceNode.cpp +7 -0
- package/common/cpp/audioapi/core/sources/AudioBufferQueueSourceNode.h +1 -0
- package/common/cpp/audioapi/core/sources/AudioBufferSourceNode.cpp +8 -14
- package/common/cpp/audioapi/core/sources/AudioBufferSourceNode.h +0 -1
- package/common/cpp/audioapi/core/sources/AudioScheduledSourceNode.cpp +14 -19
- package/common/cpp/audioapi/core/sources/AudioScheduledSourceNode.h +3 -3
- package/common/cpp/audioapi/core/sources/StreamerNode.cpp +64 -64
- package/common/cpp/audioapi/core/sources/StreamerNode.h +38 -10
- package/common/cpp/audioapi/core/utils/AudioNodeManager.cpp +5 -0
- package/common/cpp/audioapi/core/utils/Constants.h +2 -1
- package/common/cpp/audioapi/core/utils/worklets/SafeIncludes.h +12 -8
- package/common/cpp/audioapi/core/utils/worklets/WorkletsRunner.cpp +3 -3
- package/common/cpp/audioapi/core/utils/worklets/WorkletsRunner.h +1 -1
- package/common/cpp/audioapi/dsp/AudioUtils.cpp +1 -1
- package/common/cpp/audioapi/dsp/Convolver.cpp +213 -0
- package/common/cpp/audioapi/dsp/Convolver.h +45 -0
- package/common/cpp/audioapi/dsp/FFT.cpp +0 -26
- package/common/cpp/audioapi/dsp/FFT.h +26 -2
- package/common/cpp/audioapi/events/AudioEventHandlerRegistry.h +1 -1
- package/common/cpp/audioapi/external/ffmpeg_include/libavcodec/avcodec.h +4 -4
- package/common/cpp/audioapi/external/ffmpeg_include/libavcodec/codec.h +1 -1
- package/common/cpp/audioapi/external/ffmpeg_include/libavcodec/codec_desc.h +1 -1
- package/common/cpp/audioapi/external/ffmpeg_include/libavcodec/codec_id.h +3 -1
- package/common/cpp/audioapi/external/ffmpeg_include/libavcodec/codec_par.h +2 -2
- package/common/cpp/audioapi/external/ffmpeg_include/libavcodec/defs.h +3 -0
- package/common/cpp/audioapi/external/ffmpeg_include/libavcodec/packet.h +1 -1
- package/common/cpp/audioapi/external/ffmpeg_include/libavcodec/smpte_436m.h +254 -0
- package/common/cpp/audioapi/external/ffmpeg_include/libavcodec/version.h +1 -1
- package/common/cpp/audioapi/external/ffmpeg_include/libavformat/avformat.h +6 -6
- package/common/cpp/audioapi/external/ffmpeg_include/libavformat/version.h +2 -2
- package/common/cpp/audioapi/external/ffmpeg_include/libavformat/version_major.h +2 -0
- package/common/cpp/audioapi/external/ffmpeg_include/libavutil/avassert.h +5 -2
- package/common/cpp/audioapi/external/ffmpeg_include/libavutil/avutil.h +2 -2
- package/common/cpp/audioapi/external/ffmpeg_include/libavutil/channel_layout.h +2 -2
- package/common/cpp/audioapi/external/ffmpeg_include/libavutil/csp.h +1 -1
- package/common/cpp/audioapi/external/ffmpeg_include/libavutil/dict.h +1 -1
- package/common/cpp/audioapi/external/ffmpeg_include/libavutil/ffversion.h +1 -1
- package/common/cpp/audioapi/external/ffmpeg_include/libavutil/film_grain_params.h +1 -1
- package/common/cpp/audioapi/external/ffmpeg_include/libavutil/frame.h +1 -1
- package/common/cpp/audioapi/external/ffmpeg_include/libavutil/hdr_dynamic_vivid_metadata.h +3 -3
- package/common/cpp/audioapi/external/ffmpeg_include/libavutil/hwcontext.h +1 -1
- package/common/cpp/audioapi/external/ffmpeg_include/libavutil/hwcontext_opencl.h +1 -1
- package/common/cpp/audioapi/external/ffmpeg_include/libavutil/hwcontext_qsv.h +0 -1
- package/common/cpp/audioapi/external/ffmpeg_include/libavutil/hwcontext_vulkan.h +1 -1
- package/common/cpp/audioapi/external/ffmpeg_include/libavutil/iamf.h +2 -2
- package/common/cpp/audioapi/external/ffmpeg_include/libavutil/lfg.h +2 -2
- package/common/cpp/audioapi/external/ffmpeg_include/libavutil/log.h +2 -2
- package/common/cpp/audioapi/external/ffmpeg_include/libavutil/mathematics.h +1 -1
- package/common/cpp/audioapi/external/ffmpeg_include/libavutil/opt.h +4 -4
- package/common/cpp/audioapi/external/ffmpeg_include/libavutil/rational.h +1 -1
- package/common/cpp/audioapi/external/ffmpeg_include/libavutil/rc4.h +1 -1
- package/common/cpp/audioapi/external/ffmpeg_include/libavutil/refstruct.h +1 -1
- package/common/cpp/audioapi/external/ffmpeg_include/libavutil/spherical.h +6 -0
- package/common/cpp/audioapi/external/ffmpeg_include/libavutil/tdrdi.h +1 -1
- package/common/cpp/audioapi/external/ffmpeg_include/libavutil/tx.h +1 -1
- package/common/cpp/audioapi/external/ffmpeg_include/libavutil/version.h +3 -3
- package/common/cpp/audioapi/external/ffmpeg_include/libavutil/video_hint.h +1 -1
- package/common/cpp/audioapi/external/ffmpeg_include/libswresample/swresample.h +1 -1
- package/common/cpp/audioapi/external/ffmpeg_include/libswresample/version.h +1 -1
- package/common/cpp/audioapi/jsi/JsiPromise.cpp +33 -56
- package/common/cpp/audioapi/jsi/JsiPromise.h +41 -11
- package/common/cpp/audioapi/libs/ffmpeg/FFmpegDecoding.cpp +2 -3
- package/common/cpp/audioapi/libs/ffmpeg/relinking.md +24 -0
- package/common/cpp/audioapi/utils/AlignedAllocator.hpp +50 -0
- package/common/cpp/audioapi/utils/AudioBus.cpp +28 -0
- package/common/cpp/audioapi/utils/AudioBus.h +3 -0
- package/common/cpp/audioapi/utils/ThreadPool.hpp +59 -1
- package/common/cpp/test/CMakeLists.txt +19 -14
- package/common/cpp/test/src/AudioParamTest.cpp +1 -1
- package/common/cpp/test/src/AudioScheduledSourceTest.cpp +134 -0
- package/common/cpp/test/src/ConstantSourceTest.cpp +1 -1
- package/common/cpp/test/src/GainTest.cpp +1 -1
- package/common/cpp/test/src/MockAudioEventHandlerRegistry.h +4 -4
- package/common/cpp/test/src/OscillatorTest.cpp +1 -1
- package/common/cpp/test/src/StereoPannerTest.cpp +1 -1
- package/common/cpp/test/src/biquad/BiquadFilterChromium.cpp +389 -0
- package/common/cpp/test/src/biquad/BiquadFilterChromium.h +64 -0
- package/common/cpp/test/src/biquad/BiquadFilterTest.cpp +284 -0
- package/common/cpp/test/src/biquad/BiquadFilterTest.h +40 -0
- package/ios/audioapi/ios/AudioAPIModule.h +2 -1
- package/ios/audioapi/ios/AudioAPIModule.mm +34 -9
- package/ios/audioapi/ios/core/IOSAudioRecorder.h +10 -28
- package/ios/audioapi/ios/core/IOSAudioRecorder.mm +30 -117
- package/ios/audioapi/ios/core/NativeAudioRecorder.h +9 -4
- package/ios/audioapi/ios/core/NativeAudioRecorder.m +71 -29
- package/ios/audioapi/ios/core/utils/AudioDecoder.mm +0 -1
- package/ios/audioapi/ios/system/AudioEngine.mm +3 -3
- package/ios/audioapi/ios/system/AudioSessionManager.h +2 -0
- package/ios/audioapi/ios/system/AudioSessionManager.mm +24 -0
- package/ios/audioapi/ios/system/LockScreenManager.h +0 -1
- package/ios/audioapi/ios/system/LockScreenManager.mm +6 -19
- package/lib/commonjs/api.js +141 -76
- 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/AudioContext.js +1 -1
- package/lib/commonjs/core/AudioContext.js.map +1 -1
- package/lib/commonjs/core/AudioRecorder.js +13 -171
- package/lib/commonjs/core/AudioRecorder.js.map +1 -1
- package/lib/commonjs/core/BaseAudioContext.js +28 -25
- package/lib/commonjs/core/BaseAudioContext.js.map +1 -1
- package/lib/commonjs/core/ConvolverNode.js +37 -0
- package/lib/commonjs/core/ConvolverNode.js.map +1 -0
- package/lib/commonjs/core/OfflineAudioContext.js +1 -1
- package/lib/commonjs/core/OfflineAudioContext.js.map +1 -1
- package/lib/commonjs/specs/NativeAudioAPIModule.js.map +1 -1
- package/lib/commonjs/system/AudioManager.js +3 -0
- package/lib/commonjs/system/AudioManager.js.map +1 -1
- package/lib/commonjs/types.js +0 -46
- package/lib/commonjs/types.js.map +1 -1
- package/lib/commonjs/utils/index.js +19 -21
- package/lib/commonjs/utils/index.js.map +1 -1
- package/lib/commonjs/web-core/AudioContext.js +12 -0
- package/lib/commonjs/web-core/AudioContext.js.map +1 -1
- package/lib/commonjs/web-core/ConvolverNode.js +40 -0
- package/lib/commonjs/web-core/ConvolverNode.js.map +1 -0
- package/lib/commonjs/web-core/ConvolverNodeOptions.js +6 -0
- package/lib/commonjs/web-core/ConvolverNodeOptions.js.map +1 -0
- package/lib/commonjs/web-core/OfflineAudioContext.js +12 -0
- package/lib/commonjs/web-core/OfflineAudioContext.js.map +1 -1
- package/lib/module/api.js +16 -15
- 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/AudioContext.js +2 -2
- package/lib/module/core/AudioContext.js.map +1 -1
- package/lib/module/core/AudioRecorder.js +13 -171
- package/lib/module/core/AudioRecorder.js.map +1 -1
- package/lib/module/core/BaseAudioContext.js +29 -26
- package/lib/module/core/BaseAudioContext.js.map +1 -1
- package/lib/module/core/ConvolverNode.js +31 -0
- package/lib/module/core/ConvolverNode.js.map +1 -0
- package/lib/module/core/OfflineAudioContext.js +2 -2
- package/lib/module/core/OfflineAudioContext.js.map +1 -1
- package/lib/module/specs/NativeAudioAPIModule.js.map +1 -1
- package/lib/module/system/AudioManager.js +3 -0
- package/lib/module/system/AudioManager.js.map +1 -1
- package/lib/module/types.js +1 -45
- package/lib/module/types.js.map +1 -1
- package/lib/module/utils/index.js +15 -2
- package/lib/module/utils/index.js.map +1 -1
- package/lib/module/web-core/AudioContext.js +12 -0
- package/lib/module/web-core/AudioContext.js.map +1 -1
- package/lib/module/web-core/ConvolverNode.js +34 -0
- package/lib/module/web-core/ConvolverNode.js.map +1 -0
- package/lib/module/web-core/ConvolverNodeOptions.js +4 -0
- package/lib/module/web-core/ConvolverNodeOptions.js.map +1 -0
- package/lib/module/web-core/OfflineAudioContext.js +12 -0
- package/lib/module/web-core/OfflineAudioContext.js.map +1 -1
- package/lib/typescript/api.d.ts +19 -17
- 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/AudioContext.d.ts.map +1 -1
- package/lib/typescript/core/AudioRecorder.d.ts +7 -62
- package/lib/typescript/core/AudioRecorder.d.ts.map +1 -1
- package/lib/typescript/core/BaseAudioContext.d.ts +3 -1
- package/lib/typescript/core/BaseAudioContext.d.ts.map +1 -1
- package/lib/typescript/core/ConvolverNode.d.ts +12 -0
- package/lib/typescript/core/ConvolverNode.d.ts.map +1 -0
- package/lib/typescript/events/types.d.ts +0 -16
- package/lib/typescript/events/types.d.ts.map +1 -1
- package/lib/typescript/interfaces.d.ts +9 -42
- package/lib/typescript/interfaces.d.ts.map +1 -1
- package/lib/typescript/specs/NativeAudioAPIModule.d.ts +1 -0
- package/lib/typescript/specs/NativeAudioAPIModule.d.ts.map +1 -1
- package/lib/typescript/system/AudioManager.d.ts +1 -0
- package/lib/typescript/system/AudioManager.d.ts.map +1 -1
- package/lib/typescript/types.d.ts +8 -79
- package/lib/typescript/types.d.ts.map +1 -1
- package/lib/typescript/utils/index.d.ts +5 -2
- package/lib/typescript/utils/index.d.ts.map +1 -1
- package/lib/typescript/web-core/AudioContext.d.ts +3 -0
- package/lib/typescript/web-core/AudioContext.d.ts.map +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/ConvolverNode.d.ts +11 -0
- package/lib/typescript/web-core/ConvolverNode.d.ts.map +1 -0
- package/lib/typescript/web-core/ConvolverNodeOptions.d.ts +6 -0
- package/lib/typescript/web-core/ConvolverNodeOptions.d.ts.map +1 -0
- package/lib/typescript/web-core/OfflineAudioContext.d.ts +3 -0
- package/lib/typescript/web-core/OfflineAudioContext.d.ts.map +1 -1
- package/package.json +14 -5
- package/scripts/download-prebuilt-binaries.sh +61 -0
- package/scripts/rnaa_utils.rb +8 -0
- package/scripts/validate-worklets-version.js +28 -0
- package/src/api.ts +45 -18
- package/src/api.web.ts +1 -0
- package/src/core/AudioContext.ts +3 -2
- package/src/core/AudioRecorder.ts +24 -211
- package/src/core/BaseAudioContext.ts +67 -60
- package/src/core/ConvolverNode.ts +35 -0
- package/src/core/OfflineAudioContext.ts +2 -2
- package/src/events/types.ts +0 -18
- package/src/interfaces.ts +16 -52
- package/src/specs/NativeAudioAPIModule.ts +1 -0
- package/src/system/AudioManager.ts +4 -0
- package/src/types.ts +9 -90
- package/src/utils/index.ts +22 -2
- package/src/web-core/AudioContext.tsx +25 -0
- package/src/web-core/BaseAudioContext.tsx +2 -0
- package/src/web-core/ConvolverNode.tsx +43 -0
- package/src/web-core/ConvolverNodeOptions.tsx +6 -0
- package/src/web-core/OfflineAudioContext.tsx +25 -0
- package/android/src/main/cpp/audioapi/android/core/utils/AndroidFileWriterBackend.h +0 -37
- package/android/src/main/cpp/audioapi/android/core/utils/AndroidRecorderCallback.cpp +0 -187
- package/android/src/main/cpp/audioapi/android/core/utils/AndroidRecorderCallback.h +0 -57
- package/android/src/main/cpp/audioapi/android/core/utils/FileUtils.h +0 -34
- package/android/src/main/cpp/audioapi/android/core/utils/FileUtilts.cpp +0 -133
- package/android/src/main/cpp/audioapi/android/core/utils/MiniaudioImplementation.cpp +0 -3
- package/android/src/main/cpp/audioapi/android/core/utils/ffmpegBackend/FFmpegAudioFileOptions.cpp +0 -154
- package/android/src/main/cpp/audioapi/android/core/utils/ffmpegBackend/FFmpegAudioFileOptions.h +0 -41
- package/android/src/main/cpp/audioapi/android/core/utils/ffmpegBackend/FFmpegFileWriter.cpp +0 -429
- package/android/src/main/cpp/audioapi/android/core/utils/ffmpegBackend/FFmpegFileWriter.h +0 -113
- package/android/src/main/cpp/audioapi/android/core/utils/miniaudioBackend/MiniAudioFileOptions.cpp +0 -47
- package/android/src/main/cpp/audioapi/android/core/utils/miniaudioBackend/MiniAudioFileOptions.h +0 -28
- package/android/src/main/cpp/audioapi/android/core/utils/miniaudioBackend/MiniAudioFileWriter.cpp +0 -269
- package/android/src/main/cpp/audioapi/android/core/utils/miniaudioBackend/MiniAudioFileWriter.h +0 -47
- package/android/src/main/cpp/audioapi/android/system/NativeFileInfo.hpp +0 -31
- package/android/src/main/java/com/swmansion/audioapi/system/NativeFileInfo.kt +0 -18
- package/android/src/main/jniLibs/arm64-v8a/libavcodec.so +0 -0
- package/android/src/main/jniLibs/arm64-v8a/libavformat.so +0 -0
- package/android/src/main/jniLibs/arm64-v8a/libavutil.so +0 -0
- package/android/src/main/jniLibs/arm64-v8a/libswresample.so +0 -0
- package/android/src/main/jniLibs/armeabi-v7a/libavcodec.so +0 -0
- package/android/src/main/jniLibs/armeabi-v7a/libavformat.so +0 -0
- package/android/src/main/jniLibs/armeabi-v7a/libavutil.so +0 -0
- package/android/src/main/jniLibs/armeabi-v7a/libswresample.so +0 -0
- package/android/src/main/jniLibs/x86/libavcodec.so +0 -0
- package/android/src/main/jniLibs/x86/libavformat.so +0 -0
- package/android/src/main/jniLibs/x86/libavutil.so +0 -0
- package/android/src/main/jniLibs/x86/libswresample.so +0 -0
- package/android/src/main/jniLibs/x86_64/libavcodec.so +0 -0
- package/android/src/main/jniLibs/x86_64/libavformat.so +0 -0
- package/android/src/main/jniLibs/x86_64/libavutil.so +0 -0
- package/android/src/main/jniLibs/x86_64/libswresample.so +0 -0
- package/common/cpp/audioapi/external/arm64-v8a/libcrypto.a +0 -0
- package/common/cpp/audioapi/external/arm64-v8a/libogg.a +0 -0
- package/common/cpp/audioapi/external/arm64-v8a/libopus.a +0 -0
- package/common/cpp/audioapi/external/arm64-v8a/libopusfile.a +0 -0
- package/common/cpp/audioapi/external/arm64-v8a/libssl.a +0 -0
- package/common/cpp/audioapi/external/arm64-v8a/libvorbis.a +0 -0
- package/common/cpp/audioapi/external/arm64-v8a/libvorbisenc.a +0 -0
- package/common/cpp/audioapi/external/arm64-v8a/libvorbisfile.a +0 -0
- package/common/cpp/audioapi/external/armeabi-v7a/libcrypto.a +0 -0
- package/common/cpp/audioapi/external/armeabi-v7a/libogg.a +0 -0
- package/common/cpp/audioapi/external/armeabi-v7a/libopus.a +0 -0
- package/common/cpp/audioapi/external/armeabi-v7a/libopusfile.a +0 -0
- package/common/cpp/audioapi/external/armeabi-v7a/libssl.a +0 -0
- package/common/cpp/audioapi/external/armeabi-v7a/libvorbis.a +0 -0
- package/common/cpp/audioapi/external/armeabi-v7a/libvorbisenc.a +0 -0
- package/common/cpp/audioapi/external/armeabi-v7a/libvorbisfile.a +0 -0
- package/common/cpp/audioapi/external/iphoneos/libcrypto.a +0 -0
- package/common/cpp/audioapi/external/iphoneos/libogg.a +0 -0
- package/common/cpp/audioapi/external/iphoneos/libopus.a +0 -0
- package/common/cpp/audioapi/external/iphoneos/libopusfile.a +0 -0
- package/common/cpp/audioapi/external/iphoneos/libssl.a +0 -0
- package/common/cpp/audioapi/external/iphoneos/libvorbis.a +0 -0
- package/common/cpp/audioapi/external/iphoneos/libvorbisenc.a +0 -0
- package/common/cpp/audioapi/external/iphoneos/libvorbisfile.a +0 -0
- package/common/cpp/audioapi/external/iphonesimulator/libcrypto.a +0 -0
- package/common/cpp/audioapi/external/iphonesimulator/libogg.a +0 -0
- package/common/cpp/audioapi/external/iphonesimulator/libopus.a +0 -0
- package/common/cpp/audioapi/external/iphonesimulator/libopusfile.a +0 -0
- package/common/cpp/audioapi/external/iphonesimulator/libssl.a +0 -0
- package/common/cpp/audioapi/external/iphonesimulator/libvorbis.a +0 -0
- package/common/cpp/audioapi/external/iphonesimulator/libvorbisenc.a +0 -0
- package/common/cpp/audioapi/external/iphonesimulator/libvorbisfile.a +0 -0
- package/common/cpp/audioapi/external/libavcodec.xcframework/Info.plist +0 -44
- package/common/cpp/audioapi/external/libavcodec.xcframework/ios-arm64/libavcodec.framework/Info.plist +0 -1
- package/common/cpp/audioapi/external/libavcodec.xcframework/ios-arm64/libavcodec.framework/libavcodec +0 -0
- package/common/cpp/audioapi/external/libavcodec.xcframework/ios-arm64_x86_64-simulator/libavcodec.framework/Info.plist +0 -1
- package/common/cpp/audioapi/external/libavcodec.xcframework/ios-arm64_x86_64-simulator/libavcodec.framework/libavcodec +0 -0
- package/common/cpp/audioapi/external/libavformat.xcframework/Info.plist +0 -44
- package/common/cpp/audioapi/external/libavformat.xcframework/ios-arm64/libavformat.framework/Info.plist +0 -1
- package/common/cpp/audioapi/external/libavformat.xcframework/ios-arm64/libavformat.framework/libavformat +0 -0
- package/common/cpp/audioapi/external/libavformat.xcframework/ios-arm64_x86_64-simulator/libavformat.framework/Info.plist +0 -1
- package/common/cpp/audioapi/external/libavformat.xcframework/ios-arm64_x86_64-simulator/libavformat.framework/libavformat +0 -0
- package/common/cpp/audioapi/external/libavutil.xcframework/Info.plist +0 -44
- package/common/cpp/audioapi/external/libavutil.xcframework/ios-arm64/libavutil.framework/Info.plist +0 -1
- package/common/cpp/audioapi/external/libavutil.xcframework/ios-arm64/libavutil.framework/libavutil +0 -0
- package/common/cpp/audioapi/external/libavutil.xcframework/ios-arm64_x86_64-simulator/libavutil.framework/Info.plist +0 -1
- package/common/cpp/audioapi/external/libavutil.xcframework/ios-arm64_x86_64-simulator/libavutil.framework/libavutil +0 -0
- package/common/cpp/audioapi/external/libswresample.xcframework/Info.plist +0 -44
- package/common/cpp/audioapi/external/libswresample.xcframework/ios-arm64/libswresample.framework/Info.plist +0 -1
- package/common/cpp/audioapi/external/libswresample.xcframework/ios-arm64/libswresample.framework/libswresample +0 -0
- package/common/cpp/audioapi/external/libswresample.xcframework/ios-arm64_x86_64-simulator/libswresample.framework/Info.plist +0 -1
- package/common/cpp/audioapi/external/libswresample.xcframework/ios-arm64_x86_64-simulator/libswresample.framework/libswresample +0 -0
- package/common/cpp/audioapi/external/x86/libcrypto.a +0 -0
- package/common/cpp/audioapi/external/x86/libogg.a +0 -0
- package/common/cpp/audioapi/external/x86/libopus.a +0 -0
- package/common/cpp/audioapi/external/x86/libopusfile.a +0 -0
- package/common/cpp/audioapi/external/x86/libssl.a +0 -0
- package/common/cpp/audioapi/external/x86/libvorbis.a +0 -0
- package/common/cpp/audioapi/external/x86/libvorbisenc.a +0 -0
- package/common/cpp/audioapi/external/x86/libvorbisfile.a +0 -0
- package/common/cpp/audioapi/external/x86_64/libcrypto.a +0 -0
- package/common/cpp/audioapi/external/x86_64/libogg.a +0 -0
- package/common/cpp/audioapi/external/x86_64/libopus.a +0 -0
- package/common/cpp/audioapi/external/x86_64/libopusfile.a +0 -0
- package/common/cpp/audioapi/external/x86_64/libssl.a +0 -0
- package/common/cpp/audioapi/external/x86_64/libvorbis.a +0 -0
- package/common/cpp/audioapi/external/x86_64/libvorbisenc.a +0 -0
- package/common/cpp/audioapi/external/x86_64/libvorbisfile.a +0 -0
- package/common/cpp/audioapi/libs/ffmpeg/INSTRUCTIONS.md +0 -32
- package/common/cpp/audioapi/libs/ffmpeg/create_xcframework.sh +0 -111
- package/common/cpp/audioapi/libs/ffmpeg/ffmpeg_setup.sh +0 -391
- package/ios/audioapi/ios/core/IOSAudioFileOptions.h +0 -36
- package/ios/audioapi/ios/core/IOSAudioFileOptions.mm +0 -140
- package/ios/audioapi/ios/core/IOSAudioFileWriter.h +0 -51
- package/ios/audioapi/ios/core/IOSAudioFileWriter.mm +0 -223
- package/ios/audioapi/ios/core/IOSRecorderCallback.h +0 -57
- package/ios/audioapi/ios/core/IOSRecorderCallback.mm +0 -189
- package/lib/commonjs/utils/bitEnums.js +0 -33
- package/lib/commonjs/utils/bitEnums.js.map +0 -1
- package/lib/module/utils/bitEnums.js +0 -27
- package/lib/module/utils/bitEnums.js.map +0 -1
- package/lib/typescript/utils/bitEnums.d.ts +0 -4
- package/lib/typescript/utils/bitEnums.d.ts.map +0 -1
- package/src/utils/bitEnums.ts +0 -51
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
#include <audioapi/core/BaseAudioContext.h>
|
|
2
|
+
#include <audioapi/core/effects/ConvolverNode.h>
|
|
3
|
+
#include <audioapi/core/sources/AudioBuffer.h>
|
|
4
|
+
#include <audioapi/core/utils/Constants.h>
|
|
5
|
+
#include <audioapi/dsp/AudioUtils.h>
|
|
6
|
+
#include <audioapi/dsp/FFT.h>
|
|
7
|
+
#include <audioapi/utils/AudioArray.h>
|
|
8
|
+
#include <iostream>
|
|
9
|
+
#include <thread>
|
|
10
|
+
|
|
11
|
+
namespace audioapi {
|
|
12
|
+
ConvolverNode::ConvolverNode(
|
|
13
|
+
BaseAudioContext *context,
|
|
14
|
+
const std::shared_ptr<AudioBuffer> &buffer,
|
|
15
|
+
bool disableNormalization)
|
|
16
|
+
: AudioNode(context),
|
|
17
|
+
remainingSegments_(0),
|
|
18
|
+
internalBufferIndex_(0),
|
|
19
|
+
signalledToStop_(false),
|
|
20
|
+
scaleFactor_(1.0f),
|
|
21
|
+
intermediateBus_(nullptr),
|
|
22
|
+
buffer_(nullptr),
|
|
23
|
+
internalBuffer_(nullptr) {
|
|
24
|
+
channelCount_ = 2;
|
|
25
|
+
channelCountMode_ = ChannelCountMode::CLAMPED_MAX;
|
|
26
|
+
normalize_ = !disableNormalization;
|
|
27
|
+
gainCalibrationSampleRate_ = context->getSampleRate();
|
|
28
|
+
setBuffer(buffer);
|
|
29
|
+
audioBus_ = std::make_shared<AudioBus>(
|
|
30
|
+
RENDER_QUANTUM_SIZE, channelCount_, context->getSampleRate());
|
|
31
|
+
isInitialized_ = true;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
bool ConvolverNode::getNormalize_() const {
|
|
35
|
+
return normalize_;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const std::shared_ptr<AudioBuffer> &ConvolverNode::getBuffer() const {
|
|
39
|
+
return buffer_;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
void ConvolverNode::setNormalize(bool normalize) {
|
|
43
|
+
if (normalize_ != normalize) {
|
|
44
|
+
normalize_ = normalize;
|
|
45
|
+
if (normalize_ && buffer_)
|
|
46
|
+
calculateNormalizationScale();
|
|
47
|
+
}
|
|
48
|
+
if (!normalize_) {
|
|
49
|
+
scaleFactor_ = 1.0f;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
void ConvolverNode::setBuffer(const std::shared_ptr<AudioBuffer> &buffer) {
|
|
54
|
+
if (buffer_ != buffer && buffer != nullptr) {
|
|
55
|
+
buffer_ = buffer;
|
|
56
|
+
if (normalize_)
|
|
57
|
+
calculateNormalizationScale();
|
|
58
|
+
threadPool_ = std::make_shared<ThreadPool>(4);
|
|
59
|
+
convolvers_.clear();
|
|
60
|
+
for (int i = 0; i < buffer->getNumberOfChannels(); ++i) {
|
|
61
|
+
convolvers_.emplace_back();
|
|
62
|
+
AudioArray channelData(buffer->getLength());
|
|
63
|
+
memcpy(
|
|
64
|
+
channelData.getData(),
|
|
65
|
+
buffer->getChannelData(i),
|
|
66
|
+
buffer->getLength() * sizeof(float));
|
|
67
|
+
convolvers_.back().init(
|
|
68
|
+
RENDER_QUANTUM_SIZE, channelData, buffer->getLength());
|
|
69
|
+
}
|
|
70
|
+
if (buffer->getNumberOfChannels() == 1) {
|
|
71
|
+
// add one more convolver, because right now input is always stereo
|
|
72
|
+
convolvers_.emplace_back();
|
|
73
|
+
AudioArray channelData(buffer->getLength());
|
|
74
|
+
memcpy(
|
|
75
|
+
channelData.getData(),
|
|
76
|
+
buffer->getChannelData(0),
|
|
77
|
+
buffer->getLength() * sizeof(float));
|
|
78
|
+
convolvers_.back().init(
|
|
79
|
+
RENDER_QUANTUM_SIZE, channelData, buffer->getLength());
|
|
80
|
+
}
|
|
81
|
+
internalBuffer_ = std::make_shared<AudioBus>(
|
|
82
|
+
RENDER_QUANTUM_SIZE * 2, channelCount_, buffer->getSampleRate());
|
|
83
|
+
intermediateBus_ = std::make_shared<AudioBus>(
|
|
84
|
+
RENDER_QUANTUM_SIZE, convolvers_.size(), buffer->getSampleRate());
|
|
85
|
+
internalBufferIndex_ = 0;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
void ConvolverNode::onInputDisabled() {
|
|
90
|
+
numberOfEnabledInputNodes_ -= 1;
|
|
91
|
+
if (isEnabled() && numberOfEnabledInputNodes_ == 0) {
|
|
92
|
+
signalledToStop_ = true;
|
|
93
|
+
remainingSegments_ = convolvers_.at(0).getSegCount();
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
std::shared_ptr<AudioBus> ConvolverNode::processInputs(
|
|
98
|
+
const std::shared_ptr<AudioBus> &outputBus,
|
|
99
|
+
int framesToProcess,
|
|
100
|
+
bool checkIsAlreadyProcessed) {
|
|
101
|
+
if (internalBufferIndex_ < framesToProcess) {
|
|
102
|
+
return AudioNode::processInputs(outputBus, RENDER_QUANTUM_SIZE, false);
|
|
103
|
+
}
|
|
104
|
+
return AudioNode::processInputs(outputBus, 0, false);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// processing pipeline: processingBus -> intermediateBus_ -> audioBus_ (mixing
|
|
108
|
+
// with intermediateBus_)
|
|
109
|
+
std::shared_ptr<AudioBus> ConvolverNode::processNode(
|
|
110
|
+
const std::shared_ptr<AudioBus> &processingBus,
|
|
111
|
+
int framesToProcess) {
|
|
112
|
+
if (signalledToStop_) {
|
|
113
|
+
if (remainingSegments_ > 0) {
|
|
114
|
+
remainingSegments_--;
|
|
115
|
+
} else {
|
|
116
|
+
disable();
|
|
117
|
+
signalledToStop_ = false;
|
|
118
|
+
internalBufferIndex_ = 0;
|
|
119
|
+
return processingBus;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
if (internalBufferIndex_ < framesToProcess) {
|
|
123
|
+
performConvolution(processingBus); // result returned to intermediateBus_
|
|
124
|
+
audioBus_->sum(intermediateBus_.get());
|
|
125
|
+
|
|
126
|
+
internalBuffer_->copy(
|
|
127
|
+
audioBus_.get(), 0, internalBufferIndex_, RENDER_QUANTUM_SIZE);
|
|
128
|
+
internalBufferIndex_ += RENDER_QUANTUM_SIZE;
|
|
129
|
+
}
|
|
130
|
+
audioBus_->zero();
|
|
131
|
+
audioBus_->copy(internalBuffer_.get(), 0, 0, framesToProcess);
|
|
132
|
+
int remainingFrames = internalBufferIndex_ - framesToProcess;
|
|
133
|
+
if (remainingFrames > 0) {
|
|
134
|
+
for (int i = 0; i < internalBuffer_->getNumberOfChannels(); ++i) {
|
|
135
|
+
memmove(
|
|
136
|
+
internalBuffer_->getChannel(i)->getData(),
|
|
137
|
+
internalBuffer_->getChannel(i)->getData() + framesToProcess,
|
|
138
|
+
remainingFrames * sizeof(float));
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
internalBufferIndex_ -= framesToProcess;
|
|
142
|
+
|
|
143
|
+
for (int i = 0; i < audioBus_->getNumberOfChannels(); ++i) {
|
|
144
|
+
dsp::multiplyByScalar(
|
|
145
|
+
audioBus_->getChannel(i)->getData(),
|
|
146
|
+
scaleFactor_,
|
|
147
|
+
audioBus_->getChannel(i)->getData(),
|
|
148
|
+
framesToProcess);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return audioBus_;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
void ConvolverNode::calculateNormalizationScale() {
|
|
155
|
+
int numberOfChannels = buffer_->getNumberOfChannels();
|
|
156
|
+
int length = buffer_->getLength();
|
|
157
|
+
|
|
158
|
+
float power = 0;
|
|
159
|
+
|
|
160
|
+
for (int channel = 0; channel < numberOfChannels; ++channel) {
|
|
161
|
+
float channelPower = 0;
|
|
162
|
+
auto channelData = buffer_->getChannelData(channel);
|
|
163
|
+
for (int i = 0; i < length; ++i) {
|
|
164
|
+
float sample = channelData[i];
|
|
165
|
+
channelPower += sample * sample;
|
|
166
|
+
}
|
|
167
|
+
power += channelPower;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
power = std::sqrt(power / (numberOfChannels * length));
|
|
171
|
+
if (power < MIN_IR_POWER) {
|
|
172
|
+
power = MIN_IR_POWER;
|
|
173
|
+
}
|
|
174
|
+
scaleFactor_ = 1 / power;
|
|
175
|
+
scaleFactor_ *= std::pow(10, GAIN_CALIBRATION * 0.05f);
|
|
176
|
+
scaleFactor_ *= gainCalibrationSampleRate_ / buffer_->getSampleRate();
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
void ConvolverNode::performConvolution(
|
|
180
|
+
const std::shared_ptr<AudioBus> &processingBus) {
|
|
181
|
+
if (processingBus->getNumberOfChannels() == 1) {
|
|
182
|
+
for (int i = 0; i < convolvers_.size(); ++i) {
|
|
183
|
+
threadPool_->schedule([&, i] {
|
|
184
|
+
convolvers_[i].process(
|
|
185
|
+
processingBus->getChannel(0)->getData(),
|
|
186
|
+
intermediateBus_->getChannel(i)->getData());
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
} else if (processingBus->getNumberOfChannels() == 2) {
|
|
190
|
+
std::vector<int> inputChannelMap;
|
|
191
|
+
std::vector<int> outputChannelMap;
|
|
192
|
+
if (convolvers_.size() == 2) {
|
|
193
|
+
inputChannelMap = {0, 1};
|
|
194
|
+
outputChannelMap = {0, 1};
|
|
195
|
+
} else { // 4 channel IR
|
|
196
|
+
inputChannelMap = {0, 0, 1, 1};
|
|
197
|
+
outputChannelMap = {0, 3, 2, 1};
|
|
198
|
+
}
|
|
199
|
+
for (int i = 0; i < convolvers_.size(); ++i) {
|
|
200
|
+
threadPool_->schedule(
|
|
201
|
+
[this, i, inputChannelMap, outputChannelMap, &processingBus] {
|
|
202
|
+
convolvers_[i].process(
|
|
203
|
+
processingBus->getChannel(inputChannelMap[i])->getData(),
|
|
204
|
+
intermediateBus_->getChannel(outputChannelMap[i])->getData());
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
threadPool_->wait();
|
|
209
|
+
}
|
|
210
|
+
} // namespace audioapi
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <audioapi/core/AudioNode.h>
|
|
4
|
+
#include <audioapi/core/AudioParam.h>
|
|
5
|
+
#include <audioapi/dsp/Convolver.h>
|
|
6
|
+
|
|
7
|
+
#include <memory>
|
|
8
|
+
#include <vector>
|
|
9
|
+
|
|
10
|
+
#include <audioapi/utils/ThreadPool.hpp>
|
|
11
|
+
|
|
12
|
+
static constexpr int GAIN_CALIBRATION = -58; // magic number so that processed signal and dry signal have roughly the same volume
|
|
13
|
+
static constexpr double MIN_IR_POWER = 0.000125;
|
|
14
|
+
|
|
15
|
+
namespace audioapi {
|
|
16
|
+
|
|
17
|
+
class AudioBus;
|
|
18
|
+
class AudioBuffer;
|
|
19
|
+
|
|
20
|
+
class ConvolverNode : public AudioNode {
|
|
21
|
+
public:
|
|
22
|
+
explicit ConvolverNode(BaseAudioContext *context, const std::shared_ptr<AudioBuffer>& buffer, bool disableNormalization);
|
|
23
|
+
|
|
24
|
+
[[nodiscard]] bool getNormalize_() const;
|
|
25
|
+
[[nodiscard]] const std::shared_ptr<AudioBuffer> &getBuffer() const;
|
|
26
|
+
void setNormalize(bool normalize);
|
|
27
|
+
void setBuffer(const std::shared_ptr<AudioBuffer> &buffer);
|
|
28
|
+
|
|
29
|
+
protected:
|
|
30
|
+
std::shared_ptr<AudioBus> processNode(const std::shared_ptr<AudioBus>& processingBus, int framesToProcess) override;
|
|
31
|
+
|
|
32
|
+
private:
|
|
33
|
+
std::shared_ptr<AudioBus> processInputs(const std::shared_ptr<AudioBus>& outputBus, int framesToProcess, bool checkIsAlreadyProcessed) override;
|
|
34
|
+
void onInputDisabled() override;
|
|
35
|
+
float gainCalibrationSampleRate_;
|
|
36
|
+
size_t remainingSegments_;
|
|
37
|
+
size_t internalBufferIndex_;
|
|
38
|
+
bool normalize_;
|
|
39
|
+
bool signalledToStop_;
|
|
40
|
+
float scaleFactor_;
|
|
41
|
+
std::shared_ptr<AudioBus>intermediateBus_;
|
|
42
|
+
|
|
43
|
+
// impulse response buffer
|
|
44
|
+
std::shared_ptr<AudioBuffer> buffer_;
|
|
45
|
+
// buffer to hold internal processed data
|
|
46
|
+
std::shared_ptr<AudioBus> internalBuffer_;
|
|
47
|
+
// vectors of convolvers, one per channel
|
|
48
|
+
std::vector<Convolver> convolvers_;
|
|
49
|
+
std::shared_ptr<ThreadPool> threadPool_;
|
|
50
|
+
|
|
51
|
+
void calculateNormalizationScale();
|
|
52
|
+
void performConvolution(const std::shared_ptr<AudioBus>& processingBus);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
} // namespace audioapi
|
|
@@ -1,36 +1,82 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
1
|
+
#include <audioapi/HostObjects/sources/AudioBufferHostObject.h>
|
|
2
|
+
#include <audioapi/core/inputs/AudioRecorder.h>
|
|
3
|
+
#include <audioapi/core/sources/AudioBuffer.h>
|
|
4
|
+
#include <audioapi/core/sources/RecorderAdapterNode.h>
|
|
5
|
+
#include <audioapi/events/AudioEventHandlerRegistry.h>
|
|
6
|
+
#include <audioapi/utils/AudioBus.h>
|
|
7
|
+
#include <audioapi/utils/CircularAudioArray.h>
|
|
8
|
+
#include <audioapi/utils/CircularOverflowableAudioArray.h>
|
|
9
|
+
|
|
10
|
+
namespace audioapi {
|
|
11
|
+
|
|
12
|
+
AudioRecorder::AudioRecorder(
|
|
13
|
+
float sampleRate,
|
|
14
|
+
int bufferLength,
|
|
15
|
+
const std::shared_ptr<AudioEventHandlerRegistry> &audioEventHandlerRegistry)
|
|
16
|
+
: sampleRate_(sampleRate),
|
|
17
|
+
bufferLength_(bufferLength),
|
|
18
|
+
audioEventHandlerRegistry_(audioEventHandlerRegistry) {
|
|
19
|
+
constexpr int minRingBufferSize = 8192;
|
|
20
|
+
ringBufferSize_ = std::max(2 * bufferLength, minRingBufferSize);
|
|
21
|
+
circularBuffer_ = std::make_shared<CircularAudioArray>(ringBufferSize_);
|
|
22
|
+
isRunning_.store(false);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
void AudioRecorder::setOnAudioReadyCallbackId(uint64_t callbackId) {
|
|
26
|
+
onAudioReadyCallbackId_ = callbackId;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
void AudioRecorder::invokeOnAudioReadyCallback(
|
|
30
|
+
const std::shared_ptr<AudioBus> &bus,
|
|
31
|
+
int numFrames) {
|
|
32
|
+
auto audioBuffer = std::make_shared<AudioBuffer>(bus);
|
|
33
|
+
auto audioBufferHostObject =
|
|
34
|
+
std::make_shared<AudioBufferHostObject>(audioBuffer);
|
|
35
|
+
|
|
36
|
+
std::unordered_map<std::string, EventValue> body = {};
|
|
37
|
+
body.insert({"buffer", audioBufferHostObject});
|
|
38
|
+
body.insert({"numFrames", numFrames});
|
|
39
|
+
|
|
40
|
+
if (audioEventHandlerRegistry_ != nullptr) {
|
|
41
|
+
audioEventHandlerRegistry_->invokeHandlerWithEventBody(
|
|
42
|
+
"audioReady", onAudioReadyCallbackId_, body);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
void AudioRecorder::sendRemainingData() {
|
|
47
|
+
auto bus = std::make_shared<AudioBus>(
|
|
48
|
+
circularBuffer_->getNumberOfAvailableFrames(), 1, sampleRate_);
|
|
49
|
+
auto *outputChannel = bus->getChannel(0)->getData();
|
|
50
|
+
auto availableFrames =
|
|
51
|
+
static_cast<int>(circularBuffer_->getNumberOfAvailableFrames());
|
|
52
|
+
|
|
53
|
+
circularBuffer_->pop_front(
|
|
54
|
+
outputChannel, circularBuffer_->getNumberOfAvailableFrames());
|
|
55
|
+
|
|
56
|
+
invokeOnAudioReadyCallback(bus, availableFrames);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
void AudioRecorder::connect(const std::shared_ptr<RecorderAdapterNode> &node) {
|
|
60
|
+
node->init(ringBufferSize_);
|
|
61
|
+
adapterNodeLock_.lock();
|
|
62
|
+
adapterNode_ = node;
|
|
63
|
+
adapterNodeLock_.unlock();
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
void AudioRecorder::disconnect() {
|
|
67
|
+
adapterNodeLock_.lock();
|
|
68
|
+
adapterNode_ = nullptr;
|
|
69
|
+
adapterNodeLock_.unlock();
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
void AudioRecorder::writeToBuffers(const float *data, int numFrames) {
|
|
73
|
+
if (adapterNodeLock_.try_lock()) {
|
|
74
|
+
if (adapterNode_ != nullptr) {
|
|
75
|
+
adapterNode_->buff_->write(data, numFrames);
|
|
76
|
+
}
|
|
77
|
+
adapterNodeLock_.unlock();
|
|
78
|
+
}
|
|
79
|
+
circularBuffer_->push_back(data, numFrames);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
} // namespace audioapi
|
|
@@ -3,82 +3,61 @@
|
|
|
3
3
|
#include <memory>
|
|
4
4
|
#include <atomic>
|
|
5
5
|
#include <mutex>
|
|
6
|
-
#include <string>
|
|
7
|
-
#include <tuple>
|
|
8
6
|
|
|
9
7
|
namespace audioapi {
|
|
10
8
|
|
|
11
9
|
class RecorderAdapterNode;
|
|
12
10
|
class AudioBus;
|
|
13
11
|
class CircularAudioArray;
|
|
12
|
+
class CircularOverflowableAudioArray;
|
|
14
13
|
class AudioEventHandlerRegistry;
|
|
15
14
|
|
|
16
15
|
class AudioRecorder {
|
|
17
16
|
public:
|
|
18
|
-
|
|
19
|
-
explicit AudioRecorder(const std::shared_ptr<AudioEventHandlerRegistry> &audioEventHandlerRegistry):
|
|
20
|
-
audioEventHandlerRegistry_(audioEventHandlerRegistry) {}
|
|
21
|
-
virtual ~AudioRecorder() = default;
|
|
22
|
-
|
|
23
|
-
virtual std::string start() = 0;
|
|
24
|
-
virtual std::tuple<std::string, double, double> stop() = 0;
|
|
25
|
-
|
|
26
|
-
virtual void enableFileOutput(
|
|
27
|
-
float sampleRate,
|
|
28
|
-
size_t channelCount,
|
|
29
|
-
size_t bitRate,
|
|
30
|
-
size_t iosFlags,
|
|
31
|
-
size_t androidFlags) = 0;
|
|
32
|
-
virtual void disableFileOutput() = 0;
|
|
33
|
-
|
|
34
|
-
virtual void pause() = 0;
|
|
35
|
-
virtual void resume() = 0;
|
|
36
|
-
|
|
37
|
-
void connect(const std::shared_ptr<RecorderAdapterNode> &node) {}
|
|
38
|
-
void disconnect() {}
|
|
39
|
-
|
|
40
|
-
virtual void setOnAudioReadyCallback(
|
|
17
|
+
explicit AudioRecorder(
|
|
41
18
|
float sampleRate,
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
virtual void clearOnAudioReadyCallback() = 0;
|
|
46
|
-
|
|
47
|
-
virtual double getCurrentDuration() const = 0;
|
|
19
|
+
int bufferLength,
|
|
20
|
+
const std::shared_ptr<AudioEventHandlerRegistry> &audioEventHandlerRegistry
|
|
21
|
+
);
|
|
48
22
|
|
|
49
|
-
|
|
50
|
-
return callbackOutputEnabled_.load();
|
|
51
|
-
}
|
|
23
|
+
virtual ~AudioRecorder() = default;
|
|
52
24
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
25
|
+
void setOnAudioReadyCallbackId(uint64_t callbackId);
|
|
26
|
+
void invokeOnAudioReadyCallback(const std::shared_ptr<AudioBus> &bus, int numFrames);
|
|
27
|
+
void sendRemainingData();
|
|
56
28
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
29
|
+
/// @brief
|
|
30
|
+
/// # Connects the recorder to the adapter node.
|
|
31
|
+
///
|
|
32
|
+
/// The adapter node will be used to read audio data from the recorder.
|
|
33
|
+
/// @note Few frames of audio might not yet be written to the buffer when connecting.
|
|
34
|
+
void connect(const std::shared_ptr<RecorderAdapterNode> &node);
|
|
60
35
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
36
|
+
/// @brief
|
|
37
|
+
/// # Disconnects the recorder from the adapter node.
|
|
38
|
+
///
|
|
39
|
+
/// The adapter node will no longer be used to read audio data from the recorder.
|
|
40
|
+
/// @note Last few frames of audio might be written to the buffer after disconnecting.
|
|
41
|
+
void disconnect();
|
|
64
42
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
43
|
+
virtual void start() = 0;
|
|
44
|
+
virtual void stop() = 0;
|
|
68
45
|
|
|
69
46
|
protected:
|
|
70
|
-
|
|
47
|
+
float sampleRate_;
|
|
48
|
+
int bufferLength_;
|
|
49
|
+
size_t ringBufferSize_;
|
|
71
50
|
|
|
72
|
-
std::atomic<
|
|
73
|
-
std::
|
|
74
|
-
std::atomic<bool> callbackOutputEnabled_{false};
|
|
75
|
-
std::atomic<bool> isConnected_{false};
|
|
76
|
-
// std::shared_ptr<CircularAudioArray> circularBuffer_;
|
|
51
|
+
std::atomic<bool> isRunning_;
|
|
52
|
+
std::shared_ptr<CircularAudioArray> circularBuffer_;
|
|
77
53
|
|
|
78
54
|
mutable std::mutex adapterNodeLock_;
|
|
79
55
|
std::shared_ptr<RecorderAdapterNode> adapterNode_ = nullptr;
|
|
80
56
|
|
|
81
57
|
std::shared_ptr<AudioEventHandlerRegistry> audioEventHandlerRegistry_;
|
|
58
|
+
uint64_t onAudioReadyCallbackId_ = 0;
|
|
59
|
+
|
|
60
|
+
void writeToBuffers(const float *data, int numFrames);
|
|
82
61
|
};
|
|
83
62
|
|
|
84
63
|
} // namespace audioapi
|
|
@@ -36,20 +36,15 @@ std::shared_ptr<AudioParam> AudioBufferBaseSourceNode::getPlaybackRateParam()
|
|
|
36
36
|
return playbackRateParam_;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
void AudioBufferBaseSourceNode::clearOnPositionChangedCallback() {
|
|
40
|
-
if (onPositionChangedCallbackId_ == 0 || context_ == nullptr ||
|
|
41
|
-
context_->audioEventHandlerRegistry_ == nullptr) {
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
context_->audioEventHandlerRegistry_->unregisterHandler(
|
|
46
|
-
"positionChanged", onPositionChangedCallbackId_);
|
|
47
|
-
onPositionChangedCallbackId_ = 0;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
39
|
void AudioBufferBaseSourceNode::setOnPositionChangedCallbackId(
|
|
51
40
|
uint64_t callbackId) {
|
|
52
|
-
|
|
41
|
+
auto oldCallbackId = onPositionChangedCallbackId_.exchange(
|
|
42
|
+
callbackId, std::memory_order_acq_rel);
|
|
43
|
+
|
|
44
|
+
if (oldCallbackId != 0) {
|
|
45
|
+
audioEventHandlerRegistry_->unregisterHandler(
|
|
46
|
+
"positionChanged", oldCallbackId);
|
|
47
|
+
}
|
|
53
48
|
}
|
|
54
49
|
|
|
55
50
|
void AudioBufferBaseSourceNode::setOnPositionChangedInterval(int interval) {
|
|
@@ -66,14 +61,16 @@ std::mutex &AudioBufferBaseSourceNode::getBufferLock() {
|
|
|
66
61
|
}
|
|
67
62
|
|
|
68
63
|
void AudioBufferBaseSourceNode::sendOnPositionChangedEvent() {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
64
|
+
auto onPositionChangedCallbackId =
|
|
65
|
+
onPositionChangedCallbackId_.load(std::memory_order_acquire);
|
|
66
|
+
|
|
67
|
+
if (onPositionChangedCallbackId != 0 &&
|
|
68
|
+
onPositionChangedTime_ > onPositionChangedInterval_) {
|
|
72
69
|
std::unordered_map<std::string, EventValue> body = {
|
|
73
70
|
{"value", getCurrentPosition()}};
|
|
74
71
|
|
|
75
|
-
|
|
76
|
-
"positionChanged",
|
|
72
|
+
audioEventHandlerRegistry_->invokeHandlerWithEventBody(
|
|
73
|
+
"positionChanged", onPositionChangedCallbackId, body);
|
|
77
74
|
|
|
78
75
|
onPositionChangedTime_ = 0;
|
|
79
76
|
}
|
|
@@ -19,7 +19,6 @@ class AudioBufferBaseSourceNode : public AudioScheduledSourceNode {
|
|
|
19
19
|
[[nodiscard]] std::shared_ptr<AudioParam> getDetuneParam() const;
|
|
20
20
|
[[nodiscard]] std::shared_ptr<AudioParam> getPlaybackRateParam() const;
|
|
21
21
|
|
|
22
|
-
void clearOnPositionChangedCallback();
|
|
23
22
|
void setOnPositionChangedCallbackId(uint64_t callbackId);
|
|
24
23
|
void setOnPositionChangedInterval(int interval);
|
|
25
24
|
[[nodiscard]] int getOnPositionChangedInterval() const;
|
|
@@ -31,6 +31,12 @@ void AudioBufferQueueSourceNode::stop(double when) {
|
|
|
31
31
|
isPaused_ = false;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
+
void AudioBufferQueueSourceNode::start(double when) {
|
|
35
|
+
isPaused_ = false;
|
|
36
|
+
stopTime_ = -1.0;
|
|
37
|
+
AudioScheduledSourceNode::start(when);
|
|
38
|
+
}
|
|
39
|
+
|
|
34
40
|
void AudioBufferQueueSourceNode::pause() {
|
|
35
41
|
AudioScheduledSourceNode::stop(0.0);
|
|
36
42
|
isPaused_ = true;
|
|
@@ -79,6 +85,7 @@ void AudioBufferQueueSourceNode::disable() {
|
|
|
79
85
|
playbackState_ = PlaybackState::UNSCHEDULED;
|
|
80
86
|
startTime_ = -1.0;
|
|
81
87
|
stopTime_ = -1.0;
|
|
88
|
+
isPaused_ = false;
|
|
82
89
|
|
|
83
90
|
return;
|
|
84
91
|
}
|
|
@@ -21,6 +21,7 @@ class AudioBufferQueueSourceNode : public AudioBufferBaseSourceNode {
|
|
|
21
21
|
~AudioBufferQueueSourceNode() override;
|
|
22
22
|
|
|
23
23
|
void stop(double when) override;
|
|
24
|
+
void start(double when) override;
|
|
24
25
|
void pause();
|
|
25
26
|
|
|
26
27
|
std::string enqueueBuffer(const std::shared_ptr<AudioBuffer> &buffer);
|
|
@@ -123,19 +123,13 @@ void AudioBufferSourceNode::disable() {
|
|
|
123
123
|
alignedBus_.reset();
|
|
124
124
|
}
|
|
125
125
|
|
|
126
|
-
void AudioBufferSourceNode::clearOnLoopEndedCallback() {
|
|
127
|
-
if (onLoopEndedCallbackId_ == 0 || context_ == nullptr ||
|
|
128
|
-
context_->audioEventHandlerRegistry_ == nullptr) {
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
context_->audioEventHandlerRegistry_->unregisterHandler(
|
|
133
|
-
"loopEnded", onLoopEndedCallbackId_);
|
|
134
|
-
onLoopEndedCallbackId_ = 0;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
126
|
void AudioBufferSourceNode::setOnLoopEndedCallbackId(uint64_t callbackId) {
|
|
138
|
-
|
|
127
|
+
auto oldCallbackId =
|
|
128
|
+
onLoopEndedCallbackId_.exchange(callbackId, std::memory_order_acq_rel);
|
|
129
|
+
|
|
130
|
+
if (oldCallbackId != 0) {
|
|
131
|
+
audioEventHandlerRegistry_->unregisterHandler("loopEnded", oldCallbackId);
|
|
132
|
+
}
|
|
139
133
|
}
|
|
140
134
|
|
|
141
135
|
std::shared_ptr<AudioBus> AudioBufferSourceNode::processNode(
|
|
@@ -171,8 +165,8 @@ void AudioBufferSourceNode::sendOnLoopEndedEvent() {
|
|
|
171
165
|
auto onLoopEndedCallbackId =
|
|
172
166
|
onLoopEndedCallbackId_.load(std::memory_order_acquire);
|
|
173
167
|
if (onLoopEndedCallbackId != 0) {
|
|
174
|
-
|
|
175
|
-
"loopEnded",
|
|
168
|
+
audioEventHandlerRegistry_->invokeHandlerWithEventBody(
|
|
169
|
+
"loopEnded", onLoopEndedCallbackId, {});
|
|
176
170
|
}
|
|
177
171
|
}
|
|
178
172
|
|
|
@@ -34,7 +34,6 @@ class AudioBufferSourceNode : public AudioBufferBaseSourceNode {
|
|
|
34
34
|
void start(double when, double offset, double duration = -1);
|
|
35
35
|
void disable() override;
|
|
36
36
|
|
|
37
|
-
void clearOnLoopEndedCallback();
|
|
38
37
|
void setOnLoopEndedCallbackId(uint64_t callbackId);
|
|
39
38
|
|
|
40
39
|
protected:
|