2024-02-01 08:52:46 -05:00
|
|
|
#include <stdio.h>
|
|
|
|
#include "rs_sf.h"
|
|
|
|
|
2024-02-02 15:44:03 -05:00
|
|
|
static void *rs_sf;
|
2024-02-01 08:52:46 -05:00
|
|
|
static int first=1;
|
|
|
|
static int nn,kk,nroots,npad;
|
|
|
|
|
2024-02-01 10:51:48 -05:00
|
|
|
void rs_init_sf_(int *mm, int *nq, int *nn0, int *kk0, int *nfz)
|
2024-02-02 13:22:42 -05:00
|
|
|
// Initialize the RS decoder.
|
2024-02-01 08:52:46 -05:00
|
|
|
{
|
2024-02-02 13:22:42 -05:00
|
|
|
// Save parameters nn, kk, nroots, npad for global access
|
2024-02-01 08:52:46 -05:00
|
|
|
nn=*nn0;
|
|
|
|
kk=*kk0;
|
|
|
|
nroots=nn-kk;
|
|
|
|
npad=*nq-1-nn;
|
2024-02-02 13:22:42 -05:00
|
|
|
|
|
|
|
int gfpoly=0x43; //For *mm=6
|
|
|
|
if(*mm==7) gfpoly=0x89;
|
|
|
|
if(*mm==8) gfpoly=0x11d;
|
|
|
|
rs_sf=init_rs_sf(*mm,gfpoly,*nfz,1,nroots,npad);
|
2024-02-01 08:52:46 -05:00
|
|
|
first=0;
|
|
|
|
}
|
|
|
|
|
2024-02-01 10:51:48 -05:00
|
|
|
void rs_encode_sf_(int *dgen, int *sent)
|
2024-02-02 13:22:42 -05:00
|
|
|
// Encode the information symbols dgen[KK], producing channel symbols sent[NN].
|
2024-02-01 08:52:46 -05:00
|
|
|
{
|
2024-02-02 13:22:42 -05:00
|
|
|
int b[256]; //These are the parity symbols
|
|
|
|
encode_rs_sf(rs_sf,dgen,b); //Compute the parity symbols
|
|
|
|
|
|
|
|
// Copy parity symbols into sent[] array, followed by information symbols
|
|
|
|
for (int i=0; i< nn; i++) {
|
|
|
|
if(i<nroots) {
|
|
|
|
sent[i]=b[i];
|
|
|
|
} else {
|
|
|
|
sent[i]=dgen[i-nroots];
|
|
|
|
}
|
2024-02-02 12:07:40 -05:00
|
|
|
}
|
2024-02-01 08:52:46 -05:00
|
|
|
}
|
|
|
|
|
2024-02-02 13:22:42 -05:00
|
|
|
void rs_decode_sf_(int *recd, int *era_pos, int *numera, int *decoded,
|
|
|
|
int *nerr)
|
|
|
|
/*
|
|
|
|
Decode received data recd[NN], producing decoded[KK]. Positiions of
|
|
|
|
erased symbols are specified in array era_pos[numera]. The number of
|
|
|
|
corrected errors is *nerr; if the data are uncorrectable, *nerr=-1
|
|
|
|
is returned.
|
|
|
|
*/
|
2024-02-01 08:52:46 -05:00
|
|
|
{
|
2024-02-02 12:30:32 -05:00
|
|
|
*nerr=decode_rs_sf(rs_sf,recd,era_pos,*numera);
|
2024-02-02 13:22:42 -05:00
|
|
|
for(int i=0; i<kk; i++) {
|
2024-02-02 12:07:40 -05:00
|
|
|
decoded[i]=recd[nroots+i];
|
|
|
|
}
|
2024-02-01 08:52:46 -05:00
|
|
|
}
|