summaryrefslogtreecommitdiff
path: root/apps/codecs/libwma/wmafixed.h
diff options
context:
space:
mode:
authorMichael Giacomelli <giac2000@hotmail.com>2007-07-04 17:15:09 +0000
committerMichael Giacomelli <giac2000@hotmail.com>2007-07-04 17:15:09 +0000
commita16d0f389e949881c9d12ecb7942c23d4a9dcc78 (patch)
tree2d85cc9febd443de3b6c155f764738371fb04da3 /apps/codecs/libwma/wmafixed.h
parent5717a0af87cff02e28ed74b4f7018fe51a817ac7 (diff)
downloadrockbox-a16d0f389e949881c9d12ecb7942c23d4a9dcc78.tar.gz
rockbox-a16d0f389e949881c9d12ecb7942c23d4a9dcc78.zip
Code clean up: Move fixed point functions into their own files. Move various lookup tables into header files.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@13784 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/codecs/libwma/wmafixed.h')
-rw-r--r--apps/codecs/libwma/wmafixed.h92
1 files changed, 92 insertions, 0 deletions
diff --git a/apps/codecs/libwma/wmafixed.h b/apps/codecs/libwma/wmafixed.h
new file mode 100644
index 0000000000..878601d799
--- /dev/null
+++ b/apps/codecs/libwma/wmafixed.h
@@ -0,0 +1,92 @@
1/* fixed precision code. We use a combination of Sign 15.16 and Sign.31
2 precision here.
3
4 The WMA decoder does not always follow this convention, and occasionally
5 renormalizes values to other formats in order to maximize precision.
6 However, only the two precisions above are provided in this file.
7
8*/
9
10
11#define PRECISION 16
12#define PRECISION64 16
13
14
15#define fixtof64(x) (float)((float)(x) / (float)(1 << PRECISION64)) //does not work on int64_t!
16#define ftofix32(x) ((fixed32)((x) * (float)(1 << PRECISION) + ((x) < 0 ? -0.5 : 0.5)))
17#define itofix64(x) (IntTo64(x))
18#define itofix32(x) ((x) << PRECISION)
19#define fixtoi32(x) ((x) >> PRECISION)
20#define fixtoi64(x) (IntFrom64(x))
21
22
23/*fixed functions*/
24
25fixed64 IntTo64(int x);
26int IntFrom64(fixed64 x);
27fixed32 Fixed32From64(fixed64 x);
28fixed64 Fixed32To64(fixed32 x);
29fixed64 fixmul64byfixed(fixed64 x, fixed32 y);
30fixed32 fixdiv32(fixed32 x, fixed32 y);
31fixed64 fixdiv64(fixed64 x, fixed64 y);
32fixed32 fixsqrt32(fixed32 x);
33fixed32 fixsin32(fixed32 x);
34fixed32 fixcos32(fixed32 x);
35long fsincos(unsigned long phase, fixed32 *cos);
36
37
38
39
40
41#ifdef CPU_ARM
42
43/*
44 Fixed precision multiply code ASM.
45
46*/
47
48/*Sign-15.16 format */
49
50#define fixmul32(x, y) \
51 ({ int32_t __hi; \
52 uint32_t __lo; \
53 int32_t __result; \
54 asm ("smull %0, %1, %3, %4\n\t" \
55 "movs %0, %0, lsr %5\n\t" \
56 "adc %2, %0, %1, lsl %6" \
57 : "=&r" (__lo), "=&r" (__hi), "=r" (__result) \
58 : "%r" (x), "r" (y), \
59 "M" (PRECISION), "M" (32 - PRECISION) \
60 : "cc"); \
61 __result; \
62 })
63
64/*
65 Special fixmul32 that does a 16.16 x 1.31 multiply that returns a 16.16 value.
66 this is needed because the fft constants are all normalized to be less then 1
67 and can't fit into a 16 bit number without excessive rounding
68
69
70*/
71
72
73# define fixmul32b(x, y) \
74 ({ int32_t __hi; \
75 uint32_t __lo; \
76 int32_t __result; \
77 asm ("smull %0, %1, %3, %4\n\t" \
78 "movs %0, %0, lsr %5\n\t" \
79 "adc %2, %0, %1, lsl %6" \
80 : "=&r" (__lo), "=&r" (__hi), "=r" (__result) \
81 : "%r" (x), "r" (y), \
82 "M" (31), "M" (1) \
83 : "cc"); \
84 __result; \
85 })
86
87
88#else
89fixed32 fixmul32(fixed32 x, fixed32 y);
90fixed32 fixmul32b(fixed32 x, fixed32 y);
91#endif
92