diff --git a/lib_enc/cod_tcx_fx.c b/lib_enc/cod_tcx_fx.c index d6d1967321bde39fba7352d54b01efd357fbae6f..66561361eae82f8fb59ba6945bedd7fc3d432ef6 100644 --- a/lib_enc/cod_tcx_fx.c +++ b/lib_enc/cod_tcx_fx.c @@ -1671,6 +1671,12 @@ void QuantizeSpectrum_ivas_fx( QuantizeTCXSpectrum_fx( st, frame_cnt, hTcxEnc->spectrum_fx[frame_cnt], hTcxEnc->spectrum_e[frame_cnt], gainlpc_fx, gainlpc_e, Aqind, tnsSize, nb_bits, vad_hover_flag, &L_frameTCX, &L_frame, &L_spec, &tcx_offset, &noiseFillingBorder, quantized_spectrum_fx, &quantized_spectrum_e, hm_cfg, &hm_active, lf_deemph_fact_fx, &nf_seed, &ener_fx, &ener_e, &gain_tcx_fx, &gain_tcx_e, prm ); + if ( hTcxEnc->spectrum_e[frame_cnt] < 0 ) + { + /*buffer is already scaled inside QuantizeTCXSpectrum_fx*/ + hTcxEnc->spectrum_e[frame_cnt] = 0; + move16(); + } Word16 s1 = sub( getScaleFactor32( st->hTcxEnc->spectrum_fx[frame_cnt], L_frame ), 6 ); Word16 s2 = getScaleFactor32( quantized_spectrum_fx, s_max( L_frame, L_spec ) ); @@ -3553,7 +3559,7 @@ void QuantizeTCXSpectrum_fx( Encoder_State *st, /* i : state handle */ const Word16 frame_cnt, /* i : frame counter in the super_frame Q0 */ Word32 *x_orig_fx, /* i : shaped MDCT spectrum */ - const Word16 x_orig_e, /* i : exp of shaped MDCT spectrum */ + Word16 x_orig_e, /* i : exp of shaped MDCT spectrum */ Word16 *gainlpc_fx, /* i : FDNS gains */ Word16 *gainlpc_e, /* i : exp of FDNS gains */ const Word16 *Aqind, /* i : frame-independent quantized coefficients (M+1) Q0 */ @@ -3708,6 +3714,15 @@ void QuantizeTCXSpectrum_fx( } /* Start with the pre-shaped spectrum*/ + + /*scaling buffer to Q31 if exp < 0 to avoid overflow while scaling constants*/ + IF( x_orig_e < 0 ) + { + scale_sig32( x_orig_fx, L_spec, x_orig_e ); + x_orig_e = 0; + move16(); + } + Copy32( x_orig_fx, spectrum_fx, L_spec ); *spectrum_e = x_orig_e; move16(); diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index 07e3aece51546bd7b28d76f4db0a43bbac7430e2..3a6ff508ddf4c651ae30ddb978c5b6401d7ec714 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -402,10 +402,12 @@ ivas_error ivas_cpe_enc_fx( stereo_tca_enc_fx( hCPE, input_frame ); - Copy_Scale_sig32_16( sts[0]->input_buff32_fx, sts[0]->input_buff_fx, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), sub( add( Q16, 0 ), sts[0]->q_inp32 ) ); - Copy_Scale_sig32_16( sts[1]->input_buff32_fx, sts[1]->input_buff_fx, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), sub( add( Q16, 0 ), sts[1]->q_inp32 ) ); + shift = s_min( 0, sub( add( L_norm_arr( sts[0]->input_buff32_fx, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ), sts[0]->q_inp32 ), 16 ) ); + shift = s_min( shift, sub( add( L_norm_arr( sts[1]->input_buff32_fx, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ), sts[0]->q_inp32 ), 16 ) ); + Copy_Scale_sig32_16( sts[0]->input_buff32_fx, sts[0]->input_buff_fx, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), sub( add( Q16, shift ), sts[0]->q_inp32 ) ); + Copy_Scale_sig32_16( sts[1]->input_buff32_fx, sts[1]->input_buff_fx, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), sub( add( Q16, shift ), sts[1]->q_inp32 ) ); - sts[0]->q_inp = sts[1]->q_inp = sts[0]->q_old_inp = sts[1]->q_old_inp = 0; + sts[0]->q_inp = sts[1]->q_inp = sts[0]->q_old_inp = sts[1]->q_old_inp = shift; move16(); move16(); move16(); diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 621b77e33e84d91edbaa376b9223c0f9e494940d..4e0b45e46aff6c27a7535ffe048f2b1a9134eb49 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -2525,7 +2525,7 @@ void QuantizeTCXSpectrum_fx( Encoder_State *st, /* i : state handle */ const Word16 frame_cnt, /* i : frame counter in the super_frame Q0 */ Word32 *x_orig_fx, /* i : shaped MDCT spectrum */ - const Word16 x_orig_e, /* i : exp of shaped MDCT spectrum */ + Word16 x_orig_e, /* i : exp of shaped MDCT spectrum */ Word16 *gainlpc_fx, /* i : FDNS gains */ Word16 *gainlpc_e, /* i : exp of FDNS gains */ const Word16 *Aqind, /* i : frame-independent quantized coefficients (M+1) Q0 */ diff --git a/lib_enc/tcx_utils_enc_fx.c b/lib_enc/tcx_utils_enc_fx.c index 9beb4bc379f561c2b5a9860982fc682980be31a9..7098e4502c1311f8ef380b390cae106204e5c93b 100644 --- a/lib_enc/tcx_utils_enc_fx.c +++ b/lib_enc/tcx_utils_enc_fx.c @@ -369,6 +369,13 @@ void AnalyzePowerSpectrum_ivas_fx( tmp32 = L_shl( mdctSpectrum[i], shift ); powerSpec[i] = BASOP_Util_Add_Mant32Exp( powerSpec[i], shl( powerSpec_e[i], 1 ), Mpy_32_32( tmp32, tmp32 ), shl( sub( mdctSpectrum_e, shift ), 1 ), &powerSpec_e[i] ); move32(); + IF( LT_16( powerSpec_e[i], -31 ) ) + { + powerSpec[i] = L_shl( powerSpec[i], sub( powerSpec_e[i], -31 ) ); + move32(); + powerSpec_e[i] = -31; + move16(); + } temp_powerSpec_e = s_max( temp_powerSpec_e, powerSpec_e[i] ); }