AdapterMut

Trait AdapterMut 

Source
pub trait AdapterMut<'a, T>: Adapter<'a, T>
where T: Clone + 'a,
{ // Required method unsafe fn write_sample_unchecked( &mut self, channel: usize, frame: usize, value: &T, ) -> bool; // Provided methods fn write_sample( &mut self, channel: usize, frame: usize, value: &T, ) -> Option<bool> { ... } fn copy_from_slice_to_channel( &mut self, channel: usize, skip: usize, slice: &[T], ) -> (usize, usize) { ... } fn copy_from_slice_to_frame( &mut self, frame: usize, skip: usize, slice: &[T], ) -> (usize, usize) { ... } fn copy_from_other_to_channel( &mut self, other: &dyn Adapter<'a, T>, other_channel: usize, self_channel: usize, other_skip: usize, self_skip: usize, take: usize, ) -> Option<usize> { ... } fn fill_channel_with(&mut self, channel: usize, value: &T) -> Option<()> { ... } fn fill_frame_with(&mut self, frame: usize, value: &T) -> Option<()> { ... } fn fill_frames_with( &mut self, start: usize, count: usize, value: &T, ) -> Option<usize> { ... } fn fill_with(&mut self, value: &T) { ... } fn copy_frames_within( &mut self, src: usize, dest: usize, count: usize, ) -> Option<usize> { ... } fn copy_sample_within( &mut self, source_channel: usize, source_frame: usize, target_channel: usize, target_frame: usize, ) -> bool { ... } fn swap_samples( &mut self, channel_a: usize, frame_a: usize, channel_b: usize, frame_b: usize, ) -> bool { ... } }
Expand description

A trait for writing samples to a buffer. Samples are accessed indirectly by a write_sample method. Implementations may perform any needed transformation of the sample value before writing to the underlying buffer.

Required Methods§

Source

unsafe fn write_sample_unchecked( &mut self, channel: usize, frame: usize, value: &T, ) -> bool

Write a sample to the given combination of frame and channel. Returns a boolean indicating if the sample value was clipped during conversion. Implementations that do not perform any conversion always return false.

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

Source

fn write_sample( &mut self, channel: usize, frame: usize, value: &T, ) -> Option<bool>

Write a sample to the given combination of frame and channel. Returns a boolean indicating if the sample value was clipped during conversion. Implementations that do not perform any conversion always return false. Returns None if the frame or channel is out of bounds of the buffer.

Source

fn copy_from_slice_to_channel( &mut self, channel: usize, skip: usize, slice: &[T], ) -> (usize, usize)

Copies values from a slice into a channel of self. The skip argument is the offset into the channel to where the first value will be copied. If the slice is longer than the available space in the channel, then only the number of samples that fit will be copied.

Returns a tuple of two numbers. The first is the number of values copied, and the second is the number of values that were clipped during conversion. Implementations that do not perform any conversion always return zero clipped samples. If an invalid channel number is given, or if skip is larger than the length of the channel, no samples will be copied and (0, 0) is returned.

Source

fn copy_from_slice_to_frame( &mut self, frame: usize, skip: usize, slice: &[T], ) -> (usize, usize)

Copy values from a slice into a frame of self. The skip argument is the offset into the frame to where the first value will be copied. If the slice is longer than the available space in the frame, then only the number of samples that fit will be copied.

Returns a tuple of two numbers. The first is the number of values copied, and the second is the number of values that were clipped during conversion. Implementations that do not perform any conversion always return zero clipped samples. If an invalid frame number is given, or if skip is larger than the length of the frame, no samples will be copied and (0, 0) is returned.

Source

fn copy_from_other_to_channel( &mut self, other: &dyn Adapter<'a, T>, other_channel: usize, self_channel: usize, other_skip: usize, self_skip: usize, take: usize, ) -> Option<usize>

Copy values from a channel of another Adapter. The self_skip and other_skip arguments are the offsets in frames for where copying starts in the two channels. The method copies take values.

Returns the the number of values that were clipped during conversion. Implementations that do not perform any conversion always return zero clipped samples.

If an invalid channel number is given, or if either of the channels is to short to copy take values, no values will be copied and None is returned.

Source

fn fill_channel_with(&mut self, channel: usize, value: &T) -> Option<()>

Write the provided value to every sample in a channel. Can be used to clear a channel by writing zeroes, or to initialize each sample to a certain value. Returns None if called with an invalid channel number.

Source

fn fill_frame_with(&mut self, frame: usize, value: &T) -> Option<()>

Write the provided value to every sample in a frame. Can be used to clear a frame by writing zeroes, or to initialize each sample to a certain value. Returns None if called with an invalid frame number.

Source

fn fill_frames_with( &mut self, start: usize, count: usize, value: &T, ) -> Option<usize>

Write the provided value to every sample in a range of frames. Can be used to clear a range of frames by writing zeroes, or to initialize each sample to a certain value. Returns None if called with a too large range.

Source

fn fill_with(&mut self, value: &T)

Write the provided value to every sample in the entire buffer. Can be used to clear a buffer by writing zeroes, or to initialize each sample to a certain value.

Source

fn copy_frames_within( &mut self, src: usize, dest: usize, count: usize, ) -> Option<usize>

Copy frames within the buffer. Copying is performed for all channels. Copies count frames, from the range src..src+count, to the range dest..dest+count. The two regions are allowed to overlap. The default implementation copies by calling the read and write methods, while type specific implementations can use more efficient methods.

Source

fn copy_sample_within( &mut self, source_channel: usize, source_frame: usize, target_channel: usize, target_frame: usize, ) -> bool

Copy a single sample within the buffer. Copies from the source to the target frame and channel. Returns true if the sample was copied, and false if not, which may happen if the source or target frame or channel was out of bounds. The default implementation copies by calling the read and write methods, while type specific implementations can use more efficient methods.

Source

fn swap_samples( &mut self, channel_a: usize, frame_a: usize, channel_b: usize, frame_b: usize, ) -> bool

Swap two samples in the buffer. Returns true if the samples were swapped, and false if not, which may happen if the channel or frame for either sample was out of bounds. The default implementation copies by calling the read and write methods, while type specific implementations can use more efficient methods.

Implementors§

Source§

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