M17: Util code cleanup

pull/1370/head
f4exb 2022-07-31 04:24:03 +02:00
rodzic 8e1d5a3bbd
commit ca24d1bc57
3 zmienionych plików z 17 dodań i 38 usunięć

Wyświetl plik

@ -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);

Wyświetl plik

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

Wyświetl plik

@ -4,6 +4,7 @@
#include <algorithm>
#include <cstdlib>
#include <cstdint>
#include <cassert>
#include <array>
#include <bitset>
@ -170,7 +171,7 @@ std::array<U, M> depunctured(
}
template <size_t IN, size_t OUT, size_t P>
size_t depuncture(
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
@ -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 <typename T, size_t IN, typename U, size_t OUT, size_t P>
size_t puncture(
const std::array<T, IN>& in,
std::array<U, OUT>& out,
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
)
{
@ -267,30 +270,6 @@ void assign_bit_index(
else reset_bit_index(input, index);
}
template <size_t IN, size_t OUT, size_t P>
size_t puncture_bytes(
const std::array<uint8_t, IN>& in,
std::array<uint8_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 * 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.
*/