macro_rules! simple_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
),* $(,)?
},
process: $process:expr
}
) => { ... };
}Expand description
Макрос для создания простого алгоритма без параметров
§Пример
use rill_core_dsp::simple_algorithm;
use rill_core::math::Transcendental;
simple_algorithm! {
/// Простой усилитель
#[derive(Debug, Clone, Copy)]
pub struct Gain<T: Transcendental> {
params: {
/// Коэффициент усиления
gain: T = T::from_f32(1.0),
},
state: {
/// Последнее значение (для статистики)
last_output: T = T::ZERO,
},
process: |this, input| {
let output = input * this.gain;
this.last_output = output;
output
}
}
}