From aa60d616fe20b58fb6ea3b49e45eaa8b603815d3 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Mon, 13 Jun 2022 18:47:48 +0200 Subject: [PATCH] Handle infinite and NaN values in Safety Limiter --- plugins/safety_limiter/README.md | 3 ++- plugins/safety_limiter/src/lib.rs | 9 ++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/plugins/safety_limiter/README.md b/plugins/safety_limiter/README.md index b4f8a9c0..ab1da11b 100644 --- a/plugins/safety_limiter/README.md +++ b/plugins/safety_limiter/README.md @@ -3,7 +3,8 @@ This plugin is a simple tool to prevent ear damage. As soon as there is a peak above 0 dBFS or the specified threshold, the plugin will cut over to playing SOS in Morse code, gradually fading out again when the input returns back to safe -levels. Made for personal use during plugin development and intense sound design +levels. The same thing happens if the input contains infinite or NaN values. +Made for personal use during plugin development and intense sound design sessions, but maybe you'll find it useful too! **Why not use a regular brickwall peak limiter?** diff --git a/plugins/safety_limiter/src/lib.rs b/plugins/safety_limiter/src/lib.rs index fd59958c..907a568e 100644 --- a/plugins/safety_limiter/src/lib.rs +++ b/plugins/safety_limiter/src/lib.rs @@ -209,7 +209,14 @@ impl Plugin for SafetyLimiter { for mut channel_samples in buffer.iter_samples() { let mut is_peaking = false; for sample in channel_samples.iter_mut() { - is_peaking |= sample.abs() > self.params.threshold_gain.value; + if sample.is_finite() { + is_peaking |= sample.abs() > self.params.threshold_gain.value; + } else { + // Infinity or NaN values need to be completely filtered out, because otherwise + // we'll try to mix them back into the signal later + *sample = 0.0; + is_peaking = true; + } } if is_peaking {