summaryrefslogtreecommitdiff
path: root/apps/codecs
diff options
context:
space:
mode:
Diffstat (limited to 'apps/codecs')
-rw-r--r--apps/codecs/libatrac/SOURCES1
-rw-r--r--apps/codecs/libatrac/fixp_math.c66
-rw-r--r--apps/codecs/libatrac/fixp_math.h69
3 files changed, 65 insertions, 71 deletions
diff --git a/apps/codecs/libatrac/SOURCES b/apps/codecs/libatrac/SOURCES
index 76e0385186..972f9621fc 100644
--- a/apps/codecs/libatrac/SOURCES
+++ b/apps/codecs/libatrac/SOURCES
@@ -1,3 +1,2 @@
1atrac3.c 1atrac3.c
2fixp_math.c
3../lib/ffmpeg_bitstream.c 2../lib/ffmpeg_bitstream.c
diff --git a/apps/codecs/libatrac/fixp_math.c b/apps/codecs/libatrac/fixp_math.c
deleted file mode 100644
index 3f578a1ade..0000000000
--- a/apps/codecs/libatrac/fixp_math.c
+++ /dev/null
@@ -1,66 +0,0 @@
1#include "fixp_math.h"
2
3inline int32_t fixmul31(int32_t x, int32_t y)
4{
5 int64_t temp;
6 temp = x;
7 temp *= y;
8
9 temp >>= 31; //16+31-16 = 31 bits
10
11 return (int32_t)temp;
12}
13
14/*
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.
21 */
22inline int32_t fastSqrt(int32_t n)
23{
24 /*
25 * Logically, these are unsigned.
26 * We need the sign bit to test
27 * whether (op - res - one) underflowed.
28 */
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)
36 {
37 if (op >= res + one)
38 {
39 op = op - (res + one);
40 res = res + (one<<1);
41 }
42 res >>= 1;
43 one >>= 2;
44 }
45 return(res << 8);
46}
47
48inline int32_t fixmul16(int32_t x, int32_t y)
49{
50 int64_t temp;
51 temp = x;
52 temp *= y;
53
54 temp >>= 16;
55
56 return (int32_t)temp;
57}
58
59inline int32_t fixdiv16(int32_t x, int32_t y)
60{
61 int64_t temp;
62 temp = x << 16;
63 temp /= y;
64
65 return (int32_t)temp;
66}
diff --git a/apps/codecs/libatrac/fixp_math.h b/apps/codecs/libatrac/fixp_math.h
index b6621b6f1a..8a734f6b68 100644
--- a/apps/codecs/libatrac/fixp_math.h
+++ b/apps/codecs/libatrac/fixp_math.h
@@ -9,7 +9,68 @@
9#define fix31tof64(x) (float)((float)(x) / (float)(1 << 31)) 9#define fix31tof64(x) (float)((float)(x) / (float)(1 << 31))
10 10
11/* Fixed point math routines for use in atrac3.c */ 11/* Fixed point math routines for use in atrac3.c */
12inline int32_t fixmul16(int32_t x, int32_t y); 12
13inline int32_t fixmul31(int32_t x, int32_t y); 13static inline int32_t fixmul16(int32_t x, int32_t y)
14inline int32_t fixdiv16(int32_t x, int32_t y); 14{
15inline int32_t fastSqrt(int32_t n); 15 int64_t temp;
16 temp = x;
17 temp *= y;
18
19 temp >>= 16;
20
21 return (int32_t)temp;
22}
23
24static inline int32_t fixmul31(int32_t x, int32_t y)
25{
26 int64_t temp;
27 temp = x;
28 temp *= y;
29
30 temp >>= 31; //16+31-16 = 31 bits
31
32 return (int32_t)temp;
33}
34
35static inline int32_t fixdiv16(int32_t x, int32_t y)
36{
37 int64_t temp;
38 temp = x << 16;
39 temp /= y;
40
41 return (int32_t)temp;
42}
43
44/*
45 * Fast integer square root adapted from algorithm,
46 * Martin Guy @ UKC, June 1985.
47 * Originally from a book on programming abaci by Mr C. Woo.
48 * This is taken from :
49 * http://wiki.forum.nokia.com/index.php/How_to_use_fixed_point_maths#How_to_get_square_root_for_integers
50 * with a added shift up of the result by 8 bits to return result in 16.16 fixed-point representation.
51 */
52static inline int32_t fastSqrt(int32_t n)
53{
54 /*
55 * Logically, these are unsigned.
56 * We need the sign bit to test
57 * whether (op - res - one) underflowed.
58 */
59 int32_t op, res, one;
60 op = n;
61 res = 0;
62 /* "one" starts at the highest power of four <= than the argument. */
63 one = 1 << 30; /* second-to-top bit set */
64 while (one > op) one >>= 2;
65 while (one != 0)
66 {
67 if (op >= res + one)
68 {
69 op = op - (res + one);
70 res = res + (one<<1);
71 }
72 res >>= 1;
73 one >>= 2;
74 }
75 return(res << 8);
76}