2 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
3 ** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
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.
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
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"
25 ** Commercial non-GPL licensing of this software is possible.
26 ** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
28 ** $Id: common.h,v 1.77 2009/02/05 00:51:03 menno Exp $
45 #define INLINE __inline
50 #if 0 //defined(_WIN32) && !defined(_WIN32_WCE)
51 #define ALIGN __declspec(align(16))
57 #define max(a, b) (((a) > (b)) ? (a) : (b))
60 #define min(a, b) (((a) < (b)) ? (a) : (b))
63 /* COMPILE TIME DEFINITIONS */
65 /* use double precision */
66 /* #define USE_DOUBLE_PRECISION */
67 /* use fixed point reals */
69 //#define BIG_IQ_TABLE
71 /* Use if target platform has address generators with autoincrement */
72 //#define PREFER_POINTERS
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.
79 * Note that the fixed point implementation seems to be even
93 #define ERROR_RESILIENCE
96 /* Allow decoding of MAIN profile AAC */
98 /* Allow decoding of SSR profile AAC */
100 /* Allow decoding of LTP profile AAC */
102 /* Allow decoding of LD profile AAC */
104 /* Allow decoding of Digital Radio Mondiale (DRM) */
108 /* LD can't do without LTP */
110 #ifndef ERROR_RESILIENCE
111 #define ERROR_RESILIENCE
118 #define ALLOW_SMALL_FRAMELENGTH
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
129 #undef ALLOW_SMALL_FRAMELENGTH
130 #undef ERROR_RESILIENCE
134 //#define SBR_LOW_POWER
141 /* FIXED POINT: No MAIN decoding */
146 #endif // FIXED_POINT
149 # ifndef ALLOW_SMALL_FRAMELENGTH
150 # define ALLOW_SMALL_FRAMELENGTH
160 #define DIV_R(A, B) (((int64_t)A << REAL_BITS)/B)
161 #define DIV_C(A, B) (((int64_t)A << COEF_BITS)/B)
163 #define DIV_R(A, B) ((A)/(B))
164 #define DIV_C(A, B) ((A)/(B))
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)
173 #define QMF_RE(A) (A)
178 /* END COMPILE TIME DEFINITIONS */
180 #if defined(_WIN32) && !defined(__MINGW32__)
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;
199 # include <sys/types.h>
202 # include <sys/stat.h>
213 # if !STDC_HEADERS && HAVE_MEMORY_H
219 # include <strings.h>
222 # include <inttypes.h>
227 /* we need these... */
229 typedef unsigned long long uint64_t;
230 typedef signed long long int64_t;
232 typedef unsigned long uint64_t;
233 typedef signed long int64_t;
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;
244 //# include <unistd.h>
247 #ifndef HAVE_FLOAT32_T
248 typedef float float32_t;
255 # define strchr index
256 # define strrchr rindex
258 char *strchr(), *strrchr();
260 # define memcpy(d, s, n) bcopy((s), (d), (n))
261 # define memmove(d, s, n) bcopy((s), (d), (n))
267 #ifdef WORDS_BIGENDIAN
268 #define ARCH_IS_BIG_ENDIAN
271 /* FIXED_POINT doesn't work with MAIN and SSR yet */
278 #if defined(FIXED_POINT)
282 #elif defined(USE_DOUBLE_PRECISION)
284 typedef double real_t;
288 #define MUL_R(A,B) ((A)*(B))
289 #define MUL_C(A,B) ((A)*(B))
290 #define MUL_F(A,B) ((A)*(B))
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)
296 *y1 = MUL_F(x1, c1) + MUL_F(x2, c2);
297 *y2 = MUL_F(x2, c1) - MUL_F(x1, c2);
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 */
305 #else /* Normal floating point operation */
307 typedef float real_t;
309 #define MUL_R(A,B) ((A)*(B))
310 #define MUL_C(A,B) ((A)*(B))
311 #define MUL_F(A,B) ((A)*(B))
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 */
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)
322 *y1 = MUL_F(x1, c1) + MUL_F(x2, c2);
323 *y2 = MUL_F(x2, c1) - MUL_F(x1, c2);
327 #if defined(_WIN32) && !defined(__MINGW32__)
329 static INLINE int lrintf(float f)
339 #elif (defined(__i386__) && defined(__GNUC__) && \
340 !defined(__CYGWIN__) && !defined(__MINGW32__))
343 // from http://www.stereopsis.com/FPU.html
344 static INLINE int lrintf(float f)
347 __asm__ __volatile__ (
354 #endif /* HAVE_LRINTF */
358 #ifdef __ICL /* only Intel C compiler has fmath ??? */
373 # define _ISOC9X_SOURCE 1
374 # define _ISOC99_SOURCE 1
375 # define __USE_ISOC9X 1
376 # define __USE_ISOC99 1
395 # define floor floorf
410 #define lrintf(f) ((int32_t)(f))
413 typedef real_t complex_t[2];
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);
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);
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);
436 void *faad_malloc(size_t size);
437 void faad_free(void *b);
441 static int64_t faad_get_ts()
451 #define M_PI 3.14159265358979323846
453 #ifndef M_PI_2 /* PI/2 */
454 #define M_PI_2 1.57079632679489661923