LCOV - code coverage report
Current view: top level - lib_dec - core_dec_reconf_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main -- dec/rend @ 4c82f1d24d39d0296b18d775f18a006f4c7d024b Lines: 155 200 77.5 %
Date: 2025-05-17 01:59:02 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /*====================================================================================
       2             :     EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0
       3             :   ====================================================================================*/
       4             : 
       5             : #include <stdint.h>
       6             : #include <stdio.h>
       7             : #include "options.h"
       8             : #include "basop_util.h"
       9             : #include "prot_fx.h"
      10             : #include "rom_com.h"
      11             : 
      12             : 
      13       21302 : void reconfig_decoder_LPD_ivas_fx(
      14             :     Decoder_State *st,        /* i/o: decoder state structure    */
      15             :     const Word16 bits_frame,  /* i  : bit budget               Q0*/
      16             :     const Word16 bwidth,      /* i  : audio bandwidth          Q0*/
      17             :     const Word32 total_brate, /* i  : total bitrate            Q0*/
      18             :     const Word16 L_frame_old  /* i  : frame length             Q0*/
      19             : )
      20             : {
      21             :     UWord16 newLen, oldLen;
      22       21302 :     TCX_LTP_DEC_HANDLE hTcxLtpDec = st->hTcxLtpDec;
      23       21302 :     TCX_DEC_HANDLE hTcxDec = st->hTcxDec;
      24             : 
      25             :     Word32 lowrate_tcxlpc_max_br;
      26       21302 :     move16();
      27       21302 :     st->bits_frame = bits_frame;
      28       21302 :     move16();
      29             : 
      30       21302 :     IF( EQ_16( bwidth, NB ) )
      31             :     {
      32           0 :         move16();
      33           0 :         st->narrowBand = 1;
      34             :     }
      35       21302 :     ELSE IF( GT_16( bwidth, NB ) )
      36             :     {
      37       21302 :         move16();
      38       21302 :         st->narrowBand = 0;
      39             :     }
      40             : 
      41       21302 :     BITS_ALLOC_init_config_acelp( st->total_brate, st->narrowBand, st->nb_subfr, &( st->acelp_cfg ) );
      42             : 
      43             :     /*Configuration of partial copy*/
      44       21302 :     st->acelp_cfg_rf.mode_index = 1;
      45       21302 :     move16();
      46       21302 :     st->acelp_cfg_rf.midLpc = 0;
      47       21302 :     move16();
      48       21302 :     st->acelp_cfg_rf.midLpc_enable = 0;
      49       21302 :     move16();
      50       21302 :     st->acelp_cfg_rf.pre_emphasis = 0;
      51       21302 :     move16();
      52       21302 :     st->acelp_cfg_rf.formant_enh = 1;
      53       21302 :     move16();
      54       21302 :     st->acelp_cfg_rf.formant_tilt = 1;
      55       21302 :     move16();
      56       21302 :     st->acelp_cfg_rf.voice_tilt = 1;
      57       21302 :     move16();
      58       21302 :     st->acelp_cfg_rf.formant_enh_num = FORMANT_SHARPENING_G1;
      59       21302 :     move16();
      60       21302 :     st->acelp_cfg_rf.formant_enh_den = FORMANT_SHARPENING_G2;
      61       21302 :     move16();
      62             : 
      63       21302 :     IF( NE_16( st->element_mode, IVAS_SCE ) )
      64             :     {
      65       12639 :         st->flag_cna = getCnaPresent_fx( st->element_mode, st->element_brate, total_brate, bwidth );
      66       12639 :         move16();
      67             :     }
      68             : 
      69             :     /* TCX-LTP */
      70       21302 :     IF( hTcxLtpDec != NULL )
      71             :     {
      72       21302 :         hTcxLtpDec->tcxltp = getTcxLtp( st->sr_core );
      73       21302 :         move16();
      74             :     }
      75             : 
      76             :     /*Scale TCX for non-active frames to adjust loudness with ACELP*/
      77       21302 :     IF( st->hTcxCfg != NULL )
      78             :     {
      79             :         Word16 i;
      80       21302 :         st->hTcxCfg->na_scale = 32767 /*1.0f Q15*/;
      81       21302 :         move16();
      82       21302 :         test();
      83       21302 :         IF( ( LT_16( bwidth, SWB ) ) && !( st->tcxonly ) )
      84             :         {
      85        6786 :             FOR( i = 0; i < SIZE_SCALE_TABLE_TCX; i++ )
      86             :             {
      87        6786 :                 test();
      88        6786 :                 test();
      89        6786 :                 IF( ( EQ_16( bwidth, scaleTcxTable[i].bwmode ) ) &&
      90             :                     ( GE_32( total_brate, scaleTcxTable[i].bitrateFrom ) ) &&
      91             :                     ( LT_32( total_brate, scaleTcxTable[i].bitrateTo ) ) )
      92             :                 {
      93         621 :                     if ( st->rf_flag )
      94             :                     {
      95           0 :                         i = i - 1;
      96             :                     }
      97         621 :                     st->hTcxCfg->na_scale = scaleTcxTable[i].scale; /* Q0 */
      98         621 :                     move16();
      99         621 :                     BREAK;
     100             :                 }
     101             :             }
     102             :         }
     103             :     }
     104             :     /*if its not the first frame resample overlap buffer to new sampling rate */
     105       21302 :     IF( ( st->ini_frame != 0 ) )
     106             :     {
     107       16086 :         test();
     108       16086 :         test();
     109       16086 :         test();
     110       16086 :         test();
     111       16086 :         test();
     112       16086 :         IF( st->hTcxCfg != NULL &&
     113             :             ( NE_16( st->fscale, st->fscale_old ) &&
     114             :               !( st->element_mode == EVS_MONO &&
     115             :                  EQ_16( st->last_codec_mode, MODE1 ) &&
     116             :                  EQ_16( st->last_core, ACELP_CORE ) && NE_16( st->prev_bfi, 0 ) ) ) )
     117             :         /* no resempling is needed here when recovering from mode 1
     118             :                    ACELP PLC, since the buffers are already sampled with the
     119             :                    correct sampling rate in open_decoder_LPD_fx() */
     120             :         {
     121        5927 :             newLen = st->hTcxCfg->tcx_mdct_window_length;
     122        5927 :             oldLen = st->hTcxCfg->tcx_mdct_window_length_old;
     123             : 
     124        5927 :             move16();
     125        5927 :             move16();
     126        5927 :             test();
     127        5927 :             test();
     128        5927 :             IF( ( st->prev_bfi && EQ_16( st->last_core_bfi, ACELP_CORE ) ) || EQ_16( st->last_core, ACELP_CORE ) )
     129             :             {
     130        1735 :                 newLen = shr( st->L_frame, 1 );
     131        1735 :                 oldLen = shr( L_frame_old, 1 );
     132             :             }
     133             : 
     134        5927 :             IF( st->hTcxDec != NULL )
     135             :             {
     136        5927 :                 lerp( hTcxDec->old_syn_Overl, hTcxDec->old_syn_Overl, newLen, oldLen );
     137        5927 :                 lerp( hTcxDec->syn_Overl, hTcxDec->syn_Overl, newLen, oldLen );
     138             : 
     139        5927 :                 test();
     140        5927 :                 IF( st->prev_bfi && ( st->last_core_bfi == ACELP_CORE ) )
     141             :                 {
     142          78 :                     lerp( hTcxDec->syn_Overl_TDAC, hTcxDec->syn_Overl_TDAC, newLen, oldLen );
     143             :                 }
     144             :             }
     145             :         }
     146             : 
     147       16086 :         IF( LE_16( st->L_frame, L_FRAME16k ) )
     148             :         {
     149        9144 :             IF( LE_16( st->last_L_frame, L_FRAME16k ) )
     150             :             {
     151        8118 :                 IF( NE_16( st->L_frame, st->last_L_frame ) )
     152             :                 {
     153         508 :                     IF( GT_16( st->L_frame, st->last_L_frame ) )
     154             :                     {
     155         344 :                         oldLen = extract_l( L_shr( Mpy_32_16_1( L_mult0( st->last_L_frame, getInvFrameLen( st->L_frame ) /*Q21*/ ) /*Q21*/, L_SYN_MEM_CLAS_ESTIM /*Q0*/ ) /*Q6*/, 6 ) /*Q0*/ );
     156         344 :                         newLen = L_SYN_MEM_CLAS_ESTIM;
     157         344 :                         move16();
     158             :                     }
     159             :                     ELSE
     160             :                     {
     161         164 :                         oldLen = L_SYN_MEM_CLAS_ESTIM;
     162         164 :                         move16();
     163         164 :                         newLen = extract_l( L_shr( Mpy_32_16_1( L_mult0( st->L_frame, getInvFrameLen( st->last_L_frame ) /*Q21*/ ) /*Q21*/, L_SYN_MEM_CLAS_ESTIM /*Q0*/ ) /*Q6*/, 6 ) /*Q0*/ );
     164             :                     }
     165         508 :                     lerp( &st->mem_syn_clas_estim_fx[L_SYN_MEM_CLAS_ESTIM - oldLen], &st->mem_syn_clas_estim_fx[L_SYN_MEM_CLAS_ESTIM - newLen], newLen, oldLen );
     166             :                 }
     167             :             }
     168             :             ELSE
     169             :             {
     170        1026 :                 set16_fx( st->mem_syn_clas_estim_fx, 0, L_SYN_MEM_CLAS_ESTIM ); /* Qx */
     171             :             }
     172             :         }
     173             :     }
     174             : 
     175       21302 :     test();
     176       21302 :     test();
     177       21302 :     lowrate_tcxlpc_max_br = LOWRATE_TCXLPC_MAX_BR;
     178       21302 :     move16();
     179       21302 :     IF( GT_16( st->element_mode, IVAS_SCE ) )
     180             :     {
     181       12639 :         lowrate_tcxlpc_max_br = LOWRATE_TCXLPC_MAX_BR_CPE;
     182       12639 :         move32();
     183             :     }
     184       21302 :     hTcxDec->enableTcxLpc = EQ_16( st->numlpc, 1 ) && EQ_16( st->lpcQuantization, 1 ) && ( LE_32( total_brate, lowrate_tcxlpc_max_br ) /*LOWRATE_TCXLPC_MAX_BR*/ || st->rf_flag );
     185       21302 :     move16();
     186             : 
     187       21302 :     IF( ( st->ini_frame == 0 ) )
     188             :     {
     189        5216 :         hTcxDec->envWeighted = 0;
     190        5216 :         move16();
     191             :     }
     192             : 
     193       21302 :     return;
     194             : }
     195             : 
     196          32 : void reconfig_decoder_LPD_fx(
     197             :     Decoder_State *st,  /* i/o: decoder state structure    */
     198             :     Word16 bits_frame,  /* i  : bit budget               Q0*/
     199             :     Word16 bwidth,      /* i  : audio bandwidth          Q0*/
     200             :     Word32 total_brate, /* i  : total bitrate            Q0*/
     201             :     Word16 L_frame_old  /* i  : frame length             Q0*/
     202             : )
     203             : {
     204             :     Word16 newLen;
     205             :     Word16 oldLen;
     206             :     Word32 lowrate_tcxlpc_max_br;
     207             : 
     208             :     TCX_LTP_DEC_HANDLE hTcxLtpDec;
     209             :     TCX_DEC_HANDLE hTcxDec;
     210             : 
     211          32 :     hTcxLtpDec = st->hTcxLtpDec;
     212          32 :     hTcxDec = st->hTcxDec;
     213             : 
     214          32 :     move16();
     215          32 :     st->bits_frame = bits_frame;
     216             : 
     217          32 :     IF( EQ_16( bwidth, NB ) )
     218             :     {
     219           0 :         move16();
     220           0 :         st->narrowBand = 1;
     221             :     }
     222          32 :     ELSE IF( GT_16( bwidth, NB ) )
     223             :     {
     224          32 :         move16();
     225          32 :         st->narrowBand = 0;
     226             :     }
     227             : 
     228          32 :     BITS_ALLOC_init_config_acelp( st->total_brate, st->narrowBand, st->nb_subfr, &( st->acelp_cfg ) );
     229             : 
     230             :     /*Configuration of partial copy*/
     231          32 :     st->acelp_cfg_rf.mode_index = 1;
     232          32 :     move16();
     233          32 :     st->acelp_cfg_rf.midLpc = 0;
     234          32 :     move16();
     235          32 :     st->acelp_cfg_rf.midLpc_enable = 0;
     236          32 :     move16();
     237          32 :     st->acelp_cfg_rf.pre_emphasis = 0;
     238          32 :     move16();
     239          32 :     st->acelp_cfg_rf.formant_enh = 1;
     240          32 :     move16();
     241          32 :     st->acelp_cfg_rf.formant_tilt = 1;
     242          32 :     move16();
     243          32 :     st->acelp_cfg_rf.voice_tilt = 1;
     244          32 :     move16();
     245          32 :     st->acelp_cfg_rf.formant_enh_num = FORMANT_SHARPENING_G1;
     246          32 :     move16();
     247          32 :     st->acelp_cfg_rf.formant_enh_den = FORMANT_SHARPENING_G2;
     248          32 :     move16();
     249             : 
     250             : 
     251          32 :     IF( NE_16( st->element_mode, IVAS_SCE ) )
     252             :     {
     253          32 :         st->flag_cna = (Word8) getCnaPresent_fx( st->element_mode, st->element_brate, total_brate, bwidth );
     254          32 :         move16();
     255             :     }
     256             : 
     257             :     /* TCX-LTP */
     258          32 :     IF( hTcxLtpDec != NULL )
     259             :     {
     260          32 :         hTcxLtpDec->tcxltp = getTcxLtp( st->sr_core );
     261          32 :         move16();
     262             :     }
     263             : 
     264          32 :     IF( st->hTcxCfg != NULL )
     265             :     {
     266             :         Word16 i;
     267             : 
     268             :         /*Scale TCX for non-active frames to adjust loudness with ACELP*/
     269          32 :         st->hTcxCfg->na_scale = 32767 /*1.0f Q15*/;
     270          32 :         test();
     271          32 :         IF( ( LT_16( bwidth, SWB ) ) && !( st->tcxonly ) )
     272             :         {
     273           0 :             Word16 scaleTableSize = idiv1616( sizeof( scaleTcxTable ), sizeof( scaleTcxTable[0] ) ); /* is a constant */
     274             : 
     275           0 :             FOR( i = 0; i < scaleTableSize; i++ )
     276             :             {
     277           0 :                 test();
     278           0 :                 test();
     279           0 :                 IF( ( EQ_16( bwidth, scaleTcxTable[i].bwmode ) ) &&
     280             :                     ( GE_32( total_brate, scaleTcxTable[i].bitrateFrom ) ) &&
     281             :                     ( LT_32( total_brate, scaleTcxTable[i].bitrateTo ) ) )
     282             :                 {
     283           0 :                     IF( st->rf_flag )
     284             :                     {
     285           0 :                         i = i - 1;
     286           0 :                         move16();
     287             :                     }
     288           0 :                     st->hTcxCfg->na_scale = scaleTcxTable[i].scale;
     289           0 :                     move16();
     290           0 :                     BREAK;
     291             :                 }
     292             :             }
     293             :         }
     294             :     }
     295             : 
     296             :     /*if its not the first frame resample overlap buffer to new sampling rate */
     297          32 :     IF( ( st->ini_frame != 0 ) )
     298             :     {
     299          31 :         test();
     300          31 :         test();
     301          31 :         test();
     302          31 :         test();
     303          31 :         test();
     304          31 :         IF( st->hTcxCfg != NULL &&
     305             :             ( NE_16( st->fscale, st->fscale_old ) &&
     306             :               !( st->element_mode == EVS_MONO && EQ_16( st->last_codec_mode, MODE1 ) &&
     307             :                  EQ_16( st->last_core, ACELP_CORE ) && st->prev_bfi != 0 ) ) )
     308             :         /* no resempling is needed here when recovering from mode 1
     309             :            acelp plc, since the buffers are already sampled with the
     310             :            correct sampling rate in open_decoder_LPD_fx() */
     311             :         {
     312             : 
     313           0 :             newLen = st->hTcxCfg->tcx_mdct_window_length;
     314           0 :             oldLen = st->hTcxCfg->tcx_mdct_window_length_old;
     315           0 :             move16();
     316           0 :             move16();
     317           0 :             test();
     318           0 :             test();
     319           0 :             IF( ( st->prev_bfi && EQ_16( st->last_core_bfi, ACELP_CORE ) ) || EQ_16( st->last_core, ACELP_CORE ) )
     320             :             {
     321           0 :                 newLen = shr( st->L_frame, 1 );
     322           0 :                 oldLen = shr( L_frame_old, 1 );
     323             :             }
     324           0 :             IF( st->hTcxDec != NULL )
     325             :             {
     326           0 :                 lerp( hTcxDec->old_syn_Overl, hTcxDec->old_syn_Overl, newLen, oldLen );
     327           0 :                 lerp( hTcxDec->syn_Overl, hTcxDec->syn_Overl, newLen, oldLen );
     328             : 
     329           0 :                 test();
     330           0 :                 IF( st->prev_bfi && EQ_16( st->last_core_bfi, ACELP_CORE ) )
     331             :                 {
     332           0 :                     lerp( hTcxDec->syn_Overl_TDAC, hTcxDec->syn_Overl_TDAC, newLen, oldLen );
     333             :                 }
     334             :             }
     335             :         }
     336             : 
     337             : 
     338          31 :         IF( LE_16( st->L_frame, L_FRAME16k ) )
     339             :         {
     340          31 :             IF( LE_16( st->last_L_frame, L_FRAME16k ) )
     341             :             {
     342          31 :                 IF( NE_16( st->L_frame, st->last_L_frame ) )
     343             :                 {
     344           0 :                     IF( GT_16( st->L_frame, st->last_L_frame ) )
     345             :                     {
     346           0 :                         oldLen = extract_l( L_shr( Mpy_32_16_1( L_mult0( st->last_L_frame, getInvFrameLen( st->L_frame ) /*Q21*/ ) /*Q21*/, L_SYN_MEM_CLAS_ESTIM /*Q0*/ ) /*Q6*/, 6 ) /*Q0*/ );
     347           0 :                         newLen = L_SYN_MEM_CLAS_ESTIM;
     348           0 :                         move16();
     349           0 :                         move16();
     350             :                     }
     351             :                     ELSE
     352             :                     {
     353           0 :                         oldLen = L_SYN_MEM_CLAS_ESTIM;
     354           0 :                         move16();
     355           0 :                         newLen = extract_l( L_shr( Mpy_32_16_1( L_mult0( st->L_frame, getInvFrameLen( st->last_L_frame ) /*Q21*/ ) /*Q21*/, L_SYN_MEM_CLAS_ESTIM /*Q0*/ ) /*Q6*/, 6 ) /*Q0*/ );
     356             :                     }
     357           0 :                     lerp( &st->mem_syn_clas_estim_fx[L_SYN_MEM_CLAS_ESTIM - oldLen], &st->mem_syn_clas_estim_fx[L_SYN_MEM_CLAS_ESTIM - newLen], newLen, oldLen );
     358             :                 }
     359             :             }
     360             :             ELSE
     361             :             {
     362           0 :                 set16_fx( st->mem_syn_clas_estim_fx, 0, L_SYN_MEM_CLAS_ESTIM );
     363           0 :                 st->classifier_Q_mem_syn = 0;
     364           0 :                 move16();
     365             :             }
     366             :         }
     367             :     }
     368          32 :     test();
     369          32 :     test();
     370          32 :     test();
     371          32 :     lowrate_tcxlpc_max_br = LOWRATE_TCXLPC_MAX_BR;
     372          32 :     move16();
     373          32 :     IF( GT_16( st->element_mode, IVAS_SCE ) )
     374             :     {
     375           0 :         lowrate_tcxlpc_max_br = LOWRATE_TCXLPC_MAX_BR_CPE;
     376           0 :         move16();
     377             :     }
     378          32 :     hTcxDec->enableTcxLpc = EQ_16( st->numlpc, 1 ) && EQ_16( st->lpcQuantization, 1 ) && ( LE_32( total_brate, lowrate_tcxlpc_max_br ) /*LOWRATE_TCXLPC_MAX_BR*/ || st->rf_flag );
     379          32 :     move16();
     380          32 :     IF( EQ_16( st->ini_frame, 0 ) )
     381             :     {
     382           1 :         hTcxDec->envWeighted = 0;
     383           1 :         move16();
     384             :     }
     385             : 
     386             : 
     387          32 :     return;
     388             : }

Generated by: LCOV version 1.14