FEC.cpp
Go to the documentation of this file.
1 /*
2  * This code appears to be mostly copied from with some additional minor
3  * code provided by Michael Thompson.
4  *
5  * http://www.piclist.com/techref/method/error/rs-gp-pk-uoh-199609/rs_c.htm
6  *
7  * This code claims to be written by Phil Karns in 1996. The code at that
8  * site unfortunately has no license in it.
9  *
10  * The most current version of Phil's library (fec-3.0.1) is at:
11  *
12  * http://www.ka9q.net/code/fec/
13  *
14  * The fec-3.0.1 library (August 7, 2007) is distributed under LPGL.
15  *
16  * By the time I got the the code, it appears that Michael Thompson had
17  * attached a GNU Public License to it all. Given that Phil Karn is
18  * distributing his latest code under the GNU LGPL, my assumption is
19  * that his older code is actually distributed under LGPL. So I have
20  * removed the GPL and I have reattached the LGPL back onto this code
21  * (see end of this file.)
22  *
23  * Wayne C. Gramlich
24  * September 17, 2010
25  */
26 
27 /*
28  This code implements general purpose Reed-Solomon forward error correction
29  algorithm for buffers of 3-bit to 8-bit symbols. It is a based on code by
30  Phil Karn, which is in turn a rewrite of code by Robert Morelos-Zaragoza
31  and Hari Thirumoorthy, which was in turn based on an earlier program by
32  Simon Rockliff. Further information on Phil Karn's implementation can be
33  found at:
34 
35  http://www.piclist.com/techref/method/error/rs-gp-pk-uoh-199609/index.htm
36 
37  This code is woefully undocumented and uncommented. Hopefully someone
38  who can understand the math within the Reed Solomon algorithm can comment
39  and optimize this code further.
40 */
41 
42 #include <stdlib.h>
43 #include <alloca.h>
44 
45 #include "FEC.hpp"
46 
47 // No legal value in index form represents zero, so
48 // we use nn as a special value for this purpose.
49 #define ALPHA_ZERO ((uintGF) self->nn)
50 
51 // Alpha exponent for the first root of the generator polynomial.
52 #define ALPHA_ROOT 1
53 
54 // Helper macro to find minimum value.
55 #define MIN(a,b) (((a) < (b)) ? (a) : (b))
56 
57 // Primitive polynomial tables. See Lin & Costello, Error Control Coding
58 // Appendix A and Lee & Messerschmitt, Digital Communication p. 453.
59 
60 // 1 + x + x^3
61 rvUint8 pp_3[4] = { 1, 1, 0, 1 };
62 
63 // 1 + x + x^4
64 rvUint8 pp_4[5] = { 1, 1, 0, 0, 1 };
65 
66 // 1 + x^2 + x^5
67 rvUint8 pp_5[6] = { 1, 0, 1, 0, 0, 1 };
68 
69 // 1 + x + x^6
70 rvUint8 pp_6[7] = { 1, 1, 0, 0, 0, 0, 1 };
71 
72 // 1 + x^3 + x^7
73 rvUint8 pp_7[8] = { 1, 0, 0, 1, 0, 0, 0, 1 };
74 
75 // 1+x^2+x^3+x^4+x^8
76 rvUint8 pp_8[9] = { 1, 0, 1, 1, 1, 0, 0, 0, 1 };
77 
78 #if 0
79 // The following primitive polynomial tables are currently unused, but
80 // copied here for future reference.
81 
82 // 1+x^4+x^9
83 rvUint8 pp_9[10] = { 1, 0, 0, 0, 1, 0, 0, 0, 0, 1 };
84 
85 // 1+x^3+x^10
86 rvUint8 pp_10[11] = { 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1 };
87 
88 // 1+x^2+x^11
89 rvUint8 pp_11[12] = { 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1 };
90 
91 // 1+x+x^4+x^6+x^12
92 rvUint8 pp_12[13] = { 1, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1 };
93 
94 // 1+x+x^3+x^4+x^13
95 rvUint8 pp_13[14] = { 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1 };
96 
97 // 1+x+x^6+x^10+x^14
98 rvUint8 pp_14[15] = { 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1 };
99 
100 // 1+x+x^15
101 rvUint8 pp_15[16] = { 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 };
102 
103 // 1+x+x^3+x^12+x^16
104 rvUint8 pp_16[17] = { 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1 };
105 #endif
106 
107 // Helper macro to compute x mod nn.
108 #define modnn(x) ((x) % self->nn)
109 
110 static void rvFec_InitGaloisField(rvFec* self, rvUint8 *pp)
111 // Initialize GF(2**mm) table from the irreducible polynomial p(X) in pp[0]..pp[MM - 1].
112 //
113 // The following tables are created:
114 //
115 // index form to polynomial form alphaTo[] contains j=alpha**i;
116 // polynomial form to index form indexOf[j=alpha**i] = i
117 //
118 // The representation of the elements of GF(2**mm) is either in index form,
119 // where the number is the power of the primitive element alpha, which is
120 // convenient for multiplication (add the powers modulo 2**mm-1) or in
121 // polynomial form, where the bits represent the coefficients of the
122 // polynomial representation of the number, which is the most convenient form
123 // for addition. The two forms are swapped between via lookup tables.
124 // This leads to fairly messy looking expressions, but unfortunately, there
125 // is no easy alternative when working with Galois arithmetic.
126 {
127  rvUint16 i;
128  rvUint16 mask;
129 
130  // Local references so code is easier on the eyes.
131  uintGF mm = (uintGF) self->mm;
132  uintGF nn = (uintGF) self->nn;
133  uintGF *alphaTo = self->alphaTo;
134  uintGF *indexOf = self->indexOf;
135 
136  mask = 1;
137  alphaTo[mm] = 0;
138  for (i = 0; i < mm; i++) {
139  alphaTo[i] = (uintGF) mask;
140  indexOf[alphaTo[i]] = (uintGF) i;
141  if (pp[i] != 0) {
142  alphaTo[mm] ^= (uintGF) mask;
143  }
144  mask <<= 1;
145  }
146  indexOf[alphaTo[mm]] = mm;
147  mask >>= 1;
148  for (i = mm + 1; i < nn; i++) {
149  if (alphaTo[i - 1] >= mask) {
150  alphaTo[i] = alphaTo[mm] ^ ((alphaTo[i - 1] ^ mask) << 1);
151  } else {
152  alphaTo[i] = alphaTo[i - 1] << 1;
153  }
154  indexOf[alphaTo[i]] = (uintGF) i;
155  }
156  indexOf[0] = ALPHA_ZERO;
157  alphaTo[nn] = 0;
158 }
159 
160 
161 static void
163  rvFec* self)
164 {
165  // Initialize the generator polynomial table.
166  rvInt16 i;
167  rvInt16 j;
168 
169  // Local references so code is easier on the eyes.
170  uintGF *gg = self->gg;
171  uintGF *alphaTo = self->alphaTo;
172  uintGF *indexOf = self->indexOf;
173 
174  gg[0] = alphaTo[ALPHA_ROOT];
175  gg[1] = 1;
176  for (i = 2; i <= self->paritySize; i++) {
177  gg[i] = 1;
178  for (j = i - 1; j > 0; --j) {
179  if (gg[j] != 0) {
180  gg[j] = gg[j - 1] ^
181  alphaTo[modnn((indexOf[gg[j]]) + ALPHA_ROOT + i - 1)];
182  } else {
183  gg[j] = gg[j - 1];
184  }
185  }
186  gg[0] = alphaTo[modnn((indexOf[gg[0]]) + ALPHA_ROOT + i - 1)];
187  }
188 
189  // Convert gg[] to index form for quicker encoding.
190  for (i = 0; i <= self->paritySize; i++) {
191  gg[i] = indexOf[gg[i]];
192  }
193 }
194 
195 
196 rvFec* rvFec_New(rvInt16 symbolSize, rvInt16 dataSize, rvInt16 paritySize)
197 // Initialize the encoder object.
198 {
199  rvInt16 mm;
200  rvInt16 nn;
201  rvInt16 kk;
202  rvInt16 zeroSize;
203  rvInt16 blockSize;
204  rvUint8* pp = NULL;
205  uintGF* gg = NULL;
206  uintGF* alphaTo = NULL;
207  uintGF* indexOf = NULL;
208  rvFec* self = NULL;
209 
210  // Set the Reed Solomon properties.
211  mm = symbolSize;
212  nn = ((1 << mm) - 1);
213  kk = nn - paritySize;
214 
215  // The block size is the combined data and parity size.
216  blockSize = dataSize + paritySize;
217 
218  // The zero size is the size of the zero padded data.
219  zeroSize = nn - blockSize;
220 
221  // Sanity check block and data size.
222  if ((blockSize < 1) || (blockSize > nn)) return NULL;
223  if ((dataSize < 1) || (dataSize >= blockSize)) return NULL;
224 
225  // Point to primative polynomial table.
226  if (symbolSize == 3) pp = pp_3;
227  else if (symbolSize == 4) pp = pp_4;
228  else if (symbolSize == 5) pp = pp_5;
229  else if (symbolSize == 6) pp = pp_6;
230  else if (symbolSize == 7) pp = pp_7;
231  else if (symbolSize == 8) pp = pp_8;
232  else return NULL;
233 
234  // Allocate a new ecc object and tables.
235  self = (rvFec *) malloc(sizeof(rvFec));
236  gg = (uintGF*) malloc(sizeof(uintGF) * (paritySize + 1));
237  alphaTo = (uintGF*) malloc(sizeof(uintGF) * (nn + 1));
238  indexOf = (uintGF*) malloc(sizeof(uintGF) * (nn + 1));
239 
240  // Did we allocate the object.
241  if ((self != NULL) && (gg != NULL) &&
242  (alphaTo != NULL) && (indexOf != NULL)) {
243  // Set the Reed Solomon properties.
244  self->mm = mm;
245  self->nn = nn;
246  self->kk = kk;
247 
248  // Set the buffer properties.
249  self->zeroSize = zeroSize;
250  self->dataSize = dataSize;
251  self->paritySize = paritySize;
252  self->blockSize = blockSize;
253 
254  // Set the allocated tables.
255  self->gg = gg;
256  self->alphaTo = alphaTo;
257  self->indexOf = indexOf;
258 
259  // Initialize Galois Field table
260  rvFec_InitGaloisField(self, pp);
261 
262  // Initialize generator polynomial.
263  rvFec_InitPolynomial(self);
264  } else {
265  // Clean up.
266  if (self) free(self);
267  if (gg) free(gg);
268  if (alphaTo) free(alphaTo);
269  if (indexOf) free(indexOf);
270  }
271 
272  return self;
273 }
274 
275 
276 rvInt16 rvFec_Parity(rvFec* self, rvUint8* dataBuffer, rvUint8* parityBuffer)
277 // Encode parity for the data buffer. Returns 1 if success or 0 if
278 // unable to encode. Encoding is done by using a feedback shift register
279 // with appropriate connections specified by the elements of gg[], which
280 // was generated by the ecc_generate_galois_field() function.
281 {
282  rvInt16 i;
283  rvInt16 j;
284  uintGF feedback;
285 
286  // Local references so code is easier on the eyes.
287  uintGF *gg = self->gg;
288  uintGF *alphaTo = self->alphaTo;
289  uintGF *indexOf = self->indexOf;
290 
291  // Zero the parity data.
292  for (i = 0; i < self->paritySize; ++i) parityBuffer[i] = 0;
293 
294  // Loop over the data portion of the encode buffer.
295  for (i = self->zeroSize + self->dataSize; i >= 0; --i) {
296  // Pad data with zero to account for shortened buffer when
297  // determining feedback.
298  feedback =
299  indexOf[((i >= self->zeroSize) ? dataBuffer[i - self->zeroSize] : 0) ^
300  parityBuffer[self->paritySize - 1]];
301 
302  // Is the feedback term non-zero?
303  if (feedback != ALPHA_ZERO) {
304  for (j = self->paritySize - 1; j > 0; --j) {
305  if (gg[j] != ALPHA_ZERO) {
306  parityBuffer[j] =
307  parityBuffer[j - 1] ^ alphaTo[modnn(gg[j] + feedback)];
308  } else {
309  parityBuffer[j] = parityBuffer[j - 1];
310  }
311  }
312  parityBuffer[0] = alphaTo[modnn(gg[0] + feedback)];
313  } else {
314  for (j = self->paritySize - 1; j > 0; --j) {
315  parityBuffer[j] = parityBuffer[j - 1];
316  }
317  parityBuffer[0] = 0;
318  }
319  }
320 
321  return 1;
322 }
323 
324 
325 rvInt16 rvFec_Correct(rvFec* self, rvUint8* blockBuffer)
326 // Correct the block buffer. Returns 1 if success or 0 if unable to correct.
327 {
328  rvInt16 i;
329  rvInt16 j;
330  rvInt16 r;
331  rvInt16 el;
332  rvInt16 count;
333  rvInt16 syn_error;
334  rvInt16 deg_omega;
335  rvInt16 deg_lambda;
336  rvInt16 *loc;
337  uintGF q;
338  uintGF *b;
339  uintGF *t;
340  uintGF *reg;
341  uintGF *recd;
342  uintGF *root;
343  uintGF *omega;
344  uintGF *lambda;
345  uintGF *syndromes;
346 
347  // Local references so code is easier on the eyes.
348  rvInt16 nn = self->nn;
349  uintGF *gg = self->gg;
350  uintGF *alphaTo = self->alphaTo;
351  uintGF *indexOf = self->indexOf;
352 
353  // Allocate the recieve buffer off the stack.
354  recd = (uintGF*) alloca(sizeof(uintGF) * nn);
355 
356  // Copy and convert the encoded buffer from polynomial form to index form.
357  for (i = nn - 1; i >= 0; --i) {
358  // Pad data with zero to account for shortened buffer.
359  recd[i] =
360  indexOf[(i >= self->zeroSize) ? blockBuffer[i - self->zeroSize] : 0];
361  }
362 
363  // Allocate the syndromes buffer off the stack.
364  syndromes = (uintGF*) alloca(sizeof(uintGF) * (self->paritySize + 1));
365 
366  // Initialize the syndrome error flag.
367  syn_error = 0;
368 
369  // Form and store each syndrome by evaluating recd(x) at roots of g(x)
370  // namely @**(ALPHA_ROOT+i), i = 0, ... ,(nn-KK-1)
371  for (i = 1; i <= self->paritySize; i++) {
372  uintGF syndrome = 0;
373 
374  // Loop over each data byte.
375  for (j = 0; j < nn; j++) {
376  // All non-zero receive values added to the syndrome.
377  if (recd[j] != ALPHA_ZERO) {
378  syndrome ^= alphaTo[modnn(recd[j] + (ALPHA_ROOT + i - 1) * j)];
379  }
380  }
381 
382  // Set flag if non-zero syndrome.
383  syn_error |= syndrome;
384 
385  // Store syndrome in index form.
386  syndromes[i] = indexOf[syndrome];
387  }
388 
389  if (!syn_error) {
390  // If all syndromes are zero there are no errors to correct.
391  return 1;
392  }
393 
394  // Allocate the lambda buffer off the stack.
395  lambda = (uintGF*) alloca(sizeof(uintGF) * (self->paritySize + 1));
396 
397  // Clear the lampda buffer.
398  for (i = 1; i < self->paritySize + 1; ++i) lambda[i] = 0;
399 
400  lambda[0] = 1;
401 
402  b = (uintGF*) alloca(sizeof(uintGF) * (self->paritySize + 1));
403  t = (uintGF*) alloca(sizeof(uintGF) * (self->paritySize + 1));
404 
405  for (i = 0; i < self->paritySize + 1; i++) {
406  b[i] = indexOf[lambda[i]];
407  }
408 
409  // Begin Berlekamp-Massey algorithm to determine error locator polynomial.
410  el = 0;
411 
412  for (r = 1; r <= self->paritySize; ++r) {
413  uintGF discrepancy = 0;
414 
415  // Compute discrepancy at the r-th step in poly-form.
416  for (i = 0; i < r; i++) {
417  if ((lambda[i] != 0) && (syndromes[r - i] != ALPHA_ZERO)) {
418  discrepancy ^=
419  alphaTo[modnn(indexOf[lambda[i]] + syndromes[r - i])];
420  }
421  }
422 
423  // Convert the discrepancy to index form.
424  discrepancy = indexOf[discrepancy];
425 
426  // Is the discrepancy zero?
427  if (discrepancy == ALPHA_ZERO) {
428  // Move all array elements up.
429  for (i = self->paritySize - 1; i >= 0; --i) {
430  b[i + 1] = b[i];
431  }
432 
433  // The first array element is zero.
434  b[0] = ALPHA_ZERO;
435  } else {
436  // 7 lines below: T(x) <-- lambda(x) - discrepancy*x*b(x)
437  t[0] = lambda[0];
438 
439  for (i = 0 ; i < self->paritySize; i++) {
440  if (b[i] != ALPHA_ZERO) {
441  t[i+1] = lambda[i+1] ^ alphaTo[modnn(discrepancy + b[i])];
442  } else {
443  t[i+1] = lambda[i+1];
444  }
445  }
446 
447  if ((2 * el) <= (r - 1)) {
448  el = r - el;
449 
450  // 2 lines below: B(x) <-- inv(discrepancy) * lambda(x)
451  for (i = 0; i <= self->paritySize; i++) {
452  b[i] = (lambda[i] == 0) ? ALPHA_ZERO :
453  modnn(indexOf[lambda[i]] - discrepancy + nn);
454  }
455  } else {
456  // Move all array elements up.
457  for (i = self->paritySize - 1; i >= 0; --i) {
458  b[i + 1] = b[i];
459  }
460 
461  // The first array element is zero.
462  b[0] = ALPHA_ZERO;
463  }
464 
465  for (i = 0; i < self->paritySize + 1; ++i) lambda[i] = t[i];
466  }
467  }
468 
469  deg_lambda = 0;
470 
471  // Convert lambda to index form and compute deg(lambda(x)).
472  for (i = 0; i < self->paritySize + 1; ++i) {
473  lambda[i] = indexOf[lambda[i]];
474 
475  if (lambda[i] != ALPHA_ZERO) {
476  deg_lambda = i;
477  }
478  }
479 
480  loc = (rvInt16*) alloca(sizeof(rvInt16) * self->paritySize);
481  reg = (uintGF*) alloca(sizeof(uintGF) * (self->paritySize + 1));
482  root = (uintGF*) alloca(sizeof(uintGF) * self->paritySize);
483 
484  // Find roots of the error locator polynomial by Chien search.
485  for (i = 1; i < self->paritySize + 1; ++i) {
486  reg[i] = lambda[i];
487  }
488 
489  // Number of roots of lambda(x).
490  count = 0;
491 
492  for (i = 1; i <= nn; i++) {
493  q = 1;
494 
495  for (j = deg_lambda; j > 0; j--) {
496  if (reg[j] != ALPHA_ZERO) {
497  reg[j] = modnn(reg[j] + j);
498  q ^= alphaTo[reg[j]];
499  }
500  }
501 
502  if (!q) {
503  // Store root (index-form) and error location number.
504  root[count] = (uintGF) i;
505  loc[count] = nn - i;
506  count++;
507  }
508  }
509 
510 #ifdef DEBUG
511  printf("\n Final error positions:\t");
512  for (i = 0; i < count; i++) {
513  printf("%d ", loc[i]);
514  }
515  printf("\n");
516 #endif
517 
518  // If deg(lambda) unequal to number of roots then uncorrectable error
519  // detected:
520  if (deg_lambda != count) {
521  return 0;
522  }
523 
524  deg_omega = 0;
525 
526  omega = (uintGF*) alloca(sizeof(uintGF) * (self->paritySize + 1));
527 
528  // Compute error evaluator poly omega(x) =
529  // s(x) * lambda(x) (modulo x**(NN-KK))
530  // in index form. Also find deg(omega).
531  for (i = 0; i < self->paritySize; ++i) {
532  uintGF tmp = 0;
533 
534  for (j = (deg_lambda < i) ? deg_lambda : i; j >= 0; --j) {
535  if ((syndromes[i + 1 - j] != ALPHA_ZERO) &&
536  (lambda[j] != ALPHA_ZERO)) {
537  tmp ^= alphaTo[modnn(syndromes[i + 1 - j] + lambda[j])];
538  }
539  }
540 
541  if (tmp != 0) {
542  deg_omega = i;
543  }
544 
545  omega[i] = indexOf[tmp];
546  }
547 
548  omega[self->paritySize] = ALPHA_ZERO;
549 
550  // Compute error values in poly-form.
551  for (j = count - 1; j >= 0; j--) {
552  uintGF den;
553  uintGF num1;
554  uintGF num2;
555 
556  num1 = 0;
557 
558  for (i = deg_omega; i >= 0; i--) {
559  if (omega[i] != ALPHA_ZERO) {
560  num1 ^= alphaTo[modnn(omega[i] + i * root[j])];
561  }
562  }
563 
564  num2 = alphaTo[modnn(root[j] * (ALPHA_ROOT - 1) + nn)];
565 
566  den = 0;
567 
568  // lambda[i+1] for i even is the formal derivative lambda_pr
569  // of lambda[i]:
570  for (i = MIN(deg_lambda, self->paritySize - 1) & ~1; i >= 0; i -=2) {
571  if (lambda[i + 1] != ALPHA_ZERO) {
572  den ^= alphaTo[modnn(lambda[i+1] + i * root[j])];
573  }
574  }
575 
576  if (den == 0) {
577 #ifdef DEBUG
578  printf("\n ERROR: denominator = 0\n");
579 #endif
580  return 0;
581  }
582 
583  // Apply error to data.
584  if (num1 != 0) {
585  // We should never need to correct in the zero padding.
586  if (loc[j] < self->zeroSize) {
587  return 0;
588  }
589 
590  // Account for shortened data.
591  if ((loc[j] >= self->zeroSize) &&
592  (loc[j] < self->zeroSize + self->dataSize)) {
593  blockBuffer[loc[j] - self->zeroSize] ^=
594  alphaTo[modnn(indexOf[num1] + indexOf[num2] +
595  nn - indexOf[den])];
596  }
597  }
598  }
599 
600  return 1;
601 }
602 
603 bool
605  FEC fec,
606  unsigned int *data,
607  unsigned int size)
608 {
609  unsigned char data_bytes[8];
610  unsigned int index;
611  bool result;
612 
613  /* Load {data} into {data_bytes}: */
614  for (index = 0; index < size; index++) {
615  data_bytes[index] = data[index] & 0xff;
616  }
617 
618  /* Correct any errors: */
619  result = rvFec_Correct(fec, data_bytes);
620 
621  /* Load {data_bytes} into {data}: */
622  for (index = 0; index < size; index++) {
623  data[index] = data_bytes[index];
624  }
625 
626  return result;
627 }
628 
629 void
631  FEC fec,
632  unsigned int *data,
633  unsigned int size)
634 {
635  unsigned char data_bytes[8];
636  unsigned int index;
637 
638  /* Load {data} into {data_bytes}: */
639  for (index = 0; index < 8; index++) {
640  data_bytes[index] = data[index] & 0xff;
641  }
642 
643  /* Compute the parity information: */
644  rvFec_Parity(fec, data_bytes, data_bytes + 4);
645 
646  /* Load {data_bytes} into {data}: */
647  for (index = 0; index < 8; index++) {
648  data[index] = data_bytes[index];
649  }
650 }
651 
652 FEC
654  unsigned int symbol_size,
655  unsigned int data_size,
656  unsigned int parity_size)
657 {
658  return rvFec_New(symbol_size, data_size, parity_size);
659 }
660 
661 /*
662 
663  GNU LESSER GENERAL PUBLIC LICENSE
664  Version 2.1, February 1999
665 
666  Copyright (C) 1991, 1999 Free Software Foundation, Inc.
667  59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
668  Everyone is permitted to copy and distribute verbatim copies
669  of this license document, but changing it is not allowed.
670 
671 [This is the first released version of the Lesser GPL. It also counts
672  as the successor of the GNU Library Public License, version 2, hence
673  the version number 2.1.]
674 
675  Preamble
676 
677  The licenses for most software are designed to take away your
678 freedom to share and change it. By contrast, the GNU General Public
679 Licenses are intended to guarantee your freedom to share and change
680 free software--to make sure the software is free for all its users.
681 
682  This license, the Lesser General Public License, applies to some
683 specially designated software packages--typically libraries--of the
684 Free Software Foundation and other authors who decide to use it. You
685 can use it too, but we suggest you first think carefully about whether
686 this license or the ordinary General Public License is the better
687 strategy to use in any particular case, based on the explanations below.
688 
689  When we speak of free software, we are referring to freedom of use,
690 not price. Our General Public Licenses are designed to make sure that
691 you have the freedom to distribute copies of free software (and charge
692 for this service if you wish); that you receive source code or can get
693 it if you want it; that you can change the software and use pieces of
694 it in new free programs; and that you are informed that you can do
695 these things.
696 
697  To protect your rights, we need to make restrictions that forbid
698 distributors to deny you these rights or to ask you to surrender these
699 rights. These restrictions translate to certain responsibilities for
700 you if you distribute copies of the library or if you modify it.
701 
702  For example, if you distribute copies of the library, whether gratis
703 or for a fee, you must give the recipients all the rights that we gave
704 you. You must make sure that they, too, receive or can get the source
705 code. If you link other code with the library, you must provide
706 complete object files to the recipients, so that they can relink them
707 with the library after making changes to the library and recompiling
708 it. And you must show them these terms so they know their rights.
709 
710  We protect your rights with a two-step method: (1) we copyright the
711 library, and (2) we offer you this license, which gives you legal
712 permission to copy, distribute and/or modify the library.
713 
714  To protect each distributor, we want to make it very clear that
715 there is no warranty for the free library. Also, if the library is
716 modified by someone else and passed on, the recipients should know
717 that what they have is not the original version, so that the original
718 author's reputation will not be affected by problems that might be
719 introduced by others.
720 
721  Finally, software patents pose a constant threat to the existence of
722 any free program. We wish to make sure that a company cannot
723 effectively restrict the users of a free program by obtaining a
724 restrictive license from a patent holder. Therefore, we insist that
725 any patent license obtained for a version of the library must be
726 consistent with the full freedom of use specified in this license.
727 
728  Most GNU software, including some libraries, is covered by the
729 ordinary GNU General Public License. This license, the GNU Lesser
730 General Public License, applies to certain designated libraries, and
731 is quite different from the ordinary General Public License. We use
732 this license for certain libraries in order to permit linking those
733 libraries into non-free programs.
734 
735  When a program is linked with a library, whether statically or using
736 a shared library, the combination of the two is legally speaking a
737 combined work, a derivative of the original library. The ordinary
738 General Public License therefore permits such linking only if the
739 entire combination fits its criteria of freedom. The Lesser General
740 Public License permits more lax criteria for linking other code with
741 the library.
742 
743  We call this license the "Lesser" General Public License because it
744 does Less to protect the user's freedom than the ordinary General
745 Public License. It also provides other free software developers Less
746 of an advantage over competing non-free programs. These disadvantages
747 are the reason we use the ordinary General Public License for many
748 libraries. However, the Lesser license provides advantages in certain
749 special circumstances.
750 
751  For example, on rare occasions, there may be a special need to
752 encourage the widest possible use of a certain library, so that it becomes
753 a de-facto standard. To achieve this, non-free programs must be
754 allowed to use the library. A more frequent case is that a free
755 library does the same job as widely used non-free libraries. In this
756 case, there is little to gain by limiting the free library to free
757 software only, so we use the Lesser General Public License.
758 
759  In other cases, permission to use a particular library in non-free
760 programs enables a greater number of people to use a large body of
761 free software. For example, permission to use the GNU C Library in
762 non-free programs enables many more people to use the whole GNU
763 operating system, as well as its variant, the GNU/Linux operating
764 system.
765 
766  Although the Lesser General Public License is Less protective of the
767 users' freedom, it does ensure that the user of a program that is
768 linked with the Library has the freedom and the wherewithal to run
769 that program using a modified version of the Library.
770 
771  The precise terms and conditions for copying, distribution and
772 modification follow. Pay close attention to the difference between a
773 "work based on the library" and a "work that uses the library". The
774 former contains code derived from the library, whereas the latter must
775 be combined with the library in order to run.
776 
777  GNU LESSER GENERAL PUBLIC LICENSE
778  TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
779 
780  0. This License Agreement applies to any software library or other
781 program which contains a notice placed by the copyright holder or
782 other authorized party saying it may be distributed under the terms of
783 this Lesser General Public License (also called "this License").
784 Each licensee is addressed as "you".
785 
786  A "library" means a collection of software functions and/or data
787 prepared so as to be conveniently linked with application programs
788 (which use some of those functions and data) to form executables.
789 
790  The "Library", below, refers to any such software library or work
791 which has been distributed under these terms. A "work based on the
792 Library" means either the Library or any derivative work under
793 copyright law: that is to say, a work containing the Library or a
794 portion of it, either verbatim or with modifications and/or translated
795 straightforwardly into another language. (Hereinafter, translation is
796 included without limitation in the term "modification".)
797 
798  "Source code" for a work means the preferred form of the work for
799 making modifications to it. For a library, complete source code means
800 all the source code for all modules it contains, plus any associated
801 interface definition files, plus the scripts used to control compilation
802 and installation of the library.
803 
804  Activities other than copying, distribution and modification are not
805 covered by this License; they are outside its scope. The act of
806 running a program using the Library is not restricted, and output from
807 such a program is covered only if its contents constitute a work based
808 on the Library (independent of the use of the Library in a tool for
809 writing it). Whether that is true depends on what the Library does
810 and what the program that uses the Library does.
811 
812  1. You may copy and distribute verbatim copies of the Library's
813 complete source code as you receive it, in any medium, provided that
814 you conspicuously and appropriately publish on each copy an
815 appropriate copyright notice and disclaimer of warranty; keep intact
816 all the notices that refer to this License and to the absence of any
817 warranty; and distribute a copy of this License along with the
818 Library.
819 
820  You may charge a fee for the physical act of transferring a copy,
821 and you may at your option offer warranty protection in exchange for a
822 fee.
823 
824  2. You may modify your copy or copies of the Library or any portion
825 of it, thus forming a work based on the Library, and copy and
826 distribute such modifications or work under the terms of Section 1
827 above, provided that you also meet all of these conditions:
828 
829  a) The modified work must itself be a software library.
830 
831  b) You must cause the files modified to carry prominent notices
832  stating that you changed the files and the date of any change.
833 
834  c) You must cause the whole of the work to be licensed at no
835  charge to all third parties under the terms of this License.
836 
837  d) If a facility in the modified Library refers to a function or a
838  table of data to be supplied by an application program that uses
839  the facility, other than as an argument passed when the facility
840  is invoked, then you must make a good faith effort to ensure that,
841  in the event an application does not supply such function or
842  table, the facility still operates, and performs whatever part of
843  its purpose remains meaningful.
844 
845  (For example, a function in a library to compute square roots has
846  a purpose that is entirely well-defined independent of the
847  application. Therefore, Subsection 2d requires that any
848  application-supplied function or table used by this function must
849  be optional: if the application does not supply it, the square
850  root function must still compute square roots.)
851 
852 These requirements apply to the modified work as a whole. If
853 identifiable sections of that work are not derived from the Library,
854 and can be reasonably considered independent and separate works in
855 themselves, then this License, and its terms, do not apply to those
856 sections when you distribute them as separate works. But when you
857 distribute the same sections as part of a whole which is a work based
858 on the Library, the distribution of the whole must be on the terms of
859 this License, whose permissions for other licensees extend to the
860 entire whole, and thus to each and every part regardless of who wrote
861 it.
862 
863 Thus, it is not the intent of this section to claim rights or contest
864 your rights to work written entirely by you; rather, the intent is to
865 exercise the right to control the distribution of derivative or
866 collective works based on the Library.
867 
868 In addition, mere aggregation of another work not based on the Library
869 with the Library (or with a work based on the Library) on a volume of
870 a storage or distribution medium does not bring the other work under
871 the scope of this License.
872 
873  3. You may opt to apply the terms of the ordinary GNU General Public
874 License instead of this License to a given copy of the Library. To do
875 this, you must alter all the notices that refer to this License, so
876 that they refer to the ordinary GNU General Public License, version 2,
877 instead of to this License. (If a newer version than version 2 of the
878 ordinary GNU General Public License has appeared, then you can specify
879 that version instead if you wish.) Do not make any other change in
880 these notices.
881 
882  Once this change is made in a given copy, it is irreversible for
883 that copy, so the ordinary GNU General Public License applies to all
884 subsequent copies and derivative works made from that copy.
885 
886  This option is useful when you wish to copy part of the code of
887 the Library into a program that is not a library.
888 
889  4. You may copy and distribute the Library (or a portion or
890 derivative of it, under Section 2) in object code or executable form
891 under the terms of Sections 1 and 2 above provided that you accompany
892 it with the complete corresponding machine-readable source code, which
893 must be distributed under the terms of Sections 1 and 2 above on a
894 medium customarily used for software interchange.
895 
896  If distribution of object code is made by offering access to copy
897 from a designated place, then offering equivalent access to copy the
898 source code from the same place satisfies the requirement to
899 distribute the source code, even though third parties are not
900 compelled to copy the source along with the object code.
901 
902  5. A program that contains no derivative of any portion of the
903 Library, but is designed to work with the Library by being compiled or
904 linked with it, is called a "work that uses the Library". Such a
905 work, in isolation, is not a derivative work of the Library, and
906 therefore falls outside the scope of this License.
907 
908  However, linking a "work that uses the Library" with the Library
909 creates an executable that is a derivative of the Library (because it
910 contains portions of the Library), rather than a "work that uses the
911 library". The executable is therefore covered by this License.
912 Section 6 states terms for distribution of such executables.
913 
914  When a "work that uses the Library" uses material from a header file
915 that is part of the Library, the object code for the work may be a
916 derivative work of the Library even though the source code is not.
917 Whether this is true is especially significant if the work can be
918 linked without the Library, or if the work is itself a library. The
919 threshold for this to be true is not precisely defined by law.
920 
921  If such an object file uses only numerical parameters, data
922 structure layouts and accessors, and small macros and small inline
923 functions (ten lines or less in length), then the use of the object
924 file is unrestricted, regardless of whether it is legally a derivative
925 work. (Executables containing this object code plus portions of the
926 Library will still fall under Section 6.)
927 
928  Otherwise, if the work is a derivative of the Library, you may
929 distribute the object code for the work under the terms of Section 6.
930 Any executables containing that work also fall under Section 6,
931 whether or not they are linked directly with the Library itself.
932 
933  6. As an exception to the Sections above, you may also combine or
934 link a "work that uses the Library" with the Library to produce a
935 work containing portions of the Library, and distribute that work
936 under terms of your choice, provided that the terms permit
937 modification of the work for the customer's own use and reverse
938 engineering for debugging such modifications.
939 
940  You must give prominent notice with each copy of the work that the
941 Library is used in it and that the Library and its use are covered by
942 this License. You must supply a copy of this License. If the work
943 during execution displays copyright notices, you must include the
944 copyright notice for the Library among them, as well as a reference
945 directing the user to the copy of this License. Also, you must do one
946 of these things:
947 
948  a) Accompany the work with the complete corresponding
949  machine-readable source code for the Library including whatever
950  changes were used in the work (which must be distributed under
951  Sections 1 and 2 above); and, if the work is an executable linked
952  with the Library, with the complete machine-readable "work that
953  uses the Library", as object code and/or source code, so that the
954  user can modify the Library and then relink to produce a modified
955  executable containing the modified Library. (It is understood
956  that the user who changes the contents of definitions files in the
957  Library will not necessarily be able to recompile the application
958  to use the modified definitions.)
959 
960  b) Use a suitable shared library mechanism for linking with the
961  Library. A suitable mechanism is one that (1) uses at run time a
962  copy of the library already present on the user's computer system,
963  rather than copying library functions into the executable, and (2)
964  will operate properly with a modified version of the library, if
965  the user installs one, as long as the modified version is
966  interface-compatible with the version that the work was made with.
967 
968  c) Accompany the work with a written offer, valid for at
969  least three years, to give the same user the materials
970  specified in Subsection 6a, above, for a charge no more
971  than the cost of performing this distribution.
972 
973  d) If distribution of the work is made by offering access to copy
974  from a designated place, offer equivalent access to copy the above
975  specified materials from the same place.
976 
977  e) Verify that the user has already received a copy of these
978  materials or that you have already sent this user a copy.
979 
980  For an executable, the required form of the "work that uses the
981 Library" must include any data and utility programs needed for
982 reproducing the executable from it. However, as a special exception,
983 the materials to be distributed need not include anything that is
984 normally distributed (in either source or binary form) with the major
985 components (compiler, kernel, and so on) of the operating system on
986 which the executable runs, unless that component itself accompanies
987 the executable.
988 
989  It may happen that this requirement contradicts the license
990 restrictions of other proprietary libraries that do not normally
991 accompany the operating system. Such a contradiction means you cannot
992 use both them and the Library together in an executable that you
993 distribute.
994 
995  7. You may place library facilities that are a work based on the
996 Library side-by-side in a single library together with other library
997 facilities not covered by this License, and distribute such a combined
998 library, provided that the separate distribution of the work based on
999 the Library and of the other library facilities is otherwise
1000 permitted, and provided that you do these two things:
1001 
1002  a) Accompany the combined library with a copy of the same work
1003  based on the Library, uncombined with any other library
1004  facilities. This must be distributed under the terms of the
1005  Sections above.
1006 
1007  b) Give prominent notice with the combined library of the fact
1008  that part of it is a work based on the Library, and explaining
1009  where to find the accompanying uncombined form of the same work.
1010 
1011  8. You may not copy, modify, sublicense, link with, or distribute
1012 the Library except as expressly provided under this License. Any
1013 attempt otherwise to copy, modify, sublicense, link with, or
1014 distribute the Library is void, and will automatically terminate your
1015 rights under this License. However, parties who have received copies,
1016 or rights, from you under this License will not have their licenses
1017 terminated so long as such parties remain in full compliance.
1018 
1019  9. You are not required to accept this License, since you have not
1020 signed it. However, nothing else grants you permission to modify or
1021 distribute the Library or its derivative works. These actions are
1022 prohibited by law if you do not accept this License. Therefore, by
1023 modifying or distributing the Library (or any work based on the
1024 Library), you indicate your acceptance of this License to do so, and
1025 all its terms and conditions for copying, distributing or modifying
1026 the Library or works based on it.
1027 
1028  10. Each time you redistribute the Library (or any work based on the
1029 Library), the recipient automatically receives a license from the
1030 original licensor to copy, distribute, link with or modify the Library
1031 subject to these terms and conditions. You may not impose any further
1032 restrictions on the recipients' exercise of the rights granted herein.
1033 You are not responsible for enforcing compliance by third parties with
1034 this License.
1035 
1036  11. If, as a consequence of a court judgment or allegation of patent
1037 infringement or for any other reason (not limited to patent issues),
1038 conditions are imposed on you (whether by court order, agreement or
1039 otherwise) that contradict the conditions of this License, they do not
1040 excuse you from the conditions of this License. If you cannot
1041 distribute so as to satisfy simultaneously your obligations under this
1042 License and any other pertinent obligations, then as a consequence you
1043 may not distribute the Library at all. For example, if a patent
1044 license would not permit royalty-free redistribution of the Library by
1045 all those who receive copies directly or indirectly through you, then
1046 the only way you could satisfy both it and this License would be to
1047 refrain entirely from distribution of the Library.
1048 
1049 If any portion of this section is held invalid or unenforceable under any
1050 particular circumstance, the balance of the section is intended to apply,
1051 and the section as a whole is intended to apply in other circumstances.
1052 
1053 It is not the purpose of this section to induce you to infringe any
1054 patents or other property right claims or to contest validity of any
1055 such claims; this section has the sole purpose of protecting the
1056 integrity of the free software distribution system which is
1057 implemented by public license practices. Many people have made
1058 generous contributions to the wide range of software distributed
1059 through that system in reliance on consistent application of that
1060 system; it is up to the author/donor to decide if he or she is willing
1061 to distribute software through any other system and a licensee cannot
1062 impose that choice.
1063 
1064 This section is intended to make thoroughly clear what is believed to
1065 be a consequence of the rest of this License.
1066 
1067  12. If the distribution and/or use of the Library is restricted in
1068 certain countries either by patents or by copyrighted interfaces, the
1069 original copyright holder who places the Library under this License may add
1070 an explicit geographical distribution limitation excluding those countries,
1071 so that distribution is permitted only in or among countries not thus
1072 excluded. In such case, this License incorporates the limitation as if
1073 written in the body of this License.
1074 
1075  13. The Free Software Foundation may publish revised and/or new
1076 versions of the Lesser General Public License from time to time.
1077 Such new versions will be similar in spirit to the present version,
1078 but may differ in detail to address new problems or concerns.
1079 
1080 Each version is given a distinguishing version number. If the Library
1081 specifies a version number of this License which applies to it and
1082 "any later version", you have the option of following the terms and
1083 conditions either of that version or of any later version published by
1084 the Free Software Foundation. If the Library does not specify a
1085 license version number, you may choose any version ever published by
1086 the Free Software Foundation.
1087 
1088  14. If you wish to incorporate parts of the Library into other free
1089 programs whose distribution conditions are incompatible with these,
1090 write to the author to ask for permission. For software which is
1091 copyrighted by the Free Software Foundation, write to the Free
1092 Software Foundation; we sometimes make exceptions for this. Our
1093 decision will be guided by the two goals of preserving the free status
1094 of all derivatives of our free software and of promoting the sharing
1095 and reuse of software generally.
1096 
1097  NO WARRANTY
1098 
1099  15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
1100 WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
1101 EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
1102 OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
1103 KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
1104 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
1105 PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
1106 LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
1107 THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
1108 
1109  16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
1110 WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
1111 AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
1112 FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
1113 CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
1114 LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
1115 RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
1116 FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
1117 SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
1118 DAMAGES.
1119 
1120  END OF TERMS AND CONDITIONS
1121 
1122  How to Apply These Terms to Your New Libraries
1123 
1124  If you develop a new library, and you want it to be of the greatest
1125 possible use to the public, we recommend making it free software that
1126 everyone can redistribute and change. You can do so by permitting
1127 redistribution under these terms (or, alternatively, under the terms of the
1128 ordinary General Public License).
1129 
1130  To apply these terms, attach the following notices to the library. It is
1131 safest to attach them to the start of each source file to most effectively
1132 convey the exclusion of warranty; and each file should have at least the
1133 "copyright" line and a pointer to where the full notice is found.
1134 
1135  <one line to give the library's name and a brief idea of what it does.>
1136  Copyright (C) <year> <name of author>
1137 
1138  This library is free software; you can redistribute it and/or
1139  modify it under the terms of the GNU Lesser General Public
1140  License as published by the Free Software Foundation; either
1141  version 2.1 of the License, or (at your option) any later version.
1142 
1143  This library is distributed in the hope that it will be useful,
1144  but WITHOUT ANY WARRANTY; without even the implied warranty of
1145  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1146  Lesser General Public License for more details.
1147 
1148  You should have received a copy of the GNU Lesser General Public
1149  License along with this library; if not, write to the Free Software
1150  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1151 
1152 Also add information on how to contact you by electronic and paper mail.
1153 
1154 You should also get your employer (if you work as a programmer) or your
1155 school, if any, to sign a "copyright disclaimer" for the library, if
1156 necessary. Here is a sample; alter the names:
1157 
1158  Yoyodyne, Inc., hereby disclaims all copyright interest in the
1159  library `Frob' (a library for tweaking knobs) written by James Random Hacker.
1160 
1161  <signature of Ty Coon>, 1 April 1990
1162  Ty Coon, President of Vice
1163 
1164 That's all there is to it!
1165 
1166 */
rvUint8 pp_6[7]
Definition: FEC.cpp:70
#define modnn(x)
Definition: FEC.cpp:108
rvUint8 uintGF
Definition: FEC.hpp:36
rvInt16 rvFec_Correct(rvFec *self, rvUint8 *blockBuffer)
Definition: FEC.cpp:325
static void rvFec_InitGaloisField(rvFec *self, rvUint8 *pp)
Definition: FEC.cpp:110
Definition: FEC.hpp:44
#define MIN(a, b)
Definition: FEC.cpp:55
rvUint8 pp_8[9]
Definition: FEC.cpp:76
rvFec * rvFec_New(rvInt16 symbolSize, rvInt16 dataSize, rvInt16 paritySize)
Definition: FEC.cpp:196
rvUint8 pp_7[8]
Definition: FEC.cpp:73
rvUint8 pp_5[6]
Definition: FEC.cpp:67
FEC FEC__create(unsigned int symbol_size, unsigned int data_size, unsigned int parity_size)
Definition: FEC.cpp:653
static void rvFec_InitPolynomial(rvFec *self)
Definition: FEC.cpp:162
rvUint8 pp_3[4]
Definition: FEC.cpp:61
void FEC__parity(FEC fec, unsigned int *data, unsigned int size)
Definition: FEC.cpp:630
unsigned char rvUint8
Definition: FEC.hpp:27
#define ALPHA_ZERO
Definition: FEC.cpp:49
rvUint8 pp_4[5]
Definition: FEC.cpp:64
short rvInt16
Definition: FEC.hpp:26
rvInt16 rvFec_Parity(rvFec *self, rvUint8 *dataBuffer, rvUint8 *parityBuffer)
Definition: FEC.cpp:276
unsigned short rvUint16
Definition: FEC.hpp:28
bool FEC__correct(FEC fec, unsigned int *data, unsigned int size)
Definition: FEC.cpp:604
#define ALPHA_ROOT
Definition: FEC.cpp:52


fiducial_lib
Author(s): Wayne Gramlich
autogenerated on Thu Dec 28 2017 04:06:53