sdrangel/modemm17/M17Randomizer.h

52 wiersze
900 B
C
Czysty Zwykły widok Historia

2022-07-20 07:07:00 +00:00
// Copyright 2020 Mobilinkd LLC.
#pragma once
#include <array>
#include <cstdint>
#include <cstddef>
2022-07-31 03:15:58 +00:00
#include "export.h"
2022-07-04 21:03:07 +00:00
namespace modemm17
{
2022-07-31 03:15:58 +00:00
struct MODEMM17_API M17Randomizer
{
2022-07-31 02:54:39 +00:00
std::array<int8_t, 368> dc_;
M17Randomizer()
{
size_t i = 0;
2022-07-31 02:54:39 +00:00
for (auto b : DC)
{
for (size_t j = 0; j != 8; ++j)
{
dc_[i++] = (b >> (7 - j)) & 1 ? -1 : 1;
}
}
}
// Randomize and derandomize are the same operation.
2022-07-31 02:54:39 +00:00
void operator()(std::array<int8_t, 368>& frame)
{
2022-07-31 02:54:39 +00:00
for (size_t i = 0; i != 368; ++i)
{
frame[i] *= dc_[i];
}
}
2022-07-31 02:54:39 +00:00
void randomize(std::array<int8_t, 368>& frame)
{
2022-07-31 02:54:39 +00:00
for (size_t i = 0; i != 368; ++i)
{
frame[i] ^= (dc_[i] == -1);
}
}
2022-07-31 02:54:39 +00:00
private:
static const std::array<uint8_t, 46> DC;
};
2022-07-04 21:03:07 +00:00
} // modemm17