Skip to main content

OpusMSDecoder

Struct OpusMSDecoder 

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

Multistream decoder: decode each stream and remux to the output channels.

Implementations§

Source§

impl OpusMSDecoder

Source

pub fn new( sample_rate: i32, channels: usize, mapping_family: u8, ) -> Result<Self>

Create a surround decoder for channels channels.

mapping_family selects the layout, as in OpusMSEncoder::new; for a stream read from a file it is the one OpusHead::mapping_family carries.

Source

pub fn decode( &mut self, packet: &[u8], frame_size: usize, output: &mut [f32], ) -> Result<usize>

Decode a multistream packet into interleaved output (nb_channels per sample). Returns the number of samples per channel. Decode one multistream packet into interleaved float PCM.

As with OpusDecoder::decode, the output is not bounded by ±1.

Source

pub fn decode_s16( &mut self, packet: &[u8], frame_size: usize, output: &mut [i16], ) -> Result<usize>

Decode one multistream packet into interleaved 16-bit PCM.

Each stream is soft-clipped on its own before the channels are remuxed, which is where libopus applies it too (opus_multistream_decode_native hands soft_clip to each stream’s decoder). Clipping the remuxed result instead would let one stream’s peak bend another’s audio.

Source

pub fn layout(&self) -> &ChannelLayout

The channel layout this decoder produces.

Source

pub fn nb_streams(&self) -> usize

Opus streams this decoder expects in each packet.

Source

pub fn channels(&self) -> usize

The number of output channels this decoder produces.

Source

pub fn sample_rate(&self) -> i32

The sample rate this decoder was created with, in Hz.

Source

pub fn streams_mut(&mut self) -> &mut [OpusDecoder]

The per-stream decoders, so every OpusDecoder setting is reachable.

The counterpart of OpusMSEncoder::streams_mut, and the only route to gain_q8 — which is not a nicety. RFC 7845 §5.1 says a player SHOULD apply the gain a file declares, and it says nothing about mapping family, so a surround stream carrying a non-zero OpusHead::output_gain_q8 plays at the wrong level with no other symptom. A multistream decoder is N ordinary decoders and the gain belongs on every one of them:

let mut dec = OpusMSDecoder::new(48_000, 6, head.mapping_family)?;
for d in dec.streams_mut() {
    d.gain_q8 = head.output_gain_q8 as i32;
}

For mono and stereo, OpusHead::decoder does this for you and there is nothing to remember.

Source

pub fn streams(&self) -> &[OpusDecoder]

The per-stream decoders, for reading. See streams_mut to change their settings.

final_range per stream is what a conformance check compares against a reference decoder’s.

Source

pub fn reset_state(&mut self) -> Result<()>

Discard every stream’s coding state, as OpusDecoder::reset_state does for one.

Trait Implementations§

Source§

impl Debug for OpusMSDecoder

Shows the layout, not the decoders’ coding state.

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.