From 15d82fcf0d5c593d7e22e86b58f9e735cd6031e3 Mon Sep 17 00:00:00 2001 From: maciejmakowski2003 Date: Thu, 12 Mar 2026 12:44:39 +0100 Subject: [PATCH 1/2] refactor: integrated DSPAudioBuffer and DSPAudioArray into codebase --- .../docs/guides/create-your-own-effect.mdx | 6 +- .../basic/shared/MyProcessorNode.cpp | 4 +- .../templates/basic/shared/MyProcessorNode.h | 4 +- .../android/core/AndroidAudioRecorder.cpp | 2 +- .../android/core/AndroidAudioRecorder.h | 1 - .../cpp/audioapi/android/core/AudioPlayer.cpp | 4 +- .../cpp/audioapi/android/core/AudioPlayer.h | 6 +- .../core/utils/AndroidRecorderCallback.cpp | 3 +- .../core/utils/AndroidRecorderCallback.h | 1 - .../cpp/audioapi/AudioAPIModuleInstaller.h | 2 +- .../effects/ConvolverNodeHostObject.cpp | 8 +- .../effects/WaveShaperNodeHostObject.cpp | 4 +- .../AudioBufferSourceNodeHostObject.cpp | 10 +- .../common/cpp/audioapi/core/AudioContext.cpp | 4 +- .../common/cpp/audioapi/core/AudioContext.h | 3 +- .../common/cpp/audioapi/core/AudioNode.cpp | 18 +-- .../common/cpp/audioapi/core/AudioNode.h | 22 ++-- .../common/cpp/audioapi/core/AudioParam.cpp | 12 +- .../common/cpp/audioapi/core/AudioParam.h | 14 +-- .../cpp/audioapi/core/BaseAudioContext.cpp | 2 +- .../cpp/audioapi/core/BaseAudioContext.h | 1 - .../cpp/audioapi/core/OfflineAudioContext.cpp | 11 +- .../cpp/audioapi/core/OfflineAudioContext.h | 6 +- .../audioapi/core/analysis/AnalyserNode.cpp | 17 ++- .../cpp/audioapi/core/analysis/AnalyserNode.h | 18 +-- .../destinations/AudioDestinationNode.cpp | 2 +- .../core/destinations/AudioDestinationNode.h | 6 +- .../core/effects/BiquadFilterNode.cpp | 4 +- .../audioapi/core/effects/BiquadFilterNode.h | 12 +- .../audioapi/core/effects/ConvolverNode.cpp | 22 ++-- .../cpp/audioapi/core/effects/ConvolverNode.h | 18 +-- .../cpp/audioapi/core/effects/DelayNode.cpp | 6 +- .../cpp/audioapi/core/effects/DelayNode.h | 6 +- .../cpp/audioapi/core/effects/GainNode.cpp | 4 +- .../cpp/audioapi/core/effects/GainNode.h | 4 +- .../audioapi/core/effects/IIRFilterNode.cpp | 4 +- .../cpp/audioapi/core/effects/IIRFilterNode.h | 6 +- .../audioapi/core/effects/PeriodicWave.cpp | 6 +- .../cpp/audioapi/core/effects/PeriodicWave.h | 13 +- .../core/effects/StereoPannerNode.cpp | 4 +- .../audioapi/core/effects/StereoPannerNode.h | 4 +- .../audioapi/core/effects/WaveShaperNode.cpp | 4 +- .../audioapi/core/effects/WaveShaperNode.h | 4 +- .../cpp/audioapi/core/effects/WorkletNode.cpp | 4 +- .../cpp/audioapi/core/effects/WorkletNode.h | 8 +- .../core/effects/WorkletProcessingNode.cpp | 6 +- .../core/effects/WorkletProcessingNode.h | 8 +- .../audioapi/core/inputs/AudioRecorder.cpp | 1 - .../cpp/audioapi/core/inputs/AudioRecorder.h | 1 - .../sources/AudioBufferBaseSourceNode.cpp | 8 +- .../core/sources/AudioBufferBaseSourceNode.h | 10 +- .../sources/AudioBufferQueueSourceNode.cpp | 8 +- .../core/sources/AudioBufferQueueSourceNode.h | 8 +- .../core/sources/AudioBufferSourceNode.cpp | 18 ++- .../core/sources/AudioBufferSourceNode.h | 12 +- .../core/sources/AudioScheduledSourceNode.cpp | 2 +- .../core/sources/AudioScheduledSourceNode.h | 2 +- .../core/sources/ConstantSourceNode.cpp | 4 +- .../core/sources/ConstantSourceNode.h | 4 +- .../audioapi/core/sources/OscillatorNode.cpp | 6 +- .../audioapi/core/sources/OscillatorNode.h | 4 +- .../core/sources/RecorderAdapterNode.cpp | 4 +- .../core/sources/RecorderAdapterNode.h | 6 +- .../audioapi/core/sources/StreamerNode.cpp | 8 +- .../cpp/audioapi/core/sources/StreamerNode.h | 6 +- .../core/sources/WorkletSourceNode.cpp | 4 +- .../audioapi/core/sources/WorkletSourceNode.h | 8 +- .../core/utils/AudioRecorderCallback.cpp | 2 +- .../core/utils/AudioRecorderCallback.h | 2 +- .../common/cpp/audioapi/dsp/Convolver.cpp | 8 +- .../common/cpp/audioapi/dsp/Convolver.h | 6 +- .../common/cpp/audioapi/dsp/FFT.h | 12 +- .../common/cpp/audioapi/dsp/WaveShaper.cpp | 14 +-- .../common/cpp/audioapi/dsp/WaveShaper.h | 12 +- .../cpp/audioapi/dsp/r8brain/Resampler.cpp | 85 ------------- .../cpp/audioapi/dsp/r8brain/Resampler.h | 47 ------- .../cpp/audioapi/dsp/r8brain/Resampler.hpp | 118 +++++++++++++++++ .../common/cpp/audioapi/utils/AudioArray.hpp | 2 +- .../cpp/audioapi/utils/AudioArrayBuffer.hpp | 16 +-- .../common/cpp/audioapi/utils/AudioBuffer.hpp | 41 ++++-- .../cpp/audioapi/utils/CircularArray.hpp | 119 ++++++++++++++++++ .../cpp/audioapi/utils/CircularAudioArray.cpp | 101 --------------- .../cpp/audioapi/utils/CircularAudioArray.h | 32 ----- .../cpp/test/src/core/effects/DelayTest.cpp | 10 +- .../cpp/test/src/core/effects/GainTest.cpp | 8 +- .../src/core/effects/StereoPannerTest.cpp | 10 +- .../src/core/effects/WaveShaperNodeTest.cpp | 6 +- .../core/sources/AudioScheduledSourceTest.cpp | 7 +- .../src/core/sources/ConstantSourceTest.cpp | 6 +- .../ios/audioapi/ios/core/IOSAudioPlayer.h | 6 +- .../ios/audioapi/ios/core/IOSAudioPlayer.mm | 4 +- .../ios/audioapi/ios/core/IOSAudioRecorder.mm | 2 +- .../ios/core/utils/IOSRecorderCallback.h | 1 - .../ios/core/utils/IOSRecorderCallback.mm | 2 +- 94 files changed, 555 insertions(+), 586 deletions(-) delete mode 100644 packages/react-native-audio-api/common/cpp/audioapi/dsp/r8brain/Resampler.cpp delete mode 100644 packages/react-native-audio-api/common/cpp/audioapi/dsp/r8brain/Resampler.h create mode 100644 packages/react-native-audio-api/common/cpp/audioapi/dsp/r8brain/Resampler.hpp create mode 100644 packages/react-native-audio-api/common/cpp/audioapi/utils/CircularArray.hpp delete mode 100644 packages/react-native-audio-api/common/cpp/audioapi/utils/CircularAudioArray.cpp delete mode 100644 packages/react-native-audio-api/common/cpp/audioapi/utils/CircularAudioArray.h diff --git a/packages/audiodocs/docs/guides/create-your-own-effect.mdx b/packages/audiodocs/docs/guides/create-your-own-effect.mdx index 4a7f73ead..1ca972150 100644 --- a/packages/audiodocs/docs/guides/create-your-own-effect.mdx +++ b/packages/audiodocs/docs/guides/create-your-own-effect.mdx @@ -52,8 +52,8 @@ public: explicit MyProcessorNode(const std::shared_ptr &context, ); protected: - std::shared_ptr - processNode(const std::shared_ptr &buffer, + std::shared_ptr + processNode(const std::shared_ptr &buffer, int framesToProcess) override; // highlight-start @@ -80,7 +80,7 @@ namespace audioapi { isInitialized_.store(true, std::memory_order_release); } - std::shared_ptr MyProcessorNode::processNode(const std::shared_ptr &buffer, + std::shared_ptr MyProcessorNode::processNode(const std::shared_ptr &buffer, int framesToProcess) { // highlight-start for (int channel = 0; channel < buffer->getNumberOfChannels(); ++channel) { diff --git a/packages/custom-node-generator/templates/basic/shared/MyProcessorNode.cpp b/packages/custom-node-generator/templates/basic/shared/MyProcessorNode.cpp index 5d6baee0a..f1f75f7d7 100644 --- a/packages/custom-node-generator/templates/basic/shared/MyProcessorNode.cpp +++ b/packages/custom-node-generator/templates/basic/shared/MyProcessorNode.cpp @@ -7,8 +7,8 @@ MyProcessorNode::MyProcessorNode( isInitialized_.store(true, std::memory_order_release); } -std::shared_ptr -MyProcessorNode::processNode(const std::shared_ptr &buffer, +std::shared_ptr +MyProcessorNode::processNode(const std::shared_ptr &buffer, int framesToProcess) { // put your processing logic here } diff --git a/packages/custom-node-generator/templates/basic/shared/MyProcessorNode.h b/packages/custom-node-generator/templates/basic/shared/MyProcessorNode.h index c9880d678..d97b96399 100644 --- a/packages/custom-node-generator/templates/basic/shared/MyProcessorNode.h +++ b/packages/custom-node-generator/templates/basic/shared/MyProcessorNode.h @@ -10,8 +10,8 @@ class MyProcessorNode : public AudioNode { explicit MyProcessorNode(const std::shared_ptr &context, ); protected: - std::shared_ptr - processNode(const std::shared_ptr &buffer, + std::shared_ptr + processNode(const std::shared_ptr &buffer, int framesToProcess) override; }; } // namespace audioapi diff --git a/packages/react-native-audio-api/android/src/main/cpp/audioapi/android/core/AndroidAudioRecorder.cpp b/packages/react-native-audio-api/android/src/main/cpp/audioapi/android/core/AndroidAudioRecorder.cpp index 974135bd5..11b5e3c29 100644 --- a/packages/react-native-audio-api/android/src/main/cpp/audioapi/android/core/AndroidAudioRecorder.cpp +++ b/packages/react-native-audio-api/android/src/main/cpp/audioapi/android/core/AndroidAudioRecorder.cpp @@ -12,7 +12,7 @@ #include #include #include -#include +#include #include #include diff --git a/packages/react-native-audio-api/android/src/main/cpp/audioapi/android/core/AndroidAudioRecorder.h b/packages/react-native-audio-api/android/src/main/cpp/audioapi/android/core/AndroidAudioRecorder.h index 01814f023..4de0b5049 100644 --- a/packages/react-native-audio-api/android/src/main/cpp/audioapi/android/core/AndroidAudioRecorder.h +++ b/packages/react-native-audio-api/android/src/main/cpp/audioapi/android/core/AndroidAudioRecorder.h @@ -11,7 +11,6 @@ namespace audioapi { -class CircularAudioArray; class AudioFileProperties; class AndroidRecorderCallback; class AndroidFileWriterBackend; diff --git a/packages/react-native-audio-api/android/src/main/cpp/audioapi/android/core/AudioPlayer.cpp b/packages/react-native-audio-api/android/src/main/cpp/audioapi/android/core/AudioPlayer.cpp index 31da2da45..547b734fa 100644 --- a/packages/react-native-audio-api/android/src/main/cpp/audioapi/android/core/AudioPlayer.cpp +++ b/packages/react-native-audio-api/android/src/main/cpp/audioapi/android/core/AudioPlayer.cpp @@ -12,7 +12,7 @@ namespace audioapi { AudioPlayer::AudioPlayer( - const std::function, int)> &renderAudio, + const std::function, int)> &renderAudio, float sampleRate, int channelCount) : renderAudio_(renderAudio), @@ -42,7 +42,7 @@ bool AudioPlayer::openAudioStream() { return false; } - buffer_ = std::make_shared(RENDER_QUANTUM_SIZE, channelCount_, sampleRate_); + buffer_ = std::make_shared(RENDER_QUANTUM_SIZE, channelCount_, sampleRate_); return true; } diff --git a/packages/react-native-audio-api/android/src/main/cpp/audioapi/android/core/AudioPlayer.h b/packages/react-native-audio-api/android/src/main/cpp/audioapi/android/core/AudioPlayer.h index a24fcca38..878ce7b14 100644 --- a/packages/react-native-audio-api/android/src/main/cpp/audioapi/android/core/AudioPlayer.h +++ b/packages/react-native-audio-api/android/src/main/cpp/audioapi/android/core/AudioPlayer.h @@ -17,7 +17,7 @@ class AudioContext; class AudioPlayer : public AudioStreamDataCallback, AudioStreamErrorCallback { public: AudioPlayer( - const std::function, int)> &renderAudio, + const std::function, int)> &renderAudio, float sampleRate, int channelCount); @@ -40,9 +40,9 @@ class AudioPlayer : public AudioStreamDataCallback, AudioStreamErrorCallback { void onErrorAfterClose(AudioStream * /* audioStream */, Result /* error */) override; private: - std::function, int)> renderAudio_; + std::function, int)> renderAudio_; std::shared_ptr mStream_; - std::shared_ptr buffer_; + std::shared_ptr buffer_; bool isInitialized_ = false; float sampleRate_; int channelCount_; diff --git a/packages/react-native-audio-api/android/src/main/cpp/audioapi/android/core/utils/AndroidRecorderCallback.cpp b/packages/react-native-audio-api/android/src/main/cpp/audioapi/android/core/utils/AndroidRecorderCallback.cpp index 208c950ce..b38196a59 100644 --- a/packages/react-native-audio-api/android/src/main/cpp/audioapi/android/core/utils/AndroidRecorderCallback.cpp +++ b/packages/react-native-audio-api/android/src/main/cpp/audioapi/android/core/utils/AndroidRecorderCallback.cpp @@ -4,8 +4,7 @@ #include #include #include - -#include +#include #include #include diff --git a/packages/react-native-audio-api/android/src/main/cpp/audioapi/android/core/utils/AndroidRecorderCallback.h b/packages/react-native-audio-api/android/src/main/cpp/audioapi/android/core/utils/AndroidRecorderCallback.h index c35945c0c..ab726c2c2 100644 --- a/packages/react-native-audio-api/android/src/main/cpp/audioapi/android/core/utils/AndroidRecorderCallback.h +++ b/packages/react-native-audio-api/android/src/main/cpp/audioapi/android/core/utils/AndroidRecorderCallback.h @@ -10,7 +10,6 @@ namespace audioapi { -class CircularAudioArray; class AudioEventHandlerRegistry; struct CallbackData { diff --git a/packages/react-native-audio-api/common/cpp/audioapi/AudioAPIModuleInstaller.h b/packages/react-native-audio-api/common/cpp/audioapi/AudioAPIModuleInstaller.h index dc5cc6388..d01d5dd36 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/AudioAPIModuleInstaller.h +++ b/packages/react-native-audio-api/common/cpp/audioapi/AudioAPIModuleInstaller.h @@ -188,7 +188,7 @@ class AudioAPIModuleInstaller { static jsi::Function getCreateAudioBufferFunction(jsi::Runtime *jsiRuntime) { return jsi::Function::createFromHostFunction( *jsiRuntime, - jsi::PropNameID::forAscii(*jsiRuntime, "createAudioStretcher"), + jsi::PropNameID::forAscii(*jsiRuntime, "createAudioBuffer"), 3, [](jsi::Runtime &runtime, const jsi::Value &thisValue, const jsi::Value *args, size_t count) -> jsi::Value { diff --git a/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/effects/ConvolverNodeHostObject.cpp b/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/effects/ConvolverNodeHostObject.cpp index fa5e10432..ba939cefa 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/effects/ConvolverNodeHostObject.cpp +++ b/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/effects/ConvolverNodeHostObject.cpp @@ -80,17 +80,17 @@ void ConvolverNodeHostObject::setBuffer(const std::shared_ptr &buff convolvers.back().init(RENDER_QUANTUM_SIZE, channelData, copiedBuffer->getSize()); } - auto internalBuffer = std::make_shared( + auto internalBuffer = std::make_shared( RENDER_QUANTUM_SIZE * 2, convolverNode->getChannelCount(), copiedBuffer->getSampleRate()); - auto intermediateBuffer = std::make_shared( + auto intermediateBuffer = std::make_shared( RENDER_QUANTUM_SIZE, convolvers.size(), copiedBuffer->getSampleRate()); struct SetupData { std::shared_ptr buffer; std::vector convolvers; std::shared_ptr threadPool; - std::shared_ptr internalBuffer; - std::shared_ptr intermediateBuffer; + std::shared_ptr internalBuffer; + std::shared_ptr intermediateBuffer; float scaleFactor; }; diff --git a/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/effects/WaveShaperNodeHostObject.cpp b/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/effects/WaveShaperNodeHostObject.cpp index d50d04867..69d03d7d4 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/effects/WaveShaperNodeHostObject.cpp +++ b/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/effects/WaveShaperNodeHostObject.cpp @@ -47,8 +47,8 @@ JSI_HOST_FUNCTION_IMPL(WaveShaperNodeHostObject, setCurve) { thisValue.asObject(runtime).setExternalMemoryPressure(runtime, arrayBuffer.size(runtime) * 2); auto size = static_cast(arrayBuffer.size(runtime) / sizeof(float)); - curve = std::make_shared( - reinterpret_cast(arrayBuffer.data(runtime)), size); + curve = + std::make_shared(reinterpret_cast(arrayBuffer.data(runtime)), size); } auto event = [waveShaperNode, curve](BaseAudioContext &) { diff --git a/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/sources/AudioBufferSourceNodeHostObject.cpp b/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/sources/AudioBufferSourceNodeHostObject.cpp index 512ef1687..003e96d77 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/sources/AudioBufferSourceNodeHostObject.cpp +++ b/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/sources/AudioBufferSourceNodeHostObject.cpp @@ -169,13 +169,13 @@ void AudioBufferSourceNodeHostObject::setBuffer(const std::shared_ptr(node_); std::shared_ptr copiedBuffer; - std::shared_ptr playbackRateBuffer; - std::shared_ptr audioBuffer; + std::shared_ptr playbackRateBuffer; + std::shared_ptr audioBuffer; if (buffer == nullptr) { copiedBuffer = nullptr; playbackRateBuffer = nullptr; - audioBuffer = std::make_shared( + audioBuffer = std::make_shared( RENDER_QUANTUM_SIZE, 1, audioBufferSourceNode->getContextSampleRate()); } else { if (pitchCorrection_) { @@ -191,11 +191,11 @@ void AudioBufferSourceNodeHostObject::setBuffer(const std::shared_ptr(*buffer); } - playbackRateBuffer = std::make_shared( + playbackRateBuffer = std::make_shared( 3 * RENDER_QUANTUM_SIZE, copiedBuffer->getNumberOfChannels(), audioBufferSourceNode->getContextSampleRate()); - audioBuffer = std::make_shared( + audioBuffer = std::make_shared( RENDER_QUANTUM_SIZE, copiedBuffer->getNumberOfChannels(), audioBufferSourceNode->getContextSampleRate()); diff --git a/packages/react-native-audio-api/common/cpp/audioapi/core/AudioContext.cpp b/packages/react-native-audio-api/common/cpp/audioapi/core/AudioContext.cpp index efb3a0d08..cc7497116 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/core/AudioContext.cpp +++ b/packages/react-native-audio-api/common/cpp/audioapi/core/AudioContext.cpp @@ -89,8 +89,8 @@ bool AudioContext::start() { return false; } -std::function, int)> AudioContext::renderAudio() { - return [this](const std::shared_ptr &data, int frames) { +std::function, int)> AudioContext::renderAudio() { + return [this](const std::shared_ptr &data, int frames) { destination_->renderAudio(data, frames); }; } diff --git a/packages/react-native-audio-api/common/cpp/audioapi/core/AudioContext.h b/packages/react-native-audio-api/common/cpp/audioapi/core/AudioContext.h index 57295baec..5b3defe4c 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/core/AudioContext.h +++ b/packages/react-native-audio-api/common/cpp/audioapi/core/AudioContext.h @@ -2,6 +2,7 @@ #include #include +#include #include #include @@ -37,7 +38,7 @@ class AudioContext : public BaseAudioContext { bool isDriverRunning() const override; - std::function, int)> renderAudio(); + std::function, int)> renderAudio(); }; } // namespace audioapi diff --git a/packages/react-native-audio-api/common/cpp/audioapi/core/AudioNode.cpp b/packages/react-native-audio-api/common/cpp/audioapi/core/AudioNode.cpp index 65bdce8b2..a1bac0ef3 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/core/AudioNode.cpp +++ b/packages/react-native-audio-api/common/cpp/audioapi/core/AudioNode.cpp @@ -19,8 +19,8 @@ AudioNode::AudioNode( channelCountMode_(options.channelCountMode), channelInterpretation_(options.channelInterpretation), requiresTailProcessing_(options.requiresTailProcessing) { - audioBuffer_ = - std::make_shared(RENDER_QUANTUM_SIZE, channelCount_, context->getSampleRate()); + audioBuffer_ = std::make_shared( + RENDER_QUANTUM_SIZE, channelCount_, context->getSampleRate()); } AudioNode::~AudioNode() { @@ -100,8 +100,8 @@ void AudioNode::disable() { } } -std::shared_ptr AudioNode::processAudio( - const std::shared_ptr &outputBuffer, +std::shared_ptr AudioNode::processAudio( + const std::shared_ptr &outputBuffer, int framesToProcess, bool checkIsAlreadyProcessed) { if (!isInitialized_.load(std::memory_order_acquire)) { @@ -146,8 +146,8 @@ bool AudioNode::isAlreadyProcessed() { return true; } -std::shared_ptr AudioNode::processInputs( - const std::shared_ptr &outputBuffer, +std::shared_ptr AudioNode::processInputs( + const std::shared_ptr &outputBuffer, int framesToProcess, bool checkIsAlreadyProcessed) { auto processingBuffer = audioBuffer_; @@ -175,8 +175,8 @@ std::shared_ptr AudioNode::processInputs( return processingBuffer; } -std::shared_ptr AudioNode::applyChannelCountMode( - const std::shared_ptr &processingBuffer) { +std::shared_ptr AudioNode::applyChannelCountMode( + const std::shared_ptr &processingBuffer) { // If the channelCountMode is EXPLICIT, the node should output the number of // channels specified by the channelCount. if (channelCountMode_ == ChannelCountMode::EXPLICIT) { @@ -193,7 +193,7 @@ std::shared_ptr AudioNode::applyChannelCountMode( return processingBuffer; } -void AudioNode::mixInputsBuffers(const std::shared_ptr &processingBuffer) { +void AudioNode::mixInputsBuffers(const std::shared_ptr &processingBuffer) { assert(processingBuffer != nullptr); for (auto it = inputBuffers_.begin(), end = inputBuffers_.end(); it != end; ++it) { diff --git a/packages/react-native-audio-api/common/cpp/audioapi/core/AudioNode.h b/packages/react-native-audio-api/common/cpp/audioapi/core/AudioNode.h index 6966b4532..6f19a1800 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/core/AudioNode.h +++ b/packages/react-native-audio-api/common/cpp/audioapi/core/AudioNode.h @@ -31,8 +31,8 @@ class AudioNode : public std::enable_shared_from_this { void disconnect(); void disconnect(const std::shared_ptr &node); void disconnect(const std::shared_ptr ¶m); - virtual std::shared_ptr processAudio( - const std::shared_ptr &outputBuffer, + virtual std::shared_ptr processAudio( + const std::shared_ptr &outputBuffer, int framesToProcess, bool checkIsAlreadyProcessed); @@ -69,7 +69,7 @@ class AudioNode : public std::enable_shared_from_this { friend class DelayNodeHostObject; std::weak_ptr context_; - std::shared_ptr audioBuffer_; + std::shared_ptr audioBuffer_; const int numberOfInputs_ = 1; const int numberOfOutputs_ = 1; @@ -92,18 +92,20 @@ class AudioNode : public std::enable_shared_from_this { private: bool isEnabled_ = true; - std::vector> inputBuffers_ = {}; + std::vector> inputBuffers_ = {}; - virtual std::shared_ptr processInputs( - const std::shared_ptr &outputBuffer, + virtual std::shared_ptr processInputs( + const std::shared_ptr &outputBuffer, int framesToProcess, bool checkIsAlreadyProcessed); - virtual std::shared_ptr processNode(const std::shared_ptr &, int) = 0; + virtual std::shared_ptr processNode( + const std::shared_ptr &, + int) = 0; bool isAlreadyProcessed(); - std::shared_ptr applyChannelCountMode( - const std::shared_ptr &processingBuffer); - void mixInputsBuffers(const std::shared_ptr &processingBuffer); + std::shared_ptr applyChannelCountMode( + const std::shared_ptr &processingBuffer); + void mixInputsBuffers(const std::shared_ptr &processingBuffer); void connectNode(const std::shared_ptr &node); void disconnectNode(const std::shared_ptr &node); diff --git a/packages/react-native-audio-api/common/cpp/audioapi/core/AudioParam.cpp b/packages/react-native-audio-api/common/cpp/audioapi/core/AudioParam.cpp index d2dc150a7..f5a59e99a 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/core/AudioParam.cpp +++ b/packages/react-native-audio-api/common/cpp/audioapi/core/AudioParam.cpp @@ -24,7 +24,7 @@ AudioParam::AudioParam( startValue_(defaultValue), endValue_(defaultValue), audioBuffer_( - std::make_shared(RENDER_QUANTUM_SIZE, 1, context->getSampleRate())) { + std::make_shared(RENDER_QUANTUM_SIZE, 1, context->getSampleRate())) { inputBuffers_.reserve(4); inputNodes_.reserve(4); // Default calculation function just returns the static value @@ -220,8 +220,8 @@ void AudioParam::removeInputNode(AudioNode *node) { } } -std::shared_ptr AudioParam::calculateInputs( - const std::shared_ptr &processingBuffer, +std::shared_ptr AudioParam::calculateInputs( + const std::shared_ptr &processingBuffer, int framesToProcess) { processingBuffer->zero(); if (inputNodes_.empty()) { @@ -232,7 +232,7 @@ std::shared_ptr AudioParam::calculateInputs( return processingBuffer; } -std::shared_ptr AudioParam::processARateParam(int framesToProcess, double time) { +std::shared_ptr AudioParam::processARateParam(int framesToProcess, double time) { auto processingBuffer = calculateInputs(audioBuffer_, framesToProcess); std::shared_ptr context = context_.lock(); @@ -261,7 +261,7 @@ float AudioParam::processKRateParam(int framesToProcess, double time) { } void AudioParam::processInputs( - const std::shared_ptr &outputBuffer, + const std::shared_ptr &outputBuffer, int framesToProcess, bool checkIsAlreadyProcessed) { for (auto it = inputNodes_.begin(), end = inputNodes_.end(); it != end; ++it) { @@ -279,7 +279,7 @@ void AudioParam::processInputs( } } -void AudioParam::mixInputsBuffers(const std::shared_ptr &processingBuffer) { +void AudioParam::mixInputsBuffers(const std::shared_ptr &processingBuffer) { assert(processingBuffer != nullptr); // Sum all input buffers into the processing buffer diff --git a/packages/react-native-audio-api/common/cpp/audioapi/core/AudioParam.h b/packages/react-native-audio-api/common/cpp/audioapi/core/AudioParam.h index b6186f944..932e1a289 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/core/AudioParam.h +++ b/packages/react-native-audio-api/common/cpp/audioapi/core/AudioParam.h @@ -89,7 +89,7 @@ class AudioParam { void removeInputNode(AudioNode *node); /// @note Audio Thread only - std::shared_ptr processARateParam(int framesToProcess, double time); + std::shared_ptr processARateParam(int framesToProcess, double time); /// @note Audio Thread only float processKRateParam(int framesToProcess, double time); @@ -113,8 +113,8 @@ class AudioParam { // Input modulation system std::vector inputNodes_; - std::shared_ptr audioBuffer_; - std::vector> inputBuffers_; + std::shared_ptr audioBuffer_; + std::vector> inputBuffers_; /// @brief Get the end time of the parameter queue. /// @return The end time of the parameter queue or last endTime_ if queue is empty. @@ -142,12 +142,12 @@ class AudioParam { } float getValueAtTime(double time); void processInputs( - const std::shared_ptr &outputBuffer, + const std::shared_ptr &outputBuffer, int framesToProcess, bool checkIsAlreadyProcessed); - void mixInputsBuffers(const std::shared_ptr &processingBuffer); - std::shared_ptr calculateInputs( - const std::shared_ptr &processingBuffer, + void mixInputsBuffers(const std::shared_ptr &processingBuffer); + std::shared_ptr calculateInputs( + const std::shared_ptr &processingBuffer, int framesToProcess); }; diff --git a/packages/react-native-audio-api/common/cpp/audioapi/core/BaseAudioContext.cpp b/packages/react-native-audio-api/common/cpp/audioapi/core/BaseAudioContext.cpp index 7bc205f9a..67e4013e0 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/core/BaseAudioContext.cpp +++ b/packages/react-native-audio-api/common/cpp/audioapi/core/BaseAudioContext.cpp @@ -25,7 +25,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/packages/react-native-audio-api/common/cpp/audioapi/core/BaseAudioContext.h b/packages/react-native-audio-api/common/cpp/audioapi/core/BaseAudioContext.h index e3f52fd28..099e4d3d5 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/core/BaseAudioContext.h +++ b/packages/react-native-audio-api/common/cpp/audioapi/core/BaseAudioContext.h @@ -3,7 +3,6 @@ #include #include #include -#include #include #include diff --git a/packages/react-native-audio-api/common/cpp/audioapi/core/OfflineAudioContext.cpp b/packages/react-native-audio-api/common/cpp/audioapi/core/OfflineAudioContext.cpp index 389cab337..d78479a01 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/core/OfflineAudioContext.cpp +++ b/packages/react-native-audio-api/common/cpp/audioapi/core/OfflineAudioContext.cpp @@ -6,7 +6,6 @@ #include #include #include -#include #include #include @@ -26,6 +25,8 @@ OfflineAudioContext::OfflineAudioContext( length_(length), numberOfChannels_(numberOfChannels), currentSampleFrame_(0), + audioBuffer_( + std::make_shared(RENDER_QUANTUM_SIZE, numberOfChannels, sampleRate)), resultBuffer_(std::make_shared(length, numberOfChannels, sampleRate)) {} OfflineAudioContext::~OfflineAudioContext() { @@ -63,17 +64,15 @@ void OfflineAudioContext::renderAudio() { setState(ContextState::RUNNING); std::thread([this]() { - auto audioBuffer = - std::make_shared(RENDER_QUANTUM_SIZE, numberOfChannels_, getSampleRate()); - while (currentSampleFrame_ < length_) { Locker locker(mutex_); int framesToProcess = std::min(static_cast(length_ - currentSampleFrame_), RENDER_QUANTUM_SIZE); - destination_->renderAudio(audioBuffer, framesToProcess); + audioBuffer_->zero(); + destination_->renderAudio(audioBuffer_, framesToProcess); - resultBuffer_->copy(*audioBuffer, 0, currentSampleFrame_, framesToProcess); + resultBuffer_->copy(*audioBuffer_, 0, currentSampleFrame_, framesToProcess); currentSampleFrame_ += framesToProcess; diff --git a/packages/react-native-audio-api/common/cpp/audioapi/core/OfflineAudioContext.h b/packages/react-native-audio-api/common/cpp/audioapi/core/OfflineAudioContext.h index ce2015d4a..be9a3a546 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/core/OfflineAudioContext.h +++ b/packages/react-native-audio-api/common/cpp/audioapi/core/OfflineAudioContext.h @@ -2,6 +2,7 @@ #include #include +#include #include #include @@ -37,10 +38,11 @@ class OfflineAudioContext : public BaseAudioContext { std::unordered_map scheduledSuspends_; OfflineAudioContextResultCallback resultCallback_; - size_t length_; - int numberOfChannels_; + const size_t length_; + const int numberOfChannels_; size_t currentSampleFrame_; + std::shared_ptr audioBuffer_; std::shared_ptr resultBuffer_; void renderAudio(); diff --git a/packages/react-native-audio-api/common/cpp/audioapi/core/analysis/AnalyserNode.cpp b/packages/react-native-audio-api/common/cpp/audioapi/core/analysis/AnalyserNode.cpp index 21db375d4..c2fe1d96b 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/core/analysis/AnalyserNode.cpp +++ b/packages/react-native-audio-api/common/cpp/audioapi/core/analysis/AnalyserNode.cpp @@ -3,7 +3,6 @@ #include #include #include -#include #include #include @@ -15,9 +14,9 @@ AnalyserNode::AnalyserNode( const std::shared_ptr &context, const AnalyserOptions &options) : AudioNode(context, options), - inputArray_(std::make_unique(MAX_FFT_SIZE * 2)), + inputArray_(std::make_unique(MAX_FFT_SIZE * 2)), downMixBuffer_( - std::make_unique(RENDER_QUANTUM_SIZE, 1, context->getSampleRate())), + std::make_unique(RENDER_QUANTUM_SIZE, 1, context->getSampleRate())), minDecibels_(options.minDecibels), maxDecibels_(options.maxDecibels), smoothingTimeConstant_(options.smoothingTimeConstant) { @@ -32,8 +31,8 @@ void AnalyserNode::setFFTSize(int fftSize) { fft_ = std::make_unique(fftSize); complexData_ = std::vector>(fftSize); - magnitudeArray_ = std::make_unique(fftSize / 2); - tempArray_ = std::make_unique(fftSize); + magnitudeArray_ = std::make_unique(fftSize / 2); + tempArray_ = std::make_unique(fftSize); initializeWindowData(fftSize); fftSize_.store(fftSize, std::memory_order_release); } @@ -88,8 +87,8 @@ void AnalyserNode::getByteTimeDomainData(uint8_t *data, int length) { } } -std::shared_ptr AnalyserNode::processNode( - const std::shared_ptr &processingBuffer, +std::shared_ptr AnalyserNode::processNode( + const std::shared_ptr &processingBuffer, int framesToProcess) { // Analyser should behave like a sniffer node, it should not modify the // processingBuffer but instead copy the data to its own input buffer. @@ -148,7 +147,7 @@ void AnalyserNode::doFFTAnalysis() { } void AnalyserNode::initializeWindowData(int fftSize) { - windowData_ = std::make_unique(fftSize); + windowData_ = std::make_unique(fftSize); auto data = windowData_->span(); auto size = windowData_->getSize(); @@ -156,7 +155,7 @@ void AnalyserNode::initializeWindowData(int fftSize) { const auto alpha = 2.0f * std::numbers::pi_v * invSizeMinusOne; for (size_t i = 0; i < size; ++i) { - const auto phase = alpha * i; + const auto phase = alpha * static_cast(i); // 4*PI*x is just 2 * (2*PI*x) const auto window = 0.42f - 0.50f * std::cos(phase) + 0.08f * std::cos(2.0f * phase); data[i] = window; diff --git a/packages/react-native-audio-api/common/cpp/audioapi/core/analysis/AnalyserNode.h b/packages/react-native-audio-api/common/cpp/audioapi/core/analysis/AnalyserNode.h index 354a3ec91..fd7ef326c 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/core/analysis/AnalyserNode.h +++ b/packages/react-native-audio-api/common/cpp/audioapi/core/analysis/AnalyserNode.h @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -16,7 +17,6 @@ namespace audioapi { -class CircularAudioArray; struct AnalyserOptions; class AnalyserNode : public AudioNode { @@ -75,16 +75,16 @@ class AnalyserNode : public AudioNode { void getByteTimeDomainData(uint8_t *data, int length); protected: - std::shared_ptr processNode( - const std::shared_ptr &processingBuffer, + std::shared_ptr processNode( + const std::shared_ptr &processingBuffer, int framesToProcess) override; private: std::atomic fftSize_; // Audio Thread data structures - std::unique_ptr inputArray_; - std::unique_ptr downMixBuffer_; + std::unique_ptr inputArray_; + std::unique_ptr downMixBuffer_; // JS Thread parameters float minDecibels_; @@ -93,13 +93,13 @@ class AnalyserNode : public AudioNode { // JS Thread data structures std::unique_ptr fft_; - std::unique_ptr tempArray_; - std::unique_ptr windowData_; + std::unique_ptr tempArray_; + std::unique_ptr windowData_; std::vector> complexData_; - std::unique_ptr magnitudeArray_; + std::unique_ptr magnitudeArray_; struct AnalysisFrame { - AudioArray timeDomain; + DSPAudioArray timeDomain; size_t sequenceNumber = 0; int fftSize = 0; diff --git a/packages/react-native-audio-api/common/cpp/audioapi/core/destinations/AudioDestinationNode.cpp b/packages/react-native-audio-api/common/cpp/audioapi/core/destinations/AudioDestinationNode.cpp index 27a815389..e7fcd1d40 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/core/destinations/AudioDestinationNode.cpp +++ b/packages/react-native-audio-api/common/cpp/audioapi/core/destinations/AudioDestinationNode.cpp @@ -22,7 +22,7 @@ double AudioDestinationNode::getCurrentTime() const { } void AudioDestinationNode::renderAudio( - const std::shared_ptr &destinationBuffer, + const std::shared_ptr &destinationBuffer, int numFrames) { if (numFrames < 0 || !destinationBuffer || !isInitialized_.load(std::memory_order_acquire)) { return; diff --git a/packages/react-native-audio-api/common/cpp/audioapi/core/destinations/AudioDestinationNode.h b/packages/react-native-audio-api/common/cpp/audioapi/core/destinations/AudioDestinationNode.h index 51c4dcb39..5135751da 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/core/destinations/AudioDestinationNode.h +++ b/packages/react-native-audio-api/common/cpp/audioapi/core/destinations/AudioDestinationNode.h @@ -23,13 +23,13 @@ class AudioDestinationNode : public AudioNode { double getCurrentTime() const; /// @note Audio Thread only - void renderAudio(const std::shared_ptr &audioData, int numFrames); + void renderAudio(const std::shared_ptr &audioData, int numFrames); protected: // DestinationNode is triggered by AudioContext using renderAudio // processNode function is not necessary and is never called. - std::shared_ptr processNode( - const std::shared_ptr &processingBuffer, + std::shared_ptr processNode( + const std::shared_ptr &processingBuffer, int) final { return processingBuffer; }; diff --git a/packages/react-native-audio-api/common/cpp/audioapi/core/effects/BiquadFilterNode.cpp b/packages/react-native-audio-api/common/cpp/audioapi/core/effects/BiquadFilterNode.cpp index c3411a4f3..3988093e6 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/core/effects/BiquadFilterNode.cpp +++ b/packages/react-native-audio-api/common/cpp/audioapi/core/effects/BiquadFilterNode.cpp @@ -380,8 +380,8 @@ BiquadFilterNode::FilterCoefficients BiquadFilterNode::applyFilter( return coeffs; } -std::shared_ptr BiquadFilterNode::processNode( - const std::shared_ptr &processingBuffer, +std::shared_ptr BiquadFilterNode::processNode( + const std::shared_ptr &processingBuffer, int framesToProcess) { if (std::shared_ptr context = context_.lock()) { auto currentTime = context->getCurrentTime(); diff --git a/packages/react-native-audio-api/common/cpp/audioapi/core/effects/BiquadFilterNode.h b/packages/react-native-audio-api/common/cpp/audioapi/core/effects/BiquadFilterNode.h index 477feca92..47288f131 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/core/effects/BiquadFilterNode.h +++ b/packages/react-native-audio-api/common/cpp/audioapi/core/effects/BiquadFilterNode.h @@ -68,8 +68,8 @@ class BiquadFilterNode : public AudioNode { BiquadFilterType type); protected: - std::shared_ptr processNode( - const std::shared_ptr &processingBuffer, + std::shared_ptr processNode( + const std::shared_ptr &processingBuffer, int framesToProcess) override; private: @@ -80,10 +80,10 @@ class BiquadFilterNode : public AudioNode { BiquadFilterType type_; // delayed samples, one per channel - AudioArray x1_; - AudioArray x2_; - AudioArray y1_; - AudioArray y2_; + DSPAudioArray x1_; + DSPAudioArray x2_; + DSPAudioArray y1_; + DSPAudioArray y2_; struct alignas(64) FilterCoefficients { double b0, b1, b2, a1, a2; diff --git a/packages/react-native-audio-api/common/cpp/audioapi/core/effects/ConvolverNode.cpp b/packages/react-native-audio-api/common/cpp/audioapi/core/effects/ConvolverNode.cpp index 290f8716c..d2bf43911 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/core/effects/ConvolverNode.cpp +++ b/packages/react-native-audio-api/common/cpp/audioapi/core/effects/ConvolverNode.cpp @@ -29,8 +29,8 @@ void ConvolverNode::setBuffer( const std::shared_ptr &buffer, std::vector convolvers, const std::shared_ptr &threadPool, - const std::shared_ptr &internalBuffer, - const std::shared_ptr &intermediateBuffer, + const std::shared_ptr &internalBuffer, + const std::shared_ptr &intermediateBuffer, float scaleFactor) { std::shared_ptr context = context_.lock(); if (context == nullptr) { @@ -42,14 +42,8 @@ void ConvolverNode::setBuffer( if (buffer_) { graphManager->addAudioBufferForDestruction(std::move(buffer_)); } - if (internalBuffer_) { - graphManager->addAudioBufferForDestruction(std::move(internalBuffer_)); - } - if (intermediateBuffer_) { - graphManager->addAudioBufferForDestruction(std::move(intermediateBuffer_)); - } - // TODO move convolvers and thread destruction to graph manager as well + // TODO move convolvers, thread pool and DSPAudioBuffers destruction to graph manager as well buffer_ = buffer; convolvers_ = std::move(convolvers); @@ -96,8 +90,8 @@ void ConvolverNode::onInputDisabled() { } } -std::shared_ptr ConvolverNode::processInputs( - const std::shared_ptr &outputBuffer, +std::shared_ptr ConvolverNode::processInputs( + const std::shared_ptr &outputBuffer, int framesToProcess, bool checkIsAlreadyProcessed) { if (internalBufferIndex_ < framesToProcess) { @@ -108,8 +102,8 @@ std::shared_ptr ConvolverNode::processInputs( // processing pipeline: processingBuffer -> intermediateBuffer_ -> audioBuffer_ (mixing // with intermediateBuffer_) -std::shared_ptr ConvolverNode::processNode( - const std::shared_ptr &processingBuffer, +std::shared_ptr ConvolverNode::processNode( + const std::shared_ptr &processingBuffer, int framesToProcess) { if (signalledToStop_) { if (remainingSegments_ > 0) { @@ -146,7 +140,7 @@ std::shared_ptr ConvolverNode::processNode( return audioBuffer_; } -void ConvolverNode::performConvolution(const std::shared_ptr &processingBuffer) { +void ConvolverNode::performConvolution(const std::shared_ptr &processingBuffer) { if (processingBuffer->getNumberOfChannels() == 1) { for (int i = 0; i < convolvers_.size(); ++i) { threadPool_->schedule([&, i] { diff --git a/packages/react-native-audio-api/common/cpp/audioapi/core/effects/ConvolverNode.h b/packages/react-native-audio-api/common/cpp/audioapi/core/effects/ConvolverNode.h index 9c30f9570..489fa191b 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/core/effects/ConvolverNode.h +++ b/packages/react-native-audio-api/common/cpp/audioapi/core/effects/ConvolverNode.h @@ -29,20 +29,20 @@ class ConvolverNode : public AudioNode { const std::shared_ptr &buffer, std::vector convolvers, const std::shared_ptr &threadPool, - const std::shared_ptr &internalBuffer, - const std::shared_ptr &intermediateBuffer, + const std::shared_ptr &internalBuffer, + const std::shared_ptr &intermediateBuffer, float scaleFactor); float calculateNormalizationScale(const std::shared_ptr &buffer); protected: - std::shared_ptr processNode( - const std::shared_ptr &processingBuffer, + std::shared_ptr processNode( + const std::shared_ptr &processingBuffer, int framesToProcess) override; private: - std::shared_ptr processInputs( - const std::shared_ptr &outputBuffer, + std::shared_ptr processInputs( + const std::shared_ptr &outputBuffer, int framesToProcess, bool checkIsAlreadyProcessed) override; void onInputDisabled() override; @@ -51,17 +51,17 @@ class ConvolverNode : public AudioNode { size_t internalBufferIndex_; bool signalledToStop_; float scaleFactor_; - std::shared_ptr intermediateBuffer_; + std::shared_ptr intermediateBuffer_; // impulse response buffer std::shared_ptr buffer_; // buffer to hold internal processed data - std::shared_ptr internalBuffer_; + std::shared_ptr internalBuffer_; // vectors of convolvers, one per channel std::vector convolvers_; std::shared_ptr threadPool_; - void performConvolution(const std::shared_ptr &processingBuffer); + void performConvolution(const std::shared_ptr &processingBuffer); }; } // namespace audioapi diff --git a/packages/react-native-audio-api/common/cpp/audioapi/core/effects/DelayNode.cpp b/packages/react-native-audio-api/common/cpp/audioapi/core/effects/DelayNode.cpp index ef8d6ae73..d33e376a6 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/core/effects/DelayNode.cpp +++ b/packages/react-native-audio-api/common/cpp/audioapi/core/effects/DelayNode.cpp @@ -35,7 +35,7 @@ void DelayNode::onInputDisabled() { } void DelayNode::delayBufferOperation( - const std::shared_ptr &processingBuffer, + const std::shared_ptr &processingBuffer, int framesToProcess, size_t &operationStartingIndex, DelayNode::BufferAction action) { @@ -75,8 +75,8 @@ void DelayNode::delayBufferOperation( // processing is split into two parts // 1. writing to delay buffer (mixing if needed) from processing buffer // 2. reading from delay buffer to processing buffer (mixing if needed) with delay -std::shared_ptr DelayNode::processNode( - const std::shared_ptr &processingBuffer, +std::shared_ptr DelayNode::processNode( + const std::shared_ptr &processingBuffer, int framesToProcess) { // handling tail processing if (signalledToStop_) { diff --git a/packages/react-native-audio-api/common/cpp/audioapi/core/effects/DelayNode.h b/packages/react-native-audio-api/common/cpp/audioapi/core/effects/DelayNode.h index 4d76180de..38d1efe9f 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/core/effects/DelayNode.h +++ b/packages/react-native-audio-api/common/cpp/audioapi/core/effects/DelayNode.h @@ -17,15 +17,15 @@ class DelayNode : public AudioNode { [[nodiscard]] std::shared_ptr getDelayTimeParam() const; protected: - std::shared_ptr processNode( - const std::shared_ptr &processingBuffer, + std::shared_ptr processNode( + const std::shared_ptr &processingBuffer, int framesToProcess) override; private: void onInputDisabled() override; enum class BufferAction { READ, WRITE }; void delayBufferOperation( - const std::shared_ptr &processingBuffer, + const std::shared_ptr &processingBuffer, int framesToProcess, size_t &operationStartingIndex, BufferAction action); diff --git a/packages/react-native-audio-api/common/cpp/audioapi/core/effects/GainNode.cpp b/packages/react-native-audio-api/common/cpp/audioapi/core/effects/GainNode.cpp index a389ee566..b14938f8d 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/core/effects/GainNode.cpp +++ b/packages/react-native-audio-api/common/cpp/audioapi/core/effects/GainNode.cpp @@ -23,8 +23,8 @@ std::shared_ptr GainNode::getGainParam() const { return gainParam_; } -std::shared_ptr GainNode::processNode( - const std::shared_ptr &processingBuffer, +std::shared_ptr GainNode::processNode( + const std::shared_ptr &processingBuffer, int framesToProcess) { std::shared_ptr context = context_.lock(); if (context == nullptr) diff --git a/packages/react-native-audio-api/common/cpp/audioapi/core/effects/GainNode.h b/packages/react-native-audio-api/common/cpp/audioapi/core/effects/GainNode.h index 4be75e632..797a44c5a 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/core/effects/GainNode.h +++ b/packages/react-native-audio-api/common/cpp/audioapi/core/effects/GainNode.h @@ -17,8 +17,8 @@ class GainNode : public AudioNode { [[nodiscard]] std::shared_ptr getGainParam() const; protected: - std::shared_ptr processNode( - const std::shared_ptr &processingBuffer, + std::shared_ptr processNode( + const std::shared_ptr &processingBuffer, int framesToProcess) override; private: diff --git a/packages/react-native-audio-api/common/cpp/audioapi/core/effects/IIRFilterNode.cpp b/packages/react-native-audio-api/common/cpp/audioapi/core/effects/IIRFilterNode.cpp index 0f3d2640d..16e4b7b78 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/core/effects/IIRFilterNode.cpp +++ b/packages/react-native-audio-api/common/cpp/audioapi/core/effects/IIRFilterNode.cpp @@ -97,8 +97,8 @@ void IIRFilterNode::getFrequencyResponse( // TODO: tail -std::shared_ptr IIRFilterNode::processNode( - const std::shared_ptr &processingBuffer, +std::shared_ptr IIRFilterNode::processNode( + const std::shared_ptr &processingBuffer, int framesToProcess) { int numChannels = processingBuffer->getNumberOfChannels(); diff --git a/packages/react-native-audio-api/common/cpp/audioapi/core/effects/IIRFilterNode.h b/packages/react-native-audio-api/common/cpp/audioapi/core/effects/IIRFilterNode.h index 29562cf63..dfffbe62b 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/core/effects/IIRFilterNode.h +++ b/packages/react-native-audio-api/common/cpp/audioapi/core/effects/IIRFilterNode.h @@ -52,8 +52,8 @@ class IIRFilterNode : public AudioNode { size_t length) const; protected: - std::shared_ptr processNode( - const std::shared_ptr &processingBuffer, + std::shared_ptr processNode( + const std::shared_ptr &processingBuffer, int framesToProcess) override; private: @@ -64,7 +64,7 @@ class IIRFilterNode : public AudioNode { AudioBuffer xBuffers_; AudioBuffer yBuffers_; - AudioArray bufferIndices_; + DSPAudioArray bufferIndices_; static std::complex evaluatePolynomial(const AudioArray &coefficients, std::complex z, int order) { diff --git a/packages/react-native-audio-api/common/cpp/audioapi/core/effects/PeriodicWave.cpp b/packages/react-native-audio-api/common/cpp/audioapi/core/effects/PeriodicWave.cpp index 423c21789..559d95de1 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/core/effects/PeriodicWave.cpp +++ b/packages/react-native-audio-api/common/cpp/audioapi/core/effects/PeriodicWave.cpp @@ -48,7 +48,7 @@ PeriodicWave::PeriodicWave(float sampleRate, bool disableNormalization) static_cast(nyquistFrequency) / static_cast(getMaxNumberOfPartials()); scale_ = static_cast(getPeriodicWaveSize()) / static_cast(sampleRate_); bandLimitedTables_ = - std::make_unique(getPeriodicWaveSize(), numberOfRanges_, sampleRate_); + std::make_unique(getPeriodicWaveSize(), numberOfRanges_, sampleRate_); fft_ = std::make_unique(getPeriodicWaveSize()); } @@ -254,8 +254,8 @@ float PeriodicWave::doInterpolation( float phase, float phaseIncrement, float waveTableInterpolationFactor, - const AudioArray &lowerWaveData, - const AudioArray &higherWaveData) const { + const DSPAudioArray &lowerWaveData, + const DSPAudioArray &higherWaveData) const { float lowerWaveDataSample = 0; float higherWaveDataSample = 0; diff --git a/packages/react-native-audio-api/common/cpp/audioapi/core/effects/PeriodicWave.h b/packages/react-native-audio-api/common/cpp/audioapi/core/effects/PeriodicWave.h index dd756d0c1..a5dbeffa5 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/core/effects/PeriodicWave.h +++ b/packages/react-native-audio-api/common/cpp/audioapi/core/effects/PeriodicWave.h @@ -39,8 +39,8 @@ namespace audioapi { struct WaveTableSource { - const AudioArray *lower; - const AudioArray *higher; + const DSPAudioArray *lower; + const DSPAudioArray *higher; float interpolationFactor; }; @@ -86,7 +86,8 @@ class PeriodicWave { // This function returns the interpolation factor between the lower and higher // range data and sets the lower and higher wave data for the given // fundamental frequency. - WaveTableSource getWaveDataForFundamentalFrequency(float fundamentalFrequency) const; + [[nodiscard]] WaveTableSource getWaveDataForFundamentalFrequency( + float fundamentalFrequency) const; // This function performs interpolation between the lower and higher range // data based on the interpolation factor and current buffer index. Type of @@ -96,8 +97,8 @@ class PeriodicWave { float bufferIndex, float phaseIncrement, float waveTableInterpolationFactor, - const AudioArray &lowerWaveData, - const AudioArray &higherWaveData) const; + const DSPAudioArray &lowerWaveData, + const DSPAudioArray &higherWaveData) const; // determines the time resolution of the waveform. float sampleRate_; @@ -110,7 +111,7 @@ class PeriodicWave { // rate. float scale_; // array of band-limited waveforms. - std::unique_ptr bandLimitedTables_; + std::unique_ptr bandLimitedTables_; std::unique_ptr fft_; // if true, the waveTable is not normalized. bool disableNormalization_; diff --git a/packages/react-native-audio-api/common/cpp/audioapi/core/effects/StereoPannerNode.cpp b/packages/react-native-audio-api/common/cpp/audioapi/core/effects/StereoPannerNode.cpp index 0d1764b3d..b47f05c4d 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/core/effects/StereoPannerNode.cpp +++ b/packages/react-native-audio-api/common/cpp/audioapi/core/effects/StereoPannerNode.cpp @@ -22,8 +22,8 @@ std::shared_ptr StereoPannerNode::getPanParam() const { return panParam_; } -std::shared_ptr StereoPannerNode::processNode( - const std::shared_ptr &processingBuffer, +std::shared_ptr StereoPannerNode::processNode( + const std::shared_ptr &processingBuffer, int framesToProcess) { std::shared_ptr context = context_.lock(); if (context == nullptr) diff --git a/packages/react-native-audio-api/common/cpp/audioapi/core/effects/StereoPannerNode.h b/packages/react-native-audio-api/common/cpp/audioapi/core/effects/StereoPannerNode.h index ecaae9a77..f54f26682 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/core/effects/StereoPannerNode.h +++ b/packages/react-native-audio-api/common/cpp/audioapi/core/effects/StereoPannerNode.h @@ -20,8 +20,8 @@ class StereoPannerNode : public AudioNode { [[nodiscard]] std::shared_ptr getPanParam() const; protected: - std::shared_ptr processNode( - const std::shared_ptr &processingBuffer, + std::shared_ptr processNode( + const std::shared_ptr &processingBuffer, int framesToProcess) override; private: diff --git a/packages/react-native-audio-api/common/cpp/audioapi/core/effects/WaveShaperNode.cpp b/packages/react-native-audio-api/common/cpp/audioapi/core/effects/WaveShaperNode.cpp index 68e37a38a..54a56c0d6 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/core/effects/WaveShaperNode.cpp +++ b/packages/react-native-audio-api/common/cpp/audioapi/core/effects/WaveShaperNode.cpp @@ -37,8 +37,8 @@ void WaveShaperNode::setCurve(const std::shared_ptr &curve) { } } -std::shared_ptr WaveShaperNode::processNode( - const std::shared_ptr &processingBuffer, +std::shared_ptr WaveShaperNode::processNode( + const std::shared_ptr &processingBuffer, int framesToProcess) { if (curve_ == nullptr) { return processingBuffer; diff --git a/packages/react-native-audio-api/common/cpp/audioapi/core/effects/WaveShaperNode.h b/packages/react-native-audio-api/common/cpp/audioapi/core/effects/WaveShaperNode.h index 6690a3d70..f47bb9ab5 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/core/effects/WaveShaperNode.h +++ b/packages/react-native-audio-api/common/cpp/audioapi/core/effects/WaveShaperNode.h @@ -26,8 +26,8 @@ class WaveShaperNode : public AudioNode { void setCurve(const std::shared_ptr &curve); protected: - std::shared_ptr processNode( - const std::shared_ptr &processingBuffer, + std::shared_ptr processNode( + const std::shared_ptr &processingBuffer, int framesToProcess) override; private: diff --git a/packages/react-native-audio-api/common/cpp/audioapi/core/effects/WorkletNode.cpp b/packages/react-native-audio-api/common/cpp/audioapi/core/effects/WorkletNode.cpp index d18f15dbd..3c772bbbe 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/core/effects/WorkletNode.cpp +++ b/packages/react-native-audio-api/common/cpp/audioapi/core/effects/WorkletNode.cpp @@ -20,8 +20,8 @@ WorkletNode::WorkletNode( isInitialized_.store(true, std::memory_order_release); } -std::shared_ptr WorkletNode::processNode( - const std::shared_ptr &processingBuffer, +std::shared_ptr WorkletNode::processNode( + const std::shared_ptr &processingBuffer, int framesToProcess) { size_t processed = 0; size_t channelCount_ = diff --git a/packages/react-native-audio-api/common/cpp/audioapi/core/effects/WorkletNode.h b/packages/react-native-audio-api/common/cpp/audioapi/core/effects/WorkletNode.h index ad73d78dd..8d8d3b6e1 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/core/effects/WorkletNode.h +++ b/packages/react-native-audio-api/common/cpp/audioapi/core/effects/WorkletNode.h @@ -23,8 +23,8 @@ class WorkletNode : public AudioNode { : AudioNode(context) {} protected: - std::shared_ptr processNode( - const std::shared_ptr &processingBuffer, + std::shared_ptr processNode( + const std::shared_ptr &processingBuffer, int framesToProcess) override { return processingBuffer; } @@ -44,8 +44,8 @@ class WorkletNode : public AudioNode { ~WorkletNode() override = default; protected: - std::shared_ptr processNode( - const std::shared_ptr &processingBuffer, + std::shared_ptr processNode( + const std::shared_ptr &processingBuffer, int framesToProcess) override; private: diff --git a/packages/react-native-audio-api/common/cpp/audioapi/core/effects/WorkletProcessingNode.cpp b/packages/react-native-audio-api/common/cpp/audioapi/core/effects/WorkletProcessingNode.cpp index 683a34df4..2095ce87c 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/core/effects/WorkletProcessingNode.cpp +++ b/packages/react-native-audio-api/common/cpp/audioapi/core/effects/WorkletProcessingNode.cpp @@ -22,8 +22,8 @@ WorkletProcessingNode::WorkletProcessingNode( isInitialized_.store(true, std::memory_order_release); } -std::shared_ptr WorkletProcessingNode::processNode( - const std::shared_ptr &processingBuffer, +std::shared_ptr WorkletProcessingNode::processNode( + const std::shared_ptr &processingBuffer, int framesToProcess) { size_t channelCount = std::min( static_cast(2), // Fixed to stereo for now @@ -53,7 +53,7 @@ std::shared_ptr WorkletProcessingNode::processNode( // We call unsafely here because we are already on the runtime thread // and the runtime is locked by executeOnRuntimeSync (if // shouldLockRuntime is true) - float time = 0.0f; + double time = 0.0f; if (std::shared_ptr context = context_.lock()) { time = context->getCurrentTime(); } diff --git a/packages/react-native-audio-api/common/cpp/audioapi/core/effects/WorkletProcessingNode.h b/packages/react-native-audio-api/common/cpp/audioapi/core/effects/WorkletProcessingNode.h index 8a52a742e..ffd7473a3 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/core/effects/WorkletProcessingNode.h +++ b/packages/react-native-audio-api/common/cpp/audioapi/core/effects/WorkletProcessingNode.h @@ -22,8 +22,8 @@ class WorkletProcessingNode : public AudioNode { : AudioNode(context) {} protected: - std::shared_ptr processNode( - const std::shared_ptr &processingBuffer, + std::shared_ptr processNode( + const std::shared_ptr &processingBuffer, int framesToProcess) override { return processingBuffer; } @@ -39,8 +39,8 @@ class WorkletProcessingNode : public AudioNode { WorkletsRunner &&workletRunner); protected: - std::shared_ptr processNode( - const std::shared_ptr &processingBuffer, + std::shared_ptr processNode( + const std::shared_ptr &processingBuffer, int framesToProcess) override; private: diff --git a/packages/react-native-audio-api/common/cpp/audioapi/core/inputs/AudioRecorder.cpp b/packages/react-native-audio-api/common/cpp/audioapi/core/inputs/AudioRecorder.cpp index b080d0596..c53516062 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/core/inputs/AudioRecorder.cpp +++ b/packages/react-native-audio-api/common/cpp/audioapi/core/inputs/AudioRecorder.cpp @@ -1,4 +1,3 @@ - #include #include #include diff --git a/packages/react-native-audio-api/common/cpp/audioapi/core/inputs/AudioRecorder.h b/packages/react-native-audio-api/common/cpp/audioapi/core/inputs/AudioRecorder.h index f532b988e..1a384b8b2 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/core/inputs/AudioRecorder.h +++ b/packages/react-native-audio-api/common/cpp/audioapi/core/inputs/AudioRecorder.h @@ -11,7 +11,6 @@ namespace audioapi { class AudioFileWriter; -class CircularAudioArray; class RecorderAdapterNode; class AudioFileProperties; class AudioRecorderCallback; diff --git a/packages/react-native-audio-api/common/cpp/audioapi/core/sources/AudioBufferBaseSourceNode.cpp b/packages/react-native-audio-api/common/cpp/audioapi/core/sources/AudioBufferBaseSourceNode.cpp index 150a023de..3da3480d4 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/core/sources/AudioBufferBaseSourceNode.cpp +++ b/packages/react-native-audio-api/common/cpp/audioapi/core/sources/AudioBufferBaseSourceNode.cpp @@ -17,8 +17,8 @@ AudioBufferBaseSourceNode::AudioBufferBaseSourceNode( const BaseAudioBufferSourceOptions &options) : AudioScheduledSourceNode(context, options), pitchCorrection_(options.pitchCorrection), - playbackRateBuffer_( - std::make_shared( + playbackRateBuffer_( // TODO refactor init + std::make_shared( RENDER_QUANTUM_SIZE * 3, channelCount_, context->getSampleRate())), @@ -81,7 +81,7 @@ void AudioBufferBaseSourceNode::sendOnPositionChangedEvent() { } void AudioBufferBaseSourceNode::processWithPitchCorrection( - const std::shared_ptr &processingBuffer, + const std::shared_ptr &processingBuffer, int framesToProcess) { size_t startOffset = 0; size_t offsetLength = 0; @@ -130,7 +130,7 @@ void AudioBufferBaseSourceNode::processWithPitchCorrection( } void AudioBufferBaseSourceNode::processWithoutPitchCorrection( - const std::shared_ptr &processingBuffer, + const std::shared_ptr &processingBuffer, int framesToProcess) { size_t startOffset = 0; size_t offsetLength = 0; diff --git a/packages/react-native-audio-api/common/cpp/audioapi/core/sources/AudioBufferBaseSourceNode.h b/packages/react-native-audio-api/common/cpp/audioapi/core/sources/AudioBufferBaseSourceNode.h index 9d11a26fb..2898750a4 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/core/sources/AudioBufferBaseSourceNode.h +++ b/packages/react-native-audio-api/common/cpp/audioapi/core/sources/AudioBufferBaseSourceNode.h @@ -40,7 +40,7 @@ class AudioBufferBaseSourceNode : public AudioScheduledSourceNode { // pitch correction std::shared_ptr> stretch_; - std::shared_ptr playbackRateBuffer_; + std::shared_ptr playbackRateBuffer_; // k-rate params const std::shared_ptr detuneParam_; @@ -58,22 +58,22 @@ class AudioBufferBaseSourceNode : public AudioScheduledSourceNode { void sendOnPositionChangedEvent(); void processWithPitchCorrection( - const std::shared_ptr &processingBuffer, + const std::shared_ptr &processingBuffer, int framesToProcess); void processWithoutPitchCorrection( - const std::shared_ptr &processingBuffer, + const std::shared_ptr &processingBuffer, int framesToProcess); float getComputedPlaybackRateValue(int framesToProcess, double time); virtual void processWithoutInterpolation( - const std::shared_ptr &processingBuffer, + const std::shared_ptr &processingBuffer, size_t startOffset, size_t offsetLength, float playbackRate) = 0; virtual void processWithInterpolation( - const std::shared_ptr &processingBuffer, + const std::shared_ptr &processingBuffer, size_t startOffset, size_t offsetLength, float playbackRate) = 0; diff --git a/packages/react-native-audio-api/common/cpp/audioapi/core/sources/AudioBufferQueueSourceNode.cpp b/packages/react-native-audio-api/common/cpp/audioapi/core/sources/AudioBufferQueueSourceNode.cpp index 1e4a6ae31..05abf41c5 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/core/sources/AudioBufferQueueSourceNode.cpp +++ b/packages/react-native-audio-api/common/cpp/audioapi/core/sources/AudioBufferQueueSourceNode.cpp @@ -132,8 +132,8 @@ void AudioBufferQueueSourceNode::unregisterOnBufferEndedCallback(uint64_t callba audioEventHandlerRegistry_->unregisterHandler(AudioEvent::BUFFER_ENDED, callbackId); } -std::shared_ptr AudioBufferQueueSourceNode::processNode( - const std::shared_ptr &processingBuffer, +std::shared_ptr AudioBufferQueueSourceNode::processNode( + const std::shared_ptr &processingBuffer, int framesToProcess) { // no audio data to fill, zero the output and return. if (buffers_.empty()) { @@ -172,7 +172,7 @@ void AudioBufferQueueSourceNode::sendOnBufferEndedEvent(size_t bufferId, bool is */ void AudioBufferQueueSourceNode::processWithoutInterpolation( - const std::shared_ptr &processingBuffer, + const std::shared_ptr &processingBuffer, size_t startOffset, size_t offsetLength, float playbackRate) { @@ -237,7 +237,7 @@ void AudioBufferQueueSourceNode::processWithoutInterpolation( } void AudioBufferQueueSourceNode::processWithInterpolation( - const std::shared_ptr &processingBuffer, + const std::shared_ptr &processingBuffer, size_t startOffset, size_t offsetLength, float playbackRate) { diff --git a/packages/react-native-audio-api/common/cpp/audioapi/core/sources/AudioBufferQueueSourceNode.h b/packages/react-native-audio-api/common/cpp/audioapi/core/sources/AudioBufferQueueSourceNode.h index f9e992690..be0ade515 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/core/sources/AudioBufferQueueSourceNode.h +++ b/packages/react-native-audio-api/common/cpp/audioapi/core/sources/AudioBufferQueueSourceNode.h @@ -48,8 +48,8 @@ class AudioBufferQueueSourceNode : public AudioBufferBaseSourceNode { void unregisterOnBufferEndedCallback(uint64_t callbackId); protected: - std::shared_ptr processNode( - const std::shared_ptr &processingBuffer, + std::shared_ptr processNode( + const std::shared_ptr &processingBuffer, int framesToProcess) override; double getCurrentPosition() const override; @@ -69,13 +69,13 @@ class AudioBufferQueueSourceNode : public AudioBufferBaseSourceNode { uint64_t onBufferEndedCallbackId_ = 0; // 0 means no callback void processWithoutInterpolation( - const std::shared_ptr &processingBuffer, + const std::shared_ptr &processingBuffer, size_t startOffset, size_t offsetLength, float playbackRate) override; void processWithInterpolation( - const std::shared_ptr &processingBuffer, + const std::shared_ptr &processingBuffer, size_t startOffset, size_t offsetLength, float playbackRate) override; diff --git a/packages/react-native-audio-api/common/cpp/audioapi/core/sources/AudioBufferSourceNode.cpp b/packages/react-native-audio-api/common/cpp/audioapi/core/sources/AudioBufferSourceNode.cpp index 1d36d9aae..e5bf7ec4a 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/core/sources/AudioBufferSourceNode.cpp +++ b/packages/react-native-audio-api/common/cpp/audioapi/core/sources/AudioBufferSourceNode.cpp @@ -47,8 +47,8 @@ void AudioBufferSourceNode::setLoopEnd(double loopEnd) { void AudioBufferSourceNode::setBuffer( const std::shared_ptr &buffer, - const std::shared_ptr &playbackRateBuffer, - const std::shared_ptr &audioBuffer) { + const std::shared_ptr &playbackRateBuffer, + const std::shared_ptr &audioBuffer) { std::shared_ptr context = context_.lock(); if (context == nullptr) { @@ -61,11 +61,7 @@ void AudioBufferSourceNode::setBuffer( graphManager->addAudioBufferForDestruction(std::move(buffer_)); } - if (playbackRateBuffer_ != nullptr) { - graphManager->addAudioBufferForDestruction(std::move(playbackRateBuffer_)); - } - - graphManager->addAudioBufferForDestruction(std::move(audioBuffer_)); + // TODO move DSPAudioBuffers destruction to graph manager as well if (buffer == nullptr) { loopEnd_ = 0; @@ -115,8 +111,8 @@ void AudioBufferSourceNode::unregisterOnLoopEndedCallback(uint64_t callbackId) { audioEventHandlerRegistry_->unregisterHandler(AudioEvent::LOOP_ENDED, callbackId); } -std::shared_ptr AudioBufferSourceNode::processNode( - const std::shared_ptr &processingBuffer, +std::shared_ptr AudioBufferSourceNode::processNode( + const std::shared_ptr &processingBuffer, int framesToProcess) { // No audio data to fill, zero the output and return. if (buffer_ == nullptr) { @@ -151,7 +147,7 @@ void AudioBufferSourceNode::sendOnLoopEndedEvent() { */ void AudioBufferSourceNode::processWithoutInterpolation( - const std::shared_ptr &processingBuffer, + const std::shared_ptr &processingBuffer, size_t startOffset, size_t offsetLength, float playbackRate) { @@ -218,7 +214,7 @@ void AudioBufferSourceNode::processWithoutInterpolation( } void AudioBufferSourceNode::processWithInterpolation( - const std::shared_ptr &processingBuffer, + const std::shared_ptr &processingBuffer, size_t startOffset, size_t offsetLength, float playbackRate) { diff --git a/packages/react-native-audio-api/common/cpp/audioapi/core/sources/AudioBufferSourceNode.h b/packages/react-native-audio-api/common/cpp/audioapi/core/sources/AudioBufferSourceNode.h index 2d8a1e385..29f775e1e 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/core/sources/AudioBufferSourceNode.h +++ b/packages/react-native-audio-api/common/cpp/audioapi/core/sources/AudioBufferSourceNode.h @@ -33,8 +33,8 @@ class AudioBufferSourceNode : public AudioBufferBaseSourceNode { /// @note Audio Thread only void setBuffer( const std::shared_ptr &buffer, - const std::shared_ptr &playbackRateBuffer, - const std::shared_ptr &audioBuffer); + const std::shared_ptr &playbackRateBuffer, + const std::shared_ptr &audioBuffer); using AudioScheduledSourceNode::start; /// @note Audio Thread only @@ -49,8 +49,8 @@ class AudioBufferSourceNode : public AudioBufferBaseSourceNode { void unregisterOnLoopEndedCallback(uint64_t callbackId); protected: - std::shared_ptr processNode( - const std::shared_ptr &processingBuffer, + std::shared_ptr processNode( + const std::shared_ptr &processingBuffer, int framesToProcess) override; double getCurrentPosition() const override; @@ -68,13 +68,13 @@ class AudioBufferSourceNode : public AudioBufferBaseSourceNode { void sendOnLoopEndedEvent(); void processWithoutInterpolation( - const std::shared_ptr &processingBuffer, + const std::shared_ptr &processingBuffer, size_t startOffset, size_t offsetLength, float playbackRate) override; void processWithInterpolation( - const std::shared_ptr &processingBuffer, + const std::shared_ptr &processingBuffer, size_t startOffset, size_t offsetLength, float playbackRate) override; diff --git a/packages/react-native-audio-api/common/cpp/audioapi/core/sources/AudioScheduledSourceNode.cpp b/packages/react-native-audio-api/common/cpp/audioapi/core/sources/AudioScheduledSourceNode.cpp index 1d7fe8f5c..b98c5375f 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/core/sources/AudioScheduledSourceNode.cpp +++ b/packages/react-native-audio-api/common/cpp/audioapi/core/sources/AudioScheduledSourceNode.cpp @@ -70,7 +70,7 @@ void AudioScheduledSourceNode::unregisterOnEndedCallback(uint64_t callbackId) { } void AudioScheduledSourceNode::updatePlaybackInfo( - const std::shared_ptr &processingBuffer, + const std::shared_ptr &processingBuffer, int framesToProcess, size_t &startOffset, size_t &nonSilentFramesToProcess, diff --git a/packages/react-native-audio-api/common/cpp/audioapi/core/sources/AudioScheduledSourceNode.h b/packages/react-native-audio-api/common/cpp/audioapi/core/sources/AudioScheduledSourceNode.h index d4129dcd7..fdabaf152 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/core/sources/AudioScheduledSourceNode.h +++ b/packages/react-native-audio-api/common/cpp/audioapi/core/sources/AudioScheduledSourceNode.h @@ -58,7 +58,7 @@ class AudioScheduledSourceNode : public AudioNode { const std::shared_ptr audioEventHandlerRegistry_; void updatePlaybackInfo( - const std::shared_ptr &processingBuffer, + const std::shared_ptr &processingBuffer, int framesToProcess, size_t &startOffset, size_t &nonSilentFramesToProcess, diff --git a/packages/react-native-audio-api/common/cpp/audioapi/core/sources/ConstantSourceNode.cpp b/packages/react-native-audio-api/common/cpp/audioapi/core/sources/ConstantSourceNode.cpp index 789056b78..a31ee464a 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/core/sources/ConstantSourceNode.cpp +++ b/packages/react-native-audio-api/common/cpp/audioapi/core/sources/ConstantSourceNode.cpp @@ -24,8 +24,8 @@ std::shared_ptr ConstantSourceNode::getOffsetParam() const { return offsetParam_; } -std::shared_ptr ConstantSourceNode::processNode( - const std::shared_ptr &processingBuffer, +std::shared_ptr ConstantSourceNode::processNode( + const std::shared_ptr &processingBuffer, int framesToProcess) { size_t startOffset = 0; size_t offsetLength = 0; diff --git a/packages/react-native-audio-api/common/cpp/audioapi/core/sources/ConstantSourceNode.h b/packages/react-native-audio-api/common/cpp/audioapi/core/sources/ConstantSourceNode.h index 8e7684d80..33b50d35c 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/core/sources/ConstantSourceNode.h +++ b/packages/react-native-audio-api/common/cpp/audioapi/core/sources/ConstantSourceNode.h @@ -19,8 +19,8 @@ class ConstantSourceNode : public AudioScheduledSourceNode { [[nodiscard]] std::shared_ptr getOffsetParam() const; protected: - std::shared_ptr processNode( - const std::shared_ptr &processingBuffer, + std::shared_ptr processNode( + const std::shared_ptr &processingBuffer, int framesToProcess) override; private: diff --git a/packages/react-native-audio-api/common/cpp/audioapi/core/sources/OscillatorNode.cpp b/packages/react-native-audio-api/common/cpp/audioapi/core/sources/OscillatorNode.cpp index f537eb411..e0c2dee24 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/core/sources/OscillatorNode.cpp +++ b/packages/react-native-audio-api/common/cpp/audioapi/core/sources/OscillatorNode.cpp @@ -26,8 +26,6 @@ OscillatorNode::OscillatorNode( periodicWave_ = context->getBasicWaveForm(type_); } - audioBuffer_ = std::make_shared(RENDER_QUANTUM_SIZE, 1, context->getSampleRate()); - isInitialized_.store(true, std::memory_order_release); } @@ -51,8 +49,8 @@ void OscillatorNode::setPeriodicWave(const std::shared_ptr &period type_ = OscillatorType::CUSTOM; } -std::shared_ptr OscillatorNode::processNode( - const std::shared_ptr &processingBuffer, +std::shared_ptr OscillatorNode::processNode( + const std::shared_ptr &processingBuffer, int framesToProcess) { size_t startOffset = 0; size_t offsetLength = 0; diff --git a/packages/react-native-audio-api/common/cpp/audioapi/core/sources/OscillatorNode.h b/packages/react-native-audio-api/common/cpp/audioapi/core/sources/OscillatorNode.h index a3018fda1..73d41c25e 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/core/sources/OscillatorNode.h +++ b/packages/react-native-audio-api/common/cpp/audioapi/core/sources/OscillatorNode.h @@ -27,8 +27,8 @@ class OscillatorNode : public AudioScheduledSourceNode { void setPeriodicWave(const std::shared_ptr &periodicWave); protected: - std::shared_ptr processNode( - const std::shared_ptr &processingBuffer, + std::shared_ptr processNode( + const std::shared_ptr &processingBuffer, int framesToProcess) override; private: diff --git a/packages/react-native-audio-api/common/cpp/audioapi/core/sources/RecorderAdapterNode.cpp b/packages/react-native-audio-api/common/cpp/audioapi/core/sources/RecorderAdapterNode.cpp index cb9145ae6..7b99755e8 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/core/sources/RecorderAdapterNode.cpp +++ b/packages/react-native-audio-api/common/cpp/audioapi/core/sources/RecorderAdapterNode.cpp @@ -67,8 +67,8 @@ void RecorderAdapterNode::cleanup() { isInitialized_.store(false, std::memory_order_release); } -std::shared_ptr RecorderAdapterNode::processNode( - const std::shared_ptr &processingBuffer, +std::shared_ptr RecorderAdapterNode::processNode( + const std::shared_ptr &processingBuffer, int framesToProcess) { if (!isInitialized_.load(std::memory_order_acquire)) { processingBuffer->zero(); diff --git a/packages/react-native-audio-api/common/cpp/audioapi/core/sources/RecorderAdapterNode.h b/packages/react-native-audio-api/common/cpp/audioapi/core/sources/RecorderAdapterNode.h index 330112391..7b58de462 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/core/sources/RecorderAdapterNode.h +++ b/packages/react-native-audio-api/common/cpp/audioapi/core/sources/RecorderAdapterNode.h @@ -4,7 +4,7 @@ #include #include #include -#include +#include #include #include #include @@ -33,8 +33,8 @@ class RecorderAdapterNode : public AudioNode { std::vector> buff_; protected: - std::shared_ptr processNode( - const std::shared_ptr &processingBuffer, + std::shared_ptr processNode( + const std::shared_ptr &processingBuffer, int framesToProcess) override; std::shared_ptr adapterOutputBuffer_; diff --git a/packages/react-native-audio-api/common/cpp/audioapi/core/sources/StreamerNode.cpp b/packages/react-native-audio-api/common/cpp/audioapi/core/sources/StreamerNode.cpp index c07dabc9e..197cc92a4 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/core/sources/StreamerNode.cpp +++ b/packages/react-native-audio-api/common/cpp/audioapi/core/sources/StreamerNode.cpp @@ -56,8 +56,8 @@ StreamerNode::~StreamerNode() { #endif // RN_AUDIO_API_FFMPEG_DISABLED } -std::shared_ptr StreamerNode::processNode( - const std::shared_ptr &processingBuffer, +std::shared_ptr StreamerNode::processNode( + const std::shared_ptr &processingBuffer, int framesToProcess) { #if !RN_AUDIO_API_FFMPEG_DISABLED size_t startOffset = 0; @@ -144,8 +144,8 @@ bool StreamerNode::initialize(const std::string &input_url) { } channelCount_ = codecpar_->ch_layout.nb_channels; - audioBuffer_ = - std::make_shared(RENDER_QUANTUM_SIZE, channelCount_, context->getSampleRate()); + audioBuffer_ = std::make_shared( + RENDER_QUANTUM_SIZE, channelCount_, context->getSampleRate()); auto [sender, receiver] = channels::spsc::channel< StreamingData, diff --git a/packages/react-native-audio-api/common/cpp/audioapi/core/sources/StreamerNode.h b/packages/react-native-audio-api/common/cpp/audioapi/core/sources/StreamerNode.h index 8c9c2363c..70ae44973 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/core/sources/StreamerNode.h +++ b/packages/react-native-audio-api/common/cpp/audioapi/core/sources/StreamerNode.h @@ -24,7 +24,7 @@ extern "C" { } #endif // RN_AUDIO_API_FFMPEG_DISABLED -#include +#include #include #include #include @@ -68,8 +68,8 @@ class StreamerNode : public AudioScheduledSourceNode { ~StreamerNode() override; protected: - std::shared_ptr processNode( - const std::shared_ptr &processingBuffer, + std::shared_ptr processNode( + const std::shared_ptr &processingBuffer, int framesToProcess) override; private: diff --git a/packages/react-native-audio-api/common/cpp/audioapi/core/sources/WorkletSourceNode.cpp b/packages/react-native-audio-api/common/cpp/audioapi/core/sources/WorkletSourceNode.cpp index bfaf57555..7f700c74a 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/core/sources/WorkletSourceNode.cpp +++ b/packages/react-native-audio-api/common/cpp/audioapi/core/sources/WorkletSourceNode.cpp @@ -19,8 +19,8 @@ WorkletSourceNode::WorkletSourceNode( isInitialized_.store(true, std::memory_order_release); } -std::shared_ptr WorkletSourceNode::processNode( - const std::shared_ptr &processingBuffer, +std::shared_ptr WorkletSourceNode::processNode( + const std::shared_ptr &processingBuffer, int framesToProcess) { if (isUnscheduled() || isFinished() || !isEnabled()) { processingBuffer->zero(); diff --git a/packages/react-native-audio-api/common/cpp/audioapi/core/sources/WorkletSourceNode.h b/packages/react-native-audio-api/common/cpp/audioapi/core/sources/WorkletSourceNode.h index 23d4b8660..39ba4d00b 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/core/sources/WorkletSourceNode.h +++ b/packages/react-native-audio-api/common/cpp/audioapi/core/sources/WorkletSourceNode.h @@ -22,8 +22,8 @@ class WorkletSourceNode : public AudioScheduledSourceNode { : AudioScheduledSourceNode(context) {} protected: - std::shared_ptr processNode( - const std::shared_ptr &processingBuffer, + std::shared_ptr processNode( + const std::shared_ptr &processingBuffer, int framesToProcess) override { return processingBuffer; } @@ -37,8 +37,8 @@ class WorkletSourceNode : public AudioScheduledSourceNode { WorkletsRunner &&workletRunner); protected: - std::shared_ptr processNode( - const std::shared_ptr &processingBuffer, + std::shared_ptr processNode( + const std::shared_ptr &processingBuffer, int framesToProcess) override; private: diff --git a/packages/react-native-audio-api/common/cpp/audioapi/core/utils/AudioRecorderCallback.cpp b/packages/react-native-audio-api/common/cpp/audioapi/core/utils/AudioRecorderCallback.cpp index 87b49f7b5..44e303300 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/core/utils/AudioRecorderCallback.cpp +++ b/packages/react-native-audio-api/common/cpp/audioapi/core/utils/AudioRecorderCallback.cpp @@ -3,7 +3,7 @@ #include #include -#include +#include #include #include diff --git a/packages/react-native-audio-api/common/cpp/audioapi/core/utils/AudioRecorderCallback.h b/packages/react-native-audio-api/common/cpp/audioapi/core/utils/AudioRecorderCallback.h index ffcb243f9..9ea18d306 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/core/utils/AudioRecorderCallback.h +++ b/packages/react-native-audio-api/common/cpp/audioapi/core/utils/AudioRecorderCallback.h @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -12,7 +13,6 @@ namespace audioapi { -class CircularAudioArray; class AudioEventHandlerRegistry; class AudioRecorderCallback { diff --git a/packages/react-native-audio-api/common/cpp/audioapi/dsp/Convolver.cpp b/packages/react-native-audio-api/common/cpp/audioapi/dsp/Convolver.cpp index 275ff2805..74cb7b786 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/dsp/Convolver.cpp +++ b/packages/react-native-audio-api/common/cpp/audioapi/dsp/Convolver.cpp @@ -44,7 +44,7 @@ void Convolver::reset() { } } -bool Convolver::init(size_t blockSize, const audioapi::AudioArray &ir, size_t irLen) { +bool Convolver::init(size_t blockSize, const AudioArray &ir, size_t irLen) { reset(); // blockSize must be a power of two if ((blockSize & (blockSize - 1))) { @@ -72,7 +72,7 @@ bool Convolver::init(size_t blockSize, const audioapi::AudioArray &ir, size_t ir // complex-conjugate symmetricity _fftComplexSize = _segSize / 2 + 1; _fft = std::make_shared(static_cast(_segSize)); - _fftBuffer = std::make_unique(_segSize); + _fftBuffer = std::make_unique(_segSize); // segments preparation for (int i = 0; i < _segCount; ++i) { @@ -98,7 +98,7 @@ bool Convolver::init(size_t blockSize, const audioapi::AudioArray &ir, size_t ir } _preMultiplied = aligned_vec_complex(_fftComplexSize); - _inputBuffer = std::make_unique(_segSize); + _inputBuffer = std::make_unique(_segSize); _current = 0; return true; @@ -166,7 +166,7 @@ void pairwise_complex_multiply_fast( #endif } -void Convolver::process(const AudioArray &input, AudioArray &output) { +void Convolver::process(const DSPAudioArray &input, DSPAudioArray &output) { // The input buffer acts as a 2B-point sliding window of the input signal. // With each new input block, the right half of the input buffer is shifted // to the left and the new block is stored in the right half. diff --git a/packages/react-native-audio-api/common/cpp/audioapi/dsp/Convolver.h b/packages/react-native-audio-api/common/cpp/audioapi/dsp/Convolver.h index dfc9d6044..2796c729a 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/dsp/Convolver.h +++ b/packages/react-native-audio-api/common/cpp/audioapi/dsp/Convolver.h @@ -18,7 +18,7 @@ class Convolver { public: Convolver(); bool init(size_t blockSize, const AudioArray &ir, size_t irLen); - void process(const AudioArray &input, AudioArray &output); + void process(const DSPAudioArray &input, DSPAudioArray &output); void reset(); [[nodiscard]] inline size_t getSegCount() const { return _trueSegmentCount; @@ -32,11 +32,11 @@ class Convolver { size_t _fftComplexSize; std::vector _segments; std::vector _segmentsIR; - std::unique_ptr _fftBuffer; + std::unique_ptr _fftBuffer; std::shared_ptr _fft; aligned_vec_complex _preMultiplied; size_t _current; - std::unique_ptr _inputBuffer; + std::unique_ptr _inputBuffer; friend void pairwise_complex_multiply_fast( const aligned_vec_complex &ir, diff --git a/packages/react-native-audio-api/common/cpp/audioapi/dsp/FFT.h b/packages/react-native-audio-api/common/cpp/audioapi/dsp/FFT.h index 0a9290b10..ccb390e59 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/dsp/FFT.h +++ b/packages/react-native-audio-api/common/cpp/audioapi/dsp/FFT.h @@ -14,8 +14,10 @@ class FFT { explicit FFT(int size); ~FFT(); - template - void doFFT(const AudioArray &in, std::vector, Allocator> &out) { + template + void doFFT( + const AlignedAudioArray &in, + std::vector, Allocator> &out) { pffft_transform_ordered( pffftSetup_, in.begin(), reinterpret_cast(&out[0]), work_, PFFFT_FORWARD); // this is a possible place for bugs and mistakes @@ -25,8 +27,10 @@ class FFT { // out[0].imag = Nyquist component - should be pure real } - template - void doInverseFFT(std::vector, Allocator> &in, AudioArray &out) { + template + void doInverseFFT( + std::vector, Allocator> &in, + AlignedAudioArray &out) { pffft_transform_ordered( pffftSetup_, reinterpret_cast(&in[0]), out.begin(), work_, PFFFT_BACKWARD); diff --git a/packages/react-native-audio-api/common/cpp/audioapi/dsp/WaveShaper.cpp b/packages/react-native-audio-api/common/cpp/audioapi/dsp/WaveShaper.cpp index 63e7e0001..7432b89f0 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/dsp/WaveShaper.cpp +++ b/packages/react-native-audio-api/common/cpp/audioapi/dsp/WaveShaper.cpp @@ -1,7 +1,6 @@ #include #include #include -#include #include #include @@ -10,9 +9,9 @@ namespace audioapi { WaveShaper::WaveShaper(const std::shared_ptr &curve, float sampleRate) : curve_(curve), sampleRate_(sampleRate) { - tempBuffer2x_ = std::make_shared(RENDER_QUANTUM_SIZE * 2); + tempBuffer2x_ = std::make_shared(RENDER_QUANTUM_SIZE * 2); tempBuffer2x_->zero(); - tempBuffer4x_ = std::make_shared(RENDER_QUANTUM_SIZE * 4); + tempBuffer4x_ = std::make_shared(RENDER_QUANTUM_SIZE * 4); tempBuffer4x_->zero(); createResamplers(OverSampleType::OVERSAMPLE_NONE); @@ -41,7 +40,7 @@ void WaveShaper::setOversample(OverSampleType type) { createResamplers(type); } -void WaveShaper::process(AudioArray &channelData, int framesToProcess) { +void WaveShaper::process(DSPAudioArray &channelData, int framesToProcess) { if (curve_ == nullptr) { return; } @@ -61,7 +60,7 @@ void WaveShaper::process(AudioArray &channelData, int framesToProcess) { } // based on https://webaudio.github.io/web-audio-api/#WaveShaperNode -void WaveShaper::processNone(AudioArray &channelData, int framesToProcess) { +void WaveShaper::processNone(DSPAudioArray &channelData, int framesToProcess) { auto curveSize = curve_->getSize(); for (int i = 0; i < framesToProcess; i++) { @@ -80,9 +79,8 @@ void WaveShaper::processNone(AudioArray &channelData, int framesToProcess) { } } -void WaveShaper::processResampled(AudioArray &channelData, int framesToProcess) { - AudioArray &outArray = - (oversample_ == OverSampleType::OVERSAMPLE_4X) ? *tempBuffer4x_ : *tempBuffer2x_; +void WaveShaper::processResampled(DSPAudioArray &channelData, int framesToProcess) { + auto &outArray = (oversample_ == OverSampleType::OVERSAMPLE_4X) ? *tempBuffer4x_ : *tempBuffer2x_; const int outputFrames = upSampler_->process(channelData, framesToProcess, outArray); processNone(outArray, outputFrames); downSampler_->process(outArray, outputFrames, channelData); diff --git a/packages/react-native-audio-api/common/cpp/audioapi/dsp/WaveShaper.h b/packages/react-native-audio-api/common/cpp/audioapi/dsp/WaveShaper.h index af36e47ef..0fbef91be 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/dsp/WaveShaper.h +++ b/packages/react-native-audio-api/common/cpp/audioapi/dsp/WaveShaper.h @@ -1,7 +1,7 @@ #pragma once #include -#include +#include #include #include @@ -13,7 +13,7 @@ class WaveShaper { public: explicit WaveShaper(const std::shared_ptr &curve, float sampleRate); - void process(AudioArray &channelData, int framesToProcess); + void process(DSPAudioArray &channelData, int framesToProcess); void setCurve(const std::shared_ptr &curve); void setOversample(OverSampleType type); @@ -26,12 +26,12 @@ class WaveShaper { std::unique_ptr upSampler_; std::unique_ptr downSampler_; - std::shared_ptr tempBuffer2x_; - std::shared_ptr tempBuffer4x_; + std::shared_ptr tempBuffer2x_; + std::shared_ptr tempBuffer4x_; void createResamplers(OverSampleType type); - void processNone(AudioArray &channelData, int framesToProcess); - void processResampled(AudioArray &channelData, int framesToProcess); + void processNone(DSPAudioArray &channelData, int framesToProcess); + void processResampled(DSPAudioArray &channelData, int framesToProcess); }; } // namespace audioapi diff --git a/packages/react-native-audio-api/common/cpp/audioapi/dsp/r8brain/Resampler.cpp b/packages/react-native-audio-api/common/cpp/audioapi/dsp/r8brain/Resampler.cpp deleted file mode 100644 index 5dfb7609e..000000000 --- a/packages/react-native-audio-api/common/cpp/audioapi/dsp/r8brain/Resampler.cpp +++ /dev/null @@ -1,85 +0,0 @@ -#include - -namespace r8b { - -BaseResampler::BaseResampler(double srcRate, double dstRate, int numChannels, int maxInLen) { - resamplers_.reserve(static_cast(numChannels)); - inputBuffers_.reserve(static_cast(numChannels)); - for (int i = 0; i < numChannels; ++i) { - resamplers_.emplace_back(std::make_unique(srcRate, dstRate, maxInLen)); - inputBuffers_.emplace_back(static_cast(maxInLen)); - } -} - -int BaseResampler::process(const std::vector &input, int l, std::vector &output) { - int outLen = 0; - const size_t numChannels = resamplers_.size(); - - for (size_t i = 0; i < numChannels; ++i) { - const float *__restrict inData = input[i]; - double *__restrict bufData = inputBuffers_[i].data(); - - for (int j = 0; j < l; ++j) { - bufData[j] = static_cast(inData[j]); - } - - double *outPtr = nullptr; - const int currentOutLen = resamplers_[i]->process(bufData, l, outPtr); - outLen = currentOutLen; - - if (currentOutLen > 0 && outPtr != nullptr) { - const double *__restrict resampledData = outPtr; - float *__restrict outData = output[i]; - - for (int j = 0; j < currentOutLen; ++j) { - outData[j] = static_cast(resampledData[j]); - } - } - } - - return outLen; -} - -int BaseResampler::getMaxOutLen() const { - if (resamplers_.empty()) { - return 0; - } - return resamplers_[0]->getMaxOutLen(0); -} - -MultiChannelResampler::MultiChannelResampler( - double srcRate, - double dstRate, - int numChannels, - int maxInLen) - : BaseResampler(srcRate, dstRate, numChannels, maxInLen) {} - -int MultiChannelResampler::process( - const audioapi::AudioBuffer &input, - int l, - audioapi::AudioBuffer &output) { - const size_t numChannels = input.getNumberOfChannels(); - std::vector inputPtrs(numChannels); - std::vector outputPtrs(numChannels); - for (size_t i = 0; i < numChannels; ++i) { - inputPtrs[i] = input.getChannel(i)->begin(); - outputPtrs[i] = output.getChannel(i)->begin(); - } - return BaseResampler::process(inputPtrs, l, outputPtrs); -} - -SingleChannelResampler::SingleChannelResampler(double srcRate, double dstRate, int maxInLen) - : BaseResampler(srcRate, dstRate, 1, maxInLen) {} - -int SingleChannelResampler::process( - const audioapi::AudioArray &input, - int l, - audioapi::AudioArray &output) { - std::vector inputPtrs(1); - std::vector outputPtrs(1); - inputPtrs[0] = const_cast(input.begin()); - outputPtrs[0] = output.begin(); - return BaseResampler::process(inputPtrs, l, outputPtrs); -} - -} // namespace r8b diff --git a/packages/react-native-audio-api/common/cpp/audioapi/dsp/r8brain/Resampler.h b/packages/react-native-audio-api/common/cpp/audioapi/dsp/r8brain/Resampler.h deleted file mode 100644 index 539251f80..000000000 --- a/packages/react-native-audio-api/common/cpp/audioapi/dsp/r8brain/Resampler.h +++ /dev/null @@ -1,47 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include - -// Sample rate converter designed by Aleksey Vaneev of Voxengo on MIT license -#include "CDSPResampler.h" - -namespace r8b { - -class BaseResampler { - BaseResampler(const BaseResampler &) = delete; - BaseResampler &operator=(const BaseResampler &) = delete; - BaseResampler(BaseResampler &&) noexcept = default; - BaseResampler &operator=(BaseResampler &&) noexcept = default; - - private: - std::vector> resamplers_; - std::vector> inputBuffers_; - - protected: - BaseResampler(double srcRate, double dstRate, int numChannels, int maxInLen = 2048); - int process(const std::vector &input, int length, std::vector &output); - - public: - virtual ~BaseResampler() = default; - /** @return Maximum number of output samples per channel for one process() call (for the maxInLen passed to the constructor). */ - int getMaxOutLen() const; -}; - -class MultiChannelResampler : public BaseResampler { - public: - MultiChannelResampler(double srcRate, double dstRate, int numChannels, int maxInLen = 2048); - ~MultiChannelResampler() = default; - int process(const audioapi::AudioBuffer &input, int length, audioapi::AudioBuffer &output); -}; - -class SingleChannelResampler : public BaseResampler { - public: - SingleChannelResampler(double srcRate, double dstRate, int maxInLen = 2048); - ~SingleChannelResampler() = default; - int process(const audioapi::AudioArray &input, int length, audioapi::AudioArray &output); -}; -} // namespace r8b diff --git a/packages/react-native-audio-api/common/cpp/audioapi/dsp/r8brain/Resampler.hpp b/packages/react-native-audio-api/common/cpp/audioapi/dsp/r8brain/Resampler.hpp new file mode 100644 index 000000000..61e94a8ba --- /dev/null +++ b/packages/react-native-audio-api/common/cpp/audioapi/dsp/r8brain/Resampler.hpp @@ -0,0 +1,118 @@ +#pragma once + +#include +#include +#include +#include +#include + +// Sample rate converter designed by Aleksey Vaneev of Voxengo on MIT license +#include "CDSPResampler.h" + +namespace r8b { + +class BaseResampler { + BaseResampler(const BaseResampler &) = delete; + BaseResampler &operator=(const BaseResampler &) = delete; + BaseResampler(BaseResampler &&) noexcept = default; + BaseResampler &operator=(BaseResampler &&) noexcept = default; + + private: + std::vector> resamplers_; + std::vector> inputBuffers_; + + protected: + inline BaseResampler(double srcRate, double dstRate, int numChannels, int maxInLen = 2048) { + resamplers_.reserve(static_cast(numChannels)); + inputBuffers_.reserve(static_cast(numChannels)); + for (int i = 0; i < numChannels; ++i) { + resamplers_.emplace_back(std::make_unique(srcRate, dstRate, maxInLen)); + inputBuffers_.emplace_back(static_cast(maxInLen)); + } + } + + inline int process(const std::vector &input, int l, std::vector &output) { + int outLen = 0; + const size_t numChannels = resamplers_.size(); + + for (size_t i = 0; i < numChannels; ++i) { + const float *__restrict inData = input[i]; + double *__restrict bufData = inputBuffers_[i].data(); + + for (int j = 0; j < l; ++j) { + bufData[j] = static_cast(inData[j]); + } + + double *outPtr = nullptr; + const int currentOutLen = resamplers_[i]->process(bufData, l, outPtr); + outLen = currentOutLen; + + if (currentOutLen > 0 && outPtr != nullptr) { + const double *__restrict resampledData = outPtr; + float *__restrict outData = output[i]; + + for (int j = 0; j < currentOutLen; ++j) { + outData[j] = static_cast(resampledData[j]); + } + } + } + + return outLen; + } + + public: + virtual ~BaseResampler() = default; + + /** @return Maximum number of output samples per channel for one process() call (for the maxInLen passed to the constructor). */ + inline int getMaxOutLen() const { + if (resamplers_.empty()) { + return 0; + } + return resamplers_[0]->getMaxOutLen(0); + } +}; + +class MultiChannelResampler : public BaseResampler { + public: + inline MultiChannelResampler(double srcRate, double dstRate, int numChannels, int maxInLen = 2048) + : BaseResampler(srcRate, dstRate, numChannels, maxInLen) {} + + ~MultiChannelResampler() = default; + + template + int process( + const audioapi::AlignedAudioBuffer &input, + int length, + audioapi::AlignedAudioBuffer &output) { + const size_t numChannels = input.getNumberOfChannels(); + std::vector inputPtrs(numChannels); + std::vector outputPtrs(numChannels); + for (size_t i = 0; i < numChannels; ++i) { + inputPtrs[i] = input.getChannel(i)->begin(); + outputPtrs[i] = output.getChannel(i)->begin(); + } + return BaseResampler::process(inputPtrs, length, outputPtrs); + } +}; + +class SingleChannelResampler : public BaseResampler { + public: + inline SingleChannelResampler(double srcRate, double dstRate, int maxInLen = 2048) + : BaseResampler(srcRate, dstRate, 1, maxInLen) {} + + ~SingleChannelResampler() = default; + + template + int process( + const audioapi::AlignedAudioArray &input, + int length, + audioapi::AlignedAudioArray &output) { + std::vector inputPtrs(1); + std::vector outputPtrs(1); + inputPtrs[0] = const_cast(input.begin()); + outputPtrs[0] = output.begin(); + return BaseResampler::process(inputPtrs, length, outputPtrs); + } +}; + +} // namespace r8b diff --git a/packages/react-native-audio-api/common/cpp/audioapi/utils/AudioArray.hpp b/packages/react-native-audio-api/common/cpp/audioapi/utils/AudioArray.hpp index b418d09cc..2e8d59ba6 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/utils/AudioArray.hpp +++ b/packages/react-native-audio-api/common/cpp/audioapi/utils/AudioArray.hpp @@ -263,7 +263,7 @@ class AlignedAudioArray { const AlignedAudioArray &kernel, size_t startIndex = 0) const { if (kernel.size_ > size_ - startIndex) [[unlikely]] { - throw std::out_of_range("Kernal size exceeds available data for convolution."); + throw std::out_of_range("Kernel size exceeds available data for convolution."); } return dsp::computeConvolution(alignedData() + startIndex, kernel.alignedData(), kernel.size_); } diff --git a/packages/react-native-audio-api/common/cpp/audioapi/utils/AudioArrayBuffer.hpp b/packages/react-native-audio-api/common/cpp/audioapi/utils/AudioArrayBuffer.hpp index a2ed748b4..4094d7ae1 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/utils/AudioArrayBuffer.hpp +++ b/packages/react-native-audio-api/common/cpp/audioapi/utils/AudioArrayBuffer.hpp @@ -7,33 +7,27 @@ using JsiBuffer = facebook::jsi::MutableBuffer; #else // Dummy class to inherit from nothing if testing -struct JsiBuffer {}; +struct JsiBuffer { + virtual size_t size() const = 0; + virtual uint8_t *data() = 0; +}; #endif namespace audioapi { -template +template class AlignedAudioArrayBuffer : public JsiBuffer, public AlignedAudioArray { public: explicit AlignedAudioArrayBuffer(size_t size) : AlignedAudioArray(size) {}; AlignedAudioArrayBuffer(const float *data, size_t size) : AlignedAudioArray(data, size) {}; -#if !RN_AUDIO_API_TEST [[nodiscard]] size_t size() const override { return this->size_ * sizeof(float); } uint8_t *data() override { return reinterpret_cast(this->data_.data()); } -#else - [[nodiscard]] size_t size() const { - return this->size_ * sizeof(float); - } - uint8_t *data() { - return reinterpret_cast(this->data_.data()); - } -#endif }; using AudioArrayBuffer = AlignedAudioArrayBuffer; diff --git a/packages/react-native-audio-api/common/cpp/audioapi/utils/AudioBuffer.hpp b/packages/react-native-audio-api/common/cpp/audioapi/utils/AudioBuffer.hpp index 22ac2d889..eb7a5a059 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/utils/AudioBuffer.hpp +++ b/packages/react-native-audio-api/common/cpp/audioapi/utils/AudioBuffer.hpp @@ -18,7 +18,7 @@ namespace audioapi { /// @brief AlignedAudioBuffer is a multi-channel audio buffer backed by AlignedAudioArray channels. /// @tparam Alignment The memory alignment in bytes for the underlying channel arrays. -template +template class AlignedAudioBuffer { public: enum { @@ -31,6 +31,9 @@ class AlignedAudioBuffer { ChannelSurroundRight = 5, }; + template + friend class AlignedAudioBuffer; + explicit AlignedAudioBuffer() = default; explicit AlignedAudioBuffer(size_t size, int numberOfChannels, float sampleRate) @@ -158,20 +161,24 @@ class AlignedAudioBuffer { /// @brief Sums audio data from a source buffer into this buffer. /// @note Handles up-mixing and down-mixing based on channel counts. + template void sum( - const AlignedAudioBuffer &source, + const AlignedAudioBuffer &source, ChannelInterpretation interpretation = ChannelInterpretation::SPEAKERS) { sum(source, 0, 0, getSize(), interpretation); } + template void sum( - const AlignedAudioBuffer &source, + const AlignedAudioBuffer &source, size_t sourceStart, size_t destinationStart, size_t length, ChannelInterpretation interpretation = ChannelInterpretation::SPEAKERS) { - if (&source == this) { - return; + if constexpr (OtherAlignment == Alignment) { + if (&source == this) { + return; + } } auto numberOfSourceChannels = source.getNumberOfChannels(); @@ -199,17 +206,22 @@ class AlignedAudioBuffer { /// @brief Copies audio data from a source buffer into this buffer. /// @note Handles up-mixing and down-mixing based on channel counts. - void copy(const AlignedAudioBuffer &source) { // NOLINT(build/include_what_you_use) + template + void copy( + const AlignedAudioBuffer &source) { // NOLINT(build/include_what_you_use) copy(source, 0, 0, getSize()); } + template void copy( - const AlignedAudioBuffer &source, + const AlignedAudioBuffer &source, size_t sourceStart, size_t destinationStart, size_t length) { // NOLINT(build/include_what_you_use) - if (&source == this) { - return; + if constexpr (OtherAlignment == Alignment) { + if (&source == this) { + return; + } } if (source.getNumberOfChannels() == getNumberOfChannels()) { @@ -333,19 +345,21 @@ class AlignedAudioBuffer { ChannelSurroundLeft, ChannelSurroundRight}}}; + template void discreteSum( - const AlignedAudioBuffer &source, + const AlignedAudioBuffer &source, size_t sourceStart, size_t destinationStart, size_t length) const { auto numberOfChannels = std::min(getNumberOfChannels(), source.getNumberOfChannels()); for (size_t i = 0; i < numberOfChannels; i++) { - channels_[i]->sum(*source.channels_[i], sourceStart, destinationStart, length); + channels_[i]->sum(*source.getChannel(i), sourceStart, destinationStart, length); } } + template void sumByUpMixing( - const AlignedAudioBuffer &source, + const AlignedAudioBuffer &source, size_t sourceStart, size_t destinationStart, size_t length) { @@ -379,8 +393,9 @@ class AlignedAudioBuffer { } } + template void sumByDownMixing( - const AlignedAudioBuffer &source, + const AlignedAudioBuffer &source, size_t sourceStart, size_t destinationStart, size_t length) { diff --git a/packages/react-native-audio-api/common/cpp/audioapi/utils/CircularArray.hpp b/packages/react-native-audio-api/common/cpp/audioapi/utils/CircularArray.hpp new file mode 100644 index 000000000..f6a723a2d --- /dev/null +++ b/packages/react-native-audio-api/common/cpp/audioapi/utils/CircularArray.hpp @@ -0,0 +1,119 @@ +#pragma once + +#include + +namespace audioapi { + +template +concept AudioArrayBase = requires(T a, const float *c_data, float *data, size_t size) { + { a.begin() } -> std::same_as; + { a.getSize() } -> std::same_as; + a.copy(c_data, size, size, size); + a.copyTo(data, size, size, size); +} && std::constructible_from; + +template +class CircularArray : public Base { + public: + explicit CircularArray(size_t size) : Base(size) {} + + CircularArray(const CircularArray &other) = default; + CircularArray(CircularArray &&other) noexcept = default; + CircularArray &operator=(const CircularArray &other) = default; + CircularArray &operator=(CircularArray &&other) noexcept = default; + ~CircularArray() = default; + + void push_back(const Base &data, size_t size, bool skipAvailableSpaceCheck = false) { + push_back(data.begin(), size, skipAvailableSpaceCheck); + } + + void push_back(const float *data, size_t size, bool skipAvailableSpaceCheck = false) { + if (size > this->size_) { + throw std::overflow_error("size exceeds CircularArray size_"); + } + + if (size > getAvailableSpace() && !skipAvailableSpaceCheck) { + throw std::overflow_error("not enough space in CircularArray"); + } + + if (vWriteIndex_ + size > this->size_) { + auto partSize = this->size_ - vWriteIndex_; + this->copy(data, 0, vWriteIndex_, partSize); // NOLINT(build/include_what_you_use) + this->copy(data, partSize, 0, size - partSize); // NOLINT(build/include_what_you_use) + } else { + this->copy(data, 0, vWriteIndex_, size); // NOLINT(build/include_what_you_use) + } + + vWriteIndex_ = + vWriteIndex_ + size > this->size_ ? vWriteIndex_ + size - this->size_ : vWriteIndex_ + size; + } + + void pop_front(Base &data, size_t size, bool skipAvailableDataCheck = false) { + pop_front(data.begin(), size, skipAvailableDataCheck); + } + + void pop_front(float *data, size_t size, bool skipAvailableDataCheck = false) { + if (size > this->size_) { + throw std::overflow_error("size exceeds CircularArray size_"); + } + + if (size > getNumberOfAvailableFrames() && !skipAvailableDataCheck) { + throw std::overflow_error("not enough data in CircularArray"); + } + + if (vReadIndex_ + size > this->size_) { + auto partSize = this->size_ - vReadIndex_; + this->copyTo(data, vReadIndex_, 0, partSize); + this->copyTo(data, 0, partSize, size - partSize); + } else { + this->copyTo(data, vReadIndex_, 0, size); + } + + vReadIndex_ = + vReadIndex_ + size > this->size_ ? vReadIndex_ + size - this->size_ : vReadIndex_ + size; + } + + void pop_back(Base &data, size_t size, size_t offset = 0, bool skipAvailableDataCheck = false) { + pop_back(data.begin(), size, offset, skipAvailableDataCheck); + } + + void pop_back(float *data, size_t size, size_t offset = 0, bool skipAvailableDataCheck = false) { + if (size > this->size_) { + throw std::overflow_error("size exceeds CircularArray size_"); + } + + if (size + offset > getNumberOfAvailableFrames() && !skipAvailableDataCheck) { + throw std::overflow_error("not enough data in CircularArray"); + } + + if (vWriteIndex_ <= offset) { + this->copyTo(data, this->size_ - (offset - vWriteIndex_) - size, 0, size); + } else if (vWriteIndex_ <= size + offset) { + auto partSize = size + offset - vWriteIndex_; + this->copyTo(data, this->size_ - partSize, 0, partSize); + this->copyTo(data, 0, partSize, size - partSize); + } else { + this->copyTo(data, vWriteIndex_ - size - offset, 0, size); + } + + vReadIndex_ = vWriteIndex_ < offset ? size + vWriteIndex_ - offset : vWriteIndex_ - offset; + } + + [[nodiscard]] size_t getNumberOfAvailableFrames() const { + return vWriteIndex_ >= vReadIndex_ ? vWriteIndex_ - vReadIndex_ + : this->size_ - vReadIndex_ + vWriteIndex_; + } + + private: + size_t vWriteIndex_ = 0; + size_t vReadIndex_ = 0; + + [[nodiscard]] size_t getAvailableSpace() const { + return this->size_ - getNumberOfAvailableFrames(); + } +}; + +using CircularAudioArray = CircularArray; +using CircularDSPAudioArray = CircularArray; + +} // namespace audioapi diff --git a/packages/react-native-audio-api/common/cpp/audioapi/utils/CircularAudioArray.cpp b/packages/react-native-audio-api/common/cpp/audioapi/utils/CircularAudioArray.cpp deleted file mode 100644 index ec2bae997..000000000 --- a/packages/react-native-audio-api/common/cpp/audioapi/utils/CircularAudioArray.cpp +++ /dev/null @@ -1,101 +0,0 @@ -#include - -namespace audioapi { - -CircularAudioArray::CircularAudioArray(size_t size) : AudioArray(size) {} - -void CircularAudioArray::push_back( - const AudioArray &data, - size_t size, - bool skipAvailableSpaceCheck) { - push_back(data.begin(), size, skipAvailableSpaceCheck); -} - -void CircularAudioArray::push_back(const float *data, size_t size, bool skipAvailableSpaceCheck) { - if (size > size_) { - throw std::overflow_error("size exceeds CircularAudioArray size_"); - } - - if (size > getAvailableSpace() && !skipAvailableSpaceCheck) { - throw std::overflow_error("not enough space in CircularAudioArray"); - } - - if (vWriteIndex_ + size > size_) { - auto partSize = size_ - vWriteIndex_; - copy(data, 0, vWriteIndex_, partSize); // NOLINT(build/include_what_you_use) - copy(data, partSize, 0, size - partSize); // NOLINT(build/include_what_you_use) - } else { - copy(data, 0, vWriteIndex_, size); // NOLINT(build/include_what_you_use) - } - - vWriteIndex_ = vWriteIndex_ + size > size_ ? vWriteIndex_ + size - size_ : vWriteIndex_ + size; -} - -void CircularAudioArray::pop_front(AudioArray &data, size_t size, bool skipAvailableDataCheck) { - pop_front(data.begin(), size, skipAvailableDataCheck); -} - -void CircularAudioArray::pop_front(float *data, size_t size, bool skipAvailableDataCheck) { - if (size > size_) { - throw std::overflow_error("size exceeds CircularAudioArray size_"); - } - - if (size > getNumberOfAvailableFrames() && !skipAvailableDataCheck) { - throw std::overflow_error("not enough data in CircularAudioArray"); - } - - if (vReadIndex_ + size > size_) { - auto partSize = size_ - vReadIndex_; - copyTo(data, vReadIndex_, 0, partSize); - copyTo(data, 0, partSize, size - partSize); - } else { - copyTo(data, vReadIndex_, 0, size); - } - - vReadIndex_ = vReadIndex_ + size > size_ ? vReadIndex_ + size - size_ : vReadIndex_ + size; -} - -void CircularAudioArray::pop_back( - AudioArray &data, - size_t size, - size_t offset, - bool skipAvailableDataCheck) { - pop_back(data.begin(), size, offset, skipAvailableDataCheck); -} - -void CircularAudioArray::pop_back( - float *data, - size_t size, - size_t offset, - bool skipAvailableDataCheck) { - if (size > size_) { - throw std::overflow_error("size exceeds CircularAudioArray size_"); - } - - if (size + offset > getNumberOfAvailableFrames() && !skipAvailableDataCheck) { - throw std::overflow_error("not enough data in CircularAudioArray"); - } - - if (vWriteIndex_ <= offset) { - copyTo(data, size_ - (offset - vWriteIndex_) - size, 0, size); - } else if (vWriteIndex_ <= size + offset) { - auto partSize = size + offset - vWriteIndex_; - copyTo(data, size_ - partSize, 0, partSize); - copyTo(data, 0, partSize, size - partSize); - } else { - copyTo(data, vWriteIndex_ - size - offset, 0, size); - } - - vReadIndex_ = vWriteIndex_ - offset < 0 ? size + vWriteIndex_ - offset : vWriteIndex_ - offset; -} - -size_t CircularAudioArray::getNumberOfAvailableFrames() const { - return vWriteIndex_ >= vReadIndex_ ? vWriteIndex_ - vReadIndex_ - : size_ - vReadIndex_ + vWriteIndex_; -} - -size_t CircularAudioArray::getAvailableSpace() const { - return size_ - getNumberOfAvailableFrames(); -} - -} // namespace audioapi diff --git a/packages/react-native-audio-api/common/cpp/audioapi/utils/CircularAudioArray.h b/packages/react-native-audio-api/common/cpp/audioapi/utils/CircularAudioArray.h deleted file mode 100644 index a59b5693e..000000000 --- a/packages/react-native-audio-api/common/cpp/audioapi/utils/CircularAudioArray.h +++ /dev/null @@ -1,32 +0,0 @@ -#pragma once - -#include - -namespace audioapi { - -class CircularAudioArray : public AudioArray { - public: - explicit CircularAudioArray(size_t size); - CircularAudioArray(const CircularAudioArray &other) = default; - ~CircularAudioArray() = default; - - void push_back(const AudioArray &data, size_t size, bool skipAvailableSpaceCheck = false); - void push_back(const float *data, size_t size, bool skipAvailableSpaceCheck = false); - - void pop_front(AudioArray &data, size_t size, bool skipAvailableDataCheck = false); - void pop_front(float *data, size_t size, bool skipAvailableDataCheck = false); - - void - pop_back(AudioArray &data, size_t size, size_t offset = 0, bool skipAvailableDataCheck = false); - void pop_back(float *data, size_t size, size_t offset = 0, bool skipAvailableDataCheck = false); - - [[nodiscard]] size_t getNumberOfAvailableFrames() const; - - private: - size_t vWriteIndex_ = 0; - size_t vReadIndex_ = 0; - - [[nodiscard]] size_t getAvailableSpace() const; -}; - -} // namespace audioapi diff --git a/packages/react-native-audio-api/common/cpp/test/src/core/effects/DelayTest.cpp b/packages/react-native-audio-api/common/cpp/test/src/core/effects/DelayTest.cpp index 2e06889f9..095b90269 100644 --- a/packages/react-native-audio-api/common/cpp/test/src/core/effects/DelayTest.cpp +++ b/packages/react-native-audio-api/common/cpp/test/src/core/effects/DelayTest.cpp @@ -33,8 +33,8 @@ class TestableDelayNode : public DelayNode { getDelayTimeParam()->setValue(value); } - std::shared_ptr processNode( - const std::shared_ptr &processingBuffer, + std::shared_ptr processNode( + const std::shared_ptr &processingBuffer, int framesToProcess) override { return DelayNode::processNode(processingBuffer, framesToProcess); } @@ -53,7 +53,7 @@ TEST_F(DelayTest, DelayWithZeroDelayOutputsInputSignal) { auto delayNode = TestableDelayNode(context, options); delayNode.setDelayTimeParam(DELAY_TIME); - auto buffer = std::make_shared(FRAMES_TO_PROCESS, 1, sampleRate); + auto buffer = std::make_shared(FRAMES_TO_PROCESS, 1, sampleRate); for (size_t i = 0; i < buffer->getSize(); ++i) { (*buffer->getChannel(0))[i] = i + 1; } @@ -72,7 +72,7 @@ TEST_F(DelayTest, DelayAppliesTimeShiftCorrectly) { auto delayNode = TestableDelayNode(context, options); delayNode.setDelayTimeParam(DELAY_TIME); - auto buffer = std::make_shared(FRAMES_TO_PROCESS, 1, sampleRate); + auto buffer = std::make_shared(FRAMES_TO_PROCESS, 1, sampleRate); for (size_t i = 0; i < buffer->getSize(); ++i) { (*buffer->getChannel(0))[i] = i + 1; } @@ -98,7 +98,7 @@ TEST_F(DelayTest, DelayHandlesTailCorrectly) { auto delayNode = TestableDelayNode(context, options); delayNode.setDelayTimeParam(DELAY_TIME); - auto buffer = std::make_shared(FRAMES_TO_PROCESS, 1, sampleRate); + auto buffer = std::make_shared(FRAMES_TO_PROCESS, 1, sampleRate); for (size_t i = 0; i < buffer->getSize(); ++i) { (*buffer->getChannel(0))[i] = i + 1; } diff --git a/packages/react-native-audio-api/common/cpp/test/src/core/effects/GainTest.cpp b/packages/react-native-audio-api/common/cpp/test/src/core/effects/GainTest.cpp index db997f836..ebdfdcb5d 100644 --- a/packages/react-native-audio-api/common/cpp/test/src/core/effects/GainTest.cpp +++ b/packages/react-native-audio-api/common/cpp/test/src/core/effects/GainTest.cpp @@ -33,8 +33,8 @@ class TestableGainNode : public GainNode { getGainParam()->setValue(value); } - std::shared_ptr processNode( - const std::shared_ptr &processingBuffer, + std::shared_ptr processNode( + const std::shared_ptr &processingBuffer, int framesToProcess) override { return GainNode::processNode(processingBuffer, framesToProcess); } @@ -51,7 +51,7 @@ TEST_F(GainTest, GainModulatesVolumeCorrectly) { auto gainNode = TestableGainNode(context); gainNode.setGainParam(GAIN_VALUE); - auto buffer = std::make_shared(FRAMES_TO_PROCESS, 1, sampleRate); + auto buffer = std::make_shared(FRAMES_TO_PROCESS, 1, sampleRate); for (size_t i = 0; i < buffer->getSize(); ++i) { (*buffer->getChannel(0))[i] = i + 1; } @@ -68,7 +68,7 @@ TEST_F(GainTest, GainModulatesVolumeCorrectlyMultiChannel) { auto gainNode = TestableGainNode(context); gainNode.setGainParam(GAIN_VALUE); - auto buffer = std::make_shared(FRAMES_TO_PROCESS, 2, sampleRate); + auto buffer = std::make_shared(FRAMES_TO_PROCESS, 2, sampleRate); for (size_t i = 0; i < buffer->getSize(); ++i) { (*buffer->getChannel(0))[i] = i + 1; (*buffer->getChannel(1))[i] = -i - 1; diff --git a/packages/react-native-audio-api/common/cpp/test/src/core/effects/StereoPannerTest.cpp b/packages/react-native-audio-api/common/cpp/test/src/core/effects/StereoPannerTest.cpp index b345eb2fe..02b4b54ba 100644 --- a/packages/react-native-audio-api/common/cpp/test/src/core/effects/StereoPannerTest.cpp +++ b/packages/react-native-audio-api/common/cpp/test/src/core/effects/StereoPannerTest.cpp @@ -33,8 +33,8 @@ class TestableStereoPannerNode : public StereoPannerNode { getPanParam()->setValue(value); } - std::shared_ptr processNode( - const std::shared_ptr &processingBuffer, + std::shared_ptr processNode( + const std::shared_ptr &processingBuffer, int framesToProcess) override { return StereoPannerNode::processNode(processingBuffer, framesToProcess); } @@ -51,7 +51,7 @@ TEST_F(StereoPannerTest, PanModulatesInputMonoCorrectly) { auto panNode = TestableStereoPannerNode(context); panNode.setPanParam(PAN_VALUE); - auto buffer = std::make_shared(FRAMES_TO_PROCESS, 1, sampleRate); + auto buffer = std::make_shared(FRAMES_TO_PROCESS, 1, sampleRate); for (size_t i = 0; i < buffer->getSize(); ++i) { (*buffer->getChannelByType(AudioBuffer::ChannelLeft))[i] = i + 1; } @@ -78,7 +78,7 @@ TEST_F(StereoPannerTest, PanModulatesInputStereoCorrectlyWithNegativePan) { auto panNode = TestableStereoPannerNode(context); panNode.setPanParam(PAN_VALUE); - auto buffer = std::make_shared(FRAMES_TO_PROCESS, 2, sampleRate); + auto buffer = std::make_shared(FRAMES_TO_PROCESS, 2, sampleRate); for (size_t i = 0; i < buffer->getSize(); ++i) { (*buffer->getChannelByType(AudioBuffer::ChannelLeft))[i] = i + 1; (*buffer->getChannelByType(AudioBuffer::ChannelRight))[i] = i + 1; @@ -106,7 +106,7 @@ TEST_F(StereoPannerTest, PanModulatesInputStereoCorrectlyWithPositivePan) { auto panNode = TestableStereoPannerNode(context); panNode.setPanParam(PAN_VALUE); - auto buffer = std::make_shared(FRAMES_TO_PROCESS, 2, sampleRate); + auto buffer = std::make_shared(FRAMES_TO_PROCESS, 2, sampleRate); for (size_t i = 0; i < buffer->getSize(); ++i) { (*buffer->getChannelByType(AudioBuffer::ChannelLeft))[i] = i + 1; (*buffer->getChannelByType(AudioBuffer::ChannelRight))[i] = i + 1; diff --git a/packages/react-native-audio-api/common/cpp/test/src/core/effects/WaveShaperNodeTest.cpp b/packages/react-native-audio-api/common/cpp/test/src/core/effects/WaveShaperNodeTest.cpp index e90260ccc..4ee9a53ea 100644 --- a/packages/react-native-audio-api/common/cpp/test/src/core/effects/WaveShaperNodeTest.cpp +++ b/packages/react-native-audio-api/common/cpp/test/src/core/effects/WaveShaperNodeTest.cpp @@ -35,8 +35,8 @@ class TestableWaveShaperNode : public WaveShaperNode { data[2] = 2.0f; } - std::shared_ptr processNode( - const std::shared_ptr &processingBuffer, + std::shared_ptr processNode( + const std::shared_ptr &processingBuffer, int framesToProcess) override { return WaveShaperNode::processNode(processingBuffer, framesToProcess); } @@ -60,7 +60,7 @@ TEST_F(WaveShaperNodeTest, NoneOverSamplingProcessesCorrectly) { waveShaper->setOversample(OverSampleType::OVERSAMPLE_NONE); waveShaper->setCurve(waveShaper->testCurve_); - auto buffer = std::make_shared(FRAMES_TO_PROCESS, 1, sampleRate); + auto buffer = std::make_shared(FRAMES_TO_PROCESS, 1, sampleRate); for (size_t i = 0; i < buffer->getSize(); ++i) { (*buffer->getChannel(0))[i] = -1.0f + i * 0.5f; } diff --git a/packages/react-native-audio-api/common/cpp/test/src/core/sources/AudioScheduledSourceTest.cpp b/packages/react-native-audio-api/common/cpp/test/src/core/sources/AudioScheduledSourceTest.cpp index 3a73c63c1..1f08b82b0 100644 --- a/packages/react-native-audio-api/common/cpp/test/src/core/sources/AudioScheduledSourceTest.cpp +++ b/packages/react-native-audio-api/common/cpp/test/src/core/sources/AudioScheduledSourceTest.cpp @@ -33,7 +33,7 @@ class TestableAudioScheduledSourceNode : public AudioScheduledSourceNode { } void updatePlaybackInfo( - const std::shared_ptr &processingBuffer, + const std::shared_ptr &processingBuffer, int framesToProcess, size_t &startOffset, size_t &nonSilentFramesToProcess, @@ -48,7 +48,8 @@ class TestableAudioScheduledSourceNode : public AudioScheduledSourceNode { currentSampleFrame); } - std::shared_ptr processNode(const std::shared_ptr &, int) override { + std::shared_ptr processNode(const std::shared_ptr &, int) + override { return nullptr; } @@ -61,7 +62,7 @@ class TestableAudioScheduledSourceNode : public AudioScheduledSourceNode { size_t startOffset = 0; size_t nonSilentFramesToProcess = 0; auto processingBuffer = - std::make_shared(128, 2, static_cast(SAMPLE_RATE)); + std::make_shared(128, 2, static_cast(SAMPLE_RATE)); updatePlaybackInfo( processingBuffer, frames, diff --git a/packages/react-native-audio-api/common/cpp/test/src/core/sources/ConstantSourceTest.cpp b/packages/react-native-audio-api/common/cpp/test/src/core/sources/ConstantSourceTest.cpp index 89b5ec413..5e498c2bb 100644 --- a/packages/react-native-audio-api/common/cpp/test/src/core/sources/ConstantSourceTest.cpp +++ b/packages/react-native-audio-api/common/cpp/test/src/core/sources/ConstantSourceTest.cpp @@ -33,8 +33,8 @@ class TestableConstantSourceNode : public ConstantSourceNode { getOffsetParam()->setValue(value); } - std::shared_ptr processNode( - const std::shared_ptr &processingBuffer, + std::shared_ptr processNode( + const std::shared_ptr &processingBuffer, int framesToProcess) override { return ConstantSourceNode::processNode(processingBuffer, framesToProcess); } @@ -48,7 +48,7 @@ TEST_F(ConstantSourceTest, ConstantSourceCanBeCreated) { TEST_F(ConstantSourceTest, ConstantSourceOutputsConstantValue) { static constexpr int FRAMES_TO_PROCESS = 4; - auto buffer = std::make_shared(FRAMES_TO_PROCESS, 1, sampleRate); + auto buffer = std::make_shared(FRAMES_TO_PROCESS, 1, sampleRate); auto constantSource = TestableConstantSourceNode(context); // constantSource.start(context->getCurrentTime()); // auto resultBuffer = constantSource.processNode(buffer, FRAMES_TO_PROCESS); diff --git a/packages/react-native-audio-api/ios/audioapi/ios/core/IOSAudioPlayer.h b/packages/react-native-audio-api/ios/audioapi/ios/core/IOSAudioPlayer.h index 7b19da5ad..b15c69af2 100644 --- a/packages/react-native-audio-api/ios/audioapi/ios/core/IOSAudioPlayer.h +++ b/packages/react-native-audio-api/ios/audioapi/ios/core/IOSAudioPlayer.h @@ -16,7 +16,7 @@ class AudioContext; class IOSAudioPlayer { public: IOSAudioPlayer( - const std::function, int)> &renderAudio, + const std::function, int)> &renderAudio, float sampleRate, int channelCount); ~IOSAudioPlayer(); @@ -30,9 +30,9 @@ class IOSAudioPlayer { bool isRunning() const; protected: - std::shared_ptr audioBuffer_; + std::shared_ptr audioBuffer_; NativeAudioPlayer *audioPlayer_; - std::function, int)> renderAudio_; + std::function, int)> renderAudio_; int channelCount_; std::atomic isRunning_; }; diff --git a/packages/react-native-audio-api/ios/audioapi/ios/core/IOSAudioPlayer.mm b/packages/react-native-audio-api/ios/audioapi/ios/core/IOSAudioPlayer.mm index edf678af5..500d58f3a 100644 --- a/packages/react-native-audio-api/ios/audioapi/ios/core/IOSAudioPlayer.mm +++ b/packages/react-native-audio-api/ios/audioapi/ios/core/IOSAudioPlayer.mm @@ -10,7 +10,7 @@ namespace audioapi { IOSAudioPlayer::IOSAudioPlayer( - const std::function, int)> &renderAudio, + const std::function, int)> &renderAudio, float sampleRate, int channelCount) : renderAudio_(renderAudio), channelCount_(channelCount), audioBuffer_(0), isRunning_(false) @@ -42,7 +42,7 @@ sampleRate:sampleRate channelCount:channelCount_]; - audioBuffer_ = std::make_shared(RENDER_QUANTUM_SIZE, channelCount_, sampleRate); + audioBuffer_ = std::make_shared(RENDER_QUANTUM_SIZE, channelCount_, sampleRate); } IOSAudioPlayer::~IOSAudioPlayer() diff --git a/packages/react-native-audio-api/ios/audioapi/ios/core/IOSAudioRecorder.mm b/packages/react-native-audio-api/ios/audioapi/ios/core/IOSAudioRecorder.mm index 3e45741db..3ead5ed1c 100644 --- a/packages/react-native-audio-api/ios/audioapi/ios/core/IOSAudioRecorder.mm +++ b/packages/react-native-audio-api/ios/audioapi/ios/core/IOSAudioRecorder.mm @@ -18,7 +18,7 @@ #include #include #include -#include +#include #include #include diff --git a/packages/react-native-audio-api/ios/audioapi/ios/core/utils/IOSRecorderCallback.h b/packages/react-native-audio-api/ios/audioapi/ios/core/utils/IOSRecorderCallback.h index 485c05919..ed9086d80 100644 --- a/packages/react-native-audio-api/ios/audioapi/ios/core/utils/IOSRecorderCallback.h +++ b/packages/react-native-audio-api/ios/audioapi/ios/core/utils/IOSRecorderCallback.h @@ -18,7 +18,6 @@ struct CallbackData { namespace audioapi { -class CircularAudioArray; class AudioEventHandlerRegistry; class IOSRecorderCallback : public AudioRecorderCallback { diff --git a/packages/react-native-audio-api/ios/audioapi/ios/core/utils/IOSRecorderCallback.mm b/packages/react-native-audio-api/ios/audioapi/ios/core/utils/IOSRecorderCallback.mm index 1ca4cf8b3..4dba6929e 100644 --- a/packages/react-native-audio-api/ios/audioapi/ios/core/utils/IOSRecorderCallback.mm +++ b/packages/react-native-audio-api/ios/audioapi/ios/core/utils/IOSRecorderCallback.mm @@ -8,7 +8,7 @@ #include #include #include -#include +#include #include #include #include From 485ebb0ea2ea9fd4f03acfec308b1921e42e14b8 Mon Sep 17 00:00:00 2001 From: maciejmakowski2003 Date: Thu, 12 Mar 2026 13:15:15 +0100 Subject: [PATCH 2/2] fix: nits --- .../audioapi/HostObjects/effects/WaveShaperNodeHostObject.cpp | 1 - .../common/cpp/audioapi/HostObjects/utils/NodeOptionsParser.h | 2 +- .../common/cpp/audioapi/core/effects/WaveShaperNode.cpp | 1 - .../common/cpp/audioapi/types/NodeOptions.h | 3 +-- .../common/cpp/audioapi/utils/CircularArray.hpp | 1 + 5 files changed, 3 insertions(+), 5 deletions(-) diff --git a/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/effects/WaveShaperNodeHostObject.cpp b/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/effects/WaveShaperNodeHostObject.cpp index 69d03d7d4..27d26d7bc 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/effects/WaveShaperNodeHostObject.cpp +++ b/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/effects/WaveShaperNodeHostObject.cpp @@ -3,7 +3,6 @@ #include #include #include -#include #include #include diff --git a/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/utils/NodeOptionsParser.h b/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/utils/NodeOptionsParser.h index 7bfcb439d..a5e0d2ff7 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/utils/NodeOptionsParser.h +++ b/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/utils/NodeOptionsParser.h @@ -351,7 +351,7 @@ inline WaveShaperOptions parseWaveShaperOptions( if (optionsObject.hasProperty(runtime, "buffer")) { auto arrayBuffer = optionsObject.getPropertyAsObject(runtime, "buffer").getArrayBuffer(runtime); - options.curve = std::make_shared( + options.curve = std::make_shared( reinterpret_cast(arrayBuffer.data(runtime)), static_cast(arrayBuffer.size(runtime) / sizeof(float))); } diff --git a/packages/react-native-audio-api/common/cpp/audioapi/core/effects/WaveShaperNode.cpp b/packages/react-native-audio-api/common/cpp/audioapi/core/effects/WaveShaperNode.cpp index 54a56c0d6..a2b8c776f 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/core/effects/WaveShaperNode.cpp +++ b/packages/react-native-audio-api/common/cpp/audioapi/core/effects/WaveShaperNode.cpp @@ -2,7 +2,6 @@ #include #include #include -#include #include diff --git a/packages/react-native-audio-api/common/cpp/audioapi/types/NodeOptions.h b/packages/react-native-audio-api/common/cpp/audioapi/types/NodeOptions.h index 98019f152..b2df4a479 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/types/NodeOptions.h +++ b/packages/react-native-audio-api/common/cpp/audioapi/types/NodeOptions.h @@ -12,7 +12,6 @@ #include #include #include -#include #include namespace audioapi { @@ -145,7 +144,7 @@ struct IIRFilterOptions : AudioNodeOptions { }; struct WaveShaperOptions : AudioNodeOptions { - std::shared_ptr curve; + std::shared_ptr curve; OverSampleType oversample = OverSampleType::OVERSAMPLE_NONE; WaveShaperOptions() { diff --git a/packages/react-native-audio-api/common/cpp/audioapi/utils/CircularArray.hpp b/packages/react-native-audio-api/common/cpp/audioapi/utils/CircularArray.hpp index f6a723a2d..54598a442 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/utils/CircularArray.hpp +++ b/packages/react-native-audio-api/common/cpp/audioapi/utils/CircularArray.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include namespace audioapi {