From b14647c028e13dda159df3cb22b50125ff47f9c6 Mon Sep 17 00:00:00 2001 From: f4exb Date: Wed, 16 Aug 2017 03:33:05 +0200 Subject: [PATCH] UDPSink plugin: implemented buffer gauge display --- plugins/channeltx/udpsink/udpsink.h | 1 + plugins/channeltx/udpsink/udpsinkgui.cpp | 7 ++ plugins/channeltx/udpsink/udpsinkgui.ui | 103 ++++++++++++++++++ .../channeltx/udpsink/udpsinkudphandler.cpp | 15 ++- plugins/channeltx/udpsink/udpsinkudphandler.h | 13 ++- 5 files changed, 134 insertions(+), 5 deletions(-) diff --git a/plugins/channeltx/udpsink/udpsink.h b/plugins/channeltx/udpsink/udpsink.h index c246bb86a..9fef2ee96 100644 --- a/plugins/channeltx/udpsink/udpsink.h +++ b/plugins/channeltx/udpsink/udpsink.h @@ -55,6 +55,7 @@ public: virtual bool handleMessage(const Message& cmd); double getMagSq() const { return m_magsq; } + int32_t getBufferGauge() const { return m_udpHandler.getBufferGauge(); } void configure(MessageQueue* messageQueue, SampleFormat sampleFormat, diff --git a/plugins/channeltx/udpsink/udpsinkgui.cpp b/plugins/channeltx/udpsink/udpsinkgui.cpp index 512009e5a..fa2f3f160 100644 --- a/plugins/channeltx/udpsink/udpsinkgui.cpp +++ b/plugins/channeltx/udpsink/udpsinkgui.cpp @@ -492,5 +492,12 @@ 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)); + + int32_t bufferGauge = m_udpSink->getBufferGauge(); + ui->bufferGaugeNegative->setValue((bufferGauge < 0 ? -bufferGauge : 0)); + ui->bufferGaugePositive->setValue((bufferGauge < 0 ? 0 : bufferGauge)); + QString s = QString::number(bufferGauge, 'f', 0); + ui->bufferRWBalanceText->setText(tr("%1").arg(s)); + } diff --git a/plugins/channeltx/udpsink/udpsinkgui.ui b/plugins/channeltx/udpsink/udpsinkgui.ui index bd7b3eb2d..368b8ac12 100644 --- a/plugins/channeltx/udpsink/udpsinkgui.ui +++ b/plugins/channeltx/udpsink/udpsinkgui.ui @@ -505,6 +505,109 @@ + + + + + + + 16777215 + 14 + + + + Main buffer read/write positions unbalance: write lags read leads + + + 50 + + + 0 + + + false + + + true + + + %v + + + + + + + + 2 + 14 + + + + . + + + + + + + + 16777215 + 14 + + + + Main buffer read/write positions unbalance: read lags write leads + + + 50 + + + 0 + + + false + + + + + + + + + + + + 22 + 0 + + + + R/W pointers offset from optimal (%) + + + -00 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + diff --git a/plugins/channeltx/udpsink/udpsinkudphandler.cpp b/plugins/channeltx/udpsink/udpsinkudphandler.cpp index 033daeb0d..e1e419217 100644 --- a/plugins/channeltx/udpsink/udpsinkudphandler.cpp +++ b/plugins/channeltx/udpsink/udpsinkudphandler.cpp @@ -27,7 +27,8 @@ UDPSinkUDPHandler::UDPSinkUDPHandler() : m_udpReadBytes(0), m_writeIndex(0), m_readFrameIndex(m_nbUDPFrames/2), - m_readIndex(0) + m_readIndex(0), + m_rwDelta(m_nbUDPFrames/2) { } @@ -126,10 +127,15 @@ void UDPSinkUDPHandler::advanceReadPointer(int nbBytes) { m_readIndex = 0; - if (m_readFrameIndex < m_nbUDPFrames - 1) { + if (m_readFrameIndex < m_nbUDPFrames - 1) + { m_readFrameIndex++; - } else { - qDebug("UDPSinkUDPHandler::advanceReadPointer: w: %02d", m_writeIndex); + } + else + { + m_rwDelta = m_writeIndex; // raw R/W delta estimate + float d = (m_rwDelta - (m_nbUDPFrames/2))/(float) m_nbUDPFrames; + qDebug("UDPSinkUDPHandler::advanceReadPointer: w: %02d d: %f", m_writeIndex, d); m_readFrameIndex = 0; } } @@ -155,5 +161,6 @@ void UDPSinkUDPHandler::configureUDPLink(const QString& address, quint16 port) void UDPSinkUDPHandler::resetReadIndex() { m_readFrameIndex = (m_writeIndex + (m_nbUDPFrames/2)) % m_nbUDPFrames; + m_rwDelta = m_nbUDPFrames/2; m_readIndex = 0; } diff --git a/plugins/channeltx/udpsink/udpsinkudphandler.h b/plugins/channeltx/udpsink/udpsinkudphandler.h index f261ad168..17d74f697 100644 --- a/plugins/channeltx/udpsink/udpsinkudphandler.h +++ b/plugins/channeltx/udpsink/udpsinkudphandler.h @@ -39,8 +39,18 @@ public: void readSample(Real &t); void readSample(Sample &s); + /** Get buffer gauge value in % of buffer size ([-50:50]) + * [-50:0] : write leads or read lags + * [0:50] : read leads or write lags + */ + inline int32_t getBufferGauge() const + { + int32_t val = m_rwDelta - (m_nbUDPFrames/2); + return (100*val) / m_nbUDPFrames; + } + static const int m_udpBlockSize = 512; // UDP block size in number of bytes - static const int m_nbUDPFrames = 32; // number of frames of block size in the UDP buffer + static const int m_nbUDPFrames = 128; // number of frames of block size in the UDP buffer public slots: void dataReadyRead(); @@ -60,6 +70,7 @@ private: int m_writeIndex; int m_readFrameIndex; int m_readIndex; + int m_rwDelta; };