Skip to main content

AudioProcessor

Trait AudioProcessor 

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

Source

fn name(&self) -> &'static str

Processor name for debugging and logging

Source

fn process(&mut self, buffer: &mut [f64], channels: usize) -> ProcessResult

Process audio samples in-place

§Arguments
  • buffer - Interleaved audio samples [L, R, L, R, …]
  • channels - Number of audio channels
§Returns

Processing result status indicating what happened

Source

fn reset(&mut self)

Reset internal state (filter delay lines, etc.)

Called when:

  • Starting a new track
  • Changing sample rate
  • After gapless track switch
Source

fn is_enabled(&self) -> bool

Check if processor is enabled

Source

fn set_enabled(&mut self, enabled: bool)

Enable or disable the processor

Provided Methods§

Source

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".

Implementors§