Adapter

Trait Adapter 

Source
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§

Source

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.

Source

fn channels(&self) -> usize

Get the number of channels stored in this buffer.

Source

fn frames(&self) -> usize

Get the number of frames stored in this buffer.

Provided Methods§

Source

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.

Source

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.

Source

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.

Implementors§

Source§

impl<'a, T, U> Adapter<'a, T> for U
where T: Clone + Sample + 'a, U: Buf<Sample = T> + ExactSizeBuf<Sample = T>,