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