LCOV - code coverage report
Current view: top level - lib_enc - updt_enc_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main @ cede165d26d1b794bfc5f5f6f9ec19d4d64a9a3b Lines: 234 391 59.8 %
Date: 2025-11-01 03:16:20 Functions: 3 4 75.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 "options.h"     /* Compilation switches                   */
       7             : #include "cnst.h"        /* Common constants                       */
       8             : #include "rom_com.h"     /* Common constants                       */
       9             : #include "prot_fx.h"     /* Function prototypes                    */
      10             : #include "prot_fx_enc.h" /* Function prototypes                    */
      11             : #include "basop_util.h"  /* Function prototypes                    */
      12             : #include "ivas_prot_fx.h"
      13             : 
      14             : /*-------------------------------------------------------------------*
      15             :  * updt_enc()
      16             :  *
      17             :  * Common updates (all frame types)
      18             :  *-------------------------------------------------------------------*/
      19             : 
      20      172262 : void updt_enc_fx(
      21             :     Encoder_State *st,        /* i/o: state structure                          */
      22             :     const Word16 *old_exc,    /* i  : buffer of excitation                     */
      23             :     const Word16 *pitch_buf,  /* i  : floating pitch for each subframe         */
      24             :     const Word16 Es_pred,     /* i  : predicited scaled innovation energy      */
      25             :     const Word16 *Aq,         /* i  : A(z) quantized for all subframes         */
      26             :     const Word16 *lsf_new,    /* i  : current frame LSF vector                 */
      27             :     const Word16 *lsp_new,    /* i  : current frame LSP vector                 */
      28             :     const Word16 *old_bwe_exc /* i  : buffer of excitation                     */
      29             : )
      30             : {
      31             :     Word16 i, tmp;
      32      172262 :     SC_VBR_ENC_HANDLE hSC_VBR = st->hSC_VBR;
      33      172262 :     LPD_state_HANDLE hLPDmem = st->hLPDmem;
      34      172262 :     GSC_ENC_HANDLE hGSCEnc = st->hGSCEnc;
      35      172262 :     TD_BWE_ENC_HANDLE hBWE_TD = st->hBWE_TD;
      36             : 
      37             :     /* update old excitation buffer */
      38      172262 :     Copy( &old_exc[st->L_frame], hLPDmem->old_exc, L_EXC_MEM );
      39      172262 :     test();
      40      172262 :     test();
      41      172262 :     IF( !st->Opt_AMR_WB && st->hBWE_TD != NULL )
      42             :     {
      43      172141 :         Copy( &old_bwe_exc[L_FRAME32k], hBWE_TD->old_bwe_exc_fx, PIT16k_MAX * 2 );
      44             :     }
      45             : 
      46             :     /* update old LSP and LSF vector */
      47      172262 :     Copy( lsp_new, st->lsp_old_fx, M );
      48      172262 :     Copy( lsf_new, st->lsf_old_fx, M );
      49             : 
      50             :     /* update last coder type */
      51      172262 :     st->last_coder_type = st->coder_type;
      52      172262 :     move16();
      53      172262 :     test();
      54      172262 :     test();
      55      172262 :     test();
      56      172262 :     if ( EQ_16( st->coder_type, INACTIVE ) || ( EQ_16( st->bpf_off, 1 ) && NE_16( st->coder_type, AUDIO ) && NE_16( st->coder_type, TRANSITION ) ) )
      57             :     {
      58       20471 :         st->last_coder_type = UNVOICED;
      59       20471 :         move16();
      60             :     }
      61             : 
      62             :     /* this ensures that st->last_coder_type is never set to INACTIVE in case of AVQ inactive because the FEC does not distinguish between GSC inactive and AVQ inactive */
      63      172262 :     test();
      64      172262 :     if ( EQ_16( st->coder_type, INACTIVE ) && GT_32( st->total_brate, ACELP_24k40 ) )
      65             :     {
      66        3912 :         st->last_coder_type = GENERIC;
      67        3912 :         move16();
      68             :     }
      69             : 
      70      172262 :     test();
      71      172262 :     test();
      72      172262 :     test();
      73      172262 :     IF( st->Opt_AMR_WB && EQ_16( st->coder_type, INACTIVE ) && st->core_brate != SID_1k75 && st->core_brate != FRAME_NO_DATA )
      74             :     {
      75             :         /* overwrite previous coding type to help FEC */
      76           0 :         st->last_coder_type = UNVOICED;
      77           0 :         move16();
      78             :     }
      79             : 
      80             :     /* AC mode (GSC) - in speech we can consider that the last pitch band reached the max */
      81      172262 :     test();
      82      172262 :     test();
      83      172262 :     IF( st->hGSCEnc != NULL && NE_16( st->coder_type, AUDIO ) && NE_16( st->coder_type, INACTIVE ) )
      84             :     {
      85      143936 :         hGSCEnc->mem_last_pit_band = 10 + BAND1k2;
      86      143936 :         move16();
      87      143936 :         hGSCEnc->past_dyn_dec = NOISE_LEVEL_SP0 - 1;
      88      143936 :         move16(); /* tends to speech */
      89      143936 :         hGSCEnc->noise_lev = NOISE_LEVEL_SP0 - 1;
      90      143936 :         move16(); /* tends to speech */
      91             :         /*st->mid_dyn_fx = 40.0f * 0.5f + st->mid_dyn * 0.5f;*/
      92      143936 :         hGSCEnc->mid_dyn_fx = add( 20 * 128, mult_r( hGSCEnc->mid_dyn_fx, 16384 ) ); /*Q7*/
      93      143936 :         move16();
      94             :     }
      95             : 
      96             :     /* convert old LSP vector from 12kHz domain to 16kHz domain (needed in case of ACELP@12k8 <-> ACELP@16kHz switching) */
      97      172262 :     IF( EQ_16( st->L_frame, L_FRAME ) )
      98             :     {
      99       91088 :         Copy( st->lsp_old_fx, st->lsp_old16k_fx, M );
     100       91088 :         st->rate_switching_reset_16kHz = lsp_convert_poly_fx( st->lsp_old16k_fx, L_FRAME16k, st->Opt_AMR_WB );
     101       91088 :         move16();
     102             :     }
     103             : 
     104             :     /* update buffer of old subframe pitch values */
     105      172262 :     IF( NE_16( st->last_L_frame, st->L_frame ) )
     106             :     {
     107        1810 :         IF( EQ_16( st->L_frame, L_FRAME ) )
     108             :         {
     109        6295 :             FOR( i = 0; i < NB_SUBFR; i++ )
     110             :             {
     111        5036 :                 st->old_pitch_buf_fx[NB_SUBFR + i] = mult_r( 26214, st->old_pitch_buf_fx[NB_SUBFR + i + 1] );
     112        5036 :                 move16();
     113             :             }
     114             :         }
     115             :         ELSE
     116             :         {
     117        2755 :             FOR( i = NB_SUBFR; i > 0; i-- )
     118             :             {
     119        2204 :                 st->old_pitch_buf_fx[NB_SUBFR + i] = add( mult_r( 8192, st->old_pitch_buf_fx[NB_SUBFR + i - 1] ), st->old_pitch_buf_fx[NB_SUBFR + i - 1] );
     120        2204 :                 move16();
     121             :             }
     122         551 :             st->old_pitch_buf_fx[2 * NB_SUBFR16k - 1] = st->old_pitch_buf_fx[2 * NB_SUBFR16k - 2];
     123         551 :             move16();
     124             :         }
     125             :     }
     126      172262 :     tmp = shr( st->L_frame, 6 );
     127      172262 :     Copy( &st->old_pitch_buf_fx[tmp], st->old_pitch_buf_fx, tmp );
     128      172262 :     Copy( pitch_buf, &st->old_pitch_buf_fx[tmp], tmp );
     129             : 
     130             :     /* SC-VBR */
     131      172262 :     st->last_Opt_SC_VBR = st->Opt_SC_VBR;
     132      172262 :     move16();
     133      172262 :     IF( st->hSC_VBR != NULL )
     134             :     {
     135        1423 :         hSC_VBR->last_last_ppp_mode = hSC_VBR->last_ppp_mode;
     136        1423 :         move16();
     137        1423 :         hSC_VBR->last_ppp_mode = hSC_VBR->ppp_mode;
     138        1423 :         move16();
     139        1423 :         hSC_VBR->last_nelp_mode = hSC_VBR->nelp_mode;
     140        1423 :         move16();
     141             :     }
     142             :     /* core switching updates */
     143      172262 :     Copy( &Aq[( st->L_frame / L_SUBFR - 1 ) * ( M + 1 )], st->old_Aq_12_8_fx, M + 1 );
     144      172262 :     st->old_Es_pred_fx = Es_pred;
     145      172262 :     move16();
     146             : 
     147      172262 :     return;
     148             : }
     149             : 
     150             : /*-------------------------------------------------------------------*
     151             :  * updt_IO_switch()
     152             :  *
     153             :  * Common updates for AMR-WB IO mode and EVS primary mode switching
     154             :  *-------------------------------------------------------------------*/
     155             : 
     156           0 : void updt_IO_switch_enc_fx(
     157             :     Encoder_State *st,       /* i/o: state structure             */
     158             :     const Word16 input_frame /* i  : input frame length          */
     159             : )
     160             : {
     161             :     Word16 xsp_tmp[M];
     162           0 :     SC_VBR_ENC_HANDLE hSC_VBR = st->hSC_VBR;
     163           0 :     DTX_ENC_HANDLE hDtxEnc = st->hDtxEnc;
     164           0 :     TD_CNG_ENC_HANDLE hTdCngEnc = st->hTdCngEnc;
     165           0 :     GSC_ENC_HANDLE hGSCEnc = st->hGSCEnc;
     166           0 :     AMRWB_IO_ENC_HANDLE hAmrwb_IO = st->hAmrwb_IO;
     167           0 :     TD_BWE_ENC_HANDLE hBWE_TD = st->hBWE_TD;
     168           0 :     FD_BWE_ENC_HANDLE hBWE_FD = st->hBWE_FD;
     169             : 
     170           0 :     IF( EQ_16( st->last_core, AMR_WB_CORE ) ) /* switching to EVS primary mode */
     171             :     {
     172             :         /* reset onset detection counter */
     173           0 :         st->tc_cnt = -1;
     174           0 :         move16();
     175             : 
     176             :         /* force safety-net LSFQ in the first frames after the switching */
     177           0 :         st->Nb_ACELP_frames = 0;
     178           0 :         move16();
     179             : 
     180             :         /* AMR-WB IO mode uses ISF(ISP), but EVS primary mode LSF(LSP) */
     181           0 :         Copy( stable_LSP_fx, xsp_tmp, M );
     182           0 :         isf2lsf_fx( st->lsf_old_fx, st->lsf_old_fx, xsp_tmp );
     183           0 :         Copy( stable_LSP_fx, xsp_tmp, M );
     184           0 :         isp2lsp_fx( st->lsp_old_fx, st->lsp_old_fx, xsp_tmp, M );
     185           0 :         isp2lsp_fx( st->lsp_old1_fx, st->lsp_old1_fx, xsp_tmp, M );
     186             : 
     187           0 :         Copy( stable_LSP_fx, xsp_tmp, M );
     188           0 :         isp2lsp_fx( hDtxEnc->lspCNG_fx, hDtxEnc->lspCNG_fx, xsp_tmp, M );
     189             :         /*st->old_enr_index = min( (short)((float)st->old_enr_index / STEP_AMR_WB_SID * STEP_SID), 127 );*/
     190           0 :         IF( hTdCngEnc->old_enr_index >= 0 )
     191             :         {
     192             :             /* old index is initialized to -1,  and may only be updated after it has been calculated properly at least once once */
     193           0 :             hTdCngEnc->old_enr_index = s_min( mult( shl( hTdCngEnc->old_enr_index, 1 ), 32459 ), 127 ); /*32459 = 2/(STEP_SID/STEP_AMR_WB_SID)*/
     194           0 :             move16();
     195             :         }
     196             :         /* Perform preemphasis of the old input signal @16kHz */
     197           0 :         st->mem_preemph16k_fx = 0;
     198           0 :         move16();
     199           0 :         PREEMPH_FX( st->old_inp_16k_fx, PREEMPH_FAC_16k, L_INP_MEM, &( st->mem_preemph16k_fx ) );
     200           0 :         Scale_sig( st->old_inp_16k_fx, L_INP_MEM, st->prev_Q_new );
     201             :         /* reset TD BWE buffers */
     202           0 :         set16_fx( hBWE_TD->old_speech_shb_fx, 0, L_LOOK_16k + L_SUBFR16k );
     203           0 :         set16_fx( hBWE_TD->old_speech_wb_fx, 0, ( L_LOOK_12k8 + L_SUBFR ) * 5 / 16 );
     204           0 :         set16_fx( hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2 );
     205           0 :         set16_fx( hBWE_TD->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET );
     206           0 :         hBWE_TD->bwe_non_lin_prev_scale_fx = 0;
     207           0 :         move16();
     208           0 :         set16_fx( hBWE_TD->decim_state1_fx, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) );
     209           0 :         set16_fx( hBWE_TD->decim_state2_fx, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) );
     210           0 :         set16_fx( hBWE_FD->L_old_wtda_swb_fx, 0, L_FRAME16k );
     211           0 :         set16_fx( hBWE_FD->old_input_wb_fx, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) );
     212             : 
     213           0 :         wb_tbe_extras_reset_fx( hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, hBWE_TD->mem_genSHBexc_filt_down_wb3_fx );
     214             : 
     215           0 :         IF( GE_16( input_frame, L_FRAME32k ) )
     216             :         {
     217           0 :             swb_tbe_reset_fx( hBWE_TD->mem_csfilt_fx, hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->state_lpc_syn_fx,
     218           0 :                               hBWE_TD->syn_overlap_fx, hBWE_TD->state_syn_shbexc_fx, &( hBWE_TD->tbe_demph_fx ), &( hBWE_TD->tbe_premph_fx ), hBWE_TD->mem_stp_swb_fx, &( hBWE_TD->gain_prec_swb_fx ) );
     219             :         }
     220             : 
     221           0 :         IF( EQ_16( input_frame, L_FRAME48k ) )
     222             :         {
     223           0 :             set16_fx( hBWE_TD->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER );
     224           0 :             hBWE_TD->fb_tbe_demph_fx = 0;
     225           0 :             move16();
     226           0 :             fb_tbe_reset_enc_fx( hBWE_TD->elliptic_bpf_2_48k_mem_fx, &hBWE_TD->prev_fb_energy_fx, hBWE_TD->elliptic_bpf_2_48k_mem_fx_Q, &hBWE_TD->prev_fb_energy_fx_Q );
     227             :         }
     228             : 
     229             :         /* reset FD BWE buffers */
     230           0 :         hBWE_FD->prev_mode = NORMAL;
     231           0 :         move16();
     232             : 
     233             :         /* reset the unvoiced/audio signal improvement  memories */
     234           0 :         hGSCEnc->seed_tcx = 15687;
     235           0 :         move16();
     236             : 
     237           0 :         st->use_acelp_preq = 0;
     238           0 :         move16();
     239             :     }
     240             :     ELSE /* switching to AMR-WB IO mode */
     241             :     {
     242           0 :         set16_fx( st->mem_MA_fx, 0, M );
     243             : 
     244             :         /* AMR-WB IO mode uses ISF(ISP), but EVS primary mode LSF(LSP) */
     245           0 :         Copy( stable_ISP_fx, xsp_tmp, M );
     246           0 :         lsf2isf_fx( st->lsf_old_fx, st->lsf_old_fx, xsp_tmp, M );
     247           0 :         Copy( stable_ISP_fx, xsp_tmp, M );
     248           0 :         lsp2isp_fx( st->lsp_old_fx, st->lsp_old_fx, xsp_tmp, M );
     249           0 :         lsp2isp_fx( st->lsp_old1_fx, st->lsp_old1_fx, xsp_tmp, M );
     250           0 :         Copy( stable_ISP_fx, xsp_tmp, M );
     251           0 :         lsp2isp_fx( hDtxEnc->lspCNG_fx, hDtxEnc->lspCNG_fx, xsp_tmp, M );
     252             : 
     253           0 :         IF( hTdCngEnc->old_enr_index >= 0 )
     254             :         {
     255             :             /* old_enr__index is initialized to -1,  and may only be updated this way after it has been calculated properly at least once once */
     256             :             /*st->old_enr_index = min( (short)((float)st->old_enr_index / STEP_SID * STEP_AMR_WB_SID), 63 );*/
     257           0 :             hTdCngEnc->old_enr_index = s_max( s_min( mult( hTdCngEnc->old_enr_index, 16384 ), 63 ), 0 ); /*32459 = 2/(STEP_SID/STEP_AMR_WB_SID)*/
     258             :         }
     259             :         /* gain quantization memory */
     260           0 :         set16_fx( hAmrwb_IO->past_qua_en_fx, ( -14 * 1024 ), GAIN_PRED_ORDER );
     261             :         /* reset VBR signalling */
     262           0 :         IF( st->Opt_SC_VBR )
     263             :         {
     264           0 :             hSC_VBR->ppp_mode = 0;
     265           0 :             move16();
     266           0 :             hSC_VBR->nelp_mode = 0;
     267           0 :             move16();
     268             :         }
     269           0 :         st->hGSCEnc->seed_tcx = 15687; /* the re-init here was present only in float _DIFF_FLOAT_FIX_*/
     270           0 :         move16();
     271             :     }
     272             : 
     273             :     /* Force SID in case of AMR-WB IO/EVS primary mode switching */
     274           0 :     IF( hTdCngEnc != NULL )
     275             :     {
     276           0 :         hDtxEnc->cnt_SID = 0;
     277           0 :         move16();
     278             : 
     279             :         /* CNG - reset */
     280           0 :         hDtxEnc->cng_cnt = 0;
     281           0 :         move16();
     282           0 :         hTdCngEnc->ho_hist_size = 0;
     283           0 :         move16();
     284           0 :         hTdCngEnc->burst_ho_cnt = 0;
     285           0 :         move16();
     286             :     }
     287             :     /* LP memories */
     288           0 :     Copy( UVWB_Ave_fx, st->mem_AR_fx, M );
     289             : 
     290             :     /* FEC - update adaptive LSF mean vector */
     291           0 :     Copy( st->lsf_old_fx, st->lsfoldbfi0_fx, M );
     292           0 :     Copy( st->lsf_old_fx, st->lsfoldbfi1_fx, M );
     293           0 :     Copy( st->lsf_old_fx, st->lsf_adaptive_mean_fx, M );
     294             : 
     295           0 :     return;
     296             : }
     297             : 
     298             : /*-------------------------------------------------------------------*
     299             :  * updt_enc_common_fx()
     300             :  *
     301             :  * Common updates for MODE1 and MODE2
     302             :  *-------------------------------------------------------------------*/
     303             : 
     304        3100 : void updt_enc_common_fx(
     305             :     Encoder_State *st, /* i/o: encoder state structure     */
     306             :     const Word16 Etot, /* i  : total energy                */
     307             :     const Word16 Q_new /* i  : CUrrent frame scaling       */
     308             : )
     309             : {
     310             :     /*---------------------------------------------------------------------*
     311             :      * Updates - main main codec parameters
     312             :      *---------------------------------------------------------------------*/
     313             : 
     314        3100 :     st->last_sr_core = st->sr_core;
     315        3100 :     move32();
     316        3100 :     st->last_codec_mode = st->codec_mode;
     317        3100 :     move16();
     318        3100 :     st->last_L_frame = st->L_frame;
     319        3100 :     move16();
     320        3100 :     st->last_core = st->core;
     321        3100 :     move16();
     322             : 
     323        3100 :     st->last_core_brate = st->core_brate;
     324        3100 :     move32();
     325        3100 :     st->last_total_brate = st->total_brate;
     326        3100 :     move32();
     327        3100 :     st->last_extl = st->extl;
     328        3100 :     move16();
     329        3100 :     st->last_input_bwidth = st->input_bwidth;
     330        3100 :     move16();
     331        3100 :     st->last_bwidth = st->bwidth;
     332        3100 :     move16();
     333        3100 :     IF( GT_16( st->element_mode, EVS_MONO ) )
     334             :     {
     335           0 :         st->hNoiseEst->Etot_last_32fx = L_deposit_h( Etot );
     336             :     }
     337             :     ELSE
     338             :     {
     339        3100 :         st->hNoiseEst->Etot_last_fx = Etot;
     340             :     }
     341        3100 :     move16();
     342        3100 :     st->last_coder_type_raw = st->coder_type_raw;
     343        3100 :     move16();
     344             : 
     345        3100 :     st->prev_Q_new = Q_new;
     346        3100 :     move16();
     347             : 
     348        3100 :     test();
     349        3100 :     IF( GT_32( st->core_brate, SID_2k40 ) && st->hDtxEnc != NULL )
     350             :     {
     351        3100 :         st->hDtxEnc->last_active_brate = st->total_brate;
     352        3100 :         move32();
     353             :     }
     354             : 
     355        3100 :     IF( st->hBWE_TD != NULL )
     356             :     {
     357        3100 :         st->hBWE_TD->prev_coder_type = st->coder_type;
     358        3100 :         move16();
     359        3100 :         IF( EQ_16( st->core, HQ_CORE ) )
     360             :         {
     361             :             /* in the HQ core, coder_type is not used so it could have been set to anything */
     362         431 :             st->hBWE_TD->prev_coder_type = GENERIC;
     363         431 :             move16();
     364             :         }
     365             :     }
     366             : 
     367        3100 :     test();
     368        3100 :     IF( st->Opt_DTX_ON && st->hTdCngEnc != NULL )
     369             :     {
     370           0 :         IF( GT_32( st->core_brate, SID_2k40 ) )
     371             :         {
     372           0 :             IF( EQ_16( st->hDtxEnc->first_CNG, 1 ) )
     373             :             {
     374           0 :                 IF( GE_16( st->hTdCngEnc->act_cnt, BUF_DEC_RATE ) )
     375             :                 {
     376           0 :                     st->hTdCngEnc->act_cnt = 0;
     377           0 :                     move16();
     378             :                 }
     379           0 :                 st->hTdCngEnc->act_cnt = add( st->hTdCngEnc->act_cnt, 1 );
     380           0 :                 move16();
     381             : 
     382           0 :                 test();
     383           0 :                 IF( EQ_16( st->hTdCngEnc->act_cnt, BUF_DEC_RATE ) && st->hTdCngEnc->ho_hist_size > 0 )
     384             :                 {
     385           0 :                     st->hTdCngEnc->ho_hist_size = sub( st->hTdCngEnc->ho_hist_size, 1 );
     386           0 :                     move16();
     387             :                 }
     388             :             }
     389             : 
     390           0 :             test();
     391           0 :             test();
     392           0 :             test();
     393           0 :             IF( EQ_16( st->element_mode, IVAS_SCE ) || EQ_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_CPE_TD ) || EQ_16( st->hDtxEnc->first_CNG, 1 ) )
     394             :             {
     395           0 :                 st->hTdCngEnc->act_cnt2 = add( st->hTdCngEnc->act_cnt2, 1 );
     396           0 :                 st->hTdCngEnc->act_cnt2 = s_min( st->hTdCngEnc->act_cnt2, MIN_ACT_CNG_UPD );
     397           0 :                 move16();
     398           0 :                 move16();
     399             : 
     400           0 :                 test();
     401           0 :                 test();
     402           0 :                 test();
     403           0 :                 IF( ( EQ_16( st->element_mode, IVAS_SCE ) || EQ_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_CPE_TD ) ) && GE_16( st->hTdCngEnc->act_cnt2, MIN_ACT_CNG_UPD ) )
     404             :                 {
     405             :                 }
     406             :             }
     407             :         }
     408             : 
     409           0 :         test();
     410           0 :         test();
     411           0 :         test();
     412           0 :         IF( ( EQ_32( st->core_brate, SID_2k40 ) || EQ_32( st->core_brate, FRAME_NO_DATA ) ) && st->hDtxEnc->first_CNG == 0 && EQ_16( st->cng_type, LP_CNG ) )
     413             :         {
     414           0 :             st->hDtxEnc->first_CNG = 1;
     415           0 :             move16();
     416             :         }
     417             :     }
     418             : 
     419             :     /*-----------------------------------------------------------------*
     420             :      * Increase the counter of initialization frames
     421             :      * Limit the max number of init. frames
     422             :      *-----------------------------------------------------------------*/
     423             : 
     424        3100 :     if ( LT_16( st->ini_frame, MAX_FRAME_COUNTER ) )
     425             :     {
     426         600 :         st->ini_frame = add( st->ini_frame, 1 );
     427         600 :         move16();
     428             :     }
     429             : 
     430             :     /* synchronisation of CNG seeds */
     431        3100 :     test();
     432        3100 :     test();
     433        3100 :     test();
     434        3100 :     IF( st->hTdCngEnc != NULL && NE_32( st->core_brate, FRAME_NO_DATA ) && NE_32( st->core_brate, SID_2k40 ) && NE_16( st->core, AMR_WB_CORE ) )
     435             :     {
     436        3100 :         Random( &( st->hTdCngEnc->cng_seed ) );
     437        3100 :         Random( &( st->hTdCngEnc->cng_ener_seed ) );
     438             :     }
     439             : 
     440             :     /*---------------------------------------------------------------------*
     441             :      * Updates - MODE2
     442             :      *---------------------------------------------------------------------*/
     443             : 
     444        3100 :     IF( EQ_16( st->element_mode, EVS_MONO ) && EQ_16( st->mdct_sw, MODE2 ) )
     445             :     {
     446          66 :         st->codec_mode = MODE2;
     447          66 :         move16();
     448             : 
     449          66 :         st->sr_core = getCoreSamplerateMode2( EVS_MONO, st->total_brate, st->bwidth, st->flag_ACELP16k, st->rf_mode, 0 );
     450          66 :         move32();
     451             : 
     452             :         // st->L_frame = extract_l(Mult_32_16(st->sr_core, INV_FRAME_PER_SEC_Q15)); /*(int16_t)(st->sr_core / FRAMES_PER_SEC);*/
     453             : 
     454          66 :         IF( EQ_32( st->sr_core, INT_FS_12k8 ) )
     455             :         {
     456           0 :             st->preemph_fac = PREEMPH_FAC;
     457           0 :             st->gamma = GAMMA1;
     458           0 :             st->L_frame = L_FRAME;
     459           0 :             move16();
     460           0 :             move16();
     461           0 :             move16();
     462             :         }
     463             :         ELSE
     464             :         {
     465          66 :             st->preemph_fac = PREEMPH_FAC_16k;
     466          66 :             st->gamma = GAMMA16k;
     467          66 :             st->L_frame = L_FRAME16k;
     468          66 :             move16();
     469          66 :             move16();
     470          66 :             move16();
     471             :         }
     472             : 
     473          66 :         st->igf = getIgfPresent_fx( EVS_MONO, st->total_brate, st->bwidth, st->rf_mode );
     474          66 :         move16();
     475             :     }
     476             : 
     477             :     /* update FER clas */
     478        3100 :     IF( NE_16( st->core, AMR_WB_CORE ) )
     479             :     {
     480        3100 :         st->last_clas = st->clas;
     481        3100 :         move16();
     482             :     }
     483             : 
     484             :     /* Update Core */
     485        3100 :     core_encode_update_fx( st );
     486             : 
     487             :     /*---------------------------------------------------------------------*
     488             :      * RF mode updates
     489             :      *---------------------------------------------------------------------*/
     490             : 
     491        3100 :     IF( st->rf_mode )
     492             :     {
     493           0 :         IF( st->hSC_VBR != NULL )
     494             :         {
     495           0 :             st->hSC_VBR->last_nelp_mode = 0;
     496           0 :             move16();
     497           0 :             IF( EQ_16( st->hRF->rf_frame_type, RF_NELP ) )
     498             :             {
     499           0 :                 st->hSC_VBR->last_nelp_mode = 1;
     500           0 :                 move16();
     501             :             }
     502             :         }
     503             :     }
     504             : 
     505        3100 :     st->rf_mode_last = st->rf_mode;
     506        3100 :     move16();
     507             : 
     508        3100 :     IF( st->Opt_RF_ON )
     509             :     {
     510           0 :         st->L_frame = L_FRAME;
     511           0 :         st->rf_mode = 1;
     512           0 :         move16();
     513           0 :         move16();
     514             :     }
     515             : 
     516             :     /*---------------------------------------------------------------------*
     517             :      * Other updates
     518             :      *---------------------------------------------------------------------*/
     519             : 
     520        3100 :     test();
     521        3100 :     IF( GT_16( st->element_mode, EVS_MONO ) && st->hTcxEnc != NULL )
     522             :     {
     523             :     }
     524        3100 :     return;
     525             : }
     526             : 
     527             : 
     528     1133872 : void updt_enc_common_ivas_fx(
     529             :     Encoder_State *st, /* i/o: encoder state structure     */
     530             :     const Word16 Q_new /* i  : CUrrent frame scaling       */
     531             : )
     532             : {
     533             :     /*---------------------------------------------------------------------*
     534             :      * Updates - main main codec parameters
     535             :      *---------------------------------------------------------------------*/
     536     1133872 :     st->last_sr_core = st->sr_core;
     537     1133872 :     move32();
     538     1133872 :     st->last_codec_mode = st->codec_mode;
     539     1133872 :     move16();
     540     1133872 :     st->last_L_frame = st->L_frame;
     541     1133872 :     move16();
     542     1133872 :     st->last_core = st->core;
     543     1133872 :     move16();
     544             : 
     545     1133872 :     st->last_total_brate = st->total_brate;
     546     1133872 :     move32();
     547     1133872 :     st->last_bits_frame_nominal = st->bits_frame_nominal;
     548     1133872 :     move16();
     549     1133872 :     st->last_core_brate = st->core_brate;
     550     1133872 :     move32();
     551     1133872 :     st->last_extl = st->extl;
     552     1133872 :     move16();
     553     1133872 :     st->last_input_bwidth = st->input_bwidth;
     554     1133872 :     move16();
     555     1133872 :     st->last_bwidth = st->bwidth;
     556     1133872 :     move16();
     557     1133872 :     st->last_coder_type_raw = st->coder_type_raw;
     558     1133872 :     move16();
     559     1133872 :     st->prev_Q_new = Q_new;
     560     1133872 :     move16();
     561             : 
     562     1133872 :     test();
     563     1133872 :     if ( GT_32( st->core_brate, SID_2k40 ) && st->hDtxEnc != NULL )
     564             :     {
     565       97340 :         st->hDtxEnc->last_active_brate = st->total_brate;
     566       97340 :         move32();
     567             :     }
     568             : 
     569     1133872 :     IF( st->hBWE_TD != NULL )
     570             :     {
     571      414981 :         IF( EQ_16( st->core, HQ_CORE ) )
     572             :         {
     573             :             /* in the HQ core, coder_type is not used so it could have been set to anything */
     574        7801 :             st->hBWE_TD->prev_coder_type = GENERIC;
     575        7801 :             move16();
     576             :         }
     577             :         ELSE
     578             :         {
     579      407180 :             st->hBWE_TD->prev_coder_type = st->coder_type;
     580      407180 :             move16();
     581             :         }
     582             :     }
     583             : 
     584     1133872 :     test();
     585     1133872 :     IF( st->Opt_DTX_ON && st->hTdCngEnc != NULL )
     586             :     {
     587       46560 :         IF( GT_32( st->core_brate, SID_2k40 ) )
     588             :         {
     589       34533 :             IF( EQ_16( st->hDtxEnc->first_CNG, 1 ) )
     590             :             {
     591       17600 :                 if ( GE_16( st->hTdCngEnc->act_cnt, BUF_DEC_RATE ) )
     592             :                 {
     593         669 :                     st->hTdCngEnc->act_cnt = 0;
     594         669 :                     move16();
     595             :                 }
     596       17600 :                 st->hTdCngEnc->act_cnt = add( st->hTdCngEnc->act_cnt, 1 );
     597       17600 :                 move16();
     598             : 
     599       17600 :                 test();
     600       17600 :                 IF( EQ_16( st->hTdCngEnc->act_cnt, BUF_DEC_RATE ) && st->hTdCngEnc->ho_hist_size > 0 )
     601             :                 {
     602         244 :                     st->hTdCngEnc->ho_hist_size = sub( st->hTdCngEnc->ho_hist_size, 1 );
     603         244 :                     move16();
     604             :                 }
     605             :             }
     606             : 
     607       34533 :             test();
     608       34533 :             test();
     609       34533 :             test();
     610       34533 :             IF( EQ_16( st->element_mode, IVAS_SCE ) || EQ_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_CPE_TD ) || EQ_16( st->hDtxEnc->first_CNG, 1 ) )
     611             :             {
     612       34533 :                 if ( GE_16( ++( st->hTdCngEnc->act_cnt2 ), MIN_ACT_CNG_UPD ) )
     613             :                 {
     614       27880 :                     st->hTdCngEnc->act_cnt2 = MIN_ACT_CNG_UPD;
     615       27880 :                     move16();
     616             :                 }
     617             : 
     618       34533 :                 test();
     619       34533 :                 test();
     620       34533 :                 test();
     621       34533 :                 IF( ( EQ_16( st->element_mode, IVAS_SCE ) || EQ_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_CPE_TD ) ) && GE_16( st->hTdCngEnc->act_cnt2, MIN_ACT_CNG_UPD ) )
     622             :                 {
     623       27880 :                     Word32 cng_att_fx32 = 0;
     624       27880 :                     move32();
     625             : 
     626       27880 :                     apply_scale( &cng_att_fx32, st->hFdCngEnc->hFdCngCom->CngBandwidth, st->hFdCngEnc->hFdCngCom->CngBitrate, scaleTableStereo, SIZE_SCALE_TABLE_STEREO );
     627             : 
     628       27880 :                     st->hTdCngEnc->CNG_att_fx = extract_l( L_shr( cng_att_fx32, Q16 ) ); // Q23
     629       27880 :                     move16();
     630             :                 }
     631             :             }
     632             :         }
     633             : 
     634       46560 :         test();
     635       46560 :         test();
     636       46560 :         test();
     637       46560 :         if ( ( EQ_32( st->core_brate, SID_2k40 ) || EQ_32( st->core_brate, FRAME_NO_DATA ) ) && st->hDtxEnc->first_CNG == 0 && EQ_16( st->cng_type, LP_CNG ) )
     638             :         {
     639          28 :             st->hDtxEnc->first_CNG = 1;
     640          28 :             move16();
     641             :         }
     642             :     }
     643             : 
     644             :     /*-----------------------------------------------------------------*
     645             :      * Increase the counter of initialization frames
     646             :      * Limit the max number of init. frames
     647             :      *-----------------------------------------------------------------*/
     648             : 
     649     1133872 :     IF( LT_16( st->ini_frame, MAX_FRAME_COUNTER ) )
     650             :     {
     651      408815 :         st->ini_frame = add( st->ini_frame, 1 );
     652             :     }
     653             : 
     654             :     /* synchronisation of CNG seeds */
     655     1133872 :     test();
     656     1133872 :     test();
     657     1133872 :     test();
     658     1133872 :     IF( st->hTdCngEnc != NULL && ( st->core_brate != FRAME_NO_DATA ) && NE_32( st->core_brate, SID_2k40 ) && NE_16( st->core, AMR_WB_CORE ) )
     659             :     {
     660       34533 :         Random( &( st->hTdCngEnc->cng_seed ) );
     661       34533 :         Random( &( st->hTdCngEnc->cng_ener_seed ) );
     662             :     }
     663             : 
     664             :     /*---------------------------------------------------------------------*
     665             :      * Updates - MODE2
     666             :      *---------------------------------------------------------------------*/
     667             : 
     668     1133872 :     test();
     669     1133872 :     IF( ( st->element_mode == EVS_MONO ) && EQ_16( st->mdct_sw, MODE2 ) )
     670             :     {
     671           0 :         st->codec_mode = MODE2;
     672           0 :         move16();
     673             : 
     674           0 :         st->sr_core = getCoreSamplerateMode2( EVS_MONO, st->total_brate, st->bwidth, st->flag_ACELP16k, st->rf_mode, 0 );
     675           0 :         move16();
     676             : 
     677           0 :         st->L_frame = extract_l( Mpy_32_32_r( st->sr_core, ONE_BY_FRAMES_PER_SEC_Q31 ) );
     678           0 :         move16();
     679             : 
     680           0 :         IF( EQ_32( st->sr_core, INT_FS_12k8 ) )
     681             :         {
     682           0 :             st->preemph_fac = PREEMPH_FAC;
     683           0 :             st->gamma = GAMMA1;
     684             :         }
     685             :         ELSE
     686             :         {
     687             : 
     688           0 :             st->preemph_fac = PREEMPH_FAC_16k;
     689           0 :             st->gamma = GAMMA16k;
     690             :         }
     691           0 :         move16();
     692           0 :         move16();
     693             : 
     694           0 :         st->igf = getIgfPresent_fx( EVS_MONO, st->total_brate, st->bwidth, st->rf_mode );
     695           0 :         move16();
     696             :     }
     697             : 
     698             :     /* update FER clas */
     699     1133872 :     if ( NE_16( st->core, AMR_WB_CORE ) )
     700             :     {
     701     1133872 :         st->last_clas = st->clas;
     702     1133872 :         move16();
     703             :     }
     704             : 
     705             :     /* Update Core */
     706     1133872 :     core_encode_update_ivas_fx( st );
     707             : 
     708             :     /*---------------------------------------------------------------------*
     709             :      * RF mode updates
     710             :      *---------------------------------------------------------------------*/
     711             : 
     712     1133872 :     IF( st->rf_mode )
     713             :     {
     714           0 :         IF( st->hSC_VBR != NULL )
     715             :         {
     716           0 :             IF( EQ_16( st->hRF->rf_frame_type, RF_NELP ) )
     717             :             {
     718           0 :                 st->hSC_VBR->last_nelp_mode = 1;
     719           0 :                 move16();
     720             :             }
     721             :             ELSE
     722             :             {
     723           0 :                 st->hSC_VBR->last_nelp_mode = 0;
     724           0 :                 move16();
     725             :             }
     726             :         }
     727             :     }
     728             : 
     729     1133872 :     st->rf_mode_last = st->rf_mode;
     730     1133872 :     move16();
     731             : 
     732     1133872 :     IF( st->Opt_RF_ON )
     733             :     {
     734           0 :         st->L_frame = L_FRAME;
     735           0 :         st->rf_mode = 1;
     736           0 :         move16();
     737           0 :         move16();
     738             :     }
     739             : 
     740             :     /*---------------------------------------------------------------------*
     741             :      * Other updates
     742             :      *---------------------------------------------------------------------*/
     743             : 
     744     1133872 :     test();
     745     1133872 :     if ( st->element_mode > EVS_MONO && st->hTcxEnc != NULL )
     746             :     {
     747     1130061 :         st->hTcxEnc->tcxltp_norm_corr_mem = st->hTcxEnc->tcxltp_norm_corr_past;
     748     1130061 :         move16();
     749             :     }
     750             : 
     751     1133872 :     return;
     752             : }

Generated by: LCOV version 1.14