diff options
author | Sebastian Dröge <sebastian@centricular.com> | 2021-09-28 13:53:21 +0300 |
---|---|---|
committer | Sebastian Dröge <sebastian@centricular.com> | 2021-09-28 13:53:21 +0300 |
commit | b1bd3020fa075af2f441e827c7be09ce2a7c4db9 (patch) | |
tree | 8128c783de5e6a1b6aab9627938b5b7472fbe02a /audio/audiofx | |
parent | 69bb09f7ad1afc12638b23a89d73a9cd61f8a530 (diff) |
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.
Diffstat (limited to 'audio/audiofx')
-rw-r--r-- | audio/audiofx/src/audioloudnorm/imp.rs | 4 |
1 files 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 |