From 9dbdeb517e0c79da19c6ac040061d03bf31c917f Mon Sep 17 00:00:00 2001 From: f4exb Date: Sat, 14 Oct 2017 05:23:45 +0200 Subject: [PATCH] WFM modulator: separate GUI and modulator phase 1 --- plugins/channeltx/modwfm/wfmmod.cpp | 35 ++++++++++++++++++++++---- plugins/channeltx/modwfm/wfmmod.h | 33 +++++++++++++++++++++++- plugins/channeltx/modwfm/wfmmodgui.cpp | 27 ++++++-------------- plugins/channeltx/modwfm/wfmmodgui.h | 4 +-- 4 files changed, 71 insertions(+), 28 deletions(-) diff --git a/plugins/channeltx/modwfm/wfmmod.cpp b/plugins/channeltx/modwfm/wfmmod.cpp index 7a7fdebed..8386bb1be 100644 --- a/plugins/channeltx/modwfm/wfmmod.cpp +++ b/plugins/channeltx/modwfm/wfmmod.cpp @@ -17,15 +17,21 @@ #include #include #include + #include #include #include + #include #include "dsp/dspengine.h" #include "dsp/pidcontroller.h" +#include "dsp/threadedbasebandsamplesource.h" +#include "device/devicesinkapi.h" + #include "wfmmod.h" MESSAGE_CLASS_DEFINITION(WFMMod::MsgConfigureWFMMod, Message) +MESSAGE_CLASS_DEFINITION(WFMMod::MsgConfigureChannelizer, Message) MESSAGE_CLASS_DEFINITION(WFMMod::MsgConfigureFileSourceName, Message) MESSAGE_CLASS_DEFINITION(WFMMod::MsgConfigureFileSourceSeek, Message) MESSAGE_CLASS_DEFINITION(WFMMod::MsgConfigureAFInput, Message) @@ -36,7 +42,8 @@ MESSAGE_CLASS_DEFINITION(WFMMod::MsgReportFileSourceStreamTiming, Message) const int WFMMod::m_levelNbSamples = 480; // every 10ms const int WFMMod::m_rfFilterFFTLength = 1024; -WFMMod::WFMMod() : +WFMMod::WFMMod(DeviceSinkAPI *deviceAPI) : + m_deviceAPI(deviceAPI), m_modPhasor(0.0f), m_movingAverage(40, 0), m_volumeAGC(40, 0), @@ -52,14 +59,15 @@ WFMMod::WFMMod() : { setObjectName("WFMod"); - m_rfFilter = new fftfilt(-62500.0 / 384000.0, 62500.0 / 384000.0, m_rfFilterFFTLength); + m_channelizer = new UpChannelizer(this); + m_threadedChannelizer = new ThreadedBasebandSampleSource(m_channelizer, this); + m_deviceAPI->addThreadedSource(m_threadedChannelizer); + + m_rfFilter = new fftfilt(-62500.0 / 384000.0, 62500.0 / 384000.0, m_rfFilterFFTLength); m_rfFilterBuffer = new Complex[m_rfFilterFFTLength]; memset(m_rfFilterBuffer, 0, sizeof(Complex)*(m_rfFilterFFTLength)); m_rfFilterBufferIndex = 0; - //apply(); - - m_audioBuffer.resize(1<<14); m_audioBufferFill = 0; @@ -86,6 +94,9 @@ WFMMod::~WFMMod() delete m_rfFilter; delete[] m_rfFilterBuffer; DSPEngine::instance()->removeAudioSource(&m_audioFifo); + m_deviceAPI->removeThreadedSource(m_threadedChannelizer); + delete m_threadedChannelizer; + delete m_channelizer; } void WFMMod::pull(Sample& sample) @@ -291,6 +302,20 @@ bool WFMMod::handleMessage(const Message& cmd) return true; } + else if (MsgConfigureChannelizer::match(cmd)) + { + MsgConfigureChannelizer& cfg = (MsgConfigureChannelizer&) cmd; + + m_channelizer->configure(m_channelizer->getInputMessageQueue(), + cfg.getSampleRate(), + cfg.getCenterFrequency()); + + qDebug() << "WFMMod::handleMessage: MsgConfigureChannelizer:" + << " getSampleRate: " << cfg.getSampleRate() + << " getCenterFrequency: " << cfg.getCenterFrequency(); + + return true; + } else if (MsgConfigureWFMMod::match(cmd)) { MsgConfigureWFMMod& cfg = (MsgConfigureWFMMod&) cmd; diff --git a/plugins/channeltx/modwfm/wfmmod.h b/plugins/channeltx/modwfm/wfmmod.h index 15bcb62c1..bf9af824d 100644 --- a/plugins/channeltx/modwfm/wfmmod.h +++ b/plugins/channeltx/modwfm/wfmmod.h @@ -35,6 +35,10 @@ #include "wfmmodsettings.h" +class DeviceSinkAPI; +class ThreadedBasebandSampleSource; +class UpChannelizer; + class WFMMod : public BasebandSampleSource { Q_OBJECT @@ -71,6 +75,29 @@ public: { } }; + 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 MsgConfigureFileSourceName : public Message { MESSAGE_CLASS_DECLARATION @@ -199,7 +226,7 @@ public: //================================================================= - WFMMod(); + WFMMod(DeviceSinkAPI *deviceAPI); ~WFMMod(); virtual void pull(Sample& sample); @@ -228,6 +255,10 @@ private: RSRunning }; + DeviceSinkAPI* m_deviceAPI; + ThreadedBasebandSampleSource* m_threadedChannelizer; + UpChannelizer* m_channelizer; + WFMModSettings m_settings; NCO m_carrierNco; diff --git a/plugins/channeltx/modwfm/wfmmodgui.cpp b/plugins/channeltx/modwfm/wfmmodgui.cpp index b1af2bfb9..eb2715f0e 100644 --- a/plugins/channeltx/modwfm/wfmmodgui.cpp +++ b/plugins/channeltx/modwfm/wfmmodgui.cpp @@ -22,15 +22,15 @@ #include "device/devicesinkapi.h" #include "dsp/upchannelizer.h" - #include "dsp/threadedbasebandsamplesource.h" -#include "ui_wfmmodgui.h" #include "plugin/pluginapi.h" #include "util/simpleserializer.h" #include "util/db.h" #include "gui/basicchannelsettingswidget.h" #include "dsp/dspengine.h" #include "mainwindow.h" + +#include "ui_wfmmodgui.h" #include "wfmmodgui.h" const QString WFMModGUI::m_channelID = "sdrangel.channeltx.modwfm"; @@ -305,12 +305,8 @@ WFMModGUI::WFMModGUI(PluginAPI* pluginAPI, DeviceSinkAPI *deviceAPI, QWidget* pa connect(this, SIGNAL(widgetRolled(QWidget*,bool)), this, SLOT(onWidgetRolled(QWidget*,bool))); connect(this, SIGNAL(menuDoubleClickEvent()), this, SLOT(onMenuDoubleClicked())); - m_wfmMod = new WFMMod(); + m_wfmMod = new WFMMod(m_deviceAPI); m_wfmMod->setMessageQueueToGUI(getInputMessageQueue()); - m_channelizer = new UpChannelizer(m_wfmMod); - m_threadedChannelizer = new ThreadedBasebandSampleSource(m_channelizer, this); - //m_pluginAPI->addThreadedSink(m_threadedChannelizer); - m_deviceAPI->addThreadedSource(m_threadedChannelizer); connect(&m_pluginAPI->getMainWindow()->getMasterTimer(), SIGNAL(timeout()), this, SLOT(tick())); @@ -318,12 +314,6 @@ WFMModGUI::WFMModGUI(PluginAPI* pluginAPI, DeviceSinkAPI *deviceAPI, QWidget* pa ui->deltaFrequency->setColorMapper(ColorMapper(ColorMapper::GrayGold)); ui->deltaFrequency->setValueRange(false, 7, -9999999, 9999999); - //m_channelMarker = new ChannelMarker(this); -// m_channelMarker.setColor(Qt::blue); -// m_channelMarker.setBandwidth(m_rfBW[ui->rfBW->currentIndex()]); -// m_channelMarker.setCenterFrequency(0); -// m_channelMarker.setVisible(true); - m_channelMarker.setTitle("WFM Modulator"); m_channelMarker.setVisible(true); @@ -353,11 +343,7 @@ WFMModGUI::WFMModGUI(PluginAPI* pluginAPI, DeviceSinkAPI *deviceAPI, QWidget* pa WFMModGUI::~WFMModGUI() { m_deviceAPI->removeChannelInstance(this); - m_deviceAPI->removeThreadedSource(m_threadedChannelizer); - delete m_threadedChannelizer; - delete m_channelizer; delete m_wfmMod; - //delete m_channelMarker; delete ui; } @@ -372,9 +358,10 @@ void WFMModGUI::applySettings(bool force) { setTitleColor(m_channelMarker.getColor()); - m_channelizer->configure(m_channelizer->getInputMessageQueue(), - requiredBW(WFMModSettings::getRFBW(ui->rfBW->currentIndex())), - m_channelMarker.getCenterFrequency()); + WFMMod::MsgConfigureChannelizer *msgChan = WFMMod::MsgConfigureChannelizer::create( + requiredBW(WFMModSettings::getRFBW(ui->rfBW->currentIndex())), + m_channelMarker.getCenterFrequency()); + m_wfmMod->getInputMessageQueue()->push(msgChan); ui->deltaFrequency->setValue(m_channelMarker.getCenterFrequency()); diff --git a/plugins/channeltx/modwfm/wfmmodgui.h b/plugins/channeltx/modwfm/wfmmodgui.h index 38f7e28a4..5a56efabb 100644 --- a/plugins/channeltx/modwfm/wfmmodgui.h +++ b/plugins/channeltx/modwfm/wfmmodgui.h @@ -92,8 +92,8 @@ private: bool m_basicSettingsShown; bool m_doApplySettings; - ThreadedBasebandSampleSource* m_threadedChannelizer; - UpChannelizer* m_channelizer; +// ThreadedBasebandSampleSource* m_threadedChannelizer; +// UpChannelizer* m_channelizer; WFMMod* m_wfmMod; MovingAverage m_channelPowerDbAvg;