Clip Fix version 4

Feedback and Reviews for Audacity 2.x

This board is ONLY for general feedback and discussion about Audacity 2.X.

If you require help, or think you have found a "bug", please post on the forum board relevant to your operating system.
Windows
Mac OS X
GNU/Linux and Unix-like

Clip Fix version 4

Permanent link to this post Posted by DickN » Thu Jul 06, 2017 8:14 pm

I got quite a surprise when I used Clip Fix in the May 9 nightly of Audacity. Finally looked at the .ny file in an editor and noticed the version change from 1 to 4.

I'm accustomed to the peak amplitude usually (not always) increasing when I apply Clip Fix. Since Lookahead Limiter would just clip it again if it's >0dB, I normalize it using Amplify and save the (negative) gain setting so I can restore the region's amplitude after using Lookahead Limiter. That removes the abrupt amplitude change (i.e., the step in the waveform) that Amplify created at each end of the region.

Clip Fix version 4 appears to have an attempt at avoiding this overload in the processed waveform, but it goes way too far. I had a clipping event with peak amplitude of +0.016 before applying Clip Fix. If I use version 1, the result has peak amplitude of +0.459. If I use version 4, the resultant peak is -8.5dB with the rest of the region likewise attenuated. It left steps in the waveform at both ends of the selection.

I believe my rather laborious procedure outlined above does a very good job. If Clip Fix (version 5?) produces the same result in one click, I'll be very happy with it.

Here's my procedure in more detail:

1: Apply Clip Fix (version 1);
2: Use Amplify to normalize the amplitude to 0dB. Before clicking OK, save the automatic gain setting on the clipboard;
3: Apply Lookahead Limiter (set "Limit To dB" to the value from the clipboard (which will be negative), unless that leaves a higher peak than you want to allow.);
4: Apply Amplify again, with Gain set from the clipboard and the '-' sign removed.

Due to the soft knee in Lookahead Limiter when Limit To is set below about -5dB, depending on the amount of limiting needed there may still be a step in the waveform due to Lookahead Limiter reducing the amplitude at the ends of the region. If this happens (or I anticipate it), I widen the region before Step 2 to situate the ends at much lower amplitudes.

There should also be a setting for desired maximum peak amplitude since, for Clip Fix to work reliably, it must be applied before any equalization and the user might want to leave some headroom for that.
DickN
 
Posts: 309
Joined: Thu Jul 22, 2010 9:03 pm
Operating System: Windows Vista

Re: Clip Fix version 4

Permanent link to this post Posted by steve » Fri Jul 07, 2017 11:31 am

DickN wrote:Clip Fix version 4 appears to have an attempt at avoiding this overload in the processed waveform, but it goes way too far.

  • Clip Fix will either do nothing (if no clipping is detected), or will increase the peak amplitude.
  • Clipping occurs when the signal level exceeds the maximum level that can be handled by the 'system'. Often this is at, or near 0 dB in Audacity.
  • It is not possible for Clip Fix to predict how much (if at all) the peak level will increase.
  • The level increase is largely dependent on how badly clipped the audio is, and can sometimes be estimated by zooming in on a clipped region of the waveform.
  • If the track is integer format (16 or 24 bit), it is impossible to exceed 0 dB.
  • Although 32-bit float can exceed 0 dB, peaks over 0 dB will be clipped on play because (all) sound cards use integer format samples.
In most cases using Clip Fix, the audio needs to be amplified by a negative amount to allow space for the restored clips. In the case of integer format tracks where the peak level is at or very close to 0 dB, it is essential that the audio is amplified by a negative amount before restoring the peaks.

In the original version of Clip Fix, amplifying the audio to allow for the restored peaks had to be done manually as a separate effect, which would usually be with the Amplify or Normalize effect. As this 'negative gain' step is nearly always required, the new Clip Fix effect includes a built-in gain stage. By default, the gain stage is set to -9 dB, but can be set anywhere between -30 and 0 dB. Unfortunately the effect is not able to predict how much negative gain is required, so the default has been set to allow what should be enough space for all but the most extreme cases.

In most cases, the gain should be adjusted higher than the default, but that can only be estimated by observing the severity of the clipping.

For 32-bit float tracks, it does not really matter if the restored clips go over 0 dB as that can be corrected after Clip Fix, but for integer format tracks it is essential that adequate space is provided.

DickN wrote: I had a clipping event with peak amplitude of +0.016 before applying Clip Fix. If I use version 1, the result has peak amplitude of +0.459.

In this case the clipping is relatively minor. An appropriate setting for "Reduce amplitude to allow for restored peaks (dB)" in this case would be about -1 dB. That would (in this specific case) give you a final peak amplitude of -0.541 dB.

DickN wrote:3: Apply Lookahead Limiter

You need to be careful applying software limiters to signals over 0 dB. Many software limiters are designed for levels below 0 dB (0 dB being the absolute maximum possible level for integer format), and although the limiter may perform 'transparent' limiting below 0 dB, it may be less graceful with input peaks above 0 dB and just hard clip them. Without looking at the code it can be difficult to know exactly what a limiter is doing with over 0 dB samples.

DickN wrote:There should also be a setting for desired maximum peak amplitude

The fact that restored peaks may sometimes be excessive is a limitation of the algorithm. Basically the way that clipped regions are restored is by looking at two samples either side of the "flat" part of the peak and calculating the entry and exit slopes. The sample values between these two points are then calculated by cubic spline interpolation.

This algorithm works remarkably well for simple waveforms such as sine waves, but can be way off if the waveform has a lot of high frequency overtones or noise, because the slope calculations may be wildly different from the slope of the fundamental frequency. A much better algorithm would be to use "Least Squares AutoRegression" (LSAR), which is what Audacity's "Repair" effect uses, but this is computationally expensive and would be far too slow to be practical in a Nyquist plug-in.

A less computationally expensive algorithm could be to calculate the slope at each end of the clipped region by averaging the slope of three or more samples. I may try this in a later version of Clip Fix to see how it performs.

DickN wrote:I widen the region before Step 2 to situate the ends at much lower amplitudes.

Where possible, I would recommend starting and ending the selection at places where the amplitude is close to zero. For speech, this would typically be between words. For music, this would typically be immediately before the onset of a beat.

DickN wrote:There should also be a setting for desired maximum peak amplitude

This is currently difficult for Nyquist plug-ins. In this case, the new peak level cannot be predicted (it is unknown until the restored peaks have been calculated), and "normalizing" after restoring the peaks is problematic as it would require that the entire selection is stored in RAM for a second processing pass (which will crash if the selection is too long).
Future versions of Nyquist may be able to solve this problem by accessing samples on demand, but currently Nyquist relies on Audacity feeding it with data from a single variable ("*TRACK*" in version 4 syntax, "S" in version 3 and earlier).
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
steve
Site Admin
 
Posts: 44703
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Clip Fix version 4

Permanent link to this post Posted by DickN » Mon Jul 10, 2017 2:00 pm

The procedure I gave above is invalid for fixed-point arithmetic, unless it's scaled to prevent overflow. I confess it hadn't even occurred to me that one might be operating on data types other than float 32 :oops:
DickN
 
Posts: 309
Joined: Thu Jul 22, 2010 9:03 pm
Operating System: Windows Vista


Return to Audacity 2.x Feedback and Reviews



Who is online

Users browsing this forum: No registered users and 3 guests