From df11e106774ff03bb7a4d800979aa5946f7f46a0 Mon Sep 17 00:00:00 2001 From: f4exb Date: Tue, 2 Aug 2022 23:42:50 +0200 Subject: [PATCH] Revert "M17: try to fix MSVC errors" This reverts commit 75148f9659084ab9ca7a3d4d8b15ce8475849716. --- modemm17/M17FrameDecoder.h | 25 ++++------- modemm17/M17Modulator.h | 12 ++---- modemm17/Util.h | 86 ++++++++++++++++++-------------------- modemm17/Viterbi.h | 15 ++++--- 4 files changed, 60 insertions(+), 78 deletions(-) diff --git a/modemm17/M17FrameDecoder.h b/modemm17/M17FrameDecoder.h index 8aa848c3c..ed9c033b7 100644 --- a/modemm17/M17FrameDecoder.h +++ b/modemm17/M17FrameDecoder.h @@ -44,6 +44,7 @@ struct M17FrameDecoder M17Randomizer derandomize_; PolynomialInterleaver<45, 92, 368> interleaver_; Trellis<4,2> trellis_{makeTrellis<4, 2>({031,027})}; + Viterbi viterbi_{trellis_}; CRC16 crc_; enum class State { LSF, STREAM, BASIC_PACKET, FULL_PACKET, BERT }; @@ -153,10 +154,8 @@ struct M17FrameDecoder DecodeResult decode_lsf(input_buffer_t& buffer, int& viterbi_cost) { depunctured_buffer_t depuncture_buffer; - PunctureOps<368, 488, 61> punct; - punct.depuncture(buffer, depuncture_buffer.lsf, P1); - Viterbi viterbi_lsf{trellis_}; - viterbi_cost = viterbi_lsf.decode(depuncture_buffer.lsf, decode_buffer.lsf); + 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); // qDebug() << "modemm17::M17FrameDecoder::decode_lsf: vierbi:" << viterbi_cost < punct; - punct.depuncture(buffer, depuncture_buffer.bert, P2); - Viterbi viterbi_bert{trellis_}; - viterbi_cost = viterbi_bert.decode(depuncture_buffer.bert, decode_buffer.bert); + 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); output_buffer.type = FrameType::BERT; @@ -287,10 +284,8 @@ struct M17FrameDecoder std::copy(buffer.begin() + 96, buffer.end(), tmp.begin()); depunctured_buffer_t depuncture_buffer; - PunctureOps<272, 296, 12> punct; - punct.depuncture(tmp, depuncture_buffer.stream, P2); - Viterbi viterbi_stream{trellis_}; - viterbi_cost = viterbi_stream.decode(depuncture_buffer.stream, decode_buffer.stream); + 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); if ((viterbi_cost < 60) && (output_buffer.stream[0] & 0x80)) @@ -316,10 +311,8 @@ struct M17FrameDecoder DecodeResult decode_packet(input_buffer_t& buffer, int& viterbi_cost, FrameType type) { depunctured_buffer_t depuncture_buffer; - PunctureOps<368, 420, 8> punct; - punct.depuncture(buffer, depuncture_buffer.packet, P3); - Viterbi viterbi_packet{trellis_}; - viterbi_cost = viterbi_packet.decode(depuncture_buffer.packet, decode_buffer.packet); + 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); output_buffer.type = type; diff --git a/modemm17/M17Modulator.h b/modemm17/M17Modulator.h index b6860df2a..3e3959db1 100644 --- a/modemm17/M17Modulator.h +++ b/modemm17/M17Modulator.h @@ -175,8 +175,7 @@ public: } std::array punctured; - PunctureOps<488, 368, 61> punct; - auto size = punct.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; @@ -276,8 +275,7 @@ public: } std::array punctured; - modemm17::PunctureOps<296, 272, 12> punct; - auto size = punct.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; @@ -358,8 +356,7 @@ public: } std::array punctured; - PunctureOps<420, 368, 8> punct; - auto size = punct.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; @@ -440,8 +437,7 @@ public: } std::array punctured; - PunctureOps<402, 368, 12> punct; - auto size = punct.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 b01c4b003..1947dadd8 100644 --- a/modemm17/Util.h +++ b/modemm17/Util.h @@ -171,62 +171,56 @@ std::array depunctured( } template -struct PunctureOps +size_t depuncture( // FIXME: MSVC + const std::array& in, + std::array& out, + const std::array& p +) { - static constexpr size_t IN_ = IN; - static constexpr size_t OUT_ = OUT; - static constexpr size_t P_ = P; - - size_t depuncture( // FIXME: MSVC - 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 != OUT && index < IN; ++i) { - size_t index = 0; - size_t pindex = 0; - size_t bit_count = 0; - for (size_t i = 0; i != OUT && index < IN; ++i) + if (!p[pindex++]) { - if (!p[pindex++]) - { - out[i] = 0; - bit_count++; - } - else - { - out[i] = in[index++]; - } - if (pindex == P) { - pindex = 0; - } + out[i] = 0; + bit_count++; + } + else + { + out[i] = in[index++]; + } + if (pindex == P) { + pindex = 0; } - return bit_count; } + return bit_count; +} - size_t puncture( // FIXME: MSVC - const std::array& in, - std::array& out, - const std::array& p - ) + +template +size_t puncture( // FIXME: MSVC + 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 && index != OUT; ++i) { - size_t index = 0; - size_t pindex = 0; - size_t bit_count = 0; - for (size_t i = 0; i != IN && index != OUT; ++i) + if (p[pindex++]) { - if (p[pindex++]) - { - out[index++] = in[i]; - bit_count++; - } - - if (pindex == P) pindex = 0; + out[index++] = in[i]; + bit_count++; } - return bit_count; - } -}; + if (pindex == P) pindex = 0; + } + return bit_count; +} template constexpr bool get_bit_index( diff --git a/modemm17/Viterbi.h b/modemm17/Viterbi.h index da4b3e8ed..4058486f2 100644 --- a/modemm17/Viterbi.h +++ b/modemm17/Viterbi.h @@ -91,13 +91,11 @@ constexpr auto makeCost(Trellis_ trellis) * Soft decision Viterbi algorithm based on the trellis and LLR size. * */ -template +template struct Viterbi { static_assert(LLR_ < 7, "Need to be < 7 to avoid overflow errors"); - static constexpr size_t IN_ = IN; - static constexpr size_t OUT_ = OUT; static constexpr size_t K = Trellis_::K; static constexpr size_t k = Trellis_::k; static constexpr size_t n = Trellis_::n; @@ -121,10 +119,10 @@ struct Viterbi // because of a static assertion in the decode() function. std::array, 244> history_; - Viterbi(Trellis_ trellis) : - cost_(makeCost(trellis)), - nextState_(makeNextState(trellis)), - prevState_(makePrevState(trellis)) + Viterbi(Trellis_ trellis) + : cost_(makeCost(trellis)) + , nextState_(makeNextState(trellis)) + , prevState_(makePrevState(trellis)) {} void calculate_path_metric( @@ -161,7 +159,8 @@ struct Viterbi * * @return path metric for estimating BER. */ - size_t decode(const std::array& in, std::array& out) + template + size_t decode(const std::array& in, std::array& out) { static_assert(sizeof(history_) >= IN / 2, "Invalid size");