aacenc_lib.h 72 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239
  1. /* -----------------------------------------------------------------------------------------------------------
  2. Software License for The Fraunhofer FDK AAC Codec Library for Android
  3. © Copyright 1995 - 2015 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V.
  4. All rights reserved.
  5. 1. INTRODUCTION
  6. The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software that implements
  7. the MPEG Advanced Audio Coding ("AAC") encoding and decoding scheme for digital audio.
  8. This FDK AAC Codec software is intended to be used on a wide variety of Android devices.
  9. AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient general perceptual
  10. audio codecs. AAC-ELD is considered the best-performing full-bandwidth communications codec by
  11. independent studies and is widely deployed. AAC has been standardized by ISO and IEC as part
  12. of the MPEG specifications.
  13. Patent licenses for necessary patent claims for the FDK AAC Codec (including those of Fraunhofer)
  14. may be obtained through Via Licensing (www.vialicensing.com) or through the respective patent owners
  15. individually for the purpose of encoding or decoding bit streams in products that are compliant with
  16. the ISO/IEC MPEG audio standards. Please note that most manufacturers of Android devices already license
  17. these patent claims through Via Licensing or directly from the patent owners, and therefore FDK AAC Codec
  18. software may already be covered under those patent licenses when it is used for those licensed purposes only.
  19. Commercially-licensed AAC software libraries, including floating-point versions with enhanced sound quality,
  20. are also available from Fraunhofer. Users are encouraged to check the Fraunhofer website for additional
  21. applications information and documentation.
  22. 2. COPYRIGHT LICENSE
  23. Redistribution and use in source and binary forms, with or without modification, are permitted without
  24. payment of copyright license fees provided that you satisfy the following conditions:
  25. You must retain the complete text of this software license in redistributions of the FDK AAC Codec or
  26. your modifications thereto in source code form.
  27. You must retain the complete text of this software license in the documentation and/or other materials
  28. provided with redistributions of the FDK AAC Codec or your modifications thereto in binary form.
  29. You must make available free of charge copies of the complete source code of the FDK AAC Codec and your
  30. modifications thereto to recipients of copies in binary form.
  31. The name of Fraunhofer may not be used to endorse or promote products derived from this library without
  32. prior written permission.
  33. You may not charge copyright license fees for anyone to use, copy or distribute the FDK AAC Codec
  34. software or your modifications thereto.
  35. Your modified versions of the FDK AAC Codec must carry prominent notices stating that you changed the software
  36. and the date of any change. For modified versions of the FDK AAC Codec, the term
  37. "Fraunhofer FDK AAC Codec Library for Android" must be replaced by the term
  38. "Third-Party Modified Version of the Fraunhofer FDK AAC Codec Library for Android."
  39. 3. NO PATENT LICENSE
  40. NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without limitation the patents of Fraunhofer,
  41. ARE GRANTED BY THIS SOFTWARE LICENSE. Fraunhofer provides no warranty of patent non-infringement with
  42. respect to this software.
  43. You may use this FDK AAC Codec software or modifications thereto only for purposes that are authorized
  44. by appropriate patent licenses.
  45. 4. DISCLAIMER
  46. This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright holders and contributors
  47. "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, including but not limited to the implied warranties
  48. of merchantability and fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  49. CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary, or consequential damages,
  50. including but not limited to procurement of substitute goods or services; loss of use, data, or profits,
  51. or business interruption, however caused and on any theory of liability, whether in contract, strict
  52. liability, or tort (including negligence), arising in any way out of the use of this software, even if
  53. advised of the possibility of such damage.
  54. 5. CONTACT INFORMATION
  55. Fraunhofer Institute for Integrated Circuits IIS
  56. Attention: Audio and Multimedia Departments - FDK AAC LL
  57. Am Wolfsmantel 33
  58. 91058 Erlangen, Germany
  59. www.iis.fraunhofer.de/amm
  60. [email protected]
  61. ----------------------------------------------------------------------------------------------------------- */
  62. /**************************** MPEG-4 HE-AAC Encoder **************************
  63. Initial author: M. Lohwasser
  64. ******************************************************************************/
  65. /**
  66. * \file aacenc_lib.h
  67. * \brief FDK AAC Encoder library interface header file.
  68. *
  69. \mainpage Introduction
  70. \section Scope
  71. This document describes the high-level interface and usage of the ISO/MPEG-2/4 AAC Encoder
  72. library developed by the Fraunhofer Institute for Integrated Circuits (IIS).
  73. The library implements encoding on the basis of the MPEG-2 and MPEG-4 AAC Low-Complexity
  74. standard, and depending on the library's configuration, MPEG-4 High-Efficiency AAC v2 and/or AAC-ELD standard.
  75. All references to SBR (Spectral Band Replication) are only applicable to HE-AAC or AAC-ELD versions
  76. of the library. All references to PS (Parametric Stereo) are only applicable to HE-AAC v2
  77. versions of the library.
  78. \section encBasics Encoder Basics
  79. This document can only give a rough overview about the ISO/MPEG-2 and ISO/MPEG-4 AAC audio coding
  80. standard. To understand all the terms in this document, you are encouraged to read the following documents.
  81. - ISO/IEC 13818-7 (MPEG-2 AAC), which defines the syntax of MPEG-2 AAC audio bitstreams.
  82. - ISO/IEC 14496-3 (MPEG-4 AAC, subparts 1 and 4), which defines the syntax of MPEG-4 AAC audio bitstreams.
  83. - Lutzky, Schuller, Gayer, Krämer, Wabnik, "A guideline to audio codec delay", 116th AES Convention, May 8, 2004
  84. MPEG Advanced Audio Coding is based on a time-to-frequency mapping of the signal. The signal is
  85. partitioned into overlapping portions and transformed into frequency domain. The spectral components
  86. are then quantized and coded. \n
  87. An MPEG-2 or MPEG-4 AAC audio bitstream is composed of frames. Contrary to MPEG-1/2 Layer-3 (mp3), the
  88. length of individual frames is not restricted to a fixed number of bytes, but can take on any length
  89. between 1 and 768 bytes.
  90. \page LIBUSE Library Usage
  91. \section InterfaceDescription API Files
  92. All API header files are located in the folder /include of the release package. All header files
  93. are provided for usage in C/C++ programs. The AAC encoder library API functions are located at
  94. aacenc_lib.h.
  95. In binary releases the encoder core resides in statically linkable libraries called for example
  96. libAACenc.a/libFDK.a (LINUX) or FDK_fastaaclib.lib (MS Visual C++) for the plain AAC-LC core encoder
  97. and libSBRenc.a (LINUX) or FDK_sbrEncLib.lib (MS Visual C++) for the SBR (Spectral Band
  98. Replication) and PS (Parametric Stereo) modules.
  99. \section CallingSequence Calling Sequence
  100. For encoding of ISO/MPEG-2/4 AAC bitstreams the following sequence is mandatory. Input read and output
  101. write functions as well as the corresponding open and close functions are left out, since they may be
  102. implemented differently according to the user's specific requirements. The example implementation in
  103. main.cpp uses file-based input/output.
  104. -# Call aacEncOpen() to allocate encoder instance with required \ref encOpen "configuration".\n
  105. \dontinclude main.cpp
  106. \skipline hAacEncoder =
  107. \skipline aacEncOpen
  108. -# Call aacEncoder_SetParam() for each parameter to be set. AOT, samplingrate, channelMode, bitrate and transport type are \ref encParams "mandatory".
  109. \code
  110. ErrorStatus = aacEncoder_SetParam(hAacEncoder, parameter, value);
  111. \endcode
  112. -# Call aacEncEncode() with NULL parameters to \ref encReconf "initialize" encoder instance with present parameter set.
  113. \skipline aacEncEncode
  114. -# Call aacEncInfo() to retrieve a configuration data block to be transmitted out of band. This is required when using RFC3640 or RFC3016 like transport.
  115. \dontinclude main.cpp
  116. \skipline encInfo
  117. \skipline aacEncInfo
  118. -# Encode input audio data in loop.
  119. \skip Encode as long as
  120. \skipline do
  121. \until {
  122. Feed \ref feedInBuf "input buffer" with new audio data and provide input/output \ref bufDes "arguments" to aacEncEncode().
  123. \skipline aacEncEncode
  124. \until ;
  125. Write \ref writeOutData "output data" to file or audio device. \skipline while
  126. -# Call aacEncClose() and destroy encoder instance.
  127. \skipline aacEncClose
  128. \section encOpen Encoder Instance Allocation
  129. The assignment of the aacEncOpen() function is very flexible and can be used in the following way.
  130. - If the amount of memory consumption is not an issue, the encoder instance can be allocated
  131. for the maximum number of possible audio channels (for example 6 or 8) with the full functional range supported by the library.
  132. This is the default open procedure for the AAC encoder if memory consumption does not need to be minimized.
  133. \code aacEncOpen(&hAacEncoder,0,0) \endcode
  134. - If the required MPEG-4 AOTs do not call for the full functional range of the library, encoder modules can be allocated selectively.
  135. \verbatim
  136. ------------------------------------------------------
  137. AAC | SBR | PS | MD | FLAGS | value
  138. -----+-----+-----+----+-----------------------+-------
  139. X | - | - | - | (0x01) | 0x01
  140. X | X | - | - | (0x01|0x02) | 0x03
  141. X | X | X | - | (0x01|0x02|0x04) | 0x07
  142. X | - | - | X | (0x01 |0x10) | 0x11
  143. X | X | - | X | (0x01|0x02 |0x10) | 0x13
  144. X | X | X | X | (0x01|0x02|0x04|0x10) | 0x17
  145. ------------------------------------------------------
  146. - AAC: Allocate AAC Core Encoder module.
  147. - SBR: Allocate Spectral Band Replication module.
  148. - PS: Allocate Parametric Stereo module.
  149. - MD: Allocate Meta Data module within AAC encoder.
  150. \endverbatim
  151. \code aacEncOpen(&hAacEncoder,value,0) \endcode
  152. - Specifying the maximum number of channels to be supported in the encoder instance can be done as follows.
  153. - For example allocate an encoder instance which supports 2 channels for all supported AOTs.
  154. The library itself may be capable of encoding up to 6 or 8 channels but in this example only 2 channel encoding is required and thus only buffers for 2 channels are allocated to save data memory.
  155. \code aacEncOpen(&hAacEncoder,0,2) \endcode
  156. - Additionally the maximum number of supported channels in the SBR module can be denoted separately.\n
  157. In this example the encoder instance provides a maximum of 6 channels out of which up to 2 channels support SBR.
  158. This encoder instance can produce for example 5.1 channel AAC-LC streams or stereo HE-AAC (v2) streams.
  159. HE-AAC 5.1 multi channel is not possible since only 2 out of 6 channels support SBR, which saves data memory.
  160. \code aacEncOpen(&hAacEncoder,0,6|(2<<8)) \endcode
  161. \n
  162. \section bufDes Input/Output Arguments
  163. \subsection allocIOBufs Provide Buffer Descriptors
  164. In the present encoder API, the input and output buffers are described with \ref AACENC_BufDesc "buffer descriptors". This mechanism allows a flexible handling
  165. of input and output buffers without impact to the actual encoding call. Optional buffers are necessary e.g. for ancillary data, meta data input or additional output
  166. buffers describing superframing data in DAB+ or DRM+.\n
  167. At least one input buffer for audio input data and one output buffer for bitstream data must be allocated. The input buffer size can be a user defined multiple
  168. of the number of input channels. PCM input data will be copied from the user defined PCM buffer to an internal input buffer and so input data can be less than one AAC audio frame.
  169. The output buffer size should be 6144 bits per channel excluding the LFE channel.
  170. If the output data does not fit into the provided buffer, an AACENC_ERROR will be returned by aacEncEncode().
  171. \dontinclude main.cpp
  172. \skipline inputBuffer
  173. \until outputBuffer
  174. All input and output buffer must be clustered in input and output buffer arrays.
  175. \skipline inBuffer
  176. \until outBufferElSize
  177. Allocate buffer descriptors
  178. \skipline AACENC_BufDesc
  179. \skipline AACENC_BufDesc
  180. Initialize input buffer descriptor
  181. \skipline inBufDesc
  182. \until bufElSizes
  183. Initialize output buffer descriptor
  184. \skipline outBufDesc
  185. \until bufElSizes
  186. \subsection argLists Provide Input/Output Argument Lists
  187. The input and output arguments of an aacEncEncode() call are described in argument structures.
  188. \dontinclude main.cpp
  189. \skipline AACENC_InArgs
  190. \skipline AACENC_OutArgs
  191. \section feedInBuf Feed Input Buffer
  192. The input buffer should be handled as a modulo buffer. New audio data in the form of pulse-code-
  193. modulated samples (PCM) must be read from external and be fed to the input buffer depending on its
  194. fill level. The required sample bitrate (represented by the data type INT_PCM which is 16, 24 or 32
  195. bits wide) is fixed and depends on library configuration (usually 16 bit).
  196. \dontinclude main.cpp
  197. \skipline WAV_InputRead
  198. \until ;
  199. After the encoder's internal buffer is fed with incoming audio samples, and aacEncEncode()
  200. processed the new input data, update/move remaining samples in input buffer, simulating a modulo buffer:
  201. \skipline outargs.numInSamples>0
  202. \until }
  203. \section writeOutData Output Bitstream Data
  204. If any AAC bitstream data is available, write it to output file or device. This can be done once the
  205. following condition is true:
  206. \dontinclude main.cpp
  207. \skip Valid bitstream available
  208. \skipline outargs
  209. \skipline outBytes>0
  210. If you use file I/O then for example call mpegFileWrite_Write() from the library libMpegFileWrite
  211. \dontinclude main.cpp
  212. \skipline mpegFileWrite_Write
  213. \section cfgMetaData Meta Data Configuration
  214. If the present library is configured with Metadata support, it is possible to insert meta data side info into the generated
  215. audio bitstream while encoding.
  216. To work with meta data the encoder instance has to be \ref encOpen "allocated" with meta data support. The meta data mode must be be configured with
  217. the ::AACENC_METADATA_MODE parameter and aacEncoder_SetParam() function.
  218. \code aacEncoder_SetParam(hAacEncoder, AACENC_METADATA_MODE, 0-2); \endcode
  219. This configuration indicates how to embed meta data into bitstrem. Either no insertion, MPEG or ETSI style.
  220. The meta data itself must be specified within the meta data setup structure AACENC_MetaData.
  221. Changing one of the AACENC_MetaData setup parameters can be achieved from outside the library within ::IN_METADATA_SETUP input
  222. buffer. There is no need to supply meta data setup structure every frame. If there is no new meta setup data available, the
  223. encoder uses the previous setup or the default configuration in initial state.
  224. In general the audio compressor and limiter within the encoder library can be configured with the ::AACENC_METADATA_DRC_PROFILE parameter
  225. AACENC_MetaData::drc_profile and and AACENC_MetaData::comp_profile.
  226. \n
  227. \section encReconf Encoder Reconfiguration
  228. The encoder library allows reconfiguration of the encoder instance with new settings
  229. continuously between encoding frames. Each parameter to be changed must be set with
  230. a single aacEncoder_SetParam() call. The internal status of each parameter can be
  231. retrieved with an aacEncoder_GetParam() call.\n
  232. There is no stand-alone reconfiguration function available. When parameters were
  233. modified from outside the library, an internal control mechanism triggers the necessary
  234. reconfiguration process which will be applied at the beginning of the following
  235. aacEncEncode() call. This state can be observed from external via the AACENC_INIT_STATUS
  236. and aacEncoder_GetParam() function. The reconfiguration process can also be applied
  237. immediately when all parameters of an aacEncEncode() call are NULL with a valid encoder
  238. handle.\n\n
  239. The internal reconfiguration process can be controlled from extern with the following access.
  240. \code aacEncoder_SetParam(hAacEncoder, AACENC_CONTROL_STATE, AACENC_CTRLFLAGS); \endcode
  241. \section encParams Encoder Parametrization
  242. All parameteres listed in ::AACENC_PARAM can be modified within an encoder instance.
  243. \subsection encMandatory Mandatory Encoder Parameters
  244. The following parameters must be specified when the encoder instance is initialized.
  245. \code
  246. aacEncoder_SetParam(hAacEncoder, AACENC_AOT, value);
  247. aacEncoder_SetParam(hAacEncoder, AACENC_BITRATE, value);
  248. aacEncoder_SetParam(hAacEncoder, AACENC_SAMPLERATE, value);
  249. aacEncoder_SetParam(hAacEncoder, AACENC_CHANNELMODE, value);
  250. \endcode
  251. Beyond that is an internal auto mode which preinitizializes the ::AACENC_BITRATE parameter
  252. if the parameter was not set from extern. The bitrate depends on the number of effective
  253. channels and sampling rate and is determined as follows.
  254. \code
  255. AAC-LC (AOT_AAC_LC): 1.5 bits per sample
  256. HE-AAC (AOT_SBR): 0.625 bits per sample (dualrate sbr)
  257. HE-AAC (AOT_SBR): 1.125 bits per sample (downsampled sbr)
  258. HE-AAC v2 (AOT_PS): 0.5 bits per sample
  259. \endcode
  260. \subsection channelMode Channel Mode Configuration
  261. The input audio data is described with the ::AACENC_CHANNELMODE parameter in the
  262. aacEncoder_SetParam() call. It is not possible to use the encoder instance with a 'number of
  263. input channels' argument. Instead, the channelMode must be set as follows.
  264. \code aacEncoder_SetParam(hAacEncoder, AACENC_CHANNELMODE, value); \endcode
  265. The parameter is specified in ::CHANNEL_MODE and can be mapped from the number of input channels
  266. in the following way.
  267. \dontinclude main.cpp
  268. \skip CHANNEL_MODE chMode = MODE_INVALID;
  269. \until return
  270. \subsection encQual Audio Quality Considerations
  271. The default encoder configuration is suggested to be used. Encoder tools such as TNS and PNS
  272. are activated by default and are internally controlled (see \ref BEHAVIOUR_TOOLS).
  273. There is an additional quality parameter called ::AACENC_AFTERBURNER. In the default
  274. configuration this quality switch is deactivated because it would cause a workload
  275. increase which might be significant. If workload is not an issue in the application
  276. we recommended to activate this feature.
  277. \code aacEncoder_SetParam(hAacEncoder, AACENC_AFTERBURNER, 1); \endcode
  278. \subsection encELD ELD Auto Configuration Mode
  279. For ELD configuration a so called auto configurator is available which configures SBR and the SBR ratio by itself.
  280. The configurator is used when the encoder parameter ::AACENC_SBR_MODE and ::AACENC_SBR_RATIO are not set explicitely.
  281. Based on sampling rate and chosen bitrate per channel a reasonable SBR configuration will be used.
  282. \verbatim
  283. ------------------------------------------------------------
  284. Sampling Rate | Channel Bitrate | SBR | SBR Ratio
  285. -----------------+-----------------+------+-----------------
  286. ]min, 16] kHz | min - 27999 | on | downsampled SBR
  287. | 28000 - max | off | ---
  288. -----------------+-----------------+------+-----------------
  289. ]16 - 24] kHz | min - 39999 | on | downsampled SBR
  290. | 40000 - max | off | ---
  291. -----------------+-----------------+------+-----------------
  292. ]24 - 32] kHz | min - 27999 | on | dualrate SBR
  293. | 28000 - 55999 | on | downsampled SBR
  294. | 56000 - max | off | ---
  295. -----------------+-----------------+------+-----------------
  296. ]32 - 44.1] kHz | min - 63999 | on | dualrate SBR
  297. | 64000 - max | off | ---
  298. -----------------+-----------------+------+-----------------
  299. ]44.1 - 48] kHz | min - 63999 | on | dualrate SBR
  300. | 64000 - max | off | ---
  301. ------------------------------------------------------------
  302. \endverbatim
  303. \section audiochCfg Audio Channel Configuration
  304. The MPEG standard refers often to the so-called Channel Configuration. This Channel Configuration is used for a fixed Channel
  305. Mapping. The configurations 1-7 are predefined in MPEG standard and used for implicit signalling within the encoded bitstream.
  306. For user defined Configurations the Channel Configuration is set to 0 and the Channel Mapping must be explecitly described with an appropriate
  307. Program Config Element. The present Encoder implementation does not allow the user to configure this Channel Configuration from
  308. extern. The Encoder implementation supports fixed Channel Modes which are mapped to Channel Configuration as follow.
  309. \verbatim
  310. -------------------------------------------------------------------------------
  311. ChannelMode | ChCfg | front_El | side_El | back_El | lfe_El
  312. -----------------------+--------+---------------+----------+----------+--------
  313. MODE_1 | 1 | SCE | | |
  314. MODE_2 | 2 | CPE | | |
  315. MODE_1_2 | 3 | SCE, CPE | | |
  316. MODE_1_2_1 | 4 | SCE, CPE | | SCE |
  317. MODE_1_2_2 | 5 | SCE, CPE | | CPE |
  318. MODE_1_2_2_1 | 6 | SCE, CPE | | CPE | LFE
  319. MODE_1_2_2_2_1 | 7 | SCE, CPE, CPE | | CPE | LFE
  320. -----------------------+--------+---------------+----------+----------+--------
  321. MODE_7_1_REAR_SURROUND | 0 | SCE, CPE | | CPE, CPE | LFE
  322. MODE_7_1_FRONT_CENTER | 0 | SCE, CPE, CPE | | CPE | LFE
  323. -------------------------------------------------------------------------------
  324. - SCE: Single Channel Element.
  325. - CPE: Channel Pair.
  326. - SCE: Low Frequency Element.
  327. \endverbatim
  328. Moreover, the Table describes all fixed Channel Elements for each Channel Mode which are assigned to a speaker arrangement. The
  329. arrangement includes front, side, back and lfe Audio Channel Elements.\n
  330. This mapping of Audio Channel Elements is defined in MPEG standard for Channel Config 1-7. The Channel assignment for MODE_1_1,
  331. MODE_2_2 and MODE_2_1 is used from the ARIB standard. All other configurations are defined as suggested in MPEG.\n
  332. In case of Channel Config 0 or writing matrix mixdown coefficients, the encoder enables the writing of Program Config Element
  333. itself as described in \ref encPCE. The configuration used in Program Config Element refers to the denoted Table.\n
  334. Beside the Channel Element assignment the Channel Modes are resposible for audio input data channel mapping. The Channel Mapping
  335. of the audio data depends on the selected ::AACENC_CHANNELORDER which can be MPEG or WAV like order.\n
  336. Following Table describes the complete channel mapping for both Channel Order configurations.
  337. \verbatim
  338. ---------------------------------------------------------------------------------------
  339. ChannelMode | MPEG-Channelorder | WAV-Channelorder
  340. -----------------------+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---
  341. MODE_1 | 0 | | | | | | | | 0 | | | | | | |
  342. MODE_2 | 0 | 1 | | | | | | | 0 | 1 | | | | | |
  343. MODE_1_2 | 0 | 1 | 2 | | | | | | 2 | 0 | 1 | | | | |
  344. MODE_1_2_1 | 0 | 1 | 2 | 3 | | | | | 2 | 0 | 1 | 3 | | | |
  345. MODE_1_2_2 | 0 | 1 | 2 | 3 | 4 | | | | 2 | 0 | 1 | 3 | 4 | | |
  346. MODE_1_2_2_1 | 0 | 1 | 2 | 3 | 4 | 5 | | | 2 | 0 | 1 | 4 | 5 | 3 | |
  347. MODE_1_2_2_2_1 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 2 | 6 | 7 | 0 | 1 | 4 | 5 | 3
  348. -----------------------+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---
  349. MODE_7_1_REAR_SURROUND | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 2 | 0 | 1 | 6 | 7 | 4 | 5 | 3
  350. MODE_7_1_FRONT_CENTER | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 2 | 6 | 7 | 0 | 1 | 4 | 5 | 3
  351. ---------------------------------------------------------------------------------------
  352. \endverbatim
  353. The denoted mapping is important for correct audio channel assignment when using MPEG or WAV ordering. The incoming audio
  354. channels are distributed MPEG like starting at the front channels and ending at the back channels. The distribution is used as
  355. described in Table concering Channel Config and fix channel elements. Please see the following example for clarification.
  356. \verbatim
  357. Example: MODE_1_2_2_1 - WAV-Channelorder 5.1
  358. ------------------------------------------
  359. Input Channel | Coder Channel
  360. --------------------+---------------------
  361. 2 (front center) | 0 (SCE channel)
  362. 0 (left center) | 1 (1st of 1st CPE)
  363. 1 (right center) | 2 (2nd of 1st CPE)
  364. 4 (left surround) | 3 (1st of 2nd CPE)
  365. 5 (right surround) | 4 (2nd of 2nd CPE)
  366. 3 (LFE) | 5 (LFE)
  367. ------------------------------------------
  368. \endverbatim
  369. \section suppBitrates Supported Bitrates
  370. The FDK AAC Encoder provides a wide range of supported bitrates.
  371. The minimum and maximum allowed bitrate depends on the Audio Object Type. For AAC-LC the minimum
  372. bitrate is the bitrate that is required to write the most basic and minimal valid bitstream.
  373. It consists of the bitstream format header information and other static/mandatory information
  374. within the AAC payload. The maximum AAC framesize allowed by the MPEG-4 standard
  375. determines the maximum allowed bitrate for AAC-LC. For HE-AAC and HE-AAC v2 a library internal
  376. look-up table is used.
  377. A good working point in terms of audio quality, sampling rate and bitrate, is at 1 to 1.5
  378. bits/audio sample for AAC-LC, 0.625 bits/audio sample for dualrate HE-AAC, 1.125 bits/audio sample
  379. for downsampled HE-AAC and 0.5 bits/audio sample for HE-AAC v2.
  380. For example for one channel with a sampling frequency of 48 kHz, the range from
  381. 48 kbit/s to 72 kbit/s achieves reasonable audio quality for AAC-LC.
  382. For HE-AAC and HE-AAC v2 the lowest possible audio input sampling frequency is 16 kHz because then the
  383. AAC-LC core encoder operates in dual rate mode at its lowest possible sampling frequency, which is 8 kHz.
  384. HE-AAC v2 requires stereo input audio data.
  385. Please note that in HE-AAC or HE-AAC v2 mode the encoder supports much higher bitrates than are
  386. appropriate for HE-AAC or HE-AAC v2. For example, at a bitrate of more than 64 kbit/s for a stereo
  387. audio signal at 44.1 kHz it usually makes sense to use AAC-LC, which will produce better audio
  388. quality at that bitrate than HE-AAC or HE-AAC v2.
  389. \section reommendedConfig Recommended Sampling Rate and Bitrate Combinations
  390. The following table provides an overview of recommended encoder configuration parameters
  391. which we determined by virtue of numerous listening tests.
  392. \subsection reommendedConfigLC AAC-LC, HE-AAC, HE-AACv2 in Dualrate SBR mode.
  393. \verbatim
  394. -----------------------------------------------------------------------------------
  395. Audio Object Type | Bit Rate Range | Supported | Preferred | No. of
  396. | [bit/s] | Sampling Rates | Sampl. | Chan.
  397. | | [kHz] | Rate |
  398. | | | [kHz] |
  399. -------------------+------------------+-----------------------+------------+-------
  400. AAC LC + SBR + PS | 8000 - 11999 | 22.05, 24.00 | 24.00 | 2
  401. AAC LC + SBR + PS | 12000 - 17999 | 32.00 | 32.00 | 2
  402. AAC LC + SBR + PS | 18000 - 39999 | 32.00, 44.10, 48.00 | 44.10 | 2
  403. AAC LC + SBR + PS | 40000 - 56000 | 32.00, 44.10, 48.00 | 48.00 | 2
  404. -------------------+------------------+-----------------------+------------+-------
  405. AAC LC + SBR | 8000 - 11999 | 22.05, 24.00 | 24.00 | 1
  406. AAC LC + SBR | 12000 - 17999 | 32.00 | 32.00 | 1
  407. AAC LC + SBR | 18000 - 39999 | 32.00, 44.10, 48.00 | 44.10 | 1
  408. AAC LC + SBR | 40000 - 56000 | 32.00, 44.10, 48.00 | 48.00 | 1
  409. AAC LC + SBR | 16000 - 27999 | 32.00, 44.10, 48.00 | 32.00 | 2
  410. AAC LC + SBR | 28000 - 63999 | 32.00, 44.10, 48.00 | 44.10 | 2
  411. AAC LC + SBR | 64000 - 128000 | 32.00, 44.10, 48.00 | 48.00 | 2
  412. -------------------+------------------+-----------------------+------------+-------
  413. AAC LC + SBR | 64000 - 69999 | 32.00, 44.10, 48.00 | 32.00 | 5, 5.1
  414. AAC LC + SBR | 70000 - 159999 | 32.00, 44.10, 48.00 | 44.10 | 5, 5.1
  415. AAC LC + SBR | 160000 - 245999 | 32.00, 44.10, 48.00 | 48.00 | 5
  416. AAC LC + SBR | 160000 - 265999 | 32.00, 44.10, 48.00 | 48.00 | 5.1
  417. -------------------+------------------+-----------------------+------------+-------
  418. AAC LC | 8000 - 15999 | 11.025, 12.00, 16.00 | 12.00 | 1
  419. AAC LC | 16000 - 23999 | 16.00 | 16.00 | 1
  420. AAC LC | 24000 - 31999 | 16.00, 22.05, 24.00 | 24.00 | 1
  421. AAC LC | 32000 - 55999 | 32.00 | 32.00 | 1
  422. AAC LC | 56000 - 160000 | 32.00, 44.10, 48.00 | 44.10 | 1
  423. AAC LC | 160001 - 288000 | 48.00 | 48.00 | 1
  424. -------------------+------------------+-----------------------+------------+-------
  425. AAC LC | 16000 - 23999 | 11.025, 12.00, 16.00 | 12.00 | 2
  426. AAC LC | 24000 - 31999 | 16.00 | 16.00 | 2
  427. AAC LC | 32000 - 39999 | 16.00, 22.05, 24.00 | 22.05 | 2
  428. AAC LC | 40000 - 95999 | 32.00 | 32.00 | 2
  429. AAC LC | 96000 - 111999 | 32.00, 44.10, 48.00 | 32.00 | 2
  430. AAC LC | 112000 - 320001 | 32.00, 44.10, 48.00 | 44.10 | 2
  431. AAC LC | 320002 - 576000 | 48.00 | 48.00 | 2
  432. -------------------+------------------+-----------------------+------------+-------
  433. AAC LC | 160000 - 239999 | 32.00 | 32.00 | 5, 5.1
  434. AAC LC | 240000 - 279999 | 32.00, 44.10, 48.00 | 32.00 | 5, 5.1
  435. AAC LC | 280000 - 800000 | 32.00, 44.10, 48.00 | 44.10 | 5, 5.1
  436. -----------------------------------------------------------------------------------
  437. \endverbatim \n
  438. \subsection reommendedConfigLD AAC-LD, AAC-ELD, AAC-ELD with SBR in Dualrate SBR mode.
  439. \verbatim
  440. -----------------------------------------------------------------------------------
  441. Audio Object Type | Bit Rate Range | Supported | Preferred | No. of
  442. | [bit/s] | Sampling Rates | Sampl. | Chan.
  443. | | [kHz] | Rate |
  444. | | | [kHz] |
  445. -------------------+------------------+-----------------------+------------+-------
  446. ELD + SBR | 18000 - 24999 | 32.00 - 44.10 | 32.00 | 1
  447. ELD + SBR | 25000 - 31999 | 32.00 - 48.00 | 32.00 | 1
  448. ELD + SBR | 32000 - 64000 | 32.00 - 48.00 | 48.00 | 1
  449. -------------------+------------------+-----------------------+------------+-------
  450. ELD + SBR | 32000 - 51999 | 32.00 - 48.00 | 44.10 | 2
  451. ELD + SBR | 52000 - 128000 | 32.00 - 48.00 | 48.00 | 2
  452. -------------------+------------------+-----------------------+------------+-------
  453. ELD + SBR | 72000 - 160000 | 44.10 - 48.00 | 48.00 | 3
  454. -------------------+------------------+-----------------------+------------+-------
  455. ELD + SBR | 96000 - 212000 | 44.10 - 48.00 | 48.00 | 4
  456. -------------------+------------------+-----------------------+------------+-------
  457. ELD + SBR | 120000 - 246000 | 44.10 - 48.00 | 48.00 | 5
  458. -------------------+------------------+-----------------------+------------+-------
  459. ELD + SBR | 120000 - 266000 | 44.10 - 48.00 | 48.00 | 5.1
  460. -------------------+------------------+-----------------------+------------+-------
  461. LD, ELD | 16000 - 19999 | 16.00 - 24.00 | 16.00 | 1
  462. LD, ELD | 20000 - 39999 | 16.00 - 32.00 | 24.00 | 1
  463. LD, ELD | 40000 - 49999 | 22.05 - 32.00 | 32.00 | 1
  464. LD, ELD | 50000 - 61999 | 24.00 - 44.10 | 32.00 | 1
  465. LD, ELD | 62000 - 84999 | 32.00 - 48.00 | 44.10 | 1
  466. LD, ELD | 85000 - 192000 | 44.10 - 48.00 | 48.00 | 1
  467. -------------------+------------------+-----------------------+------------+-------
  468. LD, ELD | 64000 - 75999 | 24.00 - 32.00 | 32.00 | 2
  469. LD, ELD | 76000 - 97999 | 24.00 - 44.10 | 32.00 | 2
  470. LD, ELD | 98000 - 135999 | 32.00 - 48.00 | 44.10 | 2
  471. LD, ELD | 136000 - 384000 | 44.10 - 48.00 | 48.00 | 2
  472. -------------------+------------------+-----------------------+------------+-------
  473. LD, ELD | 96000 - 113999 | 24.00 - 32.00 | 32.00 | 3
  474. LD, ELD | 114000 - 146999 | 24.00 - 44.10 | 32.00 | 3
  475. LD, ELD | 147000 - 203999 | 32.00 - 48.00 | 44.10 | 3
  476. LD, ELD | 204000 - 576000 | 44.10 - 48.00 | 48.00 | 3
  477. -------------------+------------------+-----------------------+------------+-------
  478. LD, ELD | 128000 - 151999 | 24.00 - 32.00 | 32.00 | 4
  479. LD, ELD | 152000 - 195999 | 24.00 - 44.10 | 32.00 | 4
  480. LD, ELD | 196000 - 271999 | 32.00 - 48.00 | 44.10 | 4
  481. LD, ELD | 272000 - 768000 | 44.10 - 48.00 | 48.00 | 4
  482. -------------------+------------------+-----------------------+------------+-------
  483. LD, ELD | 160000 - 189999 | 24.00 - 32.00 | 32.00 | 5
  484. LD, ELD | 190000 - 244999 | 24.00 - 44.10 | 32.00 | 5
  485. LD, ELD | 245000 - 339999 | 32.00 - 48.00 | 44.10 | 5
  486. LD, ELD | 340000 - 960000 | 44.10 - 48.00 | 48.00 | 5
  487. -----------------------------------------------------------------------------------
  488. \endverbatim \n
  489. \subsection reommendedConfigELD AAC-ELD with SBR in Downsampled SBR mode.
  490. \verbatim
  491. -----------------------------------------------------------------------------------
  492. Audio Object Type | Bit Rate Range | Supported | Preferred | No. of
  493. | [bit/s] | Sampling Rates | Sampl. | Chan.
  494. | | [kHz] | Rate |
  495. | | | [kHz] |
  496. -------------------+------------------+-----------------------+------------+-------
  497. ELD + SBR | 18000 - 24999 | 16.00 - 22.05 | 22.05 | 1
  498. (downsampled SBR) | 25000 - 35999 | 22.05 - 32.00 | 24.00 | 1
  499. | 36000 - 64000 | 32.00 - 48.00 | 32.00 | 1
  500. -----------------------------------------------------------------------------------
  501. \endverbatim \n
  502. \page ENCODERBEHAVIOUR Encoder Behaviour
  503. \section BEHAVIOUR_BANDWIDTH Bandwidth
  504. The FDK AAC encoder usually does not use the full frequency range of the input signal, but restricts the bandwidth
  505. according to certain library-internal settings. They can be changed in the table "bandWidthTable" in the
  506. file bandwidth.cpp (if available).
  507. The encoder API provides the ::AACENC_BANDWIDTH parameter to adjust the bandwidth explicitly.
  508. \code
  509. aacEncoder_SetParam(hAacEncoder, AACENC_BANDWIDTH, value);
  510. \endcode
  511. However it is not recommended to change these settings, because they are based on numerious listening
  512. tests and careful tweaks to ensure the best overall encoding quality.
  513. Theoretically a signal of for example 48 kHz can contain frequencies up to 24 kHz, but to use this full range
  514. in an audio encoder usually does not make sense. Usually the encoder has a very limited amount of
  515. bits to spend (typically 128 kbit/s for stereo 48 kHz content) and to allow full range bandwidth would
  516. waste a lot of these bits for frequencies the human ear is hardly able to perceive anyway, if at all. Hence it
  517. is wise to use the available bits for the really important frequency range and just skip the rest.
  518. At lower bitrates (e. g. <= 80 kbit/s for stereo 48 kHz content) the encoder will choose an even smaller
  519. bandwidth, because an encoded signal with smaller bandwidth and hence less artifacts sounds better than a signal
  520. with higher bandwidth but then more coding artefacts across all frequencies. These artefacts would occur if
  521. small bitrates and high bandwidths are chosen because the available bits are just not enough to encode all
  522. frequencies well.
  523. Unfortunately some people evaluate encoding quality based on possible bandwidth as well, but it is a two-sided
  524. sword considering the trade-off described above.
  525. Another aspect is workload consumption. The higher the allowed bandwidth, the more frequency lines have to be
  526. processed, which in turn increases the workload.
  527. \section FRAMESIZES_AND_BIT_RESERVOIR Frame Sizes & Bit Reservoir
  528. For AAC there is a difference between constant bit rate and constant frame
  529. length due to the so-called bit reservoir technique, which allows the encoder to use less
  530. bits in an AAC frame for those audio signal sections which are easy to encode,
  531. and then spend them at a later point in
  532. time for more complex audio sections. The extent to which this "bit exchange"
  533. is done is limited to allow for reliable and relatively low delay real time
  534. streaming.
  535. Over a longer period in time the bitrate will be constant in the AAC constant
  536. bitrate mode, e.g. for ISDN transmission. This means that in AAC each bitstream
  537. frame will in general have a different length in bytes but over time it
  538. will reach the target bitrate. One could also make an MPEG compliant
  539. AAC encoder which always produces constant length packages for each AAC frame,
  540. but the audio quality would be considerably worse since the bit reservoir
  541. technique would have to be switched off completely. A higher bit rate would have
  542. to be used to get the same audio quality as with an enabled bit reservoir.
  543. The maximum AAC frame length, regardless of the available bit reservoir, is defined
  544. as 6144 bits per channel.
  545. For mp3 by the way, the same bit reservoir technique exists, but there each bit
  546. stream frame has a constant length for a given bit rate (ignoring the
  547. padding byte). In mp3 there is a so-called "back pointer" which tells
  548. the decoder which bits belong to the current mp3 frame - and in general some or
  549. many bits have been transmitted in an earlier mp3 frame. Basically this leads to
  550. the same "bit exchange between mp3 frames" as in AAC but with virtually constant
  551. length frames.
  552. This variable frame length at "constant bit rate" is not something special
  553. in this Fraunhofer IIS AAC encoder. AAC has been designed in that way.
  554. \subsection BEHAVIOUR_ESTIM_AVG_FRAMESIZES Estimating Average Frame Sizes
  555. A HE-AAC v1 or v2 audio frame contains 2048 PCM samples per channel (there is
  556. also one mode with 1920 samples per channel but this is only for special purposes
  557. such as DAB+ digital radio).
  558. The number of HE-AAC frames \f$N\_FRAMES\f$ per second at 44.1 kHz is:
  559. \f[
  560. N\_FRAMES = 44100 / 2048 = 21.5332
  561. \f]
  562. At a bit rate of 8 kbps the average number of bits per frame \f$N\_BITS\_PER\_FRAME\f$ is:
  563. \f[
  564. N\_BITS\_PER\_FRAME = 8000 / 21.5332 = 371.52
  565. \f]
  566. which is about 46.44 bytes per encoded frame.
  567. At a bit rate of 32 kbps, which is quite high for single channel HE-AAC v1, it is:
  568. \f[
  569. N\_BITS\_PER\_FRAME = 32000 / 21.5332 = 1486
  570. \f]
  571. which is about 185.76 bytes per encoded frame.
  572. These bits/frame figures are average figures where each AAC frame generally has a different
  573. size in bytes. To calculate the same for AAC-LC just use 1024 instead of 2048 PCM samples per
  574. frame and channel.
  575. For AAC-LD/ELD it is either 480 or 512 PCM samples per frame and channel.
  576. \section BEHAVIOUR_TOOLS Encoder Tools
  577. The AAC encoder supports TNS, PNS, MS, Intensity and activates these tools depending on the audio signal and
  578. the encoder configuration (i.e. bitrate or AOT). It is not required to configure these tools manually.
  579. PNS improves encoding quality only for certain bitrates. Therefore it makes sense to activate PNS only for
  580. these bitrates and save the processing power required for PNS (about 10 % of the encoder) when using other
  581. bitrates. This is done automatically inside the encoder library. PNS is disabled inside the encoder library if
  582. an MPEG-2 AOT is choosen since PNS is an MPEG-4 AAC feature.
  583. If SBR is activated, the encoder automatically deactivates PNS internally. If TNS is disabled but PNS is allowed,
  584. the encoder deactivates PNS calculation internally.
  585. */
  586. #ifndef _AAC_ENC_LIB_H_
  587. #define _AAC_ENC_LIB_H_
  588. #include "machine_type.h"
  589. #include "FDK_audio.h"
  590. #define AACENCODER_LIB_VL0 3
  591. #define AACENCODER_LIB_VL1 4
  592. #define AACENCODER_LIB_VL2 22
  593. /**
  594. * AAC encoder error codes.
  595. */
  596. typedef enum {
  597. AACENC_OK = 0x0000, /*!< No error happened. All fine. */
  598. AACENC_INVALID_HANDLE = 0x0020, /*!< Handle passed to function call was invalid. */
  599. AACENC_MEMORY_ERROR = 0x0021, /*!< Memory allocation failed. */
  600. AACENC_UNSUPPORTED_PARAMETER = 0x0022, /*!< Parameter not available. */
  601. AACENC_INVALID_CONFIG = 0x0023, /*!< Configuration not provided. */
  602. AACENC_INIT_ERROR = 0x0040, /*!< General initialization error. */
  603. AACENC_INIT_AAC_ERROR = 0x0041, /*!< AAC library initialization error. */
  604. AACENC_INIT_SBR_ERROR = 0x0042, /*!< SBR library initialization error. */
  605. AACENC_INIT_TP_ERROR = 0x0043, /*!< Transport library initialization error. */
  606. AACENC_INIT_META_ERROR = 0x0044, /*!< Meta data library initialization error. */
  607. AACENC_ENCODE_ERROR = 0x0060, /*!< The encoding process was interrupted by an unexpected error. */
  608. AACENC_ENCODE_EOF = 0x0080 /*!< End of file reached. */
  609. } AACENC_ERROR;
  610. /**
  611. * AAC encoder buffer descriptors identifier.
  612. * This identifier are used within buffer descriptors AACENC_BufDesc::bufferIdentifiers.
  613. */
  614. typedef enum {
  615. /* Input buffer identifier. */
  616. IN_AUDIO_DATA = 0, /*!< Audio input buffer, interleaved INT_PCM samples. */
  617. IN_ANCILLRY_DATA = 1, /*!< Ancillary data to be embedded into bitstream. */
  618. IN_METADATA_SETUP = 2, /*!< Setup structure for embedding meta data. */
  619. /* Output buffer identifier. */
  620. OUT_BITSTREAM_DATA = 3, /*!< Buffer holds bitstream output data. */
  621. OUT_AU_SIZES = 4 /*!< Buffer contains sizes of each access unit. This information
  622. is necessary for superframing. */
  623. } AACENC_BufferIdentifier;
  624. /**
  625. * AAC encoder handle.
  626. */
  627. typedef struct AACENCODER *HANDLE_AACENCODER;
  628. /**
  629. * Provides some info about the encoder configuration.
  630. */
  631. typedef struct {
  632. UINT maxOutBufBytes; /*!< Maximum number of encoder bitstream bytes within one frame.
  633. Size depends on maximum number of supported channels in encoder instance.
  634. For superframing (as used for example in DAB+), size has to be a multiple accordingly. */
  635. UINT maxAncBytes; /*!< Maximum number of ancillary data bytes which can be inserted into
  636. bitstream within one frame. */
  637. UINT inBufFillLevel; /*!< Internal input buffer fill level in samples per channel. This parameter
  638. will automatically be cleared if samplingrate or channel(Mode/Order) changes. */
  639. UINT inputChannels; /*!< Number of input channels expected in encoding process. */
  640. UINT frameLength; /*!< Amount of input audio samples consumed each frame per channel, depending
  641. on audio object type configuration. */
  642. UINT encoderDelay; /*!< Codec delay in PCM samples/channel. Depends on framelength and AOT. Does not
  643. include framing delay for filling up encoder PCM input buffer. */
  644. UCHAR confBuf[64]; /*!< Configuration buffer in binary format as an AudioSpecificConfig
  645. or StreamMuxConfig according to the selected transport type. */
  646. UINT confSize; /*!< Number of valid bytes in confBuf. */
  647. } AACENC_InfoStruct;
  648. /**
  649. * Describes the input and output buffers for an aacEncEncode() call.
  650. */
  651. typedef struct {
  652. INT numBufs; /*!< Number of buffers. */
  653. void **bufs; /*!< Pointer to vector containing buffer addresses. */
  654. INT *bufferIdentifiers; /*!< Identifier of each buffer element. See ::AACENC_BufferIdentifier. */
  655. INT *bufSizes; /*!< Size of each buffer in 8-bit bytes. */
  656. INT *bufElSizes; /*!< Size of each buffer element in bytes. */
  657. } AACENC_BufDesc;
  658. /**
  659. * Defines the input arguments for an aacEncEncode() call.
  660. */
  661. typedef struct {
  662. INT numInSamples; /*!< Number of valid input audio samples (multiple of input channels). */
  663. INT numAncBytes; /*!< Number of ancillary data bytes to be encoded. */
  664. } AACENC_InArgs;
  665. /**
  666. * Defines the output arguments for an aacEncEncode() call.
  667. */
  668. typedef struct {
  669. INT numOutBytes; /*!< Number of valid bitstream bytes generated during aacEncEncode(). */
  670. INT numInSamples; /*!< Number of input audio samples consumed by the encoder. */
  671. INT numAncBytes; /*!< Number of ancillary data bytes consumed by the encoder. */
  672. } AACENC_OutArgs;
  673. /**
  674. * Meta Data Compression Profiles.
  675. */
  676. typedef enum {
  677. AACENC_METADATA_DRC_NONE = 0, /*!< None. */
  678. AACENC_METADATA_DRC_FILMSTANDARD = 1, /*!< Film standard. */
  679. AACENC_METADATA_DRC_FILMLIGHT = 2, /*!< Film light. */
  680. AACENC_METADATA_DRC_MUSICSTANDARD = 3, /*!< Music standard. */
  681. AACENC_METADATA_DRC_MUSICLIGHT = 4, /*!< Music light. */
  682. AACENC_METADATA_DRC_SPEECH = 5 /*!< Speech. */
  683. } AACENC_METADATA_DRC_PROFILE;
  684. /**
  685. * Meta Data setup structure.
  686. */
  687. typedef struct {
  688. AACENC_METADATA_DRC_PROFILE drc_profile; /*!< MPEG DRC compression profile. See ::AACENC_METADATA_DRC_PROFILE. */
  689. AACENC_METADATA_DRC_PROFILE comp_profile; /*!< ETSI heavy compression profile. See ::AACENC_METADATA_DRC_PROFILE. */
  690. INT drc_TargetRefLevel; /*!< Used to define expected level to:
  691. Scaled with 16 bit. x*2^16. */
  692. INT comp_TargetRefLevel; /*!< Adjust limiter to avoid overload.
  693. Scaled with 16 bit. x*2^16. */
  694. INT prog_ref_level_present; /*!< Flag, if prog_ref_level is present */
  695. INT prog_ref_level; /*!< Programme Reference Level = Dialogue Level:
  696. -31.75dB .. 0 dB ; stepsize: 0.25dB
  697. Scaled with 16 bit. x*2^16.*/
  698. UCHAR PCE_mixdown_idx_present; /*!< Flag, if dmx-idx should be written in programme config element */
  699. UCHAR ETSI_DmxLvl_present; /*!< Flag, if dmx-lvl should be written in ETSI-ancData */
  700. SCHAR centerMixLevel; /*!< Center downmix level (0...7, according to table) */
  701. SCHAR surroundMixLevel; /*!< Surround downmix level (0...7, according to table) */
  702. UCHAR dolbySurroundMode; /*!< Indication for Dolby Surround Encoding Mode.
  703. - 0: Dolby Surround mode not indicated
  704. - 1: 2-ch audio part is not Dolby surround encoded
  705. - 2: 2-ch audio part is Dolby surround encoded */
  706. } AACENC_MetaData;
  707. /**
  708. * AAC encoder control flags.
  709. *
  710. * In interaction with the ::AACENC_CONTROL_STATE parameter it is possible to get information about the internal
  711. * initialization process. It is also possible to overwrite the internal state from extern when necessary.
  712. */
  713. typedef enum
  714. {
  715. AACENC_INIT_NONE = 0x0000, /*!< Do not trigger initialization. */
  716. AACENC_INIT_CONFIG = 0x0001, /*!< Initialize all encoder modules configuration. */
  717. AACENC_INIT_STATES = 0x0002, /*!< Reset all encoder modules history buffer. */
  718. AACENC_INIT_TRANSPORT = 0x1000, /*!< Initialize transport lib with new parameters. */
  719. AACENC_RESET_INBUFFER = 0x2000, /*!< Reset fill level of internal input buffer. */
  720. AACENC_INIT_ALL = 0xFFFF /*!< Initialize all. */
  721. }
  722. AACENC_CTRLFLAGS;
  723. /**
  724. * \brief AAC encoder setting parameters.
  725. *
  726. * Use aacEncoder_SetParam() function to configure, or use aacEncoder_GetParam() function to read
  727. * the internal status of the following parameters.
  728. */
  729. typedef enum
  730. {
  731. AACENC_AOT = 0x0100, /*!< Audio object type. See ::AUDIO_OBJECT_TYPE in FDK_audio.h.
  732. - 2: MPEG-4 AAC Low Complexity.
  733. - 5: MPEG-4 AAC Low Complexity with Spectral Band Replication (HE-AAC).
  734. - 29: MPEG-4 AAC Low Complexity with Spectral Band Replication and Parametric Stereo (HE-AAC v2).
  735. This configuration can be used only with stereo input audio data.
  736. - 23: MPEG-4 AAC Low-Delay.
  737. - 39: MPEG-4 AAC Enhanced Low-Delay. Since there is no ::AUDIO_OBJECT_TYPE for ELD in
  738. combination with SBR defined, enable SBR explicitely by ::AACENC_SBR_MODE parameter. */
  739. AACENC_BITRATE = 0x0101, /*!< Total encoder bitrate. This parameter is mandatory and interacts with ::AACENC_BITRATEMODE.
  740. - CBR: Bitrate in bits/second.
  741. See \ref suppBitrates for details. */
  742. AACENC_BITRATEMODE = 0x0102, /*!< Bitrate mode. Configuration can be different kind of bitrate configurations:
  743. - 0: Constant bitrate, use bitrate according to ::AACENC_BITRATE. (default)
  744. Within none LD/ELD ::AUDIO_OBJECT_TYPE, the CBR mode makes use of full allowed bitreservoir.
  745. In contrast, at Low-Delay ::AUDIO_OBJECT_TYPE the bitreservoir is kept very small.
  746. - 8: LD/ELD full bitreservoir for packet based transmission. */
  747. AACENC_SAMPLERATE = 0x0103, /*!< Audio input data sampling rate. Encoder supports following sampling rates:
  748. 8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100, 48000, 64000, 88200, 96000 */
  749. AACENC_SBR_MODE = 0x0104, /*!< Configure SBR independently of the chosen Audio Object Type ::AUDIO_OBJECT_TYPE.
  750. This parameter is for ELD audio object type only.
  751. - -1: Use ELD SBR auto configurator (default).
  752. - 0: Disable Spectral Band Replication.
  753. - 1: Enable Spectral Band Replication. */
  754. AACENC_GRANULE_LENGTH = 0x0105, /*!< Core encoder (AAC) audio frame length in samples:
  755. - 1024: Default configuration.
  756. - 512: Default LD/ELD configuration.
  757. - 480: Optional length in LD/ELD configuration. */
  758. AACENC_CHANNELMODE = 0x0106, /*!< Set explicit channel mode. Channel mode must match with number of input channels.
  759. - 1-7 and 33,34: MPEG channel modes supported, see ::CHANNEL_MODE in FDK_audio.h. */
  760. AACENC_CHANNELORDER = 0x0107, /*!< Input audio data channel ordering scheme:
  761. - 0: MPEG channel ordering (e. g. 5.1: C, L, R, SL, SR, LFE). (default)
  762. - 1: WAVE file format channel ordering (e. g. 5.1: L, R, C, LFE, SL, SR). */
  763. AACENC_SBR_RATIO = 0x0108, /*!< Controls activation of downsampled SBR. With downsampled SBR, the delay will be
  764. shorter. On the other hand, for achieving the same quality level, downsampled SBR
  765. needs more bits than dual-rate SBR.
  766. With downsampled SBR, the AAC encoder will work at the same sampling rate as the
  767. SBR encoder (single rate).
  768. Downsampled SBR is supported for AAC-ELD and HE-AACv1.
  769. - 1: Downsampled SBR (default for ELD).
  770. - 2: Dual-rate SBR (default for HE-AAC). */
  771. AACENC_AFTERBURNER = 0x0200, /*!< This parameter controls the use of the afterburner feature.
  772. The afterburner is a type of analysis by synthesis algorithm which increases the
  773. audio quality but also the required processing power. It is recommended to always
  774. activate this if additional memory consumption and processing power consumption
  775. is not a problem. If increased MHz and memory consumption are an issue then the MHz
  776. and memory cost of this optional module need to be evaluated against the improvement
  777. in audio quality on a case by case basis.
  778. - 0: Disable afterburner (default).
  779. - 1: Enable afterburner. */
  780. AACENC_BANDWIDTH = 0x0203, /*!< Core encoder audio bandwidth:
  781. - 0: Determine bandwidth internally (default, see chapter \ref BEHAVIOUR_BANDWIDTH).
  782. - 1 to fs/2: Frequency bandwidth in Hertz. (Experts only, better do not
  783. touch this value to avoid degraded audio quality) */
  784. AACENC_PEAK_BITRATE = 0x0207, /*!< Peak bitrate configuration parameter to adjust maximum bits per audio frame. Bitrate is in bits/second.
  785. The peak bitrate will internally be limited to the chosen bitrate ::AACENC_BITRATE as lower limit
  786. and the number_of_effective_channels*6144 bit as upper limit.
  787. Setting the peak bitrate equal to ::AACENC_BITRATE does not necessarily mean that the audio frames
  788. will be of constant size. Since the peak bitate is in bits/second, the frame sizes can vary by
  789. one byte in one or the other direction over various frames. However, it is not recommended to reduce
  790. the peak pitrate to ::AACENC_BITRATE - it would disable the bitreservoir, which would affect the
  791. audio quality by a large amount. */
  792. AACENC_TRANSMUX = 0x0300, /*!< Transport type to be used. See ::TRANSPORT_TYPE in FDK_audio.h. Following
  793. types can be configured in encoder library:
  794. - 0: raw access units
  795. - 1: ADIF bitstream format
  796. - 2: ADTS bitstream format
  797. - 6: Audio Mux Elements (LATM) with muxConfigPresent = 1
  798. - 7: Audio Mux Elements (LATM) with muxConfigPresent = 0, out of band StreamMuxConfig
  799. - 10: Audio Sync Stream (LOAS) */
  800. AACENC_HEADER_PERIOD = 0x0301, /*!< Frame count period for sending in-band configuration buffers within LATM/LOAS
  801. transport layer. Additionally this parameter configures the PCE repetition period
  802. in raw_data_block(). See \ref encPCE.
  803. - 0xFF: auto-mode default 10 for TT_MP4_ADTS, TT_MP4_LOAS and TT_MP4_LATM_MCP1, otherwise 0.
  804. - n: Frame count period. */
  805. AACENC_SIGNALING_MODE = 0x0302, /*!< Signaling mode of the extension AOT:
  806. - 0: Implicit backward compatible signaling (default for non-MPEG-4 based
  807. AOT's and for the transport formats ADIF and ADTS)
  808. - A stream that uses implicit signaling can be decoded by every AAC decoder, even AAC-LC-only decoders
  809. - An AAC-LC-only decoder will only decode the low-frequency part of the stream, resulting in a band-limited output
  810. - This method works with all transport formats
  811. - This method does not work with downsampled SBR
  812. - 1: Explicit backward compatible signaling
  813. - A stream that uses explicit backward compatible signaling can be decoded by every AAC decoder, even AAC-LC-only decoders
  814. - An AAC-LC-only decoder will only decode the low-frequency part of the stream, resulting in a band-limited output
  815. - A decoder not capable of decoding PS will only decode the AAC-LC+SBR part.
  816. If the stream contained PS, the result will be a a decoded mono downmix
  817. - This method does not work with ADIF or ADTS. For LOAS/LATM, it only works with AudioMuxVersion==1
  818. - This method does work with downsampled SBR
  819. - 2: Explicit hierarchical signaling (default for MPEG-4 based AOT's and for all transport formats excluding ADIF and ADTS)
  820. - A stream that uses explicit hierarchical signaling can be decoded only by HE-AAC decoders
  821. - An AAC-LC-only decoder will not decode a stream that uses explicit hierarchical signaling
  822. - A decoder not capable of decoding PS will not decode the stream at all if it contained PS
  823. - This method does not work with ADIF or ADTS. It works with LOAS/LATM and the MPEG-4 File format
  824. - This method does work with downsampled SBR
  825. For making sure that the listener always experiences the best audio quality,
  826. explicit hierarchical signaling should be used.
  827. This makes sure that only a full HE-AAC-capable decoder will decode those streams.
  828. The audio is played at full bandwidth.
  829. For best backwards compatibility, it is recommended to encode with implicit SBR signaling.
  830. A decoder capable of AAC-LC only will then only decode the AAC part, which means the decoded
  831. audio will sound band-limited.
  832. For MPEG-2 transport types (ADTS,ADIF), only implicit signaling is possible.
  833. For LOAS and LATM, explicit backwards compatible signaling only works together with AudioMuxVersion==1.
  834. The reason is that, for explicit backwards compatible signaling, additional information will be appended to the ASC.
  835. A decoder that is only capable of decoding AAC-LC will skip this part.
  836. Nevertheless, for jumping to the end of the ASC, it needs to know the ASC length.
  837. Transmitting the length of the ASC is a feature of AudioMuxVersion==1, it is not possible to transmit the
  838. length of the ASC with AudioMuxVersion==0, therefore an AAC-LC-only decoder will not be able to parse a
  839. LOAS/LATM stream that was being encoded with AudioMuxVersion==0.
  840. For downsampled SBR, explicit signaling is mandatory. The reason for this is that the
  841. extension sampling frequency (which is in case of SBR the sampling frequqncy of the SBR part)
  842. can only be signaled in explicit mode.
  843. For AAC-ELD, the SBR information is transmitted in the ELDSpecific Config, which is part of the
  844. AudioSpecificConfig. Therefore, the settings here will have no effect on AAC-ELD.*/
  845. AACENC_TPSUBFRAMES = 0x0303, /*!< Number of sub frames in a transport frame for LOAS/LATM or ADTS (default 1).
  846. - ADTS: Maximum number of sub frames restricted to 4.
  847. - LOAS/LATM: Maximum number of sub frames restricted to 2.*/
  848. AACENC_AUDIOMUXVER = 0x0304, /*!< AudioMuxVersion to be used for LATM. (AudioMuxVersionA, currently not implemented):
  849. - 0: Default, no transmission of tara Buffer fullness, no ASC length and including actual latm Buffer fullnes.
  850. - 1: Transmission of tara Buffer fullness, ASC length and actual latm Buffer fullness.
  851. - 2: Transmission of tara Buffer fullness, ASC length and maximum level of latm Buffer fullness. */
  852. AACENC_PROTECTION = 0x0306, /*!< Configure protection in tranpsort layer:
  853. - 0: No protection. (default)
  854. - 1: CRC active for ADTS bitstream format. */
  855. AACENC_ANCILLARY_BITRATE = 0x0500, /*!< Constant ancillary data bitrate in bits/second.
  856. - 0: Either no ancillary data or insert exact number of bytes, denoted via
  857. input parameter, numAncBytes in AACENC_InArgs.
  858. - else: Insert ancillary data with specified bitrate. */
  859. AACENC_METADATA_MODE = 0x0600, /*!< Configure Meta Data. See ::AACENC_MetaData for further details:
  860. - 0: Do not embed any metadata.
  861. - 1: Embed MPEG defined metadata only.
  862. - 2: Embed all metadata. */
  863. AACENC_CONTROL_STATE = 0xFF00, /*!< There is an automatic process which internally reconfigures the encoder instance
  864. when a configuration parameter changed or an error occured. This paramerter allows
  865. overwriting or getting the control status of this process. See ::AACENC_CTRLFLAGS. */
  866. AACENC_NONE = 0xFFFF /*!< ------ */
  867. } AACENC_PARAM;
  868. #ifdef __cplusplus
  869. extern "C" {
  870. #endif
  871. /**
  872. * \brief Open an instance of the encoder.
  873. *
  874. * Allocate memory for an encoder instance with a functional range denoted by the function parameters.
  875. * Preinitialize encoder instance with default configuration.
  876. *
  877. * \param phAacEncoder A pointer to an encoder handle. Initialized on return.
  878. * \param encModules Specify encoder modules to be supported in this encoder instance:
  879. * - 0x0: Allocate memory for all available encoder modules.
  880. * - else: Select memory allocation regarding encoder modules. Following flags are possible and can be combined.
  881. * - 0x01: AAC module.
  882. * - 0x02: SBR module.
  883. * - 0x04: PS module.
  884. * - 0x10: Metadata module.
  885. * - example: (0x01|0x02|0x04|0x10) allocates all modules and is equivalent to default configuration denotet by 0x0.
  886. * \param maxChannels Number of channels to be allocated. This parameter can be used in different ways:
  887. * - 0: Allocate maximum number of AAC and SBR channels as supported by the library.
  888. * - nChannels: Use same maximum number of channels for allocating memory in AAC and SBR module.
  889. * - nChannels | (nSbrCh<<8): Number of SBR channels can be different to AAC channels to save data memory.
  890. *
  891. * \return
  892. * - AACENC_OK, on succes.
  893. * - AACENC_INVALID_HANDLE, AACENC_MEMORY_ERROR, AACENC_INVALID_CONFIG, on failure.
  894. */
  895. AACENC_ERROR aacEncOpen(
  896. HANDLE_AACENCODER *phAacEncoder,
  897. const UINT encModules,
  898. const UINT maxChannels
  899. );
  900. /**
  901. * \brief Close the encoder instance.
  902. *
  903. * Deallocate encoder instance and free whole memory.
  904. *
  905. * \param phAacEncoder Pointer to the encoder handle to be deallocated.
  906. *
  907. * \return
  908. * - AACENC_OK, on success.
  909. * - AACENC_INVALID_HANDLE, on failure.
  910. */
  911. AACENC_ERROR aacEncClose(
  912. HANDLE_AACENCODER *phAacEncoder
  913. );
  914. /**
  915. * \brief Encode audio data.
  916. *
  917. * This function is mainly for encoding audio data. In addition the function can be used for an encoder (re)configuration
  918. * process.
  919. * - PCM input data will be retrieved from external input buffer until the fill level allows encoding a single frame.
  920. * This functionality allows an external buffer with reduced size in comparison to the AAC or HE-AAC audio frame length.
  921. * - If the value of the input samples argument is zero, just internal reinitialization will be applied if it is
  922. * requested.
  923. * - At the end of a file the flushing process can be triggerd via setting the value of the input samples argument to -1.
  924. * The encoder delay lines are fully flushed when the encoder returns no valid bitstream data AACENC_OutArgs::numOutBytes.
  925. * Furthermore the end of file is signaled by the return value AACENC_ENCODE_EOF.
  926. * - If an error occured in the previous frame or any of the encoder parameters changed, an internal reinitialization
  927. * process will be applied before encoding the incoming audio samples.
  928. * - The function can also be used for an independent reconfiguration process without encoding. The first parameter has to be a
  929. * valid encoder handle and all other parameters can be set to NULL.
  930. * - If the size of the external bitbuffer in outBufDesc is not sufficient for writing the whole bitstream, an internal
  931. * error will be the return value and a reconfiguration will be triggered.
  932. *
  933. * \param hAacEncoder A valid AAC encoder handle.
  934. * \param inBufDesc Input buffer descriptor, see AACENC_BufDesc:
  935. * - At least one input buffer with audio data is expected.
  936. * - Optionally a second input buffer with ancillary data can be fed.
  937. * \param outBufDesc Output buffer descriptor, see AACENC_BufDesc:
  938. * - Provide one output buffer for the encoded bitstream.
  939. * \param inargs Input arguments, see AACENC_InArgs.
  940. * \param outargs Output arguments, AACENC_OutArgs.
  941. *
  942. * \return
  943. * - AACENC_OK, on success.
  944. * - AACENC_INVALID_HANDLE, AACENC_ENCODE_ERROR, on failure in encoding process.
  945. * - AACENC_INVALID_CONFIG, AACENC_INIT_ERROR, AACENC_INIT_AAC_ERROR, AACENC_INIT_SBR_ERROR, AACENC_INIT_TP_ERROR,
  946. * AACENC_INIT_META_ERROR, on failure in encoder initialization.
  947. * - AACENC_ENCODE_EOF, when flushing fully concluded.
  948. */
  949. AACENC_ERROR aacEncEncode(
  950. const HANDLE_AACENCODER hAacEncoder,
  951. const AACENC_BufDesc *inBufDesc,
  952. const AACENC_BufDesc *outBufDesc,
  953. const AACENC_InArgs *inargs,
  954. AACENC_OutArgs *outargs
  955. );
  956. /**
  957. * \brief Acquire info about present encoder instance.
  958. *
  959. * This function retrieves information of the encoder configuration. In addition to informative internal states,
  960. * a configuration data block of the current encoder settings will be returned. The format is either Audio Specific Config
  961. * in case of Raw Packets transport format or StreamMuxConfig in case of LOAS/LATM transport format. The configuration
  962. * data block is binary coded as specified in ISO/IEC 14496-3 (MPEG-4 audio), to be used directly for MPEG-4 File Format
  963. * or RFC3016 or RFC3640 applications.
  964. *
  965. * \param hAacEncoder A valid AAC encoder handle.
  966. * \param pInfo Pointer to AACENC_InfoStruct. Filled on return.
  967. *
  968. * \return
  969. * - AACENC_OK, on succes.
  970. * - AACENC_INIT_ERROR, on failure.
  971. */
  972. AACENC_ERROR aacEncInfo(
  973. const HANDLE_AACENCODER hAacEncoder,
  974. AACENC_InfoStruct *pInfo
  975. );
  976. /**
  977. * \brief Set one single AAC encoder parameter.
  978. *
  979. * This function allows configuration of all encoder parameters specified in ::AACENC_PARAM. Each parameter must be
  980. * set with a separate function call. An internal validation of the configuration value range will be done and an
  981. * internal reconfiguration will be signaled. The actual configuration adoption is part of the subsequent aacEncEncode() call.
  982. *
  983. * \param hAacEncoder A valid AAC encoder handle.
  984. * \param param Parameter to be set. See ::AACENC_PARAM.
  985. * \param value Parameter value. See parameter description in ::AACENC_PARAM.
  986. *
  987. * \return
  988. * - AACENC_OK, on success.
  989. * - AACENC_INVALID_HANDLE, AACENC_UNSUPPORTED_PARAMETER, AACENC_INVALID_CONFIG, on failure.
  990. */
  991. AACENC_ERROR aacEncoder_SetParam(
  992. const HANDLE_AACENCODER hAacEncoder,
  993. const AACENC_PARAM param,
  994. const UINT value
  995. );
  996. /**
  997. * \brief Get one single AAC encoder parameter.
  998. *
  999. * This function is the complement to aacEncoder_SetParam(). After encoder reinitialization with user defined settings,
  1000. * the internal status can be obtained of each parameter, specified with ::AACENC_PARAM.
  1001. *
  1002. * \param hAacEncoder A valid AAC encoder handle.
  1003. * \param param Parameter to be returned. See ::AACENC_PARAM.
  1004. *
  1005. * \return Internal configuration value of specifed parameter ::AACENC_PARAM.
  1006. */
  1007. UINT aacEncoder_GetParam(
  1008. const HANDLE_AACENCODER hAacEncoder,
  1009. const AACENC_PARAM param
  1010. );
  1011. /**
  1012. * \brief Get information about encoder library build.
  1013. *
  1014. * Fill a given LIB_INFO structure with library version information.
  1015. *
  1016. * \param info Pointer to an allocated LIB_INFO struct.
  1017. *
  1018. * \return
  1019. * - AACENC_OK, on success.
  1020. * - AACENC_INVALID_HANDLE, AACENC_INIT_ERROR, on failure.
  1021. */
  1022. AACENC_ERROR aacEncGetLibInfo(
  1023. LIB_INFO *info
  1024. );
  1025. #ifdef __cplusplus
  1026. }
  1027. #endif
  1028. #endif /* _AAC_ENC_LIB_H_ */