Merge pull request #233 from F4FXL/FM

Remove IO from CTCSSRX
This commit is contained in:
Jonathan Naylor 2020-04-26 11:45:44 +01:00 committed by GitHub
commit 3fb0631953
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 14 deletions

16
FM.cpp
View File

@ -54,7 +54,7 @@ void CFM::samples(bool cos, q15_t* samples, uint8_t length)
for (; i < length; i++) { for (; i < length; i++) {
q15_t currentSample = samples[i];//save to a local variable to avoid indirection on every access q15_t currentSample = samples[i];//save to a local variable to avoid indirection on every access
CTCSSState ctcssState = m_ctcssRX.process(currentSample); CTCSSState ctcssState = m_ctcssRX.process(getUnscaledSample(currentSample));
if (CTCSS_NOT_READY(ctcssState) && m_modemState != STATE_FM) { if (CTCSS_NOT_READY(ctcssState) && m_modemState != STATE_FM) {
//Not enough samples to determine if you have CTCSS, just carry on //Not enough samples to determine if you have CTCSS, just carry on
@ -397,3 +397,17 @@ void CFM::beginRelaying()
m_timeoutTimer.start(); m_timeoutTimer.start();
m_ackMinTimer.start(); m_ackMinTimer.start();
} }
q15_t CFM::getUnscaledSample(q15_t sample)
{
// 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;
return q15_t(sample31);
}

2
FM.h
View File

@ -90,6 +90,8 @@ private:
void sendCallsign(); void sendCallsign();
void beginRelaying(); void beginRelaying();
q15_t getUnscaledSample(q15_t sample);
}; };
#endif #endif

View File

@ -111,17 +111,7 @@ uint8_t CFMCTCSSRX::setParams(uint8_t frequency, uint8_t threshold)
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;
@ -132,7 +122,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 + sample31; m_q0 = t3 - q2 + q31_t(sample);
m_count++; m_count++;
if (m_count == N) { if (m_count == N) {

View File

@ -55,7 +55,7 @@ public:
uint8_t setParams(uint8_t frequency, uint8_t threshold); uint8_t setParams(uint8_t frequency, uint8_t threshold);
CTCSSState process(q15_t samples); CTCSSState process(q15_t sample);
CTCSSState getState(); CTCSSState getState();