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 1240550 : 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 1240550 : noise = 0;
72 1240550 : nE = FLT_MIN;
73 :
74 508174326 : for ( sb = start; sb < stop; sb++ )
75 : {
76 506933776 : val = in[sb] * TCXNoise[sb];
77 506933776 : nE += val * val;
78 506933776 : noise += TCXNoise[sb];
79 : }
80 :
81 1240550 : *totalNoiseNrg = nE;
82 :
83 1240550 : return noise;
84 : }
85 :
86 :
87 : /*-------------------------------------------------------------------*
88 : * IGF_replaceTCXNoise_2()
89 : *
90 : * replaces TCX noise
91 : *-------------------------------------------------------------------*/
92 :
93 1807 : 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 1807 : rE = FLT_MIN;
108 415031 : for ( sb = start; sb < stop; sb++ )
109 : {
110 413224 : if ( TCXNoise[sb] )
111 : {
112 332711 : val = (float) own_random( nfSeed );
113 332711 : in[sb] = val;
114 332711 : rE += val * val;
115 : }
116 : }
117 :
118 1807 : g = (float) sqrt( totalNoiseNrg / rE );
119 :
120 415031 : for ( sb = start; sb < stop; sb++ )
121 : {
122 413224 : if ( TCXNoise[sb] )
123 : {
124 332711 : in[sb] *= g;
125 : }
126 : }
127 :
128 1807 : return;
129 : }
130 :
131 :
132 : /*-------------------------------------------------------------------*
133 : * IGF_replaceTCXNoise_2_new()
134 : *
135 : *
136 : *-------------------------------------------------------------------*/
137 :
138 2789018 : 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 2789018 : rE = FLT_MIN;
156 2789018 : n_noise_bands_tile = 0;
157 242439108 : for ( sb = start; sb < stop; sb++ )
158 : {
159 239650090 : if ( TCXNoise[sb] )
160 : {
161 209498704 : val = (float) own_random( nfSeed );
162 209498704 : in[sb] = val;
163 209498704 : rE += val * val;
164 209498704 : n_noise_bands_tile++;
165 : }
166 : }
167 :
168 2789018 : rE = max( rE, 1.f );
169 :
170 2789018 : if ( n_noise_bands_tile )
171 : {
172 2788868 : noise_band_ratio = (float) n_noise_bands_tile / n_noise_bands;
173 2788868 : g = (float) sqrt( totalNoiseNrg * noise_band_ratio / rE );
174 :
175 242434738 : for ( sb = start; sb < stop; sb++ )
176 : {
177 239645870 : if ( TCXNoise[sb] )
178 : {
179 209498704 : in[sb] *= g;
180 : }
181 : }
182 : }
183 :
184 2789018 : return;
185 : }
186 :
187 :
188 : /*-------------------------------------------------------------------*
189 : * IGF_decode_whitening_level()
190 : *
191 : * reads whitening levels
192 : *-------------------------------------------------------------------*/
193 :
194 2325932 : 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 2325932 : tmp = get_next_indice( st, 1 );
203 :
204 2325932 : if ( tmp == 1 )
205 : {
206 1374943 : tmp = get_next_indice( st, 1 );
207 1374943 : if ( tmp == 1 )
208 : {
209 759473 : hPrivateData->currWhiteningLevel[p] = IGF_WHITENING_STRONG;
210 : }
211 : else
212 : {
213 615470 : hPrivateData->currWhiteningLevel[p] = IGF_WHITENING_OFF;
214 : }
215 : }
216 : else
217 : {
218 950989 : hPrivateData->currWhiteningLevel[p] = IGF_WHITENING_MID;
219 : }
220 :
221 2325932 : return;
222 : }
223 :
224 :
225 : /*-------------------------------------------------------------------*
226 : * IGF_getMDCTSquare()
227 : *
228 : * square the MDCT spectrum
229 : *-------------------------------------------------------------------*/
230 :
231 2330850 : 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 666994970 : for ( i = startLine; i < stopLine; i++ )
241 : {
242 664664120 : pSpecDataSqaure[i] = pSpectralData[i] * pSpectralData[i];
243 : }
244 :
245 2330850 : return;
246 : }
247 :
248 :
249 : /*-------------------------------------------------------------------*
250 : * IGF_calcSfbEnergy()
251 : *
252 : * calculate energy per SFB
253 : *-------------------------------------------------------------------*/
254 :
255 2330850 : 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 24184168 : for ( sfb = startSfb; sfb < stopSfb; sfb++ )
267 : {
268 21853318 : sfbEnergy[sfb] = 0.f;
269 :
270 686517438 : for ( line = swb_offset[sfb]; line < swb_offset[sfb + 1]; line++ )
271 : {
272 664664120 : sfbEnergy[sfb] += pPowerSpectrum[line];
273 : }
274 : }
275 :
276 2330850 : return;
277 : }
278 :
279 :
280 : /*-------------------------------------------------------------------*
281 : * IGF_setLinesToZero()
282 : *
283 : * set power spectrum values to zero, needed for energy calculation
284 : *-------------------------------------------------------------------*/
285 :
286 1165425 : 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 333497485 : for ( i = startLine; i < stopLine; i++ )
296 : {
297 332332060 : if ( pSpectralData[i] != 0.f )
298 : {
299 48607 : squareSpecIGF[i] = 0.f;
300 : }
301 : }
302 :
303 1165425 : return;
304 : }
305 :
306 :
307 : /*-------------------------------------------------------------------*
308 : * IGF_prep()
309 : *
310 : * prepare IGF spectrum
311 : *-------------------------------------------------------------------*/
312 :
313 702531 : 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 702531 : hInfo = &hPrivateData->igfInfo;
329 702531 : hGrid = &hPrivateData->igfInfo.grid[igfGridIdx];
330 702531 : swb_offset = hGrid->swb_offset;
331 :
332 2754881 : for ( tile_idx = 0; tile_idx < hGrid->nTiles; tile_idx++ )
333 : {
334 : int16_t tile_width, stop;
335 :
336 2052350 : strt_cpy = hGrid->sbWrap[tile_idx];
337 :
338 2052350 : if ( element_mode > EVS_MONO )
339 : {
340 2048958 : tile_width = swb_offset[hGrid->sfbWrap[tile_idx + 1]] - swb_offset[hGrid->sfbWrap[tile_idx]];
341 2048958 : stop = strt_cpy + tile_width;
342 : }
343 : else
344 : {
345 3392 : stop = hGrid->startLine;
346 : }
347 :
348 2052350 : if ( IGF_WHITENING_STRONG == hPrivateData->currWhiteningLevel[tile_idx] )
349 : {
350 : float abs_sum;
351 596519 : abs_sum = 0.f;
352 :
353 68253653 : for ( i = strt_cpy; i < stop; i++ )
354 : {
355 67657134 : abs_sum += (float) fabs( src_spec[i] );
356 : }
357 :
358 596519 : tb = swb_offset[hGrid->sfbWrap[tile_idx]];
359 :
360 596519 : if ( abs_sum > 0.f )
361 : {
362 68178853 : for ( i = strt_cpy; i < stop; i++ )
363 : {
364 67583272 : igf_spec[tb++] = own_random( hInfo->nfSeed );
365 : }
366 : }
367 : else
368 : {
369 74800 : for ( i = strt_cpy; i < stop; i++ )
370 : {
371 73862 : igf_spec[tb++] = 0.f;
372 : }
373 : }
374 : }
375 : else
376 : {
377 1455831 : if ( IGF_WHITENING_MID == hPrivateData->currWhiteningLevel[tile_idx] )
378 : {
379 726086 : if ( element_mode > EVS_MONO )
380 : {
381 724926 : if ( hPrivateData->n_noise_bands )
382 : {
383 692113 : IGF_replaceTCXNoise_2_new( igf_spec, TCXNoise, strt_cpy, stop, hPrivateData->totalNoiseNrg, hPrivateData->n_noise_bands, hInfo->nfSeed );
384 : }
385 : }
386 : else
387 : {
388 1160 : if ( hPrivateData->n_noise_bands )
389 : {
390 1157 : IGF_replaceTCXNoise_2( igf_spec, TCXNoise, hGrid->minSrcSubband, hGrid->startLine, hPrivateData->totalNoiseNrg, hInfo->nfSeed );
391 : }
392 : }
393 :
394 726086 : sel_spec = igf_spec;
395 : }
396 : else
397 : {
398 729745 : if ( element_mode > EVS_MONO )
399 : {
400 729092 : if ( hPrivateData->n_noise_bands_off )
401 : {
402 714185 : 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 653 : if ( hPrivateData->n_noise_bands_off )
408 : {
409 650 : IGF_replaceTCXNoise_2( src_spec, TCXNoise, hGrid->minSrcSubband, hGrid->startLine, hPrivateData->totalNoiseNrg_off, hInfo->nfSeed );
410 : }
411 : }
412 :
413 729745 : sel_spec = src_spec;
414 : }
415 5439435 : for ( sfb = hGrid->sfbWrap[tile_idx]; sfb < hGrid->sfbWrap[tile_idx + 1]; sfb++ )
416 : {
417 133630086 : for ( tb = swb_offset[sfb]; tb < swb_offset[sfb + 1]; tb++ )
418 : {
419 129646482 : igf_spec[tb] = sel_spec[strt_cpy];
420 129646482 : strt_cpy++;
421 : }
422 : }
423 : }
424 : }
425 :
426 702531 : return;
427 : }
428 :
429 :
430 : /*-------------------------------------------------------------------*
431 : * IGF_prepStereo()
432 : *
433 : *
434 : *-------------------------------------------------------------------*/
435 :
436 231447 : 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 231447 : float *sel_specL = NULL;
454 231447 : float *sel_specR = NULL;
455 231447 : const float c = SQRT2_OVER_2; /* M/S scaling factor */
456 :
457 231447 : hInfoL = &hPrivateDataL->igfInfo;
458 231447 : hInfoR = &hPrivateDataR->igfInfo;
459 231447 : hGrid = &hPrivateDataL->igfInfo.grid[igfGridIdx];
460 231447 : swb_offset = hGrid->swb_offset;
461 :
462 1002539 : for ( tile_idx = 0; tile_idx < hGrid->nTiles; tile_idx++ )
463 : {
464 : int16_t tile_width, stop;
465 771092 : strt_cpy = hGrid->sbWrap[tile_idx];
466 :
467 771092 : tile_width = swb_offset[hGrid->sfbWrap[tile_idx + 1]] - swb_offset[hGrid->sfbWrap[tile_idx]];
468 771092 : stop = strt_cpy + tile_width;
469 :
470 771092 : if ( IGF_WHITENING_STRONG == hPrivateDataL->currWhiteningLevel[tile_idx] )
471 : {
472 214473 : tb = swb_offset[hGrid->sfbWrap[tile_idx]];
473 :
474 19931085 : for ( tb = swb_offset[hGrid->sfbWrap[tile_idx]]; tb < swb_offset[hGrid->sfbWrap[tile_idx + 1]]; tb++ )
475 : {
476 19716612 : igf_specL[tb] = own_random( hInfoL->nfSeed );
477 : }
478 : }
479 : else
480 : {
481 556619 : if ( IGF_WHITENING_MID == hPrivateDataL->currWhiteningLevel[tile_idx] )
482 : {
483 215931 : if ( hPrivateDataL->n_noise_bands )
484 : {
485 215394 : IGF_replaceTCXNoise_2_new( igf_specL, TCXNoiseL, strt_cpy, stop, hPrivateDataL->totalNoiseNrg, hPrivateDataL->n_noise_bands, hInfoL->nfSeed );
486 : }
487 215931 : sel_specL = igf_specL;
488 : }
489 : else
490 : {
491 340688 : if ( hPrivateDataL->n_noise_bands_off )
492 : {
493 335828 : IGF_replaceTCXNoise_2_new( src_specL, TCXNoiseL, strt_cpy, stop, hPrivateDataL->totalNoiseNrg_off, hPrivateDataL->n_noise_bands_off, hInfoL->nfSeed );
494 : }
495 340688 : sel_specL = src_specL;
496 : }
497 :
498 556619 : if ( IGF_WHITENING_MID == hPrivateDataL->currWhiteningLevel[tile_idx] )
499 : {
500 215931 : if ( hPrivateDataR->n_noise_bands )
501 : {
502 211089 : IGF_replaceTCXNoise_2_new( igf_specR, TCXNoiseR, strt_cpy, stop, hPrivateDataR->totalNoiseNrg, hPrivateDataR->n_noise_bands, hInfoR->nfSeed );
503 : }
504 215931 : sel_specR = igf_specR;
505 : }
506 : else
507 : {
508 340688 : if ( hPrivateDataR->n_noise_bands_off )
509 : {
510 322697 : IGF_replaceTCXNoise_2_new( src_specR, TCXNoiseR, strt_cpy, stop, hPrivateDataR->totalNoiseNrg_off, hPrivateDataR->n_noise_bands_off, hInfoR->nfSeed );
511 : }
512 340688 : sel_specR = src_specR;
513 : }
514 :
515 2164605 : for ( sfb = hGrid->sfbWrap[tile_idx]; sfb < hGrid->sfbWrap[tile_idx + 1]; sfb++ )
516 : {
517 49453016 : 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 47845030 : if ( coreMsMask[tb] == 0 )
524 : {
525 15044360 : if ( coreMsMask[strt_cpy] == 0 ) /* LR->LR */
526 : {
527 4759538 : igf_specL[tb] = sel_specL[strt_cpy];
528 : }
529 : else /* MS/DR -> LR */
530 : {
531 10284822 : igf_specL[tb] = ( sel_specL[strt_cpy] + sel_specR[strt_cpy] ) * c;
532 : }
533 : }
534 : else
535 : {
536 32800670 : if ( coreMsMask[strt_cpy] == 0 ) /* LR->MS/DR */
537 : {
538 825326 : igf_specL[tb] = ( sel_specL[strt_cpy] + sel_specR[strt_cpy] ) * c;
539 : }
540 : else /* MS/DR -> MS/DR */
541 : {
542 31975344 : igf_specL[tb] = sel_specL[strt_cpy];
543 : }
544 : }
545 47845030 : strt_cpy++;
546 : }
547 : }
548 : }
549 :
550 771092 : strt_cpy = hGrid->sbWrap[tile_idx];
551 :
552 771092 : if ( IGF_WHITENING_STRONG == hPrivateDataR->currWhiteningLevel[tile_idx] )
553 : {
554 212638 : tb = swb_offset[hGrid->sfbWrap[tile_idx]];
555 :
556 20598526 : for ( tb = swb_offset[hGrid->sfbWrap[tile_idx]]; tb < swb_offset[hGrid->sfbWrap[tile_idx + 1]]; tb++ )
557 : {
558 20385888 : igf_specR[tb] = own_random( hInfoR->nfSeed );
559 : }
560 : }
561 : else
562 : {
563 558454 : if ( hPrivateDataR->currWhiteningLevel[tile_idx] != hPrivateDataL->currWhiteningLevel[tile_idx] )
564 : {
565 149804 : if ( IGF_WHITENING_MID == hPrivateDataR->currWhiteningLevel[tile_idx] )
566 : {
567 87793 : if ( hPrivateDataL->n_noise_bands )
568 : {
569 87523 : IGF_replaceTCXNoise_2_new( igf_specL, TCXNoiseL, strt_cpy, stop, hPrivateDataL->totalNoiseNrg, hPrivateDataL->n_noise_bands, hInfoL->nfSeed );
570 : }
571 87793 : sel_specL = igf_specL;
572 : }
573 : else
574 : {
575 62011 : if ( hPrivateDataL->n_noise_bands_off )
576 : {
577 61796 : IGF_replaceTCXNoise_2_new( src_specL, TCXNoiseL, strt_cpy, stop, hPrivateDataL->totalNoiseNrg_off, hPrivateDataL->n_noise_bands_off, hInfoL->nfSeed );
578 : }
579 62011 : sel_specL = src_specL;
580 : }
581 :
582 149804 : if ( IGF_WHITENING_MID == hPrivateDataR->currWhiteningLevel[tile_idx] )
583 : {
584 87793 : if ( hPrivateDataR->n_noise_bands )
585 : {
586 87233 : IGF_replaceTCXNoise_2_new( igf_specR, TCXNoiseR, strt_cpy, stop, hPrivateDataR->totalNoiseNrg, hPrivateDataR->n_noise_bands, hInfoR->nfSeed );
587 : }
588 87793 : sel_specR = igf_specR;
589 : }
590 : else
591 : {
592 62011 : if ( hPrivateDataR->n_noise_bands_off )
593 : {
594 61160 : IGF_replaceTCXNoise_2_new( src_specR, TCXNoiseR, strt_cpy, stop, hPrivateDataR->totalNoiseNrg_off, hPrivateDataR->n_noise_bands_off, hInfoR->nfSeed );
595 : }
596 62011 : sel_specR = src_specR;
597 : }
598 : }
599 :
600 2185684 : for ( sfb = hGrid->sfbWrap[tile_idx]; sfb < hGrid->sfbWrap[tile_idx + 1]; sfb++ )
601 : {
602 48802984 : 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 47175754 : if ( coreMsMask[tb] == 0 )
609 : {
610 14963112 : if ( coreMsMask[strt_cpy] == 0 ) /* LR->LR */
611 : {
612 4764774 : igf_specR[tb] = sel_specR[strt_cpy];
613 : }
614 : else /* MS/DR -> LR */
615 : {
616 10198338 : igf_specR[tb] = ( sel_specL[strt_cpy] - sel_specR[strt_cpy] ) * c;
617 : }
618 : }
619 : else
620 : {
621 32212642 : if ( coreMsMask[strt_cpy] == 0 ) /* LR->MS/DR */
622 : {
623 815542 : igf_specR[tb] = ( sel_specL[strt_cpy] - sel_specR[strt_cpy] ) * c;
624 : }
625 : else /* MS/DR -> MS/DR */
626 : {
627 31397100 : igf_specR[tb] = sel_specR[strt_cpy];
628 : }
629 : }
630 47175754 : strt_cpy++;
631 : }
632 : }
633 : }
634 : }
635 :
636 231447 : return;
637 : }
638 :
639 :
640 : /*-------------------------------------------------------------------*
641 : * IGF_calc()
642 : *
643 : * calculates IGF energies
644 : *-------------------------------------------------------------------*/
645 :
646 1165425 : 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 1165425 : set_zero( tmp, N_MAX_TCX );
659 :
660 1165425 : hGrid = &hPrivateData->igfInfo.grid[igfGridIdx];
661 1165425 : igf_pN = hPrivateData->igf_pN;
662 1165425 : igf_sN = hPrivateData->igf_sN;
663 :
664 1165425 : IGF_getMDCTSquare( hGrid->startLine, hGrid->stopLine, spectrum, tmp );
665 1165425 : IGF_calcSfbEnergy( hGrid->startSfb, hGrid->stopSfb, hGrid->swb_offset, tmp, igf_sN );
666 1165425 : IGF_getMDCTSquare( hGrid->startLine, hGrid->stopLine, igf_spec, tmp );
667 1165425 : IGF_setLinesToZero( hGrid->startLine, hGrid->stopLine, spectrum, tmp );
668 1165425 : IGF_calcSfbEnergy( hGrid->startSfb, hGrid->stopSfb, hGrid->swb_offset, tmp, igf_pN );
669 :
670 1165425 : return;
671 : }
672 :
673 :
674 : /*-------------------------------------------------------------------*
675 : * IGF_appl()
676 : *
677 : * apply IGF
678 : *-------------------------------------------------------------------*/
679 :
680 1165425 : 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 1165425 : w0 = 0.201f;
711 1165425 : w1 = 0.389f;
712 1165425 : w2 = 0.410f;
713 1165425 : dE = 0.f;
714 :
715 :
716 : /* more inits */
717 1165425 : hGrid = &hPrivateData->igfInfo.grid[igfGridIdx];
718 1165425 : sN = hPrivateData->igf_sN;
719 1165425 : pN = hPrivateData->igf_pN;
720 1165425 : start_sfb = hGrid->startSfb;
721 1165425 : stop_sfb = hGrid->stopSfb;
722 1165425 : gFactor = hGrid->gFactor;
723 1165425 : fFactor = hGrid->fFactor;
724 1165425 : lFactor = hGrid->lFactor;
725 1165425 : 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 29135625 : for ( tb = hGrid->startLine - 24; tb < hGrid->startLine; tb++ )
734 : {
735 27970200 : dE += pSpectralData[tb] * pSpectralData[tb];
736 : }
737 1165425 : dE = (float) sqrt( dE / 24. );
738 :
739 1165425 : hopsize = 2;
740 1165425 : hopsize = ( hPrivateData->currWhiteningLevel[0] == IGF_WHITENING_OFF ) ? 4 : hopsize;
741 1165425 : hopsize = ( hPrivateData->currWhiteningLevel[0] == IGF_WHITENING_MID ) ? 2 : hopsize;
742 1165425 : hopsize = ( hPrivateData->currWhiteningLevel[0] == IGF_WHITENING_STRONG ) ? 1 : hopsize;
743 1165425 : hopsize = min( hopsize, hPrivateData->igfInfo.maxHopsize );
744 :
745 1165425 : if ( hPrivateData->restrict_hopsize )
746 : {
747 75936 : hopsize = min( hopsize, 2 );
748 : }
749 :
750 1165425 : if ( hopsize > 1 )
751 : {
752 3784982 : for ( sfb = start_sfb; sfb < stop_sfb; sfb += hopsize )
753 : {
754 6651150 : for ( tb = sfb + 1; tb < min( ( sfb + hopsize ), stop_sfb ); tb++ )
755 : {
756 3348879 : sN[sfb] += sN[tb];
757 3348879 : pN[sfb] += pN[tb];
758 3348879 : sN[tb] = 0.f;
759 3348879 : pN[tb] = 0.f;
760 : }
761 : }
762 : }
763 :
764 : /* IGF_rescale_SCF */
765 1165425 : if ( hGrid->infoIsRefined )
766 : {
767 5659061 : for ( sfb = start_sfb; sfb < stop_sfb; sfb += 2 )
768 : {
769 4939425 : width = (float) ( swb_offset[sfb + 2] - swb_offset[sfb] );
770 :
771 4939425 : tmp = (float) hPrivateData->igf_curr[sfb >> 1];
772 4939425 : tmp = (float) pow( 2.0, 0.25 * tmp - 4.0 );
773 4939425 : tmp = tmp * tmp;
774 :
775 4939425 : sNlocal = sN[sfb] + sN[sfb + 1];
776 4939425 : sNlocal /= width;
777 :
778 4939425 : tmp = (float) max( 0.001 * sNlocal, tmp - sNlocal );
779 4939425 : dN[sfb] = (float) sqrt( tmp );
780 4939425 : dN[sfb + 1] = dN[sfb];
781 : }
782 : }
783 : else
784 : {
785 1493598 : for ( sfb = start_sfb; sfb < stop_sfb; sfb++ )
786 : {
787 1047809 : width = (float) ( swb_offset[sfb + 1] - swb_offset[sfb] );
788 :
789 1047809 : tmp = (float) hPrivateData->igf_curr[sfb];
790 1047809 : tmp = (float) pow( 2.0, 0.25 * tmp - 4.0 );
791 1047809 : tmp = tmp * tmp;
792 :
793 1047809 : sNlocal = sN[sfb];
794 1047809 : sNlocal /= width;
795 :
796 1047809 : tmp = (float) max( 0.001 * sNlocal, tmp - sNlocal );
797 1047809 : dN[sfb] = (float) sqrt( tmp );
798 : }
799 : }
800 :
801 1165425 : dS[start_sfb] = dN[start_sfb];
802 : /* first value with adaption to core energy: */
803 1165425 : if ( dE < dN[start_sfb] )
804 : {
805 749483 : dS[start_sfb] = dN[start_sfb] + fFactor * ( dE - dN[start_sfb] );
806 : }
807 : /* last value with less energy: */
808 1165425 : dS[stop_sfb - 1] = lFactor * dN[stop_sfb - 1];
809 :
810 1165425 : if ( hGrid->infoIsRefined && hopsize == 1 )
811 : {
812 : /* apply filter to absolute energy values: */
813 2990775 : for ( sfb = start_sfb + 1; sfb < stop_sfb - 1; sfb++ )
814 : {
815 2753850 : dS[sfb] = w0 * dN[sfb - 1] + w1 * dN[sfb] + w2 * dN[sfb + 1];
816 : }
817 : }
818 : else
819 : {
820 6770459 : for ( sfb = start_sfb + 1; sfb < stop_sfb - 1; sfb++ )
821 : {
822 5841959 : dS[sfb] = dN[sfb];
823 : }
824 : }
825 :
826 8743205 : for ( sfb = start_sfb; sfb < stop_sfb; sfb += hopsize )
827 : {
828 7577780 : E = 0.f;
829 7577780 : sum = 0;
830 18530145 : for ( tb = 0; tb < hopsize; tb++ )
831 : {
832 10952365 : idx1 = min( sfb + tb + 1, stop_sfb );
833 10952365 : idx = min( sfb + tb, stop_sfb );
834 10952365 : width = (float) ( swb_offset[idx1] - swb_offset[idx] );
835 10952365 : idx = min( sfb + tb, stop_sfb - 1 );
836 10952365 : val = dS[idx];
837 10952365 : E += val * val * width;
838 10952365 : sum += width;
839 : }
840 :
841 7577780 : dS[sfb] = (float) sqrt( ( E * hopsize ) / sum );
842 7577780 : dN[sfb] = gFactor * dS[sfb];
843 :
844 7577780 : width = (float) ( swb_offset[sfb + 1] - swb_offset[sfb] );
845 7577780 : dN[sfb] = dN[sfb] * dN[sfb] * width;
846 7577780 : gain[sfb] = 0.f;
847 :
848 7577780 : if ( pN[sfb] > 1.e-20f )
849 : {
850 7550672 : gain[sfb] = (float) sqrt( dN[sfb] / pN[sfb] );
851 : }
852 :
853 10926659 : for ( s_sfb = sfb + 1; s_sfb < min( sfb + hopsize, stop_sfb ); s_sfb++ )
854 : {
855 3348879 : gain[s_sfb] = gain[sfb];
856 : }
857 : }
858 :
859 : /* tiling */
860 12092084 : for ( sfb = start_sfb; sfb < stop_sfb; sfb++ )
861 : {
862 :
863 10926659 : if ( bfi_apply_damping && hPrivateData->frameLossCounter > 0 )
864 : {
865 78814 : gain[sfb] = min( gain[sfb], 12.f );
866 :
867 78814 : if ( hPrivateData->frameLossCounter < 5 )
868 : {
869 66106 : gain[sfb] -= gain[sfb] / 8 * hPrivateData->frameLossCounter;
870 : }
871 : else
872 : {
873 12708 : gain[sfb] /= 2;
874 : }
875 : }
876 :
877 343258719 : for ( tb = swb_offset[sfb]; tb < swb_offset[sfb + 1]; tb++ )
878 : {
879 332332060 : if ( pSpectralData[tb] == 0.f )
880 : {
881 332283453 : pSpectralData[tb] = igf_spec[tb] * gain[sfb];
882 332283453 : flag_sparse[tb - IGF_START_MN] = 1;
883 : }
884 : else
885 : {
886 48607 : virtualSpec[tb - IGF_START_MN] = igf_spec[tb] * gain[sfb];
887 48607 : flag_sparse[tb - IGF_START_MN] = 2;
888 : }
889 : }
890 : }
891 :
892 1165425 : return;
893 : }
894 :
895 :
896 : /*-------------------------------------------------------------------*
897 : * IGF_getWhiteSpectralData()
898 : *
899 : * spectral whitening
900 : *-------------------------------------------------------------------*/
901 :
902 733073 : 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 733073 : div = 0.0f;
918 :
919 326621596 : for ( i = start; i < stop - level; i++ )
920 : {
921 325888523 : ak = 1e-3f;
922 6517135560 : for ( j = i - level; j < i + level + 1; j++ )
923 : {
924 6191247037 : ak += in[j] * in[j];
925 : }
926 325888523 : ak /= (float) ( level * 2 + 1 );
927 :
928 :
929 325888523 : n = (int16_t) max( 0.f, ( log( ak ) * INV_LOG_2 ) ); /* INV_LOG_2 = 1 / (float)log(2.0f)) */
930 325888523 : n >>= 1; /* sqrt() */
931 325888523 : div = (float) ( pow( 2.0f, (float) ( 21 - n ) ) );
932 :
933 :
934 325888523 : out[i] = in[i] * div; /* same as shift */
935 : }
936 :
937 7329280 : for ( ; i < stop; i++ )
938 : {
939 6596207 : ak = 1e-3f;
940 :
941 98927880 : for ( j = i - level; j < stop; j++ )
942 : {
943 92331673 : ak += in[j] * in[j];
944 : }
945 6596207 : ak /= (float) ( stop - ( i - level ) );
946 :
947 :
948 6596207 : n = (int16_t) max( 0.f, ( log( ak ) * INV_LOG_2 ) ); /* INV_LOG_2 = 1 / (float)log(2.0f)) */
949 6596207 : n >>= 1; /* sqrt() */
950 6596207 : div = (float) ( pow( 2.0f, (float) ( 21 - n ) ) );
951 :
952 :
953 6596207 : out[i] = in[i] * div; /* same as shift */
954 : }
955 :
956 733073 : return;
957 : }
958 :
959 :
960 : /*-------------------------------------------------------------------*
961 : * IGF_RefineGrid()
962 : *
963 : * refines the IGF grid
964 : *-------------------------------------------------------------------*/
965 :
966 66585 : 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 66585 : set_s( a, 0, IGF_MAX_SFB + 1 );
974 :
975 :
976 66585 : hGrid->infoIsRefined = 1;
977 603826 : for ( sfb = 0; sfb < hGrid->swb_offset_len; sfb++ )
978 : {
979 537241 : a[sfb * 2 + 0] = hGrid->swb_offset[sfb];
980 537241 : a[sfb * 2 + 1] = (int16_t) round_f( hGrid->swb_offset[sfb] + 0.45f * ( hGrid->swb_offset[sfb + 1] - hGrid->swb_offset[sfb] ) );
981 537241 : if ( a[sfb * 2 + 1] & 1 )
982 : {
983 200724 : a[sfb * 2 + 1]--;
984 : }
985 : }
986 66585 : hGrid->stopSfb = hGrid->stopSfb * 2;
987 1074482 : for ( sfb = 0; sfb <= hGrid->stopSfb; sfb++ )
988 : {
989 1007897 : hGrid->swb_offset[sfb] = a[sfb];
990 : }
991 :
992 477516 : for ( sfb = 0; sfb <= hGrid->nTiles; sfb++ )
993 : {
994 410931 : hGrid->sfbWrap[sfb] *= 2;
995 : }
996 :
997 66585 : return;
998 : }
999 :
1000 :
1001 : /*-------------------------------------------------------------------*
1002 : * IGFDecReadData()
1003 : *
1004 : * reads whitening information from the bitstream
1005 : *-------------------------------------------------------------------*/
1006 :
1007 1157903 : 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 1157903 : if ( hIGFDec != NULL )
1021 : {
1022 1157903 : hPrivateData = &hIGFDec->igfData;
1023 1157903 : hGrid = &hPrivateData->igfInfo.grid[igfGridIdx];
1024 1157903 : nT = hGrid->nTiles;
1025 1157903 : tmp = -1;
1026 :
1027 12736933 : for ( p = 0; p < IGF_MAX_TILES; p++ )
1028 : {
1029 11579030 : hPrivateData->currWhiteningLevel[p] = IGF_WHITENING_OFF;
1030 : }
1031 :
1032 1157903 : if ( isIndepFrame )
1033 : {
1034 1137869 : tmp = 0;
1035 : }
1036 : else
1037 : {
1038 20034 : tmp = get_next_indice( st, 1 );
1039 : }
1040 1157903 : if ( tmp == 1 )
1041 : {
1042 70755 : for ( p = 0; p < nT; p++ )
1043 : {
1044 51636 : hPrivateData->currWhiteningLevel[p] = hPrivateData->prevWhiteningLevel[p];
1045 : }
1046 : }
1047 : else
1048 : {
1049 1138784 : IGF_decode_whitening_level( st, hPrivateData, 0 );
1050 1138784 : if ( hPrivateData->igfInfo.bitRateIndex == IGF_BITRATE_SWB_48000_CPE || hPrivateData->igfInfo.bitRateIndex == IGF_BITRATE_FB_48000_CPE )
1051 : {
1052 109948 : tmp = 0;
1053 : }
1054 : else
1055 : {
1056 1028836 : tmp = get_next_indice( st, 1 );
1057 : }
1058 :
1059 1138784 : if ( tmp == 1 )
1060 : {
1061 2018343 : for ( p = 1; p < nT; p++ )
1062 : {
1063 1187148 : IGF_decode_whitening_level( st, hPrivateData, p );
1064 : }
1065 : }
1066 : else
1067 : {
1068 1495822 : for ( p = 1; p < nT; p++ )
1069 : {
1070 1188233 : hPrivateData->currWhiteningLevel[p] = hPrivateData->currWhiteningLevel[0];
1071 : }
1072 : }
1073 : }
1074 12736933 : for ( p = 0; p < IGF_MAX_TILES; p++ )
1075 : {
1076 11579030 : hPrivateData->prevWhiteningLevel[p] = hPrivateData->currWhiteningLevel[p];
1077 : }
1078 :
1079 : /* IGF_decode_temp_flattening_trigger()*/
1080 1157903 : hIGFDec->flatteningTrigger = get_next_indice( st, 1 );
1081 : }
1082 :
1083 1157903 : 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 1157903 : 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 1157903 : IGFAllZero = 1;
1107 :
1108 1157903 : if ( hIGFDec != NULL )
1109 : {
1110 1157903 : hPrivateData = &hIGFDec->igfData;
1111 1157903 : hGrid = &hPrivateData->igfInfo.grid[igfGridIdx];
1112 1157903 : m_igfSfbStart = hGrid->startSfb;
1113 1157903 : IGFAllZero = get_next_indice( st, 1 );
1114 :
1115 1157903 : if ( IGFAllZero == 0 )
1116 : {
1117 1152467 : mvs2s( hPrivateData->igf_curr, hPrivateData->igf_prev, hGrid->stopSfb );
1118 :
1119 1152467 : IGFSCFDecoderDecode( &hPrivateData->hArithSCFdec, st, &hPrivateData->igf_curr[m_igfSfbStart], igfGridIdx, isIndepFrame );
1120 : }
1121 : else
1122 : {
1123 5436 : IGFSCFDecoderReset( &hPrivateData->hArithSCFdec );
1124 :
1125 5436 : set_s( &hPrivateData->igf_curr[m_igfSfbStart], 0, hGrid->stopSfb - m_igfSfbStart );
1126 : }
1127 : }
1128 :
1129 1157903 : hIGFDec->infoIGFAllZero = IGFAllZero;
1130 :
1131 1157903 : return IGFAllZero;
1132 : }
1133 :
1134 :
1135 : /*-------------------------------------------------------------------*
1136 : * IGFDecApplyMono()
1137 : *
1138 : * apply the IGF decoder in mono
1139 : *-------------------------------------------------------------------*/
1140 :
1141 702867 : 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 702867 : set_zero( igf_spec, IGF_MAX_GRANULE_LEN );
1156 :
1157 : /* initialize variables */
1158 702867 : if ( element_mode > EVS_MONO )
1159 : {
1160 701542 : whiteningLevel = IGF_MID_WHITENING_LEVEL2;
1161 : }
1162 : else
1163 : {
1164 1325 : whiteningLevel = IGF_MID_WHITENING_LEVEL;
1165 : }
1166 :
1167 702867 : nShift = igfGridIdx == IGF_GRID_LB_SHORT ? 2 : 1;
1168 702867 : set_s( hIGFDec->flag_sparse, 0, ( N_MAX_TCX - IGF_START_MN ) / nShift );
1169 702867 : set_f( hIGFDec->virtualSpec, 0.f, ( N_MAX_TCX - IGF_START_MN ) / nShift );
1170 :
1171 702867 : hPrivateData = &hIGFDec->igfData;
1172 702867 : hGrid = &hPrivateData->igfInfo.grid[igfGridIdx];
1173 702867 : hPrivateData->totalNoiseNrg = 0.f;
1174 702867 : hPrivateData->n_noise_bands = 0;
1175 702867 : hPrivateData->totalNoiseNrg_off = 0.f;
1176 702867 : hPrivateData->n_noise_bands_off = 0;
1177 702867 : hPrivateData->restrict_hopsize = 0;
1178 :
1179 : /* concealment counter */
1180 702867 : if ( bfi )
1181 : {
1182 6592 : hPrivateData->frameLossCounter++;
1183 : }
1184 : else
1185 : {
1186 696275 : hPrivateData->frameLossCounter = 0;
1187 : }
1188 :
1189 : /* skip IGF processing if all IGF levels are zero */
1190 702867 : if ( !hIGFDec->infoIGFAllZero )
1191 : {
1192 1706749 : for ( i = 0; i < hGrid->nTiles; i++ )
1193 : {
1194 1414273 : if ( hPrivateData->currWhiteningLevel[i] == IGF_WHITENING_MID )
1195 : {
1196 410055 : if ( element_mode == EVS_MONO || !bfi )
1197 : {
1198 407251 : IGF_getWhiteSpectralData( hPrivateData->pSpecFlat, igf_spec, hGrid->minSrcSubband, hGrid->startLine, whiteningLevel );
1199 : }
1200 : else
1201 : {
1202 2804 : mvr2r( hPrivateData->pSpecFlat, igf_spec, hGrid->startLine );
1203 : }
1204 :
1205 410055 : hPrivateData->n_noise_bands = IGF_replaceTCXNoise_1( igf_spec, hIGFDec->infoTCXNoise, hGrid->minSrcSubband, hGrid->startLine, &hPrivateData->totalNoiseNrg );
1206 410055 : break;
1207 : }
1208 : }
1209 :
1210 1787577 : for ( i = 0; i < hGrid->nTiles; i++ )
1211 : {
1212 1339053 : if ( hPrivateData->currWhiteningLevel[i] == IGF_WHITENING_OFF )
1213 : {
1214 254007 : hPrivateData->n_noise_bands_off = IGF_replaceTCXNoise_1( hPrivateData->pSpecFlat, hIGFDec->infoTCXNoise, hGrid->minSrcSubband, hGrid->startLine, &hPrivateData->totalNoiseNrg_off );
1215 254007 : break;
1216 : }
1217 : }
1218 :
1219 : /* apply IGF in three steps: */
1220 702531 : IGF_prep( hPrivateData, igfGridIdx, hIGFDec->infoTCXNoise, igf_spec, hPrivateData->pSpecFlat, element_mode );
1221 702531 : IGF_calc( hPrivateData, igfGridIdx, spectrum, igf_spec );
1222 702531 : IGF_appl( hPrivateData, igfGridIdx, spectrum, igf_spec, hIGFDec->virtualSpec, hIGFDec->flag_sparse, 1 );
1223 : }
1224 :
1225 : /* reset TCX noise indicator vector */
1226 702867 : nLinesToReset = igfGridIdx == IGF_GRID_LB_SHORT ? 2 : 1;
1227 702867 : nLinesToReset = IGF_START_MX / nLinesToReset;
1228 702867 : set_c( (int8_t *) ( hIGFDec->infoTCXNoise ), 0, nLinesToReset );
1229 :
1230 702867 : return;
1231 : }
1232 :
1233 :
1234 : /*-------------------------------------------------------------------*
1235 : * IGFDecApplyStereo()
1236 : *
1237 : * apply the IGF decoder in stereo
1238 : *-------------------------------------------------------------------*/
1239 :
1240 231448 : 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 231448 : set_f( igf_specL, 0.f, IGF_MAX_GRANULE_LEN );
1258 231448 : set_f( igf_specR, 0.f, IGF_MAX_GRANULE_LEN );
1259 :
1260 : /* initialize variables */
1261 231448 : whiteningLevel = IGF_MID_WHITENING_LEVEL2;
1262 :
1263 231448 : nShift = igfGridIdx == IGF_GRID_LB_SHORT ? 2 : 1;
1264 231448 : set_s( hIGFDecL->flag_sparse, 0, ( N_MAX_TCX - IGF_START_MN ) / nShift );
1265 231448 : set_s( hIGFDecR->flag_sparse, 0, ( N_MAX_TCX - IGF_START_MN ) / nShift );
1266 231448 : set_f( hIGFDecL->virtualSpec, 0.f, ( N_MAX_TCX - IGF_START_MN ) / nShift );
1267 231448 : set_f( hIGFDecR->virtualSpec, 0.f, ( N_MAX_TCX - IGF_START_MN ) / nShift );
1268 :
1269 231448 : hPrivateDataL = &hIGFDecL->igfData;
1270 231448 : hGrid = &hPrivateDataL->igfInfo.grid[igfGridIdx];
1271 231448 : hPrivateDataL->totalNoiseNrg = 0.f;
1272 231448 : hPrivateDataL->n_noise_bands = 0;
1273 231448 : hPrivateDataL->totalNoiseNrg_off = 0.f;
1274 231448 : hPrivateDataL->n_noise_bands_off = 0;
1275 231448 : hPrivateDataL->restrict_hopsize = restrict_hopsize;
1276 :
1277 231448 : hPrivateDataR = &hIGFDecR->igfData;
1278 231448 : hPrivateDataR->totalNoiseNrg = 0.f;
1279 231448 : hPrivateDataR->n_noise_bands = 0;
1280 231448 : hPrivateDataR->totalNoiseNrg_off = 0.f;
1281 231448 : hPrivateDataR->n_noise_bands_off = 0;
1282 231448 : hPrivateDataR->restrict_hopsize = restrict_hopsize;
1283 :
1284 : /* concealment counter */
1285 231448 : if ( bfi )
1286 : {
1287 634 : hPrivateDataL->frameLossCounter++;
1288 634 : hPrivateDataR->frameLossCounter++;
1289 : }
1290 : else
1291 : {
1292 230814 : hPrivateDataL->frameLossCounter = 0;
1293 230814 : hPrivateDataR->frameLossCounter = 0;
1294 : }
1295 :
1296 : /* skip IGF processing if all IGF levels are zero */
1297 231448 : if ( !hIGFDecL->infoIGFAllZero || !hIGFDecR->infoIGFAllZero )
1298 : {
1299 567672 : for ( i = 0; i < hGrid->nTiles; i++ )
1300 : {
1301 499503 : if ( hPrivateDataL->currWhiteningLevel[i] == IGF_WHITENING_MID || hPrivateDataR->currWhiteningLevel[i] == IGF_WHITENING_MID )
1302 : {
1303 163278 : if ( !bfi )
1304 : {
1305 162911 : IGF_getWhiteSpectralData( hPrivateDataL->pSpecFlat, igf_specL, hGrid->minSrcSubband, hGrid->startLine, whiteningLevel );
1306 : }
1307 : else
1308 : {
1309 367 : mvr2r( hPrivateDataL->pSpecFlat, igf_specL, hGrid->startLine );
1310 : }
1311 :
1312 163278 : hPrivateDataL->n_noise_bands = IGF_replaceTCXNoise_1( igf_specL, hIGFDecL->infoTCXNoise, hGrid->minSrcSubband, hGrid->startLine, &hPrivateDataL->totalNoiseNrg );
1313 :
1314 163278 : if ( !bfi )
1315 : {
1316 162911 : IGF_getWhiteSpectralData( hPrivateDataR->pSpecFlat, igf_specR, hGrid->minSrcSubband, hGrid->startLine, whiteningLevel );
1317 : }
1318 : else
1319 : {
1320 367 : mvr2r( hPrivateDataR->pSpecFlat, igf_specR, hGrid->startLine );
1321 : }
1322 :
1323 163278 : hPrivateDataR->n_noise_bands = IGF_replaceTCXNoise_1( igf_specR, hIGFDecR->infoTCXNoise, hGrid->minSrcSubband, hGrid->startLine, &hPrivateDataR->totalNoiseNrg );
1324 :
1325 163278 : break;
1326 : }
1327 : }
1328 :
1329 545167 : for ( i = 0; i < hGrid->nTiles; i++ )
1330 : {
1331 438686 : if ( hPrivateDataL->currWhiteningLevel[i] == IGF_WHITENING_OFF || hPrivateDataR->currWhiteningLevel[i] == IGF_WHITENING_OFF )
1332 : {
1333 124966 : hPrivateDataL->n_noise_bands_off = IGF_replaceTCXNoise_1( hPrivateDataL->pSpecFlat, hIGFDecL->infoTCXNoise, hGrid->minSrcSubband, hGrid->startLine, &hPrivateDataL->totalNoiseNrg_off );
1334 :
1335 124966 : hPrivateDataR->n_noise_bands_off = IGF_replaceTCXNoise_1( hPrivateDataR->pSpecFlat, hIGFDecR->infoTCXNoise, hGrid->minSrcSubband, hGrid->startLine, &hPrivateDataR->totalNoiseNrg_off );
1336 124966 : break;
1337 : }
1338 : }
1339 :
1340 : /* apply IGF in three steps: */
1341 231447 : IGF_prepStereo( hPrivateDataL, hPrivateDataR, igfGridIdx, hIGFDecL->infoTCXNoise, hIGFDecR->infoTCXNoise, igf_specL, igf_specR, hPrivateDataL->pSpecFlat, hPrivateDataR->pSpecFlat, coreMsMask );
1342 :
1343 231447 : IGF_calc( hPrivateDataL, igfGridIdx, spectrumL, igf_specL );
1344 231447 : IGF_calc( hPrivateDataR, igfGridIdx, spectrumR, igf_specR );
1345 231447 : IGF_appl( hPrivateDataL, igfGridIdx, spectrumL, igf_specL, hIGFDecL->virtualSpec, hIGFDecL->flag_sparse, bfi_apply_damping );
1346 231447 : IGF_appl( hPrivateDataR, igfGridIdx, spectrumR, igf_specR, hIGFDecR->virtualSpec, hIGFDecR->flag_sparse, bfi_apply_damping );
1347 : }
1348 :
1349 : /* reset TCX noise indicator vector */
1350 231448 : nLinesToReset = ( igfGridIdx == IGF_GRID_LB_SHORT ) ? 2 : 1;
1351 231448 : nLinesToReset = IGF_START_MX / nLinesToReset;
1352 231448 : set_c( (int8_t *) ( hIGFDecL->infoTCXNoise ), 0, nLinesToReset );
1353 231448 : set_c( (int8_t *) ( hIGFDecR->infoTCXNoise ), 0, nLinesToReset );
1354 :
1355 231448 : 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 27293 : 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 27293 : hPrivateData = &hIGFDec->igfData;
1378 27293 : hIGFDec->isIGFActive = 0;
1379 :
1380 27293 : if ( IGFCommonFuncsIGFConfiguration( total_brate, bwidth, element_mode, &hPrivateData->igfInfo, rf_mode ) )
1381 : {
1382 27293 : IGFSCFDecoderOpen( &hPrivateData->hArithSCFdec, &hPrivateData->igfInfo, total_brate, bwidth, element_mode, rf_mode );
1383 :
1384 27293 : hIGFDec->infoIGFAllZero = 0;
1385 27293 : hIGFDec->isIGFActive = 1;
1386 27293 : hIGFDec->infoIGFStopLine = hPrivateData->igfInfo.grid[0].stopLine;
1387 27293 : hIGFDec->infoIGFStartLine = hPrivateData->igfInfo.grid[0].startLine;
1388 27293 : hIGFDec->infoIGFStopFreq = hPrivateData->igfInfo.grid[0].stopFrequency;
1389 27293 : hIGFDec->infoIGFStartFreq = hPrivateData->igfInfo.grid[0].startFrequency;
1390 :
1391 : /* no refinement if maxHopsize is 1 */
1392 27293 : if ( hPrivateData->igfInfo.bitRateIndex != IGF_BITRATE_FB_96000 && hPrivateData->igfInfo.bitRateIndex != IGF_BITRATE_FB_96000_CPE &&
1393 26039 : hPrivateData->igfInfo.bitRateIndex != IGF_BITRATE_FB_128000 && hPrivateData->igfInfo.bitRateIndex != IGF_BITRATE_FB_128000_CPE )
1394 : {
1395 22195 : IGF_RefineGrid( &hPrivateData->igfInfo.grid[IGF_GRID_LB_NORM] );
1396 22195 : IGF_RefineGrid( &hPrivateData->igfInfo.grid[IGF_GRID_LB_TRAN] );
1397 22195 : 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 27293 : hIGFDec->flag_sparse = &hIGFDec->flag_sparseBuf[0];
1411 27293 : hIGFDec->infoTCXNoise = &hIGFDec->infoTCXNoiseBuf[0];
1412 27293 : hIGFDec->virtualSpec = &hIGFDec->virtualSpecBuf[0];
1413 27293 : hIGFDec->igfData.pSpecFlat = &hIGFDec->igfData.pSpecFlatBuf[0];
1414 27293 : hIGFDec->igfData.igfInfo.nfSeed = &hIGFDec->igfData.igfInfo.nfSeedBuf[0];
1415 :
1416 27293 : return;
1417 : }
1418 :
1419 :
1420 : /*-------------------------------------------------------------------*
1421 : * IGFDecUpdateInfo()
1422 : *
1423 : * updates the start/stop frequency of IGF according to igfGridIdx
1424 : *-------------------------------------------------------------------*/
1425 :
1426 4575583 : 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 4575583 : hIGFDec->flag_sparse = &hIGFDec->flag_sparseBuf[0];
1436 4575583 : hIGFDec->infoTCXNoise = &hIGFDec->infoTCXNoiseBuf[0];
1437 4575583 : hIGFDec->virtualSpec = &hIGFDec->virtualSpecBuf[0];
1438 4575583 : hIGFDec->igfData.pSpecFlat = &hIGFDec->igfData.pSpecFlatBuf[0];
1439 4575583 : hIGFDec->igfData.igfInfo.nfSeed = &hIGFDec->igfData.igfInfo.nfSeedBuf[0];
1440 :
1441 4575583 : if ( igfGridIdx == IGF_GRID_LB_SHORT )
1442 : {
1443 176477 : IGFDecRestoreTCX10SubFrameData( hIGFDec, subFrameIdx );
1444 : }
1445 :
1446 4575583 : hPrivateData = &hIGFDec->igfData;
1447 4575583 : if ( hIGFDec->isIGFActive )
1448 : {
1449 4575583 : hGrid = &hPrivateData->igfInfo.grid[igfGridIdx];
1450 4575583 : hIGFDec->infoIGFStartFreq = hGrid->startFrequency;
1451 4575583 : hIGFDec->infoIGFStopFreq = hGrid->stopFrequency;
1452 4575583 : hIGFDec->infoIGFStartLine = hGrid->startLine;
1453 4575583 : hIGFDec->infoIGFStopLine = hGrid->stopLine;
1454 : }
1455 :
1456 4575583 : return;
1457 : }
1458 :
1459 :
1460 : /*-------------------------------------------------------------------*
1461 : * IGFDecReplicateTCX10State()
1462 : *
1463 : *
1464 : *-------------------------------------------------------------------*/
1465 :
1466 25 : void IGFDecReplicateTCX10State(
1467 : IGF_DEC_INSTANCE_HANDLE hIGFDec /* i/o: instance handle of IGF Decoder */
1468 : )
1469 : {
1470 25 : mvs2s( &hIGFDec->flag_sparseBuf[( N_MAX_TCX - IGF_START_MN ) / 2], &hIGFDec->flag_sparseBuf[0], ( N_MAX_TCX - IGF_START_MN ) / 2 );
1471 25 : mvc2c( &hIGFDec->infoTCXNoiseBuf[( IGF_START_MX ) / 2], &hIGFDec->infoTCXNoiseBuf[0], ( IGF_START_MX ) / 2 );
1472 25 : mvr2r( &hIGFDec->virtualSpecBuf[( N_MAX_TCX - IGF_START_MN ) / 2], &hIGFDec->virtualSpecBuf[0], ( N_MAX_TCX - IGF_START_MN ) / 2 );
1473 25 : mvr2r( &hIGFDec->igfData.pSpecFlatBuf[IGF_START_MX / 2], &hIGFDec->igfData.pSpecFlatBuf[0], IGF_START_MX / 2 );
1474 :
1475 25 : hIGFDec->igfData.igfInfo.nfSeedBuf[0] = hIGFDec->igfData.igfInfo.nfSeedBuf[1];
1476 :
1477 25 : return;
1478 : }
1479 :
1480 :
1481 : /*-------------------------------------------------------------------*
1482 : * IGFDecCopyLPCFlatSpectrum()
1483 : *
1484 : * copy the LPC flat spectrum to IGF buffer
1485 : *-------------------------------------------------------------------*/
1486 :
1487 1159032 : 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 1159032 : if ( hIGFDec )
1498 : {
1499 1159032 : hPrivateData = &hIGFDec->igfData;
1500 1159032 : hGrid = &hPrivateData->igfInfo.grid[igfGridIdx];
1501 :
1502 499141584 : for ( i = hGrid->minSrcSubband - IGF_MID_WHITENING_LEVEL2; i < hGrid->startLine; i++ )
1503 : {
1504 497982552 : hPrivateData->pSpecFlat[i] = pSpectrumFlat[i] * 1024.f;
1505 : }
1506 : }
1507 :
1508 1159032 : return;
1509 : }
1510 :
1511 :
1512 : /*-------------------------------------------------------------------*
1513 : * IGFDecStoreTCX10SubFrameData()
1514 : *
1515 : * store the IGF bitstream information for TCX10 subframes
1516 : *-------------------------------------------------------------------*/
1517 :
1518 40068 : 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 40068 : hPrivateData = &hIGFDec->igfData;
1526 :
1527 : /* store igf energies for subframe*/
1528 40068 : mvs2s( hPrivateData->igf_curr, hPrivateData->igf_curr_subframe[subFrameIdx][0], IGF_MAX_SFB );
1529 40068 : mvs2s( hPrivateData->igf_prev, hPrivateData->igf_prev_subframe[subFrameIdx], IGF_MAX_SFB );
1530 :
1531 : /* store spectral whitening information for current subframe */
1532 40068 : mvs2s( hPrivateData->currWhiteningLevel, hPrivateData->currWhiteningLevel_subframe[subFrameIdx], IGF_MAX_TILES );
1533 40068 : mvs2s( hPrivateData->prevWhiteningLevel, hPrivateData->prevWhiteningLevel_subframe[subFrameIdx], IGF_MAX_TILES );
1534 :
1535 : /* store flattening trigger for current subframe */
1536 40068 : hPrivateData->igf_flatteningTrigger_subframe[subFrameIdx] = hIGFDec->flatteningTrigger;
1537 :
1538 40068 : return;
1539 : }
1540 :
1541 :
1542 : /*-------------------------------------------------------------------*
1543 : * IGFDecRestoreTCX10SubFrameData()
1544 : *
1545 : * restore the IGF bitstream information for TCX10 subframes
1546 : *-------------------------------------------------------------------*/
1547 :
1548 180883 : 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 180883 : hPrivateData = &hIGFDec->igfData;
1556 :
1557 : /* store igf energies for subframe*/
1558 180883 : mvs2s( hPrivateData->igf_curr_subframe[subFrameIdx][0], hPrivateData->igf_curr, IGF_MAX_SFB );
1559 180883 : mvs2s( hPrivateData->igf_prev_subframe[subFrameIdx], hPrivateData->igf_prev, IGF_MAX_SFB );
1560 :
1561 : /* store spectral whitening information for current subframe */
1562 180883 : mvs2s( hPrivateData->currWhiteningLevel_subframe[subFrameIdx], hPrivateData->currWhiteningLevel, IGF_MAX_TILES );
1563 180883 : mvs2s( hPrivateData->prevWhiteningLevel_subframe[subFrameIdx], hPrivateData->prevWhiteningLevel, IGF_MAX_TILES );
1564 :
1565 : /* restore flattening trigger for current subframe */
1566 180883 : hIGFDec->flatteningTrigger = hPrivateData->igf_flatteningTrigger_subframe[subFrameIdx];
1567 180883 : hIGFDec->flag_sparse = &hIGFDec->flag_sparseBuf[subFrameIdx * ( N_MAX_TCX - IGF_START_MN ) / 2];
1568 180883 : hIGFDec->infoTCXNoise = &hIGFDec->infoTCXNoiseBuf[subFrameIdx * ( IGF_START_MX ) / 2];
1569 180883 : hIGFDec->virtualSpec = &hIGFDec->virtualSpecBuf[subFrameIdx * ( N_MAX_TCX - IGF_START_MN ) / 2];
1570 180883 : hIGFDec->igfData.pSpecFlat = &hIGFDec->igfData.pSpecFlatBuf[subFrameIdx * IGF_START_MX / 2];
1571 180883 : hIGFDec->igfData.igfInfo.nfSeed = &hIGFDec->igfData.igfInfo.nfSeedBuf[subFrameIdx];
1572 :
1573 180883 : return;
1574 : }
1575 :
1576 :
1577 : /*-----------------------------------------------------------------------*
1578 : * init_igf_dec()
1579 : *
1580 : * Initialize IGF decoder parameters
1581 : *-----------------------------------------------------------------------*/
1582 :
1583 14712 : void init_igf_dec(
1584 : IGF_DEC_INSTANCE_HANDLE hIGFDec /* i/o: IGF decoder handle */
1585 : )
1586 : {
1587 14712 : set_c( (int8_t *) ( hIGFDec->infoTCXNoiseBuf ), 0, IGF_START_MX );
1588 14712 : set_f( hIGFDec->igfData.pSpecFlatBuf, 0, IGF_START_MX );
1589 14712 : hIGFDec->igfData.igfInfo.nfSeedBuf[0] = 9733;
1590 14712 : hIGFDec->igfData.igfInfo.nfSeedBuf[1] = 9733;
1591 14712 : hIGFDec->igfData.igfInfo.nfSeed = &hIGFDec->igfData.igfInfo.nfSeedBuf[0];
1592 14712 : hIGFDec->igfData.pSpecFlat = &hIGFDec->igfData.pSpecFlatBuf[0];
1593 14712 : hIGFDec->flag_sparse = &hIGFDec->flag_sparseBuf[0];
1594 14712 : hIGFDec->infoTCXNoise = &hIGFDec->infoTCXNoiseBuf[0];
1595 14712 : hIGFDec->virtualSpec = &hIGFDec->virtualSpecBuf[0];
1596 14712 : hIGFDec->infoIGFStopFreq = 0;
1597 :
1598 14712 : return;
1599 : }
1600 :
1601 :
1602 : /*-----------------------------------------------------------------------*
1603 : * get_igf_startline()
1604 : *
1605 : *
1606 : *-----------------------------------------------------------------------*/
1607 :
1608 : /*! r: IGF start line */
1609 3041583 : int16_t get_igf_startline(
1610 : Decoder_State *st, /* i : decoder state */
1611 : const int16_t L_frame, /* i : length of the frame */
1612 : const int16_t L_frameTCX /* i : full band frame length */
1613 : )
1614 : {
1615 : int16_t igf_startline;
1616 :
1617 3041583 : if ( st->igf == 0 )
1618 : {
1619 1024752 : if ( st->narrowBand == 0 )
1620 : {
1621 : /* minimum needed for output with sampling rates lower then the
1622 : nominal sampling rate */
1623 1024752 : igf_startline = min( L_frameTCX, L_frame );
1624 : }
1625 : else
1626 : {
1627 0 : igf_startline = L_frameTCX;
1628 : }
1629 : }
1630 : else
1631 : {
1632 2016831 : igf_startline = min( st->hIGFDec->infoIGFStartLine, L_frameTCX );
1633 : }
1634 :
1635 3041583 : return igf_startline;
1636 : }
|