Skip to main content

Decoder

Struct Decoder 

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

The core MP3 decoder, with no internal buffering.

The decoder is about 22 KiB: it holds the filterbank state between frames and the working memory for decoding one. Nothing is allocated.

Implementations§

Source§

impl Decoder

Source

pub const fn new() -> Self

Instantiates a Decoder.

Source

pub const fn new_minimp3_compat() -> Self

Instantiates a Decoder whose output is bit-identical to minimp3’s, including quirks nanomp3 otherwise corrects. Currently that only affects i16 output, where minimp3 rounds samples in (−1.5, −0.5] to 0 instead of −1 (see Sample).

Source

pub fn decode<S: Sample>( &mut self, mp3: &[u8], pcm: &mut [S], ) -> (usize, Result<FrameInfo, DecodeError>)

Decodes the next frame of mp3 into pcm. Returns how many bytes of mp3 were consumed (always advance past them, whatever the result) and either the decoded frame’s information or why no audio came out.

mp3 should hold several frames’ worth of data (16 KiB is plenty): frames are only recognized once the frames after them are seen, and a frame cut off at the end of the input is skipped as junk.

Samples are interleaved. pcm can hold f32 samples (nominally in [-1.0, 1.0], not clipped) or signed or unsigned 8-, 16- or 32-bit integers; see Sample for the conversions.

§Panics

Panics if pcm is less than MAX_SAMPLES_PER_FRAME long.

Trait Implementations§

Source§

impl Clone for Decoder

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for Decoder

Source§

fn default() -> Self

Returns the “default value” for a type. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.