From 525c8d8c1b55a07626a64d069e3d1ae655364d70 Mon Sep 17 00:00:00 2001 From: Weird Constructor Date: Sun, 8 Aug 2021 00:12:02 +0200 Subject: [PATCH] Fixed more bugs in the Dattorro reverb (delay time interpretation in DelayBuffer) --- src/dsp/dattorro.rs | 19 +++++++++++++++++++ src/dsp/helpers.rs | 20 ++++++++++---------- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/src/dsp/dattorro.rs b/src/dsp/dattorro.rs index 4a44d8d..dd67a7a 100644 --- a/src/dsp/dattorro.rs +++ b/src/dsp/dattorro.rs @@ -102,6 +102,8 @@ pub struct DattorroReverb { left_sum: f32, right_sum: f32, + + dbg_count: usize, } pub trait DattorroReverbParams { @@ -158,6 +160,8 @@ impl DattorroReverb { left_sum: 0.0, right_sum: 0.0, + + dbg_count: 0, }; this.reset(); @@ -403,6 +407,19 @@ impl DattorroReverb { let left = self.apf2[0].0.next(left_apf2_delay_ms, self.apf2[0].2, left); let left = self.delay2[0].0.next_cubic(self.delay2[0].1, left); + if self.dbg_count % 48 == 0 { + println!("APFS dcy={:8.6}; {:8.6} {:8.6} {:8.6} {:8.6}", + decay, + left_apf1_delay_ms, right_apf1_delay_ms, + left_apf2_delay_ms, right_apf2_delay_ms); + println!("DELY1/2 {:8.6} / {:8.6} | {:8.6} / {:8.6}", + self.delay1[0].1, + self.delay2[0].1, + self.delay1[1].1, + self.delay2[1].1); + } + + // Right Sum => APF1 => Delay1 => LPF => HPF => APF2 => Delay2 // And then send this over to the left sum. let right = self.right_sum; @@ -439,6 +456,8 @@ impl DattorroReverb { let left_out = self.out_dc_block[0].next(left_accum); let right_out = self.out_dc_block[1].next(right_accum); + self.dbg_count += 1; + // (left_out * 0.5, right_out * 0.5) (left_out * 0.5, right_out * 0.5) } diff --git a/src/dsp/helpers.rs b/src/dsp/helpers.rs index 16d9e61..93fc1bb 100644 --- a/src/dsp/helpers.rs +++ b/src/dsp/helpers.rs @@ -821,9 +821,9 @@ impl DelayBuffer { } #[inline] - pub fn nearest_at(&self, delay_time: f32) -> f32 { + pub fn nearest_at(&self, delay_time_ms: f32) -> f32 { let len = self.data.len(); - let offs = (delay_time * self.srate).floor() as usize % len; + let offs = ((delay_time_ms * self.srate) / 1000.0).floor() as usize % len; let idx = ((self.wr + len) - offs) % len; self.data[idx] } @@ -860,13 +860,13 @@ impl AllPass { } #[inline] - pub fn delay_tap_n(&self, time: f32) -> f32 { - self.delay.tap_n(time) + pub fn delay_tap_n(&self, time_ms: f32) -> f32 { + self.delay.tap_n(time_ms) } #[inline] - pub fn next(&mut self, time: f32, g: f32, v: f32) -> f32 { - let s = self.delay.cubic_interpolate_at(time); + pub fn next(&mut self, time_ms: f32, g: f32, v: f32) -> f32 { + let s = self.delay.linear_interpolate_at(time_ms); let input = v + -g * s; self.delay.feed(input); input * g + s @@ -894,13 +894,13 @@ impl Comb { } #[inline] - pub fn delay_tap_c(&self, time: f32) -> f32 { - self.delay.tap_c(time) + pub fn delay_tap_c(&self, time_ms: f32) -> f32 { + self.delay.tap_c(time_ms) } #[inline] - pub fn delay_tap_n(&self, time: f32) -> f32 { - self.delay.tap_n(time) + pub fn delay_tap_n(&self, time_ms: f32) -> f32 { + self.delay.tap_n(time_ms) } #[inline]