mirror of https://github.com/g4klx/MMDVM.git
Use long based algorithm
This commit is contained in:
parent
7435074c0f
commit
32a71bfbf6
159
FMCTCSSRX.cpp
159
FMCTCSSRX.cpp
|
@ -22,67 +22,73 @@
|
||||||
|
|
||||||
const struct CTCSS_TABLE {
|
const struct CTCSS_TABLE {
|
||||||
uint8_t frequency;
|
uint8_t frequency;
|
||||||
q31_t coeff;
|
long coeff;
|
||||||
} CTCSS_TABLE_DATA[] = {
|
} CTCSS_TABLE_DATA[] = {
|
||||||
{ 67U, 131052},
|
{67, 65527},
|
||||||
{ 69U, 131051},
|
{69, 65526},
|
||||||
{ 71U, 131049},
|
{71, 65525},
|
||||||
{ 74U, 131048},
|
{74, 65524},
|
||||||
{ 77U, 131046},
|
{77, 65523},
|
||||||
{ 79U, 131044},
|
{79, 65522},
|
||||||
{ 82U, 131042},
|
{82, 65521},
|
||||||
{ 85U, 131040},
|
{85, 65520},
|
||||||
{ 88U, 131037},
|
{88, 65519},
|
||||||
{ 91U, 131035},
|
{91, 65518},
|
||||||
{ 94U, 131032},
|
{94, 65517},
|
||||||
{ 97U, 131030},
|
{97, 65516},
|
||||||
{100U, 131028},
|
{100, 65514},
|
||||||
{103U, 131024},
|
{103, 65513},
|
||||||
{107U, 131021},
|
{107, 65511},
|
||||||
{110U, 131017},
|
{110, 65509},
|
||||||
{114U, 131013},
|
{114, 65507},
|
||||||
{118U, 131009},
|
{123, 65503},
|
||||||
{123U, 131005},
|
{127, 65501},
|
||||||
{127U, 131000},
|
{131, 65498},
|
||||||
{131U, 130994},
|
{136, 65495},
|
||||||
{136U, 130989},
|
{141, 65492},
|
||||||
{141U, 130983},
|
{146, 65489},
|
||||||
{146U, 130977},
|
{150, 65487},
|
||||||
{151U, 130970},
|
{151, 65486},
|
||||||
{156U, 130962},
|
{156, 65482},
|
||||||
{159U, 130958},
|
{159, 65480},
|
||||||
{162U, 130954},
|
{162, 65478},
|
||||||
{165U, 130949},
|
{165, 65476},
|
||||||
{167U, 130946},
|
{167, 65474},
|
||||||
{171U, 130941},
|
{171, 65472},
|
||||||
{173U, 130937},
|
{173, 65470},
|
||||||
{177U, 130931},
|
{177, 65467},
|
||||||
{179U, 130927},
|
{179, 65465},
|
||||||
{183U, 130921},
|
{183, 65462},
|
||||||
{186U, 130917},
|
{186, 65460},
|
||||||
{189U, 130911},
|
{188, 65458},
|
||||||
{192U, 130906},
|
{189, 65457},
|
||||||
{196U, 130899},
|
{192, 65454},
|
||||||
{199U, 130894},
|
{196, 65451},
|
||||||
{203U, 130887},
|
{199, 65448},
|
||||||
{206U, 130881},
|
{203, 65445},
|
||||||
{210U, 130873},
|
{206, 65442},
|
||||||
{218U, 130859},
|
{210, 65438},
|
||||||
{225U, 130844},
|
{213, 65435},
|
||||||
{229U, 130837},
|
{218, 65431},
|
||||||
{233U, 130827},
|
{221, 65428},
|
||||||
{241U, 130810},
|
{225, 65424},
|
||||||
{250U, 130791},
|
{229, 65420},
|
||||||
{254U, 130783}};
|
{233, 65416},
|
||||||
|
{237, 65412},
|
||||||
|
{241, 65407},
|
||||||
|
{245, 65403},
|
||||||
|
{250, 65398},
|
||||||
|
{254, 65393}
|
||||||
|
};
|
||||||
|
|
||||||
const uint8_t CTCSS_TABLE_DATA_LEN = 50U;
|
const uint8_t CTCSS_TABLE_DATA_LEN = 55U;
|
||||||
|
|
||||||
// 4Hz bandwidth
|
// 4Hz bandwidth
|
||||||
const uint16_t N = 24000U / 4U;
|
const uint16_t N = 24000U / 4U;
|
||||||
|
|
||||||
CFMCTCSSRX::CFMCTCSSRX() :
|
CFMCTCSSRX::CFMCTCSSRX() :
|
||||||
m_coeff(0),
|
m_coeff(0),
|
||||||
m_threshold(0U),
|
m_thresholdSquared(0U),
|
||||||
m_count(0U),
|
m_count(0U),
|
||||||
m_q0(0),
|
m_q0(0),
|
||||||
m_q1(0),
|
m_q1(0),
|
||||||
|
@ -102,7 +108,7 @@ uint8_t CFMCTCSSRX::setParams(uint8_t frequency, uint8_t threshold)
|
||||||
if (m_coeff == 0)
|
if (m_coeff == 0)
|
||||||
return 4U;
|
return 4U;
|
||||||
|
|
||||||
m_threshold = threshold * threshold;
|
m_thresholdSquared = (long)(threshold * threshold);
|
||||||
|
|
||||||
return 0U;
|
return 0U;
|
||||||
}
|
}
|
||||||
|
@ -110,39 +116,24 @@ uint8_t CFMCTCSSRX::setParams(uint8_t frequency, uint8_t threshold)
|
||||||
bool CFMCTCSSRX::process(const q15_t* samples, uint8_t length)
|
bool CFMCTCSSRX::process(const q15_t* samples, uint8_t length)
|
||||||
{
|
{
|
||||||
for (unsigned int i = 0U; i < length; i++) {
|
for (unsigned int i = 0U; i < length; i++) {
|
||||||
q31_t q2 = m_q1;
|
|
||||||
|
long sampleLong = (long)samples[i];
|
||||||
|
|
||||||
|
long q2 = m_q1;
|
||||||
m_q1 = m_q0;
|
m_q1 = m_q0;
|
||||||
|
m_q0 = m_coeff * m_q1 - q2 + sampleLong;
|
||||||
// Q31 multiplication, t2 = m_coeff * m_q1
|
|
||||||
q63_t t1 = m_coeff * m_q1;
|
|
||||||
q31_t t2 = __SSAT(t1 >> 32, 31);
|
|
||||||
|
|
||||||
// m_q0 = m_coeff * m_q1 - q2 + samples[i]
|
|
||||||
m_q0 = t2 - q2 + samples[i];
|
|
||||||
|
|
||||||
m_count++;
|
m_count++;
|
||||||
if (m_count == N) {
|
if(m_count == N) {
|
||||||
// Q31 multiplication, t2 = m_q0 * m_q0
|
m_count = 0;
|
||||||
q63_t t1 = m_q0 * m_q0;
|
if(!m_result) {
|
||||||
q31_t t2 = __SSAT(t1 >> 32, 31);
|
long magnitudeSquared = m_q0 * m_q0 + m_q1 * m_q1 - m_q0 * m_q1 * m_coeff;
|
||||||
|
if(magnitudeSquared >= m_thresholdSquared) {
|
||||||
// Q31 multiplication, t4 = m_q0 * m_q0
|
m_result = magnitudeSquared >= m_thresholdSquared;
|
||||||
q63_t t3 = m_q1 * m_q1;
|
m_q0 = 0;
|
||||||
q31_t t4 = __SSAT(t3 >> 32, 31);
|
m_q1 = 0;
|
||||||
|
}
|
||||||
// Q31 multiplication, t8 = m_q0 * m_q1 * m_coeff
|
}
|
||||||
q63_t t5 = m_q0 * m_q1;
|
|
||||||
q31_t t6 = __SSAT(t5 >> 32, 31);
|
|
||||||
q63_t t7 = t6 * m_coeff;
|
|
||||||
q31_t t8 = __SSAT(t7 >> 32, 31);
|
|
||||||
|
|
||||||
// value = m_q0 * m_q0 + m_q1 * m_q1 - m_q0 * m_q1 * m_coeff
|
|
||||||
q31_t value = t2 + t4 - t8;
|
|
||||||
|
|
||||||
m_result = value >= m_threshold;
|
|
||||||
m_count = 0U;
|
|
||||||
m_q0 = 0;
|
|
||||||
m_q1 = 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,11 +32,11 @@ public:
|
||||||
void reset();
|
void reset();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
q31_t m_coeff;
|
long m_coeff;
|
||||||
uint16_t m_threshold;
|
long m_thresholdSquared;
|
||||||
uint16_t m_count;
|
uint16_t m_count;
|
||||||
q31_t m_q0;
|
long m_q0;
|
||||||
q31_t m_q1;
|
long m_q1;
|
||||||
bool m_result;
|
bool m_result;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue