Moved audio management in M17 opmode handler to audio path system
This commit is contained in:
parent
edf864337a
commit
21481072e7
|
|
@ -33,6 +33,7 @@
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <dsp.h>
|
#include <dsp.h>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
#include <audio_path.h>
|
||||||
#include <interfaces/audio_stream.h>
|
#include <interfaces/audio_stream.h>
|
||||||
#include <M17/M17Datatypes.hpp>
|
#include <M17/M17Datatypes.hpp>
|
||||||
#include <M17/M17Constants.hpp>
|
#include <M17/M17Constants.hpp>
|
||||||
|
|
@ -146,6 +147,7 @@ private:
|
||||||
*/
|
*/
|
||||||
std::unique_ptr< int16_t[] > baseband_buffer; ///< Buffer for baseband audio handling.
|
std::unique_ptr< int16_t[] > baseband_buffer; ///< Buffer for baseband audio handling.
|
||||||
streamId basebandId; ///< Id of the baseband input stream.
|
streamId basebandId; ///< Id of the baseband input stream.
|
||||||
|
pathId basebandPath; ///< Id of the baseband input path.
|
||||||
dataBlock_t baseband; ///< Data block with samples to be processed.
|
dataBlock_t baseband; ///< Data block with samples to be processed.
|
||||||
uint16_t frame_index; ///< Index for filling the raw frame.
|
uint16_t frame_index; ///< Index for filling the raw frame.
|
||||||
std::unique_ptr<frame_t > demodFrame; ///< Frame being demodulated.
|
std::unique_ptr<frame_t > demodFrame; ///< Frame being demodulated.
|
||||||
|
|
|
||||||
|
|
@ -26,8 +26,9 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <interfaces/audio_stream.h>
|
#include <interfaces/audio_stream.h>
|
||||||
#include <M17/M17Constants.hpp>
|
|
||||||
#include <M17/PwmCompensator.hpp>
|
#include <M17/PwmCompensator.hpp>
|
||||||
|
#include <M17/M17Constants.hpp>
|
||||||
|
#include <audio_path.h>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <array>
|
#include <array>
|
||||||
|
|
@ -112,6 +113,7 @@ private:
|
||||||
std::unique_ptr< int16_t[] > baseband_buffer; ///< Buffer for baseband audio handling.
|
std::unique_ptr< int16_t[] > baseband_buffer; ///< Buffer for baseband audio handling.
|
||||||
stream_sample_t *idleBuffer; ///< Half baseband buffer, free for processing.
|
stream_sample_t *idleBuffer; ///< Half baseband buffer, free for processing.
|
||||||
streamId outStream; ///< Baseband output stream ID.
|
streamId outStream; ///< Baseband output stream ID.
|
||||||
|
pathId outPath; ///< Baseband output path ID.
|
||||||
bool txRunning; ///< Transmission running.
|
bool txRunning; ///< Transmission running.
|
||||||
|
|
||||||
#if defined(PLATFORM_MD3x0) || defined(PLATFORM_MDUV3x0)
|
#if defined(PLATFORM_MD3x0) || defined(PLATFORM_MDUV3x0)
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@
|
||||||
#include <M17/M17FrameEncoder.hpp>
|
#include <M17/M17FrameEncoder.hpp>
|
||||||
#include <M17/M17Demodulator.hpp>
|
#include <M17/M17Demodulator.hpp>
|
||||||
#include <M17/M17Modulator.hpp>
|
#include <M17/M17Modulator.hpp>
|
||||||
|
#include <audio_path.h>
|
||||||
#include "OpMode.hpp"
|
#include "OpMode.hpp"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -124,6 +125,8 @@ private:
|
||||||
bool startRx; ///< Flag for RX management.
|
bool startRx; ///< Flag for RX management.
|
||||||
bool startTx; ///< Flag for TX management.
|
bool startTx; ///< Flag for TX management.
|
||||||
bool locked; ///< Demodulator locked on data stream.
|
bool locked; ///< Demodulator locked on data stream.
|
||||||
|
pathId rxAudioPath; ///< Audio path ID for RX
|
||||||
|
pathId txAudioPath; ///< Audio path ID for TX
|
||||||
M17::M17Modulator modulator; ///< M17 modulator.
|
M17::M17Modulator modulator; ///< M17 modulator.
|
||||||
M17::M17Demodulator demodulator; ///< M17 demodulator.
|
M17::M17Demodulator demodulator; ///< M17 demodulator.
|
||||||
M17::M17FrameDecoder decoder; ///< M17 frame decoder
|
M17::M17FrameDecoder decoder; ///< M17 frame decoder
|
||||||
|
|
|
||||||
|
|
@ -203,6 +203,7 @@ void M17Demodulator::terminate()
|
||||||
|
|
||||||
void M17Demodulator::startBasebandSampling()
|
void M17Demodulator::startBasebandSampling()
|
||||||
{
|
{
|
||||||
|
basebandPath = audioPath_request(SOURCE_RTX, SINK_MCU, PRIO_RX);
|
||||||
basebandId = inputStream_start(SOURCE_RTX, PRIO_RX,
|
basebandId = inputStream_start(SOURCE_RTX, PRIO_RX,
|
||||||
baseband_buffer.get(),
|
baseband_buffer.get(),
|
||||||
2 * M17_SAMPLE_BUF_SIZE,
|
2 * M17_SAMPLE_BUF_SIZE,
|
||||||
|
|
@ -218,6 +219,7 @@ void M17Demodulator::startBasebandSampling()
|
||||||
void M17Demodulator::stopBasebandSampling()
|
void M17Demodulator::stopBasebandSampling()
|
||||||
{
|
{
|
||||||
inputStream_stop(basebandId);
|
inputStream_stop(basebandId);
|
||||||
|
audioPath_release(basebandPath);
|
||||||
phase = 0;
|
phase = 0;
|
||||||
syncDetected = false;
|
syncDetected = false;
|
||||||
locked = false;
|
locked = false;
|
||||||
|
|
@ -423,6 +425,7 @@ bool M17Demodulator::update()
|
||||||
uint16_t decoded_syms = 0;
|
uint16_t decoded_syms = 0;
|
||||||
|
|
||||||
// Read samples from the ADC
|
// Read samples from the ADC
|
||||||
|
if(audioPath_getStatus(basebandPath) != PATH_OPEN) return false;
|
||||||
baseband = inputStream_getData(basebandId);
|
baseband = inputStream_getData(basebandId);
|
||||||
|
|
||||||
if(baseband.data != NULL)
|
if(baseband.data != NULL)
|
||||||
|
|
|
||||||
|
|
@ -87,6 +87,13 @@ void M17Modulator::start()
|
||||||
// Generate baseband signal and then start transmission
|
// Generate baseband signal and then start transmission
|
||||||
symbolsToBaseband();
|
symbolsToBaseband();
|
||||||
#ifndef PLATFORM_LINUX
|
#ifndef PLATFORM_LINUX
|
||||||
|
outPath = audioPath_request(SOURCE_MCU, SINK_RTX, PRIO_TX);
|
||||||
|
if(outPath < 0)
|
||||||
|
{
|
||||||
|
txRunning = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
outStream = outputStream_start(SINK_RTX, PRIO_TX, baseband_buffer.get(),
|
outStream = outputStream_start(SINK_RTX, PRIO_TX, baseband_buffer.get(),
|
||||||
2*M17_FRAME_SAMPLES, BUF_CIRC_DOUBLE,
|
2*M17_FRAME_SAMPLES, BUF_CIRC_DOUBLE,
|
||||||
M17_TX_SAMPLE_RATE);
|
M17_TX_SAMPLE_RATE);
|
||||||
|
|
@ -145,6 +152,7 @@ void M17Modulator::stop()
|
||||||
outputStream_sync(outStream, false);
|
outputStream_sync(outStream, false);
|
||||||
txRunning = false;
|
txRunning = false;
|
||||||
idleBuffer = baseband_buffer.get();
|
idleBuffer = baseband_buffer.get();
|
||||||
|
audioPath_release(outPath);
|
||||||
|
|
||||||
#if defined(PLATFORM_MD3x0) || defined(PLATFORM_MDUV3x0)
|
#if defined(PLATFORM_MD3x0) || defined(PLATFORM_MDUV3x0)
|
||||||
pwmComp.reset();
|
pwmComp.reset();
|
||||||
|
|
@ -176,6 +184,7 @@ void M17Modulator::symbolsToBaseband()
|
||||||
void M17Modulator::sendBaseband()
|
void M17Modulator::sendBaseband()
|
||||||
{
|
{
|
||||||
if(txRunning == false) return;
|
if(txRunning == false) return;
|
||||||
|
if(audioPath_getStatus(outPath) != PATH_OPEN) return;
|
||||||
|
|
||||||
// Transmission is ongoing, syncronise with stream end before proceeding
|
// Transmission is ongoing, syncronise with stream end before proceeding
|
||||||
outputStream_sync(outStream, true);
|
outputStream_sync(outStream, true);
|
||||||
|
|
|
||||||
|
|
@ -55,10 +55,9 @@ void OpMode_M17::disable()
|
||||||
startTx = false;
|
startTx = false;
|
||||||
platform_ledOff(GREEN);
|
platform_ledOff(GREEN);
|
||||||
platform_ledOff(RED);
|
platform_ledOff(RED);
|
||||||
codec_stop();
|
audioPath_release(rxAudioPath);
|
||||||
|
audioPath_release(txAudioPath);
|
||||||
codec_terminate();
|
codec_terminate();
|
||||||
audio_disableAmp();
|
|
||||||
audio_disableMic();
|
|
||||||
radio_disableRtx();
|
radio_disableRtx();
|
||||||
modulator.terminate();
|
modulator.terminate();
|
||||||
demodulator.terminate();
|
demodulator.terminate();
|
||||||
|
|
@ -124,8 +123,8 @@ void OpMode_M17::offState(rtxStatus_t *const status)
|
||||||
{
|
{
|
||||||
radio_disableRtx();
|
radio_disableRtx();
|
||||||
|
|
||||||
audio_disableMic();
|
audioPath_release(rxAudioPath);
|
||||||
audio_disableAmp();
|
audioPath_release(txAudioPath);
|
||||||
codec_stop();
|
codec_stop();
|
||||||
|
|
||||||
if(startRx)
|
if(startRx)
|
||||||
|
|
@ -147,7 +146,7 @@ void OpMode_M17::rxState(rtxStatus_t *const status)
|
||||||
demodulator.startBasebandSampling();
|
demodulator.startBasebandSampling();
|
||||||
demodulator.invertPhase(status->invertRxPhase);
|
demodulator.invertPhase(status->invertRxPhase);
|
||||||
|
|
||||||
audio_enableAmp();
|
rxAudioPath = audioPath_request(SOURCE_MCU, SINK_SPK, PRIO_RX);
|
||||||
codec_startDecode(SINK_SPK);
|
codec_startDecode(SINK_SPK);
|
||||||
|
|
||||||
radio_enableRx();
|
radio_enableRx();
|
||||||
|
|
@ -171,8 +170,10 @@ void OpMode_M17::rxState(rtxStatus_t *const status)
|
||||||
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);
|
||||||
|
|
||||||
if((type == M17FrameType::STREAM) && (lsfOk == true))
|
if((type == M17FrameType::STREAM) && (lsfOk == true) &&
|
||||||
|
(pthSts == PATH_OPEN))
|
||||||
{
|
{
|
||||||
M17StreamFrame sf = decoder.getStreamFrame();
|
M17StreamFrame sf = decoder.getStreamFrame();
|
||||||
codec_pushFrame(sf.payload().data(), false);
|
codec_pushFrame(sf.payload().data(), false);
|
||||||
|
|
@ -215,7 +216,7 @@ void OpMode_M17::txState(rtxStatus_t *const status)
|
||||||
encoder.reset();
|
encoder.reset();
|
||||||
encoder.encodeLsf(lsf, m17Frame);
|
encoder.encodeLsf(lsf, m17Frame);
|
||||||
|
|
||||||
audio_enableMic();
|
txAudioPath = audioPath_request(SOURCE_MIC, SINK_MCU, PRIO_TX);
|
||||||
codec_startEncode(SOURCE_MIC);
|
codec_startEncode(SOURCE_MIC);
|
||||||
radio_enableTx();
|
radio_enableTx();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,8 @@
|
||||||
#include <interfaces/gpio.h>
|
#include <interfaces/gpio.h>
|
||||||
#include <hwconfig.h>
|
#include <hwconfig.h>
|
||||||
|
|
||||||
|
#define PATH(x,y) ((x << 4) | y)
|
||||||
|
|
||||||
static const uint8_t pathCompatibilityMatrix[9][9] =
|
static const uint8_t pathCompatibilityMatrix[9][9] =
|
||||||
{
|
{
|
||||||
// MIC-SPK MIC-RTX MIC-MCU RTX-SPK RTX-RTX RTX-MCU MCU-SPK MCU-RTX MCU-MCU
|
// MIC-SPK MIC-RTX MIC-MCU RTX-SPK RTX-RTX RTX-MCU MCU-SPK MCU-RTX MCU-MCU
|
||||||
|
|
@ -71,20 +73,24 @@ void audio_terminate()
|
||||||
|
|
||||||
void audio_connect(const enum AudioSource source, const enum AudioSink sink)
|
void audio_connect(const enum AudioSource source, const enum AudioSink sink)
|
||||||
{
|
{
|
||||||
// If source is MIC, turn it on regardless of the sink
|
uint32_t path = PATH(source, sink);
|
||||||
#if !defined(PLATFORM_MD9600) && !defined(MDx_ENABLE_SWD)
|
|
||||||
if(source == SOURCE_MIC) gpio_setPin(MIC_PWR);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if(sink == SINK_SPK)
|
switch(path)
|
||||||
{
|
{
|
||||||
switch(source)
|
case PATH(SOURCE_MIC, SINK_SPK):
|
||||||
{
|
case PATH(SOURCE_MIC, SINK_RTX):
|
||||||
case SOURCE_RTX:
|
case PATH(SOURCE_MIC, SINK_MCU):
|
||||||
|
#if !defined(PLATFORM_MD9600) && !defined(MDx_ENABLE_SWD)
|
||||||
|
gpio_setPin(MIC_PWR);
|
||||||
|
#endif
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PATH(SOURCE_RTX, SINK_SPK):
|
||||||
radio_enableAfOutput();
|
radio_enableAfOutput();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SOURCE_MCU:
|
case PATH(SOURCE_MCU, SINK_SPK):
|
||||||
|
case PATH(SOURCE_MCU, SINK_RTX):
|
||||||
gpio_setMode(BEEP_OUT, ALTERNATE);
|
gpio_setMode(BEEP_OUT, ALTERNATE);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
@ -92,6 +98,8 @@ void audio_connect(const enum AudioSource source, const enum AudioSink sink)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(sink == SINK_SPK)
|
||||||
|
{
|
||||||
// Anti-pop: unmute speaker after 10ms from amp. power on
|
// Anti-pop: unmute speaker after 10ms from amp. power on
|
||||||
#ifndef PLATFORM_MD9600
|
#ifndef PLATFORM_MD9600
|
||||||
gpio_setPin(AUDIO_AMP_EN);
|
gpio_setPin(AUDIO_AMP_EN);
|
||||||
|
|
@ -103,10 +111,7 @@ void audio_connect(const enum AudioSource source, const enum AudioSink sink)
|
||||||
|
|
||||||
void audio_disconnect(const enum AudioSource source, const enum AudioSink sink)
|
void audio_disconnect(const enum AudioSource source, const enum AudioSink sink)
|
||||||
{
|
{
|
||||||
// If source is MIC, turn it off regardless of the sink
|
uint32_t path = PATH(source, sink);
|
||||||
#if !defined(PLATFORM_MD9600) && !defined(MDx_ENABLE_SWD)
|
|
||||||
if(source == SOURCE_MIC) gpio_clearPin(MIC_PWR);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if(sink == SINK_SPK)
|
if(sink == SINK_SPK)
|
||||||
{
|
{
|
||||||
|
|
@ -114,14 +119,24 @@ void audio_disconnect(const enum AudioSource source, const enum AudioSink sink)
|
||||||
#ifndef PLATFORM_MD9600
|
#ifndef PLATFORM_MD9600
|
||||||
gpio_clearPin(AUDIO_AMP_EN);
|
gpio_clearPin(AUDIO_AMP_EN);
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
switch(source)
|
switch(path)
|
||||||
{
|
{
|
||||||
case SOURCE_RTX:
|
case PATH(SOURCE_MIC, SINK_SPK):
|
||||||
|
case PATH(SOURCE_MIC, SINK_RTX):
|
||||||
|
case PATH(SOURCE_MIC, SINK_MCU):
|
||||||
|
#if !defined(PLATFORM_MD9600) && !defined(MDx_ENABLE_SWD)
|
||||||
|
gpio_clearPin(MIC_PWR);
|
||||||
|
#endif
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PATH(SOURCE_RTX, SINK_SPK):
|
||||||
radio_disableAfOutput();
|
radio_disableAfOutput();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SOURCE_MCU:
|
case PATH(SOURCE_MCU, SINK_SPK):
|
||||||
|
case PATH(SOURCE_MCU, SINK_RTX):
|
||||||
gpio_setMode(BEEP_OUT, INPUT); // Set output to Hi-Z
|
gpio_setMode(BEEP_OUT, INPUT); // Set output to Hi-Z
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
@ -129,7 +144,6 @@ void audio_disconnect(const enum AudioSource source, const enum AudioSink sink)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
bool audio_checkPathCompatibility(const enum AudioSource p1Source,
|
bool audio_checkPathCompatibility(const enum AudioSource p1Source,
|
||||||
const enum AudioSink p1Sink,
|
const enum AudioSink p1Sink,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue