From a3388112d14f071b9d70b59c8c68149ed5845029 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Wed, 13 Nov 2024 10:54:16 +0530 Subject: [PATCH 1/3] LTV crash fixes for encoder, float struct elements cleanup --- lib_com/ivas_dirac_com.c | 18 ++-- lib_dec/er_dec_tcx_fx.c | 5 +- lib_dec/tonalMDCTconcealment_fx.c | 4 + lib_enc/core_switching_enc.c | 11 ++- lib_enc/init_enc.c | 9 +- lib_enc/ivas_core_enc.c | 11 ++- lib_enc/ivas_core_pre_proc.c | 1 + lib_enc/ivas_masa_enc.c | 6 +- lib_enc/ivas_spar_encoder.c | 8 +- lib_enc/ivas_stereo_switching_enc.c | 4 +- lib_enc/ivas_stereo_td_enc.c | 5 +- lib_enc/ivas_tcx_core_enc.c | 7 +- lib_enc/prot_fx_enc.h | 4 + lib_enc/stat_enc.h | 58 +++++-------- lib_enc/swb_bwe_enc_fx.c | 90 ++++++++++++++------ lib_enc/swb_tbe_enc.c | 68 +++------------ lib_enc/swb_tbe_enc_fx.c | 127 +++++++++++++++++++++++++--- 17 files changed, 270 insertions(+), 166 deletions(-) diff --git a/lib_com/ivas_dirac_com.c b/lib_com/ivas_dirac_com.c index 214910cd3..aea7d7664 100644 --- a/lib_com/ivas_dirac_com.c +++ b/lib_com/ivas_dirac_com.c @@ -2100,7 +2100,8 @@ void calculate_hodirac_sector_parameters_fx( normI_fx = BASOP_Util_Add_Mant32Exp( tmp32, tmp_e, tmp_z, shl( *p_sec_I_vec_smth_z_exp, 1 ), &normI_exp ); normI_fx = Sqrt32( normI_fx, &normI_exp ); - tmp_xy_hypo = Sqrt32( tmp32, &tmp_e ); // sqrt(x^2 + y^2) + tmp32 = BASOP_Util_Add_Mant32Exp( tmp32, tmp_e, 0, 0, &tmp_e ); // normalising value of tmp32 + tmp_xy_hypo = Sqrt32( tmp32, &tmp_e ); // sqrt(x^2 + y^2) tmp16 = BASOP_util_atan2( *p_sec_I_vec_smth_y_fx, *p_sec_I_vec_smth_x_fx, sub( *p_sec_I_vec_smth_y_exp, *p_sec_I_vec_smth_x_exp ) ); // Q13 *p_azi_fx = Mpy_32_32( L_deposit_h( tmp16 ), _180_OVER_PI_Q25 ); // (Q13 + 16) + Q25 - 31 = 54 - 31 = Q23 @@ -2124,9 +2125,8 @@ void calculate_hodirac_sector_parameters_fx( move32(); tmp_diff_exp = *p_diff_exp; move16(); - // NOTE: here, assuming abs(tmp_diff) <= 1.0. --> Q30 - tmp_diff_fx = L_shr( tmp_diff_fx, sub( 1, tmp_diff_exp ) ); - tmp_diff_exp = 1; + tmp_diff_fx = L_shr( tmp_diff_fx, sub( 2, tmp_diff_exp ) ); // Q29 + tmp_diff_exp = 2; move16(); IF( tmp_diff_fx < 0 ) @@ -2134,7 +2134,7 @@ void calculate_hodirac_sector_parameters_fx( *p_diff_fx = 0; move32(); } - IF( GT_32( tmp_diff_fx, ( ONE_IN_Q30 / 2 ) ) ) + IF( GT_32( tmp_diff_fx, ( ONE_IN_Q29 / 2 ) ) ) { IF( hDirAC->firstrun_sector_params ) { @@ -2145,13 +2145,13 @@ void calculate_hodirac_sector_parameters_fx( } ELSE { - *p_azi_fx = L_shl( L_add( Mpy_32_32( L_sub( ONE_IN_Q30, tmp_diff_fx ), *p_azi_fx ), Mpy_32_32( L_sub( tmp_diff_fx, ONE_IN_Q30 / 2 ), *p_azi_prev_fx ) ), 1 ); // Q30 + Q23 - 31 = Q22 + *p_azi_fx = L_shl( L_add( Mpy_32_32( L_sub( ONE_IN_Q29, tmp_diff_fx ), *p_azi_fx ), Mpy_32_32( L_sub( tmp_diff_fx, ONE_IN_Q29 / 2 ), *p_azi_prev_fx ) ), 1 ); // Q29 + Q23 - 31 = Q21 move32(); - *p_ele_fx = L_shl( L_add( Mpy_32_32( L_sub( ONE_IN_Q30, tmp_diff_fx ), *p_ele_fx ), Mpy_32_32( L_sub( tmp_diff_fx, ONE_IN_Q30 / 2 ), *p_ele_prev_fx ) ), 1 ); // Q30 + Q23 - 31 = Q22 + *p_ele_fx = L_shl( L_add( Mpy_32_32( L_sub( ONE_IN_Q29, tmp_diff_fx ), *p_ele_fx ), Mpy_32_32( L_sub( tmp_diff_fx, ONE_IN_Q29 / 2 ), *p_ele_prev_fx ) ), 1 ); // Q29 + Q23 - 31 = Q21 move32(); - *p_azi_fx = L_shl( *p_azi_fx, 1 ); // Q22 -> Q23; + *p_azi_fx = L_shl( *p_azi_fx, 2 ); // Q21 -> Q23; move32(); - *p_ele_fx = L_shl( *p_ele_fx, 1 ); // Q22 -> Q23; + *p_ele_fx = L_shl( *p_ele_fx, 2 ); // Q21 -> Q23; move32(); } } diff --git a/lib_dec/er_dec_tcx_fx.c b/lib_dec/er_dec_tcx_fx.c index ab1d72279..897d6f2e7 100644 --- a/lib_dec/er_dec_tcx_fx.c +++ b/lib_dec/er_dec_tcx_fx.c @@ -2104,8 +2104,9 @@ void con_tcx_ivas_fx( move16(); /* create aliasing and windowing need for transition to TCX10/5 */ - bufferCopyFx( syn + L_frame, hTcxDec->syn_Overl_TDACFB, shr( L_frame, 1 ), Q_syn, 0, -1, 0 ); - hTcxDec->Q_syn_Overl_TDACFB = add( Q_syn, -1 ); + // bufferCopyFx( syn + L_frame, hTcxDec->syn_Overl_TDACFB, shr( L_frame, 1 ), Q_syn, 0, -1, 0 ); + Copy_Scale_sig( syn + L_frame, hTcxDec->syn_Overl_TDACFB, shr( L_frame, 1 ), sub( Q_syn, 1 ) ); + hTcxDec->Q_syn_Overl_TDACFB = sub( Q_syn, 1 ); move16(); FOR( i = 0; i < W12; i++ ) diff --git a/lib_dec/tonalMDCTconcealment_fx.c b/lib_dec/tonalMDCTconcealment_fx.c index 0170aa985..fa085d987 100644 --- a/lib_dec/tonalMDCTconcealment_fx.c +++ b/lib_dec/tonalMDCTconcealment_fx.c @@ -231,6 +231,10 @@ ivas_error TonalMDCTConceal_Init_ivas_fx( move16(); move16(); /* just the second half of the second last pcm output is needed */ + +#ifdef MSAN_FIX + set16_fx( hTonalMDCTConc->timeDataBuffer, 0, ( 3 * L_FRAME_MAX ) / 2 ); +#endif hTonalMDCTConc->secondLastPcmOut = &hTonalMDCTConc->timeDataBuffer[( 3 * L_FRAME_MAX ) / 2 - ( 3 * min( L_FRAME_MAX, nSamples ) / 2 )]; hTonalMDCTConc->lastPcmOut = &hTonalMDCTConc->timeDataBuffer[( 3 * L_FRAME_MAX ) / 2 - min( L_FRAME_MAX, nSamples )]; /* If the second last frame was lost, we reuse saved TonalComponentsInfo and don't update pcm buffers */ diff --git a/lib_enc/core_switching_enc.c b/lib_enc/core_switching_enc.c index c5f197eeb..142248112 100644 --- a/lib_enc/core_switching_enc.c +++ b/lib_enc/core_switching_enc.c @@ -957,10 +957,6 @@ void core_switching_post_enc( #ifdef IVAS_FLOAT_FIXED InitSWBencBufferStates_fx( st->hBWE_TD, NULL ); swb_tbe_reset_fx( st->hBWE_TD->mem_csfilt_fx, st->hBWE_TD->mem_genSHBexc_filt_down_shb_fx, st->hBWE_TD->state_lpc_syn_fx, st->hBWE_TD->syn_overlap_fx, st->hBWE_TD->state_syn_shbexc_fx, &( st->hBWE_TD->tbe_demph_fx ), &( st->hBWE_TD->tbe_premph_fx ), st->hBWE_TD->mem_stp_swb_fx, &( st->hBWE_TD->gain_prec_swb_fx ) ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - /* To be removed later when the function is converted to fixed*/ - InitSWBencBufferStates( st->hBWE_TD, NULL ); -#endif #else InitSWBencBufferStates( st->hBWE_TD, NULL ); swb_tbe_reset( st->hBWE_TD->mem_csfilt, st->hBWE_TD->mem_genSHBexc_filt_down_shb, st->hBWE_TD->state_lpc_syn, st->hBWE_TD->syn_overlap, st->hBWE_TD->state_syn_shbexc, &( st->hBWE_TD->tbe_demph ), &( st->hBWE_TD->tbe_premph ), st->hBWE_TD->mem_stp_swb, &( st->hBWE_TD->gain_prec_swb ) ); @@ -1007,11 +1003,14 @@ void core_switching_post_enc( /* Interp_3_2 CNG buffers reset */ if ( st->extl == FB_TBE && ( ( st->last_extl != FB_TBE && st->last_core != TCX_20_CORE && st->last_core != TCX_10_CORE ) || st->L_frame != st->last_L_frame ) ) { - set_f( st->hBWE_TD->fb_state_lpc_syn, 0, LPC_SHB_ORDER ); - st->hBWE_TD->fb_tbe_demph = 0; #ifdef IVAS_FLOAT_FIXED + set16_fx( st->hBWE_TD->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER ); + st->hBWE_TD->fb_tbe_demph_fx = 0; + move16(); fb_tbe_reset_enc_fx( st->hBWE_TD->elliptic_bpf_2_48k_mem_fx, &st->hBWE_TD->prev_fb_energy_fx, st->hBWE_TD->elliptic_bpf_2_48k_mem_fx_Q, &st->hBWE_TD->prev_fb_energy_fx_Q ); #else + set_f( st->hBWE_TD->fb_state_lpc_syn, 0, LPC_SHB_ORDER ); + st->hBWE_TD->fb_tbe_demph = 0; fb_tbe_reset_enc( st->hBWE_TD->elliptic_bpf_2_48k_mem, &st->hBWE_TD->prev_fb_energy ); #endif } diff --git a/lib_enc/init_enc.c b/lib_enc/init_enc.c index 355aab8d2..c754fe4bb 100644 --- a/lib_enc/init_enc.c +++ b/lib_enc/init_enc.c @@ -827,9 +827,13 @@ ivas_error init_encoder( InitSWBencBuffer( st->hBWE_TD ); #ifdef IVAS_FLOAT_FIXED - InitSWBencBuffer_fx( st ); + InitSWBencBuffer_ivas_fx( st ); #endif +#ifndef IVAS_FLOAT_FIXED ResetSHBbuffer_Enc( st->hBWE_TD ); +#else + ResetSHBbuffer_Enc_fx( st ); +#endif } else { @@ -1991,11 +1995,10 @@ ivas_error init_encoder_ivas_fx( return error; } - InitSWBencBuffer_fx( st ); + InitSWBencBuffer_ivas_fx( st ); ResetSHBbuffer_Enc_fx( st ); #if 1 InitSWBencBuffer( st->hBWE_TD ); - ResetSHBbuffer_Enc( st->hBWE_TD ); #endif } ELSE diff --git a/lib_enc/ivas_core_enc.c b/lib_enc/ivas_core_enc.c index d5939811b..a80c36ad4 100644 --- a/lib_enc/ivas_core_enc.c +++ b/lib_enc/ivas_core_enc.c @@ -905,7 +905,7 @@ ivas_error ivas_core_enc( } fixedToFloat_arr( new_swb_speech_fx_16, new_swb_speech, 0, L_FRAME48k ); - fixedToFloat_arr( shb_speech_fx, shb_speech, 0, L_FRAME16k ); + fixedToFloat_arr( shb_speech_fx, shb_speech, Q_shb_spch, L_FRAME16k ); fixedToFloat_arrL32( (Word32 *) &realBuffer_fx[0][0], (float *) &realBuffer[n][0][0], q_realImagBuffer, CLDFB_NO_COL_MAX * CLDFB_NO_CHANNELS_MAX ); fixedToFloat_arrL32( (Word32 *) &imagBuffer_fx[0][0], (float *) &imagBuffer[n][0][0], q_realImagBuffer, CLDFB_NO_COL_MAX * CLDFB_NO_CHANNELS_MAX ); @@ -930,9 +930,12 @@ ivas_error ivas_core_enc( if ( st->hBWE_TD != NULL ) { #ifdef IVAS_FLOAT_FIXED +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + floatToFixed_arr( shb_speech, shb_speech_fx, Q_shb_spch, L_FRAME16k ); +#endif InitSWBencBufferStates_fx( st->hBWE_TD, shb_speech_fx ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - InitSWBencBufferStates( st->hBWE_TD, shb_speech ); + fixedToFloat_arr( shb_speech_fx, shb_speech, Q_shb_spch, L_FRAME16k ); #endif #else InitSWBencBufferStates( st->hBWE_TD, shb_speech ); @@ -997,15 +1000,11 @@ ivas_error ivas_core_enc( // Q_input is being calculated inside already Word16 Q_input = 0; floatToFixed_arr( st->input_buff, st->input_buff_fx, Q_input, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ); - Word16 len_old_input_fhb_fx = NS2SA( 48000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ) - L_FRAME48k / 2; - st->hBWE_TD->old_input_fhb_fx_Q = Q_factor_arr( st->hBWE_TD->old_input_fhb, len_old_input_fhb_fx ); - floatToFixed_arr( st->hBWE_TD->old_input_fhb, st->hBWE_TD->old_input_fhb_fx, st->hBWE_TD->old_input_fhb_fx_Q, len_old_input_fhb_fx ); #endif fb_tbe_enc_ivas_fx( st, st->input_fx, fb_exc_fx, Q_fb_exc ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS fixedToFloat_arr( fb_exc_fx, fb_exc, Q_fb_exc, L_FRAME16k ); fixedToFloat_arr( st->input_fx, st->input, Q_input, L_FRAME48k ); - fixedToFloat_arr( st->hBWE_TD->old_input_fhb_fx, st->hBWE_TD->old_input_fhb, st->hBWE_TD->old_input_fhb_fx_Q, len_old_input_fhb_fx ); #endif #endif } diff --git a/lib_enc/ivas_core_pre_proc.c b/lib_enc/ivas_core_pre_proc.c index ecb5d2ecd..bef00f87a 100644 --- a/lib_enc/ivas_core_pre_proc.c +++ b/lib_enc/ivas_core_pre_proc.c @@ -1165,6 +1165,7 @@ ivas_error ivas_compute_core_buffers( floatToFixed_arr16( new_inp_resamp16k, new_inp_resamp16k_fx, Q_old_inp_16k, L_FRAME16k ); #endif + f2me_buf_16( st->old_inp_12k8, st->old_inp_12k8_fx, &st->exp_old_inp_12k8, 240 ); floatToFixed_arr16( st->old_inp_16k, st->old_inp_16k_fx, Q_old_inp_16k, L_INP_MEM ); floatToFixed_arr16( st->mem_decim16k, st->mem_decim16k_fx, Q_old_inp_16k, 2 * L_FILT_MAX ); floatToFixed_arr16( st->inp_16k_mem_stereo_sw, st->inp_16k_mem_stereo_sw_fx, Q_old_inp_16k, STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k ); diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index 9fc3a0de5..7d841a9a0 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -5150,9 +5150,9 @@ static void average_masa_metadata_fx( FOR( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ ) { - azi_rad_fx = extract_l( Mpy_32_32( hMeta->directional_meta[i].azimuth_fx[j][k], 2670177 /*1/(2*pi) in Q24*/ ) ); /*=angle *(1/2pi) brings the azi_rad_fx in -32767 to 32767 in q15 (this argument is further passed in cos and sin functions)*/ /*22+24-31=15*/ - ele_rad_fx = extract_l( Mpy_32_32( hMeta->directional_meta[i].elevation_fx[j][k], 2670177 /*1/(2*pi) in Q24*/ ) ); /*=angle *(1/2pi) brings the azi_rad_fx in -32767 to 32767 in q15 (this argument is further passed in cos and sin functions)*/ /*22+24-31=15*/ - vec_len_fx = extract_l( Mpy_32_32( hMeta->directional_meta[i].energy_ratio_fx[j][k] /*q30*/, energy[j][k] ) ); /*exponent=energy_e+1*/ + azi_rad_fx = extract_l( Mpy_32_32( hMeta->directional_meta[i].azimuth_fx[j][k], 46603 /*1/(360) in Q24*/ ) ); /*=angle *(1/2pi) brings the azi_rad_fx in -32767 to 32767 in q15 (this argument is further passed in cos and sin functions)*/ /*22+24-31=15*/ + ele_rad_fx = extract_l( Mpy_32_32( hMeta->directional_meta[i].elevation_fx[j][k], 46603 /*1/(360) in Q24*/ ) ); /*=angle *(1/2pi) brings the azi_rad_fx in -32767 to 32767 in q15 (this argument is further passed in cos and sin functions)*/ /*22+24-31=15*/ + vec_len_fx = Mpy_32_32( hMeta->directional_meta[i].energy_ratio_fx[j][k] /*q30*/, energy[j][k] ); /*exponent=energy_e+1*/ vec_len_e = add( energy_e[j][k], 1 ); /* energy-weighted sum over subframes */ diff --git a/lib_enc/ivas_spar_encoder.c b/lib_enc/ivas_spar_encoder.c index 2d83970c6..6339bc639 100644 --- a/lib_enc/ivas_spar_encoder.c +++ b/lib_enc/ivas_spar_encoder.c @@ -1002,12 +1002,13 @@ static ivas_error ivas_spar_enc_process_fx( { p_pcm_tmp_fx[i] = pcm_tmp_fx[i]; } - /* Need to remove flt to fix conversions */ + + /* run Filter Bank overlapping MDFT analysis first, then we can use the temporary buffer for Parameter MDFT analysis*/ ivas_fb_mixer_pcm_ingest_fx( hSpar->hFbMixer, data_fx, p_pcm_tmp_fx, input_frame, hSpar->hMdEnc->HOA_md_ind, q_data, q_p_pcm_tmp_fx ); FOR( i = 0; i < hSpar->hFbMixer->fb_cfg->num_in_chans; i++ ) { /* changing q format to q_data*/ - scale_sig32( p_pcm_tmp_fx[i], input_frame, sub( q_data, q_p_pcm_tmp_fx[i] ) ); + scale_sig32( p_pcm_tmp_fx[i], shl( input_frame, 1 ), sub( q_data, q_p_pcm_tmp_fx[i] ) ); } /* prepare Parameter MDFT analysis */ @@ -1032,6 +1033,8 @@ static ivas_error ivas_spar_enc_process_fx( p_pcm_tmp_fx[i] += l_ts; ppIn_FR_real_fx[i] += l_ts; ppIn_FR_imag_fx[i] += l_ts; + q_p_pcm_tmp_fx[i] = sub( q_data, gb ); // updating the q for p_pcm + move16(); } } @@ -1111,6 +1114,7 @@ static ivas_error ivas_spar_enc_process_fx( return error; } + set16_fx( q_p_pcm_tmp_fx, pp_fr_q, nchan_fb_in ); /*-----------------------------------------------------------------------------------------* * FB mixer *-----------------------------------------------------------------------------------------*/ diff --git a/lib_enc/ivas_stereo_switching_enc.c b/lib_enc/ivas_stereo_switching_enc.c index 3a3c6c0bb..cf683d621 100644 --- a/lib_enc/ivas_stereo_switching_enc.c +++ b/lib_enc/ivas_stereo_switching_enc.c @@ -524,8 +524,8 @@ ivas_error stereo_memory_enc_fx( } InitSWBencBuffer( st->hBWE_TD ); - InitSWBencBuffer_fx( st ); - ResetSHBbuffer_Enc( st->hBWE_TD ); + InitSWBencBuffer_ivas_fx( st ); + ResetSHBbuffer_Enc_fx( st ); IF( ( st->hBWE_FD = (FD_BWE_ENC_HANDLE) malloc( sizeof( FD_BWE_ENC_DATA ) ) ) == NULL ) { diff --git a/lib_enc/ivas_stereo_td_enc.c b/lib_enc/ivas_stereo_td_enc.c index 01737ac5b..b0e3355c8 100644 --- a/lib_enc/ivas_stereo_td_enc.c +++ b/lib_enc/ivas_stereo_td_enc.c @@ -421,12 +421,9 @@ ivas_error stereo_set_tdm_fx( InitSWBencBuffer( st->hBWE_TD ); #ifdef IVAS_FLOAT_FIXED - InitSWBencBuffer_fx( st ); + InitSWBencBuffer_ivas_fx( st ); #endif - ResetSHBbuffer_Enc( st->hBWE_TD ); -#ifdef IVAS_FLOAT_FIXED ResetSHBbuffer_Enc_fx( st ); -#endif IF( ( st->hBWE_FD = (FD_BWE_ENC_HANDLE) malloc( sizeof( FD_BWE_ENC_DATA ) ) ) == NULL ) { diff --git a/lib_enc/ivas_tcx_core_enc.c b/lib_enc/ivas_tcx_core_enc.c index d007e50a5..cea581a94 100644 --- a/lib_enc/ivas_tcx_core_enc.c +++ b/lib_enc/ivas_tcx_core_enc.c @@ -2075,6 +2075,11 @@ Word16 ivas_acelp_tcx20_switching_fx( move32(); } + Word32 mean_voicing_fr = L_mult0( voicing_fr_local[0], /* 1/4 in Q15 */ 8192 ); // Q30 + mean_voicing_fr = L_mac0( mean_voicing_fr, voicing_fr_local[1], /* 1/4 in Q15 */ 8192 ); // Q30 + mean_voicing_fr = L_mac0( mean_voicing_fr, voicing_fr_local[2], /* 1/4 in Q15 */ 8192 ); // Q30 + mean_voicing_fr = L_mac0( mean_voicing_fr, voicing_fr_local[3], /* 1/4 in Q15 */ 8192 ); // Q30 + test(); test(); test(); @@ -2085,7 +2090,7 @@ Word16 ivas_acelp_tcx20_switching_fx( test(); test(); test(); - if ( ( !flag_16k_smc ) && ( LT_32( offset_tcx, 0x18950F ) ) && GT_16( non_staX, 1280 /*5.0f Q8*/ ) && ( GE_32( snr_acelp, L_sub( tcx_snr, 262144 /*4.0f in Q16*/ ) ) ) && GE_16( st->Nb_ACELP_frames, 1 ) && ( ( GT_16( st->hSpMusClas->lps_fx, st->hSpMusClas->lpm_fx ) && GE_16( shr( sum16_fx( voicing_fr_local, 4 ), 2 ), 9830 ) ) || ( GE_16( st->Nb_ACELP_frames, 6 ) && GT_16( st->hSpMusClas->lps_fx, sub( st->hSpMusClas->lpm_fx, 192 /*1.5in Q7*/ ) ) ) ) && ( st->sp_aud_decision0 == 0 ) && st->vad_flag ) + if ( ( !flag_16k_smc ) && ( LT_32( offset_tcx, 0x18950F ) ) && GT_16( non_staX, 1280 /*5.0f Q8*/ ) && ( GE_32( snr_acelp, L_sub( tcx_snr, 262144 /*4.0f in Q16*/ ) ) ) && GE_16( st->Nb_ACELP_frames, 1 ) && ( ( GT_16( st->hSpMusClas->lps_fx, st->hSpMusClas->lpm_fx ) && GE_32( mean_voicing_fr, /* 0.3 in Q30 */ 322122547 ) ) || ( GE_16( st->Nb_ACELP_frames, 6 ) && GT_16( st->hSpMusClas->lps_fx, sub( st->hSpMusClas->lpm_fx, 192 /*1.5in Q7*/ ) ) ) ) && ( st->sp_aud_decision0 == 0 ) && st->vad_flag ) { /* Fine tuned across various databases based on various metrics to detect TCX frames in speech.*/ dsnr = 262144; /*4.0f Q16*/ diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index c126c56e9..8b2669996 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -3993,6 +3993,10 @@ void InitSWBencBuffer_fx( Encoder_State *st_fx /* i/o: SHB encoder structure */ ); +void InitSWBencBuffer_ivas_fx( + Encoder_State *st_fx /* i/o: SHB encoder structure */ +); + void ResetSHBbuffer_Enc_fx( Encoder_State *st_fx /* i/o: SHB encoder structure */ ); diff --git a/lib_enc/stat_enc.h b/lib_enc/stat_enc.h index c3573d64a..8f0dd5c8a 100644 --- a/lib_enc/stat_enc.h +++ b/lib_enc/stat_enc.h @@ -1403,19 +1403,15 @@ typedef struct td_bwe_enc_structure #ifndef IVAS_FLOAT_FIXED float old_speech_shb[L_LOOK_16k + L_SUBFR16k]; /* Buffer memories */ float old_speech_wb[( L_LOOK_12k8 + L_SUBFR ) * 5 / 16]; /* Buffer memories */ -#else - Word16 old_speech_shb_fx[L_LOOK_16k + L_SUBFR16k]; /* Buffer memories Q(Q_shb_spch) */ - Word16 old_speech_wb_fx[( L_LOOK_12k8 + L_SUBFR ) * 5 / 16]; /* Buffer memories Q(-1) */ -#endif float old_input_fhb[NS2SA( 48000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ) - L_FRAME48k / 2]; - Word16 old_input_fhb_fx[NS2SA( 48000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ) - L_FRAME48k / 2]; - Word16 old_input_fhb_fx_Q; - -#ifndef IVAS_FLOAT_FIXED float prev_lsp_shb[LPC_SHB_ORDER]; float state_ana_filt_shb[2 * ALLPASSSECTIONS_STEEP + 1]; /* states for the analysis filters */ float cldfbHBLT_flt; #else + Word16 old_speech_shb_fx[L_LOOK_16k + L_SUBFR16k]; /* Buffer memories Q(Q_shb_spch) */ + Word16 old_speech_wb_fx[( L_LOOK_12k8 + L_SUBFR ) * 5 / 16]; /* Buffer memories Q(-1) */ + Word16 old_input_fhb_fx[NS2SA( 48000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ) - L_FRAME48k / 2]; /* Q(old_input_fhb_fx_Q) */ + Word16 old_input_fhb_fx_Q; Word16 prev_lsp_shb_fx[LPC_SHB_ORDER]; /* Q15 */ Word16 state_ana_filt_shb_fx[( 2 * ALLPASSSECTIONS_STEEP + 1 )]; /* states for the analysis filters */ Word16 cldfbHBLT; /* Q13 */ @@ -1423,34 +1419,27 @@ typedef struct td_bwe_enc_structure /* states for the filters used in generating SHB excitation from WB excitation*/ #ifndef IVAS_FLOAT_FIXED float mem_csfilt[2]; + float mem_shb_res[MAX_LEN_MA_FILTER]; /* old SHB residual signal */ + float old_EnvSHBres[L_FRAME4k]; /* old TD envelope of the SHB residual signal */ + float old_mean_EnvSHBres; /* energy of the last subframe of the SHB residual signal from previous frame */ + float prev_enr_EnvSHBres; /* energy of the residual SHB envelope from the previous frame */ + float prev_shb_env_tilt; /* tilt of the residual SHB envelope from the previous frame */ + float prev_pow_exc16kWhtnd; /* power of the LB excitation signal in the previous frame */ + float prev_mix_factor; /* mixing factor in the previous frame */ + float prev_Env_error; /* error in SHB envelope modelling */ #else Word32 mem_csfilt_fx[2]; /* Q(prev_Q_bwe_exc) */ -#endif - float mem_shb_res[MAX_LEN_MA_FILTER]; /* old SHB residual signal */ - Word16 mem_shb_res_fx[MAX_LEN_MA_FILTER]; /* old SHB residual signal */ - Word32 mem_shb_res_32_fx[MAX_LEN_MA_FILTER]; /* old SHB residual signal */ - float old_EnvSHBres[L_FRAME4k]; /* old TD envelope of the SHB residual signal */ - Word16 old_EnvSHBres_fx[L_FRAME4k]; /* old TD envelope of the SHB residual signal */ -#ifndef IVAS_FLOAT_FIXED - float old_mean_EnvSHBres; /* energy of the last subframe of the SHB residual signal from previous frame */ - float prev_enr_EnvSHBres; /* energy of the residual SHB envelope from the previous frame */ - float prev_shb_env_tilt; /* tilt of the residual SHB envelope from the previous frame */ - float prev_pow_exc16kWhtnd; /* power of the LB excitation signal in the previous frame */ -#else + Word16 mem_shb_res_fx[MAX_LEN_MA_FILTER]; /* old SHB residual signal Q(prev_Q_shb) */ + Word16 old_EnvSHBres_fx[L_FRAME4k]; /* old TD envelope of the SHB residual signal Q(prev_Q_shb) */ Word16 old_mean_EnvSHBres_fx; /* energy of the last subframe of the SHB residual signal from previous frame Q15 */ Word32 prev_enr_EnvSHBres_fx; /* energy of the residual SHB envelope from the previous frame Q(31 - prev_enr_EnvSHBres_e) */ Word16 prev_enr_EnvSHBres_e; - Word16 prev_shb_env_tilt_fx; /* tilt of the residual SHB envelope from the previous frame Q(prev_shb_env_tilt_q) */ - Word16 prev_shb_env_tilt_q; + Word16 prev_shb_env_tilt_fx; /* tilt of the residual SHB envelope from the previous frame Q(prev_Q_shb) */ + Word16 prev_Q_shb; #if 0 Word16 prev_pow_exc16kWhtnd_fx; /* power of the LB excitation signal in the previous frame */ #endif Word32 prev_pow_exc16kWhtnd_fx32; /* Use this power of the LB excitation signal in the previous frame Q0 */ -#endif -#ifndef IVAS_FLOAT_FIXED - float prev_mix_factor; /* mixing factor in the previous frame */ - float prev_Env_error; /* error in SHB envelope modelling */ -#else Word16 prev_mix_factor_fx; /* mixing factor in the previous frame Q15 */ Word16 prev_Env_error_fx; /* error in SHB envelope modelling Q0 */ #endif @@ -1512,19 +1501,16 @@ typedef struct td_bwe_enc_structure #ifndef IVAS_FLOAT_FIXED float prev_wb_GainShape_flt; float swb_lsp_prev_interp[LPC_SHB_ORDER]; + float fb_state_lpc_syn[LPC_SHB_ORDER]; + float fb_tbe_demph; + float tilt_mem; #else Word16 prev_wb_GainShape; /* Q15 */ Word16 swb_lsp_prev_interp_fx[LPC_SHB_ORDER]; /* Q15 */ -#endif - float fb_state_lpc_syn[LPC_SHB_ORDER]; - float fb_tbe_demph; Word16 fb_state_lpc_syn_fx[LPC_SHB_ORDER]; Word16 prev_Q_bwe_exc_fb; Word16 fb_tbe_demph_fx; -#ifndef IVAS_FLOAT_FIXED - float tilt_mem; -#else - Word16 tilt_mem_fx; /* Q12 */ + Word16 tilt_mem_fx; /* Q12 */ #endif int16_t prev_coder_type; @@ -1532,8 +1518,8 @@ typedef struct td_bwe_enc_structure float prev_lsf_diff[LPC_SHB_ORDER - 2]; float prev_tilt_para; #else - Word16 prev_lsf_diff_fx[LPC_SHB_ORDER - 2]; /* Q15 */ - Word16 prev_tilt_para_fx; /* Q10 */ + Word16 prev_lsf_diff_fx[LPC_SHB_ORDER - 2]; /* Q15 */ + Word16 prev_tilt_para_fx; /* Q10 */ #endif float cur_sub_Aq[M + 1]; Word16 cur_sub_Aq_fx[M + 1]; /* Q12 */ diff --git a/lib_enc/swb_bwe_enc_fx.c b/lib_enc/swb_bwe_enc_fx.c index f76a740b9..91ffef59d 100644 --- a/lib_enc/swb_bwe_enc_fx.c +++ b/lib_enc/swb_bwe_enc_fx.c @@ -40,7 +40,7 @@ static Word16 SWB_BWE_encoding_ivas_fx( const Word16 *insig_lp_fx, /* i : delayed original lowband input signal at 32kHz */ const Word16 *insig_hp_fx, /* i : delayed original highband input signal at 32kHz */ const Word16 *synth_fx, /* i : delayed ACELP core synthesis at 12.8kHz */ - const Word16 *yos_fx, /* i : MDCT coefficients of the windowed original input signal at 32kHz */ + const Word32 *yos_fx, /* i : MDCT coefficients of the windowed original input signal at 32kHz */ Word16 *SWB_fenv_fx, /* o : frequency-domain quantized BWE envelope */ const Word16 tilt_nb_fx, /* i : SWB tilt */ const Word16 st_offset, /* i : start frequency offset for BWE envelope */ @@ -324,6 +324,7 @@ void swb_bwe_enc_ivas_fx( move32(); #endif Word16 fb_band_begin; + Word16 sf; FD_BWE_ENC_HANDLE hBWE_FD = st_fx->hBWE_FD; TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; @@ -437,8 +438,9 @@ void swb_bwe_enc_ivas_fx( inner_frame ); /* Scaling has been added to avoid the yorig_32 buffer becoming zero inside direct_transform_fx */ - Scale_sig32( L_old_input_fx, inner_frame, Q5 ); - new_input_fx_exp = add( new_input_fx_exp, 5 ); + sf = L_norm_arr( L_old_input_fx, inner_frame ); + scale_sig32( L_old_input_fx, inner_frame, sf ); + new_input_fx_exp = add( new_input_fx_exp, sf ); // It is Q, not exp /* DCT of the ACELP core synthesis */ direct_transform_fx( L_old_input_fx, yorig_32, 0, inner_frame, &new_input_fx_exp, st_fx->element_mode ); @@ -572,13 +574,13 @@ void swb_bwe_enc_ivas_fx( /* SWB BWE encoding */ IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) { - SWB_BWE_encoding_ivas_fx( st_fx, old_input_fx, old_input_lp_fx, new_input_hp_fx, old_syn_12k8_16k_fx, yorig_fx, - SWB_fenv_fx, tilt_nb_fx, 80, Q_slb_speech, Q_shb, Q_synth_hf, Q_synth ); + SWB_BWE_encoding_ivas_fx( st_fx, old_input_fx, old_input_lp_fx, new_input_hp_fx, old_syn_12k8_16k_fx, yorig_32, + SWB_fenv_fx, tilt_nb_fx, 80, Q_slb_speech, Q_shb, new_input_fx_exp, Q_synth ); } ELSE { - SWB_BWE_encoding_ivas_fx( st_fx, old_input_fx, old_input_lp_fx, new_input_hp_fx, old_syn_12k8_16k_fx, yorig_fx, - SWB_fenv_fx, tilt_nb_fx, 6, Q_slb_speech, Q_shb, Q_synth_hf, Q_synth ); + SWB_BWE_encoding_ivas_fx( st_fx, old_input_fx, old_input_lp_fx, new_input_hp_fx, old_syn_12k8_16k_fx, yorig_32, + SWB_fenv_fx, tilt_nb_fx, 6, Q_slb_speech, Q_shb, new_input_fx_exp, Q_synth ); } @@ -2054,7 +2056,7 @@ static void calculate_Tonality_fx( { max = gen_spec[n_coeff];move16(); }*/ - max = s_max( max, org_spec[n_coeff] ); + max = s_max( max, gen_spec[n_coeff] ); } l_shift = norm_s( max ); FOR( n_coeff = 0; n_coeff < length; n_coeff++ ) @@ -2974,7 +2976,7 @@ static Word16 SWB_BWE_encoding_ivas_fx( const Word16 *insig_lp_fx, /* i : delayed original lowband input signal at 32kHz */ const Word16 *insig_hp_fx, /* i : delayed original highband input signal at 32kHz */ const Word16 *synth_fx, /* i : delayed ACELP core synthesis at 12.8kHz */ - const Word16 *yos_fx, /* i : MDCT coefficients of the windowed original input signal at 32kHz */ + const Word32 *yos_fx, /* i : MDCT coefficients of the windowed original input signal at 32kHz */ Word16 *SWB_fenv_fx, /* o : frequency-domain quantized BWE envelope */ const Word16 tilt_nb_fx, /* i : SWB tilt */ const Word16 st_offset, /* i : start frequency offset for BWE envelope */ @@ -2991,10 +2993,13 @@ static Word16 SWB_BWE_encoding_ivas_fx( Word16 tmp; Word32 energy_fx; + Word64 energy_fx_64; Word16 tilt_fx; Word32 global_gain_fx; Word32 L_tmp; + Word64 W_tmp; Word32 L_SWB_fenv_fx[SWB_FENV]; + Word16 q_SWB_fenv[SWB_FENV]; Word16 SWB_tenv_fx[SWB_TENV]; Word32 L_SWB_tenv, WB_tenv_syn_fx, WB_tenv_orig_fx; Word16 exp, expn, expd; @@ -3008,6 +3013,10 @@ static Word16 SWB_BWE_encoding_ivas_fx( Flag Overflow = 0; move32(); #endif + Word16 inner_frame; + Word16 q_shift; + Word16 yos_fx_16[L_FRAME_MAX]; + Word16 sf; FD_BWE_ENC_HANDLE hBWE_FD = st_fx->hBWE_FD; BSTR_ENC_HANDLE hBstr = st_fx->hBstr; @@ -3023,6 +3032,17 @@ static Word16 SWB_BWE_encoding_ivas_fx( move16(); } + IF( EQ_16( st_fx->extl, FB_BWE ) ) + { + inner_frame = L_FRAME48k; + move16(); + } + ELSE + { + inner_frame = L_FRAME32k; + move16(); + } + /* HF transient detect */ IsTransient = detect_transient_fx( insig_hp_fx, L_FRAME16k, Q_shb, st_fx ); st_fx->EnergyLT_fx_exp = shl( Q_shb, 1 ); @@ -3076,15 +3096,29 @@ static Word16 SWB_BWE_encoding_ivas_fx( global_gain_fx = L_deposit_l( 0 ); FOR( n_band = 0; n_band < SWB_FENV_TRANS; n_band++ ) { - energy_fx = L_deposit_l( 0 ); + energy_fx_64 = W_deposit32_l( 0 ); FOR( n_coeff = swb_bwe_trans_subband[n_band] + st_offset; n_coeff < swb_bwe_trans_subband[n_band + 1] + st_offset; n_coeff++ ) { - L_tmp = L_shr( L_mult0( yos_fx[n_coeff], yos_fx[n_coeff] ), 7 ); /*2*Q_synth-7 */ - energy_fx = L_add( L_tmp, energy_fx ); /*2*Q_synth-7 */ + W_tmp = W_mult0_32_32( yos_fx[n_coeff], yos_fx[n_coeff] ); /*2*Q_synth */ + energy_fx_64 = W_add( W_tmp, energy_fx_64 ); /*2*Q_synth */ } - global_gain_fx = L_add( global_gain_fx, L_shr( energy_fx, sub( sub( shl( Q_synth, 1 ), 7 ), shl( Q_shb, 1 ) ) ) ); /*2*Q_shb */ + q_shift = W_norm( energy_fx_64 ); + energy_fx = W_extract_h( W_shl( energy_fx_64, q_shift ) ); /*2*Q_synth + q_shift - 32*/ + q_shift = sub( q_shift, 32 ); + + global_gain_fx = L_add( global_gain_fx, L_shr( energy_fx, sub( add( shl( Q_synth, 1 ), q_shift ), shl( Q_shb, 1 ) ) ) ); /*2*Q_shb */ L_SWB_fenv_fx[n_band] = energy_fx; move32(); + IF( L_SWB_fenv_fx[n_band] == 0 ) + { + q_SWB_fenv[n_band] = Q31; + move16(); + } + ELSE + { + q_SWB_fenv[n_band] = add( shl( Q_synth, 1 ), q_shift ); + move16(); + } } global_gain_fx = L_shr( global_gain_fx, 1 ); /*2*Q_shb */ @@ -3092,10 +3126,10 @@ static Word16 SWB_BWE_encoding_ivas_fx( { expd = norm_s( swb_bwe_trans_subband_width[n_band] ); tmp = div_s( shl( 1, sub( 14, expd ) ), swb_bwe_trans_subband_width[n_band] ); /*Q(29-expd) */ - L_tmp = Mult_32_16( L_SWB_fenv_fx[n_band], tmp ); /*2*Q_synth-7+29-expd - 15 */ + L_tmp = Mult_32_16( L_SWB_fenv_fx[n_band], tmp ); /*q_SWB_fenv[n_band]+29-expd - 15 */ exp = norm_l( L_tmp ); tmp = Log2_norm_lc( L_shl( L_tmp, exp ) ); - exp = sub( sub( 30, exp ), sub( add( shl( Q_synth, 1 ), 7 ), expd ) ); + exp = sub( sub( 30, exp ), sub( add( q_SWB_fenv[n_band], Q14 ), expd ) ); L_tmp = Mpy_32_16( exp, tmp, 24660 ); /* Q14 */ /*10log10(2) in Q13 */ tmp = round_fx( L_shl( L_tmp, 10 ) ); /* Q8 */ @@ -3371,37 +3405,45 @@ static Word16 SWB_BWE_encoding_ivas_fx( global_gain_fx = L_deposit_l( 0 ); FOR( n_band = 0; n_band < SWB_FENV; n_band++ ) { - energy_fx = L_deposit_l( 0 ); + energy_fx_64 = W_deposit32_l( 0 ); FOR( n_coeff = swb_bwe_subband[n_band] + st_offset; n_coeff < swb_bwe_subband[n_band + 1] + st_offset; n_coeff++ ) { - L_tmp = L_shr( L_mult0( yos_fx[n_coeff], yos_fx[n_coeff] ), 5 ); /*2*Q_synth-5 */ - energy_fx = L_add( L_tmp, energy_fx ); /*2*Q_synth-5 */ + W_tmp = W_mult0_32_32( yos_fx[n_coeff], yos_fx[n_coeff] ); /*2*Q_synth */ + energy_fx_64 = W_add( W_tmp, energy_fx_64 ); /*2*Q_synth */ } + q_shift = W_norm( energy_fx_64 ); + energy_fx = W_extract_h( W_shl( energy_fx_64, q_shift ) ); /*2*Q_synth + q_shift - 32*/ + q_shift = sub( q_shift, 32 ); IF( LT_16( n_band, SWB_FENV - 2 ) ) { - global_gain_fx = L_add( global_gain_fx, L_shr( energy_fx, sub( sub( shl( Q_synth, 1 ), 5 ), shl( Q_shb, 1 ) ) ) ); /*2*Q_shb */ + global_gain_fx = L_add( global_gain_fx, L_shr( energy_fx, sub( add( shl( Q_synth, 1 ), q_shift ), shl( Q_shb, 1 ) ) ) ); /*2*Q_shb */ } L_SWB_fenv_fx[n_band] = energy_fx; move32(); + q_SWB_fenv[n_band] = add( shl( Q_synth, 1 ), q_shift ); + move16(); } global_gain_fx = L_shr( global_gain_fx, 1 ); /*2*Q_shb */ - mode = FD_BWE_class_fx( yos_fx, global_gain_fx, tilt_nb_fx, Q_synth, Q_shb, st_fx ); + + sf = getScaleFactor32( yos_fx, inner_frame ); + Copy_Scale_sig32_16( yos_fx, yos_fx_16, inner_frame, sf ); + mode = FD_BWE_class_fx( yos_fx_16, global_gain_fx, tilt_nb_fx, sub( add( Q_synth, sf ), Q16 ), Q_shb, st_fx ); push_indice( hBstr, IND_SWB_CLASS, mode, 2 ); - energy_control_ivas_fx( st_fx, ACELP_CORE, mode, -1, yos_fx, st_offset, energy_factor_fx, Q_synth_lf ); + energy_control_ivas_fx( st_fx, ACELP_CORE, mode, -1, yos_fx_16, st_offset, energy_factor_fx, sub( add( Q_synth_lf, sf ), Q16 ) ); FOR( n_band = 0; n_band < SWB_FENV; n_band++ ) { - L_tmp = Mult_32_16( L_SWB_fenv_fx[n_band], energy_factor_fx[n_band] ); /*2*Q_synth-5 */ - L_tmp = Mult_32_16( L_tmp, swb_inv_bwe_subband_width_fx[n_band] ); /*2*Q_synth-5 */ + L_tmp = Mult_32_16( L_SWB_fenv_fx[n_band], energy_factor_fx[n_band] ); /*q_SWB_fenv[n_band] */ + L_tmp = Mult_32_16( L_tmp, swb_inv_bwe_subband_width_fx[n_band] ); /*q_SWB_fenv[n_band] */ IF( L_tmp != 0 ) { expn = norm_l( L_tmp ); tmp = Log2_norm_lc( L_shl( L_tmp, expn ) ); - expn = sub( 30, add( expn, sub( shl( Q_synth, 1 ), 5 ) ) ); + expn = sub( 30, add( expn, q_SWB_fenv[n_band] ) ); L_tmp = Mpy_32_16( expn, tmp, 24660 ); /* Q14 */ /*10log10(2) in Q13 */ SWB_fenv_fx[n_band] = round_fx( L_shl( L_tmp, 10 ) ); /* Q8 */ move16(); diff --git a/lib_enc/swb_tbe_enc.c b/lib_enc/swb_tbe_enc.c index 18c519939..e8d285903 100644 --- a/lib_enc/swb_tbe_enc.c +++ b/lib_enc/swb_tbe_enc.c @@ -127,18 +127,15 @@ void InitSWBencBuffer( #ifndef IVAS_FLOAT_FIXED set_f( hBWE_TD->old_speech_shb, 0.0f, L_LOOK_16k + L_SUBFR16k ); set_f( hBWE_TD->old_speech_wb, 0.0f, ( L_LOOK_12k8 + L_SUBFR ) * 5 / 16 ); + set_f( hBWE_TD->old_input_fhb, 0.0f, NS2SA( 48000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ) - L_FRAME48k / 2 ); #else set16_fx( hBWE_TD->old_speech_shb_fx, 0, L_LOOK_16k + L_SUBFR16k ); set16_fx( hBWE_TD->old_speech_wb_fx, 0, ( L_LOOK_12k8 + L_SUBFR ) * 5 / 16 ); + set16_fx( hBWE_TD->old_input_fhb_fx, 0, NS2SA( 48000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ) - L_FRAME48k / 2 ); #endif - set_f( hBWE_TD->old_input_fhb, 0.0f, NS2SA( 48000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ) - L_FRAME48k / 2 ); #ifdef IVAS_FLOAT_FIXED InitSWBencBufferStates_fx( hBWE_TD, NULL ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - /* To be removed */ - InitSWBencBufferStates( hBWE_TD, NULL ); -#endif #else InitSWBencBufferStates( hBWE_TD, NULL ); #endif @@ -176,14 +173,14 @@ void InitSWBencBuffer( hBWE_TD->prev_frGainAtten = 0; #ifndef IVAS_FLOAT_FIXED hBWE_TD->prev_wb_GainShape_flt = 0; -#else - hBWE_TD->prev_wb_GainShape = 0; -#endif set_f( hBWE_TD->fb_state_lpc_syn, 0, LPC_SHB_ORDER ); hBWE_TD->fb_tbe_demph = 0.0f; -#ifndef IVAS_FLOAT_FIXED hBWE_TD->tilt_mem = 0.0f; #else + hBWE_TD->prev_wb_GainShape = 0; + set16_fx( hBWE_TD->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER ); + hBWE_TD->fb_tbe_demph_fx = 0; + move16(); hBWE_TD->tilt_mem_fx = 0; move16(); #endif @@ -230,6 +227,7 @@ void InitSWBencBuffer( } +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * InitSWBencBufferStates() * @@ -246,35 +244,15 @@ void InitSWBencBufferStates( set_f( shb_speech, 0.0f, L_FRAME16k ); } -#ifndef IVAS_FLOAT_FIXED set_f( hBWE_TD->old_speech_shb, 0.0f, L_LOOK_16k + L_SUBFR16k ); -#else - set16_fx( hBWE_TD->old_speech_shb_fx, 0, L_LOOK_16k + L_SUBFR16k ); -#endif set_f( hBWE_TD->mem_shb_res, 0.0f, MAX_LEN_MA_FILTER ); - set16_fx( hBWE_TD->mem_shb_res_fx, 0, MAX_LEN_MA_FILTER ); - set32_fx( hBWE_TD->mem_shb_res_32_fx, 0, MAX_LEN_MA_FILTER ); set_f( hBWE_TD->old_EnvSHBres, 0.0f, L_FRAME4k ); -#ifndef IVAS_FLOAT_FIXED hBWE_TD->old_mean_EnvSHBres = 0.0f; hBWE_TD->prev_enr_EnvSHBres = 1.0f; hBWE_TD->prev_shb_env_tilt = 0.0f; -#else - hBWE_TD->old_mean_EnvSHBres_fx = 0; - hBWE_TD->prev_enr_EnvSHBres_fx = 1; /*1.0f in Q0*/ - hBWE_TD->prev_enr_EnvSHBres_e = 31; - hBWE_TD->prev_shb_env_tilt_fx = 0; - hBWE_TD->prev_shb_env_tilt_q = 15; -#endif -#ifndef IVAS_FLOAT_FIXED hBWE_TD->prev_pow_exc16kWhtnd = 1.0f; hBWE_TD->prev_mix_factor = 1.0f; hBWE_TD->prev_Env_error = 0.0f; -#else - hBWE_TD->prev_pow_exc16kWhtnd_fx32 = 1; - hBWE_TD->prev_mix_factor_fx = 32767; - hBWE_TD->prev_Env_error_fx = 0; -#endif return; } @@ -290,58 +268,32 @@ void ResetSHBbuffer_Enc( ) { /* states for the filters used in generating SHB excitation from WB excitation*/ -#ifndef IVAS_FLOAT_FIXED set_f( hBWE_TD->mem_genSHBexc_filt_down_shb, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); set_f( hBWE_TD->mem_csfilt, 0, 2 ); -#else - set16_fx( hBWE_TD->mem_genSHBexc_filt_down_shb_fx, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); - set32_fx( hBWE_TD->mem_csfilt_fx, 0, 2 ); -#endif /* states for the filters used in generating SHB signal from SHB excitation*/ -#ifndef IVAS_FLOAT_FIXED set_f( hBWE_TD->state_syn_shbexc, 0, L_SHB_LAHEAD ); set_f( hBWE_TD->state_lpc_syn, 0, LPC_SHB_ORDER ); -#else - set16_fx( hBWE_TD->state_syn_shbexc_fx, 0, L_SHB_LAHEAD ); - set16_fx( hBWE_TD->state_lpc_syn_fx, 0, LPC_SHB_ORDER ); -#endif set_f( hBWE_TD->fb_state_lpc_syn, 0, LPC_SHB_ORDER ); hBWE_TD->fb_tbe_demph = 0; /* states for the filters used in generating WB signal from WB excitation*/ -#ifndef IVAS_FLOAT_FIXED set_f( hBWE_TD->decim_state1, 0.0f, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); set_f( hBWE_TD->decim_state2, 0.0f, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); set_f( hBWE_TD->mem_genSHBexc_filt_down_wb2, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); set_f( hBWE_TD->mem_genSHBexc_filt_down_wb3, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); -#else - set16_fx( hBWE_TD->decim_state1_fx, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); - set16_fx( hBWE_TD->decim_state2_fx, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); - set16_fx( hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); - set16_fx( hBWE_TD->mem_genSHBexc_filt_down_wb3_fx, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); -#endif /* overlap buffer used to Adjust SHB Frame Gain */ -#ifndef IVAS_FLOAT_FIXED set_f( hBWE_TD->mem_stp_swb, 0, LPC_SHB_ORDER ); hBWE_TD->gain_prec_swb = 1.0f; set_f( hBWE_TD->syn_overlap, 0, L_SHB_LAHEAD ); hBWE_TD->tbe_demph = 0.0f; hBWE_TD->tbe_premph = 0.0f; -#else - set16_fx( hBWE_TD->mem_stp_swb_fx, 0, LPC_SHB_ORDER ); - hBWE_TD->gain_prec_swb_fx = ONE_IN_Q14; - set16_fx( hBWE_TD->syn_overlap_fx, 0, L_SHB_LAHEAD ); - hBWE_TD->tbe_demph_fx = 0; - hBWE_TD->tbe_premph_fx = 0; -#endif return; } -#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * wb_tbe_enc() * @@ -3041,11 +2993,13 @@ void TBEreset_enc( if ( bwidth == FB ) { - set_f( hBWE_TD->fb_state_lpc_syn, 0, LPC_SHB_ORDER ); - hBWE_TD->fb_tbe_demph = 0; #ifdef IVAS_FLOAT_FIXED + set16_fx( hBWE_TD->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER ); + hBWE_TD->fb_tbe_demph_fx = 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 ); #else + set_f( hBWE_TD->fb_state_lpc_syn, 0, LPC_SHB_ORDER ); + hBWE_TD->fb_tbe_demph = 0; fb_tbe_reset_enc( hBWE_TD->elliptic_bpf_2_48k_mem, &hBWE_TD->prev_fb_energy ); #endif } diff --git a/lib_enc/swb_tbe_enc_fx.c b/lib_enc/swb_tbe_enc_fx.c index 9a219d065..52ac2398d 100644 --- a/lib_enc/swb_tbe_enc_fx.c +++ b/lib_enc/swb_tbe_enc_fx.c @@ -498,6 +498,108 @@ void InitSWBencBuffer_fx( return; } +void InitSWBencBuffer_ivas_fx( + Encoder_State *st_fx /* i/o: SHB encoder structure */ +) +{ + Word16 i; + TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; + + set16_fx( hBWE_TD->old_bwe_exc_fx, 0, ( PIT16k_MAX * 2 ) ); + hBWE_TD->bwe_seed[0] = 23; + move16(); + hBWE_TD->bwe_seed[1] = 59; + move16(); + set16_fx( hBWE_TD->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET ); + hBWE_TD->bwe_non_lin_prev_scale_fx = L_deposit_l( 0 ); + move32(); + + set16_fx( hBWE_TD->state_ana_filt_shb_fx, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); + set32_fx( hBWE_TD->elliptic_bpf_2_48k_mem_fx[0], 0, 4 ); + set32_fx( hBWE_TD->elliptic_bpf_2_48k_mem_fx[1], 0, 4 ); + set32_fx( hBWE_TD->elliptic_bpf_2_48k_mem_fx[2], 0, 4 ); + set32_fx( hBWE_TD->elliptic_bpf_2_48k_mem_fx[3], 0, 4 ); + hBWE_TD->prev_fb_energy_fx = 0; + move16(); + + set16_fx( hBWE_TD->old_speech_shb_fx, 0, L_LOOK_16k + L_SUBFR16k ); + set16_fx( hBWE_TD->old_speech_wb_fx, 0, ( L_LOOK_12k8 + L_SUBFR ) * 5 / 16 ); + set16_fx( hBWE_TD->old_input_fhb_fx, 0, NS2SA( 48000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ) - L_FRAME48k / 2 ); + hBWE_TD->old_input_fhb_fx_Q = 0; + move16(); + + // IVAS_CODE + // set_f(hBWE_TD->mem_shb_res, 0.0f, MAX_LEN_MA_FILTER); + // set_f(hBWE_TD->old_EnvSHBres, 0.0f, L_FRAME4k); + // hBWE_TD->old_mean_EnvSHBres = 0.0f; + // hBWE_TD->prev_enr_EnvSHBres = 1.0f; + // hBWE_TD->prev_shb_env_tilt = 0.0f; + // hBWE_TD->prev_pow_exc16kWhtnd = 1.0f; + // hBWE_TD->prev_mix_factor = 1.0f; + // hBWE_TD->prev_Env_error = 0.0f; + set16_fx( hBWE_TD->prev_lsp_shb_fx, 0, 10 ); + + hBWE_TD->cldfbHBLT = 8192; /* 1.0f Q13 */ + move16(); + hBWE_TD->prev_gainFr_SHB_fx = 0; + move32(); + set16_fx( hBWE_TD->lsp_shb_slow_interpl_fx, 0, LPC_SHB_ORDER ); + set16_fx( hBWE_TD->lsp_shb_fast_interpl_fx, 0, LPC_SHB_ORDER ); + set16_fx( hBWE_TD->shb_inv_filt_mem_fx, 0, LPC_SHB_ORDER ); + set16_fx( hBWE_TD->lsp_shb_spacing_fx, 3277 /* 0.1f in Q15 */, 3 ); + set16_fx( hBWE_TD->elliptic_bpf_2_48k_mem_fx_Q, 0, 4 ); + + hBWE_TD->prev_swb_GainShape_fx = 0; + move16(); + hBWE_TD->prev_frGainAtten = 0; + move16(); + hBWE_TD->prev_wb_GainShape = 0; + move16(); + hBWE_TD->prev_Q_bwe_exc_fb = 51; + move16(); + set16_fx( hBWE_TD->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER ); + hBWE_TD->fb_tbe_demph_fx = 0; + move16(); + hBWE_TD->tilt_mem_fx = 0; + move16(); + + hBWE_TD->prev_coder_type = GENERIC; + move16(); + set16_fx( hBWE_TD->prev_lsf_diff_fx, 16384 /* 0.5f in Q15 */, LPC_SHB_ORDER - 2 ); + hBWE_TD->prev_tilt_para_fx = 0; + move16(); + set16_fx( hBWE_TD->cur_sub_Aq_fx, 0, M + 1 ); + + /* TD BWE post-processing */ + hBWE_TD->ptr_mem_stp_swb_fx = hBWE_TD->mem_stp_swb_fx + LPC_SHB_ORDER - 1; + set16_fx( hBWE_TD->mem_zero_swb_fx, 0, LPC_SHB_ORDER ); + + FOR( i = 0; i < LPC_SHB_ORDER; i++ ) + { + hBWE_TD->swb_lsp_prev_interp_fx[i] = swb_lsp_prev_interp_init[i]; + move16(); + } + + set16_fx( hBWE_TD->dec_2_over_3_mem_fx, 0, 12 ); + set16_fx( hBWE_TD->dec_2_over_3_mem_lp_fx, 0, 6 ); + + + hBWE_TD->prev_fb_energy_fx_Q = 0; + move16(); + + + // TV2TV IVAS_CODE -> To be verify if it has to be moved to hBWE_TD + st_fx->prev_Q_bwe_exc = 31; + move16(); + st_fx->prev_Q_bwe_syn = 31; + move16(); + set16_fx( st_fx->prev_lsp_wb_fx, 0, 6 ); + set16_fx( st_fx->prev_lsp_wb_temp_fx, 0, 6 ); + set16_fx( st_fx->prev_lpc_wb_fx, 0, LPC_SHB_ORDER_WB ); + + return; +} + /*-------------------------------------------------------------------* * ResetSHBbuffer_Enc() * @@ -3275,7 +3377,8 @@ void swb_tbe_enc_ivas_fx( IF( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) { /* calculate the TD envelope of the SHB residual signal */ - find_td_envelope_fx( shb_res_fx, L_FRAME16k, 20, hBWE_TD->mem_shb_res_fx, EnvSHBres_fx ); /* Q_shb */ + Scale_sig( hBWE_TD->mem_shb_res_fx, MAX_LEN_MA_FILTER, sub( hBWE_TD->prev_Q_shb, Q_shb ) ); /* Q(hBWE_TD->prev_Q_shb) -> Q(Q_shb) */ + find_td_envelope_fx( shb_res_fx, L_FRAME16k, 20, hBWE_TD->mem_shb_res_fx, EnvSHBres_fx ); /* Q_shb */ /* downsample the TD envelope by 4 */ FOR( k = 0; k < L_FRAME4k; k++ ) @@ -3353,7 +3456,7 @@ void swb_tbe_enc_ivas_fx( lls_interp_n_fx( seg_mean, 4, &shb_env_tilt_fx, &temp, 0 ); /* copy previous residual envelope to the buffer */ - Copy( hBWE_TD->old_EnvSHBres_fx, buf_EnvSHBres_fx, L_FRAME4k ); // Qs to be handled + Copy_Scale_sig( hBWE_TD->old_EnvSHBres_fx, buf_EnvSHBres_fx, L_FRAME4k, sub( hBWE_TD->prev_Q_shb, Q_shb ) ); /* Q(hBWE_TD->prev_Q_shb) -> Q(Q_shb) */ /* subtract mean value from the normalized SHB residual envelope */ p_buf = &buf_EnvSHBres_fx[L_FRAME4k]; @@ -3365,7 +3468,7 @@ void swb_tbe_enc_ivas_fx( } /* update memory */ - Copy( &buf_EnvSHBres_fx[L_FRAME4k], hBWE_TD->old_EnvSHBres_fx, L_FRAME4k ); // Qs to be handled + Copy( &buf_EnvSHBres_fx[L_FRAME4k], hBWE_TD->old_EnvSHBres_fx, L_FRAME4k ); /* calculate energy normalization factor for the auto-correlation function */ // pow0 = sum2_f( &buf_EnvSHBres[L_FRAME4k], L_FRAME4k ) + 1.0f; @@ -3471,7 +3574,7 @@ void swb_tbe_enc_ivas_fx( hBWE_TD->prev_shb_env_tilt_fx = shb_env_tilt_fx; move16(); - hBWE_TD->prev_shb_env_tilt_q = Q_shb; + hBWE_TD->prev_Q_shb = Q_shb; move16(); } @@ -3813,7 +3916,7 @@ void swb_tbe_enc_ivas_fx( test(); test(); test(); - IF( LT_16( acorr_v2a_fx, 13107 ) /* 0.4f in Q15 */ && GE_16( vf_ind_fx, 5 ) && LT_16( abs_s( GainShape_tilt_fx ), 6554 /* 0.2f in Q15 */ ) && LT_32( L_deposit_l( shb_env_tilt_fx ), L_shl( 500, Q_shb ) ) && LT_32( L_deposit_l( hBWE_TD->prev_shb_env_tilt_fx ), L_shl( 500, hBWE_TD->prev_shb_env_tilt_q ) ) ) + IF( LT_16( acorr_v2a_fx, 13107 ) /* 0.4f in Q15 */ && GE_16( vf_ind_fx, 5 ) && LT_16( abs_s( GainShape_tilt_fx ), 6554 /* 0.2f in Q15 */ ) && LT_32( L_deposit_l( shb_env_tilt_fx ), L_shl( 500, Q_shb ) ) && LT_32( L_deposit_l( hBWE_TD->prev_shb_env_tilt_fx ), L_shl( 500, hBWE_TD->prev_Q_shb ) ) ) { /* stronger smoothing in case of unvoiced SHB residual signal with gaussian excitation */ // feedback = lin_interp(acorr_v2a, 0.4f, 0.0f, 0.0f, 0.95f, 0); @@ -7481,18 +7584,20 @@ void InitSWBencBufferStates_fx( set16_fx( hBWE_TD->mem_shb_res_fx, 0, MAX_LEN_MA_FILTER ); set16_fx( hBWE_TD->old_EnvSHBres_fx, 0, L_FRAME4k ); hBWE_TD->old_mean_EnvSHBres_fx = 0; + move16(); hBWE_TD->prev_enr_EnvSHBres_fx = 1; /*1.0f in Q0*/ + move32(); hBWE_TD->prev_enr_EnvSHBres_e = 31; - hBWE_TD->prev_shb_env_tilt_fx = 0; - hBWE_TD->prev_shb_env_tilt_q = 15; - hBWE_TD->prev_pow_exc16kWhtnd_fx32 = 1; /*1.0f in Q0*/ - hBWE_TD->prev_mix_factor_fx = 32767; /*1.0f in Q15*/ - hBWE_TD->prev_Env_error_fx = 0; - move16(); move16(); + hBWE_TD->prev_shb_env_tilt_fx = 0; move16(); + hBWE_TD->prev_Q_shb = 15; move16(); + hBWE_TD->prev_pow_exc16kWhtnd_fx32 = 1; /*1.0f in Q0*/ + move32(); + hBWE_TD->prev_mix_factor_fx = 32767; /*1.0f in Q15*/ move16(); + hBWE_TD->prev_Env_error_fx = 0; move16(); return; -- GitLab From 59e700e7831c9e502ec764a61c2bf44697ee4cb2 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Wed, 13 Nov 2024 12:07:32 +0530 Subject: [PATCH 2/3] EVS Bitexactness issue fix [x] Bitt exactness afftected with bug fix made for EVS code. Created a copy to address the bug. --- lib_enc/swb_bwe_enc_fx.c | 178 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 175 insertions(+), 3 deletions(-) diff --git a/lib_enc/swb_bwe_enc_fx.c b/lib_enc/swb_bwe_enc_fx.c index 91ffef59d..e4e4cb32d 100644 --- a/lib_enc/swb_bwe_enc_fx.c +++ b/lib_enc/swb_bwe_enc_fx.c @@ -2056,7 +2056,7 @@ static void calculate_Tonality_fx( { max = gen_spec[n_coeff];move16(); }*/ - max = s_max( max, gen_spec[n_coeff] ); + max = s_max( max, org_spec[n_coeff] ); } l_shift = norm_s( max ); FOR( n_coeff = 0; n_coeff < length; n_coeff++ ) @@ -2163,6 +2163,178 @@ static void calculate_Tonality_fx( return; } +#ifdef IVAS_FLOAT_FIXED +/*-------------------------------------------------------------------* + * calculate_Tonality_ivas_fx() + * + * Calculate tonality + *-------------------------------------------------------------------*/ + +static void calculate_Tonality_ivas_fx( + const Word16 *org, /* i : MDCT coefficients of original Q_new*/ + const Word16 *gen, /* i : MDCT coefficients of generated signal Q15*/ + Word16 *SFM_org, /* o : Spectral Flatness results Q12*/ + Word16 *SFM_gen, /* o : Spectral Flatness results Q12*/ + const Word16 length /* i : length for calculating tonality */ +) +{ + Word16 n_coeff; + Word16 inv_len, max; + Word16 exp, e_tmp, f_tmp; + Word32 L_tmp, L_tmp2, L_am_org, L_am_gen, L_tmp1; + Word16 org_spec[80], gen_spec[80]; + Word32 L_log_gm_org, L_log_gm_gen; + Word16 l_shift; +#ifdef BASOP_NOGLOB_DECLARE_LOCAL + Flag Overflow = 0; + move32(); +#endif + + /* to reduce dynamic range of original spectrum */ + max = 0; + move16(); + FOR( n_coeff = 0; n_coeff < length; n_coeff++ ) + { + org_spec[n_coeff] = abs_s( org[n_coeff] ); + move16(); /*Q_new */ + /*test(); */ + /*if( sub(max, org_spec[n_coeff]) < 0) */ + /*{ */ + /* max = org_spec[n_coeff];move16();//Q_new */ + /*} */ + max = s_max( max, org_spec[n_coeff] ); + } + l_shift = norm_s( max ); + FOR( n_coeff = 0; n_coeff < length; n_coeff++ ) + { + org_spec[n_coeff] = shl( org_spec[n_coeff], l_shift ); + move16(); + IF( org_spec[n_coeff] == 0 ) + { + org_spec[n_coeff] = shl( 1, l_shift ); + move16(); + } + } + + max = 0; + move16(); + FOR( n_coeff = 0; n_coeff < length; n_coeff++ ) + { + gen_spec[n_coeff] = abs_s( gen[n_coeff] ); + move16(); /*Q15 */ + /*test(); + if( sub(max,gen_spec[n_coeff]) < 0) + { + max = gen_spec[n_coeff];move16(); + }*/ + max = s_max( max, gen_spec[n_coeff] ); + } + l_shift = norm_s( max ); + FOR( n_coeff = 0; n_coeff < length; n_coeff++ ) + { +#ifdef BASOP_NOGLOB + gen_spec[n_coeff] = shl_sat( gen_spec[n_coeff], l_shift ); +#else + gen_spec[n_coeff] = shl( gen_spec[n_coeff], l_shift ); +#endif + move16(); + IF( gen_spec[n_coeff] == 0 ) + { + gen_spec[n_coeff] = shl( 1, l_shift ); + move16(); + } + } + + exp = norm_s( length ); + inv_len = div_s( shl( 1, exp ), shl( length, exp ) ); /*Q15 */ + + L_am_org = L_deposit_l( 0 ); + L_am_gen = L_deposit_l( 0 ); + L_log_gm_org = 0; + move32(); + L_log_gm_gen = 0; + move32(); + + FOR( n_coeff = 0; n_coeff < length; n_coeff++ ) + { + L_am_org = L_add( L_am_org, L_deposit_l( org_spec[n_coeff] ) ); /*Q10 */ + L_am_gen = L_add( L_am_gen, L_deposit_l( gen_spec[n_coeff] ) ); /*Q10 */ + + IF( org_spec[n_coeff] != 0 ) + { + L_tmp = L_deposit_h( org_spec[n_coeff] ); /*Q26 */ + e_tmp = norm_l( L_tmp ); + f_tmp = Log2_norm_lc( L_shl( L_tmp, e_tmp ) ); + e_tmp = sub( sub( 30, e_tmp ), 26 ); + L_tmp = Mpy_32_16( e_tmp, f_tmp, 24660 ); /* Q14 */ /*10log10(2) in Q13 */ + L_log_gm_org = L_add( L_log_gm_org, L_tmp ); /*Q14 */ + } + + IF( gen_spec[n_coeff] != 0 ) + { + L_tmp = L_deposit_h( gen_spec[n_coeff] ); /*Q26 */ + e_tmp = norm_l( L_tmp ); + f_tmp = Log2_norm_lc( L_shl( L_tmp, e_tmp ) ); + e_tmp = sub( sub( 30, e_tmp ), 26 ); + L_tmp = Mpy_32_16( e_tmp, f_tmp, 24660 ); /* Q14 */ /*10log10(2) in Q13 */ + L_log_gm_gen = L_add( L_log_gm_gen, L_tmp ); /*Q14 */ + } + } + + IF( L_am_org != 0 ) + { + L_tmp = Mpy_32_16_1( L_am_org, inv_len ); /*Q10 */ + e_tmp = norm_l( L_tmp ); + f_tmp = Log2_norm_lc( L_shl( L_tmp, e_tmp ) ); + e_tmp = sub( sub( 30, e_tmp ), 10 ); + L_tmp1 = Mpy_32_16( e_tmp, f_tmp, 24660 ); /* Q14 */ /*10log10(2) in Q13 */ + } + ELSE + { + L_tmp1 = L_deposit_l( 0 ); + } + + L_tmp2 = Mpy_32_16_1( L_log_gm_org, inv_len ); /* Q14 */ + + L_tmp = L_sub( L_tmp1, L_tmp2 ); +#ifdef BASOP_NOGLOB + *SFM_org = round_fx_o( L_shl_o( L_tmp, 14, &Overflow ), &Overflow ); /*Q12 */ +#else + *SFM_org = round_fx( L_shl( L_tmp, 14 ) ); /*Q12 */ +#endif + move16(); + *SFM_org = s_max( 0, s_min( *SFM_org, 24547 ) ); + move16(); /*0.0001 and 5.993 in Q12 */ + + IF( L_am_gen != 0 ) + { + L_tmp = Mpy_32_16_1( L_am_gen, inv_len ); /*Q10 */ + e_tmp = norm_l( L_tmp ); + f_tmp = Log2_norm_lc( L_shl( L_tmp, e_tmp ) ); + e_tmp = sub( sub( 30, e_tmp ), 10 ); + L_tmp1 = Mpy_32_16( e_tmp, f_tmp, 24660 ); /* Q14 */ /*10log10(2) in Q13 */ + } + ELSE + { + L_tmp1 = L_deposit_l( 0 ); + } + + L_tmp2 = Mpy_32_16_1( L_log_gm_gen, inv_len ); /* Q14 */ + + L_tmp = L_sub( L_tmp1, L_tmp2 ); +#ifdef BASOP_NOGLOB + *SFM_gen = round_fx_o( L_shl_o( L_tmp, 14, &Overflow ), &Overflow ); /*Q12 */ +#else + *SFM_gen = round_fx( L_shl( L_tmp, 14 ) ); /*Q12 */ +#endif + move16(); + *SFM_gen = s_max( 0, s_min( *SFM_gen, 24547 ) ); + move16(); /*0.0001 and 5.993 in Q12 */ + + return; +} +#endif + /*-------------------------------------------------------------------* * energy_control_fx() * @@ -2333,8 +2505,8 @@ static void energy_control_ivas_fx( FOR( n_band = 0; n_band < max_band; ) { - calculate_Tonality_fx( org_fx + swb_bwe_subband[n_band] + offset, SWB_signal_fx + swb_bwe_subband[n_band] + offset, - &SFM_org_fx[n_band], &SFM_gen_fx[n_band], swb_bwe_subband[n_band + band_step] - swb_bwe_subband[n_band] ); + calculate_Tonality_ivas_fx( org_fx + swb_bwe_subband[n_band] + offset, SWB_signal_fx + swb_bwe_subband[n_band] + offset, + &SFM_org_fx[n_band], &SFM_gen_fx[n_band], swb_bwe_subband[n_band + band_step] - swb_bwe_subband[n_band] ); IF( LT_16( SFM_gen_fx[n_band], mult_r( 24576, SFM_org_fx[n_band] ) ) ) { -- GitLab From 99a8a25b9a06d9e37276220bae95b14700487992 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Wed, 13 Nov 2024 13:00:46 +0530 Subject: [PATCH 3/3] EVS bit exactness issue fix --- lib_dec/core_dec_init_fx.c | 2 +- lib_dec/tonalMDCTconcealment_fx.c | 17 ++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/lib_dec/core_dec_init_fx.c b/lib_dec/core_dec_init_fx.c index 537b586f3..b723bea2c 100644 --- a/lib_dec/core_dec_init_fx.c +++ b/lib_dec/core_dec_init_fx.c @@ -1057,7 +1057,7 @@ void open_decoder_LPD_fx( st->tonalMDCTconceal.lastBlockData.nSamples = 0; move16(); - TonalMDCTConceal_Init_ivas_fx( &st->tonalMDCTconceal, hTcxDec->L_frameTCX, st->L_frame, FDNS_NPTS, st->hTcxCfg ); + TonalMDCTConceal_Init( &st->tonalMDCTconceal, hTcxDec->L_frameTCX, st->L_frame, FDNS_NPTS, st->hTcxCfg ); } st->last_tns_active = 0; move16(); diff --git a/lib_dec/tonalMDCTconcealment_fx.c b/lib_dec/tonalMDCTconcealment_fx.c index fa085d987..6e3ddcfd2 100644 --- a/lib_dec/tonalMDCTconcealment_fx.c +++ b/lib_dec/tonalMDCTconcealment_fx.c @@ -83,7 +83,10 @@ ivas_error TonalMDCTConceal_Init( hTonalMDCTConc->secondLastBlockData.blockIsConcealed = 0; move16(); + hTonalMDCTConc->pTCI = (TonalComponentsInfo *) hTonalMDCTConc->timeDataBuffer; move16(); + + hTonalMDCTConc->lastPitchLag = L_deposit_l( 0 ); IF( NE_16( hTonalMDCTConc->nSamples, nSamples ) ) @@ -103,14 +106,14 @@ ivas_error TonalMDCTConceal_Init( move16(); #ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT PMTE() - set_zero( hTonalMDCTConc->scaleFactorsBackground_flt, FDNS_NPTS ); + set_zero( hTonalMDCTConc->scaleFactorsBackground, FDNS_NPTS ); PsychoacousticParameters_Init( INT_FS_16k, L_FRAME16k, 64, 1, 1, &hTonalMDCTConc->psychParamsTCX20 ); PsychoacousticParameters_Init( INT_FS_16k, L_FRAME16k / 2, 64, 0, 1, &hTonalMDCTConc->psychParamsTCX10 ); hTonalMDCTConc->psychParams = NULL; - hTonalMDCTConc->scf_fadeout_flt = 1.0f; - hTonalMDCTConc->last_block_nrg_flt = 0.0f; - hTonalMDCTConc->curr_noise_nrg_flt = 0.0f; - hTonalMDCTConc->faded_signal_nrg_flt = 0.0f; + hTonalMDCTConc->scf_fadeout = 1.0f; + hTonalMDCTConc->last_block_nrg = 0.0f; + hTonalMDCTConc->curr_noise_nrg = 0.0f; + hTonalMDCTConc->faded_signal_nrg = 0.0f; #endif /* Offset the pointer to the end of buffer, so that pTCI is not destroyed when @@ -118,8 +121,8 @@ ivas_error TonalMDCTConceal_Init( move16(); move16(); /* just the second half of the second last pcm output is needed */ - hTonalMDCTConc->secondLastPcmOut = &hTonalMDCTConc->timeDataBuffer[( 3 * L_FRAME_MAX ) / 2 - ( 3 * ( min( L_FRAME_MAX, nSamples ) ) / 2 )]; - hTonalMDCTConc->lastPcmOut = &hTonalMDCTConc->timeDataBuffer[( 3 * L_FRAME_MAX ) / 2 - min( L_FRAME_MAX, nSamples )]; + hTonalMDCTConc->secondLastPcmOut = &hTonalMDCTConc->timeDataBuffer[sub( ( 3 * L_FRAME_MAX ) / 2, 3 * ( s_min( L_FRAME_MAX, nSamples ) ) / 2 )]; + hTonalMDCTConc->lastPcmOut = &hTonalMDCTConc->timeDataBuffer[sub( ( 3 * L_FRAME_MAX ) / 2, s_min( L_FRAME_MAX, nSamples ) )]; /* If the second last frame was lost, we reuse saved TonalComponentsInfo and don't update pcm buffers */ assert( sizeof( *hTonalMDCTConc->pTCI ) <= ( hTonalMDCTConc->lastPcmOut - hTonalMDCTConc->timeDataBuffer ) * sizeof( hTonalMDCTConc->timeDataBuffer[0] ) ); -- GitLab