Available on crate feature
normalize only.Expand description
Loudness normalisation helpers.
Two pieces:
gain_to_target— pure function: given a measuredReportand a target LUFS, return the linear gain to apply.Normalizer— convenience pipeline: run a buffer through the analyzer, apply the calibrated gain, optionally clip-protect against true-peak overshoot.
The normaliser is intentionally a separate concern from the
analyzer (per the SPEC discipline) but lives in the same crate so
callers don’t have to wire the math themselves. This module is
gated behind the normalize feature.
§Example
use ebur128_stream::{normalize::Normalizer, Channel, Mode};
// 1 second of -3 dBFS sine (≈ -3 LUFS-ish)
let mut buf: Vec<f32> = (0..48_000)
.flat_map(|i| {
let v = 0.7 * (2.0 * std::f32::consts::PI * 1000.0 * i as f32 / 48_000.0).sin();
[v, v]
})
.collect();
let n = Normalizer::new(48_000, &[Channel::Left, Channel::Right])
.target_lufs(-23.0)
.true_peak_ceiling_dbtp(-1.0);
let report = n.normalize_in_place(&mut buf)?;
assert!(report.applied_gain_db.is_finite());Structs§
- Normalize
Report - Result of a normalisation pass.
- Normalizer
- One-shot normaliser: analyse + scale a buffer in place.
Functions§
- gain_
to_ target - Compute the linear amplitude gain that, when applied to the audio
the
Reportwas measured from, would shift its integrated loudness fromreport.integrated_lufs()totarget_lufs.