[xiph-cvs] cvs commit: speex/libspeex filters.c nb_celp.c

Jean-Marc Valin jm at xiph.org
Sun Nov 9 22:28:00 PST 2003



jm          03/11/10 01:28:00

  Modified:    libspeex filters.c nb_celp.c
  Log:
  fixed-point: scaling functions are a bit less ugly, fine exc gain
  quantization now done in the linear domain and it didn't change anything

Revision  Changes    Path
1.55      +14 -5     speex/libspeex/filters.c

Index: filters.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/filters.c,v
retrieving revision 1.54
retrieving revision 1.55
diff -u -r1.54 -r1.55
--- filters.c	8 Nov 2003 06:52:00 -0000	1.54
+++ filters.c	10 Nov 2003 06:27:59 -0000	1.55
@@ -49,20 +49,30 @@
 
 #ifdef FIXED_POINT
 
-/* FIXME: These functions are ugly and probably cause too much error on small signals */
+/* FIXME: These functions are ugly and probably might too much error */
 void signal_mul(spx_sig_t *x, spx_sig_t *y, spx_word16_t scale, int len)
 {
    int i;
+   spx_word32_t s=16384*scale;
    for (i=0;i<len;i++)
-      y[i] = scale*x[i];
+   {
+      y[i] = MULT16_32_Q14((x[i]>>4),s)<<4;
+   }
 }
 
 void signal_div(spx_sig_t *x, spx_sig_t *y, spx_word16_t scale, int len)
 {
    int i;
-   spx_word16_t scale_1 = 32768./scale;
+   spx_word16_t scale_1;
+
+   if (scale<2)
+      scale_1 = 32767;
+   else
+      scale_1 = 32767/scale;
    for (i=0;i<len;i++)
+   {
       y[i] = MULT16_32_Q15(scale_1,x[i]);
+   }
 }
 
 #else
@@ -70,7 +80,6 @@
 void signal_mul(spx_sig_t *x, spx_sig_t *y, float scale, int len)
 {
    int i;
-   scale = floor(.5+scale);
    for (i=0;i<len;i++)
       y[i] = scale*x[i];
 }
@@ -78,7 +87,7 @@
 void signal_div(spx_sig_t *x, spx_sig_t *y, float scale, int len)
 {
    int i;
-   float scale_1 = 1/floor(.5+scale);
+   float scale_1 = 1/scale;
    for (i=0;i<len;i++)
       y[i] = scale_1*x[i];
 }

<p><p>1.143     +17 -26    speex/libspeex/nb_celp.c

Index: nb_celp.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/nb_celp.c,v
retrieving revision 1.142
retrieving revision 1.143
diff -u -r1.142 -r1.143
--- nb_celp.c	8 Nov 2003 06:52:00 -0000	1.142
+++ nb_celp.c	10 Nov 2003 06:27:59 -0000	1.143
@@ -46,11 +46,6 @@
 
 #include <stdio.h>
 
-#ifdef SLOW_TRIG
-#include "math_approx.h"
-#define cos speex_cos
-#endif
-
 #ifndef M_PI
 #define M_PI           3.14159265358979323846  /* pi */
 #endif
@@ -60,10 +55,10 @@
 #endif
 
 #define SUBMODE(x) st->submodes[st->submodeID]->x
+float exc_gain_quant_scal3[8]={0.061130, 0.163546, 0.310413, 0.428220, 0.555887, 0.719055, 0.938694, 1.326874};
 
-float exc_gain_quant_scal3[8]={-2.794750f, -1.810660f, -1.169850f, -0.848119f, -0.587190f, -0.329818f, -0.063266f, 0.282826f};
+float exc_gain_quant_scal1[2]={0.70469, 1.05127};
 
-float exc_gain_quant_scal1[2]={-0.35f, 0.05f};
 
 #define sqr(x) ((x)*(x))
 
@@ -352,11 +347,11 @@
             ol_gain2=ol2;
          ol_gain2 = sqrt(2*ol_gain2*(ol1+ol2))*1.3*(1-.5*ol_pitch_coef*ol_pitch_coef);
       
-         ol_gain=sqrt(1+ol_gain2/st->frameSize);
+         ol_gain=SHR(sqrt(1+ol_gain2/st->frameSize),SIG_SHIFT);
 
       } else {
 #endif
-         ol_gain = compute_rms(st->exc, st->frameSize);
+         ol_gain = SHL(compute_rms(st->exc, st->frameSize),SIG_SHIFT);
 #ifdef EPIC_48K
       }
 #endif
@@ -532,12 +527,12 @@
          
       }
       {
-         int qe = (int)(floor(.5+2.1*log(ol_gain)))-2;
+         int qe = (int)(floor(.5+2.1*log(ol_gain*1.0/SIG_SCALING)))-2;
          if (qe<0)
             qe=0;
          if (qe>15)
             qe=15;
-         ol_gain = exp((qe+2)/2.1);
+         ol_gain = exp((qe+2)/2.1)*SIG_SCALING;
          speex_bits_pack(bits, qe, 4);
       }
 
@@ -565,12 +560,12 @@
    
    /*Quantize and transmit open-loop excitation gain*/
    {
-      int qe = (int)(floor(3.5*log(ol_gain)));
+      int qe = (int)(floor(3.5*log(ol_gain*1.0/SIG_SCALING)));
       if (qe<0)
          qe=0;
       if (qe>31)
          qe=31;
-      ol_gain = exp(qe/3.5);
+      ol_gain = exp(qe/3.5)*SIG_SCALING;
       speex_bits_pack(bits, qe, 5);
    }
 
@@ -760,7 +755,7 @@
       /* Quantization of innovation */
       {
          spx_sig_t *innov;
-         float ener=0, ener_1;
+         float ener=0;
 
          innov = st->innov+sub*st->subframeSize;
          for (i=0;i<st->subframeSize;i++)
@@ -774,13 +769,12 @@
             printf ("%f\n", st->buf2[i]/ener);
          */
          
-         ener /= ol_gain;
+         ener /= ol_gain*1.0/SIG_SCALING;
 
          /* Calculate gain correction for the sub-frame (if any) */
          if (SUBMODE(have_subframe_gain)) 
          {
             int qe;
-            ener=log(ener);
             if (SUBMODE(have_subframe_gain)==3)
             {
                qe = vq_index(&ener, exc_gain_quant_scal3, 1, 8);
@@ -791,19 +785,16 @@
                speex_bits_pack(bits, qe, 1);
                ener=exc_gain_quant_scal1[qe];               
             }
-            ener=exp(ener);
          } else {
             ener=1;
          }
 
-         ener*=ol_gain;
+         ener*=ol_gain*1.0/SIG_SCALING;
 
          /*printf ("%f %f\n", ener, ol_gain);*/
 
-         ener_1 = 1/ener;
-
          /* Normalize innovation */
-         signal_div(target, target, ener, st->subframeSize);
+         signal_div(target, target, .5+ener, st->subframeSize);
          
          /* Quantize innovation */
          if (SUBMODE(innovation_quant))
@@ -814,7 +805,7 @@
                                       innov, syn_resp, bits, stack, st->complexity);
             
             /* De-normalize innovation and update excitation */
-            signal_mul(innov, innov, ener, st->subframeSize);
+            signal_mul(innov, innov, .5+ener, st->subframeSize);
 
             for (i=0;i<st->subframeSize;i++)
                exc[i] += innov[i];
@@ -839,7 +830,7 @@
                exc[i] += innov2[i];
          }
 
-         signal_mul(target, target, ener, st->subframeSize);
+         signal_mul(target, target, .5+ener, st->subframeSize);
       }
 
       /*Keep the previous memory*/
@@ -1522,11 +1513,11 @@
          if (SUBMODE(have_subframe_gain)==3)
          {
             q_energy = speex_bits_unpack_unsigned(bits, 3);
-            ener = ol_gain*exp(exc_gain_quant_scal3[q_energy]);
+            ener = ol_gain*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]);
+            ener = ol_gain*exc_gain_quant_scal1[q_energy];
          } else {
             ener = ol_gain;
          }
@@ -1540,7 +1531,7 @@
          }
 
          /* De-normalize innovation and update excitation */
-         signal_mul(innov, innov, ener, st->subframeSize);
+         signal_mul(innov, innov, .5+ener, st->subframeSize);
 
          /*Vocoder mode*/
          if (st->submodeID==1) 

<p><p>--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the commits mailing list