Skip to main content

Decoder

Trait Decoder 

Source
pub trait Decoder: Send + Sync {
    // Required methods
    fn decode_into(
        &mut self,
        data: &[u8],
        out: &mut [Sample],
    ) -> Result<usize, CodecError>;
    fn max_decode_samples(&self, n_bytes: usize) -> usize;
    fn sample_rate(&self) -> u32;
    fn channels(&self) -> u16;

    // Provided method
    fn decode(&mut self, data: &[u8]) -> PcmBuf { ... }
}
Expand description

Decoder trait: converts codec-specific bytes into PCM samples.

The slice-based decode_into is the primary, always-available method (works in no_std). The convenience decode returning a Vec is only available with the std feature and has a default implementation that delegates to decode_into.

Required Methods§

Source

fn decode_into( &mut self, data: &[u8], out: &mut [Sample], ) -> Result<usize, CodecError>

Decode data into out, returning the number of samples written.

Returns CodecError::BufferTooSmall if out cannot hold the decoded samples (use max_decode_samples to size it).

Source

fn max_decode_samples(&self, n_bytes: usize) -> usize

Upper bound on the number of samples that decode_into will write for an input of n_bytes bytes.

Source

fn sample_rate(&self) -> u32

Get the sample rate of the decoded audio.

Source

fn channels(&self) -> u16

Get the number of channels.

Provided Methods§

Source

fn decode(&mut self, data: &[u8]) -> PcmBuf

Convenience wrapper that allocates a Vec and calls decode_into.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§