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 1826934 : 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 1826934 : noise = 0;
72 1826934 : nE = FLT_MIN;
73 :
74 694449198 : for ( sb = start; sb < stop; sb++ )
75 : {
76 692622264 : val = in[sb] * TCXNoise[sb];
77 692622264 : nE += val * val;
78 692622264 : noise += TCXNoise[sb];
79 : }
80 :
81 1826934 : *totalNoiseNrg = nE;
82 :
83 1826934 : 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 4736466 : 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 4736466 : rE = FLT_MIN;
156 4736466 : n_noise_bands_tile = 0;
157 383858028 : for ( sb = start; sb < stop; sb++ )
158 : {
159 379121562 : if ( TCXNoise[sb] )
160 : {
161 327175272 : val = (float) own_random( nfSeed );
162 327175272 : in[sb] = val;
163 327175272 : rE += val * val;
164 327175272 : n_noise_bands_tile++;
165 : }
166 : }
167 :
168 4736466 : rE = max( rE, 1.f );
169 :
170 4736466 : if ( n_noise_bands_tile )
171 : {
172 4736037 : noise_band_ratio = (float) n_noise_bands_tile / n_noise_bands;
173 4736037 : g = (float) sqrt( totalNoiseNrg * noise_band_ratio / rE );
174 :
175 383845539 : for ( sb = start; sb < stop; sb++ )
176 : {
177 379109502 : if ( TCXNoise[sb] )
178 : {
179 327175272 : in[sb] *= g;
180 : }
181 : }
182 : }
183 :
184 4736466 : return;
185 : }
186 :
187 :
188 : /*-------------------------------------------------------------------*
189 : * IGF_decode_whitening_level()
190 : *
191 : * reads whitening levels
192 : *-------------------------------------------------------------------*/
193 :
194 3691587 : 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 3691587 : tmp = get_next_indice( st, 1 );
203 :
204 3691587 : if ( tmp == 1 )
205 : {
206 2308224 : tmp = get_next_indice( st, 1 );
207 2308224 : if ( tmp == 1 )
208 : {
209 1141404 : hPrivateData->currWhiteningLevel[p] = IGF_WHITENING_STRONG;
210 : }
211 : else
212 : {
213 1166820 : hPrivateData->currWhiteningLevel[p] = IGF_WHITENING_OFF;
214 : }
215 : }
216 : else
217 : {
218 1383363 : hPrivateData->currWhiteningLevel[p] = IGF_WHITENING_MID;
219 : }
220 :
221 3691587 : return;
222 : }
223 :
224 :
225 : /*-------------------------------------------------------------------*
226 : * IGF_getMDCTSquare()
227 : *
228 : * square the MDCT spectrum
229 : *-------------------------------------------------------------------*/
230 :
231 3627216 : 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 1051386480 : for ( i = startLine; i < stopLine; i++ )
241 : {
242 1047759264 : pSpecDataSqaure[i] = pSpectralData[i] * pSpectralData[i];
243 : }
244 :
245 3627216 : return;
246 : }
247 :
248 :
249 : /*-------------------------------------------------------------------*
250 : * IGF_calcSfbEnergy()
251 : *
252 : * calculate energy per SFB
253 : *-------------------------------------------------------------------*/
254 :
255 3627216 : 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 38172504 : for ( sfb = startSfb; sfb < stopSfb; sfb++ )
267 : {
268 34545288 : sfbEnergy[sfb] = 0.f;
269 :
270 1082304552 : for ( line = swb_offset[sfb]; line < swb_offset[sfb + 1]; line++ )
271 : {
272 1047759264 : sfbEnergy[sfb] += pPowerSpectrum[line];
273 : }
274 : }
275 :
276 3627216 : return;
277 : }
278 :
279 :
280 : /*-------------------------------------------------------------------*
281 : * IGF_setLinesToZero()
282 : *
283 : * set power spectrum values to zero, needed for energy calculation
284 : *-------------------------------------------------------------------*/
285 :
286 1813608 : 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 525693240 : for ( i = startLine; i < stopLine; i++ )
296 : {
297 523879632 : if ( pSpectralData[i] != 0.f )
298 : {
299 60090 : squareSpecIGF[i] = 0.f;
300 : }
301 : }
302 :
303 1813608 : return;
304 : }
305 :
306 :
307 : /*-------------------------------------------------------------------*
308 : * IGF_prep()
309 : *
310 : * prepare IGF spectrum
311 : *-------------------------------------------------------------------*/
312 :
313 1278720 : 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 1278720 : hInfo = &hPrivateData->igfInfo;
329 1278720 : hGrid = &hPrivateData->igfInfo.grid[igfGridIdx];
330 1278720 : swb_offset = hGrid->swb_offset;
331 :
332 5620698 : for ( tile_idx = 0; tile_idx < hGrid->nTiles; tile_idx++ )
333 : {
334 : int16_t tile_width, stop;
335 :
336 4341978 : strt_cpy = hGrid->sbWrap[tile_idx];
337 :
338 4341978 : if ( element_mode > EVS_MONO )
339 : {
340 4336989 : tile_width = swb_offset[hGrid->sfbWrap[tile_idx + 1]] - swb_offset[hGrid->sfbWrap[tile_idx]];
341 4336989 : stop = strt_cpy + tile_width;
342 : }
343 : else
344 : {
345 4989 : stop = hGrid->startLine;
346 : }
347 :
348 4341978 : if ( IGF_WHITENING_STRONG == hPrivateData->currWhiteningLevel[tile_idx] )
349 : {
350 : float abs_sum;
351 1191714 : abs_sum = 0.f;
352 :
353 126186882 : for ( i = strt_cpy; i < stop; i++ )
354 : {
355 124995168 : abs_sum += (float) fabs( src_spec[i] );
356 : }
357 :
358 1191714 : tb = swb_offset[hGrid->sfbWrap[tile_idx]];
359 :
360 1191714 : if ( abs_sum > 0.f )
361 : {
362 125974362 : for ( i = strt_cpy; i < stop; i++ )
363 : {
364 124785318 : 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 3150264 : if ( IGF_WHITENING_MID == hPrivateData->currWhiteningLevel[tile_idx] )
378 : {
379 1381392 : if ( element_mode > EVS_MONO )
380 : {
381 1379700 : if ( hPrivateData->n_noise_bands )
382 : {
383 1320474 : 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 1381392 : sel_spec = igf_spec;
395 : }
396 : else
397 : {
398 1768872 : if ( element_mode > EVS_MONO )
399 : {
400 1767921 : if ( hPrivateData->n_noise_bands_off )
401 : {
402 1730778 : 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 1768872 : sel_spec = src_spec;
414 : }
415 11423754 : for ( sfb = hGrid->sfbWrap[tile_idx]; sfb < hGrid->sfbWrap[tile_idx + 1]; sfb++ )
416 : {
417 260478810 : for ( tb = swb_offset[sfb]; tb < swb_offset[sfb + 1]; tb++ )
418 : {
419 252205320 : igf_spec[tb] = sel_spec[strt_cpy];
420 252205320 : strt_cpy++;
421 : }
422 : }
423 : }
424 : }
425 :
426 1278720 : return;
427 : }
428 :
429 :
430 : /*-------------------------------------------------------------------*
431 : * IGF_prepStereo()
432 : *
433 : *
434 : *-------------------------------------------------------------------*/
435 :
436 267444 : 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 267444 : float *sel_specL = NULL;
454 267444 : float *sel_specR = NULL;
455 267444 : const float c = SQRT2_OVER_2; /* M/S scaling factor */
456 :
457 267444 : hInfoL = &hPrivateDataL->igfInfo;
458 267444 : hInfoR = &hPrivateDataR->igfInfo;
459 267444 : hGrid = &hPrivateDataL->igfInfo.grid[igfGridIdx];
460 267444 : swb_offset = hGrid->swb_offset;
461 :
462 1123056 : for ( tile_idx = 0; tile_idx < hGrid->nTiles; tile_idx++ )
463 : {
464 : int16_t tile_width, stop;
465 855612 : strt_cpy = hGrid->sbWrap[tile_idx];
466 :
467 855612 : tile_width = swb_offset[hGrid->sfbWrap[tile_idx + 1]] - swb_offset[hGrid->sfbWrap[tile_idx]];
468 855612 : stop = strt_cpy + tile_width;
469 :
470 855612 : if ( IGF_WHITENING_STRONG == hPrivateDataL->currWhiteningLevel[tile_idx] )
471 : {
472 173112 : tb = swb_offset[hGrid->sfbWrap[tile_idx]];
473 :
474 16585560 : for ( tb = swb_offset[hGrid->sfbWrap[tile_idx]]; tb < swb_offset[hGrid->sfbWrap[tile_idx + 1]]; tb++ )
475 : {
476 16412448 : igf_specL[tb] = own_random( hInfoL->nfSeed );
477 : }
478 : }
479 : else
480 : {
481 682500 : if ( IGF_WHITENING_MID == hPrivateDataL->currWhiteningLevel[tile_idx] )
482 : {
483 244134 : if ( hPrivateDataL->n_noise_bands )
484 : {
485 243048 : IGF_replaceTCXNoise_2_new( igf_specL, TCXNoiseL, strt_cpy, stop, hPrivateDataL->totalNoiseNrg, hPrivateDataL->n_noise_bands, hInfoL->nfSeed );
486 : }
487 244134 : sel_specL = igf_specL;
488 : }
489 : else
490 : {
491 438366 : if ( hPrivateDataL->n_noise_bands_off )
492 : {
493 429447 : IGF_replaceTCXNoise_2_new( src_specL, TCXNoiseL, strt_cpy, stop, hPrivateDataL->totalNoiseNrg_off, hPrivateDataL->n_noise_bands_off, hInfoL->nfSeed );
494 : }
495 438366 : sel_specL = src_specL;
496 : }
497 :
498 682500 : if ( IGF_WHITENING_MID == hPrivateDataL->currWhiteningLevel[tile_idx] )
499 : {
500 244134 : if ( hPrivateDataR->n_noise_bands )
501 : {
502 239661 : IGF_replaceTCXNoise_2_new( igf_specR, TCXNoiseR, strt_cpy, stop, hPrivateDataR->totalNoiseNrg, hPrivateDataR->n_noise_bands, hInfoR->nfSeed );
503 : }
504 244134 : sel_specR = igf_specR;
505 : }
506 : else
507 : {
508 438366 : if ( hPrivateDataR->n_noise_bands_off )
509 : {
510 416103 : IGF_replaceTCXNoise_2_new( src_specR, TCXNoiseR, strt_cpy, stop, hPrivateDataR->totalNoiseNrg_off, hPrivateDataR->n_noise_bands_off, hInfoR->nfSeed );
511 : }
512 438366 : sel_specR = src_specR;
513 : }
514 :
515 2560665 : for ( sfb = hGrid->sfbWrap[tile_idx]; sfb < hGrid->sfbWrap[tile_idx + 1]; sfb++ )
516 : {
517 58875819 : 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 56997654 : if ( coreMsMask[tb] == 0 )
524 : {
525 22982676 : if ( coreMsMask[strt_cpy] == 0 ) /* LR->LR */
526 : {
527 7045278 : igf_specL[tb] = sel_specL[strt_cpy];
528 : }
529 : else /* MS/DR -> LR */
530 : {
531 15937398 : igf_specL[tb] = ( sel_specL[strt_cpy] + sel_specR[strt_cpy] ) * c;
532 : }
533 : }
534 : else
535 : {
536 34014978 : if ( coreMsMask[strt_cpy] == 0 ) /* LR->MS/DR */
537 : {
538 862572 : igf_specL[tb] = ( sel_specL[strt_cpy] + sel_specR[strt_cpy] ) * c;
539 : }
540 : else /* MS/DR -> MS/DR */
541 : {
542 33152406 : igf_specL[tb] = sel_specL[strt_cpy];
543 : }
544 : }
545 56997654 : strt_cpy++;
546 : }
547 : }
548 : }
549 :
550 855612 : strt_cpy = hGrid->sbWrap[tile_idx];
551 :
552 855612 : if ( IGF_WHITENING_STRONG == hPrivateDataR->currWhiteningLevel[tile_idx] )
553 : {
554 163986 : tb = swb_offset[hGrid->sfbWrap[tile_idx]];
555 :
556 16879386 : for ( tb = swb_offset[hGrid->sfbWrap[tile_idx]]; tb < swb_offset[hGrid->sfbWrap[tile_idx + 1]]; tb++ )
557 : {
558 16715400 : igf_specR[tb] = own_random( hInfoR->nfSeed );
559 : }
560 : }
561 : else
562 : {
563 691626 : if ( hPrivateDataR->currWhiteningLevel[tile_idx] != hPrivateDataL->currWhiteningLevel[tile_idx] )
564 : {
565 180909 : if ( IGF_WHITENING_MID == hPrivateDataR->currWhiteningLevel[tile_idx] )
566 : {
567 93627 : if ( hPrivateDataL->n_noise_bands )
568 : {
569 93078 : IGF_replaceTCXNoise_2_new( igf_specL, TCXNoiseL, strt_cpy, stop, hPrivateDataL->totalNoiseNrg, hPrivateDataL->n_noise_bands, hInfoL->nfSeed );
570 : }
571 93627 : sel_specL = igf_specL;
572 : }
573 : else
574 : {
575 87282 : if ( hPrivateDataL->n_noise_bands_off )
576 : {
577 86688 : IGF_replaceTCXNoise_2_new( src_specL, TCXNoiseL, strt_cpy, stop, hPrivateDataL->totalNoiseNrg_off, hPrivateDataL->n_noise_bands_off, hInfoL->nfSeed );
578 : }
579 87282 : sel_specL = src_specL;
580 : }
581 :
582 180909 : if ( IGF_WHITENING_MID == hPrivateDataR->currWhiteningLevel[tile_idx] )
583 : {
584 93627 : if ( hPrivateDataR->n_noise_bands )
585 : {
586 92205 : IGF_replaceTCXNoise_2_new( igf_specR, TCXNoiseR, strt_cpy, stop, hPrivateDataR->totalNoiseNrg, hPrivateDataR->n_noise_bands, hInfoR->nfSeed );
587 : }
588 93627 : sel_specR = igf_specR;
589 : }
590 : else
591 : {
592 87282 : if ( hPrivateDataR->n_noise_bands_off )
593 : {
594 84984 : IGF_replaceTCXNoise_2_new( src_specR, TCXNoiseR, strt_cpy, stop, hPrivateDataR->totalNoiseNrg_off, hPrivateDataR->n_noise_bands_off, hInfoR->nfSeed );
595 : }
596 87282 : sel_specR = src_specR;
597 : }
598 : }
599 :
600 2605671 : for ( sfb = hGrid->sfbWrap[tile_idx]; sfb < hGrid->sfbWrap[tile_idx + 1]; sfb++ )
601 : {
602 58608747 : 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 56694702 : if ( coreMsMask[tb] == 0 )
609 : {
610 22716732 : if ( coreMsMask[strt_cpy] == 0 ) /* LR->LR */
611 : {
612 6995718 : igf_specR[tb] = sel_specR[strt_cpy];
613 : }
614 : else /* MS/DR -> LR */
615 : {
616 15721014 : igf_specR[tb] = ( sel_specL[strt_cpy] - sel_specR[strt_cpy] ) * c;
617 : }
618 : }
619 : else
620 : {
621 33977970 : if ( coreMsMask[strt_cpy] == 0 ) /* LR->MS/DR */
622 : {
623 857454 : igf_specR[tb] = ( sel_specL[strt_cpy] - sel_specR[strt_cpy] ) * c;
624 : }
625 : else /* MS/DR -> MS/DR */
626 : {
627 33120516 : igf_specR[tb] = sel_specR[strt_cpy];
628 : }
629 : }
630 56694702 : strt_cpy++;
631 : }
632 : }
633 : }
634 : }
635 :
636 267444 : return;
637 : }
638 :
639 :
640 : /*-------------------------------------------------------------------*
641 : * IGF_calc()
642 : *
643 : * calculates IGF energies
644 : *-------------------------------------------------------------------*/
645 :
646 1813608 : 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 1813608 : set_zero( tmp, N_MAX_TCX );
659 :
660 1813608 : hGrid = &hPrivateData->igfInfo.grid[igfGridIdx];
661 1813608 : igf_pN = hPrivateData->igf_pN;
662 1813608 : igf_sN = hPrivateData->igf_sN;
663 :
664 1813608 : IGF_getMDCTSquare( hGrid->startLine, hGrid->stopLine, spectrum, tmp );
665 1813608 : IGF_calcSfbEnergy( hGrid->startSfb, hGrid->stopSfb, hGrid->swb_offset, tmp, igf_sN );
666 1813608 : IGF_getMDCTSquare( hGrid->startLine, hGrid->stopLine, igf_spec, tmp );
667 1813608 : IGF_setLinesToZero( hGrid->startLine, hGrid->stopLine, spectrum, tmp );
668 1813608 : IGF_calcSfbEnergy( hGrid->startSfb, hGrid->stopSfb, hGrid->swb_offset, tmp, igf_pN );
669 :
670 1813608 : return;
671 : }
672 :
673 :
674 : /*-------------------------------------------------------------------*
675 : * IGF_appl()
676 : *
677 : * apply IGF
678 : *-------------------------------------------------------------------*/
679 :
680 1813608 : 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 1813608 : w0 = 0.201f;
711 1813608 : w1 = 0.389f;
712 1813608 : w2 = 0.410f;
713 1813608 : dE = 0.f;
714 :
715 :
716 : /* more inits */
717 1813608 : hGrid = &hPrivateData->igfInfo.grid[igfGridIdx];
718 1813608 : sN = hPrivateData->igf_sN;
719 1813608 : pN = hPrivateData->igf_pN;
720 1813608 : start_sfb = hGrid->startSfb;
721 1813608 : stop_sfb = hGrid->stopSfb;
722 1813608 : gFactor = hGrid->gFactor;
723 1813608 : fFactor = hGrid->fFactor;
724 1813608 : lFactor = hGrid->lFactor;
725 1813608 : 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 45340200 : for ( tb = hGrid->startLine - 24; tb < hGrid->startLine; tb++ )
734 : {
735 43526592 : dE += pSpectralData[tb] * pSpectralData[tb];
736 : }
737 1813608 : dE = (float) sqrt( dE / 24. );
738 :
739 1813608 : hopsize = 2;
740 1813608 : hopsize = ( hPrivateData->currWhiteningLevel[0] == IGF_WHITENING_OFF ) ? 4 : hopsize;
741 1813608 : hopsize = ( hPrivateData->currWhiteningLevel[0] == IGF_WHITENING_MID ) ? 2 : hopsize;
742 1813608 : hopsize = ( hPrivateData->currWhiteningLevel[0] == IGF_WHITENING_STRONG ) ? 1 : hopsize;
743 1813608 : hopsize = min( hopsize, hPrivateData->igfInfo.maxHopsize );
744 :
745 1813608 : if ( hPrivateData->restrict_hopsize )
746 : {
747 84858 : hopsize = min( hopsize, 2 );
748 : }
749 :
750 1813608 : 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 1813608 : 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 2118645 : for ( sfb = start_sfb; sfb < stop_sfb; sfb++ )
786 : {
787 1547358 : width = (float) ( swb_offset[sfb + 1] - swb_offset[sfb] );
788 :
789 1547358 : tmp = (float) hPrivateData->igf_curr[sfb];
790 1547358 : tmp = (float) pow( 2.0, 0.25 * tmp - 4.0 );
791 1547358 : tmp = tmp * tmp;
792 :
793 1547358 : sNlocal = sN[sfb];
794 1547358 : sNlocal /= width;
795 :
796 1547358 : tmp = (float) max( 0.001 * sNlocal, tmp - sNlocal );
797 1547358 : dN[sfb] = (float) sqrt( tmp );
798 : }
799 : }
800 :
801 1813608 : dS[start_sfb] = dN[start_sfb];
802 : /* first value with adaption to core energy: */
803 1813608 : if ( dE < dN[start_sfb] )
804 : {
805 1104366 : dS[start_sfb] = dN[start_sfb] + fFactor * ( dE - dN[start_sfb] );
806 : }
807 : /* last value with less energy: */
808 1813608 : dS[stop_sfb - 1] = lFactor * dN[stop_sfb - 1];
809 :
810 1813608 : 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 11504937 : for ( sfb = start_sfb + 1; sfb < stop_sfb - 1; sfb++ )
821 : {
822 10060500 : dS[sfb] = dN[sfb];
823 : }
824 : }
825 :
826 13316916 : for ( sfb = start_sfb; sfb < stop_sfb; sfb += hopsize )
827 : {
828 11503308 : E = 0.f;
829 11503308 : sum = 0;
830 28853070 : for ( tb = 0; tb < hopsize; tb++ )
831 : {
832 17349762 : idx1 = min( sfb + tb + 1, stop_sfb );
833 17349762 : idx = min( sfb + tb, stop_sfb );
834 17349762 : width = (float) ( swb_offset[idx1] - swb_offset[idx] );
835 17349762 : idx = min( sfb + tb, stop_sfb - 1 );
836 17349762 : val = dS[idx];
837 17349762 : E += val * val * width;
838 17349762 : sum += width;
839 : }
840 :
841 11503308 : dS[sfb] = (float) sqrt( ( E * hopsize ) / sum );
842 11503308 : dN[sfb] = gFactor * dS[sfb];
843 :
844 11503308 : width = (float) ( swb_offset[sfb + 1] - swb_offset[sfb] );
845 11503308 : dN[sfb] = dN[sfb] * dN[sfb] * width;
846 11503308 : gain[sfb] = 0.f;
847 :
848 11503308 : if ( pN[sfb] > 1.e-20f )
849 : {
850 11450496 : gain[sfb] = (float) sqrt( dN[sfb] / pN[sfb] );
851 : }
852 :
853 17272644 : 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 19086252 : for ( sfb = start_sfb; sfb < stop_sfb; sfb++ )
861 : {
862 :
863 17272644 : 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 541152276 : for ( tb = swb_offset[sfb]; tb < swb_offset[sfb + 1]; tb++ )
878 : {
879 523879632 : if ( pSpectralData[tb] == 0.f )
880 : {
881 523819542 : pSpectralData[tb] = igf_spec[tb] * gain[sfb];
882 523819542 : flag_sparse[tb - IGF_START_MN] = 1;
883 : }
884 : else
885 : {
886 60090 : virtualSpec[tb - IGF_START_MN] = igf_spec[tb] * gain[sfb];
887 60090 : flag_sparse[tb - IGF_START_MN] = 2;
888 : }
889 : }
890 : }
891 :
892 1813608 : return;
893 : }
894 :
895 :
896 : /*-------------------------------------------------------------------*
897 : * IGF_getWhiteSpectralData()
898 : *
899 : * spectral whitening
900 : *-------------------------------------------------------------------*/
901 :
902 938211 : 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 938211 : div = 0.0f;
918 :
919 385323618 : for ( i = start; i < stop - level; i++ )
920 : {
921 384385407 : ak = 1e-3f;
922 7686795144 : for ( j = i - level; j < i + level + 1; j++ )
923 : {
924 7302409737 : ak += in[j] * in[j];
925 : }
926 384385407 : ak /= (float) ( level * 2 + 1 );
927 :
928 :
929 384385407 : n = (int16_t) max( 0.f, ( log( ak ) * INV_LOG_2 ) ); /* INV_LOG_2 = 1 / (float)log(2.0f)) */
930 384385407 : n >>= 1; /* sqrt() */
931 384385407 : div = (float) ( pow( 2.0f, (float) ( 21 - n ) ) );
932 :
933 :
934 384385407 : out[i] = in[i] * div; /* same as shift */
935 : }
936 :
937 9380028 : for ( ; i < stop; i++ )
938 : {
939 8441817 : ak = 1e-3f;
940 :
941 126605394 : for ( j = i - level; j < stop; j++ )
942 : {
943 118163577 : ak += in[j] * in[j];
944 : }
945 8441817 : ak /= (float) ( stop - ( i - level ) );
946 :
947 :
948 8441817 : n = (int16_t) max( 0.f, ( log( ak ) * INV_LOG_2 ) ); /* INV_LOG_2 = 1 / (float)log(2.0f)) */
949 8441817 : n >>= 1; /* sqrt() */
950 8441817 : div = (float) ( pow( 2.0f, (float) ( 21 - n ) ) );
951 :
952 :
953 8441817 : out[i] = in[i] * div; /* same as shift */
954 : }
955 :
956 938211 : 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 1799412 : 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 1799412 : if ( hIGFDec != NULL )
1021 : {
1022 1799412 : hPrivateData = &hIGFDec->igfData;
1023 1799412 : hGrid = &hPrivateData->igfInfo.grid[igfGridIdx];
1024 1799412 : nT = hGrid->nTiles;
1025 1799412 : tmp = -1;
1026 :
1027 19793532 : for ( p = 0; p < IGF_MAX_TILES; p++ )
1028 : {
1029 17994120 : hPrivateData->currWhiteningLevel[p] = IGF_WHITENING_OFF;
1030 : }
1031 :
1032 1799412 : if ( isIndepFrame )
1033 : {
1034 1764666 : tmp = 0;
1035 : }
1036 : else
1037 : {
1038 34746 : tmp = get_next_indice( st, 1 );
1039 : }
1040 1799412 : if ( tmp == 1 )
1041 : {
1042 109464 : for ( p = 0; p < nT; p++ )
1043 : {
1044 76698 : hPrivateData->currWhiteningLevel[p] = hPrivateData->prevWhiteningLevel[p];
1045 : }
1046 : }
1047 : else
1048 : {
1049 1766646 : IGF_decode_whitening_level( st, hPrivateData, 0 );
1050 1766646 : 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 1544223 : tmp = get_next_indice( st, 1 );
1057 : }
1058 :
1059 1766646 : if ( tmp == 1 )
1060 : {
1061 3117633 : for ( p = 1; p < nT; p++ )
1062 : {
1063 1924941 : IGF_decode_whitening_level( st, hPrivateData, p );
1064 : }
1065 : }
1066 : else
1067 : {
1068 2798382 : for ( p = 1; p < nT; p++ )
1069 : {
1070 2224428 : hPrivateData->currWhiteningLevel[p] = hPrivateData->currWhiteningLevel[0];
1071 : }
1072 : }
1073 : }
1074 19793532 : for ( p = 0; p < IGF_MAX_TILES; p++ )
1075 : {
1076 17994120 : hPrivateData->prevWhiteningLevel[p] = hPrivateData->currWhiteningLevel[p];
1077 : }
1078 :
1079 : /* IGF_decode_temp_flattening_trigger()*/
1080 1799412 : hIGFDec->flatteningTrigger = get_next_indice( st, 1 );
1081 : }
1082 :
1083 1799412 : 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 1799412 : 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 1799412 : IGFAllZero = 1;
1107 :
1108 1799412 : if ( hIGFDec != NULL )
1109 : {
1110 1799412 : hPrivateData = &hIGFDec->igfData;
1111 1799412 : hGrid = &hPrivateData->igfInfo.grid[igfGridIdx];
1112 1799412 : m_igfSfbStart = hGrid->startSfb;
1113 1799412 : IGFAllZero = get_next_indice( st, 1 );
1114 :
1115 1799412 : if ( IGFAllZero == 0 )
1116 : {
1117 1798212 : mvs2s( hPrivateData->igf_curr, hPrivateData->igf_prev, hGrid->stopSfb );
1118 :
1119 1798212 : IGFSCFDecoderDecode( &hPrivateData->hArithSCFdec, st, &hPrivateData->igf_curr[m_igfSfbStart], igfGridIdx, isIndepFrame );
1120 : }
1121 : else
1122 : {
1123 1200 : IGFSCFDecoderReset( &hPrivateData->hArithSCFdec );
1124 :
1125 1200 : set_s( &hPrivateData->igf_curr[m_igfSfbStart], 0, hGrid->stopSfb - m_igfSfbStart );
1126 : }
1127 : }
1128 :
1129 1799412 : hIGFDec->infoIGFAllZero = IGFAllZero;
1130 :
1131 1799412 : return IGFAllZero;
1132 : }
1133 :
1134 :
1135 : /*-------------------------------------------------------------------*
1136 : * IGFDecApplyMono()
1137 : *
1138 : * apply the IGF decoder in mono
1139 : *-------------------------------------------------------------------*/
1140 :
1141 1279713 : 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 1279713 : set_zero( igf_spec, IGF_MAX_GRANULE_LEN );
1156 :
1157 : /* initialize variables */
1158 1279713 : if ( element_mode > EVS_MONO )
1159 : {
1160 1277775 : whiteningLevel = IGF_MID_WHITENING_LEVEL2;
1161 : }
1162 : else
1163 : {
1164 1938 : whiteningLevel = IGF_MID_WHITENING_LEVEL;
1165 : }
1166 :
1167 1279713 : nShift = igfGridIdx == IGF_GRID_LB_SHORT ? 2 : 1;
1168 1279713 : set_s( hIGFDec->flag_sparse, 0, ( N_MAX_TCX - IGF_START_MN ) / nShift );
1169 1279713 : set_f( hIGFDec->virtualSpec, 0.f, ( N_MAX_TCX - IGF_START_MN ) / nShift );
1170 :
1171 1279713 : hPrivateData = &hIGFDec->igfData;
1172 1279713 : hGrid = &hPrivateData->igfInfo.grid[igfGridIdx];
1173 1279713 : hPrivateData->totalNoiseNrg = 0.f;
1174 1279713 : hPrivateData->n_noise_bands = 0;
1175 1279713 : hPrivateData->totalNoiseNrg_off = 0.f;
1176 1279713 : hPrivateData->n_noise_bands_off = 0;
1177 1279713 : hPrivateData->restrict_hopsize = 0;
1178 :
1179 : /* concealment counter */
1180 1279713 : if ( bfi )
1181 : {
1182 13569 : hPrivateData->frameLossCounter++;
1183 : }
1184 : else
1185 : {
1186 1266144 : hPrivateData->frameLossCounter = 0;
1187 : }
1188 :
1189 : /* skip IGF processing if all IGF levels are zero */
1190 1279713 : if ( !hIGFDec->infoIGFAllZero )
1191 : {
1192 3573276 : for ( i = 0; i < hGrid->nTiles; i++ )
1193 : {
1194 2904636 : if ( hPrivateData->currWhiteningLevel[i] == IGF_WHITENING_MID )
1195 : {
1196 610080 : if ( element_mode == EVS_MONO || !bfi )
1197 : {
1198 605109 : 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 610080 : hPrivateData->n_noise_bands = IGF_replaceTCXNoise_1( igf_spec, hIGFDec->infoTCXNoise, hGrid->minSrcSubband, hGrid->startLine, &hPrivateData->totalNoiseNrg );
1206 610080 : break;
1207 : }
1208 : }
1209 :
1210 3344535 : for ( i = 0; i < hGrid->nTiles; i++ )
1211 : {
1212 2644119 : if ( hPrivateData->currWhiteningLevel[i] == IGF_WHITENING_OFF )
1213 : {
1214 578304 : hPrivateData->n_noise_bands_off = IGF_replaceTCXNoise_1( hPrivateData->pSpecFlat, hIGFDec->infoTCXNoise, hGrid->minSrcSubband, hGrid->startLine, &hPrivateData->totalNoiseNrg_off );
1215 578304 : break;
1216 : }
1217 : }
1218 :
1219 : /* apply IGF in three steps: */
1220 1278720 : IGF_prep( hPrivateData, igfGridIdx, hIGFDec->infoTCXNoise, igf_spec, hPrivateData->pSpecFlat, element_mode );
1221 1278720 : IGF_calc( hPrivateData, igfGridIdx, spectrum, igf_spec );
1222 1278720 : IGF_appl( hPrivateData, igfGridIdx, spectrum, igf_spec, hIGFDec->virtualSpec, hIGFDec->flag_sparse, 1 );
1223 : }
1224 :
1225 : /* reset TCX noise indicator vector */
1226 1279713 : nLinesToReset = igfGridIdx == IGF_GRID_LB_SHORT ? 2 : 1;
1227 1279713 : nLinesToReset = IGF_START_MX / nLinesToReset;
1228 1279713 : set_c( (int8_t *) ( hIGFDec->infoTCXNoise ), 0, nLinesToReset );
1229 :
1230 1279713 : return;
1231 : }
1232 :
1233 :
1234 : /*-------------------------------------------------------------------*
1235 : * IGFDecApplyStereo()
1236 : *
1237 : * apply the IGF decoder in stereo
1238 : *-------------------------------------------------------------------*/
1239 :
1240 267447 : 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 267447 : set_f( igf_specL, 0.f, IGF_MAX_GRANULE_LEN );
1258 267447 : set_f( igf_specR, 0.f, IGF_MAX_GRANULE_LEN );
1259 :
1260 : /* initialize variables */
1261 267447 : whiteningLevel = IGF_MID_WHITENING_LEVEL2;
1262 :
1263 267447 : nShift = igfGridIdx == IGF_GRID_LB_SHORT ? 2 : 1;
1264 267447 : set_s( hIGFDecL->flag_sparse, 0, ( N_MAX_TCX - IGF_START_MN ) / nShift );
1265 267447 : set_s( hIGFDecR->flag_sparse, 0, ( N_MAX_TCX - IGF_START_MN ) / nShift );
1266 267447 : set_f( hIGFDecL->virtualSpec, 0.f, ( N_MAX_TCX - IGF_START_MN ) / nShift );
1267 267447 : set_f( hIGFDecR->virtualSpec, 0.f, ( N_MAX_TCX - IGF_START_MN ) / nShift );
1268 :
1269 267447 : hPrivateDataL = &hIGFDecL->igfData;
1270 267447 : hGrid = &hPrivateDataL->igfInfo.grid[igfGridIdx];
1271 267447 : hPrivateDataL->totalNoiseNrg = 0.f;
1272 267447 : hPrivateDataL->n_noise_bands = 0;
1273 267447 : hPrivateDataL->totalNoiseNrg_off = 0.f;
1274 267447 : hPrivateDataL->n_noise_bands_off = 0;
1275 267447 : hPrivateDataL->restrict_hopsize = restrict_hopsize;
1276 :
1277 267447 : hPrivateDataR = &hIGFDecR->igfData;
1278 267447 : hPrivateDataR->totalNoiseNrg = 0.f;
1279 267447 : hPrivateDataR->n_noise_bands = 0;
1280 267447 : hPrivateDataR->totalNoiseNrg_off = 0.f;
1281 267447 : hPrivateDataR->n_noise_bands_off = 0;
1282 267447 : hPrivateDataR->restrict_hopsize = restrict_hopsize;
1283 :
1284 : /* concealment counter */
1285 267447 : if ( bfi )
1286 : {
1287 813 : hPrivateDataL->frameLossCounter++;
1288 813 : hPrivateDataR->frameLossCounter++;
1289 : }
1290 : else
1291 : {
1292 266634 : hPrivateDataL->frameLossCounter = 0;
1293 266634 : hPrivateDataR->frameLossCounter = 0;
1294 : }
1295 :
1296 : /* skip IGF processing if all IGF levels are zero */
1297 267447 : if ( !hIGFDecL->infoIGFAllZero || !hIGFDecR->infoIGFAllZero )
1298 : {
1299 689037 : for ( i = 0; i < hGrid->nTiles; i++ )
1300 : {
1301 588513 : if ( hPrivateDataL->currWhiteningLevel[i] == IGF_WHITENING_MID || hPrivateDataR->currWhiteningLevel[i] == IGF_WHITENING_MID )
1302 : {
1303 166920 : if ( !bfi )
1304 : {
1305 166551 : 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 166920 : hPrivateDataL->n_noise_bands = IGF_replaceTCXNoise_1( igf_specL, hIGFDecL->infoTCXNoise, hGrid->minSrcSubband, hGrid->startLine, &hPrivateDataL->totalNoiseNrg );
1313 :
1314 166920 : if ( !bfi )
1315 : {
1316 166551 : 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 166920 : hPrivateDataR->n_noise_bands = IGF_replaceTCXNoise_1( igf_specR, hIGFDecR->infoTCXNoise, hGrid->minSrcSubband, hGrid->startLine, &hPrivateDataR->totalNoiseNrg );
1324 :
1325 166920 : break;
1326 : }
1327 : }
1328 :
1329 556395 : for ( i = 0; i < hGrid->nTiles; i++ )
1330 : {
1331 441306 : if ( hPrivateDataL->currWhiteningLevel[i] == IGF_WHITENING_OFF || hPrivateDataR->currWhiteningLevel[i] == IGF_WHITENING_OFF )
1332 : {
1333 152355 : hPrivateDataL->n_noise_bands_off = IGF_replaceTCXNoise_1( hPrivateDataL->pSpecFlat, hIGFDecL->infoTCXNoise, hGrid->minSrcSubband, hGrid->startLine, &hPrivateDataL->totalNoiseNrg_off );
1334 :
1335 152355 : hPrivateDataR->n_noise_bands_off = IGF_replaceTCXNoise_1( hPrivateDataR->pSpecFlat, hIGFDecR->infoTCXNoise, hGrid->minSrcSubband, hGrid->startLine, &hPrivateDataR->totalNoiseNrg_off );
1336 152355 : break;
1337 : }
1338 : }
1339 :
1340 : /* apply IGF in three steps: */
1341 267444 : IGF_prepStereo( hPrivateDataL, hPrivateDataR, igfGridIdx, hIGFDecL->infoTCXNoise, hIGFDecR->infoTCXNoise, igf_specL, igf_specR, hPrivateDataL->pSpecFlat, hPrivateDataR->pSpecFlat, coreMsMask );
1342 :
1343 267444 : IGF_calc( hPrivateDataL, igfGridIdx, spectrumL, igf_specL );
1344 267444 : IGF_calc( hPrivateDataR, igfGridIdx, spectrumR, igf_specR );
1345 267444 : IGF_appl( hPrivateDataL, igfGridIdx, spectrumL, igf_specL, hIGFDecL->virtualSpec, hIGFDecL->flag_sparse, bfi_apply_damping );
1346 267444 : IGF_appl( hPrivateDataR, igfGridIdx, spectrumR, igf_specR, hIGFDecR->virtualSpec, hIGFDecR->flag_sparse, bfi_apply_damping );
1347 : }
1348 :
1349 : /* reset TCX noise indicator vector */
1350 267447 : nLinesToReset = ( igfGridIdx == IGF_GRID_LB_SHORT ) ? 2 : 1;
1351 267447 : nLinesToReset = IGF_START_MX / nLinesToReset;
1352 267447 : set_c( (int8_t *) ( hIGFDecL->infoTCXNoise ), 0, nLinesToReset );
1353 267447 : set_c( (int8_t *) ( hIGFDecR->infoTCXNoise ), 0, nLinesToReset );
1354 :
1355 267447 : 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 63417 : 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 63417 : hPrivateData = &hIGFDec->igfData;
1378 63417 : hIGFDec->isIGFActive = 0;
1379 :
1380 63417 : if ( IGFCommonFuncsIGFConfiguration( total_brate, bwidth, element_mode, &hPrivateData->igfInfo, rf_mode ) )
1381 : {
1382 63417 : IGFSCFDecoderOpen( &hPrivateData->hArithSCFdec, &hPrivateData->igfInfo, total_brate, bwidth, element_mode, rf_mode );
1383 :
1384 63417 : hIGFDec->infoIGFAllZero = 0;
1385 63417 : hIGFDec->isIGFActive = 1;
1386 63417 : hIGFDec->infoIGFStopLine = hPrivateData->igfInfo.grid[0].stopLine;
1387 63417 : hIGFDec->infoIGFStartLine = hPrivateData->igfInfo.grid[0].startLine;
1388 63417 : hIGFDec->infoIGFStopFreq = hPrivateData->igfInfo.grid[0].stopFrequency;
1389 63417 : hIGFDec->infoIGFStartFreq = hPrivateData->igfInfo.grid[0].startFrequency;
1390 :
1391 : /* no refinement if maxHopsize is 1 */
1392 63417 : 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 63417 : hIGFDec->flag_sparse = &hIGFDec->flag_sparseBuf[0];
1411 63417 : hIGFDec->infoTCXNoise = &hIGFDec->infoTCXNoiseBuf[0];
1412 63417 : hIGFDec->virtualSpec = &hIGFDec->virtualSpecBuf[0];
1413 63417 : hIGFDec->igfData.pSpecFlat = &hIGFDec->igfData.pSpecFlatBuf[0];
1414 63417 : hIGFDec->igfData.igfInfo.nfSeed = &hIGFDec->igfData.igfInfo.nfSeedBuf[0];
1415 :
1416 63417 : return;
1417 : }
1418 :
1419 :
1420 : /*-------------------------------------------------------------------*
1421 : * IGFDecUpdateInfo()
1422 : *
1423 : * updates the start/stop frequency of IGF according to igfGridIdx
1424 : *-------------------------------------------------------------------*/
1425 :
1426 6315684 : 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 6315684 : hIGFDec->flag_sparse = &hIGFDec->flag_sparseBuf[0];
1436 6315684 : hIGFDec->infoTCXNoise = &hIGFDec->infoTCXNoiseBuf[0];
1437 6315684 : hIGFDec->virtualSpec = &hIGFDec->virtualSpecBuf[0];
1438 6315684 : hIGFDec->igfData.pSpecFlat = &hIGFDec->igfData.pSpecFlatBuf[0];
1439 6315684 : hIGFDec->igfData.igfInfo.nfSeed = &hIGFDec->igfData.igfInfo.nfSeedBuf[0];
1440 :
1441 6315684 : if ( igfGridIdx == IGF_GRID_LB_SHORT )
1442 : {
1443 291906 : IGFDecRestoreTCX10SubFrameData( hIGFDec, subFrameIdx );
1444 : }
1445 :
1446 6315684 : hPrivateData = &hIGFDec->igfData;
1447 6315684 : if ( hIGFDec->isIGFActive )
1448 : {
1449 6315684 : hGrid = &hPrivateData->igfInfo.grid[igfGridIdx];
1450 6315684 : hIGFDec->infoIGFStartFreq = hGrid->startFrequency;
1451 6315684 : hIGFDec->infoIGFStopFreq = hGrid->stopFrequency;
1452 6315684 : hIGFDec->infoIGFStartLine = hGrid->startLine;
1453 6315684 : hIGFDec->infoIGFStopLine = hGrid->stopLine;
1454 : }
1455 :
1456 6315684 : 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 1802799 : 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 1802799 : if ( hIGFDec )
1498 : {
1499 1802799 : hPrivateData = &hIGFDec->igfData;
1500 1802799 : hGrid = &hPrivateData->igfInfo.grid[igfGridIdx];
1501 :
1502 730014408 : for ( i = hGrid->minSrcSubband - IGF_MID_WHITENING_LEVEL2; i < hGrid->startLine; i++ )
1503 : {
1504 728211609 : hPrivateData->pSpecFlat[i] = pSpectrumFlat[i] * 1024.f;
1505 : }
1506 : }
1507 :
1508 1802799 : return;
1509 : }
1510 :
1511 :
1512 : /*-------------------------------------------------------------------*
1513 : * IGFDecStoreTCX10SubFrameData()
1514 : *
1515 : * store the IGF bitstream information for TCX10 subframes
1516 : *-------------------------------------------------------------------*/
1517 :
1518 69492 : 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 69492 : hPrivateData = &hIGFDec->igfData;
1526 :
1527 : /* store igf energies for subframe*/
1528 69492 : mvs2s( hPrivateData->igf_curr, hPrivateData->igf_curr_subframe[subFrameIdx][0], IGF_MAX_SFB );
1529 69492 : mvs2s( hPrivateData->igf_prev, hPrivateData->igf_prev_subframe[subFrameIdx], IGF_MAX_SFB );
1530 :
1531 : /* store spectral whitening information for current subframe */
1532 69492 : mvs2s( hPrivateData->currWhiteningLevel, hPrivateData->currWhiteningLevel_subframe[subFrameIdx], IGF_MAX_TILES );
1533 69492 : mvs2s( hPrivateData->prevWhiteningLevel, hPrivateData->prevWhiteningLevel_subframe[subFrameIdx], IGF_MAX_TILES );
1534 :
1535 : /* store flattening trigger for current subframe */
1536 69492 : hPrivateData->igf_flatteningTrigger_subframe[subFrameIdx] = hIGFDec->flatteningTrigger;
1537 :
1538 69492 : return;
1539 : }
1540 :
1541 :
1542 : /*-------------------------------------------------------------------*
1543 : * IGFDecRestoreTCX10SubFrameData()
1544 : *
1545 : * restore the IGF bitstream information for TCX10 subframes
1546 : *-------------------------------------------------------------------*/
1547 :
1548 304314 : 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 304314 : hPrivateData = &hIGFDec->igfData;
1556 :
1557 : /* store igf energies for subframe*/
1558 304314 : mvs2s( hPrivateData->igf_curr_subframe[subFrameIdx][0], hPrivateData->igf_curr, IGF_MAX_SFB );
1559 304314 : mvs2s( hPrivateData->igf_prev_subframe[subFrameIdx], hPrivateData->igf_prev, IGF_MAX_SFB );
1560 :
1561 : /* store spectral whitening information for current subframe */
1562 304314 : mvs2s( hPrivateData->currWhiteningLevel_subframe[subFrameIdx], hPrivateData->currWhiteningLevel, IGF_MAX_TILES );
1563 304314 : mvs2s( hPrivateData->prevWhiteningLevel_subframe[subFrameIdx], hPrivateData->prevWhiteningLevel, IGF_MAX_TILES );
1564 :
1565 : /* restore flattening trigger for current subframe */
1566 304314 : hIGFDec->flatteningTrigger = hPrivateData->igf_flatteningTrigger_subframe[subFrameIdx];
1567 304314 : hIGFDec->flag_sparse = &hIGFDec->flag_sparseBuf[subFrameIdx * ( N_MAX_TCX - IGF_START_MN ) / 2];
1568 304314 : hIGFDec->infoTCXNoise = &hIGFDec->infoTCXNoiseBuf[subFrameIdx * ( IGF_START_MX ) / 2];
1569 304314 : hIGFDec->virtualSpec = &hIGFDec->virtualSpecBuf[subFrameIdx * ( N_MAX_TCX - IGF_START_MN ) / 2];
1570 304314 : hIGFDec->igfData.pSpecFlat = &hIGFDec->igfData.pSpecFlatBuf[subFrameIdx * IGF_START_MX / 2];
1571 304314 : hIGFDec->igfData.igfInfo.nfSeed = &hIGFDec->igfData.igfInfo.nfSeedBuf[subFrameIdx];
1572 :
1573 304314 : return;
1574 : }
1575 :
1576 : /*-----------------------------------------------------------------------*
1577 : * init_igf_dec()
1578 : *
1579 : * Initialize IGF decoder parameters
1580 : *-----------------------------------------------------------------------*/
1581 :
1582 28422 : void init_igf_dec(
1583 : IGF_DEC_INSTANCE_HANDLE hIGFDec /* i/o: IGF decoder handle */
1584 : )
1585 : {
1586 28422 : set_c( (int8_t *) ( hIGFDec->infoTCXNoiseBuf ), 0, IGF_START_MX );
1587 28422 : set_f( hIGFDec->igfData.pSpecFlatBuf, 0, IGF_START_MX );
1588 28422 : hIGFDec->igfData.igfInfo.nfSeedBuf[0] = 9733;
1589 28422 : hIGFDec->igfData.igfInfo.nfSeedBuf[1] = 9733;
1590 28422 : hIGFDec->igfData.igfInfo.nfSeed = &hIGFDec->igfData.igfInfo.nfSeedBuf[0];
1591 28422 : hIGFDec->igfData.pSpecFlat = &hIGFDec->igfData.pSpecFlatBuf[0];
1592 28422 : hIGFDec->flag_sparse = &hIGFDec->flag_sparseBuf[0];
1593 28422 : hIGFDec->infoTCXNoise = &hIGFDec->infoTCXNoiseBuf[0];
1594 28422 : hIGFDec->virtualSpec = &hIGFDec->virtualSpecBuf[0];
1595 :
1596 28422 : return;
1597 : }
1598 :
1599 :
1600 : /*-----------------------------------------------------------------------*
1601 : * get_igf_startline()
1602 : *
1603 : *
1604 : *-----------------------------------------------------------------------*/
1605 :
1606 : /*! r: IGF start line */
1607 4520154 : 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 4520154 : 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 2912301 : igf_startline = min( st->hIGFDec->infoIGFStartLine, L_frameTCX );
1631 : }
1632 :
1633 4520154 : return igf_startline;
1634 : }
|