1
0
mirror of https://github.com/saitohirga/WSJT-X.git synced 2025-05-14 05:40:07 -04:00
WSJT-X/lib/superfox/rs_sf.c

54 lines
1.3 KiB
C
Raw Normal View History

#include <stdio.h>
#include "rs_sf.h"
static void *rs_sf;
static int first=1;
static int nn,kk,nroots,npad;
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-02 13:22:42 -05:00
// Save parameters nn, kk, nroots, npad for global access
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);
first=0;
}
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-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 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-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++) {
decoded[i]=recd[nroots+i];
}
}