use crate::synth::va::dsp::Svf;
use crate::synth::va::engine::{cutoff_hz, param};
use crate::synth::va::fx::{Effect, Params};
pub(crate) struct ImagerFx {
side_hp: Svf,
width: f32,
mono: bool,
on: bool,
}
impl ImagerFx {
pub(crate) fn new() -> Self {
ImagerFx {
side_hp: Svf::default(),
width: 1.0,
mono: false,
on: false,
}
}
}
impl Effect for ImagerFx {
fn update(&mut self, p: &Params<'_>, sample_rate: f32) -> bool {
let img = p.get_hi(param::IMG);
let mono = p.get_hi(param::IMG_MONO);
if img == 100.0 && mono <= 0.0 && !self.on {
return false;
}
self.on = true;
self.width = img / 100.0;
self.mono = mono > 0.0;
if self.mono {
self.side_hp
.set(cutoff_hz(mono), core::f32::consts::SQRT_2, sample_rate);
}
true
}
fn process(&mut self, x: [f32; 2], _sample_rate: f32) -> [f32; 2] {
let mid = (x[0] + x[1]) * 0.5;
let mut side = (x[0] - x[1]) * 0.5;
if self.mono {
side = self.side_hp.process(side).hp;
}
let side = side * self.width;
[mid + side, mid - side]
}
fn clear(&mut self) {
self.side_hp.clear();
self.on = false;
}
}