pcmutils_lib.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. /* -----------------------------------------------------------------------------------------------------------
  2. Software License for The Fraunhofer FDK AAC Codec Library for Android
  3. © Copyright 1995 - 2013 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. /************************ FDK PCM up/downmixing module *********************
  63. Author(s): Christian Griebel
  64. Description: Declares functions to interface with the PCM downmix processing
  65. module.
  66. *******************************************************************************/
  67. #ifndef _PCMUTILS_LIB_H_
  68. #define _PCMUTILS_LIB_H_
  69. #include "machine_type.h"
  70. #include "common_fix.h"
  71. #include "FDK_audio.h"
  72. #include "FDK_bitstream.h"
  73. /* ------------------------ *
  74. * ERROR CODES: *
  75. * ------------------------ */
  76. typedef enum
  77. {
  78. PCMDMX_OK = 0x0, /*!< No error happened. */
  79. pcm_dmx_fatal_error_start,
  80. PCMDMX_OUT_OF_MEMORY = 0x2, /*!< Not enough memory to set up an instance of the module. */
  81. PCMDMX_UNKNOWN = 0x5, /*!< Error condition is of unknown reason, or from a third
  82. party module. */
  83. pcm_dmx_fatal_error_end,
  84. PCMDMX_INVALID_HANDLE, /*!< The given instance handle is not valid. */
  85. PCMDMX_INVALID_ARGUMENT, /*!< One of the parameters handed over is invalid. */
  86. PCMDMX_INVALID_CH_CONFIG, /*!< The given channel configuration is not supported and thus
  87. no processing was performed. */
  88. PCMDMX_INVALID_MODE, /*!< The set configuration/mode is not applicable. */
  89. PCMDMX_UNKNOWN_PARAM, /*!< The handed parameter is not known/supported. */
  90. PCMDMX_UNABLE_TO_SET_PARAM, /*!< Unable to set the specific parameter. Most probably the
  91. value ist out of range. */
  92. PCMDMX_CORRUPT_ANC_DATA /*!< The read ancillary data was corrupt. */
  93. } PCMDMX_ERROR;
  94. /** Macro to identify fatal errors. */
  95. #define PCMDMX_IS_FATAL_ERROR(err) ( (((err)>=pcm_dmx_fatal_error_start) && ((err)<=pcm_dmx_fatal_error_end)) ? 1 : 0)
  96. /* ------------------------ *
  97. * RUNTIME PARAMS: *
  98. * ------------------------ */
  99. typedef enum
  100. {
  101. DMX_BS_DATA_EXPIRY_FRAME, /*!< The number of frames without new metadata that have to go
  102. by before the bitstream data expires. The value 0 disables
  103. expiry. */
  104. DMX_BS_DATA_DELAY, /*!< The number of delay frames of the output samples compared
  105. to the bitstream data. */
  106. MIN_NUMBER_OF_OUTPUT_CHANNELS, /*!< The minimum number of output channels. For all input
  107. configurations that have less than the given channels the
  108. module will modify the output automatically to obtain the
  109. given number of output channels. Mono signals will be
  110. duplicated. If more than two output channels are desired
  111. the module just adds empty channels. The parameter value
  112. must be either -1, 0, 1, 2, 6 or 8. If the value is
  113. greater than zero and exceeds the value of parameter
  114. MAX_NUMBER_OF_OUTPUT_CHANNELS the latter will be set to
  115. the same value. Both values -1 and 0 disable the feature. */
  116. MAX_NUMBER_OF_OUTPUT_CHANNELS, /*!< The maximum number of output channels. For all input
  117. configurations that have more than the given channels the
  118. module will apply a mixdown automatically to obtain the
  119. given number of output channels. The value must be either
  120. -1, 0, 1, 2, 6 or 8. If it is greater than zero and lower
  121. or equal than the value of MIN_NUMBER_OF_OUTPUT_CHANNELS
  122. parameter the latter will be set to the same value.
  123. The values -1 and 0 disable the feature. */
  124. DMX_DUAL_CHANNEL_MODE, /*!< Downmix mode for two channel audio data. */
  125. DMX_PSEUDO_SURROUND_MODE /*!< Defines how module handles pseudo surround compatible
  126. signals. See PSEUDO_SURROUND_MODE type for details. */
  127. } PCMDMX_PARAM;
  128. /* Parameter value types */
  129. typedef enum
  130. {
  131. NEVER_DO_PS_DMX = -1, /*!< Never create a pseudo surround compatible downmix. */
  132. AUTO_PS_DMX = 0, /*!< Create a pseudo surround compatible downmix only if
  133. signalled in bitstreams meta data. (Default) */
  134. FORCE_PS_DMX = 1 /*!< Always create a pseudo surround compatible downmix.
  135. CAUTION: This can lead to excessive signal cancellations
  136. and signal level differences for non-compatible signals. */
  137. } PSEUDO_SURROUND_MODE;
  138. typedef enum
  139. {
  140. STEREO_MODE = 0x0, /*!< Leave stereo signals as they are. */
  141. CH1_MODE = 0x1, /*!< Create a dual mono output signal from channel 1. */
  142. CH2_MODE = 0x2, /*!< Create a dual mono output signal from channel 2. */
  143. MIXED_MODE = 0x3 /*!< Create a dual mono output signal by mixing the two
  144. channels. */
  145. } DUAL_CHANNEL_MODE;
  146. /* ------------------------ *
  147. * MODULES INTERFACE: *
  148. * ------------------------ */
  149. typedef struct PCM_DMX_INSTANCE *HANDLE_PCM_DOWNMIX;
  150. /* Modules reset flags */
  151. #define PCMDMX_RESET_PARAMS ( 1 )
  152. #define PCMDMX_RESET_BS_DATA ( 2 )
  153. #define PCMDMX_RESET_FULL ( PCMDMX_RESET_PARAMS | PCMDMX_RESET_BS_DATA )
  154. #ifdef __cplusplus
  155. extern "C"
  156. {
  157. #endif
  158. /** Open and initialize an instance of the PCM downmix module
  159. * @param [out] Pointer to a buffer receiving the handle of the new instance.
  160. * @returns Returns an error code.
  161. **/
  162. PCMDMX_ERROR pcmDmx_Open (
  163. HANDLE_PCM_DOWNMIX *pSelf
  164. );
  165. /** Set one parameter for one instance of the PCM downmix module.
  166. * @param [in] Handle of PCM downmix instance.
  167. * @param [in] Parameter to be set.
  168. * @param [in] Parameter value.
  169. * @returns Returns an error code.
  170. **/
  171. PCMDMX_ERROR pcmDmx_SetParam (
  172. HANDLE_PCM_DOWNMIX self,
  173. const PCMDMX_PARAM param,
  174. const INT value
  175. );
  176. /** Get one parameter value of one PCM downmix module instance.
  177. * @param [in] Handle of PCM downmix module instance.
  178. * @param [in] Parameter to be set.
  179. * @param [out] Pointer to buffer receiving the parameter value.
  180. * @returns Returns an error code.
  181. **/
  182. PCMDMX_ERROR pcmDmx_GetParam (
  183. HANDLE_PCM_DOWNMIX self,
  184. const PCMDMX_PARAM param,
  185. INT * const pValue
  186. );
  187. /** Read downmix meta-data directly from a given bitstream.
  188. * @param [in] Handle of PCM downmix instance.
  189. * @param [in] Handle of FDK bitstream buffer.
  190. * @param [in] Length of ancillary data in bits.
  191. * @param [in] Flag indicating wheter the ancillary data is from a MPEG-1/2 or an MPEG-4 stream.
  192. * @returns Returns an error code.
  193. **/
  194. PCMDMX_ERROR pcmDmx_Parse (
  195. HANDLE_PCM_DOWNMIX self,
  196. HANDLE_FDK_BITSTREAM hBitStream,
  197. UINT ancDataBits,
  198. int isMpeg2
  199. );
  200. /** Read downmix meta-data from a given data buffer.
  201. * @param [in] Handle of PCM downmix instance.
  202. * @param [in] Pointer to ancillary data buffer.
  203. * @param [in] Size of ancillary data in bytes.
  204. * @param [in] Flag indicating wheter the ancillary data is from a MPEG-1/2 or an MPEG-4 stream.
  205. * @returns Returns an error code.
  206. **/
  207. PCMDMX_ERROR pcmDmx_ReadDvbAncData (
  208. HANDLE_PCM_DOWNMIX self,
  209. UCHAR *pAncDataBuf,
  210. UINT ancDataBytes,
  211. int isMpeg2
  212. );
  213. /** Set the matrix mixdown information extracted from the PCE of an AAC bitstream.
  214. * @param [in] Handle of PCM downmix instance.
  215. * @param [in] Matrix mixdown index present flag extracted from PCE.
  216. * @param [in] The 2 bit matrix mixdown index extracted from PCE.
  217. * @param [in] The pseudo surround enable flag extracted from PCE.
  218. * @returns Returns an error code.
  219. **/
  220. PCMDMX_ERROR pcmDmx_SetMatrixMixdownFromPce (
  221. HANDLE_PCM_DOWNMIX self,
  222. int matrixMixdownPresent,
  223. int matrixMixdownIdx,
  224. int pseudoSurroundEnable
  225. );
  226. /** Reset the module.
  227. * @param [in] Handle of PCM downmix instance.
  228. * @param [in] Flags telling which parts of the module shall be reset.
  229. * @returns Returns an error code.
  230. **/
  231. PCMDMX_ERROR pcmDmx_Reset (
  232. HANDLE_PCM_DOWNMIX self,
  233. UINT flags
  234. );
  235. /** Create a mixdown, bypass or extend the output signal depending on the modules settings and the
  236. * respective given input configuration.
  237. *
  238. * \param [in] Handle of PCM downmix module instance.
  239. * \param [inout] Pointer to time buffer with decoded PCM samples.
  240. * \param [in] The I/O block size which is the number of samples per channel.
  241. * \param [inout] Pointer to buffer that holds the number of input channels and where the
  242. * amount of output channels is written to.
  243. * \param [in] Flag which indicates if output time data is writtern interleaved or as
  244. * subsequent blocks.
  245. * \param [inout] Array were the corresponding channel type for each output audio channel is
  246. * stored into.
  247. * \param [inout] Array were the corresponding channel type index for each output audio channel
  248. * is stored into.
  249. * \param [in] Array containing the output channel mapping to be used (from MPEG PCE ordering
  250. * to whatever is required).
  251. * \param [out] Pointer on a field receiving the scale factor that has to be applied on all
  252. * samples afterwards. If the handed pointer is NULL the final scaling is done
  253. * internally.
  254. * @returns Returns an error code.
  255. **/
  256. PCMDMX_ERROR pcmDmx_ApplyFrame (
  257. HANDLE_PCM_DOWNMIX self,
  258. INT_PCM *pPcmBuf,
  259. UINT frameSize,
  260. INT *nChannels,
  261. int fInterleaved,
  262. AUDIO_CHANNEL_TYPE channelType[],
  263. UCHAR channelIndices[],
  264. const UCHAR channelMapping[][8],
  265. INT *pDmxOutScale
  266. );
  267. /** Close an instance of the PCM downmix module.
  268. * @param [inout] Pointer to a buffer containing the handle of the instance.
  269. * @returns Returns an error code.
  270. **/
  271. PCMDMX_ERROR pcmDmx_Close (
  272. HANDLE_PCM_DOWNMIX *pSelf
  273. );
  274. /** Get library info for this module.
  275. * @param [out] Pointer to an allocated LIB_INFO structure.
  276. * @returns Returns an error code.
  277. */
  278. PCMDMX_ERROR pcmDmx_GetLibInfo( LIB_INFO *info );
  279. #ifdef __cplusplus
  280. }
  281. #endif
  282. #endif /* _PCMUTILS_LIB_H_ */