diff --git a/plugins/safety_limiter/CHANGELOG.md b/plugins/safety_limiter/CHANGELOG.md new file mode 100644 index 00000000..e9d6ecbc --- /dev/null +++ b/plugins/safety_limiter/CHANGELOG.md @@ -0,0 +1,16 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic +Versioning](https://semver.org/spec/v2.0.0.html). + +## [Unreleased] + +### Added + +- Safety Limiter now logs occurrences of NaN and infinite values so they're + easier to spot. These values already caused Safety Limiter to engage, but this + makes it very easy to notice that something fishy is going on during + development. diff --git a/plugins/safety_limiter/src/lib.rs b/plugins/safety_limiter/src/lib.rs index 67f70c63..088078d9 100644 --- a/plugins/safety_limiter/src/lib.rs +++ b/plugins/safety_limiter/src/lib.rs @@ -15,6 +15,7 @@ // along with this program. If not, see . use nih_plug::prelude::*; +use nih_plug::util::permit_alloc; use std::sync::Arc; /// After reaching the threshold, it will take this many milliseconds under that threshold to start @@ -206,6 +207,11 @@ impl Plugin for SafetyLimiter { return ProcessStatus::Normal; } + // We'll print this once per buffer to make it obvious something very fishy is going on + // without tanking performance too much + let mut buffer_contains_nan = false; + let mut buffer_contains_inf = false; + let &(morse_seq_len, _) = self.morse_seq_edges_samples.last().unwrap(); for mut channel_samples in buffer.iter_samples() { let mut is_peaking = false; @@ -217,6 +223,14 @@ impl Plugin for SafetyLimiter { // we'll try to mix them back into the signal later *sample = 0.0; is_peaking = true; + + if sample.is_nan() { + buffer_contains_nan = true; + } else if sample.is_infinite() { + buffer_contains_inf = true; + } else { + unreachable!(); + } } } @@ -290,6 +304,13 @@ impl Plugin for SafetyLimiter { } } + if buffer_contains_nan { + permit_alloc(|| nih_log!("The buffer contains NaN values")); + } + if buffer_contains_inf { + permit_alloc(|| nih_log!("The buffer contains infinite values")); + } + ProcessStatus::Normal } }