From 053b6f5d156928c79e7fcf4f8813a22150af960e Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Fri, 5 Jul 2024 12:27:26 +0530 Subject: [PATCH] Addressed comments shared in 3gpp issue 668 [x] Addressed comments in https://forge.3gpp.org/rep/sa4/audio/ivas-basop/-/issues/668 [x] ivas_tools.c and tools.c instrumentation will be addressed in another MR. --- lib_com/hp50.c | 19 ++++++++----------- lib_com/ivas_mdct_imdct_fx.c | 8 ++++---- lib_com/modif_fs.c | 8 ++++++-- lib_dec/ivas_mc_param_dec.c | 12 ++++++------ lib_dec/ivas_sba_rendering_internal.c | 13 ++++++++----- lib_dec/ivas_spar_md_dec.c | 18 ++++++++++++------ lib_dec/ivas_stereo_dft_dec_fx.c | 5 +++++ lib_dec/swb_tbe_dec.c | 4 ++-- lib_rend/ivas_reverb_filter_design.c | 20 ++++---------------- 9 files changed, 55 insertions(+), 52 deletions(-) diff --git a/lib_com/hp50.c b/lib_com/hp50.c index 288d690e3..b080d0431 100644 --- a/lib_com/hp50.c +++ b/lib_com/hp50.c @@ -654,23 +654,18 @@ void hp20_fix32( Qprev_y1 = extract_l( mem_fx[4] ); Qprev_y2 = extract_l( mem_fx[5] ); - y1_fx64 = (Word64) mem_fx[0]; - y2_fx64 = (Word64) mem_fx[1]; - x0_fx64 = (Word64) mem_fx[2]; - x1_fx64 = (Word64) mem_fx[3]; - move64(); - move64(); - move64(); - move64(); + y1_fx64 = W_deposit32_l( mem_fx[0] ); + y2_fx64 = W_deposit32_l( mem_fx[1] ); + x0_fx64 = W_deposit32_l( mem_fx[2] ); + x1_fx64 = W_deposit32_l( mem_fx[3] ); FOR( i = 0; i < lg; i++ ) { x2_fx64 = x1_fx64; - x1_fx64 = x0_fx64; - x0_fx64 = (Word64) signal_fx[i]; - move64(); move64(); + x1_fx64 = x0_fx64; move64(); + x0_fx64 = W_deposit32_l( signal_fx[i] ); Qy1 = W_norm( y1_fx64 ); if ( y1_fx64 == 0 ) @@ -732,9 +727,11 @@ void hp20_fix32( y0_fx64 = W_shr( y0_fx64, 29 ); signal_fx[i] = W_extract_l( W_shr( y0_fx64, Qmin ) ); + move32(); IF( signal_fx[i] < 0 ) { signal_fx[i] = L_add( signal_fx[i], 1 ); + move32(); } y2_fx64 = y1_fx64; diff --git a/lib_com/ivas_mdct_imdct_fx.c b/lib_com/ivas_mdct_imdct_fx.c index cb64739e8..730a2fe7e 100644 --- a/lib_com/ivas_mdct_imdct_fx.c +++ b/lib_com/ivas_mdct_imdct_fx.c @@ -303,9 +303,9 @@ void ivas_imdct_fx( FOR( i = 0; i < len_by_2; i++ ) { - re[i] = L_add( Mpy_32_16_1( pIn[sub( sub( length, imult1616( 2, i ) ), 1 )], pTwid_re[i] ), Mpy_32_16_1( pIn[2 * i], pTwid_im[i] ) ); /*stl_arr_index*/ + re[i] = L_add( Mpy_32_16_1( pIn[sub( sub( length, shl( i, 1 ) ), 1 )], pTwid_re[i] ), Mpy_32_16_1( pIn[2 * i], pTwid_im[i] ) ); /*stl_arr_index*/ move32(); - im[i] = L_sub( Mpy_32_16_1( pIn[2 * i], pTwid_re[i] ), Mpy_32_16_1( pIn[sub( sub( length, imult1616( 2, i ) ), 1 )], pTwid_im[i] ) ); /*stl_arr_index*/ + im[i] = L_sub( Mpy_32_16_1( pIn[2 * i], pTwid_re[i] ), Mpy_32_16_1( pIn[sub( sub( length, shl( i, 1 ) ), 1 )], pTwid_im[i] ) ); /*stl_arr_index*/ move32(); } @@ -328,9 +328,9 @@ void ivas_imdct_fx( FOR( i = ( len_by_2 - 1 ); i >= 0; i-- ) { - re[add( imult1616( 2, i ), 1 )] = im[sub( sub( len_by_2, 1 ), i )]; + re[add( shl( i, 1 ), 1 )] = im[sub( sub( len_by_2, 1 ), i )]; move32(); - re[imult1616( 2, i )] = L_negate( re[i] ); + re[2 * i] = L_negate( re[i] ); move32(); } diff --git a/lib_com/modif_fs.c b/lib_com/modif_fs.c index b4552998d..4bccd568b 100644 --- a/lib_com/modif_fs.c +++ b/lib_com/modif_fs.c @@ -1081,7 +1081,7 @@ void interpolate_3_over_1_allpass_32( Word32 *mem /* i/o: memory */ ) { - Word16 i; + Word16 i, tmp16; Word32 Vu[2], Vm[2], Vl[2]; /* Outputs of three cascaded allpass stages (upper, middle, and lower) */ Word32 *out1; Word32 mem_temp; @@ -1104,6 +1104,7 @@ void interpolate_3_over_1_allpass_32( mem[2] = Vu[1]; move32(); *out1++ = mem[3]; + move32(); /* Middle branch */ Vm[0] = L_add_sat( mem[0], Mpy_32_16_1( L_sub( input[i], mem[4] ), filt_coeff[3] ) ); @@ -1118,6 +1119,7 @@ void interpolate_3_over_1_allpass_32( mem[5] = Vm[1]; move32(); *out1++ = mem[6]; + move32(); /* Lower branch */ Vl[0] = L_add_sat( mem[0], Mpy_32_16_1( L_sub( input[i], mem[7] ), filt_coeff[6] ) ); @@ -1134,10 +1136,12 @@ void interpolate_3_over_1_allpass_32( mem[8] = Vl[1]; move32(); *out1++ = mem[9]; + move32(); } /*LPF*/ - FOR( i = 0; i < len * 3; i++ ) + tmp16 = imult1616( len, 3 ); + FOR( i = 0; i < tmp16; i++ ) { mem_temp = out[i]; move32(); diff --git a/lib_dec/ivas_mc_param_dec.c b/lib_dec/ivas_mc_param_dec.c index d25fff5f8..4887ffa12 100644 --- a/lib_dec/ivas_mc_param_dec.c +++ b/lib_dec/ivas_mc_param_dec.c @@ -6208,7 +6208,7 @@ static void ivas_param_mc_dequantize_cov_fx( tmp_e = Cp_buf_e[add( k, imult1616( nY_int, k ) )]; move16(); - IF( NE_32( Cproto_fx[add( k, imult1616( nY_int, k ) )], 0 ) ) + IF( Cproto_fx[add( k, imult1616( nY_int, k ) )] != 0 ) { L_tmp = ISqrt32( Cproto_fx[add( k, imult1616( nY_int, k ) )], &tmp_e ); } @@ -6269,13 +6269,13 @@ static void ivas_param_mc_dequantize_cov_fx( Cy_state_int_e[hParamMC->hMetadataPMC->icc_mapping[param_frame_idx][k][1] + nY_int * hParamMC->hMetadataPMC->icc_mapping[param_frame_idx][k][0]] = tmp; move16(); #else - Cy_state_int_fx[hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][0] + nY_int * hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][1]] = L_shr( L_deposit_h( icc_q_fx[k] ), tmp ); + Cy_state_int_fx[add( hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][0], imult1616( nY_int, hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][1] ) )] = L_shr( L_deposit_h( icc_q_fx[k] ), tmp ); move32(); - Cy_state_int_e[hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][0] + nY_int * hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][1]] = tmp; + Cy_state_int_e[add( hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][0], imult1616( nY_int, hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][1] ) )] = tmp; move16(); - Cy_state_int_fx[hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][1] + nY_int * hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][0]] = L_shr( L_deposit_h( icc_q_fx[k] ), tmp ); + Cy_state_int_fx[add( hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][1], imult1616( nY_int, hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][0] ) )] = L_shr( L_deposit_h( icc_q_fx[k] ), tmp ); move32(); - Cy_state_int_e[hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][1] + nY_int * hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][0]] = tmp; + Cy_state_int_e[add( hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][1], imult1616( nY_int, hParamMC->hMetadataPMC->icc_mapping_conf->icc_mapping[k][0] ) )] = tmp; move16(); #endif } @@ -6339,7 +6339,7 @@ static void ivas_param_mc_dequantize_cov_fx( } } - IF( synth_conf == PARAM_MC_SYNTH_LS_CONV_COV ) + IF( EQ_32( synth_conf, PARAM_MC_SYNTH_LS_CONV_COV ) ) { /* Cy = dmx*Cy*dmx' */ Word32 mat_mult_buffer1_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS]; diff --git a/lib_dec/ivas_sba_rendering_internal.c b/lib_dec/ivas_sba_rendering_internal.c index 03b5eb85c..e925bd3e6 100644 --- a/lib_dec/ivas_sba_rendering_internal.c +++ b/lib_dec/ivas_sba_rendering_internal.c @@ -200,6 +200,7 @@ void ivas_sba2mc_cldfb_fixed( * * MC signals transformed into SBA in TD domain *-------------------------------------------------------------------------*/ + #ifdef IVAS_FLOAT_FIXED void ivas_mc2sba_fx( IVAS_OUTPUT_SETUP hIntSetup, /* i : Format of decoder output */ @@ -233,6 +234,7 @@ void ivas_mc2sba_fx( move16(); FOR( i = 0; i < add( hIntSetup.nchan_out_woLFE, hIntSetup.num_lfe ); i++ ) { + test(); IF( ( hIntSetup.num_lfe > 0 ) && EQ_16( i, hIntSetup.index_lfe[idx_lfe] ) ) { IF( gain_lfe_fx > 0 ) @@ -245,16 +247,16 @@ void ivas_mc2sba_fx( } } - IF( LT_16( idx_lfe, sub( hIntSetup.num_lfe, 1 ) ) ) + if ( LT_16( idx_lfe, sub( hIntSetup.num_lfe, 1 ) ) ) { idx_lfe = add( idx_lfe, 1 ); } } ELSE { - azimuth = (Word16) L_shr( hIntSetup.ls_azimuth_fx[idx_in], 22 ); + azimuth = extract_l( L_shr( hIntSetup.ls_azimuth_fx[idx_in], Q22 ) ); move16(); - elevation = (Word16) L_shr( hIntSetup.ls_elevation_fx[idx_in], 22 ); + elevation = extract_l( L_shr( hIntSetup.ls_elevation_fx[idx_in], Q22 ) ); move16(); idx_in = add( idx_in, 1 ); ivas_dirac_dec_get_response_fx( @@ -284,7 +286,6 @@ void ivas_mc2sba_fx( return; } #else - void ivas_mc2sba( IVAS_OUTPUT_SETUP hIntSetup, /* i : Format of decoder output */ float *in_buffer_td[], /* i : MC signals (on input) and the HOA3 (on output) */ @@ -362,6 +363,7 @@ void ivas_mc2sba( } #endif + /*-------------------------------------------------------------------------* * ivas_param_mc_mc2sba_cldfb() * @@ -402,6 +404,7 @@ void ivas_param_mc_mc2sba_cldfb_fx( FOR( idx_ch = 0; idx_ch < add( hTransSetup.nchan_out_woLFE, hTransSetup.num_lfe ); idx_ch++ ) { + test(); IF( ( hTransSetup.num_lfe > 0 ) && EQ_16( idx_ch, hTransSetup.index_lfe[idx_lfe] ) ) { IF( gain_lfe_fx > 0 ) @@ -413,7 +416,7 @@ void ivas_param_mc_mc2sba_cldfb_fx( move32(); } - IF( LT_16( idx_lfe, sub( hTransSetup.num_lfe, 1 ) ) ) + if ( LT_16( idx_lfe, sub( hTransSetup.num_lfe, 1 ) ) ) { idx_lfe = add( idx_lfe, 1 ); } diff --git a/lib_dec/ivas_spar_md_dec.c b/lib_dec/ivas_spar_md_dec.c index 50ca91a30..6e7f24878 100644 --- a/lib_dec/ivas_spar_md_dec.c +++ b/lib_dec/ivas_spar_md_dec.c @@ -4079,6 +4079,7 @@ static void ivas_spar_md_fill_invalid_bandcoeffs( * * *-----------------------------------------------------------------------------------------*/ + #ifdef IVAS_FLOAT_FIXED static void ivas_spar_dec_compute_ramp_down_post_matrix_fx( ivas_spar_md_dec_state_t *hMdDec, @@ -4091,20 +4092,22 @@ static void ivas_spar_dec_compute_ramp_down_post_matrix_fx( num_out_ch = hMdDec->spar_md_cfg.num_umx_chs; move16(); move16(); - IF( EQ_16( bfi, 0 ) ) + IF( bfi == 0 ) { hMdDec->spar_plc_num_lost_frames = 0; move16(); } ELSE { - IF( EQ_16( hMdDec->td_decorr_flag, 0 ) ) + IF( hMdDec->td_decorr_flag == 0 ) { assert( 0 ); } hMdDec->spar_plc_num_lost_frames = add( hMdDec->spar_plc_num_lost_frames, 1 ); + move16(); hMdDec->spar_plc_num_lost_frames = s_min( hMdDec->spar_plc_num_lost_frames, 100 ); /*hMdDec->spar_plc_num_lost_frames is always <=100*/ + move16(); IF( GT_16( hMdDec->spar_plc_num_lost_frames, ivas_spar_dec_plc_num_frames_keep ) ) /*if control enters then ivas_spar_dec_plc_num_frames_keep<100 */ { @@ -4118,13 +4121,15 @@ static void ivas_spar_dec_compute_ramp_down_post_matrix_fx( num_fade_frames = s_max( sub( hMdDec->spar_plc_num_lost_frames, ivas_spar_dec_plc_num_frames_keep ), 0 ); norm_nff = norm_s( num_fade_frames ); gain_dB = -imult1616( s_min( num_fade_frames, ivas_spar_dec_plc_max_num_frames_ramp_down ), ivas_spar_dec_plc_per_frame_ramp_down_gain_dB ); /*abs(gain_dB)<99*/ /*Q(gain_dB)=7Q24*/ - Word16 exp_gain = 0; /*stores exponent for gain_fx*/ + Word16 exp_gain; /*stores exponent for gain_fx*/ gain_fx = BASOP_util_Pow2( Mult_32_16( imult3216( 13421773 /*=2^28/20*/, gain_dB ), 27213 /*=log2(10)*2^13*/ ), 5, &exp_gain ); Q_gain = sub( 31, exp_gain ); FOR( i = 0; i < IVAS_SPAR_MAX_CH; i++ ) { post_matrix_fx[i] = add( shl( 1, norm_nff ), mult( s_min( mult( shl( num_fade_frames, norm_nff ), 3640 /* 1 / ivas_spar_dec_plc_num_frames_fade_out in Q15 */ ), shl( 1, norm_nff ) ), shl( sub( ivas_spar_dec_plc_spatial_target[i], 1 ), 15 ) ) ); /*Q=norm_nff*/ - post_matrix_fx[i] = Mult_32_16( gain_fx, (Word16) post_matrix_fx[i] ); /*Q_gain+norm_nff-15*/ + move32(); + post_matrix_fx[i] = Mult_32_16( gain_fx, extract_l( post_matrix_fx[i] ) ); /*Q_gain+norm_nff-15*/ + move32(); } Q_post_matrix = sub( add( Q_gain, norm_nff ), 15 ); /* apply the post matrix */ @@ -4136,19 +4141,20 @@ static void ivas_spar_dec_compute_ramp_down_post_matrix_fx( { FOR( b = 0; b < num_bands_out; b++ ) { - hMdDec->mixer_mat_fx[i][j][b + i_ts * IVAS_MAX_NUM_BANDS] = Mult_32_32( hMdDec->mixer_mat_fx[i][j][b + i_ts * IVAS_MAX_NUM_BANDS], post_matrix_fx[i] ); + hMdDec->mixer_mat_fx[i][j][add( b, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )] = Mult_32_32( hMdDec->mixer_mat_fx[i][j][add( b, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )], post_matrix_fx[i] ); + move32(); } } } } hMdDec->Q_mixer_mat = sub( add( Q_post_matrix, hMdDec->Q_mixer_mat ), 31 ); + move16(); } } return; } #else - static void ivas_spar_dec_compute_ramp_down_post_matrix( ivas_spar_md_dec_state_t *hMdDec, const int16_t num_bands_out, diff --git a/lib_dec/ivas_stereo_dft_dec_fx.c b/lib_dec/ivas_stereo_dft_dec_fx.c index 6f0775a9a..87831a269 100644 --- a/lib_dec/ivas_stereo_dft_dec_fx.c +++ b/lib_dec/ivas_stereo_dft_dec_fx.c @@ -2461,18 +2461,22 @@ static void stereo_dft_dequantize_ipd_fx( IF( EQ_16( bits, 2 ) ) /* 2-bit phase quantization for the highest frequency band only */ { delta_fx = ( EVS_PI_FX ) >> 1; + move16(); } ELSE IF( EQ_16( bits, 3 ) ) { delta_fx = ( EVS_PI_FX ) >> 2; + move16(); } ELSE IF( EQ_16( bits, 4 ) ) { delta_fx = ( EVS_PI_FX ) >> 3; + move16(); } ELSE { delta_fx = ( EVS_PI_FX ) >> 2; + move16(); assert( 0 ); } @@ -2480,6 +2484,7 @@ static void stereo_dft_dequantize_ipd_fx( { temp_out = L_sub( L_mult0( ind[i], delta_fx ), ( EVS_PI_FX ) ); *out_fx = L_shl( temp_out, 14 ); + move32(); } return; } diff --git a/lib_dec/swb_tbe_dec.c b/lib_dec/swb_tbe_dec.c index 2b1bd7f63..613e82b3f 100644 --- a/lib_dec/swb_tbe_dec.c +++ b/lib_dec/swb_tbe_dec.c @@ -4610,7 +4610,7 @@ void GenTransition_fixed( { IF( i % 2 == 0 ) { - syn_overlap_32k_fx[i] = -syn_overlap_32k_fx[i]; + syn_overlap_32k_fx[i] = L_negate( syn_overlap_32k_fx[i] ); move32(); } ELSE @@ -4729,7 +4729,7 @@ void GenTransition_WB_fixed( { IF( i % 2 == 0 ) { - speech_buf_16k2_fx[i] = -speech_buf_16k2_fx[i]; + speech_buf_16k2_fx[i] = L_negate( speech_buf_16k2_fx[i] ); move32(); } ELSE diff --git a/lib_rend/ivas_reverb_filter_design.c b/lib_rend/ivas_reverb_filter_design.c index 8ffc766d4..b293d6e22 100644 --- a/lib_rend/ivas_reverb_filter_design.c +++ b/lib_rend/ivas_reverb_filter_design.c @@ -277,6 +277,7 @@ static void calc_min_phase_fx( Word16 guarded_bits; guarded_bits = find_guarded_bits_fx( fft_size ); *q_pCepstrum = sub( L_norm_arr( pCepstrum, fft_size ), guarded_bits ); + move16(); FOR( Word16 j = 0; j < fft_size; j++ ) { @@ -284,6 +285,7 @@ static void calc_min_phase_fx( move32(); } *q_pCepstrum = add( *q_pCepstrum, 26 ); + move16(); /* Compute the real pCepstrum of the log amplitude spectrum */ fft_rel_fx32( pCepstrum, fft_size, log2_fft_size ); @@ -295,14 +297,6 @@ static void calc_min_phase_fx( pCepstrum[idx] = Mpy_32_32( pCepstrum[idx], scale_factor ); // q = q_pCepstrum move32(); } -#if 0 - guarded_bits = L_norm_arr(pCepstrum, fft_size); - FOR(Word16 j = 0; j < fft_size; j++) - { - pCepstrum[j] = L_shl(pCepstrum[j], guarded_bits - 3); - } - q_pCepstrum += guarded_bits - 3; -#endif /* Fold the pCepstrum to ensure that zeros outside the unit circle move inside it, making it minimum phase. */ pFolded_cepstrum_re[0] = pCepstrum[0]; move32(); @@ -313,7 +307,7 @@ static void calc_min_phase_fx( { pFolded_cepstrum_re[idx] = L_shl( pCepstrum[idx], 1 ); // q = q_pCepstrum move32(); - pFolded_cepstrum_im[idx] = L_negate( L_shl( pCepstrum[fft_size - idx], 1 ) ); // q = q_pCepstrum + pFolded_cepstrum_im[idx] = L_negate( L_shl( pCepstrum[sub( fft_size, idx )], 1 ) ); // q = q_pCepstrum move32(); /* Note: sign inverted because of fft rather than ifft used before */ } @@ -344,13 +338,7 @@ static void calc_min_phase_fx( IF( LE_16( fft_size, 512 ) ) /* for size <= 512 using complex-value FFT (more effecient, but available only up to 512 size) */ { DoRTFTn_fx_ivas( pFolded_cepstrum_re, pFolded_cepstrum_im, fft_size ); - // guarded_bits = L_norm_arr(pFolded_cepstrum_im, fft_size); -#if 0 - FOR(Word16 j = 0; j < fft_size; j++) - { - pFolded_cepstrum_im[j] = L_shl(pFolded_cepstrum_im[j], 30 - *q_pCepstrum); - } -#endif + /* Copying the img part into the output */ FOR( idx = 1; idx < half_fft_size; idx++ ) { -- GitLab