Class TruePeakDetector

Streaming 4× polyphase true-peak detector for ONE channel (ITU-R BS.1770-5 Annex 2). Maintains a 12-sample input history so successive blocks join seamlessly, runs every phase of the polyphase FIR per input sample (giving the 4× oversampled stream), rectifies, and tracks the running max.

The verbatim coefficients are quoted at 48 kHz. At higher input rates fewer oversampling phases are needed for the same accuracy (Annex 2: 96 kHz → 2× suffices); this 4× design is the conservative default at any rate.

Constructors

  • Parameters

    • sampleRate: number = 48_000

      Input sample rate in Hz. Selects the oversampling factor so the oversampled rate reaches BS.1770-5's ≥192 kHz requirement (Annex 2, p.18). Defaults to 48 kHz (the rate the verbatim FIR is quoted at → 4×).

    Returns TruePeakDetector

Properties

fir: readonly (readonly number[])[]

The polyphase FIR actually used (verbatim at 4×, generated for >4×).

history: Float32Array
oversample: number

Oversampling factor chosen for the input sample rate (≥4; ≥192 kHz).

peak: number = 0
writeIndex: number = 0

Methods

  • Pushes a block of input samples through the polyphase interpolator and updates the running true peak (max absolute oversampled value).

    Parameters

    • samples: Float32Array

    Returns void

  • True-peak level in dBTP (ITU-R BS.1770-5 Annex 2 stage 5: 20·log10 of the rectified oversampled peak, relative to 100% full scale). Returns -Infinity for pure silence.

    Returns number