mirror of
https://github.com/f4exb/sdrangel.git
synced 2025-08-02 22:12:26 -04:00
UDPSink buffer: implemented R/W pointer skew auto compensation
This commit is contained in:
parent
2cff745cda
commit
60b502ce7e
@ -115,8 +115,6 @@ void UDPSink::modulateSample()
|
|||||||
|
|
||||||
bool UDPSink::handleMessage(const Message& cmd)
|
bool UDPSink::handleMessage(const Message& cmd)
|
||||||
{
|
{
|
||||||
qDebug() << "UDPSink::handleMessage";
|
|
||||||
|
|
||||||
if (UpChannelizer::MsgChannelizerNotification::match(cmd))
|
if (UpChannelizer::MsgChannelizerNotification::match(cmd))
|
||||||
{
|
{
|
||||||
UpChannelizer::MsgChannelizerNotification& notif = (UpChannelizer::MsgChannelizerNotification&) cmd;
|
UpChannelizer::MsgChannelizerNotification& notif = (UpChannelizer::MsgChannelizerNotification&) cmd;
|
||||||
@ -167,7 +165,17 @@ bool UDPSink::handleMessage(const Message& cmd)
|
|||||||
}
|
}
|
||||||
else if (UDPSinkMessages::MsgSampleRateCorrection::match(cmd))
|
else if (UDPSinkMessages::MsgSampleRateCorrection::match(cmd))
|
||||||
{
|
{
|
||||||
// TODO
|
UDPSinkMessages::MsgSampleRateCorrection& cfg = (UDPSinkMessages::MsgSampleRateCorrection&) cmd;
|
||||||
|
m_actualInputSampleRate += cfg.getCorrectionFactor() * m_actualInputSampleRate;
|
||||||
|
qDebug("UDPSink::handleMessage: MsgSampleRateCorrection: corr: %f new rate: %f", cfg.getCorrectionFactor(), m_actualInputSampleRate);
|
||||||
|
|
||||||
|
m_settingsMutex.lock();
|
||||||
|
m_interpolatorDistanceRemain = 0;
|
||||||
|
m_interpolatorConsumed = false;
|
||||||
|
m_interpolatorDistance = (Real) m_actualInputSampleRate / (Real) m_config.m_outputSampleRate;
|
||||||
|
//m_interpolator.create(48, m_actualInputSampleRate, m_config.m_rfBandwidth / 2.2, 3.0); // causes clicking: leaving at standard frequency
|
||||||
|
m_settingsMutex.unlock();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -223,6 +231,8 @@ void UDPSink::apply(bool force)
|
|||||||
m_interpolatorConsumed = false;
|
m_interpolatorConsumed = false;
|
||||||
m_interpolatorDistance = (Real) m_config.m_inputSampleRate / (Real) m_config.m_outputSampleRate;
|
m_interpolatorDistance = (Real) m_config.m_inputSampleRate / (Real) m_config.m_outputSampleRate;
|
||||||
m_interpolator.create(48, m_config.m_inputSampleRate, m_config.m_rfBandwidth / 2.2, 3.0);
|
m_interpolator.create(48, m_config.m_inputSampleRate, m_config.m_rfBandwidth / 2.2, 3.0);
|
||||||
|
m_actualInputSampleRate = m_config.m_inputSampleRate;
|
||||||
|
m_udpHandler.resetReadIndex();
|
||||||
m_settingsMutex.unlock();
|
m_settingsMutex.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -198,6 +198,7 @@ private:
|
|||||||
MovingAverage<double> m_movingAverage;
|
MovingAverage<double> m_movingAverage;
|
||||||
|
|
||||||
UDPSinkUDPHandler m_udpHandler;
|
UDPSinkUDPHandler m_udpHandler;
|
||||||
|
Real m_actualInputSampleRate; //!< sample rate with UDP buffer skew compensation
|
||||||
|
|
||||||
QMutex m_settingsMutex;
|
QMutex m_settingsMutex;
|
||||||
|
|
||||||
|
@ -16,7 +16,9 @@
|
|||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
|
#include "udpsinkmsg.h"
|
||||||
#include "udpsinkudphandler.h"
|
#include "udpsinkudphandler.h"
|
||||||
|
#include "util/messagequeue.h"
|
||||||
|
|
||||||
UDPSinkUDPHandler::UDPSinkUDPHandler() :
|
UDPSinkUDPHandler::UDPSinkUDPHandler() :
|
||||||
m_dataSocket(0),
|
m_dataSocket(0),
|
||||||
@ -29,6 +31,7 @@ UDPSinkUDPHandler::UDPSinkUDPHandler() :
|
|||||||
m_readFrameIndex(m_nbUDPFrames/2),
|
m_readFrameIndex(m_nbUDPFrames/2),
|
||||||
m_readIndex(0),
|
m_readIndex(0),
|
||||||
m_rwDelta(m_nbUDPFrames/2),
|
m_rwDelta(m_nbUDPFrames/2),
|
||||||
|
m_d(0),
|
||||||
m_feedbackMessageQueue(0)
|
m_feedbackMessageQueue(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -136,8 +139,26 @@ void UDPSinkUDPHandler::advanceReadPointer(int nbBytes)
|
|||||||
{
|
{
|
||||||
m_rwDelta = m_writeIndex; // raw R/W delta estimate
|
m_rwDelta = m_writeIndex; // raw R/W delta estimate
|
||||||
float d = (m_rwDelta - (m_nbUDPFrames/2))/(float) m_nbUDPFrames;
|
float d = (m_rwDelta - (m_nbUDPFrames/2))/(float) m_nbUDPFrames;
|
||||||
qDebug("UDPSinkUDPHandler::advanceReadPointer: w: %02d d: %f", m_writeIndex, d);
|
//qDebug("UDPSinkUDPHandler::advanceReadPointer: w: %02d d: %f", m_writeIndex, d);
|
||||||
m_readFrameIndex = 0;
|
|
||||||
|
if ((d < -0.45) || (d > 0.45))
|
||||||
|
{
|
||||||
|
resetReadIndex();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
float dd = d - m_d; // derivative
|
||||||
|
float c = (d + dd) / 10.0; // (d / 10.0) + (dd / 10.0); // damping and scaling
|
||||||
|
c = c < -0.05 ? -0.05 : c > 0.05 ? 0.05 : c; // limit
|
||||||
|
UDPSinkMessages::MsgSampleRateCorrection *msg = UDPSinkMessages::MsgSampleRateCorrection::create(c);
|
||||||
|
|
||||||
|
if (m_feedbackMessageQueue) {
|
||||||
|
m_feedbackMessageQueue->push(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
m_readFrameIndex = 0;
|
||||||
|
m_d = d;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -164,4 +185,5 @@ void UDPSinkUDPHandler::resetReadIndex()
|
|||||||
m_readFrameIndex = (m_writeIndex + (m_nbUDPFrames/2)) % m_nbUDPFrames;
|
m_readFrameIndex = (m_writeIndex + (m_nbUDPFrames/2)) % m_nbUDPFrames;
|
||||||
m_rwDelta = m_nbUDPFrames/2;
|
m_rwDelta = m_nbUDPFrames/2;
|
||||||
m_readIndex = 0;
|
m_readIndex = 0;
|
||||||
|
m_d = 0.0f;
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
static const int m_udpBlockSize = 512; // UDP block size in number of bytes
|
static const int m_udpBlockSize = 512; // UDP block size in number of bytes
|
||||||
static const int m_nbUDPFrames = 128; // number of frames of block size in the UDP buffer
|
static const int m_nbUDPFrames = 256; // number of frames of block size in the UDP buffer
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void dataReadyRead();
|
void dataReadyRead();
|
||||||
@ -75,6 +75,7 @@ private:
|
|||||||
int m_readFrameIndex;
|
int m_readFrameIndex;
|
||||||
int m_readIndex;
|
int m_readIndex;
|
||||||
int m_rwDelta;
|
int m_rwDelta;
|
||||||
|
float m_d;
|
||||||
MessageQueue *m_feedbackMessageQueue;
|
MessageQueue *m_feedbackMessageQueue;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user