Newb - whats the theory behind "gain matching" (making sure the outgoing signal has same volume compared to the incoming one)?

Lets say I’m making a simple Saturation plugin.
Adding saturation to a signal increases its volume.
How can I go about doing a “gain match” (or I think its sometimes called level-matching) so that the outgoing signal has the saturation effect on it, but its not “louder” ?

There’s a whole world to go into on this topic, and there’s no one size fits all solution that I’m aware of.

First, the waveshaping algorithm by nature is nonlinear, so it will usually boost level at some range and attenuate it at others. So the compensation required will depend on the source material. Some more recent implementations I’ve seen kicking around have a ‘learn’ button that will measure the loudness (rms or lufs) of the input and output signals for a short while (5 seconds or so) and then apply gain to make the difference. This is a pretty good method as it will be precise. The downside is you have to relearn every time you tweak settings. I’ve seen this taken a step further where a part of the learning process will establish a relationship to the threshold parameter so gain will then be adjusted with the threshold after the initial learning.

Another thing I’ve seen floated is a constant running rms comparison of input and output which actively adapts as the gap widens. The problem with this is: this is introducing dynamics into a process which is probably intended to remove dynamics. Active auto gain IMO is acting against the process preceding it, and I much prefer static auto gain that only changes as parameters do.

1 Like

Thanks, thats helpful. :+1: The “learn” algorithm sounds good, but 5 seconds seems a lot before the volume adjustment kicks in.

Also note that I don’t think you want to match the volume, but rather match the perceived loudness, which is a totally different thing alltogether.
You could look into loudness like algorithms like RMS or R128 for this.

1 Like

if you decided for a specific overall input volume to be the sweetspot of your plugin and also considered that the user always goes into it with a rather naturally distributed spectrum (pink noise) you could make an autogain feature by calculating the ratio between a burst of pink noise and the same burst of pink noise processed by different parameter values and using that value as your gain. that works perfectly fine with linear processors like filters, but it is tricky with nonlinear ones. the good thing about it is that it will not adapt to your signal constantly, so that the user is not confused why the gain changes after a while. every amount of drive corresponds to a specific gain match value. another downside of this technique is that you need to consider multiple dimensions of parameter value combinations if you want to incorporate multiple parameters into the system, like with filter(cutoff, reso) etc. it’s not hard to code, but i find it hard to write such a thing in a generalisable form.

here’s some resources on how to make pink noise: DSP Generation of Pink Noise

1 Like

Out of interest, has anyone here ever found auto gain to actually work? In my experience, it’s a total marketing gimmick. Yes, it can apply make up gain in an automatic way, but it’s never quite right in terms of perceived loudness. So I still find myself manually adjusting gain, so all it really does is change your starting point, from one wrong to another wrong.

1 Like

i see it more as a nice starting point. if your autogain works well you don’t have to give your plugins’ out gain knobs a -70 to 70db range or something like that

1 Like