Skip to main content

Module normalize

Module normalize 

Source
Available on crate feature normalize only.
Expand description

Loudness normalisation helpers.

Two pieces:

  1. gain_to_target — pure function: given a measured Report and a target LUFS, return the linear gain to apply.
  2. 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§

NormalizeReport
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 Report was measured from, would shift its integrated loudness from report.integrated_lufs() to target_lufs.