Pure Go implementation of EBU R-128 / ITU-R BS.1770-4 loudness measurement.
- Integrated loudness (LUFS) with absolute and relative gating
- True peak (dBTP) via 4x polyphase FIR oversampling
- Loudness range (LU) per EBU TECH 3342
- Stereo and 5.1 surround support
Input: interleaved []float64 or []float32 PCM at 48 kHz, stereo or 5.1.
meter, err := ebur128.New(ebur128.LayoutStereo, 48000)
if err != nil {
log.Fatal(err)
}
meter.Write(buf) // []float64, interleaved L/R
res := meter.Loudness()
fmt.Printf("Integrated: %.1f LUFS\n", res.IntegratedLoudness)
fmt.Printf("True peak: %.1f dBTP\n", res.TruePeak)
fmt.Printf("LRA: %.1f LU\n", res.LoudnessRange)See cmd/example for a complete CLI tool.
Also available: WriteFloat32, Reset, Finalize (zero-pads trailing partial sub-block), Reserve (pre-alloc for known duration).
Cross-validated with ffmpeg -af ebur128=peak=true on generated test signals (see testdata/generate.sh):
| Metric | Tolerance |
|---|---|
| Integrated loudness | ±0.2 LUFS |
| True peak | ±0.5 dB |
| Loudness range | ±1.0 LU |
Example:
$ go run ./cmd/example testdata/sine_stereo_1k_loud.wav
Integrated loudness: -20.0 LUFS
True peak: -20.0 dBTP
Loudness range: 0.0 LU
$ ffmpeg -i testdata/sine_stereo_1k_loud.wav -af ebur128=peak=true -f null -
I: -20.0 LUFS
Peak: -20.0 dBFS
LRA: 0.0 LU
Integration tests require WAV files generated with ffmpeg:
bash testdata/generate.sh # generates ~6 MB of test WAVs
go test -v -count=1
Tests skip automatically if the WAV files are missing.
Benchmarks (Apple M2 Max 16-core CPU):
| Operation | Throughput | Allocations |
|---|---|---|
Write (Stereo, float64) |
~215 MB/s (>140x real-time) | 0 allocs/op |
WriteFloat32 (Stereo) |
~115 MB/s (>75x real-time) | 0 allocs/op |
Loudness (60s analysis) |
~20 µs | 3 allocs/op |
Write and WriteFloat32 are allocation-free in steady state.
- EBU R 128 / ITU-R BS.1770-4
- EBU TECH 3341 (loudness metering)
- EBU TECH 3342 (loudness range)