1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-26 09:48:45 -05:00

KiwiSDR: implement variable sample rate. Fixes #1523

This commit is contained in:
f4exb 2022-11-27 00:28:55 +01:00
parent ba1dfa97f3
commit 6bba016a7d
4 changed files with 82 additions and 12 deletions

View File

@ -43,6 +43,7 @@ MESSAGE_CLASS_DEFINITION(KiwiSDRInput::MsgSetStatus, Message)
KiwiSDRInput::KiwiSDRInput(DeviceAPI *deviceAPI) :
m_deviceAPI(deviceAPI),
m_sampleRate(12000),
m_settings(),
m_kiwiSDRWorker(nullptr),
m_kiwiSDRWorkerThread(nullptr),
@ -101,6 +102,7 @@ bool KiwiSDRInput::start()
m_kiwiSDRWorkerThread = new QThread();
m_kiwiSDRWorker = new KiwiSDRWorker(&m_sampleFifo);
m_kiwiSDRWorker->setInputMessageQueue(getInputMessageQueue());
m_kiwiSDRWorker->moveToThread(m_kiwiSDRWorkerThread);
QObject::connect(m_kiwiSDRWorkerThread, &QThread::finished, m_kiwiSDRWorker, &QObject::deleteLater);
@ -174,7 +176,7 @@ const QString& KiwiSDRInput::getDeviceDescription() const
int KiwiSDRInput::getSampleRate() const
{
return 12000;
return m_sampleRate;
}
quint64 KiwiSDRInput::getCenterFrequency() const
@ -219,6 +221,22 @@ bool KiwiSDRInput::handleMessage(const Message& message)
return true;
}
else if (KiwiSDRWorker::MsgReportSampleRate::match(message))
{
KiwiSDRWorker::MsgReportSampleRate& report = (KiwiSDRWorker::MsgReportSampleRate&) message;
m_sampleRate = report.getSampleRate();
qDebug() << "KiwiSDRInput::handleMessage: KiwiSDRWorker::MsgReportSampleRate: m_sampleRate: " << m_sampleRate;
if (!m_sampleFifo.setSize(m_sampleRate * 2)) {
qCritical("KiwiSDRInput::KiwiSDRInput: Could not allocate SampleFifo");
}
DSPSignalNotification *notif = new DSPSignalNotification(
m_sampleRate, m_settings.m_centerFrequency);
m_deviceAPI->getDeviceEngineInputMessageQueue()->push(notif);
return true;
}
else if (MsgStartStop::match(message))
{
MsgStartStop& cmd = (MsgStartStop&) message;

View File

@ -155,6 +155,7 @@ public:
private:
DeviceAPI *m_deviceAPI;
QMutex m_mutex;
int m_sampleRate;
KiwiSDRSettings m_settings;
KiwiSDRWorker* m_kiwiSDRWorker;
QThread *m_kiwiSDRWorkerThread;

View File

@ -16,14 +16,19 @@
///////////////////////////////////////////////////////////////////////////////////
#include <boost/endian/conversion.hpp>
#include "util/messagequeue.h"
#include "kiwisdrworker.h"
MESSAGE_CLASS_DEFINITION(KiwiSDRWorker::MsgReportSampleRate, Message)
KiwiSDRWorker::KiwiSDRWorker(SampleSinkFifo* sampleFifo) :
QObject(),
m_timer(this),
m_samplesBuf(),
m_sampleFifo(sampleFifo),
m_centerFrequency(1450000),
m_sampleRate(12000),
m_inputMessageQueue(nullptr),
m_gain(20),
m_useAGC(true),
m_status(0)
@ -66,7 +71,8 @@ void KiwiSDRWorker::sendCenterFrequency()
return;
QString freq = QString::number(m_centerFrequency / 1000.0, 'f', 3);
QString msg = "SET mod=iq low_cut=-5980 high_cut=5980 freq=" + freq;
int bw = (m_sampleRate/2) - 20;
QString msg = QString("SET mod=iq low_cut=-%1 high_cut=%2 freq=%3").arg(bw).arg(bw).arg(freq);
m_webSocket.sendTextMessage(msg);
}
@ -87,16 +93,36 @@ void KiwiSDRWorker::onBinaryMessageReceived(const QByteArray &message)
if (message[0] == 'M' && message[1] == 'S' && message[2] == 'G')
{
QStringList al = QString::fromUtf8(message).split(' ');
if (al.size() > 2 && al[2] == "audio_rate=12000")
{
m_webSocket.sendTextMessage("SET AR OK in=12000 out=48000");
m_webSocket.sendTextMessage("SERVER DE CLIENT KiwiAngel SND");
sendGain();
sendCenterFrequency();
m_timer.start(5000);
m_status = 2;
emit updateStatus(2);
}
if ((al.size() > 2) && al[2].startsWith("audio_rate="))
{
QStringList rateKeyVal = al[2].split('=');
if (rateKeyVal.size() > 1)
{
bool ok;
int sampleRate = rateKeyVal[1].toInt(&ok);
if (ok) {
m_sampleRate = sampleRate;
}
qDebug("KiwiSDRWorker::onBinaryMessageReceived: sample rate: %d", m_sampleRate);
if (m_inputMessageQueue) {
m_inputMessageQueue->push(MsgReportSampleRate::create(m_sampleRate));
}
QString msg = QString("SET AR OK in=%1 out=48000").arg(m_sampleRate);
m_webSocket.sendTextMessage(msg);
m_webSocket.sendTextMessage("SERVER DE CLIENT KiwiAngel SND");
sendGain();
sendCenterFrequency();
m_timer.start(5000);
m_status = 2;
emit updateStatus(2);
}
}
}
else if (message[0] == 'S' && message[1] == 'N' && message[2] == 'D')
{

View File

@ -22,13 +22,36 @@
#include <QtWebSockets/QtWebSockets>
#include "dsp/samplesinkfifo.h"
#include "util/message.h"
class MessageQueue;
class KiwiSDRWorker : public QObject {
Q_OBJECT
public:
class MsgReportSampleRate : public Message {
MESSAGE_CLASS_DECLARATION
public:
int getSampleRate() const { return m_sampleRate; }
static MsgReportSampleRate* create(int sampleRate) {
return new MsgReportSampleRate(sampleRate);
}
private:
int m_sampleRate;
MsgReportSampleRate(int sampleRate) :
Message(),
m_sampleRate(sampleRate)
{ }
};
KiwiSDRWorker(SampleSinkFifo* sampleFifo);
int getStatus() const { return m_status; }
void setInputMessageQueue(MessageQueue *messageQueue) { m_inputMessageQueue = messageQueue; }
private:
QTimer m_timer;
@ -39,6 +62,8 @@ private:
QString m_serverAddress;
uint64_t m_centerFrequency;
int m_sampleRate;
MessageQueue *m_inputMessageQueue;
uint32_t m_gain;
bool m_useAGC;