DATE CREATED: 20/8/2010
Codec2 simulation. Combines encoder and decoder and allows
- switching in and out various algorithms and quantisation
- steps. Used for algorithm development.
+ switching in and out various algorithms and quantisation steps. Used
+ for algorithm development.
\*---------------------------------------------------------------------------*/
int postfilt;
float bg_est;
- int hand_voicing = 0, phaseexp = 0, ampexp = 0, hi =0;
+ int hand_voicing = 0, phaseexp = 0, ampexp = 0, hi = 0, simlpcpf = 0;
FILE *fvoicing = 0;
MODEL prev_model, interp_model;
{ "dec", no_argument, &decimate, 1 },
{ "dt", no_argument, &dt, 1 },
{ "hi", no_argument, &hi, 1 },
+ { "simlpcpf", no_argument, &simlpcpf, 1 },
{ "dump_pitch_e", required_argument, &dump_pitch_e, 1 },
{ "sq_pitch_e", no_argument, &scalar_quant_Wo_e, 1 },
{ "vq_pitch_e", no_argument, &vector_quant_Wo_e, 1 },
}
- aks_to_M2(fft_fwd_cfg, ak, order, &model, e, &snr, 1);
+ aks_to_M2(fft_fwd_cfg, ak, order, &model, e, &snr, 1, simlpcpf);
/* note SNR on interpolated frames can't be measured properly
by comparing Am as L has changed. We can dump interp lsps
interpolate_lsp_ver2(&lsps[0][0], c2->prev_lsps_dec, &lsps[1][0], 0.5);
for(i=0; i<2; i++) {
lsp_to_lpc(&lsps[i][0], &ak[i][0], LPC_ORD);
- aks_to_M2(c2->fft_fwd_cfg, &ak[i][0], LPC_ORD, &model[i], e[i], &snr, 1);
+ aks_to_M2(c2->fft_fwd_cfg, &ak[i][0], LPC_ORD, &model[i], e[i], &snr, 1, 0);
apply_lpc_correction(&model[i]);
}
Encodes 320 speech samples (40ms of speech) into 56 bits.
The codec2 algorithm actually operates internally on 10ms (80
- sample) frames, so we run the encoding algorithm for times:
+ sample) frames, so we run the encoding algorithm 4 times:
frame 0: voicing bit
frame 1: voicing bit, joint VQ of Wo and E
}
for(i=0; i<4; i++) {
lsp_to_lpc(&lsps[i][0], &ak[i][0], LPC_ORD);
- aks_to_M2(c2->fft_fwd_cfg, &ak[i][0], LPC_ORD, &model[i], e[i], &snr, 1);
+ aks_to_M2(c2->fft_fwd_cfg, &ak[i][0], LPC_ORD, &model[i], e[i], &snr, 1, 0);
apply_lpc_correction(&model[i]);
}
}
for(i=0; i<4; i++) {
lsp_to_lpc(&lsps[i][0], &ak[i][0], LPC_ORD);
- aks_to_M2(c2->fft_fwd_cfg, &ak[i][0], LPC_ORD, &model[i], e[i], &snr, 1);
+ aks_to_M2(c2->fft_fwd_cfg, &ak[i][0], LPC_ORD, &model[i], e[i], &snr, 1, 0);
apply_lpc_correction(&model[i]);
}
/* convert back to amplitudes */
lsp_to_lpc(lsps_interp, ak_interp, LPC_ORD);
- aks_to_M2(fft_fwd_cfg, ak_interp, LPC_ORD, interp, e, &snr, 0);
+ aks_to_M2(fft_fwd_cfg, ak_interp, LPC_ORD, interp, e, &snr, 0, 0);
//printf(" interp: ak[1]: %f A[1] %f\n", ak_interp[1], interp->A[1]);
}
}
#endif
- aks_to_M2(ak,order,model,E,&snr, 1); /* {ak} -> {Am} LPC decode */
+ aks_to_M2(ak,order,model,E,&snr, 1, 0); /* {ak} -> {Am} LPC decode */
return snr;
}
MODEL *model, /* sinusoidal model parameters for this frame */
float E, /* energy term */
float *snr, /* signal to noise ratio for this frame in dB */
- int dump /* true to dump sample to dump file */
+ int dump, /* true to dump sample to dump file */
+ int sim_pf /* true to simulate a post filter */
)
{
COMP pw[FFT_ENC]; /* input to FFT for power spectrum */
signal += pow(model->A[m],2.0);
noise += pow(model->A[m] - Am,2.0);
- /* this code improves perf of LPC model, in particular with phase0 */
+ /* This code significantly improves perf of LPC model, in
+ particular when combined with phase0. The LPC spectrum tends
+ to track just under the peaks of the spectral envelope, and
+ just above nulls. This algorithm does the reverse to
+ compensate - raising the amplitudes of spectral peaks, while
+ attenuating the null. This enhances the formants, and
+ supresses the energy between formants. */
+
+ if (sim_pf) {
+ if (Am > model->A[m])
+ Am *= 0.7;
+ if (Am < model->A[m])
+ Am *= 1.4;
+ }
- if (Am > model->A[m])
- Am *= 0.7;
- if (Am < model->A[m])
- Am *= 1.4;
-
model->A[m] = Am;
}
*snr = 10.0*log10(signal/noise);
bw_expand_lsps(lsps, LPC_ORD);
lsp_to_lpc(lsps, ak, LPC_ORD);
*e = decode_energy(energy_index);
- aks_to_M2(ak, LPC_ORD, model, *e, &snr, 1);
+ aks_to_M2(ak, LPC_ORD, model, *e, &snr, 1, 0);
apply_lpc_correction(model);
return snr;
float lpc_model_amplitudes(float Sn[], float w[], MODEL *model, int order,
int lsp,float ak[]);
void aks_to_M2(kiss_fft_cfg fft_fwd_cfg, float ak[], int order, MODEL *model,
- float E, float *snr, int dump);
+ float E, float *snr, int dump, int sim_pf);
int encode_Wo(float Wo);
float decode_Wo(int index);