diff --git a/apps/renderer.c b/apps/renderer.c index 242b80fbfe49420e6d0397a4221e4c1de5b96985..5917e4d29a89aa14e3ce6f240e3a3a4134bdb634 100644 --- a/apps/renderer.c +++ b/apps/renderer.c @@ -49,6 +49,7 @@ #include "split_rend_bfi_file_reader.h" #include "vector3_pair_file_reader.h" #include "wmc_auto.h" +#include "basop32.h" #define WMC_TOOL_SKIP diff --git a/lib_com/basop32.c b/lib_com/basop32.c index 6a34cff43e570ae4a6a3212891067ca5887bef48..eebc1684915ccba9a062a49f561a112f2208d36d 100644 --- a/lib_com/basop32.c +++ b/lib_com/basop32.c @@ -1268,7 +1268,7 @@ Word16 round_fx( Word32 L_var1 ) Word32 L_rounded; BASOP_SATURATE_WARNING_OFF - L_rounded = L_add( L_var1, (Word32) 0x00008000L ); + L_rounded = L_add_sat( L_var1, (Word32) 0x00008000L ); BASOP_SATURATE_WARNING_ON var_out = extract_h( L_rounded ); diff --git a/lib_com/basop_util.c b/lib_com/basop_util.c index ee959cf6f3320476902e45215ee49b6872d4ed69..bb92e286f399aa6f44d24ccab9abc17adb05ae18 100644 --- a/lib_com/basop_util.c +++ b/lib_com/basop_util.c @@ -2085,6 +2085,8 @@ Word32 norm_llQ31( /* o : normalized result Q31 */ return L_sum; } +#ifndef FIX_ISSUE_1817_REPLACE_CARRY_OVERFLOW +/* note: now available in basop_util.h */ Word32 w_norm_llQ31( Word64 L_sum, Word16 *exp ); Word32 w_norm_llQ31( /* o : normalized result Q31 */ Word64 L_sum, /* i : upper and lower bits of accu, unsigned Q31 */ @@ -2111,6 +2113,7 @@ Word32 w_norm_llQ31( /* o : normalized result Q31 */ L_tmp = W_extract_h( L64_inp64 ); return L_tmp; } +#endif Word32 Dot_product16HQ( /* o : normalized result Q31 */ const Word32 L_off, /* i : initial sum value Qn */ @@ -2135,6 +2138,24 @@ Word32 Dot_product16HQ( /* o : normalized result return L_sum; } +Word32 sum_array_norm( /* o : normalized result Q31 */ + const Word32 x[], /* i : x vector Qn */ + const Word16 lg, /* i : vector length, range [0..7FFF] Q0 */ + Word16 *exp /* o : exponent of result in [-32,31] Q0 */ +) +{ + Word16 i; + Word64 W_tmp = 0; + Word32 L_tmp; + FOR( i = 0; i < lg; i++ ) + { + W_tmp = W_add( W_tmp, x[i] ); /*Q31*/ + } + L_tmp = w_norm_llQ31( W_tmp, exp ); /*Q31 - *exp*/ + return L_tmp; +} + + Word32 Norm32Norm( const Word32 *x, const Word16 headroom, const Word16 length, Word16 *result_e ) { Word32 L_tmp, L_tmp2; diff --git a/lib_com/basop_util.h b/lib_com/basop_util.h index c95bf8100c976ed26819a27e1141278398ee098a..0a82d112d46338b3259f53939c4f40407ff980f3 100644 --- a/lib_com/basop_util.h +++ b/lib_com/basop_util.h @@ -612,6 +612,20 @@ Word32 Dot_product16HQ( /* #include #include "prot_fx.h" +#include "options.h" #include "basop_util.h" #include "stl.h" -#include "options.h" #include "math.h" #include "ivas_prot_fx.h" #include "rom_com.h" @@ -1859,6 +1859,7 @@ static Word32 CalculateAbsEnergy_fx( /* o : normalized resul const Word16 lg, /* i : vector length, range [0..7FFF] Q0 */ Word16 *exp /* o : exponent of result in [-32,31] Q0 */ ) +#ifndef FIX_ISSUE_1817_REPLACE_CARRY_OVERFLOW { Word16 i; Word32 L_sum, L_c; @@ -1895,7 +1896,22 @@ static Word32 CalculateAbsEnergy_fx( /* o : normalized resul L_sum = norm_llQ31( L_c, L_sum, exp ); return L_sum; } +#else +{ + Word16 i; + Word32 L_sum; + Word64 L_sum64; + + L_sum64 = W_deposit32_l( L_off ); + FOR( i = 0; i < lg; i += 2 ) + { + L_sum64 = W_mac_16_16( L_sum64, x[i], x[i] ); + } + L_sum = w_norm_llQ31( L_sum64, exp ); /*Q31 - *exp */ + return L_sum; +} +#endif /* FIX_ISSUE_1817_REPLACE_CARRY_OVERFLOW */ void IMDCT_fx( Word32 *x, Word16 x_e, Word16 *old_syn_overl, Word16 *syn_Overl_TDAC, Word16 *xn_buf, const Word16 *tcx_aldo_window_1, const PWord16 *tcx_aldo_window_1_trunc, const PWord16 *tcx_aldo_window_2, const PWord16 *tcx_mdct_window_half, const PWord16 *tcx_mdct_window_minimum, const PWord16 *tcx_mdct_window_trans, Word16 tcx_mdct_window_half_length, Word16 tcx_mdct_window_min_length, Word16 index, Word16 left_rect, Word16 tcx_offset, Word16 overlap, Word16 L_frame, Word16 L_frameTCX, Word16 L_spec_TCX5, Word16 L_frame_glob, Word16 frame_cnt, Word16 bfi, Word16 *old_out, Word16 *Q_old_wtda, Decoder_State *st, Word16 fullbandScale, Word16 *acelp_zir ) { diff --git a/lib_dec/fd_cng_dec_fx.c b/lib_dec/fd_cng_dec_fx.c index 416b9c716c9f2d58245067be8072d25f5a7ca44c..1e78b792becb0373958b675bf9a4995e0e4fd819 100644 --- a/lib_dec/fd_cng_dec_fx.c +++ b/lib_dec/fd_cng_dec_fx.c @@ -576,13 +576,17 @@ Word16 ApplyFdCng_fx( Word16 facTab[NPART]; Word16 facTabExp[NPART]; Word16 tmp_loop; +#ifndef FIX_ISSUE_1817_REPLACE_CARRY_OVERFLOW Word32 L_c; +#endif Word16 lsp_cng[M]; HANDLE_FD_CNG_DEC hFdCngDec; HANDLE_FD_CNG_COM hFdCngCom; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; +#ifndef FIX_ISSUE_1817_REPLACE_CARRY_OVERFLOW Flag Carry = 0; +#endif move16(); move16(); #endif @@ -794,6 +798,7 @@ Word16 ApplyFdCng_fx( { tmp_loop = sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); +#ifndef FIX_ISSUE_1817_REPLACE_CARRY_OVERFLOW L_tmp = L_deposit_h( 0 ); L_c = L_deposit_h( 0 ); FOR( j = 0; j < tmp_loop; j++ ) @@ -826,6 +831,19 @@ Word16 ApplyFdCng_fx( st->hTcxDec->conCngLevelBackgroundTrace = round_fx_sat( Sqrt32( L_tmp, &L_tmp_exp ) ); /*Q15 - L_tmp_exp*/ move16(); L_tmp_exp = add( L_tmp_exp, 1 ); +#else + L_tmp = sum_array_norm( cngNoiseLevel, tmp_loop, &L_tmp_exp ); /*Q31 - L_tmp_exp*/ + L_tmp_exp = sub( add( L_tmp_exp, *cngNoiseLevel_exp ), 1 ); + + L_tmp = L_shr( L_tmp, 15 ); /*Q16 - L_tmp_exp*/ + + L_tmp = Mpy_32_16_1( L_tmp, shr( T_DIV_L_Frame[L_shl( L_mac( -28000, NORM_MDCT_FACTOR, 95 ), 1 - 15 )], 1 ) ); /*Q16,exp -7*/ + L_tmp_exp = add( L_tmp_exp, -7 + ( 31 - 16 ) ); /*->Q31, L_tmp_exp*/ + + st->hTcxDec->conCngLevelBackgroundTrace = round_fx_sat( Sqrt32( L_tmp, &L_tmp_exp ) ); /*Q15 - L_tmp_exp*/ + move16(); + L_tmp_exp = add( L_tmp_exp, 1 ); +#endif st->hTcxDec->conCngLevelBackgroundTrace_e = L_tmp_exp; move16(); } @@ -833,6 +851,7 @@ Word16 ApplyFdCng_fx( { tmp_loop = sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); +#ifndef FIX_ISSUE_1817_REPLACE_CARRY_OVERFLOW L_tmp = L_deposit_h( 0 ); L_c = L_deposit_h( 0 ); FOR( j = 0; j < tmp_loop; j++ ) @@ -863,12 +882,25 @@ Word16 ApplyFdCng_fx( L_tmp_exp = add( L_tmp_exp, 31 - 16 ); /*->Q31, L_tmp_exp*/ st->hTcxDec->conCngLevelBackgroundTrace = round_fx_sat( Sqrt32( L_tmp, &L_tmp_exp ) ); /*Q15 - L_tmp_exp*/ +#else + L_tmp = sum_array_norm( cngNoiseLevel, tmp_loop, &L_tmp_exp ); + L_tmp_exp = sub( add( L_tmp_exp, *cngNoiseLevel_exp ), 1 ); + + L_tmp = Mpy_32_16_1( L_tmp, hFdCngCom->fftlen ); /*Q16 - L_tmp_exp*/ + + L_tmp = Mpy_32_16_1( L_tmp, T_DIV_L_Frame[L_shl( L_mac( -28000, st->L_frame, 95 ), 1 - 15 )] ); /*Q16,exp -7*/ + L_tmp_exp = add( L_tmp_exp, -7 + ( 31 - 16 ) ); /*->Q31, L_tmp_exp*/ + + + st->hTcxDec->conCngLevelBackgroundTrace = round_fx_sat( Sqrt32( L_tmp, &L_tmp_exp ) ); /*Q15 - L_tmp_exp*/ +#endif move16(); st->hTcxDec->conCngLevelBackgroundTrace_e = L_tmp_exp; move16(); } tmp_loop = sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); +#ifndef FIX_ISSUE_1817_REPLACE_CARRY_OVERFLOW L_tmp = L_deposit_h( 0 ); L_c = L_deposit_h( 0 ); FOR( j = 0; j < tmp_loop; j++ ) @@ -900,6 +932,19 @@ Word16 ApplyFdCng_fx( st->cngTDLevel = round_fx_sat( Sqrt32( L_tmp, &L_tmp_exp ) ); /*Q15 - L_tmp_exp*/ move16(); +#else + L_tmp = sum_array_norm( cngNoiseLevel, tmp_loop, &L_tmp_exp ); /*Q31 - L_tmp_exp*/ + L_tmp_exp = sub( add( L_tmp_exp, *cngNoiseLevel_exp ), 1 ); + + L_tmp = Mpy_32_16_1( L_tmp, hFdCngCom->fftlen ); /*Q16 - L_tmp_exp*/ + + L_tmp = Mpy_32_16_1( L_tmp, T_DIV_L_Frame[L_shr( L_mac( -28000, st->L_frame, 95 ), 15 - 1 )] ); /*Q16,exp -7*/ + L_tmp_exp = add( L_tmp_exp, -7 + ( 31 - 16 ) ); /*->Q31, L_tmp_exp */ + + st->cngTDLevel = round_fx_sat( Sqrt32( L_tmp, &L_tmp_exp ) ); /*Q15 - L_tmp_exp*/ + move16(); + +#endif st->cngTDLevel_e = L_tmp_exp; move16(); } @@ -1018,6 +1063,7 @@ Word16 ApplyFdCng_fx( /*st->cngTDLevel = (float)sqrt( (sumFLOAT(cngNoiseLevel, hFdCngCom->stopFFTbin - hFdCngCom->startBand) / 2 * hFdCngCom->fftlen) / st->Mode2_L_frame);*/ tmp_loop = sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); +#ifndef FIX_ISSUE_1817_REPLACE_CARRY_OVERFLOW L_tmp = L_deposit_h( 0 ); L_c = L_deposit_h( 0 ); FOR( j = 0; j < tmp_loop; j++ ) @@ -1049,6 +1095,18 @@ Word16 ApplyFdCng_fx( st->cngTDLevel = round_fx_o( Sqrt32( L_tmp, &L_tmp_exp ), &Overflow ); /*Q15 - L_tmp_exp*/ move16(); +#else + L_tmp = sum_array_norm( cngNoiseLevel, tmp_loop, &L_tmp_exp ); /*Q31 - L_tmp_exp*/ + L_tmp_exp = sub( add( L_tmp_exp, *cngNoiseLevel_exp ), 1 ); + + L_tmp = Mpy_32_16_1( L_tmp, hFdCngCom->fftlen ); /*Q16 - L_tmp_exp*/ + + L_tmp = Mpy_32_16_1( L_tmp, T_DIV_L_Frame[L_shl( L_mac( -28000, st->L_frame, 95 ), 1 - 15 )] ); /*Q16,exp -7*/ + L_tmp_exp = add( L_tmp_exp, -7 + ( 31 - 16 ) ); /*->Q31, L_tmp_exp*/ + + st->cngTDLevel = round_fx( Sqrt32( L_tmp, &L_tmp_exp ) ); /*Q15 - L_tmp_exp*/ + move16(); +#endif st->cngTDLevel_e = L_tmp_exp; move16(); BREAK;