pub trait Module: Send {
type In;
type Out;
// Required methods
fn tick(&mut self, input: Self::In) -> Self::Out;
fn reset(&mut self);
// Provided methods
fn process(&mut self, input: &[Self::In], output: &mut [Self::Out])
where Self::In: Clone { ... }
fn set_sample_rate(&mut self, _sample_rate: f64) { ... }
}Expand description
A signal processing module with typed input and output.
This is the fundamental abstraction for DSP processing in Quiver. Modules are
stateful processors that transform input samples to output samples. The
associated types In and Out enable compile-time verification of signal shape
(arity): a Module<Out = f64> only chains into a Module<In = f64>, a stereo
(f64, f64) only into a (f64, f64), and so on. This is structural type safety;
it does not check semantic SignalKind (Audio vs CV
vs V/Oct) — both are f64 here. Signal-kind compatibility is validated by the graph
layer (crate::port / crate::graph).
§Mathematical Model
A module represents a morphism in the category of signals:
M : In → OutThe tick method computes one step of this transformation, potentially updating
internal state (like oscillator phase or filter memory).
§Implementing Module
use quiver::prelude::*;
struct Amplifier { gain: f64 }
impl Module for Amplifier {
type In = f64;
type Out = f64;
fn tick(&mut self, input: f64) -> f64 {
input * self.gain
}
fn reset(&mut self) {
// Amplifier is stateless, nothing to reset
}
}
let mut amp = Amplifier { gain: 2.0 };
assert_eq!(amp.tick(0.5), 1.0);§Thread Safety
All modules must be Send to allow audio processing on dedicated threads.
Required Associated Types§
Required Methods§
Provided Methods§
Sourcefn process(&mut self, input: &[Self::In], output: &mut [Self::Out])
fn process(&mut self, input: &[Self::In], output: &mut [Self::Out])
Process a block of samples for efficiency.
Override this method for SIMD optimization or when block processing is
more efficient than sample-by-sample. The default implementation simply
calls tick in a loop.
Sourcefn set_sample_rate(&mut self, _sample_rate: f64)
fn set_sample_rate(&mut self, _sample_rate: f64)
Notify module of sample rate changes.
Modules with time-dependent behavior (filters, delays, envelopes) should recalculate coefficients here.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".