Imported Upstream version 3.2.2
[debian/gnuradio] / gnuradio-core / src / lib / reed-solomon / encode_rs.c
1 /* Reed-Solomon encoder
2  * Copyright 2002, Phil Karn, KA9Q
3  * May be used under the terms of the GNU General Public License (GPL)
4  */
5 #include <string.h>
6 #include <strings.h>
7
8 #ifdef FIXED
9 #include "fixed.h"
10 #elif defined(BIGSYM)
11 #include "int.h"
12 #else
13 #include "char.h"
14 #endif
15
16 void ENCODE_RS(
17 #ifndef FIXED
18 void *p,
19 #endif
20 DTYPE *data, DTYPE *bb){
21 #ifndef FIXED
22   struct rs *rs = (struct rs *)p;
23 #endif
24   int i, j;
25   DTYPE feedback;
26
27   memset(bb,0,NROOTS*sizeof(DTYPE));
28
29   for(i=0;i<NN-NROOTS;i++){
30     feedback = INDEX_OF[data[i] ^ bb[0]];
31     if(feedback != A0){      /* feedback term is non-zero */
32 #ifdef UNNORMALIZED
33       /* This line is unnecessary when GENPOLY[NROOTS] is unity, as it must
34        * always be for the polynomials constructed by init_rs()
35        */
36       feedback = MODNN(NN - GENPOLY[NROOTS] + feedback);
37 #endif
38       for(j=1;j<NROOTS;j++)
39         bb[j] ^= ALPHA_TO[MODNN(feedback + GENPOLY[NROOTS-j])];
40     }
41     /* Shift */
42     memmove(&bb[0],&bb[1],sizeof(DTYPE)*(NROOTS-1));
43     if(feedback != A0)
44       bb[NROOTS-1] = ALPHA_TO[MODNN(feedback + GENPOLY[0])];
45     else
46       bb[NROOTS-1] = 0;
47   }
48 }