Unexpected behaviour in AudioSampleBuffer::copyFrom


When using the method that takes gain as a parameter, i.e.,

void AudioSampleBuffer::copyFrom (const int destChannel, const int destStartSample, const float* source, int numSamples, const float gain) throw()

the behaviour is unexpected if gain equals 0. The copy is skipped, so if you are relying on this to clear a buffer it won’t work.

I changed it to this:

[code] if (numSamples > 0)
float* d = channels [destChannel] + destStartSample;

    if (gain == 0.0f)
        zeromem(d, sizeof(float) * numSamples);
    else if (gain != 1.0f)
        while (--numSamples >= 0)
            *d++ = gain * *source++;
        memcpy (d, source, sizeof (float) * numSamples);



Wow - yes, thanks for that! Looks like a typo, but it must have been there for ages - I’m amazed no-one spotted it before! Will get it fixed right away…