From 70c52a5488254ca81b1266449d9210da59f1b43b Mon Sep 17 00:00:00 2001 From: Bart Brouns Date: Thu, 5 Dec 2024 19:17:09 +0100 Subject: [PATCH] dry the pan gain smoother calcs --- src/lib.rs | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 5b0410c..dcfb438 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -886,25 +886,17 @@ impl Plugin for Del2 { .smoothed_offset_r .set_target(sample_rate, offset_r); - let eq_gain_target_l = util::db_to_gain_fast((MIN_EQ_GAIN * pan).min(0.0)); - delay_tap - .eq_gain_l - .set_target(sample_rate, eq_gain_target_l); - let eq_gain_target_r = - util::db_to_gain_fast((MIN_EQ_GAIN * pan * -1.0).min(0.0)); - delay_tap - .eq_gain_r - .set_target(sample_rate, eq_gain_target_r); - let pan_gain_target_l = - util::db_to_gain_fast((MIN_PAN_GAIN * pan).min(0.0)); - delay_tap - .pan_gain_l - .set_target(sample_rate, pan_gain_target_l); - let pan_gain_target_r = - util::db_to_gain_fast((MIN_PAN_GAIN * pan * -1.0).min(0.0)); - delay_tap - .pan_gain_r - .set_target(sample_rate, pan_gain_target_r); + let calculate_and_set_gain = + |target: &mut Smoother, min_gain: f32, multiplier: f32| { + let gain_value = + util::db_to_gain_fast((min_gain * pan * multiplier).min(0.0)); + target.set_target(sample_rate, gain_value); + }; + + calculate_and_set_gain(&mut delay_tap.eq_gain_l, MIN_EQ_GAIN, 1.0); + calculate_and_set_gain(&mut delay_tap.eq_gain_r, MIN_EQ_GAIN, -1.0); + calculate_and_set_gain(&mut delay_tap.pan_gain_l, MIN_PAN_GAIN, 1.0); + calculate_and_set_gain(&mut delay_tap.pan_gain_r, MIN_PAN_GAIN, -1.0); let delay_time = delay_tap.delay_time as isize; let write_index = self.delay_write_index;