# How to smooth the echo duration change to get rid of audio clicks?

I implemented an echo effect using the following diagrams:

To summarize, an echo effect is basically a positive feedback effect that is implemented with a delay line zD which delays the input signal by D samples. My effects works fine. I get the echo effect.

My issue is I gave the user to adjust D sample amount during runtime just like in Pioneer equiments you can set echo as 4beats, 2beats, 1beats etc. When a user request a beat duration change I immediatly change the D parameter in my audio plugin. The problem is sometimes this causes click due to sudden audio level changes. I am trying to find a way to counter this but so far I can not think of anyways to do it. How may I ensure that the audio level is continous(doesnt spike and result in audio clicks) when user changes the parameter D?

Maybe, when $$D$$ changes, you can crossfade from the audio at the old $$D$$ to audio at the new $$D$$.

If you ran a pitch detector alongside of the delay (and stored the detected period length in a corresponding array) you could crossfade one period at a time until you got to within a period of your new $$D$$. Then slide very slowly to the exact $$D$$.

• I tried cross fade with 16ms, the results got way better but somehow I sometimes do get clicks still. This audio click problem shows up everytime I work with audio. So frustrating. It ruins my code base too. Is there something like a general click detector algorithm to detect the clicks and smooth them? I really tried to find one but no luck. I notice this issue is even present on YouTube app. So I guess its not very easy to solve this issue... – cs guy Apr 23 at 2:32
• I think a 16 ms cross fade is long enough when $D$ changes smoothly. But since $D$ won't change all the time, you may try a longer cross fade. – ZR Han Apr 23 at 3:13
• 16 ms is the displacement of the crossfades, right? The difference between the initial $D$ and the final $D$, right? It's not necessarily the crossfade time, right? – robert bristow-johnson Apr 23 at 13:25
• @robertbristow-johnson 16ms it is the crossfade time between fading from initial $D$ to final $D$, here is how i used it in my code crossFadePerc * targetDelayVal + (1 - crossFadePerc) * curDelayVal; with each sample crossFadePerc increases from 0.0f to 1.0f – cs guy Apr 23 at 14:07
• I applied equal power cross fade (I've seen this in one of your posts) and pushed the cross fade value to my echo buffer and the results are very good. I am testing the results on a bass sample and I get very minimal noise alike sounds, clicks are gone. Thank your for helping. You are awesome. – cs guy Apr 23 at 15:44

One way to do this is to have a simple one pole smoothing filter. The one-pole lowpass filter is often used to smooth noisy signals to seek slow-moving trends in them. The one pole filter is defined as \begin{aligned} y(n) = x(n) + a_1 y(n-1)\\ H(z) = \frac{Y(z)}{X(z)} = \frac{1}{1-a_1z^{-1}} \end{aligned} The pole is located at $$z = a_1$$. In such applications where the parameter needs to be interpolated smoothly, the pole is typically located near DC, and you can use $$a_1 \approx 0.99$$. This means the output of your filter starts rolling off at a rate of -20dB/decade near 0Hz.

You are applying this filter to your parameter value, $$D$$, which is being changed by the user. This filter ensures that your parameter value changes smoothly (it filters out rapid changes), and does not cause any clicks in the audio. There must be a function in your plugin that takes care of that update. $$x(n)$$ is the input value from the slider, $$y(n)$$ will be the smoothed and filtered value that you will send to the echo effect in the audio callback function. In the update method, you will need to store the value of the last element that was output, $$y(n-1)$$, to calculate the current value of $$y(n)$$.

• Well this answer was too advanced for me to understand sadly, I haven't worked with filters before, there is a section about filters in the book I am reading, It is around 40 pages, I will read that and will check with this answer. Let me ask one thing, so basically your solution is to apply this filter after applying echo parameter change right? – cs guy Apr 22 at 18:30
• Also wouldn't a low pass filter alter the audio signal a lot? I've heard people suggesting low pass filters for clicks before but I was always hesitant since I wouldn't want my original audio signal to sound too different after smoothing with a Low pass, I might be wrong here, I'm very new to filters – cs guy Apr 22 at 18:50
• I have updated my answer, you are applying the low pass filter to the parameter value, not to the signal. It is just a filter to smooth out rapid changes in the slider value. – orchi_d Apr 22 at 19:12
• I tried something similar, I tried a linear interpolation on value change with 16ms (1 frame 60fps), the problem was it caused a strange audable audio, i suspected that it is because the ms change gets feed into feedback, I am not sure if my implementation was wrong or not tho, ie let's say you want to go from 2 beats to 1 beats, if you interpolate the feedback will use some values between 2beats and 1 beat causing a potential strange audio – cs guy Apr 22 at 20:35
• i debuged my code and, smoothing the D value actually causes strange audable audio, this is again probably due to smoothed data gets fed into the feedback causing strange additions, is there a way to solve my problem without parameter smoothing? – cs guy Apr 22 at 21:51