pub struct InstanceChannelBuffer<T: Clone + Copy + Default + Sized + Unpin, const INSTANCES: usize, const CHANNELS: usize> { /* private fields */ }
Expand description
A memory-efficient buffer of samples with a fixed compile-time number of instances each with a
fixed compile-time number of CHANNELS
. Each channel has a fixed runtime number of frames
(samples in a single channel of audio).
Implementations§
Source§impl<T: Clone + Copy + Default + Sized + Unpin, const INSTANCES: usize, const CHANNELS: usize> InstanceChannelBuffer<T, INSTANCES, CHANNELS>
impl<T: Clone + Copy + Default + Sized + Unpin, const INSTANCES: usize, const CHANNELS: usize> InstanceChannelBuffer<T, INSTANCES, CHANNELS>
Sourcepub fn new(num_instances: usize, frames: usize) -> Self
pub fn new(num_instances: usize, frames: usize) -> Self
Create a new InstanceChannelBuffer
allocated with the given number of
instances
, each with the given number of frames
(samples in a single channel
of audio).
All data will be initialized with the default value.
Sourcepub unsafe fn new_uninit(num_instances: usize, frames: usize) -> Self
pub unsafe fn new_uninit(num_instances: usize, frames: usize) -> Self
Create a new InstanceChannelBuffer
allocated with the given number of
instances
, each with the given number of frames
(samples in a single channel
of audio).
No data will be initialized.
§Safety
Any data must be initialized before reading.
Sourcepub fn num_instances(&self) -> usize
pub fn num_instances(&self) -> usize
The number of instances 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 instance<'a>(
&'a self,
index: usize,
) -> Option<ChannelBufferRef<'a, T, CHANNELS>>
pub fn instance<'a>( &'a self, index: usize, ) -> Option<ChannelBufferRef<'a, T, CHANNELS>>
Get an immutable reference to the instance at the given index.
Returns None
if index
is out of bounds.
Sourcepub unsafe fn instance_unchecked<'a>(
&'a self,
index: usize,
) -> ChannelBufferRef<'a, T, CHANNELS>
pub unsafe fn instance_unchecked<'a>( &'a self, index: usize, ) -> ChannelBufferRef<'a, T, CHANNELS>
Get an immutable reference to the instance at the given index.
§Safety
index
must be less than self.num_instances()
.
Sourcepub fn instance_mut<'a>(
&'a mut self,
index: usize,
) -> Option<ChannelBufferRefMut<'a, T, CHANNELS>>
pub fn instance_mut<'a>( &'a mut self, index: usize, ) -> Option<ChannelBufferRefMut<'a, T, CHANNELS>>
Get a mutable reference to the instance at the given index.
Returns None
if index
is out of bounds.
Sourcepub unsafe fn instance_unchecked_mut<'a>(
&'a mut self,
index: usize,
) -> ChannelBufferRefMut<'a, T, CHANNELS>
pub unsafe fn instance_unchecked_mut<'a>( &'a mut self, index: usize, ) -> ChannelBufferRefMut<'a, T, CHANNELS>
Get a mutable reference to the instance at the given index.
§Safety
index
must be less than self.num_instances()
.
Sourcepub fn all_instances<'a>(
&'a self,
) -> [ChannelBufferRef<'a, T, CHANNELS>; INSTANCES]
pub fn all_instances<'a>( &'a self, ) -> [ChannelBufferRef<'a, T, CHANNELS>; INSTANCES]
Get an immutable reference to all instances.
Sourcepub fn all_instances_mut<'a>(
&'a mut self,
) -> [ChannelBufferRefMut<'a, T, CHANNELS>; INSTANCES]
pub fn all_instances_mut<'a>( &'a mut self, ) -> [ChannelBufferRefMut<'a, T, CHANNELS>; INSTANCES]
Get a mutable reference to all instances.