Skip to main content

Algorithm

Trait Algorithm 

Source
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§

Source

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, or None for source ports / control output ports).
  • output — Buffer to fill with processed data.
  • ctx — Processing context (clock tick, block position, etc.).
Source

fn reset(&mut self)

Reset the algorithm to its initial state.

Called when the owning node is reset, or when feedback delay lines need clearing.

Provided Methods§

Source

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.

Source

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.

Source

fn metadata(&self) -> AlgorithmMetadata

Descriptive metadata (defaults to empty).

Implementors§