From b245be464f93e2d930ea544405d60796cf3fec6c Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Wed, 13 May 2020 22:57:42 +0200 Subject: [PATCH 1/2] Fix txbuffer overflows and bring back elegant while loop --- FM.cpp | 27 +++++---------------------- 1 file changed, 5 insertions(+), 22 deletions(-) diff --git a/FM.cpp b/FM.cpp index 6315f36..19e980f 100644 --- a/FM.cpp +++ b/FM.cpp @@ -20,7 +20,7 @@ #include "Globals.h" #include "FM.h" -const uint16_t FM_TX_BLOCK_SIZE = 400U; +const uint16_t FM_TX_BLOCK_SIZE = 100U; const uint16_t FM_SERIAL_BLOCK_SIZE = 42U;//this is actually the number of sample pairs to send over serial. One sample pair is 3bytes. //three times this value shall never exceed 126 ! @@ -152,30 +152,13 @@ void CFM::samples(bool cos, q15_t* samples, uint8_t length) void CFM::process() { - uint16_t space = io.getSpace() - 2U; - uint16_t length = m_outputRFRB.getData(); - if (space > 2 && length >= FM_TX_BLOCK_SIZE ) { - - if(length > FM_TX_BLOCK_SIZE) - length = FM_TX_BLOCK_SIZE; - if(space > FM_TX_BLOCK_SIZE) - space = FM_TX_BLOCK_SIZE; - if(length > space) - length = space; - - q15_t samples[FM_TX_BLOCK_SIZE]; - - for (uint16_t i = 0U; i < length; i++) { - q15_t sample = 0; - m_outputRFRB.get(sample); - samples[i] = sample; - } - - io.write(STATE_FM, samples, length); + q15_t sample; + while (io.getSpace() >= 3U && m_outputRFRB.get(sample)) { + io.write(STATE_FM, &sample, 1); } if(m_extEnabled) { - length = m_downsampler.getData(); + uint16_t length = m_downsampler.getData(); if(length >= FM_SERIAL_BLOCK_SIZE) { if(length > FM_SERIAL_BLOCK_SIZE) From cfcb7ed8524b65f83048f49f56432efaec3bddd4 Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Thu, 14 May 2020 09:10:11 +0200 Subject: [PATCH 2/2] Really fix TX Buffer ovrflows,, reduce delay buffer memory footprint --- FM.cpp | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/FM.cpp b/FM.cpp index 19e980f..f4174fc 100644 --- a/FM.cpp +++ b/FM.cpp @@ -54,7 +54,7 @@ m_extAudioBoost(1U), m_downsampler(400U),// 100 ms of audio m_extEnabled(false), m_rxLevel(1), -m_inputRFRB(4800U), // 200ms of audio +m_inputRFRB(2401U), // 100ms of audio + 1 sample m_outputRFRB(2400U), // 100ms of audio m_inputExtRB(2400U) // 100ms of Audio { @@ -152,9 +152,26 @@ void CFM::samples(bool cos, q15_t* samples, uint8_t length) void CFM::process() { - q15_t sample; - while (io.getSpace() >= 3U && m_outputRFRB.get(sample)) { - io.write(STATE_FM, &sample, 1); + uint16_t space = io.getSpace(); + uint16_t length = m_outputRFRB.getData(); + if (space > FM_TX_BLOCK_SIZE && length >= FM_TX_BLOCK_SIZE ) { + + if(length > FM_TX_BLOCK_SIZE) + length = FM_TX_BLOCK_SIZE; + if(space > FM_TX_BLOCK_SIZE) + space = FM_TX_BLOCK_SIZE; + if(length > space) + length = space; + + q15_t samples[FM_TX_BLOCK_SIZE]; + + for (uint16_t i = 0U; i < length; i++) { + q15_t sample = 0; + m_outputRFRB.get(sample); + samples[i] = sample; + } + + io.write(STATE_FM, samples, length); } if(m_extEnabled) {