LCOV - code coverage report
Current view: top level - lib_dec - core_dec_reconf.c (source / functions) Hit Total Coverage
Test: Coverage on main -- short test vectors @ 6c9ddc4024a9c0e1ecb8f643f114a84a0e26ec6b Lines: 59 61 96.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 <stdint.h>
      38             : #include "options.h"
      39             : #ifdef DEBUGGING
      40             : #include "debug.h"
      41             : #endif
      42             : #include "prot.h"
      43             : #include "rom_com.h"
      44             : #include "rom_dec.h"
      45             : #include "wmc_auto.h"
      46             : 
      47             : /*---------------------------------------------------------------------*
      48             :  * reconfig_decoder_LPD()
      49             :  *
      50             :  *
      51             :  *---------------------------------------------------------------------*/
      52             : 
      53       74370 : void reconfig_decoder_LPD(
      54             :     Decoder_State *st,         /* i/o: decoder state structure  */
      55             :     const int16_t bits_frame,  /* i  : bit budget               */
      56             :     const int16_t bwidth,      /* i  : audio bandwidth          */
      57             :     const int32_t total_brate, /* i  : total bitrate            */
      58             :     const int16_t L_frame_old  /* i  : frame length             */
      59             : )
      60             : {
      61             :     int16_t i;
      62             :     uint16_t newLen, oldLen;
      63       74370 :     TCX_LTP_DEC_HANDLE hTcxLtpDec = st->hTcxLtpDec;
      64       74370 :     TCX_DEC_HANDLE hTcxDec = st->hTcxDec;
      65             : 
      66       74370 :     st->bits_frame = bits_frame;
      67             : 
      68       74370 :     if ( bwidth == NB )
      69             :     {
      70           0 :         st->narrowBand = 1;
      71             :     }
      72       74370 :     else if ( bwidth > NB )
      73             :     {
      74       74370 :         st->narrowBand = 0;
      75             :     }
      76             : 
      77       74370 :     BITS_ALLOC_init_config_acelp( st->total_brate, st->narrowBand, st->nb_subfr, &( st->acelp_cfg ) );
      78             : 
      79             :     /*Configuration of partial copy*/
      80       74370 :     st->acelp_cfg_rf.mode_index = 1;
      81       74370 :     st->acelp_cfg_rf.midLpc = 0;
      82       74370 :     st->acelp_cfg_rf.midLpc_enable = 0;
      83       74370 :     st->acelp_cfg_rf.pre_emphasis = 0;
      84       74370 :     st->acelp_cfg_rf.formant_enh = 1;
      85       74370 :     st->acelp_cfg_rf.formant_tilt = 1;
      86       74370 :     st->acelp_cfg_rf.voice_tilt = 1;
      87       74370 :     st->acelp_cfg_rf.formant_enh_num = FORMANT_SHARPENING_G1;
      88       74370 :     st->acelp_cfg_rf.formant_enh_den = FORMANT_SHARPENING_G2;
      89             : 
      90       74370 :     if ( st->element_mode != IVAS_SCE )
      91             :     {
      92       44913 :         st->flag_cna = getCnaPresent( st->element_mode, st->element_brate, total_brate, bwidth );
      93             :     }
      94             : 
      95             :     /* TCX-LTP */
      96       74370 :     if ( hTcxLtpDec != NULL )
      97             :     {
      98       74370 :         hTcxLtpDec->tcxltp = getTcxLtp( st->sr_core );
      99             :     }
     100             : 
     101             :     /*Scale TCX for non-active frames to adjust loudness with ACELP*/
     102       74370 :     if ( st->hTcxCfg != NULL )
     103             :     {
     104       74370 :         st->hTcxCfg->na_scale = 1.f;
     105             : 
     106       74370 :         if ( bwidth < SWB && !( st->tcxonly ) )
     107             :         {
     108       21213 :             for ( i = 0; i < SIZE_SCALE_TABLE_TCX; i++ )
     109             :             {
     110       21213 :                 if ( ( bwidth == scaleTcxTable[i].bwmode ) &&
     111        9567 :                      ( total_brate >= scaleTcxTable[i].bitrateFrom ) &&
     112        9567 :                      ( total_brate < scaleTcxTable[i].bitrateTo ) )
     113             :                 {
     114        1941 :                     if ( st->rf_flag )
     115             :                     {
     116           0 :                         i--;
     117             :                     }
     118        1941 :                     st->hTcxCfg->na_scale = scaleTcxTable[i].scale;
     119        1941 :                     break;
     120             :                 }
     121             :             }
     122             :         }
     123             :     }
     124             : 
     125             :     /*if its not the first frame resample overlap buffer to new sampling rate */
     126       74370 :     if ( st->ini_frame != 0 )
     127             :     {
     128       55299 :         if ( st->hTcxCfg != NULL && st->fscale != st->fscale_old && !( st->element_mode == EVS_MONO && st->last_codec_mode == MODE1 && st->last_core == ACELP_CORE && st->prev_bfi != 0 ) )
     129             :         /* no resempling is needed here when recovering from mode 1
     130             :                ACELP PLC, since the buffers are already sampled with the
     131             :                correct sampling rate in open_decoder_LPD() */
     132             :         {
     133       19557 :             newLen = st->hTcxCfg->tcx_mdct_window_length;
     134       19557 :             oldLen = st->hTcxCfg->tcx_mdct_window_length_old;
     135             : 
     136       19557 :             if ( ( st->prev_bfi && st->last_core_bfi == ACELP_CORE ) || st->last_core == ACELP_CORE )
     137             :             {
     138        5541 :                 newLen = st->L_frame / 2;
     139        5541 :                 oldLen = L_frame_old / 2;
     140             :             }
     141             : 
     142       19557 :             if ( st->hTcxDec != NULL )
     143             :             {
     144       19557 :                 lerp( st->hTcxDec->old_syn_Overl, st->hTcxDec->old_syn_Overl, newLen, oldLen );
     145       19557 :                 lerp( st->hTcxDec->syn_Overl, st->hTcxDec->syn_Overl, newLen, oldLen );
     146             : 
     147       19557 :                 if ( st->prev_bfi && st->last_core_bfi == ACELP_CORE )
     148             :                 {
     149         294 :                     lerp( st->hTcxDec->syn_Overl_TDAC, st->hTcxDec->syn_Overl_TDAC, newLen, oldLen );
     150             :                 }
     151             :             }
     152             :         }
     153             : 
     154       55299 :         if ( st->L_frame <= L_FRAME16k )
     155             :         {
     156       31608 :             if ( st->last_L_frame <= L_FRAME16k )
     157             :             {
     158       28254 :                 if ( st->L_frame != st->last_L_frame )
     159             :                 {
     160        1587 :                     if ( st->L_frame > st->last_L_frame )
     161             :                     {
     162        1071 :                         oldLen = L_SYN_MEM_CLAS_ESTIM * st->last_L_frame / st->L_frame;
     163        1071 :                         newLen = L_SYN_MEM_CLAS_ESTIM;
     164             :                     }
     165             :                     else
     166             :                     {
     167         516 :                         oldLen = L_SYN_MEM_CLAS_ESTIM;
     168         516 :                         newLen = L_SYN_MEM_CLAS_ESTIM * st->L_frame / st->last_L_frame;
     169             :                     }
     170        1587 :                     lerp( &st->mem_syn_clas_estim[L_SYN_MEM_CLAS_ESTIM - oldLen], &st->mem_syn_clas_estim[L_SYN_MEM_CLAS_ESTIM - newLen], newLen, oldLen );
     171             :                 }
     172             :             }
     173             :             else
     174             :             {
     175        3354 :                 set_zero( st->mem_syn_clas_estim, L_SYN_MEM_CLAS_ESTIM );
     176             :             }
     177             :         }
     178             :     }
     179             : 
     180       74370 :     if ( st->element_mode > IVAS_SCE )
     181             :     {
     182       44799 :         hTcxDec->enableTcxLpc = ( st->numlpc == 1 ) && ( st->lpcQuantization == 1 ) && ( total_brate <= LOWRATE_TCXLPC_MAX_BR_CPE || st->rf_flag );
     183             :     }
     184             :     else
     185             :     {
     186       29571 :         hTcxDec->enableTcxLpc = ( st->numlpc == 1 ) && ( st->lpcQuantization == 1 ) && ( total_brate <= LOWRATE_TCXLPC_MAX_BR || st->rf_flag );
     187             :     }
     188             : 
     189       74370 :     if ( st->ini_frame == 0 )
     190             :     {
     191       19071 :         hTcxDec->envWeighted = 0;
     192             :     }
     193             : 
     194       74370 :     return;
     195             : }

Generated by: LCOV version 1.14