/* ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding ** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com ** ** This program is free software; you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation; either version 2 of the License, or ** (at your option) any later version. ** ** This program is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. ** ** You should have received a copy of the GNU General Public License ** along with this program; if not, write to the Free Software ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ** ** Any non-GPL usage of this software or parts of this software is strictly ** forbidden. ** ** The "appropriate copyright message" mentioned in section 2c of the GPLv2 ** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com" ** ** Commercial non-GPL licensing of this software is possible. ** For more info contact Nero AG through Mpeg4AAClicense@nero.com. ** ** $Id: common.h,v 1.79 2015/01/26 17:48:53 knik Exp $ **/ #ifndef __COMMON_H__ #define __COMMON_H__ #ifdef __cplusplus extern "C" { #endif #include "config.h" #include "neaacdec.h" #define INLINE __inline #define ALIGN #ifndef max #define max(a, b) (((a) > (b)) ? (a) : (b)) #endif #ifndef min #define min(a, b) (((a) < (b)) ? (a) : (b)) #endif /* COMPILE TIME DEFINITIONS */ /* Allow decoding of Digital Radio Mondiale (DRM) */ #ifdef DRM_SUPPORT #define DRM #define DRM_PS #endif /* LD can't do without LTP */ #ifdef LD_DEC #ifndef ERROR_RESILIENCE #define ERROR_RESILIENCE #endif #ifndef LTP_DEC #define LTP_DEC #endif #endif // Define LC_ONLY_DECODER if you want a pure AAC LC decoder (independant of SBR_DEC and PS_DEC) //#define LC_ONLY_DECODER #ifdef LC_ONLY_DECODER #undef LD_DEC #undef LTP_DEC #undef MAIN_DEC #undef SSR_DEC #undef DRM #undef DRM_PS #undef ALLOW_SMALL_FRAMELENGTH #undef ERROR_RESILIENCE #endif #ifndef DISABLE_SBR # define SBR_DEC # ifndef SBR_LOW_POWER # define PS_DEC # endif // SBR_LOW_POWER #endif // DISABLE_SBR /* FIXED POINT: No MAIN decoding */ #ifdef FIXED_POINT # ifdef MAIN_DEC # undef MAIN_DEC # endif #endif // FIXED_POINT #ifdef DRM # ifndef ALLOW_SMALL_FRAMELENGTH # define ALLOW_SMALL_FRAMELENGTH # endif # undef LD_DEC # undef LTP_DEC # undef MAIN_DEC # undef SSR_DEC #endif #ifdef FIXED_POINT #define DIV_R(A, B) (((int64_t)A * REAL_PRECISION)/B) #define DIV_C(A, B) (((int64_t)A * COEF_PRECISION)/B) #define DIV_F(A, B) (((int64_t)A * FRAC_PRECISION)/B) #else #define DIV_R(A, B) ((A)/(B)) #define DIV_C(A, B) ((A)/(B)) #define DIV_F(A, B) ((A)/(B)) #endif #ifndef SBR_LOW_POWER #define qmf_t complex_t #define QMF_RE(A) RE(A) #define QMF_IM(A) IM(A) #else #define qmf_t real_t #define QMF_RE(A) (A) #define QMF_IM(A) #endif /* END COMPILE TIME DEFINITIONS */ #if defined(_WIN32) && !defined(__MINGW32__) #include #include typedef unsigned __int64 uint64_t; typedef unsigned __int32 uint32_t; typedef unsigned __int16 uint16_t; typedef unsigned __int8 uint8_t; typedef signed __int64 int64_t; typedef signed __int32 int32_t; typedef signed __int16 int16_t; typedef signed __int8 int8_t; typedef float float32_t; #else /* WIN */ #include #include #if HAVE_SYS_STAT_H # include #endif #include #include #include #if HAVE_STRINGS_H # include #endif #include #ifndef HAVE_FLOAT32_T typedef float float32_t; #endif #endif /* WIN */ /* FIXED_POINT doesn't work with MAIN and SSR yet */ #ifdef FIXED_POINT #undef MAIN_DEC #undef SSR_DEC #endif #if defined(FIXED_POINT) #include "fixed.h" #elif defined(USE_DOUBLE_PRECISION) typedef double real_t; #include #define MUL_R(A,B) ((A)*(B)) #define MUL_C(A,B) ((A)*(B)) #define MUL_F(A,B) ((A)*(B)) /* Complex multiplication */ static INLINE void ComplexMult(real_t *y1, real_t *y2, real_t x1, real_t x2, real_t c1, real_t c2) { *y1 = MUL_F(x1, c1) + MUL_F(x2, c2); *y2 = MUL_F(x2, c1) - MUL_F(x1, c2); } #define REAL_CONST(A) ((real_t)(A)) #define COEF_CONST(A) ((real_t)(A)) #define Q2_CONST(A) ((real_t)(A)) #define FRAC_CONST(A) ((real_t)(A)) /* pure fractional part */ #else /* Normal floating point operation */ typedef float real_t; #define MUL_R(A,B) ((A)*(B)) #define MUL_C(A,B) ((A)*(B)) #define MUL_F(A,B) ((A)*(B)) #define REAL_CONST(A) ((real_t)(A)) #define COEF_CONST(A) ((real_t)(A)) #define Q2_CONST(A) ((real_t)(A)) #define FRAC_CONST(A) ((real_t)(A)) /* pure fractional part */ /* Complex multiplication */ static INLINE void ComplexMult(real_t *y1, real_t *y2, real_t x1, real_t x2, real_t c1, real_t c2) { *y1 = MUL_F(x1, c1) + MUL_F(x2, c2); *y2 = MUL_F(x2, c1) - MUL_F(x1, c2); } #ifdef __ICL /* only Intel C compiler has fmath ??? */ #include #define sin sinf #define cos cosf #define log logf #define floor floorf #define ceil ceilf #define sqrt sqrtf #else #include #define sin sinf #define cos cosf #define log logf #define exp expf #define floor floorf #define ceil ceilf #define sqrt sqrtf #endif #endif typedef real_t complex_t[2]; #define RE(A) (A)[0] #define IM(A) (A)[1] /* common functions */ uint8_t cpu_has_sse(void); uint32_t ne_rng(uint32_t *__r1, uint32_t *__r2); #ifdef FIXED_POINT uint32_t wl_min_lzc(uint32_t x); #define LOG2_MIN_INF REAL_CONST(-10000) int32_t log2_int(uint64_t val); uint64_t pow2_int(real_t val); real_t pow2_fix(real_t val); #endif uint8_t get_sr_index(const uint32_t samplerate); uint8_t max_pred_sfb(const uint8_t sr_index); uint8_t max_tns_sfb(const uint8_t sr_index, const uint8_t object_type, const uint8_t is_short); uint32_t get_sample_rate(const uint8_t sr_index); int8_t can_decode_ot(const uint8_t object_type); void *faad_malloc(size_t size); void faad_free(void *b); //#define PROFILE #ifdef PROFILE static int64_t faad_get_ts() { __asm { rdtsc } } #endif #ifndef M_PI #define M_PI 3.14159265358979323846 #endif #ifndef M_PI_2 /* PI/2 */ #define M_PI_2 1.57079632679489661923 #endif #ifdef __cplusplus } #endif #endif