Skip to content

The resampler

BS.1770-4 defines its K-weighting filter coefficients for a 48 kHz sample rate only. To measure arbitrary-rate material, dsp-audio-metrics resamples every channel to 48 kHz before weighting. The same core also produces the 4× oversampled signal used for true peak.

Polyphase windowed-sinc

resamplePoly(x, up, down) in src/common.mjs is a textbook polyphase implementation of the ideal bandlimited interpolator, h(t) = a*sinc(a*t) with a = U/max(U, D):

  • a = 1 for pure upsampling — interpolation with a flat passband to the output Nyquist.
  • a = U/D < 1 for downsampling — the anti-aliasing lowpass sits at the output Nyquist.

Each of the up phases is a 129-tap (2*64 + 1) windowed-sinc FIR: the sinc is multiplied by a Kaiser window (β = 8.6) for ~90 dB stopband rejection, then the whole phase is normalized to unit gain, which guarantees a DC signal passes through with zero error — the property the test suite asserts on a 3000-sample interior.

text
continuous filter:  h(t) = a · sinc(a·t)              a = U / max(U, D)
phase p, tap m:     h_p[m] = a · sinc(a·(p/U + m − T)) · kaiser(m)     m ∈ [0, 2T]
output sample o:    inPos = o·D/U,  src = ⌊inPos⌋ + T − m

tapsPerPhase = 64, up can be 4 (true peak) or the reduced ratio for 44.1 kHz (160/147 after gcd). The full FIR would be 2·64·up + 1 taps; polyphase decomposition makes it up reads of 129 taps per output sample.

Where it runs

CallRatioPurpose
resampleToRate(ch, inRate)48k/inRate (reduced)K-weighting grid
truePeakDb4/1≥192 kHz reconstruction

Edge behavior

Like any FIR, the first and last ~taps·up output samples are partially clipped (the filter "hangs" past the signal's ends). The suite asserts DC exactly on the interior and tolerates the transients — for real measurements the affected fraction of a 30-second program is negligible.

Why not FFT resampling?

A windowed-sinc resampler is O(n·taps), FFT resampling is O(n log n), but FFT resampling circularly wraps the signal (spectral leakage from the edges) and forces a fixed overlap strategy. For a streaming loudness meter the polyphase filter is exact in the interior, has zero dependencies, and is trivially auditable line-by-line against the math above.