1c55a96383497a772a307b346368133960b02ad03Eric Laurent
2c55a96383497a772a307b346368133960b02ad03Eric Laurent/* -----------------------------------------------------------------------------------------------------------
3c55a96383497a772a307b346368133960b02ad03Eric LaurentSoftware License for The Fraunhofer FDK AAC Codec Library for Android
4c55a96383497a772a307b346368133960b02ad03Eric Laurent
5c55a96383497a772a307b346368133960b02ad03Eric Laurent� Copyright  1995 - 2013 Fraunhofer-Gesellschaft zur F�rderung der angewandten Forschung e.V.
6c55a96383497a772a307b346368133960b02ad03Eric Laurent  All rights reserved.
7c55a96383497a772a307b346368133960b02ad03Eric Laurent
8c55a96383497a772a307b346368133960b02ad03Eric Laurent 1.    INTRODUCTION
9c55a96383497a772a307b346368133960b02ad03Eric LaurentThe Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software that implements
10c55a96383497a772a307b346368133960b02ad03Eric Laurentthe MPEG Advanced Audio Coding ("AAC") encoding and decoding scheme for digital audio.
11c55a96383497a772a307b346368133960b02ad03Eric LaurentThis FDK AAC Codec software is intended to be used on a wide variety of Android devices.
12c55a96383497a772a307b346368133960b02ad03Eric Laurent
13c55a96383497a772a307b346368133960b02ad03Eric LaurentAAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient general perceptual
14c55a96383497a772a307b346368133960b02ad03Eric Laurentaudio codecs. AAC-ELD is considered the best-performing full-bandwidth communications codec by
15c55a96383497a772a307b346368133960b02ad03Eric Laurentindependent studies and is widely deployed. AAC has been standardized by ISO and IEC as part
16c55a96383497a772a307b346368133960b02ad03Eric Laurentof the MPEG specifications.
17c55a96383497a772a307b346368133960b02ad03Eric Laurent
18c55a96383497a772a307b346368133960b02ad03Eric LaurentPatent licenses for necessary patent claims for the FDK AAC Codec (including those of Fraunhofer)
19c55a96383497a772a307b346368133960b02ad03Eric Laurentmay be obtained through Via Licensing (www.vialicensing.com) or through the respective patent owners
20c55a96383497a772a307b346368133960b02ad03Eric Laurentindividually for the purpose of encoding or decoding bit streams in products that are compliant with
21c55a96383497a772a307b346368133960b02ad03Eric Laurentthe ISO/IEC MPEG audio standards. Please note that most manufacturers of Android devices already license
22c55a96383497a772a307b346368133960b02ad03Eric Laurentthese patent claims through Via Licensing or directly from the patent owners, and therefore FDK AAC Codec
23c55a96383497a772a307b346368133960b02ad03Eric Laurentsoftware may already be covered under those patent licenses when it is used for those licensed purposes only.
24c55a96383497a772a307b346368133960b02ad03Eric Laurent
25c55a96383497a772a307b346368133960b02ad03Eric LaurentCommercially-licensed AAC software libraries, including floating-point versions with enhanced sound quality,
26c55a96383497a772a307b346368133960b02ad03Eric Laurentare also available from Fraunhofer. Users are encouraged to check the Fraunhofer website for additional
27c55a96383497a772a307b346368133960b02ad03Eric Laurentapplications information and documentation.
28c55a96383497a772a307b346368133960b02ad03Eric Laurent
29c55a96383497a772a307b346368133960b02ad03Eric Laurent2.    COPYRIGHT LICENSE
30c55a96383497a772a307b346368133960b02ad03Eric Laurent
31c55a96383497a772a307b346368133960b02ad03Eric LaurentRedistribution and use in source and binary forms, with or without modification, are permitted without
32c55a96383497a772a307b346368133960b02ad03Eric Laurentpayment of copyright license fees provided that you satisfy the following conditions:
33c55a96383497a772a307b346368133960b02ad03Eric Laurent
34c55a96383497a772a307b346368133960b02ad03Eric LaurentYou must retain the complete text of this software license in redistributions of the FDK AAC Codec or
35c55a96383497a772a307b346368133960b02ad03Eric Laurentyour modifications thereto in source code form.
36c55a96383497a772a307b346368133960b02ad03Eric Laurent
37c55a96383497a772a307b346368133960b02ad03Eric LaurentYou must retain the complete text of this software license in the documentation and/or other materials
38c55a96383497a772a307b346368133960b02ad03Eric Laurentprovided with redistributions of the FDK AAC Codec or your modifications thereto in binary form.
39c55a96383497a772a307b346368133960b02ad03Eric LaurentYou must make available free of charge copies of the complete source code of the FDK AAC Codec and your
40c55a96383497a772a307b346368133960b02ad03Eric Laurentmodifications thereto to recipients of copies in binary form.
41c55a96383497a772a307b346368133960b02ad03Eric Laurent
42c55a96383497a772a307b346368133960b02ad03Eric LaurentThe name of Fraunhofer may not be used to endorse or promote products derived from this library without
43c55a96383497a772a307b346368133960b02ad03Eric Laurentprior written permission.
44c55a96383497a772a307b346368133960b02ad03Eric Laurent
45c55a96383497a772a307b346368133960b02ad03Eric LaurentYou may not charge copyright license fees for anyone to use, copy or distribute the FDK AAC Codec
46c55a96383497a772a307b346368133960b02ad03Eric Laurentsoftware or your modifications thereto.
47c55a96383497a772a307b346368133960b02ad03Eric Laurent
48c55a96383497a772a307b346368133960b02ad03Eric LaurentYour modified versions of the FDK AAC Codec must carry prominent notices stating that you changed the software
49c55a96383497a772a307b346368133960b02ad03Eric Laurentand the date of any change. For modified versions of the FDK AAC Codec, the term
50c55a96383497a772a307b346368133960b02ad03Eric Laurent"Fraunhofer FDK AAC Codec Library for Android" must be replaced by the term
51c55a96383497a772a307b346368133960b02ad03Eric Laurent"Third-Party Modified Version of the Fraunhofer FDK AAC Codec Library for Android."
52c55a96383497a772a307b346368133960b02ad03Eric Laurent
53c55a96383497a772a307b346368133960b02ad03Eric Laurent3.    NO PATENT LICENSE
54c55a96383497a772a307b346368133960b02ad03Eric Laurent
55c55a96383497a772a307b346368133960b02ad03Eric LaurentNO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without limitation the patents of Fraunhofer,
56c55a96383497a772a307b346368133960b02ad03Eric LaurentARE GRANTED BY THIS SOFTWARE LICENSE. Fraunhofer provides no warranty of patent non-infringement with
57c55a96383497a772a307b346368133960b02ad03Eric Laurentrespect to this software.
58c55a96383497a772a307b346368133960b02ad03Eric Laurent
59c55a96383497a772a307b346368133960b02ad03Eric LaurentYou may use this FDK AAC Codec software or modifications thereto only for purposes that are authorized
60c55a96383497a772a307b346368133960b02ad03Eric Laurentby appropriate patent licenses.
61c55a96383497a772a307b346368133960b02ad03Eric Laurent
62c55a96383497a772a307b346368133960b02ad03Eric Laurent4.    DISCLAIMER
63c55a96383497a772a307b346368133960b02ad03Eric Laurent
64c55a96383497a772a307b346368133960b02ad03Eric LaurentThis FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright holders and contributors
65c55a96383497a772a307b346368133960b02ad03Eric Laurent"AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, including but not limited to the implied warranties
66c55a96383497a772a307b346368133960b02ad03Eric Laurentof merchantability and fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
67c55a96383497a772a307b346368133960b02ad03Eric LaurentCONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary, or consequential damages,
68c55a96383497a772a307b346368133960b02ad03Eric Laurentincluding but not limited to procurement of substitute goods or services; loss of use, data, or profits,
69c55a96383497a772a307b346368133960b02ad03Eric Laurentor business interruption, however caused and on any theory of liability, whether in contract, strict
70c55a96383497a772a307b346368133960b02ad03Eric Laurentliability, or tort (including negligence), arising in any way out of the use of this software, even if
71c55a96383497a772a307b346368133960b02ad03Eric Laurentadvised of the possibility of such damage.
72c55a96383497a772a307b346368133960b02ad03Eric Laurent
73c55a96383497a772a307b346368133960b02ad03Eric Laurent5.    CONTACT INFORMATION
74
75Fraunhofer Institute for Integrated Circuits IIS
76Attention: Audio and Multimedia Departments - FDK AAC LL
77Am Wolfsmantel 33
7891058 Erlangen, Germany
79
80www.iis.fraunhofer.de/amm
81amm-info@iis.fraunhofer.de
82----------------------------------------------------------------------------------------------------------- */
83
84/*****************************  MPEG-4 AAC Decoder  **************************
85
86   Author(s): Manuel Jander
87   Description: MPEG Transport data tables
88
89******************************************************************************/
90
91#ifndef __TP_DATA_H__
92#define __TP_DATA_H__
93
94#include "machine_type.h"
95#include "FDK_audio.h"
96#include "FDK_bitstream.h"
97
98/*
99 * Configuration
100 */
101#define TP_GA_ENABLE
102/* #define TP_CELP_ENABLE */
103/* #define TP_HVXC_ENABLE */
104/* #define TP_SLS_ENABLE */
105#define TP_ELD_ENABLE
106/* #define TP_USAC_ENABLE */
107/* #define TP_RSVD50_ENABLE */
108
109#if defined(TP_GA_ENABLE) || defined(TP_SLS_ENABLE)
110#define TP_PCE_ENABLE       /**< Enable full PCE support */
111#endif
112
113/**
114 * ProgramConfig struct.
115 */
116/* ISO/IEC 14496-3 4.4.1.1 Table 4.2 Program config element */
117#define PC_FSB_CHANNELS_MAX 16 /* Front/Side/Back channels */
118#define PC_LFE_CHANNELS_MAX 4
119#define PC_ASSOCDATA_MAX    8
120#define PC_CCEL_MAX         16 /* CC elements */
121#define PC_COMMENTLENGTH    256
122
123typedef struct
124{
125#ifdef TP_PCE_ENABLE
126  /* PCE bitstream elements: */
127  UCHAR ElementInstanceTag;
128  UCHAR Profile;
129  UCHAR SamplingFrequencyIndex;
130  UCHAR NumFrontChannelElements;
131  UCHAR NumSideChannelElements;
132  UCHAR NumBackChannelElements;
133  UCHAR NumLfeChannelElements;
134  UCHAR NumAssocDataElements;
135  UCHAR NumValidCcElements;
136
137  UCHAR MonoMixdownPresent;
138  UCHAR MonoMixdownElementNumber;
139
140  UCHAR StereoMixdownPresent;
141  UCHAR StereoMixdownElementNumber;
142
143  UCHAR MatrixMixdownIndexPresent;
144  UCHAR MatrixMixdownIndex;
145  UCHAR PseudoSurroundEnable;
146
147  UCHAR FrontElementIsCpe[PC_FSB_CHANNELS_MAX];
148  UCHAR FrontElementTagSelect[PC_FSB_CHANNELS_MAX];
149  UCHAR FrontElementHeightInfo[PC_FSB_CHANNELS_MAX];
150
151  UCHAR SideElementIsCpe[PC_FSB_CHANNELS_MAX];
152  UCHAR SideElementTagSelect[PC_FSB_CHANNELS_MAX];
153  UCHAR SideElementHeightInfo[PC_FSB_CHANNELS_MAX];
154
155  UCHAR BackElementIsCpe[PC_FSB_CHANNELS_MAX];
156  UCHAR BackElementTagSelect[PC_FSB_CHANNELS_MAX];
157  UCHAR BackElementHeightInfo[PC_FSB_CHANNELS_MAX];
158
159  UCHAR LfeElementTagSelect[PC_LFE_CHANNELS_MAX];
160
161  UCHAR AssocDataElementTagSelect[PC_ASSOCDATA_MAX];
162
163  UCHAR CcElementIsIndSw[PC_CCEL_MAX];
164  UCHAR ValidCcElementTagSelect[PC_CCEL_MAX];
165
166  UCHAR CommentFieldBytes;
167  UCHAR Comment[PC_COMMENTLENGTH];
168#endif /* TP_PCE_ENABLE */
169
170  /* Helper variables for administration: */
171  UCHAR isValid;               /*!< Flag showing if PCE has been read successfully. */
172  UCHAR NumChannels;           /*!< Amount of audio channels summing all channel elements including LFEs */
173  UCHAR NumEffectiveChannels;  /*!< Amount of audio channels summing only SCEs and CPEs */
174  UCHAR elCounter;
175
176} CProgramConfig;
177
178typedef enum {
179  ASCEXT_UNKOWN = -1,
180  ASCEXT_SBR    = 0x2b7,
181  ASCEXT_PS     = 0x548,
182  ASCEXT_MPS    = 0x76a,
183  ASCEXT_SAOC   = 0x7cb,
184  ASCEXT_LDMPS  = 0x7cc
185
186} TP_ASC_EXTENSION_ID;
187
188#ifdef TP_GA_ENABLE
189/**
190 * GaSpecificConfig struct
191 */
192typedef struct {
193  UINT m_frameLengthFlag ;
194  UINT m_dependsOnCoreCoder ;
195  UINT m_coreCoderDelay ;
196
197  UINT m_extensionFlag ;
198  UINT m_extensionFlag3 ;
199
200  UINT m_layer;
201  UINT m_numOfSubFrame;
202  UINT m_layerLength;
203
204} CSGaSpecificConfig;
205#endif /* TP_GA_ENABLE */
206
207
208
209
210#ifdef TP_ELD_ENABLE
211
212typedef enum {
213  ELDEXT_TERM  = 0x0,   /* Termination tag */
214  ELDEXT_SAOC  = 0x1,   /* SAOC config */
215  ELDEXT_LDSAC = 0x2    /* LD MPEG Surround config */
216  /* reserved */
217} ASC_ELD_EXT_TYPE;
218
219typedef struct {
220  UCHAR m_frameLengthFlag;
221
222  UCHAR m_sbrPresentFlag;
223  UCHAR m_useLdQmfTimeAlign;  /* Use LD-MPS QMF in SBR to achive time alignment */
224  UCHAR m_sbrSamplingRate;
225  UCHAR m_sbrCrcFlag;
226
227} CSEldSpecificConfig;
228#endif /* TP_ELD_ENABLE */
229
230
231
232
233/**
234 * Audio configuration struct, suitable for encoder and decoder configuration.
235 */
236typedef struct {
237
238  /* XYZ Specific Data */
239  union {
240#ifdef TP_GA_ENABLE
241    CSGaSpecificConfig    m_gaSpecificConfig;       /**< General audio specific configuration.         */
242#endif /* TP_GA_ENABLE */
243#ifdef TP_ELD_ENABLE
244    CSEldSpecificConfig   m_eldSpecificConfig;      /**< ELD specific configuration.                   */
245#endif /* TP_ELD_ENABLE */
246  } m_sc;
247
248  /* Common ASC parameters */
249#ifdef TP_PCE_ENABLE
250  CProgramConfig        m_progrConfigElement;     /**< Program configuration.                          */
251#endif /* TP_PCE_ENABLE */
252
253  AUDIO_OBJECT_TYPE     m_aot;                    /**< Audio Object Type.                              */
254  UINT                  m_samplingFrequency;      /**< Samplerate.                                     */
255  UINT                  m_samplesPerFrame;        /**< Amount of samples per frame.                    */
256  UINT                  m_directMapping;          /**< Document this please !!                         */
257
258  AUDIO_OBJECT_TYPE     m_extensionAudioObjectType;        /**< Audio object type                      */
259  UINT                  m_extensionSamplingFrequency;      /**< Samplerate                             */
260
261  SCHAR                 m_channelConfiguration;   /**< Channel configuration index                     */
262
263  SCHAR                 m_epConfig;               /**< Error protection index                           */
264  SCHAR                 m_vcb11Flag;              /**< aacSectionDataResilienceFlag                     */
265  SCHAR                 m_rvlcFlag;               /**< aacScalefactorDataResilienceFlag                 */
266  SCHAR                 m_hcrFlag;                /**< aacSpectralDataResilienceFlag                    */
267
268  SCHAR                 m_sbrPresentFlag;         /**< Flag indicating the presence of SBR data in the bitstream               */
269  SCHAR                 m_psPresentFlag;          /**< Flag indicating the presence of parametric stereo data in the bitstream */
270  UCHAR                 m_samplingFrequencyIndex; /**< Samplerate index                                 */
271  UCHAR                 m_extensionSamplingFrequencyIndex; /**< Samplerate index                        */
272  SCHAR                 m_extensionChannelConfiguration;   /**< Channel configuration index             */
273
274} CSAudioSpecificConfig;
275
276typedef INT (*cbUpdateConfig_t)(void*, const CSAudioSpecificConfig*);
277typedef INT (*cbSsc_t)(
278        void*, HANDLE_FDK_BITSTREAM,
279        const AUDIO_OBJECT_TYPE coreCodec,
280        const INT samplingFrequency,
281        const INT muxMode,
282        const INT configBytes
283        );
284typedef INT (*cbSbr_t)(
285        void *                  self,
286        HANDLE_FDK_BITSTREAM    hBs,
287        const INT sampleRateIn,
288        const INT sampleRateOut,
289        const INT samplesPerFrame,
290        const AUDIO_OBJECT_TYPE coreCodec,
291        const MP4_ELEMENT_ID    elementID,
292        const INT               elementIndex
293        );
294
295typedef struct  {
296  cbUpdateConfig_t cbUpdateConfig; /*!< Function pointer for Config change notify callback.  */
297  void *cbUpdateConfigData;        /*!< User data pointer for Config change notify callback. */
298  cbSsc_t cbSsc;                   /*!< Function pointer for SSC parser callback. */
299  void *cbSscData;                 /*!< User data pointer for SSC parser callback. */
300  cbSbr_t cbSbr;                   /*!< Function pointer for SBR header parser callback. */
301  void *cbSbrData;                 /*!< User data pointer for SBR header parser callback. */
302} CSTpCallBacks;
303
304static const UINT SamplingRateTable[] =
305{ 96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050, 16000, 12000, 11025, 8000, 7350, 0, 0,
306  0
307};
308
309static inline
310int getSamplingRateIndex( UINT samplingRate )
311{
312  UINT sf_index, tableSize=sizeof(SamplingRateTable)/sizeof(UINT);
313
314  for (sf_index=0; sf_index<tableSize; sf_index++) {
315    if( SamplingRateTable[sf_index] == samplingRate ) break;
316  }
317
318  if (sf_index>tableSize-1) {
319    return tableSize-1;
320  }
321
322  return sf_index;
323}
324
325/*
326 * Get Channel count from channel configuration
327 */
328static inline int getNumberOfTotalChannels(int channelConfig)
329{
330  switch (channelConfig) {
331  case 1: case 2: case 3:
332  case 4: case 5: case 6:
333    return channelConfig;
334  case 7: case 12: case 14:
335    return 8;
336  case 11:
337    return 7;
338  default:
339    return 0;
340  }
341}
342
343static inline
344int getNumberOfEffectiveChannels(const int channelConfig)
345{        /* index: 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 */
346  const int n[] = {0,1,2,3,4,5,5,7,0,0, 0, 6, 7, 0, 7, 0};
347  return n[channelConfig];
348}
349
350#endif /* __TP_DATA_H__ */
351