Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop runaway modulators on extreme changes #6863

Merged
merged 1 commit into from
Mar 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions src/common/ModulationSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#pragma once

#include <random>
#include <cassert>

#include "basic_dsp.h"

enum modsrctype
Expand Down Expand Up @@ -484,8 +486,12 @@ template <int NDX = 1> 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];
}
Expand Down Expand Up @@ -516,11 +522,8 @@ template <int NDX = 1> 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]));
}
}

Expand Down