Changed codec_startEncode() and codec_startDecode() input parameter from an audio source/sink to an audio path

This commit is contained in:
Silvano Seva 2023-05-20 12:36:12 +02:00
parent 60b771b375
commit adf88611f4
4 changed files with 35 additions and 19 deletions

View File

@ -21,7 +21,7 @@
#ifndef AUDIO_CODEC_H
#define AUDIO_CODEC_H
#include <interfaces/audio.h>
#include <audio_path.h>
#include <stdint.h>
#include <stdbool.h>
@ -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.

View File

@ -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)
{

View File

@ -581,8 +581,8 @@ void vp_tick()
{
vpStartTime = 0;
voicePromptActive = true;
codec_startDecode(SINK_SPK);
enableSpkOutput();
codec_startDecode(vpAudioPath);
}
if (voicePromptActive == false)

View File

@ -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);