From dd118d0a87806feadfbe77ec9b0380898a646463 Mon Sep 17 00:00:00 2001 From: Silvano Seva Date: Sat, 20 May 2023 14:30:35 +0200 Subject: [PATCH] Adapted voice prompt and M17 code to new codec2 API --- openrtx/src/core/voicePrompts.c | 7 ++++--- openrtx/src/rtx/OpMode_M17.cpp | 21 ++++++++++++++------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/openrtx/src/core/voicePrompts.c b/openrtx/src/core/voicePrompts.c index 184e39c6..c421f2c8 100644 --- a/openrtx/src/core/voicePrompts.c +++ b/openrtx/src/core/voicePrompts.c @@ -32,6 +32,7 @@ #include #include #include +#include static const uint32_t VOICE_PROMPTS_DATA_MAGIC = 0x5056; //'VP' static const uint32_t VOICE_PROMPTS_DATA_VERSION = 0x1000; // v1000 OpenRTX @@ -404,8 +405,8 @@ void vp_terminate() void vp_stop() { voicePromptActive = false; + codec_stop(vpAudioPath); disableSpkOutput(); - codec_stop(); // Clear voice prompt sequence data vpCurrentSequence.pos = 0; @@ -614,7 +615,7 @@ void vp_tick() if(audioPath_getStatus(vpAudioPath) != PATH_OPEN) return; - if (codec_pushFrame(c2Frame, false) == false) + if(codec_pushFrame(c2Frame, false) < 0) return; vpCurrentSequence.c2DataIndex += 8; @@ -632,8 +633,8 @@ void vp_tick() vpCurrentSequence.pos = 0; vpCurrentSequence.c2DataIndex = 0; vpCurrentSequence.c2DataLength = 0; + codec_stop(vpAudioPath); disableSpkOutput(); - codec_stop(); } } diff --git a/openrtx/src/rtx/OpMode_M17.cpp b/openrtx/src/rtx/OpMode_M17.cpp index 0e2a6498..42ebc210 100644 --- a/openrtx/src/rtx/OpMode_M17.cpp +++ b/openrtx/src/rtx/OpMode_M17.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #ifdef PLATFORM_MOD17 @@ -141,9 +142,10 @@ void OpMode_M17::offState(rtxStatus_t *const status) { radio_disableRtx(); + codec_stop(rxAudioPath); + codec_stop(txAudioPath); audioPath_release(rxAudioPath); audioPath_release(txAudioPath); - codec_stop(); if(startRx) { @@ -164,9 +166,6 @@ void OpMode_M17::rxState(rtxStatus_t *const status) demodulator.startBasebandSampling(); demodulator.invertPhase(invertRxPhase); - rxAudioPath = audioPath_request(SOURCE_MCU, SINK_SPK, PRIO_RX); - codec_startDecode(rxAudioPath); - radio_enableRx(); startRx = false; @@ -175,10 +174,13 @@ 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 + // Reset frame decoder when transitioning from unlocked to locked state and + // setup audio path towards the speaker. if((lock == true) && (locked == false)) { decoder.reset(); + rxAudioPath = audioPath_request(SOURCE_MCU, SINK_SPK, PRIO_RX); + codec_startDecode(rxAudioPath); } locked = lock; @@ -189,13 +191,18 @@ void OpMode_M17::rxState(rtxStatus_t *const status) 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(); - codec_pushFrame(sf.payload().data(), false); - codec_pushFrame(sf.payload().data() + 8, false); + 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); } }