1
2/* -----------------------------------------------------------------------------------------------------------
3Software License for The Fraunhofer FDK AAC Codec Library for Android
4
5� Copyright  1995 - 2012 Fraunhofer-Gesellschaft zur F�rderung der angewandten Forschung e.V.
6  All rights reserved.
7
8 1.    INTRODUCTION
9The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software that implements
10the MPEG Advanced Audio Coding ("AAC") encoding and decoding scheme for digital audio.
11This FDK AAC Codec software is intended to be used on a wide variety of Android devices.
12
13AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient general perceptual
14audio codecs. AAC-ELD is considered the best-performing full-bandwidth communications codec by
15independent studies and is widely deployed. AAC has been standardized by ISO and IEC as part
16of the MPEG specifications.
17
18Patent licenses for necessary patent claims for the FDK AAC Codec (including those of Fraunhofer)
19may be obtained through Via Licensing (www.vialicensing.com) or through the respective patent owners
20individually for the purpose of encoding or decoding bit streams in products that are compliant with
21the ISO/IEC MPEG audio standards. Please note that most manufacturers of Android devices already license
22these patent claims through Via Licensing or directly from the patent owners, and therefore FDK AAC Codec
23software may already be covered under those patent licenses when it is used for those licensed purposes only.
24
25Commercially-licensed AAC software libraries, including floating-point versions with enhanced sound quality,
26are also available from Fraunhofer. Users are encouraged to check the Fraunhofer website for additional
27applications information and documentation.
28
292.    COPYRIGHT LICENSE
30
31Redistribution and use in source and binary forms, with or without modification, are permitted without
32payment of copyright license fees provided that you satisfy the following conditions:
33
34You must retain the complete text of this software license in redistributions of the FDK AAC Codec or
35your modifications thereto in source code form.
36
37You must retain the complete text of this software license in the documentation and/or other materials
38provided with redistributions of the FDK AAC Codec or your modifications thereto in binary form.
39You must make available free of charge copies of the complete source code of the FDK AAC Codec and your
40modifications thereto to recipients of copies in binary form.
41
42The name of Fraunhofer may not be used to endorse or promote products derived from this library without
43prior written permission.
44
45You may not charge copyright license fees for anyone to use, copy or distribute the FDK AAC Codec
46software or your modifications thereto.
47
48Your modified versions of the FDK AAC Codec must carry prominent notices stating that you changed the software
49and 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
533.    NO PATENT LICENSE
54
55NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without limitation the patents of Fraunhofer,
56ARE GRANTED BY THIS SOFTWARE LICENSE. Fraunhofer provides no warranty of patent non-infringement with
57respect to this software.
58
59You may use this FDK AAC Codec software or modifications thereto only for purposes that are authorized
60by appropriate patent licenses.
61
624.    DISCLAIMER
63
64This 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
66of merchantability and fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
67CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary, or consequential damages,
68including but not limited to procurement of substitute goods or services; loss of use, data, or profits,
69or business interruption, however caused and on any theory of liability, whether in contract, strict
70liability, or tort (including negligence), arising in any way out of the use of this software, even if
71advised of the possibility of such damage.
72
735.    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
150  UCHAR SideElementIsCpe[PC_FSB_CHANNELS_MAX];
151  UCHAR SideElementTagSelect[PC_FSB_CHANNELS_MAX];
152
153  UCHAR BackElementIsCpe[PC_FSB_CHANNELS_MAX];
154  UCHAR BackElementTagSelect[PC_FSB_CHANNELS_MAX];
155
156  UCHAR LfeElementTagSelect[PC_LFE_CHANNELS_MAX];
157
158  UCHAR AssocDataElementTagSelect[PC_ASSOCDATA_MAX];
159
160  UCHAR CcElementIsIndSw[PC_CCEL_MAX];
161  UCHAR ValidCcElementTagSelect[PC_CCEL_MAX];
162
163  UCHAR CommentFieldBytes;
164  UCHAR Comment[PC_COMMENTLENGTH];
165#endif /* TP_PCE_ENABLE */
166
167  /* Helper variables for administration: */
168  UCHAR isValid;               /*!< Flag showing if PCE has been read successfully. */
169  UCHAR NumChannels;           /*!< Amount of audio channels summing all channel elements including LFEs */
170  UCHAR NumEffectiveChannels;  /*!< Amount of audio channels summing only SCEs and CPEs */
171  UCHAR elCounter;
172
173} CProgramConfig;
174
175typedef enum {
176  ASCEXT_UNKOWN = -1,
177  ASCEXT_SBR    = 0x2b7,
178  ASCEXT_PS     = 0x548,
179  ASCEXT_MPS    = 0x76a,
180  ASCEXT_SAOC   = 0x7cb,
181  ASCEXT_LDMPS  = 0x7cc
182
183} TP_ASC_EXTENSION_ID;
184
185#ifdef TP_GA_ENABLE
186/**
187 * GaSpecificConfig struct
188 */
189typedef struct {
190  UINT m_frameLengthFlag ;
191  UINT m_dependsOnCoreCoder ;
192  UINT m_coreCoderDelay ;
193
194  UINT m_extensionFlag ;
195  UINT m_extensionFlag3 ;
196
197  UINT m_layer;
198  UINT m_numOfSubFrame;
199  UINT m_layerLength;
200
201} CSGaSpecificConfig;
202#endif /* TP_GA_ENABLE */
203
204
205
206
207#ifdef TP_ELD_ENABLE
208
209typedef enum {
210  ELDEXT_TERM  = 0x0,   /* Termination tag */
211  ELDEXT_SAOC  = 0x1,   /* SAOC config */
212  ELDEXT_LDSAC = 0x2    /* LD MPEG Surround config */
213  /* reserved */
214} ASC_ELD_EXT_TYPE;
215
216typedef struct {
217  UCHAR m_frameLengthFlag;
218
219  UCHAR m_sbrPresentFlag;
220  UCHAR m_useLdQmfTimeAlign;  /* Use LD-MPS QMF in SBR to achive time alignment */
221  UCHAR m_sbrSamplingRate;
222  UCHAR m_sbrCrcFlag;
223
224} CSEldSpecificConfig;
225#endif /* TP_ELD_ENABLE */
226
227
228
229
230/**
231 * Audio configuration struct, suitable for encoder and decoder configuration.
232 */
233typedef struct {
234
235  /* XYZ Specific Data */
236  union {
237#ifdef TP_GA_ENABLE
238    CSGaSpecificConfig    m_gaSpecificConfig;       /**< General audio specific configuration.         */
239#endif /* TP_GA_ENABLE */
240#ifdef TP_ELD_ENABLE
241    CSEldSpecificConfig   m_eldSpecificConfig;      /**< ELD specific configuration.                   */
242#endif /* TP_ELD_ENABLE */
243  } m_sc;
244
245  /* Common ASC parameters */
246#ifdef TP_PCE_ENABLE
247  CProgramConfig        m_progrConfigElement;     /**< Program configuration.                          */
248#endif /* TP_PCE_ENABLE */
249
250  AUDIO_OBJECT_TYPE     m_aot;                    /**< Audio Object Type.                              */
251  UINT                  m_samplingFrequency;      /**< Samplerate.                                     */
252  UINT                  m_samplesPerFrame;        /**< Amount of samples per frame.                    */
253  UINT                  m_directMapping;          /**< Document this please !!                         */
254
255  AUDIO_OBJECT_TYPE     m_extensionAudioObjectType;        /**< Audio object type                      */
256  UINT                  m_extensionSamplingFrequency;      /**< Samplerate                             */
257
258  SCHAR                 m_channelConfiguration;   /**< Channel configuration index                     */
259
260  SCHAR                 m_epConfig;               /**< Error protection index                           */
261  SCHAR                 m_vcb11Flag;              /**< aacSectionDataResilienceFlag                     */
262  SCHAR                 m_rvlcFlag;               /**< aacScalefactorDataResilienceFlag                 */
263  SCHAR                 m_hcrFlag;                /**< aacSpectralDataResilienceFlag                    */
264
265  SCHAR                 m_sbrPresentFlag;         /**< Flag indicating the presence of SBR data in the bitstream               */
266  SCHAR                 m_psPresentFlag;          /**< Flag indicating the presence of parametric stereo data in the bitstream */
267  UCHAR                 m_samplingFrequencyIndex; /**< Samplerate index                                 */
268  UCHAR                 m_extensionSamplingFrequencyIndex; /**< Samplerate index                        */
269  SCHAR                 m_extensionChannelConfiguration;   /**< Channel configuration index             */
270
271} CSAudioSpecificConfig;
272
273typedef INT (*cbUpdateConfig_t)(void*, const CSAudioSpecificConfig*);
274typedef INT (*cbSsc_t)(
275        void*, HANDLE_FDK_BITSTREAM,
276        const AUDIO_OBJECT_TYPE coreCodec,
277        const INT samplingFrequency,
278        const INT muxMode,
279        const INT configBytes
280        );
281typedef INT (*cbSbr_t)(
282        void *                  self,
283        HANDLE_FDK_BITSTREAM    hBs,
284        const INT sampleRateIn,
285        const INT sampleRateOut,
286        const INT samplesPerFrame,
287        const AUDIO_OBJECT_TYPE coreCodec,
288        const MP4_ELEMENT_ID    elementID,
289        const INT               elementIndex
290        );
291
292typedef struct  {
293  cbUpdateConfig_t cbUpdateConfig; /*!< Function pointer for Config change notify callback.  */
294  void *cbUpdateConfigData;        /*!< User data pointer for Config change notify callback. */
295  cbSsc_t cbSsc;                   /*!< Function pointer for SSC parser callback. */
296  void *cbSscData;                 /*!< User data pointer for SSC parser callback. */
297  cbSbr_t cbSbr;                   /*!< Function pointer for SBR header parser callback. */
298  void *cbSbrData;                 /*!< User data pointer for SBR header parser callback. */
299} CSTpCallBacks;
300
301static const UINT SamplingRateTable[] =
302{ 96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050, 16000, 12000, 11025, 8000, 7350, 0, 0,
303  0
304};
305
306static inline
307int getSamplingRateIndex( UINT samplingRate )
308{
309  UINT sf_index, tableSize=sizeof(SamplingRateTable)/sizeof(UINT);
310
311  for (sf_index=0; sf_index<tableSize; sf_index++) {
312    if( SamplingRateTable[sf_index] == samplingRate ) break;
313  }
314
315  if (sf_index>tableSize-1) {
316    return tableSize-1;
317  }
318
319  return sf_index;
320}
321
322/*
323 * Get Channel count from channel configuration
324 */
325static inline int getNumberOfTotalChannels(int channelConfig)
326{
327  if (channelConfig > 0 && channelConfig < 8)
328    return (channelConfig == 7)?8:channelConfig;
329  else
330    return 0;
331}
332
333static inline
334int getNumberOfEffectiveChannels(const int channelConfig)
335{
336  const int n[] = {0,1,2,3,4,5,5,7};
337  return n[channelConfig];
338}
339
340#endif /* __TP_DATA_H__ */
341