AudioSampleBuffer tutorial, clicks in loop at lower volume

Trying to understand buffers I extended the Looping audio using AudioSampleBuffer (advanced)

I added a volume slider working directly on the bufferToFill

I put it inside the getNextAudioBlock method of MainContentComponent directly after the buffer been copied.

for (auto channel = 0; channel < numOutputChannels; ++channel)
         bufferToFill.buffer->copyFrom (channel,
                                        bufferToFill.startSample + outputSamplesOffset,
                                        channel % numInputChannels,
        bufferToFill.buffer->applyGain(playbackGain);   // APPLYING GAIN

This works but I have two questions.

  1. applyGain is a pre built method of AudioBuffer, but which methods would I use, keeping the threading of the advanced tutorial i mind, to make a more general processing (adding filters and stuff) the correct way?

  2. When I lower the volume, there’s a slight and steadily recurring pop in the playback. I believe the pop interval is equal to the loop interval and it’s easily heard in the sine example. This indicates som kind of error in the loop restart in relation to the set gain. But I can not see a more appopriate location for the buffer->applyGain that could explain this error, where would that be? Just to make clear, at full volume there are no pops and looping the example sine in some other looper reveals a seamless loop, no pops. It’s the gain that introduces some kind of discontinuity.

Of course the best thing - although completely different approach - might be to apply the gain once to the whole file instead? But that’s an extension to this example I don’t know how to at this point. But I’m interested in advice in that direction too. :slightly_smiling_face: