Parameter<S> Type

The generic parameter type for static and modulated values.

Definition

#![allow(unused)]
fn main() {
pub enum Parameter<S: Sample> {
    /// Fixed value
    Constant(S),

    /// Value controlled by a modulator block
    Modulated(BlockId),
}
}

Usage in Blocks

Blocks store parameters as Parameter<S>:

#![allow(unused)]
fn main() {
pub struct OscillatorBlock<S: Sample> {
    frequency: Parameter<S>,
    waveform: Waveform,
    phase: S,
}
}

Resolving Values

During processing, resolve the actual value:

#![allow(unused)]
fn main() {
impl<S: Sample> OscillatorBlock<S> {
    fn get_frequency(&self, modulation: &[S]) -> S {
        match &self.frequency {
            Parameter::Constant(value) => *value,
            Parameter::Modulated(block_id) => {
                let base = S::from_f64(440.0);
                let mod_value = modulation[block_id.0];
                base * (S::ONE + mod_value * S::from_f64(0.1))  // ±10%
            }
        }
    }
}
}

Constant vs Modulated

Constant

  • Value known at creation
  • No per-block overhead
  • Simple and direct
#![allow(unused)]
fn main() {
let gain = Parameter::Constant(S::from_f64(-6.0));
}

Modulated

  • Value changes each buffer
  • Requires modulator block
  • Adds routing complexity
#![allow(unused)]
fn main() {
let frequency = Parameter::Modulated(lfo_block_id);
}

Design Rationale

The Parameter enum:

  1. Unifies constant and dynamic - Same API for both
  2. Type-safe modulation - Compile-time block ID checking
  3. Zero-cost constant - No indirection for constant values
  4. Sample-type generic - Works with f32 and f64