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
impl Decoder
Sourcepub const fn new_minimp3_compat() -> Self
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).
Sourcepub fn decode<S: Sample>(
&mut self,
mp3: &[u8],
pcm: &mut [S],
) -> (usize, Result<FrameInfo, DecodeError>)
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.