Coverage Report

Created: 2025-10-13 06:42

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/aac/libSBRdec/src/pvc_dec.cpp
Line
Count
Source
1
/* -----------------------------------------------------------------------------
2
Software License for The Fraunhofer FDK AAC Codec Library for Android
3
4
© Copyright  1995 - 2019 Fraunhofer-Gesellschaft zur Förderung der angewandten
5
Forschung e.V. All rights reserved.
6
7
 1.    INTRODUCTION
8
The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
9
that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
10
scheme for digital audio. This FDK AAC Codec software is intended to be used on
11
a wide variety of Android devices.
12
13
AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
14
general perceptual audio codecs. AAC-ELD is considered the best-performing
15
full-bandwidth communications codec by independent studies and is widely
16
deployed. AAC has been standardized by ISO and IEC as part of the MPEG
17
specifications.
18
19
Patent licenses for necessary patent claims for the FDK AAC Codec (including
20
those of Fraunhofer) may be obtained through Via Licensing
21
(www.vialicensing.com) or through the respective patent owners individually for
22
the purpose of encoding or decoding bit streams in products that are compliant
23
with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
24
Android devices already license these patent claims through Via Licensing or
25
directly from the patent owners, and therefore FDK AAC Codec software may
26
already be covered under those patent licenses when it is used for those
27
licensed purposes only.
28
29
Commercially-licensed AAC software libraries, including floating-point versions
30
with enhanced sound quality, are also available from Fraunhofer. Users are
31
encouraged to check the Fraunhofer website for additional applications
32
information and documentation.
33
34
2.    COPYRIGHT LICENSE
35
36
Redistribution and use in source and binary forms, with or without modification,
37
are permitted without payment of copyright license fees provided that you
38
satisfy the following conditions:
39
40
You must retain the complete text of this software license in redistributions of
41
the FDK AAC Codec or your modifications thereto in source code form.
42
43
You must retain the complete text of this software license in the documentation
44
and/or other materials provided with redistributions of the FDK AAC Codec or
45
your modifications thereto in binary form. You must make available free of
46
charge copies of the complete source code of the FDK AAC Codec and your
47
modifications thereto to recipients of copies in binary form.
48
49
The name of Fraunhofer may not be used to endorse or promote products derived
50
from this library without prior written permission.
51
52
You may not charge copyright license fees for anyone to use, copy or distribute
53
the FDK AAC Codec software or your modifications thereto.
54
55
Your modified versions of the FDK AAC Codec must carry prominent notices stating
56
that you changed the software and the date of any change. For modified versions
57
of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
58
must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
59
AAC Codec Library for Android."
60
61
3.    NO PATENT LICENSE
62
63
NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
64
limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
65
Fraunhofer provides no warranty of patent non-infringement with respect to this
66
software.
67
68
You may use this FDK AAC Codec software or modifications thereto only for
69
purposes that are authorized by appropriate patent licenses.
70
71
4.    DISCLAIMER
72
73
This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
74
holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
75
including but not limited to the implied warranties of merchantability and
76
fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
77
CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
78
or consequential damages, including but not limited to procurement of substitute
79
goods or services; loss of use, data, or profits, or business interruption,
80
however caused and on any theory of liability, whether in contract, strict
81
liability, or tort (including negligence), arising in any way out of the use of
82
this software, even if advised of the possibility of such damage.
83
84
5.    CONTACT INFORMATION
85
86
Fraunhofer Institute for Integrated Circuits IIS
87
Attention: Audio and Multimedia Departments - FDK AAC LL
88
Am Wolfsmantel 33
89
91058 Erlangen, Germany
90
91
www.iis.fraunhofer.de/amm
92
amm-info@iis.fraunhofer.de
93
----------------------------------------------------------------------------- */
94
95
/**************************** SBR decoder library ******************************
96
97
   Author(s):   Matthias Hildenbrand
98
99
   Description: Decode Predictive Vector Coding Data
100
101
*******************************************************************************/
102
103
#include "pvc_dec.h"
104
105
/* PVC interal definitions */
106
#define PVC_DIVMODE_BITS 3
107
#define PVC_NSMODE_BITS 1
108
#define PVC_REUSEPVCID_BITS 1
109
#define PVC_PVCID_BITS 7
110
#define PVC_GRIDINFO_BITS 1
111
#define PVC_NQMFBAND 64
112
64.0M
#define PVC_NBLOW 3 /* max. number of grouped QMF subbands below SBR range */
113
114
#define PVC_NTAB1 3
115
#define PVC_NTAB2 128
116
#define PVC_ID_NBIT 7
117
118
/* Exponent of pPvcStaticData->Esg and predictedEsg in dB domain.
119
   max(Esg) = 10*log10(2^15*2^15) = 90.30;
120
   min(Esg) = 10*log10(0.1) = -10
121
   max of predicted Esg seems to be higher than 90dB but 7 Bit should be enough.
122
*/
123
23.9M
#define PVC_ESG_EXP 7
124
125
#define LOG10FAC 0.752574989159953f     /* == 10/log2(10) * 2^-2 */
126
#define LOG10FAC_INV 0.664385618977472f /* == log2(10)/10 * 2^1 */
127
128
RAM_ALIGN
129
LNK_SECTION_CONSTDATA
130
static const FIXP_SGL pvc_SC_16[] = {
131
    FX_DBL2FXCONST_SGL(0x14413695), FX_DBL2FXCONST_SGL(0x1434b6cb),
132
    FX_DBL2FXCONST_SGL(0x140f27c7), FX_DBL2FXCONST_SGL(0x13d0591d),
133
    FX_DBL2FXCONST_SGL(0x1377f502), FX_DBL2FXCONST_SGL(0x130577d6),
134
    FX_DBL2FXCONST_SGL(0x12782266), FX_DBL2FXCONST_SGL(0x11cee459),
135
    FX_DBL2FXCONST_SGL(0x11083a2a), FX_DBL2FXCONST_SGL(0x1021f5e9),
136
    FX_DBL2FXCONST_SGL(0x0f18e17c), FX_DBL2FXCONST_SGL(0x0de814ca),
137
    FX_DBL2FXCONST_SGL(0x0c87a568), FX_DBL2FXCONST_SGL(0x0ae9b167),
138
    FX_DBL2FXCONST_SGL(0x08f24226), FX_DBL2FXCONST_SGL(0x06575ed5),
139
};
140
141
RAM_ALIGN
142
LNK_SECTION_CONSTDATA
143
static const FIXP_SGL pvc_SC_12[] = {
144
    FX_DBL2FXCONST_SGL(0x1aba6b3e), FX_DBL2FXCONST_SGL(0x1a9d164e),
145
    FX_DBL2FXCONST_SGL(0x1a44d56d), FX_DBL2FXCONST_SGL(0x19b0d742),
146
    FX_DBL2FXCONST_SGL(0x18df969a), FX_DBL2FXCONST_SGL(0x17ce91a0),
147
    FX_DBL2FXCONST_SGL(0x1679c3fa), FX_DBL2FXCONST_SGL(0x14daabfc),
148
    FX_DBL2FXCONST_SGL(0x12e65221), FX_DBL2FXCONST_SGL(0x1088d125),
149
    FX_DBL2FXCONST_SGL(0x0d9907b3), FX_DBL2FXCONST_SGL(0x09a80e9d),
150
};
151
152
RAM_ALIGN
153
LNK_SECTION_CONSTDATA
154
static const FIXP_SGL pvc_SC_4[] = {
155
    FX_DBL2FXCONST_SGL(0x4ad6ab0f),
156
    FX_DBL2FXCONST_SGL(0x47ef0dbe),
157
    FX_DBL2FXCONST_SGL(0x3eee7496),
158
    FX_DBL2FXCONST_SGL(0x2e4bd29d),
159
};
160
161
RAM_ALIGN
162
LNK_SECTION_CONSTDATA
163
static const FIXP_SGL pvc_SC_3[] = {
164
    FX_DBL2FXCONST_SGL(0x610dc761),
165
    FX_DBL2FXCONST_SGL(0x5a519a3d),
166
    FX_DBL2FXCONST_SGL(0x44a09e62),
167
};
168
169
static const UCHAR g_3a_pvcTab1_mode1[PVC_NTAB1][PVC_NBLOW][PVC_NBHIGH_MODE1] =
170
    {{{0x4F, 0x5B, 0x57, 0x52, 0x4D, 0x65, 0x45, 0x57},
171
      {0xF3, 0x0F, 0x18, 0x20, 0x19, 0x4F, 0x3D, 0x23},
172
      {0x78, 0x57, 0x55, 0x50, 0x50, 0x20, 0x36, 0x37}},
173
     {{0x4C, 0x5F, 0x53, 0x37, 0x1E, 0xFD, 0x15, 0x0A},
174
      {0x05, 0x0E, 0x28, 0x41, 0x48, 0x6E, 0x54, 0x5B},
175
      {0x59, 0x47, 0x40, 0x40, 0x3D, 0x33, 0x3F, 0x39}},
176
     {{0x47, 0x5F, 0x57, 0x34, 0x3C, 0x2E, 0x2E, 0x31},
177
      {0xFA, 0x13, 0x23, 0x4E, 0x44, 0x7C, 0x34, 0x38},
178
      {0x63, 0x43, 0x41, 0x3D, 0x35, 0x19, 0x3D, 0x33}}};
179
180
static const UCHAR g_2a_pvcTab2_mode1[PVC_NTAB2][PVC_NBHIGH_MODE1] = {
181
    {0xCB, 0xD1, 0xCC, 0xD2, 0xE2, 0xEB, 0xE7, 0xE8},
182
    {0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80},
183
    {0x84, 0x8C, 0x88, 0x83, 0x90, 0x93, 0x86, 0x80},
184
    {0xD7, 0xD8, 0xC0, 0xC7, 0xCF, 0xE5, 0xF1, 0xF6},
185
    {0xA5, 0xA6, 0xAA, 0xA8, 0xB0, 0xB1, 0xB8, 0xB8},
186
    {0xD7, 0xCB, 0xC1, 0xC3, 0xC5, 0xC9, 0xC9, 0xCE},
187
    {0xCA, 0xB5, 0xB8, 0xB3, 0xAC, 0xB6, 0xBB, 0xB8},
188
    {0xC1, 0xC4, 0xC3, 0xC5, 0xC6, 0xCA, 0xCA, 0xCB},
189
    {0xE0, 0xE1, 0xD8, 0xCD, 0xCB, 0xCB, 0xCE, 0xCC},
190
    {0xDB, 0xE1, 0xDF, 0xDB, 0xDC, 0xD9, 0xD9, 0xD6},
191
    {0xE0, 0xDE, 0xDD, 0xDD, 0xE0, 0xE3, 0xE5, 0xE6},
192
    {0xCA, 0xD2, 0xCD, 0xCE, 0xD5, 0xDB, 0xD9, 0xDB},
193
    {0xD2, 0xE0, 0xDB, 0xD5, 0xDB, 0xDE, 0xE3, 0xE1},
194
    {0xE5, 0xDB, 0xD0, 0xD2, 0xD8, 0xDD, 0xDB, 0xDD},
195
    {0xC0, 0xB5, 0xBF, 0xDD, 0xE3, 0xDC, 0xDC, 0xE4},
196
    {0xDB, 0xCE, 0xC6, 0xCF, 0xCF, 0xD1, 0xD3, 0xD4},
197
    {0xC9, 0xD7, 0xDA, 0xE2, 0xE9, 0xE7, 0xDF, 0xDC},
198
    {0x0A, 0x07, 0x0A, 0x08, 0x19, 0x24, 0x1F, 0x22},
199
    {0x1E, 0x1F, 0x11, 0x0E, 0x22, 0x2D, 0x33, 0x32},
200
    {0xF0, 0xDA, 0xDC, 0x18, 0x1F, 0x19, 0x0A, 0x1E},
201
    {0x09, 0xF8, 0xE6, 0x05, 0x19, 0x11, 0x0E, 0x0B},
202
    {0x09, 0x10, 0x0E, 0xE6, 0xF4, 0x20, 0x22, 0xFA},
203
    {0xF2, 0xE5, 0xF8, 0x0E, 0x18, 0x15, 0x0D, 0x10},
204
    {0x15, 0x13, 0x16, 0x0A, 0x0D, 0x1F, 0x1D, 0x1B},
205
    {0xFA, 0xFF, 0xFE, 0xFF, 0x09, 0x11, 0x03, 0x0B},
206
    {0xFE, 0xFA, 0xF2, 0xF8, 0x0C, 0x1E, 0x11, 0x12},
207
    {0xFA, 0xF8, 0x0B, 0x17, 0x1D, 0x17, 0x0E, 0x16},
208
    {0x00, 0xF3, 0xFD, 0x0A, 0x1C, 0x17, 0xFD, 0x08},
209
    {0xEA, 0xEA, 0x03, 0x12, 0x1E, 0x14, 0x09, 0x04},
210
    {0x02, 0xFE, 0x04, 0xFB, 0x0C, 0x0E, 0x07, 0x02},
211
    {0xF6, 0x02, 0x07, 0x0B, 0x17, 0x17, 0x01, 0xFF},
212
    {0xF5, 0xFB, 0xFE, 0x04, 0x12, 0x14, 0x0C, 0x0D},
213
    {0x10, 0x10, 0x0E, 0x04, 0x07, 0x11, 0x0F, 0x13},
214
    {0x0C, 0x0F, 0xFB, 0xF2, 0x0A, 0x12, 0x09, 0x0D},
215
    {0x0D, 0x1D, 0xF1, 0xF4, 0x2A, 0x06, 0x3B, 0x32},
216
    {0xFC, 0x08, 0x06, 0x02, 0x0E, 0x17, 0x08, 0x0E},
217
    {0x07, 0x02, 0xEE, 0xEE, 0x2B, 0xF6, 0x23, 0x13},
218
    {0x04, 0x02, 0x05, 0x08, 0x0B, 0x0E, 0xFB, 0xFB},
219
    {0x00, 0x04, 0x10, 0x18, 0x22, 0x25, 0x1D, 0x1F},
220
    {0xFB, 0x0D, 0x07, 0x00, 0x0C, 0x0F, 0xFC, 0x02},
221
    {0x00, 0x00, 0x00, 0x01, 0x05, 0x07, 0x03, 0x05},
222
    {0x04, 0x05, 0x08, 0x13, 0xFF, 0xEB, 0x0C, 0x06},
223
    {0x05, 0x13, 0x0E, 0x0B, 0x12, 0x15, 0x09, 0x0A},
224
    {0x09, 0x03, 0x09, 0x05, 0x12, 0x16, 0x11, 0x12},
225
    {0x14, 0x1A, 0x06, 0x01, 0x10, 0x11, 0xFE, 0x02},
226
    {0x01, 0x0B, 0x0B, 0x0C, 0x18, 0x21, 0x10, 0x13},
227
    {0x12, 0x0D, 0x0A, 0x10, 0x1C, 0x1D, 0x0D, 0x10},
228
    {0x03, 0x09, 0x14, 0x15, 0x1B, 0x1A, 0x01, 0xFF},
229
    {0x08, 0x12, 0x13, 0x0E, 0x16, 0x1D, 0x14, 0x1B},
230
    {0x07, 0x15, 0x1C, 0x1B, 0x20, 0x21, 0x11, 0x0E},
231
    {0x12, 0x18, 0x19, 0x17, 0x20, 0x25, 0x1A, 0x1E},
232
    {0x0C, 0x1A, 0x1D, 0x22, 0x2F, 0x33, 0x27, 0x28},
233
    {0x0E, 0x1A, 0x17, 0x10, 0x0A, 0x0E, 0xFF, 0x06},
234
    {0x1A, 0x1C, 0x18, 0x14, 0x1A, 0x16, 0x0A, 0x0E},
235
    {0x1E, 0x27, 0x25, 0x26, 0x27, 0x2A, 0x21, 0x21},
236
    {0xF1, 0x0A, 0x16, 0x1C, 0x28, 0x25, 0x15, 0x19},
237
    {0x08, 0x12, 0x09, 0x08, 0x16, 0x17, 0xEF, 0xF6},
238
    {0x0C, 0x0B, 0x00, 0xFC, 0x04, 0x09, 0xFC, 0x03},
239
    {0xFB, 0xF1, 0xF8, 0x26, 0x24, 0x18, 0x1D, 0x20},
240
    {0xF9, 0x01, 0x0C, 0x0F, 0x07, 0x08, 0x06, 0x07},
241
    {0x07, 0x06, 0x08, 0x04, 0x07, 0x0D, 0x07, 0x09},
242
    {0xFE, 0x01, 0x06, 0x05, 0x13, 0x1B, 0x14, 0x19},
243
    {0x09, 0x0C, 0x0E, 0x01, 0x08, 0x05, 0xFB, 0xFD},
244
    {0x07, 0x06, 0x03, 0x0A, 0x16, 0x12, 0x04, 0x07},
245
    {0x04, 0x01, 0x00, 0x04, 0x1F, 0x20, 0x0E, 0x0A},
246
    {0x03, 0xFF, 0xF6, 0xFB, 0x15, 0x1A, 0x00, 0x03},
247
    {0xFC, 0x18, 0x0B, 0x2D, 0x35, 0x23, 0x12, 0x09},
248
    {0x02, 0xFE, 0x01, 0xFF, 0x0C, 0x11, 0x0D, 0x0F},
249
    {0xFA, 0xE9, 0xD9, 0xFF, 0x0D, 0x05, 0x0D, 0x10},
250
    {0xF1, 0xE0, 0xF0, 0x01, 0x06, 0x06, 0x06, 0x10},
251
    {0xE9, 0xD4, 0xD7, 0x0F, 0x14, 0x0B, 0x0D, 0x16},
252
    {0x00, 0xFF, 0xEE, 0xE5, 0xFF, 0x08, 0x02, 0xF9},
253
    {0xE0, 0xDA, 0xE5, 0xFE, 0x09, 0x02, 0xF9, 0x04},
254
    {0xE0, 0xE2, 0xF4, 0x09, 0x13, 0x0C, 0x0D, 0x09},
255
    {0xFC, 0x02, 0x04, 0xFF, 0x00, 0xFF, 0xF8, 0xF7},
256
    {0xFE, 0xFB, 0xED, 0xF2, 0xFE, 0xFE, 0x08, 0x0C},
257
    {0xF3, 0xEF, 0xD0, 0xE3, 0x05, 0x11, 0xFD, 0xFF},
258
    {0xFA, 0xEF, 0xEA, 0xFE, 0x0D, 0x0E, 0xFE, 0x02},
259
    {0xF7, 0xFB, 0xDB, 0xDF, 0x14, 0xDD, 0x07, 0xFE},
260
    {0xFE, 0x08, 0x00, 0xDB, 0xE5, 0x1A, 0x13, 0xED},
261
    {0xF9, 0xFE, 0xFF, 0xF4, 0xF3, 0x00, 0x05, 0x02},
262
    {0xEF, 0xDE, 0xD8, 0xEB, 0xEA, 0xF5, 0x0E, 0x19},
263
    {0xFB, 0xFC, 0xFA, 0xEC, 0xEB, 0xED, 0xEE, 0xE8},
264
    {0xEE, 0xFC, 0xFD, 0x00, 0x04, 0xFC, 0xF0, 0xF5},
265
    {0x00, 0xFA, 0xF4, 0xF1, 0xF5, 0xFA, 0xFB, 0xF9},
266
    {0xEB, 0xF0, 0xDF, 0xE3, 0xEF, 0x07, 0x02, 0x05},
267
    {0xF7, 0xF0, 0xE6, 0xE7, 0x06, 0x15, 0x06, 0x0C},
268
    {0xF1, 0xE4, 0xD8, 0xEA, 0x06, 0xF2, 0x07, 0x09},
269
    {0xFF, 0xFE, 0xFE, 0xF9, 0xFF, 0xFF, 0x02, 0xF9},
270
    {0xDD, 0xF4, 0xF0, 0xF1, 0xFF, 0xFF, 0xEA, 0xF1},
271
    {0xF0, 0xF1, 0xFD, 0x03, 0x03, 0xFE, 0x00, 0x05},
272
    {0xF1, 0xF6, 0xE0, 0xDF, 0xF5, 0x01, 0xF4, 0xF8},
273
    {0x02, 0x03, 0xE5, 0xDC, 0xE7, 0xFD, 0x02, 0x08},
274
    {0xEC, 0xF1, 0xF5, 0xEC, 0xF2, 0xF8, 0xF6, 0xEE},
275
    {0xF3, 0xF4, 0xF6, 0xF4, 0xF5, 0xF1, 0xE7, 0xEA},
276
    {0xF7, 0xF3, 0xEC, 0xEA, 0xEF, 0xF0, 0xEE, 0xF1},
277
    {0xEB, 0xF6, 0xFB, 0xFA, 0xEF, 0xF3, 0xF3, 0xF7},
278
    {0x01, 0x03, 0xF1, 0xF6, 0x05, 0xF8, 0xE1, 0xEB},
279
    {0xF5, 0xF6, 0xF6, 0xF4, 0xFB, 0xFB, 0xFF, 0x00},
280
    {0xF8, 0x01, 0xFB, 0xFA, 0xFF, 0x03, 0xFE, 0x04},
281
    {0x04, 0xFB, 0x03, 0xFD, 0xF5, 0xF7, 0xF6, 0xFB},
282
    {0x06, 0x09, 0xFB, 0xF4, 0xF9, 0xFA, 0xFC, 0xFF},
283
    {0xF5, 0xF6, 0xF1, 0xEE, 0xF5, 0xF8, 0xF5, 0xF9},
284
    {0xF5, 0xF9, 0xFA, 0xFC, 0x07, 0x09, 0x01, 0xFB},
285
    {0xD7, 0xE9, 0xE8, 0xEC, 0x00, 0x0C, 0xFE, 0xF1},
286
    {0xEC, 0x04, 0xE9, 0xDF, 0x03, 0xE8, 0x00, 0xFA},
287
    {0xE6, 0xE2, 0xFF, 0x0A, 0x13, 0x01, 0x00, 0xF7},
288
    {0xF1, 0xFA, 0xF7, 0xF5, 0x01, 0x06, 0x05, 0x0A},
289
    {0xF6, 0xF6, 0xFC, 0xF6, 0xE8, 0x11, 0xF2, 0xFE},
290
    {0xFE, 0x08, 0x05, 0x12, 0xFD, 0xD0, 0x0E, 0x07},
291
    {0xF1, 0xFE, 0xF7, 0xF2, 0xFB, 0x02, 0xFA, 0xF8},
292
    {0xF4, 0xEA, 0xEC, 0xF3, 0xFE, 0x01, 0xF7, 0xF6},
293
    {0xFF, 0xFA, 0xFB, 0xF9, 0xFF, 0x01, 0x04, 0x03},
294
    {0x00, 0xF9, 0xF4, 0xFC, 0x05, 0xFC, 0xF7, 0xFB},
295
    {0xF8, 0xFF, 0xEF, 0xEC, 0xFB, 0x04, 0xF8, 0x03},
296
    {0xEB, 0xF1, 0xED, 0xF4, 0x02, 0x0E, 0x0B, 0x04},
297
    {0xF7, 0x01, 0xF8, 0xF4, 0xF8, 0xEF, 0xF8, 0x04},
298
    {0xEB, 0xF0, 0xF7, 0xFC, 0x10, 0x0D, 0xF8, 0xF8},
299
    {0xE8, 0xFE, 0xEE, 0xE8, 0xED, 0xF7, 0xF5, 0xF8},
300
    {0xED, 0xEB, 0xE9, 0xEA, 0xF2, 0xF5, 0xF4, 0xF9},
301
    {0xEA, 0xF2, 0xEF, 0xEE, 0xF9, 0xFE, 0xFD, 0x02},
302
    {0xFA, 0xFD, 0x02, 0x0D, 0xFA, 0xE4, 0x0F, 0x01},
303
    {0xFF, 0x08, 0x05, 0xF6, 0xF7, 0xFB, 0xF1, 0xF1},
304
    {0xF4, 0xEC, 0xEE, 0xF6, 0xEE, 0xEE, 0xF8, 0x06},
305
    {0xE8, 0xFA, 0xF8, 0xE8, 0xF8, 0xE9, 0xEE, 0xF9},
306
    {0xE5, 0xE9, 0xF0, 0x00, 0x00, 0xEF, 0xF3, 0xF8},
307
    {0xF7, 0xFB, 0xFB, 0xF7, 0xF9, 0xF9, 0xF5, 0xF0},
308
    {0xFD, 0xFF, 0xF2, 0xEE, 0xF2, 0xF5, 0xF1, 0xF3}};
309
310
static const UCHAR g_3a_pvcTab1_mode2[PVC_NTAB1][PVC_NBLOW][PVC_NBHIGH_MODE2] =
311
    {{{0x11, 0x27, 0x0F, 0xFD, 0x04, 0xFC},
312
      {0x00, 0xBE, 0xE3, 0xF4, 0xDB, 0xF0},
313
      {0x09, 0x1E, 0x18, 0x1A, 0x21, 0x1B}},
314
     {{0x16, 0x28, 0x2B, 0x29, 0x25, 0x32},
315
      {0xF2, 0xE9, 0xE4, 0xE5, 0xE2, 0xD4},
316
      {0x0E, 0x0B, 0x0C, 0x0D, 0x0D, 0x0E}},
317
     {{0x2E, 0x3C, 0x20, 0x16, 0x1B, 0x1A},
318
      {0xE4, 0xC6, 0xE5, 0xF4, 0xDC, 0xDC},
319
      {0x0F, 0x1B, 0x18, 0x14, 0x1E, 0x1A}}};
320
321
static const UCHAR g_2a_pvcTab2_mode2[PVC_NTAB2][PVC_NBHIGH_MODE2] = {
322
    {0x26, 0x25, 0x11, 0x0C, 0xFA, 0x15}, {0x1B, 0x18, 0x11, 0x0E, 0x0E, 0x0E},
323
    {0x12, 0x10, 0x10, 0x10, 0x11, 0x10}, {0x1E, 0x24, 0x19, 0x15, 0x14, 0x12},
324
    {0x24, 0x16, 0x12, 0x13, 0x15, 0x1C}, {0xEA, 0xED, 0xEB, 0xEA, 0xEC, 0xEB},
325
    {0xFC, 0xFD, 0xFD, 0xFC, 0xFE, 0xFE}, {0x0F, 0x0C, 0x0B, 0x0A, 0x0B, 0x0B},
326
    {0x22, 0x0B, 0x16, 0x18, 0x13, 0x19}, {0x1C, 0x14, 0x1D, 0x20, 0x19, 0x1A},
327
    {0x10, 0x08, 0x00, 0xFF, 0x02, 0x05}, {0x06, 0x07, 0x05, 0x03, 0x05, 0x04},
328
    {0x2A, 0x1F, 0x12, 0x12, 0x11, 0x18}, {0x19, 0x19, 0x02, 0x04, 0x00, 0x04},
329
    {0x18, 0x17, 0x17, 0x15, 0x16, 0x15}, {0x21, 0x1E, 0x1B, 0x19, 0x1C, 0x1B},
330
    {0x3C, 0x35, 0x20, 0x1D, 0x30, 0x34}, {0x3A, 0x1F, 0x37, 0x38, 0x33, 0x31},
331
    {0x37, 0x34, 0x25, 0x27, 0x35, 0x34}, {0x34, 0x2E, 0x32, 0x31, 0x34, 0x31},
332
    {0x36, 0x33, 0x2F, 0x2F, 0x32, 0x2F}, {0x35, 0x20, 0x2F, 0x32, 0x2F, 0x2C},
333
    {0x2E, 0x2B, 0x2F, 0x34, 0x36, 0x30}, {0x3F, 0x39, 0x30, 0x28, 0x29, 0x29},
334
    {0x3C, 0x30, 0x32, 0x37, 0x39, 0x36}, {0x37, 0x36, 0x30, 0x2B, 0x26, 0x24},
335
    {0x44, 0x38, 0x2F, 0x2D, 0x2D, 0x2D}, {0x38, 0x2B, 0x2C, 0x2C, 0x30, 0x2D},
336
    {0x37, 0x36, 0x2F, 0x23, 0x2D, 0x32}, {0x3C, 0x39, 0x29, 0x2E, 0x38, 0x37},
337
    {0x3B, 0x3A, 0x35, 0x32, 0x31, 0x2D}, {0x32, 0x31, 0x2F, 0x2C, 0x2D, 0x28},
338
    {0x2C, 0x31, 0x32, 0x30, 0x32, 0x2D}, {0x35, 0x34, 0x34, 0x34, 0x35, 0x33},
339
    {0x34, 0x38, 0x3B, 0x3C, 0x3E, 0x3A}, {0x3E, 0x3C, 0x3B, 0x3A, 0x3C, 0x39},
340
    {0x3D, 0x41, 0x46, 0x41, 0x3D, 0x38}, {0x44, 0x41, 0x40, 0x3E, 0x3F, 0x3A},
341
    {0x47, 0x47, 0x47, 0x42, 0x44, 0x40}, {0x4C, 0x4A, 0x4A, 0x46, 0x49, 0x45},
342
    {0x53, 0x52, 0x52, 0x4C, 0x4E, 0x49}, {0x41, 0x3D, 0x39, 0x2C, 0x2E, 0x2E},
343
    {0x2D, 0x37, 0x36, 0x30, 0x28, 0x36}, {0x3B, 0x32, 0x2E, 0x2D, 0x2D, 0x29},
344
    {0x40, 0x39, 0x36, 0x35, 0x36, 0x32}, {0x30, 0x2D, 0x2D, 0x2E, 0x31, 0x30},
345
    {0x38, 0x3D, 0x3B, 0x37, 0x35, 0x34}, {0x44, 0x3D, 0x3C, 0x38, 0x37, 0x33},
346
    {0x3A, 0x36, 0x37, 0x37, 0x39, 0x36}, {0x32, 0x36, 0x37, 0x30, 0x2E, 0x2A},
347
    {0x3C, 0x33, 0x33, 0x31, 0x33, 0x30}, {0x30, 0x31, 0x36, 0x37, 0x38, 0x34},
348
    {0x26, 0x27, 0x2E, 0x29, 0x1C, 0x16}, {0x14, 0x15, 0x1F, 0x17, 0x15, 0x1C},
349
    {0x38, 0x2D, 0x18, 0x13, 0x1E, 0x2B}, {0x30, 0x22, 0x17, 0x1A, 0x26, 0x2B},
350
    {0x24, 0x20, 0x1F, 0x10, 0x0C, 0x11}, {0x27, 0x1F, 0x13, 0x17, 0x24, 0x2A},
351
    {0x2F, 0x13, 0x18, 0x13, 0x2A, 0x32}, {0x31, 0x1E, 0x1E, 0x1E, 0x21, 0x28},
352
    {0x2A, 0x12, 0x19, 0x17, 0x16, 0x24}, {0x27, 0x0F, 0x16, 0x1D, 0x17, 0x1C},
353
    {0x2F, 0x26, 0x25, 0x22, 0x20, 0x22}, {0x1E, 0x1B, 0x1E, 0x18, 0x1E, 0x24},
354
    {0x31, 0x26, 0x0E, 0x15, 0x15, 0x25}, {0x2D, 0x22, 0x1E, 0x14, 0x10, 0x22},
355
    {0x25, 0x1B, 0x18, 0x11, 0x13, 0x1F}, {0x2F, 0x1B, 0x13, 0x1B, 0x18, 0x22},
356
    {0x21, 0x24, 0x1D, 0x1C, 0x1D, 0x1B}, {0x23, 0x1E, 0x28, 0x29, 0x27, 0x25},
357
    {0x2E, 0x2A, 0x1D, 0x17, 0x26, 0x2D}, {0x31, 0x2C, 0x1A, 0x0E, 0x1A, 0x24},
358
    {0x26, 0x16, 0x20, 0x1D, 0x14, 0x1E}, {0x29, 0x20, 0x1B, 0x1B, 0x17, 0x17},
359
    {0x1D, 0x06, 0x1A, 0x1E, 0x1B, 0x1D}, {0x2B, 0x23, 0x1F, 0x1F, 0x1D, 0x1C},
360
    {0x27, 0x1A, 0x0C, 0x0E, 0x0F, 0x1A}, {0x29, 0x1D, 0x1E, 0x22, 0x22, 0x24},
361
    {0x20, 0x21, 0x1B, 0x18, 0x13, 0x21}, {0x27, 0x0E, 0x10, 0x14, 0x10, 0x1A},
362
    {0x26, 0x24, 0x25, 0x25, 0x26, 0x28}, {0x1A, 0x24, 0x25, 0x29, 0x26, 0x24},
363
    {0x1D, 0x1D, 0x15, 0x12, 0x0F, 0x18}, {0x1E, 0x14, 0x13, 0x12, 0x14, 0x18},
364
    {0x16, 0x13, 0x13, 0x1A, 0x1B, 0x1D}, {0x20, 0x27, 0x22, 0x24, 0x1A, 0x19},
365
    {0x1F, 0x17, 0x19, 0x18, 0x17, 0x18}, {0x20, 0x1B, 0x1C, 0x1C, 0x1B, 0x1A},
366
    {0x23, 0x19, 0x1D, 0x1F, 0x1E, 0x21}, {0x26, 0x1F, 0x1D, 0x1B, 0x19, 0x1A},
367
    {0x23, 0x1E, 0x1F, 0x20, 0x1F, 0x1E}, {0x29, 0x20, 0x22, 0x20, 0x20, 0x1F},
368
    {0x26, 0x23, 0x21, 0x22, 0x23, 0x23}, {0x29, 0x1F, 0x24, 0x25, 0x26, 0x29},
369
    {0x2B, 0x22, 0x25, 0x27, 0x23, 0x21}, {0x29, 0x21, 0x19, 0x0E, 0x22, 0x2D},
370
    {0x32, 0x29, 0x1F, 0x1C, 0x1B, 0x21}, {0x1E, 0x1A, 0x1E, 0x24, 0x25, 0x25},
371
    {0x24, 0x1D, 0x21, 0x22, 0x22, 0x25}, {0x2C, 0x25, 0x21, 0x22, 0x23, 0x25},
372
    {0x24, 0x1E, 0x21, 0x26, 0x2B, 0x2C}, {0x28, 0x24, 0x1B, 0x1F, 0x28, 0x2D},
373
    {0x23, 0x13, 0x16, 0x22, 0x22, 0x29}, {0x1B, 0x23, 0x1C, 0x20, 0x14, 0x0D},
374
    {0x1E, 0x16, 0x1A, 0x1E, 0x1C, 0x1D}, {0x2B, 0x1C, 0x1D, 0x20, 0x1B, 0x1C},
375
    {0x1C, 0x1B, 0x23, 0x1F, 0x19, 0x1E}, {0x21, 0x23, 0x26, 0x20, 0x20, 0x22},
376
    {0x1D, 0x0B, 0x19, 0x1E, 0x11, 0x19}, {0x18, 0x17, 0x16, 0x17, 0x14, 0x16},
377
    {0x16, 0x19, 0x1C, 0x20, 0x21, 0x22}, {0x30, 0x1E, 0x22, 0x24, 0x25, 0x26},
378
    {0x1B, 0x1F, 0x17, 0x1D, 0x1E, 0x21}, {0x32, 0x2B, 0x27, 0x1F, 0x1B, 0x1A},
379
    {0x28, 0x20, 0x1A, 0x1B, 0x1F, 0x23}, {0x32, 0x21, 0x20, 0x21, 0x1D, 0x1F},
380
    {0x22, 0x18, 0x12, 0x15, 0x1B, 0x20}, {0x27, 0x27, 0x2A, 0x24, 0x21, 0x21},
381
    {0x1E, 0x0F, 0x0D, 0x1A, 0x1D, 0x23}, {0x28, 0x25, 0x27, 0x21, 0x17, 0x25},
382
    {0x2B, 0x27, 0x23, 0x19, 0x13, 0x14}, {0x25, 0x2B, 0x22, 0x22, 0x20, 0x21},
383
    {0x27, 0x1B, 0x16, 0x17, 0x0F, 0x15}, {0x29, 0x26, 0x23, 0x15, 0x1E, 0x28},
384
    {0x24, 0x1C, 0x19, 0x1A, 0x18, 0x19}, {0x2D, 0x15, 0x27, 0x2B, 0x24, 0x23},
385
    {0x2C, 0x12, 0x1F, 0x23, 0x1F, 0x20}, {0x25, 0x0F, 0x22, 0x27, 0x1F, 0x21}};
386
387
static const UCHAR g_a_pvcTab1_dp_mode1[PVC_NTAB1 - 1] = {17, 68};
388
static const UCHAR g_a_pvcTab1_dp_mode2[PVC_NTAB1 - 1] = {16, 52};
389
/* fractional exponent which corresponds to Q representation value */
390
static const SCHAR g_a_scalingCoef_mode1[PVC_NBLOW + 1] = {
391
    -1, -1, 0, 6}; /* { 8, 8, 7, 1 }; Q scaling */
392
static const SCHAR g_a_scalingCoef_mode2[PVC_NBLOW + 1] = {
393
    0, 0, 1, 7}; /* { 7, 7, 6, 0 }; Q scaling */
394
395
int pvcInitFrame(PVC_STATIC_DATA *pPvcStaticData,
396
                 PVC_DYNAMIC_DATA *pPvcDynamicData, const UCHAR pvcMode,
397
                 const UCHAR ns, const int RATE, const int kx,
398
290k
                 const int pvcBorder0, const UCHAR *pPvcID) {
399
290k
  int lbw, hbw, i, temp;
400
290k
  pPvcDynamicData->pvc_mode = pvcMode;
401
290k
  pPvcDynamicData->kx = kx;
402
290k
  pPvcDynamicData->RATE = RATE;
403
404
290k
  switch (pvcMode) {
405
187k
    case 0:
406
      /* legacy SBR, nothing to do */
407
187k
      return 0;
408
14.8k
    case 1:
409
14.8k
      pPvcDynamicData->nbHigh = 8;
410
14.8k
      pPvcDynamicData->pPVCTab1 = (const UCHAR *)g_3a_pvcTab1_mode1;
411
14.8k
      pPvcDynamicData->pPVCTab2 = (const UCHAR *)g_2a_pvcTab2_mode1;
412
14.8k
      pPvcDynamicData->pPVCTab1_dp = g_a_pvcTab1_dp_mode1;
413
14.8k
      pPvcDynamicData->pScalingCoef = g_a_scalingCoef_mode1;
414
14.8k
      hbw = 8 / RATE;
415
14.8k
      break;
416
87.7k
    case 2:
417
87.7k
      pPvcDynamicData->nbHigh = 6;
418
87.7k
      pPvcDynamicData->pPVCTab1 = (const UCHAR *)g_3a_pvcTab1_mode2;
419
87.7k
      pPvcDynamicData->pPVCTab2 = (const UCHAR *)g_2a_pvcTab2_mode2;
420
87.7k
      pPvcDynamicData->pPVCTab1_dp = g_a_pvcTab1_dp_mode2;
421
87.7k
      pPvcDynamicData->pScalingCoef = g_a_scalingCoef_mode2;
422
87.7k
      hbw = 12 / RATE;
423
87.7k
      break;
424
0
    default:
425
      /* invalid pvcMode */
426
0
      return 1;
427
290k
  }
428
429
102k
  pPvcDynamicData->pvcBorder0 = pvcBorder0;
430
102k
  UCHAR pvcBorder0_last = pPvcStaticData->pvcBorder0;
431
102k
  pPvcStaticData->pvcBorder0 = pvcBorder0;
432
102k
  pPvcDynamicData->pPvcID = pPvcID;
433
434
102k
  pPvcDynamicData->ns = ns;
435
102k
  switch (ns) {
436
9.88k
    case 16:
437
9.88k
      pPvcDynamicData->pSCcoeffs = pvc_SC_16;
438
9.88k
      break;
439
4.83k
    case 12:
440
4.83k
      pPvcDynamicData->pSCcoeffs = pvc_SC_12;
441
4.83k
      break;
442
4.92k
    case 4:
443
4.92k
      pPvcDynamicData->pSCcoeffs = pvc_SC_4;
444
4.92k
      break;
445
82.9k
    case 3:
446
82.9k
      pPvcDynamicData->pSCcoeffs = pvc_SC_3;
447
82.9k
      break;
448
0
    default:
449
0
      return 1;
450
102k
  }
451
452
  /* in the lower part of Esg-array there are previous values of Esg (from last
453
     call to this function In case of an previous legay-SBR frame, or if there
454
     was a change in cross-over FQ the value of first PVC SBR timeslot is
455
     propagated to prev-values in order to have reasonable values for
456
     smooth-filtering
457
  */
458
102k
  if ((pPvcStaticData->pvc_mode_last == 0) || (pPvcStaticData->kx_last != kx)) {
459
13.5k
    pPvcDynamicData->pastEsgSlotsAvail = 0;
460
88.9k
  } else {
461
88.9k
    pPvcDynamicData->pastEsgSlotsAvail = PVC_NS_MAX - pvcBorder0_last;
462
88.9k
  }
463
464
102k
  lbw = 8 / RATE;
465
466
102k
  temp = kx;
467
512k
  for (i = PVC_NBLOW; i >= 0; i--) {
468
410k
    pPvcDynamicData->sg_offset_low[i] = temp;
469
410k
    temp -= lbw;
470
410k
  }
471
472
102k
  temp = 0;
473
850k
  for (i = 0; i <= pPvcDynamicData->nbHigh; i++) {
474
747k
    pPvcDynamicData->sg_offset_high_kx[i] = temp;
475
747k
    temp += hbw;
476
747k
  }
477
478
102k
  return 0;
479
102k
}
480
481
/* call if pvcMode = 1,2 */
482
void pvcDecodeFrame(PVC_STATIC_DATA *pPvcStaticData,
483
                    PVC_DYNAMIC_DATA *pPvcDynamicData, FIXP_DBL **qmfBufferReal,
484
                    FIXP_DBL **qmfBufferImag, const int overlap,
485
                    const int qmfExponentOverlap,
486
102k
                    const int qmfExponentCurrent) {
487
102k
  int t;
488
102k
  FIXP_DBL *predictedEsgSlot;
489
102k
  int RATE = pPvcDynamicData->RATE;
490
102k
  int pvcBorder0 = pPvcDynamicData->pvcBorder0;
491
492
1.74M
  for (t = pvcBorder0; t < PVC_NTIMESLOT; t++) {
493
1.64M
    int *pPredEsg_exp = &pPvcDynamicData->predEsg_exp[t];
494
1.64M
    predictedEsgSlot = pPvcDynamicData->predEsg[t];
495
496
1.64M
    pvcDecodeTimeSlot(
497
1.64M
        pPvcStaticData, pPvcDynamicData, &qmfBufferReal[t * RATE],
498
1.64M
        &qmfBufferImag[t * RATE],
499
1.64M
        (t * RATE < overlap) ? qmfExponentOverlap : qmfExponentCurrent,
500
1.64M
        pvcBorder0, t, predictedEsgSlot, pPredEsg_exp);
501
1.64M
  }
502
503
102k
  return;
504
102k
}
505
506
void pvcDecodeTimeSlot(PVC_STATIC_DATA *pPvcStaticData,
507
                       PVC_DYNAMIC_DATA *pPvcDynamicData,
508
                       FIXP_DBL **qmfSlotReal, FIXP_DBL **qmfSlotImag,
509
                       const int qmfExponent, const int pvcBorder0,
510
                       const int timeSlotNumber, FIXP_DBL predictedEsgSlot[],
511
1.64M
                       int *predictedEsg_exp) {
512
1.64M
  int i, band, ksg, ksg_start = 0;
513
1.64M
  int RATE = pPvcDynamicData->RATE;
514
1.64M
  int Esg_index = pPvcStaticData->Esg_slot_index;
515
1.64M
  const SCHAR *sg_borders = pPvcDynamicData->sg_offset_low;
516
1.64M
  FIXP_DBL *pEsg = pPvcStaticData->Esg[Esg_index];
517
1.64M
  FIXP_DBL E[PVC_NBLOW] = {0};
518
519
  /* Subband grouping in QMF subbands below SBR range */
520
  /* Within one timeslot ( i = [0...(RATE-1)] QMF subsamples) calculate energy
521
     E(ib,t) and group them to Esg(ksg,t). Then transfer values to logarithmical
522
     domain and store them for time domain smoothing. (7.5.6.3 Subband grouping
523
     in QMF subbands below SBR range)
524
  */
525
1.64M
  for (ksg = 0; sg_borders[ksg] < 0; ksg++) {
526
7.43k
    pEsg[ksg] = FL2FXCONST_DBL(-10.0 / (1 << PVC_ESG_EXP)); /* 10*log10(0.1) */
527
7.43k
    ksg_start++;
528
7.43k
  }
529
530
5.27M
  for (i = 0; i < RATE; i++) {
531
3.63M
    FIXP_DBL *qmfR, *qmfI;
532
3.63M
    qmfR = qmfSlotReal[i];
533
3.63M
    qmfI = qmfSlotImag[i];
534
14.5M
    for (ksg = ksg_start; ksg < PVC_NBLOW; ksg++) {
535
50.2M
      for (band = sg_borders[ksg]; band < sg_borders[ksg + 1]; band++) {
536
        /* The division by 8 == (RATE*lbw) is required algorithmically */
537
39.3M
        E[ksg] +=
538
39.3M
            ((fPow2Div2(qmfR[band]) >> 1) + (fPow2Div2(qmfI[band]) >> 1)) >> 3;
539
39.3M
      }
540
10.8M
    }
541
3.63M
  }
542
6.55M
  for (ksg = ksg_start; ksg < PVC_NBLOW; ksg++) {
543
4.91M
    if (E[ksg] > (FIXP_DBL)0) {
544
      /* 10/log2(10) = 0.752574989159953 * 2^2 */
545
3.33M
      int exp_log;
546
3.33M
      FIXP_DBL nrg = CalcLog2(E[ksg], 2 * qmfExponent + 2, &exp_log);
547
3.33M
      nrg = fMult(nrg, FL2FXCONST_SGL(LOG10FAC));
548
3.33M
      nrg = scaleValue(nrg, exp_log - PVC_ESG_EXP + 2);
549
3.33M
      pEsg[ksg] = fMax(nrg, FL2FXCONST_DBL(-10.0 / (1 << PVC_ESG_EXP)));
550
3.33M
    } else {
551
1.58M
      pEsg[ksg] =
552
1.58M
          FL2FXCONST_DBL(-10.0 / (1 << PVC_ESG_EXP)); /* 10*log10(0.1) */
553
1.58M
    }
554
4.91M
  }
555
556
  /* Time domain smoothing of subband-grouped energy */
557
1.64M
  {
558
1.64M
    int idx = pPvcStaticData->Esg_slot_index;
559
1.64M
    FIXP_DBL *pEsg_filt;
560
1.64M
    FIXP_SGL SCcoeff;
561
562
1.64M
    E[0] = E[1] = E[2] = (FIXP_DBL)0;
563
9.39M
    for (i = 0; i < pPvcDynamicData->ns; i++) {
564
7.75M
      SCcoeff = pPvcDynamicData->pSCcoeffs[i];
565
7.75M
      pEsg_filt = pPvcStaticData->Esg[idx];
566
      /* Div2 is compensated by scaling of coeff table */
567
7.75M
      E[0] = fMultAddDiv2(E[0], pEsg_filt[0], SCcoeff);
568
7.75M
      E[1] = fMultAddDiv2(E[1], pEsg_filt[1], SCcoeff);
569
7.75M
      E[2] = fMultAddDiv2(E[2], pEsg_filt[2], SCcoeff);
570
7.75M
      if (i >= pPvcDynamicData->pastEsgSlotsAvail) {
571
        /* if past Esg values are not available use the ones from the last valid
572
         * slot */
573
576k
        continue;
574
576k
      }
575
7.17M
      if (idx > 0) {
576
6.77M
        idx--;
577
6.77M
      } else {
578
396k
        idx += PVC_NS_MAX - 1;
579
396k
      }
580
7.17M
    }
581
1.64M
  }
582
583
  /* SBR envelope scalefactor prediction */
584
1.64M
  {
585
1.64M
    int E_high_exp[PVC_NBHIGH_MAX];
586
1.64M
    int E_high_exp_max = 0;
587
1.64M
    int pvcTab1ID;
588
1.64M
    int pvcTab2ID = (int)pPvcDynamicData->pPvcID[timeSlotNumber];
589
1.64M
    const UCHAR *pTab1, *pTab2;
590
1.64M
    if (pvcTab2ID < pPvcDynamicData->pPVCTab1_dp[0]) {
591
185k
      pvcTab1ID = 0;
592
1.45M
    } else if (pvcTab2ID < pPvcDynamicData->pPVCTab1_dp[1]) {
593
170k
      pvcTab1ID = 1;
594
1.28M
    } else {
595
1.28M
      pvcTab1ID = 2;
596
1.28M
    }
597
1.64M
    pTab1 = &(pPvcDynamicData
598
1.64M
                  ->pPVCTab1[pvcTab1ID * PVC_NBLOW * pPvcDynamicData->nbHigh]);
599
1.64M
    pTab2 = &(pPvcDynamicData->pPVCTab2[pvcTab2ID * pPvcDynamicData->nbHigh]);
600
11.9M
    for (ksg = 0; ksg < pPvcDynamicData->nbHigh; ksg++) {
601
10.3M
      FIXP_SGL predCoeff;
602
10.3M
      FIXP_DBL accu;
603
10.3M
      int predCoeff_exp, kb;
604
10.3M
      E_high_exp[ksg] = 0;
605
606
      /* residual part */
607
10.3M
      accu = ((LONG)(SCHAR)*pTab2++) << (DFRACT_BITS - 8 - PVC_ESG_EXP - 2 +
608
10.3M
                                         pPvcDynamicData->pScalingCoef[3]);
609
610
      /* linear combination of lower grouped energies part */
611
41.2M
      for (kb = 0; kb < PVC_NBLOW; kb++) {
612
30.9M
        predCoeff = (FIXP_SGL)(
613
30.9M
            (SHORT)(SCHAR)pTab1[kb * pPvcDynamicData->nbHigh + ksg] << 8);
614
30.9M
        predCoeff_exp = -(pPvcDynamicData->pScalingCoef[kb] + 1 -
615
30.9M
                          2); /* +1 to compensate for Div2; -2 for accu */
616
30.9M
        accu += fMultDiv2(E[kb], predCoeff) >> predCoeff_exp;
617
30.9M
      }
618
      /* convert back to linear domain */
619
10.3M
      accu = fMult(accu, FL2FXCONST_SGL(LOG10FAC_INV));
620
10.3M
      accu = f2Pow(accu, PVC_ESG_EXP - 1 + 2,
621
10.3M
                   &predCoeff_exp); /* -1 compensates for exponent of
622
                                       LOG10FAC_INV; +2 for accu */
623
10.3M
      predictedEsgSlot[ksg] = accu;
624
10.3M
      E_high_exp[ksg] = predCoeff_exp;
625
10.3M
      if (predCoeff_exp > E_high_exp_max) {
626
1.89M
        E_high_exp_max = predCoeff_exp;
627
1.89M
      }
628
10.3M
    }
629
630
    /* rescale output vector according to largest exponent */
631
11.9M
    for (ksg = 0; ksg < pPvcDynamicData->nbHigh; ksg++) {
632
10.3M
      int scale = fMin(E_high_exp_max - E_high_exp[ksg], DFRACT_BITS - 1);
633
10.3M
      predictedEsgSlot[ksg] = predictedEsgSlot[ksg] >> scale;
634
10.3M
    }
635
1.64M
    *predictedEsg_exp = E_high_exp_max;
636
1.64M
  }
637
638
1.64M
  pPvcStaticData->Esg_slot_index =
639
1.64M
      (pPvcStaticData->Esg_slot_index + 1) & (PVC_NS_MAX - 1);
640
1.64M
  pPvcDynamicData->pastEsgSlotsAvail =
641
1.64M
      fMin(pPvcDynamicData->pastEsgSlotsAvail + 1, PVC_NS_MAX - 1);
642
1.64M
  return;
643
1.64M
}
644
645
/* call if pvcMode = 0,1,2 */
646
void pvcEndFrame(PVC_STATIC_DATA *pPvcStaticData,
647
290k
                 PVC_DYNAMIC_DATA *pPvcDynamicData) {
648
290k
  pPvcStaticData->pvc_mode_last = pPvcDynamicData->pvc_mode;
649
290k
  pPvcStaticData->kx_last = pPvcDynamicData->kx;
650
651
290k
  if (pPvcDynamicData->pvc_mode == 0) return;
652
653
102k
  {
654
102k
    int t, max = -100;
655
1.74M
    for (t = pPvcDynamicData->pvcBorder0; t < PVC_NTIMESLOT; t++) {
656
1.64M
      if (pPvcDynamicData->predEsg_exp[t] > max) {
657
206k
        max = pPvcDynamicData->predEsg_exp[t];
658
206k
      }
659
1.64M
    }
660
102k
    pPvcDynamicData->predEsg_expMax = max;
661
102k
  }
662
102k
  return;
663
290k
}
664
665
void expandPredEsg(const PVC_DYNAMIC_DATA *pPvcDynamicData, const int timeSlot,
666
                   const int lengthOutputVector, FIXP_DBL *pOutput,
667
1.64M
                   SCHAR *pOutput_exp) {
668
1.64M
  int k = 0, ksg;
669
1.64M
  const FIXP_DBL *predEsg = pPvcDynamicData->predEsg[timeSlot];
670
671
11.9M
  for (ksg = 0; ksg < pPvcDynamicData->nbHigh; ksg++) {
672
65.5M
    for (; k < pPvcDynamicData->sg_offset_high_kx[ksg + 1]; k++) {
673
55.2M
      pOutput[k] = predEsg[ksg];
674
55.2M
      pOutput_exp[k] = (SCHAR)pPvcDynamicData->predEsg_exp[timeSlot];
675
55.2M
    }
676
10.3M
  }
677
1.64M
  ksg--;
678
38.2M
  for (; k < lengthOutputVector; k++) {
679
36.6M
    pOutput[k] = predEsg[ksg];
680
36.6M
    pOutput_exp[k] = (SCHAR)pPvcDynamicData->predEsg_exp[timeSlot];
681
36.6M
  }
682
683
1.64M
  return;
684
1.64M
}