pub struct AudioBlockPlanarView<'a, S, V>{ /* private fields */ }Expand description
A read-only view of planar / separate-channel audio 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 data = vec![[0.0, 0.0, 0.0], [1.0, 1.0, 1.0]];
let block = AudioBlockPlanarView::from_slice(&data);
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, V> AudioBlockPlanarView<'a, S, V>
impl<'a, S, V> AudioBlockPlanarView<'a, S, V>
Sourcepub fn from_slice(data: &'a [V]) -> AudioBlockPlanarView<'a, S, V>
pub fn from_slice(data: &'a [V]) -> AudioBlockPlanarView<'a, S, V>
Sourcepub fn from_slice_limited(
data: &'a [V],
num_channels_visible: u16,
num_frames_visible: usize,
) -> AudioBlockPlanarView<'a, S, V>
pub fn from_slice_limited( data: &'a [V], num_channels_visible: u16, num_frames_visible: usize, ) -> AudioBlockPlanarView<'a, S, V>
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 planar audio samples (one slice per channel)num_channels_visible- Number of audio channels to expose in the viewnum_frames_visible- Number of audio frames to expose in the view
§Panics
- Panics if
num_channels_visibleexceeds the number of channels indata - Panics if
num_frames_visibleexceeds the length of any channel buffer - Panics if channel slices have different lengths
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) -> &[V]
pub fn raw_data(&self) -> &[V]
Provides direct mutable access to the underlying memory.
This function gives access to all allocated data, including any reserved capacity beyond the active range.
pub fn view(&self) -> AudioBlockPlanarView<'_, S, V>
Trait Implementations§
Source§impl<S, V> AudioBlock<S> for AudioBlockPlanarView<'_, S, V>
impl<S, V> AudioBlock<S> for AudioBlockPlanarView<'_, S, V>
type PlanarView = V
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 layout(&self) -> BlockLayout
fn layout(&self) -> BlockLayout
Returns the memory layout of this audio block (interleaved, sequential, or planar).
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_iter(&self, channel: u16) -> impl Iterator<Item = &S>
fn channel_iter(&self, channel: u16) -> impl Iterator<Item = &S>
Returns an iterator over all samples in the specified channel. Read more
Source§fn channels_iter(&self) -> impl Iterator<Item = impl Iterator<Item = &S>>
fn channels_iter(&self) -> impl Iterator<Item = impl Iterator<Item = &S>>
Returns an iterator that yields an iterator for each channel.
Source§fn frame_iter(&self, frame: usize) -> impl Iterator<Item = &S>
fn frame_iter(&self, frame: usize) -> impl Iterator<Item = &S>
Returns an iterator over all samples in the specified frame (across all channels). Read more
Source§fn frame_iters(&self) -> impl Iterator<Item = impl Iterator<Item = &S>>
fn frame_iters(&self) -> impl Iterator<Item = impl Iterator<Item = &S>>
Returns an iterator that yields an iterator for each frame.
Source§fn as_view(&self) -> impl AudioBlock<S>
fn as_view(&self) -> impl AudioBlock<S>
Creates a non-owning view of this audio block. Read more
Source§fn as_planar_view(
&self,
) -> Option<AudioBlockPlanarView<'_, S, <AudioBlockPlanarView<'_, S, V> as AudioBlock<S>>::PlanarView>>
fn as_planar_view( &self, ) -> Option<AudioBlockPlanarView<'_, S, <AudioBlockPlanarView<'_, S, V> as AudioBlock<S>>::PlanarView>>
Attempts to downcast this generic audio block to a concrete planar view.
This enables access to frame slices and the underlying raw data. Read more
Source§fn as_interleaved_view(&self) -> Option<AudioBlockInterleavedView<'_, S>>
fn as_interleaved_view(&self) -> Option<AudioBlockInterleavedView<'_, S>>
Attempts to downcast this generic audio block to a concrete interleaved view.
This enables access to frame slices and the underlying raw data. Read more
Source§fn as_sequential_view(&self) -> Option<AudioBlockSequentialView<'_, S>>
fn as_sequential_view(&self) -> Option<AudioBlockSequentialView<'_, S>>
Attempts to downcast this generic audio block to a concrete sequential view.
This enables access to frame slices and the underlying raw data. Read more
Auto Trait Implementations§
impl<'a, S, V> Freeze for AudioBlockPlanarView<'a, S, V>
impl<'a, S, V> RefUnwindSafe for AudioBlockPlanarView<'a, S, V>where
S: RefUnwindSafe,
V: RefUnwindSafe,
impl<'a, S, V> Send for AudioBlockPlanarView<'a, S, V>
impl<'a, S, V> Sync for AudioBlockPlanarView<'a, S, V>
impl<'a, S, V> Unpin for AudioBlockPlanarView<'a, S, V>where
S: Unpin,
impl<'a, S, V> UnwindSafe for AudioBlockPlanarView<'a, S, V>where
S: UnwindSafe,
V: RefUnwindSafe,
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