From 88cc58600cbe0e96eec16f31117608b9816c14df Mon Sep 17 00:00:00 2001 From: Hyunjin Song Date: Sat, 12 Aug 2017 10:16:34 +0900 Subject: [PATCH] Fix producing of NaN from Env/LFO parameter change while playing (#3761) Guarantee thread safety to ensure fillLevel() not to read value from wrong buffer address. --- include/EnvelopeAndLfoParameters.h | 1 + src/core/EnvelopeAndLfoParameters.cpp | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/include/EnvelopeAndLfoParameters.h b/include/EnvelopeAndLfoParameters.h index 4bafbde4b..747bb94c2 100644 --- a/include/EnvelopeAndLfoParameters.h +++ b/include/EnvelopeAndLfoParameters.h @@ -121,6 +121,7 @@ private: static LfoInstances * s_lfoInstances; bool m_used; + QMutex m_paramMutex; FloatModel m_predelayModel; FloatModel m_attackModel; diff --git a/src/core/EnvelopeAndLfoParameters.cpp b/src/core/EnvelopeAndLfoParameters.cpp index d044f98f3..d1fbaeb03 100644 --- a/src/core/EnvelopeAndLfoParameters.cpp +++ b/src/core/EnvelopeAndLfoParameters.cpp @@ -291,6 +291,8 @@ void EnvelopeAndLfoParameters::fillLevel( float * _buf, f_cnt_t _frame, const f_cnt_t _release_begin, const fpp_t _frames ) { + QMutexLocker m(&m_paramMutex); + if( _frame < 0 || _release_begin < 0 ) { return; @@ -402,6 +404,8 @@ void EnvelopeAndLfoParameters::loadSettings( const QDomElement & _this ) void EnvelopeAndLfoParameters::updateSampleVars() { + QMutexLocker m(&m_paramMutex); + const float frames_per_env_seg = SECS_PER_ENV_SEGMENT * Engine::mixer()->processingSampleRate(); // TODO: Remove the expKnobVals, time should be linear