Coverage Report

Created: 2025-07-01 06:21

/src/aac/libSBRdec/src/transcendent.h
Line
Count
Source (jump to first uncovered line)
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  FDK Fixed Point Arithmetic Library Interface
106
*/
107
108
#ifndef TRANSCENDENT_H
109
#define TRANSCENDENT_H
110
111
#include "sbrdecoder.h"
112
#include "sbr_rom.h"
113
114
/************************************************************************/
115
/*!
116
  \brief   Get number of octaves between frequencies a and b
117
118
  The Result is scaled with 1/8.
119
  The valid range for a and b is 1 to LOG_DUALIS_TABLE_SIZE.
120
121
  \return   ld(a/b) / 8
122
*/
123
/************************************************************************/
124
static inline FIXP_SGL FDK_getNumOctavesDiv8(INT a, /*!< lower band */
125
                                             INT b) /*!< upper band */
126
0
{
127
0
  return ((SHORT)((LONG)(CalcLdInt(b) - CalcLdInt(a)) >> (FRACT_BITS - 3)));
128
0
}
Unexecuted instantiation: env_calc.cpp:FDK_getNumOctavesDiv8(int, int)
Unexecuted instantiation: env_dec.cpp:FDK_getNumOctavesDiv8(int, int)
Unexecuted instantiation: sbrdec_freq_sca.cpp:FDK_getNumOctavesDiv8(int, int)
Unexecuted instantiation: sbrdecoder.cpp:FDK_getNumOctavesDiv8(int, int)
129
130
/************************************************************************/
131
/*!
132
  \brief   Add two values given by mantissa and exponent.
133
134
  Mantissas are in fract format with values between 0 and 1. <br>
135
  The base for exponents is 2.  Example:  \f$  a = a\_m * 2^{a\_e}  \f$<br>
136
*/
137
/************************************************************************/
138
inline void FDK_add_MantExp(FIXP_SGL a_m, /*!< Mantissa of 1st operand a */
139
                            SCHAR a_e,    /*!< Exponent of 1st operand a */
140
                            FIXP_SGL b_m, /*!< Mantissa of 2nd operand b */
141
                            SCHAR b_e,    /*!< Exponent of 2nd operand b */
142
                            FIXP_SGL *ptrSum_m, /*!< Mantissa of result */
143
                            SCHAR *ptrSum_e)    /*!< Exponent of result */
144
0
{
145
0
  FIXP_DBL accu;
146
0
  int shift;
147
0
  int shiftAbs;
148
149
0
  FIXP_DBL shiftedMantissa;
150
0
  FIXP_DBL otherMantissa;
151
152
  /* Equalize exponents of the summands.
153
     For the smaller summand, the exponent is adapted and
154
     for compensation, the mantissa is shifted right. */
155
156
0
  shift = (int)(a_e - b_e);
157
158
0
  shiftAbs = (shift > 0) ? shift : -shift;
159
0
  shiftAbs = (shiftAbs < DFRACT_BITS - 1) ? shiftAbs : DFRACT_BITS - 1;
160
0
  shiftedMantissa = (shift > 0) ? (FX_SGL2FX_DBL(b_m) >> shiftAbs)
161
0
                                : (FX_SGL2FX_DBL(a_m) >> shiftAbs);
162
0
  otherMantissa = (shift > 0) ? FX_SGL2FX_DBL(a_m) : FX_SGL2FX_DBL(b_m);
163
0
  *ptrSum_e = (shift > 0) ? a_e : b_e;
164
165
0
  accu = (shiftedMantissa >> 1) + (otherMantissa >> 1);
166
  /* shift by 1 bit to avoid overflow */
167
168
0
  if ((accu >= (FL2FXCONST_DBL(0.5f) - (FIXP_DBL)1)) ||
169
0
      (accu <= FL2FXCONST_DBL(-0.5f)))
170
0
    *ptrSum_e += 1;
171
0
  else
172
0
    accu = (shiftedMantissa + otherMantissa);
173
174
0
  *ptrSum_m = FX_DBL2FX_SGL(accu);
175
0
}
176
177
inline void FDK_add_MantExp(FIXP_DBL a,       /*!< Mantissa of 1st operand a */
178
                            SCHAR a_e,        /*!< Exponent of 1st operand a */
179
                            FIXP_DBL b,       /*!< Mantissa of 2nd operand b */
180
                            SCHAR b_e,        /*!< Exponent of 2nd operand b */
181
                            FIXP_DBL *ptrSum, /*!< Mantissa of result */
182
                            SCHAR *ptrSum_e)  /*!< Exponent of result */
183
0
{
184
0
  FIXP_DBL accu;
185
0
  int shift;
186
0
  int shiftAbs;
187
188
0
  FIXP_DBL shiftedMantissa;
189
0
  FIXP_DBL otherMantissa;
190
191
  /* Equalize exponents of the summands.
192
     For the smaller summand, the exponent is adapted and
193
     for compensation, the mantissa is shifted right. */
194
195
0
  shift = (int)(a_e - b_e);
196
197
0
  shiftAbs = (shift > 0) ? shift : -shift;
198
0
  shiftAbs = (shiftAbs < DFRACT_BITS - 1) ? shiftAbs : DFRACT_BITS - 1;
199
0
  shiftedMantissa = (shift > 0) ? (b >> shiftAbs) : (a >> shiftAbs);
200
0
  otherMantissa = (shift > 0) ? a : b;
201
0
  *ptrSum_e = (shift > 0) ? a_e : b_e;
202
203
0
  accu = (shiftedMantissa >> 1) + (otherMantissa >> 1);
204
  /* shift by 1 bit to avoid overflow */
205
206
0
  if ((accu >= (FL2FXCONST_DBL(0.5f) - (FIXP_DBL)1)) ||
207
0
      (accu <= FL2FXCONST_DBL(-0.5f)))
208
0
    *ptrSum_e += 1;
209
0
  else
210
0
    accu = (shiftedMantissa + otherMantissa);
211
212
0
  *ptrSum = accu;
213
0
}
214
215
/************************************************************************/
216
/*!
217
  \brief   Divide two values given by mantissa and exponent.
218
219
  Mantissas are in fract format with values between 0 and 1. <br>
220
  The base for exponents is 2.  Example:  \f$  a = a\_m * 2^{a\_e}  \f$<br>
221
222
  For performance reasons, the division is based on a table lookup
223
  which limits accuracy.
224
*/
225
/************************************************************************/
226
static inline void FDK_divide_MantExp(
227
    FIXP_SGL a_m,          /*!< Mantissa of dividend a */
228
    SCHAR a_e,             /*!< Exponent of dividend a */
229
    FIXP_SGL b_m,          /*!< Mantissa of divisor b */
230
    SCHAR b_e,             /*!< Exponent of divisor b */
231
    FIXP_SGL *ptrResult_m, /*!< Mantissa of quotient a/b */
232
    SCHAR *ptrResult_e)    /*!< Exponent of quotient a/b */
233
234
0
{
235
0
  int preShift, postShift, index, shift;
236
0
  FIXP_DBL ratio_m;
237
0
  FIXP_SGL bInv_m = FL2FXCONST_SGL(0.0f);
238
239
0
  preShift = CntLeadingZeros(FX_SGL2FX_DBL(b_m));
240
241
  /*
242
    Shift b into the range from 0..INV_TABLE_SIZE-1,
243
244
    E.g. 10 bits must be skipped for INV_TABLE_BITS 8:
245
    - leave 8 bits as index for table
246
    - skip sign bit,
247
    - skip first bit of mantissa, because this is always the same (>0.5)
248
249
    We are dealing with energies, so we need not care
250
    about negative numbers
251
  */
252
253
  /*
254
    The first interval has half width so the lowest bit of the index is
255
    needed for a doubled resolution.
256
  */
257
0
  shift = (FRACT_BITS - 2 - INV_TABLE_BITS - preShift);
258
259
0
  index = (shift < 0) ? (LONG)b_m << (-shift) : (LONG)b_m >> shift;
260
261
  /* The index has INV_TABLE_BITS +1 valid bits here. Clear the other bits. */
262
0
  index &= (1 << (INV_TABLE_BITS + 1)) - 1;
263
264
  /* Remove offset of half an interval */
265
0
  index--;
266
267
  /* Now the lowest bit is shifted out */
268
0
  index = index >> 1;
269
270
  /* Fetch inversed mantissa from table: */
271
0
  bInv_m = (index < 0) ? bInv_m : FDK_sbrDecoder_invTable[index];
272
273
  /* Multiply a with the inverse of b: */
274
0
  ratio_m = (index < 0) ? FX_SGL2FX_DBL(a_m >> 1) : fMultDiv2(bInv_m, a_m);
275
276
0
  postShift = CntLeadingZeros(ratio_m) - 1;
277
278
0
  *ptrResult_m = FX_DBL2FX_SGL(ratio_m << postShift);
279
0
  *ptrResult_e = a_e - b_e + 1 + preShift - postShift;
280
0
}
Unexecuted instantiation: env_calc.cpp:FDK_divide_MantExp(short, signed char, short, signed char, short*, signed char*)
Unexecuted instantiation: env_dec.cpp:FDK_divide_MantExp(short, signed char, short, signed char, short*, signed char*)
Unexecuted instantiation: sbrdec_freq_sca.cpp:FDK_divide_MantExp(short, signed char, short, signed char, short*, signed char*)
Unexecuted instantiation: sbrdecoder.cpp:FDK_divide_MantExp(short, signed char, short, signed char, short*, signed char*)
281
282
static inline void FDK_divide_MantExp(
283
    FIXP_DBL a_m,          /*!< Mantissa of dividend a */
284
    SCHAR a_e,             /*!< Exponent of dividend a */
285
    FIXP_DBL b_m,          /*!< Mantissa of divisor b */
286
    SCHAR b_e,             /*!< Exponent of divisor b */
287
    FIXP_DBL *ptrResult_m, /*!< Mantissa of quotient a/b */
288
    SCHAR *ptrResult_e)    /*!< Exponent of quotient a/b */
289
290
0
{
291
0
  int preShift, postShift, index, shift;
292
0
  FIXP_DBL ratio_m;
293
0
  FIXP_SGL bInv_m = FL2FXCONST_SGL(0.0f);
294
295
0
  preShift = CntLeadingZeros(b_m);
296
297
  /*
298
    Shift b into the range from 0..INV_TABLE_SIZE-1,
299
300
    E.g. 10 bits must be skipped for INV_TABLE_BITS 8:
301
    - leave 8 bits as index for table
302
    - skip sign bit,
303
    - skip first bit of mantissa, because this is always the same (>0.5)
304
305
    We are dealing with energies, so we need not care
306
    about negative numbers
307
  */
308
309
  /*
310
    The first interval has half width so the lowest bit of the index is
311
    needed for a doubled resolution.
312
  */
313
0
  shift = (DFRACT_BITS - 2 - INV_TABLE_BITS - preShift);
314
315
0
  index = (shift < 0) ? (LONG)b_m << (-shift) : (LONG)b_m >> shift;
316
317
  /* The index has INV_TABLE_BITS +1 valid bits here. Clear the other bits. */
318
0
  index &= (1 << (INV_TABLE_BITS + 1)) - 1;
319
320
  /* Remove offset of half an interval */
321
0
  index--;
322
323
  /* Now the lowest bit is shifted out */
324
0
  index = index >> 1;
325
326
  /* Fetch inversed mantissa from table: */
327
0
  bInv_m = (index < 0) ? bInv_m : FDK_sbrDecoder_invTable[index];
328
329
  /* Multiply a with the inverse of b: */
330
0
  ratio_m = (index < 0) ? (a_m >> 1) : fMultDiv2(bInv_m, a_m);
331
332
0
  postShift = CntLeadingZeros(ratio_m) - 1;
333
334
0
  *ptrResult_m = ratio_m << postShift;
335
0
  *ptrResult_e = a_e - b_e + 1 + preShift - postShift;
336
0
}
Unexecuted instantiation: env_calc.cpp:FDK_divide_MantExp(int, signed char, int, signed char, int*, signed char*)
Unexecuted instantiation: env_dec.cpp:FDK_divide_MantExp(int, signed char, int, signed char, int*, signed char*)
Unexecuted instantiation: sbrdec_freq_sca.cpp:FDK_divide_MantExp(int, signed char, int, signed char, int*, signed char*)
Unexecuted instantiation: sbrdecoder.cpp:FDK_divide_MantExp(int, signed char, int, signed char, int*, signed char*)
337
338
/*!
339
  \brief   Calculate the squareroot of a number given by mantissa and exponent
340
341
  Mantissa is in fract format with values between 0 and 1. <br>
342
  The base for the exponent is 2.  Example:  \f$  a = a\_m * 2^{a\_e}  \f$<br>
343
  The operand is addressed via pointers and will be overwritten with the result.
344
345
  For performance reasons, the square root is based on a table lookup
346
  which limits accuracy.
347
*/
348
static inline void FDK_sqrt_MantExp(
349
    FIXP_DBL *mantissa, /*!< Pointer to mantissa */
350
0
    SCHAR *exponent, const SCHAR *destScale) {
351
0
  FIXP_DBL input_m = *mantissa;
352
0
  int input_e = (int)*exponent;
353
0
  FIXP_DBL result = FL2FXCONST_DBL(0.0f);
354
0
  int result_e = -FRACT_BITS;
355
356
  /* Call lookup square root, which does internally normalization. */
357
0
  result = sqrtFixp_lookup(input_m, &input_e);
358
0
  result_e = input_e;
359
360
  /* Write result */
361
0
  if (exponent == destScale) {
362
0
    *mantissa = result;
363
0
    *exponent = result_e;
364
0
  } else {
365
0
    int shift = result_e - *destScale;
366
0
    *mantissa = (shift >= 0) ? result << (INT)fixMin(DFRACT_BITS - 1, shift)
367
0
                             : result >> (INT)fixMin(DFRACT_BITS - 1, -shift);
368
0
    *exponent = *destScale;
369
0
  }
370
0
}
Unexecuted instantiation: env_calc.cpp:FDK_sqrt_MantExp(int*, signed char*, signed char const*)
Unexecuted instantiation: env_dec.cpp:FDK_sqrt_MantExp(int*, signed char*, signed char const*)
Unexecuted instantiation: sbrdec_freq_sca.cpp:FDK_sqrt_MantExp(int*, signed char*, signed char const*)
Unexecuted instantiation: sbrdecoder.cpp:FDK_sqrt_MantExp(int*, signed char*, signed char const*)
371
372
#endif