From 6dd0a718e0b812f59fb0a5e914b2a0b0783a4e69 Mon Sep 17 00:00:00 2001 From: Silvano Seva Date: Wed, 30 Aug 2023 18:02:46 +0200 Subject: [PATCH] Fixed bug in M17 opmode handler causing missing audio output --- openrtx/src/rtx/OpMode_M17.cpp | 57 +++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 25 deletions(-) diff --git a/openrtx/src/rtx/OpMode_M17.cpp b/openrtx/src/rtx/OpMode_M17.cpp index 42ebc210..230ac17e 100644 --- a/openrtx/src/rtx/OpMode_M17.cpp +++ b/openrtx/src/rtx/OpMode_M17.cpp @@ -174,38 +174,45 @@ void OpMode_M17::rxState(rtxStatus_t *const status) bool newData = demodulator.update(); bool lock = demodulator.isLocked(); - // Reset frame decoder when transitioning from unlocked to locked state and - // setup audio path towards the speaker. + // Reset frame decoder when transitioning from unlocked to locked state. if((lock == true) && (locked == false)) { decoder.reset(); - rxAudioPath = audioPath_request(SOURCE_MCU, SINK_SPK, PRIO_RX); - codec_startDecode(rxAudioPath); + locked = lock; + } + + if(locked) + { + // Check RX audio path status, open it if necessary + uint8_t pthSts = audioPath_getStatus(rxAudioPath); + if(pthSts == PATH_CLOSED) + { + rxAudioPath = audioPath_request(SOURCE_MCU, SINK_SPK, PRIO_RX); + pthSts = audioPath_getStatus(rxAudioPath); + } + + // Start codec2 module if not already up + if(codec_running() == false) + codec_startDecode(rxAudioPath); + + // Process new data + if(newData) + { + auto& frame = demodulator.getFrame(); + auto type = decoder.decodeFrame(frame); + bool lsfOk = decoder.getLsf().valid(); + + if((type == M17FrameType::STREAM) && (lsfOk == true) && (pthSts == PATH_OPEN)) + { + M17StreamFrame sf = decoder.getStreamFrame(); + codec_pushFrame(sf.payload().data(), false); + codec_pushFrame(sf.payload().data() + 8, false); + } + } } locked = lock; - if(locked && newData) - { - auto& frame = demodulator.getFrame(); - auto type = decoder.decodeFrame(frame); - bool lsfOk = decoder.getLsf().valid(); - uint8_t pthSts = audioPath_getStatus(rxAudioPath); - int result = 0; - - if((type == M17FrameType::STREAM) && (lsfOk == true) && - (pthSts == PATH_OPEN)) - { - M17StreamFrame sf = decoder.getStreamFrame(); - result = codec_pushFrame(sf.payload().data(), false); - result = codec_pushFrame(sf.payload().data() + 8, false); - - // Try restarting audio codec if it went down - if(result == -EPERM) - codec_startDecode(rxAudioPath); - } - } - if(platform_getPttStatus()) { demodulator.stopBasebandSampling();