pub struct ChannelBufferRef<'a, T: Clone + Copy + Default + Sized, const CHANNELS: usize> { /* private fields */ }
Expand description
An immutable 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> ChannelBufferRef<'a, T, CHANNELS>
impl<'a, T: Clone + Copy + Default + Sized, const CHANNELS: usize> ChannelBufferRef<'a, T, CHANNELS>
Sourcepub fn empty() -> Self
pub fn empty() -> Self
Create an empty ChannelBufferRef
with no data.
Sourcepub fn new(data: &'a [T]) -> Self
pub fn new(data: &'a [T]) -> Self
Create a new ChannelBufferRef
using the given slice as the data.
Sourcepub unsafe fn new_unchecked(data: &'a [T], frames: usize) -> Self
pub unsafe fn new_unchecked(data: &'a [T], frames: usize) -> Self
Create a new ChannelBufferRef
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 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_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.
Trait Implementations§
Source§impl<'a, T: Clone + Clone + Copy + Default + Sized, const CHANNELS: usize> Clone for ChannelBufferRef<'a, T, CHANNELS>
impl<'a, T: Clone + Clone + Copy + Default + Sized, const CHANNELS: usize> Clone for ChannelBufferRef<'a, T, CHANNELS>
Source§fn clone(&self) -> ChannelBufferRef<'a, T, CHANNELS>
fn clone(&self) -> ChannelBufferRef<'a, T, CHANNELS>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more