From e2ae08e1112c1437ce93c5f965514228ce688808 Mon Sep 17 00:00:00 2001 From: hogliux Date: Tue, 7 Nov 2017 14:41:33 +0000 Subject: [PATCH] DSP: Added an alignment argument to AudioBlock --- modules/juce_dsp/containers/juce_AudioBlock.h | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/modules/juce_dsp/containers/juce_AudioBlock.h b/modules/juce_dsp/containers/juce_AudioBlock.h index c25647edfe..64465d8d5c 100644 --- a/modules/juce_dsp/containers/juce_AudioBlock.h +++ b/modules/juce_dsp/containers/juce_AudioBlock.h @@ -95,14 +95,15 @@ public: use, because it will be referencing its data. */ AudioBlock (HeapBlock& heapBlockToUseForAllocation, - size_t numberOfChannels, size_t numberOfSamples) noexcept + size_t numberOfChannels, size_t numberOfSamples, + size_t alignmentInBytes = defaultAlignment) noexcept : numChannels (static_cast (numberOfChannels)), numSamples (numberOfSamples) { auto roundedUpNumSamples = (numberOfSamples + elementMask) & ~elementMask; auto channelSize = sizeof (SampleType) * roundedUpNumSamples; auto channelListBytes = sizeof (SampleType*) * numberOfChannels; - auto extraBytes = sizeof (SampleType) - 1; + auto extraBytes = alignmentInBytes - 1; heapBlockToUseForAllocation.malloc (channelListBytes + extraBytes + channelSize * numberOfChannels); @@ -110,7 +111,7 @@ public: channels = chanArray; auto* data = reinterpret_cast (addBytesToPointer (chanArray, channelListBytes)); - data = snapPointerToAlignment (data, sizeof (SampleType)); + data = snapPointerToAlignment (data, alignmentInBytes); for (ChannelCountType i = 0; i < numChannels; ++i) { @@ -536,9 +537,15 @@ private: using ChannelCountType = unsigned int; //============================================================================== - static constexpr size_t sizeFactor = sizeof (SampleType) / sizeof (NumericType); - static constexpr size_t elementMask = sizeFactor - 1; - static constexpr size_t byteMask = (sizeFactor * sizeof (NumericType)) - 1; + static constexpr size_t sizeFactor = sizeof (SampleType) / sizeof (NumericType); + static constexpr size_t elementMask = sizeFactor - 1; + static constexpr size_t byteMask = (sizeFactor * sizeof (NumericType)) - 1; + + #if JUCE_USE_SIMD + static constexpr size_t defaultAlignment = sizeof (SIMDRegister); + #else + static constexpr size_t defaultAlignment = sizeof (NumericType); + #endif SampleType* const* channels; ChannelCountType numChannels = 0;