diff --git a/lib/wsprd/wsprd.c b/lib/wsprd/wsprd.c index 024afaa48..2e4c3c232 100644 --- a/lib/wsprd/wsprd.c +++ b/lib/wsprd/wsprd.c @@ -43,6 +43,9 @@ #include "wsprsim_utils.h" #define max(x,y) ((x) > (y) ? (x) : (y)) + +extern void osdwspr_ (float [], unsigned char [], int *, unsigned char [], int *, float *); + // Possible PATIENCE options: FFTW_ESTIMATE, FFTW_ESTIMATE_PATIENT, // FFTW_MEASURE, FFTW_PATIENT, FFTW_EXHAUSTIVE #define PATIENCE FFTW_ESTIMATE @@ -59,8 +62,6 @@ unsigned char pr3[162]= 0,0,0,0,0,0,0,1,1,0,1,0,1,1,0,0,0,1,1,0, 0,0}; -unsigned long nr; - int printdata=0; //*************************************************************************** @@ -73,18 +74,18 @@ unsigned long readc2file(char *ptr_to_infile, float *idat, float *qdat, char *c2file[15]; FILE* fp; - buffer=calloc(2*65536,sizeof(float)); - fp = fopen(ptr_to_infile,"rb"); if (fp == NULL) { fprintf(stderr, "Cannot open data file '%s'\n", ptr_to_infile); return 1; } - unsigned long nread=fread(c2file,sizeof(char),14,fp); - nread=fread(&ntrmin,sizeof(int),1,fp); - nread=fread(&dfreq,sizeof(double),1,fp); + fread(c2file,sizeof(char),14,fp); + fread(&ntrmin,sizeof(int),1,fp); + fread(&dfreq,sizeof(double),1,fp); *freq=dfreq; - nread=fread(buffer,sizeof(float),2*45000,fp); + + buffer=calloc(2*65536,sizeof(float)); + unsigned long nread=fread(buffer,sizeof(float),2*45000,fp); fclose(fp); *wspr_type=ntrmin; @@ -93,13 +94,13 @@ unsigned long readc2file(char *ptr_to_infile, float *idat, float *qdat, idat[i]=buffer[2*i]; qdat[i]=-buffer[2*i+1]; } + free(buffer); if( nread == 2*45000 ) { return nread/2; } else { return 1; } - free(buffer); } //*************************************************************************** @@ -132,15 +133,16 @@ unsigned long readwavfile(char *ptr_to_infile, int ntrmin, float *idat, float *q FILE *fp; short int *buf2; - buf2 = calloc(npoints,sizeof(short int)); fp = fopen(ptr_to_infile,"rb"); if (fp == NULL) { fprintf(stderr, "Cannot open data file '%s'\n", ptr_to_infile); return 1; } - nr=fread(buf2,2,22,fp); //Read and ignore header - nr=fread(buf2,2,npoints,fp); //Read raw data + + buf2 = calloc(npoints,sizeof(short int)); + fread(buf2,2,22,fp); //Read and ignore header + fread(buf2,2,npoints,fp); //Read raw data fclose(fp); realin=(float*) fftwf_malloc(sizeof(float)*nfft1); @@ -154,8 +156,8 @@ unsigned long readwavfile(char *ptr_to_infile, int ntrmin, float *idat, float *q for (i=npoints; i<(size_t)nfft1; i++) { realin[i]=0.0; } - free(buf2); + fftwf_execute(PLAN1); fftwf_free(realin); @@ -648,30 +650,27 @@ unsigned long writec2file(char *c2filename, int trmin, double freq { int i; float *buffer; - buffer=calloc(2*45000,sizeof(float)); - FILE *fp; fp = fopen(c2filename,"wb"); if( fp == NULL ) { fprintf(stderr, "Could not open c2 file '%s'\n", c2filename); - free(buffer); return 0; } unsigned long nwrite = fwrite(c2filename,sizeof(char),14,fp); nwrite = fwrite(&trmin, sizeof(int), 1, fp); nwrite = fwrite(&freq, sizeof(double), 1, fp); + buffer=calloc(2*45000,sizeof(float)); for(i=0; i<45000; i++) { buffer[2*i]=idat[i]; buffer[2*i+1]=-qdat[i]; } - nwrite = fwrite(buffer, sizeof(float), 2*45000, fp); + free(buffer); if( nwrite == 2*45000 ) { return nwrite; } else { - free(buffer); return 0; } } @@ -718,7 +717,7 @@ int main(int argc, char *argv[]) char timer_fname[200],hash_fname[200]; char uttime[5],date[7]; int c,delta,maxpts=65536,verbose=0,quickmode=0,more_candidates=0, stackdecoder=0; - int writenoise=0,usehashtable=1,wspr_type=2, ipass, nblocksize,use_osd=0; + int writenoise=0,usehashtable=1,wspr_type=2, ipass, nblocksize; int nhardmin,ihash; int writec2=0,maxdrift; int shift1, lagmin, lagmax, lagstep, ifmin, ifmax, worth_a_try, not_decoded; @@ -743,17 +742,17 @@ int main(int argc, char *argv[]) struct result { char date[7]; char time[5]; float sync; float snr; float dt; double freq; char message[23]; float drift; unsigned int cycles; int jitter; int blocksize; unsigned int metric; - unsigned char osd_decode }; + unsigned char osd_decode; }; struct result decodes[50]; char *hashtab; hashtab=calloc(32768*13,sizeof(char)); int nh; - symbols=calloc(nbits*2,sizeof(char)); - apmask=calloc(162,sizeof(char)); - cw=calloc(162,sizeof(char)); - decdata=calloc(11,sizeof(char)); - channel_symbols=calloc(nbits*2,sizeof(char)); + symbols=calloc(nbits*2,sizeof(unsigned char)); + apmask=calloc(162,sizeof(unsigned char)); + cw=calloc(162,sizeof(unsigned char)); + decdata=calloc(11,sizeof(unsigned char)); + channel_symbols=calloc(nbits*2,sizeof(unsigned char)); callsign=calloc(13,sizeof(char)); call_loc_pow=calloc(23,sizeof(char)); float allfreqs[100]; @@ -892,10 +891,10 @@ int main(int argc, char *argv[]) // fdiag=fopen("wsprd_diag","a"); if((ftimer=fopen(timer_fname,"r"))) { - //Accumulate timing data - nr=fscanf(ftimer,"%f %f %f %f %f %f %f", - &treadwav,&tcandidates,&tsync0,&tsync1,&tsync2,&tfano,&ttotal); - fclose(ftimer); + //Accumulate timing data + fscanf(ftimer,"%f %f %f %f %f %f %f", + &treadwav,&tcandidates,&tsync0,&tsync1,&tsync2,&tfano,&ttotal); + fclose(ftimer); } ftimer=fopen(timer_fname,"w");