mirror of
https://github.com/f4exb/sdrangel.git
synced 2025-09-19 06:58:24 -04:00
KiwiSDR: implement variable sample rate. Fixes #1523
This commit is contained in:
parent
ba1dfa97f3
commit
6bba016a7d
@ -43,6 +43,7 @@ MESSAGE_CLASS_DEFINITION(KiwiSDRInput::MsgSetStatus, Message)
|
|||||||
|
|
||||||
KiwiSDRInput::KiwiSDRInput(DeviceAPI *deviceAPI) :
|
KiwiSDRInput::KiwiSDRInput(DeviceAPI *deviceAPI) :
|
||||||
m_deviceAPI(deviceAPI),
|
m_deviceAPI(deviceAPI),
|
||||||
|
m_sampleRate(12000),
|
||||||
m_settings(),
|
m_settings(),
|
||||||
m_kiwiSDRWorker(nullptr),
|
m_kiwiSDRWorker(nullptr),
|
||||||
m_kiwiSDRWorkerThread(nullptr),
|
m_kiwiSDRWorkerThread(nullptr),
|
||||||
@ -101,6 +102,7 @@ bool KiwiSDRInput::start()
|
|||||||
|
|
||||||
m_kiwiSDRWorkerThread = new QThread();
|
m_kiwiSDRWorkerThread = new QThread();
|
||||||
m_kiwiSDRWorker = new KiwiSDRWorker(&m_sampleFifo);
|
m_kiwiSDRWorker = new KiwiSDRWorker(&m_sampleFifo);
|
||||||
|
m_kiwiSDRWorker->setInputMessageQueue(getInputMessageQueue());
|
||||||
m_kiwiSDRWorker->moveToThread(m_kiwiSDRWorkerThread);
|
m_kiwiSDRWorker->moveToThread(m_kiwiSDRWorkerThread);
|
||||||
|
|
||||||
QObject::connect(m_kiwiSDRWorkerThread, &QThread::finished, m_kiwiSDRWorker, &QObject::deleteLater);
|
QObject::connect(m_kiwiSDRWorkerThread, &QThread::finished, m_kiwiSDRWorker, &QObject::deleteLater);
|
||||||
@ -174,7 +176,7 @@ const QString& KiwiSDRInput::getDeviceDescription() const
|
|||||||
|
|
||||||
int KiwiSDRInput::getSampleRate() const
|
int KiwiSDRInput::getSampleRate() const
|
||||||
{
|
{
|
||||||
return 12000;
|
return m_sampleRate;
|
||||||
}
|
}
|
||||||
|
|
||||||
quint64 KiwiSDRInput::getCenterFrequency() const
|
quint64 KiwiSDRInput::getCenterFrequency() const
|
||||||
@ -219,6 +221,22 @@ bool KiwiSDRInput::handleMessage(const Message& message)
|
|||||||
|
|
||||||
return true;
|
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))
|
else if (MsgStartStop::match(message))
|
||||||
{
|
{
|
||||||
MsgStartStop& cmd = (MsgStartStop&) message;
|
MsgStartStop& cmd = (MsgStartStop&) message;
|
||||||
|
@ -155,6 +155,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
DeviceAPI *m_deviceAPI;
|
DeviceAPI *m_deviceAPI;
|
||||||
QMutex m_mutex;
|
QMutex m_mutex;
|
||||||
|
int m_sampleRate;
|
||||||
KiwiSDRSettings m_settings;
|
KiwiSDRSettings m_settings;
|
||||||
KiwiSDRWorker* m_kiwiSDRWorker;
|
KiwiSDRWorker* m_kiwiSDRWorker;
|
||||||
QThread *m_kiwiSDRWorkerThread;
|
QThread *m_kiwiSDRWorkerThread;
|
||||||
|
@ -16,14 +16,19 @@
|
|||||||
///////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#include <boost/endian/conversion.hpp>
|
#include <boost/endian/conversion.hpp>
|
||||||
|
#include "util/messagequeue.h"
|
||||||
#include "kiwisdrworker.h"
|
#include "kiwisdrworker.h"
|
||||||
|
|
||||||
|
MESSAGE_CLASS_DEFINITION(KiwiSDRWorker::MsgReportSampleRate, Message)
|
||||||
|
|
||||||
KiwiSDRWorker::KiwiSDRWorker(SampleSinkFifo* sampleFifo) :
|
KiwiSDRWorker::KiwiSDRWorker(SampleSinkFifo* sampleFifo) :
|
||||||
QObject(),
|
QObject(),
|
||||||
m_timer(this),
|
m_timer(this),
|
||||||
m_samplesBuf(),
|
m_samplesBuf(),
|
||||||
m_sampleFifo(sampleFifo),
|
m_sampleFifo(sampleFifo),
|
||||||
m_centerFrequency(1450000),
|
m_centerFrequency(1450000),
|
||||||
|
m_sampleRate(12000),
|
||||||
|
m_inputMessageQueue(nullptr),
|
||||||
m_gain(20),
|
m_gain(20),
|
||||||
m_useAGC(true),
|
m_useAGC(true),
|
||||||
m_status(0)
|
m_status(0)
|
||||||
@ -66,7 +71,8 @@ void KiwiSDRWorker::sendCenterFrequency()
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
QString freq = QString::number(m_centerFrequency / 1000.0, 'f', 3);
|
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);
|
m_webSocket.sendTextMessage(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,16 +93,36 @@ void KiwiSDRWorker::onBinaryMessageReceived(const QByteArray &message)
|
|||||||
if (message[0] == 'M' && message[1] == 'S' && message[2] == 'G')
|
if (message[0] == 'M' && message[1] == 'S' && message[2] == 'G')
|
||||||
{
|
{
|
||||||
QStringList al = QString::fromUtf8(message).split(' ');
|
QStringList al = QString::fromUtf8(message).split(' ');
|
||||||
if (al.size() > 2 && al[2] == "audio_rate=12000")
|
|
||||||
{
|
if ((al.size() > 2) && al[2].startsWith("audio_rate="))
|
||||||
m_webSocket.sendTextMessage("SET AR OK in=12000 out=48000");
|
{
|
||||||
m_webSocket.sendTextMessage("SERVER DE CLIENT KiwiAngel SND");
|
QStringList rateKeyVal = al[2].split('=');
|
||||||
sendGain();
|
|
||||||
sendCenterFrequency();
|
if (rateKeyVal.size() > 1)
|
||||||
m_timer.start(5000);
|
{
|
||||||
m_status = 2;
|
bool ok;
|
||||||
emit updateStatus(2);
|
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')
|
else if (message[0] == 'S' && message[1] == 'N' && message[2] == 'D')
|
||||||
{
|
{
|
||||||
|
@ -22,13 +22,36 @@
|
|||||||
#include <QtWebSockets/QtWebSockets>
|
#include <QtWebSockets/QtWebSockets>
|
||||||
|
|
||||||
#include "dsp/samplesinkfifo.h"
|
#include "dsp/samplesinkfifo.h"
|
||||||
|
#include "util/message.h"
|
||||||
|
|
||||||
|
class MessageQueue;
|
||||||
|
|
||||||
class KiwiSDRWorker : public QObject {
|
class KiwiSDRWorker : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
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);
|
KiwiSDRWorker(SampleSinkFifo* sampleFifo);
|
||||||
int getStatus() const { return m_status; }
|
int getStatus() const { return m_status; }
|
||||||
|
void setInputMessageQueue(MessageQueue *messageQueue) { m_inputMessageQueue = messageQueue; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QTimer m_timer;
|
QTimer m_timer;
|
||||||
@ -39,6 +62,8 @@ private:
|
|||||||
|
|
||||||
QString m_serverAddress;
|
QString m_serverAddress;
|
||||||
uint64_t m_centerFrequency;
|
uint64_t m_centerFrequency;
|
||||||
|
int m_sampleRate;
|
||||||
|
MessageQueue *m_inputMessageQueue;
|
||||||
|
|
||||||
uint32_t m_gain;
|
uint32_t m_gain;
|
||||||
bool m_useAGC;
|
bool m_useAGC;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user