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
impl Analyzer
Sourcepub fn sample_rate(&self) -> u32
pub fn sample_rate(&self) -> u32
Configured sample rate, in hertz.
Sourcepub fn samples_per_block(&self) -> u32
pub fn samples_per_block(&self) -> u32
Number of samples in one 100 ms block at the configured rate.
Sourcepub fn push_planar<S: Sample>(&mut self, channels: &[&[S]]) -> Result<(), Error>
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
Error::ChannelMismatchifchannels.len()differs from the configured layout length.Error::PlanarLengthMismatchif slices have different lengths.Error::NonFiniteSampleif any sample isNaNor infinity.
§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])?;Sourcepub fn push_interleaved<S: Sample>(
&mut self,
samples: &[S],
) -> Result<(), Error>
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
Error::InterleavedLengthNotMultipleif the buffer length isn’t divisible by the channel count.Error::NonFiniteSampleif any sample isNaNor infinity.
§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)?;Sourcepub fn snapshot(&mut self) -> Snapshot
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());Sourcepub fn finalize(self) -> Report
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());Sourcepub fn reset(&mut self)
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);