2 /* -----------------------------------------------------------------------------------------------------------
3 Software License for The Fraunhofer FDK AAC Codec Library for Android
5 © Copyright 1995 - 2013 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V.
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.
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.
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.
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.
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:
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.
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.
42 The name of Fraunhofer may not be used to endorse or promote products derived from this library without
43 prior written permission.
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.
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."
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.
59 You may use this FDK AAC Codec software or modifications thereto only for purposes that are authorized
60 by appropriate patent licenses.
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.
73 5. CONTACT INFORMATION
75 Fraunhofer Institute for Integrated Circuits IIS
76 Attention: Audio and Multimedia Departments - FDK AAC LL
78 91058 Erlangen, Germany
80 www.iis.fraunhofer.de/amm
81 amm-info@iis.fraunhofer.de
82 ----------------------------------------------------------------------------------------------------------- */
84 /************************** Fraunhofer IIS FDK SysLib **********************
87 Description: - Generic memory, stdio, string, etc. function wrappers or
89 - OS dependant function wrappers.
91 ******************************************************************************/
93 #define _CRT_SECURE_NO_WARNINGS
95 #include "genericStds.h"
100 #define SYS_LIB_VL0 1
101 #define SYS_LIB_VL1 3
102 #define SYS_LIB_VL2 4
103 #define SYS_LIB_TITLE "System Integration Library"
104 #define SYS_LIB_BUILD_DATE __DATE__
105 #define SYS_LIB_BUILD_TIME __TIME__
113 /***************************************************************
114 * memory allocation monitoring variables
115 ***************************************************************/
118 /* Include OS/System specific implementations. */
119 #if defined(__linux__) /* cppp replaced: elif */
120 #include "linux/genericStds_linux.cpp"
124 #if !(defined(USE_BUILTIN_STRING_FUNCTIONS) || defined(__SYMBIAN32__))
129 #ifndef FUNCTION_FDKprintf
130 void FDKprintf( const char* szFmt
, ...) {
135 #ifdef ARCH_WA_FLUSH_CONSOLE
141 #ifndef FUNCTION_FDKprintfErr
142 void FDKprintfErr( const char* szFmt
, ...) {
145 #if defined(ARCH_WA_SLOWCON)
148 vfprintf(stderr
, szFmt
, ap
);
151 #ifdef ARCH_WA_FLUSH_CONSOLE
157 int FDKgetchar(void) { return getchar(); }
159 INT
FDKfprintf(FDKFILE
*stream
, const char *format
, ...) {
162 va_start(ap
, format
);
163 chars
+= vfprintf((FILE*)stream
, format
, ap
);
168 #ifndef FUNCTION_FDKsprintf
169 INT
FDKsprintf(char *str
, const char *format
, ...) {
172 va_start(ap
, format
);
173 chars
+= vsprintf(str
, format
, ap
);
181 void FDKprintf( const char* szFmt
, ...) { /* stub! */; }
182 void FDKprintfErr( const char* szFmt
, ...) { /* stub! */; }
183 INT
FDKfprintf(FILE *stream
, const char *format
, ...) { /*stub ! */; }
184 INT
FDKsprintf(char *str
, const char *format
, ...) { /* stub! */; }
188 /************************************************************************************************/
191 const char *FDKstrchr(const char *s
, INT c
) { return strchr(s
, c
); }
192 const char *FDKstrstr(const char *haystack
, const char *needle
) { return strstr(haystack
, needle
); }
193 #ifndef FUNCTION_FDKstrcpy
194 char *FDKstrcpy(char *dest
, const char *src
) { return strcpy(dest
, src
); }
196 char *FDKstrncpy(char *dest
, const char *src
, UINT n
) { return strncpy(dest
, src
, n
); }
198 /*************************************************************************
199 * DYNAMIC MEMORY management (heap)
200 *************************************************************************/
202 #ifndef FUNCTION_FDKcalloc
203 void *FDKcalloc (const UINT n
, const UINT size
)
207 ptr
= calloc(n
, size
);
213 #ifndef FUNCTION_FDKmalloc
214 void *FDKmalloc (const UINT size
)
224 #ifndef FUNCTION_FDKfree
225 void FDKfree (void *ptr
)
227 /* FDKprintf("f, heapSize: %d\n", heapSizeCurr); */
232 #ifndef FUNCTION_FDKaalloc
233 void *FDKaalloc(const UINT size
, const UINT alignment
)
235 void *addr
, *result
=NULL
;
236 addr
= FDKcalloc(1, size
+ alignment
+ sizeof(void*)); /* Malloc and clear memory. */
240 result
= ALIGN_PTR((unsigned char*)addr
+ sizeof(void*)); /* Get aligned memory base address. */
241 *(((void**)result
) - 1) = addr
; /* Save malloc'ed memory pointer. */
244 return result
; /* Return aligned address. */
248 #ifndef FUNCTION_FDKafree
249 void FDKafree (void *ptr
)
252 addr
= *(((void**)ptr
)-1); /* Get pointer to malloc'ed memory. */
253 FDKfree(addr
); /* Free malloc'ed memory area. */
258 #ifndef FUNCTION_FDKcalloc_L
260 /*--------------------------------------------------------------------------*
261 * DATA MEMORY L1/L2 (fallback)
262 *--------------------------------------------------------------------------*/
266 /*--------------------------------------------------------------------------*
268 *--------------------------------------------------------------------------*/
269 void *FDKcalloc_L(const UINT dim
, const UINT size
, MEMORY_SECTION s
)
273 if (s
== SECT_DATA_EXTERN
)
276 a_size
= ((dim
*size
+3)&0xfffffffc); /* force 4 byte alignment (1111 .... 1111 1100) */
282 //printf("Warning, out of internal memory\n");
285 return FDKcalloc(dim
, size
);
287 #endif /* FUNCTION_FDKcalloc_L */
289 #ifndef FUNCTION_FDKfree_L
290 void FDKfree_L (void *p
)
295 #endif /* FUNCTION_FDKfree_L */
297 #ifndef FUNCTION_FDKaalloc_L
298 void *FDKaalloc_L(const UINT size
, const UINT alignment
, MEMORY_SECTION s
)
300 void *addr
, *result
=NULL
;
301 addr
= FDKcalloc_L(1, size
+ alignment
+ sizeof(void*), s
); /* Malloc and clear memory. */
305 result
= ALIGN_PTR((unsigned char *)addr
+ sizeof(void*)); /* Get aligned memory base address. */
306 *(((void**)result
) - 1) = addr
; /* Save malloc'ed memory pointer. */
309 return result
; /* Return aligned address. */
313 #ifndef FUNCTION_FDKafree_L
314 void FDKafree_L (void *ptr
)
318 addr
= *(((void**)ptr
)-1); /* Get pointer to malloc'ed memory. */
319 FDKfree_L(addr
); /* Free malloc'ed memory area. */
325 /*---------------------------------------------------------------------------------------
326 * FUNCTION: FDKmemcpy
327 * DESCRIPTION: - copies memory from "src" to "dst" with length "size" bytes
328 * - compiled with FDK_DEBUG will give you warnings
329 *---------------------------------------------------------------------------------------*/
330 void FDKmemcpy(void *dst
, const void *src
, const UINT size
)
334 memcpy(dst
, src
, size
);
337 void FDKmemmove(void *dst
, const void *src
, const UINT size
) { memmove(dst
, src
, size
); }
338 void FDKmemset(void *memPtr
, const INT value
, const UINT size
) { memset(memPtr
, value
, size
); }
339 void FDKmemclear(void *memPtr
, const UINT size
) { FDKmemset(memPtr
,0,size
); }
340 UINT
FDKstrlen(const char *s
) { return (UINT
)strlen(s
); }
342 /* Compare function wrappers */
343 INT
FDKmemcmp(const void *s1
, const void *s2
, const UINT size
) { return memcmp(s1
, s2
, size
); }
344 INT
FDKstrcmp(const char *s1
, const char *s2
) { return strcmp(s1
, s2
); }
345 INT
FDKstrncmp(const char *s1
, const char *s2
, const UINT size
) { return strncmp(s1
, s2
, size
); }
348 /* Math function wrappers. Only intended for compatibility, not to be highly optimized. */
350 INT
FDKabs(INT j
) { return abs(j
); }
351 double FDKfabs(double x
) { return fabs(x
); }
352 double FDKpow(double x
, double y
) { return pow(x
,y
); }
353 double FDKsqrt(double x
) { return sqrt(x
); }
354 double FDKatan(double x
) { return atan(x
); }
355 double FDKlog(double x
) { return log(x
); }
356 double FDKsin(double x
) { return sin(x
); }
357 double FDKcos(double x
) { return cos(x
); }
358 double FDKexp(double x
) { return exp(x
); }
359 double FDKatan2(double y
, double x
) { return atan2(y
, x
); }
360 double FDKacos(double x
) { return acos(x
); }
361 double FDKtan(double x
) { return tan(x
); }
362 double FDKfloor(double x
) { return floor(x
); }
363 double FDKceil(double x
) { return ceil(x
); }
365 INT
FDKatoi(const char *nptr
) { return atoi(nptr
); }
366 long FDKatol(const char *nptr
) { return atol(nptr
); }
367 float FDKatof(const char *nptr
) { return (float)atof(nptr
); }
370 /* ==================== FILE I/O ====================== */
372 #if !defined(FUNCTION_FDKfopen)
373 FDKFILE
*FDKfopen(const char *filename
, const char *mode
) { return fopen(filename
, mode
); }
375 #if !defined(FUNCTION_FDKfclose)
376 INT
FDKfclose(FDKFILE
*fp
) { return fclose((FILE*)fp
);}
378 #if !defined(FUNCTION_FDKfseek)
379 INT
FDKfseek(FDKFILE
*fp
, LONG OFFSET
, int WHENCE
) { return fseek((FILE*)fp
, OFFSET
, WHENCE
);}
381 #if !defined(FUNCTION_FDKftell)
382 INT
FDKftell(FDKFILE
*fp
) { return ftell((FILE*)fp
); }
384 #if !defined(FUNCTION_FDKfflush)
385 INT
FDKfflush(FDKFILE
*fp
) { return fflush((FILE*)fp
); }
387 const INT FDKSEEK_SET
= SEEK_SET
;
388 const INT FDKSEEK_CUR
= SEEK_CUR
;
389 const INT FDKSEEK_END
= SEEK_END
;
391 #if !defined(FUNCTION_FDKfwrite)
392 UINT
FDKfwrite(void *ptrf
, INT size
, UINT nmemb
, FDKFILE
*fp
) { return fwrite(ptrf
, size
, nmemb
, (FILE*)fp
); }
394 #if !defined(FUNCTION_FDKfread)
395 UINT
FDKfread(void *dst
, INT size
, UINT nmemb
, FDKFILE
*fp
) { return fread(dst
, size
, nmemb
, (FILE*)fp
); }
397 #if !defined(FUNCTION_FDKfgets)
398 char* FDKfgets(void *dst
, INT size
, FDKFILE
*fp
) { return fgets((char *)dst
, size
, (FILE*)fp
); }
400 #if !defined(FUNCTION_FDKrewind)
401 void FDKrewind(FDKFILE
*fp
) { FDKfseek((FILE*)fp
,0,FDKSEEK_SET
); }
405 UINT
FDKfwrite_EL(void *ptrf
, INT size
, UINT nmemb
, FDKFILE
*fp
) {
407 if (IS_LITTLE_ENDIAN()) {
408 FDKfwrite(ptrf
, size
, nmemb
, fp
);
413 UCHAR
*ptr
= (UCHAR
*) ptrf
;
415 for (n
=0; n
<nmemb
; n
++) {
416 for (s
=size
-1; s
>=0; s
--) {
417 //FDKprintf("char = %c\n", (char)*(ptr+s));
418 FDKfwrite(ptr
+ s
, 1, 1, fp
);
427 UINT
FDKfread_EL(void *dst
, INT size
, UINT nmemb
, FDKFILE
*fp
) {
432 /* Enforce alignment of 24 bit data. */
436 for (n
=0; n
<nmemb
; n
++) {
437 if ((err
= FDKfread(tmp24
, 1, 3, fp
)) != 3) {
444 if (tmp24
[2] & 0x80) {
453 if ((err
= FDKfread(dst
, size
, nmemb
, fp
)) != nmemb
) {
457 if (!IS_LITTLE_ENDIAN() && size
> 1) {
459 for (n
=0; n
<nmemb
; n
++) {
460 for (s0
=0, s1
=size
-1; s0
< s1
; s0
++, s1
--) {
471 INT
FDKfeof(FDKFILE
*fp
) { return feof((FILE*)fp
); }
473 /* Global initialization/cleanup */
475 #if defined(_DEBUG) && defined(_WIN32) && !defined(_WIN32_WCE)
476 #define _CRTDBG_MAP_ALLOC
483 void FDKprintDisclaimer(void)
486 "This program is protected by copyright law and international treaties.\n" \
487 "Any reproduction or distribution of this program, or any portion\n" \
488 "of it, may result in severe civil and criminal penalties, and will be\n" \
489 "prosecuted to the maximum extent possible under law.\n\n");