pub trait Processor: Send + 'static {
type Params: ProcessorParams + Default + Send + Sync + 'static;
// Required method
fn process(
&mut self,
buffer: &mut [&mut [f32]],
transport: &Transport,
params: &Self::Params,
);
// Provided methods
fn set_sample_rate(&mut self, _sample_rate: f32) { ... }
fn reset(&mut self) { ... }
}Expand description
Trait for user-implemented DSP processors.
Implement this trait to define custom audio processing logic. All methods must be real-time safe (no allocations, locks, or syscalls).
§Example
use wavecraft_dsp::{ParamRange, ParamSpec, Processor, ProcessorParams, Transport};
#[derive(Default)]
struct MyGainParams {
level: f32,
}
impl ProcessorParams for MyGainParams {
fn param_specs() -> &'static [ParamSpec] {
&[ParamSpec {
name: "Level",
id_suffix: "level",
range: ParamRange::Linear { min: 0.0, max: 2.0 },
default: 1.0,
unit: "x",
group: None,
}]
}
}
struct MyGain {
sample_rate: f32,
}
impl Processor for MyGain {
type Params = MyGainParams;
fn process(
&mut self,
buffer: &mut [&mut [f32]],
_transport: &Transport,
params: &Self::Params,
) {
for channel in buffer.iter_mut() {
for sample in channel.iter_mut() {
*sample *= params.level;
}
}
}
}Required Associated Types§
Required Methods§
Sourcefn process(
&mut self,
buffer: &mut [&mut [f32]],
transport: &Transport,
params: &Self::Params,
)
fn process( &mut self, buffer: &mut [&mut [f32]], transport: &Transport, params: &Self::Params, )
Process a buffer of audio samples.
The buffer is provided as a slice of mutable slices, one per channel. Modify samples in-place to apply your DSP effect.
§Arguments
buffer- Audio channels as[L, R, ...]where each channel is[samples]transport- Playback timing informationparams- Current parameter values
§Real-Time Safety
This method is called on the audio thread. It MUST be real-time safe:
- No allocations (
Vec::push,String,Box::new) - No locks (
Mutex,RwLock) - No syscalls (file I/O, logging, network)
- No panics (use
debug_assert!only)