diff --git a/plugins/channelrx/chanalyzer/chanalyzer.cpp b/plugins/channelrx/chanalyzer/chanalyzer.cpp index c8cc07706..4899e6609 100644 --- a/plugins/channelrx/chanalyzer/chanalyzer.cpp +++ b/plugins/channelrx/chanalyzer/chanalyzer.cpp @@ -34,6 +34,7 @@ const QString ChannelAnalyzer::m_channelId = "ChannelAnalyzer"; ChannelAnalyzer::ChannelAnalyzer(DeviceAPI *deviceAPI) : ChannelAPI(m_channelIdURI, ChannelAPI::StreamSingleSink), m_deviceAPI(deviceAPI), + m_spectrumVis(SDR_RX_SCALEF), m_basebandSampleRate(0) { qDebug("ChannelAnalyzer::ChannelAnalyzer"); @@ -41,6 +42,7 @@ ChannelAnalyzer::ChannelAnalyzer(DeviceAPI *deviceAPI) : m_thread = new QThread(this); m_basebandSink = new ChannelAnalyzerBaseband(); + m_basebandSink->setSampleSink(&m_spectrumVis); m_basebandSink->moveToThread(m_thread); applySettings(m_settings, true); diff --git a/plugins/channelrx/chanalyzer/chanalyzer.h b/plugins/channelrx/chanalyzer/chanalyzer.h index aa01a79d5..3cfe8ce2e 100644 --- a/plugins/channelrx/chanalyzer/chanalyzer.h +++ b/plugins/channelrx/chanalyzer/chanalyzer.h @@ -22,6 +22,7 @@ #include #include "dsp/basebandsamplesink.h" +#include "dsp/spectrumvis.h" #include "channel/channelapi.h" #include "util/message.h" #include "util/movingaverage.h" @@ -58,7 +59,7 @@ public: ChannelAnalyzer(DeviceAPI *deviceAPI); virtual ~ChannelAnalyzer(); virtual void destroy() { delete this; } - void setSampleSink(BasebandSampleSink* sampleSink) { m_basebandSink->setSampleSink(sampleSink); } + SpectrumVis *getSpectrumVis() { return &m_spectrumVis; } int getChannelSampleRate() const { return m_basebandSink->getChannelSampleRate(); } int getDecimation() const { return 1<glSpectrum); + m_channelAnalyzer = (ChannelAnalyzer*) rxChannel; //new ChannelAnalyzer(m_deviceUISet->m_deviceSourceAPI); + m_spectrumVis = m_channelAnalyzer->getSpectrumVis(); + m_spectrumVis->setGLSpectrum(ui->glSpectrum); m_scopeVis = new ScopeVis(ui->glScope); m_spectrumScopeComboVis = new SpectrumScopeComboVis(m_spectrumVis, m_scopeVis); - m_channelAnalyzer = (ChannelAnalyzer*) rxChannel; //new ChannelAnalyzer(m_deviceUISet->m_deviceSourceAPI); - m_channelAnalyzer->setSampleSink(m_spectrumScopeComboVis); m_channelAnalyzer->setMessageQueueToGUI(getInputMessageQueue()); ui->deltaFrequencyLabel->setText(QString("%1f").arg(QChar(0x94, 0x03))); @@ -455,7 +455,6 @@ ChannelAnalyzerGUI::~ChannelAnalyzerGUI() { m_deviceUISet->removeRxChannelInstance(this); delete m_channelAnalyzer; // TODO: check this: when the GUI closes it has to delete the demodulator - delete m_spectrumVis; delete m_scopeVis; delete m_spectrumScopeComboVis; delete ui; diff --git a/plugins/channelrx/demodbfm/bfmdemod.cpp b/plugins/channelrx/demodbfm/bfmdemod.cpp index fce7a68fb..cd2a5050f 100644 --- a/plugins/channelrx/demodbfm/bfmdemod.cpp +++ b/plugins/channelrx/demodbfm/bfmdemod.cpp @@ -48,12 +48,14 @@ const int BFMDemod::m_udpBlockSize = 512; BFMDemod::BFMDemod(DeviceAPI *deviceAPI) : ChannelAPI(m_channelIdURI, ChannelAPI::StreamSingleSink), m_deviceAPI(deviceAPI), + m_spectrumVis(SDR_RX_SCALEF), m_basebandSampleRate(0) { setObjectName(m_channelId); m_thread = new QThread(this); m_basebandSink = new BFMDemodBaseband(); + m_basebandSink->setSpectrumSink(&m_spectrumVis); m_basebandSink->moveToThread(m_thread); applySettings(m_settings, true); diff --git a/plugins/channelrx/demodbfm/bfmdemod.h b/plugins/channelrx/demodbfm/bfmdemod.h index baf3ca7dc..a3d50433e 100644 --- a/plugins/channelrx/demodbfm/bfmdemod.h +++ b/plugins/channelrx/demodbfm/bfmdemod.h @@ -25,6 +25,7 @@ #include #include "dsp/basebandsamplesink.h" +#include "dsp/spectrumvis.h" #include "channel/channelapi.h" #include "util/message.h" @@ -69,7 +70,7 @@ public: BFMDemod(DeviceAPI *deviceAPI); virtual ~BFMDemod(); virtual void destroy() { delete this; } - void setSpectrumSink(BasebandSampleSink* spectrumSink) { m_basebandSink->setSpectrumSink(spectrumSink); } + SpectrumVis *getSpectrumVis() { return &m_spectrumVis; } void setBasebandMessageQueueToGUI(MessageQueue *messageQueue) { m_basebandSink->setMessageQueueToGUI(messageQueue); } virtual void feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool po); @@ -142,6 +143,7 @@ private: QThread *m_thread; BFMDemodBaseband* m_basebandSink; BFMDemodSettings m_settings; + SpectrumVis m_spectrumVis; int m_basebandSampleRate; //!< stored from device message used when starting baseband sink static const int m_udpBlockSize; diff --git a/plugins/channelrx/demodbfm/bfmdemodgui.cpp b/plugins/channelrx/demodbfm/bfmdemodgui.cpp index 2cad95cab..d2386ac74 100644 --- a/plugins/channelrx/demodbfm/bfmdemodgui.cpp +++ b/plugins/channelrx/demodbfm/bfmdemodgui.cpp @@ -117,6 +117,7 @@ bool BFMDemodGUI::handleMessage(const Message& message) qDebug("BFMDemodGUI::handleMessage: BFMDemodReport::MsgReportChannelSampleRateChanged: %d S/s", m_rate); ui->glSpectrum->setCenterFrequency(m_rate / 4); ui->glSpectrum->setSampleRate(m_rate / 2); + m_spectrumVis->configureDSP(m_rate / 4, m_rate / 2); return true; } else if (BFMDemod::MsgConfigureBFMDemod::match(message)) @@ -385,11 +386,11 @@ BFMDemodGUI::BFMDemodGUI(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, Baseban connect(this, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(onMenuDialogCalled(const QPoint &))); connect(getInputMessageQueue(), SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages())); - m_spectrumVis = new SpectrumVis(SDR_RX_SCALEF, ui->glSpectrum); m_bfmDemod = (BFMDemod*) rxChannel; //new BFMDemod(m_deviceUISet->m_deviceSourceAPI); + m_spectrumVis = m_bfmDemod->getSpectrumVis(); + m_spectrumVis->setGLSpectrum(ui->glSpectrum); m_bfmDemod->setMessageQueueToGUI(getInputMessageQueue()); m_bfmDemod->setBasebandMessageQueueToGUI(getInputMessageQueue()); - m_bfmDemod->setSpectrumSink(m_spectrumVis); ui->glSpectrum->setCenterFrequency(m_rate / 4); ui->glSpectrum->setSampleRate(m_rate / 2); @@ -406,6 +407,7 @@ BFMDemodGUI::BFMDemodGUI(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, Baseban SpectrumVis::AvgModeNone, // no averaging FFTWindow::BlackmanHarris, false); // logarithmic scale + m_spectrumVis->configureDSP(m_rate / 4, m_rate / 2); connect(&MainWindow::getInstance()->getMasterTimer(), SIGNAL(timeout()), this, SLOT(tick())); m_channelMarker.blockSignals(true); @@ -444,7 +446,6 @@ BFMDemodGUI::~BFMDemodGUI() { m_deviceUISet->removeRxChannelInstance(this); delete m_bfmDemod; // TODO: check this: when the GUI closes it has to delete the demodulator - delete m_spectrumVis; delete ui; } diff --git a/plugins/channelrx/demodfreedv/freedvdemod.cpp b/plugins/channelrx/demodfreedv/freedvdemod.cpp index e288389eb..0e08e5f38 100644 --- a/plugins/channelrx/demodfreedv/freedvdemod.cpp +++ b/plugins/channelrx/demodfreedv/freedvdemod.cpp @@ -42,12 +42,14 @@ const QString FreeDVDemod::m_channelId = "FreeDVDemod"; FreeDVDemod::FreeDVDemod(DeviceAPI *deviceAPI) : ChannelAPI(m_channelIdURI, ChannelAPI::StreamSingleSink), - m_deviceAPI(deviceAPI) + m_deviceAPI(deviceAPI), + m_spectrumVis(SDR_RX_SCALEF) { setObjectName(m_channelId); m_thread = new QThread(this); m_basebandSink = new FreeDVDemodBaseband(); + m_basebandSink->setSpectrumSink(&m_spectrumVis); m_basebandSink->moveToThread(m_thread); applySettings(m_settings, true); diff --git a/plugins/channelrx/demodfreedv/freedvdemod.h b/plugins/channelrx/demodfreedv/freedvdemod.h index b52c17379..75604076b 100644 --- a/plugins/channelrx/demodfreedv/freedvdemod.h +++ b/plugins/channelrx/demodfreedv/freedvdemod.h @@ -23,6 +23,7 @@ #include #include "dsp/basebandsamplesink.h" +#include "dsp/spectrumvis.h" #include "channel/channelapi.h" #include "util/message.h" #include "util/doublebufferfifo.h" @@ -76,7 +77,7 @@ public: FreeDVDemod(DeviceAPI *deviceAPI); virtual ~FreeDVDemod(); virtual void destroy() { delete this; } - void setSampleSink(BasebandSampleSink* spectrumSink) { m_basebandSink->setSpectrumSink(spectrumSink); } + SpectrumVis *getSpectrumVis() { return &m_spectrumVis; } virtual void feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool positiveOnly); virtual void start(); @@ -145,6 +146,7 @@ private: QThread *m_thread; FreeDVDemodBaseband *m_basebandSink; FreeDVDemodSettings m_settings; + SpectrumVis m_spectrumVis; int m_basebandSampleRate; //!< stored from device message used when starting baseband sink QNetworkAccessManager *m_networkManager; diff --git a/plugins/channelrx/demodfreedv/freedvdemodgui.cpp b/plugins/channelrx/demodfreedv/freedvdemodgui.cpp index 6e47a5f65..1b3a0bec2 100644 --- a/plugins/channelrx/demodfreedv/freedvdemodgui.cpp +++ b/plugins/channelrx/demodfreedv/freedvdemodgui.cpp @@ -275,9 +275,9 @@ FreeDVDemodGUI::FreeDVDemodGUI(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, B connect(this, SIGNAL(widgetRolled(QWidget*,bool)), this, SLOT(onWidgetRolled(QWidget*,bool))); connect(this, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(onMenuDialogCalled(const QPoint &))); - m_spectrumVis = new SpectrumVis(SDR_RX_SCALEF, ui->glSpectrum); m_freeDVDemod = (FreeDVDemod*) rxChannel; - m_freeDVDemod->setSampleSink(m_spectrumVis); + m_spectrumVis = m_freeDVDemod->getSpectrumVis(); + m_spectrumVis->setGLSpectrum(ui->glSpectrum); m_freeDVDemod->setMessageQueueToGUI(getInputMessageQueue()); m_freeDVDemod->propagateMessageQueueToGUI(); @@ -332,7 +332,6 @@ FreeDVDemodGUI::~FreeDVDemodGUI() { m_deviceUISet->removeRxChannelInstance(this); delete m_freeDVDemod; // TODO: check this: when the GUI closes it has to delete the demodulator - delete m_spectrumVis; delete ui; } diff --git a/plugins/channelrx/demodssb/ssbdemod.cpp b/plugins/channelrx/demodssb/ssbdemod.cpp index b799e7713..5b370c8e5 100644 --- a/plugins/channelrx/demodssb/ssbdemod.cpp +++ b/plugins/channelrx/demodssb/ssbdemod.cpp @@ -48,12 +48,14 @@ const QString SSBDemod::m_channelId = "SSBDemod"; SSBDemod::SSBDemod(DeviceAPI *deviceAPI) : ChannelAPI(m_channelIdURI, ChannelAPI::StreamSingleSink), m_deviceAPI(deviceAPI), + m_spectrumVis(SDR_RX_SCALEF), m_basebandSampleRate(0) { setObjectName(m_channelId); m_thread = new QThread(this); m_basebandSink = new SSBDemodBaseband(); + m_basebandSink->setSpectrumSink(&m_spectrumVis); m_basebandSink->moveToThread(m_thread); applySettings(m_settings, true); diff --git a/plugins/channelrx/demodssb/ssbdemod.h b/plugins/channelrx/demodssb/ssbdemod.h index d94239438..c82516d12 100644 --- a/plugins/channelrx/demodssb/ssbdemod.h +++ b/plugins/channelrx/demodssb/ssbdemod.h @@ -25,6 +25,7 @@ #include #include "dsp/basebandsamplesink.h" +#include "dsp/spectrumvis.h" #include "channel/channelapi.h" #include "util/message.h" @@ -65,7 +66,7 @@ public: SSBDemod(DeviceAPI *deviceAPI); virtual ~SSBDemod(); virtual void destroy() { delete this; } - void setSpectrumSink(BasebandSampleSink* spectrumSink) { m_basebandSink->setSpectrumSink(spectrumSink); } + SpectrumVis *getSpectrumVis() { return &m_spectrumVis; } virtual void feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool positiveOnly); virtual void start(); @@ -130,6 +131,7 @@ private: QThread *m_thread; SSBDemodBaseband* m_basebandSink; SSBDemodSettings m_settings; + SpectrumVis m_spectrumVis; int m_basebandSampleRate; //!< stored from device message used when starting baseband sink QNetworkAccessManager *m_networkManager; diff --git a/plugins/channelrx/demodssb/ssbdemodgui.cpp b/plugins/channelrx/demodssb/ssbdemodgui.cpp index c32c31b0b..77c1ddaa8 100644 --- a/plugins/channelrx/demodssb/ssbdemodgui.cpp +++ b/plugins/channelrx/demodssb/ssbdemodgui.cpp @@ -307,11 +307,11 @@ SSBDemodGUI::SSBDemodGUI(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, Baseban connect(this, SIGNAL(widgetRolled(QWidget*,bool)), this, SLOT(onWidgetRolled(QWidget*,bool))); connect(this, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(onMenuDialogCalled(const QPoint &))); - m_spectrumVis = new SpectrumVis(SDR_RX_SCALEF, ui->glSpectrum); m_ssbDemod = (SSBDemod*) rxChannel; //new SSBDemod(m_deviceUISet->m_deviceSourceAPI); + m_spectrumVis = m_ssbDemod->getSpectrumVis(); + m_spectrumVis->setGLSpectrum(ui->glSpectrum); m_ssbDemod->setMessageQueueToGUI(getInputMessageQueue()); m_ssbDemod->propagateMessageQueueToGUI(); - m_ssbDemod->setSpectrumSink(m_spectrumVis); CRightClickEnabler *audioMuteRightClickEnabler = new CRightClickEnabler(ui->audioMute); connect(audioMuteRightClickEnabler, SIGNAL(rightClick(const QPoint &)), this, SLOT(audioSelect())); @@ -366,7 +366,6 @@ SSBDemodGUI::~SSBDemodGUI() { m_deviceUISet->removeRxChannelInstance(this); delete m_ssbDemod; // TODO: check this: when the GUI closes it has to delete the demodulator - delete m_spectrumVis; delete ui; } diff --git a/plugins/channelrx/udpsink/udpsink.cpp b/plugins/channelrx/udpsink/udpsink.cpp index b216278f9..a596005ea 100644 --- a/plugins/channelrx/udpsink/udpsink.cpp +++ b/plugins/channelrx/udpsink/udpsink.cpp @@ -44,6 +44,7 @@ const QString UDPSink::m_channelId = "UDPSink"; UDPSink::UDPSink(DeviceAPI *deviceAPI) : ChannelAPI(m_channelIdURI, ChannelAPI::StreamSingleSink), m_deviceAPI(deviceAPI), + m_spectrumVis(SDR_RX_SCALEF), m_channelSampleRate(48000), m_channelFrequencyOffset(0) { @@ -51,6 +52,7 @@ UDPSink::UDPSink(DeviceAPI *deviceAPI) : m_thread = new QThread(this); m_basebandSink = new UDPSinkBaseband(); + m_basebandSink->setSpectrum(&m_spectrumVis); m_basebandSink->moveToThread(m_thread); applySettings(m_settings, true); diff --git a/plugins/channelrx/udpsink/udpsink.h b/plugins/channelrx/udpsink/udpsink.h index 5bece97f4..1c9cac3f4 100644 --- a/plugins/channelrx/udpsink/udpsink.h +++ b/plugins/channelrx/udpsink/udpsink.h @@ -23,6 +23,7 @@ #include #include "dsp/basebandsamplesink.h" +#include "dsp/spectrumvis.h" #include "channel/channelapi.h" #include "util/message.h" @@ -64,7 +65,7 @@ public: virtual ~UDPSink(); virtual void destroy() { delete this; } - void setSpectrum(BasebandSampleSink* spectrum) { m_basebandSink->setSpectrum(spectrum); } + SpectrumVis *getSpectrumVis() { return &m_spectrumVis; } void enableSpectrum(bool enable); void setSpectrumPositiveOnly(bool positiveOnly) { m_basebandSink->setSpectrumPositiveOnly(positiveOnly); } double getMagSq() const { return m_basebandSink->getMagSq(); } @@ -130,6 +131,7 @@ protected: QThread *m_thread; UDPSinkBaseband* m_basebandSink; UDPSinkSettings m_settings; + SpectrumVis m_spectrumVis; int m_basebandSampleRate; //!< stored from device message used when starting baseband sink int m_channelSampleRate; diff --git a/plugins/channelrx/udpsink/udpsinkgui.cpp b/plugins/channelrx/udpsink/udpsinkgui.cpp index 79bee4979..4be4c04d9 100644 --- a/plugins/channelrx/udpsink/udpsinkgui.cpp +++ b/plugins/channelrx/udpsink/udpsinkgui.cpp @@ -171,9 +171,9 @@ UDPSinkGUI::UDPSinkGUI(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, BasebandS connect(this, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(onMenuDialogCalled(const QPoint &))); setAttribute(Qt::WA_DeleteOnClose, true); - m_spectrumVis = new SpectrumVis(SDR_RX_SCALEF, ui->glSpectrum); m_udpSink = (UDPSink*) rxChannel; //new UDPSrc(m_deviceUISet->m_deviceSourceAPI); - m_udpSink->setSpectrum(m_spectrumVis); + m_spectrumVis = m_udpSink->getSpectrumVis(); + m_spectrumVis->setGLSpectrum(ui->glSpectrum); m_udpSink->setMessageQueueToGUI(getInputMessageQueue()); ui->fmDeviation->setEnabled(false); @@ -232,7 +232,6 @@ UDPSinkGUI::~UDPSinkGUI() { m_deviceUISet->removeRxChannelInstance(this); delete m_udpSink; // TODO: check this: when the GUI closes it has to delete the demodulator - delete m_spectrumVis; delete ui; } diff --git a/plugins/channeltx/modfreedv/freedvmod.cpp b/plugins/channeltx/modfreedv/freedvmod.cpp index 38a56c30e..6ee04c7ba 100644 --- a/plugins/channeltx/modfreedv/freedvmod.cpp +++ b/plugins/channeltx/modfreedv/freedvmod.cpp @@ -52,6 +52,7 @@ const QString FreeDVMod::m_channelId = "FreeDVMod"; FreeDVMod::FreeDVMod(DeviceAPI *deviceAPI) : ChannelAPI(m_channelIdURI, ChannelAPI::StreamSingleSource), m_deviceAPI(deviceAPI), + m_spectrumVis(SDR_TX_SCALEF), m_settingsMutex(QMutex::Recursive), m_fileSize(0), m_recordLength(0), @@ -61,6 +62,7 @@ FreeDVMod::FreeDVMod(DeviceAPI *deviceAPI) : m_thread = new QThread(this); m_basebandSource = new FreeDVModBaseband(); + m_basebandSource->setSpectrumSampleSink(&m_spectrumVis); m_basebandSource->setInputFileStream(&m_ifstream); m_basebandSource->moveToThread(m_thread); @@ -622,11 +624,6 @@ void FreeDVMod::networkManagerFinished(QNetworkReply *reply) reply->deleteLater(); } -void FreeDVMod::setSpectrumSampleSink(BasebandSampleSink* sampleSink) -{ - m_basebandSource->setSpectrumSampleSink(sampleSink); -} - uint32_t FreeDVMod::getAudioSampleRate() const { return m_basebandSource->getAudioSampleRate(); diff --git a/plugins/channeltx/modfreedv/freedvmod.h b/plugins/channeltx/modfreedv/freedvmod.h index 9c8c3519f..d41b800d5 100644 --- a/plugins/channeltx/modfreedv/freedvmod.h +++ b/plugins/channeltx/modfreedv/freedvmod.h @@ -26,8 +26,9 @@ #include #include "dsp/basebandsamplesource.h" -#include "channel/channelapi.h" #include "dsp/basebandsamplesink.h" +#include "dsp/spectrumvis.h" +#include "channel/channelapi.h" #include "util/message.h" #include "freedvmodsettings.h" @@ -224,6 +225,7 @@ public: const QStringList& channelSettingsKeys, SWGSDRangel::SWGChannelSettings& response); + SpectrumVis *getSpectrumVis() { return &m_spectrumVis; } uint32_t getAudioSampleRate() const; uint32_t getModemSampleRate() const; Real getLowCutoff() const; @@ -231,7 +233,6 @@ public: double getMagSq() const; CWKeyer *getCWKeyer(); void setLevelMeter(QObject *levelMeter); - void setSpectrumSampleSink(BasebandSampleSink* sampleSink); uint32_t getNumberOfDeviceStreams() const; static const QString m_channelIdURI; @@ -247,6 +248,7 @@ private: QThread *m_thread; FreeDVModBaseband* m_basebandSource; FreeDVModSettings m_settings; + SpectrumVis m_spectrumVis; SampleVector m_sampleBuffer; QMutex m_settingsMutex; diff --git a/plugins/channeltx/modfreedv/freedvmodgui.cpp b/plugins/channeltx/modfreedv/freedvmodgui.cpp index 9184d33b7..3b85a2cd2 100644 --- a/plugins/channeltx/modfreedv/freedvmodgui.cpp +++ b/plugins/channeltx/modfreedv/freedvmodgui.cpp @@ -369,9 +369,9 @@ FreeDVModGUI::FreeDVModGUI(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, Baseb connect(this, SIGNAL(widgetRolled(QWidget*,bool)), this, SLOT(onWidgetRolled(QWidget*,bool))); connect(this, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(onMenuDialogCalled(const QPoint &))); - m_spectrumVis = new SpectrumVis(SDR_TX_SCALEF, ui->glSpectrum); m_freeDVMod = (FreeDVMod*) channelTx; - m_freeDVMod->setSpectrumSampleSink(m_spectrumVis); + m_spectrumVis = m_freeDVMod->getSpectrumVis(); + m_spectrumVis->setGLSpectrum(ui->glSpectrum); m_freeDVMod->setMessageQueueToGUI(getInputMessageQueue()); resetToDefaults(); @@ -419,7 +419,6 @@ FreeDVModGUI::~FreeDVModGUI() { m_deviceUISet->removeTxChannelInstance(this); delete m_freeDVMod; // TODO: check this: when the GUI closes it has to delete the modulator - delete m_spectrumVis; delete ui; } diff --git a/plugins/channeltx/modssb/ssbmod.cpp b/plugins/channeltx/modssb/ssbmod.cpp index 3b2c02c17..63d042cd4 100644 --- a/plugins/channeltx/modssb/ssbmod.cpp +++ b/plugins/channeltx/modssb/ssbmod.cpp @@ -53,6 +53,7 @@ const QString SSBMod::m_channelId = "SSBMod"; SSBMod::SSBMod(DeviceAPI *deviceAPI) : ChannelAPI(m_channelIdURI, ChannelAPI::StreamSingleSource), m_deviceAPI(deviceAPI), + m_spectrumVis(SDR_TX_SCALEF), m_settingsMutex(QMutex::Recursive), m_fileSize(0), m_recordLength(0), @@ -62,6 +63,7 @@ SSBMod::SSBMod(DeviceAPI *deviceAPI) : m_thread = new QThread(this); m_basebandSource = new SSBModBaseband(); + m_basebandSource->setSpectrumSink(&m_spectrumVis); m_basebandSource->setInputFileStream(&m_ifstream); m_basebandSource->moveToThread(m_thread); @@ -697,11 +699,6 @@ unsigned int SSBMod::getAudioSampleRate() const return m_basebandSource->getAudioSampleRate(); } -void SSBMod::setSpectrumSink(BasebandSampleSink *sampleSink) -{ - m_basebandSource->setSpectrumSink(sampleSink); -} - uint32_t SSBMod::getNumberOfDeviceStreams() const { return m_deviceAPI->getNbSinkStreams(); diff --git a/plugins/channeltx/modssb/ssbmod.h b/plugins/channeltx/modssb/ssbmod.h index 1ec6b1833..33c4a3171 100644 --- a/plugins/channeltx/modssb/ssbmod.h +++ b/plugins/channeltx/modssb/ssbmod.h @@ -26,6 +26,7 @@ #include #include "dsp/basebandsamplesource.h" +#include "dsp/spectrumvis.h" #include "channel/channelapi.h" #include "dsp/basebandsamplesink.h" #include "util/message.h" @@ -222,11 +223,11 @@ public: const QStringList& channelSettingsKeys, SWGSDRangel::SWGChannelSettings& response); + SpectrumVis *getSpectrumVis() { return &m_spectrumVis; } double getMagSq() const; CWKeyer *getCWKeyer(); void setLevelMeter(QObject *levelMeter); unsigned int getAudioSampleRate() const; - void setSpectrumSink(BasebandSampleSink *sampleSink); uint32_t getNumberOfDeviceStreams() const; static const QString m_channelIdURI; @@ -242,6 +243,7 @@ private: QThread *m_thread; SSBModBaseband* m_basebandSource; SSBModSettings m_settings; + SpectrumVis m_spectrumVis; SampleVector m_sampleBuffer; QMutex m_settingsMutex; diff --git a/plugins/channeltx/modssb/ssbmodgui.cpp b/plugins/channeltx/modssb/ssbmodgui.cpp index 8e236dd4d..4f8f7101c 100644 --- a/plugins/channeltx/modssb/ssbmodgui.cpp +++ b/plugins/channeltx/modssb/ssbmodgui.cpp @@ -419,9 +419,9 @@ SSBModGUI::SSBModGUI(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, BasebandSam connect(this, SIGNAL(widgetRolled(QWidget*,bool)), this, SLOT(onWidgetRolled(QWidget*,bool))); connect(this, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(onMenuDialogCalled(const QPoint &))); - m_spectrumVis = new SpectrumVis(SDR_TX_SCALEF, ui->glSpectrum); m_ssbMod = (SSBMod*) channelTx; //new SSBMod(m_deviceUISet->m_deviceSinkAPI); - m_ssbMod->setSpectrumSink(m_spectrumVis); + m_spectrumVis = m_ssbMod->getSpectrumVis(); + m_spectrumVis->setGLSpectrum(ui->glSpectrum); m_ssbMod->setMessageQueueToGUI(getInputMessageQueue()); resetToDefaults(); @@ -486,7 +486,6 @@ SSBModGUI::~SSBModGUI() { m_deviceUISet->removeTxChannelInstance(this); delete m_ssbMod; // TODO: check this: when the GUI closes it has to delete the modulator - delete m_spectrumVis; delete ui; } diff --git a/plugins/channeltx/udpsource/udpsource.cpp b/plugins/channeltx/udpsource/udpsource.cpp index 910f9197b..d018a55e6 100644 --- a/plugins/channeltx/udpsource/udpsource.cpp +++ b/plugins/channeltx/udpsource/udpsource.cpp @@ -41,12 +41,14 @@ const QString UDPSource::m_channelId = "UDPSource"; UDPSource::UDPSource(DeviceAPI *deviceAPI) : ChannelAPI(m_channelIdURI, ChannelAPI::StreamSingleSource), m_deviceAPI(deviceAPI), + m_spectrumVis(SDR_TX_SCALEF), m_settingsMutex(QMutex::Recursive) { setObjectName(m_channelId); m_thread = new QThread(this); m_basebandSource = new UDPSourceBaseband(); + m_basebandSource->setSpectrumSink(&m_spectrumVis); m_basebandSource->moveToThread(m_thread); applySettings(m_settings, true); @@ -127,11 +129,6 @@ bool UDPSource::handleMessage(const Message& cmd) } } -void UDPSource::setSpectrumSink(BasebandSampleSink* spectrum) -{ - m_basebandSource->setSpectrumSink(spectrum); -} - void UDPSource::setSpectrum(bool enabled) { Message* cmd = UDPSourceBaseband::MsgUDPSourceSpectrum::create(enabled); @@ -174,8 +171,10 @@ void UDPSource::applySettings(const UDPSourceSettings& settings, bool force) if ((settings.m_sampleFormat != m_settings.m_sampleFormat) || force) { reverseAPIKeys.append("sampleFormat"); } - if ((settings.m_inputSampleRate != m_settings.m_inputSampleRate) || force) { + if ((settings.m_inputSampleRate != m_settings.m_inputSampleRate) || force) + { reverseAPIKeys.append("inputSampleRate"); + m_spectrumVis.configureDSP(0, settings.m_inputSampleRate); } if ((settings.m_rfBandwidth != m_settings.m_rfBandwidth) || force) { reverseAPIKeys.append("rfBandwidth"); diff --git a/plugins/channeltx/udpsource/udpsource.h b/plugins/channeltx/udpsource/udpsource.h index 5e755d8f4..40d85926e 100644 --- a/plugins/channeltx/udpsource/udpsource.h +++ b/plugins/channeltx/udpsource/udpsource.h @@ -22,6 +22,7 @@ #include #include "dsp/basebandsamplesource.h" +#include "dsp/spectrumvis.h" #include "channel/channelapi.h" #include "dsp/basebandsamplesink.h" #include "util/message.h" @@ -141,11 +142,11 @@ public: const QStringList& channelSettingsKeys, SWGSDRangel::SWGChannelSettings& response); + SpectrumVis *getSpectrumVis() { return &m_spectrumVis; } double getMagSq() const; double getInMagSq() const; int32_t getBufferGauge() const; bool getSquelchOpen() const; - void setSpectrumSink(BasebandSampleSink* spectrum); void setSpectrum(bool enabled); void resetReadIndex(); void setLevelMeter(QObject *levelMeter); @@ -162,6 +163,7 @@ private: QThread *m_thread; UDPSourceBaseband* m_basebandSource; UDPSourceSettings m_settings; + SpectrumVis m_spectrumVis; SampleVector m_sampleBuffer; QMutex m_settingsMutex; diff --git a/plugins/channeltx/udpsource/udpsourcegui.cpp b/plugins/channeltx/udpsource/udpsourcegui.cpp index e5aa44a2e..41394cd5f 100644 --- a/plugins/channeltx/udpsource/udpsourcegui.cpp +++ b/plugins/channeltx/udpsource/udpsourcegui.cpp @@ -130,9 +130,9 @@ UDPSourceGUI::UDPSourceGUI(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, Baseb connect(this, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(onMenuDialogCalled(const QPoint &))); setAttribute(Qt::WA_DeleteOnClose, true); - m_spectrumVis = new SpectrumVis(SDR_TX_SCALEF, ui->glSpectrum); m_udpSource = (UDPSource*) channelTx; - m_udpSource->setSpectrumSink(m_spectrumVis); + m_spectrumVis = m_udpSource->getSpectrumVis(); + m_spectrumVis->setGLSpectrum(ui->glSpectrum); m_udpSource->setMessageQueueToGUI(getInputMessageQueue()); ui->fmDeviation->setEnabled(false); @@ -185,7 +185,6 @@ UDPSourceGUI::~UDPSourceGUI() { m_deviceUISet->removeTxChannelInstance(this); delete m_udpSource; // TODO: check this: when the GUI closes it has to delete the modulator - delete m_spectrumVis; delete ui; } diff --git a/plugins/samplesink/testsink/testsinkgui.cpp b/plugins/samplesink/testsink/testsinkgui.cpp index 55168a757..591d3cc50 100644 --- a/plugins/samplesink/testsink/testsinkgui.cpp +++ b/plugins/samplesink/testsink/testsinkgui.cpp @@ -57,8 +57,8 @@ TestSinkGui::TestSinkGui(DeviceUISet *deviceUISet, QWidget* parent) : ui->sampleRate->setColorMapper(ColorMapper(ColorMapper::GrayGreenYellow)); ui->sampleRate->setValueRange(7, 32000U, 9000000U); - m_spectrumVis = new SpectrumVis(SDR_TX_SCALEF, ui->glSpectrum); - m_sampleSink->setSpectrumSink(m_spectrumVis); + m_spectrumVis = m_sampleSink->getSpectrumVis(); + m_spectrumVis->setGLSpectrum(ui->glSpectrum); ui->glSpectrum->setCenterFrequency(m_settings.m_centerFrequency); ui->glSpectrum->setSampleRate(m_settings.m_sampleRate*(1<glSpectrum->connectTimer(MainWindow::getInstance()->getMasterTimer()); @@ -76,7 +76,6 @@ TestSinkGui::TestSinkGui(DeviceUISet *deviceUISet, QWidget* parent) : TestSinkGui::~TestSinkGui() { - delete m_spectrumVis; delete ui; } diff --git a/plugins/samplesink/testsink/testsinkoutput.cpp b/plugins/samplesink/testsink/testsinkoutput.cpp index 91be4117f..6a79c1371 100644 --- a/plugins/samplesink/testsink/testsinkoutput.cpp +++ b/plugins/samplesink/testsink/testsinkoutput.cpp @@ -38,10 +38,10 @@ MESSAGE_CLASS_DEFINITION(TestSinkOutput::MsgStartStop, Message) TestSinkOutput::TestSinkOutput(DeviceAPI *deviceAPI) : m_deviceAPI(deviceAPI), m_settings(), + m_spectrumVis(SDR_TX_SCALEF), m_testSinkThread(nullptr), m_deviceDescription("TestSink"), - m_masterTimer(deviceAPI->getMasterTimer()), - m_spectrumSink(nullptr) + m_masterTimer(deviceAPI->getMasterTimer()) { m_deviceAPI->setNbSinkStreams(1); } @@ -67,7 +67,7 @@ bool TestSinkOutput::start() qDebug() << "TestSinkOutput::start"; m_testSinkThread = new TestSinkThread(&m_sampleSourceFifo); - m_testSinkThread->setSpectrumSink(m_spectrumSink); + m_testSinkThread->setSpectrumSink(&m_spectrumVis); m_testSinkThread->setSamplerate(m_settings.m_sampleRate); m_testSinkThread->setLog2Interpolation(m_settings.m_log2Interp); m_testSinkThread->connectTimer(m_masterTimer); diff --git a/plugins/samplesink/testsink/testsinkoutput.h b/plugins/samplesink/testsink/testsinkoutput.h index 76e48b0fe..4c08befa2 100644 --- a/plugins/samplesink/testsink/testsinkoutput.h +++ b/plugins/samplesink/testsink/testsinkoutput.h @@ -25,6 +25,7 @@ #include #include "dsp/devicesamplesink.h" +#include "dsp/spectrumvis.h" #include "testsinksettings.h" class TestSinkThread; @@ -104,17 +105,17 @@ public: SWGSDRangel::SWGDeviceState& response, QString& errorMessage); - void setSpectrumSink(BasebandSampleSink* spectrumSink) { m_spectrumSink = spectrumSink; } + SpectrumVis *getSpectrumVis() { return &m_spectrumVis; } private: DeviceAPI *m_deviceAPI; QMutex m_mutex; TestSinkSettings m_settings; + SpectrumVis m_spectrumVis; std::ofstream m_ofstream; TestSinkThread* m_testSinkThread; QString m_deviceDescription; const QTimer& m_masterTimer; - BasebandSampleSink* m_spectrumSink; void applySettings(const TestSinkSettings& settings, bool force = false); }; diff --git a/sdrbase/dsp/spectrumvis.cpp b/sdrbase/dsp/spectrumvis.cpp index 5931d129f..b0564e3e7 100644 --- a/sdrbase/dsp/spectrumvis.cpp +++ b/sdrbase/dsp/spectrumvis.cpp @@ -38,10 +38,12 @@ inline double log2f(double n) MESSAGE_CLASS_DEFINITION(SpectrumVis::MsgConfigureSpectrumVis, Message) MESSAGE_CLASS_DEFINITION(SpectrumVis::MsgConfigureDSP, Message) MESSAGE_CLASS_DEFINITION(SpectrumVis::MsgConfigureScalingFactor, Message) +MESSAGE_CLASS_DEFINITION(SpectrumVis::MsgConfigureWSpectrumOpenClose, Message) +MESSAGE_CLASS_DEFINITION(SpectrumVis::MsgConfigureWSpectrum, Message) const Real SpectrumVis::m_mult = (10.0f / log2f(10.0f)); -SpectrumVis::SpectrumVis(Real scalef, GLSpectrumInterface* glSpectrum) : +SpectrumVis::SpectrumVis(Real scalef) : BasebandSampleSink(), m_fft(nullptr), m_fftEngineSequence(0), @@ -50,7 +52,7 @@ SpectrumVis::SpectrumVis(Real scalef, GLSpectrumInterface* glSpectrum) : m_fftBufferFill(0), m_needMoreSamples(false), m_scalef(scalef), - m_glSpectrum(glSpectrum), + m_glSpectrum(nullptr), m_averageNb(0), m_avgMode(AvgModeNone), m_linear(false), @@ -62,7 +64,7 @@ SpectrumVis::SpectrumVis(Real scalef, GLSpectrumInterface* glSpectrum) : { setObjectName("SpectrumVis"); handleConfigure(1024, 0, 100, 0, 0, AvgModeNone, FFTWindow::BlackmanHarris, false); - m_wsSpectrum.openSocket(); // FIXME: conditional + //m_wsSpectrum.openSocket(); // FIXME: conditional } SpectrumVis::~SpectrumVis() @@ -71,6 +73,18 @@ SpectrumVis::~SpectrumVis() fftFactory->releaseEngine(m_fftSize, false, m_fftEngineSequence); } +void SpectrumVis::openWSSpectrum() +{ + MsgConfigureWSpectrumOpenClose *cmd = new MsgConfigureWSpectrumOpenClose(true); + getInputMessageQueue()->push(cmd); +} + +void SpectrumVis::closeWSSpectrum() +{ + MsgConfigureWSpectrumOpenClose *cmd = new MsgConfigureWSpectrumOpenClose(false); + getInputMessageQueue()->push(cmd); +} + void SpectrumVis::configure(MessageQueue* msgQueue, int fftSize, float refLevel, @@ -106,6 +120,12 @@ void SpectrumVis::setScalef(Real scalef) getInputMessageQueue()->push(cmd); } +void SpectrumVis::configureWSSpectrum(const QString& address, uint16_t port) +{ + MsgConfigureWSpectrum* cmd = new MsgConfigureWSpectrum(address, port); + getInputMessageQueue()->push(cmd); +} + void SpectrumVis::feedTriggered(const SampleVector::const_iterator& triggerPoint, const SampleVector::const_iterator& end, bool positiveOnly) { feed(triggerPoint, end, positiveOnly); // normal feed from trigger point @@ -617,7 +637,17 @@ void SpectrumVis::stop() bool SpectrumVis::handleMessage(const Message& message) { - if (MsgConfigureSpectrumVis::match(message)) + if (DSPSignalNotification::match(message)) + { + // This is coming from device engine and will apply to main spectrum + DSPSignalNotification& notif = (DSPSignalNotification&) message; + qDebug() << "SpectrumVis::handleMessage: DSPSignalNotification:" + << " centerFrequency: " << notif.getCenterFrequency() + << " sampleRate: " << notif.getSampleRate(); + handleConfigureDSP(notif.getCenterFrequency(), notif.getSampleRate()); + return true; + } + else if (MsgConfigureSpectrumVis::match(message)) { MsgConfigureSpectrumVis& conf = (MsgConfigureSpectrumVis&) message; handleConfigure(conf.getFFTSize(), @@ -632,6 +662,7 @@ bool SpectrumVis::handleMessage(const Message& message) } else if (MsgConfigureDSP::match(message)) { + // This is coming from plugins GUI via configureDSP for auxiliary spectra MsgConfigureDSP& conf = (MsgConfigureDSP&) message; handleConfigureDSP(conf.getCenterFrequency(), conf.getSampleRate()); return true; @@ -641,6 +672,15 @@ bool SpectrumVis::handleMessage(const Message& message) MsgConfigureScalingFactor& conf = (MsgConfigureScalingFactor&) message; handleScalef(conf.getScalef()); return true; + } + else if (MsgConfigureWSpectrumOpenClose::match(message)) + { + MsgConfigureWSpectrumOpenClose& conf = (MsgConfigureWSpectrumOpenClose&) message; + handleWSOpenClose(conf.getOpenClose()); + } + else if (MsgConfigureWSpectrum::match(message)) { + MsgConfigureWSpectrum& conf = (MsgConfigureWSpectrum&) message; + handleConfigureWSSpectrum(conf.getAddress(), conf.getPort()); } else { @@ -707,4 +747,34 @@ void SpectrumVis::handleScalef(Real scalef) { QMutexLocker mutexLocker(&m_mutex); m_scalef = scalef; +} + +void SpectrumVis::handleWSOpenClose(bool openClose) +{ + QMutexLocker mutexLocker(&m_mutex); + + if (openClose) { + m_wsSpectrum.openSocket(); + } else { + m_wsSpectrum.closeSocket(); + } +} + +void SpectrumVis::handleConfigureWSSpectrum(const QString& address, uint16_t port) +{ + QMutexLocker mutexLocker(&m_mutex); + bool wsSpectrumWasOpen = false; + + if (m_wsSpectrum.socketOpened()) + { + m_wsSpectrum.closeSocket(); + wsSpectrumWasOpen = true; + } + + m_wsSpectrum.setListeningAddress(address); + m_wsSpectrum.setPort(port); + + if (wsSpectrumWasOpen) { + m_wsSpectrum.openSocket(); + } } \ No newline at end of file diff --git a/sdrbase/dsp/spectrumvis.h b/sdrbase/dsp/spectrumvis.h index 8deffaf5f..e65d50cbe 100644 --- a/sdrbase/dsp/spectrumvis.h +++ b/sdrbase/dsp/spectrumvis.h @@ -47,6 +47,34 @@ public: AvgModeMax }; + SpectrumVis(Real scalef); + virtual ~SpectrumVis(); + + void setGLSpectrum(GLSpectrumInterface* glSpectrum) { m_glSpectrum = glSpectrum; } + void openWSSpectrum(); + void closeWSSpectrum(); + + void configure(MessageQueue* msgQueue, + int fftSize, + float refLevel, + float powerRange, + int overlapPercent, + unsigned int averagingNb, + AvgMode averagingMode, + FFTWindow::Function window, + bool m_linear); + void configureDSP(uint64_t centerFrequency, int sampleRate); + void setScalef(Real scalef); + void configureWSSpectrum(const QString& address, uint16_t port); + + virtual void feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool positiveOnly); + virtual void feed(const Complex *begin, unsigned int length); //!< direct FFT feed + void feedTriggered(const SampleVector::const_iterator& triggerPoint, const SampleVector::const_iterator& end, bool positiveOnly); + virtual void start(); + virtual void stop(); + virtual bool handleMessage(const Message& message); + +private: class MsgConfigureSpectrumVis : public Message { MESSAGE_CLASS_DECLARATION @@ -126,29 +154,41 @@ public: Real m_scalef; }; - SpectrumVis(Real scalef, GLSpectrumInterface* glSpectrum = nullptr); - virtual ~SpectrumVis(); + class MsgConfigureWSpectrumOpenClose : public Message + { + MESSAGE_CLASS_DECLARATION - void configure(MessageQueue* msgQueue, - int fftSize, - float refLevel, - float powerRange, - int overlapPercent, - unsigned int averagingNb, - AvgMode averagingMode, - FFTWindow::Function window, - bool m_linear); - void configureDSP(uint64_t centerFrequency, int sampleRate); - void setScalef(Real scalef); + public: + MsgConfigureWSpectrumOpenClose(bool openClose) : + Message(), + m_openClose(openClose) + {} - virtual void feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool positiveOnly); - virtual void feed(const Complex *begin, unsigned int length); //!< direct FFT feed - void feedTriggered(const SampleVector::const_iterator& triggerPoint, const SampleVector::const_iterator& end, bool positiveOnly); - virtual void start(); - virtual void stop(); - virtual bool handleMessage(const Message& message); + Real getOpenClose() const { return m_openClose; } + + private: + bool m_openClose; + }; + + class MsgConfigureWSpectrum : public Message + { + MESSAGE_CLASS_DECLARATION + + public: + MsgConfigureWSpectrum(const QString& address, uint16_t port) : + Message(), + m_address(address), + m_port(port) + {} + + const QString& getAddress() const { return m_address; } + uint16_t getPort() const { return m_port; } + + private: + QString m_address; + uint16_t m_port; + }; -private: FFTEngine* m_fft; FFTWindow m_window; unsigned int m_fftEngineSequence; @@ -192,9 +232,11 @@ private: AvgMode averagingMode, FFTWindow::Function window, bool linear); + void handleWSOpenClose(bool openClose); void handleConfigureDSP(uint64_t centerFrequency, int sampleRate); void handleScalef(Real scalef); + void handleConfigureWSSpectrum(const QString& address, uint16_t port); }; #endif // INCLUDE_SPECTRUMVIS_H diff --git a/sdrgui/device/deviceuiset.cpp b/sdrgui/device/deviceuiset.cpp index 5fe086f9c..123377997 100644 --- a/sdrgui/device/deviceuiset.cpp +++ b/sdrgui/device/deviceuiset.cpp @@ -37,11 +37,18 @@ DeviceUISet::DeviceUISet(int tabIndex, int deviceType, QTimer& timer) { m_spectrum = new GLSpectrum; - if ((deviceType == 0) || (deviceType == 2)) { // Single Rx or MIMO - m_spectrumVis = new SpectrumVis(SDR_RX_SCALEF, m_spectrum); - } else if (deviceType == 1) { // Single Tx - m_spectrumVis = new SpectrumVis(SDR_TX_SCALEF, m_spectrum); + + if ((deviceType == 0) || (deviceType == 2)) // Single Rx or MIMO + { + m_spectrumVis = new SpectrumVis(SDR_RX_SCALEF); + m_spectrumVis->setGLSpectrum(m_spectrum); } + else if (deviceType == 1) // Single Tx + { + m_spectrumVis = new SpectrumVis(SDR_TX_SCALEF); + m_spectrumVis->setGLSpectrum(m_spectrum); + } + m_spectrum->connectTimer(timer); m_spectrumGUI = new GLSpectrumGUI; m_spectrumGUI->setBuddies(m_spectrumVis->getInputMessageQueue(), m_spectrumVis, m_spectrum);