Move division to CTCSSRX, change sample unscaling to 1/rxLevel

This commit is contained in:
Geoffrey Merck 2020-04-27 11:16:06 +02:00
parent f9530ee82a
commit 4ffaa62855
4 changed files with 31 additions and 27 deletions

View file

@ -53,7 +53,7 @@ class CFMCTCSSRX {
public:
CFMCTCSSRX();
uint8_t setParams(uint8_t frequency, uint8_t threshold);
uint8_t setParams(uint8_t frequency, uint8_t threshold, q15_t rxLevel);
CTCSSState process(q15_t sample);
@ -62,12 +62,25 @@ public:
void reset();
private:
q63_t m_coeffDivTwo;
q31_t m_threshold;
uint16_t m_count;
q31_t m_q0;
q31_t m_q1;
CTCSSState m_result;
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;
};
#endif