From afb1629b107fb5bcf6fcdb4c34dab67891edf4f9 Mon Sep 17 00:00:00 2001 From: Arun Ganesh Nayak <100918@ittiam.com> Date: Mon, 17 Feb 2025 14:17:44 +0530 Subject: [PATCH 1/2] Fix for 3GPP issue 1285: Assert in ivas_fill_spectrum_fx of BASOP decoder when fed with OMASA bitstream from BASOP encoder --- lib_com/fill_spectrum.c | 2 +- lib_com/hq_tools_fx.c | 30 +++ lib_com/options.h | 2 + lib_com/prot_fx.h | 23 ++ lib_com/swb_bwe_com_fx.c | 556 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 612 insertions(+), 1 deletion(-) diff --git a/lib_com/fill_spectrum.c b/lib_com/fill_spectrum.c index 111ac6d2f..5a4f7c4bc 100644 --- a/lib_com/fill_spectrum.c +++ b/lib_com/fill_spectrum.c @@ -263,7 +263,7 @@ void ivas_fill_spectrum_fx( } ELSE IF( EQ_16( HQ_mode, HQ_GEN_SWB ) || EQ_16( HQ_mode, HQ_GEN_FB ) ) { - hq_bwe_fx( HQ_mode, L_coeff_out1, hq_generic_fenv, L_coeff_out, hq_generic_offset, prev_L_swb_norm, hq_generic_exc_clas, sfm_end, num_sfm, num_env_bands, R ); + hq_bwe_ivas_fx( HQ_mode, L_coeff_out1, hq_generic_fenv, L_coeff_out, hq_generic_offset, prev_L_swb_norm, hq_generic_exc_clas, sfm_end, num_sfm, num_env_bands, R ); } /*----------------------------------------------------------------* diff --git a/lib_com/hq_tools_fx.c b/lib_com/hq_tools_fx.c index 998f3f048..7b7da27e6 100644 --- a/lib_com/hq_tools_fx.c +++ b/lib_com/hq_tools_fx.c @@ -2102,6 +2102,36 @@ void hq_bwe_fx( return; } +void hq_bwe_ivas_fx( + const Word16 HQ_mode, /* i : HQ mode Q0*/ + Word32 *coeff_out1, /* i/o: BWE input & temporary buffer Q12*/ + const Word16 *hq_generic_fenv, /* i : SWB frequency envelopes Q1*/ + Word32 *coeff_out, /* o : SWB signal in MDCT domain Q12*/ + const Word16 hq_generic_offset, /* i : frequency offset for representing hq generic Q0*/ + Word16 *prev_L_swb_norm, /* i/o: last normalize length Q0*/ + const Word16 hq_generic_exc_clas, /* i : hq generic hf excitation class Q0*/ + const Word16 *sfm_end, /* i : End of bands Q0*/ + const Word16 num_sfm, /* i : Number of bands Q0*/ + const Word16 num_env_bands, /* i : Number of coded envelope bands Q0*/ + const Word16 *R /* i : Bit allocation Q0*/ +) +{ + Word16 n_swb_overlap_offset, n_swb_overlap; + Word32 hq_swb_overlap_buf_fx[L_FRAME32k]; + + n_swb_overlap_offset = add( swb_bwe_subband[0], hq_generic_offset ); + n_swb_overlap = sub( sfm_end[( num_env_bands - 1 )], n_swb_overlap_offset ); /*Q0*/ + + + Copy32( &coeff_out[n_swb_overlap_offset], hq_swb_overlap_buf_fx, sub( add( n_swb_overlap, sfm_end[( num_sfm - 1 )] ), sfm_end[( num_env_bands - 1 )] ) ); /*Q12*/ + + hq_generic_decoding_ivas_fx( HQ_mode, coeff_out1, hq_generic_fenv, coeff_out, hq_generic_offset, prev_L_swb_norm, hq_generic_exc_clas, R ); + + overlap_hq_bwe_fx( hq_swb_overlap_buf_fx, coeff_out, n_swb_overlap_offset, n_swb_overlap, R, num_env_bands, num_sfm, sfm_end ); + + return; +} + /*--------------------------------------------------------------------------* * hq_wb_nf_bwe() * diff --git a/lib_com/options.h b/lib_com/options.h index 56a6eeabf..0c8105d8c 100755 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -162,4 +162,6 @@ #define NONBE_FIX_1087_OOB_SBA_DTX_RS /* VA: issue 1087: Extend the length of the buffer for MCT decoding to avoid out-of-bound writing in SBA SID bitrate switching decoding */ #define FIX_ISSUE_1279 /* VA: correction of wrong scaling update */ #define FIX_ISSUE_1247 +#define NONBE_FIX_1087_OOB_SBA_DTX_RS /* VA: issue 1087: Extend the length of the buffer for MCT decoding to avoid out-of-bound writing in SBA SID bitrate switching decoding */ +#define FIX_1285_DECODER_CRASH #endif diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index dc84a2f36..cf7072cf5 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -434,6 +434,16 @@ void hq_generic_decoding_fx( const Word16 hq_generic_exc_clas, /* i : bwe excitation class */ const Word16 *R ); +void hq_generic_decoding_ivas_fx( + const Word16 HQ_mode, /* i : HQ mode */ + Word32 *coeff_out1_fx, /* i/o: BWE i & temporary buffer */ + const Word16 *hq_generic_fenv_fx, /* i : SWB frequency envelopes */ + Word32 *coeff_out_fx, /* o : SWB signal in MDCT domain */ + const Word16 hq_generic_offset, /* i : frequency offset for representing hq generic*/ + Word16 *prev_L_swb_norm, /* i/o: last normalize length */ + const Word16 hq_generic_exc_clas, /* i : bwe excitation class */ + const Word16 *R ); + void save_old_syn_fx( const Word16 L_frame, /* i : frame length */ const Word16 syn[], /* i : ACELP synthesis */ @@ -706,6 +716,19 @@ void hq_bwe_fx( const Word16 num_env_bands, const Word16 *R ); +void hq_bwe_ivas_fx( + const Word16 HQ_mode, /* i : HQ mode */ + Word32 *coeff_out1, /* i/o: BWE i & temporary buffer */ + const Word16 *hq_generic_fenv, /* i : SWB frequency envelopes */ + Word32 *coeff_out, /* o : SWB signal in MDCT domain */ + const Word16 hq_generic_offset, /* i : frequency offset for representing hq generic bwe*/ + Word16 *prev_L_swb_norm, /*i/o : last normalize length */ + const Word16 hq_generic_exc_clas, /* i : bwe excitation class */ + const Word16 *sfm_end, /* i : End of bands */ + const Word16 num_sfm, + const Word16 num_env_bands, + const Word16 *R ); + void hq_wb_nf_bwe_fx( const Word16 *coeff_fx, /* i : coded/noisefilled normalized spectrum */ const Word16 is_transient, diff --git a/lib_com/swb_bwe_com_fx.c b/lib_com/swb_bwe_com_fx.c index 303d453f1..5cbdd105e 100644 --- a/lib_com/swb_bwe_com_fx.c +++ b/lib_com/swb_bwe_com_fx.c @@ -3021,6 +3021,562 @@ void hq_generic_decoding_fx( return; } +void hq_generic_decoding_ivas_fx( + const Word16 HQ_mode, /* i : HQ mode : Q0 */ + Word32 *coeff_out1_fx, /* i/o: BWE input & temporary buffer : Q12 */ + const Word16 *hq_generic_fenv_fx, /* i : SWB frequency envelopes : Q1 */ + Word32 *coeff_out_fx, /* o : SWB signal in MDCT domain : Q12 */ + const Word16 hq_generic_offset, /* i : frequency offset for representing hq generci : Q0 */ + Word16 *prev_L_swb_norm, /* i/o: last normalize length : Q0 */ + const Word16 hq_generic_exc_clas, /* i : bwe excitation class " Q0 */ + const Word16 *R ) +{ + Word16 i, n_freq, n_band, L_swb_norm; + Word16 k; + Word16 nenv; + Word16 tenv; + + Word16 exp, exp1, exp2, frac, tmp, tmp2, cs; + Word32 L_tmp, L_tmp1, L_tmp2, max_coeff_fx; + Word16 fenvL_fx, wfenv_fx, factor_fx; + Word32 *pit1_fx; + Word16 tmp1_fx, tmp2_fx, tmp3_fx, tmp4_fx; + Word32 energy_fx; + + Word32 envelope_fx[L_FRAME16k]; + Word32 mean_vector_fx[20]; + Word16 rn_weight0_fx; + Word16 s; + Word16 blen, nband_lf, sfidx, efidx; + Word16 bwe_seed; + Word16 signum[L_FRAME16k]; + + nenv = sub( SWB_FENV, 2 ); + if ( LE_16( hq_generic_offset, HQ_GENERIC_FOFFSET_24K4 ) ) + { + nenv = SWB_FENV; + move16(); + } + + tenv = nenv; + move16(); + if ( EQ_16( HQ_mode, HQ_GEN_FB ) ) + { + tenv = add( nenv, DIM_FB ); + } + + max_coeff_fx = 0; + move16(); + tmp = add( swb_bwe_subband[0], hq_generic_offset ); + FOR( n_freq = add( HQ_GENERIC_ST_FREQ, hq_generic_offset ); n_freq < tmp; n_freq++ ) + { + max_coeff_fx = L_max( max_coeff_fx, L_abs( coeff_out1_fx[n_freq] ) ); + } + cs = norm_l( max_coeff_fx ); + + L_tmp = 0; + move16(); + tmp2 = add( swb_bwe_subband[0], hq_generic_offset ); + FOR( n_freq = add( HQ_GENERIC_ST_FREQ, hq_generic_offset ); n_freq < tmp2; n_freq++ ) + { + tmp = extract_h( L_shl( coeff_out1_fx[n_freq], cs ) ); /*12 + cs - 16 */ + L_tmp1 = L_mult0( tmp, tmp ); /*2*(cs-2) */ + L_tmp = L_add( L_tmp, L_shr( L_tmp1, 5 ) ); /*2*(cs-2) - 5 */ + } + cs = sub( shl( cs, 1 ), 9 ); + fenvL_fx = 0; + move16(); + IF( L_tmp != 0 ) + { + exp = norm_l( L_tmp ); +#ifdef EVS_FUNC_MODIFIED + frac = round_fx_sat( L_shl( L_tmp, exp ) ); /*cs+exp-16 */ +#else + frac = round_fx( L_shl( L_tmp, exp ) ); /*cs+exp-16 */ +#endif + tmp = div_s( 16384, frac ); /*15 + 14 - (cs+exp-16) */ + exp = sub( add( cs, exp ), 30 ); + L_tmp = Isqrt_lc( L_deposit_h( tmp ), &exp ); /*Q31 - exp */ + fenvL_fx = round_fx_sat( L_shl_sat( L_tmp, sub( exp, 14 ) ) ); /*Q1 */ + } + + calc_normal_length_fx_32( HQ_CORE, coeff_out1_fx, HQ_GEN_SWB, -1, &L_swb_norm, prev_L_swb_norm ); + + calc_norm_envelop_lf_fx( coeff_out1_fx, envelope_fx, &L_swb_norm, HQ_mode, hq_generic_offset, &sfidx, &efidx ); + + blen = 16; + move16(); + + IF( EQ_16( hq_generic_exc_clas, HQ_GENERIC_EXC0 ) ) + { + rn_weight0_fx = 819; + move16(); /* 0.8 Q10 */ + } + ELSE IF( EQ_16( hq_generic_exc_clas, HQ_GENERIC_EXC1 ) ) + { + rn_weight0_fx = 51; + move16(); /* 0.05 Q10*/ + } + ELSE + { + rn_weight0_fx = 205; + move16(); /* 0.02 Q10 */ + } + + tmp = sub( efidx, sfidx ); + IF( tmp == 0 ) + { + nband_lf = 0; + move16(); + } + ELSE + { + exp = norm_s( tmp ); + nband_lf = shl( tmp, sub( exp, 1 ) ); + exp1 = norm_s( blen ); + tmp = shl( blen, exp1 ); + nband_lf = shr( div_s( nband_lf, tmp ), add( sub( 14, exp1 ), exp ) ); /* 15 + exp-1 - exp1, Q0*/ + } + + FOR( n_freq = sfidx; n_freq < efidx; n_freq++ ) + { + IF( coeff_out1_fx[n_freq] < 0 ) + { + signum[n_freq] = -1; + move16(); + coeff_out1_fx[n_freq] = L_negate( coeff_out1_fx[n_freq] ); + move32(); + } + ELSE + { + signum[n_freq] = 1; + move16(); + } + } + + /* applying whitening */ + FOR( n_freq = sfidx; n_freq < efidx; n_freq++ ) + { + exp = norm_l( coeff_out1_fx[n_freq] ) - 1; + exp1 = norm_l( envelope_fx[n_freq] ); + + L_tmp = L_shl( coeff_out1_fx[n_freq], exp ); + L_tmp1 = L_shl( envelope_fx[n_freq], exp1 ); + + logic16(); + coeff_out1_fx[n_freq] = Div_32( L_tmp, extract_h( L_tmp1 ), extract_l( L_shr( L_tmp1, 1 ) ) & 0x00007fff ); + move32(); /*31 + exp1 - exp2*/ + + exp = add( 31, sub( exp, exp1 ) ); + coeff_out1_fx[n_freq] = L_shl( coeff_out1_fx[n_freq], sub( 20, exp ) ); + move32(); /*Q12->Q20*/ + } + + /* mean vector generation for controlling dynamic range */ + FOR( k = 0; k < nband_lf; ++k ) + { + energy_fx = 1; + move16(); + + tmp = add( i_mult2( add( k, 1 ), blen ), sfidx ); + FOR( i = add( i_mult2( k, blen ), sfidx ); i < tmp; ++i ) + { + energy_fx = L_add( energy_fx, coeff_out1_fx[i] ); + } + exp = sub( norm_l( energy_fx ), 1 ); + L_tmp = L_shl( energy_fx, exp ); + exp1 = norm_l( L_and( blen, 0x00007fff ) ); + L_tmp1 = L_shl( blen, exp1 ); + logic16(); + mean_vector_fx[k] = Div_32( L_tmp, extract_h( L_tmp1 ), extract_l( L_shr( L_tmp1, 1 ) ) & 0x00007fff ); + move32(); /*31 + 20 + exp1 - exp2*/ + exp = add( 51, sub( exp, exp1 ) ); + mean_vector_fx[k] = L_shl( mean_vector_fx[k], sub( 20, exp ) ); + move32(); /*Q12->Q20*/ + } + + /* dynamics control */ + FOR( k = 0; k < nband_lf; ++k ) + { + tmp = add( i_mult2( add( k, 1 ), blen ), sfidx ); + FOR( i = add( i_mult2( k, blen ), sfidx ); i < tmp; ++i ) + { + L_tmp = L_sub( coeff_out1_fx[i], mean_vector_fx[k] ); + exp = norm_l( L_tmp ); + L_tmp = L_shl( L_tmp, exp ); /* exp+12*/ + exp1 = norm_l( rn_weight0_fx ); + L_tmp1 = L_shl( rn_weight0_fx, exp1 ); /* exp1+10*/ + L_tmp = L_mult( extract_h( L_tmp ), extract_h( L_tmp1 ) ); + L_tmp = L_shr( L_tmp, add( exp, sub( exp1, 21 ) ) ); /* Q20*/ + coeff_out1_fx[i] = L_sub( coeff_out1_fx[i], L_tmp ); + move32(); + } + } + + IF( EQ_16( hq_generic_exc_clas, HQ_GENERIC_EXC0 ) ) + { + bwe_seed = add( add( shl( R[0], 3 ), shl( R[1], 2 ) ), add( shl( R[2], 1 ), R[3] ) ); + + FOR( n_freq = sfidx; n_freq < efidx; n_freq++ ) + { + IF( signum[n_freq] < 0 ) + { + coeff_out1_fx[n_freq] = L_negate( coeff_out1_fx[n_freq] ); + move32(); + } + + IF( Random( &bwe_seed ) < 0 ) + { + coeff_out1_fx[n_freq] = L_negate( coeff_out1_fx[n_freq] ); + move32(); + } + } + } + ELSE + { + FOR( n_freq = sfidx; n_freq < efidx; n_freq++ ) + { + IF( signum[n_freq] < 0 ) + { + coeff_out1_fx[n_freq] = L_negate( coeff_out1_fx[n_freq] ); + move32(); + } + } + } + + /* normalizing modified low frequency spectrum */ + FOR( k = 0; k < nband_lf; ++k ) + { + energy_fx = 1; + move16(); + tmp = add( i_mult2( add( k, 1 ), blen ), sfidx ); + FOR( i = add( ( i_mult2( k, blen ) ), sfidx ); i < tmp; ++i ) + { + exp = norm_l( coeff_out1_fx[i] ); + L_tmp1 = L_shl( coeff_out1_fx[i], exp ); /* exp + 12*/ + + L_tmp = Mult_32_32( L_tmp1, L_tmp1 ); + L_tmp = L_shr( L_tmp, sub( i_mult2( 2, exp ), 11 ) ); /*Q20 */ + energy_fx = L_add( energy_fx, L_tmp ); + } + + exp = norm_l( energy_fx ); + L_tmp = L_shl( energy_fx, sub( exp, 1 ) ); + exp1 = norm_s( blen ); + L_tmp1 = L_shl( (Word32) blen, add( exp1, 16 ) ); + + L_tmp = Div_32( L_tmp, extract_h( L_tmp1 ), extract_l( L_shr( L_tmp1, 1 ) ) & 0x00007fff ); + exp = sub( add( 34, exp ), exp1 ); + L_tmp = L_shr( L_tmp, sub( exp, 31 ) ); + exp = 31; + move16(); + + exp = sub( 31, exp ); + IF( exp & 0x1 ) + { + L_tmp = L_shr( L_tmp, 1 ); + exp = add( exp, 1 ); + } + L_tmp = Sqrt_l( L_tmp, &exp1 ); + exp = add( 31, sub( shr( exp1, 1 ), shr( exp, 1 ) ) ); + energy_fx = L_shl( L_tmp, sub( 31, exp ) ); /*Q31*/ + + tmp = add( i_mult2( add( k, 1 ), blen ), sfidx ); + FOR( i = add( ( i_mult2( k, blen ) ), sfidx ); i < tmp; ++i ) + { + IF( NE_32( L_abs( coeff_out1_fx[i] ), coeff_out1_fx[i] ) ) + { + s = -1; + move16(); + coeff_out1_fx[i] = L_abs( coeff_out1_fx[i] ); + move32(); + } + ELSE + { + s = 0; + move16(); + } + exp = norm_l( coeff_out1_fx[i] ); + L_tmp = L_shl( coeff_out1_fx[i], sub( exp, 1 ) ); + exp1 = norm_l( energy_fx ); + L_tmp1 = L_shl( (Word32) energy_fx, exp1 ); + logic16(); + L_tmp = Div_32( L_tmp, extract_h( L_tmp1 ), extract_l( L_shr( L_tmp1, 1 ) ) & 0x00007fff ); + exp = add( sub( 19, exp1 ), exp ); + coeff_out1_fx[i] = L_shl( L_tmp, add( sub( 12, exp ), 15 ) ); + move32(); /* Q12 -> Q27 */ + IF( s ) + { + coeff_out1_fx[i] = L_negate( coeff_out1_fx[i] ); + move32(); + } + } + } + + Copy32( &coeff_out1_fx[HQ_GENERIC_OFFSET], &coeff_out_fx[HQ_GENERIC_HIGH0 + hq_generic_offset], HQ_GENERIC_LEN0 ); + Copy32( &coeff_out1_fx[HQ_GENERIC_OFFSET], &coeff_out_fx[HQ_GENERIC_HIGH1 + hq_generic_offset], HQ_GENERIC_LEN0 ); + + IF( LE_16( hq_generic_offset, HQ_GENERIC_FOFFSET_24K4 ) ) + { + Copy32( &coeff_out1_fx[HQ_GENERIC_LOW0], &coeff_out_fx[HQ_GENERIC_HIGH2 + hq_generic_offset], HQ_GENERIC_END_FREQ - HQ_GENERIC_HIGH2 ); + } + + IF( EQ_16( HQ_mode, HQ_GEN_FB ) ) + { + IF( LE_16( hq_generic_offset, HQ_GENERIC_FOFFSET_24K4 ) ) + { + Copy32( &coeff_out1_fx[HQ_GENERIC_LOW0 + HQ_GENERIC_END_FREQ - HQ_GENERIC_HIGH2], &coeff_out_fx[fb_bwe_subband[0]], 160 ); + } + ELSE + { + Copy32( &coeff_out1_fx[HQ_GENERIC_OFFSET + HQ_GENERIC_LEN0], &coeff_out_fx[fb_bwe_subband[0]], 160 ); + } + } + + + L_tmp1 = L_deposit_l( 0 ); + L_tmp2 = L_deposit_l( 0 ); + FOR( i = 0; i < 5; ++i ) + { + L_tmp1 = L_add( L_tmp1, L_shr( L_abs( coeff_out_fx[HQ_GENERIC_HIGH1 + hq_generic_offset + i] ), 3 ) ); // adding guard bits + L_tmp2 = L_add( L_tmp2, L_shr( L_abs( coeff_out_fx[HQ_GENERIC_HIGH1 - 2 + hq_generic_offset - i] ), 3 ) ); //adding guard bits + } + + pit1_fx = &coeff_out_fx[HQ_GENERIC_HIGH1 + hq_generic_offset]; + L_tmp1 = L_max( L_tmp1, 1 ); + L_tmp2 = L_max( L_tmp2, 1 ); + exp1 = norm_l( L_tmp1 ); + exp2 = sub( norm_l( L_tmp2 ), 1 ); + tmp1_fx = extract_h( L_shl( L_tmp1, exp1 ) ); + tmp2_fx = extract_h( L_shl( L_tmp2, exp2 ) ); + tmp3_fx = div_s( tmp2_fx, tmp1_fx ); /*15 + exp2 + 15 - (exp1 + 15) */ + tmp3_fx = shr( tmp3_fx, add( 5, sub( exp2, exp1 ) ) ); /*10 */ + + if ( LT_16( tmp3_fx, 307 /*0.3 in Q10 */ ) ) + { + tmp3_fx = 307 /*0.3 in Q10 */; + move16(); + } + FOR( ; tmp3_fx < 1024; tmp3_fx += 102 ) + { + *pit1_fx = Mult_32_16( *pit1_fx, shl( tmp3_fx, 5 ) ); + move32(); /*15 + 5 + 10 -15 */ + pit1_fx++; + } + + pit1_fx = &coeff_out_fx[HQ_GENERIC_HIGH1 - 1 + hq_generic_offset]; + + exp1 = sub( norm_l( L_tmp1 ), 1 ); + exp2 = norm_l( L_tmp2 ); + tmp1_fx = extract_h( L_shl( L_tmp1, exp1 ) ); + tmp2_fx = extract_h( L_shl( L_tmp2, exp2 ) ); + tmp3_fx = div_s( tmp1_fx, tmp2_fx ); /*15 + exp2 + 15 - (exp1 + 15) */ + tmp3_fx = shr( tmp3_fx, add( 5, sub( exp1, exp2 ) ) ); /*10 */ + + IF( GT_16( tmp3_fx, 5120 ) ) + { + FOR( tmp3_fx = 5120; tmp3_fx > 1024; tmp3_fx -= 512 ) + { + /* Adding saturation suggested as fix for issue #957 */ + L_tmp1 = L_shl_sat( Mult_32_16( *pit1_fx, tmp3_fx ), 5 ); /*15 + 5 + 10 -15 */ + *pit1_fx-- = L_tmp1; + move32(); + } + } + + IF( LE_16( hq_generic_offset, HQ_GENERIC_FOFFSET_24K4 ) ) + { + L_tmp1 = L_add( L_abs( coeff_out_fx[HQ_GENERIC_HIGH2 + hq_generic_offset] ), L_abs( coeff_out_fx[HQ_GENERIC_HIGH2 + 1 + hq_generic_offset] ) ); + L_tmp2 = L_add( L_abs( coeff_out_fx[HQ_GENERIC_HIGH2 - 4 + hq_generic_offset] ), L_add( L_abs( coeff_out_fx[HQ_GENERIC_HIGH2 - 3 + hq_generic_offset] ), + L_add( L_abs( coeff_out_fx[HQ_GENERIC_HIGH2 - 2 + hq_generic_offset] ), L_abs( coeff_out_fx[HQ_GENERIC_HIGH2 - 1 + hq_generic_offset] ) ) ) ); + + pit1_fx = &coeff_out_fx[HQ_GENERIC_HIGH2 + hq_generic_offset]; + + L_tmp1 = L_max( L_tmp1, 1 ); + L_tmp2 = L_max( L_tmp2, 1 ); + exp1 = norm_l( L_tmp1 ); + exp2 = sub( norm_l( L_tmp2 ), 1 ); + tmp1_fx = extract_h( L_shl( L_tmp1, exp1 ) ); + tmp2_fx = extract_h( L_shl( L_tmp2, exp2 ) ); + tmp3_fx = div_s( tmp2_fx, tmp1_fx ); /*15 + exp2 + 15 - (exp1 + 15) */ + tmp3_fx = shr_sat( tmp3_fx, add( 5, sub( exp2, exp1 ) ) ); /*10 */ + if ( LT_16( tmp3_fx, 307 /* 0.3 in Q10*/ ) ) + { + tmp3_fx = 307; /* 0.3 in Q10*/ + move16(); + } + FOR( ; tmp3_fx < 1024; tmp3_fx += 102 ) + { + L_tmp = L_shl( Mult_32_16( *pit1_fx, tmp3_fx ), 5 ); /*15 + 5 + 10 -15 */ + *pit1_fx++ = L_tmp; + move32(); + } + + pit1_fx = &coeff_out_fx[HQ_GENERIC_HIGH2 - 1 + hq_generic_offset]; + + exp1 = sub( norm_l( L_tmp1 ), 1 ); + exp2 = norm_l( L_tmp2 ); + tmp1_fx = extract_h( L_shl( L_tmp1, exp1 ) ); + tmp2_fx = extract_h( L_shl( L_tmp2, exp2 ) ); + tmp3_fx = div_s( tmp1_fx, tmp2_fx ); /*15 + exp2 + 15 - (exp1 + 15) */ + tmp3_fx = shr( tmp3_fx, add( 5, sub( exp1, exp2 ) ) ); /*10 */ + tmp3_fx = shr( tmp3_fx, 1 ); + tmp4_fx = mult_r( tmp3_fx, 1638 /* 0.05 in Q15 */ ); + WHILE( tmp3_fx > 1024 /* 1 in Q10*/ ) + { +#ifdef EVS_FUNC_MODIFIED + L_tmp1 = L_shl( Mult_32_16( *pit1_fx, tmp3_fx ), 5 ); /*15 + 5 + 10 -15 */ +#else + L_tmp1 = Mult_32_16( L_shl( *pit1_fx, 5 ), tmp3_fx ); /*15 + 5 + 10 -15 */ +#endif + *pit1_fx-- = L_tmp1; + move32(); + tmp3_fx = sub( tmp3_fx, tmp4_fx ); + } + } + + + wfenv_fx = hq_generic_fenv_fx[0]; + move16(); /*1 */ + i = 0; + move16(); + tmp2 = add( add( swb_bwe_subband[0], hq_generic_offset ), 8 ); + FOR( n_freq = add( swb_bwe_subband[0], hq_generic_offset ); n_freq < tmp2; n_freq++ ) + { + factor_fx = shl( i, 12 ); /*15 */ + L_tmp1 = L_mult( sub( 32767, factor_fx ), fenvL_fx ); /*17 */ + L_tmp2 = L_mult( factor_fx, wfenv_fx ); /*17 */ + L_tmp1 = L_add( L_tmp1, L_tmp2 ); /*17 */ + + cs = norm_l( L_tmp1 ); + tmp = extract_h( L_shl( L_tmp1, cs ) ); /*17 + cs - 16 */ + L_tmp = Mult_32_16( coeff_out_fx[n_freq], tmp ); /*12 + 15 + 17 + cs - 16 - 15 */ + coeff_out_fx[n_freq] = L_shr( L_tmp, add( 1, cs ) ); + move32(); /*12 */ + i++; + move16(); + } + + k = sub( nenv, 2 ); + FOR( n_band = 0; n_band < k; n_band++ ) + { + wfenv_fx = hq_generic_fenv_fx[n_band + 1]; + move16(); /*1 */ + + tmp2 = swb_bwe_sm_subband[n_band + 1] + hq_generic_offset; + FOR( i = 0; n_freq < tmp2; i++ ) + { + L_tmp1 = L_mult( sub( wfenv_fx, hq_generic_fenv_fx[n_band] ), smooth_factor_fx[n_band] ); /*17 */ + L_tmp1 = Mult_32_16( L_tmp1, shl( i, 10 ) ); /*17 + 10 - 15 */ + L_tmp1 = L_add( L_tmp1, L_shl( hq_generic_fenv_fx[n_band], 11 ) ); /*12 */ + + cs = norm_l( L_tmp1 ); + tmp = extract_h( L_shl( L_tmp1, cs ) ); /*12 + cs - 16 */ + L_tmp = Mult_32_16( coeff_out_fx[n_freq], tmp ); /*12 + 15 + 12 + cs - 16 - 15 */ + coeff_out_fx[n_freq] = L_shl( L_tmp, sub( 4, cs ) ); + move32(); /*12 */ + n_freq++; + } + } + + wfenv_fx = hq_generic_fenv_fx[nenv - 1]; + move16(); /*1 */ + tmp2 = add( swb_bwe_sm_subband[nenv - 1], hq_generic_offset ); + FOR( i = 0; n_freq < tmp2; i++ ) + { + L_tmp1 = L_mult( sub( wfenv_fx, hq_generic_fenv_fx[nenv - 2] ), smooth_factor_fx[nenv - 2] ); /*17 */ + L_tmp1 = Mult_32_16( L_tmp1, shl( i, 10 ) ); /*17 + 10 - 15 */ + L_tmp1 = L_add( L_tmp1, L_shl( hq_generic_fenv_fx[nenv - 2], 11 ) ); /*12 */ + + cs = norm_l( L_tmp1 ); + tmp = extract_h( L_shl( L_tmp1, cs ) ); /*12 + cs - 16 */ + L_tmp = Mult_32_16( coeff_out_fx[n_freq], tmp ); /*12 + 15 + 12 + cs - 16 - 15 */ + coeff_out_fx[n_freq] = L_shl( L_tmp, sub( 4, cs ) ); + move32(); /*12 */ + n_freq++; + } + + IF( EQ_16( HQ_mode, HQ_GEN_SWB ) ) + { + FOR( n_band = sub( nenv, 1 ); n_band < nenv; ++n_band ) + { + wfenv_fx = hq_generic_fenv_fx[n_band]; + move16(); /*1 */ + tmp2 = add( swb_bwe_subband[n_band + 1], hq_generic_offset ); + FOR( ; n_freq < tmp2; n_freq++ ) + { + L_tmp = Mult_32_16( coeff_out_fx[n_freq], wfenv_fx ); /*15 + 12 + 1 - 15 */ + coeff_out_fx[n_freq] = L_shr( L_tmp, 1 ); + move32(); /*12 */ + } + } + } + ELSE + { + test(); + IF( GT_16( sub( hq_generic_fenv_fx[nenv - 1], hq_generic_fenv_fx[nenv] ), 30 ) || LT_16( hq_generic_fenv_fx[nenv], 10 ) ) + { + wfenv_fx = hq_generic_fenv_fx[nenv - 1]; + move16(); /*1 */ + FOR( i = 0; n_freq < fb_bwe_subband[0]; i++ ) + { + L_tmp = Mult_32_16( coeff_out_fx[n_freq], wfenv_fx ); /*15 + 12 + 1 - 15 */ + coeff_out_fx[n_freq] = L_shr( L_tmp, 1 ); + move32(); /*12 */ + n_freq++; + } + + FOR( n_band = 0; n_band < DIM_FB; n_band++ ) + { + wfenv_fx = hq_generic_fenv_fx[n_band + nenv]; + move16(); /*1 */ + tmp2 = fb_bwe_subband[n_band + 1]; + FOR( i = 0; n_freq < tmp2; i++ ) + { + L_tmp = Mult_32_16( coeff_out_fx[n_freq], wfenv_fx ); /*15 + 12 + 1 - 15 */ + coeff_out_fx[n_freq] = L_shr( L_tmp, 1 ); + move32(); /*12 */ + n_freq++; + } + } + } + ELSE + { + FOR( n_band = 0; n_band < DIM_FB; n_band++ ) + { + wfenv_fx = hq_generic_fenv_fx[n_band + nenv - 1]; + move16(); /*1 */ + + FOR( i = 0; n_freq < fb_bwe_sm_subband[n_band]; i++ ) + { + L_tmp1 = L_mult( sub( wfenv_fx, hq_generic_fenv_fx[n_band + nenv] ), fb_smooth_factor_fx[n_band] ); /*17 */ + L_tmp1 = Mult_32_16( L_tmp1, shl( i, 9 ) ); /*17 + 9 - 15 */ + L_tmp1 = L_add( L_tmp1, L_shl( hq_generic_fenv_fx[n_band + nenv], 10 ) ); /*11 */ + + cs = norm_l( L_tmp1 ); + tmp = extract_h( L_shl( L_tmp1, cs ) ); /*11 + cs - 16 */ + L_tmp = Mult_32_16( coeff_out_fx[n_freq], tmp ); /*12 + 15 + 11 + cs - 16 - 15 */ + coeff_out_fx[n_freq] = L_shl( L_tmp, sub( 5, cs ) ); + move32(); /*12 */ + n_freq = add( n_freq, 1 ); + } + } + + wfenv_fx = hq_generic_fenv_fx[tenv - 1]; + move16(); /*1 */ + + FOR( ; n_freq < fb_bwe_subband[DIM_FB]; n_freq++ ) + { + L_tmp = Mult_32_16( coeff_out_fx[n_freq], wfenv_fx ); /*15 + 12 + 1 - 15 */ + coeff_out_fx[n_freq] = L_shr( L_tmp, 1 ); + move32(); /*12 */ + } + } + } + + return; +} + /*-------------------------------------------------------------------* * save_old_syn() -- GitLab From dc01d1167c817794bcd534b1b7ee4d8c0488abe1 Mon Sep 17 00:00:00 2001 From: Arun Ganesh Nayak <100918@ittiam.com> Date: Mon, 17 Feb 2025 14:24:39 +0530 Subject: [PATCH 2/2] Fix for 3GPP issue 1285: Assert in ivas_fill_spectrum_fx of BASOP decoder when fed with OMASA bitstream from BASOP encoder --- lib_com/swb_bwe_com_fx.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib_com/swb_bwe_com_fx.c b/lib_com/swb_bwe_com_fx.c index 5cbdd105e..09f72b230 100644 --- a/lib_com/swb_bwe_com_fx.c +++ b/lib_com/swb_bwe_com_fx.c @@ -3338,8 +3338,8 @@ void hq_generic_decoding_ivas_fx( L_tmp2 = L_deposit_l( 0 ); FOR( i = 0; i < 5; ++i ) { - L_tmp1 = L_add( L_tmp1, L_shr( L_abs( coeff_out_fx[HQ_GENERIC_HIGH1 + hq_generic_offset + i] ), 3 ) ); // adding guard bits - L_tmp2 = L_add( L_tmp2, L_shr( L_abs( coeff_out_fx[HQ_GENERIC_HIGH1 - 2 + hq_generic_offset - i] ), 3 ) ); //adding guard bits + L_tmp1 = L_add( L_tmp1, L_shr( L_abs( coeff_out_fx[HQ_GENERIC_HIGH1 + hq_generic_offset + i] ), 3 ) ); // adding guard bits + L_tmp2 = L_add( L_tmp2, L_shr( L_abs( coeff_out_fx[HQ_GENERIC_HIGH1 - 2 + hq_generic_offset - i] ), 3 ) ); // adding guard bits } pit1_fx = &coeff_out_fx[HQ_GENERIC_HIGH1 + hq_generic_offset]; -- GitLab