blob: e59f81161bac15ba1fdb46c38105dbf3618f8399
1 | /* |
2 | ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding |
3 | ** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com |
4 | ** |
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. |
9 | ** |
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. |
14 | ** |
15 | ** You should have received a copy of the GNU General Public License |
16 | ** along with this program; if not, write to the Free Software |
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 | ** The "appropriate copyright message" mentioned in section 2c of the GPLv2 |
23 | ** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com" |
24 | ** |
25 | ** Commercial non-GPL licensing of this software is possible. |
26 | ** For more info contact Nero AG through Mpeg4AAClicense@nero.com. |
27 | ** |
28 | ** $Id: common.h,v 1.77 2009/02/05 00:51:03 menno Exp $ |
29 | **/ |
30 | |
31 | #ifndef __COMMON_H__ |
32 | #define __COMMON_H__ |
33 | |
34 | #ifdef __cplusplus |
35 | extern "C" { |
36 | #endif |
37 | |
38 | #ifdef HAVE_CONFIG_H |
39 | # include "../config.h" |
40 | #endif |
41 | |
42 | #include "neaacdec.h" |
43 | #include <android/log.h> |
44 | |
45 | #define LOG_TAG "FaadDecoder" |
46 | #define audio_codec_print(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__) |
47 | #define DEBUG audio_codec_print |
48 | #define HAVE_MEMCPY 1 |
49 | #if 1 |
50 | #define INLINE __inline |
51 | #else |
52 | #define INLINE inline |
53 | #endif |
54 | |
55 | #if 0 //defined(_WIN32) && !defined(_WIN32_WCE) |
56 | #define ALIGN __declspec(align(16)) |
57 | #else |
58 | #define ALIGN |
59 | #endif |
60 | |
61 | #ifndef max |
62 | #define max(a, b) (((a) > (b)) ? (a) : (b)) |
63 | #endif |
64 | #ifndef min |
65 | #define min(a, b) (((a) < (b)) ? (a) : (b)) |
66 | #endif |
67 | |
68 | /* COMPILE TIME DEFINITIONS */ |
69 | |
70 | /* use double precision */ |
71 | #define USE_DOUBLE_PRECISION |
72 | /* use fixed point reals */ |
73 | //#define FIXED_POINT |
74 | //#define BIG_IQ_TABLE |
75 | |
76 | /* Use if target platform has address generators with autoincrement */ |
77 | //#define PREFER_POINTERS |
78 | |
79 | #ifdef _WIN32_WCE |
80 | #define FIXED_POINT |
81 | #endif |
82 | |
83 | #ifdef __BFIN__ |
84 | #define FIXED_POINT |
85 | #endif |
86 | |
87 | #define ERROR_RESILIENCE |
88 | |
89 | |
90 | /* Allow decoding of MAIN profile AAC */ |
91 | #define MAIN_DEC |
92 | /* Allow decoding of SSR profile AAC */ |
93 | //#define SSR_DEC |
94 | /* Allow decoding of LTP profile AAC */ |
95 | #define LTP_DEC |
96 | /* Allow decoding of LD profile AAC */ |
97 | #define LD_DEC |
98 | /* Allow decoding of Digital Radio Mondiale (DRM) */ |
99 | //#define DRM |
100 | //#define DRM_PS |
101 | |
102 | /* LD can't do without LTP */ |
103 | #ifdef LD_DEC |
104 | #ifndef ERROR_RESILIENCE |
105 | #define ERROR_RESILIENCE |
106 | #endif |
107 | #ifndef LTP_DEC |
108 | #define LTP_DEC |
109 | #endif |
110 | #endif |
111 | |
112 | #define ALLOW_SMALL_FRAMELENGTH |
113 | |
114 | |
115 | // Define LC_ONLY_DECODER if you want a pure AAC LC decoder (independant of SBR_DEC and PS_DEC) |
116 | //#define LC_ONLY_DECODER |
117 | #ifdef LC_ONLY_DECODER |
118 | #undef LD_DEC |
119 | #undef LTP_DEC |
120 | #undef MAIN_DEC |
121 | #undef SSR_DEC |
122 | #undef DRM |
123 | #undef ALLOW_SMALL_FRAMELENGTH |
124 | #undef ERROR_RESILIENCE |
125 | #endif |
126 | //#define DISABLE_SBR |
127 | #define SBR_DEC |
128 | //#define SBR_LOW_POWER |
129 | #define PS_DEC |
130 | |
131 | #ifdef SBR_LOW_POWER |
132 | #undef PS_DEC |
133 | #endif |
134 | |
135 | /* FIXED POINT: No MAIN decoding */ |
136 | #ifdef FIXED_POINT |
137 | # ifdef MAIN_DEC |
138 | # undef MAIN_DEC |
139 | # endif |
140 | #endif // FIXED_POINT |
141 | |
142 | #ifdef DRM |
143 | # ifndef ALLOW_SMALL_FRAMELENGTH |
144 | # define ALLOW_SMALL_FRAMELENGTH |
145 | # endif |
146 | # undef LD_DEC |
147 | # undef LTP_DEC |
148 | # undef MAIN_DEC |
149 | # undef SSR_DEC |
150 | #endif |
151 | |
152 | |
153 | #ifdef FIXED_POINT |
154 | #define DIV_R(A, B) (((int64_t)A << REAL_BITS)/B) |
155 | #define DIV_C(A, B) (((int64_t)A << COEF_BITS)/B) |
156 | #else |
157 | #define DIV_R(A, B) ((A)/(B)) |
158 | #define DIV_C(A, B) ((A)/(B)) |
159 | #endif |
160 | |
161 | #ifndef SBR_LOW_POWER |
162 | #define qmf_t complex_t |
163 | #define QMF_RE(A) RE(A) |
164 | #define QMF_IM(A) IM(A) |
165 | #else |
166 | #define qmf_t real_t |
167 | #define QMF_RE(A) (A) |
168 | #define QMF_IM(A) |
169 | #endif |
170 | |
171 | |
172 | /* END COMPILE TIME DEFINITIONS */ |
173 | |
174 | #if defined(_WIN32) && !defined(__MINGW32__) |
175 | |
176 | #include <stdlib.h> |
177 | |
178 | typedef unsigned __int64 uint64_t; |
179 | typedef unsigned __int32 uint32_t; |
180 | typedef unsigned __int16 uint16_t; |
181 | typedef unsigned __int8 uint8_t; |
182 | typedef signed __int64 int64_t; |
183 | typedef signed __int32 int32_t; |
184 | typedef signed __int16 int16_t; |
185 | typedef signed __int8 int8_t; |
186 | typedef float float32_t; |
187 | |
188 | |
189 | #else |
190 | |
191 | #include <stdio.h> |
192 | #if HAVE_SYS_TYPES_H |
193 | # include <sys/types.h> |
194 | #endif |
195 | #if HAVE_SYS_STAT_H |
196 | # include <sys/stat.h> |
197 | #endif |
198 | #if STDC_HEADERS |
199 | # include <stdlib.h> |
200 | # include <stddef.h> |
201 | #else |
202 | # if HAVE_STDLIB_H |
203 | # include <stdlib.h> |
204 | # endif |
205 | #endif |
206 | #if HAVE_STRING_H |
207 | # if !STDC_HEADERS && HAVE_MEMORY_H |
208 | # include <memory.h> |
209 | # endif |
210 | # include <string.h> |
211 | #endif |
212 | #if HAVE_STRINGS_H |
213 | # include <strings.h> |
214 | #endif |
215 | #if HAVE_INTTYPES_H |
216 | # include <inttypes.h> |
217 | #else |
218 | # if HAVE_STDINT_H |
219 | # include <stdint.h> |
220 | # else |
221 | /* we need these... */ |
222 | #ifndef __TCS__ |
223 | //typedef unsigned long long uint64_t; |
224 | //typedef signed long long int64_t; |
225 | #else |
226 | typedef unsigned long uint64_t; |
227 | typedef signed long int64_t; |
228 | #endif |
229 | //typedef unsigned long uint32_t; |
230 | typedef unsigned short uint16_t; |
231 | typedef unsigned char uint8_t; |
232 | //typedef signed long int32_t; |
233 | typedef signed short int16_t; |
234 | typedef signed 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 | |
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 | } |
293 | |
294 | #define REAL_CONST(A) ((real_t)(A)) |
295 | #define COEF_CONST(A) ((real_t)(A)) |
296 | #define Q2_CONST(A) ((real_t)(A)) |
297 | #define FRAC_CONST(A) ((real_t)(A)) /* pure fractional part */ |
298 | |
299 | #else /* Normal floating point operation */ |
300 | |
301 | typedef float real_t; |
302 | |
303 | #define MUL_R(A,B) ((A)*(B)) |
304 | #define MUL_C(A,B) ((A)*(B)) |
305 | #define MUL_F(A,B) ((A)*(B)) |
306 | |
307 | #define REAL_CONST(A) ((real_t)(A)) |
308 | #define COEF_CONST(A) ((real_t)(A)) |
309 | #define Q2_CONST(A) ((real_t)(A)) |
310 | #define FRAC_CONST(A) ((real_t)(A)) /* pure fractional part */ |
311 | |
312 | /* Complex multiplication */ |
313 | static INLINE void ComplexMult(real_t *y1, real_t *y2, |
314 | real_t x1, real_t x2, real_t c1, real_t c2) |
315 | { |
316 | *y1 = MUL_F(x1, c1) + MUL_F(x2, c2); |
317 | *y2 = MUL_F(x2, c1) - MUL_F(x1, c2); |
318 | } |
319 | |
320 | |
321 | #if defined(_WIN32) && !defined(__MINGW32__) |
322 | #define HAS_LRINTF |
323 | static INLINE int lrintf(float f) |
324 | { |
325 | int i; |
326 | __asm { |
327 | fld f |
328 | fistp i |
329 | } |
330 | return i; |
331 | } |
332 | #elif (defined(__i386__) && defined(__GNUC__) && \ |
333 | !defined(__CYGWIN__) && !defined(__MINGW32__)) |
334 | #ifndef HAVE_LRINTF |
335 | #define HAS_LRINTF |
336 | // from http://www.stereopsis.com/FPU.html |
337 | static INLINE int lrintf(float f) |
338 | { |
339 | int i; |
340 | __asm__ __volatile__( |
341 | "flds %1 \n\t" |
342 | "fistpl %0 \n\t" |
343 | : "=m"(i) |
344 | : "m"(f)); |
345 | return i; |
346 | } |
347 | #endif /* HAVE_LRINTF */ |
348 | #endif |
349 | |
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 | |
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 | |
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 | |
401 | #ifndef HAS_LRINTF |
402 | /* standard cast */ |
403 | #define lrintf(f) ((int32_t)(f)) |
404 | #endif |
405 | |
406 | typedef real_t complex_t[2]; |
407 | #define RE(A) A[0] |
408 | #define IM(A) A[1] |
409 | |
410 | |
411 | /* common functions */ |
412 | uint8_t cpu_has_sse(void); |
413 | uint32_t ne_rng(uint32_t *__r1, uint32_t *__r2); |
414 | uint32_t wl_min_lzc(uint32_t x); |
415 | #ifdef FIXED_POINT |
416 | #define LOG2_MIN_INF REAL_CONST(-10000) |
417 | int32_t log2_int(uint32_t val); |
418 | int32_t log2_fix(uint32_t val); |
419 | int32_t pow2_int(real_t val); |
420 | real_t pow2_fix(real_t val); |
421 | #endif |
422 | uint8_t get_sr_index(const uint32_t samplerate); |
423 | uint8_t max_pred_sfb(const uint8_t sr_index); |
424 | uint8_t max_tns_sfb(const uint8_t sr_index, const uint8_t object_type, |
425 | const uint8_t is_short); |
426 | uint32_t get_sample_rate(const uint8_t sr_index); |
427 | int8_t can_decode_ot(const uint8_t object_type); |
428 | |
429 | void *faad_malloc(size_t size); |
430 | void faad_free(void *b); |
431 | |
432 | //#define PROFILE |
433 | #ifdef PROFILE |
434 | static int64_t faad_get_ts() |
435 | { |
436 | __asm { |
437 | rdtsc |
438 | } |
439 | } |
440 | #endif |
441 | |
442 | #ifndef M_PI |
443 | #define M_PI 3.14159265358979323846 |
444 | #endif |
445 | #ifndef M_PI_2 /* PI/2 */ |
446 | #define M_PI_2 1.57079632679489661923 |
447 | #endif |
448 | |
449 | |
450 | #ifdef __cplusplus |
451 | } |
452 | #endif |
453 | #endif |
454 |