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 3 : 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 3 : j = 0;
61 3 : move16();
62 19 : WHILE( LT_16( j, SIZE_BRATE_TBL ) && NE_32( ivas_total_brate, brate_tbl[j] ) )
63 : {
64 16 : test();
65 16 : j = add( j, 1 );
66 : }
67 :
68 : /* AMR-WB IO mode/EVS primary mode determination */
69 3 : 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 3 : *Opt_AMR_WB = 0;
95 3 : move16();
96 : }
97 :
98 3 : 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 3103 : Word16 get_codec_mode(
110 : const Word32 total_brate /* i : total bitrate Q0*/
111 : )
112 : {
113 : Word16 codec_mode;
114 3103 : codec_mode = -1;
115 3103 : move16();
116 :
117 3103 : 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 1051 : case 13200:
136 1051 : codec_mode = MODE1;
137 1051 : move16();
138 1051 : BREAK;
139 0 : case 16400:
140 0 : codec_mode = MODE2;
141 0 : move16();
142 0 : BREAK;
143 1051 : case 24400:
144 1051 : codec_mode = MODE2;
145 1051 : move16();
146 1051 : 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 1001 : case 64000:
156 1001 : codec_mode = MODE1;
157 1001 : move16();
158 1001 : 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 3103 : return codec_mode; /*Q0*/
170 : }
171 :
172 :
173 : /*-------------------------------------------------------------------*
174 : * getTcxonly_ivas()
175 : *
176 : *
177 : *-------------------------------------------------------------------*/
178 :
179 98806 : 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 98806 : Word16 tcxonly = 0;
187 98806 : move16();
188 : Word32 temp_flag;
189 98806 : if ( MCT_flag )
190 : {
191 7680 : temp_flag = IVAS_32k;
192 7680 : move32();
193 : }
194 : else
195 : {
196 91126 : temp_flag = IVAS_48k;
197 91126 : move32();
198 : }
199 :
200 98806 : 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 19546 : case IVAS_SCE:
210 19546 : if ( is_ism_format )
211 : {
212 15717 : if ( GT_32( total_brate, MAX_ACELP_BRATE_ISM ) )
213 : {
214 1574 : tcxonly = 1;
215 1574 : move16();
216 : }
217 : }
218 : else
219 : {
220 3829 : if ( GT_32( total_brate, MAX_ACELP_BRATE ) )
221 : {
222 337 : tcxonly = 1;
223 337 : move16();
224 : }
225 : }
226 19546 : BREAK;
227 :
228 2437 : case IVAS_CPE_DFT:
229 : case IVAS_CPE_TD:
230 2437 : if ( GT_32( total_brate, MAX_ACELP_BRATE ) )
231 : {
232 0 : tcxonly = 1;
233 0 : move16();
234 : }
235 2437 : BREAK;
236 76823 : case IVAS_CPE_MDCT:
237 76823 : if ( GE_32( total_brate, temp_flag ) )
238 : {
239 16058 : tcxonly = 1;
240 16058 : move16();
241 : }
242 76823 : BREAK;
243 : }
244 :
245 98806 : return tcxonly; /*Q0*/
246 : }
247 :
248 164 : Word16 getTcxonly(
249 : const Word32 total_brate /* i : total bitrate */
250 : )
251 : {
252 :
253 : Word16 tcxonly;
254 164 : tcxonly = 0;
255 164 : move16();
256 164 : if ( GT_32( total_brate, 32000 ) )
257 : {
258 1 : tcxonly = 1;
259 1 : move16();
260 : }
261 164 : return tcxonly; /*Q0*/
262 : }
263 :
264 260556 : 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 260556 : tcxonly = 0;
273 260556 : move16();
274 :
275 260556 : 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 227274 : case IVAS_SCE:
285 227274 : IF( is_ism_format )
286 : {
287 188293 : if ( GT_32( total_brate, MAX_ACELP_BRATE_ISM ) )
288 : {
289 98790 : tcxonly = 1;
290 98790 : move16();
291 : }
292 : }
293 : ELSE
294 : {
295 38981 : if ( GT_32( total_brate, MAX_ACELP_BRATE ) )
296 : {
297 5915 : tcxonly = 1;
298 5915 : move16();
299 : }
300 : }
301 227274 : BREAK;
302 :
303 3852 : case IVAS_CPE_DFT:
304 : case IVAS_CPE_TD:
305 3852 : if ( GT_32( total_brate, MAX_ACELP_BRATE ) )
306 : {
307 0 : tcxonly = 1;
308 0 : move16();
309 : }
310 3852 : BREAK;
311 27982 : case IVAS_CPE_MDCT:
312 27982 : IF( MCT_flag )
313 : {
314 :
315 14704 : if ( GE_32( total_brate, IVAS_32k ) )
316 : {
317 14704 : tcxonly = 1;
318 14704 : move16();
319 : }
320 : }
321 : ELSE
322 : {
323 13278 : if ( GE_32( total_brate, IVAS_48k ) )
324 : {
325 8670 : tcxonly = 1;
326 8670 : move16();
327 : }
328 : }
329 27982 : BREAK;
330 : }
331 :
332 260556 : return tcxonly; /*Q0*/
333 : }
334 :
335 : /*-------------------------------------------------------------------*
336 : * getCtxHm()
337 : *
338 : *
339 : *-------------------------------------------------------------------*/
340 :
341 1832173 : 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 1832173 : ctx_hm = 0;
350 1832173 : move16();
351 1832173 : test();
352 1832173 : test();
353 1832173 : test();
354 1832173 : test();
355 1832173 : test();
356 1832173 : test();
357 1832173 : test();
358 1832173 : test();
359 1832173 : test();
360 1832173 : 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 383417 : ctx_hm = 1;
363 383417 : move16();
364 : }
365 :
366 1832173 : return ctx_hm; /*Q0*/
367 : }
368 :
369 : /*-------------------------------------------------------------------*
370 : * getResq()
371 : *
372 : *
373 : *-------------------------------------------------------------------*/
374 :
375 1832173 : Word16 getResq(
376 : const Word32 total_brate /* i : total bitrate Q0*/
377 : )
378 : {
379 : Word16 resq;
380 :
381 1832173 : resq = 0;
382 1832173 : move16();
383 1832173 : if ( LE_32( total_brate, IVAS_64k ) )
384 : {
385 822622 : resq = 1;
386 822622 : move16();
387 : }
388 :
389 1832173 : return resq; /*Q0*/
390 : }
391 :
392 : /*-------------------------------------------------------------------*
393 : * getTnsAllowed()
394 : *
395 : *
396 : *-------------------------------------------------------------------*/
397 :
398 1860613 : 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 1860613 : tnsAllowed = 0;
407 1860613 : move16();
408 1860613 : IF( igf != 0 )
409 : {
410 1279078 : test();
411 1279078 : test();
412 1279078 : if ( GT_32( total_brate, HQ_16k40 ) || ( GT_32( total_brate, HQ_13k20 ) && EQ_16( element_mode, IVAS_CPE_DFT ) ) )
413 : {
414 1135367 : tnsAllowed = 1;
415 1135367 : move16();
416 : }
417 : }
418 : ELSE
419 : {
420 581535 : if ( GT_32( total_brate, HQ_32k ) )
421 : {
422 553670 : tnsAllowed = 1;
423 553670 : move16();
424 : }
425 : }
426 :
427 1860613 : return tnsAllowed; /*Q0*/
428 : }
429 :
430 : /*-------------------------------------------------------------------*
431 : * getRestrictedMode()
432 : *
433 : *
434 : *-------------------------------------------------------------------*/
435 :
436 39229 : 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 39229 : restrictedMode = 3;
444 39229 : move16();
445 :
446 39229 : test();
447 39229 : test();
448 39229 : test();
449 39229 : test();
450 39229 : IF( !Opt_AMR_WB && ( GT_32( total_brate, HQ_32k ) && NE_16( element_mode, IVAS_SCE ) ) )
451 : {
452 16719 : restrictedMode = 6;
453 16719 : move16();
454 : }
455 22510 : ELSE IF( !Opt_AMR_WB && ( GT_32( total_brate, HQ_48k ) && EQ_16( element_mode, IVAS_SCE ) ) )
456 : {
457 1300 : restrictedMode = 6;
458 1300 : move16();
459 : }
460 21210 : ELSE IF( Opt_AMR_WB )
461 : {
462 0 : restrictedMode = 1;
463 0 : move16();
464 : }
465 :
466 39229 : return restrictedMode; /*Q0*/
467 : }
468 :
469 : /*-------------------------------------------------------------------*
470 : * getMdctWindowLength()
471 : *
472 : *
473 : *-------------------------------------------------------------------*/
474 86909 : Word16 getMdctWindowLength_fx(
475 : const Word16 fscale /*Q0*/ )
476 : {
477 : Word16 mdctWindowLength;
478 86909 : mdctWindowLength = extract_l( L_shr( L_mult0( L_LOOK_12k8, fscale ), LD_FSCALE_DENOM ) );
479 :
480 86909 : return mdctWindowLength; /*Q0*/
481 : }
482 :
483 : /*-------------------------------------------------------------------*
484 : * sr2fscale()
485 : *
486 : *
487 : *-------------------------------------------------------------------*/
488 2932394 : Word16 sr2fscale_fx(
489 : const Word32 sr_core /* i : internal sampling rate Q0*/
490 : )
491 : {
492 2932394 : return extract_l( Mpy_32_16_1( sr_core, FSCALE_DENOM_BY_12800_Q15 ) ); /*Q0*/
493 : }
494 :
495 126287 : int16_t sr2fscale(
496 : const int32_t sr_core /* i : internal sampling rate */
497 : )
498 : {
499 :
500 126287 : return (int16_t) ( ( FSCALE_DENOM * sr_core ) / 12800 );
501 : }
502 :
503 2819330 : 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 2819330 : sr_core = -1; /* to suppress MSVC warning */
516 2819330 : move32();
517 :
518 2819330 : bwd_swb_or_fb_flag = s_or( (Word16) EQ_16( bwidth, SWB ), (Word16) EQ_16( bwidth, FB ) );
519 2819330 : test();
520 2819330 : test();
521 2819330 : test();
522 2819330 : test();
523 2819330 : test();
524 2819330 : test();
525 2819330 : test();
526 2819330 : test();
527 2819330 : test();
528 2819330 : test();
529 2819330 : test();
530 2819330 : test();
531 2819330 : test();
532 2819330 : test();
533 2819330 : test();
534 2819330 : test();
535 2819330 : test();
536 2819330 : test();
537 2819330 : test();
538 2819330 : test();
539 2819330 : test();
540 2819330 : test();
541 2819330 : test();
542 2819330 : IF( EQ_16( bwidth, NB ) )
543 : {
544 7236 : sr_core = INT_FS_12k8;
545 7236 : move32();
546 : }
547 2812094 : 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 321 : sr_core = INT_FS_12k8;
551 321 : move32();
552 : }
553 2811773 : ELSE IF( GT_16( element_mode, EVS_MONO ) && flag_ACELP16k == 0 )
554 : {
555 173768 : sr_core = INT_FS_12k8;
556 173768 : move32();
557 : }
558 2638005 : ELSE IF( EQ_32( bwidth, WB ) || ( ( LE_32( total_brate, ACELP_32k ) ) && ( ( EQ_32( bwidth, SWB ) ) || ( EQ_32( bwidth, FB ) ) ) ) )
559 : {
560 416551 : sr_core = INT_FS_16k;
561 416551 : move32();
562 : }
563 2221454 : 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 1462 : sr_core = INT_FS_16k;
566 1462 : move32();
567 : }
568 2219992 : 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 27691 : sr_core = INT_FS_16k;
571 27691 : move32();
572 : }
573 2192301 : 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 23543 : sr_core = 25600;
576 23543 : move32();
577 : }
578 2168758 : 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 836963 : sr_core = 25600;
581 836963 : move32();
582 : }
583 1331795 : ELSE IF( bwd_swb_or_fb_flag )
584 : {
585 1331795 : sr_core = 32000;
586 1331795 : move32();
587 : }
588 : ELSE
589 : {
590 0 : assert( 0 );
591 : }
592 :
593 2819330 : return sr_core; /*Q0*/
594 : }
595 :
596 91530 : Word16 getTcxBandwidth(
597 : const Word16 bwidth /* i : audio bandwidth Q0*/
598 : )
599 : {
600 :
601 : Word16 tcxBandwidth;
602 :
603 91530 : tcxBandwidth = 16384 /*0.5f Q15*/;
604 91530 : move16();
605 91530 : if ( EQ_16( bwidth, NB ) )
606 : {
607 9764 : tcxBandwidth = 10240 /*0.3125f Q15*/;
608 9764 : move16();
609 : }
610 :
611 91530 : return tcxBandwidth; /*Q15*/
612 : }
613 :
614 :
615 1850071 : 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 1850071 : igfPresent = 0;
624 1850071 : move16();
625 :
626 1850071 : IF( EQ_16( bwidth, SWB ) )
627 : {
628 504019 : SWITCH( element_mode )
629 : {
630 128389 : case EVS_MONO:
631 : case IVAS_SCE:
632 128389 : if ( LE_32( total_brate, HQ_64k ) )
633 : {
634 125742 : igfPresent = 1;
635 125742 : move16();
636 : }
637 128389 : BREAK;
638 20265 : case IVAS_CPE_DFT:
639 : case IVAS_CPE_TD:
640 20265 : if ( LE_32( total_brate, HQ_48k ) )
641 : {
642 20265 : igfPresent = 1;
643 20265 : move16();
644 : }
645 20265 : BREAK;
646 355365 : case IVAS_CPE_MDCT:
647 355365 : if ( LE_32( total_brate, IVAS_96k ) )
648 : {
649 222661 : igfPresent = 1;
650 222661 : move16();
651 : }
652 355365 : BREAK;
653 : }
654 504019 : }
655 1346052 : ELSE IF( EQ_16( bwidth, FB ) )
656 : {
657 1202509 : SWITCH( element_mode )
658 : {
659 313702 : case EVS_MONO:
660 : case IVAS_SCE:
661 313702 : if ( LE_32( total_brate, IVAS_128k ) )
662 : {
663 312489 : igfPresent = 1;
664 312489 : move16();
665 : }
666 313702 : BREAK;
667 7149 : case IVAS_CPE_DFT:
668 : case IVAS_CPE_TD:
669 7149 : if ( LE_32( total_brate, IVAS_48k ) )
670 : {
671 7149 : igfPresent = 1;
672 7149 : move16();
673 : }
674 7149 : BREAK;
675 881658 : case IVAS_CPE_MDCT:
676 881658 : if ( LE_32( total_brate, IVAS_128k ) )
677 : {
678 587237 : igfPresent = 1;
679 587237 : move16();
680 : }
681 881658 : BREAK;
682 : }
683 1202509 : }
684 143543 : ELSE IF( EQ_16( bwidth, WB ) )
685 : {
686 143451 : SWITCH( element_mode )
687 : {
688 15149 : case EVS_MONO:
689 : case IVAS_SCE:
690 15149 : if ( LE_32( total_brate, ACELP_9k60 ) )
691 : {
692 251 : igfPresent = 1;
693 251 : move16();
694 : }
695 15149 : BREAK;
696 128302 : case IVAS_CPE_DFT:
697 : case IVAS_CPE_TD:
698 : case IVAS_CPE_MDCT:
699 128302 : if ( LE_32( total_brate, ACELP_13k20 ) )
700 : {
701 2688 : igfPresent = 1;
702 2688 : move16();
703 : }
704 128302 : BREAK;
705 : }
706 92 : }
707 1850071 : test();
708 1850071 : test();
709 1850071 : test();
710 1850071 : 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 1850071 : return igfPresent; /*Q0*/
717 : }
718 :
719 :
720 12671 : 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 12671 : flag_cna = 0;
729 12671 : move16();
730 :
731 12671 : test();
732 12671 : IF( EQ_16( element_mode, IVAS_CPE_DFT ) && LE_32( element_brate, CNA_MAX_BRATE_DFT_STEREO ) )
733 : {
734 1351 : flag_cna = 1;
735 1351 : move16();
736 : }
737 : ELSE
738 : {
739 11320 : test();
740 11320 : if ( LE_16( bwidth, SWB ) && ( LE_32( total_brate, ACELP_13k20 ) ) )
741 : {
742 20 : flag_cna = 1;
743 20 : move16();
744 : }
745 : }
746 :
747 12671 : return flag_cna; /*Q0*/
748 : }
749 : /*-------------------------------------------------------------------*
750 : * getTcxLtp()
751 : *
752 : *
753 : *-------------------------------------------------------------------*/
754 :
755 976959 : Word16 getTcxLtp(
756 : const Word32 sr_core /* i : internal sampling rate Q0*/
757 : )
758 : {
759 : Word16 tcxltp;
760 :
761 976959 : tcxltp = 0;
762 976959 : move16();
763 :
764 976959 : if ( ( LE_32( sr_core, 25600 ) ) )
765 : {
766 538541 : tcxltp = 1;
767 538541 : move16();
768 : }
769 :
770 976959 : return tcxltp; /*Q0*/
771 : }
772 :
773 : /*-------------------------------------------------------------------*
774 : * initPitchLagParameters()
775 : *
776 : *
777 : *-------------------------------------------------------------------*/
778 :
779 67799 : 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 67799 : IF( EQ_32( sr_core, INT_FS_12k8 ) )
790 : {
791 45576 : *pit_min = PIT_MIN_12k8;
792 45576 : move16();
793 45576 : *pit_max = PIT_MAX_12k8;
794 45576 : move16();
795 45576 : *pit_fr2 = PIT_FR2_12k8;
796 45576 : move16();
797 45576 : *pit_fr1 = PIT_FR1_12k8;
798 45576 : move16();
799 45576 : *pit_fr1b = PIT_FR1_8b_12k8;
800 45576 : move16();
801 45576 : pit_res_max = 4;
802 45576 : move16();
803 : }
804 22223 : ELSE IF( EQ_32( sr_core, INT_FS_16k ) )
805 : {
806 19040 : *pit_min = PIT_MIN_16k;
807 19040 : move16();
808 19040 : *pit_max = PIT16k_MAX;
809 19040 : move16();
810 19040 : *pit_fr2 = PIT_FR2_16k;
811 19040 : move16();
812 19040 : *pit_fr1 = PIT_FR1_16k;
813 19040 : move16();
814 19040 : *pit_fr1b = PIT_FR1_8b_16k;
815 19040 : move16();
816 19040 : pit_res_max = 6;
817 19040 : move16();
818 : }
819 3183 : ELSE IF( EQ_32( sr_core, 25600 ) )
820 : {
821 990 : *pit_min = PIT_MIN_25k6;
822 990 : move16();
823 990 : *pit_max = PIT_MAX_25k6;
824 990 : move16();
825 990 : *pit_fr2 = PIT_FR2_25k6;
826 990 : move16();
827 990 : *pit_fr1 = PIT_FR1_25k6;
828 990 : move16();
829 990 : *pit_fr1b = PIT_FR1_8b_25k6;
830 990 : move16();
831 990 : pit_res_max = 4;
832 990 : move16();
833 : }
834 : ELSE /* sr_core==32000 */
835 : {
836 2193 : *pit_min = PIT_MIN_32k;
837 2193 : move16();
838 2193 : *pit_max = PIT_MAX_32k;
839 2193 : move16();
840 2193 : *pit_fr2 = PIT_FR2_32k;
841 2193 : move16();
842 2193 : *pit_fr1 = PIT_FR1_32k;
843 2193 : move16();
844 2193 : *pit_fr1b = PIT_FR1_8b_32k;
845 2193 : move16();
846 2193 : pit_res_max = 6;
847 2193 : move16();
848 : }
849 :
850 67799 : return pit_res_max; /*Q0*/
851 : }
852 :
853 : /*-------------------------------------------------------------------*
854 : * getNumTcxCodedLines()
855 : *
856 : *
857 : *-------------------------------------------------------------------*/
858 :
859 422110 : Word16 getNumTcxCodedLines(
860 : const Word16 bwidth /* i : audio bandwidth Q0*/
861 : )
862 : {
863 : Word16 tcx_coded_lines;
864 :
865 422110 : tcx_coded_lines = 0;
866 422110 : move16();
867 :
868 422110 : SWITCH( bwidth )
869 : {
870 2531 : case NB:
871 2531 : tcx_coded_lines = 160;
872 2531 : move16();
873 2531 : BREAK;
874 30438 : case WB:
875 30438 : tcx_coded_lines = 320;
876 30438 : move16();
877 30438 : BREAK;
878 137041 : case SWB:
879 137041 : tcx_coded_lines = 640;
880 137041 : move16();
881 137041 : BREAK;
882 252100 : case FB:
883 252100 : tcx_coded_lines = 960;
884 252100 : move16();
885 252100 : BREAK;
886 0 : default:
887 0 : tcx_coded_lines = 0;
888 0 : move16();
889 0 : BREAK;
890 : }
891 :
892 422110 : return tcx_coded_lines; /*Q0*/
893 : }
894 :
895 : /*-------------------------------------------------------------------*
896 : * getTcxLpcShapedAri()
897 : *
898 : *
899 : *-------------------------------------------------------------------*/
900 :
901 1836781 : 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 1836781 : tcx_lpc_shaped_ari = 0;
909 1836781 : move16();
910 :
911 1836781 : test();
912 1836781 : test();
913 1836781 : test();
914 1836781 : test();
915 1836781 : 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 42305 : tcx_lpc_shaped_ari = 1;
918 42305 : move16();
919 : }
920 :
921 1836781 : return tcx_lpc_shaped_ari; /*Q0*/
922 : }
923 :
924 :
925 : /*-----------------------------------------------------------------------*
926 : * init_tcx()
927 : *
928 : * Initialization of TCX
929 : *-----------------------------------------------------------------------*/
930 :
931 39064 : 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 39064 : hTcxCfg->preemph_fac = preemph_fac;
955 39064 : move16();
956 :
957 39064 : hTcxCfg->tcx5Size = shr( L_frame, 2 ); /* Always 5 ms Q0*/
958 39064 : hTcxCfg->tcx5SizeFB = shr( L_frameTCX, 2 ); /* Always 5 ms Q0*/
959 39064 : move16();
960 39064 : move16();
961 :
962 39064 : hTcxCfg->tcx_mdct_window_length_old = hTcxCfg->tcx_mdct_window_length; /*Q0*/
963 39064 : move16();
964 39064 : mdctWindowLength = getMdctWindowLength_fx( fscale ); /*Q0*/
965 39064 : mdctWindowLengthFB = (Word16) ( mdctWindowLength * input_Fs / sr_core );
966 :
967 39064 : init_tcx_window_cfg_fx( hTcxCfg, sr_core, input_Fs, L_frame, L_frameTCX, mdctWindowLength, mdctWindowLengthFB, element_mode );
968 : /* SQ deadzone & memory quantization*/
969 39064 : hTcxCfg->sq_rounding = 12288 /*0.375f Q15*/; /*deadzone of 1.25->rounding=1-1.25/2 (No deadzone=0.5)*/
970 39064 : move16();
971 :
972 : /* TCX rate loop */
973 39064 : hTcxCfg->tcxRateLoopOpt = 0;
974 39064 : move16();
975 :
976 39064 : if ( tcxonly != 0 )
977 : {
978 17969 : hTcxCfg->tcxRateLoopOpt = 2;
979 17969 : move16();
980 : }
981 39064 : if ( EQ_16( element_mode, IVAS_CPE_MDCT ) )
982 : {
983 17180 : hTcxCfg->tcxRateLoopOpt = 3;
984 17180 : move16();
985 : }
986 39064 : hTcxCfg->bandwidth = getTcxBandwidth( bwidth ); /*Q15*/
987 39064 : move16();
988 :
989 : /* set number of coded lines */
990 39064 : hTcxCfg->tcx_coded_lines = getNumTcxCodedLines( bwidth ); /*Q0*/
991 39064 : move16();
992 :
993 : /* TNS in TCX */
994 39064 : hTcxCfg->pCurrentTnsConfig = NULL;
995 39064 : hTcxCfg->fIsTNSAllowed = getTnsAllowed( total_brate, igf, element_mode ); /*Q0*/
996 39064 : move16();
997 :
998 39064 : IF( hTcxCfg->fIsTNSAllowed )
999 : {
1000 30763 : InitTnsConfigs_ivas_fx( bwidth, hTcxCfg->tcx_coded_lines, hTcxCfg->tnsConfig, infoIGFStopFreq, total_brate, element_mode, MCT_flag );
1001 :
1002 30763 : SetAllowTnsOnWhite( hTcxCfg->tnsConfig, (Word8) EQ_16( element_mode, IVAS_CPE_MDCT ) );
1003 : }
1004 :
1005 39064 : IF( ini_frame == 0 )
1006 : {
1007 14467 : hTcxCfg->tcx_curr_overlap_mode = hTcxCfg->tcx_last_overlap_mode = ALDO_WINDOW;
1008 14467 : hTcxCfg->last_aldo = 1;
1009 14467 : move16();
1010 14467 : move16();
1011 14467 : move16();
1012 : }
1013 :
1014 : /* Context HM*/
1015 39064 : hTcxCfg->ctx_hm = getCtxHm( element_mode, total_brate, rf_mode ); /*Q0*/
1016 39064 : move16();
1017 :
1018 : /* Residual Coding*/
1019 39064 : hTcxCfg->resq = getResq( total_brate ); /*Q0*/
1020 39064 : move16();
1021 39064 : test();
1022 39064 : if ( hTcxCfg->resq && !tcxonly )
1023 : {
1024 21095 : hTcxCfg->tcxRateLoopOpt = 1;
1025 21095 : move16();
1026 : }
1027 :
1028 : /*Set bandwidth scale*/
1029 39064 : IF( EQ_16( bwidth, NB ) )
1030 : {
1031 0 : na_scale_bwidth = NB;
1032 : }
1033 39064 : ELSE IF( LE_32( sr_core, INT_FS_16k ) )
1034 : {
1035 21158 : na_scale_bwidth = WB;
1036 : }
1037 : ELSE
1038 : {
1039 17906 : na_scale_bwidth = SWB;
1040 : }
1041 39064 : move16();
1042 39064 : hTcxCfg->na_scale = 32767 /*1.0f Q15*/;
1043 39064 : move16();
1044 :
1045 39064 : test();
1046 39064 : IF( LT_16( na_scale_bwidth, SWB ) && !tcxonly )
1047 : {
1048 226963 : FOR( i = 0; i < SIZE_SCALE_TABLE_TCX; i++ )
1049 : {
1050 224747 : test();
1051 224747 : test();
1052 224747 : 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 18229 : if ( rf_mode )
1057 : {
1058 0 : i = sub( i, 1 );
1059 : }
1060 18229 : hTcxCfg->na_scale = scaleTcxTable[i].scale; /*Q15*/
1061 18229 : move16();
1062 18229 : BREAK;
1063 : }
1064 : }
1065 : }
1066 :
1067 39064 : IF( tcxonly )
1068 : {
1069 17969 : InitPsychLPC_fx( sr_core, L_frame, hTcxCfg );
1070 : }
1071 : ELSE
1072 : {
1073 21095 : hTcxCfg->psychParamsCurrent = NULL;
1074 : }
1075 :
1076 39064 : return;
1077 : }
1078 :
1079 63079 : 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 63079 : hTcxCfg->tcx_mdct_window_delay = mdctWindowLength;
1092 63079 : hTcxCfg->tcx_mdct_window_delayFB = mdctWindowLengthFB;
1093 63079 : hTcxCfg->tcx_mdct_window_length = mdctWindowLength;
1094 63079 : hTcxCfg->tcx_mdct_window_lengthFB = mdctWindowLengthFB;
1095 63079 : move16();
1096 63079 : move16();
1097 63079 : move16();
1098 63079 : move16();
1099 63079 : mdct_window_sine_IVAS_updated( hTcxCfg->tcx_mdct_window, sr_core, hTcxCfg->tcx_mdct_window_length, FULL_OVERLAP, element_mode );
1100 :
1101 63079 : IF( EQ_16( hTcxCfg->tcx_mdct_window_length, hTcxCfg->tcx_mdct_window_lengthFB ) )
1102 : {
1103 3914 : Copy_pword( hTcxCfg->tcx_mdct_window, hTcxCfg->tcx_mdct_windowFB, shr( hTcxCfg->tcx_mdct_window_length, 1 ) ); /*Q15*/
1104 : }
1105 : ELSE
1106 : {
1107 59165 : 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 63079 : mdct_window_aldo( hTcxCfg->tcx_aldo_window_1, hTcxCfg->tcx_aldo_window_1_trunc, hTcxCfg->tcx_aldo_window_2, L_frame );
1112 63079 : 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 63079 : hTcxCfg->tcx_mdct_window_trans_length = NS2SA_FX2( sr_core, ACELP_TCX_TRANS_NS ); /*Q0*/
1116 63079 : move16();
1117 63079 : mdct_window_sine_IVAS_updated( hTcxCfg->tcx_mdct_window_trans, sr_core, hTcxCfg->tcx_mdct_window_trans_length, TRANSITION_OVERLAP, element_mode );
1118 63079 : hTcxCfg->tcx_mdct_window_trans_lengthFB = NS2SA_FX2( input_Fs, ACELP_TCX_TRANS_NS ); /*Q0*/
1119 63079 : move16();
1120 63079 : IF( EQ_16( hTcxCfg->tcx_mdct_window_trans_length, hTcxCfg->tcx_mdct_window_trans_lengthFB ) )
1121 : {
1122 3914 : 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 59165 : 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 63079 : 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 63079 : 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 63079 : move16();
1133 63079 : move16();
1134 63079 : assert( GT_16( hTcxCfg->tcx_mdct_window_half_length, 16 ) && "Half window can not be large enough!" );
1135 :
1136 63079 : mdct_window_sine_IVAS_updated( hTcxCfg->tcx_mdct_window_half, sr_core, hTcxCfg->tcx_mdct_window_half_length, HALF_OVERLAP, element_mode );
1137 63079 : IF( EQ_16( hTcxCfg->tcx_mdct_window_half_length, hTcxCfg->tcx_mdct_window_half_lengthFB ) )
1138 : {
1139 3914 : 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 59165 : 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 63079 : hTcxCfg->tcx_mdct_window_min_length = shr( L_frame, 4 ); /* 1.25ms */
1148 63079 : hTcxCfg->tcx_mdct_window_min_lengthFB = shr( L_frameTCX, 4 ); /* 1.25ms */
1149 63079 : move16();
1150 63079 : move16();
1151 : /* save complexity by copying the small windows if they have the same length */
1152 63079 : IF( EQ_16( hTcxCfg->tcx_mdct_window_min_length, hTcxCfg->tcx_mdct_window_trans_length ) )
1153 : {
1154 63079 : 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 63079 : IF( EQ_16( hTcxCfg->tcx_mdct_window_min_lengthFB, hTcxCfg->tcx_mdct_window_trans_lengthFB ) )
1162 : {
1163 63079 : 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 63079 : hTcxCfg->tcx_offset = shr( hTcxCfg->tcx_mdct_window_delay, 1 ); /*Q0*/
1175 63079 : 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 63079 : hTcxCfg->lfacNext = sub( hTcxCfg->tcx_offset, shr( L_frame, 2 ) );
1178 63079 : hTcxCfg->lfacNextFB = sub( hTcxCfg->tcx_offsetFB, shr( L_frameTCX, 2 ) );
1179 63079 : move16();
1180 63079 : move16();
1181 63079 : move16();
1182 63079 : move16();
1183 :
1184 63079 : return;
1185 : }
1186 :
1187 23830 : 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 23830 : hTcxCfg->preemph_fac = preemph_fac;
1212 23830 : move16();
1213 :
1214 23830 : hTcxCfg->tcx5Size = shr( L_frame, 2 ); /* Always 5 ms Q0*/
1215 23830 : hTcxCfg->tcx5SizeFB = shr( L_frameTCX, 2 ); /* Always 5 ms Q0*/
1216 23830 : move16();
1217 23830 : move16();
1218 :
1219 23830 : hTcxCfg->tcx_mdct_window_length_old = hTcxCfg->tcx_mdct_window_length; /*Q0*/
1220 23830 : move16();
1221 23830 : mdctWindowLength = getMdctWindowLength_fx( fscale ); /*Q0*/
1222 23830 : mdctWindowLengthFB = getMdctWindowLength_fx( fscaleFB ); /*Q0*/
1223 23830 : init_tcx_window_cfg_fx( hTcxCfg, sr_core, input_Fs, L_frame, L_frameTCX, mdctWindowLength, mdctWindowLengthFB, element_mode );
1224 : /* SQ deadzone & memory quantization*/
1225 23830 : hTcxCfg->sq_rounding = 12288 /*0.375f Q15*/; /*deadzone of 1.25->rounding=1-1.25/2 (No deadzone=0.5)*/
1226 23830 : move16();
1227 :
1228 : /* TCX rate loop */
1229 23830 : hTcxCfg->tcxRateLoopOpt = 0;
1230 23830 : move16();
1231 :
1232 23830 : if ( tcxonly != 0 )
1233 : {
1234 12541 : hTcxCfg->tcxRateLoopOpt = 2;
1235 12541 : move16();
1236 : }
1237 23830 : if ( EQ_16( element_mode, IVAS_CPE_MDCT ) )
1238 : {
1239 11220 : hTcxCfg->tcxRateLoopOpt = 3;
1240 11220 : move16();
1241 : }
1242 23830 : hTcxCfg->bandwidth = getTcxBandwidth( bwidth ); /*Q15*/
1243 23830 : move16();
1244 :
1245 : /* set number of coded lines */
1246 23830 : hTcxCfg->tcx_coded_lines = getNumTcxCodedLines( bwidth ); /*Q0*/
1247 23830 : move16();
1248 :
1249 : /* TNS in TCX */
1250 23830 : hTcxCfg->pCurrentTnsConfig = NULL;
1251 23830 : hTcxCfg->fIsTNSAllowed = getTnsAllowed( total_brate, igf, element_mode ); /*Q0*/
1252 23830 : move16();
1253 :
1254 23830 : IF( hTcxCfg->fIsTNSAllowed )
1255 : {
1256 16123 : InitTnsConfigs( bwidth, hTcxCfg->tcx_coded_lines, hTcxCfg->tnsConfig, infoIGFStopFreq, total_brate, element_mode, MCT_flag );
1257 :
1258 16123 : SetAllowTnsOnWhite( hTcxCfg->tnsConfig, (Word8) EQ_16( element_mode, IVAS_CPE_MDCT ) );
1259 : }
1260 :
1261 23830 : IF( ini_frame == 0 )
1262 : {
1263 7744 : hTcxCfg->tcx_curr_overlap_mode = hTcxCfg->tcx_last_overlap_mode = ALDO_WINDOW;
1264 7744 : hTcxCfg->last_aldo = 1;
1265 7744 : move16();
1266 7744 : move16();
1267 7744 : move16();
1268 : }
1269 :
1270 : /* Context HM*/
1271 23830 : hTcxCfg->ctx_hm = getCtxHm( element_mode, total_brate, rf_mode ); /*Q0*/
1272 23830 : move16();
1273 :
1274 : /* Residual Coding*/
1275 23830 : hTcxCfg->resq = getResq( total_brate ); /*Q0*/
1276 23830 : move16();
1277 23830 : test();
1278 23830 : if ( hTcxCfg->resq && !tcxonly )
1279 : {
1280 11289 : hTcxCfg->tcxRateLoopOpt = 1;
1281 11289 : move16();
1282 : }
1283 :
1284 : /*Set bandwidth scale*/
1285 23830 : IF( EQ_16( bwidth, NB ) )
1286 : {
1287 2528 : na_scale_bwidth = NB;
1288 : }
1289 21302 : ELSE IF( LE_32( sr_core, INT_FS_16k ) )
1290 : {
1291 9394 : na_scale_bwidth = WB;
1292 : }
1293 : ELSE
1294 : {
1295 11908 : na_scale_bwidth = SWB;
1296 : }
1297 23830 : move16();
1298 23830 : hTcxCfg->na_scale = 32767 /*1.0f Q15*/;
1299 23830 : move16();
1300 :
1301 23830 : test();
1302 23830 : IF( LT_16( na_scale_bwidth, SWB ) && !tcxonly )
1303 : {
1304 96749 : FOR( i = 0; i < SIZE_SCALE_TABLE_TCX; i++ )
1305 : {
1306 96295 : test();
1307 96295 : test();
1308 96295 : 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 10835 : if ( rf_mode )
1313 : {
1314 0 : i = sub( i, 1 );
1315 : }
1316 10835 : hTcxCfg->na_scale = scaleTcxTable[i].scale; /*Q15*/
1317 10835 : move16();
1318 10835 : BREAK;
1319 : }
1320 : }
1321 : }
1322 :
1323 23830 : IF( tcxonly )
1324 : {
1325 12541 : InitPsychLPC_fx( sr_core, L_frame, hTcxCfg );
1326 : }
1327 : ELSE
1328 : {
1329 11289 : hTcxCfg->psychParamsCurrent = NULL;
1330 : }
1331 :
1332 23830 : return;
1333 : }
|