pub struct PlanarViewMut<'a, S: Sample, V: AsMut<[S]> + AsRef<[S]>> { /* private fields */ }Expand description
A mutable view of planar / separate-channel audio data.
- Layout:
[[ch0, ch0, ch0], [ch1, ch1, ch1]] - Interpretation: Each channel has its own separate buffer or array.
- Terminology: Also described as “planar” or “channels first” though more specifically it’s channel-isolated buffers.
- Usage: Very common in real-time DSP, as it simplifies memory access and can improve SIMD/vectorization efficiency.
§Example
use audio_blocks::*;
let mut data = vec![[0.0, 0.0, 0.0], [1.0, 1.0, 1.0]];
let block = PlanarViewMut::from_slice(&mut data);
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<'a, S: Sample, V: AsMut<[S]> + AsRef<[S]>> PlanarViewMut<'a, S, V>
impl<'a, S: Sample, V: AsMut<[S]> + AsRef<[S]>> PlanarViewMut<'a, S, V>
Sourcepub fn from_slice(data: &'a mut [V]) -> Self
pub fn from_slice(data: &'a mut [V]) -> Self
Sourcepub fn from_slice_limited(
data: &'a mut [V],
num_channels_visible: u16,
num_frames_visible: usize,
) -> Self
pub fn from_slice_limited( data: &'a mut [V], num_channels_visible: u16, num_frames_visible: usize, ) -> Self
Creates a new audio block from a mutable slice with limited visibility.
This function allows creating a view that exposes only a subset of the allocated channels and frames, which is useful for working with a logical section of a larger buffer.
§Parameters
data- The mutable slice containing planar audio samples (one slice per channel)num_channels_visible- Number of audio channels to expose in the viewnum_frames_visible- Number of audio frames to expose in the view
§Panics
- Panics if
num_channels_visibleexceeds the number of channels indata - Panics if
num_frames_visibleexceeds the length of any channel buffer - Panics if channel slices have different lengths
Sourcepub fn channel_mut(&mut self, channel: u16) -> &mut [S]
pub fn channel_mut(&mut self, channel: u16) -> &mut [S]
Sourcepub fn channels(&self) -> impl ExactSizeIterator<Item = &[S]>
pub fn channels(&self) -> impl ExactSizeIterator<Item = &[S]>
Returns an iterator over all channels in the block.
Each channel is represented as a slice of samples.
Sourcepub fn channels_mut(&mut self) -> impl ExactSizeIterator<Item = &mut [S]>
pub fn channels_mut(&mut self) -> impl ExactSizeIterator<Item = &mut [S]>
Returns a mutable iterator over all channels in the block.
Each channel is represented as a mutable slice of samples.
Sourcepub fn raw_data(&self) -> &[V]
pub fn raw_data(&self) -> &[V]
Provides direct access to the underlying memory.
This function gives access to all allocated data, including any reserved capacity beyond the visible range.
Sourcepub fn raw_data_mut(&mut self) -> &mut [V]
pub fn raw_data_mut(&mut self) -> &mut [V]
Provides direct access to the underlying memory.
This function gives access to all allocated data, including any reserved capacity beyond the visible range.
pub fn view(&self) -> PlanarView<'_, S, V>
pub fn view_mut(&mut self) -> PlanarViewMut<'_, S, V>
Trait Implementations§
Source§impl<S: Sample, V: AsMut<[S]> + AsRef<[S]>> AudioBlock<S> for PlanarViewMut<'_, S, V>
impl<S: Sample, V: AsMut<[S]> + AsRef<[S]>> AudioBlock<S> for PlanarViewMut<'_, S, V>
type PlanarView = V
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_planar_view(&self) -> Option<PlanarView<'_, S, Self::PlanarView>>
fn as_planar_view(&self) -> Option<PlanarView<'_, S, Self::PlanarView>>
Source§fn as_interleaved_view(&self) -> Option<InterleavedView<'_, S>>
fn as_interleaved_view(&self) -> Option<InterleavedView<'_, S>>
Source§fn as_sequential_view(&self) -> Option<SequentialView<'_, S>>
fn as_sequential_view(&self) -> Option<SequentialView<'_, S>>
Source§impl<S: Sample, V: AsMut<[S]> + AsRef<[S]>> AudioBlockMut<S> for PlanarViewMut<'_, S, V>
impl<S: Sample, V: AsMut<[S]> + AsRef<[S]>> AudioBlockMut<S> for PlanarViewMut<'_, S, V>
type PlanarViewMut = V
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 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 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_sequential_view_mut(&mut self) -> Option<SequentialViewMut<'_, S>>
fn as_sequential_view_mut(&mut self) -> Option<SequentialViewMut<'_, S>>
Auto Trait Implementations§
impl<'a, S, V> Freeze for PlanarViewMut<'a, S, V>
impl<'a, S, V> RefUnwindSafe for PlanarViewMut<'a, S, V>where
S: RefUnwindSafe,
V: RefUnwindSafe,
impl<'a, S, V> Send for PlanarViewMut<'a, S, V>
impl<'a, S, V> Sync for PlanarViewMut<'a, S, V>
impl<'a, S, V> Unpin for PlanarViewMut<'a, S, V>where
S: Unpin,
impl<'a, S, V> UnsafeUnpin for PlanarViewMut<'a, S, V>
impl<'a, S, V> !UnwindSafe for PlanarViewMut<'a, S, V>
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.