Avoid Clicks and pops when Looping over a part of a Sample

Hello, I am creating a kind of Granular Synth Logic to generate the Voice of a Monster in game project that I’m creating with juce as my sound engine …
However, if I loop over a part of a sample, I always get clicks and pops here and there.
Is there a way to create some kind of interpolation in the loop to avoid this problem?

If you’re doing granular, then should be using windowing functions which will smooth the start & end points of your audio functions:

JUCE has many of the default window functions built in:


If you’re simply looping audio, you’ll need to implement crossfading. When you start to get to the end of the sample, start to fade out, as you fade in from the beginning. What you’re experience is called an audio discontinuity, and happens when a large jump in a waveform occurs.


You can also make sure your loop starts and ends in silence. That way there is no change in the audio that is detectable. Might not be what you want, but it’s one method that’s been used to resolve this common looping problem without any code involved at all.

AudioBuffer btw has applyGainRamp that can help you with that.

1 Like

Worth adding that if the silence is very brief the sounding result might still sound discontinous. I know this from years of working with loops on samplers. It’s very dependant of the material used. But sure, with a smooth fade out, fade in there are no pops. On the other hand that’s not really a loop but rather the same sound being replayed over and over.