How to smooth changes in delay time using Linear SmoothedValue?

Hi there, I’m fairly a new JUCE user. So I currently have a delay plug-in with different sliders that can control the delay time. However, while the delay time is changing (turning a slider) the audio crackles and sounds awful. I think it has to do with the read position in the buffer skipping over samples.

I’ve tried using linear smoothed value to gradually increment from the last delay time to the next delay time, though I’m convinced I’m using it wrong. A general explanation on how to implement the smoothing would be immensely helpful! If it’s useful for me to include, this is the piece of code I have in my “readFromDelayBuffer” method that should handle the smoothing:

if (lastDelayTime != currentDelayTime) { //if you turn the knob
	if (smoothedValue.getTargetValue() != currentDelayTime) { //if you keep turning the knob
			smoothedValue.setTargetValue(currentDelayTime); //update the target value
			lastDelayTime = smoothedValue.getNextValue(); //do the smoothing
	}
}

There are a couple of approaches to make delay time changes smoother :

  • Fade the audio out when the delay time starts changing and fade it back when its settled.
  • Interpolate through the delay buffer at a different speed to reach the new read head position corresponding to the new delay time. This is often used in “vintage” delay emulations. The interpolation should be high quality, plain linear interpolation probably isn’t going to work great.

Just using a SmoothedValue for the delay time parameter likely isn’t going to work.

3 Likes

OT: when writing code snippets, prepend each line with 4 spaces or put 3 backticks ` before and after your code to make it more readable like this:

if (lastDelayTime != currentDelayTime) { //if you turn the knob
    if (smoothedValue.getTargetValue() != currentDelayTime) { //if you keep turning the knob
        smoothedValue.setTargetValue(currentDelayTime); //update the target value
        lastDelayTime = smoothedValue.getNextValue(); //do the smoothing
    }
}

Edit: it’s the same as selecting your code snippet when editing, and clicking on the tool button that has this symbol on it: </>

1 Like

Could you explain what high quality interpolation would be in comparison to linear? Specifically in terms of how to go about programming it? Thanks!

Sinc interpolation is generally considered “high-quality”, because it approaches a perfect reconstruction of the original (bandlimited) signal as more samples are included in the sum. For even higher quality, apply a sinc window function to the samples as well (see Lanczos resampling).

1 Like