ebur128
Rust implementation of the EBU R128 loudness standard for audio analysis and normalization
Repository Health
Technical Analysis
ebur128 is a Rust crate implementing the EBU R128 loudness recommendation, the broadcast-industry standard for measuring and normalizing perceived audio loudness so different pieces of audio sound like roughly the same volume to listeners. It is a Rust port of the widely used libebur128 C library, producing matching results with comparable performance, and covers momentary (M), short-term (S), and integrated (I) loudness modes, loudness range (LRA) measurement, and true-peak scanning across arbitrary sample rates.
The crate exposes a small, focused EbuR128 analyzer type that accepts interleaved or planar audio frames in i16, i32, f32, or f64 formats, making it easy to drop into existing audio pipelines regardless of the sample format in use. An optional C API layer provides ABI compatibility with the original libebur128, so the crate can also serve as a drop-in replacement in C/C++ codebases via cargo-c. It is used in production by projects like GStreamer’s loudness-normalization elements and various audio mastering and podcast/streaming tools that need standards-compliant loudness metering.
What You Get
- An
EbuR128analyzer supporting momentary, short-term, and integrated (program) loudness modes - Loudness range (LRA) measurement per EBU TECH 3342
- True-peak scanning for detecting inter-sample peaks
- Support for i16/i32/f32/f64 samples in both interleaved and planar layouts
- An optional C API that is ABI-compatible with libebur128, buildable via cargo-c
- Automatic recalculation of filter coefficients to support arbitrary sample rates
Common Use Cases
- Normalizing loudness across a podcast or streaming catalog so episodes/tracks play back at consistent volume
- Implementing broadcast-compliant loudness metering in audio production and mastering tools
- Adding EBU R128 loudness analysis to media pipelines such as GStreamer-based transcoding or playback systems
- Validating that exported audio/video deliverables meet loudness targets required by broadcasters or streaming platforms
Under The Hood
Architecture - The crate centers on a single EbuR128 struct (src/ebur128.rs) that owns per-channel filter state, a sliding history buffer (src/history.rs), and gating-block accumulators used to compute momentary, short-term, and integrated loudness. Incoming audio frames are pushed through add_frames_*/seed_frames_* entry points for i16/i32/f32/f64 samples in interleaved or planar layout, run through a K-weighting filter (src/filter.rs), then accumulated into 400ms gating blocks whose energies are stored in a histogram (src/histogram_bins.rs) for later loudness/LRA queries. True-peak detection (src/true_peak.rs) uses an oversampling interpolator (src/interp.rs) to catch inter-sample peaks that plain sample-peak metering misses. An optional capi module (src/capi.rs) wraps the safe Rust API in an unsafe, ABI-compatible C interface for consumption from non-Rust codebases via cargo-c.
Tech Stack - Pure Rust (edition 2018, MSRV 1.60) with a deliberately small dependency footprint: bitflags for the Mode flags, smallvec for small-buffer optimization, and dasp_sample/dasp_frame for generic sample-format handling. Dev-dependencies (criterion, quickcheck, hound, and a reference ebur128-c C binding) support benchmarking, property-based testing, and cross-validation against the original C implementation. The optional C API is built via cargo-c, which generates a shared/static library, C header, and pkg-config file compatible with libebur128.
Code Quality - The crate has a dedicated tests/ directory including a reference_tests suite (gated behind a reference-tests feature) that validates results against the official EBU compliance test vectors, plus quickcheck-based property tests comparing output against the ebur128-c reference binding under the c-tests feature. Internal modules (interp, true_peak, history, filter, utils) are conditionally exposed as pub only under an internal-tests feature, keeping the public surface minimal in normal builds while still allowing focused unit/benchmark coverage. Code favors explicit Result<_, Error> returns over panics for fallible operations like channel configuration and window sizing.
API Design - The public API is small and consistent: construct with EbuR128::new(channels, rate, mode), feed samples through one of eight add_frames_*/seed_frames_* variants matched to sample type and layout, then read results via loudness_global, loudness_momentary, loudness_shortterm, loudness_range, and their _multiple variants for combining several analyzers. Bitflag Mode values let callers enable only the measurement modes they need, avoiding unnecessary computation, and fallible setters return Result<(), Error> rather than panicking on invalid channel/window configuration. Documentation is concise but sufficient, with doc comments on the crate root and public methods plus links out to the underlying EBU TECH specifications for readers who need the full standard.
Used by 2 apps in this directory
Anarlog
Note Taking · AI Assistants · Productivity
Anarlog is an open-source, local-first AI meeting notetaker that records, transcribes, and summarizes meetings entirely on your device — no cloud lock-in, no mandatory account, and every note saved as a plain markdown file you own forever.
Meetily
Productivity · AI Assistants
Privacy-first AI meeting assistant that transcribes and summarizes your meetings entirely on your local machine — no cloud, no data leakage.