How Does a Downward Expander Works?

I am new to JUCE and I am currently following Will C. Pirkle’s book “Designing Audio Effect Plugins in C++”. I have successfully implemented a compressor, but I am having difficulty implementing a downward expander as described in the book. Can anyone provide guidance on how to implement a downward expander?

1 Like

A downward expander sounds like it could just be like a noise gate. Except the signal below the threshold doesn’t get reduced to 0dB.

https://docs.juce.com/master/classdsp_1_1NoiseGate.html

The juce::dsp::NoiseGate class doc says it can be used like an expander

It’s like a noise gate, but instead of drastically cutting off the entire audio to silence at the threshold, it gradually becomes more dynamic the less you reach threshold depending on the ratio/knee control(s), just like how an extreme compressor is basically a brickwall limiter. some plugins, like pro-mb also have a lower range control, so that it never gates to complete silence. in a compressor lookahead leads to less transients, because it already pushes the signal down before the transient appears. but in an expander you know your lookahead is working when it does the opposite, when it finally lets through the entire transient, because it’s supposed to kick in the signal before the transient starts already

Compression reduces dynamic range while Expansion increases dynamic range. Upwards/Downwards refers to whether this is done by boosting or attenuating parts of the signal:

// Downwards compressor
if (input > threshold)
    output = threshold + (signal - threshold) / ratio
else
    output = input

// Upwards compressor
if (input < threshold)
    output = threshold + (signal - threshold) / ratio
else
    output = input

// Downwards expander
if (input < threshold)
    output = threshold + (signal - threshold) * ratio
else
    output = input

// Upwards expander
if (input > threshold)
    output = threshold + (signal - threshold) * ratio
else
    output = input

// Limiter
output = limit(0, threshold, input)
1 Like

if (input < threshold)
output = threshold + (signal - threshold) * ratio
else
output = input
I’m implementing this code, and the equation is the same as the book says, but I think it’s wrong. For example, if I have a threshold of -10dB, and the input is -20dB with a ratio of 2:1, the output signal must be -25dB.

output = threshold + (signal - threshold) * ratio
output = -10 + (-20 - (-10) ) * 2 = -30

1 Like

Why -25dB?

A ratio of 2:1 says the level below the threshold should be scaled by a factor of 2. So with a threshold of -10dB, and a signal level of -20dB, your signal is 10dB below the threshold. You then scale that to be 20dB below the threshold which gives you your output gain of -30dB.