1 2 /* ----------------------------------------------------------------------------------------------------------- 3 Software License for The Fraunhofer FDK AAC Codec Library for Android 4 5 Copyright 1995 - 2012 Fraunhofer-Gesellschaft zur Frderung 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 (at) iis.fraunhofer.de 82 ----------------------------------------------------------------------------------------------------------- */ 83 84 /************************* Fast MPEG AAC Audio Encoder ********************** 85 86 Initial author: M. Schug / A. Groeschel 87 contents/description: fast aac coder interface library functions 88 89 ******************************************************************************/ 90 91 #ifndef _aacenc_h_ 92 #define _aacenc_h_ 93 94 #include "common_fix.h" 95 #include "FDK_audio.h" 96 97 #include "tpenc_lib.h" 98 99 #include "sbr_encoder.h" 100 101 #ifdef __cplusplus 102 extern "C" { 103 #endif 104 105 /* 106 * AAC-LC error codes. 107 */ 108 typedef enum { 109 AAC_ENC_OK = 0x0000, /*!< All fine. */ 110 111 AAC_ENC_UNKNOWN = 0x0002, /*!< Error condition is of unknown reason, or from another module. */ 112 113 /* initialization errors */ 114 aac_enc_init_error_start = 0x2000, 115 AAC_ENC_INVALID_HANDLE = 0x2020, /*!< The handle passed to the function call was invalid (probably NULL). */ 116 AAC_ENC_INVALID_FRAME_LENGTH = 0x2080, /*!< Invalid frame length (must be 1024 or 960). */ 117 AAC_ENC_INVALID_N_CHANNELS = 0x20e0, /*!< Invalid amount of audio input channels. */ 118 AAC_ENC_INVALID_SFB_TABLE = 0x2140, /*!< Internal encoder error. */ 119 120 AAC_ENC_UNSUPPORTED_AOT = 0x3000, /*!< The Audio Object Type (AOT) is not supported. */ 121 AAC_ENC_UNSUPPORTED_BITRATE = 0x3020, /*!< The chosen bitrate is not supported. */ 122 AAC_ENC_UNSUPPORTED_BITRATE_MODE = 0x3028, /*!< Unsupported bit rate mode (CBR or VBR). */ 123 AAC_ENC_UNSUPPORTED_ANC_BITRATE = 0x3040, /*!< Unsupported ancillay bitrate. */ 124 AAC_ENC_UNSUPPORTED_ANC_MODE = 0x3060, 125 AAC_ENC_UNSUPPORTED_TRANSPORT_TYPE = 0x3080, /*!< The bitstream format is not supported. */ 126 AAC_ENC_UNSUPPORTED_ER_FORMAT = 0x30a0, /*!< The error resilience tool format is not supported. */ 127 AAC_ENC_UNSUPPORTED_EPCONFIG = 0x30c0, /*!< The error protection format is not supported. */ 128 AAC_ENC_UNSUPPORTED_CHANNELCONFIG = 0x30e0, /*!< The channel configuration (either number or arrangement) is not supported. */ 129 AAC_ENC_UNSUPPORTED_SAMPLINGRATE = 0x3100, /*!< Sample rate of audio input is not supported. */ 130 AAC_ENC_NO_MEMORY = 0x3120, /*!< Could not allocate memory. */ 131 AAC_ENC_PE_INIT_TABLE_NOT_FOUND = 0x3140, /*!< Internal encoder error. */ 132 133 aac_enc_init_error_end, 134 135 /* encode errors */ 136 aac_enc_error_start = 0x4000, 137 AAC_ENC_QUANT_ERROR = 0x4020, /*!< Too many bits used in quantization. */ 138 AAC_ENC_WRITTEN_BITS_ERROR = 0x4040, /*!< Unexpected number of written bits, differs to 139 calculated number of bits. */ 140 AAC_ENC_PNS_TABLE_ERROR = 0x4060, /*!< PNS level out of range. */ 141 AAC_ENC_GLOBAL_GAIN_TOO_HIGH = 0x4080, /*!< Internal quantizer error. */ 142 AAC_ENC_BITRES_TOO_LOW = 0x40a0, /*!< Too few bits in bit reservoir. */ 143 AAC_ENC_BITRES_TOO_HIGH = 0x40a1, /*!< Too many bits in bit reservoir. */ 144 AAC_ENC_INVALID_CHANNEL_BITRATE = 0x4100, 145 AAC_ENC_INVALID_ELEMENTINFO_TYPE = 0x4120, /*!< Internal encoder error. */ 146 147 AAC_ENC_WRITE_SCAL_ERROR = 0x41e0, /*!< Error writing scalefacData. */ 148 AAC_ENC_WRITE_SEC_ERROR = 0x4200, /*!< Error writing sectionData. */ 149 AAC_ENC_WRITE_SPEC_ERROR = 0x4220, /*!< Error writing spectralData. */ 150 aac_enc_error_end 151 152 } AAC_ENCODER_ERROR; 153 /*-------------------------- defines --------------------------------------*/ 154 155 #define ANC_DATA_BUFFERSIZE 1024 /* ancBuffer size */ 156 #define DEFAULT_FRAMELENGTH 1024 /* size of AAC core frame in (new) PCM samples */ 157 158 #define MAX_TOTAL_EXT_PAYLOADS (((6) * (1)) + (2+2)) 159 160 161 typedef enum { 162 AACENC_BR_MODE_INVALID = -1, /*!< Invalid bitrate mode. */ 163 AACENC_BR_MODE_CBR = 0, /*!< Constant bitrate mode. */ 164 AACENC_BR_MODE_VBR_1 = 1, /*!< Variable bitrate mode, about 32 kbps/channel. */ 165 AACENC_BR_MODE_VBR_2 = 2, /*!< Variable bitrate mode, about 40 kbps/channel. */ 166 AACENC_BR_MODE_VBR_3 = 3, /*!< Variable bitrate mode, about 48-56 kbps/channel. */ 167 AACENC_BR_MODE_VBR_4 = 4, /*!< Variable bitrate mode, about 64 kbps/channel. */ 168 AACENC_BR_MODE_VBR_5 = 5, /*!< Variable bitrate mode, about 80-96 kbps/channel. */ 169 AACENC_BR_MODE_FF = 6, /*!< Fixed frame mode. */ 170 AACENC_BR_MODE_SFR = 7 /*!< Superframe mode. */ 171 172 } AACENC_BITRATE_MODE; 173 174 typedef enum { 175 176 CH_ORDER_MPEG = 0, /*!< MPEG channel ordering (e. g. 5.1: C, L, R, SL, SR, LFE) */ 177 CH_ORDER_WAV /*!< WAV fileformat channel ordering (e. g. 5.1: L, R, C, LFE, SL, SR) */ 178 179 } CHANNEL_ORDER; 180 181 /*-------------------- structure definitions ------------------------------*/ 182 183 struct AACENC_CONFIG { 184 INT sampleRate; /* encoder sample rate */ 185 INT bitRate; /* encoder bit rate in bits/sec */ 186 INT ancDataBitRate; /* additional bits consumed by anc data or sbr have to be consiedered while configuration */ 187 188 INT nSubFrames; /* number of frames in super frame (not ADTS/LATM subframes !) */ 189 AUDIO_OBJECT_TYPE audioObjectType; /* Audio Object Type */ 190 191 INT averageBits; /* encoder bit rate in bits/superframe */ 192 INT bitrateMode; /* encoder bitrate mode (CBR/VBR) */ 193 INT nChannels; /* number of channels to process */ 194 CHANNEL_ORDER channelOrder; /* Input Channel ordering scheme. */ 195 INT bandWidth; /* targeted audio bandwidth in Hz */ 196 CHANNEL_MODE channelMode; /* encoder channel mode configuration */ 197 INT framelength; /* used frame size */ 198 199 UINT syntaxFlags; /* bitstreams syntax configuration */ 200 SCHAR epConfig; /* error protection configuration */ 201 202 INT anc_Rate; /* ancillary rate, 0 (disabled), -1 (default) else desired rate */ 203 UINT maxAncBytesPerAU; 204 INT minBitsPerFrame; /* minimum number of bits in AU */ 205 INT maxBitsPerFrame; /* maximum number of bits in AU */ 206 INT bitreservoir; /* size of bitreservoir */ 207 208 UCHAR useTns; /* flag: use temporal noise shaping */ 209 UCHAR usePns; /* flag: use perceptual noise substitution */ 210 UCHAR useIS; /* flag: use intensity coding */ 211 212 UCHAR useRequant; /* flag: use afterburner */ 213 }; 214 215 typedef struct { 216 UCHAR *pData; /* pointer to extension payload data */ 217 UINT dataSize; /* extension payload data size in bits */ 218 EXT_PAYLOAD_TYPE dataType; /* extension payload data type */ 219 INT associatedChElement; /* number of the channel element the data is assigned to */ 220 } AACENC_EXT_PAYLOAD; 221 222 typedef struct AAC_ENC *HANDLE_AAC_ENC; 223 224 /** 225 * \brief Limit given bit rate to a valid value 226 * \param hTpEnc transport encoder handle 227 * \param coreSamplingRate the sample rate to be used for the AAC encoder 228 * \param frameLength the frameLength to be used for the AAC encoder 229 * \param nChannels number of total channels 230 * \param nChannelsEff number of effective channels 231 * \param bitRate the initial bit rate value for which the closest valid bit rate value is searched for 232 * \param averageBits average bits per frame for fixed framing. Set to -1 if not available. 233 * \param optional pointer where the current bits per frame are stored into. 234 * \param bitrateMode the current bit rate mode 235 * \param nSubFrames number of sub frames for super framing (not transport frames). 236 * \return a valid bit rate value as close as possible or identical to bitRate 237 */ 238 INT FDKaacEnc_LimitBitrate( 239 HANDLE_TRANSPORTENC hTpEnc, 240 INT coreSamplingRate, 241 INT frameLength, 242 INT nChannels, 243 INT nChannelsEff, 244 INT bitRate, 245 INT averageBits, 246 INT *pAverageBitsPerFrame, 247 INT bitrateMode, 248 INT nSubFrames 249 ); 250 251 /*----------------------------------------------------------------------------- 252 253 functionname: FDKaacEnc_GetVBRBitrate 254 description: Get VBR bitrate from vbr quality 255 input params: int vbrQuality (VBR0, VBR1, VBR2) 256 channelMode 257 returns: vbr bitrate 258 259 ------------------------------------------------------------------------------*/ 260 INT FDKaacEnc_GetVBRBitrate(INT bitrateMode, CHANNEL_MODE channelMode); 261 262 263 /*----------------------------------------------------------------------------- 264 265 functionname: FDKaacEnc_AacInitDefaultConfig 266 description: gives reasonable default configuration 267 returns: --- 268 269 ------------------------------------------------------------------------------*/ 270 void FDKaacEnc_AacInitDefaultConfig(AACENC_CONFIG *config); 271 272 /*--------------------------------------------------------------------------- 273 274 functionname:FDKaacEnc_Open 275 description: allocate and initialize a new encoder instance 276 returns: 0 if success 277 278 ---------------------------------------------------------------------------*/ 279 AAC_ENCODER_ERROR FDKaacEnc_Open(HANDLE_AAC_ENC *phAacEnc, /* pointer to an encoder handle, initialized on return */ 280 const INT nElements, /* number of maximal elements in instance to support */ 281 const INT nChannels, /* number of maximal channels in instance to support */ 282 const INT nSubFrames); /* support superframing in instance */ 283 284 285 AAC_ENCODER_ERROR FDKaacEnc_Initialize(HANDLE_AAC_ENC hAacEncoder, /* pointer to an encoder handle, initialized on return */ 286 AACENC_CONFIG *config, /* pre-initialized config struct */ 287 HANDLE_TRANSPORTENC hTpEnc, 288 ULONG initFlags); 289 290 291 /*--------------------------------------------------------------------------- 292 293 functionname: FDKaacEnc_EncodeFrame 294 description: encode one frame 295 returns: 0 if success 296 297 ---------------------------------------------------------------------------*/ 298 299 AAC_ENCODER_ERROR FDKaacEnc_EncodeFrame( HANDLE_AAC_ENC hAacEnc, /* encoder handle */ 300 HANDLE_TRANSPORTENC hTpEnc, 301 INT_PCM* inputBuffer, 302 INT* numOutBytes, 303 AACENC_EXT_PAYLOAD extPayload[MAX_TOTAL_EXT_PAYLOADS] 304 ); 305 306 /*--------------------------------------------------------------------------- 307 308 functionname:FDKaacEnc_Close 309 description: delete encoder instance 310 returns: 311 312 ---------------------------------------------------------------------------*/ 313 314 void FDKaacEnc_Close( HANDLE_AAC_ENC* phAacEnc); /* encoder handle */ 315 316 #ifdef __cplusplus 317 } 318 #endif 319 320 #endif /* _aacenc_h_ */ 321 322