pub trait Adapter<'a, T: 'a> {
// Required methods
unsafe fn read_sample_unchecked(&self, channel: usize, frame: usize) -> T;
fn channels(&self) -> usize;
fn frames(&self) -> usize;
// Provided methods
fn read_sample(&self, channel: usize, frame: usize) -> Option<T> { ... }
fn copy_from_channel_to_slice(
&self,
channel: usize,
skip: usize,
slice: &mut [T],
) -> usize { ... }
fn copy_from_frame_to_slice(
&self,
frame: usize,
skip: usize,
slice: &mut [T],
) -> usize { ... }
}Expand description
A trait for reading samples from a buffer.
Samples are accessed indirectly by a read_sample method.
Implementations may perform any needed transformation
of the sample value before returning it.
Required Methods§
Sourceunsafe fn read_sample_unchecked(&self, channel: usize, frame: usize) -> T
unsafe fn read_sample_unchecked(&self, channel: usize, frame: usize) -> T
Read the sample at a given combination of frame and channel.
§Safety
This method performs no bounds checking. Calling it with an out-of-bound value for frame or channel results in undefined behavior, for example returning an invalid value or panicking.
Provided Methods§
Sourcefn read_sample(&self, channel: usize, frame: usize) -> Option<T>
fn read_sample(&self, channel: usize, frame: usize) -> Option<T>
Read the sample at
a given combination of frame and channel.
Returns None if the frame or channel is
out of bounds of the buffer.
Sourcefn copy_from_channel_to_slice(
&self,
channel: usize,
skip: usize,
slice: &mut [T],
) -> usize
fn copy_from_channel_to_slice( &self, channel: usize, skip: usize, slice: &mut [T], ) -> usize
Copy values from a channel of self to a slice.
The skip argument is the offset in samples from
where the first value will be copied.
If the target slice is longer than the available number of values in the channel,
then only the available number of samples will be copied.
Returns the number of values copied.
If an invalid channel number is given,
or if skip is larger than the length of the channel,
no samples will be copied and zero is returned.
Sourcefn copy_from_frame_to_slice(
&self,
frame: usize,
skip: usize,
slice: &mut [T],
) -> usize
fn copy_from_frame_to_slice( &self, frame: usize, skip: usize, slice: &mut [T], ) -> usize
Copy values from a frame of self to a slice.
The skip argument is the offset in samples from
where the first value will be copied.
If the slice is longer than the available number of values in the frame,
then only the available number of samples will be copied.
Returns the number of values copied.
If an invalid frame number is given,
or if skip is larger than the length of the frame,
no samples will be copied and zero is returned.