comparison libfaad2/common.h @ 12527:4a370c80fe5c

update to the 2.0 release of faad, patch by adland
author diego
date Wed, 02 Jun 2004 22:59:04 +0000
parents 3185f64f6350
children d81145997036
comparison
equal deleted inserted replaced
12526:e183ad37d24c 12527:4a370c80fe5c
1 /* 1 /*
2 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding 2 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
3 ** Copyright (C) 2003 M. Bakker, Ahead Software AG, http://www.nero.com 3 ** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
4 ** 4 **
5 ** This program is free software; you can redistribute it and/or modify 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 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 7 ** the Free Software Foundation; either version 2 of the License, or
8 ** (at your option) any later version. 8 ** (at your option) any later version.
9 ** 9 **
10 ** This program is distributed in the hope that it will be useful, 10 ** This program is distributed in the hope that it will be useful,
11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ** GNU General Public License for more details. 13 ** GNU General Public License for more details.
14 ** 14 **
15 ** You should have received a copy of the GNU General Public License 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 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. 17 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 ** 18 **
19 ** Any non-GPL usage of this software or parts of this software is strictly 19 ** Any non-GPL usage of this software or parts of this software is strictly
20 ** forbidden. 20 ** forbidden.
21 ** 21 **
30 30
31 #ifdef __cplusplus 31 #ifdef __cplusplus
32 extern "C" { 32 extern "C" {
33 #endif 33 #endif
34 34
35 # include "../config.h" 35 /* Allow build on cygwin*/
36 #if defined(__CYGWIN__)
37 #define __STRICT_ANSI__
38 #endif
36 39
37 #define INLINE __inline 40 #define INLINE __inline
41 #if defined(_WIN32) && !defined(_WIN32_WCE)
42 #define ALIGN __declspec(align(16))
43 #else
44 #define ALIGN
45 #endif
38 46
39 #ifndef max 47 #ifndef max
40 #define max(a, b) (((a) > (b)) ? (a) : (b)) 48 #define max(a, b) (((a) > (b)) ? (a) : (b))
41 #endif 49 #endif
42 #ifndef min 50 #ifndef min
43 #define min(a, b) (((a) < (b)) ? (a) : (b)) 51 #define min(a, b) (((a) < (b)) ? (a) : (b))
44 #endif 52 #endif
45
46 53
47 /* COMPILE TIME DEFINITIONS */ 54 /* COMPILE TIME DEFINITIONS */
48 55
49 /* use double precision */ 56 /* use double precision */
50 /* #define USE_DOUBLE_PRECISION */ 57 /* #define USE_DOUBLE_PRECISION */
51 /* use fixed point reals */ 58 /* use fixed point reals */
52 //#define FIXED_POINT 59 //#define FIXED_POINT
60
61 #ifdef _WIN32_WCE
62 #define FIXED_POINT
63 #endif
64
53 65
54 #define ERROR_RESILIENCE 66 #define ERROR_RESILIENCE
55 67
56 68
57 /* Allow decoding of MAIN profile AAC */ 69 /* Allow decoding of MAIN profile AAC */
60 //#define SSR_DEC 72 //#define SSR_DEC
61 /* Allow decoding of LTP profile AAC */ 73 /* Allow decoding of LTP profile AAC */
62 #define LTP_DEC 74 #define LTP_DEC
63 /* Allow decoding of LD profile AAC */ 75 /* Allow decoding of LD profile AAC */
64 #define LD_DEC 76 #define LD_DEC
77 /* Allow decoding of scalable profiles */
78 //#define SCALABLE_DEC
79 /* Allow decoding of Digital Radio Mondiale (DRM) */
80 //#define DRM
81 //#define DRM_PS
65 82
66 /* LD can't do without LTP */ 83 /* LD can't do without LTP */
67 #ifdef LD_DEC 84 #ifdef LD_DEC
68 #ifndef ERROR_RESILIENCE 85 #ifndef ERROR_RESILIENCE
69 #define ERROR_RESILIENCE 86 #define ERROR_RESILIENCE
71 #ifndef LTP_DEC 88 #ifndef LTP_DEC
72 #define LTP_DEC 89 #define LTP_DEC
73 #endif 90 #endif
74 #endif 91 #endif
75 92
93 #define ALLOW_SMALL_FRAMELENGTH
94
95
96 // Define LC_ONLY_DECODER if you want a pure AAC LC decoder (independant of SBR_DEC)
97 //#define LC_ONLY_DECODER
98 #ifdef LC_ONLY_DECODER
99 #undef LTP_DEC
100 #undef MAIN_DEC
101 #undef SSR_DEC
102 #undef DRM
103 #undef ALLOW_SMALL_FRAMELENGTH
104 #undef ERROR_RESILIENCE
105 #endif
76 106
77 #define SBR_DEC 107 #define SBR_DEC
78 //#define SBR_LOW_POWER 108 //#define SBR_LOW_POWER
79 109 //#define PS_DEC
110
111 /* FIXED POINT: No MAIN decoding, no SBR decoding */
80 #ifdef FIXED_POINT 112 #ifdef FIXED_POINT
81 #ifndef SBR_LOW_POWER 113 # ifdef MAIN_DEC
82 #define SBR_LOW_POWER 114 # undef MAIN_DEC
115 # endif
116 //# ifndef SBR_LOW_POWER
117 //# define SBR_LOW_POWER
118 //# endif
119 # ifdef SBR_DEC
120 # undef SBR_DEC
121 # endif
122 #endif // FIXED_POINT
123
124 #ifdef DRM
125 # ifndef SCALABLE_DEC
126 # define SCALABLE_DEC
127 # endif
128 #endif
129
130 #if ((defined(_WIN32) && !defined(_WIN32_WCE)) /* || ((__GNUC__ >= 3) && defined(__i386__)) */ )
131 #ifndef FIXED_POINT
132 /* includes <xmmintrin.h> to enable SSE intrinsics */
133 //#define USE_SSE
83 #endif 134 #endif
84 #endif 135 #endif
85 136
86 #ifdef FIXED_POINT 137 #ifdef FIXED_POINT
87 #define SBR_DIV(A, B) (((int64_t)A << REAL_BITS)/B) 138 #define SBR_DIV(A, B) (((int64_t)A << REAL_BITS)/B)
94 #define QMF_RE(A) RE(A) 145 #define QMF_RE(A) RE(A)
95 #define QMF_IM(A) IM(A) 146 #define QMF_IM(A) IM(A)
96 #else 147 #else
97 #define qmf_t real_t 148 #define qmf_t real_t
98 #define QMF_RE(A) (A) 149 #define QMF_RE(A) (A)
99 #define QMF_IM(A) 0 150 #define QMF_IM(A)
100 #endif 151 #endif
101 152
102 153
103 /* END COMPILE TIME DEFINITIONS */ 154 /* END COMPILE TIME DEFINITIONS */
104
105 #ifndef FIXED_POINT
106 #define POW_TABLE_SIZE 200
107 #endif
108
109 155
110 #if defined(_WIN32) 156 #if defined(_WIN32)
111 157
112 #if 0 158 #if 0
113 typedef unsigned __int64 uint64_t; 159 typedef unsigned __int64 uint64_t;
123 #endif 169 #endif
124 typedef float float32_t; 170 typedef float float32_t;
125 171
126 172
127 #else 173 #else
128
129 /* Define if needed */ 174 /* Define if needed */
175
130 /* #undef HAVE_FLOAT32_T */ 176 /* #undef HAVE_FLOAT32_T */
131
132 /* Define if you have the <inttypes.h> header file. */ 177 /* Define if you have the <inttypes.h> header file. */
133 #define HAVE_INTTYPES_H 1 178 #define HAVE_INTTYPES_H 1
134 179
135 /* Define if you have the `memcpy' function. */ 180 /* Define if you have the `memcpy' function. */
136 #define HAVE_MEMCPY 1 181 #define HAVE_MEMCPY 1
142 #define HAVE_STRCHR 1 187 #define HAVE_STRCHR 1
143 188
144 /* Define if you have the ANSI C header files. */ 189 /* Define if you have the ANSI C header files. */
145 #define STDC_HEADERS 1 190 #define STDC_HEADERS 1
146 191
147 192 #ifdef HAVE_CONFIG_H
193 # include "../config.h"
194 #endif
148 195
149 #include <stdio.h> 196 #include <stdio.h>
150 #if HAVE_SYS_TYPES_H 197 #if HAVE_SYS_TYPES_H
151 # include <sys/types.h> 198 # include <sys/types.h>
152 #endif 199 #endif
222 #endif 269 #endif
223 270
224 271
225 #if defined(FIXED_POINT) 272 #if defined(FIXED_POINT)
226 273
227 #ifdef HAS_MATHF_H
228 #include <mathf.h>
229 #else
230 #include <math.h>
231 #endif
232
233 #include "fixed.h" 274 #include "fixed.h"
234 275
235 #elif defined(USE_DOUBLE_PRECISION) 276 #elif defined(USE_DOUBLE_PRECISION)
236 277
237 typedef double real_t; 278 typedef double real_t;
238 279
239 #include <math.h> 280 #include <math.h>
240 281
241 #define MUL(A,B) ((A)*(B)) 282 #define MUL_R(A,B) ((A)*(B))
242 #define MUL_C_C(A,B) ((A)*(B)) 283 #define MUL_C(A,B) ((A)*(B))
243 #define MUL_R_C(A,B) ((A)*(B)) 284 #define MUL_F(A,B) ((A)*(B))
285
286 /* Complex multiplication */
287 static INLINE void ComplexMult(real_t *y1, real_t *y2,
288 real_t x1, real_t x2, real_t c1, real_t c2)
289 {
290 *y1 = MUL_F(x1, c1) + MUL_F(x2, c2);
291 *y2 = MUL_F(x2, c1) - MUL_F(x1, c2);
292 }
244 293
245 #define REAL_CONST(A) ((real_t)(A)) 294 #define REAL_CONST(A) ((real_t)(A))
246 #define COEF_CONST(A) ((real_t)(A)) 295 #define COEF_CONST(A) ((real_t)(A))
296 #define FRAC_CONST(A) ((real_t)(A)) /* pure fractional part */
247 297
248 #else /* Normal floating point operation */ 298 #else /* Normal floating point operation */
249 299
250 typedef float real_t; 300 typedef float real_t;
251 301
252 #define MUL(A,B) ((A)*(B)) 302 #ifdef USE_SSE
253 #define MUL_C_C(A,B) ((A)*(B)) 303 # include <xmmintrin.h>
254 #define MUL_R_C(A,B) ((A)*(B)) 304 #endif
305
306 #define MUL_R(A,B) ((A)*(B))
307 #define MUL_C(A,B) ((A)*(B))
308 #define MUL_F(A,B) ((A)*(B))
255 309
256 #define REAL_CONST(A) ((real_t)(A)) 310 #define REAL_CONST(A) ((real_t)(A))
257 #define COEF_CONST(A) ((real_t)(A)) 311 #define COEF_CONST(A) ((real_t)(A))
312 #define FRAC_CONST(A) ((real_t)(A)) /* pure fractional part */
313
314 /* Complex multiplication */
315 static INLINE void ComplexMult(real_t *y1, real_t *y2,
316 real_t x1, real_t x2, real_t c1, real_t c2)
317 {
318 *y1 = MUL_F(x1, c1) + MUL_F(x2, c2);
319 *y2 = MUL_F(x2, c1) - MUL_F(x1, c2);
320 }
321
322
323 #if defined(_WIN32) && !defined(__MINGW32__)
324 #define HAS_LRINTF
325 static INLINE int lrintf(float f)
326 {
327 int i;
328 __asm
329 {
330 fld f
331 fistp i
332 }
333 return i;
334 }
335 #elif (defined(__i386__) && defined(__GNUC__)) && !defined(__MINGW32__)
336 #define HAS_LRINTF
337 // from http://www.stereopsis.com/FPU.html
338 static INLINE int lrintf(float f)
339 {
340 int i;
341 __asm__ __volatile__ (
342 "flds %1 \n\t"
343 "fistpl %0 \n\t"
344 : "=m" (i)
345 : "m" (f));
346 return i;
347 }
348 #endif
349
258 350
259 #ifdef __ICL /* only Intel C compiler has fmath ??? */ 351 #ifdef __ICL /* only Intel C compiler has fmath ??? */
260 352
261 #include <mathf.h> 353 #include <mathf.h>
262 354
267 #define ceil ceilf 359 #define ceil ceilf
268 #define sqrt sqrtf 360 #define sqrt sqrtf
269 361
270 #else 362 #else
271 363
364 #ifdef HAVE_LRINTF
365 # define HAS_LRINTF
366 # define _ISOC9X_SOURCE 1
367 # define _ISOC99_SOURCE 1
368 # define __USE_ISOC9X 1
369 # define __USE_ISOC99 1
370 #endif
371
272 #include <math.h> 372 #include <math.h>
273 373
274 #ifdef HAVE_SINF 374 #ifdef HAVE_SINF
275 # define sin sinf 375 # define sin sinf
276 #error 376 #error
296 396
297 #endif 397 #endif
298 398
299 #endif 399 #endif
300 400
401 #ifndef HAS_LRINTF
402 /* standard cast */
403 #define lrintf(f) ((int32_t)(f))
404 #endif
405
301 typedef real_t complex_t[2]; 406 typedef real_t complex_t[2];
302 #define RE(A) A[0] 407 #define RE(A) A[0]
303 #define IM(A) A[1] 408 #define IM(A) A[1]
304 409
305 410
306 /* common functions */ 411 /* common functions */
307 int32_t int_log2(int32_t val); 412 uint8_t cpu_has_sse(void);
308 uint32_t random_int(void); 413 uint32_t random_int(void);
309 uint8_t get_sr_index(uint32_t samplerate); 414 uint8_t get_sr_index(const uint32_t samplerate);
310 uint32_t get_sample_rate(uint8_t sr_index); 415 uint8_t max_pred_sfb(const uint8_t sr_index);
311 int8_t can_decode_ot(uint8_t object_type); 416 uint8_t max_tns_sfb(const uint8_t sr_index, const uint8_t object_type,
417 const uint8_t is_short);
418 uint32_t get_sample_rate(const uint8_t sr_index);
419 int8_t can_decode_ot(const uint8_t object_type);
420
421 void *faad_malloc(int32_t size);
422 void faad_free(void *b);
423
424 //#define PROFILE
425 #ifdef PROFILE
426 static int64_t faad_get_ts()
427 {
428 __asm
429 {
430 rdtsc
431 }
432 }
433 #endif
312 434
313 #ifndef M_PI 435 #ifndef M_PI
314 #define M_PI 3.14159265358979323846f 436 #define M_PI 3.14159265358979323846
315 #endif 437 #endif
316 #ifndef M_PI_2 /* PI/2 */ 438 #ifndef M_PI_2 /* PI/2 */
317 #define M_PI_2 1.57079632679489661923 439 #define M_PI_2 1.57079632679489661923
318 #endif 440 #endif
319 441