[xiph-cvs] cvs commit: speex/libspeex cb_search.c filters.c filters.h nb_celp.c sb_celp.c smallft.c

Jean-Marc Valin jm at xiph.org
Tue Oct 7 21:52:27 PDT 2003



jm          03/10/08 00:52:27

  Modified:    libspeex cb_search.c filters.c filters.h nb_celp.c sb_celp.c
                        smallft.c
  Log:
  fixed-point: computation of rms values in fp

Revision  Changes    Path
1.96      +1 -1      speex/libspeex/cb_search.c

Index: cb_search.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/cb_search.c,v
retrieving revision 1.95
retrieving revision 1.96
diff -u -r1.95 -r1.96
--- cb_search.c	8 Oct 2003 04:50:44 -0000	1.95
+++ cb_search.c	8 Oct 2003 04:52:27 -0000	1.96
@@ -314,7 +314,7 @@
       }
 #else
       for (j=0;j<subvect_size;j++)
-         e[subvect_size*i+j]=sign*0.03125*SIG_SCALING*shape_cb[rind*subvect_size+j];
+         e[subvect_size*i+j]=sign*0.03125*shape_cb[rind*subvect_size+j];
 #endif
    }   
    /* Update excitation */

<p><p>1.41      +51 -0     speex/libspeex/filters.c

Index: filters.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/filters.c,v
retrieving revision 1.40
retrieving revision 1.41
diff -u -r1.40 -r1.41
--- filters.c	8 Oct 2003 04:42:59 -0000	1.40
+++ filters.c	8 Oct 2003 04:52:27 -0000	1.41
@@ -49,6 +49,47 @@
 
 #ifdef FIXED_POINT
 
+spx_word16_t compute_rms(spx_sig_t *x, int len)
+{
+   int i;
+   spx_word32_t sum=0;
+   spx_sig_t max_val=1;
+   int sig_shift;
+
+   for (i=0;i<len;i++)
+   {
+      spx_sig_t tmp = x[i];
+      if (tmp<0)
+         tmp = -1;
+      if (tmp > max_val)
+         max_val = tmp;
+   }
+
+   sig_shift=0;
+   while (max_val>2048)
+   {
+      sig_shift++;
+      max_val >>= 1;
+   }
+
+   for (i=0;i<len;i+=4)
+   {
+      spx_word32_t sum2=0;
+      spx_word16_t tmp;
+      tmp = SHR(x[i],sig_shift);
+      sum2 += MULT16_16(tmp,tmp);
+      tmp = SHR(x[i+1],sig_shift);
+      sum2 += MULT16_16(tmp,tmp);
+      tmp = SHR(x[i+2],sig_shift);
+      sum2 += MULT16_16(tmp,tmp);
+      tmp = SHR(x[i+3],sig_shift);
+      sum2 += MULT16_16(tmp,tmp);
+      sum += sum2;
+   }
+   
+   /*FIXME: remove division*/
+   return (1<<sig_shift)*sqrt(1+sum/len)/SIG_SCALING;
+}
 
 #define MUL_16_32_R15(a,bh,bl) ((a)*(bh) + ((a)*(bl)>>15))
 
@@ -123,6 +164,16 @@
 #include "filters_sse.h"
 #else
 
+spx_word16_t compute_rms(spx_sig_t *x, int len)
+{
+   int i;
+   float sum=0;
+   for (i=0;i<len;i++)
+   {
+      sum += x[i]*x[i];
+   }
+   return sqrt(.1+sum/len);
+}
 
 void filter_mem2(spx_sig_t *x, spx_coef_t *num, spx_coef_t *den, spx_sig_t *y, int N, int ord,  spx_mem_t *mem)
 {

<p><p>1.26      +2 -0      speex/libspeex/filters.h

Index: filters.h
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/filters.h,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -r1.25 -r1.26
--- filters.h	8 Oct 2003 04:40:41 -0000	1.25
+++ filters.h	8 Oct 2003 04:52:27 -0000	1.26
@@ -35,6 +35,8 @@
 
 #include "misc.h"
 
+spx_word16_t compute_rms(spx_sig_t *x, int len);
+
 typedef struct CombFilterMem {
    int   last_pitch;
    float last_pitch_gain[3];

<p><p>1.133     +9 -12     speex/libspeex/nb_celp.c

Index: nb_celp.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/nb_celp.c,v
retrieving revision 1.132
retrieving revision 1.133
diff -u -r1.132 -r1.133
--- nb_celp.c	8 Oct 2003 04:42:59 -0000	1.132
+++ nb_celp.c	8 Oct 2003 04:52:27 -0000	1.133
@@ -350,10 +350,11 @@
       if (st->lbr_48k)
       {
          float ol1=0,ol2=0;
-         for (i=0;i<st->frameSize>>1;i++)
-            ol1 += st->exc[i]*st->exc[i] / (SIG_SCALING*SIG_SCALING);
-         for (i=st->frameSize>>1;i<st->frameSize;i++)
-            ol2 += st->exc[i]*st->exc[i] / (SIG_SCALING*SIG_SCALING);
+         
+         ol1 = compute_rms(st->exc, st->frameSize>>1);
+         ol2 = compute_rms(st->exc+(st->frameSize>>1), st->frameSize>>1);
+         ol1 *= ol1*(st->frameSize>>1);
+         ol2 *= ol2*(st->frameSize>>1);
 
          ol_gain=ol1;
          if (ol2>ol1)
@@ -364,11 +365,7 @@
 
       } else {
 #endif
-      ol_gain=0;
-      for (i=0;i<st->frameSize;i++)
-         ol_gain += st->exc[i]*st->exc[i] / (SIG_SCALING*SIG_SCALING);
-      
-      ol_gain=sqrt(1+ol_gain/st->frameSize);
+         ol_gain = compute_rms(st->exc, st->frameSize);
 #ifdef EPIC_48K
       }
 #endif
@@ -783,9 +780,9 @@
             innov[i]=0;
          
          residue_percep_zero(target, st->interp_qlpc, st->bw_lpc1, st->bw_lpc2, st->buf2, st->subframeSize, st->lpcSize, stack);
-         for (i=0;i<st->subframeSize;i++)
-            ener+=st->buf2[i]*st->buf2[i] / (SIG_SCALING*SIG_SCALING);
-         ener=sqrt(.1+ener/st->subframeSize);
+
+         ener = compute_rms(st->buf2, st->subframeSize);
+
          /*for (i=0;i<st->subframeSize;i++)
             printf ("%f\n", st->buf2[i]/ener);
          */

<p><p>1.135     +15 -23    speex/libspeex/sb_celp.c

Index: sb_celp.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/sb_celp.c,v
retrieving revision 1.134
retrieving revision 1.135
diff -u -r1.134 -r1.135
--- sb_celp.c	8 Oct 2003 04:44:02 -0000	1.134
+++ sb_celp.c	8 Oct 2003 04:52:27 -0000	1.135
@@ -356,13 +356,11 @@
       }
 
 
-      for (i=0;i<st->frame_size;i++)
-      {
-         /*FIXME: Are the two signals (low, high) in sync? */
-         e_low  += st->x0d[i]* st->x0d[i] / (SIG_SCALING*SIG_SCALING);
-         e_high += st->high[i]* st->high[i] / (SIG_SCALING*SIG_SCALING);
-      }
-      ratio = log((1+e_high)/(1+e_low));
+      /*FIXME: Are the two signals (low, high) in sync? */
+      e_low = compute_rms(st->x0d, st->frame_size);
+      e_high = compute_rms(st->high, st->frame_size);
+      ratio = 2*log((1+e_high)/(1+e_low));
+      
       speex_encoder_ctl(st->st_low, SPEEX_GET_RELATIVE_QUALITY, &st->relative_quality);
       if (ratio<-4)
          ratio=-4;
@@ -533,18 +531,16 @@
       /* Compute "real excitation" */
       fir_mem2(sp, st->interp_qlpc, exc, st->subframeSize, st->lpcSize, st->mem_sp2);
       /* Compute energy of low-band and high-band excitation */
-      for (i=0;i<st->subframeSize;i++)
-         eh+=sqr(exc[i]/SIG_SCALING);
+
+      eh = compute_rms(exc, st->subframeSize);
 
       if (!SUBMODE(innovation_quant)) {/* 1 for spectral folding excitation, 0 for stochastic */
          float g;
-         /*speex_bits_pack(bits, 1, 1);*/
-         for (i=0;i<st->subframeSize;i++)
-            el+=sqr(low_innov[offset+i]/SIG_SCALING);
+
+         el = compute_rms(low_innov+offset, st->subframeSize);
 
          /* Gain to use if we want to use the low-band excitation for high-band */
          g=eh/(.01+el);
-         g=sqrt(g);
 
          g *= filter_ratio;
          /*print_vec(&g, 1, "gain factor");*/
@@ -565,11 +561,10 @@
       } else {
          float gc, scale, scale_1;
 
-         for (i=0;i<st->subframeSize;i++)
-            el+=sqr(low_exc[offset+i]/SIG_SCALING);
-         /*speex_bits_pack(bits, 0, 1);*/
+         el = compute_rms(low_exc+offset, st->subframeSize);
+         /*FIXME: cleanup the "historical" mess with sqrt(st->subframeSize) */
+         gc = (1+eh)*filter_ratio/(1+el)/sqrt(st->subframeSize);
 
-         gc = sqrt(1+eh)*filter_ratio/sqrt((1+el)*st->subframeSize);
          {
             int qgc = (int)floor(.5+3.7*(log(gc)+2));
             if (qgc<0)
@@ -580,7 +575,7 @@
             gc = exp((1/3.7)*qgc-2);
          }
 
-         scale = gc*sqrt(1+el)/filter_ratio;
+         scale = gc*(1+el*sqrt(st->subframeSize))/filter_ratio;
          scale_1 = 1/scale;
 
          for (i=0;i<st->subframeSize;i++)
@@ -1024,8 +1019,6 @@
          float g;
          int quant;
 
-         for (i=0;i<st->subframeSize;i++)
-            el+=sqr(low_innov[offset+i]/SIG_SCALING);
          quant = speex_bits_unpack_unsigned(bits, 5);
          g= exp(((float)quant-10)/8.0);
          
@@ -1039,13 +1032,12 @@
       } else {
          float gc, scale;
          int qgc = speex_bits_unpack_unsigned(bits, 4);
-         for (i=0;i<st->subframeSize;i++)
-            el+=sqr(low_exc[offset+i]/SIG_SCALING);
 
+         el = compute_rms(low_exc+offset, st->subframeSize);
 
          gc = exp((1/3.7)*qgc-2);
 
-         scale = gc*sqrt(1+el)/filter_ratio;
+         scale = gc*(1+el*sqrt(st->subframeSize))/filter_ratio;
 
          SUBMODE(innovation_unquant)(exc, SUBMODE(innovation_params), st->subframeSize, 
                                 bits, stack);

<p><p>1.10      +0 -0      speex/libspeex/smallft.c

Index: smallft.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/smallft.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- smallft.c	8 Oct 2003 04:50:44 -0000	1.9
+++ smallft.c	8 Oct 2003 04:52:27 -0000	1.10
@@ -11,7 +11,7 @@
  ********************************************************************
 
  function: *unnormalized* fft transform
- last mod: $Id: smallft.c,v 1.9 2003/10/08 04:50:44 jm Exp $
+ last mod: $Id: smallft.c,v 1.10 2003/10/08 04:52:27 jm Exp $
 
  ********************************************************************/
 

<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