pub struct AudioBlockInterleaved<S: Sample> { /* private fields */ }Expand description
An interleaved audio block that owns its data.
- Layout:
[ch0, ch1, ch0, ch1, ch0, ch1] - Interpretation: Each group of channel samples represents a frame. So, this layout stores frames one after another.
- Terminology: Described as “packed” or “frames first” because each time step is grouped and processed as a unit (a frame).
- Usage: Often used in APIs or hardware-level interfaces, where synchronized playback across channels is crucial.
§Example
use audio_blocks::*;
let block = AudioBlockInterleaved::new(2, 3);
let mut block = AudioBlockInterleaved::from_block(&block);
block.frame_mut(0).fill(0.0);
block.frame_mut(1).fill(1.0);
block.frame_mut(2).fill(2.0);
assert_eq!(block.raw_data(), &[0.0, 0.0, 1.0, 1.0, 2.0, 2.0]);Implementations§
Source§impl<S: Sample + Default> AudioBlockInterleaved<S>
impl<S: Sample + Default> AudioBlockInterleaved<S>
Sourcepub fn new(num_channels: u16, num_frames: usize) -> Self
pub fn new(num_channels: u16, num_frames: usize) -> Self
Creates a new interleaved audio block with the specified dimensions.
Allocates memory for a new interleaved 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.
Source§impl<S: Sample> AudioBlockInterleaved<S>
impl<S: Sample> AudioBlockInterleaved<S>
Sourcepub fn from_slice(data: &[S], num_channels: u16) -> Self
pub fn from_slice(data: &[S], num_channels: u16) -> Self
Sourcepub fn from_slice_limited(
data: &[S],
num_channels_visible: u16,
num_frames_visible: usize,
num_channels_allocated: u16,
num_frames_allocated: usize,
) -> Self
pub fn from_slice_limited( data: &[S], num_channels_visible: u16, num_frames_visible: usize, num_channels_allocated: u16, num_frames_allocated: usize, ) -> Self
Creates a new interleaved audio block by copying the data from a slice of interleaved audio data with limited visibility.
This function allows creating a block that exposes only a subset of the allocated channels and frames, which is useful for working with a logical section of a larger buffer.
§Parameters
data- The slice containing interleaved audio samplesnum_channels_visible- Number of audio channels to exposenum_frames_visible- Number of audio frames to exposenum_channels_allocated- Total number of channels allocated in the data buffernum_frames_allocated- Total number of frames allocated in the data buffer
§Panics
- Panics if the length of
datadoesn’t equalnum_channels_allocated * num_frames_allocated - Panics if
num_channels_visibleexceedsnum_channels_allocated - Panics if
num_frames_visibleexceedsnum_frames_allocated
Sourcepub fn from_block(block: &impl AudioBlock<S>) -> Self
pub fn from_block(block: &impl AudioBlock<S>) -> Self
Creates a new audio block by copying data from another AudioBlock.
Converts any AudioBlock implementation to an interleaved format by iterating
through each frame 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
Sourcepub fn frames(&self) -> impl Iterator<Item = &[S]>
pub fn frames(&self) -> impl Iterator<Item = &[S]>
Returns an iterator over all frames in the block.
Each frame is represented as a slice of samples.
Sourcepub fn frames_mut(&mut self) -> impl Iterator<Item = &mut [S]>
pub fn frames_mut(&mut self) -> impl Iterator<Item = &mut [S]>
Returns a mutable iterator over all frames in the block.
Each frame is represented as a mutable slice of samples.
Sourcepub fn raw_data(&self) -> &[S]
pub fn raw_data(&self) -> &[S]
Provides direct access to the underlying memory as an interleaved slice.
This function gives access to all allocated data, including any reserved capacity beyond the visible range.
Sourcepub fn raw_data_mut(&mut self) -> &mut [S]
pub fn raw_data_mut(&mut self) -> &mut [S]
Provides direct mutable access to the underlying memory as an interleaved slice.
This function gives mutable access to all allocated data, including any reserved capacity beyond the visible range.
pub fn view(&self) -> AudioBlockInterleavedView<'_, S>
pub fn view_mut(&mut self) -> AudioBlockInterleavedViewMut<'_, S>
Trait Implementations§
Source§impl<S: Sample> AudioBlock<S> for AudioBlockInterleaved<S>
impl<S: Sample> AudioBlock<S> for AudioBlockInterleaved<S>
type PlanarView = [S; 0]
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 layout(&self) -> BlockLayout
fn layout(&self) -> BlockLayout
Source§fn sample(&self, channel: u16, frame: usize) -> S
fn sample(&self, channel: u16, frame: usize) -> S
Source§fn channel_iter(&self, channel: u16) -> impl Iterator<Item = &S>
fn channel_iter(&self, channel: u16) -> impl Iterator<Item = &S>
Source§fn channels_iter(
&self,
) -> impl Iterator<Item = impl Iterator<Item = &S> + '_> + '_
fn channels_iter( &self, ) -> impl Iterator<Item = impl Iterator<Item = &S> + '_> + '_
Source§fn frame_iter(&self, frame: usize) -> impl Iterator<Item = &S>
fn frame_iter(&self, frame: usize) -> impl Iterator<Item = &S>
Source§fn frames_iter(
&self,
) -> impl Iterator<Item = impl Iterator<Item = &S> + '_> + '_
fn frames_iter( &self, ) -> impl Iterator<Item = impl Iterator<Item = &S> + '_> + '_
Source§fn as_view(&self) -> impl AudioBlock<S>
fn as_view(&self) -> impl AudioBlock<S>
Source§fn as_interleaved_view(&self) -> Option<AudioBlockInterleavedView<'_, S>>
fn as_interleaved_view(&self) -> Option<AudioBlockInterleavedView<'_, S>>
Source§fn as_planar_view(
&self,
) -> Option<AudioBlockPlanarView<'_, S, Self::PlanarView>>
fn as_planar_view( &self, ) -> Option<AudioBlockPlanarView<'_, S, Self::PlanarView>>
Source§fn as_sequential_view(&self) -> Option<AudioBlockSequentialView<'_, S>>
fn as_sequential_view(&self) -> Option<AudioBlockSequentialView<'_, S>>
Source§impl<S: Sample> AudioBlockMut<S> for AudioBlockInterleaved<S>
impl<S: Sample> AudioBlockMut<S> for AudioBlockInterleaved<S>
type PlanarViewMut = [S; 0]
Source§fn set_num_channels_visible(&mut self, num_channels: u16)
fn set_num_channels_visible(&mut self, num_channels: u16)
Source§fn set_num_frames_visible(&mut self, num_frames: usize)
fn set_num_frames_visible(&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_iter_mut(&mut self, channel: u16) -> impl Iterator<Item = &mut S>
fn channel_iter_mut(&mut self, channel: u16) -> impl Iterator<Item = &mut S>
Source§fn channels_iter_mut(
&mut self,
) -> impl Iterator<Item = impl Iterator<Item = &mut S> + '_> + '_
fn channels_iter_mut( &mut self, ) -> impl Iterator<Item = impl Iterator<Item = &mut S> + '_> + '_
Source§fn frame_iter_mut(&mut self, frame: usize) -> impl Iterator<Item = &mut S>
fn frame_iter_mut(&mut self, frame: usize) -> impl Iterator<Item = &mut S>
Source§fn frames_iter_mut(
&mut self,
) -> impl Iterator<Item = impl Iterator<Item = &mut S> + '_> + '_
fn frames_iter_mut( &mut self, ) -> impl Iterator<Item = impl Iterator<Item = &mut S> + '_> + '_
Source§fn as_view_mut(&mut self) -> impl AudioBlockMut<S>
fn as_view_mut(&mut self) -> impl AudioBlockMut<S>
Source§fn as_interleaved_view_mut(
&mut self,
) -> Option<AudioBlockInterleavedViewMut<'_, S>>
fn as_interleaved_view_mut( &mut self, ) -> Option<AudioBlockInterleavedViewMut<'_, S>>
Source§fn set_visible(&mut self, num_channels: u16, num_frames: usize)
fn set_visible(&mut self, num_channels: u16, num_frames: usize)
Source§fn as_planar_view_mut(
&mut self,
) -> Option<AudioBlockPlanarViewMut<'_, S, Self::PlanarViewMut>>
fn as_planar_view_mut( &mut self, ) -> Option<AudioBlockPlanarViewMut<'_, S, Self::PlanarViewMut>>
Source§fn as_sequential_view_mut(
&mut self,
) -> Option<AudioBlockSequentialViewMut<'_, S>>
fn as_sequential_view_mut( &mut self, ) -> Option<AudioBlockSequentialViewMut<'_, S>>
Auto Trait Implementations§
impl<S> Freeze for AudioBlockInterleaved<S>
impl<S> RefUnwindSafe for AudioBlockInterleaved<S>where
S: RefUnwindSafe,
impl<S> Send for AudioBlockInterleaved<S>where
S: Send,
impl<S> Sync for AudioBlockInterleaved<S>where
S: Sync,
impl<S> Unpin for AudioBlockInterleaved<S>
impl<S> UnwindSafe for AudioBlockInterleaved<S>where
S: UnwindSafe,
Blanket Implementations§
Source§impl<S, B> AudioBlockOps<S> for Bwhere
S: Sample,
B: AudioBlock<S>,
impl<S, B> AudioBlockOps<S> for Bwhere
S: Sample,
B: AudioBlock<S>,
Source§fn mix_to_mono(&self, dest: &mut AudioBlockMonoViewMut<'_, S>)
fn mix_to_mono(&self, dest: &mut AudioBlockMonoViewMut<'_, S>)
Source§impl<S, B> AudioBlockOpsMut<S> for Bwhere
S: Sample,
B: AudioBlockMut<S>,
impl<S, B> AudioBlockOpsMut<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>)
min(src, dst) channels and frames.
Never panics - safely handles mismatched block sizes.Source§fn copy_from_block_exact(&mut self, block: &impl AudioBlock<S>)
fn copy_from_block_exact(&mut self, block: &impl AudioBlock<S>)
Source§fn copy_mono_to_all_channels(&mut self, mono: &AudioBlockMonoView<'_, S>)
fn copy_mono_to_all_channels(&mut self, mono: &AudioBlockMonoView<'_, 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.