Skip to main content

OpusDecoder

Struct OpusDecoder 

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

High-level single-stream Opus decoder.

This wrapper exposes the stable public API for packet-to-PCM decoding while keeping CELT and SILK state management internal to the crate.

Implementations§

Source§

impl OpusDecoder

Source

pub const MAX_FRAME_SIZE_48K: usize = Decoder::MAX_FRAME_SIZE_48K

Maximum decoded frame size per channel at 48 kHz.

Source

pub fn new(sample_rate: u32, channels: usize) -> Result<Self, OpusError>

Create a new decoder.

sample_rate must be 8000, 12000, 16000, 24000, or 48000, and channels must be 1 or 2.

§Examples
use opus_decoder::OpusDecoder;

let decoder = OpusDecoder::new(48_000, 2)?;
Source

pub fn max_frame_size_per_channel(&self) -> usize

Return the maximum decoded frame size per channel for this output rate.

Source

pub fn decode( &mut self, packet: &[u8], pcm: &mut [i16], fec: bool, ) -> Result<usize, OpusError>

Decode a packet into 16-bit PCM samples (interleaved if stereo).

Empty packet input triggers packet loss concealment using the previous decoder state. Returns the number of decoded samples per channel.

  • fec: reserved for future in-band FEC support. Currently treated as packet loss concealment (PLC) when true. Pass false for normal decode.
§Examples
use opus_decoder::OpusDecoder;

let mut decoder = OpusDecoder::new(48_000, 2)?;
let packet = std::fs::read("frame.opus")?;
let mut pcm = vec![0i16; 960 * 2];
let samples = decoder.decode(&packet, &mut pcm, false)?;
Source

pub fn decode_float( &mut self, packet: &[u8], pcm: &mut [f32], fec: bool, ) -> Result<usize, OpusError>

Decode a packet into f32 PCM samples (interleaved if stereo).

Empty packet input triggers packet loss concealment using the previous decoder state. Returns the number of decoded samples per channel.

  • fec: reserved for future in-band FEC support. Currently treated as packet loss concealment (PLC) when true. Pass false for normal decode.
§Examples
use opus_decoder::OpusDecoder;

let mut decoder = OpusDecoder::new(48_000, 1)?;
let packet = std::fs::read("frame.opus")?;
let mut pcm = vec![0.0f32; 960];
let samples = decoder.decode_float(&packet, &mut pcm, false)?;
Source

pub fn reset(&mut self)

Reset decoder state (e.g. after packet loss or seek).

Parameters: none. Returns: nothing.

Source

pub fn final_range(&self) -> u32

Return the last range-coder final state observed by the decoder.

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.