CTCSS threshold is level agnostic, experimental

This commit is contained in:
Geoffrey Merck 2020-04-25 22:12:16 +02:00
parent 8c38fdb36d
commit d2d50e21e1
3 changed files with 21 additions and 2 deletions

View File

@ -109,10 +109,21 @@ uint8_t CFMCTCSSRX::setParams(uint8_t frequency, uint8_t threshold)
return 0U; return 0U;
} }
char bla[256];
CTCSSState CFMCTCSSRX::process(q15_t sample) CTCSSState CFMCTCSSRX::process(q15_t sample)
{ {
m_result = m_result & (~CTS_READY); m_result = m_result & (~CTS_READY);
// sample / rxLevel
q15_t rxLevel = io.getRxLevel();
q31_t sample31 = q31_t(sample) << 16;
if (((sample31 >> 31) & 1) == ((rxLevel >> 15) & 1))
sample31 += rxLevel >> 1;
else
sample31 -= rxLevel >> 1;
sample31 /= rxLevel;
q31_t q2 = m_q1; q31_t q2 = m_q1;
m_q1 = m_q0; m_q1 = m_q0;
@ -122,7 +133,7 @@ CTCSSState CFMCTCSSRX::process(q15_t sample)
q31_t t3 = t2 * 2; q31_t t3 = t2 * 2;
// m_q0 = m_coeffDivTwo * m_q1 * 2 - q2 + sample // m_q0 = m_coeffDivTwo * m_q1 * 2 - q2 + sample
m_q0 = t3 - q2 + q31_t(sample); m_q0 = t3 - q2 + sample31;
m_count++; m_count++;
if (m_count == N) { if (m_count == N) {
@ -143,7 +154,8 @@ CTCSSState 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;
sprintf(bla, "CTCSS Value / Threshold %d %d", value, m_threshold);
DEBUG1(bla);
m_result = m_result | CTS_READY; m_result = m_result | CTS_READY;
if (value >= m_threshold) if (value >= m_threshold)
m_result = m_result | CTS_VALID; m_result = m_result | CTS_VALID;

5
IO.cpp
View File

@ -592,3 +592,8 @@ bool CIO::hasLockout() const
{ {
return m_lockout; return m_lockout;
} }
q15_t CIO::getRxLevel() const
{
return m_rxLevel;
}

2
IO.h
View File

@ -56,6 +56,8 @@ public:
void selfTest(); void selfTest();
q15_t getRxLevel() const;
private: private:
bool m_started; bool m_started;