Reduced number of bits to code subframe excitation gain on low modes
authorjmvalin <jmvalin@0101bb08-14d6-0310-b084-bc0e0c8e3800>
Thu, 8 Aug 2002 20:53:21 +0000 (20:53 +0000)
committerjmvalin <jmvalin@0101bb08-14d6-0310-b084-bc0e0c8e3800>
Thu, 8 Aug 2002 20:53:21 +0000 (20:53 +0000)
git-svn-id: http://svn.xiph.org/trunk/speex@3769 0101bb08-14d6-0310-b084-bc0e0c8e3800

libspeex/modes.c
libspeex/nb_celp.c

index fb3c2ea..dcc3355 100644 (file)
@@ -144,7 +144,7 @@ static SpeexSubmode nb_submode1 = {
    NULL,
 
    0, 0, -1,
-   2500
+   2100
 };
 
 static SpeexSubmode nb_submode2 = {
@@ -183,7 +183,7 @@ static SpeexSubmode nb_submode3 = {
    &split_cb_nb_lbr,
 
    0.75, 0.6, .5,
-   8350
+   7950
 };
 
 static SpeexSubmode nb_submode4 = {
@@ -202,12 +202,12 @@ static SpeexSubmode nb_submode4 = {
    &split_cb_nb_med,
 
    0.72, 0.65, .3,
-   11350
+   10950
 };
 
 static SpeexSubmode nb_submode5 = {
    -1,
-   1,
+   3,
    /*LSP quantization*/
    lsp_quant_nb,
    lsp_unquant_nb,
@@ -226,7 +226,7 @@ static SpeexSubmode nb_submode5 = {
 
 static SpeexSubmode nb_submode6 = {
    -1,
-   1,
+   3,
    /*LSP quantization*/
    lsp_quant_nb,
    lsp_unquant_nb,
@@ -267,7 +267,7 @@ SpeexMode speex_nb_mode = {
    &nb_mode,
    "narrowband",
    0,
-   3,
+   4,
    &nb_encoder_init,
    &nb_encoder_destroy,
    &nb_encode,
@@ -362,7 +362,7 @@ SpeexMode speex_wb_mode = {
    &sb_wb_mode,
    "full-rate wideband (sub-band CELP)",
    1,
-   3,
+   4,
    &sb_encoder_init,
    &sb_encoder_destroy,
    &sb_encode,
index b4f2d5e..c56f36f 100644 (file)
 #include "vbr.h"
 #include "misc.h"
 
+extern int training_weight;
 #ifndef M_PI
 #define M_PI           3.14159265358979323846  /* pi */
 #endif
 
 #define SUBMODE(x) st->submodes[st->submodeID]->x
 
-float exc_gain_quant_scal[8]={-2.794750, -1.810660, -1.169850, -0.848119, -0.587190, -0.329818, -0.063266, 0.282826};
+float exc_gain_quant_scal3[8]={-2.794750, -1.810660, -1.169850, -0.848119, -0.587190, -0.329818, -0.063266, 0.282826};
+
+float exc_gain_quant_scal1[2]={-0.35, 0.05};
 
 #define sqr(x) ((x)*(x))
 #define min(a,b) ((a) < (b) ? (a) : (b))
@@ -540,22 +544,43 @@ void nb_encode(void *state, float *in, SpeexBits *bits)
             ener+=st->buf2[i]*st->buf2[i];
          ener=sqrt(.1+ener/st->subframeSize);
 
+         
          ener /= ol_gain;
+
+         if (1)
+            printf ("ener: %f %f %f\n", ener, ol_gain, ol_pitch_coef);
+
          if (SUBMODE(have_subframe_gain)) 
          {
             int qe;
             ener=log(ener);
-            qe = vq_index(&ener, exc_gain_quant_scal, 1, 8);
-            speex_bits_pack(bits, qe, 3);
-            ener=exc_gain_quant_scal[qe];
+            if (SUBMODE(have_subframe_gain)==3)
+            {
+               qe = vq_index(&ener, exc_gain_quant_scal3, 1, 8);
+               speex_bits_pack(bits, qe, 3);
+               ener=exc_gain_quant_scal3[qe];
+            } else {
+               qe = vq_index(&ener, exc_gain_quant_scal1, 1, 2);
+               speex_bits_pack(bits, qe, 1);
+               ener=exc_gain_quant_scal1[qe];               
+            }
             ener=exp(ener);
             /*printf ("encode gain: %d %f\n", qe, ener);*/
          } else {
             ener=1;
          }
+
          ener*=ol_gain;
          /*printf ("transmit gain: %f\n", ener);*/
          ener_1 = 1/ener;
+
+         if (0) {
+            int start=rand()%35;
+            printf ("norm_exc: ");
+            for (i=start;i<start+5;i++)
+               printf ("%f ", ener_1*st->buf2[i]);
+            printf ("\n");
+         }
          
          for (i=0;i<st->subframeSize;i++)
             target[i]*=ener_1;
@@ -879,10 +904,14 @@ void nb_decode(void *state, SpeexBits *bits, float *out, int lost)
          for (i=0;i<st->subframeSize;i++)
             innov[i]=0;
 
-         if (SUBMODE(have_subframe_gain))
+         if (SUBMODE(have_subframe_gain)==3)
          {
             q_energy = speex_bits_unpack_unsigned(bits, 3);
-            ener = ol_gain*exp(exc_gain_quant_scal[q_energy]);
+            ener = ol_gain*exp(exc_gain_quant_scal3[q_energy]);
+         } else if (SUBMODE(have_subframe_gain)==1)
+         {
+            q_energy = speex_bits_unpack_unsigned(bits, 1);
+            ener = ol_gain*exp(exc_gain_quant_scal1[q_energy]);
          } else {
             ener = ol_gain;
          }