Skip to main content

Analyzer

Struct Analyzer 

Source
pub struct Analyzer { /* private fields */ }
Expand description

Streaming EBU R128 loudness analyzer.

See the crate-level documentation for an overview of the API. Build with AnalyzerBuilder.

Implementations§

Source§

impl Analyzer

Source

pub fn sample_rate(&self) -> u32

Configured sample rate, in hertz.

Source

pub fn channels(&self) -> &[Channel]

Configured channel layout.

Source

pub fn modes(&self) -> Mode

Configured modes.

Source

pub fn samples_per_block(&self) -> u32

Number of samples in one 100 ms block at the configured rate.

Source

pub fn push_planar<S: Sample>(&mut self, channels: &[&[S]]) -> Result<(), Error>

Push samples laid out as one slice per channel, in the same order as the configured channel layout.

All slices must have the same length.

§Errors
§Example
use ebur128_stream::{AnalyzerBuilder, Channel, Mode};

let mut analyzer = AnalyzerBuilder::new()
    .sample_rate(48_000)
    .channels(&[Channel::Left, Channel::Right])
    .modes(Mode::Momentary)
    .build()?;

let left  = vec![0.0_f32; 9_600]; // 100 ms
let right = vec![0.0_f32; 9_600];
analyzer.push_planar::<f32>(&[&left, &right])?;
Source

pub fn push_interleaved<S: Sample>( &mut self, samples: &[S], ) -> Result<(), Error>

Push samples laid out as interleaved frames ([L0, R0, L1, R1, ...]).

samples.len() must be a whole multiple of the channel count.

§Errors
§Example
use ebur128_stream::{AnalyzerBuilder, Channel, Mode};

let mut analyzer = AnalyzerBuilder::new()
    .sample_rate(48_000)
    .channels(&[Channel::Left, Channel::Right])
    .modes(Mode::Momentary)
    .build()?;

// 100 ms of stereo silence (9 600 frames × 2 channels).
let stereo = vec![0.0_f32; 9_600 * 2];
analyzer.push_interleaved::<f32>(&stereo)?;
Source

pub fn snapshot(&mut self) -> Snapshot

Take a snapshot of the current measurements.

Cheap to call repeatedly; momentary and short-term values are O(1). Integrated and LRA values are O(programme blocks) but cached between pushes.

§Example
use ebur128_stream::{AnalyzerBuilder, Channel, Mode};

let mut analyzer = AnalyzerBuilder::new()
    .sample_rate(48_000)
    .channels(&[Channel::Center])
    .modes(Mode::Momentary)
    .build()?;

analyzer.push_interleaved::<f32>(&vec![0.1; 48_000])?;  // 1 s
let s = analyzer.snapshot();
// Momentary fills after 400 ms; with 1 s pushed it's available.
assert!(s.momentary_lufs().is_some());
Source

pub fn finalize(self) -> Report

Consume the analyzer and return the final Report.

§Example
use ebur128_stream::{AnalyzerBuilder, Channel, Mode};

let mut a = AnalyzerBuilder::new()
    .sample_rate(48_000)
    .channels(&[Channel::Center])
    .modes(Mode::Integrated)
    .build()?;
a.push_interleaved::<f32>(&vec![0.0; 48_000])?;
let report = a.finalize();
// Silent input clears no gating block — integrated is None.
assert!(report.integrated_lufs().is_none());
Source

pub fn reset(&mut self)

Reset all internal state, retaining configuration.

Use this when reusing one analyzer across multiple programmes (e.g. between songs in a playback application).

§Example
use ebur128_stream::{AnalyzerBuilder, Channel, Mode};

let mut a = AnalyzerBuilder::new()
    .sample_rate(48_000)
    .channels(&[Channel::Center])
    .modes(Mode::Momentary)
    .build()?;
a.push_interleaved::<f32>(&vec![0.1; 48_000])?;
a.reset();
assert_eq!(a.snapshot().programme_duration_seconds(), 0.0);

Trait Implementations§

Source§

impl Debug for Analyzer

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.