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