LCOV - code coverage report
Current view: top level - lib_dec - hq_core_dec.c (source / functions) Hit Total Coverage
Test: Coverage on main -- short test vectors @ 6c9ddc4024a9c0e1ecb8f643f114a84a0e26ec6b Lines: 210 240 87.5 %
Date: 2025-05-23 08:37:30 Functions: 3 3 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 <math.h>
      43             : #include "cnst.h"
      44             : #include "prot.h"
      45             : #include "rom_com.h"
      46             : #include "wmc_auto.h"
      47             : #include "ivas_prot.h"
      48             : 
      49             : 
      50             : /*--------------------------------------------------------------------------
      51             :  *  hq_core_dec()
      52             :  *
      53             :  *  HQ core decoder
      54             :  *--------------------------------------------------------------------------*/
      55             : 
      56       25434 : void hq_core_dec(
      57             :     Decoder_State *st,                 /* i/o: decoder state structure                 */
      58             :     float synth[],                     /* o  : output synthesis                        */
      59             :     const int16_t output_frame,        /* i  : output frame length                     */
      60             :     const int16_t hq_core_type,        /* i  : HQ core type                            */
      61             :     const int16_t core_switching_flag, /* i  : ACELP->HQ switching frame flag          */
      62             :     float *output                      /* o  : LB synthesis in case of ACELP-HQ switch */
      63             : )
      64             : {
      65             :     int16_t num_bits, is_transient, hqswb_clas, inner_frame;
      66             :     int16_t i, j, flag_uv, num_Sb, nb_sfm;
      67             :     int16_t ynrm[NB_SFM], num_bands_p[MAX_SB_NB];
      68             :     float ener_match, mean_en_high;
      69             :     float t_audio_q[L_FRAME48k_EXT], wtda_audio[2 * L_FRAME48k];
      70             :     float wtda_audio_LB[2 * L_FRAME16k];
      71             :     int16_t delay_comp;
      72             :     float normq[NB_SFM], SWB_fenv[SWB_FENV + DIM_FB];
      73             :     const int16_t *sfmsize, *sfm_start, *sfm_end;
      74             :     float gapsynth[L_FRAME48k];
      75             : 
      76             :     HQ_DEC_HANDLE hHQ_core;
      77             :     HQ_NBFEC_HANDLE hHQ_nbfec;
      78             : 
      79             :     TCX_DEC_HANDLE hTcxDec;
      80             :     TCX_CONFIG_HANDLE tcx_cfg;
      81             :     int16_t index, left_rect, tcx_offsetFB, overlapFB, L_frameTCX;
      82             :     int16_t tcx_offset, overlap, L_frame, L_spec, fscaleFB;
      83             :     int16_t L_frameTCX_glob, L_frame_glob;
      84             :     float acelp_zir[L_FRAME_MAX / 2];
      85             :     int16_t encoderLookahead, encoderLookaheadFB;
      86             :     int16_t hq_recovery_flag;
      87             :     int16_t mdctWindowLength;
      88             :     int16_t mdctWindowLengthFB;
      89             : 
      90       25434 :     push_wmops( "hq_core_dec" );
      91             :     /*--------------------------------------------------------------------------
      92             :      * Initializations
      93             :      *--------------------------------------------------------------------------*/
      94             : 
      95       25434 :     hHQ_core = st->hHQ_core;
      96       25434 :     hHQ_nbfec = st->hHQ_nbfec;
      97             : 
      98       25434 :     set_f( t_audio_q, 0.0f, L_FRAME48k_EXT );
      99       25434 :     set_f( gapsynth, 0.0f, L_FRAME48k );
     100       25434 :     set_s( num_bands_p, 0, MAX_SB_NB );
     101       25434 :     set_s( ynrm, 39, NB_SFM ); /* Initialize to the smallest value */
     102       25434 :     mean_en_high = 0.0f;
     103       25434 :     sfm_start = sfm_end = NULL;
     104       25434 :     num_Sb = nb_sfm = 0;
     105             : 
     106       25434 :     hTcxDec = st->hTcxDec;
     107             : 
     108       25434 :     if ( st->hTcxCfg->tcx_curr_overlap_mode == FULL_OVERLAP )
     109             :     {
     110         783 :         st->hTcxCfg->tcx_last_overlap_mode = ALDO_WINDOW;
     111             :     }
     112             :     else
     113             :     {
     114       24651 :         st->hTcxCfg->tcx_last_overlap_mode = st->hTcxCfg->tcx_curr_overlap_mode;
     115             :     }
     116       25434 :     st->hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW;
     117             : 
     118       25434 :     hq_recovery_flag = ( st->last_core == ACELP_CORE ) && st->prev_bfi && ( st->element_mode > EVS_MONO ); /* ACELP -> HQtrans -> HQ; with HQtrans lost */
     119             : 
     120             :     /*--------------------------------------------------------------------------
     121             :      * Find the number of bits for transform-domain coding
     122             :      *--------------------------------------------------------------------------*/
     123             : 
     124             :     /* set the total bit-budget */
     125       25434 :     num_bits = (int16_t) ( st->total_brate / FRAMES_PER_SEC );
     126             : 
     127             :     /* Set default spectrum length */
     128       25434 :     L_spec = l_spec_tbl[st->bwidth];
     129             : 
     130       25434 :     if ( !st->bfi )
     131             :     {
     132       24807 :         if ( core_switching_flag )
     133             :         {
     134         663 :             if ( st->element_mode != EVS_MONO )
     135             :             {
     136         588 :                 L_spec = l_spec_ext_tbl[st->bwidth];
     137             :             }
     138             :             else
     139             :             {
     140             :                 /* Preprocessing in the first HQ frame after ACELP frame */
     141          75 :                 core_switching_hq_prepare_dec( st, &num_bits, output_frame );
     142             : 
     143             :                 /* During ACELP->HQ core switching, limit the HQ core bitrate to 48kbps */
     144          75 :                 if ( num_bits > HQ_48k / FRAMES_PER_SEC )
     145             :                 {
     146          36 :                     num_bits = (int16_t) ( HQ_48k / FRAMES_PER_SEC );
     147             :                 }
     148             :             }
     149             :         }
     150             : 
     151       24807 :         if ( hq_recovery_flag )
     152             :         {
     153           9 :             acelp_plc_mdct_transition( st );
     154             :         }
     155             : 
     156             :         /* subtract signaling bits */
     157       24807 :         num_bits -= st->next_bit_pos;
     158             : 
     159             :         /* set FEC parameters */
     160       24807 :         flag_uv = 1 - hHQ_core->HqVoicing;
     161             : 
     162             :         /* subtract the number of bits for pitch & gain at higher bitrates */
     163       24807 :         if ( !( core_switching_flag ) && st->core_brate > MINIMUM_RATE_TO_ENCODE_VOICING_FLAG )
     164             :         {
     165        1515 :             hHQ_core->HqVoicing = get_next_indice( st, 1 );
     166        1515 :             num_bits -= 1;
     167             :         }
     168             :         else
     169             :         {
     170       23292 :             hHQ_core->HqVoicing = 0;
     171       23292 :             if ( st->core_brate > MINIMUM_RATE_TO_ENCODE_VOICING_FLAG )
     172             :             {
     173          39 :                 hHQ_core->HqVoicing = 1;
     174             :             }
     175             :         }
     176             :     }
     177             :     else
     178             :     {
     179         627 :         flag_uv = 0;
     180             :     }
     181             : 
     182             :     /* set inner frame (== coded bandwidth) length */
     183       25434 :     inner_frame = inner_frame_tbl[st->bwidth];
     184             : 
     185       25434 :     if ( st->bfi == 0 )
     186             :     {
     187       24807 :         if ( output_frame >= L_FRAME16k )
     188             :         {
     189       24807 :             hHQ_core->ph_ecu_HqVoicing = hHQ_core->HqVoicing;
     190             :         }
     191             :         else
     192             :         {
     193           0 :             hHQ_core->ph_ecu_HqVoicing = 0;
     194             :         }
     195             :     }
     196             : 
     197       25434 :     if ( output_frame == L_FRAME8k )
     198             :     {
     199           0 :         hq_configure_bfi( &nb_sfm, &num_Sb, num_bands_p, &sfmsize, &sfm_start, &sfm_end );
     200             :     }
     201             : 
     202             :     /*--------------------------------------------------------------------------
     203             :      * transform-domain decoding
     204             :      *--------------------------------------------------------------------------*/
     205             : 
     206       25434 :     if ( st->bfi )
     207             :     {
     208         627 :         is_transient = hHQ_core->old_is_transient[0];
     209         627 :         if ( output_frame >= L_FRAME16k )
     210             :         {
     211         627 :             hq_ecu( st->hTcxDec->prev_good_synth, t_audio_q, &hHQ_core->time_offs, hHQ_core->X_sav, &hHQ_core->num_p, hHQ_core->plocs, hHQ_core->plocsi, hHQ_core->env_stab, &hHQ_core->last_fec, hHQ_core->ph_ecu_HqVoicing, &hHQ_core->ph_ecu_active, gapsynth, st->prev_bfi, hHQ_core->old_is_transient, hHQ_core->mag_chg_1st, hHQ_core->Xavg, &hHQ_core->beta_mute, output_frame, st );
     212             :         }
     213             :         else
     214             :         {
     215           0 :             HQ_FEC_processing( st, t_audio_q, is_transient, hHQ_nbfec->ynrm_values, hHQ_nbfec->r_p_values, num_Sb, nb_sfm, num_bands_p, output_frame, sfm_start, sfm_end );
     216             :         }
     217             : 
     218         627 :         hHQ_core->old_is_transient[2] = hHQ_core->old_is_transient[1];
     219         627 :         hHQ_core->old_is_transient[1] = hHQ_core->old_is_transient[0];
     220             : 
     221         627 :         if ( output_frame >= L_FRAME16k )
     222             :         {
     223             :             /* keep st->previoussynth updated as in FEC_HQ_pitch_analysis but no LP analysis */
     224         627 :             delay_comp = NS2SA( st->output_Fs, DELAY_CLDFB_NS );
     225         627 :             mvr2r( st->previoussynth + delay_comp, st->previoussynth, output_frame - delay_comp );
     226         627 :             mvr2r( st->delay_buf_out, st->previoussynth + output_frame - delay_comp, delay_comp );
     227             : 
     228         627 :             flag_uv = 1;                                      /*  disable costly pitch out synthesis in bfi frame  */
     229         627 :             hHQ_core->HqVoicing = 1 - flag_uv;                /*  safety setting for HQ->ACELP switch logic           */
     230         627 :             set_f( hHQ_core->fer_samples, 0.0f, L_FRAME48k ); /*  safety, create a known signal state for HQ->ACELP switch logic */
     231             :         }
     232             :     }
     233             :     else
     234             :     {
     235       24807 :         if ( hq_core_type == LOW_RATE_HQ_CORE )
     236             :         {
     237         102 :             if ( st->prev_bfi == 1 )
     238             :             {
     239           0 :                 set_f( hHQ_core->last_ni_gain, 0, BANDS_MAX );
     240           0 :                 set_f( hHQ_core->last_env, 0, BANDS_MAX );
     241           0 :                 hHQ_core->last_max_pos_pulse = 0;
     242             :             }
     243             : 
     244             :             /* HQ low rate decoder */
     245         102 :             hq_lr_dec( st, t_audio_q, inner_frame, num_bits, &is_transient );
     246             : 
     247         102 :             hqswb_clas = is_transient;
     248             :         }
     249             :         else
     250             :         {
     251             :             /* HQ high rate decoder */
     252       24705 :             hq_hr_dec( st, t_audio_q, L_spec, num_bits, ynrm, &is_transient, &hqswb_clas, SWB_fenv, core_switching_flag );
     253             :         }
     254             : 
     255       24807 :         if ( st->element_mode == EVS_MONO || ( !core_switching_flag && !hq_recovery_flag ) )
     256             :         {
     257             :             /* scaling (coefficients are in nominal level) */
     258       24213 :             if ( output_frame != NORM_MDCT_FACTOR )
     259             :             {
     260       24213 :                 ener_match = (float) sqrt( (float) output_frame / (float) NORM_MDCT_FACTOR );
     261             : 
     262    20616213 :                 for ( i = 0; i < inner_frame; i++ )
     263             :                 {
     264    20592000 :                     t_audio_q[i] *= ener_match;
     265             :                 }
     266             :             }
     267             :         }
     268             : 
     269       24807 :         HQ_FEC_Mem_update( st, t_audio_q, normq, ynrm, num_bands_p, is_transient, hqswb_clas, core_switching_flag, nb_sfm, num_Sb, &mean_en_high, hq_core_type, output_frame );
     270             :     }
     271             : 
     272             :     /*--------------------------------------------------------------------------
     273             :      * Attenuate HFs in case of band-width switching (from higher BW to lower BW)
     274             :      *--------------------------------------------------------------------------*/
     275             : 
     276             :     /* attenuate HFs in case of band-width switching */
     277       25434 :     if ( st->bws_cnt1 > 0 )
     278             :     {
     279           0 :         ener_match = (float) st->bws_cnt1 / (float) N_NS2W_FRAMES;
     280             : 
     281           0 :         if ( is_transient )
     282             :         {
     283           0 :             for ( i = 0; i < NUM_TIME_SWITCHING_BLOCKS; i++ )
     284             :             {
     285           0 :                 for ( j = inner_frame_tbl[st->bwidth - 1] / NUM_TIME_SWITCHING_BLOCKS; j < inner_frame / NUM_TIME_SWITCHING_BLOCKS; j++ )
     286             :                 {
     287           0 :                     t_audio_q[i * inner_frame / NUM_TIME_SWITCHING_BLOCKS + j] *= ener_match;
     288             :                 }
     289             :             }
     290             :         }
     291             :         else
     292             :         {
     293           0 :             for ( i = inner_frame_tbl[st->bwidth - 1]; i < inner_frame; i++ )
     294             :             {
     295           0 :                 t_audio_q[i] *= ener_match;
     296             :             }
     297             :         }
     298             :     }
     299             : 
     300             :     /* WB/SWB bandwidth switching */
     301       25434 :     if ( is_transient )
     302             :     {
     303        1656 :         mvr2r( t_audio_q + 240, st->t_audio_q, 80 );
     304             :     }
     305             :     else
     306             :     {
     307       23778 :         mvr2r( t_audio_q, st->t_audio_q, L_FRAME );
     308             :     }
     309             : 
     310             :     /*--------------------------------------------------------------------------
     311             :      * Inverse transform
     312             :      * Overlap-add
     313             :      * Pre-echo reduction
     314             :      *--------------------------------------------------------------------------*/
     315             : 
     316       25434 :     if ( st->element_mode > EVS_MONO && ( core_switching_flag || hq_recovery_flag ) )
     317             :     {
     318             :         /* Initializations for TCX MDCT framework, to be used for switching frame */
     319         594 :         tcx_cfg = st->hTcxCfg;
     320         594 :         L_frameTCX_glob = hTcxDec->L_frameTCX;
     321         594 :         L_frame_glob = st->L_frame;
     322         594 :         L_spec = hTcxDec->L_frameTCX;
     323         594 :         st->fscale = sr2fscale( st->sr_core );
     324         594 :         fscaleFB = sr2fscale( st->output_Fs );
     325         594 :         encoderLookahead = ( L_LOOK_12k8 * st->fscale ) / FSCALE_DENOM;
     326         594 :         encoderLookaheadFB = ( L_LOOK_12k8 * fscaleFB ) / FSCALE_DENOM;
     327         594 :         mdctWindowLength = getMdctWindowLength( st->fscale );
     328         594 :         mdctWindowLengthFB = (int16_t) ( mdctWindowLength * st->output_Fs / st->sr_core );
     329         594 :         if ( core_switching_flag )
     330             :         {
     331         588 :             tcx_cfg->tcx_last_overlap_mode = TRANSITION_OVERLAP;
     332         588 :             tcx_cfg->tcx_curr_overlap_mode = FULL_OVERLAP;
     333             :         }
     334             :         else
     335             :         {
     336           6 :             tcx_cfg->tcx_last_overlap_mode = ALDO_WINDOW;
     337           6 :             tcx_cfg->tcx_curr_overlap_mode = ALDO_WINDOW;
     338           6 :             st->last_core = HQ_CORE; /* Needed to decode non-transition frame */
     339             :         }
     340             : 
     341         594 :         init_tcx_window_cfg( tcx_cfg, st->sr_core, st->output_Fs, st->L_frame, hTcxDec->L_frameTCX, encoderLookahead, encoderLookaheadFB, mdctWindowLength, mdctWindowLengthFB, st->element_mode );
     342             : 
     343         594 :         init_tcx_info( st, L_frame_glob, L_frameTCX_glob, 0, st->bfi, &tcx_offset, &tcx_offsetFB, &L_frame, &L_frameTCX, &left_rect, &L_spec );
     344             : 
     345         594 :         overlap = tcx_cfg->tcx_mdct_window_length;
     346         594 :         overlapFB = tcx_cfg->tcx_mdct_window_lengthFB;
     347         594 :         index = tcx_cfg->tcx_last_overlap_mode;
     348             : 
     349             :         /* LB synthesis */
     350         594 :         IMDCT( t_audio_q, hTcxDec->syn_Overl, hTcxDec->syn_Overl_TDAC, wtda_audio, tcx_cfg->tcx_aldo_window_1_trunc, tcx_cfg->tcx_aldo_window_2, tcx_cfg->tcx_mdct_window_half, tcx_cfg->tcx_mdct_window_minimum, tcx_cfg->tcx_mdct_window_trans, tcx_cfg->tcx_mdct_window_half_length, tcx_cfg->tcx_mdct_window_min_length, index,
     351         594 :                MDCT_IV, left_rect, tcx_offset, overlap, L_frame, L_frameTCX, max( L_frameTCX, L_spec ) >> 1, L_frame_glob, 0, st->bfi, hHQ_core->old_outLB, 0, st, 0, acelp_zir );
     352             : 
     353         594 :         mvr2r( wtda_audio + ( overlap >> 1 ) - tcx_offset, output, L_frame_glob );
     354             : 
     355             :         /* FB synthesis */
     356         594 :         IMDCT( t_audio_q, hTcxDec->syn_OverlFB, hTcxDec->syn_Overl_TDACFB, wtda_audio, tcx_cfg->tcx_aldo_window_1_FB_trunc, tcx_cfg->tcx_aldo_window_2_FB, tcx_cfg->tcx_mdct_window_halfFB, tcx_cfg->tcx_mdct_window_minimumFB, tcx_cfg->tcx_mdct_window_transFB, tcx_cfg->tcx_mdct_window_half_lengthFB, tcx_cfg->tcx_mdct_window_min_lengthFB, index,
     357         594 :                MDCT_IV, left_rect, tcx_offsetFB, overlapFB, L_frameTCX, L_frameTCX, max( L_frameTCX, L_spec ) >> 1, L_frameTCX_glob, 0, st->bfi, hHQ_core->old_out, 1, st, FSCALE_DENOM * L_frameTCX_glob / L_frame_glob, acelp_zir );
     358             : 
     359         594 :         mvr2r( wtda_audio + ( overlapFB >> 1 ) - tcx_offsetFB, synth, L_frameTCX_glob );
     360             : 
     361         594 :         if ( !core_switching_flag )
     362             :         {
     363           6 :             st->last_core = ACELP_CORE; /* Restore last core */
     364             :         }
     365             :     }
     366             :     else
     367             :     {
     368       24840 :         if ( output_frame == L_FRAME8k || st->bfi == 0 )
     369             :         {
     370       24213 :             if ( ( output_frame != inner_frame ) && ( st->bfi == 1 ) )
     371             :             {
     372           0 :                 inverse_transform( t_audio_q, wtda_audio, is_transient, output_frame, output_frame, st->element_mode );
     373             :             }
     374             :             else
     375             :             {
     376       24213 :                 inverse_transform( t_audio_q, wtda_audio, is_transient, output_frame, inner_frame, st->element_mode );
     377             :             }
     378             :         }
     379             : 
     380       24840 :         if ( st->element_mode > EVS_MONO )
     381             :         {
     382       23520 :             if ( st->bfi )
     383             :             {
     384             :                 /* Rough resampling, but reduces energy loss in case of switch to ACELP in first good frame */
     385         627 :                 lerp( t_audio_q, wtda_audio_LB, st->L_frame, inner_frame );
     386         627 :                 v_multc( t_audio_q, 0.5f, wtda_audio_LB, st->L_frame );
     387             :             }
     388             :             else
     389             :             {
     390             :                 /* LB synthesis for potential switch to ACELP */
     391       22893 :                 ener_match = (float) sqrt( (float) st->L_frame / (float) output_frame );
     392       22893 :                 v_multc( t_audio_q, ener_match, t_audio_q, inner_frame );
     393       22893 :                 inverse_transform( t_audio_q, wtda_audio_LB, is_transient, st->L_frame, inner_frame, st->element_mode );
     394             :             }
     395             :         }
     396             : 
     397       24840 :         if ( output_frame == L_FRAME8k )
     398             :         {
     399           0 :             if ( st->bfi == 0 && st->prev_bfi == 0 )
     400             :             {
     401           0 :                 mvr2r( hHQ_core->old_out + (int16_t) ( N_ZERO_MDCT_NS * output_frame / FRAME_SIZE_NS ), hHQ_nbfec->prev_oldauOut, output_frame - (int16_t) ( N_ZERO_MDCT_NS * output_frame / FRAME_SIZE_NS ) );
     402             :             }
     403           0 :             else if ( st->prev_bfi == 1 )
     404             :             {
     405           0 :                 set_f( hHQ_nbfec->prev_oldauOut, 0.0f, output_frame );
     406             :             }
     407             : 
     408           0 :             if ( ( st->prev_bfi == 1 || st->bfi == 1 ) && !hHQ_core->old_is_transient[2] && st->last_core == HQ_CORE && st->last_codec_mode == MODE1 )
     409             :             {
     410           0 :                 time_domain_FEC_HQ( st, wtda_audio, synth, mean_en_high, output_frame );
     411             :             }
     412             :             else
     413             :             {
     414           0 :                 window_ola( wtda_audio, synth, hHQ_core->old_out, output_frame, st->hTcxCfg->tcx_last_overlap_mode, st->hTcxCfg->tcx_curr_overlap_mode, st->prev_bfi, hHQ_core->oldHqVoicing, hHQ_core->oldgapsynth );
     415           0 :                 hHQ_nbfec->phase_mat_next = 0;
     416             :             }
     417             : 
     418           0 :             if ( ( !st->bfi && !st->prev_bfi ) || ( !( output_frame >= L_FRAME16k ) ) )
     419             :             {
     420           0 :                 preecho_sb( st->core_brate, wtda_audio, synth, output_frame, &hHQ_core->memfilt_lb, &hHQ_core->mean_prev_hb, &hHQ_core->smoothmem, &hHQ_core->mean_prev, &hHQ_core->mean_prev_nc, &hHQ_core->wmold_hb, &hHQ_core->prevflag, &hHQ_core->pastpre, st->bwidth );
     421             :             }
     422             :         }
     423             :         else
     424             :         {
     425       24840 :             if ( st->bfi && output_frame >= L_FRAME16k )
     426             :             {
     427         627 :                 window_ola( t_audio_q, synth, hHQ_core->old_out, output_frame, ALDO_WINDOW, ALDO_WINDOW, st->prev_bfi && !hHQ_core->ph_ecu_active, hHQ_core->oldHqVoicing, hHQ_core->oldgapsynth );
     428             :             }
     429             :             else
     430             :             {
     431       24213 :                 window_ola( wtda_audio, synth, hHQ_core->old_out, output_frame, st->hTcxCfg->tcx_last_overlap_mode, st->hTcxCfg->tcx_curr_overlap_mode, st->prev_bfi && !hHQ_core->ph_ecu_active, hHQ_core->oldHqVoicing, hHQ_core->oldgapsynth );
     432             :             }
     433             : 
     434       24840 :             if ( st->element_mode > EVS_MONO )
     435             :             {
     436             :                 /* LB synthesis for potential switch to ACELP */
     437       23520 :                 window_ola( wtda_audio_LB, output, hHQ_core->old_outLB, L_FRAME16k, st->hTcxCfg->tcx_last_overlap_mode, st->hTcxCfg->tcx_curr_overlap_mode, st->prev_bfi && !hHQ_core->ph_ecu_active, hHQ_core->oldHqVoicing, hHQ_core->oldgapsynth );
     438             :             }
     439             : 
     440       24840 :             if ( ( !st->bfi && !st->prev_bfi ) || ( !( output_frame >= L_FRAME16k ) ) )
     441             :             {
     442       23865 :                 preecho_sb( st->core_brate, wtda_audio, synth, output_frame, &hHQ_core->memfilt_lb, &hHQ_core->mean_prev_hb, &hHQ_core->smoothmem, &hHQ_core->mean_prev, &hHQ_core->mean_prev_nc, &hHQ_core->wmold_hb, &hHQ_core->prevflag, &hHQ_core->pastpre, st->bwidth );
     443             :             }
     444             :         }
     445             :     }
     446             : 
     447       25434 :     if ( !st->bfi && st->prev_bfi && st->last_total_brate >= HQ_48k && st->last_codec_mode == MODE2 && ( st->last_core_bfi == TCX_20_CORE || st->last_core_bfi == TCX_10_CORE ) && st->hPlcInfo->concealment_method == TCX_NONTONAL && st->hPlcInfo->nbLostCmpt < 4 )
     448             :     {
     449           0 :         waveform_adj2( st->hPlcInfo, st->hTonalMDCTConc->secondLastPcmOut, synth, 0, st->hPlcInfo->nbLostCmpt + 1, st->bfi );
     450             :     }
     451             : 
     452       25434 :     if ( output_frame >= L_FRAME16k )
     453             :     {
     454       25434 :         if ( hHQ_core->ph_ecu_HqVoicing )
     455             :         {
     456          39 :             hHQ_core->oldHqVoicing = 1;
     457          39 :             mvr2r( gapsynth, hHQ_core->oldgapsynth, L_FRAME48k );
     458             :         }
     459             :         else
     460             :         {
     461       25395 :             hHQ_core->oldHqVoicing = 0;
     462             :         }
     463             :     }
     464             :     else
     465             :     {
     466           0 :         hHQ_core->oldHqVoicing = 0;
     467             :     }
     468             : 
     469       25434 :     if ( st->nbLostCmpt == FRAMECTTOSTART_MDCT )
     470             :     {
     471           6 :         hHQ_core->HqVoicing = 0;
     472             :     }
     473             : 
     474       25434 :     if ( output_frame == L_FRAME8k )
     475             :     {
     476           0 :         mvr2r( wtda_audio, hHQ_nbfec->oldIMDCTout, L_FRAME8k / 2 );
     477           0 :         mvr2r( hHQ_nbfec->old_auOut_2fr + output_frame, hHQ_nbfec->old_auOut_2fr, output_frame );
     478           0 :         mvr2r( synth, hHQ_nbfec->old_auOut_2fr + output_frame, output_frame );
     479             :     }
     480             : 
     481             : 
     482             :     /* update buffer of old subframe pitch values */
     483       25434 :     if ( st->last_core == HQ_CORE && st->L_frame != st->last_L_frame )
     484             :     {
     485           0 :         set_f( &st->old_pitch_buf[st->L_frame / L_SUBFR], (float) L_SUBFR, st->L_frame / L_SUBFR );
     486             :     }
     487       25434 :     mvr2r( &st->old_pitch_buf[st->L_frame / L_SUBFR], st->old_pitch_buf, st->L_frame / L_SUBFR );
     488       25434 :     set_f( &st->old_pitch_buf[st->L_frame / L_SUBFR], (float) L_SUBFR, st->L_frame / L_SUBFR );
     489       25434 :     mvr2r( &st->mem_pitch_gain[2], &st->mem_pitch_gain[st->L_frame / L_SUBFR + 2], st->L_frame / L_SUBFR );
     490       25434 :     set_zero( &st->mem_pitch_gain[2], st->L_frame / L_SUBFR );
     491             : 
     492             :     /* Move LB excitation to old_exc memory in case of switch HQ->ACELP */
     493       25434 :     if ( st->element_mode > EVS_MONO )
     494             :     {
     495       24114 :         mvr2r( output, st->old_exc + L_EXC_MEM_DEC - st->L_frame, st->L_frame );
     496             :     }
     497             : 
     498       25434 :     pop_wmops();
     499       25434 :     return;
     500             : }
     501             : 
     502             : 
     503             : /*-------------------------------------------------------------------*
     504             :  * hq_core_dec_init()
     505             :  *
     506             :  * Initialize HQ core state structure
     507             :  *-------------------------------------------------------------------*/
     508             : 
     509       28422 : void HQ_core_dec_init(
     510             :     HQ_DEC_HANDLE hHQ_core /* i/o: HQ core data handle  */
     511             : )
     512             : {
     513             : 
     514       28422 :     set_f( hHQ_core->old_out, 0, L_FRAME48k );
     515       28422 :     set_f( hHQ_core->old_outLB, 0, L_FRAME32k );
     516       28422 :     set_s( hHQ_core->old_is_transient, 0, 3 );
     517             : 
     518       28422 :     hHQ_core->oldHqVoicing = 0;
     519             : 
     520       28422 :     set_f( hHQ_core->prev_noise_level, 0.0f, 2 );
     521       28422 :     hHQ_core->prev_R = 0;
     522       28422 :     set_f( hHQ_core->prev_coeff_out, 0, L_HQ_WB_BWE );
     523       28422 :     set_s( hHQ_core->prev_SWB_peak_pos, 0, SPT_SHORTEN_SBNUM );
     524             : 
     525             :     /* HQ GENERIC */
     526       28422 :     hHQ_core->hq_generic_seed = RANDOM_INITSEED;
     527             : 
     528       28422 :     hHQ_core->mem_norm[0] = 31;
     529       28422 :     set_s( hHQ_core->mem_norm + 1, 39, SFM_N_ENV_STAB - 1 );
     530       28422 :     hHQ_core->mem_env_delta = 0;
     531       28422 :     hHQ_core->no_att_hangover = 0;
     532       28422 :     hHQ_core->energy_lt = 300.0f;
     533             : 
     534       28422 :     hHQ_core->HqVoicing = 0;
     535       28422 :     set_f( hHQ_core->fer_samples, 0, L_FRAME48k );
     536       28422 :     set_f( hHQ_core->prev_env, 0, SFM_N_WB );
     537       28422 :     set_f( hHQ_core->prev_normq, 0, SFM_N_WB );
     538       28422 :     hHQ_core->prev_hqswb_clas = HQ_NORMAL;
     539             : 
     540       28422 :     set_f( hHQ_core->last_ni_gain, 0, BANDS_MAX );
     541       28422 :     set_f( hHQ_core->last_env, 0, BANDS_MAX );
     542       28422 :     hHQ_core->last_max_pos_pulse = 0;
     543       28422 :     hHQ_core->prev_frm_hfe2 = 0;
     544       28422 :     hHQ_core->prev_stab_hfe2 = 0;
     545       28422 :     hHQ_core->prev_ni_ratio = 0.5f;
     546       28422 :     set_f( hHQ_core->prev_En_sb, 0.0f, NB_SWB_SUBBANDS );
     547             : 
     548             : 
     549             :     /*----------------------------------------------------------------------------------*
     550             :      * HQ FEC
     551             :      *----------------------------------------------------------------------------------*/
     552             : 
     553       28422 :     set_f( hHQ_core->X_sav, 0.0f, PH_ECU_SPEC_SIZE );
     554       28422 :     hHQ_core->num_p = 0;
     555       28422 :     hHQ_core->ph_ecu_active = 0;
     556       28422 :     hHQ_core->ni_seed_forfec = 0;
     557       28422 :     hHQ_core->last_fec = 0;
     558       28422 :     hHQ_core->ph_ecu_HqVoicing = 0;
     559       28422 :     set_f( hHQ_core->oldgapsynth, 0.0f, L_FRAME48k );
     560       28422 :     hHQ_core->env_stab = 0.75f;
     561       28422 :     hHQ_core->mem_norm_hqfec[0] = 31;
     562       28422 :     set_s( hHQ_core->mem_norm_hqfec + 1, 39, SFM_N_ENV_STAB - 1 );
     563       28422 :     hHQ_core->mem_env_delta_hqfec = 0;
     564       28422 :     hHQ_core->env_stab_plc = 0.0f;
     565       28422 :     set_f( hHQ_core->env_stab_state_p, 1.0f / NUM_ENV_STAB_PLC_STATES, NUM_ENV_STAB_PLC_STATES );
     566       28422 :     hHQ_core->envstabplc_hocnt = 0;
     567             : 
     568       28422 :     set_f( hHQ_core->mag_chg_1st, 1.0f, LGW_MAX );
     569       28422 :     set_f( hHQ_core->Xavg, 0.0f, LGW_MAX );
     570       28422 :     hHQ_core->beta_mute = BETA_MUTE_FAC_INI;
     571             : 
     572       28422 :     hHQ_core->time_offs = 0;
     573       28422 :     hHQ_core->ber_occured_in_pvq = 0;
     574             : 
     575       28422 :     hHQ_core->last_hq_core_type = -1;
     576             : 
     577       28422 :     reset_preecho_dec( hHQ_core );
     578             : 
     579       28422 :     return;
     580             : }
     581             : 
     582             : /*-------------------------------------------------------------------*
     583             :  * HQ_nbfec_init()
     584             :  *
     585             :  * Initialize HQ NB FEC state structure
     586             :  *-------------------------------------------------------------------*/
     587             : 
     588           9 : void HQ_nbfec_init(
     589             :     HQ_NBFEC_HANDLE hHQ_nbfec /* i/o: HQ NB FEC data handle  */
     590             : )
     591             : {
     592             :     int16_t i, j;
     593             : 
     594           9 :     hHQ_nbfec->prev_last_core = -1;
     595             : 
     596           9 :     set_f( hHQ_nbfec->old_coeffs, 0, L_FRAME8k );
     597           9 :     set_f( hHQ_nbfec->old_auOut_2fr, 0, L_FRAME8k * 2 );
     598           9 :     set_f( hHQ_nbfec->old_out_pha[0], 0, N_LEAD_NB );
     599           9 :     set_f( hHQ_nbfec->old_out_pha[1], 0, N_LEAD_NB );
     600             : 
     601           9 :     hHQ_nbfec->phase_mat_flag = 0;
     602           9 :     hHQ_nbfec->phase_mat_next = 0;
     603           9 :     hHQ_nbfec->old_Min_ind = 0;
     604           9 :     hHQ_nbfec->diff_energy = 0.f;
     605           9 :     set_f( hHQ_nbfec->oldIMDCTout, 0.f, L_FRAME8k / 2 );
     606           9 :     set_f( hHQ_nbfec->prev_oldauOut, 0.f, L_FRAME8k );
     607           9 :     hHQ_nbfec->stat_mode_out = 0;
     608           9 :     hHQ_nbfec->stat_mode_old = 0;
     609             : 
     610          36 :     for ( i = 0; i < MAX_SB_NB; i++ )
     611             :     {
     612         216 :         for ( j = 0; j < MAX_PGF; j++ )
     613             :         {
     614         189 :             hHQ_nbfec->ynrm_values[i][j] = 0.f;
     615             :         }
     616          81 :         for ( j = 0; j < MAX_ROW; j++ )
     617             :         {
     618          54 :             hHQ_nbfec->r_p_values[i][j] = 0.f;
     619             :         }
     620             :     }
     621           9 :     set_f( hHQ_nbfec->Norm_gain, 1.f, SFM_N_NB );
     622           9 :     set_f( hHQ_nbfec->energy_MA_Curr, 100.f, 2 );
     623           9 :     hHQ_nbfec->HQ_FEC_seed = RANDOM_INITSEED;
     624             : 
     625           9 :     set_s( hHQ_nbfec->prev_sign_switch, 0, HQ_FEC_SIGN_SFM );
     626           9 :     set_s( hHQ_nbfec->prev_sign_switch_2, 0, HQ_FEC_SIGN_SFM );
     627             : 
     628           9 :     return;
     629             : }

Generated by: LCOV version 1.14