use super::*;
#[derive(Clone, Copy, Default)]
pub(super) struct BodyFilter {
pub(super) bands: [[Svf; BODY_BANDS]; 2],
pub(super) shift: Option<u32>,
}
pub(super) const BODY_BANDS: usize = 5;
pub(super) const BODY_HZ: [f32; BODY_BANDS] = [275.0, 460.0, 540.0, 1100.0, 2900.0];
pub(super) const BODY_K: [f32; BODY_BANDS] = [0.18, 0.1, 0.1, 0.6, 0.9];
pub(super) const BODY_GAIN: [f32; BODY_BANDS] = [0.7, 1.0, 0.9, 0.35, 0.8];
pub(super) const BODY_DRY: f32 = 0.3;
pub(super) const BODY_MAKEUP: f32 = 1.3;
impl BodyFilter {
pub(super) fn process(
&mut self,
l: f32,
r: f32,
amount: f32,
shift: u32,
sr: f32,
) -> (f32, f32) {
if self.shift != Some(shift) {
let k = m::exp2((shift as f32 - 24.0) / 12.0);
for side in &mut self.bands {
for ((f, &hz), &q) in side.iter_mut().zip(&BODY_HZ).zip(&BODY_K) {
f.set(hz * k, q, sr);
}
}
self.shift = Some(shift);
}
let mut out = [l, r];
for (x, side) in out.iter_mut().zip(&mut self.bands) {
let mut y = *x * BODY_DRY;
for ((f, &q), &g) in side.iter_mut().zip(&BODY_K).zip(&BODY_GAIN) {
y += f.process(*x).bp * q * g;
}
*x = *x * (1.0 - amount) + y * BODY_MAKEUP * amount;
}
(out[0], out[1])
}
pub(super) fn clear(&mut self) {
for f in self.bands.iter_mut().flatten() {
f.clear();
}
}
}
#[derive(Clone, Copy)]
pub(super) struct BowNoise {
pub(super) noise: Noise,
pub(super) hiss: Svf,
pub(super) grit: Svf,
pub(super) ready: bool,
}
pub(super) const BOW_HISS_HZ: f32 = 3200.0;
pub(super) const BOW_HISS_K: f32 = 1.2;
pub(super) const BOW_GRIT_HZ: f32 = 900.0;
pub(super) const BOW_GRIT_K: f32 = 1.0;
pub(super) const BOW_HISS_GAIN: f32 = 0.5;
pub(super) const BOW_GRIT_GAIN: f32 = 1.6;
pub(super) const BOW_GRIT_SECS: f32 = 0.04;
impl BowNoise {
pub(super) fn new(seed: u32) -> Self {
BowNoise {
noise: Noise::new(seed),
hiss: Svf::default(),
grit: Svf::default(),
ready: false,
}
}
pub(super) fn next(&mut self, bow: f32, scratch: f32, t: f32, sr: f32) -> f32 {
if !self.ready {
self.hiss.set(BOW_HISS_HZ, BOW_HISS_K, sr);
self.grit.set(BOW_GRIT_HZ, BOW_GRIT_K, sr);
self.ready = true;
}
let n = self.noise.next();
let mut v = 0.0;
if bow > 0.0 {
v += self.hiss.process(n).bp * BOW_HISS_K * BOW_HISS_GAIN * bow;
}
if scratch > 0.0 {
let e = m::exp(-t / BOW_GRIT_SECS);
v += self.grit.process(n).bp * BOW_GRIT_K * BOW_GRIT_GAIN * scratch * e;
}
v
}
}