From ea32e0966c1c5d86787c51b70eb824caef70e80a Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Wed, 16 Oct 2024 22:15:27 +0530 Subject: [PATCH] Fix for 3GPP issue 925: Decoder crash for MC 7.1+4 at 384kbps in IGF_replaceTCXNoise_1() [x] Exponent of totalNoiseNrg and totalNoiseNrg_off updated to prevent saturation which was the cause of crash --- lib_dec/igf_dec_fx.c | 139 ++++++++++++++++++++++++++++++------------- 1 file changed, 97 insertions(+), 42 deletions(-) diff --git a/lib_dec/igf_dec_fx.c b/lib_dec/igf_dec_fx.c index fed5ee9fb..dc36524a2 100644 --- a/lib_dec/igf_dec_fx.c +++ b/lib_dec/igf_dec_fx.c @@ -129,6 +129,55 @@ static Word16 IGF_replaceTCXNoise_1( /**< ou return noise; } +static Word16 ivas_IGF_replaceTCXNoise_1_fx( /**< out: Q0 | number of noise bands */ + const Word32 *in, /**< in: Q31 | MDCT spectrum */ + Word16 s_l, /**< in: Q0 | noise headroom */ + const Word16 *TCXNoise, /**< in: | tcx noise indicator vector */ + const Word16 start, /**< in: Q0 | start MDCT subband index */ + const Word16 stop, /**< in: Q0 | stop MDCT subband index */ + Word32 *totalNoiseNrg, /**< out: | measured noise energy */ + Word16 *totalNoiseNrg_exp ) +{ + Word16 sb; + Word16 tmp16; + Word16 noise; + Word64 nE; + + + tmp16 = 0; + move16(); + noise = 0; + move16(); + s_l = sub( s_l, 5 ); + nE = 0; + move64(); + + FOR( sb = start; sb < stop; sb++ ) + { + IF( TCXNoise[sb] ) + { + tmp16 = extract_h( L_shl( in[sb], s_l ) ); + } + IF( TCXNoise[sb] ) + { + nE = W_mac_16_16( nE, tmp16, tmp16 ); + } + if ( TCXNoise[sb] ) + { + noise = add( noise, 1 ); + } + } + + tmp16 = W_norm( nE ); + nE = W_shl( nE, tmp16 ); + *totalNoiseNrg = W_extract_h( nE ); + move32(); + *totalNoiseNrg_exp = sub( tmp16, 32 ); + move16(); + + return noise; +} + /**********************************************************************/ /* replaces TCX noise **************************************************************************/ @@ -3544,15 +3593,16 @@ void IGFDecApplyMono_ivas( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in igf_spec + hGrid->minSrcSubband, sub( hGrid->startLine, hGrid->minSrcSubband ) ); move16(); - hPrivateData->n_noise_bands = IGF_replaceTCXNoise_1( igf_spec, - hPrivateData->headroom_TCX_noise_white, - hInstance->infoTCXNoise_ptr, - hGrid->minSrcSubband, - hGrid->startLine, - &hPrivateData->totalNoiseNrg ); + hPrivateData->n_noise_bands = ivas_IGF_replaceTCXNoise_1_fx( igf_spec, + hPrivateData->headroom_TCX_noise_white, + hInstance->infoTCXNoise_ptr, + hGrid->minSrcSubband, + hGrid->startLine, + &hPrivateData->totalNoiseNrg, + &hPrivateData->totalNoiseNrg_exp ); move16(); - hPrivateData->totalNoiseNrg_exp = shl( sub( igf_spec_e[i], sub( hPrivateData->headroom_TCX_noise_white, 5 ) ), 1 ); + hPrivateData->totalNoiseNrg_exp = sub( shl( sub( igf_spec_e[i], sub( hPrivateData->headroom_TCX_noise_white, 5 ) ), 1 ), hPrivateData->totalNoiseNrg_exp ); move16(); BREAK; @@ -3570,14 +3620,15 @@ void IGFDecApplyMono_ivas( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in sub( hGrid->startLine, hGrid->minSrcSubband ) ); move16(); - hPrivateData->n_noise_bands_off = IGF_replaceTCXNoise_1( hPrivateData->pSpecFlat, - hPrivateData->headroom_TCX_noise, - hInstance->infoTCXNoise_ptr, - hGrid->minSrcSubband, - hGrid->startLine, - &hPrivateData->totalNoiseNrg_off ); + hPrivateData->n_noise_bands_off = ivas_IGF_replaceTCXNoise_1_fx( hPrivateData->pSpecFlat, + hPrivateData->headroom_TCX_noise, + hInstance->infoTCXNoise_ptr, + hGrid->minSrcSubband, + hGrid->startLine, + &hPrivateData->totalNoiseNrg_off, + &hPrivateData->totalNoiseNrg_off_exp ); move16(); - hPrivateData->totalNoiseNrg_off_exp = shl( sub( hPrivateData->pSpecFlat_exp, sub( hPrivateData->headroom_TCX_noise, 5 ) ), 1 ); + hPrivateData->totalNoiseNrg_off_exp = sub( shl( sub( hPrivateData->pSpecFlat_exp, sub( hPrivateData->headroom_TCX_noise, 5 ) ), 1 ), hPrivateData->totalNoiseNrg_off_exp ); move16(); BREAK; } @@ -3767,15 +3818,16 @@ void IGFDecApplyStereo( igf_specL_fx + hGrid->minSrcSubband, sub( hGrid->startLine, hGrid->minSrcSubband ) ); move16(); - hPrivateDataL->n_noise_bands = IGF_replaceTCXNoise_1( igf_specL_fx, - hPrivateDataL->headroom_TCX_noise_white, - hIGFDecL->infoTCXNoise_ptr, - hGrid->minSrcSubband, - hGrid->startLine, - &hPrivateDataL->totalNoiseNrg ); + hPrivateDataL->n_noise_bands = ivas_IGF_replaceTCXNoise_1_fx( igf_specL_fx, + hPrivateDataL->headroom_TCX_noise_white, + hIGFDecL->infoTCXNoise_ptr, + hGrid->minSrcSubband, + hGrid->startLine, + &hPrivateDataL->totalNoiseNrg, + &hPrivateDataL->totalNoiseNrg_exp ); move16(); - hPrivateDataL->totalNoiseNrg_exp = shl( sub( specMedL_e, sub( hPrivateDataL->headroom_TCX_noise_white, 5 ) ), 1 ); + hPrivateDataL->totalNoiseNrg_exp = sub( shl( sub( specMedL_e, sub( hPrivateDataL->headroom_TCX_noise_white, 5 ) ), 1 ), hPrivateDataL->totalNoiseNrg_exp ); move16(); IF( !bfi ) @@ -3802,14 +3854,15 @@ void IGFDecApplyStereo( igf_specR_fx + hGrid->minSrcSubband, sub( hGrid->startLine, hGrid->minSrcSubband ) ); move16(); - hPrivateDataR->n_noise_bands = IGF_replaceTCXNoise_1( igf_specR_fx, - hPrivateDataR->headroom_TCX_noise_white, - hIGFDecR->infoTCXNoise_ptr, - hGrid->minSrcSubband, - hGrid->startLine, - &hPrivateDataR->totalNoiseNrg ); + hPrivateDataR->n_noise_bands = ivas_IGF_replaceTCXNoise_1_fx( igf_specR_fx, + hPrivateDataR->headroom_TCX_noise_white, + hIGFDecR->infoTCXNoise_ptr, + hGrid->minSrcSubband, + hGrid->startLine, + &hPrivateDataR->totalNoiseNrg, + &hPrivateDataR->totalNoiseNrg_exp ); move16(); - hPrivateDataR->totalNoiseNrg_exp = shl( sub( specMedR_e, sub( hPrivateDataR->headroom_TCX_noise_white, 5 ) ), 1 ); + hPrivateDataR->totalNoiseNrg_exp = sub( shl( sub( specMedR_e, sub( hPrivateDataR->headroom_TCX_noise_white, 5 ) ), 1 ), hPrivateDataR->totalNoiseNrg_exp ); move16(); BREAK; @@ -3824,13 +3877,14 @@ void IGFDecApplyStereo( hPrivateDataL->headroom_TCX_noise_white = IGF_getScaleFactor32Cond( hIGFDecL->infoTCXNoise_ptr + hGrid->minSrcSubband, hPrivateDataL->pSpecFlat + hGrid->minSrcSubband, sub( hGrid->startLine, hGrid->minSrcSubband ) ); - hPrivateDataL->n_noise_bands_off = IGF_replaceTCXNoise_1( hPrivateDataL->pSpecFlat, - hPrivateDataL->headroom_TCX_noise_white, - hIGFDecL->infoTCXNoise_ptr, - hGrid->minSrcSubband, - hGrid->startLine, - &hPrivateDataL->totalNoiseNrg_off ); - hPrivateDataL->totalNoiseNrg_off_exp = shl( sub( hPrivateDataL->pSpecFlat_exp, sub( hPrivateDataL->headroom_TCX_noise_white, 5 ) ), 1 ); + hPrivateDataL->n_noise_bands_off = ivas_IGF_replaceTCXNoise_1_fx( hPrivateDataL->pSpecFlat, + hPrivateDataL->headroom_TCX_noise_white, + hIGFDecL->infoTCXNoise_ptr, + hGrid->minSrcSubband, + hGrid->startLine, + &hPrivateDataL->totalNoiseNrg_off, + &hPrivateDataL->totalNoiseNrg_off_exp ); + hPrivateDataL->totalNoiseNrg_off_exp = sub( shl( sub( hPrivateDataL->pSpecFlat_exp, sub( hPrivateDataL->headroom_TCX_noise_white, 5 ) ), 1 ), hPrivateDataL->totalNoiseNrg_off_exp ); move16(); move16(); move16(); @@ -3838,13 +3892,14 @@ void IGFDecApplyStereo( hPrivateDataR->headroom_TCX_noise_white = IGF_getScaleFactor32Cond( hIGFDecR->infoTCXNoise_ptr, hPrivateDataR->pSpecFlat + hGrid->minSrcSubband, sub( hGrid->startLine, hGrid->minSrcSubband ) ); - hPrivateDataR->n_noise_bands_off = IGF_replaceTCXNoise_1( hPrivateDataR->pSpecFlat, - hPrivateDataR->headroom_TCX_noise_white, - hIGFDecR->infoTCXNoise_ptr, - hGrid->minSrcSubband, - hGrid->startLine, - &hPrivateDataR->totalNoiseNrg_off ); - hPrivateDataR->totalNoiseNrg_off_exp = shl( sub( hPrivateDataR->pSpecFlat_exp, sub( hPrivateDataR->headroom_TCX_noise_white, 5 ) ), 1 ); + hPrivateDataR->n_noise_bands_off = ivas_IGF_replaceTCXNoise_1_fx( hPrivateDataR->pSpecFlat, + hPrivateDataR->headroom_TCX_noise_white, + hIGFDecR->infoTCXNoise_ptr, + hGrid->minSrcSubband, + hGrid->startLine, + &hPrivateDataR->totalNoiseNrg_off, + &hPrivateDataR->totalNoiseNrg_off_exp ); + hPrivateDataR->totalNoiseNrg_off_exp = sub( shl( sub( hPrivateDataR->pSpecFlat_exp, sub( hPrivateDataR->headroom_TCX_noise_white, 5 ) ), 1 ), hPrivateDataR->totalNoiseNrg_off_exp ); move16(); move16(); move16(); -- GitLab