From 70aca67dbdf180aca3f8c24517f4f34dec01e637 Mon Sep 17 00:00:00 2001 From: Paul Date: Sun, 13 Nov 2022 11:21:12 -0500 Subject: [PATCH] Add an optional LFO onepole for FROM_LAST envelope mode (#6699) * Add an optional LFO onepole for FROM_LAST envelope mode In envelope mode with high deform in FROM_LAST mode the signal from the envelope is not continuous. This is basically unsolvable analytically - the deform plus state is too hard - and so leave it on by default but add an optional one pole to smooth it out, which may be useful in some cases. Expose configurations of that to the rack LFO Addresses https://github.com/surge-synthesizer/surge-rack/issues/607 --- src/common/dsp/modulators/LFOModulationSource.cpp | 13 +++++++++++++ src/common/dsp/modulators/LFOModulationSource.h | 4 ++++ 2 files changed, 17 insertions(+) diff --git a/src/common/dsp/modulators/LFOModulationSource.cpp b/src/common/dsp/modulators/LFOModulationSource.cpp index b6437342070..5ed50e76450 100644 --- a/src/common/dsp/modulators/LFOModulationSource.cpp +++ b/src/common/dsp/modulators/LFOModulationSource.cpp @@ -77,6 +77,9 @@ void LFOModulationSource::assign(SurgeStorage *storage, LFOStorage *lfo, pdata * { wf_history[i] = 0.f; } + + for (int i = 0; i < 3; ++i) + onepoleState[i] = 0.f; } float LFOModulationSource::bend1(float x) @@ -1289,6 +1292,16 @@ void LFOModulationSource::process_block() output_multi[1] *= useenvval; output_multi[1] += useenv0; } + + if (envRetrigMode == FROM_LAST && lfo->deform.deform_type != type_3) + { + // Now appy the one pole + float alpha = onepoleFactor; + output_multi[0] = (1.0 - alpha) * output_multi[0] + alpha * onepoleState[0]; + output_multi[1] = (1.0 - alpha) * output_multi[1] + alpha * onepoleState[1]; + onepoleState[0] = output_multi[0]; + onepoleState[1] = output_multi[1]; + } } } diff --git a/src/common/dsp/modulators/LFOModulationSource.h b/src/common/dsp/modulators/LFOModulationSource.h index 92a751e3448..752a0074ce0 100644 --- a/src/common/dsp/modulators/LFOModulationSource.h +++ b/src/common/dsp/modulators/LFOModulationSource.h @@ -111,6 +111,8 @@ class LFOModulationSource : public ModulationSource inline int getEnvState() { return env_state; } inline int getStep() { return step; } + float onepoleFactor{0}; + private: pdata *localcopy; bool phaseInitialized; @@ -128,6 +130,8 @@ class LFOModulationSource : public ModulationSource int step, shuffle_id; int magn, rate, iattack, idecay, idelay, ihold, isustain, irelease, startphase, ideform; + float onepoleState[3]; + std::default_random_engine gen; std::uniform_real_distribution distro; std::function urng;