1 /* -----------------------------------------------------------------------------
2 Software License for The Fraunhofer FDK AAC Codec Library for Android
3 
4 © Copyright  1995 - 2019 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 /**************************** PCM utility library ******************************
96 
97    Author(s):   Matthias Neusinger
98 
99    Description: Hard limiter for clipping prevention
100 
101 *******************************************************************************/
102 
103 #ifndef LIMITER_H
104 #define LIMITER_H
105 
106 #include "common_fix.h"
107 #include "FDK_audio.h"
108 
109 #define TDL_ATTACK_DEFAULT_MS (15)  /* default attack  time in ms */
110 #define TDL_RELEASE_DEFAULT_MS (50) /* default release time in ms */
111 
112 #ifdef __cplusplus
113 extern "C" {
114 #endif
115 
116 struct TDLimiter {
117   unsigned int attack;
118   FIXP_DBL attackConst, releaseConst;
119   unsigned int attackMs, releaseMs, maxAttackMs;
120   FIXP_DBL threshold;
121   unsigned int channels, maxChannels;
122   UINT sampleRate, maxSampleRate;
123   FIXP_DBL cor, max;
124   FIXP_DBL* maxBuf;
125   FIXP_DBL* delayBuf;
126   unsigned int maxBufIdx, delayBufIdx;
127   FIXP_DBL smoothState0;
128   FIXP_DBL minGain;
129   INT scaling;
130 };
131 
132 typedef enum {
133   TDLIMIT_OK = 0,
134   TDLIMIT_UNKNOWN = -1,
135 
136   __error_codes_start = -100,
137 
138   TDLIMIT_INVALID_HANDLE,
139   TDLIMIT_INVALID_PARAMETER,
140 
141   __error_codes_end
142 } TDLIMITER_ERROR;
143 
144 struct TDLimiter;
145 typedef struct TDLimiter* TDLimiterPtr;
146 
147 #define PCM_LIM LONG
148 #define FIXP_DBL2PCM_LIM(x) (x)
149 #define PCM_LIM2FIXP_DBL(x) (x)
150 #define PCM_LIM_BITS 32
151 #define FIXP_PCM_LIM FIXP_DBL
152 
153 #define SAMPLE_BITS_LIM DFRACT_BITS
154 
155 /******************************************************************************
156  * pcmLimiter_Reset                                                            *
157  * limiter: limiter handle                                                     *
158  * returns: error code                                                         *
159  ******************************************************************************/
160 TDLIMITER_ERROR pcmLimiter_Reset(TDLimiterPtr limiter);
161 
162 /******************************************************************************
163  * pcmLimiter_Destroy                                                          *
164  * limiter: limiter handle                                                     *
165  * returns: error code                                                         *
166  ******************************************************************************/
167 TDLIMITER_ERROR pcmLimiter_Destroy(TDLimiterPtr limiter);
168 
169 /******************************************************************************
170  * pcmLimiter_GetDelay                                                         *
171  * limiter: limiter handle                                                     *
172  * returns: exact delay caused by the limiter in samples per channel           *
173  ******************************************************************************/
174 unsigned int pcmLimiter_GetDelay(TDLimiterPtr limiter);
175 
176 /******************************************************************************
177  * pcmLimiter_GetMaxGainReduction                                              *
178  * limiter: limiter handle                                                     *
179  * returns: maximum gain reduction in last processed block in dB               *
180  ******************************************************************************/
181 INT pcmLimiter_GetMaxGainReduction(TDLimiterPtr limiter);
182 
183 /******************************************************************************
184  * pcmLimiter_SetNChannels                                                     *
185  * limiter:   limiter handle                                                   *
186  * nChannels: number of channels ( <= maxChannels specified on create)         *
187  * returns:   error code                                                       *
188  ******************************************************************************/
189 TDLIMITER_ERROR pcmLimiter_SetNChannels(TDLimiterPtr limiter,
190                                         unsigned int nChannels);
191 
192 /******************************************************************************
193  * pcmLimiter_SetSampleRate                                                    *
194  * limiter:    limiter handle                                                  *
195  * sampleRate: sampling rate in Hz ( <= maxSampleRate specified on create)     *
196  * returns:    error code                                                      *
197  ******************************************************************************/
198 TDLIMITER_ERROR pcmLimiter_SetSampleRate(TDLimiterPtr limiter, UINT sampleRate);
199 
200 /******************************************************************************
201  * pcmLimiter_SetAttack                                                        *
202  * limiter:    limiter handle                                                  *
203  * attackMs:   attack time in ms ( <= maxAttackMs specified on create)         *
204  * returns:    error code                                                      *
205  ******************************************************************************/
206 TDLIMITER_ERROR pcmLimiter_SetAttack(TDLimiterPtr limiter,
207                                      unsigned int attackMs);
208 
209 /******************************************************************************
210  * pcmLimiter_SetRelease                                                       *
211  * limiter:    limiter handle                                                  *
212  * releaseMs:  release time in ms                                              *
213  * returns:    error code                                                      *
214  ******************************************************************************/
215 TDLIMITER_ERROR pcmLimiter_SetRelease(TDLimiterPtr limiter,
216                                       unsigned int releaseMs);
217 
218 /******************************************************************************
219  * pcmLimiter_GetLibInfo                                                       *
220  * info:       pointer to an allocated and initialized LIB_INFO structure      *
221  * returns:    error code                                                      *
222  ******************************************************************************/
223 TDLIMITER_ERROR pcmLimiter_GetLibInfo(LIB_INFO* info);
224 
225 #ifdef __cplusplus
226 }
227 #endif
228 
229 /******************************************************************************
230  * pcmLimiter_Create                                                           *
231  * maxAttackMs:   maximum and initial attack/lookahead time in milliseconds    *
232  * releaseMs:     release time in milliseconds (90% time constant)             *
233  * threshold:     limiting threshold                                           *
234  * maxChannels:   maximum and initial number of channels                       *
235  * maxSampleRate: maximum and initial sampling rate in Hz                      *
236  * returns:       limiter handle                                               *
237  ******************************************************************************/
238 TDLimiterPtr pcmLimiter_Create(unsigned int maxAttackMs, unsigned int releaseMs,
239                                FIXP_DBL threshold, unsigned int maxChannels,
240                                UINT maxSampleRate);
241 
242 /******************************************************************************
243  * pcmLimiter_SetThreshold                                                     *
244  * limiter:    limiter handle                                                  *
245  * threshold:  limiter threshold                                               *
246  * returns:    error code                                                      *
247  ******************************************************************************/
248 TDLIMITER_ERROR pcmLimiter_SetThreshold(TDLimiterPtr limiter,
249                                         FIXP_DBL threshold);
250 
251 /******************************************************************************
252  * pcmLimiter_Apply                                                            *
253  * limiter:        limiter handle                                              *
254  * samplesIn:      pointer to input buffer containing interleaved samples      *
255  * samplesOut:     pointer to output buffer containing interleaved samples     *
256  * pGainPerSample: pointer to gains for each sample                            *
257  * scaling:        scaling of output samples                                   *
258  * nSamples:       number of samples per channel                               *
259  * returns:    error code                                                      *
260  ******************************************************************************/
261 TDLIMITER_ERROR pcmLimiter_Apply(TDLimiterPtr limiter, PCM_LIM* samplesIn,
262                                  INT_PCM* samplesOut, FIXP_DBL* pGainPerSample,
263                                  const INT scaling, const UINT nSamples);
264 
265 #endif /* #ifndef LIMITER_H */
266