From: drowe67 Date: Fri, 12 Nov 2010 00:46:25 +0000 (+0000) Subject: Added ability to dump Ew from voicing estimator X-Git-Url: http://git.whiteaudio.com/gitweb/?a=commitdiff_plain;h=d3bf9ceae20648ecd21680fffff63157ddbaea1a;p=freetel-svn-tracking.git Added ability to dump Ew from voicing estimator git-svn-id: https://svn.code.sf.net/p/freetel/code@216 01035d8c-6547-0410-b346-abe4f91aad63 --- diff --git a/codec2/src/c2sim.c b/codec2/src/c2sim.c index 42a665c2..950d1061 100644 --- a/codec2/src/c2sim.c +++ b/codec2/src/c2sim.c @@ -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; iSn, 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); } diff --git a/codec2/src/dump.c b/codec2/src/dump.c index c3613f91..2215bf27 100644 --- a/codec2/src/dump.c +++ b/codec2/src/dump.c @@ -24,6 +24,7 @@ */ #include "defines.h" +#include "comp.h" #include "dump.h" #include #include @@ -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 #include "defines.h" +#include "comp.h" #include "dump.h" #include "postfilter.h" diff --git a/codec2/src/sine.c b/codec2/src/sine.c index 011ca0f3..9a07a4c4 100644 --- a/codec2/src/sine.c +++ b/codec2/src/sine.c @@ -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; iWo; 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; - } /*---------------------------------------------------------------------------*\ diff --git a/codec2/src/sine.h b/codec2/src/sine.h index d56ac983..73d928fd 100644 --- a/codec2/src/sine.h +++ b/codec2/src/sine.h @@ -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);