new 1300 bit/s mode
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Mon, 18 Mar 2013 04:20:52 +0000 (04:20 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Mon, 18 Mar 2013 04:20:52 +0000 (04:20 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@1207 01035d8c-6547-0410-b346-abe4f91aad63

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

index 5c6d279c807fe30f710517b9796151596a44fa4c..b9efcc4cf213e69e35db5dcea3c4f0a24220f6be 100644 (file)
@@ -55,6 +55,8 @@ struct CODEC2 {
 
     float         xq_enc[2];               /* joint pitch and energy VQ states          */
     float         xq_dec[2];
+
+    int           smoothing;               /* enable smoothing for channels with errors */
 };
 
 #endif
index a8d818fa4279eebd19ee07b9dbc6800f1f5bfe2a..d7e56abba5aef86872421634ee90090d5ac8ead5 100644 (file)
@@ -223,6 +223,26 @@ void interp_Wo(
   MODEL *prev,      /* previous frames model params                  */
   MODEL *next       /* next frames model params                      */
               )
+{
+    interp_Wo2(interp, prev, next, 0.5);
+}
+
+/*---------------------------------------------------------------------------*\
+
+  FUNCTION....: interp_Wo2()        
+  AUTHOR......: David Rowe                           
+  DATE CREATED: 22 May 2012
+        
+  Weighted interpolation of two Wo samples.
+  
+\*---------------------------------------------------------------------------*/
+
+void interp_Wo2(
+  MODEL *interp,    /* interpolated model params                     */
+  MODEL *prev,      /* previous frames model params                  */
+  MODEL *next,      /* next frames model params                      */
+  float  weight
+)
 {
     /* trap corner case where voicing est is probably wrong */
 
@@ -234,7 +254,7 @@ void interp_Wo(
 
     if (interp->voiced) {
        if (prev->voiced && next->voiced)
-           interp->Wo = (prev->Wo + next->Wo)/2.0;
+           interp->Wo = (1.0 - weight)*prev->Wo + weight*next->Wo;
        if (!prev->voiced && next->voiced)
            interp->Wo = next->Wo;
        if (prev->voiced && !next->voiced)
@@ -265,6 +285,24 @@ float interp_energy(float prev_e, float next_e)
 }
 
 
+/*---------------------------------------------------------------------------*\
+
+  FUNCTION....: interp_energy2()            
+  AUTHOR......: David Rowe                           
+  DATE CREATED: 22 May 2012
+        
+  Interpolates centre 10ms sample of energy given two samples 20ms
+  apart.
+  
+\*---------------------------------------------------------------------------*/
+
+float interp_energy2(float prev_e, float next_e, float weight)
+{
+    return pow(10.0, (1.0 - weight)*log10(prev_e) + weight*log10(next_e));
+}
+
+
 /*---------------------------------------------------------------------------*\
 
   FUNCTION....: interpolate_lsp_ver2()      
index 312ccb76da586e153b9db6420067d25147ac18b0..68d817b7de10bfa0c05ee471e974e5668d518367 100644 (file)
@@ -37,7 +37,9 @@ void interpolate_lsp(kiss_fft_cfg  fft_dec_cfg,
                     float *next_lsps, float  next_e,
                     float *ak_interp, float *lsps_interp);
 void interp_Wo(MODEL *interp, MODEL *prev, MODEL *next);
+void interp_Wo2(MODEL *interp, MODEL *prev, MODEL *next, float weight);
 float interp_energy(float prev, float next);
+float interp_energy2(float prev, float next, float weight);
 void interpolate_lsp_ver2(float interp[], float prev[],  float next[], float weight);
 
 #endif
index 1153943b9fe6a21f42d2f06f3db33001eea3142c..62728b843741256578910f55de01e43f3a71243f 100644 (file)
@@ -727,11 +727,12 @@ int check_lsp_order(float lsp[], int lpc_order)
 
     for(i=1; i<lpc_order; i++)
        if (lsp[i] < lsp[i-1]) {
-           //printf("swap %d\n",i);
+           //fprintf(stderr, "swap %d\n",i);
            swaps++;
            tmp = lsp[i-1];
-           lsp[i-1] = lsp[i]-0.05;
-           lsp[i] = tmp+0.05;
+           lsp[i-1] = lsp[i]-0.1;
+           lsp[i] = tmp+0.1;
+            i = 1; /* start check again, as swap may have caused out of order */
        }
 
     return swaps;
@@ -1644,7 +1645,7 @@ void bw_expand_lsps(float lsp[],
 
     for(i=1; i<4; i++) {
        
-       if ((lsp[i] - lsp[i-1]) < 50*(PI/4000.0))
+       if ((lsp[i] - lsp[i-1]) < 50.0*(PI/4000.0))
            lsp[i] = lsp[i-1] + 50.0*(PI/4000.0);
        
     }
@@ -1655,8 +1656,32 @@ void bw_expand_lsps(float lsp[],
     */
 
     for(i=4; i<order; i++) {
-       if (lsp[i] - lsp[i-1] < PI*(100.0/4000.0))
-           lsp[i] = lsp[i-1] + PI*(100.0/4000.0);
+       if (lsp[i] - lsp[i-1] < 100.0*(PI/4000.0))
+           lsp[i] = lsp[i-1] + 100.0*(PI/4000.0);
+    }
+}
+
+void bw_expand_lsps2(float lsp[],
+                   int   order
+)
+{
+    int i;
+
+    for(i=1; i<4; i++) {
+       
+       if ((lsp[i] - lsp[i-1]) < 100.0*(PI/4000.0))
+           lsp[i] = lsp[i-1] + 100.0*(PI/4000.0);
+       
+    }
+
+    /* As quantiser gaps increased, larger BW expansion was required
+       to prevent twinkly noises.  This may need more experiment for
+       different quanstisers.
+    */
+
+    for(i=4; i<order; i++) {
+       if (lsp[i] - lsp[i-1] < 200.0*(PI/4000.0))
+           lsp[i] = lsp[i-1] + 200.0*(PI/4000.0);
     }
 }
 
index 1f5f9ee788d7890254e74ae7d1bff85c267ccdef..a8597d99b66f09df61cdd470887ba45a49607059 100644 (file)
@@ -112,6 +112,7 @@ float speech_to_uq_lsps(float lsp[],
                        );
 int check_lsp_order(float lsp[], int lpc_order);
 void bw_expand_lsps(float lsp[], int order);
+void bw_expand_lsps2(float lsp[], int order);
 void locate_lsps_jnd_steps(float lsp[], int order);
 float decode_amplitudes(MODEL *model, 
                        float  ak[],