• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 /* -----------------------------------------------------------------------------------------------------------
3 Software License for The Fraunhofer FDK AAC Codec Library for Android
4 
5 � Copyright  1995 - 2012 Fraunhofer-Gesellschaft zur F�rderung der angewandten Forschung e.V.
6   All rights reserved.
7 
8  1.    INTRODUCTION
9 The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software that implements
10 the MPEG Advanced Audio Coding ("AAC") encoding and decoding scheme for digital audio.
11 This FDK AAC Codec software is intended to be used on a wide variety of Android devices.
12 
13 AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient general perceptual
14 audio codecs. AAC-ELD is considered the best-performing full-bandwidth communications codec by
15 independent studies and is widely deployed. AAC has been standardized by ISO and IEC as part
16 of the MPEG specifications.
17 
18 Patent licenses for necessary patent claims for the FDK AAC Codec (including those of Fraunhofer)
19 may be obtained through Via Licensing (www.vialicensing.com) or through the respective patent owners
20 individually for the purpose of encoding or decoding bit streams in products that are compliant with
21 the ISO/IEC MPEG audio standards. Please note that most manufacturers of Android devices already license
22 these patent claims through Via Licensing or directly from the patent owners, and therefore FDK AAC Codec
23 software may already be covered under those patent licenses when it is used for those licensed purposes only.
24 
25 Commercially-licensed AAC software libraries, including floating-point versions with enhanced sound quality,
26 are also available from Fraunhofer. Users are encouraged to check the Fraunhofer website for additional
27 applications information and documentation.
28 
29 2.    COPYRIGHT LICENSE
30 
31 Redistribution and use in source and binary forms, with or without modification, are permitted without
32 payment of copyright license fees provided that you satisfy the following conditions:
33 
34 You must retain the complete text of this software license in redistributions of the FDK AAC Codec or
35 your modifications thereto in source code form.
36 
37 You must retain the complete text of this software license in the documentation and/or other materials
38 provided with redistributions of the FDK AAC Codec or your modifications thereto in binary form.
39 You must make available free of charge copies of the complete source code of the FDK AAC Codec and your
40 modifications thereto to recipients of copies in binary form.
41 
42 The name of Fraunhofer may not be used to endorse or promote products derived from this library without
43 prior written permission.
44 
45 You may not charge copyright license fees for anyone to use, copy or distribute the FDK AAC Codec
46 software or your modifications thereto.
47 
48 Your modified versions of the FDK AAC Codec must carry prominent notices stating that you changed the software
49 and the date of any change. For modified versions of the FDK AAC Codec, the term
50 "Fraunhofer FDK AAC Codec Library for Android" must be replaced by the term
51 "Third-Party Modified Version of the Fraunhofer FDK AAC Codec Library for Android."
52 
53 3.    NO PATENT LICENSE
54 
55 NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without limitation the patents of Fraunhofer,
56 ARE GRANTED BY THIS SOFTWARE LICENSE. Fraunhofer provides no warranty of patent non-infringement with
57 respect to this software.
58 
59 You may use this FDK AAC Codec software or modifications thereto only for purposes that are authorized
60 by appropriate patent licenses.
61 
62 4.    DISCLAIMER
63 
64 This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright holders and contributors
65 "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, including but not limited to the implied warranties
66 of merchantability and fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
67 CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary, or consequential damages,
68 including but not limited to procurement of substitute goods or services; loss of use, data, or profits,
69 or business interruption, however caused and on any theory of liability, whether in contract, strict
70 liability, or tort (including negligence), arising in any way out of the use of this software, even if
71 advised of the possibility of such damage.
72 
73 5.    CONTACT INFORMATION
74 
75 Fraunhofer Institute for Integrated Circuits IIS
76 Attention: Audio and Multimedia Departments - FDK AAC LL
77 Am Wolfsmantel 33
78 91058 Erlangen, Germany
79 
80 www.iis.fraunhofer.de/amm
81 amm-info@iis.fraunhofer.de
82 ----------------------------------------------------------------------------------------------------------- */
83 
84 /**************************  Fraunhofer IIS FDK SysLib  **********************
85 
86    Author(s):
87 
88 ******************************************************************************/
89 
90 /** \file   genericStds.h
91     \brief  Generic Run-Time Support function wrappers and heap allocation monitoring.
92  */
93 
94 #if !defined(__GENERICSTDS_H__)
95 #define __GENERICSTDS_H__
96 
97 #include "machine_type.h"
98 
99 /* Work around for broken android toolchain: sys/types.h:137: error: 'uint64_t' does not name a type */
100 #define _SYS_TYPES_H_
101 
102 
103 /* Always increase verbosity of memory allocation in case of a debug built. DEBUG is defined globally in that case. */
104 #if defined(DEBUG) || defined(FDK_DEBUG)
105 //#define MEMORY_MEASUREMENT
106 #endif
107 
108 #ifndef M_PI
109   #define M_PI   3.14159265358979323846  /*! Pi. Only used in example projects. */
110 #endif
111 
112 
113 /* #define _CRT_SECURE_NO_DEPRECATE */
114 
115 
116 /**
117  * Identifiers for various memory locations. They are used along with memory allocation
118  * functions like FDKcalloc_L() to specify the requested memory's location.
119  */
120 typedef enum {
121   /* Internal */
122   SECT_DATA_L1 = 0x2000,
123   SECT_DATA_L2,
124   SECT_DATA_L1_A,
125   SECT_DATA_L1_B,
126   SECT_CONSTDATA_L1,
127 
128   /* External */
129   SECT_DATA_EXTERN = 0x4000,
130   SECT_CONSTDATA_EXTERN
131 
132 } MEMORY_SECTION;
133 
134 
135 /**
136  * The H_ prefix indicates header file version, the C_* prefix indicates the corresponding
137  * object version.
138  *
139  * Declaring memory areas requires to specify a unique name and a data type. Use the H_ macro
140  * for this purpose inside a header file.
141  *
142  * For defining a memory area your require additionally one or two sizes, depending if the
143  * memory should be organized into one or two dimensions.
144  *
145  * The macros containing the keyword AALLOC instead of ALLOC also do take care of returning
146  * aligned memory addresses (beyond the natural alignment of its type). The preprocesor macro
147  * ::ALIGNMENT_DEFAULT indicates the aligment to be used (this is hardware specific).
148  *
149  * The _L suffix indicates that the memory will be located in a specific section. This is
150  * useful to allocate critical memory section into fast internal SRAM for example.
151  *
152  */
153 
154 #define H_ALLOC_MEM(name,type)          type * Get ## name(int n=0); void Free ## name(type** p); \
155                                         UINT GetRequiredMem ## name(void);
156 
157 /** See #H_ALLOC_MEM for description. */
158 #define H_ALLOC_MEM_OVERLAY(name,type)  type * Get ## name(int n=0); void Free ## name(type** p); \
159                                         UINT GetRequiredMem ## name(void);
160 
161 
162   /** See #H_ALLOC_MEM for description. */
163   #define C_ALLOC_MEM(name,type,num) \
164     type * Get ## name(int n) { FDK_ASSERT((n) == 0); return ((type*)FDKcalloc(num, sizeof(type))); } \
165     void Free ## name(type** p) { if (p != NULL) { FDKfree(*p); *p=NULL; } } \
166     UINT GetRequiredMem ## name(void) { return ALGN_SIZE_EXTRES((num) * sizeof(type)); }
167 
168   /** See #H_ALLOC_MEM for description. */
169   #define C_ALLOC_MEM_STATIC(name,type,num) \
170     static type * Get ## name(int n) { FDK_ASSERT((n) == 0); return ((type*)FDKcalloc(num, sizeof(type))); } \
171     static void Free ## name(type** p) { if (p != NULL) { FDKfree(*p); *p=NULL; } } \
172     static UINT GetRequiredMem ## name(void) { return ALGN_SIZE_EXTRES((num) * sizeof(type)); }
173 
174   /** See #H_ALLOC_MEM for description. */
175   #define C_ALLOC_MEM2(name,type,n1,n2) \
176     type * Get ## name (int n) { FDK_ASSERT((n) < (n2)); return ((type*)FDKcalloc(n1, sizeof(type))); } \
177     void Free ## name(type** p) { if (p != NULL) { FDKfree(*p); *p=NULL; } } \
178     UINT GetRequiredMem ## name(void) { return ALGN_SIZE_EXTRES((n1) * sizeof(type)) * (n2); }
179 
180   /** See #H_ALLOC_MEM for description. */
181   #define C_AALLOC_MEM(name,type,num) \
182     type * Get ## name(int n) { FDK_ASSERT((n) == 0); return ((type*)FDKaalloc((num)*sizeof(type), ALIGNMENT_DEFAULT)); } \
183     void Free ## name(type** p) { if (p != NULL) { FDKafree(*p); *p=NULL; } } \
184     UINT GetRequiredMem ## name(void) { return ALGN_SIZE_EXTRES((num) * sizeof(type) + ALIGNMENT_DEFAULT + sizeof(void *)); }
185 
186   /** See #H_ALLOC_MEM for description. */
187   #define C_AALLOC_MEM2(name,type,n1,n2) \
188     type * Get ## name (int n) { FDK_ASSERT((n) < (n2)); return ((type*)FDKaalloc((n1)*sizeof(type), ALIGNMENT_DEFAULT)); } \
189     void Free ## name(type** p) { if (p != NULL) { FDKafree(*p); *p=NULL; } } \
190     UINT GetRequiredMem ## name(void) { return ALGN_SIZE_EXTRES((n1) * sizeof(type) + ALIGNMENT_DEFAULT + sizeof(void *)) * (n2); }
191 
192   /** See #H_ALLOC_MEM for description. */
193   #define C_ALLOC_MEM_L(name,type,num,s) \
194     type * Get ## name(int n) { FDK_ASSERT((n) == 0); return ((type*)FDKcalloc_L(num, sizeof(type), s)); } \
195     void Free ## name(type** p) { if (p != NULL) { FDKfree_L(*p); *p=NULL; } } \
196     UINT GetRequiredMem ## name(void) { return ALGN_SIZE_EXTRES((num) * sizeof(type)); }
197 
198   /** See #H_ALLOC_MEM for description. */
199   #define C_ALLOC_MEM2_L(name,type,n1,n2,s) \
200     type * Get ## name (int n) { FDK_ASSERT((n) < (n2)); return (type*)FDKcalloc_L(n1, sizeof(type), s); } \
201     void Free ## name(type** p) { if (p != NULL) { FDKfree_L(*p); *p=NULL; } } \
202     UINT GetRequiredMem ## name(void) { return ALGN_SIZE_EXTRES((n1) * sizeof(type)) * (n2); }
203 
204   /** See #H_ALLOC_MEM for description. */
205   #define C_AALLOC_MEM_L(name,type,num,s) \
206     type * Get ## name(int n) { FDK_ASSERT((n) == 0); return ((type*)FDKaalloc_L((num)*sizeof(type), ALIGNMENT_DEFAULT, s)); } \
207     void Free ## name(type** p) { if (p != NULL) { FDKafree_L(*p); *p=NULL; } } \
208     UINT GetRequiredMem ## name(void) { return ALGN_SIZE_EXTRES((num) * sizeof(type) + ALIGNMENT_DEFAULT + sizeof(void *)); }
209 
210   /** See #H_ALLOC_MEM for description. */
211   #define C_AALLOC_MEM2_L(name,type,n1,n2,s) \
212     type * Get ## name (int n) { FDK_ASSERT((n) < (n2)); return ((type*)FDKaalloc_L((n1)*sizeof(type), ALIGNMENT_DEFAULT, s)); } \
213     void Free ## name(type** p) { if (p != NULL) { FDKafree_L(*p); *p=NULL; } } \
214     UINT GetRequiredMem ## name(void) { return ALGN_SIZE_EXTRES((n1) * sizeof(type) + ALIGNMENT_DEFAULT + sizeof(void *)) * (n2); }
215 
216 /** See #H_ALLOC_MEM_OVERLAY for description. */
217 
218 
219   #define C_ALLOC_MEM_OVERLAY(name,type,num,sect,tag) C_AALLOC_MEM_L(name,type,num,sect)
220 
221 
222    #define C_AALLOC_SCRATCH_START(name,type,n) \
223      type _ ## name[(n)+(ALIGNMENT_DEFAULT+sizeof(type)-1)]; \
224      type * name = (type*)ALIGN_PTR(_ ## name); \
225 
226    #define C_ALLOC_SCRATCH_START(name,type,n) \
227      type name[n];
228 
229    #define C_AALLOC_SCRATCH_END(name,type,n)
230    #define C_ALLOC_SCRATCH_END(name,type,n)
231 
232 
233 /*--------------------------------------------
234  * Runtime support declarations
235  *---------------------------------------------*/
236 #ifdef __cplusplus
237 extern "C" {
238 #endif
239 
240 /** printf() using stdout. If ::ARCH_WA_FLUSH_CONSOLE defined, a flush is  done additionally after printf(). */
241 void FDKprintf    ( const char* szFmt, ...);
242 
243 /** printf() using stderr. If ::ARCH_WA_FLUSH_CONSOLE defined, a flush is done additionally after printf(). */
244 void FDKprintfErr ( const char* szFmt, ...);
245 
246 /** Wrapper for <stdio.h>'s getchar(). */
247 int FDKgetchar(void);
248 
249 INT  FDKfprintf(void  *stream,  const  char *format, ...);
250 INT  FDKsprintf(char *str, const char *format, ...);
251 
252 
253 
254 const char *FDKstrchr(const char *s, INT c);
255 const char *FDKstrstr(const char *haystack, const char *needle);
256 char *FDKstrcpy(char *dest, const char *src);
257 char *FDKstrncpy(char *dest, const char *src, const UINT n);
258 
259 #define FDK_MAX_OVERLAYS 8   /**< Maximum number of memory overlays. */
260 
261 
262 void *FDKcalloc (const UINT n, const UINT size);
263 void *FDKmalloc (const UINT size);
264 void  FDKfree   (void *ptr);
265 
266 /**
267  *  Allocate and clear an aligned memory area. Use FDKafree() instead of FDKfree() for these memory areas.
268  *
269  * \param size       Size of requested memory in bytes.
270  * \param alignment  Alignment of requested memory in bytes.
271  * \return           Pointer to allocated memory.
272  */
273 void *FDKaalloc (const UINT size, const UINT alignment);
274 
275 /**
276  *  Free an aligned memory area.
277  *
278  * \param ptr  Pointer to be freed.
279  * \return     void
280  */
281 void FDKafree (void *ptr);
282 
283 
284 /**
285  *  Allocate memory in a specific memory section.
286  *  Requests can be made for internal or external memory. If internal memory is
287  *  requested, FDKcalloc_L() first tries to use L1 memory, which sizes are defined
288  *  by ::DATA_L1_A_SIZE and ::DATA_L1_B_SIZE. If no L1 memory is available, then
289  *  FDKcalloc_L() tries to use L2 memory. If that fails as well, the requested
290  *  memory is allocated at an extern location using the fallback FDKcalloc().
291  *
292  * \param n     See MSDN documentation on calloc().
293  * \param size  See MSDN documentation on calloc().
294  * \param s     Memory section.
295  * \return      See MSDN documentation on calloc().
296  */
297 void *FDKcalloc_L(const UINT n, const UINT size, MEMORY_SECTION s);
298 
299 /**
300  *  Allocate aligned memory in a specific memory section.
301  *  See FDKcalloc_L() description for details - same applies here.
302  */
303 void *FDKaalloc_L(const UINT size, const UINT alignment, MEMORY_SECTION s);
304 
305 /**
306  *  Free memory that was allocated in a specific memory section.
307  */
308 void  FDKfree_L(void *ptr);
309 
310 /**
311  *  Free aligned memory that was allocated in a specific memory section.
312  */
313 void  FDKafree_L(void *ptr);
314 
315 
316 /**
317  * Copy memory. Source and destination memory must not overlap.
318  * Either use implementation from a Standard Library, or, if no Standard Library
319  * is available, a generic implementation.
320  * The define ::USE_BUILTIN_MEM_FUNCTIONS in genericStds.cpp controls what to use.
321  * The function arguments correspond to the standard memcpy(). Please see MSDN
322  * documentation for details on how to use it.
323  */
324 void FDKmemcpy(void *dst, const void *src, const UINT size);
325 
326 /**
327  * Copy memory. Source and destination memory are allowed to overlap.
328  * Either use implementation from a Standard Library, or, if no Standard Library
329  * is available, a generic implementation.
330  * The define ::USE_BUILTIN_MEM_FUNCTIONS in genericStds.cpp controls what to use.
331  * The function arguments correspond to the standard memmove(). Please see MSDN
332  * documentation for details on how to use it.
333 */
334 void FDKmemmove(void *dst, const void *src, const UINT size);
335 
336 /**
337  * Clear memory.
338  * Either use implementation from a Standard Library, or, if no Standard Library
339  * is available, a generic implementation.
340  * The define ::USE_BUILTIN_MEM_FUNCTIONS in genericStds.cpp controls what to use.
341  * The function arguments correspond to the standard memclear(). Please see MSDN
342  * documentation for details on how to use it.
343 */
344 void FDKmemclear(void *memPtr, const UINT size);
345 
346 /**
347  * Fill memory with values.
348  * The function arguments correspond to the standard memset(). Please see MSDN
349  * documentation for details on how to use it.
350  */
351 void FDKmemset(void *memPtr, const INT value, const UINT size);
352 
353 /* Compare function wrappers */
354 INT   FDKmemcmp(const void *s1, const void *s2, const UINT size);
355 INT   FDKstrcmp(const char *s1, const char *s2);
356 INT   FDKstrncmp(const char *s1, const char *s2, const UINT size);
357 
358 UINT  FDKstrlen(const char *s);
359 
360 #define FDKmax(a,b) ( (a) > (b) ? (a):(b))
361 #define FDKmin(a,b) ( (a) < (b) ? (a):(b))
362 
363 #define FDK_INT_MAX ((INT)0x7FFFFFFF)
364 #define FDK_INT_MIN ((INT)0x80000000)
365 
366 /* Math function wrappers. Only intended for compatibility, not to be highly optimized. */
367 /* Used for debugging, dev code .. */
368 
369 INT FDKabs(INT j);
370 double FDKfabs(double x);
371 double FDKpow(double x, double y);
372 double FDKsqrt(double x);
373 double FDKatan(double x);
374 double FDKlog(double x);
375 double FDKsin(double x);
376 double FDKcos(double x);
377 double FDKexp(double x);
378 #define FDKlog2(a) (FDKlog(a)*1.442695041) /* log(2.0) = 1.442695041 */
379 #define FDKlog10(a) (FDKlog(a)*0.434294482) /* 1.0/log(10.0) = 0.434294482 */
380 double FDKatan2(double y, double x);
381 double FDKacos(double x);
382 double FDKtan(double x);
383 double FDKfloor(double x);
384 double FDKceil(double x);
385 INT   FDKatoi(const char *nptr);
386 long  FDKatol(const char *nptr);
387 float FDKatof(const char *nptr);
388 /* LONG LONG FDKatoll(const char *nptr); */
389 /* LONG LONG FDKatoq(const char *nptr); */
390 
391 
392 
393 /* FILE I/O */
394 
395 /*!
396  *  Check platform for endianess.
397  *
398  * \return  1 if platform is little endian, non-1 if platform is big endian.
399  */
400 #ifdef __cplusplus
401 inline
402 #else
403 static
404 #endif
IS_LITTLE_ENDIAN(void)405 int IS_LITTLE_ENDIAN(void) {
406   int __dummy = 1;
407   return ( *( (UCHAR*)(&(__dummy) ) ) );
408 }
409 
410 /*!
411  *  Convert input value to little endian format.
412  *
413  * \param val  Value to be converted. It may be in both big or little endian.
414  * \return     Value in little endian format.
415  */
416 #define TO_LITTLE_ENDIAN(val) \
417   ( (IS_LITTLE_ENDIAN()) ? \
418      (val) \
419    : ( (((val) & 0xff) << 24) || (((val) & 0xff00)<< 8) || (((val) & 0xff0000)>>8) || (((val) & 0xff000000) >> 24) ) )
420 
421 
422 /*!
423  * \fn     FDKFILE *FDKfopen(const char *filename, const char *mode);
424  *         Standard fopen() wrapper.
425  * \fn     INT FDKfclose(FDKFILE *FP);
426  *         Standard fclose() wrapper.
427  * \fn     INT FDKfseek(FDKFILE *FP, LONG OFFSET, int WHENCE);
428  *         Standard fseek() wrapper.
429  * \fn     INT FDKftell(FDKFILE *FP);
430  *         Standard ftell() wrapper.
431  * \fn     INT FDKfflush(FDKFILE *fp);
432  *         Standard fflush() wrapper.
433  * \fn     UINT FDKfwrite(void *ptrf, INT size, UINT nmemb, FDKFILE *fp);
434  *         Standard fwrite() wrapper.
435  * \fn     UINT FDKfread(void *dst, INT size, UINT nmemb, FDKFILE *fp);
436  *         Standard fread() wrapper.
437  */
438 typedef void FDKFILE;
439 extern const INT FDKSEEK_SET, FDKSEEK_CUR, FDKSEEK_END;
440 
441 FDKFILE *FDKfopen(const char *filename, const char *mode);
442 INT FDKfclose(FDKFILE *FP);
443 INT FDKfseek(FDKFILE *FP, LONG OFFSET, int WHENCE);
444 INT FDKftell(FDKFILE *FP);
445 INT FDKfflush(FDKFILE *fp);
446 UINT FDKfwrite(void *ptrf, INT size, UINT nmemb, FDKFILE *fp);
447 UINT FDKfread(void *dst, INT size, UINT nmemb, FDKFILE *fp);
448 char* FDKfgets(void *dst, INT size, FDKFILE *fp);
449 void FDKrewind(FDKFILE *fp);
450 INT FDKfeof(FDKFILE *fp);
451 
452 /**
453  * \brief        Write each member in little endian order. Convert automatically to host endianess.
454  * \param ptrf   Pointer to memory where to read data from.
455  * \param size   Size of each item to be written.
456  * \param nmemb  Number of items to be written.
457  * \param fp     File pointer of type FDKFILE.
458  * \return       Number of items read on success and fread() error on failure.
459  */
460 UINT FDKfwrite_EL(void *ptrf, INT size, UINT nmemb, FDKFILE *fp);
461 
462 /**
463  * \brief        Read variable of size "size" as little endian. Convert automatically to host endianess.
464  *                4-byte alignment is enforced for 24 bit data, at 32 bit full scale.
465  * \param dst    Pointer to memory where to store data into.
466  * \param size   Size of each item to be read.
467  * \param nmemb  Number of items to be read.
468  * \param fp     File pointer of type FDKFILE.
469  * \return       Number of items read on success and fread() error on failure.
470  */
471 UINT FDKfread_EL(void *dst, INT size, UINT nmemb, FDKFILE *fp);
472 
473 
474 /**
475  * \brief  Print FDK software disclaimer.
476  */
477 void FDKprintDisclaimer(void);
478 
479 #ifdef __cplusplus
480 }
481 #endif
482 
483 #endif /* __GENERICSTDS_H__ */
484