integratedLufs
Computes the program loudness (the number streaming platforms normalize to), following ITU-R BS.1770-4.
ts
integratedLufs(audio: AudioInput, sampleRate: number): numberArguments
| Param | Type | Description |
|---|---|---|
audio | AudioInput | Mono buffer or 2-D array of channels (see below). |
sampleRate | number | Input sample rate; must be a positive integer. |
AudioInput is Float64Array | Array<number> | Array<Float64Array>. A 1-D input is treated as mono and duplicated to stereo; a 2-D input is treated as the individual channels.
Returns
number — the gated integrated loudness in LUFS (same unit as LKFS). Returns -Infinity for a silent or too-short input (the gate requires at least one 400 ms block to survive).
Algorithm (exactly as BS.1770-4)
- Resample to the 48 kHz measurement grid (polyphase Kaiser sinc — the K-weight filter coefficients are only valid at 48 kHz).
- Apply the K-weighting filter per channel: a high-pass at 38 Hz followed by a high-shelf that is flat to 1 kHz and rises to +4 dB above 2 kHz.
- Compute
meanSquareper 400 ms block (75% overlap), then apply the absolute gate (-70 LKFS), then the relative gate (block - gatedLoudness > -10 LU), iterated to convergence. -0.691 + 10 * log10(gatedSum), wheregatedSumweights channels[1, 1, 1, 1.41, 1.41]for mono/stereo/LR/LC/Rs.
Examples
js
import { integratedLufs } from "dsp-audio-metrics";
// Full-scale 1 kHz sine → -3.01
const sr = 48000;
const sine = new Float64Array(sr).map((_, i) =>
Math.sin((2 * Math.PI * 1000 * i) / sr),
);
integratedLufs(sine, sr); // -3.01...
// 44.1 kHz content is resampled internally
integratedLufs(sine44k, 44100); // agrees with the 48k version within 0.1 LUErrors
Throws RangeError if sampleRate is not a positive integer, and TypeError for empty input (the loudness of zero samples is undefined).
