From 8fbdc43ce3562013deeb6f80c9828e093c42db76 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Fri, 22 Jul 2022 23:22:39 +0200 Subject: [PATCH] Fix the high frequency rolloff --- .../spectral_compressor/src/compressor_bank.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/plugins/spectral_compressor/src/compressor_bank.rs b/plugins/spectral_compressor/src/compressor_bank.rs index 50480e7d..e3a92d79 100644 --- a/plugins/spectral_compressor/src/compressor_bank.rs +++ b/plugins/spectral_compressor/src/compressor_bank.rs @@ -557,7 +557,7 @@ impl CompressorBank { // If the high-frequency rolloff is enabled then higher frequency bins will have their // ratios reduced to reduce harshness. This follows the octave scale. let target_ratio_recip = compressor.downwards_ratio.value.recip(); - if high_freq_ratio_rolloff == 1.0 { + if high_freq_ratio_rolloff == 0.0 { self.downwards_ratio_recips.fill(target_ratio_recip); } else { for (log2_freq, ratio) in self @@ -565,11 +565,11 @@ impl CompressorBank { .iter() .zip(self.downwards_ratio_recips.iter_mut()) { - // This is scaled by octaves since we're calculating this in log space let octave_fraction = log2_freq / log2_nyquist_freq; - // Division because we're dealing with the reciprocal here - *ratio = - target_ratio_recip / (1.0 - (octave_fraction * high_freq_ratio_rolloff)); + let rolloff_t = octave_fraction * high_freq_ratio_rolloff; + // If the octave fraction times the rolloff amount is high, then this should get + // closer to `high_freq_ratio_rolloff` (which is in [0, 1]). + *ratio = (target_ratio_recip * (1.0 - rolloff_t)) + rolloff_t; } } } @@ -580,7 +580,7 @@ impl CompressorBank { .is_ok() { let target_ratio_recip = compressor.upwards_ratio.value.recip(); - if high_freq_ratio_rolloff == 1.0 { + if high_freq_ratio_rolloff == 0.0 { self.upwards_ratio_recips.fill(target_ratio_recip); } else { for (log2_freq, ratio) in self @@ -589,8 +589,8 @@ impl CompressorBank { .zip(self.upwards_ratio_recips.iter_mut()) { let octave_fraction = log2_freq / log2_nyquist_freq; - *ratio = - target_ratio_recip / (1.0 - (octave_fraction * high_freq_ratio_rolloff)); + let rolloff_t = octave_fraction * high_freq_ratio_rolloff; + *ratio = (target_ratio_recip * (1.0 - rolloff_t)) + rolloff_t; } } }