From 75148f9659084ab9ca7a3d4d8b15ce8475849716 Mon Sep 17 00:00:00 2001 From: f4exb Date: Tue, 2 Aug 2022 05:56:40 +0200 Subject: [PATCH] M17: try to fix MSVC errors --- modemm17/M17FrameDecoder.h | 25 +++++++---- modemm17/M17Modulator.h | 12 ++++-- modemm17/Util.h | 86 ++++++++++++++++++++------------------ modemm17/Viterbi.h | 15 +++---- 4 files changed, 78 insertions(+), 60 deletions(-) diff --git a/modemm17/M17FrameDecoder.h b/modemm17/M17FrameDecoder.h index ed9c033b7..8aa848c3c 100644 --- a/modemm17/M17FrameDecoder.h +++ b/modemm17/M17FrameDecoder.h @@ -44,7 +44,6 @@ 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 }; @@ -154,8 +153,10 @@ struct M17FrameDecoder DecodeResult decode_lsf(input_buffer_t& buffer, int& viterbi_cost) { depunctured_buffer_t depuncture_buffer; - depuncture<368, 488, 61>(buffer, depuncture_buffer.lsf, P1); - viterbi_cost = viterbi_.decode(depuncture_buffer.lsf, decode_buffer.lsf); + 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); to_byte_array(decode_buffer.lsf, output_buffer.lsf); // qDebug() << "modemm17::M17FrameDecoder::decode_lsf: vierbi:" << viterbi_cost <(buffer, depuncture_buffer.bert, P2); - viterbi_cost = viterbi_.decode(depuncture_buffer.bert, decode_buffer.bert); + PunctureOps<368, 402, 12> punct; + punct.depuncture(buffer, depuncture_buffer.bert, P2); + Viterbi viterbi_bert{trellis_}; + viterbi_cost = viterbi_bert.decode(depuncture_buffer.bert, decode_buffer.bert); to_byte_array(decode_buffer.bert, output_buffer.bert); output_buffer.type = FrameType::BERT; @@ -284,8 +287,10 @@ struct M17FrameDecoder std::copy(buffer.begin() + 96, buffer.end(), tmp.begin()); depunctured_buffer_t depuncture_buffer; - depuncture<272, 296, 12>(tmp, depuncture_buffer.stream, P2); - viterbi_cost = viterbi_.decode(depuncture_buffer.stream, decode_buffer.stream); + 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); to_byte_array(decode_buffer.stream, output_buffer.stream); if ((viterbi_cost < 60) && (output_buffer.stream[0] & 0x80)) @@ -311,8 +316,10 @@ struct M17FrameDecoder DecodeResult decode_packet(input_buffer_t& buffer, int& viterbi_cost, FrameType type) { depunctured_buffer_t depuncture_buffer; - depuncture<368, 420, 8>(buffer, depuncture_buffer.packet, P3); - viterbi_cost = viterbi_.decode(depuncture_buffer.packet, decode_buffer.packet); + 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); to_byte_array(decode_buffer.packet, output_buffer.packet); output_buffer.type = type; diff --git a/modemm17/M17Modulator.h b/modemm17/M17Modulator.h index 3e3959db1..b6860df2a 100644 --- a/modemm17/M17Modulator.h +++ b/modemm17/M17Modulator.h @@ -175,7 +175,8 @@ public: } std::array punctured; - auto size = puncture<488, 368, 61>(encoded, punctured, P1); + PunctureOps<488, 368, 61> punct; + auto size = punct.puncture(encoded, punctured, P1); if (size != 368) { qWarning() << "modemm17::M17Modulator::make_lsf: incorrect size (not 368)" << size; @@ -275,7 +276,8 @@ public: } std::array punctured; - auto size = modemm17::puncture<296, 272, 12>(encoded, punctured, modemm17::P2); + modemm17::PunctureOps<296, 272, 12> punct; + auto size = punct.puncture(encoded, punctured, modemm17::P2); if (size != 272) { qWarning() << "modemm17::M17Modulator::make_stream_data_frame: incorrect size (not 272)" << size; @@ -356,7 +358,8 @@ public: } std::array punctured; - auto size = puncture<420, 368, 8>(encoded, punctured, P3); + PunctureOps<420, 368, 8> punct; + auto size = punct.puncture(encoded, punctured, P3); if (size != 368) { qWarning() << "modemm17::M17Modulator::make_packet_frame: incorrect size (not 368)" << size; @@ -437,7 +440,8 @@ public: } std::array punctured; - auto size = puncture<402, 368, 12>(encoded, punctured, P2); + PunctureOps<402, 368, 12> punct; + auto size = punct.puncture(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 1947dadd8..b01c4b003 100644 --- a/modemm17/Util.h +++ b/modemm17/Util.h @@ -171,56 +171,62 @@ std::array depunctured( } template -size_t depuncture( // FIXME: MSVC - const std::array& in, - std::array& out, - const std::array& p -) +struct PunctureOps { - size_t index = 0; - size_t pindex = 0; - size_t bit_count = 0; - for (size_t i = 0; i != OUT && index < IN; ++i) + 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 + ) { - if (!p[pindex++]) + size_t index = 0; + size_t pindex = 0; + size_t bit_count = 0; + for (size_t i = 0; i != OUT && index < IN; ++i) { - out[i] = 0; - bit_count++; - } - else - { - out[i] = in[index++]; - } - if (pindex == P) { - pindex = 0; + if (!p[pindex++]) + { + out[i] = 0; + bit_count++; + } + else + { + out[i] = in[index++]; + } + if (pindex == P) { + pindex = 0; + } } + return bit_count; } - return bit_count; -} - -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 puncture( // FIXME: MSVC + const std::array& in, + std::array& out, + const std::array& p + ) { - if (p[pindex++]) + size_t index = 0; + size_t pindex = 0; + size_t bit_count = 0; + for (size_t i = 0; i != IN && index != OUT; ++i) { - out[index++] = in[i]; - bit_count++; - } + if (p[pindex++]) + { + out[index++] = in[i]; + bit_count++; + } - if (pindex == P) pindex = 0; + if (pindex == P) pindex = 0; + } + return bit_count; } - return bit_count; -} +}; + template constexpr bool get_bit_index( diff --git a/modemm17/Viterbi.h b/modemm17/Viterbi.h index 4058486f2..da4b3e8ed 100644 --- a/modemm17/Viterbi.h +++ b/modemm17/Viterbi.h @@ -91,11 +91,13 @@ 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; @@ -119,10 +121,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( @@ -159,8 +161,7 @@ struct Viterbi * * @return path metric for estimating BER. */ - template - size_t decode(const std::array& in, std::array& out) + size_t decode(const std::array& in, std::array& out) { static_assert(sizeof(history_) >= IN / 2, "Invalid size");