Any shortcuts to "True Peak" detection?

DSP, Plugin and Host development discussion.
RELATED
PRODUCTS

Post

I am trying to add "True Peak" detection to a limiter and finding "True Peak" to be quite elusive.

I am currently using a 193 tap FIR interpolator with Kaiser window (a=2.3) oversampled 4x at 44.1kHz (176.4kHz filter samplerate). The filter cutoff frequency is 1/2 the audio samplerate (22.05kHz).

I arrived at these filter parameters via FIR design software that shows this filter should produce less than 0.002 dB ripple and a roll off of only -0.01 dB at 20kHz - i.e., it's nearly a perfect filter. Yet according to several "ISP" meters the limiter is not completely capturing ISPs. Occasionally ISPs emerge from the limiter exceeding the set point by 0.2dB or more. I tried increasing the oversampling rate to 8x but it made almost no difference (actually showed no difference at all on some meters).

This is a very high quality interpolator yet it seems it is still not "good enough" to catch ISPs.

I know that calculation of "True Peak" is theoretical as it would require an infinite oversampling rate - but how are so many meters, limiters, etc., detecting ISPs so efficiently and with such consistent precision? Are there tricks/shortcuts to "True Peak" detection?

Post

It appears that the "magical" window for FIR interpolation is the Lanczos window. Just tried it and I am getting better ISP detection with less filter taps and only 4x oversampling (once again, going to 8x made little/no difference).

Are there still better/faster methods for ISP detection or is this the typical approach (upsampling through a FIR interpolator)?

Post

The only way you can detect true peaks "exactly" is by measuring them exactly the same way with the same filters as the meter you use to validate your results. The meter itself won't be exact (and won't match another meter exactly), the DAC that actually outputs the final signal into the analog real won't be exact (and won't match another DAC exactly) and the whole concept is fundamentally an approximate affair.

Also keep in mind that even if your limiter detected "true peaks" exactly (for whatever definition of exact) then once you apply a gain reduction curve you'll get bandwidth expansion and when you either filter it out or let it alias, you'll typically end up with new intersample peaks anyway.

Post

Here's one method but dunno if it is any simpler or more complex to your method: https://notebook.community/carthach/ess ... akdetector https://techblog.izotope.com/2015/08/24 ... detection/

Post

juha_p wrote: Wed Jun 08, 2022 12:15 pm Here's one method but dunno if it is any simpler or more complex to your method: https://notebook.community/carthach/ess ... akdetector
The choice of parabolic interpolation might not be ideal though, since that's really quite a crappy interpolator. One could instead use something like Catmull-Rom cubic that's actually a half-decent interpolator in general (especially when combined with oversampling; I'd imagine 4x should be more than plenty for this) and the roots of the derivative (for local minimum/maximum) are still readily solvable with the quadratic formula (and one could probably skip the whole thing if the curve appears to be monotone.. which with oversampling would really be most of the intervals).

Post

mystran wrote: Wed Jun 08, 2022 1:18 pm The choice of parabolic interpolation might not be ideal though, since that's really quite a crappy interpolator.
I originally tried a 4 point, 3rd order cubic spline interpolator - which is very fast/low CPU - but the curve underestimates the ISPs (the curve is too "flat" between points).

I understand the Lanczos sinc interpolator is best for audio but I have yet to find any examples of the process. I think what I'm currently using may be similar (but computationally expensive).

The waveform display in Steinberg's Wavelab seems to show True Peak and is calculated very quickly - so I'm thinking there must be some type of simple (4 point?) interpolator that produces fairly accurate True Peak interpolation.
mystran wrote: Wed Jun 08, 2022 9:24 am The only way you can detect true peaks "exactly" is by measuring them exactly the same way with the same filters as the meter you use to validate your results. The meter itself won't be exact (and won't match another meter exactly), the DAC that actually outputs the final signal into the analog real won't be exact (and won't match another DAC exactly) and the whole concept is fundamentally an approximate affair.

Also keep in mind that even if your limiter detected "true peaks" exactly (for whatever definition of exact) then once you apply a gain reduction curve you'll get bandwidth expansion and when you either filter it out or let it alias, you'll typically end up with new intersample peaks anyway.
I think I'm on the same page as you (this seems kind of a futile endeavour) but it's what customers have come to expect from a "professional" limiter. And many specs now, like EBU R128, specify max levels in dBTP so we have to be at least close (EBU's TP tolerance is +/-0.3dB which it appears I currently meet, so maybe what I have is good enough).

Post

juha_p wrote: Wed Jun 08, 2022 12:15 pm Here's one method but dunno if it is any simpler or more complex to your method: https://notebook.community/carthach/ess ... akdetector https://techblog.izotope.com/2015/08/24 ... detection/
Thank you for these links. Good info!

Notice that Izotope's waveform display (like Wavelab) also shows the waveform as an smooth "true analog" shape (vs. straight line segments) from sample to sample. So somehow, it seems, they are interpolating True Peak (or at least very close to it) in their graphical display calculations. How? I can't believe they are running a CPU-intensive high-oversampling routine just to draw a curve (but maybe they are? IDK).

Post

Fender19 wrote: Wed Jun 08, 2022 6:10 pm
mystran wrote: Wed Jun 08, 2022 1:18 pm The choice of parabolic interpolation might not be ideal though, since that's really quite a crappy interpolator.
I originally tried a 4 point, 3rd order cubic spline interpolator - which is very fast/low CPU - but the curve underestimates the ISPs (the curve is too "flat" between points).
It won't work well without oversampling, but I'd imagine it should work reasonably well with 4x or so oversampling with a quality kernel
I understand the Lanczos sinc interpolator is best for audio but I have yet to find any examples of the process. I think what I'm currently using may be similar (but computationally expensive).
Lanczos is not a great window for audio (in general anyway) as it's attenuation is garbage.

Sufficiently high-order cosine windows (eg. the 4-term windows like Blackman-Nuttall or Blackman-Harris are pretty much the lowest workable order) or Kaiser (just bump alpha to 3-4 at least) are much better for general resampling duties.

Whether Lanczos happens to overestimate peaks (which might be preferable in this particular application) is another question... but like in general it's something you'd use for image processing, not something you'd use for audio.

Your original design with 193 taps for 4x (~48 taps per branch; with resampling "taps per branch" is a much more helpful metric than the total kernel length, because if you increase the oversampling factor by 2 you'll need essentially twice as many total taps to get the same quality and you should be computing this in polyphase anyway) is squarely in the "tradeoff" category (not terrible, but not exactly great either) in terms of it's length. The chosen length is also potentially wasteful as it's one more than any usual SIMD width (whether you're 4-wide or 8-wide) ... and arguably also 1 over full cache lines, but that might not matter here too much.

Post

mystran wrote: Wed Jun 08, 2022 7:55 pm
Fender19 wrote: Wed Jun 08, 2022 6:10 pm I originally tried a 4 point, 3rd order cubic spline interpolator - which is very fast/low CPU - but the curve underestimates the ISPs (the curve is too "flat" between points).
It won't work well without oversampling, but I'd imagine it should work reasonably well with 4x or so oversampling with a quality kernel
Can you expand on this comment a bit? If we oversample before the interpolator why would we need the interpolator? I don't understand.

The 4 point cubic ("Hermite") interpolator I tried WAS the "oversampling". I fed it 4 source samples (y-1, y, y+1 and y+2) and it interpolated points on a spline between the middle two points by whatever "oversampling" increments I wanted. I advanced the 4 y-value input points with every native input sample. The interpolated points were close but not "peaky" enough to generate true (sine-based) ISPs.

A fast and simple interpolator/oversampler that works like that but with sine-based curves, rather than cubic, would be ideal. Is there any such thing?

Post

I'd like to digress a bit into a question how exact does the ISP need to be, e.g. for the purposes of limiting. mystran already outlined a few aspects of the whole thing being approximate, I'd like to point out a few other aspects, which might be clear to some people, but probably not to everybody.

I guess the idea of detecting ISP comes from the desire to have the limiter behaving, in intuitive terms, "as close to analog as possible". Or at least intuitively treating the signals as continuous time ones. Usually this is a pretty sound approach, but with the topic of ISP we might be getting close to the boundary where such parallel no longer makes unquestionable sense. What I'd like to get to, is that this parallel works only somewhat. This is related to the "approximate" aspect which mystran mentioned.

The biggest problem comparing digital limiters to analog is that digital signals are usually hard-bandlimited, while analog signals are only soft-bandlimited, and generally with much higher band limits (so that no audible losses occur, which otherwise with soft-bandlimiting could be a problem). Now, hard-bandlimiting does some fundamental changes to the overall shape of the waveform. I'm speaking of the Gibbs phenomenon and similar effects. Given a sawtooth wave, its hard-bandlimited version can have higher peak amplitude than its non-bandlimited version (which, is somewhat counterintuitive, intuitively one would expect lowpass filtering to smooth the signal and possibly lower the amplitude).

Now there can be further more exotic cases with even larger amplitude overshoots. IIRC someone suggested an example of an alternating +-1 digital sequence with a phase jump at one point, which, theoretically produces an infinitely high peak upon conversion to continuous time. I'd wonder whether there a real continuous-time signal, producing such sequence upon sampling. Let me refine this statement more rigorously: apparently such infinitely high peak upon bandlimiting will produce such sequence, but that doesn't feel like a real world example. Let's rather say, whether a unit-peak-amplitude continuous signal can produce this sequence (of a possibly somewhat lower, but not too much lower amplitude).

The point here being, such hard-bandlimited signals actually normally not met in analog domain, and their processing (such as limiting) in analog domain could sound awkward due to the overshoots arising from bandlimiting. So, the intuitive assumption that by treating the ISPs we behave "like analog stuff" doesn't fully apply, since such signals are not commonly met there.

One other example (not related to limiting) is ringmodulation (or, for that matter, frequency shifting), which cannot sound the same in digital domain, no matter how perfectly done, as we'd be missing frequencies above 20kHz, which would be shifted into the audible range by the effect.

Post

Z1202 wrote: Thu Jun 09, 2022 8:01 am I guess the idea of detecting ISP comes from the desire to have the limiter behaving, in intuitive terms, "as close to analog as possible". Or at least intuitively treating the signals as continuous time ones.
Well, perhaps "as close to analog" is one side of it, but the other side is that eventually the signal will be converted to an analog waveform and the device performing this conversion is going to have a finite headroom... and historically some cheap DAC didn't have a whole lot of additional headroom and when we got into the famous loudness wars and started pushing signals close to the digital ceiling, such DACs would then produce distortion due to inter-sample peaks. Some people claim that it should be less of an issue these days, I have no idea.

Now there can be further more exotic cases with even larger amplitude overshoots. IIRC someone suggested an example of an alternating +-1 digital sequence with a phase jump at one point, which, theoretically produces an infinitely high peak upon conversion to continuous time. I'd wonder whether there a real continuous-time signal, producing such sequence upon sampling. Let me refine this statement more rigorously: apparently such infinitely high peak upon bandlimiting will produce such sequence, but that doesn't feel like a real world example. Let's rather say, whether a unit-peak-amplitude continuous signal can produce this sequence (of a possibly somewhat lower, but not too much lower amplitude).
The theoretical case is mostly of interest because it illustrates that there is no finite limit on intersample peaks with a theoretically perfect reconstruction filter and in practice the peaks are only bounded by an imperfect reconstruction filter. In case of FIR resampling (eg. in an oversampling converter) the longer the filter, the higher the theoretical peaks you could see. This also brings up another topic: the inter-sample peaks might become an issue with headroom even before the signal even hits the analog realm.

That said, any half-decent design (whether a DAC or an analog signal path) has some headroom, so whether your ISPs peak at 0dB or +0.2dB is probably irrelevant, it's probably good enough in practice. If meter readings going over (slightly) bothers you, then measure a reasonable worst-case value and leave that much headroom by turning the gain down. It's not like you're losing a whole lot of loudness if the threshold is at -0.2dB instead of 0dB. :)
One other example (not related to limiting) is ringmodulation (or, for that matter, frequency shifting), which cannot sound the same in digital domain, no matter how perfectly done, as we'd be missing frequencies above 20kHz, which would be shifted into the audible range by the effect.
There's a lot of other non-linear things where this can become an issue. For example your average synth filter typically sounds better if you synthesize your oscillators at a higher rate (eg. 2x) with very gradual roll-off compared to synthesizing at 44.1kHz with a sharp cutoff and then oversampling, because of the IMD effects with the frequencies that aren't directly audible.

Post

mystran wrote: Thu Jun 09, 2022 12:53 pm Well, perhaps "as close to analog" is one side of it, but the other side is that eventually the signal will be converted to an analog waveform and the device performing this conversion is going to have a finite headroom... and historically some cheap DAC didn't have a whole lot of additional headroom and when we got into the famous loudness wars and started pushing signals close to the digital ceiling, such DACs would then produce distortion due to inter-sample peaks. Some people claim that it should be less of an issue these days, I have no idea.
Exactly. And this is my point: there is a tradeoff between a larger gain reduction, compared to analog, and ISP overshoots. How bad is each is YMMV. Besides cheap DACs which might be an issue, a safety clipper at the end of a DAW mixer chain might be an issue, if that's an advanced clipper with stuff like e.g. internal oversampling. Naive clippers of course do not matter. A too large gain reduction is IMHO usually perceived as a bad quality of the limiter (compared to another limiter which doesn't reduce the gain as much).

Post

In Windows case, one should also take care of its own CAudioLimiter which kicks in when signal level exceeds -0.12 dBFS ... but, fortunately, this is not an issue when ASIO or WASAPI Exclusive Mode is used.

https://www.diyaudio.com/community/thre ... st-6482547

Dunno if W11 makes things different.

Post

Am I getting "the drift" here that attempting to detect and limit ISPs is basically a waste of time? If there is no theoretical bound to ISP amplitudes then any limiter reacting precisely to them will likely sound very bad - massively overshooting/ducking when there is no audible reason to. The only other choice is to clip them which is what we a trying to avoid in the first place!

I understand the point but I guess someone needs to tell the folks who wrote the specs for broadcasting, EBU-R and others, that the requirement to control max ISP levels is nonsense. I'm just trying to do what they require.

Post

Fender19 wrote: Thu Jun 09, 2022 6:15 pm Am I getting "the drift" here that attempting to detect and limit ISPs is basically a waste of time?
Not necessarily... but trying to be super-exact about it is probably a waste of time. The peaks will mostly be similar with most reconstruction filters (assuming we're using linear-phase at least), but the exact magnitude of any peak will vary based on the exact design of any given filter. The degenerate worst-case signal is not realistic at all in actual music, yet it serves as a reminder that you can't put a strict bound on these things (unless you know the exact reconstruction/resampling filter design).

The important part here though is that from practical engineering point of view there's a big difference between plenty of gross overshoots everywhere in actual music and sometimes overshooting the threshold very slightly. The former might cause some actual problems downstream where as the latter can be fixed by turning the gain down slightly if absolutely necessary (ie. it's not like -0.2dB or similar is that much more quiet than 0dB).

Tolerances are normal part of engineering (as opposed to theoretical science). Think of it as an engineering tolerance where you're not aiming for perfection, but trying to make it "good enough in practice."

Post Reply

Return to “DSP and Plugin Development”