AudioBlockSequential

Struct AudioBlockSequential 

Source
pub struct AudioBlockSequential<S>
where S: Sample,
{ /* private fields */ }
Expand description

A sequential audio block that owns its data.

  • Layout: [ch0, ch0, ch0, ch1, ch1, ch1]
  • Interpretation: All samples from ch0 are stored first, followed by all from ch1, etc.
  • Terminology: Described as “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 block = AudioBlockSequential::new(2, 3);
let mut block = AudioBlockSequential::from_block(&block);

block.channel_mut(0).fill(0.0);
block.channel_mut(1).fill(1.0);

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<S> AudioBlockSequential<S>
where S: Sample,

Source

pub fn new(num_channels: u16, num_frames: usize) -> AudioBlockSequential<S>

Creates a new audio block with the specified dimensions.

Allocates memory with exactly the specified number of channels and frames. The block is initialized with zeros.

Do not use in real-time processes!

§Arguments
  • num_channels - The number of audio channels
  • num_frames - The number of frames per channel
§Panics

Panics if the multiplication of num_channels and num_frames would overflow a usize.

Source

pub fn from_block(block: &impl AudioBlock<S>) -> AudioBlockSequential<S>

Creates a new audio block by copying data from another AudioBlock.

Converts any AudioBlock implementation to a sequential format by iterating through each channel of the source block and copying its samples. The new block will have the same dimensions as the source block.

§Warning

This function allocates memory and should not be used in real-time audio processing contexts.

§Arguments
  • block - The source audio block to copy data from
Source

pub fn channel(&self, channel: u16) -> &[S]

Returns a slice for a single channel.

§Panics

Panics if channel index is out of bounds.

Source

pub fn channel_mut(&mut self, channel: u16) -> &mut [S]

Returns a mutable slice for a single channel.

§Panics

Panics if channel index is out of bounds.

Source

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.

Source

pub fn channels_mut(&mut self) -> impl Iterator<Item = &mut [S]>

Returns a mutable iterator over all channels in the block.

Each channel is represented as a mutable slice of samples.

Source

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.

Source

pub fn raw_data_mut(&mut self) -> &mut [S]

Provides direct mutable access to the underlying memory as an interleaved slice.

This function gives mutable access to all allocated data, including any reserved capacity beyond the active range.

Source

pub fn view(&self) -> AudioBlockSequentialView<'_, S>

Source

pub fn view_mut(&mut self) -> AudioBlockSequentialViewMut<'_, S>

Trait Implementations§

Source§

impl<S> AudioBlock<S> for AudioBlockSequential<S>
where S: Sample,

Source§

type PlanarView = [S; 0]

Source§

fn num_channels(&self) -> u16

Returns the number of active audio channels.
Source§

fn num_frames(&self) -> usize

Returns the number of audio frames (samples per channel).
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 layout(&self) -> BlockLayout

Returns the memory layout of this audio block (interleaved, sequential, or planar).
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_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>>

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

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>>

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

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

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

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
Source§

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_planar_view( &self, ) -> Option<AudioBlockPlanarView<'_, S, Self::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§

impl<S> AudioBlockMut<S> for AudioBlockSequential<S>
where S: Sample,

Source§

type PlanarViewMut = [S; 0]

Source§

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)

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

Returns a mutable reference to the sample at the specified channel and frame position. Read more
Source§

fn channel_iter_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_iter_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_iter_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_iter_mut( &mut self, ) -> impl Iterator<Item = impl Iterator<Item = &mut S>>

Returns a mutable iterator that yields mutable iterators for each frame.
Source§

fn as_view_mut(&mut self) -> impl AudioBlockMut<S>

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

fn as_sequential_view_mut( &mut self, ) -> Option<AudioBlockSequentialViewMut<'_, 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
Source§

fn set_active_size(&mut self, num_channels: u16, num_frames: usize)

Sets the active size of the audio block to the specified number of channels and frames. Read more
Source§

fn as_interleaved_view_mut( &mut self, ) -> Option<AudioBlockInterleavedViewMut<'_, 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_planar_view_mut( &mut self, ) -> Option<AudioBlockPlanarViewMut<'_, S, Self::PlanarViewMut>>

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§

impl<S> Debug for AudioBlockSequential<S>
where S: Sample + Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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<S, B> AudioBlockOps<S> for B
where S: Sample, B: AudioBlockMut<S>,

Source§

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>)

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(&mut self, f: impl FnMut(&mut S))

Gives access to all samples in the block.
Source§

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))

Gives access to all samples in the block while supplying the information about which channel and frame number the sample is stored in.
Source§

fn enumerate_including_non_visible(&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. Read more
Source§

fn fill_with(&mut self, sample: S)

Sets all samples in the block to the specified value
Source§

fn clear(&mut self)

Sets all samples in the block to zero
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<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

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.