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

Even more M17 library code cleanup

This commit is contained in:
f4exb 2022-07-20 09:57:59 +02:00
parent a7392ab56f
commit 3515f6a7ee
9 changed files with 60 additions and 40 deletions

View File

@ -2,7 +2,6 @@
#pragma once #pragma once
#include <bit>
#include <cstdint> #include <cstdint>
#include <cstddef> #include <cstddef>

View File

@ -4,7 +4,6 @@
#pragma once #pragma once
#include <array> #include <array>
#include <bit>
#include <cstdint> #include <cstdint>
#include <algorithm> #include <algorithm>
#include <utility> #include <utility>

View File

@ -5,7 +5,6 @@
#include <array> #include <array>
#include <cstdint> #include <cstdint>
#include <cmath> #include <cmath>
// #include <string_view> // Don't have std::span in C++17.
#include <stdexcept> #include <stdexcept>
#include <algorithm> #include <algorithm>

View File

@ -15,7 +15,6 @@
#include <algorithm> #include <algorithm>
#include <array> #include <array>
#include <functional> #include <functional>
#include <optional>
#include <tuple> #include <tuple>
#include "export.h" #include "export.h"

View File

@ -2,7 +2,6 @@
#pragma once #pragma once
#include <bit>
#include <cstdint> #include <cstdint>
#include "Util.h" #include "Util.h"

View File

@ -7,7 +7,6 @@
#include <array> #include <array>
#include <algorithm> #include <algorithm>
#include <numeric> #include <numeric>
#include <optional>
#include <tuple> #include <tuple>
namespace modemm17 namespace modemm17

View File

@ -18,18 +18,18 @@ namespace modemm17
namespace detail { namespace detail {
template<std::size_t...Is, class Tuple> // template<std::size_t...Is, class Tuple>
constexpr std::bitset<sizeof...(Is)> make_bitset(std::index_sequence<Is...>, Tuple&& tuple) // constexpr std::bitset<sizeof...(Is)> make_bitset(std::index_sequence<Is...>, Tuple&& tuple)
{ // {
constexpr auto size = sizeof...(Is); // constexpr auto size = sizeof...(Is);
std::bitset<size> result; // std::bitset<size> result;
using expand = int[]; // using expand = int[];
for (size_t i = 0; i != size; ++i) // for (size_t i = 0; i != size; ++i)
{ // {
void(expand {0, result[Is] = std::get<Is>(tuple)...}); // void(expand {0, result[Is] = std::get<Is>(tuple)...});
} // }
return result; // return result;
} // }
/** /**
* This is the max value for the LLR based on size N. * This is the max value for the LLR based on size N.
@ -104,12 +104,12 @@ constexpr std::array<std::tuple<float, std::tuple<int8_t, int8_t>>, llr_size<LLR
} }
template<class...Bools> // template<class...Bools>
constexpr auto make_bitset(Bools&&...bools) // constexpr auto make_bitset(Bools&&...bools)
{ // {
return detail::make_bitset(std::make_index_sequence<sizeof...(Bools)>(), // return detail::make_bitset(std::make_index_sequence<sizeof...(Bools)>(),
std::make_tuple(bool(bools)...)); // std::make_tuple(bool(bools)...));
} // }
inline int from_4fsk(int symbol) inline int from_4fsk(int symbol)
{ {
@ -144,7 +144,10 @@ auto llr(float sample)
} }
template <size_t M, typename T, size_t N, typename U, size_t IN> template <size_t M, typename T, size_t N, typename U, size_t IN>
auto depunctured(std::array<T, N> puncture_matrix, std::array<U, IN> in) std::array<U, M> depunctured(
std::array<T, N> puncture_matrix,
std::array<U, IN> in
)
{ {
static_assert(M % N == 0, "M must be an integer multiple of N"); static_assert(M % N == 0, "M must be an integer multiple of N");
@ -167,8 +170,11 @@ auto depunctured(std::array<T, N> puncture_matrix, std::array<U, IN> in)
} }
template <size_t IN, size_t OUT, size_t P> template <size_t IN, size_t OUT, size_t P>
size_t depuncture(const std::array<int8_t, IN>& in, size_t depuncture(
std::array<int8_t, OUT>& out, const std::array<int8_t, P>& p) 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 index = 0;
size_t pindex = 0; size_t pindex = 0;
@ -191,8 +197,11 @@ size_t depuncture(const std::array<int8_t, IN>& in,
template <typename T, size_t IN, typename U, size_t OUT, size_t P> template <typename T, size_t IN, typename U, size_t OUT, size_t P>
size_t puncture(const std::array<T, IN>& in, size_t puncture(
std::array<U, OUT>& out, const std::array<int8_t, P>& p) const std::array<T, IN>& in,
std::array<U, OUT>& out,
const std::array<int8_t, P>& p
)
{ {
size_t index = 0; size_t index = 0;
size_t pindex = 0; size_t pindex = 0;
@ -211,7 +220,10 @@ size_t puncture(const std::array<T, IN>& in,
} }
template <size_t N> template <size_t N>
constexpr bool get_bit_index(const std::array<uint8_t, N>& input, size_t index) constexpr bool get_bit_index(
const std::array<uint8_t, N>& input,
size_t index
)
{ {
auto byte_index = index >> 3; auto byte_index = index >> 3;
assert(byte_index < N); assert(byte_index < N);
@ -221,7 +233,10 @@ constexpr bool get_bit_index(const std::array<uint8_t, N>& input, size_t index)
} }
template <size_t N> template <size_t N>
void set_bit_index(std::array<uint8_t, N>& input, size_t index) void set_bit_index(
std::array<uint8_t, N>& input,
size_t index
)
{ {
auto byte_index = index >> 3; auto byte_index = index >> 3;
assert(byte_index < N); assert(byte_index < N);
@ -230,7 +245,10 @@ void set_bit_index(std::array<uint8_t, N>& input, size_t index)
} }
template <size_t N> template <size_t N>
void reset_bit_index(std::array<uint8_t, N>& input, size_t index) void reset_bit_index(
std::array<uint8_t, N>& input,
size_t index
)
{ {
auto byte_index = index >> 3; auto byte_index = index >> 3;
assert(byte_index < N); assert(byte_index < N);
@ -239,7 +257,11 @@ void reset_bit_index(std::array<uint8_t, N>& input, size_t index)
} }
template <size_t N> template <size_t N>
void assign_bit_index(std::array<uint8_t, N>& input, size_t index, bool value) void assign_bit_index(
std::array<uint8_t, N>& input,
size_t index,
bool value
)
{ {
if (value) set_bit_index(input, index); if (value) set_bit_index(input, index);
else reset_bit_index(input, index); else reset_bit_index(input, index);
@ -247,8 +269,11 @@ void assign_bit_index(std::array<uint8_t, N>& input, size_t index, bool value)
template <size_t IN, size_t OUT, size_t P> template <size_t IN, size_t OUT, size_t P>
size_t puncture_bytes(const std::array<uint8_t, IN>& in, size_t puncture_bytes(
std::array<uint8_t, OUT>& out, const std::array<int8_t, P>& p) 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 index = 0;
size_t pindex = 0; size_t pindex = 0;
@ -298,7 +323,10 @@ constexpr auto to_byte_array(std::array<T, N> in)
} }
template <typename T, size_t N> template <typename T, size_t N>
constexpr void to_byte_array(std::array<T, N> in, std::array<uint8_t, (N + 7) / 8>& out) constexpr void to_byte_array(
std::array<T, N> in,
std::array<uint8_t, (N + 7) / 8>& out
)
{ {
size_t i = 0; size_t i = 0;
size_t b = 0; size_t b = 0;

View File

@ -160,7 +160,7 @@ struct Viterbi
* @return path metric for estimating BER. * @return path metric for estimating BER.
*/ */
template <size_t IN, size_t OUT> template <size_t IN, size_t OUT>
size_t decode(std::array<int8_t, IN> const& in, std::array<uint8_t, OUT>& 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"); static_assert(sizeof(history_) >= IN / 2, "Invalid size");

View File

@ -10,7 +10,6 @@
#include <iomanip> #include <iomanip>
#include <iostream> #include <iostream>
#include <iterator> #include <iterator>
#include <optional>
#include <sstream> #include <sstream>
#include <stdexcept> #include <stdexcept>
#include <string> #include <string>
@ -168,8 +167,7 @@ private:
{ {
std::string repeater = frame.substr(index, ADDRESS_LENGTH); std::string repeater = frame.substr(index, ADDRESS_LENGTH);
index += ADDRESS_LENGTH; index += ADDRESS_LENGTH;
more = fixup_address(repeater) more = fixup_address(repeater) && ((index + ADDRESS_LENGTH) < frame.length());
and (index + ADDRESS_LENGTH) < frame.length();
result.push_back(repeater); result.push_back(repeater);
} }