diff --git a/plugins/channelrx/demodnfm/nfmdemod.cpp b/plugins/channelrx/demodnfm/nfmdemod.cpp index 32f200651..4d6f93f27 100644 --- a/plugins/channelrx/demodnfm/nfmdemod.cpp +++ b/plugins/channelrx/demodnfm/nfmdemod.cpp @@ -38,6 +38,7 @@ NFMDemod::NFMDemod() : m_squelchGate(2400), m_audioMute(false), m_squelchOpen(false), + m_afSquelchOpen(false), m_magsq(0.0f), m_magsqSum(0.0f), m_magsqPeak(0.0f), @@ -180,22 +181,46 @@ void NFMDemod::feed(const SampleVector::const_iterator& begin, const SampleVecto // AF processing - if ( (m_running.m_deltaSquelch && ((deviation > m_squelchLevel) || (deviation < -m_squelchLevel))) || - (!m_running.m_deltaSquelch && (m_movingAverage.average() < m_squelchLevel)) ) + if (m_running.m_deltaSquelch) { - if (m_squelchCount > 0) - { - m_squelchCount--; - } + if (m_afSquelch.analyze(demod)) { + m_squelchCount = m_afSquelch.evaluate() ? m_squelchGate + 480 : 0; + } } else { - if (m_squelchCount < m_squelchGate + 480) - { - m_squelchCount++; - } + if (m_movingAverage.average() < m_squelchLevel) + { + if (m_squelchCount > 0) + { + m_squelchCount--; + } + } + else + { + if (m_squelchCount < m_squelchGate + 480) + { + m_squelchCount++; + } + } } +// if ( (m_running.m_deltaSquelch && ((deviation > m_squelchLevel) || (deviation < -m_squelchLevel))) || +// (!m_running.m_deltaSquelch && (m_movingAverage.average() < m_squelchLevel)) ) +// { +// if (m_squelchCount > 0) +// { +// m_squelchCount--; +// } +// } +// else +// { +// if (m_squelchCount < m_squelchGate + 480) +// { +// m_squelchCount++; +// } +// } + //squelchOpen = (getMag() > m_squelchLevel); m_squelchOpen = (m_squelchCount > m_squelchGate); @@ -244,9 +269,17 @@ void NFMDemod::feed(const SampleVector::const_iterator& begin, const SampleVecto } else { - Real squelchFactor = (Real) (m_squelchCount - m_squelchGate) / 480.0f; - demod = m_bandpass.filter(demod); - sample = demod * m_running.m_volume * squelchFactor * squelchFactor; + demod = m_bandpass.filter(demod); + + if (m_running.m_deltaSquelch) + { + sample = demod * m_running.m_volume; + } + else + { + Real squelchFactor = (Real) (m_squelchCount - m_squelchGate) / 480.0f; + sample = demod * m_running.m_volume * squelchFactor * squelchFactor; + } } } else @@ -400,13 +433,17 @@ void NFMDemod::apply() if ((m_config.m_squelch != m_running.m_squelch) || (m_config.m_deltaSquelch != m_running.m_deltaSquelch)) { - if (m_config.m_deltaSquelch) { // input is a value in negative millis - m_squelchLevel = - m_config.m_squelch / 1000.0; - } else { // input is a value in centi-Bels + if (m_config.m_deltaSquelch) + { // input is a value in negative millis + m_squelchLevel = (- m_config.m_squelch) / 1000.0; + m_afSquelch.setThreshold(m_squelchLevel); + } + else + { // input is a value in centi-Bels m_squelchLevel = std::pow(10.0, m_config.m_squelch / 100.0); } //m_squelchLevel *= m_squelchLevel; - //m_afSquelch.setThreshold(m_squelchLevel); + //m_afSquelch.setThreshold(m_squelchLevel); } m_running.m_inputSampleRate = m_config.m_inputSampleRate; diff --git a/plugins/channelrx/demodnfm/nfmdemod.h b/plugins/channelrx/demodnfm/nfmdemod.h index 88e0ff1cc..9a02f47e6 100644 --- a/plugins/channelrx/demodnfm/nfmdemod.h +++ b/plugins/channelrx/demodnfm/nfmdemod.h @@ -215,6 +215,7 @@ private: Real m_squelchLevel; bool m_squelchOpen; + bool m_afSquelchOpen; Real m_magsq; //!< displayed averaged value Real m_magsqSum; Real m_magsqPeak; diff --git a/plugins/channelrx/demodnfm/nfmdemodgui.cpp b/plugins/channelrx/demodnfm/nfmdemodgui.cpp index 6e6cade4f..15fe66b3a 100644 --- a/plugins/channelrx/demodnfm/nfmdemodgui.cpp +++ b/plugins/channelrx/demodnfm/nfmdemodgui.cpp @@ -216,7 +216,7 @@ void NFMDemodGUI::on_deltaSquelch_toggled(bool checked) if (ui->deltaSquelch->isChecked()) { ui->squelchText->setText(QString("%1").arg((-ui->squelch->value()) / 10.0, 0, 'f', 1)); - ui->squelchText->setToolTip(tr("Squelch deviation threshold (%)")); + ui->squelchText->setToolTip(tr("Squelch AF balance threshold (%)")); } else { diff --git a/plugins/channelrx/demodnfm/nfmdemodgui.ui b/plugins/channelrx/demodnfm/nfmdemodgui.ui index 9cbce67ba..8098c82fb 100644 --- a/plugins/channelrx/demodnfm/nfmdemodgui.ui +++ b/plugins/channelrx/demodnfm/nfmdemodgui.ui @@ -407,8 +407,11 @@ 24 + + true + - Toggle frequency deviation (on) or channel power (off) based squelch + Toggle AF balance (on) or channel power (off) based squelch D diff --git a/sdrbase/dsp/afsquelch.cpp b/sdrbase/dsp/afsquelch.cpp index 453c1f7fe..0ae54d192 100644 --- a/sdrbase/dsp/afsquelch.cpp +++ b/sdrbase/dsp/afsquelch.cpp @@ -37,7 +37,7 @@ AFSquelch::AFSquelch() : m_u0 = new double[m_nTones]; m_u1 = new double[m_nTones]; m_power = new double[m_nTones]; - m_movingAverages.resize(m_nTones, MovingAverage(m_nbAvg, 0.0)); + m_movingAverages.resize(m_nTones, MovingAverage(m_nbAvg, 0.0)); m_toneSet[0] = 2000.0; m_toneSet[1] = 10000.0; @@ -89,7 +89,7 @@ void AFSquelch::setCoefficients(int N, unsigned int nbAvg, int _samplerate, int m_sampleRate = _samplerate; m_samplesAttack = _samplesAttack; m_samplesDecay = _samplesDecay; - m_movingAverages.resize(m_nTones, MovingAverage(m_nbAvg, 0.0)); + m_movingAverages.resize(m_nTones, MovingAverage(m_nbAvg, 1.0)); // for each of the frequencies (tones) of interest calculate // k and the associated filter coefficient as per the Goertzel @@ -169,7 +169,7 @@ void AFSquelch::reset() bool AFSquelch::evaluate() { - double maxPower = 0.0; + double maxPower = 1.0; double minPower; int minIndex = 0, maxIndex = 0; @@ -194,6 +194,7 @@ bool AFSquelch::evaluate() // principle is to open if power is uneven because noise gives even power bool open = (minPower/maxPower < m_threshold) && (minIndex > maxIndex); + //qDebug("AFSquelch::evaluate: %g : %g", minPower/maxPower, m_threshold); if (open) { diff --git a/sdrbase/dsp/afsquelch.h b/sdrbase/dsp/afsquelch.h index eb587995d..22d52531b 100644 --- a/sdrbase/dsp/afsquelch.h +++ b/sdrbase/dsp/afsquelch.h @@ -83,7 +83,7 @@ private: double *m_u0; double *m_u1; double *m_power; - std::vector > m_movingAverages; + std::vector > m_movingAverages; };