Struct StackedView

Source
pub struct StackedView<'a, S: Sample, V: AsRef<[S]>> { /* private fields */ }
Expand description

A read-only view of stacked / 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 = StackedView::from_slice(&data);

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, V: AsRef<[S]>> StackedView<'a, S, V>

Source

pub fn from_slice(data: &'a [V]) -> Self

Creates a new StackedView from a slice of stacked audio data.

§Parameters
  • data - The slice containing stacked audio samples (one slice per channel)
§Panics

Panics if the channel slices have different lengths.

Source

pub fn from_slice_limited( data: &'a [V], num_channels_visible: u16, num_frames_visible: usize, ) -> Self

Creates a new StackedView 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 stacked audio samples (one slice per channel)
  • num_channels_visible - Number of audio channels to expose in the view
  • num_frames_visible - Number of audio frames to expose in the view
§Panics
  • Panics if num_channels_visible exceeds the number of channels in data
  • Panics if num_frames_visible exceeds the length of any channel buffer
  • Panics if channel slices have different lengths

Trait Implementations§

Source§

impl<S: Sample, V: AsRef<[S]>> AudioBlock<S> for StackedView<'_, S, V>

Source§

fn num_frames(&self) -> usize

Returns the number of audio frames (samples per channel).
Source§

fn num_channels(&self) -> u16

Returns the number of active audio channels.
Source§

fn num_channels_allocated(&self) -> u16

Returns the total number of channels allocated in memory. Read more
Source§

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

Returns the sample value at the specified channel and frame position. Read more
Source§

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> + '_> + '_

Returns an iterator that yields iterators for each channel.
Source§

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> + '_> + '_

Returns an iterator that yields iterators for each frame.
Source§

fn view(&self) -> impl AudioBlock<S>

Creates a non-owning view of this audio block. Read more
Source§

fn layout(&self) -> BlockLayout

Returns the memory layout of this audio block (interleaved, sequential, or stacked).
Source§

fn raw_data(&self, stacked_ch: Option<u16>) -> &[S]

Provides direct access to the underlying memory as a slice. Read more

Auto Trait Implementations§

§

impl<'a, S, V> Freeze for StackedView<'a, S, V>

§

impl<'a, S, V> RefUnwindSafe for StackedView<'a, S, V>

§

impl<'a, S, V> Send for StackedView<'a, S, V>
where S: Send, V: Sync,

§

impl<'a, S, V> Sync for StackedView<'a, S, V>
where S: Sync, V: Sync,

§

impl<'a, S, V> Unpin for StackedView<'a, S, V>
where S: Unpin,

§

impl<'a, S, V> UnwindSafe for StackedView<'a, S, V>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.