Added ability to dump Ew from voicing estimator
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Fri, 12 Nov 2010 00:46:25 +0000 (00:46 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Fri, 12 Nov 2010 00:46:25 +0000 (00:46 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@216 01035d8c-6547-0410-b346-abe4f91aad63

codec2/src/c2sim.c
codec2/src/codec2.c
codec2/src/dump.c
codec2/src/dump.h
codec2/src/postfilter.c
codec2/src/sine.c
codec2/src/sine.h

index 42a665c2eee93433418160d24363bf8d183ccc3f..950d1061bc67add20e054ddfe0e96a536d3b827d 100644 (file)
@@ -103,7 +103,8 @@ int main(int argc, char *argv[])
   int lsp, lsp_quantiser;
   float ak[LPC_MAX];
   COMP  Sw_[FFT_ENC];
-  
+  COMP  Ew[FFT_ENC]; 
   int dump;
   
   int phase0;
@@ -281,9 +282,10 @@ int main(int argc, char *argv[])
        
        /* determine voicing */
 
-       snr = est_voicing_mbe(&model, Sw, W, (FS/TWO_PI)*model.Wo, Sw_);
+       snr = est_voicing_mbe(&model, Sw, W, Sw_, Ew);
 #ifdef DUMP
        dump_Sw_(Sw_);
+       dump_Ew(Ew);
        dump_snr(snr);
 #endif
 
@@ -307,12 +309,6 @@ int main(int argc, char *argv[])
 
        if (lsp) {
            encode_lsps(lsp_indexes, lsps, LPC_ORD);
-           /*
-             for(i=0; i<LPC_ORD; i++)
-               printf("lsps[%d] = %f lsp_indexes[%d] = %d\n", 
-                      i, lsps[i], i, lsp_indexes[i]);
-             printf("\n");
-           */
            decode_lsps(lsps, lsp_indexes, LPC_ORD);
            bw_expand_lsps(lsps, LPC_ORD);
            lsp_to_lpc(lsps, ak, LPC_ORD);
index 1c71cc12fd583633138fd0a5f9df57ed970e2504..e23da2cba75697d844ab1434ec899aedfeea9b5d 100644 (file)
@@ -314,6 +314,7 @@ void analyse_one_frame(CODEC2 *c2, MODEL *model, short speech[])
 {
     COMP    Sw[FFT_ENC];
     COMP    Sw_[FFT_ENC];
+    COMP    Ew[FFT_ENC];
     float   pitch;
     int     i;
 
@@ -337,5 +338,5 @@ void analyse_one_frame(CODEC2 *c2, MODEL *model, short speech[])
     dft_speech(Sw, c2->Sn, c2->w); 
     two_stage_pitch_refinement(model, Sw);
     estimate_amplitudes(model, Sw, c2->W);
-    est_voicing_mbe(model, Sw, c2->W, (FS/TWO_PI)*model->Wo, Sw_);
+    est_voicing_mbe(model, Sw, c2->W, Sw_, Ew);
 }
index c3613f91b0ca202275e6a72c7b38499af5b1c525..2215bf274e297107d73f14adca589fb5bd60200d 100644 (file)
@@ -24,6 +24,7 @@
 */
 
 #include "defines.h"
+#include "comp.h"
 #include "dump.h"
 #include <assert.h>
 #include <stdlib.h>
@@ -36,6 +37,7 @@ static int dumpon = 0;
 
 static FILE *fsn = NULL;
 static FILE *fsw = NULL;
+static FILE *few = NULL;
 static FILE *fsw_ = NULL;
 static FILE *fmodel = NULL;
 static FILE *fqmodel = NULL;
@@ -51,6 +53,7 @@ static FILE *fsnr = NULL;
 static FILE *fak = NULL;
 static FILE *fbg = NULL;
 static FILE *fE = NULL;
+static FILE *frk = NULL;
 
 static char  prefix[MAX_STR];
 
@@ -66,6 +69,8 @@ void dump_off(){
        fclose(fsw);
     if (fsw_ != NULL)
        fclose(fsw_);
+    if (few != NULL)
+       fclose(few);
     if (fmodel != NULL)
        fclose(fmodel);
     if (fqmodel != NULL)
@@ -94,6 +99,8 @@ void dump_off(){
        fclose(fbg);
     if (fE != NULL)
        fclose(fE);
+    if (frk != NULL)
+       fclose(frk);
 }
 
 void dump_Sn(float Sn[]) {
@@ -155,6 +162,24 @@ void dump_Sw_(COMP Sw_[]) {
     fprintf(fsw_,"\n");    
 }
 
+void dump_Ew(COMP Ew[]) {
+    int i;
+    char s[MAX_STR];
+
+    if (!dumpon) return;
+
+    if (few == NULL) {
+       sprintf(s,"%s_ew.txt", prefix);
+       few = fopen(s, "wt");
+       assert(few != NULL);
+    }
+
+    for(i=0; i<FFT_ENC/2; i++)
+       fprintf(few,"%f\t",
+               10.0*log10(Ew[i].real*Ew[i].real + Ew[i].imag*Ew[i].imag));
+    fprintf(few,"\n");    
+}
+
 void dump_model(MODEL *model) {
     int l;
     char s[MAX_STR];
@@ -400,4 +425,22 @@ void dump_E(float E) {
 
     fprintf(fE,"%f\n", 10.0*log10(E));
 }
+
+void dump_Rk(float Rk[]) {
+    int i;
+    char s[MAX_STR];
+
+    if (!dumpon) return;
+
+    if (frk == NULL) {
+       sprintf(s,"%s_rk.txt", prefix);
+       frk = fopen(s, "wt");
+       assert(frk != NULL);
+    }
+
+    for(i=0; i<P_MAX; i++)
+       fprintf(frk,"%f\t",Rk[i]);
+    fprintf(frk,"\n");    
+}
+
 #endif
index aebda4156d84804d6c5934be0979f3f47bd65c03..2c7de189d171f460107ee2870b3e39dac4766567 100644 (file)
@@ -34,6 +34,7 @@ void dump_off();
 void dump_Sn(float Sn[]);
 void dump_Sw(COMP Sw[]);
 void dump_Sw_(COMP Sw_[]);
+void dump_Ew(COMP Ew[]);
 
 /* amplitude modelling */
 
@@ -56,6 +57,7 @@ void dump_sq(float sq[]);
 void dump_dec(COMP Fw[]);
 void dump_Fw(COMP Fw[]);
 void dump_e(float e_hz[]);
+void dump_Rk(float Rk[]);
 
 /* post filter */
 
index dead6a346e96669b1c19e4447bdaff125a8bf417..6e17eeb8723e327ddf60d499cf3b48a180b50ec5 100644 (file)
@@ -32,6 +32,7 @@
 #include <math.h>
 
 #include "defines.h"
+#include "comp.h"
 #include "dump.h"
 #include "postfilter.h"
 
index 011ca0f3d0a16bf5ab76b05170afe719a03984ec..9a07a4c4e4e74033f52f09c953b6f57e360915d0 100644 (file)
@@ -361,9 +361,9 @@ float est_voicing_mbe(
     MODEL *model,
     COMP   Sw[],
     COMP   W[],
-    float  f0,
-    COMP   Sw_[]          /* DFT of all voiced synthesised signal for f0 */
-                          /* useful for debugging/dump file              */
+    COMP   Sw_[],         /* DFT of all voiced synthesised signal  */
+                          /* useful for debugging/dump file        */
+    COMP   Ew[]           /* DFT of error                        */
 )
 {
     int   i,l,al,bl,m;    /* loop variables */
@@ -371,28 +371,26 @@ float est_voicing_mbe(
     int   offset;         /* centers Hw[] about current harmonic */
     float den;            /* denominator of Am expression */
     float error;          /* accumulated error between originl and synthesised */
-    float Wo;             /* current "test" fundamental freq. */
-    int   L;
+    float Wo;            
     float sig, snr;
 
     sig = 0.0;
     for(l=1; l<=model->L/4; l++) {
        sig += model->A[l]*model->A[l];
     }
-
     for(i=0; i<FFT_ENC; i++) {
        Sw_[i].real = 0.0;
        Sw_[i].imag = 0.0;
+       Ew[i].real = 0.0;
+       Ew[i].imag = 0.0;
     }
 
-    L = floor((FS/2.0)/f0);
-    Wo = f0*(TWO_PI/FS);
-
+    Wo = model->Wo;
     error = 0.0;
 
     /* Just test across the harmonics in the first 1000 Hz (L/4) */
 
-    for(l=1; l<=L/4; l++) {
+    for(l=1; l<=model->L/4; l++) {
        Am.real = 0.0;
        Am.imag = 0.0;
        den = 0.0;
@@ -417,17 +415,19 @@ float est_voicing_mbe(
            offset = FFT_ENC/2 + m - l*Wo*FFT_ENC/TWO_PI + 0.5;
            Sw_[m].real = Am.real*W[offset].real - Am.imag*W[offset].imag;
            Sw_[m].imag = Am.real*W[offset].imag + Am.imag*W[offset].real;
-           error += (Sw[m].real - Sw_[m].real)*(Sw[m].real - Sw_[m].real);
-           error += (Sw[m].imag - Sw_[m].imag)*(Sw[m].imag - Sw_[m].imag);
+           Ew[m].real = Sw[m].real - Sw_[m].real;
+           Ew[m].imag = Sw[m].imag - Sw_[m].imag;
+           error += Ew[m].real*Ew[m].real;
+           error += Ew[m].imag*Ew[m].imag;
        }
     }
-
+    
     snr = 10.0*log10(sig/error);
     if (snr > V_THRESH)
        model->voiced = 1;
     else
        model->voiced = 0;
-
+   
     return snr;
 }
 
@@ -461,7 +461,6 @@ void make_synthesis_window(float Pn[])
     Pn[i] = win;
   for(i=3*N/2+TW; i<2*N; i++)
     Pn[i] = 0.0;
-
 }
 
 /*---------------------------------------------------------------------------*\
index d56ac9838f1b60cc3c8c5e37fc81fd4f1d60ab84..73d928fd0498ef484e3fa389f18d21f2c2d4ac0e 100644 (file)
@@ -35,7 +35,7 @@ void make_analysis_window(float w[], COMP W[]);
 void dft_speech(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[], float f0, COMP Sw_[]);
+float est_voicing_mbe(MODEL *model, COMP Sw[], COMP W[], COMP Sw_[],COMP Ew[]);
 void make_synthesis_window(float Pn[]);
 void synthesise(float Sn_[], MODEL *model, float Pn[], int shift);