Skip to content

Commit

Permalink
Fix the M17 convolution.
Browse files Browse the repository at this point in the history
  • Loading branch information
g4klx committed Aug 11, 2021
1 parent e2e5ddf commit 14bf500
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 33 deletions.
25 changes: 4 additions & 21 deletions M17Control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,29 +258,12 @@ bool CM17Control::writeModem(unsigned char* data, unsigned int len)
unsigned char frame[M17_FN_LENGTH_BYTES + M17_PAYLOAD_LENGTH_BYTES];
unsigned int errors = conv.decodeData(data + 2U + M17_SYNC_LENGTH_BYTES + M17_LICH_FRAGMENT_FEC_LENGTH_BYTES, frame);

// If we have a BER of less than 12, then we consider the audio to be usable
bool valid = errors < 12U;

if (!valid) {
m_rfFN++;

frame[0U] = (m_rfFN >> 8) & 0xFFU;
frame[1U] = (m_rfFN >> 0) & 0xFFU;

if (m_rfState == RS_RF_AUDIO) {
::memcpy(frame + 2U + 0U, M17_3200_SILENCE, 8U);
::memcpy(frame + 2U + 8U, M17_3200_SILENCE, 8U);
} else {
::memcpy(frame + 2U + 0U, M17_1600_SILENCE, 4U);
::memcpy(frame + 2U + 4U, M17_1600_SILENCE, 4U);
::memset(frame + 2U + 8U, 0x00U, 8U);
}
} else {
m_rfFN = (frame[0U] << 8) + (frame[1U] << 0);
}
m_rfFN = (frame[0U] << 8) + (frame[1U] << 0);

LogDebug("M17, audio: FN: %u, errs: %u/272 (%.1f%%)", m_rfFN & 0x7FFFU, errors, float(errors) / 2.72F);

m_rfFN++;

m_rfBits += 272U;
m_rfErrs += errors;

Expand Down Expand Up @@ -343,7 +326,7 @@ bool CM17Control::writeModem(unsigned char* data, unsigned int len)
m_rfLSFn = 0U;

// Only check for the EOT marker if the frame has a reasonable BER
if (valid && ((m_rfFN & 0x8000U) == 0x8000U)) {
if ((m_rfFN & 0x8000U) == 0x8000U) {
std::string source = m_rfLSF.getSource();
std::string dest = m_rfLSF.getDest();

Expand Down
18 changes: 7 additions & 11 deletions M17Convolution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const unsigned int PUNCTURE_LIST_LINK_SETUP[] = {
362U, 369U, 372U, 375U, 378U, 385U, 388U, 391U, 394U, 401U, 404U, 407U, 410U, 417U, 420U, 423U, 430U, 433U, 436U, 439U, 446U,
449U, 452U, 455U, 462U, 465U, 468U, 471U, 478U, 481U, 484U};

const unsigned int PUNCTURE_LIST_DATA_COUNT = 22U;
const unsigned int PUNCTURE_LIST_DATA_COUNT = 12U;

const unsigned int PUNCTURE_LIST_DATA[] = {
11U, 23U, 35U, 47U, 59U, 71U, 83U, 95U, 107U, 119U, 131U, 143U, 155U, 167U, 179U, 191U, 203U, 215U, 227U, 239U, 251U, 263U,
Expand Down Expand Up @@ -128,6 +128,7 @@ unsigned int CM17Convolution::decodeLinkSetup(const unsigned char* in, unsigned
assert(out != NULL);

uint8_t temp[500U];
::memset(temp, 0x00U, 500U);

unsigned int n = 0U;
unsigned int index = 0U;
Expand All @@ -141,9 +142,6 @@ unsigned int CM17Convolution::decodeLinkSetup(const unsigned char* in, unsigned
temp[n++] = b ? 2U : 0U;
}

for (unsigned int i = 0U; i < 8U; i++)
temp[n++] = 0U;

start();

n = 0U;
Expand All @@ -154,15 +152,16 @@ unsigned int CM17Convolution::decodeLinkSetup(const unsigned char* in, unsigned
decode(s0, s1);
}

return chainback(out, 144U) - PUNCTURE_LIST_LINK_SETUP_COUNT;
return chainback(out, 240U) - PUNCTURE_LIST_LINK_SETUP_COUNT;
}

unsigned int CM17Convolution::decodeData(const unsigned char* in, unsigned char* out)
{
assert(in != NULL);
assert(out != NULL);

uint8_t temp[350U];
uint8_t temp[300U];
::memset(temp, 0x00U, 300U);

unsigned int n = 0U;
unsigned int index = 0U;
Expand All @@ -176,20 +175,17 @@ unsigned int CM17Convolution::decodeData(const unsigned char* in, unsigned char*
temp[n++] = b ? 2U : 0U;
}

for (unsigned int i = 0U; i < 8U; i++)
temp[n++] = 0U;

start();

n = 0U;
for (unsigned int i = 0U; i < 164U; i++) {
for (unsigned int i = 0U; i < 148U; i++) {
uint8_t s0 = temp[n++];
uint8_t s1 = temp[n++];

decode(s0, s1);
}

return chainback(out, 160U) - PUNCTURE_LIST_DATA_COUNT;
return chainback(out, 144U) - PUNCTURE_LIST_DATA_COUNT;
}

void CM17Convolution::start()
Expand Down
2 changes: 1 addition & 1 deletion Version.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@
#if !defined(VERSION_H)
#define VERSION_H

const char* VERSION = "20210810";
const char* VERSION = "20210811";

#endif

0 comments on commit 14bf500

Please sign in to comment.