pub struct Decoder { /* private fields */ }Expand description
OPUS Decoder
Implementations§
Source§impl Decoder
impl Decoder
Sourcepub fn new(channels: Channels, rate: SampleRate) -> Result<Self, ErrorCode>
pub fn new(channels: Channels, rate: SampleRate) -> Result<Self, ErrorCode>
Creates new decoder instance
Sourcepub fn channels(&self) -> Channels
pub fn channels(&self) -> Channels
Returns channels number
When decoding, it is used to determine frame size as output.len() / channels
Sourcepub fn decode_to(
&mut self,
input: &[u8],
output: &mut [MaybeUninit<u16>],
decode_fec: bool,
) -> Result<usize, ErrorCode>
pub fn decode_to( &mut self, input: &[u8], output: &mut [MaybeUninit<u16>], decode_fec: bool, ) -> Result<usize, ErrorCode>
Decodes input packet, returning number of decoded samples.
If more than 1 channel is configured, then input must be interleaved.
Output size must correspond to sampling rate. For example, at 48 kHz allowed frame sizes are 120, 240, 480, 960, 1920, and 2880.
Maximum packet duration is 120ms therefore maximum frame size must be
frame_bytes_size(SampleRate::Hz48000, Channels::Stereo, 120)
When input size is 0, libopus shall treat it as packet loss, in which case output size must
match expected output of next packet to know how much frames is skipped
When decode_fec is true, requests that any in-band forward error correction data be decoded.
If no such data is available, the frame is decoded as if it were lost.
Sourcepub fn decode_to_slice(
&mut self,
input: &[u8],
output: &mut [u16],
decode_fec: bool,
) -> Result<usize, ErrorCode>
pub fn decode_to_slice( &mut self, input: &[u8], output: &mut [u16], decode_fec: bool, ) -> Result<usize, ErrorCode>
Decodes input packet, returning number of decoded samples.
Refer to decode_to for details
Sourcepub fn decode_to_vec(
&mut self,
input: &[u8],
output: &mut Vec<u16>,
decode_len: usize,
decode_fec: bool,
) -> Result<usize, ErrorCode>
pub fn decode_to_vec( &mut self, input: &[u8], output: &mut Vec<u16>, decode_len: usize, decode_fec: bool, ) -> Result<usize, ErrorCode>
Decodes input packet, returning number of decoded samples.
Vector will be written into spare capacity, modifying its length on success.
decode_len is used to reserve additional memory and will be passed exactly with this size to decode_to
Refer to decode_to for details
Sourcepub fn decode_float_to(
&mut self,
input: &[u8],
output: &mut [MaybeUninit<f32>],
decode_fec: bool,
) -> Result<usize, ErrorCode>
pub fn decode_float_to( &mut self, input: &[u8], output: &mut [MaybeUninit<f32>], decode_fec: bool, ) -> Result<usize, ErrorCode>
Decodes input packet, returning number of decoded samples.
If more than 1 channel is configured, then input must be interleaved.
Output size must correspond to sampling rate. For example, at 48 kHz allowed frame sizes are 120, 240, 480, 960, 1920, and 2880.
Maximum packet duration is 120ms therefore maximum frame size must be
frame_bytes_size(SampleRate::Hz48000, Channels::Stereo, 120)
When input size is 0, libopus shall treat it as packet loss, in which case output size must
match expected output of next packet to know how much frames is skipped
When decode_fec is true, requests that any in-band forward error correction data be decoded.
If no such data is available, the frame is decoded as if it were lost.
Sourcepub fn decode_float_to_slice(
&mut self,
input: &[u8],
output: &mut [f32],
decode_fec: bool,
) -> Result<usize, ErrorCode>
pub fn decode_float_to_slice( &mut self, input: &[u8], output: &mut [f32], decode_fec: bool, ) -> Result<usize, ErrorCode>
Decodes input packet, returning number of decoded samples.
Refer to decode_to for details
Sourcepub fn decode_float_to_vec(
&mut self,
input: &[u8],
output: &mut Vec<f32>,
decode_len: usize,
decode_fec: bool,
) -> Result<usize, ErrorCode>
pub fn decode_float_to_vec( &mut self, input: &[u8], output: &mut Vec<f32>, decode_len: usize, decode_fec: bool, ) -> Result<usize, ErrorCode>
Decodes input packet, returning number of decoded samples.
Vector will be written into spare capacity, modifying its length on success.
decode_len is used to reserve additional memory and will be passed exactly with this size to decode_to
Refer to decode_to for details
Sourcepub fn get_nb_samples(&self, input: &[u8]) -> Result<usize, ErrorCode>
pub fn get_nb_samples(&self, input: &[u8]) -> Result<usize, ErrorCode>
Gets the number of samples of an Opus packet.
Sourcepub fn get_pitch(&mut self) -> Result<Option<NonZeroU32>, ErrorCode>
pub fn get_pitch(&mut self) -> Result<Option<NonZeroU32>, ErrorCode>
Gets the pitch of the last decoded frame, if available.
This can be used for any post-processing algorithm requiring the use of pitch, e.g. time stretching/shortening. If the last frame was not voiced, or if the pitch was not coded in the frame, then zero is returned.
Sourcepub fn get_last_packet_duration(&mut self) -> Result<u32, ErrorCode>
pub fn get_last_packet_duration(&mut self) -> Result<u32, ErrorCode>
Gets the duration (in samples) of the last packet successfully decoded or concealed.
Sourcepub fn set_gain(&mut self, value: i32) -> Result<(), ErrorCode>
pub fn set_gain(&mut self, value: i32) -> Result<(), ErrorCode>
Configures decoder gain adjustment.
Scales the decoded output by a factor specified in Q8 dB units.
This has a maximum range of -32768 to 32767 inclusive, and returns BadArg otherwise.
The default is zero indicating no adjustment.
This setting survives decoder reset.
Formula:
gain = pow(10, x/(20.0*256))
Sourcepub fn set_complexity(&mut self, value: u8) -> Result<(), ErrorCode>
pub fn set_complexity(&mut self, value: u8) -> Result<(), ErrorCode>
Configures the decoder’s computational complexity.
The supported range is 0-10 inclusive with 10 representing the highest complexity. Values of 5 or above will use deep packet loss concealment.
Sourcepub fn get_complexity(&mut self) -> Result<u8, ErrorCode>
pub fn get_complexity(&mut self) -> Result<u8, ErrorCode>
Gets the decoder’s complexity configuration.
Sourcepub fn get_bandwidth(&mut self) -> Result<Bandwidth, ErrorCode>
pub fn get_bandwidth(&mut self) -> Result<Bandwidth, ErrorCode>
Gets the decoder’s last bandpass
Sourcepub fn get_sample_rate(&mut self) -> Result<SampleRate, ErrorCode>
pub fn get_sample_rate(&mut self) -> Result<SampleRate, ErrorCode>
Gets configured sample rate of this instance
Sourcepub fn get_phase_inversion_disabled(&mut self) -> Result<bool, ErrorCode>
pub fn get_phase_inversion_disabled(&mut self) -> Result<bool, ErrorCode>
Gets the decoder’s configured phase inversion status.
Sourcepub fn set_phase_inversion_disabled(
&mut self,
value: bool,
) -> Result<(), ErrorCode>
pub fn set_phase_inversion_disabled( &mut self, value: bool, ) -> Result<(), ErrorCode>
Configures phase inversion.
If set to true, disables the use of phase inversion for intensity stereo, improving the quality
of mono downmixes, but slightly reducing normal stereo quality.
Disabling phase inversion in the decoder does not comply with RFC 6716, although it does not cause any interoperability issue and is expected to become part of the Opus standard once RFC 6716 is updated by draft-ietf-codec-opus-update.