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

Jean-Marc Valin jm at xiph.org
Mon Nov 10 23:33:04 PST 2003



jm          03/11/11 02:33:04

  Modified:    libspeex lsp.c nb_celp.c sb_celp.c
  Log:
  fixed-point: increased precision of the cos approximation, fixed some
  floating-point/fixed-point mismatch

Revision  Changes    Path
1.43      +14 -9     speex/libspeex/lsp.c

Index: lsp.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/lsp.c,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -r1.42 -r1.43
--- lsp.c	10 Nov 2003 08:57:27 -0000	1.42
+++ lsp.c	11 Nov 2003 07:33:03 -0000	1.43
@@ -58,26 +58,31 @@
 
 #ifdef FIXED_POINT
 
-#define C1 8187
-#define C2 -4058
-#define C3 301
-static spx_word16_t cos_32(spx_word16_t x)
+#define C1 8192
+#define C2 -4096
+#define C3 340
+#define C4 -10
+
+static spx_word16_t spx_cos(spx_word16_t x)
 {
    spx_word16_t x2;
 
    if (x<12868)
    {
-      x2 = MULT16_16_Q13(x,x);
-      return ADD32(C1, MULT16_16_Q13(x2, ADD32(C2, MULT16_16_Q13(C3, x2))));
+      x2 = MULT16_16_P13(x,x);
+      return ADD32(C1, MULT16_16_P13(x2, ADD32(C2, MULT16_16_P13(x2, ADD32(C3, MULT16_16_P13(C4, x2))))));
    } else {
       x = 25736-x;
-      x2 = MULT16_16_Q13(x,x);
-      return SUB32(-C1, MULT16_16_Q13(x2, ADD32(C2, MULT16_16_Q13(C3, x2))));
+      x2 = MULT16_16_P13(x,x);
+      return SUB32(-C1, MULT16_16_P13(x2, ADD32(C2, MULT16_16_P13(x2, ADD32(C3, MULT16_16_P13(C4, x2))))));
+      //return SUB32(-C1, MULT16_16_Q13(x2, ADD32(C2, MULT16_16_Q13(C3, x2))));
    }
 }
 
+
 #define FREQ_SCALE 16384
-#define ANGLE2X(a) (SHL(cos_32(a),2))
+//#define ANGLE2X(a) (32768*cos(((a)/8192.)))
+#define ANGLE2X(a) (SHL(spx_cos(a),2))
 //#define X2ANGLE(x) (acos(.00006103515625*(x))*LSP_SCALING)
 #define X2ANGLE(x) (spx_acos(x))
 /* maybe we could approximate acos as 

<p><p>1.147     +16 -2     speex/libspeex/nb_celp.c

Index: nb_celp.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/nb_celp.c,v
retrieving revision 1.146
retrieving revision 1.147
diff -u -r1.146 -r1.147
--- nb_celp.c	10 Nov 2003 19:28:20 -0000	1.146
+++ nb_celp.c	11 Nov 2003 07:33:03 -0000	1.147
@@ -788,8 +788,11 @@
          /*printf ("%f %f\n", ener, ol_gain);*/
 
          /* Normalize innovation */
+#ifdef FIXED_POINT
          signal_div(target, target, .5+ener, st->subframeSize);
-         
+#else
+         signal_div(target, target, ener, st->subframeSize);
+#endif
          /* Quantize innovation */
          if (SUBMODE(innovation_quant))
          {
@@ -799,7 +802,11 @@
                                       innov, syn_resp, bits, stack, st->complexity);
             
             /* De-normalize innovation and update excitation */
+#ifdef FIXED_POINT
             signal_mul(innov, innov, .5+ener, st->subframeSize);
+#else
+            signal_mul(innov, innov, ener, st->subframeSize);
+#endif
 
             for (i=0;i<st->subframeSize;i++)
                exc[i] += innov[i];
@@ -824,7 +831,11 @@
                exc[i] += innov2[i];
          }
 
+#ifdef FIXED_POINT
          signal_mul(target, target, .5+ener, st->subframeSize);
+#else
+         signal_mul(target, target, ener, st->subframeSize);
+#endif
       }
 
       /*Keep the previous memory*/
@@ -1523,8 +1534,11 @@
          }
 
          /* De-normalize innovation and update excitation */
+#ifdef FIXED_POINT
          signal_mul(innov, innov, .5+ener, st->subframeSize);
-
+#else
+         signal_mul(innov, innov, ener, st->subframeSize);
+#endif
          /*Vocoder mode*/
          if (st->submodeID==1) 
          {

<p><p>1.145     +12 -3     speex/libspeex/sb_celp.c

Index: sb_celp.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/sb_celp.c,v
retrieving revision 1.144
retrieving revision 1.145
diff -u -r1.144 -r1.145
--- sb_celp.c	11 Nov 2003 04:33:38 -0000	1.144
+++ sb_celp.c	11 Nov 2003 07:33:03 -0000	1.145
@@ -618,9 +618,11 @@
          for (i=0;i<st->subframeSize;i++)
            exc[i]=0;
 
-
+#ifdef FIXED_POINT
+         signal_div(target, target, .5+scale, st->subframeSize);
+#else
          signal_div(target, target, scale, st->subframeSize);
-
+#endif
          /* Reset excitation */
          for (i=0;i<st->subframeSize;i++)
             innov[i]=0;
@@ -631,8 +633,11 @@
                                    innov, syn_resp, bits, stack, (st->complexity+1)>>1);
          /*print_vec(target, st->subframeSize, "after");*/
 
+#ifdef FIXED_POINT
+         signal_mul(innov, innov, .5+scale, st->subframeSize);
+#else
          signal_mul(innov, innov, scale, st->subframeSize);
-
+#endif
          for (i=0;i<st->subframeSize;i++)
             exc[i] += innov[i];
 
@@ -1043,7 +1048,11 @@
          SUBMODE(innovation_unquant)(exc, SUBMODE(innovation_params), st->subframeSize, 
                                 bits, stack);
 
+#ifdef FIXED_POINT
+         signal_mul(exc,exc,.5+scale,st->subframeSize);
+#else
          signal_mul(exc,exc,scale,st->subframeSize);
+#endif
 
          if (SUBMODE(double_codebook)) {
             char *tmp_stack=stack;

<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