From c9538b92cd5271a6cebce8a684b2f34e9fa9815b Mon Sep 17 00:00:00 2001 From: drowe67 Date: Sat, 12 Sep 2009 05:16:03 +0000 Subject: [PATCH] fixed bug in zero phase model, all sound close to original phases through speaker except for mmt1. Also some tests with continuous phase syth algorithm, but no sig change in speech quality git-svn-id: https://svn.code.sf.net/p/freetel/code@57 01035d8c-6547-0410-b346-abe4f91aad63 --- codec2/src/phase.c | 12 +++--- codec2/src/phase.h | 1 + codec2/src/sinedec.c | 10 ++--- codec2/unittest/Makefile | 2 +- codec2/unittest/tcontphase.c | 79 ++++++++++++++++++++++++++++++++---- 5 files changed, 82 insertions(+), 22 deletions(-) diff --git a/codec2/src/phase.c b/codec2/src/phase.c index faba8853..80016f93 100644 --- a/codec2/src/phase.c +++ b/codec2/src/phase.c @@ -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; } } diff --git a/codec2/src/phase.h b/codec2/src/phase.h index 5dd4ad69..e7c58300 100644 --- a/codec2/src/phase.h +++ b/codec2/src/phase.h @@ -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); diff --git a/codec2/src/sinedec.c b/codec2/src/sinedec.c index bd4bef58..a39e96b9 100644 --- a/codec2/src/sinedec.c +++ b/codec2/src/sinedec.c @@ -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; i2.0), &Wo_prev, phi_prev); - else - synthesise_mixed(Pn,&model,Sn_); + synthesise_mixed(Pn,&model,Sn_); /* Save output speech to disk */ diff --git a/codec2/unittest/Makefile b/codec2/unittest/Makefile index abccf595..5c74eb43 100644 --- a/codec2/unittest/Makefile +++ b/codec2/unittest/Makefile @@ -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 diff --git a/codec2/unittest/tcontphase.c b/codec2/unittest/tcontphase.c index d21a2fd3..4c6c4aa2 100644 --- a/codec2/unittest/tcontphase.c +++ b/codec2/unittest/tcontphase.c @@ -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 #include @@ -36,9 +39,25 @@ #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