LCOV - code coverage report
Current view: top level - lib_enc - core_enc_reconf.c (source / functions) Hit Total Coverage
Test: Coverage on main -- short test vectors @ b5bd5e0684ad2d9250297e1e7a0ddc986cb7b37e Lines: 81 82 98.8 %
Date: 2025-10-27 07:01:45 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_enc.h"
      45             : #include "wmc_auto.h"
      46             : 
      47             : /*-----------------------------------------------------------------*
      48             :  * Funtion  core_coder_reconfig                                    *
      49             :  *          ~~~~~~~~~~~~~~~~~~~                                    *
      50             :  * - reconfig core coder when switching to another frame type      *
      51             :  *-----------------------------------------------------------------*/
      52             : 
      53       93492 : void core_coder_reconfig(
      54             :     Encoder_State *st,
      55             :     const int32_t last_total_brate )
      56             : {
      57       93492 :     TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc;
      58             :     int16_t bwidth, i, index;
      59             : 
      60             :     /*Configuration of ACELP*/
      61       93492 :     BITS_ALLOC_init_config_acelp( st->total_brate, st->narrowBand, st->nb_subfr, &( st->acelp_cfg ) );
      62             : 
      63             :     /*Configuration of partial copy*/
      64       93492 :     if ( st->Opt_RF_ON )
      65             :     {
      66          32 :         st->hRF->acelp_cfg_rf.mode_index = 1;
      67          32 :         st->hRF->acelp_cfg_rf.midLpc = 0;
      68          32 :         st->hRF->acelp_cfg_rf.midLpc_enable = 0;
      69          32 :         st->hRF->acelp_cfg_rf.pre_emphasis = 0;
      70          32 :         st->hRF->acelp_cfg_rf.formant_enh = 1;
      71          32 :         st->hRF->acelp_cfg_rf.formant_tilt = 1;
      72          32 :         st->hRF->acelp_cfg_rf.voice_tilt = 1;
      73          32 :         st->hRF->acelp_cfg_rf.formant_enh_num = FORMANT_SHARPENING_G1;
      74          32 :         st->hRF->acelp_cfg_rf.formant_enh_den = FORMANT_SHARPENING_G2;
      75             :     }
      76             : 
      77       93492 :     if ( st->element_mode == IVAS_CPE_MDCT )
      78             :     {
      79       49774 :         st->nb_bits_header_tcx = 2; /* signal class */
      80             :     }
      81       43718 :     else if ( st->tcxonly )
      82             :     {
      83        5047 :         st->nb_bits_header_tcx = 1 + 1; /*TCX20/TCX10 + last_core*/
      84        5047 :         st->nb_bits_header_tcx += 2;    /* Siganl class*/
      85             :     }
      86             :     else
      87             :     {
      88       38671 :         st->nb_bits_header_ace = 1 + 2 + 1; /*TCX/ACELP+coder_type + last_core*/
      89       38671 :         st->nb_bits_header_tcx = st->nb_bits_header_ace;
      90             : 
      91       38671 :         if ( st->hTcxCfg != NULL )
      92             :         {
      93       38008 :             if ( st->hTcxCfg->lfacNext <= 0 )
      94             :             {
      95       38008 :                 st->nb_bits_header_ace--; /*No last_core*/
      96             :             }
      97             :         }
      98             :     }
      99             : 
     100             :     /*Switch off  TCX or ACELP?*/
     101       93492 :     if ( st->sr_core == INT_FS_12k8 )
     102             :     {
     103       11994 :         st->acelpEnabled = ( st->restrictedMode & 1 ) == 1;
     104       11994 :         st->tcx20Enabled = ( st->restrictedMode & 2 ) == 2;
     105             :     }
     106       93492 :     st->prevEnergyHF = st->currEnergyHF = 65535.0f; /* prevent block switch */
     107             : 
     108             :     /* TCX-LTP */
     109       93492 :     if ( st->hTcxEnc != NULL )
     110             :     {
     111       92829 :         st->hTcxEnc->tcxltp = getTcxLtp( st->sr_core );
     112             :     }
     113             : 
     114             :     /*Use for 12.8 kHz sampling rate and low bitrates, the conventional pulse search->better SNR*/
     115       93492 :     st->acelp_autocorr = 1;
     116       93492 :     if ( st->total_brate <= ACELP_9k60 && st->sr_core == INT_FS_12k8 )
     117             :     {
     118        4878 :         st->acelp_autocorr = 0;
     119             :     }
     120             : 
     121             :     /*Get audio bandwidth info*/
     122       93492 :     if ( st->narrowBand )
     123             :     {
     124          19 :         bwidth = NB;
     125             :     }
     126       93473 :     else if ( st->sr_core <= INT_FS_16k )
     127             :     {
     128       46025 :         bwidth = WB;
     129             :     }
     130             :     else
     131             :     {
     132       47448 :         bwidth = SWB;
     133             :     }
     134             : 
     135             :     /*Scale TCX for non-active frames to adjust loudness with ACELP*/
     136       93492 :     if ( st->hTcxCfg != NULL )
     137             :     {
     138       92829 :         st->hTcxCfg->na_scale = 1.f;
     139       92829 :         if ( bwidth < SWB && !( st->tcxonly ) )
     140             :         {
     141      441163 :             for ( i = 0; i < SIZE_SCALE_TABLE_TCX; i++ )
     142             :             {
     143      438447 :                 if ( ( bwidth == scaleTcxTable[i].bwmode ) &&
     144      200073 :                      ( st->total_brate >= scaleTcxTable[i].bitrateFrom ) &&
     145      200073 :                      ( st->total_brate < scaleTcxTable[i].bitrateTo ) )
     146             :                 {
     147       37032 :                     if ( st->rf_mode )
     148             :                     {
     149          32 :                         i--;
     150             :                     }
     151       37032 :                     st->hTcxCfg->na_scale = scaleTcxTable[i].scale;
     152       37032 :                     break;
     153             :                 }
     154             :             }
     155             :         }
     156             :     }
     157             : 
     158       93492 :     if ( st->element_mode > IVAS_SCE )
     159             :     {
     160       55910 :         st->enableTcxLpc = ( st->lpcQuantization == 1 ) && ( st->total_brate <= LOWRATE_TCXLPC_MAX_BR_CPE || st->rf_mode );
     161             :     }
     162             :     else
     163             :     {
     164       37582 :         st->enableTcxLpc = ( st->lpcQuantization == 1 ) && ( st->total_brate <= LOWRATE_TCXLPC_MAX_BR || st->rf_mode );
     165             :     }
     166             : 
     167       93492 :     if ( st->ini_frame == 0 || st->last_codec_mode == MODE1 )
     168             :     {
     169       93460 :         st->envWeighted = 0;
     170             :     }
     171             : 
     172       93492 :     if ( st->bwidth == SWB && ( st->total_brate == ACELP_16k40 || st->total_brate == ACELP_24k40 ) && st->element_mode == EVS_MONO )
     173             :     {
     174         256 :         if ( st->tec_tfa == 0 )
     175             :         {
     176           0 :             set_zero( st->hTECEnc->loBuffer, MAX_TEC_SMOOTHING_DEG );
     177             :         }
     178         256 :         st->tec_tfa = 1;
     179             :     }
     180             :     else
     181             :     {
     182       93236 :         st->tec_tfa = 0;
     183             :     }
     184             : 
     185       93492 :     st->enablePlcWaveadjust = 0;
     186       93492 :     if ( st->total_brate >= HQ_48k )
     187             :     {
     188       47933 :         st->enablePlcWaveadjust = 1;
     189             :     }
     190             : 
     191       93492 :     st->glr = 0;
     192       93492 :     if ( ( st->total_brate == ACELP_9k60 || st->total_brate == ACELP_16k40 || st->total_brate == ACELP_24k40 ) && st->element_mode == EVS_MONO )
     193             :     {
     194         365 :         st->glr = 1;
     195             :     }
     196             : 
     197       93492 :     if ( st->glr )
     198             :     {
     199         365 :         st->nb_bits_header_ace += G_LPC_RECOVERY_BITS;
     200             :     }
     201             : 
     202       93492 :     if ( hTcxEnc != NULL )
     203             :     {
     204       92829 :         if ( st->bwidth == NB || st->bwidth == WB )
     205             :         {
     206        9171 :             index = min( N_TCX_STARTLINE_NOISE_WB - 1, (uint16_t) max( 0, ( st->rf_mode == 0 ) ? st->frame_size_index : st->frame_size_index - 1 ) );
     207        9171 :             hTcxEnc->nmStartLine = startLineWB[index];
     208             :         }
     209             :         else /* (st->bwidth == SWB || st->bwidth == FB) */
     210             :         {
     211       83658 :             index = min( N_TCX_STARTLINE_NOISE_SWB - 1, (uint16_t) max( 3, ( st->rf_mode == 0 ) ? st->frame_size_index : st->frame_size_index - 1 ) - 3 );
     212       83658 :             if ( st->total_brate >= IVAS_96k && st->total_brate <= IVAS_192k && st->element_mode > IVAS_SCE )
     213             :             {
     214       16014 :                 index--;
     215             :             }
     216       83658 :             hTcxEnc->nmStartLine = startLineSWB[index];
     217       83658 :             if ( st->total_brate == IVAS_48k && st->element_mode == IVAS_CPE_MDCT && hTcxEnc->nmStartLine * 5 < st->L_frame * 4 )
     218             :             {
     219        1800 :                 hTcxEnc->nmStartLine = ( hTcxEnc->nmStartLine * 5 ) >> 2; /* low-rate stereo is more efficient than dual-mono due to stereo processing */
     220             :             }
     221             :         }
     222             :     }
     223             : 
     224       93492 :     if ( hTcxEnc != NULL )
     225             :     {
     226       92829 :         if ( st->total_brate < ACELP_24k40 && ( ( st->total_brate > last_total_brate ) || ( st->last_codec_mode == MODE1 ) ) )
     227             :         {
     228             :             /* low-freq memQuantZeros must be reset partially if bitrate increased */
     229       21011 :             set_s( hTcxEnc->memQuantZeros, 0, hTcxEnc->nmStartLine );
     230             :         }
     231             :         else
     232             :         {
     233       71818 :             if ( st->total_brate >= ACELP_24k40 && st->total_brate <= ACELP_32k && last_total_brate >= ACELP_13k20 && last_total_brate < ACELP_24k40 )
     234             :             {
     235         105 :                 set_s( hTcxEnc->memQuantZeros, 0, st->L_frame );
     236             :             }
     237             :         }
     238             :     }
     239             : 
     240       93492 :     return;
     241             : }

Generated by: LCOV version 1.14