diff options
Diffstat (limited to 'apps/codecs/libwma/wmafixed.h')
-rw-r--r-- | apps/codecs/libwma/wmafixed.h | 92 |
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 | |||
25 | fixed64 IntTo64(int x); | ||
26 | int IntFrom64(fixed64 x); | ||
27 | fixed32 Fixed32From64(fixed64 x); | ||
28 | fixed64 Fixed32To64(fixed32 x); | ||
29 | fixed64 fixmul64byfixed(fixed64 x, fixed32 y); | ||
30 | fixed32 fixdiv32(fixed32 x, fixed32 y); | ||
31 | fixed64 fixdiv64(fixed64 x, fixed64 y); | ||
32 | fixed32 fixsqrt32(fixed32 x); | ||
33 | fixed32 fixsin32(fixed32 x); | ||
34 | fixed32 fixcos32(fixed32 x); | ||
35 | long 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 | ||
89 | fixed32 fixmul32(fixed32 x, fixed32 y); | ||
90 | fixed32 fixmul32b(fixed32 x, fixed32 y); | ||
91 | #endif | ||
92 | |||