Coverage Report

Created: 2026-09-04 07:02

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
27.3k
                          int *refIsFwd, int *refNrgFwd, int *refScfFwd) {
132
27.3k
  int band, bnds, group, startBand;
133
27.3k
  int idIs, idNrg, idScf;
134
27.3k
  int conceal_min, conceal_group_min;
135
27.3k
  int MaximumScaleFactorBands;
136
137
27.3k
  if (GetWindowSequence(&pAacDecoderChannelInfo->icsInfo) == BLOCK_SHORT)
138
642
    MaximumScaleFactorBands = 16;
139
26.7k
  else
140
26.7k
    MaximumScaleFactorBands = 64;
141
142
27.3k
  conceal_min = pRvlc->conceal_min % MaximumScaleFactorBands;
143
27.3k
  conceal_group_min = pRvlc->conceal_min / MaximumScaleFactorBands;
144
145
  /* calculate first reference value for approach in forward direction */
146
27.3k
  idIs = idNrg = idScf = 1;
147
148
  /* set reference values */
149
27.3k
  *refIsFwd = -SF_OFFSET;
150
27.3k
  *refNrgFwd = pAacDecoderChannelInfo->pDynData->RawDataInfo.GlobalGain -
151
27.3k
               SF_OFFSET - 90 - 256;
152
27.3k
  *refScfFwd =
153
27.3k
      pAacDecoderChannelInfo->pDynData->RawDataInfo.GlobalGain - SF_OFFSET;
154
155
27.3k
  startBand = conceal_min - 1;
156
55.5k
  for (group = conceal_group_min; group >= 0; group--) {
157
46.2k
    for (band = startBand; band >= 0; band--) {
158
18.0k
      bnds = 16 * group + band;
159
18.0k
      switch (pAacDecoderChannelInfo->pDynData->aCodeBook[bnds]) {
160
2.99k
        case ZERO_HCB:
161
2.99k
          break;
162
752
        case INTENSITY_HCB:
163
1.14k
        case INTENSITY_HCB2:
164
1.14k
          if (idIs) {
165
366
            *refIsFwd =
166
366
                pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds];
167
366
            idIs = 0; /* reference value has been set */
168
366
          }
169
1.14k
          break;
170
938
        case NOISE_HCB:
171
938
          if (idNrg) {
172
298
            *refNrgFwd =
173
298
                pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds];
174
298
            idNrg = 0; /* reference value has been set */
175
298
          }
176
938
          break;
177
12.9k
        default:
178
12.9k
          if (idScf) {
179
5.53k
            *refScfFwd =
180
5.53k
                pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds];
181
5.53k
            idScf = 0; /* reference value has been set */
182
5.53k
          }
183
12.9k
          break;
184
18.0k
      }
185
18.0k
    }
186
28.1k
    startBand = pRvlc->maxSfbTransmitted - 1;
187
28.1k
  }
188
27.3k
}
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
27.3k
                          int *refIsBwd, int *refNrgBwd, int *refScfBwd) {
208
27.3k
  int band, bnds, group, startBand;
209
27.3k
  int idIs, idNrg, idScf;
210
27.3k
  int conceal_max, conceal_group_max;
211
27.3k
  int MaximumScaleFactorBands;
212
213
27.3k
  if (GetWindowSequence(&pAacDecoderChannelInfo->icsInfo) == BLOCK_SHORT)
214
642
    MaximumScaleFactorBands = 16;
215
26.7k
  else
216
26.7k
    MaximumScaleFactorBands = 64;
217
218
27.3k
  conceal_max = pRvlc->conceal_max % MaximumScaleFactorBands;
219
27.3k
  conceal_group_max = pRvlc->conceal_max / MaximumScaleFactorBands;
220
221
  /* calculate first reference value for approach in backward direction */
222
27.3k
  idIs = idNrg = idScf = 1;
223
224
  /* set reference values */
225
27.3k
  *refIsBwd = pRvlc->dpcm_is_last_position - SF_OFFSET;
226
27.3k
  *refNrgBwd = pRvlc->rev_global_gain + pRvlc->dpcm_noise_last_position -
227
27.3k
               SF_OFFSET - 90 - 256 + pRvlc->dpcm_noise_nrg;
228
27.3k
  *refScfBwd = pRvlc->rev_global_gain - SF_OFFSET;
229
230
27.3k
  startBand = conceal_max + 1;
231
232
  /* if needed, re-set reference values */
233
56.3k
  for (group = conceal_group_max; group < pRvlc->numWindowGroups; group++) {
234
47.6k
    for (band = startBand; band < pRvlc->maxSfbTransmitted; band++) {
235
18.6k
      bnds = 16 * group + band;
236
18.6k
      switch (pAacDecoderChannelInfo->pDynData->aCodeBook[bnds]) {
237
3.19k
        case ZERO_HCB:
238
3.19k
          break;
239
873
        case INTENSITY_HCB:
240
1.52k
        case INTENSITY_HCB2:
241
1.52k
          if (idIs) {
242
443
            *refIsBwd =
243
443
                pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[bnds];
244
443
            idIs = 0; /* reference value has been set */
245
443
          }
246
1.52k
          break;
247
580
        case NOISE_HCB:
248
580
          if (idNrg) {
249
175
            *refNrgBwd =
250
175
                pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[bnds];
251
175
            idNrg = 0; /* reference value has been set */
252
175
          }
253
580
          break;
254
13.3k
        default:
255
13.3k
          if (idScf) {
256
5.52k
            *refScfBwd =
257
5.52k
                pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[bnds];
258
5.52k
            idScf = 0; /* reference value has been set */
259
5.52k
          }
260
13.3k
          break;
261
18.6k
      }
262
18.6k
    }
263
28.9k
    startBand = 0;
264
28.9k
  }
265
27.3k
}
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
34.5k
    CAacDecoderChannelInfo *pAacDecoderChannelInfo) {
288
34.5k
  CErRvlcInfo *pRvlc =
289
34.5k
      &pAacDecoderChannelInfo->pComData->overlay.aac.erRvlcInfo;
290
34.5k
  int band, bnds, startBand, endBand, group;
291
34.5k
  int conceal_min, conceal_max;
292
34.5k
  int conceal_group_min, conceal_group_max;
293
34.5k
  int MaximumScaleFactorBands;
294
295
34.5k
  if (GetWindowSequence(&pAacDecoderChannelInfo->icsInfo) == BLOCK_SHORT) {
296
4.56k
    MaximumScaleFactorBands = 16;
297
30.0k
  } else {
298
30.0k
    MaximumScaleFactorBands = 64;
299
30.0k
  }
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
34.5k
  if (pRvlc->conceal_min == CONCEAL_MIN_INIT) pRvlc->conceal_min = 0;
307
308
34.5k
  if (pRvlc->conceal_max == CONCEAL_MAX_INIT)
309
2.99k
    pRvlc->conceal_max =
310
2.99k
        (pRvlc->numWindowGroups - 1) * 16 + pRvlc->maxSfbTransmitted - 1;
311
312
34.5k
  conceal_min = pRvlc->conceal_min % MaximumScaleFactorBands;
313
34.5k
  conceal_group_min = pRvlc->conceal_min / MaximumScaleFactorBands;
314
34.5k
  conceal_max = pRvlc->conceal_max % MaximumScaleFactorBands;
315
34.5k
  conceal_group_max = pRvlc->conceal_max / MaximumScaleFactorBands;
316
317
34.5k
  if (pRvlc->conceal_min == pRvlc->conceal_max) {
318
27.3k
    int refIsFwd, refNrgFwd, refScfFwd;
319
27.3k
    int refIsBwd, refNrgBwd, refScfBwd;
320
321
27.3k
    bnds = pRvlc->conceal_min;
322
27.3k
    calcRefValFwd(pRvlc, pAacDecoderChannelInfo, &refIsFwd, &refNrgFwd,
323
27.3k
                  &refScfFwd);
324
27.3k
    calcRefValBwd(pRvlc, pAacDecoderChannelInfo, &refIsBwd, &refNrgBwd,
325
27.3k
                  &refScfBwd);
326
327
27.3k
    switch (pAacDecoderChannelInfo->pDynData->aCodeBook[bnds]) {
328
19.1k
      case ZERO_HCB:
329
19.1k
        break;
330
725
      case INTENSITY_HCB:
331
866
      case INTENSITY_HCB2:
332
866
        if (refIsFwd < refIsBwd)
333
118
          pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = refIsFwd;
334
748
        else
335
748
          pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = refIsBwd;
336
866
        break;
337
270
      case NOISE_HCB:
338
270
        if (refNrgFwd < refNrgBwd)
339
139
          pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = refNrgFwd;
340
131
        else
341
131
          pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = refNrgBwd;
342
270
        break;
343
7.04k
      default:
344
7.04k
        if (refScfFwd < refScfBwd)
345
6.04k
          pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = refScfFwd;
346
994
        else
347
994
          pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = refScfBwd;
348
7.04k
        break;
349
27.3k
    }
350
27.3k
  } else {
351
7.20k
    pAacDecoderChannelInfo->pComData->overlay.aac
352
7.20k
        .aRvlcScfFwd[pRvlc->conceal_max] =
353
7.20k
        pAacDecoderChannelInfo->pComData->overlay.aac
354
7.20k
            .aRvlcScfBwd[pRvlc->conceal_max];
355
7.20k
    pAacDecoderChannelInfo->pComData->overlay.aac
356
7.20k
        .aRvlcScfBwd[pRvlc->conceal_min] =
357
7.20k
        pAacDecoderChannelInfo->pComData->overlay.aac
358
7.20k
            .aRvlcScfFwd[pRvlc->conceal_min];
359
360
    /* consider the smaller of the forward and backward decoded value as the
361
     * correct one */
362
7.20k
    startBand = conceal_min;
363
7.20k
    if (conceal_group_min == conceal_group_max)
364
4.42k
      endBand = conceal_max;
365
2.77k
    else
366
2.77k
      endBand = pRvlc->maxSfbTransmitted - 1;
367
368
18.8k
    for (group = conceal_group_min; group <= conceal_group_max; group++) {
369
52.6k
      for (band = startBand; band <= endBand; band++) {
370
40.9k
        bnds = 16 * group + band;
371
40.9k
        if (pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds] <
372
40.9k
            pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[bnds])
373
17.9k
          pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
374
17.9k
              pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds];
375
23.0k
        else
376
23.0k
          pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
377
23.0k
              pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[bnds];
378
40.9k
      }
379
11.6k
      startBand = 0;
380
11.6k
      if ((group + 1) == conceal_group_max) endBand = conceal_max;
381
11.6k
    }
382
7.20k
  }
383
384
  /* now copy all data to the output buffer which needs not to be concealed */
385
34.5k
  if (conceal_group_min == 0)
386
32.3k
    endBand = conceal_min;
387
2.24k
  else
388
2.24k
    endBand = pRvlc->maxSfbTransmitted;
389
77.5k
  for (group = 0; group <= conceal_group_min; group++) {
390
103k
    for (band = 0; band < endBand; band++) {
391
60.8k
      bnds = 16 * group + band;
392
60.8k
      pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
393
60.8k
          pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds];
394
60.8k
    }
395
43.0k
    if ((group + 1) == conceal_group_min) endBand = conceal_min;
396
43.0k
  }
397
398
34.5k
  startBand = conceal_max + 1;
399
78.5k
  for (group = conceal_group_max; group < pRvlc->numWindowGroups; group++) {
400
95.0k
    for (band = startBand; band < pRvlc->maxSfbTransmitted; band++) {
401
51.0k
      bnds = 16 * group + band;
402
51.0k
      pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
403
51.0k
          pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[bnds];
404
51.0k
    }
405
43.9k
    startBand = 0;
406
43.9k
  }
407
34.5k
}
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
18.9k
    CAacDecoderStaticChannelInfo *pAacDecoderStaticChannelInfo) {
435
18.9k
  CErRvlcInfo *pRvlc =
436
18.9k
      &pAacDecoderChannelInfo->pComData->overlay.aac.erRvlcInfo;
437
18.9k
  int band, bnds, startBand, endBand, group;
438
18.9k
  int conceal_min, conceal_max;
439
18.9k
  int conceal_group_min, conceal_group_max;
440
18.9k
  int MaximumScaleFactorBands;
441
18.9k
  SHORT commonMin;
442
443
18.9k
  if (GetWindowSequence(&pAacDecoderChannelInfo->icsInfo) == BLOCK_SHORT) {
444
2.78k
    MaximumScaleFactorBands = 16;
445
16.2k
  } else {
446
16.2k
    MaximumScaleFactorBands = 64;
447
16.2k
  }
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
18.9k
  if (pRvlc->conceal_min == CONCEAL_MIN_INIT) pRvlc->conceal_min = 0;
455
456
18.9k
  if (pRvlc->conceal_max == CONCEAL_MAX_INIT)
457
1.83k
    pRvlc->conceal_max =
458
1.83k
        (pRvlc->numWindowGroups - 1) * 16 + pRvlc->maxSfbTransmitted - 1;
459
460
18.9k
  conceal_min = pRvlc->conceal_min % MaximumScaleFactorBands;
461
18.9k
  conceal_group_min = pRvlc->conceal_min / MaximumScaleFactorBands;
462
18.9k
  conceal_max = pRvlc->conceal_max % MaximumScaleFactorBands;
463
18.9k
  conceal_group_max = pRvlc->conceal_max / MaximumScaleFactorBands;
464
465
18.9k
  pAacDecoderChannelInfo->pComData->overlay.aac
466
18.9k
      .aRvlcScfFwd[pRvlc->conceal_max] =
467
18.9k
      pAacDecoderChannelInfo->pComData->overlay.aac
468
18.9k
          .aRvlcScfBwd[pRvlc->conceal_max];
469
18.9k
  pAacDecoderChannelInfo->pComData->overlay.aac
470
18.9k
      .aRvlcScfBwd[pRvlc->conceal_min] =
471
18.9k
      pAacDecoderChannelInfo->pComData->overlay.aac
472
18.9k
          .aRvlcScfFwd[pRvlc->conceal_min];
473
474
  /* consider the smaller of the forward and backward decoded value as the
475
   * correct one */
476
18.9k
  startBand = conceal_min;
477
18.9k
  if (conceal_group_min == conceal_group_max)
478
16.5k
    endBand = conceal_max;
479
2.48k
  else
480
2.48k
    endBand = pRvlc->maxSfbTransmitted - 1;
481
482
42.5k
  for (group = conceal_group_min; group <= conceal_group_max; group++) {
483
75.2k
    for (band = startBand; band <= endBand; band++) {
484
51.7k
      bnds = 16 * group + band;
485
51.7k
      switch (pAacDecoderChannelInfo->pDynData->aCodeBook[bnds]) {
486
14.4k
        case ZERO_HCB:
487
14.4k
          pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = 0;
488
14.4k
          break;
489
490
2.49k
        case INTENSITY_HCB:
491
12.3k
        case INTENSITY_HCB2:
492
12.3k
          if ((pAacDecoderStaticChannelInfo->concealmentInfo
493
12.3k
                   .aRvlcPreviousCodebook[bnds] == INTENSITY_HCB) ||
494
12.3k
              (pAacDecoderStaticChannelInfo->concealmentInfo
495
12.3k
                   .aRvlcPreviousCodebook[bnds] == INTENSITY_HCB2)) {
496
3.67k
            commonMin = fMin(
497
3.67k
                pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds],
498
3.67k
                pAacDecoderChannelInfo->pComData->overlay.aac
499
3.67k
                    .aRvlcScfBwd[bnds]);
500
3.67k
            pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
501
3.67k
                fMin(commonMin, pAacDecoderStaticChannelInfo->concealmentInfo
502
3.67k
                                    .aRvlcPreviousScaleFactor[bnds]);
503
8.69k
          } else {
504
8.69k
            pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = fMin(
505
8.69k
                pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds],
506
8.69k
                pAacDecoderChannelInfo->pComData->overlay.aac
507
8.69k
                    .aRvlcScfBwd[bnds]);
508
8.69k
          }
509
12.3k
          break;
510
511
2.00k
        case NOISE_HCB:
512
2.00k
          if (pAacDecoderStaticChannelInfo->concealmentInfo
513
2.00k
                  .aRvlcPreviousCodebook[bnds] == NOISE_HCB) {
514
292
            commonMin = fMin(
515
292
                pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds],
516
292
                pAacDecoderChannelInfo->pComData->overlay.aac
517
292
                    .aRvlcScfBwd[bnds]);
518
292
            pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
519
292
                fMin(commonMin, pAacDecoderStaticChannelInfo->concealmentInfo
520
292
                                    .aRvlcPreviousScaleFactor[bnds]);
521
1.71k
          } else {
522
1.71k
            pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = fMin(
523
1.71k
                pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds],
524
1.71k
                pAacDecoderChannelInfo->pComData->overlay.aac
525
1.71k
                    .aRvlcScfBwd[bnds]);
526
1.71k
          }
527
2.00k
          break;
528
529
22.9k
        default:
530
22.9k
          if ((pAacDecoderStaticChannelInfo->concealmentInfo
531
22.9k
                   .aRvlcPreviousCodebook[bnds] != ZERO_HCB) &&
532
3.27k
              (pAacDecoderStaticChannelInfo->concealmentInfo
533
3.27k
                   .aRvlcPreviousCodebook[bnds] != NOISE_HCB) &&
534
3.10k
              (pAacDecoderStaticChannelInfo->concealmentInfo
535
3.10k
                   .aRvlcPreviousCodebook[bnds] != INTENSITY_HCB) &&
536
2.77k
              (pAacDecoderStaticChannelInfo->concealmentInfo
537
2.77k
                   .aRvlcPreviousCodebook[bnds] != INTENSITY_HCB2)) {
538
2.56k
            commonMin = fMin(
539
2.56k
                pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds],
540
2.56k
                pAacDecoderChannelInfo->pComData->overlay.aac
541
2.56k
                    .aRvlcScfBwd[bnds]);
542
2.56k
            pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
543
2.56k
                fMin(commonMin, pAacDecoderStaticChannelInfo->concealmentInfo
544
2.56k
                                    .aRvlcPreviousScaleFactor[bnds]);
545
20.3k
          } else {
546
20.3k
            pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = fMin(
547
20.3k
                pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds],
548
20.3k
                pAacDecoderChannelInfo->pComData->overlay.aac
549
20.3k
                    .aRvlcScfBwd[bnds]);
550
20.3k
          }
551
22.9k
          break;
552
51.7k
      }
553
51.7k
    }
554
23.5k
    startBand = 0;
555
23.5k
    if ((group + 1) == conceal_group_max) endBand = conceal_max;
556
23.5k
  }
557
558
  /* now copy all data to the output buffer which needs not to be concealed */
559
18.9k
  if (conceal_group_min == 0)
560
16.2k
    endBand = conceal_min;
561
2.72k
  else
562
2.72k
    endBand = pRvlc->maxSfbTransmitted;
563
44.6k
  for (group = 0; group <= conceal_group_min; group++) {
564
51.0k
    for (band = 0; band < endBand; band++) {
565
25.3k
      bnds = 16 * group + band;
566
25.3k
      pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
567
25.3k
          pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds];
568
25.3k
    }
569
25.7k
    if ((group + 1) == conceal_group_min) endBand = conceal_min;
570
25.7k
  }
571
572
18.9k
  startBand = conceal_max + 1;
573
41.1k
  for (group = conceal_group_max; group < pRvlc->numWindowGroups; group++) {
574
38.4k
    for (band = startBand; band < pRvlc->maxSfbTransmitted; band++) {
575
16.2k
      bnds = 16 * group + band;
576
16.2k
      pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
577
16.2k
          pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[bnds];
578
16.2k
    }
579
22.1k
    startBand = 0;
580
22.1k
  }
581
18.9k
}
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
4.21k
void StatisticalEstimation(CAacDecoderChannelInfo *pAacDecoderChannelInfo) {
605
4.21k
  CErRvlcInfo *pRvlc =
606
4.21k
      &pAacDecoderChannelInfo->pComData->overlay.aac.erRvlcInfo;
607
4.21k
  int band, bnds, group;
608
4.21k
  int sumIsFwd, sumIsBwd;   /* sum of intensity data forward/backward */
609
4.21k
  int sumNrgFwd, sumNrgBwd; /* sum of noise energy data forward/backward */
610
4.21k
  int sumScfFwd, sumScfBwd; /* sum of scalefactor data forward/backward */
611
4.21k
  int useIsFwd, useNrgFwd, useScfFwd; /* the flags signals the elements which
612
                                         are used for the final result */
613
614
4.21k
  sumIsFwd = sumIsBwd = sumNrgFwd = sumNrgBwd = sumScfFwd = sumScfBwd = 0;
615
4.21k
  useIsFwd = useNrgFwd = useScfFwd = 0;
616
617
  /* calculate sum of each group (scf,nrg,is) of forward and backward direction
618
   */
619
8.81k
  for (group = 0; group < pRvlc->numWindowGroups; group++) {
620
28.9k
    for (band = 0; band < pRvlc->maxSfbTransmitted; band++) {
621
24.3k
      bnds = 16 * group + band;
622
24.3k
      switch (pAacDecoderChannelInfo->pDynData->aCodeBook[bnds]) {
623
10.2k
        case ZERO_HCB:
624
10.2k
          break;
625
626
614
        case INTENSITY_HCB:
627
1.12k
        case INTENSITY_HCB2:
628
1.12k
          sumIsFwd +=
629
1.12k
              pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds];
630
1.12k
          sumIsBwd +=
631
1.12k
              pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[bnds];
632
1.12k
          break;
633
634
623
        case NOISE_HCB:
635
623
          sumNrgFwd +=
636
623
              pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds];
637
623
          sumNrgBwd +=
638
623
              pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[bnds];
639
623
          break;
640
641
12.3k
        default:
642
12.3k
          sumScfFwd +=
643
12.3k
              pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds];
644
12.3k
          sumScfBwd +=
645
12.3k
              pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[bnds];
646
12.3k
          break;
647
24.3k
      }
648
24.3k
    }
649
4.59k
  }
650
651
  /* find for each group (scf,nrg,is) the correct direction */
652
4.21k
  if (sumIsFwd < sumIsBwd) useIsFwd = 1;
653
654
4.21k
  if (sumNrgFwd < sumNrgBwd) useNrgFwd = 1;
655
656
4.21k
  if (sumScfFwd < sumScfBwd) useScfFwd = 1;
657
658
  /* conceal each group (scf,nrg,is) */
659
8.81k
  for (group = 0; group < pRvlc->numWindowGroups; group++) {
660
28.9k
    for (band = 0; band < pRvlc->maxSfbTransmitted; band++) {
661
24.3k
      bnds = 16 * group + band;
662
24.3k
      switch (pAacDecoderChannelInfo->pDynData->aCodeBook[bnds]) {
663
10.2k
        case ZERO_HCB:
664
10.2k
          break;
665
666
614
        case INTENSITY_HCB:
667
1.12k
        case INTENSITY_HCB2:
668
1.12k
          if (useIsFwd)
669
231
            pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
670
231
                pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds];
671
896
          else
672
896
            pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
673
896
                pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[bnds];
674
1.12k
          break;
675
676
623
        case NOISE_HCB:
677
623
          if (useNrgFwd)
678
249
            pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
679
249
                pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds];
680
374
          else
681
374
            pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
682
374
                pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[bnds];
683
623
          break;
684
685
12.3k
        default:
686
12.3k
          if (useScfFwd)
687
5.59k
            pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
688
5.59k
                pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds];
689
6.78k
          else
690
6.78k
            pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
691
6.78k
                pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd[bnds];
692
12.3k
          break;
693
24.3k
      }
694
24.3k
    }
695
4.59k
  }
696
4.21k
}
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
4.93k
    CAacDecoderStaticChannelInfo *pAacDecoderStaticChannelInfo) {
718
4.93k
  CErRvlcInfo *pRvlc =
719
4.93k
      &pAacDecoderChannelInfo->pComData->overlay.aac.erRvlcInfo;
720
4.93k
  int band, bnds, group;
721
4.93k
  SHORT commonMin;
722
723
10.3k
  for (group = 0; group < pRvlc->numWindowGroups; group++) {
724
16.2k
    for (band = 0; band < pRvlc->maxSfbTransmitted; band++) {
725
10.8k
      bnds = 16 * group + band;
726
10.8k
      switch (pAacDecoderChannelInfo->pDynData->aCodeBook[bnds]) {
727
124
        case ZERO_HCB:
728
124
          pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = 0;
729
124
          break;
730
731
87
        case INTENSITY_HCB:
732
5.78k
        case INTENSITY_HCB2:
733
5.78k
          if ((pAacDecoderStaticChannelInfo->concealmentInfo
734
5.78k
                   .aRvlcPreviousCodebook[bnds] == INTENSITY_HCB) ||
735
5.76k
              (pAacDecoderStaticChannelInfo->concealmentInfo
736
5.76k
                   .aRvlcPreviousCodebook[bnds] == INTENSITY_HCB2)) {
737
4.16k
            commonMin = fMin(
738
4.16k
                pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds],
739
4.16k
                pAacDecoderChannelInfo->pComData->overlay.aac
740
4.16k
                    .aRvlcScfBwd[bnds]);
741
4.16k
            pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
742
4.16k
                fMin(commonMin, pAacDecoderStaticChannelInfo->concealmentInfo
743
4.16k
                                    .aRvlcPreviousScaleFactor[bnds]);
744
4.16k
          } else {
745
1.62k
            pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = -110;
746
1.62k
          }
747
5.78k
          break;
748
749
296
        case NOISE_HCB:
750
296
          if (pAacDecoderStaticChannelInfo->concealmentInfo
751
296
                  .aRvlcPreviousCodebook[bnds] == NOISE_HCB) {
752
168
            commonMin = fMin(
753
168
                pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds],
754
168
                pAacDecoderChannelInfo->pComData->overlay.aac
755
168
                    .aRvlcScfBwd[bnds]);
756
168
            pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
757
168
                fMin(commonMin, pAacDecoderStaticChannelInfo->concealmentInfo
758
168
                                    .aRvlcPreviousScaleFactor[bnds]);
759
168
          } else {
760
128
            pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = -110;
761
128
          }
762
296
          break;
763
764
4.64k
        default:
765
4.64k
          if ((pAacDecoderStaticChannelInfo->concealmentInfo
766
4.64k
                   .aRvlcPreviousCodebook[bnds] != ZERO_HCB) &&
767
3.42k
              (pAacDecoderStaticChannelInfo->concealmentInfo
768
3.42k
                   .aRvlcPreviousCodebook[bnds] != NOISE_HCB) &&
769
3.38k
              (pAacDecoderStaticChannelInfo->concealmentInfo
770
3.38k
                   .aRvlcPreviousCodebook[bnds] != INTENSITY_HCB) &&
771
3.25k
              (pAacDecoderStaticChannelInfo->concealmentInfo
772
3.25k
                   .aRvlcPreviousCodebook[bnds] != INTENSITY_HCB2)) {
773
3.17k
            commonMin = fMin(
774
3.17k
                pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfFwd[bnds],
775
3.17k
                pAacDecoderChannelInfo->pComData->overlay.aac
776
3.17k
                    .aRvlcScfBwd[bnds]);
777
3.17k
            pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] =
778
3.17k
                fMin(commonMin, pAacDecoderStaticChannelInfo->concealmentInfo
779
3.17k
                                    .aRvlcPreviousScaleFactor[bnds]);
780
3.17k
          } else {
781
1.46k
            pAacDecoderChannelInfo->pDynData->aScaleFactor[bnds] = 0;
782
1.46k
          }
783
4.64k
          break;
784
10.8k
      }
785
10.8k
    }
786
5.42k
  }
787
4.93k
}