Fixed bug in M17 opmode handler causing missing audio output

This commit is contained in:
Silvano Seva 2023-08-30 18:02:46 +02:00
parent c9cd620530
commit 6dd0a718e0
1 changed files with 32 additions and 25 deletions

View File

@ -174,37 +174,44 @@ void OpMode_M17::rxState(rtxStatus_t *const status)
bool newData = demodulator.update(); bool newData = demodulator.update();
bool lock = demodulator.isLocked(); bool lock = demodulator.isLocked();
// Reset frame decoder when transitioning from unlocked to locked state and // Reset frame decoder when transitioning from unlocked to locked state.
// setup audio path towards the speaker.
if((lock == true) && (locked == false)) if((lock == true) && (locked == false))
{ {
decoder.reset(); decoder.reset();
rxAudioPath = audioPath_request(SOURCE_MCU, SINK_SPK, PRIO_RX); locked = lock;
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);
}
if(locked && newData) // Start codec2 module if not already up
if(codec_running() == false)
codec_startDecode(rxAudioPath);
// Process new data
if(newData)
{ {
auto& frame = demodulator.getFrame(); auto& frame = demodulator.getFrame();
auto type = decoder.decodeFrame(frame); auto type = decoder.decodeFrame(frame);
bool lsfOk = decoder.getLsf().valid(); bool lsfOk = decoder.getLsf().valid();
uint8_t pthSts = audioPath_getStatus(rxAudioPath);
int result = 0;
if((type == M17FrameType::STREAM) && (lsfOk == true) && if((type == M17FrameType::STREAM) && (lsfOk == true) && (pthSts == PATH_OPEN))
(pthSts == PATH_OPEN))
{ {
M17StreamFrame sf = decoder.getStreamFrame(); M17StreamFrame sf = decoder.getStreamFrame();
result = codec_pushFrame(sf.payload().data(), false); codec_pushFrame(sf.payload().data(), false);
result = codec_pushFrame(sf.payload().data() + 8, false); codec_pushFrame(sf.payload().data() + 8, false);
}
}
}
// Try restarting audio codec if it went down locked = lock;
if(result == -EPERM)
codec_startDecode(rxAudioPath);
}
}
if(platform_getPttStatus()) if(platform_getPttStatus())
{ {