M17 mode handler: calling demodulator update function when in RX mode

This commit is contained in:
Silvano Seva 2021-12-26 21:55:08 +01:00
parent d22948a096
commit 963fbdc141
4 changed files with 28 additions and 17 deletions

View File

@ -36,7 +36,8 @@
namespace M17 namespace M17
{ {
typedef struct { typedef struct
{
int32_t index; int32_t index;
bool lsf; bool lsf;
} sync_t; } sync_t;
@ -113,7 +114,7 @@ private:
/** /**
* M17 syncwords; * M17 syncwords;
*/ */
int8_t lsf_syncword[M17_SYNCWORD_SYMBOLS] = { +3, +3, +3, +3, -3, -3, +3, -3 }; int8_t lsf_syncword[M17_SYNCWORD_SYMBOLS] = { +3, +3, +3, +3, -3, -3, +3, -3 };
int8_t stream_syncword[M17_SYNCWORD_SYMBOLS] = { -3, -3, -3, -3, +3, +3, -3, +3 }; int8_t stream_syncword[M17_SYNCWORD_SYMBOLS] = { -3, -3, -3, -3, +3, +3, -3, +3 };
using dataBuffer_t = std::array< int16_t, M17_FRAME_SAMPLES_24K >; using dataBuffer_t = std::array< int16_t, M17_FRAME_SAMPLES_24K >;

View File

@ -22,6 +22,7 @@
#define OPMODE_M17_H #define OPMODE_M17_H
#include <M17/M17Transmitter.h> #include <M17/M17Transmitter.h>
#include <M17/M17Demodulator.h>
#include <M17/M17Modulator.h> #include <M17/M17Modulator.h>
#include <array> #include <array>
#include "OpMode.h" #include "OpMode.h"
@ -105,6 +106,7 @@ private:
bool enterRx; ///< Flag for RX management. bool enterRx; ///< Flag for RX management.
M17::M17Modulator modulator; ///< M17 modulator. M17::M17Modulator modulator; ///< M17 modulator.
M17::M17Demodulator demodulator; ///< M17 demodulator.
M17::M17Transmitter m17Tx; ///< M17 transmission manager. M17::M17Transmitter m17Tx; ///< M17 transmission manager.
}; };

View File

@ -24,12 +24,6 @@
#include <interfaces/audio_stream.h> #include <interfaces/audio_stream.h>
#include <math.h> #include <math.h>
#if defined(PLATFORM_MD3x0) || defined(PLATFORM_MDUV3x0)
#include <toneGenerator_MDx.h>
#elif defined(PLATFORM_LINUX)
#include <stdio.h>
#endif
namespace M17 namespace M17
{ {
@ -82,7 +76,8 @@ void M17Demodulator::stopBasebandSampling()
inputStream_stop(basebandId); inputStream_stop(basebandId);
} }
void M17Demodulator::resetCorrelationStats() { void M17Demodulator::resetCorrelationStats()
{
conv_ema = 0.0f; conv_ema = 0.0f;
conv_emvar = 20000000000.0f; conv_emvar = 20000000000.0f;
} }
@ -94,9 +89,9 @@ void M17Demodulator::resetCorrelationStats() {
void M17Demodulator::updateCorrelationStats(int32_t value) void M17Demodulator::updateCorrelationStats(int32_t value)
{ {
float delta = (float) value - conv_ema; float delta = (float) value - conv_ema;
float incr = conv_stats_alpha * delta; float incr = conv_stats_alpha * delta;
conv_ema += incr; conv_ema += incr;
conv_emvar = (1.0f - conv_stats_alpha) * (conv_emvar + delta * incr); conv_emvar = (1.0f - conv_stats_alpha) * (conv_emvar + delta * incr);
} }
float M17Demodulator::getCorrelationStddev() float M17Demodulator::getCorrelationStddev()
@ -104,21 +99,31 @@ float M17Demodulator::getCorrelationStddev()
return sqrt(conv_emvar); return sqrt(conv_emvar);
} }
void M17Demodulator::resetQuantizationStats() { void M17Demodulator::resetQuantizationStats()
{
qnt_max = 0.0f; qnt_max = 0.0f;
} }
void M17Demodulator::updateQuantizationStats(uint32_t offset) void M17Demodulator::updateQuantizationStats(uint32_t offset)
{ {
auto value = baseband.data[offset]; auto value = baseband.data[offset];
if (value > qnt_max) { if (value > qnt_max)
{
qnt_max = value; qnt_max = value;
} else }
else
{
qnt_max *= qnt_maxmin_alpha; qnt_max *= qnt_maxmin_alpha;
if (value < qnt_min) { }
if (value < qnt_min)
{
qnt_min = value; qnt_min = value;
} else }
else
{
qnt_min *= qnt_maxmin_alpha; qnt_min *= qnt_maxmin_alpha;
}
} }
float M17Demodulator::getQuantizationMax() float M17Demodulator::getQuantizationMax()

View File

@ -125,6 +125,7 @@ void OpMode_M17::enable()
pthread_create(&codecThread, &codecAttr, threadFunc, NULL); pthread_create(&codecThread, &codecAttr, threadFunc, NULL);
modulator.init(); modulator.init();
demodulator.init();
enterRx = true; enterRx = true;
} }
@ -138,6 +139,7 @@ void OpMode_M17::disable()
enterRx = false; enterRx = false;
modulator.terminate(); modulator.terminate();
demodulator.terminate();
} }
void OpMode_M17::update(rtxStatus_t *const status, const bool newCfg) void OpMode_M17::update(rtxStatus_t *const status, const bool newCfg)
@ -148,6 +150,7 @@ void OpMode_M17::update(rtxStatus_t *const status, const bool newCfg)
if(status->opStatus == RX) if(status->opStatus == RX)
{ {
// TODO: Implement M17 Rx // TODO: Implement M17 Rx
demodulator.update();
sleepFor(0u, 30u); sleepFor(0u, 30u);
} }
else if((status->opStatus == OFF) && enterRx) else if((status->opStatus == OFF) && enterRx)