Negating the effects of soft limiting

Effects, Recipes, Interfacing with other software, etc.
Forum rules
If you require help using Audacity, please post on the forum board relevant to your operating system:
Windows
Mac OS X
GNU/Linux and Unix-like
Post Reply
samspots
Posts: 39
Joined: Sat Jan 08, 2011 1:17 am
Operating System: Please select

Negating the effects of soft limiting

Post by samspots » Sat Jan 08, 2011 1:29 am

Well, I noticed that it is very common to use soft limiting to make audio louder, and I was wondering whether there is a viable way to test for amount and softness of limiting on waveforms, and remove it. I could not do it through any of my known waveform modification techniques, and the clip fix filter is totally useless. The technique I thought could work would be to take audio, copy it, re-apply what I think is the amount of limiting they did, invert it, and combine. Instead, this just produces a ridiculously-limited waveform. What am I doing wrong, and is there a more precise way to do this? I am aware of bit rate loss that can be somewhat fixed by oversampling.

Trebor
Posts: 9954
Joined: Sat Dec 27, 2008 5:22 pm
Operating System: Windows 8 or 8.1

Re: Negating the effects of soft limiting

Post by Trebor » Sat Jan 08, 2011 2:36 am

If by "soft limiting" you mean "dynamic range compression", then it is possible to reverse dynamic range compression using an expander.

There is a free plugin for Audacity called Chris's Compressor, if you put a negative value in it for the "compression ratio" it acts as an expander: expanding the dynamic range, i.e. making the quiet bits quieter and the loud bits louder.
samspots wrote: I noticed that it is very common to use soft limiting to make audio louder
see "loudness war" ... http://en.wikipedia.org/wiki/Loudness_war

samspots
Posts: 39
Joined: Sat Jan 08, 2011 1:17 am
Operating System: Please select

Re: Negating the effects of soft limiting

Post by samspots » Sat Jan 08, 2011 3:21 pm

Nono, not dynamic range compression. Getting rid of that is nearly impossible without some sort of breathing. I'm talking about soft limiting, which applies a variable amount of distortion and a big gain in loudness by crushing the waveform. No attack or release or anything.

Trebor
Posts: 9954
Joined: Sat Dec 27, 2008 5:22 pm
Operating System: Windows 8 or 8.1

Re: Negating the effects of soft limiting

Post by Trebor » Sat Jan 08, 2011 5:15 pm

samspots wrote:Nono, not dynamic range compression. Getting rid of that is nearly impossible without some sort of breathing.
Attached is a before-after example of using Chris’s Compressor as an expander to reverse dynamic range compression, (judge for yourself whether there is breathing or other obvious unpleasant artifacts in the "After" version) ...
Before-After Dynamic range expanded (using Chris's Compressor).png
Before-After Dynamic range expanded (using Chris's Compressor).png (26.18 KiB) Viewed 2283 times
Last edited by Trebor on Sat Jan 08, 2011 5:35 pm, edited 1 time in total.

steve
Site Admin
Posts: 81627
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Negating the effects of soft limiting

Post by steve » Sat Jan 08, 2011 5:34 pm

samspots wrote: I'm talking about soft limiting, which applies a variable amount of distortion and a big gain in loudness by crushing the waveform. No attack or release or anything.
The effect you are referring to is more accurately described as "soft clipping".
Yes it is possible to reverse soft clipping, but you need to know:
1) the threshold level at which the "crushing" starts.
2) the "contour" of the "crushing".

The type of "limiting" that you are referring to works by applying non-linear amplification to the waveform.
Up to a set threshold level, the amplification is linear - in the most simple case a 1:1 ratio = what you put in is what you get out = no effect.
Above the threshold level, negative amplification is applied, so an increase in the input amplitude produces a smaller increase in the output amplitude.

In the most simple case, the amplification above the threshold is linear, but at a lower ratio.

Here's an example of such a "soft limiter" written in Nyquist.

Code: Select all

(setq thresh 0.5)
(setq ratio 4.0)

(setq nthresh (* -1 thresh))
(setq ratio (/ ratio))
(setq tops (s-max s thresh))
(setq mids (s-max (s-min s thresh) nthresh))
(setq bottoms (s-min s nthresh))

(setq tops (mult ratio tops))
(setq bottoms (mult ratio bottoms))

(sum tops mids bottoms)
To use this effect, Select the audio, then from the "Effect" menu select "Nyquist Prompt".
Copy and paste the above code into the Nyquist Prompt text box and apply it.

Here's a sine wave (amplitude 1.0) where I have applied the effect to a section:
trackpanel000.png
trackpanel000.png (9.19 KiB) Viewed 2282 times
As you can see, the waveform above the threshold (+/- 0.5) has been "crushed" with a ratio of 4:1
This would allow the processed (soft clipped) wave to be amplified, producing a "louder" mix.

In this case we can easily reverse the effect by applying amplification with a ratio of 1:4 to the "crushed" part of the waveform.
Here's the code (the only difference is that the 4th line of code has been omitted).

Code: Select all

(setq thresh 0.5)
(setq ratio 4.0)

(setq nthresh (* -1 thresh))

(setq tops (s-max s thresh))
(setq mids (s-max (s-min s thresh) nthresh))
(setq bottoms (s-min s nthresh))

(setq tops (mult ratio tops))
(setq bottoms (mult ratio bottoms))

(sum tops mids bottoms)
The problem of reversing the initial effect is made slightly more complicated if we had amplified (maximised) the waveform after crushing the tops and bottoms.
In the given example, the crushed waveform could be amplified by about 4.1 dB (approximately 1.6 times).
In this case we would need to first amplify the waveform by -4.1 dB (1/1.6) in order to make room for the peaks that we wish to expand. This would also bring the "threshold" (the point at which the waveform starts to get clipped) back down to the original threshold level of 0.5 (approximately -6 dB).

Unfortunately the "simplest case" given above is rarely if ever used because for high "crushing" ratios it does not sound very good.
Rather than using a linear reduced gain above the threshold value, the gain is usually reduced progressively. Instead of having a "corner" in the gain map at the threshold level, the amplification will be curved rather than linear.

For example, the gain (amplification) at the threshold level may be 1:1, then just above the threshold it may reduce to 1:2, then a bit above that reduce further to 1:3, then 1:4 and so on in a curve. An example of this type of soft clipping can be found in the "Broadcast Limiter II (RFT-Limiter-II.ny)" http://wiki.audacityteam.org/wiki/Downl ... t_plug-ins
The central part of the code for this plug-in is:

Code: Select all

(scale (/ 1 (/ vl (db-to-linear 0.45))) (sim
  (scale 0.2 (clip s vl))
  (scale 0.2 (clip s (db-to-linear (- limit 0.25))))
  (scale 0.2 (clip s (db-to-linear (- limit 0.50))))
  (scale 0.2 (clip s (db-to-linear (- limit 0.75))))
  (scale 0.2 (clip s (db-to-linear (- limit 1.00))))
))
In effect, what this is doing is progressively decreasing the gain in 5 steps when the amplitude rises above the threshold level.
Although this is not a "smooth" curve, it is a lot smoother than having a single high ratio step. It also makes it a lot more difficult to accurately reverse the effect.
The effect can be approximately reversed using the second code example, provided that you can make a good guess of the threshold and ratio.
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

samspots
Posts: 39
Joined: Sat Jan 08, 2011 1:17 am
Operating System: Please select

Re: Negating the effects of soft limiting

Post by samspots » Sat Jan 08, 2011 10:06 pm

I think the decibal limit is at 5, and the softness is 0.1, so how would I approximate that?

steve
Site Admin
Posts: 81627
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Negating the effects of soft limiting

Post by steve » Sun Jan 09, 2011 5:20 pm

"softness" is not a standard measurement. The amount of "crushing" will depend on what effect was used to create the soft clipping.
Probably the best you will do is to experiment with the code that I posted. Experiment with different values for "thresh" (threshold) and "ratio" and see which sounds best.
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

Post Reply