Struct servo_media_audio::block::Block

source ·
pub struct Block {
    channels: u8,
    repeat: bool,
    buffer: Vec<f32>,
}
Expand description

We render audio in blocks of size FRAMES_PER_BLOCK

A single block may contain multiple channels

Fields§

§channels: u8

The number of channels in this block

§repeat: bool

This is an optimization which means that the buffer is representing multiple channels with the same content at once. Happens when audio is upmixed or when a source like an oscillator node has multiple channel outputs

§buffer: Vec<f32>

If this vector is empty, it is a shorthand for “silence” It is possible to obtain an explicitly silent buffer via .explicit_silence()

This must be of length channels * FRAMES_PER_BLOCK, unless repeat is true, in which case it will be of length FRAMES_PER_BLOCK

Implementations§

source§

impl Block

source

pub fn empty() -> Self

Empty block with no channels, for pushing new channels to.

Must be used with push_chan

source

pub fn for_channels_explicit(channels: u8) -> Self

source

pub fn as_mut_byte_slice(&mut self) -> &mut [u8]

This provides the entire buffer as a mutable slice of u8

source

pub fn for_vec(buffer: Vec<f32>) -> Self

source

pub fn sum(self, other: Self) -> Self

Zero-gain sum with another buffer

Used after mixing multiple inputs to a single port

source

pub fn explicit_silence(&mut self)

If this is in “silence” mode without a buffer, allocate a silent buffer

source

pub fn data_mut(&mut self) -> &mut [f32]

This provides the entire buffer as a mutable slice of f32

source

pub fn explicit_repeat(&mut self)

source

pub fn data_chan_mut(&mut self, chan: u8) -> &mut [f32]

source

pub fn data_chan(&self, chan: u8) -> &[f32]

source

pub fn take(&mut self) -> Block

source

pub fn chan_count(&self) -> u8

source

pub fn iter(&mut self) -> FrameIterator<'_>

source

pub fn is_silence(&self) -> bool

source

pub fn is_repeat(&self) -> bool

source

pub fn data_chan_frame(&self, frame: usize, chan: u8) -> f32

source

pub fn push_chan(&mut self, data: &[f32])

source

pub fn mix(&mut self, channels: u8, interpretation: ChannelInterpretation)

upmix/downmix the channels if necessary

Currently only supports upmixing from 1

source

pub fn resize_silence(&mut self, channels: u8)

Resize to add or remove channels, fill extra channels with silence

source

pub fn repeat(&mut self, channels: u8)

Take a single-channel block and repeat the channel

source

pub fn interleave(&mut self) -> Vec<f32>

source

pub fn is_empty(&self) -> bool

source

pub fn listener_data( &self, frame: Tick, ) -> (Vector3D<f32>, Vector3D<f32>, Vector3D<f32>)

Get the position, forward, and up vectors for a given AudioListener-produced block

Trait Implementations§

source§

impl Clone for Block

source§

fn clone(&self) -> Block

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Block

source§

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

Formats the value using the given formatter. Read more
source§

impl Default for Block

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<'de> Deserialize<'de> for Block

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl Serialize for Block

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,