New cos approximation for slow CPU's (don't use it on x86)
authorjm <jm@0101bb08-14d6-0310-b084-bc0e0c8e3800>
Wed, 30 Oct 2002 20:27:03 +0000 (20:27 +0000)
committerjm <jm@0101bb08-14d6-0310-b084-bc0e0c8e3800>
Wed, 30 Oct 2002 20:27:03 +0000 (20:27 +0000)
git-svn-id: http://svn.xiph.org/trunk/speex@4070 0101bb08-14d6-0310-b084-bc0e0c8e3800

libspeex/Makefile.am
libspeex/math_approx.c [new file with mode: 0644]
libspeex/math_approx.h [new file with mode: 0644]
libspeex/nb_celp.c

index 6f6f9e5..0e5ca72 100644 (file)
@@ -1,6 +1,6 @@
 ## Process this file with automake to produce Makefile.in. -*-Makefile-*-
 
-# $Id: Makefile.am,v 1.42 2002/10/27 06:01:30 jm Exp $
+# $Id: Makefile.am,v 1.43 2002/10/30 20:27:03 jm Exp $
 
 # Disable automatic dependency tracking if using other tools than gcc and gmake
 #AUTOMAKE_OPTIONS = no-dependencies
@@ -33,7 +33,8 @@ libspeex_la_SOURCES = nb_celp.c \
        hexc_10_32_table.c \
        misc.c \
        speex_header.c \
-       speex_callbacks.c
+       speex_callbacks.c \
+       math_approx.c
 
 
 include_HEADERS =  speex.h \
@@ -55,7 +56,8 @@ noinst_HEADERS = lsp.h \
        vbr.h \
        misc.h \
        ltp_sse.h \
-       filters_sse.h
+       filters_sse.h \
+       math_approx.c
        
        
 libspeex_la_LDFLAGS = -release $(LT_RELEASE)
diff --git a/libspeex/math_approx.c b/libspeex/math_approx.c
new file mode 100644 (file)
index 0000000..6959e4a
--- /dev/null
@@ -0,0 +1,99 @@
+/* Copyright (C) 2002 Jean-Marc Valin 
+   File: math_approx.c
+   Various math approximation functions for Speex
+
+   Redistribution and use in source and binary forms, with or without
+   modification, are permitted provided that the following conditions
+   are met:
+   
+   - Redistributions of source code must retain the above copyright
+   notice, this list of conditions and the following disclaimer.
+   
+   - Redistributions in binary form must reproduce the above copyright
+   notice, this list of conditions and the following disclaimer in the
+   documentation and/or other materials provided with the distribution.
+   
+   - Neither the name of the Xiph.org Foundation nor the names of its
+   contributors may be used to endorse or promote products derived from
+   this software without specific prior written permission.
+   
+   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+   ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+   A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR
+   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+   EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+   PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+   PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+   LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include <math.h>
+
+float cos_sin[202] = {
+   1.00000000, 0.00000000,
+   0.99804751, 0.06245932,
+   0.99219767, 0.12467473,
+   0.98247331, 0.18640330,
+   0.96891242, 0.24740396,
+   0.95156795, 0.30743851,
+   0.93050762, 0.36627253,
+   0.90581368, 0.42367626,
+   0.87758256, 0.47942554,
+   0.84592450, 0.53330267,
+   0.81096312, 0.58509727,
+   0.77283495, 0.63460708,
+   0.73168887, 0.68163876,
+   0.68768556, 0.72600866,
+   0.64099686, 0.76754350,
+   0.59180508, 0.80608111,
+   0.54030231, 0.84147098,
+   0.48668967, 0.87357494,
+   0.43117652, 0.90226759,
+   0.37397963, 0.92743692,
+   0.31532236, 0.94898462,
+   0.25543377, 0.96682656,
+   0.19454771, 0.98089306,
+   0.13290194, 0.99112919,
+   0.07073720, 0.99749499,
+   0.00829623, 0.99996559,
+   -0.05417714, 0.99853134,
+   -0.11643894, 0.99319785,
+   -0.17824606, 0.98398595,
+   -0.23935712, 0.97093160,
+   -0.29953351, 0.95408578,
+   -0.35854022, 0.93351428,
+   -0.41614684, 0.90929743,
+   -0.47212841, 0.88152979,
+   -0.52626633, 0.85031979,
+   -0.57834920, 0.81578931,
+   -0.62817362, 0.77807320,
+   -0.67554504, 0.73731872,
+   -0.72027847, 0.69368503,
+   -0.76219923, 0.64734252,
+   -0.80114362, 0.59847214,
+   -0.83695955, 0.54726475,
+   -0.86950718, 0.49392030,
+   -0.89865940, 0.43864710,
+   -0.92430238, 0.38166099,
+   -0.94633597, 0.32318451,
+   -0.96467415, 0.26344599,
+   -0.97924529, 0.20267873,
+   -0.98999250, 0.14112001,
+   -0.99687381, 0.07901022,
+   -0.99986235, 0.01659189
+};
+
+float speex_cos(float x)
+{
+   int ind;
+   float delta;
+   ind = (int)floor(x*16+.5);
+   delta = x-0.062500*ind;
+   ind <<= 1;
+   return cos_sin[ind] - delta*(cos_sin[ind+1] + 
+                                  .5*delta*(cos_sin[ind] - 
+                                            .3333333*delta*cos_sin[ind+1]));
+}
diff --git a/libspeex/math_approx.h b/libspeex/math_approx.h
new file mode 100644 (file)
index 0000000..87b7502
--- /dev/null
@@ -0,0 +1 @@
+float speex_cos(float x);
index da21645..1782f69 100644 (file)
 #include "misc.h"
 #include "speex_callbacks.h"
 
+#ifdef SLOW_TRIG
+#include "math_approx.h"
+#define cos speex_cos
+#endif
+
 extern int training_weight;
 #ifndef M_PI
 #define M_PI           3.14159265358979323846  /* pi */