diff --git a/plugins/channelrx/demodssb/ssbdemod.cpp b/plugins/channelrx/demodssb/ssbdemod.cpp index 387b7bdb4..715d1bd40 100644 --- a/plugins/channelrx/demodssb/ssbdemod.cpp +++ b/plugins/channelrx/demodssb/ssbdemod.cpp @@ -16,19 +16,25 @@ // along with this program. If not, see . // /////////////////////////////////////////////////////////////////////////////////// -#include "ssbdemod.h" -#include #include #include #include + #include "audio/audiooutput.h" #include "dsp/dspengine.h" +#include +#include "dsp/threadedbasebandsamplesink.h" +#include "device/devicesourceapi.h" #include "util/db.h" -MESSAGE_CLASS_DEFINITION(SSBDemod::MsgConfigureSSBDemod, Message) +#include "ssbdemod.h" -SSBDemod::SSBDemod(BasebandSampleSink* sampleSink) : +MESSAGE_CLASS_DEFINITION(SSBDemod::MsgConfigureSSBDemod, Message) +MESSAGE_CLASS_DEFINITION(SSBDemod::MsgConfigureChannelizer, Message) + +SSBDemod::SSBDemod(DeviceSourceAPI *deviceAPI) : + m_deviceAPI(deviceAPI), m_audioBinaual(false), m_audioFlipChannels(false), m_dsb(false), @@ -40,7 +46,7 @@ SSBDemod::SSBDemod(BasebandSampleSink* sampleSink) : m_agcPowerThreshold(1e-2), m_agcThresholdGate(0), m_audioActive(false), - m_sampleSink(sampleSink), + m_sampleSink(0), m_audioFifo(24000), m_settingsMutex(QMutex::Recursive) { @@ -75,6 +81,10 @@ SSBDemod::SSBDemod(BasebandSampleSink* sampleSink) : SSBFilter = new fftfilt(m_LowCutoff / m_audioSampleRate, m_Bandwidth / m_audioSampleRate, ssbFftLen); DSBFilter = new fftfilt((2.0f * m_Bandwidth) / m_audioSampleRate, 2 * ssbFftLen); + m_channelizer = new DownChannelizer(this); + m_threadedChannelizer = new ThreadedBasebandSampleSink(m_channelizer, this); + m_deviceAPI->addThreadedSink(m_threadedChannelizer); + DSPEngine::instance()->addAudioSink(&m_audioFifo); } @@ -84,6 +94,10 @@ SSBDemod::~SSBDemod() if (DSBFilter) delete DSBFilter; DSPEngine::instance()->removeAudioSink(&m_audioFifo); + + m_deviceAPI->removeThreadedSink(m_threadedChannelizer); + delete m_threadedChannelizer; + delete m_channelizer; } void SSBDemod::configure(MessageQueue* messageQueue, @@ -284,6 +298,16 @@ bool SSBDemod::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 (MsgConfigureSSBDemod::match(cmd)) { MsgConfigureSSBDemod& cfg = (MsgConfigureSSBDemod&) cmd; diff --git a/plugins/channelrx/demodssb/ssbdemod.h b/plugins/channelrx/demodssb/ssbdemod.h index dd6e4f74b..2e23568d4 100644 --- a/plugins/channelrx/demodssb/ssbdemod.h +++ b/plugins/channelrx/demodssb/ssbdemod.h @@ -31,10 +31,38 @@ #define ssbFftLen 1024 #define agcTarget 3276.8 // -10 dB amplitude => -20 dB power: center of normal signal +class DeviceSourceAPI; +class ThreadedBasebandSampleSink; +class DownChannelizer; + class SSBDemod : public BasebandSampleSink { public: - SSBDemod(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) + { } + }; + + SSBDemod(DeviceSourceAPI *deviceAPI); virtual ~SSBDemod(); + void setSampleSink(BasebandSampleSink* sampleSink) { m_sampleSink = sampleSink; } void configure(MessageQueue* messageQueue, Real Bandwidth, @@ -164,6 +192,10 @@ private: { } }; + DeviceSourceAPI *m_deviceAPI; + ThreadedBasebandSampleSink* m_threadedChannelizer; + DownChannelizer* m_channelizer; + Real m_Bandwidth; Real m_LowCutoff; Real m_volume; diff --git a/plugins/channelrx/demodssb/ssbdemodgui.cpp b/plugins/channelrx/demodssb/ssbdemodgui.cpp index 2af1b61a4..de143e298 100644 --- a/plugins/channelrx/demodssb/ssbdemodgui.cpp +++ b/plugins/channelrx/demodssb/ssbdemodgui.cpp @@ -2,11 +2,9 @@ #include "ssbdemodgui.h" #include -#include #include #include -#include "dsp/threadedbasebandsamplesink.h" #include "ui_ssbdemodgui.h" #include "ui_ssbdemodgui.h" #include "dsp/spectrumvis.h" @@ -373,10 +371,9 @@ SSBDemodGUI::SSBDemodGUI(PluginAPI* pluginAPI, DeviceSourceAPI *deviceAPI, QWidg connect(this, SIGNAL(menuDoubleClickEvent()), this, SLOT(onMenuDoubleClicked())); m_spectrumVis = new SpectrumVis(ui->glSpectrum); - m_ssbDemod = new SSBDemod(m_spectrumVis); - m_channelizer = new DownChannelizer(m_ssbDemod); - m_threadedChannelizer = new ThreadedBasebandSampleSink(m_channelizer, this); - m_deviceAPI->addThreadedSink(m_threadedChannelizer); + m_ssbDemod = new SSBDemod(m_deviceAPI); + m_ssbDemod->setMessageQueueToGUI(getInputMessageQueue()); + m_ssbDemod->setSampleSink(m_spectrumVis); ui->deltaFrequencyLabel->setText(QString("%1f").arg(QChar(0x94, 0x03))); ui->deltaFrequency->setColorMapper(ColorMapper(ColorMapper::GrayGold)); @@ -389,7 +386,6 @@ SSBDemodGUI::SSBDemodGUI(PluginAPI* pluginAPI, DeviceSourceAPI *deviceAPI, QWidg connect(&m_pluginAPI->getMainWindow()->getMasterTimer(), SIGNAL(timeout()), this, SLOT(tick())); - //m_channelMarker = new ChannelMarker(this); m_channelMarker.setColor(Qt::green); m_channelMarker.setBandwidth(m_rate); m_channelMarker.setSidebands(ChannelMarker::usb); @@ -413,12 +409,8 @@ SSBDemodGUI::SSBDemodGUI(PluginAPI* pluginAPI, DeviceSourceAPI *deviceAPI, QWidg SSBDemodGUI::~SSBDemodGUI() { m_deviceAPI->removeChannelInstance(this); - m_deviceAPI->removeThreadedSink(m_threadedChannelizer); - delete m_threadedChannelizer; - delete m_channelizer; delete m_ssbDemod; delete m_spectrumVis; - //delete m_channelMarker; delete ui; } @@ -511,9 +503,9 @@ void SSBDemodGUI::applySettings() setTitleColor(m_channelMarker.getColor()); ui->deltaFrequency->setValue(m_channelMarker.getCenterFrequency()); - m_channelizer->configure(m_channelizer->getInputMessageQueue(), - 48000, - m_channelMarker.getCenterFrequency()); + SSBDemod::MsgConfigureChannelizer* channelConfigMsg = SSBDemod::MsgConfigureChannelizer::create( + 48000, m_channelMarker.getCenterFrequency()); + m_ssbDemod->getInputMessageQueue()->push(channelConfigMsg); m_ssbDemod->configure(m_ssbDemod->getInputMessageQueue(), ui->BW->value() * 100.0, diff --git a/plugins/channelrx/demodssb/ssbdemodgui.h b/plugins/channelrx/demodssb/ssbdemodgui.h index e59bf74c2..626bc0112 100644 --- a/plugins/channelrx/demodssb/ssbdemodgui.h +++ b/plugins/channelrx/demodssb/ssbdemodgui.h @@ -11,8 +11,6 @@ class PluginAPI; class DeviceSourceAPI; class AudioFifo; -class ThreadedBasebandSampleSink; -class DownChannelizer; class SSBDemod; class SpectrumVis; @@ -76,8 +74,6 @@ private: bool m_squelchOpen; uint32_t m_tickCount; - ThreadedBasebandSampleSink* m_threadedChannelizer; - DownChannelizer* m_channelizer; SSBDemod* m_ssbDemod; SpectrumVis* m_spectrumVis; MessageQueue m_inputMessageQueue;