Issue in AudioBlock copyFrom and copyTo

Hi,

I think I found an issue in AudioBlock copyFrom and copyTo methods.

Here is the implementation of copyFrom

 forcedinline const AudioBlock& copyTo (AudioBuffer<NumericType>& dst, size_t srcPos = 0, size_t dstPos = 0, size_t numElements = std::numeric_limits<size_t>::max()) const {
    auto dstlen = static_cast<size_t> (dst.getNumSamples()) / sizeFactor;
    auto n = static_cast<int> (jmin (numSamples - srcPos, dstlen - dstPos, numElements) * sizeFactor);
    auto maxChannels = jmin (static_cast<size_t> (dst.getNumChannels()), static_cast<size_t> (numChannels));
    for (size_t ch = 0; ch < maxChannels; ++ch) {
        FloatVectorOperations::copy (dst.getWritePointer (static_cast<int> (ch), static_cast<int> (dstPos * sizeFactor)), channelPtr (ch), n);
        }
    return *this;
}

But is it me or the srcPos is never used to move in buffer in AudioBlock?

Here is an example of what I have as issue

srcAudioBuffer = [1 2 3 4 5 6 7 8 9 10]
block = [0 0 0 0 0 0]

block.copyFrom(srcAudioBuffer, 6, 0, 4)
-> 7 8 9 10 0 0

copyFrom(src, 0, 4, 2)
-> 1 2 9 10 0 0
instead of 7 8 9 10 1 2

The sourcePosition is still 0 instead of 4.

Does it come from the fact that
FloatVectorOperations::copy (dst.getWritePointer (static_cast<int> (ch), static_cast<int> (dstPos * sizeFactor)), channelPtr (ch), n);
use channelPtr (ch) instead of channelPtr (ch) + srcPos ?

The copyTo has the kind of same issue, instead of sourcePosition, the destinationPosition seems to not being used.

Wow, good catch! Thanks for reporting, I’ll get a fix pushed right away…

1 Like