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