LCOV - code coverage report
Current view: top level - lib_com - core_com_config.c (source / functions) Hit Total Coverage
Test: Coverage on main -- dec/rend @ 4c82f1d24d39d0296b18d775f18a006f4c7d024b Lines: 431 625 69.0 %
Date: 2025-05-17 01:59:02 Functions: 19 23 82.6 %

          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          35 : Word16 getTcxonly(
     249             :     const Word32 total_brate /* i  : total bitrate                       */
     250             : )
     251             : {
     252             : 
     253             :     Word16 tcxonly;
     254          35 :     tcxonly = 0;
     255          35 :     move16();
     256          35 :     if ( GT_32( total_brate, 32000 ) )
     257             :     {
     258           0 :         tcxonly = 1;
     259           0 :         move16();
     260             :     }
     261          35 :     return tcxonly; /*Q0*/
     262             : }
     263             : 
     264      229576 : 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      229576 :     tcxonly = 0;
     273      229576 :     move16();
     274             : 
     275      229576 :     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      210687 :         case IVAS_SCE:
     285      210687 :             IF( is_ism_format )
     286             :             {
     287      174736 :                 if ( GT_32( total_brate, MAX_ACELP_BRATE_ISM ) )
     288             :                 {
     289       97740 :                     tcxonly = 1;
     290       97740 :                     move16();
     291             :                 }
     292             :             }
     293             :             ELSE
     294             :             {
     295       35951 :                 if ( GT_32( total_brate, MAX_ACELP_BRATE ) )
     296             :                 {
     297        5589 :                     tcxonly = 1;
     298        5589 :                     move16();
     299             :                 }
     300             :             }
     301      210687 :             BREAK;
     302             : 
     303        1613 :         case IVAS_CPE_DFT:
     304             :         case IVAS_CPE_TD:
     305        1613 :             if ( GT_32( total_brate, MAX_ACELP_BRATE ) )
     306             :             {
     307           0 :                 tcxonly = 1;
     308           0 :                 move16();
     309             :             }
     310        1613 :             BREAK;
     311       15828 :         case IVAS_CPE_MDCT:
     312       15828 :             IF( MCT_flag )
     313             :             {
     314             : 
     315        7024 :                 if ( GE_32( total_brate, IVAS_32k ) )
     316             :                 {
     317        7024 :                     tcxonly = 1;
     318        7024 :                     move16();
     319             :                 }
     320             :             }
     321             :             ELSE
     322             :             {
     323        8804 :                 if ( GE_32( total_brate, IVAS_48k ) )
     324             :                 {
     325        4196 :                     tcxonly = 1;
     326        4196 :                     move16();
     327             :                 }
     328             :             }
     329       15828 :             BREAK;
     330             :     }
     331             : 
     332      229576 :     return tcxonly; /*Q0*/
     333             : }
     334             : 
     335             : /*-------------------------------------------------------------------*
     336             :  * getCtxHm()
     337             :  *
     338             :  *
     339             :  *-------------------------------------------------------------------*/
     340             : 
     341      871166 : 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      871166 :     ctx_hm = 0;
     350      871166 :     move16();
     351      871166 :     test();
     352      871166 :     test();
     353      871166 :     test();
     354      871166 :     test();
     355      871166 :     test();
     356      871166 :     test();
     357      871166 :     test();
     358      871166 :     test();
     359      871166 :     test();
     360      871166 :     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      180378 :         ctx_hm = 1;
     363      180378 :         move16();
     364             :     }
     365             : 
     366      871166 :     return ctx_hm; /*Q0*/
     367             : }
     368             : 
     369             : /*-------------------------------------------------------------------*
     370             :  * getResq()
     371             :  *
     372             :  *
     373             :  *-------------------------------------------------------------------*/
     374             : 
     375      871166 : Word16 getResq(
     376             :     const Word32 total_brate /* i  : total bitrate               Q0*/
     377             : )
     378             : {
     379             :     Word16 resq;
     380             : 
     381      871166 :     resq = 0;
     382      871166 :     move16();
     383      871166 :     if ( LE_32( total_brate, IVAS_64k ) )
     384             :     {
     385      392226 :         resq = 1;
     386      392226 :         move16();
     387             :     }
     388             : 
     389      871166 :     return resq; /*Q0*/
     390             : }
     391             : 
     392             : /*-------------------------------------------------------------------*
     393             :  * getTnsAllowed()
     394             :  *
     395             :  *
     396             :  *-------------------------------------------------------------------*/
     397             : 
     398      899606 : 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      899606 :     tnsAllowed = 0;
     407      899606 :     move16();
     408      899606 :     IF( igf != 0 )
     409             :     {
     410      611703 :         test();
     411      611703 :         test();
     412      611703 :         if ( GT_32( total_brate, HQ_16k40 ) || ( GT_32( total_brate, HQ_13k20 ) && EQ_16( element_mode, IVAS_CPE_DFT ) ) )
     413             :         {
     414      543121 :             tnsAllowed = 1;
     415      543121 :             move16();
     416             :         }
     417             :     }
     418             :     ELSE
     419             :     {
     420      287903 :         if ( GT_32( total_brate, HQ_32k ) )
     421             :         {
     422      269362 :             tnsAllowed = 1;
     423      269362 :             move16();
     424             :         }
     425             :     }
     426             : 
     427      899606 :     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       47845 : Word16 getMdctWindowLength_fx(
     475             :     const Word16 fscale /*Q0*/ )
     476             : {
     477             :     Word16 mdctWindowLength;
     478       47845 :     mdctWindowLength = extract_l( L_shr( L_mult0( L_LOOK_12k8, fscale ), LD_FSCALE_DENOM ) );
     479             : 
     480       47845 :     return mdctWindowLength; /*Q0*/
     481             : }
     482             : 
     483             : /*-------------------------------------------------------------------*
     484             :  * sr2fscale()
     485             :  *
     486             :  *
     487             :  *-------------------------------------------------------------------*/
     488     1940374 : Word16 sr2fscale_fx(
     489             :     const Word32 sr_core /* i  : internal sampling rate    Q0*/
     490             : )
     491             : {
     492     1940374 :     return extract_l( Mpy_32_16_1( sr_core, FSCALE_DENOM_BY_12800_Q15 ) ); /*Q0*/
     493             : }
     494             : 
     495       48030 : int16_t sr2fscale(
     496             :     const int32_t sr_core /* i  : internal sampling rate    */
     497             : )
     498             : {
     499             : 
     500       48030 :     return (int16_t) ( ( FSCALE_DENOM * sr_core ) / 12800 );
     501             : }
     502             : 
     503      897205 : 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      897205 :     sr_core = -1; /* to suppress MSVC warning */
     516      897205 :     move32();
     517             : 
     518      897205 :     bwd_swb_or_fb_flag = s_or( (Word16) EQ_16( bwidth, SWB ), (Word16) EQ_16( bwidth, FB ) );
     519      897205 :     test();
     520      897205 :     test();
     521      897205 :     test();
     522      897205 :     test();
     523      897205 :     test();
     524      897205 :     test();
     525      897205 :     test();
     526      897205 :     test();
     527      897205 :     test();
     528      897205 :     test();
     529      897205 :     test();
     530      897205 :     test();
     531      897205 :     test();
     532      897205 :     test();
     533      897205 :     test();
     534      897205 :     test();
     535      897205 :     test();
     536      897205 :     test();
     537      897205 :     test();
     538      897205 :     test();
     539      897205 :     test();
     540      897205 :     test();
     541      897205 :     test();
     542      897205 :     IF( EQ_16( bwidth, NB ) )
     543             :     {
     544        7236 :         sr_core = INT_FS_12k8;
     545        7236 :         move32();
     546             :     }
     547      889969 :     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          40 :         sr_core = INT_FS_12k8;
     551          40 :         move32();
     552             :     }
     553      889929 :     ELSE IF( GT_16( element_mode, EVS_MONO ) && flag_ACELP16k == 0 )
     554             :     {
     555       53745 :         sr_core = INT_FS_12k8;
     556       53745 :         move32();
     557             :     }
     558      836184 :     ELSE IF( EQ_32( bwidth, WB ) || ( ( LE_32( total_brate, ACELP_32k ) ) && ( ( EQ_32( bwidth, SWB ) ) || ( EQ_32( bwidth, FB ) ) ) ) )
     559             :     {
     560      129548 :         sr_core = INT_FS_16k;
     561      129548 :         move32();
     562             :     }
     563      706636 :     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      706124 :     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        7768 :         sr_core = INT_FS_16k;
     571        7768 :         move32();
     572             :     }
     573      698356 :     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        7987 :         sr_core = 25600;
     576        7987 :         move32();
     577             :     }
     578      690369 :     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      268648 :         sr_core = 25600;
     581      268648 :         move32();
     582             :     }
     583      421721 :     ELSE IF( bwd_swb_or_fb_flag )
     584             :     {
     585      421721 :         sr_core = 32000;
     586      421721 :         move32();
     587             :     }
     588             :     ELSE
     589             :     {
     590           0 :         assert( 0 );
     591             :     }
     592             : 
     593      897205 :     return sr_core; /*Q0*/
     594             : }
     595             : 
     596       52400 : Word16 getTcxBandwidth(
     597             :     const Word16 bwidth /* i  : audio bandwidth        Q0*/
     598             : )
     599             : {
     600             : 
     601             :     Word16 tcxBandwidth;
     602             : 
     603       52400 :     tcxBandwidth = 16384 /*0.5f Q15*/;
     604       52400 :     move16();
     605       52400 :     if ( EQ_16( bwidth, NB ) )
     606             :     {
     607        9764 :         tcxBandwidth = 10240 /*0.3125f Q15*/;
     608        9764 :         move16();
     609             :     }
     610             : 
     611       52400 :     return tcxBandwidth; /*Q15*/
     612             : }
     613             : 
     614             : 
     615      870268 : 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      870268 :     igfPresent = 0;
     624      870268 :     move16();
     625             : 
     626      870268 :     IF( EQ_16( bwidth, SWB ) )
     627             :     {
     628      240313 :         SWITCH( element_mode )
     629             :         {
     630       55698 :             case EVS_MONO:
     631             :             case IVAS_SCE:
     632       55698 :                 if ( LE_32( total_brate, HQ_64k ) )
     633             :                 {
     634       54415 :                     igfPresent = 1;
     635       54415 :                     move16();
     636             :                 }
     637       55698 :                 BREAK;
     638        9296 :             case IVAS_CPE_DFT:
     639             :             case IVAS_CPE_TD:
     640        9296 :                 if ( LE_32( total_brate, HQ_48k ) )
     641             :                 {
     642        9296 :                     igfPresent = 1;
     643        9296 :                     move16();
     644             :                 }
     645        9296 :                 BREAK;
     646      175319 :             case IVAS_CPE_MDCT:
     647      175319 :                 if ( LE_32( total_brate, IVAS_96k ) )
     648             :                 {
     649      110053 :                     igfPresent = 1;
     650      110053 :                     move16();
     651             :                 }
     652      175319 :                 BREAK;
     653             :         }
     654      240313 :     }
     655      629955 :     ELSE IF( EQ_16( bwidth, FB ) )
     656             :     {
     657      559871 :         SWITCH( element_mode )
     658             :         {
     659      146920 :             case EVS_MONO:
     660             :             case IVAS_SCE:
     661      146920 :                 if ( LE_32( total_brate, IVAS_128k ) )
     662             :                 {
     663      146467 :                     igfPresent = 1;
     664      146467 :                     move16();
     665             :                 }
     666      146920 :                 BREAK;
     667        3085 :             case IVAS_CPE_DFT:
     668             :             case IVAS_CPE_TD:
     669        3085 :                 if ( LE_32( total_brate, IVAS_48k ) )
     670             :                 {
     671        3085 :                     igfPresent = 1;
     672        3085 :                     move16();
     673             :                 }
     674        3085 :                 BREAK;
     675      409866 :             case IVAS_CPE_MDCT:
     676      409866 :                 if ( LE_32( total_brate, IVAS_128k ) )
     677             :                 {
     678      270739 :                     igfPresent = 1;
     679      270739 :                     move16();
     680             :                 }
     681      409866 :                 BREAK;
     682             :         }
     683      559871 :     }
     684       70084 :     ELSE IF( EQ_16( bwidth, WB ) )
     685             :     {
     686       69992 :         SWITCH( element_mode )
     687             :         {
     688        7118 :             case EVS_MONO:
     689             :             case IVAS_SCE:
     690        7118 :                 if ( LE_32( total_brate, ACELP_9k60 ) )
     691             :                 {
     692         115 :                     igfPresent = 1;
     693         115 :                     move16();
     694             :                 }
     695        7118 :                 BREAK;
     696       62874 :             case IVAS_CPE_DFT:
     697             :             case IVAS_CPE_TD:
     698             :             case IVAS_CPE_MDCT:
     699       62874 :                 if ( LE_32( total_brate, ACELP_13k20 ) )
     700             :                 {
     701        1370 :                     igfPresent = 1;
     702        1370 :                     move16();
     703             :                 }
     704       62874 :                 BREAK;
     705             :         }
     706          92 :     }
     707      870268 :     test();
     708      870268 :     test();
     709      870268 :     test();
     710      870268 :     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      870268 :     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      898699 : Word16 getTcxLtp(
     756             :     const Word32 sr_core /* i  : internal sampling rate Q0*/
     757             : )
     758             : {
     759             :     Word16 tcxltp;
     760             : 
     761      898699 :     tcxltp = 0;
     762      898699 :     move16();
     763             : 
     764      898699 :     if ( ( LE_32( sr_core, 25600 ) ) )
     765             :     {
     766      476743 :         tcxltp = 1;
     767      476743 :         move16();
     768             :     }
     769             : 
     770      898699 :     return tcxltp; /*Q0*/
     771             : }
     772             : 
     773             : /*-------------------------------------------------------------------*
     774             :  * initPitchLagParameters()
     775             :  *
     776             :  *
     777             :  *-------------------------------------------------------------------*/
     778             : 
     779       28570 : 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       28570 :     IF( EQ_32( sr_core, INT_FS_12k8 ) )
     790             :     {
     791       22272 :         *pit_min = PIT_MIN_12k8;
     792       22272 :         move16();
     793       22272 :         *pit_max = PIT_MAX_12k8;
     794       22272 :         move16();
     795       22272 :         *pit_fr2 = PIT_FR2_12k8;
     796       22272 :         move16();
     797       22272 :         *pit_fr1 = PIT_FR1_12k8;
     798       22272 :         move16();
     799       22272 :         *pit_fr1b = PIT_FR1_8b_12k8;
     800       22272 :         move16();
     801       22272 :         pit_res_max = 4;
     802       22272 :         move16();
     803             :     }
     804        6298 :     ELSE IF( EQ_32( sr_core, INT_FS_16k ) )
     805             :     {
     806        5002 :         *pit_min = PIT_MIN_16k;
     807        5002 :         move16();
     808        5002 :         *pit_max = PIT16k_MAX;
     809        5002 :         move16();
     810        5002 :         *pit_fr2 = PIT_FR2_16k;
     811        5002 :         move16();
     812        5002 :         *pit_fr1 = PIT_FR1_16k;
     813        5002 :         move16();
     814        5002 :         *pit_fr1b = PIT_FR1_8b_16k;
     815        5002 :         move16();
     816        5002 :         pit_res_max = 6;
     817        5002 :         move16();
     818             :     }
     819        1296 :     ELSE IF( EQ_32( sr_core, 25600 ) )
     820             :     {
     821         378 :         *pit_min = PIT_MIN_25k6;
     822         378 :         move16();
     823         378 :         *pit_max = PIT_MAX_25k6;
     824         378 :         move16();
     825         378 :         *pit_fr2 = PIT_FR2_25k6;
     826         378 :         move16();
     827         378 :         *pit_fr1 = PIT_FR1_25k6;
     828         378 :         move16();
     829         378 :         *pit_fr1b = PIT_FR1_8b_25k6;
     830         378 :         move16();
     831         378 :         pit_res_max = 4;
     832         378 :         move16();
     833             :     }
     834             :     ELSE /* sr_core==32000 */
     835             :     {
     836         918 :         *pit_min = PIT_MIN_32k;
     837         918 :         move16();
     838         918 :         *pit_max = PIT_MAX_32k;
     839         918 :         move16();
     840         918 :         *pit_fr2 = PIT_FR2_32k;
     841         918 :         move16();
     842         918 :         *pit_fr1 = PIT_FR1_32k;
     843         918 :         move16();
     844         918 :         *pit_fr1b = PIT_FR1_8b_32k;
     845         918 :         move16();
     846         918 :         pit_res_max = 6;
     847         918 :         move16();
     848             :     }
     849             : 
     850       28570 :     return pit_res_max; /*Q0*/
     851             : }
     852             : 
     853             : /*-------------------------------------------------------------------*
     854             :  * getNumTcxCodedLines()
     855             :  *
     856             :  *
     857             :  *-------------------------------------------------------------------*/
     858             : 
     859      309196 : Word16 getNumTcxCodedLines(
     860             :     const Word16 bwidth /* i  : audio bandwidth        Q0*/
     861             : )
     862             : {
     863             :     Word16 tcx_coded_lines;
     864             : 
     865      309196 :     tcx_coded_lines = 0;
     866      309196 :     move16();
     867             : 
     868      309196 :     SWITCH( bwidth )
     869             :     {
     870        2531 :         case NB:
     871        2531 :             tcx_coded_lines = 160;
     872        2531 :             move16();
     873        2531 :             BREAK;
     874       28292 :         case WB:
     875       28292 :             tcx_coded_lines = 320;
     876       28292 :             move16();
     877       28292 :             BREAK;
     878       90957 :         case SWB:
     879       90957 :             tcx_coded_lines = 640;
     880       90957 :             move16();
     881       90957 :             BREAK;
     882      187416 :         case FB:
     883      187416 :             tcx_coded_lines = 960;
     884      187416 :             move16();
     885      187416 :             BREAK;
     886           0 :         default:
     887           0 :             tcx_coded_lines = 0;
     888           0 :             move16();
     889           0 :             BREAK;
     890             :     }
     891             : 
     892      309196 :     return tcx_coded_lines; /*Q0*/
     893             : }
     894             : 
     895             : /*-------------------------------------------------------------------*
     896             :  * getTcxLpcShapedAri()
     897             :  *
     898             :  *
     899             :  *-------------------------------------------------------------------*/
     900             : 
     901      875774 : 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      875774 :     tcx_lpc_shaped_ari = 0;
     909      875774 :     move16();
     910             : 
     911      875774 :     test();
     912      875774 :     test();
     913      875774 :     test();
     914      875774 :     test();
     915      875774 :     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       22776 :         tcx_lpc_shaped_ari = 1;
     918       22776 :         move16();
     919             :     }
     920             : 
     921      875774 :     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       24015 : 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       24015 :     hTcxCfg->tcx_mdct_window_delay = mdctWindowLength;
    1092       24015 :     hTcxCfg->tcx_mdct_window_delayFB = mdctWindowLengthFB;
    1093       24015 :     hTcxCfg->tcx_mdct_window_length = mdctWindowLength;
    1094       24015 :     hTcxCfg->tcx_mdct_window_lengthFB = mdctWindowLengthFB;
    1095       24015 :     move16();
    1096       24015 :     move16();
    1097       24015 :     move16();
    1098       24015 :     move16();
    1099       24015 :     mdct_window_sine_IVAS_updated( hTcxCfg->tcx_mdct_window, sr_core, hTcxCfg->tcx_mdct_window_length, FULL_OVERLAP, element_mode );
    1100             : 
    1101       24015 :     IF( EQ_16( hTcxCfg->tcx_mdct_window_length, hTcxCfg->tcx_mdct_window_lengthFB ) )
    1102             :     {
    1103        1569 :         Copy_pword( hTcxCfg->tcx_mdct_window, hTcxCfg->tcx_mdct_windowFB, shr( hTcxCfg->tcx_mdct_window_length, 1 ) ); /*Q15*/
    1104             :     }
    1105             :     ELSE
    1106             :     {
    1107       22446 :         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       24015 :     mdct_window_aldo( hTcxCfg->tcx_aldo_window_1, hTcxCfg->tcx_aldo_window_1_trunc, hTcxCfg->tcx_aldo_window_2, L_frame );
    1112       24015 :     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       24015 :     hTcxCfg->tcx_mdct_window_trans_length = NS2SA_FX2( sr_core, ACELP_TCX_TRANS_NS ); /*Q0*/
    1116       24015 :     move16();
    1117       24015 :     mdct_window_sine_IVAS_updated( hTcxCfg->tcx_mdct_window_trans, sr_core, hTcxCfg->tcx_mdct_window_trans_length, TRANSITION_OVERLAP, element_mode );
    1118       24015 :     hTcxCfg->tcx_mdct_window_trans_lengthFB = NS2SA_FX2( input_Fs, ACELP_TCX_TRANS_NS ); /*Q0*/
    1119       24015 :     move16();
    1120       24015 :     IF( EQ_16( hTcxCfg->tcx_mdct_window_trans_length, hTcxCfg->tcx_mdct_window_trans_lengthFB ) )
    1121             :     {
    1122        1569 :         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       22446 :         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       24015 :     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       24015 :     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       24015 :     move16();
    1133       24015 :     move16();
    1134       24015 :     assert( GT_16( hTcxCfg->tcx_mdct_window_half_length, 16 ) && "Half window can not be large enough!" );
    1135             : 
    1136       24015 :     mdct_window_sine_IVAS_updated( hTcxCfg->tcx_mdct_window_half, sr_core, hTcxCfg->tcx_mdct_window_half_length, HALF_OVERLAP, element_mode );
    1137       24015 :     IF( EQ_16( hTcxCfg->tcx_mdct_window_half_length, hTcxCfg->tcx_mdct_window_half_lengthFB ) )
    1138             :     {
    1139        1569 :         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       22446 :         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       24015 :     hTcxCfg->tcx_mdct_window_min_length = shr( L_frame, 4 );      /* 1.25ms */
    1148       24015 :     hTcxCfg->tcx_mdct_window_min_lengthFB = shr( L_frameTCX, 4 ); /* 1.25ms */
    1149       24015 :     move16();
    1150       24015 :     move16();
    1151             :     /* save complexity by copying the small windows if they have the same length */
    1152       24015 :     IF( EQ_16( hTcxCfg->tcx_mdct_window_min_length, hTcxCfg->tcx_mdct_window_trans_length ) )
    1153             :     {
    1154       24015 :         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       24015 :     IF( EQ_16( hTcxCfg->tcx_mdct_window_min_lengthFB, hTcxCfg->tcx_mdct_window_trans_lengthFB ) )
    1162             :     {
    1163       24015 :         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       24015 :     hTcxCfg->tcx_offset = shr( hTcxCfg->tcx_mdct_window_delay, 1 );     /*Q0*/
    1175       24015 :     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       24015 :     hTcxCfg->lfacNext = sub( hTcxCfg->tcx_offset, shr( L_frame, 2 ) );
    1178       24015 :     hTcxCfg->lfacNextFB = sub( hTcxCfg->tcx_offsetFB, shr( L_frameTCX, 2 ) );
    1179       24015 :     move16();
    1180       24015 :     move16();
    1181       24015 :     move16();
    1182       24015 :     move16();
    1183             : 
    1184       24015 :     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             : }

Generated by: LCOV version 1.14