summaryrefslogtreecommitdiff
path: root/apps/codecs/libspeex/pseudofloat.h
diff options
context:
space:
mode:
authorDan Everton <dan@iocaine.org>2007-02-10 11:44:26 +0000
committerDan Everton <dan@iocaine.org>2007-02-10 11:44:26 +0000
commit7bf62e8da66ca8ff0acc2702f92ea4fe06eb94b1 (patch)
treec9db4558a73ae3094839c4655fa0b8ebc2231c56 /apps/codecs/libspeex/pseudofloat.h
parent51587512635a8b19e6a5f19a20074d0d4d1f17da (diff)
downloadrockbox-7bf62e8da66ca8ff0acc2702f92ea4fe06eb94b1.zip
rockbox-7bf62e8da66ca8ff0acc2702f92ea4fe06eb94b1.tar.gz
rockbox-7bf62e8da66ca8ff0acc2702f92ea4fe06eb94b1.tar.bz2
rockbox-7bf62e8da66ca8ff0acc2702f92ea4fe06eb94b1.tar.xz
* Sync Speex codec with Speex SVN revision 12449 (roughly Speex 1.2beta1).
* Redo the changes required to make Speex compile in Rockbox. Should be a bit easier to keep in sync with Speex SVN now. * Fix name of Speex library in codecs Makefile. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@12254 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/codecs/libspeex/pseudofloat.h')
-rw-r--r--apps/codecs/libspeex/pseudofloat.h105
1 files changed, 42 insertions, 63 deletions
diff --git a/apps/codecs/libspeex/pseudofloat.h b/apps/codecs/libspeex/pseudofloat.h
index 1608df7..67f01b3 100644
--- a/apps/codecs/libspeex/pseudofloat.h
+++ b/apps/codecs/libspeex/pseudofloat.h
@@ -37,7 +37,7 @@
#include "misc.h"
#include "math_approx.h"
-//#include <math.h>
+#include <math.h>
#ifdef FIXED_POINT
@@ -50,9 +50,7 @@ static const spx_float_t FLOAT_ZERO = {0,0};
static const spx_float_t FLOAT_ONE = {16384,-14};
static const spx_float_t FLOAT_HALF = {16384,-15};
-#ifndef MIN
#define MIN(a,b) ((a)<(b)?(a):(b))
-#endif
static inline spx_float_t PSEUDOFLOAT(spx_int32_t x)
{
int e=0;
@@ -67,18 +65,8 @@ static inline spx_float_t PSEUDOFLOAT(spx_int32_t x)
spx_float_t r = {0,0};
return r;
}
- while (x>32767)
- {
- x >>= 1;
- /*x *= .5;*/
- e++;
- }
- while (x<16383)
- {
- x <<= 1;
- /*x *= 2;*/
- e--;
- }
+ e = spx_ilog2(ABS32(x))-14;
+ x = VSHR32(x, e);
if (sign)
{
spx_float_t r;
@@ -207,6 +195,14 @@ static inline spx_float_t FLOAT_MULT(spx_float_t a, spx_float_t b)
return r;
}
+static inline spx_float_t FLOAT_AMULT(spx_float_t a, spx_float_t b)
+{
+ spx_float_t r;
+ r.m = (spx_int16_t)((spx_int32_t)(a).m*(b).m>>15);
+ r.e = (a).e+(b).e+15;
+ return r;
+}
+
static inline spx_float_t FLOAT_SHL(spx_float_t a, int b)
{
@@ -232,64 +228,40 @@ static inline spx_int32_t FLOAT_EXTRACT32(spx_float_t a)
return EXTEND32(a.m)<<a.e;
}
-
static inline spx_int32_t FLOAT_MUL32(spx_float_t a, spx_word32_t b)
{
- if (a.e<-15)
- return SHR32(MULT16_32_Q15(a.m, b),-a.e-15);
- else
- return SHL32(MULT16_32_Q15(a.m, b),15+a.e);
+ return VSHR32(MULT16_32_Q15(a.m, b),-a.e-15);
}
static inline spx_float_t FLOAT_MUL32U(spx_word32_t a, spx_word32_t b)
{
- int e=0;
+ int e1, e2;
spx_float_t r;
- /* FIXME: Handle the sign */
- if (a==0)
+ if (a==0 || b==0)
{
return FLOAT_ZERO;
}
- while (a>32767)
- {
- a >>= 1;
- e++;
- }
- while (a<16384)
- {
- a <<= 1;
- e--;
- }
- while (b>32767)
- {
- b >>= 1;
- e++;
- }
- while (b<16384)
- {
- b <<= 1;
- e--;
- }
+ e1 = spx_ilog2(ABS32(a));
+ a = VSHR32(a, e1-14);
+ e2 = spx_ilog2(ABS32(b));
+ b = VSHR32(b, e2-14);
r.m = MULT16_16_Q15(a,b);
- r.e = e+15;
+ r.e = e1+e2-13;
return r;
}
+/* Do NOT attempt to divide by a negative number */
static inline spx_float_t FLOAT_DIV32_FLOAT(spx_word32_t a, spx_float_t b)
{
int e=0;
spx_float_t r;
- /* FIXME: Handle the sign */
if (a==0)
{
return FLOAT_ZERO;
}
- while (a<SHL32(EXTEND32(b.m),14))
- {
- a <<= 1;
- e--;
- }
- while (a>=SHL32(EXTEND32(b.m-1),15))
+ e = spx_ilog2(ABS32(a))-spx_ilog2(b.m-1)-15;
+ a = VSHR32(a, e);
+ if (ABS32(a)>=SHL32(EXTEND32(b.m-1),15))
{
a >>= 1;
e++;
@@ -300,41 +272,47 @@ static inline spx_float_t FLOAT_DIV32_FLOAT(spx_word32_t a, spx_float_t b)
}
+/* Do NOT attempt to divide by a negative number */
static inline spx_float_t FLOAT_DIV32(spx_word32_t a, spx_word32_t b)
{
- int e=0;
+ int e0=0,e=0;
spx_float_t r;
- /* FIXME: Handle the sign */
if (a==0)
{
return FLOAT_ZERO;
}
- while (b>32767)
+ if (b>32767)
{
- b >>= 1;
- e--;
+ e0 = spx_ilog2(b)-14;
+ b = VSHR32(b, e0);
+ e0 = -e0;
}
- while (a<SHL32(b,14))
- {
- a <<= 1;
- e--;
- }
- while (a>=SHL32(b-1,15))
+ e = spx_ilog2(ABS32(a))-spx_ilog2(b-1)-15;
+ a = VSHR32(a, e);
+ if (ABS32(a)>=SHL32(EXTEND32(b-1),15))
{
a >>= 1;
e++;
}
+ e += e0;
r.m = DIV32_16(a,b);
r.e = e;
return r;
}
+/* Do NOT attempt to divide by a negative number */
static inline spx_float_t FLOAT_DIVU(spx_float_t a, spx_float_t b)
{
int e=0;
spx_int32_t num;
spx_float_t r;
+ if (b.m<=0)
+ {
+ speex_warning_int("Attempted to divide by", b.m);
+ return FLOAT_ONE;
+ }
num = a.m;
+ a.m = ABS16(a.m);
while (a.m >= b.m)
{
e++;
@@ -350,7 +328,7 @@ static inline spx_float_t FLOAT_SQRT(spx_float_t a)
{
spx_float_t r;
spx_int32_t m;
- m = a.m << 14;
+ m = SHL32(EXTEND32(a.m), 14);
r.e = a.e - 14;
if (r.e & 1)
{
@@ -370,6 +348,7 @@ static inline spx_float_t FLOAT_SQRT(spx_float_t a)
#define FLOAT_HALF 0.5f
#define PSEUDOFLOAT(x) (x)
#define FLOAT_MULT(a,b) ((a)*(b))
+#define FLOAT_AMULT(a,b) ((a)*(b))
#define FLOAT_MUL32(a,b) ((a)*(b))
#define FLOAT_DIV32(a,b) ((a)/(b))
#define FLOAT_EXTRACT16(a) (a)