Smoothing of dsp::Gain

Hi everyone!

I have a bit of a problem with smoothing my dsp::Gain in my audio plugin. What I basically would like to achieve is that whenever the buffer is hitting a certain threshold (set by a parameter) of the amplitude (volume) I want the gain to go down and then back up. The time that takes should be determined by another parameter (gain.setRampDurationSeconds()). The code kind of works but I still get this “glitches” everytime the threshold is reached, kind of as the gainramp only works to lower the volume and not when it is moving back up. Here is the relevant code from the process block:

float sample = *buffer.getWritePointer(0);

if (abs(sample) > *thresholdParameter) {

I have tried values of the smoothing between 0 and 5 seconds. I can hear some difference, especially between 0 and 1 seconds, but it is still glitchy.

I appreciate all the help and suggestions I can get, thank you for taking your time! :slight_smile:


That‘s not how it works, imagine what happens if you send a sine wave in whenever it crosses zero :wink:

Thanks for the reply!

I don’t think that matters to my plugin. If I understand you correctly, I have for example an incoming 500Hz sine wave. That period time is 1/500s, meaning the first peak will come after 1/4 of the period time 1/(500*4)=1/2000s. In my plugin, that response time is more than sufficient. Plus that the function itself do work, just not the smoothing.

I suppose the gain ramp is coded something like multiplying the buffer (block) with the previous gain down with a linear gain multiplication down to the desired gain level during the time you set in the setRampDurationInSeconds function. But it just don’t seem to do that as I would like it to.