From: drowe67 Date: Sat, 25 Aug 2012 04:56:01 +0000 (+0000) Subject: added simulate lpc psotfiler option to c2sim X-Git-Url: http://git.whiteaudio.com/gitweb/?a=commitdiff_plain;h=f6af026bb42dafc20e8b0fa86457acf47f3976bb;p=freetel-svn-tracking.git added simulate lpc psotfiler option to c2sim git-svn-id: https://svn.code.sf.net/p/freetel/code@641 01035d8c-6547-0410-b346-abe4f91aad63 --- diff --git a/codec2-dev/src/c2sim.c b/codec2-dev/src/c2sim.c index 434f4f39..eb08cb9a 100644 --- a/codec2-dev/src/c2sim.c +++ b/codec2-dev/src/c2sim.c @@ -5,8 +5,8 @@ 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. \*---------------------------------------------------------------------------*/ @@ -98,7 +98,7 @@ int main(int argc, char *argv[]) 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; @@ -144,6 +144,7 @@ int main(int argc, char *argv[]) { "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 }, @@ -611,7 +612,7 @@ int main(int argc, char *argv[]) } - 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 diff --git a/codec2-dev/src/codec2.c b/codec2-dev/src/codec2.c index 7b848392..4e41e1a0 100644 --- a/codec2-dev/src/codec2.c +++ b/codec2-dev/src/codec2.c @@ -356,7 +356,7 @@ void codec2_decode_2400(struct CODEC2 *c2, short speech[], const unsigned char * 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]); } @@ -383,7 +383,7 @@ void codec2_decode_2400(struct CODEC2 *c2, short speech[], const unsigned char * 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 @@ -528,7 +528,7 @@ void codec2_decode_1400(struct CODEC2 *c2, short speech[], const unsigned char * } 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]); } @@ -705,7 +705,7 @@ void codec2_decode_1200(struct CODEC2 *c2, short speech[], const unsigned char * } 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]); } diff --git a/codec2-dev/src/interp.c b/codec2-dev/src/interp.c index e7ae2d38..bd7389fe 100644 --- a/codec2-dev/src/interp.c +++ b/codec2-dev/src/interp.c @@ -201,7 +201,7 @@ void interpolate_lsp( /* 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]); } diff --git a/codec2-dev/src/quantise.c b/codec2-dev/src/quantise.c index 5f24dd73..e07b2d7e 100644 --- a/codec2-dev/src/quantise.c +++ b/codec2-dev/src/quantise.c @@ -645,7 +645,7 @@ float lpc_model_amplitudes( } #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; } @@ -668,7 +668,8 @@ void aks_to_M2( 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 */ @@ -721,13 +722,21 @@ void aks_to_M2( 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); @@ -1447,7 +1456,7 @@ float decode_amplitudes(kiss_fft_cfg fft_fwd_cfg, 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; diff --git a/codec2-dev/src/quantise.h b/codec2-dev/src/quantise.h index e184a189..fd434f78 100644 --- a/codec2-dev/src/quantise.h +++ b/codec2-dev/src/quantise.h @@ -52,7 +52,7 @@ void quantise_init(); 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);