diff --git a/src/demod/DemodulatorThread.cpp b/src/demod/DemodulatorThread.cpp index 3ea60ca..63414b1 100644 --- a/src/demod/DemodulatorThread.cpp +++ b/src/demod/DemodulatorThread.cpp @@ -13,7 +13,10 @@ #include #endif -DemodulatorThread::DemodulatorThread(DemodulatorInstance *parent) +std::atomic DemodulatorThread::squelchLock(nullptr); +std::mutex DemodulatorThread::squelchLockMutex; + +DemodulatorThread::DemodulatorThread(DemodulatorInstance *parent) : IOThread(), outputBuffers("DemodulatorThreadBuffers"), squelchLevel(-100), signalLevel(-100), signalFloor(-30), signalCeil(30), squelchEnabled(false) { @@ -23,6 +26,10 @@ DemodulatorThread::DemodulatorThread(DemodulatorInstance *parent) } DemodulatorThread::~DemodulatorThread() { + std::lock_guard < std::mutex > lock(squelchLockMutex); + if (squelchLock.load() == demodInstance) { + squelchLock.store(nullptr); + } } void DemodulatorThread::onBindOutput(std::string name, ThreadQueueBase *threadQueue) { @@ -182,16 +189,29 @@ void DemodulatorThread::run() { signalLevel = signalLevel + (currentSignalLevel - signalLevel) * 0.05 * sampleTime * 30.0; } - bool squelched = (squelchEnabled && (signalLevel < squelchLevel)); + bool squelched = (muted.load() || (squelchEnabled && (signalLevel < squelchLevel))); if (squelchEnabled) { if (!squelched && !squelchBreak) { - if (wxGetApp().getSoloMode() && !muted.load()) { - wxGetApp().getDemodMgr().setActiveDemodulator(demodInstance, false); - } - squelchBreak = true; - demodInstance->getVisualCue()->triggerSquelchBreak(120); + if (wxGetApp().getSoloMode()) { + std::lock_guard < std::mutex > lock(squelchLockMutex); + if (squelchLock.load() == nullptr) { + squelchLock.store(demodInstance); + wxGetApp().getDemodMgr().setActiveDemodulator(nullptr); + wxGetApp().getDemodMgr().setActiveDemodulator(demodInstance, false); + squelchBreak = true; + demodInstance->getVisualCue()->triggerSquelchBreak(120); + } + } else { + squelchBreak = true; + demodInstance->getVisualCue()->triggerSquelchBreak(120); + } + } else if (squelched && squelchBreak) { + std::lock_guard < std::mutex > lock(squelchLockMutex); + if (squelchLock.load() == demodInstance) { + squelchLock.store(nullptr); + } squelchBreak = false; } } diff --git a/src/demod/DemodulatorThread.h b/src/demod/DemodulatorThread.h index 6a582b9..5176c72 100644 --- a/src/demod/DemodulatorThread.h +++ b/src/demod/DemodulatorThread.h @@ -51,6 +51,10 @@ protected: std::atomic signalLevel, signalFloor, signalCeil; bool squelchEnabled, squelchBreak; + static std::atomic squelchLock; + static std::mutex squelchLockMutex; + + Modem *cModem = nullptr; ModemKit *cModemKit = nullptr; diff --git a/src/process/SpectrumVisualProcessor.cpp b/src/process/SpectrumVisualProcessor.cpp index 33efcde..ad80374 100644 --- a/src/process/SpectrumVisualProcessor.cpp +++ b/src/process/SpectrumVisualProcessor.cpp @@ -313,7 +313,7 @@ void SpectrumVisualProcessor::process() { } if (!resampler || resampleBw != lastBandwidth || lastInputBandwidth != iqData->sampleRate) { - float As = 120.0f; + float As = 480.0; if (resampler) { msresamp_crcf_destroy(resampler);