react-native-audio-api 0.11.0-alpha.0 → 0.11.0-nightly-bfab178-20251107
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 -94
- package/android/src/main/cpp/audioapi/android/core/AndroidAudioRecorder.h +14 -28
- 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/BaseAudioContextHostObject.cpp +18 -0
- package/common/cpp/audioapi/HostObjects/BaseAudioContextHostObject.h +1 -0
- 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 -80
- package/common/cpp/audioapi/HostObjects/inputs/AudioRecorderHostObject.h +6 -15
- 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/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 +49 -102
- package/common/cpp/audioapi/core/inputs/AudioRecorder.h +28 -46
- 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/AudioBufferSourceNode.cpp +8 -14
- package/common/cpp/audioapi/core/sources/AudioBufferSourceNode.h +0 -1
- package/common/cpp/audioapi/core/sources/AudioScheduledSourceNode.cpp +14 -18
- package/common/cpp/audioapi/core/sources/AudioScheduledSourceNode.h +2 -2
- 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/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 +13 -0
- package/ios/audioapi/ios/core/IOSAudioRecorder.h +9 -18
- package/ios/audioapi/ios/core/IOSAudioRecorder.mm +28 -70
- package/ios/audioapi/ios/core/NativeAudioRecorder.h +6 -2
- package/ios/audioapi/ios/core/NativeAudioRecorder.m +73 -5
- 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 +12 -157
- 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 +12 -157
- 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 +6 -58
- 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 +8 -39
- 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 -74
- 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 +20 -190
- 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 +15 -47
- package/src/specs/NativeAudioAPIModule.ts +1 -0
- package/src/system/AudioManager.ts +4 -0
- package/src/types.ts +9 -84
- 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 -33
- 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 -431
- package/android/src/main/cpp/audioapi/android/core/utils/ffmpegBackend/FFmpegFileWriter.h +0 -112
- 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 -237
- package/android/src/main/cpp/audioapi/android/core/utils/miniaudioBackend/MiniAudioFileWriter.h +0 -46
- 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 -35
- package/ios/audioapi/ios/core/IOSAudioFileOptions.mm +0 -135
- package/ios/audioapi/ios/core/IOSAudioFileWriter.h +0 -38
- package/ios/audioapi/ios/core/IOSAudioFileWriter.mm +0 -187
- 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
|
@@ -25,14 +25,12 @@ StreamerNode::StreamerNode(BaseAudioContext *context)
|
|
|
25
25
|
codecpar_(nullptr),
|
|
26
26
|
pkt_(nullptr),
|
|
27
27
|
frame_(nullptr),
|
|
28
|
-
pendingFrame_(nullptr),
|
|
29
|
-
bufferedBus_(nullptr),
|
|
30
|
-
bufferedBusIndex_(0),
|
|
31
|
-
maxBufferSize_(0),
|
|
32
|
-
audio_stream_index_(-1),
|
|
33
28
|
swrCtx_(nullptr),
|
|
34
29
|
resampledData_(nullptr),
|
|
35
|
-
|
|
30
|
+
bufferedBus_(nullptr),
|
|
31
|
+
audio_stream_index_(-1),
|
|
32
|
+
maxResampledSamples_(0),
|
|
33
|
+
processedSamples_(0) {}
|
|
36
34
|
|
|
37
35
|
StreamerNode::~StreamerNode() {
|
|
38
36
|
cleanup();
|
|
@@ -66,26 +64,22 @@ bool StreamerNode::initialize(const std::string &input_url) {
|
|
|
66
64
|
return false;
|
|
67
65
|
}
|
|
68
66
|
|
|
69
|
-
maxBufferSize_ = BUFFER_LENGTH_SECONDS * codecCtx_->sample_rate;
|
|
70
|
-
// If decoding is faster than playing, we buffer few seconds of audio
|
|
71
|
-
bufferedBus_ = std::make_shared<AudioBus>(
|
|
72
|
-
maxBufferSize_, codecpar_->ch_layout.nb_channels, codecCtx_->sample_rate);
|
|
73
|
-
|
|
74
67
|
channelCount_ = codecpar_->ch_layout.nb_channels;
|
|
75
68
|
audioBus_ = std::make_shared<AudioBus>(
|
|
76
69
|
RENDER_QUANTUM_SIZE, channelCount_, context_->getSampleRate());
|
|
77
70
|
|
|
71
|
+
auto [sender, receiver] = channels::spsc::channel<
|
|
72
|
+
StreamingData,
|
|
73
|
+
channels::spsc::OverflowStrategy::WAIT_ON_FULL,
|
|
74
|
+
channels::spsc::WaitStrategy::ATOMIC_WAIT>(CHANNEL_CAPACITY);
|
|
75
|
+
sender_ = std::move(sender);
|
|
76
|
+
receiver_ = std::move(receiver);
|
|
77
|
+
|
|
78
78
|
streamingThread_ = std::thread(&StreamerNode::streamAudio, this);
|
|
79
|
-
streamFlag.store(true);
|
|
80
79
|
isInitialized_ = true;
|
|
81
80
|
return true;
|
|
82
81
|
}
|
|
83
82
|
|
|
84
|
-
void StreamerNode::stop(double when) {
|
|
85
|
-
AudioScheduledSourceNode::stop(when);
|
|
86
|
-
streamFlag.store(false);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
83
|
bool StreamerNode::setupResampler() {
|
|
90
84
|
// Allocate resampler context
|
|
91
85
|
swrCtx_ = swr_alloc();
|
|
@@ -122,30 +116,27 @@ bool StreamerNode::setupResampler() {
|
|
|
122
116
|
}
|
|
123
117
|
|
|
124
118
|
void StreamerNode::streamAudio() {
|
|
125
|
-
while (
|
|
126
|
-
if (
|
|
127
|
-
|
|
119
|
+
while (!isNodeFinished_.load(std::memory_order_acquire)) {
|
|
120
|
+
if (av_read_frame(fmtCtx_, pkt_) < 0) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
if (pkt_->stream_index == audio_stream_index_) {
|
|
124
|
+
if (avcodec_send_packet(codecCtx_, pkt_) != 0) {
|
|
128
125
|
return;
|
|
129
126
|
}
|
|
130
|
-
|
|
131
|
-
if (av_read_frame(fmtCtx_, pkt_) < 0) {
|
|
127
|
+
if (avcodec_receive_frame(codecCtx_, frame_) != 0) {
|
|
132
128
|
return;
|
|
133
129
|
}
|
|
134
|
-
if (
|
|
135
|
-
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
if (avcodec_receive_frame(codecCtx_, frame_) != 0) {
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
|
-
if (!processFrameWithResampler(frame_)) {
|
|
142
|
-
return;
|
|
143
|
-
}
|
|
130
|
+
if (!processFrameWithResampler(frame_)) {
|
|
131
|
+
return;
|
|
144
132
|
}
|
|
145
|
-
av_packet_unref(pkt_);
|
|
146
133
|
}
|
|
147
|
-
|
|
134
|
+
av_packet_unref(pkt_);
|
|
148
135
|
}
|
|
136
|
+
StreamingData dummy;
|
|
137
|
+
while (receiver_.try_receive(dummy) ==
|
|
138
|
+
channels::spsc::ResponseStatus::SUCCESS)
|
|
139
|
+
; // clear the receiver
|
|
149
140
|
}
|
|
150
141
|
|
|
151
142
|
std::shared_ptr<AudioBus> StreamerNode::processNode(
|
|
@@ -154,34 +145,44 @@ std::shared_ptr<AudioBus> StreamerNode::processNode(
|
|
|
154
145
|
size_t startOffset = 0;
|
|
155
146
|
size_t offsetLength = 0;
|
|
156
147
|
updatePlaybackInfo(processingBus, framesToProcess, startOffset, offsetLength);
|
|
148
|
+
isNodeFinished_.store(isFinished(), std::memory_order_release);
|
|
157
149
|
|
|
158
150
|
if (!isPlaying() && !isStopScheduled()) {
|
|
159
151
|
processingBus->zero();
|
|
160
152
|
return processingBus;
|
|
161
153
|
}
|
|
162
154
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
155
|
+
int bufferRemaining = bufferedBusSize_ - processedSamples_;
|
|
156
|
+
int alreadyProcessed = 0;
|
|
157
|
+
if (bufferRemaining < framesToProcess) {
|
|
158
|
+
if (bufferedBus_ != nullptr) {
|
|
159
|
+
for (int ch = 0; ch < processingBus->getNumberOfChannels(); ch++) {
|
|
160
|
+
memcpy(
|
|
161
|
+
processingBus->getChannel(ch)->getData(),
|
|
162
|
+
bufferedBus_->getChannel(ch)->getData() + processedSamples_,
|
|
163
|
+
bufferRemaining * sizeof(float));
|
|
164
|
+
}
|
|
165
|
+
framesToProcess -= bufferRemaining;
|
|
166
|
+
alreadyProcessed += bufferRemaining;
|
|
167
|
+
}
|
|
168
|
+
StreamingData data;
|
|
169
|
+
auto res = receiver_.try_receive(data);
|
|
170
|
+
if (res == channels::spsc::ResponseStatus::SUCCESS) {
|
|
171
|
+
bufferedBus_ = std::make_shared<AudioBus>(std::move(data.bus));
|
|
172
|
+
bufferedBusSize_ = data.size;
|
|
173
|
+
processedSamples_ = 0;
|
|
174
|
+
} else {
|
|
175
|
+
bufferedBus_ = nullptr;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
if (bufferedBus_ != nullptr) {
|
|
166
179
|
for (int ch = 0; ch < processingBus->getNumberOfChannels(); ch++) {
|
|
167
180
|
memcpy(
|
|
168
|
-
processingBus->getChannel(ch)->getData(),
|
|
169
|
-
bufferedBus_->getChannel(ch)->getData(),
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
memmove(
|
|
173
|
-
bufferedBus_->getChannel(ch)->getData(),
|
|
174
|
-
bufferedBus_->getChannel(ch)->getData() + offsetLength,
|
|
175
|
-
(maxBufferSize_ - offsetLength) * sizeof(float));
|
|
181
|
+
processingBus->getChannel(ch)->getData() + alreadyProcessed,
|
|
182
|
+
bufferedBus_->getChannel(ch)->getData() + processedSamples_,
|
|
183
|
+
framesToProcess * sizeof(float));
|
|
176
184
|
}
|
|
177
|
-
|
|
178
|
-
} else {
|
|
179
|
-
if (VERBOSE)
|
|
180
|
-
printf(
|
|
181
|
-
"Buffer underrun: have %zu, need %zu\n",
|
|
182
|
-
bufferedBusIndex_,
|
|
183
|
-
(size_t)framesToProcess);
|
|
184
|
-
processingBus->zero();
|
|
185
|
+
processedSamples_ += framesToProcess;
|
|
185
186
|
}
|
|
186
187
|
|
|
187
188
|
return processingBus;
|
|
@@ -220,22 +221,21 @@ bool StreamerNode::processFrameWithResampler(AVFrame *frame) {
|
|
|
220
221
|
return false;
|
|
221
222
|
}
|
|
222
223
|
|
|
223
|
-
//
|
|
224
|
-
if (
|
|
225
|
-
pendingFrame_ = frame;
|
|
224
|
+
// if we would like to finish dont copy anything
|
|
225
|
+
if (this->isFinished()) {
|
|
226
226
|
return true;
|
|
227
|
-
} else {
|
|
228
|
-
pendingFrame_ = nullptr;
|
|
229
227
|
}
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
228
|
+
auto bus = AudioBus(
|
|
229
|
+
static_cast<size_t>(converted_samples),
|
|
230
|
+
codecCtx_->ch_layout.nb_channels,
|
|
231
|
+
context_->getSampleRate());
|
|
233
232
|
for (int ch = 0; ch < codecCtx_->ch_layout.nb_channels; ch++) {
|
|
234
233
|
auto *src = reinterpret_cast<float *>(resampledData_[ch]);
|
|
235
|
-
float *dst =
|
|
234
|
+
float *dst = bus.getChannel(ch)->getData();
|
|
236
235
|
memcpy(dst, src, converted_samples * sizeof(float));
|
|
237
236
|
}
|
|
238
|
-
|
|
237
|
+
StreamingData data{std::move(bus), static_cast<size_t>(converted_samples)};
|
|
238
|
+
sender_.send(std::move(data));
|
|
239
239
|
return true;
|
|
240
240
|
}
|
|
241
241
|
|
|
@@ -280,7 +280,7 @@ bool StreamerNode::setupDecoder() {
|
|
|
280
280
|
}
|
|
281
281
|
|
|
282
282
|
void StreamerNode::cleanup() {
|
|
283
|
-
|
|
283
|
+
this->playbackState_ = PlaybackState::FINISHED;
|
|
284
284
|
// cleanup cannot be called from the streaming thread so there is no need to
|
|
285
285
|
// check if we are in the same thread
|
|
286
286
|
streamingThread_.join();
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
#pragma once
|
|
12
12
|
|
|
13
13
|
#include <audioapi/core/sources/AudioScheduledSourceNode.h>
|
|
14
|
+
#include <audioapi/utils/AudioBus.h>
|
|
14
15
|
|
|
15
16
|
#ifndef AUDIO_API_TEST_SUITE
|
|
16
17
|
extern "C" {
|
|
@@ -27,8 +28,35 @@ extern "C" {
|
|
|
27
28
|
#include <memory>
|
|
28
29
|
#include <string>
|
|
29
30
|
#include <atomic>
|
|
31
|
+
#include <utility>
|
|
32
|
+
#ifndef AUDIO_API_TEST_SUITE
|
|
33
|
+
#include <audioapi/utils/SpscChannel.hpp>
|
|
30
34
|
|
|
31
|
-
static
|
|
35
|
+
static constexpr audioapi::channels::spsc::OverflowStrategy STREAMER_NODE_SPSC_OVERFLOW_STRATEGY =
|
|
36
|
+
audioapi::channels::spsc::OverflowStrategy::WAIT_ON_FULL;
|
|
37
|
+
static constexpr audioapi::channels::spsc::WaitStrategy STREAMER_NODE_SPSC_WAIT_STRATEGY =
|
|
38
|
+
audioapi::channels::spsc::WaitStrategy::ATOMIC_WAIT;
|
|
39
|
+
#endif
|
|
40
|
+
|
|
41
|
+
static constexpr bool VERBOSE = false;
|
|
42
|
+
static constexpr int CHANNEL_CAPACITY = 32;
|
|
43
|
+
|
|
44
|
+
struct StreamingData{
|
|
45
|
+
audioapi::AudioBus bus;
|
|
46
|
+
size_t size;
|
|
47
|
+
StreamingData() = default;
|
|
48
|
+
StreamingData(audioapi::AudioBus b, size_t s) : bus(b), size(s) {}
|
|
49
|
+
StreamingData(const StreamingData& data) : bus(data.bus), size(data.size) {}
|
|
50
|
+
StreamingData(StreamingData&& data) noexcept : bus(std::move(data.bus)), size(data.size) {}
|
|
51
|
+
StreamingData& operator=(const StreamingData& data) {
|
|
52
|
+
if (this == &data) {
|
|
53
|
+
return *this;
|
|
54
|
+
}
|
|
55
|
+
bus = data.bus;
|
|
56
|
+
size = data.size;
|
|
57
|
+
return *this;
|
|
58
|
+
}
|
|
59
|
+
};
|
|
32
60
|
|
|
33
61
|
namespace audioapi {
|
|
34
62
|
|
|
@@ -43,7 +71,6 @@ class StreamerNode : public AudioScheduledSourceNode {
|
|
|
43
71
|
* @brief Initialize all necessary ffmpeg components for streaming audio
|
|
44
72
|
*/
|
|
45
73
|
bool initialize(const std::string& inputUrl);
|
|
46
|
-
void stop(double when) override;
|
|
47
74
|
|
|
48
75
|
protected:
|
|
49
76
|
std::shared_ptr<AudioBus> processNode(const std::shared_ptr<AudioBus>& processingBus, int framesToProcess) override;
|
|
@@ -56,19 +83,20 @@ class StreamerNode : public AudioScheduledSourceNode {
|
|
|
56
83
|
AVCodecParameters* codecpar_;
|
|
57
84
|
AVPacket* pkt_;
|
|
58
85
|
AVFrame* frame_; // Frame that is currently being processed
|
|
59
|
-
AVFrame* pendingFrame_; // Frame that is saved if bufferedBus is full
|
|
60
|
-
std::shared_ptr<AudioBus> bufferedBus_; // audio bus for buffering hls frames
|
|
61
|
-
size_t bufferedBusIndex_; // index in the buffered bus where we write the next frame
|
|
62
|
-
size_t maxBufferSize_; // maximum size of the buffered bus
|
|
63
|
-
int audio_stream_index_; // index of the audio stream channel in the input
|
|
64
86
|
SwrContext* swrCtx_;
|
|
65
87
|
uint8_t** resampledData_; // weird ffmpeg way of using raw byte pointers for resampled data
|
|
88
|
+
|
|
89
|
+
std::shared_ptr<AudioBus> bufferedBus_; // audio bus for buffering hls frames
|
|
90
|
+
size_t bufferedBusSize_; // size of currently buffered bus
|
|
91
|
+
int audio_stream_index_; // index of the audio stream channel in the input
|
|
66
92
|
int maxResampledSamples_;
|
|
67
|
-
|
|
93
|
+
size_t processedSamples_;
|
|
94
|
+
|
|
68
95
|
std::thread streamingThread_;
|
|
69
|
-
std::atomic<bool>
|
|
70
|
-
static constexpr float BUFFER_LENGTH_SECONDS = 5.0f; // Length of the buffer in seconds
|
|
96
|
+
std::atomic<bool> isNodeFinished_; // Flag to control the streaming thread
|
|
71
97
|
static constexpr int INITIAL_MAX_RESAMPLED_SAMPLES = 8192; // Initial size for resampled data
|
|
98
|
+
channels::spsc::Sender<StreamingData, STREAMER_NODE_SPSC_OVERFLOW_STRATEGY, STREAMER_NODE_SPSC_WAIT_STRATEGY> sender_;
|
|
99
|
+
channels::spsc::Receiver<StreamingData, STREAMER_NODE_SPSC_OVERFLOW_STRATEGY, STREAMER_NODE_SPSC_WAIT_STRATEGY> receiver_;
|
|
72
100
|
|
|
73
101
|
/**
|
|
74
102
|
* @brief Setting up the resampler
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
#include <audioapi/core/AudioNode.h>
|
|
2
2
|
#include <audioapi/core/AudioParam.h>
|
|
3
|
+
#include <audioapi/core/effects/ConvolverNode.h>
|
|
3
4
|
#include <audioapi/core/sources/AudioScheduledSourceNode.h>
|
|
4
5
|
#include <audioapi/core/utils/AudioNodeManager.h>
|
|
5
6
|
#include <audioapi/core/utils/Locker.h>
|
|
@@ -221,6 +222,10 @@ inline bool AudioNodeManager::nodeCanBeDestructed(
|
|
|
221
222
|
if constexpr (std::is_base_of_v<AudioScheduledSourceNode, U>) {
|
|
222
223
|
return node.use_count() == 1 &&
|
|
223
224
|
(node->isUnscheduled() || node->isFinished());
|
|
225
|
+
} else if constexpr (std::is_base_of_v<
|
|
226
|
+
ConvolverNode,
|
|
227
|
+
U>) { // convolver overrides disabling behavior
|
|
228
|
+
return node.use_count() == 1 && !node->isEnabled();
|
|
224
229
|
}
|
|
225
230
|
return node.use_count() == 1;
|
|
226
231
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
#pragma once
|
|
2
2
|
|
|
3
|
+
#include <numbers>
|
|
3
4
|
#include <cmath>
|
|
4
5
|
#include <limits>
|
|
5
6
|
|
|
@@ -19,7 +20,7 @@ static constexpr float MOST_POSITIVE_SINGLE_FLOAT = static_cast<float>(std::nume
|
|
|
19
20
|
static constexpr float MOST_NEGATIVE_SINGLE_FLOAT = static_cast<float>(std::numeric_limits<float>::lowest());
|
|
20
21
|
static float LOG2_MOST_POSITIVE_SINGLE_FLOAT = std::log2(MOST_POSITIVE_SINGLE_FLOAT);
|
|
21
22
|
static float LOG10_MOST_POSITIVE_SINGLE_FLOAT = std::log10(MOST_POSITIVE_SINGLE_FLOAT);
|
|
22
|
-
static constexpr float PI =
|
|
23
|
+
static constexpr float PI = std::numbers::pi_v<float>;
|
|
23
24
|
|
|
24
25
|
// buffer sizes
|
|
25
26
|
static constexpr size_t PROMISE_VENDOR_THREAD_POOL_WORKER_COUNT = 4;
|
|
@@ -5,14 +5,8 @@
|
|
|
5
5
|
#include <string>
|
|
6
6
|
#include <memory>
|
|
7
7
|
|
|
8
|
-
#
|
|
9
|
-
|
|
10
|
-
/// they should be accessible if someone has react-native-worklets in node_modules
|
|
11
|
-
#if __has_include(<worklets/WorkletRuntime/WorkletRuntime.h>)
|
|
12
|
-
#define RN_AUDIO_API_ENABLE_WORKLETS 1
|
|
13
|
-
#else
|
|
14
|
-
#define RN_AUDIO_API_ENABLE_WORKLETS 0
|
|
15
|
-
#endif
|
|
8
|
+
#if ANDROID
|
|
9
|
+
#include <fbjni/detail/Environment.h>
|
|
16
10
|
#endif
|
|
17
11
|
|
|
18
12
|
#ifndef RN_AUDIO_API_TEST
|
|
@@ -78,4 +72,14 @@ class SerializableWorklet {
|
|
|
78
72
|
struct RuntimeRegistry {
|
|
79
73
|
std::weak_ptr<worklets::WorkletRuntime> uiRuntime;
|
|
80
74
|
std::shared_ptr<worklets::WorkletRuntime> audioRuntime;
|
|
75
|
+
|
|
76
|
+
#if ANDROID
|
|
77
|
+
~RuntimeRegistry() {
|
|
78
|
+
facebook::jni::ThreadScope::WithClassLoader(
|
|
79
|
+
[this]() {
|
|
80
|
+
uiRuntime.reset();
|
|
81
|
+
audioRuntime.reset();
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
#endif
|
|
81
85
|
};
|
|
@@ -4,7 +4,7 @@ namespace audioapi {
|
|
|
4
4
|
|
|
5
5
|
WorkletsRunner::WorkletsRunner(
|
|
6
6
|
std::weak_ptr<worklets::WorkletRuntime> weakRuntime,
|
|
7
|
-
std::shared_ptr<worklets::SerializableWorklet> shareableWorklet,
|
|
7
|
+
const std::shared_ptr<worklets::SerializableWorklet> &shareableWorklet,
|
|
8
8
|
bool shouldLockRuntime)
|
|
9
9
|
: weakRuntime_(std::move(weakRuntime)),
|
|
10
10
|
shouldLockRuntime(shouldLockRuntime) {
|
|
@@ -33,8 +33,8 @@ WorkletsRunner::WorkletsRunner(
|
|
|
33
33
|
WorkletsRunner::WorkletsRunner(WorkletsRunner &&other)
|
|
34
34
|
: weakRuntime_(std::move(other.weakRuntime_)),
|
|
35
35
|
unsafeRuntimePtr(other.unsafeRuntimePtr),
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
workletInitialized(other.workletInitialized),
|
|
37
|
+
shouldLockRuntime(other.shouldLockRuntime) {
|
|
38
38
|
if (workletInitialized) {
|
|
39
39
|
std::memcpy(&unsafeWorklet, &other.unsafeWorklet, sizeof(unsafeWorklet));
|
|
40
40
|
other.workletInitialized = false;
|
|
@@ -28,7 +28,7 @@ class WorkletsRunner {
|
|
|
28
28
|
public:
|
|
29
29
|
explicit WorkletsRunner(
|
|
30
30
|
std::weak_ptr<worklets::WorkletRuntime> weakRuntime,
|
|
31
|
-
std::shared_ptr<worklets::SerializableWorklet
|
|
31
|
+
const std::shared_ptr<worklets::SerializableWorklet>& shareableWorklet,
|
|
32
32
|
bool shouldLockRuntime = true);
|
|
33
33
|
WorkletsRunner(WorkletsRunner&&);
|
|
34
34
|
~WorkletsRunner();
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
// implementation of linear convolution algorithm described in this paper:
|
|
2
|
+
// https://publications.rwth-aachen.de/record/466561/files/466561.pdf page 110
|
|
3
|
+
|
|
4
|
+
#if defined(__ARM_NEON)
|
|
5
|
+
#include <arm_neon.h>
|
|
6
|
+
#endif
|
|
7
|
+
|
|
8
|
+
#include <audioapi/core/sources/AudioBuffer.h>
|
|
9
|
+
#include <audioapi/dsp/Convolver.h>
|
|
10
|
+
#include <audioapi/dsp/VectorMath.h>
|
|
11
|
+
#include <audioapi/utils/AudioArray.h>
|
|
12
|
+
#include <chrono>
|
|
13
|
+
#include <iostream>
|
|
14
|
+
|
|
15
|
+
namespace audioapi {
|
|
16
|
+
|
|
17
|
+
Convolver::Convolver()
|
|
18
|
+
: _blockSize(0),
|
|
19
|
+
_segSize(0),
|
|
20
|
+
_segCount(0),
|
|
21
|
+
_fftComplexSize(0),
|
|
22
|
+
_segments(),
|
|
23
|
+
_segmentsIR(),
|
|
24
|
+
_fftBuffer(0),
|
|
25
|
+
_fft(nullptr),
|
|
26
|
+
_preMultiplied(),
|
|
27
|
+
_current(0),
|
|
28
|
+
_inputBuffer(0) {}
|
|
29
|
+
|
|
30
|
+
void Convolver::reset() {
|
|
31
|
+
_blockSize = 0;
|
|
32
|
+
_segSize = 0;
|
|
33
|
+
_segCount = 0;
|
|
34
|
+
_fftComplexSize = 0;
|
|
35
|
+
_current = 0;
|
|
36
|
+
_fft = nullptr;
|
|
37
|
+
_segments.clear();
|
|
38
|
+
_segmentsIR.clear();
|
|
39
|
+
_preMultiplied.clear();
|
|
40
|
+
_fftBuffer.zero();
|
|
41
|
+
_inputBuffer.zero();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
bool Convolver::init(
|
|
45
|
+
size_t blockSize,
|
|
46
|
+
const audioapi::AudioArray &ir,
|
|
47
|
+
size_t irLen) {
|
|
48
|
+
reset();
|
|
49
|
+
// blockSize must be a power of two
|
|
50
|
+
if ((blockSize & (blockSize - 1))) {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Ignore zeros at the end of the impulse response because they only waste
|
|
55
|
+
// computation time
|
|
56
|
+
_blockSize = blockSize;
|
|
57
|
+
_trueSegmentCount = (size_t)(std::ceil((float)irLen / (float)_blockSize));
|
|
58
|
+
while (irLen > 0 && ::fabs(ir[irLen - 1]) < 10e-3) {
|
|
59
|
+
--irLen;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (irLen == 0) {
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// The length-N is split into P = N/B length-B sub filters
|
|
67
|
+
_segCount = (size_t)(std::ceil((float)irLen / (float)_blockSize));
|
|
68
|
+
_segSize = 2 * _blockSize;
|
|
69
|
+
// size of the FFT is 2B, so the complex size is B+1, due to the
|
|
70
|
+
// complex-conjugate symmetricity
|
|
71
|
+
_fftComplexSize = _segSize / 2 + 1;
|
|
72
|
+
_fft = std::make_shared<dsp::FFT>((int)_segSize);
|
|
73
|
+
_fftBuffer.resize(_segSize);
|
|
74
|
+
|
|
75
|
+
// segments preparation
|
|
76
|
+
for (int i = 0; i < _segCount; ++i) {
|
|
77
|
+
aligned_vec_complex vec(_fftComplexSize, std::complex<float>(0.0f, 0.0f));
|
|
78
|
+
_segments.push_back(vec);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// ir preparation
|
|
82
|
+
for (int i = 0; i < _segCount; ++i) {
|
|
83
|
+
aligned_vec_complex segment(_fftComplexSize);
|
|
84
|
+
const size_t remainingSamples = irLen - (i * _blockSize);
|
|
85
|
+
const size_t samplesToCopy = std::min(_blockSize, remainingSamples);
|
|
86
|
+
|
|
87
|
+
if (samplesToCopy > 0) {
|
|
88
|
+
memcpy(
|
|
89
|
+
_fftBuffer.getData(),
|
|
90
|
+
ir.getData() + i * _blockSize,
|
|
91
|
+
samplesToCopy * sizeof(float));
|
|
92
|
+
}
|
|
93
|
+
// Each sub filter is zero-padded to length 2B and transformed using a
|
|
94
|
+
// 2B-point real-to-complex FFT.
|
|
95
|
+
memset(_fftBuffer.getData() + _blockSize, 0, _blockSize * sizeof(float));
|
|
96
|
+
_fft->doFFT(_fftBuffer.getData(), segment);
|
|
97
|
+
segment.at(0).imag(0.0f); // ensure DC component is real
|
|
98
|
+
_segmentsIR.push_back(segment);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
_preMultiplied = aligned_vec_complex(_fftComplexSize);
|
|
102
|
+
_inputBuffer.resize(_segSize);
|
|
103
|
+
_current = 0;
|
|
104
|
+
|
|
105
|
+
return true;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/// @brief Fast pairwise complex multiplication using ARM NEON intrinsics
|
|
109
|
+
/// @param ir Impulse response
|
|
110
|
+
/// @param audio Input audio signal
|
|
111
|
+
/// @param pre Output buffer for pre-multiplied results
|
|
112
|
+
/// @note IMPORTANT: ir, audio, and pre must be the same size and should be
|
|
113
|
+
/// aligned to 16 bytes for optimal performance
|
|
114
|
+
void pairwise_complex_multiply_fast(
|
|
115
|
+
const Convolver::aligned_vec_complex &ir,
|
|
116
|
+
const Convolver::aligned_vec_complex &audio,
|
|
117
|
+
Convolver::aligned_vec_complex &pre) {
|
|
118
|
+
size_t n = ir.size();
|
|
119
|
+
|
|
120
|
+
/// @note Using ARM NEON intrinsics for SIMD optimization
|
|
121
|
+
/// This implementation is on average 2x faster than the scalar version on ARM
|
|
122
|
+
/// architectures With 16-byte alignment it can be even faster up to 2.5x
|
|
123
|
+
#ifdef __ARM_NEON
|
|
124
|
+
size_t j = 0;
|
|
125
|
+
|
|
126
|
+
// Main vector loop: process 4 complex samples (8 floats) per iteration using
|
|
127
|
+
// vld2q/vst2q deinterleave
|
|
128
|
+
for (; j <= n - 4; j += 4) {
|
|
129
|
+
// load de-interleaved real/imag for 4 complex values
|
|
130
|
+
float32x4x2_t ir_de = vld2q_f32(reinterpret_cast<const float *>(&ir[j]));
|
|
131
|
+
float32x4x2_t a_de = vld2q_f32(reinterpret_cast<const float *>(&audio[j]));
|
|
132
|
+
float32x4x2_t pre_de = vld2q_f32(reinterpret_cast<float *>(&pre[j]));
|
|
133
|
+
|
|
134
|
+
float32x4_t ir_re = ir_de.val[0];
|
|
135
|
+
float32x4_t ir_im = ir_de.val[1];
|
|
136
|
+
float32x4_t a_re = a_de.val[0];
|
|
137
|
+
float32x4_t a_im = a_de.val[1];
|
|
138
|
+
|
|
139
|
+
// real = ir_re * a_re - ir_im * a_im
|
|
140
|
+
float32x4_t real = vmulq_f32(ir_re, a_re);
|
|
141
|
+
real = vmlsq_f32(real, ir_im, a_im);
|
|
142
|
+
// imag = ir_re * a_im + ir_im * a_re
|
|
143
|
+
float32x4_t imag = vmulq_f32(ir_re, a_im);
|
|
144
|
+
imag = vmlaq_f32(imag, ir_im, a_re);
|
|
145
|
+
|
|
146
|
+
// accumulate into pre
|
|
147
|
+
float32x4_t new_re = vaddq_f32(pre_de.val[0], real);
|
|
148
|
+
float32x4_t new_im = vaddq_f32(pre_de.val[1], imag);
|
|
149
|
+
|
|
150
|
+
float32x4x2_t out_de;
|
|
151
|
+
out_de.val[0] = new_re;
|
|
152
|
+
out_de.val[1] = new_im;
|
|
153
|
+
|
|
154
|
+
vst2q_f32(reinterpret_cast<float *>(&pre[j]), out_de);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// Tail
|
|
158
|
+
for (; j < n; ++j) {
|
|
159
|
+
pre[j] += ir[j] * audio[j];
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
#else
|
|
163
|
+
// Fallback scalar implementation
|
|
164
|
+
for (size_t i = 0; i < n; ++i) {
|
|
165
|
+
pre[i] += ir[i] * audio[i];
|
|
166
|
+
}
|
|
167
|
+
#endif
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
void Convolver::process(float *data, float *outputData) {
|
|
171
|
+
// The input buffer acts as a 2B-point sliding window of the input signal.
|
|
172
|
+
// With each new input block, the right half of the input buffer is shifted
|
|
173
|
+
// to the left and the new block is stored in the right half.
|
|
174
|
+
memmove(
|
|
175
|
+
_inputBuffer.getData(),
|
|
176
|
+
_inputBuffer.getData() + _blockSize,
|
|
177
|
+
_blockSize * sizeof(float));
|
|
178
|
+
memcpy(_inputBuffer.getData() + _blockSize, data, _blockSize * sizeof(float));
|
|
179
|
+
|
|
180
|
+
// All contents (DFT spectra) in the FDL are shifted up by one slot.
|
|
181
|
+
_current = (_current > 0) ? _current - 1 : _segCount - 1;
|
|
182
|
+
// A 2B-point real-to-complex FFT is computed from the input buffer,
|
|
183
|
+
// resulting in B+1 complex-conjugate symmetric DFT coefficients. The
|
|
184
|
+
// result is stored in the first FDL slot.
|
|
185
|
+
// _current marks first FDL slot, which is the current input block.
|
|
186
|
+
_fft->doFFT(_inputBuffer.getData(), _segments[_current]);
|
|
187
|
+
_segments[_current][0].imag(0.0f); // ensure DC component is real
|
|
188
|
+
|
|
189
|
+
// The P sub filter spectra are pairwisely multiplied with the input spectra
|
|
190
|
+
// in the FDL. The results are accumulated in the frequency-domain.
|
|
191
|
+
memset(
|
|
192
|
+
_preMultiplied.data(),
|
|
193
|
+
0,
|
|
194
|
+
_preMultiplied.size() * sizeof(std::complex<float>));
|
|
195
|
+
// this is a bottleneck of the algorithm
|
|
196
|
+
for (int i = 0; i < _segCount; ++i) {
|
|
197
|
+
const int indexAudio = (_current + i) % _segCount;
|
|
198
|
+
const auto &impulseResponseSegment = _segmentsIR[i];
|
|
199
|
+
const auto &audioSegment = _segments[indexAudio];
|
|
200
|
+
pairwise_complex_multiply_fast(
|
|
201
|
+
impulseResponseSegment, audioSegment, _preMultiplied);
|
|
202
|
+
}
|
|
203
|
+
// Of the accumulated spectral convolutions, an 2B-point complex-to-real
|
|
204
|
+
// IFFT is computed. From the resulting 2B samples, the left half is
|
|
205
|
+
// discarded and the right half is returned as the next output block.
|
|
206
|
+
_fft->doInverseFFT(_preMultiplied, _fftBuffer.getData());
|
|
207
|
+
|
|
208
|
+
memcpy(
|
|
209
|
+
outputData,
|
|
210
|
+
_fftBuffer.getData() + _blockSize,
|
|
211
|
+
_blockSize * sizeof(float));
|
|
212
|
+
}
|
|
213
|
+
} // namespace audioapi
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <audioapi/utils/AudioArray.h>
|
|
4
|
+
#include <audioapi/dsp/FFT.h>
|
|
5
|
+
#include <vector>
|
|
6
|
+
#include <cstring>
|
|
7
|
+
#include <complex>
|
|
8
|
+
#include <memory>
|
|
9
|
+
#include <audioapi/utils/AlignedAllocator.hpp>
|
|
10
|
+
|
|
11
|
+
namespace audioapi {
|
|
12
|
+
|
|
13
|
+
class AudioBuffer;
|
|
14
|
+
|
|
15
|
+
class Convolver {
|
|
16
|
+
using aligned_vec_complex =
|
|
17
|
+
std::vector<std::complex<float>, AlignedAllocator<std::complex<float>, 16>>;
|
|
18
|
+
|
|
19
|
+
public:
|
|
20
|
+
Convolver();
|
|
21
|
+
bool init(size_t blockSize, const AudioArray &ir, size_t irLen);
|
|
22
|
+
void process(float* inputData, float* outputData);
|
|
23
|
+
void reset();
|
|
24
|
+
inline size_t getSegCount() const { return _trueSegmentCount; }
|
|
25
|
+
|
|
26
|
+
private:
|
|
27
|
+
size_t _trueSegmentCount;
|
|
28
|
+
size_t _blockSize;
|
|
29
|
+
size_t _segSize;
|
|
30
|
+
size_t _segCount;
|
|
31
|
+
size_t _fftComplexSize;
|
|
32
|
+
std::vector<aligned_vec_complex> _segments;
|
|
33
|
+
std::vector<aligned_vec_complex> _segmentsIR;
|
|
34
|
+
AudioArray _fftBuffer;
|
|
35
|
+
std::shared_ptr<dsp::FFT> _fft;
|
|
36
|
+
aligned_vec_complex _preMultiplied;
|
|
37
|
+
size_t _current;
|
|
38
|
+
AudioArray _inputBuffer;
|
|
39
|
+
|
|
40
|
+
friend void pairwise_complex_multiply_fast(
|
|
41
|
+
const aligned_vec_complex& ir,
|
|
42
|
+
const aligned_vec_complex& audio,
|
|
43
|
+
aligned_vec_complex& pre);
|
|
44
|
+
};
|
|
45
|
+
} // namespace audioapi
|
|
@@ -12,30 +12,4 @@ FFT::~FFT() {
|
|
|
12
12
|
pffft_aligned_free(work_);
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
void FFT::doFFT(float *in, std::vector<std::complex<float>> &out) {
|
|
16
|
-
pffft_transform_ordered(
|
|
17
|
-
pffftSetup_,
|
|
18
|
-
in,
|
|
19
|
-
reinterpret_cast<float *>(&out[0]),
|
|
20
|
-
work_,
|
|
21
|
-
PFFFT_FORWARD);
|
|
22
|
-
|
|
23
|
-
dsp::multiplyByScalar(
|
|
24
|
-
reinterpret_cast<float *>(&out[0]),
|
|
25
|
-
0.5f,
|
|
26
|
-
reinterpret_cast<float *>(&out[0]),
|
|
27
|
-
size_ * 2);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
void FFT::doInverseFFT(std::vector<std::complex<float>> &in, float *out) {
|
|
31
|
-
pffft_transform_ordered(
|
|
32
|
-
pffftSetup_,
|
|
33
|
-
reinterpret_cast<float *>(&in[0]),
|
|
34
|
-
out,
|
|
35
|
-
work_,
|
|
36
|
-
PFFFT_BACKWARD);
|
|
37
|
-
|
|
38
|
-
dsp::multiplyByScalar(out, 1.0f / static_cast<float>(size_), out, size_);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
15
|
} // namespace audioapi::dsp
|