Dynamics Tutorial 2: Dynamics Processing
This tutorial looks at using envelope following techniques to create dynamics processors in MSP. Once we've derived the amplitude envelope of a waveform as a control signal, we can add patcher logic to make decisions on the overall gain of a signal. This allows us to make compressors, limiters, and gates based on the time-varying amplitude of our audio.
Audio compression and limiting
If we have an audio signal containing a wide range of amplitudes (such as a drum loop or expressive vocals) it's often necessary to reduce, or compress, this range. A compressor algorithm reduces the dynamic range of an audio signal by tracking its envelope and checking that value against a threshold number. When the audio signal exceeds the threshold, its gain is reduced by a scaling factor called a compression ratio. We can change the behavior of a compressor by adjusting its threshold and ratio, as well as by making intelligent decisions regarding the way in which the envelope signal is derived.
Our compression patcher contains the standard controls that we would find on a hardware compressor box or a dynamics plug-in for a DAW program. The 'Attack' and 'Decay' controls set parameters for the envelope following of the audio signal. These values (converted from milliseconds to samples by the * objects) set how fast the rampsmooth~ object allows the envelope to rise and fall based on the incoming signal. A long attack and decay will make the compressor circuit less responsive, but will also limit some of the artifacts associated with a highly responsive compressor, such as audible 'pumping' of the gain. The 'Threshold' and 'Ratio' controls alter how the compressor deals with scaling the gain. Our circuit implements the following equation to set the gain, where is the gain, is the envelope signal, and and are the threshold and ratio, respectively:
g = ( (e-t)*(1/r) + t ) / e; 0<=g<=1.
This gain value multislider objects labeled 'Enveloped' and 'Reduction'. The colors in the 'Reduction' multislider are flipped so that the colored area is greater as the gain is lower, visually cueing us into the fact that the audio volume is being attenuated by our compressor.is clipped in the range of to and then multiplied by our original audio to control its volume. The envelope value and output gain are shown in the patcher in the
A limiter is a compression circuit with an infinite compression ratio, i.e. sound above the threshold is attenuated to never exceed that threshold. For a limiter, theterm is infinite, zeroing out part of the equation:
g = t / e; 0<=g<=1.
The MSP circuit in this patcher starts on the same premise of a compressor: that of an envelope follower and a threshold. Rather than reducing the gain of audio energy that exceeds the threshold, however, this circuit attenuates signals that fall below it. This type of dynamics compression is called a gate (it is also sometimes referred to as a noise gate). Unlike a compressor, however, the gate has a knee setting instead of a compression ratio. This setting is a proportion of the threshold within which the audio is attenuated rather than cut altogether. So with the default settings in the tutorial patch, we can expect the following results:
Sound below and above (the threshold * the knee) are scaled between 0 and 1.
Sound below are gated out ( = 0)
In equation form, our gate looks something like this, whereis the gain, is the envelope signal, and and are the threshold and knee:
g = (e-(t*k)) / (t-(t*k); 0<=g<=1.
As with our compressor,is clipped between and .
Dynamics processors in MSP can be constructed using signal processing algorithms that take an envelope follower output as their control signal. Compressors and limiters attenuate audio signals that exceed a certain amplitude threshold according to their envelopes; gates attenuate audio that falls below a threshold. The parameters of the envelope follower itself control the responsiveness of the dynamics circuit, while parameters such as the threshold and ratio / kne. control the 'sound' of the processing.