LCOV - code coverage report
Current view: top level - lib_dec - ivas_decision_matrix_dec_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main enc/dec/rend @ 3b2f07138c61dcf997bbf4165d0882f794b2995f Lines: 306 318 96.2 %
Date: 2025-05-03 01:55:50 Functions: 1 1 100.0 %

          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             : #include <stdint.h>
      34             : #include "options.h"
      35             : #include "stat_dec.h"
      36             : #include "rom_com.h"
      37             : #include "prot_fx.h"
      38             : #include "ivas_cnst.h"
      39             : #include "wmc_auto.h"
      40             : #include "ivas_prot_fx.h"
      41             : 
      42             : /*-----------------------------------------------------------------*
      43             :  * ivas_decision_matrix_dec()
      44             :  *
      45             :  * ACELP/TCX/HQ core selection
      46             :  * Read ACELP signaling bits from the bitstream
      47             :  * Set extension layers
      48             :  *-----------------------------------------------------------------*/
      49             : static Word16 get_next_index_4_by_15[16] = {
      50             :     0, 2184, 4369, 6553, 8738, 10922, 13107, 15291, 17476, 19660, 21845, 24029, 26214, 28398, 30583, 32767
      51             : };
      52     1012562 : void ivas_decision_matrix_dec_fx(
      53             :     Decoder_State *st,           /* i/o: decoder state structure             */
      54             :     Word16 *sharpFlag,           /* o  : formant sharpening flag             */
      55             :     Word16 *core_switching_flag, /* o  : ACELP->HQ switching frame flag      */
      56             :     const Word32 element_brate,  /* i  : element bitrate                     */
      57             :     const Word16 nchan_out       /* i  : Number of output channels           */
      58             : )
      59             : {
      60             :     Word16 tmp;
      61             :     Word32 icbwe_brate;
      62             : 
      63             :     /* init */
      64     1012562 :     icbwe_brate = 0;
      65     1012562 :     move32();
      66     1012562 :     st->core = -1;
      67     1012562 :     move16();
      68     1012562 :     st->core_brate = 0;
      69     1012562 :     move32();
      70     1012562 :     st->extl = -1;
      71     1012562 :     move16();
      72     1012562 :     st->extl_brate = 0;
      73     1012562 :     move32();
      74     1012562 :     st->ppp_mode_dec = 0;
      75     1012562 :     move16();
      76     1012562 :     st->nelp_mode_dec = 0;
      77     1012562 :     move16();
      78     1012562 :     st->igf = 0;
      79     1012562 :     move16();
      80     1012562 :     st->vbr_hw_BWE_disable_dec = 0;
      81     1012562 :     move16();
      82             : 
      83             :     /*-----------------------------------------------------------------*
      84             :      * Read SID signaling bits from the bitstream
      85             :      *-----------------------------------------------------------------*/
      86             : 
      87     1012562 :     test();
      88     1012562 :     test();
      89     1012562 :     test();
      90     1012562 :     test();
      91     1012562 :     IF( ( st->idchan == 0 && ( ( st->total_brate == FRAME_NO_DATA ) || EQ_32( st->total_brate, SID_2k40 ) ) ) || ( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && LE_32( st->total_brate, SID_2k40 ) ) )
      92             :     {
      93       26082 :         st->core = ACELP_CORE;
      94       26082 :         move16();
      95       26082 :         st->core_brate = st->total_brate;
      96       26082 :         move32();
      97             : 
      98       26082 :         test();
      99       26082 :         test();
     100       26082 :         test();
     101       26082 :         test();
     102       26082 :         test();
     103       26082 :         IF( EQ_32( st->total_brate, SID_2k40 ) && !( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) )
     104             :         {
     105        2907 :             IF( NE_16( st->element_mode, IVAS_CPE_DFT ) )
     106             :             {
     107        1415 :                 st->cng_type = get_next_indice_fx( st, 1 );
     108        1415 :                 move16();
     109             : 
     110        1415 :                 IF( EQ_16( st->cng_type, FD_CNG ) )
     111             :                 {
     112        1415 :                     st->bwidth = get_next_indice_fx( st, 2 );
     113        1415 :                     move16();
     114             :                 }
     115             :             }
     116        2907 :             IF( get_next_indice_fx( st, 1 ) )
     117             :             {
     118        1683 :                 st->L_frame = L_FRAME16k;
     119        1683 :                 move16();
     120             :             }
     121             :             ELSE
     122             :             {
     123        1224 :                 st->L_frame = L_FRAME;
     124        1224 :                 move16();
     125             :             }
     126             :         }
     127       23175 :         ELSE IF( EQ_32( st->total_brate, SID_2k40 ) && EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_MDCT ) && st->cng_sba_flag == 0 )
     128             :         {
     129             :             /* read channel coherence */
     130             :             Word16 index;
     131         410 :             index = get_next_indice_fx( st, 4 );
     132         410 :             st->hFdCngDec->hFdCngCom->coherence_fx = get_next_index_4_by_15[index];
     133         410 :             move16();
     134             : 
     135             : 
     136             :             /* read flag for no side noise shape */
     137         410 :             st->hFdCngDec->hFdCngCom->no_side_flag = get_next_indice_fx( st, 1 );
     138         410 :             move16();
     139             :         }
     140             : 
     141       26082 :         test();
     142       26082 :         test();
     143       26082 :         test();
     144       26082 :         test();
     145       26082 :         test();
     146       26082 :         if ( ( GE_32( st->output_Fs, 32000 ) && GE_16( st->bwidth, SWB ) ) || ( EQ_16( st->element_mode, IVAS_CPE_DFT ) && GE_16( st->bwidth, SWB ) && EQ_16( nchan_out, 2 ) && LT_16( st->L_frame, L_FRAME16k ) ) )
     147             :         {
     148       18718 :             st->extl = SWB_CNG;
     149       18718 :             move16();
     150             :         }
     151             : 
     152       26082 :         test();
     153       26082 :         test();
     154       26082 :         test();
     155       26082 :         if ( ( st->total_brate == FRAME_NO_DATA ) && st->prev_bfi && !st->bfi && GT_16( st->L_frame, L_FRAME16k ) )
     156             :         {
     157           0 :             st->L_frame = st->last_CNG_L_frame;
     158           0 :             move16();
     159             :         }
     160             : 
     161       26082 :         return;
     162             :     }
     163             : 
     164             :     /*---------------------------------------------------------------------*
     165             :      * ACELP/HQ core selection
     166             :      *---------------------------------------------------------------------*/
     167             : 
     168      986480 :     test();
     169      986480 :     test();
     170      986480 :     IF( EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( st->idchan, 1 ) )
     171             :     {
     172             :         /* minimal signaling for the secondary channel, most of the parameters are deduced from the primary channel */
     173        3695 :         st->core = ACELP_CORE;
     174        3695 :         move16();
     175             :     }
     176      982785 :     ELSE IF( EQ_16( st->element_mode, IVAS_SCE ) && st->low_rate_mode )
     177             :     {
     178             :         /* ISM Low-rate mode -> always WB, ACELP core, IC coder_type */
     179        6736 :         st->core = ACELP_CORE;
     180        6736 :         move16();
     181             :     }
     182      976049 :     ELSE IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) )
     183             :     {
     184      628078 :         st->core = TCX_20_CORE;
     185      628078 :         move16();
     186             :     }
     187             :     ELSE
     188             :     {
     189      347971 :         st->core = ACELP_CORE;
     190      347971 :         move16();
     191             : 
     192      347971 :         test();
     193      347971 :         IF( EQ_16( st->element_mode, IVAS_CPE_TD ) || GE_32( st->total_brate, STEREO_TCX_MIN_RATE ) )
     194             :         {
     195             :             /* ACELP/transform core selection bit */
     196      340616 :             IF( get_next_indice_fx( st, 1 ) )
     197             :             {
     198      219699 :                 st->core = HQ_CORE;
     199      219699 :                 move16();
     200             :             }
     201             :             ELSE
     202             :             {
     203      120917 :                 st->core = ACELP_CORE;
     204      120917 :                 move16();
     205             :             }
     206             :         }
     207             :     }
     208             : 
     209             :     /*-----------------------------------------------------------------*
     210             :      * Read ACELP signaling bits from the bitstream
     211             :      *-----------------------------------------------------------------*/
     212             : 
     213      986480 :     IF( EQ_16( st->core, ACELP_CORE ) )
     214             :     {
     215      138703 :         test();
     216      138703 :         test();
     217      138703 :         IF( EQ_16( st->element_mode, IVAS_SCE ) && st->low_rate_mode )
     218             :         {
     219             :             /* ISM Low-rate mode */
     220        6736 :             st->bwidth = WB;
     221        6736 :             move16();
     222        6736 :             st->coder_type = INACTIVE;
     223        6736 :             move16();
     224        6736 :             *sharpFlag = 0;
     225        6736 :             move16();
     226             :         }
     227      131967 :         ELSE IF( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) )
     228             :         {
     229        3695 :             *sharpFlag = 0;
     230        3695 :             move16();
     231        3695 :             test();
     232        3695 :             if ( EQ_16( st->coder_type, GENERIC ) || EQ_16( st->coder_type, VOICED ) )
     233             :             {
     234        3600 :                 *sharpFlag = 1;
     235        3600 :                 move16();
     236             :             }
     237             : 
     238        3695 :             st->core_brate = st->total_brate;
     239        3695 :             move32();
     240        3695 :             st->codec_mode = MODE1;
     241        3695 :             move16();
     242             : 
     243        3695 :             test();
     244        3695 :             test();
     245        3695 :             if ( EQ_16( st->idchan, 1 ) && ( st->tdm_LRTD_flag == 0 || LT_16( st->bits_frame_channel, IVAS_16k4 / FRAMES_PER_SEC ) ) )
     246             :             {
     247         126 :                 st->bwidth = WB; /* only WB in the secondary channel */
     248         126 :                 move16();
     249             :             }
     250             :         }
     251             :         ELSE
     252             :         {
     253      128272 :             IF( LT_32( element_brate, FRMT_SHP_MIN_BRATE_IVAS ) )
     254             :             {
     255       59795 :                 st->coder_type = get_next_indice_fx( st, 3 );
     256       59795 :                 move16();
     257       59795 :                 *sharpFlag = 0;
     258       59795 :                 move16();
     259             : 
     260       59795 :                 test();
     261       59795 :                 test();
     262       59795 :                 test();
     263       59795 :                 if ( LT_32( element_brate, IVAS_24k4 ) && ( EQ_16( st->coder_type, VOICED ) || EQ_16( st->coder_type, GENERIC ) || EQ_16( st->coder_type, TRANSITION ) ) )
     264             :                 {
     265       47363 :                     *sharpFlag = 1;
     266       47363 :                     move16();
     267             :                 }
     268             :             }
     269             :             ELSE
     270             :             {
     271             :                 /* get coder_type info */
     272       68477 :                 st->coder_type = get_next_indice_fx( st, 3 );
     273       68477 :                 move16();
     274             :                 /* get sharpening flag */
     275       68477 :                 *sharpFlag = get_next_indice_fx( st, 1 );
     276       68477 :                 move16();
     277             :             }
     278             :         }
     279             :     }
     280             : 
     281             :     /*-----------------------------------------------------------------*
     282             :      * Set extension layers
     283             :      *-----------------------------------------------------------------*/
     284             : 
     285      986480 :     IF( EQ_16( st->core, ACELP_CORE ) )
     286             :     {
     287      138703 :         test();
     288      138703 :         test();
     289      138703 :         test();
     290      138703 :         test();
     291      138703 :         test();
     292      138703 :         test();
     293      138703 :         test();
     294      138703 :         IF( EQ_16( st->bwidth, WB ) && st->low_rate_mode )
     295             :         {
     296        6736 :             st->extl = WB_BWE;
     297        6736 :             move16();
     298        6736 :             if ( GE_32( st->total_brate, MIN_BRATE_WB_BWE ) )
     299             :             {
     300          61 :                 st->extl_brate = WB_BWE_0k35;
     301          61 :                 move32();
     302             :             }
     303             :         }
     304      131967 :         ELSE IF( EQ_16( st->bwidth, WB ) && ( LT_32( st->total_brate, MIN_BRATE_WB_BWE ) || ( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) ) ) )
     305             :         {
     306         902 :             if ( st->vbr_hw_BWE_disable_dec == 0 )
     307             :             {
     308         902 :                 st->extl = WB_BWE;
     309         902 :                 move16();
     310             :             }
     311             :         }
     312      131065 :         ELSE IF( EQ_16( st->bwidth, WB ) && GE_32( st->total_brate, MIN_BRATE_WB_BWE ) && !st->flag_ACELP16k )
     313             :         {
     314             :             /* read the WB TBE/BWE selection bit */
     315       10950 :             IF( get_next_indice_fx( st, 1 ) )
     316             :             {
     317        4031 :                 st->extl = WB_BWE;
     318        4031 :                 move16();
     319        4031 :                 st->extl_brate = WB_BWE_0k35;
     320        4031 :                 move32();
     321             :             }
     322             :             ELSE
     323             :             {
     324        6919 :                 st->extl = WB_TBE;
     325        6919 :                 move16();
     326        6919 :                 test();
     327        6919 :                 test();
     328        6919 :                 IF( LT_32( st->total_brate, MIN_BRATE_WB_TBE_1k05 ) || ( EQ_16( st->element_mode, IVAS_CPE_TD ) && LT_32( st->total_brate, MIN_TDM_BRATE_WB_TBE_1k05 ) ) )
     329             :                 {
     330        2435 :                     st->extl_brate = WB_TBE_0k35;
     331        2435 :                     move32();
     332             :                 }
     333             :                 ELSE
     334             :                 {
     335        4484 :                     st->extl_brate = WB_TBE_1k05;
     336        4484 :                     move32();
     337             :                 }
     338             :             }
     339             :         }
     340      120115 :         ELSE IF( EQ_16( st->bwidth, SWB ) || EQ_16( st->bwidth, FB ) )
     341             :         {
     342      111643 :             test();
     343      111643 :             test();
     344      111643 :             test();
     345      111643 :             test();
     346      111643 :             test();
     347      111643 :             test();
     348      111643 :             test();
     349      111643 :             test();
     350      111643 :             IF( GE_32( st->total_brate, MIN_BRATE_SWB_BWE ) || ( GE_32( st->total_brate, MIN_MIN_BRATE_LRTD_SWB_BWE ) && EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( st->bwidth, SWB ) && st->tdm_LRTD_flag ) || ( LT_32( element_brate, IVAS_16k4 ) && GE_32( st->total_brate, MIN_MIN_BRATE_LRTD_SWB_BWE ) && EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( st->bwidth, SWB ) ) )
     351             :             {
     352             :                 /* read the SWB TBE/BWE selection bit */
     353      111643 :                 tmp = get_next_indice_fx( st, 1 );
     354             : 
     355      111643 :                 IF( tmp )
     356             :                 {
     357        9673 :                     st->extl = SWB_BWE;
     358        9673 :                     move16();
     359        9673 :                     st->extl_brate = SWB_BWE_1k6;
     360        9673 :                     move32();
     361             :                 }
     362             :                 ELSE
     363             :                 {
     364      101970 :                     st->extl = SWB_TBE;
     365      101970 :                     move16();
     366      101970 :                     st->extl_brate = SWB_TBE_1k6;
     367      101970 :                     move32();
     368      101970 :                     test();
     369      101970 :                     test();
     370      101970 :                     test();
     371      101970 :                     IF( GE_32( st->total_brate, MIN_BRATE_SWB_TBE_2k80 ) && st->flag_ACELP16k && EQ_16( st->element_mode, IVAS_SCE ) )
     372             :                     {
     373       20876 :                         st->extl_brate = SWB_TBE_2k8;
     374       20876 :                         move32();
     375             :                     }
     376       81094 :                     ELSE IF( EQ_16( st->tdm_LRTD_flag, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) )
     377             :                     {
     378        5504 :                         IF( LT_32( st->element_brate, IVAS_24k4 ) )
     379             :                         {
     380         866 :                             st->extl_brate = SWB_TBE_1k10;
     381         866 :                             move32();
     382             :                         }
     383             :                         ELSE
     384             :                         {
     385        4638 :                             st->extl_brate = SWB_TBE_1k75;
     386        4638 :                             move32();
     387             :                         }
     388             :                     }
     389       75590 :                     ELSE IF( LT_32( st->total_brate, MIN_BRATE_SWB_TBE_1k60 ) )
     390             :                     {
     391       25807 :                         st->extl_brate = SWB_TBE_0k95;
     392       25807 :                         move32();
     393             :                     }
     394             :                 }
     395             :             }
     396             :             ELSE
     397             :             {
     398           0 :                 st->extl = WB_BWE;
     399           0 :                 move16();
     400           0 :                 st->extl_brate = 0;
     401           0 :                 move32();
     402             :             }
     403             : 
     404             :             /* set FB TBE and FB BWE extension layers */
     405      111643 :             IF( EQ_16( st->bwidth, FB ) )
     406             :             {
     407       43738 :                 IF( EQ_16( st->extl, SWB_BWE ) )
     408             :                 {
     409        3995 :                     st->extl = FB_BWE;
     410        3995 :                     move16();
     411        3995 :                     st->extl_brate = FB_BWE_1k8;
     412        3995 :                     move32();
     413             :                 }
     414       39743 :                 ELSE IF( EQ_16( st->extl, SWB_TBE ) )
     415             :                 {
     416       39743 :                     st->extl = FB_TBE;
     417       39743 :                     move16();
     418       39743 :                     st->extl_brate = FB_TBE_1k8;
     419       39743 :                     move32();
     420       39743 :                     test();
     421       39743 :                     test();
     422       39743 :                     if ( GE_32( st->total_brate, MIN_BRATE_SWB_TBE_2k80 ) && st->flag_ACELP16k && EQ_16( st->element_mode, IVAS_SCE ) )
     423             :                     {
     424       17013 :                         st->extl_brate = FB_TBE_3k0;
     425       17013 :                         move32();
     426             :                     }
     427             :                 }
     428             :             }
     429             :             /* set IC-BWE bitrate */
     430      111643 :             test();
     431      111643 :             test();
     432      111643 :             IF( EQ_16( st->element_mode, IVAS_CPE_TD ) && !( GE_16( st->bwidth, SWB ) && st->tdm_LRTD_flag ) )
     433             :             {
     434          34 :                 icbwe_brate = STEREO_BITS_ICBWE * FRAMES_PER_SEC;
     435          34 :                 move32();
     436          34 :                 if ( st->flag_ACELP16k == 0 )
     437             :                 {
     438          12 :                     icbwe_brate = ( STEREO_BITS_ICBWE - STEREO_ICBWE_SPBITS ) * FRAMES_PER_SEC;
     439          12 :                     move32();
     440             :                 }
     441             :             }
     442      111609 :             ELSE IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) )
     443             :             {
     444       25893 :                 icbwe_brate = STEREO_BITS_ICBWE_DFT * FRAMES_PER_SEC;
     445       25893 :                 move32();
     446       25893 :                 if ( st->flag_ACELP16k == 0 )
     447             :                 {
     448       13142 :                     icbwe_brate = ( STEREO_BITS_ICBWE_DFT - STEREO_ICBWE_SPBITS ) * FRAMES_PER_SEC;
     449       13142 :                     move32();
     450             :                 }
     451             :             }
     452             : 
     453      111643 :             test();
     454      111643 :             test();
     455      111643 :             test();
     456      111643 :             test();
     457      111643 :             test();
     458      111643 :             if ( GE_16( st->element_mode, IVAS_CPE_DFT ) && ( st->core == ACELP_CORE ) && ( EQ_16( st->extl, SWB_TBE ) || EQ_16( st->extl, FB_TBE ) ) && !( EQ_16( st->element_mode, IVAS_CPE_TD ) && st->tdm_LRTD_flag ) )
     459             :             {
     460       23339 :                 icbwe_brate = L_add( icbwe_brate, STEREO_ICBWE_MSFLAG_BITS * FRAMES_PER_SEC );
     461             :             }
     462             :         }
     463             :     }
     464             : 
     465             :     /* set core bitrate */
     466      986480 :     st->core_brate = L_sub( L_sub( st->total_brate, st->extl_brate ), icbwe_brate );
     467      986480 :     move32();
     468             : 
     469             :     /*-----------------------------------------------------------------*
     470             :      * Read transform core (TCX vs. HQ) signaling bit from the bitstream
     471             :      *-----------------------------------------------------------------*/
     472             : 
     473      986480 :     test();
     474      986480 :     test();
     475      986480 :     test();
     476      986480 :     IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) && !( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) ) && EQ_16( st->core, HQ_CORE ) )
     477             :     {
     478      219699 :         IF( get_next_indice_fx( st, 1 ) )
     479             :         {
     480      212368 :             st->core = TCX_20_CORE;
     481      212368 :             move16();
     482             :         }
     483             :         ELSE
     484             :         {
     485        7331 :             st->core = HQ_CORE;
     486        7331 :             move16();
     487             :         }
     488             :     }
     489             : 
     490      986480 :     test();
     491      986480 :     IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) && EQ_16( st->core, TCX_20_CORE ) )
     492             :     {
     493      212368 :         st->extl = IGF_BWE;
     494      212368 :         move16();
     495      212368 :         st->extl_brate = 0;
     496      212368 :         move32();
     497             :     }
     498             : 
     499             :     /*-----------------------------------------------------------------*
     500             :      * Read ACELP->HQ core switching flag
     501             :      *-----------------------------------------------------------------*/
     502             : 
     503      986480 :     test();
     504      986480 :     IF( EQ_16( st->core, HQ_CORE ) || EQ_16( st->core, TCX_20_CORE ) )
     505             :     {
     506      847777 :         IF( EQ_16( st->core, HQ_CORE ) )
     507             :         {
     508             :             /* read ACELP->HQ core switching flag */
     509        7331 :             *core_switching_flag = get_next_indice_fx( st, 1 );
     510        7331 :             move16();
     511             :         }
     512             :         ELSE
     513             :         {
     514      840446 :             *core_switching_flag = 0;
     515      840446 :             move16();
     516             :         }
     517             : 
     518      847777 :         IF( EQ_16( *core_switching_flag, 1 ) )
     519             :         {
     520         185 :             st->last_core_from_bs = ACELP_CORE;
     521         185 :             move16();
     522             : 
     523         185 :             if ( EQ_16( st->core, st->last_core ) )
     524             :             {
     525             :                 /* A mismatch between the core_switching_flag and the st->core/st->last_core
     526             :                    indicates a frame was lost. if prev_bfi is not set the frame loss
     527             :                    occured during CNG and the prev_bfi needs to be set. */
     528           0 :                 st->prev_bfi = 1;
     529           0 :                 move16();
     530             :             }
     531             :         }
     532             :         ELSE
     533             :         {
     534      847592 :             st->last_core_from_bs = HQ_CORE; /* Could also be TCX, but it does not make any dIFference */
     535      847592 :             move16();
     536             :         }
     537             : 
     538      847777 :         st->last_L_frame_ori = st->last_L_frame;
     539      847777 :         move16();
     540             :     }
     541             : 
     542             :     /*-----------------------------------------------------------------*
     543             :      * Set ACELP frame length
     544             :      *-----------------------------------------------------------------*/
     545             : 
     546      986480 :     test();
     547      986480 :     test();
     548      986480 :     test();
     549      986480 :     test();
     550      986480 :     test();
     551      986480 :     test();
     552      986480 :     IF( EQ_32( st->core_brate, FRAME_NO_DATA ) )
     553             :     {
     554             :         /* prevent "L_frame" changes in CNG segments */
     555           0 :         st->L_frame = st->last_L_frame;
     556           0 :         move16();
     557             :     }
     558      986480 :     ELSE IF( EQ_32( st->core_brate, SID_2k40 ) && EQ_16( st->bwidth, WB ) && st->first_CNG && LT_16( st->hTdCngDec->act_cnt2, MIN_ACT_CNG_UPD ) )
     559             :     {
     560             :         /* prevent "L_frame" changes in SID frame after short segment of active frames */
     561           0 :         st->L_frame = st->last_CNG_L_frame;
     562           0 :         move16();
     563             :     }
     564      986480 :     ELSE IF( ( EQ_32( st->core_brate, SID_2k40 ) && GE_32( st->total_brate, ACELP_9k60 ) && EQ_16( st->bwidth, WB ) ) || st->flag_ACELP16k )
     565             :     {
     566      868320 :         st->L_frame = L_FRAME16k;
     567      868320 :         move16();
     568             :     }
     569             :     ELSE
     570             :     {
     571      118160 :         st->L_frame = L_FRAME;
     572      118160 :         move16();
     573             :     }
     574             : 
     575      986480 :     IF( EQ_16( st->L_frame, L_FRAME16k ) )
     576             :     {
     577      868320 :         st->nb_subfr = NB_SUBFR16k;
     578      868320 :         move16();
     579             :     }
     580             :     ELSE
     581             :     {
     582      118160 :         st->nb_subfr = NB_SUBFR;
     583      118160 :         move16();
     584             :     }
     585             : 
     586             :     /*-----------------------------------------------------------------*
     587             :      * set inactive coder_type flag in ACELP core
     588             :      *-----------------------------------------------------------------*/
     589             : 
     590      986480 :     st->inactive_coder_type_flag = 0; /* AVQ by default */
     591      986480 :     move16();
     592             : 
     593      986480 :     if ( LE_32( st->total_brate, MAX_GSC_INACTIVE_BRATE ) )
     594             :     {
     595      210272 :         st->inactive_coder_type_flag = 1; /* GSC */
     596      210272 :         move16();
     597             :     }
     598             : 
     599             :     /*-----------------------------------------------------------------*
     600             :      * Reconfigure in case when output_Fs < input_Fs
     601             :      *-----------------------------------------------------------------*/
     602             : 
     603      986480 :     st->extl_orig = st->extl;
     604      986480 :     move16();
     605      986480 :     st->extl_brate_orig = st->extl_brate;
     606      986480 :     move32();
     607             : 
     608             : 
     609      986480 :     test();
     610      986480 :     test();
     611      986480 :     IF( EQ_32( st->output_Fs, 16000 ) && EQ_16( st->L_frame, L_FRAME16k ) && NE_16( st->extl, IGF_BWE ) )
     612             :     {
     613       60925 :         st->extl = -1;
     614       60925 :         move16();
     615       60925 :         st->extl_brate = 0;
     616       60925 :         move32();
     617             :     }
     618             : 
     619      986480 :     IF( st->ini_frame == 0 )
     620             :     {
     621             :         /* avoid switching of internal ACELP Fs in the very first frame */
     622        7193 :         st->last_L_frame = st->L_frame;
     623        7193 :         move16();
     624        7193 :         st->last_core = st->core;
     625        7193 :         move16();
     626        7193 :         st->last_core_brate = st->core_brate;
     627        7193 :         move32();
     628        7193 :         st->last_extl = st->extl;
     629        7193 :         move16();
     630             :     }
     631             : 
     632      986480 :     return;
     633             : }

Generated by: LCOV version 1.14