Skip to main content

AudioBlockOpsMut

Trait AudioBlockOpsMut 

Source
pub trait AudioBlockOpsMut<S: Sample> {
    // Required methods
    fn copy_from_block(
        &mut self,
        block: &impl AudioBlock<S>,
    ) -> Option<(u16, usize)>;
    fn copy_from_block_exact(&mut self, block: &impl AudioBlock<S>);
    fn copy_mono_to_all_channels(
        &mut self,
        mono: &MonoView<'_, S>,
    ) -> Option<usize>;
    fn copy_mono_to_all_channels_exact(&mut self, mono: &MonoView<'_, S>);
    fn for_each(&mut self, f: impl FnMut(&mut S));
    fn enumerate(&mut self, f: impl FnMut(u16, usize, &mut S));
    fn for_each_allocated(&mut self, f: impl FnMut(&mut S));
    fn enumerate_allocated(&mut self, f: impl FnMut(u16, usize, &mut S));
    fn fill_with(&mut self, sample: S);
    fn clear(&mut self)
       where S: Default;
    fn gain(&mut self, gain: S)
       where S: Mul<Output = S> + Copy;
}

Required Methods§

Source

fn copy_from_block( &mut self, block: &impl AudioBlock<S>, ) -> Option<(u16, usize)>

Copy samples from source block into destination. Only copies min(src, dst) channels and frames. Returns None if the entire block was copied (exact match), or Some((channels_copied, frames_copied)) if a partial copy occurred. Never panics - safely handles mismatched block sizes.

Source

fn copy_from_block_exact(&mut self, block: &impl AudioBlock<S>)

Copy samples from source block, requiring exact size match. Panics if source and destination don’t have identical channels and frames.

Source

fn copy_mono_to_all_channels(&mut self, mono: &MonoView<'_, S>) -> Option<usize>

Copy a mono block to all channels of this block. Only copies min(src_frames, dst_frames) frames. Returns None if all frames were copied (exact match), or Some(frames_copied) if a partial copy occurred.

Source

fn copy_mono_to_all_channels_exact(&mut self, mono: &MonoView<'_, S>)

Copy a mono block to all channels of this block. Panics if blocks don’t have the same number of frames.

Source

fn for_each(&mut self, f: impl FnMut(&mut S))

Gives access to all samples in the block.

Source

fn enumerate(&mut self, f: impl FnMut(u16, usize, &mut S))

Gives access to all samples in the block while supplying the information about which channel and frame number the sample is stored in.

Source

fn for_each_allocated(&mut self, f: impl FnMut(&mut S))

Iterate over all allocated samples using fast linear buffer iteration.

This iterates over num_frames_allocated() samples, not just num_frames(). It uses cache-friendly linear access over the underlying storage, which is significantly faster than for_each for large buffers when the visible window is close to the allocated size.

§Performance Note

Only use this when num_frames() is close to num_frames_allocated(). If the buffer has been resized dramatically (e.g., set_visible() to half the allocation), for_each will be faster as it respects the visible window.

Source

fn enumerate_allocated(&mut self, f: impl FnMut(u16, usize, &mut S))

Iterate over all allocated samples with indices using fast linear buffer iteration.

Like for_each_allocated, this iterates over the entire allocated buffer for cache-friendly linear access. Only faster than enumerate when the visible window is close to the allocated size.

Source

fn fill_with(&mut self, sample: S)

Sets all samples in the block to the specified value. Iterates over the entire allocated buffer for efficiency.

Source

fn clear(&mut self)
where S: Default,

Sets all samples in the block to the default value (zero for numeric types). Iterates over the entire allocated buffer for efficiency.

Source

fn gain(&mut self, gain: S)
where S: Mul<Output = S> + Copy,

Applies gain to all samples by multiplying each sample. Iterates over the entire allocated buffer for efficiency.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§