• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* -----------------------------------------------------------------------------
2 Software License for The Fraunhofer FDK AAC Codec Library for Android
3 
4 © Copyright  1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
5 Forschung e.V. All rights reserved.
6 
7  1.    INTRODUCTION
8 The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
9 that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
10 scheme for digital audio. This FDK AAC Codec software is intended to be used on
11 a wide variety of Android devices.
12 
13 AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
14 general perceptual audio codecs. AAC-ELD is considered the best-performing
15 full-bandwidth communications codec by independent studies and is widely
16 deployed. AAC has been standardized by ISO and IEC as part of the MPEG
17 specifications.
18 
19 Patent licenses for necessary patent claims for the FDK AAC Codec (including
20 those of Fraunhofer) may be obtained through Via Licensing
21 (www.vialicensing.com) or through the respective patent owners individually for
22 the purpose of encoding or decoding bit streams in products that are compliant
23 with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
24 Android devices already license these patent claims through Via Licensing or
25 directly from the patent owners, and therefore FDK AAC Codec software may
26 already be covered under those patent licenses when it is used for those
27 licensed purposes only.
28 
29 Commercially-licensed AAC software libraries, including floating-point versions
30 with enhanced sound quality, are also available from Fraunhofer. Users are
31 encouraged to check the Fraunhofer website for additional applications
32 information and documentation.
33 
34 2.    COPYRIGHT LICENSE
35 
36 Redistribution and use in source and binary forms, with or without modification,
37 are permitted without payment of copyright license fees provided that you
38 satisfy the following conditions:
39 
40 You must retain the complete text of this software license in redistributions of
41 the FDK AAC Codec or your modifications thereto in source code form.
42 
43 You must retain the complete text of this software license in the documentation
44 and/or other materials provided with redistributions of the FDK AAC Codec or
45 your modifications thereto in binary form. You must make available free of
46 charge copies of the complete source code of the FDK AAC Codec and your
47 modifications thereto to recipients of copies in binary form.
48 
49 The name of Fraunhofer may not be used to endorse or promote products derived
50 from this library without prior written permission.
51 
52 You may not charge copyright license fees for anyone to use, copy or distribute
53 the FDK AAC Codec software or your modifications thereto.
54 
55 Your modified versions of the FDK AAC Codec must carry prominent notices stating
56 that you changed the software and the date of any change. For modified versions
57 of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
58 must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
59 AAC Codec Library for Android."
60 
61 3.    NO PATENT LICENSE
62 
63 NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
64 limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
65 Fraunhofer provides no warranty of patent non-infringement with respect to this
66 software.
67 
68 You may use this FDK AAC Codec software or modifications thereto only for
69 purposes that are authorized by appropriate patent licenses.
70 
71 4.    DISCLAIMER
72 
73 This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
74 holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
75 including but not limited to the implied warranties of merchantability and
76 fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
77 CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
78 or consequential damages, including but not limited to procurement of substitute
79 goods or services; loss of use, data, or profits, or business interruption,
80 however caused and on any theory of liability, whether in contract, strict
81 liability, or tort (including negligence), arising in any way out of the use of
82 this software, even if advised of the possibility of such damage.
83 
84 5.    CONTACT INFORMATION
85 
86 Fraunhofer Institute for Integrated Circuits IIS
87 Attention: Audio and Multimedia Departments - FDK AAC LL
88 Am Wolfsmantel 33
89 91058 Erlangen, Germany
90 
91 www.iis.fraunhofer.de/amm
92 amm-info@iis.fraunhofer.de
93 ----------------------------------------------------------------------------- */
94 
95 /**************************** SBR decoder library ******************************
96 
97    Author(s):
98 
99    Description:
100 
101 *******************************************************************************/
102 
103 /*!
104   \file
105   \brief  Sbr decoder
106 */
107 #ifndef PSDEC_H
108 #define PSDEC_H
109 
110 #include "sbrdecoder.h"
111 #include "FDK_hybrid.h"
112 
113 #include "FDK_decorrelate.h"
114 
115 /* This PS decoder implements the baseline version. So it always uses the     */
116 /* hybrid filter structure for 20 stereo bands and does not implemet IPD/OPD  */
117 /* synthesis. The baseline version has to support the complete PS bitstream   */
118 /* syntax. But IPD/OPD data is ignored and set to 0. If 34 stereo band config */
119 /* is used in the bitstream for IIS/ICC the decoded parameters are mapped to  */
120 /* 20 stereo bands.                                                           */
121 
122 #include "FDK_bitstream.h"
123 
124 #define SCAL_HEADROOM (2)
125 
126 #define PS_EXTENSION_SIZE_BITS (4)
127 #define PS_EXTENSION_ESC_COUNT_BITS (8)
128 
129 #define NO_QMF_CHANNELS (64)
130 #define MAX_NUM_COL (32)
131 
132 #define NO_QMF_BANDS_HYBRID20 (3)
133 #define NO_SUB_QMF_CHANNELS (12)
134 #define HYBRID_FILTER_DELAY (6)
135 
136 #define MAX_NO_PS_ENV (4 + 1) /* +1 needed for VAR_BORDER */
137 
138 #define NO_HI_RES_BINS (34)
139 #define NO_MID_RES_BINS (20)
140 #define NO_LOW_RES_BINS (10)
141 
142 #define NO_HI_RES_IID_BINS (NO_HI_RES_BINS)
143 #define NO_HI_RES_ICC_BINS (NO_HI_RES_BINS)
144 
145 #define NO_MID_RES_IID_BINS (NO_MID_RES_BINS)
146 #define NO_MID_RES_ICC_BINS (NO_MID_RES_BINS)
147 
148 #define NO_LOW_RES_IID_BINS (NO_LOW_RES_BINS)
149 #define NO_LOW_RES_ICC_BINS (NO_LOW_RES_BINS)
150 
151 #define SUBQMF_GROUPS (10)
152 #define QMF_GROUPS (12)
153 
154 //#define SUBQMF_GROUPS_HI_RES            ( 32 )
155 //#define QMF_GROUPS_HI_RES               ( 18 )
156 
157 #define NO_IID_GROUPS (SUBQMF_GROUPS + QMF_GROUPS)
158 //#define NO_IID_GROUPS_HI_RES            ( SUBQMF_GROUPS_HI_RES +
159 // QMF_GROUPS_HI_RES )
160 
161 #define NO_IID_STEPS (7)       /* 1 .. + 7 */
162 #define NO_IID_STEPS_FINE (15) /* 1 .. +15 */
163 #define NO_ICC_STEPS (8)       /* 0 .. + 7 */
164 
165 #define NO_IID_LEVELS (2 * NO_IID_STEPS + 1)           /* - 7 ..  + 7 */
166 #define NO_IID_LEVELS_FINE (2 * NO_IID_STEPS_FINE + 1) /* -15 ..  +15 */
167 #define NO_ICC_LEVELS (NO_ICC_STEPS)                   /*   0 ..  + 7 */
168 
169 #define FIXP_SQRT05 ((FIXP_DBL)0x5a827980) /* 1/SQRT2 */
170 
171 struct PS_DEC_COEFFICIENTS {
172   FIXP_DBL H11r[NO_IID_GROUPS]; /*!< coefficients of the sub-subband groups */
173   FIXP_DBL H12r[NO_IID_GROUPS]; /*!< coefficients of the sub-subband groups */
174   FIXP_DBL H21r[NO_IID_GROUPS]; /*!< coefficients of the sub-subband groups */
175   FIXP_DBL H22r[NO_IID_GROUPS]; /*!< coefficients of the sub-subband groups */
176 
177   FIXP_DBL
178   DeltaH11r[NO_IID_GROUPS]; /*!< coefficients of the sub-subband groups */
179   FIXP_DBL
180   DeltaH12r[NO_IID_GROUPS]; /*!< coefficients of the sub-subband groups */
181   FIXP_DBL
182   DeltaH21r[NO_IID_GROUPS]; /*!< coefficients of the sub-subband groups */
183   FIXP_DBL
184   DeltaH22r[NO_IID_GROUPS]; /*!< coefficients of the sub-subband groups */
185 
186   SCHAR
187   aaIidIndexMapped[MAX_NO_PS_ENV]
188                   [NO_HI_RES_IID_BINS]; /*!< The mapped IID index for all
189                                            envelopes and all IID bins */
190   SCHAR
191   aaIccIndexMapped[MAX_NO_PS_ENV]
192                   [NO_HI_RES_ICC_BINS]; /*!< The mapped ICC index for all
193                                            envelopes and all ICC bins */
194 };
195 
196 typedef enum { ppt_none = 0, ppt_mpeg = 1, ppt_drm = 2 } PS_PAYLOAD_TYPE;
197 
198 typedef struct {
199   UCHAR bPsHeaderValid; /*!< set if new header is available from bitstream */
200 
201   UCHAR bEnableIid; /*!< One bit denoting the presence of IID parameters */
202   UCHAR bEnableIcc; /*!< One bit denoting the presence of ICC parameters */
203   UCHAR bEnableExt; /*!< The PS extension layer is enabled using the enable_ext
204                        bit. If it is set to %1 the IPD and OPD parameters are
205                        sent. If it is disabled, i.e. %0, the extension layer is
206                        skipped.   */
207 
208   UCHAR
209   modeIid;       /*!< The configuration of IID parameters (number of bands and
210                       quantisation grid, iid_quant) is determined by iid_mode.   */
211   UCHAR modeIcc; /*!< The configuration of Inter-channel Coherence parameters
212                       (number of bands and quantisation grid) is determined by
213                       icc_mode. */
214 
215   UCHAR freqResIid; /*!< 0=low, 1=mid or 2=high frequency resolution for iid */
216   UCHAR freqResIcc; /*!< 0=low, 1=mid or 2=high frequency resolution for icc */
217 
218   UCHAR bFineIidQ; /*!< Use fine Iid quantisation. */
219 
220   UCHAR bFrameClass; /*!< The frame_class bit determines whether the parameter
221                           positions of the current frame are uniformly spaced
222                           accross the frame or they are defined using the
223                         positions described by border_position.
224                       */
225 
226   UCHAR noEnv; /*!< The number of envelopes per frame */
227   UCHAR aEnvStartStop[MAX_NO_PS_ENV + 1]; /*!< In case of variable parameter
228                                              spacing the parameter positions are
229                                              determined by border_position */
230 
231   SCHAR abIidDtFlag[MAX_NO_PS_ENV]; /*!< Deltacoding time/freq flag for IID, 0
232                                        => freq           */
233   SCHAR abIccDtFlag[MAX_NO_PS_ENV]; /*!< Deltacoding time/freq flag for ICC, 0
234                                        => freq           */
235 
236   SCHAR
237   aaIidIndex[MAX_NO_PS_ENV]
238             [NO_HI_RES_IID_BINS]; /*!< The IID index for all envelopes and
239                                      all IID bins        */
240   SCHAR
241   aaIccIndex[MAX_NO_PS_ENV]
242             [NO_HI_RES_ICC_BINS]; /*!< The ICC index for all envelopes and
243                                      all ICC bins        */
244 
245 } MPEG_PS_BS_DATA;
246 
247 struct PS_DEC {
248   SCHAR noSubSamples;
249   SCHAR noChannels;
250 
251   SCHAR procFrameBased; /*!< Helper to detected switching from frame based to
252                            slot based processing
253                          */
254 
255   PS_PAYLOAD_TYPE
256   bPsDataAvail[(1) + 1]; /*!< set if new data available from bitstream */
257   UCHAR psDecodedPrv;    /*!< set if PS has been processed in the last frame */
258 
259   /* helpers for frame delay line */
260   UCHAR bsLastSlot;  /*!< Index of last read slot.  */
261   UCHAR bsReadSlot;  /*!< Index of current read slot for additional delay.  */
262   UCHAR processSlot; /*!< Index of current slot for processing (need for add.
263                         delay).   */
264 
265   union { /* Bitstream data */
266     MPEG_PS_BS_DATA
267     mpeg; /*!< Struct containing all MPEG specific PS data from bitstream.
268            */
269   } bsData[(1) + 1];
270 
271   shouldBeUnion { /* Static data */
272     struct {
273       SCHAR aIidPrevFrameIndex[NO_HI_RES_IID_BINS]; /*!< The IID index for
274                                                        previous frame */
275       SCHAR aIccPrevFrameIndex[NO_HI_RES_ICC_BINS]; /*!< The ICC index for
276                                                        previous frame */
277       UCHAR
278       bPrevFrameFineIidQ;   /*!< The IID quantization of the previous frame */
279       UCHAR prevFreqResIid; /*!< Frequency resolution for IID of the previous
280                                frame            */
281       UCHAR prevFreqResIcc; /*!< Frequency resolution for ICC of the previous
282                                frame            */
283       UCHAR lastUsb; /*!< uppermost WMF delay band of last frame          */
284 
285       FIXP_DBL pHybridAnaStatesLFdmx
286           [2 * 13 * NO_QMF_BANDS_HYBRID20]; /*!< Memory used in hybrid analysis
287                                                  for filter states. */
288       FDK_ANA_HYB_FILTER hybridAnalysis;
289       FDK_SYN_HYB_FILTER hybridSynthesis[2];
290 
291       DECORR_DEC apDecor; /*!< Decorrelator instance. */
292       FIXP_DBL decorrBufferCplx[(2 * ((825) + (373)))];
293 
294       FIXP_DBL h11rPrev[NO_IID_GROUPS]; /*!< previous calculated h(xy)
295                                            coefficients */
296       FIXP_DBL h12rPrev[NO_IID_GROUPS]; /*!< previous calculated h(xy)
297                                            coefficients */
298       FIXP_DBL h21rPrev[NO_IID_GROUPS]; /*!< previous calculated h(xy)
299                                            coefficients */
300       FIXP_DBL h22rPrev[NO_IID_GROUPS]; /*!< previous calculated h(xy)
301                                            coefficients */
302 
303       PS_DEC_COEFFICIENTS
304       *pCoef; /*!< temporal coefficients are on reusable scratch memory */
305 
306     } mpeg;
307   }
308   specificTo;
309 };
310 
311 typedef struct PS_DEC *HANDLE_PS_DEC;
312 
313 int CreatePsDec(HANDLE_PS_DEC *h_PS_DEC, int aacSamplesPerFrame);
314 
315 int DeletePsDec(HANDLE_PS_DEC *h_PS_DEC);
316 
317 void PreparePsProcessing(HANDLE_PS_DEC h_ps_d,
318                          const FIXP_DBL *const *const rIntBufferLeft,
319                          const FIXP_DBL *const *const iIntBufferLeft,
320                          const int scaleFactorLowBand);
321 
322 void initSlotBasedRotation(HANDLE_PS_DEC h_ps_d, int env, int usb);
323 
324 void ApplyPsSlot(
325     HANDLE_PS_DEC h_ps_d,      /* parametric stereo decoder handle    */
326     FIXP_DBL **rIntBufferLeft, /* real values of left qmf timeslot    */
327     FIXP_DBL **iIntBufferLeft, /* imag values of left qmf timeslot    */
328     FIXP_DBL *rIntBufferRight, /* real values of right qmf timeslot   */
329     FIXP_DBL *iIntBufferRight, /* imag values of right qmf timeslot   */
330     const int scaleFactorLowBand_no_ov, const int scaleFactorLowBand,
331     const int scaleFactorHighBand, const int lsb, const int usb);
332 
333 #endif /* PSDEC_H */
334