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

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 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.

Source

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.

Implementors§

Source§

impl<'a, T> Adapter<'a, T> for InterleavedSlice<&'a [T]>
where T: Clone,

Source§

impl<'a, T> Adapter<'a, T> for InterleavedSlice<&'a mut [T]>
where T: Clone,

Source§

impl<'a, T> Adapter<'a, T> for InterleavedSliceOfVecs<&'a [Vec<T>]>
where T: Clone,

Source§

impl<'a, T> Adapter<'a, T> for InterleavedSliceOfVecs<&'a mut [Vec<T>]>
where T: Clone,

Source§

impl<'a, T> Adapter<'a, T> for SequentialSlice<&'a [T]>
where T: Clone,

Source§

impl<'a, T> Adapter<'a, T> for SequentialSlice<&'a mut [T]>
where T: Clone,

Source§

impl<'a, T> Adapter<'a, T> for SequentialSliceOfVecs<&'a [Vec<T>]>
where T: Clone,

Source§

impl<'a, T> Adapter<'a, T> for SequentialSliceOfVecs<&'a mut [Vec<T>]>
where T: Clone,

Source§

impl<'a, T> Adapter<'a, T> for SparseSequentialSliceOfVecs<&'a [Vec<T>]>
where T: Clone + Default,

Source§

impl<'a, T> Adapter<'a, T> for SparseSequentialSliceOfVecs<&'a mut [Vec<T>]>
where T: Clone + Default,

Source§

impl<'a, T> Adapter<'a, T> for InterleavedOwned<T>
where T: Clone + 'a,

Source§

impl<'a, T> Adapter<'a, T> for SequentialOwned<T>
where T: Clone + 'a,

Source§

impl<'a, T, U> Adapter<'a, T> for ConvertBytes<T, U, &'a dyn Adapter<'a, [u8; 2]>>
where T: Float + 'a, U: BytesSample + RawSample + 'a,

Source§

impl<'a, T, U> Adapter<'a, T> for ConvertBytes<T, U, &'a mut dyn AdapterMut<'a, [u8; 2]>>
where T: Float + 'a, U: BytesSample + RawSample + 'a,

Source§

impl<'a, T, U> Adapter<'a, T> for ConvertNumbers<&'a dyn Adapter<'a, U>, T>
where T: Float + 'a, U: RawSample + 'a,

Source§

impl<'a, T, U> Adapter<'a, T> for ConvertNumbers<&'a mut dyn AdapterMut<'a, U>, T>
where T: Float + 'a, U: RawSample + 'a,

Source§

impl<'a, T, U> Adapter<'a, T> for InterleavedNumbers<&'a [U], T>
where T: Float + 'a, U: RawSample,

Source§

impl<'a, T, U> Adapter<'a, T> for InterleavedNumbers<&'a mut [U], T>
where T: Float + 'a, U: RawSample,

Source§

impl<'a, T, U> Adapter<'a, T> for SequentialNumbers<&'a [U], T>
where T: Float + 'a, U: RawSample,

Source§

impl<'a, T, U> Adapter<'a, T> for SequentialNumbers<&'a mut [U], T>
where T: Float + 'a, U: RawSample,

Source§

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