2
|
1 /*
|
|
2 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
|
|
3 ** Copyright (C) 2003 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: common.h,v 1.38 2003/11/12 20:47:57 menno Exp $
|
|
26 **/
|
|
27
|
|
28 #ifndef __COMMON_H__
|
|
29 #define __COMMON_H__
|
|
30
|
|
31 #ifdef __cplusplus
|
|
32 extern "C" {
|
|
33 #endif
|
|
34
|
|
35 #define INLINE __inline
|
|
36
|
|
37 #ifndef max
|
|
38 #define max(a, b) (((a) > (b)) ? (a) : (b))
|
|
39 #endif
|
|
40 #ifndef min
|
|
41 #define min(a, b) (((a) < (b)) ? (a) : (b))
|
|
42 #endif
|
|
43
|
|
44 /* COMPILE TIME DEFINITIONS */
|
|
45
|
|
46 /* use double precision */
|
|
47 /* #define USE_DOUBLE_PRECISION */
|
|
48 /* use fixed point reals */
|
|
49 //#define FIXED_POINT
|
|
50
|
|
51 #ifdef _WIN32_WCE
|
|
52 #define FIXED_POINT
|
|
53 #endif
|
|
54
|
|
55
|
|
56 #define ERROR_RESILIENCE
|
|
57
|
|
58
|
|
59 /* Allow decoding of MAIN profile AAC */
|
|
60 #define MAIN_DEC
|
|
61 /* Allow decoding of SSR profile AAC */
|
|
62 //#define SSR_DEC
|
|
63 /* Allow decoding of LTP profile AAC */
|
|
64 #define LTP_DEC
|
|
65 /* Allow decoding of LD profile AAC */
|
|
66 #define LD_DEC
|
|
67 /* Allow decoding of Digital Radio Mondiale (DRM) */
|
|
68 //#define DRM
|
|
69
|
|
70 /* LD can't do without LTP */
|
|
71 #ifdef LD_DEC
|
|
72 #ifndef ERROR_RESILIENCE
|
|
73 #define ERROR_RESILIENCE
|
|
74 #endif
|
|
75 #ifndef LTP_DEC
|
|
76 #define LTP_DEC
|
|
77 #endif
|
|
78 #endif
|
|
79
|
|
80 #define ALLOW_SMALL_FRAMELENGTH
|
|
81
|
|
82
|
|
83 // Define LC_ONLY_DECODER if you want a pure AAC LC decoder (independant of SBR_DEC)
|
|
84 //#define LC_ONLY_DECODER
|
|
85 #ifdef LC_ONLY_DECODER
|
|
86 #undef LTP_DEC
|
|
87 #undef MAIN_DEC
|
|
88 #undef SSR_DEC
|
|
89 #undef DRM
|
|
90 #undef ALLOW_SMALL_FRAMELENGTH
|
|
91 #undef ERROR_RESILIENCE
|
|
92 #endif
|
|
93
|
|
94 #define SBR_DEC
|
|
95 //#define SBR_LOW_POWER
|
|
96
|
|
97 /* FIXED POINT: No MAIN decoding, forced SBR Low Power decoder */
|
|
98 #ifdef FIXED_POINT
|
|
99 # ifdef MAIN_DEC
|
|
100 # undef MAIN_DEC
|
|
101 # endif
|
|
102 # ifndef SBR_LOW_POWER
|
|
103 # define SBR_LOW_POWER
|
|
104 # endif
|
|
105 #endif // FIXED_POINT
|
|
106
|
|
107 #ifdef FIXED_POINT
|
|
108 #define SBR_DIV(A, B) (((int64_t)A << REAL_BITS)/B)
|
|
109 #else
|
|
110 #define SBR_DIV(A, B) ((A)/(B))
|
|
111 #endif
|
|
112
|
|
113 #ifndef SBR_LOW_POWER
|
|
114 #define qmf_t complex_t
|
|
115 #define QMF_RE(A) RE(A)
|
|
116 #define QMF_IM(A) IM(A)
|
|
117 #else
|
|
118 #define qmf_t real_t
|
|
119 #define QMF_RE(A) (A)
|
|
120 #define QMF_IM(A)
|
|
121 #endif
|
|
122
|
|
123
|
|
124 /* END COMPILE TIME DEFINITIONS */
|
|
125
|
|
126 #ifndef FIXED_POINT
|
|
127 #define POW_TABLE_SIZE 200
|
|
128 #endif
|
|
129
|
|
130
|
|
131 #if defined(_WIN32)
|
|
132
|
|
133
|
|
134 typedef unsigned __int64 uint64_t;
|
|
135 typedef unsigned __int32 uint32_t;
|
|
136 typedef unsigned __int16 uint16_t;
|
|
137 typedef unsigned __int8 uint8_t;
|
|
138 typedef __int64 int64_t;
|
|
139 typedef __int32 int32_t;
|
|
140 typedef __int16 int16_t;
|
|
141 typedef __int8 int8_t;
|
|
142 typedef float float32_t;
|
|
143
|
|
144
|
|
145 #else
|
|
146
|
|
147 #ifdef HAVE_CONFIG_H
|
5
|
148 # include "../../../config.h"
|
2
|
149 #endif
|
|
150
|
|
151 #include <stdio.h>
|
|
152 #if HAVE_SYS_TYPES_H
|
|
153 # include <sys/types.h>
|
|
154 #endif
|
|
155 #if HAVE_SYS_STAT_H
|
|
156 # include <sys/stat.h>
|
|
157 #endif
|
|
158 #if STDC_HEADERS
|
|
159 # include <stdlib.h>
|
|
160 # include <stddef.h>
|
|
161 #else
|
|
162 # if HAVE_STDLIB_H
|
|
163 # include <stdlib.h>
|
|
164 # endif
|
|
165 #endif
|
|
166 #if HAVE_STRING_H
|
|
167 # if !STDC_HEADERS && HAVE_MEMORY_H
|
|
168 # include <memory.h>
|
|
169 # endif
|
|
170 # include <string.h>
|
|
171 #endif
|
|
172 #if HAVE_STRINGS_H
|
|
173 # include <strings.h>
|
|
174 #endif
|
|
175 #if HAVE_INTTYPES_H
|
|
176 # include <inttypes.h>
|
|
177 #else
|
|
178 # if HAVE_STDINT_H
|
|
179 # include <stdint.h>
|
|
180 # else
|
|
181 /* we need these... */
|
|
182 typedef unsigned long long uint64_t;
|
|
183 typedef unsigned long uint32_t;
|
|
184 typedef unsigned short uint16_t;
|
|
185 typedef unsigned char uint8_t;
|
|
186 typedef long long int64_t;
|
|
187 typedef long int32_t;
|
|
188 typedef short int16_t;
|
|
189 typedef char int8_t;
|
|
190 # endif
|
|
191 #endif
|
|
192 #if HAVE_UNISTD_H
|
|
193 # include <unistd.h>
|
|
194 #endif
|
|
195
|
|
196 #ifndef HAVE_FLOAT32_T
|
|
197 typedef float float32_t;
|
|
198 #endif
|
|
199
|
|
200 #if STDC_HEADERS
|
|
201 # include <string.h>
|
|
202 #else
|
|
203 # if !HAVE_STRCHR
|
|
204 # define strchr index
|
|
205 # define strrchr rindex
|
|
206 # endif
|
|
207 char *strchr(), *strrchr();
|
|
208 # if !HAVE_MEMCPY
|
|
209 # define memcpy(d, s, n) bcopy((s), (d), (n))
|
|
210 # define memmove(d, s, n) bcopy((s), (d), (n))
|
|
211 # endif
|
|
212 #endif
|
|
213
|
|
214 #endif
|
|
215
|
|
216 #ifdef WORDS_BIGENDIAN
|
|
217 #define ARCH_IS_BIG_ENDIAN
|
|
218 #endif
|
|
219
|
|
220 /* FIXED_POINT doesn't work with MAIN and SSR yet */
|
|
221 #ifdef FIXED_POINT
|
|
222 #undef MAIN_DEC
|
|
223 #undef SSR_DEC
|
|
224 #endif
|
|
225
|
|
226
|
|
227 #if defined(FIXED_POINT)
|
|
228
|
|
229 #ifdef HAS_MATHF_H
|
|
230 #include <mathf.h>
|
|
231 #else
|
|
232 #include <math.h>
|
|
233 #endif
|
|
234
|
|
235 #include "fixed.h"
|
|
236
|
|
237 #elif defined(USE_DOUBLE_PRECISION)
|
|
238
|
|
239 typedef double real_t;
|
|
240
|
|
241 #include <math.h>
|
|
242
|
|
243 #define MUL_R(A,B) ((A)*(B))
|
|
244 #define MUL_C(A,B) ((A)*(B))
|
|
245 #define MUL_F(A,B) ((A)*(B))
|
|
246
|
|
247 /* Complex multiplication */
|
|
248 static INLINE void ComplexMult(real_t *y1, real_t *y2,
|
|
249 real_t x1, real_t x2, real_t c1, real_t c2)
|
|
250 {
|
|
251 *y1 = MUL_F(x1, c1) + MUL_F(x2, c2);
|
|
252 *y2 = MUL_F(x2, c1) - MUL_F(x1, c2);
|
|
253 }
|
|
254
|
|
255 #define REAL_CONST(A) ((real_t)(A))
|
|
256 #define COEF_CONST(A) ((real_t)(A))
|
|
257 #define FRAC_CONST(A) ((real_t)(A)) /* pure fractional part */
|
|
258
|
|
259 #else /* Normal floating point operation */
|
|
260
|
|
261 typedef float real_t;
|
|
262
|
|
263 #define MUL_R(A,B) ((A)*(B))
|
|
264 #define MUL_C(A,B) ((A)*(B))
|
|
265 #define MUL_F(A,B) ((A)*(B))
|
|
266
|
|
267 #define REAL_CONST(A) ((real_t)(A))
|
|
268 #define COEF_CONST(A) ((real_t)(A))
|
|
269 #define FRAC_CONST(A) ((real_t)(A)) /* pure fractional part */
|
|
270
|
|
271 /* Complex multiplication */
|
|
272 static INLINE void ComplexMult(real_t *y1, real_t *y2,
|
|
273 real_t x1, real_t x2, real_t c1, real_t c2)
|
|
274 {
|
|
275 *y1 = MUL_F(x1, c1) + MUL_F(x2, c2);
|
|
276 *y2 = MUL_F(x2, c1) - MUL_F(x1, c2);
|
|
277 }
|
|
278
|
|
279
|
|
280 #ifdef _WIN32
|
|
281 #define HAS_LRINTF
|
|
282 static INLINE int lrintf(float f)
|
|
283 {
|
|
284 int i;
|
|
285 __asm
|
|
286 {
|
|
287 fld f
|
|
288 fistp i
|
|
289 }
|
|
290 return i;
|
|
291 }
|
|
292 #endif
|
|
293
|
|
294
|
|
295 #ifdef __ICL /* only Intel C compiler has fmath ??? */
|
|
296
|
|
297 #include <mathf.h>
|
|
298
|
|
299 #define sin sinf
|
|
300 #define cos cosf
|
|
301 #define log logf
|
|
302 #define floor floorf
|
|
303 #define ceil ceilf
|
|
304 #define sqrt sqrtf
|
|
305
|
|
306 #else
|
|
307
|
|
308 #ifdef HAVE_LRINTF
|
|
309 # define HAS_LRINTF
|
|
310 # define _ISOC9X_SOURCE 1
|
|
311 # define _ISOC99_SOURCE 1
|
|
312 # define __USE_ISOC9X 1
|
|
313 # define __USE_ISOC99 1
|
|
314 #endif
|
|
315
|
|
316 #include <math.h>
|
|
317
|
|
318 #ifdef HAVE_SINF
|
|
319 # define sin sinf
|
|
320 #error
|
|
321 #endif
|
|
322 #ifdef HAVE_COSF
|
|
323 # define cos cosf
|
|
324 #endif
|
|
325 #ifdef HAVE_LOGF
|
|
326 # define log logf
|
|
327 #endif
|
|
328 #ifdef HAVE_EXPF
|
|
329 # define exp expf
|
|
330 #endif
|
|
331 #ifdef HAVE_FLOORF
|
|
332 # define floor floorf
|
|
333 #endif
|
|
334 #ifdef HAVE_CEILF
|
|
335 # define ceil ceilf
|
|
336 #endif
|
|
337 #ifdef HAVE_SQRTF
|
|
338 # define sqrt sqrtf
|
|
339 #endif
|
|
340
|
|
341 #endif
|
|
342
|
|
343 #endif
|
|
344
|
|
345 #ifndef HAS_LRINTF
|
|
346 /* standard cast */
|
|
347 #define lrintf(f) ((int32_t)(f))
|
|
348 #endif
|
|
349
|
|
350 typedef real_t complex_t[2];
|
|
351 #define RE(A) A[0]
|
|
352 #define IM(A) A[1]
|
|
353
|
|
354
|
|
355 /* common functions */
|
|
356 int32_t int_log2(int32_t val);
|
|
357 uint32_t random_int(void);
|
|
358 uint8_t get_sr_index(uint32_t samplerate);
|
|
359 uint8_t max_pred_sfb(uint8_t sr_index);
|
|
360 uint8_t max_tns_sfb(uint8_t sr_index, uint8_t object_type, uint8_t is_short);
|
|
361 uint32_t get_sample_rate(uint8_t sr_index);
|
|
362 int8_t can_decode_ot(uint8_t object_type);
|
|
363
|
|
364 #ifndef M_PI
|
|
365 #define M_PI 3.14159265358979323846f
|
|
366 #endif
|
|
367 #ifndef M_PI_2 /* PI/2 */
|
|
368 #define M_PI_2 1.57079632679489661923
|
|
369 #endif
|
|
370
|
|
371
|
|
372 #ifdef __cplusplus
|
|
373 }
|
|
374 #endif
|
|
375 #endif
|