Repository Public
1//! ORIX Sonata2//! File: crates/sonata-dsp/src/effect.rs3//! Description: The Effect contract between the DSP library and the runtime.4//!5//! Author: Simon-Pierre Boucher6//! Contact: contact@spboucher.ai78use sonata_ir::EffectDesc;910/// An insert effect processing stereo audio in place.11///12/// Contract with the runtime:13/// * `prepare` is called off the audio thread and is the only place allowed to allocate;14/// * `process` writes the **fully wet** signal over its input. Dry/wet mix, bypass and the15/// latency-aligned dry path are done by the runtime, uniformly for every effect, so a bypassed16/// effect keeps its reported latency;17/// * `process` never allocates, locks, logs or panics; output must be finite for any finite18/// input and any parameter inside its declared range (flush denormals, clamp internal state);19/// * `set_param` takes the index of the parameter in the effect's [`EffectDesc::params`], in20/// canonical units, already clamped by the caller; effects smooth audible parameters themselves;21/// * `left.len() == right.len() <= max_block`.22pub trait Effect: Send {23 fn prepare(&mut self, sample_rate: f32, max_block: usize);24 fn reset(&mut self);25 fn set_param(&mut self, index: usize, value: f32);26 /// Sets a `Choice` parameter by the index of the choice. Default: ignored.27 fn set_choice(&mut self, _index: usize, _choice: usize) {}28 fn process(&mut self, left: &mut [f32], right: &mut [f32]);29 /// Latency in samples at the prepared sample rate; must equal `EffectDesc::latency.at(rate)`.30 fn latency(&self) -> u32 {31 032 }33 /// Time the effect keeps ringing after its input stops (reverb and delay tails), seconds.34 fn tail_seconds(&self) -> f32 {35 0.036 }37}3839/// Creates an effect by registry kind. `None` for an unknown kind.40pub fn create_effect(kind: &str) -> Option<Box<dyn Effect>> {41 crate::effects::create(kind)42}4344/// Descriptors of every effect, in documentation order.45pub fn effect_registry() -> Vec<EffectDesc> {46 crate::effects::descriptors()47}48