Mercurial > mplayer.hg
annotate libfaad2/common.h @ 16848:279cd50f2ba0
Switch from our own to the upstream DVD key caching strategy and directory.
Should work just as well while reducing our diff towards upstream and
enhancing compatibility with external libdvdcss implementations.
author | diego |
---|---|
date | Mon, 24 Oct 2005 09:50:42 +0000 |
parents | ba7a79482bec |
children | 59b6fa5b4201 |
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 |
4 ** | |
10725 | 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. | |
12527 | 9 ** |
10725 | 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. | |
12527 | 14 ** |
10725 | 15 ** You should have received a copy of the GNU General Public License |
12527 | 16 ** along with this program; if not, write to the Free Software |
10725 | 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 |
10725 | 26 ** $Id$ |
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/ |
14731 | 28 ** local_changes.diff contains the exact changes to this file. |
10725 | 29 **/ |
30 | |
31 #ifndef __COMMON_H__ | |
32 #define __COMMON_H__ | |
33 | |
34 #ifdef __cplusplus | |
35 extern "C" { | |
36 #endif | |
37 | |
14729
b4378a6f87a6
Sync missing cosmetics from the 2004-07-12 CVS snapshot.
diego
parents:
13685
diff
changeset
|
38 /* Allow build on Cygwin*/ |
12527 | 39 #if defined(__CYGWIN__) |
40 #define __STRICT_ANSI__ | |
41 #endif | |
10725 | 42 |
13685 | 43 #include "../config.h" |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
44 |
10725 | 45 #define INLINE __inline |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
46 #if 0 //defined(_WIN32) && !defined(_WIN32_WCE) |
12527 | 47 #define ALIGN __declspec(align(16)) |
48 #else | |
49 #define ALIGN | |
50 #endif | |
10725 | 51 |
52 #ifndef max | |
53 #define max(a, b) (((a) > (b)) ? (a) : (b)) | |
54 #endif | |
55 #ifndef min | |
56 #define min(a, b) (((a) < (b)) ? (a) : (b)) | |
57 #endif | |
58 | |
59 /* COMPILE TIME DEFINITIONS */ | |
60 | |
61 /* use double precision */ | |
62 /* #define USE_DOUBLE_PRECISION */ | |
63 /* use fixed point reals */ | |
64 //#define FIXED_POINT | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
65 //#define BIG_IQ_TABLE |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
66 |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
67 /* Use if target platform has address generators with autoincrement */ |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
68 //#define PREFER_POINTERS |
10725 | 69 |
16230
ba7a79482bec
prefer FIXED_POINT for ARM - patch by AGAWA Koji <i at atty.sakura.ne.jp>
alex
parents:
15593
diff
changeset
|
70 #if defined(_WIN32_WCE) || defined(__arm__) |
12527 | 71 #define FIXED_POINT |
72 #endif | |
73 | |
74 | |
10725 | 75 #define ERROR_RESILIENCE |
76 | |
77 | |
78 /* Allow decoding of MAIN profile AAC */ | |
79 #define MAIN_DEC | |
80 /* Allow decoding of SSR profile AAC */ | |
81 //#define SSR_DEC | |
82 /* Allow decoding of LTP profile AAC */ | |
83 #define LTP_DEC | |
84 /* Allow decoding of LD profile AAC */ | |
85 #define LD_DEC | |
12527 | 86 /* Allow decoding of scalable profiles */ |
87 //#define SCALABLE_DEC | |
88 /* Allow decoding of Digital Radio Mondiale (DRM) */ | |
89 //#define DRM | |
90 //#define DRM_PS | |
10725 | 91 |
92 /* LD can't do without LTP */ | |
93 #ifdef LD_DEC | |
94 #ifndef ERROR_RESILIENCE | |
95 #define ERROR_RESILIENCE | |
96 #endif | |
97 #ifndef LTP_DEC | |
98 #define LTP_DEC | |
99 #endif | |
100 #endif | |
101 | |
12527 | 102 #define ALLOW_SMALL_FRAMELENGTH |
103 | |
104 | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
105 // Define LC_ONLY_DECODER if you want a pure AAC LC decoder (independant of SBR_DEC and PS_DEC) |
12527 | 106 //#define LC_ONLY_DECODER |
107 #ifdef LC_ONLY_DECODER | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
108 #undef LD_DEC |
12527 | 109 #undef LTP_DEC |
110 #undef MAIN_DEC | |
111 #undef SSR_DEC | |
112 #undef DRM | |
113 #undef ALLOW_SMALL_FRAMELENGTH | |
114 #undef ERROR_RESILIENCE | |
115 #endif | |
10725 | 116 |
117 #define SBR_DEC | |
118 //#define SBR_LOW_POWER | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
119 #define PS_DEC |
10725 | 120 |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
121 /* FIXED POINT: No MAIN decoding */ |
10725 | 122 #ifdef FIXED_POINT |
12527 | 123 # ifdef MAIN_DEC |
124 # undef MAIN_DEC | |
125 # endif | |
13485
93a84777a6b5
SBR code does NOT work with fixed point (uses floats, slow as hell)
rfelker
parents:
13453
diff
changeset
|
126 # ifdef SBR_DEC |
93a84777a6b5
SBR code does NOT work with fixed point (uses floats, slow as hell)
rfelker
parents:
13453
diff
changeset
|
127 # undef SBR_DEC |
93a84777a6b5
SBR code does NOT work with fixed point (uses floats, slow as hell)
rfelker
parents:
13453
diff
changeset
|
128 # endif |
12527 | 129 #endif // FIXED_POINT |
130 | |
131 #ifdef DRM | |
132 # ifndef SCALABLE_DEC | |
133 # define SCALABLE_DEC | |
134 # endif | |
135 #endif | |
136 | |
137 #if ((defined(_WIN32) && !defined(_WIN32_WCE)) /* || ((__GNUC__ >= 3) && defined(__i386__)) */ ) | |
138 #ifndef FIXED_POINT | |
139 /* includes <xmmintrin.h> to enable SSE intrinsics */ | |
140 //#define USE_SSE | |
10725 | 141 #endif |
142 #endif | |
143 | |
144 #ifdef FIXED_POINT | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
145 #define DIV_R(A, B) (((int64_t)A << REAL_BITS)/B) |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
146 #define DIV_C(A, B) (((int64_t)A << COEF_BITS)/B) |
10725 | 147 #else |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
148 #define DIV_R(A, B) ((A)/(B)) |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
149 #define DIV_C(A, B) ((A)/(B)) |
10725 | 150 #endif |
151 | |
152 #ifndef SBR_LOW_POWER | |
153 #define qmf_t complex_t | |
154 #define QMF_RE(A) RE(A) | |
155 #define QMF_IM(A) IM(A) | |
156 #else | |
157 #define qmf_t real_t | |
158 #define QMF_RE(A) (A) | |
12527 | 159 #define QMF_IM(A) |
10725 | 160 #endif |
161 | |
162 | |
163 /* END COMPILE TIME DEFINITIONS */ | |
164 | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
165 #if defined(_WIN32) && !defined(__MINGW32__) |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
166 |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
167 #include <stdlib.h> |
10725 | 168 |
10805
125a35fc47a5
fixed win32 compile problems and broken bigendian support
alex
parents:
10725
diff
changeset
|
169 #if 0 |
10725 | 170 typedef unsigned __int64 uint64_t; |
171 typedef unsigned __int32 uint32_t; | |
172 typedef unsigned __int16 uint16_t; | |
173 typedef unsigned __int8 uint8_t; | |
174 typedef __int64 int64_t; | |
175 typedef __int32 int32_t; | |
176 typedef __int16 int16_t; | |
177 typedef __int8 int8_t; | |
10805
125a35fc47a5
fixed win32 compile problems and broken bigendian support
alex
parents:
10725
diff
changeset
|
178 #else |
125a35fc47a5
fixed win32 compile problems and broken bigendian support
alex
parents:
10725
diff
changeset
|
179 #include <inttypes.h> |
125a35fc47a5
fixed win32 compile problems and broken bigendian support
alex
parents:
10725
diff
changeset
|
180 #endif |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
181 |
10725 | 182 typedef float float32_t; |
183 | |
184 | |
185 #else | |
186 | |
187 /* #undef HAVE_FLOAT32_T */ | |
188 /* Define if you have the <inttypes.h> header file. */ | |
189 #define HAVE_INTTYPES_H 1 | |
190 | |
191 /* Define if you have the `memcpy' function. */ | |
192 #define HAVE_MEMCPY 1 | |
193 | |
194 /* Define if you have the <stdint.h> header file. */ | |
195 #define HAVE_STDINT_H 1 | |
196 | |
197 /* Define if you have the `strchr' function. */ | |
198 #define HAVE_STRCHR 1 | |
199 | |
200 /* Define if you have the ANSI C header files. */ | |
201 #define STDC_HEADERS 1 | |
202 | |
203 #include <stdio.h> | |
204 #if HAVE_SYS_TYPES_H | |
205 # include <sys/types.h> | |
206 #endif | |
207 #if HAVE_SYS_STAT_H | |
208 # include <sys/stat.h> | |
209 #endif | |
210 #if STDC_HEADERS | |
211 # include <stdlib.h> | |
212 # include <stddef.h> | |
213 #else | |
214 # if HAVE_STDLIB_H | |
215 # include <stdlib.h> | |
216 # endif | |
217 #endif | |
218 #if HAVE_STRING_H | |
219 # if !STDC_HEADERS && HAVE_MEMORY_H | |
220 # include <memory.h> | |
221 # endif | |
222 # include <string.h> | |
223 #endif | |
224 #if HAVE_STRINGS_H | |
225 # include <strings.h> | |
226 #endif | |
227 #if HAVE_INTTYPES_H | |
228 # include <inttypes.h> | |
229 #else | |
230 # if HAVE_STDINT_H | |
231 # include <stdint.h> | |
232 # else | |
233 /* we need these... */ | |
234 typedef unsigned long long uint64_t; | |
235 typedef unsigned long uint32_t; | |
236 typedef unsigned short uint16_t; | |
237 typedef unsigned char uint8_t; | |
238 typedef long long int64_t; | |
239 typedef long int32_t; | |
240 typedef short int16_t; | |
241 typedef char int8_t; | |
242 # endif | |
243 #endif | |
244 #if HAVE_UNISTD_H | |
245 # include <unistd.h> | |
246 #endif | |
247 | |
248 #ifndef HAVE_FLOAT32_T | |
249 typedef float float32_t; | |
250 #endif | |
251 | |
252 #if STDC_HEADERS | |
253 # include <string.h> | |
254 #else | |
255 # if !HAVE_STRCHR | |
256 # define strchr index | |
257 # define strrchr rindex | |
258 # endif | |
259 char *strchr(), *strrchr(); | |
260 # if !HAVE_MEMCPY | |
261 # define memcpy(d, s, n) bcopy((s), (d), (n)) | |
262 # define memmove(d, s, n) bcopy((s), (d), (n)) | |
263 # endif | |
264 #endif | |
265 | |
266 #endif | |
267 | |
268 #ifdef WORDS_BIGENDIAN | |
269 #define ARCH_IS_BIG_ENDIAN | |
270 #endif | |
271 | |
272 /* FIXED_POINT doesn't work with MAIN and SSR yet */ | |
273 #ifdef FIXED_POINT | |
274 #undef MAIN_DEC | |
275 #undef SSR_DEC | |
276 #endif | |
277 | |
278 | |
279 #if defined(FIXED_POINT) | |
280 | |
281 #include "fixed.h" | |
282 | |
283 #elif defined(USE_DOUBLE_PRECISION) | |
284 | |
285 typedef double real_t; | |
286 | |
287 #include <math.h> | |
288 | |
12527 | 289 #define MUL_R(A,B) ((A)*(B)) |
290 #define MUL_C(A,B) ((A)*(B)) | |
291 #define MUL_F(A,B) ((A)*(B)) | |
292 | |
293 /* Complex multiplication */ | |
294 static INLINE void ComplexMult(real_t *y1, real_t *y2, | |
295 real_t x1, real_t x2, real_t c1, real_t c2) | |
296 { | |
297 *y1 = MUL_F(x1, c1) + MUL_F(x2, c2); | |
298 *y2 = MUL_F(x2, c1) - MUL_F(x1, c2); | |
299 } | |
10725 | 300 |
10989 | 301 #define REAL_CONST(A) ((real_t)(A)) |
302 #define COEF_CONST(A) ((real_t)(A)) | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
303 #define Q2_CONST(A) ((real_t)(A)) |
12527 | 304 #define FRAC_CONST(A) ((real_t)(A)) /* pure fractional part */ |
10725 | 305 |
306 #else /* Normal floating point operation */ | |
307 | |
308 typedef float real_t; | |
309 | |
12527 | 310 #ifdef USE_SSE |
311 # include <xmmintrin.h> | |
312 #endif | |
313 | |
314 #define MUL_R(A,B) ((A)*(B)) | |
315 #define MUL_C(A,B) ((A)*(B)) | |
316 #define MUL_F(A,B) ((A)*(B)) | |
10725 | 317 |
10989 | 318 #define REAL_CONST(A) ((real_t)(A)) |
319 #define COEF_CONST(A) ((real_t)(A)) | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
320 #define Q2_CONST(A) ((real_t)(A)) |
12527 | 321 #define FRAC_CONST(A) ((real_t)(A)) /* pure fractional part */ |
322 | |
323 /* Complex multiplication */ | |
324 static INLINE void ComplexMult(real_t *y1, real_t *y2, | |
325 real_t x1, real_t x2, real_t c1, real_t c2) | |
326 { | |
327 *y1 = MUL_F(x1, c1) + MUL_F(x2, c2); | |
328 *y2 = MUL_F(x2, c1) - MUL_F(x1, c2); | |
329 } | |
330 | |
331 | |
15593 | 332 #if defined(_WIN32) && !defined(__MINGW32__) && !defined(HAVE_LRINTF) |
12527 | 333 #define HAS_LRINTF |
334 static INLINE int lrintf(float f) | |
335 { | |
336 int i; | |
337 __asm | |
338 { | |
339 fld f | |
340 fistp i | |
341 } | |
342 return i; | |
343 } | |
15593 | 344 #elif (defined(__i386__) && defined(__GNUC__)) && !defined(__MINGW32__) && !defined(HAVE_LRINTF) |
12527 | 345 #define HAS_LRINTF |
346 // from http://www.stereopsis.com/FPU.html | |
347 static INLINE int lrintf(float f) | |
348 { | |
349 int i; | |
350 __asm__ __volatile__ ( | |
351 "flds %1 \n\t" | |
352 "fistpl %0 \n\t" | |
353 : "=m" (i) | |
354 : "m" (f)); | |
355 return i; | |
356 } | |
357 #endif | |
358 | |
10725 | 359 |
360 #ifdef __ICL /* only Intel C compiler has fmath ??? */ | |
361 | |
362 #include <mathf.h> | |
363 | |
364 #define sin sinf | |
365 #define cos cosf | |
366 #define log logf | |
367 #define floor floorf | |
368 #define ceil ceilf | |
369 #define sqrt sqrtf | |
370 | |
371 #else | |
372 | |
13685 | 373 #include <math.h> |
374 | |
12527 | 375 #ifdef HAVE_LRINTF |
376 # define HAS_LRINTF | |
377 # define _ISOC9X_SOURCE 1 | |
378 # define _ISOC99_SOURCE 1 | |
379 # define __USE_ISOC9X 1 | |
380 # define __USE_ISOC99 1 | |
381 #endif | |
382 | |
10725 | 383 #ifdef HAVE_SINF |
384 # define sin sinf | |
385 #error | |
386 #endif | |
387 #ifdef HAVE_COSF | |
388 # define cos cosf | |
389 #endif | |
390 #ifdef HAVE_LOGF | |
391 # define log logf | |
392 #endif | |
393 #ifdef HAVE_EXPF | |
394 # define exp expf | |
395 #endif | |
396 #ifdef HAVE_FLOORF | |
397 # define floor floorf | |
398 #endif | |
399 #ifdef HAVE_CEILF | |
400 # define ceil ceilf | |
401 #endif | |
402 #ifdef HAVE_SQRTF | |
403 # define sqrt sqrtf | |
404 #endif | |
405 | |
406 #endif | |
407 | |
408 #endif | |
409 | |
12527 | 410 #ifndef HAS_LRINTF |
411 /* standard cast */ | |
412 #define lrintf(f) ((int32_t)(f)) | |
413 #endif | |
414 | |
10725 | 415 typedef real_t complex_t[2]; |
416 #define RE(A) A[0] | |
417 #define IM(A) A[1] | |
418 | |
419 | |
420 /* common functions */ | |
12527 | 421 uint8_t cpu_has_sse(void); |
10725 | 422 uint32_t random_int(void); |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
423 uint32_t ones32(uint32_t x); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
424 uint32_t floor_log2(uint32_t x); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
425 uint32_t wl_min_lzc(uint32_t x); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
426 #ifdef FIXED_POINT |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
427 #define LOG2_MIN_INF REAL_CONST(-10000) |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
428 int32_t log2_int(uint32_t val); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
429 int32_t pow2_int(real_t val); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
430 real_t pow2_fix(real_t val); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
431 #endif |
12527 | 432 uint8_t get_sr_index(const uint32_t samplerate); |
433 uint8_t max_pred_sfb(const uint8_t sr_index); | |
434 uint8_t max_tns_sfb(const uint8_t sr_index, const uint8_t object_type, | |
435 const uint8_t is_short); | |
436 uint32_t get_sample_rate(const uint8_t sr_index); | |
437 int8_t can_decode_ot(const uint8_t object_type); | |
438 | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
439 void *faad_malloc(size_t size); |
12527 | 440 void faad_free(void *b); |
441 | |
442 //#define PROFILE | |
443 #ifdef PROFILE | |
444 static int64_t faad_get_ts() | |
445 { | |
446 __asm | |
447 { | |
448 rdtsc | |
449 } | |
450 } | |
451 #endif | |
10725 | 452 |
453 #ifndef M_PI | |
12527 | 454 #define M_PI 3.14159265358979323846 |
10725 | 455 #endif |
456 #ifndef M_PI_2 /* PI/2 */ | |
457 #define M_PI_2 1.57079632679489661923 | |
458 #endif | |
459 | |
460 | |
461 #ifdef __cplusplus | |
462 } | |
463 #endif | |
464 #endif |