10725
|
1 /*
|
|
2 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
|
12527
|
3 ** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
|
10725
|
4 **
|
|
5 ** This program is free software; you can redistribute it and/or modify
|
|
6 ** it under the terms of the GNU General Public License as published by
|
|
7 ** the Free Software Foundation; either version 2 of the License, or
|
|
8 ** (at your option) any later version.
|
|
9 **
|
|
10 ** This program is distributed in the hope that it will be useful,
|
|
11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13 ** GNU General Public License for more details.
|
|
14 **
|
|
15 ** You should have received a copy of the GNU General Public License
|
|
16 ** along with this program; if not, write to the Free Software
|
|
17 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
18 **
|
|
19 ** Any non-GPL usage of this software or parts of this software is strictly
|
|
20 ** forbidden.
|
|
21 **
|
|
22 ** Commercial non-GPL licensing of this software is possible.
|
|
23 ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
|
|
24 **
|
12527
|
25 ** $Id: fixed.h,v 1.2 2003/10/03 22:22:27 alex Exp $
|
10725
|
26 **/
|
|
27
|
|
28 #ifndef __FIXED_H__
|
|
29 #define __FIXED_H__
|
|
30
|
|
31 #ifdef __cplusplus
|
|
32 extern "C" {
|
|
33 #endif
|
|
34
|
12527
|
35 #ifdef _WIN32_WCE
|
|
36 #include <cmnintrin.h>
|
|
37 #endif
|
10725
|
38
|
|
39 #define COEF_BITS 28
|
|
40 #define COEF_PRECISION (1 << COEF_BITS)
|
10989
|
41 #define REAL_BITS 14 // MAXIMUM OF 14 FOR FIXED POINT SBR
|
10725
|
42 #define REAL_PRECISION (1 << REAL_BITS)
|
|
43
|
12527
|
44 /* FRAC is the fractional only part of the fixed point number [0.0..1.0) */
|
|
45 #define FRAC_SIZE 32 /* frac is a 32 bit integer */
|
|
46 #define FRAC_BITS 31
|
|
47 #define FRAC_PRECISION ((uint32_t)(1 << FRAC_BITS))
|
|
48 #define FRAC_MAX 0x7FFFFFFF
|
10725
|
49
|
|
50 typedef int32_t real_t;
|
|
51
|
|
52
|
12527
|
53 #define REAL_CONST(A) (((A) >= 0) ? ((real_t)((A)*(REAL_PRECISION)+0.5)) : ((real_t)((A)*(REAL_PRECISION)-0.5)))
|
|
54 #define COEF_CONST(A) (((A) >= 0) ? ((real_t)((A)*(COEF_PRECISION)+0.5)) : ((real_t)((A)*(COEF_PRECISION)-0.5)))
|
|
55 #define FRAC_CONST(A) (((A) == 1.00) ? ((real_t)FRAC_MAX) : (((A) >= 0) ? ((real_t)((A)*(FRAC_PRECISION)+0.5)) : ((real_t)((A)*(FRAC_PRECISION)-0.5))))
|
10725
|
56
|
|
57 #if defined(_WIN32) && !defined(_WIN32_WCE)
|
|
58
|
12527
|
59 /* multiply with real shift */
|
|
60 static INLINE real_t MUL_R(real_t A, real_t B)
|
10725
|
61 {
|
|
62 _asm {
|
|
63 mov eax,A
|
|
64 imul B
|
|
65 shrd eax,edx,REAL_BITS
|
|
66 }
|
|
67 }
|
|
68
|
12527
|
69 /* multiply with coef shift */
|
|
70 static INLINE real_t MUL_C(real_t A, real_t B)
|
10725
|
71 {
|
|
72 _asm {
|
|
73 mov eax,A
|
|
74 imul B
|
|
75 shrd eax,edx,COEF_BITS
|
|
76 }
|
|
77 }
|
|
78
|
12527
|
79 static INLINE real_t _MulHigh(real_t A, real_t B)
|
10725
|
80 {
|
|
81 _asm {
|
|
82 mov eax,A
|
|
83 imul B
|
12527
|
84 mov eax,edx
|
10725
|
85 }
|
|
86 }
|
|
87
|
12527
|
88 /* multiply with fractional shift */
|
|
89 static INLINE real_t MUL_F(real_t A, real_t B)
|
|
90 {
|
|
91 return _MulHigh(A,B) << (FRAC_SIZE-FRAC_BITS);
|
|
92 }
|
|
93
|
|
94 /* Complex multiplication */
|
|
95 static INLINE void ComplexMult(real_t *y1, real_t *y2,
|
|
96 real_t x1, real_t x2, real_t c1, real_t c2)
|
|
97 {
|
|
98 *y1 = (_MulHigh(x1, c1) + _MulHigh(x2, c2))<<(FRAC_SIZE-FRAC_BITS);
|
|
99 *y2 = (_MulHigh(x2, c1) - _MulHigh(x1, c2))<<(FRAC_SIZE-FRAC_BITS);
|
|
100 }
|
|
101
|
10725
|
102 #elif defined(__GNUC__) && defined (__arm__)
|
|
103
|
|
104 /* taken from MAD */
|
|
105 #define arm_mul(x, y, SCALEBITS) \
|
12527
|
106 ({ \
|
|
107 uint32_t __hi; \
|
|
108 uint32_t __lo; \
|
|
109 uint32_t __result; \
|
|
110 asm("smull %0, %1, %3, %4\n\t" \
|
|
111 "movs %0, %0, lsr %5\n\t" \
|
|
112 "adc %2, %0, %1, lsl %6" \
|
|
113 : "=&r" (__lo), "=&r" (__hi), "=r" (__result) \
|
|
114 : "%r" (x), "r" (y), \
|
|
115 "M" (SCALEBITS), "M" (32 - (SCALEBITS)) \
|
|
116 : "cc"); \
|
|
117 __result; \
|
|
118 })
|
10725
|
119
|
12527
|
120 static INLINE real_t MUL_R(real_t A, real_t B)
|
10725
|
121 {
|
12527
|
122 return arm_mul(A, B, REAL_BITS);
|
|
123 }
|
|
124
|
|
125 static INLINE real_t MUL_C(real_t A, real_t B)
|
|
126 {
|
|
127 return arm_mul(A, B, COEF_BITS);
|
10725
|
128 }
|
|
129
|
12527
|
130 static INLINE real_t _MulHigh(real_t x, real_t y)
|
10725
|
131 {
|
12527
|
132 uint32_t __lo;
|
|
133 uint32_t __hi;
|
|
134 asm("smull\t%0, %1, %2, %3"
|
|
135 : "=&r"(__lo),"=&r"(__hi)
|
|
136 : "%r"(x),"r"(y)
|
|
137 : "cc");
|
|
138 return __hi;
|
|
139 }
|
|
140
|
|
141 static INLINE real_t MUL_F(real_t A, real_t B)
|
|
142 {
|
|
143 return _MulHigh(A, B) << (FRAC_SIZE-FRAC_BITS);
|
10725
|
144 }
|
|
145
|
12527
|
146 /* Complex multiplication */
|
|
147 static INLINE void ComplexMult(real_t *y1, real_t *y2,
|
|
148 real_t x1, real_t x2, real_t c1, real_t c2)
|
10725
|
149 {
|
12527
|
150 int32_t tmp, yt1, yt2;
|
|
151 asm("smull %0, %1, %4, %6\n\t"
|
|
152 "smlal %0, %1, %5, %7\n\t"
|
|
153 "rsb %3, %4, #0\n\t"
|
|
154 "smull %0, %2, %5, %6\n\t"
|
|
155 "smlal %0, %2, %3, %7"
|
|
156 : "=&r" (tmp), "=&r" (yt1), "=&r" (yt2), "=r" (x1)
|
|
157 : "3" (x1), "r" (x2), "r" (c1), "r" (c2)
|
|
158 : "cc" );
|
|
159 *y1 = yt1 << (FRAC_SIZE-FRAC_BITS);
|
|
160 *y2 = yt2 << (FRAC_SIZE-FRAC_BITS);
|
10725
|
161 }
|
|
162
|
|
163 #else
|
|
164
|
12527
|
165 /* multiply with real shift */
|
|
166 #define MUL_R(A,B) (real_t)(((int64_t)(A)*(int64_t)(B)+(1 << (REAL_BITS-1))) >> REAL_BITS)
|
|
167 /* multiply with coef shift */
|
|
168 #define MUL_C(A,B) (real_t)(((int64_t)(A)*(int64_t)(B)+(1 << (COEF_BITS-1))) >> COEF_BITS)
|
|
169 /* multiply with fractional shift */
|
|
170 #ifndef _WIN32_WCE
|
|
171 #define _MulHigh(A,B) (real_t)(((int64_t)(A)*(int64_t)(B)+(1 << (FRAC_SIZE-1))) >> FRAC_SIZE)
|
|
172 #define MUL_F(A,B) (real_t)(((int64_t)(A)*(int64_t)(B)+(1 << (FRAC_BITS-1))) >> FRAC_BITS)
|
|
173 #else
|
|
174 /* eVC for PocketPC has an intrinsic function that returns only the high 32 bits of a 32x32 bit multiply */
|
|
175 static INLINE real_t MUL_F(real_t A, real_t B)
|
|
176 {
|
|
177 return _MulHigh(A,B) << (32-FRAC_BITS);
|
|
178 }
|
|
179 #endif
|
|
180
|
|
181 /* Complex multiplication */
|
|
182 static INLINE void ComplexMult(real_t *y1, real_t *y2,
|
|
183 real_t x1, real_t x2, real_t c1, real_t c2)
|
|
184 {
|
|
185 *y1 = (_MulHigh(x1, c1) + _MulHigh(x2, c2))<<(FRAC_SIZE-FRAC_BITS);
|
|
186 *y2 = (_MulHigh(x2, c1) - _MulHigh(x1, c2))<<(FRAC_SIZE-FRAC_BITS);
|
|
187 }
|
10725
|
188
|
|
189 #endif
|
|
190
|
|
191
|
12527
|
192
|
10725
|
193 #ifdef __cplusplus
|
|
194 }
|
|
195 #endif
|
|
196 #endif
|