Coverage Report

Created: 2026-01-09 06:47

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/aac/libAACdec/src/rvlcconceal.cpp
Line
Count
Source
1
/* -----------------------------------------------------------------------------
2
Software License for The Fraunhofer FDK AAC Codec Library for Android
3
4
© Copyright  1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten
5
Forschung e.V. All rights reserved.
6
7
 1.    INTRODUCTION
8
The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software
9
that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding
10
scheme for digital audio. This FDK AAC Codec software is intended to be used on
11
a wide variety of Android devices.
12
13
AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient
14
general perceptual audio codecs. AAC-ELD is considered the best-performing
15
full-bandwidth communications codec by independent studies and is widely
16
deployed. AAC has been standardized by ISO and IEC as part of the MPEG
17
specifications.
18
19
Patent licenses for necessary patent claims for the FDK AAC Codec (including
20
those of Fraunhofer) may be obtained through Via Licensing
21
(www.vialicensing.com) or through the respective patent owners individually for
22
the purpose of encoding or decoding bit streams in products that are compliant
23
with the ISO/IEC MPEG audio standards. Please note that most manufacturers of
24
Android devices already license these patent claims through Via Licensing or
25
directly from the patent owners, and therefore FDK AAC Codec software may
26
already be covered under those patent licenses when it is used for those
27
licensed purposes only.
28
29
Commercially-licensed AAC software libraries, including floating-point versions
30
with enhanced sound quality, are also available from Fraunhofer. Users are
31
encouraged to check the Fraunhofer website for additional applications
32
information and documentation.
33
34
2.    COPYRIGHT LICENSE
35
36
Redistribution and use in source and binary forms, with or without modification,
37
are permitted without payment of copyright license fees provided that you
38
satisfy the following conditions:
39
40
You must retain the complete text of this software license in redistributions of
41
the FDK AAC Codec or your modifications thereto in source code form.
42
43
You must retain the complete text of this software license in the documentation
44
and/or other materials provided with redistributions of the FDK AAC Codec or
45
your modifications thereto in binary form. You must make available free of
46
charge copies of the complete source code of the FDK AAC Codec and your
47
modifications thereto to recipients of copies in binary form.
48
49
The name of Fraunhofer may not be used to endorse or promote products derived
50
from this library without prior written permission.
51
52
You may not charge copyright license fees for anyone to use, copy or distribute
53
the FDK AAC Codec software or your modifications thereto.
54
55
Your modified versions of the FDK AAC Codec must carry prominent notices stating
56
that you changed the software and the date of any change. For modified versions
57
of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android"
58
must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK
59
AAC Codec Library for Android."
60
61
3.    NO PATENT LICENSE
62
63
NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without
64
limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE.
65
Fraunhofer provides no warranty of patent non-infringement with respect to this
66
software.
67
68
You may use this FDK AAC Codec software or modifications thereto only for
69
purposes that are authorized by appropriate patent licenses.
70
71
4.    DISCLAIMER
72
73
This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright
74
holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
75
including but not limited to the implied warranties of merchantability and
76
fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
77
CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary,
78
or consequential damages, including but not limited to procurement of substitute
79
goods or services; loss of use, data, or profits, or business interruption,
80
however caused and on any theory of liability, whether in contract, strict
81
liability, or tort (including negligence), arising in any way out of the use of
82
this software, even if advised of the possibility of such damage.
83
84
5.    CONTACT INFORMATION
85
86
Fraunhofer Institute for Integrated Circuits IIS
87
Attention: Audio and Multimedia Departments - FDK AAC LL
88
Am Wolfsmantel 33
89
91058 Erlangen, Germany
90
91
www.iis.fraunhofer.de/amm
92
amm-info@iis.fraunhofer.de
93
----------------------------------------------------------------------------- */
94
95
/**************************** AAC decoder library ******************************
96
97
   Author(s):
98
99
   Description:
100
101
*******************************************************************************/
102
103
/*!
104
  \file
105
  \brief  rvlc concealment
106
  \author Josef Hoepfl
107
*/
108
109
#include "rvlcconceal.h"
110
111
#include "block.h"
112
#include "rvlc.h"
113
114
/*---------------------------------------------------------------------------------------------
115
  function:      calcRefValFwd
116
117
  description:   The function determines the scalefactor which is closed to the
118
scalefactorband conceal_min. The same is done for intensity data and noise
119
energies.
120
-----------------------------------------------------------------------------------------------
121
  output:        - reference value scf
122
                 - reference value internsity data
123
                 - reference value noise energy
124
-----------------------------------------------------------------------------------------------
125
  return:        -
126
--------------------------------------------------------------------------------------------
127
*/
128
129
static void calcRefValFwd(CErRvlcInfo *pRvlc,
130
                          CAacDecoderChannelInfo *pAacDecoderChannelInfo,
131
39.1k
                          int *refIsFwd, int *refNrgFwd, int *refScfFwd) {
132
39.1k
  int band, bnds, group, startBand;
133
39.1k
  int idIs, idNrg, idScf;
134
39.1k
  int conceal_min, conceal_group_min;
135
39.1k
  int MaximumScaleFactorBands;
136
137
39.1k
  if (GetWindowSequence(&pAacDecoderChannelInfo->icsInfo) == BLOCK_SHORT)
138
758
    MaximumScaleFactorBands = 16;
139
38.3k
  else
140
38.3k
    MaximumScaleFactorBands = 64;
141
142
39.1k
  conceal_min = pRvlc->conceal_min % MaximumScaleFactorBands;
143
39.1k
  conceal_group_min = pRvlc->conceal_min / MaximumScaleFactorBands;
144
145
  /* calculate first reference value for approach in forward direction */
146
39.1k
  idIs = idNrg = idScf = 1;
147
148
  /* set reference values */
149
39.1k
  *refIsFwd = -SF_OFFSET;
150
39.1k
  *refNrgFwd = pAacDecoderChannelInfo->pDynData->RawDataInfo.GlobalGain -
151
39.1k
               SF_OFFSET - 90 - 256;
152
39.1k
  *refScfFwd =
153
39.1k
      pAacDecoderChannelInfo->pDynData->RawDataInfo.GlobalGain - SF_OFFSET;
154
155
39.1k
  startBand = conceal_min - 1;
156
79.0k
  for (group = conceal_group_min; group >= 0; group--) {
157
63.2k
    for (band = startBand; band >= 0; band--) {
158
23.3k
      bnds = 16 * group + band;
159
23.3k
      switch (pAacDecoderChannelInfo->pDynData->aCodeBook[bnds]) {
160
3.37k
        case ZERO_HCB:
161
3.37k
          break;
162
1.03k
        case INTENSITY_HCB:
163
1.49k
        case INTENSITY_HCB2:
164
1.49k
          if (idIs) {
165
480
            *refIsFwd =
166
480
                pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds];
167
480
            idIs = 0; /* reference value has been set */
168
480
          }
169
1.49k
          break;
170
1.08k
        case NOISE_HCB:
171
1.08k
          if (idNrg) {
172
352
            *refNrgFwd =
173
352
                pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds];
174
352
            idNrg = 0; /* reference value has been set */
175
352
          }
176
1.08k
          break;
177
17.4k
        default:
178
17.4k
          if (idScf) {
179
7.63k
            *refScfFwd =
180
7.63k
                pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds];
181
7.63k
            idScf = 0; /* reference value has been set */
182
7.63k
          }
183
17.4k
          break;
184
23.3k
      }
185
23.3k
    }
186
39.9k
    startBand = pRvlc->maxSfbTransmitted - 1;
187
39.9k
  }
188
39.1k
}
189
190
/*---------------------------------------------------------------------------------------------
191
  function:      calcRefValBwd
192
193
  description:   The function determines the scalefactor which is closed to the
194
scalefactorband conceal_max. The same is done for intensity data and noise
195
energies.
196
-----------------------------------------------------------------------------------------------
197
  output:        - reference value scf
198
                 - reference value internsity data
199
                 - reference value noise energy
200
-----------------------------------------------------------------------------------------------
201
  return:        -
202
--------------------------------------------------------------------------------------------
203
*/
204
205
static void calcRefValBwd(CErRvlcInfo *pRvlc,
206
                          CAacDecoderChannelInfo *pAacDecoderChannelInfo,
207
39.1k
                          int *refIsBwd, int *refNrgBwd, int *refScfBwd) {
208
39.1k
  int band, bnds, group, startBand;
209
39.1k
  int idIs, idNrg, idScf;
210
39.1k
  int conceal_max, conceal_group_max;
211
39.1k
  int MaximumScaleFactorBands;
212
213
39.1k
  if (GetWindowSequence(&pAacDecoderChannelInfo->icsInfo) == BLOCK_SHORT)
214
758
    MaximumScaleFactorBands = 16;
215
38.3k
  else
216
38.3k
    MaximumScaleFactorBands = 64;
217
218
39.1k
  conceal_max = pRvlc->conceal_max % MaximumScaleFactorBands;
219
39.1k
  conceal_group_max = pRvlc->conceal_max / MaximumScaleFactorBands;
220
221
  /* calculate first reference value for approach in backward direction */
222
39.1k
  idIs = idNrg = idScf = 1;
223
224
  /* set reference values */
225
39.1k
  *refIsBwd = pRvlc->dpcm_is_last_position - SF_OFFSET;
226
39.1k
  *refNrgBwd = pRvlc->rev_global_gain + pRvlc->dpcm_noise_last_position -
227
39.1k
               SF_OFFSET - 90 - 256 + pRvlc->dpcm_noise_nrg;
228
39.1k
  *refScfBwd = pRvlc->rev_global_gain - SF_OFFSET;
229
230
39.1k
  startBand = conceal_max + 1;
231
232
  /* if needed, re-set reference values */
233
80.0k
  for (group = conceal_group_max; group < pRvlc->numWindowGroups; group++) {
234
69.4k
    for (band = startBand; band < pRvlc->maxSfbTransmitted; band++) {
235
28.4k
      bnds = 16 * group + band;
236
28.4k
      switch (pAacDecoderChannelInfo->pDynData->aCodeBook[bnds]) {
237
6.97k
        case ZERO_HCB:
238
6.97k
          break;
239
781
        case INTENSITY_HCB:
240
1.89k
        case INTENSITY_HCB2:
241
1.89k
          if (idIs) {
242
472
            *refIsBwd =
243
472
                pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[bnds];
244
472
            idIs = 0; /* reference value has been set */
245
472
          }
246
1.89k
          break;
247
805
        case NOISE_HCB:
248
805
          if (idNrg) {
249
208
            *refNrgBwd =
250
208
                pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[bnds];
251
208
            idNrg = 0; /* reference value has been set */
252
208
          }
253
805
          break;
254
18.7k
        default:
255
18.7k
          if (idScf) {
256
8.00k
            *refScfBwd =
257
8.00k
                pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[bnds];
258
8.00k
            idScf = 0; /* reference value has been set */
259
8.00k
          }
260
18.7k
          break;
261
28.4k
      }
262
28.4k
    }
263
40.9k
    startBand = 0;
264
40.9k
  }
265
39.1k
}
266
267
/*---------------------------------------------------------------------------------------------
268
  function:      BidirectionalEstimation_UseLowerScfOfCurrentFrame
269
270
  description:   This approach by means of bidirectional estimation is generally
271
performed when a single bit error has been detected, the bit error can be
272
isolated between 'conceal_min' and 'conceal_max' and the 'sf_concealment' flag
273
is not set. The sets of scalefactors decoded in forward and backward direction
274
are compared with each other. The smaller scalefactor will be considered as the
275
correct one respectively. The reconstruction of the scalefactors with this
276
approach archieve good results in audio quality. The strategy must be applied to
277
scalefactors, intensity data and noise energy seperately.
278
-----------------------------------------------------------------------------------------------
279
  output:        Concealed scalefactor, noise energy and intensity data between
280
conceal_min and conceal_max
281
-----------------------------------------------------------------------------------------------
282
  return:        -
283
--------------------------------------------------------------------------------------------
284
*/
285
286
void BidirectionalEstimation_UseLowerScfOfCurrentFrame(
287
47.7k
    CAacDecoderChannelInfo *pAacDecoderChannelInfo) {
288
47.7k
  CErRvlcInfo *pRvlc =
289
47.7k
      &pAacDecoderChannelInfo->pComData->overlay.aac.erRvlcInfo;
290
47.7k
  int band, bnds, startBand, endBand, group;
291
47.7k
  int conceal_min, conceal_max;
292
47.7k
  int conceal_group_min, conceal_group_max;
293
47.7k
  int MaximumScaleFactorBands;
294
295
47.7k
  if (GetWindowSequence(&pAacDecoderChannelInfo->icsInfo) == BLOCK_SHORT) {
296
5.49k
    MaximumScaleFactorBands = 16;
297
42.2k
  } else {
298
42.2k
    MaximumScaleFactorBands = 64;
299
42.2k
  }
300
301
  /* If an error was detected just in forward or backward direction, set the
302
     corresponding border for concealment to a appropriate scalefactor band. The
303
     border is set to first or last sfb respectively, because the error will
304
     possibly not follow directly after the corrupt bit but just after decoding
305
     some more (wrong) scalefactors. */
306
47.7k
  if (pRvlc->conceal_min == CONCEAL_MIN_INIT) pRvlc->conceal_min = 0;
307
308
47.7k
  if (pRvlc->conceal_max == CONCEAL_MAX_INIT)
309
3.43k
    pRvlc->conceal_max =
310
3.43k
        (pRvlc->numWindowGroups - 1) * 16 + pRvlc->maxSfbTransmitted - 1;
311
312
47.7k
  conceal_min = pRvlc->conceal_min % MaximumScaleFactorBands;
313
47.7k
  conceal_group_min = pRvlc->conceal_min / MaximumScaleFactorBands;
314
47.7k
  conceal_max = pRvlc->conceal_max % MaximumScaleFactorBands;
315
47.7k
  conceal_group_max = pRvlc->conceal_max / MaximumScaleFactorBands;
316
317
47.7k
  if (pRvlc->conceal_min == pRvlc->conceal_max) {
318
39.1k
    int refIsFwd, refNrgFwd, refScfFwd;
319
39.1k
    int refIsBwd, refNrgBwd, refScfBwd;
320
321
39.1k
    bnds = pRvlc->conceal_min;
322
39.1k
    calcRefValFwd(pRvlc, pAacDecoderChannelInfo, &refIsFwd, &refNrgFwd,
323
39.1k
                  &refScfFwd);
324
39.1k
    calcRefValBwd(pRvlc, pAacDecoderChannelInfo, &refIsBwd, &refNrgBwd,
325
39.1k
                  &refScfBwd);
326
327
39.1k
    switch (pAacDecoderChannelInfo->pDynData->aCodeBook[bnds]) {
328
26.3k
      case ZERO_HCB:
329
26.3k
        break;
330
960
      case INTENSITY_HCB:
331
1.11k
      case INTENSITY_HCB2:
332
1.11k
        if (refIsFwd < refIsBwd)
333
112
          pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = refIsFwd;
334
1.00k
        else
335
1.00k
          pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = refIsBwd;
336
1.11k
        break;
337
534
      case NOISE_HCB:
338
534
        if (refNrgFwd < refNrgBwd)
339
316
          pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = refNrgFwd;
340
218
        else
341
218
          pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = refNrgBwd;
342
534
        break;
343
11.0k
      default:
344
11.0k
        if (refScfFwd < refScfBwd)
345
8.56k
          pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = refScfFwd;
346
2.52k
        else
347
2.52k
          pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = refScfBwd;
348
11.0k
        break;
349
39.1k
    }
350
39.1k
  } else {
351
8.66k
    pAacDecoderChannelInfo->pComData->overlay.aac
352
8.66k
        .aRvlcScfFwd[pRvlc->conceal_max] =
353
8.66k
        pAacDecoderChannelInfo->pComData->overlay.aac
354
8.66k
            .aRvlcScfBwd[pRvlc->conceal_max];
355
8.66k
    pAacDecoderChannelInfo->pComData->overlay.aac
356
8.66k
        .aRvlcScfBwd[pRvlc->conceal_min] =
357
8.66k
        pAacDecoderChannelInfo->pComData->overlay.aac
358
8.66k
            .aRvlcScfFwd[pRvlc->conceal_min];
359
360
    /* consider the smaller of the forward and backward decoded value as the
361
     * correct one */
362
8.66k
    startBand = conceal_min;
363
8.66k
    if (conceal_group_min == conceal_group_max)
364
5.20k
      endBand = conceal_max;
365
3.45k
    else
366
3.45k
      endBand = pRvlc->maxSfbTransmitted - 1;
367
368
23.4k
    for (group = conceal_group_min; group <= conceal_group_max; group++) {
369
65.1k
      for (band = startBand; band <= endBand; band++) {
370
50.2k
        bnds = 16 * group + band;
371
50.2k
        if (pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds] <
372
50.2k
            pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[bnds])
373
20.8k
          pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
374
20.8k
              pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds];
375
29.4k
        else
376
29.4k
          pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
377
29.4k
              pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[bnds];
378
50.2k
      }
379
14.8k
      startBand = 0;
380
14.8k
      if ((group + 1) == conceal_group_max) endBand = conceal_max;
381
14.8k
    }
382
8.66k
  }
383
384
  /* now copy all data to the output buffer which needs not to be concealed */
385
47.7k
  if (conceal_group_min == 0)
386
45.1k
    endBand = conceal_min;
387
2.65k
  else
388
2.65k
    endBand = pRvlc->maxSfbTransmitted;
389
105k
  for (group = 0; group <= conceal_group_min; group++) {
390
124k
    for (band = 0; band < endBand; band++) {
391
67.1k
      bnds = 16 * group + band;
392
67.1k
      pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
393
67.1k
          pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds];
394
67.1k
    }
395
57.3k
    if ((group + 1) == conceal_group_min) endBand = conceal_min;
396
57.3k
  }
397
398
47.7k
  startBand = conceal_max + 1;
399
106k
  for (group = conceal_group_max; group < pRvlc->numWindowGroups; group++) {
400
126k
    for (band = startBand; band < pRvlc->maxSfbTransmitted; band++) {
401
67.7k
      bnds = 16 * group + band;
402
67.7k
      pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
403
67.7k
          pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[bnds];
404
67.7k
    }
405
58.4k
    startBand = 0;
406
58.4k
  }
407
47.7k
}
408
409
/*---------------------------------------------------------------------------------------------
410
  function:      BidirectionalEstimation_UseScfOfPrevFrameAsReference
411
412
  description:   This approach by means of bidirectional estimation is generally
413
performed when a single bit error has been detected, the bit error can be
414
isolated between 'conceal_min' and 'conceal_max', the 'sf_concealment' flag is
415
set and the previous frame has the same block type as the current frame. The
416
scalefactor decoded in forward and backward direction and the scalefactor of the
417
previous frame are compared with each other. The smaller scalefactor will be
418
considered as the correct one. At this the codebook of the previous and current
419
frame must be of the same set (scf, nrg, is) in each scalefactorband. Otherwise
420
the scalefactor of the previous frame is not considered in the minimum
421
calculation. The reconstruction of the scalefactors with this approach archieve
422
good results in audio quality. The strategy must be applied to scalefactors,
423
intensity data and noise energy seperately.
424
-----------------------------------------------------------------------------------------------
425
  output:        Concealed scalefactor, noise energy and intensity data between
426
conceal_min and conceal_max
427
-----------------------------------------------------------------------------------------------
428
  return:        -
429
--------------------------------------------------------------------------------------------
430
*/
431
432
void BidirectionalEstimation_UseScfOfPrevFrameAsReference(
433
    CAacDecoderChannelInfo *pAacDecoderChannelInfo,
434
36.7k
    CAacDecoderStaticChannelInfo *pAacDecoderStaticChannelInfo) {
435
36.7k
  CErRvlcInfo *pRvlc =
436
36.7k
      &pAacDecoderChannelInfo->pComData->overlay.aac.erRvlcInfo;
437
36.7k
  int band, bnds, startBand, endBand, group;
438
36.7k
  int conceal_min, conceal_max;
439
36.7k
  int conceal_group_min, conceal_group_max;
440
36.7k
  int MaximumScaleFactorBands;
441
36.7k
  SHORT commonMin;
442
443
36.7k
  if (GetWindowSequence(&pAacDecoderChannelInfo->icsInfo) == BLOCK_SHORT) {
444
5.08k
    MaximumScaleFactorBands = 16;
445
31.6k
  } else {
446
31.6k
    MaximumScaleFactorBands = 64;
447
31.6k
  }
448
449
  /* If an error was detected just in forward or backward direction, set the
450
     corresponding border for concealment to a appropriate scalefactor band. The
451
     border is set to first or last sfb respectively, because the error will
452
     possibly not follow directly after the corrupt bit but just after decoding
453
     some more (wrong) scalefactors. */
454
36.7k
  if (pRvlc->conceal_min == CONCEAL_MIN_INIT) pRvlc->conceal_min = 0;
455
456
36.7k
  if (pRvlc->conceal_max == CONCEAL_MAX_INIT)
457
3.43k
    pRvlc->conceal_max =
458
3.43k
        (pRvlc->numWindowGroups - 1) * 16 + pRvlc->maxSfbTransmitted - 1;
459
460
36.7k
  conceal_min = pRvlc->conceal_min % MaximumScaleFactorBands;
461
36.7k
  conceal_group_min = pRvlc->conceal_min / MaximumScaleFactorBands;
462
36.7k
  conceal_max = pRvlc->conceal_max % MaximumScaleFactorBands;
463
36.7k
  conceal_group_max = pRvlc->conceal_max / MaximumScaleFactorBands;
464
465
36.7k
  pAacDecoderChannelInfo->pComData->overlay.aac
466
36.7k
      .aRvlcScfFwd[pRvlc->conceal_max] =
467
36.7k
      pAacDecoderChannelInfo->pComData->overlay.aac
468
36.7k
          .aRvlcScfBwd[pRvlc->conceal_max];
469
36.7k
  pAacDecoderChannelInfo->pComData->overlay.aac
470
36.7k
      .aRvlcScfBwd[pRvlc->conceal_min] =
471
36.7k
      pAacDecoderChannelInfo->pComData->overlay.aac
472
36.7k
          .aRvlcScfFwd[pRvlc->conceal_min];
473
474
  /* consider the smaller of the forward and backward decoded value as the
475
   * correct one */
476
36.7k
  startBand = conceal_min;
477
36.7k
  if (conceal_group_min == conceal_group_max)
478
32.2k
    endBand = conceal_max;
479
4.55k
  else
480
4.55k
    endBand = pRvlc->maxSfbTransmitted - 1;
481
482
82.9k
  for (group = conceal_group_min; group <= conceal_group_max; group++) {
483
144k
    for (band = startBand; band <= endBand; band++) {
484
98.6k
      bnds = 16 * group + band;
485
98.6k
      switch (pAacDecoderChannelInfo->pDynData->aCodeBook[bnds]) {
486
25.9k
        case ZERO_HCB:
487
25.9k
          pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = 0;
488
25.9k
          break;
489
490
6.32k
        case INTENSITY_HCB:
491
25.5k
        case INTENSITY_HCB2:
492
25.5k
          if ((pAacDecoderStaticChannelInfo->concealmentInfo
493
25.5k
                   .aRvlcPreviousCodebook[bnds] == INTENSITY_HCB) ||
494
25.4k
              (pAacDecoderStaticChannelInfo->concealmentInfo
495
25.4k
                   .aRvlcPreviousCodebook[bnds] == INTENSITY_HCB2)) {
496
8.65k
            commonMin = fMin(
497
8.65k
                pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds],
498
8.65k
                pAacDecoderChannelInfo->pComData->overlay.aac
499
8.65k
                    .aRvlcScfBwd[bnds]);
500
8.65k
            pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
501
8.65k
                fMin(commonMin, pAacDecoderStaticChannelInfo->concealmentInfo
502
8.65k
                                    .aRvlcPreviousScaleFactor[bnds]);
503
16.8k
          } else {
504
16.8k
            pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = fMin(
505
16.8k
                pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds],
506
16.8k
                pAacDecoderChannelInfo->pComData->overlay.aac
507
16.8k
                    .aRvlcScfBwd[bnds]);
508
16.8k
          }
509
25.5k
          break;
510
511
4.13k
        case NOISE_HCB:
512
4.13k
          if (pAacDecoderStaticChannelInfo->concealmentInfo
513
4.13k
                  .aRvlcPreviousCodebook[bnds] == NOISE_HCB) {
514
470
            commonMin = fMin(
515
470
                pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds],
516
470
                pAacDecoderChannelInfo->pComData->overlay.aac
517
470
                    .aRvlcScfBwd[bnds]);
518
470
            pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
519
470
                fMin(commonMin, pAacDecoderStaticChannelInfo->concealmentInfo
520
470
                                    .aRvlcPreviousScaleFactor[bnds]);
521
3.66k
          } else {
522
3.66k
            pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = fMin(
523
3.66k
                pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds],
524
3.66k
                pAacDecoderChannelInfo->pComData->overlay.aac
525
3.66k
                    .aRvlcScfBwd[bnds]);
526
3.66k
          }
527
4.13k
          break;
528
529
43.0k
        default:
530
43.0k
          if ((pAacDecoderStaticChannelInfo->concealmentInfo
531
43.0k
                   .aRvlcPreviousCodebook[bnds] != ZERO_HCB) &&
532
6.29k
              (pAacDecoderStaticChannelInfo->concealmentInfo
533
6.29k
                   .aRvlcPreviousCodebook[bnds] != NOISE_HCB) &&
534
5.88k
              (pAacDecoderStaticChannelInfo->concealmentInfo
535
5.88k
                   .aRvlcPreviousCodebook[bnds] != INTENSITY_HCB) &&
536
5.81k
              (pAacDecoderStaticChannelInfo->concealmentInfo
537
5.81k
                   .aRvlcPreviousCodebook[bnds] != INTENSITY_HCB2)) {
538
5.74k
            commonMin = fMin(
539
5.74k
                pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds],
540
5.74k
                pAacDecoderChannelInfo->pComData->overlay.aac
541
5.74k
                    .aRvlcScfBwd[bnds]);
542
5.74k
            pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
543
5.74k
                fMin(commonMin, pAacDecoderStaticChannelInfo->concealmentInfo
544
5.74k
                                    .aRvlcPreviousScaleFactor[bnds]);
545
37.3k
          } else {
546
37.3k
            pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = fMin(
547
37.3k
                pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds],
548
37.3k
                pAacDecoderChannelInfo->pComData->overlay.aac
549
37.3k
                    .aRvlcScfBwd[bnds]);
550
37.3k
          }
551
43.0k
          break;
552
98.6k
      }
553
98.6k
    }
554
46.1k
    startBand = 0;
555
46.1k
    if ((group + 1) == conceal_group_max) endBand = conceal_max;
556
46.1k
  }
557
558
  /* now copy all data to the output buffer which needs not to be concealed */
559
36.7k
  if (conceal_group_min == 0)
560
32.1k
    endBand = conceal_min;
561
4.66k
  else
562
4.66k
    endBand = pRvlc->maxSfbTransmitted;
563
84.9k
  for (group = 0; group <= conceal_group_min; group++) {
564
89.7k
    for (band = 0; band < endBand; band++) {
565
41.5k
      bnds = 16 * group + band;
566
41.5k
      pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
567
41.5k
          pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds];
568
41.5k
    }
569
48.2k
    if ((group + 1) == conceal_group_min) endBand = conceal_min;
570
48.2k
  }
571
572
36.7k
  startBand = conceal_max + 1;
573
78.1k
  for (group = conceal_group_max; group < pRvlc->numWindowGroups; group++) {
574
64.8k
    for (band = startBand; band < pRvlc->maxSfbTransmitted; band++) {
575
23.4k
      bnds = 16 * group + band;
576
23.4k
      pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
577
23.4k
          pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[bnds];
578
23.4k
    }
579
41.3k
    startBand = 0;
580
41.3k
  }
581
36.7k
}
582
583
/*---------------------------------------------------------------------------------------------
584
  function:      StatisticalEstimation
585
586
  description:   This approach by means of statistical estimation is generally
587
performed when both the start value and the end value are different and no
588
further errors have been detected. Considering the forward and backward decoded
589
scalefactors, the set with the lower scalefactors in sum will be considered as
590
the correct one. The scalefactors are differentially encoded. Normally it would
591
reach to compare one pair of the forward and backward decoded scalefactors to
592
specify the lower set. But having detected no further errors does not
593
necessarily mean the absence of errors. Therefore all scalefactors decoded in
594
forward and backward direction are summed up seperately. The set with the lower
595
sum will be used. The strategy must be applied to scalefactors, intensity data
596
and noise energy seperately.
597
-----------------------------------------------------------------------------------------------
598
  output:        Concealed scalefactor, noise energy and intensity data
599
-----------------------------------------------------------------------------------------------
600
  return:        -
601
--------------------------------------------------------------------------------------------
602
*/
603
604
3.20k
void StatisticalEstimation(CAacDecoderChannelInfo *pAacDecoderChannelInfo) {
605
3.20k
  CErRvlcInfo *pRvlc =
606
3.20k
      &pAacDecoderChannelInfo->pComData->overlay.aac.erRvlcInfo;
607
3.20k
  int band, bnds, group;
608
3.20k
  int sumIsFwd, sumIsBwd;   /* sum of intensity data forward/backward */
609
3.20k
  int sumNrgFwd, sumNrgBwd; /* sum of noise energy data forward/backward */
610
3.20k
  int sumScfFwd, sumScfBwd; /* sum of scalefactor data forward/backward */
611
3.20k
  int useIsFwd, useNrgFwd, useScfFwd; /* the flags signals the elements which
612
                                         are used for the final result */
613
614
3.20k
  sumIsFwd = sumIsBwd = sumNrgFwd = sumNrgBwd = sumScfFwd = sumScfBwd = 0;
615
3.20k
  useIsFwd = useNrgFwd = useScfFwd = 0;
616
617
  /* calculate sum of each group (scf,nrg,is) of forward and backward direction
618
   */
619
7.14k
  for (group = 0; group < pRvlc->numWindowGroups; group++) {
620
33.4k
    for (band = 0; band < pRvlc->maxSfbTransmitted; band++) {
621
29.5k
      bnds = 16 * group + band;
622
29.5k
      switch (pAacDecoderChannelInfo->pDynData->aCodeBook[bnds]) {
623
8.62k
        case ZERO_HCB:
624
8.62k
          break;
625
626
857
        case INTENSITY_HCB:
627
1.71k
        case INTENSITY_HCB2:
628
1.71k
          sumIsFwd +=
629
1.71k
              pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds];
630
1.71k
          sumIsBwd +=
631
1.71k
              pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[bnds];
632
1.71k
          break;
633
634
1.19k
        case NOISE_HCB:
635
1.19k
          sumNrgFwd +=
636
1.19k
              pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds];
637
1.19k
          sumNrgBwd +=
638
1.19k
              pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[bnds];
639
1.19k
          break;
640
641
17.9k
        default:
642
17.9k
          sumScfFwd +=
643
17.9k
              pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds];
644
17.9k
          sumScfBwd +=
645
17.9k
              pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[bnds];
646
17.9k
          break;
647
29.5k
      }
648
29.5k
    }
649
3.93k
  }
650
651
  /* find for each group (scf,nrg,is) the correct direction */
652
3.20k
  if (sumIsFwd < sumIsBwd) useIsFwd = 1;
653
654
3.20k
  if (sumNrgFwd < sumNrgBwd) useNrgFwd = 1;
655
656
3.20k
  if (sumScfFwd < sumScfBwd) useScfFwd = 1;
657
658
  /* conceal each group (scf,nrg,is) */
659
7.14k
  for (group = 0; group < pRvlc->numWindowGroups; group++) {
660
33.4k
    for (band = 0; band < pRvlc->maxSfbTransmitted; band++) {
661
29.5k
      bnds = 16 * group + band;
662
29.5k
      switch (pAacDecoderChannelInfo->pDynData->aCodeBook[bnds]) {
663
8.62k
        case ZERO_HCB:
664
8.62k
          break;
665
666
857
        case INTENSITY_HCB:
667
1.71k
        case INTENSITY_HCB2:
668
1.71k
          if (useIsFwd)
669
514
            pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
670
514
                pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds];
671
1.20k
          else
672
1.20k
            pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
673
1.20k
                pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[bnds];
674
1.71k
          break;
675
676
1.19k
        case NOISE_HCB:
677
1.19k
          if (useNrgFwd)
678
315
            pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
679
315
                pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds];
680
875
          else
681
875
            pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
682
875
                pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[bnds];
683
1.19k
          break;
684
685
17.9k
        default:
686
17.9k
          if (useScfFwd)
687
5.41k
            pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
688
5.41k
                pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds];
689
12.5k
          else
690
12.5k
            pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
691
12.5k
                pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[bnds];
692
17.9k
          break;
693
29.5k
      }
694
29.5k
    }
695
3.93k
  }
696
3.20k
}
697
698
/*---------------------------------------------------------------------------------------------
699
  description:   Approach by means of predictive interpolation
700
                 This approach by means of predictive estimation is generally
701
performed when the error cannot be isolated between 'conceal_min' and
702
'conceal_max', the 'sf_concealment' flag is set and the previous frame has the
703
same block type as the current frame. Check for each scalefactorband if the same
704
type of data (scalefactor, internsity data, noise energies) is transmitted. If
705
so use the scalefactor (intensity data, noise energy) in the current frame.
706
Otherwise set the scalefactor (intensity data, noise energy) for this
707
scalefactorband to zero.
708
-----------------------------------------------------------------------------------------------
709
  output:        Concealed scalefactor, noise energy and intensity data
710
-----------------------------------------------------------------------------------------------
711
  return:        -
712
--------------------------------------------------------------------------------------------
713
*/
714
715
void PredictiveInterpolation(
716
    CAacDecoderChannelInfo *pAacDecoderChannelInfo,
717
5.76k
    CAacDecoderStaticChannelInfo *pAacDecoderStaticChannelInfo) {
718
5.76k
  CErRvlcInfo *pRvlc =
719
5.76k
      &pAacDecoderChannelInfo->pComData->overlay.aac.erRvlcInfo;
720
5.76k
  int band, bnds, group;
721
5.76k
  SHORT commonMin;
722
723
12.3k
  for (group = 0; group < pRvlc->numWindowGroups; group++) {
724
29.2k
    for (band = 0; band < pRvlc->maxSfbTransmitted; band++) {
725
22.6k
      bnds = 16 * group + band;
726
22.6k
      switch (pAacDecoderChannelInfo->pDynData->aCodeBook[bnds]) {
727
155
        case ZERO_HCB:
728
155
          pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = 0;
729
155
          break;
730
731
118
        case INTENSITY_HCB:
732
11.6k
        case INTENSITY_HCB2:
733
11.6k
          if ((pAacDecoderStaticChannelInfo->concealmentInfo
734
11.6k
                   .aRvlcPreviousCodebook[bnds] == INTENSITY_HCB) ||
735
11.6k
              (pAacDecoderStaticChannelInfo->concealmentInfo
736
11.6k
                   .aRvlcPreviousCodebook[bnds] == INTENSITY_HCB2)) {
737
10.2k
            commonMin = fMin(
738
10.2k
                pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds],
739
10.2k
                pAacDecoderChannelInfo->pComData->overlay.aac
740
10.2k
                    .aRvlcScfBwd[bnds]);
741
10.2k
            pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
742
10.2k
                fMin(commonMin, pAacDecoderStaticChannelInfo->concealmentInfo
743
10.2k
                                    .aRvlcPreviousScaleFactor[bnds]);
744
10.2k
          } else {
745
1.47k
            pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = -110;
746
1.47k
          }
747
11.6k
          break;
748
749
1.13k
        case NOISE_HCB:
750
1.13k
          if (pAacDecoderStaticChannelInfo->concealmentInfo
751
1.13k
                  .aRvlcPreviousCodebook[bnds] == NOISE_HCB) {
752
504
            commonMin = fMin(
753
504
                pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds],
754
504
                pAacDecoderChannelInfo->pComData->overlay.aac
755
504
                    .aRvlcScfBwd[bnds]);
756
504
            pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
757
504
                fMin(commonMin, pAacDecoderStaticChannelInfo->concealmentInfo
758
504
                                    .aRvlcPreviousScaleFactor[bnds]);
759
635
          } else {
760
635
            pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = -110;
761
635
          }
762
1.13k
          break;
763
764
9.71k
        default:
765
9.71k
          if ((pAacDecoderStaticChannelInfo->concealmentInfo
766
9.71k
                   .aRvlcPreviousCodebook[bnds] != ZERO_HCB) &&
767
8.34k
              (pAacDecoderStaticChannelInfo->concealmentInfo
768
8.34k
                   .aRvlcPreviousCodebook[bnds] != NOISE_HCB) &&
769
7.97k
              (pAacDecoderStaticChannelInfo->concealmentInfo
770
7.97k
                   .aRvlcPreviousCodebook[bnds] != INTENSITY_HCB) &&
771
7.90k
              (pAacDecoderStaticChannelInfo->concealmentInfo
772
7.90k
                   .aRvlcPreviousCodebook[bnds] != INTENSITY_HCB2)) {
773
7.83k
            commonMin = fMin(
774
7.83k
                pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds],
775
7.83k
                pAacDecoderChannelInfo->pComData->overlay.aac
776
7.83k
                    .aRvlcScfBwd[bnds]);
777
7.83k
            pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
778
7.83k
                fMin(commonMin, pAacDecoderStaticChannelInfo->concealmentInfo
779
7.83k
                                    .aRvlcPreviousScaleFactor[bnds]);
780
7.83k
          } else {
781
1.87k
            pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = 0;
782
1.87k
          }
783
9.71k
          break;
784
22.6k
      }
785
22.6k
    }
786
6.54k
  }
787
5.76k
}