From: baobrien Date: Sun, 17 Jan 2016 20:27:00 +0000 (+0000) Subject: Further memory managment fixery X-Git-Url: http://git.whiteaudio.com/gitweb/?a=commitdiff_plain;h=0484b60ec2d29992b52f09e0c4516c8b3d5870a2;p=freetel-svn-tracking.git Further memory managment fixery git-svn-id: https://svn.code.sf.net/p/freetel/code@2629 01035d8c-6547-0410-b346-abe4f91aad63 --- diff --git a/codec2-dev/src/fsk.c b/codec2-dev/src/fsk.c index 5ee6b493..8447edbd 100644 --- a/codec2-dev/src/fsk.c +++ b/codec2-dev/src/fsk.c @@ -167,7 +167,7 @@ void fsk_destroy(struct FSK *fsk){ * fsk_in - block of samples in this demod cycles, must be nin long * f1_est - pointer to f1 estimate variable in demod * f2_est - pointer to f2 estimate variable in demod - * twist - pointer to twist estimate in demod - Note: this isn't correct right now + * twist - pointer to twist estimate in demod */ void fsk_demod_freq_est(struct FSK *fsk, float fsk_in[],float *f1_est,float *f2_est,float *twist){ int Ndft = fsk->Ndft; @@ -178,6 +178,7 @@ void fsk_demod_freq_est(struct FSK *fsk, float fsk_in[],float *f1_est,float *f2_ float hann; float max; int m1,m2; + float m1v,m2v,t; kiss_fftr_cfg fft_cfg = fsk->fft_cfg; /* Array to do complex FFT from using kiss_fft */ @@ -193,6 +194,8 @@ void fsk_demod_freq_est(struct FSK *fsk, float fsk_in[],float *f1_est,float *f2_ /* resulting in a dirty FFT */ /* An easy fix would be to ensure that Ndft is always greater than N+Ts/2 * instead of N */ + /* Another easy fix would be to apply the hann window over fft_samps + * instead of nin */ /* This bug isn't a big deal and can't show up in the balloon config */ /* as 8192 > 8040 */ hann = sinf((M_PI*(float)i)/((float)nin-1)); @@ -225,6 +228,8 @@ void fsk_demod_freq_est(struct FSK *fsk, float fsk_in[],float *f1_est,float *f2_ } } + m1v = sqrtf(fftout[m1].r); + /* Zero out 100Hz around the maximum */ i = m1 - 100*Ndft/Fs; i = i<0 ? 0 : i; @@ -244,20 +249,23 @@ void fsk_demod_freq_est(struct FSK *fsk, float fsk_in[],float *f1_est,float *f2_ } } + m2v = sqrtf(fftout[m2].r); + /* f1 is always the lower tone */ if(m1>m2){ j=m1; m1=m2; m2=j; + t=m1v; + m1v=m2v; + m2v=t; } *f1_est = (float)m1*(float)Fs/(float)Ndft; *f2_est = (float)m2*(float)Fs/(float)Ndft; - *twist = 20*log10f((float)(m1)/(float)(m2)); + *twist = 20*log10f(m1v/m2v); //printf("ESTF - f1 = %f, f2 = %f, twist = %f \n",*f1_est,*f2_est,*twist); - - free(fftin); - free(fftout); + } /* @@ -291,10 +299,9 @@ static inline int comp_mag_gt(COMP a,COMP b){ /* * Normalize a complex number's magnitude to 1 */ - static inline COMP comp_normalize(COMP a){ - float av = sqrtf((a.real*a.real)+(a.imag*a.imag)); COMP b; + float av = sqrtf((a.real*a.real)+(a.imag*a.imag)); b.real = a.real/av; b.imag = a.imag/av; return b; @@ -312,7 +319,7 @@ void fsk_demod(struct FSK *fsk, uint8_t rx_bits[], float fsk_in[]){ int Nmem = fsk->Nmem; int i,j,dc_i,cbuf_i; float ft1,ft2; - float twist; /* NOTE: This is not correct ATM */ + float twist; int nstash = fsk->nstash; COMP *f1_int, *f2_int; COMP t1,t2; @@ -330,6 +337,9 @@ void fsk_demod(struct FSK *fsk, uint8_t rx_bits[], float fsk_in[]){ /* Estimate tone frequencies */ fsk_demod_freq_est(fsk,fsk_in,&f1,&f2,&twist); + fsk->f1_est = f1; + fsk->f2_est = f2; + fsk->twist_est = twist; /* allocate memory for the integrated samples */ /* Note: This must be kept after fsk_demod_freq_est for memory usage reasons */ @@ -474,11 +484,6 @@ void fsk_demod(struct FSK *fsk, uint8_t rx_bits[], float fsk_in[]){ /* Soft output goes here */ } - free(f1_int); - free(f2_int); - free(f1_intbuf); - free(f2_intbuf); - printf("rx_timing: %3.2f low_sample: %d high_sample: %d fract: %3.3f nin_next: %d\n", rx_timing, low_sample, high_sample, fract, fsk->nin); } diff --git a/codec2-dev/src/fsk.h b/codec2-dev/src/fsk.h index 3f65e67f..35ef7b13 100644 --- a/codec2-dev/src/fsk.h +++ b/codec2-dev/src/fsk.h @@ -64,8 +64,9 @@ struct FSK { /* Statistics generated by demod */ float EbNodB; /* Estimated EbNo in dB */ - float f1_est; /* Estimated f1 freq. */ - float f2_est; /* Estimated f2 freq. */ + float f1_est; /* Estimated f1 freq. */ + float f2_est; /* Estimated f2 freq. */ + float twist_est; /* Estimaged 'twist' from freq est */ /* Parameters used by mod/demod and driving code */ int nin; /* Number of samples to feed the next demod cycle */