pub trait AudioBuffer {
    type SampleType;

    fn num_channels(&self) -> usize;
    fn num_samples(&self) -> usize;
    fn slice(&self) -> &[Self::SampleType];
    fn slice_mut(&mut self) -> &mut [Self::SampleType];
    fn get(&self, channel: usize, sample: usize) -> &Self::SampleType;
    fn get_mut(
        &mut self,
        channel: usize,
        sample: usize
    ) -> &mut Self::SampleType; fn set(&mut self, channel: usize, sample: usize, value: Self::SampleType); fn frames(&self) -> Chunks<'_, Self::SampleType> { ... } fn frames_mut(&mut self) -> ChunksMut<'_, Self::SampleType> { ... } unsafe fn get_unchecked(
        &self,
        channel: usize,
        sample: usize
    ) -> &Self::SampleType { ... } unsafe fn get_unchecked_mut(
        &mut self,
        channel: usize,
        sample: usize
    ) -> &mut Self::SampleType { ... } unsafe fn set_unchecked(
        &mut self,
        channel: usize,
        sample: usize,
        value: Self::SampleType
    ) { ... } }
Expand description

Represents an audio buffer. This decouples audio processing code from a certain representation of multi-channel sample buffers.

This crate provides implementations of this trait for CPal style buffers, which use interleaved internal representation.

When processing samples, it’ll be more efficient to use .slice and .slice_mut than .get / .set methods. For the VST buffer, these methods will not work.

It’s recommended to convert the buffer into interleaved layout before processing as that will be around as expensive as the overhead of get/set methods on a single loop through samples.

(due to bounds checking and other compiler optimisations that fail with them)

Required Associated Types

The type of samples within this buffer.

Required Methods

The number of channels in this buffer

The number of samples in this buffer

Get a slice to the internal data. Will not work with VST adapter

This is the faster way to process

Get a mutable slice to the internal data. Will not work with VST adapter

This is the faster way to process

Get a ref to an INPUT sample in this buffer.

Calling this on a loop will be ~20x slower than reading from slice.

Get a mutable ref to an OUTPUT sample in this buffer

On some implementations this may yield a different value than .get.

Calling this on a loop will be ~20x slower than reading from slice.

Set an OUTPUT sample in this buffer

Provided Methods

Shortcut for .slice().chunks(num_channels)

Shortcut for .slice_mut().chunks_mut(num_channels)

This is a frame representing a sample in time, for all channels.

Unsafe, no bounds check - Get a ref to an INPUT sample in this buffer

Calling this on a loop will be ~10x slower than reading from slice.

Safety

This performs no bounds checks. Make sure indexes are in range.

Unsafe, no bounds check - Get a mutable ref to an OUTPUT sample in this buffer

On some implementations this may yield a different value than .get.

Calling this on a loop will be ~10x slower than reading from slice.

Safety

This performs no bounds checks. Make sure indexes are in range.

Unsafe, no bounds check - Set an OUTPUT sample in this buffer

Calling this on a loop will be ~10x slower than reading from slice.

Safety

This performs no bounds checks. Make sure indexes are in range.

Implementors