partially refactored
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Mon, 12 Sep 2016 07:50:00 +0000 (07:50 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Mon, 12 Sep 2016 07:50:00 +0000 (07:50 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@2856 01035d8c-6547-0410-b346-abe4f91aad63

codec2-dev/src/ldpc_enc.c

index c7d033118ab5c7393a21751f170f4a8ce631754e..d6753bfcc1da9d5a405e4ed38cfa6ce3470f8bf3 100644 (file)
@@ -1,31 +1,28 @@
-/* RA encoder  program;  Bill,  March 2016 
-   Using the elegant back substitution of RA LDPC codes. 
-   This version does not store the data in bytes! */
+/* 
+  FILE...: ldpc_enc.c
+  AUTHOR.: Bill Cowley, David Rowe
+  CREATED: Sep 2016
 
+  RA LDPC encoder program. Using the elegant back substitution of RA
+  LDPC codes.
+*/
 
 #include <stdio.h>
 #include <stdlib.h>
 
-#define Nibits 2064
-#define Npbits 516
-#define Nwt     12
-
 /* generated by ldpc_fsk_lib.m:ldpc_decode() */
 
 #include "ldpc_code.h"
 
-unsigned char  ibits[Nibits];    // info array 
-unsigned char  pbits[Npbits];    // parity array 
-
-void encode()   {
-    unsigned int   p, i, tmp, par, prev=0;
+void encode(unsigned char ibits[], unsigned char pbits[]) {
+    unsigned int p, i, tmp, par, prev=0;
     int ind;
 
-    for (p=0; p<Npbits; p++) {
+    for (p=0; p<NUMBERPARITYBITS; p++) {
         par = 0; 
 
-        for (i=0; i<Nwt; i++) {
-            ind = (int)H_rows[p + i*Npbits];
+        for (i=0; i<MAX_ROW_WEIGHT; i++) {
+            ind = (int)H_rows[p + i*NUMBERPARITYBITS];
             par = par + ibits[ind-1];
         }
 
@@ -39,30 +36,32 @@ void encode()   {
 
 int main(void)
 {
-  short  k;
-  unsigned int x;
+    unsigned char ibits[NUMBERROWSHCOLS];
+    unsigned char pbits[NUMBERPARITYBITS];
+    short  k;
+    unsigned int x;
 
-  printf("Test C Encoder\n");
+    printf("Test C Encoder\n");
   
-  FILE *infp, *opfp;
-  infp = fopen("dat_in2064.txt", "r");   // read info bits from file   
-  if (infp == NULL) {printf("Unable to open file.\n"); exit(1);} 
+    FILE *infp, *opfp;
+    infp = fopen("dat_in2064.txt", "r");   // read info bits from file   
+    if (infp == NULL) {printf("Unable to open file.\n"); exit(1);} 
  
-  for (k=0; k<Nibits; k++)     { 
-      fscanf(infp, "%u\n", &x);
-      ibits[k] = x; 
+    for (k=0; k<NUMBERROWSHCOLS; k++)     { 
+        fscanf(infp, "%u\n", &x);
+        ibits[k] = x; 
     }
-  fclose(infp);  
+    fclose(infp);  
 
-  encode();  
+    encode(ibits, pbits);  
 
-  opfp = fopen("dat_op2064.bin", "wb");   // write par bits to file
-  if (opfp == NULL) {printf("Unable to output file.\n"); exit(1);}  
-  for (k=0; k<Nibits; k++)
-      fwrite(&ibits[k], sizeof(char), 1, opfp); 
-  for (k=0; k<Npbits; k++)
-      fwrite(&pbits[k], sizeof(char), 1, opfp); 
-  fclose(opfp); 
+    opfp = fopen("dat_op2064.bin", "wb");   // write par bits to file
+    if (opfp == NULL) {printf("Unable to output file.\n"); exit(1);}  
+    for (k=0; k<NUMBERROWSHCOLS; k++)
+        fwrite(&ibits[k], sizeof(char), 1, opfp); 
+    for (k=0; k<NUMBERPARITYBITS; k++)
+        fwrite(&pbits[k], sizeof(char), 1, opfp); 
+    fclose(opfp); 
 
-  return 1;
+    return 1;
 }