1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-12-22 09:31:10 -05:00

Revert "M17: try to fix MSVC errors"

This reverts commit 75148f9659.
This commit is contained in:
f4exb 2022-08-02 23:42:50 +02:00
parent 2588a7faea
commit df11e10677
4 changed files with 60 additions and 78 deletions

View File

@ -44,6 +44,7 @@ struct M17FrameDecoder
M17Randomizer derandomize_;
PolynomialInterleaver<45, 92, 368> interleaver_;
Trellis<4,2> trellis_{makeTrellis<4, 2>({031,027})};
Viterbi<decltype(trellis_), 4> 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<decltype(trellis_), 4, 488, 240> 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 <<dump(output_buffer.lsf);
@ -269,10 +268,8 @@ struct M17FrameDecoder
DecodeResult decode_bert(input_buffer_t& buffer, int& viterbi_cost)
{
depunctured_buffer_t depuncture_buffer;
PunctureOps<368, 402, 12> punct;
punct.depuncture(buffer, depuncture_buffer.bert, P2);
Viterbi<decltype(trellis_), 4, 402, 197> 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<decltype(trellis_), 4, 296, 144> 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<decltype(trellis_), 4, 420, 206> 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;

View File

@ -175,8 +175,7 @@ public:
}
std::array<int8_t, 368> 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<int8_t, 272> 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<int8_t, 368> 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<int8_t, 368> 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;

View File

@ -171,62 +171,56 @@ std::array<U, M> depunctured(
}
template <size_t IN, size_t OUT, size_t P>
struct PunctureOps
size_t depuncture( // FIXME: MSVC
const std::array<int8_t, IN>& in,
std::array<int8_t, OUT>& out,
const std::array<int8_t, P>& 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<int8_t, IN_>& in,
std::array<int8_t, OUT_>& out,
const std::array<int8_t, P_>& 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<uint8_t, IN_>& in,
std::array<int8_t, OUT_>& out,
const std::array<int8_t, P_>& p
)
template <size_t IN, size_t OUT, size_t P>
size_t puncture( // FIXME: MSVC
const std::array<uint8_t, IN>& in,
std::array<int8_t, OUT>& out,
const std::array<int8_t, P>& 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 <size_t N>
constexpr bool get_bit_index(

View File

@ -91,13 +91,11 @@ constexpr auto makeCost(Trellis_ trellis)
* Soft decision Viterbi algorithm based on the trellis and LLR size.
*
*/
template <typename Trellis_, size_t LLR_, size_t IN, size_t OUT>
template <typename Trellis_, size_t LLR_ = 2>
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<std::bitset<NumStates>, 244> history_;
Viterbi(Trellis_ trellis) :
cost_(makeCost<Trellis_, LLR_>(trellis)),
nextState_(makeNextState(trellis)),
prevState_(makePrevState(trellis))
Viterbi(Trellis_ trellis)
: cost_(makeCost<Trellis_, LLR_>(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<int8_t, IN_>& in, std::array<uint8_t, OUT_>& out)
template <size_t IN, size_t OUT>
size_t decode(const std::array<int8_t, IN>& in, std::array<uint8_t, OUT>& out)
{
static_assert(sizeof(history_) >= IN / 2, "Invalid size");