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