diff --git a/plugins/channelrx/demodnfm/nfmdemod.cpp b/plugins/channelrx/demodnfm/nfmdemod.cpp index d377c23a5..24d4aecfa 100644 --- a/plugins/channelrx/demodnfm/nfmdemod.cpp +++ b/plugins/channelrx/demodnfm/nfmdemod.cpp @@ -27,7 +27,7 @@ #include "dsp/dspengine.h" #include "nfmdemodgui.h" -static const double afSqTones[2] = {1200.0, 8000.0}; // {1200.0, 8000.0}; +static const double afSqTones[2] = {1000.0, 6000.0}; // {1200.0, 8000.0}; MESSAGE_CLASS_DEFINITION(NFMDemod::MsgConfigureNFMDemod, Message) @@ -75,7 +75,7 @@ NFMDemod::NFMDemod() : m_movingAverage.resize(32, 0); m_ctcssDetector.setCoefficients(3000, 6000.0); // 0.5s / 2 Hz resolution - m_afSquelch.setCoefficients(24, 600, 48000.0, 200, 0); // 0.5ms test period, 300ms average span, 48kS/s SR, 100ms attack, no decay + m_afSquelch.setCoefficients(24, 60, 48000.0, 20, 0); // 0.5ms test period, 30ms average span, 48kS/s SR, 10ms attack, no decay DSPEngine::instance()->addAudioSink(&m_audioFifo); } diff --git a/sdrbase/dsp/afsquelch.cpp b/sdrbase/dsp/afsquelch.cpp index cc61e43c8..44844bc30 100644 --- a/sdrbase/dsp/afsquelch.cpp +++ b/sdrbase/dsp/afsquelch.cpp @@ -29,6 +29,7 @@ AFSquelch::AFSquelch() : m_attackCount(0), m_samplesDecay(0), m_decayCount(0), + m_squelchCount(0), m_isOpen(false), m_threshold(0.0) { @@ -65,6 +66,7 @@ AFSquelch::AFSquelch(unsigned int nbTones, const double *tones) : m_attackCount(0), m_samplesDecay(0), m_decayCount(0), + m_squelchCount(0), m_isOpen(false), m_threshold(0.0) { @@ -117,6 +119,7 @@ void AFSquelch::setCoefficients( m_maxPowerIndex = 0; m_attackCount = 0; m_decayCount = 0; + m_squelchCount = 0; m_isOpen = false; m_threshold = 0.0; @@ -239,32 +242,55 @@ bool AFSquelch::evaluate() } } - if ((minPower/maxPower < m_threshold) && (minIndex > maxIndex)) // open condition - { - if ((m_samplesAttack > 0) && (m_attackCount < m_samplesAttack)) - { - m_isOpen = false; - m_attackCount++; - } - else - { - m_isOpen = true; - m_decayCount = 0; - } - } - else - { - if ((m_samplesDecay > 0) && (m_decayCount < m_samplesDecay)) - { - m_isOpen = true; - m_decayCount++; - } - else - { - m_isOpen = false; - m_attackCount = 0; - } - } +// m_isOpen = ((minPower/maxPower < m_threshold) && (minIndex > maxIndex)); + + if ((minPower/maxPower < m_threshold) && (minIndex > maxIndex)) // open condition + { + if (m_squelchCount < m_samplesAttack + m_samplesDecay) + { + m_squelchCount++; + } + } + else + { + if (m_squelchCount > m_samplesAttack) + { + m_squelchCount--; + } + else + { + m_squelchCount = 0; + } + } + + m_isOpen = (m_squelchCount >= m_samplesAttack) ; + +// if ((minPower/maxPower < m_threshold) && (minIndex > maxIndex)) // open condition +// { +// if ((m_samplesAttack > 0) && (m_attackCount < m_samplesAttack)) +// { +// m_isOpen = false; +// m_attackCount++; +// } +// else +// { +// m_isOpen = true; +// m_decayCount = 0; +// } +// } +// else +// { +// if ((m_samplesDecay > 0) && (m_decayCount < m_samplesDecay)) +// { +// m_isOpen = true; +// m_decayCount++; +// } +// else +// { +// m_isOpen = false; +// m_attackCount = 0; +// } +// } return m_isOpen; } diff --git a/sdrbase/dsp/afsquelch.h b/sdrbase/dsp/afsquelch.h index dabc6ba9a..503dd4893 100644 --- a/sdrbase/dsp/afsquelch.h +++ b/sdrbase/dsp/afsquelch.h @@ -76,6 +76,7 @@ private: unsigned int m_attackCount; unsigned int m_samplesDecay; unsigned int m_decayCount; + unsigned int m_squelchCount; bool m_isOpen; double m_threshold; double *m_k;