pub struct InterleavedViewMut<'a, S: Sample> { /* private fields */ }Expand description
A mutable view of interleaved audio 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 mut data = vec![0.0, 1.0, 0.0, 1.0, 0.0, 1.0];
let block = InterleavedViewMut::from_slice(&mut data, 2, 3);
block.channel(0).for_each(|&v| assert_eq!(v, 0.0));
block.channel(1).for_each(|&v| assert_eq!(v, 1.0));Implementations§
Source§impl<'a, S: Sample> InterleavedViewMut<'a, S>
impl<'a, S: Sample> InterleavedViewMut<'a, S>
Sourcepub fn from_slice(
data: &'a mut [S],
num_channels: u16,
num_frames: usize,
) -> Self
pub fn from_slice( data: &'a mut [S], num_channels: u16, num_frames: usize, ) -> Self
Creates a new InterleavedViewMut from a mutable slice of interleaved audio data.
§Parameters
data- The slice containing mutable interleaved audio samplesnum_channels- Number of audio channels in the datanum_frames- Number of audio frames in the data
§Panics
Panics if the length of data doesn’t equal num_channels * num_frames.
Sourcepub fn from_slice_limited(
data: &'a mut [S],
num_channels_visible: u16,
num_frames_visible: usize,
num_channels_available: u16,
num_frames_available: usize,
) -> Self
pub fn from_slice_limited( data: &'a mut [S], num_channels_visible: u16, num_frames_visible: usize, num_channels_available: u16, num_frames_available: usize, ) -> Self
Creates a new InterleavedViewMut from a mutable slice with limited visibility.
This function allows creating a view 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 mutable slice containing interleaved audio samplesnum_channels_visible- Number of audio channels to expose in the viewnum_frames_visible- Number of audio frames to expose in the viewnum_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 unsafe fn from_raw(
ptr: *mut S,
num_channels: u16,
num_frames: usize,
) -> Self
pub unsafe fn from_raw( ptr: *mut S, num_channels: u16, num_frames: usize, ) -> Self
Creates a new InterleavedViewMut from raw parts with.
§Safety
The caller must ensure that:
ptrpoints to valid memory containing at leastnum_channels_available * num_frames_availableelements- The memory referenced by
ptrmust be valid for the lifetime of the returnedSequentialView - The memory must not be mutated through other pointers while this view exists
Sourcepub unsafe fn from_raw_limited(
ptr: *mut S,
num_channels_visible: u16,
num_frames_visible: usize,
num_channels_available: u16,
num_frames_available: usize,
) -> Self
pub unsafe fn from_raw_limited( ptr: *mut S, num_channels_visible: u16, num_frames_visible: usize, num_channels_available: u16, num_frames_available: usize, ) -> Self
Creates a new InterleavedViewMut from raw parts with a limited amount of channels and/or frames.
§Safety
The caller must ensure that:
ptrpoints to valid memory containing at leastnum_channels_available * num_frames_availableelements- The memory referenced by
ptrmust be valid for the lifetime of the returnedSequentialView - The memory must not be mutated through other pointers while this view exists
Trait Implementations§
Source§impl<S: Sample> AudioBlock<S> for InterleavedViewMut<'_, S>
impl<S: Sample> AudioBlock<S> for InterleavedViewMut<'_, S>
Source§fn num_channels(&self) -> u16
fn num_channels(&self) -> u16
Returns the number of active audio channels.
Source§fn num_frames(&self) -> usize
fn num_frames(&self) -> usize
Returns the number of audio frames (samples per channel).
Source§fn num_channels_allocated(&self) -> u16
fn num_channels_allocated(&self) -> u16
Returns the total number of channels allocated in memory. Read more
Source§fn num_frames_allocated(&self) -> usize
fn num_frames_allocated(&self) -> usize
Returns the total number of frames allocated in memory. Read more
Source§fn sample(&self, channel: u16, frame: usize) -> S
fn sample(&self, channel: u16, frame: usize) -> S
Returns the sample value at the specified channel and frame position. Read more
Source§fn channel(&self, channel: u16) -> impl Iterator<Item = &S>
fn channel(&self, channel: u16) -> impl Iterator<Item = &S>
Returns an iterator over all samples in the specified channel. Read more
Source§fn channels(&self) -> impl Iterator<Item = impl Iterator<Item = &S> + '_> + '_
fn channels(&self) -> impl Iterator<Item = impl Iterator<Item = &S> + '_> + '_
Returns an iterator that yields iterators for each channel.
Source§fn frame(&self, frame: usize) -> impl Iterator<Item = &S>
fn frame(&self, frame: usize) -> impl Iterator<Item = &S>
Returns an iterator over all samples in the specified frame (across all channels). Read more
Source§fn frames(&self) -> impl Iterator<Item = impl Iterator<Item = &S> + '_> + '_
fn frames(&self) -> impl Iterator<Item = impl Iterator<Item = &S> + '_> + '_
Returns an iterator that yields iterators for each frame.
Source§fn frame_slice(&self, frame: usize) -> Option<&[S]>
fn frame_slice(&self, frame: usize) -> Option<&[S]>
Returns a slice of the data in case of interleaved memory layout.
Source§fn view(&self) -> impl AudioBlock<S>
fn view(&self) -> impl AudioBlock<S>
Creates a non-owning view of this audio block. Read more
Source§fn layout(&self) -> BlockLayout
fn layout(&self) -> BlockLayout
Returns the memory layout of this audio block (interleaved, sequential, or stacked).
Source§impl<S: Sample> AudioBlockMut<S> for InterleavedViewMut<'_, S>
impl<S: Sample> AudioBlockMut<S> for InterleavedViewMut<'_, S>
Source§fn set_active_num_channels(&mut self, num_channels: u16)
fn set_active_num_channels(&mut self, num_channels: u16)
Sets the active size of the audio block to the specified number of channels. Read more
Source§fn set_active_num_frames(&mut self, num_frames: usize)
fn set_active_num_frames(&mut self, num_frames: usize)
Sets the active size of the audio block to the specified number of frames. Read more
Source§fn sample_mut(&mut self, channel: u16, frame: usize) -> &mut S
fn sample_mut(&mut self, channel: u16, frame: usize) -> &mut S
Returns a mutable reference to the sample at the specified channel and frame position. Read more
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>
Returns a mutable iterator over all samples in the specified channel. Read more
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> + '_> + '_
Returns a mutable iterator that yields mutable iterators for each channel.
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>
Returns a mutable iterator over all samples in the specified frame (across all channels). Read more
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> + '_> + '_
Returns a mutable iterator that yields mutable iterators for each frame.
Source§fn frame_slice_mut(&mut self, frame: usize) -> Option<&mut [S]>
fn frame_slice_mut(&mut self, frame: usize) -> Option<&mut [S]>
Returns a slice of the data in case of interleaved memory layout.
Source§fn view_mut(&mut self) -> impl AudioBlockMut<S>
fn view_mut(&mut self) -> impl AudioBlockMut<S>
Creates a non-owning mutable view of this audio block. Read more
Source§fn raw_data_mut(&mut self, _: Option<u16>) -> &mut [S]
fn raw_data_mut(&mut self, _: Option<u16>) -> &mut [S]
Provides direct mutable access to the underlying memory as a slice. Read more
Auto Trait Implementations§
impl<'a, S> Freeze for InterleavedViewMut<'a, S>
impl<'a, S> RefUnwindSafe for InterleavedViewMut<'a, S>where
S: RefUnwindSafe,
impl<'a, S> Send for InterleavedViewMut<'a, S>where
S: Send,
impl<'a, S> Sync for InterleavedViewMut<'a, S>where
S: Sync,
impl<'a, S> Unpin for InterleavedViewMut<'a, S>
impl<'a, S> !UnwindSafe for InterleavedViewMut<'a, S>
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
Mutably borrows from an owned value. Read more
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>)
Copy will panic if blocks don’t have the exact same size
Source§fn copy_from_block_resize(&mut self, block: &impl AudioBlock<S>)
fn copy_from_block_resize(&mut self, block: &impl AudioBlock<S>)
Destination block will take over the size from source block.
Panics if destination block has not enough memory allocated to grow.
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))
Gives access to all samples in the block.
This is faster than
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.Source§fn enumerate(&mut self, f: impl FnMut(u16, usize, &mut S))
fn enumerate(&mut self, f: impl FnMut(u16, usize, &mut S))
Gives access to all samples in the block while supplying the information
about which channel and frame number the sample is stored in.