#include "postfilter.h"
#include "interp.h"
-void synth_one_frame(short buf[], MODEL *model, float Sn_[], float Pn[]);
+void synth_one_frame(kiss_fft_cfg fft_dec_cfg, short buf[], MODEL *model, float Sn_[], float Pn[]);
void print_help(const struct option *long_options, int num_opts, char* argv[]);
/*---------------------------------------------------------------------------*\
float Sn[M]; /* float input speech samples */
COMP Sw[FFT_ENC]; /* DFT of Sn[] */
kiss_fft_cfg fft_enc_cfg;
+ kiss_fft_cfg fft_dec_cfg;
float w[M]; /* time domain hamming window */
COMP W[FFT_ENC]; /* DFT of w[] */
MODEL model;
/* Initialise ------------------------------------------------------------*/
fft_enc_cfg = kiss_fft_alloc(FFT_ENC, 1, NULL, NULL);
+ fft_dec_cfg = kiss_fft_alloc(FFT_DEC, 0, NULL, NULL);
make_analysis_window(fft_enc_cfg, w,W);
make_synthesis_window(Pn);
quantise_init();
order);
if (postfilt)
postfilter(&interp_model, &bg_est);
- synth_one_frame(buf, &interp_model, Sn_, Pn);
+ synth_one_frame(fft_dec_cfg, buf, &interp_model, Sn_, Pn);
//printf(" buf[0] %d\n", buf[0]);
if (fout != NULL)
fwrite(buf,sizeof(short),N,fout);
phase_synth_zero_order(&model, ak, ex_phase, order);
if (postfilt)
postfilter(&model, &bg_est);
- synth_one_frame(buf, &model, Sn_, Pn);
+ synth_one_frame(fft_dec_cfg, buf, &model, Sn_, Pn);
//printf(" buf[0] %d\n", buf[0]);
if (fout != NULL)
fwrite(buf,sizeof(short),N,fout);
phase_synth_zero_order(&model, ak, ex_phase, order);
if (postfilt)
postfilter(&model, &bg_est);
- synth_one_frame(buf, &model, Sn_, Pn);
+ synth_one_frame(fft_dec_cfg, buf, &model, Sn_, Pn);
if (fout != NULL) fwrite(buf,sizeof(short),N,fout);
}
return 0;
}
-void synth_one_frame(short buf[], MODEL *model, float Sn_[], float Pn[])
+void synth_one_frame(kiss_fft_cfg fft_dec_cfg, short buf[], MODEL *model, float Sn_[], float Pn[])
{
int i;
- synthesise(Sn_, model, Pn, 1);
+ synthesise(fft_dec_cfg, Sn_, model, Pn, 1);
for(i=0; i<N; i++) {
if (Sn_[i] > 32767.0)
c2->fft_enc_cfg = kiss_fft_alloc(FFT_ENC, 1, NULL, NULL);
make_analysis_window(c2->fft_enc_cfg, c2->w,c2->W);
make_synthesis_window(c2->Pn);
+ c2->fft_dec_cfg = kiss_fft_alloc(FFT_DEC, 0, NULL, NULL);
quantise_init();
c2->prev_Wo_enc = 0.0;
c2->bg_est = 0.0;
assert(c2 != NULL);
nlp_destroy(c2->nlp);
KISS_FFT_FREE(c2->fft_enc_cfg);
+ KISS_FFT_FREE(c2->fft_dec_cfg);
free(c2);
}
phase_synth_zero_order(model, ak, &c2->ex_phase, LPC_ORD);
postfilter(model, &c2->bg_est);
- synthesise(c2->Sn_, model, c2->Pn, 1);
+ synthesise(c2->fft_dec_cfg, c2->Sn_, model, c2->Pn, 1);
for(i=0; i<N; i++) {
if (c2->Sn_[i] > 32767.0)
float hpf_states[2]; /* high pass filter states */
void *nlp; /* pitch predictor states */
+ kiss_fft_cfg fft_dec_cfg; /* FFT config for decoder */
float Sn_[2*N]; /* synthesised output speech */
float ex_phase; /* excitation model phase track */
float bg_est; /* background noise estimate for post filter */
kiss_fft(fft_enc_cfg, (kiss_fft_cpx *)wshift, (kiss_fft_cpx *)W);
- // fft(&W[0].real,FFT_ENC,-1); /* "Numerical Recipes in C" FFT */
-
/*
Re-arrange W[] to be symmetrical about FFT_ENC/2. Makes later
analysis convenient.
void dft_speech(kiss_fft_cfg fft_enc_cfg, COMP Sw[], float Sn[], float w[])
{
- int i;
-
+ int i;
+ COMP sw[FFT_ENC];
+
for(i=0; i<FFT_ENC; i++) {
- Sw[i].real = 0.0;
- Sw[i].imag = 0.0;
+ sw[i].real = 0.0;
+ sw[i].imag = 0.0;
}
/* Centre analysis window on time axis, we need to arrange input
/* move 2nd half to start of FFT input vector */
for(i=0; i<NW/2; i++)
- Sw[i].real = Sn[i+M/2]*w[i+M/2];
+ sw[i].real = Sn[i+M/2]*w[i+M/2];
/* move 1st half to end of FFT input vector */
for(i=0; i<NW/2; i++)
- Sw[FFT_ENC-NW/2+i].real = Sn[i+M/2-NW/2]*w[i+M/2-NW/2];
+ sw[FFT_ENC-NW/2+i].real = Sn[i+M/2-NW/2]*w[i+M/2-NW/2];
- fft(&Sw[0].real,FFT_ENC,-1);
+ kiss_fft(fft_enc_cfg, (kiss_fft_cpx *)sw, (kiss_fft_cpx *)Sw);
}
/*---------------------------------------------------------------------------*\
/* Estimate phase of harmonic */
- model->phi[m] = atan2(Sw[b].imag,Sw[b].real);
+ model->phi[m] = atan2(-Sw[b].imag,Sw[b].real);
}
}
\*---------------------------------------------------------------------------*/
void synthesise(
+ kiss_fft_cfg fft_dec_cfg,
float Sn_[], /* time domain synthesised signal */
MODEL *model, /* ptr to model parameters for this frame */
float Pn[], /* time domain Parzen window */
{
int i,l,j,b; /* loop variables */
COMP Sw_[FFT_DEC]; /* DFT of synthesised signal */
+ COMP sw_[FFT_DEC]; /* synthesised signal */
if (shift) {
/* Update memories */
b = (FFT_DEC/2)-1;
}
Sw_[b].real = model->A[l]*cos(model->phi[l]);
- Sw_[b].imag = model->A[l]*sin(model->phi[l]);
+ Sw_[b].imag = -model->A[l]*sin(model->phi[l]);
Sw_[FFT_DEC-b].real = Sw_[b].real;
Sw_[FFT_DEC-b].imag = -Sw_[b].imag;
}
/* Perform inverse DFT */
- fft(&Sw_[0].real,FFT_DEC,1);
+ kiss_fft(fft_dec_cfg, (kiss_fft_cpx *)Sw_, (kiss_fft_cpx *)sw_);
#else
/*
Direct time domain synthesis using the cos() function. Works
/* Overlap add to previous samples */
for(i=0; i<N-1; i++) {
- Sn_[i] += Sw_[FFT_DEC-N+1+i].real*Pn[i];
+ Sn_[i] += sw_[FFT_DEC-N+1+i].real*Pn[i];
}
if (shift)
for(i=N-1,j=0; i<2*N; i++,j++)
- Sn_[i] = Sw_[j].real*Pn[i];
+ Sn_[i] = sw_[j].real*Pn[i];
else
for(i=N-1,j=0; i<2*N; i++,j++)
- Sn_[i] += Sw_[j].real*Pn[i];
+ Sn_[i] += sw_[j].real*Pn[i];
}
float est_voicing_mbe(MODEL *model, COMP Sw[], COMP W[], COMP Sw_[],COMP Ew[],
float prev_Wo);
void make_synthesis_window(float Pn[]);
-void synthesise(float Sn_[], MODEL *model, float Pn[], int shift);
+void synthesise(kiss_fft_cfg fft_dec_cfg, float Sn_[], MODEL *model, float Pn[], int shift);
#endif