From 6a33fb40aaa9b33613d40a6cba277a7cfd8656ee Mon Sep 17 00:00:00 2001 From: drowe67 Date: Tue, 1 Sep 2009 06:52:58 +0000 Subject: [PATCH] just tried MBE voicing measure but doesn't look good due to F0 accuracy so will remove on next revision git-svn-id: https://svn.code.sf.net/p/freetel/code@36 01035d8c-6547-0410-b346-abe4f91aad63 --- codec2/octave/plamp.m | 43 ++++++++--- codec2/octave/pulse.m | 29 +++---- codec2/pitch/{hts2.p => hts2a.p} | 0 codec2/script/raw2wav.sh | 3 + codec2/src/Makefile | 2 +- codec2/src/dump.c | 128 +++++++++++++++++++++---------- codec2/src/dump.h | 1 + codec2/src/globals.c | 1 + codec2/src/initenc.c | 29 ++++++- codec2/src/sinenc.c | 50 ++++++++++-- codec2/src/spec.c | 22 ++++++ codec2/src/synth.c | 1 - 12 files changed, 232 insertions(+), 77 deletions(-) rename codec2/pitch/{hts2.p => hts2a.p} (100%) mode change 100755 => 100644 create mode 100755 codec2/script/raw2wav.sh diff --git a/codec2/octave/plamp.m b/codec2/octave/plamp.m index b7b479d0..e72f9303 100644 --- a/codec2/octave/plamp.m +++ b/codec2/octave/plamp.m @@ -8,14 +8,28 @@ function plamp(samname, f) sn_name = strcat(samname,"_sn.txt"); Sn = load(sn_name); + sw_name = strcat(samname,"_sw.txt"); Sw = load(sw_name); + + sw__name = strcat(samname,"_sw_.txt"); + if (file_in_path(".",sw__name)) + Sw_ = load(sw__name); + endif + model_name = strcat(samname,"_model.txt"); model = load(model_name); + modelq_name = strcat(samname,"_qmodel.txt"); - modelq = load(modelq_name); + if (file_in_path(".",modelq_name)) + modelq = load(modelq_name); + endif + pw_name = strcat(samname,"_pw.txt"); - Pw = load(pw_name); + if (file_in_path(".",pw_name)) + Pw = load(pw_name); + endif + lsp_name = strcat(samname,"_lsp.txt"); if (file_in_path(".",lsp_name)) lsp = load(lsp_name); @@ -36,19 +50,28 @@ function plamp(samname, f) axis([1 4000 -10 80]); hold on; plot((0:255)*4000/256, Sw(f,:),";Sw;"); - Amq = modelq(f,3:(L+2)); - plot((1:L)*Wo*4000/pi, 20*log10(Amq),";Amq;" ); - plot((0:255)*4000/256, 10*log10(Pw(f,:)),";Pw;"); - signal = Am * Am'; - noise = (Am-Amq) * (Am-Amq)'; - snr = 10*log10(signal/noise); - Am_err_label = sprintf(";Am_err SNR %4.2f dB;",snr); - plot((1:L)*Wo*4000/pi, 20*log10(Amq) - 20*log10(Am), Am_err_label); + + if (file_in_path(".",sw__name)) + plot((0:255)*4000/256, Sw_(f,:),";Sw_;"); + endif + + if (file_in_path(".",modelq_name)) + Amq = modelq(f,3:(L+2)); + plot((1:L)*Wo*4000/pi, 20*log10(Amq),";Amq;" ); + plot((0:255)*4000/256, 10*log10(Pw(f,:)),";Pw;"); + signal = Am * Am'; + noise = (Am-Amq) * (Am-Amq)'; + snr = 10*log10(signal/noise); + Am_err_label = sprintf(";Am_err SNR %4.2f dB;",snr); + plot((1:L)*Wo*4000/pi, 20*log10(Amq) - 20*log10(Am), Am_err_label); + endif + if (file_in_path(".",lsp_name)) for l=1:10 plot([lsp(f,l)*4000/pi lsp(f,l)*4000/pi], [60 80], 'r'); endfor endif + hold off; % interactive menu diff --git a/codec2/octave/pulse.m b/codec2/octave/pulse.m index 7df4a8de..994ceceb 100644 --- a/codec2/octave/pulse.m +++ b/codec2/octave/pulse.m @@ -1,28 +1,21 @@ % pulse.m % David Rowe August 2009 -% experiments with phase for sinusoidal codecs -% - lets see how pulse waveforms are perceived at different F0 -% - experiment suggested by O'Shaughnessy, "Speech Communication", page 145 -% - in low F0 alternative phase pulses are perceived as 2F0 +% experiments with human pulse perception for sinusoidal codecs +% lets try some pulses in noise -function pulse(samname, F0, alternate) - Wo = 2*pi*F0/8000; - P = 2*pi/Wo +function pulse(samname, F0, snr) + + N = 16000; + s = zeros(1,N); + Wo = 2*pi*F0/8000; L = floor(pi/Wo); - N = 16000; - A = 1000; + A = 10000; phi = zeros(1,L); - if (alternate == 1) - % shift phases of some harmonics to introduce -ve pulses - % note magnitude spectrum unchanged - phi(2:2:L) = (2:2:L)*pi*(P)*Wo; - endif - s = zeros(1,N); - for m=1:L - s = s + A*cos(m*Wo*(0:(N-1)) + phi(m)); + s = s + (A/L)*cos(m*Wo*(1:N) + phi(m)); endfor - + randn("seed", 0); + s = s + A*(10 .^(-snr/20))*randn(1,N); plot(s(1:250)); fs=fopen(samname,"wb"); diff --git a/codec2/pitch/hts2.p b/codec2/pitch/hts2a.p old mode 100755 new mode 100644 similarity index 100% rename from codec2/pitch/hts2.p rename to codec2/pitch/hts2a.p diff --git a/codec2/script/raw2wav.sh b/codec2/script/raw2wav.sh new file mode 100755 index 00000000..010a1b9d --- /dev/null +++ b/codec2/script/raw2wav.sh @@ -0,0 +1,3 @@ +#!/bin/sh +# Converts 16 bit signed short 8 kHz raw (headerless) files to wave +sox -t raw -r 8000 -s -w -c 1 $1 $2 diff --git a/codec2/src/Makefile b/codec2/src/Makefile index 6acf8144..0de20f0c 100644 --- a/codec2/src/Makefile +++ b/codec2/src/Makefile @@ -1,7 +1,7 @@ CC=gcc CFLAGS=-g -Wall -I. -I../src -I../speex -Wall -g -DFLOATING_POINT -DVAR_ARRAYS -SINENC_OBJ = sinenc.o globals.o initenc.o four1.o refine.o spec.o +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 ../speex/lsp.o \ ../speex/quant_lsp.o ../speex/bits.o ../speex/lsp_tables_nb.o \ diff --git a/codec2/src/dump.c b/codec2/src/dump.c index 55698f40..bd65fb1c 100644 --- a/codec2/src/dump.c +++ b/codec2/src/dump.c @@ -28,60 +28,53 @@ #include #include #include +#include static int dumpon = 0; -static FILE *fsn; -static FILE *fsw; -static FILE *fmodel; -static FILE *fqmodel; -static FILE *fpw; -static FILE *flsp; - -void dump_on(char prefix[]) { - char s[MAX_STR]; +static FILE *fsn = NULL; +static FILE *fsw = NULL; +static FILE *fsw_ = NULL; +static FILE *fmodel = NULL; +static FILE *fqmodel = NULL; +static FILE *fpw = NULL; +static FILE *flsp = NULL; +static char prefix[MAX_STR]; +void dump_on(char p[]) { dumpon = 1; - - sprintf(s,"%s_sn.txt", prefix); - fsn = fopen(s, "wt"); - assert(fsn != NULL); - - sprintf(s,"%s_sw.txt", prefix); - fsw = fopen(s, "wt"); - assert(fsw != NULL); - - sprintf(s,"%s_model.txt", prefix); - fmodel = fopen(s, "wt"); - assert(fmodel != NULL); - - sprintf(s,"%s_qmodel.txt", prefix); - fqmodel = fopen(s, "wt"); - assert(fqmodel != NULL); - - sprintf(s,"%s_pw.txt", prefix); - fpw = fopen(s, "wt"); - assert(fpw != NULL); - - sprintf(s,"%s_lsp.txt", prefix); - flsp = fopen(s, "wt"); - assert(flsp != NULL); + strcpy(prefix, p); } void dump_off(){ - fclose(fsn); - fclose(fsw); - fclose(fmodel); - fclose(fqmodel); - fclose(fpw); - fclose(flsp); + if (fsn != NULL) + fclose(fsn); + if (fsw != NULL) + fclose(fsw); + if (fsw_ != NULL) + fclose(fsw_); + if (fmodel != NULL) + fclose(fmodel); + if (fqmodel != NULL) + fclose(fqmodel); + if (fpw != NULL) + fclose(fpw); + if (flsp != NULL) + fclose(flsp); } void dump_Sn(float Sn[]) { int i; + char s[MAX_STR]; if (!dumpon) return; + if (fsn == NULL) { + sprintf(s,"%s_sn.txt", prefix); + fsn = fopen(s, "wt"); + assert(fsn != NULL); + } + /* split across two lines to avoid max line length problems */ /* reconstruct in Octave */ @@ -95,33 +88,76 @@ void dump_Sn(float Sn[]) { void dump_Sw(COMP Sw[]) { int i; + char s[MAX_STR]; if (!dumpon) return; + if (fsw == NULL) { + sprintf(s,"%s_sw.txt", prefix); + fsw = fopen(s, "wt"); + assert(fsw != NULL); + } + for(i=0; iWo, model->L); for(l=1; l<=model->L; l++) fprintf(fmodel,"%f\t",model->A[l]); for(l=model->L+1; lL; l++) + fprintf(fmodel,"%f\t",model->v[l]); + for(l=model->L+1; lWo, model->L); for(l=1; l<=model->L; l++) fprintf(fqmodel,"%f\t",model->A[l]); @@ -132,9 +168,16 @@ void dump_quantised_model(MODEL *model) { void dump_Pw(COMP Pw[]) { int i; + char s[MAX_STR]; if (!dumpon) return; + if (fpw == NULL) { + sprintf(s,"%s_pw.txt", prefix); + fpw = fopen(s, "wt"); + assert(fpw != NULL); + } + for(i=0; i + +/*---------------------------------------------------------------------------*\ + + switch_present() + + Searches the command line arguments for a "switch". If the switch is + found, returns the command line argument where it ws found, else returns + NULL. + +\*---------------------------------------------------------------------------*/ + +int switch_present(sw,argc,argv) +register char sw[]; /* switch in string form */ +register int argc; /* number of command line arguments */ +register char *argv[]; /* array of command line arguments in string form */ +{ + register int i; /* loop variable */ + + for(i=1; i 5) { - if ((fref = fopen(argv[5],"wt")) == NULL) { + dump = switch_present("--dump",argc,argv); + if (dump) + dump_on(argv[dump+1]); + + if ((arg == switch_present("--ref",argc,argv))) { + if ((fref = fopen(argv[arg+1],"wt")) == NULL) { printf("Error opening output pitch refinement file: %s\n",argv[5]); exit(1); } @@ -84,7 +117,8 @@ int main(int argc, char *argv[]) /* Main loop ------------------------------------------------------------*/ - while(fread(buf,sizeof(short),N,fin) == N && frames != length) { + frames = 0; + while((fread(buf,sizeof(short),N,fin) == N) && (frames != length)) { frames++; /* Update input speech buffers */ @@ -110,9 +144,10 @@ int main(int argc, char *argv[]) /* estimate and model parameters */ - dft_speech(); + dft_speech(); two_stage_pitch_refinement(); estimate_amplitudes(); + dump_Sn(Sn); dump_Sw(Sw); dump_Sw_(Sw_); dump_model(&model); /* save model parameters */ @@ -128,6 +163,9 @@ int main(int argc, char *argv[]) fclose(fin); fclose(fmodel); + if (dump) + dump_off(); + return 0; } diff --git a/codec2/src/spec.c b/codec2/src/spec.c index 247d5123..fbad779c 100644 --- a/codec2/src/spec.c +++ b/codec2/src/spec.c @@ -52,8 +52,15 @@ void estimate_amplitudes() int b; /* DFT bin of centre of current harmonic */ float den; /* denominator of amplitude expression */ float r; /* number of rads/bin */ + float E; + int offset; + COMP Am; r = TWO_PI/FFT_ENC; + for(i=0; i