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

Jean-Marc Valin jm at xiph.org
Fri Nov 7 22:52:01 PST 2003



jm          03/11/08 01:52:01

  Modified:    libspeex filters.c filters.h lsp.c nb_celp.c testenc.c
  Log:
  fixed-point: removed some float ops in lpc_to_lsp and wrote signal scaling
  functions (which need to be improved).

Revision  Changes    Path
1.54      +37 -0     speex/libspeex/filters.c

Index: filters.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/filters.c,v
retrieving revision 1.53
retrieving revision 1.54
diff -u -r1.53 -r1.54
--- filters.c	7 Nov 2003 08:34:14 -0000	1.53
+++ filters.c	8 Nov 2003 06:52:00 -0000	1.54
@@ -47,6 +47,43 @@
    }
 }
 
+#ifdef FIXED_POINT
+
+/* FIXME: These functions are ugly and probably cause too much error on small signals */
+void signal_mul(spx_sig_t *x, spx_sig_t *y, spx_word16_t scale, int len)
+{
+   int i;
+   for (i=0;i<len;i++)
+      y[i] = scale*x[i];
+}
+
+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;
+   for (i=0;i<len;i++)
+      y[i] = MULT16_32_Q15(scale_1,x[i]);
+}
+
+#else
+
+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];
+}
+
+void signal_div(spx_sig_t *x, spx_sig_t *y, float scale, int len)
+{
+   int i;
+   float scale_1 = 1/floor(.5+scale);
+   for (i=0;i<len;i++)
+      y[i] = scale_1*x[i];
+}
+#endif
+
 
 
 #ifdef FIXED_POINT

<p><p>1.30      +5 -0      speex/libspeex/filters.h

Index: filters.h
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/filters.h,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -r1.29 -r1.30
--- filters.h	8 Oct 2003 22:31:41 -0000	1.29
+++ filters.h	8 Nov 2003 06:52:00 -0000	1.30
@@ -36,8 +36,13 @@
 #include "misc.h"
 
 spx_word16_t compute_rms(spx_sig_t *x, int len);
+void signal_mul(spx_sig_t *x, spx_sig_t *y, spx_word16_t scale, int len);
+void signal_div(spx_sig_t *x, spx_sig_t *y, spx_word16_t scale, int len);
+
 #ifdef FIXED_POINT
+
 int normalize16(spx_sig_t *x, spx_word16_t *y, int max_scale, int len);
+
 #endif
 
 typedef struct CombFilterMem {

<p><p>1.40      +3 -3      speex/libspeex/lsp.c

Index: lsp.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/lsp.c,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -r1.39 -r1.40
--- lsp.c	7 Nov 2003 08:34:14 -0000	1.39
+++ lsp.c	8 Nov 2003 06:52:00 -0000	1.40
@@ -208,7 +208,7 @@
 
 
 {
-
+    spx_word16_t ndelta;
     spx_word16_t temp_xr,xl,xr,xm=0;
     spx_word32_t psuml,psumr,psumm,temp_psumr/*,temp_qsumr*/;
     int i,j,m,flag,k;
@@ -224,7 +224,7 @@
     flag = 1;                	/*  program is searching for a root when,
                                 1 else has found one 			*/
     m = lpcrdr/2;            	/* order of P'(z) & Q'(z) polynomials 	*/
-
+    ndelta = delta*32768;
 
     /* Allocate memory space for polynomials */
     Q = PUSH(stack, (m+1), spx_word32_t);
@@ -299,7 +299,7 @@
            spx_word16_t dd;
            /* Modified by JMV to provide smaller steps around x=+-1 */
 #ifdef FIXED_POINT
-           dd = delta*(FREQ_SCALE - MULT16_16_Q14(MULT16_16_Q14(xl,xl),14000));
+           dd = MULT16_16_Q15(ndelta,(FREQ_SCALE - MULT16_16_Q14(MULT16_16_Q14(xl,xl),14000)));
            if (psuml<512 && psuml>-512)
               dd = PSHR(dd,1);
 #else

<p><p>1.142     +10 -14    speex/libspeex/nb_celp.c

Index: nb_celp.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/nb_celp.c,v
retrieving revision 1.141
retrieving revision 1.142
diff -u -r1.141 -r1.142
--- nb_celp.c	7 Nov 2003 08:34:14 -0000	1.141
+++ nb_celp.c	8 Nov 2003 06:52:00 -0000	1.142
@@ -341,18 +341,18 @@
       if (st->lbr_48k)
       {
          float ol1=0,ol2=0;
-         
+         float ol_gain2;
          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;
+         ol_gain2=ol1;
          if (ol2>ol1)
-            ol_gain=ol2;
-         ol_gain = sqrt(2*ol_gain*(ol1+ol2))*1.3*(1-.5*ol_pitch_coef*ol_pitch_coef);
+            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_gain/st->frameSize);
+         ol_gain=sqrt(1+ol_gain2/st->frameSize);
 
       } else {
 #endif
@@ -803,8 +803,7 @@
          ener_1 = 1/ener;
 
          /* Normalize innovation */
-         for (i=0;i<st->subframeSize;i++)
-            target[i]*=ener_1;
+         signal_div(target, target, ener, st->subframeSize);
          
          /* Quantize innovation */
          if (SUBMODE(innovation_quant))
@@ -815,8 +814,8 @@
                                       innov, syn_resp, bits, stack, st->complexity);
             
             /* De-normalize innovation and update excitation */
-            for (i=0;i<st->subframeSize;i++)
-               innov[i]*=ener;
+            signal_mul(innov, innov, ener, st->subframeSize);
+
             for (i=0;i<st->subframeSize;i++)
                exc[i] += innov[i];
          } else {
@@ -840,9 +839,7 @@
                exc[i] += innov2[i];
          }
 
-         for (i=0;i<st->subframeSize;i++)
-            target[i]*=ener;
-
+         signal_mul(target, target, ener, st->subframeSize);
       }
 
       /*Keep the previous memory*/
@@ -1543,8 +1540,7 @@
          }
 
          /* De-normalize innovation and update excitation */
-         for (i=0;i<st->subframeSize;i++)
-            innov[i]*=ener;
+         signal_mul(innov, innov, ener, st->subframeSize);
 
          /*Vocoder mode*/
          if (st->submodeID==1) 

<p><p>1.52      +1 -1      speex/libspeex/testenc.c

Index: testenc.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/testenc.c,v
retrieving revision 1.51
retrieving revision 1.52
diff -u -r1.51 -r1.52
--- testenc.c	2 Nov 2003 07:44:35 -0000	1.51
+++ testenc.c	8 Nov 2003 06:52:00 -0000	1.52
@@ -112,7 +112,7 @@
             s += (float)in_short[i] * in_short[i];
             e += ((float)in_short[i]-out_short[i]) * ((float)in_short[i]-out_short[i]);
         }
-	seg_snr += 10*log10((s+1)/(e+1));
+	seg_snr += 10*log10((s+160)/(e+160));
         sigpow += s;
         errpow += e;
         snr_frames++;

<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