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 : #include "rom_com.h"
41 : #include "prot_fx.h"
42 : #include "wmc_auto.h"
43 : #include "ivas_prot_fx.h"
44 :
45 : #define FSCALE_DENOM_BY_12800_Q15 1311
46 : /*-------------------------------------------------------------------*
47 : * is_EVS_bitrate()
48 : *
49 : * check if the bitrate is EVS supported active bitrate
50 : *-------------------------------------------------------------------*/
51 :
52 : /*! r: flag indicating a valid bitrate */
53 0 : Word16 is_EVS_bitrate(
54 : const Word32 ivas_total_brate, /* i : IVAS total bitrate Q0*/
55 : Word16 *Opt_AMR_WB /* i : AMR-WB IO flag Q0*/
56 : )
57 : {
58 : Word16 j;
59 :
60 0 : j = 0;
61 0 : move16();
62 0 : WHILE( LT_16( j, SIZE_BRATE_TBL ) && NE_32( ivas_total_brate, brate_tbl[j] ) )
63 : {
64 0 : test();
65 0 : j = add( j, 1 );
66 : }
67 :
68 : /* AMR-WB IO mode/EVS primary mode determination */
69 0 : IF( GE_16( j, SIZE_BRATE_TBL ) )
70 : {
71 0 : SWITCH( ivas_total_brate )
72 : {
73 0 : case ACELP_6k60:
74 : case ACELP_8k85:
75 : case ACELP_12k65:
76 : case ACELP_14k25:
77 : case ACELP_15k85:
78 : case ACELP_18k25:
79 : case ACELP_19k85:
80 : case ACELP_23k05:
81 : case ACELP_23k85:
82 0 : BREAK;
83 0 : default:
84 : {
85 0 : return 0;
86 : }
87 : }
88 :
89 0 : *Opt_AMR_WB = 1;
90 0 : move16();
91 : }
92 : ELSE
93 : {
94 0 : *Opt_AMR_WB = 0;
95 0 : move16();
96 : }
97 :
98 0 : return 1;
99 : }
100 :
101 :
102 : /*-------------------------------------------------------------------*
103 : * get_codec_mode()
104 : *
105 : * Get codec_mode (MODE1 or MODE2)
106 : *-------------------------------------------------------------------*/
107 :
108 : /*! r: codec mode */
109 3100 : Word16 get_codec_mode(
110 : const Word32 total_brate /* i : total bitrate Q0*/
111 : )
112 : {
113 : Word16 codec_mode;
114 3100 : codec_mode = -1;
115 3100 : move16();
116 :
117 3100 : SWITCH( total_brate )
118 : {
119 0 : case 5900:
120 0 : codec_mode = MODE1;
121 0 : move16();
122 0 : BREAK;
123 0 : case 7200:
124 0 : codec_mode = MODE1;
125 0 : move16();
126 0 : BREAK;
127 0 : case 8000:
128 0 : codec_mode = MODE1;
129 0 : move16();
130 0 : BREAK;
131 0 : case 9600:
132 0 : codec_mode = MODE2;
133 0 : move16();
134 0 : BREAK;
135 1050 : case 13200:
136 1050 : codec_mode = MODE1;
137 1050 : move16();
138 1050 : BREAK;
139 0 : case 16400:
140 0 : codec_mode = MODE2;
141 0 : move16();
142 0 : BREAK;
143 1050 : case 24400:
144 1050 : codec_mode = MODE2;
145 1050 : move16();
146 1050 : BREAK;
147 0 : case 32000:
148 0 : codec_mode = MODE1;
149 0 : move16();
150 0 : BREAK;
151 0 : case 48000:
152 0 : codec_mode = MODE2;
153 0 : move16();
154 0 : BREAK;
155 1000 : case 64000:
156 1000 : codec_mode = MODE1;
157 1000 : move16();
158 1000 : BREAK;
159 0 : case 96000:
160 0 : codec_mode = MODE2;
161 0 : move16();
162 0 : BREAK;
163 0 : case 128000:
164 0 : codec_mode = MODE2;
165 0 : move16();
166 0 : BREAK;
167 : }
168 :
169 3100 : return codec_mode; /*Q0*/
170 : }
171 :
172 :
173 : /*-------------------------------------------------------------------*
174 : * getTcxonly_ivas()
175 : *
176 : *
177 : *-------------------------------------------------------------------*/
178 :
179 0 : Word16 getTcxonly_ivas_fx(
180 : const Word16 element_mode, /* i : IVAS element mode Q0*/
181 : const Word32 total_brate, /* i : total bitrate Q0*/
182 : const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) Q0*/
183 : const Word16 is_ism_format /* i : flag indicating ISM format Q0*/
184 : )
185 : {
186 0 : Word16 tcxonly = 0;
187 0 : move16();
188 : Word32 temp_flag;
189 0 : if ( MCT_flag )
190 : {
191 0 : temp_flag = IVAS_32k;
192 0 : move32();
193 : }
194 : else
195 : {
196 0 : temp_flag = IVAS_48k;
197 0 : move32();
198 : }
199 :
200 0 : SWITCH( element_mode )
201 : {
202 0 : case EVS_MONO:
203 0 : if ( GT_32( total_brate, ACELP_32k ) )
204 : {
205 0 : tcxonly = 1;
206 0 : move16();
207 : }
208 0 : BREAK;
209 0 : case IVAS_SCE:
210 0 : if ( is_ism_format )
211 : {
212 0 : if ( GT_32( total_brate, MAX_ACELP_BRATE_ISM ) )
213 : {
214 0 : tcxonly = 1;
215 0 : move16();
216 : }
217 : }
218 : else
219 : {
220 0 : if ( GT_32( total_brate, MAX_ACELP_BRATE ) )
221 : {
222 0 : tcxonly = 1;
223 0 : move16();
224 : }
225 : }
226 0 : BREAK;
227 :
228 0 : case IVAS_CPE_DFT:
229 : case IVAS_CPE_TD:
230 0 : if ( GT_32( total_brate, MAX_ACELP_BRATE ) )
231 : {
232 0 : tcxonly = 1;
233 0 : move16();
234 : }
235 0 : BREAK;
236 0 : case IVAS_CPE_MDCT:
237 0 : if ( GE_32( total_brate, temp_flag ) )
238 : {
239 0 : tcxonly = 1;
240 0 : move16();
241 : }
242 0 : BREAK;
243 : }
244 :
245 0 : return tcxonly; /*Q0*/
246 : }
247 :
248 41 : Word16 getTcxonly(
249 : const Word32 total_brate /* i : total bitrate */
250 : )
251 : {
252 :
253 : Word16 tcxonly;
254 41 : tcxonly = 0;
255 41 : move16();
256 41 : if ( GT_32( total_brate, 32000 ) )
257 : {
258 0 : tcxonly = 1;
259 0 : move16();
260 : }
261 41 : return tcxonly; /*Q0*/
262 : }
263 :
264 236592 : Word16 getTcxonly_fx(
265 : const Word16 element_mode, /* i : IVAS element mode Q0*/
266 : const Word32 total_brate, /* i : total bitrate Q0*/
267 : const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) Q0*/
268 : const Word16 is_ism_format /* i : flag indicating ISM format Q0*/
269 : )
270 : {
271 : Word16 tcxonly;
272 236592 : tcxonly = 0;
273 236592 : move16();
274 :
275 236592 : SWITCH( element_mode )
276 : {
277 0 : case EVS_MONO:
278 0 : if ( GT_32( total_brate, ACELP_32k ) )
279 : {
280 0 : tcxonly = 1;
281 0 : move16();
282 : }
283 0 : BREAK;
284 215042 : case IVAS_SCE:
285 215042 : IF( is_ism_format )
286 : {
287 177496 : if ( GT_32( total_brate, MAX_ACELP_BRATE_ISM ) )
288 : {
289 97850 : tcxonly = 1;
290 97850 : move16();
291 : }
292 : }
293 : ELSE
294 : {
295 37546 : if ( GT_32( total_brate, MAX_ACELP_BRATE ) )
296 : {
297 5891 : tcxonly = 1;
298 5891 : move16();
299 : }
300 : }
301 215042 : BREAK;
302 :
303 1658 : case IVAS_CPE_DFT:
304 : case IVAS_CPE_TD:
305 1658 : if ( GT_32( total_brate, MAX_ACELP_BRATE ) )
306 : {
307 0 : tcxonly = 1;
308 0 : move16();
309 : }
310 1658 : BREAK;
311 18366 : case IVAS_CPE_MDCT:
312 18366 : IF( MCT_flag )
313 : {
314 :
315 8346 : if ( GE_32( total_brate, IVAS_32k ) )
316 : {
317 8346 : tcxonly = 1;
318 8346 : move16();
319 : }
320 : }
321 : ELSE
322 : {
323 10020 : if ( GE_32( total_brate, IVAS_48k ) )
324 : {
325 4638 : tcxonly = 1;
326 4638 : move16();
327 : }
328 : }
329 18366 : BREAK;
330 : }
331 :
332 236592 : return tcxonly; /*Q0*/
333 : }
334 :
335 : /*-------------------------------------------------------------------*
336 : * getCtxHm()
337 : *
338 : *
339 : *-------------------------------------------------------------------*/
340 :
341 924488 : Word16 getCtxHm(
342 : const Word16 element_mode, /* i : IVAS element mode Q0*/
343 : const Word32 total_brate, /* i : total bitrate Q0*/
344 : const Word16 rf_flag /* i : flag to signal the RF mode Q0*/
345 : )
346 : {
347 : Word16 ctx_hm;
348 :
349 924488 : ctx_hm = 0;
350 924488 : move16();
351 924488 : test();
352 924488 : test();
353 924488 : test();
354 924488 : test();
355 924488 : test();
356 924488 : test();
357 924488 : test();
358 924488 : test();
359 924488 : test();
360 924488 : if ( ( ( LE_16( element_mode, IVAS_SCE ) && GT_32( total_brate, LPC_SHAPED_ARI_MAX_RATE ) ) || ( GT_16( element_mode, IVAS_SCE ) && GT_32( total_brate, LPC_SHAPED_ARI_MAX_RATE_CPE ) ) ) && !rf_flag && ( ( LE_32( total_brate, IVAS_64k ) && NE_16( element_mode, IVAS_CPE_DFT ) ) || ( LT_32( total_brate, 24400 ) && EQ_16( element_mode, IVAS_CPE_DFT ) ) ) && NE_16( element_mode, IVAS_CPE_MDCT ) )
361 : {
362 184500 : ctx_hm = 1;
363 184500 : move16();
364 : }
365 :
366 924488 : return ctx_hm; /*Q0*/
367 : }
368 :
369 : /*-------------------------------------------------------------------*
370 : * getResq()
371 : *
372 : *
373 : *-------------------------------------------------------------------*/
374 :
375 924488 : Word16 getResq(
376 : const Word32 total_brate /* i : total bitrate Q0*/
377 : )
378 : {
379 : Word16 resq;
380 :
381 924488 : resq = 0;
382 924488 : move16();
383 924488 : if ( LE_32( total_brate, IVAS_64k ) )
384 : {
385 406066 : resq = 1;
386 406066 : move16();
387 : }
388 :
389 924488 : return resq; /*Q0*/
390 : }
391 :
392 : /*-------------------------------------------------------------------*
393 : * getTnsAllowed()
394 : *
395 : *
396 : *-------------------------------------------------------------------*/
397 :
398 955843 : Word16 getTnsAllowed(
399 : const Word32 total_brate, /* i : total bitrate Q0*/
400 : const Word16 igf, /* i : flag indicating IGF activity Q0*/
401 : const Word16 element_mode /* i : IVAS element mode Q0*/
402 : )
403 : {
404 : Word16 tnsAllowed;
405 :
406 955843 : tnsAllowed = 0;
407 955843 : move16();
408 955843 : IF( igf != 0 )
409 : {
410 645438 : test();
411 645438 : test();
412 645438 : if ( GT_32( total_brate, HQ_16k40 ) || ( GT_32( total_brate, HQ_13k20 ) && EQ_16( element_mode, IVAS_CPE_DFT ) ) )
413 : {
414 576711 : tnsAllowed = 1;
415 576711 : move16();
416 : }
417 : }
418 : ELSE
419 : {
420 310405 : if ( GT_32( total_brate, HQ_32k ) )
421 : {
422 290616 : tnsAllowed = 1;
423 290616 : move16();
424 : }
425 : }
426 :
427 955843 : return tnsAllowed; /*Q0*/
428 : }
429 :
430 : /*-------------------------------------------------------------------*
431 : * getRestrictedMode()
432 : *
433 : *
434 : *-------------------------------------------------------------------*/
435 :
436 0 : Word16 getRestrictedMode(
437 : const Word16 element_mode, /* i : IVAS element mode Q0*/
438 : const Word32 total_brate, /* i : total bitrate Q0*/
439 : const Word16 Opt_AMR_WB /* i : flag indicating AMR-WB IO mode Q0*/
440 : )
441 : {
442 : Word16 restrictedMode;
443 0 : restrictedMode = 3;
444 0 : move16();
445 :
446 0 : test();
447 0 : test();
448 0 : test();
449 0 : test();
450 0 : IF( !Opt_AMR_WB && ( GT_32( total_brate, HQ_32k ) && NE_16( element_mode, IVAS_SCE ) ) )
451 : {
452 0 : restrictedMode = 6;
453 0 : move16();
454 : }
455 0 : ELSE IF( !Opt_AMR_WB && ( GT_32( total_brate, HQ_48k ) && EQ_16( element_mode, IVAS_SCE ) ) )
456 : {
457 0 : restrictedMode = 6;
458 0 : move16();
459 : }
460 0 : ELSE IF( Opt_AMR_WB )
461 : {
462 0 : restrictedMode = 1;
463 0 : move16();
464 : }
465 :
466 0 : return restrictedMode; /*Q0*/
467 : }
468 :
469 : /*-------------------------------------------------------------------*
470 : * getMdctWindowLength()
471 : *
472 : *
473 : *-------------------------------------------------------------------*/
474 52126 : Word16 getMdctWindowLength_fx(
475 : const Word16 fscale /*Q0*/ )
476 : {
477 : Word16 mdctWindowLength;
478 52126 : mdctWindowLength = extract_l( L_shr( L_mult0( L_LOOK_12k8, fscale ), LD_FSCALE_DENOM ) );
479 :
480 52126 : return mdctWindowLength; /*Q0*/
481 : }
482 :
483 : /*-------------------------------------------------------------------*
484 : * sr2fscale()
485 : *
486 : *
487 : *-------------------------------------------------------------------*/
488 2053044 : Word16 sr2fscale_fx(
489 : const Word32 sr_core /* i : internal sampling rate Q0*/
490 : )
491 : {
492 2053044 : return extract_l( Mpy_32_16_1( sr_core, FSCALE_DENOM_BY_12800_Q15 ) ); /*Q0*/
493 : }
494 :
495 52316 : Word16 sr2fscale(
496 : const Word32 sr_core /* i : internal sampling rate */
497 : )
498 : {
499 :
500 52316 : return (Word16) ( ( FSCALE_DENOM * sr_core ) / 12800 );
501 : }
502 :
503 953297 : Word32 getCoreSamplerateMode2(
504 : const Word16 element_mode, /* i : IVAS element mode Q0*/
505 : const Word32 total_brate, /* i : total bitrate Q0*/
506 : const Word16 bwidth, /* i : audio bandwidth Q0*/
507 : const Word16 flag_ACELP16k, /* i : ACELP@16kHz flag Q0*/
508 : const Word16 rf_mode, /* i : flag to signal the RF mode Q0*/
509 : const IVAS_FORMAT is_ism_format /* i : flag indicating ISM format Q0*/
510 : )
511 : {
512 :
513 : Word32 sr_core;
514 : Word16 bwd_swb_or_fb_flag;
515 953297 : sr_core = -1; /* to suppress MSVC warning */
516 953297 : move32();
517 :
518 953297 : bwd_swb_or_fb_flag = s_or( (Word16) EQ_16( bwidth, SWB ), (Word16) EQ_16( bwidth, FB ) );
519 953297 : test();
520 953297 : test();
521 953297 : test();
522 953297 : test();
523 953297 : test();
524 953297 : test();
525 953297 : test();
526 953297 : test();
527 953297 : test();
528 953297 : test();
529 953297 : test();
530 953297 : test();
531 953297 : test();
532 953297 : test();
533 953297 : test();
534 953297 : test();
535 953297 : test();
536 953297 : test();
537 953297 : test();
538 953297 : test();
539 953297 : test();
540 953297 : test();
541 953297 : test();
542 953297 : IF( EQ_16( bwidth, NB ) )
543 : {
544 8160 : sr_core = INT_FS_12k8;
545 8160 : move32();
546 : }
547 945137 : ELSE IF( EQ_16( element_mode, EVS_MONO ) && ( L_and( EQ_32( bwidth, WB ), LT_32( total_brate, ACELP_13k20 ) ) ||
548 : L_and( EQ_32( bwidth, SWB ), LE_32( total_brate, ACELP_13k20 ) ) || EQ_16( rf_mode, 1 ) ) )
549 : {
550 48 : sr_core = INT_FS_12k8;
551 48 : move32();
552 : }
553 945089 : ELSE IF( GT_16( element_mode, EVS_MONO ) && flag_ACELP16k == 0 )
554 : {
555 53774 : sr_core = INT_FS_12k8;
556 53774 : move32();
557 : }
558 891315 : ELSE IF( EQ_32( bwidth, WB ) || ( ( LE_32( total_brate, ACELP_32k ) ) && ( ( EQ_32( bwidth, SWB ) ) || ( EQ_32( bwidth, FB ) ) ) ) )
559 : {
560 139269 : sr_core = INT_FS_16k;
561 139269 : move32();
562 : }
563 752046 : ELSE IF( bwd_swb_or_fb_flag && LE_32( total_brate, MAX_ACELP_BRATE ) && EQ_16( element_mode, IVAS_SCE ) && !is_ism_format )
564 : {
565 512 : sr_core = INT_FS_16k;
566 512 : move32();
567 : }
568 751534 : ELSE IF( bwd_swb_or_fb_flag && LE_32( total_brate, MAX_ACELP_BRATE_ISM ) && EQ_16( element_mode, IVAS_SCE ) && is_ism_format )
569 : {
570 7793 : sr_core = INT_FS_16k;
571 7793 : move32();
572 : }
573 743741 : ELSE IF( bwd_swb_or_fb_flag && LE_32( total_brate, MAX_ACELP_BRATE ) && EQ_16( element_mode, IVAS_SCE ) && is_ism_format )
574 : {
575 8076 : sr_core = 25600;
576 8076 : move32();
577 : }
578 735665 : ELSE IF( ( EQ_16( element_mode, EVS_MONO ) && ( bwd_swb_or_fb_flag && LE_32( total_brate, HQ_64k ) ) ) || ( GT_16( element_mode, IVAS_SCE ) && ( ( EQ_16( bwidth, SWB ) && LE_32( total_brate, IVAS_96k ) ) || ( EQ_16( bwidth, FB ) && LE_32( total_brate, IVAS_96k ) ) ) ) )
579 : {
580 288910 : sr_core = 25600;
581 288910 : move32();
582 : }
583 446755 : ELSE IF( bwd_swb_or_fb_flag )
584 : {
585 446755 : sr_core = 32000;
586 446755 : move32();
587 : }
588 : ELSE
589 : {
590 0 : assert( 0 );
591 : }
592 :
593 953297 : return sr_core; /*Q0*/
594 : }
595 :
596 57457 : Word16 getTcxBandwidth(
597 : const Word16 bwidth /* i : audio bandwidth Q0*/
598 : )
599 : {
600 :
601 : Word16 tcxBandwidth;
602 :
603 57457 : tcxBandwidth = 16384 /*0.5f Q15*/;
604 57457 : move16();
605 57457 : if ( EQ_16( bwidth, NB ) )
606 : {
607 10837 : tcxBandwidth = 10240 /*0.3125f Q15*/;
608 10837 : move16();
609 : }
610 :
611 57457 : return tcxBandwidth; /*Q15*/
612 : }
613 :
614 :
615 923837 : Word16 getIgfPresent_fx(
616 : const Word16 element_mode, /* i : IVAS element mode Q0*/
617 : const Word32 total_brate, /* i : total bitrate Q0*/
618 : const Word16 bwidth, /* i : audio bandwidth Q0*/
619 : const Word16 rf_mode /* i : flag to signal the RF mode Q0*/
620 : )
621 : {
622 : Word16 igfPresent;
623 923837 : igfPresent = 0;
624 923837 : move16();
625 :
626 923837 : IF( EQ_16( bwidth, SWB ) )
627 : {
628 247970 : SWITCH( element_mode )
629 : {
630 58076 : case EVS_MONO:
631 : case IVAS_SCE:
632 58076 : if ( LE_32( total_brate, HQ_64k ) )
633 : {
634 56793 : igfPresent = 1;
635 56793 : move16();
636 : }
637 58076 : BREAK;
638 9426 : case IVAS_CPE_DFT:
639 : case IVAS_CPE_TD:
640 9426 : if ( LE_32( total_brate, HQ_48k ) )
641 : {
642 9426 : igfPresent = 1;
643 9426 : move16();
644 : }
645 9426 : BREAK;
646 180468 : case IVAS_CPE_MDCT:
647 180468 : if ( LE_32( total_brate, IVAS_96k ) )
648 : {
649 112823 : igfPresent = 1;
650 112823 : move16();
651 : }
652 180468 : BREAK;
653 : }
654 247970 : }
655 675867 : ELSE IF( EQ_16( bwidth, FB ) )
656 : {
657 600385 : SWITCH( element_mode )
658 : {
659 148674 : case EVS_MONO:
660 : case IVAS_SCE:
661 148674 : if ( LE_32( total_brate, IVAS_128k ) )
662 : {
663 147919 : igfPresent = 1;
664 147919 : move16();
665 : }
666 148674 : BREAK;
667 3193 : case IVAS_CPE_DFT:
668 : case IVAS_CPE_TD:
669 3193 : if ( LE_32( total_brate, IVAS_48k ) )
670 : {
671 3193 : igfPresent = 1;
672 3193 : move16();
673 : }
674 3193 : BREAK;
675 448518 : case IVAS_CPE_MDCT:
676 448518 : if ( LE_32( total_brate, IVAS_128k ) )
677 : {
678 296455 : igfPresent = 1;
679 296455 : move16();
680 : }
681 448518 : BREAK;
682 : }
683 600385 : }
684 75482 : ELSE IF( EQ_16( bwidth, WB ) )
685 : {
686 75399 : SWITCH( element_mode )
687 : {
688 7277 : case EVS_MONO:
689 : case IVAS_SCE:
690 7277 : if ( LE_32( total_brate, ACELP_9k60 ) )
691 : {
692 118 : igfPresent = 1;
693 118 : move16();
694 : }
695 7277 : BREAK;
696 68122 : case IVAS_CPE_DFT:
697 : case IVAS_CPE_TD:
698 : case IVAS_CPE_MDCT:
699 68122 : if ( LE_32( total_brate, ACELP_13k20 ) )
700 : {
701 1370 : igfPresent = 1;
702 1370 : move16();
703 : }
704 68122 : BREAK;
705 : }
706 83 : }
707 923837 : test();
708 923837 : test();
709 923837 : test();
710 923837 : if ( ( ( EQ_16( bwidth, WB ) ) || ( EQ_16( bwidth, SWB ) ) ) && ( EQ_16( rf_mode, 1 ) ) && ( EQ_32( total_brate, ACELP_13k20 ) ) )
711 : {
712 0 : igfPresent = 1;
713 0 : move16();
714 : }
715 :
716 923837 : return igfPresent; /*Q0*/
717 : }
718 :
719 :
720 14484 : Word16 getCnaPresent_fx(
721 : const Word16 element_mode, /* i : element mode Q0*/
722 : const Word32 element_brate, /* i : element bitrate Q0*/
723 : const Word32 total_brate, /* i : total bitrate Q0*/
724 : const Word16 bwidth /* i : audio bandwidth Q0*/
725 : )
726 : {
727 : Word16 flag_cna;
728 14484 : flag_cna = 0;
729 14484 : move16();
730 :
731 14484 : test();
732 14484 : IF( EQ_16( element_mode, IVAS_CPE_DFT ) && LE_32( element_brate, CNA_MAX_BRATE_DFT_STEREO ) )
733 : {
734 1395 : flag_cna = 1;
735 1395 : move16();
736 : }
737 : ELSE
738 : {
739 13089 : test();
740 13089 : if ( LE_16( bwidth, SWB ) && ( LE_32( total_brate, ACELP_13k20 ) ) )
741 : {
742 24 : flag_cna = 1;
743 24 : move16();
744 : }
745 : }
746 :
747 14484 : return flag_cna; /*Q0*/
748 : }
749 : /*-------------------------------------------------------------------*
750 : * getTcxLtp()
751 : *
752 : *
753 : *-------------------------------------------------------------------*/
754 :
755 954872 : Word16 getTcxLtp(
756 : const Word32 sr_core /* i : internal sampling rate Q0*/
757 : )
758 : {
759 : Word16 tcxltp;
760 :
761 954872 : tcxltp = 0;
762 954872 : move16();
763 :
764 954872 : if ( ( LE_32( sr_core, 25600 ) ) )
765 : {
766 507872 : tcxltp = 1;
767 507872 : move16();
768 : }
769 :
770 954872 : return tcxltp; /*Q0*/
771 : }
772 :
773 : /*-------------------------------------------------------------------*
774 : * initPitchLagParameters()
775 : *
776 : *
777 : *-------------------------------------------------------------------*/
778 :
779 31489 : Word16 initPitchLagParameters(
780 : const Word32 sr_core, /*Q0*/
781 : Word16 *pit_min, /*Q0*/
782 : Word16 *pit_fr1, /*Q0*/
783 : Word16 *pit_fr1b, /*Q0*/
784 : Word16 *pit_fr2, /*Q0*/
785 : Word16 *pit_max /*Q0*/ )
786 : {
787 : Word16 pit_res_max;
788 :
789 31489 : IF( EQ_32( sr_core, INT_FS_12k8 ) )
790 : {
791 24921 : *pit_min = PIT_MIN_12k8;
792 24921 : move16();
793 24921 : *pit_max = PIT_MAX_12k8;
794 24921 : move16();
795 24921 : *pit_fr2 = PIT_FR2_12k8;
796 24921 : move16();
797 24921 : *pit_fr1 = PIT_FR1_12k8;
798 24921 : move16();
799 24921 : *pit_fr1b = PIT_FR1_8b_12k8;
800 24921 : move16();
801 24921 : pit_res_max = 4;
802 24921 : move16();
803 : }
804 6568 : ELSE IF( EQ_32( sr_core, INT_FS_16k ) )
805 : {
806 5243 : *pit_min = PIT_MIN_16k;
807 5243 : move16();
808 5243 : *pit_max = PIT16k_MAX;
809 5243 : move16();
810 5243 : *pit_fr2 = PIT_FR2_16k;
811 5243 : move16();
812 5243 : *pit_fr1 = PIT_FR1_16k;
813 5243 : move16();
814 5243 : *pit_fr1b = PIT_FR1_8b_16k;
815 5243 : move16();
816 5243 : pit_res_max = 6;
817 5243 : move16();
818 : }
819 1325 : ELSE IF( EQ_32( sr_core, 25600 ) )
820 : {
821 393 : *pit_min = PIT_MIN_25k6;
822 393 : move16();
823 393 : *pit_max = PIT_MAX_25k6;
824 393 : move16();
825 393 : *pit_fr2 = PIT_FR2_25k6;
826 393 : move16();
827 393 : *pit_fr1 = PIT_FR1_25k6;
828 393 : move16();
829 393 : *pit_fr1b = PIT_FR1_8b_25k6;
830 393 : move16();
831 393 : pit_res_max = 4;
832 393 : move16();
833 : }
834 : ELSE /* sr_core==32000 */
835 : {
836 932 : *pit_min = PIT_MIN_32k;
837 932 : move16();
838 932 : *pit_max = PIT_MAX_32k;
839 932 : move16();
840 932 : *pit_fr2 = PIT_FR2_32k;
841 932 : move16();
842 932 : *pit_fr1 = PIT_FR1_32k;
843 932 : move16();
844 932 : *pit_fr1b = PIT_FR1_8b_32k;
845 932 : move16();
846 932 : pit_res_max = 6;
847 932 : move16();
848 : }
849 :
850 31489 : return pit_res_max; /*Q0*/
851 : }
852 :
853 : /*-------------------------------------------------------------------*
854 : * getNumTcxCodedLines()
855 : *
856 : *
857 : *-------------------------------------------------------------------*/
858 :
859 336745 : Word16 getNumTcxCodedLines(
860 : const Word16 bwidth /* i : audio bandwidth Q0*/
861 : )
862 : {
863 : Word16 tcx_coded_lines;
864 :
865 336745 : tcx_coded_lines = 0;
866 336745 : move16();
867 :
868 336745 : SWITCH( bwidth )
869 : {
870 2680 : case NB:
871 2680 : tcx_coded_lines = 160;
872 2680 : move16();
873 2680 : BREAK;
874 32182 : case WB:
875 32182 : tcx_coded_lines = 320;
876 32182 : move16();
877 32182 : BREAK;
878 94440 : case SWB:
879 94440 : tcx_coded_lines = 640;
880 94440 : move16();
881 94440 : BREAK;
882 207443 : case FB:
883 207443 : tcx_coded_lines = 960;
884 207443 : move16();
885 207443 : BREAK;
886 0 : default:
887 0 : tcx_coded_lines = 0;
888 0 : move16();
889 0 : BREAK;
890 : }
891 :
892 336745 : return tcx_coded_lines; /*Q0*/
893 : }
894 :
895 : /*-------------------------------------------------------------------*
896 : * getTcxLpcShapedAri()
897 : *
898 : *
899 : *-------------------------------------------------------------------*/
900 :
901 929870 : Word16 getTcxLpcShapedAri(
902 : const Word32 total_brate, /* i : total bitrate Q0*/
903 : const Word16 rf_mode, /* i : flag to signal the RF mode Q0*/
904 : const Word16 element_mode /* i : IVAS element mode Q0*/
905 : )
906 : {
907 : Word16 tcx_lpc_shaped_ari;
908 929870 : tcx_lpc_shaped_ari = 0;
909 929870 : move16();
910 :
911 929870 : test();
912 929870 : test();
913 929870 : test();
914 929870 : test();
915 929870 : if ( ( ( LE_16( element_mode, IVAS_SCE ) && LE_32( total_brate, LPC_SHAPED_ARI_MAX_RATE ) ) || ( GT_16( element_mode, IVAS_SCE ) && LE_32( total_brate, LPC_SHAPED_ARI_MAX_RATE_CPE ) ) ) || rf_mode )
916 : {
917 23723 : tcx_lpc_shaped_ari = 1;
918 23723 : move16();
919 : }
920 :
921 929870 : return tcx_lpc_shaped_ari; /*Q0*/
922 : }
923 :
924 :
925 : /*-----------------------------------------------------------------------*
926 : * init_tcx()
927 : *
928 : * Initialization of TCX
929 : *-----------------------------------------------------------------------*/
930 :
931 0 : void init_tcx_cfg_ivas_fx(
932 : TCX_CONFIG_HANDLE hTcxCfg,
933 : const Word32 total_brate, /*Q0*/
934 : const Word32 sr_core, /*Q0*/
935 : const Word32 input_Fs, /*Q0*/
936 : const Word16 L_frame, /*Q0*/
937 : const Word16 bwidth, /*Q0*/
938 : const Word16 L_frameTCX, /*Q0*/
939 : const Word16 fscale, /*Q0*/
940 : const Word16 preemph_fac, /*Q15*/
941 : const Word16 tcxonly, /*Q0*/
942 : const Word16 rf_mode, /*Q0*/
943 : const Word16 igf, /*Q0*/
944 : const Word16 infoIGFStopFreq, /*Q0*/
945 : const Word16 element_mode, /*Q0*/
946 : const Word16 ini_frame, /*Q0*/
947 : const Word16 MCT_flag /*Q0*/ )
948 : {
949 : Word16 i;
950 : Word16 mdctWindowLength;
951 : Word16 mdctWindowLengthFB;
952 : Word16 na_scale_bwidth;
953 :
954 0 : hTcxCfg->preemph_fac = preemph_fac;
955 0 : move16();
956 :
957 0 : hTcxCfg->tcx5Size = shr( L_frame, 2 ); /* Always 5 ms Q0*/
958 0 : hTcxCfg->tcx5SizeFB = shr( L_frameTCX, 2 ); /* Always 5 ms Q0*/
959 0 : move16();
960 0 : move16();
961 :
962 0 : hTcxCfg->tcx_mdct_window_length_old = hTcxCfg->tcx_mdct_window_length; /*Q0*/
963 0 : move16();
964 0 : mdctWindowLength = getMdctWindowLength_fx( fscale ); /*Q0*/
965 0 : mdctWindowLengthFB = (Word16) ( mdctWindowLength * input_Fs / sr_core );
966 :
967 0 : init_tcx_window_cfg_fx( hTcxCfg, sr_core, input_Fs, L_frame, L_frameTCX, mdctWindowLength, mdctWindowLengthFB, element_mode );
968 : /* SQ deadzone & memory quantization*/
969 0 : hTcxCfg->sq_rounding = 12288 /*0.375f Q15*/; /*deadzone of 1.25->rounding=1-1.25/2 (No deadzone=0.5)*/
970 0 : move16();
971 :
972 : /* TCX rate loop */
973 0 : hTcxCfg->tcxRateLoopOpt = 0;
974 0 : move16();
975 :
976 0 : if ( tcxonly != 0 )
977 : {
978 0 : hTcxCfg->tcxRateLoopOpt = 2;
979 0 : move16();
980 : }
981 0 : if ( EQ_16( element_mode, IVAS_CPE_MDCT ) )
982 : {
983 0 : hTcxCfg->tcxRateLoopOpt = 3;
984 0 : move16();
985 : }
986 0 : hTcxCfg->bandwidth = getTcxBandwidth( bwidth ); /*Q15*/
987 0 : move16();
988 :
989 : /* set number of coded lines */
990 0 : hTcxCfg->tcx_coded_lines = getNumTcxCodedLines( bwidth ); /*Q0*/
991 0 : move16();
992 :
993 : /* TNS in TCX */
994 0 : hTcxCfg->pCurrentTnsConfig = NULL;
995 0 : hTcxCfg->fIsTNSAllowed = getTnsAllowed( total_brate, igf, element_mode ); /*Q0*/
996 0 : move16();
997 :
998 0 : IF( hTcxCfg->fIsTNSAllowed )
999 : {
1000 0 : InitTnsConfigs_ivas_fx( bwidth, hTcxCfg->tcx_coded_lines, hTcxCfg->tnsConfig, infoIGFStopFreq, total_brate, element_mode, MCT_flag );
1001 :
1002 0 : SetAllowTnsOnWhite( hTcxCfg->tnsConfig, (Word8) EQ_16( element_mode, IVAS_CPE_MDCT ) );
1003 : }
1004 :
1005 0 : IF( ini_frame == 0 )
1006 : {
1007 0 : hTcxCfg->tcx_curr_overlap_mode = hTcxCfg->tcx_last_overlap_mode = ALDO_WINDOW;
1008 0 : hTcxCfg->last_aldo = 1;
1009 0 : move16();
1010 0 : move16();
1011 0 : move16();
1012 : }
1013 :
1014 : /* Context HM*/
1015 0 : hTcxCfg->ctx_hm = getCtxHm( element_mode, total_brate, rf_mode ); /*Q0*/
1016 0 : move16();
1017 :
1018 : /* Residual Coding*/
1019 0 : hTcxCfg->resq = getResq( total_brate ); /*Q0*/
1020 0 : move16();
1021 0 : test();
1022 0 : if ( hTcxCfg->resq && !tcxonly )
1023 : {
1024 0 : hTcxCfg->tcxRateLoopOpt = 1;
1025 0 : move16();
1026 : }
1027 :
1028 : /*Set bandwidth scale*/
1029 0 : IF( EQ_16( bwidth, NB ) )
1030 : {
1031 0 : na_scale_bwidth = NB;
1032 : }
1033 0 : ELSE IF( LE_32( sr_core, INT_FS_16k ) )
1034 : {
1035 0 : na_scale_bwidth = WB;
1036 : }
1037 : ELSE
1038 : {
1039 0 : na_scale_bwidth = SWB;
1040 : }
1041 0 : move16();
1042 0 : hTcxCfg->na_scale = 32767 /*1.0f Q15*/;
1043 0 : move16();
1044 :
1045 0 : test();
1046 0 : IF( LT_16( na_scale_bwidth, SWB ) && !tcxonly )
1047 : {
1048 0 : FOR( i = 0; i < SIZE_SCALE_TABLE_TCX; i++ )
1049 : {
1050 0 : test();
1051 0 : test();
1052 0 : IF( ( EQ_16( na_scale_bwidth, scaleTcxTable[i].bwmode ) ) &&
1053 : ( GE_32( total_brate, scaleTcxTable[i].bitrateFrom ) ) &&
1054 : ( LT_32( total_brate, scaleTcxTable[i].bitrateTo ) ) )
1055 : {
1056 0 : if ( rf_mode )
1057 : {
1058 0 : i = sub( i, 1 );
1059 : }
1060 0 : hTcxCfg->na_scale = scaleTcxTable[i].scale; /*Q15*/
1061 0 : move16();
1062 0 : BREAK;
1063 : }
1064 : }
1065 : }
1066 :
1067 0 : IF( tcxonly )
1068 : {
1069 0 : InitPsychLPC_fx( sr_core, L_frame, hTcxCfg );
1070 : }
1071 : ELSE
1072 : {
1073 0 : hTcxCfg->psychParamsCurrent = NULL;
1074 : }
1075 :
1076 0 : return;
1077 : }
1078 :
1079 26158 : void init_tcx_window_cfg_fx(
1080 : TCX_CONFIG_HANDLE hTcxCfg, /* i/o: TCX Config handle Q0*/
1081 : const Word32 sr_core, /* i : SR core Q0*/
1082 : const Word32 input_Fs, /* i : input/output SR Q0*/
1083 : const Word16 L_frame, /* i : L_frame at sr_core Q0*/
1084 : const Word16 L_frameTCX, /* i : L_frame at i/o SR Q0*/
1085 : const Word16 mdctWindowLength, /* i : window length at sr_core Q0*/
1086 : const Word16 mdctWindowLengthFB, /* i : window length at i/o SR Q0*/
1087 : const Word16 element_mode /* i : mode of CPE/SCE Q0*/
1088 : )
1089 : {
1090 : /* Symmetric window = sine LD window*/
1091 26158 : hTcxCfg->tcx_mdct_window_delay = mdctWindowLength;
1092 26158 : hTcxCfg->tcx_mdct_window_delayFB = mdctWindowLengthFB;
1093 26158 : hTcxCfg->tcx_mdct_window_length = mdctWindowLength;
1094 26158 : hTcxCfg->tcx_mdct_window_lengthFB = mdctWindowLengthFB;
1095 26158 : move16();
1096 26158 : move16();
1097 26158 : move16();
1098 26158 : move16();
1099 26158 : mdct_window_sine_IVAS_updated( hTcxCfg->tcx_mdct_window, sr_core, hTcxCfg->tcx_mdct_window_length, FULL_OVERLAP, element_mode );
1100 :
1101 26158 : IF( EQ_16( hTcxCfg->tcx_mdct_window_length, hTcxCfg->tcx_mdct_window_lengthFB ) )
1102 : {
1103 1807 : Copy_pword( hTcxCfg->tcx_mdct_window, hTcxCfg->tcx_mdct_windowFB, shr( hTcxCfg->tcx_mdct_window_length, 1 ) ); /*Q15*/
1104 : }
1105 : ELSE
1106 : {
1107 24351 : mdct_window_sine_IVAS_updated( hTcxCfg->tcx_mdct_windowFB, input_Fs, hTcxCfg->tcx_mdct_window_lengthFB, FULL_OVERLAP, element_mode );
1108 : }
1109 :
1110 : /*ALDO windows for MODE2*/
1111 26158 : mdct_window_aldo( hTcxCfg->tcx_aldo_window_1, hTcxCfg->tcx_aldo_window_1_trunc, hTcxCfg->tcx_aldo_window_2, L_frame );
1112 26158 : mdct_window_aldo( hTcxCfg->tcx_aldo_window_1_FB, hTcxCfg->tcx_aldo_window_1_FB_trunc, hTcxCfg->tcx_aldo_window_2_FB, NS2SA_FX2( input_Fs, FRAME_SIZE_NS ) );
1113 :
1114 : /*1.25ms transition window for ACELP->TCX*/
1115 26158 : hTcxCfg->tcx_mdct_window_trans_length = NS2SA_FX2( sr_core, ACELP_TCX_TRANS_NS ); /*Q0*/
1116 26158 : move16();
1117 26158 : mdct_window_sine_IVAS_updated( hTcxCfg->tcx_mdct_window_trans, sr_core, hTcxCfg->tcx_mdct_window_trans_length, TRANSITION_OVERLAP, element_mode );
1118 26158 : hTcxCfg->tcx_mdct_window_trans_lengthFB = NS2SA_FX2( input_Fs, ACELP_TCX_TRANS_NS ); /*Q0*/
1119 26158 : move16();
1120 26158 : IF( EQ_16( hTcxCfg->tcx_mdct_window_trans_length, hTcxCfg->tcx_mdct_window_trans_lengthFB ) )
1121 : {
1122 1807 : Copy_pword( hTcxCfg->tcx_mdct_window_trans, hTcxCfg->tcx_mdct_window_transFB, shr( hTcxCfg->tcx_mdct_window_trans_length, 1 ) ); /*Q15*/
1123 : }
1124 : ELSE
1125 : {
1126 24351 : mdct_window_sine_IVAS_updated( hTcxCfg->tcx_mdct_window_transFB, input_Fs, hTcxCfg->tcx_mdct_window_trans_lengthFB, TRANSITION_OVERLAP, element_mode );
1127 : }
1128 : /*Mid-OLA*/
1129 : /*compute minimum length for "half" window: lookahead - 5ms. It must be also multiple of 2*/
1130 26158 : hTcxCfg->tcx_mdct_window_half_length = extract_l( L_shr( L_mult0( L_LOOK_12k8 - NS2SA( 12800, 5000000L ), sr2fscale( sr_core ) ), LD_FSCALE_DENOM ) ); /*Q0*/
1131 26158 : hTcxCfg->tcx_mdct_window_half_lengthFB = extract_l( L_shr( L_mult0( L_LOOK_12k8 - NS2SA( 12800, 5000000L ), sr2fscale( input_Fs ) ), LD_FSCALE_DENOM ) ); /*Q0*/
1132 26158 : move16();
1133 26158 : move16();
1134 26158 : assert( GT_16( hTcxCfg->tcx_mdct_window_half_length, 16 ) && "Half window can not be large enough!" );
1135 :
1136 26158 : mdct_window_sine_IVAS_updated( hTcxCfg->tcx_mdct_window_half, sr_core, hTcxCfg->tcx_mdct_window_half_length, HALF_OVERLAP, element_mode );
1137 26158 : IF( EQ_16( hTcxCfg->tcx_mdct_window_half_length, hTcxCfg->tcx_mdct_window_half_lengthFB ) )
1138 : {
1139 1807 : Copy_pword( hTcxCfg->tcx_mdct_window_half, hTcxCfg->tcx_mdct_window_halfFB, shr( hTcxCfg->tcx_mdct_window_half_length, 1 ) ); /*Q15*/
1140 : }
1141 : ELSE
1142 : {
1143 24351 : mdct_window_sine_IVAS_updated( hTcxCfg->tcx_mdct_window_halfFB, input_Fs, hTcxCfg->tcx_mdct_window_half_lengthFB, HALF_OVERLAP, element_mode );
1144 : }
1145 :
1146 : /* minimum overlap 1.25 ms */
1147 26158 : hTcxCfg->tcx_mdct_window_min_length = shr( L_frame, 4 ); /* 1.25ms */
1148 26158 : hTcxCfg->tcx_mdct_window_min_lengthFB = shr( L_frameTCX, 4 ); /* 1.25ms */
1149 26158 : move16();
1150 26158 : move16();
1151 : /* save complexity by copying the small windows if they have the same length */
1152 26158 : IF( EQ_16( hTcxCfg->tcx_mdct_window_min_length, hTcxCfg->tcx_mdct_window_trans_length ) )
1153 : {
1154 26158 : Copy_pword( hTcxCfg->tcx_mdct_window_trans, hTcxCfg->tcx_mdct_window_minimum, shr( hTcxCfg->tcx_mdct_window_min_length, 1 ) ); /*Q15*/
1155 : }
1156 : ELSE
1157 : {
1158 0 : mdct_window_sine_IVAS_updated( hTcxCfg->tcx_mdct_window_minimum, sr_core, hTcxCfg->tcx_mdct_window_min_length, MIN_OVERLAP, element_mode );
1159 : }
1160 :
1161 26158 : IF( EQ_16( hTcxCfg->tcx_mdct_window_min_lengthFB, hTcxCfg->tcx_mdct_window_trans_lengthFB ) )
1162 : {
1163 26158 : Copy_pword( hTcxCfg->tcx_mdct_window_transFB, hTcxCfg->tcx_mdct_window_minimumFB, shr( hTcxCfg->tcx_mdct_window_min_lengthFB, 1 ) ); /*Q15*/
1164 : }
1165 0 : ELSE IF( EQ_16( hTcxCfg->tcx_mdct_window_min_length, hTcxCfg->tcx_mdct_window_min_lengthFB ) )
1166 : {
1167 0 : Copy_pword( hTcxCfg->tcx_mdct_window_minimum, hTcxCfg->tcx_mdct_window_minimumFB, shr( hTcxCfg->tcx_mdct_window_min_lengthFB, 1 ) ); /*Q15*/
1168 : }
1169 : ELSE
1170 : {
1171 0 : mdct_window_sine_IVAS_updated( hTcxCfg->tcx_mdct_window_minimumFB, input_Fs, hTcxCfg->tcx_mdct_window_min_lengthFB, MIN_OVERLAP, element_mode );
1172 : }
1173 : /* TCX Offset */
1174 26158 : hTcxCfg->tcx_offset = shr( hTcxCfg->tcx_mdct_window_delay, 1 ); /*Q0*/
1175 26158 : hTcxCfg->tcx_offsetFB = shr( hTcxCfg->tcx_mdct_window_delayFB, 1 ); /*Q0*/
1176 : /*<0 rectangular transition with optimized window size = L_frame+L_frame/4*/
1177 26158 : hTcxCfg->lfacNext = sub( hTcxCfg->tcx_offset, shr( L_frame, 2 ) );
1178 26158 : hTcxCfg->lfacNextFB = sub( hTcxCfg->tcx_offsetFB, shr( L_frameTCX, 2 ) );
1179 26158 : move16();
1180 26158 : move16();
1181 26158 : move16();
1182 26158 : move16();
1183 :
1184 26158 : return;
1185 : }
1186 :
1187 25968 : void init_tcx_cfg_fx(
1188 : TCX_CONFIG_HANDLE hTcxCfg,
1189 : const Word32 total_brate, /*Q0*/
1190 : const Word32 sr_core, /*Q0*/
1191 : const Word32 input_Fs, /*Q0*/
1192 : const Word16 L_frame, /*Q0*/
1193 : const Word16 bwidth, /*Q0*/
1194 : const Word16 L_frameTCX, /*Q0*/
1195 : const Word16 fscale, /*Q0*/
1196 : const Word16 preemph_fac, /*Q15*/
1197 : const Word16 tcxonly, /*Q0*/
1198 : const Word16 rf_mode, /*Q0*/
1199 : const Word16 igf, /*Q0*/
1200 : const Word16 infoIGFStopFreq, /*Q0*/
1201 : const Word16 element_mode, /*Q0*/
1202 : const Word16 ini_frame, /*Q0*/
1203 : const Word16 MCT_flag, /*Q0*/
1204 : const Word16 fscaleFB /*Q0*/ )
1205 : {
1206 : Word16 i;
1207 : Word16 mdctWindowLength;
1208 : Word16 mdctWindowLengthFB;
1209 : Word16 na_scale_bwidth;
1210 :
1211 25968 : hTcxCfg->preemph_fac = preemph_fac;
1212 25968 : move16();
1213 :
1214 25968 : hTcxCfg->tcx5Size = shr( L_frame, 2 ); /* Always 5 ms Q0*/
1215 25968 : hTcxCfg->tcx5SizeFB = shr( L_frameTCX, 2 ); /* Always 5 ms Q0*/
1216 25968 : move16();
1217 25968 : move16();
1218 :
1219 25968 : hTcxCfg->tcx_mdct_window_length_old = hTcxCfg->tcx_mdct_window_length; /*Q0*/
1220 25968 : move16();
1221 25968 : mdctWindowLength = getMdctWindowLength_fx( fscale ); /*Q0*/
1222 25968 : mdctWindowLengthFB = getMdctWindowLength_fx( fscaleFB ); /*Q0*/
1223 25968 : init_tcx_window_cfg_fx( hTcxCfg, sr_core, input_Fs, L_frame, L_frameTCX, mdctWindowLength, mdctWindowLengthFB, element_mode );
1224 : /* SQ deadzone & memory quantization*/
1225 25968 : hTcxCfg->sq_rounding = 12288 /*0.375f Q15*/; /*deadzone of 1.25->rounding=1-1.25/2 (No deadzone=0.5)*/
1226 25968 : move16();
1227 :
1228 : /* TCX rate loop */
1229 25968 : hTcxCfg->tcxRateLoopOpt = 0;
1230 25968 : move16();
1231 :
1232 25968 : if ( tcxonly != 0 )
1233 : {
1234 14334 : hTcxCfg->tcxRateLoopOpt = 2;
1235 14334 : move16();
1236 : }
1237 25968 : if ( EQ_16( element_mode, IVAS_CPE_MDCT ) )
1238 : {
1239 12984 : hTcxCfg->tcxRateLoopOpt = 3;
1240 12984 : move16();
1241 : }
1242 25968 : hTcxCfg->bandwidth = getTcxBandwidth( bwidth ); /*Q15*/
1243 25968 : move16();
1244 :
1245 : /* set number of coded lines */
1246 25968 : hTcxCfg->tcx_coded_lines = getNumTcxCodedLines( bwidth ); /*Q0*/
1247 25968 : move16();
1248 :
1249 : /* TNS in TCX */
1250 25968 : hTcxCfg->pCurrentTnsConfig = NULL;
1251 25968 : hTcxCfg->fIsTNSAllowed = getTnsAllowed( total_brate, igf, element_mode ); /*Q0*/
1252 25968 : move16();
1253 :
1254 25968 : IF( hTcxCfg->fIsTNSAllowed )
1255 : {
1256 18124 : InitTnsConfigs( bwidth, hTcxCfg->tcx_coded_lines, hTcxCfg->tnsConfig, infoIGFStopFreq, total_brate, element_mode, MCT_flag );
1257 :
1258 18124 : SetAllowTnsOnWhite( hTcxCfg->tnsConfig, (Word8) EQ_16( element_mode, IVAS_CPE_MDCT ) );
1259 : }
1260 :
1261 25968 : IF( ini_frame == 0 )
1262 : {
1263 8690 : hTcxCfg->tcx_curr_overlap_mode = hTcxCfg->tcx_last_overlap_mode = ALDO_WINDOW;
1264 8690 : hTcxCfg->last_aldo = 1;
1265 8690 : move16();
1266 8690 : move16();
1267 8690 : move16();
1268 : }
1269 :
1270 : /* Context HM*/
1271 25968 : hTcxCfg->ctx_hm = getCtxHm( element_mode, total_brate, rf_mode ); /*Q0*/
1272 25968 : move16();
1273 :
1274 : /* Residual Coding*/
1275 25968 : hTcxCfg->resq = getResq( total_brate ); /*Q0*/
1276 25968 : move16();
1277 25968 : test();
1278 25968 : if ( hTcxCfg->resq && !tcxonly )
1279 : {
1280 11634 : hTcxCfg->tcxRateLoopOpt = 1;
1281 11634 : move16();
1282 : }
1283 :
1284 : /*Set bandwidth scale*/
1285 25968 : IF( EQ_16( bwidth, NB ) )
1286 : {
1287 2677 : na_scale_bwidth = NB;
1288 : }
1289 23291 : ELSE IF( LE_32( sr_core, INT_FS_16k ) )
1290 : {
1291 9878 : na_scale_bwidth = WB;
1292 : }
1293 : ELSE
1294 : {
1295 13413 : na_scale_bwidth = SWB;
1296 : }
1297 25968 : move16();
1298 25968 : hTcxCfg->na_scale = 32767 /*1.0f Q15*/;
1299 25968 : move16();
1300 :
1301 25968 : test();
1302 25968 : IF( LT_16( na_scale_bwidth, SWB ) && !tcxonly )
1303 : {
1304 99549 : FOR( i = 0; i < SIZE_SCALE_TABLE_TCX; i++ )
1305 : {
1306 99091 : test();
1307 99091 : test();
1308 99091 : IF( ( EQ_16( na_scale_bwidth, scaleTcxTable[i].bwmode ) ) &&
1309 : ( GE_32( total_brate, scaleTcxTable[i].bitrateFrom ) ) &&
1310 : ( LT_32( total_brate, scaleTcxTable[i].bitrateTo ) ) )
1311 : {
1312 11176 : if ( rf_mode )
1313 : {
1314 0 : i = sub( i, 1 );
1315 : }
1316 11176 : hTcxCfg->na_scale = scaleTcxTable[i].scale; /*Q15*/
1317 11176 : move16();
1318 11176 : BREAK;
1319 : }
1320 : }
1321 : }
1322 :
1323 25968 : IF( tcxonly )
1324 : {
1325 14334 : InitPsychLPC_fx( sr_core, L_frame, hTcxCfg );
1326 : }
1327 : ELSE
1328 : {
1329 11634 : hTcxCfg->psychParamsCurrent = NULL;
1330 : }
1331 :
1332 25968 : return;
1333 : }
|