summaryrefslogtreecommitdiff
path: root/lib/encode_rs.c
diff options
context:
space:
mode:
authorIain R. Learmonth <irl@debian.org>2015-10-18 17:55:15 +0100
committerIain R. Learmonth <irl@debian.org>2015-10-18 17:55:15 +0100
commitc720a3d55c5ec832c29cb7ce50b6fb4b70c55b11 (patch)
treeecf89ef5fb2aa173119808e84e6d2e4cc15b962c /lib/encode_rs.c
Imported Upstream version 1.1.r3496upstream/1.1.r3496
Diffstat (limited to 'lib/encode_rs.c')
-rw-r--r--lib/encode_rs.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/lib/encode_rs.c b/lib/encode_rs.c
new file mode 100644
index 00000000..911bc36d
--- /dev/null
+++ b/lib/encode_rs.c
@@ -0,0 +1,52 @@
+/* Reed-Solomon encoder
+ * Copyright 2002, Phil Karn, KA9Q
+ * May be used under the terms of the GNU General Public License (GPL)
+ */
+#include <string.h>
+
+#ifdef FIXED
+#include "fixed.h"
+#elif defined(BIGSYM)
+#include "int.h"
+#else
+#include "char.h"
+#endif
+
+void ENCODE_RS(
+#ifdef FIXED
+DTYPE *data, DTYPE *bb,int pad){
+#else
+void *p,DTYPE *data, DTYPE *bb){
+ struct rs *rs = (struct rs *)p;
+#endif
+ int i, j;
+ DTYPE feedback;
+
+#ifdef FIXED
+ /* Check pad parameter for validity */
+ if(pad < 0 || pad >= NN)
+ return;
+#endif
+
+ memset(bb,0,NROOTS*sizeof(DTYPE));
+
+ for(i=0;i<NN-NROOTS-PAD;i++){
+ feedback = INDEX_OF[data[i] ^ bb[0]];
+ if(feedback != A0){ /* feedback term is non-zero */
+#ifdef UNNORMALIZED
+ /* This line is unnecessary when GENPOLY[NROOTS] is unity, as it must
+ * always be for the polynomials constructed by init_rs()
+ */
+ feedback = MODNN(NN - GENPOLY[NROOTS] + feedback);
+#endif
+ for(j=1;j<NROOTS;j++)
+ bb[j] ^= ALPHA_TO[MODNN(feedback + GENPOLY[NROOTS-j])];
+ }
+ /* Shift */
+ memmove(&bb[0],&bb[1],sizeof(DTYPE)*(NROOTS-1));
+ if(feedback != A0)
+ bb[NROOTS-1] = ALPHA_TO[MODNN(feedback + GENPOLY[0])];
+ else
+ bb[NROOTS-1] = 0;
+ }
+}