Skip to main content

AudioBuffer

Trait AudioBuffer 

Source
pub trait AudioBuffer<T: Sample> {
    // Required methods
    fn num_channels(&self) -> usize;
    fn num_frames(&self) -> FrameSize;
    fn channel(&self, index: usize) -> Option<&[T]>;
    fn channel_mut(&mut self, index: usize) -> Option<&mut [T]>;
    fn clear(&mut self);

    // Provided methods
    fn copy_to_interleaved(
        &self,
        output: &mut [T],
    ) -> Result<usize, AudioGraphError> { ... }
    fn copy_from_interleaved(
        &mut self,
        input: &[T],
        num_channels: usize,
    ) -> Result<FrameSize, AudioGraphError> { ... }
    fn add(
        &mut self,
        other: &dyn AudioBuffer<T>,
        channel_selection: &Option<ChannelSelection>,
    ) { ... }
}
Expand description

Trait representing a buffer of audio samples organized by channels

Audiograph expects audio to be organized in a channel-based format where each channel stores its samples in contiguous memory. Implementations for the most common use cases are provided (see MultiChannelBuffer for owned buffers and MultiChannelBufferView for non-owning views), but you can implement this trait for your own custom buffer types as needed.

Required Methods§

Source

fn num_channels(&self) -> usize

Returns the number of channels in the buffer

Source

fn num_frames(&self) -> FrameSize

Returns the number of frames (samples per channel) in the buffer

Source

fn channel(&self, index: usize) -> Option<&[T]>

Returns a slice of samples for the specified channel index, or None if the index is out of bounds

Source

fn channel_mut(&mut self, index: usize) -> Option<&mut [T]>

Returns a mutable slice of samples for the specified channel index, or None if the index is out of bounds

Source

fn clear(&mut self)

Clears the buffer, setting all samples to zero

Provided Methods§

Source

fn copy_to_interleaved( &self, output: &mut [T], ) -> Result<usize, AudioGraphError>

Interleaves the audio buffer into the provided output slice

Returns the number of samples written to the output buffer or an error if the output buffer is too small.

Source

fn copy_from_interleaved( &mut self, input: &[T], num_channels: usize, ) -> Result<FrameSize, AudioGraphError>

Copies interleaved audio data from the input slice into the deinterleaved buffer format

Returns the number of frames processed, or an error if the number of channels or the size of the input buffer exceeds the capacity of this buffer. Clears any remaining channels if num_channels is less than the number of channels in this buffer. Errors out if the provided input buffer size is not a multiple of the provided number of channels.

Source

fn add( &mut self, other: &dyn AudioBuffer<T>, channel_selection: &Option<ChannelSelection>, )

Sums channels from another buffer into this buffer, optionally using a channel selection to specify which channels to sum.

Implementors§