Skip to main content

AudioBlockMonoView

Struct AudioBlockMonoView 

Source
pub struct AudioBlockMonoView<'a, S: Sample> { /* private fields */ }
Expand description

A read-only view of mono (single-channel) audio data.

This provides a lightweight, non-owning reference to a slice of mono audio samples.

  • Layout: [sample0, sample1, sample2, ...]
  • Interpretation: A simple sequence of samples representing a single audio channel.
  • Usage: Ideal for mono audio processing, side-chain signals, or any single-channel audio data.

§Example

use audio_blocks::{mono::AudioBlockMonoView, AudioBlock};

let data = vec![0.0, 1.0, 2.0, 3.0, 4.0];
let block = AudioBlockMonoView::from_slice(&data);

assert_eq!(block.sample(0), 0.0);
assert_eq!(block.sample(4), 4.0);
assert_eq!(block.num_frames(), 5);

Implementations§

Source§

impl<'a, S: Sample> AudioBlockMonoView<'a, S>

Source

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

Creates a new mono audio block view from a slice of audio samples.

§Parameters
  • data - The slice containing mono audio samples
§Example
use audio_blocks::{mono::AudioBlockMonoView, AudioBlock};

let samples = [1.0, 2.0, 3.0, 4.0, 5.0];
let block = AudioBlockMonoView::from_slice(&samples);
assert_eq!(block.num_frames(), 5);
Source

pub fn from_slice_limited( data: &'a [S], num_frames_visible: usize, num_frames_allocated: usize, ) -> Self

Creates a new mono audio block view from a slice with limited visibility.

This function allows creating a view that exposes only a subset of the allocated frames, which is useful for working with a logical section of a larger buffer.

§Parameters
  • data - The slice containing mono audio samples
  • num_frames_visible - Number of audio frames to expose in the view
  • num_frames_allocated - Total number of frames allocated in the data buffer
§Panics
  • Panics if the length of data doesn’t equal num_frames_allocated
  • Panics if num_frames_visible exceeds num_frames_allocated
§Example
use audio_blocks::{mono::AudioBlockMonoView, AudioBlock};

let samples = [1.0, 2.0, 3.0, 4.0, 5.0];
let block = AudioBlockMonoView::from_slice_limited(&samples, 3, 5);
assert_eq!(block.num_frames(), 3);
assert_eq!(block.num_frames_allocated(), 5);
Source

pub unsafe fn from_ptr(ptr: *const S, num_frames: usize) -> Self

Creates a new mono audio block view from a pointer.

§Safety

The caller must ensure that:

  • ptr points to valid memory containing at least num_frames elements
  • The memory referenced by ptr must be valid for the lifetime of the returned view
  • The memory must not be mutated through other pointers while this view exists
§Example
use audio_blocks::{mono::AudioBlockMonoView, AudioBlock};

let samples = [1.0, 2.0, 3.0, 4.0, 5.0];
let block = unsafe { AudioBlockMonoView::from_ptr(samples.as_ptr(), 5) };
assert_eq!(block.num_frames(), 5);
Source

pub unsafe fn from_ptr_limited( ptr: *const S, num_frames_visible: usize, num_frames_allocated: usize, ) -> Self

Creates a new mono audio block view from a pointer with limited visibility.

§Safety

The caller must ensure that:

  • ptr points to valid memory containing at least num_frames_allocated elements
  • The memory referenced by ptr must be valid for the lifetime of the returned view
  • The memory must not be mutated through other pointers while this view exists
Source

pub fn sample(&self, frame: usize) -> S

Returns the sample at the specified frame index.

§Panics

Panics if frame index is out of bounds.

Source

pub fn samples(&self) -> &[S]

Provides direct access to the underlying samples as a slice.

Returns only the visible samples (up to num_frames).

Source

pub fn raw_data(&self) -> &[S]

Provides direct access to all allocated memory, including reserved capacity.

Source

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

Trait Implementations§

Source§

impl<S: Sample> AudioBlock<S> for AudioBlockMonoView<'_, S>

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 frames_iter( &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_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§

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§

impl<S: Sample + Debug> Debug for AudioBlockMonoView<'_, S>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a, S> Freeze for AudioBlockMonoView<'a, S>

§

impl<'a, S> RefUnwindSafe for AudioBlockMonoView<'a, S>
where S: RefUnwindSafe,

§

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

§

impl<'a, S> Sync for AudioBlockMonoView<'a, S>
where S: Sync,

§

impl<'a, S> Unpin for AudioBlockMonoView<'a, S>

§

impl<'a, S> UnwindSafe for AudioBlockMonoView<'a, S>
where S: RefUnwindSafe,

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: AudioBlock<S>,

Source§

fn mix_to_mono(&self, dest: &mut AudioBlockMonoViewMut<'_, S>)
where S: AddAssign + Div<Output = S> + From<u16>,

Mix all channels to mono by averaging them. Panics if source and destination don’t have the same number of frames.
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.