Skip to main content

WaveformAnalyzer

Struct WaveformAnalyzer 

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

Computes peak and RMS amplitude per time interval for an audio file.

Decodes audio via AudioDecoder (requesting packed f32 output so that per-sample arithmetic needs no format dispatch) and computes, for each configurable interval, the peak and RMS amplitudes in dBFS. The resulting Vec<WaveformSample> is designed for waveform display rendering.

§Examples

use ff_decode::WaveformAnalyzer;
use std::time::Duration;

let samples = WaveformAnalyzer::new("audio.mp3")
    .interval(Duration::from_millis(50))
    .run()?;

for s in &samples {
    println!("{:?}: peak={:.1} dBFS  rms={:.1} dBFS",
             s.timestamp, s.peak_db, s.rms_db);
}

Implementations§

Source§

impl WaveformAnalyzer

Source

pub fn new(input: impl AsRef<Path>) -> Self

Creates a new analyzer for the given audio file.

The default sampling interval is 100 ms. Call interval to override it.

Source

pub fn interval(self, d: Duration) -> Self

Sets the sampling interval.

Peak and RMS are computed independently for each interval of this length. Passing Duration::ZERO causes run to return DecodeError::AnalysisFailed.

Default: 100 ms.

Source

pub fn run(self) -> Result<Vec<WaveformSample>, DecodeError>

Runs the waveform analysis and returns one WaveformSample per interval.

The timestamp of each sample is the start of its interval. Audio is decoded as packed f32 samples; the decoder performs any necessary format conversion automatically.

§Errors

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.