|
DSPark 1.9.0
Header-only C++20 DSP for real-time and offline audio
|
Block-based reading of the band-limited reconstruction peak. More...
#include <TruePeakDetector.h>
Classes | |
| struct | Channel |
| History of one channel (kTaps - 1 samples plus one chunk). More... | |
Public Member Functions | |
| TruePeakEstimator () noexcept | |
| Designs the interpolation phases. | |
| void | process (Channel &channel, const T *x, int n, T *peak, bool annex2Guard=false) noexcept |
| Appends samples to a channel and raises each peak[i] to the reading of x[i]'s position. | |
| T | processMax (Channel &channel, const T *x, int n, T atLeast) noexcept |
| Appends samples to a channel and returns the largest finite reading among them (0 if none), as process() would read them. | |
| T | getTailPeak (const Channel &channel) noexcept |
| Peak of the zero-extended tail of a finite programme. | |
Static Public Member Functions | |
| static constexpr int | getDelay () noexcept |
| Input samples one reading reaches back. | |
Static Public Attributes | |
| static constexpr int | kTaps = 64 |
| Taps per interpolation phase. | |
| static constexpr int | kPhases = 3 |
| Quarter, half and three-quarter points. | |
| static constexpr int | kChunk = 128 |
| Most samples one process() call takes. | |
Block-based reading of the band-limited reconstruction peak.
The BS.1770 Annex 2 procedure (4x over-sampling, low-pass interpolation, absolute value) with a longer interpolator than the Annex 2 example table: the reconstruction is evaluated at the quarter, half and three-quarter points of every sample interval with a 64-tap Kaiser-windowed sinc per phase (beta 8, cut at Nyquist, each phase normalised to unity at DC), and every local maximum of that 4x grid is refined with the vertex of the parabola through it and its two neighbours, which removes most of the grid error (a 4x grid alone misses a crest at 0.45 fs by up to 0.55 dB).
Measured against the exact reconstruction sum of the zero-extended signal (the Annex 2 table in brackets): steady sines read within 0.003 dB up to 0.49 fs (+0.22 dB); tones up to 0.45 fs that start abruptly within -0.24 / +0.07 dB (-0.78 / +0.19); noise band-limited to 0.45 fs within -0.03 / +0.01 dB (-0.37 / +0.04). Content between 0.45 fs and Nyquist is beyond any short kernel: tones there that start abruptly read -1.1 / +0.75 dB (-2.8 / +0.23) and white noise -0.55 / +0.47 dB (-1.08 / +0.40); the table reads that band low because it attenuates it. A crest there is built by samples hundreds of positions away, so a reading that must answer within getDelay() samples cannot follow it: meters, which can wait, read with TruePeakAnalyzer.
Each reading at input sample n describes the interval x[n - 32] .. x[n - 31] and the half grid step before it, so it reaches back getDelay() samples; a finite programme is completed with getTailPeak().
Cost per sample of one channel in 128-sample chunks of white noise, with the Annex 2 guard, measured on hosted CI runners (before the reading loops ran on vectors in brackets): 7 to 10 ns in float and 14 to 20 in double on x86-64 with the run-time dispatch (GCC, Clang and MSVC; 10 to 26 and 24 to 34), 13 to 16 and 25 to 33 on SSE2 (16 to 26 and 33 to 40), and 16 to 20 and 33 to 40 on an arm64 server core (17 to 31 and 33 to 46). processMax() also skips every vector whose grid points cannot reach the maximum it already holds, and costs 0.37 to 0.83 of what it did.
Threading: a channel's state and the estimator's scratch belong to the stream owner; process() and getTailPeak() are not re-entrant. No allocation; the kernel is designed by the constructor.
| T | Sample type (float or double). |
Definition at line 558 of file TruePeakDetector.h.
|
inlinenoexcept |
Designs the interpolation phases.
Definition at line 574 of file TruePeakDetector.h.
|
inlinestaticconstexprnoexcept |
Input samples one reading reaches back.
Definition at line 581 of file TruePeakDetector.h.
|
inlinenoexcept |
Peak of the zero-extended tail of a finite programme.
Reads kTaps zero samples on a copy of the channel, so every interval the last samples still reach is measured; the live history is not changed. Returns only the tail; combine it with the readings already taken. Same threading as process().
| channel | The channel's history. |
Definition at line 662 of file TruePeakDetector.h.
|
inlinenoexcept |
Appends samples to a channel and raises each peak[i] to the reading of x[i]'s position.
NaN readings are ignored (peak[i] keeps its value).
| channel | The channel's history (owned by the caller). |
| x | Input samples. |
| n | Sample count, 1 .. kChunk. |
| peak | Readings to raise, n values. |
| annex2Guard | Also raises peak[i] to the BS.1770 Annex 2 table's phases over the same window, so a meter built on that table never reads above the result either. |
Definition at line 597 of file TruePeakDetector.h.
|
inlinenoexcept |
Appends samples to a channel and returns the largest finite reading among them (0 if none), as process() would read them.
For a running maximum: when no grid point of the chunk exceeds atLeast / 1.25 (a crest refinement raises a grid point by at most a quarter), the refinement is skipped and the grid maximum is returned; otherwise every reading is evaluated exactly as process() does. The history advances the same way in both cases.
| channel | The channel's history (owned by the caller). |
| x | Input samples. |
| n | Sample count, 1 .. kChunk. |
| atLeast | The running maximum the caller already holds. |
Definition at line 634 of file TruePeakDetector.h.
|
staticconstexpr |
Most samples one process() call takes.
Definition at line 563 of file TruePeakDetector.h.
|
staticconstexpr |
Quarter, half and three-quarter points.
Definition at line 562 of file TruePeakDetector.h.
|
staticconstexpr |
Taps per interpolation phase.
Definition at line 561 of file TruePeakDetector.h.