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

Jean-Marc Valin jm at xiph.org
Sat Nov 1 09:42:23 PST 2003



jm          03/11/01 12:42:22

  Modified:    libspeex lsp.c quant_lsp.c
  Log:
  fixed-point: cos approximation for lsp_to_lpc, removed some float ops
  in LSP quantization (more to do).

Revision  Changes    Path
1.34      +24 -2     speex/libspeex/lsp.c

Index: lsp.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/lsp.c,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -r1.33 -r1.34
--- lsp.c	9 Oct 2003 03:54:37 -0000	1.33
+++ lsp.c	1 Nov 2003 17:42:22 -0000	1.34
@@ -57,11 +57,33 @@
 #endif
 
 #ifdef FIXED_POINT
-#define ANGLE2X(a) (cos((a)/LSP_SCALING))
+
+#define C1 8187
+#define C2 -4058
+#define C3 301
+static spx_word16_t cos_32(spx_word16_t x)
+{
+   spx_word16_t x2;
+
+   if (x<12868)
+   {
+      x2 = MULT16_16_Q13(x,x);
+      return C1 + MULT16_16_Q13(x2, C2 + MULT16_16_Q13(C3, x2));
+   } else {
+      x = 25736-x;
+      x2 = MULT16_16_Q13(x,x);
+      return -C1 - MULT16_16_Q13(x2, C2 + MULT16_16_Q13(C3, x2));
+   }
+}
+
+#define ANGLE2X(a) (SHL(cos_32(a),2))
 #define X2ANGLE(x) (acos(x)*LSP_SCALING)
+
 #else
+
 #define ANGLE2X(a) (cos(a))
 #define X2ANGLE(x) (acos(x))
+
 #endif
 
 
@@ -344,7 +366,7 @@
     
     freqn = PUSH(stack, lpcrdr, spx_word16_t);
     for (i=0;i<lpcrdr;i++)
-       freqn[i] = ANGLE2X(freq[i])*32768.;
+       freqn[i] = ANGLE2X(freq[i]);
 
     Wp = PUSH(stack, 4*m+2, spx_word32_t);
     pw = Wp;

<p><p>1.28      +7 -8      speex/libspeex/quant_lsp.c

Index: quant_lsp.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/quant_lsp.c,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -r1.27 -r1.28
--- quant_lsp.c	9 Oct 2003 06:51:03 -0000	1.27
+++ quant_lsp.c	1 Nov 2003 17:42:22 -0000	1.28
@@ -38,11 +38,10 @@
 /* FIXME: Get rid of this kludge quick before someone gets hurt */
 
 #ifdef FIXED_POINT
-#define LSP_SCALE (8192./LSP_SCALING)
-#define LSP_OVERSCALE (32./LSP_SCALING)
+#define LSP_LINEAR(i) (SHL(i+1,11))
 #else
-#define LSP_SCALE 256
-#define LSP_OVERSCALE 1
+#define LSP_LINEAR(i) (.25*(i)+.25)
+#define LSP_SCALE 256.
 #endif
 
 static void compute_quant_weights(spx_lsp_t *qlsp, spx_word16_t *quant_weight, int order)
@@ -138,7 +137,7 @@
    compute_quant_weights(qlsp, quant_weight, order);
 
    for (i=0;i<order;i++)
-      qlsp[i]-=LSP_SCALING*(.25*i+.25);
+      qlsp[i]-=LSP_LINEAR(i);
 
 #ifndef FIXED_POINT
    for (i=0;i<order;i++)
@@ -184,7 +183,7 @@
 {
    int i, id;
    for (i=0;i<order;i++)
-      lsp[i]=LSP_SCALING*(.25*i+.25);
+      lsp[i]=LSP_LINEAR(i);
 
 
    id=speex_bits_unpack_unsigned(bits, 6);
@@ -221,7 +220,7 @@
    compute_quant_weights(qlsp, quant_weight, order);
 
    for (i=0;i<order;i++)
-      qlsp[i]-=LSP_SCALING*(.25*i+.25);
+      qlsp[i]-=LSP_LINEAR(i);
 #ifndef FIXED_POINT
    for (i=0;i<order;i++)
       qlsp[i]=qlsp[i]*LSP_SCALE;
@@ -254,7 +253,7 @@
 {
    int i, id;
    for (i=0;i<order;i++)
-      lsp[i]=LSP_SCALING*(.25*i+.25);
+      lsp[i]=LSP_LINEAR(i);
 
 
    id=speex_bits_unpack_unsigned(bits, 6);

<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