From d796a7b71246d77e440dcf6fbfd8a014f9e55c6c Mon Sep 17 00:00:00 2001 From: Paul Walker Date: Fri, 3 Mar 2023 07:57:55 -0500 Subject: [PATCH] Stop runaway modulators on extreme changes In extreme (really computer generated) midi sequences you could force the modulator smoother to runaway since in one case it would push you outside of [target,value] when interpolating. Fix that with a clamp; and add an assert in case theres other future problems. Closes #6835 --- src/common/ModulationSource.h | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/common/ModulationSource.h b/src/common/ModulationSource.h index 0ad981ef1c4..a35fb98b036 100644 --- a/src/common/ModulationSource.h +++ b/src/common/ModulationSource.h @@ -16,6 +16,8 @@ #pragma once #include +#include + #include "basic_dsp.h" enum modsrctype @@ -484,8 +486,12 @@ template class ControllerModulationSourceVector : public Modulatio } else { - float a = (mode == Modulator::SmoothingMode::FAST_EXP ? 0.99f : 0.9f) * 44100 * - samplerate_inv * b; + // Don't allow us to push outside of [target,value] + // so clamp the interpolator to 0,1 + float a = + std::clamp((mode == Modulator::SmoothingMode::FAST_EXP ? 0.99f : 0.9f) * + 44100 * samplerate_inv * b, + 0.f, 1.f); value[idx] = (1 - a) * value[idx] + a * target[idx]; } @@ -516,11 +522,8 @@ template class ControllerModulationSourceVector : public Modulatio value[idx] = target[idx]; } - // GitHub issue #6835 - if (std::isinf(value[idx])) - { - value[idx] = 0.f; - } + // Just in case #6835 sneaks back + assert(!std::isnan(value[idx]) && !std::isinf(value[idx])); } }