From adf88611f4b02dc6506c19461e398e00f4665992 Mon Sep 17 00:00:00 2001 From: Silvano Seva Date: Sat, 20 May 2023 12:36:12 +0200 Subject: [PATCH] Changed codec_startEncode() and codec_startDecode() input parameter from an audio source/sink to an audio path --- openrtx/include/core/audio_codec.h | 10 ++++---- openrtx/src/core/audio_codec.c | 38 +++++++++++++++++++++--------- openrtx/src/core/voicePrompts.c | 2 +- openrtx/src/rtx/OpMode_M17.cpp | 4 ++-- 4 files changed, 35 insertions(+), 19 deletions(-) diff --git a/openrtx/include/core/audio_codec.h b/openrtx/include/core/audio_codec.h index a4d80096..88f1d330 100644 --- a/openrtx/include/core/audio_codec.h +++ b/openrtx/include/core/audio_codec.h @@ -21,7 +21,7 @@ #ifndef AUDIO_CODEC_H #define AUDIO_CODEC_H -#include +#include #include #include @@ -48,10 +48,10 @@ void codec_terminate(); * Only an encoding or decoding operation at a time is possible: in case there * is already an operation in progress, this function returns false. * - * @param source: audio source for encoding. + * @param path: audio path for encoding source. * @return true on success, false on failure. */ -bool codec_startEncode(const enum AudioSource source); +bool codec_startEncode(const pathId path); /** * Start dencoding of audio data sending the uncompressed samples to a given @@ -59,10 +59,10 @@ bool codec_startEncode(const enum AudioSource source); * Only an encoding or decoding operation at a time is possible: in case there * is already an operation in progress, this function returns false. * - * @param destination: destination for decoded audio. + * @param path: audio path for decoded audio. * @return true on success, false on failure. */ -bool codec_startDecode(const enum AudioSink destination); +bool codec_startDecode(const pathId path); /** * Stop an ongoing encoding or decoding operation. diff --git a/openrtx/src/core/audio_codec.c b/openrtx/src/core/audio_codec.c index 39ad82a6..57605e8d 100644 --- a/openrtx/src/core/audio_codec.c +++ b/openrtx/src/core/audio_codec.c @@ -106,17 +106,25 @@ void codec_terminate() } } -bool codec_startEncode(const enum AudioSource source) +bool codec_startEncode(const pathId path) { - if(running) return false; - if(audioBuf == NULL) return false; + if(running) + return false; + + if(audioBuf == NULL) + return false; + + // Bad incoming path + if(audioPath_getStatus(path) != PATH_OPEN) + return false; running = true; - audioStream = inputStream_start(source, PRIO_TX, audioBuf, 320, - BUF_CIRC_DOUBLE, 8000); + pathInfo_t pathInfo = audioPath_getInfo(path); + audioStream = inputStream_start(pathInfo.source, pathInfo.prio, audioBuf, + 320, BUF_CIRC_DOUBLE, 8000); - if(audioStream == -1) + if(audioStream < 0) { running = false; return false; @@ -131,16 +139,24 @@ bool codec_startEncode(const enum AudioSource source) return true; } -bool codec_startDecode(const enum AudioSink destination) +bool codec_startDecode(const pathId path) { - if(running) return false; - if(audioBuf == NULL) return false; + if(running) + return false; + + if(audioBuf == NULL) + return false; + + // Bad incoming path + if(audioPath_getStatus(path) != PATH_OPEN) + return false; running = true; memset(audioBuf, 0x00, 320 * sizeof(stream_sample_t)); - audioStream = outputStream_start(destination, PRIO_RX, audioBuf, 320, - BUF_CIRC_DOUBLE, 8000); + pathInfo_t pathInfo = audioPath_getInfo(path); + audioStream = outputStream_start(pathInfo.sink, pathInfo.prio, audioBuf, + 320, BUF_CIRC_DOUBLE, 8000); if(audioStream == -1) { diff --git a/openrtx/src/core/voicePrompts.c b/openrtx/src/core/voicePrompts.c index 404ecad1..184e39c6 100644 --- a/openrtx/src/core/voicePrompts.c +++ b/openrtx/src/core/voicePrompts.c @@ -581,8 +581,8 @@ void vp_tick() { vpStartTime = 0; voicePromptActive = true; - codec_startDecode(SINK_SPK); enableSpkOutput(); + codec_startDecode(vpAudioPath); } if (voicePromptActive == false) diff --git a/openrtx/src/rtx/OpMode_M17.cpp b/openrtx/src/rtx/OpMode_M17.cpp index e2fcd3ba..0e2a6498 100644 --- a/openrtx/src/rtx/OpMode_M17.cpp +++ b/openrtx/src/rtx/OpMode_M17.cpp @@ -165,7 +165,7 @@ void OpMode_M17::rxState(rtxStatus_t *const status) demodulator.invertPhase(invertRxPhase); rxAudioPath = audioPath_request(SOURCE_MCU, SINK_SPK, PRIO_RX); - codec_startDecode(SINK_SPK); + codec_startDecode(rxAudioPath); radio_enableRx(); @@ -235,7 +235,7 @@ void OpMode_M17::txState(rtxStatus_t *const status) encoder.encodeLsf(lsf, m17Frame); txAudioPath = audioPath_request(SOURCE_MIC, SINK_MCU, PRIO_TX); - codec_startEncode(SOURCE_MIC); + codec_startEncode(txAudioPath); radio_enableTx(); modulator.invertPhase(invertTxPhase);