From: drowe67 Date: Sun, 10 Jun 2012 10:21:02 +0000 (+0000) Subject: kiss fft port - make_window working X-Git-Url: http://git.whiteaudio.com/gitweb/?a=commitdiff_plain;h=edf6d0ff7b56c14070c0997242d48e70a79bce75;p=freetel-svn-tracking.git kiss fft port - make_window working git-svn-id: https://svn.code.sf.net/p/freetel/code@538 01035d8c-6547-0410-b346-abe4f91aad63 --- diff --git a/codec2-dev/src/c2sim.c b/codec2-dev/src/c2sim.c index 983111cf..740c63eb 100644 --- a/codec2-dev/src/c2sim.c +++ b/codec2-dev/src/c2sim.c @@ -63,6 +63,7 @@ int main(int argc, char *argv[]) short buf[N]; /* input/output buffer */ float Sn[M]; /* float input speech samples */ COMP Sw[FFT_ENC]; /* DFT of Sn[] */ + kiss_fft_cfg fft_enc_cfg; float w[M]; /* time domain hamming window */ COMP W[FFT_ENC]; /* DFT of w[] */ MODEL model; @@ -307,7 +308,8 @@ int main(int argc, char *argv[]) /* Initialise ------------------------------------------------------------*/ - make_analysis_window(w,W); + fft_enc_cfg = kiss_fft_alloc(FFT_ENC, 1, NULL, NULL); + make_analysis_window(fft_enc_cfg, w,W); make_synthesis_window(Pn); quantise_init(); @@ -339,7 +341,7 @@ int main(int argc, char *argv[]) nlp(nlp_states,Sn,N,M,P_MIN,P_MAX,&pitch,Sw,&prev_uq_Wo); model.Wo = TWO_PI/pitch; - dft_speech(Sw, Sn, w); + dft_speech(fft_enc_cfg, Sw, Sn, w); two_stage_pitch_refinement(&model, Sw); estimate_amplitudes(&model, Sw, W); uq_Wo = model.Wo; diff --git a/codec2-dev/src/codec2.c b/codec2-dev/src/codec2.c index 373f2fd4..79fb6b96 100644 --- a/codec2-dev/src/codec2.c +++ b/codec2-dev/src/codec2.c @@ -101,7 +101,8 @@ struct CODEC2 * CODEC2_WIN32SUPPORT codec2_create(int mode) c2->hpf_states[0] = c2->hpf_states[1] = 0.0; for(i=0; i<2*N; i++) c2->Sn_[i] = 0; - make_analysis_window(c2->w,c2->W); + c2->fft_enc_cfg = kiss_fft_alloc(FFT_ENC, 1, NULL, NULL); + make_analysis_window(c2->fft_enc_cfg, c2->w,c2->W); make_synthesis_window(c2->Pn); quantise_init(); c2->prev_Wo_enc = 0.0; @@ -145,6 +146,7 @@ void CODEC2_WIN32SUPPORT codec2_destroy(struct CODEC2 *c2) { assert(c2 != NULL); nlp_destroy(c2->nlp); + KISS_FFT_FREE(c2->fft_enc_cfg); free(c2); } @@ -774,7 +776,7 @@ void analyse_one_frame(struct CODEC2 *c2, MODEL *model, short speech[]) for(i=0; iSn[i+M-N] = speech[i]; - dft_speech(Sw, c2->Sn, c2->w); + dft_speech(c2->fft_enc_cfg, Sw, c2->Sn, c2->w); /* Estimate pitch */ diff --git a/codec2-dev/src/codec2_internal.h b/codec2-dev/src/codec2_internal.h index 9aa18552..88cb7d1f 100644 --- a/codec2-dev/src/codec2_internal.h +++ b/codec2-dev/src/codec2_internal.h @@ -30,23 +30,25 @@ #define __CODEC2_INTERNAL__ struct CODEC2 { - int mode; - float w[M]; /* time domain hamming window */ - COMP W[FFT_ENC]; /* DFT of w[] */ - float Pn[2*N]; /* trapezoidal synthesis window */ - float Sn[M]; /* input speech */ - float hpf_states[2]; /* high pass filter states */ - void *nlp; /* pitch predictor states */ - float Sn_[2*N]; /* synthesised output speech */ - float ex_phase; /* excitation model phase track */ - float bg_est; /* background noise estimate for post filter */ - float prev_Wo_enc; /* previous frame's pitch estimate */ - MODEL prev_model_dec; /* previous frame's model parameters */ - float prev_lsps_dec[LPC_ORD]; /* previous frame's LSPs */ - float prev_e_dec; /* previous frame's LPC energy */ - - float xq_enc[2]; /* joint pitch and energy VQ states */ - float xq_dec[2]; + int mode; + kiss_fft_cfg fft_enc_cfg; /* FFT config for encoder */ + float w[M]; /* time domain hamming window */ + COMP W[FFT_ENC]; /* DFT of w[] */ + float Pn[2*N]; /* trapezoidal synthesis window */ + float Sn[M]; /* input speech */ + float hpf_states[2]; /* high pass filter states */ + void *nlp; /* pitch predictor states */ + + float Sn_[2*N]; /* synthesised output speech */ + float ex_phase; /* excitation model phase track */ + float bg_est; /* background noise estimate for post filter */ + float prev_Wo_enc; /* previous frame's pitch estimate */ + MODEL prev_model_dec; /* previous frame's model parameters */ + float prev_lsps_dec[LPC_ORD]; /* previous frame's LSPs */ + float prev_e_dec; /* previous frame's LPC energy */ + + float xq_enc[2]; /* joint pitch and energy VQ states */ + float xq_dec[2]; }; #endif diff --git a/codec2-dev/src/fdmdv.c b/codec2-dev/src/fdmdv.c index c5a6ba1a..8b7c9640 100644 --- a/codec2-dev/src/fdmdv.c +++ b/codec2-dev/src/fdmdv.c @@ -1362,37 +1362,55 @@ void CODEC2_WIN32SUPPORT fdmdv_48_to_8(float out8k[], float in48k[], int n) The output can be used to plot a spectrum of the demod input. Sucessive calls can be used to build up a waterfall or spectrogram - plot, but mapping the levels to colours. + plot, by mapping the received levels to colours. + + The time-frequency resolution of the FFT can be adjusted by varying + FDMDV_NFFT. Note that a 2*FDMDV_NFFT size FFT is reqd to get + FDMDV_NFFT output points. \*---------------------------------------------------------------------------*/ void CODEC2_WIN32SUPPORT fdmdv_get_fft(struct FDMDV *f, float mag_dB[], float rx_fdm[], int nin) { int i,j; - COMP F[2*FDMDV_NFFT]; + COMP fft_io[2*FDMDV_NFFT]; float fullscale_dB; +#ifdef TT /* update buffer of input samples */ for(i=0; i<2*FDMDV_NFFT-nin; i++) f->fft_buf[i] = f->fft_buf[i+nin]; for(j=0; jfft_buf[i] = rx_fdm[j]; + assert(i == 2*FDMDV_NFFT); /* window and FFT */ for(i=0; i<2*FDMDV_NFFT; i++) { - F[i].real = f->fft_buf[i] * (0.5 - 0.5*cos((float)i*2.0*PI/FDMDV_NFFT)); - F[i].imag = 0.0; + fft_io[i].real = f->fft_buf[i] * (0.5 - 0.5*cos((float)i*2.0*PI/(2*FDMDV_NFFT))); + fft_io[i].imag = 0.0; + } +#endif + for(i=0; i<2*FDMDV_NFFT; i++) { + fft_io[i].real = 1.0; + fft_io[i].imag = 0.0; } - fft(&F[0].real, 2*FDMDV_NFFT, -1); + fft(&fft_io[0].real, 2*FDMDV_NFFT, -1); + printf("%d fft_io[%d] %f %f\n", FDMDV_NFFT,0, fft_io[0].real, fft_io[0].imag); + +#ifdef TMP /* scale and convert to dB */ - fullscale_dB = 20*log10(FDMDV_NFFT*32767.0); + fullscale_dB = 20.0*log10(FDMDV_NFFT*32767.0); + for(i=0; ifft_cfg, (kiss_fft_cpx *)fw, (kiss_fft_cpx *)Fw); + kiss_fft(nlp->fft_cfg, (kiss_fft_cpx *)fw, (kiss_fft_cpx *)Fw); //fft(&Fw[0].real,PE_FFT_SIZE,1); for(i=0; i