2022-07-20 03:07:00 -04:00
|
|
|
// Copyright 2020 Mobilinkd LLC.
|
2022-06-06 21:22:18 -04:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <array>
|
|
|
|
#include <cstdint>
|
|
|
|
#include <cstddef>
|
|
|
|
|
2022-07-30 23:15:58 -04:00
|
|
|
#include "export.h"
|
2022-07-04 17:03:07 -04:00
|
|
|
namespace modemm17
|
2022-06-06 21:22:18 -04:00
|
|
|
{
|
|
|
|
|
2022-07-30 23:15:58 -04:00
|
|
|
struct MODEMM17_API M17Randomizer
|
2022-06-06 21:22:18 -04:00
|
|
|
{
|
2022-07-30 22:54:39 -04:00
|
|
|
std::array<int8_t, 368> dc_;
|
2022-06-06 21:22:18 -04:00
|
|
|
|
|
|
|
M17Randomizer()
|
|
|
|
{
|
|
|
|
size_t i = 0;
|
2022-07-30 22:54:39 -04:00
|
|
|
for (auto b : DC)
|
2022-06-06 21:22:18 -04:00
|
|
|
{
|
|
|
|
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-30 22:54:39 -04:00
|
|
|
void operator()(std::array<int8_t, 368>& frame)
|
2022-06-06 21:22:18 -04:00
|
|
|
{
|
2022-07-30 22:54:39 -04:00
|
|
|
for (size_t i = 0; i != 368; ++i)
|
2022-06-06 21:22:18 -04:00
|
|
|
{
|
|
|
|
frame[i] *= dc_[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-30 22:54:39 -04:00
|
|
|
void randomize(std::array<int8_t, 368>& frame)
|
2022-06-06 21:22:18 -04:00
|
|
|
{
|
2022-07-30 22:54:39 -04:00
|
|
|
for (size_t i = 0; i != 368; ++i)
|
2022-06-06 21:22:18 -04:00
|
|
|
{
|
|
|
|
frame[i] ^= (dc_[i] == -1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-30 22:54:39 -04:00
|
|
|
private:
|
|
|
|
static const std::array<uint8_t, 46> DC;
|
2022-06-06 21:22:18 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2022-07-04 17:03:07 -04:00
|
|
|
} // modemm17
|