mirror of
https://github.com/f4exb/sdrangel.git
synced 2024-12-03 05:25:17 -05:00
SDRDaemonSink: transfer sample rate control from GUI to core (2)
This commit is contained in:
parent
a0a9dc4dae
commit
6f3bb72d52
@ -41,6 +41,8 @@ MESSAGE_CLASS_DEFINITION(SDRdaemonSinkOutput::MsgConfigureSDRdaemonSinkWork, Mes
|
|||||||
MESSAGE_CLASS_DEFINITION(SDRdaemonSinkOutput::MsgStartStop, Message)
|
MESSAGE_CLASS_DEFINITION(SDRdaemonSinkOutput::MsgStartStop, Message)
|
||||||
MESSAGE_CLASS_DEFINITION(SDRdaemonSinkOutput::MsgConfigureSDRdaemonSinkChunkCorrection, Message)
|
MESSAGE_CLASS_DEFINITION(SDRdaemonSinkOutput::MsgConfigureSDRdaemonSinkChunkCorrection, Message)
|
||||||
|
|
||||||
|
const uint32_t SDRdaemonSinkOutput::NbSamplesForRateCorrection = 5000000;
|
||||||
|
|
||||||
SDRdaemonSinkOutput::SDRdaemonSinkOutput(DeviceSinkAPI *deviceAPI) :
|
SDRdaemonSinkOutput::SDRdaemonSinkOutput(DeviceSinkAPI *deviceAPI) :
|
||||||
m_deviceAPI(deviceAPI),
|
m_deviceAPI(deviceAPI),
|
||||||
m_settings(),
|
m_settings(),
|
||||||
@ -49,6 +51,7 @@ SDRdaemonSinkOutput::SDRdaemonSinkOutput(DeviceSinkAPI *deviceAPI) :
|
|||||||
m_startingTimeStamp(0),
|
m_startingTimeStamp(0),
|
||||||
m_masterTimer(deviceAPI->getMasterTimer()),
|
m_masterTimer(deviceAPI->getMasterTimer()),
|
||||||
m_tickCount(0),
|
m_tickCount(0),
|
||||||
|
m_tickMultiplier(20),
|
||||||
m_lastSampleCount(0),
|
m_lastSampleCount(0),
|
||||||
m_lastTimestampUs(0),
|
m_lastTimestampUs(0),
|
||||||
m_lastTimestampRateCorrection(0),
|
m_lastTimestampRateCorrection(0),
|
||||||
@ -268,6 +271,9 @@ void SDRdaemonSinkOutput::applySettings(const SDRdaemonSinkSettings& settings, b
|
|||||||
m_sdrDaemonSinkThread->setSamplerate(settings.m_sampleRate);
|
m_sdrDaemonSinkThread->setSamplerate(settings.m_sampleRate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_tickMultiplier = (20*NbSamplesForRateCorrection) / (2*settings.m_sampleRate); // two times per sample filling period
|
||||||
|
m_tickMultiplier = m_tickMultiplier < 20 ? 20 : m_tickMultiplier; // not below half a second
|
||||||
|
|
||||||
forwardChange = true;
|
forwardChange = true;
|
||||||
changeTxDelay = true;
|
changeTxDelay = true;
|
||||||
}
|
}
|
||||||
@ -449,7 +455,7 @@ void SDRdaemonSinkOutput::webapiFormatDeviceReport(SWGSDRangel::SWGDeviceReport&
|
|||||||
|
|
||||||
void SDRdaemonSinkOutput::tick()
|
void SDRdaemonSinkOutput::tick()
|
||||||
{
|
{
|
||||||
if (++m_tickCount == 20*60) // once per minute
|
if (++m_tickCount == m_tickMultiplier)
|
||||||
{
|
{
|
||||||
QString reportURL;
|
QString reportURL;
|
||||||
|
|
||||||
@ -515,18 +521,12 @@ void SDRdaemonSinkOutput::analyzeApiReply(const QJsonObject& jsonObject)
|
|||||||
uint32_t sampleCountDelta, sampleCount;
|
uint32_t sampleCountDelta, sampleCount;
|
||||||
sampleCount = report["samplesCount"].toInt();
|
sampleCount = report["samplesCount"].toInt();
|
||||||
|
|
||||||
qDebug("SDRdaemonSinkOutput::analyzeApiReply: sampleCount: %u m_nbSamplesSinceRateCorrection: %u",
|
|
||||||
sampleCount,
|
|
||||||
m_nbSamplesSinceRateCorrection);
|
|
||||||
|
|
||||||
if (sampleCount < m_lastSampleCount) {
|
if (sampleCount < m_lastSampleCount) {
|
||||||
sampleCountDelta = (0xFFFFFFFFU - m_lastSampleCount) + sampleCount + 1;
|
sampleCountDelta = (0xFFFFFFFFU - m_lastSampleCount) + sampleCount + 1;
|
||||||
} else {
|
} else {
|
||||||
sampleCountDelta = sampleCount - m_lastSampleCount;
|
sampleCountDelta = sampleCount - m_lastSampleCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sampleCountDelta != 0)
|
|
||||||
{
|
|
||||||
if (m_lastTimestampRateCorrection == 0) {
|
if (m_lastTimestampRateCorrection == 0) {
|
||||||
m_lastTimestampRateCorrection = timestampUs;
|
m_lastTimestampRateCorrection = timestampUs;
|
||||||
}
|
}
|
||||||
@ -534,14 +534,18 @@ void SDRdaemonSinkOutput::analyzeApiReply(const QJsonObject& jsonObject)
|
|||||||
{
|
{
|
||||||
m_nbSamplesSinceRateCorrection += sampleCountDelta;
|
m_nbSamplesSinceRateCorrection += sampleCountDelta;
|
||||||
|
|
||||||
if ((m_nbSamplesSinceRateCorrection > 20000000) && ((queueLengthPercent > 60) || (queueLengthPercent < 40)))
|
qDebug("SDRdaemonSinkOutput::analyzeApiReply: queueLengthPercent: %d sampleCount: %u m_nbSamplesSinceRateCorrection: %u",
|
||||||
|
queueLengthPercent,
|
||||||
|
sampleCount,
|
||||||
|
m_nbSamplesSinceRateCorrection);
|
||||||
|
|
||||||
|
if ((m_nbSamplesSinceRateCorrection > NbSamplesForRateCorrection) && ((queueLengthPercent > 60) || (queueLengthPercent < 40)))
|
||||||
{
|
{
|
||||||
sampleRateCorrection(queueLength, queueSize, timestampUs - m_lastTimestampRateCorrection);
|
sampleRateCorrection(queueLength, queueSize, timestampUs - m_lastTimestampRateCorrection);
|
||||||
m_lastTimestampRateCorrection = timestampUs;
|
m_lastTimestampRateCorrection = timestampUs;
|
||||||
m_nbSamplesSinceRateCorrection = 0;
|
m_nbSamplesSinceRateCorrection = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
m_lastSampleCount = sampleCount;
|
m_lastSampleCount = sampleCount;
|
||||||
m_lastTimestampUs = timestampUs;
|
m_lastTimestampUs = timestampUs;
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QNetworkRequest>
|
#include <QNetworkRequest>
|
||||||
@ -36,6 +37,7 @@ class QNetworkReply;
|
|||||||
class QJsonObject;
|
class QJsonObject;
|
||||||
|
|
||||||
class SDRdaemonSinkOutput : public DeviceSampleSink {
|
class SDRdaemonSinkOutput : public DeviceSampleSink {
|
||||||
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
class MsgConfigureSDRdaemonSink : public Message {
|
class MsgConfigureSDRdaemonSink : public Message {
|
||||||
MESSAGE_CLASS_DECLARATION
|
MESSAGE_CLASS_DECLARATION
|
||||||
@ -171,6 +173,7 @@ private:
|
|||||||
std::time_t m_startingTimeStamp;
|
std::time_t m_startingTimeStamp;
|
||||||
const QTimer& m_masterTimer;
|
const QTimer& m_masterTimer;
|
||||||
uint32_t m_tickCount;
|
uint32_t m_tickCount;
|
||||||
|
uint32_t m_tickMultiplier;
|
||||||
|
|
||||||
QNetworkAccessManager *m_networkManager;
|
QNetworkAccessManager *m_networkManager;
|
||||||
QNetworkRequest m_networkRequest;
|
QNetworkRequest m_networkRequest;
|
||||||
@ -180,6 +183,7 @@ private:
|
|||||||
uint64_t m_lastTimestampRateCorrection;
|
uint64_t m_lastTimestampRateCorrection;
|
||||||
uint32_t m_nbSamplesSinceRateCorrection;
|
uint32_t m_nbSamplesSinceRateCorrection;
|
||||||
int m_chunkSizeCorrection;
|
int m_chunkSizeCorrection;
|
||||||
|
static const uint32_t NbSamplesForRateCorrection;
|
||||||
|
|
||||||
void applySettings(const SDRdaemonSinkSettings& settings, bool force = false);
|
void applySettings(const SDRdaemonSinkSettings& settings, bool force = false);
|
||||||
void webapiFormatDeviceSettings(SWGSDRangel::SWGDeviceSettings& response, const SDRdaemonSinkSettings& settings);
|
void webapiFormatDeviceSettings(SWGSDRangel::SWGDeviceSettings& response, const SDRdaemonSinkSettings& settings);
|
||||||
|
Loading…
Reference in New Issue
Block a user