diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 3698eba021737cf1efac9de47b6afb10e1d28550..5104fd611b1050959e903ca9664da8da0b69660e 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -1078,7 +1078,7 @@ Word16 WB_BWE_encoding_fx( /* o : classification of wb Word16 WB_BWE_encoding_ivas_fx( /* o : classification of wb signal */ Encoder_State *st_fx, /* i/o: Encoder structure */ - const Word16 *yos_fx, /* i : MDCT coefficients of weighted original */ + const Word32 *yos_fx, /* i : MDCT coefficients of weighted original */ Word16 *WB_fenv_fx, /* i/o: energy of WB envelope */ Word16 Q_synth, Word16 Q_synth_lf ); diff --git a/lib_enc/swb_bwe_enc_fx.c b/lib_enc/swb_bwe_enc_fx.c index 3fe7d30fbb80af1bc543ee935e02425c39ec8cff..e0d84645895236cce9f93b1eaa9062c56a794ec2 100644 --- a/lib_enc/swb_bwe_enc_fx.c +++ b/lib_enc/swb_bwe_enc_fx.c @@ -211,11 +211,9 @@ void wb_bwe_enc_ivas_fx( Word16 Sample_Delay_WB_BWE; Word16 old_input_fx[NS2SA( 16000, DELAY_FD_BWE_ENC_NS + DELAY_FIR_RESAMPL_NS ) + L_FRAME16k]; Word32 yorig_32[L_FRAME16k]; - Word16 yorig_fx[L_FRAME16k]; Word32 L_wtda_synth_fx[2 * L_FRAME16k]; Word16 *new_input_fx; /* pointer to original input signal */ - Word16 scl, new_input_fx_exp; - Word16 Q_synth; + Word16 new_input_fx_exp; FD_BWE_ENC_HANDLE hBWE_FD = st_fx->hBWE_FD; Word16 WB_fenv_fx[SWB_FENV]; @@ -239,7 +237,7 @@ void wb_bwe_enc_ivas_fx( /* MDCT of the core synthesis signal */ /*---------------------------------------------------------------------*/ - new_input_fx_exp = 0; + new_input_fx_exp = -1; move16(); wtda_fx( old_input_fx, &new_input_fx_exp, L_wtda_synth_fx, hBWE_FD->L_old_wtda_swb_fx, @@ -249,22 +247,7 @@ void wb_bwe_enc_ivas_fx( /* DCT of the ACELP core synthesis */ direct_transform_fx( L_wtda_synth_fx, yorig_32, 0, L_FRAME16k, &new_input_fx_exp, st_fx->element_mode ); - /* Convert to 16 Bits (Calc Shift Required to Stay within MAX_Q_NEW_INPUT) */ - scl = sub( 16 + 8 /*MAX_Q_NEW_INPUT*/, new_input_fx_exp ); - /* Possible to Upscale? */ - IF( scl > 0 ) - { - /* Yes */ - /* Calc Room to Upscale */ - Q_synth = Find_Max_Norm32( yorig_32, L_FRAME16k ); - - /* Stay within MAX_Q_NEW_INPUT */ - scl = s_min( Q_synth, scl ); - } - Copy_Scale_sig32_16( yorig_32, yorig_fx, L_FRAME16k, scl ); - Q_synth = sub( add( sub( new_input_fx_exp, 16 ), scl ), 1 ); - - mode = WB_BWE_encoding_ivas_fx( st_fx, yorig_fx, WB_fenv_fx, Q_synth, Q_synth ); + mode = WB_BWE_encoding_ivas_fx( st_fx, yorig_32, WB_fenv_fx, new_input_fx_exp, new_input_fx_exp ); move16(); push_indice( st_fx->hBstr, IND_WB_CLASS, sub( mode, 2 ), 1 ); } @@ -2517,7 +2500,7 @@ Word16 WB_BWE_encoding_fx( /* o : classification of wb Word16 WB_BWE_encoding_ivas_fx( /* o : classification of wb signal */ Encoder_State *st_fx, /* i/o: Encoder structure */ - const Word16 *yos_fx, /* i : MDCT coefficients of weighted original */ + const Word32 *yos_fx, /* i : MDCT coefficients of weighted original */ Word16 *WB_fenv_fx, /* i/o: energy of WB envelope */ Word16 Q_synth, Word16 Q_synth_lf ) @@ -2531,35 +2514,48 @@ Word16 WB_BWE_encoding_ivas_fx( /* o : classification of Word16 ener_40, exp; Word32 L_tmp; Word16 tmp; - + Word64 energy_fx_64; + Word16 q_shift, scale; + Word16 q_WB_fenv[2]; + Word16 yos_fx_16[L_FRAME16k]; n_band = 0; move16(); FOR( i = 0; i < 2; i++ ) { - energy_fx = L_deposit_l( 0 ); + energy_fx_64 = 0; + move64(); FOR( n_coeff = swb_bwe_subband[n_band]; n_coeff < swb_bwe_subband[n_band + 2]; n_coeff++ ) { - energy_fx = L_add( energy_fx, L_shr( L_mult0( yos_fx[n_coeff], yos_fx[n_coeff] ), 6 ) ); /*2*Q_synth-6 */ + energy_fx_64 = W_add( energy_fx_64, W_mult0_32_32( yos_fx[n_coeff], yos_fx[n_coeff] ) ); /*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 ); L_WB_fenv_fx[i] = energy_fx; - move32(); /*2*Q_synth-6 */ + move32(); + q_WB_fenv[i] = add( shl( Q_synth, 1 ), q_shift ); + move16(); n_band = add( n_band, 2 ); } - mode = FD_BWE_class_fx( yos_fx, 0, 0, Q_synth, 0, st_fx ); - energy_control_ivas_fx( st_fx, ACELP_CORE, mode, st_fx->coder_type, yos_fx, 0, energy_factor_fx, Q_synth_lf ); + scale = s_min( L_norm_arr( yos_fx, L_FRAME16k ), sub( Q27, Q_synth ) /* To accomodate 10 in Q_synth*/ ); + Copy_Scale_sig32_16( yos_fx, yos_fx_16, L_FRAME16k, scale ); + + mode = FD_BWE_class_fx( yos_fx_16, 0, 0, sub( add( Q_synth, scale ), Q16 ), 0, st_fx ); + + energy_control_ivas_fx( st_fx, ACELP_CORE, mode, st_fx->coder_type, yos_fx_16, 0, energy_factor_fx, sub( add( Q_synth_lf, scale ), Q16 ) ); FOR( i = 0; i < 2; i++ ) { ener_40 = mult_r( shr( energy_factor_fx[shl( i, 1 )], 1 ), 26214 ); /*Q19 */ - L_tmp = Mpy_32_16_1( L_WB_fenv_fx[i], ener_40 ); /*2*Q_synth-2 */ + L_tmp = Mpy_32_16_1( L_WB_fenv_fx[i], ener_40 ); /*q_WB_fenv[i]+4 */ IF( L_tmp ) { exp = norm_l( L_tmp ); tmp = Log2_norm_lc( L_shl( L_tmp, exp ) ); - /*exp = 30-exp-(2*Q_synth-2); */ - exp = sub( sub( 30, exp ), ( sub( shl( Q_synth, 1 ), 2 ) ) ); + /*exp = 30-exp-(q_WB_fenv[i]+4); */ + exp = sub( sub( 30, exp ), ( add( q_WB_fenv[i], 4 ) ) ); L_tmp = Mpy_32_16( exp, tmp, 32767 ); /* Q16 */ WB_fenv_fx[i] = round_fx( L_shl( L_tmp, 10 ) ); /*Q10 */ move16();