Newbie question: compression algorithm

Hi all,
I’m a complete newbie to this forum. How can I find the algorithm specifics about the compression in the Effects menu? Specifically, how is the rms computed. I mean equations. What does “use peak” actually mean. Can I use a non-causal filter for the power estimation. define noise floor.

Please excuse a newbie if I am asking in the wrong forum and kindly redirect me.

Thanks very much.

Topic moved to the Audio Processing forum.

Interesting questions. I’m not sure how much detail you want, so to start, here is the manual page for the Compressor effect:

I realize that the Audacity Compressor is not very “intuitive” to use, so if you have further questions or require clarification, please ask.

In response to steve (moderator),

I would like to know some more than what is in the manual page. If I ask too much, please direct me to the appropriate place.

I assume the RMS measure is on a rectangular window at a fixed “look ahead” offset (apparently 1/3 sec).

Question: what is the size of the RMS measuring window?

The “make-up for 0 gain” switch seems to be
made-up_gain(x) = compression_gain(x) + compression_gain(0)

The “use peak …” switch seems to use the same RMS (not a peak) measure for input , then does something else.

Question: what does the gain function actually do when the “peak” switch is on?

Wishful thinking: I would love to provide my own input/output or input/gain function or table to provide multiple compression knees and ratios.

I don’t currently have access to a Matlab (ok, Mathworks. hey, I’m really old), to write my own function. (I’m not only old, but lazy and stupid).

Any pointers or advice would be greatly appreciated.

Chris’s Compressor” plugin for Audacity allows you to set knees, as does the compressor plugin “SC4”.

You could compress in two or more passes, each with different thresholds / knees / ratios, rather than going to the length of creating a custom compression function which did everything in one pass.

The “Make up gain” is named incorrectly imho. It is actually a kind of “normalizing”. When selected, the output of the compressor is amplified such that the peak amplitude is 0 dB. If the compressor is applied to multiple tracks or to multi-channel (stereo) tracks, the same amount of post-compressor amplification is applied to all channels/tracks. The track/channel that has the highest peak level after compression will be amplified to 0 dB, and all other tracks/channels are amplified by that amount.

I’m not sure about the rms measurement off the top of my head - I’ll need to look that up and get back to you.

“Nyquist” could be just the thing for you :wink:
Nyquist is a high level programming language based on LISP (XLISP), that is designed for generating, processing and analysing audio, and it included in Audacity. As a high level language with lots of built in DSP primitives, developing effects and algorithms can be much easier and quicker than using a lower level language (and much easier than MatLab).

Nyquist has two forms of syntax: There is the original XLISP syntax, and a newer syntax called SAL which is more C/C++ like. If you have experience with C/C++ you would probably find SAL more comfortable, otherwise I would recommend starting with the LISP syntax as that is what people on this forum use so we can provide better support for that.

See here for an introduction to Nyquist in Audacity:

It appears to be a 100 sample square window.

Some additional information about the algorithm:
The compressor creates an “envelope” that follows the peaks of the signal (or rms signal), and then applies gain according to the level of that envelope. The “follow” algorithm comes from an algorithm in Nyquist (by Professor Roger B. Dannenberg) and is described in the code comments:

"Follow"ing algorithm by Roger B. Dannenberg, taken from
Nyquist. His description follows. -DMM

Description: this is a sophisticated envelope follower.
The input is an envelope, e.g. something produced with
the AVG function. The purpose of this function is to
generate a smooth envelope that is generally not less
than the input signal. In other words, we want to “ride”
the peaks of the signal with a smooth function. The
algorithm is as follows: keep a current output value
(called the “value”). The value is allowed to increase
by at most rise_factor and decrease by at most fall_factor.
Therefore, the next value should be between
value * rise_factor and value * fall_factor. If the input
is in this range, then the next value is simply the input.
If the input is less than value * fall_factor, then the
next value is just value * fall_factor, which will be greater
than the input signal. If the input is greater than value *
rise_factor, then we compute a rising envelope that meets
the input value by working bacwards in time, changing the
previous values to input / rise_factor, input / rise_factor^2,
input / rise_factor^3, etc. until this new envelope intersects
the previously computed values. There is only a limited buffer
in which we can work backwards, so if the new envelope does not
intersect the old one, then make yet another pass, this time
from the oldest buffered value forward, increasing on each
sample by rise_factor to produce a maximal envelope. This will
still be less than the input.

The value has a lower limit of floor to make sure value has a
reasonable positive value from which to begin an attack.

Make-up-gain is a very common name for the post-compressing normalisation. It simply means that the effect “makes up” for the loss by the compression ratio (input 0 dB >> comp thres -6 dB/Ratio 1:2 >> output -3dB >> make-up-gain 0 dB or other).
What equation do you want for RMS? The general ones or those specific to the Audacity compression?
The RMS is unfortunately not standardised.
I quote here an excerpt from a recent post of mine. It actually deals with the question if RMS makes sense for one sample. However, it should apply to RMS in general.

There are 4 types of RMS which are facetiously
interchanged among physicians, statisticians and others.
One is defined with mean correction (=standard deviation) the other without. And both can be biased or estimated when the signal is only a portion of a longer or continuous one. Examples for a single value:

Peak-value: -0.8
Mean (DC): -0.8 (x/1)
General RMS: 0.8 [sqrt (x^2)1/n ;n=1]
RMS (std-dev): 0 [sqrt((x-mu)^2/n) ;n=1, mu=mean)
RMS (biased/estimated std-dev): divide by 0 error [same as above but divided by n-1]

Nyquist uses the first implementation (the general, unbiased one)
Code: Select all
(setf peak (snd-from-array 0 1 #(-0.8)))
(print (snd-fetch (rms peak 1)))

Excel has the second one, both biased and unbiased.
Math world defines the RMS as the second one (special case of power mean)
Analog devices make use of the definitions for continuous signals and apply also some “math tricks” via the built-in circuits.

It really depends on what you want to do in order to select the right one.

  • subtracting the mean compensates for a DC offset.
  • For a single number (over a whole song) the unbiased version is appropriate.
  • for a sample data set (a portion of the sound) dividing by (n-1) yields more reliable results.
    The last holds particularly true for short time series.
    See also here:
    for comparison of power spectra.

but NOT in the case of the Audacity Compressor effect.
“Make-up gain” usually, as you say, makes up for the reduction in level due to the (downward) compression, but in the case of the Audacity Compressor effect that is not how it works (which imho is a bug). In the Audacity Compressor effect, the (so called) Make-up gain normalizes to 0 dB regardless of the input level.

To illustrate the difference:
With a “conventional” compressor, if the compressor threshold is set at -6 dB (hard knee), and the ratio is set to 2:1, then a 0 dB input signal will be compressed down to -3 dB, so make-up gain will be +3 dB. Thus, if the input signal has a level of -12 dB, it is below the threshold so it will not be compressed, and the output level will be -9 dB (3 dB higher than the input level due to the +3 dB make-up gain.

For the Audacity compressor with the same settings, a 12 dB input signal is still below the compression threshold, so before make-up gain the level is -12 dB, but if the (so called) make-up gain is enabled it will be normalized to 0 dB.