Mercurial > mplayer.hg
annotate libfaad2/fixed.h @ 14291:f4b8d6abce22
Install libdha into LIBDIR.
author | reimar |
---|---|
date | Sat, 01 Jan 2005 14:45:11 +0000 |
parents | 6d50ef45a058 |
children | 2ae5ab4331ca |
rev | line source |
---|---|
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 ** | |
12625
d81145997036
More information about modifications to comply more closely with GPL 2a.
diego
parents:
12527
diff
changeset
|
25 ** Initially modified for use with MPlayer by Arpad Gereöffy on 2003/08/30 |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
26 ** $Id: fixed.h,v 1.4 2004/06/23 13:50:50 diego Exp $ |
12625
d81145997036
More information about modifications to comply more closely with GPL 2a.
diego
parents:
12527
diff
changeset
|
27 ** detailed CVS changelog at http://www.mplayerhq.hu/cgi-bin/cvsweb.cgi/main/ |
10725 | 28 **/ |
29 | |
30 #ifndef __FIXED_H__ | |
31 #define __FIXED_H__ | |
32 | |
33 #ifdef __cplusplus | |
34 extern "C" { | |
35 #endif | |
36 | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
37 #if defined(_WIN32_WCE) && defined(_ARM_) |
12527 | 38 #include <cmnintrin.h> |
39 #endif | |
10725 | 40 |
41 #define COEF_BITS 28 | |
42 #define COEF_PRECISION (1 << COEF_BITS) | |
10989 | 43 #define REAL_BITS 14 // MAXIMUM OF 14 FOR FIXED POINT SBR |
10725 | 44 #define REAL_PRECISION (1 << REAL_BITS) |
45 | |
12527 | 46 /* FRAC is the fractional only part of the fixed point number [0.0..1.0) */ |
47 #define FRAC_SIZE 32 /* frac is a 32 bit integer */ | |
48 #define FRAC_BITS 31 | |
49 #define FRAC_PRECISION ((uint32_t)(1 << FRAC_BITS)) | |
50 #define FRAC_MAX 0x7FFFFFFF | |
10725 | 51 |
52 typedef int32_t real_t; | |
53 | |
54 | |
12527 | 55 #define REAL_CONST(A) (((A) >= 0) ? ((real_t)((A)*(REAL_PRECISION)+0.5)) : ((real_t)((A)*(REAL_PRECISION)-0.5))) |
56 #define COEF_CONST(A) (((A) >= 0) ? ((real_t)((A)*(COEF_PRECISION)+0.5)) : ((real_t)((A)*(COEF_PRECISION)-0.5))) | |
57 #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)))) | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
58 //#define FRAC_CONST(A) (((A) >= 0) ? ((real_t)((A)*(FRAC_PRECISION)+0.5)) : ((real_t)((A)*(FRAC_PRECISION)-0.5))) |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
59 |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
60 #define Q2_BITS 22 |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
61 #define Q2_PRECISION (1 << Q2_BITS) |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
62 #define Q2_CONST(A) (((A) >= 0) ? ((real_t)((A)*(Q2_PRECISION)+0.5)) : ((real_t)((A)*(Q2_PRECISION)-0.5))) |
10725 | 63 |
64 #if defined(_WIN32) && !defined(_WIN32_WCE) | |
65 | |
12527 | 66 /* multiply with real shift */ |
67 static INLINE real_t MUL_R(real_t A, real_t B) | |
10725 | 68 { |
69 _asm { | |
70 mov eax,A | |
71 imul B | |
72 shrd eax,edx,REAL_BITS | |
73 } | |
74 } | |
75 | |
12527 | 76 /* multiply with coef shift */ |
77 static INLINE real_t MUL_C(real_t A, real_t B) | |
10725 | 78 { |
79 _asm { | |
80 mov eax,A | |
81 imul B | |
82 shrd eax,edx,COEF_BITS | |
83 } | |
84 } | |
85 | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
86 static INLINE real_t MUL_Q2(real_t A, real_t B) |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
87 { |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
88 _asm { |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
89 mov eax,A |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
90 imul B |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
91 shrd eax,edx,Q2_BITS |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
92 } |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
93 } |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
94 |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
95 static INLINE real_t MUL_SHIFT6(real_t A, real_t B) |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
96 { |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
97 _asm { |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
98 mov eax,A |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
99 imul B |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
100 shrd eax,edx,6 |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
101 } |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
102 } |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
103 |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
104 static INLINE real_t MUL_SHIFT23(real_t A, real_t B) |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
105 { |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
106 _asm { |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
107 mov eax,A |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
108 imul B |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
109 shrd eax,edx,23 |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
110 } |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
111 } |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
112 |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
113 #if 1 |
12527 | 114 static INLINE real_t _MulHigh(real_t A, real_t B) |
10725 | 115 { |
116 _asm { | |
117 mov eax,A | |
118 imul B | |
12527 | 119 mov eax,edx |
10725 | 120 } |
121 } | |
122 | |
12527 | 123 /* multiply with fractional shift */ |
124 static INLINE real_t MUL_F(real_t A, real_t B) | |
125 { | |
126 return _MulHigh(A,B) << (FRAC_SIZE-FRAC_BITS); | |
127 } | |
128 | |
129 /* Complex multiplication */ | |
130 static INLINE void ComplexMult(real_t *y1, real_t *y2, | |
131 real_t x1, real_t x2, real_t c1, real_t c2) | |
132 { | |
133 *y1 = (_MulHigh(x1, c1) + _MulHigh(x2, c2))<<(FRAC_SIZE-FRAC_BITS); | |
134 *y2 = (_MulHigh(x2, c1) - _MulHigh(x1, c2))<<(FRAC_SIZE-FRAC_BITS); | |
135 } | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
136 #else |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
137 static INLINE real_t MUL_F(real_t A, real_t B) |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
138 { |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
139 _asm { |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
140 mov eax,A |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
141 imul B |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
142 shrd eax,edx,FRAC_BITS |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
143 } |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
144 } |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
145 |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
146 /* Complex multiplication */ |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
147 static INLINE void ComplexMult(real_t *y1, real_t *y2, |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
148 real_t x1, real_t x2, real_t c1, real_t c2) |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
149 { |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
150 *y1 = MUL_F(x1, c1) + MUL_F(x2, c2); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
151 *y2 = MUL_F(x2, c1) - MUL_F(x1, c2); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
152 } |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
153 #endif |
12527 | 154 |
10725 | 155 #elif defined(__GNUC__) && defined (__arm__) |
156 | |
157 /* taken from MAD */ | |
158 #define arm_mul(x, y, SCALEBITS) \ | |
12527 | 159 ({ \ |
160 uint32_t __hi; \ | |
161 uint32_t __lo; \ | |
162 uint32_t __result; \ | |
163 asm("smull %0, %1, %3, %4\n\t" \ | |
164 "movs %0, %0, lsr %5\n\t" \ | |
165 "adc %2, %0, %1, lsl %6" \ | |
166 : "=&r" (__lo), "=&r" (__hi), "=r" (__result) \ | |
167 : "%r" (x), "r" (y), \ | |
168 "M" (SCALEBITS), "M" (32 - (SCALEBITS)) \ | |
169 : "cc"); \ | |
170 __result; \ | |
171 }) | |
10725 | 172 |
12527 | 173 static INLINE real_t MUL_R(real_t A, real_t B) |
10725 | 174 { |
12527 | 175 return arm_mul(A, B, REAL_BITS); |
176 } | |
177 | |
178 static INLINE real_t MUL_C(real_t A, real_t B) | |
179 { | |
180 return arm_mul(A, B, COEF_BITS); | |
10725 | 181 } |
182 | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
183 static INLINE real_t MUL_Q2(real_t A, real_t B) |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
184 { |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
185 return arm_mul(A, B, Q2_BITS); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
186 } |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
187 |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
188 static INLINE real_t MUL_SHIFT6(real_t A, real_t B) |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
189 { |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
190 return arm_mul(A, B, 6); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
191 } |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
192 |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
193 static INLINE real_t MUL_SHIFT23(real_t A, real_t B) |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
194 { |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
195 return arm_mul(A, B, 23); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
196 } |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
197 |
12527 | 198 static INLINE real_t _MulHigh(real_t x, real_t y) |
10725 | 199 { |
12527 | 200 uint32_t __lo; |
201 uint32_t __hi; | |
202 asm("smull\t%0, %1, %2, %3" | |
203 : "=&r"(__lo),"=&r"(__hi) | |
204 : "%r"(x),"r"(y) | |
205 : "cc"); | |
206 return __hi; | |
207 } | |
208 | |
209 static INLINE real_t MUL_F(real_t A, real_t B) | |
210 { | |
211 return _MulHigh(A, B) << (FRAC_SIZE-FRAC_BITS); | |
10725 | 212 } |
213 | |
12527 | 214 /* Complex multiplication */ |
215 static INLINE void ComplexMult(real_t *y1, real_t *y2, | |
216 real_t x1, real_t x2, real_t c1, real_t c2) | |
10725 | 217 { |
12527 | 218 int32_t tmp, yt1, yt2; |
219 asm("smull %0, %1, %4, %6\n\t" | |
220 "smlal %0, %1, %5, %7\n\t" | |
221 "rsb %3, %4, #0\n\t" | |
222 "smull %0, %2, %5, %6\n\t" | |
223 "smlal %0, %2, %3, %7" | |
224 : "=&r" (tmp), "=&r" (yt1), "=&r" (yt2), "=r" (x1) | |
225 : "3" (x1), "r" (x2), "r" (c1), "r" (c2) | |
226 : "cc" ); | |
227 *y1 = yt1 << (FRAC_SIZE-FRAC_BITS); | |
228 *y2 = yt2 << (FRAC_SIZE-FRAC_BITS); | |
10725 | 229 } |
230 | |
231 #else | |
232 | |
12527 | 233 /* multiply with real shift */ |
234 #define MUL_R(A,B) (real_t)(((int64_t)(A)*(int64_t)(B)+(1 << (REAL_BITS-1))) >> REAL_BITS) | |
235 /* multiply with coef shift */ | |
236 #define MUL_C(A,B) (real_t)(((int64_t)(A)*(int64_t)(B)+(1 << (COEF_BITS-1))) >> COEF_BITS) | |
237 /* multiply with fractional shift */ | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
238 #if defined(_WIN32_WCE) && defined(_ARM_) |
12527 | 239 /* eVC for PocketPC has an intrinsic function that returns only the high 32 bits of a 32x32 bit multiply */ |
240 static INLINE real_t MUL_F(real_t A, real_t B) | |
241 { | |
242 return _MulHigh(A,B) << (32-FRAC_BITS); | |
243 } | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
244 #else |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
245 #define _MulHigh(A,B) (real_t)(((int64_t)(A)*(int64_t)(B)+(1 << (FRAC_SIZE-1))) >> FRAC_SIZE) |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
246 #define MUL_F(A,B) (real_t)(((int64_t)(A)*(int64_t)(B)+(1 << (FRAC_BITS-1))) >> FRAC_BITS) |
12527 | 247 #endif |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
248 #define MUL_Q2(A,B) (real_t)(((int64_t)(A)*(int64_t)(B)+(1 << (Q2_BITS-1))) >> Q2_BITS) |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
249 #define MUL_SHIFT6(A,B) (real_t)(((int64_t)(A)*(int64_t)(B)+(1 << (6-1))) >> 6) |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
250 #define MUL_SHIFT23(A,B) (real_t)(((int64_t)(A)*(int64_t)(B)+(1 << (23-1))) >> 23) |
12527 | 251 |
252 /* Complex multiplication */ | |
253 static INLINE void ComplexMult(real_t *y1, real_t *y2, | |
254 real_t x1, real_t x2, real_t c1, real_t c2) | |
255 { | |
256 *y1 = (_MulHigh(x1, c1) + _MulHigh(x2, c2))<<(FRAC_SIZE-FRAC_BITS); | |
257 *y2 = (_MulHigh(x2, c1) - _MulHigh(x1, c2))<<(FRAC_SIZE-FRAC_BITS); | |
258 } | |
10725 | 259 |
260 #endif | |
261 | |
262 | |
12527 | 263 |
10725 | 264 #ifdef __cplusplus |
265 } | |
266 #endif | |
267 #endif |