From 7d90d15a5fb5bada299fadca85ca43a0f012fb61 Mon Sep 17 00:00:00 2001 From: Silvano Seva Date: Sat, 6 May 2023 21:41:42 +0200 Subject: [PATCH] Adapt code to the new audio stream API. --- openrtx/src/core/audio_codec.c | 15 ++++++-------- openrtx/src/protocols/M17/M17Demodulator.cpp | 21 ++++++++++---------- openrtx/src/protocols/M17/M17Modulator.cpp | 11 +++++----- 3 files changed, 21 insertions(+), 26 deletions(-) diff --git a/openrtx/src/core/audio_codec.c b/openrtx/src/core/audio_codec.c index 57605e8d..c0747771 100644 --- a/openrtx/src/core/audio_codec.c +++ b/openrtx/src/core/audio_codec.c @@ -120,9 +120,8 @@ bool codec_startEncode(const pathId path) running = true; - pathInfo_t pathInfo = audioPath_getInfo(path); - audioStream = inputStream_start(pathInfo.source, pathInfo.prio, audioBuf, - 320, BUF_CIRC_DOUBLE, 8000); + audioStream = audioStream_start(path, audioBuf, 320, 8000, + STREAM_INPUT | BUF_CIRC_DOUBLE); if(audioStream < 0) { @@ -154,9 +153,8 @@ bool codec_startDecode(const pathId path) running = true; memset(audioBuf, 0x00, 320 * sizeof(stream_sample_t)); - pathInfo_t pathInfo = audioPath_getInfo(path); - audioStream = outputStream_start(pathInfo.sink, pathInfo.prio, audioBuf, - 320, BUF_CIRC_DOUBLE, 8000); + audioStream = audioStream_start(path, audioBuf, 320, 8000, + STREAM_OUTPUT | BUF_CIRC_DOUBLE); if(audioStream == -1) { @@ -299,7 +297,7 @@ static void *encodeFunc(void *arg) } } - inputStream_stop(audioStream); + audioStream_terminate(audioStream); codec2_destroy(codec2); return NULL; @@ -357,8 +355,7 @@ static void *decodeFunc(void *arg) } // Stop stream and wait until its effective termination - outputStream_stop(audioStream); - outputStream_sync(audioStream, false); + audioStream_stop(audioStream); codec2_destroy(codec2); return NULL; diff --git a/openrtx/src/protocols/M17/M17Demodulator.cpp b/openrtx/src/protocols/M17/M17Demodulator.cpp index 0d6e617d..1214a0ec 100644 --- a/openrtx/src/protocols/M17/M17Demodulator.cpp +++ b/openrtx/src/protocols/M17/M17Demodulator.cpp @@ -190,7 +190,7 @@ void M17Demodulator::terminate() { // Ensure proper termination of baseband sampling audioPath_release(basebandPath); - inputStream_stop(basebandId); + audioStream_terminate(basebandId); // Delete the buffers and deallocate memory. baseband_buffer.reset(); @@ -205,11 +205,10 @@ void M17Demodulator::terminate() void M17Demodulator::startBasebandSampling() { basebandPath = audioPath_request(SOURCE_RTX, SINK_MCU, PRIO_RX); - basebandId = inputStream_start(SOURCE_RTX, PRIO_RX, - baseband_buffer.get(), - 2 * M17_SAMPLE_BUF_SIZE, - BUF_CIRC_DOUBLE, - M17_RX_SAMPLE_RATE); + basebandId = audioStream_start(basebandPath, baseband_buffer.get(), + 2 * M17_SAMPLE_BUF_SIZE, M17_RX_SAMPLE_RATE, + STREAM_INPUT | BUF_CIRC_DOUBLE); + // Clean start of the demodulation statistics resetCorrelationStats(); resetQuantizationStats(); @@ -219,11 +218,11 @@ void M17Demodulator::startBasebandSampling() void M17Demodulator::stopBasebandSampling() { - inputStream_stop(basebandId); - audioPath_release(basebandPath); - phase = 0; - syncDetected = false; - locked = false; + audioStream_terminate(basebandId); + audioPath_release(basebandPath); + phase = 0; + syncDetected = false; + locked = false; } void M17Demodulator::resetCorrelationStats() diff --git a/openrtx/src/protocols/M17/M17Modulator.cpp b/openrtx/src/protocols/M17/M17Modulator.cpp index 14fd422b..febc1ca6 100644 --- a/openrtx/src/protocols/M17/M17Modulator.cpp +++ b/openrtx/src/protocols/M17/M17Modulator.cpp @@ -63,7 +63,7 @@ void M17Modulator::terminate() // Terminate an ongoing stream, if present if(txRunning) { - outputStream_terminate(outStream); + audioStream_terminate(outStream); txRunning = false; } @@ -97,9 +97,9 @@ void M17Modulator::start() return; } - outStream = outputStream_start(SINK_RTX, PRIO_TX, baseband_buffer.get(), - 2*M17_FRAME_SAMPLES, BUF_CIRC_DOUBLE, - M17_TX_SAMPLE_RATE); + outStream = audioStream_start(outPath, baseband_buffer.get(), + 2*M17_FRAME_SAMPLES, M17_TX_SAMPLE_RATE, + STREAM_OUTPUT | BUF_CIRC_DOUBLE); idleBuffer = outputStream_getIdleBuffer(outStream); #else sendBaseband(); @@ -130,8 +130,7 @@ void M17Modulator::stop() if(txRunning == false) return; - outputStream_stop(outStream); - outputStream_sync(outStream, false); + audioStream_stop(outStream); txRunning = false; idleBuffer = baseband_buffer.get(); audioPath_release(outPath);