More VBR work.
authorjmvalin <jmvalin@0101bb08-14d6-0310-b084-bc0e0c8e3800>
Wed, 10 Jul 2002 20:45:53 +0000 (20:45 +0000)
committerjmvalin <jmvalin@0101bb08-14d6-0310-b084-bc0e0c8e3800>
Wed, 10 Jul 2002 20:45:53 +0000 (20:45 +0000)
Also added a 5.5 kbps mode and added frame-wide pitch to comfort noise
mode (now at 2.3 kbps).

git-svn-id: http://svn.xiph.org/trunk/speex@3565 0101bb08-14d6-0310-b084-bc0e0c8e3800

configure.in
libspeex/modes.c
libspeex/nb_celp.c
libspeex/sb_celp.c
libspeex/testenc_wb.c
libspeex/vbr.c

index ac759b5..3acfa46 100644 (file)
@@ -3,7 +3,7 @@ dnl Process this file with autoconf to produce a configure script. -*-m4-*-
 AC_INIT(libspeex/speex.h)
 
 SPEEX_MAJOR_VERSION=0
-SPEEX_MINOR_VERSION=4
+SPEEX_MINOR_VERSION=5
 SPEEX_MICRO_VERSION=0
 SPEEX_VERSION=$SPEEX_MAJOR_VERSION.$SPEEX_MINOR_VERSION.$SPEEX_MICRO_VERSION
 SPEEX_BINARY_AGE=0
index b74c2fa..3ec667d 100644 (file)
@@ -90,6 +90,13 @@ ltp_params ltp_params_med = {
    7
 };
 
+/* Split-VQ innovation parameters for very low bit-rate narrowband */
+split_cb_params split_cb_nb_vlbr = {
+   10,               /*subvect_size*/
+   4,               /*nb_subvect*/
+   exc_10_32_table, /*shape_cb*/
+   4,               /*shape_bits*/
+};
 
 /* Split-VQ innovation parameters for low bit-rate narrowband */
 split_cb_params split_cb_nb_lbr = {
@@ -162,6 +169,25 @@ SpeexSubmode nb_submode1 = {
 };
 
 SpeexSubmode nb_submode2 = {
+   0,
+   0,
+   /*LSP quantization*/
+   lsp_quant_lbr,
+   lsp_unquant_lbr,
+   /*No pitch quantization*/
+   NULL,
+   NULL,
+   NULL,
+   /*Innovation quantization*/
+   split_cb_search_nogain2,
+   split_cb_nogain_unquant,
+   &split_cb_nb_vlbr,
+   nb_post_filter,
+   &pf_params_lbr
+};
+
+
+SpeexSubmode nb_submode3 = {
    -1,
    1,
    /*LSP quantization*/
@@ -179,7 +205,7 @@ SpeexSubmode nb_submode2 = {
    &pf_params_lbr
 };
 
-SpeexSubmode nb_submode3 = {
+SpeexSubmode nb_submode4 = {
    -1,
    1,
    /*LSP quantization*/
@@ -197,7 +223,7 @@ SpeexSubmode nb_submode3 = {
    &pf_params_nb
 };
 
-SpeexSubmode nb_submode4 = {
+SpeexSubmode nb_submode5 = {
    -1,
    1,
    /*LSP quantization*/
@@ -215,7 +241,7 @@ SpeexSubmode nb_submode4 = {
    &pf_params_nb
 };
 
-SpeexSubmode nb_submode5 = {
+SpeexSubmode nb_submode6 = {
    -1,
    1,
    /*LSP quantization*/
@@ -247,9 +273,9 @@ SpeexNBMode nb_mode = {
    .005,   /*lag_factor*/
    1.0001, /*lpc_floor*/
    0.0,    /*preemph*/
-   {NULL, &nb_submode1, &nb_submode2, &nb_submode3, &nb_submode4, &nb_submode5, NULL, NULL,
+   {NULL, &nb_submode1, &nb_submode2, &nb_submode3, &nb_submode4, &nb_submode5, &nb_submode6, NULL,
    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
-   4
+   5
 };
 
 
index 89e838a..ef22060 100644 (file)
@@ -283,7 +283,7 @@ void nb_encode(void *state, float *in, SpeexBits *bits)
          qual=10;
       speex_encoder_ctl(state, SPEEX_SET_QUALITY, &qual);
    }
-   printf ("VBR quality = %f\n", vbr_qual);
+   /*printf ("VBR quality = %f\n", vbr_qual);*/
 
    /* First, transmit the sub-mode we use for this frame */
    speex_bits_pack(bits, st->submodeID, NB_SUBMODE_BITS);
@@ -298,11 +298,23 @@ void nb_encode(void *state, float *in, SpeexBits *bits)
 #endif
 
    /*If we use low bit-rate pitch mode, transmit open-loop pitch*/
-   if (SUBMODE(lbr_pitch) && SUBMODE(ltp_params))
+   if (SUBMODE(lbr_pitch)!=-1 && SUBMODE(ltp_params))
    {
       speex_bits_pack(bits, ol_pitch-st->min_pitch, 7);
+   } else if (SUBMODE(lbr_pitch)==0)
+   {
+      int quant;
+      speex_bits_pack(bits, ol_pitch-st->min_pitch, 7);
+      quant = (int)floor(.5+15*ol_pitch_coef);
+      if (quant>15)
+         quant=0;
+      if (quant<0)
+         quant=0;
+      speex_bits_pack(bits, quant, 4);
+      ol_pitch_coef=0.066667*quant;
    }
    
+   
    /*Quantize and transmit open-loop excitation gain*/
    {
       int qe = (int)(floor(3.5*log(ol_gain)));
@@ -451,6 +463,11 @@ void nb_encode(void *state, float *in, SpeexBits *bits)
          }
          /*printf ("cl_pitch: %d\n", pitch);*/
          st->pitch[sub]=pitch;
+      } else if (SUBMODE(lbr_pitch==0)) {
+         for (i=0;i<st->subframeSize;i++)
+         {
+            exc[i]=exc[i-ol_pitch]*ol_pitch_coef;
+         }
       }
 
       /* Update target for adaptive codebook contribution */
@@ -714,6 +731,7 @@ void nb_decode(void *state, SpeexBits *bits, float *out, int lost)
    float pitch_gain[3];
    float ol_gain;
    int ol_pitch=0;
+   float ol_pitch_coef=0;
    int best_pitch=40;
    float best_pitch_gain=-1;
    st=state;
@@ -737,8 +755,17 @@ void nb_decode(void *state, SpeexBits *bits, float *out, int lost)
    }
 
    /* Get open-loop pitch estimation for low bit-rate pitch coding */
-   if (SUBMODE(lbr_pitch) && SUBMODE(ltp_params))
+   if (SUBMODE(lbr_pitch)!=-1 && SUBMODE(ltp_params))
+   {
+      ol_pitch = st->min_pitch+speex_bits_unpack_unsigned(bits, 7);
+      speex_bits_pack(bits, ol_pitch-st->min_pitch, 7);
+   } else if (SUBMODE(lbr_pitch)==0)
+   {
+      int quant;
       ol_pitch = st->min_pitch+speex_bits_unpack_unsigned(bits, 7);
+      quant = speex_bits_unpack_unsigned(bits, 4);
+      ol_pitch_coef=0.066667*quant;
+   }
    
    /* Get global excitation gain */
    {
@@ -833,6 +860,11 @@ void nb_decode(void *state, SpeexBits *bits, float *out, int lost)
             for (i=0;i<st->subframeSize;i++)
                exc[i]=st->last_pitch_gain*exc[i-st->last_pitch];
          }
+      } else if (SUBMODE(lbr_pitch==0)) {
+         for (i=0;i<st->subframeSize;i++)
+         {
+            exc[i]=exc[i-ol_pitch]*ol_pitch_coef;
+         }
       }
       
       /* Unquantize the innovation */
@@ -860,8 +892,10 @@ void nb_decode(void *state, SpeexBits *bits, float *out, int lost)
             /*Fixed codebook contribution*/
             SUBMODE(innovation_unquant)(innov, SUBMODE(innovation_params), st->subframeSize, bits, st->stack);
          } else {
+            float scale;
+            scale = 3*sqrt(1.2-ol_pitch_coef);
             for (i=0;i<st->subframeSize;i++)
-               innov[i] = 3*((((float)rand())/RAND_MAX)-.5);
+               innov[i] = scale*((((float)rand())/RAND_MAX)-.5);
             
          }
 
@@ -932,16 +966,18 @@ void nb_encoder_ctl(void *state, int request, void *ptr)
          int quality = (*(int*)ptr);
          if (quality<=0)
             st->submodeID = 1;
-         else if (quality<=2)
+         else if (quality<=1)
             st->submodeID = 1;
-         else if (quality<=4)
+         else if (quality<=2)
             st->submodeID = 2;
-         else if (quality<=6)
+         else if (quality<=4)
             st->submodeID = 3;
-         else if (quality<=8)
+         else if (quality<=6)
             st->submodeID = 4;
-         else if (quality<=10)
+         else if (quality<=8)
             st->submodeID = 5;
+         else if (quality<=10)
+            st->submodeID = 6;
          else
             fprintf(stderr, "Unknown nb_ctl quality: %d\n", quality);
       }
index bb064ee..a891b62 100644 (file)
@@ -176,7 +176,7 @@ void *sb_encoder_init(SpeexMode *m)
    st->submodes=mode->submodes;
    st->submodeID=mode->defaultSubmode;
    {
-      int mod=5;
+      int mod=6;
       speex_encoder_ctl(st->st_low, SPEEX_SET_MODE, &mod);
    }
 
@@ -930,35 +930,38 @@ void sb_encoder_ctl(void *state, int request, void *ptr)
          switch (quality)
          {
          case 0:
-         case 1:
             nb_mode=1;
             st->submodeID = 1;
             break;
-         case 2:
+         case 1:
             nb_mode=2;
             st->submodeID = 1;
             break;
-         case 3:
+         case 2:
             nb_mode=3;
             st->submodeID = 1;
             break;
+         case 3:
+            nb_mode=4;
+            st->submodeID = 1;
+            break;
          case 4:
-            nb_mode=3;
+            nb_mode=4;
             st->submodeID = 2;
             break;
          case 5:
-            nb_mode=4;
+            nb_mode=5;
             st->submodeID = 2;
             break;
          case 6:
          case 7:
-            nb_mode=5;
+            nb_mode=6;
             st->submodeID = 2;
             break;
          case 8:
          case 9:
          case 10:
-            nb_mode=5;
+            nb_mode=6;
             st->submodeID = 3;
             break;
          default:
index 6fa6a75..c1fdf72 100644 (file)
@@ -25,6 +25,8 @@ int main(int argc, char **argv)
 
    pf=0;
    speex_decoder_ctl(dec, SPEEX_SET_PF, &pf);
+   pf=10;
+   speex_encoder_ctl(st, SPEEX_SET_QUALITY, &pf);
 
    if (argc != 4 && argc != 3)
    {
index 6af414d..c6a4999 100644 (file)
@@ -172,7 +172,7 @@ float vbr_analysis(VBRState *vbr, float *sig, int len, int pitch, float pitch_co
       vbr->last_log_energy[i] = vbr->last_log_energy[i-1];
    vbr->last_log_energy[0] = log_energy;
 
-   printf ("VBR: %f %f %f %d %f\n", (float)(log_energy-log(vbr->average_energy+MIN_ENERGY)), non_st, voicing, va, vbr->noise_level);
+   /*printf ("VBR: %f %f %f %d %f\n", (float)(log_energy-log(vbr->average_energy+MIN_ENERGY)), non_st, voicing, va, vbr->noise_level);*/
 
    return qual;
 }