phase synth converted to kiss_fft
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Sun, 10 Jun 2012 12:20:24 +0000 (12:20 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Sun, 10 Jun 2012 12:20:24 +0000 (12:20 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@540 01035d8c-6547-0410-b346-abe4f91aad63

codec2-dev/src/c2sim.c
codec2-dev/src/codec2.c
codec2-dev/src/interp.c
codec2-dev/src/interp.h
codec2-dev/src/nlp.c
codec2-dev/src/phase.c
codec2-dev/src/phase.h
codec2-dev/src/quantise.c
codec2-dev/src/quantise.h

index 354c3452555a79b4945c98db4e5e7099e26c20dc..51089be4fd07ba86d9d9f567fbfcab320d6bd178 100644 (file)
@@ -311,7 +311,7 @@ int main(int argc, char *argv[])
 
     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_analysis_window(fft_enc_cfg, w, W);
     make_synthesis_window(Pn);
     quantise_init();
 
@@ -574,7 +574,7 @@ int main(int argc, char *argv[])
 
            }
 
-           aks_to_M2(ak, order, &model, e, &snr, 1); 
+           aks_to_M2(fft_dec_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(&interp_model, &prev_model, &model,
+               interpolate_lsp(fft_dec_cfg, &interp_model, &prev_model, &model,
                                prev_lsps_, prev_e, lsps_, e, ak_interp, lsps_interp);          
                apply_lpc_correction(&interp_model);
 
@@ -660,7 +660,7 @@ int main(int argc, char *argv[])
                 #endif
 
                if (phase0)
-                   phase_synth_zero_order(&interp_model, ak_interp, ex_phase,
+                   phase_synth_zero_order(fft_dec_cfg, &interp_model, ak_interp, ex_phase,
                                           order);      
                if (postfilt)
                    postfilter(&interp_model, &bg_est);
@@ -672,7 +672,7 @@ int main(int argc, char *argv[])
                /* decode this frame */
 
                if (phase0)
-                   phase_synth_zero_order(&model, ak, ex_phase, order);        
+                   phase_synth_zero_order(fft_dec_cfg, &model, ak, ex_phase, order);   
                if (postfilt)
                    postfilter(&model, &bg_est);
                synth_one_frame(fft_dec_cfg, buf, &model, Sn_, Pn);
@@ -695,7 +695,7 @@ int main(int argc, char *argv[])
            /* no decimation - sythesise each 10ms frame immediately */
 
            if (phase0)
-               phase_synth_zero_order(&model, ak, ex_phase, order);    
+               phase_synth_zero_order(fft_dec_cfg, &model, ak, ex_phase, order);       
            if (postfilt)
                postfilter(&model, &bg_est);
            synth_one_frame(fft_dec_cfg, buf, &model, Sn_, Pn);
index f55e33dc212903048c392a942c87ec4814d37d5e..b981c7ef5e494d65c71e2a1a22ac35d615c34da7 100644 (file)
@@ -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(&ak[i][0], LPC_ORD, &model[i], e[i], &snr, 1); 
+       aks_to_M2(c2->fft_dec_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(&ak[i][0], LPC_ORD, &model[i], e[i], &snr, 1); 
+       aks_to_M2(c2->fft_dec_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(&ak[i][0], LPC_ORD, &model[i], e[i], &snr, 1); 
+       aks_to_M2(c2->fft_dec_cfg, &ak[i][0], LPC_ORD, &model[i], e[i], &snr, 1); 
        apply_lpc_correction(&model[i]);
     }
 
@@ -737,7 +737,7 @@ void synthesise_one_frame(struct CODEC2 *c2, short speech[], MODEL *model, float
 {
     int     i;
 
-    phase_synth_zero_order(model, ak, &c2->ex_phase, LPC_ORD);
+    phase_synth_zero_order(c2->fft_dec_cfg, model, ak, &c2->ex_phase, LPC_ORD);
     postfilter(model, &c2->bg_est);
     synthesise(c2->fft_dec_cfg, c2->Sn_, model, c2->Pn, 1);
 
index 253e57bf23f891ddeb53e80545c3b0f534e97f2e..2aca6b26de362c06469702adaf70867cb9774011 100644 (file)
@@ -146,6 +146,7 @@ float sample_log_amp(MODEL *model, float w)
 \*---------------------------------------------------------------------------*/
 
 void interpolate_lsp(
+  kiss_fft_cfg  fft_dec_cfg, 
   MODEL *interp,    /* interpolated model params                     */
   MODEL *prev,      /* previous frames model params                  */
   MODEL *next,      /* next frames model params                      */
@@ -200,7 +201,7 @@ void interpolate_lsp(
     /* convert back to amplitudes */
 
     lsp_to_lpc(lsps_interp, ak_interp, LPC_ORD);
-    aks_to_M2(ak_interp, LPC_ORD, interp, e, &snr, 0); 
+    aks_to_M2(fft_dec_cfg, ak_interp, LPC_ORD, interp, e, &snr, 0); 
     //printf("  interp: ak[1]: %f A[1] %f\n", ak_interp[1], interp->A[1]);
 }
 
index 87caf574016c14a3243138b972bf3e04b39ec3da..312ccb76da586e153b9db6420067d25147ac18b0 100644 (file)
 #ifndef __INTERP__
 #define __INTERP__
 
+#include "kiss_fft.h"
+
 void interpolate(MODEL *interp, MODEL *prev, MODEL *next);
-void interpolate_lsp(MODEL *interp, MODEL *prev, MODEL *next, 
-                     float *prev_lsps, float  prev_e,
-                     float *next_lsps, float  next_e,
-                     float *ak_interp, float *lsps_interp);
+void interpolate_lsp(kiss_fft_cfg  fft_dec_cfg,
+                    MODEL *interp, MODEL *prev, MODEL *next, 
+                    float *prev_lsps, float  prev_e,
+                    float *next_lsps, float  next_e,
+                    float *ak_interp, float *lsps_interp);
 void interp_Wo(MODEL *interp, MODEL *prev, MODEL *next);
 float interp_energy(float prev, float next);
 void interpolate_lsp_ver2(float interp[], float prev[],  float next[], float weight);
index d5d53edcbc56400b0d8bb6e65e9d81a528f1e223..c417020a9c4b42b12acaa753eba731b6c37a4780 100644 (file)
@@ -261,7 +261,6 @@ float nlp(
     dump_dec(Fw);
 #endif
     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<PE_FFT_SIZE; i++)
        Fw[i].real = Fw[i].real*Fw[i].real + Fw[i].imag*Fw[i].imag;
 
index d1a88fa3d2e1db5288cfeaad2fb7ac415133739a..5701020f7fee5d7819ed5e27930d32e1165f4fac 100644 (file)
@@ -48,6 +48,7 @@
 \*---------------------------------------------------------------------------*/
 
 void aks_to_H(
+              kiss_fft_cfg fft_dec_cfg, 
              MODEL *model,     /* model parameters */
              float  aks[],     /* LPC's */
              float  G,         /* energy term */
@@ -55,7 +56,8 @@ void aks_to_H(
              int    order
 )
 {
-  COMP  Pw[FFT_DEC];   /* power spectrum */
+  COMP  pw[FFT_DEC];   /* power spectrum (input) */
+  COMP  Pw[FFT_DEC];   /* power spectrum (output) */
   int   i,m;           /* loop variables */
   int   am,bm;         /* limits of current band */
   float r;             /* no. rads/bin */
@@ -69,14 +71,14 @@ void aks_to_H(
   /* Determine DFT of A(exp(jw)) ------------------------------------------*/
 
   for(i=0; i<FFT_DEC; i++) {
-    Pw[i].real = 0.0;
-    Pw[i].imag = 0.0;
+    pw[i].real = 0.0;
+    pw[i].imag = 0.0;
   }
 
   for(i=0; i<=order; i++)
-    Pw[i].real = aks[i];
+    pw[i].real = aks[i];
 
-  fft(&Pw[0].real,FFT_DEC,-1);
+  kiss_fft(fft_dec_cfg, (kiss_fft_cpx *)pw, (kiss_fft_cpx *)Pw);
 
   /* Sample magnitude and phase at harmonics */
 
@@ -188,6 +190,7 @@ void aks_to_H(
 \*---------------------------------------------------------------------------*/
 
 void phase_synth_zero_order(
+    kiss_fft_cfg fft_dec_cfg,     
     MODEL *model,
     float  aks[],
     float *ex_phase,            /* excitation phase of fundamental */
@@ -205,7 +208,7 @@ void phase_synth_zero_order(
   int   b;
 
   G = 1.0;
-  aks_to_H(model, aks, G, H, order);
+  aks_to_H(fft_dec_cfg, model, aks, G, H, order);
 
   /* 
      Update excitation fundamental phase track, this sets the position
index 833bc7cdcec86560a2ffcf2b9cb1b21f598dd246..725698d90530d483866172dfdd4008a0f8132dbf 100644 (file)
@@ -28,7 +28,9 @@
 #ifndef __PHASE__
 #define __PHASE__
 
-void phase_synth_zero_order(MODEL *model, float aks[], float *ex_phase, 
-                           int order);
+#include "kiss_fft.h"
+
+void phase_synth_zero_order(kiss_fft_cfg fft_dec_cfg, MODEL *model, float aks[], 
+                            float *ex_phase, int order);
 
 #endif
index 81973a6de6117e7ed17ad04002839fe7ae5af2f9..b71989a650a31b2dee496a2c11ffce61774725bf 100644 (file)
@@ -36,7 +36,7 @@
 #include "quantise.h"
 #include "lpc.h"
 #include "lsp.h"
-#include "fft.h"
+#include "kiss_fft.h"
 
 #define LSP_DELTA1 0.01         /* grid spacing for LSP root searches */
 
@@ -526,6 +526,7 @@ void force_min_lsp_dist(float lsp[], int lpc_order)
        }
 }
 
+#ifdef NOT_USED
 /*---------------------------------------------------------------------------*\
                                                                              
   lpc_model_amplitudes
@@ -648,6 +649,7 @@ float lpc_model_amplitudes(
 
   return snr;
 }
+#endif
 
 /*---------------------------------------------------------------------------*\
                                                                          
@@ -660,15 +662,17 @@ float lpc_model_amplitudes(
 \*---------------------------------------------------------------------------*/
 
 void aks_to_M2(
-  float  ak[], /* LPC's */
-  int    order,
-  MODEL *model,        /* sinusoidal model parameters for this frame */
-  float  E,    /* energy term */
-  float *snr,  /* signal to noise ratio for this frame in dB */
-  int    dump   /* true to dump sample to dump file */
+  kiss_fft_cfg  fft_dec_cfg, 
+  float         ak[],       /* LPC's */
+  int           order,
+  MODEL        *model,      /* sinusoidal model parameters for this frame */
+  float         E,          /* energy term */
+  float        *snr,        /* signal to noise ratio for this frame in dB */
+  int           dump         /* true to dump sample to dump file */
 )
 {
-  COMP Pw[FFT_DEC];    /* power spectrum */
+  COMP pw[FFT_DEC];    /* input to FFT for power spectrum */
+  COMP Pw[FFT_DEC];    /* output power spectrum */
   int i,m;             /* loop variables */
   int am,bm;           /* limits of current band */
   float r;             /* no. rads/bin */
@@ -681,22 +685,22 @@ void aks_to_M2(
   /* Determine DFT of A(exp(jw)) --------------------------------------------*/
 
   for(i=0; i<FFT_DEC; i++) {
-    Pw[i].real = 0.0;
-    Pw[i].imag = 0.0; 
+    pw[i].real = 0.0;
+    pw[i].imag = 0.0; 
   }
 
   for(i=0; i<=order; i++)
-    Pw[i].real = ak[i];
-  fft(&Pw[0].real,FFT_DEC,1);
+    pw[i].real = ak[i];
+  kiss_fft(fft_dec_cfg, (kiss_fft_cpx *)pw, (kiss_fft_cpx *)Pw);
 
   /* Determine power spectrum P(w) = E/(A(exp(jw))^2 ------------------------*/
 
   for(i=0; i<FFT_DEC/2; i++)
     Pw[i].real = E/(Pw[i].real*Pw[i].real + Pw[i].imag*Pw[i].imag);
-#ifdef DUMP
+  #ifdef DUMP
   if (dump) 
       dump_Pw(Pw);
-#endif
+  #endif
 
   /* Determine magnitudes by linear interpolation of P(w) -------------------*/
 
@@ -1404,6 +1408,7 @@ float decode_energy(int index)
     return e;
 }
 
+#ifdef NOT_USED
 /*---------------------------------------------------------------------------*\
                                                        
   FUNCTION....: decode_amplitudes()         
@@ -1415,7 +1420,8 @@ float decode_energy(int index)
 
 \*---------------------------------------------------------------------------*/
 
-float decode_amplitudes(MODEL *model, 
+float decode_amplitudes(kiss_fft_cfg  fft_dec_cfg, 
+                       MODEL *model, 
                        float  ak[],
                        int    lsp_indexes[], 
                        int    energy_index,
@@ -1434,7 +1440,7 @@ float decode_amplitudes(MODEL *model,
 
     return snr;
 }
-
+#endif
 
 static float ge_coeff[2] = {0.8, 0.9};
 
index b3206be7c8dd42da5517c3ed6089dcb5daeaa277..59f880b8abd0f193cba6fdb37d6d0197d319749e 100644 (file)
@@ -26,6 +26,8 @@
 #ifndef __QUANTISE__
 #define __QUANTISE__
 
+#include "kiss_fft.h"
+
 #define WO_BITS     7
 #define WO_LEVELS   (1<<WO_BITS)
 #define WO_DT_BITS  3
@@ -49,8 +51,8 @@
 void quantise_init();
 float lpc_model_amplitudes(float Sn[], float w[], MODEL *model, int order,
                           int lsp,float ak[]);
-void aks_to_M2(float ak[], int order, MODEL *model, float E, float *snr
-              int dump);
+void aks_to_M2(kiss_fft_cfg  fft_dec_cfg, float ak[], int order, MODEL *model
+              float E, float *snr, int dump);
 
 int   encode_Wo(float Wo);
 float decode_Wo(int index);