One loop to rule them all !

Change CFM::Samples and CFMCTCSSRX::process to be able to process all
stuff in one and only loop.
This commit is contained in:
Geoffrey Merck 2020-04-22 11:04:27 +02:00
parent 03f5056236
commit 63847ebe62
3 changed files with 91 additions and 31 deletions

39
FM.cpp
View file

@ -60,17 +60,39 @@ m_hangTimer()
void CFM::samples(q15_t* samples, uint8_t length)
{
bool validCTCSS = m_ctcssRX.process(samples, length);
stateMachine(validCTCSS, length);
if (m_modemState != STATE_FM)
return;
CTCSSState ctcssState;
bool validCTCSS = false;
q15_t currentSample;
for (uint8_t i = 0U; i < length; i++) {
uint8_t i = 0;
for (; i < length; i++) {
currentSample = samples[i];//save to a local variable to avoid indirection on every access
ctcssState = m_ctcssRX.process(currentSample);
if(CTCSS_NOT_READY(ctcssState) && m_modemState != STATE_FM) {
//Not enough samples to determine if you have CTCSS, just carry on
continue;
} else if(CTCSS_READY(ctcssState) && m_modemState != STATE_FM) {
//we had enough samples for CTCSS and we are in some other mode than FM
validCTCSS = CTCSS_VALID(ctcssState);
stateMachine(validCTCSS, i + 1U);
if (m_modemState != STATE_FM)
continue;
} else if(CTCSS_READY(ctcssState) && m_modemState == STATE_FM) {
//We had enough samples for CTCSS and we are in FM mode, trigger the state machine
validCTCSS = CTCSS_VALID(ctcssState);
stateMachine(validCTCSS, i + 1U);
if (m_modemState != STATE_FM)
break;
} else if(CTCSS_NOT_READY(ctcssState) && m_modemState == STATE_FM && i == length - 1) {
//Not enough samples for CTCSS but we already are in FM, trigger the state machine
//but do not trigger the state machine on every single sample, save CPU!
validCTCSS = CTCSS_VALID(ctcssState);
stateMachine(validCTCSS, i + 1U);
}
// Only let audio through when relaying audio
if (m_state != FS_RELAYING && m_state != FS_KERCHUNK)
currentSample = 0U;
@ -92,7 +114,8 @@ void CFM::samples(q15_t* samples, uint8_t length)
samples[i] = currentSample;
}
io.write(STATE_FM, samples, length);
if(m_modemState == STATE_FM)
io.write(STATE_FM, samples, i);//only write the actual number of processed samples to IO
}
void CFM::process()