From f387d2406cce9cc5f42f39694cc01ee3ca61d6b8 Mon Sep 17 00:00:00 2001 From: baobrien Date: Sun, 17 Jan 2016 20:13:47 +0000 Subject: [PATCH] Fixed allocation git-svn-id: https://svn.code.sf.net/p/freetel/code@2628 01035d8c-6547-0410-b346-abe4f91aad63 --- codec2-dev/src/fsk.c | 35 ++++++++++++----------------------- codec2-dev/src/fsk.h | 4 ++-- 2 files changed, 14 insertions(+), 25 deletions(-) diff --git a/codec2-dev/src/fsk.c b/codec2-dev/src/fsk.c index a426b511..5ee6b493 100644 --- a/codec2-dev/src/fsk.c +++ b/codec2-dev/src/fsk.c @@ -182,10 +182,8 @@ void fsk_demod_freq_est(struct FSK *fsk, float fsk_in[],float *f1_est,float *f2_ /* Array to do complex FFT from using kiss_fft */ /* It'd probably make more sense here to use kiss_fftr */ - //kiss_fft_scalar fftin[Ndft]; - kiss_fft_scalar *fftin = (kiss_fft_scalar*)malloc(sizeof(kiss_fft_scalar)*Ndft); - //kiss_fft_cpx fftout[(Ndft/2)+1]; - kiss_fft_cpx *fftout = (kiss_fft_cpx*)malloc(sizeof(kiss_fft_cpx)*(Ndft/2)+1); + 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); fft_samps = nin ((b.real*b.real)+(b.imag*b.imag)); } +/* + * 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; @@ -331,19 +333,13 @@ void fsk_demod(struct FSK *fsk, uint8_t rx_bits[], float fsk_in[]){ /* 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); - //f2_int = (COMP*) alloca(sizeof(COMP)*(nsym+1)*P); + f1_int = (COMP*) alloca(sizeof(COMP)*(nsym+1)*P); + f2_int = (COMP*) alloca(sizeof(COMP)*(nsym+1)*P); /* Allocate circular buffers for integration */ - //f1_intbuf = (COMP*) alloca(sizeof(COMP)*Ts); - //f2_intbuf = (COMP*) alloca(sizeof(COMP)*Ts); - /* Note: This must be kept after fsk_demod_freq_est for memory usage reasons */ - f1_int = (COMP*) malloc(sizeof(COMP)*(nsym+1)*P); - f2_int = (COMP*) malloc(sizeof(COMP)*(nsym+1)*P); - - /* Allocate circular buffers for integration */ - f1_intbuf = (COMP*) malloc(sizeof(COMP)*Ts); - f2_intbuf = (COMP*) malloc(sizeof(COMP)*Ts); + f1_intbuf = (COMP*) alloca(sizeof(COMP)*Ts); + f2_intbuf = (COMP*) alloca(sizeof(COMP)*Ts); + /* Note: This would all be quite a bit faster with complex oscillators, like * TX. */ @@ -531,13 +527,8 @@ void fsk_mod(struct FSK *fsk,float fsk_out[],uint8_t tx_bits[]){ COMP dosc_f1, dosc_f2; /* phase shift per sample */ COMP dph; /* phase shift of current bit */ int i,j; - float tx_phase_mag; /* Figure out the amount of phase shift needed per sample */ - /*dosc_f1.real = cosf(2*M_PI*((float)(f1_tx)/(float)(Fs))); - dosc_f1.imag = sinf(2*M_PI*((float)(f1_tx)/(float)(Fs))); - dosc_f2.real = cosf(2*M_PI*((float)(f2_tx)/(float)(Fs))); - dosc_f2.imag = sinf(2*M_PI*((float)(f2_tx)/(float)(Fs)));*/ dosc_f1 = comp_exp_j(2*M_PI*((float)(f1_tx)/(float)(Fs))); dosc_f2 = comp_exp_j(2*M_PI*((float)(f2_tx)/(float)(Fs))); @@ -552,9 +543,7 @@ void fsk_mod(struct FSK *fsk,float fsk_out[],uint8_t tx_bits[]){ } /* Normalize TX phase to prevent drift */ - tx_phase_mag = cabsolute(tx_phase_c); - tx_phase_c.real = tx_phase_c.real/tx_phase_mag; - tx_phase_c.imag = tx_phase_c.imag/tx_phase_mag; + tx_phase_c = comp_normalize(tx_phase_c); /* save TX phase */ fsk->tx_phase_c = tx_phase_c; diff --git a/codec2-dev/src/fsk.h b/codec2-dev/src/fsk.h index 85e624ce..3f65e67f 100644 --- a/codec2-dev/src/fsk.h +++ b/codec2-dev/src/fsk.h @@ -64,8 +64,8 @@ struct FSK { /* Statistics generated by demod */ float EbNodB; /* Estimated EbNo in dB */ - int f1_est; /* Estimated f1 freq. */ - int f2_est; /* Estimated f2 freq. */ + float f1_est; /* Estimated f1 freq. */ + float f2_est; /* Estimated f2 freq. */ /* Parameters used by mod/demod and driving code */ int nin; /* Number of samples to feed the next demod cycle */ -- 2.25.1