From 84b635cb488d8c2e02a7d8c28d895fa3261d96ea Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Mon, 19 Aug 2024 14:18:00 +0530 Subject: [PATCH] Fix for LTV crashes observed with changes made for issue 824 (MR 541) --- lib_dec/fd_cng_dec_fx.c | 48 ++++++++++++----------------------------- 1 file changed, 14 insertions(+), 34 deletions(-) diff --git a/lib_dec/fd_cng_dec_fx.c b/lib_dec/fd_cng_dec_fx.c index 48c91b684..dc234e502 100644 --- a/lib_dec/fd_cng_dec_fx.c +++ b/lib_dec/fd_cng_dec_fx.c @@ -2468,15 +2468,15 @@ void perform_noise_estimation_dec_ivas_fx( SWITCH( hFdCngDec->hFdCngCom->fftlen ) { case 640: - rescale_fac = 83886; // 4/(640 * 640) in Q33 + rescale_fac = 671089; // 4/(640 * 640) in Q36 move32(); BREAK; case 512: - rescale_fac = 131072; // 4/(512 * 512) in Q33 + rescale_fac = 1048576; // 4/(512 * 512) in Q36 move32(); BREAK; case 320: - rescale_fac = 335544; // 4/(320 * 320) in Q33 + rescale_fac = 2684354; // 4/(320 * 320) in Q36 move32(); BREAK; default: @@ -2507,23 +2507,12 @@ void perform_noise_estimation_dec_ivas_fx( tmp_s = W_norm( W_tmp ); tmp_q = sub( add( i_mult( sub( 31, fftBuffer_exp ), 2 ), tmp_s ), 32 ); - IF( tmp_q < 0 ) - { - W_tmp = W_shr( W_tmp, negate( tmp_q ) ); - } + *ptr_per = W_extract_h( W_shl( W_tmp, tmp_s ) ); IF( LT_16( tmp_q, min_q ) ) { reIter = ptr_per; Word16 diff; - IF( tmp_q <= 0 ) - { - diff = min_q; - move16(); - } - ELSE - { - diff = sub( min_q, tmp_q ); - } + diff = sub( min_q, tmp_q ); WHILE( reIter > periodog ) { @@ -2531,34 +2520,25 @@ void perform_noise_estimation_dec_ivas_fx( *reIter = L_shr( *reIter, diff ); move32(); } - IF( tmp_q >= 0 ) - { - min_q = tmp_q; - } - ELSE IF( tmp_q < 0 ) - { - min_q = 0; - } + min_q = tmp_q; move16(); } - ( *ptr_per ) = W_extract_l( W_shr( W_tmp, sub( shl( sub( 31, fftBuffer_exp ), 1 ), min_q ) ) ); // Qmin_q - move32(); + ELSE + { + Word16 diff; + diff = sub( tmp_q, min_q ); + ( *ptr_per ) = L_shr( ( *ptr_per ), diff ); + } /* Rescale to get energy/sample: it should be 2*(1/N)*(2/N), parseval relation with 1/N,*2 for nrg computed till Nyquist only, 2/N as windowed samples correspond to half a frame*/ - ( *ptr_per ) = Mpy_32_32_r( ( *ptr_per ), rescale_fac ); // Q = min_q+2 + ( *ptr_per ) = Mpy_32_32_r( ( *ptr_per ), rescale_fac ); // Q = min_q+36-31=min_q+5 move32(); - IF( tmp_q < 0 ) - { - ( *ptr_per ) = L_shl( ( *ptr_per ), negate( tmp_q ) ); - move32(); - } - ptr_r += 2; ptr_i += 2; } - hFdCngDec->hFdCngCom->periodog_exp = sub( 31 - 2, min_q ); + hFdCngDec->hFdCngCom->periodog_exp = sub( 31 - 5, min_q ); hFdCngDec->hFdCngCom->fftBuffer_exp = fftBuffer_exp; move16(); move16(); -- GitLab