claxon::frame

Struct Block

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

A block of raw audio samples.

Implementations§

Source§

impl Block

Source

pub fn empty() -> Block

Returns a block with 0 channels and 0 samples.

Source

pub fn time(&self) -> u64

Returns the inter-channel sample number of the first sample in the block.

The time is independent of the number of channels. To get the start time of the block in seconds, divide this number by the sample rate in the streaminfo.

Source

pub fn len(&self) -> u32

Returns the total number of samples in this block.

Samples in different channels are counted as distinct samples.

Source

pub fn duration(&self) -> u32

Returns the number of inter-channel samples in the block.

The duration is independent of the number of channels. The returned value is also referred to as the block size. To get the duration of the block in seconds, divide this number by the sample rate in the streaminfo.

Source

pub fn channels(&self) -> u32

Returns the number of channels in the block.

Source

pub fn channel(&self, ch: u32) -> &[i32]

Returns the (zero-based) ch-th channel as a slice.

§Panics

Panics if ch >= channels().

Source

pub fn sample(&self, ch: u32, sample: u32) -> i32

Returns a sample in this block.

The value returned is for the zero-based ch-th channel of the inter-channel sample with index sample in this block (so this is not the global sample number).

§Panics

Panics if ch >= channels() or if sample >= len() for the last channel.

Source

pub fn into_buffer(self) -> Vec<i32>

Returns the underlying buffer that stores the samples in this block.

This allows the buffer to be reused to decode the next frame. The capacity of the buffer may be bigger than len() times channels().

Source

pub fn stereo_samples<'a>(&'a self) -> StereoSamples<'a>

Returns an iterator that produces left and right channel samples.

This iterator can be more efficient than requesting a sample directly, because it avoids a bounds check.

§Panics

Panics if the number of channels in the block is not 2.

Auto Trait Implementations§

§

impl Freeze for Block

§

impl RefUnwindSafe for Block

§

impl Send for Block

§

impl Sync for Block

§

impl Unpin for Block

§

impl UnwindSafe for Block

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

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.