react-native-audio-api 0.11.0-alpha.1 → 0.11.0-alpha.2
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 +25 -18
- package/android/build.gradle +41 -5
- package/android/src/main/cpp/audioapi/CMakeLists.txt +6 -3
- package/android/src/main/cpp/audioapi/android/AudioAPIModule.cpp +10 -16
- package/android/src/main/cpp/audioapi/android/OnLoad.cpp +1 -2
- package/android/src/main/cpp/audioapi/android/core/AndroidAudioRecorder.cpp +219 -84
- package/android/src/main/cpp/audioapi/android/core/AndroidAudioRecorder.h +24 -23
- package/android/src/main/cpp/audioapi/android/core/AudioPlayer.cpp +13 -20
- package/android/src/main/cpp/audioapi/android/core/utils/AndroidFileWriterBackend.h +14 -18
- package/android/src/main/cpp/audioapi/android/core/utils/AndroidRecorderCallback.cpp +72 -89
- package/android/src/main/cpp/audioapi/android/core/utils/AndroidRecorderCallback.h +12 -23
- package/android/src/main/cpp/audioapi/android/core/utils/AudioDecoder.cpp +47 -47
- package/android/src/main/cpp/audioapi/android/core/utils/FileOptions.cpp +83 -0
- package/android/src/main/cpp/audioapi/android/core/utils/FileOptions.h +22 -0
- package/android/src/main/cpp/audioapi/android/core/utils/MiniaudioImplementation.cpp +5 -0
- package/android/src/main/cpp/audioapi/android/core/utils/ffmpegBackend/FFmpegFileWriter.cpp +379 -298
- package/android/src/main/cpp/audioapi/android/core/utils/ffmpegBackend/FFmpegFileWriter.h +48 -91
- package/android/src/main/cpp/audioapi/android/core/utils/ffmpegBackend/ptrs.hpp +48 -0
- package/android/src/main/cpp/audioapi/android/core/utils/ffmpegBackend/utils.cpp +110 -0
- package/android/src/main/cpp/audioapi/android/core/utils/ffmpegBackend/utils.h +34 -0
- package/android/src/main/cpp/audioapi/android/core/utils/miniaudioBackend/MiniAudioFileWriter.cpp +132 -104
- package/android/src/main/cpp/audioapi/android/core/utils/miniaudioBackend/MiniAudioFileWriter.h +8 -16
- package/android/src/main/java/com/swmansion/audioapi/AudioAPIModule.kt +28 -1
- package/android/src/main/java/com/swmansion/audioapi/system/LockScreenManager.kt +28 -6
- package/android/src/main/java/com/swmansion/audioapi/system/MediaNotificationManager.kt +11 -0
- 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/android/src/oldarch/NativeAudioAPIModuleSpec.java +4 -0
- package/common/cpp/audioapi/AudioAPIModuleInstaller.h +45 -70
- package/common/cpp/audioapi/HostObjects/AudioContextHostObject.cpp +20 -22
- package/common/cpp/audioapi/HostObjects/AudioNodeHostObject.cpp +3 -4
- package/common/cpp/audioapi/HostObjects/AudioParamHostObject.cpp +6 -8
- package/common/cpp/audioapi/HostObjects/AudioParamHostObject.h +2 -2
- package/common/cpp/audioapi/HostObjects/BaseAudioContextHostObject.cpp +102 -63
- package/common/cpp/audioapi/HostObjects/BaseAudioContextHostObject.h +4 -1
- package/common/cpp/audioapi/HostObjects/OfflineAudioContextHostObject.cpp +25 -31
- package/common/cpp/audioapi/HostObjects/OfflineAudioContextHostObject.h +3 -3
- package/common/cpp/audioapi/HostObjects/WorkletNodeHostObject.h +1 -2
- package/common/cpp/audioapi/HostObjects/WorkletProcessingNodeHostObject.h +1 -2
- package/common/cpp/audioapi/HostObjects/analysis/AnalyserNodeHostObject.cpp +10 -18
- package/common/cpp/audioapi/HostObjects/destinations/AudioDestinationNodeHostObject.h +2 -3
- package/common/cpp/audioapi/HostObjects/effects/BiquadFilterNodeHostObject.cpp +18 -30
- package/common/cpp/audioapi/HostObjects/effects/BiquadFilterNodeHostObject.h +1 -2
- package/common/cpp/audioapi/HostObjects/effects/ConvolverNodeHostObject.cpp +50 -0
- package/common/cpp/audioapi/HostObjects/effects/ConvolverNodeHostObject.h +20 -0
- package/common/cpp/audioapi/HostObjects/effects/DelayNodeHostObject.cpp +27 -0
- package/common/cpp/audioapi/HostObjects/effects/DelayNodeHostObject.h +21 -0
- package/common/cpp/audioapi/HostObjects/effects/GainNodeHostObject.cpp +2 -2
- package/common/cpp/audioapi/HostObjects/effects/IIRFilterNodeHostObject.cpp +33 -0
- package/common/cpp/audioapi/HostObjects/effects/IIRFilterNodeHostObject.h +20 -0
- package/common/cpp/audioapi/HostObjects/effects/PeriodicWaveHostObject.h +1 -2
- package/common/cpp/audioapi/HostObjects/effects/StereoPannerNodeHostObject.cpp +2 -2
- package/common/cpp/audioapi/HostObjects/effects/StereoPannerNodeHostObject.h +1 -2
- package/common/cpp/audioapi/HostObjects/events/AudioEventHandlerRegistryHostObject.cpp +6 -12
- package/common/cpp/audioapi/HostObjects/events/AudioEventHandlerRegistryHostObject.h +7 -7
- package/common/cpp/audioapi/HostObjects/inputs/AudioRecorderHostObject.cpp +98 -50
- package/common/cpp/audioapi/HostObjects/inputs/AudioRecorderHostObject.h +5 -2
- package/common/cpp/audioapi/HostObjects/sources/AudioBufferBaseSourceNodeHostObject.cpp +27 -22
- package/common/cpp/audioapi/HostObjects/sources/AudioBufferBaseSourceNodeHostObject.h +12 -10
- package/common/cpp/audioapi/HostObjects/sources/AudioBufferHostObject.cpp +17 -22
- package/common/cpp/audioapi/HostObjects/sources/AudioBufferHostObject.h +5 -7
- package/common/cpp/audioapi/HostObjects/sources/AudioBufferQueueSourceNodeHostObject.cpp +25 -11
- package/common/cpp/audioapi/HostObjects/sources/AudioBufferQueueSourceNodeHostObject.h +8 -8
- package/common/cpp/audioapi/HostObjects/sources/AudioBufferSourceNodeHostObject.cpp +19 -30
- package/common/cpp/audioapi/HostObjects/sources/AudioBufferSourceNodeHostObject.h +2 -4
- package/common/cpp/audioapi/HostObjects/sources/AudioScheduledSourceNodeHostObject.cpp +7 -11
- package/common/cpp/audioapi/HostObjects/sources/ConstantSourceNodeHostObject.cpp +2 -2
- package/common/cpp/audioapi/HostObjects/sources/ConstantSourceNodeHostObject.h +1 -2
- package/common/cpp/audioapi/HostObjects/sources/OscillatorNodeHostObject.cpp +6 -8
- package/common/cpp/audioapi/HostObjects/sources/OscillatorNodeHostObject.h +1 -2
- package/common/cpp/audioapi/HostObjects/sources/RecorderAdapterNodeHostObject.h +4 -5
- package/common/cpp/audioapi/HostObjects/sources/StreamerNodeHostObject.cpp +6 -2
- package/common/cpp/audioapi/HostObjects/sources/StreamerNodeHostObject.h +5 -6
- package/common/cpp/audioapi/HostObjects/sources/WorkletSourceNodeHostObject.h +1 -2
- package/common/cpp/audioapi/HostObjects/utils/AudioDecoderHostObject.cpp +39 -60
- package/common/cpp/audioapi/HostObjects/utils/AudioStretcherHostObject.cpp +15 -30
- package/common/cpp/audioapi/core/AudioContext.cpp +23 -28
- package/common/cpp/audioapi/core/AudioContext.h +6 -3
- package/common/cpp/audioapi/core/AudioNode.cpp +17 -19
- package/common/cpp/audioapi/core/AudioNode.h +19 -8
- package/common/cpp/audioapi/core/AudioParam.cpp +68 -100
- package/common/cpp/audioapi/core/AudioParam.h +20 -12
- package/common/cpp/audioapi/core/BaseAudioContext.cpp +52 -34
- package/common/cpp/audioapi/core/BaseAudioContext.h +26 -14
- package/common/cpp/audioapi/core/OfflineAudioContext.cpp +12 -17
- package/common/cpp/audioapi/core/OfflineAudioContext.h +10 -5
- package/common/cpp/audioapi/core/analysis/AnalyserNode.cpp +13 -21
- package/common/cpp/audioapi/core/analysis/AnalyserNode.h +8 -6
- package/common/cpp/audioapi/core/destinations/AudioDestinationNode.cpp +1 -0
- package/common/cpp/audioapi/core/destinations/AudioDestinationNode.h +5 -3
- package/common/cpp/audioapi/core/effects/BiquadFilterNode.cpp +84 -66
- package/common/cpp/audioapi/core/effects/BiquadFilterNode.h +39 -10
- package/common/cpp/audioapi/core/effects/ConvolverNode.cpp +201 -0
- package/common/cpp/audioapi/core/effects/ConvolverNode.h +64 -0
- package/common/cpp/audioapi/core/effects/DelayNode.cpp +101 -0
- package/common/cpp/audioapi/core/effects/DelayNode.h +39 -0
- package/common/cpp/audioapi/core/effects/GainNode.cpp +1 -0
- package/common/cpp/audioapi/core/effects/GainNode.h +3 -1
- package/common/cpp/audioapi/core/effects/IIRFilterNode.cpp +166 -0
- package/common/cpp/audioapi/core/effects/IIRFilterNode.h +74 -0
- package/common/cpp/audioapi/core/effects/PeriodicWave.cpp +22 -35
- package/common/cpp/audioapi/core/effects/PeriodicWave.h +4 -9
- package/common/cpp/audioapi/core/effects/StereoPannerNode.cpp +4 -5
- package/common/cpp/audioapi/core/effects/StereoPannerNode.h +4 -2
- package/common/cpp/audioapi/core/effects/WorkletNode.cpp +11 -13
- package/common/cpp/audioapi/core/effects/WorkletNode.h +15 -12
- package/common/cpp/audioapi/core/effects/WorkletProcessingNode.cpp +4 -4
- package/common/cpp/audioapi/core/effects/WorkletProcessingNode.h +15 -14
- package/common/cpp/audioapi/core/inputs/AudioRecorder.cpp +58 -36
- package/common/cpp/audioapi/core/inputs/AudioRecorder.h +41 -44
- package/common/cpp/audioapi/core/sources/AudioBuffer.cpp +4 -6
- package/common/cpp/audioapi/core/sources/AudioBuffer.h +4 -7
- package/common/cpp/audioapi/core/sources/AudioBufferBaseSourceNode.cpp +48 -57
- package/common/cpp/audioapi/core/sources/AudioBufferBaseSourceNode.h +37 -34
- package/common/cpp/audioapi/core/sources/AudioBufferQueueSourceNode.cpp +55 -17
- package/common/cpp/audioapi/core/sources/AudioBufferQueueSourceNode.h +35 -28
- package/common/cpp/audioapi/core/sources/AudioBufferSourceNode.cpp +41 -49
- package/common/cpp/audioapi/core/sources/AudioBufferSourceNode.h +8 -6
- package/common/cpp/audioapi/core/sources/AudioScheduledSourceNode.cpp +29 -24
- package/common/cpp/audioapi/core/sources/AudioScheduledSourceNode.h +6 -6
- package/common/cpp/audioapi/core/sources/ConstantSourceNode.cpp +3 -4
- package/common/cpp/audioapi/core/sources/ConstantSourceNode.h +3 -1
- package/common/cpp/audioapi/core/sources/OscillatorNode.cpp +12 -23
- package/common/cpp/audioapi/core/sources/OscillatorNode.h +6 -4
- package/common/cpp/audioapi/core/sources/RecorderAdapterNode.cpp +43 -16
- package/common/cpp/audioapi/core/sources/RecorderAdapterNode.h +22 -17
- package/common/cpp/audioapi/core/sources/StreamerNode.cpp +104 -87
- package/common/cpp/audioapi/core/sources/StreamerNode.h +69 -33
- package/common/cpp/audioapi/core/sources/WorkletSourceNode.cpp +5 -7
- package/common/cpp/audioapi/core/sources/WorkletSourceNode.h +15 -13
- package/common/cpp/audioapi/core/types/AudioFormat.h +1 -11
- package/common/cpp/audioapi/core/utils/AudioDecoder.h +15 -6
- package/common/cpp/audioapi/core/utils/AudioFileWriter.cpp +41 -0
- package/common/cpp/audioapi/core/utils/AudioFileWriter.h +43 -0
- package/common/cpp/audioapi/core/utils/AudioNodeDestructor.cpp +5 -6
- package/common/cpp/audioapi/core/utils/AudioNodeDestructor.h +7 -10
- package/common/cpp/audioapi/core/utils/AudioNodeManager.cpp +17 -19
- package/common/cpp/audioapi/core/utils/AudioNodeManager.h +8 -11
- package/common/cpp/audioapi/core/utils/AudioParamEventQueue.cpp +3 -3
- package/common/cpp/audioapi/core/utils/AudioParamEventQueue.h +5 -5
- package/common/cpp/audioapi/core/utils/AudioRecorderCallback.cpp +101 -0
- package/common/cpp/audioapi/core/utils/AudioRecorderCallback.h +51 -0
- package/common/cpp/audioapi/core/utils/AudioStretcher.cpp +6 -6
- package/common/cpp/audioapi/core/utils/Constants.h +7 -3
- package/common/cpp/audioapi/core/utils/ParamChangeEvent.cpp +1 -0
- package/common/cpp/audioapi/core/utils/ParamChangeEvent.h +9 -9
- package/common/cpp/audioapi/core/utils/worklets/SafeIncludes.h +33 -34
- package/common/cpp/audioapi/core/utils/worklets/WorkletsRunner.cpp +17 -19
- package/common/cpp/audioapi/core/utils/worklets/WorkletsRunner.h +23 -19
- package/common/cpp/audioapi/dsp/AudioUtils.cpp +4 -10
- package/common/cpp/audioapi/dsp/AudioUtils.h +1 -1
- package/common/cpp/audioapi/dsp/Convolver.cpp +201 -0
- package/common/cpp/audioapi/dsp/Convolver.h +47 -0
- package/common/cpp/audioapi/dsp/FFT.cpp +1 -27
- package/common/cpp/audioapi/dsp/FFT.h +19 -3
- package/common/cpp/audioapi/dsp/VectorMath.cpp +24 -58
- package/common/cpp/audioapi/dsp/VectorMath.h +35 -8
- package/common/cpp/audioapi/dsp/Windows.cpp +4 -9
- package/common/cpp/audioapi/dsp/Windows.h +24 -23
- package/common/cpp/audioapi/events/AudioEventHandlerRegistry.cpp +12 -17
- package/common/cpp/audioapi/events/AudioEventHandlerRegistry.h +45 -40
- package/common/cpp/audioapi/events/IAudioEventHandlerRegistry.h +15 -7
- 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/external/{libavcodec.xcframework → ffmpeg_ios/libavcodec.xcframework}/ios-arm64/libavcodec.framework/libavcodec +0 -0
- package/common/cpp/audioapi/external/{libavcodec.xcframework → ffmpeg_ios/libavcodec.xcframework}/ios-arm64_x86_64-simulator/libavcodec.framework/libavcodec +0 -0
- package/common/cpp/audioapi/external/{libavformat.xcframework → ffmpeg_ios/libavformat.xcframework}/ios-arm64/libavformat.framework/libavformat +0 -0
- package/common/cpp/audioapi/external/{libavformat.xcframework → ffmpeg_ios/libavformat.xcframework}/ios-arm64_x86_64-simulator/libavformat.framework/libavformat +0 -0
- package/common/cpp/audioapi/external/{libavutil.xcframework → ffmpeg_ios/libavutil.xcframework}/ios-arm64/libavutil.framework/libavutil +0 -0
- package/common/cpp/audioapi/external/{libavutil.xcframework → ffmpeg_ios/libavutil.xcframework}/ios-arm64_x86_64-simulator/libavutil.framework/libavutil +0 -0
- package/common/cpp/audioapi/external/{libswresample.xcframework → ffmpeg_ios/libswresample.xcframework}/ios-arm64/libswresample.framework/libswresample +0 -0
- package/common/cpp/audioapi/external/{libswresample.xcframework → ffmpeg_ios/libswresample.xcframework}/ios-arm64_x86_64-simulator/libswresample.framework/libswresample +0 -0
- package/common/cpp/audioapi/jsi/AudioArrayBuffer.h +4 -5
- package/common/cpp/audioapi/jsi/JsiHostObject.cpp +11 -13
- package/common/cpp/audioapi/jsi/JsiHostObject.h +26 -33
- package/common/cpp/audioapi/jsi/JsiPromise.cpp +34 -67
- package/common/cpp/audioapi/jsi/JsiPromise.h +65 -26
- package/common/cpp/audioapi/jsi/RuntimeLifecycleMonitor.cpp +7 -10
- package/common/cpp/audioapi/jsi/RuntimeLifecycleMonitor.h +1 -3
- package/common/cpp/audioapi/libs/ffmpeg/FFmpegDecoding.cpp +4 -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/AudioArray.cpp +3 -8
- package/common/cpp/audioapi/utils/AudioArray.h +3 -11
- package/common/cpp/audioapi/utils/AudioBus.cpp +79 -149
- package/common/cpp/audioapi/utils/AudioBus.h +17 -14
- package/common/cpp/audioapi/utils/AudioFileProperties.cpp +92 -0
- package/common/cpp/audioapi/utils/AudioFileProperties.h +76 -0
- package/common/cpp/audioapi/utils/CircularAudioArray.cpp +6 -18
- package/common/cpp/audioapi/utils/CircularOverflowableAudioArray.cpp +6 -10
- package/common/cpp/audioapi/utils/CircularOverflowableAudioArray.h +2 -2
- package/common/cpp/audioapi/utils/Result.hpp +286 -0
- package/common/cpp/audioapi/utils/ThreadPool.hpp +59 -1
- package/common/cpp/audioapi/utils/UnitConversion.h +9 -0
- package/common/cpp/test/CMakeLists.txt +20 -14
- package/common/cpp/test/src/AudioParamTest.cpp +4 -3
- package/common/cpp/test/src/AudioScheduledSourceTest.cpp +113 -0
- package/common/cpp/test/src/ConstantSourceTest.cpp +5 -7
- package/common/cpp/test/src/DelayTest.cpp +108 -0
- package/common/cpp/test/src/GainTest.cpp +4 -5
- package/common/cpp/test/src/IIRFilterTest.cpp +153 -0
- package/common/cpp/test/src/MockAudioEventHandlerRegistry.h +19 -11
- package/common/cpp/test/src/OscillatorTest.cpp +2 -1
- package/common/cpp/test/src/StereoPannerTest.cpp +6 -9
- package/common/cpp/test/src/biquad/BiquadFilterChromium.cpp +372 -0
- package/common/cpp/test/src/biquad/BiquadFilterChromium.h +65 -0
- package/common/cpp/test/src/biquad/BiquadFilterTest.cpp +272 -0
- package/common/cpp/test/src/biquad/BiquadFilterTest.h +47 -0
- package/ios/audioapi/ios/AudioAPIModule.h +2 -1
- package/ios/audioapi/ios/AudioAPIModule.mm +44 -20
- package/ios/audioapi/ios/core/IOSAudioPlayer.h +2 -2
- package/ios/audioapi/ios/core/IOSAudioPlayer.mm +7 -6
- package/ios/audioapi/ios/core/IOSAudioRecorder.h +26 -18
- package/ios/audioapi/ios/core/IOSAudioRecorder.mm +193 -53
- package/ios/audioapi/ios/core/NativeAudioPlayer.m +16 -13
- package/ios/audioapi/ios/core/NativeAudioRecorder.h +4 -0
- package/ios/audioapi/ios/core/NativeAudioRecorder.m +42 -7
- package/ios/audioapi/ios/core/utils/AudioDecoder.mm +21 -4
- package/ios/audioapi/ios/core/utils/FileOptions.h +31 -0
- package/ios/audioapi/ios/core/utils/FileOptions.mm +177 -0
- package/ios/audioapi/ios/core/{IOSAudioFileWriter.h → utils/IOSFileWriter.h} +16 -14
- package/ios/audioapi/ios/core/utils/IOSFileWriter.mm +224 -0
- package/ios/audioapi/ios/core/{IOSRecorderCallback.h → utils/IOSRecorderCallback.h} +7 -17
- package/ios/audioapi/ios/core/utils/IOSRecorderCallback.mm +172 -0
- package/ios/audioapi/ios/system/AudioEngine.h +19 -16
- package/ios/audioapi/ios/system/AudioEngine.mm +101 -134
- package/ios/audioapi/ios/system/AudioSessionManager.h +25 -11
- package/ios/audioapi/ios/system/AudioSessionManager.mm +273 -202
- package/ios/audioapi/ios/system/LockScreenManager.mm +39 -23
- package/ios/audioapi/ios/system/NotificationManager.mm +37 -52
- package/lib/commonjs/AudioAPIModule/AudioAPIModule.js +90 -0
- package/lib/commonjs/AudioAPIModule/AudioAPIModule.js.map +1 -0
- package/lib/commonjs/AudioAPIModule/globals.d.js +6 -0
- package/lib/commonjs/AudioAPIModule/globals.d.js.map +1 -0
- package/lib/commonjs/AudioAPIModule/index.js +14 -0
- package/lib/commonjs/AudioAPIModule/index.js.map +1 -0
- package/lib/commonjs/api.js +18 -12
- package/lib/commonjs/api.js.map +1 -1
- package/lib/commonjs/api.web.js +8 -0
- package/lib/commonjs/api.web.js.map +1 -1
- package/lib/commonjs/core/AudioBufferBaseSourceNode.js +3 -0
- package/lib/commonjs/core/AudioBufferBaseSourceNode.js.map +1 -1
- package/lib/commonjs/core/AudioBufferQueueSourceNode.js +5 -2
- package/lib/commonjs/core/AudioBufferQueueSourceNode.js.map +1 -1
- package/lib/commonjs/core/AudioContext.js +5 -8
- package/lib/commonjs/core/AudioContext.js.map +1 -1
- package/lib/commonjs/core/AudioNode.js +1 -1
- package/lib/commonjs/core/AudioNode.js.map +1 -1
- package/lib/commonjs/core/AudioParam.js +18 -11
- package/lib/commonjs/core/AudioParam.js.map +1 -1
- package/lib/commonjs/core/AudioRecorder.js +43 -55
- package/lib/commonjs/core/AudioRecorder.js.map +1 -1
- package/lib/commonjs/core/BaseAudioContext.js +61 -30
- 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/DelayNode.js +17 -0
- package/lib/commonjs/core/DelayNode.js.map +1 -0
- package/lib/commonjs/core/IIRFilterNode.js +19 -0
- package/lib/commonjs/core/IIRFilterNode.js.map +1 -0
- package/lib/commonjs/core/OfflineAudioContext.js +3 -6
- package/lib/commonjs/core/OfflineAudioContext.js.map +1 -1
- package/lib/commonjs/plugin/withAudioAPI.js +46 -0
- package/lib/commonjs/plugin/withAudioAPI.js.map +1 -1
- package/lib/commonjs/specs/NativeAudioAPIModule.js.map +1 -1
- package/lib/commonjs/system/AudioManager.js +4 -7
- package/lib/commonjs/system/AudioManager.js.map +1 -1
- package/lib/commonjs/types.js +16 -23
- package/lib/commonjs/types.js.map +1 -1
- package/lib/commonjs/utils/filePresets.js +43 -0
- package/lib/commonjs/utils/filePresets.js.map +1 -0
- package/lib/commonjs/utils/index.js +12 -27
- package/lib/commonjs/utils/index.js.map +1 -1
- package/lib/commonjs/web-core/AudioContext.js +21 -1
- 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/DelayNode.js +17 -0
- package/lib/commonjs/web-core/DelayNode.js.map +1 -0
- package/lib/commonjs/web-core/IIRFilterNode.js +19 -0
- package/lib/commonjs/web-core/IIRFilterNode.js.map +1 -0
- package/lib/commonjs/web-core/OfflineAudioContext.js +20 -0
- package/lib/commonjs/web-core/OfflineAudioContext.js.map +1 -1
- package/lib/module/AudioAPIModule/AudioAPIModule.js +87 -0
- package/lib/module/AudioAPIModule/AudioAPIModule.js.map +1 -0
- package/lib/module/AudioAPIModule/globals.d.js +4 -0
- package/lib/module/AudioAPIModule/globals.d.js.map +1 -0
- package/lib/module/AudioAPIModule/index.js +4 -0
- package/lib/module/AudioAPIModule/index.js.map +1 -0
- package/lib/module/api.js +3 -12
- package/lib/module/api.js.map +1 -1
- package/lib/module/api.web.js +1 -0
- package/lib/module/api.web.js.map +1 -1
- package/lib/module/core/AudioBufferBaseSourceNode.js +3 -0
- package/lib/module/core/AudioBufferBaseSourceNode.js.map +1 -1
- package/lib/module/core/AudioBufferQueueSourceNode.js +5 -2
- package/lib/module/core/AudioBufferQueueSourceNode.js.map +1 -1
- package/lib/module/core/AudioContext.js +5 -8
- package/lib/module/core/AudioContext.js.map +1 -1
- package/lib/module/core/AudioNode.js +1 -1
- package/lib/module/core/AudioNode.js.map +1 -1
- package/lib/module/core/AudioParam.js +18 -11
- package/lib/module/core/AudioParam.js.map +1 -1
- package/lib/module/core/AudioRecorder.js +44 -56
- package/lib/module/core/AudioRecorder.js.map +1 -1
- package/lib/module/core/BaseAudioContext.js +63 -32
- 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/DelayNode.js +11 -0
- package/lib/module/core/DelayNode.js.map +1 -0
- package/lib/module/core/IIRFilterNode.js +13 -0
- package/lib/module/core/IIRFilterNode.js.map +1 -0
- package/lib/module/core/OfflineAudioContext.js +3 -6
- package/lib/module/core/OfflineAudioContext.js.map +1 -1
- package/lib/module/plugin/withAudioAPI.js +47 -1
- package/lib/module/plugin/withAudioAPI.js.map +1 -1
- package/lib/module/specs/NativeAudioAPIModule.js.map +1 -1
- package/lib/module/system/AudioManager.js +4 -7
- package/lib/module/system/AudioManager.js.map +1 -1
- package/lib/module/types.js +15 -22
- package/lib/module/types.js.map +1 -1
- package/lib/module/utils/filePresets.js +39 -0
- package/lib/module/utils/filePresets.js.map +1 -0
- package/lib/module/utils/index.js +10 -10
- package/lib/module/utils/index.js.map +1 -1
- package/lib/module/web-core/AudioContext.js +21 -1
- 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/DelayNode.js +11 -0
- package/lib/module/web-core/DelayNode.js.map +1 -0
- package/lib/module/web-core/IIRFilterNode.js +13 -0
- package/lib/module/web-core/IIRFilterNode.js.map +1 -0
- package/lib/module/web-core/OfflineAudioContext.js +20 -0
- package/lib/module/web-core/OfflineAudioContext.js.map +1 -1
- package/lib/typescript/AudioAPIModule/AudioAPIModule.d.ts +36 -0
- package/lib/typescript/AudioAPIModule/AudioAPIModule.d.ts.map +1 -0
- package/lib/typescript/AudioAPIModule/index.d.ts +2 -0
- package/lib/typescript/AudioAPIModule/index.d.ts.map +1 -0
- package/lib/typescript/api.d.ts +3 -9
- package/lib/typescript/api.d.ts.map +1 -1
- package/lib/typescript/api.web.d.ts +1 -0
- package/lib/typescript/api.web.d.ts.map +1 -1
- package/lib/typescript/core/AudioBufferBaseSourceNode.d.ts +1 -0
- package/lib/typescript/core/AudioBufferBaseSourceNode.d.ts.map +1 -1
- package/lib/typescript/core/AudioBufferQueueSourceNode.d.ts +1 -1
- package/lib/typescript/core/AudioBufferQueueSourceNode.d.ts.map +1 -1
- package/lib/typescript/core/AudioContext.d.ts +1 -1
- package/lib/typescript/core/AudioContext.d.ts.map +1 -1
- package/lib/typescript/core/AudioNode.d.ts +2 -1
- package/lib/typescript/core/AudioNode.d.ts.map +1 -1
- package/lib/typescript/core/AudioParam.d.ts.map +1 -1
- package/lib/typescript/core/AudioRecorder.d.ts +13 -6
- package/lib/typescript/core/AudioRecorder.d.ts.map +1 -1
- package/lib/typescript/core/BaseAudioContext.d.ts +9 -3
- 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/core/DelayNode.d.ts +9 -0
- package/lib/typescript/core/DelayNode.d.ts.map +1 -0
- package/lib/typescript/core/IIRFilterNode.d.ts +5 -0
- package/lib/typescript/core/IIRFilterNode.d.ts.map +1 -0
- package/lib/typescript/core/OfflineAudioContext.d.ts +1 -1
- package/lib/typescript/core/OfflineAudioContext.d.ts.map +1 -1
- package/lib/typescript/events/types.d.ts +4 -0
- package/lib/typescript/events/types.d.ts.map +1 -1
- package/lib/typescript/interfaces.d.ts +34 -34
- package/lib/typescript/interfaces.d.ts.map +1 -1
- package/lib/typescript/plugin/withAudioAPI.d.ts +1 -0
- package/lib/typescript/plugin/withAudioAPI.d.ts.map +1 -1
- package/lib/typescript/specs/NativeAudioAPIModule.d.ts +2 -1
- package/lib/typescript/specs/NativeAudioAPIModule.d.ts.map +1 -1
- package/lib/typescript/system/AudioManager.d.ts +3 -2
- package/lib/typescript/system/AudioManager.d.ts.map +1 -1
- package/lib/typescript/types.d.ts +42 -34
- package/lib/typescript/types.d.ts.map +1 -1
- package/lib/typescript/utils/filePresets.d.ts +9 -0
- package/lib/typescript/utils/filePresets.d.ts.map +1 -0
- package/lib/typescript/utils/index.d.ts +1 -8
- package/lib/typescript/utils/index.d.ts.map +1 -1
- package/lib/typescript/web-core/AudioContext.d.ts +9 -2
- package/lib/typescript/web-core/AudioContext.d.ts.map +1 -1
- package/lib/typescript/web-core/BaseAudioContext.d.ts +7 -1
- 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/DelayNode.d.ts +8 -0
- package/lib/typescript/web-core/DelayNode.d.ts.map +1 -0
- package/lib/typescript/web-core/IIRFilterNode.d.ts +5 -0
- package/lib/typescript/web-core/IIRFilterNode.d.ts.map +1 -0
- package/lib/typescript/web-core/OfflineAudioContext.d.ts +8 -1
- package/lib/typescript/web-core/OfflineAudioContext.d.ts.map +1 -1
- package/package.json +11 -4
- package/scripts/download-prebuilt-binaries.sh +61 -0
- package/scripts/rnaa_utils.rb +8 -0
- package/scripts/validate-worklets-version.js +27 -0
- package/src/AudioAPIModule/AudioAPIModule.ts +122 -0
- package/src/AudioAPIModule/globals.d.ts +33 -0
- package/src/AudioAPIModule/index.ts +1 -0
- package/src/api.ts +4 -52
- package/src/api.web.ts +1 -0
- package/src/core/AudioBufferBaseSourceNode.ts +8 -0
- package/src/core/AudioBufferQueueSourceNode.ts +8 -2
- package/src/core/AudioContext.ts +5 -8
- package/src/core/AudioNode.ts +4 -3
- package/src/core/AudioParam.ts +18 -11
- package/src/core/AudioRecorder.ts +63 -78
- package/src/core/BaseAudioContext.ts +120 -54
- package/src/core/ConvolverNode.ts +35 -0
- package/src/core/DelayNode.ts +13 -0
- package/src/core/IIRFilterNode.ts +25 -0
- package/src/core/OfflineAudioContext.ts +4 -7
- package/src/events/types.ts +5 -0
- package/src/interfaces.ts +51 -34
- package/src/plugin/withAudioAPI.ts +61 -0
- package/src/specs/NativeAudioAPIModule.ts +3 -2
- package/src/system/AudioManager.ts +13 -19
- package/src/types.ts +45 -36
- package/src/utils/filePresets.ts +47 -0
- package/src/utils/index.ts +13 -19
- package/src/web-core/AudioContext.tsx +40 -1
- package/src/web-core/BaseAudioContext.tsx +11 -1
- package/src/web-core/ConvolverNode.tsx +43 -0
- package/src/web-core/ConvolverNodeOptions.tsx +6 -0
- package/src/web-core/DelayNode.tsx +12 -0
- package/src/web-core/IIRFilterNode.tsx +25 -0
- package/src/web-core/OfflineAudioContext.tsx +39 -0
- 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/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/miniaudioBackend/MiniAudioFileOptions.cpp +0 -47
- package/android/src/main/cpp/audioapi/android/core/utils/miniaudioBackend/MiniAudioFileOptions.h +0 -28
- 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.mm +0 -223
- 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/metro-config/index.d.ts +0 -5
- package/metro-config/index.js +0 -41
- package/metro-config/tsconfig.json +0 -3
- package/src/utils/bitEnums.ts +0 -51
- package/common/cpp/audioapi/external/{libavcodec.xcframework → ffmpeg_ios/libavcodec.xcframework}/Info.plist +5 -5
- package/common/cpp/audioapi/external/{libavcodec.xcframework → ffmpeg_ios/libavcodec.xcframework}/ios-arm64/libavcodec.framework/Info.plist +0 -0
- package/common/cpp/audioapi/external/{libavcodec.xcframework → ffmpeg_ios/libavcodec.xcframework}/ios-arm64_x86_64-simulator/libavcodec.framework/Info.plist +0 -0
- package/common/cpp/audioapi/external/{libavformat.xcframework → ffmpeg_ios/libavformat.xcframework}/Info.plist +0 -0
- package/common/cpp/audioapi/external/{libavformat.xcframework → ffmpeg_ios/libavformat.xcframework}/ios-arm64/libavformat.framework/Info.plist +0 -0
- package/common/cpp/audioapi/external/{libavformat.xcframework → ffmpeg_ios/libavformat.xcframework}/ios-arm64_x86_64-simulator/libavformat.framework/Info.plist +0 -0
- package/common/cpp/audioapi/external/{libavutil.xcframework → ffmpeg_ios/libavutil.xcframework}/Info.plist +5 -5
- package/common/cpp/audioapi/external/{libavutil.xcframework → ffmpeg_ios/libavutil.xcframework}/ios-arm64/libavutil.framework/Info.plist +0 -0
- package/common/cpp/audioapi/external/{libavutil.xcframework → ffmpeg_ios/libavutil.xcframework}/ios-arm64_x86_64-simulator/libavutil.framework/Info.plist +0 -0
- package/common/cpp/audioapi/external/{libswresample.xcframework → ffmpeg_ios/libswresample.xcframework}/Info.plist +5 -5
- /package/common/cpp/audioapi/external/{libswresample.xcframework → ffmpeg_ios/libswresample.xcframework}/ios-arm64/libswresample.framework/Info.plist +0 -0
- /package/common/cpp/audioapi/external/{libswresample.xcframework → ffmpeg_ios/libswresample.xcframework}/ios-arm64_x86_64-simulator/libswresample.framework/Info.plist +0 -0
|
@@ -0,0 +1,201 @@
|
|
|
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 <algorithm>
|
|
13
|
+
#include <chrono>
|
|
14
|
+
#include <iostream>
|
|
15
|
+
#include <memory>
|
|
16
|
+
|
|
17
|
+
namespace audioapi {
|
|
18
|
+
|
|
19
|
+
Convolver::Convolver()
|
|
20
|
+
: _blockSize(0),
|
|
21
|
+
_segSize(0),
|
|
22
|
+
_segCount(0),
|
|
23
|
+
_fftComplexSize(0),
|
|
24
|
+
_segments(),
|
|
25
|
+
_segmentsIR(),
|
|
26
|
+
_fftBuffer(0),
|
|
27
|
+
_fft(nullptr),
|
|
28
|
+
_preMultiplied(),
|
|
29
|
+
_current(0),
|
|
30
|
+
_inputBuffer(0) {}
|
|
31
|
+
|
|
32
|
+
void Convolver::reset() {
|
|
33
|
+
_blockSize = 0;
|
|
34
|
+
_segSize = 0;
|
|
35
|
+
_segCount = 0;
|
|
36
|
+
_fftComplexSize = 0;
|
|
37
|
+
_current = 0;
|
|
38
|
+
_fft = nullptr;
|
|
39
|
+
_segments.clear();
|
|
40
|
+
_segmentsIR.clear();
|
|
41
|
+
_preMultiplied.clear();
|
|
42
|
+
_fftBuffer.zero();
|
|
43
|
+
_inputBuffer.zero();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
bool Convolver::init(size_t blockSize, const audioapi::AudioArray &ir, size_t irLen) {
|
|
47
|
+
reset();
|
|
48
|
+
// blockSize must be a power of two
|
|
49
|
+
if ((blockSize & (blockSize - 1))) {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Ignore zeros at the end of the impulse response because they only waste
|
|
54
|
+
// computation time
|
|
55
|
+
_blockSize = blockSize;
|
|
56
|
+
_trueSegmentCount =
|
|
57
|
+
static_cast<size_t>((std::ceil(static_cast<float>(irLen) / static_cast<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 =
|
|
68
|
+
static_cast<size_t>((std::ceil(static_cast<float>(irLen) / static_cast<float>(_blockSize))));
|
|
69
|
+
_segSize = 2 * _blockSize;
|
|
70
|
+
// size of the FFT is 2B, so the complex size is B+1, due to the
|
|
71
|
+
// complex-conjugate symmetricity
|
|
72
|
+
_fftComplexSize = _segSize / 2 + 1;
|
|
73
|
+
_fft = std::make_shared<dsp::FFT>(static_cast<int>(_segSize));
|
|
74
|
+
_fftBuffer.resize(_segSize);
|
|
75
|
+
|
|
76
|
+
// segments preparation
|
|
77
|
+
for (int i = 0; i < _segCount; ++i) {
|
|
78
|
+
aligned_vec_complex vec(_fftComplexSize, std::complex<float>(0.0f, 0.0f));
|
|
79
|
+
_segments.push_back(vec);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// ir preparation
|
|
83
|
+
for (int i = 0; i < _segCount; ++i) {
|
|
84
|
+
aligned_vec_complex segment(_fftComplexSize);
|
|
85
|
+
const size_t remainingSamples = irLen - (i * _blockSize);
|
|
86
|
+
const size_t samplesToCopy = std::min(_blockSize, remainingSamples);
|
|
87
|
+
|
|
88
|
+
if (samplesToCopy > 0) {
|
|
89
|
+
memcpy(_fftBuffer.getData(), ir.getData() + i * _blockSize, samplesToCopy * sizeof(float));
|
|
90
|
+
}
|
|
91
|
+
// Each sub filter is zero-padded to length 2B and transformed using a
|
|
92
|
+
// 2B-point real-to-complex FFT.
|
|
93
|
+
memset(_fftBuffer.getData() + _blockSize, 0, _blockSize * sizeof(float));
|
|
94
|
+
_fft->doFFT(_fftBuffer.getData(), segment);
|
|
95
|
+
segment.at(0).imag(0.0f); // ensure DC component is real
|
|
96
|
+
_segmentsIR.push_back(segment);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
_preMultiplied = aligned_vec_complex(_fftComplexSize);
|
|
100
|
+
_inputBuffer.resize(_segSize);
|
|
101
|
+
_current = 0;
|
|
102
|
+
|
|
103
|
+
return true;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/// @brief Fast pairwise complex multiplication using ARM NEON intrinsics
|
|
107
|
+
/// @param ir Impulse response
|
|
108
|
+
/// @param audio Input audio signal
|
|
109
|
+
/// @param pre Output buffer for pre-multiplied results
|
|
110
|
+
/// @note IMPORTANT: ir, audio, and pre must be the same size and should be
|
|
111
|
+
/// aligned to 16 bytes for optimal performance
|
|
112
|
+
void pairwise_complex_multiply_fast(
|
|
113
|
+
const Convolver::aligned_vec_complex &ir,
|
|
114
|
+
const Convolver::aligned_vec_complex &audio,
|
|
115
|
+
Convolver::aligned_vec_complex &pre) {
|
|
116
|
+
size_t n = ir.size();
|
|
117
|
+
|
|
118
|
+
/// @note Using ARM NEON intrinsics for SIMD optimization
|
|
119
|
+
/// This implementation is on average 2x faster than the scalar version on ARM
|
|
120
|
+
/// architectures With 16-byte alignment it can be even faster up to 2.5x
|
|
121
|
+
#ifdef __ARM_NEON
|
|
122
|
+
size_t j = 0;
|
|
123
|
+
|
|
124
|
+
// Main vector loop: process 4 complex samples (8 floats) per iteration using
|
|
125
|
+
// vld2q/vst2q deinterleave
|
|
126
|
+
for (; j <= n - 4; j += 4) {
|
|
127
|
+
// load de-interleaved real/imag for 4 complex values
|
|
128
|
+
float32x4x2_t ir_de = vld2q_f32(reinterpret_cast<const float *>(&ir[j]));
|
|
129
|
+
float32x4x2_t a_de = vld2q_f32(reinterpret_cast<const float *>(&audio[j]));
|
|
130
|
+
float32x4x2_t pre_de = vld2q_f32(reinterpret_cast<float *>(&pre[j]));
|
|
131
|
+
|
|
132
|
+
float32x4_t ir_re = ir_de.val[0];
|
|
133
|
+
float32x4_t ir_im = ir_de.val[1];
|
|
134
|
+
float32x4_t a_re = a_de.val[0];
|
|
135
|
+
float32x4_t a_im = a_de.val[1];
|
|
136
|
+
|
|
137
|
+
// real = ir_re * a_re - ir_im * a_im
|
|
138
|
+
float32x4_t real = vmulq_f32(ir_re, a_re);
|
|
139
|
+
real = vmlsq_f32(real, ir_im, a_im);
|
|
140
|
+
// imag = ir_re * a_im + ir_im * a_re
|
|
141
|
+
float32x4_t imag = vmulq_f32(ir_re, a_im);
|
|
142
|
+
imag = vmlaq_f32(imag, ir_im, a_re);
|
|
143
|
+
|
|
144
|
+
// accumulate into pre
|
|
145
|
+
float32x4_t new_re = vaddq_f32(pre_de.val[0], real);
|
|
146
|
+
float32x4_t new_im = vaddq_f32(pre_de.val[1], imag);
|
|
147
|
+
|
|
148
|
+
float32x4x2_t out_de;
|
|
149
|
+
out_de.val[0] = new_re;
|
|
150
|
+
out_de.val[1] = new_im;
|
|
151
|
+
|
|
152
|
+
vst2q_f32(reinterpret_cast<float *>(&pre[j]), out_de);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Tail
|
|
156
|
+
for (; j < n; ++j) {
|
|
157
|
+
pre[j] += ir[j] * audio[j];
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
#else
|
|
161
|
+
// Fallback scalar implementation
|
|
162
|
+
for (size_t i = 0; i < n; ++i) {
|
|
163
|
+
pre[i] += ir[i] * audio[i];
|
|
164
|
+
}
|
|
165
|
+
#endif
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
void Convolver::process(float *data, float *outputData) {
|
|
169
|
+
// The input buffer acts as a 2B-point sliding window of the input signal.
|
|
170
|
+
// With each new input block, the right half of the input buffer is shifted
|
|
171
|
+
// to the left and the new block is stored in the right half.
|
|
172
|
+
memmove(_inputBuffer.getData(), _inputBuffer.getData() + _blockSize, _blockSize * sizeof(float));
|
|
173
|
+
memcpy(_inputBuffer.getData() + _blockSize, data, _blockSize * sizeof(float));
|
|
174
|
+
|
|
175
|
+
// All contents (DFT spectra) in the FDL are shifted up by one slot.
|
|
176
|
+
_current = (_current > 0) ? _current - 1 : _segCount - 1;
|
|
177
|
+
// A 2B-point real-to-complex FFT is computed from the input buffer,
|
|
178
|
+
// resulting in B+1 complex-conjugate symmetric DFT coefficients. The
|
|
179
|
+
// result is stored in the first FDL slot.
|
|
180
|
+
// _current marks first FDL slot, which is the current input block.
|
|
181
|
+
_fft->doFFT(_inputBuffer.getData(), _segments[_current]);
|
|
182
|
+
_segments[_current][0].imag(0.0f); // ensure DC component is real
|
|
183
|
+
|
|
184
|
+
// The P sub filter spectra are pairwisely multiplied with the input spectra
|
|
185
|
+
// in the FDL. The results are accumulated in the frequency-domain.
|
|
186
|
+
memset(_preMultiplied.data(), 0, _preMultiplied.size() * sizeof(std::complex<float>));
|
|
187
|
+
// this is a bottleneck of the algorithm
|
|
188
|
+
for (int i = 0; i < _segCount; ++i) {
|
|
189
|
+
const int indexAudio = (_current + i) % _segCount;
|
|
190
|
+
const auto &impulseResponseSegment = _segmentsIR[i];
|
|
191
|
+
const auto &audioSegment = _segments[indexAudio];
|
|
192
|
+
pairwise_complex_multiply_fast(impulseResponseSegment, audioSegment, _preMultiplied);
|
|
193
|
+
}
|
|
194
|
+
// Of the accumulated spectral convolutions, an 2B-point complex-to-real
|
|
195
|
+
// IFFT is computed. From the resulting 2B samples, the left half is
|
|
196
|
+
// discarded and the right half is returned as the next output block.
|
|
197
|
+
_fft->doInverseFFT(_preMultiplied, _fftBuffer.getData());
|
|
198
|
+
|
|
199
|
+
memcpy(outputData, _fftBuffer.getData() + _blockSize, _blockSize * sizeof(float));
|
|
200
|
+
}
|
|
201
|
+
} // namespace audioapi
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <audioapi/dsp/FFT.h>
|
|
4
|
+
#include <audioapi/utils/AlignedAllocator.hpp>
|
|
5
|
+
#include <audioapi/utils/AudioArray.h>
|
|
6
|
+
#include <complex>
|
|
7
|
+
#include <cstring>
|
|
8
|
+
#include <memory>
|
|
9
|
+
#include <vector>
|
|
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 {
|
|
25
|
+
return _trueSegmentCount;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
private:
|
|
29
|
+
size_t _trueSegmentCount;
|
|
30
|
+
size_t _blockSize;
|
|
31
|
+
size_t _segSize;
|
|
32
|
+
size_t _segCount;
|
|
33
|
+
size_t _fftComplexSize;
|
|
34
|
+
std::vector<aligned_vec_complex> _segments;
|
|
35
|
+
std::vector<aligned_vec_complex> _segmentsIR;
|
|
36
|
+
AudioArray _fftBuffer;
|
|
37
|
+
std::shared_ptr<dsp::FFT> _fft;
|
|
38
|
+
aligned_vec_complex _preMultiplied;
|
|
39
|
+
size_t _current;
|
|
40
|
+
AudioArray _inputBuffer;
|
|
41
|
+
|
|
42
|
+
friend void pairwise_complex_multiply_fast(
|
|
43
|
+
const aligned_vec_complex &ir,
|
|
44
|
+
const aligned_vec_complex &audio,
|
|
45
|
+
aligned_vec_complex &pre);
|
|
46
|
+
};
|
|
47
|
+
} // namespace audioapi
|
|
@@ -4,7 +4,7 @@ namespace audioapi::dsp {
|
|
|
4
4
|
|
|
5
5
|
FFT::FFT(int size) : size_(size) {
|
|
6
6
|
pffftSetup_ = pffft_new_setup(size_, PFFFT_REAL);
|
|
7
|
-
work_ =
|
|
7
|
+
work_ = reinterpret_cast<float *>(pffft_aligned_malloc(size_ * sizeof(float)));
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
FFT::~FFT() {
|
|
@@ -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
|
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
|
|
6
6
|
#include <algorithm>
|
|
7
7
|
#include <cmath>
|
|
8
|
-
#include <utility>
|
|
9
8
|
#include <complex>
|
|
9
|
+
#include <utility>
|
|
10
10
|
#include <vector>
|
|
11
11
|
|
|
12
12
|
namespace audioapi::dsp {
|
|
@@ -16,8 +16,24 @@ class FFT {
|
|
|
16
16
|
explicit FFT(int size);
|
|
17
17
|
~FFT();
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
void
|
|
19
|
+
template <typename Allocator>
|
|
20
|
+
void doFFT(float *in, std::vector<std::complex<float>, Allocator> &out) {
|
|
21
|
+
pffft_transform_ordered(
|
|
22
|
+
pffftSetup_, in, reinterpret_cast<float *>(&out[0]), work_, PFFFT_FORWARD);
|
|
23
|
+
// this is a possible place for bugs and mistakes
|
|
24
|
+
// due to pffft implementation and how it stores results
|
|
25
|
+
// keep this information in mind
|
|
26
|
+
// out[0].real = DC component - should be pure real
|
|
27
|
+
// out[0].imag = Nyquist component - should be pure real
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
template <typename Allocator>
|
|
31
|
+
void doInverseFFT(std::vector<std::complex<float>, Allocator> &in, float *out) {
|
|
32
|
+
pffft_transform_ordered(
|
|
33
|
+
pffftSetup_, reinterpret_cast<float *>(&in[0]), out, work_, PFFFT_BACKWARD);
|
|
34
|
+
|
|
35
|
+
dsp::multiplyByScalar(out, 1.0f / static_cast<float>(size_), out, size_);
|
|
36
|
+
}
|
|
21
37
|
|
|
22
38
|
private:
|
|
23
39
|
int size_;
|
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
|
|
26
26
|
#include <audioapi/dsp/AudioUtils.h>
|
|
27
27
|
#include <audioapi/dsp/VectorMath.h>
|
|
28
|
+
#include <algorithm>
|
|
28
29
|
|
|
29
30
|
#if defined(HAVE_ACCELERATE)
|
|
30
31
|
#include <Accelerate/Accelerate.h>
|
|
@@ -47,8 +48,7 @@ void multiplyByScalar(
|
|
|
47
48
|
float scalar,
|
|
48
49
|
float *outputVector,
|
|
49
50
|
size_t numberOfElementsToProcess) {
|
|
50
|
-
vDSP_vsmul(
|
|
51
|
-
inputVector, 1, &scalar, outputVector, 1, numberOfElementsToProcess);
|
|
51
|
+
vDSP_vsmul(inputVector, 1, &scalar, outputVector, 1, numberOfElementsToProcess);
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
void addScalar(
|
|
@@ -56,8 +56,7 @@ void addScalar(
|
|
|
56
56
|
float scalar,
|
|
57
57
|
float *outputVector,
|
|
58
58
|
size_t numberOfElementsToProcess) {
|
|
59
|
-
vDSP_vsadd(
|
|
60
|
-
inputVector, 1, &scalar, outputVector, 1, numberOfElementsToProcess);
|
|
59
|
+
vDSP_vsadd(inputVector, 1, &scalar, outputVector, 1, numberOfElementsToProcess);
|
|
61
60
|
}
|
|
62
61
|
|
|
63
62
|
void add(
|
|
@@ -65,14 +64,7 @@ void add(
|
|
|
65
64
|
const float *inputVector2,
|
|
66
65
|
float *outputVector,
|
|
67
66
|
size_t numberOfElementsToProcess) {
|
|
68
|
-
vDSP_vadd(
|
|
69
|
-
inputVector1,
|
|
70
|
-
1,
|
|
71
|
-
inputVector2,
|
|
72
|
-
1,
|
|
73
|
-
outputVector,
|
|
74
|
-
1,
|
|
75
|
-
numberOfElementsToProcess);
|
|
67
|
+
vDSP_vadd(inputVector1, 1, inputVector2, 1, outputVector, 1, numberOfElementsToProcess);
|
|
76
68
|
}
|
|
77
69
|
|
|
78
70
|
void subtract(
|
|
@@ -80,14 +72,7 @@ void subtract(
|
|
|
80
72
|
const float *inputVector2,
|
|
81
73
|
float *outputVector,
|
|
82
74
|
size_t numberOfElementsToProcess) {
|
|
83
|
-
vDSP_vsub(
|
|
84
|
-
inputVector1,
|
|
85
|
-
1,
|
|
86
|
-
inputVector2,
|
|
87
|
-
1,
|
|
88
|
-
outputVector,
|
|
89
|
-
1,
|
|
90
|
-
numberOfElementsToProcess);
|
|
75
|
+
vDSP_vsub(inputVector1, 1, inputVector2, 1, outputVector, 1, numberOfElementsToProcess);
|
|
91
76
|
}
|
|
92
77
|
|
|
93
78
|
void multiply(
|
|
@@ -95,19 +80,10 @@ void multiply(
|
|
|
95
80
|
const float *inputVector2,
|
|
96
81
|
float *outputVector,
|
|
97
82
|
size_t numberOfElementsToProcess) {
|
|
98
|
-
vDSP_vmul(
|
|
99
|
-
inputVector1,
|
|
100
|
-
1,
|
|
101
|
-
inputVector2,
|
|
102
|
-
1,
|
|
103
|
-
outputVector,
|
|
104
|
-
1,
|
|
105
|
-
numberOfElementsToProcess);
|
|
83
|
+
vDSP_vmul(inputVector1, 1, inputVector2, 1, outputVector, 1, numberOfElementsToProcess);
|
|
106
84
|
}
|
|
107
85
|
|
|
108
|
-
float maximumMagnitude(
|
|
109
|
-
const float *inputVector,
|
|
110
|
-
size_t numberOfElementsToProcess) {
|
|
86
|
+
float maximumMagnitude(const float *inputVector, size_t numberOfElementsToProcess) {
|
|
111
87
|
float maximumValue = 0;
|
|
112
88
|
vDSP_maxmgv(inputVector, 1, &maximumValue, numberOfElementsToProcess);
|
|
113
89
|
return maximumValue;
|
|
@@ -118,15 +94,7 @@ void multiplyByScalarThenAddToOutput(
|
|
|
118
94
|
float scalar,
|
|
119
95
|
float *outputVector,
|
|
120
96
|
size_t numberOfElementsToProcess) {
|
|
121
|
-
vDSP_vsma(
|
|
122
|
-
inputVector,
|
|
123
|
-
1,
|
|
124
|
-
&scalar,
|
|
125
|
-
outputVector,
|
|
126
|
-
1,
|
|
127
|
-
outputVector,
|
|
128
|
-
1,
|
|
129
|
-
numberOfElementsToProcess);
|
|
97
|
+
vDSP_vsma(inputVector, 1, &scalar, outputVector, 1, outputVector, 1, numberOfElementsToProcess);
|
|
130
98
|
}
|
|
131
99
|
|
|
132
100
|
#else
|
|
@@ -508,15 +476,15 @@ void multiply(
|
|
|
508
476
|
bool source2Aligned = is16ByteAligned(inputVector2);
|
|
509
477
|
bool destAligned = is16ByteAligned(outputVector);
|
|
510
478
|
|
|
511
|
-
#define SSE2_MULT(loadInstr, storeInstr)
|
|
512
|
-
while (outputVector < endP) {
|
|
513
|
-
pSource1 = _mm_load_ps(inputVector1);
|
|
479
|
+
#define SSE2_MULT(loadInstr, storeInstr) \
|
|
480
|
+
while (outputVector < endP) { \
|
|
481
|
+
pSource1 = _mm_load_ps(inputVector1); \
|
|
514
482
|
pSource2 = _mm_##loadInstr##_ps(inputVector2); \
|
|
515
|
-
dest = _mm_mul_ps(pSource1, pSource2);
|
|
516
|
-
_mm_##storeInstr##_ps(outputVector, dest);
|
|
517
|
-
inputVector1 += 4;
|
|
518
|
-
inputVector2 += 4;
|
|
519
|
-
outputVector += 4;
|
|
483
|
+
dest = _mm_mul_ps(pSource1, pSource2); \
|
|
484
|
+
_mm_##storeInstr##_ps(outputVector, dest); \
|
|
485
|
+
inputVector1 += 4; \
|
|
486
|
+
inputVector2 += 4; \
|
|
487
|
+
outputVector += 4; \
|
|
520
488
|
}
|
|
521
489
|
|
|
522
490
|
if (source2Aligned && destAligned) // Both aligned.
|
|
@@ -552,9 +520,7 @@ void multiply(
|
|
|
552
520
|
}
|
|
553
521
|
}
|
|
554
522
|
|
|
555
|
-
float maximumMagnitude(
|
|
556
|
-
const float *inputVector,
|
|
557
|
-
size_t numberOfElementsToProcess) {
|
|
523
|
+
float maximumMagnitude(const float *inputVector, size_t numberOfElementsToProcess) {
|
|
558
524
|
size_t n = numberOfElementsToProcess;
|
|
559
525
|
float max = 0;
|
|
560
526
|
|
|
@@ -647,15 +613,15 @@ void multiplyByScalarThenAddToOutput(
|
|
|
647
613
|
|
|
648
614
|
bool destAligned = is16ByteAligned(outputVector);
|
|
649
615
|
|
|
650
|
-
#define SSE2_MULT_ADD(loadInstr, storeInstr)
|
|
651
|
-
while (outputVector < endP) {
|
|
652
|
-
pSource = _mm_load_ps(inputVector);
|
|
653
|
-
temp = _mm_mul_ps(pSource, mScale);
|
|
616
|
+
#define SSE2_MULT_ADD(loadInstr, storeInstr) \
|
|
617
|
+
while (outputVector < endP) { \
|
|
618
|
+
pSource = _mm_load_ps(inputVector); \
|
|
619
|
+
temp = _mm_mul_ps(pSource, mScale); \
|
|
654
620
|
dest = _mm_##loadInstr##_ps(outputVector); \
|
|
655
|
-
dest = _mm_add_ps(dest, temp);
|
|
621
|
+
dest = _mm_add_ps(dest, temp); \
|
|
656
622
|
_mm_##storeInstr##_ps(outputVector, dest); \
|
|
657
|
-
inputVector += 4;
|
|
658
|
-
outputVector += 4;
|
|
623
|
+
inputVector += 4; \
|
|
624
|
+
outputVector += 4; \
|
|
659
625
|
}
|
|
660
626
|
|
|
661
627
|
if (destAligned)
|
|
@@ -28,23 +28,50 @@
|
|
|
28
28
|
// Defines the interface for several vector math functions whose implementation
|
|
29
29
|
// will ideally be optimized.
|
|
30
30
|
|
|
31
|
-
#include <cstddef>
|
|
32
31
|
#include <algorithm>
|
|
33
32
|
#include <cmath>
|
|
33
|
+
#include <cstddef>
|
|
34
34
|
|
|
35
35
|
namespace audioapi::dsp {
|
|
36
36
|
|
|
37
|
-
void multiplyByScalarThenAddToOutput(
|
|
37
|
+
void multiplyByScalarThenAddToOutput(
|
|
38
|
+
const float *inputVector,
|
|
39
|
+
float scalar,
|
|
40
|
+
float *outputVector,
|
|
41
|
+
size_t numberOfElementsToProcess);
|
|
38
42
|
|
|
39
|
-
void multiplyByScalar(
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
43
|
+
void multiplyByScalar(
|
|
44
|
+
const float *inputVector,
|
|
45
|
+
float scalar,
|
|
46
|
+
float *outputVector,
|
|
47
|
+
size_t numberOfElementsToProcess);
|
|
48
|
+
void addScalar(
|
|
49
|
+
const float *inputVector,
|
|
50
|
+
float scalar,
|
|
51
|
+
float *outputVector,
|
|
52
|
+
size_t numberOfElementsToProcess);
|
|
53
|
+
void add(
|
|
54
|
+
const float *inputVector1,
|
|
55
|
+
const float *inputVector2,
|
|
56
|
+
float *outputVector,
|
|
57
|
+
size_t numberOfElementsToProcess);
|
|
58
|
+
void subtract(
|
|
59
|
+
const float *inputVector1,
|
|
60
|
+
const float *inputVector2,
|
|
61
|
+
float *outputVector,
|
|
62
|
+
size_t numberOfElementsToProcess);
|
|
63
|
+
void multiply(
|
|
64
|
+
const float *inputVector1,
|
|
65
|
+
const float *inputVector2,
|
|
66
|
+
float *outputVector,
|
|
67
|
+
size_t numberOfElementsToProcess);
|
|
44
68
|
|
|
45
69
|
// Finds the maximum magnitude of a float vector.
|
|
46
70
|
float maximumMagnitude(const float *inputVector, size_t numberOfElementsToProcess);
|
|
47
71
|
|
|
48
|
-
void linearToDecibels(
|
|
72
|
+
void linearToDecibels(
|
|
73
|
+
const float *inputVector,
|
|
74
|
+
float *outputVector,
|
|
75
|
+
size_t numberOfElementsToProcess);
|
|
49
76
|
|
|
50
77
|
} // namespace audioapi::dsp
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
#include <audioapi/core/utils/Constants.h>
|
|
2
2
|
#include <audioapi/dsp/Windows.h>
|
|
3
|
+
#include <algorithm>
|
|
3
4
|
|
|
4
5
|
namespace audioapi::dsp {
|
|
5
6
|
|
|
6
|
-
void WindowFunction::forcePerfectReconstruction(
|
|
7
|
-
float *data,
|
|
8
|
-
int windowLength,
|
|
9
|
-
int interval) {
|
|
7
|
+
void WindowFunction::forcePerfectReconstruction(float *data, int windowLength, int interval) {
|
|
10
8
|
for (int i = 0; i < interval; ++i) {
|
|
11
9
|
float sum2 = 0;
|
|
12
10
|
|
|
@@ -58,14 +56,11 @@ float Kaiser::bandwidthToBeta(float bandwidth, bool heuristicOptimal) {
|
|
|
58
56
|
}
|
|
59
57
|
|
|
60
58
|
void ApproximateConfinedGaussian::apply(float *data, int size) const {
|
|
61
|
-
auto offsetScale =
|
|
62
|
-
getGaussian(1.0f) / (getGaussian(3.0f) + getGaussian(-1.0f));
|
|
59
|
+
auto offsetScale = getGaussian(1.0f) / (getGaussian(3.0f) + getGaussian(-1.0f));
|
|
63
60
|
auto norm = 1 / (getGaussian(1.0f) - 2 * offsetScale * getGaussian(2.0f));
|
|
64
61
|
for (int i = 0; i < size; ++i) {
|
|
65
62
|
auto r = static_cast<float>(2 * i + 1) / static_cast<float>(size) - 1.0f;
|
|
66
|
-
data[i] = norm *
|
|
67
|
-
(getGaussian(r) -
|
|
68
|
-
offsetScale * (getGaussian(r - 2) + getGaussian(r + 2)));
|
|
63
|
+
data[i] = norm * (getGaussian(r) - offsetScale * (getGaussian(r - 2) + getGaussian(r + 2)));
|
|
69
64
|
}
|
|
70
65
|
}
|
|
71
66
|
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
#pragma once
|
|
2
2
|
|
|
3
3
|
#include <cmath>
|
|
4
|
-
#include <algorithm>
|
|
5
4
|
|
|
6
5
|
namespace audioapi::dsp {
|
|
7
6
|
|
|
@@ -9,7 +8,7 @@ namespace audioapi::dsp {
|
|
|
9
8
|
// https://personalpages.hs-kempten.de/~vollratj/InEl/pdf/Window%20function%20-%20Wikipedia.pdf
|
|
10
9
|
class WindowFunction {
|
|
11
10
|
public:
|
|
12
|
-
explicit WindowFunction(float amplitude = 1.0f): amplitude_(amplitude) {}
|
|
11
|
+
explicit WindowFunction(float amplitude = 1.0f) : amplitude_(amplitude) {}
|
|
13
12
|
|
|
14
13
|
virtual void apply(float *data, int size) const = 0;
|
|
15
14
|
// forces STFT perfect-reconstruction (WOLA) on an existing window, for a given STFT interval.
|
|
@@ -23,29 +22,30 @@ class WindowFunction {
|
|
|
23
22
|
//https://en.wikipedia.org/wiki/Hann_function
|
|
24
23
|
// https://www.sciencedirect.com/topics/engineering/hanning-window
|
|
25
24
|
// https://docs.scipy.org/doc//scipy-1.2.3/reference/generated/scipy.signal.windows.hann.html#scipy.signal.windows.hann
|
|
26
|
-
class Hann: public WindowFunction {
|
|
25
|
+
class Hann : public WindowFunction {
|
|
27
26
|
public:
|
|
28
|
-
explicit Hann(float amplitude = 1.0f): WindowFunction(amplitude) {}
|
|
27
|
+
explicit Hann(float amplitude = 1.0f) : WindowFunction(amplitude) {}
|
|
29
28
|
|
|
30
29
|
void apply(float *data, int size) const override;
|
|
31
30
|
};
|
|
32
31
|
|
|
33
32
|
// https://www.sciencedirect.com/topics/engineering/blackman-window
|
|
34
33
|
// https://docs.scipy.org/doc//scipy-1.2.3/reference/generated/scipy.signal.windows.blackman.html#scipy.signal.windows.blackman
|
|
35
|
-
class Blackman: public WindowFunction {
|
|
34
|
+
class Blackman : public WindowFunction {
|
|
36
35
|
public:
|
|
37
|
-
explicit Blackman(float amplitude = 1.0f): WindowFunction(amplitude) {}
|
|
36
|
+
explicit Blackman(float amplitude = 1.0f) : WindowFunction(amplitude) {}
|
|
38
37
|
|
|
39
38
|
void apply(float *data, int size) const override;
|
|
40
39
|
};
|
|
41
40
|
|
|
42
|
-
|
|
43
41
|
// https://en.wikipedia.org/wiki/Kaiser_window
|
|
44
|
-
class Kaiser: public WindowFunction {
|
|
42
|
+
class Kaiser : public WindowFunction {
|
|
45
43
|
public:
|
|
46
|
-
explicit Kaiser(float beta, float amplitude = 1.0f)
|
|
44
|
+
explicit Kaiser(float beta, float amplitude = 1.0f)
|
|
45
|
+
: WindowFunction(amplitude), beta_(beta), invB0_(1.0f / bessel0(beta)) {}
|
|
47
46
|
|
|
48
|
-
static Kaiser
|
|
47
|
+
static Kaiser
|
|
48
|
+
withBandwidth(float bandwidth, bool heuristicOptimal = false, float amplitude = 1.0f) {
|
|
49
49
|
return Kaiser(bandwidthToBeta(bandwidth, heuristicOptimal), amplitude);
|
|
50
50
|
}
|
|
51
51
|
|
|
@@ -59,25 +59,26 @@ class Kaiser: public WindowFunction {
|
|
|
59
59
|
|
|
60
60
|
// https://en.wikipedia.org/wiki/Bessel_function#Modified_Bessel_functions:_I%CE%B1,_K%CE%B1
|
|
61
61
|
static inline float bessel0(float x) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
62
|
+
const double significanceLimit = 1e-4;
|
|
63
|
+
auto result = 0.0f;
|
|
64
|
+
auto term = 1.0f;
|
|
65
|
+
auto m = 1.0f;
|
|
66
|
+
while (term > significanceLimit) {
|
|
67
|
+
result += term;
|
|
68
|
+
++m;
|
|
69
|
+
term *= (x * x) / (4 * m * m);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return result;
|
|
73
73
|
}
|
|
74
74
|
static float bandwidthToBeta(float bandwidth, bool heuristicOptimal = false);
|
|
75
75
|
};
|
|
76
76
|
|
|
77
77
|
// https://www.recordingblogs.com/wiki/gaussian-window
|
|
78
|
-
class ApproximateConfinedGaussian: public WindowFunction {
|
|
78
|
+
class ApproximateConfinedGaussian : public WindowFunction {
|
|
79
79
|
public:
|
|
80
|
-
explicit ApproximateConfinedGaussian(float sigma, float amplitude = 1.0f)
|
|
80
|
+
explicit ApproximateConfinedGaussian(float sigma, float amplitude = 1.0f)
|
|
81
|
+
: WindowFunction(amplitude), gaussianFactor_(0.0625f / (sigma * sigma)) {}
|
|
81
82
|
|
|
82
83
|
static ApproximateConfinedGaussian withBandwidth(float bandwidth, float amplitude = 1.0f) {
|
|
83
84
|
return ApproximateConfinedGaussian(bandwidthToSigma(bandwidth), amplitude);
|