From df30662071abcdd96e35e429b8ee311986bd4076 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Thu, 26 May 2022 00:47:41 +0200 Subject: [PATCH] Add an equal power fade to Safety Limiter --- plugins/safety_limiter/src/lib.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/plugins/safety_limiter/src/lib.rs b/plugins/safety_limiter/src/lib.rs index 85145ca6..29ae9192 100644 --- a/plugins/safety_limiter/src/lib.rs +++ b/plugins/safety_limiter/src/lib.rs @@ -174,7 +174,8 @@ impl Plugin for SafetyLimiter { self.osc_phase_tau -= std::f32::consts::TAU; } - let original_t = if self.morse_fadeout_samples_current + // We'll do an equal power fade + let original_t_squared = if self.morse_fadeout_samples_current < self.morse_fadeout_samples_start { 0.0 @@ -182,7 +183,8 @@ impl Plugin for SafetyLimiter { (self.morse_fadeout_samples_current - self.morse_fadeout_samples_start) as f32 / (self.morse_fadeout_samples_end - self.morse_fadeout_samples_start) as f32 }; - let morse_t = 1.0 - original_t; + let original_t = original_t_squared.sqrt(); + let morse_t = (1.0 - original_t_squared).sqrt(); for sample in channel_samples { *sample = (sine_wave * morse_t) + (*sample * original_t); }