pub trait AudioProcessor: Send {
// Required methods
fn name(&self) -> &'static str;
fn process(&mut self, buffer: &mut [f64], channels: usize) -> ProcessResult;
fn reset(&mut self);
fn is_enabled(&self) -> bool;
fn set_enabled(&mut self, enabled: bool);
// Provided method
fn set_sample_rate(&mut self, _sample_rate: f64) { ... }
}Expand description
Core audio processor trait
All DSP processors must implement this trait to be used in the DspChain. The trait provides a unified interface for:
- Audio processing
- State reset
- Enable/disable control
§Thread Safety
Implementations must be Send because processors are owned by the audio thread.
Parameters should be passed via the snapshot types in lockfree_params.
§Example
ⓘ
use crate::processor::traits::{AudioProcessor, ProcessResult};
struct MyProcessor {
enabled: bool,
gain: f64,
}
impl AudioProcessor for MyProcessor {
fn name(&self) -> &'static str { "MyProcessor" }
fn process(&mut self, buffer: &mut [f64], channels: usize) -> ProcessResult {
if !self.enabled {
return ProcessResult::Bypassed;
}
for sample in buffer.iter_mut() {
*sample *= self.gain;
}
ProcessResult::Ok
}
fn reset(&mut self) {}
fn is_enabled(&self) -> bool { self.enabled }
fn set_enabled(&mut self, enabled: bool) { self.enabled = enabled; }
}Required Methods§
Sourcefn process(&mut self, buffer: &mut [f64], channels: usize) -> ProcessResult
fn process(&mut self, buffer: &mut [f64], channels: usize) -> ProcessResult
Sourcefn reset(&mut self)
fn reset(&mut self)
Reset internal state (filter delay lines, etc.)
Called when:
- Starting a new track
- Changing sample rate
- After gapless track switch
Sourcefn is_enabled(&self) -> bool
fn is_enabled(&self) -> bool
Check if processor is enabled
Sourcefn set_enabled(&mut self, enabled: bool)
fn set_enabled(&mut self, enabled: bool)
Enable or disable the processor
Provided Methods§
Sourcefn set_sample_rate(&mut self, _sample_rate: f64)
fn set_sample_rate(&mut self, _sample_rate: f64)
Update sample rate and recalculate internal coefficients if needed.
Default implementation is no-op for processors that are sample-rate agnostic.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".