22#include " Utils.h"
33
44#include < sstream>
5+ #include < string>
56
67#include " DspHost.h"
78#include " EventArgs.h"
@@ -17,6 +18,7 @@ extern "C" {
1718#include < QDebug>
1819#include < cstring>
1920#include < assert.h>
21+ #include < QTimer>
2022
2123/* C interop */
2224inline JamesDSPLib* cast (void * raw){
@@ -50,7 +52,7 @@ inline void* GetStringForIndex(eel_string_context_state *st, float val, int32_t
5052 return (void *)&st->m_literal_strings [idx];
5153}
5254
53- DspHost::DspHost (void * dspPtr, MessageHandlerFunc&& extraHandler) : _extraFunc(std::move(extraHandler))
55+ DspHost::DspHost (void * dspPtr, MessageHandlerFunc&& extraHandler) : _extraFunc(std::move(extraHandler)), _stereoWideDebounce( new QTimer())
5456{
5557 auto dsp = static_cast <JamesDSPLib*>(dspPtr);
5658 if (!dsp)
@@ -68,10 +70,23 @@ DspHost::DspHost(void* dspPtr, MessageHandlerFunc&& extraHandler) : _extraFunc(s
6870
6971 _dsp = dsp;
7072 _cache = new DspConfig ();
73+
74+
75+ /* Workaround: calling StereoEnhancementSetParam while processing has a small chance of causing a crash inside analysisWarpedPFBStereo
76+ * due to the possiblity that snh->subband[x] is accessed before initWarpedPFB or assignPtrWarpedPFB is called by StereoEnhancementSetParam
77+ -> pausing processing not easily doable (in time); reduce strain on StereoEnhancementSetParam instead */
78+ /* TODO: replace workaround with proper patch */
79+ _stereoWideDebounce->setInterval (750 );
80+ _stereoWideDebounce->setSingleShot (true );
81+ QObject::connect (_stereoWideDebounce, &QTimer::timeout, [this ]{
82+ util::debug (" -> Timer finished!" );
83+ StereoEnhancementSetParam (cast (this ->_dsp ), _cache->get <float >(DspConfig::stereowide_level) / 100 .0f );
84+ });
7185}
7286
7387DspHost::~DspHost ()
7488{
89+ _stereoWideDebounce->deleteLater ();
7590 setStdOutHandler (NULL , NULL );
7691}
7792
@@ -582,9 +597,28 @@ bool DspHost::update(DspConfig *config, bool ignoreCache)
582597 else
583598 StereoEnhancementDisable (cast (this ->_dsp ));
584599 break ;
585- case DspConfig::stereowide_level:
586- StereoEnhancementSetParam (cast (this ->_dsp ), current.toFloat () / 100 .0f );
600+ case DspConfig::stereowide_level: {
601+ _stereoWideClock.tock ();
602+ auto duration = _stereoWideClock.duration ();
603+ _stereoWideClock.tick ();
604+ util::debug (std::to_string (duration.count ()));
605+
606+ if (duration.count () > 750 && !_stereoWideDebounce->isActive ())
607+ {
608+ util::debug (" StereoEnhancementSetParam" );
609+ StereoEnhancementSetParam (cast (this ->_dsp ), _cache->get <float >(DspConfig::stereowide_level) / 100 .0f );
610+ }
611+ else if (!_stereoWideDebounce->isActive ())
612+ {
613+ util::debug (" Timer start!" );
614+ _stereoWideDebounce->start ();
615+ }
616+ else
617+ {
618+ util::debug (" Timer already running!" );
619+ }
587620 break ;
621+ }
588622 case DspConfig::tone_enable:
589623 if (current.toBool ())
590624 FIREqualizerEnable (cast (this ->_dsp ));
0 commit comments