LCOV - code coverage report
Current view: top level - lib_dec - core_dec_switch.c (source / functions) Hit Total Coverage
Test: Coverage on main -- short test vectors @ 6c9ddc4024a9c0e1ecb8f643f114a84a0e26ec6b Lines: 50 75 66.7 %
Date: 2025-05-23 08:37:30 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             : /*====================================================================================
      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             : #ifdef DEBUGGING
      41             : #include "debug.h"
      42             : #endif
      43             : #include "prot.h"
      44             : #include "rom_com.h"
      45             : #include "wmc_auto.h"
      46             : 
      47             : /*-------------------------------------------------------------*
      48             :  * mode_switch_decoder_LPD()
      49             :  *
      50             :  *
      51             :  *-------------------------------------------------------------*/
      52             : 
      53       74370 : void mode_switch_decoder_LPD(
      54             :     Decoder_State *st,              /* i/o: decoder state structure             */
      55             :     const int16_t bwidth,           /* i  : audio bandwidth                     */
      56             :     const int32_t total_brate,      /* i  : total bitrate                       */
      57             :     const int32_t last_total_brate, /* i  : last frame total bitrate            */
      58             :     const int16_t frame_size_index, /* i  : index determining the frame size    */
      59             :     const int16_t MCT_flag,         /* i  : hMCT handle allocated (1) or not (0)*/
      60             :     const int16_t last_element_mode /* i  : last element mode                   */
      61             : )
      62             : {
      63             :     int16_t fscale, switchWB;
      64             :     int32_t sr_core;
      65             :     int16_t bSwitchFromAmrwbIO;
      66             :     int16_t frame_size;
      67       74370 :     TCX_DEC_HANDLE hTcxDec = st->hTcxDec;
      68             : 
      69       74370 :     switchWB = 0;
      70       74370 :     bSwitchFromAmrwbIO = 0;
      71       74370 :     if ( st->last_core == AMR_WB_CORE )
      72             :     {
      73           0 :         bSwitchFromAmrwbIO = 1;
      74             :     }
      75       74370 :     sr_core = getCoreSamplerateMode2( st->element_mode, total_brate, bwidth, st->flag_ACELP16k, st->rf_flag, st->is_ism_format );
      76       74370 :     fscale = sr2fscale( sr_core );
      77             : 
      78             :     /* set number of coded lines */
      79       74370 :     st->hTcxCfg->tcx_coded_lines = getNumTcxCodedLines( bwidth );
      80             : 
      81       74370 :     if ( ( bwidth >= WB ) && ( fscale == ( FSCALE_DENOM * 16000 ) / 12800 ) && ( fscale == st->fscale ) )
      82             :     {
      83       18912 :         if ( ( ( total_brate > ACELP_32k ) && ( st->tcxonly == 0 ) ) || ( ( total_brate <= ACELP_32k ) && ( st->tcxonly == 1 ) ) )
      84             :         {
      85        2997 :             switchWB = 1;
      86             :         }
      87             :     }
      88             : 
      89       74370 :     if ( st->last_L_frame > L_FRAME16k && total_brate <= ACELP_32k )
      90             :     {
      91        1536 :         switchWB = 1; /*force init when coming from MODE1*/
      92             :     }
      93             : 
      94       74370 :     st->igf = getIgfPresent( st->element_mode, total_brate, bwidth, st->rf_flag );
      95             : 
      96       74370 :     if ( st->hIGFDec != NULL )
      97             :     {
      98       74370 :         st->hIGFDec->infoIGFStopFreq = -1;
      99             :     }
     100             : 
     101       74370 :     if ( st->igf && ( st->idchan == 0 || st->element_mode == IVAS_CPE_MDCT ) )
     102             :     {
     103             :         /* switch IGF configuration */
     104       59676 :         IGFDecSetMode( st->hIGFDec, total_brate, bwidth, st->element_mode, -1, -1, st->rf_flag );
     105             :     }
     106             : 
     107       74370 :     if ( fscale != st->fscale || switchWB || bSwitchFromAmrwbIO || st->last_codec_mode == MODE1 || st->force_lpd_reset )
     108             :     {
     109       74370 :         open_decoder_LPD( st, total_brate, last_total_brate, bwidth, MCT_flag, last_element_mode, 0 );
     110             :     }
     111             :     else
     112             :     {
     113           0 :         assert( fscale > ( FSCALE_DENOM / 2 ) );
     114           0 :         st->fscale_old = st->fscale;
     115           0 :         st->fscale = fscale;
     116           0 :         st->L_frame = (int16_t) ( st->sr_core / FRAMES_PER_SEC );
     117           0 :         if ( st->hTcxDec != NULL )
     118             :         {
     119           0 :             st->hTcxDec->L_frameTCX = (int16_t) ( st->output_Fs / FRAMES_PER_SEC );
     120             :         }
     121             : 
     122           0 :         if ( st->hTcxCfg != NULL )
     123             :         {
     124           0 :             st->hTcxCfg->ctx_hm = getCtxHm( st->element_mode, total_brate, st->rf_flag );
     125           0 :             st->hTcxCfg->resq = getResq( total_brate );
     126             :         }
     127             : 
     128           0 :         hTcxDec->tcx_lpc_shaped_ari = getTcxLpcShapedAri( total_brate, st->rf_flag, st->element_mode );
     129             : 
     130           0 :         if ( bwidth == NB )
     131             :         {
     132           0 :             st->narrowBand = 1;
     133             :         }
     134             :         else
     135             :         {
     136           0 :             st->narrowBand = 0;
     137             :         }
     138           0 :         st->TcxBandwidth = getTcxBandwidth( bwidth );
     139             : 
     140           0 :         if ( st->hTcxCfg != NULL )
     141             :         {
     142           0 :             st->hTcxCfg->pCurrentTnsConfig = NULL;
     143           0 :             st->hTcxCfg->fIsTNSAllowed = getTnsAllowed( total_brate, st->igf, st->element_mode );
     144             :         }
     145             : 
     146           0 :         if ( st->hTcxCfg->fIsTNSAllowed && st->hIGFDec != NULL && st->hTcxCfg != NULL )
     147             :         {
     148           0 :             InitTnsConfigs( bwidth, st->hTcxCfg->tcx_coded_lines, st->hTcxCfg->tnsConfig, st->hIGFDec->infoIGFStopFreq, total_brate, st->element_mode, MCT_flag );
     149             : 
     150           0 :             SetAllowTnsOnWhite( st->hTcxCfg->tnsConfig, st->element_mode == IVAS_CPE_MDCT );
     151             :         }
     152             :     }
     153             : 
     154       74370 :     frame_size = FrameSizeConfig[frame_size_index].frame_net_bits;
     155       74370 :     reconfig_decoder_LPD( st, frame_size, bwidth, total_brate, st->last_L_frame );
     156             : 
     157       74370 :     if ( hTcxDec->envWeighted && !hTcxDec->enableTcxLpc )
     158             :     {
     159           0 :         mvr2r( st->lspold_uw, st->lsp_old, M );
     160           0 :         mvr2r( st->lsfold_uw, st->lsf_old, M );
     161           0 :         hTcxDec->envWeighted = 0;
     162             :     }
     163             : 
     164             :     /* update PLC LSF memories */
     165       74370 :     lsp2lsf( st->lsp_old, st->lsfoldbfi1, M, st->sr_core );
     166       74370 :     mvr2r( st->lsfoldbfi1, st->lsfoldbfi0, M );
     167       74370 :     mvr2r( st->lsfoldbfi1, st->lsf_adaptive_mean, M );
     168             : 
     169       74370 :     if ( st->igf && st->hBWE_TD != NULL )
     170             :     {
     171             :         /* reset TBE */
     172       35244 :         if ( ( st->bwidth == WB && st->last_extl != WB_TBE ) ||
     173       35154 :              ( st->bwidth == SWB && st->last_extl != SWB_TBE ) ||
     174       27459 :              ( st->bwidth == FB && st->last_extl != FB_TBE ) )
     175             :         {
     176       17568 :             TBEreset_dec( st );
     177             :         }
     178             :         else
     179             :         {
     180       17676 :             set_f( st->hBWE_TD->state_lpc_syn, 0.0f, LPC_SHB_ORDER );
     181       17676 :             set_f( st->hBWE_TD->state_syn_shbexc, 0.0f, L_SHB_LAHEAD );
     182       17676 :             set_f( st->hBWE_TD->mem_stp_swb, 0.0f, LPC_SHB_ORDER );
     183       17676 :             set_f( st->hBWE_TD->mem_zero_swb, 0, LPC_SHB_ORDER );
     184       17676 :             st->hBWE_TD->gain_prec_swb = 1.0f;
     185             :         }
     186             :     }
     187             : 
     188       74370 :     if ( bwidth == SWB && ( total_brate == ACELP_16k40 || total_brate == ACELP_24k40 ) && st->element_mode == EVS_MONO )
     189             :     {
     190          42 :         if ( st->tec_tfa == 0 && st->hTECDec != NULL )
     191             :         {
     192           0 :             set_zero( st->hTECDec->loBuffer, MAX_TEC_SMOOTHING_DEG );
     193             :         }
     194          42 :         st->tec_tfa = 1;
     195             :     }
     196             :     else
     197             :     {
     198       74328 :         st->tec_tfa = 0;
     199             :     }
     200             : 
     201       74370 :     st->tec_flag = 0;
     202       74370 :     st->tfa_flag = 0;
     203             : 
     204             :     /* needed in decoder to read the bitstream */
     205       74370 :     if ( bwidth >= WB && total_brate == ACELP_24k40 && st->element_mode == EVS_MONO )
     206             :     {
     207          42 :         st->enableGplc = 1;
     208             :     }
     209             :     else
     210             :     {
     211       74328 :         st->enableGplc = 0;
     212             :     }
     213             : 
     214       74370 :     if ( ( total_brate == ACELP_9k60 || total_brate == ACELP_16k40 || total_brate == ACELP_24k40 ) && st->element_mode == EVS_MONO )
     215             :     {
     216          42 :         st->dec_glr = 1;
     217             :     }
     218             :     else
     219             :     {
     220       74328 :         st->dec_glr = 0;
     221             :     }
     222             : 
     223       74370 :     st->dec_glr_idx = 0;
     224             : 
     225       74370 :     return;
     226             : }

Generated by: LCOV version 1.14