From 330593fabf7600348b5111d8e7a990beccea332e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gonzalo=20Jos=C3=A9=20Carracedo=20Carballal?= Date: Sat, 25 May 2024 23:44:59 +0200 Subject: [PATCH] Add AGC button --- Default/Audio/AudioProcessor.cpp | 84 ++++++++++++++++++-------------- Default/Audio/AudioProcessor.h | 2 + Default/Audio/AudioWidget.cpp | 30 ++++++++++++ Default/Audio/AudioWidget.h | 4 ++ Default/Audio/AudioWidget.ui | 36 ++++++++++++-- 5 files changed, 116 insertions(+), 40 deletions(-) diff --git a/Default/Audio/AudioProcessor.cpp b/Default/Audio/AudioProcessor.cpp index 367828df..50997b08 100644 --- a/Default/Audio/AudioProcessor.cpp +++ b/Default/Audio/AudioProcessor.cpp @@ -55,7 +55,7 @@ AudioProcessor::AudioProcessor(UIMediator *mediator, QObject *parent) assertAudioDevice(); m_tracker = new Suscan::AnalyzerRequestTracker(this); - this->connectAll(); + connectAll(); m_squelchLevel = 1e-2; } @@ -73,19 +73,19 @@ void AudioProcessor::connectAll() { connect( - this->m_tracker, + m_tracker, SIGNAL(opened(Suscan::AnalyzerRequest const &)), this, SLOT(onOpened(Suscan::AnalyzerRequest const &))); connect( - this->m_tracker, + m_tracker, SIGNAL(cancelled(Suscan::AnalyzerRequest const &)), this, SLOT(onCancelled(Suscan::AnalyzerRequest const &))); connect( - this->m_tracker, + m_tracker, SIGNAL(error(Suscan::AnalyzerRequest const &, const std::string &)), this, SLOT(onError(Suscan::AnalyzerRequest const &, const std::string &))); @@ -142,7 +142,7 @@ AudioProcessor::openAudio() // Prepare channel ch.bw = m_maxAudioBw; ch.ft = 0; - ch.fc = this->calcTrueLoFreq(); + ch.fc = calcTrueLoFreq(); ch.fLow = -.5 * m_maxAudioBw; ch.fHigh = +.5 * m_maxAudioBw; @@ -187,7 +187,7 @@ AudioProcessor::closeAudio() } // Just in case - this->stopRecording(); + stopRecording(); m_opening = false; m_opened = false; @@ -217,7 +217,7 @@ SUFREQ AudioProcessor::calcTrueLoFreq() const { SUFREQ delta = 0; - SUFREQ bw = this->calcTrueBandwidth(); + SUFREQ bw = calcTrueBandwidth(); if (m_demod == AudioDemod::USB) delta += .5 * bw; @@ -233,7 +233,7 @@ AudioProcessor::setTrueLoFreq() assert(m_analyzer != nullptr); assert(m_audioInspectorOpened); - m_analyzer->setInspectorFreq(m_audioInspHandle, this->calcTrueLoFreq()); + m_analyzer->setInspectorFreq(m_audioInspHandle, calcTrueLoFreq()); } void @@ -244,7 +244,7 @@ AudioProcessor::setTrueBandwidth() m_analyzer->setInspectorBandwidth( m_audioInspHandle, - this->calcTrueBandwidth()); + calcTrueBandwidth()); } void @@ -261,6 +261,7 @@ AudioProcessor::setParams() cfg.set("audio.demodulator", SCAST(uint64_t, m_demod + 1)); cfg.set("audio.squelch", m_squelch); cfg.set("audio.squelch-level", m_squelchLevel); + cfg.set("agc.enabled", m_agc); // Set audio inspector parameters m_analyzer->setInspectorConfig(m_audioInspHandle, cfg); @@ -335,8 +336,8 @@ void AudioProcessor::setAnalyzer(Suscan::Analyzer *analyzer) { if (m_analyzer != nullptr) { - this->disconnectAnalyzer(); - this->closeAudio(); + disconnectAnalyzer(); + closeAudio(); } m_analyzer = analyzer; @@ -344,9 +345,9 @@ AudioProcessor::setAnalyzer(Suscan::Analyzer *analyzer) // Was audio enabled? Open it back if (m_analyzer != nullptr) { - this->connectAnalyzer(); + connectAnalyzer(); if (m_enabled) - this->openAudio(); + openAudio(); } } @@ -359,10 +360,10 @@ AudioProcessor::setEnabled(bool enabled) if (m_analyzer != nullptr) { if (enabled) { if (!m_opened && !m_opening) - this->openAudio(); + openAudio(); } else { if (m_opened || m_opening) - this->closeAudio(); + closeAudio(); } } } @@ -375,7 +376,18 @@ AudioProcessor::setSquelchEnabled(bool enabled) m_squelch = enabled; if (m_audioInspectorOpened) - this->setParams(); + setParams(); + } +} + +void +AudioProcessor::setAGCEnabled(bool enabled) +{ + if (m_agc != enabled) { + m_agc = enabled; + + if (m_audioInspectorOpened) + setParams(); } } @@ -386,7 +398,7 @@ AudioProcessor::setSquelchLevel(float level) m_squelchLevel = level; if (m_audioInspectorOpened) - this->setParams(); + setParams(); } } @@ -432,14 +444,14 @@ AudioProcessor::setDemod(AudioDemod demod) m_demod = demod; if (m_audioInspectorOpened) { - this->setTrueLoFreq(); - this->setTrueBandwidth(); - this->setParams(); + setTrueLoFreq(); + setTrueBandwidth(); + setParams(); } if (m_audioFileSaver != nullptr) { - this->stopRecording(); - this->startRecording(m_savedPath); + stopRecording(); + startRecording(m_savedPath); } } } @@ -455,7 +467,7 @@ AudioProcessor::setSampleRate(unsigned rate) // acknowledgment to call setSampleRate if (m_audioInspectorOpened) { m_settingRate = true; - this->setParams(); + setParams(); m_analyzer->setInspectorWatermark( m_audioInspHandle, PlaybackWorker::calcBufferSizeForRate(m_sampleRate) / 2); @@ -464,8 +476,8 @@ AudioProcessor::setSampleRate(unsigned rate) } if (m_audioFileSaver != nullptr) { - this->stopRecording(); - this->startRecording(m_savedPath); + stopRecording(); + startRecording(m_savedPath); } } } @@ -477,7 +489,7 @@ AudioProcessor::setCutOff(float cutOff) m_cutOff = cutOff; if (m_audioInspectorOpened) - this->setParams(); + setParams(); } } @@ -496,7 +508,7 @@ AudioProcessor::setLoFreq(SUFREQ lo) m_lo = lo; if (m_audioInspectorOpened) - this->setTrueLoFreq(); + setTrueLoFreq(); } } @@ -508,18 +520,18 @@ AudioProcessor::setBandwidth(SUFREQ bw) bw = m_maxAudioBw; if (!sufeq(m_bw, bw, 1e-8f)) { - SUFREQ trueLo = this->calcTrueLoFreq(); + SUFREQ trueLo = calcTrueLoFreq(); SUFREQ newLo; m_bw = bw; - newLo = this->calcTrueLoFreq(); + newLo = calcTrueLoFreq(); if (m_audioInspectorOpened) { - this->setTrueBandwidth(); + setTrueBandwidth(); if (!sufeq(trueLo, newLo, 1e-8f)) - this->setTrueLoFreq(); + setTrueLoFreq(); } } } @@ -588,7 +600,7 @@ AudioProcessor::startRecording(QString path) params.modulation = m_demod; m_audioFileSaver = new AudioFileSaver(params, nullptr); - this->connectAudioFileSaver(); + connectAudioFileSaver(); opened = true; } @@ -646,7 +658,7 @@ AudioProcessor::onInspectorMessage(Suscan::InspectorMessage const &msg) case SUSCAN_ANALYZER_INSPECTOR_MSGKIND_WRONG_OBJECT: case SUSCAN_ANALYZER_INSPECTOR_MSGKIND_WRONG_HANDLE: if (!m_opened) { - this->closeAudio(); + closeAudio(); emit audioError("Unexpected error while opening audio channel"); } @@ -714,9 +726,9 @@ AudioProcessor::onOpened(Suscan::AnalyzerRequest const &req) m_audioInspId = req.inspectorId; m_audioInspectorOpened = true; - this->setTrueBandwidth(); - this->setTrueLoFreq(); - this->setParams(); + setTrueBandwidth(); + setTrueLoFreq(); + setParams(); m_analyzer->setInspectorWatermark( m_audioInspHandle, diff --git a/Default/Audio/AudioProcessor.h b/Default/Audio/AudioProcessor.h index c9573572..7b46948c 100644 --- a/Default/Audio/AudioProcessor.h +++ b/Default/Audio/AudioProcessor.h @@ -42,6 +42,7 @@ namespace SigDigger { // Demodulator state Suscan::Orbit m_orbit; bool m_enabled = false; + bool m_agc = true; float m_volume = 0; float m_cutOff = 0; SUFREQ m_lo = 0; @@ -100,6 +101,7 @@ namespace SigDigger { void setEnabled(bool); void setVolume(float); void setSquelchEnabled(bool); + void setAGCEnabled(bool); void setSquelchLevel(float); void setAudioCorrection(Suscan::Orbit const &); void setCorrectionEnabled(bool); diff --git a/Default/Audio/AudioWidget.cpp b/Default/Audio/AudioWidget.cpp index 0823d72d..13b97b14 100644 --- a/Default/Audio/AudioWidget.cpp +++ b/Default/Audio/AudioWidget.cpp @@ -70,6 +70,7 @@ AudioWidgetConfig::deserialize(Suscan::Object const &conf) LOAD(enabled); LOAD(collapsed); LOAD(lockToFreq); + LOAD(agc); LOAD(demod); LOAD(rate); LOAD(cutOff); @@ -94,6 +95,7 @@ AudioWidgetConfig::serialize() STORE(enabled); STORE(collapsed); STORE(lockToFreq); + STORE(agc); STORE(demod); STORE(rate); STORE(cutOff); @@ -235,6 +237,12 @@ AudioWidget::connectAll() this, SLOT(onOpenDopplerSettings())); + connect( + m_ui->agcButton, + SIGNAL(clicked(bool)), + this, + SLOT(onAGCChanged())); + connect( m_fcDialog, SIGNAL(accepted()), @@ -480,6 +488,12 @@ AudioWidget::isMuted() const return m_ui->muteButton->isChecked(); } +bool +AudioWidget::isAGCEnabled() const +{ + return m_ui->agcButton->isChecked(); +} + bool AudioWidget::isCorrectionEnabled() const { @@ -578,6 +592,15 @@ AudioWidget::setVolume(SUFLOAT volume) m_processor->setVolume(getMuteableVolume()); } +void +AudioWidget::setAGCEnabled(bool enabled) +{ + m_panelConfig->agc = enabled; + BLOCKSIG(m_ui->agcButton, setChecked(enabled)); + + m_processor->setAGCEnabled(enabled); +} + void AudioWidget::setMuted(bool muted) { @@ -765,6 +788,7 @@ AudioWidget::applyConfig() setSampleRate(m_panelConfig->rate); setCutOff(m_panelConfig->cutOff); setVolume(m_panelConfig->volume); + setAGCEnabled(m_panelConfig->agc); setDemod(SigDiggerHelpers::strToDemod(m_panelConfig->demod)); setEnabled(m_panelConfig->enabled); setLockToFreq(m_panelConfig->lockToFreq); @@ -945,6 +969,12 @@ AudioWidget::onVolumeChanged() setVolume(getVolume()); } +void +AudioWidget::onAGCChanged() +{ + setAGCEnabled(isAGCEnabled()); +} + void AudioWidget::onMuteToggled(bool) { diff --git a/Default/Audio/AudioWidget.h b/Default/Audio/AudioWidget.h index ee8a06ba..9b37fa9c 100644 --- a/Default/Audio/AudioWidget.h +++ b/Default/Audio/AudioWidget.h @@ -38,6 +38,7 @@ namespace SigDigger { bool enabled = false; bool collapsed = false; bool lockToFreq = false; + bool agc = true; std::string demod; std::string savePath; @@ -104,6 +105,7 @@ namespace SigDigger { void setCutOff(SUFLOAT); void setVolume(SUFLOAT); void setMuted(bool); + void setAGCEnabled(bool); void setSquelchEnabled(bool); void setSquelchLevel(SUFLOAT); @@ -123,6 +125,7 @@ namespace SigDigger { enum AudioDemod getDemod() const; bool getLockToFreq() const; unsigned int getSampleRate() const; + bool isAGCEnabled() const; SUFLOAT getCutOff() const; SUFLOAT getVolume() const; bool isMuted() const; @@ -169,6 +172,7 @@ namespace SigDigger { void onSquelchLevelChanged(); void onOpenDopplerSettings(); void onLockToFreqChanged(); + void onAGCChanged(); // Notifications void onSetTLE(Suscan::InspectorMessage const &); diff --git a/Default/Audio/AudioWidget.ui b/Default/Audio/AudioWidget.ui index 61747787..67551ea1 100644 --- a/Default/Audio/AudioWidget.ui +++ b/Default/Audio/AudioWidget.ui @@ -6,8 +6,8 @@ 0 0 - 271 - 276 + 281 + 277 @@ -194,6 +194,28 @@ 0 + + + + + 0 + 0 + + + + + 48 + 16777215 + + + + &SQL + + + true + + + @@ -215,15 +237,21 @@ - + 0 0 + + + 48 + 16777215 + + - &SQL + &AGC true