From 52d01dc1563c8390d3977d4ecfbc2a2f01c71884 Mon Sep 17 00:00:00 2001 From: drowe67 Date: Mon, 11 Jun 2012 00:53:37 +0000 Subject: [PATCH] found out kiss fft direction was the wrong way around so went back and fixed it everywhere git-svn-id: https://svn.code.sf.net/p/freetel/code@541 01035d8c-6547-0410-b346-abe4f91aad63 --- codec2-dev/octave/tfdmdv.m | 2 +- codec2-dev/src/Makefile.am | 1 - codec2-dev/src/Makefile.in | 24 ++++++-------------- codec2-dev/src/c2sim.c | 34 ++++++++++++++-------------- codec2-dev/src/codec2.c | 22 +++++++++--------- codec2-dev/src/codec2_internal.h | 4 ++-- codec2-dev/src/fdmdv.c | 21 +++++++++++------ codec2-dev/src/fdmdv_internal.h | 4 +++- codec2-dev/src/interp.c | 4 ++-- codec2-dev/src/nlp.c | 11 +++++---- codec2-dev/src/phase.c | 16 ++++++------- codec2-dev/src/quantise.c | 16 ++++++------- codec2-dev/src/quantise.h | 2 +- codec2-dev/src/sine.c | 16 ++++++------- codec2-dev/src/sine.h | 6 ++--- codec2-dev/unittest/Makefile.am | 7 +----- codec2-dev/unittest/Makefile.in | 39 +++++++++----------------------- codec2-dev/unittest/tlspsens.c | 4 +++- codec2-dev/unittest/tnlp.c | 7 ++++-- 19 files changed, 111 insertions(+), 129 deletions(-) diff --git a/codec2-dev/octave/tfdmdv.m b/codec2-dev/octave/tfdmdv.m index 67f4ac02..787913cf 100644 --- a/codec2-dev/octave/tfdmdv.m +++ b/codec2-dev/octave/tfdmdv.m @@ -270,7 +270,7 @@ function check(a, b, test_name) end printf(": "); - if abs(sum(a - b))/n < 1E-3 + if sum(abs(a - b))/n < 1E-3 printf("OK\n"); passes++; else diff --git a/codec2-dev/src/Makefile.am b/codec2-dev/src/Makefile.am index 6ba41367..84904375 100644 --- a/codec2-dev/src/Makefile.am +++ b/codec2-dev/src/Makefile.am @@ -101,7 +101,6 @@ postfilter.c \ sine.c \ codec2.c \ fdmdv.c \ -fft.c \ kiss_fft.c \ interp.c \ lsp.c \ diff --git a/codec2-dev/src/Makefile.in b/codec2-dev/src/Makefile.in index 1989a457..0c62be50 100644 --- a/codec2-dev/src/Makefile.in +++ b/codec2-dev/src/Makefile.in @@ -66,14 +66,13 @@ libcodec2_la_LIBADD = am_libcodec2_la_OBJECTS = libcodec2_la-dump.lo libcodec2_la-lpc.lo \ libcodec2_la-nlp.lo libcodec2_la-postfilter.lo \ libcodec2_la-sine.lo libcodec2_la-codec2.lo \ - libcodec2_la-fdmdv.lo libcodec2_la-fft.lo \ - libcodec2_la-kiss_fft.lo libcodec2_la-interp.lo \ - libcodec2_la-lsp.lo libcodec2_la-phase.lo \ - libcodec2_la-quantise.lo libcodec2_la-pack.lo \ - libcodec2_la-codebook.lo libcodec2_la-codebookd.lo \ - libcodec2_la-codebookvq.lo libcodec2_la-codebookjnd.lo \ - libcodec2_la-codebookjvm.lo libcodec2_la-codebookdt.lo \ - libcodec2_la-codebookge.lo + libcodec2_la-fdmdv.lo libcodec2_la-kiss_fft.lo \ + libcodec2_la-interp.lo libcodec2_la-lsp.lo \ + libcodec2_la-phase.lo libcodec2_la-quantise.lo \ + libcodec2_la-pack.lo libcodec2_la-codebook.lo \ + libcodec2_la-codebookd.lo libcodec2_la-codebookvq.lo \ + libcodec2_la-codebookjnd.lo libcodec2_la-codebookjvm.lo \ + libcodec2_la-codebookdt.lo libcodec2_la-codebookge.lo libcodec2_la_OBJECTS = $(am_libcodec2_la_OBJECTS) binPROGRAMS_INSTALL = $(INSTALL_PROGRAM) PROGRAMS = $(bin_PROGRAMS) $(noinst_PROGRAMS) @@ -309,7 +308,6 @@ postfilter.c \ sine.c \ codec2.c \ fdmdv.c \ -fft.c \ kiss_fft.c \ interp.c \ lsp.c \ @@ -511,7 +509,6 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcodec2_la-codec2.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcodec2_la-dump.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcodec2_la-fdmdv.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcodec2_la-fft.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcodec2_la-interp.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcodec2_la-kiss_fft.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcodec2_la-lpc.Plo@am__quote@ @@ -594,13 +591,6 @@ libcodec2_la-fdmdv.lo: fdmdv.c @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcodec2_la_CFLAGS) $(CFLAGS) -c -o libcodec2_la-fdmdv.lo `test -f 'fdmdv.c' || echo '$(srcdir)/'`fdmdv.c -libcodec2_la-fft.lo: fft.c -@am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcodec2_la_CFLAGS) $(CFLAGS) -MT libcodec2_la-fft.lo -MD -MP -MF "$(DEPDIR)/libcodec2_la-fft.Tpo" -c -o libcodec2_la-fft.lo `test -f 'fft.c' || echo '$(srcdir)/'`fft.c; \ -@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libcodec2_la-fft.Tpo" "$(DEPDIR)/libcodec2_la-fft.Plo"; else rm -f "$(DEPDIR)/libcodec2_la-fft.Tpo"; exit 1; fi -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='fft.c' object='libcodec2_la-fft.lo' libtool=yes @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcodec2_la_CFLAGS) $(CFLAGS) -c -o libcodec2_la-fft.lo `test -f 'fft.c' || echo '$(srcdir)/'`fft.c - libcodec2_la-kiss_fft.lo: kiss_fft.c @am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcodec2_la_CFLAGS) $(CFLAGS) -MT libcodec2_la-kiss_fft.lo -MD -MP -MF "$(DEPDIR)/libcodec2_la-kiss_fft.Tpo" -c -o libcodec2_la-kiss_fft.lo `test -f 'kiss_fft.c' || echo '$(srcdir)/'`kiss_fft.c; \ @am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libcodec2_la-kiss_fft.Tpo" "$(DEPDIR)/libcodec2_la-kiss_fft.Plo"; else rm -f "$(DEPDIR)/libcodec2_la-kiss_fft.Tpo"; exit 1; fi diff --git a/codec2-dev/src/c2sim.c b/codec2-dev/src/c2sim.c index 51089be4..5a412ea2 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(kiss_fft_cfg fft_dec_cfg, short buf[], MODEL *model, float Sn_[], float Pn[]); +void synth_one_frame(kiss_fft_cfg fft_inv_cfg, short buf[], MODEL *model, float Sn_[], float Pn[]); void print_help(const struct option *long_options, int num_opts, char* argv[]); /*---------------------------------------------------------------------------*\ @@ -63,8 +63,8 @@ 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; - kiss_fft_cfg fft_dec_cfg; + kiss_fft_cfg fft_fwd_cfg; + kiss_fft_cfg fft_inv_cfg; float w[M]; /* time domain hamming window */ COMP W[FFT_ENC]; /* DFT of w[] */ MODEL model; @@ -309,9 +309,9 @@ 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); + fft_fwd_cfg = kiss_fft_alloc(FFT_ENC, 0, NULL, NULL); /* fwd FFT,used in several places */ + fft_inv_cfg = kiss_fft_alloc(FFT_DEC, 1, NULL, NULL); /* inverse FFT, used just for synth */ + make_analysis_window(fft_fwd_cfg, w, W); make_synthesis_window(Pn); quantise_init(); @@ -343,7 +343,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(fft_enc_cfg, Sw, Sn, w); + dft_speech(fft_fwd_cfg, Sw, Sn, w); two_stage_pitch_refinement(&model, Sw); estimate_amplitudes(&model, Sw, W); uq_Wo = model.Wo; @@ -574,7 +574,7 @@ int main(int argc, char *argv[]) } - aks_to_M2(fft_dec_cfg, ak, order, &model, e, &snr, 1); + aks_to_M2(fft_fwd_cfg, ak, order, &model, e, &snr, 1); /* note SNR on interpolated frames can't be measured properly by comparing Am as L has changed. We can dump interp lsps @@ -625,7 +625,7 @@ int main(int argc, char *argv[]) interp_model.voiced = voiced1; - interpolate_lsp(fft_dec_cfg, &interp_model, &prev_model, &model, + interpolate_lsp(fft_fwd_cfg, &interp_model, &prev_model, &model, prev_lsps_, prev_e, lsps_, e, ak_interp, lsps_interp); apply_lpc_correction(&interp_model); @@ -660,11 +660,11 @@ int main(int argc, char *argv[]) #endif if (phase0) - phase_synth_zero_order(fft_dec_cfg, &interp_model, ak_interp, ex_phase, + phase_synth_zero_order(fft_fwd_cfg, &interp_model, ak_interp, ex_phase, order); if (postfilt) postfilter(&interp_model, &bg_est); - synth_one_frame(fft_dec_cfg, buf, &interp_model, Sn_, Pn); + synth_one_frame(fft_inv_cfg, buf, &interp_model, Sn_, Pn); //printf(" buf[0] %d\n", buf[0]); if (fout != NULL) fwrite(buf,sizeof(short),N,fout); @@ -672,10 +672,10 @@ int main(int argc, char *argv[]) /* decode this frame */ if (phase0) - phase_synth_zero_order(fft_dec_cfg, &model, ak, ex_phase, order); + phase_synth_zero_order(fft_fwd_cfg, &model, ak, ex_phase, order); if (postfilt) postfilter(&model, &bg_est); - synth_one_frame(fft_dec_cfg, buf, &model, Sn_, Pn); + synth_one_frame(fft_inv_cfg, buf, &model, Sn_, Pn); //printf(" buf[0] %d\n", buf[0]); if (fout != NULL) fwrite(buf,sizeof(short),N,fout); @@ -695,10 +695,10 @@ int main(int argc, char *argv[]) /* no decimation - sythesise each 10ms frame immediately */ if (phase0) - phase_synth_zero_order(fft_dec_cfg, &model, ak, ex_phase, order); + phase_synth_zero_order(fft_fwd_cfg, &model, ak, ex_phase, order); if (postfilt) postfilter(&model, &bg_est); - synth_one_frame(fft_dec_cfg, buf, &model, Sn_, Pn); + synth_one_frame(fft_inv_cfg, buf, &model, Sn_, Pn); if (fout != NULL) fwrite(buf,sizeof(short),N,fout); } @@ -737,11 +737,11 @@ int main(int argc, char *argv[]) return 0; } -void synth_one_frame(kiss_fft_cfg fft_dec_cfg, short buf[], MODEL *model, float Sn_[], float Pn[]) +void synth_one_frame(kiss_fft_cfg fft_inv_cfg, short buf[], MODEL *model, float Sn_[], float Pn[]) { int i; - synthesise(fft_dec_cfg, Sn_, model, Pn, 1); + synthesise(fft_inv_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 b981c7ef..7b848392 100644 --- a/codec2-dev/src/codec2.c +++ b/codec2-dev/src/codec2.c @@ -101,10 +101,10 @@ 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; - c2->fft_enc_cfg = kiss_fft_alloc(FFT_ENC, 1, NULL, NULL); - make_analysis_window(c2->fft_enc_cfg, c2->w,c2->W); + c2->fft_fwd_cfg = kiss_fft_alloc(FFT_ENC, 0, NULL, NULL); + make_analysis_window(c2->fft_fwd_cfg, c2->w,c2->W); make_synthesis_window(c2->Pn); - c2->fft_dec_cfg = kiss_fft_alloc(FFT_DEC, 0, NULL, NULL); + c2->fft_inv_cfg = kiss_fft_alloc(FFT_DEC, 1, NULL, NULL); quantise_init(); c2->prev_Wo_enc = 0.0; c2->bg_est = 0.0; @@ -147,8 +147,8 @@ 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); + KISS_FFT_FREE(c2->fft_fwd_cfg); + KISS_FFT_FREE(c2->fft_inv_cfg); free(c2); } @@ -356,7 +356,7 @@ void codec2_decode_2400(struct CODEC2 *c2, short speech[], const unsigned char * interpolate_lsp_ver2(&lsps[0][0], c2->prev_lsps_dec, &lsps[1][0], 0.5); for(i=0; i<2; i++) { lsp_to_lpc(&lsps[i][0], &ak[i][0], LPC_ORD); - aks_to_M2(c2->fft_dec_cfg, &ak[i][0], LPC_ORD, &model[i], e[i], &snr, 1); + aks_to_M2(c2->fft_fwd_cfg, &ak[i][0], LPC_ORD, &model[i], e[i], &snr, 1); apply_lpc_correction(&model[i]); } @@ -528,7 +528,7 @@ void codec2_decode_1400(struct CODEC2 *c2, short speech[], const unsigned char * } for(i=0; i<4; i++) { lsp_to_lpc(&lsps[i][0], &ak[i][0], LPC_ORD); - aks_to_M2(c2->fft_dec_cfg, &ak[i][0], LPC_ORD, &model[i], e[i], &snr, 1); + aks_to_M2(c2->fft_fwd_cfg, &ak[i][0], LPC_ORD, &model[i], e[i], &snr, 1); apply_lpc_correction(&model[i]); } @@ -705,7 +705,7 @@ void codec2_decode_1200(struct CODEC2 *c2, short speech[], const unsigned char * } for(i=0; i<4; i++) { lsp_to_lpc(&lsps[i][0], &ak[i][0], LPC_ORD); - aks_to_M2(c2->fft_dec_cfg, &ak[i][0], LPC_ORD, &model[i], e[i], &snr, 1); + aks_to_M2(c2->fft_fwd_cfg, &ak[i][0], LPC_ORD, &model[i], e[i], &snr, 1); apply_lpc_correction(&model[i]); } @@ -737,9 +737,9 @@ void synthesise_one_frame(struct CODEC2 *c2, short speech[], MODEL *model, float { int i; - phase_synth_zero_order(c2->fft_dec_cfg, model, ak, &c2->ex_phase, LPC_ORD); + phase_synth_zero_order(c2->fft_fwd_cfg, model, ak, &c2->ex_phase, LPC_ORD); postfilter(model, &c2->bg_est); - synthesise(c2->fft_dec_cfg, c2->Sn_, model, c2->Pn, 1); + synthesise(c2->fft_inv_cfg, c2->Sn_, model, c2->Pn, 1); for(i=0; iSn_[i] > 32767.0) @@ -778,7 +778,7 @@ void analyse_one_frame(struct CODEC2 *c2, MODEL *model, short speech[]) for(i=0; iSn[i+M-N] = speech[i]; - dft_speech(c2->fft_enc_cfg, Sw, c2->Sn, c2->w); + dft_speech(c2->fft_fwd_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 2060a97a..df5b8e21 100644 --- a/codec2-dev/src/codec2_internal.h +++ b/codec2-dev/src/codec2_internal.h @@ -31,7 +31,7 @@ struct CODEC2 { int mode; - kiss_fft_cfg fft_enc_cfg; /* FFT config for encoder */ + kiss_fft_cfg fft_fwd_cfg; /* forward FFT config */ float w[M]; /* time domain hamming window */ COMP W[FFT_ENC]; /* DFT of w[] */ float Pn[2*N]; /* trapezoidal synthesis window */ @@ -39,7 +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 */ + kiss_fft_cfg fft_inv_cfg; /* inverse FFT config */ 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/fdmdv.c b/codec2-dev/src/fdmdv.c index 8b7c9640..9f02ac1c 100644 --- a/codec2-dev/src/fdmdv.c +++ b/codec2-dev/src/fdmdv.c @@ -42,6 +42,7 @@ #include "rn.h" #include "test_bits.h" #include "pilot_coeff.h" +#include "kiss_fft.h" #include "fft.h" #include "hanning.h" #include "os.h" @@ -195,6 +196,9 @@ struct FDMDV * CODEC2_WIN32SUPPORT fdmdv_create(void) /* freq Offset estimation states */ + f->fft_pilot_cfg = kiss_fft_alloc (MPILOTFFT, 0, NULL, NULL); + assert(f->fft_pilot_cfg != NULL); + for(i=0; ipilot_baseband1[i].real = f->pilot_baseband2[i].real = 0.0; f->pilot_baseband1[i].imag = f->pilot_baseband2[i].imag = 0.0; @@ -240,6 +244,7 @@ struct FDMDV * CODEC2_WIN32SUPPORT fdmdv_create(void) void CODEC2_WIN32SUPPORT fdmdv_destroy(struct FDMDV *fdmdv) { assert(fdmdv != NULL); + KISS_FFT_FREE(fdmdv->fft_pilot_cfg); free(fdmdv); } @@ -561,10 +566,12 @@ void generate_pilot_lut(COMP pilot_lut[], COMP *pilot_freq) \*---------------------------------------------------------------------------*/ -void lpf_peak_pick(float *foff, float *max, COMP pilot_baseband[], COMP pilot_lpf[], COMP S[], int nin) +void lpf_peak_pick(float *foff, float *max, COMP pilot_baseband[], + COMP pilot_lpf[], kiss_fft_cfg fft_pilot_cfg, COMP S[], int nin) { int i,j,k; int mpilot; + COMP s[MPILOTFFT]; float mag, imax; int ix; float r; @@ -583,13 +590,13 @@ void lpf_peak_pick(float *foff, float *max, COMP pilot_baseband[], COMP pilot_lp mpilot = FS/(2*200); /* calc decimation rate given new sample rate is twice LPF freq */ for(i=0; ipilot_baseband2[j] = fcmult(rx_fdm[i], cconj(prev_pilot[i])); } - lpf_peak_pick(&foff1, &max1, f->pilot_baseband1, f->pilot_lpf1, f->S1, nin); - lpf_peak_pick(&foff2, &max2, f->pilot_baseband2, f->pilot_lpf2, f->S2, nin); + lpf_peak_pick(&foff1, &max1, f->pilot_baseband1, f->pilot_lpf1, f->fft_pilot_cfg, f->S1, nin); + lpf_peak_pick(&foff2, &max2, f->pilot_baseband2, f->pilot_lpf2, f->fft_pilot_cfg, f->S2, nin); if (max1 > max2) foff = foff1; @@ -1396,7 +1403,7 @@ void CODEC2_WIN32SUPPORT fdmdv_get_fft(struct FDMDV *f, float mag_dB[], float rx fft_io[i].real = 1.0; fft_io[i].imag = 0.0; } - fft(&fft_io[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 diff --git a/codec2-dev/src/fdmdv_internal.h b/codec2-dev/src/fdmdv_internal.h index fa49acc8..a712e57d 100644 --- a/codec2-dev/src/fdmdv_internal.h +++ b/codec2-dev/src/fdmdv_internal.h @@ -31,6 +31,7 @@ #include "comp.h" #include "fdmdv.h" +#include "kiss_fft.h" /*---------------------------------------------------------------------------*\ @@ -100,6 +101,7 @@ struct FDMDV { /* freq offset estimation states */ + kiss_fft_cfg fft_pilot_cfg; COMP pilot_baseband1[NPILOTBASEBAND]; COMP pilot_baseband2[NPILOTBASEBAND]; COMP pilot_lpf1[NPILOTLPF]; @@ -150,7 +152,7 @@ void fdm_upconvert(COMP tx_fdm[], COMP tx_baseband[NC+1][M], COMP phase_tx[], CO void generate_pilot_fdm(COMP *pilot_fdm, int *bit, float *symbol, float *filter_mem, COMP *phase, COMP *freq); void generate_pilot_lut(COMP pilot_lut[], COMP *pilot_freq); float rx_est_freq_offset(struct FDMDV *f, float rx_fdm[], int nin); -void lpf_peak_pick(float *foff, float *max, COMP pilot_baseband[], COMP pilot_lpf[], COMP S[], int nin); +void lpf_peak_pick(float *foff, float *max, COMP pilot_baseband[], COMP pilot_lpf[], kiss_fft_cfg fft_pilot_cfg, COMP S[], int nin); void freq_shift(COMP rx_fdm_fcorr[], float rx_fdm[], float foff, COMP *foff_rect, COMP *foff_phase_rect, int nin); void fdm_downconvert(COMP rx_baseband[NC+1][M+M/P], COMP rx_fdm[], COMP phase_rx[], COMP freq[], int nin); void rx_filter(COMP rx_filt[NC+1][P+1], COMP rx_baseband[NC+1][M+M/P], COMP rx_filter_memory[NC+1][NFILTER], int nin); diff --git a/codec2-dev/src/interp.c b/codec2-dev/src/interp.c index 2aca6b26..e7ae2d38 100644 --- a/codec2-dev/src/interp.c +++ b/codec2-dev/src/interp.c @@ -146,7 +146,7 @@ float sample_log_amp(MODEL *model, float w) \*---------------------------------------------------------------------------*/ void interpolate_lsp( - kiss_fft_cfg fft_dec_cfg, + kiss_fft_cfg fft_fwd_cfg, MODEL *interp, /* interpolated model params */ MODEL *prev, /* previous frames model params */ MODEL *next, /* next frames model params */ @@ -201,7 +201,7 @@ void interpolate_lsp( /* convert back to amplitudes */ lsp_to_lpc(lsps_interp, ak_interp, LPC_ORD); - aks_to_M2(fft_dec_cfg, ak_interp, LPC_ORD, interp, e, &snr, 0); + aks_to_M2(fft_fwd_cfg, ak_interp, LPC_ORD, interp, e, &snr, 0); //printf(" interp: ak[1]: %f A[1] %f\n", ak_interp[1], interp->A[1]); } diff --git a/codec2-dev/src/nlp.c b/codec2-dev/src/nlp.c index c417020a..ef58c57e 100644 --- a/codec2-dev/src/nlp.c +++ b/codec2-dev/src/nlp.c @@ -146,7 +146,7 @@ void *nlp_create() for(i=0; imem_fir[i] = 0.0; - nlp->fft_cfg = kiss_fft_alloc (PE_FFT_SIZE, 1, NULL, NULL); + nlp->fft_cfg = kiss_fft_alloc (PE_FFT_SIZE, 0, NULL, NULL); assert(nlp->fft_cfg != NULL); return (void*)nlp; @@ -257,17 +257,18 @@ float nlp( for(i=0; isq[i*DEC]*(0.5 - 0.5*cos(2*PI*i/(m/DEC-1))); } -#ifdef DUMP + #ifdef DUMP dump_dec(Fw); -#endif + #endif + kiss_fft(nlp->fft_cfg, (kiss_fft_cpx *)fw, (kiss_fft_cpx *)Fw); for(i=0; isq); dump_Fw(Fw); -#endif + #endif /* find global peak */ diff --git a/codec2-dev/src/phase.c b/codec2-dev/src/phase.c index 5701020f..563103cd 100644 --- a/codec2-dev/src/phase.c +++ b/codec2-dev/src/phase.c @@ -48,7 +48,7 @@ \*---------------------------------------------------------------------------*/ void aks_to_H( - kiss_fft_cfg fft_dec_cfg, + kiss_fft_cfg fft_fwd_cfg, MODEL *model, /* model parameters */ float aks[], /* LPC's */ float G, /* energy term */ @@ -56,8 +56,8 @@ void aks_to_H( int order ) { - COMP pw[FFT_DEC]; /* power spectrum (input) */ - COMP Pw[FFT_DEC]; /* power spectrum (output) */ + COMP pw[FFT_ENC]; /* power spectrum (input) */ + COMP Pw[FFT_ENC]; /* power spectrum (output) */ int i,m; /* loop variables */ int am,bm; /* limits of current band */ float r; /* no. rads/bin */ @@ -66,11 +66,11 @@ void aks_to_H( int b; /* centre bin of harmonic */ float phi_; /* phase of LPC spectra */ - r = TWO_PI/(FFT_DEC); + r = TWO_PI/(FFT_ENC); /* Determine DFT of A(exp(jw)) ------------------------------------------*/ - for(i=0; iphi[m] = atan2(-Sw[b].imag,Sw[b].real); + model->phi[m] = atan2(Sw[b].imag,Sw[b].real); } } @@ -557,7 +557,7 @@ void make_synthesis_window(float Pn[]) \*---------------------------------------------------------------------------*/ void synthesise( - kiss_fft_cfg fft_dec_cfg, + kiss_fft_cfg fft_inv_cfg, float Sn_[], /* time domain synthesised signal */ MODEL *model, /* ptr to model parameters for this frame */ float Pn[], /* time domain Parzen window */ @@ -607,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 */ - kiss_fft(fft_dec_cfg, (kiss_fft_cpx *)Sw_, (kiss_fft_cpx *)sw_); + kiss_fft(fft_inv_cfg, (kiss_fft_cpx *)Sw_, (kiss_fft_cpx *)sw_); #else /* Direct time domain synthesis using the cos() function. Works diff --git a/codec2-dev/src/sine.h b/codec2-dev/src/sine.h index 0a173a90..202adfd2 100644 --- a/codec2-dev/src/sine.h +++ b/codec2-dev/src/sine.h @@ -32,14 +32,14 @@ #include "comp.h" #include "kiss_fft.h" -void make_analysis_window(kiss_fft_cfg fft_enc_cfg, float w[], COMP W[]); +void make_analysis_window(kiss_fft_cfg fft_fwd_cfg, float w[], COMP W[]); float hpf(float x, float states[]); -void dft_speech(kiss_fft_cfg fft_enc_cfg, COMP Sw[], float Sn[], float w[]); +void dft_speech(kiss_fft_cfg fft_fwd_cfg, COMP Sw[], float Sn[], float w[]); void two_stage_pitch_refinement(MODEL *model, COMP Sw[]); void estimate_amplitudes(MODEL *model, COMP Sw[], COMP W[]); float est_voicing_mbe(MODEL *model, COMP Sw[], COMP W[], COMP Sw_[],COMP Ew[], float prev_Wo); void make_synthesis_window(float Pn[]); -void synthesise(kiss_fft_cfg fft_dec_cfg, float Sn_[], MODEL *model, float Pn[], int shift); +void synthesise(kiss_fft_cfg fft_inv_cfg, float Sn_[], MODEL *model, float Pn[], int shift); #endif diff --git a/codec2-dev/unittest/Makefile.am b/codec2-dev/unittest/Makefile.am index 58e68d77..55f3df2e 100644 --- a/codec2-dev/unittest/Makefile.am +++ b/codec2-dev/unittest/Makefile.am @@ -3,7 +3,7 @@ AUTOMAKE_OPTS = gnu NAME = libcodec2 AM_CPPFLAGS = $(AM_CFLAGS) -noinst_PROGRAMS = genres genlsp extract vqtrain vqtrainjnd tnlp tinterp tquant tcodec2 vq_train_jvm scalarlsptest tfdmdv t48_8 lspsync create_interleaver tlspsens +noinst_PROGRAMS = genres genlsp extract vqtrain vqtrainjnd tnlp tinterp tquant vq_train_jvm scalarlsptest tfdmdv t48_8 lspsync create_interleaver tlspsens genres_SOURCES = genres.c ../src/lpc.c genres_LDADD = $(lib_LTLIBRARIES) @@ -43,11 +43,6 @@ tquant_SOURCES = tquant.c ../src/quantise.c ../src/lpc.c ../src/lsp.c ../src/dum tquant_LDADD = $(lib_LTLIBRARIES) tquant_LDFLAGS = $(LIBS) -tcodec2_SOURCES = tcodec2.c ../src/quantise.c ../src/lpc.c ../src/lsp.c ../src/dump.c ../src/fft.c ../src/kiss_fft.c \ -../src/codec2.c ../src/sine.c ../src/nlp.c ../src/postfilter.c ../src/phase.c ../src/interp.c ../src/pack.c $(CODEBOOKS) -tcodec2_LDADD = $(lib_LTLIBRARIES) -tcodec2_LDFLAGS = $(LIBS) - scalarlsptest_SOURCES = scalarlsptest.c ../src/quantise.c ../src/lpc.c ../src/lsp.c ../src/dump.c ../src/fft.c ../src/kiss_fft.c $(CODEBOOKS) scalarlsptest_LDADD = $(lib_LTLIBRARIES) scalarlsptest_LDFLAGS = $(LIBS) diff --git a/codec2-dev/unittest/Makefile.in b/codec2-dev/unittest/Makefile.in index f912b00f..86db4c26 100644 --- a/codec2-dev/unittest/Makefile.in +++ b/codec2-dev/unittest/Makefile.in @@ -38,10 +38,9 @@ build_triplet = @build@ host_triplet = @host@ noinst_PROGRAMS = genres$(EXEEXT) genlsp$(EXEEXT) extract$(EXEEXT) \ vqtrain$(EXEEXT) vqtrainjnd$(EXEEXT) tnlp$(EXEEXT) \ - tinterp$(EXEEXT) tquant$(EXEEXT) tcodec2$(EXEEXT) \ - vq_train_jvm$(EXEEXT) scalarlsptest$(EXEEXT) tfdmdv$(EXEEXT) \ - t48_8$(EXEEXT) lspsync$(EXEEXT) create_interleaver$(EXEEXT) \ - tlspsens$(EXEEXT) + tinterp$(EXEEXT) tquant$(EXEEXT) vq_train_jvm$(EXEEXT) \ + scalarlsptest$(EXEEXT) tfdmdv$(EXEEXT) t48_8$(EXEEXT) \ + lspsync$(EXEEXT) create_interleaver$(EXEEXT) tlspsens$(EXEEXT) subdir = unittest DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 @@ -83,13 +82,6 @@ am_t48_8_OBJECTS = t48_8.$(OBJEXT) fdmdv.$(OBJEXT) fft.$(OBJEXT) \ kiss_fft.$(OBJEXT) t48_8_OBJECTS = $(am_t48_8_OBJECTS) t48_8_DEPENDENCIES = -am_tcodec2_OBJECTS = tcodec2.$(OBJEXT) quantise.$(OBJEXT) \ - lpc.$(OBJEXT) lsp.$(OBJEXT) dump.$(OBJEXT) fft.$(OBJEXT) \ - kiss_fft.$(OBJEXT) codec2.$(OBJEXT) sine.$(OBJEXT) \ - nlp.$(OBJEXT) postfilter.$(OBJEXT) phase.$(OBJEXT) \ - interp.$(OBJEXT) pack.$(OBJEXT) $(am__objects_1) -tcodec2_OBJECTS = $(am_tcodec2_OBJECTS) -tcodec2_DEPENDENCIES = am_tfdmdv_OBJECTS = tfdmdv.$(OBJEXT) fdmdv.$(OBJEXT) fft.$(OBJEXT) \ kiss_fft.$(OBJEXT) octave.$(OBJEXT) tfdmdv_OBJECTS = $(am_tfdmdv_OBJECTS) @@ -138,16 +130,16 @@ LINK = $(LIBTOOL) --tag=CC --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ $(AM_LDFLAGS) $(LDFLAGS) -o $@ SOURCES = $(create_interleaver_SOURCES) $(extract_SOURCES) \ $(genlsp_SOURCES) $(genres_SOURCES) $(lspsync_SOURCES) \ - $(scalarlsptest_SOURCES) $(t48_8_SOURCES) $(tcodec2_SOURCES) \ - $(tfdmdv_SOURCES) $(tinterp_SOURCES) $(tlspsens_SOURCES) \ - $(tnlp_SOURCES) $(tquant_SOURCES) $(vq_train_jvm_SOURCES) \ - $(vqtrain_SOURCES) $(vqtrainjnd_SOURCES) + $(scalarlsptest_SOURCES) $(t48_8_SOURCES) $(tfdmdv_SOURCES) \ + $(tinterp_SOURCES) $(tlspsens_SOURCES) $(tnlp_SOURCES) \ + $(tquant_SOURCES) $(vq_train_jvm_SOURCES) $(vqtrain_SOURCES) \ + $(vqtrainjnd_SOURCES) DIST_SOURCES = $(create_interleaver_SOURCES) $(extract_SOURCES) \ $(genlsp_SOURCES) $(genres_SOURCES) $(lspsync_SOURCES) \ - $(scalarlsptest_SOURCES) $(t48_8_SOURCES) $(tcodec2_SOURCES) \ - $(tfdmdv_SOURCES) $(tinterp_SOURCES) $(tlspsens_SOURCES) \ - $(tnlp_SOURCES) $(tquant_SOURCES) $(vq_train_jvm_SOURCES) \ - $(vqtrain_SOURCES) $(vqtrainjnd_SOURCES) + $(scalarlsptest_SOURCES) $(t48_8_SOURCES) $(tfdmdv_SOURCES) \ + $(tinterp_SOURCES) $(tlspsens_SOURCES) $(tnlp_SOURCES) \ + $(tquant_SOURCES) $(vq_train_jvm_SOURCES) $(vqtrain_SOURCES) \ + $(vqtrainjnd_SOURCES) ETAGS = etags CTAGS = ctags DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) @@ -287,11 +279,6 @@ tinterp_LDFLAGS = $(LIBS) tquant_SOURCES = tquant.c ../src/quantise.c ../src/lpc.c ../src/lsp.c ../src/dump.c ../src/fft.c ../src/kiss_fft.c $(CODEBOOKS) tquant_LDADD = $(lib_LTLIBRARIES) tquant_LDFLAGS = $(LIBS) -tcodec2_SOURCES = tcodec2.c ../src/quantise.c ../src/lpc.c ../src/lsp.c ../src/dump.c ../src/fft.c ../src/kiss_fft.c \ -../src/codec2.c ../src/sine.c ../src/nlp.c ../src/postfilter.c ../src/phase.c ../src/interp.c ../src/pack.c $(CODEBOOKS) - -tcodec2_LDADD = $(lib_LTLIBRARIES) -tcodec2_LDFLAGS = $(LIBS) scalarlsptest_SOURCES = scalarlsptest.c ../src/quantise.c ../src/lpc.c ../src/lsp.c ../src/dump.c ../src/fft.c ../src/kiss_fft.c $(CODEBOOKS) scalarlsptest_LDADD = $(lib_LTLIBRARIES) scalarlsptest_LDFLAGS = $(LIBS) @@ -373,9 +360,6 @@ scalarlsptest$(EXEEXT): $(scalarlsptest_OBJECTS) $(scalarlsptest_DEPENDENCIES) t48_8$(EXEEXT): $(t48_8_OBJECTS) $(t48_8_DEPENDENCIES) @rm -f t48_8$(EXEEXT) $(LINK) $(t48_8_LDFLAGS) $(t48_8_OBJECTS) $(t48_8_LDADD) $(LIBS) -tcodec2$(EXEEXT): $(tcodec2_OBJECTS) $(tcodec2_DEPENDENCIES) - @rm -f tcodec2$(EXEEXT) - $(LINK) $(tcodec2_LDFLAGS) $(tcodec2_OBJECTS) $(tcodec2_LDADD) $(LIBS) tfdmdv$(EXEEXT): $(tfdmdv_OBJECTS) $(tfdmdv_DEPENDENCIES) @rm -f tfdmdv$(EXEEXT) $(LINK) $(tfdmdv_LDFLAGS) $(tfdmdv_OBJECTS) $(tfdmdv_LDADD) $(LIBS) @@ -436,7 +420,6 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/scalarlsptest.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sine.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/t48_8.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tcodec2.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tfdmdv.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tinterp.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tlspsens.Po@am__quote@ diff --git a/codec2-dev/unittest/tlspsens.c b/codec2-dev/unittest/tlspsens.c index bc1c17a8..e4d70809 100644 --- a/codec2-dev/unittest/tlspsens.c +++ b/codec2-dev/unittest/tlspsens.c @@ -43,6 +43,7 @@ float run_a_test(char raw_file_name[], int bit_to_corrupt) FILE *fin; short buf[N]; struct CODEC2 *c2; + kiss_fft_cfg fft_fwd_cfg; MODEL model; float ak[LPC_ORD+1]; float lsps[LPC_ORD], e; @@ -51,6 +52,7 @@ float run_a_test(char raw_file_name[], int bit_to_corrupt) int frames, i, mask, index; c2 = codec2_create(CODEC2_MODE_2400); + fft_fwd_cfg = kiss_fft_alloc(FFT_ENC, 0, NULL, NULL); fin = fopen(raw_file_name, "rb"); assert(fin != NULL); @@ -91,7 +93,7 @@ float run_a_test(char raw_file_name[], int bit_to_corrupt) check_lsp_order(lsps, LPC_ORD); bw_expand_lsps(lsps, LPC_ORD); lsp_to_lpc(lsps, ak, LPC_ORD); - aks_to_M2(ak, LPC_ORD, &model, e, &snr, 1); + aks_to_M2(fft_fwd_cfg, ak, LPC_ORD, &model, e, &snr, 1); snr_sum += snr; frames++; diff --git a/codec2-dev/unittest/tnlp.c b/codec2-dev/unittest/tnlp.c index 43ef9cb0..e44b392b 100644 --- a/codec2-dev/unittest/tnlp.c +++ b/codec2-dev/unittest/tnlp.c @@ -40,6 +40,7 @@ #include "dump.h" #include "sine.h" #include "nlp.h" +#include "kiss_fft.h" int frames; @@ -80,6 +81,7 @@ char *argv[]; FILE *fin,*fout; short buf[N]; float Sn[M]; /* float input speech samples */ + kiss_fft_cfg fft_fwd_cfg; COMP Sw[FFT_ENC]; /* DFT of Sn[] */ float w[M]; /* time domain hamming window */ COMP W[FFT_ENC]; /* DFT of w[] */ @@ -121,7 +123,8 @@ char *argv[]; #endif nlp_states = nlp_create(); - make_analysis_window(w,W); + fft_fwd_cfg = kiss_fft_alloc(FFT_ENC, 0, NULL, NULL); + make_analysis_window(fft_fwd_cfg, w, W); frames = 0; prev_Wo = 0; @@ -134,7 +137,7 @@ char *argv[]; Sn[i] = Sn[i+N]; for(i=0; i