diff --git a/src/AppFrame.cpp b/src/AppFrame.cpp index a0de6c0..3e39091 100644 --- a/src/AppFrame.cpp +++ b/src/AppFrame.cpp @@ -1402,7 +1402,11 @@ void AppFrame::OnIdle(wxIdleEvent& event) { demodWaterfallCanvas->setBandwidth(demodBw); demodSpectrumCanvas->setBandwidth(demodBw); } + demodSignalMeter->setLevel(demod->getSignalLevel()); + demodSignalMeter->setMin(demod->getSignalFloor()); + demodSignalMeter->setMax(demod->getSignalCeil()); + demodGainMeter->setLevel(demod->getGain()); if (demodSignalMeter->inputChanged()) { demod->setSquelchLevel(demodSignalMeter->getInputValue()); diff --git a/src/demod/DemodulatorInstance.cpp b/src/demod/DemodulatorInstance.cpp index c3a22ee..7b770b3 100644 --- a/src/demod/DemodulatorInstance.cpp +++ b/src/demod/DemodulatorInstance.cpp @@ -257,6 +257,14 @@ float DemodulatorInstance::getSignalLevel() { return demodulatorThread->getSignalLevel(); } +float DemodulatorInstance::getSignalFloor() { + return demodulatorThread->getSignalFloor(); +} + +float DemodulatorInstance::getSignalCeil() { + return demodulatorThread->getSignalCeil(); +} + void DemodulatorInstance::setSquelchLevel(float signal_level_in) { demodulatorThread->setSquelchLevel(signal_level_in); wxGetApp().getDemodMgr().setLastSquelchLevel(signal_level_in); diff --git a/src/demod/DemodulatorInstance.h b/src/demod/DemodulatorInstance.h index 07d7c29..554ed48 100644 --- a/src/demod/DemodulatorInstance.h +++ b/src/demod/DemodulatorInstance.h @@ -63,6 +63,8 @@ public: void setSquelchEnabled(bool state); float getSignalLevel(); + float getSignalFloor(); + float getSignalCeil(); void setSquelchLevel(float signal_level_in); float getSquelchLevel(); diff --git a/src/demod/DemodulatorThread.cpp b/src/demod/DemodulatorThread.cpp index fcde477..e7ef7c6 100644 --- a/src/demod/DemodulatorThread.cpp +++ b/src/demod/DemodulatorThread.cpp @@ -15,7 +15,7 @@ DemodulatorThread::DemodulatorThread(DemodulatorInstance *parent) : IOThread(), outputBuffers("DemodulatorThreadBuffers"), squelchLevel(-100), - signalLevel(-100), squelchEnabled(false) { + signalLevel(-100), signalFloor(-30), signalCeil(30), squelchEnabled(false) { demodInstance = parent; muted.store(false); @@ -114,6 +114,33 @@ void DemodulatorThread::run() { currentSignalLevel = DEMOD_SIGNAL_MIN+1; } + float sampleTime = float(inp->data.size()) / float(inp->sampleRate); + float sf = signalFloor.load(), sc = signalCeil.load(), sl = squelchLevel.load(); + + if (currentSignalLevel > sc) { + sc = currentSignalLevel; + } + + if (currentSignalLevel < sf) { + sf = currentSignalLevel; + } + + if (sl+1.0f > sc) { + sc = sl+1.0f; + } + + if ((sf+2.0f) > sc) { + sc = sf+2.0f; + } + + sc -= (sc - (currentSignalLevel + 2.0f)) * sampleTime * 0.15f; + sf += ((currentSignalLevel - 5.0f) - sf) * sampleTime * 0.15f; + + signalFloor.store(sf); + signalCeil.store(sc); + +// std::cout << "sf:" << sf << "sc: " << sc << std::endl; + std::vector *inputData; inputData = &inp->data; @@ -330,6 +357,14 @@ float DemodulatorThread::getSignalLevel() { return signalLevel.load(); } +float DemodulatorThread::getSignalFloor() { + return signalFloor.load(); +} + +float DemodulatorThread::getSignalCeil() { + return signalCeil.load(); +} + void DemodulatorThread::setSquelchLevel(float signal_level_in) { if (!squelchEnabled) { squelchEnabled = true; diff --git a/src/demod/DemodulatorThread.h b/src/demod/DemodulatorThread.h index 0892589..6a582b9 100644 --- a/src/demod/DemodulatorThread.h +++ b/src/demod/DemodulatorThread.h @@ -30,6 +30,8 @@ public: bool isMuted(); float getSignalLevel(); + float getSignalCeil(); + float getSignalFloor(); void setSquelchLevel(float signal_level_in); float getSquelchLevel(); @@ -46,7 +48,7 @@ protected: std::atomic_bool muted; std::atomic squelchLevel; - std::atomic signalLevel; + std::atomic signalLevel, signalFloor, signalCeil; bool squelchEnabled, squelchBreak; Modem *cModem = nullptr;