pub struct Decoder { /* private fields */ }Expand description
Opus decoder.
Implementations§
Source§impl Decoder
impl Decoder
Sourcepub fn new(freq: SamplingRate, channels: Channels) -> Result<Self, DecoderError>
pub fn new(freq: SamplingRate, channels: Channels) -> Result<Self, DecoderError>
Construct decoder from requested sampling rate and number of channels.
See also opus_decoder_get_size and opus_decoder_init.
Sourcepub fn get_nb_samples_total(&self, data: &[u8]) -> Result<usize, DecoderError>
pub fn get_nb_samples_total(&self, data: &[u8]) -> Result<usize, DecoderError>
Return the number of samples in the opus data multiplied by the number of channels.
This value can be used for output buffer size for decoding when total number of samples in frame is expected.
See also Decoder::get_nb_samples.
Sourcepub fn get_nb_samples(&self, data: &[u8]) -> Result<usize, DecoderError>
pub fn get_nb_samples(&self, data: &[u8]) -> Result<usize, DecoderError>
Return the number of samples in the opus data.
This value can be used for audio output when frame size is expected, i.e. the number of samples per channel.
See also opus_decoder_get_nb_samples.
Sourcepub fn decode<'output>(
&mut self,
data: &[u8],
output: &'output mut [i16],
) -> Result<&'output [i16], DecoderError>
pub fn decode<'output>( &mut self, data: &[u8], output: &'output mut [i16], ) -> Result<&'output [i16], DecoderError>
Decode opus packet from data into output buffer.
Returns decoded frame stored on output buffer. Its length is total number of samples in a frame.
let mut decoder = Decoder::new(SamplingRate::F24k, Channels::Mono).unwrap();
let mut output = Vec::new();
output.resize(decoder.get_nb_samples_total(data).unwrap(), 0);
let output = decoder.decode(data, &mut output).unwrap();
println!("Got {} samples of data in output", output.len());See also opus_decode.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Decoder
impl RefUnwindSafe for Decoder
impl Send for Decoder
impl Sync for Decoder
impl Unpin for Decoder
impl UnwindSafe for Decoder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
Source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Casts the value.
Source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
Source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Casts the value.
Source§impl<T> OverflowingAs for T
impl<T> OverflowingAs for T
Source§fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
Casts the value.
Source§impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
Source§fn overflowing_cast_from(src: Src) -> (Dst, bool)
fn overflowing_cast_from(src: Src) -> (Dst, bool)
Casts the value.
Source§impl<T> SaturatingAs for T
impl<T> SaturatingAs for T
Source§fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
Casts the value.
Source§impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
Source§fn saturating_cast_from(src: Src) -> Dst
fn saturating_cast_from(src: Src) -> Dst
Casts the value.
Source§impl<T> UnwrappedAs for T
impl<T> UnwrappedAs for T
Source§fn unwrapped_as<Dst>(self) -> Dstwhere
T: UnwrappedCast<Dst>,
fn unwrapped_as<Dst>(self) -> Dstwhere
T: UnwrappedCast<Dst>,
Casts the value.
Source§impl<Src, Dst> UnwrappedCastFrom<Src> for Dstwhere
Src: UnwrappedCast<Dst>,
impl<Src, Dst> UnwrappedCastFrom<Src> for Dstwhere
Src: UnwrappedCast<Dst>,
Source§fn unwrapped_cast_from(src: Src) -> Dst
fn unwrapped_cast_from(src: Src) -> Dst
Casts the value.
Source§impl<T> WrappingAs for T
impl<T> WrappingAs for T
Source§fn wrapping_as<Dst>(self) -> Dstwhere
T: WrappingCast<Dst>,
fn wrapping_as<Dst>(self) -> Dstwhere
T: WrappingCast<Dst>,
Casts the value.
Source§impl<Src, Dst> WrappingCastFrom<Src> for Dstwhere
Src: WrappingCast<Dst>,
impl<Src, Dst> WrappingCastFrom<Src> for Dstwhere
Src: WrappingCast<Dst>,
Source§fn wrapping_cast_from(src: Src) -> Dst
fn wrapping_cast_from(src: Src) -> Dst
Casts the value.