pub struct ChannelBufferRefMut<'a, T: Clone + Copy + Default + Sized, const CHANNELS: usize> { /* private fields */ }
Expand description
A mutable memory-efficient buffer of samples with a fixed compile-time number of channels each with a fixed runtime number of frames (samples in a single channel of audio).
This version uses a reference to a slice as its data source.
Implementations§
Source§impl<'a, T: Clone + Copy + Default + Sized, const CHANNELS: usize> ChannelBufferRefMut<'a, T, CHANNELS>
impl<'a, T: Clone + Copy + Default + Sized, const CHANNELS: usize> ChannelBufferRefMut<'a, T, CHANNELS>
Sourcepub fn empty() -> Self
pub fn empty() -> Self
Create an empty ChannelBufferRefMut
with no data.
Sourcepub fn new(data: &'a mut [T]) -> Self
pub fn new(data: &'a mut [T]) -> Self
Create a new ChannelBufferRefMut
using the given slice as the data.
Sourcepub unsafe fn new_unchecked(data: &'a mut [T], frames: usize) -> Self
pub unsafe fn new_unchecked(data: &'a mut [T], frames: usize) -> Self
Create a new ChannelBufferRefMut
using the given slice as the data.
§Safety
The caller must uphold that data.len() >= frames * CHANNELS
.
Sourcepub fn frames(&self) -> usize
pub fn frames(&self) -> usize
The number of frames (samples in a single channel of audio) that are allocated in this buffer.
Sourcepub fn channel(&self, index: usize) -> Option<&[T]>
pub fn channel(&self, index: usize) -> Option<&[T]>
Get an immutable reference to the channel at index
. The slice will have a length
of self.frames()
.
Returns None
if index
is out of bounds.
Sourcepub unsafe fn channel_unchecked(&self, index: usize) -> &[T]
pub unsafe fn channel_unchecked(&self, index: usize) -> &[T]
Get an immutable reference to the channel at index
. The slice will have a length
of self.frames()
.
§Safety
index
must be less than self.channels()
Sourcepub fn channel_mut(&mut self, index: usize) -> Option<&mut [T]>
pub fn channel_mut(&mut self, index: usize) -> Option<&mut [T]>
Get a mutable reference to the channel at index
. The slice will have a length
of self.frames()
.
Returns None
if index
is out of bounds.
Sourcepub unsafe fn channel_unchecked_mut(&mut self, index: usize) -> &mut [T]
pub unsafe fn channel_unchecked_mut(&mut self, index: usize) -> &mut [T]
Get a mutable reference to the channel at index
. The slice will have a length
of self.frames()
.
§Safety
index
must be less than self.channels()
Sourcepub fn as_slices(&self) -> [&[T]; CHANNELS]
pub fn as_slices(&self) -> [&[T]; CHANNELS]
Get all channels as immutable slices. Each slice will have a length of self.frames()
.
Sourcepub fn as_mut_slices(&mut self) -> [&mut [T]; CHANNELS]
pub fn as_mut_slices(&mut self) -> [&mut [T]; CHANNELS]
Get all channels as mutable slices. Each slice will have a length of self.frames()
.
Sourcepub fn as_slices_with_length(&self, frames: usize) -> [&[T]; CHANNELS]
pub fn as_slices_with_length(&self, frames: usize) -> [&[T]; CHANNELS]
Get all channels as immutable slices with the given length in frames.
If frames > self.frames()
, then each slice will have a length of self.frames()
instead.
Sourcepub fn as_mut_slices_with_length(
&mut self,
frames: usize,
) -> [&mut [T]; CHANNELS]
pub fn as_mut_slices_with_length( &mut self, frames: usize, ) -> [&mut [T]; CHANNELS]
Get all channels as immutable slices with the given length in frames.
If frames > self.frames()
, then each slice will have a length of self.frames()
instead.
Sourcepub fn as_slices_with_range(&self, range: Range<usize>) -> [&[T]; CHANNELS]
pub fn as_slices_with_range(&self, range: Range<usize>) -> [&[T]; CHANNELS]
Get all channels as immutable slices in the given range.
If all or part of the range falls out of bounds, then only the part that falls within range will be returned.
Sourcepub fn as_mut_slices_with_range(
&mut self,
range: Range<usize>,
) -> [&mut [T]; CHANNELS]
pub fn as_mut_slices_with_range( &mut self, range: Range<usize>, ) -> [&mut [T]; CHANNELS]
Get all channels as immutable slices in the given range.
If all or part of the range falls out of bounds, then only the part that falls within range will be returned.
Sourcepub fn raw_mut(&mut self) -> &mut [T]
pub fn raw_mut(&mut self) -> &mut [T]
Get the entire contents of the buffer as a single mutable slice.
Sourcepub fn clear_frames(&mut self, frames: usize)
pub fn clear_frames(&mut self, frames: usize)
Clear all data in each channel up to frames
with the default value.