diff --git a/modules/dsp/chowdsp_buffers/Buffers/chowdsp_Buffer.cpp b/modules/dsp/chowdsp_buffers/Buffers/chowdsp_Buffer.cpp index 0241bbaee..b3db748f5 100644 --- a/modules/dsp/chowdsp_buffers/Buffers/chowdsp_Buffer.cpp +++ b/modules/dsp/chowdsp_buffers/Buffers/chowdsp_Buffer.cpp @@ -2,14 +2,14 @@ namespace chowdsp { -template -Buffer::Buffer (int numChannels, int numSamples) +template +Buffer::Buffer (int numChannels, int numSamples) { setMaxSize (numChannels, numSamples); } -template -void Buffer::setMaxSize (int numChannels, int numSamples) +template +void Buffer::setMaxSize (int numChannels, int numSamples) { // Make sure we don't have any null internal buffers jassert (juce::isPositiveAndNotGreaterThan (numChannels, maxNumChannels)); @@ -37,8 +37,8 @@ void Buffer::setMaxSize (int numChannels, int numSamples) setCurrentSize (numChannels, numSamples); } -template -void Buffer::setCurrentSize (int numChannels, int numSamples) noexcept +template +void Buffer::setCurrentSize (int numChannels, int numSamples) noexcept { // trying to set a current size, but we don't have enough memory allocated! jassert (numSamples * numChannels <= (int) rawData.size()); @@ -56,79 +56,79 @@ void Buffer::setCurrentSize (int numChannels, int numSamples) noexce currentNumSamples = numSamples; } -template -SampleType* Buffer::getWritePointer (int channel) noexcept +template +SampleType* Buffer::getWritePointer (int channel) noexcept { hasBeenCleared = false; return channelPointers[(size_t) channel]; } -template -const SampleType* Buffer::getReadPointer (int channel) const noexcept +template +const SampleType* Buffer::getReadPointer (int channel) const noexcept { return channelPointers[(size_t) channel]; } -template -nonstd::span Buffer::getWriteSpan (int channel) noexcept +template +nonstd::span Buffer::getWriteSpan (int channel) noexcept { hasBeenCleared = false; return { channelPointers[(size_t) channel], (size_t) currentNumSamples }; } -template -nonstd::span Buffer::getReadSpan (int channel) const noexcept +template +nonstd::span Buffer::getReadSpan (int channel) const noexcept { return { channelPointers[(size_t) channel], (size_t) currentNumSamples }; } -template -SampleType** Buffer::getArrayOfWritePointers() noexcept +template +SampleType** Buffer::getArrayOfWritePointers() noexcept { hasBeenCleared = false; return channelPointers.data(); } -template -const SampleType** Buffer::getArrayOfReadPointers() const noexcept +template +const SampleType** Buffer::getArrayOfReadPointers() const noexcept { return const_cast (channelPointers.data()); // NOSONAR (using const_cast to be more strict) } #if CHOWDSP_USING_JUCE -template +template template -std::enable_if_t, juce::AudioBuffer> Buffer::toAudioBuffer() +std::enable_if_t, juce::AudioBuffer> Buffer::toAudioBuffer() { return { getArrayOfWritePointers(), currentNumChannels, currentNumSamples }; } -template +template template -std::enable_if_t, juce::AudioBuffer> Buffer::toAudioBuffer() const +std::enable_if_t, juce::AudioBuffer> Buffer::toAudioBuffer() const { return { const_cast (getArrayOfReadPointers()), currentNumChannels, currentNumSamples }; // NOSONAR } #if JUCE_MODULE_AVAILABLE_juce_dsp -template +template template -std::enable_if_t, AudioBlock> Buffer::toAudioBlock() +std::enable_if_t, AudioBlock> Buffer::toAudioBlock() { return { getArrayOfWritePointers(), (size_t) currentNumChannels, (size_t) currentNumSamples }; } -template +template template -std::enable_if_t, AudioBlock> Buffer::toAudioBlock() const +std::enable_if_t, AudioBlock> Buffer::toAudioBlock() const { return { getArrayOfReadPointers(), (size_t) currentNumChannels, (size_t) currentNumSamples }; } #endif #endif -template -void Buffer::clear() noexcept +template +void Buffer::clear() noexcept { if (hasBeenCleared) return; diff --git a/modules/dsp/chowdsp_buffers/Buffers/chowdsp_Buffer.h b/modules/dsp/chowdsp_buffers/Buffers/chowdsp_Buffer.h index fa0cd6e38..d3db0c0ed 100644 --- a/modules/dsp/chowdsp_buffers/Buffers/chowdsp_Buffer.h +++ b/modules/dsp/chowdsp_buffers/Buffers/chowdsp_Buffer.h @@ -28,8 +28,13 @@ namespace buffer_detail /** * An audio sample buffer that allocates its own memory. + * + * By default each buffer channel will be aligned to the appropriate SIMD + * byte boundary, unless CHOWDSP_NO_XSIMD is enabled. If you would like to + * provide a custom alignment, you can specify the alignment as the second + * template argument. */ -template +template class Buffer { public: @@ -43,10 +48,10 @@ class Buffer Buffer (int numChannels, int numSamples); /** Move constructor */ - Buffer (Buffer&&) noexcept = default; + Buffer (Buffer&&) noexcept = default; /** Move assignment */ - Buffer& operator= (Buffer&&) noexcept = default; + Buffer& operator= (Buffer&&) noexcept = default; /** * Sets the maximum size that this buffer can have, and sets the current size as well. @@ -116,11 +121,13 @@ class Buffer private: #if ! CHOWDSP_NO_XSIMD - using Allocator = xsimd::default_allocator; + using Allocator = std::conditional_t, + xsimd::aligned_allocator>; #else using Allocator = std::allocator; #endif - std::vector rawData; + std::vector rawData {}; int currentNumChannels = 0; int currentNumSamples = 0; diff --git a/modules/dsp/chowdsp_simd/chowdsp_simd.h b/modules/dsp/chowdsp_simd/chowdsp_simd.h index ea7bb1085..207c553eb 100644 --- a/modules/dsp/chowdsp_simd/chowdsp_simd.h +++ b/modules/dsp/chowdsp_simd/chowdsp_simd.h @@ -53,7 +53,8 @@ JUCE_BEGIN_IGNORE_WARNINGS_GCC_LIKE ("-Wcast-align", "-Wc++98-compat-extra-semi", "-Wshorten-64-to-32", "-Wfloat-equal", - "-Woverflow") + "-Woverflow", + "-Wdeprecated") JUCE_BEGIN_IGNORE_WARNINGS_MSVC (4244) #include "third_party/xsimd/include/xsimd/xsimd.hpp" JUCE_END_IGNORE_WARNINGS_GCC_LIKE diff --git a/tests/dsp_tests/chowdsp_buffers_test/BufferTest.cpp b/tests/dsp_tests/chowdsp_buffers_test/BufferTest.cpp index e98abafb7..7f75ceffa 100644 --- a/tests/dsp_tests/chowdsp_buffers_test/BufferTest.cpp +++ b/tests/dsp_tests/chowdsp_buffers_test/BufferTest.cpp @@ -6,10 +6,13 @@ JUCE_BEGIN_IGNORE_WARNINGS_GCC_LIKE ("-Wfloat-equal") template class chowdsp::Buffer; +template +using TestBuffer = chowdsp::Buffer; + template using TestStaticBuffer = chowdsp::StaticBuffer; -TEMPLATE_PRODUCT_TEST_CASE ("Buffer Test", "[dsp][buffers][simd]", (chowdsp::Buffer, TestStaticBuffer), (float, double, xsimd::batch, xsimd::batch, int, std::string)) +TEMPLATE_PRODUCT_TEST_CASE ("Buffer Test", "[dsp][buffers][simd]", (TestBuffer, TestStaticBuffer), (float, double, xsimd::batch, xsimd::batch, int, std::string)) { using BufferType = TestType; using SampleType = typename BufferType::Type;