diff --git a/plugins/channelrx/chanalyzer/chanalyzer.cpp b/plugins/channelrx/chanalyzer/chanalyzer.cpp index 641f75037..d7c42629f 100644 --- a/plugins/channelrx/chanalyzer/chanalyzer.cpp +++ b/plugins/channelrx/chanalyzer/chanalyzer.cpp @@ -14,19 +14,25 @@ // along with this program. If not, see . // /////////////////////////////////////////////////////////////////////////////////// -#include "../../channelrx/chanalyzer/chanalyzer.h" +#include "chanalyzer.h" -#include #include #include #include + +#include +#include "dsp/threadedbasebandsamplesink.h" +#include "device/devicesourceapi.h" #include "audio/audiooutput.h" MESSAGE_CLASS_DEFINITION(ChannelAnalyzer::MsgConfigureChannelAnalyzer, Message) +MESSAGE_CLASS_DEFINITION(ChannelAnalyzer::MsgConfigureChannelizer, Message) +MESSAGE_CLASS_DEFINITION(ChannelAnalyzer::MsgReportChannelSampleRateChanged, Message) -ChannelAnalyzer::ChannelAnalyzer(BasebandSampleSink* sampleSink) : - m_sampleSink(sampleSink), +ChannelAnalyzer::ChannelAnalyzer(DeviceSourceAPI *deviceAPI) : + m_deviceAPI(deviceAPI), + m_sampleSink(0), m_settingsMutex(QMutex::Recursive) { m_Bandwidth = 5000; @@ -42,12 +48,20 @@ ChannelAnalyzer::ChannelAnalyzer(BasebandSampleSink* sampleSink) : m_magsq = 0; SSBFilter = new fftfilt(m_LowCutoff / m_sampleRate, m_Bandwidth / m_sampleRate, ssbFftLen); DSBFilter = new fftfilt(m_Bandwidth / m_sampleRate, 2*ssbFftLen); + + 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); } ChannelAnalyzer::~ChannelAnalyzer() { if (SSBFilter) delete SSBFilter; if (DSBFilter) delete DSBFilter; + m_deviceAPI->removeThreadedSink(m_threadedChannelizer); + delete m_threadedChannelizer; + delete m_channelizer; } void ChannelAnalyzer::configure(MessageQueue* messageQueue, @@ -130,6 +144,12 @@ void ChannelAnalyzer::stop() { } +void ChannelAnalyzer::channelSampleRateChanged() +{ + MsgReportChannelSampleRateChanged *msg = MsgReportChannelSampleRateChanged::create(); + getMessageQueueToGUI()->push(msg); +} + bool ChannelAnalyzer::handleMessage(const Message& cmd) { float band, lowCutoff; @@ -148,6 +168,16 @@ bool ChannelAnalyzer::handleMessage(const Message& cmd) return true; } + else if (MsgConfigureChannelizer::match(cmd)) + { + MsgConfigureChannelizer& cfg = (MsgConfigureChannelizer&) cmd; + + m_channelizer->configure(m_channelizer->getInputMessageQueue(), + m_channelizer->getInputSampleRate(), + cfg.getCenterFrequency()); + + return true; + } else if (MsgConfigureChannelAnalyzer::match(cmd)) { MsgConfigureChannelAnalyzer& cfg = (MsgConfigureChannelAnalyzer&) cmd; diff --git a/plugins/channelrx/chanalyzer/chanalyzer.h b/plugins/channelrx/chanalyzer/chanalyzer.h index adc2c1361..7dd26732f 100644 --- a/plugins/channelrx/chanalyzer/chanalyzer.h +++ b/plugins/channelrx/chanalyzer/chanalyzer.h @@ -27,10 +27,87 @@ #define ssbFftLen 1024 +class DeviceSourceAPI; +class ThreadedBasebandSampleSink; +class DownChannelizer; + class ChannelAnalyzer : public BasebandSampleSink { public: - ChannelAnalyzer(BasebandSampleSink* m_sampleSink); + class MsgConfigureChannelAnalyzer : public Message { + MESSAGE_CLASS_DECLARATION + + public: + Real getBandwidth() const { return m_Bandwidth; } + Real getLoCutoff() const { return m_LowCutoff; } + int getSpanLog2() const { return m_spanLog2; } + bool getSSB() const { return m_ssb; } + + static MsgConfigureChannelAnalyzer* create(Real Bandwidth, + Real LowCutoff, + int spanLog2, + bool ssb) + { + return new MsgConfigureChannelAnalyzer(Bandwidth, LowCutoff, spanLog2, ssb); + } + + private: + Real m_Bandwidth; + Real m_LowCutoff; + int m_spanLog2; + bool m_ssb; + + MsgConfigureChannelAnalyzer(Real Bandwidth, + Real LowCutoff, + int spanLog2, + bool ssb) : + Message(), + m_Bandwidth(Bandwidth), + m_LowCutoff(LowCutoff), + m_spanLog2(spanLog2), + m_ssb(ssb) + { } + }; + + class MsgConfigureChannelizer : public Message { + MESSAGE_CLASS_DECLARATION + + public: + int getCenterFrequency() const { return m_centerFrequency; } + + static MsgConfigureChannelizer* create(int centerFrequency) + { + return new MsgConfigureChannelizer(centerFrequency); + } + + private: + int m_centerFrequency; + + MsgConfigureChannelizer(int centerFrequency) : + Message(), + m_centerFrequency(centerFrequency) + { } + }; + + class MsgReportChannelSampleRateChanged : public Message { + MESSAGE_CLASS_DECLARATION + + public: + + static MsgReportChannelSampleRateChanged* create() + { + return new MsgReportChannelSampleRateChanged(); + } + + private: + + MsgReportChannelSampleRateChanged() : + Message() + { } + }; + + ChannelAnalyzer(DeviceSourceAPI *deviceAPI); virtual ~ChannelAnalyzer(); + void setSampleSink(BasebandSampleSink* sampleSink) { m_sampleSink = sampleSink; } void configure(MessageQueue* messageQueue, Real Bandwidth, @@ -46,41 +123,13 @@ public: virtual void stop(); virtual bool handleMessage(const Message& cmd); +private slots: + void channelSampleRateChanged(); + private: - class MsgConfigureChannelAnalyzer : public Message { - MESSAGE_CLASS_DECLARATION - - public: - Real getBandwidth() const { return m_Bandwidth; } - Real getLoCutoff() const { return m_LowCutoff; } - int getSpanLog2() const { return m_spanLog2; } - bool getSSB() const { return m_ssb; } - - static MsgConfigureChannelAnalyzer* create(Real Bandwidth, - Real LowCutoff, - int spanLog2, - bool ssb) - { - return new MsgConfigureChannelAnalyzer(Bandwidth, LowCutoff, spanLog2, ssb); - } - - private: - Real m_Bandwidth; - Real m_LowCutoff; - int m_spanLog2; - bool m_ssb; - - MsgConfigureChannelAnalyzer(Real Bandwidth, - Real LowCutoff, - int spanLog2, - bool ssb) : - Message(), - m_Bandwidth(Bandwidth), - m_LowCutoff(LowCutoff), - m_spanLog2(spanLog2), - m_ssb(ssb) - { } - }; + DeviceSourceAPI *m_deviceAPI; + ThreadedBasebandSampleSink* m_threadedChannelizer; + DownChannelizer* m_channelizer; Real m_Bandwidth; Real m_LowCutoff; diff --git a/plugins/channelrx/chanalyzer/chanalyzergui.cpp b/plugins/channelrx/chanalyzer/chanalyzergui.cpp index 0cc9b561d..147edac22 100644 --- a/plugins/channelrx/chanalyzer/chanalyzergui.cpp +++ b/plugins/channelrx/chanalyzer/chanalyzergui.cpp @@ -154,11 +154,32 @@ bool ChannelAnalyzerGUI::deserialize(const QByteArray& data) } } -bool ChannelAnalyzerGUI::handleMessage(const Message& message __attribute__((unused))) +bool ChannelAnalyzerGUI::handleMessage(const Message& message) { + if (ChannelAnalyzer::MsgReportChannelSampleRateChanged::match(message)) + { + setNewRate(m_spanLog2); + return true; + } + return false; } +void ChannelAnalyzerGUI::handleInputMessages() +{ + Message* message; + + while ((message = getInputMessageQueue()->pop()) != 0) + { + qDebug("ChannelAnalyzerGUI::handleInputMessages: message: %s", message->getIdentifier()); + + if (handleMessage(*message)) + { + delete message; + } + } +} + void ChannelAnalyzerGUI::viewChanged() { applySettings(); @@ -171,11 +192,6 @@ void ChannelAnalyzerGUI::tick() ui->channelPower->setText(QString::number(m_channelPowerDbAvg.average(), 'f', 1)); } -void ChannelAnalyzerGUI::channelSampleRateChanged() -{ - setNewRate(m_spanLog2); -} - void ChannelAnalyzerGUI::on_deltaMinus_toggled(bool minus) { int deltaFrequency = m_channelMarker.getCenterFrequency(); @@ -326,11 +342,9 @@ ChannelAnalyzerGUI::ChannelAnalyzerGUI(PluginAPI* pluginAPI, DeviceSourceAPI *de m_spectrumVis = new SpectrumVis(ui->glSpectrum); m_scopeVis = new ScopeVis(ui->glScope); m_spectrumScopeComboVis = new SpectrumScopeComboVis(m_spectrumVis, m_scopeVis); - m_channelAnalyzer = new ChannelAnalyzer(m_spectrumScopeComboVis); - m_channelizer = new DownChannelizer(m_channelAnalyzer); - m_threadedChannelizer = new ThreadedBasebandSampleSink(m_channelizer, this); - connect(m_channelizer, SIGNAL(inputSampleRateChanged()), this, SLOT(channelSampleRateChanged())); - m_deviceAPI->addThreadedSink(m_threadedChannelizer); + m_channelAnalyzer = new ChannelAnalyzer(m_deviceAPI); + m_channelAnalyzer->setSampleSink(m_spectrumScopeComboVis); + m_channelAnalyzer->setMessageQueueToGUI(getInputMessageQueue()); ui->deltaFrequency->setColorMapper(ColorMapper(ColorMapper::ReverseGold)); ui->deltaFrequency->setValueRange(7, 0U, 9999999U); @@ -361,6 +375,8 @@ ChannelAnalyzerGUI::ChannelAnalyzerGUI(PluginAPI* pluginAPI, DeviceSourceAPI *de ui->spectrumGUI->setBuddies(m_spectrumVis->getInputMessageQueue(), m_spectrumVis, ui->glSpectrum); ui->scopeGUI->setBuddies(m_scopeVis->getInputMessageQueue(), m_scopeVis, ui->glScope); + connect(getInputMessageQueue(), SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages())); + applySettings(); setNewRate(m_spanLog2); } @@ -368,9 +384,6 @@ ChannelAnalyzerGUI::ChannelAnalyzerGUI(PluginAPI* pluginAPI, DeviceSourceAPI *de ChannelAnalyzerGUI::~ChannelAnalyzerGUI() { m_deviceAPI->removeChannelInstance(this); - m_deviceAPI->removeThreadedSink(m_threadedChannelizer); - delete m_threadedChannelizer; - delete m_channelizer; delete m_channelAnalyzer; delete m_spectrumVis; delete m_scopeVis; @@ -457,9 +470,8 @@ void ChannelAnalyzerGUI::applySettings() ui->deltaFrequency->setValue(abs(m_channelMarker.getCenterFrequency())); ui->deltaMinus->setChecked(m_channelMarker.getCenterFrequency() < 0); - m_channelizer->configure(m_channelizer->getInputMessageQueue(), - m_channelizer->getInputSampleRate(), - m_channelMarker.getCenterFrequency()); + ChannelAnalyzer::MsgConfigureChannelizer *msg = ChannelAnalyzer::MsgConfigureChannelizer::create(m_channelMarker.getCenterFrequency()); + m_channelAnalyzer->getInputMessageQueue()->push(msg); m_channelAnalyzer->configure(m_channelAnalyzer->getInputMessageQueue(), ui->BW->value() * 100.0, diff --git a/plugins/channelrx/chanalyzer/chanalyzergui.h b/plugins/channelrx/chanalyzer/chanalyzergui.h index 36d00b8ce..c13238f40 100644 --- a/plugins/channelrx/chanalyzer/chanalyzergui.h +++ b/plugins/channelrx/chanalyzer/chanalyzergui.h @@ -59,7 +59,6 @@ public: private slots: void viewChanged(); - void channelSampleRateChanged(); void on_deltaFrequency_changed(quint64 value); void on_deltaMinus_toggled(bool minus); void on_BW_valueChanged(int value); @@ -68,6 +67,7 @@ private slots: void on_ssb_toggled(bool checked); void onWidgetRolled(QWidget* widget, bool rollDown); void onMenuDoubleClicked(); + void handleInputMessages(); void tick(); private: @@ -81,8 +81,8 @@ private: int m_spanLog2; MovingAverage m_channelPowerDbAvg; - ThreadedBasebandSampleSink* m_threadedChannelizer; - DownChannelizer* m_channelizer; +// ThreadedBasebandSampleSink* m_threadedChannelizer; +// DownChannelizer* m_channelizer; ChannelAnalyzer* m_channelAnalyzer; SpectrumScopeComboVis* m_spectrumScopeComboVis; SpectrumVis* m_spectrumVis;