From 5cba51b23ac2d2c49ed057c1b3a9f59da5d28ee6 Mon Sep 17 00:00:00 2001 From: f4exb Date: Thu, 13 Oct 2022 00:46:23 +0200 Subject: [PATCH] AM demod: update threading model complements --- plugins/channelrx/demodam/amdemod.cpp | 15 +++++++-------- plugins/channelrx/demodam/amdemod.h | 16 ++++++++++------ 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/plugins/channelrx/demodam/amdemod.cpp b/plugins/channelrx/demodam/amdemod.cpp index bc2238038..5ae96a1ac 100644 --- a/plugins/channelrx/demodam/amdemod.cpp +++ b/plugins/channelrx/demodam/amdemod.cpp @@ -546,18 +546,17 @@ void AMDemod::webapiFormatChannelSettings(SWGSDRangel::SWGChannelSettings& respo void AMDemod::webapiFormatChannelReport(SWGSDRangel::SWGChannelReport& response) { + if (!m_running) { + return; + } + double magsqAvg, magsqPeak; int nbMagsqSamples; getMagSqLevels(magsqAvg, magsqPeak, nbMagsqSamples); - response.getAmDemodReport()->setChannelPowerDb(CalcDb::dbPower(magsqAvg)); - - if (m_running) - { - response.getAmDemodReport()->setSquelch(m_basebandSink->getSquelchOpen() ? 1 : 0); - response.getAmDemodReport()->setAudioSampleRate(m_basebandSink->getAudioSampleRate()); - response.getAmDemodReport()->setChannelSampleRate(m_basebandSink->getChannelSampleRate()); - } + response.getAmDemodReport()->setSquelch(m_basebandSink->getSquelchOpen() ? 1 : 0); + response.getAmDemodReport()->setAudioSampleRate(m_basebandSink->getAudioSampleRate()); + response.getAmDemodReport()->setChannelSampleRate(m_basebandSink->getChannelSampleRate()); } void AMDemod::webapiReverseSendSettings(QList& channelSettingsKeys, const AMDemodSettings& settings, bool force) diff --git a/plugins/channelrx/demodam/amdemod.h b/plugins/channelrx/demodam/amdemod.h index 3df4148a9..c11a14f4c 100644 --- a/plugins/channelrx/demodam/amdemod.h +++ b/plugins/channelrx/demodam/amdemod.h @@ -119,14 +119,18 @@ public: const QStringList& channelSettingsKeys, SWGSDRangel::SWGChannelSettings& response); - uint32_t getAudioSampleRate() const { return m_basebandSink->getAudioSampleRate(); } - double getMagSq() const { return m_basebandSink->getMagSq(); } - bool getSquelchOpen() const { return m_basebandSink->getSquelchOpen(); } - bool getPllLocked() const { return m_settings.m_pll && m_basebandSink->getPllLocked(); } - Real getPllFrequency() const { return m_basebandSink->getPllFrequency(); } + uint32_t getAudioSampleRate() const { return m_running ? m_basebandSink->getAudioSampleRate() : 0; } + double getMagSq() const { return m_running ? m_basebandSink->getMagSq() : 0.0; } + bool getSquelchOpen() const { return m_running ? m_basebandSink->getSquelchOpen() : false; } + bool getPllLocked() const { return m_settings.m_pll && m_running && m_basebandSink->getPllLocked(); } + Real getPllFrequency() const { return m_running ? m_basebandSink->getPllFrequency() : 0.0; } void getMagSqLevels(double& avg, double& peak, int& nbSamples) { - m_basebandSink->getMagSqLevels(avg, peak, nbSamples); + if (m_running) { + m_basebandSink->getMagSqLevels(avg, peak, nbSamples); + } else { + avg = 0.0; peak = 0.0; nbSamples = 1; + } } uint32_t getNumberOfDeviceStreams() const;