[xiph-commits] r9165 - trunk/speex/libspeex

jm at motherfish-iii.xiph.org jm at motherfish-iii.xiph.org
Thu Apr 21 23:23:31 PDT 2005


Author: jm
Date: 2005-04-21 23:23:27 -0700 (Thu, 21 Apr 2005)
New Revision: 9165

Modified:
   trunk/speex/libspeex/arch.h
   trunk/speex/libspeex/cb_search.c
   trunk/speex/libspeex/filters.c
   trunk/speex/libspeex/fixed_arm4.h
   trunk/speex/libspeex/fixed_arm5e.h
   trunk/speex/libspeex/fixed_debug.h
   trunk/speex/libspeex/fixed_generic.h
   trunk/speex/libspeex/lpc.c
   trunk/speex/libspeex/lsp.c
   trunk/speex/libspeex/nb_celp.c
   trunk/speex/libspeex/sb_celp.c
Log:
Added some more fixed-point operators


Modified: trunk/speex/libspeex/arch.h
===================================================================
--- trunk/speex/libspeex/arch.h	2005-04-22 04:40:52 UTC (rev 9164)
+++ trunk/speex/libspeex/arch.h	2005-04-22 06:23:27 UTC (rev 9165)
@@ -102,6 +102,19 @@
 
 #define VERY_SMALL 1e-30
 
+#define NEG16(x) (-(x))
+#define NEG32(x) (-(x))
+#define EXTRACT16(x) (x)
+#define EXTEND32(x) (x)
+#define SHR16(a,shift) (a)
+#define SHL16(a,shift) (a)
+#define SHR32(a,shift) (a)
+#define SHL32(a,shift) (a)
+#define PSHR16(a,shift) (a)
+#define PSHR32(a,shift) (a)
+#define SATURATE16(x,a) (x)
+#define SATURATE32(x,a) (x)
+
 #define PSHR(a,shift)       (a)
 #define SHR(a,shift)       (a)
 #define SHL(a,shift)       (a)
@@ -130,6 +143,7 @@
 #define MULT16_16_Q13(a,b)     ((a)*(b))
 #define MULT16_16_Q14(a,b)     ((a)*(b))
 #define MULT16_16_Q15(a,b)     ((a)*(b))
+#define MULT16_16_P15(a,b)     ((a)*(b))
 
 #define DIV32_16(a,b)     ((a)/(b))
 #define DIV32(a,b)     ((a)/(b))

Modified: trunk/speex/libspeex/cb_search.c
===================================================================
--- trunk/speex/libspeex/cb_search.c	2005-04-22 04:40:52 UTC (rev 9164)
+++ trunk/speex/libspeex/cb_search.c	2005-04-22 06:23:27 UTC (rev 9165)
@@ -177,10 +177,10 @@
          if (sign)
          {
             for (j=0;j<subvect_size;j++)
-               e[subvect_size*i+j]=SHL((spx_word32_t)shape_cb[rind*subvect_size+j],SIG_SHIFT-5);
+               e[subvect_size*i+j]=SHL(EXTEND32(shape_cb[rind*subvect_size+j]),SIG_SHIFT-5);
          } else {
             for (j=0;j<subvect_size;j++)
-               e[subvect_size*i+j]=-SHL((spx_word32_t)shape_cb[rind*subvect_size+j],SIG_SHIFT-5);
+               e[subvect_size*i+j]=NEG32(SHL(EXTEND32(shape_cb[rind*subvect_size+j]),SIG_SHIFT-5));
          }
 #else
          for (j=0;j<subvect_size;j++)
@@ -500,10 +500,10 @@
       if (sign==1)
       {
          for (j=0;j<subvect_size;j++)
-            e[subvect_size*i+j]=SHL((spx_word32_t)shape_cb[rind*subvect_size+j],SIG_SHIFT-5);
+            e[subvect_size*i+j]=SHL(EXTEND32(shape_cb[rind*subvect_size+j]),SIG_SHIFT-5);
       } else {
          for (j=0;j<subvect_size;j++)
-            e[subvect_size*i+j]=-SHL((spx_word32_t)shape_cb[rind*subvect_size+j],SIG_SHIFT-5);
+            e[subvect_size*i+j]=NEG32(SHL(EXTEND32(shape_cb[rind*subvect_size+j]),SIG_SHIFT-5));
       }
 #else
       for (j=0;j<subvect_size;j++)
@@ -572,7 +572,7 @@
             exc[subvect_size*i+j]=SHL((spx_word32_t)shape_cb[ind[i]*subvect_size+j],SIG_SHIFT-5);
       } else {
          for (j=0;j<subvect_size;j++)
-            exc[subvect_size*i+j]=-SHL((spx_word32_t)shape_cb[ind[i]*subvect_size+j],SIG_SHIFT-5);
+            exc[subvect_size*i+j]=NEG32(SHL(EXTEND32(shape_cb[ind[i]*subvect_size+j]),SIG_SHIFT-5));
       }
 #else
       for (j=0;j<subvect_size;j++)

Modified: trunk/speex/libspeex/filters.c
===================================================================
--- trunk/speex/libspeex/filters.c	2005-04-22 04:40:52 UTC (rev 9164)
+++ trunk/speex/libspeex/filters.c	2005-04-22 06:23:27 UTC (rev 9165)
@@ -41,7 +41,6 @@
 #include "ltp.h"
 #include <math.h>
 
-#ifdef FIXED_POINT
 void bw_lpc(spx_word16_t gamma, const spx_coef_t *lpc_in, spx_coef_t *lpc_out, int order)
 {
    int i;
@@ -53,21 +52,8 @@
       tmp = MULT16_16_P15(tmp, gamma);
    }
 }
-#else
-void bw_lpc(spx_word16_t gamma, const spx_coef_t *lpc_in, spx_coef_t *lpc_out, int order)
-{
-   int i;
-   float tmp=1;
-   for (i=0;i<order+1;i++)
-   {
-      lpc_out[i] = tmp * lpc_in[i];
-      tmp *= gamma;
-   }
-}
 
-#endif
 
-
 #ifdef FIXED_POINT
 
 /* FIXME: These functions are ugly and probably introduce too much error */
@@ -202,15 +188,15 @@
 
    for (i=0;i<N;i++)
    {
-      xi=PSHR(SATURATE(x[i],536870911),SIG_SHIFT);
-      yi = PSHR(SATURATE(ADD32(x[i], SHL(mem[0],1)),536870911),SIG_SHIFT);
-      nyi = -yi;
+      xi= EXTRACT16(PSHR32(SATURATE(x[i],536870911),SIG_SHIFT));
+      yi = EXTRACT16(PSHR32(SATURATE(ADD32(x[i], SHL32(mem[0],1)),536870911),SIG_SHIFT));
+      nyi = NEG16(yi);
       for (j=0;j<ord-1;j++)
       {
          mem[j] = MAC16_16(MAC16_16(mem[j+1], num[j+1],xi), den[j+1],nyi);
       }
       mem[ord-1] = ADD32(MULT16_16(num[ord],xi), MULT16_16(den[ord],nyi));
-      y[i] = SHL(yi,SIG_SHIFT);
+      y[i] = SHL32(EXTEND32(yi),SIG_SHIFT);
    }
 }
 #else
@@ -222,8 +208,8 @@
    for (i=0;i<N;i++)
    {
       xi=SATURATE(x[i],805306368);
-      yi = SATURATE(ADD32(xi, SHL(mem[0],2)),805306368);
-      nyi = -yi;
+      yi = SATURATE(ADD32(xi, SHL32(mem[0],2)),805306368);
+      nyi = NEG32(yi);
       for (j=0;j<ord-1;j++)
       {
          mem[j] = MAC16_32_Q15(MAC16_32_Q15(mem[j+1], num[j+1],xi), den[j+1],nyi);
@@ -242,15 +228,15 @@
 
    for (i=0;i<N;i++)
    {
-      xi=PSHR(SATURATE(x[i],536870911),SIG_SHIFT);
-      yi = PSHR(SATURATE(x[i] + (mem[0]<<1),536870911),SIG_SHIFT);
-      nyi = -yi;
+      xi=EXTRACT16(PSHR32(SATURATE(x[i],536870911),SIG_SHIFT));
+      yi = EXTRACT16(PSHR32(SATURATE(x[i] + SHL32(mem[0],1),536870911),SIG_SHIFT));
+      nyi = NEG16(yi);
       for (j=0;j<ord-1;j++)
       {
          mem[j] = MAC16_16(mem[j+1],den[j+1],nyi);
       }
       mem[ord-1] = MULT16_16(den[ord],nyi);
-      y[i] = SHL(yi,SIG_SHIFT);
+      y[i] = SHL32(EXTEND32(yi),SIG_SHIFT);
    }
 }
 #else
@@ -262,13 +248,13 @@
    for (i=0;i<N;i++)
    {
       xi=SATURATE(x[i],805306368);
-      yi = SATURATE(xi + (mem[0]<<2),805306368);
-      nyi = -yi;
+      yi = SATURATE(xi + SHL32(mem[0],2),805306368);
+      nyi = NEG32(yi);
       for (j=0;j<ord-1;j++)
       {
          mem[j] = MAC16_32_Q15(mem[j+1],den[j+1],nyi);
       }
-      mem[ord-1] = - MULT16_32_Q15(den[ord],yi);
+      mem[ord-1] = MULT16_32_Q15(den[ord],nyi);
       y[i] = yi;
    }
 }
@@ -285,14 +271,14 @@
 
    for (i=0;i<N;i++)
    {
-      xi= PSHR(SATURATE(x[i],536870911),SIG_SHIFT);
-      yi = PSHR(SATURATE(x[i] + (mem[0]<<1),536870911),SIG_SHIFT);
+      xi= EXTRACT16(PSHR32(SATURATE(x[i],536870911),SIG_SHIFT));
+      yi = EXTRACT16(PSHR32(SATURATE(x[i] + SHL32(mem[0],1),536870911),SIG_SHIFT));
       for (j=0;j<ord-1;j++)
       {
          mem[j] = MAC16_16(mem[j+1], num[j+1],xi);
       }
       mem[ord-1] = MULT16_16(num[ord],xi);
-      y[i] = SHL(yi,SIG_SHIFT);
+      y[i] = SHL32(EXTEND32(yi),SIG_SHIFT);
    }
 }
 #else
@@ -304,7 +290,7 @@
    for (i=0;i<N;i++)
    {
       xi=SATURATE(x[i],805306368);
-      yi = xi + (mem[0]<<2);
+      yi = xi + SHL32(mem[0],2);
       for (j=0;j<ord-1;j++)
       {
          mem[j] = MAC16_32_Q15(mem[j+1], num[j+1],xi);
@@ -433,9 +419,9 @@
    for (i=0;i<N;i++)
    {
       y1 = ADD16(y[i], PSHR(mem1[0],LPC_SHIFT));
-      ny1i = -y1;
+      ny1i = NEG16(y1);
       y[i] = ADD16(SHL(y1,1), PSHR(mem2[0],LPC_SHIFT));
-      ny2i = -y[i];
+      ny2i = NEG16(y[i]);
       for (j=0;j<ord-1;j++)
       {
          mem1[j] = MAC16_16(mem1[j+1], awk2[j+1],ny1i);

Modified: trunk/speex/libspeex/fixed_arm4.h
===================================================================
--- trunk/speex/libspeex/fixed_arm4.h	2005-04-22 04:40:52 UTC (rev 9164)
+++ trunk/speex/libspeex/fixed_arm4.h	2005-04-22 06:23:27 UTC (rev 9165)
@@ -35,10 +35,23 @@
 #ifndef FIXED_ARM4_H
 #define FIXED_ARM4_H
 
+#define NEG16(x) (-(x))
+#define NEG32(x) (-(x))
+#define EXTRACT16(x) ((spx_word16_t)x)
+#define EXTEND32(x) ((spx_word32_t)x)
+#define SHR16(a,shift) ((a) >> (shift))
+#define SHL16(a,shift) ((a) << (shift))
+#define SHR32(a,shift) ((a) >> (shift))
+#define SHL32(a,shift) ((a) << (shift))
+#define PSHR16(a,shift) (SHR16((a)+(1<<((shift)-1)),shift))
+#define PSHR32(a,shift) (SHR32((a)+(1<<((shift)-1)),shift))
+#define SATURATE16(x,a) (((x)>(a) ? (a) : (x)<-(a) ? -(a) : (x)))
+#define SATURATE32(x,a) (((x)>(a) ? (a) : (x)<-(a) ? -(a) : (x)))
+
 #define SHR(a,shift) ((a) >> (shift))
 #define SHL(a,shift) ((a) << (shift))
-
 #define SATURATE(x,a) ((x)>(a) ? (a) : (x)<-(a) ? -(a) : (x))
+#define PSHR(a,shift) (SHR((a)+(1<<((shift)-1)),shift))
 
 #define ADD16(a,b) ((a)+(b))
 #define SUB16(a,b) ((a)-(b))
@@ -46,7 +59,6 @@
 #define SUB32(a,b) ((a)-(b))
 #define ADD64(a,b) ((a)+(b))
 
-#define PSHR(a,shift) (SHR((a)+(1<<((shift)-1)),shift))
 
 /* result fits in 16 bits */
 #define MULT16_16_16(a,b)     ((a)*(b))

Modified: trunk/speex/libspeex/fixed_arm5e.h
===================================================================
--- trunk/speex/libspeex/fixed_arm5e.h	2005-04-22 04:40:52 UTC (rev 9164)
+++ trunk/speex/libspeex/fixed_arm5e.h	2005-04-22 06:23:27 UTC (rev 9165)
@@ -35,10 +35,23 @@
 #ifndef FIXED_ARM5E_H
 #define FIXED_ARM5E_H
 
+#define NEG16(x) (-(x))
+#define NEG32(x) (-(x))
+#define EXTRACT16(x) ((spx_word16_t)x)
+#define EXTEND32(x) ((spx_word32_t)x)
+#define SHR16(a,shift) ((a) >> (shift))
+#define SHL16(a,shift) ((a) << (shift))
+#define SHR32(a,shift) ((a) >> (shift))
+#define SHL32(a,shift) ((a) << (shift))
+#define PSHR16(a,shift) (SHR16((a)+(1<<((shift)-1)),shift))
+#define PSHR32(a,shift) (SHR32((a)+(1<<((shift)-1)),shift))
+#define SATURATE16(x,a) (((x)>(a) ? (a) : (x)<-(a) ? -(a) : (x)))
+#define SATURATE32(x,a) (((x)>(a) ? (a) : (x)<-(a) ? -(a) : (x)))
+
 #define SHR(a,shift) ((a) >> (shift))
 #define SHL(a,shift) ((a) << (shift))
-
 #define SATURATE(x,a) ((x)>(a) ? (a) : (x)<-(a) ? -(a) : (x))
+#define PSHR(a,shift) (SHR((a)+(1<<((shift)-1)),shift))
 
 
 #define ADD16(a,b) ((short)((short)(a)+(short)(b)))
@@ -47,7 +60,6 @@
 #define SUB32(a,b) ((a)-(b))
 #define ADD64(a,b) ((a)+(b))
 
-#define PSHR(a,shift) (SHR((a)+(1<<((shift)-1)),shift))
 
 /* result fits in 16 bits */
 #define MULT16_16_16(a,b)     (((short)(a))*((short)(b)))

Modified: trunk/speex/libspeex/fixed_debug.h
===================================================================
--- trunk/speex/libspeex/fixed_debug.h	2005-04-22 04:40:52 UTC (rev 9164)
+++ trunk/speex/libspeex/fixed_debug.h	2005-04-22 06:23:27 UTC (rev 9165)
@@ -43,6 +43,117 @@
 #define VERIFY_SHORT(x) ((x)<=32767&&(x)>=-32768)
 #define VERIFY_INT(x) ((x)<=2147483647LL&&(x)>=-2147483648LL)
 
+static inline short NEG16(int x)
+{
+   int res;
+   if (!VERIFY_SHORT(x))
+   {
+      fprintf (stderr, "NEG16: input is not short: %d\n", x);
+   }
+   res = -x;
+   if (!VERIFY_SHORT(res))
+      fprintf (stderr, "NEG16: output is not short: %d\n", res);
+   spx_mips++;
+   return res;
+}
+static inline int NEG32(long long x)
+{
+   long long res;
+   if (!VERIFY_INT(x))
+   {
+      fprintf (stderr, "NEG16: input is not int: %d\n", x);
+   }
+   res = -x;
+   if (!VERIFY_INT(res))
+      fprintf (stderr, "NEG16: output is not int: %d\n", res);
+   spx_mips++;
+   return res;
+}
+
+static inline short EXTRACT16(int x)
+{
+   int res;
+   if (!VERIFY_SHORT(x))
+   {
+      fprintf (stderr, "EXTRACT16: input is not short: %d\n", x);
+   }
+   res = x;
+   spx_mips++;
+   return res;
+}
+
+static inline int EXTEND32(int x)
+{
+   int res;
+   if (!VERIFY_SHORT(x))
+   {
+      fprintf (stderr, "EXTRACT16: input is not short: %d\n", x);
+   }
+   res = x;
+   spx_mips++;
+   return res;
+}
+
+static inline short SHR16(int a, int shift) 
+{
+   int res;
+   if (!VERIFY_SHORT(a) || !VERIFY_SHORT(shift))
+   {
+      fprintf (stderr, "SHR16: inputs are not short: %d %d\n", a, shift);
+   }
+   res = a>>shift;
+   if (!VERIFY_SHORT(res))
+      fprintf (stderr, "SHR16: output is not short: %d\n", res);
+   spx_mips++;
+   return res;
+}
+static inline short SHL16(int a, int shift) 
+{
+   int res;
+   if (!VERIFY_SHORT(a) || !VERIFY_SHORT(shift))
+   {
+      fprintf (stderr, "SHR16: inputs are not short: %d %d\n", a, shift);
+   }
+   res = a<<shift;
+   if (!VERIFY_SHORT(res))
+      fprintf (stderr, "SHR16: output is not short: %d\n", res);
+   spx_mips++;
+   return res;
+}
+
+static inline int SHR32(long long a, int shift) 
+{
+   long long  res;
+   if (!VERIFY_INT(a) || !VERIFY_SHORT(shift))
+   {
+      fprintf (stderr, "SHR32: inputs are not int: %d %d\n", a, shift);
+   }
+   res = a>>shift;
+   if (!VERIFY_INT(res))
+      fprintf (stderr, "SHR32: output is not int: %d\n", res);
+   spx_mips++;
+   return res;
+}
+static inline int SHL32(long long a, int shift) 
+{
+   long long  res;
+   if (!VERIFY_INT(a) || !VERIFY_SHORT(shift))
+   {
+      fprintf (stderr, "SHR32: inputs are not int: %d %d\n", a, shift);
+   }
+   res = a<<shift;
+   if (!VERIFY_INT(res))
+      fprintf (stderr, "SHR32: output is not int: %d\n", res);
+   spx_mips++;
+   return res;
+}
+
+
+#define PSHR16(a,shift) (SHR16(ADD16(a,(1<<((shift)-1))),shift))
+#define PSHR32(a,shift) (SHR32(ADD32(a,(1<<((shift)-1))),shift))
+#define SATURATE16(x,a) (((x)>(a) ? (a) : (x)<-(a) ? -(a) : (x)))
+#define SATURATE32(x,a) (((x)>(a) ? (a) : (x)<-(a) ? -(a) : (x)))
+
 #define SHR(a,shift) ((a) >> (shift))
 #define SHL(a,shift) ((a) << (shift))
 
@@ -136,12 +247,12 @@
 #define MULT16_16B(a,b)     (((short)(a))*((short)(b)))
 
 #define MAC16_16(c,a,b)     (ADD32((c),MULT16_16((a),(b))))
-#define MAC16_16_Q11(c,a,b)     (ADD32((c),SHR(MULT16_16((a),(b)),11)))
-#define MAC16_16_Q13(c,a,b)     (ADD32((c),SHR(MULT16_16((a),(b)),13)))
+#define MAC16_16_Q11(c,a,b)     (ADD16((c),EXTRACT16(SHR32(MULT16_16((a),(b)),11))))
+#define MAC16_16_Q13(c,a,b)     (ADD16((c),EXTRACT16(SHR32(MULT16_16((a),(b)),13))))
 
-#define MULT16_32_Q12(a,b) ADD32(MULT16_16((a),SHR((b),12)), SHR(MULT16_16((a),((b)&0x00000fff)),12))
-#define MULT16_32_Q13(a,b) ADD32(MULT16_16((a),SHR((b),13)), SHR(MULT16_16((a),((b)&0x00001fff)),13))
-#define MULT16_32_Q14(a,b) ADD32(MULT16_16((a),SHR((b),14)), SHR(MULT16_16((a),((b)&0x00003fff)),14))
+#define MULT16_32_Q12(a,b) ADD32(MULT16_16((a),SHR32((b),12)), SHR32(MULT16_16((a),((b)&0x00000fff)),12))
+#define MULT16_32_Q13(a,b) ADD32(MULT16_16((a),SHR32((b),13)), SHR32(MULT16_16((a),((b)&0x00001fff)),13))
+#define MULT16_32_Q14(a,b) ADD32(MULT16_16((a),SHR32((b),14)), SHR32(MULT16_16((a),((b)&0x00003fff)),14))
 
 #define MULT16_32_Q11(a,b) ADD32(MULT16_16((a),SHR((b),11)), SHR(MULT16_16((a),((b)&0x000007ff)),11))
 #define MAC16_32_Q11(c,a,b) ADD32(c,ADD32(MULT16_16((a),SHR((b),11)), SHR(MULT16_16((a),((b)&0x000007ff)),11)))

Modified: trunk/speex/libspeex/fixed_generic.h
===================================================================
--- trunk/speex/libspeex/fixed_generic.h	2005-04-22 04:40:52 UTC (rev 9164)
+++ trunk/speex/libspeex/fixed_generic.h	2005-04-22 06:23:27 UTC (rev 9165)
@@ -35,9 +35,22 @@
 #ifndef FIXED_GENERIC_H
 #define FIXED_GENERIC_H
 
+#define NEG16(x) (-(x))
+#define NEG32(x) (-(x))
+#define EXTRACT16(x) ((spx_word16_t)x)
+#define EXTEND32(x) ((spx_word32_t)x)
+#define SHR16(a,shift) ((a) >> (shift))
+#define SHL16(a,shift) ((a) << (shift))
+#define SHR32(a,shift) ((a) >> (shift))
+#define SHL32(a,shift) ((a) << (shift))
+#define PSHR16(a,shift) (SHR16((a)+(1<<((shift)-1)),shift))
+#define PSHR32(a,shift) (SHR32((a)+(1<<((shift)-1)),shift))
+#define SATURATE16(x,a) (((x)>(a) ? (a) : (x)<-(a) ? -(a) : (x)))
+#define SATURATE32(x,a) (((x)>(a) ? (a) : (x)<-(a) ? -(a) : (x)))
+
 #define SHR(a,shift) ((a) >> (shift))
 #define SHL(a,shift) ((spx_word32_t)(a) << (shift))
-
+#define PSHR(a,shift) (SHR((a)+(1<<((shift)-1)),shift))
 #define SATURATE(x,a) (((x)>(a) ? (a) : (x)<-(a) ? -(a) : (x)))
 
 static inline spx_word32_t slow_saturate(spx_word32_t x, spx_word16_t a)
@@ -51,7 +64,6 @@
 #define SUB32(a,b) ((spx_word32_t)(a)-(spx_word32_t)(b))
 #define ADD64(a,b) ((spx_word64_t)(a)+(spx_word64_t)(b))
 
-#define PSHR(a,shift) (SHR((a)+(1<<((shift)-1)),shift))
 
 /* result fits in 16 bits */
 #define MULT16_16_16(a,b)     ((((spx_word16_t)(a))*((spx_word16_t)(b))))

Modified: trunk/speex/libspeex/lpc.c
===================================================================
--- trunk/speex/libspeex/lpc.c	2005-04-22 04:40:52 UTC (rev 9164)
+++ trunk/speex/libspeex/lpc.c	2005-04-22 06:23:27 UTC (rev 9165)
@@ -88,7 +88,7 @@
    for (i = 0; i < p; i++) {
 
       /* Sum up this iteration's reflection coefficient */
-      spx_word32_t rr = -SHL(ac[i + 1],13);
+      spx_word32_t rr = NEG32(SHL32(EXTEND32(ac[i + 1]),13));
       for (j = 0; j < i; j++) 
          rr = SUB32(rr,MULT16_16(lpc[j],ac[i - j]));
 #ifdef FIXED_POINT

Modified: trunk/speex/libspeex/lsp.c
===================================================================
--- trunk/speex/libspeex/lsp.c	2005-04-22 04:40:52 UTC (rev 9164)
+++ trunk/speex/libspeex/lsp.c	2005-04-22 06:23:27 UTC (rev 9165)
@@ -77,7 +77,7 @@
       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;
+      x = SUB16(25736,x);
       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))));*/
@@ -115,7 +115,7 @@
    } else {
       x = M_PI-x;
       x *= x;
-      return -(C1 + x*(C2+x*(C3+C4*x)));
+      return NEG16(C1 + x*(C2+x*(C3+C4*x)));
    }
 }
 #define FREQ_SCALE 1.
@@ -176,7 +176,7 @@
     /*x *= 2;*/
     for(i=2;i<=m2;i++)
     {
-       T[i] = MULT16_16_Q13(x,T[i-1]) - T[i-2];
+       T[i] = SUB16(MULT16_16_Q13(x,T[i-1]), T[i-2]);
        sum = ADD32(sum, MULT16_16_P14(coefn[m2-i],T[i]));
        /*printf ("%f ", sum);*/
     }
@@ -276,8 +276,8 @@
     *px++ = LPC_SCALING;
     *qx++ = LPC_SCALING;
     for(i=1;i<=m;i++){
-	*px++ = (a[i]+a[lpcrdr+1-i]) - *p++;
-	*qx++ = (a[i]-a[lpcrdr+1-i]) + *q++;
+       *px++ = SUB32(ADD32(EXTEND32(a[i]),EXTEND32(a[lpcrdr+1-i])), *p++);
+       *qx++ = ADD32(SUB32(EXTEND32(a[i]),EXTEND32(a[lpcrdr+1-i])), *q++);
     }
     px = P;
     qx = Q;
@@ -333,7 +333,7 @@
            spx_word16_t dd;
            /* Modified by JMV to provide smaller steps around x=+-1 */
 #ifdef FIXED_POINT
-           dd = MULT16_16_Q15(delta,(FREQ_SCALE - MULT16_16_Q14(MULT16_16_Q14(xl,xl),14000)));
+           dd = MULT16_16_Q15(delta,SUB16(FREQ_SCALE, MULT16_16_Q14(MULT16_16_Q14(xl,xl),14000)));
            if (psuml<512 && psuml>-512)
               dd = PSHR(dd,1);
 #else
@@ -341,7 +341,7 @@
            if (fabs(psuml)<.2)
               dd *= .5;
 #endif
-           xr = xl - dd;                        	/* interval spacing 	*/
+           xr = SUB16(xl, dd);                        	/* interval spacing 	*/
 	    psumr = cheb_poly_eva(pt,xr,lpcrdr,stack);/* poly(xl-delta_x) 	*/
 	    temp_psumr = psumr;
 	    temp_xr = xr;

Modified: trunk/speex/libspeex/nb_celp.c
===================================================================
--- trunk/speex/libspeex/nb_celp.c	2005-04-22 04:40:52 UTC (rev 9164)
+++ trunk/speex/libspeex/nb_celp.c	2005-04-22 06:23:27 UTC (rev 9165)
@@ -236,7 +236,7 @@
    /* Copy new data in input buffer */
    speex_move(st->inBuf, st->inBuf+st->frameSize, (st->windowSize-st->frameSize)*sizeof(spx_sig_t));
    for (i=0;i<st->frameSize;i++)
-      st->inBuf[st->windowSize-st->frameSize+i] = SHL((int)in[i], SIG_SHIFT);
+      st->inBuf[st->windowSize-st->frameSize+i] = SHL32(EXTEND32(in[i]), SIG_SHIFT);
 
    /* Move signals 1 frame towards the past */
    speex_move(st->excBuf, st->excBuf+st->frameSize, (st->max_pitch+1)*sizeof(spx_sig_t));
@@ -247,7 +247,7 @@
       ALLOC(w_sig, st->windowSize, spx_word16_t);
       /* Window for analysis */
       for (i=0;i<st->windowSize;i++)
-         w_sig[i] = SHR(MULT16_16(SHR((spx_word32_t)(st->frame[i]),SIG_SHIFT),st->window[i]),SIG_SHIFT);
+         w_sig[i] = EXTRACT16(SHR32(MULT16_16(EXTRACT16(SHR32(st->frame[i],SIG_SHIFT)),st->window[i]),SIG_SHIFT));
 
       /* Compute auto-correlation */
       _spx_autocorr(w_sig, st->autocorr, st->lpcSize+1, st->windowSize);
@@ -371,7 +371,7 @@
 
       } else {
 #endif
-         ol_gain = SHL((spx_word32_t)compute_rms(st->exc, st->frameSize),SIG_SHIFT);
+         ol_gain = SHL32(EXTEND32(compute_rms(st->exc, st->frameSize)),SIG_SHIFT);
 #ifdef EPIC_48K
       }
 #endif
@@ -690,11 +690,6 @@
       
       if (st->complexity==0)
          response_bound >>= 1;
-      /* Compute impulse response of A(z/g1) / ( A(z)*A(z/g2) )*/
-      /*for (i=0;i<st->subframeSize;i++)
-         exc[i]=VERY_SMALL;
-      exc[0]=SIG_SCALING;
-      syn_percep_zero(exc, st->interp_qlpc, st->bw_lpc1, st->bw_lpc2, syn_resp, response_bound, st->lpcSize, stack);*/
       compute_impulse_response(st->interp_qlpc, st->bw_lpc1, st->bw_lpc2, syn_resp, response_bound, st->lpcSize, stack);
       for (i=response_bound;i<st->subframeSize;i++)
          syn_resp[i]=VERY_SMALL;
@@ -803,7 +798,7 @@
          for (i=0;i<st->subframeSize;i++)
             real_exc[i] = SUB32(real_exc[i], exc[i]);
 
-         ener = SHL((spx_word32_t)compute_rms(real_exc, st->subframeSize),SIG_SHIFT);
+         ener = SHL32(EXTEND32(compute_rms(real_exc, st->subframeSize)),SIG_SHIFT);
          
          /*FIXME: Should use DIV32_16 and make sure result fits in 16 bits */
 #ifdef FIXED_POINT

Modified: trunk/speex/libspeex/sb_celp.c
===================================================================
--- trunk/speex/libspeex/sb_celp.c	2005-04-22 04:40:52 UTC (rev 9164)
+++ trunk/speex/libspeex/sb_celp.c	2005-04-22 06:23:27 UTC (rev 9165)
@@ -676,10 +676,6 @@
 
          scale = SHL(MULT16_16(DIV32_16(SHL(gc,SIG_SHIFT-4),filter_ratio),(1+el)),4);
 
-         /*for (i=0;i<st->subframeSize;i++)
-            exc[i]=VERY_SMALL;
-         exc[0]=SIG_SCALING;
-         syn_percep_zero(exc, st->interp_qlpc, st->bw_lpc1, st->bw_lpc2, syn_resp, st->subframeSize, st->lpcSize, stack);*/
          compute_impulse_response(st->interp_qlpc, st->bw_lpc1, st->bw_lpc2, syn_resp, st->subframeSize, st->lpcSize, stack);
 
          



More information about the commits mailing list