1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-21 23:55:13 -05:00
sdrangel/modemm17/M17Randomizer.h

52 lines
900 B
C
Raw Normal View History

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