testing MBE voicing estimator, sounds about the 1st order phase model, better for...
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Thu, 19 Aug 2010 00:15:12 +0000 (00:15 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Thu, 19 Aug 2010 00:15:12 +0000 (00:15 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@174 01035d8c-6547-0410-b346-abe4f91aad63

codec2/TODO.txt
codec2/octave/plphase.m
codec2/raw/b0067.raw [new file with mode: 0644]
codec2/src/Makefile
codec2/src/nlp.c
codec2/src/nlp.h
codec2/src/sinedec.c
codec2/unittest/tcontphase.c

index dac0925d4de810cb6571fb147037f0e06309c4bb..fd5e2223ef7a9fbb8f70d3e33b54bccb31c41181 100644 (file)
@@ -1,6 +1,16 @@
 TODO for codec2
 ---------------
 
+Mysteries
+---------
+
+[ ] buzzy sound in bg noise ofr b0067
+[ ] LSP quantiser has problems for b0067
+[ ] synthetic sound for hts2a and to bg nouse on _uq models
+    + breakdown in sinusoidal model for noise
+    + MELP does better
+    + perhaps synth UV using white noise might work better
+
 29 July 2010, current status:
 - g729a is a bit better, but c2 is not put to shame
 - c2 betters GSM in some cases
@@ -233,4 +243,4 @@ So todo:
 
 
 
\ No newline at end of file
index 82cf0f26c048e253ea28f4978da774088cc539cd..9e6118567694e0a986bcceef7eb62e60e9df3519 100644 (file)
@@ -15,6 +15,11 @@ function plphase(samname, f)
   model_name = strcat(samname,"_model.txt");
   model = load(model_name);
 
+  sw__name = strcat(samname,"_sw_.txt");
+  if (file_in_path(".",sw__name))
+    Sw_ = load(sw__name);
+  endif
+
   pw_name = strcat(samname,"_pw.txt");
   if (file_in_path(".",pw_name))
     Pw = load(pw_name);
@@ -49,7 +54,7 @@ function plphase(samname, f)
   k = ' ';
   do 
     figure(1);
-    clg;
+    clf;
     s = [ Sn(2*f-1,:) Sn(2*f,:) ];
     plot(s);
     grid;
@@ -63,12 +68,16 @@ function plphase(samname, f)
     Wo = model(f,1);
     L = model(f,2);
     Am = model(f,3:(L+2));
-    plot((1:L)*Wo*4000/pi, 20*log10(Am),";Am;");
+    plot((1:L)*Wo*4000/pi, 20*log10(Am),"r;Am;");
     axis([1 4000 -10 80]);
     hold on;
     plot((0:255)*4000/256, Sw(f,:),";Sw;");
     grid;
 
+    if (file_in_path(".",sw__name))
+      plot((0:255)*4000/256, Sw_(f,:),"g;Sw_;");
+    endif      
+
     if (file_in_path(".",pw_name))
        plot((0:255)*4000/256, 10*log10(Pw(f,:)),";Pw;");
     endif      
@@ -87,7 +96,7 @@ function plphase(samname, f)
       noise = (orig-synth) * (orig-synth)';
       snr_phase = 10*log10(signal/noise);
 
-      phase_err_label = sprintf(";phase_err SNR %4.2f dB;",snr_phase);
+      phase_err_label = sprintf("g;phase_err SNR %4.2f dB;",snr_phase);
       plot((1:L)*Wo*4000/pi, 20*log10(orig-synth), phase_err_label);
     endif
 
@@ -103,7 +112,7 @@ function plphase(samname, f)
       axis;
       if (file_in_path(".", phase_name_))
         hold on;
-        plot((1:L)*Wo*4000/pi, phase_(f,1:L)*180/pi, ";phase_;");
+        plot((1:L)*Wo*4000/pi, phase_(f,1:L)*180/pi, "g;phase_;");
        grid
        hold off;
       endif
diff --git a/codec2/raw/b0067.raw b/codec2/raw/b0067.raw
new file mode 100644 (file)
index 0000000..3aea9cd
Binary files /dev/null and b/codec2/raw/b0067.raw differ
index 216430588a950ebd53f29c3ba4c3ee1d43d942ac..5b888cef6c73373bbb2e4c0dc1cd33d839da51ee 100644 (file)
@@ -4,7 +4,7 @@ CFLAGS=-g -Wall -I. -I../src -Wall -g -DFLOATING_POINT -DVAR_ARRAYS
 SINENC_OBJ  = sinenc.o globals.o initenc.o four1.o refine.o spec.o dump.o
 SINEDEC_OBJ = sinedec.o globals.o initenc.o initdec.o four1.o synth.o \
               quantise.o lpc.o dump.o refine.o lsp.o phase.o postfilter.o \
-              interp.o
+              interp.o nlp.o
 
 all: sinenc sinedec
 
index d1077894eef5f7f85a8303dfa8c054ffacb2879b..c7a3ed21803cba0b836fe7006c2ffe5c339f9024 100644 (file)
@@ -106,7 +106,6 @@ float nlp_fir[] = {
   -1.0818124e-03
 };
 
-float test_candidate_mbe(COMP Sw[], float f0);
 float post_process_mbe(COMP Fw[], int pmin, int pmax, float gmax);
 float post_process_sub_multiples(COMP Fw[], 
                                 int pmin, int pmax, float gmax, int gmax_bin,
@@ -330,6 +329,7 @@ float post_process_mbe(COMP Fw[], int pmin, int pmax, float gmax)
   int   bin;
   float f0_min, f0_max;
   float f0_start, f0_end;
+  COMP  Sw_[FFT_ENC];
 
   f0_min = (float)SAMPLE_RATE/pmax;
   f0_max = (float)SAMPLE_RATE/pmin;
@@ -357,7 +357,7 @@ float post_process_mbe(COMP Fw[], int pmin, int pmax, float gmax)
            if (f0_end > f0_max) f0_end = f0_max;
 
            for(f0=f0_start; f0<=f0_end; f0+= 2.5) {
-               e = test_candidate_mbe(Sw, f0);
+               e = test_candidate_mbe(Sw, f0, Sw_);
                bin = floor(f0); assert((bin > 0) && (bin < F0_MAX));
                e_hz[bin] = e;
                if (e < e_min) {
@@ -387,11 +387,12 @@ float post_process_mbe(COMP Fw[], int pmin, int pmax, float gmax)
 
 float test_candidate_mbe(
     COMP  Sw[],
-    float f0
+    float f0,
+    COMP  Sw_[]           /* DFT of all voiced synthesised signal for f0 */
+                          /* useful for debugging/dump file              */
 )
 {
-    COMP  Sw_[FFT_ENC];   /* DFT of all voiced synthesised signal */
-    int   l,al,bl,m;      /* loop variables */
+    int   i,l,al,bl,m;    /* loop variables */
     COMP  Am;             /* amplitude sample for this band */
     int   offset;         /* centers Hw[] about current harmonic */
     float den;            /* denominator of Am expression */
@@ -399,6 +400,11 @@ float test_candidate_mbe(
     float Wo;             /* current "test" fundamental freq. */
     int   L;
     
+    for(i=0; i<FFT_ENC; i++) {
+       Sw_[i].real = 0.0;
+       Sw_[i].imag = 0.0;
+    }
+
     L = floor((SAMPLE_RATE/2.0)/f0);
     Wo = f0*(2*PI/SAMPLE_RATE);
 
@@ -406,7 +412,7 @@ float test_candidate_mbe(
 
     /* Just test across the harmonics in the first 1000 Hz (L/4) */
 
-    for(l=1; l<L/4; l++) {
+    for(l=1; l<=L/4; l++) {
        Am.real = 0.0;
        Am.imag = 0.0;
        den = 0.0;
index 05000617e284bcca10a581fde0c511a9902bae72..bf0ed90d40bcf939844e373b3b18361091237487 100644 (file)
@@ -34,5 +34,6 @@
 #define NLP_NTAP 48     /* Decimation LPF order */
 
 float nlp(float Sn[], int n, int m, int pmin, int pmax, float *pitch, COMP Sw[], float *prev_Wo);
+float test_candidate_mbe(COMP Sw[], float f0, COMP Sw_[]);
 
 #endif
index 184337262bd323a674f7293bdd72e0203a7ac841..e8988cb576a5f623aa6746bc60cda1b9364c3367 100644 (file)
@@ -36,6 +36,7 @@
 #include "synth.h"
 #include "postfilter.h"
 #include "interp.h"
+#include "nlp.h"
 
 /*---------------------------------------------------------------------------*\
                                                                              
@@ -254,7 +255,49 @@ int main(int argc, char *argv[])
            assert(order == PHASE_LPC_ORD);
 
        dump_ak(ak_phase, PHASE_LPC_ORD);
-       snr = phase_model_first_order(ak_phase, H, &n_min, &min_Am, &voiced);
+
+       {
+           COMP  Sw_[FFT_ENC];
+           float sig = 0.0;
+           float noise;
+            int   m;
+           float candidate_f0;
+           float f0,best_f0;   
+           float e,e_min;               
+           int   i;
+           float f0_min, f0_max;
+           float f0_start, f0_end;
+
+           for(m=1; m<=model.L/4; m++) {
+               sig += model.A[m]*model.A[m];
+           }
+           f0_min = (float)8000.0/P_MAX;
+           f0_max = (float)8000.0/P_MIN;
+           candidate_f0 = (4000.0/PI)*model.Wo;
+           f0_start = candidate_f0-5;
+           f0_end = candidate_f0+5;
+           if (f0_start < f0_min) f0_start = f0_min;
+           if (f0_end > f0_max) f0_end = f0_max;
+            e_min = 1E32;
+
+           for(f0=f0_start; f0<=f0_end; f0+= 1) {
+               e = test_candidate_mbe(Sw, f0, Sw_);
+               if (e < e_min) {
+                   e_min = e;
+                   best_f0 = f0;
+               }
+           }
+           noise = test_candidate_mbe(Sw,best_f0, Sw_);
+           snr = sig/noise;
+           dump_Sw_(Sw_);
+       }
+       
+       phase_model_first_order(ak_phase, H, &n_min, &min_Am, &voiced);
+           if (snr > 4.0)
+               voiced = 1;
+           else
+               voiced = 0;
+       
 
        dump_snr(snr);
        if (phase_model == 0) {
@@ -278,7 +321,7 @@ int main(int argc, char *argv[])
         //dump_phase_(&model.phi[0]);
     }
  
-   /* optional LPC model amplitudes */
+    /* optional LPC model amplitudes */
 
     if (lpc_model) {
        snr = lpc_model_amplitudes(Sn, &model, order, lsp, ak);
index 4c6c4aa2cacc4a513adb72e684ee2389d9acbfc9..8fefab931aa4a080b23806b5ba246027bb246997 100644 (file)
@@ -170,7 +170,7 @@ char *argv[];
        synthesise_continuous_phase(Pn, &model, Sn_, 1, &Wo_prev, phi_prev);
        #else
        phase_synth_zero_order(5.0, H, &Wo_prev, &ex_phase);
-       synthesise_mixed(Pn,&model,Sn_);
+       synthesise_mixed(Pn,&model,Sn_,1);
        #endif
 
        for(i=0; i<N; i++)