Coverage Report

Created: 2025-07-18 06:04

/src/aac/libSBRdec/src/pvc_dec.cpp
Line
Count
Source (jump to first uncovered line)
1
/* -----------------------------------------------------------------------------
2
Software License for The Fraunhofer FDK AAC Codec Library for Android
3
4
© Copyright  1995 - 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
0
#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
0
#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
0
                 const int pvcBorder0, const UCHAR *pPvcID) {
399
0
  int lbw, hbw, i, temp;
400
0
  pPvcDynamicData->pvc_mode = pvcMode;
401
0
  pPvcDynamicData->kx = kx;
402
0
  pPvcDynamicData->RATE = RATE;
403
404
0
  switch (pvcMode) {
405
0
    case 0:
406
      /* legacy SBR, nothing to do */
407
0
      return 0;
408
0
    case 1:
409
0
      pPvcDynamicData->nbHigh = 8;
410
0
      pPvcDynamicData->pPVCTab1 = (const UCHAR *)g_3a_pvcTab1_mode1;
411
0
      pPvcDynamicData->pPVCTab2 = (const UCHAR *)g_2a_pvcTab2_mode1;
412
0
      pPvcDynamicData->pPVCTab1_dp = g_a_pvcTab1_dp_mode1;
413
0
      pPvcDynamicData->pScalingCoef = g_a_scalingCoef_mode1;
414
0
      hbw = 8 / RATE;
415
0
      break;
416
0
    case 2:
417
0
      pPvcDynamicData->nbHigh = 6;
418
0
      pPvcDynamicData->pPVCTab1 = (const UCHAR *)g_3a_pvcTab1_mode2;
419
0
      pPvcDynamicData->pPVCTab2 = (const UCHAR *)g_2a_pvcTab2_mode2;
420
0
      pPvcDynamicData->pPVCTab1_dp = g_a_pvcTab1_dp_mode2;
421
0
      pPvcDynamicData->pScalingCoef = g_a_scalingCoef_mode2;
422
0
      hbw = 12 / RATE;
423
0
      break;
424
0
    default:
425
      /* invalid pvcMode */
426
0
      return 1;
427
0
  }
428
429
0
  pPvcDynamicData->pvcBorder0 = pvcBorder0;
430
0
  UCHAR pvcBorder0_last = pPvcStaticData->pvcBorder0;
431
0
  pPvcStaticData->pvcBorder0 = pvcBorder0;
432
0
  pPvcDynamicData->pPvcID = pPvcID;
433
434
0
  pPvcDynamicData->ns = ns;
435
0
  switch (ns) {
436
0
    case 16:
437
0
      pPvcDynamicData->pSCcoeffs = pvc_SC_16;
438
0
      break;
439
0
    case 12:
440
0
      pPvcDynamicData->pSCcoeffs = pvc_SC_12;
441
0
      break;
442
0
    case 4:
443
0
      pPvcDynamicData->pSCcoeffs = pvc_SC_4;
444
0
      break;
445
0
    case 3:
446
0
      pPvcDynamicData->pSCcoeffs = pvc_SC_3;
447
0
      break;
448
0
    default:
449
0
      return 1;
450
0
  }
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
0
  if ((pPvcStaticData->pvc_mode_last == 0) || (pPvcStaticData->kx_last != kx)) {
459
0
    pPvcDynamicData->pastEsgSlotsAvail = 0;
460
0
  } else {
461
0
    pPvcDynamicData->pastEsgSlotsAvail = PVC_NS_MAX - pvcBorder0_last;
462
0
  }
463
464
0
  lbw = 8 / RATE;
465
466
0
  temp = kx;
467
0
  for (i = PVC_NBLOW; i >= 0; i--) {
468
0
    pPvcDynamicData->sg_offset_low[i] = temp;
469
0
    temp -= lbw;
470
0
  }
471
472
0
  temp = 0;
473
0
  for (i = 0; i <= pPvcDynamicData->nbHigh; i++) {
474
0
    pPvcDynamicData->sg_offset_high_kx[i] = temp;
475
0
    temp += hbw;
476
0
  }
477
478
0
  return 0;
479
0
}
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
0
                    const int qmfExponentCurrent) {
487
0
  int t;
488
0
  FIXP_DBL *predictedEsgSlot;
489
0
  int RATE = pPvcDynamicData->RATE;
490
0
  int pvcBorder0 = pPvcDynamicData->pvcBorder0;
491
492
0
  for (t = pvcBorder0; t < PVC_NTIMESLOT; t++) {
493
0
    int *pPredEsg_exp = &pPvcDynamicData->predEsg_exp[t];
494
0
    predictedEsgSlot = pPvcDynamicData->predEsg[t];
495
496
0
    pvcDecodeTimeSlot(
497
0
        pPvcStaticData, pPvcDynamicData, &qmfBufferReal[t * RATE],
498
0
        &qmfBufferImag[t * RATE],
499
0
        (t * RATE < overlap) ? qmfExponentOverlap : qmfExponentCurrent,
500
0
        pvcBorder0, t, predictedEsgSlot, pPredEsg_exp);
501
0
  }
502
503
0
  return;
504
0
}
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
0
                       int *predictedEsg_exp) {
512
0
  int i, band, ksg, ksg_start = 0;
513
0
  int RATE = pPvcDynamicData->RATE;
514
0
  int Esg_index = pPvcStaticData->Esg_slot_index;
515
0
  const SCHAR *sg_borders = pPvcDynamicData->sg_offset_low;
516
0
  FIXP_DBL *pEsg = pPvcStaticData->Esg[Esg_index];
517
0
  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
0
  for (ksg = 0; sg_borders[ksg] < 0; ksg++) {
526
0
    pEsg[ksg] = FL2FXCONST_DBL(-10.0 / (1 << PVC_ESG_EXP)); /* 10*log10(0.1) */
527
0
    ksg_start++;
528
0
  }
529
530
0
  for (i = 0; i < RATE; i++) {
531
0
    FIXP_DBL *qmfR, *qmfI;
532
0
    qmfR = qmfSlotReal[i];
533
0
    qmfI = qmfSlotImag[i];
534
0
    for (ksg = ksg_start; ksg < PVC_NBLOW; ksg++) {
535
0
      for (band = sg_borders[ksg]; band < sg_borders[ksg + 1]; band++) {
536
        /* The division by 8 == (RATE*lbw) is required algorithmically */
537
0
        E[ksg] +=
538
0
            ((fPow2Div2(qmfR[band]) >> 1) + (fPow2Div2(qmfI[band]) >> 1)) >> 3;
539
0
      }
540
0
    }
541
0
  }
542
0
  for (ksg = ksg_start; ksg < PVC_NBLOW; ksg++) {
543
0
    if (E[ksg] > (FIXP_DBL)0) {
544
      /* 10/log2(10) = 0.752574989159953 * 2^2 */
545
0
      int exp_log;
546
0
      FIXP_DBL nrg = CalcLog2(E[ksg], 2 * qmfExponent + 2, &exp_log);
547
0
      nrg = fMult(nrg, FL2FXCONST_SGL(LOG10FAC));
548
0
      nrg = scaleValue(nrg, exp_log - PVC_ESG_EXP + 2);
549
0
      pEsg[ksg] = fMax(nrg, FL2FXCONST_DBL(-10.0 / (1 << PVC_ESG_EXP)));
550
0
    } else {
551
0
      pEsg[ksg] =
552
0
          FL2FXCONST_DBL(-10.0 / (1 << PVC_ESG_EXP)); /* 10*log10(0.1) */
553
0
    }
554
0
  }
555
556
  /* Time domain smoothing of subband-grouped energy */
557
0
  {
558
0
    int idx = pPvcStaticData->Esg_slot_index;
559
0
    FIXP_DBL *pEsg_filt;
560
0
    FIXP_SGL SCcoeff;
561
562
0
    E[0] = E[1] = E[2] = (FIXP_DBL)0;
563
0
    for (i = 0; i < pPvcDynamicData->ns; i++) {
564
0
      SCcoeff = pPvcDynamicData->pSCcoeffs[i];
565
0
      pEsg_filt = pPvcStaticData->Esg[idx];
566
      /* Div2 is compensated by scaling of coeff table */
567
0
      E[0] = fMultAddDiv2(E[0], pEsg_filt[0], SCcoeff);
568
0
      E[1] = fMultAddDiv2(E[1], pEsg_filt[1], SCcoeff);
569
0
      E[2] = fMultAddDiv2(E[2], pEsg_filt[2], SCcoeff);
570
0
      if (i >= pPvcDynamicData->pastEsgSlotsAvail) {
571
        /* if past Esg values are not available use the ones from the last valid
572
         * slot */
573
0
        continue;
574
0
      }
575
0
      if (idx > 0) {
576
0
        idx--;
577
0
      } else {
578
0
        idx += PVC_NS_MAX - 1;
579
0
      }
580
0
    }
581
0
  }
582
583
  /* SBR envelope scalefactor prediction */
584
0
  {
585
0
    int E_high_exp[PVC_NBHIGH_MAX];
586
0
    int E_high_exp_max = 0;
587
0
    int pvcTab1ID;
588
0
    int pvcTab2ID = (int)pPvcDynamicData->pPvcID[timeSlotNumber];
589
0
    const UCHAR *pTab1, *pTab2;
590
0
    if (pvcTab2ID < pPvcDynamicData->pPVCTab1_dp[0]) {
591
0
      pvcTab1ID = 0;
592
0
    } else if (pvcTab2ID < pPvcDynamicData->pPVCTab1_dp[1]) {
593
0
      pvcTab1ID = 1;
594
0
    } else {
595
0
      pvcTab1ID = 2;
596
0
    }
597
0
    pTab1 = &(pPvcDynamicData
598
0
                  ->pPVCTab1[pvcTab1ID * PVC_NBLOW * pPvcDynamicData->nbHigh]);
599
0
    pTab2 = &(pPvcDynamicData->pPVCTab2[pvcTab2ID * pPvcDynamicData->nbHigh]);
600
0
    for (ksg = 0; ksg < pPvcDynamicData->nbHigh; ksg++) {
601
0
      FIXP_SGL predCoeff;
602
0
      FIXP_DBL accu;
603
0
      int predCoeff_exp, kb;
604
0
      E_high_exp[ksg] = 0;
605
606
      /* residual part */
607
0
      accu = ((LONG)(SCHAR)*pTab2++) << (DFRACT_BITS - 8 - PVC_ESG_EXP - 2 +
608
0
                                         pPvcDynamicData->pScalingCoef[3]);
609
610
      /* linear combination of lower grouped energies part */
611
0
      for (kb = 0; kb < PVC_NBLOW; kb++) {
612
0
        predCoeff = (FIXP_SGL)(
613
0
            (SHORT)(SCHAR)pTab1[kb * pPvcDynamicData->nbHigh + ksg] << 8);
614
0
        predCoeff_exp = -(pPvcDynamicData->pScalingCoef[kb] + 1 -
615
0
                          2); /* +1 to compensate for Div2; -2 for accu */
616
0
        accu += fMultDiv2(E[kb], predCoeff) >> predCoeff_exp;
617
0
      }
618
      /* convert back to linear domain */
619
0
      accu = fMult(accu, FL2FXCONST_SGL(LOG10FAC_INV));
620
0
      accu = f2Pow(accu, PVC_ESG_EXP - 1 + 2,
621
0
                   &predCoeff_exp); /* -1 compensates for exponent of
622
                                       LOG10FAC_INV; +2 for accu */
623
0
      predictedEsgSlot[ksg] = accu;
624
0
      E_high_exp[ksg] = predCoeff_exp;
625
0
      if (predCoeff_exp > E_high_exp_max) {
626
0
        E_high_exp_max = predCoeff_exp;
627
0
      }
628
0
    }
629
630
    /* rescale output vector according to largest exponent */
631
0
    for (ksg = 0; ksg < pPvcDynamicData->nbHigh; ksg++) {
632
0
      int scale = fMin(E_high_exp_max - E_high_exp[ksg], DFRACT_BITS - 1);
633
0
      predictedEsgSlot[ksg] = predictedEsgSlot[ksg] >> scale;
634
0
    }
635
0
    *predictedEsg_exp = E_high_exp_max;
636
0
  }
637
638
0
  pPvcStaticData->Esg_slot_index =
639
0
      (pPvcStaticData->Esg_slot_index + 1) & (PVC_NS_MAX - 1);
640
0
  pPvcDynamicData->pastEsgSlotsAvail =
641
0
      fMin(pPvcDynamicData->pastEsgSlotsAvail + 1, PVC_NS_MAX - 1);
642
0
  return;
643
0
}
644
645
/* call if pvcMode = 0,1,2 */
646
void pvcEndFrame(PVC_STATIC_DATA *pPvcStaticData,
647
0
                 PVC_DYNAMIC_DATA *pPvcDynamicData) {
648
0
  pPvcStaticData->pvc_mode_last = pPvcDynamicData->pvc_mode;
649
0
  pPvcStaticData->kx_last = pPvcDynamicData->kx;
650
651
0
  if (pPvcDynamicData->pvc_mode == 0) return;
652
653
0
  {
654
0
    int t, max = -100;
655
0
    for (t = pPvcDynamicData->pvcBorder0; t < PVC_NTIMESLOT; t++) {
656
0
      if (pPvcDynamicData->predEsg_exp[t] > max) {
657
0
        max = pPvcDynamicData->predEsg_exp[t];
658
0
      }
659
0
    }
660
0
    pPvcDynamicData->predEsg_expMax = max;
661
0
  }
662
0
  return;
663
0
}
664
665
void expandPredEsg(const PVC_DYNAMIC_DATA *pPvcDynamicData, const int timeSlot,
666
                   const int lengthOutputVector, FIXP_DBL *pOutput,
667
0
                   SCHAR *pOutput_exp) {
668
0
  int k = 0, ksg;
669
0
  const FIXP_DBL *predEsg = pPvcDynamicData->predEsg[timeSlot];
670
671
0
  for (ksg = 0; ksg < pPvcDynamicData->nbHigh; ksg++) {
672
0
    for (; k < pPvcDynamicData->sg_offset_high_kx[ksg + 1]; k++) {
673
0
      pOutput[k] = predEsg[ksg];
674
0
      pOutput_exp[k] = (SCHAR)pPvcDynamicData->predEsg_exp[timeSlot];
675
0
    }
676
0
  }
677
0
  ksg--;
678
0
  for (; k < lengthOutputVector; k++) {
679
0
    pOutput[k] = predEsg[ksg];
680
0
    pOutput_exp[k] = (SCHAR)pPvcDynamicData->predEsg_exp[timeSlot];
681
0
  }
682
683
0
  return;
684
0
}