Imported Upstream version 3.0
[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
7 #ifdef FIXED
8 #include "fixed.h"
9 #elif defined(BIGSYM)
10 #include "int.h"
11 #else
12 #include "char.h"
13 #endif
14
15 void ENCODE_RS(
16 #ifndef FIXED
17 void *p,
18 #endif
19 DTYPE *data, DTYPE *bb){
20 #ifndef FIXED
21   struct rs *rs = (struct rs *)p;
22 #endif
23   int i, j;
24   DTYPE feedback;
25
26   memset(bb,0,NROOTS*sizeof(DTYPE));
27
28   for(i=0;i<NN-NROOTS;i++){
29     feedback = INDEX_OF[data[i] ^ bb[0]];
30     if(feedback != A0){      /* feedback term is non-zero */
31 #ifdef UNNORMALIZED
32       /* This line is unnecessary when GENPOLY[NROOTS] is unity, as it must
33        * always be for the polynomials constructed by init_rs()
34        */
35       feedback = MODNN(NN - GENPOLY[NROOTS] + feedback);
36 #endif
37       for(j=1;j<NROOTS;j++)
38         bb[j] ^= ALPHA_TO[MODNN(feedback + GENPOLY[NROOTS-j])];
39     }
40     /* Shift */
41     memmove(&bb[0],&bb[1],sizeof(DTYPE)*(NROOTS-1));
42     if(feedback != A0)
43       bb[NROOTS-1] = ALPHA_TO[MODNN(feedback + GENPOLY[0])];
44     else
45       bb[NROOTS-1] = 0;
46   }
47 }