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 write_from_channel_to_slice(
&self,
channel: usize,
skip: usize,
slice: &mut [T],
) -> usize { ... }
fn write_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 write_from_channel_to_slice(
&self,
channel: usize,
skip: usize,
slice: &mut [T],
) -> usize
fn write_from_channel_to_slice( &self, channel: usize, skip: usize, slice: &mut [T], ) -> usize
Write values from a channel of the buffer to a slice.
The skip argument is the offset into the buffer channel
where the first value will be read from.
If the slice is longer than the available number of values in the channel of the buffer,
then only the available number of samples will be written.
Returns the number of values written.
If an invalid channel number is given,
or if skip is larger than the length of the channel,
no samples will be written and zero is returned.
Sourcefn write_from_frame_to_slice(
&self,
frame: usize,
skip: usize,
slice: &mut [T],
) -> usize
fn write_from_frame_to_slice( &self, frame: usize, skip: usize, slice: &mut [T], ) -> usize
Write values from a frame of the buffer to a slice.
The skip argument is the offset into the buffer frame
where the first value will be read from.
If the slice is longer than the available number of values in the buffer frame,
then only the available number of samples will be written.
Returns the number of values written.
If an invalid frame number is given,
or if skip is larger than the length of the frame,
no samples will be written and zero is returned.