pub struct OpusDecoder {
pub last_range: u32,
/* private fields */
}Expand description
An Opus decoder for one mono or stereo stream.
Decodes packets from any Opus encoder at any of the five API rates and either channel count (a stereo stream can be decoded to mono and vice versa). Pass an empty packet to conceal a lost one. After the first few frames, decoding performs no heap allocation.
Fields§
§last_range: u32Final range-decoder state of the last decoded packet (libopus
OPUS_GET_FINAL_RANGE): equal to the encoder’s for a correctly
transmitted packet, so it detects corruption and desynchronisation.
Implementations§
Source§impl OpusDecoder
impl OpusDecoder
Sourcepub fn new(sampling_rate: i32, channels: usize) -> Result<Self, Error>
pub fn new(sampling_rate: i32, channels: usize) -> Result<Self, Error>
§Errors
Error::BadArg if sampling_rate is not 8000, 12000, 16000, 24000 or
48000 Hz or channels is not 1 or 2.
Sourcepub fn decode_fec(
&mut self,
packet: &[u8],
frame_size: usize,
output: &mut [f32],
) -> Result<usize, Error>
pub fn decode_fec( &mut self, packet: &[u8], frame_size: usize, output: &mut [f32], ) -> Result<usize, Error>
Forward-error-correction decode: reconstruct a LOST frame from the LBRR
(low-bitrate redundancy) embedded in the NEXT received packet. Drives
the SILK decoder in FLAG_DECODE_LBRR mode, which self-selects: it decodes
the redundant frame when the packet carries LBRR for it, and falls back
to PLC extrapolation when it doesn’t. CELT-only or multi-frame packets
fall back to plain PLC (no SILK LBRR to recover). After this call the
caller decodes packet normally for the following frame.
§Errors
Error::InvalidPacket if input is malformed or truncated;
Error::BufferTooSmall if frame_size exceeds the decoder’s capacity or
output; Error::Internal if a codec stage fails.
Sourcepub fn decode(
&mut self,
input: &[u8],
frame_size: usize,
output: &mut [f32],
) -> Result<usize, Error>
pub fn decode( &mut self, input: &[u8], frame_size: usize, output: &mut [f32], ) -> Result<usize, Error>
§Errors
Error::InvalidPacket if input is malformed, truncated, or longer than
120 ms; Error::BufferTooSmall if output cannot hold the decoded frame;
Error::Internal if a codec stage fails. A malformed packet never panics.