Skip to main content

AudioDecoderBuilder

Struct AudioDecoderBuilder 

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

Builder for configuring and constructing an AudioDecoder.

This struct provides a fluent interface for setting up decoder options before opening an audio file. It is created by calling AudioDecoder::open().

§Examples

§Basic Usage

use ff_decode::AudioDecoder;

let decoder = AudioDecoder::open("audio.mp3")?
    .build()?;

§With Custom Format and Sample Rate

use ff_decode::AudioDecoder;
use ff_format::SampleFormat;

let decoder = AudioDecoder::open("audio.mp3")?
    .output_format(SampleFormat::F32)
    .output_sample_rate(48000)
    .build()?;

Implementations§

Source§

impl AudioDecoderBuilder

Source

pub fn output_format(self, format: SampleFormat) -> Self

Sets the output sample format for decoded frames.

If not set, frames are returned in the source format. Setting an output format enables automatic conversion during decoding.

§Common Formats
§Examples
use ff_decode::AudioDecoder;
use ff_format::SampleFormat;

let decoder = AudioDecoder::open("audio.mp3")?
    .output_format(SampleFormat::F32)
    .build()?;
Source

pub fn output_sample_rate(self, sample_rate: u32) -> Self

Sets the output sample rate in Hz.

If not set, frames are returned at the source sample rate. Setting an output sample rate enables automatic resampling during decoding.

§Common Sample Rates
  • 44100 Hz - CD quality audio
  • 48000 Hz - Professional audio, most common in video
  • 96000 Hz - High-resolution audio
§Examples
use ff_decode::AudioDecoder;

// Resample to 48kHz
let decoder = AudioDecoder::open("audio.mp3")?
    .output_sample_rate(48000)
    .build()?;
Source

pub fn output_channels(self, channels: u32) -> Self

Sets the output channel count.

If not set, frames are returned with the source channel count. Setting an output channel count enables automatic channel remixing during decoding.

§Common Channel Counts
  • 1 - Mono
  • 2 - Stereo
  • 6 - 5.1 surround sound
§Examples
use ff_decode::AudioDecoder;

// Convert to stereo
let decoder = AudioDecoder::open("audio.mp3")?
    .output_channels(2)
    .build()?;
Source

pub fn path(&self) -> &Path

Returns the configured file path.

Source

pub fn get_output_format(&self) -> Option<SampleFormat>

Returns the configured output format, if any.

Source

pub fn get_output_sample_rate(&self) -> Option<u32>

Returns the configured output sample rate, if any.

Source

pub fn get_output_channels(&self) -> Option<u32>

Returns the configured output channel count, if any.

Source

pub fn build(self) -> Result<AudioDecoder, DecodeError>

Builds the audio decoder with the configured options.

This method opens the media file, initializes the decoder context, and prepares for frame decoding.

§Errors

Returns an error if:

§Examples
use ff_decode::AudioDecoder;

let decoder = AudioDecoder::open("audio.mp3")?
    .build()?;

// Start decoding
for frame in decoder.frames().take(100) {
    let frame = frame?;
    // Process frame...
}

Trait Implementations§

Source§

impl Debug for AudioDecoderBuilder

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.