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
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
|
|
3
|
-
#ifndef __OBJC__ // when compiled as C++
|
|
4
|
-
typedef struct objc_object AVAudioFile;
|
|
5
|
-
typedef struct objc_object NSURL;
|
|
6
|
-
typedef struct objc_object AudioBufferList;
|
|
7
|
-
#endif // __OBJC__
|
|
8
|
-
|
|
9
|
-
namespace audioapi {
|
|
10
|
-
|
|
11
|
-
class IOSAudioFileOptions {
|
|
12
|
-
public:
|
|
13
|
-
IOSAudioFileOptions(float sampleRate, size_t channelCount, size_t bitRate, size_t flags);
|
|
14
|
-
~IOSAudioFileOptions() = default;
|
|
15
|
-
|
|
16
|
-
AudioFormatID getFormat() const;
|
|
17
|
-
NSInteger getQuality() const;
|
|
18
|
-
NSInteger getFlacCompressionLevel() const;
|
|
19
|
-
NSSearchPathDirectory getDirectory() const;
|
|
20
|
-
NSString *getFileExtension() const;
|
|
21
|
-
NSInteger getBitDepth() const;
|
|
22
|
-
NSDictionary *getFileSettings();
|
|
23
|
-
float getSampleRate();
|
|
24
|
-
|
|
25
|
-
private:
|
|
26
|
-
uint8_t format_;
|
|
27
|
-
uint8_t quality_;
|
|
28
|
-
uint8_t flacCompressionLevel_;
|
|
29
|
-
uint8_t directory_;
|
|
30
|
-
uint8_t bitDepth_;
|
|
31
|
-
float sampleRate_;
|
|
32
|
-
size_t channelCount_;
|
|
33
|
-
size_t bitRate_;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
} // namespace audioapi
|
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
#import <AVFoundation/AVFoundation.h>
|
|
2
|
-
#import <Foundation/Foundation.h>
|
|
3
|
-
|
|
4
|
-
#include <audioapi/ios/core/IOSAudioFileOptions.h>
|
|
5
|
-
|
|
6
|
-
namespace audioapi {
|
|
7
|
-
|
|
8
|
-
IOSAudioFileOptions::IOSAudioFileOptions(float sampleRate, size_t channelCount, size_t bitRate, size_t flags)
|
|
9
|
-
{
|
|
10
|
-
sampleRate_ = sampleRate;
|
|
11
|
-
channelCount_ = channelCount;
|
|
12
|
-
bitRate_ = bitRate;
|
|
13
|
-
|
|
14
|
-
format_ = static_cast<uint8_t>(((flags >> 0) & 0xF));
|
|
15
|
-
quality_ = static_cast<uint8_t>(((flags >> 4) & 0xF));
|
|
16
|
-
flacCompressionLevel_ = static_cast<uint8_t>(((flags >> 8) & 0xF));
|
|
17
|
-
directory_ = static_cast<uint8_t>(((flags >> 12) & 0xF));
|
|
18
|
-
bitDepth_ = static_cast<uint8_t>(((flags >> 16) & 0xF));
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
AudioFormatID IOSAudioFileOptions::getFormat() const
|
|
22
|
-
{
|
|
23
|
-
switch (format_) {
|
|
24
|
-
case 1:
|
|
25
|
-
return kAudioFormatLinearPCM; // WAV <-> Linear PCM container
|
|
26
|
-
case 2:
|
|
27
|
-
return kAudioFormatLinearPCM; // CAF <-> Linear PCM container
|
|
28
|
-
case 3:
|
|
29
|
-
return kAudioFormatMPEG4AAC; // M4A <-> AAC
|
|
30
|
-
case 4:
|
|
31
|
-
return kAudioFormatFLAC; // FLAC <-> FLAC
|
|
32
|
-
default:
|
|
33
|
-
return kAudioFormatLinearPCM; // Default to Linear PCM
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
NSInteger IOSAudioFileOptions::getQuality() const
|
|
38
|
-
{
|
|
39
|
-
switch (quality_) {
|
|
40
|
-
case 1:
|
|
41
|
-
return AVAudioQualityMin;
|
|
42
|
-
case 2:
|
|
43
|
-
return AVAudioQualityLow;
|
|
44
|
-
case 3:
|
|
45
|
-
return AVAudioQualityMedium;
|
|
46
|
-
case 4:
|
|
47
|
-
return AVAudioQualityHigh;
|
|
48
|
-
case 5:
|
|
49
|
-
return AVAudioQualityMax;
|
|
50
|
-
default:
|
|
51
|
-
return AVAudioQualityMedium; // Default to Medium
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
NSInteger IOSAudioFileOptions::getFlacCompressionLevel() const
|
|
56
|
-
{
|
|
57
|
-
// Shift the quality from 1-9 to 0-8 for real values
|
|
58
|
-
// Default to 5 if out of range
|
|
59
|
-
return (flacCompressionLevel_ >= 1 && flacCompressionLevel_ <= 9) ? flacCompressionLevel_ - 1 : 5;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
NSSearchPathDirectory IOSAudioFileOptions::getDirectory() const
|
|
63
|
-
{
|
|
64
|
-
switch (directory_) {
|
|
65
|
-
case 1:
|
|
66
|
-
return NSDocumentDirectory;
|
|
67
|
-
case 2:
|
|
68
|
-
return NSCachesDirectory;
|
|
69
|
-
default:
|
|
70
|
-
return NSCachesDirectory; // Default to Caches
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
NSString *IOSAudioFileOptions::getFileExtension() const
|
|
75
|
-
{
|
|
76
|
-
switch (format_) {
|
|
77
|
-
case 1:
|
|
78
|
-
return @"wav"; // WAV <-> Linear PCM container
|
|
79
|
-
case 2:
|
|
80
|
-
return @"caf"; // CAF <-> Linear PCM container
|
|
81
|
-
case 3:
|
|
82
|
-
return @"m4a"; // M4A <-> AAC
|
|
83
|
-
case 4:
|
|
84
|
-
return @"flac"; // FLAC <-> FLAC
|
|
85
|
-
default:
|
|
86
|
-
return @"wav"; // Default to WAV
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
NSInteger IOSAudioFileOptions::getBitDepth() const
|
|
91
|
-
{
|
|
92
|
-
switch (bitDepth_) {
|
|
93
|
-
case 1:
|
|
94
|
-
return 16;
|
|
95
|
-
case 2:
|
|
96
|
-
return 24;
|
|
97
|
-
case 3:
|
|
98
|
-
return 32;
|
|
99
|
-
default:
|
|
100
|
-
return 24; // Default to 24-bit
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
NSDictionary *IOSAudioFileOptions::getFileSettings()
|
|
105
|
-
{
|
|
106
|
-
AudioFormatID format = getFormat();
|
|
107
|
-
NSMutableDictionary *settings = [NSMutableDictionary dictionary];
|
|
108
|
-
|
|
109
|
-
settings[AVFormatIDKey] = @(format);
|
|
110
|
-
settings[AVSampleRateKey] = @(sampleRate_);
|
|
111
|
-
settings[AVNumberOfChannelsKey] = @(channelCount_);
|
|
112
|
-
|
|
113
|
-
settings[AVEncoderAudioQualityKey] = @(getQuality());
|
|
114
|
-
|
|
115
|
-
if (format == kAudioFormatMPEG4AAC) {
|
|
116
|
-
settings[AVEncoderBitRateKey] = @(bitRate_);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
if (format == kAudioFormatLinearPCM) {
|
|
120
|
-
NSInteger bitDepth = getBitDepth();
|
|
121
|
-
|
|
122
|
-
settings[AVLinearPCMBitDepthKey] = @(bitDepth);
|
|
123
|
-
settings[AVLinearPCMIsFloatKey] = @(bitDepth == 32);
|
|
124
|
-
settings[AVLinearPCMIsBigEndianKey] = @(NO);
|
|
125
|
-
settings[AVLinearPCMIsNonInterleaved] = @(NO);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
if (format == kAudioFormatFLAC) {
|
|
129
|
-
settings[@"FLACCompressionLevel"] = @(getFlacCompressionLevel());
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
return settings;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
float IOSAudioFileOptions::getSampleRate()
|
|
136
|
-
{
|
|
137
|
-
return sampleRate_;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
} // namespace audioapi
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
|
|
3
|
-
#include <memory>
|
|
4
|
-
#include <string>
|
|
5
|
-
#include <tuple>
|
|
6
|
-
|
|
7
|
-
#ifndef __OBJC__ // when compiled as C++
|
|
8
|
-
typedef struct objc_object NSURL;
|
|
9
|
-
typedef struct objc_object NSString;
|
|
10
|
-
typedef struct objc_object AVAudioFile;
|
|
11
|
-
typedef struct objc_object AVAudioFormat;
|
|
12
|
-
typedef struct objc_object AudioBufferList;
|
|
13
|
-
typedef struct objc_object AVAudioConverter;
|
|
14
|
-
#endif // __OBJC__
|
|
15
|
-
|
|
16
|
-
namespace audioapi {
|
|
17
|
-
|
|
18
|
-
class IOSAudioFileOptions;
|
|
19
|
-
|
|
20
|
-
class IOSAudioFileWriter {
|
|
21
|
-
public:
|
|
22
|
-
IOSAudioFileWriter(float sampleRate, size_t channelCount, size_t bitRate, size_t iosFlags);
|
|
23
|
-
~IOSAudioFileWriter();
|
|
24
|
-
|
|
25
|
-
std::string openFile(AVAudioFormat *bufferFormat, size_t maxInputBufferLength);
|
|
26
|
-
std::tuple<double, double> closeFile();
|
|
27
|
-
|
|
28
|
-
bool writeAudioData(const AudioBufferList *audioBufferList, int numFrames);
|
|
29
|
-
|
|
30
|
-
double getCurrentDuration() const;
|
|
31
|
-
|
|
32
|
-
private:
|
|
33
|
-
size_t converterInputBufferSize_;
|
|
34
|
-
size_t converterOutputBufferSize_;
|
|
35
|
-
std::atomic<size_t> framesWritten_{0};
|
|
36
|
-
|
|
37
|
-
NSString *getISODateStringForDirectory();
|
|
38
|
-
NSString *getTimestampForFilename();
|
|
39
|
-
NSURL *getFileURL();
|
|
40
|
-
|
|
41
|
-
std::shared_ptr<IOSAudioFileOptions> fileOptions_;
|
|
42
|
-
AVAudioFile *audioFile_;
|
|
43
|
-
AVAudioFormat *bufferFormat_;
|
|
44
|
-
AVAudioConverter *converter_;
|
|
45
|
-
NSURL *fileURL_;
|
|
46
|
-
|
|
47
|
-
AVAudioPCMBuffer *converterInputBuffer_;
|
|
48
|
-
AVAudioPCMBuffer *converterOutputBuffer_;
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
} // namespace audioapi
|
|
@@ -1,223 +0,0 @@
|
|
|
1
|
-
#import <AVFoundation/AVFoundation.h>
|
|
2
|
-
#import <Foundation/Foundation.h>
|
|
3
|
-
|
|
4
|
-
#include <audioapi/ios/core/IOSAudioFileOptions.h>
|
|
5
|
-
#include <audioapi/ios/core/IOSAudioFileWriter.h>
|
|
6
|
-
|
|
7
|
-
constexpr double BYTES_TO_MB = 1024.0 * 1024.0;
|
|
8
|
-
|
|
9
|
-
namespace audioapi {
|
|
10
|
-
IOSAudioFileWriter::IOSAudioFileWriter(float sampleRate, size_t channelCount, size_t bitRate, size_t iosFlags)
|
|
11
|
-
{
|
|
12
|
-
fileOptions_ = std::make_shared<IOSAudioFileOptions>(sampleRate, channelCount, bitRate, iosFlags);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
IOSAudioFileWriter::~IOSAudioFileWriter()
|
|
16
|
-
{
|
|
17
|
-
fileURL_ = nil;
|
|
18
|
-
audioFile_ = nil;
|
|
19
|
-
converter_ = nil;
|
|
20
|
-
bufferFormat_ = nil;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
std::string IOSAudioFileWriter::openFile(AVAudioFormat *bufferFormat, size_t maxInputBufferLength)
|
|
24
|
-
{
|
|
25
|
-
@autoreleasepool {
|
|
26
|
-
if (audioFile_ != nil) {
|
|
27
|
-
NSLog(@"⚠️ createFileForWriting: currentAudioFile_ already exists");
|
|
28
|
-
return "";
|
|
29
|
-
}
|
|
30
|
-
framesWritten_.store(0);
|
|
31
|
-
|
|
32
|
-
bufferFormat_ = bufferFormat;
|
|
33
|
-
|
|
34
|
-
NSError *error = nil;
|
|
35
|
-
NSDictionary *settings = fileOptions_->getFileSettings();
|
|
36
|
-
fileURL_ = getFileURL();
|
|
37
|
-
|
|
38
|
-
NSLog(@"ℹ️ Creating audio file at URL: %@", [fileURL_ absoluteString]);
|
|
39
|
-
|
|
40
|
-
audioFile_ = [[AVAudioFile alloc] initForWriting:fileURL_
|
|
41
|
-
settings:settings
|
|
42
|
-
commonFormat:AVAudioPCMFormatFloat32
|
|
43
|
-
interleaved:bufferFormat.interleaved
|
|
44
|
-
error:&error];
|
|
45
|
-
converter_ = [[AVAudioConverter alloc] initFromFormat:bufferFormat toFormat:[audioFile_ processingFormat]];
|
|
46
|
-
converter_.sampleRateConverterAlgorithm = AVSampleRateConverterAlgorithm_Normal;
|
|
47
|
-
converter_.sampleRateConverterQuality = AVAudioQualityMax;
|
|
48
|
-
converter_.primeMethod = AVAudioConverterPrimeMethod_None;
|
|
49
|
-
|
|
50
|
-
converterInputBufferSize_ = maxInputBufferLength;
|
|
51
|
-
converterOutputBufferSize_ = std::max(
|
|
52
|
-
(double)maxInputBufferLength, fileOptions_->getSampleRate() / bufferFormat.sampleRate * maxInputBufferLength);
|
|
53
|
-
|
|
54
|
-
converterInputBuffer_ = [[AVAudioPCMBuffer alloc] initWithPCMFormat:bufferFormat
|
|
55
|
-
frameCapacity:(AVAudioFrameCount)maxInputBufferLength];
|
|
56
|
-
converterOutputBuffer_ = [[AVAudioPCMBuffer alloc] initWithPCMFormat:[audioFile_ processingFormat]
|
|
57
|
-
frameCapacity:(AVAudioFrameCount)maxInputBufferLength];
|
|
58
|
-
|
|
59
|
-
if (error != nil || audioFile_ == nil) {
|
|
60
|
-
NSLog(@"Error creating audio file for writing: %@", [error debugDescription]);
|
|
61
|
-
audioFile_ = nil;
|
|
62
|
-
|
|
63
|
-
return "";
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
return [[fileURL_ path] UTF8String];
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
std::tuple<double, double> IOSAudioFileWriter::closeFile()
|
|
71
|
-
{
|
|
72
|
-
@autoreleasepool {
|
|
73
|
-
NSError *error;
|
|
74
|
-
std::string filePath = [[fileURL_ path] UTF8String];
|
|
75
|
-
|
|
76
|
-
if (audioFile_ == nil) {
|
|
77
|
-
return {0, 0};
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// AVAudioFile automatically finalizes the file when deallocated
|
|
81
|
-
audioFile_ = nil;
|
|
82
|
-
|
|
83
|
-
double fileDuration = CMTimeGetSeconds([[AVURLAsset URLAssetWithURL:fileURL_ options:nil] duration]);
|
|
84
|
-
double fileSizeBytesMb =
|
|
85
|
-
static_cast<double>([[[NSFileManager defaultManager] attributesOfItemAtPath:fileURL_.path
|
|
86
|
-
error:&error] fileSize]) /
|
|
87
|
-
BYTES_TO_MB;
|
|
88
|
-
|
|
89
|
-
NSLog(
|
|
90
|
-
@"ℹ️ Closed audio file at path: %s, duration: %.2f sec, size: %.2f MB",
|
|
91
|
-
filePath.c_str(),
|
|
92
|
-
fileDuration,
|
|
93
|
-
fileSizeBytesMb);
|
|
94
|
-
|
|
95
|
-
if (error != nil) {
|
|
96
|
-
NSLog(@"⚠️ closeFile: error while retrieving file size");
|
|
97
|
-
fileSizeBytesMb = 0;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
fileURL_ = nil;
|
|
101
|
-
|
|
102
|
-
return {fileSizeBytesMb, fileDuration};
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
bool IOSAudioFileWriter::writeAudioData(const AudioBufferList *audioBufferList, int numFrames)
|
|
107
|
-
{
|
|
108
|
-
if (audioFile_ == nil) {
|
|
109
|
-
NSLog(@"⚠️ writeAudioData: audioFile is nil, cannot write data");
|
|
110
|
-
return false;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
@autoreleasepool {
|
|
114
|
-
NSError *error = nil;
|
|
115
|
-
AVAudioFormat *fileFormat = [audioFile_ processingFormat];
|
|
116
|
-
|
|
117
|
-
if (bufferFormat_.sampleRate == fileFormat.sampleRate && bufferFormat_.channelCount == fileFormat.channelCount &&
|
|
118
|
-
bufferFormat_.isInterleaved == fileFormat.isInterleaved) {
|
|
119
|
-
AVAudioPCMBuffer *processingBuffer = [[AVAudioPCMBuffer alloc] initWithPCMFormat:fileFormat
|
|
120
|
-
bufferListNoCopy:audioBufferList
|
|
121
|
-
deallocator:NULL];
|
|
122
|
-
processingBuffer.frameLength = (AVAudioFrameCount)numFrames;
|
|
123
|
-
|
|
124
|
-
[audioFile_ writeFromBuffer:processingBuffer error:&error];
|
|
125
|
-
|
|
126
|
-
if (error != nil) {
|
|
127
|
-
NSLog(@"Error writing audio data to file: %@", [error debugDescription]);
|
|
128
|
-
return false;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
framesWritten_.fetch_add(numFrames);
|
|
132
|
-
return true;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
size_t outputFrameCount = ceil(numFrames * fileFormat.sampleRate / bufferFormat_.sampleRate);
|
|
136
|
-
|
|
137
|
-
for (size_t i = 0; i < bufferFormat_.channelCount; ++i) {
|
|
138
|
-
memcpy(
|
|
139
|
-
converterInputBuffer_.mutableAudioBufferList->mBuffers[i].mData,
|
|
140
|
-
audioBufferList->mBuffers[i].mData,
|
|
141
|
-
audioBufferList->mBuffers[i].mDataByteSize);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
converterInputBuffer_.frameLength = numFrames;
|
|
145
|
-
|
|
146
|
-
AVAudioConverterInputBlock inputBlock =
|
|
147
|
-
^AVAudioBuffer *_Nullable(AVAudioPacketCount inNumberOfPackets, AVAudioConverterInputStatus *outStatus)
|
|
148
|
-
{
|
|
149
|
-
// this line is probably an delusion, but for my sanity lets keep it
|
|
150
|
-
inNumberOfPackets = numFrames;
|
|
151
|
-
*outStatus = AVAudioConverterInputStatus_HaveData;
|
|
152
|
-
return converterInputBuffer_;
|
|
153
|
-
};
|
|
154
|
-
|
|
155
|
-
[converter_ convertToBuffer:converterOutputBuffer_ error:&error withInputFromBlock:inputBlock];
|
|
156
|
-
|
|
157
|
-
if (error != nil) {
|
|
158
|
-
NSLog(@"Error during audio conversion: %@", [error debugDescription]);
|
|
159
|
-
return false;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
[audioFile_ writeFromBuffer:converterOutputBuffer_ error:&error];
|
|
163
|
-
|
|
164
|
-
if (error != nil) {
|
|
165
|
-
NSLog(@"Error writing audio data to file: %@", [error debugDescription]);
|
|
166
|
-
return false;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
framesWritten_.fetch_add(numFrames);
|
|
170
|
-
return true;
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
NSString *IOSAudioFileWriter::getISODateStringForDirectory()
|
|
175
|
-
{
|
|
176
|
-
NSDateFormatter *fmt = [[NSDateFormatter alloc] init];
|
|
177
|
-
fmt.locale = [NSLocale localeWithLocaleIdentifier:@"en_US_POSIX"];
|
|
178
|
-
fmt.timeZone = [NSTimeZone timeZoneWithAbbreviation:@"UTC"]; // or local if you prefer
|
|
179
|
-
fmt.dateFormat = @"yyyy-MM-dd";
|
|
180
|
-
return [fmt stringFromDate:[NSDate date]];
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
NSString *IOSAudioFileWriter::getTimestampForFilename()
|
|
184
|
-
{
|
|
185
|
-
NSDateFormatter *fmt = [[NSDateFormatter alloc] init];
|
|
186
|
-
fmt.locale = [NSLocale localeWithLocaleIdentifier:@"en_US_POSIX"];
|
|
187
|
-
fmt.timeZone = [NSTimeZone timeZoneWithAbbreviation:@"UTC"]; // or local if you prefer
|
|
188
|
-
fmt.dateFormat = @"yyyyMMdd_HHmmss_SSS";
|
|
189
|
-
return [fmt stringFromDate:[NSDate date]];
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
NSURL *IOSAudioFileWriter::getFileURL()
|
|
193
|
-
{
|
|
194
|
-
NSError *error = nil;
|
|
195
|
-
|
|
196
|
-
NSSearchPathDirectory searchDirectory = fileOptions_->getDirectory();
|
|
197
|
-
NSString *directory = [NSString stringWithFormat:@"AudioAPI/%@", getISODateStringForDirectory()];
|
|
198
|
-
|
|
199
|
-
NSURL *baseURL = [[[NSFileManager defaultManager] URLsForDirectory:searchDirectory
|
|
200
|
-
inDomains:NSUserDomainMask] firstObject];
|
|
201
|
-
NSURL *dirURL = [baseURL URLByAppendingPathComponent:directory isDirectory:YES];
|
|
202
|
-
|
|
203
|
-
[[NSFileManager defaultManager] createDirectoryAtURL:dirURL
|
|
204
|
-
withIntermediateDirectories:YES
|
|
205
|
-
attributes:nil
|
|
206
|
-
error:&error];
|
|
207
|
-
|
|
208
|
-
if (error != nil) {
|
|
209
|
-
NSLog(@"Error creating directory for audio recordings: %@", [error debugDescription]);
|
|
210
|
-
dirURL = baseURL;
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
NSString *fileName =
|
|
214
|
-
[NSString stringWithFormat:@"audio_%@.%@", getTimestampForFilename(), fileOptions_->getFileExtension()];
|
|
215
|
-
return [dirURL URLByAppendingPathComponent:fileName];
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
double IOSAudioFileWriter::getCurrentDuration() const
|
|
219
|
-
{
|
|
220
|
-
return static_cast<double>(framesWritten_.load()) / bufferFormat_.sampleRate;
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
} // namespace audioapi
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
|
|
3
|
-
#ifndef __OBJC__ // when compiled as C++
|
|
4
|
-
typedef struct objc_object AVAudioFormat;
|
|
5
|
-
typedef struct objc_object AudioBufferList;
|
|
6
|
-
typedef struct objc_object AVAudioConverter;
|
|
7
|
-
#endif
|
|
8
|
-
|
|
9
|
-
#include <memory>
|
|
10
|
-
#include <vector>
|
|
11
|
-
|
|
12
|
-
namespace audioapi {
|
|
13
|
-
|
|
14
|
-
class AudioBus;
|
|
15
|
-
class CircularAudioArray;
|
|
16
|
-
class AudioEventHandlerRegistry;
|
|
17
|
-
|
|
18
|
-
class IOSRecorderCallback {
|
|
19
|
-
public:
|
|
20
|
-
IOSRecorderCallback(
|
|
21
|
-
const std::shared_ptr<AudioEventHandlerRegistry> &audioEventHandlerRegistry,
|
|
22
|
-
float sampleRate,
|
|
23
|
-
size_t bufferLength,
|
|
24
|
-
size_t channelCount,
|
|
25
|
-
uint64_t callbackId);
|
|
26
|
-
~IOSRecorderCallback();
|
|
27
|
-
|
|
28
|
-
void prepare(AVAudioFormat *bufferFormat, size_t maxInputBufferLength);
|
|
29
|
-
void cleanup();
|
|
30
|
-
|
|
31
|
-
void receiveAudioData(const AudioBufferList *audioBufferList, int numFrames);
|
|
32
|
-
void emitAudioData();
|
|
33
|
-
|
|
34
|
-
void invokeCallback(const std::shared_ptr<AudioBus> &bus, int numFrames);
|
|
35
|
-
void sendRemainingData();
|
|
36
|
-
|
|
37
|
-
private:
|
|
38
|
-
float sampleRate_;
|
|
39
|
-
size_t bufferLength_;
|
|
40
|
-
size_t channelCount_;
|
|
41
|
-
uint64_t callbackId_;
|
|
42
|
-
size_t ringBufferSize_;
|
|
43
|
-
size_t converterInputBufferSize_;
|
|
44
|
-
size_t converterOutputBufferSize_;
|
|
45
|
-
|
|
46
|
-
std::shared_ptr<AudioEventHandlerRegistry> audioEventHandlerRegistry_;
|
|
47
|
-
std::vector<std::shared_ptr<CircularAudioArray>> circularBus_;
|
|
48
|
-
|
|
49
|
-
AVAudioFormat *bufferFormat_;
|
|
50
|
-
AVAudioFormat *callbackFormat_;
|
|
51
|
-
AVAudioConverter *converter_;
|
|
52
|
-
|
|
53
|
-
AVAudioPCMBuffer *converterInputBuffer_;
|
|
54
|
-
AVAudioPCMBuffer *converterOutputBuffer_;
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
} // namespace audioapi
|
|
@@ -1,189 +0,0 @@
|
|
|
1
|
-
#import <AVFoundation/AVFoundation.h>
|
|
2
|
-
#import <Foundation/Foundation.h>
|
|
3
|
-
|
|
4
|
-
#include <audioapi/HostObjects/sources/AudioBufferHostObject.h>
|
|
5
|
-
#include <audioapi/core/utils/Constants.h>
|
|
6
|
-
#include <audioapi/dsp/VectorMath.h>
|
|
7
|
-
#include <audioapi/events/AudioEventHandlerRegistry.h>
|
|
8
|
-
#include <audioapi/ios/core/IOSRecorderCallback.h>
|
|
9
|
-
#include <audioapi/utils/AudioArray.h>
|
|
10
|
-
#include <audioapi/utils/AudioBus.h>
|
|
11
|
-
#include <audioapi/utils/CircularAudioArray.h>
|
|
12
|
-
#include <algorithm>
|
|
13
|
-
|
|
14
|
-
namespace audioapi {
|
|
15
|
-
|
|
16
|
-
IOSRecorderCallback::IOSRecorderCallback(
|
|
17
|
-
const std::shared_ptr<AudioEventHandlerRegistry> &audioEventHandlerRegistry,
|
|
18
|
-
float sampleRate,
|
|
19
|
-
size_t bufferLength,
|
|
20
|
-
size_t channelCount,
|
|
21
|
-
uint64_t callbackId)
|
|
22
|
-
: audioEventHandlerRegistry_(audioEventHandlerRegistry),
|
|
23
|
-
sampleRate_(sampleRate),
|
|
24
|
-
bufferLength_(bufferLength),
|
|
25
|
-
channelCount_(channelCount),
|
|
26
|
-
callbackId_(callbackId)
|
|
27
|
-
{
|
|
28
|
-
ringBufferSize_ = std::max((int)bufferLength_ * 2, 8192);
|
|
29
|
-
circularBus_.resize(channelCount_);
|
|
30
|
-
|
|
31
|
-
for (size_t i = 0; i < channelCount_; ++i) {
|
|
32
|
-
auto busAudioArray = std::make_shared<CircularAudioArray>(ringBufferSize_);
|
|
33
|
-
circularBus_[i] = busAudioArray;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
IOSRecorderCallback::~IOSRecorderCallback()
|
|
38
|
-
{
|
|
39
|
-
@autoreleasepool {
|
|
40
|
-
converter_ = nil;
|
|
41
|
-
bufferFormat_ = nil;
|
|
42
|
-
callbackFormat_ = nil;
|
|
43
|
-
converterInputBuffer_ = nil;
|
|
44
|
-
converterOutputBuffer_ = nil;
|
|
45
|
-
|
|
46
|
-
for (size_t i = 0; i < channelCount_; ++i) {
|
|
47
|
-
circularBus_[i].reset();
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
void IOSRecorderCallback::prepare(AVAudioFormat *bufferFormat, size_t maxInputBufferLength)
|
|
53
|
-
{
|
|
54
|
-
@autoreleasepool {
|
|
55
|
-
bufferFormat_ = bufferFormat;
|
|
56
|
-
converterInputBufferSize_ = maxInputBufferLength;
|
|
57
|
-
|
|
58
|
-
converterOutputBufferSize_ =
|
|
59
|
-
std::max((double)maxInputBufferLength, sampleRate_ / bufferFormat.sampleRate * maxInputBufferLength);
|
|
60
|
-
|
|
61
|
-
callbackFormat_ = [[AVAudioFormat alloc] initWithCommonFormat:AVAudioPCMFormatFloat32
|
|
62
|
-
sampleRate:sampleRate_
|
|
63
|
-
channels:channelCount_
|
|
64
|
-
interleaved:NO];
|
|
65
|
-
|
|
66
|
-
converter_ = [[AVAudioConverter alloc] initFromFormat:bufferFormat toFormat:callbackFormat_];
|
|
67
|
-
converter_.sampleRateConverterAlgorithm = AVSampleRateConverterAlgorithm_Normal;
|
|
68
|
-
converter_.sampleRateConverterQuality = AVAudioQualityMax;
|
|
69
|
-
converter_.primeMethod = AVAudioConverterPrimeMethod_None;
|
|
70
|
-
|
|
71
|
-
converterInputBuffer_ = [[AVAudioPCMBuffer alloc] initWithPCMFormat:bufferFormat_
|
|
72
|
-
frameCapacity:(AVAudioFrameCount)converterInputBufferSize_];
|
|
73
|
-
converterOutputBuffer_ = [[AVAudioPCMBuffer alloc] initWithPCMFormat:callbackFormat_
|
|
74
|
-
frameCapacity:(AVAudioFrameCount)converterOutputBufferSize_];
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
void IOSRecorderCallback::cleanup()
|
|
79
|
-
{
|
|
80
|
-
@autoreleasepool {
|
|
81
|
-
sendRemainingData();
|
|
82
|
-
|
|
83
|
-
converter_ = nil;
|
|
84
|
-
bufferFormat_ = nil;
|
|
85
|
-
callbackFormat_ = nil;
|
|
86
|
-
converterInputBuffer_ = nil;
|
|
87
|
-
converterOutputBuffer_ = nil;
|
|
88
|
-
|
|
89
|
-
for (size_t i = 0; i < channelCount_; ++i) {
|
|
90
|
-
circularBus_[i].reset();
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
void IOSRecorderCallback::receiveAudioData(const AudioBufferList *inputBuffer, int numFrames)
|
|
96
|
-
{
|
|
97
|
-
@autoreleasepool {
|
|
98
|
-
NSError *error = nil;
|
|
99
|
-
|
|
100
|
-
if (bufferFormat_.sampleRate == sampleRate_ && bufferFormat_.channelCount == channelCount_ &&
|
|
101
|
-
!bufferFormat_.isInterleaved) {
|
|
102
|
-
// Directly write to circular buffer
|
|
103
|
-
for (size_t i = 0; i < channelCount_; ++i) {
|
|
104
|
-
auto *inputChannel = static_cast<float *>(inputBuffer->mBuffers[i].mData);
|
|
105
|
-
circularBus_[i]->push_back(inputChannel, numFrames);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
emitAudioData();
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
size_t outputFrameCount = ceil(numFrames * (sampleRate_ / bufferFormat_.sampleRate));
|
|
113
|
-
|
|
114
|
-
for (size_t i = 0; i < bufferFormat_.channelCount; ++i) {
|
|
115
|
-
memcpy(
|
|
116
|
-
converterInputBuffer_.mutableAudioBufferList->mBuffers[i].mData,
|
|
117
|
-
inputBuffer->mBuffers[i].mData,
|
|
118
|
-
inputBuffer->mBuffers[i].mDataByteSize);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
converterInputBuffer_.frameLength = numFrames;
|
|
122
|
-
|
|
123
|
-
AVAudioConverterInputBlock inputBlock =
|
|
124
|
-
^AVAudioBuffer *_Nullable(AVAudioPacketCount inNumberOfPackets, AVAudioConverterInputStatus *outStatus)
|
|
125
|
-
{
|
|
126
|
-
// this line is probably an delusion, but for my sanity lets keep it
|
|
127
|
-
inNumberOfPackets = numFrames;
|
|
128
|
-
*outStatus = AVAudioConverterInputStatus_HaveData;
|
|
129
|
-
return converterInputBuffer_;
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
[converter_ convertToBuffer:converterOutputBuffer_ error:&error withInputFromBlock:inputBlock];
|
|
133
|
-
|
|
134
|
-
if (error != nil) {
|
|
135
|
-
NSLog(@"Error during audio conversion: %@", [error debugDescription]);
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
for (size_t i = 0; i < channelCount_; ++i) {
|
|
140
|
-
auto *inputChannel = static_cast<float *>(converterOutputBuffer_.audioBufferList->mBuffers[i].mData);
|
|
141
|
-
circularBus_[i]->push_back(inputChannel, outputFrameCount);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
emitAudioData();
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
void IOSRecorderCallback::emitAudioData()
|
|
149
|
-
{
|
|
150
|
-
while (circularBus_[0]->getNumberOfAvailableFrames() >= bufferLength_) {
|
|
151
|
-
auto bus = std::make_shared<AudioBus>(bufferLength_, channelCount_, sampleRate_);
|
|
152
|
-
|
|
153
|
-
for (size_t i = 0; i < channelCount_; ++i) {
|
|
154
|
-
auto *outputChannel = bus->getChannel(i)->getData();
|
|
155
|
-
circularBus_[i]->pop_front(outputChannel, bufferLength_);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
invokeCallback(bus, bufferLength_);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
void IOSRecorderCallback::invokeCallback(const std::shared_ptr<AudioBus> &bus, int numFrames)
|
|
163
|
-
{
|
|
164
|
-
auto audioBuffer = std::make_shared<AudioBuffer>(bus);
|
|
165
|
-
auto audioBufferHostObject = std::make_shared<AudioBufferHostObject>(audioBuffer);
|
|
166
|
-
|
|
167
|
-
std::unordered_map<std::string, EventValue> eventPayload = {};
|
|
168
|
-
eventPayload.insert({"buffer", audioBufferHostObject});
|
|
169
|
-
eventPayload.insert({"numFrames", numFrames});
|
|
170
|
-
|
|
171
|
-
if (audioEventHandlerRegistry_) {
|
|
172
|
-
audioEventHandlerRegistry_->invokeHandlerWithEventBody("audioReady", callbackId_, eventPayload);
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
void IOSRecorderCallback::sendRemainingData()
|
|
177
|
-
{
|
|
178
|
-
auto numberOfFrames = circularBus_[0]->getNumberOfAvailableFrames();
|
|
179
|
-
auto bus = std::make_shared<AudioBus>(circularBus_[0]->getNumberOfAvailableFrames(), channelCount_, sampleRate_);
|
|
180
|
-
|
|
181
|
-
for (size_t i = 0; i < channelCount_; ++i) {
|
|
182
|
-
auto *outputChannel = bus->getChannel(i)->getData();
|
|
183
|
-
circularBus_[i]->pop_front(outputChannel, numberOfFrames);
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
invokeCallback(bus, numberOfFrames);
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
} // namespace audioapi
|