From a5aabd8fac4cafdb68f507c18c85bd04fae6f84d Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Tue, 12 May 2020 08:35:48 +0200 Subject: [PATCH 1/7] Update TX ON/OFF debug info --- IO.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/IO.cpp b/IO.cpp index c668f1f..beea107 100644 --- a/IO.cpp +++ b/IO.cpp @@ -264,7 +264,7 @@ void CIO::process() if (m_txBuffer.getData() == 0U && m_tx) { m_tx = false; setPTTInt(m_pttInvert ? true : false); - DEBUG1("Process TX OFF"); + DEBUG1("TX OFF"); } if (m_rxBuffer.getData() >= RX_BLOCK_SIZE) { @@ -454,7 +454,7 @@ void CIO::write(MMDVM_STATE mode, q15_t* samples, uint16_t length, const uint8_t if (!m_tx) { m_tx = true; setPTTInt(m_pttInvert ? false : true); - DEBUG1("Write TX ON"); + DEBUG1("TX ON"); } q15_t txLevel = 0; From ca1cc7096a4fdb834cec1cd532b844d092e8870a Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Tue, 12 May 2020 08:36:38 +0200 Subject: [PATCH 2/7] Fix modem not goign on transmit, still some cleansing to be done --- FM.cpp | 22 ++++++++-------------- FM.h | 1 - 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/FM.cpp b/FM.cpp index 7eb7261..8a7d144 100644 --- a/FM.cpp +++ b/FM.cpp @@ -20,7 +20,7 @@ #include "Globals.h" #include "FM.h" -const uint16_t FM_TX_BLOCK_SIZE = 250U; +const uint16_t FM_TX_BLOCK_SIZE = 127U; const uint16_t FM_SERIAL_BLOCK_SIZE = 127U; CFM::CFM() : @@ -89,18 +89,18 @@ void CFM::samples(bool cos, q15_t* samples, uint8_t length) bool inputExt = m_inputExtRB.get(currentExtSample);//always consume the external input data so it does not overflow inputExt = inputExt && m_extEnabled; - if (!inputExt && (CTCSS_NOT_READY(ctcssState))) { + if (!inputExt && (CTCSS_NOT_READY(ctcssState)) && m_modemState != STATE_FM) { //Not enough samples to determine if you have CTCSS, just carry on. But only if we haven't any external data in the queue continue; - } else if ((inputExt || CTCSS_READY(ctcssState))) { + } else if ((inputExt || CTCSS_READY(ctcssState)) && m_modemState != STATE_FM) { //we had enough samples for CTCSS and we are in some other mode than FM bool validCTCSS = CTCSS_VALID(ctcssState); stateMachine(validCTCSS && cos, inputExt); - } else if ((inputExt || CTCSS_READY(ctcssState))) { + } else if ((inputExt || CTCSS_READY(ctcssState)) && m_modemState == STATE_FM) { //We had enough samples for CTCSS and we are in FM mode, trigger the state machine bool validCTCSS = CTCSS_VALID(ctcssState); stateMachine(validCTCSS && cos, inputExt); - } else if ((inputExt || CTCSS_NOT_READY(ctcssState)) && i == length - 1) { + } else if ((inputExt || 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! bool validCTCSS = CTCSS_VALID(ctcssState); @@ -147,13 +147,7 @@ void CFM::samples(bool cos, q15_t* samples, uint8_t length) currentSample += m_ctcssTX.getAudio(); m_outputRFRB.put(currentSample); - //samples[i] = currentSample; } - - // XXX This relays audio correctly, no tones yet, process need to be commented - // if (m_state == FS_RELAYING_RF || m_state == FS_KERCHUNK_RF || m_state == FS_RELAYING_EXT || m_state == FS_KERCHUNK_EXT) - // io.write(STATE_FM, samples, i); - } void CFM::process() @@ -744,8 +738,8 @@ void CFM::insertDelay(uint16_t ms) void CFM::insertSilence(uint16_t ms) { - uint32_t nSamples = ms * 24U; + // uint32_t nSamples = ms * 24U; - for (uint32_t i = 0U; i < nSamples; i++) - m_outputRFRB.put(0); + // for (uint32_t i = 0U; i < nSamples; i++) + // m_outputRFRB.put(0); } diff --git a/FM.h b/FM.h index a4c82f9..3255c05 100644 --- a/FM.h +++ b/FM.h @@ -117,7 +117,6 @@ private: void clock(uint8_t length); void sendCallsign(); - void sendBeeps(); void beginRelaying(); void insertDelay(uint16_t ms); From 1b40044a2306f9ba8d06c4cc3d157f13b0992082 Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Tue, 12 May 2020 09:28:24 +0200 Subject: [PATCH 3/7] Re-enable write audio to serial --- FM.cpp | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/FM.cpp b/FM.cpp index 8a7d144..a335a60 100644 --- a/FM.cpp +++ b/FM.cpp @@ -173,26 +173,24 @@ void CFM::process() 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 (m_extEnabled) { + length = m_downsampler.getData(); + //Write audio to serial + if (length >= FM_SERIAL_BLOCK_SIZE) { + + if(length > FM_SERIAL_BLOCK_SIZE) + length = FM_SERIAL_BLOCK_SIZE; - // if(length > FM_SERIAL_BLOCK_SIZE)//max message size on serial is 127 - // 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; + } - // 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); - // } + serial.writeFMData(serialSamples, length); + } + } } void CFM::reset() From 0fad84b46dbdeef95cca87e49adb1bbc1ef61f9a Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Tue, 12 May 2020 09:29:01 +0200 Subject: [PATCH 4/7] Remove silence --- FM.cpp | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/FM.cpp b/FM.cpp index a335a60..1adb307 100644 --- a/FM.cpp +++ b/FM.cpp @@ -359,8 +359,6 @@ void CFM::listeningState(bool validRFSignal, bool validExtSignal) sendCallsign(); } - insertSilence(50U); - beginRelaying(); m_callsignTimer.start(); @@ -381,8 +379,6 @@ void CFM::listeningState(bool validRFSignal, bool validExtSignal) sendCallsign(); } - insertSilence(50U); - beginRelaying(); m_callsignTimer.start(); @@ -733,11 +729,3 @@ void CFM::insertDelay(uint16_t ms) for (uint32_t i = 0U; i < nSamples; i++) m_inputRFRB.put(0); } - -void CFM::insertSilence(uint16_t ms) -{ - // uint32_t nSamples = ms * 24U; - - // for (uint32_t i = 0U; i < nSamples; i++) - // m_outputRFRB.put(0); -} From a0a3080da2e7a023a7a53f282d579c0bcb034fe8 Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Tue, 12 May 2020 14:15:04 +0200 Subject: [PATCH 5/7] Make sure downsampler always buffers 22 samples at a time --- FM.cpp | 102 +++++++++++++++++++++++++++++----------------- FM.h | 1 - FMDownsampler.cpp | 8 ++-- FMDownsampler.h | 10 ++++- 4 files changed, 77 insertions(+), 44 deletions(-) diff --git a/FM.cpp b/FM.cpp index 1adb307..69b25c0 100644 --- a/FM.cpp +++ b/FM.cpp @@ -20,8 +20,8 @@ #include "Globals.h" #include "FM.h" -const uint16_t FM_TX_BLOCK_SIZE = 127U; -const uint16_t FM_SERIAL_BLOCK_SIZE = 127U; +const uint16_t FM_TX_BLOCK_SIZE = 400U; +const uint16_t FM_SERIAL_BLOCK_SIZE = 126U; CFM::CFM() : m_callsign(), @@ -50,7 +50,7 @@ m_useCOS(true), m_cosInvert(false), m_rfAudioBoost(1U), m_extAudioBoost(1U), -m_downsampler(1200U),// 100 ms of audio +m_downsampler(400U),// 100 ms of audio m_extEnabled(false), m_rxLevel(1), m_inputRFRB(4800U), // 200ms of audio @@ -117,10 +117,6 @@ void CFM::samples(bool cos, q15_t* samples, uint8_t length) // Only let RF audio through when relaying RF audio if (m_state == FS_RELAYING_RF || m_state == FS_KERCHUNK_RF || m_state == FS_RELAYING_EXT || m_state == FS_KERCHUNK_EXT) { currentSample = m_blanking.process(currentSample); - - if (m_extEnabled && (m_state == FS_RELAYING_RF || m_state == FS_KERCHUNK_RF)) - m_downsampler.addSample(currentSample); - currentSample *= currentBoost; } else { currentSample = 0; @@ -153,44 +149,75 @@ 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; + uint16_t txLength = m_outputRFRB.getData(); + if (space > 2 && txLength >= FM_TX_BLOCK_SIZE ) { + + if(txLength > FM_TX_BLOCK_SIZE) + txLength = FM_TX_BLOCK_SIZE; if(space > FM_TX_BLOCK_SIZE) space = FM_TX_BLOCK_SIZE; - if(length > space) - length = space; + if(txLength > space) + txLength = space; q15_t samples[FM_TX_BLOCK_SIZE]; - for(uint16_t i = 0U; i < length; i++) { + + for (uint16_t i = 0U; i < txLength; i++) { q15_t sample = 0; m_outputRFRB.get(sample); samples[i] = sample; - } - io.write(STATE_FM, samples, length); - } - - if (m_extEnabled) { - length = m_downsampler.getData(); - //Write audio to serial - if (length >= FM_SERIAL_BLOCK_SIZE) { - - 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; + if(m_extEnabled && (m_state == FS_RELAYING_RF || m_state == FS_KERCHUNK_RF)) { + m_downsampler.addSample(sample); + uint16_t downSamplerLength = m_downsampler.getData(); + if(downSamplerLength >= FM_SERIAL_BLOCK_SIZE) { + TSamplePairPack serialSamples[FM_SERIAL_BLOCK_SIZE]; + for(uint16_t j = 0U; j < downSamplerLength; j++) { + m_downsampler.getPackedData(serialSamples[j]); + } + serial.writeFMData((uint8_t*)serialSamples, txLength * sizeof(TSamplePairPack)); + } } - - serial.writeFMData(serialSamples, length); } + + io.write(STATE_FM, samples, txLength); } + // 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); + // } + + // if (m_extEnabled) { + // length = m_downsampler.getData(); + // //Write audio to serial + // if (length >= FM_SERIAL_BLOCK_SIZE) { + + // if(length > FM_SERIAL_BLOCK_SIZE) + // length = FM_SERIAL_BLOCK_SIZE; + + // TSamplePairPack serialSamples[FM_SERIAL_BLOCK_SIZE]; + // for(uint16_t i = 0U; i < length; i++) { + // TSamplePairPack samplePair = {0U, 0U, 0U}; + // m_downsampler.getPackedData(samplePair); + // serialSamples[i] = samplePair; + // } + + // serial.writeFMData((uint8_t*)&serialSamples, length * sizeof(TSamplePairPack)); + // } + // } } void CFM::reset() @@ -338,7 +365,7 @@ void CFM::clock(uint8_t length) m_statusTimer.clock(length); if (m_statusTimer.isRunning() && m_statusTimer.hasExpired()) { - serial.writeFMStatus(); + serial.writeFMStatus(false); m_statusTimer.start(); } } @@ -364,7 +391,7 @@ void CFM::listeningState(bool validRFSignal, bool validExtSignal) m_callsignTimer.start(); m_statusTimer.start(); - serial.writeFMStatus(); + serial.writeFMStatus(true); } else if (validExtSignal) { if (m_kerchunkTimer.getTimeout() > 0U) { DEBUG1("State to KERCHUNK_EXT"); @@ -384,7 +411,7 @@ void CFM::listeningState(bool validRFSignal, bool validExtSignal) m_callsignTimer.start(); m_statusTimer.start(); - serial.writeFMStatus(); + serial.writeFMStatus(false); } } @@ -729,3 +756,4 @@ void CFM::insertDelay(uint16_t ms) for (uint32_t i = 0U; i < nSamples; i++) m_inputRFRB.put(0); } + diff --git a/FM.h b/FM.h index 3255c05..285c20b 100644 --- a/FM.h +++ b/FM.h @@ -120,7 +120,6 @@ private: void beginRelaying(); void insertDelay(uint16_t ms); - void insertSilence(uint16_t ms); }; #endif diff --git a/FMDownsampler.cpp b/FMDownsampler.cpp index 3209778..4c6b733 100644 --- a/FMDownsampler.cpp +++ b/FMDownsampler.cpp @@ -43,9 +43,9 @@ void CFMDownsampler::addSample(q15_t sample) m_samplePack |= uint32_t(sample); //we did not use MSB; skip it - m_ringBuffer.put(m_samplePackPointer[1U]); - m_ringBuffer.put(m_samplePackPointer[2U]); - m_ringBuffer.put(m_samplePackPointer[3U]); + TSamplePairPack pair{m_samplePackPointer[1U], m_samplePackPointer[2U], m_samplePackPointer[3U]}; + + m_ringBuffer.put(pair); m_samplePack = 0;//reset the sample pack } @@ -64,7 +64,7 @@ void CFMDownsampler::addSample(q15_t sample) m_downSampleIndex = 0U; } -bool CFMDownsampler::getPackedData(uint8_t& data) +bool CFMDownsampler::getPackedData(TSamplePairPack& data) { return m_ringBuffer.get(data); } diff --git a/FMDownsampler.h b/FMDownsampler.h index 179493f..677a315 100644 --- a/FMDownsampler.h +++ b/FMDownsampler.h @@ -23,16 +23,22 @@ #include "Config.h" #include "RingBuffer.h" +struct TSamplePairPack { + uint8_t byte0; + uint8_t byte1; + uint8_t byte2; +}; + class CFMDownsampler { public: CFMDownsampler(uint16_t length); void addSample(q15_t sample); - bool getPackedData(uint8_t& data); + bool getPackedData(TSamplePairPack& data); uint16_t getData(); void reset(); private: - CRingBuffer m_ringBuffer; + CRingBuffer m_ringBuffer; uint32_t m_samplePack; uint32_t *m_samplePackPointer; From d23c0900c18e7f4f4f777823d37865069aabeacd Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Tue, 12 May 2020 14:18:27 +0200 Subject: [PATCH 6/7] Fix compilation --- FM.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/FM.cpp b/FM.cpp index 69b25c0..a73bd2f 100644 --- a/FM.cpp +++ b/FM.cpp @@ -365,7 +365,7 @@ void CFM::clock(uint8_t length) m_statusTimer.clock(length); if (m_statusTimer.isRunning() && m_statusTimer.hasExpired()) { - serial.writeFMStatus(false); + serial.writeFMStatus(); m_statusTimer.start(); } } @@ -391,7 +391,7 @@ void CFM::listeningState(bool validRFSignal, bool validExtSignal) m_callsignTimer.start(); m_statusTimer.start(); - serial.writeFMStatus(true); + serial.writeFMStatus(); } else if (validExtSignal) { if (m_kerchunkTimer.getTimeout() > 0U) { DEBUG1("State to KERCHUNK_EXT"); @@ -411,7 +411,7 @@ void CFM::listeningState(bool validRFSignal, bool validExtSignal) m_callsignTimer.start(); m_statusTimer.start(); - serial.writeFMStatus(false); + serial.writeFMStatus(); } } From b64712f65720a99081381c5ee4468f3852550903 Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Tue, 12 May 2020 14:45:03 +0200 Subject: [PATCH 7/7] Restore silence --- FM.cpp | 49 ++++++++++++------------------------------------- FM.h | 1 + 2 files changed, 13 insertions(+), 37 deletions(-) diff --git a/FM.cpp b/FM.cpp index a73bd2f..06f6cfd 100644 --- a/FM.cpp +++ b/FM.cpp @@ -181,43 +181,6 @@ void CFM::process() io.write(STATE_FM, samples, txLength); } - // 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); - // } - - // if (m_extEnabled) { - // length = m_downsampler.getData(); - // //Write audio to serial - // if (length >= FM_SERIAL_BLOCK_SIZE) { - - // if(length > FM_SERIAL_BLOCK_SIZE) - // length = FM_SERIAL_BLOCK_SIZE; - - // TSamplePairPack serialSamples[FM_SERIAL_BLOCK_SIZE]; - // for(uint16_t i = 0U; i < length; i++) { - // TSamplePairPack samplePair = {0U, 0U, 0U}; - // m_downsampler.getPackedData(samplePair); - // serialSamples[i] = samplePair; - // } - - // serial.writeFMData((uint8_t*)&serialSamples, length * sizeof(TSamplePairPack)); - // } - // } } void CFM::reset() @@ -386,6 +349,8 @@ void CFM::listeningState(bool validRFSignal, bool validExtSignal) sendCallsign(); } + insertDelay(50U); + beginRelaying(); m_callsignTimer.start(); @@ -406,6 +371,8 @@ void CFM::listeningState(bool validRFSignal, bool validExtSignal) sendCallsign(); } + insertDelay(50U); + beginRelaying(); m_callsignTimer.start(); @@ -757,3 +724,11 @@ void CFM::insertDelay(uint16_t ms) m_inputRFRB.put(0); } +void CFM::insertSilence(uint16_t ms) +{ + uint32_t nSamples = ms * 24U; + + for (uint32_t i = 0U; i < nSamples; i++) + m_outputRFRB.put(0); +} + diff --git a/FM.h b/FM.h index 285c20b..3255c05 100644 --- a/FM.h +++ b/FM.h @@ -120,6 +120,7 @@ private: void beginRelaying(); void insertDelay(uint16_t ms); + void insertSilence(uint16_t ms); }; #endif