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: u8The number of channels in this block
repeat: boolThis 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
impl Block
Sourcepub fn empty() -> Self
pub fn empty() -> Self
Empty block with no channels, for pushing new channels to.
Must be used with push_chan
pub fn for_channels_explicit(channels: u8) -> Self
Sourcepub fn as_mut_byte_slice(&mut self) -> &mut [u8] ⓘ
pub fn as_mut_byte_slice(&mut self) -> &mut [u8] ⓘ
This provides the entire buffer as a mutable slice of u8
pub fn for_vec(buffer: Vec<f32>) -> Self
Sourcepub fn sum(self, other: Self) -> Self
pub fn sum(self, other: Self) -> Self
Zero-gain sum with another buffer
Used after mixing multiple inputs to a single port
Sourcepub fn explicit_silence(&mut self)
pub fn explicit_silence(&mut self)
If this is in “silence” mode without a buffer, allocate a silent buffer
Sourcepub fn data_mut(&mut self) -> &mut [f32]
pub fn data_mut(&mut self) -> &mut [f32]
This provides the entire buffer as a mutable slice of f32
pub fn explicit_repeat(&mut self)
pub fn data_chan_mut(&mut self, chan: u8) -> &mut [f32]
pub fn data_chan(&self, chan: u8) -> &[f32]
pub fn take(&mut self) -> Block
pub fn chan_count(&self) -> u8
pub fn iter(&mut self) -> FrameIterator<'_>
pub fn is_silence(&self) -> bool
pub fn is_repeat(&self) -> bool
pub fn data_chan_frame(&self, frame: usize, chan: u8) -> f32
pub fn push_chan(&mut self, data: &[f32])
Sourcepub fn mix(&mut self, channels: u8, interpretation: ChannelInterpretation)
pub fn mix(&mut self, channels: u8, interpretation: ChannelInterpretation)
upmix/downmix the channels if necessary
Currently only supports upmixing from 1
Sourcepub fn resize_silence(&mut self, channels: u8)
pub fn resize_silence(&mut self, channels: u8)
Resize to add or remove channels, fill extra channels with silence
pub fn interleave(&mut self) -> Vec<f32>
pub fn is_empty(&self) -> bool
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Block
impl<'de> Deserialize<'de> for Block
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for Block
impl RefUnwindSafe for Block
impl Send for Block
impl Sync for Block
impl Unpin for Block
impl UnsafeUnpin for Block
impl UnwindSafe for Block
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more