fix crossfade setting broken by r22192.
[kugel-rb.git] / apps / codecs / libatrac / fixp_math.c
blob3f578a1adea4165c4f5931637e42826d99045430
1 #include "fixp_math.h"
3 inline int32_t fixmul31(int32_t x, int32_t y)
5 int64_t temp;
6 temp = x;
7 temp *= y;
9 temp >>= 31; //16+31-16 = 31 bits
11 return (int32_t)temp;
15 * Fast integer square root adapted from algorithm,
16 * Martin Guy @ UKC, June 1985.
17 * Originally from a book on programming abaci by Mr C. Woo.
18 * This is taken from :
19 * http://wiki.forum.nokia.com/index.php/How_to_use_fixed_point_maths#How_to_get_square_root_for_integers
20 * with a added shift up of the result by 8 bits to return result in 16.16 fixed-point representation.
22 inline int32_t fastSqrt(int32_t n)
25 * Logically, these are unsigned.
26 * We need the sign bit to test
27 * whether (op - res - one) underflowed.
29 int32_t op, res, one;
30 op = n;
31 res = 0;
32 /* "one" starts at the highest power of four <= than the argument. */
33 one = 1 << 30; /* second-to-top bit set */
34 while (one > op) one >>= 2;
35 while (one != 0)
37 if (op >= res + one)
39 op = op - (res + one);
40 res = res + (one<<1);
42 res >>= 1;
43 one >>= 2;
45 return(res << 8);
48 inline int32_t fixmul16(int32_t x, int32_t y)
50 int64_t temp;
51 temp = x;
52 temp *= y;
54 temp >>= 16;
56 return (int32_t)temp;
59 inline int32_t fixdiv16(int32_t x, int32_t y)
61 int64_t temp;
62 temp = x << 16;
63 temp /= y;
65 return (int32_t)temp;