diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index 8da9cd9ac117fdbe20bb7fe92661abc1c31b84b0..17566e3cb20bf02778690228d2fe096a13fdbbb6 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -2711,7 +2711,8 @@ void stereo_coder_tcx_fx( Word32 *inv_spectrum_fx[CPE_CHANNELS][NB_DIV], /* i/o: inverse spectrum */ Word32 *inv_mdst_spectrum_fx[CPE_CHANNELS][NB_DIV], /* i/o: inverse MDST spectrum */ const Word16 mct_on, /* i : flag mct block (1) or stereo (0) */ - Word16 q_spec ); + Word16 exp_spec, + Word16 exp_mdst_spec ); // bw_detect_fx.c Word16 set_bw_mct_fx( diff --git a/lib_enc/ivas_core_enc_fx.c b/lib_enc/ivas_core_enc_fx.c index 066d105d551b5ef1fa5aa1f16dd92ad07a1bf1bd..f5d3c4d73400b17391cda39f757af1481d8ee862 100644 --- a/lib_enc/ivas_core_enc_fx.c +++ b/lib_enc/ivas_core_enc_fx.c @@ -744,7 +744,7 @@ ivas_error ivas_core_enc_fx( IF( EQ_16( st->extl, FB_TBE ) ) { /* FB TBE encoder */ - fb_tbe_enc_ivas_fx( st, st->input_fx, fb_exc_fx, Q_fb_exc ); + fb_tbe_enc_ivas_fx( st, st->input_fx, fb_exc_fx, Q_fb_exc, st->q_inp ); } } } diff --git a/lib_enc/ivas_mct_enc_mct_fx.c b/lib_enc/ivas_mct_enc_mct_fx.c index 66bdb1235b492cfd383cd176295a6c5afbc656ee..aed6aefa4c2e1c4d6bce4e62c0923a448bd0a2b4 100644 --- a/lib_enc/ivas_mct_enc_mct_fx.c +++ b/lib_enc/ivas_mct_enc_mct_fx.c @@ -385,7 +385,7 @@ static void getBlockValues_fx( p_st[0] = sts[ch1]; p_st[1] = sts[ch2]; - stereo_coder_tcx_fx( hBlock->hStereoMdct, p_st, hBlock->mask, p_mdst_spectrum, p_inv_spectrum, p_inv_mdst_spectrum, 1, q_spec ); + stereo_coder_tcx_fx( hBlock->hStereoMdct, p_st, hBlock->mask, p_mdst_spectrum, p_inv_spectrum, p_inv_mdst_spectrum, 1, sub( 31, q_spec ), sub( 31, q_spec ) ); test(); test(); @@ -1073,6 +1073,7 @@ void mctStereoIGF_enc_fx( EQ_16( hMCT->hBlockData[b]->hStereoMdct->mdct_stereo_mode[n], SMDCT_BW_MS ) ) { Word16 exp_powerSpec_tmp[CPE_CHANNELS]; + Word16 exp_p_inv_spectrum[CPE_CHANNELS]; FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) { s = s_min( s, sub( 31, p_st[ch]->hTcxEnc->spectrum_e[n] ) ); @@ -1097,10 +1098,13 @@ void mctStereoIGF_enc_fx( } exp_powerSpec_tmp[0] = p_st[0]->hTcxEnc->spectrum_e[0]; exp_powerSpec_tmp[1] = p_st[1]->hTcxEnc->spectrum_e[0]; + exp_p_inv_spectrum[0] = exp_p_inv_spectrum[1] = p_st[0]->hTcxEnc->spectrum_e[0]; + move16(); + move16(); move16(); move16(); ProcessStereoIGF_fx( hMCT->hBlockData[b]->hStereoMdct, p_st, hMCT->hBlockData[b]->mask, p_orig_spectrum_fx, q_origSpec, q_origSpec, p_powerSpec_fx, exp_powerSpec_tmp, - p_powerSpecMsInv_fx, exp_powerSpec_tmp, p_inv_spectrum_fx, exp_powerSpec_tmp, n, sp_aud_decision0[ch1], p_st[0]->total_brate, 1 ); + p_powerSpecMsInv_fx, exp_powerSpec_tmp, p_inv_spectrum_fx, exp_p_inv_spectrum, n, sp_aud_decision0[ch1], p_st[0]->total_brate, 1 ); } ELSE { diff --git a/lib_enc/ivas_stereo_mdct_core_enc_fx.c b/lib_enc/ivas_stereo_mdct_core_enc_fx.c index 46134a27003ae2e970766643382ee84a84056feb..aa762a77c522ca298eacf8b1d5fe69be56853d31 100644 --- a/lib_enc/ivas_stereo_mdct_core_enc_fx.c +++ b/lib_enc/ivas_stereo_mdct_core_enc_fx.c @@ -152,8 +152,8 @@ void stereo_mdct_core_enc_fx( Word32 *p_mdst_spectrum_long_fx[CPE_CHANNELS]; Word32 mdst_spectrum_long_fx[CPE_CHANNELS][N_MAX]; Word32 *mdst_spectrum_fx[CPE_CHANNELS][NB_DIV]; - Word16 exp_powSpecMsInv[MCT_MAX_CHANNELS], q_spec, tmp_s; - Word16 tmp_q_powSpecInv[N_MAX], *tmp_q_psi[2]; + Word16 exp_powSpecMsInv[MCT_MAX_CHANNELS]; + Word16 tmp_q_powSpecInv[N_MAX], *exp_powSpecInv[2]; Word64 W_tmp; Encoder_State *st, **sts; STEREO_MDCT_ENC_DATA_HANDLE hStereoMdct; @@ -188,8 +188,8 @@ void stereo_mdct_core_enc_fx( set16_fx( tmp_q_powSpecInv, 63, N_MAX ); - tmp_q_psi[0] = tmp_q_powSpecInv; - tmp_q_psi[1] = &tmp_q_powSpecInv[N_TCX10_MAX]; + exp_powSpecInv[0] = tmp_q_powSpecInv; + exp_powSpecInv[1] = &tmp_q_powSpecInv[N_TCX10_MAX]; sts = hCPE->hCoreCoder; hStereoMdct = hCPE->hStereoMdct; @@ -343,61 +343,59 @@ void stereo_mdct_core_enc_fx( IF( !hStereoMdct->isSBAStereoMode ) { /* Common q for mdst_spectrum and spectrum */ - Word16 k; - q_spec = 0; + Word16 exp1, exp2; Word16 length; - FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) - { - FOR( k = 0; k <= ( ( sts[ch]->core == TCX_20_CORE ) ? 1 : NB_DIV ) - 1; k++ ) - { - q_spec = s_max( q_spec, sts[ch]->hTcxEnc->spectrum_e[k] ); - q_spec = s_max( q_spec, mdst_spectrum_e[ch][k] ); - } - } - q_spec = sub( Q31, q_spec ); /*find headroom to increase precision*/ - Word16 hdrm_min = MAX_16; + exp1 = MIN_16; + exp2 = MIN_16; + move16(); move16(); FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) { length = sts[ch]->hTcxEnc->spectrum_length; move16(); - IF( NE_16( sts[ch]->hTcxEnc->tcxMode, TCX_20 ) ) + if ( NE_16( sts[ch]->hTcxEnc->tcxMode, TCX_20 ) ) { length = shr( length, 1 ); } - hdrm_min = s_min( hdrm_min, L_norm_arr( sts[ch]->hTcxEnc->spectrum_fx[0], length ) ); - hdrm_min = s_min( hdrm_min, L_norm_arr( mdst_spectrum_fx[ch][0], length ) ); + exp1 = s_max( exp1, sub( sts[ch]->hTcxEnc->spectrum_e[0], L_norm_arr( sts[ch]->hTcxEnc->spectrum_fx[0], length ) ) ); + exp2 = s_max( exp2, sub( mdst_spectrum_e[ch][0], L_norm_arr( mdst_spectrum_fx[ch][0], length ) ) ); IF( NE_16( sts[ch]->hTcxEnc->tcxMode, TCX_20 ) ) { - hdrm_min = s_min( hdrm_min, L_norm_arr( sts[ch]->hTcxEnc->spectrum_fx[1], length ) ); - hdrm_min = s_min( hdrm_min, L_norm_arr( mdst_spectrum_fx[ch][1], length ) ); + exp1 = s_max( exp1, sub( sts[ch]->hTcxEnc->spectrum_e[1], L_norm_arr( sts[ch]->hTcxEnc->spectrum_fx[1], length ) ) ); + exp2 = s_max( exp2, sub( mdst_spectrum_e[ch][1], L_norm_arr( mdst_spectrum_fx[ch][1], length ) ) ); } } - q_spec = sub( add( hdrm_min, q_spec ), 1 ); /* 1 guard bit to avoid over-flows in stereo_coder_tcx_fx */ + exp1 = add( exp1, 1 ); /* 1 guard bit to avoid over-flows in stereo_coder_tcx_fx */ + exp2 = add( exp2, 1 ); /* 1 guard bit to avoid over-flows in stereo_coder_tcx_fx */ FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) { length = sts[ch]->hTcxEnc->spectrum_length; move16(); - IF( NE_16( sts[ch]->hTcxEnc->tcxMode, TCX_20 ) ) + if ( NE_16( sts[ch]->hTcxEnc->tcxMode, TCX_20 ) ) { length = shr( length, 1 ); } - FOR( k = 0; k <= ( ( sts[ch]->core == TCX_20_CORE ) ? 1 : NB_DIV ) - 1; k++ ) + + scale_sig32( sts[ch]->hTcxEnc->spectrum_fx[0], length, sub( sts[ch]->hTcxEnc->spectrum_e[0], exp1 ) ); /* exp1 */ + sts[ch]->hTcxEnc->spectrum_e[0] = exp1; + scale_sig32( mdst_spectrum_fx[ch][0], length, sub( mdst_spectrum_e[ch][0], exp2 ) ); /* exp2 */ + mdst_spectrum_e[ch][0] = exp2; + IF( NE_16( sts[ch]->hTcxEnc->tcxMode, TCX_20 ) ) { - Scale_sig32( sts[ch]->hTcxEnc->spectrum_fx[k], length, sub( q_spec, sub( Q31, sts[ch]->hTcxEnc->spectrum_e[k] ) ) ); /* q_spec */ - sts[ch]->hTcxEnc->spectrum_e[k] = sub( Q31, q_spec ); - Scale_sig32( mdst_spectrum_fx[ch][k], length, sub( q_spec, sub( Q31, mdst_spectrum_e[ch][k] ) ) ); /* q_spec */ - mdst_spectrum_e[ch][k] = sub( Q31, q_spec ); + scale_sig32( sts[ch]->hTcxEnc->spectrum_fx[1], length, sub( sts[ch]->hTcxEnc->spectrum_e[1], exp1 ) ); /* exp1 */ + sts[ch]->hTcxEnc->spectrum_e[1] = exp1; + scale_sig32( mdst_spectrum_fx[ch][1], length, sub( mdst_spectrum_e[ch][1], exp2 ) ); /* exp2 */ + mdst_spectrum_e[ch][1] = exp2; } } - stereo_coder_tcx_fx( hStereoMdct, sts, ms_mask, mdst_spectrum_fx, inv_spectrum_fx, inv_mdst_spectrum_fx, 0, q_spec ); - exp_inv_spectrum[0] = exp_inv_spectrum[1] = sub( Q31, q_spec ); + stereo_coder_tcx_fx( hStereoMdct, sts, ms_mask, mdst_spectrum_fx, inv_spectrum_fx, inv_mdst_spectrum_fx, 0, sts[0]->hTcxEnc->spectrum_e[0], mdst_spectrum_e[0][0] ); + exp_inv_spectrum[0] = exp_inv_spectrum[1] = sts[0]->hTcxEnc->spectrum_e[0]; move16(); move16(); } @@ -406,10 +404,13 @@ void stereo_mdct_core_enc_fx( * Power spectrum calculation *---------------------------------------------------------------*/ Word16 length, exp, shift1, shift2, norm; - Word32 mdct, mdst; + Word32 mdct, mdst, imdct, imdst; FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) { + L_subframeTCX = shr( sts[ch]->hTcxEnc->L_frameTCX, 1 ); /* Q0 */ + nSubframes = NB_DIV; + move16(); IF( EQ_16( sts[ch]->hTcxEnc->tcxMode, TCX_20 ) ) { nSubframes = 1; @@ -417,12 +418,6 @@ void stereo_mdct_core_enc_fx( move16(); move16(); } - ELSE - { - nSubframes = NB_DIV; - move16(); - L_subframeTCX = shr( sts[ch]->hTcxEnc->L_frameTCX, 1 ); /* Q0 */ - } /* in MCT only relevant for bitrate switching from non-MCT bitrates */ IF( EQ_16( sts[ch]->last_core, ACELP_CORE ) ) @@ -432,8 +427,6 @@ void stereo_mdct_core_enc_fx( FOR( n = 0; n < nSubframes; n++ ) { - q_spec = sub( 31, sts[ch]->hTcxEnc->spectrum_e[n] ); - IF( sts[ch]->hTcxEnc->tns_ms_flag[n] ) { exp = add( s_max( mdst_spectrum_e[ch][n], sts[ch]->hTcxEnc->spectrum_e[n] ), 1 ); @@ -443,16 +436,18 @@ void stereo_mdct_core_enc_fx( /* power spectrum: MDCT^2 + MDST^2 */ FOR( i = 0; i < L_subframeTCX; i++ ) { - W_tmp = W_mac_32_32( W_mult_32_32( inv_mdst_spectrum_fx[ch][n][i], inv_mdst_spectrum_fx[ch][n][i] ), inv_spectrum_fx[ch][n][i], inv_spectrum_fx[ch][n][i] ); /* 2*q_spec+1 */ - tmp_s = W_norm( W_tmp ); - W_tmp = W_shl( W_tmp, tmp_s ); /* 2*q_spec+1+tmp_s */ - powerSpecMsInv_fx[ch][n][i] = W_extract_h( W_tmp ); /* 2*q_spec+1+tmp_s-32 */ - tmp_q_psi[n][i] = sub( add( imult1616( q_spec, 2 ), tmp_s ), 31 ); // Q = 2 * q_spec + 1 + tmp_s - 32 + mdst = L_shl( mdst_spectrum_fx[ch][n][i], shift1 ); // exp: exp + mdct = L_shl( sts[ch]->hTcxEnc->spectrum_fx[n][i], shift2 ); // exp: exp + imdst = L_shl( inv_mdst_spectrum_fx[ch][n][i], shift1 ); // exp: exp + imdct = L_shl( inv_spectrum_fx[ch][n][i], shift2 ); // exp: exp + + W_tmp = W_mac_32_32( W_mult_32_32( imdct, imdct ), imdst, imdst ); // exp: 2*exp + norm = W_norm( W_tmp ); + powerSpecMsInv_fx[ch][n][i] = W_extract_h( W_shl( W_tmp, norm ) ); // exp: 2*exp-norm + exp_powSpecInv[n][i] = sub( shl( exp, 1 ), norm ); move32(); move16(); - mdst = L_shl( mdst_spectrum_fx[ch][n][i], shift1 ); // exp: exp - mdct = L_shl( sts[ch]->hTcxEnc->spectrum_fx[n][i], shift2 ); // exp: exp powerSpec64[ch][i + n * L_subframeTCX] = W_mac_32_32( W_mult_32_32( mdct, mdct ), mdst, mdst ); // exp: 2*exp move64(); } @@ -464,32 +459,28 @@ void stereo_mdct_core_enc_fx( IF( NE_16( hStereoMdct->mdct_stereo_mode[n], SMDCT_DUAL_MONO ) ) { /* power spectrum: MDCT^2 + MDST^2 */ - W_tmp = W_mult_32_32( inv_spectrum_fx[ch][n][0], inv_spectrum_fx[ch][n][0] ); /* 2*q_spec+1 */ - tmp_s = W_norm( W_tmp ); - W_tmp = W_shl( W_tmp, tmp_s ); /* 2*q_spec+1+tmp_s */ - powerSpecMsInv_fx[ch][n][0] = W_extract_h( W_tmp ); /* 2*q_spec+1+tmp_s-32 */ - tmp_q_psi[n][0] = sub( add( imult1616( q_spec, 2 ), tmp_s ), 31 ); // Q = 2 * q_spec + 1 + tmp_s - 32 + W_tmp = W_mult_32_32( inv_spectrum_fx[ch][n][0], inv_spectrum_fx[ch][n][0] ); // exp: 2*sts[ch]->hTcxEnc->spectrum_e[n] + norm = W_norm( W_tmp ); + powerSpecMsInv_fx[ch][n][0] = W_extract_h( W_shl( W_tmp, norm ) ); // exp: 2*sts[ch]->hTcxEnc->spectrum_e[n]-norm + exp_powSpecInv[n][0] = sub( shl( sts[ch]->hTcxEnc->spectrum_e[n], 1 ), norm ); move32(); move16(); FOR( i = 1; i < L_subframeTCX - 1; i++ ) { - Word32 mdst_fx = L_sub( inv_spectrum_fx[ch][n][i + 1], inv_spectrum_fx[ch][n][i - 1] ); /* An MDST estimate q_spec*/ - - W_tmp = W_mac_32_32( W_mult_32_32( mdst_fx, mdst_fx ), inv_spectrum_fx[ch][n][i], inv_spectrum_fx[ch][n][i] ); /* 2*q_spec+1 */ - tmp_s = W_norm( W_tmp ); - W_tmp = W_shl( W_tmp, tmp_s ); /* 2*q_spec+1+tmp_s */ - powerSpecMsInv_fx[ch][n][i] = W_extract_h( W_tmp ); /* 2*q_spec+1+tmp_s-32 */ - tmp_q_psi[n][i] = sub( add( imult1616( q_spec, 2 ), tmp_s ), 31 ); // Q = 2 * q_spec + 1 + tmp_s - 32 + Word32 mdst_fx = L_sub( inv_spectrum_fx[ch][n][i + 1], inv_spectrum_fx[ch][n][i - 1] ); // exp: sts[ch]->hTcxEnc->spectrum_e[n] + W_tmp = W_mac_32_32( W_mult_32_32( mdst_fx, mdst_fx ), inv_spectrum_fx[ch][n][i], inv_spectrum_fx[ch][n][i] ); // exp: 2*sts[ch]->hTcxEnc->spectrum_e[n] + norm = W_norm( W_tmp ); + powerSpecMsInv_fx[ch][n][i] = W_extract_h( W_shl( W_tmp, norm ) ); // exp: 2*sts[ch]->hTcxEnc->spectrum_e[n]-norm + exp_powSpecInv[n][i] = sub( shl( sts[ch]->hTcxEnc->spectrum_e[n], 1 ), norm ); move32(); move16(); } - W_tmp = W_mult_32_32( inv_spectrum_fx[ch][n][L_subframeTCX - 1], inv_spectrum_fx[ch][n][L_subframeTCX - 1] ); /* 2*q_spec+1 */ - tmp_s = W_norm( W_tmp ); - W_tmp = W_shl( W_tmp, tmp_s ); /* 2*q_spec+1+tmp_s */ - powerSpecMsInv_fx[ch][n][L_subframeTCX - 1] = W_extract_h( W_tmp ); /* 2*q_spec+1+tmp_s-32 */ - tmp_q_psi[n][L_subframeTCX - 1] = sub( add( imult1616( q_spec, 2 ), tmp_s ), 31 ); // Q = 2 * q_spec + 1 + tmp_s - 32 + W_tmp = W_mult_32_32( inv_spectrum_fx[ch][n][L_subframeTCX - 1], inv_spectrum_fx[ch][n][L_subframeTCX - 1] ); // exp: 2*sts[ch]->hTcxEnc->spectrum_e[n] + norm = W_norm( W_tmp ); + powerSpecMsInv_fx[ch][n][L_subframeTCX - 1] = W_extract_h( W_shl( W_tmp, norm ) ); // exp: 2*sts[ch]->hTcxEnc->spectrum_e[n]-norm + exp_powSpecInv[n][L_subframeTCX - 1] = sub( shl( sts[ch]->hTcxEnc->spectrum_e[n], 1 ), norm ); move32(); move16(); } @@ -517,30 +508,31 @@ void stereo_mdct_core_enc_fx( } /* Aligning the Q-factors */ + exp = MIN_16; + move16(); + FOR( n = 0; n < nSubframes; n++ ) { - Word16 q_temp = Q31; - move16(); - FOR( n = 0; n < nSubframes; n++ ) + FOR( i = 0; i < L_subframeTCX; i++ ) { - FOR( i = 0; i < L_subframeTCX; i++ ) + if ( powerSpecMsInv_fx[ch][n][i] != 0 ) { - if ( powerSpecMsInv_fx[ch][n][i] != 0 ) - { - q_temp = s_min( q_temp, tmp_q_psi[n][i] ); - } + exp = s_max( exp, exp_powSpecInv[n][i] ); } } + } + IF( NE_16( exp, MIN_16 ) ) + { FOR( n = 0; n < nSubframes; n++ ) { FOR( i = 0; i < L_subframeTCX; i++ ) { - powerSpecMsInv_fx[ch][n][i] = L_shr_sat( powerSpecMsInv_fx[ch][n][i], sub( tmp_q_psi[n][i], q_temp ) ); + powerSpecMsInv_fx[ch][n][i] = L_shl( powerSpecMsInv_fx[ch][n][i], sub( exp_powSpecInv[n][i], exp ) ); move32(); } } - exp_powSpecMsInv[ch] = sub( Q31, q_temp ); - move16(); } + exp_powSpecMsInv[ch] = exp; + move16(); } FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) diff --git a/lib_enc/ivas_stereo_mdct_stereo_enc_fx.c b/lib_enc/ivas_stereo_mdct_stereo_enc_fx.c index b1eae78622015239c7242dbc896b441e04e2dffe..2f1b7d6c8d6a37248247971dece778020c06e8e5 100644 --- a/lib_enc/ivas_stereo_mdct_stereo_enc_fx.c +++ b/lib_enc/ivas_stereo_mdct_stereo_enc_fx.c @@ -190,7 +190,8 @@ void stereo_coder_tcx_fx( Word32 *inv_mdst_spectrum_fx[CPE_CHANNELS][NB_DIV], /* i/o: inverse MDST spectrum */ // Q( q_spec ) (same as spectrum buffer in hTcxEnc) const Word16 mct_on, /* i : flag mct block (1) or stereo (0) Q0*/ - Word16 q_spec ) + Word16 exp_spec, + Word16 exp_mdct_spec ) { STEREO_MDCT_BAND_PARAMETERS *sfbConf = NULL; Word32 nrgRatio_fx[CPE_CHANNELS]; @@ -255,8 +256,8 @@ void stereo_coder_tcx_fx( tmp = Inv16( extract_h( nrgRatio_fx[k] ), &e_tmp ); /* Q15-e_tmp */ tmp = shl( tmp, e_tmp ); /* Q15 */ - v_multc_fixed_16( sts[1]->hTcxEnc->spectrum_fx[k], tmp, sts[1]->hTcxEnc->spectrum_fx[k], L_frameTCX ); /* Q31-spectrum_e[k] */ - v_multc_fixed_16( mdst_spectrum_fx[1][k], tmp, mdst_spectrum_fx[1][k], L_frameTCX ); /* q_spec */ + v_multc_fixed_16( sts[1]->hTcxEnc->spectrum_fx[k], tmp, sts[1]->hTcxEnc->spectrum_fx[k], L_frameTCX ); /* exp: exp_spec */ + v_multc_fixed_16( mdst_spectrum_fx[1][k], tmp, mdst_spectrum_fx[1][k], L_frameTCX ); /* exp: exp_mdct_spec */ } ELSE IF( EQ_16( BASOP_Util_Cmp_Mant32Exp( nrgRatio_fx[k], nrgRatio_e[k], ONE_IN_Q27, 4 ), -1 ) && LT_16( k, EQ_16( sts[0]->core, TCX_20_CORE ) ? 1 : NB_DIV ) ) { @@ -264,8 +265,8 @@ void stereo_coder_tcx_fx( L_frameTCX = idiv1616( L_frameTCX, ( sts[0]->core == TCX_20_CORE ) ? 1 : NB_DIV ); /* Q0 */ /* This operation is resulting in some high MLDs in fixed point. */ - v_multc_fixed_16( sts[0]->hTcxEnc->spectrum_fx[k], extract_l( L_shr( nrgRatio_fx[k], 16 - nrgRatio_e[k] ) ), sts[0]->hTcxEnc->spectrum_fx[k], L_frameTCX ); /* Q31-spectrum_e[k] */ - v_multc_fixed_16( mdst_spectrum_fx[0][k], extract_l( L_shr( nrgRatio_fx[k], 16 - nrgRatio_e[k] ) ), mdst_spectrum_fx[0][k], L_frameTCX ); /* q_spec */ + v_multc_fixed_16( sts[0]->hTcxEnc->spectrum_fx[k], extract_l( L_shr( nrgRatio_fx[k], 16 - nrgRatio_e[k] ) ), sts[0]->hTcxEnc->spectrum_fx[k], L_frameTCX ); /* exp: exp_spec */ + v_multc_fixed_16( mdst_spectrum_fx[0][k], extract_l( L_shr( nrgRatio_fx[k], 16 - nrgRatio_e[k] ) ), mdst_spectrum_fx[0][k], L_frameTCX ); /* exp: exp_mdct_spec */ } } } @@ -356,7 +357,7 @@ void stereo_coder_tcx_fx( move16(); const Word16 sfbWidth = sub( endLine, startLine ); - nrgRatio_e[0] = nrgRatio_e[1] = sub( Q31, q_spec ); + nrgRatio_e[0] = nrgRatio_e[1] = exp_spec; move16(); move16(); @@ -370,10 +371,12 @@ void stereo_coder_tcx_fx( { Word32 tmp_fx; Word16 tmp_e; - tmp_e = sub( Q31, q_spec ); + tmp_e = exp_mdct_spec; + move16(); tmp_fx = sum2_32_fx( &mdst_spectrum_fx[0][k][startLine], sfbWidth, &tmp_e ); /* Q31-tmp_e */ nrgRatio_fx[0] = BASOP_Util_Add_Mant32Exp( nrgRatio_fx[0], nrgRatio_e[0], tmp_fx, tmp_e, &nrgRatio_e[0] ); /* Q31-nrgRatio_e[0] */ - tmp_e = sub( Q31, q_spec ); + tmp_e = exp_mdct_spec; + move16(); tmp_fx = sum2_32_fx( &mdst_spectrum_fx[1][k][startLine], sfbWidth, &tmp_e ); /* Q31-tmp_e */ nrgRatio_fx[1] = BASOP_Util_Add_Mant32Exp( nrgRatio_fx[1], nrgRatio_e[1], tmp_fx, tmp_e, &nrgRatio_e[1] ); /* Q31-nrgRatio_e[1] */ } @@ -426,15 +429,15 @@ void stereo_coder_tcx_fx( move32(); - v_multc_fixed( &sts[0]->hTcxEnc->spectrum_fx[k][startLine], nrgRatio_fx[0], &sts[0]->hTcxEnc->spectrum_fx[k][startLine], sfbWidth ); /* q_spec+30-31 */ - v_multc_fixed( &mdst_spectrum_fx[0][k][startLine], nrgRatio_fx[0], &mdst_spectrum_fx[0][k][startLine], sfbWidth ); /* q_spec+30-31 */ - scale_sig32( &sts[0]->hTcxEnc->spectrum_fx[k][startLine], sfbWidth, Q1 ); // Scaling back to q_spec - scale_sig32( &mdst_spectrum_fx[0][k][startLine], sfbWidth, Q1 ); // Scaling back to q_spec + v_multc_fixed( &sts[0]->hTcxEnc->spectrum_fx[k][startLine], nrgRatio_fx[0], &sts[0]->hTcxEnc->spectrum_fx[k][startLine], sfbWidth ); /* exp: exp_spec+1 */ + v_multc_fixed( &mdst_spectrum_fx[0][k][startLine], nrgRatio_fx[0], &mdst_spectrum_fx[0][k][startLine], sfbWidth ); /* exp: exp_mdct_spec+1 */ + scale_sig32( &sts[0]->hTcxEnc->spectrum_fx[k][startLine], sfbWidth, Q1 ); // exp: exp_spec + scale_sig32( &mdst_spectrum_fx[0][k][startLine], sfbWidth, Q1 ); // exp: exp_mdct_spec - v_multc_fixed( &sts[1]->hTcxEnc->spectrum_fx[k][startLine], nrgRatio_fx[1], &sts[1]->hTcxEnc->spectrum_fx[k][startLine], sfbWidth ); /* q_spec+30-31 */ - v_multc_fixed( &mdst_spectrum_fx[1][k][startLine], nrgRatio_fx[1], &mdst_spectrum_fx[1][k][startLine], sfbWidth ); /* q_spec+30-31 */ - scale_sig32( &sts[1]->hTcxEnc->spectrum_fx[k][startLine], sfbWidth, Q1 ); // Scaling back to q_spec - scale_sig32( &mdst_spectrum_fx[1][k][startLine], sfbWidth, Q1 ); // Scaling back to q_spec + v_multc_fixed( &sts[1]->hTcxEnc->spectrum_fx[k][startLine], nrgRatio_fx[1], &sts[1]->hTcxEnc->spectrum_fx[k][startLine], sfbWidth ); /* exp: exp_spec+1 */ + v_multc_fixed( &mdst_spectrum_fx[1][k][startLine], nrgRatio_fx[1], &mdst_spectrum_fx[1][k][startLine], sfbWidth ); /* exp: exp_mdct_spec+1 */ + scale_sig32( &sts[1]->hTcxEnc->spectrum_fx[k][startLine], sfbWidth, Q1 ); // exp: exp_spec + scale_sig32( &mdst_spectrum_fx[1][k][startLine], sfbWidth, Q1 ); // exp: exp_mdct_spec } } } @@ -469,11 +472,11 @@ void stereo_coder_tcx_fx( nAvailBitsMS[k] = idiv1616( nAvailBitsMS[k], nSubframes ); /* Q0 */ move16(); - MsStereoDecision_fx( sfbConf, sts[0]->hTcxEnc->spectrum_fx[k], sts[1]->hTcxEnc->spectrum_fx[k], inv_spectrum_fx[0][k], inv_spectrum_fx[1][k], q_spec, &hStereoMdct->mdct_stereo_mode[k], &ms_mask[k][0], nAvailBitsMS[k] ); + MsStereoDecision_fx( sfbConf, sts[0]->hTcxEnc->spectrum_fx[k], sts[1]->hTcxEnc->spectrum_fx[k], inv_spectrum_fx[0][k], inv_spectrum_fx[1][k], sub( Q31, exp_spec ), &hStereoMdct->mdct_stereo_mode[k], &ms_mask[k][0], nAvailBitsMS[k] ); IF( sts[0]->igf ) { - IGFEncStereoEncoder_fx( sfbConf, sts[0]->hIGFEnc, sts[0]->hTcxEnc->spectrum_fx[k], sts[1]->hTcxEnc->spectrum_fx[k], q_spec, &ms_mask[k][0], + IGFEncStereoEncoder_fx( sfbConf, sts[0]->hIGFEnc, sts[0]->hTcxEnc->spectrum_fx[k], sts[1]->hTcxEnc->spectrum_fx[k], sub( Q31, exp_spec ), &ms_mask[k][0], &hStereoMdct->IGFStereoMode[k], hStereoMdct->mdct_stereo_mode[k], (Word16) EQ_16( sts[0]->core, TCX_20_CORE ), (Word16) EQ_16( sts[0]->last_core, ACELP_CORE ) ); } ELSE diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index d9389eb9c6a476898a4b238cfbc84aa70c4f673a..73ec00cbda0c7f3d9eb115182960774279079e15 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -216,9 +216,10 @@ void fb_tbe_enc_fx( void fb_tbe_enc_ivas_fx( Encoder_State *st, /* i/o: encoder state structure */ - const Word16 new_input[], /* i : i speech at 48 kHz sample rate Q0*/ + const Word16 new_input[], /* i : i speech at 48 kHz sample rate Q_new_input*/ const Word16 fb_exc[], /* i : FB excitation from the SWB part Q_fb_exc*/ - Word16 Q_fb_exc ); + Word16 Q_fb_exc, + Word16 Q_new_input ); void fb_tbe_reset_enc_fx( Word32 elliptic_bpf_2_48k_mem_fx[][4], diff --git a/lib_enc/swb_tbe_enc_fx.c b/lib_enc/swb_tbe_enc_fx.c index 316a5b5494e613ab5cf8ed39e651ca6c57ff478e..633ede535775d594e9912f67cab67c34ae15ac16 100644 --- a/lib_enc/swb_tbe_enc_fx.c +++ b/lib_enc/swb_tbe_enc_fx.c @@ -7415,9 +7415,10 @@ void fb_tbe_enc_fx( void fb_tbe_enc_ivas_fx( Encoder_State *st, /* i/o: encoder state structure */ - const Word16 new_input[], /* i : input speech at 48 kHz sample rate Q0 */ + const Word16 new_input[], /* i : input speech at 48 kHz sample rate Q_new_input */ const Word16 fb_exc[], /* i : FB excitation from the SWB part Q_fb_exc */ - Word16 Q_fb_exc ) + Word16 Q_fb_exc, + Word16 Q_new_input ) { Word16 ratio; Word16 tmp_vec[L_FRAME48k]; @@ -7446,7 +7447,7 @@ void fb_tbe_enc_ivas_fx( } Copy_Scale_sig( new_input - NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), input_fhb_new, L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), exp_temp ); - + exp_temp = add( exp_temp, Q_new_input ); IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) ) { elliptic_bpf_48k_generic_fx( input_fhb_new, &exp_temp, tmp_vec, hBWE_TD->elliptic_bpf_2_48k_mem_fx, hBWE_TD->elliptic_bpf_2_48k_mem_fx_Q, full_band_bpf_2_fx );