pub struct InterleavedView<'a, S: Sample> { /* private fields */ }Expand description
A read-only 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 data = vec![0.0, 1.0, 0.0, 1.0, 0.0, 1.0];
let block = InterleavedView::from_slice(&data, 2);
assert_eq!(block.frame(0), &[0.0, 1.0]);
assert_eq!(block.frame(1), &[0.0, 1.0]);
assert_eq!(block.frame(2), &[0.0, 1.0]);Implementations§
Source§impl<'a, S: Sample> InterleavedView<'a, S>
impl<'a, S: Sample> InterleavedView<'a, S>
Sourcepub fn from_slice(data: &'a [S], num_channels: u16) -> Self
pub fn from_slice(data: &'a [S], num_channels: u16) -> Self
Sourcepub fn from_slice_limited(
data: &'a [S],
num_channels_visible: u16,
num_frames_visible: usize,
num_channels_allocated: u16,
num_frames_allocated: usize,
) -> Self
pub fn from_slice_limited( data: &'a [S], num_channels_visible: u16, num_frames_visible: usize, num_channels_allocated: u16, num_frames_allocated: usize, ) -> Self
Creates a new interleaved audio block from a 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 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_ptr(
ptr: *const S,
num_channels: u16,
num_frames: usize,
) -> Self
pub unsafe fn from_ptr( ptr: *const S, num_channels: u16, num_frames: usize, ) -> Self
Creates a new interleaved audio block from a pointer.
§Safety
The caller must ensure that:
ptrpoints to valid memory containing at leastnum_channels_allocated * num_frames_allocatedelements- 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_ptr_limited(
ptr: *const S,
num_channels_visible: u16,
num_frames_visible: usize,
num_channels_allocated: u16,
num_frames_allocated: usize,
) -> Self
pub unsafe fn from_ptr_limited( ptr: *const S, num_channels_visible: u16, num_frames_visible: usize, num_channels_allocated: u16, num_frames_allocated: usize, ) -> Self
Creates a new audio block from a pointer with a limited amount of channels and/or frames.
§Safety
The caller must ensure that:
ptrpoints to valid memory containing at leastnum_channels_allocated * num_frames_allocatedelements- 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 fn frames(&self) -> impl ExactSizeIterator<Item = &[S]>
pub fn frames(&self) -> impl ExactSizeIterator<Item = &[S]>
Returns an iterator over all frames in the block.
Each frame is represented as a 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.
pub fn view(&self) -> InterleavedView<'_, S>
Trait Implementations§
Source§impl<S: Sample> AudioBlock<S> for InterleavedView<'_, S>
impl<S: Sample> AudioBlock<S> for InterleavedView<'_, 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 ExactSizeIterator<Item = &S>
fn channel_iter(&self, channel: u16) -> impl ExactSizeIterator<Item = &S>
Source§fn channels_iter(
&self,
) -> impl ExactSizeIterator<Item = impl ExactSizeIterator<Item = &S>>
fn channels_iter( &self, ) -> impl ExactSizeIterator<Item = impl ExactSizeIterator<Item = &S>>
Source§fn frame_iter(&self, frame: usize) -> impl ExactSizeIterator<Item = &S>
fn frame_iter(&self, frame: usize) -> impl ExactSizeIterator<Item = &S>
Source§fn frames_iter(
&self,
) -> impl ExactSizeIterator<Item = impl ExactSizeIterator<Item = &S>>
fn frames_iter( &self, ) -> impl ExactSizeIterator<Item = impl ExactSizeIterator<Item = &S>>
Source§fn as_view(&self) -> impl AudioBlock<S>
fn as_view(&self) -> impl AudioBlock<S>
Source§fn as_interleaved_view(&self) -> Option<InterleavedView<'_, S>>
fn as_interleaved_view(&self) -> Option<InterleavedView<'_, S>>
Source§fn as_planar_view(&self) -> Option<PlanarView<'_, S, Self::PlanarView>>
fn as_planar_view(&self) -> Option<PlanarView<'_, S, Self::PlanarView>>
Source§fn as_sequential_view(&self) -> Option<SequentialView<'_, S>>
fn as_sequential_view(&self) -> Option<SequentialView<'_, S>>
Auto Trait Implementations§
impl<'a, S> Freeze for InterleavedView<'a, S>
impl<'a, S> RefUnwindSafe for InterleavedView<'a, S>where
S: RefUnwindSafe,
impl<'a, S> Send for InterleavedView<'a, S>where
S: Sync,
impl<'a, S> Sync for InterleavedView<'a, S>where
S: Sync,
impl<'a, S> Unpin for InterleavedView<'a, S>
impl<'a, S> UnsafeUnpin for InterleavedView<'a, S>
impl<'a, S> UnwindSafe for InterleavedView<'a, S>where
S: RefUnwindSafe,
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 MonoViewMut<'_, S>) -> Option<usize>
fn mix_to_mono(&self, dest: &mut MonoViewMut<'_, S>) -> Option<usize>
min(src_frames, dst_frames) frames.
Returns None if all frames were processed (exact match),
or Some(frames_processed) if a partial mix occurred.Source§fn mix_to_mono_exact(&self, dest: &mut MonoViewMut<'_, S>)
fn mix_to_mono_exact(&self, dest: &mut MonoViewMut<'_, S>)
Source§fn copy_channel_to_mono(
&self,
dest: &mut MonoViewMut<'_, S>,
channel: u16,
) -> Option<usize>
fn copy_channel_to_mono( &self, dest: &mut MonoViewMut<'_, S>, channel: u16, ) -> Option<usize>
min(src_frames, dst_frames) frames.
Returns None if all frames were copied (exact match),
or Some(frames_copied) if a partial copy occurred.