From 2bffe014e8c547746015eac61d073fa6bc00cf8b Mon Sep 17 00:00:00 2001 From: maciejmakowski2003 Date: Tue, 10 Mar 2026 14:52:02 +0100 Subject: [PATCH 1/6] refactor: implmented aligned audio array implementation --- .../common/cpp/audioapi/utils/AudioArray.cpp | 202 ------------- .../common/cpp/audioapi/utils/AudioArray.h | 166 ---------- .../common/cpp/audioapi/utils/AudioArray.hpp | 286 ++++++++++++++++++ 3 files changed, 286 insertions(+), 368 deletions(-) delete mode 100644 packages/react-native-audio-api/common/cpp/audioapi/utils/AudioArray.cpp delete mode 100644 packages/react-native-audio-api/common/cpp/audioapi/utils/AudioArray.h create mode 100644 packages/react-native-audio-api/common/cpp/audioapi/utils/AudioArray.hpp diff --git a/packages/react-native-audio-api/common/cpp/audioapi/utils/AudioArray.cpp b/packages/react-native-audio-api/common/cpp/audioapi/utils/AudioArray.cpp deleted file mode 100644 index 060eb9af0..000000000 --- a/packages/react-native-audio-api/common/cpp/audioapi/utils/AudioArray.cpp +++ /dev/null @@ -1,202 +0,0 @@ -#include -#include - -#include -#include -#include - -namespace audioapi { - -AudioArray::AudioArray(size_t size) : size_(size) { - if (size_ > 0) { - data_ = std::make_unique(size_); - zero(); - } -} - -AudioArray::AudioArray(const float *data, size_t size) : size_(size) { - if (size_ > 0) { - data_ = std::make_unique(size_); - copy(data, 0, 0, size_); - } -} - -AudioArray::AudioArray(const AudioArray &other) : size_(other.size_) { - if (size_ > 0 && other.data_) { - data_ = std::make_unique(size_); - copy(other); - } -} - -AudioArray::AudioArray(audioapi::AudioArray &&other) noexcept - : data_(std::move(other.data_)), size_(std::exchange(other.size_, 0)) {} - -AudioArray &AudioArray::operator=(const audioapi::AudioArray &other) { - if (this != &other) { - if (size_ != other.size_) { - size_ = other.size_; - data_ = (size_ > 0) ? std::make_unique(size_) : nullptr; - } - - if (size_ > 0 && data_) { - copy(other); - } - } - - return *this; -} - -AudioArray &AudioArray::operator=(audioapi::AudioArray &&other) noexcept { - if (this != &other) { - data_ = std::move(other.data_); - size_ = std::exchange(other.size_, 0); - } - - return *this; -} - -void AudioArray::zero() noexcept { - zero(0, size_); -} - -void AudioArray::zero(size_t start, size_t length) noexcept { - memset(data_.get() + start, 0, length * sizeof(float)); -} - -void AudioArray::sum(const AudioArray &source, float gain) { - sum(source, 0, 0, size_, gain); -} - -void AudioArray::sum( - const AudioArray &source, - size_t sourceStart, - size_t destinationStart, - size_t length, - float gain) { - if (size_ - destinationStart < length || source.size_ - sourceStart < length) [[unlikely]] { - throw std::out_of_range("Not enough data to sum two vectors."); - } - - // Using restrict to inform the compiler that the source and destination do not overlap - float *__restrict dest = data_.get() + destinationStart; - const float *__restrict src = source.data_.get() + sourceStart; - - dsp::multiplyByScalarThenAddToOutput(src, gain, dest, length); -} - -void AudioArray::multiply(const AudioArray &source) { - multiply(source, size_); -} - -void AudioArray::multiply(const audioapi::AudioArray &source, size_t length) { - if (size_ < length || source.size_ < length) [[unlikely]] { - throw std::out_of_range("Not enough data to perform vector multiplication."); - } - - float *__restrict dest = data_.get(); - const float *__restrict src = source.data_.get(); - - dsp::multiply(src, dest, dest, length); -} - -void AudioArray::copy(const AudioArray &source) { - copy(source, 0, 0, size_); -} - -void AudioArray::copy( - const AudioArray &source, - size_t sourceStart, - size_t destinationStart, - size_t length) { - if (source.size_ - sourceStart < length) [[unlikely]] { - throw std::out_of_range("Not enough data to copy from source."); - } - - copy(source.data_.get(), sourceStart, destinationStart, length); -} - -void AudioArray::copy( - const float *source, - size_t sourceStart, - size_t destinationStart, - size_t length) { - if (size_ - destinationStart < length) [[unlikely]] { - throw std::out_of_range("Not enough space to copy to destination."); - } - - memcpy(data_.get() + destinationStart, source + sourceStart, length * sizeof(float)); -} - -void AudioArray::copyReverse( - const audioapi::AudioArray &source, - size_t sourceStart, - size_t destinationStart, - size_t length) { - if (size_ - destinationStart < length || source.size_ - sourceStart < length) [[unlikely]] { - throw std::out_of_range("Not enough space to copy to destination or from source."); - } - - auto dstView = this->subSpan(length, destinationStart); - auto srcView = source.span(); - const float *__restrict srcPtr = &srcView[sourceStart]; - - for (size_t i = 0; i < length; ++i) { - dstView[i] = srcPtr[-static_cast(i)]; - } -} - -void AudioArray::copyTo( - float *destination, - size_t sourceStart, - size_t destinationStart, - size_t length) const { - if (size_ - sourceStart < length) [[unlikely]] { - throw std::out_of_range("Not enough data to copy from source."); - } - - memcpy(destination + destinationStart, data_.get() + sourceStart, length * sizeof(float)); -} - -void AudioArray::copyWithin(size_t sourceStart, size_t destinationStart, size_t length) { - if (size_ - sourceStart < length || size_ - destinationStart < length) [[unlikely]] { - throw std::out_of_range("Not enough space for moving data or data to move."); - } - - memmove(data_.get() + destinationStart, data_.get() + sourceStart, length * sizeof(float)); -} - -void AudioArray::reverse() { - if (size_ <= 1) { - return; - } - - std::reverse(begin(), end()); -} - -void AudioArray::normalize() { - float maxAbsValue = getMaxAbsValue(); - - if (maxAbsValue == 0.0f || maxAbsValue == 1.0f) { - return; - } - - dsp::multiplyByScalar(data_.get(), 1.0f / maxAbsValue, data_.get(), size_); -} - -void AudioArray::scale(float value) { - dsp::multiplyByScalar(data_.get(), value, data_.get(), size_); -} - -float AudioArray::getMaxAbsValue() const { - return dsp::maximumMagnitude(data_.get(), size_); -} - -float AudioArray::computeConvolution(const audioapi::AudioArray &kernel, size_t startIndex) const { - if (kernel.size_ > size_ - startIndex) [[unlikely]] { - throw std::out_of_range("Kernal size exceeds available data for convolution."); - } - - return dsp::computeConvolution(data_.get() + startIndex, kernel.data_.get(), kernel.size_); -} - -} // namespace audioapi diff --git a/packages/react-native-audio-api/common/cpp/audioapi/utils/AudioArray.h b/packages/react-native-audio-api/common/cpp/audioapi/utils/AudioArray.h deleted file mode 100644 index 6836f51ae..000000000 --- a/packages/react-native-audio-api/common/cpp/audioapi/utils/AudioArray.h +++ /dev/null @@ -1,166 +0,0 @@ -#pragma once - -#include -#include -#include -#include - -namespace audioapi { - -/// @brief AudioArray is a simple wrapper around a float array for audio data manipulation. -/// It provides various utility functions for audio processing. -/// @note AudioArray manages its own memory and provides copy and move semantics. -/// @note Not thread-safe. -class AudioArray { - public: - explicit AudioArray(size_t size); - - /// @brief Constructs an AudioArray from existing data. - /// @note The data is copied, so it does not take ownership of the pointer - AudioArray(const float *data, size_t size); - ~AudioArray() = default; - - AudioArray(const AudioArray &other); - AudioArray(AudioArray &&other) noexcept; - AudioArray &operator=(const AudioArray &other); - AudioArray &operator=(AudioArray &&other) noexcept; - - [[nodiscard]] size_t getSize() const noexcept { - return size_; - } - - float &operator[](size_t index) noexcept { - return data_[index]; - } - const float &operator[](size_t index) const noexcept { - return data_[index]; - } - - [[nodiscard]] float *begin() noexcept { - return data_.get(); - } - [[nodiscard]] float *end() noexcept { - return data_.get() + size_; - } - - [[nodiscard]] const float *begin() const noexcept { - return data_.get(); - } - [[nodiscard]] const float *end() const noexcept { - return data_.get() + size_; - } - - [[nodiscard]] std::span span() noexcept { - return {data_.get(), size_}; - } - - [[nodiscard]] std::span span() const noexcept { - return {data_.get(), size_}; - } - - [[nodiscard]] std::span subSpan(size_t length, size_t offset = 0) { - if (offset + length > size_) { - throw std::out_of_range("AudioArray::subSpan - offset + length exceeds array size"); - } - - return {data_.get() + offset, length}; - } - - void zero() noexcept; - void zero(size_t start, size_t length) noexcept; - - /// @brief Sums the source AudioArray into this AudioArray with an optional gain. - /// @param source The source AudioArray to sum from. - /// @param gain The gain to apply to the source before summing. Default is 1.0f. - /// @note Assumes that source and this are located in two distinct, non-overlapping memory locations. - void sum(const AudioArray &source, float gain = 1.0f); - - /// @brief Sums the source AudioArray into this AudioArray with an optional gain. - /// @param source The source AudioArray to sum from. - /// @param sourceStart The starting index in the source AudioArray. - /// @param destinationStart The starting index in this AudioArray. - /// @param length The number of samples to sum. - /// @param gain The gain to apply to the source before summing. Default is 1.0f. - /// @note Assumes that source and this are located in two distinct, non-overlapping memory locations. - void sum( - const AudioArray &source, - size_t sourceStart, - size_t destinationStart, - size_t length, - float gain = 1.0f); - - /// @brief Multiplies this AudioArray by the source AudioArray element-wise. - /// @param source The source AudioArray to multiply with. - /// @note Assumes that source and this are located in two distinct, non-overlapping memory locations. - void multiply(const AudioArray &source); - - /// @brief Multiplies this AudioArray by the source AudioArray element-wise. - /// @param source The source AudioArray to multiply with. - /// @param length The number of samples to multiply. - /// @note Assumes that source and this are located in two distinct, non-overlapping memory locations. - void multiply(const AudioArray &source, size_t length); - - /// @brief Copies source AudioArray into this AudioArray - /// @param source The source AudioArray to copy. - /// @note Assumes that source and this are located in two distinct, non-overlapping memory locations. - void copy(const AudioArray &source); // NOLINT(build/include_what_you_use) - - /// @brief Copies source AudioArray into this AudioArray - /// @param source The source AudioArray to copy. - /// @param sourceStart The starting index in the source AudioArray. - /// @param destinationStart The starting index in this AudioArray. - /// @param length The number of samples to copy. - /// @note Assumes that source and this are located in two distinct, non-overlapping memory locations. - void copy( - const AudioArray &source, - size_t sourceStart, - size_t destinationStart, - size_t length); // NOLINT(build/include_what_you_use) - - /// @brief Copies data from a raw float pointer into this AudioArray. - /// @param source The source float pointer to copy from. - /// @param sourceStart The starting index in the source float pointer. - /// @param destinationStart The starting index in this AudioArray. - /// @param length The number of samples to copy. - /// @note Assumes that source and this are located in two distinct, non-overlapping memory locations. - void copy( - const float *source, - size_t sourceStart, - size_t destinationStart, - size_t length); // NOLINT(build/include_what_you_use) - - /// @brief Copies data from the source AudioArray in reverse order into this AudioArray. - /// @param source The source AudioArray to copy from. - /// @param sourceStart The starting index in the source AudioArray. - /// @param destinationStart The starting index in this AudioArray. - /// @param length The number of samples to copy. - /// @note Assumes that source and this are located in two distinct, non-overlapping memory locations. - void - copyReverse(const AudioArray &source, size_t sourceStart, size_t destinationStart, size_t length); - - /// @brief Copies data to a raw float pointer from this AudioArray. - /// @param destination The destination float pointer to copy to. - /// @param sourceStart The starting index in the this AudioArray. - /// @param destinationStart The starting index in the destination float pointer. - /// @param length The number of samples to copy. - /// @note Assumes that destination and this are located in two distinct, non-overlapping memory locations. - void copyTo(float *destination, size_t sourceStart, size_t destinationStart, size_t length) const; - - /// @brief Copies a sub-section of the array to another location within itself. - /// @param sourceStart The index where the data to be copied begins. - /// @param destinationStart The index where the data should be placed. - /// @param length The number of samples to copy. - void copyWithin(size_t sourceStart, size_t destinationStart, size_t length); - - void reverse(); - void normalize(); - void scale(float value); - [[nodiscard]] float getMaxAbsValue() const; - [[nodiscard]] float computeConvolution(const AudioArray &kernel, size_t startIndex = 0) const; - - protected: - std::unique_ptr data_ = nullptr; - size_t size_ = 0; -}; - -} // namespace audioapi 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 new file mode 100644 index 000000000..60891b1cf --- /dev/null +++ b/packages/react-native-audio-api/common/cpp/audioapi/utils/AudioArray.hpp @@ -0,0 +1,286 @@ +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace audioapi { + +/// @brief AlignedAudioArray is a simple wrapper around an aligned float vector for audio data manipulation. +/// It provides various utility functions for audio processing. +/// @tparam Alignment The memory alignment in bytes for the underlying storage. +/// @note AlignedAudioArray manages its own memory and provides copy and move semantics. +/// @note Not thread-safe. +/// @note Operations between different alignment specializations are supported. +template +class AlignedAudioArray { + template + friend class AlignedAudioArray; + + public: + explicit AlignedAudioArray(size_t size) : data_(size, 0.0f), size_(size) {} + + /// @brief Constructs a AlignedAudioArray from existing data. + /// @note The data is copied, so it does not take ownership of the pointer. + AlignedAudioArray(const float *data, size_t size) : data_(size), size_(size) { + if (size_ > 0) { + copy(data, 0, 0, size_); + } + } + + ~AlignedAudioArray() = default; + + AlignedAudioArray(const AlignedAudioArray &other) : data_(other.data_), size_(other.size_) {} + + AlignedAudioArray(AlignedAudioArray &&other) noexcept + : data_(std::move(other.data_)), size_(std::exchange(other.size_, 0)) {} + + AlignedAudioArray &operator=(const AlignedAudioArray &other) { + if (this != &other) { + if (size_ != other.size_) { + size_ = other.size_; + data_.resize(size_); + } + if (size_ > 0) { + copy(other); + } + } + return *this; + } + + AlignedAudioArray &operator=(AlignedAudioArray &&other) noexcept { + if (this != &other) { + data_ = std::move(other.data_); + size_ = std::exchange(other.size_, 0); + } + return *this; + } + + [[nodiscard]] size_t getSize() const noexcept { + return size_; + } + + float &operator[](size_t index) noexcept { + return data_[index]; + } + const float &operator[](size_t index) const noexcept { + return data_[index]; + } + + [[nodiscard]] float *begin() noexcept { + return alignedData(); + } + [[nodiscard]] float *end() noexcept { + return alignedData() + size_; + } + + [[nodiscard]] const float *begin() const noexcept { + return alignedData(); + } + [[nodiscard]] const float *end() const noexcept { + return alignedData() + size_; + } + + [[nodiscard]] std::span span() noexcept { + return {alignedData(), size_}; + } + + [[nodiscard]] std::span span() const noexcept { + return {alignedData(), size_}; + } + + [[nodiscard]] std::span subSpan(size_t length, size_t offset = 0) { + if (offset + length > size_) { + throw std::out_of_range("AudioArray::subSpan - offset + length exceeds array size"); + } + return {alignedData() + offset, length}; + } + + void zero() noexcept { + zero(0, size_); + } + + void zero(size_t start, size_t length) noexcept { + memset(alignedData() + start, 0, length * sizeof(float)); + } + + /// @brief Sums the source array into this array with an optional gain. + /// @note Assumes source and this are in distinct, non-overlapping memory locations. + template + void sum(const AlignedAudioArray &source, float gain = 1.0f) { + sum(source, 0, 0, size_, gain); + } + + /// @brief Sums a sub-range of source into this array with an optional gain. + /// @note Assumes source and this are in distinct, non-overlapping memory locations. + template + void sum( + const AlignedAudioArray &source, + size_t sourceStart, + size_t destinationStart, + size_t length, + float gain = 1.0f) { + if (size_ - destinationStart < length || source.size_ - sourceStart < length) [[unlikely]] { + throw std::out_of_range("Not enough data to sum two vectors."); + } + + // Using restrict to inform the compiler that the source and destination do not overlap + float *__restrict dest = alignedData() + destinationStart; + const float *__restrict src = source.alignedData() + sourceStart; + + dsp::multiplyByScalarThenAddToOutput(src, gain, dest, length); + } + + /// @brief Multiplies this array by the source array element-wise. + /// @note Assumes source and this are in distinct, non-overlapping memory locations. + template + void multiply(const AlignedAudioArray &source) { + multiply(source, size_); + } + + /// @brief Multiplies the first length elements of this array by the source array element-wise. + /// @note Assumes source and this are in distinct, non-overlapping memory locations. + template + void multiply(const AlignedAudioArray &source, size_t length) { + if (size_ < length || source.size_ < length) [[unlikely]] { + throw std::out_of_range("Not enough data to perform vector multiplication."); + } + + float *__restrict dest = alignedData(); + const float *__restrict src = source.alignedData(); + + dsp::multiply(src, dest, dest, length); + } + + /// @brief Copies source array into this array. + /// @note Assumes source and this are in distinct, non-overlapping memory locations. + template + void copy(const AlignedAudioArray &source) { // NOLINT(build/include_what_you_use) + copy(source, 0, 0, size_); + } + + /// @brief Copies a sub-range of source into this array. + /// @note Assumes source and this are in distinct, non-overlapping memory locations. + template + void copy( + const AlignedAudioArray &source, + size_t sourceStart, + size_t destinationStart, + size_t length) { // NOLINT(build/include_what_you_use) + if (source.size_ - sourceStart < length) [[unlikely]] { + throw std::out_of_range("Not enough data to copy from source."); + } + copy(source.alignedData(), sourceStart, destinationStart, length); + } + + /// @brief Copies data from a raw float pointer into this array. + /// @note Assumes source and this are in distinct, non-overlapping memory locations. + void copy( + const float *source, + size_t sourceStart, + size_t destinationStart, + size_t length) { // NOLINT(build/include_what_you_use) + if (size_ - destinationStart < length) [[unlikely]] { + throw std::out_of_range("Not enough space to copy to destination."); + } + memcpy(alignedData() + destinationStart, source + sourceStart, length * sizeof(float)); + } + + /// @brief Copies source array in reverse order into this array. + /// @note Assumes source and this are in distinct, non-overlapping memory locations. + template + void copyReverse( + const AlignedAudioArray &source, + size_t sourceStart, + size_t destinationStart, + size_t length) { + if (size_ - destinationStart < length || source.size_ - sourceStart < length) [[unlikely]] { + throw std::out_of_range("Not enough space to copy to destination or from source."); + } + + auto dstView = this->subSpan(length, destinationStart); + auto srcView = source.span(); + const float *__restrict srcPtr = &srcView[sourceStart]; + + for (size_t i = 0; i < length; ++i) { + dstView[i] = srcPtr[-static_cast(i)]; + } + } + + /// @brief Copies data from this array to a raw float pointer. + /// @note Assumes destination and this are in distinct, non-overlapping memory locations. + void copyTo(float *destination, size_t sourceStart, size_t destinationStart, size_t length) const { + if (size_ - sourceStart < length) [[unlikely]] { + throw std::out_of_range("Not enough data to copy from source."); + } + memcpy(destination + destinationStart, alignedData() + sourceStart, length * sizeof(float)); + } + + /// @brief Copies a sub-section of the array to another location within itself. + void copyWithin(size_t sourceStart, size_t destinationStart, size_t length) { + if (size_ - sourceStart < length || size_ - destinationStart < length) [[unlikely]] { + throw std::out_of_range("Not enough space for moving data or data to move."); + } + float *base = alignedData(); + memmove(base + destinationStart, base + sourceStart, length * sizeof(float)); + } + + void reverse() { + if (size_ <= 1) { + return; + } + std::reverse(begin(), end()); + } + + void normalize() { + float maxAbsValue = getMaxAbsValue(); + if (maxAbsValue == 0.0f || maxAbsValue == 1.0f) { + return; + } + float *data = alignedData(); + dsp::multiplyByScalar(data, 1.0f / maxAbsValue, data, size_); + } + + void scale(float value) { + float *data = alignedData(); + dsp::multiplyByScalar(data, value, data, size_); + } + + [[nodiscard]] float getMaxAbsValue() const { + return dsp::maximumMagnitude(alignedData(), size_); + } + + template + [[nodiscard]] float computeConvolution( + 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."); + } + return dsp::computeConvolution(alignedData() + startIndex, kernel.alignedData(), kernel.size_); + } + + private: + [[nodiscard]] float *alignedData() noexcept { + return std::assume_aligned(data_.data()); + } + [[nodiscard]] const float *alignedData() const noexcept { + return std::assume_aligned(data_.data()); + } + + protected: + std::vector> data_; + size_t size_ = 0; +}; + +using AudioArray = AlignedAudioArray; +using DSPAudioArray = AlignedAudioArray<64>; + +} // namespace audioapi From 7b17b7b80c3defe019d07b65461590c71dccf7e2 Mon Sep 17 00:00:00 2001 From: maciejmakowski2003 Date: Tue, 10 Mar 2026 15:02:44 +0100 Subject: [PATCH 2/6] refactor: renamed includes from AudioArray.h to AudioArray.hpp --- apps/fabric-example/ios/Podfile.lock | 2 +- .../audiodocs/docs/guides/create-your-own-effect.mdx | 2 +- .../audioapi/android/core/AndroidAudioRecorder.cpp | 2 +- .../cpp/audioapi/android/core/AndroidAudioRecorder.h | 2 +- .../main/cpp/audioapi/android/core/AudioPlayer.cpp | 2 +- .../android/core/utils/AndroidRecorderCallback.cpp | 2 +- .../android/core/utils/AndroidRecorderCallback.h | 2 +- .../cpp/audioapi/HostObjects/AudioParamHostObject.cpp | 2 +- .../HostObjects/effects/ConvolverNodeHostObject.cpp | 2 +- .../common/cpp/audioapi/core/AudioNode.cpp | 2 +- .../common/cpp/audioapi/core/AudioParam.cpp | 2 +- .../common/cpp/audioapi/core/BaseAudioContext.cpp | 2 +- .../common/cpp/audioapi/core/OfflineAudioContext.cpp | 2 +- .../common/cpp/audioapi/core/analysis/AnalyserNode.h | 2 +- .../cpp/audioapi/core/effects/BiquadFilterNode.cpp | 2 +- .../cpp/audioapi/core/effects/ConvolverNode.cpp | 2 +- .../common/cpp/audioapi/core/effects/DelayNode.cpp | 2 +- .../common/cpp/audioapi/core/effects/GainNode.cpp | 2 +- .../cpp/audioapi/core/effects/IIRFilterNode.cpp | 2 +- .../common/cpp/audioapi/core/effects/IIRFilterNode.h | 2 +- .../cpp/audioapi/core/effects/StereoPannerNode.cpp | 2 +- .../cpp/audioapi/core/effects/WaveShaperNode.cpp | 2 +- .../common/cpp/audioapi/core/effects/WaveShaperNode.h | 4 +--- .../common/cpp/audioapi/core/effects/WorkletNode.h | 2 +- .../cpp/audioapi/core/effects/WorkletProcessingNode.h | 2 +- .../core/sources/AudioBufferBaseSourceNode.cpp | 2 +- .../core/sources/AudioBufferQueueSourceNode.cpp | 2 +- .../audioapi/core/sources/AudioBufferSourceNode.cpp | 2 +- .../core/sources/AudioScheduledSourceNode.cpp | 2 +- .../cpp/audioapi/core/sources/ConstantSourceNode.cpp | 2 +- .../cpp/audioapi/core/sources/OscillatorNode.cpp | 2 +- .../cpp/audioapi/core/sources/RecorderAdapterNode.cpp | 2 +- .../common/cpp/audioapi/core/sources/StreamerNode.cpp | 2 +- .../cpp/audioapi/core/sources/WorkletSourceNode.h | 2 +- .../common/cpp/audioapi/core/utils/AudioDecoder.cpp | 2 +- .../cpp/audioapi/core/utils/AudioRecorderCallback.cpp | 2 +- .../cpp/audioapi/core/utils/AudioRecorderCallback.h | 2 +- .../common/cpp/audioapi/core/utils/AudioStretcher.cpp | 2 +- .../common/cpp/audioapi/dsp/Convolver.cpp | 2 +- .../common/cpp/audioapi/dsp/Convolver.h | 2 +- .../common/cpp/audioapi/dsp/FFT.h | 2 +- .../common/cpp/audioapi/dsp/WaveShaper.cpp | 2 +- .../common/cpp/audioapi/dsp/WaveShaper.h | 2 +- .../common/cpp/audioapi/dsp/r8brain/Resampler.h | 2 +- .../cpp/audioapi/libs/ffmpeg/FFmpegDecoding.cpp | 2 +- .../common/cpp/audioapi/types/NodeOptions.h | 2 +- .../common/cpp/audioapi/utils/AudioArray.hpp | 11 ++++++----- .../common/cpp/audioapi/utils/AudioArrayBuffer.hpp | 6 +++--- .../common/cpp/audioapi/utils/AudioBuffer.cpp | 2 +- .../common/cpp/audioapi/utils/AudioBuffer.h | 2 +- .../common/cpp/audioapi/utils/CircularAudioArray.h | 2 +- .../audioapi/utils/CircularOverflowableAudioArray.h | 2 +- .../common/cpp/test/src/core/effects/DelayTest.cpp | 2 +- .../common/cpp/test/src/core/effects/GainTest.cpp | 2 +- .../cpp/test/src/core/effects/StereoPannerTest.cpp | 2 +- .../cpp/test/src/core/effects/WaveShaperNodeTest.cpp | 2 +- .../cpp/test/src/core/sources/ConstantSourceTest.cpp | 2 +- .../common/cpp/test/src/utils/AudioArrayTest.cpp | 2 +- .../ios/audioapi/ios/core/IOSAudioPlayer.mm | 2 +- .../ios/audioapi/ios/core/IOSAudioRecorder.mm | 2 +- .../audioapi/ios/core/utils/IOSRecorderCallback.mm | 2 +- 61 files changed, 68 insertions(+), 69 deletions(-) diff --git a/apps/fabric-example/ios/Podfile.lock b/apps/fabric-example/ios/Podfile.lock index 83b7e4707..a344b24dc 100644 --- a/apps/fabric-example/ios/Podfile.lock +++ b/apps/fabric-example/ios/Podfile.lock @@ -2588,7 +2588,7 @@ SPEC CHECKSUMS: ReactCodegen: f66521b131699d6af0790f10653933b3f1f79a6f ReactCommon: 07572bf9e687c8a52fbe4a3641e9e3a1a477c78e ReactNativeDependencies: 3467a1fea6f7a524df13b30430bebcc254d9aee2 - RNAudioAPI: cb97b644449ba63f7ae31c02f73e9cf1ab8fd259 + RNAudioAPI: fa5c075d2fcdb1ad9a695754b38f07c8c3074396 RNGestureHandler: 07de6f059e0ee5744ae9a56feb07ee345338cc31 RNReanimated: d75c81956bf7531fe08ba4390149002ab8bdd127 RNScreens: 6cb648bdad8fe9bee9259fe144df95b6d1d5b707 diff --git a/packages/audiodocs/docs/guides/create-your-own-effect.mdx b/packages/audiodocs/docs/guides/create-your-own-effect.mdx index f882ccc27..42a018888 100644 --- a/packages/audiodocs/docs/guides/create-your-own-effect.mdx +++ b/packages/audiodocs/docs/guides/create-your-own-effect.mdx @@ -71,7 +71,7 @@ private: ```cpp #include "MyProcessorNode.h" #include -#include +#include namespace audioapi { MyProcessorNode::MyProcessorNode(const std::shared_ptr &context) 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 8765606ce..f2b2a0499 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 @@ -11,7 +11,7 @@ #include #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 ea91f63cd..1ea0d295a 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 @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -10,7 +11,6 @@ namespace audioapi { class AudioBuffer; -class AudioArray; class CircularAudioArray; class AudioFileProperties; class AndroidRecorderCallback; 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 6e3bd1692..1f04c29ae 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 @@ -2,7 +2,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.cpp b/packages/react-native-audio-api/android/src/main/cpp/audioapi/android/core/utils/AndroidRecorderCallback.cpp index fa40b19f6..2c51c7cba 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 @@ -3,7 +3,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 7ac5b9b03..cc73fef07 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 @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -9,7 +10,6 @@ namespace audioapi { class AudioBuffer; -class AudioArray; class CircularAudioArray; class AudioEventHandlerRegistry; diff --git a/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/AudioParamHostObject.cpp b/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/AudioParamHostObject.cpp index 6fe82bb01..b396991d4 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/AudioParamHostObject.cpp +++ b/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/AudioParamHostObject.cpp @@ -1,7 +1,7 @@ #include #include -#include +#include #include #include 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 af1bcf22d..3811ac5f2 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 @@ -5,7 +5,7 @@ #include #include #include -#include +#include #include #include 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 ed0540b11..bc77a51d4 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 @@ -3,7 +3,7 @@ #include #include #include -#include +#include #include #include 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 bb440803b..d2dc150a7 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 @@ -2,7 +2,7 @@ #include #include #include -#include +#include #include #include 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 5d0584b31..c8428deed 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 @@ -24,7 +24,7 @@ #include #include #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 2b21002af..336712c6b 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 @@ -5,7 +5,7 @@ #include #include #include -#include +#include #include #include 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 c806e820b..212e33f36 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 @@ -3,7 +3,7 @@ #include #include #include -#include +#include #include #include 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 5c77ffe48..cd40e4baa 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 @@ -30,7 +30,7 @@ #include #include #include -#include +#include #include #include 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 5415eb6f3..435d69d6b 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 @@ -3,7 +3,7 @@ #include #include #include -#include +#include #include #include #include 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 2350315be..bdf40aa79 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 @@ -2,7 +2,7 @@ #include #include #include -#include +#include #include #include 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 e2afde588..fe0b1149d 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 @@ -2,7 +2,7 @@ #include #include #include -#include +#include #include #include 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 3592fb022..41076e557 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 @@ -27,7 +27,7 @@ #include #include #include -#include +#include #include #include #include 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 a5f6416cf..f6771940e 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 @@ -29,7 +29,7 @@ #include #include -#include +#include #include #include 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 c2e837518..baec091c0 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 @@ -2,7 +2,7 @@ #include #include #include -#include +#include #include #include 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 fd56d8aae..d7dfb88d2 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,7 @@ #include #include #include -#include +#include #include #include #include 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 dd6125b47..cdd8dfd2f 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 @@ -3,16 +3,14 @@ #include #include #include +#include -#include #include -#include #include namespace audioapi { class AudioBuffer; -class AudioArray; struct WaveShaperOptions; class WaveShaperNode : public AudioNode { 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 f7a3382cf..acdf28880 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 @@ -3,7 +3,7 @@ #include #include #include -#include +#include #include #include #include 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 42e8ec72b..d493a8047 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 @@ -3,7 +3,7 @@ #include #include #include -#include +#include #include #include #include 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 eedb0ea47..38505c478 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 @@ -4,7 +4,7 @@ #include #include #include -#include +#include #include #include #include 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 5a2d8383e..df989de48 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 @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include #include 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 c4fddbe80..9286a5ca9 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 @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include #include #include 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 551b93982..4ad8ce92e 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 @@ -3,7 +3,7 @@ #include #include #include -#include +#include #include #if !RN_AUDIO_API_TEST 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 8f863698c..13fdc9874 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 @@ -2,7 +2,7 @@ #include #include #include -#include +#include #include #include 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 2d32fb8dc..18833824f 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 @@ -2,7 +2,7 @@ #include #include #include -#include +#include #include #include 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 4ac6ba93b..2d72f26f2 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 @@ -2,7 +2,7 @@ #include #include #include -#include +#include #include #include 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 d567c84d5..178d87085 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 @@ -12,7 +12,7 @@ #include #include #include -#include +#include #include #include #include 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 9596f6822..93589ba3f 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 @@ -3,7 +3,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/packages/react-native-audio-api/common/cpp/audioapi/core/utils/AudioDecoder.cpp b/packages/react-native-audio-api/common/cpp/audioapi/core/utils/AudioDecoder.cpp index c37448064..2b0f1acc3 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/core/utils/AudioDecoder.cpp +++ b/packages/react-native-audio-api/common/cpp/audioapi/core/utils/AudioDecoder.cpp @@ -1,7 +1,7 @@ #include #include #include -#include +#include #include #include 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 08f3e1c11..d7035a444 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 aa37ec754..51cde9f66 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 @@ -1,5 +1,6 @@ #pragma once +#include #include #include #include @@ -11,7 +12,6 @@ namespace audioapi { class AudioBuffer; -class AudioArray; class CircularAudioArray; class AudioEventHandlerRegistry; diff --git a/packages/react-native-audio-api/common/cpp/audioapi/core/utils/AudioStretcher.cpp b/packages/react-native-audio-api/common/cpp/audioapi/core/utils/AudioStretcher.cpp index 9e4ff8cdd..286254fa8 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/core/utils/AudioStretcher.cpp +++ b/packages/react-native-audio-api/common/cpp/audioapi/core/utils/AudioStretcher.cpp @@ -1,7 +1,7 @@ #include #include #include -#include +#include #include #include #include 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 36eb46919..7a2ddde88 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 @@ -7,7 +7,7 @@ #include #include -#include +#include #include #include #include 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 8d7b966cb..a5a05637d 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 @@ -2,7 +2,7 @@ #include #include -#include +#include #include #include #include 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 38daa7397..0a9290b10 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 @@ -2,7 +2,7 @@ #include #include -#include +#include #include #include 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 d48923b86..645a03b71 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,7 @@ #include #include #include -#include +#include #include #include 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 fed67f2f6..ef645a985 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 @@ -2,13 +2,13 @@ #include #include +#include #include namespace audioapi { class AudioBuffer; -class AudioArray; class WaveShaper { public: 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 index 5da979247..55a464868 100644 --- 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 @@ -1,6 +1,6 @@ #pragma once -#include +#include #include #include #include diff --git a/packages/react-native-audio-api/common/cpp/audioapi/libs/ffmpeg/FFmpegDecoding.cpp b/packages/react-native-audio-api/common/cpp/audioapi/libs/ffmpeg/FFmpegDecoding.cpp index 59aabb408..71ab6babc 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/libs/ffmpeg/FFmpegDecoding.cpp +++ b/packages/react-native-audio-api/common/cpp/audioapi/libs/ffmpeg/FFmpegDecoding.cpp @@ -11,7 +11,7 @@ #if !RN_AUDIO_API_FFMPEG_DISABLED #include #endif // RN_AUDIO_API_FFMPEG_DISABLED -#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 e5846f1ec..be6c53310 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 @@ -11,7 +11,7 @@ #include #include #include -#include +#include #include #include 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 60891b1cf..b418d09cc 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 @@ -1,15 +1,15 @@ #pragma once +#include +#include +#include #include #include #include #include -#include #include -#include #include -#include -#include +#include namespace audioapi { @@ -216,7 +216,8 @@ class AlignedAudioArray { /// @brief Copies data from this array to a raw float pointer. /// @note Assumes destination and this are in distinct, non-overlapping memory locations. - void copyTo(float *destination, size_t sourceStart, size_t destinationStart, size_t length) const { + void copyTo(float *destination, size_t sourceStart, size_t destinationStart, size_t length) + const { if (size_ - sourceStart < length) [[unlikely]] { throw std::out_of_range("Not enough data to copy from source."); } 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 8f629aa8b..cf0082880 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 @@ -1,6 +1,6 @@ #pragma once -#include +#include #include #if !RN_AUDIO_API_TEST @@ -23,14 +23,14 @@ class AudioArrayBuffer : public JsiBuffer, public AudioArray { return size_ * sizeof(float); } uint8_t *data() override { - return reinterpret_cast(data_.get()); + return reinterpret_cast(data_.data()); } #else [[nodiscard]] size_t size() const { return size_ * sizeof(float); } uint8_t *data() { - return reinterpret_cast(data_.get()); + return reinterpret_cast(data_.data()); } #endif }; diff --git a/packages/react-native-audio-api/common/cpp/audioapi/utils/AudioBuffer.cpp b/packages/react-native-audio-api/common/cpp/audioapi/utils/AudioBuffer.cpp index a1fabff8d..e310534ad 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/utils/AudioBuffer.cpp +++ b/packages/react-native-audio-api/common/cpp/audioapi/utils/AudioBuffer.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include #include #include diff --git a/packages/react-native-audio-api/common/cpp/audioapi/utils/AudioBuffer.h b/packages/react-native-audio-api/common/cpp/audioapi/utils/AudioBuffer.h index f9b27f046..3694e859b 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/utils/AudioBuffer.h +++ b/packages/react-native-audio-api/common/cpp/audioapi/utils/AudioBuffer.h @@ -1,7 +1,7 @@ #pragma once #include -#include +#include #include #include 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 index b86994697..a59b5693e 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/utils/CircularAudioArray.h +++ b/packages/react-native-audio-api/common/cpp/audioapi/utils/CircularAudioArray.h @@ -1,6 +1,6 @@ #pragma once -#include +#include namespace audioapi { diff --git a/packages/react-native-audio-api/common/cpp/audioapi/utils/CircularOverflowableAudioArray.h b/packages/react-native-audio-api/common/cpp/audioapi/utils/CircularOverflowableAudioArray.h index 4aef5e5a8..1aae18afe 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/utils/CircularOverflowableAudioArray.h +++ b/packages/react-native-audio-api/common/cpp/audioapi/utils/CircularOverflowableAudioArray.h @@ -1,7 +1,7 @@ #pragma once -#include +#include #include #include 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 d3ca4a3e4..effc552a1 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 @@ -2,7 +2,7 @@ #include #include #include -#include +#include #include #include #include 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 501daf655..803f3ab0b 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 @@ -2,7 +2,7 @@ #include #include #include -#include +#include #include #include #include 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 123a9adb8..afe2dbee1 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 @@ -2,7 +2,7 @@ #include #include #include -#include +#include #include #include #include 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 6faa6bfe4..5e0923178 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 @@ -3,7 +3,7 @@ #include #include #include -#include +#include #include #include #include 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 6136b4abe..5e1a7a8da 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 @@ -2,7 +2,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/packages/react-native-audio-api/common/cpp/test/src/utils/AudioArrayTest.cpp b/packages/react-native-audio-api/common/cpp/test/src/utils/AudioArrayTest.cpp index e3e6072e7..c1e2b8a2e 100644 --- a/packages/react-native-audio-api/common/cpp/test/src/utils/AudioArrayTest.cpp +++ b/packages/react-native-audio-api/common/cpp/test/src/utils/AudioArrayTest.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include 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 5fca12e33..e58376bba 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 @@ -4,7 +4,7 @@ #include #include #include -#include +#include #include namespace audioapi { 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 a680c15da..36bd7bd6b 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 @@ -15,7 +15,7 @@ #include #include #include -#include +#include #include #include #include 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 e4df13e64..637e84c86 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 @@ -6,7 +6,7 @@ #include #include #include -#include +#include #include #include #include From 2ac74daf3f55dacd7edd92d64b958ba31bfd80bc Mon Sep 17 00:00:00 2001 From: maciejmakowski2003 Date: Tue, 10 Mar 2026 16:48:18 +0100 Subject: [PATCH 3/6] refactor: implemented AlignedAudioBuffer --- .../cpp/audioapi/utils/AudioArrayBuffer.hpp | 19 +- .../common/cpp/audioapi/utils/AudioBuffer.cpp | 381 --------------- .../common/cpp/audioapi/utils/AudioBuffer.h | 180 ------- .../common/cpp/audioapi/utils/AudioBuffer.hpp | 443 ++++++++++++++++++ 4 files changed, 454 insertions(+), 569 deletions(-) delete mode 100644 packages/react-native-audio-api/common/cpp/audioapi/utils/AudioBuffer.cpp delete mode 100644 packages/react-native-audio-api/common/cpp/audioapi/utils/AudioBuffer.h create mode 100644 packages/react-native-audio-api/common/cpp/audioapi/utils/AudioBuffer.hpp 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 cf0082880..a2ed748b4 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 @@ -1,7 +1,6 @@ #pragma once #include -#include #if !RN_AUDIO_API_TEST #include @@ -13,26 +12,30 @@ struct JsiBuffer {}; namespace audioapi { -class AudioArrayBuffer : public JsiBuffer, public AudioArray { +template +class AlignedAudioArrayBuffer : public JsiBuffer, public AlignedAudioArray { public: - explicit AudioArrayBuffer(size_t size) : AudioArray(size) {}; - AudioArrayBuffer(const float *data, size_t size) : AudioArray(data, size) {}; + 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 size_ * sizeof(float); + return this->size_ * sizeof(float); } uint8_t *data() override { - return reinterpret_cast(data_.data()); + return reinterpret_cast(this->data_.data()); } #else [[nodiscard]] size_t size() const { - return size_ * sizeof(float); + return this->size_ * sizeof(float); } uint8_t *data() { - return reinterpret_cast(data_.data()); + return reinterpret_cast(this->data_.data()); } #endif }; +using AudioArrayBuffer = AlignedAudioArrayBuffer; + } // namespace audioapi diff --git a/packages/react-native-audio-api/common/cpp/audioapi/utils/AudioBuffer.cpp b/packages/react-native-audio-api/common/cpp/audioapi/utils/AudioBuffer.cpp deleted file mode 100644 index e310534ad..000000000 --- a/packages/react-native-audio-api/common/cpp/audioapi/utils/AudioBuffer.cpp +++ /dev/null @@ -1,381 +0,0 @@ -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -namespace audioapi { - -const float SQRT_HALF = sqrtf(0.5f); -constexpr int BLOCK_SIZE = 64; - -AudioBuffer::AudioBuffer(size_t size, int numberOfChannels, float sampleRate) - : numberOfChannels_(numberOfChannels), sampleRate_(sampleRate), size_(size) { - channels_.reserve(numberOfChannels_); - for (size_t i = 0; i < numberOfChannels_; ++i) { - channels_.emplace_back(std::make_shared(size_)); - } -} - -AudioBuffer::AudioBuffer(const AudioBuffer &other) - : numberOfChannels_(other.numberOfChannels_), - sampleRate_(other.sampleRate_), - size_(other.size_) { - channels_.reserve(numberOfChannels_); - for (const auto &channel : other.channels_) { - channels_.emplace_back(std::make_shared(*channel)); - } -} - -AudioBuffer::AudioBuffer(audioapi::AudioBuffer &&other) noexcept - : channels_(std::move(other.channels_)), - numberOfChannels_(std::exchange(other.numberOfChannels_, 0)), - sampleRate_(std::exchange(other.sampleRate_, 0.0f)), - size_(std::exchange(other.size_, 0)) {} - -AudioBuffer &AudioBuffer::operator=(const AudioBuffer &other) { - if (this != &other) { - sampleRate_ = other.sampleRate_; - - if (numberOfChannels_ != other.numberOfChannels_) { - numberOfChannels_ = other.numberOfChannels_; - size_ = other.size_; - channels_.clear(); - channels_.reserve(numberOfChannels_); - - for (const auto &channel : other.channels_) { - channels_.emplace_back(std::make_shared(*channel)); - } - - return *this; - } - - if (size_ != other.size_) { - size_ = other.size_; - } - - for (size_t i = 0; i < numberOfChannels_; ++i) { - *channels_[i] = *other.channels_[i]; - } - } - - return *this; -} - -AudioBuffer &AudioBuffer::operator=(audioapi::AudioBuffer &&other) noexcept { - if (this != &other) { - channels_ = std::move(other.channels_); - - numberOfChannels_ = std::exchange(other.numberOfChannels_, 0); - sampleRate_ = std::exchange(other.sampleRate_, 0.0f); - size_ = std::exchange(other.size_, 0); - } - return *this; -} - -AudioArray *AudioBuffer::getChannel(size_t index) const { - return channels_[index].get(); -} - -AudioArray *AudioBuffer::getChannelByType(int channelType) const { - auto it = kChannelLayouts.find(getNumberOfChannels()); - if (it == kChannelLayouts.end()) { - return nullptr; - } - const auto &channelOrder = it->second; - for (size_t i = 0; i < channelOrder.size(); ++i) { - if (channelOrder[i] == channelType) { - return getChannel(i); - } - } - - return nullptr; -} - -std::shared_ptr AudioBuffer::getSharedChannel(size_t index) const { - return channels_[index]; -} - -void AudioBuffer::zero() { - zero(0, getSize()); -} - -void AudioBuffer::zero(size_t start, size_t length) { - for (auto it = channels_.begin(); it != channels_.end(); it += 1) { - it->get()->zero(start, length); - } -} - -void AudioBuffer::sum(const AudioBuffer &source, ChannelInterpretation interpretation) { - sum(source, 0, 0, getSize(), interpretation); -} - -void AudioBuffer::sum( - const AudioBuffer &source, - size_t sourceStart, - size_t destinationStart, - size_t length, - ChannelInterpretation interpretation) { - if (&source == this) { - return; - } - - auto numberOfSourceChannels = source.getNumberOfChannels(); - auto numberOfChannels = getNumberOfChannels(); - - if (interpretation == ChannelInterpretation::DISCRETE) { - discreteSum(source, sourceStart, destinationStart, length); - return; - } - - // Source channel count is smaller than current buffer, we need to up-mix. - if (numberOfSourceChannels < numberOfChannels) { - sumByUpMixing(source, sourceStart, destinationStart, length); - return; - } - - // Source channel count is larger than current buffer, we need to down-mix. - if (numberOfSourceChannels > numberOfChannels) { - sumByDownMixing(source, sourceStart, destinationStart, length); - return; - } - - // Source and destination channel counts are the same. Just sum the channels. - for (size_t i = 0; i < getNumberOfChannels(); ++i) { - channels_[i]->sum(*source.channels_[i], sourceStart, destinationStart, length); - } -} - -void AudioBuffer::copy(const AudioBuffer &source) { - copy(source, 0, 0, getSize()); -} - -void AudioBuffer::copy( - const AudioBuffer &source, - size_t sourceStart, - size_t destinationStart, - size_t length) { - if (&source == this) { - return; - } - - if (source.getNumberOfChannels() == getNumberOfChannels()) { - for (size_t i = 0; i < getNumberOfChannels(); ++i) { - channels_[i]->copy(*source.channels_[i], sourceStart, destinationStart, length); - } - - return; - } - - // zero + sum is equivalent to copy, but takes care of up/down-mixing. - zero(destinationStart, length); - sum(source, sourceStart, destinationStart, length); -} - -void AudioBuffer::deinterleaveFrom(const float *source, size_t frames) { - if (frames == 0) { - return; - } - - if (numberOfChannels_ == 1) { - channels_[0]->copy(source, 0, 0, frames); - return; - } - - if (numberOfChannels_ == 2) { - dsp::deinterleaveStereo(source, channels_[0]->begin(), channels_[1]->begin(), frames); - return; - } - - float *channelsPtrs[MAX_CHANNEL_COUNT]; - for (size_t i = 0; i < numberOfChannels_; ++i) { - channelsPtrs[i] = channels_[i]->begin(); - } - - for (size_t blockStart = 0; blockStart < frames; blockStart += BLOCK_SIZE) { - size_t blockEnd = std::min(blockStart + BLOCK_SIZE, frames); - for (size_t i = blockStart; i < blockEnd; ++i) { - const float *frameSource = source + (i * numberOfChannels_); - for (size_t ch = 0; ch < numberOfChannels_; ++ch) { - channelsPtrs[ch][i] = frameSource[ch]; - } - } - } -} - -void AudioBuffer::interleaveTo(float *destination, size_t frames) const { - if (frames == 0) { - return; - } - - if (numberOfChannels_ == 1) { - channels_[0]->copyTo(destination, 0, 0, frames); - return; - } - - if (numberOfChannels_ == 2) { - dsp::interleaveStereo(channels_[0]->begin(), channels_[1]->begin(), destination, frames); - return; - } - - float *channelsPtrs[MAX_CHANNEL_COUNT]; - for (size_t i = 0; i < numberOfChannels_; ++i) { - channelsPtrs[i] = channels_[i]->begin(); - } - - for (size_t blockStart = 0; blockStart < frames; blockStart += BLOCK_SIZE) { - size_t blockEnd = std::min(blockStart + BLOCK_SIZE, frames); - for (size_t i = blockStart; i < blockEnd; ++i) { - float *frameDest = destination + (i * numberOfChannels_); - for (size_t ch = 0; ch < numberOfChannels_; ++ch) { - frameDest[ch] = channelsPtrs[ch][i]; - } - } - } -} - -void AudioBuffer::normalize() { - float maxAbsValue = this->maxAbsValue(); - - if (maxAbsValue == 0.0f || maxAbsValue == 1.0f) { - return; - } - - float scale = 1.0f / maxAbsValue; - this->scale(scale); -} - -void AudioBuffer::scale(float value) { - for (auto &channel : channels_) { - channel->scale(value); - } -} - -float AudioBuffer::maxAbsValue() const { - float maxAbsValue = 1.0f; - - for (const auto &channel : channels_) { - float channelMaxAbsValue = channel->getMaxAbsValue(); - maxAbsValue = std::max(maxAbsValue, channelMaxAbsValue); - } - - return maxAbsValue; -} - -/** - * Internal tooling - channel initialization - */ - -void AudioBuffer::discreteSum( - const AudioBuffer &source, - size_t sourceStart, - size_t destinationStart, - size_t length) const { - auto numberOfChannels = std::min(getNumberOfChannels(), source.getNumberOfChannels()); - - // In case of source > destination, we "down-mix" and drop the extra channels. - // In case of source < destination, we "up-mix" as many channels as we have, - // leaving the remaining channels untouched. - for (size_t i = 0; i < numberOfChannels; i++) { - channels_[i]->sum(*source.channels_[i], sourceStart, destinationStart, length); - } -} - -void AudioBuffer::sumByUpMixing( - const AudioBuffer &source, - size_t sourceStart, - size_t destinationStart, - size_t length) { - auto numberOfSourceChannels = source.getNumberOfChannels(); - auto numberOfChannels = getNumberOfChannels(); - - auto mix = [&](int srcType, int dstType) { - getChannelByType(dstType)->sum( - *source.getChannelByType(srcType), sourceStart, destinationStart, length); - }; - - // Mono to stereo (1 -> 2, 4) - if (numberOfSourceChannels == 1 && (numberOfChannels == 2 || numberOfChannels == 4)) { - mix(ChannelMono, ChannelLeft); - mix(ChannelMono, ChannelRight); - // Mono to 5.1 (1 -> 6) - } else if (numberOfSourceChannels == 1 && numberOfChannels == 6) { - mix(ChannelMono, ChannelCenter); - // Stereo 2 to stereo 4 or 5.1 (2 -> 4, 6) - } else if (numberOfSourceChannels == 2 && (numberOfChannels == 4 || numberOfChannels == 6)) { - mix(ChannelLeft, ChannelLeft); - mix(ChannelRight, ChannelRight); - // Stereo 4 to 5.1 (4 -> 6) - } else if (numberOfSourceChannels == 4 && numberOfChannels == 6) { - mix(ChannelLeft, ChannelLeft); - mix(ChannelRight, ChannelRight); - mix(ChannelSurroundLeft, ChannelSurroundLeft); - mix(ChannelSurroundRight, ChannelSurroundRight); - } else { - discreteSum(source, sourceStart, destinationStart, length); - } -} - -void AudioBuffer::sumByDownMixing( - const AudioBuffer &source, - size_t sourceStart, - size_t destinationStart, - size_t length) { - auto numberOfSourceChannels = source.getNumberOfChannels(); - auto numberOfChannels = getNumberOfChannels(); - - auto mix = [&](int srcType, int dstType, float scale = 1.0f) { - getChannelByType(dstType)->sum( - *source.getChannelByType(srcType), sourceStart, destinationStart, length, scale); - }; - - // Stereo to mono (2 -> 1): output += 0.5 * (input.L + input.R) - if (numberOfSourceChannels == 2 && numberOfChannels == 1) { - mix(ChannelLeft, ChannelMono, 0.5f); - mix(ChannelRight, ChannelMono, 0.5f); - // Stereo 4 to mono (4 -> 1): output += 0.25 * (input.L + input.R + input.SL + input.SR) - } else if (numberOfSourceChannels == 4 && numberOfChannels == 1) { - mix(ChannelLeft, ChannelMono, 0.25f); - mix(ChannelRight, ChannelMono, 0.25f); - mix(ChannelSurroundLeft, ChannelMono, 0.25f); - mix(ChannelSurroundRight, ChannelMono, 0.25f); - // 5.1 to mono (6 -> 1): output += sqrt(0.5)*(L+R) + C + 0.5*(SL+SR) - } else if (numberOfSourceChannels == 6 && numberOfChannels == 1) { - mix(ChannelLeft, ChannelMono, SQRT_HALF); - mix(ChannelRight, ChannelMono, SQRT_HALF); - mix(ChannelCenter, ChannelMono); - mix(ChannelSurroundLeft, ChannelMono, 0.5f); - mix(ChannelSurroundRight, ChannelMono, 0.5f); - // Stereo 4 to stereo 2 (4 -> 2): L += 0.5*(L+SL), R += 0.5*(R+SR) - } else if (numberOfSourceChannels == 4 && numberOfChannels == 2) { - mix(ChannelLeft, ChannelLeft, 0.5f); - mix(ChannelSurroundLeft, ChannelLeft, 0.5f); - mix(ChannelRight, ChannelRight, 0.5f); - mix(ChannelSurroundRight, ChannelRight, 0.5f); - // 5.1 to stereo (6 -> 2): L += L + sqrt(0.5)*(C+SL), R += R + sqrt(0.5)*(C+SR) - } else if (numberOfSourceChannels == 6 && numberOfChannels == 2) { - mix(ChannelLeft, ChannelLeft); - mix(ChannelCenter, ChannelLeft, SQRT_HALF); - mix(ChannelSurroundLeft, ChannelLeft, SQRT_HALF); - mix(ChannelRight, ChannelRight); - mix(ChannelCenter, ChannelRight, SQRT_HALF); - mix(ChannelSurroundRight, ChannelRight, SQRT_HALF); - // 5.1 to stereo 4 (6 -> 4): L += L + sqrt(0.5)*C, R += R + sqrt(0.5)*C, SL += SL, SR += SR - } else if (numberOfSourceChannels == 6 && numberOfChannels == 4) { - mix(ChannelLeft, ChannelLeft); - mix(ChannelCenter, ChannelLeft, SQRT_HALF); - mix(ChannelRight, ChannelRight); - mix(ChannelCenter, ChannelRight, SQRT_HALF); - mix(ChannelSurroundLeft, ChannelSurroundLeft); - mix(ChannelSurroundRight, ChannelSurroundRight); - } else { - discreteSum(source, sourceStart, destinationStart, length); - } -} - -} // namespace audioapi diff --git a/packages/react-native-audio-api/common/cpp/audioapi/utils/AudioBuffer.h b/packages/react-native-audio-api/common/cpp/audioapi/utils/AudioBuffer.h deleted file mode 100644 index 3694e859b..000000000 --- a/packages/react-native-audio-api/common/cpp/audioapi/utils/AudioBuffer.h +++ /dev/null @@ -1,180 +0,0 @@ -#pragma once - -#include -#include -#include - -#include -#include -#include -#include - -namespace audioapi { - -class AudioArrayBuffer; - -class AudioBuffer { - public: - enum { - ChannelMono = 0, - ChannelLeft = 0, - ChannelRight = 1, - ChannelCenter = 2, - ChannelLFE = 3, - ChannelSurroundLeft = 4, - ChannelSurroundRight = 5, - }; - - explicit AudioBuffer() = default; - explicit AudioBuffer(size_t size, int numberOfChannels, float sampleRate); - AudioBuffer(const AudioBuffer &other); - AudioBuffer(AudioBuffer &&other) noexcept; - AudioBuffer &operator=(const AudioBuffer &other); - AudioBuffer &operator=(AudioBuffer &&other) noexcept; - ~AudioBuffer() = default; - - [[nodiscard]] size_t getNumberOfChannels() const noexcept { - return numberOfChannels_; - } - [[nodiscard]] float getSampleRate() const noexcept { - return sampleRate_; - } - [[nodiscard]] size_t getSize() const noexcept { - return size_; - } - - [[nodiscard]] double getDuration() const noexcept { - return static_cast(size_) / static_cast(getSampleRate()); - } - - /// @brief Get the AudioArray for a specific channel index. - /// @param index The channel index. - /// @return Pointer to the AudioArray for the specified channel - not owning. - [[nodiscard]] AudioArray *getChannel(size_t index) const; - - /// @brief Get the AudioArray for a specific channel type. - /// @param channelType The channel type: ChannelMono = 0, ChannelLeft = 0, - /// ChannelRight = 1, ChannelCenter = 2, ChannelLFE = 3, - /// ChannelSurroundLeft = 4, ChannelSurroundRight = 5 - /// @return Pointer to the AudioArray for the specified channel type - not owning. - [[nodiscard]] AudioArray *getChannelByType(int channelType) const; - - /// @brief Get a copy of shared pointer to the AudioArray for a specific channel index. - /// @param index The channel index. - /// @return Copy of shared pointer to the AudioArray for the specified channel - [[nodiscard]] std::shared_ptr getSharedChannel(size_t index) const; - - AudioArray &operator[](size_t index) { - return *channels_[index]; - } - const AudioArray &operator[](size_t index) const { - return *channels_[index]; - } - - void zero(); - void zero(size_t start, size_t length); - - /// @brief Sums audio data from a source AudioBuffer into this AudioBuffer. - /// @param source The source AudioBuffer to sum from. - /// @param interpretation The channel interpretation to use for summing (default is SPEAKERS). - /// @note Handles up-mixing and down-mixing based on the number of channels in both buffers. - /// Assumes that source and this are located in two distinct, non-overlapping memory locations. - void sum( - const AudioBuffer &source, - ChannelInterpretation interpretation = ChannelInterpretation::SPEAKERS); - - /// @brief Sums audio data from a source AudioBuffer into this AudioBuffer. - /// @param source The source AudioBuffer to sum from. - /// @param sourceStart The starting index in the source AudioBuffer. - /// @param destinationStart The starting index in this AudioBuffer. - /// @param length The number of samples to sum. - /// @param interpretation The channel interpretation to use for summing (default is SPEAKERS). - /// @note Handles up-mixing and down-mixing based on the number of channels in both buffers. - /// Assumes that source and this are located in two distinct, non-overlapping memory locations. - void sum( - const AudioBuffer &source, - size_t sourceStart, - size_t destinationStart, - size_t length, - ChannelInterpretation interpretation = ChannelInterpretation::SPEAKERS); - - /// @brief Copies audio data from a source AudioBuffer into this AudioBuffer. - /// @param source The source AudioBuffer to copy from. - /// @note Handles up-mixing and down-mixing based on the number of channels in both buffers. - /// Assumes that source and this are located in two distinct, non-overlapping memory locations. - void copy(const AudioBuffer &source); // NOLINT(build/include_what_you_use) - - /// @brief Copies audio data from a source AudioBuffer into this AudioBuffer. - /// @param source The source AudioBuffer to copy from. - /// @param sourceStart The starting index in the source AudioBuffer. - /// @param destinationStart The starting index in this AudioBuffer. - /// @param length The number of samples to copy. - /// @note Handles up-mixing and down-mixing based on the number of channels in both buffers. - /// Assumes that source and this are located in two distinct, non-overlapping memory locations. - void copy( - const AudioBuffer &source, - size_t sourceStart, - size_t destinationStart, - size_t length); // NOLINT(build/include_what_you_use) - - /// @brief Deinterleave audio data from a source buffer into this AudioBuffer. - /// @param source Pointer to the source buffer containing interleaved audio data. - /// @param frames Number of frames to deinterleave from the source buffer. - /// @note The source buffer should contain interleaved audio data according to the number of channels in this AudioBuffer. - /// Example of interleaved data for stereo (2 channels): - /// [L0, R0, L1, R1, L2, R2, ...] - /// Assumes that source and this are located in two distinct, non-overlapping memory locations. - void deinterleaveFrom(const float *source, size_t frames); - - /// @brief Interleave audio data from this AudioBuffer into a destination buffer. - /// @param destination Pointer to the destination buffer where interleaved audio data will be written. - /// @param frames Number of frames to interleave into the destination buffer. - /// @note The destination buffer should have enough space to hold the interleaved data - /// according to the number of channels in this AudioBuffer. - /// Example of interleaved data for stereo (2 channels): - /// [L0, R0, L1, R1, L2, R2, ...] - /// Assumes that this and destination are located in two distinct, non-overlapping memory locations. - void interleaveTo(float *destination, size_t frames) const; - - void normalize(); - void scale(float value); - [[nodiscard]] float maxAbsValue() const; - - private: - std::vector> channels_; - - size_t numberOfChannels_ = 0; - float sampleRate_ = 0.0f; - size_t size_ = 0; - - inline static const std::unordered_map> kChannelLayouts = { - {1, {ChannelMono}}, - {2, {ChannelLeft, ChannelRight}}, - {4, {ChannelLeft, ChannelRight, ChannelSurroundLeft, ChannelSurroundRight}}, - {5, {ChannelLeft, ChannelRight, ChannelCenter, ChannelSurroundLeft, ChannelSurroundRight}}, - {6, - {ChannelLeft, - ChannelRight, - ChannelCenter, - ChannelLFE, - ChannelSurroundLeft, - ChannelSurroundRight}}}; - - void discreteSum( - const AudioBuffer &source, - size_t sourceStart, - size_t destinationStart, - size_t length) const; - void sumByUpMixing( - const AudioBuffer &source, - size_t sourceStart, - size_t destinationStart, - size_t length); - void sumByDownMixing( - const AudioBuffer &source, - size_t sourceStart, - size_t destinationStart, - size_t length); -}; - -} // namespace audioapi 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 new file mode 100644 index 000000000..22ac2d889 --- /dev/null +++ b/packages/react-native-audio-api/common/cpp/audioapi/utils/AudioBuffer.hpp @@ -0,0 +1,443 @@ +#pragma once + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +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 +class AlignedAudioBuffer { + public: + enum { + ChannelMono = 0, + ChannelLeft = 0, + ChannelRight = 1, + ChannelCenter = 2, + ChannelLFE = 3, + ChannelSurroundLeft = 4, + ChannelSurroundRight = 5, + }; + + explicit AlignedAudioBuffer() = default; + + explicit AlignedAudioBuffer(size_t size, int numberOfChannels, float sampleRate) + : numberOfChannels_(numberOfChannels), sampleRate_(sampleRate), size_(size) { + channels_.reserve(numberOfChannels_); + for (size_t i = 0; i < numberOfChannels_; ++i) { + channels_.emplace_back(std::make_shared>(size_)); + } + } + + AlignedAudioBuffer(const AlignedAudioBuffer &other) + : numberOfChannels_(other.numberOfChannels_), + sampleRate_(other.sampleRate_), + size_(other.size_) { + channels_.reserve(numberOfChannels_); + for (const auto &channel : other.channels_) { + channels_.emplace_back(std::make_shared>(*channel)); + } + } + + AlignedAudioBuffer(AlignedAudioBuffer &&other) noexcept + : channels_(std::move(other.channels_)), + numberOfChannels_(std::exchange(other.numberOfChannels_, 0)), + sampleRate_(std::exchange(other.sampleRate_, 0.0f)), + size_(std::exchange(other.size_, 0)) {} + + AlignedAudioBuffer &operator=(const AlignedAudioBuffer &other) { + if (this != &other) { + sampleRate_ = other.sampleRate_; + + if (numberOfChannels_ != other.numberOfChannels_) { + numberOfChannels_ = other.numberOfChannels_; + size_ = other.size_; + channels_.clear(); + channels_.reserve(numberOfChannels_); + + for (const auto &channel : other.channels_) { + channels_.emplace_back(std::make_shared>(*channel)); + } + + return *this; + } + + if (size_ != other.size_) { + size_ = other.size_; + } + + for (size_t i = 0; i < numberOfChannels_; ++i) { + *channels_[i] = *other.channels_[i]; + } + } + + return *this; + } + + AlignedAudioBuffer &operator=(AlignedAudioBuffer &&other) noexcept { + if (this != &other) { + channels_ = std::move(other.channels_); + numberOfChannels_ = std::exchange(other.numberOfChannels_, 0); + sampleRate_ = std::exchange(other.sampleRate_, 0.0f); + size_ = std::exchange(other.size_, 0); + } + return *this; + } + + ~AlignedAudioBuffer() = default; + + [[nodiscard]] size_t getNumberOfChannels() const noexcept { + return numberOfChannels_; + } + [[nodiscard]] float getSampleRate() const noexcept { + return sampleRate_; + } + [[nodiscard]] size_t getSize() const noexcept { + return size_; + } + [[nodiscard]] double getDuration() const noexcept { + return static_cast(size_) / static_cast(getSampleRate()); + } + + /// @brief Get the channel array for a specific channel index. + /// @return Pointer to the AlignedAudioArray for the specified channel - not owning. + [[nodiscard]] AlignedAudioArray *getChannel(size_t index) const { + return channels_[index].get(); + } + + /// @brief Get the channel array for a specific channel type. + /// @return Pointer to the AlignedAudioArray for the specified channel type - not owning. + [[nodiscard]] AlignedAudioArray *getChannelByType(int channelType) const { + auto it = kChannelLayouts.find(getNumberOfChannels()); + if (it == kChannelLayouts.end()) { + return nullptr; + } + const auto &channelOrder = it->second; + for (size_t i = 0; i < channelOrder.size(); ++i) { + if (channelOrder[i] == channelType) { + return getChannel(i); + } + } + return nullptr; + } + + /// @brief Get a copy of shared pointer to the channel buffer for a specific index. + [[nodiscard]] std::shared_ptr> getSharedChannel( + size_t index) const { + return channels_[index]; + } + + AlignedAudioArray &operator[](size_t index) { + return *channels_[index]; + } + const AlignedAudioArray &operator[](size_t index) const { + return *channels_[index]; + } + + void zero() { + zero(0, getSize()); + } + + void zero(size_t start, size_t length) { + for (auto it = channels_.begin(); it != channels_.end(); it += 1) { + it->get()->zero(start, length); + } + } + + /// @brief Sums audio data from a source buffer into this buffer. + /// @note Handles up-mixing and down-mixing based on channel counts. + void sum( + const AlignedAudioBuffer &source, + ChannelInterpretation interpretation = ChannelInterpretation::SPEAKERS) { + sum(source, 0, 0, getSize(), interpretation); + } + + void sum( + const AlignedAudioBuffer &source, + size_t sourceStart, + size_t destinationStart, + size_t length, + ChannelInterpretation interpretation = ChannelInterpretation::SPEAKERS) { + if (&source == this) { + return; + } + + auto numberOfSourceChannels = source.getNumberOfChannels(); + auto numberOfChannels = getNumberOfChannels(); + + if (interpretation == ChannelInterpretation::DISCRETE) { + discreteSum(source, sourceStart, destinationStart, length); + return; + } + + if (numberOfSourceChannels < numberOfChannels) { + sumByUpMixing(source, sourceStart, destinationStart, length); + return; + } + + if (numberOfSourceChannels > numberOfChannels) { + sumByDownMixing(source, sourceStart, destinationStart, length); + return; + } + + for (size_t i = 0; i < getNumberOfChannels(); ++i) { + channels_[i]->sum(*source.channels_[i], sourceStart, destinationStart, length); + } + } + + /// @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) + copy(source, 0, 0, getSize()); + } + + void copy( + const AlignedAudioBuffer &source, + size_t sourceStart, + size_t destinationStart, + size_t length) { // NOLINT(build/include_what_you_use) + if (&source == this) { + return; + } + + if (source.getNumberOfChannels() == getNumberOfChannels()) { + for (size_t i = 0; i < getNumberOfChannels(); ++i) { + channels_[i]->copy(*source.channels_[i], sourceStart, destinationStart, length); + } + return; + } + + // zero + sum is equivalent to copy, but takes care of up/down-mixing. + zero(destinationStart, length); + sum(source, sourceStart, destinationStart, length); + } + + /// @brief Deinterleave audio data from an interleaved source buffer. + void deinterleaveFrom(const float *source, size_t frames) { + if (frames == 0) { + return; + } + + if (numberOfChannels_ == 1) { + channels_[0]->copy(source, 0, 0, frames); + return; + } + + if (numberOfChannels_ == 2) { + dsp::deinterleaveStereo(source, channels_[0]->begin(), channels_[1]->begin(), frames); + return; + } + + float *channelsPtrs[MAX_CHANNEL_COUNT]; + for (size_t i = 0; i < numberOfChannels_; ++i) { + channelsPtrs[i] = channels_[i]->begin(); + } + + for (size_t blockStart = 0; blockStart < frames; blockStart += kBlockSize) { + size_t blockEnd = std::min(blockStart + kBlockSize, frames); + for (size_t i = blockStart; i < blockEnd; ++i) { + const float *frameSource = source + (i * numberOfChannels_); + for (size_t ch = 0; ch < numberOfChannels_; ++ch) { + channelsPtrs[ch][i] = frameSource[ch]; + } + } + } + } + + /// @brief Interleave audio data from this buffer into a destination buffer. + void interleaveTo(float *destination, size_t frames) const { + if (frames == 0) { + return; + } + + if (numberOfChannels_ == 1) { + channels_[0]->copyTo(destination, 0, 0, frames); + return; + } + + if (numberOfChannels_ == 2) { + dsp::interleaveStereo(channels_[0]->begin(), channels_[1]->begin(), destination, frames); + return; + } + + float *channelsPtrs[MAX_CHANNEL_COUNT]; + for (size_t i = 0; i < numberOfChannels_; ++i) { + channelsPtrs[i] = channels_[i]->begin(); + } + + for (size_t blockStart = 0; blockStart < frames; blockStart += kBlockSize) { + size_t blockEnd = std::min(blockStart + kBlockSize, frames); + for (size_t i = blockStart; i < blockEnd; ++i) { + float *frameDest = destination + (i * numberOfChannels_); + for (size_t ch = 0; ch < numberOfChannels_; ++ch) { + frameDest[ch] = channelsPtrs[ch][i]; + } + } + } + } + + void normalize() { + float maxAbs = maxAbsValue(); + if (maxAbs == 0.0f || maxAbs == 1.0f) { + return; + } + scale(1.0f / maxAbs); + } + + void scale(float value) { + for (auto &channel : channels_) { + channel->scale(value); + } + } + + [[nodiscard]] float maxAbsValue() const { + float maxAbs = 1.0f; + for (const auto &channel : channels_) { + maxAbs = std::max(maxAbs, channel->getMaxAbsValue()); + } + return maxAbs; + } + + private: + std::vector>> channels_; + + size_t numberOfChannels_ = 0; + float sampleRate_ = 0.0f; + size_t size_ = 0; + + static constexpr float kSqrtHalf = 0.7071067811865476f; // sqrtf(0.5f) + static constexpr int kBlockSize = 64; + + inline static const std::unordered_map> kChannelLayouts = { + {1, {ChannelMono}}, + {2, {ChannelLeft, ChannelRight}}, + {4, {ChannelLeft, ChannelRight, ChannelSurroundLeft, ChannelSurroundRight}}, + {5, {ChannelLeft, ChannelRight, ChannelCenter, ChannelSurroundLeft, ChannelSurroundRight}}, + {6, + {ChannelLeft, + ChannelRight, + ChannelCenter, + ChannelLFE, + ChannelSurroundLeft, + ChannelSurroundRight}}}; + + void discreteSum( + 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); + } + } + + void sumByUpMixing( + const AlignedAudioBuffer &source, + size_t sourceStart, + size_t destinationStart, + size_t length) { + auto numberOfSourceChannels = source.getNumberOfChannels(); + auto numberOfChannels = getNumberOfChannels(); + + auto mix = [&](int srcType, int dstType) { + getChannelByType(dstType)->sum( + *source.getChannelByType(srcType), sourceStart, destinationStart, length); + }; + + // Mono to stereo (1 -> 2, 4) + if (numberOfSourceChannels == 1 && (numberOfChannels == 2 || numberOfChannels == 4)) { + mix(ChannelMono, ChannelLeft); + mix(ChannelMono, ChannelRight); + } else if (numberOfSourceChannels == 1 && numberOfChannels == 6) { + // Mono to 5.1 (1 -> 6) + mix(ChannelMono, ChannelCenter); + } else if (numberOfSourceChannels == 2 && (numberOfChannels == 4 || numberOfChannels == 6)) { + // Stereo to 4 or 5.1 (2 -> 4, 6) + mix(ChannelLeft, ChannelLeft); + mix(ChannelRight, ChannelRight); + } else if (numberOfSourceChannels == 4 && numberOfChannels == 6) { + // Stereo 4 to 5.1 (4 -> 6) + mix(ChannelLeft, ChannelLeft); + mix(ChannelRight, ChannelRight); + mix(ChannelSurroundLeft, ChannelSurroundLeft); + mix(ChannelSurroundRight, ChannelSurroundRight); + } else { + discreteSum(source, sourceStart, destinationStart, length); + } + } + + void sumByDownMixing( + const AlignedAudioBuffer &source, + size_t sourceStart, + size_t destinationStart, + size_t length) { + auto numberOfSourceChannels = source.getNumberOfChannels(); + auto numberOfChannels = getNumberOfChannels(); + + auto mix = [&](int srcType, int dstType, float gain = 1.0f) { + getChannelByType(dstType)->sum( + *source.getChannelByType(srcType), sourceStart, destinationStart, length, gain); + }; + + // Stereo to mono (2 -> 1): output += 0.5 * (input.L + input.R) + if (numberOfSourceChannels == 2 && numberOfChannels == 1) { + mix(ChannelLeft, ChannelMono, 0.5f); + mix(ChannelRight, ChannelMono, 0.5f); + } else if (numberOfSourceChannels == 4 && numberOfChannels == 1) { + // Stereo 4 to mono (4 -> 1): output += 0.25 * (L + R + SL + SR) + mix(ChannelLeft, ChannelMono, 0.25f); + mix(ChannelRight, ChannelMono, 0.25f); + mix(ChannelSurroundLeft, ChannelMono, 0.25f); + mix(ChannelSurroundRight, ChannelMono, 0.25f); + } else if (numberOfSourceChannels == 6 && numberOfChannels == 1) { + // 5.1 to mono (6 -> 1): output += sqrt(0.5)*(L+R) + C + 0.5*(SL+SR) + mix(ChannelLeft, ChannelMono, kSqrtHalf); + mix(ChannelRight, ChannelMono, kSqrtHalf); + mix(ChannelCenter, ChannelMono); + mix(ChannelSurroundLeft, ChannelMono, 0.5f); + mix(ChannelSurroundRight, ChannelMono, 0.5f); + } else if (numberOfSourceChannels == 4 && numberOfChannels == 2) { + // Stereo 4 to stereo 2 (4 -> 2): L += 0.5*(L+SL), R += 0.5*(R+SR) + mix(ChannelLeft, ChannelLeft, 0.5f); + mix(ChannelSurroundLeft, ChannelLeft, 0.5f); + mix(ChannelRight, ChannelRight, 0.5f); + mix(ChannelSurroundRight, ChannelRight, 0.5f); + } else if (numberOfSourceChannels == 6 && numberOfChannels == 2) { + // 5.1 to stereo (6 -> 2): L += L + sqrt(0.5)*(C+SL), R += R + sqrt(0.5)*(C+SR) + mix(ChannelLeft, ChannelLeft); + mix(ChannelCenter, ChannelLeft, kSqrtHalf); + mix(ChannelSurroundLeft, ChannelLeft, kSqrtHalf); + mix(ChannelRight, ChannelRight); + mix(ChannelCenter, ChannelRight, kSqrtHalf); + mix(ChannelSurroundRight, ChannelRight, kSqrtHalf); + } else if (numberOfSourceChannels == 6 && numberOfChannels == 4) { + // 5.1 to stereo 4 (6 -> 4): L += L + sqrt(0.5)*C, R += R + sqrt(0.5)*C, SL += SL, SR += SR + mix(ChannelLeft, ChannelLeft); + mix(ChannelCenter, ChannelLeft, kSqrtHalf); + mix(ChannelRight, ChannelRight); + mix(ChannelCenter, ChannelRight, kSqrtHalf); + mix(ChannelSurroundLeft, ChannelSurroundLeft); + mix(ChannelSurroundRight, ChannelSurroundRight); + } else { + discreteSum(source, sourceStart, destinationStart, length); + } + } +}; + +using AudioBuffer = AlignedAudioBuffer; +using DSPAudioBuffer = AlignedAudioBuffer<64>; + +} // namespace audioapi From 82c43e136e3e337500489a060a41aa21e17c3111 Mon Sep 17 00:00:00 2001 From: maciejmakowski2003 Date: Tue, 10 Mar 2026 16:48:55 +0100 Subject: [PATCH 4/6] refactor: renamed AudioBuffer.h to AudioBuffer.hpp and updated all includes accordingly --- packages/audiodocs/docs/guides/create-your-own-effect.mdx | 4 ++-- .../templates/basic/shared/MyProcessorNode.cpp | 1 - .../templates/basic/shared/MyProcessorNode.h | 3 ++- .../main/cpp/audioapi/android/core/AndroidAudioRecorder.cpp | 2 +- .../main/cpp/audioapi/android/core/AndroidAudioRecorder.h | 2 +- .../src/main/cpp/audioapi/android/core/AudioPlayer.cpp | 2 +- .../src/main/cpp/audioapi/android/core/AudioPlayer.h | 2 +- .../audioapi/android/core/utils/AndroidRecorderCallback.cpp | 2 +- .../audioapi/android/core/utils/AndroidRecorderCallback.h | 2 +- .../common/cpp/audioapi/AudioAPIModuleInstaller.h | 6 +++--- .../HostObjects/effects/ConvolverNodeHostObject.cpp | 2 +- .../audioapi/HostObjects/effects/ConvolverNodeHostObject.h | 2 +- .../audioapi/HostObjects/inputs/AudioRecorderHostObject.cpp | 2 +- .../audioapi/HostObjects/sources/AudioBufferHostObject.cpp | 1 - .../audioapi/HostObjects/sources/AudioBufferHostObject.h | 2 +- .../HostObjects/sources/AudioBufferSourceNodeHostObject.cpp | 2 +- .../HostObjects/sources/AudioBufferSourceNodeHostObject.h | 2 +- .../common/cpp/audioapi/core/AudioNode.cpp | 2 +- .../common/cpp/audioapi/core/AudioNode.h | 2 +- .../common/cpp/audioapi/core/AudioParam.h | 2 +- .../common/cpp/audioapi/core/BaseAudioContext.cpp | 1 - .../common/cpp/audioapi/core/BaseAudioContext.h | 3 +-- .../common/cpp/audioapi/core/OfflineAudioContext.cpp | 1 - .../common/cpp/audioapi/core/analysis/AnalyserNode.cpp | 2 +- .../common/cpp/audioapi/core/analysis/AnalyserNode.h | 2 +- .../cpp/audioapi/core/destinations/AudioDestinationNode.cpp | 2 +- .../cpp/audioapi/core/destinations/AudioDestinationNode.h | 2 +- .../common/cpp/audioapi/core/effects/BiquadFilterNode.cpp | 2 +- .../common/cpp/audioapi/core/effects/BiquadFilterNode.h | 2 +- .../common/cpp/audioapi/core/effects/ConvolverNode.cpp | 2 +- .../common/cpp/audioapi/core/effects/ConvolverNode.h | 3 +-- .../common/cpp/audioapi/core/effects/DelayNode.cpp | 2 +- .../common/cpp/audioapi/core/effects/DelayNode.h | 2 +- .../common/cpp/audioapi/core/effects/GainNode.cpp | 2 +- .../common/cpp/audioapi/core/effects/GainNode.h | 2 +- .../common/cpp/audioapi/core/effects/IIRFilterNode.cpp | 2 +- .../common/cpp/audioapi/core/effects/IIRFilterNode.h | 2 +- .../common/cpp/audioapi/core/effects/PeriodicWave.h | 2 +- .../common/cpp/audioapi/core/effects/StereoPannerNode.cpp | 2 +- .../common/cpp/audioapi/core/effects/StereoPannerNode.h | 2 +- .../common/cpp/audioapi/core/effects/WaveShaperNode.cpp | 2 +- .../common/cpp/audioapi/core/effects/WaveShaperNode.h | 2 +- .../common/cpp/audioapi/core/effects/WorkletNode.h | 2 +- .../cpp/audioapi/core/effects/WorkletProcessingNode.h | 2 +- .../common/cpp/audioapi/core/inputs/AudioRecorder.h | 2 +- .../cpp/audioapi/core/sources/AudioBufferBaseSourceNode.cpp | 2 +- .../cpp/audioapi/core/sources/AudioBufferBaseSourceNode.h | 4 +--- .../audioapi/core/sources/AudioBufferQueueSourceNode.cpp | 1 - .../cpp/audioapi/core/sources/AudioBufferQueueSourceNode.h | 4 +--- .../cpp/audioapi/core/sources/AudioBufferSourceNode.cpp | 2 +- .../cpp/audioapi/core/sources/AudioBufferSourceNode.h | 3 +-- .../cpp/audioapi/core/sources/AudioScheduledSourceNode.cpp | 1 - .../common/cpp/audioapi/core/sources/ConstantSourceNode.cpp | 2 +- .../common/cpp/audioapi/core/sources/ConstantSourceNode.h | 2 +- .../common/cpp/audioapi/core/sources/OscillatorNode.cpp | 2 +- .../common/cpp/audioapi/core/sources/OscillatorNode.h | 1 - .../cpp/audioapi/core/sources/RecorderAdapterNode.cpp | 1 - .../common/cpp/audioapi/core/sources/RecorderAdapterNode.h | 3 +-- .../common/cpp/audioapi/core/sources/StreamerNode.cpp | 2 +- .../common/cpp/audioapi/core/sources/StreamerNode.h | 3 +-- .../common/cpp/audioapi/core/sources/WorkletSourceNode.h | 2 +- .../common/cpp/audioapi/core/utils/AudioDecoder.cpp | 1 - .../common/cpp/audioapi/core/utils/AudioDecoder.h | 3 +-- .../common/cpp/audioapi/core/utils/AudioGraphManager.cpp | 2 +- .../common/cpp/audioapi/core/utils/AudioGraphManager.h | 2 +- .../cpp/audioapi/core/utils/AudioRecorderCallback.cpp | 2 +- .../common/cpp/audioapi/core/utils/AudioRecorderCallback.h | 2 +- .../common/cpp/audioapi/core/utils/AudioStretcher.cpp | 2 +- .../common/cpp/audioapi/core/utils/AudioStretcher.h | 3 +-- .../common/cpp/audioapi/dsp/Convolver.cpp | 2 +- .../common/cpp/audioapi/dsp/Convolver.h | 3 +-- .../common/cpp/audioapi/dsp/WaveShaper.cpp | 1 - .../common/cpp/audioapi/dsp/WaveShaper.h | 3 +-- .../common/cpp/audioapi/dsp/r8brain/Resampler.h | 2 +- .../common/cpp/audioapi/libs/ffmpeg/FFmpegDecoding.cpp | 2 -- .../common/cpp/audioapi/libs/ffmpeg/FFmpegDecoding.h | 2 +- .../common/cpp/audioapi/types/NodeOptions.h | 2 +- .../common/cpp/test/src/core/effects/DelayTest.cpp | 2 +- .../common/cpp/test/src/core/effects/GainTest.cpp | 2 +- .../common/cpp/test/src/core/effects/StereoPannerTest.cpp | 2 +- .../common/cpp/test/src/core/effects/WaveShaperNodeTest.cpp | 2 +- .../cpp/test/src/core/sources/AudioScheduledSourceTest.cpp | 2 +- .../common/cpp/test/src/core/sources/ConstantSourceTest.cpp | 2 +- .../common/cpp/test/src/utils/AudioBufferTest.cpp | 2 +- .../ios/audioapi/ios/core/IOSAudioPlayer.h | 2 +- .../ios/audioapi/ios/core/IOSAudioPlayer.mm | 2 +- .../ios/audioapi/ios/core/IOSAudioRecorder.mm | 2 +- .../ios/audioapi/ios/core/utils/IOSRecorderCallback.h | 3 +-- .../ios/audioapi/ios/core/utils/IOSRecorderCallback.mm | 2 +- 89 files changed, 82 insertions(+), 107 deletions(-) diff --git a/packages/audiodocs/docs/guides/create-your-own-effect.mdx b/packages/audiodocs/docs/guides/create-your-own-effect.mdx index 42a018888..4a7f73ead 100644 --- a/packages/audiodocs/docs/guides/create-your-own-effect.mdx +++ b/packages/audiodocs/docs/guides/create-your-own-effect.mdx @@ -43,9 +43,9 @@ For the sake of a simplicity, we will use value as a raw `double` type, not wrap ```cpp #pragma once #include +#include namespace audioapi { -class AudioBuffer; class MyProcessorNode : public AudioNode { public: @@ -70,7 +70,7 @@ private: ```cpp #include "MyProcessorNode.h" -#include +#include #include namespace audioapi { diff --git a/packages/custom-node-generator/templates/basic/shared/MyProcessorNode.cpp b/packages/custom-node-generator/templates/basic/shared/MyProcessorNode.cpp index 033597f6c..5d6baee0a 100644 --- a/packages/custom-node-generator/templates/basic/shared/MyProcessorNode.cpp +++ b/packages/custom-node-generator/templates/basic/shared/MyProcessorNode.cpp @@ -1,5 +1,4 @@ #include "MyProcessorNode.h" -#include namespace audioapi { MyProcessorNode::MyProcessorNode( diff --git a/packages/custom-node-generator/templates/basic/shared/MyProcessorNode.h b/packages/custom-node-generator/templates/basic/shared/MyProcessorNode.h index 250321092..c9880d678 100644 --- a/packages/custom-node-generator/templates/basic/shared/MyProcessorNode.h +++ b/packages/custom-node-generator/templates/basic/shared/MyProcessorNode.h @@ -1,8 +1,9 @@ #pragma once + #include +#include namespace audioapi { -class AudioBuffer; class MyProcessorNode : public AudioNode { public: 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 f2b2a0499..3721aafe0 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 1ea0d295a..01814f023 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 @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -10,7 +11,6 @@ namespace audioapi { -class AudioBuffer; class CircularAudioArray; class AudioFileProperties; class AndroidRecorderCallback; 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 1f04c29ae..31da2da45 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 @@ -3,7 +3,7 @@ #include #include #include -#include + #include #include 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 c453382a5..a24fcca38 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 @@ -6,13 +6,13 @@ #include #include +#include namespace audioapi { using namespace oboe; class AudioContext; -class AudioBuffer; class AudioPlayer : public AudioStreamDataCallback, AudioStreamErrorCallback { public: 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 2c51c7cba..208c950ce 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,7 +4,7 @@ #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 cc73fef07..c35945c0c 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 @@ -3,13 +3,13 @@ #include #include #include +#include #include #include #include namespace audioapi { -class AudioBuffer; class CircularAudioArray; class AudioEventHandlerRegistry; 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 221d90783..dc5cc6388 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/AudioAPIModuleInstaller.h +++ b/packages/react-native-audio-api/common/cpp/audioapi/AudioAPIModuleInstaller.h @@ -10,7 +10,7 @@ #include #include #include -#include +#include #include #include @@ -35,7 +35,7 @@ class AudioAPIModuleInstaller { getCreateAudioRecorderFunction(jsiRuntime, audioEventHandlerRegistry); auto createOfflineAudioContext = getCreateOfflineAudioContextFunction( jsiRuntime, jsCallInvoker, audioEventHandlerRegistry, uiRuntime); - auto createAudioBuffer = getCrateAudioBufferFunction(jsiRuntime); + auto createAudioBuffer = getCreateAudioBufferFunction(jsiRuntime); auto createAudioDecoder = getCreateAudioDecoderFunction(jsiRuntime, jsCallInvoker); auto createAudioStretcher = getCreateAudioStretcherFunction(jsiRuntime, jsCallInvoker); @@ -185,7 +185,7 @@ class AudioAPIModuleInstaller { }); } - static jsi::Function getCrateAudioBufferFunction(jsi::Runtime *jsiRuntime) { + static jsi::Function getCreateAudioBufferFunction(jsi::Runtime *jsiRuntime) { return jsi::Function::createFromHostFunction( *jsiRuntime, jsi::PropNameID::forAscii(*jsiRuntime, "createAudioStretcher"), 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 3811ac5f2..fa5e10432 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 @@ -6,7 +6,7 @@ #include #include #include -#include + #include #include diff --git a/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/effects/ConvolverNodeHostObject.h b/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/effects/ConvolverNodeHostObject.h index fc10c9cd1..bb46711c6 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/effects/ConvolverNodeHostObject.h +++ b/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/effects/ConvolverNodeHostObject.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include @@ -9,7 +10,6 @@ using namespace facebook; struct ConvolverOptions; class BaseAudioContext; -class AudioBuffer; class ConvolverNodeHostObject : public AudioNodeHostObject { public: diff --git a/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/inputs/AudioRecorderHostObject.cpp b/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/inputs/AudioRecorderHostObject.cpp index 9ea3aeb0e..ff2661f79 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/inputs/AudioRecorderHostObject.cpp +++ b/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/inputs/AudioRecorderHostObject.cpp @@ -5,7 +5,7 @@ #include #include #include -#include + #include #ifdef ANDROID #include diff --git a/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/sources/AudioBufferHostObject.cpp b/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/sources/AudioBufferHostObject.cpp index a111272d5..23cae13c2 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/sources/AudioBufferHostObject.cpp +++ b/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/sources/AudioBufferHostObject.cpp @@ -1,7 +1,6 @@ #include #include -#include #include #include diff --git a/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/sources/AudioBufferHostObject.h b/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/sources/AudioBufferHostObject.h index 0f8db07d9..660836dbb 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/sources/AudioBufferHostObject.h +++ b/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/sources/AudioBufferHostObject.h @@ -1,7 +1,7 @@ #pragma once #include -#include +#include #include #include 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 02f120edf..512ef1687 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 @@ -5,7 +5,7 @@ #include #include #include -#include + #include #include diff --git a/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/sources/AudioBufferSourceNodeHostObject.h b/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/sources/AudioBufferSourceNodeHostObject.h index 45f81fd30..b6de2993f 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/sources/AudioBufferSourceNodeHostObject.h +++ b/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/sources/AudioBufferSourceNodeHostObject.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include @@ -10,7 +11,6 @@ using namespace facebook; struct AudioBufferSourceOptions; class BaseAudioContext; class AudioBufferHostObject; -class AudioBuffer; class AudioBufferSourceNodeHostObject : public AudioBufferBaseSourceNodeHostObject { public: 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 bc77a51d4..65bdce8b2 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 @@ -4,7 +4,7 @@ #include #include #include -#include + #include namespace audioapi { 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 4890f3848..6966b4532 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 @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -15,7 +16,6 @@ namespace audioapi { -class AudioBuffer; class AudioParam; class AudioNode : public std::enable_shared_from_this { 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 06abccab8..b6186f944 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 @@ -5,7 +5,7 @@ #include #include #include -#include +#include #include #include 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 c8428deed..7bc205f9a 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,6 @@ #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 fa3c9efad..e3f52fd28 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,6 +3,7 @@ #include #include #include +#include #include #include @@ -15,10 +16,8 @@ namespace audioapi { -class AudioBuffer; class GainNode; class DelayNode; -class AudioBuffer; class PeriodicWave; class OscillatorNode; class ConstantSourceNode; 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 336712c6b..768e450ab 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 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 8f1f3bdb5..8372e753e 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,7 @@ #include #include #include -#include + #include #include 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 212e33f36..354a3ec91 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 @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -15,7 +16,6 @@ namespace audioapi { -class AudioBuffer; class CircularAudioArray; struct AnalyserOptions; 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 53628b4c7..27a815389 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 @@ -3,7 +3,7 @@ #include #include #include -#include + #include namespace audioapi { 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 42d54b689..51c4dcb39 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 @@ -2,6 +2,7 @@ #include #include +#include #include #include @@ -9,7 +10,6 @@ namespace audioapi { -class AudioBuffer; class BaseAudioContext; class AudioDestinationNode : public AudioNode { 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 cd40e4baa..c3411a4f3 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 @@ -31,7 +31,7 @@ #include #include #include -#include + #include // https://webaudio.github.io/Audio-EQ-Cookbook/audio-eq-cookbook.html - math 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 e5dcc830a..477feca92 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 @@ -31,6 +31,7 @@ #include #include #include +#include #if RN_AUDIO_API_TEST #include #endif // RN_AUDIO_API_TEST @@ -39,7 +40,6 @@ namespace audioapi { -class AudioBuffer; struct BiquadFilterOptions; class BiquadFilterNode : public AudioNode { 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 435d69d6b..290f8716c 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 @@ -4,7 +4,7 @@ #include #include #include -#include + #include #include #include 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 4041d3c5b..9c30f9570 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 @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -15,8 +16,6 @@ static constexpr double MIN_IR_POWER = 0.000125; namespace audioapi { -class AudioBuffer; -class AudioBuffer; struct ConvolverOptions; class ConvolverNode : public AudioNode { 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 bdf40aa79..ef8d6ae73 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 @@ -3,7 +3,7 @@ #include #include #include -#include + #include namespace audioapi { 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 d380952c1..4d76180de 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 @@ -2,12 +2,12 @@ #include #include +#include #include namespace audioapi { -class AudioBuffer; struct DelayOptions; class DelayNode : public AudioNode { 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 fe0b1149d..a389ee566 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 @@ -3,7 +3,7 @@ #include #include #include -#include + #include namespace audioapi { 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 192a69979..4be75e632 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 @@ -2,12 +2,12 @@ #include #include +#include #include namespace audioapi { -class AudioBuffer; struct GainOptions; class GainNode : public AudioNode { 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 41076e557..98de31b2a 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 @@ -28,7 +28,7 @@ #include #include #include -#include + #include #include #include 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 f6771940e..29562cf63 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 @@ -30,7 +30,7 @@ #include #include -#include +#include #include namespace audioapi { 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 5d26c1cd2..dd756d0c1 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 @@ -30,7 +30,7 @@ #include #include -#include +#include #include #include 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 baec091c0..0d1764b3d 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 @@ -3,7 +3,7 @@ #include #include #include -#include + #include // https://webaudio.github.io/web-audio-api/#stereopanner-algorithm 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 f78134619..ecaae9a77 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 @@ -2,13 +2,13 @@ #include #include +#include #include #include namespace audioapi { -class AudioBuffer; struct StereoPannerOptions; class StereoPannerNode : public AudioNode { 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 d7dfb88d2..bb13b7625 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 @@ -4,7 +4,7 @@ #include #include #include -#include + #include namespace audioapi { 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 cdd8dfd2f..6690a3d70 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 @@ -4,13 +4,13 @@ #include #include #include +#include #include #include namespace audioapi { -class AudioBuffer; struct WaveShaperOptions; class WaveShaperNode : public AudioNode { 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 acdf28880..ad73d78dd 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 @@ -5,7 +5,7 @@ #include #include #include -#include +#include #include #include 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 d493a8047..8a52a742e 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 @@ -5,7 +5,7 @@ #include #include #include -#include +#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 c2b196765..f532b988e 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 @@ -1,5 +1,6 @@ #pragma once +#include #include #include #include @@ -9,7 +10,6 @@ namespace audioapi { -class AudioBuffer; class AudioFileWriter; class CircularAudioArray; class RecorderAdapterNode; 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 38505c478..150a023de 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 @@ -5,7 +5,7 @@ #include #include #include -#include + #include #include #include 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 f8330650c..9d11a26fb 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 @@ -2,14 +2,12 @@ #include #include +#include -#include #include -#include namespace audioapi { -class AudioBuffer; class AudioParam; struct BaseAudioBufferSourceOptions; 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 df989de48..1e4a6ae31 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 @@ -8,7 +8,6 @@ #include #include #include -#include #include #include 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 1d56886c9..f9e992690 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 @@ -2,16 +2,14 @@ #include #include -#include +#include #include #include #include -#include namespace audioapi { -class AudioBuffer; class AudioParam; struct BaseAudioBufferSourceOptions; 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 9286a5ca9..1d36d9aae 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 @@ -8,7 +8,7 @@ #include #include #include -#include + #include #include #include 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 a63d640f0..2d8a1e385 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 @@ -2,14 +2,13 @@ #include #include -#include +#include #include #include namespace audioapi { -class AudioBuffer; class AudioParam; struct AudioBufferSourceOptions; 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 4ad8ce92e..1d7fe8f5c 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 @@ -4,7 +4,6 @@ #include #include #include -#include #if !RN_AUDIO_API_TEST #include 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 13fdc9874..789056b78 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 @@ -3,7 +3,7 @@ #include #include #include -#include + #include namespace audioapi { 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 5c030c59f..8e7684d80 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 @@ -2,12 +2,12 @@ #include #include +#include #include namespace audioapi { -class AudioBuffer; struct ConstantSourceOptions; class ConstantSourceNode : public AudioScheduledSourceNode { 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 18833824f..f537eb411 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 @@ -3,7 +3,7 @@ #include #include #include -#include + #include namespace audioapi { 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 3b6eb6bb4..a3018fda1 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 @@ -9,7 +9,6 @@ namespace audioapi { -class AudioBuffer; struct OscillatorOptions; class OscillatorNode : public AudioScheduledSourceNode { 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 2d72f26f2..cb9145ae6 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 @@ -3,7 +3,6 @@ #include #include #include -#include #include #include 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 d56f54041..330112391 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 @@ -5,14 +5,13 @@ #include #include #include +#include #include #include #include namespace audioapi { -class AudioBuffer; - /// @brief RecorderAdapterNode is an AudioNode which adapts push Recorder into pull graph. /// It uses RingBuffer to store audio data and AudioParam to provide audio data in pull mode. /// It is used to connect native audio recording APIs with Audio API. 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 178d87085..c07dabc9e 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 @@ -13,7 +13,7 @@ #include #include #include -#include + #include #include #include 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 2331b5790..8c9c2363c 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 @@ -11,7 +11,7 @@ #pragma once #include -#include +#include #if !RN_AUDIO_API_FFMPEG_DISABLED extern "C" { @@ -58,7 +58,6 @@ struct StreamingData { namespace audioapi { -class AudioBuffer; struct StreamerOptions; class StreamerNode : public AudioScheduledSourceNode { 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 93589ba3f..23d4b8660 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 @@ -5,7 +5,7 @@ #include #include #include -#include +#include #include #include diff --git a/packages/react-native-audio-api/common/cpp/audioapi/core/utils/AudioDecoder.cpp b/packages/react-native-audio-api/common/cpp/audioapi/core/utils/AudioDecoder.cpp index 2b0f1acc3..79154a11c 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/core/utils/AudioDecoder.cpp +++ b/packages/react-native-audio-api/common/cpp/audioapi/core/utils/AudioDecoder.cpp @@ -2,7 +2,6 @@ #include #include #include -#include #include #include diff --git a/packages/react-native-audio-api/common/cpp/audioapi/core/utils/AudioDecoder.h b/packages/react-native-audio-api/common/cpp/audioapi/core/utils/AudioDecoder.h index 39e0809d9..0c44d7419 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/core/utils/AudioDecoder.h +++ b/packages/react-native-audio-api/common/cpp/audioapi/core/utils/AudioDecoder.h @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -12,8 +13,6 @@ namespace audioapi { -class AudioBuffer; - using AudioBufferResult = Result, std::string>; struct MemorySource { diff --git a/packages/react-native-audio-api/common/cpp/audioapi/core/utils/AudioGraphManager.cpp b/packages/react-native-audio-api/common/cpp/audioapi/core/utils/AudioGraphManager.cpp index 3755ec935..1689fc6b6 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/core/utils/AudioGraphManager.cpp +++ b/packages/react-native-audio-api/common/cpp/audioapi/core/utils/AudioGraphManager.cpp @@ -5,7 +5,7 @@ #include #include #include -#include + #include #include #include diff --git a/packages/react-native-audio-api/common/cpp/audioapi/core/utils/AudioGraphManager.h b/packages/react-native-audio-api/common/cpp/audioapi/core/utils/AudioGraphManager.h index 4a7bd2deb..462fbddb0 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/core/utils/AudioGraphManager.h +++ b/packages/react-native-audio-api/common/cpp/audioapi/core/utils/AudioGraphManager.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include @@ -13,7 +14,6 @@ namespace audioapi { class AudioNode; class AudioScheduledSourceNode; class AudioParam; -class AudioBuffer; #define AUDIO_GRAPH_MANAGER_SPSC_OPTIONS \ std::unique_ptr, channels::spsc::OverflowStrategy::WAIT_ON_FULL, \ 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 d7035a444..40531f240 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 @@ -4,7 +4,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 51cde9f66..ffcb243f9 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 @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include #include @@ -11,7 +12,6 @@ namespace audioapi { -class AudioBuffer; class CircularAudioArray; class AudioEventHandlerRegistry; diff --git a/packages/react-native-audio-api/common/cpp/audioapi/core/utils/AudioStretcher.cpp b/packages/react-native-audio-api/common/cpp/audioapi/core/utils/AudioStretcher.cpp index 286254fa8..c618031e9 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/core/utils/AudioStretcher.cpp +++ b/packages/react-native-audio-api/common/cpp/audioapi/core/utils/AudioStretcher.cpp @@ -2,7 +2,7 @@ #include #include #include -#include + #include #include #include diff --git a/packages/react-native-audio-api/common/cpp/audioapi/core/utils/AudioStretcher.h b/packages/react-native-audio-api/common/cpp/audioapi/core/utils/AudioStretcher.h index 4a8e47482..ba248cce4 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/core/utils/AudioStretcher.h +++ b/packages/react-native-audio-api/common/cpp/audioapi/core/utils/AudioStretcher.h @@ -1,12 +1,11 @@ #pragma once +#include #include #include namespace audioapi { -class AudioBuffer; - class AudioStretcher { public: AudioStretcher() = delete; 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 7a2ddde88..275ff2805 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 @@ -8,7 +8,7 @@ #include #include #include -#include + #include #include 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 a5a05637d..dfc9d6044 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 @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -10,8 +11,6 @@ namespace audioapi { -class AudioBuffer; - class Convolver { using aligned_vec_complex = std::vector, AlignedAllocator, 16>>; 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 645a03b71..5994e6773 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 @@ -2,7 +2,6 @@ #include #include #include -#include #include #include 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 ef645a985..af36e47ef 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 @@ -3,13 +3,12 @@ #include #include #include +#include #include namespace audioapi { -class AudioBuffer; - class WaveShaper { public: explicit WaveShaper(const std::shared_ptr &curve, float sampleRate); 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 index 55a464868..539251f80 100644 --- 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 @@ -1,7 +1,7 @@ #pragma once #include -#include +#include #include #include #include diff --git a/packages/react-native-audio-api/common/cpp/audioapi/libs/ffmpeg/FFmpegDecoding.cpp b/packages/react-native-audio-api/common/cpp/audioapi/libs/ffmpeg/FFmpegDecoding.cpp index 71ab6babc..041992795 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/libs/ffmpeg/FFmpegDecoding.cpp +++ b/packages/react-native-audio-api/common/cpp/audioapi/libs/ffmpeg/FFmpegDecoding.cpp @@ -12,8 +12,6 @@ #include #endif // RN_AUDIO_API_FFMPEG_DISABLED #include -#include -#include namespace audioapi::ffmpegdecoder { diff --git a/packages/react-native-audio-api/common/cpp/audioapi/libs/ffmpeg/FFmpegDecoding.h b/packages/react-native-audio-api/common/cpp/audioapi/libs/ffmpeg/FFmpegDecoding.h index c376b4b7a..46eea8f1d 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/libs/ffmpeg/FFmpegDecoding.h +++ b/packages/react-native-audio-api/common/cpp/audioapi/libs/ffmpeg/FFmpegDecoding.h @@ -8,7 +8,7 @@ * FFmpeg, you must comply with the terms of the LGPL for FFmpeg itself. */ -#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 be6c53310..98019f152 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 @@ -13,7 +13,7 @@ #include #include #include -#include +#include namespace audioapi { struct AudioNodeOptions { 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 effc552a1..2e06889f9 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 @@ -3,7 +3,7 @@ #include #include #include -#include +#include #include #include #include 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 803f3ab0b..db997f836 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 @@ -3,7 +3,7 @@ #include #include #include -#include +#include #include #include #include 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 afe2dbee1..b345eb2fe 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 @@ -3,7 +3,7 @@ #include #include #include -#include +#include #include #include #include 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 5e0923178..e90260ccc 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 @@ -4,7 +4,7 @@ #include #include #include -#include +#include #include #include #include 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 ed0c9beb5..3a73c63c1 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 @@ -2,7 +2,7 @@ #include #include #include -#include +#include #include #include #include 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 5e1a7a8da..89b5ec413 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 @@ -3,7 +3,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/packages/react-native-audio-api/common/cpp/test/src/utils/AudioBufferTest.cpp b/packages/react-native-audio-api/common/cpp/test/src/utils/AudioBufferTest.cpp index 4ad399162..bfef79e9c 100644 --- a/packages/react-native-audio-api/common/cpp/test/src/utils/AudioBufferTest.cpp +++ b/packages/react-native-audio-api/common/cpp/test/src/utils/AudioBufferTest.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include 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 bf4643abf..7b19da5ad 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 @@ -6,11 +6,11 @@ typedef struct objc_object NativeAudioPlayer; #endif // __OBJC__ +#include #include namespace audioapi { -class AudioBuffer; class AudioContext; class IOSAudioPlayer { 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 e58376bba..edf678af5 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 @@ -5,7 +5,7 @@ #include #include #include -#include +#include namespace audioapi { 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 36bd7bd6b..3e45741db 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 @@ -16,7 +16,7 @@ #include #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 173c24ce7..485c05919 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 @@ -7,9 +7,9 @@ typedef struct objc_object AVAudioConverter; #endif #include +#include #include #include -#include struct CallbackData { const AudioBufferList *audioBufferList; @@ -18,7 +18,6 @@ struct CallbackData { namespace audioapi { -class AudioBuffer; class CircularAudioArray; class AudioEventHandlerRegistry; 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 637e84c86..1ca4cf8b3 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 @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include #include #include From c720c8971ffa2342e56897810995a93b87cc42b3 Mon Sep 17 00:00:00 2001 From: maciejmakowski2003 Date: Tue, 10 Mar 2026 17:00:31 +0100 Subject: [PATCH 5/6] fix: nitpicks --- .../main/cpp/audioapi/android/core/AndroidAudioRecorder.cpp | 2 -- .../audioapi/HostObjects/inputs/AudioRecorderHostObject.cpp | 2 +- .../common/cpp/audioapi/core/OfflineAudioContext.cpp | 1 + .../common/cpp/audioapi/core/analysis/AnalyserNode.cpp | 1 - .../common/cpp/audioapi/core/effects/IIRFilterNode.cpp | 1 - .../common/cpp/audioapi/core/effects/WaveShaperNode.cpp | 1 - .../common/cpp/audioapi/core/utils/AudioRecorderCallback.cpp | 2 -- .../common/cpp/audioapi/dsp/WaveShaper.cpp | 3 +-- 8 files changed, 3 insertions(+), 10 deletions(-) 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 3721aafe0..974135bd5 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 @@ -11,8 +11,6 @@ #include #include #include -#include - #include #include #include diff --git a/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/inputs/AudioRecorderHostObject.cpp b/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/inputs/AudioRecorderHostObject.cpp index ff2661f79..2dbbb3d3c 100644 --- a/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/inputs/AudioRecorderHostObject.cpp +++ b/packages/react-native-audio-api/common/cpp/audioapi/HostObjects/inputs/AudioRecorderHostObject.cpp @@ -5,7 +5,7 @@ #include #include #include - +#include #include #ifdef ANDROID #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 768e450ab..389cab337 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,6 +6,7 @@ #include #include #include +#include #include #include 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 8372e753e..21db375d4 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 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 98de31b2a..0f3d2640d 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 @@ -27,7 +27,6 @@ #include #include #include -#include #include #include 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 bb13b7625..68e37a38a 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 #include 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 40531f240..87b49f7b5 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,8 +3,6 @@ #include #include -#include - #include #include 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 5994e6773..63e7e0001 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,11 +1,10 @@ #include #include #include -#include +#include #include #include -#include "audioapi/dsp/r8brain/Resampler.h" namespace audioapi { From 7b1633aa77ce797b33af3db0318eabb3c9ded85f Mon Sep 17 00:00:00 2001 From: maciejmakowski2003 Date: Thu, 12 Mar 2026 12:45:37 +0100 Subject: [PATCH 6/6] fix: nits --- .../common/cpp/audioapi/AudioAPIModuleInstaller.h | 2 +- .../common/cpp/audioapi/utils/AudioArray.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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/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_); }