diff --git a/plugins/channelrx/demodatv/atvdemod.cpp b/plugins/channelrx/demodatv/atvdemod.cpp index 8c3cda96e..d276762aa 100644 --- a/plugins/channelrx/demodatv/atvdemod.cpp +++ b/plugins/channelrx/demodatv/atvdemod.cpp @@ -59,6 +59,8 @@ ATVDemod::ATVDemod() : m_blnInitialized=false; m_intNumberOfRowsToDisplay=0; + m_objMagSqAverage.resize(16, 1.0); + memset((void*)m_fltBufferI,0,6*sizeof(float)); memset((void*)m_fltBufferQ,0,6*sizeof(float)); @@ -239,9 +241,12 @@ void ATVDemod::feed(const SampleVector::const_iterator& begin, const SampleVecto //********** demodulation ********** - fltNorm = sqrt(fltI*fltI + fltQ*fltQ); + double magSq = fltI*fltI + fltQ*fltQ; + m_objMagSqAverage.feed(magSq); - if(m_enmModulation!=ATV_AM) + fltNorm = sqrt(magSq); + + if ((m_enmModulation == ATV_FM1) || (m_enmModulation == ATV_FM2)) { //Amplitude FM @@ -290,7 +295,7 @@ void ATVDemod::feed(const SampleVector::const_iterator& begin, const SampleVecto m_fltBufferQ[0]=fltNormQ; } - else + else if (m_enmModulation == ATV_AM) { //Amplitude AM fltVal = fltNorm; @@ -311,6 +316,10 @@ void ATVDemod::feed(const SampleVector::const_iterator& begin, const SampleVecto fltVal -= m_fltAmpMin; fltVal /=m_fltAmpDelta; } + else + { + fltVal = 0.0f; + } m_fltAmpLineAverage += fltVal; diff --git a/plugins/channelrx/demodatv/atvdemod.h b/plugins/channelrx/demodatv/atvdemod.h index 9bd4c1e0b..3d4538cb2 100644 --- a/plugins/channelrx/demodatv/atvdemod.h +++ b/plugins/channelrx/demodatv/atvdemod.h @@ -101,6 +101,7 @@ public: bool blnHSync, bool blnVSync); int GetSampleRate(); + double getMagSq() const { return m_objMagSqAverage.average(); } //!< Beware this is scaled to 2^30 private: @@ -144,6 +145,10 @@ private: int m_intColIndex; int m_intRowIndex; + //*************** RF *************** + + MovingAverage m_objMagSqAverage; + //QElapsedTimer m_objTimer; private: diff --git a/plugins/channelrx/demodatv/atvdemodgui.cpp b/plugins/channelrx/demodatv/atvdemodgui.cpp index 80e71e705..5035b0b8d 100644 --- a/plugins/channelrx/demodatv/atvdemodgui.cpp +++ b/plugins/channelrx/demodatv/atvdemodgui.cpp @@ -181,6 +181,7 @@ void ATVDemodGUI::viewChanged() void ATVDemodGUI::channelSampleRateChanged() { qDebug("ATVDemodGUI::channelSampleRateChanged"); + ui->channelSampleRateText->setText(tr("%1k").arg(m_objChannelizer->getInputSampleRate()/1000.0f, 0, 'f', 0)); applySettings(); } @@ -207,7 +208,8 @@ ATVDemodGUI::ATVDemodGUI(PluginAPI* objPluginAPI, DeviceSourceAPI *objDeviceAPI, m_objDeviceAPI(objDeviceAPI), m_objChannelMarker(this), m_blnBasicSettingsShown(false), - m_blnDoApplySettings(true) + m_blnDoApplySettings(true), + m_intTickCount(0) { ui->setupUi(this); setAttribute(Qt::WA_DeleteOnClose, true); @@ -221,7 +223,7 @@ ATVDemodGUI::ATVDemodGUI(PluginAPI* objPluginAPI, DeviceSourceAPI *objDeviceAPI, m_objThreadedChannelizer = new ThreadedBasebandSampleSink(m_objChannelizer, this); m_objDeviceAPI->addThreadedSink(m_objThreadedChannelizer); - //connect(&m_objPluginAPI->getMainWindow()->getMasterTimer(), SIGNAL(timeout()), this, SLOT(tick())); // 50 ms + connect(&m_objPluginAPI->getMainWindow()->getMasterTimer(), SIGNAL(timeout()), this, SLOT(tick())); // 50 ms ui->deltaFrequency->setColorMapper(ColorMapper(ColorMapper::ReverseGold)); ui->deltaFrequency->setValueRange(7, 0U, 9999999U); @@ -332,6 +334,21 @@ void ATVDemodGUI::enterEvent(QEvent*) void ATVDemodGUI::tick() { + if (m_intTickCount < 10) // ~500 ms + { + m_intTickCount++; + } + else + { + if (m_objATVDemod) + { + double magSqDB = CalcDb::dbPower(m_objATVDemod->getMagSq() / (1<<30)); + ui->channePowerText->setText(tr("%1 dB").arg(magSqDB, 0, 'f', 1)); + } + + m_intTickCount = 0; + } + return; } diff --git a/plugins/channelrx/demodatv/atvdemodgui.h b/plugins/channelrx/demodatv/atvdemodgui.h index 4dd09d19f..fbd6a7bde 100644 --- a/plugins/channelrx/demodatv/atvdemodgui.h +++ b/plugins/channelrx/demodatv/atvdemodgui.h @@ -85,6 +85,8 @@ private: bool m_blnBasicSettingsShown; bool m_blnDoApplySettings; + int m_intTickCount; + explicit ATVDemodGUI(PluginAPI* objPluginAPI, DeviceSourceAPI *objDeviceAPI, QWidget* objParent = NULL); virtual ~ATVDemodGUI();