diff options
author | Sean Bartell <wingedtachikoma@gmail.com> | 2011-06-25 21:32:25 -0400 |
---|---|---|
committer | Nils Wallménius <nils@rockbox.org> | 2012-04-25 22:13:20 +0200 |
commit | f40bfc9267b13b54e6379dfe7539447662879d24 (patch) | |
tree | 9b20069d5e62809ff434061ad730096836f916f2 /lib/rbcodec/codecs/libfaad/common.h | |
parent | a0009907de7a0107d49040d8a180f140e2eff299 (diff) | |
download | rockbox-f40bfc9267b13b54e6379dfe7539447662879d24.tar.gz rockbox-f40bfc9267b13b54e6379dfe7539447662879d24.zip |
Add codecs to librbcodec.
Change-Id: Id7f4717d51ed02d67cb9f9cb3c0ada4a81843f97
Reviewed-on: http://gerrit.rockbox.org/137
Reviewed-by: Nils Wallménius <nils@rockbox.org>
Tested-by: Nils Wallménius <nils@rockbox.org>
Diffstat (limited to 'lib/rbcodec/codecs/libfaad/common.h')
-rw-r--r-- | lib/rbcodec/codecs/libfaad/common.h | 475 |
1 files changed, 475 insertions, 0 deletions
diff --git a/lib/rbcodec/codecs/libfaad/common.h b/lib/rbcodec/codecs/libfaad/common.h new file mode 100644 index 0000000000..720042b4aa --- /dev/null +++ b/lib/rbcodec/codecs/libfaad/common.h | |||
@@ -0,0 +1,475 @@ | |||
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. | ||
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 | ** 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 | |||
35 | #include "faad_config.h" | ||
36 | #include "codeclib.h" | ||
37 | |||
38 | extern struct codec_api* ci; | ||
39 | |||
40 | #if defined(DEBUG) || defined(SIMULATOR) | ||
41 | #undef DEBUGF | ||
42 | #define DEBUGF ci->debugf | ||
43 | #else | ||
44 | #define DEBUGF(...) | ||
45 | #endif | ||
46 | |||
47 | #ifdef ROCKBOX_HAS_LOGF | ||
48 | #undef LOGF | ||
49 | #define LOGF ci->logf | ||
50 | #else | ||
51 | #define LOGF(...) | ||
52 | #endif | ||
53 | |||
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 | ||
60 | |||
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 | ||
67 | |||
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 | ||
74 | #define HAVE_FAAD_XLR_IN_IRAM | ||
75 | |||
76 | #else | ||
77 | /* Not enough IRAM available. */ | ||
78 | #define IBSS_ATTR_FAAD_LARGE_IRAM | ||
79 | #define ICODE_ATTR_FAAD_LARGE_IRAM | ||
80 | #define ICONST_ATTR_FAAD_LARGE_IRAM | ||
81 | #define IBSS_ATTR_FAAD_XLR | ||
82 | #endif | ||
83 | |||
84 | /* Used to allocate several SBR + PS arrays and variables statically. */ | ||
85 | //#define FAAD_STATIC_ALLOC | ||
86 | |||
87 | #define INLINE __inline | ||
88 | #if 0 //defined(_WIN32) && !defined(_WIN32_WCE) | ||
89 | #define ALIGN __declspec(align(16)) | ||
90 | #else | ||
91 | #define ALIGN | ||
92 | #endif | ||
93 | |||
94 | #ifndef max | ||
95 | #define max(a, b) (((a) > (b)) ? (a) : (b)) | ||
96 | #endif | ||
97 | #ifndef min | ||
98 | #define min(a, b) (((a) < (b)) ? (a) : (b)) | ||
99 | #endif | ||
100 | |||
101 | /* COMPILE TIME DEFINITIONS */ | ||
102 | |||
103 | /* use double precision */ | ||
104 | /* #define USE_DOUBLE_PRECISION */ | ||
105 | /* use fixed point reals */ | ||
106 | #define FIXED_POINT | ||
107 | #define BIG_IQ_TABLE /* BIG_IQ_TABLE results in faster requantization */ | ||
108 | |||
109 | /* Use if target platform has address generators with autoincrement */ | ||
110 | //#define PREFER_POINTERS | ||
111 | |||
112 | #define ERROR_RESILIENCE | ||
113 | |||
114 | |||
115 | /* Allow decoding of MAIN profile AAC */ | ||
116 | #define MAIN_DEC | ||
117 | /* Allow decoding of SSR profile AAC */ | ||
118 | #define SSR_DEC | ||
119 | /* Allow decoding of LTP profile AAC */ | ||
120 | #define LTP_DEC | ||
121 | /* Allow decoding of LD profile AAC */ | ||
122 | #define LD_DEC | ||
123 | /* Allow decoding of scalable profiles */ | ||
124 | //#define SCALABLE_DEC | ||
125 | /* Allow decoding of Digital Radio Mondiale (DRM) */ | ||
126 | //#define DRM | ||
127 | //#define DRM_PS | ||
128 | |||
129 | /* LD can't do without LTP */ | ||
130 | #ifdef LD_DEC | ||
131 | #ifndef ERROR_RESILIENCE | ||
132 | #define ERROR_RESILIENCE | ||
133 | #endif | ||
134 | #ifndef LTP_DEC | ||
135 | #define LTP_DEC | ||
136 | #endif | ||
137 | #endif | ||
138 | |||
139 | #define ALLOW_SMALL_FRAMELENGTH | ||
140 | |||
141 | |||
142 | // Define LC_ONLY_DECODER if you want a pure AAC LC decoder (independant of SBR_DEC and PS_DEC) | ||
143 | #define LC_ONLY_DECODER | ||
144 | #ifdef LC_ONLY_DECODER | ||
145 | #undef LD_DEC | ||
146 | #undef LTP_DEC | ||
147 | #undef MAIN_DEC | ||
148 | #undef SSR_DEC | ||
149 | #undef DRM | ||
150 | #undef ALLOW_SMALL_FRAMELENGTH | ||
151 | #undef ERROR_RESILIENCE | ||
152 | #endif | ||
153 | |||
154 | #if CODEC_SIZE >= 0x80000 | ||
155 | #define SBR_DEC | ||
156 | //#define SBR_LOW_POWER /* Does not work yet in rockbox. */ | ||
157 | #define PS_DEC | ||
158 | #endif | ||
159 | |||
160 | /* FIXED POINT: No MAIN decoding */ | ||
161 | #ifdef FIXED_POINT | ||
162 | # ifdef MAIN_DEC | ||
163 | # undef MAIN_DEC | ||
164 | # endif | ||
165 | #endif // FIXED_POINT | ||
166 | |||
167 | #ifdef DRM | ||
168 | # ifndef SCALABLE_DEC | ||
169 | # define SCALABLE_DEC | ||
170 | # endif | ||
171 | #endif | ||
172 | |||
173 | |||
174 | #ifdef FIXED_POINT | ||
175 | #define DIV_R(A, B) (((int64_t)A << REAL_BITS)/B) | ||
176 | #define DIV_C(A, B) (((int64_t)A << COEF_BITS)/B) | ||
177 | #define DIV_Q(A, B) (((int64_t)A << Q2_BITS )/B) | ||
178 | #else | ||
179 | #define DIV_R(A, B) ((A)/(B)) | ||
180 | #define DIV_C(A, B) ((A)/(B)) | ||
181 | #define DIV_Q(A, B) ((A)/(B)) | ||
182 | #endif | ||
183 | |||
184 | #ifndef SBR_LOW_POWER | ||
185 | #define qmf_t complex_t | ||
186 | #define QMF_RE(A) RE(A) | ||
187 | #define QMF_IM(A) IM(A) | ||
188 | #else | ||
189 | #define qmf_t real_t | ||
190 | #define QMF_RE(A) (A) | ||
191 | #define QMF_IM(A) | ||
192 | #endif | ||
193 | |||
194 | |||
195 | /* END COMPILE TIME DEFINITIONS */ | ||
196 | |||
197 | #if defined(_WIN32) && !defined(__MINGW32__) | ||
198 | |||
199 | #include <stdlib.h> | ||
200 | |||
201 | typedef unsigned __int64 uint64_t; | ||
202 | typedef unsigned __int32 uint32_t; | ||
203 | typedef unsigned __int16 uint16_t; | ||
204 | typedef unsigned __int8 uint8_t; | ||
205 | typedef __int64 int64_t; | ||
206 | typedef __int32 int32_t; | ||
207 | typedef __int16 int16_t; | ||
208 | typedef __int8 int8_t; | ||
209 | typedef float float32_t; | ||
210 | |||
211 | |||
212 | #else | ||
213 | |||
214 | #include <stdio.h> | ||
215 | #ifdef HAVE_SYS_TYPES_H | ||
216 | # include "inttypes.h" | ||
217 | #endif | ||
218 | #ifdef HAVE_SYS_STAT_H | ||
219 | # include <sys/stat.h> | ||
220 | #endif | ||
221 | #ifdef STDC_HEADERS | ||
222 | # include <stdlib.h> | ||
223 | # include <stddef.h> | ||
224 | #else | ||
225 | # ifdef HAVE_STDLIB_H | ||
226 | # include <stdlib.h> | ||
227 | # endif | ||
228 | #endif | ||
229 | #ifdef HAVE_STRING_H | ||
230 | # if !defined(STDC_HEADERS) && defined(HAVE_MEMORY_H) | ||
231 | # include <memory.h> | ||
232 | # endif | ||
233 | //# include <string.h> | ||
234 | #endif | ||
235 | #ifdef HAVE_STRINGS_H | ||
236 | //# include <strings.h> | ||
237 | #endif | ||
238 | #ifdef HAVE_INTTYPES_H | ||
239 | # include <inttypes.h> | ||
240 | #else | ||
241 | # ifdef HAVE_STDINT_H | ||
242 | # include <stdint.h> | ||
243 | # else | ||
244 | /* we need these... */ | ||
245 | typedef unsigned long long uint64_t; | ||
246 | typedef unsigned long uint32_t; | ||
247 | typedef unsigned short uint16_t; | ||
248 | typedef unsigned char uint8_t; | ||
249 | typedef long long int64_t; | ||
250 | typedef long int32_t; | ||
251 | typedef short int16_t; | ||
252 | typedef char int8_t; | ||
253 | # endif | ||
254 | #endif | ||
255 | #ifdef HAVE_UNISTD_H | ||
256 | # include <unistd.h> | ||
257 | #endif | ||
258 | |||
259 | #ifndef HAVE_FLOAT32_T | ||
260 | typedef float float32_t; | ||
261 | #endif | ||
262 | |||
263 | #if STDC_HEADERS | ||
264 | //# include <string.h> | ||
265 | #else | ||
266 | # if !HAVE_STRCHR | ||
267 | # define strchr index | ||
268 | # define strrchr rindex | ||
269 | # endif | ||
270 | char *strchr(), *strrchr(); | ||
271 | # if !HAVE_MEMCPY | ||
272 | # define memcpy(d, s, n) bcopy((s), (d), (n)) | ||
273 | # define memmove(d, s, n) bcopy((s), (d), (n)) | ||
274 | # endif | ||
275 | #endif | ||
276 | |||
277 | #endif | ||
278 | |||
279 | #ifdef WORDS_BIGENDIAN | ||
280 | #define ARCH_IS_BIG_ENDIAN | ||
281 | #endif | ||
282 | |||
283 | /* FIXED_POINT doesn't work with MAIN and SSR yet */ | ||
284 | #ifdef FIXED_POINT | ||
285 | #undef MAIN_DEC | ||
286 | #undef SSR_DEC | ||
287 | #endif | ||
288 | |||
289 | |||
290 | #if defined(FIXED_POINT) | ||
291 | |||
292 | #include "fixed.h" | ||
293 | |||
294 | #elif defined(USE_DOUBLE_PRECISION) | ||
295 | |||
296 | typedef double real_t; | ||
297 | |||
298 | #include <math.h> | ||
299 | |||
300 | #define MUL_R(A,B) ((A)*(B)) | ||
301 | #define MUL_C(A,B) ((A)*(B)) | ||
302 | #define MUL_F(A,B) ((A)*(B)) | ||
303 | #define MUL_Q2(A,B) ((A)*(B)) | ||
304 | |||
305 | /* Complex multiplication */ | ||
306 | static INLINE void ComplexMult(real_t *y1, real_t *y2, | ||
307 | real_t x1, real_t x2, real_t c1, real_t c2) | ||
308 | { | ||
309 | *y1 = MUL_F(x1, c1) + MUL_F(x2, c2); | ||
310 | *y2 = MUL_F(x2, c1) - MUL_F(x1, c2); | ||
311 | } | ||
312 | |||
313 | #define REAL_CONST(A) ((real_t)(A)) | ||
314 | #define COEF_CONST(A) ((real_t)(A)) | ||
315 | #define Q2_CONST(A) ((real_t)(A)) | ||
316 | #define FRAC_CONST(A) ((real_t)(A)) /* pure fractional part */ | ||
317 | |||
318 | #else /* Normal floating point operation */ | ||
319 | |||
320 | typedef float real_t; | ||
321 | |||
322 | #define MUL_R(A,B) ((A)*(B)) | ||
323 | #define MUL_C(A,B) ((A)*(B)) | ||
324 | #define MUL_F(A,B) ((A)*(B)) | ||
325 | #define MUL_Q2(A,B) ((A)*(B)) | ||
326 | |||
327 | #define REAL_CONST(A) ((real_t)(A)) | ||
328 | #define COEF_CONST(A) ((real_t)(A)) | ||
329 | #define Q2_CONST(A) ((real_t)(A)) | ||
330 | #define FRAC_CONST(A) ((real_t)(A)) /* pure fractional part */ | ||
331 | |||
332 | /* Complex multiplication */ | ||
333 | static INLINE void ComplexMult(real_t *y1, real_t *y2, | ||
334 | real_t x1, real_t x2, real_t c1, real_t c2) | ||
335 | { | ||
336 | *y1 = MUL_F(x1, c1) + MUL_F(x2, c2); | ||
337 | *y2 = MUL_F(x2, c1) - MUL_F(x1, c2); | ||
338 | } | ||
339 | |||
340 | /* rockbox: must be commented to build for non-FP | ||
341 | #if defined(_WIN32) && !defined(__MINGW32__) | ||
342 | #define HAS_LRINTF | ||
343 | static INLINE int lrintf(float f) | ||
344 | { | ||
345 | int i; | ||
346 | __asm | ||
347 | { | ||
348 | fld f | ||
349 | fistp i | ||
350 | } | ||
351 | return i; | ||
352 | } | ||
353 | #elif (defined(__i386__) && defined(__GNUC__)) | ||
354 | #define HAS_LRINTF | ||
355 | // from http://www.stereopsis.com/FPU.html | ||
356 | static INLINE int lrintf(float f) | ||
357 | { | ||
358 | int i; | ||
359 | __asm__ __volatile__ ( | ||
360 | "flds %1 \n\t" | ||
361 | "fistpl %0 \n\t" | ||
362 | : "=m" (i) | ||
363 | : "m" (f)); | ||
364 | return i; | ||
365 | } | ||
366 | #endif | ||
367 | */ | ||
368 | |||
369 | #ifdef __ICL /* only Intel C compiler has fmath ??? */ | ||
370 | |||
371 | #include <mathf.h> | ||
372 | |||
373 | #define sin sinf | ||
374 | #define cos cosf | ||
375 | #define log logf | ||
376 | #define floor floorf | ||
377 | #define ceil ceilf | ||
378 | #define sqrt sqrtf | ||
379 | |||
380 | #else | ||
381 | |||
382 | #ifdef HAVE_LRINTF | ||
383 | # define HAS_LRINTF | ||
384 | # define _ISOC9X_SOURCE 1 | ||
385 | # define _ISOC99_SOURCE 1 | ||
386 | # define __USE_ISOC9X 1 | ||
387 | # define __USE_ISOC99 1 | ||
388 | #endif | ||
389 | |||
390 | #include <math.h> | ||
391 | |||
392 | #ifdef HAVE_SINF | ||
393 | # define sin sinf | ||
394 | #error | ||
395 | #endif | ||
396 | #ifdef HAVE_COSF | ||
397 | # define cos cosf | ||
398 | #endif | ||
399 | #ifdef HAVE_LOGF | ||
400 | # define log logf | ||
401 | #endif | ||
402 | #ifdef HAVE_EXPF | ||
403 | # define exp expf | ||
404 | #endif | ||
405 | #ifdef HAVE_FLOORF | ||
406 | # define floor floorf | ||
407 | #endif | ||
408 | #ifdef HAVE_CEILF | ||
409 | # define ceil ceilf | ||
410 | #endif | ||
411 | #ifdef HAVE_SQRTF | ||
412 | # define sqrt sqrtf | ||
413 | #endif | ||
414 | |||
415 | #endif | ||
416 | |||
417 | #endif | ||
418 | |||
419 | #ifndef HAS_LRINTF | ||
420 | /* standard cast */ | ||
421 | #define lrintf(f) ((int32_t)(f)) | ||
422 | #endif | ||
423 | |||
424 | typedef real_t complex_t[2]; | ||
425 | #define RE(A) A[0] | ||
426 | #define IM(A) A[1] | ||
427 | |||
428 | |||
429 | /* common functions */ | ||
430 | uint8_t cpu_has_sse(void); | ||
431 | uint32_t random_int(void); | ||
432 | #define wl_min_lzc(x) bs_generic(x, BS_LOG2|BS_0_0) | ||
433 | #ifdef FIXED_POINT | ||
434 | #define LOG2_MIN_INF REAL_CONST(-10000) | ||
435 | int32_t log2_int(uint32_t val); | ||
436 | int32_t log2_fix(uint32_t val); | ||
437 | uint32_t pow2_int(real_t val); | ||
438 | uint32_t pow2_fix(real_t val); | ||
439 | #endif | ||
440 | uint8_t get_sr_index(const uint32_t samplerate); | ||
441 | uint8_t max_pred_sfb(const uint8_t sr_index); | ||
442 | uint8_t max_tns_sfb(const uint8_t sr_index, const uint8_t object_type, | ||
443 | const uint8_t is_short); | ||
444 | uint32_t get_sample_rate(const uint8_t sr_index); | ||
445 | int8_t can_decode_ot(const uint8_t object_type); | ||
446 | |||
447 | #ifndef FAAD_STATIC_ALLOC | ||
448 | /* Those should not be defined or used anymore */ | ||
449 | #define faad_malloc(A) malloc(A) | ||
450 | #define faad_free(A) free(A) | ||
451 | #endif | ||
452 | |||
453 | //#define PROFILE | ||
454 | #ifdef PROFILE | ||
455 | static int64_t faad_get_ts() | ||
456 | { | ||
457 | __asm | ||
458 | { | ||
459 | rdtsc | ||
460 | } | ||
461 | } | ||
462 | #endif | ||
463 | |||
464 | #ifndef M_PI | ||
465 | #define M_PI 3.14159265358979323846 | ||
466 | #endif | ||
467 | #ifndef M_PI_2 /* PI/2 */ | ||
468 | #define M_PI_2 1.57079632679489661923 | ||
469 | #endif | ||
470 | |||
471 | |||
472 | #ifdef __cplusplus | ||
473 | } | ||
474 | #endif | ||
475 | #endif | ||