From fa29a27695d1b99208ae7b7add37814bc3951b51 Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Sat, 9 May 2020 12:53:50 +0100 Subject: [PATCH 1/3] Ensure all output audio is flushed before leaving FM state. --- FM.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FM.cpp b/FM.cpp index 7695e81..94bd693 100644 --- a/FM.cpp +++ b/FM.cpp @@ -245,7 +245,7 @@ void CFM::stateMachine(bool validSignal) } if (m_state == FS_LISTENING && m_modemState == STATE_FM) { - if (!m_callsign.isRunning() && !m_rfAck.isRunning()) { + if (!m_callsign.isRunning() && !m_rfAck.isRunning() && m_outputRB.getData() == 0U) { DEBUG1("Change to STATE_IDLE"); m_modemState = STATE_IDLE; m_callsignTimer.stop(); From 3bb7cde3223f448e74201b400a552043f14dfff5 Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Sat, 9 May 2020 13:01:02 +0100 Subject: [PATCH 2/3] Add input audio delay to match the CTCSS decoder results. --- FM.cpp | 14 ++++++++++++++ FM.h | 3 +++ 2 files changed, 17 insertions(+) diff --git a/FM.cpp b/FM.cpp index 94bd693..66bd5af 100644 --- a/FM.cpp +++ b/FM.cpp @@ -46,8 +46,10 @@ m_cosInvert(false), m_rfAudioBoost(1U), m_downsampler(128U),//Size might need adjustement m_rxLevel(1), +m_inputRB(4800U), // 200ms of audio m_outputRB(2400U) // 100ms of audio { + insertDelay(100U); } void CFM::samples(bool cos, const q15_t* samples, uint8_t length) @@ -68,6 +70,10 @@ void CFM::samples(bool cos, const q15_t* samples, uint8_t length) uint8_t ctcssState = m_ctcssRX.process(currentSample); + // Delay the audio by 100ms to better match the CTCSS detector output + m_inputRB.put(currentSample); + m_inputRB.get(currentSample); + if (CTCSS_NOT_READY(ctcssState) && m_modemState != STATE_FM) { //Not enough samples to determine if you have CTCSS, just carry on continue; @@ -462,6 +468,14 @@ void CFM::beginRelaying() m_ackMinTimer.start(); } +void CFM::insertDelay(uint16_t ms) +{ + uint32_t nSamples = ms * 24U; + + for (uint32_t i = 0U; i < nSamples; i++) + m_inputRB.put(0); +} + void CFM::insertSilence(uint16_t ms) { uint32_t nSamples = ms * 24U; diff --git a/FM.h b/FM.h index 4901d6a..29887a8 100644 --- a/FM.h +++ b/FM.h @@ -84,6 +84,7 @@ private: q15_t m_rfAudioBoost; CFMDownsampler m_downsampler; q15_t m_rxLevel; + CFMRB m_inputRB; CFMRB m_outputRB; void stateMachine(bool validSignal); @@ -99,6 +100,8 @@ private: void sendCallsign(); void beginRelaying(); + + void insertDelay(uint16_t ms); void insertSilence(uint16_t ms); }; From c04e207821ddd67882a7b887357ef1290fd2918b Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Sat, 9 May 2020 13:10:02 +0100 Subject: [PATCH 3/3] Insert the missing silence. --- FM.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/FM.cpp b/FM.cpp index 55fd0f0..8bf2448 100644 --- a/FM.cpp +++ b/FM.cpp @@ -342,6 +342,8 @@ void CFM::listeningState(bool validRFSignal, bool validExtSignal) sendCallsign(); } + insertSilence(50U); + beginRelaying(); m_callsignTimer.start();