diff --git a/FM.cpp b/FM.cpp index 85f9fb5..4a2eb70 100644 --- a/FM.cpp +++ b/FM.cpp @@ -156,7 +156,7 @@ uint8_t CFM::setMisc(uint16_t timeout, uint8_t timeoutLevel, uint8_t ctcssFreque m_timeoutTone.setParams(timeoutLevel); m_blanking.setParams(maxDev, timeoutLevel); - uint8_t ret = m_ctcssRX.setParams(ctcssFrequency, ctcssThreshold, q15_t(rxLevel * 128)); + uint8_t ret = m_ctcssRX.setParams(ctcssFrequency, ctcssThreshold, rxLevel); if (ret != 0U) return ret; @@ -397,5 +397,3 @@ void CFM::beginRelaying() m_timeoutTimer.start(); m_ackMinTimer.start(); } - - diff --git a/FMCTCSSRX.cpp b/FMCTCSSRX.cpp index 180f1f3..00eebc6 100644 --- a/FMCTCSSRX.cpp +++ b/FMCTCSSRX.cpp @@ -91,10 +91,9 @@ m_rxLevelInverse(1) { } -uint8_t CFMCTCSSRX::setParams(uint8_t frequency, uint8_t threshold, q15_t rxLevel) +uint8_t CFMCTCSSRX::setParams(uint8_t frequency, uint8_t threshold, uint8_t level) { - // Calculate 1/rxLevel - m_rxLevelInverse = q31_t(q15Division(65535 /* This value should be 32767 (q15 1). But this does not work.*/, rxLevel)); + m_rxLevelInverse = 255 / q15_t(level); m_coeffDivTwo = 0; @@ -115,7 +114,7 @@ uint8_t CFMCTCSSRX::setParams(uint8_t frequency, uint8_t threshold, q15_t rxLeve CTCSSState CFMCTCSSRX::process(q15_t sample) { - q63_t sample31 = q31_t(sample) * m_rxLevelInverse; + q31_t sample31 = q31_t(sample) * m_rxLevelInverse; m_result = m_result & (~CTS_READY); diff --git a/FMCTCSSRX.h b/FMCTCSSRX.h index 7f36b32..4c1dfc3 100644 --- a/FMCTCSSRX.h +++ b/FMCTCSSRX.h @@ -53,7 +53,7 @@ class CFMCTCSSRX { public: CFMCTCSSRX(); - uint8_t setParams(uint8_t frequency, uint8_t threshold, q15_t rxLevel); + uint8_t setParams(uint8_t frequency, uint8_t threshold, uint8_t level); CTCSSState process(q15_t sample); @@ -62,25 +62,13 @@ public: void reset(); private: - static inline q15_t q15Division(q15_t a, q15_t divisor) - { - q31_t a31 = q31_t(a) << 16; - - if (((a >> 31) & 1) == ((divisor >> 15) & 1)) - a31 += divisor >> 1; - else - a31 -= divisor >> 1; - - return a31 / divisor; - } - q63_t m_coeffDivTwo; q31_t m_threshold; uint16_t m_count; q31_t m_q0; q31_t m_q1; CTCSSState m_result; - q31_t m_rxLevelInverse; + q15_t m_rxLevelInverse; }; #endif diff --git a/SerialPort.cpp b/SerialPort.cpp index 7a6e609..da81dfd 100644 --- a/SerialPort.cpp +++ b/SerialPort.cpp @@ -101,7 +101,7 @@ const uint8_t MMDVM_DEBUG5 = 0xF5U; #define HW_TYPE "MMDVM" #endif -#define DESCRIPTION "20200426 (D-Star/DMR/System Fusion/P25/NXDN/POCSAG/FM)" +#define DESCRIPTION "20200427 (D-Star/DMR/System Fusion/P25/NXDN/POCSAG/FM)" #if defined(GITVERSION) #define concat(h, a, b, c) h " " a " " b " GitID #" c ""