fixed bug in zero phase model, all sound close to original phases through speaker...
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Sat, 12 Sep 2009 05:16:03 +0000 (05:16 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Sat, 12 Sep 2009 05:16:03 +0000 (05:16 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@57 01035d8c-6547-0410-b346-abe4f91aad63

codec2/src/phase.c
codec2/src/phase.h
codec2/src/sinedec.c
codec2/unittest/Makefile
codec2/unittest/tcontphase.c

index faba88533fc864e1c6850cc3bbbe693dfaaf47f2..80016f939a57c8f80c95d0cd244868ad5da8f831 100644 (file)
@@ -344,6 +344,12 @@ void phase_synth_zero_order(
     if (m <= Lrand) {
         Ex[m].real = cos(ex_phase[0]*m);
        Ex[m].imag = sin(ex_phase[0]*m);
+
+       /* following is an experiment in dispersing pulse energy over time,
+          didn't really change sound at all, e.g. mmt1 still sounded
+          "clicky"*/
+        //Ex[m].real = cos(ex_phase[0]*m + model.Wo*m*m*0.3);
+       //Ex[m].imag = sin(ex_phase[0]*m + model.Wo*m*m*0.3);
     }
     else {
        /* we probably don't need to LPC filter phase in unvoiced case,
@@ -362,12 +368,6 @@ void phase_synth_zero_order(
 
     new_phi = atan2(A_[m].imag, A_[m].real+1E-12);
     model.phi[m] = new_phi;
-
-    /* little bit of randomness to phase - possibly makes females
-       sound slightly better, need to do some more research.  May not
-       be needed */
-
-    model.phi[m] += (m*model.Wo)*rand()/RAND_MAX;
   }
 }
 
index 5dd4ad69242136717fe635d73bb940b2d05504bb..e7c583002245f52d000839fd1364541a52a3ccef 100644 (file)
@@ -31,6 +31,7 @@
 
 #define PHASE_LPC_ORD 10
 
+void aks_to_H(MODEL *model, float aks[], float G, COMP H[], int order);
 float phase_model_first_order(float aks[], COMP H[], float *n_min, COMP *min_Am);
 void phase_synth_zero_order(float snr, COMP H[], float *prev_Wo, float *ex_phase);
 void phase_synth_first_order(float snr, COMP H[], float n_min, COMP min_Am);
index bd4bef5855128328bce17609a7eebf4261df2272..a39e96b937aff76fe1456ca188f109aeb450b2b1 100644 (file)
@@ -87,8 +87,6 @@ int main(int argc, char *argv[])
   
   int phase, phase_model;
   float prev_Wo, ex_phase;
-  float phi_prev[MAX_AMP];
-  float Wo_prev;
 
   if (argc < 3) {
     printf("usage: sinedec InputFile ModelFile [-o OutputFile] [-o lpc Order]\n");
@@ -226,6 +224,9 @@ int main(int argc, char *argv[])
 
        dump_snr(snr);
        if (phase_model == 0) {
+           /* just to make sure we are not cheating - kill all phases */
+           for(i=0; i<MAX_AMP; i++)
+               model.phi[i] = 0;
            phase_synth_zero_order(snr, H, &prev_Wo, &ex_phase);
        }
 
@@ -239,10 +240,7 @@ int main(int argc, char *argv[])
 
     if (fout != NULL) {
 
-       if (phase)
-           synthesise_continuous_phase(Pn, &model, Sn_, (snr>2.0), &Wo_prev, phi_prev);
-       else
-           synthesise_mixed(Pn,&model,Sn_);
+       synthesise_mixed(Pn,&model,Sn_);
 
        /* Save output speech to disk */
 
index abccf595d2aeada4f831295b211eda0c2878b4d1..5c74eb43cfdc23260c7519e04138d091f37e9324 100644 (file)
@@ -13,7 +13,7 @@ TNLP_OBJ     = tnlp.o ../src/nlp.o ../src/four1.o ../src/initenc.o ../src/dump.o
                ../src/globals.o  ../src/refine.o
 
 TCONTPHASE_OBJ = tcontphase.o ../src/globals.o ../src/dump.o ../src/synth.o \
-                 ../src/four1.c ../src/initdec.o
+                 ../src/four1.c ../src/initdec.o ../src/phase.o
 
 lsptest: $(LSP_TEST_OBJ)
        gcc $(CFLAGS) -o lsptest $(LSP_TEST_OBJ) -lm
index d21a2fd34a871542ac0888172f89aefc0a95cddc..4c6c4aa2cacc4a513adb72e684ee2389d9acbfc9 100644 (file)
@@ -4,7 +4,9 @@
   AUTHOR......: David Rowe                                            
   DATE CREATED: 11/9/09                                        
                                                                
-  Test program for developing continuous phase track synthesis algorithms.
+  Test program for developing continuous phase track synthesis algorithm.
+  However while developing this it was discovered that synthesis_mixed()
+  worked just as well.
                                                                    
 \*---------------------------------------------------------------------------*/
 
@@ -28,6 +30,7 @@
 
 #define N  80          /* frame size          */
 #define F 160           /* frames to synthesis */
+#define P  10           /* LPC order           */
 
 #include <stdlib.h>
 #include <stdio.h>
 #include "sine.h"
 #include "dump.h"
 #include "synth.h"
+#include "phase.h"
 
 int   frames;
 
+float ak[] = {
+ 1.000000,
+-1.455836,
+ 1.361841,
+-0.879267,
+ 0.915985,
+-1.002202,
+ 0.944103,
+-0.743094,
+ 1.053356,
+-0.817491,
+ 0.431222
+};
+
+
 /*---------------------------------------------------------------------------*\
                                                                              
   switch_present()                                                            
@@ -78,10 +97,13 @@ char *argv[];
     int   i,j; 
     int   dump;
     float phi_prev[MAX_AMP];
-    float Wo_prev;
-    
-    if (argc < 2) {
-       printf("\nusage: tcontphase OutputRawSpeechFile\n");
+    float Wo_prev, ex_phase, G;
+    //float ak[P+1];
+    COMP  H[MAX_AMP];  
+    float f0;
+
+    if (argc < 3) {
+       printf("\nusage: tcontphase OutputRawSpeechFile F0\n");
         exit(0);
     }
 
@@ -92,6 +114,8 @@ char *argv[];
       exit(1);
     }
 
+    f0 = atof(argv[2]);
+
     dump = switch_present("--dump",argc,argv);
     if (dump) 
       dump_on(argv[dump+1]);
@@ -102,16 +126,53 @@ char *argv[];
        phi_prev[i] = 0.0;
     Wo_prev = 0.0;
        
-    model.L      = 1;
-    model.A[1]   = 1000;
-    model.Wo     = PI*(50.0/4000.0);
-    model.phi[1] = 0;
+    model.Wo = PI*(f0/4000.0);
+    G = 1000.0;
+    model.L = floor(PI/model.Wo);
+    
+    //aks_to_H(&model, ak, G , H, P);
+    //for(i=1; i<=model.L; i++)
+       model.A[i] = sqrt(H[i].real*H[i].real + H[i].imag*H[i].imag);
+    //printf("L = %d\n", model.L);
+    //model.L = 10;
+    for(i=1; i<=model.L; i++) {
+      model.A[i]   = 1000/model.L;
+      model.phi[i] = 0;
+      H[i].real = 1.0; H[i].imag = 0.0;
+    }
+
+    //ak[0] = 1.0;
+    //for(i=1; i<=P; i++)
+    //  ak[i] = 0.0;
 
     frames = 0;
     for(j=0; j<F; j++) {
        frames++;
 
+       #ifdef SWAP
+       /* lets make phases bounce around from frame to frame.  This
+          could happen if H[m] is varying, for example due to frame
+          to frame Wo variations, or non-stationary speech.
+          Continous model generally results in smooth phase track
+          under these circumstances. */
+       if (j%2){
+           H[1].real = 1.0; H[1].imag = 0.0;
+           model.phi[1] = 0.0;
+       }
+       else {
+           H[1].real = 0.0; H[1].imag = 1.0;
+           model.phi[1] = PI/2;
+       }
+       #endif
+
+       //#define CONT
+       #ifdef CONT
        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_);
+       #endif
+
        for(i=0; i<N; i++)
            buf[i] = Sn_[i];
        fwrite(buf,sizeof(short),N,fout);