17 #ifndef LEANSDR_CONVOLUTIONAL_H 18 #define LEANSDR_CONVOLUTIONAL_H 32 template <
typename Tin,
41 inline u8 SYMVAL(
const hardsymbol *s) {
return *s; }
51 int run(
const Tin *pin,
const u8 remap[], decoded_byte *pout,
int nb)
58 decoded_byte byte = 0;
60 for (
int bit = 8; bit--; ++pin)
63 byte = (byte << 1) |
parity(
hist & POLY_DECONVOL);
85 template <
typename Tin,
95 inline u8 SYMVAL(
const hardsymbol *s) {
return *s; }
105 int run(
const Tin *pin,
const u8 remap[], decoded_byte *pout,
int nb)
107 if (nb & (
sizeof(Thist) - 1)) {
108 fail(
"Must deconvolve sizeof(Thist) bytes at a time");
112 unsigned long nerrors = 0;
113 int halfway = nb / 2;
114 Thist histI = inI, histQ = inQ;
123 for (
int bit=
sizeof(Thist)*8; bit--; ++pin ) {
125 histI = (histI<<1) | (iq>>1);
126 histQ = (histQ<<1) | (iq&1);
127 if ( POLY_DECONVOL & ((Tpoly)2<<(2*bit)) ) wd ^= histI;
128 if ( POLY_DECONVOL & ((Tpoly)1<<(2*bit)) ) wd ^= histQ;
129 if ( POLY_ERRORS & ((Tpoly)2<<(2*bit)) ) we ^= histI;
130 if ( POLY_ERRORS & ((Tpoly)1<<(2*bit)) ) we ^= histQ;
136 u8 iq = remap[SYMVAL(pin)]; \ 137 histI = (histI << 1) | (iq >> 1); \ 138 histQ = (histQ << 1) | (iq & 1); \ 139 if (POLY_DECONVOL & ((Tpoly)2 << (2 * bit))) \ 141 if (POLY_DECONVOL & ((Tpoly)1 << (2 * bit))) \ 143 if (POLY_ERRORS & ((Tpoly)2 << (2 * bit))) \ 145 if (POLY_ERRORS & ((Tpoly)1 << (2 * bit))) \ 150 switch (
sizeof(Thist) * 8)
152 #if 0 // Not needed yet - avoid compiler warnings 203 fail(
"Thist not supported");
207 switch (
sizeof(Thist) * 8)
209 #if 0 // Not needed yet - avoid compiler warnings 228 fail(
"Thist not supported");
248 template <
typename Thist, u
int64_t POLY1, u
int64_t POLY2>
258 void run(
const uncoded_byte *pin,
const u8 remap[],
259 hardsymbol *pout,
int count)
261 for (; count--; ++pin)
263 uncoded_byte b = *pin;
265 for (
int bit = 8; bit--; ++pout)
267 hist = (
hist >> 1) | (((b >> bit) & 1) << 6);
280 template <
typename Thist,
int HISTSIZE>
285 int bits_in, bits_out,
bps;
289 : bits_in(0), bits_out(0), bps(0),
290 hist(0), nhist(0), sersymb(0), nsersymb(0)
294 void encode(
const uncoded_byte *pin, hardsymbol *pout,
int count)
296 if (!bits_in || !bits_out || !bps) {
297 fatal(
"convol_multipoly not configured");
300 hardsymbol symbmask = (1 << bps) - 1;
302 for (; count--; ++pin)
304 uncoded_byte b = *pin;
306 for (
int bit = 8; bit--;)
308 hist = (
hist >> 1) | ((Thist)((b >> bit) & 1) << (HISTSIZE - 1));
311 if (nhist == bits_in)
313 for (
int p = 0; p < bits_out; ++p)
316 sersymb = (sersymb << 1) | b;
320 nsersymb += bits_out;
322 while (nsersymb >= bps)
324 hardsymbol s = (sersymb >> (nsersymb - bps)) & symbmask;
333 if (nhist || nsersymb) {
334 fatal(
"partial run");
347 #endif // LEANSDR_CONVOLUTIONAL_H u8 SYMVAL(const hardsymbol *s)
void run(const uncoded_byte *pin, const u8 remap[], hardsymbol *pout, int count)
int run(const Tin *pin, const u8 remap[], decoded_byte *pout, int nb)
int hamming_weight(uint8_t x)
u8 SYMVAL(const softsymbol *s)
void encode(const uncoded_byte *pin, hardsymbol *pout, int count)
u8 SYMVAL(const softsymbol *s)
int run(const Tin *pin, const u8 remap[], decoded_byte *pout, int nb)
void fatal(const char *s)
unsigned char parity(uint8_t x)
u8 SYMVAL(const hardsymbol *s)