int lsp, lsp_quantiser;
float ak[LPC_MAX];
COMP Sw_[FFT_ENC];
-
+ COMP Ew[FFT_ENC];
+
int dump;
int phase0;
/* 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
if (lsp) {
encode_lsps(lsp_indexes, lsps, LPC_ORD);
- /*
- for(i=0; i<LPC_ORD; i++)
- printf("lsps[%d] = %f lsp_indexes[%d] = %d\n",
- i, lsps[i], i, lsp_indexes[i]);
- printf("\n");
- */
decode_lsps(lsps, lsp_indexes, LPC_ORD);
bw_expand_lsps(lsps, LPC_ORD);
lsp_to_lpc(lsps, ak, LPC_ORD);
{
COMP Sw[FFT_ENC];
COMP Sw_[FFT_ENC];
+ COMP Ew[FFT_ENC];
float pitch;
int i;
dft_speech(Sw, c2->Sn, 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);
}
*/
#include "defines.h"
+#include "comp.h"
#include "dump.h"
#include <assert.h>
#include <stdlib.h>
static FILE *fsn = NULL;
static FILE *fsw = NULL;
+static FILE *few = NULL;
static FILE *fsw_ = NULL;
static FILE *fmodel = NULL;
static FILE *fqmodel = NULL;
static FILE *fak = NULL;
static FILE *fbg = NULL;
static FILE *fE = NULL;
+static FILE *frk = NULL;
static char prefix[MAX_STR];
fclose(fsw);
if (fsw_ != NULL)
fclose(fsw_);
+ if (few != NULL)
+ fclose(few);
if (fmodel != NULL)
fclose(fmodel);
if (fqmodel != NULL)
fclose(fbg);
if (fE != NULL)
fclose(fE);
+ if (frk != NULL)
+ fclose(frk);
}
void dump_Sn(float Sn[]) {
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<FFT_ENC/2; i++)
+ fprintf(few,"%f\t",
+ 10.0*log10(Ew[i].real*Ew[i].real + Ew[i].imag*Ew[i].imag));
+ fprintf(few,"\n");
+}
+
void dump_model(MODEL *model) {
int l;
char s[MAX_STR];
fprintf(fE,"%f\n", 10.0*log10(E));
}
+
+void dump_Rk(float Rk[]) {
+ int i;
+ char s[MAX_STR];
+
+ if (!dumpon) return;
+
+ if (frk == NULL) {
+ sprintf(s,"%s_rk.txt", prefix);
+ frk = fopen(s, "wt");
+ assert(frk != NULL);
+ }
+
+ for(i=0; i<P_MAX; i++)
+ fprintf(frk,"%f\t",Rk[i]);
+ fprintf(frk,"\n");
+}
+
#endif
void dump_Sn(float Sn[]);
void dump_Sw(COMP Sw[]);
void dump_Sw_(COMP Sw_[]);
+void dump_Ew(COMP Ew[]);
/* amplitude modelling */
void dump_dec(COMP Fw[]);
void dump_Fw(COMP Fw[]);
void dump_e(float e_hz[]);
+void dump_Rk(float Rk[]);
/* post filter */
#include <math.h>
#include "defines.h"
+#include "comp.h"
#include "dump.h"
#include "postfilter.h"
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 */
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; i<FFT_ENC; i++) {
Sw_[i].real = 0.0;
Sw_[i].imag = 0.0;
+ Ew[i].real = 0.0;
+ Ew[i].imag = 0.0;
}
- L = floor((FS/2.0)/f0);
- Wo = f0*(TWO_PI/FS);
-
+ Wo = model->Wo;
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;
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;
}
Pn[i] = win;
for(i=3*N/2+TW; i<2*N; i++)
Pn[i] = 0.0;
-
}
/*---------------------------------------------------------------------------*\
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);