pub trait PluginDsp:
Default
+ Send
+ 'static {
// Required methods
fn new() -> Self;
fn prepare(&mut self, context: &DspContext);
fn reset(&mut self);
fn apply_parameters(&mut self, params: &[f32]);
fn process(
&mut self,
inputs: &[&[f32]],
outputs: &mut [&mut [f32]],
context: &DspContext,
);
}Expand description
Trait for plugin-specific DSP implementations.
Consumers implement this trait to define their audio processing chain. The FFI layer uses this trait to manage the DSP lifecycle.
§Example
ⓘ
use bbx_dsp::{PluginDsp, context::DspContext};
use bbx_dsp::blocks::effectors::gain::GainBlock;
pub struct PluginGraph {
pub gain: GainBlock<f32>,
}
impl PluginDsp for PluginGraph {
fn new() -> Self {
Self { gain: GainBlock::new(0.0) }
}
fn prepare(&mut self, context: &DspContext) {
// Initialize blocks for the given sample rate/buffer size
}
fn reset(&mut self) {
// Clear filter states, etc.
}
fn apply_parameters(&mut self, params: &[f32]) {
// Map parameter array to block fields
}
fn process(&mut self, inputs: &[&[f32]], outputs: &mut [&mut [f32]], context: &DspContext) {
// Process audio through the chain
}
}Required Methods§
Sourcefn prepare(&mut self, context: &DspContext)
fn prepare(&mut self, context: &DspContext)
Prepare the DSP chain for playback.
Called when audio specs change (sample rate, buffer size, channels).
Sourcefn reset(&mut self)
fn reset(&mut self)
Reset all DSP state.
Called to clear filter histories, oscillator phases, etc.
Sourcefn apply_parameters(&mut self, params: &[f32])
fn apply_parameters(&mut self, params: &[f32])
Apply parameter values from a flat array.
The parameter indices are plugin-specific, typically defined
via generated constants from parameters.json.
Sourcefn process(
&mut self,
inputs: &[&[f32]],
outputs: &mut [&mut [f32]],
context: &DspContext,
)
fn process( &mut self, inputs: &[&[f32]], outputs: &mut [&mut [f32]], context: &DspContext, )
Process a block of audio.
inputs: Array of input channel buffersoutputs: Array of output channel bufferscontext: DSP context with sample rate, buffer size, etc.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.