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>
impl<'a, S: Sample> Buffer<'a, S>
Sourcepub fn new(
inputs: impl IntoIterator<Item = &'a [S]>,
outputs: impl IntoIterator<Item = &'a mut [S]>,
num_samples: usize,
) -> Self
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.
Sourcepub fn num_samples(&self) -> usize
pub fn num_samples(&self) -> usize
Number of samples in this processing block.
Sourcepub fn num_input_channels(&self) -> usize
pub fn num_input_channels(&self) -> usize
Number of input channels.
Sourcepub fn num_output_channels(&self) -> usize
pub fn num_output_channels(&self) -> usize
Number of output channels.
Sourcepub fn input(&self, channel: usize) -> &[S]
pub fn input(&self, channel: usize) -> &[S]
Get an input channel by index.
Returns an empty slice if the channel doesn’t exist.
Sourcepub fn output_checked(&mut self, channel: usize) -> Option<&mut [S]>
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.
Sourcepub fn outputs_mut(&mut self) -> impl Iterator<Item = &mut [S]> + use<'_, 'a, S>
pub fn outputs_mut(&mut self) -> impl Iterator<Item = &mut [S]> + use<'_, 'a, S>
Iterate over all output channels mutably.
Sourcepub fn zip_channels(
&mut self,
) -> impl Iterator<Item = (&[S], &mut [S])> + use<'_, 'a, S>
pub fn zip_channels( &mut self, ) -> impl Iterator<Item = (&[S], &mut [S])> + use<'_, 'a, S>
Sourcepub fn copy_to_output(&mut self)
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.
Sourcepub fn clear_outputs(&mut self)
pub fn clear_outputs(&mut self)
Clear all output channels to silence.
Sourcepub fn apply_output_gain(&mut self, gain: S)
pub fn apply_output_gain(&mut self, gain: S)
Apply a gain factor to all output channels.