pub trait Algorithm<T: Transcendental>: Send + Sync {
// Required methods
fn process(
&mut self,
input: Option<&[T]>,
output: &mut [T],
ctx: &ActionContext<'_>,
) -> ProcessResult<()>;
fn reset(&mut self);
// Provided methods
fn apply_command(&mut self, _value: T) { ... }
fn init(&mut self, _sample_rate: f32) { ... }
fn metadata(&self) -> AlgorithmMetadata { ... }
}Expand description
Unified processing primitive for ports and DSP blocks.
Every port in the graph owns an optional Box<dyn Algorithm>. When present,
the port’s run_action() calls Algorithm::process() to fill its buffer.
Low-level DSP components (filters, generators, effects) also implement this trait directly, making them usable both inside the graph and standalone.
§Required methods
process()— the main per-block processing entry point.reset()— restore initial state.
§Optional methods
init()— configure sample rate.apply_command()— receive a real-time parameter value from the control path (called between samples by the graph driver).metadata()— return descriptive info (defaults to empty).
Required Methods§
Sourcefn process(
&mut self,
input: Option<&[T]>,
output: &mut [T],
ctx: &ActionContext<'_>,
) -> ProcessResult<()>
fn process( &mut self, input: Option<&[T]>, output: &mut [T], ctx: &ActionContext<'_>, ) -> ProcessResult<()>
Process one block of audio.
§Arguments
input— Audio data from upstream (empty when the port is unconnected, orNonefor source ports / control output ports).output— Buffer to fill with processed data.ctx— Processing context (clock tick, block position, etc.).
Provided Methods§
Sourcefn apply_command(&mut self, _value: T)
fn apply_command(&mut self, _value: T)
Receive a real-time command value from the control path.
Called by the graph driver between process() calls when a
SetParameter targets this port. The algorithm should store the
value and apply it (possibly smoothed) on the next process().
Default: no-op.
Sourcefn init(&mut self, _sample_rate: f32)
fn init(&mut self, _sample_rate: f32)
Initialise the algorithm with a sample rate.
Called once when the node is added to the graph. Available for coefficient pre-computation.
Default: no-op.
Sourcefn metadata(&self) -> AlgorithmMetadata
fn metadata(&self) -> AlgorithmMetadata
Descriptive metadata (defaults to empty).