diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 5cc639543b2cafdf7facbb1313e5e3f8d1498bc4..420c2ba0d45368a65db4326905b8e97bd0d8e842 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -9462,6 +9462,12 @@ Word16 maximum_fx( /* o : index of the maximum value in t Word16 *max_fx /* o : maximum value in the input vector */ ); +Word16 maximum_abs_16_fx( /* o : index of the maximum abs value in the input vector */ + const Word16 *vec, /* i : input vector */ + const Word16 lvec, /* i : length of input vector */ + Word16 *max_val /* o : maximum value in the input vector */ +); + Word16 minimum_abs32_fx( /* o : index of the minimum value in the input vector */ const Word32 *vec_fx, /* i : input vector */ const Word16 lvec_fx, /* i : length of input vector */ diff --git a/lib_com/swb_tbe_com_fx.c b/lib_com/swb_tbe_com_fx.c index b5f418fc6fcab569153193caffa1eed8f5fac008..282317cdec4d9a2f2d70a0046c3c8dae093be964 100644 --- a/lib_com/swb_tbe_com_fx.c +++ b/lib_com/swb_tbe_com_fx.c @@ -2816,6 +2816,9 @@ void GenShapedSHBExcitation_ivas_fx( Word32 White_exc16k_32[L_FRAME16k]; Word16 Q_temp; Word16 prev_Q_bwe_exc_fb; + Word16 chk1, chk2; + chk1 = 0; + chk2 = 0; #if 1 // def ADD_IVAS_TBE_CODE Word16 alpha, step, mem_csfilt_left, mem_csfilt_right, excNoisyEnvLeft[L_FRAME16k], excNoisyEnvRight[L_FRAME16k]; @@ -2898,6 +2901,7 @@ void GenShapedSHBExcitation_ivas_fx( /*excTmp2[k ] = (float)(fabs(exc16kWhtnd[k]));*/ excTmp2[k] = abs_s( exc16kWhtnd[k] ); move16(); + chk1 = s_or( chk1, exc16kWhtnd[k] ); /* pow1 += exc16kWhtnd[k] * exc16kWhtnd[k]; */ #ifdef BASOP_NOGLOB @@ -3149,6 +3153,7 @@ void GenShapedSHBExcitation_ivas_fx( /* White_exc16k[k] *= excNoisyEnv[k]; */ White_exc16k[k] = mult_r( excNoisyEnv[k], shl( White_exc16k[k], tmp ) ); move16(); + chk2 = s_or( chk2, White_exc16k[k] ); /* i: excNoisyEnv in (Q_bwe_exc) */ /* i: White_exc16k in Q6 */ /* o: White_exc16k in (Q_bwe_exc-NOISE_QADJ) */ @@ -3446,6 +3451,12 @@ void GenShapedSHBExcitation_ivas_fx( #endif { L_tmp = root_a_over_b_fx( pow1, Q_pow1, pow22, Q_pow22, &exp ); + test(); + if ( chk1 == 0 && chk2 == 0 ) + { + L_tmp = 0; + move32(); + } #ifdef BASOP_NOGLOB scale = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /*Q15 */ #else diff --git a/lib_com/tools_fx.c b/lib_com/tools_fx.c index 4641195552d10c5d10436b6bb0e034b7293d412f..a1ececc58764190332bd245ef500eb0f5e70a79e 100644 --- a/lib_com/tools_fx.c +++ b/lib_com/tools_fx.c @@ -1100,6 +1100,39 @@ Word16 maximum_fx( /* o : index of the maximum value in t return ind; } +/*---------------------------------------------------------------------* + * maximum_abs_16_fx() + * + * Find index and value of the absolute maximum in a vector + *---------------------------------------------------------------------*/ + +Word16 maximum_abs_16_fx( /* o : index of the maximum abs value in the input vector */ + const Word16 *vec, /* i : input vector */ + const Word16 lvec, /* i : length of input vector */ + Word16 *max_val /* o : maximum value in the input vector */ +) +{ + Word16 j, ind; + Word16 tmp; + ind = 0; + move16(); + tmp = abs_s( vec[0] ); + + FOR( j = 1; j < lvec; j++ ) + { + if ( GT_16( abs_s( vec[j] ), tmp ) ) + { + ind = j; + move16(); + } + tmp = s_max( tmp, abs_s( vec[j] ) ); + } + *max_val = tmp; + move16(); + + return ind; +} + /*---------------------------------------------------------------------* * minimum_abs32_fx() * diff --git a/lib_dec/tonalMDCTconcealment_fx.c b/lib_dec/tonalMDCTconcealment_fx.c index 5e97ae8e69ff315024137c0928300e9ee7b72006..f4dfca6560a8adba1fdda3d0a13f28495805cc00 100644 --- a/lib_dec/tonalMDCTconcealment_fx.c +++ b/lib_dec/tonalMDCTconcealment_fx.c @@ -1377,6 +1377,8 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( Word16 inv_exp, inv_samples, exp; Word32 last_block_nrg_correct; Word16 last_block_nrg_correct_e; + Word32 max_concealment_value; + Word16 max_spectral_value; crossfadeGain = crossfadeGain_const; move16(); @@ -1463,7 +1465,6 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( { Word32 num, den; Word16 exp_num, exp_den; - Word32 max_concealment_value; exp_num = cngLevelBackgroundTrace_bfi_e; move16(); @@ -1519,6 +1520,13 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( move16(); } } + ELSE + { + (void) maximum_abs_16_fx( hTonalMDCTConc->lastBlockData.spectralData, crossOverFreq, &max_spectral_value ); + exp = sub( norm_l( L_mult( max_spectral_value, crossfadeGain ) ), find_guarded_bits_fx( crossOverFreq ) ); + *mdctSpectrum_exp = sub( hTonalMDCTConc->lastBlockData.spectralData_exp, exp ); + move16(); + } FOR( i = 0; i < crossOverFreq; i++ ) { @@ -1646,7 +1654,6 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( { Word32 num, den; Word16 exp_num, exp_den; - Word32 max_concealment_value; exp_num = cngLevelBackgroundTrace_bfi_e; move16(); @@ -1674,7 +1681,7 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( L_tmp = L_deposit_h( 0 ); exp = sub( hTonalMDCTConc->lastBlockData.spectralData_exp, add( concealment_noise_e, exp ) ); - (void) maximum_abs_32_fx( concealment_noise, hTonalMDCTConc->pTCI->lowerIndex[0], &max_concealment_value ); + (void) maximum_abs_32_fx( concealment_noise, crossOverFreq, &max_concealment_value ); IF( GT_32( max_concealment_value, 0 ) ) { IF( GT_16( exp, 0 ) ) @@ -1703,6 +1710,13 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( move16(); } } + ELSE + { + (void) maximum_abs_16_fx( hTonalMDCTConc->lastBlockData.spectralData, crossOverFreq, &max_spectral_value ); + exp = sub( norm_l( L_mult( max_spectral_value, crossfadeGain ) ), find_guarded_bits_fx( crossOverFreq ) ); + *mdctSpectrum_exp = sub( hTonalMDCTConc->lastBlockData.spectralData_exp, exp ); + move16(); + } FOR( l = 0; l < hTonalMDCTConc->pTCI->lowerIndex[0]; l++ ) {