[xiph-commits] r10636 - trunk/speex/libspeex
jm at svn.xiph.org
jm at svn.xiph.org
Sun Dec 18 05:13:30 PST 2005
Author: jm
Date: 2005-12-18 05:13:26 -0800 (Sun, 18 Dec 2005)
New Revision: 10636
Modified:
trunk/speex/libspeex/lsp.c
trunk/speex/libspeex/math_approx.c
trunk/speex/libspeex/math_approx.h
trunk/speex/libspeex/mdf.c
Log:
Moved spx_cos to math_approx.c and use it for initializing the mdf window.
Modified: trunk/speex/libspeex/lsp.c
===================================================================
--- trunk/speex/libspeex/lsp.c 2005-12-18 12:54:54 UTC (rev 10635)
+++ trunk/speex/libspeex/lsp.c 2005-12-18 13:13:26 UTC (rev 10636)
@@ -63,28 +63,8 @@
#ifdef FIXED_POINT
-#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_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 = 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))));*/
- }
-}
-
-
#define FREQ_SCALE 16384
/*#define ANGLE2X(a) (32768*cos(((a)/8192.)))*/
@@ -99,25 +79,6 @@
#define C2 -0.49558072
#define C3 0.03679168*/
-#define C1 0.9999932946f
-#define C2 -0.4999124376f
-#define C3 0.0414877472f
-#define C4 -0.0012712095f
-
-
-#define SPX_PI_2 1.5707963268
-static inline spx_word16_t spx_cos(spx_word16_t x)
-{
- if (x<SPX_PI_2)
- {
- x *= x;
- return C1 + x*(C2+x*(C3+C4*x));
- } else {
- x = M_PI-x;
- x *= x;
- return NEG16(C1 + x*(C2+x*(C3+C4*x)));
- }
-}
#define FREQ_SCALE 1.
#define ANGLE2X(a) (spx_cos(a))
#define X2ANGLE(x) (acos(x))
Modified: trunk/speex/libspeex/math_approx.c
===================================================================
--- trunk/speex/libspeex/math_approx.c 2005-12-18 12:54:54 UTC (rev 10635)
+++ trunk/speex/libspeex/math_approx.c 2005-12-18 13:13:26 UTC (rev 10636)
@@ -128,4 +128,48 @@
return ret;
}
+
+#define K1 8192
+#define K2 -4096
+#define K3 340
+#define K4 -10
+
+spx_word16_t spx_cos(spx_word16_t x)
+{
+ spx_word16_t x2;
+
+ if (x<12868)
+ {
+ x2 = MULT16_16_P13(x,x);
+ return ADD32(K1, MULT16_16_P13(x2, ADD32(K2, MULT16_16_P13(x2, ADD32(K3, MULT16_16_P13(K4, x2))))));
+ } else {
+ x = SUB16(25736,x);
+ x2 = MULT16_16_P13(x,x);
+ return SUB32(-K1, MULT16_16_P13(x2, ADD32(K2, MULT16_16_P13(x2, ADD32(K3, MULT16_16_P13(K4, x2))))));
+ }
+}
+
+#else
+
+#define C1 0.9999932946f
+#define C2 -0.4999124376f
+#define C3 0.0414877472f
+#define C4 -0.0012712095f
+
+
+#define SPX_PI_2 1.5707963268
+inline spx_word16_t spx_cos(spx_word16_t x)
+{
+ if (x<SPX_PI_2)
+ {
+ x *= x;
+ return C1 + x*(C2+x*(C3+C4*x));
+ } else {
+ x = M_PI-x;
+ x *= x;
+ return NEG16(C1 + x*(C2+x*(C3+C4*x)));
+ }
+}
+
+
#endif
Modified: trunk/speex/libspeex/math_approx.h
===================================================================
--- trunk/speex/libspeex/math_approx.h 2005-12-18 12:54:54 UTC (rev 10635)
+++ trunk/speex/libspeex/math_approx.h 2005-12-18 13:13:26 UTC (rev 10636)
@@ -37,6 +37,8 @@
#include "misc.h"
+spx_word16_t spx_cos(spx_word16_t x);
+
#ifdef FIXED_POINT
spx_word16_t spx_sqrt(spx_word32_t x);
spx_word16_t spx_acos(spx_word16_t x);
Modified: trunk/speex/libspeex/mdf.c
===================================================================
--- trunk/speex/libspeex/mdf.c 2005-12-18 12:54:54 UTC (rev 10635)
+++ trunk/speex/libspeex/mdf.c 2005-12-18 13:13:26 UTC (rev 10636)
@@ -45,6 +45,7 @@
#include "smallft.h"
#include "fftwrap.h"
#include "pseudofloat.h"
+#include "math_approx.h"
#ifndef M_PI
#define M_PI 3.14159265358979323846
@@ -239,8 +240,11 @@
st->power_1 = (spx_float_t*)speex_alloc((frame_size+1)*sizeof(spx_float_t));
st->window = (spx_word16_t*)speex_alloc(N*sizeof(spx_word16_t));
#ifdef FIXED_POINT
- for (i=0;i<N;i++)
- st->window[i] = 32767.*(.5-.5*cos(2*M_PI*i/N));
+ for (i=0;i<N>>1;i++)
+ {
+ st->window[i] = (16383-SHL16(spx_cos(DIV32_16(MULT16_16(25736,i<<1),N)),1));
+ st->window[N-i-1] = st->window[i];
+ }
#else
for (i=0;i<N;i++)
st->window[i] = .5-.5*cos(2*M_PI*i/N);
More information about the commits
mailing list