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>
impl<'a, S: Sample> AudioBlockMonoView<'a, S>
Sourcepub fn from_slice(data: &'a [S]) -> Self
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);Sourcepub fn from_slice_limited(
data: &'a [S],
num_frames_visible: usize,
num_frames_allocated: usize,
) -> Self
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 samplesnum_frames_visible- Number of audio frames to expose in the viewnum_frames_allocated- Total number of frames allocated in the data buffer
§Panics
- Panics if the length of
datadoesn’t equalnum_frames_allocated - Panics if
num_frames_visibleexceedsnum_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);Sourcepub unsafe fn from_ptr(ptr: *const S, num_frames: usize) -> Self
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:
ptrpoints to valid memory containing at leastnum_frameselements- The memory referenced by
ptrmust 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);Sourcepub unsafe fn from_ptr_limited(
ptr: *const S,
num_frames_visible: usize,
num_frames_allocated: usize,
) -> Self
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:
ptrpoints to valid memory containing at leastnum_frames_allocatedelements- The memory referenced by
ptrmust be valid for the lifetime of the returned view - The memory must not be mutated through other pointers while this view exists
Sourcepub fn samples(&self) -> &[S]
pub fn samples(&self) -> &[S]
Provides direct access to the underlying samples as a slice.
Returns only the visible samples (up to num_frames).
Sourcepub fn raw_data(&self) -> &[S]
pub fn raw_data(&self) -> &[S]
Provides direct access to all allocated memory, including reserved capacity.