Fix red by moving fsincos back to libwma
[kugel-rb.git] / apps / codecs / libwma / wmafixed.h
blobd07acb3c6c2d2a3cac9008193d325a97b89d9585
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 long fsincos(unsigned long phase, fixed32 *cos);
56 #ifdef CPU_ARM
58 /*Sign-15.16 format */
59 #define fixmul32(x, y) \
60 ({ int32_t __hi; \
61 uint32_t __lo; \
62 int32_t __result; \
63 asm ("smull %0, %1, %3, %4\n\t" \
64 "movs %0, %0, lsr %5\n\t" \
65 "adc %2, %0, %1, lsl %6" \
66 : "=&r" (__lo), "=&r" (__hi), "=r" (__result) \
67 : "%r" (x), "r" (y), \
68 "M" (PRECISION), "M" (32 - PRECISION) \
69 : "cc"); \
70 __result; \
73 #elif defined(CPU_COLDFIRE)
75 static inline int32_t fixmul32(int32_t x, int32_t y)
77 #if PRECISION != 16
78 #warning Coldfire fixmul32() only works for PRECISION == 16
79 #endif
80 int32_t t1;
81 asm (
82 "mac.l %[x], %[y], %%acc0 \n" // multiply
83 "mulu.l %[y], %[x] \n" // get lower half, avoid emac stall
84 "movclr.l %%acc0, %[t1] \n" // get higher half
85 "lsr.l #1, %[t1] \n"
86 "move.w %[t1], %[x] \n"
87 "swap %[x] \n"
88 : [t1] "=&d" (t1), [x] "+d" (x)
89 : [y] "d" (y)
91 return x;
94 #else
96 static inline fixed32 fixmul32(fixed32 x, fixed32 y)
98 fixed64 temp;
99 temp = x;
100 temp *= y;
102 temp >>= PRECISION;
104 return (fixed32)temp;
107 #endif
110 /* Inverse gain of circular cordic rotation in s0.31 format. */
111 long fsincos(unsigned long phase, fixed32 *cos);