pub struct AudioBlockSequentialView<'a, S>where
S: Sample,{ /* private fields */ }Expand description
A read-only view of sequential audio data.
- Layout:
[ch0, ch0, ch0, ch1, ch1, ch1] - Interpretation: All samples from
ch0are stored first, followed by all fromch1, etc. - Terminology: Described “channels first” in the sense that all data for one channel appears before any data for the next.
- Usage: Used in DSP pipelines where per-channel processing is easier and more efficient.
§Example
use audio_blocks::*;
let data = vec![0.0, 0.0, 0.0, 1.0, 1.0, 1.0];
let block = AudioBlockSequentialView::from_slice(&data, 2, 3);
assert_eq!(block.channel(0), &[0.0, 0.0, 0.0]);
assert_eq!(block.channel(1), &[1.0, 1.0, 1.0]);Implementations§
Source§impl<'a, S> AudioBlockSequentialView<'a, S>where
S: Sample,
impl<'a, S> AudioBlockSequentialView<'a, S>where
S: Sample,
Sourcepub fn from_slice(
data: &'a [S],
num_channels: u16,
num_frames: usize,
) -> AudioBlockSequentialView<'a, S>
pub fn from_slice( data: &'a [S], num_channels: u16, num_frames: usize, ) -> AudioBlockSequentialView<'a, S>
Creates a new audio block from a slice of sequential audio data.
§Parameters
data- The slice containing sequential 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 [S],
num_channels_visible: u16,
num_frames_visible: usize,
num_channels_allocated: u16,
num_frames_allocated: usize,
) -> AudioBlockSequentialView<'a, S>
pub fn from_slice_limited( data: &'a [S], num_channels_visible: u16, num_frames_visible: usize, num_channels_allocated: u16, num_frames_allocated: usize, ) -> AudioBlockSequentialView<'a, S>
Creates a new 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 sequential 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,
) -> AudioBlockSequentialView<'a, S>
pub unsafe fn from_ptr( ptr: *const S, num_channels: u16, num_frames: usize, ) -> AudioBlockSequentialView<'a, S>
Creates a new audio block from a raw pointers.
§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_ptr_limited(
ptr: *const S,
num_channels_visible: u16,
num_frames_visible: usize,
num_channels_allocated: u16,
num_frames_allocated: usize,
) -> AudioBlockSequentialView<'a, S>
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, ) -> AudioBlockSequentialView<'a, S>
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_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 fn channels(&self) -> impl Iterator<Item = &[S]>
pub fn channels(&self) -> impl Iterator<Item = &[S]>
Returns an iterator over all channels in the block.
Each channel 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 active range.