diff --git a/FM.cpp b/FM.cpp index 6fb513a..9c25d83 100644 --- a/FM.cpp +++ b/FM.cpp @@ -20,10 +20,8 @@ #include "Globals.h" #include "FM.h" -const uint8_t BIT_MASK_TABLE[] = {0x80U, 0x40U, 0x20U, 0x10U, 0x08U, 0x04U, 0x02U, 0x01U}; - -#define WRITE_BIT_AUDIO(p,i,b) p[(i)>>3] = (b) ? (p[(i)>>3] | BIT_MASK_TABLE[(i)&7]) : (p[(i)>>3] & ~BIT_MASK_TABLE[(i)&7]) -#define READ_BIT_AUDIO(p,i) (p[(i)>>3] & BIT_MASK_TABLE[(i)&7]) +const uint16_t FM_TX_BLOCK_SIZE = 250U; +const uint16_t FM_SERIAL_BLOCK_SIZE = 127U; CFM::CFM() : m_callsign(), @@ -154,39 +152,51 @@ void CFM::samples(bool cos, const q15_t* samples, uint8_t length) void CFM::process() { - 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 - uint16_t length = m_outputRFRB.getData(); - uint16_t space = io.getSpace() - 2; + q15_t sample; + while (io.getSpace() >= 3U && m_outputRFRB.get(sample)) + io.write(STATE_FM, &sample, 1U); - if(length > space) - length = space; + // if (io.getSpace() > 2 && (m_outputRFRB.getData() >= FM_TX_BLOCK_SIZE || 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_outputRFRB.getData(); + // uint16_t space = io.getSpace() - 2; - q15_t samples[length]; - for(uint16_t i = 0; i < length; i++) { - q15_t sample = 0; - m_outputRFRB.get(sample); - samples[i] = sample; - } + // 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; - io.write(STATE_FM, samples, length); - } + // q15_t samples[FM_TX_BLOCK_SIZE]; + // for(uint16_t i = 0; i < length; i++) { + // q15_t sample = 0; + // m_outputRFRB.get(sample); + // samples[i] = sample; + // } - //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(); + // io.write(STATE_FM, samples, length); + // } - if(length > 127U)//max message size on serial is 127 - length = 127U; + // //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(); - uint8_t serialSamples[length]; + // if(length > FM_SERIAL_BLOCK_SIZE)//max message size on serial is 127 + // length = FM_SERIAL_BLOCK_SIZE; - for(uint16_t i = 0U; i < length; i++) { - uint8_t serialSample = 0U; - m_downsampler.getPackedData(serialSample); - serialSamples[i] = serialSample; - } - serial.writeFMData(serialSamples, length); - } + // if(length > FM_SERIAL_BLOCK_SIZE) + // length = FM_SERIAL_BLOCK_SIZE; + + // uint8_t serialSamples[FM_SERIAL_BLOCK_SIZE]; + + // for(uint16_t i = 0U; i < length; i++) { + // uint8_t serialSample = 0U; + // m_downsampler.getPackedData(serialSample); + // serialSamples[i] = serialSample; + // } + + // serial.writeFMData(serialSamples, length); + // } } void CFM::reset()