wmafixed.h: remove double declaration
[kugel-rb.git] / apps / codecs / libwma / wmafixed.h
blob7f04a955ef386c486935df05a4372e87209cc694
1 /****************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
9 * Copyright (C) 2007 Michael Giacomelli
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
17 * KIND, either express or implied.
19 ****************************************************************************/
21 /* fixed precision code. We use a combination of Sign 15.16 and Sign.31
22 precision here.
24 The WMA decoder does not always follow this convention, and occasionally
25 renormalizes values to other formats in order to maximize precision.
26 However, only the two precisions above are provided in this file.
30 #include "types.h"
32 #define PRECISION 16
33 #define PRECISION64 16
36 #define fixtof64(x) (float)((float)(x) / (float)(1 << PRECISION64)) //does not work on int64_t!
37 #define ftofix32(x) ((fixed32)((x) * (float)(1 << PRECISION) + ((x) < 0 ? -0.5 : 0.5)))
38 #define itofix64(x) (IntTo64(x))
39 #define itofix32(x) ((x) << PRECISION)
40 #define fixtoi32(x) ((x) >> PRECISION)
41 #define fixtoi64(x) (IntFrom64(x))
44 /*fixed functions*/
46 fixed64 IntTo64(int x);
47 int IntFrom64(fixed64 x);
48 fixed32 Fixed32From64(fixed64 x);
49 fixed64 Fixed32To64(fixed32 x);
50 fixed32 fixdiv32(fixed32 x, fixed32 y);
51 fixed64 fixdiv64(fixed64 x, fixed64 y);
52 fixed32 fixsqrt32(fixed32 x);
53 /* Inverse gain of circular cordic rotation in s0.31 format. */
54 long fsincos(unsigned long phase, fixed32 *cos);
57 #ifdef CPU_ARM
59 /*Sign-15.16 format */
60 #define fixmul32(x, y) \
61 ({ int32_t __hi; \
62 uint32_t __lo; \
63 int32_t __result; \
64 asm ("smull %0, %1, %3, %4\n\t" \
65 "movs %0, %0, lsr %5\n\t" \
66 "adc %2, %0, %1, lsl %6" \
67 : "=&r" (__lo), "=&r" (__hi), "=r" (__result) \
68 : "%r" (x), "r" (y), \
69 "M" (PRECISION), "M" (32 - PRECISION) \
70 : "cc"); \
71 __result; \
74 #elif defined(CPU_COLDFIRE)
76 static inline int32_t fixmul32(int32_t x, int32_t y)
78 #if PRECISION != 16
79 #warning Coldfire fixmul32() only works for PRECISION == 16
80 #endif
81 int32_t t1;
82 asm (
83 "mac.l %[x], %[y], %%acc0 \n" // multiply
84 "mulu.l %[y], %[x] \n" // get lower half, avoid emac stall
85 "movclr.l %%acc0, %[t1] \n" // get higher half
86 "lsr.l #1, %[t1] \n"
87 "move.w %[t1], %[x] \n"
88 "swap %[x] \n"
89 : [t1] "=&d" (t1), [x] "+d" (x)
90 : [y] "d" (y)
92 return x;
95 #else
97 static inline fixed32 fixmul32(fixed32 x, fixed32 y)
99 fixed64 temp;
100 temp = x;
101 temp *= y;
103 temp >>= PRECISION;
105 return (fixed32)temp;
108 #endif