Coverage Report

Created: 2025-07-11 06:39

/proc/self/cwd/libfaad/common.h
Line
Count
Source (jump to first uncovered line)
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.79 2015/01/26 17:48:53 knik 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
0
#define max(a, b) (((a) > (b)) ? (a) : (b))
58
#endif
59
#ifndef min
60
0
#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
#ifdef _WIN32_WCE
75
#define FIXED_POINT
76
#endif
77
78
#ifdef __BFIN__
79
#define FIXED_POINT
80
#endif
81
82
#define ERROR_RESILIENCE
83
84
85
/* Allow decoding of MAIN profile AAC */
86
#define MAIN_DEC
87
/* Allow decoding of SSR profile AAC */
88
//#define SSR_DEC
89
/* Allow decoding of LTP profile AAC */
90
#define LTP_DEC
91
/* Allow decoding of LD profile AAC */
92
#define LD_DEC
93
/* Allow decoding of Digital Radio Mondiale (DRM) */
94
#ifdef DRM_SUPPORT
95
#define DRM
96
#define DRM_PS
97
#endif
98
99
/* LD can't do without LTP */
100
#ifdef LD_DEC
101
#ifndef ERROR_RESILIENCE
102
#define ERROR_RESILIENCE
103
#endif
104
#ifndef LTP_DEC
105
#define LTP_DEC
106
#endif
107
#endif
108
109
#define ALLOW_SMALL_FRAMELENGTH
110
111
112
// Define LC_ONLY_DECODER if you want a pure AAC LC decoder (independant of SBR_DEC and PS_DEC)
113
//#define LC_ONLY_DECODER
114
#ifdef LC_ONLY_DECODER
115
  #undef LD_DEC
116
  #undef LTP_DEC
117
  #undef MAIN_DEC
118
  #undef SSR_DEC
119
  #undef DRM
120
  #undef DRM_PS
121
  #undef ALLOW_SMALL_FRAMELENGTH
122
  #undef ERROR_RESILIENCE
123
#endif
124
125
// Define DISABLE_SBR if you want to disable SBR decoding.
126
//#define DISABLE_SBR
127
128
// Define SBR_LOW_POWER if you want only low power SBR decoding without PS.
129
//#define SBR_LOW_POWER
130
131
#ifndef DISABLE_SBR
132
# define SBR_DEC
133
# ifndef SBR_LOW_POWER
134
#  define PS_DEC
135
# endif // SBR_LOW_POWER
136
#endif // DISABLE_SBR
137
138
/* FIXED POINT: No MAIN decoding */
139
#ifdef FIXED_POINT
140
# ifdef MAIN_DEC
141
#  undef MAIN_DEC
142
# endif
143
#endif // FIXED_POINT
144
145
#ifdef DRM
146
# ifndef ALLOW_SMALL_FRAMELENGTH
147
#  define ALLOW_SMALL_FRAMELENGTH
148
# endif
149
# undef LD_DEC
150
# undef LTP_DEC
151
# undef MAIN_DEC
152
# undef SSR_DEC
153
#endif
154
155
156
#ifdef FIXED_POINT
157
#define DIV_R(A, B) (((int64_t)A * REAL_PRECISION)/B)
158
#define DIV_C(A, B) (((int64_t)A * COEF_PRECISION)/B)
159
#define DIV_F(A, B) (((int64_t)A * FRAC_PRECISION)/B)
160
#else
161
0
#define DIV_R(A, B) ((A)/(B))
162
#define DIV_C(A, B) ((A)/(B))
163
0
#define DIV_F(A, B) ((A)/(B))
164
#endif
165
166
#ifndef SBR_LOW_POWER
167
0
#define qmf_t complex_t
168
0
#define QMF_RE(A) RE(A)
169
0
#define QMF_IM(A) IM(A)
170
#else
171
#define qmf_t real_t
172
#define QMF_RE(A) (A)
173
#define QMF_IM(A)
174
#endif
175
176
177
/* END COMPILE TIME DEFINITIONS */
178
179
#if defined(_WIN32) && !defined(__MINGW32__)
180
181
#include <stdlib.h>
182
#include <string.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  /* WIN */
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
#include <stdlib.h>
205
#include <stddef.h>
206
#if HAVE_STRING_H
207
# include <string.h>
208
#endif
209
#if HAVE_STRINGS_H
210
# include <strings.h>
211
#endif
212
#if HAVE_INTTYPES_H
213
# include <inttypes.h>
214
#else
215
# if HAVE_STDINT_H
216
#  include <stdint.h>
217
# else
218
/* we need these... */
219
#ifndef __TCS__
220
typedef unsigned long long uint64_t;
221
typedef signed long long int64_t;
222
#else
223
typedef unsigned long uint64_t;
224
typedef signed long int64_t;
225
#endif
226
typedef unsigned long uint32_t;
227
typedef unsigned short uint16_t;
228
typedef unsigned char uint8_t;
229
typedef signed long int32_t;
230
typedef signed short int16_t;
231
typedef signed char int8_t;
232
# endif
233
#endif
234
#if HAVE_UNISTD_H
235
//# include <unistd.h>
236
#endif
237
238
#ifndef HAVE_FLOAT32_T
239
typedef float float32_t;
240
#endif
241
242
#include <string.h>
243
244
#endif  /* WIN */
245
246
/* FIXED_POINT doesn't work with MAIN and SSR yet */
247
#ifdef FIXED_POINT
248
  #undef MAIN_DEC
249
  #undef SSR_DEC
250
#endif
251
252
253
#if defined(FIXED_POINT)
254
255
  #include "fixed.h"
256
257
#elif defined(USE_DOUBLE_PRECISION)
258
259
  typedef double real_t;
260
261
  #include <math.h>
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
  /* Complex multiplication */
268
  static INLINE void ComplexMult(real_t *y1, real_t *y2,
269
      real_t x1, real_t x2, real_t c1, real_t c2)
270
  {
271
      *y1 = MUL_F(x1, c1) + MUL_F(x2, c2);
272
      *y2 = MUL_F(x2, c1) - MUL_F(x1, c2);
273
  }
274
275
  #define REAL_CONST(A) ((real_t)(A))
276
  #define COEF_CONST(A) ((real_t)(A))
277
  #define Q2_CONST(A) ((real_t)(A))
278
  #define FRAC_CONST(A) ((real_t)(A)) /* pure fractional part */
279
280
#else /* Normal floating point operation */
281
282
  typedef float real_t;
283
284
0
  #define MUL_R(A,B) ((A)*(B))
285
0
  #define MUL_C(A,B) ((A)*(B))
286
0
  #define MUL_F(A,B) ((A)*(B))
287
288
0
  #define REAL_CONST(A) ((real_t)(A))
289
0
  #define COEF_CONST(A) ((real_t)(A))
290
  #define Q2_CONST(A) ((real_t)(A))
291
0
  #define FRAC_CONST(A) ((real_t)(A)) /* pure fractional part */
292
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)
296
0
  {
297
0
      *y1 = MUL_F(x1, c1) + MUL_F(x2, c2);
298
0
      *y2 = MUL_F(x2, c1) - MUL_F(x1, c2);
299
0
  }
Unexecuted instantiation: decoder.c:ComplexMult
Unexecuted instantiation: common.c:ComplexMult
Unexecuted instantiation: bits.c:ComplexMult
Unexecuted instantiation: drc.c:ComplexMult
Unexecuted instantiation: error.c:ComplexMult
Unexecuted instantiation: filtbank.c:ComplexMult
Unexecuted instantiation: mdct.c:ComplexMult
Unexecuted instantiation: cfft.c:ComplexMult
Unexecuted instantiation: mp4.c:ComplexMult
Unexecuted instantiation: output.c:ComplexMult
Unexecuted instantiation: sbr_dec.c:ComplexMult
Unexecuted instantiation: ps_dec.c:ComplexMult
Unexecuted instantiation: sbr_hfadj.c:ComplexMult
Unexecuted instantiation: sbr_hfgen.c:ComplexMult
Unexecuted instantiation: sbr_fbt.c:ComplexMult
Unexecuted instantiation: sbr_qmf.c:ComplexMult
Unexecuted instantiation: sbr_dct.c:ComplexMult
Unexecuted instantiation: syntax.c:ComplexMult
Unexecuted instantiation: specrec.c:ComplexMult
Unexecuted instantiation: ic_predict.c:ComplexMult
Unexecuted instantiation: lt_predict.c:ComplexMult
Unexecuted instantiation: pns.c:ComplexMult
Unexecuted instantiation: ms.c:ComplexMult
Unexecuted instantiation: is.c:ComplexMult
Unexecuted instantiation: sbr_syntax.c:ComplexMult
Unexecuted instantiation: sbr_huff.c:ComplexMult
Unexecuted instantiation: sbr_e_nf.c:ComplexMult
Unexecuted instantiation: sbr_tf_grid.c:ComplexMult
Unexecuted instantiation: ps_syntax.c:ComplexMult
Unexecuted instantiation: rvlc.c:ComplexMult
Unexecuted instantiation: hcr.c:ComplexMult
Unexecuted instantiation: huffman.c:ComplexMult
Unexecuted instantiation: pulse.c:ComplexMult
Unexecuted instantiation: tns.c:ComplexMult
300
301
302
  #if defined(_WIN32) && defined(_M_IX86) && !defined(__MINGW32__)
303
    #ifndef HAVE_LRINTF
304
    #define HAS_LRINTF
305
    static INLINE long lrintf(float f)
306
    {
307
        int i;
308
        __asm
309
        {
310
            fld   f
311
            fistp i
312
        }
313
        return i;
314
    }
315
    #endif /* HAVE_LRINTF */
316
  #elif (defined(__i386__) && defined(__GNUC__) && \
317
  !defined(__CYGWIN__) && !defined(__MINGW32__))
318
    #ifndef HAVE_LRINTF
319
    #define HAS_LRINTF
320
    // from http://www.stereopsis.com/FPU.html
321
    static INLINE long lrintf(float f)
322
    {
323
        int i;
324
        __asm__ __volatile__ (
325
            "flds %1        \n\t"
326
            "fistpl %0      \n\t"
327
            : "=m" (i)
328
            : "m" (f));
329
        return i;
330
    }
331
    #endif /* HAVE_LRINTF */
332
  #endif
333
334
335
  #ifdef __ICL /* only Intel C compiler has fmath ??? */
336
337
    #include <mathf.h>
338
339
    #define sin sinf
340
    #define cos cosf
341
    #define log logf
342
    #define floor floorf
343
    #define ceil ceilf
344
    #define sqrt sqrtf
345
346
  #else
347
348
#ifdef HAVE_LRINTF
349
#  define HAS_LRINTF
350
#  define _ISOC9X_SOURCE 1
351
#  define _ISOC99_SOURCE 1
352
#  define __USE_ISOC9X   1
353
#  define __USE_ISOC99   1
354
#endif
355
356
    #include <math.h>
357
358
#ifdef HAVE_SINF
359
#  define sin sinf
360
#error
361
#endif
362
#ifdef HAVE_COSF
363
#  define cos cosf
364
#endif
365
#ifdef HAVE_LOGF
366
#  define log logf
367
#endif
368
#ifdef HAVE_EXPF
369
#  define exp expf
370
#endif
371
#ifdef HAVE_FLOORF
372
#  define floor floorf
373
#endif
374
#ifdef HAVE_CEILF
375
#  define ceil ceilf
376
#endif
377
#ifdef HAVE_SQRTF
378
#  define sqrt sqrtf
379
#endif
380
381
  #endif
382
383
#endif
384
385
#ifndef HAS_LRINTF
386
/* standard cast */
387
0
#define lrintf(f) ((long)(f))
388
#endif
389
390
typedef real_t complex_t[2];
391
0
#define RE(A) (A)[0]
392
0
#define IM(A) (A)[1]
393
394
395
/* common functions */
396
uint8_t cpu_has_sse(void);
397
uint32_t ne_rng(uint32_t *__r1, uint32_t *__r2);
398
#ifdef FIXED_POINT
399
uint32_t wl_min_lzc(uint32_t x);
400
#define LOG2_MIN_INF REAL_CONST(-10000)
401
int32_t log2_int(uint64_t val);
402
uint64_t pow2_int(real_t val);
403
real_t pow2_fix(real_t val);
404
#endif
405
uint8_t get_sr_index(const uint32_t samplerate);
406
uint8_t max_pred_sfb(const uint8_t sr_index);
407
uint8_t max_tns_sfb(const uint8_t sr_index, const uint8_t object_type,
408
                    const uint8_t is_short);
409
uint32_t get_sample_rate(const uint8_t sr_index);
410
int8_t can_decode_ot(const uint8_t object_type);
411
412
void *faad_malloc(size_t size);
413
void faad_free(void *b);
414
415
//#define PROFILE
416
#ifdef PROFILE
417
static int64_t faad_get_ts()
418
{
419
    __asm
420
    {
421
        rdtsc
422
    }
423
}
424
#endif
425
426
#ifndef M_PI
427
#define M_PI 3.14159265358979323846
428
#endif
429
#ifndef M_PI_2 /* PI/2 */
430
#define M_PI_2 1.57079632679489661923
431
#endif
432
433
434
#ifdef __cplusplus
435
}
436
#endif
437
#endif