From 5faef29f3eadc657e78746b34c4a40bf49a163fa Mon Sep 17 00:00:00 2001 From: hogliux Date: Mon, 30 Apr 2018 14:59:54 +0100 Subject: [PATCH] DSP: added the methods AudioBlock::copyTo/AudioBlock::copyFrom which facilitate copying to/from an AudioBuffer --- modules/juce_dsp/containers/juce_AudioBlock.h | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/modules/juce_dsp/containers/juce_AudioBlock.h b/modules/juce_dsp/containers/juce_AudioBlock.h index aa13b7039b..1e7c4d304a 100644 --- a/modules/juce_dsp/containers/juce_AudioBlock.h +++ b/modules/juce_dsp/containers/juce_AudioBlock.h @@ -261,6 +261,49 @@ public: return *this; } + /** Copy the values from a JUCE's AudioBuffer to the receiver. + + All indices and sizes are in the receiver's units, i.e. if SampleType is a + SIMDRegister then incrementing srcPos by one will increase the sample position + in the AudioBuffer's units by a factor of SIMDRegister::::SIMDNumElements. + */ + forcedinline AudioBlock& copyFrom (const AudioBuffer& src, size_t srcPos = 0, size_t dstPos = 0, + size_t numElements = std::numeric_limits::max()) + { + auto srclen = static_cast (src.getNumSamples()) / sizeFactor; + auto n = static_cast (jmin (srclen - srcPos, numSamples - dstPos, numElements) * sizeFactor); + auto maxChannels = jmin (static_cast (src.getNumChannels()), static_cast (numChannels)); + + for (size_t ch = 0; ch < maxChannels; ++ch) + FloatVectorOperations::copy (channelPtr (ch), + src.getReadPointer (static_cast (ch), + static_cast (srcPos * sizeFactor)), + n); + + return *this; + } + + /** Copy the values from the receiver to a JUCE's AudioBuffer. + + All indices and sizes are in the receiver's units, i.e. if SampleType is a + SIMDRegister then incrementing dstPos by one will increase the sample position + in the AudioBuffer's units by a factor of SIMDRegister::::SIMDNumElements. + */ + forcedinline const AudioBlock& copyTo (AudioBuffer& dst, size_t srcPos = 0, size_t dstPos = 0, + size_t numElements = std::numeric_limits::max()) const + { + auto dstlen = static_cast (dst.getNumSamples()) / sizeFactor; + auto n = static_cast (jmin (numSamples - srcPos, dstlen - dstPos, numElements) * sizeFactor); + auto maxChannels = jmin (static_cast (dst.getNumChannels()), static_cast (numChannels)); + + for (size_t ch = 0; ch < maxChannels; ++ch) + FloatVectorOperations::copy (dst.getWritePointer (static_cast (ch), + static_cast (dstPos * sizeFactor)), + channelPtr (ch), n); + + return *this; + } + /** Move memory within the receiver from the position srcPos to the position dstPos. If numElements is not specified then move will move the maximum amount of memory. */