Coverage Report

Created: 2026-10-17 06:51

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/aac/libAACdec/src/ldfiltbank.cpp
Line
Count
Source
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
/**************************** AAC decoder library ******************************
96
97
   Author(s):
98
99
   Description: low delay filterbank
100
101
*******************************************************************************/
102
103
#include "ldfiltbank.h"
104
105
#include "aac_rom.h"
106
#include "dct.h"
107
#include "FDK_tools_rom.h"
108
#include "mdct.h"
109
110
450k
#define LDFB_HEADROOM 2
111
112
#if defined(__arm__)
113
#endif
114
115
static void multE2_DinvF_fdk(PCM_DEC *output, FIXP_DBL *x, const FIXP_WTB *fb,
116
225k
                             FIXP_DBL *z, const int N) {
117
225k
  int i;
118
119
  /*  scale for FIXP_DBL -> PCM_DEC conversion:       */
120
225k
  const int scale = (DFRACT_BITS - PCM_OUT_BITS) - LDFB_HEADROOM + (3);
121
122
#if ((DFRACT_BITS - PCM_OUT_BITS - LDFB_HEADROOM + (3) - 1) > 0)
123
  FIXP_DBL rnd_val_wts0 = (FIXP_DBL)0;
124
  FIXP_DBL rnd_val_wts1 = (FIXP_DBL)0;
125
#if ((DFRACT_BITS - PCM_OUT_BITS - LDFB_HEADROOM + (3) - WTS0 - 1) > 0)
126
  if (-WTS0 - 1 + scale)
127
    rnd_val_wts0 = (FIXP_DBL)(1 << (-WTS0 - 1 + scale - 1));
128
#endif
129
  if (-WTS1 - 1 + scale)
130
    rnd_val_wts1 = (FIXP_DBL)(1 << (-WTS1 - 1 + scale - 1));
131
#endif
132
133
26.4M
  for (i = 0; i < N / 4; i++) {
134
26.2M
    FIXP_DBL z0, z2, tmp;
135
136
26.2M
    z2 = x[N / 2 + i];
137
26.2M
    z0 = fAddSaturate(z2,
138
26.2M
                      (fMultDiv2(z[N / 2 + i], fb[2 * N + i]) >> (-WTS2 - 1)));
139
140
26.2M
    z[N / 2 + i] = fAddSaturate(
141
26.2M
        x[N / 2 - 1 - i],
142
26.2M
        (fMultDiv2(z[N + i], fb[2 * N + N / 2 + i]) >> (-WTS2 - 1)));
143
144
26.2M
    tmp = (fMultDiv2(z[N / 2 + i], fb[N + N / 2 - 1 - i]) +
145
26.2M
           fMultDiv2(z[i], fb[N + N / 2 + i]));
146
147
#if ((DFRACT_BITS - PCM_OUT_BITS - LDFB_HEADROOM + (3) - 1) > 0)
148
    FDK_ASSERT((-WTS1 - 1 + scale) >= 0);
149
    FDK_ASSERT(tmp <= ((FIXP_DBL)0x7FFFFFFF -
150
                       rnd_val_wts1)); /* rounding must not cause overflow */
151
    output[(N * 3 / 4 - 1 - i)] = (PCM_DEC)SATURATE_RIGHT_SHIFT(
152
        tmp + rnd_val_wts1, -WTS1 - 1 + scale, PCM_OUT_BITS);
153
#else
154
26.2M
    FDK_ASSERT((WTS1 + 1 - scale) >= 0);
155
26.2M
    output[(N * 3 / 4 - 1 - i)] =
156
26.2M
        (PCM_DEC)SATURATE_LEFT_SHIFT(tmp, WTS1 + 1 - scale, PCM_OUT_BITS);
157
26.2M
#endif
158
159
26.2M
    z[i] = z0;
160
26.2M
    z[N + i] = z2;
161
26.2M
  }
162
163
26.4M
  for (i = N / 4; i < N / 2; i++) {
164
26.2M
    FIXP_DBL z0, z2, tmp0, tmp1;
165
166
26.2M
    z2 = x[N / 2 + i];
167
26.2M
    z0 = fAddSaturate(z2,
168
26.2M
                      (fMultDiv2(z[N / 2 + i], fb[2 * N + i]) >> (-WTS2 - 1)));
169
170
26.2M
    z[N / 2 + i] = fAddSaturate(
171
26.2M
        x[N / 2 - 1 - i],
172
26.2M
        (fMultDiv2(z[N + i], fb[2 * N + N / 2 + i]) >> (-WTS2 - 1)));
173
174
26.2M
    tmp0 = (fMultDiv2(z[N / 2 + i], fb[N / 2 - 1 - i]) +
175
26.2M
            fMultDiv2(z[i], fb[N / 2 + i]));
176
26.2M
    tmp1 = (fMultDiv2(z[N / 2 + i], fb[N + N / 2 - 1 - i]) +
177
26.2M
            fMultDiv2(z[i], fb[N + N / 2 + i]));
178
179
#if ((DFRACT_BITS - PCM_OUT_BITS - LDFB_HEADROOM + (3) - 1) > 0)
180
    FDK_ASSERT((-WTS0 - 1 + scale) >= 0);
181
    FDK_ASSERT(tmp0 <= ((FIXP_DBL)0x7FFFFFFF -
182
                        rnd_val_wts0)); /* rounding must not cause overflow */
183
    FDK_ASSERT(tmp1 <= ((FIXP_DBL)0x7FFFFFFF -
184
                        rnd_val_wts1)); /* rounding must not cause overflow */
185
    output[(i - N / 4)] = (PCM_DEC)SATURATE_RIGHT_SHIFT(
186
        tmp0 + rnd_val_wts0, -WTS0 - 1 + scale, PCM_OUT_BITS);
187
    output[(N * 3 / 4 - 1 - i)] = (PCM_DEC)SATURATE_RIGHT_SHIFT(
188
        tmp1 + rnd_val_wts1, -WTS1 - 1 + scale, PCM_OUT_BITS);
189
#else
190
26.2M
    FDK_ASSERT((WTS0 + 1 - scale) >= 0);
191
26.2M
    output[(i - N / 4)] =
192
26.2M
        (PCM_DEC)SATURATE_LEFT_SHIFT(tmp0, WTS0 + 1 - scale, PCM_OUT_BITS);
193
26.2M
    output[(N * 3 / 4 - 1 - i)] =
194
26.2M
        (PCM_DEC)SATURATE_LEFT_SHIFT(tmp1, WTS1 + 1 - scale, PCM_OUT_BITS);
195
26.2M
#endif
196
26.2M
    z[i] = z0;
197
26.2M
    z[N + i] = z2;
198
26.2M
  }
199
200
  /* Exchange quarter parts of x to bring them in the "right" order */
201
26.4M
  for (i = 0; i < N / 4; i++) {
202
26.2M
    FIXP_DBL tmp0 = fMultDiv2(z[i], fb[N / 2 + i]);
203
204
#if ((DFRACT_BITS - PCM_OUT_BITS - LDFB_HEADROOM + (3) - 1) > 0)
205
    FDK_ASSERT((-WTS0 - 1 + scale) >= 0);
206
    FDK_ASSERT(tmp0 <= ((FIXP_DBL)0x7FFFFFFF -
207
                        rnd_val_wts0)); /* rounding must not cause overflow */
208
    output[(N * 3 / 4 + i)] = (PCM_DEC)SATURATE_RIGHT_SHIFT(
209
        tmp0 + rnd_val_wts0, -WTS0 - 1 + scale, PCM_OUT_BITS);
210
#else
211
26.2M
    FDK_ASSERT((WTS0 + 1 - scale) >= 0);
212
26.2M
    output[(N * 3 / 4 + i)] =
213
26.2M
        (PCM_DEC)SATURATE_LEFT_SHIFT(tmp0, WTS0 + 1 - scale, PCM_OUT_BITS);
214
26.2M
#endif
215
26.2M
  }
216
225k
}
217
218
int InvMdctTransformLowDelay_fdk(FIXP_DBL *mdctData, const int mdctData_e,
219
                                 PCM_DEC *output, FIXP_DBL *fs_buffer,
220
225k
                                 const int N) {
221
225k
  const FIXP_WTB *coef;
222
225k
  FIXP_DBL gain = (FIXP_DBL)0;
223
225k
  int scale = mdctData_e + MDCT_OUT_HEADROOM -
224
225k
              LDFB_HEADROOM; /* The LDFB_HEADROOM is compensated inside
225
                                multE2_DinvF_fdk() below */
226
225k
  int i;
227
228
  /* Select LD window slope */
229
225k
  switch (N) {
230
10.2k
    case 256:
231
10.2k
      coef = LowDelaySynthesis256;
232
10.2k
      break;
233
7.05k
    case 240:
234
7.05k
      coef = LowDelaySynthesis240;
235
7.05k
      break;
236
161
    case 160:
237
161
      coef = LowDelaySynthesis160;
238
161
      break;
239
936
    case 128:
240
936
      coef = LowDelaySynthesis128;
241
936
      break;
242
2.22k
    case 120:
243
2.22k
      coef = LowDelaySynthesis120;
244
2.22k
      break;
245
63.8k
    case 512:
246
63.8k
      coef = LowDelaySynthesis512;
247
63.8k
      break;
248
140k
    case 480:
249
140k
    default:
250
140k
      coef = LowDelaySynthesis480;
251
140k
      break;
252
225k
  }
253
254
  /*
255
     Apply exponent and 1/N factor.
256
     Note: "scale" is off by one because for LD_MDCT the window length is twice
257
     the window length of a regular MDCT. This is corrected inside
258
     multE2_DinvF_fdk(). Refer to ISO/IEC 14496-3:2009 page 277,
259
     chapter 4.6.20.2 "Low Delay Window".
260
   */
261
225k
  imdct_gain(&gain, &scale, N);
262
263
225k
  dct_IV(mdctData, N, &scale);
264
265
225k
  if (N == 256 || N == 240 || N == 160) {
266
17.4k
    scale -= 1;
267
207k
  } else if (N == 128 || N == 120) {
268
3.16k
    scale -= 2;
269
3.16k
  }
270
271
225k
  if (gain != (FIXP_DBL)0) {
272
69.6M
    for (i = 0; i < N; i++) {
273
69.4M
      mdctData[i] = fMult(mdctData[i], gain);
274
69.4M
    }
275
150k
  }
276
225k
  scaleValuesSaturate(mdctData, N, scale);
277
278
  /* Since all exponent and factors have been applied, current exponent is zero.
279
   */
280
225k
  multE2_DinvF_fdk(output, mdctData, coef, fs_buffer, N);
281
282
225k
  return (1);
283
225k
}