pub struct AudioBlockMonoViewMut<'a, S: Sample> { /* private fields */ }Expand description
A mutable view of mono (single-channel) audio data.
This provides a lightweight, non-owning mutable 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::AudioBlockMonoViewMut, AudioBlock};
let mut data = vec![0.0, 1.0, 2.0, 3.0, 4.0];
let mut block = AudioBlockMonoViewMut::from_slice(&mut data);
*block.sample_mut(0) = 10.0;
assert_eq!(block.sample(0), 10.0);Implementations§
Source§impl<'a, S: Sample> AudioBlockMonoViewMut<'a, S>
impl<'a, S: Sample> AudioBlockMonoViewMut<'a, S>
Sourcepub fn from_slice(data: &'a mut [S]) -> Self
pub fn from_slice(data: &'a mut [S]) -> Self
Creates a new mono audio block view from a mutable slice of audio samples.
§Parameters
data- The mutable slice containing mono audio samples
§Example
use audio_blocks::{mono::AudioBlockMonoViewMut, AudioBlock};
let mut samples = [1.0, 2.0, 3.0, 4.0, 5.0];
let mut block = AudioBlockMonoViewMut::from_slice(&mut samples);
assert_eq!(block.num_frames(), 5);Sourcepub fn from_slice_limited(
data: &'a mut [S],
num_frames_visible: usize,
num_frames_allocated: usize,
) -> Self
pub fn from_slice_limited( data: &'a mut [S], num_frames_visible: usize, num_frames_allocated: usize, ) -> Self
Creates a new mono audio block view from a mutable 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 mutable 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::AudioBlockMonoViewMut, AudioBlock};
let mut samples = [1.0, 2.0, 3.0, 4.0, 5.0];
let mut block = AudioBlockMonoViewMut::from_slice_limited(&mut samples, 3, 5);
assert_eq!(block.num_frames(), 3);
assert_eq!(block.num_frames_allocated(), 5);Sourcepub unsafe fn from_ptr(ptr: *mut S, num_frames: usize) -> Self
pub unsafe fn from_ptr(ptr: *mut S, num_frames: usize) -> Self
Creates a new mono audio block view from a mutable 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 - No other references (mutable or immutable) exist to the same memory
§Example
use audio_blocks::{mono::AudioBlockMonoViewMut, AudioBlock};
let mut samples = [1.0, 2.0, 3.0, 4.0, 5.0];
let mut block = unsafe { AudioBlockMonoViewMut::from_ptr(samples.as_mut_ptr(), 5) };
assert_eq!(block.num_frames(), 5);Sourcepub unsafe fn from_ptr_limited(
ptr: *mut S,
num_frames_visible: usize,
num_frames_allocated: usize,
) -> Self
pub unsafe fn from_ptr_limited( ptr: *mut S, num_frames_visible: usize, num_frames_allocated: usize, ) -> Self
Creates a new mono audio block view from a mutable 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 - No other references (mutable or immutable) exist to the same memory
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.
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.
pub fn view(&self) -> AudioBlockMonoView<'_, S>
pub fn view_mut(&mut self) -> AudioBlockMonoViewMut<'_, S>
Trait Implementations§
Source§impl<S: Sample> AudioBlock<S> for AudioBlockMonoViewMut<'_, S>
impl<S: Sample> AudioBlock<S> for AudioBlockMonoViewMut<'_, 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 Iterator<Item = &S>
fn channel_iter(&self, channel: u16) -> impl Iterator<Item = &S>
Source§fn channels_iter(
&self,
) -> impl Iterator<Item = impl Iterator<Item = &S> + '_> + '_
fn channels_iter( &self, ) -> impl Iterator<Item = impl Iterator<Item = &S> + '_> + '_
Source§fn frame_iter(&self, frame: usize) -> impl Iterator<Item = &S>
fn frame_iter(&self, frame: usize) -> impl Iterator<Item = &S>
Source§fn frames_iter(
&self,
) -> impl Iterator<Item = impl Iterator<Item = &S> + '_> + '_
fn frames_iter( &self, ) -> impl Iterator<Item = impl Iterator<Item = &S> + '_> + '_
Source§fn as_view(&self) -> impl AudioBlock<S>
fn as_view(&self) -> impl AudioBlock<S>
Source§fn as_interleaved_view(&self) -> Option<AudioBlockInterleavedView<'_, S>>
fn as_interleaved_view(&self) -> Option<AudioBlockInterleavedView<'_, S>>
Source§fn as_planar_view(
&self,
) -> Option<AudioBlockPlanarView<'_, S, Self::PlanarView>>
fn as_planar_view( &self, ) -> Option<AudioBlockPlanarView<'_, S, Self::PlanarView>>
Source§fn as_sequential_view(&self) -> Option<AudioBlockSequentialView<'_, S>>
fn as_sequential_view(&self) -> Option<AudioBlockSequentialView<'_, S>>
Source§impl<S: Sample> AudioBlockMut<S> for AudioBlockMonoViewMut<'_, S>
impl<S: Sample> AudioBlockMut<S> for AudioBlockMonoViewMut<'_, 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 Iterator<Item = &mut S>
fn channel_iter_mut(&mut self, channel: u16) -> impl Iterator<Item = &mut S>
Source§fn channels_iter_mut(
&mut self,
) -> impl Iterator<Item = impl Iterator<Item = &mut S> + '_> + '_
fn channels_iter_mut( &mut self, ) -> impl Iterator<Item = impl Iterator<Item = &mut S> + '_> + '_
Source§fn frame_iter_mut(&mut self, frame: usize) -> impl Iterator<Item = &mut S>
fn frame_iter_mut(&mut self, frame: usize) -> impl Iterator<Item = &mut S>
Source§fn frames_iter_mut(
&mut self,
) -> impl Iterator<Item = impl Iterator<Item = &mut S> + '_> + '_
fn frames_iter_mut( &mut self, ) -> impl Iterator<Item = impl Iterator<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<AudioBlockInterleavedViewMut<'_, S>>
fn as_interleaved_view_mut( &mut self, ) -> Option<AudioBlockInterleavedViewMut<'_, S>>
Source§fn as_planar_view_mut(
&mut self,
) -> Option<AudioBlockPlanarViewMut<'_, S, Self::PlanarViewMut>>
fn as_planar_view_mut( &mut self, ) -> Option<AudioBlockPlanarViewMut<'_, S, Self::PlanarViewMut>>
Source§fn as_sequential_view_mut(
&mut self,
) -> Option<AudioBlockSequentialViewMut<'_, S>>
fn as_sequential_view_mut( &mut self, ) -> Option<AudioBlockSequentialViewMut<'_, S>>
Auto Trait Implementations§
impl<'a, S> Freeze for AudioBlockMonoViewMut<'a, S>
impl<'a, S> RefUnwindSafe for AudioBlockMonoViewMut<'a, S>where
S: RefUnwindSafe,
impl<'a, S> Send for AudioBlockMonoViewMut<'a, S>where
S: Send,
impl<'a, S> Sync for AudioBlockMonoViewMut<'a, S>where
S: Sync,
impl<'a, S> Unpin for AudioBlockMonoViewMut<'a, S>
impl<'a, S> !UnwindSafe for AudioBlockMonoViewMut<'a, S>
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 AudioBlockMonoViewMut<'_, S>)
fn mix_to_mono(&self, dest: &mut AudioBlockMonoViewMut<'_, S>)
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>)
fn copy_from_block(&mut self, block: &impl AudioBlock<S>)
min(src, dst) channels and frames.
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: &AudioBlockMonoView<'_, S>)
fn copy_mono_to_all_channels(&mut self, mono: &AudioBlockMonoView<'_, S>)
Source§fn for_each_including_non_visible(&mut self, f: impl FnMut(&mut S))
fn for_each_including_non_visible(&mut self, f: impl FnMut(&mut S))
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.