From: baobrien Date: Sat, 13 Feb 2016 23:44:07 +0000 (+0000) Subject: Changed memory allocation in fsk.c to allow for X-Git-Url: http://git.whiteaudio.com/gitweb/?a=commitdiff_plain;h=fc875ac9c8d8ca6d9912ef00dc051a635d2b9d8b;p=freetel-svn-tracking.git Changed memory allocation in fsk.c to allow for git-svn-id: https://svn.code.sf.net/p/freetel/code@2700 01035d8c-6547-0410-b346-abe4f91aad63 --- diff --git a/codec2-dev/src/fsk.c b/codec2-dev/src/fsk.c index 8333f8ed..9456257c 100644 --- a/codec2-dev/src/fsk.c +++ b/codec2-dev/src/fsk.c @@ -38,6 +38,9 @@ /* This needs square roots, may take more cpu time than it's worth */ #define EST_EBNO +/* This is a flag to make the mod/demod allocate their memory on the stack instead of the heap */ +/* At large sample rates, there's not enough stack space to run the demod */ +#define DEMOD_ALLOC_STACK /*---------------------------------------------------------------------------*\ INCLUDES @@ -377,8 +380,15 @@ void fsk_demod_freq_est(struct FSK *fsk, float fsk_in[],float *freqs,int M){ /* Array to do complex FFT from using kiss_fft */ /* It'd probably make more sense here to use kiss_fftr */ + + #ifdef DEMOD_ALLOC_STACK kiss_fft_scalar *fftin = (kiss_fft_scalar*)alloca(sizeof(kiss_fft_scalar)*Ndft); kiss_fft_cpx *fftout = (kiss_fft_cpx*)alloca(sizeof(kiss_fft_cpx)*(Ndft/2)+1); + #else + kiss_fft_scalar *fftin = (kiss_fft_scalar*)malloc(sizeof(kiss_fft_scalar)*(Ndft+4)); + kiss_fft_cpx *fftout = (kiss_fft_cpx*) malloc(sizeof(kiss_fft_cpx) *((Ndft/2)+4)); + #endif + fft_samps = Ndft; f_min = (fsk->est_min*Ndft)/Fs; @@ -466,6 +476,11 @@ void fsk_demod_freq_est(struct FSK *fsk, float fsk_in[],float *freqs,int M){ for(i=0; if1_est<1){ @@ -722,6 +746,13 @@ void fsk2_demod(struct FSK *fsk, uint8_t rx_bits[], float fsk_in[]){ fsk->EbNodB = 1; #endif + #ifndef DEMOD_ALLOC_STACK + free(f1_int); + free(f2_int); + free(f1_intbuf); + free(f2_intbuf); + #endif + /* Dump some internal samples */ modem_probe_samp_f("t_EbNodB",&(fsk->EbNodB),1); modem_probe_samp_f("t_ppm",&(fsk->ppm),1); @@ -765,7 +796,8 @@ void fsk4_demod(struct FSK *fsk, uint8_t rx_bits[], float fsk_in[]){ /* Estimate tone frequencies */ fsk_demod_freq_est(fsk,fsk_in,f_est,M); modem_probe_samp_f("t_f_est",f_est,M); - + + #ifdef DEMOD_ALLOC_STACK /* allocate memory for the integrated samples */ /* Note: This must be kept after fsk_demod_freq_est for memory usage reasons */ f1_int = (COMP*) alloca(sizeof(COMP)*(nsym+1)*P); @@ -778,7 +810,17 @@ void fsk4_demod(struct FSK *fsk, uint8_t rx_bits[], float fsk_in[]){ f2_intbuf = (COMP*) alloca(sizeof(COMP)*Ts); f3_intbuf = (COMP*) alloca(sizeof(COMP)*Ts); f4_intbuf = (COMP*) alloca(sizeof(COMP)*Ts); - + #else + f1_int = (COMP*) malloc(sizeof(COMP)*(nsym+1)*P); + f2_int = (COMP*) malloc(sizeof(COMP)*(nsym+1)*P); + f3_int = (COMP*) malloc(sizeof(COMP)*(nsym+1)*P); + f4_int = (COMP*) malloc(sizeof(COMP)*(nsym+1)*P); + + f1_intbuf = (COMP*) malloc(sizeof(COMP)*Ts); + f2_intbuf = (COMP*) malloc(sizeof(COMP)*Ts); + f3_intbuf = (COMP*) malloc(sizeof(COMP)*Ts); + f4_intbuf = (COMP*) malloc(sizeof(COMP)*Ts); + #endif /* If this is the first run, we won't have any valid f_est */ if(fsk->f1_est<1){ fsk->f1_est = f_est[0]; @@ -1070,6 +1112,17 @@ void fsk4_demod(struct FSK *fsk, uint8_t rx_bits[], float fsk_in[]){ fsk->EbNodB = 0; #endif + #ifndef DEMOD_ALLOC_STACK + free(f1_int); + free(f2_int); + free(f3_int); + free(f4_int); + free(f1_intbuf); + free(f2_intbuf); + free(f3_intbuf); + free(f4_intbuf); + #endif + /* Dump some internal samples */ modem_probe_samp_f("t_EbNodB",&(fsk->EbNodB),1); modem_probe_samp_f("t_ppm",&(fsk->ppm),1); diff --git a/codec2-dev/src/fsk_demod.c b/codec2-dev/src/fsk_demod.c index 9a21d636..5368e990 100644 --- a/codec2-dev/src/fsk_demod.c +++ b/codec2-dev/src/fsk_demod.c @@ -94,9 +94,9 @@ int main(int argc,char *argv[]){ } /* allocate buffers for processing */ - bitbuf = (uint8_t*)alloca(sizeof(uint8_t)*fsk->Nbits); - rawbuf = (int16_t*)alloca(sizeof(int16_t)*(fsk->N+fsk->Ts*2)); - modbuf = (float*)alloca(sizeof(float)*(fsk->N+fsk->Ts*2)); + bitbuf = (uint8_t*)malloc(sizeof(uint8_t)*fsk->Nbits); + rawbuf = (int16_t*)malloc(sizeof(int16_t)*(fsk->N+fsk->Ts*2)); + modbuf = (float*)malloc(sizeof(float)*(fsk->N+fsk->Ts*2)); /* Demodulate! */ while( fread(rawbuf,sizeof(int16_t),fsk_nin(fsk),fin) == fsk_nin(fsk) ){ @@ -117,6 +117,9 @@ int main(int argc,char *argv[]){ } } + free(bitbuf); + free(rawbuf); + free(modbuf); modem_probe_close(); cleanup: diff --git a/codec2-dev/src/fsk_mod.c b/codec2-dev/src/fsk_mod.c index c5a39991..cb890c4c 100644 --- a/codec2-dev/src/fsk_mod.c +++ b/codec2-dev/src/fsk_mod.c @@ -76,9 +76,9 @@ int main(int argc,char *argv[]){ } /* allocate buffers for processing */ - bitbuf = (uint8_t*)alloca(sizeof(uint8_t)*fsk->Nbits); - rawbuf = (int16_t*)alloca(sizeof(int16_t)*fsk->N); - modbuf = (float*)alloca(sizeof(float)*fsk->N); + bitbuf = (uint8_t*)malloc(sizeof(uint8_t)*fsk->Nbits); + rawbuf = (int16_t*)malloc(sizeof(int16_t)*fsk->N); + modbuf = (float*)malloc(sizeof(float)*fsk->N); /* Modulate! */ while( fread(bitbuf,sizeof(uint8_t),fsk->Nbits,fin) == fsk->Nbits ){ @@ -93,6 +93,9 @@ int main(int argc,char *argv[]){ fflush(fout); } } + free(bitbuf); + free(rawbuf); + free(modbuf); cleanup: fclose(fin);