1 
2 /* -----------------------------------------------------------------------------------------------------------
3 Software License for The Fraunhofer FDK AAC Codec Library for Android
4 
5 � Copyright  1995 - 2013 Fraunhofer-Gesellschaft zur F�rderung der angewandten Forschung e.V.
6   All rights reserved.
7 
8  1.    INTRODUCTION
9 The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software that implements
10 the MPEG Advanced Audio Coding ("AAC") encoding and decoding scheme for digital audio.
11 This FDK AAC Codec software is intended to be used on a wide variety of Android devices.
12 
13 AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient general perceptual
14 audio codecs. AAC-ELD is considered the best-performing full-bandwidth communications codec by
15 independent studies and is widely deployed. AAC has been standardized by ISO and IEC as part
16 of the MPEG specifications.
17 
18 Patent licenses for necessary patent claims for the FDK AAC Codec (including those of Fraunhofer)
19 may be obtained through Via Licensing (www.vialicensing.com) or through the respective patent owners
20 individually for the purpose of encoding or decoding bit streams in products that are compliant with
21 the ISO/IEC MPEG audio standards. Please note that most manufacturers of Android devices already license
22 these patent claims through Via Licensing or directly from the patent owners, and therefore FDK AAC Codec
23 software may already be covered under those patent licenses when it is used for those licensed purposes only.
24 
25 Commercially-licensed AAC software libraries, including floating-point versions with enhanced sound quality,
26 are also available from Fraunhofer. Users are encouraged to check the Fraunhofer website for additional
27 applications information and documentation.
28 
29 2.    COPYRIGHT LICENSE
30 
31 Redistribution and use in source and binary forms, with or without modification, are permitted without
32 payment of copyright license fees provided that you satisfy the following conditions:
33 
34 You must retain the complete text of this software license in redistributions of the FDK AAC Codec or
35 your modifications thereto in source code form.
36 
37 You must retain the complete text of this software license in the documentation and/or other materials
38 provided with redistributions of the FDK AAC Codec or your modifications thereto in binary form.
39 You must make available free of charge copies of the complete source code of the FDK AAC Codec and your
40 modifications thereto to recipients of copies in binary form.
41 
42 The name of Fraunhofer may not be used to endorse or promote products derived from this library without
43 prior written permission.
44 
45 You may not charge copyright license fees for anyone to use, copy or distribute the FDK AAC Codec
46 software or your modifications thereto.
47 
48 Your modified versions of the FDK AAC Codec must carry prominent notices stating that you changed the software
49 and the date of any change. For modified versions of the FDK AAC Codec, the term
50 "Fraunhofer FDK AAC Codec Library for Android" must be replaced by the term
51 "Third-Party Modified Version of the Fraunhofer FDK AAC Codec Library for Android."
52 
53 3.    NO PATENT LICENSE
54 
55 NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without limitation the patents of Fraunhofer,
56 ARE GRANTED BY THIS SOFTWARE LICENSE. Fraunhofer provides no warranty of patent non-infringement with
57 respect to this software.
58 
59 You may use this FDK AAC Codec software or modifications thereto only for purposes that are authorized
60 by appropriate patent licenses.
61 
62 4.    DISCLAIMER
63 
64 This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright holders and contributors
65 "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, including but not limited to the implied warranties
66 of merchantability and fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
67 CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary, or consequential damages,
68 including but not limited to procurement of substitute goods or services; loss of use, data, or profits,
69 or business interruption, however caused and on any theory of liability, whether in contract, strict
70 liability, or tort (including negligence), arising in any way out of the use of this software, even if
71 advised of the possibility of such damage.
72 
73 5.    CONTACT INFORMATION
74 
75 Fraunhofer Institute for Integrated Circuits IIS
76 Attention: Audio and Multimedia Departments - FDK AAC LL
77 Am Wolfsmantel 33
78 91058 Erlangen, Germany
79 
80 www.iis.fraunhofer.de/amm
81 amm-info@iis.fraunhofer.de
82 ----------------------------------------------------------------------------------------------------------- */
83 
84 /************************  Fraunhofer IIS SBR decoder library ******************
85 
86    Author(s):
87    Description: SBR decoder front-end prototypes and definitions.
88 
89 ******************************************************************************/
90 
91 #ifndef __SBRDECODER_H
92 #define __SBRDECODER_H
93 
94 #include "common_fix.h"
95 
96 #include "FDK_bitstream.h"
97 #include "FDK_audio.h"
98 
99 
100 #define SBR_DEBUG_EXTHLP "\
101 --- SBR ---\n\
102     0x00000010 Ancillary data and SBR-Header\n\
103     0x00000020 SBR-Side info\n\
104     0x00000040 Decoded SBR-bitstream data, e.g. envelope data\n\
105     0x00000080 SBR-Bitstream statistics\n\
106     0x00000100 Miscellaneous SBR-messages\n\
107     0x00000200 SBR-Energies and gains in the adjustor\n\
108     0x00000400 Fatal SBR errors\n\
109     0x00000800 Transposer coefficients for inverse filtering\n\
110 "
111 
112 /* Capability flags */
113 #define CAPF_SBR_LP          0x00000001   /*!< Flag indicating library's capability of Low Power mode.            */
114 #define CAPF_SBR_HQ          0x00000002   /*!< Flag indicating library's capability of High Quality mode.         */
115 #define CAPF_SBR_DRM_BS      0x00000004   /*!< Flag indicating library's capability to decode DRM SBR data.       */
116 #define CAPF_SBR_CONCEALMENT 0x00000008   /*!< Flag indicating library's capability to conceal erroneous frames.  */
117 #define CAPF_SBR_DRC         0x00000010   /*!< Flag indicating library's capability for Dynamic Range Control.    */
118 #define CAPF_SBR_PS_MPEG     0x00000020   /*!< Flag indicating library's capability to do MPEG Parametric Stereo. */
119 #define CAPF_SBR_PS_DRM      0x00000040   /*!< Flag indicating library's capability to do DRM Parametric Stereo.  */
120 
121 typedef enum
122 {
123   SBRDEC_OK = 0,                       /*!< All fine.                                                       */
124   /* SBRDEC_CONCEAL,                                                                                        */
125   /* SBRDEC_NOSYNCH,                                                                                        */
126   /* SBRDEC_ILLEGAL_PROGRAM,                                                                                */
127   /* SBRDEC_ILLEGAL_TAG,                                                                                    */
128   /* SBRDEC_ILLEGAL_CHN_CONFIG,                                                                             */
129   /* SBRDEC_ILLEGAL_SECTION,                                                                                */
130   /* SBRDEC_ILLEGAL_SCFACTORS,                                                                              */
131   /* SBRDEC_ILLEGAL_PULSE_DATA,                                                                             */
132   /* SBRDEC_MAIN_PROFILE_NOT_IMPLEMENTED,                                                                   */
133   /* SBRDEC_GC_NOT_IMPLEMENTED,                                                                             */
134   /* SBRDEC_ILLEGAL_PLUS_ELE_ID,                                                                            */
135   SBRDEC_CREATE_ERROR,                 /*!<                                                                 */
136   SBRDEC_NOT_INITIALIZED,              /*!<                                                                 */
137   SBRDEC_MEM_ALLOC_FAILED,             /*!< Memory allocation failed. Probably not enough memory available. */
138   SBRDEC_PARSE_ERROR,                  /*!<                                                                 */
139   SBRDEC_UNSUPPORTED_CONFIG,           /*!<                                                                 */
140   SBRDEC_SET_PARAM_FAIL                /*!<                                                                 */
141 } SBR_ERROR;
142 
143 typedef enum
144 {
145   SBR_SYSTEM_BITSTREAM_DELAY,          /*!< System: Switch to enable an additional SBR bitstream delay of one frame. */
146   SBR_QMF_MODE,                        /*!< Set QMF mode, either complex or low power. */
147   SBR_LD_QMF_TIME_ALIGN,               /*!< Set QMF type, either LD-MPS or CLDFB. Relevant for ELD streams only. */
148   SBR_FLUSH_DATA,                      /*!< Set internal state to flush the decoder with the next process call. */
149   SBR_CLEAR_HISTORY,                   /*!< Clear all internal states (delay lines, QMF states, ...). */
150   SBR_BS_INTERRUPTION                  /*!< Signal bit stream interruption. Value is ignored. */
151 } SBRDEC_PARAM;
152 
153 typedef struct SBR_DECODER_INSTANCE *HANDLE_SBRDECODER;
154 
155 
156 #ifdef __cplusplus
157 extern "C"
158 {
159 #endif
160 
161 
162 /**
163  * \brief        Allocates and initializes one SBR decoder instance.
164  * \param pSelf  Pointer to where a SBR decoder handle is copied into.
165  * \return       Error code.
166  */
167 SBR_ERROR sbrDecoder_Open ( HANDLE_SBRDECODER *pSelf );
168 
169 /**
170  * \brief  Initialize a SBR decoder runtime instance. Must be called before decoding starts.
171  *
172  * \param self             Handle to a SBR decoder instance.
173  * \param sampleRateIn     Input samplerate of the SBR decoder instance.
174  * \param sampleRateOut    Output samplerate of the SBR decoder instance.
175  * \param samplesPerFrame  Number of samples per frames.
176  * \param coreCodec        Audio Object Type (AOT) of the core codec.
177  * \param elementID        Table with MPEG-4 element Ids in canonical order.
178  * \param forceReset       Flag that enforces a complete decoder reset.
179  *
180  * \return  Error code.
181  */
182 SBR_ERROR sbrDecoder_InitElement (
183         HANDLE_SBRDECODER       self,
184         const int               sampleRateIn,
185         const int               sampleRateOut,
186         const int               samplesPerFrame,
187         const AUDIO_OBJECT_TYPE coreCodec,
188         const MP4_ELEMENT_ID    elementID,
189         const int               elementIndex
190         );
191 
192 /**
193  * \brief pass out of band SBR header to SBR decoder
194  *
195  * \param self         Handle to a SBR decoder instance.
196  * \param hBs          bit stream handle data source.
197  * \param elementID    SBR element ID.
198  * \param elementIndex SBR element index.
199  *
200  * \return  Error code.
201  */
202 INT sbrDecoder_Header (
203         HANDLE_SBRDECODER       self,
204         HANDLE_FDK_BITSTREAM    hBs,
205         const INT sampleRateIn,
206         const INT sampleRateOut,
207         const INT samplesPerFrame,
208         const AUDIO_OBJECT_TYPE coreCodec,
209         const MP4_ELEMENT_ID    elementID,
210         const INT               elementIndex
211         );
212 
213 /**
214  * \brief        Set a parameter of the SBR decoder runtime instance.
215  * \param self   SBR decoder handle.
216  * \param param  Parameter which will be set if successfull.
217  * \param value  New parameter value.
218  * \return       Error code.
219  */
220 SBR_ERROR sbrDecoder_SetParam ( HANDLE_SBRDECODER   self,
221                                 const SBRDEC_PARAM  param,
222                                 const INT           value );
223 
224 /**
225  * \brief  Feed DRC channel data into a SBR decoder runtime instance.
226  *
227  * \param self                    SBR decoder handle.
228  * \param ch                      Channel number to which the DRC data is associated to.
229  * \param numBands                Number of DRC bands.
230  * \param pNextFact_mag           Pointer to a table with the DRC factor magnitudes.
231  * \param nextFact_exp            Exponent for all DRC factors.
232  * \param drcInterpolationScheme  DRC interpolation scheme.
233  * \param winSequence             Window sequence from core coder (eight short or one long window).
234  * \param pBandTop                Pointer to a table with the top borders for all DRC bands.
235  *
236  * \return  Error code.
237  */
238 SBR_ERROR sbrDecoder_drcFeedChannel ( HANDLE_SBRDECODER  self,
239                                       INT                ch,
240                                       UINT               numBands,
241                                       FIXP_DBL          *pNextFact_mag,
242                                       INT                nextFact_exp,
243                                       SHORT              drcInterpolationScheme,
244                                       UCHAR              winSequence,
245                                       USHORT            *pBandTop );
246 
247 /**
248  * \brief  Disable SBR DRC for a certain channel.
249  *
250  * \param hSbrDecoder  SBR decoder handle.
251  * \param ch           Number of the channel that has to be disabled.
252  *
253  * \return  None.
254  */
255 void sbrDecoder_drcDisable ( HANDLE_SBRDECODER  self,
256                              INT                ch );
257 
258 
259 /**
260  * \brief  Parse one SBR element data extension data block. The bit stream position will
261  *         be placed at the end of the SBR payload block. The remaining bits will be returned
262  *         into *count if a payload length is given (byPayLen > 0). If no SBR payload length is
263  *         given (bsPayLen < 0) then the bit stream position on return will be random after this
264  *         function call in case of errors, and any further decoding will be completely pointless.
265  *
266  * \param self           SBR decoder handle.
267  * \param hBs            Bit stream handle as data source.
268  * \param count          Pointer to an integer where the amount of parsed SBR payload bits is stored into.
269  * \param bsPayLen       If > 0 this value is the SBR payload length. If < 0, the SBR payload length is unknown.
270  * \param flags          CRC flag (0: EXT_SBR_DATA; 1: EXT_SBR_DATA_CRC)
271  * \param prev_element   Previous MPEG-4 element ID.
272  * \param element_index  Index of the current element.
273  *
274  * \return  Error code.
275  */
276 SBR_ERROR sbrDecoder_Parse (
277         HANDLE_SBRDECODER  self,
278         HANDLE_FDK_BITSTREAM hBs,
279         int *count,
280         int  bsPayLen,
281         int  crcFlag,
282         MP4_ELEMENT_ID prev_element,
283         int element_index,
284         int fGlobalIndependencyFlag
285         );
286 
287 /**
288  * \brief  This function decodes the given SBR bitstreams and applies SBR to the given time data.
289  *
290  * SBR-processing works InPlace. I.e. the calling function has to provide
291  * a time domain buffer timeData which can hold the completely decoded
292  * result.
293  *
294  * Left and right channel are read and stored according to the
295  * interleaving flag, frame length and number of channels.
296  *
297  * \param self            Handle of an open SBR decoder instance.
298  * \param hSbrBs          SBR Bitstream handle.
299  * \param timeData        Pointer to input and finally upsampled output data.
300  * \param numChannels     Pointer to a buffer holding the number of channels in time data buffer.
301  * \param sampleRate      Output samplerate.
302  * \param channelMapping  Channel mapping indices.
303  * \param interleaved     Flag indicating if time data is stored interleaved (1: Interleaved time data, 0: non-interleaved timedata).
304  * \param coreDecodedOk   Flag indicating if the core decoder did not find any error (0: core decoder found errors, 1: no errors).
305  * \param psDecoded       Pointer to a buffer holding a flag. Input: PS is possible, Output: PS has been rendered.
306  *
307  * \return  Error code.
308  */
309 SBR_ERROR sbrDecoder_Apply ( HANDLE_SBRDECODER    self,
310                              INT_PCM             *timeData,
311                              int                 *numChannels,
312                              int                 *sampleRate,
313                              const UCHAR          channelMapping[(8)],
314                              const int            interleaved,
315                              const int            coreDecodedOk,
316                              UCHAR               *psDecoded );
317 
318 
319 /**
320  * \brief       Close SBR decoder instance and free memory.
321  * \param self  SBR decoder handle.
322  * \return      Error Code.
323  */
324 SBR_ERROR sbrDecoder_Close ( HANDLE_SBRDECODER *self );
325 
326 
327 /**
328  * \brief       Get SBR decoder library information.
329  * \param info  Pointer to a LIB_INFO struct, where library information is written to.
330  * \return      0 on success, -1 if invalid handle or if no free element is available to write information to.
331  */
332 INT sbrDecoder_GetLibInfo( LIB_INFO *info );
333 
334 /**
335  * \brief       Determine the modules output signal delay in samples.
336  * \param self  SBR decoder handle.
337  * \return      The number of samples signal delay added by the module.
338  */
339 UINT sbrDecoder_GetDelay( const HANDLE_SBRDECODER self );
340 
341 
342 #ifdef __cplusplus
343 }
344 #endif
345 
346 #endif
347