From ca24d1bc5723daf44e154a51bab1ea31c359d0fb Mon Sep 17 00:00:00 2001 From: f4exb Date: Sun, 31 Jul 2022 04:24:03 +0200 Subject: [PATCH] M17: Util code cleanup --- modemm17/M17FrameDecoder.h | 8 ++++---- modemm17/M17Modulator.h | 8 ++++---- modemm17/Util.h | 39 +++++++++----------------------------- 3 files changed, 17 insertions(+), 38 deletions(-) diff --git a/modemm17/M17FrameDecoder.h b/modemm17/M17FrameDecoder.h index 108d1ed49..081fa8375 100644 --- a/modemm17/M17FrameDecoder.h +++ b/modemm17/M17FrameDecoder.h @@ -154,7 +154,7 @@ struct M17FrameDecoder DecodeResult decode_lsf(input_buffer_t& buffer, int& viterbi_cost) { depunctured_buffer_t depuncture_buffer; - depuncture(buffer, depuncture_buffer.lsf, P1); + depuncture<368, 488, 61>(buffer, depuncture_buffer.lsf, P1); viterbi_cost = viterbi_.decode(depuncture_buffer.lsf, decode_buffer.lsf); to_byte_array(decode_buffer.lsf, output_buffer.lsf); @@ -268,7 +268,7 @@ struct M17FrameDecoder DecodeResult decode_bert(input_buffer_t& buffer, int& viterbi_cost) { depunctured_buffer_t depuncture_buffer; - depuncture(buffer, depuncture_buffer.bert, P2); + depuncture<368, 402, 12>(buffer, depuncture_buffer.bert, P2); viterbi_cost = viterbi_.decode(depuncture_buffer.bert, decode_buffer.bert); to_byte_array(decode_buffer.bert, output_buffer.bert); @@ -284,7 +284,7 @@ struct M17FrameDecoder std::copy(buffer.begin() + 96, buffer.end(), tmp.begin()); depunctured_buffer_t depuncture_buffer; - depuncture(tmp, depuncture_buffer.stream, P2); + depuncture<272, 296, 12>(tmp, depuncture_buffer.stream, P2); viterbi_cost = viterbi_.decode(depuncture_buffer.stream, decode_buffer.stream); to_byte_array(decode_buffer.stream, output_buffer.stream); @@ -311,7 +311,7 @@ struct M17FrameDecoder DecodeResult decode_packet(input_buffer_t& buffer, int& viterbi_cost, FrameType type) { depunctured_buffer_t depuncture_buffer; - depuncture(buffer, depuncture_buffer.packet, P3); + depuncture<368, 420, 8>(buffer, depuncture_buffer.packet, P3); viterbi_cost = viterbi_.decode(depuncture_buffer.packet, decode_buffer.packet); to_byte_array(decode_buffer.packet, output_buffer.packet); diff --git a/modemm17/M17Modulator.h b/modemm17/M17Modulator.h index 015130399..378e0817f 100644 --- a/modemm17/M17Modulator.h +++ b/modemm17/M17Modulator.h @@ -173,7 +173,7 @@ public: } std::array punctured; - auto size = puncture(encoded, punctured, P1); + auto size = puncture<488, 368, 61>(encoded, punctured, P1); if (size != 368) { qWarning() << "modemm17::M17Modulator::make_lsf: incorrect size (not 368)" << size; @@ -273,7 +273,7 @@ public: } std::array punctured; - auto size = modemm17::puncture(encoded, punctured, modemm17::P2); + auto size = modemm17::puncture<296, 272, 12>(encoded, punctured, modemm17::P2); if (size != 272) { qWarning() << "modemm17::M17Modulator::make_stream_data_frame: incorrect size (not 272)" << size; @@ -354,7 +354,7 @@ public: } std::array punctured; - auto size = puncture(encoded, punctured, P3); + auto size = puncture<420, 368, 8>(encoded, punctured, P3); if (size != 368) { qWarning() << "modemm17::M17Modulator::make_packet_frame: incorrect size (not 368)" << size; @@ -435,7 +435,7 @@ public: } std::array punctured; - auto size = puncture(encoded, punctured, P2); + auto size = puncture<402, 368, 12>(encoded, punctured, P2); if (size != 368) { qWarning() << "modemm17::M17Modulator::make_bert_frame: incorrect size (not 368)" << size; diff --git a/modemm17/Util.h b/modemm17/Util.h index 337a1b2b5..1947dadd8 100644 --- a/modemm17/Util.h +++ b/modemm17/Util.h @@ -4,6 +4,7 @@ #include #include +#include #include #include #include @@ -170,7 +171,7 @@ std::array depunctured( } template -size_t depuncture( +size_t depuncture( // FIXME: MSVC const std::array& in, std::array& out, const std::array& p @@ -190,16 +191,18 @@ size_t depuncture( { out[i] = in[index++]; } - if (pindex == P) pindex = 0; + if (pindex == P) { + pindex = 0; + } } return bit_count; } -template -size_t puncture( - const std::array& in, - std::array& out, +template +size_t puncture( // FIXME: MSVC + const std::array& in, + std::array& out, const std::array& p ) { @@ -267,30 +270,6 @@ void assign_bit_index( else reset_bit_index(input, index); } - -template -size_t puncture_bytes( - const std::array& in, - std::array& out, - const std::array& p -) -{ - size_t index = 0; - size_t pindex = 0; - size_t bit_count = 0; - for (size_t i = 0; i != IN * 8 && index != OUT * 8; ++i) - { - if (p[pindex++]) - { - assign_bit_index(out, index++, get_bit_index(in, i)); - bit_count++; - } - - if (pindex == P) pindex = 0; - } - return bit_count; -} - /** * Sign-extend an n-bit value to a specific signed integer type. */