From: drowe67 Date: Tue, 24 Aug 2010 02:32:16 +0000 (+0000) Subject: new 20ms interpolation working OK for hts1a X-Git-Url: http://git.whiteaudio.com/gitweb/?a=commitdiff_plain;h=6612558370260b854d7c025bb9db8282c06167dc;p=freetel-svn-tracking.git new 20ms interpolation working OK for hts1a git-svn-id: https://svn.code.sf.net/p/freetel/code@184 01035d8c-6547-0410-b346-abe4f91aad63 --- diff --git a/codec2/octave/plinterp.m b/codec2/octave/plinterp.m new file mode 100644 index 00000000..794a0853 --- /dev/null +++ b/codec2/octave/plinterp.m @@ -0,0 +1,11 @@ +load ../unittest/tinterp_prev.txt; +load ../unittest/tinterp_interp.txt; +load ../unittest/tinterp_next.txt; + +clf; +plot(tinterp_prev(:,1), 20.0*log10(tinterp_prev(:,2)),";prev;") +hold on; +plot(tinterp_interp(:,1), 20.0*log10(tinterp_interp(:,2)),'g+-;interp;') +plot(tinterp_next(:,1), 20.0*log10(tinterp_next(:,2)),'ro-;next;') +hold off; +axis([0 pi 0 80]) diff --git a/codec2/src/c2sim.c b/codec2/src/c2sim.c index a84ea591..4049f3b7 100644 --- a/codec2/src/c2sim.c +++ b/codec2/src/c2sim.c @@ -67,6 +67,8 @@ register char *argv[]; /* array of command line arguments in string form */ return 0; } +void synth_one_frame(short buf[], MODEL *model, float Sn_[], float Pn[]); + /*---------------------------------------------------------------------------*\ MAIN @@ -89,6 +91,8 @@ int main(int argc, char *argv[]) int frames; float prev_Wo; float pitch; + int voiced1; + float phi1[MAX_AMP]; char out_file[MAX_STR]; int arg; @@ -97,7 +101,8 @@ int main(int argc, char *argv[]) int lpc_model, order; int lsp, lsp_quantiser; - float ak[LPC_MAX+1]; + float ak[LPC_MAX]; + COMP Sw_[FFT_ENC]; int dump; @@ -110,8 +115,10 @@ int main(int argc, char *argv[]) int hand_voicing; FILE *fvoicing; - MODEL model_1, model_2, model_3, model_synth, model_a, model_b; - int transition, decimate; + MODEL prev_model, interp_model, tmp_model; + int decimate; + float tmp_phi = 0; + float ak_phase[LPC_ORD+1]; for(i=0; i TWO_PI/20.0) model.Wo = TWO_PI/20.0; - if (model.Wo < TWO_PI/160.0) model.Wo = TWO_PI/160.0; - model.L = floor(PI/model.Wo); - */ - - /* Synthesise speech */ - - if (fout != NULL) { - - if (transition) { - synthesise(Sn_,&model_a,Pn,1); - synthesise(Sn_,&model_b,Pn,0); - } - else { - synthesise(Sn_,&model,Pn,1); - } + /* odd frame - interpolate */ - /* Save output speech to disk */ + if (frames%2) { - for(i=0; i 32767.0) - buf[i] = 32767; - else if (Sn_[i] < -32767.0) - buf[i] = -32767; + #ifdef TEST + model.voiced = 1; + prev_model.voiced = 1; + if (fabs(prev_model.Wo - model.Wo) < 0.1*model.Wo) { + interp_model.voiced = 1; + interpolate(&interp_model, &prev_model, &model); + for(i=0; i<=interp_model.L; i++) { + interp_model.phi[i] = phi1[i]; + } + printf("interp\n"); + } else - buf[i] = Sn_[i]; + interp_model = tmp_model; + #endif + + interp_model.voiced = voiced1; + interpolate(&interp_model, &prev_model, &model); + + if (phase0) + phase_synth_zero_order(&interp_model, ak_phase, ex_phase); + if (postfilt) + postfilter(&interp_model, &bg_est); + synth_one_frame(buf, &interp_model, Sn_, Pn); + fwrite(buf,sizeof(short),N,fout); + + if (phase0) + phase_synth_zero_order(&model, ak_phase, ex_phase); + if (postfilt) + postfilter(&model, &bg_est); + synth_one_frame(buf, &model, Sn_, Pn); + fwrite(buf,sizeof(short),N,fout); + + prev_model = model; + } + else { + voiced1 = model.voiced; } + } + else { + if (phase0) + phase_synth_zero_order(&model, ak_phase, ex_phase); + if (postfilt) + postfilter(&model, &bg_est); + synth_one_frame(buf, &model, Sn_, Pn); fwrite(buf,sizeof(short),N,fout); - } + } } if (fout != NULL) @@ -366,3 +364,19 @@ int main(int argc, char *argv[]) return 0; } +void synth_one_frame(short buf[], MODEL *model, float Sn_[], float Pn[]) +{ + int i; + + synthesise(Sn_, model, Pn, 1); + + for(i=0; i 32767.0) + buf[i] = 32767; + else if (Sn_[i] < -32767.0) + buf[i] = -32767; + else + buf[i] = Sn_[i]; + } + +} diff --git a/codec2/src/code.sh b/codec2/src/code.sh deleted file mode 100755 index adeddc49..00000000 --- a/codec2/src/code.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/sh -# code.sh -# David Rowe 10 Sep 2009 -# -# Run steps to encode a speech sample - -../unittest/tnlp ../raw/$1.raw ../unittest/$1_nlp.p -../src/sinenc ../raw/$1.raw $1.mdl 300 ../unittest/$1_nlp.p -../src/sinedec ../raw/$1.raw $1.mdl -o $1_uq.raw -../src/sinedec ../raw/$1.raw $1.mdl --phase0 -o $1_phase0.raw --postfilter -../src/sinedec ../raw/$1.raw $1.mdl --lpc 10 -o $1_lpc10.raw -../src/sinedec ../raw/$1.raw $1.mdl --lpc 10 --lsp -o $1_lsp.raw -../src/sinedec ../raw/$1.raw $1.mdl --phase0 --lpc 10 -o $1_phase0_lpc10.raw --postfilter -../src/sinedec ../raw/$1.raw $1.mdl --phase0 --lpc 10 --lsp -o $1_phase0_lsp.raw --postfilter - diff --git a/codec2/src/interp.c b/codec2/src/interp.c index 2bdf38c2..5ccee794 100644 --- a/codec2/src/interp.c +++ b/codec2/src/interp.c @@ -103,8 +103,8 @@ float sample_log_amp(MODEL *model, float w) assert(w > 0.0); assert (w <= PI); - m = floor(w/model->Wo); - f = w - m*model->Wo; + m = floor(w/model->Wo + 0.5); + f = (w - m*model->Wo)/w; assert(f <= 1.0); if (m < 1) { diff --git a/codec2/unittest/Makefile b/codec2/unittest/Makefile index 35143c20..56657d61 100644 --- a/codec2/unittest/Makefile +++ b/codec2/unittest/Makefile @@ -12,7 +12,7 @@ TNLP_OBJ = tnlp.o ../src/sine.o ../src/nlp.o ../src/four1.o ../src/dump.o TCONTPHASE_OBJ = tcontphase.o ../src/globals.o ../src/dump.o ../src/synth.o \ ../src/four1.c ../src/initdec.o ../src/phase.o -TINTERP_OBJ = tinterp.o ../src/interp.o +TINTERP_OBJ = tinterp.o ../src/sine.o ../src/four1.o ../src/interp.o TQUANT_OBJ = tquant.o ../src/quantise.o ../src/lpc.o ../src/lsp.o \ ../src/dump.o ../src/four1.o diff --git a/codec2/unittest/tinterp.c b/codec2/unittest/tinterp.c index f0cf8539..dcd69b70 100644 --- a/codec2/unittest/tinterp.c +++ b/codec2/unittest/tinterp.c @@ -31,37 +31,98 @@ #include #include #include +#include #include "defines.h" -#include "dump.h" +#include "sine.h" #include "interp.h" -int main() { - MODEL prev, next, interp; - int l; +void make_amp(MODEL *model, float f0, float cdB, float mdBHz) +{ + int i; + float mdBrad = mdBHz*FS/TWO_PI; + + model->Wo = f0*TWO_PI/FS; + model->L = PI/model->Wo; + for(i=0; i<=model->L; i++) + model->A[i] = pow(10.0,(cdB + (float)i*model->Wo*mdBrad)/20.0); + model->voiced = 1; +} + +void write_amp(char file[], MODEL *model) +{ FILE *f; + int i; - f = fopen("interp.txt","wt"); + f = fopen(file,"wt"); + for(i=1; i<=model->L; i++) + fprintf(f, "%f\t%f\n", model->Wo*i, model->A[i]); + fclose(f); +} - prev.Wo = PI/20; - prev.L = PI/prev.Wo; - prev.voiced = 1; - for(l=1;l<=prev.L; l++) - prev.A[l] = 1000.0; +char *get_next_float(char *s, float *num) +{ + char *p = s; + char tmp[MAX_STR]; - next.Wo = PI/30; - next.L = PI/next.Wo; - next.voiced = 1; - for(l=1;l<=next.L; l++) - next.A[l] = 2000.0; + while(*p && !isspace(*p)) + p++; + memcpy(tmp, s, p-s); + tmp[p-s] = 0; + *num = atof(tmp); - interp.voiced = 1.0; - interpolate(&interp, &prev, &next); - printf("Wo = %f\n", interp.Wo); - - for(l=1; l<=interp.L; l++) - fprintf(f, "%f\n", interp.A[l]); + return p+1; +} + +char *get_next_int(char *s, int *num) +{ + char *p = s; + char tmp[MAX_STR]; + + while(*p && !isspace(*p)) + p++; + memcpy(tmp, s, p-s); + tmp[p-s] = 0; + *num = atoi(tmp); + + return p+1; +} +void load_amp(MODEL *model, char file[], int frame) +{ + FILE *f; + int i; + char s[1024]; + char *ps; + + f = fopen(file,"rt"); + + for(i=0; iWo); + ps = get_next_int(ps, &model->L); + for(i=1; i<=model->L; i++) + ps = get_next_float(ps, &model->A[i]); + fclose(f); +} + +int main() { + MODEL prev, next, interp; + + //make_amp(&prev, 50.0, 60.0, 6E-3); + //make_amp(&next, 50.0, 40.0, 6E-3); + load_amp(&prev, "../src/hts1a_model.txt", 32); + load_amp(&next, "../src/hts1a_model.txt", 34); + + interp.voiced = 1; + interpolate(&interp, &prev, &next); + + write_amp("tinterp_prev.txt", &prev); + write_amp("tinterp_interp.txt", &interp); + write_amp("tinterp_next.txt", &next); + return 0; }