From bbd3b58a959c0739815533ff96cb7546c8f43b5c Mon Sep 17 00:00:00 2001 From: Bart Brouns Date: Mon, 23 Dec 2024 11:23:08 +0100 Subject: [PATCH] wip use svf as main filter --- src/delay_tap.rs | 2 ++ src/lib.rs | 12 ++++++++++-- src/svf_simper.rs | 19 +++++++++++-------- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/src/delay_tap.rs b/src/delay_tap.rs index 5bdad17..a0110af 100644 --- a/src/delay_tap.rs +++ b/src/delay_tap.rs @@ -14,6 +14,7 @@ pub struct DelayTap { pub filter_params: Arc, pub ladders: LadderFilter, + pub lowpass: SVFSimper<4>, pub shelving_eq: SVFSimper<4>, pub mute_in_delayed: Box<[bool]>, /// Fades between 0 and 1 with timings based on the global attack and release settings. @@ -57,6 +58,7 @@ impl DelayTap { delayed_audio_r: vec![0.0; MAX_BLOCK_SIZE].into_boxed_slice(), filter_params: filter_params.clone(), ladders: LadderFilter::new(filter_params), + lowpass: SVFSimper::new(440.0, 0.5, 48000.0), shelving_eq: SVFSimper::new(PANNER_EQ_FREQ, PANNER_EQ_RES, 48000.0), mute_in_delayed: vec![false; MAX_BLOCK_SIZE].into_boxed_slice(), amp_envelope: Smoother::new(SmoothingStyle::Linear(13.0)), diff --git a/src/lib.rs b/src/lib.rs index 879a01e..8f259c8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -639,6 +639,7 @@ impl Plugin for Del2 { // Initialize filter parameters for each tap self.initialize_filter_parameters(); for delay_tap in &mut self.delay_taps { + delay_tap.lowpass.reset(440.0, 0.5, sample_rate); delay_tap .shelving_eq .reset(PANNER_EQ_FREQ, PANNER_EQ_RES, sample_rate); @@ -655,7 +656,6 @@ impl Plugin for Del2 { delay_tap.amp_envelope.reset(0.0); delay_tap.ladders.s = [f32x4::splat(0.); 4]; }); - self.drive_main_smoother.reset(0.0); // then fill the array for tap_index in 0..tap_counter { @@ -956,6 +956,12 @@ impl Plugin for Del2 { + value_idx as f32, ) * pre_filter_gain; } + + // TODO: smooth + let cutoff = taps_params.cutoff_main.value(); + let res = taps_params.res_main.value(); + delay_tap.lowpass.set(cutoff, res * 2.0); + // HQ mode: for i in block_start..block_end { let frame = f32x4::from_array([ @@ -972,8 +978,10 @@ impl Plugin for Del2 { 0.0, ]); - let frame_filtered = *delay_tap.ladders.tick_pivotal(frame).as_array(); + // let frame_filtered = *delay_tap.ladders.tick_pivotal(frame).as_array(); // let frame_filtered = *delay_tap.ladders.tick_linear(frame).as_array(); + let frame_filtered = delay_tap.lowpass.lowpass(frame); + // let frame_filtered = delay_tap.lowpass.bandpass(frame); let frame_out = delay_tap .shelving_eq .highshelf_cheap(frame_filtered.into(), gain_values); diff --git a/src/svf_simper.rs b/src/svf_simper.rs index 1e82641..60fdac1 100644 --- a/src/svf_simper.rs +++ b/src/svf_simper.rs @@ -94,7 +94,9 @@ where #[inline] fn compute_parameters(cutoff: f32, resonance: f32, pi_over_sr: f32) -> (f32, f32, f32, f32) { let g = (cutoff * pi_over_sr).tan(); - let k = 2.0 * (1.0 - resonance.clamp(0.0, 1.0)); + // let k = 2.0 * (1.0 - resonance.clamp(0.0, 1.0)); + // let k = (2.0 * (1.0 - resonance)).min(2.0); + let k = 2.0 * (1.0 - resonance); let a1 = g.mul_add(g + k, 1.0).recip(); let a2 = g * a1; let a3 = g * a2; @@ -108,9 +110,8 @@ where #[inline] pub fn fast_tanh(v: Simd) -> Simd { let square = v * v; // Element-wise squaring - v * (Simd::splat(25.95) + square) - / (Simd::splat(26.369) + Simd::splat(8.78) * square) - .simd_clamp(Simd::splat(-1.0), Simd::splat(1.0)) + (v * (Simd::splat(25.95) + square) / (Simd::splat(26.369) + Simd::splat(8.78) * square)) + .simd_clamp(Simd::splat(-1.0), Simd::splat(1.0)) } // quickerTanh / quickerTanh64 credits to mopo synthesis library: @@ -126,11 +127,13 @@ where #[inline] fn process(&mut self, v0: Simd) -> (Simd, Simd) { let v3 = v0 - self.ic2eq; - let v1 = Self::fast_tanh((self.a1 * self.ic1eq) + (self.a2 * v3)); + let v1 = (self.a1 * self.ic1eq) + (self.a2 * v3); let v2 = self.ic2eq + (self.a2 * self.ic1eq) + (self.a3 * v3); - self.ic1eq = (Simd::splat(2.0) * v1) - self.ic1eq; - self.ic2eq = (Simd::splat(2.0) * v2) - self.ic2eq; + // self.ic1eq = (Simd::splat(2.0) * v1) - self.ic1eq; + self.ic1eq = Self::fast_tanh((Simd::splat(2.0) * v1) - self.ic1eq); + // self.ic2eq = (Simd::splat(2.0) * v2) - self.ic2eq; + self.ic2eq = Self::fast_tanh((Simd::splat(2.0) * v2) - self.ic2eq); (v1, v2) } @@ -190,7 +193,7 @@ where v0: Simd, lin_gain: Simd, ) -> Simd { - let (v1, v2) = self.process(v0); + let (_, v2) = self.process(v0); lin_gain.mul_add(v2, v0 - v2) } #[inline]