diff --git a/examples/DSP/SIMDRegisterDemo.h b/examples/DSP/SIMDRegisterDemo.h index cf613fcbb0..e433641289 100644 --- a/examples/DSP/SIMDRegisterDemo.h +++ b/examples/DSP/SIMDRegisterDemo.h @@ -53,6 +53,14 @@ using namespace dsp; +template +static T* toBasePointer (SIMDRegister* r) noexcept +{ + return reinterpret_cast (r); +} + +constexpr auto registerSize = dsp::SIMDRegister::size(); + //============================================================================== struct SIMDRegisterDemoDSP { @@ -73,33 +81,44 @@ struct SIMDRegisterDemoDSP iir->prepare (monoSpec); } + template + auto prepareChannelPointers (const AudioBlock& block) + { + std::array result {}; + + for (size_t ch = 0; ch < result.size(); ++ch) + result[ch] = (ch < block.getNumChannels() ? block.getChannelPointer (ch) : zero.getChannelPointer (ch)); + + return result; + } + void process (const ProcessContextReplacing& context) { jassert (context.getInputBlock().getNumSamples() == context.getOutputBlock().getNumSamples()); jassert (context.getInputBlock().getNumChannels() == context.getOutputBlock().getNumChannels()); - auto& input = context.getInputBlock(); - auto& output = context.getOutputBlock(); - auto n = (int) input.getNumSamples(); - auto* inout = channelPointers.getData(); + const auto& input = context.getInputBlock(); + const auto numSamples = (int) input.getNumSamples(); - for (size_t ch = 0; ch < SIMDRegister::size(); ++ch) - inout[ch] = (ch < input.getNumChannels() ? const_cast (input.getChannelPointer (ch)) : zero.getChannelPointer (ch)); + auto inChannels = prepareChannelPointers (input); - using DstSampleType = AudioData::Pointer; - using SrcSampleType = AudioData::Pointer; - - DstSampleType dstData (interleaved.getChannelPointer (0), (int) interleaved.getNumChannels()); - SrcSampleType srcData (inout); - - dstData.convertSamples (srcData, n); + AudioData::interleaveSamples (inChannels.data(), + registerSize, + toBasePointer (interleaved.getChannelPointer (0)), + registerSize, + numSamples); iir->process (ProcessContextReplacing> (interleaved)); - for (size_t ch = 0; ch < input.getNumChannels(); ++ch) - inout[ch] = output.getChannelPointer (ch); + auto outChannels = prepareChannelPointers (context.getOutputBlock()); - srcData.convertSamples (dstData, n); + AudioData::deinterleaveSamples (toBasePointer (interleaved.getChannelPointer (0)), + registerSize, + outChannels.data(), + registerSize, + numSamples); } void reset() @@ -132,7 +151,6 @@ struct SIMDRegisterDemoDSP AudioBlock zero; HeapBlock interleavedBlockData, zeroData; - HeapBlock channelPointers { SIMDRegister::size() }; ChoiceParameter typeParam { { "Low-pass", "High-pass", "Band-pass" }, 1, "Type" }; SliderParameter cutoffParam { { 20.0, 20000.0 }, 0.5, 440.0f, "Cutoff", "Hz" };