pub struct Stacked<S: Sample> { /* private fields */ }Expand description
A stacked / seperate-channel audio block that owns its data.
- Layout:
[[ch0, ch0, ch0], [ch1, ch1, ch1]] - Interpretation: Each channel has its own separate buffer or array.
- Terminology: Also described as “planar” or “channels first” though more specifically it’s channel-isolated buffers.
- Usage: Very common in real-time DSP, as it simplifies memory access and can improve SIMD/vectorization efficiency.
§Example
use audio_blocks::*;
let block = Stacked::new(2, 3);
let mut block = Stacked::from_block(&block);
block.channel_mut(0).for_each(|v| *v = 0.0);
block.channel_mut(1).for_each(|v| *v = 1.0);
assert_eq!(block.raw_data(Some(0)), &[0.0, 0.0, 0.0]);
assert_eq!(block.raw_data(Some(1)), &[1.0, 1.0, 1.0]);Implementations§
Source§impl<S: Sample> Stacked<S>
impl<S: Sample> Stacked<S>
Sourcepub fn new(num_channels: u16, num_frames: usize) -> Self
pub fn new(num_channels: u16, num_frames: usize) -> Self
Creates a new Stacked audio block with the specified dimensions.
Allocates memory for a new stacked audio block with exactly the specified number of channels and frames. The block is initialized with the default value for the sample type.
Do not use in real-time processes!
§Arguments
num_channels- The number of audio channelsnum_frames- The number of frames per channel
§Panics
Panics if the multiplication of num_channels and num_frames would overflow a usize.
Sourcepub fn from_block(block: &impl AudioBlock<S>) -> Self
pub fn from_block(block: &impl AudioBlock<S>) -> Self
Creates a new Stacked audio block by copying data from another AudioBlock.
Converts any AudioBlock implementation to a stacked format by iterating
through each channel of the source block and copying its samples. The new block
will have the same dimensions as the source block.
§Warning
This function allocates memory and should not be used in real-time audio processing contexts.
§Arguments
block- The source audio block to copy data from
Trait Implementations§
Source§impl<S: Sample> AudioBlock<S> for Stacked<S>
impl<S: Sample> AudioBlock<S> for Stacked<S>
Source§fn num_channels(&self) -> u16
fn num_channels(&self) -> u16
Source§fn num_frames(&self) -> usize
fn num_frames(&self) -> usize
Source§fn num_channels_allocated(&self) -> u16
fn num_channels_allocated(&self) -> u16
Source§fn num_frames_allocated(&self) -> usize
fn num_frames_allocated(&self) -> usize
Source§fn sample(&self, channel: u16, frame: usize) -> S
fn sample(&self, channel: u16, frame: usize) -> S
Source§fn channel(&self, channel: u16) -> impl Iterator<Item = &S>
fn channel(&self, channel: u16) -> impl Iterator<Item = &S>
Source§fn channels(&self) -> impl Iterator<Item = impl Iterator<Item = &S> + '_> + '_
fn channels(&self) -> impl Iterator<Item = impl Iterator<Item = &S> + '_> + '_
Source§fn channel_slice(&self, channel: u16) -> Option<&[S]>
fn channel_slice(&self, channel: u16) -> Option<&[S]>
Source§fn frame(&self, frame: usize) -> impl Iterator<Item = &S>
fn frame(&self, frame: usize) -> impl Iterator<Item = &S>
Source§fn frames(&self) -> impl Iterator<Item = impl Iterator<Item = &S> + '_> + '_
fn frames(&self) -> impl Iterator<Item = impl Iterator<Item = &S> + '_> + '_
Source§fn view(&self) -> impl AudioBlock<S>
fn view(&self) -> impl AudioBlock<S>
Source§fn layout(&self) -> BlockLayout
fn layout(&self) -> BlockLayout
Source§impl<S: Sample> AudioBlockMut<S> for Stacked<S>
impl<S: Sample> AudioBlockMut<S> for Stacked<S>
Source§fn set_active_num_channels(&mut self, num_channels: u16)
fn set_active_num_channels(&mut self, num_channels: u16)
Source§fn set_active_num_frames(&mut self, num_frames: usize)
fn set_active_num_frames(&mut self, num_frames: usize)
Source§fn sample_mut(&mut self, channel: u16, frame: usize) -> &mut S
fn sample_mut(&mut self, channel: u16, frame: usize) -> &mut S
Source§fn channel_mut(&mut self, channel: u16) -> impl Iterator<Item = &mut S>
fn channel_mut(&mut self, channel: u16) -> impl Iterator<Item = &mut S>
Source§fn channels_mut(
&mut self,
) -> impl Iterator<Item = impl Iterator<Item = &mut S> + '_> + '_
fn channels_mut( &mut self, ) -> impl Iterator<Item = impl Iterator<Item = &mut S> + '_> + '_
Source§fn channel_slice_mut(&mut self, channel: u16) -> Option<&mut [S]>
fn channel_slice_mut(&mut self, channel: u16) -> Option<&mut [S]>
Source§fn frame_mut(&mut self, frame: usize) -> impl Iterator<Item = &mut S>
fn frame_mut(&mut self, frame: usize) -> impl Iterator<Item = &mut S>
Source§fn frames_mut(
&mut self,
) -> impl Iterator<Item = impl Iterator<Item = &mut S> + '_> + '_
fn frames_mut( &mut self, ) -> impl Iterator<Item = impl Iterator<Item = &mut S> + '_> + '_
Source§fn view_mut(&mut self) -> impl AudioBlockMut<S>
fn view_mut(&mut self) -> impl AudioBlockMut<S>
Source§fn raw_data_mut(&mut self, stacked_ch: Option<u16>) -> &mut [S]
fn raw_data_mut(&mut self, stacked_ch: Option<u16>) -> &mut [S]
Auto Trait Implementations§
impl<S> Freeze for Stacked<S>
impl<S> RefUnwindSafe for Stacked<S>where
S: RefUnwindSafe,
impl<S> Send for Stacked<S>where
S: Send,
impl<S> Sync for Stacked<S>where
S: Sync,
impl<S> Unpin for Stacked<S>
impl<S> UnwindSafe for Stacked<S>where
S: UnwindSafe,
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<S, B> Ops<S> for Bwhere
S: Sample,
B: AudioBlockMut<S>,
impl<S, B> Ops<S> for Bwhere
S: Sample,
B: AudioBlockMut<S>,
Source§fn copy_from_block(&mut self, block: &impl AudioBlock<S>)
fn copy_from_block(&mut self, block: &impl AudioBlock<S>)
Source§fn copy_from_block_resize(&mut self, block: &impl AudioBlock<S>)
fn copy_from_block_resize(&mut self, block: &impl AudioBlock<S>)
Source§fn for_each_including_non_visible(&mut self, f: impl FnMut(&mut S))
fn for_each_including_non_visible(&mut self, f: impl FnMut(&mut S))
for_each by not checking bounds of the block.
It can be used if your algorithm does not change if wrong samples are accessed.
For example this is the case for gain, clear, etc.