diff --git a/lib_dec/FEC_HQ_phase_ecu_fx.c b/lib_dec/FEC_HQ_phase_ecu_fx.c index a98bd9b3083690a36c013f1f53d1b2b2595a08c2..99dfd8be50fe62573c0c717ca13c4704815fb357 100644 --- a/lib_dec/FEC_HQ_phase_ecu_fx.c +++ b/lib_dec/FEC_HQ_phase_ecu_fx.c @@ -2251,7 +2251,7 @@ static void ivas_subst_spec_fx( tmp = sub( tmp, ph_ecu_lookahead ); tmp = add( tmp, sub( Lecu, shr( sub( Lecu, Lprot ), 1 ) ) ); tmp = sub( tmp, shr( output_frame, 1 ) ); - tmp1 = L_add( L_mult0( tmp, Lprot_inv ), L_mult0( time_offs, Lprot_inv ) ); /* Q22 */ + tmp1 = L_mac0( L_mult0( tmp, Lprot_inv ), time_offs, Lprot_inv ); /* Q22 */ pPlocsi = plocsi; pCorrPhase = corr_phase; diff --git a/lib_dec/fd_cng_dec_fx.c b/lib_dec/fd_cng_dec_fx.c index dc234e502b4d5e9ea14bbf198b185136f793e1af..de5474bd4a7d6b5a6b80563856e50f921b7541c9 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 = 671089; // 4/(640 * 640) in Q36 + rescale_fac = 335544; // 4/(640 * 640) in Q35 move32(); BREAK; case 512: - rescale_fac = 1048576; // 4/(512 * 512) in Q36 + rescale_fac = 524288; // 4/(512 * 512) in Q35 move32(); BREAK; case 320: - rescale_fac = 2684354; // 4/(320 * 320) in Q36 + rescale_fac = 1342177; // 4/(320 * 320) in Q35 move32(); BREAK; default: @@ -2538,7 +2538,7 @@ void perform_noise_estimation_dec_ivas_fx( ptr_i += 2; } - hFdCngDec->hFdCngCom->periodog_exp = sub( 31 - 5, min_q ); + hFdCngDec->hFdCngCom->periodog_exp = sub( 31 - 4, min_q ); hFdCngDec->hFdCngCom->fftBuffer_exp = fftBuffer_exp; move16(); move16(); @@ -2581,6 +2581,19 @@ void perform_noise_estimation_dec_ivas_fx( { i = 0; move16(); + + /* This is done to avoid overflow when checking "if ( msPeriodog[p] < 1e-5f )" */ + IF( LT_16( hFdCngDec->msPeriodog_exp, -16 ) ) + { + FOR( p = 0; p < NPART_SHAPING; p++ ) + { + msPeriodog[p] = L_shr( msPeriodog[p], sub( -16, hFdCngDec->msPeriodog_exp ) ); + move32(); + } + hFdCngDec->msPeriodog_exp = -16; + move16(); + } + FOR( p = 0; p < npart; p++ ) { /* calculate variance over all bins in power partition */ diff --git a/lib_dec/ivas_mc_param_dec.c b/lib_dec/ivas_mc_param_dec.c index 10077e345eedc9427dbb6b9fa93272e948c03f9f..96835b219d94f29657782da3630e0cf21edffd2d 100644 --- a/lib_dec/ivas_mc_param_dec.c +++ b/lib_dec/ivas_mc_param_dec.c @@ -3499,12 +3499,11 @@ void ivas_param_mc_dec_render_fx( move16(); } } - } - - IF( is_zero ) - { - hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_exp[j] = 0; - move16(); + IF( is_zero ) + { + hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_exp[j] = 0; + move16(); + } } } FOR( subframe_idx = first_sf; subframe_idx < last_sf; subframe_idx++ ) @@ -5078,8 +5077,6 @@ static void ivas_param_mc_get_mixing_matrices_fx( Word16 proto_matrix_noLFE_e = 0; move16(); - Word16 guard_bit_cx = find_guarded_bits_fx( nY_intern + 1 ); - Word16 guard_bit_cy = find_guarded_bits_fx( nY_cov * nY_cov ); Word32 Cx_in_fx[PARAM_MC_MAX_PARAMETER_BANDS][PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS]; @@ -5213,39 +5210,8 @@ static void ivas_param_mc_get_mixing_matrices_fx( /* smoothing gains are now identical to one, simply add up */ // v_add( Cy_state, Cy_old_state, Cy_full, nY_cov * nY_cov ); - tmp_e = add( s_max( hParamMC->h_output_synthesis_cov_state.cx_old_e[param_band_idx], Cx_state_e ), guard_bit_cx ); - FOR( i = 0; i < nX * nX; i++ ) - { - Cx_old_state_fx[i] = L_shr( Cx_old_state_fx[i], sub( tmp_e, hParamMC->h_output_synthesis_cov_state.cx_old_e[param_band_idx] ) ); - move32(); - Cx_state_fx[i] = L_shr( Cx_state_fx[i], sub( tmp_e, Cx_state_e ) ); - move32(); - } - - hParamMC->h_output_synthesis_cov_state.cx_old_e[param_band_idx] = tmp_e; - move16(); - Cx_state_e = tmp_e; - move16(); - tmp_e = add( s_max( hParamMC->h_output_synthesis_cov_state.cy_old_e[param_band_idx], Cy_state_e ), guard_bit_cy ); - FOR( i = 0; i < imult1616( nY_cov, nY_cov ); i++ ) - { - Cy_old_state_fx[i] = L_shr( Cy_old_state_fx[i], sub( tmp_e, hParamMC->h_output_synthesis_cov_state.cy_old_e[param_band_idx] ) ); - move32(); - Cy_state_fx[i] = L_shr( Cy_state_fx[i], sub( tmp_e, Cy_state_e ) ); - move32(); - } - - hParamMC->h_output_synthesis_cov_state.cy_old_e[param_band_idx] = tmp_e; - Cy_state_e = tmp_e; - move16(); - - v_add_32( Cx_state_fx, Cx_old_state_fx, Cx_fx, imult1616( nX, nX ) ); - v_add_32( Cy_state_fx, Cy_old_state_fx, Cy_full_fx, imult1616( nY_cov, nY_cov ) ); - - Cy_full_e = Cy_state_e; - move16(); - Cx_e = Cx_state_e; - move16(); + v_add_fixed_me( Cx_state_fx, Cx_state_e, Cx_old_state_fx, hParamMC->h_output_synthesis_cov_state.cx_old_e[param_band_idx], Cx_fx, &Cx_e, imult1616( nX, nX ), 1 ); + v_add_fixed_me( Cy_state_fx, Cy_state_e, Cy_old_state_fx, hParamMC->h_output_synthesis_cov_state.cy_old_e[param_band_idx], Cy_full_fx, &Cy_full_e, imult1616( nY_cov, nY_cov ), 1 ); } Copy32( Cx_state_fx, Cx_old_state_fx, imult1616( nX, nX ) ); @@ -5304,32 +5270,8 @@ static void ivas_param_mc_get_mixing_matrices_fx( matrix_product_fx( proto_matrix_ptr_fx, nY_band, nX, 0, Cx_fx, nX, nX, 0, mat_mult_buffer1_fx ); mat_mult_buffer1_e = add( proto_matrix_ptr_e, Cx_e ); - Word16 guard_bits = find_guarded_bits_fx( add( nY_band, 1 ) ); - - FOR( i = 0; i < imult1616( nY_band, nX ); ++i ) - { - proto_matrix_ptr_fx[i] = L_shr( proto_matrix_ptr_fx[i], guard_bits ); - move32(); - mat_mult_buffer1_fx[i] = L_shr( mat_mult_buffer1_fx[i], guard_bits ); - move32(); - } - - proto_matrix_ptr_e = add( proto_matrix_ptr_e, guard_bits ); - mat_mult_buffer1_e = add( mat_mult_buffer1_e, guard_bits ); - matrix_product_diag_fx( mat_mult_buffer1_fx, mat_mult_buffer1_e, nY_band, nX, 0, proto_matrix_ptr_fx, proto_matrix_ptr_e, nY_band, nX, 1, Cproto_diag_fx, &Cproto_diag_e ); - FOR( i = 0; i < imult1616( nY_band, nX ); ++i ) - { - proto_matrix_ptr_fx[i] = L_shl( proto_matrix_ptr_fx[i], guard_bits ); - move32(); - mat_mult_buffer1_fx[i] = L_shl( mat_mult_buffer1_fx[i], guard_bits ); - move32(); - } - - proto_matrix_ptr_e = sub( proto_matrix_ptr_e, guard_bits ); - mat_mult_buffer1_e = sub( mat_mult_buffer1_e, guard_bits ); - /* make sure we have no negative entries in Cproto_diag due to rounding errors */ FOR( ch_idx1 = 0; ch_idx1 < nY_band; ch_idx1++ ) diff --git a/lib_dec/ivas_mdct_core_dec.c b/lib_dec/ivas_mdct_core_dec.c index 7a9785b6f172997a11cee6c58967771cebd2645a..684f941168b470a67838cbbc6cfe554516d1d532 100644 --- a/lib_dec/ivas_mdct_core_dec.c +++ b/lib_dec/ivas_mdct_core_dec.c @@ -2103,7 +2103,7 @@ void ivas_mdct_core_reconstruct_fx( } decoder_tcx_post_ivas_fx( st, synth_fx, synthFB_fx, NULL, bfi, MCT_flag ); - sf = getScaleFactor16( synth_buf_fx, add( add( st->hTcxDec->old_synth_len, L_FRAME_PLUS ), M ) ); + sf = s_min( getScaleFactor16( synth_buf_fx, add( add( st->hTcxDec->old_synth_len, L_FRAME_PLUS ), M ) ), getScaleFactor16( synth_bufFB_fx, add( add( st->hTcxDec->old_synth_lenFB, L_FRAME_PLUS ), M ) ) ); IF( LT_16( sf, 2 ) ) { q_syn = sub( sf, 2 ); diff --git a/lib_dec/ivas_sba_dirac_stereo_dec_fx.c b/lib_dec/ivas_sba_dirac_stereo_dec_fx.c index 3804609bf9ab1e4907879b9904c34d41e1f3298b..faf5711c234ce3dd5113b8887d0768aad0886213 100644 --- a/lib_dec/ivas_sba_dirac_stereo_dec_fx.c +++ b/lib_dec/ivas_sba_dirac_stereo_dec_fx.c @@ -1234,6 +1234,8 @@ void ivas_sba_dirac_stereo_dec_fx( Word32 DFT[CPE_CHANNELS][STEREO_DFT_BUF_MAX]; Word16 q_dft[2] = { 0, 0 }; Word16 q = 0; + Word16 q_synth = 0; + move16(); SCE_DEC_HANDLE hSCE; CPE_DEC_HANDLE hCPE; STEREO_DFT_DEC_DATA_HANDLE hStereoDft; @@ -1309,6 +1311,10 @@ void ivas_sba_dirac_stereo_dec_fx( /* do updates here after skipping this in SCE decoder (needs to be done after core switching) */ ivas_updt_dec_common_fx( hSCE->hCoreCoder[0], NORMAL_HQ_CORE, -1, hSCE->save_synth_fx, q ); + + q_synth = sub( getScaleFactor32( tmp_synth, hSCE->hCoreCoder[0]->L_frame ), 10 ); + scale_sig32( tmp_synth, hSCE->hCoreCoder[0]->L_frame, q_synth ); + q_synth = add( q_synth, hSCE->q_save_synth_fx ); } /* mapping of DirAC parameters (azimuth, elevation, diffuseness) to DFT Stereo parameters (side gain, prediction gain) */ @@ -1318,7 +1324,7 @@ void ivas_sba_dirac_stereo_dec_fx( test(); map_params_dirac_to_stereo( hStereoDft, st_ivas->hQMetaData, tmp_synth, DFT[0], st_ivas->ivas_format == MC_FORMAT, ( ( NE_16( st_ivas->ivas_format, SBA_FORMAT ) && NE_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) || mcmasa ) ? hSCE->hCoreCoder[0]->L_frame : output_frame, - ( ( NE_16( st_ivas->ivas_format, SBA_FORMAT ) && NE_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) || mcmasa ), hSCE != NULL ? hSCE->q_save_synth_fx : 0 ); + ( ( NE_16( st_ivas->ivas_format, SBA_FORMAT ) && NE_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) || mcmasa ), hSCE != NULL ? q_synth : 0 ); IF( ( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) || EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) && !mcmasa ) {