2 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
3 ** Copyright (C) 2003-2004 M. Bakker, Ahead Software 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 ** Commercial non-GPL licensing of this software is possible.
23 ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
25 ** Initially modified for use with MPlayer by Arpad Gereöffy on 2003/08/30
27 ** detailed CVS changelog at http://www.mplayerhq.hu/cgi-bin/cvsweb.cgi/main/
28 ** local_changes.diff contains the exact changes to this file.
38 /* Allow build on Cygwin*/
39 #if defined(__CYGWIN__)
40 #define __STRICT_ANSI__
43 #include "../config.h"
45 #define INLINE __inline
46 #if 0 //defined(_WIN32) && !defined(_WIN32_WCE)
47 #define ALIGN __declspec(align(16))
53 #define max(a, b) (((a) > (b)) ? (a) : (b))
56 #define min(a, b) (((a) < (b)) ? (a) : (b))
59 /* COMPILE TIME DEFINITIONS */
61 /* use double precision */
62 /* #define USE_DOUBLE_PRECISION */
63 /* use fixed point reals */
65 //#define BIG_IQ_TABLE
67 /* Use if target platform has address generators with autoincrement */
68 //#define PREFER_POINTERS
75 #define ERROR_RESILIENCE
78 /* Allow decoding of MAIN profile AAC */
80 /* Allow decoding of SSR profile AAC */
82 /* Allow decoding of LTP profile AAC */
84 /* Allow decoding of LD profile AAC */
86 /* Allow decoding of scalable profiles */
87 //#define SCALABLE_DEC
88 /* Allow decoding of Digital Radio Mondiale (DRM) */
92 /* LD can't do without LTP */
94 #ifndef ERROR_RESILIENCE
95 #define ERROR_RESILIENCE
102 #define ALLOW_SMALL_FRAMELENGTH
105 // Define LC_ONLY_DECODER if you want a pure AAC LC decoder (independant of SBR_DEC and PS_DEC)
106 //#define LC_ONLY_DECODER
107 #ifdef LC_ONLY_DECODER
113 #undef ALLOW_SMALL_FRAMELENGTH
114 #undef ERROR_RESILIENCE
118 //#define SBR_LOW_POWER
121 /* FIXED POINT: No MAIN decoding */
129 #endif // FIXED_POINT
132 # ifndef SCALABLE_DEC
133 # define SCALABLE_DEC
137 #if ((defined(_WIN32) && !defined(_WIN32_WCE)) /* || ((__GNUC__ >= 3) && defined(__i386__)) */ )
139 /* includes <xmmintrin.h> to enable SSE intrinsics */
145 #define DIV_R(A, B) (((int64_t)A << REAL_BITS)/B)
146 #define DIV_C(A, B) (((int64_t)A << COEF_BITS)/B)
148 #define DIV_R(A, B) ((A)/(B))
149 #define DIV_C(A, B) ((A)/(B))
152 #ifndef SBR_LOW_POWER
153 #define qmf_t complex_t
154 #define QMF_RE(A) RE(A)
155 #define QMF_IM(A) IM(A)
158 #define QMF_RE(A) (A)
163 /* END COMPILE TIME DEFINITIONS */
165 #if defined(_WIN32) && !defined(__MINGW32__)
170 typedef unsigned __int64
uint64_t;
171 typedef unsigned __int32
uint32_t;
172 typedef unsigned __int16
uint16_t;
173 typedef unsigned __int8
uint8_t;
174 typedef __int64
int64_t;
175 typedef __int32
int32_t;
176 typedef __int16
int16_t;
177 typedef __int8
int8_t;
179 #include <inttypes.h>
182 typedef float float32_t
;
187 /* #undef HAVE_FLOAT32_T */
188 /* Define if you have the <inttypes.h> header file. */
189 #define HAVE_INTTYPES_H 1
191 /* Define if you have the `memcpy' function. */
192 #define HAVE_MEMCPY 1
194 /* Define if you have the <stdint.h> header file. */
195 #define HAVE_STDINT_H 1
197 /* Define if you have the `strchr' function. */
198 #define HAVE_STRCHR 1
200 /* Define if you have the ANSI C header files. */
201 #define STDC_HEADERS 1
205 # include <sys/types.h>
208 # include <sys/stat.h>
219 # if !STDC_HEADERS && HAVE_MEMORY_H
225 # include <strings.h>
228 # include <inttypes.h>
233 /* we need these... */
234 typedef unsigned long long uint64_t;
235 typedef unsigned long uint32_t;
236 typedef unsigned short uint16_t;
237 typedef unsigned char uint8_t;
238 typedef long long int64_t;
239 typedef long int32_t;
240 typedef short int16_t;
248 #ifndef HAVE_FLOAT32_T
249 typedef float float32_t
;
256 # define strchr index
257 # define strrchr rindex
259 char *strchr(), *strrchr();
261 # define memcpy(d, s, n) bcopy((s), (d), (n))
262 # define memmove(d, s, n) bcopy((s), (d), (n))
268 #ifdef WORDS_BIGENDIAN
269 #define ARCH_IS_BIG_ENDIAN
272 /* FIXED_POINT doesn't work with MAIN and SSR yet */
279 #if defined(FIXED_POINT)
283 #elif defined(USE_DOUBLE_PRECISION)
285 typedef double real_t
;
289 #define MUL_R(A,B) ((A)*(B))
290 #define MUL_C(A,B) ((A)*(B))
291 #define MUL_F(A,B) ((A)*(B))
293 /* Complex multiplication */
294 static INLINE
void ComplexMult(real_t
*y1
, real_t
*y2
,
295 real_t x1
, real_t x2
, real_t c1
, real_t c2
)
297 *y1
= MUL_F(x1
, c1
) + MUL_F(x2
, c2
);
298 *y2
= MUL_F(x2
, c1
) - MUL_F(x1
, c2
);
301 #define REAL_CONST(A) ((real_t)(A))
302 #define COEF_CONST(A) ((real_t)(A))
303 #define Q2_CONST(A) ((real_t)(A))
304 #define FRAC_CONST(A) ((real_t)(A)) /* pure fractional part */
306 #else /* Normal floating point operation */
308 typedef float real_t
;
311 # include <xmmintrin.h>
314 #define MUL_R(A,B) ((A)*(B))
315 #define MUL_C(A,B) ((A)*(B))
316 #define MUL_F(A,B) ((A)*(B))
318 #define REAL_CONST(A) ((real_t)(A))
319 #define COEF_CONST(A) ((real_t)(A))
320 #define Q2_CONST(A) ((real_t)(A))
321 #define FRAC_CONST(A) ((real_t)(A)) /* pure fractional part */
323 /* Complex multiplication */
324 static INLINE
void ComplexMult(real_t
*y1
, real_t
*y2
,
325 real_t x1
, real_t x2
, real_t c1
, real_t c2
)
327 *y1
= MUL_F(x1
, c1
) + MUL_F(x2
, c2
);
328 *y2
= MUL_F(x2
, c1
) - MUL_F(x1
, c2
);
332 #if defined(_WIN32) && !defined(__MINGW32__) && !defined(HAVE_LRINTF)
334 static INLINE
int lrintf(float f
)
344 #elif (defined(__i386__) && defined(__GNUC__)) && !defined(__MINGW32__) && !defined(HAVE_LRINTF)
346 // from http://www.stereopsis.com/FPU.html
347 static INLINE
int lrintf(float f
)
350 __asm__
__volatile__ (
360 #ifdef __ICL /* only Intel C compiler has fmath ??? */
377 # define _ISOC9X_SOURCE 1
378 # define _ISOC99_SOURCE 1
379 # define __USE_ISOC9X 1
380 # define __USE_ISOC99 1
397 # define floor floorf
412 #define lrintf(f) ((int32_t)(f))
415 typedef real_t complex_t
[2];
420 /* common functions */
421 uint8_t cpu_has_sse(void);
422 uint32_t random_int(void);
423 uint32_t ones32(uint32_t x
);
424 uint32_t floor_log2(uint32_t x
);
425 uint32_t wl_min_lzc(uint32_t x
);
427 #define LOG2_MIN_INF REAL_CONST(-10000)
428 int32_t log2_int(uint32_t val
);
429 int32_t pow2_int(real_t val
);
430 real_t
pow2_fix(real_t val
);
432 uint8_t get_sr_index(const uint32_t samplerate
);
433 uint8_t max_pred_sfb(const uint8_t sr_index
);
434 uint8_t max_tns_sfb(const uint8_t sr_index
, const uint8_t object_type
,
435 const uint8_t is_short
);
436 uint32_t get_sample_rate(const uint8_t sr_index
);
437 int8_t can_decode_ot(const uint8_t object_type
);
439 void *faad_malloc(size_t size
);
440 void faad_free(void *b
);
444 static int64_t faad_get_ts()
454 #define M_PI 3.14159265358979323846
456 #ifndef M_PI_2 /* PI/2 */
457 #define M_PI_2 1.57079632679489661923