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