added simulate lpc psotfiler option to c2sim
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Sat, 25 Aug 2012 04:56:01 +0000 (04:56 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Sat, 25 Aug 2012 04:56:01 +0000 (04:56 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@641 01035d8c-6547-0410-b346-abe4f91aad63

codec2-dev/src/c2sim.c
codec2-dev/src/codec2.c
codec2-dev/src/interp.c
codec2-dev/src/quantise.c
codec2-dev/src/quantise.h

index 434f4f399a43a34c379d4b1f06440f95a96146aa..eb08cb9ad1191d89ea924fc942fda0ee7eea6d6a 100644 (file)
@@ -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
index 7b848392578ff6aac922aa45822dcfc48cd251f7..4e41e1a08e1316f62ed8972c233968fc2afd0a80 100644 (file)
@@ -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]);
     }
 
index e7ae2d386233331cdddcb25a4f9fbd31eb4e7e3d..bd7389fe44ac04a71bf8a30a05bfd35782fe4ca9 100644 (file)
@@ -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]);
 }
 
index 5f24dd7337825857ddc43c8b8316eaf0c0d14ba2..e07b2d7e985573ed846c8686680924097d97293a 100644 (file)
@@ -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;
index e184a189cd49ff6a2f34ca815b481a1833051e6e..fd434f789a1cf6a86d4c5aba4c291dd439d3a5ed 100644 (file)
@@ -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);