refactor: implemented aligned audio array implementation#980
refactor: implemented aligned audio array implementation#980maciejmakowski2003 wants to merge 6 commits intomainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR refactors AudioArray and AudioBuffer from traditional .h/.cpp class pairs into C++ template header-only (.hpp) implementations, introducing configurable memory alignment via the AlignedAudioArray<Alignment> and AlignedAudioBuffer<Alignment> template classes. Type aliases preserve backward compatibility (AudioArray, AudioBuffer) while adding new DSPAudioArray and DSPAudioBuffer types with 64-byte alignment for SIMD optimization.
Changes:
- Replaced
AudioArray.h/.cppandAudioBuffer.h/.cppwith template header-onlyAudioArray.hppandAudioBuffer.hpp, parameterized on memory alignment. - Updated all
#includedirectives and removed now-unnecessary forward declarations (class AudioBuffer;,class AudioArray;) across ~50 files. - Fixed a typo in
AudioAPIModuleInstaller.hrenaminggetCrateAudioBufferFunctiontogetCreateAudioBufferFunction.
Reviewed changes
Copilot reviewed 102 out of 103 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
AudioArray.hpp |
New template header replacing AudioArray.h/.cpp with alignment-parameterized AlignedAudioArray<Alignment> |
AudioBuffer.hpp |
New template header replacing AudioBuffer.h/.cpp with alignment-parameterized AlignedAudioBuffer<Alignment> |
AudioArrayBuffer.hpp |
Updated to use templatized AlignedAudioArrayBuffer<Alignment> inheriting from AlignedAudioArray |
AudioArray.h/.cpp |
Deleted (replaced by .hpp) |
AudioBuffer.h/.cpp |
Deleted (replaced by .hpp) |
AudioAPIModuleInstaller.h |
Fixed function name typo (getCrate... → getCreate...) |
~40 other .h/.cpp/.mm files |
Updated includes from .h to .hpp and removed stale forward declarations |
create-your-own-effect.mdx |
Updated documentation with new include paths |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
packages/react-native-audio-api/common/cpp/audioapi/utils/AudioArray.hpp
Outdated
Show resolved
Hide resolved
packages/react-native-audio-api/common/cpp/audioapi/AudioAPIModuleInstaller.h
Outdated
Show resolved
Hide resolved
| template <size_t A> | ||
| friend class AlignedAudioArray; |
| } | ||
|
|
||
| template <size_t OtherAlignment> | ||
| [[nodiscard]] float computeConvolution( |
There was a problem hiding this comment.
I think this function is no longer needed
| }; | ||
|
|
||
| using AudioBuffer = AlignedAudioBuffer<alignof(std::max_align_t)>; | ||
| using DSPAudioBuffer = AlignedAudioBuffer<64>; |
| }; | ||
|
|
||
| using AudioArray = AlignedAudioArray<alignof(std::max_align_t)>; | ||
| using DSPAudioArray = AlignedAudioArray<64>; |
| } | ||
|
|
||
| private: | ||
| std::vector<std::shared_ptr<AlignedAudioArrayBuffer<Alignment>>> channels_; |
There was a problem hiding this comment.
shouldn't DspAudioBuffer has channels as
std::vector<AudioArray<Alignment>>
to not introduce overhead from jsi where it is not needed?
Part of RNAA-425
Introduced changes
AlignedAudioArraythat allows to specify alignment used to allocate it's data. There are two default template instantiations:AudioArrayaligned toalignof(std::max_align_t)- in common 16 bytes,DSPAudioArrayaligned to 64 bytes in order to avoid false sharing and boost SIMD.AlignedAudioBufferthat is a wrapper around a vector of AlignedAudioArray.Checklist