Improve the code efficiency slightly.

This commit is contained in:
Jonathan Naylor 2020-07-14 14:54:47 +01:00
parent dc41fd83d2
commit 1ac0628c1c
1 changed files with 31 additions and 26 deletions

15
FM.cpp
View File

@ -75,14 +75,14 @@ void CFM::samples(bool cos, const q15_t* samples, uint8_t length)
// ARMv7-M has hardware integer division // ARMv7-M has hardware integer division
q15_t currentSample = q15_t((q31_t(samples[i]) << 8) / m_rxLevel); q15_t currentSample = q15_t((q31_t(samples[i]) << 8) / m_rxLevel);
uint8_t ctcssState = m_ctcssRX.process(currentSample);
switch (m_accessMode) { switch (m_accessMode) {
case 0U: case 0U:
stateMachine(cos); stateMachine(cos);
break; break;
case 1U: case 1U: {
uint8_t ctcssState = m_ctcssRX.process(currentSample);
// Delay the audio by 100ms to better match the CTCSS detector output // Delay the audio by 100ms to better match the CTCSS detector output
m_inputRB.put(currentSample); m_inputRB.put(currentSample);
m_inputRB.get(currentSample); m_inputRB.get(currentSample);
@ -93,18 +93,22 @@ void CFM::samples(bool cos, const q15_t* samples, uint8_t length)
bool validCTCSS = CTCSS_VALID(ctcssState); bool validCTCSS = CTCSS_VALID(ctcssState);
stateMachine(validCTCSS); stateMachine(validCTCSS);
} }
}
break; break;
case 2U: case 2U: {
uint8_t ctcssState = m_ctcssRX.process(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
} else { } else {
bool validCTCSS = CTCSS_VALID(ctcssState); bool validCTCSS = CTCSS_VALID(ctcssState);
stateMachine(validCTCSS && cos); stateMachine(validCTCSS && cos);
} }
}
break; break;
default: default: {
uint8_t ctcssState = m_ctcssRX.process(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
} else if (CTCSS_READY(ctcssState) && m_modemState != STATE_FM) { } else if (CTCSS_READY(ctcssState) && m_modemState != STATE_FM) {
@ -114,6 +118,7 @@ void CFM::samples(bool cos, const q15_t* samples, uint8_t length)
} else { } else {
stateMachine(cos); stateMachine(cos);
} }
}
break; break;
} }