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