<<

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

UNDER THE HOOD OF A COMPRESSOR

With thanks to Michael Massberg and Dimitrios Giannoulis Questions and Challenges

“No two compressors sound alike... each one is inaccurate in its own unique way” – 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? ƒ 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 ƒ How not to use a dynamic range compressor ( war) à But will show how better design helps prevent misuse ƒ Hearing aids à Still applicable, but we’re concerned with compressors for music production, and broadcast ƒ Sidechaining and parallel compression ƒ Multiband compression ƒ Additiona l parameters à 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 parts untreated à Then (optionally) boosting whole signal to make it as loud as, or louder than, original uncompressed signal ƒ Unlike gain, , 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. ƒ Knee Width‐ W à Controls transition in the ratio around the threshold ƒ Make‐up Gain‐ M à UdUsed to mathtch the outttput siil’gnal’s overall lldoudness to the oriiigina 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

ƒ Side‐chain à Level detection xLL[]nyn→ [] ‚ Estimate the ‘signal level’

à Decibel conversion yndB[]= 20log10 xn dB [] à Gain com puter xGG[]nyn→ [] ‚ Apply threshold, ratio, knee à Timing (Ballistics, Smoothing) xnTT[]→ yn [] ‚ Apply attack and release ƒ Gain stage yndB[]=++ xncn dB [] dB [] M ƒ Output is input multiplied by control vector produced by side‐ chain Level Detection –the options

ƒ Peak vs RMS à Peak detection ‐ Based on absolute value of the signal

ynLL[]= | xn []| à RMS ‐ BdBased on square of the siilgnal ‚ Square of the level is average of square of the input

M /2− 1 221 ynLL[]= ∑ xnm [− ] M mM=− /2 Or Square of the level is smoothed estimate of square of the input

222 yLLL[](1)[1][]n =−ααy nxn −+ Exponential Moving Average Filter

yn[]= α yn [−+− 1](1α )[] xn ƒ Also known as smoothing filter, one pole low pass filter...

ƒ Step response n y[]nxnn= 1−=≥α for [] 1, 1

ƒ Time constant ‐ time it takes a system to reach 1‐1/e= 63%

τ fs −1 of its final value yf[]1ταs = −=− 1e → α = e−1/τ fs Issues with RMS level detection

ƒ 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, OtbOctober 1999. à J. S. Abel and D. P. Berners, "On peak‐detecting and rms feedback and feedforward compressors," in 115th AES Convention, 2003. The Gain Computer

Static Compression Curve

0

-5 Knee Width dB)

( -10 G y -15

-20

-25 Make-up No compression -30 Gain 5:1 compression, hard knee 515:1 compress ion, so ftkft knee -35

-40 Threshold -45 -45 -40 -35 -30 -25 -20 -15 -10 -5 0 xG (dB) 0 The Gain Computer -5 Knee Width

(dB) -10 G y -15

-20

-25 Make-up No compression -30 Gain 5:1 compression, hard knee 5:1 compression, soft knee ƒ Compression ratio -35 -40 Threshold à Hard knee xTG − -45 RforxT= G > -45 -40 -35 -30 -25 -20 -15 -10 -5 0 x (dB) yTG − G

⎧ xGGxT≤ yG = ⎨ ⎩TxTRxT+ ()/GG−> à Soft knee ‚ Linear interpolation (bad)

⎧ xGG2(xT− ) <− W ⎪ yGG= ⎨TW−+−++/2 ( x TW /2)(1 1/ R )/2 2|( x G −≤ T )| W ⎪ ⎩ TxTR+−()/GG 2() xTW −> ‚ Second order interpolation (good)

⎧ xGG2(xT− ) <− W ⎪ 2 yGG= ⎨x+−−+(1 / R 1)( xTW G / 2) / (2 W ) 2 | ( xT G −≤ ) | W ⎪ ⎩ TxTR+−()/GG 2() xTW −> Time constants ƒ From the smoothing filter ƒ Officially, time it takes a system to reach 1‐1/e= 63% of its final value

à τA – 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 takes for level to reach 1‐0.63=0.37. ƒ 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,

ynTRT[]= α yn [−+− 1](1α A )max([] xn TT − yn [ − 1],0)

‚ Where τA=RAC and τR=RRC

−−1/ττA fsRs 1/ f α AR= ee,α = à Used in ‚ DD.. BBerners,erners, "Analysis of DDynamicynamic Range Control ((DRC)DRC) DDevices,evices," Universal Audio WebZine, vol. 4, September 2006. ‚ P. Dutilleux and U. Zölzer, "Nonlinear Processing, Chap. 5," in DAFX ‐ Digital Audio Effects, U. Zoelzer, Ed., 1st ed: Wiley, John & Sons, 2002 Analog Peak Detector 1.0 Input signal 0.9 PkdttPeak detector, 50 ms rel ease ti me Peak detector, 200ms release time 0.8 Peak detector, 500ms release time 0.7

e 0.6 0.5 Voltag 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 m 1−ατAR yn[]=− (1ARA )∑ ( + − 1) → ≈ ƒ Step response m=0 2 −α RARA−+αττ ƒ 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 time Decoupled Peak Detector

_ RA

+ CA CR RR

yn11[]=− max([], xTR nα yn [ 1])

ynTAT[]= αα yn [− 1](1+ − A ) yn1 [] ƒ attack envelope is now impressed upon release envelope ƒ good estimate of actual release time given by adding attack time constant to release time constant Branching Peak Detector

⎧ααATyn[− 1](1+− A ) xn T [] xn T [] > yn T [ − 1] ynT []= ⎨ ⎩ α RTyn[[1]−1][][ xn T [][1]≤−≤ yn T 1]

ƒ Easily accomplished in digital implementation

G. W. McNally, "Dynamic Range Control of Digital Audio Signals," Journal of the Audio Engineering Society, vol. 32, pp. 316‐327, May 1984. U. Zolzer, Digital Audio , 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, τ =100ms, τ =300ms 0.8 A R Decoupled, τA=100ms, τR=100ms Branching, τ =100ms, τ =200ms 0.7 A R

0.6 al Level

nn 050.5 Sig 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 for different release time constants à branching 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

yn11[]==+ max([] xnTR,αα yn[1](1)[]) [− 1](1+ − RT ) xn [])

ynTAT[]=−+−αα yn [ 1](1 A ) yn1 [] ƒ ShSmooth bhibranching peak detector

⎧ααA ynTATTT[− 1](1+− ) xn [] xn [] > yn [ − 1] ynL []= ⎨ ⎩ααRTyn[− 1](1+− R ) xn T [] xn T [] ≤ yn T [ − 1] à Used in ‚ P. Dutilleux, et al., "Nonlinear Processing, Chap. 4," in Dafx:Digital Audio Effects, 2nd ed: Wiley, 2011, p. 554. ‚ U. Zolzer, Digital , 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 ƒ abrupt switch from attack to release à release envelope is continuous for smoothed, decoupled peak detector 1.0

0.9 1.0 Inset

0.8 090.9 0.7

0.6 0.8 0.25 0.30 0.35 Level ll 0.5 Input Decoupled Signa 0.4 Branching Decoupled, smooth 030.3 BhiSthBranching, Smooth 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

ycxdB=+ dB dB

yTxTRdB=+()/ dB − →

cRxTdB= (1 /−− 1)( dB )

ƒ Feedback

ycxdB= dB+ dB

yTxTRdB=+()/ dB − →

cRyTdB= (1−− )( dB )

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

x []nyn→ [] à Level detection LL yn[ ]= 20log xn [ ] à Decibel conversion dB10 dB

à Gain computer xGG[]nyn→ [] xn[]→ yn [] à Timing (Ballistics, Smoothing) TT Timing Placement‐ linear domain

xnTL[]= yn []

xGL[]nyn= 20log10 []

cndB[]= ynxnM G []−+ G []

ƒ R. J. Cassidy, "Level Detection Tunings and Techniques for the Dynamic Range Compression of Audio Signals," in 117th AES Convention, 2004. ƒ J. S. Abe l and D. P. Berners, "On peak‐dtdetec ting and rms fdbkfeedback and feedforward compressors," in 115th AES Convention, 2003. ƒ U. Zolzer, Digital Audio Signal Processing, 2nd ed.: John Wiley and Sons, Ltd., 2008. ƒ 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. ƒ S. J. Orfanidis, Introduction to Signal Processing Orfanidis (prev. Prentice Hall), 2010. Timing Placement‐ biased linear domain

T /20 xnTL[]=− | xn []|10 T /20 xnGT[]=+ 20log(10 yn [] 10 )

cndB[]=−+ ynxnM G [] G [] ƒ Attack and release now depend on threshold, not zero ƒ Envelope smoothly fades out once signal falls below threshold Timing Placement‐ linear domain, post‐gain

xnGL[]= 20log10 xn[]

([][])yGGnxnM− + /20 xnT []= 10

cn[]= yT [] n ƒ J. Bitzer and D. SShchm idt, "Paramet er EtiEstima tion of DDiynamic Range Compressors: Models, Procedures and Test Signals," presented at the 120th AES Convention, 2006 ƒ L. Lu, "A digital realization of audio dynamic range control," in Fourth International Conference on Signal Processing Proceedings (IEEE ICSP), 1998, pp. 1424 ‐ 1427. Timing Placement‐ log (dB) domain

xGL[]nxn= 20log10 []

xTGG[]nxn= []− y []n

cndB[]=− Myn T [] ƒ S. WiWei and W. Xu, "FPGA ilimplemen ttitation of gain calltilculation using a polynomial expression for audio signal level dynamic compression," J. Acoust. Soc. Jpn. (E), vol. 29, pp. 372‐377, 2008. ƒ S. Wei and K. Shimizu, "Dynamic Range Compression Characteristics Using an Interppgolating Polynomial for Digital Audio Syy,stems," IEICE Trans. Fundamentals, vol. E88‐A, pp. 586‐589, 2005. Performance –sidechain configuration 0.0

Linear domain Biased, linear domain Log domain

) -0.2 BB

Gain (d -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 à Dropouts ‚ Long release ‐> keeps attenuating after transient finished à Overshoot ‚ Long attack ‐> misses attenuation of initial transient à Lack of clarity ‚ Short attack ‐> squash all transients à ‚ Short release ‐> jump in signal level after transient à BhiBreathing ‚ Noticeable movement of noise floor Performance‐ Noise and ƒ Signal to Noise Ratio à Not useful ƒ Total Harmonic Distortion à Measures strength of harmonics (introduced by compression) in relation to original frequency 28

24

20

%) Compressor Design (( Branching 16 Decoupled Branching Smooth THD 12 Decoupled Smooth

8

4

0 2 3 4 10 10 10 Frequency (Hz) Performance – frequency dependence ƒ Effective compression ratio à used in assessing compressors in cochlear implants and hearing aids à amplitude modulated sine wave applied at input

x[]nm= (1+ cos(2π fmcn ))cos(2π f n ) à spectrum consists of a carrier and two side bdbands

à ΔSi difference between amplitude of side bands and amplitude of carrier of input signal

à ΔSo difference between amplitude of side bands and amplitude of carrier of compressed signal is found,.

à effective compression ratio is then given by ΔSi/ΔSo. Performance – effective compression ratio 6.5

6.0 Compressor Design Branching Ratio 555.5 Decoupled Branching Smooth 5.0 Decoupled Smooth

ression 454.5 pp 4.0

e Com 3.5 vv 3.0

Effecti 2.5 2.0

4 8 12 16 20 24 28 32 36 Modulation Frequency (Hz) à Interpretation? Performance‐ Ballistics and sidechain configuration

Detector Fidelityypp() of Envelope Shape (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

Fide lity of the Log Branching Smooth 0.852 0.927 0.640 0.941 envelope shape domain Decoupled Smooth 0.859 0.911 0.648 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 0770.775 0800.805 0.461 0.934

ƒ Measures correlation between envelopes of compressed and uncompressed signals ƒ Nonsmooth designs do well since they often apply no compression ƒ Plac ing ba llis tics (ttk(attack and rel)lease) in log didomain outftperforms 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: logar ithm ic thres ho 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) 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 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 à Commercial designs: >40 ƒ 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 music production and broadcast: 0 ! Recommendations

ƒ Feedforward compressors are preferred à more stable and predicta ble than fdbkfeedback didesigns à 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 à Linear interpolation gives two hard knees Recommendations ƒ Ballistics in the log domain after the gain computer à Maintain envelope shape à no attac k lag à 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 ƒ 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