Struct ebur128::EbuR128

source ·
pub struct EbuR128 { /* private fields */ }
Expand description

EBU R128 loudness analyzer.

Implementations§

source§

impl EbuR128

source

pub fn new(channels: u32, rate: u32, mode: Mode) -> Result<Self, Error>

Create a new instance with the given configuration.

source

pub fn mode(&self) -> Mode

Get the configured mode.

source

pub fn channels(&self) -> u32

Get the configured number of channels.

source

pub fn rate(&self) -> u32

Get the configured sample rate.

source

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

Get the configured channel types.

source

pub fn max_window(&self) -> usize

Get the configured maximum window duration in ms.

source

pub fn max_history(&self) -> usize

Get the configured maximum history in ms.

source

pub fn set_channel( &mut self, channel_number: u32, value: Channel ) -> Result<(), Error>

Set channel type.

The default is:

  • 0 -> Left
  • 1 -> Right
  • 2 -> Center
  • 3 -> Unused
  • 4 -> LeftSurround
  • 5 -> RightSurround
  • _ -> Unused
source

pub fn set_channel_map(&mut self, channel_map: &[Channel]) -> Result<(), Error>

Set channel types.

The default is:

  • 0 -> Left
  • 1 -> Right
  • 2 -> Center
  • 3 -> Unused
  • 4 -> LeftSurround
  • 5 -> RightSurround
  • _ -> Unused
source

pub fn change_parameters( &mut self, channels: u32, rate: u32 ) -> Result<(), Error>

Change library parameters.

Note that the channel map will be reset when setting a different number of channels. The current unfinished block will be lost.

source

pub fn set_max_window(&mut self, window: u32) -> Result<(), Error>

Set the maximum window duration.

Set the maximum duration in ms that will be used for EbuR128::loudness_window. Note that this destroys the current content of the audio buffer.

source

pub fn set_max_history(&mut self, history: u32) -> Result<(), Error>

Set the maximum history.

Set the maximum history in ms that will be stored for loudness integration. More history provides more accurate results, but requires more resources.

Applies to EbuR128::loudness_range and EbuR128::loudness_global when Mode::HISTOGRAM is not set.

Default is ULONG_MAX (at least ~50 days). Minimum is 3000ms for Mode::LRA and 400ms for Mode::M.

source

pub fn reset(&mut self)

Resets the current state.

source

pub fn add_frames_i16(&mut self, frames: &[i16]) -> Result<(), Error>

Add interleaved frames to be processed.

source

pub fn add_frames_i32(&mut self, frames: &[i32]) -> Result<(), Error>

Add interleaved frames to be processed.

source

pub fn add_frames_f32(&mut self, frames: &[f32]) -> Result<(), Error>

Add interleaved frames to be processed.

source

pub fn add_frames_f64(&mut self, frames: &[f64]) -> Result<(), Error>

Add interleaved frames to be processed.

source

pub fn add_frames_planar_i16(&mut self, frames: &[&[i16]]) -> Result<(), Error>

Add planar frames to be processed.

source

pub fn add_frames_planar_i32(&mut self, frames: &[&[i32]]) -> Result<(), Error>

Add planar frames to be processed.

source

pub fn add_frames_planar_f32(&mut self, frames: &[&[f32]]) -> Result<(), Error>

Add planar frames to be processed.

source

pub fn add_frames_planar_f64(&mut self, frames: &[&[f64]]) -> Result<(), Error>

Add planar frames to be processed.

source

pub fn seed_frames_i16(&mut self, frames: &[i16]) -> Result<(), Error>

Add interleaved frames to warmup filters, but not be considered for measurements. See EbuR128::loudness_global_multiple for example usage.

source

pub fn seed_frames_i32(&mut self, frames: &[i32]) -> Result<(), Error>

Add interleaved frames to warmup filters, but not be considered for measurements. See EbuR128::loudness_global_multiple for example usage.

source

pub fn seed_frames_f32(&mut self, frames: &[f32]) -> Result<(), Error>

Add interleaved frames to warmup filters, but not be considered for measurements. See EbuR128::loudness_global_multiple for example usage.

source

pub fn seed_frames_f64(&mut self, frames: &[f64]) -> Result<(), Error>

Add interleaved frames to warmup filters, but not be considered for measurements. See EbuR128::loudness_global_multiple for example usage.

source

pub fn seed_frames_planar_i16(&mut self, frames: &[&[i16]]) -> Result<(), Error>

Add planar frames to warmup filters, but not be considered for measurements. See EbuR128::loudness_global_multiple for example usage.

source

pub fn seed_frames_planar_i32(&mut self, frames: &[&[i32]]) -> Result<(), Error>

Add planar frames to warmup filters, but not be considered for measurements. See EbuR128::loudness_global_multiple for example usage.

source

pub fn seed_frames_planar_f32(&mut self, frames: &[&[f32]]) -> Result<(), Error>

Add planar frames to warmup filters, but not be considered for measurements. See EbuR128::loudness_global_multiple for example usage.

source

pub fn seed_frames_planar_f64(&mut self, frames: &[&[f64]]) -> Result<(), Error>

Add planar frames to warmup filters, but not be considered for measurements. See EbuR128::loudness_global_multiple for example usage.

source

pub fn loudness_global(&self) -> Result<f64, Error>

Get global integrated loudness in LUFS.

source

pub fn loudness_global_multiple<'a>( iter: impl Iterator<Item = &'a Self> ) -> Result<f64, Error>

Get global integrated loudness in LUFS across multiple instances.

This can be used to allow parallel iteration of long signals, assuming some care is taken:

  1. Divide input-signal up in “chunks” of even 100ms samples. Make chunks overlap by 400ms, for example (0-10s, 9.6-20s, 19.6-30s, …)
  2. The first chunk is processed as normal. Then in parallel, for each remaining chunk, create a new instance of EbuR128, and in parallel:
    1. Feed the first 100ms of the chunk (these are samples overlapping with last chunk) through seed_frames_* function. This is sufficient to make filter-states in each instance what they would have been if a single analyzer would have reached this point.
    2. Process the remaining samples of each chunk through the analyzer
  3. Call EbuR128::loudness_global_multiple over all the chunks to get the global loudness
source

pub fn loudness_momentary(&self) -> Result<f64, Error>

Get momentary loudness (last 400ms) in LUFS.

source

pub fn loudness_shortterm(&self) -> Result<f64, Error>

Get short-term loudness (last 3s) in LUFS.

source

pub fn loudness_window(&self, window: u32) -> Result<f64, Error>

Get loudness of the specified window in LUFS.

window must not be larger than the current window. The current window can be changed by calling EbuR128::set_max_window.

source

pub fn loudness_range(&self) -> Result<f64, Error>

Get loudness range (LRA) of programme in LU.

Calculates loudness range according to EBU 3342.

source

pub fn loudness_range_multiple<'a>( iter: impl IntoIterator<Item = &'a Self> ) -> Result<f64, Error>

Get loudness range (LRA) of programme in LU across multiple instances.

Calculates loudness range according to EBU 3342.

source

pub fn sample_peak(&self, channel_number: u32) -> Result<f64, Error>

Get maximum sample peak from all frames that have been processed.

The equation to convert to dBFS is: 20 * log10(out)

source

pub fn prev_sample_peak(&self, channel_number: u32) -> Result<f64, Error>

Get maximum sample peak from the last call to EbuR128::add_frames.

The equation to convert to dBFS is: 20 * log10(out)

source

pub fn true_peak(&self, channel_number: u32) -> Result<f64, Error>

Get maximum true peak from all frames that have been processed.

Uses an implementation defined algorithm to calculate the true peak. Do not try to compare resulting values across different versions of the library, as the algorithm may change.

The current implementation uses a custom polyphase FIR interpolator to calculate true peak. Will oversample 4x for sample rates < 96000 Hz, 2x for sample rates < 192000 Hz and leave the signal unchanged for 192000 Hz.

The equation to convert to dBTP is: 20 * log10(out)

source

pub fn prev_true_peak(&self, channel_number: u32) -> Result<f64, Error>

Get maximum true peak from the last call to EbuR128::add_frames.

Uses an implementation defined algorithm to calculate the true peak. Do not try to compare resulting values across different versions of the library, as the algorithm may change.

The current implementation uses a custom polyphase FIR interpolator to calculate true peak. Will oversample 4x for sample rates < 96000 Hz, 2x for sample rates < 192000 Hz and leave the signal unchanged for 192000 Hz.

The equation to convert to dBTP is: 20 * log10(out)

source

pub fn relative_threshold(&self) -> Result<f64, Error>

Get relative threshold in LUFS.

Trait Implementations§

source§

impl Debug for EbuR128

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 Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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<S> FromSample<S> for S

source§

fn from_sample_(s: S) -> S

source§

impl<T, U> Into<U> for Twhere 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> ToSample<U> for Twhere U: FromSample<T>,

source§

fn to_sample_(self) -> U

source§

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

§

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 Twhere U: TryFrom<T>,

§

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.
source§

impl<S, T> Duplex<S> for Twhere T: FromSample<S> + ToSample<S>,