macro_rules! parameterized_algorithm {
(
$(#[$struct_meta:meta])*
$vis:vis struct $name:ident<$($generic:ident: $bound:path),+> {
params: {
$(
$(#[$param_meta:meta])*
$param_name:ident : $param_type:ty = $param_default:expr
),* $(,)?
},
state: {
$(
$(#[$state_meta:meta])*
$state_name:ident : $state_type:ty = $state_default:expr
),* $(,)?
},
update: $update:expr,
process: $process:expr
}
) => { ... };
}Expand description
Macro for creating a parameterized algorithm
ยงExample
use rill_core_dsp::parameterized_algorithm;
use rill_core::math::Transcendental;
parameterized_algorithm! {
/// Filter with variable cutoff frequency
#[derive(Debug, Clone, Copy)]
pub struct LowPass<T: Transcendental> {
params: {
/// Cutoff frequency in Hz
cutoff: T = T::from_f32(1000.0),
/// Quality factor
q: T = T::from_f32(0.707),
},
state: {
/// Internal filter state
y1: T = T::ZERO,
y2: T = T::ZERO,
},
update: |this| {
// Update coefficients when parameters change
},
process: |this, input| {
// Process with current parameters
input
}
}
}