Line data Source code
1 : /******************************************************************************************************
2 :
3 : (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
4 : Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
5 : Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
6 : Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
7 : contributors to this repository. All Rights Reserved.
8 :
9 : This software is protected by copyright law and by international treaties.
10 : The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
11 : Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
12 : Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
13 : Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
14 : contributors to this repository retain full ownership rights in their respective contributions in
15 : the software. This notice grants no license of any kind, including but not limited to patent
16 : license, nor is any license granted by implication, estoppel or otherwise.
17 :
18 : Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
19 : contributions.
20 :
21 : This software is provided "AS IS", without any express or implied warranties. The software is in the
22 : development stage. It is intended exclusively for experts who have experience with such software and
23 : solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
24 : and fitness for a particular purpose are hereby disclaimed and excluded.
25 :
26 : Any dispute, controversy or claim arising under or in relation to providing this software shall be
27 : submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
28 : accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
29 : the United Nations Convention on Contracts on the International Sales of Goods.
30 :
31 : *******************************************************************************************************/
32 :
33 : /*====================================================================================
34 : EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0
35 : ====================================================================================*/
36 :
37 : #include <assert.h>
38 : #include <stdint.h>
39 : #include "options.h"
40 : #ifdef DEBUGGING
41 : #include "debug.h"
42 : #endif
43 : #include <math.h>
44 : #include "prot.h"
45 : #include "cnst.h"
46 : #include "stat_dec.h"
47 : #include "ivas_prot.h"
48 : #include "wmc_auto.h"
49 :
50 :
51 : /*-------------------------------------------------------------------*
52 : * IGF_replaceTCXNoise_1()
53 : *
54 : * measures TCX noise
55 : *-------------------------------------------------------------------*/
56 :
57 : /*! r: number of noise bands */
58 1833576 : static int16_t IGF_replaceTCXNoise_1(
59 : const float *in, /* i : MDCT spectrum */
60 : const uint8_t *TCXNoise, /* i : tcx noise indicator vector */
61 : const int16_t start, /* i : start MDCT subband index */
62 : const int16_t stop, /* i : stop MDCT subband index */
63 : float *totalNoiseNrg /* o : measured noise energy */
64 : )
65 : {
66 : int16_t sb;
67 : int16_t noise;
68 : float nE;
69 : float val;
70 :
71 1833576 : noise = 0;
72 1833576 : nE = FLT_MIN;
73 :
74 697385760 : for ( sb = start; sb < stop; sb++ )
75 : {
76 695552184 : val = in[sb] * TCXNoise[sb];
77 695552184 : nE += val * val;
78 695552184 : noise += TCXNoise[sb];
79 : }
80 :
81 1833576 : *totalNoiseNrg = nE;
82 :
83 1833576 : return noise;
84 : }
85 :
86 :
87 : /*-------------------------------------------------------------------*
88 : * IGF_replaceTCXNoise_2()
89 : *
90 : * replaces TCX noise
91 : *-------------------------------------------------------------------*/
92 :
93 2637 : static void IGF_replaceTCXNoise_2(
94 : float *in, /* i/o: MDCT spectrum */
95 : const uint8_t *TCXNoise, /* i : tcx noise indicator vector */
96 : const int16_t start, /* i : start MDCT subband index */
97 : const int16_t stop, /* i : stop MDCT subband index */
98 : float totalNoiseNrg, /* i : measured noise energy */
99 : int16_t *nfSeed /* i/o: random generator noise seed */
100 : )
101 : {
102 : int16_t sb;
103 : float rE;
104 : float g;
105 : float val;
106 :
107 2637 : rE = FLT_MIN;
108 606933 : for ( sb = start; sb < stop; sb++ )
109 : {
110 604296 : if ( TCXNoise[sb] )
111 : {
112 484992 : val = (float) own_random( nfSeed );
113 484992 : in[sb] = val;
114 484992 : rE += val * val;
115 : }
116 : }
117 :
118 2637 : g = (float) sqrt( totalNoiseNrg / rE );
119 :
120 606933 : for ( sb = start; sb < stop; sb++ )
121 : {
122 604296 : if ( TCXNoise[sb] )
123 : {
124 484992 : in[sb] *= g;
125 : }
126 : }
127 :
128 2637 : return;
129 : }
130 :
131 :
132 : /*-------------------------------------------------------------------*
133 : * IGF_replaceTCXNoise_2_new()
134 : *
135 : *
136 : *-------------------------------------------------------------------*/
137 :
138 4746543 : static void IGF_replaceTCXNoise_2_new(
139 : float *in, /* i/o: MDCT spectrum */
140 : const uint8_t *TCXNoise, /* i : tcx noise indicator vector */
141 : const int16_t start, /* i : start MDCT subband index */
142 : const int16_t stop, /* i : stop MDCT subband index */
143 : float totalNoiseNrg, /* i : measured noise energy */
144 : int16_t n_noise_bands, /* i : number of noise bands in src */
145 : int16_t *nfSeed /* i/o: random generator noise seed */
146 : )
147 : {
148 : int16_t sb;
149 : float rE;
150 : float g;
151 : float val;
152 : int16_t n_noise_bands_tile;
153 : float noise_band_ratio;
154 :
155 4746543 : rE = FLT_MIN;
156 4746543 : n_noise_bands_tile = 0;
157 385299369 : for ( sb = start; sb < stop; sb++ )
158 : {
159 380552826 : if ( TCXNoise[sb] )
160 : {
161 328369935 : val = (float) own_random( nfSeed );
162 328369935 : in[sb] = val;
163 328369935 : rE += val * val;
164 328369935 : n_noise_bands_tile++;
165 : }
166 : }
167 :
168 4746543 : rE = max( rE, 1.f );
169 :
170 4746543 : if ( n_noise_bands_tile )
171 : {
172 4746114 : noise_band_ratio = (float) n_noise_bands_tile / n_noise_bands;
173 4746114 : g = (float) sqrt( totalNoiseNrg * noise_band_ratio / rE );
174 :
175 385286880 : for ( sb = start; sb < stop; sb++ )
176 : {
177 380540766 : if ( TCXNoise[sb] )
178 : {
179 328369935 : in[sb] *= g;
180 : }
181 : }
182 : }
183 :
184 4746543 : return;
185 : }
186 :
187 :
188 : /*-------------------------------------------------------------------*
189 : * IGF_decode_whitening_level()
190 : *
191 : * reads whitening levels
192 : *-------------------------------------------------------------------*/
193 :
194 3702867 : static void IGF_decode_whitening_level(
195 : Decoder_State *st, /* i : decoder state */
196 : IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /* i/o: instance handle of IGF Deccoder */
197 : const int16_t p /* i : tile index, p = [0, 3] */
198 : )
199 : {
200 : int16_t tmp;
201 :
202 3702867 : tmp = get_next_indice( st, 1 );
203 :
204 3702867 : if ( tmp == 1 )
205 : {
206 2316030 : tmp = get_next_indice( st, 1 );
207 2316030 : if ( tmp == 1 )
208 : {
209 1146729 : hPrivateData->currWhiteningLevel[p] = IGF_WHITENING_STRONG;
210 : }
211 : else
212 : {
213 1169301 : hPrivateData->currWhiteningLevel[p] = IGF_WHITENING_OFF;
214 : }
215 : }
216 : else
217 : {
218 1386837 : hPrivateData->currWhiteningLevel[p] = IGF_WHITENING_MID;
219 : }
220 :
221 3702867 : return;
222 : }
223 :
224 :
225 : /*-------------------------------------------------------------------*
226 : * IGF_getMDCTSquare()
227 : *
228 : * square the MDCT spectrum
229 : *-------------------------------------------------------------------*/
230 :
231 3645402 : static void IGF_getMDCTSquare(
232 : const int16_t startLine, /* i : start MDCT subband index */
233 : const int16_t stopLine, /* i : stop MDCT subband index */
234 : const float *pSpectralData, /* i : MDCT spectrum */
235 : float *pSpecDataSqaure /* o : Squared MDCT spectrum */
236 : )
237 : {
238 : int16_t i;
239 :
240 1056583482 : for ( i = startLine; i < stopLine; i++ )
241 : {
242 1052938080 : pSpecDataSqaure[i] = pSpectralData[i] * pSpectralData[i];
243 : }
244 :
245 3645402 : return;
246 : }
247 :
248 :
249 : /*-------------------------------------------------------------------*
250 : * IGF_calcSfbEnergy()
251 : *
252 : * calculate energy per SFB
253 : *-------------------------------------------------------------------*/
254 :
255 3645402 : static void IGF_calcSfbEnergy(
256 : const int16_t startSfb, /* i : start sfb index */
257 : const int16_t stopSfb, /* i : stop sfb index */
258 : const int16_t *swb_offset, /* i : IGF swb offset table */
259 : const float *pPowerSpectrum, /* i : power spectrum */
260 : float *sfbEnergy /* o : SFB energies, will be initialized inside this function */
261 : )
262 : {
263 : int16_t sfb;
264 : int16_t line;
265 :
266 38281620 : for ( sfb = startSfb; sfb < stopSfb; sfb++ )
267 : {
268 34636218 : sfbEnergy[sfb] = 0.f;
269 :
270 1087574298 : for ( line = swb_offset[sfb]; line < swb_offset[sfb + 1]; line++ )
271 : {
272 1052938080 : sfbEnergy[sfb] += pPowerSpectrum[line];
273 : }
274 : }
275 :
276 3645402 : return;
277 : }
278 :
279 :
280 : /*-------------------------------------------------------------------*
281 : * IGF_setLinesToZero()
282 : *
283 : * set power spectrum values to zero, needed for energy calculation
284 : *-------------------------------------------------------------------*/
285 :
286 1822701 : static void IGF_setLinesToZero(
287 : const int16_t startLine, /* i : start MDCT subband index */
288 : const int16_t stopLine, /* i : stop MDCT subband index */
289 : const float *pSpectralData, /* i : original MDCT spectrum */
290 : float *squareSpecIGF /* i/o: prepared IGF energy spectrum */
291 : )
292 : {
293 : int16_t i;
294 :
295 528291741 : for ( i = startLine; i < stopLine; i++ )
296 : {
297 526469040 : if ( pSpectralData[i] != 0.f )
298 : {
299 60501 : squareSpecIGF[i] = 0.f;
300 : }
301 : }
302 :
303 1822701 : return;
304 : }
305 :
306 :
307 : /*-------------------------------------------------------------------*
308 : * IGF_prep()
309 : *
310 : * prepare IGF spectrum
311 : *-------------------------------------------------------------------*/
312 :
313 1284633 : static void IGF_prep(
314 : IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /* i : IGF private data handle */
315 : const int16_t igfGridIdx, /* i : in case of CELP->TCX switching, use 1.25 framelength */
316 : const uint8_t *TCXNoise, /* i : TCX noise vector */
317 : float *igf_spec, /* o : prepared IGF spectrum */
318 : float *src_spec, /* i : source spectrum */
319 : const int16_t element_mode /* i : IVAS element mode */
320 : )
321 : {
322 : H_IGF_GRID hGrid;
323 : H_IGF_INFO hInfo;
324 : int16_t i, tb, sfb, strt_cpy, tile_idx;
325 : int16_t *swb_offset;
326 : float *sel_spec;
327 :
328 1284633 : hInfo = &hPrivateData->igfInfo;
329 1284633 : hGrid = &hPrivateData->igfInfo.grid[igfGridIdx];
330 1284633 : swb_offset = hGrid->swb_offset;
331 :
332 5638437 : for ( tile_idx = 0; tile_idx < hGrid->nTiles; tile_idx++ )
333 : {
334 : int16_t tile_width, stop;
335 :
336 4353804 : strt_cpy = hGrid->sbWrap[tile_idx];
337 :
338 4353804 : if ( element_mode > EVS_MONO )
339 : {
340 4348815 : tile_width = swb_offset[hGrid->sfbWrap[tile_idx + 1]] - swb_offset[hGrid->sfbWrap[tile_idx]];
341 4348815 : stop = strt_cpy + tile_width;
342 : }
343 : else
344 : {
345 4989 : stop = hGrid->startLine;
346 : }
347 :
348 4353804 : if ( IGF_WHITENING_STRONG == hPrivateData->currWhiteningLevel[tile_idx] )
349 : {
350 : float abs_sum;
351 1198044 : abs_sum = 0.f;
352 :
353 127097052 : for ( i = strt_cpy; i < stop; i++ )
354 : {
355 125899008 : abs_sum += (float) fabs( src_spec[i] );
356 : }
357 :
358 1198044 : tb = swb_offset[hGrid->sfbWrap[tile_idx]];
359 :
360 1198044 : if ( abs_sum > 0.f )
361 : {
362 126884532 : for ( i = strt_cpy; i < stop; i++ )
363 : {
364 125689158 : igf_spec[tb++] = own_random( hInfo->nfSeed );
365 : }
366 : }
367 : else
368 : {
369 212520 : for ( i = strt_cpy; i < stop; i++ )
370 : {
371 209850 : igf_spec[tb++] = 0.f;
372 : }
373 : }
374 : }
375 : else
376 : {
377 3155760 : if ( IGF_WHITENING_MID == hPrivateData->currWhiteningLevel[tile_idx] )
378 : {
379 1384494 : if ( element_mode > EVS_MONO )
380 : {
381 1382802 : if ( hPrivateData->n_noise_bands )
382 : {
383 1323576 : IGF_replaceTCXNoise_2_new( igf_spec, TCXNoise, strt_cpy, stop, hPrivateData->totalNoiseNrg, hPrivateData->n_noise_bands, hInfo->nfSeed );
384 : }
385 : }
386 : else
387 : {
388 1692 : if ( hPrivateData->n_noise_bands )
389 : {
390 1692 : IGF_replaceTCXNoise_2( igf_spec, TCXNoise, hGrid->minSrcSubband, hGrid->startLine, hPrivateData->totalNoiseNrg, hInfo->nfSeed );
391 : }
392 : }
393 :
394 1384494 : sel_spec = igf_spec;
395 : }
396 : else
397 : {
398 1771266 : if ( element_mode > EVS_MONO )
399 : {
400 1770315 : if ( hPrivateData->n_noise_bands_off )
401 : {
402 1733142 : IGF_replaceTCXNoise_2_new( src_spec, TCXNoise, strt_cpy, stop, hPrivateData->totalNoiseNrg_off, hPrivateData->n_noise_bands_off, hInfo->nfSeed );
403 : }
404 : }
405 : else
406 : {
407 951 : if ( hPrivateData->n_noise_bands_off )
408 : {
409 945 : IGF_replaceTCXNoise_2( src_spec, TCXNoise, hGrid->minSrcSubband, hGrid->startLine, hPrivateData->totalNoiseNrg_off, hInfo->nfSeed );
410 : }
411 : }
412 :
413 1771266 : sel_spec = src_spec;
414 : }
415 11442750 : for ( sfb = hGrid->sfbWrap[tile_idx]; sfb < hGrid->sfbWrap[tile_idx + 1]; sfb++ )
416 : {
417 261272406 : for ( tb = swb_offset[sfb]; tb < swb_offset[sfb + 1]; tb++ )
418 : {
419 252985416 : igf_spec[tb] = sel_spec[strt_cpy];
420 252985416 : strt_cpy++;
421 : }
422 : }
423 : }
424 : }
425 :
426 1284633 : return;
427 : }
428 :
429 :
430 : /*-------------------------------------------------------------------*
431 : * IGF_prepStereo()
432 : *
433 : *
434 : *-------------------------------------------------------------------*/
435 :
436 269034 : static void IGF_prepStereo(
437 : IGF_DEC_PRIVATE_DATA_HANDLE hPrivateDataL, /* i : IGF private data handle */
438 : IGF_DEC_PRIVATE_DATA_HANDLE hPrivateDataR, /* i : IGF private data handle */
439 : const int16_t igfGridIdx, /* i : in case of CELP->TCX switching, use 1.25 framelength */
440 : const uint8_t *TCXNoiseL, /* i : TCX noise vector */
441 : const uint8_t *TCXNoiseR, /* i : TCX noise vector */
442 : float *igf_specL, /* o : prepared IGF spectrum */
443 : float *igf_specR, /* o : prepared IGF spectrum */
444 : float *src_specL, /* i : source spectrum */
445 : float *src_specR, /* i : source spectrum */
446 : const int16_t *coreMsMask /* i : line wise ms Mask */
447 : )
448 : {
449 : H_IGF_GRID hGrid;
450 : H_IGF_INFO hInfoL, hInfoR;
451 : int16_t tb, sfb, strt_cpy, tile_idx;
452 : int16_t *swb_offset;
453 269034 : float *sel_specL = NULL;
454 269034 : float *sel_specR = NULL;
455 269034 : const float c = SQRT2_OVER_2; /* M/S scaling factor */
456 :
457 269034 : hInfoL = &hPrivateDataL->igfInfo;
458 269034 : hInfoR = &hPrivateDataR->igfInfo;
459 269034 : hGrid = &hPrivateDataL->igfInfo.grid[igfGridIdx];
460 269034 : swb_offset = hGrid->swb_offset;
461 :
462 1127826 : for ( tile_idx = 0; tile_idx < hGrid->nTiles; tile_idx++ )
463 : {
464 : int16_t tile_width, stop;
465 858792 : strt_cpy = hGrid->sbWrap[tile_idx];
466 :
467 858792 : tile_width = swb_offset[hGrid->sfbWrap[tile_idx + 1]] - swb_offset[hGrid->sfbWrap[tile_idx]];
468 858792 : stop = strt_cpy + tile_width;
469 :
470 858792 : if ( IGF_WHITENING_STRONG == hPrivateDataL->currWhiteningLevel[tile_idx] )
471 : {
472 174498 : tb = swb_offset[hGrid->sfbWrap[tile_idx]];
473 :
474 16786338 : for ( tb = swb_offset[hGrid->sfbWrap[tile_idx]]; tb < swb_offset[hGrid->sfbWrap[tile_idx + 1]]; tb++ )
475 : {
476 16611840 : igf_specL[tb] = own_random( hInfoL->nfSeed );
477 : }
478 : }
479 : else
480 : {
481 684294 : if ( IGF_WHITENING_MID == hPrivateDataL->currWhiteningLevel[tile_idx] )
482 : {
483 244929 : if ( hPrivateDataL->n_noise_bands )
484 : {
485 243843 : IGF_replaceTCXNoise_2_new( igf_specL, TCXNoiseL, strt_cpy, stop, hPrivateDataL->totalNoiseNrg, hPrivateDataL->n_noise_bands, hInfoL->nfSeed );
486 : }
487 244929 : sel_specL = igf_specL;
488 : }
489 : else
490 : {
491 439365 : if ( hPrivateDataL->n_noise_bands_off )
492 : {
493 430434 : IGF_replaceTCXNoise_2_new( src_specL, TCXNoiseL, strt_cpy, stop, hPrivateDataL->totalNoiseNrg_off, hPrivateDataL->n_noise_bands_off, hInfoL->nfSeed );
494 : }
495 439365 : sel_specL = src_specL;
496 : }
497 :
498 684294 : if ( IGF_WHITENING_MID == hPrivateDataL->currWhiteningLevel[tile_idx] )
499 : {
500 244929 : if ( hPrivateDataR->n_noise_bands )
501 : {
502 240456 : IGF_replaceTCXNoise_2_new( igf_specR, TCXNoiseR, strt_cpy, stop, hPrivateDataR->totalNoiseNrg, hPrivateDataR->n_noise_bands, hInfoR->nfSeed );
503 : }
504 244929 : sel_specR = igf_specR;
505 : }
506 : else
507 : {
508 439365 : if ( hPrivateDataR->n_noise_bands_off )
509 : {
510 417096 : IGF_replaceTCXNoise_2_new( src_specR, TCXNoiseR, strt_cpy, stop, hPrivateDataR->totalNoiseNrg_off, hPrivateDataR->n_noise_bands_off, hInfoR->nfSeed );
511 : }
512 439365 : sel_specR = src_specR;
513 : }
514 :
515 2566938 : for ( sfb = hGrid->sfbWrap[tile_idx]; sfb < hGrid->sfbWrap[tile_idx + 1]; sfb++ )
516 : {
517 59133642 : for ( tb = swb_offset[sfb]; tb < swb_offset[sfb + 1]; tb++ )
518 : {
519 : #ifdef DEBUGGING
520 : assert( strt_cpy < hGrid->swb_offset[0] );
521 : #endif
522 :
523 57250998 : if ( coreMsMask[tb] == 0 )
524 : {
525 23207832 : if ( coreMsMask[strt_cpy] == 0 ) /* LR->LR */
526 : {
527 7138194 : igf_specL[tb] = sel_specL[strt_cpy];
528 : }
529 : else /* MS/DR -> LR */
530 : {
531 16069638 : igf_specL[tb] = ( sel_specL[strt_cpy] + sel_specR[strt_cpy] ) * c;
532 : }
533 : }
534 : else
535 : {
536 34043166 : if ( coreMsMask[strt_cpy] == 0 ) /* LR->MS/DR */
537 : {
538 866004 : igf_specL[tb] = ( sel_specL[strt_cpy] + sel_specR[strt_cpy] ) * c;
539 : }
540 : else /* MS/DR -> MS/DR */
541 : {
542 33177162 : igf_specL[tb] = sel_specL[strt_cpy];
543 : }
544 : }
545 57250998 : strt_cpy++;
546 : }
547 : }
548 : }
549 :
550 858792 : strt_cpy = hGrid->sbWrap[tile_idx];
551 :
552 858792 : if ( IGF_WHITENING_STRONG == hPrivateDataR->currWhiteningLevel[tile_idx] )
553 : {
554 165522 : tb = swb_offset[hGrid->sfbWrap[tile_idx]];
555 :
556 17101050 : for ( tb = swb_offset[hGrid->sfbWrap[tile_idx]]; tb < swb_offset[hGrid->sfbWrap[tile_idx + 1]]; tb++ )
557 : {
558 16935528 : igf_specR[tb] = own_random( hInfoR->nfSeed );
559 : }
560 : }
561 : else
562 : {
563 693270 : if ( hPrivateDataR->currWhiteningLevel[tile_idx] != hPrivateDataL->currWhiteningLevel[tile_idx] )
564 : {
565 181431 : if ( IGF_WHITENING_MID == hPrivateDataR->currWhiteningLevel[tile_idx] )
566 : {
567 94026 : if ( hPrivateDataL->n_noise_bands )
568 : {
569 93474 : IGF_replaceTCXNoise_2_new( igf_specL, TCXNoiseL, strt_cpy, stop, hPrivateDataL->totalNoiseNrg, hPrivateDataL->n_noise_bands, hInfoL->nfSeed );
570 : }
571 94026 : sel_specL = igf_specL;
572 : }
573 : else
574 : {
575 87405 : if ( hPrivateDataL->n_noise_bands_off )
576 : {
577 86811 : IGF_replaceTCXNoise_2_new( src_specL, TCXNoiseL, strt_cpy, stop, hPrivateDataL->totalNoiseNrg_off, hPrivateDataL->n_noise_bands_off, hInfoL->nfSeed );
578 : }
579 87405 : sel_specL = src_specL;
580 : }
581 :
582 181431 : if ( IGF_WHITENING_MID == hPrivateDataR->currWhiteningLevel[tile_idx] )
583 : {
584 94026 : if ( hPrivateDataR->n_noise_bands )
585 : {
586 92604 : IGF_replaceTCXNoise_2_new( igf_specR, TCXNoiseR, strt_cpy, stop, hPrivateDataR->totalNoiseNrg, hPrivateDataR->n_noise_bands, hInfoR->nfSeed );
587 : }
588 94026 : sel_specR = igf_specR;
589 : }
590 : else
591 : {
592 87405 : if ( hPrivateDataR->n_noise_bands_off )
593 : {
594 85107 : IGF_replaceTCXNoise_2_new( src_specR, TCXNoiseR, strt_cpy, stop, hPrivateDataR->totalNoiseNrg_off, hPrivateDataR->n_noise_bands_off, hInfoR->nfSeed );
595 : }
596 87405 : sel_specR = src_specR;
597 : }
598 : }
599 :
600 2611392 : for ( sfb = hGrid->sfbWrap[tile_idx]; sfb < hGrid->sfbWrap[tile_idx + 1]; sfb++ )
601 : {
602 58845432 : for ( tb = swb_offset[sfb]; tb < swb_offset[sfb + 1]; tb++ )
603 : {
604 : #ifdef DEBUGGING
605 : assert( strt_cpy < hGrid->swb_offset[0] );
606 : #endif
607 :
608 56927310 : if ( coreMsMask[tb] == 0 )
609 : {
610 22928016 : if ( coreMsMask[strt_cpy] == 0 ) /* LR->LR */
611 : {
612 7081692 : igf_specR[tb] = sel_specR[strt_cpy];
613 : }
614 : else /* MS/DR -> LR */
615 : {
616 15846324 : igf_specR[tb] = ( sel_specL[strt_cpy] - sel_specR[strt_cpy] ) * c;
617 : }
618 : }
619 : else
620 : {
621 33999294 : if ( coreMsMask[strt_cpy] == 0 ) /* LR->MS/DR */
622 : {
623 860028 : igf_specR[tb] = ( sel_specL[strt_cpy] - sel_specR[strt_cpy] ) * c;
624 : }
625 : else /* MS/DR -> MS/DR */
626 : {
627 33139266 : igf_specR[tb] = sel_specR[strt_cpy];
628 : }
629 : }
630 56927310 : strt_cpy++;
631 : }
632 : }
633 : }
634 : }
635 :
636 269034 : return;
637 : }
638 :
639 :
640 : /*-------------------------------------------------------------------*
641 : * IGF_calc()
642 : *
643 : * calculates IGF energies
644 : *-------------------------------------------------------------------*/
645 :
646 1822701 : static void IGF_calc(
647 : const IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /* i/o: IGF private data handle */
648 : const int16_t igfGridIdx, /* i : in case of CELP->TCX switching, use 1.25 framelength */
649 : const float *spectrum, /* i : MDCT spectrum */
650 : const float *igf_spec /* i : prepared IGF spectrum */
651 : )
652 : {
653 : H_IGF_GRID hGrid;
654 : float *igf_pN;
655 : float *igf_sN;
656 : float tmp[N_MAX_TCX];
657 :
658 1822701 : set_zero( tmp, N_MAX_TCX );
659 :
660 1822701 : hGrid = &hPrivateData->igfInfo.grid[igfGridIdx];
661 1822701 : igf_pN = hPrivateData->igf_pN;
662 1822701 : igf_sN = hPrivateData->igf_sN;
663 :
664 1822701 : IGF_getMDCTSquare( hGrid->startLine, hGrid->stopLine, spectrum, tmp );
665 1822701 : IGF_calcSfbEnergy( hGrid->startSfb, hGrid->stopSfb, hGrid->swb_offset, tmp, igf_sN );
666 1822701 : IGF_getMDCTSquare( hGrid->startLine, hGrid->stopLine, igf_spec, tmp );
667 1822701 : IGF_setLinesToZero( hGrid->startLine, hGrid->stopLine, spectrum, tmp );
668 1822701 : IGF_calcSfbEnergy( hGrid->startSfb, hGrid->stopSfb, hGrid->swb_offset, tmp, igf_pN );
669 :
670 1822701 : return;
671 : }
672 :
673 :
674 : /*-------------------------------------------------------------------*
675 : * IGF_appl()
676 : *
677 : * apply IGF
678 : *-------------------------------------------------------------------*/
679 :
680 1822701 : static void IGF_appl(
681 : IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /* i : IGF private data handle */
682 : const int16_t igfGridIdx, /* i : in case of ACELP->TCX switching, use 1.25 framelength*/
683 : float *pSpectralData, /* i/o: Q31 | MDCT spectrum */
684 : const float *igf_spec, /* i : Q31 | prepared IGF spectrum */
685 : float *virtualSpec, /* o : Q31 | virtual IGF spectrum, used for temp flattening */
686 : int16_t *flag_sparse, /* o : Q0 | temp flattening indicator */
687 : const int16_t bfi_apply_damping /* i : flag to indicate if damping for lost frames should be applied */
688 : )
689 : {
690 : H_IGF_GRID hGrid;
691 : int16_t tb; /* target subband */
692 : int16_t sfb, s_sfb, start_sfb, stop_sfb;
693 : int16_t *swb_offset;
694 : int16_t hopsize;
695 : float tmp, dE;
696 : float dN[IGF_MAX_SFB + 1];
697 : float gain[IGF_MAX_SFB];
698 : float dS[IGF_MAX_SFB];
699 : float width;
700 : float sNlocal;
701 : float E, sum, val;
702 : float w0, w1, w2;
703 : float *sN, *pN;
704 : float gFactor; /* general SCF adaption */
705 : float fFactor; /* first SCF adaption */
706 : float lFactor; /* last SCF adaption */
707 : int16_t idx, idx1;
708 :
709 : /* initialize variables */
710 1822701 : w0 = 0.201f;
711 1822701 : w1 = 0.389f;
712 1822701 : w2 = 0.410f;
713 1822701 : dE = 0.f;
714 :
715 :
716 : /* more inits */
717 1822701 : hGrid = &hPrivateData->igfInfo.grid[igfGridIdx];
718 1822701 : sN = hPrivateData->igf_sN;
719 1822701 : pN = hPrivateData->igf_pN;
720 1822701 : start_sfb = hGrid->startSfb;
721 1822701 : stop_sfb = hGrid->stopSfb;
722 1822701 : gFactor = hGrid->gFactor;
723 1822701 : fFactor = hGrid->fFactor;
724 1822701 : lFactor = hGrid->lFactor;
725 1822701 : swb_offset = hGrid->swb_offset;
726 :
727 : #ifdef DEBUGGING
728 : /* make sure we don't read/write OOB for arrays whose size was reduced by IGF_START_MN to safe on memory */
729 : assert( swb_offset[start_sfb] >= IGF_START_MN );
730 : #endif
731 :
732 : /* collect energy below hGrid->startLine: */
733 45567525 : for ( tb = hGrid->startLine - 24; tb < hGrid->startLine; tb++ )
734 : {
735 43744824 : dE += pSpectralData[tb] * pSpectralData[tb];
736 : }
737 1822701 : dE = (float) sqrt( dE / 24. );
738 :
739 1822701 : hopsize = 2;
740 1822701 : hopsize = ( hPrivateData->currWhiteningLevel[0] == IGF_WHITENING_OFF ) ? 4 : hopsize;
741 1822701 : hopsize = ( hPrivateData->currWhiteningLevel[0] == IGF_WHITENING_MID ) ? 2 : hopsize;
742 1822701 : hopsize = ( hPrivateData->currWhiteningLevel[0] == IGF_WHITENING_STRONG ) ? 1 : hopsize;
743 1822701 : hopsize = min( hopsize, hPrivateData->igfInfo.maxHopsize );
744 :
745 1822701 : if ( hPrivateData->restrict_hopsize )
746 : {
747 85212 : hopsize = min( hopsize, 2 );
748 : }
749 :
750 1822701 : if ( hopsize > 1 )
751 : {
752 6505830 : for ( sfb = start_sfb; sfb < stop_sfb; sfb += hopsize )
753 : {
754 11402016 : for ( tb = sfb + 1; tb < min( ( sfb + hopsize ), stop_sfb ); tb++ )
755 : {
756 5769336 : sN[sfb] += sN[tb];
757 5769336 : pN[sfb] += pN[tb];
758 5769336 : sN[tb] = 0.f;
759 5769336 : pN[tb] = 0.f;
760 : }
761 : }
762 : }
763 :
764 : /* IGF_rescale_SCF */
765 1822701 : if ( hGrid->infoIsRefined )
766 : {
767 9104964 : for ( sfb = start_sfb; sfb < stop_sfb; sfb += 2 )
768 : {
769 7862643 : width = (float) ( swb_offset[sfb + 2] - swb_offset[sfb] );
770 :
771 7862643 : tmp = (float) hPrivateData->igf_curr[sfb >> 1];
772 7862643 : tmp = (float) pow( 2.0, 0.25 * tmp - 4.0 );
773 7862643 : tmp = tmp * tmp;
774 :
775 7862643 : sNlocal = sN[sfb] + sN[sfb + 1];
776 7862643 : sNlocal /= width;
777 :
778 7862643 : tmp = (float) max( 0.001 * sNlocal, tmp - sNlocal );
779 7862643 : dN[sfb] = (float) sqrt( tmp );
780 7862643 : dN[sfb + 1] = dN[sfb];
781 : }
782 : }
783 : else
784 : {
785 2173203 : for ( sfb = start_sfb; sfb < stop_sfb; sfb++ )
786 : {
787 1592823 : width = (float) ( swb_offset[sfb + 1] - swb_offset[sfb] );
788 :
789 1592823 : tmp = (float) hPrivateData->igf_curr[sfb];
790 1592823 : tmp = (float) pow( 2.0, 0.25 * tmp - 4.0 );
791 1592823 : tmp = tmp * tmp;
792 :
793 1592823 : sNlocal = sN[sfb];
794 1592823 : sNlocal /= width;
795 :
796 1592823 : tmp = (float) max( 0.001 * sNlocal, tmp - sNlocal );
797 1592823 : dN[sfb] = (float) sqrt( tmp );
798 : }
799 : }
800 :
801 1822701 : dS[start_sfb] = dN[start_sfb];
802 : /* first value with adaption to core energy: */
803 1822701 : if ( dE < dN[start_sfb] )
804 : {
805 1109742 : dS[start_sfb] = dN[start_sfb] + fFactor * ( dE - dN[start_sfb] );
806 : }
807 : /* last value with less energy: */
808 1822701 : dS[stop_sfb - 1] = lFactor * dN[stop_sfb - 1];
809 :
810 1822701 : if ( hGrid->infoIsRefined && hopsize == 1 )
811 : {
812 : /* apply filter to absolute energy values: */
813 3954099 : for ( sfb = start_sfb + 1; sfb < stop_sfb - 1; sfb++ )
814 : {
815 3584928 : dS[sfb] = w0 * dN[sfb - 1] + w1 * dN[sfb] + w2 * dN[sfb + 1];
816 : }
817 : }
818 : else
819 : {
820 11541309 : for ( sfb = start_sfb + 1; sfb < stop_sfb - 1; sfb++ )
821 : {
822 10087779 : dS[sfb] = dN[sfb];
823 : }
824 : }
825 :
826 13371474 : for ( sfb = start_sfb; sfb < stop_sfb; sfb += hopsize )
827 : {
828 11548773 : E = 0.f;
829 11548773 : sum = 0;
830 28944000 : for ( tb = 0; tb < hopsize; tb++ )
831 : {
832 17395227 : idx1 = min( sfb + tb + 1, stop_sfb );
833 17395227 : idx = min( sfb + tb, stop_sfb );
834 17395227 : width = (float) ( swb_offset[idx1] - swb_offset[idx] );
835 17395227 : idx = min( sfb + tb, stop_sfb - 1 );
836 17395227 : val = dS[idx];
837 17395227 : E += val * val * width;
838 17395227 : sum += width;
839 : }
840 :
841 11548773 : dS[sfb] = (float) sqrt( ( E * hopsize ) / sum );
842 11548773 : dN[sfb] = gFactor * dS[sfb];
843 :
844 11548773 : width = (float) ( swb_offset[sfb + 1] - swb_offset[sfb] );
845 11548773 : dN[sfb] = dN[sfb] * dN[sfb] * width;
846 11548773 : gain[sfb] = 0.f;
847 :
848 11548773 : if ( pN[sfb] > 1.e-20f )
849 : {
850 11495931 : gain[sfb] = (float) sqrt( dN[sfb] / pN[sfb] );
851 : }
852 :
853 17318109 : for ( s_sfb = sfb + 1; s_sfb < min( sfb + hopsize, stop_sfb ); s_sfb++ )
854 : {
855 5769336 : gain[s_sfb] = gain[sfb];
856 : }
857 : }
858 :
859 : /* tiling */
860 19140810 : for ( sfb = start_sfb; sfb < stop_sfb; sfb++ )
861 : {
862 :
863 17318109 : if ( bfi_apply_damping && hPrivateData->frameLossCounter > 0 )
864 : {
865 162732 : gain[sfb] = min( gain[sfb], 12.f );
866 :
867 162732 : if ( hPrivateData->frameLossCounter < 5 )
868 : {
869 124608 : gain[sfb] -= gain[sfb] / 8 * hPrivateData->frameLossCounter;
870 : }
871 : else
872 : {
873 38124 : gain[sfb] /= 2;
874 : }
875 : }
876 :
877 543787149 : for ( tb = swb_offset[sfb]; tb < swb_offset[sfb + 1]; tb++ )
878 : {
879 526469040 : if ( pSpectralData[tb] == 0.f )
880 : {
881 526408539 : pSpectralData[tb] = igf_spec[tb] * gain[sfb];
882 526408539 : flag_sparse[tb - IGF_START_MN] = 1;
883 : }
884 : else
885 : {
886 60501 : virtualSpec[tb - IGF_START_MN] = igf_spec[tb] * gain[sfb];
887 60501 : flag_sparse[tb - IGF_START_MN] = 2;
888 : }
889 : }
890 : }
891 :
892 1822701 : return;
893 : }
894 :
895 :
896 : /*-------------------------------------------------------------------*
897 : * IGF_getWhiteSpectralData()
898 : *
899 : * spectral whitening
900 : *-------------------------------------------------------------------*/
901 :
902 942021 : static void IGF_getWhiteSpectralData(
903 : const float *in, /* i : MDCT spectrum */
904 : float *out, /* o : whitened spectrum */
905 : const int16_t start, /* i : start MDCT subband index */
906 : const int16_t stop, /* i : stop MDCT subband index */
907 : const int16_t level /* i : whitening strength */
908 : )
909 : {
910 : int16_t i;
911 : int16_t n;
912 : int16_t j;
913 : float div;
914 : float ak;
915 :
916 : /* inits */
917 942021 : div = 0.0f;
918 :
919 387000018 : for ( i = start; i < stop - level; i++ )
920 : {
921 386057997 : ak = 1e-3f;
922 7720246944 : for ( j = i - level; j < i + level + 1; j++ )
923 : {
924 7334188947 : ak += in[j] * in[j];
925 : }
926 386057997 : ak /= (float) ( level * 2 + 1 );
927 :
928 :
929 386057997 : n = (int16_t) max( 0.f, ( log( ak ) * INV_LOG_2 ) ); /* INV_LOG_2 = 1 / (float)log(2.0f)) */
930 386057997 : n >>= 1; /* sqrt() */
931 386057997 : div = (float) ( pow( 2.0f, (float) ( 21 - n ) ) );
932 :
933 :
934 386057997 : out[i] = in[i] * div; /* same as shift */
935 : }
936 :
937 9418128 : for ( ; i < stop; i++ )
938 : {
939 8476107 : ak = 1e-3f;
940 :
941 127119744 : for ( j = i - level; j < stop; j++ )
942 : {
943 118643637 : ak += in[j] * in[j];
944 : }
945 8476107 : ak /= (float) ( stop - ( i - level ) );
946 :
947 :
948 8476107 : n = (int16_t) max( 0.f, ( log( ak ) * INV_LOG_2 ) ); /* INV_LOG_2 = 1 / (float)log(2.0f)) */
949 8476107 : n >>= 1; /* sqrt() */
950 8476107 : div = (float) ( pow( 2.0f, (float) ( 21 - n ) ) );
951 :
952 :
953 8476107 : out[i] = in[i] * div; /* same as shift */
954 : }
955 :
956 942021 : return;
957 : }
958 :
959 :
960 : /*-------------------------------------------------------------------*
961 : * IGF_RefineGrid()
962 : *
963 : * refines the IGF grid
964 : *-------------------------------------------------------------------*/
965 :
966 159552 : static void IGF_RefineGrid(
967 : H_IGF_GRID hGrid /* i/o: IGF grid handle */
968 : )
969 : {
970 : int16_t a[IGF_MAX_SFB + 1]; /* +1: because in for-loop one value too much will be extrapolated */
971 : int16_t sfb;
972 :
973 159552 : set_s( a, 0, IGF_MAX_SFB + 1 );
974 :
975 :
976 159552 : hGrid->infoIsRefined = 1;
977 1418178 : for ( sfb = 0; sfb < hGrid->swb_offset_len; sfb++ )
978 : {
979 1258626 : a[sfb * 2 + 0] = hGrid->swb_offset[sfb];
980 1258626 : a[sfb * 2 + 1] = (int16_t) round_f( hGrid->swb_offset[sfb] + 0.45f * ( hGrid->swb_offset[sfb + 1] - hGrid->swb_offset[sfb] ) );
981 1258626 : if ( a[sfb * 2 + 1] & 1 )
982 : {
983 474402 : a[sfb * 2 + 1]--;
984 : }
985 : }
986 159552 : hGrid->stopSfb = hGrid->stopSfb * 2;
987 2517252 : for ( sfb = 0; sfb <= hGrid->stopSfb; sfb++ )
988 : {
989 2357700 : hGrid->swb_offset[sfb] = a[sfb];
990 : }
991 :
992 1166769 : for ( sfb = 0; sfb <= hGrid->nTiles; sfb++ )
993 : {
994 1007217 : hGrid->sfbWrap[sfb] *= 2;
995 : }
996 :
997 159552 : return;
998 : }
999 :
1000 :
1001 : /*-------------------------------------------------------------------*
1002 : * IGFDecReadData()
1003 : *
1004 : * reads whitening information from the bitstream
1005 : *-------------------------------------------------------------------*/
1006 :
1007 1808514 : void IGFDecReadData(
1008 : const IGF_DEC_INSTANCE_HANDLE hIGFDec, /* i/o: instance handle of IGF Deccoder */
1009 : Decoder_State *st, /* i : decoder state */
1010 : const int16_t igfGridIdx, /* i : in case of CELP->TCX switching, use 1.25 framelength */
1011 : const int16_t isIndepFrame /* i : if 1: arith dec force reset, if 0: no reset */
1012 : )
1013 : {
1014 : IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData;
1015 : H_IGF_GRID hGrid;
1016 : int16_t p;
1017 : int16_t nT;
1018 : int16_t tmp;
1019 :
1020 1808514 : if ( hIGFDec != NULL )
1021 : {
1022 1808514 : hPrivateData = &hIGFDec->igfData;
1023 1808514 : hGrid = &hPrivateData->igfInfo.grid[igfGridIdx];
1024 1808514 : nT = hGrid->nTiles;
1025 1808514 : tmp = -1;
1026 :
1027 19893654 : for ( p = 0; p < IGF_MAX_TILES; p++ )
1028 : {
1029 18085140 : hPrivateData->currWhiteningLevel[p] = IGF_WHITENING_OFF;
1030 : }
1031 :
1032 1808514 : if ( isIndepFrame )
1033 : {
1034 1773666 : tmp = 0;
1035 : }
1036 : else
1037 : {
1038 34848 : tmp = get_next_indice( st, 1 );
1039 : }
1040 1808514 : if ( tmp == 1 )
1041 : {
1042 109770 : for ( p = 0; p < nT; p++ )
1043 : {
1044 76902 : hPrivateData->currWhiteningLevel[p] = hPrivateData->prevWhiteningLevel[p];
1045 : }
1046 : }
1047 : else
1048 : {
1049 1775646 : IGF_decode_whitening_level( st, hPrivateData, 0 );
1050 1775646 : if ( hPrivateData->igfInfo.bitRateIndex == IGF_BITRATE_SWB_48000_CPE || hPrivateData->igfInfo.bitRateIndex == IGF_BITRATE_FB_48000_CPE )
1051 : {
1052 222423 : tmp = 0;
1053 : }
1054 : else
1055 : {
1056 1553223 : tmp = get_next_indice( st, 1 );
1057 : }
1058 :
1059 1775646 : if ( tmp == 1 )
1060 : {
1061 3122193 : for ( p = 1; p < nT; p++ )
1062 : {
1063 1927221 : IGF_decode_whitening_level( st, hPrivateData, p );
1064 : }
1065 : }
1066 : else
1067 : {
1068 2811822 : for ( p = 1; p < nT; p++ )
1069 : {
1070 2231148 : hPrivateData->currWhiteningLevel[p] = hPrivateData->currWhiteningLevel[0];
1071 : }
1072 : }
1073 : }
1074 19893654 : for ( p = 0; p < IGF_MAX_TILES; p++ )
1075 : {
1076 18085140 : hPrivateData->prevWhiteningLevel[p] = hPrivateData->currWhiteningLevel[p];
1077 : }
1078 :
1079 : /* IGF_decode_temp_flattening_trigger()*/
1080 1808514 : hIGFDec->flatteningTrigger = get_next_indice( st, 1 );
1081 : }
1082 :
1083 1808514 : return;
1084 : }
1085 :
1086 :
1087 : /*-------------------------------------------------------------------*
1088 : * IGFDecReadLevel()
1089 : *
1090 : * read the IGF level information from the bitstream
1091 : *-------------------------------------------------------------------*/
1092 :
1093 : /*! r: return igfAllZero flag indicating if no envelope is transmitted */
1094 1808514 : int16_t IGFDecReadLevel(
1095 : const IGF_DEC_INSTANCE_HANDLE hIGFDec, /* i/o: instance handle of IGF Deccoder */
1096 : Decoder_State *st, /* i : decoder state */
1097 : const int16_t igfGridIdx, /* i : in case of CELP->TCX switching, use 1.25 framelength */
1098 : const int16_t isIndepFrame /* i : if 1: arith dec force reset, if 0: no reset */
1099 : )
1100 : {
1101 : IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData;
1102 : H_IGF_GRID hGrid;
1103 : int16_t m_igfSfbStart;
1104 : int16_t IGFAllZero;
1105 :
1106 1808514 : IGFAllZero = 1;
1107 :
1108 1808514 : if ( hIGFDec != NULL )
1109 : {
1110 1808514 : hPrivateData = &hIGFDec->igfData;
1111 1808514 : hGrid = &hPrivateData->igfInfo.grid[igfGridIdx];
1112 1808514 : m_igfSfbStart = hGrid->startSfb;
1113 1808514 : IGFAllZero = get_next_indice( st, 1 );
1114 :
1115 1808514 : if ( IGFAllZero == 0 )
1116 : {
1117 1807305 : mvs2s( hPrivateData->igf_curr, hPrivateData->igf_prev, hGrid->stopSfb );
1118 :
1119 1807305 : IGFSCFDecoderDecode( &hPrivateData->hArithSCFdec, st, &hPrivateData->igf_curr[m_igfSfbStart], igfGridIdx, isIndepFrame );
1120 : }
1121 : else
1122 : {
1123 1209 : IGFSCFDecoderReset( &hPrivateData->hArithSCFdec );
1124 :
1125 1209 : set_s( &hPrivateData->igf_curr[m_igfSfbStart], 0, hGrid->stopSfb - m_igfSfbStart );
1126 : }
1127 : }
1128 :
1129 1808514 : hIGFDec->infoIGFAllZero = IGFAllZero;
1130 :
1131 1808514 : return IGFAllZero;
1132 : }
1133 :
1134 :
1135 : /*-------------------------------------------------------------------*
1136 : * IGFDecApplyMono()
1137 : *
1138 : * apply the IGF decoder in mono
1139 : *-------------------------------------------------------------------*/
1140 :
1141 1285635 : void IGFDecApplyMono(
1142 : const IGF_DEC_INSTANCE_HANDLE hIGFDec, /* i/o: instance handle of IGF Decoder */
1143 : float *spectrum, /* i/o: MDCT spectrum */
1144 : const int16_t igfGridIdx, /* i : in case of CELP->TCX switching, use 1.25 framelength */
1145 : const int16_t bfi, /* i : frame loss == 1, frame good == 0 */
1146 : const int16_t element_mode /* i : IVAS element mode */
1147 : )
1148 : {
1149 : IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData;
1150 : H_IGF_GRID hGrid;
1151 : int16_t i, whiteningLevel, nLinesToReset;
1152 : float igf_spec[IGF_MAX_GRANULE_LEN];
1153 : int16_t nShift;
1154 :
1155 1285635 : set_zero( igf_spec, IGF_MAX_GRANULE_LEN );
1156 :
1157 : /* initialize variables */
1158 1285635 : if ( element_mode > EVS_MONO )
1159 : {
1160 1283697 : whiteningLevel = IGF_MID_WHITENING_LEVEL2;
1161 : }
1162 : else
1163 : {
1164 1938 : whiteningLevel = IGF_MID_WHITENING_LEVEL;
1165 : }
1166 :
1167 1285635 : nShift = igfGridIdx == IGF_GRID_LB_SHORT ? 2 : 1;
1168 1285635 : set_s( hIGFDec->flag_sparse, 0, ( N_MAX_TCX - IGF_START_MN ) / nShift );
1169 1285635 : set_f( hIGFDec->virtualSpec, 0.f, ( N_MAX_TCX - IGF_START_MN ) / nShift );
1170 :
1171 1285635 : hPrivateData = &hIGFDec->igfData;
1172 1285635 : hGrid = &hPrivateData->igfInfo.grid[igfGridIdx];
1173 1285635 : hPrivateData->totalNoiseNrg = 0.f;
1174 1285635 : hPrivateData->n_noise_bands = 0;
1175 1285635 : hPrivateData->totalNoiseNrg_off = 0.f;
1176 1285635 : hPrivateData->n_noise_bands_off = 0;
1177 1285635 : hPrivateData->restrict_hopsize = 0;
1178 :
1179 : /* concealment counter */
1180 1285635 : if ( bfi )
1181 : {
1182 13569 : hPrivateData->frameLossCounter++;
1183 : }
1184 : else
1185 : {
1186 1272066 : hPrivateData->frameLossCounter = 0;
1187 : }
1188 :
1189 : /* skip IGF processing if all IGF levels are zero */
1190 1285635 : if ( !hIGFDec->infoIGFAllZero )
1191 : {
1192 3587421 : for ( i = 0; i < hGrid->nTiles; i++ )
1193 : {
1194 2915130 : if ( hPrivateData->currWhiteningLevel[i] == IGF_WHITENING_MID )
1195 : {
1196 612342 : if ( element_mode == EVS_MONO || !bfi )
1197 : {
1198 607371 : IGF_getWhiteSpectralData( hPrivateData->pSpecFlat, igf_spec, hGrid->minSrcSubband, hGrid->startLine, whiteningLevel );
1199 : }
1200 : else
1201 : {
1202 4971 : mvr2r( hPrivateData->pSpecFlat, igf_spec, hGrid->startLine );
1203 : }
1204 :
1205 612342 : hPrivateData->n_noise_bands = IGF_replaceTCXNoise_1( igf_spec, hIGFDec->infoTCXNoise, hGrid->minSrcSubband, hGrid->startLine, &hPrivateData->totalNoiseNrg );
1206 612342 : break;
1207 : }
1208 : }
1209 :
1210 3359592 : for ( i = 0; i < hGrid->nTiles; i++ )
1211 : {
1212 2654769 : if ( hPrivateData->currWhiteningLevel[i] == IGF_WHITENING_OFF )
1213 : {
1214 579810 : hPrivateData->n_noise_bands_off = IGF_replaceTCXNoise_1( hPrivateData->pSpecFlat, hIGFDec->infoTCXNoise, hGrid->minSrcSubband, hGrid->startLine, &hPrivateData->totalNoiseNrg_off );
1215 579810 : break;
1216 : }
1217 : }
1218 :
1219 : /* apply IGF in three steps: */
1220 1284633 : IGF_prep( hPrivateData, igfGridIdx, hIGFDec->infoTCXNoise, igf_spec, hPrivateData->pSpecFlat, element_mode );
1221 1284633 : IGF_calc( hPrivateData, igfGridIdx, spectrum, igf_spec );
1222 1284633 : IGF_appl( hPrivateData, igfGridIdx, spectrum, igf_spec, hIGFDec->virtualSpec, hIGFDec->flag_sparse, 1 );
1223 : }
1224 :
1225 : /* reset TCX noise indicator vector */
1226 1285635 : nLinesToReset = igfGridIdx == IGF_GRID_LB_SHORT ? 2 : 1;
1227 1285635 : nLinesToReset = IGF_START_MX / nLinesToReset;
1228 1285635 : set_c( (int8_t *) ( hIGFDec->infoTCXNoise ), 0, nLinesToReset );
1229 :
1230 1285635 : return;
1231 : }
1232 :
1233 :
1234 : /*-------------------------------------------------------------------*
1235 : * IGFDecApplyStereo()
1236 : *
1237 : * apply the IGF decoder in stereo
1238 : *-------------------------------------------------------------------*/
1239 :
1240 269037 : void IGFDecApplyStereo(
1241 : const IGF_DEC_INSTANCE_HANDLE hIGFDecL, /* i : instance handle of IGF Decoder */
1242 : const IGF_DEC_INSTANCE_HANDLE hIGFDecR, /* i : instance handle of IGF Decoder */
1243 : float *spectrumL, /* i/o: L MDCT spectrum */
1244 : float *spectrumR, /* i/o: R MDCT spectrum */
1245 : const int16_t igfGridIdx, /* i : in case of CELP->TCX switching, use 1.25 framelength */
1246 : const int16_t *coreMsMask,
1247 : const int16_t restrict_hopsize,
1248 : const int16_t bfi, /* i : frame loss == 1, frame good == 0 */
1249 : const int16_t bfi_apply_damping )
1250 : {
1251 : IGF_DEC_PRIVATE_DATA_HANDLE hPrivateDataL, hPrivateDataR;
1252 : H_IGF_GRID hGrid;
1253 : int16_t i, whiteningLevel, nLinesToReset;
1254 : float igf_specL[IGF_MAX_GRANULE_LEN], igf_specR[IGF_MAX_GRANULE_LEN];
1255 : int16_t nShift;
1256 :
1257 269037 : set_f( igf_specL, 0.f, IGF_MAX_GRANULE_LEN );
1258 269037 : set_f( igf_specR, 0.f, IGF_MAX_GRANULE_LEN );
1259 :
1260 : /* initialize variables */
1261 269037 : whiteningLevel = IGF_MID_WHITENING_LEVEL2;
1262 :
1263 269037 : nShift = igfGridIdx == IGF_GRID_LB_SHORT ? 2 : 1;
1264 269037 : set_s( hIGFDecL->flag_sparse, 0, ( N_MAX_TCX - IGF_START_MN ) / nShift );
1265 269037 : set_s( hIGFDecR->flag_sparse, 0, ( N_MAX_TCX - IGF_START_MN ) / nShift );
1266 269037 : set_f( hIGFDecL->virtualSpec, 0.f, ( N_MAX_TCX - IGF_START_MN ) / nShift );
1267 269037 : set_f( hIGFDecR->virtualSpec, 0.f, ( N_MAX_TCX - IGF_START_MN ) / nShift );
1268 :
1269 269037 : hPrivateDataL = &hIGFDecL->igfData;
1270 269037 : hGrid = &hPrivateDataL->igfInfo.grid[igfGridIdx];
1271 269037 : hPrivateDataL->totalNoiseNrg = 0.f;
1272 269037 : hPrivateDataL->n_noise_bands = 0;
1273 269037 : hPrivateDataL->totalNoiseNrg_off = 0.f;
1274 269037 : hPrivateDataL->n_noise_bands_off = 0;
1275 269037 : hPrivateDataL->restrict_hopsize = restrict_hopsize;
1276 :
1277 269037 : hPrivateDataR = &hIGFDecR->igfData;
1278 269037 : hPrivateDataR->totalNoiseNrg = 0.f;
1279 269037 : hPrivateDataR->n_noise_bands = 0;
1280 269037 : hPrivateDataR->totalNoiseNrg_off = 0.f;
1281 269037 : hPrivateDataR->n_noise_bands_off = 0;
1282 269037 : hPrivateDataR->restrict_hopsize = restrict_hopsize;
1283 :
1284 : /* concealment counter */
1285 269037 : if ( bfi )
1286 : {
1287 813 : hPrivateDataL->frameLossCounter++;
1288 813 : hPrivateDataR->frameLossCounter++;
1289 : }
1290 : else
1291 : {
1292 268224 : hPrivateDataL->frameLossCounter = 0;
1293 268224 : hPrivateDataR->frameLossCounter = 0;
1294 : }
1295 :
1296 : /* skip IGF processing if all IGF levels are zero */
1297 269037 : if ( !hIGFDecL->infoIGFAllZero || !hIGFDecR->infoIGFAllZero )
1298 : {
1299 692430 : for ( i = 0; i < hGrid->nTiles; i++ )
1300 : {
1301 591090 : if ( hPrivateDataL->currWhiteningLevel[i] == IGF_WHITENING_MID || hPrivateDataR->currWhiteningLevel[i] == IGF_WHITENING_MID )
1302 : {
1303 167694 : if ( !bfi )
1304 : {
1305 167325 : IGF_getWhiteSpectralData( hPrivateDataL->pSpecFlat, igf_specL, hGrid->minSrcSubband, hGrid->startLine, whiteningLevel );
1306 : }
1307 : else
1308 : {
1309 369 : mvr2r( hPrivateDataL->pSpecFlat, igf_specL, hGrid->startLine );
1310 : }
1311 :
1312 167694 : hPrivateDataL->n_noise_bands = IGF_replaceTCXNoise_1( igf_specL, hIGFDecL->infoTCXNoise, hGrid->minSrcSubband, hGrid->startLine, &hPrivateDataL->totalNoiseNrg );
1313 :
1314 167694 : if ( !bfi )
1315 : {
1316 167325 : IGF_getWhiteSpectralData( hPrivateDataR->pSpecFlat, igf_specR, hGrid->minSrcSubband, hGrid->startLine, whiteningLevel );
1317 : }
1318 : else
1319 : {
1320 369 : mvr2r( hPrivateDataR->pSpecFlat, igf_specR, hGrid->startLine );
1321 : }
1322 :
1323 167694 : hPrivateDataR->n_noise_bands = IGF_replaceTCXNoise_1( igf_specR, hIGFDecR->infoTCXNoise, hGrid->minSrcSubband, hGrid->startLine, &hPrivateDataR->totalNoiseNrg );
1324 :
1325 167694 : break;
1326 : }
1327 : }
1328 :
1329 559950 : for ( i = 0; i < hGrid->nTiles; i++ )
1330 : {
1331 443934 : if ( hPrivateDataL->currWhiteningLevel[i] == IGF_WHITENING_OFF || hPrivateDataR->currWhiteningLevel[i] == IGF_WHITENING_OFF )
1332 : {
1333 153018 : hPrivateDataL->n_noise_bands_off = IGF_replaceTCXNoise_1( hPrivateDataL->pSpecFlat, hIGFDecL->infoTCXNoise, hGrid->minSrcSubband, hGrid->startLine, &hPrivateDataL->totalNoiseNrg_off );
1334 :
1335 153018 : hPrivateDataR->n_noise_bands_off = IGF_replaceTCXNoise_1( hPrivateDataR->pSpecFlat, hIGFDecR->infoTCXNoise, hGrid->minSrcSubband, hGrid->startLine, &hPrivateDataR->totalNoiseNrg_off );
1336 153018 : break;
1337 : }
1338 : }
1339 :
1340 : /* apply IGF in three steps: */
1341 269034 : IGF_prepStereo( hPrivateDataL, hPrivateDataR, igfGridIdx, hIGFDecL->infoTCXNoise, hIGFDecR->infoTCXNoise, igf_specL, igf_specR, hPrivateDataL->pSpecFlat, hPrivateDataR->pSpecFlat, coreMsMask );
1342 :
1343 269034 : IGF_calc( hPrivateDataL, igfGridIdx, spectrumL, igf_specL );
1344 269034 : IGF_calc( hPrivateDataR, igfGridIdx, spectrumR, igf_specR );
1345 269034 : IGF_appl( hPrivateDataL, igfGridIdx, spectrumL, igf_specL, hIGFDecL->virtualSpec, hIGFDecL->flag_sparse, bfi_apply_damping );
1346 269034 : IGF_appl( hPrivateDataR, igfGridIdx, spectrumR, igf_specR, hIGFDecR->virtualSpec, hIGFDecR->flag_sparse, bfi_apply_damping );
1347 : }
1348 :
1349 : /* reset TCX noise indicator vector */
1350 269037 : nLinesToReset = ( igfGridIdx == IGF_GRID_LB_SHORT ) ? 2 : 1;
1351 269037 : nLinesToReset = IGF_START_MX / nLinesToReset;
1352 269037 : set_c( (int8_t *) ( hIGFDecL->infoTCXNoise ), 0, nLinesToReset );
1353 269037 : set_c( (int8_t *) ( hIGFDecR->infoTCXNoise ), 0, nLinesToReset );
1354 :
1355 269037 : return;
1356 : }
1357 :
1358 :
1359 : /*-------------------------------------------------------------------*
1360 : * IGFDecSetMode()
1361 : *
1362 : * set mode is used to init the IGF dec with a new bitrate
1363 : *-------------------------------------------------------------------*/
1364 :
1365 63429 : void IGFDecSetMode(
1366 : const IGF_DEC_INSTANCE_HANDLE hIGFDec, /* i : instance handle of IGF Decoder */
1367 : const int32_t total_brate, /* i : bitrate */
1368 : const int16_t bwidth, /* i : audio bandwidth */
1369 : const int16_t element_mode, /* i : IVAS element mode */
1370 : const int16_t defaultStartLine, /* i : default start subband index */
1371 : const int16_t defaultStopLine, /* i : default stop subband index */
1372 : const int16_t rf_mode /* i : flag to signal the RF mode */
1373 : )
1374 : {
1375 : IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData;
1376 :
1377 63429 : hPrivateData = &hIGFDec->igfData;
1378 63429 : hIGFDec->isIGFActive = 0;
1379 :
1380 63429 : if ( IGFCommonFuncsIGFConfiguration( total_brate, bwidth, element_mode, &hPrivateData->igfInfo, rf_mode ) )
1381 : {
1382 63429 : IGFSCFDecoderOpen( &hPrivateData->hArithSCFdec, &hPrivateData->igfInfo, total_brate, bwidth, element_mode, rf_mode );
1383 :
1384 63429 : hIGFDec->infoIGFAllZero = 0;
1385 63429 : hIGFDec->isIGFActive = 1;
1386 63429 : hIGFDec->infoIGFStopLine = hPrivateData->igfInfo.grid[0].stopLine;
1387 63429 : hIGFDec->infoIGFStartLine = hPrivateData->igfInfo.grid[0].startLine;
1388 63429 : hIGFDec->infoIGFStopFreq = hPrivateData->igfInfo.grid[0].stopFrequency;
1389 63429 : hIGFDec->infoIGFStartFreq = hPrivateData->igfInfo.grid[0].startFrequency;
1390 :
1391 : /* no refinement if maxHopsize is 1 */
1392 63429 : if ( hPrivateData->igfInfo.bitRateIndex != IGF_BITRATE_FB_96000 && hPrivateData->igfInfo.bitRateIndex != IGF_BITRATE_FB_96000_CPE &&
1393 60156 : hPrivateData->igfInfo.bitRateIndex != IGF_BITRATE_FB_128000 && hPrivateData->igfInfo.bitRateIndex != IGF_BITRATE_FB_128000_CPE )
1394 : {
1395 53184 : IGF_RefineGrid( &hPrivateData->igfInfo.grid[IGF_GRID_LB_NORM] );
1396 53184 : IGF_RefineGrid( &hPrivateData->igfInfo.grid[IGF_GRID_LB_TRAN] );
1397 53184 : IGF_RefineGrid( &hPrivateData->igfInfo.grid[IGF_GRID_LB_SHORT] );
1398 : }
1399 : /* IGFDecOutInformation(hIGFDec); */
1400 : }
1401 : else
1402 : {
1403 0 : hIGFDec->infoIGFStopLine = defaultStopLine;
1404 0 : hIGFDec->infoIGFStartLine = defaultStartLine;
1405 0 : hIGFDec->infoIGFStopFreq = -1;
1406 0 : hIGFDec->infoIGFStartFreq = -1;
1407 0 : IVAS_ERROR( IVAS_ERR_INTERNAL, "IGFDecSetMode: initialization error!" );
1408 : }
1409 :
1410 63429 : hIGFDec->flag_sparse = &hIGFDec->flag_sparseBuf[0];
1411 63429 : hIGFDec->infoTCXNoise = &hIGFDec->infoTCXNoiseBuf[0];
1412 63429 : hIGFDec->virtualSpec = &hIGFDec->virtualSpecBuf[0];
1413 63429 : hIGFDec->igfData.pSpecFlat = &hIGFDec->igfData.pSpecFlatBuf[0];
1414 63429 : hIGFDec->igfData.igfInfo.nfSeed = &hIGFDec->igfData.igfInfo.nfSeedBuf[0];
1415 :
1416 63429 : return;
1417 : }
1418 :
1419 :
1420 : /*-------------------------------------------------------------------*
1421 : * IGFDecUpdateInfo()
1422 : *
1423 : * updates the start/stop frequency of IGF according to igfGridIdx
1424 : *-------------------------------------------------------------------*/
1425 :
1426 6362604 : void IGFDecUpdateInfo(
1427 : const IGF_DEC_INSTANCE_HANDLE hIGFDec, /* i/o: instance handle of IGF Decoder */
1428 : const int16_t subFrameIdx, /* i : index of subframe */
1429 : const int16_t igfGridIdx /* i : IGF grid index */
1430 : )
1431 : {
1432 : IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData;
1433 : H_IGF_GRID hGrid;
1434 :
1435 6362604 : hIGFDec->flag_sparse = &hIGFDec->flag_sparseBuf[0];
1436 6362604 : hIGFDec->infoTCXNoise = &hIGFDec->infoTCXNoiseBuf[0];
1437 6362604 : hIGFDec->virtualSpec = &hIGFDec->virtualSpecBuf[0];
1438 6362604 : hIGFDec->igfData.pSpecFlat = &hIGFDec->igfData.pSpecFlatBuf[0];
1439 6362604 : hIGFDec->igfData.igfInfo.nfSeed = &hIGFDec->igfData.igfInfo.nfSeedBuf[0];
1440 :
1441 6362604 : if ( igfGridIdx == IGF_GRID_LB_SHORT )
1442 : {
1443 292890 : IGFDecRestoreTCX10SubFrameData( hIGFDec, subFrameIdx );
1444 : }
1445 :
1446 6362604 : hPrivateData = &hIGFDec->igfData;
1447 6362604 : if ( hIGFDec->isIGFActive )
1448 : {
1449 6362604 : hGrid = &hPrivateData->igfInfo.grid[igfGridIdx];
1450 6362604 : hIGFDec->infoIGFStartFreq = hGrid->startFrequency;
1451 6362604 : hIGFDec->infoIGFStopFreq = hGrid->stopFrequency;
1452 6362604 : hIGFDec->infoIGFStartLine = hGrid->startLine;
1453 6362604 : hIGFDec->infoIGFStopLine = hGrid->stopLine;
1454 : }
1455 :
1456 6362604 : return;
1457 : }
1458 :
1459 :
1460 : /*-------------------------------------------------------------------*
1461 : * IGFDecReplicateTCX10State()
1462 : *
1463 : *
1464 : *-------------------------------------------------------------------*/
1465 :
1466 75 : void IGFDecReplicateTCX10State(
1467 : IGF_DEC_INSTANCE_HANDLE hIGFDec /* i/o: instance handle of IGF Decoder */
1468 : )
1469 : {
1470 75 : mvs2s( &hIGFDec->flag_sparseBuf[( N_MAX_TCX - IGF_START_MN ) / 2], &hIGFDec->flag_sparseBuf[0], ( N_MAX_TCX - IGF_START_MN ) / 2 );
1471 75 : mvc2c( &hIGFDec->infoTCXNoiseBuf[( IGF_START_MX ) / 2], &hIGFDec->infoTCXNoiseBuf[0], ( IGF_START_MX ) / 2 );
1472 75 : mvr2r( &hIGFDec->virtualSpecBuf[( N_MAX_TCX - IGF_START_MN ) / 2], &hIGFDec->virtualSpecBuf[0], ( N_MAX_TCX - IGF_START_MN ) / 2 );
1473 75 : mvr2r( &hIGFDec->igfData.pSpecFlatBuf[IGF_START_MX / 2], &hIGFDec->igfData.pSpecFlatBuf[0], IGF_START_MX / 2 );
1474 :
1475 75 : hIGFDec->igfData.igfInfo.nfSeedBuf[0] = hIGFDec->igfData.igfInfo.nfSeedBuf[1];
1476 :
1477 75 : return;
1478 : }
1479 :
1480 :
1481 : /*-------------------------------------------------------------------*
1482 : * IGFDecCopyLPCFlatSpectrum()
1483 : *
1484 : * copy the LPC flat spectrum to IGF buffer
1485 : *-------------------------------------------------------------------*/
1486 :
1487 1811901 : void IGFDecCopyLPCFlatSpectrum(
1488 : const IGF_DEC_INSTANCE_HANDLE hIGFDec, /* i/o: instance handle of IGF Decoder */
1489 : const float *pSpectrumFlat, /* i : LPC flattend spectrum from TCX dec */
1490 : const int16_t igfGridIdx /* i : IGF grid index */
1491 : )
1492 : {
1493 : IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData;
1494 : H_IGF_GRID hGrid;
1495 : int16_t i;
1496 :
1497 1811901 : if ( hIGFDec )
1498 : {
1499 1811901 : hPrivateData = &hIGFDec->igfData;
1500 1811901 : hGrid = &hPrivateData->igfInfo.grid[igfGridIdx];
1501 :
1502 734137428 : for ( i = hGrid->minSrcSubband - IGF_MID_WHITENING_LEVEL2; i < hGrid->startLine; i++ )
1503 : {
1504 732325527 : hPrivateData->pSpecFlat[i] = pSpectrumFlat[i] * 1024.f;
1505 : }
1506 : }
1507 :
1508 1811901 : return;
1509 : }
1510 :
1511 :
1512 : /*-------------------------------------------------------------------*
1513 : * IGFDecStoreTCX10SubFrameData()
1514 : *
1515 : * store the IGF bitstream information for TCX10 subframes
1516 : *-------------------------------------------------------------------*/
1517 :
1518 69696 : void IGFDecStoreTCX10SubFrameData(
1519 : const IGF_DEC_INSTANCE_HANDLE hIGFDec, /* i/o: instance handle of IGF Decoder */
1520 : const int16_t subFrameIdx /* i : index of subframe */
1521 : )
1522 : {
1523 : IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData;
1524 :
1525 69696 : hPrivateData = &hIGFDec->igfData;
1526 :
1527 : /* store igf energies for subframe*/
1528 69696 : mvs2s( hPrivateData->igf_curr, hPrivateData->igf_curr_subframe[subFrameIdx][0], IGF_MAX_SFB );
1529 69696 : mvs2s( hPrivateData->igf_prev, hPrivateData->igf_prev_subframe[subFrameIdx], IGF_MAX_SFB );
1530 :
1531 : /* store spectral whitening information for current subframe */
1532 69696 : mvs2s( hPrivateData->currWhiteningLevel, hPrivateData->currWhiteningLevel_subframe[subFrameIdx], IGF_MAX_TILES );
1533 69696 : mvs2s( hPrivateData->prevWhiteningLevel, hPrivateData->prevWhiteningLevel_subframe[subFrameIdx], IGF_MAX_TILES );
1534 :
1535 : /* store flattening trigger for current subframe */
1536 69696 : hPrivateData->igf_flatteningTrigger_subframe[subFrameIdx] = hIGFDec->flatteningTrigger;
1537 :
1538 69696 : return;
1539 : }
1540 :
1541 :
1542 : /*-------------------------------------------------------------------*
1543 : * IGFDecRestoreTCX10SubFrameData()
1544 : *
1545 : * restore the IGF bitstream information for TCX10 subframes
1546 : *-------------------------------------------------------------------*/
1547 :
1548 305298 : void IGFDecRestoreTCX10SubFrameData(
1549 : const IGF_DEC_INSTANCE_HANDLE hIGFDec, /* i/o: instance handle of IGF Decoder */
1550 : const int16_t subFrameIdx /* i : index of subframe */
1551 : )
1552 : {
1553 : IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData;
1554 :
1555 305298 : hPrivateData = &hIGFDec->igfData;
1556 :
1557 : /* store igf energies for subframe*/
1558 305298 : mvs2s( hPrivateData->igf_curr_subframe[subFrameIdx][0], hPrivateData->igf_curr, IGF_MAX_SFB );
1559 305298 : mvs2s( hPrivateData->igf_prev_subframe[subFrameIdx], hPrivateData->igf_prev, IGF_MAX_SFB );
1560 :
1561 : /* store spectral whitening information for current subframe */
1562 305298 : mvs2s( hPrivateData->currWhiteningLevel_subframe[subFrameIdx], hPrivateData->currWhiteningLevel, IGF_MAX_TILES );
1563 305298 : mvs2s( hPrivateData->prevWhiteningLevel_subframe[subFrameIdx], hPrivateData->prevWhiteningLevel, IGF_MAX_TILES );
1564 :
1565 : /* restore flattening trigger for current subframe */
1566 305298 : hIGFDec->flatteningTrigger = hPrivateData->igf_flatteningTrigger_subframe[subFrameIdx];
1567 305298 : hIGFDec->flag_sparse = &hIGFDec->flag_sparseBuf[subFrameIdx * ( N_MAX_TCX - IGF_START_MN ) / 2];
1568 305298 : hIGFDec->infoTCXNoise = &hIGFDec->infoTCXNoiseBuf[subFrameIdx * ( IGF_START_MX ) / 2];
1569 305298 : hIGFDec->virtualSpec = &hIGFDec->virtualSpecBuf[subFrameIdx * ( N_MAX_TCX - IGF_START_MN ) / 2];
1570 305298 : hIGFDec->igfData.pSpecFlat = &hIGFDec->igfData.pSpecFlatBuf[subFrameIdx * IGF_START_MX / 2];
1571 305298 : hIGFDec->igfData.igfInfo.nfSeed = &hIGFDec->igfData.igfInfo.nfSeedBuf[subFrameIdx];
1572 :
1573 305298 : return;
1574 : }
1575 :
1576 : /*-----------------------------------------------------------------------*
1577 : * init_igf_dec()
1578 : *
1579 : * Initialize IGF decoder parameters
1580 : *-----------------------------------------------------------------------*/
1581 :
1582 28434 : void init_igf_dec(
1583 : IGF_DEC_INSTANCE_HANDLE hIGFDec /* i/o: IGF decoder handle */
1584 : )
1585 : {
1586 28434 : set_c( (int8_t *) ( hIGFDec->infoTCXNoiseBuf ), 0, IGF_START_MX );
1587 28434 : set_f( hIGFDec->igfData.pSpecFlatBuf, 0, IGF_START_MX );
1588 28434 : hIGFDec->igfData.igfInfo.nfSeedBuf[0] = 9733;
1589 28434 : hIGFDec->igfData.igfInfo.nfSeedBuf[1] = 9733;
1590 28434 : hIGFDec->igfData.igfInfo.nfSeed = &hIGFDec->igfData.igfInfo.nfSeedBuf[0];
1591 28434 : hIGFDec->igfData.pSpecFlat = &hIGFDec->igfData.pSpecFlatBuf[0];
1592 28434 : hIGFDec->flag_sparse = &hIGFDec->flag_sparseBuf[0];
1593 28434 : hIGFDec->infoTCXNoise = &hIGFDec->infoTCXNoiseBuf[0];
1594 28434 : hIGFDec->virtualSpec = &hIGFDec->virtualSpecBuf[0];
1595 :
1596 28434 : return;
1597 : }
1598 :
1599 :
1600 : /*-----------------------------------------------------------------------*
1601 : * get_igf_startline()
1602 : *
1603 : *
1604 : *-----------------------------------------------------------------------*/
1605 :
1606 : /*! r: IGF start line */
1607 4538256 : int16_t get_igf_startline(
1608 : Decoder_State *st, /* i : decoder state */
1609 : const int16_t L_frame, /* i : length of the frame */
1610 : const int16_t L_frameTCX /* i : full band frame length */
1611 : )
1612 : {
1613 : int16_t igf_startline;
1614 :
1615 4538256 : if ( st->igf == 0 )
1616 : {
1617 1607853 : if ( st->narrowBand == 0 )
1618 : {
1619 : /* minimum needed for output with sampling rates lower then the
1620 : nominal sampling rate */
1621 1607853 : igf_startline = min( L_frameTCX, L_frame );
1622 : }
1623 : else
1624 : {
1625 0 : igf_startline = L_frameTCX;
1626 : }
1627 : }
1628 : else
1629 : {
1630 2930403 : igf_startline = min( st->hIGFDec->infoIGFStartLine, L_frameTCX );
1631 : }
1632 :
1633 4538256 : return igf_startline;
1634 : }
|