diff --git a/plugins/channeltx/udpsink/udpsink.cpp b/plugins/channeltx/udpsink/udpsink.cpp index 28218aa57..d878c4a9d 100644 --- a/plugins/channeltx/udpsink/udpsink.cpp +++ b/plugins/channeltx/udpsink/udpsink.cpp @@ -26,6 +26,8 @@ UDPSink::UDPSink(MessageQueue* uiMessageQueue, UDPSinkGUI* udpSinkGUI, BasebandS m_uiMessageQueue(uiMessageQueue), m_udpSinkGUI(udpSinkGUI), m_spectrum(spectrum), + m_magsq(1e-10), + m_movingAverage(16, 0), m_settingsMutex(QMutex::Recursive) { setObjectName("UDPSink"); @@ -81,6 +83,11 @@ void UDPSink::pull(Sample& sample) m_settingsMutex.unlock(); + Real magsq = ci.real() * ci.real() + ci.imag() * ci.imag(); + magsq /= (1<<30); + m_movingAverage.feed(magsq); + m_magsq = m_movingAverage.average(); + sample.m_real = (FixReal) ci.real(); sample.m_imag = (FixReal) ci.imag(); } diff --git a/plugins/channeltx/udpsink/udpsink.h b/plugins/channeltx/udpsink/udpsink.h index 50bc3057e..9af96b31b 100644 --- a/plugins/channeltx/udpsink/udpsink.h +++ b/plugins/channeltx/udpsink/udpsink.h @@ -22,6 +22,7 @@ #include "dsp/basebandsamplesource.h" #include "dsp/basebandsamplesink.h" #include "dsp/interpolator.h" +#include "dsp/movingaverage.h" #include "dsp/nco.h" #include "util/message.h" @@ -51,6 +52,8 @@ public: virtual void pull(Sample& sample); virtual bool handleMessage(const Message& cmd); + double getMagSq() const { return m_magsq; } + void configure(MessageQueue* messageQueue, SampleFormat sampleFormat, Real inputSampleRate, @@ -181,6 +184,9 @@ private: Real m_interpolatorDistanceRemain; bool m_interpolatorConsumed; + double m_magsq; + MovingAverage m_movingAverage; + QMutex m_settingsMutex; void apply(bool force); diff --git a/plugins/channeltx/udpsink/udpsinkgui.cpp b/plugins/channeltx/udpsink/udpsinkgui.cpp index a34dbaee6..21861b57a 100644 --- a/plugins/channeltx/udpsink/udpsinkgui.cpp +++ b/plugins/channeltx/udpsink/udpsinkgui.cpp @@ -20,6 +20,7 @@ #include "dsp/spectrumvis.h" #include "dsp/dspengine.h" #include "util/simpleserializer.h" +#include "util/db.h" #include "gui/basicchannelsettingswidget.h" #include "plugin/pluginapi.h" #include "mainwindow.h" @@ -201,6 +202,7 @@ UDPSinkGUI::UDPSinkGUI(PluginAPI* pluginAPI, DeviceSinkAPI *deviceAPI, QWidget* ui(new Ui::UDPSinkGUI), m_pluginAPI(pluginAPI), m_deviceAPI(deviceAPI), + m_channelPowerDbAvg(20,0), m_channelMarker(this), m_basicSettingsShown(false), m_doApplySettings(true) @@ -472,3 +474,10 @@ void UDPSinkGUI::enterEvent(QEvent*) blockApplySettings(false); } +void UDPSinkGUI::tick() +{ + double powDb = CalcDb::dbPower(m_udpSink->getMagSq()); + m_channelPowerDbAvg.feed(powDb); + ui->channelPower->setText(tr("%1 dB").arg(m_channelPowerDbAvg.average(), 0, 'f', 1)); +} + diff --git a/plugins/channeltx/udpsink/udpsinkgui.h b/plugins/channeltx/udpsink/udpsinkgui.h index 596ca6ce7..a564b8964 100644 --- a/plugins/channeltx/udpsink/udpsinkgui.h +++ b/plugins/channeltx/udpsink/udpsinkgui.h @@ -69,6 +69,7 @@ private slots: void onMenuDoubleClicked(); void on_volume_valueChanged(int value); void on_channelMute_toggled(bool checked); + void tick(); private: Ui::UDPSinkGUI* ui; @@ -78,6 +79,7 @@ private: UpChannelizer* m_channelizer; SpectrumVis* m_spectrumVis; UDPSink* m_udpSink; + MovingAverage m_channelPowerDbAvg; ChannelMarker m_channelMarker; // settings