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