1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-21 23:55:13 -05:00
sdrangel/modemm17/M17Randomizer.h
2022-07-31 05:15:58 +02:00

52 lines
900 B
C++

// Copyright 2020 Mobilinkd LLC.
#pragma once
#include <array>
#include <cstdint>
#include <cstddef>
#include "export.h"
namespace modemm17
{
struct MODEMM17_API M17Randomizer
{
std::array<int8_t, 368> dc_;
M17Randomizer()
{
size_t i = 0;
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.
void operator()(std::array<int8_t, 368>& frame)
{
for (size_t i = 0; i != 368; ++i)
{
frame[i] *= dc_[i];
}
}
void randomize(std::array<int8_t, 368>& frame)
{
for (size_t i = 0; i != 368; ++i)
{
frame[i] ^= (dc_[i] == -1);
}
}
private:
static const std::array<uint8_t, 46> DC;
};
} // modemm17