BFM demod: GUI and demod separation

pull/85/head
f4exb 2017-10-01 12:48:31 +02:00
rodzic a9d1b2ef65
commit b646d0c89f
5 zmienionych plików z 126 dodań i 31 usunięć

Wyświetl plik

@ -15,29 +15,30 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#include "../../channelrx/demodbfm/bfmdemod.h"
#include <QTime>
#include <QDebug>
#include <stdio.h>
#include <complex.h>
#include "audio/audiooutput.h"
#include "dsp/dspengine.h"
#include "dsp/pidcontroller.h"
#include "bfmdemod.h"
#include <dsp/downchannelizer.h>
#include "dsp/threadedbasebandsamplesink.h"
#include "device/devicesourceapi.h"
#include "rdsparser.h"
#include "bfmdemod.h"
MESSAGE_CLASS_DEFINITION(BFMDemod::MsgConfigureChannelizer, Message)
MESSAGE_CLASS_DEFINITION(BFMDemod::MsgReportChannelSampleRateChanged, Message)
MESSAGE_CLASS_DEFINITION(BFMDemod::MsgConfigureBFMDemod, Message)
const Real BFMDemod::default_deemphasis = 50.0; // 50 us
const int BFMDemod::m_udpBlockSize = 512;
BFMDemod::BFMDemod(DeviceSourceAPI *deviceAPI, BasebandSampleSink* sampleSink) :
BFMDemod::BFMDemod(DeviceSourceAPI *deviceAPI) :
m_deviceAPI(deviceAPI),
m_sampleSink(sampleSink),
m_audioFifo(250000),
m_settingsMutex(QMutex::Recursive),
m_pilotPLL(19000/384000, 50/384000, 0.01),
@ -47,6 +48,11 @@ BFMDemod::BFMDemod(DeviceSourceAPI *deviceAPI, BasebandSampleSink* sampleSink) :
{
setObjectName("BFMDemod");
m_channelizer = new DownChannelizer(this);
m_threadedChannelizer = new ThreadedBasebandSampleSink(m_channelizer, this);
connect(m_channelizer, SIGNAL(inputSampleRateChanged()), this, SLOT(channelSampleRateChanged()));
m_deviceAPI->addThreadedSink(m_threadedChannelizer);
m_config.m_inputSampleRate = 384000;
m_config.m_inputFrequencyOffset = 0;
m_config.m_rfBandwidth = 180000;
@ -83,6 +89,10 @@ BFMDemod::~BFMDemod()
DSPEngine::instance()->removeAudioSink(&m_audioFifo);
delete m_udpBufferAudio;
m_deviceAPI->removeThreadedSink(m_threadedChannelizer);
delete m_threadedChannelizer;
delete m_channelizer;
}
void BFMDemod::configure(MessageQueue* messageQueue,
@ -310,6 +320,12 @@ void BFMDemod::stop()
{
}
void BFMDemod::channelSampleRateChanged()
{
MsgReportChannelSampleRateChanged *msg = MsgReportChannelSampleRateChanged::create(getSampleRate());
getMessageQueueToGUI()->push(msg);
}
bool BFMDemod::handleMessage(const Message& cmd)
{
if (DownChannelizer::MsgChannelizerNotification::match(cmd))

Wyświetl plik

@ -38,11 +38,57 @@
#include "rdsdemod.h"
class DeviceSourceAPI;
class ThreadedBasebandSampleSink;
class DownChannelizer;
class BFMDemod : public BasebandSampleSink {
public:
BFMDemod(DeviceSourceAPI *deviceAPI, BasebandSampleSink* sampleSink);
class MsgConfigureChannelizer : public Message {
MESSAGE_CLASS_DECLARATION
public:
int getSampleRate() const { return m_sampleRate; }
int getCenterFrequency() const { return m_centerFrequency; }
static MsgConfigureChannelizer* create(int sampleRate, int centerFrequency)
{
return new MsgConfigureChannelizer(sampleRate, centerFrequency);
}
private:
int m_sampleRate;
int m_centerFrequency;
MsgConfigureChannelizer(int sampleRate, int centerFrequency) :
Message(),
m_sampleRate(sampleRate),
m_centerFrequency(centerFrequency)
{ }
};
class MsgReportChannelSampleRateChanged : public Message {
MESSAGE_CLASS_DECLARATION
public:
int getSampleRate() const { return m_sampleRate; }
static MsgReportChannelSampleRateChanged* create(int sampleRate)
{
return new MsgReportChannelSampleRateChanged(sampleRate);
}
private:
int m_sampleRate;
MsgReportChannelSampleRateChanged(int sampleRate) :
Message(),
m_sampleRate(sampleRate)
{ }
};
BFMDemod(DeviceSourceAPI *deviceAPI);
virtual ~BFMDemod();
void setSampleSink(BasebandSampleSink* sampleSink) { m_sampleSink = sampleSink; }
void configure(MessageQueue* messageQueue,
Real rfBandwidth,
@ -88,6 +134,9 @@ public:
RDSParser& getRDSParser() { return m_rdsParser; }
private slots:
void channelSampleRateChanged();
private:
class MsgConfigureBFMDemod : public Message {
MESSAGE_CLASS_DECLARATION
@ -218,6 +267,8 @@ private:
Config m_running;
DeviceSourceAPI *m_deviceAPI;
ThreadedBasebandSampleSink* m_threadedChannelizer;
DownChannelizer* m_channelizer;
NCO m_nco;
Interpolator m_interpolator; //!< Interpolator between fixed demod bandwidth and audio bandwidth (rational)

Wyświetl plik

@ -201,11 +201,38 @@ bool BFMDemodGUI::deserialize(const QByteArray& data)
}
}
bool BFMDemodGUI::handleMessage(const Message& message __attribute__((unused)))
bool BFMDemodGUI::handleMessage(const Message& message)
{
return false;
if (BFMDemod::MsgReportChannelSampleRateChanged::match(message))
{
BFMDemod::MsgReportChannelSampleRateChanged& report = (BFMDemod::MsgReportChannelSampleRateChanged&) message;
m_rate = report.getSampleRate();
ui->glSpectrum->setCenterFrequency(m_rate / 4);
ui->glSpectrum->setSampleRate(m_rate / 2);
return true;
}
else
{
return false;
}
}
void BFMDemodGUI::handleInputMessages()
{
Message* message;
while ((message = getInputMessageQueue()->pop()) != 0)
{
qDebug("BFMDemodGUI::handleInputMessages: message: %s", message->getIdentifier());
if (handleMessage(*message))
{
delete message;
}
}
}
void BFMDemodGUI::channelMarkerChanged()
{
this->setWindowTitle(m_channelMarker.getTitle());
@ -385,13 +412,16 @@ BFMDemodGUI::BFMDemodGUI(PluginAPI* pluginAPI, DeviceSourceAPI *deviceAPI, QWidg
setAttribute(Qt::WA_DeleteOnClose, true);
connect(this, SIGNAL(widgetRolled(QWidget*,bool)), this, SLOT(onWidgetRolled(QWidget*,bool)));
connect(this, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(onMenuDialogCalled(const QPoint &)));
connect(getInputMessageQueue(), SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages()));
m_spectrumVis = new SpectrumVis(ui->glSpectrum);
m_bfmDemod = new BFMDemod(m_deviceAPI, m_spectrumVis);
m_channelizer = new DownChannelizer(m_bfmDemod);
m_threadedChannelizer = new ThreadedBasebandSampleSink(m_channelizer, this);
connect(m_channelizer, SIGNAL(inputSampleRateChanged()), this, SLOT(channelSampleRateChanged()));
m_deviceAPI->addThreadedSink(m_threadedChannelizer);
m_bfmDemod = new BFMDemod(m_deviceAPI);
m_bfmDemod->setMessageQueueToGUI(getInputMessageQueue());
m_bfmDemod->setSampleSink(m_spectrumVis);
// m_channelizer = new DownChannelizer(m_bfmDemod);
// m_threadedChannelizer = new ThreadedBasebandSampleSink(m_channelizer, this);
// connect(m_channelizer, SIGNAL(inputSampleRateChanged()), this, SLOT(channelSampleRateChanged()));
// m_deviceAPI->addThreadedSink(m_threadedChannelizer);
ui->glSpectrum->setCenterFrequency(m_rate / 4);
ui->glSpectrum->setSampleRate(m_rate / 2);
@ -432,9 +462,9 @@ BFMDemodGUI::BFMDemodGUI(PluginAPI* pluginAPI, DeviceSourceAPI *deviceAPI, QWidg
BFMDemodGUI::~BFMDemodGUI()
{
m_deviceAPI->removeChannelInstance(this);
m_deviceAPI->removeThreadedSink(m_threadedChannelizer);
delete m_threadedChannelizer;
delete m_channelizer;
// m_deviceAPI->removeThreadedSink(m_threadedChannelizer);
// delete m_threadedChannelizer;
// delete m_channelizer;
delete m_bfmDemod;
//delete m_channelMarker;
delete ui;
@ -456,9 +486,14 @@ void BFMDemodGUI::applySettings(bool force)
{
setTitleColor(m_channelMarker.getColor());
m_channelizer->configure(m_channelizer->getInputMessageQueue(),
requiredBW(m_rfBW[ui->rfBW->value()]), // TODO: this is where requested sample rate is specified
m_channelMarker.getCenterFrequency());
BFMDemod::MsgConfigureChannelizer *message = BFMDemod::MsgConfigureChannelizer::create(
requiredBW(m_rfBW[ui->rfBW->value()]),
m_channelMarker.getCenterFrequency());
m_bfmDemod->getInputMessageQueue()->push(message);
// m_channelizer->configure(m_channelizer->getInputMessageQueue(),
// requiredBW(m_rfBW[ui->rfBW->value()]), // TODO: this is where requested sample rate is specified
// m_channelMarker.getCenterFrequency());
ui->deltaFrequency->setValue(m_channelMarker.getCenterFrequency());
@ -541,13 +576,6 @@ void BFMDemodGUI::tick()
//qDebug() << "Pilot lock: " << m_bfmDemod->getPilotLock() << ":" << m_bfmDemod->getPilotLevel(); TODO: update a GUI item with status
}
void BFMDemodGUI::channelSampleRateChanged()
{
m_rate = m_bfmDemod->getSampleRate();
ui->glSpectrum->setCenterFrequency(m_rate / 4);
ui->glSpectrum->setSampleRate(m_rate / 2);
}
void BFMDemodGUI::rdsUpdateFixedFields()
{
ui->g00Label->setText(m_bfmDemod->getRDSParser().rds_group_acronym_tags[0].c_str());

Wyświetl plik

@ -59,7 +59,6 @@ public:
private slots:
void channelMarkerChanged();
void channelSampleRateChanged();
void on_deltaFrequency_changed(qint64 value);
void on_rfBW_valueChanged(int value);
void on_afBW_valueChanged(int value);
@ -77,6 +76,7 @@ private slots:
void on_g14AltFrequencies_activated(int index);
void onWidgetRolled(QWidget* widget, bool rollDown);
void onMenuDialogCalled(const QPoint& p);
void handleInputMessages();
void tick();
private:
@ -87,8 +87,8 @@ private:
bool m_doApplySettings;
int m_rdsTimerCount;
ThreadedBasebandSampleSink* m_threadedChannelizer;
DownChannelizer* m_channelizer;
// ThreadedBasebandSampleSink* m_threadedChannelizer;
// DownChannelizer* m_channelizer;
SpectrumVis* m_spectrumVis;
BFMDemod* m_bfmDemod;

Wyświetl plik

@ -24,7 +24,7 @@
const PluginDescriptor BFMPlugin::m_pluginDescriptor = {
QString("Broadcast FM Demodulator"),
QString("3.6.1"),
QString("3.7.3"),
QString("(c) Edouard Griffiths, F4EXB"),
QString("https://github.com/f4exb/sdrangel"),
true,