diff --git a/lib_com/options.h b/lib_com/options.h index 2b2ccec9b5bf38b4fb29f383fec7f0b457a730ac..8cfd1dc741bc64766fb42acb602b483cfb2fc01c 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -154,6 +154,8 @@ #define FIX_BASOP_2562_HQ_PREECHO_SAT /* Eri/Orange: Basop issue 2562: Add saturation to L_add in preecho calculations */ #define FIX_BASOP_2561_STEREO_DFT_ENC_COMPUTE_ITD /* BASOP issue 2561: fix diffs in stereo_dft_enc_compute_itd() between float and BASOP */ #define FIX_BASOP_2517_CLICK_IN_OMASA_LTV /* FhG: BASOP #2517: preserve precision by removing one-bit headroom from Q_min and allowing saturation during buffer scaling */ +#define NONBE_FIX_ISSUE_2518 /* FhG: Fix issue 2518, noise during ACELP switching from 16KHz to 12k8Hz by improving Q_new calculation. */ +#define NONBE_FIX_ISSUE_2518_TRANSENC_SAT_FIX /* FhG: Fix issue 2518, fix wrong amplitude because of saturation of x_tran in transf_cdbk_enc_fx() for transient signals. */ #define FIX_BASOP_2559_Q_SYNTH_HISTORY_RESET /* FhG: BASOP issue 2559: reset hTcxDec->q_synth_history_fx in allocate_CoreCoder_TCX_fx() */ #define FIX_FLOAT_1578_OMASA_REND_SPIKES /* Nokia: Float issue 1578: Fix spikes and collapsed perception in OMASA/MASA rendering to FOA/HOA */ #define FIX_1521_SBA_LOUDNESS_STEREO /* FhG: issue 1521: Fix loudness for SBA to stereo rendering */ diff --git a/lib_enc/acelp_core_enc_fx.c b/lib_enc/acelp_core_enc_fx.c index 5949ce99f57ba77a968a0a45fccd6731f68ec4db..5f38e5bd374a43f5ab6bcb754be4c4bc2ca77128 100644 --- a/lib_enc/acelp_core_enc_fx.c +++ b/lib_enc/acelp_core_enc_fx.c @@ -117,6 +117,9 @@ ivas_error acelp_core_enc_fx( move16(); hLPDmem->q_mem_syn = sub( Q_new, 1 ); move16(); +#ifdef NONBE_FIX_ISSUE_2518 + st->mem_deemp_preQ_fx = shl_sat( st->mem_deemp_preQ_fx, sub( Q_new, st->prev_Q_new ) ); +#endif } Scale_sig32( st->Bin_E_old_fx, L_FFT / 2, sub( add( Q_new, Q_SCALE - 2 ), st->q_Bin_E_old ) ); // Q_new + Q_scale - 2 @@ -973,6 +976,7 @@ ivas_error acelp_core_enc_fx( * Updates *-----------------------------------------------------------------*/ +#ifndef NONBE_FIX_ISSUE_2518 IF( st->element_mode > EVS_MONO ) { if ( st->hBWE_TD != NULL ) @@ -983,6 +987,7 @@ ivas_error acelp_core_enc_fx( hLPDmem->q_lpd_old_exc = Q_new; move16(); } +#endif updt_enc_fx( st, old_exc_fx, pitch_buf, Es_pred_fx, Aq, lsf_new_fx, lsp_new, old_bwe_exc_fx ); diff --git a/lib_enc/core_enc_init_fx.c b/lib_enc/core_enc_init_fx.c index d79a2a3c9d263491ee645326c13280bdbffaf4cd..7efe8a9ff28578122718235c8d76ca5239c7f991 100644 --- a/lib_enc/core_enc_init_fx.c +++ b/lib_enc/core_enc_init_fx.c @@ -28,7 +28,11 @@ static void init_tcx_ivas_fx( Encoder_State *st, const Word16 L_frame_old, const static void init_core_sig_ana_ivas_fx( Encoder_State *st ); static void init_modes_ivas_fx( Encoder_State *st, const Word32 last_total_brate ); static void init_sig_buffers_ivas_fx( Encoder_State *st, const Word16 L_frame_old, const Word16 L_subfr, const Word32 last_total_brate ); +#ifdef NONBE_FIX_ISSUE_2518 +static void init_acelp_ivas_fx( Encoder_State *st, Word16 L_frame_old, const Word32 last_total_brate ); +#else static void init_acelp_ivas_fx( Encoder_State *st, Word16 L_frame_old, Word16 shift, const Word32 last_total_brate ); +#endif /*-----------------------------------------------------------------------* * init_coder_ace_plus_fx() @@ -1085,7 +1089,11 @@ void init_coder_ace_plus_ivas_fx( /* Initialize ACELP */ +#ifdef NONBE_FIX_ISSUE_2518 + init_acelp_ivas_fx( st, L_frame_old, last_total_brate ); +#else init_acelp_ivas_fx( st, L_frame_old, 0, last_total_brate ); +#endif if ( st->ini_frame == 0 ) { @@ -1538,7 +1546,11 @@ static void init_core_sig_ana_ivas_fx( Encoder_State *st ) * * *-----------------------------------------------------------------------*/ +#ifdef NONBE_FIX_ISSUE_2518 +static void init_acelp_ivas_fx( Encoder_State *st, Word16 L_frame_old, const Word32 last_total_brate ) +#else static void init_acelp_ivas_fx( Encoder_State *st, Word16 L_frame_old, Word16 shift, const Word32 last_total_brate ) +#endif { Word16 mem_syn_r_size_old; Word16 mem_syn_r_size_new; @@ -1721,8 +1733,13 @@ static void init_acelp_ivas_fx( Encoder_State *st, Word16 L_frame_old, Word16 sh move16(); Copy( hLPDmem->mem_syn2, tmp_buf + 1, M ); deemph_fx( tmp_buf + 1, st->preemph_fac, M, &tmp ); +#ifdef NONBE_FIX_ISSUE_2518 + Residu3_fx( Ap, tmp_buf + M, &tmp, 1, 0 ); + hLPDmem->mem_w0 = sub_sat( shl_sat( st->wspeech_enc[-1], sub( hLPDmem->q_mem_syn, sub( Q15, st->exp_buf_wspeech_enc ) ) ), tmp ); +#else Residu3_fx( Ap, tmp_buf + M, &tmp, 1, 1 ); hLPDmem->mem_w0 = sub_sat( shr_sat( st->wspeech_enc[-1], shift ), tmp ); +#endif move16(); } } diff --git a/lib_enc/core_enc_switch_fx.c b/lib_enc/core_enc_switch_fx.c index b94595176ae98324ce53fa314f1424ce6a59b05e..3bea33c1228bb5293ae6bd52acca6f1f7c148435 100644 --- a/lib_enc/core_enc_switch_fx.c +++ b/lib_enc/core_enc_switch_fx.c @@ -386,6 +386,7 @@ void core_coder_mode_switch_ivas_fx( move32(); st->currEnergyHF_e_fx = 0; move16(); +#ifndef NONBE_FIX_ISSUE_2518 Word16 shift = getScaleFactor16( st->old_inp_16k_fx, L_INP_MEM ); Scale_sig( st->old_inp_16k_fx, L_INP_MEM, shift ); st->exp_old_inp_16k = sub( st->exp_old_inp_16k, shift ); @@ -394,12 +395,15 @@ void core_coder_mode_switch_ivas_fx( Scale_sig( st->old_inp_12k8_fx, L_INP_MEM, shift ); st->exp_old_inp_12k8 = sub( st->exp_old_inp_12k8, shift ); move16(); +#endif init_coder_ace_plus_ivas_fx( st, last_total_brate, st->total_brate, MCT_flag ); +#ifndef NONBE_FIX_ISSUE_2518 if ( st->hLPDmem != NULL ) { st->hLPDmem->q_lpd_old_exc = st->prev_Q_new; move16(); } +#endif } test(); diff --git a/lib_enc/core_enc_updt_fx.c b/lib_enc/core_enc_updt_fx.c index f6aba6f612395a6ef00d9b002f6376151556a4af..3272830e8166679fe0ed2934210addacc4c01edc 100644 --- a/lib_enc/core_enc_updt_fx.c +++ b/lib_enc/core_enc_updt_fx.c @@ -102,6 +102,7 @@ void core_encode_update_cng_fx( p_A += ( M + 1 ); } + assert( st->element_mode == EVS_MONO ); tmp = sub( st->wspeech_enc[-1], shl( hLPDmem->mem_w0, shift ) ); E_UTIL_deemph2( negate( shift ), wsyn, st->preemph_fac, st->L_frame, &tmp ); hLPDmem->mem_w0 = sub_sat( st->wspeech_enc[st->L_frame - 1], tmp ); diff --git a/lib_enc/enc_higher_acelp_fx.c b/lib_enc/enc_higher_acelp_fx.c index 24bf48838bdb9584f095f79c2f889e114930026f..9d74cedc9a0239c1a1ca624a140f485df08b483e 100644 --- a/lib_enc/enc_higher_acelp_fx.c +++ b/lib_enc/enc_higher_acelp_fx.c @@ -301,11 +301,26 @@ void transf_cdbk_enc_fx( * DCT transform *--------------------------------------------------------------*/ +#ifdef NONBE_FIX_ISSUE_2518_TRANSENC_SAT_FIX + Word16 q_x_tran; + IF( EQ_16( st_fx->element_mode, EVS_MONO ) ) + { + q_x_tran = Q_AVQ_OUT_DEC; + move16(); + Copy_Scale_sig( x_norm, x_tran, Nsv * WIDTH_BAND, q_x_tran ); + } + ELSE + { + q_x_tran = s_min( Q_AVQ_OUT_DEC, norm_arr( x_norm, Nsv * WIDTH_BAND ) ); + Copy_Scale_sig_nosat( x_norm, x_tran, Nsv * WIDTH_BAND, q_x_tran ); + } +#else FOR( i = 0; i < Nsv * WIDTH_BAND; i++ ) { x_tran[i] = shl_sat( x_norm[i], Q_AVQ_OUT_DEC ); move16(); } +#endif test(); test(); @@ -321,8 +336,13 @@ void transf_cdbk_enc_fx( edct2_fx( L_SUBFR, 1, x_tran, out32, &Qdct, ip_edct2_64, w_edct2_64_fx ); /*qdct = sub(Q_AVQ_OUT_DEC,qdct+Q_AVQ_OUT_DEC);*/ Qdct = negate( Qdct ); +#ifdef NONBE_FIX_ISSUE_2518_TRANSENC_SAT_FIX + Copy_Scale_sig_32_16( out32, code_preQ, L_SUBFR, Qdct ); /* Output in q_x_tran */ + /*qdct = q_x_tran;*/ +#else Copy_Scale_sig_32_16( out32, code_preQ, L_SUBFR, Qdct ); /* Output in Q_AVQ_OUT_DEC */ - /*qdct = Q_AVQ_OUT_DEC;*/ + /*qdct = Q_AVQ_OUT_DEC;*/ +#endif } /*--------------------------------------------------------------* @@ -348,22 +368,41 @@ void transf_cdbk_enc_fx( test(); IF( GT_16( st_fx->element_mode, EVS_MONO ) && NE_16( st_fx->coder_type, INACTIVE ) && GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) && LE_32( st_fx->core_brate, MAX_BRATE_AVQ_EXC_TD ) && !harm_flag_acelp && code_preQ[0] != 0 ) { +#ifdef NONBE_FIX_ISSUE_2518_TRANSENC_SAT_FIX + IF( GT_16( abs_s( st_fx->last_code_preq ), shl_sat( abs_s( code_preQ[0] ), sub( Q_AVQ_OUT_DEC + 4, q_x_tran ) ) ) ) +#else IF( GT_16( abs_s( st_fx->last_code_preq ), shl_sat( abs_s( code_preQ[0] ), 4 ) ) ) +#endif { st_fx->mem_preemp_preQ_fx = shr( st_fx->mem_preemp_preQ_fx, 4 ); move16(); } +#ifdef NONBE_FIX_ISSUE_2518_TRANSENC_SAT_FIX + ELSE IF( GT_16( abs_s( st_fx->last_code_preq ), shl_sat( abs_s( code_preQ[0] ), sub( Q_AVQ_OUT_DEC + 3, q_x_tran ) ) ) ) +#else ELSE IF( GT_16( abs_s( st_fx->last_code_preq ), shl_sat( abs_s( code_preQ[0] ), 3 ) ) ) +#endif { st_fx->mem_preemp_preQ_fx = shr( st_fx->mem_preemp_preQ_fx, 3 ); move16(); } } +#ifdef NONBE_FIX_ISSUE_2518_TRANSENC_SAT_FIX + st_fx->last_code_preq = shl_sat( code_preQ[L_SUBFR - 1], sub( 1, q_x_tran ) ); // Q0 ? Q1 + move16(); + + st_fx->mem_preemp_preQ_fx = shl_sat( st_fx->mem_preemp_preQ_fx, sub( q_x_tran, Q_AVQ_OUT_DEC ) ); + move16(); + preemph_fx( code_preQ, FAC_PRE_AVQ_FX, L_SUBFR, &( st_fx->mem_preemp_preQ_fx ) ); + st_fx->mem_preemp_preQ_fx = shl_sat( st_fx->mem_preemp_preQ_fx, sub( Q_AVQ_OUT_DEC, q_x_tran ) ); + move16(); +#else st_fx->last_code_preq = shr( code_preQ[L_SUBFR - 1], 9 ); // Q0 move16(); preemph_fx( code_preQ, FAC_PRE_AVQ_FX, L_SUBFR, &( st_fx->mem_preemp_preQ_fx ) ); +#endif /*--------------------------------------------------------------* * For inactive segments @@ -376,22 +415,36 @@ void transf_cdbk_enc_fx( IF( EQ_16( st_fx->coder_type, INACTIVE ) ) { /*ftemp = fcode_preQ[0] *fh1[L_SUBFR-1];*/ +#ifdef NONBE_FIX_ISSUE_2518_TRANSENC_SAT_FIX + Ltmp = L_mult( code_preQ[0], h1[L_SUBFR - 1] ); /*1+14+shift + q_x_tran */ +#else Ltmp = L_mult( code_preQ[0], h1[L_SUBFR - 1] ); /*1+14+shift + Q_AVQ_OUT */ +#endif FOR( i = 1; i < L_SUBFR; i++ ) { /*ftemp += fcode_preQ[i] * fh1[L_SUBFR-1-i];*/ Ltmp = L_mac( Ltmp, code_preQ[i], h1[L_SUBFR - 1 - i] ); } /*fxn[L_SUBFR-1] -= *fgain_preQ * ftemp;*/ +#ifdef NONBE_FIX_ISSUE_2518_TRANSENC_SAT_FIX + Ltmp = L_shr( Mult_32_16( Ltmp, *gain_preQ ), sub( add( q_x_tran, 2 ), Q_new ) ); /* (2 + 1 + 14 +shift+Q_AVQ_OUT)-(Q_AVQ_OUT+2-Q_new) = 15 + Q_new + shift */ +#else Ltmp = L_shr( Mult_32_16( Ltmp, *gain_preQ ), sub( add( Q_AVQ_OUT_DEC, 2 ), Q_new ) ); /* (2 + 1 + 14 +shift+Q_AVQ_OUT)-(Q_AVQ_OUT+2-Q_new) = 15 + Q_new + shift */ - xn[L_SUBFR - 1] = round_fx( L_sub( L_mult( xn[L_SUBFR - 1], 32767 ), Ltmp ) ); /* -> Q_new + shift -1 */ +#endif + xn[L_SUBFR - 1] = round_fx( L_sub( L_mult( xn[L_SUBFR - 1], 32767 ), Ltmp ) ); /* -> Q_new + shift -1 */ } ELSE { conv_fx( code_preQ, h1, x_tran, L_SUBFR ); +#ifdef NONBE_FIX_ISSUE_2518_TRANSENC_SAT_FIX + updt_tar_HR_fx( cn, cn, code_preQ, *gain_preQ, sub( Q_new, add( -15 + 2, q_x_tran ) ), L_SUBFR ); + + updt_tar_HR_fx( xn, xn, x_tran, *gain_preQ, sub( Q_new, add( -15 + 2, q_x_tran ) ), L_SUBFR ); +#else updt_tar_HR_fx( cn, cn, code_preQ, *gain_preQ, sub( Q_new, add( -15 + 2, Q_AVQ_OUT_DEC ) ), L_SUBFR ); updt_tar_HR_fx( xn, xn, x_tran, *gain_preQ, sub( Q_new, add( -15 + 2, Q_AVQ_OUT_DEC ) ), L_SUBFR ); +#endif *gain_pit = corr_xy1_fx( xn, y1, g_corr, L_SUBFR, 0, &Overflow ); /* Q14 */ move16(); /* clip gain if necessary to avoid problems at decoder */ diff --git a/lib_enc/init_enc_fx.c b/lib_enc/init_enc_fx.c index e47b7621f600edcb7e015104284d1027875515ef..60760e2fb95cf291a1a0553e5c7633b1421a077a 100644 --- a/lib_enc/init_enc_fx.c +++ b/lib_enc/init_enc_fx.c @@ -249,6 +249,13 @@ ivas_error init_encoder_fx( st->prev_Q_new = 0; move16(); +#ifdef NONBE_FIX_ISSUE_2518 + if ( st->element_mode > EVS_MONO ) + { + st->prev_Q_new = Q15; + move16(); + } +#endif IF( EQ_32( st->input_Fs, 8000 ) ) { @@ -1144,11 +1151,13 @@ ivas_error init_encoder_fx( init_coder_ace_plus_ivas_fx( st, st->last_total_brate, igf_brate, 0 ); } +#ifndef NONBE_FIX_ISSUE_2518 IF( st->hLPDmem != NULL ) { st->hLPDmem->q_lpd_old_exc = st->prev_Q_new; move16(); } +#endif /*-----------------------------------------------------------------* * FD-CNG encoder diff --git a/lib_enc/ivas_core_enc_fx.c b/lib_enc/ivas_core_enc_fx.c index 6b8f647e5c34d538fcfe5b95837a7bc552712bdb..b734fce5223b569dbb8e7f4934e0004a8d112ed3 100644 --- a/lib_enc/ivas_core_enc_fx.c +++ b/lib_enc/ivas_core_enc_fx.c @@ -452,11 +452,13 @@ ivas_error ivas_core_enc_fx( #ifndef NONBE_FIX_ISSUE_2206_MDCT_STEREO_FIX_2549 Scale_sig( old_inp_16k_fx[n], L_INP, sub( Q1, Q_new[n] ) ); // Q0 #endif +#ifndef NONBE_FIX_ISSUE_2518 IF( NE_16( st->element_mode, IVAS_CPE_DFT ) && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { st->hTcxEnc->exp_buf_speech_ltp = st->exp_buf_speech_enc; move16(); } +#endif } Word16 Q_spec_old[2], L_spec; #endif @@ -582,12 +584,14 @@ ivas_error ivas_core_enc_fx( Scale_sig( old_inp_16k_fx[i], L_INP, sub( Q1, Q_new[i] ) ); // Q0 #endif +#ifndef NONBE_FIX_ISSUE_2518 test(); IF( NE_16( st->element_mode, IVAS_CPE_DFT ) && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { st->hTcxEnc->exp_buf_speech_ltp = st->exp_buf_speech_enc; move16(); } +#endif shift = norm_arr( st->input_fx, input_frame ); #ifdef NONBE_FIX_ISSUE_2206 Q_min = add( st->q_inp, shift ); diff --git a/lib_enc/ivas_core_pre_proc_front_fx.c b/lib_enc/ivas_core_pre_proc_front_fx.c index 6c9d56fe00df90bff37035853da975202063ca19..77be7fe6ddeffe3b78136ebc404aa9a0beaa302b 100644 --- a/lib_enc/ivas_core_pre_proc_front_fx.c +++ b/lib_enc/ivas_core_pre_proc_front_fx.c @@ -211,9 +211,15 @@ void pre_proc_front_ivas_fx( Word16 sf_energySum[CLDFB_NO_CHANNELS_MAX]; Word16 Q_inp_const = -1; move16(); +#ifdef NONBE_FIX_ISSUE_2518 + Word16 preemp_len; + Word16 *preemp_start_idx = NULL; + Word32 sig_out[STEREO_DFT_OVL_16k + L_FRAME16k /* = max( L_FRAME16k + STEREO_DFT_OVL_16k, L_FRAME16k + L_FILT16k + lMemRecalc_16k ) */]; +#else Word16 headroom, preemp_len, inp_max; Word16 *preemp_start_idx = NULL; Word32 sig_out[STEREO_DFT_OVL_16k + L_FRAME16k /* = max( L_FRAME16k + STEREO_DFT_OVL_16k, L_FRAME16k + L_FILT16k + lMemRecalc_16k ) */], max_32; +#endif push_wmops( "pre_proc_front" ); /*------------------------------------------------------------------* @@ -572,9 +578,15 @@ void pre_proc_front_ivas_fx( #endif } #ifdef NONBE_FIX_ISSUE_2206 +#ifdef NONBE_FIX_ISSUE_2518 + st->q_mem_decim_fx = add( st->q_inp, norm_arr( st->mem_decim_fx_q_inp, 2 * L_FILT_MAX ) ); + move16(); + Copy_Scale_sig_nosat( st->mem_decim_fx_q_inp, st->mem_decim_fx, 2 * L_FILT_MAX, sub( st->q_mem_decim_fx, st->q_inp ) ); +#else Copy( st->mem_decim_fx_q_inp, st->mem_decim_fx, 2 * L_FILT_MAX ); st->q_mem_decim_fx = st->q_inp; move16(); +#endif Word16 q_buf_speech_enc; @@ -627,6 +639,7 @@ void pre_proc_front_ivas_fx( * Perform fixed preemphasis (12.8 kHz signal) through 1 - g*z^-1 *-----------------------------------------------------------------*/ +#ifndef NONBE_FIX_ISSUE_2518 #ifdef NONBE_FIX_ISSUE_2206 headroom = 0; move16(); @@ -638,6 +651,7 @@ void pre_proc_front_ivas_fx( #else headroom = 2; move16(); +#endif #endif preemp_len = 0; move16(); @@ -734,6 +748,26 @@ void pre_proc_front_ivas_fx( move16(); st->mem_preemph_q = st->q_inp; move16(); +#ifdef NONBE_FIX_ISSUE_2518 + Word16 shift = L_norm_arr( sig_out, preemp_len ); + shift = s_min( shift, norm_arr( old_inp_12k8_fx, (Word16) ( preemp_start_idx - old_inp_12k8_fx ) ) ); + shift = add( shift, st->q_inp ); + + /* Avoid saturation of resampling/delay decimation buffer. */ + shift = s_min( shift, st->q_mem_decim16k_fx ); + + /* Limit Q_new here to st->q_inp because inside ivas_compute_core_buffers_fx() st->input is rescaled to Q_new */ + shift = s_min( shift, st->q_inp ); + IF( st->hLPDmem != NULL ) + { + shift = s_min( shift, st->hLPDmem->q_lpd_old_exc ); + shift = s_min( shift, st->hLPDmem->q_lpd_syn ); + shift = s_min( shift, add( st->hLPDmem->q_mem_syn, 1 ) ); + } + + *Q_new = s_min( shift, Q_MAX ); + move16(); +#else maximum_abs_32_fx( sig_out, preemp_len, &max_32 ); inp_max = s_max( extract_h( max_32 ), 1 ); @@ -769,7 +803,9 @@ void pre_proc_front_ivas_fx( st->Q_max[i] = shift; move16(); #endif +#endif +#ifndef NONBE_FIX_ISSUE_2518 #ifdef NONBE_FIX_ISSUE_2206 /* Avoid saturation of resampling decimation buffer inside ivas_compute_core_buffers_fx(). */ *Q_new = s_min( *Q_new, st->q_mem_decim16k_fx ); @@ -778,6 +814,7 @@ void pre_proc_front_ivas_fx( #endif *Q_new = add( *Q_new, Q_inp_const ); move16(); +#endif Copy_Scale_sig32_16( sig_out, preemp_start_idx, preemp_len, sub( add( *Q_new, 1 ), st->q_inp ) ); /* Q_new */ Scale_sig( old_inp_12k8_fx, (Word16) ( preemp_start_idx - old_inp_12k8_fx ), sub( *Q_new, st->q_inp ) ); /* Q_new */ #ifdef NONBE_FIX_ISSUE_2206 diff --git a/lib_enc/ivas_core_pre_proc_fx.c b/lib_enc/ivas_core_pre_proc_fx.c index 6f95331cc3bc11efdda01ec153eb61746ad4785d..22bf0522bd20212f4721d7bfa553ac6927b1f5b8 100644 --- a/lib_enc/ivas_core_pre_proc_fx.c +++ b/lib_enc/ivas_core_pre_proc_fx.c @@ -831,9 +831,15 @@ void ivas_compute_core_buffers_fx( #else Word16 i, shift, Q_min; #endif +#ifdef NONBE_FIX_ISSUE_2518 + Word16 preemp_len; + Word16 *preemp_start_idx = NULL; + Word32 sig_out[STEREO_DFT_OVL_16k + L_FRAME16k + L_FILT16k]; +#else Word16 preemp_len, inp_max; Word16 *preemp_start_idx = NULL; Word32 sig_out[STEREO_DFT_OVL_16k + L_FRAME16k + L_FILT16k], max_32; +#endif #ifdef NONBE_FIX_ISSUE_2206 assert( Q_old_inp_16k == ( *Q_new - 1 ) ); @@ -961,7 +967,6 @@ void ivas_compute_core_buffers_fx( size_modified = modify_Fs_fx( temp1F_icatdmResampBuf_fx, NS2SA_FX2( input_Fs, DELAY_FIR_RESAMPL_NS ), input_Fs, new_inp_16k_fx + NS2SA_FX2( sr_core, FRAME_SIZE_NS ), sr_core, mem_decim16k_dummy_fx, 0, &Q_tmp, &mem_decim16k_size ); /* Q0 */ #ifdef NONBE_FIX_ISSUE_2206 scale_sig( new_inp_16k_fx + NS2SA_FX2( sr_core, FRAME_SIZE_NS ), size_modified, negate( Q_tmp ) ); /* scaling back to Q_old_inp_16k */ - // Scale_sig( st->mem_decim16k_fx, 2 * L_FILT_MAX, sub( -1, Q_old_inp_16k ) ); /* Q(-1) */ Q_tmp = norm_arr( st->mem_decim16k_fx, mem_decim16k_size ); scale_sig( st->mem_decim16k_fx, mem_decim16k_size, Q_tmp ); st->q_mem_decim16k_fx = add( Q_tmp, Q_old_inp_16k ); @@ -1314,6 +1319,23 @@ void ivas_compute_core_buffers_fx( preemp_len = L_FRAME16k + L_FILT16k; move16(); } +#ifdef NONBE_FIX_ISSUE_2518 + shift = L_norm_arr( sig_out, preemp_len ); + shift = s_min( shift, norm_arr( old_inp_16k_fx, (Word16) ( preemp_start_idx - old_inp_16k_fx ) ) ); + shift = add( shift, Q_old_inp_16k ); + + /* Avoid saturation of resampling/delay decimation buffer. */ + shift = s_min( shift, add( st->q_mem_decim16k_fx, 1 ) ); + + IF( st->hLPDmem != NULL ) + { + shift = s_min( shift, st->hLPDmem->q_lpd_old_exc ); + shift = s_min( shift, st->hLPDmem->q_lpd_syn ); + shift = s_min( shift, add( st->hLPDmem->q_mem_syn, 1 ) ); + } + *Q_new = s_min( shift, Q_MAX ); + move16(); +#else maximum_abs_32_fx( sig_out, preemp_len, &max_32 ); inp_max = s_max( extract_h( max_32 ), 1 ); @@ -1323,6 +1345,7 @@ void ivas_compute_core_buffers_fx( #else shift = sub( norm_s( inp_max ), 1 /* headroom */ ); #endif + #ifdef NONBE_FIX_ISSUE_2206 *Q_new = s_min( shift, Q_MAX ); move16(); @@ -1353,6 +1376,7 @@ void ivas_compute_core_buffers_fx( st->Q_max_16k[i] = shift; move16(); #endif +#endif #ifndef NONBE_FIX_ISSUE_2206 Copy_Scale_sig32_16( sig_out, preemp_start_idx, preemp_len, add( *Q_new, 1 ) ); diff --git a/lib_enc/stat_enc.h b/lib_enc/stat_enc.h index f84b518245749b39889e90a05a467a075887a2d5..862292de802b6e7ce0b1c5b68a1b1f2192f2a79a 100644 --- a/lib_enc/stat_enc.h +++ b/lib_enc/stat_enc.h @@ -1790,7 +1790,9 @@ typedef struct enc_core_structure * Fixed point only variables *----------------------------------------------------------------------------------*/ +#ifndef NONBE_FIX_ISSUE_2518 Word16 Q_exc; +#endif Word16 Q_stat_noise_ge; Word16 Q_stat_noise; Word16 Q_syn2; diff --git a/lib_enc/updt_enc_fx.c b/lib_enc/updt_enc_fx.c index 65f997c63b029eb47fbd593750dbd44414bbd7d2..9224b1081343fb5b130dae255ec461b4ddb0670d 100644 --- a/lib_enc/updt_enc_fx.c +++ b/lib_enc/updt_enc_fx.c @@ -34,8 +34,47 @@ void updt_enc_fx( GSC_ENC_HANDLE hGSCEnc = st->hGSCEnc; TD_BWE_ENC_HANDLE hBWE_TD = st->hBWE_TD; +#ifdef NONBE_FIX_ISSUE_2518 + /* update old excitation buffer */ + IF( st->element_mode > EVS_MONO ) + { + tmp = norm_arr( &old_exc[st->L_frame], L_EXC_MEM ); + tmp = s_min( tmp, sub( 15, hLPDmem->q_lpd_old_exc ) ); + Copy_Scale_sig_nosat( &old_exc[st->L_frame], hLPDmem->old_exc, L_EXC_MEM, tmp ); + hLPDmem->q_lpd_old_exc = add( hLPDmem->q_lpd_old_exc, tmp ); + move16(); + + tmp = norm_arr( st->hLPDmem->syn, M + 1 ); + tmp = s_min( tmp, sub( 15, hLPDmem->q_lpd_syn ) ); + scale_sig( st->hLPDmem->syn, M, tmp ); + st->hLPDmem->q_lpd_syn = add( st->hLPDmem->q_lpd_syn, tmp ); + move16(); + + tmp = norm_arr( hLPDmem->mem_syn, M ); + tmp = s_min( tmp, norm_arr( hLPDmem->mem_syn1_fx, M ) ); + tmp = s_min( tmp, norm_arr( hLPDmem->mem_syn2, M ) ); + tmp = s_min( tmp, norm_arr( hLPDmem->mem_syn3, M ) ); + tmp = s_min( tmp, norm_arr( hLPDmem->mem_syn_r, L_SYN_MEM ) ); + tmp = s_min( tmp, norm_s( hLPDmem->mem_w0 ) ); + tmp = s_min( tmp, sub( 15, hLPDmem->q_mem_syn ) ); + // tmp = sub( tmp, 1 ); + scale_sig( hLPDmem->mem_syn, M, tmp ); + scale_sig( hLPDmem->mem_syn1_fx, M, tmp ); + scale_sig( hLPDmem->mem_syn2, M, tmp ); + scale_sig( hLPDmem->mem_syn3, M, tmp ); + scale_sig( hLPDmem->mem_syn_r, L_SYN_MEM, tmp ); + hLPDmem->mem_w0 = shl( hLPDmem->mem_w0, tmp ); + move16(); + st->hLPDmem->q_mem_syn = add( st->hLPDmem->q_mem_syn, tmp ); + } + ELSE + { + Copy( &old_exc[st->L_frame], hLPDmem->old_exc, L_EXC_MEM ); + } +#else /* update old excitation buffer */ Copy( &old_exc[st->L_frame], hLPDmem->old_exc, L_EXC_MEM ); +#endif test(); test(); IF( !st->Opt_AMR_WB && st->hBWE_TD != NULL )