From 21152d5b2f473df1a9057620e00be863ec297a43 Mon Sep 17 00:00:00 2001 From: drowe67 Date: Sun, 10 Jun 2012 11:29:29 +0000 Subject: [PATCH] sine.c converted to kiss_fft, phase & quantise left git-svn-id: https://svn.code.sf.net/p/freetel/code@539 01035d8c-6547-0410-b346-abe4f91aad63 --- codec2-dev/src/c2sim.c | 14 ++++++++------ codec2-dev/src/codec2.c | 4 +++- codec2-dev/src/codec2_internal.h | 1 + codec2-dev/src/sine.c | 31 ++++++++++++++++--------------- codec2-dev/src/sine.h | 2 +- 5 files changed, 29 insertions(+), 23 deletions(-) diff --git a/codec2-dev/src/c2sim.c b/codec2-dev/src/c2sim.c index 740c63eb..354c3452 100644 --- a/codec2-dev/src/c2sim.c +++ b/codec2-dev/src/c2sim.c @@ -47,7 +47,7 @@ #include "postfilter.h" #include "interp.h" -void synth_one_frame(short buf[], MODEL *model, float Sn_[], float Pn[]); +void synth_one_frame(kiss_fft_cfg fft_dec_cfg, short buf[], MODEL *model, float Sn_[], float Pn[]); void print_help(const struct option *long_options, int num_opts, char* argv[]); /*---------------------------------------------------------------------------*\ @@ -64,6 +64,7 @@ int main(int argc, char *argv[]) float Sn[M]; /* float input speech samples */ COMP Sw[FFT_ENC]; /* DFT of Sn[] */ kiss_fft_cfg fft_enc_cfg; + kiss_fft_cfg fft_dec_cfg; float w[M]; /* time domain hamming window */ COMP W[FFT_ENC]; /* DFT of w[] */ MODEL model; @@ -309,6 +310,7 @@ int main(int argc, char *argv[]) /* Initialise ------------------------------------------------------------*/ fft_enc_cfg = kiss_fft_alloc(FFT_ENC, 1, NULL, NULL); + fft_dec_cfg = kiss_fft_alloc(FFT_DEC, 0, NULL, NULL); make_analysis_window(fft_enc_cfg, w,W); make_synthesis_window(Pn); quantise_init(); @@ -662,7 +664,7 @@ int main(int argc, char *argv[]) order); if (postfilt) postfilter(&interp_model, &bg_est); - synth_one_frame(buf, &interp_model, Sn_, Pn); + synth_one_frame(fft_dec_cfg, buf, &interp_model, Sn_, Pn); //printf(" buf[0] %d\n", buf[0]); if (fout != NULL) fwrite(buf,sizeof(short),N,fout); @@ -673,7 +675,7 @@ int main(int argc, char *argv[]) phase_synth_zero_order(&model, ak, ex_phase, order); if (postfilt) postfilter(&model, &bg_est); - synth_one_frame(buf, &model, Sn_, Pn); + synth_one_frame(fft_dec_cfg, buf, &model, Sn_, Pn); //printf(" buf[0] %d\n", buf[0]); if (fout != NULL) fwrite(buf,sizeof(short),N,fout); @@ -696,7 +698,7 @@ int main(int argc, char *argv[]) phase_synth_zero_order(&model, ak, ex_phase, order); if (postfilt) postfilter(&model, &bg_est); - synth_one_frame(buf, &model, Sn_, Pn); + synth_one_frame(fft_dec_cfg, buf, &model, Sn_, Pn); if (fout != NULL) fwrite(buf,sizeof(short),N,fout); } @@ -735,11 +737,11 @@ int main(int argc, char *argv[]) return 0; } -void synth_one_frame(short buf[], MODEL *model, float Sn_[], float Pn[]) +void synth_one_frame(kiss_fft_cfg fft_dec_cfg, short buf[], MODEL *model, float Sn_[], float Pn[]) { int i; - synthesise(Sn_, model, Pn, 1); + synthesise(fft_dec_cfg, Sn_, model, Pn, 1); for(i=0; i 32767.0) diff --git a/codec2-dev/src/codec2.c b/codec2-dev/src/codec2.c index 79fb6b96..f55e33dc 100644 --- a/codec2-dev/src/codec2.c +++ b/codec2-dev/src/codec2.c @@ -104,6 +104,7 @@ struct CODEC2 * CODEC2_WIN32SUPPORT codec2_create(int mode) 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); + c2->fft_dec_cfg = kiss_fft_alloc(FFT_DEC, 0, NULL, NULL); quantise_init(); c2->prev_Wo_enc = 0.0; c2->bg_est = 0.0; @@ -147,6 +148,7 @@ void CODEC2_WIN32SUPPORT codec2_destroy(struct CODEC2 *c2) assert(c2 != NULL); nlp_destroy(c2->nlp); KISS_FFT_FREE(c2->fft_enc_cfg); + KISS_FFT_FREE(c2->fft_dec_cfg); free(c2); } @@ -737,7 +739,7 @@ void synthesise_one_frame(struct CODEC2 *c2, short speech[], MODEL *model, float phase_synth_zero_order(model, ak, &c2->ex_phase, LPC_ORD); postfilter(model, &c2->bg_est); - synthesise(c2->Sn_, model, c2->Pn, 1); + synthesise(c2->fft_dec_cfg, c2->Sn_, model, c2->Pn, 1); for(i=0; iSn_[i] > 32767.0) diff --git a/codec2-dev/src/codec2_internal.h b/codec2-dev/src/codec2_internal.h index 88cb7d1f..2060a97a 100644 --- a/codec2-dev/src/codec2_internal.h +++ b/codec2-dev/src/codec2_internal.h @@ -39,6 +39,7 @@ struct CODEC2 { float hpf_states[2]; /* high pass filter states */ void *nlp; /* pitch predictor states */ + kiss_fft_cfg fft_dec_cfg; /* FFT config for decoder */ float Sn_[2*N]; /* synthesised output speech */ float ex_phase; /* excitation model phase track */ float bg_est; /* background noise estimate for post filter */ diff --git a/codec2-dev/src/sine.c b/codec2-dev/src/sine.c index 9f46b981..392554c9 100644 --- a/codec2-dev/src/sine.c +++ b/codec2-dev/src/sine.c @@ -134,8 +134,6 @@ void make_analysis_window(kiss_fft_cfg fft_enc_cfg, float w[], COMP W[]) kiss_fft(fft_enc_cfg, (kiss_fft_cpx *)wshift, (kiss_fft_cpx *)W); - // fft(&W[0].real,FFT_ENC,-1); /* "Numerical Recipes in C" FFT */ - /* Re-arrange W[] to be symmetrical about FFT_ENC/2. Makes later analysis convenient. @@ -203,11 +201,12 @@ float hpf(float x, float states[]) void dft_speech(kiss_fft_cfg fft_enc_cfg, COMP Sw[], float Sn[], float w[]) { - int i; - + int i; + COMP sw[FFT_ENC]; + for(i=0; iphi[m] = atan2(Sw[b].imag,Sw[b].real); + model->phi[m] = atan2(-Sw[b].imag,Sw[b].real); } } @@ -558,6 +557,7 @@ void make_synthesis_window(float Pn[]) \*---------------------------------------------------------------------------*/ void synthesise( + kiss_fft_cfg fft_dec_cfg, float Sn_[], /* time domain synthesised signal */ MODEL *model, /* ptr to model parameters for this frame */ float Pn[], /* time domain Parzen window */ @@ -566,6 +566,7 @@ void synthesise( { int i,l,j,b; /* loop variables */ COMP Sw_[FFT_DEC]; /* DFT of synthesised signal */ + COMP sw_[FFT_DEC]; /* synthesised signal */ if (shift) { /* Update memories */ @@ -606,14 +607,14 @@ void synthesise( b = (FFT_DEC/2)-1; } Sw_[b].real = model->A[l]*cos(model->phi[l]); - Sw_[b].imag = model->A[l]*sin(model->phi[l]); + Sw_[b].imag = -model->A[l]*sin(model->phi[l]); Sw_[FFT_DEC-b].real = Sw_[b].real; Sw_[FFT_DEC-b].imag = -Sw_[b].imag; } /* Perform inverse DFT */ - fft(&Sw_[0].real,FFT_DEC,1); + kiss_fft(fft_dec_cfg, (kiss_fft_cpx *)Sw_, (kiss_fft_cpx *)sw_); #else /* Direct time domain synthesis using the cos() function. Works @@ -634,14 +635,14 @@ void synthesise( /* Overlap add to previous samples */ for(i=0; i