diff --git a/lib_enc/speech_music_classif_fx.c b/lib_enc/speech_music_classif_fx.c index 65000a7b3f444acf3256676c1840db27129c5681..817e5fb70a5782fc5c56d32aab9605d3abb3dc30 100644 --- a/lib_enc/speech_music_classif_fx.c +++ b/lib_enc/speech_music_classif_fx.c @@ -2612,7 +2612,7 @@ static Word16 attack_det_ivas_fx( /* o : attack flag Word16 *last_strong_attack /* i/o: last strong attack flag */ ) { - Word16 i, j, tmp, tmp1, attack, exp1; + Word16 i, j, tmp, tmp1, attack, exp1, etmp_e, etmp2_e, s; Word32 L_tmp, etmp, etmp2, finc[ATT_NSEG], mean_finc; Word16 att_3lsub_pos; Word16 attack1; @@ -2665,29 +2665,42 @@ static Word16 attack_det_ivas_fx( /* o : attack flag exp1 = norm_s( att_3lsub_pos ); tmp = div_s( shl( 1, sub( 14, exp1 ) ), att_3lsub_pos ); /*Q(29-exp1) */ - L_tmp = L_shr_o( finc[0], Qx, &Overflow ); /*Qx */ - - FOR( i = 1; i < att_3lsub_pos; i++ ) + W_tmp = 0; + move64(); + FOR( i = 0; i < att_3lsub_pos; i++ ) { - L_tmp = L_add_o( L_tmp, L_shr_o( finc[i], Qx, &Overflow ), &Overflow ); /*Qx */ + W_tmp = W_add( W_tmp, finc[i] ); /* *q_ finc_prev */ } - L_tmp = Mult_32_16( L_tmp, tmp ); /*Q(14-exp1+Qx) */ - etmp = L_shl( L_tmp, sub( exp1, 14 ) ); /*Qx */ + s = W_norm( W_tmp ); + L_tmp = W_extract_h( W_shl( W_tmp, s ) ); // *q_finc_prev + s - 32 + + L_tmp = Mpy_32_16_1( L_tmp, tmp ); /* *q_finc_prev + s - 32 + Q29 - exp1 - 15 => *q_finc_prev + s - exp1 - 18 */ + etmp = L_tmp; + move32(); + etmp_e = sub( 31, add( *q_finc_prev, sub( s, add( exp1, 18 ) ) ) ); + tmp1 = sub( ATT_NSEG, attack ); exp1 = norm_s( tmp1 ); tmp = div_s( shl( 1, sub( 14, exp1 ) ), tmp1 ); /*Q(29-exp1) */ - L_tmp = L_shr_o( finc[attack], Qx, &Overflow ); /*Qx */ - FOR( i = 1; i < tmp1; i++ ) + W_tmp = 0; + move64(); + FOR( i = 0; i < tmp1; i++ ) { - L_tmp = L_add_o( L_tmp, L_shr_o( finc[i + attack], Qx, &Overflow ), &Overflow ); /*Qx */ + W_tmp = W_add( W_tmp, finc[i + attack] ); /* *q_finc_prev */ } - L_tmp = Mult_32_16( L_tmp, tmp ); /*Q(14-exp1+Qx) */ - etmp2 = L_shl( L_tmp, sub( exp1, 14 ) ); /*Qx */ + s = W_norm( W_tmp ); + L_tmp = W_extract_h( W_shl( W_tmp, s ) ); // *q_finc_prev + s - 32 + + L_tmp = Mpy_32_16_1( L_tmp, tmp ); /* *q_finc_prev + s - 32 + Q29 - exp1 - 15 => *q_finc_prev + s - exp1 - 18 */ + etmp2 = L_tmp; + move32(); + etmp2_e = sub( 31, add( *q_finc_prev, sub( s, add( exp1, 18 ) ) ) ); /* and compare them */ - if ( GT_32( etmp, L_shr( etmp2, 3 ) ) ) + /* if ( etmp * 8 > etmp2 ) */ + if ( BASOP_Util_Cmp_Mant32Exp( etmp, add( etmp_e, 3 ), etmp2, etmp2_e ) > 0 ) { /* stop, if the attack is not sufficiently strong */ attack = 0; @@ -2695,7 +2708,8 @@ static Word16 attack_det_ivas_fx( /* o : attack flag } test(); - if ( EQ_16( last_clas, VOICED_CLAS ) && GT_32( L_add( L_shl( etmp, 4 ), L_shl( etmp, 2 ) ), etmp2 ) ) + /* if ( last_clas == VOICED_CLAS && etmp * 20 > etmp2 ) */ + if ( EQ_16( last_clas, VOICED_CLAS ) && BASOP_Util_Cmp_Mant32Exp( etmp, etmp_e, Mpy_32_16_1( etmp2, 1638 /* 1/20 in Q15 */ ), etmp2_e ) > 0 ) { /* stop, if the signal was voiced and the attack is not sufficiently strong */ attack = 0;