Coverage Report

Created: 2026-05-30 06:09

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/aac/libSBRdec/src/transcendent.h
Line
Count
Source
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
564k
{
127
564k
  return ((SHORT)((LONG)(CalcLdInt(b) - CalcLdInt(a)) >> (FRACT_BITS - 3)));
128
564k
}
Unexecuted instantiation: env_calc.cpp:FDK_getNumOctavesDiv8(int, int)
env_dec.cpp:FDK_getNumOctavesDiv8(int, int)
Line
Count
Source
126
54.1k
{
127
54.1k
  return ((SHORT)((LONG)(CalcLdInt(b) - CalcLdInt(a)) >> (FRACT_BITS - 3)));
128
54.1k
}
sbrdec_freq_sca.cpp:FDK_getNumOctavesDiv8(int, int)
Line
Count
Source
126
510k
{
127
510k
  return ((SHORT)((LONG)(CalcLdInt(b) - CalcLdInt(a)) >> (FRACT_BITS - 3)));
128
510k
}
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
373k
{
145
373k
  FIXP_DBL accu;
146
373k
  int shift;
147
373k
  int shiftAbs;
148
149
373k
  FIXP_DBL shiftedMantissa;
150
373k
  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
373k
  shift = (int)(a_e - b_e);
157
158
373k
  shiftAbs = (shift > 0) ? shift : -shift;
159
373k
  shiftAbs = (shiftAbs < DFRACT_BITS - 1) ? shiftAbs : DFRACT_BITS - 1;
160
373k
  shiftedMantissa = (shift > 0) ? (FX_SGL2FX_DBL(b_m) >> shiftAbs)
161
373k
                                : (FX_SGL2FX_DBL(a_m) >> shiftAbs);
162
373k
  otherMantissa = (shift > 0) ? FX_SGL2FX_DBL(a_m) : FX_SGL2FX_DBL(b_m);
163
373k
  *ptrSum_e = (shift > 0) ? a_e : b_e;
164
165
373k
  accu = (shiftedMantissa >> 1) + (otherMantissa >> 1);
166
  /* shift by 1 bit to avoid overflow */
167
168
373k
  if ((accu >= (FL2FXCONST_DBL(0.5f) - (FIXP_DBL)1)) ||
169
362k
      (accu <= FL2FXCONST_DBL(-0.5f)))
170
10.8k
    *ptrSum_e += 1;
171
362k
  else
172
362k
    accu = (shiftedMantissa + otherMantissa);
173
174
373k
  *ptrSum_m = FX_DBL2FX_SGL(accu);
175
373k
}
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
153M
{
184
153M
  FIXP_DBL accu;
185
153M
  int shift;
186
153M
  int shiftAbs;
187
188
153M
  FIXP_DBL shiftedMantissa;
189
153M
  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
153M
  shift = (int)(a_e - b_e);
196
197
153M
  shiftAbs = (shift > 0) ? shift : -shift;
198
153M
  shiftAbs = (shiftAbs < DFRACT_BITS - 1) ? shiftAbs : DFRACT_BITS - 1;
199
153M
  shiftedMantissa = (shift > 0) ? (b >> shiftAbs) : (a >> shiftAbs);
200
153M
  otherMantissa = (shift > 0) ? a : b;
201
153M
  *ptrSum_e = (shift > 0) ? a_e : b_e;
202
203
153M
  accu = (shiftedMantissa >> 1) + (otherMantissa >> 1);
204
  /* shift by 1 bit to avoid overflow */
205
206
153M
  if ((accu >= (FL2FXCONST_DBL(0.5f) - (FIXP_DBL)1)) ||
207
144M
      (accu <= FL2FXCONST_DBL(-0.5f)))
208
9.83M
    *ptrSum_e += 1;
209
144M
  else
210
144M
    accu = (shiftedMantissa + otherMantissa);
211
212
153M
  *ptrSum = accu;
213
153M
}
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
373k
{
235
373k
  int preShift, postShift, index, shift;
236
373k
  FIXP_DBL ratio_m;
237
373k
  FIXP_SGL bInv_m = FL2FXCONST_SGL(0.0f);
238
239
373k
  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
373k
  shift = (FRACT_BITS - 2 - INV_TABLE_BITS - preShift);
258
259
373k
  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
373k
  index &= (1 << (INV_TABLE_BITS + 1)) - 1;
263
264
  /* Remove offset of half an interval */
265
373k
  index--;
266
267
  /* Now the lowest bit is shifted out */
268
373k
  index = index >> 1;
269
270
  /* Fetch inversed mantissa from table: */
271
373k
  bInv_m = (index < 0) ? bInv_m : FDK_sbrDecoder_invTable[index];
272
273
  /* Multiply a with the inverse of b: */
274
373k
  ratio_m = (index < 0) ? FX_SGL2FX_DBL(a_m >> 1) : fMultDiv2(bInv_m, a_m);
275
276
373k
  postShift = CntLeadingZeros(ratio_m) - 1;
277
278
373k
  *ptrResult_m = FX_DBL2FX_SGL(ratio_m << postShift);
279
373k
  *ptrResult_e = a_e - b_e + 1 + preShift - postShift;
280
373k
}
Unexecuted instantiation: env_calc.cpp:FDK_divide_MantExp(short, signed char, short, signed char, short*, signed char*)
env_dec.cpp:FDK_divide_MantExp(short, signed char, short, signed char, short*, signed char*)
Line
Count
Source
234
373k
{
235
373k
  int preShift, postShift, index, shift;
236
373k
  FIXP_DBL ratio_m;
237
373k
  FIXP_SGL bInv_m = FL2FXCONST_SGL(0.0f);
238
239
373k
  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
373k
  shift = (FRACT_BITS - 2 - INV_TABLE_BITS - preShift);
258
259
373k
  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
373k
  index &= (1 << (INV_TABLE_BITS + 1)) - 1;
263
264
  /* Remove offset of half an interval */
265
373k
  index--;
266
267
  /* Now the lowest bit is shifted out */
268
373k
  index = index >> 1;
269
270
  /* Fetch inversed mantissa from table: */
271
373k
  bInv_m = (index < 0) ? bInv_m : FDK_sbrDecoder_invTable[index];
272
273
  /* Multiply a with the inverse of b: */
274
373k
  ratio_m = (index < 0) ? FX_SGL2FX_DBL(a_m >> 1) : fMultDiv2(bInv_m, a_m);
275
276
373k
  postShift = CntLeadingZeros(ratio_m) - 1;
277
278
373k
  *ptrResult_m = FX_DBL2FX_SGL(ratio_m << postShift);
279
373k
  *ptrResult_e = a_e - b_e + 1 + preShift - postShift;
280
373k
}
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
59.5M
{
291
59.5M
  int preShift, postShift, index, shift;
292
59.5M
  FIXP_DBL ratio_m;
293
59.5M
  FIXP_SGL bInv_m = FL2FXCONST_SGL(0.0f);
294
295
59.5M
  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
59.5M
  shift = (DFRACT_BITS - 2 - INV_TABLE_BITS - preShift);
314
315
59.5M
  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
59.5M
  index &= (1 << (INV_TABLE_BITS + 1)) - 1;
319
320
  /* Remove offset of half an interval */
321
59.5M
  index--;
322
323
  /* Now the lowest bit is shifted out */
324
59.5M
  index = index >> 1;
325
326
  /* Fetch inversed mantissa from table: */
327
59.5M
  bInv_m = (index < 0) ? bInv_m : FDK_sbrDecoder_invTable[index];
328
329
  /* Multiply a with the inverse of b: */
330
59.5M
  ratio_m = (index < 0) ? (a_m >> 1) : fMultDiv2(bInv_m, a_m);
331
332
59.5M
  postShift = CntLeadingZeros(ratio_m) - 1;
333
334
59.5M
  *ptrResult_m = ratio_m << postShift;
335
59.5M
  *ptrResult_e = a_e - b_e + 1 + preShift - postShift;
336
59.5M
}
env_calc.cpp:FDK_divide_MantExp(int, signed char, int, signed char, int*, signed char*)
Line
Count
Source
290
59.5M
{
291
59.5M
  int preShift, postShift, index, shift;
292
59.5M
  FIXP_DBL ratio_m;
293
59.5M
  FIXP_SGL bInv_m = FL2FXCONST_SGL(0.0f);
294
295
59.5M
  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
59.5M
  shift = (DFRACT_BITS - 2 - INV_TABLE_BITS - preShift);
314
315
59.5M
  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
59.5M
  index &= (1 << (INV_TABLE_BITS + 1)) - 1;
319
320
  /* Remove offset of half an interval */
321
59.5M
  index--;
322
323
  /* Now the lowest bit is shifted out */
324
59.5M
  index = index >> 1;
325
326
  /* Fetch inversed mantissa from table: */
327
59.5M
  bInv_m = (index < 0) ? bInv_m : FDK_sbrDecoder_invTable[index];
328
329
  /* Multiply a with the inverse of b: */
330
59.5M
  ratio_m = (index < 0) ? (a_m >> 1) : fMultDiv2(bInv_m, a_m);
331
332
59.5M
  postShift = CntLeadingZeros(ratio_m) - 1;
333
334
59.5M
  *ptrResult_m = ratio_m << postShift;
335
59.5M
  *ptrResult_e = a_e - b_e + 1 + preShift - postShift;
336
59.5M
}
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
115M
    SCHAR *exponent, const SCHAR *destScale) {
351
115M
  FIXP_DBL input_m = *mantissa;
352
115M
  int input_e = (int)*exponent;
353
115M
  FIXP_DBL result = FL2FXCONST_DBL(0.0f);
354
115M
  int result_e = -FRACT_BITS;
355
356
  /* Call lookup square root, which does internally normalization. */
357
115M
  result = sqrtFixp_lookup(input_m, &input_e);
358
115M
  result_e = input_e;
359
360
  /* Write result */
361
115M
  if (exponent == destScale) {
362
38.3M
    *mantissa = result;
363
38.3M
    *exponent = result_e;
364
76.6M
  } else {
365
76.6M
    int shift = result_e - *destScale;
366
76.6M
    *mantissa = (shift >= 0) ? result << (INT)fixMin(DFRACT_BITS - 1, shift)
367
76.6M
                             : result >> (INT)fixMin(DFRACT_BITS - 1, -shift);
368
76.6M
    *exponent = *destScale;
369
76.6M
  }
370
115M
}
env_calc.cpp:FDK_sqrt_MantExp(int*, signed char*, signed char const*)
Line
Count
Source
350
115M
    SCHAR *exponent, const SCHAR *destScale) {
351
115M
  FIXP_DBL input_m = *mantissa;
352
115M
  int input_e = (int)*exponent;
353
115M
  FIXP_DBL result = FL2FXCONST_DBL(0.0f);
354
115M
  int result_e = -FRACT_BITS;
355
356
  /* Call lookup square root, which does internally normalization. */
357
115M
  result = sqrtFixp_lookup(input_m, &input_e);
358
115M
  result_e = input_e;
359
360
  /* Write result */
361
115M
  if (exponent == destScale) {
362
38.3M
    *mantissa = result;
363
38.3M
    *exponent = result_e;
364
76.6M
  } else {
365
76.6M
    int shift = result_e - *destScale;
366
76.6M
    *mantissa = (shift >= 0) ? result << (INT)fixMin(DFRACT_BITS - 1, shift)
367
76.6M
                             : result >> (INT)fixMin(DFRACT_BITS - 1, -shift);
368
76.6M
    *exponent = *destScale;
369
76.6M
  }
370
115M
}
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