BUG in AudioTransportSource?

I think theres a bug in AudioTransportSource::getNextAudioBlock
(juce_AudioTransportSource.cpp, line 280).

[code]void AudioTransportSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
{
const ScopedLock sl (callbackLock);

if (masterSource != 0 && ! stopped)
{
    masterSource->getNextAudioBlock (info);

    if (! playing)
    {
        // just stopped playing, so fade out the last block..
        for (int i = info.buffer->getNumChannels(); --i >= 0;)
            info.buffer->applyGainRamp (i, 0, jmin (256, info.numSamples), 1.0f, 0.0f); // BUG, LINE 280

///////////////////// BUGFIX: /////////////////////

        if (info.numSamples > 256)
            info.buffer->clear(256, info.numSamples - 256);

/////////////////////////////////////////////////////

    }

    if (positionableSource->getNextReadPosition() > positionableSource->getTotalLength() + 1
         && ! positionableSource->isLooping())
    {
        playing = false;
        sendChangeMessage (this);
    }

    stopped = ! playing;

    for (int i = info.buffer->getNumChannels(); --i >= 0;)
    {
        info.buffer->applyGainRamp (i, info.startSample, info.numSamples,
                                    lastGain, gain);
    }
}
else
{
    info.clearActiveBufferRegion();
    stopped = true;
}

lastGain = gain;

}[/code]

It only has an effect while using audio settings with buffer sizes larger than 256 samples. In these cases, the applied gain ramp is smaller than the buffer size, and the rest of the buffer is not set to zero.

Greetings
Jan

juce_AudioTransportSource.cpp, line 74. If setSource gets called and the
following conditions are true:

source != 0
source == newSource
readAheadBufferSize_ == readAheadBufferSize
sourceSampleRate == sourceSampleRateToCorrectFor

then the the source is set to zero instead of newSource.

void AudioTransportSource::setSource (PositionableAudioSource* const newSource, int readAheadBufferSize_, double sourceSampleRateToCorrectFor) { if (source == newSource) { if (source == 0 || (readAheadBufferSize_ == readAheadBufferSize && sourceSampleRate == sourceSampleRateToCorrectFor)) { deleteAndZero (resamplerSource); deleteAndZero (bufferingSource); masterSource = 0; positionableSource = 0; return; } else { setSource (0, 0, 0); // deselect and reselect to avoid releasing resources wrongly } } // .... }

A simple bugfix would be:

if (source == newSource) { if (source == 0) // BUGFIX: // || (readAheadBufferSize_ == readAheadBufferSize // && sourceSampleRate == sourceSampleRateToCorrectFor)) { // ...

Greetings
Jan

Just a little detail in juce_AudioTransportSource.h, line 174:

The private member “speed” is not needed.

Great! I think that the bug you found solves the problem I had with audio clicks when switching playout between different wavfiles.

Doh! Thanks. There was actually another bug in there too, which I’ve also fixed now!