diff --git a/plugins/channelrx/udpsrc/udpsrc.cpp b/plugins/channelrx/udpsrc/udpsrc.cpp index 7d697f14e..2bba92aca 100644 --- a/plugins/channelrx/udpsrc/udpsrc.cpp +++ b/plugins/channelrx/udpsrc/udpsrc.cpp @@ -18,15 +18,18 @@ #include #include -#include "dsp/downchannelizer.h" #include "dsp/dspengine.h" #include "util/db.h" +#include "dsp/downchannelizer.h" +#include "dsp/threadedbasebandsamplesink.h" +#include "device/devicesourceapi.h" #include "udpsrcgui.h" #include "udpsrc.h" const Real UDPSrc::m_agcTarget = 16384.0f; +MESSAGE_CLASS_DEFINITION(UDPSrc::MsgConfigureChannelizer, Message) MESSAGE_CLASS_DEFINITION(UDPSrc::MsgUDPSrcConfigure, Message) MESSAGE_CLASS_DEFINITION(UDPSrc::MsgUDPSrcConfigureImmediate, Message) MESSAGE_CLASS_DEFINITION(UDPSrc::MsgUDPSrcSpectrum, Message) @@ -68,6 +71,11 @@ UDPSrc::UDPSrc(DeviceSourceAPI *deviceAPI) : m_scale = 0; m_magsq = 0; m_inMagsq = 0; + + m_channelizer = new DownChannelizer(this); + m_threadedChannelizer = new ThreadedBasebandSampleSink(m_channelizer, this); + m_deviceAPI->addThreadedSink(m_threadedChannelizer); + UDPFilter = new fftfilt(0.0, (m_config.m_rfBandwidth / 2.0) / m_config.m_outputSampleRate, udpBlockSize); m_phaseDiscri.setFMScaling((float) m_config. m_outputSampleRate / (2.0f * m_config.m_fmDeviation)); @@ -96,6 +104,9 @@ UDPSrc::~UDPSrc() delete[] m_udpAudioBuf; if (UDPFilter) delete UDPFilter; if (m_running.m_audioActive) DSPEngine::instance()->removeAudioSink(&m_audioFifo); + m_deviceAPI->removeThreadedSink(m_threadedChannelizer); + delete m_threadedChannelizer; + delete m_channelizer; } /** what needs the "apply" button validation */ @@ -363,6 +374,16 @@ bool UDPSrc::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()); + + return true; + } else if (MsgUDPSrcConfigureImmediate::match(cmd)) { MsgUDPSrcConfigureImmediate& cfg = (MsgUDPSrcConfigureImmediate&) cmd; diff --git a/plugins/channelrx/udpsrc/udpsrc.h b/plugins/channelrx/udpsrc/udpsrc.h index aec5b9ff8..61e283120 100644 --- a/plugins/channelrx/udpsrc/udpsrc.h +++ b/plugins/channelrx/udpsrc/udpsrc.h @@ -35,11 +35,36 @@ class QUdpSocket; class DeviceSourceAPI; +class ThreadedBasebandSampleSink; +class DownChannelizer; class UDPSrc : public BasebandSampleSink { Q_OBJECT 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) + { } + }; + enum SampleFormat { FormatS16LE, FormatNFM, @@ -294,6 +319,8 @@ protected: Config m_running; DeviceSourceAPI *m_deviceAPI; + ThreadedBasebandSampleSink* m_threadedChannelizer; + DownChannelizer* m_channelizer; QUdpSocket *m_audioSocket; diff --git a/plugins/channelrx/udpsrc/udpsrcgui.cpp b/plugins/channelrx/udpsrc/udpsrcgui.cpp index 9d9a53c45..6f9e46d56 100644 --- a/plugins/channelrx/udpsrc/udpsrcgui.cpp +++ b/plugins/channelrx/udpsrc/udpsrcgui.cpp @@ -18,8 +18,6 @@ #include "udpsrcgui.h" #include "device/devicesourceapi.h" -#include "dsp/downchannelizer.h" -#include "dsp/threadedbasebandsamplesink.h" #include "plugin/pluginapi.h" #include "dsp/spectrumvis.h" #include "dsp/dspengine.h" @@ -273,9 +271,6 @@ UDPSrcGUI::UDPSrcGUI(PluginAPI* pluginAPI, DeviceSourceAPI *deviceAPI, QWidget* m_spectrumVis = new SpectrumVis(ui->glSpectrum); m_udpSrc = new UDPSrc(m_deviceAPI); m_udpSrc->setSpectrum(m_spectrumVis); - m_channelizer = new DownChannelizer(m_udpSrc); - m_threadedChannelizer = new ThreadedBasebandSampleSink(m_channelizer, this); - m_deviceAPI->addThreadedSink(m_threadedChannelizer); ui->fmDeviation->setEnabled(false); @@ -293,7 +288,6 @@ UDPSrcGUI::UDPSrcGUI(PluginAPI* pluginAPI, DeviceSourceAPI *deviceAPI, QWidget* ui->glSpectrum->connectTimer(m_pluginAPI->getMainWindow()->getMasterTimer()); connect(&m_pluginAPI->getMainWindow()->getMasterTimer(), SIGNAL(timeout()), this, SLOT(tick())); - //m_channelMarker = new ChannelMarker(this); m_channelMarker.setBandwidth(16000); m_channelMarker.setCenterFrequency(0); m_channelMarker.setTitle("UDP Sample Source"); @@ -319,12 +313,8 @@ UDPSrcGUI::UDPSrcGUI(PluginAPI* pluginAPI, DeviceSourceAPI *deviceAPI, QWidget* UDPSrcGUI::~UDPSrcGUI() { m_deviceAPI->removeChannelInstance(this); - m_deviceAPI->removeThreadedSink(m_threadedChannelizer); - delete m_threadedChannelizer; - delete m_channelizer; delete m_udpSrc; delete m_spectrumVis; - //delete m_channelMarker; delete ui; } @@ -402,9 +392,9 @@ void UDPSrcGUI::applySettings(bool force) connect(&m_channelMarker, SIGNAL(changed()), this, SLOT(channelMarkerChanged())); ui->glSpectrum->setSampleRate(outputSampleRate); - m_channelizer->configure(m_channelizer->getInputMessageQueue(), - outputSampleRate, - m_channelMarker.getCenterFrequency()); + UDPSrc::MsgConfigureChannelizer* channelConfigMsg = UDPSrc::MsgConfigureChannelizer::create( + outputSampleRate, m_channelMarker.getCenterFrequency()); + m_udpSrc->getInputMessageQueue()->push(channelConfigMsg); UDPSrc::SampleFormat sampleFormat; diff --git a/plugins/channelrx/udpsrc/udpsrcgui.h b/plugins/channelrx/udpsrc/udpsrcgui.h index 55e51243c..56de35ff0 100644 --- a/plugins/channelrx/udpsrc/udpsrcgui.h +++ b/plugins/channelrx/udpsrc/udpsrcgui.h @@ -29,8 +29,6 @@ class PluginAPI; class DeviceSourceAPI; -class ThreadedBasebandSampleSink; -class DownChannelizer; class UDPSrc; class SpectrumVis; @@ -103,8 +101,6 @@ private: MessageQueue m_inputMessageQueue; // RF path - ThreadedBasebandSampleSink* m_threadedChannelizer; - DownChannelizer* m_channelizer; SpectrumVis* m_spectrumVis; explicit UDPSrcGUI(PluginAPI* pluginAPI, DeviceSourceAPI *deviceAPI, QWidget* parent = 0);