The last submit had one define too much. Nevertheless fix the IRAM configuration...
[kugel-rb.git] / apps / codecs / libfaad / common.h
blobe5b86ba97831a2358714595e59135ad9d61262cf
1 /*
2 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
3 ** Copyright (C) 2003-2004 M. Bakker, Ahead Software 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.
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.
19 ** Any non-GPL usage of this software or parts of this software is strictly
20 ** forbidden.
22 ** Commercial non-GPL licensing of this software is possible.
23 ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
25 ** $Id$
26 **/
28 #ifndef __COMMON_H__
29 #define __COMMON_H__
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
35 #include "faad_config.h"
36 #include "codeclib.h"
38 extern struct codec_api* ci;
40 #if defined(DEBUG) || defined(SIMULATOR)
41 #undef DEBUGF
42 #define DEBUGF ci->debugf
43 #else
44 #define DEBUGF(...)
45 #endif
47 #ifdef ROCKBOX_HAS_LOGF
48 #undef LOGF
49 #define LOGF ci->logf
50 #else
51 #define LOGF(...)
52 #endif
54 #if (CONFIG_CPU == MCF5250)
55 /* Enough IRAM but performance suffers with ICODE_ATTR. */
56 #define IBSS_ATTR_FAAD_LARGE_IRAM IBSS_ATTR
57 #define ICODE_ATTR_FAAD_LARGE_IRAM
58 #define ICONST_ATTR_FAAD_LARGE_IRAM ICONST_ATTR
59 #define IBSS_ATTR_FAAD_XLR
61 #elif (CONFIG_CPU == PP5022) || (CONFIG_CPU == PP5024)
62 /* Enough IRAM to move additional data and code to it. */
63 #define IBSS_ATTR_FAAD_LARGE_IRAM IBSS_ATTR
64 #define ICODE_ATTR_FAAD_LARGE_IRAM ICODE_ATTR
65 #define ICONST_ATTR_FAAD_LARGE_IRAM ICONST_ATTR
66 #define IBSS_ATTR_FAAD_XLR
68 #elif defined(CPU_S5L870X)
69 /* Very large IRAM. Move even more data to it. */
70 #define IBSS_ATTR_FAAD_LARGE_IRAM IBSS_ATTR
71 #define ICODE_ATTR_FAAD_LARGE_IRAM ICODE_ATTR
72 #define ICONST_ATTR_FAAD_LARGE_IRAM ICONST_ATTR
73 #define IBSS_ATTR_FAAD_XLR IBSS_ATTR
75 #else
76 /* Not enough IRAM available. */
77 #define IBSS_ATTR_FAAD_LARGE_IRAM
78 #define ICODE_ATTR_FAAD_LARGE_IRAM
79 #define ICONST_ATTR_FAAD_LARGE_IRAM
80 #define IBSS_ATTR_FAAD_XLR
81 #endif
83 /* Used to allocate several SBR + PS arrays and variables statically. */
84 //#define FAAD_STATIC_ALLOC
86 #define INLINE __inline
87 #if 0 //defined(_WIN32) && !defined(_WIN32_WCE)
88 #define ALIGN __declspec(align(16))
89 #else
90 #define ALIGN
91 #endif
93 #ifndef max
94 #define max(a, b) (((a) > (b)) ? (a) : (b))
95 #endif
96 #ifndef min
97 #define min(a, b) (((a) < (b)) ? (a) : (b))
98 #endif
100 /* COMPILE TIME DEFINITIONS */
102 /* use double precision */
103 /* #define USE_DOUBLE_PRECISION */
104 /* use fixed point reals */
105 #define FIXED_POINT
106 #define BIG_IQ_TABLE /* BIG_IQ_TABLE results in faster requantization */
108 /* Use if target platform has address generators with autoincrement */
109 //#define PREFER_POINTERS
111 #define ERROR_RESILIENCE
114 /* Allow decoding of MAIN profile AAC */
115 #define MAIN_DEC
116 /* Allow decoding of SSR profile AAC */
117 #define SSR_DEC
118 /* Allow decoding of LTP profile AAC */
119 #define LTP_DEC
120 /* Allow decoding of LD profile AAC */
121 #define LD_DEC
122 /* Allow decoding of scalable profiles */
123 //#define SCALABLE_DEC
124 /* Allow decoding of Digital Radio Mondiale (DRM) */
125 //#define DRM
126 //#define DRM_PS
128 /* LD can't do without LTP */
129 #ifdef LD_DEC
130 #ifndef ERROR_RESILIENCE
131 #define ERROR_RESILIENCE
132 #endif
133 #ifndef LTP_DEC
134 #define LTP_DEC
135 #endif
136 #endif
138 #define ALLOW_SMALL_FRAMELENGTH
141 // Define LC_ONLY_DECODER if you want a pure AAC LC decoder (independant of SBR_DEC and PS_DEC)
142 #define LC_ONLY_DECODER
143 #ifdef LC_ONLY_DECODER
144 #undef LD_DEC
145 #undef LTP_DEC
146 #undef MAIN_DEC
147 #undef SSR_DEC
148 #undef DRM
149 #undef ALLOW_SMALL_FRAMELENGTH
150 #undef ERROR_RESILIENCE
151 #endif
153 #if CODEC_SIZE >= 0x80000
154 #define SBR_DEC
155 //#define SBR_LOW_POWER /* Does not work yet in rockbox. */
156 #define PS_DEC
157 #endif
159 /* FIXED POINT: No MAIN decoding */
160 #ifdef FIXED_POINT
161 # ifdef MAIN_DEC
162 # undef MAIN_DEC
163 # endif
164 #endif // FIXED_POINT
166 #ifdef DRM
167 # ifndef SCALABLE_DEC
168 # define SCALABLE_DEC
169 # endif
170 #endif
173 #ifdef FIXED_POINT
174 #define DIV_R(A, B) (((int64_t)A << REAL_BITS)/B)
175 #define DIV_C(A, B) (((int64_t)A << COEF_BITS)/B)
176 #define DIV_Q(A, B) (((int64_t)A << Q2_BITS )/B)
177 #else
178 #define DIV_R(A, B) ((A)/(B))
179 #define DIV_C(A, B) ((A)/(B))
180 #define DIV_Q(A, B) ((A)/(B))
181 #endif
183 #ifndef SBR_LOW_POWER
184 #define qmf_t complex_t
185 #define QMF_RE(A) RE(A)
186 #define QMF_IM(A) IM(A)
187 #else
188 #define qmf_t real_t
189 #define QMF_RE(A) (A)
190 #define QMF_IM(A)
191 #endif
194 /* END COMPILE TIME DEFINITIONS */
196 #if defined(_WIN32) && !defined(__MINGW32__)
198 #include <stdlib.h>
200 typedef unsigned __int64 uint64_t;
201 typedef unsigned __int32 uint32_t;
202 typedef unsigned __int16 uint16_t;
203 typedef unsigned __int8 uint8_t;
204 typedef __int64 int64_t;
205 typedef __int32 int32_t;
206 typedef __int16 int16_t;
207 typedef __int8 int8_t;
208 typedef float float32_t;
211 #else
213 #include <stdio.h>
214 #ifdef HAVE_SYS_TYPES_H
215 # include "inttypes.h"
216 #endif
217 #ifdef HAVE_SYS_STAT_H
218 # include <sys/stat.h>
219 #endif
220 #ifdef STDC_HEADERS
221 # include <stdlib.h>
222 # include <stddef.h>
223 #else
224 # ifdef HAVE_STDLIB_H
225 # include <stdlib.h>
226 # endif
227 #endif
228 #ifdef HAVE_STRING_H
229 # if !defined(STDC_HEADERS) && defined(HAVE_MEMORY_H)
230 # include <memory.h>
231 # endif
232 //# include <string.h>
233 #endif
234 #ifdef HAVE_STRINGS_H
235 //# include <strings.h>
236 #endif
237 #ifdef HAVE_INTTYPES_H
238 # include <inttypes.h>
239 #else
240 # ifdef HAVE_STDINT_H
241 # include <stdint.h>
242 # else
243 /* we need these... */
244 typedef unsigned long long uint64_t;
245 typedef unsigned long uint32_t;
246 typedef unsigned short uint16_t;
247 typedef unsigned char uint8_t;
248 typedef long long int64_t;
249 typedef long int32_t;
250 typedef short int16_t;
251 typedef char int8_t;
252 # endif
253 #endif
254 #ifdef HAVE_UNISTD_H
255 # include <unistd.h>
256 #endif
258 #ifndef HAVE_FLOAT32_T
259 typedef float float32_t;
260 #endif
262 #if STDC_HEADERS
263 //# include <string.h>
264 #else
265 # if !HAVE_STRCHR
266 # define strchr index
267 # define strrchr rindex
268 # endif
269 char *strchr(), *strrchr();
270 # if !HAVE_MEMCPY
271 # define memcpy(d, s, n) bcopy((s), (d), (n))
272 # define memmove(d, s, n) bcopy((s), (d), (n))
273 # endif
274 #endif
276 #endif
278 #ifdef WORDS_BIGENDIAN
279 #define ARCH_IS_BIG_ENDIAN
280 #endif
282 /* FIXED_POINT doesn't work with MAIN and SSR yet */
283 #ifdef FIXED_POINT
284 #undef MAIN_DEC
285 #undef SSR_DEC
286 #endif
289 #if defined(FIXED_POINT)
291 #include "fixed.h"
293 #elif defined(USE_DOUBLE_PRECISION)
295 typedef double real_t;
297 #include <math.h>
299 #define MUL_R(A,B) ((A)*(B))
300 #define MUL_C(A,B) ((A)*(B))
301 #define MUL_F(A,B) ((A)*(B))
302 #define MUL_Q2(A,B) ((A)*(B))
304 /* Complex multiplication */
305 static INLINE void ComplexMult(real_t *y1, real_t *y2,
306 real_t x1, real_t x2, real_t c1, real_t c2)
308 *y1 = MUL_F(x1, c1) + MUL_F(x2, c2);
309 *y2 = MUL_F(x2, c1) - MUL_F(x1, c2);
312 #define REAL_CONST(A) ((real_t)(A))
313 #define COEF_CONST(A) ((real_t)(A))
314 #define Q2_CONST(A) ((real_t)(A))
315 #define FRAC_CONST(A) ((real_t)(A)) /* pure fractional part */
317 #else /* Normal floating point operation */
319 typedef float real_t;
321 #define MUL_R(A,B) ((A)*(B))
322 #define MUL_C(A,B) ((A)*(B))
323 #define MUL_F(A,B) ((A)*(B))
324 #define MUL_Q2(A,B) ((A)*(B))
326 #define REAL_CONST(A) ((real_t)(A))
327 #define COEF_CONST(A) ((real_t)(A))
328 #define Q2_CONST(A) ((real_t)(A))
329 #define FRAC_CONST(A) ((real_t)(A)) /* pure fractional part */
331 /* Complex multiplication */
332 static INLINE void ComplexMult(real_t *y1, real_t *y2,
333 real_t x1, real_t x2, real_t c1, real_t c2)
335 *y1 = MUL_F(x1, c1) + MUL_F(x2, c2);
336 *y2 = MUL_F(x2, c1) - MUL_F(x1, c2);
339 /* rockbox: must be commented to build for non-FP
340 #if defined(_WIN32) && !defined(__MINGW32__)
341 #define HAS_LRINTF
342 static INLINE int lrintf(float f)
344 int i;
345 __asm
347 fld f
348 fistp i
350 return i;
352 #elif (defined(__i386__) && defined(__GNUC__))
353 #define HAS_LRINTF
354 // from http://www.stereopsis.com/FPU.html
355 static INLINE int lrintf(float f)
357 int i;
358 __asm__ __volatile__ (
359 "flds %1 \n\t"
360 "fistpl %0 \n\t"
361 : "=m" (i)
362 : "m" (f));
363 return i;
365 #endif
368 #ifdef __ICL /* only Intel C compiler has fmath ??? */
370 #include <mathf.h>
372 #define sin sinf
373 #define cos cosf
374 #define log logf
375 #define floor floorf
376 #define ceil ceilf
377 #define sqrt sqrtf
379 #else
381 #ifdef HAVE_LRINTF
382 # define HAS_LRINTF
383 # define _ISOC9X_SOURCE 1
384 # define _ISOC99_SOURCE 1
385 # define __USE_ISOC9X 1
386 # define __USE_ISOC99 1
387 #endif
389 #include <math.h>
391 #ifdef HAVE_SINF
392 # define sin sinf
393 #error
394 #endif
395 #ifdef HAVE_COSF
396 # define cos cosf
397 #endif
398 #ifdef HAVE_LOGF
399 # define log logf
400 #endif
401 #ifdef HAVE_EXPF
402 # define exp expf
403 #endif
404 #ifdef HAVE_FLOORF
405 # define floor floorf
406 #endif
407 #ifdef HAVE_CEILF
408 # define ceil ceilf
409 #endif
410 #ifdef HAVE_SQRTF
411 # define sqrt sqrtf
412 #endif
414 #endif
416 #endif
418 #ifndef HAS_LRINTF
419 /* standard cast */
420 #define lrintf(f) ((int32_t)(f))
421 #endif
423 typedef real_t complex_t[2];
424 #define RE(A) A[0]
425 #define IM(A) A[1]
428 /* common functions */
429 uint8_t cpu_has_sse(void);
430 uint32_t random_int(void);
431 #define wl_min_lzc(x) bs_generic(x, BS_LOG2|BS_0_0)
432 #ifdef FIXED_POINT
433 #define LOG2_MIN_INF REAL_CONST(-10000)
434 int32_t log2_int(uint32_t val);
435 int32_t log2_fix(uint32_t val);
436 uint32_t pow2_int(real_t val);
437 uint32_t pow2_fix(real_t val);
438 #endif
439 uint8_t get_sr_index(const uint32_t samplerate);
440 uint8_t max_pred_sfb(const uint8_t sr_index);
441 uint8_t max_tns_sfb(const uint8_t sr_index, const uint8_t object_type,
442 const uint8_t is_short);
443 uint32_t get_sample_rate(const uint8_t sr_index);
444 int8_t can_decode_ot(const uint8_t object_type);
446 #ifndef FAAD_STATIC_ALLOC
447 /* Those should not be defined or used anymore */
448 #define faad_malloc(A) malloc(A)
449 #define faad_free(A) free(A)
450 #endif
452 //#define PROFILE
453 #ifdef PROFILE
454 static int64_t faad_get_ts()
456 __asm
458 rdtsc
461 #endif
463 #ifndef M_PI
464 #define M_PI 3.14159265358979323846
465 #endif
466 #ifndef M_PI_2 /* PI/2 */
467 #define M_PI_2 1.57079632679489661923
468 #endif
471 #ifdef __cplusplus
473 #endif
474 #endif