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).