common.h

00001 /*
00002 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
00003 ** Copyright (C) 2003-2005 M. Bakker, Ahead Software AG, http://www.nero.com
00004 **  
00005 ** This program is free software; you can redistribute it and/or modify
00006 ** it under the terms of the GNU General Public License as published by
00007 ** the Free Software Foundation; either version 2 of the License, or
00008 ** (at your option) any later version.
00009 ** 
00010 ** This program is distributed in the hope that it will be useful,
00011 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 ** GNU General Public License for more details.
00014 ** 
00015 ** You should have received a copy of the GNU General Public License
00016 ** along with this program; if not, write to the Free Software 
00017 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00018 **
00019 ** Any non-GPL usage of this software or parts of this software is strictly
00020 ** forbidden.
00021 **
00022 ** Software using this code must display the following message visibly in the
00023 ** software:
00024 ** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Ahead Software, www.nero.com"
00025 ** in, for example, the about-box or help/startup screen.
00026 **
00027 ** Commercial non-GPL licensing of this software is possible.
00028 ** For more info contact Ahead Software through [email protected].
00029 **
00030 ** $Id: common.h,v 1.2 2005/11/01 21:41:43 gabest Exp $
00031 **/
00032 
00033 #ifndef __COMMON_H__
00034 #define __COMMON_H__
00035 
00036 #ifdef __cplusplus
00037 extern "C" {
00038 #endif
00039 
00040 #ifdef HAVE_CONFIG_H
00041 #  include "../config.h"
00042 #endif
00043 
00044 #if 1
00045 #define INLINE __inline
00046 #else
00047 #define INLINE inline
00048 #endif
00049 
00050 #if 0 //defined(_WIN32) && !defined(_WIN32_WCE)
00051 #define ALIGN __declspec(align(16))
00052 #else
00053 #define ALIGN
00054 #endif
00055 
00056 #ifndef max
00057 #define max(a, b) (((a) > (b)) ? (a) : (b))
00058 #endif
00059 #ifndef min
00060 #define min(a, b) (((a) < (b)) ? (a) : (b))
00061 #endif
00062 
00063 /* COMPILE TIME DEFINITIONS */
00064 
00065 /* use double precision */
00066 /* #define USE_DOUBLE_PRECISION */
00067 /* use fixed point reals */
00068 //#define FIXED_POINT
00069 //#define BIG_IQ_TABLE
00070 
00071 /* Use if target platform has address generators with autoincrement */
00072 //#define PREFER_POINTERS
00073 
00074 #ifdef _WIN32_WCE
00075 #define FIXED_POINT
00076 #endif
00077 
00078 #define ERROR_RESILIENCE
00079 
00080 
00081 /* Allow decoding of MAIN profile AAC */
00082 #define MAIN_DEC
00083 /* Allow decoding of SSR profile AAC */
00084 //#define SSR_DEC
00085 /* Allow decoding of LTP profile AAC */
00086 #define LTP_DEC
00087 /* Allow decoding of LD profile AAC */
00088 #define LD_DEC
00089 /* Allow decoding of Digital Radio Mondiale (DRM) */
00090 //#define DRM
00091 //#define DRM_PS
00092 
00093 /* LD can't do without LTP */
00094 #ifdef LD_DEC
00095 #ifndef ERROR_RESILIENCE
00096 #define ERROR_RESILIENCE
00097 #endif
00098 #ifndef LTP_DEC
00099 #define LTP_DEC
00100 #endif
00101 #endif
00102 
00103 #define ALLOW_SMALL_FRAMELENGTH
00104 
00105 
00106 // Define LC_ONLY_DECODER if you want a pure AAC LC decoder (independant of SBR_DEC and PS_DEC)
00107 //#define LC_ONLY_DECODER
00108 #ifdef LC_ONLY_DECODER
00109   #undef LD_DEC
00110   #undef LTP_DEC
00111   #undef MAIN_DEC
00112   #undef SSR_DEC
00113   #undef DRM
00114   #undef ALLOW_SMALL_FRAMELENGTH
00115   #undef ERROR_RESILIENCE
00116 #endif
00117 
00118 #define SBR_DEC
00119 //#define SBR_LOW_POWER
00120 #define PS_DEC
00121 
00122 #ifdef SBR_LOW_POWER
00123 #undef PS_DEC
00124 #endif
00125 
00126 /* FIXED POINT: No MAIN decoding */
00127 #ifdef FIXED_POINT
00128 # ifdef MAIN_DEC
00129 #  undef MAIN_DEC
00130 # endif
00131 #endif // FIXED_POINT
00132 
00133 #ifdef DRM
00134 # ifndef ALLOW_SMALL_FRAMELENGTH
00135 #  define ALLOW_SMALL_FRAMELENGTH
00136 # endif
00137 # undef LD_DEC
00138 # undef LTP_DEC
00139 # undef MAIN_DEC
00140 # undef SSR_DEC
00141 #endif
00142 
00143 
00144 #ifdef FIXED_POINT
00145 #define DIV_R(A, B) (((int64_t)A << REAL_BITS)/B)
00146 #define DIV_C(A, B) (((int64_t)A << COEF_BITS)/B)
00147 #else
00148 #define DIV_R(A, B) ((A)/(B))
00149 #define DIV_C(A, B) ((A)/(B))
00150 #endif
00151 
00152 #ifndef SBR_LOW_POWER
00153 #define qmf_t complex_t
00154 #define QMF_RE(A) RE(A)
00155 #define QMF_IM(A) IM(A)
00156 #else
00157 #define qmf_t real_t
00158 #define QMF_RE(A) (A)
00159 #define QMF_IM(A)
00160 #endif
00161 
00162 
00163 /* END COMPILE TIME DEFINITIONS */
00164 
00165 #if defined(_WIN32) && !defined(__MINGW32__)
00166 
00167 #include <stdlib.h>
00168 
00169 typedef unsigned __int64 uint64_t;
00170 typedef unsigned __int32 uint32_t;
00171 typedef unsigned __int16 uint16_t;
00172 typedef unsigned __int8 uint8_t;
00173 typedef __int64 int64_t;
00174 typedef __int32 int32_t;
00175 typedef __int16 int16_t;
00176 typedef __int8  int8_t;
00177 typedef float float32_t;
00178 
00179 
00180 #else
00181 
00182 #include <stdio.h>
00183 #if HAVE_SYS_TYPES_H
00184 # include <sys/types.h>
00185 #endif
00186 #if HAVE_SYS_STAT_H
00187 # include <sys/stat.h>
00188 #endif
00189 #if STDC_HEADERS
00190 # include <stdlib.h>
00191 # include <stddef.h>
00192 #else
00193 # if HAVE_STDLIB_H
00194 #  include <stdlib.h>
00195 # endif
00196 #endif
00197 #if HAVE_STRING_H
00198 # if !STDC_HEADERS && HAVE_MEMORY_H
00199 #  include <memory.h>
00200 # endif
00201 # include <string.h>
00202 #endif
00203 #if HAVE_STRINGS_H
00204 # include <strings.h>
00205 #endif
00206 #if HAVE_INTTYPES_H
00207 # include <inttypes.h>
00208 #else
00209 # if HAVE_STDINT_H
00210 #  include <stdint.h>
00211 # else
00212 /* we need these... */
00213 #ifndef __TCS__
00214 typedef unsigned long long uint64_t;
00215 typedef long long int64_t;
00216 #else
00217 typedef unsigned long uint64_t;
00218 typedef long int64_t;
00219 #endif
00220 typedef unsigned long uint32_t;
00221 typedef unsigned short uint16_t;
00222 typedef unsigned char uint8_t;
00223 typedef long int32_t;
00224 typedef short int16_t;
00225 typedef char int8_t;
00226 # endif
00227 #endif
00228 #if HAVE_UNISTD_H
00229 //# include <unistd.h>
00230 #endif
00231 
00232 #ifndef HAVE_FLOAT32_T
00233 typedef float float32_t;
00234 #endif
00235 
00236 #if STDC_HEADERS
00237 # include <string.h>
00238 #else
00239 # if !HAVE_STRCHR
00240 #  define strchr index
00241 #  define strrchr rindex
00242 # endif
00243 char *strchr(), *strrchr();
00244 # if !HAVE_MEMCPY
00245 #  define memcpy(d, s, n) bcopy((s), (d), (n))
00246 #  define memmove(d, s, n) bcopy((s), (d), (n))
00247 # endif
00248 #endif
00249 
00250 #endif
00251 
00252 #ifdef WORDS_BIGENDIAN
00253 #define ARCH_IS_BIG_ENDIAN
00254 #endif
00255 
00256 /* FIXED_POINT doesn't work with MAIN and SSR yet */
00257 #ifdef FIXED_POINT
00258   #undef MAIN_DEC
00259   #undef SSR_DEC
00260 #endif
00261 
00262 
00263 #if defined(FIXED_POINT)
00264 
00265   #include "fixed.h"
00266 
00267 #elif defined(USE_DOUBLE_PRECISION)
00268 
00269   typedef double real_t;
00270 
00271   #include <math.h>
00272 
00273   #define MUL_R(A,B) ((A)*(B))
00274   #define MUL_C(A,B) ((A)*(B))
00275   #define MUL_F(A,B) ((A)*(B))
00276 
00277   /* Complex multiplication */
00278   static INLINE void ComplexMult(real_t *y1, real_t *y2,
00279       real_t x1, real_t x2, real_t c1, real_t c2)
00280   {
00281       *y1 = MUL_F(x1, c1) + MUL_F(x2, c2);
00282       *y2 = MUL_F(x2, c1) - MUL_F(x1, c2);
00283   }
00284 
00285   #define REAL_CONST(A) ((real_t)(A))
00286   #define COEF_CONST(A) ((real_t)(A))
00287   #define Q2_CONST(A) ((real_t)(A))
00288   #define FRAC_CONST(A) ((real_t)(A)) /* pure fractional part */
00289 
00290 #else /* Normal floating point operation */
00291 
00292   typedef float real_t;
00293 
00294   #define MUL_R(A,B) ((A)*(B))
00295   #define MUL_C(A,B) ((A)*(B))
00296   #define MUL_F(A,B) ((A)*(B))
00297 
00298   #define REAL_CONST(A) ((real_t)(A))
00299   #define COEF_CONST(A) ((real_t)(A))
00300   #define Q2_CONST(A) ((real_t)(A))
00301   #define FRAC_CONST(A) ((real_t)(A)) /* pure fractional part */
00302 
00303   /* Complex multiplication */
00304   static INLINE void ComplexMult(real_t *y1, real_t *y2,
00305       real_t x1, real_t x2, real_t c1, real_t c2)
00306   {
00307       *y1 = MUL_F(x1, c1) + MUL_F(x2, c2);
00308       *y2 = MUL_F(x2, c1) - MUL_F(x1, c2);
00309   }
00310 
00311 
00312   #if defined(_WIN32) && !defined(__MINGW32__)
00313     #define HAS_LRINTF
00314     static INLINE int lrintf(float f)
00315     {
00316         int i;
00317         __asm
00318         {
00319             fld   f
00320             fistp i
00321         }
00322         return i;
00323     }
00324   #elif (defined(__i386__) && defined(__GNUC__))
00325     #define HAS_LRINTF
00326     // from http://www.stereopsis.com/FPU.html
00327     static INLINE int lrintf(float f)
00328     {
00329         int i;
00330         __asm__ __volatile__ (
00331             "flds %1        \n\t"
00332             "fistpl %0      \n\t"
00333             : "=m" (i)
00334             : "m" (f));
00335         return i;
00336     }
00337   #endif
00338 
00339 
00340   #ifdef __ICL /* only Intel C compiler has fmath ??? */
00341 
00342     #include <mathf.h>
00343 
00344     #define sin sinf
00345     #define cos cosf
00346     #define log logf
00347     #define floor floorf
00348     #define ceil ceilf
00349     #define sqrt sqrtf
00350 
00351   #else
00352 
00353 #ifdef HAVE_LRINTF
00354 #  define HAS_LRINTF
00355 #  define _ISOC9X_SOURCE 1
00356 #  define _ISOC99_SOURCE 1
00357 #  define __USE_ISOC9X   1
00358 #  define __USE_ISOC99   1
00359 #endif
00360 
00361     #include <math.h>
00362 
00363 #ifdef HAVE_SINF
00364 #  define sin sinf
00365 #error
00366 #endif
00367 #ifdef HAVE_COSF
00368 #  define cos cosf
00369 #endif
00370 #ifdef HAVE_LOGF
00371 #  define log logf
00372 #endif
00373 #ifdef HAVE_EXPF
00374 #  define exp expf
00375 #endif
00376 #ifdef HAVE_FLOORF
00377 #  define floor floorf
00378 #endif
00379 #ifdef HAVE_CEILF
00380 #  define ceil ceilf
00381 #endif
00382 #ifdef HAVE_SQRTF
00383 #  define sqrt sqrtf
00384 #endif
00385 
00386   #endif
00387 
00388 #endif
00389 
00390 #ifndef HAS_LRINTF
00391 /* standard cast */
00392 #define lrintf(f) ((int32_t)(f))
00393 #endif
00394 
00395 typedef real_t complex_t[2];
00396 #define RE(A) A[0]
00397 #define IM(A) A[1]
00398 
00399 
00400 /* common functions */
00401 uint8_t cpu_has_sse(void);
00402 uint32_t random_int(void);
00403 uint32_t ones32(uint32_t x);
00404 uint32_t floor_log2(uint32_t x);
00405 uint32_t wl_min_lzc(uint32_t x);
00406 #ifdef FIXED_POINT
00407 #define LOG2_MIN_INF REAL_CONST(-10000)
00408 int32_t log2_int(uint32_t val);
00409 int32_t log2_fix(uint32_t val);
00410 int32_t pow2_int(real_t val);
00411 real_t pow2_fix(real_t val);
00412 #endif
00413 uint8_t get_sr_index(const uint32_t samplerate);
00414 uint8_t max_pred_sfb(const uint8_t sr_index);
00415 uint8_t max_tns_sfb(const uint8_t sr_index, const uint8_t object_type,
00416                     const uint8_t is_short);
00417 uint32_t get_sample_rate(const uint8_t sr_index);
00418 int8_t can_decode_ot(const uint8_t object_type);
00419 
00420 void *faad_malloc(size_t size);
00421 void faad_free(void *b);
00422 
00423 //#define PROFILE
00424 #ifdef PROFILE
00425 static int64_t faad_get_ts()
00426 {
00427     __asm
00428     {
00429         rdtsc
00430     }
00431 }
00432 #endif
00433 
00434 #ifndef M_PI
00435 #define M_PI 3.14159265358979323846
00436 #endif
00437 #ifndef M_PI_2 /* PI/2 */
00438 #define M_PI_2 1.57079632679489661923
00439 #endif
00440 
00441 
00442 #ifdef __cplusplus
00443 }
00444 #endif
00445 #endif

Generated on Tue Dec 13 14:47:13 2005 for guliverkli by  doxygen 1.4.5