sbrdecoder.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  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. /************************ Fraunhofer IIS SBR decoder library ******************
  63. Author(s):
  64. Description: SBR decoder front-end prototypes and definitions.
  65. ******************************************************************************/
  66. #ifndef __SBRDECODER_H
  67. #define __SBRDECODER_H
  68. #include "common_fix.h"
  69. #include "FDK_bitstream.h"
  70. #include "FDK_audio.h"
  71. #define SBR_DEBUG_EXTHLP "\
  72. --- SBR ---\n\
  73. 0x00000010 Ancillary data and SBR-Header\n\
  74. 0x00000020 SBR-Side info\n\
  75. 0x00000040 Decoded SBR-bitstream data, e.g. envelope data\n\
  76. 0x00000080 SBR-Bitstream statistics\n\
  77. 0x00000100 Miscellaneous SBR-messages\n\
  78. 0x00000200 SBR-Energies and gains in the adjustor\n\
  79. 0x00000400 Fatal SBR errors\n\
  80. 0x00000800 Transposer coefficients for inverse filtering\n\
  81. "
  82. /* Capability flags */
  83. #define CAPF_SBR_LP 0x00000001 /*!< Flag indicating library's capability of Low Power mode. */
  84. #define CAPF_SBR_HQ 0x00000002 /*!< Flag indicating library's capability of High Quality mode. */
  85. #define CAPF_SBR_DRM_BS 0x00000004 /*!< Flag indicating library's capability to decode DRM SBR data. */
  86. #define CAPF_SBR_CONCEALMENT 0x00000008 /*!< Flag indicating library's capability to conceal erroneous frames. */
  87. #define CAPF_SBR_DRC 0x00000010 /*!< Flag indicating library's capability for Dynamic Range Control. */
  88. #define CAPF_SBR_PS_MPEG 0x00000020 /*!< Flag indicating library's capability to do MPEG Parametric Stereo. */
  89. #define CAPF_SBR_PS_DRM 0x00000040 /*!< Flag indicating library's capability to do DRM Parametric Stereo. */
  90. typedef enum
  91. {
  92. SBRDEC_OK = 0, /*!< All fine. */
  93. /* SBRDEC_CONCEAL, */
  94. /* SBRDEC_NOSYNCH, */
  95. /* SBRDEC_ILLEGAL_PROGRAM, */
  96. /* SBRDEC_ILLEGAL_TAG, */
  97. /* SBRDEC_ILLEGAL_CHN_CONFIG, */
  98. /* SBRDEC_ILLEGAL_SECTION, */
  99. /* SBRDEC_ILLEGAL_SCFACTORS, */
  100. /* SBRDEC_ILLEGAL_PULSE_DATA, */
  101. /* SBRDEC_MAIN_PROFILE_NOT_IMPLEMENTED, */
  102. /* SBRDEC_GC_NOT_IMPLEMENTED, */
  103. /* SBRDEC_ILLEGAL_PLUS_ELE_ID, */
  104. SBRDEC_CREATE_ERROR, /*!< */
  105. SBRDEC_NOT_INITIALIZED, /*!< */
  106. SBRDEC_MEM_ALLOC_FAILED, /*!< Memory allocation failed. Probably not enough memory available. */
  107. SBRDEC_PARSE_ERROR, /*!< */
  108. SBRDEC_UNSUPPORTED_CONFIG, /*!< */
  109. SBRDEC_SET_PARAM_FAIL /*!< */
  110. } SBR_ERROR;
  111. typedef enum
  112. {
  113. SBR_SYSTEM_BITSTREAM_DELAY, /*!< System: Switch to enable an additional SBR bitstream delay of one frame. */
  114. SBR_QMF_MODE, /*!< Set QMF mode, either complex or low power. */
  115. SBR_LD_QMF_TIME_ALIGN, /*!< Set QMF type, either LD-MPS or CLDFB. Relevant for ELD streams only. */
  116. SBR_FLUSH_DATA, /*!< Set internal state to flush the decoder with the next process call. */
  117. SBR_CLEAR_HISTORY, /*!< Clear all internal states (delay lines, QMF states, ...). */
  118. SBR_BS_INTERRUPTION /*!< Signal bit stream interruption. Value is ignored. */
  119. } SBRDEC_PARAM;
  120. typedef struct SBR_DECODER_INSTANCE *HANDLE_SBRDECODER;
  121. #ifdef __cplusplus
  122. extern "C"
  123. {
  124. #endif
  125. /**
  126. * \brief Allocates and initializes one SBR decoder instance.
  127. * \param pSelf Pointer to where a SBR decoder handle is copied into.
  128. * \return Error code.
  129. */
  130. SBR_ERROR sbrDecoder_Open ( HANDLE_SBRDECODER *pSelf );
  131. /**
  132. * \brief Initialize a SBR decoder runtime instance. Must be called before decoding starts.
  133. *
  134. * \param self Handle to a SBR decoder instance.
  135. * \param sampleRateIn Input samplerate of the SBR decoder instance.
  136. * \param sampleRateOut Output samplerate of the SBR decoder instance.
  137. * \param samplesPerFrame Number of samples per frames.
  138. * \param coreCodec Audio Object Type (AOT) of the core codec.
  139. * \param elementID Table with MPEG-4 element Ids in canonical order.
  140. * \param forceReset Flag that enforces a complete decoder reset.
  141. *
  142. * \return Error code.
  143. */
  144. SBR_ERROR sbrDecoder_InitElement (
  145. HANDLE_SBRDECODER self,
  146. const int sampleRateIn,
  147. const int sampleRateOut,
  148. const int samplesPerFrame,
  149. const AUDIO_OBJECT_TYPE coreCodec,
  150. const MP4_ELEMENT_ID elementID,
  151. const int elementIndex
  152. );
  153. /**
  154. * \brief pass out of band SBR header to SBR decoder
  155. *
  156. * \param self Handle to a SBR decoder instance.
  157. * \param hBs bit stream handle data source.
  158. * \param elementID SBR element ID.
  159. * \param elementIndex SBR element index.
  160. *
  161. * \return Error code.
  162. */
  163. INT sbrDecoder_Header (
  164. HANDLE_SBRDECODER self,
  165. HANDLE_FDK_BITSTREAM hBs,
  166. const INT sampleRateIn,
  167. const INT sampleRateOut,
  168. const INT samplesPerFrame,
  169. const AUDIO_OBJECT_TYPE coreCodec,
  170. const MP4_ELEMENT_ID elementID,
  171. const INT elementIndex
  172. );
  173. /**
  174. * \brief Set a parameter of the SBR decoder runtime instance.
  175. * \param self SBR decoder handle.
  176. * \param param Parameter which will be set if successfull.
  177. * \param value New parameter value.
  178. * \return Error code.
  179. */
  180. SBR_ERROR sbrDecoder_SetParam ( HANDLE_SBRDECODER self,
  181. const SBRDEC_PARAM param,
  182. const INT value );
  183. /**
  184. * \brief Feed DRC channel data into a SBR decoder runtime instance.
  185. *
  186. * \param self SBR decoder handle.
  187. * \param ch Channel number to which the DRC data is associated to.
  188. * \param numBands Number of DRC bands.
  189. * \param pNextFact_mag Pointer to a table with the DRC factor magnitudes.
  190. * \param nextFact_exp Exponent for all DRC factors.
  191. * \param drcInterpolationScheme DRC interpolation scheme.
  192. * \param winSequence Window sequence from core coder (eight short or one long window).
  193. * \param pBandTop Pointer to a table with the top borders for all DRC bands.
  194. *
  195. * \return Error code.
  196. */
  197. SBR_ERROR sbrDecoder_drcFeedChannel ( HANDLE_SBRDECODER self,
  198. INT ch,
  199. UINT numBands,
  200. FIXP_DBL *pNextFact_mag,
  201. INT nextFact_exp,
  202. SHORT drcInterpolationScheme,
  203. UCHAR winSequence,
  204. USHORT *pBandTop );
  205. /**
  206. * \brief Disable SBR DRC for a certain channel.
  207. *
  208. * \param hSbrDecoder SBR decoder handle.
  209. * \param ch Number of the channel that has to be disabled.
  210. *
  211. * \return None.
  212. */
  213. void sbrDecoder_drcDisable ( HANDLE_SBRDECODER self,
  214. INT ch );
  215. /**
  216. * \brief Parse one SBR element data extension data block. The bit stream position will
  217. * be placed at the end of the SBR payload block. The remaining bits will be returned
  218. * into *count if a payload length is given (byPayLen > 0). If no SBR payload length is
  219. * given (bsPayLen < 0) then the bit stream position on return will be random after this
  220. * function call in case of errors, and any further decoding will be completely pointless.
  221. * This function accepts either normal ordered SBR data or reverse ordered DRM SBR data.
  222. *
  223. * \param self SBR decoder handle.
  224. * \param hBs Bit stream handle as data source.
  225. * \param count Pointer to an integer where the amount of parsed SBR payload bits is stored into.
  226. * \param bsPayLen If > 0 this value is the SBR payload length. If < 0, the SBR payload length is unknown.
  227. * \param flags CRC flag (0: EXT_SBR_DATA; 1: EXT_SBR_DATA_CRC)
  228. * \param prev_element Previous MPEG-4 element ID.
  229. * \param element_index Index of the current element.
  230. *
  231. * \return Error code.
  232. */
  233. SBR_ERROR sbrDecoder_Parse (
  234. HANDLE_SBRDECODER self,
  235. HANDLE_FDK_BITSTREAM hBs,
  236. int *count,
  237. int bsPayLen,
  238. int crcFlag,
  239. MP4_ELEMENT_ID prev_element,
  240. int element_index,
  241. int fGlobalIndependencyFlag
  242. );
  243. /**
  244. * \brief This function decodes the given SBR bitstreams and applies SBR to the given time data.
  245. *
  246. * SBR-processing works InPlace. I.e. the calling function has to provide
  247. * a time domain buffer timeData which can hold the completely decoded
  248. * result.
  249. *
  250. * Left and right channel are read and stored according to the
  251. * interleaving flag, frame length and number of channels.
  252. *
  253. * \param self Handle of an open SBR decoder instance.
  254. * \param hSbrBs SBR Bitstream handle.
  255. * \param timeData Pointer to input and finally upsampled output data.
  256. * \param numChannels Pointer to a buffer holding the number of channels in time data buffer.
  257. * \param sampleRate Output samplerate.
  258. * \param channelMapping Channel mapping indices.
  259. * \param interleaved Flag indicating if time data is stored interleaved (1: Interleaved time data, 0: non-interleaved timedata).
  260. * \param coreDecodedOk Flag indicating if the core decoder did not find any error (0: core decoder found errors, 1: no errors).
  261. * \param psDecoded Pointer to a buffer holding a flag. Input: PS is possible, Output: PS has been rendered.
  262. *
  263. * \return Error code.
  264. */
  265. SBR_ERROR sbrDecoder_Apply ( HANDLE_SBRDECODER self,
  266. INT_PCM *timeData,
  267. int *numChannels,
  268. int *sampleRate,
  269. const UCHAR channelMapping[(8)],
  270. const int interleaved,
  271. const int coreDecodedOk,
  272. UCHAR *psDecoded );
  273. /**
  274. * \brief Close SBR decoder instance and free memory.
  275. * \param self SBR decoder handle.
  276. * \return Error Code.
  277. */
  278. SBR_ERROR sbrDecoder_Close ( HANDLE_SBRDECODER *self );
  279. /**
  280. * \brief Get SBR decoder library information.
  281. * \param info Pointer to a LIB_INFO struct, where library information is written to.
  282. * \return 0 on success, -1 if invalid handle or if no free element is available to write information to.
  283. */
  284. INT sbrDecoder_GetLibInfo( LIB_INFO *info );
  285. /**
  286. * \brief Determine the modules output signal delay in samples.
  287. * \param self SBR decoder handle.
  288. * \return The number of samples signal delay added by the module.
  289. */
  290. UINT sbrDecoder_GetDelay( const HANDLE_SBRDECODER self );
  291. #ifdef __cplusplus
  292. }
  293. #endif
  294. #endif