summaryrefslogtreecommitdiff
path: root/apps/plugins/lib
diff options
context:
space:
mode:
authorRobert Keevil <rkeevil+rockbox@gmail.com>2007-07-31 17:23:49 +0000
committerRobert Keevil <rkeevil+rockbox@gmail.com>2007-07-31 17:23:49 +0000
commit98e607390673a2e81eed132724d83f430a0ea66e (patch)
tree1a9ec519c852f7614e416d44161c755ee1fbc115 /apps/plugins/lib
parentaea433c3e30a7ab2f836bd516b0104a236612bbf (diff)
downloadrockbox-98e607390673a2e81eed132724d83f430a0ea66e.zip
rockbox-98e607390673a2e81eed132724d83f430a0ea66e.tar.gz
rockbox-98e607390673a2e81eed132724d83f430a0ea66e.tar.bz2
rockbox-98e607390673a2e81eed132724d83f430a0ea66e.tar.xz
vu_meter: Use the fixedpoint lib (moving flog there)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@14103 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/lib')
-rw-r--r--apps/plugins/lib/fixedpoint.c30
-rw-r--r--apps/plugins/lib/fixedpoint.h1
2 files changed, 31 insertions, 0 deletions
diff --git a/apps/plugins/lib/fixedpoint.c b/apps/plugins/lib/fixedpoint.c
index cf69d9c..88c2f6e 100644
--- a/apps/plugins/lib/fixedpoint.c
+++ b/apps/plugins/lib/fixedpoint.c
@@ -202,3 +202,33 @@ long cos_int(int val)
}
return 0;
}
+
+/**
+ * Fixed-point natural log
+ * taken from http://www.quinapalus.com/efunc.html
+ * "The code assumes integers are at least 32 bits long. The (positive)
+ * argument and the result of the function are both expressed as fixed-point
+ * values with 16 fractional bits, although intermediates are kept with 28
+ * bits of precision to avoid loss of accuracy during shifts."
+ */
+
+long flog(int x) {
+ long t,y;
+
+ y=0xa65af;
+ if(x<0x00008000) x<<=16, y-=0xb1721;
+ if(x<0x00800000) x<<= 8, y-=0x58b91;
+ if(x<0x08000000) x<<= 4, y-=0x2c5c8;
+ if(x<0x20000000) x<<= 2, y-=0x162e4;
+ if(x<0x40000000) x<<= 1, y-=0x0b172;
+ t=x+(x>>1); if((t&0x80000000)==0) x=t,y-=0x067cd;
+ t=x+(x>>2); if((t&0x80000000)==0) x=t,y-=0x03920;
+ t=x+(x>>3); if((t&0x80000000)==0) x=t,y-=0x01e27;
+ t=x+(x>>4); if((t&0x80000000)==0) x=t,y-=0x00f85;
+ t=x+(x>>5); if((t&0x80000000)==0) x=t,y-=0x007e1;
+ t=x+(x>>6); if((t&0x80000000)==0) x=t,y-=0x003f8;
+ t=x+(x>>7); if((t&0x80000000)==0) x=t,y-=0x001fe;
+ x=0x80000000-x;
+ y-=x>>15;
+ return y;
+}
diff --git a/apps/plugins/lib/fixedpoint.h b/apps/plugins/lib/fixedpoint.h
index c587989..7199157 100644
--- a/apps/plugins/lib/fixedpoint.h
+++ b/apps/plugins/lib/fixedpoint.h
@@ -23,3 +23,4 @@ long fsincos(unsigned long phase, long *cos);
long fsqrt(long a, unsigned int fracbits);
long cos_int(int val);
long sin_int(int val);
+long flog(int x);