Coverage Report

Created: 2026-02-14 06:49

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/aac/libSBRdec/src/hbe.cpp
Line
Count
Source
1
/* -----------------------------------------------------------------------------
2
Software License for The Fraunhofer FDK AAC Codec Library for Android
3
4
© Copyright  1995 - 2021 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  Fast FFT routines prototypes
106
  \author Fabian Haussel
107
*/
108
109
#include "hbe.h"
110
#include "qmf.h"
111
#include "env_extr.h"
112
113
#define HBE_MAX_QMF_BANDS (40)
114
115
24.8M
#define HBE_MAX_OUT_SLOTS (11)
116
117
#define QMF_WIN_LEN                                                          \
118
30.3M
  (12 + 6 - 4 - 1) /* 6 subband slots extra delay to align with HQ - 4 slots \
119
                      to compensate for critical sampling delay - 1 slot to  \
120
                      align critical sampling exactly (w additional time     \
121
                      domain delay)*/
122
123
#ifndef PI
124
#define PI 3.14159265358979323846
125
#endif
126
127
static const int xProducts[MAX_STRETCH_HBE - 1] = {
128
    1, 1, 1}; /* Cross products on(1)/off(0) for T=2,3,4. */
129
static const int startSubband2kL[33] = {
130
    0, 0, 0, 0, 0, 0, 0,  2,  2,  2,  4,  4,  4,  4,  4,  6, 6,
131
    6, 8, 8, 8, 8, 8, 10, 10, 10, 12, 12, 12, 12, 12, 12, 12};
132
133
static const int pmin = 12;
134
135
static const FIXP_DBL hintReal_F[4][3] = {
136
    {FL2FXCONST_DBL(0.39840335f), FL2FXCONST_DBL(0.39840335f),
137
     FL2FXCONST_DBL(-0.39840335f)},
138
    {FL2FXCONST_DBL(0.39840335f), FL2FXCONST_DBL(-0.39840335f),
139
     FL2FXCONST_DBL(-0.39840335f)},
140
    {FL2FXCONST_DBL(-0.39840335f), FL2FXCONST_DBL(-0.39840335f),
141
     FL2FXCONST_DBL(0.39840335f)},
142
    {FL2FXCONST_DBL(-0.39840335f), FL2FXCONST_DBL(0.39840335f),
143
     FL2FXCONST_DBL(0.39840335f)}};
144
145
static const FIXP_DBL factors[4] = {
146
    FL2FXCONST_DBL(0.39840335f), FL2FXCONST_DBL(-0.39840335f),
147
    FL2FXCONST_DBL(-0.39840335f), FL2FXCONST_DBL(0.39840335f)};
148
149
#define PSCALE 32
150
151
static const FIXP_DBL p_F[128] = {FL2FXCONST_DBL(0.f / (PSCALE * 12.f)),
152
                                  FL2FXCONST_DBL(1.f / (PSCALE * 12.f)),
153
                                  FL2FXCONST_DBL(2.f / (PSCALE * 12.f)),
154
                                  FL2FXCONST_DBL(3.f / (PSCALE * 12.f)),
155
                                  FL2FXCONST_DBL(4.f / (PSCALE * 12.f)),
156
                                  FL2FXCONST_DBL(5.f / (PSCALE * 12.f)),
157
                                  FL2FXCONST_DBL(6.f / (PSCALE * 12.f)),
158
                                  FL2FXCONST_DBL(7.f / (PSCALE * 12.f)),
159
                                  FL2FXCONST_DBL(8.f / (PSCALE * 12.f)),
160
                                  FL2FXCONST_DBL(9.f / (PSCALE * 12.f)),
161
                                  FL2FXCONST_DBL(10.f / (PSCALE * 12.f)),
162
                                  FL2FXCONST_DBL(11.f / (PSCALE * 12.f)),
163
                                  FL2FXCONST_DBL(12.f / (PSCALE * 12.f)),
164
                                  FL2FXCONST_DBL(13.f / (PSCALE * 12.f)),
165
                                  FL2FXCONST_DBL(14.f / (PSCALE * 12.f)),
166
                                  FL2FXCONST_DBL(15.f / (PSCALE * 12.f)),
167
                                  FL2FXCONST_DBL(16.f / (PSCALE * 12.f)),
168
                                  FL2FXCONST_DBL(17.f / (PSCALE * 12.f)),
169
                                  FL2FXCONST_DBL(18.f / (PSCALE * 12.f)),
170
                                  FL2FXCONST_DBL(19.f / (PSCALE * 12.f)),
171
                                  FL2FXCONST_DBL(20.f / (PSCALE * 12.f)),
172
                                  FL2FXCONST_DBL(21.f / (PSCALE * 12.f)),
173
                                  FL2FXCONST_DBL(22.f / (PSCALE * 12.f)),
174
                                  FL2FXCONST_DBL(23.f / (PSCALE * 12.f)),
175
                                  FL2FXCONST_DBL(24.f / (PSCALE * 12.f)),
176
                                  FL2FXCONST_DBL(25.f / (PSCALE * 12.f)),
177
                                  FL2FXCONST_DBL(26.f / (PSCALE * 12.f)),
178
                                  FL2FXCONST_DBL(27.f / (PSCALE * 12.f)),
179
                                  FL2FXCONST_DBL(28.f / (PSCALE * 12.f)),
180
                                  FL2FXCONST_DBL(29.f / (PSCALE * 12.f)),
181
                                  FL2FXCONST_DBL(30.f / (PSCALE * 12.f)),
182
                                  FL2FXCONST_DBL(31.f / (PSCALE * 12.f)),
183
                                  FL2FXCONST_DBL(32.f / (PSCALE * 12.f)),
184
                                  FL2FXCONST_DBL(33.f / (PSCALE * 12.f)),
185
                                  FL2FXCONST_DBL(34.f / (PSCALE * 12.f)),
186
                                  FL2FXCONST_DBL(35.f / (PSCALE * 12.f)),
187
                                  FL2FXCONST_DBL(36.f / (PSCALE * 12.f)),
188
                                  FL2FXCONST_DBL(37.f / (PSCALE * 12.f)),
189
                                  FL2FXCONST_DBL(38.f / (PSCALE * 12.f)),
190
                                  FL2FXCONST_DBL(39.f / (PSCALE * 12.f)),
191
                                  FL2FXCONST_DBL(40.f / (PSCALE * 12.f)),
192
                                  FL2FXCONST_DBL(41.f / (PSCALE * 12.f)),
193
                                  FL2FXCONST_DBL(42.f / (PSCALE * 12.f)),
194
                                  FL2FXCONST_DBL(43.f / (PSCALE * 12.f)),
195
                                  FL2FXCONST_DBL(44.f / (PSCALE * 12.f)),
196
                                  FL2FXCONST_DBL(45.f / (PSCALE * 12.f)),
197
                                  FL2FXCONST_DBL(46.f / (PSCALE * 12.f)),
198
                                  FL2FXCONST_DBL(47.f / (PSCALE * 12.f)),
199
                                  FL2FXCONST_DBL(48.f / (PSCALE * 12.f)),
200
                                  FL2FXCONST_DBL(49.f / (PSCALE * 12.f)),
201
                                  FL2FXCONST_DBL(50.f / (PSCALE * 12.f)),
202
                                  FL2FXCONST_DBL(51.f / (PSCALE * 12.f)),
203
                                  FL2FXCONST_DBL(52.f / (PSCALE * 12.f)),
204
                                  FL2FXCONST_DBL(53.f / (PSCALE * 12.f)),
205
                                  FL2FXCONST_DBL(54.f / (PSCALE * 12.f)),
206
                                  FL2FXCONST_DBL(55.f / (PSCALE * 12.f)),
207
                                  FL2FXCONST_DBL(56.f / (PSCALE * 12.f)),
208
                                  FL2FXCONST_DBL(57.f / (PSCALE * 12.f)),
209
                                  FL2FXCONST_DBL(58.f / (PSCALE * 12.f)),
210
                                  FL2FXCONST_DBL(59.f / (PSCALE * 12.f)),
211
                                  FL2FXCONST_DBL(60.f / (PSCALE * 12.f)),
212
                                  FL2FXCONST_DBL(61.f / (PSCALE * 12.f)),
213
                                  FL2FXCONST_DBL(62.f / (PSCALE * 12.f)),
214
                                  FL2FXCONST_DBL(63.f / (PSCALE * 12.f)),
215
                                  FL2FXCONST_DBL(64.f / (PSCALE * 12.f)),
216
                                  FL2FXCONST_DBL(65.f / (PSCALE * 12.f)),
217
                                  FL2FXCONST_DBL(66.f / (PSCALE * 12.f)),
218
                                  FL2FXCONST_DBL(67.f / (PSCALE * 12.f)),
219
                                  FL2FXCONST_DBL(68.f / (PSCALE * 12.f)),
220
                                  FL2FXCONST_DBL(69.f / (PSCALE * 12.f)),
221
                                  FL2FXCONST_DBL(70.f / (PSCALE * 12.f)),
222
                                  FL2FXCONST_DBL(71.f / (PSCALE * 12.f)),
223
                                  FL2FXCONST_DBL(72.f / (PSCALE * 12.f)),
224
                                  FL2FXCONST_DBL(73.f / (PSCALE * 12.f)),
225
                                  FL2FXCONST_DBL(74.f / (PSCALE * 12.f)),
226
                                  FL2FXCONST_DBL(75.f / (PSCALE * 12.f)),
227
                                  FL2FXCONST_DBL(76.f / (PSCALE * 12.f)),
228
                                  FL2FXCONST_DBL(77.f / (PSCALE * 12.f)),
229
                                  FL2FXCONST_DBL(78.f / (PSCALE * 12.f)),
230
                                  FL2FXCONST_DBL(79.f / (PSCALE * 12.f)),
231
                                  FL2FXCONST_DBL(80.f / (PSCALE * 12.f)),
232
                                  FL2FXCONST_DBL(81.f / (PSCALE * 12.f)),
233
                                  FL2FXCONST_DBL(82.f / (PSCALE * 12.f)),
234
                                  FL2FXCONST_DBL(83.f / (PSCALE * 12.f)),
235
                                  FL2FXCONST_DBL(84.f / (PSCALE * 12.f)),
236
                                  FL2FXCONST_DBL(85.f / (PSCALE * 12.f)),
237
                                  FL2FXCONST_DBL(86.f / (PSCALE * 12.f)),
238
                                  FL2FXCONST_DBL(87.f / (PSCALE * 12.f)),
239
                                  FL2FXCONST_DBL(88.f / (PSCALE * 12.f)),
240
                                  FL2FXCONST_DBL(89.f / (PSCALE * 12.f)),
241
                                  FL2FXCONST_DBL(90.f / (PSCALE * 12.f)),
242
                                  FL2FXCONST_DBL(91.f / (PSCALE * 12.f)),
243
                                  FL2FXCONST_DBL(92.f / (PSCALE * 12.f)),
244
                                  FL2FXCONST_DBL(93.f / (PSCALE * 12.f)),
245
                                  FL2FXCONST_DBL(94.f / (PSCALE * 12.f)),
246
                                  FL2FXCONST_DBL(95.f / (PSCALE * 12.f)),
247
                                  FL2FXCONST_DBL(96.f / (PSCALE * 12.f)),
248
                                  FL2FXCONST_DBL(97.f / (PSCALE * 12.f)),
249
                                  FL2FXCONST_DBL(98.f / (PSCALE * 12.f)),
250
                                  FL2FXCONST_DBL(99.f / (PSCALE * 12.f)),
251
                                  FL2FXCONST_DBL(100.f / (PSCALE * 12.f)),
252
                                  FL2FXCONST_DBL(101.f / (PSCALE * 12.f)),
253
                                  FL2FXCONST_DBL(102.f / (PSCALE * 12.f)),
254
                                  FL2FXCONST_DBL(103.f / (PSCALE * 12.f)),
255
                                  FL2FXCONST_DBL(104.f / (PSCALE * 12.f)),
256
                                  FL2FXCONST_DBL(105.f / (PSCALE * 12.f)),
257
                                  FL2FXCONST_DBL(106.f / (PSCALE * 12.f)),
258
                                  FL2FXCONST_DBL(107.f / (PSCALE * 12.f)),
259
                                  FL2FXCONST_DBL(108.f / (PSCALE * 12.f)),
260
                                  FL2FXCONST_DBL(109.f / (PSCALE * 12.f)),
261
                                  FL2FXCONST_DBL(110.f / (PSCALE * 12.f)),
262
                                  FL2FXCONST_DBL(111.f / (PSCALE * 12.f)),
263
                                  FL2FXCONST_DBL(112.f / (PSCALE * 12.f)),
264
                                  FL2FXCONST_DBL(113.f / (PSCALE * 12.f)),
265
                                  FL2FXCONST_DBL(114.f / (PSCALE * 12.f)),
266
                                  FL2FXCONST_DBL(115.f / (PSCALE * 12.f)),
267
                                  FL2FXCONST_DBL(116.f / (PSCALE * 12.f)),
268
                                  FL2FXCONST_DBL(117.f / (PSCALE * 12.f)),
269
                                  FL2FXCONST_DBL(118.f / (PSCALE * 12.f)),
270
                                  FL2FXCONST_DBL(119.f / (PSCALE * 12.f)),
271
                                  FL2FXCONST_DBL(120.f / (PSCALE * 12.f)),
272
                                  FL2FXCONST_DBL(121.f / (PSCALE * 12.f)),
273
                                  FL2FXCONST_DBL(122.f / (PSCALE * 12.f)),
274
                                  FL2FXCONST_DBL(123.f / (PSCALE * 12.f)),
275
                                  FL2FXCONST_DBL(124.f / (PSCALE * 12.f)),
276
                                  FL2FXCONST_DBL(125.f / (PSCALE * 12.f)),
277
                                  FL2FXCONST_DBL(126.f / (PSCALE * 12.f)),
278
                                  FL2FXCONST_DBL(127.f / (PSCALE * 12.f))};
279
280
static const FIXP_DBL band_F[64] = {
281
    FL2FXCONST_DBL((0.f * 2.f + 1) / (PSCALE << 2)),
282
    FL2FXCONST_DBL((1.f * 2.f + 1) / (PSCALE << 2)),
283
    FL2FXCONST_DBL((2.f * 2.f + 1) / (PSCALE << 2)),
284
    FL2FXCONST_DBL((3.f * 2.f + 1) / (PSCALE << 2)),
285
    FL2FXCONST_DBL((4.f * 2.f + 1) / (PSCALE << 2)),
286
    FL2FXCONST_DBL((5.f * 2.f + 1) / (PSCALE << 2)),
287
    FL2FXCONST_DBL((6.f * 2.f + 1) / (PSCALE << 2)),
288
    FL2FXCONST_DBL((7.f * 2.f + 1) / (PSCALE << 2)),
289
    FL2FXCONST_DBL((8.f * 2.f + 1) / (PSCALE << 2)),
290
    FL2FXCONST_DBL((9.f * 2.f + 1) / (PSCALE << 2)),
291
    FL2FXCONST_DBL((10.f * 2.f + 1) / (PSCALE << 2)),
292
    FL2FXCONST_DBL((11.f * 2.f + 1) / (PSCALE << 2)),
293
    FL2FXCONST_DBL((12.f * 2.f + 1) / (PSCALE << 2)),
294
    FL2FXCONST_DBL((13.f * 2.f + 1) / (PSCALE << 2)),
295
    FL2FXCONST_DBL((14.f * 2.f + 1) / (PSCALE << 2)),
296
    FL2FXCONST_DBL((15.f * 2.f + 1) / (PSCALE << 2)),
297
    FL2FXCONST_DBL((16.f * 2.f + 1) / (PSCALE << 2)),
298
    FL2FXCONST_DBL((17.f * 2.f + 1) / (PSCALE << 2)),
299
    FL2FXCONST_DBL((18.f * 2.f + 1) / (PSCALE << 2)),
300
    FL2FXCONST_DBL((19.f * 2.f + 1) / (PSCALE << 2)),
301
    FL2FXCONST_DBL((20.f * 2.f + 1) / (PSCALE << 2)),
302
    FL2FXCONST_DBL((21.f * 2.f + 1) / (PSCALE << 2)),
303
    FL2FXCONST_DBL((22.f * 2.f + 1) / (PSCALE << 2)),
304
    FL2FXCONST_DBL((23.f * 2.f + 1) / (PSCALE << 2)),
305
    FL2FXCONST_DBL((24.f * 2.f + 1) / (PSCALE << 2)),
306
    FL2FXCONST_DBL((25.f * 2.f + 1) / (PSCALE << 2)),
307
    FL2FXCONST_DBL((26.f * 2.f + 1) / (PSCALE << 2)),
308
    FL2FXCONST_DBL((27.f * 2.f + 1) / (PSCALE << 2)),
309
    FL2FXCONST_DBL((28.f * 2.f + 1) / (PSCALE << 2)),
310
    FL2FXCONST_DBL((29.f * 2.f + 1) / (PSCALE << 2)),
311
    FL2FXCONST_DBL((30.f * 2.f + 1) / (PSCALE << 2)),
312
    FL2FXCONST_DBL((31.f * 2.f + 1) / (PSCALE << 2)),
313
    FL2FXCONST_DBL((32.f * 2.f + 1) / (PSCALE << 2)),
314
    FL2FXCONST_DBL((33.f * 2.f + 1) / (PSCALE << 2)),
315
    FL2FXCONST_DBL((34.f * 2.f + 1) / (PSCALE << 2)),
316
    FL2FXCONST_DBL((35.f * 2.f + 1) / (PSCALE << 2)),
317
    FL2FXCONST_DBL((36.f * 2.f + 1) / (PSCALE << 2)),
318
    FL2FXCONST_DBL((37.f * 2.f + 1) / (PSCALE << 2)),
319
    FL2FXCONST_DBL((38.f * 2.f + 1) / (PSCALE << 2)),
320
    FL2FXCONST_DBL((39.f * 2.f + 1) / (PSCALE << 2)),
321
    FL2FXCONST_DBL((40.f * 2.f + 1) / (PSCALE << 2)),
322
    FL2FXCONST_DBL((41.f * 2.f + 1) / (PSCALE << 2)),
323
    FL2FXCONST_DBL((42.f * 2.f + 1) / (PSCALE << 2)),
324
    FL2FXCONST_DBL((43.f * 2.f + 1) / (PSCALE << 2)),
325
    FL2FXCONST_DBL((44.f * 2.f + 1) / (PSCALE << 2)),
326
    FL2FXCONST_DBL((45.f * 2.f + 1) / (PSCALE << 2)),
327
    FL2FXCONST_DBL((46.f * 2.f + 1) / (PSCALE << 2)),
328
    FL2FXCONST_DBL((47.f * 2.f + 1) / (PSCALE << 2)),
329
    FL2FXCONST_DBL((48.f * 2.f + 1) / (PSCALE << 2)),
330
    FL2FXCONST_DBL((49.f * 2.f + 1) / (PSCALE << 2)),
331
    FL2FXCONST_DBL((50.f * 2.f + 1) / (PSCALE << 2)),
332
    FL2FXCONST_DBL((51.f * 2.f + 1) / (PSCALE << 2)),
333
    FL2FXCONST_DBL((52.f * 2.f + 1) / (PSCALE << 2)),
334
    FL2FXCONST_DBL((53.f * 2.f + 1) / (PSCALE << 2)),
335
    FL2FXCONST_DBL((54.f * 2.f + 1) / (PSCALE << 2)),
336
    FL2FXCONST_DBL((55.f * 2.f + 1) / (PSCALE << 2)),
337
    FL2FXCONST_DBL((56.f * 2.f + 1) / (PSCALE << 2)),
338
    FL2FXCONST_DBL((57.f * 2.f + 1) / (PSCALE << 2)),
339
    FL2FXCONST_DBL((58.f * 2.f + 1) / (PSCALE << 2)),
340
    FL2FXCONST_DBL((59.f * 2.f + 1) / (PSCALE << 2)),
341
    FL2FXCONST_DBL((60.f * 2.f + 1) / (PSCALE << 2)),
342
    FL2FXCONST_DBL((61.f * 2.f + 1) / (PSCALE << 2)),
343
    FL2FXCONST_DBL((62.f * 2.f + 1) / (PSCALE << 2)),
344
    FL2FXCONST_DBL((63.f * 2.f + 1) / (PSCALE << 2))};
345
346
static const FIXP_DBL tr_str[3] = {FL2FXCONST_DBL(1.f / 4.f),
347
                                   FL2FXCONST_DBL(2.f / 4.f),
348
                                   FL2FXCONST_DBL(3.f / 4.f)};
349
350
static const FIXP_DBL stretchfac[3] = {FL2FXCONST_DBL(1.f / 2.f),
351
                                       FL2FXCONST_DBL(1.f / 3.f),
352
                                       FL2FXCONST_DBL(1.f / 4.f)};
353
354
static const FIXP_DBL cos_F[64] = {
355
    26353028,   -79043208,   131685776,  -184244944,  236697216,  -289006912,
356
    341142496,  -393072608,  444773984,  -496191392,  547325824,  -598114752,
357
    648559104,  -698597248,  748230016,  -797411904,  846083200,  -894275136,
358
    941928192,  -989013760,  1035474624, -1081340672, 1126555136, -1171063296,
359
    1214893696, -1257992192, 1300332544, -1341889408, 1382612736, -1422503808,
360
    1461586944, -1499741440, 1537039104, -1573364864, 1608743808, -1643196672,
361
    1676617344, -1709028992, 1740450560, -1770784896, 1800089472, -1828273536,
362
    1855357440, -1881356288, 1906190080, -1929876608, 1952428928, -1973777664,
363
    1993962880, -2012922240, 2030670208, -2047216000, 2062508288, -2076559488,
364
    2089376128, -2100932224, 2111196800, -2120214784, 2127953792, -2134394368,
365
    2139565056, -2143444864, 2146026624, -2147321856};
366
367
static const FIXP_DBL twiddle[121] = {1073741824,
368
                                      1071442860,
369
                                      1064555814,
370
                                      1053110176,
371
                                      1037154959,
372
                                      1016758484,
373
                                      992008094,
374
                                      963009773,
375
                                      929887697,
376
                                      892783698,
377
                                      851856663,
378
                                      807281846,
379
                                      759250125,
380
                                      707967178,
381
                                      653652607,
382
                                      596538995,
383
                                      536870912,
384
                                      474903865,
385
                                      410903207,
386
                                      345142998,
387
                                      277904834,
388
                                      209476638,
389
                                      140151432,
390
                                      70226075,
391
                                      0,
392
                                      -70226075,
393
                                      -140151432,
394
                                      -209476638,
395
                                      -277904834,
396
                                      -345142998,
397
                                      -410903207,
398
                                      -474903865,
399
                                      -536870912,
400
                                      -596538995,
401
                                      -653652607,
402
                                      -707967178,
403
                                      -759250125,
404
                                      -807281846,
405
                                      -851856663,
406
                                      -892783698,
407
                                      -929887697,
408
                                      -963009773,
409
                                      -992008094,
410
                                      -1016758484,
411
                                      -1037154959,
412
                                      -1053110176,
413
                                      -1064555814,
414
                                      -1071442860,
415
                                      -1073741824,
416
                                      -1071442860,
417
                                      -1064555814,
418
                                      -1053110176,
419
                                      -1037154959,
420
                                      -1016758484,
421
                                      -992008094,
422
                                      -963009773,
423
                                      -929887697,
424
                                      -892783698,
425
                                      -851856663,
426
                                      -807281846,
427
                                      -759250125,
428
                                      -707967178,
429
                                      -653652607,
430
                                      -596538995,
431
                                      -536870912,
432
                                      -474903865,
433
                                      -410903207,
434
                                      -345142998,
435
                                      -277904834,
436
                                      -209476638,
437
                                      -140151432,
438
                                      -70226075,
439
                                      0,
440
                                      70226075,
441
                                      140151432,
442
                                      209476638,
443
                                      277904834,
444
                                      345142998,
445
                                      410903207,
446
                                      474903865,
447
                                      536870912,
448
                                      596538995,
449
                                      653652607,
450
                                      707967178,
451
                                      759250125,
452
                                      807281846,
453
                                      851856663,
454
                                      892783698,
455
                                      929887697,
456
                                      963009773,
457
                                      992008094,
458
                                      1016758484,
459
                                      1037154959,
460
                                      1053110176,
461
                                      1064555814,
462
                                      1071442860,
463
                                      1073741824,
464
                                      1071442860,
465
                                      1064555814,
466
                                      1053110176,
467
                                      1037154959,
468
                                      1016758484,
469
                                      992008094,
470
                                      963009773,
471
                                      929887697,
472
                                      892783698,
473
                                      851856663,
474
                                      807281846,
475
                                      759250125,
476
                                      707967178,
477
                                      653652607,
478
                                      596538995,
479
                                      536870912,
480
                                      474903865,
481
                                      410903207,
482
                                      345142998,
483
                                      277904834,
484
                                      209476638,
485
                                      140151432,
486
                                      70226075,
487
                                      0};
488
489
#if FIXP_QTW == FIXP_SGL
490
#define HTW(x) (x)
491
#else
492
#define HTW(x) FX_DBL2FX_QTW(FX_SGL2FX_DBL((const FIXP_SGL)x))
493
#endif
494
495
static const FIXP_QTW post_twiddle_cos_8[8] = {
496
    HTW(-1606),  HTW(4756),  HTW(-7723),  HTW(10394),
497
    HTW(-12665), HTW(14449), HTW(-15679), HTW(16305)};
498
499
static const FIXP_QTW post_twiddle_cos_16[16] = {
500
    HTW(-804),   HTW(2404),  HTW(-3981),  HTW(5520),  HTW(-7005),  HTW(8423),
501
    HTW(-9760),  HTW(11003), HTW(-12140), HTW(13160), HTW(-14053), HTW(14811),
502
    HTW(-15426), HTW(15893), HTW(-16207), HTW(16364)};
503
504
static const FIXP_QTW post_twiddle_cos_24[24] = {
505
    HTW(-536),   HTW(1606),  HTW(-2669),  HTW(3720),  HTW(-4756),  HTW(5771),
506
    HTW(-6762),  HTW(7723),  HTW(-8652),  HTW(9543),  HTW(-10394), HTW(11200),
507
    HTW(-11958), HTW(12665), HTW(-13318), HTW(13913), HTW(-14449), HTW(14924),
508
    HTW(-15334), HTW(15679), HTW(-15956), HTW(16165), HTW(-16305), HTW(16375)};
509
510
static const FIXP_QTW post_twiddle_cos_32[32] = {
511
    HTW(-402),   HTW(1205),  HTW(-2006),  HTW(2801),  HTW(-3590),  HTW(4370),
512
    HTW(-5139),  HTW(5897),  HTW(-6639),  HTW(7366),  HTW(-8076),  HTW(8765),
513
    HTW(-9434),  HTW(10080), HTW(-10702), HTW(11297), HTW(-11866), HTW(12406),
514
    HTW(-12916), HTW(13395), HTW(-13842), HTW(14256), HTW(-14635), HTW(14978),
515
    HTW(-15286), HTW(15557), HTW(-15791), HTW(15986), HTW(-16143), HTW(16261),
516
    HTW(-16340), HTW(16379)};
517
518
static const FIXP_QTW post_twiddle_cos_40[40] = {
519
    HTW(-322),   HTW(965),   HTW(-1606),  HTW(2245),  HTW(-2880),  HTW(3511),
520
    HTW(-4137),  HTW(4756),  HTW(-5368),  HTW(5971),  HTW(-6566),  HTW(7150),
521
    HTW(-7723),  HTW(8285),  HTW(-8833),  HTW(9368),  HTW(-9889),  HTW(10394),
522
    HTW(-10883), HTW(11356), HTW(-11810), HTW(12247), HTW(-12665), HTW(13063),
523
    HTW(-13441), HTW(13799), HTW(-14135), HTW(14449), HTW(-14741), HTW(15011),
524
    HTW(-15257), HTW(15480), HTW(-15679), HTW(15853), HTW(-16003), HTW(16129),
525
    HTW(-16229), HTW(16305), HTW(-16356), HTW(16381)};
526
527
static const FIXP_QTW post_twiddle_sin_8[8] = {
528
    HTW(16305), HTW(-15679), HTW(14449), HTW(-12665),
529
    HTW(10394), HTW(-7723),  HTW(4756),  HTW(-1606)};
530
531
static const FIXP_QTW post_twiddle_sin_16[16] = {
532
    HTW(16364), HTW(-16207), HTW(15893), HTW(-15426), HTW(14811), HTW(-14053),
533
    HTW(13160), HTW(-12140), HTW(11003), HTW(-9760),  HTW(8423),  HTW(-7005),
534
    HTW(5520),  HTW(-3981),  HTW(2404),  HTW(-804)};
535
536
static const FIXP_QTW post_twiddle_sin_24[24] = {
537
    HTW(16375), HTW(-16305), HTW(16165), HTW(-15956), HTW(15679), HTW(-15334),
538
    HTW(14924), HTW(-14449), HTW(13913), HTW(-13318), HTW(12665), HTW(-11958),
539
    HTW(11200), HTW(-10394), HTW(9543),  HTW(-8652),  HTW(7723),  HTW(-6762),
540
    HTW(5771),  HTW(-4756),  HTW(3720),  HTW(-2669),  HTW(1606),  HTW(-536)};
541
542
static const FIXP_QTW post_twiddle_sin_32[32] = {
543
    HTW(16379), HTW(-16340), HTW(16261), HTW(-16143), HTW(15986), HTW(-15791),
544
    HTW(15557), HTW(-15286), HTW(14978), HTW(-14635), HTW(14256), HTW(-13842),
545
    HTW(13395), HTW(-12916), HTW(12406), HTW(-11866), HTW(11297), HTW(-10702),
546
    HTW(10080), HTW(-9434),  HTW(8765),  HTW(-8076),  HTW(7366),  HTW(-6639),
547
    HTW(5897),  HTW(-5139),  HTW(4370),  HTW(-3590),  HTW(2801),  HTW(-2006),
548
    HTW(1205),  HTW(-402)};
549
550
static const FIXP_QTW post_twiddle_sin_40[40] = {
551
    HTW(16381), HTW(-16356), HTW(16305), HTW(-16229), HTW(16129), HTW(-16003),
552
    HTW(15853), HTW(-15679), HTW(15480), HTW(-15257), HTW(15011), HTW(-14741),
553
    HTW(14449), HTW(-14135), HTW(13799), HTW(-13441), HTW(13063), HTW(-12665),
554
    HTW(12247), HTW(-11810), HTW(11356), HTW(-10883), HTW(10394), HTW(-9889),
555
    HTW(9368),  HTW(-8833),  HTW(8285),  HTW(-7723),  HTW(7150),  HTW(-6566),
556
    HTW(5971),  HTW(-5368),  HTW(4756),  HTW(-4137),  HTW(3511),  HTW(-2880),
557
    HTW(2245),  HTW(-1606),  HTW(965),   HTW(-322)};
558
559
static const FIXP_DBL preModCos[32] = {
560
    -749875776, 786681536,   711263552,  -821592064,  -670937792, 854523392,
561
    628995648,  -885396032,  -585538240, 914135680,   540670208,  -940673088,
562
    -494499680, 964944384,   447137824,  -986891008,  -398698816, 1006460096,
563
    349299264,  -1023604544, -299058240, 1038283072,  248096752,  -1050460288,
564
    -196537584, 1060106816,  144504928,  -1067199488, -92124160,  1071721152,
565
    39521456,   -1073660992};
566
567
static const FIXP_DBL preModSin[32] = {
568
    768510144,   730789760,  -804379072,  -691308864, 838310208,   650162560,
569
    -870221760,  -607449920, 900036928,   563273856,  -927683776,  -517740896,
570
    953095808,   470960608,  -976211712,  -423045728, 996975808,   374111712,
571
    -1015338112, -324276416, 1031254400,  273659904,  -1044686336, -222384144,
572
    1055601472,  170572640,  -1063973632, -118350192, 1069782528,  65842640,
573
    -1073014208, -13176464};
574
575
/* The cube root function */
576
/*****************************************************************************
577
578
    functionname: invCubeRootNorm2
579
    description:  delivers 1/cuberoot(op) in Q1.31 format and modified exponent
580
581
*****************************************************************************/
582
235M
#define CUBE_ROOT_BITS 7
583
#define CUBE_ROOT_VALUES (128 + 2)
584
117M
#define CUBE_ROOT_BITS_MASK 0x7f
585
117M
#define CUBE_ROOT_FRACT_BITS_MASK 0x007FFFFF
586
/* Inverse cube root table for operands running from 0.5 to 1.0 */
587
/* (INT) (1.0/cuberoot((op)));                    */
588
/* Implicit exponent is 1.                        */
589
590
LNK_SECTION_CONSTDATA
591
static const FIXP_DBL invCubeRootTab[CUBE_ROOT_VALUES] = {
592
    (0x50a28be6), (0x506d1172), (0x503823c4), (0x5003c05a), (0x4fcfe4c0),
593
    (0x4f9c8e92), (0x4f69bb7d), (0x4f37693b), (0x4f059594), (0x4ed43e5f),
594
    (0x4ea36181), (0x4e72fcea), (0x4e430e98), (0x4e139495), (0x4de48cf5),
595
    (0x4db5f5db), (0x4d87cd73), (0x4d5a11f2), (0x4d2cc19c), (0x4cffdabb),
596
    (0x4cd35ba4), (0x4ca742b7), (0x4c7b8e5c), (0x4c503d05), (0x4c254d2a),
597
    (0x4bfabd50), (0x4bd08c00), (0x4ba6b7cd), (0x4b7d3f53), (0x4b542134),
598
    (0x4b2b5c18), (0x4b02eeb1), (0x4adad7b8), (0x4ab315ea), (0x4a8ba80d),
599
    (0x4a648cec), (0x4a3dc35b), (0x4a174a30), (0x49f1204a), (0x49cb448d),
600
    (0x49a5b5e2), (0x49807339), (0x495b7b86), (0x4936cdc2), (0x491268ec),
601
    (0x48ee4c08), (0x48ca761f), (0x48a6e63e), (0x48839b76), (0x486094de),
602
    (0x483dd190), (0x481b50ad), (0x47f91156), (0x47d712b3), (0x47b553f0),
603
    (0x4793d43c), (0x477292c9), (0x47518ece), (0x4730c785), (0x47103c2d),
604
    (0x46efec06), (0x46cfd655), (0x46affa61), (0x46905777), (0x4670ece4),
605
    (0x4651b9f9), (0x4632be0b), (0x4613f871), (0x45f56885), (0x45d70da5),
606
    (0x45b8e72f), (0x459af487), (0x457d3511), (0x455fa835), (0x45424d5d),
607
    (0x452523f6), (0x45082b6e), (0x44eb6337), (0x44cecac5), (0x44b2618d),
608
    (0x44962708), (0x447a1ab1), (0x445e3c02), (0x44428a7c), (0x4427059e),
609
    (0x440bacec), (0x43f07fe9), (0x43d57e1c), (0x43baa70e), (0x439ffa48),
610
    (0x43857757), (0x436b1dc8), (0x4350ed2b), (0x4336e511), (0x431d050c),
611
    (0x43034cb2), (0x42e9bb98), (0x42d05156), (0x42b70d85), (0x429defc0),
612
    (0x4284f7a2), (0x426c24cb), (0x425376d8), (0x423aed6a), (0x42228823),
613
    (0x420a46a6), (0x41f22898), (0x41da2d9f), (0x41c25561), (0x41aa9f86),
614
    (0x41930bba), (0x417b99a5), (0x416448f5), (0x414d1956), (0x41360a76),
615
    (0x411f1c06), (0x41084db5), (0x40f19f35), (0x40db1039), (0x40c4a074),
616
    (0x40ae4f9b), (0x40981d64), (0x40820985), (0x406c13b6), (0x40563bb1),
617
    (0x4040812e), (0x402ae3e7), (0x40156399), (0x40000000), (0x3FEAB8D9)};
618
/*  n.a.  */
619
static const FIXP_DBL invCubeRootCorrection[3] = {0x40000000, 0x50A28BE6,
620
                                                  0x6597FA95};
621
622
/*****************************************************************************
623
 * \brief calculate 1.0/cube_root(op), op contains mantissa and exponent
624
 * \param op_m: (i) mantissa of operand, must not be zero (0x0000.0000) or
625
 * negative
626
 * \param op_e: (i) pointer to the exponent of the operand (must be initialized)
627
 * and .. (o) pointer to the exponent of the result
628
 * \return:     (o) mantissa of the result
629
 * \description:
630
 *  This routine calculates the cube root of the input operand, that is
631
 *  given with its mantissa in Q31 format (FIXP_DBL) and its exponent (INT).
632
 *  The resulting mantissa is returned in format Q31. The exponent (*op_e)
633
 *  is modified accordingly. It is not assured, that the result is fully
634
 * left-aligned but assumed to have not more than 2 bits headroom. There is one
635
 * macro to activate the use of this algorithm: FUNCTION_invCubeRootNorm2 By
636
 * means of activating the macro INVCUBEROOTNORM2_LINEAR_INTERPOLATE_HQ, a
637
 * slightly higher precision is reachable (by default, not active). For DEBUG
638
 * purpose only: a FDK_ASSERT macro validates, if the input mantissa is greater
639
 * zero.
640
 *
641
 */
642
static
643
#ifdef __arm__
644
    FIXP_DBL __attribute__((always_inline))
645
    invCubeRootNorm2(FIXP_DBL op_m, INT* op_e)
646
#else
647
    FIXP_DBL
648
    invCubeRootNorm2(FIXP_DBL op_m, INT* op_e)
649
#endif
650
117M
{
651
117M
  FDK_ASSERT(op_m > FIXP_DBL(0));
652
653
  /* normalize input, calculate shift value */
654
117M
  INT exponent = (INT)fNormz(op_m) - 1;
655
117M
  op_m <<= exponent;
656
657
117M
  INT index = (INT)(op_m >> (DFRACT_BITS - 1 - (CUBE_ROOT_BITS + 1))) &
658
117M
              CUBE_ROOT_BITS_MASK;
659
117M
  FIXP_DBL fract = (FIXP_DBL)(((INT)op_m & CUBE_ROOT_FRACT_BITS_MASK)
660
117M
                              << (CUBE_ROOT_BITS + 1));
661
117M
  FIXP_DBL diff = invCubeRootTab[index + 1] - invCubeRootTab[index];
662
117M
  op_m = fMultAddDiv2(invCubeRootTab[index], diff << 1, fract);
663
#if defined(INVCUBEROOTNORM2_LINEAR_INTERPOLATE_HQ)
664
  /* reg1 = t[i] + (t[i+1]-t[i])*fract ... already computed ... +
665
   * (1-fract)fract*(t[i+2]-t[i+1])/2 */
666
  if (fract != (FIXP_DBL)0) {
667
    /* fract = fract * (1 - fract) */
668
    fract = fMultDiv2(fract, (FIXP_DBL)((LONG)0x80000000 - (LONG)fract)) << 1;
669
    diff = diff - (invCubeRootTab[index + 2] - invCubeRootTab[index + 1]);
670
    op_m = fMultAddDiv2(op_m, fract, diff);
671
  }
672
#endif /* INVCUBEROOTNORM2_LINEAR_INTERPOLATE_HQ */
673
674
  /* calculate the output exponent = input * exp/3 = cubicroot(m)*2^(exp/3)
675
   * where 2^(exp/3) = 2^k'*2 or 2^k'*2^(1/3) or 2^k'*2^(2/3) */
676
117M
  exponent = exponent - *op_e + 3;
677
117M
  INT shift_tmp =
678
117M
      ((INT)fMultDiv2((FIXP_SGL)fAbs(exponent), (FIXP_SGL)0x5556)) >> 16;
679
117M
  if (exponent < 0) {
680
69.8M
    shift_tmp = -shift_tmp;
681
69.8M
  }
682
117M
  INT rem = exponent - 3 * shift_tmp;
683
117M
  if (rem < 0) {
684
47.2M
    rem += 3;
685
47.2M
    shift_tmp--;
686
47.2M
  }
687
688
117M
  *op_e = shift_tmp;
689
117M
  op_m = fMultDiv2(op_m, invCubeRootCorrection[rem]) << 2;
690
691
117M
  return (op_m);
692
117M
}
693
694
  /*****************************************************************************
695
696
      functionname: invFourthRootNorm2
697
      description:  delivers 1/FourthRoot(op) in Q1.31 format and modified
698
  exponent
699
700
  *****************************************************************************/
701
702
248M
#define FOURTHROOT_BITS 7
703
#define FOURTHROOT_VALUES (128 + 2)
704
124M
#define FOURTHROOT_BITS_MASK 0x7f
705
124M
#define FOURTHROOT_FRACT_BITS_MASK 0x007FFFFF
706
707
LNK_SECTION_CONSTDATA
708
static const FIXP_DBL invFourthRootTab[FOURTHROOT_VALUES] = {
709
    (0x4c1bf829), (0x4bf61977), (0x4bd09843), (0x4bab72ef), (0x4b86a7eb),
710
    (0x4b6235ac), (0x4b3e1ab6), (0x4b1a5592), (0x4af6e4d4), (0x4ad3c718),
711
    (0x4ab0fb03), (0x4a8e7f42), (0x4a6c5288), (0x4a4a7393), (0x4a28e126),
712
    (0x4a079a0c), (0x49e69d16), (0x49c5e91f), (0x49a57d04), (0x498557ac),
713
    (0x49657802), (0x4945dcf9), (0x49268588), (0x490770ac), (0x48e89d6a),
714
    (0x48ca0ac9), (0x48abb7d6), (0x488da3a6), (0x486fcd4f), (0x485233ed),
715
    (0x4834d6a3), (0x4817b496), (0x47faccf0), (0x47de1ee0), (0x47c1a999),
716
    (0x47a56c51), (0x47896643), (0x476d96af), (0x4751fcd6), (0x473697ff),
717
    (0x471b6773), (0x47006a81), (0x46e5a079), (0x46cb08ae), (0x46b0a279),
718
    (0x46966d34), (0x467c683d), (0x466292f4), (0x4648ecbc), (0x462f74fe),
719
    (0x46162b20), (0x45fd0e91), (0x45e41ebe), (0x45cb5b19), (0x45b2c315),
720
    (0x459a562a), (0x458213cf), (0x4569fb81), (0x45520cbc), (0x453a4701),
721
    (0x4522a9d1), (0x450b34b0), (0x44f3e726), (0x44dcc0ba), (0x44c5c0f7),
722
    (0x44aee768), (0x4498339e), (0x4481a527), (0x446b3b96), (0x4454f67e),
723
    (0x443ed576), (0x4428d815), (0x4412fdf3), (0x43fd46ad), (0x43e7b1de),
724
    (0x43d23f23), (0x43bcee1e), (0x43a7be6f), (0x4392afb8), (0x437dc19d),
725
    (0x4368f3c5), (0x435445d6), (0x433fb779), (0x432b4856), (0x4316f81a),
726
    (0x4302c66f), (0x42eeb305), (0x42dabd8a), (0x42c6e5ad), (0x42b32b21),
727
    (0x429f8d96), (0x428c0cc2), (0x4278a859), (0x42656010), (0x4252339e),
728
    (0x423f22bc), (0x422c2d23), (0x4219528b), (0x420692b2), (0x41f3ed51),
729
    (0x41e16228), (0x41cef0f2), (0x41bc9971), (0x41aa5b62), (0x41983687),
730
    (0x41862aa2), (0x41743775), (0x41625cc3), (0x41509a50), (0x413eefe2),
731
    (0x412d5d3e), (0x411be22b), (0x410a7e70), (0x40f931d5), (0x40e7fc23),
732
    (0x40d6dd24), (0x40c5d4a2), (0x40b4e268), (0x40a40642), (0x40933ffc),
733
    (0x40828f64), (0x4071f447), (0x40616e73), (0x4050fdb9), (0x4040a1e6),
734
    (0x40305acc), (0x4020283c), (0x40100a08), (0x40000000), (0x3ff009f9),
735
};
736
737
static const FIXP_DBL invFourthRootCorrection[4] = {0x40000000, 0x4C1BF829,
738
                                                    0x5A82799A, 0x6BA27E65};
739
740
/* The fourth root function */
741
/*****************************************************************************
742
 * \brief calculate 1.0/fourth_root(op), op contains mantissa and exponent
743
 * \param op_m: (i) mantissa of operand, must not be zero (0x0000.0000) or
744
 * negative
745
 * \param op_e: (i) pointer to the exponent of the operand (must be initialized)
746
 * and .. (o) pointer to the exponent of the result
747
 * \return:     (o) mantissa of the result
748
 * \description:
749
 *  This routine calculates the cube root of the input operand, that is
750
 *  given with its mantissa in Q31 format (FIXP_DBL) and its exponent (INT).
751
 *  The resulting mantissa is returned in format Q31. The exponent (*op_e)
752
 *  is modified accordingly. It is not assured, that the result is fully
753
 * left-aligned but assumed to have not more than 2 bits headroom. There is one
754
 * macro to activate the use of this algorithm: FUNCTION_invFourthRootNorm2 By
755
 * means of activating the macro INVFOURTHROOTNORM2_LINEAR_INTERPOLATE_HQ, a
756
 * slightly higher precision is reachable (by default, not active). For DEBUG
757
 * purpose only: a FDK_ASSERT macro validates, if the input mantissa is greater
758
 * zero.
759
 *
760
 */
761
762
/* #define INVFOURTHROOTNORM2_LINEAR_INTERPOLATE_HQ */
763
764
static
765
#ifdef __arm__
766
    FIXP_DBL __attribute__((always_inline))
767
    invFourthRootNorm2(FIXP_DBL op_m, INT* op_e)
768
#else
769
    FIXP_DBL
770
    invFourthRootNorm2(FIXP_DBL op_m, INT* op_e)
771
#endif
772
124M
{
773
124M
  FDK_ASSERT(op_m > FL2FXCONST_DBL(0.0));
774
775
  /* normalize input, calculate shift value */
776
124M
  INT exponent = (INT)fNormz(op_m) - 1;
777
124M
  op_m <<= exponent;
778
779
124M
  INT index = (INT)(op_m >> (DFRACT_BITS - 1 - (FOURTHROOT_BITS + 1))) &
780
124M
              FOURTHROOT_BITS_MASK;
781
124M
  FIXP_DBL fract = (FIXP_DBL)(((INT)op_m & FOURTHROOT_FRACT_BITS_MASK)
782
124M
                              << (FOURTHROOT_BITS + 1));
783
124M
  FIXP_DBL diff = invFourthRootTab[index + 1] - invFourthRootTab[index];
784
124M
  op_m = invFourthRootTab[index] + (fMultDiv2(diff, fract) << 1);
785
786
#if defined(INVFOURTHROOTNORM2_LINEAR_INTERPOLATE_HQ)
787
  /* reg1 = t[i] + (t[i+1]-t[i])*fract ... already computed ... +
788
   * (1-fract)fract*(t[i+2]-t[i+1])/2 */
789
  if (fract != (FIXP_DBL)0) {
790
    /* fract = fract * (1 - fract) */
791
    fract = fMultDiv2(fract, (FIXP_DBL)((LONG)0x80000000 - (LONG)fract)) << 1;
792
    diff = diff - (invFourthRootTab[index + 2] - invFourthRootTab[index + 1]);
793
    op_m = fMultAddDiv2(op_m, fract, diff);
794
  }
795
#endif /* INVFOURTHROOTNORM2_LINEAR_INTERPOLATE_HQ */
796
797
124M
  exponent = exponent - *op_e + 4;
798
124M
  INT rem = exponent & 0x00000003;
799
124M
  INT shift_tmp = (exponent >> 2);
800
801
124M
  *op_e = shift_tmp;
802
124M
  op_m = fMultDiv2(op_m, invFourthRootCorrection[rem]) << 2;
803
804
124M
  return (op_m);
805
124M
}
806
807
/*****************************************************************************
808
809
    functionname: inv3EigthRootNorm2
810
    description:  delivers 1/cubert(op) normalized to .5...1 and the shift value
811
of the OUTPUT
812
813
*****************************************************************************/
814
84.2M
#define THREEIGTHROOT_BITS 7
815
#define THREEIGTHROOT_VALUES (128 + 2)
816
42.1M
#define THREEIGTHROOT_BITS_MASK 0x7f
817
42.1M
#define THREEIGTHROOT_FRACT_BITS_MASK 0x007FFFFF
818
819
LNK_SECTION_CONSTDATA
820
static const FIXP_DBL inv3EigthRootTab[THREEIGTHROOT_VALUES] = {
821
    (0x45cae0f2), (0x45b981bf), (0x45a8492a), (0x45973691), (0x45864959),
822
    (0x457580e6), (0x4564dca4), (0x45545c00), (0x4543fe6b), (0x4533c35a),
823
    (0x4523aa44), (0x4513b2a4), (0x4503dbf7), (0x44f425be), (0x44e48f7b),
824
    (0x44d518b6), (0x44c5c0f7), (0x44b687c8), (0x44a76cb8), (0x44986f58),
825
    (0x44898f38), (0x447acbef), (0x446c2514), (0x445d9a3f), (0x444f2b0d),
826
    (0x4440d71a), (0x44329e07), (0x44247f73), (0x44167b04), (0x4408905e),
827
    (0x43fabf28), (0x43ed070b), (0x43df67b0), (0x43d1e0c5), (0x43c471f7),
828
    (0x43b71af6), (0x43a9db71), (0x439cb31c), (0x438fa1ab), (0x4382a6d2),
829
    (0x4375c248), (0x4368f3c5), (0x435c3b03), (0x434f97bc), (0x434309ac),
830
    (0x43369091), (0x432a2c28), (0x431ddc30), (0x4311a06c), (0x4305789c),
831
    (0x42f96483), (0x42ed63e5), (0x42e17688), (0x42d59c30), (0x42c9d4a6),
832
    (0x42be1fb1), (0x42b27d1a), (0x42a6ecac), (0x429b6e2f), (0x42900172),
833
    (0x4284a63f), (0x42795c64), (0x426e23b0), (0x4262fbf2), (0x4257e4f9),
834
    (0x424cde96), (0x4241e89a), (0x423702d8), (0x422c2d23), (0x4221674d),
835
    (0x4216b12c), (0x420c0a94), (0x4201735b), (0x41f6eb57), (0x41ec725f),
836
    (0x41e2084b), (0x41d7acf3), (0x41cd6030), (0x41c321db), (0x41b8f1ce),
837
    (0x41aecfe5), (0x41a4bbf8), (0x419ab5e6), (0x4190bd89), (0x4186d2bf),
838
    (0x417cf565), (0x41732558), (0x41696277), (0x415faca1), (0x415603b4),
839
    (0x414c6792), (0x4142d818), (0x4139552a), (0x412fdea6), (0x41267470),
840
    (0x411d1668), (0x4113c472), (0x410a7e70), (0x41014445), (0x40f815d4),
841
    (0x40eef302), (0x40e5dbb4), (0x40dccfcd), (0x40d3cf33), (0x40cad9cb),
842
    (0x40c1ef7b), (0x40b9102a), (0x40b03bbd), (0x40a7721c), (0x409eb32e),
843
    (0x4095feda), (0x408d5508), (0x4084b5a0), (0x407c208b), (0x407395b2),
844
    (0x406b14fd), (0x40629e56), (0x405a31a6), (0x4051ced8), (0x404975d5),
845
    (0x40412689), (0x4038e0dd), (0x4030a4bd), (0x40287215), (0x402048cf),
846
    (0x401828d7), (0x4010121a), (0x40080483), (0x40000000), (0x3ff8047d),
847
};
848
849
/* The last value is rounded in order to avoid any overflow due to the values
850
 * range of the root table */
851
static const FIXP_DBL inv3EigthRootCorrection[8] = {
852
    0x40000000, 0x45CAE0F2, 0x4C1BF829, 0x52FF6B55,
853
    0x5A82799A, 0x62B39509, 0x6BA27E65, 0x75606373};
854
855
/* The 3/8 root function */
856
/*****************************************************************************
857
 * \brief calculate 1.0/3Eigth_root(op) = 1.0/(x)^(3/8), op contains mantissa
858
 * and exponent
859
 * \param op_m: (i) mantissa of operand, must not be zero (0x0000.0000) or
860
 * negative
861
 * \param op_e: (i) pointer to the exponent of the operand (must be initialized)
862
 * and .. (o) pointer to the exponent of the result
863
 * \return:     (o) mantissa of the result
864
 * \description:
865
 *  This routine calculates the cube root of the input operand, that is
866
 *  given with its mantissa in Q31 format (FIXP_DBL) and its exponent (INT).
867
 *  The resulting mantissa is returned in format Q31. The exponent (*op_e)
868
 *  is modified accordingly. It is not assured, that the result is fully
869
 * left-aligned but assumed to have not more than 2 bits headroom. There is one
870
 * macro to activate the use of this algorithm: FUNCTION_inv3EigthRootNorm2 By
871
 * means of activating the macro INVTHREEIGTHROOTNORM2_LINEAR_INTERPOLATE_HQ, a
872
 * slightly higher precision is reachable (by default, not active). For DEBUG
873
 * purpose only: a FDK_ASSERT macro validates, if the input mantissa is greater
874
 * zero.
875
 *
876
 */
877
878
/* #define INVTHREEIGTHROOTNORM2_LINEAR_INTERPOLATE_HQ */
879
880
static
881
#ifdef __arm__
882
    FIXP_DBL __attribute__((always_inline))
883
    inv3EigthRootNorm2(FIXP_DBL op_m, INT* op_e)
884
#else
885
    FIXP_DBL
886
    inv3EigthRootNorm2(FIXP_DBL op_m, INT* op_e)
887
#endif
888
42.1M
{
889
42.1M
  FDK_ASSERT(op_m > FL2FXCONST_DBL(0.0));
890
891
  /* normalize input, calculate shift op_mue */
892
42.1M
  INT exponent = (INT)fNormz(op_m) - 1;
893
42.1M
  op_m <<= exponent;
894
895
42.1M
  INT index = (INT)(op_m >> (DFRACT_BITS - 1 - (THREEIGTHROOT_BITS + 1))) &
896
42.1M
              THREEIGTHROOT_BITS_MASK;
897
42.1M
  FIXP_DBL fract = (FIXP_DBL)(((INT)op_m & THREEIGTHROOT_FRACT_BITS_MASK)
898
42.1M
                              << (THREEIGTHROOT_BITS + 1));
899
42.1M
  FIXP_DBL diff = inv3EigthRootTab[index + 1] - inv3EigthRootTab[index];
900
42.1M
  op_m = inv3EigthRootTab[index] + (fMultDiv2(diff, fract) << 1);
901
902
#if defined(INVTHREEIGTHROOTNORM2_LINEAR_INTERPOLATE_HQ)
903
  /* op_m = t[i] + (t[i+1]-t[i])*fract ... already computed ... +
904
   * (1-fract)fract*(t[i+2]-t[i+1])/2 */
905
  if (fract != (FIXP_DBL)0) {
906
    /* fract = fract * (1 - fract) */
907
    fract = fMultDiv2(fract, (FIXP_DBL)((LONG)0x80000000 - (LONG)fract)) << 1;
908
    diff = diff - (inv3EigthRootTab[index + 2] - inv3EigthRootTab[index + 1]);
909
    op_m = fMultAddDiv2(op_m, fract, diff);
910
  }
911
#endif /* INVTHREEIGTHROOTNORM2_LINEAR_INTERPOLATE_HQ */
912
913
42.1M
  exponent = exponent - *op_e + 8;
914
42.1M
  INT rem = exponent & 0x00000007;
915
42.1M
  INT shift_tmp = (exponent >> 3);
916
917
42.1M
  *op_e = shift_tmp * 3;
918
42.1M
  op_m = fMultDiv2(op_m, inv3EigthRootCorrection[rem]) << 2;
919
920
42.1M
  return (fMult(op_m, fMult(op_m, op_m)));
921
42.1M
}
922
923
SBR_ERROR
924
QmfTransposerCreate(HANDLE_HBE_TRANSPOSER* hQmfTransposer, const int frameSize,
925
20.6k
                    int bDisableCrossProducts, int bSbr41) {
926
20.6k
  HANDLE_HBE_TRANSPOSER hQmfTran = NULL;
927
928
20.6k
  int i;
929
930
20.6k
  if (hQmfTransposer != NULL) {
931
    /* Memory allocation */
932
    /*--------------------------------------------------------------------------------------------*/
933
20.6k
    hQmfTran =
934
20.6k
        (HANDLE_HBE_TRANSPOSER)FDKcalloc(1, sizeof(struct hbeTransposer));
935
20.6k
    if (hQmfTran == NULL) {
936
0
      return SBRDEC_MEM_ALLOC_FAILED;
937
0
    }
938
939
82.4k
    for (i = 0; i < MAX_STRETCH_HBE - 1; i++) {
940
61.8k
      hQmfTran->bXProducts[i] = (bDisableCrossProducts ? 0 : xProducts[i]);
941
61.8k
    }
942
943
20.6k
    hQmfTran->timeDomainWinLen = frameSize;
944
20.6k
    if (frameSize == 768) {
945
8.41k
      hQmfTran->noCols =
946
8.41k
          (8 * frameSize / 3) / QMF_SYNTH_CHANNELS; /* 32 for 24:64 */
947
12.2k
    } else {
948
12.2k
      hQmfTran->noCols =
949
12.2k
          (bSbr41 + 1) * 2 * frameSize /
950
12.2k
          QMF_SYNTH_CHANNELS; /* 32 for 32:64 and 64 for 16:64 -> identical to
951
                                 sbrdec->no_cols */
952
12.2k
    }
953
954
20.6k
    hQmfTran->noChannels = frameSize / hQmfTran->noCols;
955
956
20.6k
    hQmfTran->qmfInBufSize = QMF_WIN_LEN;
957
20.6k
    hQmfTran->qmfOutBufSize = 2 * (hQmfTran->noCols / 2 + QMF_WIN_LEN - 1);
958
959
20.6k
    hQmfTran->inBuf_F =
960
20.6k
        (LONG*)FDKcalloc(QMF_SYNTH_CHANNELS + 20 + 1, sizeof(LONG));
961
    /* buffered time signal needs to be delayed by synthesis_size; max
962
     * synthesis_size = 20; */
963
20.6k
    if (hQmfTran->inBuf_F == NULL) {
964
0
      QmfTransposerClose(hQmfTran);
965
0
      return SBRDEC_MEM_ALLOC_FAILED;
966
0
    }
967
968
20.6k
    hQmfTran->qmfInBufReal_F =
969
20.6k
        (FIXP_DBL**)FDKcalloc(hQmfTran->qmfInBufSize, sizeof(FIXP_DBL*));
970
20.6k
    hQmfTran->qmfInBufImag_F =
971
20.6k
        (FIXP_DBL**)FDKcalloc(hQmfTran->qmfInBufSize, sizeof(FIXP_DBL*));
972
973
20.6k
    if (hQmfTran->qmfInBufReal_F == NULL) {
974
0
      QmfTransposerClose(hQmfTran);
975
0
      return SBRDEC_MEM_ALLOC_FAILED;
976
0
    }
977
20.6k
    if (hQmfTran->qmfInBufImag_F == NULL) {
978
0
      QmfTransposerClose(hQmfTran);
979
0
      return SBRDEC_MEM_ALLOC_FAILED;
980
0
    }
981
982
288k
    for (i = 0; i < hQmfTran->qmfInBufSize; i++) {
983
268k
      hQmfTran->qmfInBufReal_F[i] = (FIXP_DBL*)FDKaalloc(
984
268k
          QMF_SYNTH_CHANNELS * sizeof(FIXP_DBL), ALIGNMENT_DEFAULT);
985
268k
      hQmfTran->qmfInBufImag_F[i] = (FIXP_DBL*)FDKaalloc(
986
268k
          QMF_SYNTH_CHANNELS * sizeof(FIXP_DBL), ALIGNMENT_DEFAULT);
987
268k
      if (hQmfTran->qmfInBufReal_F[i] == NULL) {
988
0
        QmfTransposerClose(hQmfTran);
989
0
        return SBRDEC_MEM_ALLOC_FAILED;
990
0
      }
991
268k
      if (hQmfTran->qmfInBufImag_F[i] == NULL) {
992
0
        QmfTransposerClose(hQmfTran);
993
0
        return SBRDEC_MEM_ALLOC_FAILED;
994
0
      }
995
268k
    }
996
997
20.6k
    hQmfTran->qmfHBEBufReal_F =
998
20.6k
        (FIXP_DBL**)FDKcalloc(HBE_MAX_OUT_SLOTS, sizeof(FIXP_DBL*));
999
20.6k
    hQmfTran->qmfHBEBufImag_F =
1000
20.6k
        (FIXP_DBL**)FDKcalloc(HBE_MAX_OUT_SLOTS, sizeof(FIXP_DBL*));
1001
1002
20.6k
    if (hQmfTran->qmfHBEBufReal_F == NULL) {
1003
0
      QmfTransposerClose(hQmfTran);
1004
0
      return SBRDEC_MEM_ALLOC_FAILED;
1005
0
    }
1006
20.6k
    if (hQmfTran->qmfHBEBufImag_F == NULL) {
1007
0
      QmfTransposerClose(hQmfTran);
1008
0
      return SBRDEC_MEM_ALLOC_FAILED;
1009
0
    }
1010
1011
247k
    for (i = 0; i < HBE_MAX_OUT_SLOTS; i++) {
1012
226k
      hQmfTran->qmfHBEBufReal_F[i] =
1013
226k
          (FIXP_DBL*)FDKcalloc(QMF_SYNTH_CHANNELS, sizeof(FIXP_DBL));
1014
226k
      hQmfTran->qmfHBEBufImag_F[i] =
1015
226k
          (FIXP_DBL*)FDKcalloc(QMF_SYNTH_CHANNELS, sizeof(FIXP_DBL));
1016
226k
      if (hQmfTran->qmfHBEBufReal_F[i] == NULL) {
1017
0
        QmfTransposerClose(hQmfTran);
1018
0
        return SBRDEC_MEM_ALLOC_FAILED;
1019
0
      }
1020
226k
      if (hQmfTran->qmfHBEBufImag_F[i] == NULL) {
1021
0
        QmfTransposerClose(hQmfTran);
1022
0
        return SBRDEC_MEM_ALLOC_FAILED;
1023
0
      }
1024
226k
    }
1025
1026
20.6k
    hQmfTran->qmfBufferCodecTempSlot_F =
1027
20.6k
        (FIXP_DBL*)FDKcalloc(QMF_SYNTH_CHANNELS / 2, sizeof(FIXP_DBL));
1028
20.6k
    if (hQmfTran->qmfBufferCodecTempSlot_F == NULL) {
1029
0
      QmfTransposerClose(hQmfTran);
1030
0
      return SBRDEC_MEM_ALLOC_FAILED;
1031
0
    }
1032
1033
20.6k
    hQmfTran->bSbr41 = bSbr41;
1034
1035
20.6k
    hQmfTran->highband_exp[0] = 0;
1036
20.6k
    hQmfTran->highband_exp[1] = 0;
1037
20.6k
    hQmfTran->target_exp[0] = 0;
1038
20.6k
    hQmfTran->target_exp[1] = 0;
1039
1040
20.6k
    *hQmfTransposer = hQmfTran;
1041
20.6k
  }
1042
1043
20.6k
  return SBRDEC_OK;
1044
20.6k
}
1045
1046
SBR_ERROR QmfTransposerReInit(HANDLE_HBE_TRANSPOSER hQmfTransposer,
1047
                              UCHAR* FreqBandTable[2], UCHAR NSfb[2])
1048
/* removed bSbr41 from parameterlist:
1049
   don't know where to get this value from
1050
   at call-side */
1051
23.4k
{
1052
23.4k
  int L, sfb, patch, stopPatch, qmfErr;
1053
1054
23.4k
  if (hQmfTransposer != NULL) {
1055
23.4k
    const FIXP_QTW* tmp_t_cos;
1056
23.4k
    const FIXP_QTW* tmp_t_sin;
1057
1058
23.4k
    hQmfTransposer->startBand = FreqBandTable[0][0];
1059
23.4k
    FDK_ASSERT((!hQmfTransposer->bSbr41 && hQmfTransposer->startBand <= 32) ||
1060
23.4k
               (hQmfTransposer->bSbr41 &&
1061
23.4k
                hQmfTransposer->startBand <=
1062
23.4k
                    16)); /* is checked by resetFreqBandTables() */
1063
23.4k
    hQmfTransposer->stopBand = FreqBandTable[0][NSfb[0]];
1064
1065
23.4k
    hQmfTransposer->synthSize =
1066
23.4k
        4 * ((hQmfTransposer->startBand + 4) / 8 + 1); /* 8, 12, 16, 20 */
1067
23.4k
    hQmfTransposer->kstart = startSubband2kL[hQmfTransposer->startBand];
1068
1069
    /* don't know where to take this information from */
1070
    /* hQmfTransposer->bSbr41 = bSbr41;               */
1071
1072
23.4k
    if (hQmfTransposer->bSbr41) {
1073
5.97k
      if (hQmfTransposer->kstart + hQmfTransposer->synthSize > 16)
1074
2.89k
        hQmfTransposer->kstart = 16 - hQmfTransposer->synthSize;
1075
17.4k
    } else if (hQmfTransposer->timeDomainWinLen == 768) {
1076
16.9k
      if (hQmfTransposer->kstart + hQmfTransposer->synthSize > 24)
1077
8.82k
        hQmfTransposer->kstart = 24 - hQmfTransposer->synthSize;
1078
16.9k
    }
1079
1080
23.4k
    hQmfTransposer->synthesisQmfPreModCos_F =
1081
23.4k
        &preModCos[hQmfTransposer->kstart];
1082
23.4k
    hQmfTransposer->synthesisQmfPreModSin_F =
1083
23.4k
        &preModSin[hQmfTransposer->kstart];
1084
1085
23.4k
    L = 2 * hQmfTransposer->synthSize; /* 8, 16, 24, 32, 40 */
1086
                                       /* Change analysis post twiddles */
1087
1088
23.4k
    switch (L) {
1089
0
      case 8:
1090
0
        tmp_t_cos = post_twiddle_cos_8;
1091
0
        tmp_t_sin = post_twiddle_sin_8;
1092
0
        break;
1093
2.80k
      case 16:
1094
2.80k
        tmp_t_cos = post_twiddle_cos_16;
1095
2.80k
        tmp_t_sin = post_twiddle_sin_16;
1096
2.80k
        break;
1097
11.3k
      case 24:
1098
11.3k
        tmp_t_cos = post_twiddle_cos_24;
1099
11.3k
        tmp_t_sin = post_twiddle_sin_24;
1100
11.3k
        break;
1101
8.30k
      case 32:
1102
8.30k
        tmp_t_cos = post_twiddle_cos_32;
1103
8.30k
        tmp_t_sin = post_twiddle_sin_32;
1104
8.30k
        break;
1105
977
      case 40:
1106
977
        tmp_t_cos = post_twiddle_cos_40;
1107
977
        tmp_t_sin = post_twiddle_sin_40;
1108
977
        break;
1109
0
      default:
1110
0
        return SBRDEC_UNSUPPORTED_CONFIG;
1111
23.4k
    }
1112
1113
23.4k
    qmfErr = qmfInitSynthesisFilterBank(
1114
23.4k
        &hQmfTransposer->HBESynthesisQMF, hQmfTransposer->synQmfStates,
1115
23.4k
        hQmfTransposer->noCols, 0, hQmfTransposer->synthSize,
1116
23.4k
        hQmfTransposer->synthSize, 1);
1117
23.4k
    if (qmfErr != 0) {
1118
0
      return SBRDEC_UNSUPPORTED_CONFIG;
1119
0
    }
1120
1121
23.4k
    qmfErr = qmfInitAnalysisFilterBank(
1122
23.4k
        &hQmfTransposer->HBEAnalysiscQMF, hQmfTransposer->anaQmfStates,
1123
23.4k
        hQmfTransposer->noCols / 2, 0, 2 * hQmfTransposer->synthSize,
1124
23.4k
        2 * hQmfTransposer->synthSize, 0);
1125
1126
23.4k
    if (qmfErr != 0) {
1127
0
      return SBRDEC_UNSUPPORTED_CONFIG;
1128
0
    }
1129
1130
23.4k
    hQmfTransposer->HBEAnalysiscQMF.t_cos = tmp_t_cos;
1131
23.4k
    hQmfTransposer->HBEAnalysiscQMF.t_sin = tmp_t_sin;
1132
1133
23.4k
    FDKmemset(hQmfTransposer->xOverQmf, 0,
1134
23.4k
              MAX_NUM_PATCHES * sizeof(int)); /* global */
1135
23.4k
    sfb = 0;
1136
23.4k
    if (hQmfTransposer->bSbr41) {
1137
5.97k
      stopPatch = MAX_NUM_PATCHES;
1138
5.97k
      hQmfTransposer->maxStretch = MAX_STRETCH_HBE;
1139
17.4k
    } else {
1140
17.4k
      stopPatch = MAX_STRETCH_HBE;
1141
17.4k
    }
1142
1143
80.4k
    for (patch = 1; patch <= stopPatch; patch++) {
1144
286k
      while (sfb <= NSfb[0] &&
1145
263k
             FreqBandTable[0][sfb] <= patch * hQmfTransposer->startBand)
1146
206k
        sfb++;
1147
80.4k
      if (sfb <= NSfb[0]) {
1148
        /* If the distance is larger than three QMF bands - try aligning to high
1149
         * resolution frequency bands instead. */
1150
57.0k
        if ((patch * hQmfTransposer->startBand - FreqBandTable[0][sfb - 1]) <=
1151
57.0k
            3) {
1152
52.3k
          hQmfTransposer->xOverQmf[patch - 1] = FreqBandTable[0][sfb - 1];
1153
52.3k
        } else {
1154
4.71k
          int sfb_tmp = 0;
1155
74.5k
          while (sfb_tmp <= NSfb[1] &&
1156
74.5k
                 FreqBandTable[1][sfb_tmp] <= patch * hQmfTransposer->startBand)
1157
69.7k
            sfb_tmp++;
1158
4.71k
          hQmfTransposer->xOverQmf[patch - 1] = FreqBandTable[1][sfb_tmp - 1];
1159
4.71k
        }
1160
57.0k
      } else {
1161
23.3k
        hQmfTransposer->xOverQmf[patch - 1] = hQmfTransposer->stopBand;
1162
23.3k
        hQmfTransposer->maxStretch = fMin(patch, MAX_STRETCH_HBE);
1163
23.3k
        break;
1164
23.3k
      }
1165
80.4k
    }
1166
1167
23.4k
    hQmfTransposer->highband_exp[0] = 0;
1168
23.4k
    hQmfTransposer->highband_exp[1] = 0;
1169
23.4k
    hQmfTransposer->target_exp[0] = 0;
1170
23.4k
    hQmfTransposer->target_exp[1] = 0;
1171
23.4k
  }
1172
1173
23.4k
  return SBRDEC_OK;
1174
23.4k
}
1175
1176
20.6k
void QmfTransposerClose(HANDLE_HBE_TRANSPOSER hQmfTransposer) {
1177
20.6k
  int i;
1178
1179
20.6k
  if (hQmfTransposer != NULL) {
1180
20.6k
    if (hQmfTransposer->inBuf_F) FDKfree(hQmfTransposer->inBuf_F);
1181
1182
20.6k
    if (hQmfTransposer->qmfInBufReal_F) {
1183
288k
      for (i = 0; i < hQmfTransposer->qmfInBufSize; i++) {
1184
268k
        FDKafree(hQmfTransposer->qmfInBufReal_F[i]);
1185
268k
      }
1186
20.6k
      FDKfree(hQmfTransposer->qmfInBufReal_F);
1187
20.6k
    }
1188
1189
20.6k
    if (hQmfTransposer->qmfInBufImag_F) {
1190
288k
      for (i = 0; i < hQmfTransposer->qmfInBufSize; i++) {
1191
268k
        FDKafree(hQmfTransposer->qmfInBufImag_F[i]);
1192
268k
      }
1193
20.6k
      FDKfree(hQmfTransposer->qmfInBufImag_F);
1194
20.6k
    }
1195
1196
20.6k
    if (hQmfTransposer->qmfHBEBufReal_F) {
1197
247k
      for (i = 0; i < HBE_MAX_OUT_SLOTS; i++) {
1198
226k
        FDKfree(hQmfTransposer->qmfHBEBufReal_F[i]);
1199
226k
      }
1200
20.6k
      FDKfree(hQmfTransposer->qmfHBEBufReal_F);
1201
20.6k
    }
1202
1203
20.6k
    if (hQmfTransposer->qmfHBEBufImag_F) {
1204
247k
      for (i = 0; i < HBE_MAX_OUT_SLOTS; i++) {
1205
226k
        FDKfree(hQmfTransposer->qmfHBEBufImag_F[i]);
1206
226k
      }
1207
20.6k
      FDKfree(hQmfTransposer->qmfHBEBufImag_F);
1208
20.6k
    }
1209
1210
20.6k
    FDKfree(hQmfTransposer->qmfBufferCodecTempSlot_F);
1211
1212
20.6k
    FDKfree(hQmfTransposer);
1213
20.6k
  }
1214
20.6k
}
1215
1216
403M
inline void scaleUp(FIXP_DBL* real_m, FIXP_DBL* imag_m, INT* _e) {
1217
403M
  INT reserve;
1218
  /* shift gc_r and gc_i up if possible */
1219
403M
  reserve = CntLeadingZeros((INT(*real_m) ^ INT((*real_m >> 31))) |
1220
403M
                            (INT(*imag_m) ^ INT((*imag_m >> 31)))) -
1221
403M
            1;
1222
403M
  reserve = fMax(reserve - 1,
1223
403M
                 0); /* Leave one bit headroom such that (real_m^2 + imag_m^2)
1224
                        does not overflow later if both are 0x80000000. */
1225
403M
  reserve = fMin(reserve, *_e);
1226
403M
  FDK_ASSERT(reserve >= 0);
1227
403M
  *real_m <<= reserve;
1228
403M
  *imag_m <<= reserve;
1229
403M
  *_e -= reserve;
1230
403M
}
1231
1232
static void calculateCenterFIXP(FIXP_DBL gammaVecReal, FIXP_DBL gammaVecImag,
1233
                                FIXP_DBL* centerReal, FIXP_DBL* centerImag,
1234
59.6M
                                INT* exponent, int stretch, int mult) {
1235
59.6M
  scaleUp(&gammaVecReal, &gammaVecImag, exponent);
1236
59.6M
  FIXP_DBL energy = fPow2Div2(gammaVecReal) + fPow2Div2(gammaVecImag);
1237
1238
59.6M
  if (energy != FL2FXCONST_DBL(0.f)) {
1239
33.5M
    FIXP_DBL gc_r_m, gc_i_m, factor_m = (FIXP_DBL)0;
1240
33.5M
    INT factor_e, gc_e;
1241
33.5M
    factor_e = 2 * (*exponent) + 1;
1242
1243
33.5M
    switch (stretch) {
1244
12.3M
      case 2:
1245
12.3M
        factor_m = invFourthRootNorm2(energy, &factor_e);
1246
12.3M
        break;
1247
14.2M
      case 3:
1248
14.2M
        factor_m = invCubeRootNorm2(energy, &factor_e);
1249
14.2M
        break;
1250
6.90M
      case 4:
1251
6.90M
        factor_m = inv3EigthRootNorm2(energy, &factor_e);
1252
6.90M
        break;
1253
33.5M
    }
1254
1255
33.5M
    gc_r_m = fMultDiv2(gammaVecReal,
1256
33.5M
                       factor_m); /* exponent = HBE_SCALE + factor_e + 1 */
1257
33.5M
    gc_i_m = fMultDiv2(gammaVecImag,
1258
33.5M
                       factor_m); /* exponent = HBE_SCALE + factor_e + 1*/
1259
33.5M
    gc_e = *exponent + factor_e + 1;
1260
1261
33.5M
    scaleUp(&gc_r_m, &gc_i_m, &gc_e);
1262
1263
33.5M
    switch (mult) {
1264
13.6M
      case 0:
1265
13.6M
        *centerReal = gc_r_m;
1266
13.6M
        *centerImag = gc_i_m;
1267
13.6M
        break;
1268
13.7M
      case 1:
1269
13.7M
        *centerReal = fPow2Div2(gc_r_m) - fPow2Div2(gc_i_m);
1270
13.7M
        *centerImag = fMult(gc_r_m, gc_i_m);
1271
13.7M
        gc_e = 2 * gc_e + 1;
1272
13.7M
        break;
1273
6.10M
      case 2:
1274
6.10M
        FIXP_DBL tmp_r = gc_r_m;
1275
6.10M
        FIXP_DBL tmp_i = gc_i_m;
1276
6.10M
        gc_r_m = fPow2Div2(gc_r_m) - fPow2Div2(gc_i_m);
1277
6.10M
        gc_i_m = fMult(tmp_r, gc_i_m);
1278
6.10M
        gc_e = 3 * gc_e + 1 + 1;
1279
6.10M
        cplxMultDiv2(&centerReal[0], &centerImag[0], gc_r_m, gc_i_m, tmp_r,
1280
6.10M
                     tmp_i);
1281
6.10M
        break;
1282
33.5M
    }
1283
1284
33.5M
    scaleUp(centerReal, centerImag, &gc_e);
1285
1286
33.5M
    FDK_ASSERT(gc_e >= 0);
1287
33.5M
    *exponent = gc_e;
1288
33.5M
  } else {
1289
26.1M
    *centerReal = energy; /* energy = 0 */
1290
26.1M
    *centerImag = energy; /* energy = 0 */
1291
26.1M
    *exponent = (INT)energy;
1292
26.1M
  }
1293
59.6M
}
1294
1295
static int getHBEScaleFactorFrame(const int bSbr41, const int maxStretch,
1296
90.9k
                                  const int pitchInBins) {
1297
90.9k
  if (pitchInBins >= pmin * (1 + bSbr41)) {
1298
    /* crossproducts enabled */
1299
7.65k
    return 26;
1300
83.3k
  } else {
1301
83.3k
    return (maxStretch == 2) ? 24 : 25;
1302
83.3k
  }
1303
90.9k
}
1304
1305
static void addHighBandPart(FIXP_DBL g_r_m, FIXP_DBL g_i_m, INT g_e,
1306
                            FIXP_DBL mult, FIXP_DBL gammaCenterReal_m,
1307
                            FIXP_DBL gammaCenterImag_m, INT gammaCenter_e,
1308
                            INT stretch, INT scale_factor_hbe,
1309
                            FIXP_DBL* qmfHBEBufReal_F,
1310
465M
                            FIXP_DBL* qmfHBEBufImag_F) {
1311
465M
  if ((g_r_m | g_i_m) != FL2FXCONST_DBL(0.f)) {
1312
250M
    FIXP_DBL factor_m = (FIXP_DBL)0;
1313
250M
    INT factor_e;
1314
250M
    INT add = (stretch == 4) ? 1 : 0;
1315
250M
    INT shift = (stretch == 4) ? 1 : 2;
1316
1317
250M
    scaleUp(&g_r_m, &g_i_m, &g_e);
1318
250M
    FIXP_DBL energy = fPow2AddDiv2(fPow2Div2(g_r_m), g_i_m);
1319
250M
    factor_e = 2 * g_e + 1;
1320
1321
250M
    switch (stretch) {
1322
112M
      case 2:
1323
112M
        factor_m = invFourthRootNorm2(energy, &factor_e);
1324
112M
        break;
1325
103M
      case 3:
1326
103M
        factor_m = invCubeRootNorm2(energy, &factor_e);
1327
103M
        break;
1328
35.2M
      case 4:
1329
35.2M
        factor_m = inv3EigthRootNorm2(energy, &factor_e);
1330
35.2M
        break;
1331
250M
    }
1332
1333
250M
    factor_m = fMult(factor_m, mult);
1334
1335
250M
    FIXP_DBL tmp_r, tmp_i;
1336
250M
    cplxMultDiv2(&tmp_r, &tmp_i, g_r_m, g_i_m, gammaCenterReal_m,
1337
250M
                 gammaCenterImag_m);
1338
1339
250M
    g_r_m = fMultDiv2(tmp_r, factor_m) << shift;
1340
250M
    g_i_m = fMultDiv2(tmp_i, factor_m) << shift;
1341
250M
    g_e = scale_factor_hbe - (g_e + factor_e + gammaCenter_e + add);
1342
250M
    g_e = fMax((INT)0, g_e);
1343
250M
    *qmfHBEBufReal_F += g_r_m >> g_e;
1344
250M
    *qmfHBEBufImag_F += g_i_m >> g_e;
1345
250M
  }
1346
465M
}
1347
1348
void QmfTransposerApply(HANDLE_HBE_TRANSPOSER hQmfTransposer,
1349
                        FIXP_DBL** qmfBufferCodecReal,
1350
                        FIXP_DBL** qmfBufferCodecImag, int nColsIn,
1351
                        FIXP_DBL** ppQmfBufferOutReal_F,
1352
                        FIXP_DBL** ppQmfBufferOutImag_F,
1353
                        FIXP_DBL lpcFilterStatesReal[2 + (3 * (4))][(64)],
1354
                        FIXP_DBL lpcFilterStatesImag[2 + (3 * (4))][(64)],
1355
                        int pitchInBins, int scale_lb, int scale_hbe,
1356
                        int* scale_hb, int timeStep, int firstSlotOffsset,
1357
                        int ov_len,
1358
90.9k
                        KEEP_STATES_SYNCED_MODE keepStatesSyncedMode) {
1359
90.9k
  int i, j, stretch, band, sourceband, r, s;
1360
90.9k
  int qmfVocoderColsIn = hQmfTransposer->noCols / 2;
1361
90.9k
  int bSbr41 = hQmfTransposer->bSbr41;
1362
1363
90.9k
  const int winLength[3] = {10, 8, 6};
1364
90.9k
  const int slotOffset = 6; /* hQmfTransposer->winLen-6; */
1365
1366
90.9k
  int qmfOffset = 2 * hQmfTransposer->kstart;
1367
90.9k
  int scale_border = (nColsIn == 64) ? 32 : nColsIn;
1368
1369
90.9k
  INT slot_stretch4[9] = {0, 0, 0, 0, 2, 4, 6, 8, 10};
1370
90.9k
  INT slot_stretch2[11] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
1371
90.9k
  INT slot_stretch3[10] = {0, 0, 0, 1, 3, 4, 6, 7, 9, 10};
1372
90.9k
  INT filt_stretch3[10] = {0, 0, 0, 1, 0, 1, 0, 1, 0, 1};
1373
90.9k
  INT filt_dummy[11] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
1374
90.9k
  INT* pSlotStretch;
1375
90.9k
  INT* pFilt;
1376
1377
90.9k
  int offset = 0; /* where to take  QmfTransposer data */
1378
1379
90.9k
  int signPreMod =
1380
90.9k
      (hQmfTransposer->synthesisQmfPreModCos_F[0] < FL2FXCONST_DBL(0.f)) ? 1
1381
90.9k
                                                                         : -1;
1382
1383
90.9k
  int scale_factor_hbe =
1384
90.9k
      getHBEScaleFactorFrame(bSbr41, hQmfTransposer->maxStretch, pitchInBins);
1385
1386
90.9k
  if (keepStatesSyncedMode != KEEP_STATES_SYNCED_OFF) {
1387
56.6k
    offset = hQmfTransposer->noCols - ov_len - LPC_ORDER;
1388
56.6k
  }
1389
1390
90.9k
  hQmfTransposer->highband_exp[0] = hQmfTransposer->highband_exp[1];
1391
90.9k
  hQmfTransposer->target_exp[0] = hQmfTransposer->target_exp[1];
1392
1393
90.9k
  hQmfTransposer->highband_exp[1] = scale_factor_hbe;
1394
90.9k
  hQmfTransposer->target_exp[1] =
1395
90.9k
      fixMax(hQmfTransposer->highband_exp[1], hQmfTransposer->highband_exp[0]);
1396
1397
90.9k
  scale_factor_hbe = hQmfTransposer->target_exp[1];
1398
1399
90.9k
  int shift_ov = hQmfTransposer->target_exp[0] - hQmfTransposer->target_exp[1];
1400
1401
90.9k
  if (shift_ov != 0) {
1402
333k
    for (i = 0; i < HBE_MAX_OUT_SLOTS; i++) {
1403
305k
      scaleValuesSaturate(&hQmfTransposer->qmfHBEBufReal_F[i][0],
1404
305k
                          QMF_SYNTH_CHANNELS, shift_ov);
1405
305k
      scaleValuesSaturate(&hQmfTransposer->qmfHBEBufImag_F[i][0],
1406
305k
                          QMF_SYNTH_CHANNELS, shift_ov);
1407
305k
    }
1408
1409
27.7k
    if (keepStatesSyncedMode == KEEP_STATES_SYNCED_OFF) {
1410
3.11k
      int nBands =
1411
3.11k
          fMax(0, hQmfTransposer->stopBand - hQmfTransposer->startBand);
1412
1413
17.0k
      for (i = timeStep * firstSlotOffsset; i < ov_len; i++) {
1414
13.9k
        scaleValuesSaturate(&ppQmfBufferOutReal_F[i][hQmfTransposer->startBand],
1415
13.9k
                            nBands, shift_ov);
1416
13.9k
        scaleValuesSaturate(&ppQmfBufferOutImag_F[i][hQmfTransposer->startBand],
1417
13.9k
                            nBands, shift_ov);
1418
13.9k
      }
1419
1420
      /* shift lpc filterstates */
1421
16.9k
      for (i = 0; i < timeStep * firstSlotOffsset + LPC_ORDER; i++) {
1422
13.8k
        scaleValuesSaturate(&lpcFilterStatesReal[i][0], (64), shift_ov);
1423
13.8k
        scaleValuesSaturate(&lpcFilterStatesImag[i][0], (64), shift_ov);
1424
13.8k
      }
1425
3.11k
    }
1426
27.7k
  }
1427
1428
90.9k
  FIXP_DBL twid_m_new[3][2]; /* [stretch][cos/sin] */
1429
90.9k
  INT stepsize = 1 + !bSbr41, sine_offset = 24, mod = 96;
1430
90.9k
  INT mult[3] = {1, 2, 3};
1431
1432
363k
  for (s = 0; s <= MAX_STRETCH_HBE - 2; s++) {
1433
272k
    twid_m_new[s][0] = twiddle[(mult[s] * (stepsize * pitchInBins)) % mod];
1434
272k
    twid_m_new[s][1] =
1435
272k
        twiddle[((mult[s] * (stepsize * pitchInBins)) + sine_offset) % mod];
1436
272k
  }
1437
1438
  /* Time-stretch */
1439
2.07M
  for (j = 0; j < qmfVocoderColsIn; j++) {
1440
1.98M
    int sign = -1, k, z, addrshift, codecTemp_e;
1441
    /* update inbuf */
1442
26.3M
    for (i = 0; i < hQmfTransposer->synthSize; i++) {
1443
24.3M
      hQmfTransposer->inBuf_F[i] =
1444
24.3M
          hQmfTransposer->inBuf_F[i + 2 * hQmfTransposer->synthSize];
1445
24.3M
    }
1446
1447
    /* run synthesis for two sbr slots as transposer uses
1448
    half slots double bands representation */
1449
5.94M
    for (z = 0; z < 2; z++) {
1450
3.96M
      int scale_factor = ((nColsIn == 64) && ((2 * j + z) < scale_border))
1451
3.96M
                             ? scale_lb
1452
3.96M
                             : scale_hbe;
1453
3.96M
      codecTemp_e = scale_factor - 1; /* -2 for Div2 and cos/sin scale of 1 */
1454
1455
52.7M
      for (k = 0; k < hQmfTransposer->synthSize; k++) {
1456
48.7M
        int ki = hQmfTransposer->kstart + k;
1457
48.7M
        hQmfTransposer->qmfBufferCodecTempSlot_F[k] =
1458
48.7M
            fMultDiv2(signPreMod * hQmfTransposer->synthesisQmfPreModCos_F[k],
1459
48.7M
                      qmfBufferCodecReal[2 * j + z][ki]);
1460
48.7M
        hQmfTransposer->qmfBufferCodecTempSlot_F[k] +=
1461
48.7M
            fMultDiv2(signPreMod * hQmfTransposer->synthesisQmfPreModSin_F[k],
1462
48.7M
                      qmfBufferCodecImag[2 * j + z][ki]);
1463
48.7M
      }
1464
1465
3.96M
      C_AALLOC_SCRATCH_START(pWorkBuffer, FIXP_DBL, (HBE_MAX_QMF_BANDS << 1));
1466
1467
3.96M
      qmfSynthesisFilteringSlot(
1468
3.96M
          &hQmfTransposer->HBESynthesisQMF,
1469
3.96M
          hQmfTransposer->qmfBufferCodecTempSlot_F, NULL, 0,
1470
3.96M
          -7 - hQmfTransposer->HBESynthesisQMF.filterScale - codecTemp_e + 1,
1471
3.96M
          hQmfTransposer->inBuf_F + hQmfTransposer->synthSize * (z + 1), 1,
1472
3.96M
          pWorkBuffer);
1473
1474
3.96M
      C_AALLOC_SCRATCH_END(pWorkBuffer, FIXP_DBL, (HBE_MAX_QMF_BANDS << 1));
1475
3.96M
    }
1476
1477
1.98M
    C_AALLOC_SCRATCH_START(pWorkBuffer, FIXP_DBL, (HBE_MAX_QMF_BANDS << 1));
1478
1479
1.98M
    qmfAnalysisFilteringSlot(&hQmfTransposer->HBEAnalysiscQMF,
1480
1.98M
                             hQmfTransposer->qmfInBufReal_F[QMF_WIN_LEN - 1],
1481
1.98M
                             hQmfTransposer->qmfInBufImag_F[QMF_WIN_LEN - 1],
1482
1.98M
                             hQmfTransposer->inBuf_F + 1, 1, pWorkBuffer);
1483
1484
1.98M
    C_AALLOC_SCRATCH_END(pWorkBuffer, FIXP_DBL, (HBE_MAX_QMF_BANDS << 1));
1485
1486
1.98M
    if ((keepStatesSyncedMode == KEEP_STATES_SYNCED_NORMAL) &&
1487
545k
        j <= qmfVocoderColsIn - ((LPC_ORDER + ov_len + QMF_WIN_LEN - 1) >> 1)) {
1488
      /* update in buffer */
1489
3.72M
      for (i = 0; i < QMF_WIN_LEN - 1; i++) {
1490
3.43M
        FDKmemcpy(
1491
3.43M
            hQmfTransposer->qmfInBufReal_F[i],
1492
3.43M
            hQmfTransposer->qmfInBufReal_F[i + 1],
1493
3.43M
            sizeof(FIXP_DBL) * hQmfTransposer->HBEAnalysiscQMF.no_channels);
1494
3.43M
        FDKmemcpy(
1495
3.43M
            hQmfTransposer->qmfInBufImag_F[i],
1496
3.43M
            hQmfTransposer->qmfInBufImag_F[i + 1],
1497
3.43M
            sizeof(FIXP_DBL) * hQmfTransposer->HBEAnalysiscQMF.no_channels);
1498
3.43M
      }
1499
286k
      continue;
1500
286k
    }
1501
1502
5.64M
    for (stretch = 2; stretch <= hQmfTransposer->maxStretch; stretch++) {
1503
3.94M
      int start = slotOffset - winLength[stretch - 2] / 2;
1504
3.94M
      int stop = slotOffset + winLength[stretch - 2] / 2;
1505
1506
3.94M
      FIXP_DBL factor = FL2FXCONST_DBL(1.f / 3.f);
1507
1508
3.94M
      for (band = hQmfTransposer->xOverQmf[stretch - 2];
1509
54.2M
           band < hQmfTransposer->xOverQmf[stretch - 1]; band++) {
1510
50.3M
        FIXP_DBL gammaCenterReal_m[2] = {(FIXP_DBL)0, (FIXP_DBL)0},
1511
50.3M
                 gammaCenterImag_m[2] = {(FIXP_DBL)0, (FIXP_DBL)0};
1512
50.3M
        INT gammaCenter_e[2] = {0, 0};
1513
1514
50.3M
        FIXP_DBL gammaVecReal_m[2] = {(FIXP_DBL)0, (FIXP_DBL)0},
1515
50.3M
                 gammaVecImag_m[2] = {(FIXP_DBL)0, (FIXP_DBL)0};
1516
50.3M
        INT gammaVec_e[2] = {0, 0};
1517
1518
50.3M
        FIXP_DBL wingain = (FIXP_DBL)0;
1519
1520
50.3M
        gammaCenter_e[0] =
1521
50.3M
            SCALE2EXP(-hQmfTransposer->HBEAnalysiscQMF.outScalefactor);
1522
50.3M
        gammaCenter_e[1] =
1523
50.3M
            SCALE2EXP(-hQmfTransposer->HBEAnalysiscQMF.outScalefactor);
1524
1525
        /* interpolation filters for 3rd order */
1526
50.3M
        sourceband = 2 * band / stretch - qmfOffset;
1527
50.3M
        FDK_ASSERT(sourceband >= 0);
1528
1529
        /* maximum gammaCenter_e == 20 */
1530
50.3M
        calculateCenterFIXP(
1531
50.3M
            hQmfTransposer->qmfInBufReal_F[slotOffset][sourceband],
1532
50.3M
            hQmfTransposer->qmfInBufImag_F[slotOffset][sourceband],
1533
50.3M
            &gammaCenterReal_m[0], &gammaCenterImag_m[0], &gammaCenter_e[0],
1534
50.3M
            stretch, stretch - 2);
1535
1536
50.3M
        if (stretch == 4) {
1537
12.5M
          r = band - 2 * (band / 2);
1538
12.5M
          sourceband += (r == 0) ? -1 : 1;
1539
12.5M
          pSlotStretch = slot_stretch4;
1540
12.5M
          factor = FL2FXCONST_DBL(2.f / 3.f);
1541
12.5M
          pFilt = filt_dummy;
1542
37.8M
        } else if (stretch == 2) {
1543
20.1M
          r = 0;
1544
20.1M
          sourceband = 2 * band / stretch - qmfOffset;
1545
20.1M
          pSlotStretch = slot_stretch2;
1546
20.1M
          factor = FL2FXCONST_DBL(1.f / 3.f);
1547
20.1M
          pFilt = filt_dummy;
1548
20.1M
        } else {
1549
17.6M
          r = 2 * band - 3 * (2 * band / 3);
1550
17.6M
          sourceband = 2 * band / stretch - qmfOffset;
1551
17.6M
          pSlotStretch = slot_stretch3;
1552
17.6M
          factor = FL2FXCONST_DBL(1.4142f / 3.0f);
1553
17.6M
          pFilt = filt_stretch3;
1554
17.6M
        }
1555
1556
50.3M
        if (r == 2) {
1557
5.93M
          calculateCenterFIXP(
1558
5.93M
              hQmfTransposer->qmfInBufReal_F[slotOffset][sourceband + 1],
1559
5.93M
              hQmfTransposer->qmfInBufImag_F[slotOffset][sourceband + 1],
1560
5.93M
              &gammaCenterReal_m[1], &gammaCenterImag_m[1], &gammaCenter_e[1],
1561
5.93M
              stretch, stretch - 2);
1562
1563
5.93M
          factor = FL2FXCONST_DBL(1.4142f / 6.0f);
1564
5.93M
        }
1565
1566
50.3M
        if (r == 2) {
1567
53.3M
          for (k = start; k < stop; k++) {
1568
47.4M
            gammaVecReal_m[0] =
1569
47.4M
                hQmfTransposer->qmfInBufReal_F[pSlotStretch[k]][sourceband];
1570
47.4M
            gammaVecReal_m[1] =
1571
47.4M
                hQmfTransposer->qmfInBufReal_F[pSlotStretch[k]][sourceband + 1];
1572
47.4M
            gammaVecImag_m[0] =
1573
47.4M
                hQmfTransposer->qmfInBufImag_F[pSlotStretch[k]][sourceband];
1574
47.4M
            gammaVecImag_m[1] =
1575
47.4M
                hQmfTransposer->qmfInBufImag_F[pSlotStretch[k]][sourceband + 1];
1576
47.4M
            gammaVec_e[0] = gammaVec_e[1] =
1577
47.4M
                SCALE2EXP(-hQmfTransposer->HBEAnalysiscQMF.outScalefactor);
1578
1579
47.4M
            if (pFilt[k] == 1) {
1580
23.7M
              FIXP_DBL tmpRealF = gammaVecReal_m[0], tmpImagF;
1581
23.7M
              gammaVecReal_m[0] =
1582
23.7M
                  (fMult(gammaVecReal_m[0], hintReal_F[sourceband % 4][1]) -
1583
23.7M
                   fMult(gammaVecImag_m[0],
1584
23.7M
                         hintReal_F[(sourceband + 3) % 4][1])) >>
1585
23.7M
                  1; /* sum should be <= 1 because of sin/cos multiplication */
1586
23.7M
              gammaVecImag_m[0] =
1587
23.7M
                  (fMult(tmpRealF, hintReal_F[(sourceband + 3) % 4][1]) +
1588
23.7M
                   fMult(gammaVecImag_m[0], hintReal_F[sourceband % 4][1])) >>
1589
23.7M
                  1; /* sum should be <= 1 because of sin/cos multiplication */
1590
1591
23.7M
              tmpRealF = hQmfTransposer
1592
23.7M
                             ->qmfInBufReal_F[pSlotStretch[k] + 1][sourceband];
1593
23.7M
              tmpImagF = hQmfTransposer
1594
23.7M
                             ->qmfInBufImag_F[pSlotStretch[k] + 1][sourceband];
1595
1596
23.7M
              gammaVecReal_m[0] +=
1597
23.7M
                  (fMult(tmpRealF, hintReal_F[sourceband % 4][1]) -
1598
23.7M
                   fMult(tmpImagF, hintReal_F[(sourceband + 1) % 4][1])) >>
1599
23.7M
                  1; /* sum should be <= 1 because of sin/cos multiplication */
1600
23.7M
              gammaVecImag_m[0] +=
1601
23.7M
                  (fMult(tmpRealF, hintReal_F[(sourceband + 1) % 4][1]) +
1602
23.7M
                   fMult(tmpImagF, hintReal_F[sourceband % 4][1])) >>
1603
23.7M
                  1; /* sum should be <= 1 because of sin/cos multiplication */
1604
23.7M
              gammaVec_e[0]++;
1605
1606
23.7M
              tmpRealF = gammaVecReal_m[1];
1607
1608
23.7M
              gammaVecReal_m[1] =
1609
23.7M
                  (fMult(gammaVecReal_m[1], hintReal_F[sourceband % 4][2]) -
1610
23.7M
                   fMult(gammaVecImag_m[1],
1611
23.7M
                         hintReal_F[(sourceband + 3) % 4][2])) >>
1612
23.7M
                  1;
1613
23.7M
              gammaVecImag_m[1] =
1614
23.7M
                  (fMult(tmpRealF, hintReal_F[(sourceband + 3) % 4][2]) +
1615
23.7M
                   fMult(gammaVecImag_m[1], hintReal_F[sourceband % 4][2])) >>
1616
23.7M
                  1;
1617
1618
23.7M
              tmpRealF =
1619
23.7M
                  hQmfTransposer
1620
23.7M
                      ->qmfInBufReal_F[pSlotStretch[k] + 1][sourceband + 1];
1621
23.7M
              tmpImagF =
1622
23.7M
                  hQmfTransposer
1623
23.7M
                      ->qmfInBufImag_F[pSlotStretch[k] + 1][sourceband + 1];
1624
1625
23.7M
              gammaVecReal_m[1] +=
1626
23.7M
                  (fMult(tmpRealF, hintReal_F[sourceband % 4][2]) -
1627
23.7M
                   fMult(tmpImagF, hintReal_F[(sourceband + 1) % 4][2])) >>
1628
23.7M
                  1;
1629
23.7M
              gammaVecImag_m[1] +=
1630
23.7M
                  (fMult(tmpRealF, hintReal_F[(sourceband + 1) % 4][2]) +
1631
23.7M
                   fMult(tmpImagF, hintReal_F[sourceband % 4][2])) >>
1632
23.7M
                  1;
1633
23.7M
              gammaVec_e[1]++;
1634
23.7M
            }
1635
1636
47.4M
            addHighBandPart(gammaVecReal_m[1], gammaVecImag_m[1], gammaVec_e[1],
1637
47.4M
                            factor, gammaCenterReal_m[0], gammaCenterImag_m[0],
1638
47.4M
                            gammaCenter_e[0], stretch, scale_factor_hbe,
1639
47.4M
                            &hQmfTransposer->qmfHBEBufReal_F[k][band],
1640
47.4M
                            &hQmfTransposer->qmfHBEBufImag_F[k][band]);
1641
1642
47.4M
            addHighBandPart(gammaVecReal_m[0], gammaVecImag_m[0], gammaVec_e[0],
1643
47.4M
                            factor, gammaCenterReal_m[1], gammaCenterImag_m[1],
1644
47.4M
                            gammaCenter_e[1], stretch, scale_factor_hbe,
1645
47.4M
                            &hQmfTransposer->qmfHBEBufReal_F[k][band],
1646
47.4M
                            &hQmfTransposer->qmfHBEBufImag_F[k][band]);
1647
47.4M
          }
1648
44.3M
        } else {
1649
414M
          for (k = start; k < stop; k++) {
1650
370M
            gammaVecReal_m[0] =
1651
370M
                hQmfTransposer->qmfInBufReal_F[pSlotStretch[k]][sourceband];
1652
370M
            gammaVecImag_m[0] =
1653
370M
                hQmfTransposer->qmfInBufImag_F[pSlotStretch[k]][sourceband];
1654
370M
            gammaVec_e[0] =
1655
370M
                SCALE2EXP(-hQmfTransposer->HBEAnalysiscQMF.outScalefactor);
1656
1657
370M
            if (pFilt[k] == 1) {
1658
46.8M
              FIXP_DBL tmpRealF = gammaVecReal_m[0], tmpImagF;
1659
46.8M
              gammaVecReal_m[0] =
1660
46.8M
                  (fMult(gammaVecReal_m[0], hintReal_F[sourceband % 4][1]) -
1661
46.8M
                   fMult(gammaVecImag_m[0],
1662
46.8M
                         hintReal_F[(sourceband + 3) % 4][1])) >>
1663
46.8M
                  1; /* sum should be <= 1 because of sin/cos multiplication */
1664
46.8M
              gammaVecImag_m[0] =
1665
46.8M
                  (fMult(tmpRealF, hintReal_F[(sourceband + 3) % 4][1]) +
1666
46.8M
                   fMult(gammaVecImag_m[0], hintReal_F[sourceband % 4][1])) >>
1667
46.8M
                  1; /* sum should be <= 1 because of sin/cos multiplication */
1668
1669
46.8M
              tmpRealF = hQmfTransposer
1670
46.8M
                             ->qmfInBufReal_F[pSlotStretch[k] + 1][sourceband];
1671
46.8M
              tmpImagF = hQmfTransposer
1672
46.8M
                             ->qmfInBufImag_F[pSlotStretch[k] + 1][sourceband];
1673
1674
46.8M
              gammaVecReal_m[0] +=
1675
46.8M
                  (fMult(tmpRealF, hintReal_F[sourceband % 4][1]) -
1676
46.8M
                   fMult(tmpImagF, hintReal_F[(sourceband + 1) % 4][1])) >>
1677
46.8M
                  1; /* sum should be <= 1 because of sin/cos multiplication */
1678
46.8M
              gammaVecImag_m[0] +=
1679
46.8M
                  (fMult(tmpRealF, hintReal_F[(sourceband + 1) % 4][1]) +
1680
46.8M
                   fMult(tmpImagF, hintReal_F[sourceband % 4][1])) >>
1681
46.8M
                  1; /* sum should be <= 1 because of sin/cos multiplication */
1682
46.8M
              gammaVec_e[0]++;
1683
46.8M
            }
1684
1685
370M
            addHighBandPart(gammaVecReal_m[0], gammaVecImag_m[0], gammaVec_e[0],
1686
370M
                            factor, gammaCenterReal_m[0], gammaCenterImag_m[0],
1687
370M
                            gammaCenter_e[0], stretch, scale_factor_hbe,
1688
370M
                            &hQmfTransposer->qmfHBEBufReal_F[k][band],
1689
370M
                            &hQmfTransposer->qmfHBEBufImag_F[k][band]);
1690
370M
          }
1691
44.3M
        }
1692
1693
        /* pitchInBins is given with the resolution of a 768 bins FFT and we
1694
         * need 64 QMF units so factor 768/64 = 12 */
1695
50.3M
        if (pitchInBins >= pmin * (1 + bSbr41)) {
1696
5.26M
          int tr, ti1, ti2, mTr = 0, ts1 = 0, ts2 = 0, mVal_e = 0, temp_e = 0;
1697
5.26M
          int sqmag0_e =
1698
5.26M
              SCALE2EXP(-hQmfTransposer->HBEAnalysiscQMF.outScalefactor);
1699
1700
5.26M
          FIXP_DBL mVal_F = FL2FXCONST_DBL(0.f), sqmag0_F, sqmag1_F, sqmag2_F,
1701
5.26M
                   temp_F, f1_F; /* all equal exponent */
1702
5.26M
          sign = -1;
1703
1704
5.26M
          sourceband = 2 * band / stretch - qmfOffset; /* consistent with the
1705
                                                          already computed for
1706
                                                          stretch = 3,4. */
1707
5.26M
          FDK_ASSERT(sourceband >= 0);
1708
1709
5.26M
          FIXP_DBL sqmag0R_F =
1710
5.26M
              hQmfTransposer->qmfInBufReal_F[slotOffset][sourceband];
1711
5.26M
          FIXP_DBL sqmag0I_F =
1712
5.26M
              hQmfTransposer->qmfInBufImag_F[slotOffset][sourceband];
1713
5.26M
          scaleUp(&sqmag0R_F, &sqmag0I_F, &sqmag0_e);
1714
1715
5.26M
          sqmag0_F = fPow2Div2(sqmag0R_F);
1716
5.26M
          sqmag0_F += fPow2Div2(sqmag0I_F);
1717
5.26M
          sqmag0_e = 2 * sqmag0_e + 1;
1718
1719
14.5M
          for (tr = 1; tr < stretch; tr++) {
1720
9.29M
            int sqmag1_e =
1721
9.29M
                SCALE2EXP(-hQmfTransposer->HBEAnalysiscQMF.outScalefactor);
1722
9.29M
            int sqmag2_e =
1723
9.29M
                SCALE2EXP(-hQmfTransposer->HBEAnalysiscQMF.outScalefactor);
1724
1725
9.29M
            FIXP_DBL tmp_band = band_F[band];
1726
9.29M
            FIXP_DBL tr_p =
1727
9.29M
                fMult(p_F[pitchInBins] >> bSbr41, tr_str[tr - 1]); /* scale 7 */
1728
9.29M
            f1_F =
1729
9.29M
                fMult(tmp_band - tr_p, stretchfac[stretch - 2]); /* scale 7 */
1730
9.29M
            ti1 = (INT)(f1_F >> (DFRACT_BITS - 1 - 7)) - qmfOffset;
1731
9.29M
            ti2 = (INT)(((f1_F) + ((p_F[pitchInBins] >> bSbr41) >> 2)) >>
1732
9.29M
                        (DFRACT_BITS - 1 - 7)) -
1733
9.29M
                  qmfOffset;
1734
1735
9.29M
            if (ti1 >= 0 && ti2 < 2 * hQmfTransposer->synthSize) {
1736
9.07M
              FIXP_DBL sqmag1R_F =
1737
9.07M
                  hQmfTransposer->qmfInBufReal_F[slotOffset][ti1];
1738
9.07M
              FIXP_DBL sqmag1I_F =
1739
9.07M
                  hQmfTransposer->qmfInBufImag_F[slotOffset][ti1];
1740
9.07M
              scaleUp(&sqmag1R_F, &sqmag1I_F, &sqmag1_e);
1741
9.07M
              sqmag1_F = fPow2Div2(sqmag1R_F);
1742
9.07M
              sqmag1_F += fPow2Div2(sqmag1I_F);
1743
9.07M
              sqmag1_e = 2 * sqmag1_e + 1;
1744
1745
9.07M
              FIXP_DBL sqmag2R_F =
1746
9.07M
                  hQmfTransposer->qmfInBufReal_F[slotOffset][ti2];
1747
9.07M
              FIXP_DBL sqmag2I_F =
1748
9.07M
                  hQmfTransposer->qmfInBufImag_F[slotOffset][ti2];
1749
9.07M
              scaleUp(&sqmag2R_F, &sqmag2I_F, &sqmag2_e);
1750
9.07M
              sqmag2_F = fPow2Div2(sqmag2R_F);
1751
9.07M
              sqmag2_F += fPow2Div2(sqmag2I_F);
1752
9.07M
              sqmag2_e = 2 * sqmag2_e + 1;
1753
1754
9.07M
              int shift1 = fMin(fMax(sqmag1_e, sqmag2_e) - sqmag1_e, 31);
1755
9.07M
              int shift2 = fMin(fMax(sqmag1_e, sqmag2_e) - sqmag2_e, 31);
1756
1757
9.07M
              temp_F = fMin((sqmag1_F >> shift1), (sqmag2_F >> shift2));
1758
9.07M
              temp_e = fMax(sqmag1_e, sqmag2_e);
1759
1760
9.07M
              int shift3 = fMin(fMax(temp_e, mVal_e) - temp_e, 31);
1761
9.07M
              int shift4 = fMin(fMax(temp_e, mVal_e) - mVal_e, 31);
1762
1763
9.07M
              if ((temp_F >> shift3) > (mVal_F >> shift4)) {
1764
3.87M
                mVal_F = temp_F;
1765
3.87M
                mVal_e = temp_e; /* equals sqmag2_e + shift2 */
1766
3.87M
                mTr = tr;
1767
3.87M
                ts1 = ti1;
1768
3.87M
                ts2 = ti2;
1769
3.87M
              }
1770
9.07M
            }
1771
9.29M
          }
1772
1773
5.26M
          int shift1 = fMin(fMax(sqmag0_e, mVal_e) - sqmag0_e, 31);
1774
5.26M
          int shift2 = fMin(fMax(sqmag0_e, mVal_e) - mVal_e, 31);
1775
1776
5.26M
          if ((mVal_F >> shift2) > (sqmag0_F >> shift1) && ts1 >= 0 &&
1777
1.12M
              ts2 < 2 * hQmfTransposer->synthSize) {
1778
1.12M
            INT gammaOut_e[2];
1779
1.12M
            FIXP_DBL gammaOutReal_m[2], gammaOutImag_m[2];
1780
1.12M
            FIXP_DBL tmpReal_m = (FIXP_DBL)0, tmpImag_m = (FIXP_DBL)0;
1781
1782
1.12M
            int Tcenter, Tvec;
1783
1784
1.12M
            Tcenter = stretch - mTr; /* default phase power parameters */
1785
1.12M
            Tvec = mTr;
1786
1.12M
            switch (stretch) /* 2 tap block creation design depends on stretch
1787
                                order */
1788
1.12M
            {
1789
344k
              case 2:
1790
344k
                wingain =
1791
344k
                    FL2FXCONST_DBL(5.f / 12.f); /* sum of taps divided by two */
1792
1793
344k
                if (hQmfTransposer->bXProducts[0]) {
1794
344k
                  gammaCenterReal_m[0] =
1795
344k
                      hQmfTransposer->qmfInBufReal_F[slotOffset][ts1];
1796
344k
                  gammaCenterImag_m[0] =
1797
344k
                      hQmfTransposer->qmfInBufImag_F[slotOffset][ts1];
1798
1799
1.03M
                  for (k = 0; k < 2; k++) {
1800
689k
                    gammaVecReal_m[k] =
1801
689k
                        hQmfTransposer->qmfInBufReal_F[slotOffset - 1 + k][ts2];
1802
689k
                    gammaVecImag_m[k] =
1803
689k
                        hQmfTransposer->qmfInBufImag_F[slotOffset - 1 + k][ts2];
1804
689k
                  }
1805
1806
344k
                  gammaCenter_e[0] = SCALE2EXP(
1807
344k
                      -hQmfTransposer->HBEAnalysiscQMF.outScalefactor);
1808
344k
                  gammaVec_e[0] = gammaVec_e[1] = SCALE2EXP(
1809
344k
                      -hQmfTransposer->HBEAnalysiscQMF.outScalefactor);
1810
344k
                }
1811
344k
                break;
1812
1813
334k
              case 4:
1814
334k
                wingain =
1815
334k
                    FL2FXCONST_DBL(6.f / 12.f); /* sum of taps divided by two */
1816
334k
                if (hQmfTransposer->bXProducts[2]) {
1817
334k
                  if (mTr == 1) {
1818
111k
                    gammaCenterReal_m[0] =
1819
111k
                        hQmfTransposer->qmfInBufReal_F[slotOffset][ts1];
1820
111k
                    gammaCenterImag_m[0] =
1821
111k
                        hQmfTransposer->qmfInBufImag_F[slotOffset][ts1];
1822
1823
334k
                    for (k = 0; k < 2; k++) {
1824
222k
                      gammaVecReal_m[k] =
1825
222k
                          hQmfTransposer
1826
222k
                              ->qmfInBufReal_F[slotOffset + 2 * (k - 1)][ts2];
1827
222k
                      gammaVecImag_m[k] =
1828
222k
                          hQmfTransposer
1829
222k
                              ->qmfInBufImag_F[slotOffset + 2 * (k - 1)][ts2];
1830
222k
                    }
1831
223k
                  } else if (mTr == 2) {
1832
129k
                    gammaCenterReal_m[0] =
1833
129k
                        hQmfTransposer->qmfInBufReal_F[slotOffset][ts1];
1834
129k
                    gammaCenterImag_m[0] =
1835
129k
                        hQmfTransposer->qmfInBufImag_F[slotOffset][ts1];
1836
1837
389k
                    for (k = 0; k < 2; k++) {
1838
259k
                      gammaVecReal_m[k] =
1839
259k
                          hQmfTransposer
1840
259k
                              ->qmfInBufReal_F[slotOffset + (k - 1)][ts2];
1841
259k
                      gammaVecImag_m[k] =
1842
259k
                          hQmfTransposer
1843
259k
                              ->qmfInBufImag_F[slotOffset + (k - 1)][ts2];
1844
259k
                    }
1845
129k
                  } else /* (mTr == 3) */
1846
93.5k
                  {
1847
93.5k
                    sign = 1;
1848
93.5k
                    Tcenter = mTr; /* opposite phase power parameters as ts2 is
1849
                                      center */
1850
93.5k
                    Tvec = stretch - mTr;
1851
1852
93.5k
                    gammaCenterReal_m[0] =
1853
93.5k
                        hQmfTransposer->qmfInBufReal_F[slotOffset][ts2];
1854
93.5k
                    gammaCenterImag_m[0] =
1855
93.5k
                        hQmfTransposer->qmfInBufImag_F[slotOffset][ts2];
1856
1857
280k
                    for (k = 0; k < 2; k++) {
1858
187k
                      gammaVecReal_m[k] =
1859
187k
                          hQmfTransposer
1860
187k
                              ->qmfInBufReal_F[slotOffset + 2 * (k - 1)][ts1];
1861
187k
                      gammaVecImag_m[k] =
1862
187k
                          hQmfTransposer
1863
187k
                              ->qmfInBufImag_F[slotOffset + 2 * (k - 1)][ts1];
1864
187k
                    }
1865
93.5k
                  }
1866
1867
334k
                  gammaCenter_e[0] = SCALE2EXP(
1868
334k
                      -hQmfTransposer->HBEAnalysiscQMF.outScalefactor);
1869
334k
                  gammaVec_e[0] = gammaVec_e[1] = SCALE2EXP(
1870
334k
                      -hQmfTransposer->HBEAnalysiscQMF.outScalefactor);
1871
334k
                }
1872
334k
                break;
1873
1874
449k
              case 3:
1875
449k
                wingain = FL2FXCONST_DBL(5.6568f /
1876
449k
                                         12.f); /* sum of taps divided by two */
1877
1878
449k
                if (hQmfTransposer->bXProducts[1]) {
1879
449k
                  FIXP_DBL tmpReal_F, tmpImag_F;
1880
449k
                  if (mTr == 1) {
1881
201k
                    gammaCenterReal_m[0] =
1882
201k
                        hQmfTransposer->qmfInBufReal_F[slotOffset][ts1];
1883
201k
                    gammaCenterImag_m[0] =
1884
201k
                        hQmfTransposer->qmfInBufImag_F[slotOffset][ts1];
1885
201k
                    gammaVecReal_m[1] =
1886
201k
                        hQmfTransposer->qmfInBufReal_F[slotOffset][ts2];
1887
201k
                    gammaVecImag_m[1] =
1888
201k
                        hQmfTransposer->qmfInBufImag_F[slotOffset][ts2];
1889
1890
201k
                    addrshift = -2;
1891
201k
                    tmpReal_F =
1892
201k
                        hQmfTransposer
1893
201k
                            ->qmfInBufReal_F[addrshift + slotOffset][ts2];
1894
201k
                    tmpImag_F =
1895
201k
                        hQmfTransposer
1896
201k
                            ->qmfInBufImag_F[addrshift + slotOffset][ts2];
1897
1898
201k
                    gammaVecReal_m[0] =
1899
201k
                        (fMult(factors[ts2 % 4], tmpReal_F) -
1900
201k
                         fMult(factors[(ts2 + 3) % 4], tmpImag_F)) >>
1901
201k
                        1;
1902
201k
                    gammaVecImag_m[0] =
1903
201k
                        (fMult(factors[(ts2 + 3) % 4], tmpReal_F) +
1904
201k
                         fMult(factors[ts2 % 4], tmpImag_F)) >>
1905
201k
                        1;
1906
1907
201k
                    tmpReal_F =
1908
201k
                        hQmfTransposer
1909
201k
                            ->qmfInBufReal_F[addrshift + 1 + slotOffset][ts2];
1910
201k
                    tmpImag_F =
1911
201k
                        hQmfTransposer
1912
201k
                            ->qmfInBufImag_F[addrshift + 1 + slotOffset][ts2];
1913
1914
201k
                    gammaVecReal_m[0] +=
1915
201k
                        (fMult(factors[ts2 % 4], tmpReal_F) -
1916
201k
                         fMult(factors[(ts2 + 1) % 4], tmpImag_F)) >>
1917
201k
                        1;
1918
201k
                    gammaVecImag_m[0] +=
1919
201k
                        (fMult(factors[(ts2 + 1) % 4], tmpReal_F) +
1920
201k
                         fMult(factors[ts2 % 4], tmpImag_F)) >>
1921
201k
                        1;
1922
1923
201k
                  } else /* (mTr == 2) */
1924
247k
                  {
1925
247k
                    sign = 1;
1926
247k
                    Tcenter = mTr; /* opposite phase power parameters as ts2 is
1927
                                      center */
1928
247k
                    Tvec = stretch - mTr;
1929
1930
247k
                    gammaCenterReal_m[0] =
1931
247k
                        hQmfTransposer->qmfInBufReal_F[slotOffset][ts2];
1932
247k
                    gammaCenterImag_m[0] =
1933
247k
                        hQmfTransposer->qmfInBufImag_F[slotOffset][ts2];
1934
247k
                    gammaVecReal_m[1] =
1935
247k
                        hQmfTransposer->qmfInBufReal_F[slotOffset][ts1];
1936
247k
                    gammaVecImag_m[1] =
1937
247k
                        hQmfTransposer->qmfInBufImag_F[slotOffset][ts1];
1938
1939
247k
                    addrshift = -2;
1940
247k
                    tmpReal_F =
1941
247k
                        hQmfTransposer
1942
247k
                            ->qmfInBufReal_F[addrshift + slotOffset][ts1];
1943
247k
                    tmpImag_F =
1944
247k
                        hQmfTransposer
1945
247k
                            ->qmfInBufImag_F[addrshift + slotOffset][ts1];
1946
1947
247k
                    gammaVecReal_m[0] =
1948
247k
                        (fMult(factors[ts1 % 4], tmpReal_F) -
1949
247k
                         fMult(factors[(ts1 + 3) % 4], tmpImag_F)) >>
1950
247k
                        1;
1951
247k
                    gammaVecImag_m[0] =
1952
247k
                        (fMult(factors[(ts1 + 3) % 4], tmpReal_F) +
1953
247k
                         fMult(factors[ts1 % 4], tmpImag_F)) >>
1954
247k
                        1;
1955
1956
247k
                    tmpReal_F =
1957
247k
                        hQmfTransposer
1958
247k
                            ->qmfInBufReal_F[addrshift + 1 + slotOffset][ts1];
1959
247k
                    tmpImag_F =
1960
247k
                        hQmfTransposer
1961
247k
                            ->qmfInBufImag_F[addrshift + 1 + slotOffset][ts1];
1962
1963
247k
                    gammaVecReal_m[0] +=
1964
247k
                        (fMult(factors[ts1 % 4], tmpReal_F) -
1965
247k
                         fMult(factors[(ts1 + 1) % 4], tmpImag_F)) >>
1966
247k
                        1;
1967
247k
                    gammaVecImag_m[0] +=
1968
247k
                        (fMult(factors[(ts1 + 1) % 4], tmpReal_F) +
1969
247k
                         fMult(factors[ts1 % 4], tmpImag_F)) >>
1970
247k
                        1;
1971
247k
                  }
1972
1973
449k
                  gammaCenter_e[0] = gammaVec_e[1] = SCALE2EXP(
1974
449k
                      -hQmfTransposer->HBEAnalysiscQMF.outScalefactor);
1975
449k
                  gammaVec_e[0] =
1976
449k
                      SCALE2EXP(
1977
449k
                          -hQmfTransposer->HBEAnalysiscQMF.outScalefactor) +
1978
449k
                      1;
1979
449k
                }
1980
449k
                break;
1981
0
              default:
1982
0
                FDK_ASSERT(0);
1983
0
                break;
1984
1.12M
            } /* stretch cases */
1985
1986
            /* parameter controlled phase modification parts */
1987
            /* maximum *_e == 20 */
1988
1.12M
            calculateCenterFIXP(gammaCenterReal_m[0], gammaCenterImag_m[0],
1989
1.12M
                                &gammaCenterReal_m[0], &gammaCenterImag_m[0],
1990
1.12M
                                &gammaCenter_e[0], stretch, Tcenter - 1);
1991
1.12M
            calculateCenterFIXP(gammaVecReal_m[0], gammaVecImag_m[0],
1992
1.12M
                                &gammaVecReal_m[0], &gammaVecImag_m[0],
1993
1.12M
                                &gammaVec_e[0], stretch, Tvec - 1);
1994
1.12M
            calculateCenterFIXP(gammaVecReal_m[1], gammaVecImag_m[1],
1995
1.12M
                                &gammaVecReal_m[1], &gammaVecImag_m[1],
1996
1.12M
                                &gammaVec_e[1], stretch, Tvec - 1);
1997
1998
            /*    Final multiplication of prepared parts  */
1999
3.38M
            for (k = 0; k < 2; k++) {
2000
2.25M
              gammaOutReal_m[k] =
2001
2.25M
                  fMultDiv2(gammaVecReal_m[k], gammaCenterReal_m[0]) -
2002
2.25M
                  fMultDiv2(gammaVecImag_m[k], gammaCenterImag_m[0]);
2003
2.25M
              gammaOutImag_m[k] =
2004
2.25M
                  fMultDiv2(gammaVecReal_m[k], gammaCenterImag_m[0]) +
2005
2.25M
                  fMultDiv2(gammaVecImag_m[k], gammaCenterReal_m[0]);
2006
2.25M
              gammaOut_e[k] = gammaCenter_e[0] + gammaVec_e[k] + 1;
2007
2.25M
            }
2008
2009
1.12M
            scaleUp(&gammaOutReal_m[0], &gammaOutImag_m[0], &gammaOut_e[0]);
2010
1.12M
            scaleUp(&gammaOutReal_m[1], &gammaOutImag_m[1], &gammaOut_e[1]);
2011
1.12M
            FDK_ASSERT(gammaOut_e[0] >= 0);
2012
1.12M
            FDK_ASSERT(gammaOut_e[0] < 32);
2013
2014
1.12M
            tmpReal_m = gammaOutReal_m[0];
2015
1.12M
            tmpImag_m = gammaOutImag_m[0];
2016
2017
1.12M
            INT modstretch4 = ((stretch == 4) && (mTr == 2));
2018
2019
1.12M
            FIXP_DBL cos_twid = twid_m_new[stretch - 2 - modstretch4][0];
2020
1.12M
            FIXP_DBL sin_twid = sign * twid_m_new[stretch - 2 - modstretch4][1];
2021
2022
1.12M
            gammaOutReal_m[0] =
2023
1.12M
                fMult(tmpReal_m, cos_twid) -
2024
1.12M
                fMult(tmpImag_m, sin_twid); /* sum should be <= 1 because of
2025
                                               sin/cos multiplication */
2026
1.12M
            gammaOutImag_m[0] =
2027
1.12M
                fMult(tmpImag_m, cos_twid) +
2028
1.12M
                fMult(tmpReal_m, sin_twid); /* sum should be <= 1 because of
2029
                                               sin/cos multiplication */
2030
2031
            /* wingain */
2032
3.38M
            for (k = 0; k < 2; k++) {
2033
2.25M
              gammaOutReal_m[k] = (fMult(gammaOutReal_m[k], wingain) << 1);
2034
2.25M
              gammaOutImag_m[k] = (fMult(gammaOutImag_m[k], wingain) << 1);
2035
2.25M
            }
2036
2037
1.12M
            gammaOutReal_m[1] >>= 1;
2038
1.12M
            gammaOutImag_m[1] >>= 1;
2039
1.12M
            gammaOut_e[0] += 2;
2040
1.12M
            gammaOut_e[1] += 2;
2041
2042
            /* OLA including window scaling by wingain/3 */
2043
3.38M
            for (k = 0; k < 2; k++) /* need k=1 to correspond to
2044
                                       grainModImag[slotOffset] -> out to
2045
                                       j*2+(slotOffset-offset)  */
2046
2.25M
            {
2047
2.25M
              hQmfTransposer->qmfHBEBufReal_F[(k + slotOffset - 1)][band] +=
2048
2.25M
                  gammaOutReal_m[k] >> (scale_factor_hbe - gammaOut_e[k]);
2049
2.25M
              hQmfTransposer->qmfHBEBufImag_F[(k + slotOffset - 1)][band] +=
2050
2.25M
                  gammaOutImag_m[k] >> (scale_factor_hbe - gammaOut_e[k]);
2051
2.25M
            }
2052
1.12M
          } /* mVal > qThrQMF * qThrQMF * sqmag0 && ts1 > 0 && ts2 < 64 */
2053
5.26M
        }   /* p >= pmin */
2054
50.3M
      }     /* for band */
2055
3.94M
    }       /* for stretch */
2056
2057
22.0M
    for (i = 0; i < QMF_WIN_LEN - 1; i++) {
2058
20.3M
      FDKmemcpy(hQmfTransposer->qmfInBufReal_F[i],
2059
20.3M
                hQmfTransposer->qmfInBufReal_F[i + 1],
2060
20.3M
                sizeof(FIXP_DBL) * hQmfTransposer->HBEAnalysiscQMF.no_channels);
2061
20.3M
      FDKmemcpy(hQmfTransposer->qmfInBufImag_F[i],
2062
20.3M
                hQmfTransposer->qmfInBufImag_F[i + 1],
2063
20.3M
                sizeof(FIXP_DBL) * hQmfTransposer->HBEAnalysiscQMF.no_channels);
2064
20.3M
    }
2065
2066
1.69M
    if (keepStatesSyncedMode != KEEP_STATES_SYNCED_NOOUT) {
2067
1.57M
      if (2 * j >= offset) {
2068
        /* copy first two slots of internal buffer to output */
2069
1.09M
        if (keepStatesSyncedMode == KEEP_STATES_SYNCED_OUTDIFF) {
2070
325k
          for (i = 0; i < 2; i++) {
2071
216k
            FDKmemcpy(&ppQmfBufferOutReal_F[2 * j - offset + i]
2072
216k
                                           [hQmfTransposer->xOverQmf[0]],
2073
216k
                      &hQmfTransposer
2074
216k
                           ->qmfHBEBufReal_F[i][hQmfTransposer->xOverQmf[0]],
2075
216k
                      (QMF_SYNTH_CHANNELS - hQmfTransposer->xOverQmf[0]) *
2076
216k
                          sizeof(FIXP_DBL));
2077
216k
            FDKmemcpy(&ppQmfBufferOutImag_F[2 * j - offset + i]
2078
216k
                                           [hQmfTransposer->xOverQmf[0]],
2079
216k
                      &hQmfTransposer
2080
216k
                           ->qmfHBEBufImag_F[i][hQmfTransposer->xOverQmf[0]],
2081
216k
                      (QMF_SYNTH_CHANNELS - hQmfTransposer->xOverQmf[0]) *
2082
216k
                          sizeof(FIXP_DBL));
2083
216k
          }
2084
989k
        } else {
2085
2.96M
          for (i = 0; i < 2; i++) {
2086
1.97M
            FDKmemcpy(&ppQmfBufferOutReal_F[2 * j + i + ov_len]
2087
1.97M
                                           [hQmfTransposer->xOverQmf[0]],
2088
1.97M
                      &hQmfTransposer
2089
1.97M
                           ->qmfHBEBufReal_F[i][hQmfTransposer->xOverQmf[0]],
2090
1.97M
                      (QMF_SYNTH_CHANNELS - hQmfTransposer->xOverQmf[0]) *
2091
1.97M
                          sizeof(FIXP_DBL));
2092
1.97M
            FDKmemcpy(&ppQmfBufferOutImag_F[2 * j + i + ov_len]
2093
1.97M
                                           [hQmfTransposer->xOverQmf[0]],
2094
1.97M
                      &hQmfTransposer
2095
1.97M
                           ->qmfHBEBufImag_F[i][hQmfTransposer->xOverQmf[0]],
2096
1.97M
                      (QMF_SYNTH_CHANNELS - hQmfTransposer->xOverQmf[0]) *
2097
1.97M
                          sizeof(FIXP_DBL));
2098
1.97M
          }
2099
989k
        }
2100
1.09M
      }
2101
1.57M
    }
2102
2103
    /* move slots up */
2104
16.9M
    for (i = 0; i < HBE_MAX_OUT_SLOTS - 2; i++) {
2105
15.2M
      FDKmemcpy(
2106
15.2M
          &hQmfTransposer->qmfHBEBufReal_F[i][hQmfTransposer->xOverQmf[0]],
2107
15.2M
          &hQmfTransposer->qmfHBEBufReal_F[i + 2][hQmfTransposer->xOverQmf[0]],
2108
15.2M
          (QMF_SYNTH_CHANNELS - hQmfTransposer->xOverQmf[0]) *
2109
15.2M
              sizeof(FIXP_DBL));
2110
15.2M
      FDKmemcpy(
2111
15.2M
          &hQmfTransposer->qmfHBEBufImag_F[i][hQmfTransposer->xOverQmf[0]],
2112
15.2M
          &hQmfTransposer->qmfHBEBufImag_F[i + 2][hQmfTransposer->xOverQmf[0]],
2113
15.2M
          (QMF_SYNTH_CHANNELS - hQmfTransposer->xOverQmf[0]) *
2114
15.2M
              sizeof(FIXP_DBL));
2115
15.2M
    }
2116
2117
    /* finally set last two slot to zero */
2118
5.09M
    for (i = 0; i < 2; i++) {
2119
3.39M
      FDKmemset(&hQmfTransposer->qmfHBEBufReal_F[HBE_MAX_OUT_SLOTS - 1 - i]
2120
3.39M
                                                [hQmfTransposer->xOverQmf[0]],
2121
3.39M
                0,
2122
3.39M
                (QMF_SYNTH_CHANNELS - hQmfTransposer->xOverQmf[0]) *
2123
3.39M
                    sizeof(FIXP_DBL));
2124
3.39M
      FDKmemset(&hQmfTransposer->qmfHBEBufImag_F[HBE_MAX_OUT_SLOTS - 1 - i]
2125
3.39M
                                                [hQmfTransposer->xOverQmf[0]],
2126
3.39M
                0,
2127
3.39M
                (QMF_SYNTH_CHANNELS - hQmfTransposer->xOverQmf[0]) *
2128
3.39M
                    sizeof(FIXP_DBL));
2129
3.39M
    }
2130
1.69M
  } /* qmfVocoderColsIn */
2131
2132
90.9k
  if (keepStatesSyncedMode != KEEP_STATES_SYNCED_NOOUT) {
2133
83.4k
    if (keepStatesSyncedMode == KEEP_STATES_SYNCED_OUTDIFF) {
2134
239k
      for (i = 0; i < ov_len + LPC_ORDER; i++) {
2135
7.29M
        for (band = hQmfTransposer->startBand; band < hQmfTransposer->stopBand;
2136
7.08M
             band++) {
2137
7.08M
          FIXP_DBL tmpR = ppQmfBufferOutReal_F[i][band];
2138
7.08M
          FIXP_DBL tmpI = ppQmfBufferOutImag_F[i][band];
2139
2140
7.08M
          ppQmfBufferOutReal_F[i][band] =
2141
7.08M
              fMult(tmpR, cos_F[band]) -
2142
7.08M
              fMult(tmpI, (-cos_F[64 - band - 1])); /* sum should be <= 1
2143
                                                       because of sin/cos
2144
                                                       multiplication */
2145
7.08M
          ppQmfBufferOutImag_F[i][band] =
2146
7.08M
              fMult(tmpR, (-cos_F[64 - band - 1])) +
2147
7.08M
              fMult(tmpI, cos_F[band]); /* sum should by <= 1 because of sin/cos
2148
                                           multiplication */
2149
7.08M
        }
2150
216k
      }
2151
60.4k
    } else {
2152
2.03M
      for (i = offset; i < hQmfTransposer->noCols; i++) {
2153
64.6M
        for (band = hQmfTransposer->startBand; band < hQmfTransposer->stopBand;
2154
62.6M
             band++) {
2155
62.6M
          FIXP_DBL tmpR = ppQmfBufferOutReal_F[i + ov_len][band];
2156
62.6M
          FIXP_DBL tmpI = ppQmfBufferOutImag_F[i + ov_len][band];
2157
2158
62.6M
          ppQmfBufferOutReal_F[i + ov_len][band] =
2159
62.6M
              fMult(tmpR, cos_F[band]) -
2160
62.6M
              fMult(tmpI, (-cos_F[64 - band - 1])); /* sum should be <= 1
2161
                                                       because of sin/cos
2162
                                                       multiplication */
2163
62.6M
          ppQmfBufferOutImag_F[i + ov_len][band] =
2164
62.6M
              fMult(tmpR, (-cos_F[64 - band - 1])) +
2165
62.6M
              fMult(tmpI, cos_F[band]); /* sum should by <= 1 because of sin/cos
2166
                                           multiplication */
2167
62.6M
        }
2168
1.97M
      }
2169
60.4k
    }
2170
83.4k
  }
2171
2172
90.9k
  *scale_hb = EXP2SCALE(scale_factor_hbe);
2173
90.9k
}
2174
2175
227k
int* GetxOverBandQmfTransposer(HANDLE_HBE_TRANSPOSER hQmfTransposer) {
2176
227k
  if (hQmfTransposer)
2177
74.4k
    return hQmfTransposer->xOverQmf;
2178
153k
  else
2179
153k
    return NULL;
2180
227k
}
2181
2182
202k
int Get41SbrQmfTransposer(HANDLE_HBE_TRANSPOSER hQmfTransposer) {
2183
202k
  if (hQmfTransposer != NULL)
2184
48.8k
    return hQmfTransposer->bSbr41;
2185
153k
  else
2186
153k
    return 0;
2187
202k
}