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 /******************* Library for basic calculation routines ********************
96 
97    Author(s):   Markus Lohwasser
98 
99    Description: FDK Tools Decorrelator
100 
101 *******************************************************************************/
102 
103 #ifndef FDK_DECORRELATE_H
104 #define FDK_DECORRELATE_H
105 
106 #include "common_fix.h"
107 
108 #define FIXP_MPS FIXP_DBL
109 
110 #ifndef ARCH_PREFER_MULT_32x32
111 #define FIXP_DECORR FIXP_SGL
112 #define FX_DECORR2FX_DBL FX_SGL2FX_DBL
113 #define FX_DECORR2FX_SGL
114 #define FX_DBL2FX_DECORR FX_DBL2FX_SGL
115 #define FX_SGL2FX_DECORR
116 #define DECORR(a) (FX_DBL2FXCONST_SGL(a))
117 #define FL2FXCONST_DECORR FL2FXCONST_SGL
118 #else
119 #define FIXP_DECORR FIXP_DBL
120 #define FX_DECORR2FX_DBL
121 #define FX_DECORR2FX_SGL FX_DBL2FX_SGL
122 #define FX_DBL2FX_DECORR
123 #define FX_SGL2FX_DECORR FX_SGL2FX_DBL
124 #define DECORR(a) FIXP_DBL(a)
125 #define FL2FXCONST_DECORR FL2FXCONST_DBL
126 #endif
127 
128 /*--------------- enums -------------------------------*/
129 
130 /**
131  * Decorrelator types.
132  */
133 typedef enum {
134   DECORR_MPS,  /**< Decorrelator type used by MPS LP/HQ */
135   DECORR_PS,   /**< Decorrelator type used by HEAACv2 and MPS LP */
136   DECORR_USAC, /**< Decorrelator type used by USAC */
137   DECORR_LD    /**< Decorrelator type used by MPS Low Delay */
138 } FDK_DECORR_TYPE;
139 
140 /**
141  * Ducker types.
142  */
143 typedef enum {
144   DUCKER_AUTOMATIC, /**< FDKdecorrelateInit() chooses correct ducker type
145                        depending on provided parameters. */
146   DUCKER_MPS,       /**< Force ducker type to MPS. */
147   DUCKER_PS         /**< Force ducker type to PS. */
148 } FDK_DUCKER_TYPE;
149 
150 /**
151  * Reverb band types.
152  */
153 typedef enum {
154   NOT_EXIST, /**< Mark reverb band as non-existing (number of bands = 0). */
155   DELAY, /**< Reverb bands just contains delay elements and no allpass filters.
156           */
157   COMMON_REAL,  /**< Real filter coeffs, common filter coeffs within one reverb
158                    band */
159   COMMON_CPLX,  /**< Complex filter coeffs, common filter coeffs within one
160                    reverb band */
161   INDEP_CPLX,   /**< Complex filter coeffs, independent filter coeffs for each
162                    hybrid band */
163   INDEP_CPLX_PS /**< PS optimized implementation of general INDEP_CPLX type */
164 } REVBAND_FILT_TYPE;
165 
166 typedef struct DECORR_DEC *HANDLE_DECORR_DEC;
167 
168 typedef struct DUCKER_INSTANCE {
169   int hybridBands;
170   int parameterBands;
171   int partiallyComplex;
172   FDK_DUCKER_TYPE duckerType;
173 
174   const UCHAR *qs_next;
175   const UCHAR *mapProcBands2HybBands;
176   const UCHAR *mapHybBands2ProcBands;
177   /* interleaved     SmoothDirectNrg[] and SmoothReverbNrg[],
178      non-interleaved SmoothDirectNrg[] in case of parametric stereo */
179   FIXP_MPS SmoothDirRevNrg[2 * (28)];
180 
181   /*
182     parametric stereo
183   */
184   FIXP_MPS peakDecay[(28)];
185   FIXP_MPS peakDiff[(28)];
186   FIXP_DBL maxValDirectData;
187   FIXP_DBL maxValReverbData;
188   SCHAR scaleDirectNrg;
189   SCHAR scaleReverbNrg;
190   SCHAR scaleSmoothDirRevNrg;
191   SCHAR headroomSmoothDirRevNrg;
192 
193 } DUCKER_INSTANCE;
194 
195 typedef struct DECORR_FILTER_INSTANCE {
196   FIXP_MPS *stateCplx;
197   FIXP_DBL *DelayBufferCplx;
198 
199   const FIXP_DECORR *numeratorReal;
200   const FIXP_STP *coeffsPacked;
201   const FIXP_DECORR *denominatorReal;
202 } DECORR_FILTER_INSTANCE;
203 
204 typedef struct DECORR_DEC {
205   INT L_stateBufferCplx;
206   FIXP_DBL *stateBufferCplx;
207   INT L_delayBufferCplx;
208   FIXP_DBL *delayBufferCplx;
209 
210   const REVBAND_FILT_TYPE *REV_filtType;
211   const UCHAR *REV_bandOffset;
212   const UCHAR *REV_delay;
213   const SCHAR *REV_filterOrder;
214   INT reverbBandDelayBufferIndex[(4)];
215   UCHAR stateBufferOffset[(3)];
216 
217   DECORR_FILTER_INSTANCE Filter[(71)];
218   DUCKER_INSTANCE ducker;
219 
220   int numbins;
221   int partiallyComplex;
222 } DECORR_DEC;
223 
224 /**
225  * \brief  Create one instance of Decorrelator.
226  *
227  * \param hDecorrDec          A pointer to a decorrelator instance which was
228  * allocated externally.
229  * \param bufferCplx          Externally allocated buffer (allocate (2*( ( 825 )
230  * + ( 373 ) )) FIXP_DBL values).
231  * \param bufLen              Length of bufferCplx. Must be >= (2*( ( 825 ) + (
232  * 373 ) )).
233  *
234  * \return  0 on success.
235  */
236 INT FDKdecorrelateOpen(HANDLE_DECORR_DEC hDecorrDec, FIXP_DBL *bufferCplx,
237                        const INT bufLen);
238 
239 /**
240  * \brief  Initialize and configure Decorrelator instance.
241  *
242  * \param hDecorrDec          A Decorrelator handle.
243  * \param nrHybBands          Number of (hybrid) bands.
244  * \param decorrType          Decorrelator type to use.
245  * \param duckerType          Ducker type to use (in general use
246  * DUCKER_AUTOMATIC).
247  * \param decorrConfig        Depending on decorrType values of 0,1,2 are
248  * allowed.
249  * \param seed                Seed of decorrelator instance. Allowed maximum
250  * valued depends on decorrType.
251  * \param partiallyComplex    Low power or high quality processing 0: HQ, 1: LQ
252  * (only allowed for DECORR_MPS | DECORR_PS).
253  * \param useFractDelay       Indicate usage of fractional delay 0: off, 1: on
254  * (currently not supported).
255  * \param isLegacyPS          Indicate if DECORR_PS is used for HEAACv2 (for all
256  * other cases: isLegacyPS = 0). The purpose of this parameter is to select the
257  * correct number of param bands for the ducker.
258  * \param initStatesFlag      Indicates whether the states buffer has to be
259  * cleared.
260  *
261  * \return  0 on success.
262  */
263 INT FDKdecorrelateInit(HANDLE_DECORR_DEC hDecorrDec, const INT nrHybBands,
264                        const FDK_DECORR_TYPE decorrType,
265                        const FDK_DUCKER_TYPE duckerType, const INT decorrConfig,
266                        const INT seed, const INT partiallyComplex,
267                        const INT useFractDelay, const INT isLegacyPS,
268                        const INT initStatesFlag);
269 
270 /**
271  * \brief  Apply Decorrelator on input data.
272  *
273  * Function applies decorrelator and ducker inplace on hybrid input data.
274  * Modified hybrid data will be returned inplace.
275  *
276  * \param hDecorrDec          A decorrelator handle.
277  * \param dataRealIn          In (hybrid) data.
278  * \param dataImagIn          In (hybrid) data.
279  * \param dataRealOut         Out (hybrid) data (can be same as dataRealIn for
280  * in-place calculation).
281  * \param dataImagOut         Out (hybrid) data (can be same as dataImagIn for
282  * in-place calculation).
283  * \param startHybBand        Hybrid band to start with decorrelation.
284  *
285  * \return  0 on success.
286  */
287 INT FDKdecorrelateApply(HANDLE_DECORR_DEC hDecorrDec, FIXP_DBL *dataRealIn,
288                         FIXP_DBL *dataImagIn, FIXP_DBL *dataRealOut,
289                         FIXP_DBL *dataImagOut, const INT startHybBand);
290 
291 /**
292  * \brief  Destroy a Decorrelator instance.
293  *
294  * Deallocate whole memory of decorraltor and inside ducker.
295  *
296  * \param hDecorrDec  Pointer to a decoderrolator handle. Null initialized on
297  * return.
298  *
299  * \return  0 on success.
300  */
301 INT FDKdecorrelateClose(HANDLE_DECORR_DEC hDecorrDec);
302 
303 /**
304  * \brief  Get max value address of direct signal.
305  *
306  * Get max value address of direct signal needed for ducker energy calculation.
307  *
308  * \param hDecorrDec  Pointer to a decoderrolator handle.
309  *
310  * \return  address of max value
311  */
312 FIXP_DBL *getAddrDirectSignalMaxVal(HANDLE_DECORR_DEC hDecorrDec);
313 
314 #endif /* FDK_DECORRELATE_H */
315