DSPark 1.9.0
Header-only C++20 DSP for real-time and offline audio
Loading...
Searching...
No Matches
dspark::TruePeakDetector< T, MaxChannels > Class Template Reference

Per-channel 4x-oversampled inter-sample peak estimator. More...

#include <TruePeakDetector.h>

Public Member Functions

void reset () noexcept
 Clears all channel histories. Safe on the audio thread.
 
T processSample (T sample, int channel) noexcept
 Feeds one sample and returns the local true-peak estimate.
 
T getTailPeak (int channel) const noexcept
 Measures the zero-extended interpolation tail of one channel. Evaluates getTaps()-1 zero frames on a stack copy of that channel's state. Does not advance or clear live history. Call from the stream owner, not concurrently with processing/reset. Allocation-free and bounded work. Returns only the tail peak; combine with the maximum already observed.
 

Static Public Member Functions

static constexpr int getLatency () noexcept
 Group delay of the interpolation FIR in samples (per phase).
 
static constexpr int getTaps () noexcept
 Input samples one estimate is computed from (taps per phase).
 
static constexpr int getPhases () noexcept
 Number of interpolation phases (4x over-sampling).
 
static constexpr const T * getReversedPhase (int phase) noexcept
 One official interpolation phase, row reversed, for callers that run the interpolator as a block FIR.
 

Detailed Description

template<FloatType T, int MaxChannels = 16>
class dspark::TruePeakDetector< T, MaxChannels >

Per-channel 4x-oversampled inter-sample peak estimator.

Real-time safe: the polyphase coefficients are compile-time constants and processing is a fixed 48-multiply routine per sample (for float on SSE2 and NEON, one 4-lane pass with the phases as lanes; elsewhere the scalar per-phase dot products). The reading is the maximum of the four official interpolation phases and the raw |sample| (the raw sample can only pull the estimate toward the true analog peak, never above it).

Template Parameters
TSample type (float or double).
MaxChannelsNumber of independent channel histories.

Definition at line 81 of file TruePeakDetector.h.

Member Function Documentation

◆ getLatency()

template<FloatType T, int MaxChannels = 16>
static constexpr int dspark::TruePeakDetector< T, MaxChannels >::getLatency ( )
inlinestaticconstexprnoexcept

Group delay of the interpolation FIR in samples (per phase).

Definition at line 130 of file TruePeakDetector.h.

◆ getPhases()

template<FloatType T, int MaxChannels = 16>
static constexpr int dspark::TruePeakDetector< T, MaxChannels >::getPhases ( )
inlinestaticconstexprnoexcept

Number of interpolation phases (4x over-sampling).

Definition at line 143 of file TruePeakDetector.h.

◆ getReversedPhase()

template<FloatType T, int MaxChannels = 16>
static constexpr const T * dspark::TruePeakDetector< T, MaxChannels >::getReversedPhase ( int  phase)
inlinestaticconstexprnoexcept

One official interpolation phase, row reversed, for callers that run the interpolator as a block FIR.

Element j multiplies x[n - getTaps() + 1 + j] (the window oldest first). The maximum of the absolute values of the four phases and of |x[n]| is the reading processSample() returns, up to summation rounding.

Parameters
phasePhase index, clamped to [0, getPhases() - 1].
Returns
getTaps() coefficients in read-only storage.

Definition at line 156 of file TruePeakDetector.h.

◆ getTailPeak()

template<FloatType T, int MaxChannels = 16>
T dspark::TruePeakDetector< T, MaxChannels >::getTailPeak ( int  channel) const
inlinenoexcept

Measures the zero-extended interpolation tail of one channel. Evaluates getTaps()-1 zero frames on a stack copy of that channel's state. Does not advance or clear live history. Call from the stream owner, not concurrently with processing/reset. Allocation-free and bounded work. Returns only the tail peak; combine with the maximum already observed.

Definition at line 118 of file TruePeakDetector.h.

◆ getTaps()

template<FloatType T, int MaxChannels = 16>
static constexpr int dspark::TruePeakDetector< T, MaxChannels >::getTaps ( )
inlinestaticconstexprnoexcept

Input samples one estimate is computed from (taps per phase).

The reading returned for sample n was formed from x[n-getTaps()+1] .. x[n]. A caller that wants to change a reported peak has to change all of them: a gain applied to only part of that span does not scale the estimate by that gain.

Definition at line 140 of file TruePeakDetector.h.

◆ processSample()

template<FloatType T, int MaxChannels = 16>
T dspark::TruePeakDetector< T, MaxChannels >::processSample ( T  sample,
int  channel 
)
inlinenoexcept

Feeds one sample and returns the local true-peak estimate.

The result is the maximum of |sample| and the absolute values of the four official Annex 2 interpolation phases evaluated at this position (together they tile the 4x-oversampled reconstruction grid).

Parameters
sampleInput sample.
channelChannel index (0-based; clamped into range).
Returns
True-peak magnitude (>= |sample|).

Definition at line 102 of file TruePeakDetector.h.

◆ reset()

template<FloatType T, int MaxChannels = 16>
void dspark::TruePeakDetector< T, MaxChannels >::reset ( )
inlinenoexcept

Clears all channel histories. Safe on the audio thread.

Definition at line 85 of file TruePeakDetector.h.


The documentation for this class was generated from the following file: