Implementing an ITU-R BS.1770-4 loudness meter in pure JavaScript is straightforward to approximate and surprisingly easy to get wrong by 0.2 to 2.0 dB. Two shortcuts account for almost every broken web meter: hardcoding the 48 kHz K-weighting biquad coefficients for 44.1 kHz files, and substituting a 4-point cubic spline for the Annex 2 True Peak oversampling filter.
1. Why Cubic Splines Miss
𝑓
𝑠
/
4
f
s
/4 45-Degree Overshoots by ~2 dB
Digital-to-analog converters and lossy codecs (Ogg Vorbis, AAC) reconstruct continuous waveforms between discrete PCM samples. The canonical stress test is a full-scale sine wave at f=fs/4 sampled at a 45-degree phase offset:
x[n]=2sin(4π+2nπ)⟹{+1,+1,−1,−1,…}
Every stored sample sits safely at 0.00 dBFS, yet the true continuous peak halfway between the consecutive +1 samples reaches 2≈1.4142, or +3.01 dBTP.
Naive JavaScript meters often try to detect inter-sample peaks with cubic polynomial or spline interpolation instead of FIR oversampling. That fails mathematically because short cubic kernels suffer severe high-frequency roll-off near fs/4:
-
Catmull-Rom / 4-point Lagrange cubic: At the midpoint (t=0.5), the kernel
[-1/16, 9/16, 9/16, -1/16]evaluates[-1, +1, +1, -1]to 1620=1.25 (+1.94 dBTP)—already under-reading by 1.07 dB. -
Cubic B-splines and damped/monotonic Hermite splines: Widely copied from graphics libraries, a cubic B-spline attenuates fs/4 signals by −3.77 dB at the midpoint, while monotonic splines clamp slopes to zero whenever consecutive samples tie (
+1, +1), reading 0.00 dBTP. Across real-world high-frequency transients and 45-degree fs/4 bursts, spline estimators routinely under-report true peaks by ~2 dB, clearing masters that hard-clip during streaming transcoding.
2. Exact BS.1770-4 K-Weighting + 48-Tap 4x Polyphase FIR in Pure JS
JavaScript's Number type is natively IEEE-754 Float64, which avoids single-precision quantization drift in low-frequency IIR filters—provided you compute both K-weighting biquad stages dynamically for the buffer's actual sampleRate via the bilinear transform:
- Stage 1 (Pre-filter High-Shelf): +4.0 dB shelf centered near 1681.97 Hz (Q≈0.707175), modeling acoustic head diffraction.
- Stage 2 (RLB High-Pass): Second-order high-pass near 38.135 Hz (Q≈0.500327), attenuating sub-bass rumble.
Hardcoding the 48 kHz coefficients from the BS.1770-4 table onto a 44.1 kHz Red Book master shifts both corner frequencies downward by ~8.8%, introducing measurable error on bass-heavy mixes.
For True Peak detection, implement the exact Annex 2 48-tap 4x oversampling FIR filter decomposed into 4 polyphase sub-filters of 12 taps each. Each input sample yields 4 candidate peaks using only 12 multiply-adds per phase:
JavaScript
// 4x polyphase FIR True Peak inner loop (4 phases x 12 taps = 48 taps)
let maxTruePeak = 0.0;
for (let i = 0; i < samples.length; i++) {
delayLine[writeIdx] = samples[i];
for (let p = 0; p < 4; p++) {
let acc = 0.0;
const h = POLYPHASE_48[p];
for (let k = 0; k < 12; k++) {
acc += h[k] * delayLine[(writeIdx - k + 12) % 12];
}
const mag = Math.abs(acc);
if (mag > maxTruePeak) maxTruePeak = mag;
}
writeIdx = (writeIdx + 1) % 12;
}
const truePeakDb = 20 * Math.log10(maxTruePeak);
Because phase 0 reproduces the original discrete sample and phases 1–3 evaluate the windowed-sinc fractional delays (+0.25,+0.50,+0.75 samples), passband droop stays flat through fs/4, accurately capturing the +3.01 dBTP overshoot.
3. EBU Tech 3341 Calibration Workflow (
±
0.011
LU
±0.011 LU /
+
0.108
dBTP
+0.108 dBTP)
Before shipping a loudness meter, validate it programmatically against the official EBU Tech 3341 compliance test vectors:
-
Two-stage gating vectors (
seq-3341-1toseq-3341-7): Verify the 400 ms block (75% overlap / 100 ms step) loudness math, the −70 LUFS absolute gate, and the Γr=Γa−10 LU relative gate across stepped bursts and multi-channel sums. -
Frequency & real-program vectors (
seq-3341-8toseq-3341-14): Validate Momentary (400 ms), Short-Term (3 s), and Integrated Loudness across multiple sample rates and dynamic mixes. -
True Peak vectors (
seq-3341-15andseq-3341-16): Feed phase-shifted fs/4 sinusoids and impulses to check overshoot bounds.
EBU Tech 3341 requires loudness accuracy within ±0.1 LU and True Peak accuracy within −0.4/+0.2 dBTP. With Float64 bilinear K-weighting and the 48-tap polyphase FIR filter, measured worst-case deviation across the compliance suite tightens to ±0.011 LU on integrated loudness and +0.108 dBTP on True Peak.
4. Production Delivery Targets
| Platform / Standard | Integrated Target | True Peak Ceiling | Practical Engineering Note |
|---|---|---|---|
| Spotify | -14.0 LUFS | -1.0 dBTP (-2.0 dBTP for loud masters) | Normalization turns loud masters down; extra ceiling absorbs Ogg Vorbis/AAC overshoot |
| Apple Music / Podcasts | -16.0 LUFS (-19.0 LUFS mono podcasts) | -1.0 dBTP | Matches Apple Sound Check and AES TD1008 podcast guidance |
| EBU R128 Broadcast | -23.0 ± 0.5 LUFS | -1.0 dBTP | Strict European broadcast delivery compliance |
You can inspect Integrated, Short-Term, Momentary, LRA, and 48-tap FIR True Peak locally in your browser using AIAC's LUFS Meter, and pull version-controlled platform normalization specs for CI/CD mastering checks from WaterJason/streaming-lufs-targets.
Ready to turn these engineering guides into shipping assets:
Top comments (0)