Clamp the modulated cutoff to reasonable limits

This commit is contained in:
Jean Pierre Cimalando 2020-02-18 05:34:25 +01:00 committed by Paul Ferrand
parent 87347f690f
commit ffe708331b

View file

@ -5,6 +5,7 @@
// If not, contact the sfizz maintainers at https://github.com/sfztools/sfizz
#include "sfizz/SfzFilter.h"
#include "sfizz/MathHelpers.h"
#include "ui_DemoFilters.h"
#include <QApplication>
#include <QMainWindow>
@ -294,7 +295,10 @@ int DemoApp::processAudio(jack_nframes_t nframes, void *cbdata)
for (jack_nframes_t i = 0; i < nframes; ++i) {
float lfo = cutoffMod * triangleLfo(cutoffLfoPhase);
tempCutoff[i] *= std::exp2(lfo * (1.0f / 12.0f));
float modCutoff = tempCutoff[i];
modCutoff *= std::exp2(lfo * (1.0f / 12.0f));
modCutoff = clamp(modCutoff, 0.0f, 20000.0f);
tempCutoff[i] = modCutoff;
cutoffLfoPhase += cutoffRate * sampleTime;
cutoffLfoPhase -= (int)cutoffLfoPhase;
}