Write larger chunks of data to IO

This commit is contained in:
Geoffrey Merck 2020-05-11 16:04:58 +02:00
parent eac2aa4ac1
commit 5d4df6ffd9
1 changed files with 21 additions and 6 deletions

27
FM.cpp
View File

@ -154,21 +154,36 @@ void CFM::samples(bool cos, const q15_t* samples, uint8_t length)
void CFM::process() void CFM::process()
{ {
q15_t sample; if (io.getSpace() > 2 && (m_outputRFRB.getData() >= 250 || m_state != STATE_FM)) {//if we just left FM mode, so write all what is left in buffer, regardless of the amoutn of data
while (io.getSpace() >= 3U && m_outputRFRB.get(sample)) uint16_t length = m_outputRFRB.getData();
io.write(STATE_FM, &sample, 1U); uint16_t space = io.getSpace() - 2;
if(m_downsampler.getData() >= 127) { if(length > space)
uint8_t length = uint8_t(m_downsampler.getData()); length = space;
q15_t samples[length];
for(uint16_t i = 0; i < length; i++) {
q15_t sample = 0;
m_outputRFRB.get(sample);
samples[i] = sample;
}
io.write(STATE_FM, samples, length);
}
//Write audio to serial
if (m_downsampler.getData() >= 127 || m_state != STATE_FM) {//if we just left FM mode, so write all what is left in buffer, regardless of the amoutn of data
uint16_t length = m_downsampler.getData();
if(length > 127U)//max message size on serial is 127 if(length > 127U)//max message size on serial is 127
length = 127U; length = 127U;
uint8_t serialSamples[length]; uint8_t serialSamples[length];
for(uint8_t i = 0U; i < length; i++) { for(uint16_t i = 0U; i < length; i++) {
uint8_t serialSample = 0U; uint8_t serialSample = 0U;
m_downsampler.getPackedData(serialSample); m_downsampler.getPackedData(serialSample);
serialSamples[i] = serialSample;
} }
serial.writeFMData(serialSamples, length); serial.writeFMData(serialSamples, length);
} }