From 7075df5192492960fe53b6fc67dc5e86d9c11f2b Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Sun, 19 Jan 2025 13:44:23 +0530 Subject: [PATCH 1/2] LTV crash fix for -10dB OMASA, warning fix and bug fix in swb_tbs_enc --- lib_enc/ivas_core_pre_proc.c | 9 +- lib_enc/swb_tbe_enc_fx.c | 272 +++++++++++++++++++++++++++++++++-- 2 files changed, 267 insertions(+), 14 deletions(-) diff --git a/lib_enc/ivas_core_pre_proc.c b/lib_enc/ivas_core_pre_proc.c index 8c2c31adb..848e26ce3 100644 --- a/lib_enc/ivas_core_pre_proc.c +++ b/lib_enc/ivas_core_pre_proc.c @@ -585,8 +585,13 @@ ivas_error pre_proc_ivas_fx( { return error; } - *epsP_fx_q = add( Q_r[0], 1 ); - move16(); + + test(); + IF( EQ_16( st->L_frame, L_FRAME16k ) && NE_16( element_mode, IVAS_CPE_MDCT ) ) + { + *epsP_fx_q = add( Q_r[0], 1 ); + move16(); + } } test(); IF( !( EQ_16( st->L_frame, L_FRAME16k ) && NE_16( element_mode, IVAS_CPE_MDCT ) ) ) diff --git a/lib_enc/swb_tbe_enc_fx.c b/lib_enc/swb_tbe_enc_fx.c index cb1151941..c18dd4155 100644 --- a/lib_enc/swb_tbe_enc_fx.c +++ b/lib_enc/swb_tbe_enc_fx.c @@ -63,6 +63,16 @@ static void EstimateSHBFrameGain_fx( const Word16 length, const Word16 *subwin_shb, const Word16 n_subfr_saturation ); +static void EstimateSHBFrameGain_ivas_fx( const Word16 length, + const Word16 *oriSHB, + const Word16 Q_oriSHB, + const Word16 *synSHB, + const Word16 Q_synSHB, + Word16 *subgain, + Word32 *GainFrame, + const Word16 *win_shb, + const Word16 *subwin_shb, + const Word16 n_subfr_saturation ); static void EstimateSHBGainShape_fx( const Word16 length, const Word16 *oriSHB, @@ -1198,7 +1208,7 @@ void wb_tbe_enc_fx( tmp = round_fx_o( L_tmp, &Overflow ); /* Q15 */ #else /* BASOP_NOGLOB */ L_tmp = L_shl( L_tmp, add( exp, 10 ) ); - tmp = round_fx( L_tmp ); /* Q15 */ + tmp = round_fx( L_tmp ); /* Q15 */ #endif } @@ -1243,6 +1253,7 @@ void wb_tbe_enc_fx( /* Adjust the subframe and frame gain of the synthesized SHB signal */ /* Scale the shaped excitation*/ + ScaleShapedSHB_fx( SHB_OVERLAP_LEN / 2, shaped_wb_excitation, hBWE_TD->syn_overlap_fx, GainShape, GainFrame, window_wb_fx, subwin_wb_fx, &Q_bwe_exc_ext, &dummy, dummy, dummy ); @@ -1377,7 +1388,7 @@ void wb_tbe_enc_ivas_fx( /* convert into lsps and calculate weights */ FOR( i = 0; i <= LPC_SHB_ORDER_WB; i++ ) { - lpc_wb_32_fx[i] = L_negate( L_deposit_h( L_shr( lpc_wb_temp_fx[i], 1 ) ) ); // Q27 + lpc_wb_32_fx[i] = L_negate( L_deposit_h( shr( lpc_wb_temp_fx[i], 1 ) ) ); // Q27 move32(); } @@ -1617,7 +1628,7 @@ void wb_tbe_enc_ivas_fx( #ifdef BASOP_NOGLOB prev_pow = L_shl_sat( 1407374848l /*0.00001f Q47*/, tmp ); /*Q_prev_pow*/ #else - prev_pow = L_shl( 1407374848l /*0.00001f Q47*/, tmp ); /*Q_prev_pow*/ + prev_pow = L_shl( 1407374848l /*0.00001f Q47*/, tmp ); /*Q_prev_pow*/ #endif } FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) @@ -1676,7 +1687,7 @@ void wb_tbe_enc_ivas_fx( #ifdef BASOP_NOGLOB curr_pow = L_shl_sat( 1407374848l /*0.00001f Q47*/, tmp ); /*Q(Q_cur_pow)*/ #else - curr_pow = L_shl( 1407374848l /*0.00001f Q47*/, tmp ); /* 2*(Q_bwe_exc_ext) */ + curr_pow = L_shl( 1407374848l /*0.00001f Q47*/, tmp ); /* 2*(Q_bwe_exc_ext) */ #endif } FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) @@ -1697,14 +1708,18 @@ void wb_tbe_enc_ivas_fx( #ifdef BASOP_NOGLOB shaped_wb_excitation[i] = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q_bwe_exc_ext */ #else - shaped_wb_excitation[i] = round_fx( L_shl( L_tmp, exp ) ); /* Q_bwe_exc_ext */ + shaped_wb_excitation[i] = round_fx( L_shl( L_tmp, exp ) ); /* Q_bwe_exc_ext */ #endif move16(); } Lscale = root_a_fx( Lscale, sub( 31, exp ), &exp ); - L_tmp = Mpy_32_16_1( Lscale, shaped_wb_excitation[L_SHB_LAHEAD / 4 - 1] ); /* Q(16-exp+Q_bwe_exc_ext) */ + L_tmp = Mpy_32_16_1( Lscale, shaped_wb_excitation[L_SHB_LAHEAD / 4 - 1] ); /* Q(16-exp+Q_bwe_exc_ext) */ +#ifdef BASOP_NOGLOB + shaped_wb_excitation[L_SHB_LAHEAD / 4 - 1] = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q_bwe_exc_ext */ +#else shaped_wb_excitation[L_SHB_LAHEAD / 4 - 1] = round_fx( L_shl( L_tmp, exp ) ); /* Q_bwe_exc_ext */ +#endif move16(); /* Update WB excitation */ @@ -1825,8 +1840,8 @@ void wb_tbe_enc_ivas_fx( } /* Estimate the gain parameter */ - EstimateSHBFrameGain_fx( SHB_OVERLAP_LEN / 2, hb_frame, Q_ns, shaped_wb_excitation, Q_bwe_exc_ext, GainShape, - &GainFrame, window_wb_fx, subwin_wb_fx, 0 ); + EstimateSHBFrameGain_ivas_fx( SHB_OVERLAP_LEN / 2, hb_frame, Q_ns, shaped_wb_excitation, Q_bwe_exc_ext, GainShape, + &GainFrame, window_wb_fx, subwin_wb_fx, 0 ); /* If there's a big difference in the power of gains away from the peak gain */ @@ -1909,9 +1924,14 @@ void wb_tbe_enc_ivas_fx( /* Adjust the subframe and frame gain of the synthesized SHB signal */ /* Scale the shaped excitation*/ + + scale_sig( shaped_wb_excitation, ( L_FRAME16k + L_SHB_LAHEAD ) / 4, -1 ); + scale_sig( hBWE_TD->syn_overlap_fx, L_SHB_LAHEAD, -1 ); + Q_bwe_exc_ext = sub( Q_bwe_exc_ext, 1 ); ScaleShapedSHB_fx( SHB_OVERLAP_LEN / 2, shaped_wb_excitation, hBWE_TD->syn_overlap_fx, GainShape, GainFrame, window_wb_fx, subwin_wb_fx, &Q_bwe_exc_ext, &dummy, dummy, dummy ); + Scale_sig( hBWE_TD->syn_overlap_fx, L_SHB_LAHEAD, 1 ); st_fx->prev_Q_bwe_exc = Q_bwe_exc; move16(); @@ -4122,8 +4142,8 @@ void swb_tbe_enc_ivas_fx( } /* Estimate the gain parameter */ - EstimateSHBFrameGain_fx( SHB_OVERLAP_LEN, shb_frame_fx, Q_shb, shaped_shb_excitation_fx, Q_bwe_exc, - GainShape_fx, &GainFrame_fx, window_shb_fx, subwin_shb_fx, n_subfr_saturation ); + EstimateSHBFrameGain_ivas_fx( SHB_OVERLAP_LEN, shb_frame_fx, Q_shb, shaped_shb_excitation_fx, Q_bwe_exc, + GainShape_fx, &GainFrame_fx, window_shb_fx, subwin_shb_fx, n_subfr_saturation ); IF( EQ_16( st_fx->tec_tfa, 1 ) ) { @@ -4475,7 +4495,6 @@ void swb_tbe_enc_ivas_fx( /* RETURN ARGUMENTS : */ /* _ None */ /*--------------------------------------------------------------------------*/ - static void EstimateSHBFrameGain_fx( const Word16 length, /* i : SHB overlap length */ const Word16 *oriSHB, /* i : target original SHB frame Q(Q_oriSHB) */ @@ -4688,7 +4707,7 @@ static void EstimateSHBFrameGain_fx( oriNrg = L_mac0_o( oriNrg, sig, sig, &Overflow ); /* 2*Q_oriSHB + 2*scaling */ #else sig = mult_r( shl( oriSHB[i], scaling ), win_shb[l_frame + l_shb_lahead - 1 - i] ); - oriNrg = L_mac0( oriNrg, sig, sig ); /* 2*Q_oriSHB + 2*scaling */ + oriNrg = L_mac0( oriNrg, sig, sig ); /* 2*Q_oriSHB + 2*scaling */ #endif } } @@ -4696,6 +4715,235 @@ static void EstimateSHBFrameGain_fx( exp_out = sub( exp_out, scaling ); #ifdef BASOP_NOGLOB frame_gain = L_shl_sat( L_tmp, sub( exp_out, 13 ) ); /* Q18 */ +#else + frame_gain = L_shl( L_tmp, sub( exp_out, 13 ) ); /* Q18 */ +#endif + *GainFrame = frame_gain; + move32(); + + return; +} + +static void EstimateSHBFrameGain_ivas_fx( + const Word16 length, /* i : SHB overlap length */ + const Word16 *oriSHB, /* i : target original SHB frame Q(Q_oriSHB) */ + const Word16 Q_oriSHB, /* i : Q of arget original SHB frame */ + const Word16 *synSHB, /* i : shaped SHB excitation Q(Q_synSHB) */ + const Word16 Q_synSHB, /* i : Q of shaped SHB excitation */ + Word16 *subgain, /* i : estimate of gain shape Q15 */ + Word32 *GainFrame, /* o : estimat of gain frame Q18 */ + const Word16 *win_shb, /* i : SHB window Q15 */ + const Word16 *subwin_shb_local, /* i : SHB subframe window Q15 */ + const Word16 n_subfr_saturation /* i : Number of subframes which saturated in GainShape oriNrg calculation */ +) +{ + const Word16 *skip; + Word16 i, j, k, l_shb_lahead, l_frame; + Word16 join_length, num_join, sig; + Word32 mod_syn[L_FRAME16k + L_SHB_LAHEAD]; + Word32 oriNrg, synNrg; + Word16 sum_gain; + Word32 frame_gain; + Word32 L_tmp; + Word16 exp_out; + Word16 tmp; + Word16 scaling = 0; +#ifdef BASOP_NOGLOB_DECLARE_LOCAL + Flag Overflow = 0; + move32(); +#endif + move16(); + + /* initilaization */ + l_frame = L_FRAME16k; + move16(); + l_shb_lahead = L_SHB_LAHEAD; + move16(); + skip = skip_bands_SWB_TBE; + + IF( EQ_16( length, SHB_OVERLAP_LEN / 2 ) ) + { + skip = skip_bands_WB_TBE; + l_frame = L_FRAME16k / 4; + move16(); + l_shb_lahead = L_SHB_LAHEAD / 4; + move16(); + } + + /* apply gain for each subframe, and store noise output signal using overlap-add*/ + set32_fx( mod_syn, 0, l_frame + l_shb_lahead ); + + IF( EQ_16( length, SHB_OVERLAP_LEN / 2 ) ) + { + sum_gain = 0; + move16(); + j = skip[0]; + move16(); + FOR( k = 0; k < length / 2; k++ ) + { + sum_gain = mult_r( subwin_shb_local[2 * k + 2], subgain[0] ); /* Q15 */ + mod_syn[j + k] = L_mult0( synSHB[j + k], sum_gain ); + move32(); /* Q(16+Q_synSHB) */ + mod_syn[j + k + length / 2] = L_mult0( synSHB[j + k + length / 2], subgain[0] ); + move32(); /* Q(16+Q_synSHB) */ + } + + FOR( i = 1; i < NUM_SHB_SUBFR / 2; i++ ) + { + j = skip[i]; + move16(); + FOR( k = 0; k < length; k++ ) + { + L_tmp = L_mult0( subwin_shb_local[k + 1], subgain[i] ); /* Q30 */ + sum_gain = round_fx( L_mac0( L_tmp, subwin_shb_local[length - k - 1], subgain[i - 1] ) ); /* Q14 */ + mod_syn[j + k] = L_mult( sum_gain, synSHB[j + k] ); + move32(); /* Q(16+Q_synSHB) */ + } + } + FOR( k = 0; k < length / 2; k++ ) + { + j = skip[i]; + move16(); + sum_gain = mult_r( subwin_shb_fx[length - 2 * k - 2], subgain[i - 1] ); /* Q15 */ + mod_syn[j + k] = L_mult0( synSHB[j + k], sum_gain ); + move32(); /* Q(16+Q_synSHB) */ + } + } + ELSE + { + num_join = NUM_SHB_SUBFR / NUM_SHB_SUBGAINS; + move16(); + join_length = i_mult2( num_join, length ); + j = 0; + move16(); + FOR( k = 0; k < length; k++ ) + { + sum_gain = mult_r( subwin_shb_local[k + 1], subgain[0] ); /* Q15 */ + mod_syn[j] = L_mult0( synSHB[j], sum_gain ); + move32(); /* Q(16+Q_synSHB) */ + j = add( j, 1 ); + } + FOR( i = 0; i < NUM_SHB_SUBGAINS - 1; i++ ) + { + FOR( k = 0; k < join_length - length; k++ ) + { + mod_syn[j] = L_mult0( synSHB[j], subgain[i * num_join] ); + move32(); /* Q(16+Q_synSHB) */ + j = add( j, 1 ); + } + + FOR( k = 0; k < length; k++ ) + { + L_tmp = L_mult0( subwin_shb_local[length - k - 1], subgain[i * num_join] ); + tmp = round_fx( L_mac0( L_tmp, subwin_shb_local[k + 1], subgain[( i + 1 ) * num_join] ) ); /* Q14 */ + mod_syn[j] = L_mult( tmp, synSHB[j] ); + move32(); /* Q(16+Q_synSHB) */ + j = add( j, 1 ); + } + } + FOR( k = 0; k < join_length - length; k++ ) + { + mod_syn[j] = L_mult0( synSHB[j], subgain[( NUM_SHB_SUBGAINS - 1 ) * num_join] ); + move32(); /* Q(16+Q_synSHB)*/ + j = add( j, 1 ); + } + FOR( k = 0; k < length; k++ ) + { + tmp = mult_r( subwin_shb_local[length - k - 1], subgain[( NUM_SHB_SUBGAINS - 1 ) * num_join] ); /* Q15 */ + mod_syn[j] = L_mult0( tmp, synSHB[j] ); + move32(); /* Q(16+Q_synSHB ) */ + j = add( j, 1 ); + } + } + /* adjust frame energy */ + oriNrg = L_deposit_l( 0 ); + synNrg = L_deposit_l( 0 ); + + FOR( i = 0; i < l_shb_lahead; i++ ) + { +#ifdef BASOP_NOGLOB + sig = mult_ro( oriSHB[i], win_shb[i], &Overflow ); /* Q_oriSHB */ + oriNrg = L_mac0_o( oriNrg, sig, sig, &Overflow ); /* 2*Q_orisHB*/ + sig = round_fx_o( Mult_32_16( mod_syn[i], win_shb[i] ), &Overflow ); /*Q_synSHB */ + synNrg = L_mac0_o( synNrg, sig, sig, &Overflow ); /* 2*Q_synSHB - 2*/ +#else + sig = mult_r( oriSHB[i], win_shb[i] ); /* Q_oriSHB */ + oriNrg = L_mac0( oriNrg, sig, sig ); /* 2*Q_orisHB*/ + sig = round_fx( Mult_32_16( mod_syn[i], win_shb[i] ) ); /*Q_synSHB */ + synNrg = L_mac0( synNrg, sig, sig ); /* 2*Q_synSHB */ +#endif + } + + FOR( ; i < l_frame; i++ ) + { +#ifdef BASOP_NOGLOB + oriNrg = L_mac0_o( oriNrg, oriSHB[i], oriSHB[i], &Overflow ); /* 2*Q_oriSHB */ + sig = round_fx_o( mod_syn[i], &Overflow ); /* Q_oriSHB */ + synNrg = L_mac0_o( synNrg, sig, sig, &Overflow ); /* 2*Q_oriSHB - 2*/ +#else + oriNrg = L_mac0( oriNrg, oriSHB[i], oriSHB[i] ); /* 2*Q_oriSHB */ + sig = round_fx( mod_syn[i] ); /* Q_oriSHB */ + synNrg = L_mac0( synNrg, sig, sig ); /* 2*Q_oriSHB */ +#endif + } + + tmp = add( l_frame, l_shb_lahead ); + FOR( ; i < tmp; i++ ) + { +#ifdef BASOP_NOGLOB + sig = mult_ro( oriSHB[i], win_shb[l_frame + l_shb_lahead - 1 - i], &Overflow ); /* Q_oriSHB */ + oriNrg = L_mac0_o( oriNrg, sig, sig, &Overflow ); /* 2*Q_oriSHB */ + + sig = round_fx_o( Mult_32_16( mod_syn[i], win_shb[l_frame + l_shb_lahead - 1 - i] ), &Overflow ); /* Q_oriSHB */ + synNrg = L_mac0_o( synNrg, sig, sig, &Overflow ); /* 2*Q_oriSHB - 2*/ +#else + sig = mult_r( oriSHB[i], win_shb[l_frame + l_shb_lahead - 1 - i] ); /* Q_oriSHB */ + oriNrg = L_mac0( oriNrg, sig, sig ); /* 2*Q_oriSHB */ + + sig = round_fx( Mult_32_16( mod_syn[i], win_shb[l_frame + l_shb_lahead - 1 - i] ) ); /* Q_oriSHB */ + synNrg = L_mac0( synNrg, sig, sig ); /* 2*Q_oriSHB */ +#endif + } + IF( EQ_32( oriNrg, MAX_32 ) ) + { + scaling = negate( add( shr( n_subfr_saturation, 1 ), 1 ) ); + oriNrg = 0; + move32(); + FOR( i = 0; i < l_shb_lahead; i++ ) + { +#ifdef BASOP_NOGLOB + sig = mult_r( shl_o( oriSHB[i], scaling, &Overflow ), win_shb[i] ); + oriNrg = L_mac0_o( oriNrg, sig, sig, &Overflow ); /* 2*Q_oriSHB + 2*scaling */ +#else + sig = mult_r( shl( oriSHB[i], scaling ), win_shb[i] ); + oriNrg = L_mac0( oriNrg, sig, sig ); /* 2*Q_oriSHB + 2*scaling */ +#endif + } + FOR( ; i < l_frame; i++ ) + { +#ifdef BASOP_NOGLOB + sig = shl_o( oriSHB[i], scaling, &Overflow ); + oriNrg = L_mac0_o( oriNrg, sig, sig, &Overflow ); /* 2*Q_oriSHB + 2*scaling */ +#else + sig = shl( oriSHB[i], scaling ); + oriNrg = L_mac0( oriNrg, sig, sig ); /* 2*Q_oriSHB + 2*scaling */ +#endif + } + FOR( ; i < tmp; i++ ) + { +#ifdef BASOP_NOGLOB + sig = mult_r( shl_o( oriSHB[i], scaling, &Overflow ), win_shb[l_frame + l_shb_lahead - 1 - i] ); + oriNrg = L_mac0_o( oriNrg, sig, sig, &Overflow ); /* 2*Q_oriSHB + 2*scaling */ +#else + sig = mult_r( shl( oriSHB[i], scaling ), win_shb[l_frame + l_shb_lahead - 1 - i] ); + oriNrg = L_mac0( oriNrg, sig, sig ); /* 2*Q_oriSHB + 2*scaling */ +#endif + } + } + L_tmp = root_a_over_b_fx( oriNrg, shl( Q_oriSHB, 1 ), synNrg, sub( shl( Q_synSHB, 1 ), 2 ), &exp_out ); + exp_out = sub( exp_out, scaling ); +#ifdef BASOP_NOGLOB + frame_gain = L_shl_sat( L_tmp, sub( exp_out, 13 ) ); /* Q18 */ #else frame_gain = L_shl( L_tmp, sub( exp_out, 13 ) ); /* Q18 */ #endif -- GitLab From fa1ef3d985153ac83505e44338db1821de073231 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Sun, 19 Jan 2025 13:50:56 +0530 Subject: [PATCH 2/2] Clang formatting --- lib_enc/swb_tbe_enc_fx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_enc/swb_tbe_enc_fx.c b/lib_enc/swb_tbe_enc_fx.c index c18dd4155..0772fc336 100644 --- a/lib_enc/swb_tbe_enc_fx.c +++ b/lib_enc/swb_tbe_enc_fx.c @@ -1208,7 +1208,7 @@ void wb_tbe_enc_fx( tmp = round_fx_o( L_tmp, &Overflow ); /* Q15 */ #else /* BASOP_NOGLOB */ L_tmp = L_shl( L_tmp, add( exp, 10 ) ); - tmp = round_fx( L_tmp ); /* Q15 */ + tmp = round_fx( L_tmp ); /* Q15 */ #endif } -- GitLab