Buffer

Struct Buffer 

Source
pub struct Buffer<'a, S: Sample = f32> { /* private fields */ }
Expand description

Main audio buffer for plugin processing.

Contains input and output channel slices for the primary audio bus. This is what most plugins interact with - simple stereo or surround I/O.

§Type Parameter

S is the sample type, defaulting to f32. Use Buffer<f64> for 64-bit double precision processing.

§Lifetime

The 'a lifetime ties the buffer to the host’s audio data. Buffers are only valid within a single process() call.

§Channel Layout

Channels are indexed starting from 0:

  • Stereo: 0 = Left, 1 = Right
  • Surround: 0 = Left, 1 = Right, 2 = Center, etc.

§Real-Time Safety

This struct uses fixed-size stack storage. No heap allocations occur during construction or use.

Implementations§

Source§

impl<'a, S: Sample> Buffer<'a, S>

Source

pub fn new( inputs: impl IntoIterator<Item = &'a [S]>, outputs: impl IntoIterator<Item = &'a mut [S]>, num_samples: usize, ) -> Self

Create a new buffer from channel slices.

This is called by the VST3 wrapper, not by plugin code. Channels beyond MAX_CHANNELS are silently ignored.

Source

pub fn num_samples(&self) -> usize

Number of samples in this processing block.

Source

pub fn num_input_channels(&self) -> usize

Number of input channels.

Source

pub fn num_output_channels(&self) -> usize

Number of output channels.

Source

pub fn is_stereo(&self) -> bool

Returns true if this is a stereo buffer (2 in, 2 out).

Source

pub fn is_mono(&self) -> bool

Returns true if this is a mono buffer (1 in, 1 out).

Source

pub fn input(&self, channel: usize) -> &[S]

Get an input channel by index.

Returns an empty slice if the channel doesn’t exist.

Source

pub fn output(&mut self, channel: usize) -> &mut [S]

Get a mutable output channel by index.

§Panics

Panics if the channel index is out of bounds.

Source

pub fn output_checked(&mut self, channel: usize) -> Option<&mut [S]>

Try to get a mutable output channel by index.

Returns None if the channel doesn’t exist.

Source

pub fn inputs(&self) -> impl Iterator<Item = &[S]> + '_

Iterate over all input channels.

Source

pub fn outputs_mut(&mut self) -> impl Iterator<Item = &mut [S]> + use<'_, 'a, S>

Iterate over all output channels mutably.

Source

pub fn zip_channels( &mut self, ) -> impl Iterator<Item = (&[S], &mut [S])> + use<'_, 'a, S>

Iterate over paired (input, output) channels.

This is the most common pattern for in-place processing. Only yields channels that exist in both input and output.

§Example
for (input, output) in buffer.zip_channels() {
    for (i, o) in input.iter().zip(output.iter_mut()) {
        *o = *i * gain;
    }
}
Source

pub fn copy_to_output(&mut self)

Copy all input channels to output channels.

Useful for bypass or passthrough. Only copies channels that exist in both input and output.

Source

pub fn clear_outputs(&mut self)

Clear all output channels to silence.

Source

pub fn apply_output_gain(&mut self, gain: S)

Apply a gain factor to all output channels.

Auto Trait Implementations§

§

impl<'a, S> Freeze for Buffer<'a, S>

§

impl<'a, S> RefUnwindSafe for Buffer<'a, S>
where S: RefUnwindSafe,

§

impl<'a, S> Send for Buffer<'a, S>

§

impl<'a, S> Sync for Buffer<'a, S>

§

impl<'a, S> Unpin for Buffer<'a, S>

§

impl<'a, S = f32> !UnwindSafe for Buffer<'a, S>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.