pub struct Mono<S: Sample> { /* private fields */ }Expand description
A mono (single-channel) audio block that owns its data.
This is a simplified version of the multi-channel audio blocks, optimized for mono audio processing with a streamlined API that doesn’t require channel indexing.
- 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::*;
let mut block = Mono::new(512);
// Fill with a simple ramp
for (i, sample) in block.samples_mut().iter_mut().enumerate() {
*sample = i as f32;
}
assert_eq!(block.sample(0), 0.0);
assert_eq!(block.sample(511), 511.0);Implementations§
Source§impl<S: Sample + Default> Mono<S>
impl<S: Sample + Default> Mono<S>
Sourcepub fn new(num_frames: usize) -> Self
pub fn new(num_frames: usize) -> Self
Creates a new mono audio block with the specified number of frames.
Allocates memory for a new mono audio block with exactly the specified number of frames. The block is initialized with the default value (zero) for the sample type.
Do not use in real-time processes!
§Arguments
num_frames- The number of frames (samples)
§Example
use audio_blocks::{mono::Mono, AudioBlock};
let block = Mono::<f32>::new(1024);
assert_eq!(block.num_frames(), 1024);Source§impl<S: Sample> Mono<S>
impl<S: Sample> Mono<S>
Sourcepub fn from_slice(samples: &[S]) -> Self
pub fn from_slice(samples: &[S]) -> Self
Sourcepub fn from_slice_limited(samples: &[S], num_frames_visible: usize) -> Self
pub fn from_slice_limited(samples: &[S], num_frames_visible: usize) -> Self
Creates a new mono audio block from a slice of samples.
Copies the provided slice into a new owned mono block.
§Warning
This function allocates memory and should not be used in real-time audio processing contexts.
§Arguments
samples- The slice of samples to copynum_frames_visible- Number of audio frames to expose
Sourcepub fn from_block(block: &impl AudioBlock<S>) -> Self
pub fn from_block(block: &impl AudioBlock<S>) -> Self
Creates a new mono audio block by copying data from another AudioBlock.
Extracts the first channel from any AudioBlock implementation.
If the source block has no channels, creates an empty mono 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 (first channel will be used)
§Panics
Panics if the source block has zero channels.
Sourcepub fn sample_mut(&mut self, frame: usize) -> &mut S
pub fn sample_mut(&mut self, frame: usize) -> &mut S
Returns a mutable reference to the sample at the specified frame index.
§Panics
Panics if frame index is out of bounds.
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 samples_mut(&mut self) -> &mut [S]
pub fn samples_mut(&mut self) -> &mut [S]
Provides direct mutable 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.
This gives access to the full allocated buffer, including any frames beyond the visible range.
Sourcepub fn raw_data_mut(&mut self) -> &mut [S]
pub fn raw_data_mut(&mut self) -> &mut [S]
Provides direct mutable access to all allocated memory, including reserved capacity.
This gives mutable access to the full allocated buffer, including any frames beyond the visible range.
Sourcepub fn view_mut(&mut self) -> MonoViewMut<'_, S>
pub fn view_mut(&mut self) -> MonoViewMut<'_, S>
Creates a mutable view of this mono audio block.
Trait Implementations§
Source§impl<S: Sample> AudioBlock<S> for Mono<S>
impl<S: Sample> AudioBlock<S> for Mono<S>
type PlanarView = [S; 0]
Source§fn num_channels(&self) -> u16
fn num_channels(&self) -> u16
Source§fn num_frames(&self) -> usize
fn num_frames(&self) -> usize
Source§fn num_channels_allocated(&self) -> u16
fn num_channels_allocated(&self) -> u16
Source§fn num_frames_allocated(&self) -> usize
fn num_frames_allocated(&self) -> usize
Source§fn layout(&self) -> BlockLayout
fn layout(&self) -> BlockLayout
Source§fn sample(&self, channel: u16, frame: usize) -> S
fn sample(&self, channel: u16, frame: usize) -> S
Source§fn channel_iter(&self, channel: u16) -> impl ExactSizeIterator<Item = &S>
fn channel_iter(&self, channel: u16) -> impl ExactSizeIterator<Item = &S>
Source§fn channels_iter(
&self,
) -> impl ExactSizeIterator<Item = impl ExactSizeIterator<Item = &S>>
fn channels_iter( &self, ) -> impl ExactSizeIterator<Item = impl ExactSizeIterator<Item = &S>>
Source§fn frame_iter(&self, frame: usize) -> impl ExactSizeIterator<Item = &S>
fn frame_iter(&self, frame: usize) -> impl ExactSizeIterator<Item = &S>
Source§fn frames_iter(
&self,
) -> impl ExactSizeIterator<Item = impl ExactSizeIterator<Item = &S>>
fn frames_iter( &self, ) -> impl ExactSizeIterator<Item = impl ExactSizeIterator<Item = &S>>
Source§fn as_view(&self) -> impl AudioBlock<S>
fn as_view(&self) -> impl AudioBlock<S>
Source§fn as_interleaved_view(&self) -> Option<InterleavedView<'_, S>>
fn as_interleaved_view(&self) -> Option<InterleavedView<'_, S>>
Source§fn as_planar_view(&self) -> Option<PlanarView<'_, S, Self::PlanarView>>
fn as_planar_view(&self) -> Option<PlanarView<'_, S, Self::PlanarView>>
Source§fn as_sequential_view(&self) -> Option<SequentialView<'_, S>>
fn as_sequential_view(&self) -> Option<SequentialView<'_, S>>
Source§impl<S: Sample> AudioBlockMut<S> for Mono<S>
impl<S: Sample> AudioBlockMut<S> for Mono<S>
type PlanarViewMut = [S; 0]
Source§fn set_num_channels_visible(&mut self, num_channels: u16)
fn set_num_channels_visible(&mut self, num_channels: u16)
Source§fn set_num_frames_visible(&mut self, num_frames: usize)
fn set_num_frames_visible(&mut self, num_frames: usize)
Source§fn sample_mut(&mut self, channel: u16, frame: usize) -> &mut S
fn sample_mut(&mut self, channel: u16, frame: usize) -> &mut S
Source§fn channel_iter_mut(
&mut self,
channel: u16,
) -> impl ExactSizeIterator<Item = &mut S>
fn channel_iter_mut( &mut self, channel: u16, ) -> impl ExactSizeIterator<Item = &mut S>
Source§fn channels_iter_mut(
&mut self,
) -> impl ExactSizeIterator<Item = impl ExactSizeIterator<Item = &mut S>>
fn channels_iter_mut( &mut self, ) -> impl ExactSizeIterator<Item = impl ExactSizeIterator<Item = &mut S>>
Source§fn frame_iter_mut(
&mut self,
frame: usize,
) -> impl ExactSizeIterator<Item = &mut S>
fn frame_iter_mut( &mut self, frame: usize, ) -> impl ExactSizeIterator<Item = &mut S>
Source§fn frames_iter_mut(
&mut self,
) -> impl ExactSizeIterator<Item = impl ExactSizeIterator<Item = &mut S>>
fn frames_iter_mut( &mut self, ) -> impl ExactSizeIterator<Item = impl ExactSizeIterator<Item = &mut S>>
Source§fn as_view_mut(&mut self) -> impl AudioBlockMut<S>
fn as_view_mut(&mut self) -> impl AudioBlockMut<S>
Source§fn set_visible(&mut self, num_channels: u16, num_frames: usize)
fn set_visible(&mut self, num_channels: u16, num_frames: usize)
Source§fn as_interleaved_view_mut(&mut self) -> Option<InterleavedViewMut<'_, S>>
fn as_interleaved_view_mut(&mut self) -> Option<InterleavedViewMut<'_, S>>
Source§fn as_planar_view_mut(
&mut self,
) -> Option<PlanarViewMut<'_, S, Self::PlanarViewMut>>
fn as_planar_view_mut( &mut self, ) -> Option<PlanarViewMut<'_, S, Self::PlanarViewMut>>
Source§fn as_sequential_view_mut(&mut self) -> Option<SequentialViewMut<'_, S>>
fn as_sequential_view_mut(&mut self) -> Option<SequentialViewMut<'_, S>>
Auto Trait Implementations§
impl<S> Freeze for Mono<S>
impl<S> RefUnwindSafe for Mono<S>where
S: RefUnwindSafe,
impl<S> Send for Mono<S>where
S: Send,
impl<S> Sync for Mono<S>where
S: Sync,
impl<S> Unpin for Mono<S>
impl<S> UnsafeUnpin for Mono<S>
impl<S> UnwindSafe for Mono<S>where
S: UnwindSafe,
Blanket Implementations§
Source§impl<S, B> AudioBlockOps<S> for Bwhere
S: Sample,
B: AudioBlock<S>,
impl<S, B> AudioBlockOps<S> for Bwhere
S: Sample,
B: AudioBlock<S>,
Source§fn mix_to_mono(&self, dest: &mut MonoViewMut<'_, S>) -> Option<usize>
fn mix_to_mono(&self, dest: &mut MonoViewMut<'_, S>) -> Option<usize>
min(src_frames, dst_frames) frames.
Returns None if all frames were processed (exact match),
or Some(frames_processed) if a partial mix occurred.Source§fn mix_to_mono_exact(&self, dest: &mut MonoViewMut<'_, S>)
fn mix_to_mono_exact(&self, dest: &mut MonoViewMut<'_, S>)
Source§fn copy_channel_to_mono(
&self,
dest: &mut MonoViewMut<'_, S>,
channel: u16,
) -> Option<usize>
fn copy_channel_to_mono( &self, dest: &mut MonoViewMut<'_, S>, channel: u16, ) -> Option<usize>
min(src_frames, dst_frames) frames.
Returns None if all frames were copied (exact match),
or Some(frames_copied) if a partial copy occurred.Source§fn copy_channel_to_mono_exact(
&self,
dest: &mut MonoViewMut<'_, S>,
channel: u16,
)
fn copy_channel_to_mono_exact( &self, dest: &mut MonoViewMut<'_, S>, channel: u16, )
Source§impl<S, B> AudioBlockOpsMut<S> for Bwhere
S: Sample,
B: AudioBlockMut<S>,
impl<S, B> AudioBlockOpsMut<S> for Bwhere
S: Sample,
B: AudioBlockMut<S>,
Source§fn copy_from_block(
&mut self,
block: &impl AudioBlock<S>,
) -> Option<(u16, usize)>
fn copy_from_block( &mut self, block: &impl AudioBlock<S>, ) -> Option<(u16, usize)>
min(src, dst) channels and frames.
Returns None if the entire block was copied (exact match),
or Some((channels_copied, frames_copied)) if a partial copy occurred.
Never panics - safely handles mismatched block sizes.Source§fn copy_from_block_exact(&mut self, block: &impl AudioBlock<S>)
fn copy_from_block_exact(&mut self, block: &impl AudioBlock<S>)
Source§fn copy_mono_to_all_channels(&mut self, mono: &MonoView<'_, S>) -> Option<usize>
fn copy_mono_to_all_channels(&mut self, mono: &MonoView<'_, S>) -> Option<usize>
min(src_frames, dst_frames) frames.
Returns None if all frames were copied (exact match),
or Some(frames_copied) if a partial copy occurred.