You are on page 1of 38

Josh 

Reiss
Centre for Digital Music
Queen Mary, University of London
www.elec.qmul.ac.uk/digitalmusic/audioengineering/

UNDER THE HOOD OF A 
DYNAMIC RANGE COMPRESSOR

With thanks to Michael Massberg and


With thanks to Michael Massberg imitrios Giannoulis
and Dimitrios
Questions and Challenges
“No two compressors sound alike... each 
one is inaccurate in its own unique way” 
q y –
Roey Izhaki, Mixing Audio: Concepts, Theory and Practice

ƒ Given how a compressor is used, how can you build one?
ƒ How can you emulate an analog design?
ƒ What makes compressors sound different?
ƒ Why do attack and release times mean different things 
for different compressors?
p
ƒ How can you measure the performance of a compressor?
What we’re not going to talk about
ƒ How to use a dynamic range compressor
à Preferred parameter settings for different tasks
Preferred parameter settings for different tasks
ƒ How not to use a dynamic range compressor 
(Loudness war)
(Loudness war)
à But will show how better design helps prevent misuse
ƒ Hearing aids
à Still applicable, but we’re concerned with compressors for 
pp p
music production, mastering and broadcast
ƒ Sidechaining and parallel compression
Sidechaining and parallel compression
ƒ Multiband compression
ƒ Additional parameters
dd l
à Look‐ahead, hold...
Introducing the dynamic range compressor
ƒ map dynamic range of audio signal to smaller range 
à Reduce signal level of higher peaks while leaving quieter 
g g p gq
parts untreated
à Then (optionally) boosting whole signal to make it as 
Then (optionally) boosting whole signal to make it as
loud as, or louder than, original uncompressed signal
ƒ Unlike gain, delay, EQ, panning... 
Unlike gain delay EQ panning
à Poorly defined
‚ Not always agreed what compression parameters do
à An adaptive audio effect
‚ Action of the compressor depends on the input signal
à Nonlinear
‚ Generally noninvertible
Compressor Controls
ƒ Threshold‐ T
à level above which compression starts
ƒ Ratio‐ R
à determines the amount of compression applied.
p pp
ƒ Knee Width‐ W
à Controls transition in the ratio around the threshold
Controls transition in the ratio around the threshold
ƒ Make‐up Gain‐ M
à Used to match the output signal’s overall loudness to the original
U dt t h th t t i l’ ll l d t th i i l
ƒ Attack Time‐ τA
à Time to decrease gain once signal overshoots threshold
ƒ Release Time‐ τR
à Time to bring gain back to normal once signal falls below 
threshold
Main 
components
t

ƒ Side‐chain
Side chain
à Level detection xL [ n ] → y L [ n ]
‚ Estimate the ‘signal level’
g
à Decibel conversion ydB [n] = 20 log10 xdB [n]

à Ga
Gain computer
co pute xG [n] → yG [n]
‚ Apply threshold, ratio, knee
à Timing (Ballistics, Smoothing)
xT [n] → yT [n]
‚ Apply attack and release
ƒ Gain stage
g ydB [n] = xdB [n] + cdB [n] + M
ƒ Output is input multiplied by control vector produced by side‐
chain
Level Detection – the options

ƒ Peak vs RMS
à Peak detection ‐
Peak detection Based on absolute value of the signal
Based on absolute value of the signal
yL [n] =| xL [n] |

à RMS
RMS ‐ Based on square of the signal
B d f th i l
‚ Square of the level is average of square of the input
M / 2 −1
1
y L [ n] =
2

M

m =− M / 2
xL 2 [ n − m ]

Or Square of the level is smoothed estimate of square of the input
q q p
yL 2 [ n] = (1 − α ) yL 2 [ n − 1] + α xL 2 [ n]
Exponential Moving Average Filter

y[ n] = α y[ n − 1] + (1 − α ) x[ n]

ƒ Also known as smoothing filter, one pole low pass filter...
Also known as smoothing filter one pole low pass filter
ƒ Step response y[ n] = 1 − α n for x[ n] = 1, n ≥ 1

ƒ Time constant ‐ time it takes a system to reach 1‐1/e= 63% 
y /
of its final value y[τ f s ] = 1 − α τ fs = 1 − e −1

α = e −1/τ f s
Issues with RMS level detection

ƒ Introduces significant delay
Introduces significant delay
ƒ Introduces additional parameter, M or τ
ƒ Several studies suggest general behaviour is the same for 
peak & RMS detection
à F. Floru, "Attack and Release Time Constants in RMS‐Based 
Feedback Compressors," Journal of the Audio Engineering Society, 
vol. 47, pp. 788‐804, October 1999.
l 47 788 804 O t b 1999
à J. S. Abel and D. P. Berners, "On peak‐detecting and rms feedback 
and feedforward compressors " in 115th AES Convention, 2003.
and feedforward compressors, in 115th AES Convention 2003
The Gain Computer
Static Compression Curve

-5 Knee Width
yG (dB)

-10
10

-15

-20
20

-25
Make-up No compression
-30 Gain 5:1 compression, hard knee
5 1 compression,
5:1 i soft
ft kknee

-35

-40
Threshold
-45
-45 -40 -35 -30 -25 -20 -15 -10 -5 0
xG (dB)
0

The Gain Computer -5 Knee Width

yG (dB)
-10

-15

-20

-25
Make-up No compression

ƒ Compression ratio
-30 Gain 5:1 compression, hard knee

Compression ratio -35


5:1 compression, soft knee

-40

à Hard knee x −T
R= G for xG > T
-45
Threshold

-45 -40 -35 -30 -25 -20 -15 -10 -5 0


yG − T xG (dB)

⎧ xG xG ≤ T
yG = ⎨
⎩T + ( xG − T ) / R xG > T

à Soft knee
‚ Linear interpolation (bad)
⎧ xG 2( xG − T ) < −W

yG = ⎨T − W / 2 + ( xG − T + W / 2)(1 + 1/ R) / 2 2 | ( xG − T ) |≤ W
⎪ T + ( xG − T ) / R 2( xG − T ) > W

‚ Second order interpolation (good)
⎧ xG 2( xG − T ) < −W

yG = ⎨ xG + (1/ R − 1)( xG − T + W / 2) 2 / (2W ) 2 | ( xG − T ) |≤ W
⎪ T + ( xG − T ) / R 2( xG − T ) > W

Time constants
ƒ From the smoothing filter
ƒ Officially, time it takes a system to reach 1‐1/e= 63% of 
y, y / %
its final value
à τA – level starts at 0, goes to 1. Attack time is the time it 
level starts at 0 goes to 1 Attack time is the time it
takes for level to reach 0.63.
à τR – level starts at 1, goes to 0. Release time is the time it 
level starts at 1 goes to 0 Release time is the time it
takes for level to reach 1‐0.63=0.37.
ƒ But some compressors,
But some compressors
à Miscalculate it
à Define it as time to go from 90% of initial value to 10% of 
final value
à Define it as time to change level by so many dBs
à ...
Analog Peak Detector
RA

C RR

à Assuming ideal diode,
yT [ n] = α R yT [ n − 1] + (1 − α A ) max( xT [ n] − yT [ n − 1], 0)

‚ Where τA=RAC and τR=RRC


α A = e −1/τ f , α R = e −1/τ
A s R fs

à Used in
‚ D. Berners, 
D. Berners, "Analysis of Dynamic Range Control (DRC) Devices," 
Analysis of Dynamic Range Control (DRC) Devices,  
Universal Audio WebZine, vol. 4, September 2006.
‚ P. Dutilleux and U. Zölzer, "Nonlinear Processing, Chap. 5," in 
g p
DAFX ‐ Digital Audio Effects, U. Zoelzer, Ed., 1st ed: Wiley, John 
& Sons, 2002
Analog Peak Detector 
1.0
Input signal
Peakk detector,
P d t t 50ms50 release
l ti
time
0.9 Peak detector, 200ms release time
Peak detector, 500ms release time
0.8
0.7
0.6
Voltage
0.5
0.4
0.3
0.2
0.1
0.0
0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0
Time (sec)
n −1
1−αA τR
y[n] = (1 − α A ) ∑ (α R + α A − 1) m → ≈
ƒ Step response m=0 2 −αR −α A τ R +τ A

ƒ correct peak estimate only when release time is 
considerably longer than attack time
ƒ attack time gets slightly scaled by release time
à faster attack time than expected when we use a fast release 
faster attack time than expected when we use a fast release
time
Decoupled Peak Detector
_ RA

+
CA
CR RR

y1[n] = max( xT [n], α R y1[n − 1])


yT [n] = α A yT [n − 1] + (1 − α A ) y1[n]

ƒ attack envelope is now impressed upon release 
envelope
ƒ good estimate of actual release time given by adding 
good estimate of actual release time given by adding
attack time constant to release time constant
Branching Peak Detector
⎧α A yT [n − 1] + (1 − α A ) xT [n] xT [n] > yT [n − 1]
yT [n] = ⎨
⎩ α R yT [n − 1] xT [n] ≤ yT [n − 1]

ƒ Easily accomplished in digital implementation
y p g p

G. W. McNally, 
G. W. McNally, "Dynamic
Dynamic Range Control of Digital Audio 
Range Control of Digital Audio
Signals," Journal of the Audio Engineering Society, vol. 32, 
pp
pp. 316‐327, May 1984.
, y
U. Zolzer, Digital Audio Signal Processing, 2nd ed.: John Wiley 
and Sons, Ltd., 2008.
, ,
Time constants in decoupled & branching peak detectors
1.0

0.9 Input Signal


Decoupled, τA=100ms, τR=200ms
Branching, τA=100ms, τR=300ms
0.8
Decoupled, τA=100ms, τR=100ms
Branching, τA=100ms, τR=200ms
0.7

nal Level
0.6

05
0.5
Sign

0.4

0.3

0.2

0.1

0.0
0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0
Time (sec)

ƒ Output of decoupled and branching peak detector circuits 
Output of decoupled and branching peak detector circuits
for different release time constants
à branching
branching peak detector produces intended release time constant
peak detector produces intended release time constant
à decoupled peak detector produces measured  time constant ~ τA+τR.
Smooth, level corrected peak detector
ƒ Smooth decoupled peak detector
] α R y1[n − 1] + (1 − α R ) xT [n])
y1[n] = max( xT [n],
yT [n] = α A yT [n − 1] + (1 − α A ) y1[n]
ƒ Smooth branching peak detector
S hb hi kd
⎧α A yT [n − 1] + (1 − α A ) xT [n] xT [n] > yT [n − 1]
yL [ n] = ⎨
⎩α R yT [n − 1] + (1 − α R ) xT [n] xT [n] ≤ yT [n − 1]

à Used
Used in
in
‚ P. Dutilleux, et al., "Nonlinear Processing, Chap. 4," in 
Dafx:Digital Audio Effects, 2nd ed: Wiley, 2011, p. 554.
Audio Effects, 2nd ed: Wiley, 2011, p. 554.
‚ U. Zolzer, Digital Audio Signal Processing, 2nd ed.: John Wiley 
, ,
and Sons, Ltd., 2008.
Comparison of Digital Peak Detectors
ƒ All envelopes reach maximum peak value and feature similar attack trajectories
ƒ Release envelopes too short for decoupled and branching peak detectors
ƒ smoothed versions make full use of release time
ƒ Discontinuity for smooth, branching peak detector
y gp
ƒ abrupt switch from attack to release
à release envelope is continuous for smoothed, decoupled peak detector
1.0

0.9 1.0 Inset

0.8
09
0.9
0.7
Signall Level

0.6 0.8
0.25 0.30 0.35
0.5 Input
Decoupled
0.4 Branching
Decoupled, smooth
03
0.3 B
Branching,
hi S
Smooth
th

0.2

0.1

0.0
0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0
Time (ms)
Feedforward or feedback design

ƒ Feedforward
ydB = cdB + xdB
ydB = T + ( xdB − T ) / R

cdB = (1 / R − 1)( xdB − T )

ƒ Feedback
ydB = cdB + xdB
ydB = T + ( xdB − T ) / R

cdB = (1 − R )( ydB − T )

à Limiter (ratio of 
Limiter (ratio of ∞:: 1) needs infinite negative amplification
1) needs infinite negative amplification
à Not designed for look‐ahead 
Sidechain configuration

à Level detection xL [ n ] → y L [ n ]

à Decibel conversion
Decibel conversion ydB [n] = 20 log10 xdB [n]

à Gain computer xG [n] → yG [n]

à Timing (Ballistics, Smoothing)
Timing (Ballistics Smoothing) xT [n] → yT [n]
Timing Placement‐ linear domain

xT [n] = yL [n]
xG [n] = 20 log10 yL [n]
cdB [n] = yG [n] − xG [n] + M

ƒ R. J. Cassidy, "Level Detection Tunings and Techniques for the Dynamic Range 
Compression of Audio Signals," in 117th AES Convention, 2004.
ƒ J. S. Abel and D. P. Berners, "On peak‐detecting and rms feedback and 
J S Ab l d D P B "O k d t ti d f db k d
feedforward compressors," in 115th AES Convention, 2003.
ƒ U. Zolzer, Digital Audio Signal Processing, 2nd ed.: John Wiley and Sons, Ltd., 2008.
, g g g, y , ,
ƒ P. Hämäläinen, "Smoothing of the Control Signal Without Clipped Output in Digital 
Peak Limiters," in International Conference on Digital Audio Effects (DAFx), 
Hamburg Germany 2002 pp 195 198
Hamburg, Germany, 2002, pp. 195‐198.
ƒ S. J. Orfanidis, Introduction to Signal Processing Orfanidis (prev. Prentice Hall), 
2010.
Timing Placement‐ biased linear domain

xT [n] =| xL [n] | −10T / 20


xG [n] = 20 log10 ( yT [n] + 10T / 20 )
cdB [n] = yG [n] − xG [n] + M

ƒ Attack and release now depend on threshold, not zero
ƒ Envelope smoothly fades out once signal falls below 
threshold
Timing Placement‐ linear domain, post‐gain

xG [n] = 20 log10 xL [n]


xT [n] = 10( yG [ n ]− xG [ n ]+ M ))/ 20
c[n] = yT [n]

ƒ J. Bitzer and D. Schmidt, "Parameter Estimation of Dynamic 
J Bit d D S h idt "P t E ti ti fD i
Range Compressors: Models, Procedures and Test Signals," 
presented at the 120th AES Convention 2006
presented at the 120th AES Convention, 2006
ƒ L. Lu, "A digital realization of audio dynamic range control," in 
Fourth International Conference on Signal Processing 
g g
Proceedings (IEEE ICSP), 1998, pp. 1424 ‐ 1427.
Timing Placement‐ log (dB) domain

xG [n] = 20 log10 xL [n]


xT [n] = xG [n] − yG [n]
cdB [n] = M − yT [n]

ƒ S. Wei and W. Xu, "FPGA implementation of gain calculation using a 
S W i d W X "FPGA i l t ti f i l l ti i
polynomial expression for audio signal level dynamic compression," 
J Acoust Soc Jpn (E) vol 29 pp 372‐377
J. Acoust. Soc. Jpn. (E), vol. 29, pp. 372 377, 2008.
2008
ƒ S. Wei and K. Shimizu, "Dynamic Range Compression Characteristics 
Using an Interpolating Polynomial for Digital Audio Systems," IEICE 
g p g y g y ,
Trans. Fundamentals, vol. E88‐A, pp. 586‐589, 2005.
Performance – sidechain configuration
0.0
Linear domain
Biased, linear domain
Log domain
-0.2

B)
Gain (dB -0.4

-0.6

0.0 0.2 0.4 0.6 0.8 1.0


Time (sec)
gain envelope produced by different placement of 
ballistics in sidechain configurations
ƒ release discontinuity in linear domain return‐to‐zero detector
ƒ linear domain return‐to‐threshold (biased) and log domain detector 
curves look similar
à faster attack, slower release for linear domain return‐to‐threshold 
Performance‐ Artifacts
ƒ How can we measure and characterise performance of a 
compressor?
ƒ Most artifacts associated with parameter settings, not 
design
g
à Dropouts
‚ Long release ‐> keeps attenuating after transient finished
à Overshoot
‚ Long attack ‐> misses attenuation of initial transient
à Lack of clarity
‚ Short attack ‐> squash all transients
à Pumping
‚ Short release ‐> jump in signal level after transient
à Breathing
B hi
‚ Noticeable movement of noise floor
Performance‐ Noise and Distortion
ƒ Signal to Noise Ratio
Signal to Noise Ratio
à Not useful
ƒ Total Harmonic Distortion
à Measures strength of harmonics (introduced by 
g ( y
compression) in relation to original frequency
28

24

20
THD ((%)

Compressor Design
g
Branching
16 Decoupled
Branching Smooth
Decoupled Smooth
12

0
2 3 4
10 10 10
Frequency (Hz)
Performance – frequency dependence
ƒ Effective compression ratio
à used in assessing compressors in cochlear implants and 
g p p
hearing aids
à amplitude modulated sine wave
amplitude modulated sine wave applied at input
applied at input
x[n] = (1 + m cos(2π f m n)) cos(2π f c n)

à spectrum consists of a carrier and two side bands
i f i d id b d
à ΔSi difference between amplitude of side bands and 
amplitude of carrier of input signal
à ΔSo difference between amplitude of side bands and 
p
amplitude of carrier of compressed signal is found,. 
effective compression ratio is then given by ΔSi/ΔSo.
à effective compression ratio is then given by ΔS
Performance – effective compression ratio
6.5

pression Ratio
6.0 Compressor Design
Branching
55
5.5 Decoupled
Branching Smooth
5.0 Decoupled Smooth

45
4.5
Effectivve Comp

4.0
3.5
3.0
2.5
2.0

4 8 12 16 20 24 28 32 36
Modulation Frequency (Hz)

à Interpretation?
Performance‐ Ballistics and sidechain configuration
Detector Fidelity
y of Envelope
p Shape
p (FES)
( )
Detector Type
Placement Guitar Bass Drums Vocals

Branching 0.884 0.945 0.766 0.952

Decoupled 0.899 0.932 0.755 0.941


Fidelity of the 
Fid lit f th Log
domain Branching Smooth 0.852 0.927 0.640 0.941
envelope shape
Decoupled Smooth 0 859
0.859 0 911
0.911 0 648
0.648 0 936
0.936

Branching 0.836 0.879 0.517 0.932

Decoupled 0.790 0.831 0.537 0.930

Linear
domain Branching Smooth 0.825 0.856 0.456 0.932

Decoupled Smooth 0 775


0.775 0 805
0.805 0 461
0.461 0 934
0.934

ƒ Measures correlation between envelopes of compressed and 
uncompressed signals
uncompressed signals
ƒ Nonsmooth designs do well since they often apply no compression
ƒ Placing ballistics (attack and release) in log domain outperforms 
Pl i b lli ti ( tt k d l )i l d i t f
placing them in linear domain
Pseudocode
% Smoothed branching digital dynamic range compressor.
% Parameters
% x: input signal
% fs: sample rate (kHz)
% tauAttack: attack time constant (ms)
% tauRelease: release time constant (ms)
% T
T: l
logarithmic
ith i th
threshold
h ld
% R: compression ratio
% W: decibel width of the knee transistion
% M: decibel Make-up Gain
% Returns
% y: output (compressed) signal
%LEVEL DETECTION
y_L = max(abs(x), 1e-6);
Pseudocode
%DECIBEL CONVERSION
x_dB= y_L;
y_dB = 20*log10(x_dB);
x_G=y_dB;
%GAIN COMPUTER
slope = 1 / Ratio - 1;% Feed-forward topology
overshoot = x_G - T;
;
if (overshoot <= -W/2)
y_G =x_G;
if ((overshoot > -W/2) & (overshoot < W/2))
y_G =x_G+slope* (overshoot + W / 2) .^ 2/ (2*W) ;
if (overshoot >
>= -W/2)
W/2)
y_G =x_G+slope* overshoot ;

x_T=y_G-x_G;
Pseudocode
%BALLISTICS
alphaAtt = exp(‐1 / (tauAttack * fs));
alphaRel = exp(‐1 / (tauRelease * fs));
if x_T(0) > 0
y_T(0) = (1‐alphaAtt)*x_T(0);
else
y_T(0) = (1‐alphaRel)*x_T(0);
end
for i=2:length(x_T)
if x_T(i) > y_T(i‐1)
y_T(i)= alphaAtt * y_T(i‐1) + (1‐alphaAtt)*x_T(i);
else
y_T(i)= alphaRel * y_T(i‐1) + (1‐alphaRel)*x_T(i);
end
d
end
c_dB = M‐y_T; %CONTROL VECTOR, WITH MAKE‐UP GAIN
gain = 10.^(c_dB./20); %CONVERT TO LINEAR
y = x .* gain; %GAIN STAGE
The big unknown – psychoacoustics
ƒ Compressor designs 
à in the literature: >20
in the literature: >20
à Commercial designs: >40
ƒ Studies of parameter settings 
Studies of parameter settings
à for hearing aids: >10
à for music production and broadcast: 0 ?
‚ Anecdotal recommendations : 10? 
ƒ Studies of compressor designs 
à for hearing aids: <5?
for hearing aids: <5?
à for music production and broadcast: 0 !
Recommendations
ƒ Feedforward compressors are preferred 
à more stable and predictable than feedback designs
bl d di bl h f db k d i
à Benefits of feedback designs are only relevant in analog
ƒ Peak level detection suggested over RMS
à RMS introduces additional parameter
‚ Often not user controlled
à Smoothing done anyway by attack and release
à May introduce unnecessary delay
ƒ Soft knee with high order interpolation
Soft knee with high order interpolation
à Linear interpolation gives two hard knees
Recommendations
ƒ Ballistics in the log domain after the gain computer
Ballistics in the log domain after the gain computer
à Maintain envelope shape
à no attack lag
tt k l
à easy implementation of variable knee width
ƒ Smooth, peak detector for attack and release
à Decoupled 
‚ Low harmonic distortion
‚ Prevent discontinuities
à Branching
‚ detailed knowledge of the effect of the time constants
‚ Minor discontinuities in the slope of the gain curve
d h l f h
ƒ Make‐up gain at end of side‐chain
à Agrees with expected use
à Not intended or needed to be smoothed
Thanks
ƒ Michael Massberg
à See his talk this afternoon, at 2:30pm
à “Digital Low‐Pass Filter Design with Analog Matched Magnitude 
Response”
ƒ Dimitrios Giannoulis

You might also like