The No.1 Website for Pro Audio
 All  This Thread  Reviews  Gear Database  Gear for sale     Latest  Trending
Understand compression (really!)
Old 13th October 2013
  #1
Understand compression (really!)

Hey guys,

I've started to make some notes about understanding all basic aspects of audio. Might end up being a free e-book of some sort, but right now I'm battling with compression. I know how it works, but I'm a perfectionist and I want to make sure I REALLY understand how it works.

So here is the issue.

If I is the input signal volume, O is the output signal volume, T is the threshold volume, R is the ratio R:1, then we have

O = T + (I - T) / R

To make sure I had it right, I verified it manually, and then thought I'd do a quick Excel file to make testing the function easier in different scenarii. Turned out it wasn't as easy as I thought it would be but the file is here: http://sdrv.ms/GSxX0n (default input ignal volume is -40 dB).

With the example displayed when you open the file, you see that the attack and compression phases look OK when compared to, for example, the Wikipedia article on Audio Compression (look under Attack and Release).

But what bugs me is that the behaviour depicted in the article for the release phase is not what I obtain in my rendition of the function (see the graph in the Excel file). How can the output signal go below the input signal if the compressor compresses with respect to the threshold? If it compresses with respect to the threshold, then the output signal is always between the input and the threshold, isn't it?

Thank you for your help
V.
Old 28th October 2013
  #2
@MODS: maybe move it out of the newb section?
Old 28th October 2013
  #3
Gear Addict
 
JustMastering's Avatar
Quote:
Originally Posted by vinnie2k View Post

But what bugs me is that the behaviour depicted in the article for the release phase is not what I obtain in my rendition of the function (see the graph in the Excel file). How can the output signal go below the input signal if the compressor compresses with respect to the threshold? If it compresses with respect to the threshold, then the output signal is always between the input and the threshold, isn't it?
Hi,

That's a great visual! That's excellent. I am assuming that the blue line is the original audio and the green line is what the compressor is doing to the audio, correct? Regarding the release phase, I have attached an updated view with my comments (done rather crudely and quickly - my apologies but I hope you get the idea).

The release time is how long it takes the compressor to return to the "normal" state after the signal drops below the threshold. So your unprocessed signal, ramping up very quick to -20dBFS at 50ms in, the compressor brings it to -25dBFS within 50ms (2:1 ratio with threshold of -30dBFS), and then when the original signal stops at roughly 250ms in, the compressor returns to normal by the time we get to 300ms.

Maybe the graph needs three lines - original audio, a line to indicate the compressor's action, and a third line to indicate the resulting change in the audio (depending on the settings you use, and how complex you draw the original audio, that might help further visualize the attack vs release settings).

Once again, that's a really neat way to depict what the compressor is doing and it makes for a great learning tool. I am interested to see how this develops as you make further updates.

EDIT: Reviewing your sheet again, if you just went with original and processed audio, you could just cut off that last curve all together (since the original audio stops, you would not hear anything afterwards - you'd only see the attack portion in the chart. You'd see the release if you had the original audio ramp down to the threshold -30dBFS.

Cheers !
Rob
Attached Thumbnails
Understand compression (really!)-adjustedwithcomments.jpg  

Last edited by JustMastering; 28th October 2013 at 11:57 PM.. Reason: Clarification
Old 29th October 2013
  #4
Hi Rob,

Thanks a lot for your reply, I'll get back to you when I'll dig back into the details, hopefully this weekend.

However, just by reading your comments, I can't if you agree that the Wikipedia image is misleading, or not?
Old 29th October 2013
  #5
Lives for gear
 
Tinderwet's Avatar
Quote:
Originally Posted by JustMastering View Post

The release time is how long it takes the compressor to return to the "normal" state after the signal drops below the threshold.
That's an incorrect statement. Both attack and release react to changes in signal level indirectly by controlling the raise or fall of gain reduction, so it can reach the required compression ratio in a set amount of time. It's not the threshold that controls either of them.
Old 29th October 2013
  #6
Quote:
Originally Posted by Tinderwet View Post
That's an incorrect statement. Both attack and release react to changes in signal level indirectly by controlling the raise or fall of gain reduction, so it can reach the required compression ratio in a set amount of time. It's not the threshold that controls either of them.
They react to the signal level set by the threshold.
Old 29th October 2013
  #7
Lives for gear
 
Tinderwet's Avatar
Quote:
Originally Posted by CiaranDeCeol View Post
They react to the signal level set by the threshold.
That's incorrect. They only decrease (slow down) the rate by which gain reduction changes. They are unaware of the signal level.
Old 29th October 2013
  #8
Lives for gear
 

Better formula

If I less than T then O = I

If I larger than T then O =T +(( I - T) / R)
Old 29th October 2013
  #9
Gear Addict
 
JustMastering's Avatar
Quote:
Originally Posted by Tinderwet View Post
That's an incorrect statement. Both attack and release react to changes in signal level indirectly by controlling the raise or fall of gain reduction, so it can reach the required compression ratio in a set amount of time. It's not the threshold that controls either of them.
Hi Tinderwet,

I'm not 100% sure, but I think we might be saying the same thing, I might just not have been clear enough in my original statement. I agree with you - the threshold doesn't have any direct control over anything. The compressor applies gain reduction when it senses audio above the threshold, and the attack/release times are what determine how quickly the compressor reacts.

Cheers
Rob
Old 29th October 2013
  #10
Gear Addict
 
JustMastering's Avatar
Quote:
Originally Posted by vinnie2k View Post
Hi Rob,

Thanks a lot for your reply, I'll get back to you when I'll dig back into the details, hopefully this weekend.

However, just by reading your comments, I can't if you agree that the Wikipedia image is misleading, or not?
It's a pleasure - I am looking forward to see what you come up with !

I find that the Wikipedia article explains it well, and those charts are fairly standard, however, because they do not include the *time* component, the way yours does, they really can't illustrate what the compressor does to the signal over time (only over the increase in amplitude).

Having that time component depicted, the way you have done provides a clearer explanation in my view.

Cheers !
Rob
Old 30th October 2013
  #11
Quote:
Originally Posted by JustMastering View Post
Hi Tinderwet,

I'm not 100% sure, but I think we might be saying the same thing, I might just not have been clear enough in my original statement. I agree with you - the threshold doesn't have any direct control over anything. The compressor applies gain reduction when it senses audio above the threshold, and the attack/release times are what determine how quickly the compressor reacts.

Cheers
Rob
This is correct. The threshold is a guide for when the compressor should react. It is a signal level you define.
The attack and release are the speed the compressor kicks in and out.
Old 30th October 2013
  #12
Play with a synth that has ASDR. it's not really anymore difficult than that. the controls on the synth will work a little differently then the synth, i.e. fast release will make the synth die more quickly, on the compressor it will bring up the ambience. attack will be the same, fast synth attack will make a clicky sound, fast attack on a snare will bring up the point of the strike. decay has more to do with gain reduction. Compressors are very simple utilitarian tools. The real interesting part about compression is the harmonic distortion and saturation they exhibit. Just glorified, and much more controllable, distortion circuits really.
Old 30th October 2013
  #13
Gear Nut
 
Maelstrom's Avatar
On a related note, what exactly does Make-Up gain do to the signal in relation to the other parameters?
Old 30th October 2013
  #14
Quote:
Originally Posted by Maelstrom View Post
On a related note, what exactly does Make-Up gain do to the signal in relation to the other parameters?
Say you have a signal with a 20dB dynamic range ranging from -30dB to -10dB.
You set your threshold at -30dB and ratio at 5:1.
This will reduce the dynamic range from 20dB to 4dB giving the sig a dynamic range of -30db to -26dB.

Your highest peak in volume is now 16dB less than it was pre-compression so it will be quieter in the mix.

Theoretically 16dB of make up gain should be added to have it as loud as before. However in practice, the main up gain does not match the gain reduction exactly.
Old 30th October 2013
  #15
Compressors are essentially control systems. The subject has an enormous academic foundation. It's a good starting point for studies. It explains different approaches and their behaviour.

Also, it's really essential to realize that any audio dynamics compressor represents an incredibly complex time, level, and frequency dependent non-linear system. Sadly, non-linear systems have the vicious property to be very hard to measure and understand (if possible at all).

Most literature on audio dynamics compression fails to properly describe the process. All these static gain plots, timing labelling and implications on the true gain reduction/overload-protection are all WRONG. These graphs and descriptions are misunderstood at best.

Not sure who down-voted CiaranDeCeol, but he's totally right with his remarks. It is important to understand that the indicated ratio (and thus the gain transfer plot) never ever reaches its full value in practice! Never! (at least not with all analogue and all classic compressor designs). Instead, it constantly "hunts" the target defined by the ratio control. This hunting is usually "slowed" down by a simple pole filter which changes it's coefficient depending on whether the detected level rises or falls.

The attack and release timing values shown on the front panel basically only control this simple low-pass filter. Engineers call this an "infinite impulse response" filter. Because of this infinity thing, it never really reaches its target value (it would need an infinite amount of time to do so). And this leads us to the fact how timing filters (and conventional frequency domain filters) get specified: Usually somewhere at the point were the filter output reaches ~70% of its input (or whatever else value depending on the manufacturer).

In other words, the timing values shown on compressors are pretty pointless and arbitrary. They definitely do not tell how long the compressor takes to reach its full ratio value. Not even close! As Ciaran mentioned, they describe the "speed" (within limited amounts).


Regarding the original question, here's pseudo code of a super basic compressor:


// Detector (simple AC to DC converter)
dcDetected = abs( input )

// Value is now converted into dB scale
dcDetected = linearToDB( dcDetected )

// Remove threshold "offset" from detected signal
dcDetected = dcDetected - threshold

// We only want "above threshold" compression, that's why we "clip"
// everything that goes below zero (i.e. we ignore what's below the user defined threshold)
if( dcDetected < 0 )
dcDetected = 0

// dcDetected now describes the level above threshold.
// Now multiply with ratio
dcDetected = dcDetected * ratio

// dcDetected now describes the level "error" we want to correct.
// But this sounds bad, as it's too fast (close to a clipper). Now we need
// to limit the rate of speed to avoid distortion. Here we switch between
// two simple filters depending on the change rate's polarity:

if( dcDetected > controlSignal ) // attack phase
controlSignal = filterWithAttackCoeff( dcDetected )
else // release phase
controlSignal = filterWithReleaseCoeff( dcDetected )

// Now, we only need to and invert the sign of the control signal and
// convert our control signal back to the linear scale
controlSignal = dbToLinear( -controlSignal )

// Finally, we multiply ("amplify") the actual audio with the generated control
// signal
input = input * controlSignal


I hope this helps somehow. Make sure to properly understand the difference
between calculations in the linear and log ("dB") domain. This is an important
detail of the above algorithm.
Old 30th October 2013
  #16
Great post above.

Sounds like a man who knows his stuff!
Old 30th October 2013
  #17
Lives for gear
 
Tinderwet's Avatar
Quote:
Originally Posted by JustMastering View Post
Hi Tinderwet,

I'm not 100% sure, but I think we might be saying the same thing, I might just not have been clear enough in my original statement. I agree with you - the threshold doesn't have any direct control over anything. The compressor applies gain reduction when it senses audio above the threshold, and the attack/release times are what determine how quickly the compressor reacts.

Cheers
Rob
No problem, Rob. Well...

The problem was that you put "after the signal drops below the threshold". Attack and release phases happen even when the signal level remains constantly over the threshold, as long as there are changes in the signal level. They are not related to the threshold.

The time you can set up with the attack and release knobs are usually not the actual amount of time it takes for the gain reduction to raise or fall. Rather, it's the amount of time it takes for the gain to change by a predefined amount in dB, which is often 10 dB. The compressor's time constants are referenced to that dB amount.
Old 30th October 2013
  #18
Gear Nut
 
Maelstrom's Avatar
Quote:
Originally Posted by CiaranDeCeol View Post
Say you have a signal with a 20dB dynamic range ranging from -30dB to -10dB.
You set your threshold at -30dB and ratio at 5:1.
This will reduce the dynamic range from 20dB to 4dB giving the sig a dynamic range of -30db to -26dB.

Your highest peak in volume is now 16dB less than it was pre-compression so it will be quieter in the mix.

Theoretically 16dB of make up gain should be added to have it as loud as before. However in practice, the main up gain does not match the gain reduction exactly.
This is what I thought, but one can never be sure. So say for example with Ableton's compressor, Make-up gain can be switched on or off and the default value is 0.00db. I'm assuming this means it will (theoretically) to return the signal to the original level with compression applied?

E.g: Make-up = 0.00db. Applied to your example above the new dynamic range would be -10db to -14db (theoretically)
Old 30th October 2013
  #19
Quote:
Originally Posted by Maelstrom View Post
This is what I thought, but one can never be sure. So say for example with Ableton's compressor, Make-up gain can be switched on or off and the default value is 0.00db. I'm assuming this means it will (theoretically) to return the signal to the original level with compression applied?

E.g: Make-up = 0.00db. Applied to your example above the new dynamic range would be -10db to -14db (theoretically)
Correct me if I'm wrong but the output gain knob does not act like a fader which controls the signal volume.
If you have the output gain knob set to 0dB, it means you are applying 0dB of make up gain. It does not mean that the signal after compression is now set to 0dB.

At least that is my understanding.
Old 30th October 2013
  #20
Gear Addict
 
JustMastering's Avatar
Quote:
Originally Posted by Tinderwet View Post
The time you can set up with the attack and release knobs are usually not the actual amount of time it takes for the gain reduction to raise or fall. Rather, it's the amount of time it takes for the gain to change by a predefined amount in dB, which is often 10 dB. The compressor's time constants are referenced to that dB amount.
Thanks Tinderwet. That is an important nuance for anyone using a compressor to be aware of - I appreciate you taking the time to explain (clearly, I was oversimplifying things a little in my initial statements!).

Cheers
Rob
Old 31st October 2013
  #21
Lives for gear
 
Tinderwet's Avatar
Quote:
Originally Posted by JustMastering View Post
Thanks Tinderwet. That is an important nuance for anyone using a compressor to be aware of - I appreciate you taking the time to explain (clearly, I was oversimplifying things a little in my initial statements!).

Cheers
Rob
You're welcome, Rob!

Actually, it seems like I've oversimplified things a bit, too. At least according to this article: http://www.rane.com/pdf/ranenotes/Dy...Processors.pdf

They only attribute the "time per 10dB change" to the release function.

They specify the attack time differently: "Because increasing time has a diminishing effect on gain for compressors, it is practical to specify attack as the time required for gain to settle to a defined percent of final value. Typical are 86% or 95% of the final value."

Looks like there are a lot of variables about compressor design.
Old 31st October 2013
  #22
Gear Addict
 
Dimmy's Avatar
 

Quote:
Originally Posted by Tinderwet View Post
The time you can set up with the attack and release knobs are usually not the actual amount of time it takes for the gain reduction to raise or fall. Rather, it's the amount of time it takes for the gain to change by a predefined amount in dB, which is often 10 dB. The compressor's time constants are referenced to that dB amount.
This means that the numbers dialled in on Attack and Release are only close to accurate when one compresses a signal by exactly 10 dB, and that with any other amount of gain reduction they'll be slightly off? And the reference value varies from compressor to compressor?
Old 31st October 2013
  #23
...not to mention that dB linear behaviour of the timing filters (attack/release) is the exception. In the analogue domain in particular (were most compressor's timing is also level dependent).

All better sounding compressor are "automated" and very dynamic. Depending on the situation, the same UI setting may well "trigger" different timing behaviour than the same setting tested with different material.

And as mentioned before, you cannot really specify a compressor. A compressor could be designed to react to the moon-phases, but you'll never find out until you fully understand the hidden "mechanics" of the system.

The attack/release is far too complicated to be expressed with a static value. In half way good sounding compressors, the time-"contstants" are all but constant. They are super dynamic.

Again, these numbers are arbitrary and completely at the mercy of the manufacturers philosophy, their measurement standards, hidden automatisms and so on. They only make sense when comparing two of the same compressors. 500ms on one compressor could well have become 125ms with a minutely different measurement standard. No need to take them seriously.
Old 3rd November 2013
  #24
I'm glad I asked the question, but now I'm in deep trouble to simplify all of this so that other n00bs like me understand how a compressor really works. Ouch :-/
Old 3rd November 2013
  #25
Quote:
Originally Posted by Tinderwet View Post
You're welcome, Rob!

Actually, it seems like I've oversimplified things a bit, too. At least according to this article: http://www.rane.com/pdf/ranenotes/Dy...Processors.pdf
Page 23: how can they display attack and release times for compressors in general if what is being said in this thread is true? If 100mx on one compressor is 250ms on another, it makes no sense, right?
Old 3rd November 2013
  #26
Quote:
Originally Posted by FabienTDR View Post
...not to mention that dB linear behaviour of the timing filters (attack/release) is the exception. In the analogue domain in particular (were most compressor's timing is also level dependent).

All better sounding compressor are "automated" and very dynamic. Depending on the situation, the same UI setting may well "trigger" different timing behaviour than the same setting tested with different material.

And as mentioned before, you cannot really specify a compressor. A compressor could be designed to react to the moon-phases, but you'll never find out until you fully understand the hidden "mechanics" of the system.

The attack/release is far too complicated to be expressed with a static value. In half way good sounding compressors, the time-"contstants" are all but constant. They are super dynamic.

Again, these numbers are arbitrary and completely at the mercy of the manufacturers philosophy, their measurement standards, hidden automatisms and so on. They only make sense when comparing two of the same compressors. 500ms on one compressor could well have become 125ms with a minutely different measurement standard. No need to take them seriously.
Is this only true of analog compressors because of the electronics involved, or is it also true of digital compressors because of the design? For examplel I use the stock compressor plugin in Reaper. When I set the attack on that compressor to 50ms, does it ramp up the ratio from 1:1 to x:1 in 50ms or not?
Old 4th November 2013
  #27
Quote:
Originally Posted by vinnie2k View Post
Is this only true of analog compressors because of the electronics involved, or is it also true of digital compressors because of the design?
As mentioned above, the attack/release smoothing is usually done with a simple first order filter:

y[i] := y[i-1] + a * (x[i] - y[i-1])

where "a" is the filter coefficient, for example 0.1
and "i" is the sample number

Look closely, the change from one filter output to the next is proportional to the difference between the previous output and the next input. The change is exponential and approaches the target value in an asymptotic manner: It (theoretically) never reaches the target value.

That's why engineers define certain thresholds for their measurements, 50%, 70% or whatever else. They can't define the time constant as "the time it takes to reach the full target value", because it wouldn't make sense in most cases.

Quote:
Originally Posted by vinnie2k View Post
For examplel I use the stock compressor plugin in Reaper. When I set the attack on that compressor to 50ms, does it ramp up the ratio from 1:1 to x:1 in 50ms or not?
No idea about the stock reaper comp, but most probably: No. It will need much more time (depending how you define your measurement). Just run a test in your audio editor.
Old 6th November 2013
  #28
This is all slowly sinking in

So let me try to summarize.

1) Attack and release phases are not features of a compressor per se, they're there as damage containment to prevent clipping the signal when abruptly switching the compressor on when dcDetected > 0, correct?

2) The attack and release times are not times but speeds, i.e. how fast (x decibels in y ms)are we approaching the target set volume, correct?

3) In your algorithm, this part confuses me:

1 if( dcDetected > controlSignal ) // attack phase
2 controlSignal = filterWithAttackCoeff( dcDetected )
3 else // release phase
4 controlSignal = filterWithReleaseCoeff( dcDetected )

Shouldn't it be something like

1 For i from 0 to maxSampleSize
2 if (dcDetected[i] > controlSignal[i])
3 controlSignal[i] := controlSignal[i-1] + a * (dcDetected[i] - controlSignal[i-1]) // a > 0
4 else
5 controlSignal[i] := controlSignal[i-1] + b * (dcDetected[i] - controlSignal[i-1]) // b < 0
6 endif

I might seem to be splitting hairs but I do want to understand this stuff

Herzlichen Dank Fabien

Last edited by vinnie2k; 7th November 2013 at 09:29 PM.. Reason: Proper syntax :-P
Old 7th November 2013
  #29
1) They prevent abrupt waveshaping by "slowing down" the control signal. But the details depends on the given implementation. The algorithm I posted above is very, very basic. Usually, a "better" compressor will have several hidden "smoothing" filters and handle the A/R switching in a more musical manner. It really depends.

For example, the typical diode circuits used to do the "if" branching for the threshold or A/R switch saturate and lag by themselves. Things complicate quickly, even without any explicit timing automatism.

2) Yes, exactly. But even the dB/sec unit is not really adequate for non log-based ("dB aware") compressors. Their dB/sec will change substantially depending on the amount of gain reduction.

3) Yes, that's fine (except that missing closing bracket maybe :P)
Old 9th March 2014
  #30
I'm back

I've been hacking at my Excel file to try and implement what Fabien has taught me, just to see if I can get some sort of graph for my book.

Here's the Excel:
http://1drv.ms/1fXv089

I'm struggling with making this real, i.e. what voltages do I need to consider, what's the real conversion function between linear and dB scale, etc.

Would anyone be willing to help?
Topic:
Post Reply

Welcome to the Gearslutz Pro Audio Community!

Registration benefits include:
  • The ability to reply to and create new discussions
  • Access to members-only giveaways & competitions
  • Interact with VIP industry experts in our guest Q&As
  • Access to members-only sub forum discussions
  • Access to members-only Chat Room
  • Get INSTANT ACCESS to the world's best private pro audio Classifieds for only USD $20/year
  • Promote your eBay auctions and Reverb.com listings for free
  • Remove this message!
You need an account to post a reply. Create a username and password below and an account will be created and your post entered.


 
 
Slide to join now Processing…
Thread Tools
Search this Thread
Search this Thread:

Advanced Search
Forum Jump
Forum Jump