mirror of https://github.com/g4klx/MMDVM.git
Simplify the CTCSS and Noise Squelch decoders and logic.
This commit is contained in:
parent
b5ba384495
commit
2a001f491d
69
FM.cpp
69
FM.cpp
|
@ -89,10 +89,8 @@ void CFM::samples(bool cos, q15_t* samples, uint8_t length)
|
||||||
// ARMv7-M has hardware integer division
|
// ARMv7-M has hardware integer division
|
||||||
q15_t currentRFSample = q15_t((q31_t(samples[i]) << 8) / m_rxLevel);
|
q15_t currentRFSample = q15_t((q31_t(samples[i]) << 8) / m_rxLevel);
|
||||||
|
|
||||||
if (m_noiseSquelch) {
|
if (m_noiseSquelch)
|
||||||
uint8_t squelchState = m_squelch.process(currentRFSample);
|
cos = m_squelch.process(currentRFSample);
|
||||||
cos = NSQ_VALID(squelchState);
|
|
||||||
}
|
|
||||||
|
|
||||||
q15_t currentExtSample;
|
q15_t currentExtSample;
|
||||||
bool inputExt = m_inputExtRB.getSample(currentExtSample);//always consume the external input data so it does not overflow
|
bool inputExt = m_inputExtRB.getSample(currentExtSample);//always consume the external input data so it does not overflow
|
||||||
|
@ -107,55 +105,50 @@ void CFM::samples(bool cos, q15_t* samples, uint8_t length)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 1U: {
|
case 1U: {
|
||||||
uint8_t ctcssState = m_ctcssRX.process(currentRFSample);
|
bool ctcss = m_ctcssRX.process(currentRFSample);
|
||||||
|
|
||||||
// Delay the audio by 100ms to better match the CTCSS detector output
|
// Delay the audio by 100ms to better match the CTCSS detector output
|
||||||
m_inputRFRB.put(currentRFSample);
|
m_inputRFRB.put(currentRFSample);
|
||||||
m_inputRFRB.get(currentRFSample);
|
m_inputRFRB.get(currentRFSample);
|
||||||
|
|
||||||
if (!inputExt && CTCSS_NOT_READY(ctcssState) && m_modemState != STATE_FM) {
|
if (!inputExt && !ctcss && m_modemState != STATE_FM) {
|
||||||
// Not enough samples to determine if you have CTCSS, just carry on
|
// No CTCSS detected, just carry on
|
||||||
continue;
|
continue;
|
||||||
} else if ((inputExt || CTCSS_READY(ctcssState)) && m_modemState != STATE_FM) {
|
} else if ((inputExt || ctcss) && m_modemState != STATE_FM) {
|
||||||
// We had enough samples for CTCSS and we are in some other mode than FM
|
// We had CTCSS or external input
|
||||||
bool validCTCSS = CTCSS_VALID(ctcssState);
|
stateMachine(ctcss, inputExt);
|
||||||
stateMachine(validCTCSS, inputExt);
|
|
||||||
if (m_state == FS_LISTENING)
|
|
||||||
continue;
|
|
||||||
} else {
|
|
||||||
bool validCTCSS = CTCSS_VALID(ctcssState);
|
|
||||||
stateMachine(validCTCSS, inputExt);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 2U: {
|
|
||||||
uint8_t ctcssState = m_ctcssRX.process(currentRFSample);
|
|
||||||
if (!inputExt && CTCSS_NOT_READY(ctcssState) && m_modemState != STATE_FM) {
|
|
||||||
// Not enough samples to determine if you have CTCSS, just carry on
|
|
||||||
continue;
|
|
||||||
} else if ((inputExt || CTCSS_READY(ctcssState)) && m_modemState != STATE_FM) {
|
|
||||||
// We had enough samples for CTCSS and we are in some other mode than FM
|
|
||||||
bool validCTCSS = CTCSS_VALID(ctcssState);
|
|
||||||
stateMachine(validCTCSS && cos, inputExt);
|
|
||||||
if (m_state == FS_LISTENING)
|
if (m_state == FS_LISTENING)
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
bool validCTCSS = CTCSS_VALID(ctcssState);
|
stateMachine(ctcss, inputExt);
|
||||||
stateMachine(validCTCSS && cos, inputExt);
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 2U: {
|
||||||
|
bool ctcss = m_ctcssRX.process(currentRFSample);
|
||||||
|
if (!inputExt && !ctcss && m_modemState != STATE_FM) {
|
||||||
|
// No CTCSS detected, just carry on
|
||||||
|
continue;
|
||||||
|
} else if ((inputExt || (ctcss && cos)) && m_modemState != STATE_FM) {
|
||||||
|
// We had CTCSS or external input
|
||||||
|
stateMachine(ctcss && cos, inputExt);
|
||||||
|
if (m_state == FS_LISTENING)
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
stateMachine(ctcss && cos, inputExt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default: {
|
default: {
|
||||||
uint8_t ctcssState = m_ctcssRX.process(currentRFSample);
|
bool ctcss = m_ctcssRX.process(currentRFSample);
|
||||||
if (!inputExt && CTCSS_NOT_READY(ctcssState) && m_modemState != STATE_FM) {
|
if (!inputExt && !ctcss && m_modemState != STATE_FM) {
|
||||||
// Not enough samples to determine if you have CTCSS, just carry on
|
// No CTCSS detected, just carry on
|
||||||
continue;
|
continue;
|
||||||
} else if ((inputExt || CTCSS_READY(ctcssState)) && m_modemState != STATE_FM) {
|
} else if ((inputExt || (ctcss && cos)) && m_modemState != STATE_FM) {
|
||||||
// We had enough samples for CTCSS and we are in some other mode than FM
|
// We had CTCSS or external input
|
||||||
bool validCTCSS = CTCSS_VALID(ctcssState);
|
stateMachine(ctcss && cos, inputExt);
|
||||||
stateMachine(validCTCSS && cos, inputExt);
|
|
||||||
if (m_state == FS_LISTENING)
|
if (m_state == FS_LISTENING)
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -87,7 +87,7 @@ m_lowThreshold(0),
|
||||||
m_count(0U),
|
m_count(0U),
|
||||||
m_q0(0),
|
m_q0(0),
|
||||||
m_q1(0),
|
m_q1(0),
|
||||||
m_result(CTS_NONE)
|
m_state(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,13 +111,11 @@ uint8_t CFMCTCSSRX::setParams(uint8_t frequency, uint8_t highThreshold, uint8_t
|
||||||
return 0U;
|
return 0U;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t CFMCTCSSRX::process(q15_t sample)
|
bool CFMCTCSSRX::process(q15_t sample)
|
||||||
{
|
{
|
||||||
//get more dynamic into the decoder by multiplying the sample by 1.5
|
//get more dynamic into the decoder by multiplying the sample by 1.5
|
||||||
q31_t sample31 = q31_t(sample) + (q31_t(sample) >> 1);
|
q31_t sample31 = q31_t(sample) + (q31_t(sample) >> 1);
|
||||||
|
|
||||||
m_result &= ~CTS_READY;
|
|
||||||
|
|
||||||
q31_t q2 = m_q1;
|
q31_t q2 = m_q1;
|
||||||
m_q1 = m_q0;
|
m_q1 = m_q0;
|
||||||
|
|
||||||
|
@ -149,33 +147,29 @@ uint8_t CFMCTCSSRX::process(q15_t sample)
|
||||||
// value = m_q0 * m_q0 + m_q1 * m_q1 - m_q0 * m_q1 * m_coeffDivTwo * 2
|
// value = m_q0 * m_q0 + m_q1 * m_q1 - m_q0 * m_q1 * m_coeffDivTwo * 2
|
||||||
q31_t value = t2 + t4 - t9;
|
q31_t value = t2 + t4 - t9;
|
||||||
|
|
||||||
bool previousCTCSSValid = CTCSS_VALID(m_result);
|
bool previousState = m_state;
|
||||||
|
|
||||||
q31_t threshold = m_highThreshold;
|
q31_t threshold = m_highThreshold;
|
||||||
if (previousCTCSSValid)
|
if (previousState)
|
||||||
threshold = m_lowThreshold;
|
threshold = m_lowThreshold;
|
||||||
|
|
||||||
m_result |= CTS_READY;
|
m_state = value >= threshold;
|
||||||
if (value >= threshold)
|
|
||||||
m_result |= CTS_VALID;
|
|
||||||
else
|
|
||||||
m_result &= ~CTS_VALID;
|
|
||||||
|
|
||||||
if (previousCTCSSValid != CTCSS_VALID(m_result))
|
if (previousState != m_state)
|
||||||
DEBUG4("CTCSS Value / Threshold / Valid", value, threshold, CTCSS_VALID(m_result));
|
DEBUG4("CTCSS Value / Threshold / Valid", value, threshold, m_state);
|
||||||
|
|
||||||
m_count = 0U;
|
m_count = 0U;
|
||||||
m_q0 = 0;
|
m_q0 = 0;
|
||||||
m_q1 = 0;
|
m_q1 = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return m_result;
|
return m_state;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CFMCTCSSRX::reset()
|
void CFMCTCSSRX::reset()
|
||||||
{
|
{
|
||||||
m_q0 = 0;
|
m_q0 = 0;
|
||||||
m_q1 = 0;
|
m_q1 = 0;
|
||||||
m_result = CTS_NONE;
|
m_state = false;
|
||||||
m_count = 0U;
|
m_count = 0U;
|
||||||
}
|
}
|
||||||
|
|
13
FMCTCSSRX.h
13
FMCTCSSRX.h
|
@ -21,22 +21,13 @@
|
||||||
|
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
|
|
||||||
const uint8_t CTS_NONE = 0U;
|
|
||||||
const uint8_t CTS_READY = 1U;
|
|
||||||
const uint8_t CTS_VALID = 2U;
|
|
||||||
|
|
||||||
#define CTCSS_READY(a) ((a & CTS_READY) != 0)
|
|
||||||
#define CTCSS_NOT_READY(a) ((a & CTS_READY) == 0)
|
|
||||||
#define CTCSS_VALID(a) ((a & CTS_VALID) != 0)
|
|
||||||
#define CTCSS_NOT_VALID(a) ((a & CTS_VALID) == 0)
|
|
||||||
|
|
||||||
class CFMCTCSSRX {
|
class CFMCTCSSRX {
|
||||||
public:
|
public:
|
||||||
CFMCTCSSRX();
|
CFMCTCSSRX();
|
||||||
|
|
||||||
uint8_t setParams(uint8_t frequency, uint8_t highThreshold, uint8_t lowThreshold);
|
uint8_t setParams(uint8_t frequency, uint8_t highThreshold, uint8_t lowThreshold);
|
||||||
|
|
||||||
uint8_t process(q15_t sample);
|
bool process(q15_t sample);
|
||||||
|
|
||||||
void reset();
|
void reset();
|
||||||
|
|
||||||
|
@ -47,7 +38,7 @@ private:
|
||||||
uint16_t m_count;
|
uint16_t m_count;
|
||||||
q31_t m_q0;
|
q31_t m_q0;
|
||||||
q31_t m_q1;
|
q31_t m_q1;
|
||||||
uint8_t m_result;
|
bool m_state;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -32,23 +32,21 @@ m_lowThreshold(0),
|
||||||
m_count(0U),
|
m_count(0U),
|
||||||
m_q0(0),
|
m_q0(0),
|
||||||
m_q1(0),
|
m_q1(0),
|
||||||
m_result(NS_NONE)
|
m_state(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void CFMNoiseSquelch::setParams(uint8_t highThreshold, uint8_t lowThreshold)
|
void CFMNoiseSquelch::setParams(uint8_t highThreshold, uint8_t lowThreshold)
|
||||||
{
|
{
|
||||||
m_highThreshold = q31_t(highThreshold);
|
m_highThreshold = q31_t(highThreshold) * 20;
|
||||||
m_lowThreshold = q31_t(lowThreshold);
|
m_lowThreshold = q31_t(lowThreshold) * 20;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t CFMNoiseSquelch::process(q15_t sample)
|
bool CFMNoiseSquelch::process(q15_t sample)
|
||||||
{
|
{
|
||||||
//get more dynamic into the decoder by multiplying the sample by 1.5
|
//get more dynamic into the decoder by multiplying the sample by 1.5
|
||||||
q31_t sample31 = q31_t(sample) + (q31_t(sample) >> 1);
|
q31_t sample31 = q31_t(sample) + (q31_t(sample) >> 1);
|
||||||
|
|
||||||
m_result &= ~NS_READY;
|
|
||||||
|
|
||||||
q31_t q2 = m_q1;
|
q31_t q2 = m_q1;
|
||||||
m_q1 = m_q0;
|
m_q1 = m_q0;
|
||||||
|
|
||||||
|
@ -80,33 +78,29 @@ uint8_t CFMNoiseSquelch::process(q15_t sample)
|
||||||
// value = m_q0 * m_q0 + m_q1 * m_q1 - m_q0 * m_q1 * m_coeffDivTwo * 2
|
// value = m_q0 * m_q0 + m_q1 * m_q1 - m_q0 * m_q1 * m_coeffDivTwo * 2
|
||||||
q31_t value = t2 + t4 - t9;
|
q31_t value = t2 + t4 - t9;
|
||||||
|
|
||||||
bool previousNSQValid = NSQ_VALID(m_result);
|
bool previousState = m_state;
|
||||||
|
|
||||||
q31_t threshold = m_highThreshold;
|
q31_t threshold = m_highThreshold;
|
||||||
if (previousNSQValid)
|
if (previousState)
|
||||||
threshold = m_lowThreshold;
|
threshold = m_lowThreshold;
|
||||||
|
|
||||||
m_result |= NS_READY;
|
m_state = value < threshold;
|
||||||
if (value < threshold)
|
|
||||||
m_result |= NS_VALID;
|
|
||||||
else
|
|
||||||
m_result &= ~NS_VALID;
|
|
||||||
|
|
||||||
if (previousNSQValid != NSQ_VALID(m_result))
|
if (previousState != m_state)
|
||||||
DEBUG4("Noise Squelch Value / Threshold / Valid", value, threshold, NSQ_VALID(m_result));
|
DEBUG4("Noise Squelch Value / Threshold / Valid", value, threshold, m_state);
|
||||||
|
|
||||||
m_count = 0U;
|
m_count = 0U;
|
||||||
m_q0 = 0;
|
m_q0 = 0;
|
||||||
m_q1 = 0;
|
m_q1 = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return m_result;
|
return m_state;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CFMNoiseSquelch::reset()
|
void CFMNoiseSquelch::reset()
|
||||||
{
|
{
|
||||||
m_q0 = 0;
|
m_q0 = 0;
|
||||||
m_q1 = 0;
|
m_q1 = 0;
|
||||||
m_result = NS_NONE;
|
m_state = false;
|
||||||
m_count = 0U;
|
m_count = 0U;
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,22 +21,13 @@
|
||||||
|
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
|
|
||||||
const uint8_t NS_NONE = 0U;
|
|
||||||
const uint8_t NS_READY = 1U;
|
|
||||||
const uint8_t NS_VALID = 2U;
|
|
||||||
|
|
||||||
#define NSQ_READY(a) ((a & NS_READY) != 0)
|
|
||||||
#define NSQ_NOT_READY(a) ((a & NS_READY) == 0)
|
|
||||||
#define NSQ_VALID(a) ((a & NS_VALID) != 0)
|
|
||||||
#define NSQ_NOT_VALID(a) ((a & NS_VALID) == 0)
|
|
||||||
|
|
||||||
class CFMNoiseSquelch {
|
class CFMNoiseSquelch {
|
||||||
public:
|
public:
|
||||||
CFMNoiseSquelch();
|
CFMNoiseSquelch();
|
||||||
|
|
||||||
void setParams(uint8_t highThreshold, uint8_t lowThreshold);
|
void setParams(uint8_t highThreshold, uint8_t lowThreshold);
|
||||||
|
|
||||||
uint8_t process(q15_t sample);
|
bool process(q15_t sample);
|
||||||
|
|
||||||
void reset();
|
void reset();
|
||||||
|
|
||||||
|
@ -46,7 +37,7 @@ private:
|
||||||
uint16_t m_count;
|
uint16_t m_count;
|
||||||
q31_t m_q0;
|
q31_t m_q0;
|
||||||
q31_t m_q1;
|
q31_t m_q1;
|
||||||
uint8_t m_result;
|
bool m_state;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -109,7 +109,7 @@ const uint8_t MMDVM_DEBUG5 = 0xF5U;
|
||||||
#define HW_TYPE "MMDVM"
|
#define HW_TYPE "MMDVM"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define DESCRIPTION "20200728 (D-Star/DMR/System Fusion/P25/NXDN/POCSAG/FM/AX.25)"
|
#define DESCRIPTION "20200731 (D-Star/DMR/System Fusion/P25/NXDN/POCSAG/FM/AX.25)"
|
||||||
|
|
||||||
#if defined(GITVERSION)
|
#if defined(GITVERSION)
|
||||||
#define concat(h, a, b, c) h " " a " " b " GitID #" c ""
|
#define concat(h, a, b, c) h " " a " " b " GitID #" c ""
|
||||||
|
|
Loading…
Reference in New Issue