From c0c0ac7b04b2bf0bab3b24152d6d8eb00b4f5c59 Mon Sep 17 00:00:00 2001 From: Weird Constructor Date: Sun, 8 Aug 2021 21:16:40 +0200 Subject: [PATCH] fixed interpolation in the delay line and switched to nearest for the delays in the dattorro reverb and to cubic inside the modulated all-pass filters. --- src/dsp/dattorro.rs | 8 ++++---- src/dsp/helpers.rs | 20 ++++++++++++++------ 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/dsp/dattorro.rs b/src/dsp/dattorro.rs index 5a2108d..bee1289 100644 --- a/src/dsp/dattorro.rs +++ b/src/dsp/dattorro.rs @@ -399,12 +399,12 @@ impl DattorroReverb { let left = self.left_sum; let left = self.apf1[0].0.next(left_apf1_delay_ms, self.apf1[0].2, left); let left_apf_tap = left; - let left = self.delay1[0].0.next_cubic(self.delay1[0].1, left); + let left = self.delay1[0].0.next_nearest(self.delay1[0].1, left); let left = self.lpf[0].process(left); let left = self.hpf[0].process(left); let left = left * decay; 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); + let left = self.delay2[0].0.next_nearest(self.delay2[0].1, left); // if self.dbg_count % 48 == 0 { // println!("APFS dcy={:8.6}; {:8.6} {:8.6} {:8.6} {:8.6} | {:8.6} {:8.6} {:8.6} {:8.6}", @@ -428,12 +428,12 @@ impl DattorroReverb { let right = self.right_sum; let right = self.apf1[1].0.next(right_apf1_delay_ms, self.apf1[1].2, right); let right_apf_tap = right; - let right = self.delay1[1].0.next_cubic(self.delay1[1].1, right); + let right = self.delay1[1].0.next_nearest(self.delay1[1].1, right); let right = self.lpf[1].process(right); let right = self.hpf[1].process(right); let right = right * decay; let right = self.apf2[1].0.next(right_apf2_delay_ms, self.apf2[1].2, right); - let right = self.delay2[1].0.next_cubic(self.delay2[1].1, right); + let right = self.delay2[1].0.next_nearest(self.delay2[1].1, right); self.right_sum = left * decay; self.left_sum = right * decay; diff --git a/src/dsp/helpers.rs b/src/dsp/helpers.rs index c66236d..e9edcf6 100644 --- a/src/dsp/helpers.rs +++ b/src/dsp/helpers.rs @@ -777,6 +777,14 @@ impl DelayBuffer { res } + /// Combines [DelayBuffer::nearest_at] and [DelayBuffer::feed] + /// into one convenient function. + #[inline] + pub fn next_nearest(&mut self, delay_time_ms: F, input: F) -> F { + let res = self.nearest_at(delay_time_ms); + self.feed(input); + res + } /// Shorthand for [DelayBuffer::cubic_interpolate_at]. #[inline] @@ -807,8 +815,8 @@ impl DelayBuffer { let fract = s_offs.fract(); let i = (self.wr + len) - offs; - let x0 = data[i % len]; - let x1 = data[(i + 1) % len]; + let x0 = data[i % len]; + let x1 = data[(i - 1) % len]; x0 + fract * (x1 - x0) } @@ -833,10 +841,10 @@ impl DelayBuffer { // // For the interpolation code: // MIT License, Copyright (c) 2021 Eric Wood - let xm1 = data[(i - 1) % len]; + let xm1 = data[(i + 1) % len]; let x0 = data[i % len]; - let x1 = data[(i + 1) % len]; - let x2 = data[(i + 2) % len]; + let x1 = data[(i - 1) % len]; + let x2 = data[(i - 2) % len]; let c = (x1 - xm1) * f(0.5); let v = x0 - x1; @@ -897,7 +905,7 @@ impl AllPass { #[inline] pub fn next(&mut self, time_ms: F, g: F, v: F) -> F { - let s = self.delay.linear_interpolate_at(time_ms); + let s = self.delay.cubic_interpolate_at(time_ms); let input = v + -g * s; self.delay.feed(input); input * g + s