pub struct Buffer<'a> { /* private fields */ }
Expand description
The audio buffers used during processing. This contains the output audio output buffers with the inputs already copied to the outputs. You can either use the iterator adapters to conveniently and efficiently iterate over the samples, or you can do your own thing using the raw audio buffers.
TODO: This lifetime makes zero sense because you’re going to need unsafe lifetime casts to use this either way. Maybe just get rid of it in favor for raw pointers.
Implementations§
source§impl<'a> Buffer<'a>
impl<'a> Buffer<'a>
sourcepub fn as_slice_immutable(&self) -> &[&'a mut [f32]]
pub fn as_slice_immutable(&self) -> &[&'a mut [f32]]
The same as as_slice()
, but for a non-mutable reference. This is
usually not needed.
sourcepub fn iter_samples<'slice>(&'slice mut self) -> SamplesIter<'slice, 'a> ⓘ
pub fn iter_samples<'slice>(&'slice mut self) -> SamplesIter<'slice, 'a> ⓘ
Iterate over the samples, returning a channel iterator for each sample.
sourcepub fn iter_blocks<'slice>(
&'slice mut self,
max_block_size: usize
) -> BlocksIter<'slice, 'a> ⓘ
pub fn iter_blocks<'slice>( &'slice mut self, max_block_size: usize ) -> BlocksIter<'slice, 'a> ⓘ
Iterate over the buffer in blocks with the specified maximum size. The ideal maximum block
size depends on the plugin in question, but 64 or 128 samples works for most plugins. Since
the buffer’s total size may not be cleanly divisible by the maximum size, the returned
buffers may have any size in [1, max_block_size]
. This is useful when using algorithms
that work on entire blocks of audio, like those that would otherwise need to perform
expensive per-sample branching or that can use per-sample SIMD as opposed to per-channel
SIMD.
The parameter smoothers can also produce smoothed values for an entire block using
Smoother::next_block()
.
You can use this to obtain block-slices from a buffer so you can pass them to a library:
for block in buffer.iter_blocks(128) {
let mut block_channels = block.into_iter();
let stereo_slice = &[
block_channels.next().unwrap(),
block_channels.next().unwrap(),
];
// Do something cool with `stereo_slice`
}
sourcepub unsafe fn set_slices(
&mut self,
num_samples: usize,
update: impl FnOnce(&mut Vec<&'a mut [f32]>)
)
pub unsafe fn set_slices( &mut self, num_samples: usize, update: impl FnOnce(&mut Vec<&'a mut [f32]>) )
Set the slices in the raw output slice vector. This vector needs to be resized to match the
number of output channels during the plugin’s initialization. Then during audio processing,
these slices should be updated to point to the plugin’s audio buffers. The num_samples
argument should match the length of the inner slices.
Safety
The stored slices must point to live data when this object is passed to the plugins’ process function. The rest of this object also assumes all channel lengths are equal. Panics will likely occur if this is not the case.