From 844239a6923b81064f5cca1ed069ee2c5bc0533c Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Sun, 25 Aug 2024 20:45:31 +0530 Subject: [PATCH] MLD improvements --- lib_dec/core_switching_dec_fx.c | 4 +- lib_dec/ivas_mc_param_dec.c | 4 +- lib_dec/ivas_tcx_core_dec.c | 2 +- lib_rend/ivas_dirac_decorr_dec.c | 45 ++++++++++++++++++---- lib_rend/ivas_dirac_rend.c | 65 +++++++++++++++++++++++--------- 5 files changed, 89 insertions(+), 31 deletions(-) diff --git a/lib_dec/core_switching_dec_fx.c b/lib_dec/core_switching_dec_fx.c index f2c94e09d..97ac2de0b 100644 --- a/lib_dec/core_switching_dec_fx.c +++ b/lib_dec/core_switching_dec_fx.c @@ -2193,9 +2193,7 @@ ivas_error core_switching_post_dec_ivas_fx( set16_fx( hBWE_TD->int_3_over_2_tbemem_dec_fx, 0, INTERP_3_2_MEM_LEN ); set32_fx( hBWE_TD->int_3_over_2_tbemem_dec_fx_32, 0, INTERP_3_2_MEM_LEN ); } - ELSE IF( ( EQ_16( st_fx->extl, SWB_TBE ) || EQ_16( st_fx->extl, FB_TBE ) ) && - ( NE_32( st_fx->last_total_brate, st_fx->total_brate ) || NE_16( st_fx->last_bwidth, st_fx->bwidth ) || - NE_16( st_fx->last_codec_mode, MODE1 ) || NE_16( st_fx->rf_flag, st_fx->rf_flag_last ) ) ) + ELSE IF( ( EQ_16( st_fx->extl, SWB_TBE ) || EQ_16( st_fx->extl, FB_TBE ) ) && ( ( EQ_16( st_fx->element_mode, IVAS_CPE_TD ) && NE_16( st_fx->last_extl, SWB_TBE ) && NE_16( st_fx->last_extl, FB_TBE ) ) || ( NE_16( st_fx->element_mode, IVAS_CPE_TD ) && NE_32( st_fx->last_total_brate, st_fx->total_brate ) ) || NE_16( st_fx->last_bwidth, st_fx->bwidth ) || NE_16( st_fx->last_codec_mode, MODE1 ) || NE_16( st_fx->rf_flag, st_fx->rf_flag_last ) ) ) { set16_fx( hBWE_TD->state_lpc_syn_fx, 0, LPC_SHB_ORDER ); set16_fx( hBWE_TD->state_syn_shbexc_fx, 0, L_SHB_LAHEAD ); diff --git a/lib_dec/ivas_mc_param_dec.c b/lib_dec/ivas_mc_param_dec.c index f8411d5bf..09cacd4f1 100644 --- a/lib_dec/ivas_mc_param_dec.c +++ b/lib_dec/ivas_mc_param_dec.c @@ -1578,7 +1578,7 @@ ivas_error ivas_param_mc_dec_reconfig_fx( v_add_fixed_me( tmp_buf_fx, cov_state_old.cy_old_e[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx]], hParamMC->h_output_synthesis_cov_state.cy_old_fx[new_param_band_idx], hParamMC->h_output_synthesis_cov_state.cy_old_e[new_param_band_idx], hParamMC->h_output_synthesis_cov_state.cy_old_fx[new_param_band_idx], &hParamMC->h_output_synthesis_cov_state.cy_old_e[new_param_band_idx], imult1616( nchan_out_cov, nchan_out_cov ), 0 ); /* mixing matrix*/ v_multc_fixed_16( cov_state_old.mixing_matrix_old_fx[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx]], parameter_band_mapping.source_band_factor_fx[new_param_band_idx][source_param_idx], tmp_buf_fx, imult1616( nchan_transport_old, nchan_out_cov ) ); - v_add_fx( tmp_buf_fx, hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_fx[new_param_band_idx], hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_fx[new_param_band_idx], imult1616( nchan_transport_old, nchan_out_cov ) ); + v_add_fixed_me( tmp_buf_fx, cov_state_old.mixing_matrix_old_exp[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx]], hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_fx[new_param_band_idx], hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_exp[new_param_band_idx], hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_fx[new_param_band_idx], &hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_exp[new_param_band_idx], imult1616( nchan_transport_old, nchan_out_cov ), 0 ); } } FOR( new_param_band_idx = 0; new_param_band_idx < max_param_band_residual; new_param_band_idx++ ) @@ -1587,7 +1587,7 @@ ivas_error ivas_param_mc_dec_reconfig_fx( { /* residual mixing matrix*/ v_multc_fixed_16( cov_state_old.mixing_matrix_res_old_fx[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx]], parameter_band_mapping.source_band_factor_fx[new_param_band_idx][source_param_idx], tmp_buf_fx, imult1616( nchan_out_cov, nchan_out_cov ) ); - v_add_fx( tmp_buf_fx, hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old_fx[new_param_band_idx], hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old_fx[new_param_band_idx], imult1616( nchan_out_cov, nchan_out_cov ) ); + v_add_fixed_me( tmp_buf_fx, cov_state_old.mixing_matrix_res_old_exp[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx]], hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old_fx[new_param_band_idx], hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old_exp[new_param_band_idx], hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old_fx[new_param_band_idx], &hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old_exp[new_param_band_idx], imult1616( nchan_out_cov, nchan_out_cov ), 0 ); } } } diff --git a/lib_dec/ivas_tcx_core_dec.c b/lib_dec/ivas_tcx_core_dec.c index c1d9e2f35..7b8e6c48b 100644 --- a/lib_dec/ivas_tcx_core_dec.c +++ b/lib_dec/ivas_tcx_core_dec.c @@ -733,7 +733,7 @@ void stereo_tcx_core_dec_fx( TonalMDCTConceal_SaveTimeSignal( st->hTonalMDCTConc, synthFB_fx, hTcxDec->L_frameTCX ); } - decoder_tcx_post_fx( st, synth_fx, synthFB_fx, Aq_fx, bfi ); + decoder_tcx_post_ivas_fx( st, synth_fx, synthFB_fx, Aq_fx, bfi, 0 ); IF( EQ_16( st->core, TCX_20_CORE ) ) { diff --git a/lib_rend/ivas_dirac_decorr_dec.c b/lib_rend/ivas_dirac_decorr_dec.c index cbcc63812..b1281b6a2 100644 --- a/lib_rend/ivas_dirac_decorr_dec.c +++ b/lib_rend/ivas_dirac_decorr_dec.c @@ -1425,16 +1425,45 @@ void ivas_dirac_dec_decorr_process_fx( *-----------------------------------------------------------------*/ q_shift = sub( q_input_frame, q_frame_f ); -#ifdef MSAN_FIX - // scaling it to input q - FOR( ch_idx = 0; ch_idx < num_channels; ++ch_idx ) + Word16 q_if_local = 0; // shift adjust for input_frame_fx values + IF( q_shift > 0 ) { - Scale_sig32( &frame_dec_fx[shl( imult1616( ch_idx, num_freq_bands ), 1 )], shl( max_band_decorr, 1 ), q_shift ); + Word16 sf = MAX_16; + FOR( ch_idx = 0; ch_idx < num_channels; ++ch_idx ) + { + sf = s_min( sf, getScaleFactor32( &frame_dec_fx[shl( imult1616( ch_idx, num_freq_bands ), 1 )], shl( max_band_decorr, 1 ) ) ); + } + sf = s_min( sub( sf, 1 ), q_shift ); + q_if_local = sub( q_shift, sf ); + q_shift = sf; + move16(); + // scaling it to sf +#ifdef MSAN_FIX + FOR( ch_idx = 0; ch_idx < num_channels; ++ch_idx ) + { + scale_sig32( &frame_dec_fx[shl( imult1616( ch_idx, num_freq_bands ), 1 )], shl( max_band_decorr, 1 ), q_shift ); + } +#else + Scale_sig32( frame_dec_fx, ( 2 * max_band_decorr + incr_aux ) * num_channels, q_shift ); // scaling it to input q +#endif + q_frame_f = add( q_frame_f, sf ); } + ELSE IF( q_shift < 0 ) + { + // scaling it to input q +#ifdef MSAN_FIX + FOR( ch_idx = 0; ch_idx < num_channels; ++ch_idx ) + { + scale_sig32( &frame_dec_fx[shl( imult1616( ch_idx, num_freq_bands ), 1 )], shl( max_band_decorr, 1 ), q_shift ); + } #else - Scale_sig32( frame_dec_fx, ( 2 * max_band_decorr + incr_aux ) * num_channels, q_shift ); // scaling it to input q + Scale_sig32( frame_dec_fx, ( 2 * max_band_decorr + incr_aux ) * num_channels, q_shift ); // scaling it to input q #endif - q_frame_f = q_input_frame; + q_frame_f = q_input_frame; + q_if_local = 0; + move16(); + move16(); + } move16(); IF( EQ_16( h_freq_domain_decorr_ap_params->add_back_onsets_on, 1 ) ) @@ -1445,8 +1474,8 @@ void ivas_dirac_dec_decorr_process_fx( FOR( k = 0; k < max_band_decorr; ++k ) { - aux_buffer_fx[2 * k] = Mpy_32_32( input_frame_fx[add( shl( offset, 1 ), shl( k, 1 ) )], L_sub( ONE_IN_Q31, onset_filter_fx[add( offset, k )] ) ); - aux_buffer_fx[add( shl( k, 1 ), 1 )] = Mpy_32_32( input_frame_fx[add( add( shl( offset, 1 ), shl( k, 1 ) ), 1 )], L_sub( ONE_IN_Q31, onset_filter_fx[add( offset, k )] ) ); // q_input_f + aux_buffer_fx[2 * k] = Mpy_32_32( L_shr_r( input_frame_fx[add( shl( offset, 1 ), shl( k, 1 ) )], q_if_local ), L_sub( ONE_IN_Q31, onset_filter_fx[add( offset, k )] ) ); + aux_buffer_fx[add( shl( k, 1 ), 1 )] = Mpy_32_32( L_shr_r( input_frame_fx[add( add( shl( offset, 1 ), shl( k, 1 ) ), 1 )], q_if_local ), L_sub( ONE_IN_Q31, onset_filter_fx[add( offset, k )] ) ); // q_frame_f move32(); move32(); } diff --git a/lib_rend/ivas_dirac_rend.c b/lib_rend/ivas_dirac_rend.c index 0d79c6014..9e8733d3f 100644 --- a/lib_rend/ivas_dirac_rend.c +++ b/lib_rend/ivas_dirac_rend.c @@ -2857,6 +2857,9 @@ void protoSignalComputation2_fx( Word32 tempSpaced_fx, tempDmx_fx; Word16 q_shift, min_q_shift, exp, q_temp, temp_q_shift, q_temp2; Word32 temp; + Word64 W_tmp1, W_tmp2; + Word64 reference_power_64fx[CLDFB_NO_CHANNELS_MAX]; + Word16 q_reference_power_64fx; /* Calculate maximum possible shift for the buffers RealBuffer_fx and ImagBuffer_fx */ min_q_shift = Q31; move16(); @@ -2919,11 +2922,15 @@ void protoSignalComputation2_fx( Real_aux_fx = L_add( re1, re2 ); Imag_aux_fx = L_add( im1, im2 ); - Left_power_fx = Madd_32_32( Mpy_32_32( re1, re1 ), im1, im1 ); - Right_power_fx = Madd_32_32( Mpy_32_32( re2, re2 ), im2, im2 ); + // Left_power_fx = Madd_32_32( Mpy_32_32( re1, re1 ), im1, im1 ); + W_tmp1 = W_add( W_mult0_32_32( re1, re1 ), W_mult0_32_32( im1, im1 ) ); // 2*(q_cldfb+min_q_shift) + // Right_power_fx = Madd_32_32( Mpy_32_32( re2, re2 ), im2, im2 ); + W_tmp2 = W_add( W_mult0_32_32( re2, re2 ), W_mult0_32_32( im2, im2 ) ); // 2*(q_cldfb+min_q_shift) - reference_power_fx[l] = L_add( Left_power_fx, Right_power_fx ); - move32(); + + // reference_power_fx[l] = L_add( Left_power_fx, Right_power_fx ); + reference_power_64fx[l] = W_add( W_tmp1, W_tmp2 ); // 2*(q_cldfb+min_q_shift) + move64(); temp = Madd_32_32( Mpy_32_32( Real_aux_fx, Real_aux_fx ), Imag_aux_fx, Imag_aux_fx ); @@ -3055,21 +3062,28 @@ void protoSignalComputation2_fx( Imag_aux_fx = L_add( im1, im2 ); /* Compute reference power */ - Left_power_fx = Madd_32_32( Mpy_32_32( re1, re1 ), im1, im1 ); - Right_power_fx = Madd_32_32( Mpy_32_32( re2, re2 ), im2, im2 ); + // Left_power_fx = Madd_32_32( Mpy_32_32( re1, re1 ), im1, im1 ); + W_tmp1 = W_add( W_mult0_32_32( re1, re1 ), W_mult0_32_32( im1, im1 ) ); // 2*(q_cldfb+min_q_shift) + Left_power_fx = W_extract_l( W_shr( W_tmp1, 31 ) ); + // Right_power_fx = Madd_32_32( Mpy_32_32( re2, re2 ), im2, im2 ); + W_tmp2 = W_add( W_mult0_32_32( re2, re2 ), W_mult0_32_32( im2, im2 ) ); // 2*(q_cldfb+min_q_shift) + Right_power_fx = W_extract_l( W_shr( W_tmp2, 31 ) ); - reference_power_fx[l] = L_add( Left_power_fx, Right_power_fx ); - move32(); + // reference_power_fx[l] = L_add( Left_power_fx, Right_power_fx ); + reference_power_64fx[l] = W_add( W_tmp1, W_tmp2 ); // 2*(q_cldfb+min_q_shift) + move64(); left_bb_power_fx = L_add( left_bb_power_fx, Left_power_fx ); right_bb_power_fx = L_add( right_bb_power_fx, Right_power_fx ); - total_bb_power_fx = L_add( total_bb_power_fx, reference_power_fx[l] ); + // total_bb_power_fx = L_add( total_bb_power_fx, reference_power_fx[l] ); + total_bb_power_fx = L_add( total_bb_power_fx, W_extract_l( W_shr( reference_power_64fx[l], 31 ) ) ); IF( GT_16( l, MASA_HI_FREQ_START_BIN ) ) { left_hi_power_fx = L_add( left_hi_power_fx, Left_power_fx ); right_hi_power_fx = L_add( right_hi_power_fx, Right_power_fx ); - total_hi_power_fx = L_add( total_hi_power_fx, reference_power_fx[l] ); + // total_hi_power_fx = L_add( total_hi_power_fx, reference_power_fx[l] ); + total_hi_power_fx = L_add( total_hi_power_fx, W_extract_l( W_shr( reference_power_64fx[l], 31 ) ) ); } IF( LT_16( l, s_min( num_freq_bands, MASA_SUM_FREQ_RANGE_BINS ) ) ) @@ -3091,7 +3105,7 @@ void protoSignalComputation2_fx( move32(); } - temp = Mpy_32_32( a_fx, reference_power_fx[l] ); + temp = Mpy_32_32( a_fx, W_extract_l( W_shr( reference_power_64fx[l], 31 ) ) ); IF( LT_16( q_temp, stereo_type_detect->q_total_power ) ) { stereo_type_detect->total_power_fx[l] = L_add( temp, L_shr( Mpy_32_32( b_fx, stereo_type_detect->total_power_fx[l] ), sub( stereo_type_detect->q_total_power, q_temp ) ) ); @@ -3552,17 +3566,18 @@ void protoSignalComputation2_fx( Real_aux_fx = L_add( re1, re2 ); Imag_aux_fx = L_add( im1, im2 ); - reference_power_fx[l] = Madd_32_32( Mpy_32_32( Real_aux_fx, Real_aux_fx ), Imag_aux_fx, Imag_aux_fx ); - move32(); + // reference_power_fx[l] = Madd_32_32( Mpy_32_32( Real_aux_fx, Real_aux_fx ), Imag_aux_fx, Imag_aux_fx ); + reference_power_64fx[l] = W_add( W_mult0_32_32( Real_aux_fx, Real_aux_fx ), W_mult0_32_32( Imag_aux_fx, Imag_aux_fx ) ); // 2*(q_cldfb+min_q_shift) + move64(); IF( LT_16( q_temp, *q_proto_power_smooth ) ) { - proto_power_smooth_fx[l] = L_add( L_shr( proto_power_smooth_fx[l], sub( *q_proto_power_smooth, q_temp ) ), reference_power_fx[l] ); + proto_power_smooth_fx[l] = L_add( L_shr( proto_power_smooth_fx[l], sub( *q_proto_power_smooth, q_temp ) ), W_extract_l( W_shr( reference_power_64fx[l], 31 ) ) ); move32(); } ELSE { - proto_power_smooth_fx[l] = L_add( proto_power_smooth_fx[l], L_shr( reference_power_fx[l], sub( q_temp, *q_proto_power_smooth ) ) ); + proto_power_smooth_fx[l] = L_add( proto_power_smooth_fx[l], L_shr( W_extract_l( W_shr( reference_power_64fx[l], 31 ) ), sub( q_temp, *q_proto_power_smooth ) ) ); move32(); } @@ -3603,14 +3618,30 @@ void protoSignalComputation2_fx( move32(); } } + q_reference_power_64fx = shl( add( q_cldfb, min_q_shift ), 1 ); + Word16 norm_shift = 63; + move16(); + FOR( l = 0; l < num_freq_bands; l++ ) + { + IF( reference_power_64fx[l] ) + { + norm_shift = s_min( norm_shift, W_norm( reference_power_64fx[l] ) ); + } + } + FOR( l = 0; l < num_freq_bands; l++ ) + { + reference_power_fx[l] = W_extract_h( W_shl( reference_power_64fx[l], norm_shift ) ); + move32(); + } + *q_reference_power = sub( add( q_reference_power_64fx, norm_shift ), 32 ); + move16(); + *q_proto_frame_f = add( q_cldfb, min_q_shift ); move16(); *q_proto_direct_buffer_f = add( q_cldfb, min_q_shift ); move16(); *q_proto_power_smooth = s_min( *q_proto_power_smooth, q_temp ); move16(); - *q_reference_power = q_temp; - move16(); return; } -- GitLab