baseplug icon indicating copy to clipboard operation
baseplug copied to clipboard

input/output buffer types

Open wrl opened this issue 5 years ago • 1 comments

right now, the input buffer type is &[f32] and the output buffer type is &mut [f32]. these represent pretty much exactly what we get from the host.

i have seen other rust libs wrap these buffers in higher-level types (for example, vst-rs's AudioBuffer). perhaps this is a better route?

seems like this could come along with #3 for better defining the "shape" of the buffers that are passed to the plugin.

wrl avatar Aug 19 '20 15:08 wrl

I initially had interleaved float arrays as the buffer type in my internal audio engine for Wavr, but changed it to a custom audio buffer similar to vst-rs's because I needed to process channels separatedly, and separating and recombining the interleaved buffer several times was wasteful; instead the audio engine gets a block of interleaved audio from the system, deinterleaves it, and passes it through the audio graph. I don't think there's a use-case for needing interleaved audio from within a plugin anyway, and if there is, it's so niche that the benefits outweigh the hypothetical cost of a plugin having to manually reinterleave the buffer anyway.

Furthermore, having your own audio buffer type means you can attach methods to it providing basic transformation and processing (i.e. VST3 having an audio buffer class that provides per-channel RMS calculation, or my audio buffer implementation here). While those buffers have runtime checking of the shape, with Rust it's entirely possible to have type-level constant generics and trait associated constants to define (and later check) the shape of the I/O buffers.

SolarLiner avatar Aug 19 '20 19:08 SolarLiner