LCOV - code coverage report
Current view: top level - lib_enc - ivas_decision_matrix_enc_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main enc/dec/rend @ 3b2f07138c61dcf997bbf4165d0882f794b2995f Lines: 258 264 97.7 %
Date: 2025-05-03 01:55:50 Functions: 2 2 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 "cnst.h"
      36             : #include "ivas_cnst.h"
      37             : #include "rom_com.h"
      38             : #include "prot_fx.h"
      39             : #include "ivas_rom_com.h"
      40             : #include "wmc_auto.h"
      41             : #include "ivas_prot_fx.h" /* Function prototypes                    */
      42             : #include "ivas_prot_fx.h" /* Function prototypes                    */
      43             : #include "prot_fx_enc.h"  /* Function prototypes                    */
      44             : 
      45             : /*-----------------------------------------------------------------*
      46             :  *  ivas_decision_matrix_enc()
      47             :  *
      48             :  *  Core technology selection in the IVAS codec
      49             :  *
      50             :  *  CPE
      51             :  *  bitrate    13.2          16.4          24.4           32            48            >48(*)
      52             :  * ----------------------------------------------------------------------------------------
      53             :  *  WB
      54             :  *  speech     ACELP         ACELP         ACELP          ACELP         ACELP         TCX
      55             :  *  music      GSC/TCX       GSC/TCX       TCX/HQ         TCX/HQ        TCX/HQ        TCX
      56             :  *  inactive   ACELP-I/TCX   ACELP-I/TCX   ACELP-I/TCX    ACELP-I/TCX   ACELP-I/TCX   TCX
      57             :  *
      58             :  *  SWB
      59             :  *  speech     ACELP         ACELP         ACELP          ACELP         ACELP         TCX
      60             :  *  music      GSC/TCX       GSD/TCX       TCX/HQ         TCX/HQ        TCX/HQ        TCX
      61             :  *  inactive   ACELP-I/TCX   ACELP-I/TCX   ACELP-I/TCX    ACELP-I/TCX   ACELP-I/TCX   TCX
      62             :  *
      63             :  *  FB
      64             :  *  speech                                                ACELP         ACELP         TCX
      65             :  *  music                                                 TCX/HQ        TCX/HQ        TCX
      66             :  *  inactive                                              ACELP-I/TCX   ACELP-I/TCX   TCX
      67             :  *
      68             :  * ACELP-I: GSC Inactive mode used for total_brate <= 28 kbps (total_brate), AVQ Inactive mode used otherwise
      69             :  * (*): TCX core is selected when total_brate > 48kbps, not CPE bitrate
      70             :  * Note: in MDCT stereo mode, TCX core is selected for all content
      71             :  * -------------------------------------------------------------------------------------------------------------------------------------------------------------*/
      72             : 
      73     1108119 : void ivas_decision_matrix_enc_fx(
      74             :     Encoder_State *st,          /* i  : encoder state structure                 */
      75             :     const Word32 element_brate, /* i  : element bitrate                         Q0*/
      76             :     const Word16 fft_buff[],    /* i  : FFT buffer                              Qx*/
      77             :     const Word32 enerBuffer[],  /* i  : energy buffer                                                   enerBuffer_exp*/
      78             :     Word16 enerBuffer_exp,
      79             :     const Word16 last_element_mode /* i  : last element mode                     Q0*/
      80             : )
      81             : {
      82             :     Word32 icbwe_brate;
      83             :     /* init */
      84     1108119 :     icbwe_brate = 0;
      85     1108119 :     move32();
      86             : 
      87             :     /* initialization */
      88     1108119 :     st->core = -1;
      89     1108119 :     move16();
      90             : 
      91     1108119 :     st->extl = -1;
      92     1108119 :     move16();
      93             : 
      94     1108119 :     st->extl_brate = 0;
      95     1108119 :     move16();
      96             : 
      97     1108119 :     if ( NE_16( st->element_mode, IVAS_CPE_MDCT ) )
      98             :     {
      99      414549 :         st->igf = 0;
     100      414549 :         move16();
     101             :     }
     102             : 
     103     1108119 :     test();
     104     1108119 :     test();
     105             : 
     106             :     /* SID and FRAME_NO_DATA frames */
     107     1108119 :     IF( st->Opt_DTX_ON && ( EQ_32( st->core_brate, SID_2k40 ) || st->core_brate == FRAME_NO_DATA ) )
     108             :     {
     109       22511 :         st->core = ACELP_CORE;
     110       22511 :         move16();
     111             : 
     112       22511 :         test();
     113       22511 :         if ( GE_32( st->input_Fs, 32000 ) || GE_16( st->bwidth, SWB ) )
     114             :         {
     115       17881 :             st->extl = SWB_CNG;
     116       17881 :             move16();
     117             :         }
     118       22511 :         st->rf_mode = 0;
     119       22511 :         move16();
     120             : 
     121       22511 :         return;
     122             :     }
     123             : 
     124             :     /*---------------------------------------------------------------------*
     125             :      * Select the core
     126             :      *---------------------------------------------------------------------*/
     127             : 
     128     1085608 :     test();
     129     1085608 :     test();
     130     1085608 :     test();
     131             : 
     132     1085608 :     IF( EQ_16( st->element_mode, IVAS_SCE ) && st->low_rate_mode )
     133             :     {
     134             :         /* ISM low-rate mode */
     135        7518 :         st->core = ACELP_CORE;
     136        7518 :         move16();
     137             : 
     138        7518 :         st->coder_type = INACTIVE;
     139        7518 :         move16();
     140             :     }
     141     1078090 :     ELSE IF( GT_32( st->total_brate, MAX_ACELP_BRATE ) )
     142             :     {
     143             :         /* highest bitrates */
     144      622475 :         st->core = TCX_20_CORE;
     145      622475 :         move16();
     146             :     }
     147      455615 :     ELSE IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) )
     148             :     {
     149             :         /* in MDCT stereo set TCX core */
     150      163720 :         st->core = TCX_20_CORE;
     151      163720 :         move16();
     152             :     }
     153      291895 :     ELSE IF( EQ_16( st->coder_type, INACTIVE ) )
     154             :     {
     155             :         /* inactive frames */
     156       17266 :         test();
     157       17266 :         IF( EQ_16( st->cng_type, FD_CNG ) && GE_32( st->total_brate, STEREO_TCX_MIN_RATE ) )
     158             :         {
     159       10462 :             st->core = TCX_20_CORE;
     160       10462 :             move16();
     161             :         }
     162             :         ELSE
     163             :         {
     164        6804 :             st->core = ACELP_CORE;
     165        6804 :             move16();
     166             :         }
     167             :     }
     168      274629 :     ELSE IF( st->sp_aud_decision1 == 0 && st->sp_aud_decision2 == 0 )
     169             :     {
     170             :         /* speech */
     171      132163 :         st->core = ACELP_CORE;
     172      132163 :         move16();
     173             :     }
     174      142466 :     ELSE IF( EQ_16( st->sp_aud_decision1, 1 ) && st->sp_aud_decision2 == 0 )
     175             :     {
     176             :         /* music w. GSC core */
     177        5721 :         st->core = ACELP_CORE;
     178             : 
     179        5721 :         move16();
     180             :     }
     181             :     ELSE /* sp_aud_decision1 == 1 && *sp_aud_decision2 == 1 */
     182             :     {
     183             :         /* music w. TCX or HQ core */
     184      136745 :         st->core = TCX_20_CORE;
     185      136745 :         move16();
     186             : 
     187      136745 :         test();
     188      136745 :         IF( EQ_16( st->element_mode, IVAS_CPE_TD ) || st->sp_aud_decision0 == 0 )
     189             :         {
     190       46498 :             st->core = TCX_20_CORE;
     191       46498 :             move16();
     192             :         }
     193             :         ELSE
     194             :         {
     195             :             /* select TCX core or HQ core using bits_frame_nominal to match the TCX configuration bitrate */
     196       90247 :             st->core = mdct_classifier_ivas_fx( st, fft_buff, enerBuffer, enerBuffer_exp, L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ) ); /* Q0 */
     197       90247 :             move16();
     198             :         }
     199             :     }
     200             : 
     201     1085608 :     test();
     202     1085608 :     test();
     203     1085608 :     test();
     204     1085608 :     test();
     205     1085608 :     test();
     206     1085608 :     test();
     207             : 
     208             : #ifdef DEBUG_FORCE_DIR
     209             :     if ( st->force_dir[0] != '\0' )
     210             :     {
     211             :         dbgread( &st->core, sizeof( int16_t ), 1, fname( st->force_dir, "force_core_loc1.enf", -1, -1, -1 ) );
     212             :     }
     213             :     else
     214             :     {
     215             :         dbgwrite( &st->core, sizeof( int16_t ), 1, 1, "res/force_core_loc1.enf" );
     216             :     }
     217             : #endif
     218             : 
     219             :     /* do not allow TD stereo ACELP core -> DFT stereo TCX core switching as it is on the WC complexity path */
     220     1085608 :     if ( ( ( st->last_core == ACELP_CORE && EQ_16( last_element_mode, IVAS_CPE_TD ) && EQ_16( st->element_mode, IVAS_CPE_DFT ) ) || ( EQ_16( st->tdm_LRTD_flag, 1 ) && LE_32( st->total_brate, IVAS_16k4 ) ) ) && EQ_16( st->core, TCX_20_CORE ) && LE_32( st->total_brate, MAX_ACELP_BRATE ) ) /* Override TCX in case of LRTD && primary channel has low bitrate*/
     221             :     {
     222         422 :         st->core = ACELP_CORE;
     223         422 :         move16();
     224             :     }
     225             : 
     226     1085608 :     test();
     227     1085608 :     if ( st->is_ism_format && st->tcxonly )
     228             :     {
     229      102420 :         st->core = TCX_20_CORE;
     230      102420 :         move16();
     231             :     }
     232             : 
     233             : #ifdef DEBUGGING
     234             :     if ( st->idchan == 0 )
     235             :     {
     236             :         if ( st->force == FORCE_SPEECH && st->element_mode != IVAS_CPE_MDCT && st->total_brate <= MAX_ACELP_BRATE )
     237             :         {
     238             :             st->core = ACELP_CORE;
     239             :         }
     240             :         else if ( st->force == FORCE_MUSIC && st->core == ACELP_CORE )
     241             :         {
     242             :             st->core = TCX_20_CORE;
     243             :         }
     244             :         else if ( st->force == FORCE_ACELP && st->element_mode != IVAS_CPE_MDCT && st->total_brate <= MAX_ACELP_BRATE )
     245             :         {
     246             :             st->core = ACELP_CORE;
     247             :             if ( st->coder_type == AUDIO )
     248             :             {
     249             :                 st->coder_type = GENERIC;
     250             :             }
     251             :         }
     252             :         else if ( st->force == FORCE_GSC && element_brate < IVAS_24k4 )
     253             :         {
     254             :             st->core = ACELP_CORE;
     255             :         }
     256             : #ifdef SUPPORT_FORCE_TCX10_TCX20
     257             :         else if ( st->force == FORCE_TCX20 || st->force == FORCE_TCX10 ) /* Initalizations should always happen with TCX20*/
     258             :         {
     259             :             st->core = TCX_20_CORE;
     260             :         }
     261             : #else
     262             :         else if ( st->force == FORCE_TCX )
     263             :         {
     264             :             st->core = TCX_20_CORE;
     265             :         }
     266             : #endif
     267             :         else if ( st->force == FORCE_HQ && st->element_mode != IVAS_CPE_MDCT && element_brate >= IVAS_24k4 )
     268             :         {
     269             :             st->core = HQ_CORE;
     270             :         }
     271             :     }
     272             : #endif
     273             : 
     274             :     /* TCX not available at low bitrates -> replace it by GSC */
     275     1085608 :     test();
     276     1085608 :     IF( EQ_16( st->core, TCX_20_CORE ) && LT_32( st->total_brate, STEREO_TCX_MIN_RATE ) )
     277             :     {
     278        5238 :         st->core = ACELP_CORE;
     279             : 
     280        5238 :         test();
     281        5238 :         test();
     282        5238 :         test();
     283             :         /* In TD stereo below 24.4 kbps we cannot overwrite the `coder_type` when it is set to TRANSITION, */
     284             :         /* as it is used for TD stereo bit allocation. To ensure consistent bit allocation, it must remain unchanged on the decoder side. */
     285        5238 :         if ( st->idchan == 0 && !( LT_32( element_brate, IVAS_24k4 ) && EQ_16( st->coder_type, TRANSITION ) && EQ_16( st->element_mode, IVAS_CPE_TD ) ) )
     286             :         {
     287        5238 :             st->coder_type = AUDIO;
     288        5238 :             move16();
     289             :         }
     290        5238 :         st->sp_aud_decision2 = 0;
     291             : 
     292        5238 :         move16();
     293        5238 :         move16();
     294             : 
     295        5238 :         if ( st->low_rate_mode )
     296             :         {
     297        1057 :             st->coder_type = INACTIVE;
     298        1057 :             move16();
     299             :         }
     300             :     }
     301             : 
     302             :     /* sanity check to avoid too low ACELP bitrate in case of "limitation to avoid too high bitrate in one active TCX channel" at element_brate = 32000 */
     303     1085608 :     test();
     304     1085608 :     test();
     305     1085608 :     test();
     306     1085608 :     test();
     307     1085608 :     if ( st->is_ism_format && st->flag_ACELP16k && !st->low_rate_mode && st->core == ACELP_CORE && LT_32( st->total_brate, add( ACELP_16k_LOW_LIMIT, FB_TBE_1k8 ) ) )
     308             :     {
     309           0 :         st->core = TCX_20_CORE;
     310           0 :         move16();
     311             :     }
     312             : 
     313             : #ifdef DEBUG_FORCE_DIR
     314             :     if ( st->force_dir[0] != '\0' )
     315             :     {
     316             :         dbgread( &st->core, sizeof( int16_t ), 1, fname( st->force_dir, "force_core_loc2.enf", -1, -1, -1 ) );
     317             :     }
     318             :     else
     319             :     {
     320             :         dbgwrite( &st->core, sizeof( int16_t ), 1, 1, "res/force_core_loc2.enf" );
     321             :     }
     322             : #endif
     323             : 
     324             :     /*---------------------------------------------------------------------*
     325             :      * Select ACELP and GSC extension layer
     326             :      *---------------------------------------------------------------------*/
     327             : 
     328     1085608 :     IF( st->core == ACELP_CORE )
     329             :     {
     330             :         /* WB */
     331      155916 :         test();
     332      155916 :         IF( EQ_16( st->bwidth, WB ) )
     333             :         {
     334       29071 :             test();
     335       29071 :             test();
     336       29071 :             test();
     337       29071 :             IF( LT_32( st->total_brate, MIN_BRATE_WB_BWE ) || ( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) ) )
     338             :             {
     339        8426 :                 st->extl = WB_BWE;
     340        8426 :                 move16();
     341             :             }
     342       20645 :             ELSE IF( GE_16( extract_l( st->total_brate ), MIN_BRATE_WB_BWE ) && !st->flag_ACELP16k )
     343             :             {
     344       11500 :                 test();
     345       11500 :                 test();
     346       11500 :                 IF( ( EQ_16( st->sp_aud_decision1, 1 ) && st->sp_aud_decision2 == 0 ) || st->coder_type == INACTIVE )
     347             :                 {
     348        4157 :                     st->extl = WB_BWE;
     349        4157 :                     move16();
     350             : 
     351        4157 :                     st->extl_brate = WB_BWE_0k35;
     352        4157 :                     move32();
     353             :                 }
     354             :                 ELSE
     355             :                 {
     356        7343 :                     st->extl = WB_TBE;
     357        7343 :                     move16();
     358             : 
     359        7343 :                     test();
     360        7343 :                     test();
     361        7343 :                     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 ) ) )
     362             :                     {
     363        2442 :                         st->extl_brate = WB_TBE_0k35;
     364        2442 :                         move32();
     365             :                     }
     366             :                     ELSE
     367             :                     {
     368        4901 :                         st->extl_brate = WB_TBE_1k05;
     369        4901 :                         move32();
     370             :                     }
     371             :                 }
     372             :             }
     373             : 
     374             : #ifdef DEBUG_FORCE_DIR
     375             :             if ( st->force_dir[0] != '\0' )
     376             :             {
     377             :                 dbgread( &st->extl, sizeof( int16_t ), 1, fname( st->force_dir, "force_extl.enf", -1, -1, -1 ) );
     378             :                 dbgread( &st->extl_brate, sizeof( int32_t ), 1, fname( st->force_dir, "force_extl_brate.enf", -1, -1, -1 ) );
     379             :             }
     380             :             else
     381             :             {
     382             :                 dbgwrite( &st->extl, sizeof( int16_t ), 1, 1, "res/force_extl.enf" );
     383             :                 dbgwrite( &st->extl_brate, sizeof( int32_t ), 1, 1, "res/force_extl_brate.enf" );
     384             :             }
     385             : #endif
     386             :         }
     387             : 
     388             :         /* SWB and FB */
     389      126845 :         ELSE IF( EQ_16( st->bwidth, SWB ) || EQ_16( st->bwidth, FB ) )
     390             :         {
     391      126845 :             test();
     392      126845 :             test();
     393      126845 :             test();
     394      126845 :             test();
     395      126845 :             test();
     396      126845 :             test();
     397      126845 :             test();
     398      126845 :             IF( GE_32( st->total_brate, MIN_BRATE_SWB_BWE ) /*&& (NE_16(*coder_type, AUDIO) || GE_32(st->total_brate, add(MIN_BWE_PRI_BRATE, 600)))*/
     399             :                 || ( 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 ) ) )
     400             :             {
     401      126845 :                 test();
     402      126845 :                 test();
     403      126845 :                 test();
     404      126845 :                 IF( ( ( ( EQ_16( st->sp_aud_decision1, 1 ) && st->sp_aud_decision2 == 0 ) || st->coder_type == INACTIVE ) && !st->GSC_noisy_speech ) /* Note: SWB BWE is not used for GSC noisy speech */ )
     405             :                 {
     406       11736 :                     st->extl = SWB_BWE;
     407       11736 :                     move16();
     408             : 
     409       11736 :                     st->extl_brate = SWB_BWE_1k6;
     410       11736 :                     move32();
     411             : 
     412       11736 :                     IF( EQ_16( st->bwidth, FB ) )
     413             :                     {
     414        4779 :                         st->extl = FB_BWE;
     415        4779 :                         move16();
     416             : 
     417        4779 :                         st->extl_brate = FB_BWE_1k8;
     418        4779 :                         move32();
     419             :                     }
     420             :                 }
     421             :                 ELSE
     422             :                 {
     423      115109 :                     st->extl = SWB_TBE;
     424      115109 :                     move16();
     425             : 
     426      115109 :                     st->extl_brate = SWB_TBE_1k6;
     427      115109 :                     move32();
     428             : 
     429      115109 :                     test();
     430      115109 :                     test();
     431      115109 :                     test();
     432      115109 :                     IF( GE_32( st->total_brate, MIN_BRATE_SWB_TBE_2k80 ) && st->flag_ACELP16k && EQ_16( st->element_mode, IVAS_SCE ) )
     433             :                     {
     434       25058 :                         st->extl_brate = SWB_TBE_2k8;
     435       25058 :                         move32();
     436             :                     }
     437       90051 :                     ELSE IF( EQ_16( st->tdm_LRTD_flag, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) )
     438             :                     {
     439        5635 :                         IF( LT_32( st->element_brate, IVAS_24k4 ) )
     440             :                         {
     441         914 :                             st->extl_brate = SWB_TBE_1k10;
     442         914 :                             move32();
     443             :                         }
     444             :                         ELSE
     445             :                         {
     446        4721 :                             st->extl_brate = SWB_TBE_1k75;
     447        4721 :                             move32();
     448             :                         }
     449             :                     }
     450       84416 :                     ELSE IF( LT_32( st->total_brate, MIN_BRATE_SWB_TBE_1k60 ) )
     451             :                     {
     452       32480 :                         st->extl_brate = SWB_TBE_0k95;
     453       32480 :                         move32();
     454             :                     }
     455             : 
     456      115109 :                     IF( EQ_16( st->bwidth, FB ) )
     457             :                     {
     458       43652 :                         st->extl = FB_TBE;
     459       43652 :                         move16();
     460             : 
     461       43652 :                         st->extl_brate = FB_TBE_1k8;
     462       43652 :                         move32();
     463             : 
     464       43652 :                         test();
     465       43652 :                         test();
     466       43652 :                         if ( GE_32( st->total_brate, MIN_BRATE_SWB_TBE_2k80 ) && st->flag_ACELP16k && EQ_16( st->element_mode, IVAS_SCE ) )
     467             :                         {
     468       20174 :                             st->extl_brate = FB_TBE_3k0;
     469       20174 :                             move32();
     470             :                         }
     471             :                     }
     472             :                 }
     473             :             }
     474             :             ELSE
     475             :             {
     476           0 :                 st->extl = WB_BWE;
     477           0 :                 move16();
     478             : 
     479           0 :                 st->extl_brate = 0;
     480           0 :                 move32();
     481             :             }
     482             : 
     483             : #ifdef DEBUG_FORCE_DIR
     484             :             if ( st->force_dir[0] != '\0' )
     485             :             {
     486             :                 dbgread( &st->extl, sizeof( int16_t ), 1, fname( st->force_dir, "force_extl.enf", -1, -1, -1 ) );
     487             :                 dbgread( &st->extl_brate, sizeof( int32_t ), 1, fname( st->force_dir, "force_extl_brate.enf", -1, -1, -1 ) );
     488             :             }
     489             :             else
     490             :             {
     491             :                 dbgwrite( &st->extl, sizeof( int16_t ), 1, 1, "res/force_extl.enf" );
     492             :                 dbgwrite( &st->extl_brate, sizeof( int32_t ), 1, 1, "res/force_extl_brate.enf" );
     493             :             }
     494             : #endif
     495             : 
     496             :             /* set IC-BWE bitrate */
     497      126845 :             test();
     498      126845 :             test();
     499      126845 :             IF( EQ_16( st->element_mode, IVAS_CPE_TD ) && ( st->idchan == 0 ) && !st->tdm_LRTD_flag )
     500             :             {
     501          74 :                 icbwe_brate = STEREO_BITS_ICBWE * FRAMES_PER_SEC;
     502          74 :                 move32();
     503             : 
     504          74 :                 if ( st->flag_ACELP16k == 0 )
     505             :                 {
     506          12 :                     icbwe_brate = ( STEREO_BITS_ICBWE - STEREO_ICBWE_SPBITS ) * FRAMES_PER_SEC;
     507          12 :                     move32();
     508             :                 }
     509             :             }
     510      126771 :             ELSE IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) )
     511             :             {
     512       26645 :                 icbwe_brate = STEREO_BITS_ICBWE_DFT * FRAMES_PER_SEC;
     513       26645 :                 move32();
     514             : 
     515       26645 :                 if ( st->flag_ACELP16k == 0 )
     516             :                 {
     517       13544 :                     icbwe_brate = ( STEREO_BITS_ICBWE_DFT - STEREO_ICBWE_SPBITS ) * FRAMES_PER_SEC;
     518       13544 :                     move32();
     519             :                 }
     520             :             }
     521             : 
     522      126845 :             test();
     523      126845 :             test();
     524      126845 :             test();
     525      126845 :             test();
     526      126845 :             test();
     527      126845 :             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 ) )
     528             :             {
     529       24220 :                 icbwe_brate = L_add( icbwe_brate, STEREO_ICBWE_MSFLAG_BITS * FRAMES_PER_SEC ); /* Q0 */
     530       24220 :                 move32();
     531             :             }
     532             :         }
     533             :     }
     534             : 
     535             :     /* set core bitrate */
     536             : 
     537     1085608 :     st->core_brate = L_sub( L_sub( st->total_brate, st->extl_brate ), icbwe_brate ); /* Q0 */
     538     1085608 :     move32();
     539             : 
     540     1085608 :     IF( st->ini_frame == 0 )
     541             :     {
     542             :         /* avoid core switching in the very first frame */
     543        8143 :         st->last_core = st->core; /* Q0 */
     544        8143 :         move16();
     545             : 
     546        8143 :         st->last_core_brate = st->core_brate; /* Q0 */
     547        8143 :         move32();
     548             : 
     549        8143 :         st->last_extl = st->extl; /* Q0 */
     550        8143 :         move16();
     551             :     }
     552             : 
     553             :     /*-----------------------------------------------------------------*
     554             :      * set inactive coder_type flag in ACELP core
     555             :      *-----------------------------------------------------------------*/
     556             : 
     557     1085608 :     st->inactive_coder_type_flag = 0; /* AVQ by default */
     558     1085608 :     move16();
     559             : 
     560     1085608 :     if ( LE_32( st->total_brate, MAX_GSC_INACTIVE_BRATE ) )
     561             :     {
     562      305598 :         st->inactive_coder_type_flag = 1; /* GSC */
     563      305598 :         move16();
     564             :     }
     565             : 
     566     1085608 :     return;
     567             : }
     568             : 
     569             : /*---------------------------------------------------------------------*
     570             :  * ivas_signaling_enc()
     571             :  *
     572             :  * write signaling information of SCE/CPE mode into the bitstream
     573             :  *---------------------------------------------------------------------*/
     574             : 
     575      785721 : void ivas_signaling_enc_fx(
     576             :     Encoder_State *st,                /* i/o: encoder state structure                                                   */
     577             :     const Word16 MCT_flag,            /* i  : hMCT handle allocated (1) or not (0)                              Q0*/
     578             :     const Word32 element_brate,       /* i  : element bitrate                                                                   Q0*/
     579             :     const Word16 tdm_SM_or_LRTD_Pri,  /* i  : channel combination scheme flag in TD stereo OR LRTD primary channel      Q0*/
     580             :     const Word16 tdm_Pitch_reuse_flag /* i  : primary channel pitch reuse flag in TD stereo             Q0*/
     581             : )
     582             : {
     583             :     Word16 ind;
     584      785721 :     BSTR_ENC_HANDLE hBstr = st->hBstr;
     585             : 
     586      785721 :     test();
     587      785721 :     test();
     588      785721 :     test();
     589      785721 :     test();
     590      785721 :     IF( EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( st->idchan, 1 ) )
     591             :     {
     592             :         /* minimal signaling for the secondary channel, most of the parameters are deduced from the primary channel */
     593        3827 :         signaling_enc_secondary_fx( st, tdm_SM_or_LRTD_Pri, tdm_Pitch_reuse_flag );
     594             :     }
     595      781894 :     ELSE IF( EQ_16( st->element_mode, IVAS_SCE ) && st->low_rate_mode )
     596             :     {
     597             :         /* ISM Low-rate mode -> do nothing -> always WB, ACELP core, IC coder_type */
     598             :     }
     599      774376 :     ELSE IF( ( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && EQ_16( st->idchan, 1 ) ) || LE_32( st->core_brate, SID_2k40 ) )
     600             :     {
     601             :         /* do nothing */
     602             :     }
     603             :     ELSE
     604             :     {
     605      570015 :         IF( st->idchan == 0 )
     606             :         {
     607             :             /*--------------------------------------------------------------------------
     608             :              * Write element mode info
     609             :              *--------------------------------------------------------------------------*/
     610             : 
     611      570015 :             test();
     612      570015 :             test();
     613      570015 :             IF( ( EQ_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_CPE_TD ) ) && !MCT_flag ) /* note: in MCT, the MDCT stereo is used exclusively */
     614             :             {
     615       53163 :                 ind = sub( st->element_mode, IVAS_CPE_DFT ); /* Q0 */
     616       53163 :                 push_indice( hBstr, IND_SMODE, ind, NBITS_ELEMENT_MODE );
     617             :             }
     618             : 
     619             :             /*--------------------------------------------------------------------------
     620             :              * Write band-width info
     621             :              *--------------------------------------------------------------------------*/
     622             : 
     623      570015 :             test();
     624      570015 :             test();
     625      570015 :             test();
     626      570015 :             test();
     627      570015 :             IF( EQ_16( st->element_mode, IVAS_SCE ) && LT_32( element_brate, MIN_BRATE_SWB_SCE ) )
     628             :             {
     629             :                 /* only WB is supported */
     630             :             }
     631      564061 :             ELSE IF( ( LT_32( element_brate, MIN_BRATE_FB_STEREO ) && !st->is_ism_format ) ||
     632             :                      ( LT_32( element_brate, MIN_BRATE_FB_ISM ) && st->is_ism_format ) )
     633             :             {
     634             :                 /* WB and SWB are supported */
     635       97689 :                 ind = sub( st->bwidth, WB ); /* Q0 */
     636       97689 :                 push_indice( hBstr, IND_BWIDTH, ind, 1 );
     637             :             }
     638             :             ELSE
     639             :             {
     640             :                 /* WB, SWB and FB are supported */
     641      466372 :                 push_indice( hBstr, IND_BWIDTH, st->bwidth, NBITS_BWIDTH );
     642             :             }
     643             : 
     644      570015 :             IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) )
     645             :             {
     646             :                 /*--------------------------------------------------------------------------
     647             :                  * Write ACELP/MDCT core selection bit
     648             :                  *--------------------------------------------------------------------------*/
     649             : 
     650      388165 :                 test();
     651      388165 :                 IF( EQ_16( st->element_mode, IVAS_CPE_TD ) || GE_32( st->total_brate, STEREO_TCX_MIN_RATE ) )
     652             :                 {
     653      379993 :                     IF( st->core == ACELP_CORE )
     654             :                     {
     655      136399 :                         push_indice( hBstr, IND_CORE, 0, 1 );
     656             :                     }
     657             :                     ELSE
     658             :                     {
     659      243594 :                         push_indice( hBstr, IND_CORE, 1, 1 );
     660             :                     }
     661             :                 }
     662             : 
     663             :                 /*--------------------------------------------------------------------------
     664             :                  * Write core dependent signaling
     665             :                  *--------------------------------------------------------------------------*/
     666             : 
     667      388165 :                 IF( st->core == ACELP_CORE )
     668             :                 {
     669             :                     /* write coder type */
     670      144571 :                     push_indice( hBstr, IND_ACELP_SIGNALLING, st->coder_type, 3 );
     671             : 
     672      144571 :                     IF( GE_32( element_brate, FRMT_SHP_MIN_BRATE_IVAS ) )
     673             :                     {
     674             :                         /* write sharpening flag */
     675       75604 :                         push_indice( hBstr, IND_SHARP_FLAG, st->sharpFlag, 1 );
     676             :                     }
     677             : 
     678             :                     /* write extension layer flag to distinguish between TBE (0) and BWE (1) */
     679      144571 :                     IF( st->extl_brate > 0 )
     680             :                     {
     681      135426 :                         test();
     682      135426 :                         test();
     683      135426 :                         test();
     684      135426 :                         test();
     685      135426 :                         IF( EQ_16( st->extl, WB_TBE ) || EQ_16( st->extl, SWB_TBE ) || EQ_16( st->extl, FB_TBE ) )
     686             :                         {
     687      119592 :                             push_indice( hBstr, IND_BWE_FLAG, 0, 1 );
     688             :                         }
     689       15834 :                         ELSE IF( EQ_16( st->extl, WB_BWE ) || EQ_16( st->extl, SWB_BWE ) || EQ_16( st->extl, FB_BWE ) )
     690             :                         {
     691       15834 :                             push_indice( hBstr, IND_BWE_FLAG, 1, 1 );
     692             :                         }
     693             :                     }
     694             :                 }
     695             :                 ELSE /* MDCT core */
     696             :                 {
     697             :                     /* write TCX/HQ selection flag */
     698      243594 :                     IF( EQ_16( st->core, HQ_CORE ) )
     699             :                     {
     700        7815 :                         push_indice( hBstr, IND_MDCT_CORE, 0, 1 );
     701             :                     }
     702             :                     ELSE /* TCX20/TCX10 core */
     703             :                     {
     704      235779 :                         push_indice( hBstr, IND_MDCT_CORE, 1, 1 );
     705             :                     }
     706             : 
     707      243594 :                     IF( EQ_16( st->core, HQ_CORE ) )
     708             :                     {
     709        7815 :                         IF( EQ_16( st->last_core, ACELP_CORE ) )
     710             :                         {
     711         204 :                             push_indice( hBstr, IND_HQ_SWITCHING_FLG, 1, 1 );
     712             :                         }
     713             :                         ELSE
     714             :                         {
     715        7611 :                             push_indice( hBstr, IND_HQ_SWITCHING_FLG, 0, 1 );
     716             :                         }
     717             :                     }
     718             :                 }
     719             :             } /* element_mode != IVAS_CPE_MDCT */
     720             :         }
     721             :     }
     722             : 
     723      785721 :     return;
     724             : }

Generated by: LCOV version 1.14