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
impl OpusDecoder
Sourcepub const MAX_FRAME_SIZE_48K: usize = Decoder::MAX_FRAME_SIZE_48K
pub const MAX_FRAME_SIZE_48K: usize = Decoder::MAX_FRAME_SIZE_48K
Maximum decoded frame size per channel at 48 kHz.
Sourcepub fn new(sample_rate: u32, channels: usize) -> Result<Self, OpusError>
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)?;Sourcepub fn max_frame_size_per_channel(&self) -> usize
pub fn max_frame_size_per_channel(&self) -> usize
Return the maximum decoded frame size per channel for this output rate.
Sourcepub fn decode(
&mut self,
packet: &[u8],
pcm: &mut [i16],
fec: bool,
) -> Result<usize, OpusError>
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) whentrue. Passfalsefor 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)?;Sourcepub fn decode_float(
&mut self,
packet: &[u8],
pcm: &mut [f32],
fec: bool,
) -> Result<usize, OpusError>
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) whentrue. Passfalsefor 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)?;Sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Reset decoder state (e.g. after packet loss or seek).
Parameters: none. Returns: nothing.
Sourcepub fn final_range(&self) -> u32
pub fn final_range(&self) -> u32
Return the last range-coder final state observed by the decoder.