From 3a3dc0d8c0eaddc4e99748000af697e4d0dec05f Mon Sep 17 00:00:00 2001 From: f4exb Date: Sat, 10 Jul 2021 22:41:24 +0200 Subject: [PATCH] Channel Analyzer / Scope: fixed sample rate handling. Fixes #956 --- plugins/channelrx/chanalyzer/chanalyzer.cpp | 21 ++++++++++++++++++- plugins/channelrx/chanalyzer/chanalyzer.h | 3 +-- .../channelrx/chanalyzer/chanalyzergui.cpp | 4 ++++ sdrgui/gui/glscopegui.cpp | 2 +- 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/plugins/channelrx/chanalyzer/chanalyzer.cpp b/plugins/channelrx/chanalyzer/chanalyzer.cpp index 0873811a7..732109e91 100644 --- a/plugins/channelrx/chanalyzer/chanalyzer.cpp +++ b/plugins/channelrx/chanalyzer/chanalyzer.cpp @@ -23,6 +23,7 @@ #include "device/deviceapi.h" #include "dsp/dspcommands.h" +#include "dsp/devicesamplesource.h" #include "chanalyzer.h" MESSAGE_CLASS_DEFINITION(ChannelAnalyzer::MsgConfigureChannelAnalyzer, Message) @@ -38,7 +39,7 @@ ChannelAnalyzer::ChannelAnalyzer(DeviceAPI *deviceAPI) : { qDebug("ChannelAnalyzer::ChannelAnalyzer"); setObjectName(m_channelId); - + getChannelSampleRate(); m_basebandSink = new ChannelAnalyzerBaseband(); m_basebandSink->moveToThread(&m_thread); @@ -62,6 +63,18 @@ ChannelAnalyzer::~ChannelAnalyzer() qDebug("ChannelAnalyzer::~ChannelAnalyzer: done"); } +int ChannelAnalyzer::getChannelSampleRate() +{ + DeviceSampleSource *source = m_deviceAPI->getSampleSource(); + + if (source) { + m_basebandSampleRate = source->getSampleRate(); + } + + qDebug("ChannelAnalyzer::getChannelSampleRate: %d", m_basebandSampleRate); + return m_basebandSampleRate; +} + void ChannelAnalyzer::feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool positiveOnly) { (void) positiveOnly; @@ -82,6 +95,12 @@ void ChannelAnalyzer::start() ChannelAnalyzerBaseband::MsgConfigureChannelAnalyzerBaseband *msg = ChannelAnalyzerBaseband::MsgConfigureChannelAnalyzerBaseband::create(m_settings, true); m_basebandSink->getInputMessageQueue()->push(msg); + + if (getMessageQueueToGUI()) + { + DSPSignalNotification *notifToGUI = new DSPSignalNotification(m_basebandSampleRate, m_centerFrequency); + getMessageQueueToGUI()->push(notifToGUI); + } } void ChannelAnalyzer::stop() diff --git a/plugins/channelrx/chanalyzer/chanalyzer.h b/plugins/channelrx/chanalyzer/chanalyzer.h index dcf4a27d7..9079ccfea 100644 --- a/plugins/channelrx/chanalyzer/chanalyzer.h +++ b/plugins/channelrx/chanalyzer/chanalyzer.h @@ -63,8 +63,7 @@ public: SpectrumVis *getSpectrumVis() { return &m_spectrumVis; } ScopeVis *getScopeVis() { return &m_scopeVis; } void setScopeVis(ScopeVis *scopeVis) { m_basebandSink->setScopeVis(scopeVis); } - - int getChannelSampleRate() const { return m_basebandSink->getChannelSampleRate(); } + int getChannelSampleRate(); int getDecimation() const { return 1<getMagSq(); } double getMagSqAvg() const { return m_basebandSink->getMagSqAvg(); } diff --git a/plugins/channelrx/chanalyzer/chanalyzergui.cpp b/plugins/channelrx/chanalyzer/chanalyzergui.cpp index c9dea7616..9ab184553 100644 --- a/plugins/channelrx/chanalyzer/chanalyzergui.cpp +++ b/plugins/channelrx/chanalyzer/chanalyzergui.cpp @@ -231,6 +231,7 @@ bool ChannelAnalyzerGUI::handleMessage(const Message& message) { DSPSignalNotification& cmd = (DSPSignalNotification&) message; m_basebandSampleRate = cmd.getSampleRate(); + qDebug("ChannelAnalyzerGUI::handleMessage: DSPSignalNotification: m_basebandSampleRate: %d", m_basebandSampleRate); setSinkSampleRate(); } @@ -470,6 +471,8 @@ ChannelAnalyzerGUI::ChannelAnalyzerGUI(PluginAPI* pluginAPI, DeviceUISet *device connect(this, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(onMenuDialogCalled(const QPoint &))); m_channelAnalyzer = (ChannelAnalyzer*) rxChannel; + m_basebandSampleRate = m_channelAnalyzer->getChannelSampleRate(); + qDebug("ChannelAnalyzerGUI::ChannelAnalyzerGUI: m_basebandSampleRate: %d", m_basebandSampleRate); m_spectrumVis = m_channelAnalyzer->getSpectrumVis(); m_spectrumVis->setGLSpectrum(ui->glSpectrum); m_scopeVis = m_channelAnalyzer->getScopeVis(); @@ -557,6 +560,7 @@ void ChannelAnalyzerGUI::setSinkSampleRate() ui->sinkSampleRateText->setText(tr("%1 kS/s").arg(s)); m_scopeVis->setLiveRate(sinkSampleRate == 0 ? 48000 : sinkSampleRate); + ui->scopeGUI->setSampleRate(sinkSampleRate == 0 ? 48000 : sinkSampleRate); } void ChannelAnalyzerGUI::setFiltersUIBoundaries() diff --git a/sdrgui/gui/glscopegui.cpp b/sdrgui/gui/glscopegui.cpp index 0c4ee0980..af618e259 100644 --- a/sdrgui/gui/glscopegui.cpp +++ b/sdrgui/gui/glscopegui.cpp @@ -130,7 +130,7 @@ void GLScopeGUI::setBuddies(MessageQueue* messageQueue, ScopeVis* scopeVis, GLSc void GLScopeGUI::setSampleRate(int sampleRate) { - m_sampleRate = sampleRate; + onScopeSampleRateChanged(sampleRate); } void GLScopeGUI::onScopeSampleRateChanged(int sampleRate)