pub struct VarChannelBufferRef<'a, T: Clone + Copy + Default + Sized, const MAX_CHANNELS: usize> { /* private fields */ }
Expand description
An immutable memory-efficient buffer of samples with a fixed runtime 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 MAX_CHANNELS: usize> VarChannelBufferRef<'a, T, MAX_CHANNELS>
impl<'a, T: Clone + Copy + Default + Sized, const MAX_CHANNELS: usize> VarChannelBufferRef<'a, T, MAX_CHANNELS>
Sourcepub fn empty() -> Self
pub fn empty() -> Self
Create an empty VarChannelBufferRef
with no data.
Sourcepub fn new(data: &'a [T], channels: NonZeroUsize) -> Self
pub fn new(data: &'a [T], channels: NonZeroUsize) -> Self
Create a new VarChannelBufferRef
using the given slice as the data.
§Panics
Panics if channels.get() > MAX_CHANNELS
.
Sourcepub unsafe fn new_unchecked(
data: &'a [T],
frames: usize,
channels: NonZeroUsize,
) -> Self
pub unsafe fn new_unchecked( data: &'a [T], frames: usize, channels: NonZeroUsize, ) -> Self
Create a new VarChannelBufferRef
using the given slice as the data.
§Safety
The caller must uphold that:
data.len() >= frames * self.channels().get()
- and
channels.get() <= MAX_CHANNELS
Sourcepub fn channels(&self) -> NonZeroUsize
pub fn channels(&self) -> NonZeroUsize
The number of channels in this buffer.
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 as_slices(&self) -> ArrayVec<&[T], MAX_CHANNELS>
pub fn as_slices(&self) -> ArrayVec<&[T], MAX_CHANNELS>
Get all channels as immutable slices. Each slice will have a length of self.frames()
.
Sourcepub fn as_slices_with_length(
&self,
frames: usize,
) -> ArrayVec<&[T], MAX_CHANNELS>
pub fn as_slices_with_length( &self, frames: usize, ) -> ArrayVec<&[T], MAX_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.
Trait Implementations§
Source§impl<'a, T: Clone + Clone + Copy + Default + Sized, const MAX_CHANNELS: usize> Clone for VarChannelBufferRef<'a, T, MAX_CHANNELS>
impl<'a, T: Clone + Clone + Copy + Default + Sized, const MAX_CHANNELS: usize> Clone for VarChannelBufferRef<'a, T, MAX_CHANNELS>
Source§fn clone(&self) -> VarChannelBufferRef<'a, T, MAX_CHANNELS>
fn clone(&self) -> VarChannelBufferRef<'a, T, MAX_CHANNELS>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more