From 7b9b120a353a831d262bbf54477b71a72f1c5960 Mon Sep 17 00:00:00 2001 From: Paul Date: Sun, 5 Jan 2020 18:53:45 -0500 Subject: [PATCH] Fix an Init Delay Timing Condition (#1453) Init on Delay with temposync could happen before the global tempo was set when you unstreamed in a DAW. As a result the lag for the time would catch up on the first and only first play leading to glitches. To fix it, detect if setvars(true) (the init condition) is called when temposync hasn't been set yet and defer the initialization if so. The frequency shifter would have the same bug so fix that also. Closes #1444. --- src/common/SurgeStorage.cpp | 2 ++ src/common/dsp/effect/DualDelayEffect.cpp | 12 ++++++++++++ src/common/dsp/effect/FreqshiftEffect.cpp | 14 ++++++++++++++ src/common/dsp/effect/effect_defs.h | 2 ++ 4 files changed, 30 insertions(+) diff --git a/src/common/SurgeStorage.cpp b/src/common/SurgeStorage.cpp index 071263007b1..4943672229d 100644 --- a/src/common/SurgeStorage.cpp +++ b/src/common/SurgeStorage.cpp @@ -109,6 +109,8 @@ SurgeStorage::SurgeStorage(std::string suppliedDataPath) last_key[0] = 60; last_key[1] = 60; temposyncratio = 1.f; + temposyncratio_inv = 0.0f; // Use this as a sentinel (since it was not initialized prior to 1.6.5 this was the value at least win and mac had). #1444 + songpos = 0; for (int i = 0; i < n_customcontrollers; i++) diff --git a/src/common/dsp/effect/DualDelayEffect.cpp b/src/common/dsp/effect/DualDelayEffect.cpp index eb1695f4704..baef177771e 100644 --- a/src/common/dsp/effect/DualDelayEffect.cpp +++ b/src/common/dsp/effect/DualDelayEffect.cpp @@ -29,10 +29,22 @@ void DualDelayEffect::init() lp.suspend(); hp.suspend(); setvars(true); + inithadtempo = true; + // See issue #1444 and the fix for this stuff + if( storage->temposyncratio_inv == 0 ) + { + inithadtempo = false; + } } void DualDelayEffect::setvars(bool init) { + if( ! inithadtempo && storage->temposyncratio_inv != 0 ) + { + init = true; + inithadtempo = true; + } + float fb = amp_to_linear(*f[2]); float cf = amp_to_linear(*f[3]); diff --git a/src/common/dsp/effect/FreqshiftEffect.cpp b/src/common/dsp/effect/FreqshiftEffect.cpp index 787d3e57b3c..b31397f5f26 100644 --- a/src/common/dsp/effect/FreqshiftEffect.cpp +++ b/src/common/dsp/effect/FreqshiftEffect.cpp @@ -35,10 +35,24 @@ void FreqshiftEffect::init() fi.reset(); ringout = 10000000; setvars(true); + + inithadtempo = true; + // See issue #1444 and the fix for this stuff + if( storage->temposyncratio_inv == 0 ) + { + inithadtempo = false; + } + } void FreqshiftEffect::setvars(bool init) { + if( ! inithadtempo && storage->temposyncratio_inv != 0 ) + { + init = true; + inithadtempo = true; + } + feedback.newValue(amp_to_linear(*f[fsp_feedback])); if (init) diff --git a/src/common/dsp/effect/effect_defs.h b/src/common/dsp/effect/effect_defs.h index 68d9696fb9b..bdd0a7ba108 100644 --- a/src/common/dsp/effect/effect_defs.h +++ b/src/common/dsp/effect/effect_defs.h @@ -50,6 +50,7 @@ class DualDelayEffect : public Effect private: lag timeL, timeR; + bool inithadtempo; float envf; int wpos; BiquadFilter lp, hp; @@ -121,6 +122,7 @@ class FreqshiftEffect : public Effect private: lipol feedback; lag time, shiftL, shiftR; + bool inithadtempo; float buffer[2][max_delay_length]; int wpos; // CHalfBandFilter<6> frL,fiL,frR,fiR;