The documentation for the dsp::DelayLine class says
Note: If you intend to change the delay in real time, you may want to smooth changes to the delay systematically using either a ramp or a low-pass filter.
Consider looking at these options.
A useful class for ramping values to avoid pops and clicks with realtime code is the LinearSmoothedValue or SmoothedValue classes.
Really thank you guys, but I cannot figure out how can I integrate LinearSmoothedValue.
Also using push and pop what is the value to smooth.
For example on a gain I can smooth a gain, here I should smooth the num in setDelay? I immagine that also doing this glitches are created anyway…
First, you should call setDelay() in the audio thread.
You could have a class which declare juce::dsp::DelayLine, an atomic and a smoothed value as class members. Then the process function may look like this:
currentDelay = atomicDelay.load()
smoothedDelay.setTargetValue(currentDelay);
if (smoothedDelay.isSmoothing()) {
// iterate over sample index
delayLine.setDelay(smoothedDelay.getNextValue())
// iterate over channel
// update samples by pushing and poping
} else { // process it as a audio block }
You should call setDelay(smoothedDelay.getNextValue()) per sample instead of per buffer. Because of this, you may need to set the sample index as the outer loop.
BTW, you may set the ramp length as a fixed time length, e.g., samplerate * 0.01.
AFAIK using a low pass might be a better solution (I have seen some discussions here before).