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