From b1bd3020fa075af2f441e827c7be09ce2a7c4db9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Tue, 28 Sep 2021 13:53:21 +0300 Subject: [PATCH] audioloudnorm: Clamp to the expected limits instead of asserting The calculations on the floating point numbers can't get out of the expected range by construction expect for rounding errors at the limits. Rounding errors at the limits shouldn't lead to assertions, so instead clamp to the limits. --- audio/audiofx/src/audioloudnorm/imp.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/audio/audiofx/src/audioloudnorm/imp.rs b/audio/audiofx/src/audioloudnorm/imp.rs index 429f64ed..829258dd 100644 --- a/audio/audiofx/src/audioloudnorm/imp.rs +++ b/audio/audiofx/src/audioloudnorm/imp.rs @@ -1028,7 +1028,7 @@ impl State { // Calculate at which point we would reach the new gain reduction // relative to 0.0 == attack window start, 1.0 attack window end. let new_end = (gain_reduction - self.gain_reduction[0]) / old_slope; - assert!(new_end >= 1.0); + let new_end = f64::max(new_end, 1.0); // New start of the window, this will be in the past let new_start = new_end - 1.0; @@ -1049,7 +1049,7 @@ impl State { // Calculate the current position in the attack window let cur_pos = (current_gain_reduction - self.gain_reduction[0]) / old_slope; - assert!((0.0..=1.0).contains(&cur_pos)); + let cur_pos = f64::clamp(cur_pos, 0.0, 1.0); self.env_cnt = ((LIMITER_ATTACK_WINDOW as f64 - 1.0) * cur_pos) as usize; // Need to sustain in any case for this many samples to actually