From 9332ccdec7af282aceb93b5841e2ec7d358dee7d Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Fri, 27 Jun 2025 10:58:14 +0530 Subject: [PATCH 1/2] Non bit exact optimizations in sba dec path Max MLD deviation observed < 0.1 normalizePanningGains_fx, dirac_out_synth_sfr, ivas_mdct_core_tns_ns_fx, ivas_mct_dec functions changed --- lib_com/ivas_prot_fx.h | 15 +++- lib_com/options.h | 1 + lib_com/prot_fx.h | 8 +- lib_dec/dec_tcx_fx.c | 6 ++ lib_dec/ivas_dirac_output_synthesis_cov_fx.c | 9 +++ lib_dec/ivas_mct_core_dec_fx.c | 25 +++++- lib_dec/ivas_mct_dec_fx.c | 32 +++++++- lib_dec/ivas_mct_dec_mct_fx_fx.c | 29 +++++++ lib_dec/ivas_mdct_core_dec_fx.c | 84 +++++++++++++++++++- lib_dec/ivas_stereo_mdct_core_dec_fx.c | 21 ++++- lib_dec/tonalMDCTconcealment_fx.c | 14 +++- 11 files changed, 231 insertions(+), 13 deletions(-) diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index e35cf648c..9e9e65bb7 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -1575,7 +1575,12 @@ void ivas_mdct_core_tns_ns_fx( Word32 *x_fx[CPE_CHANNELS][NB_DIV], /* o : synthesis @internal_FS */ Word32 Aq_fx[CPE_CHANNELS][( NB_SUBFR16k + 1 ) * ( M + 1 )], /* o : LP coefficients */ const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) */ - Word16 x_e[CPE_CHANNELS][NB_DIV] ); +#ifdef OPT_SBA_DEC_V2_NBE + Word16 x_e +#else /* OPT_SBA_DEC_V2_NBE */ + Word16 x_e[CPE_CHANNELS][NB_DIV] +#endif /* OPT_SBA_DEC_V2_NBE */ +); void decoder_tcx_imdct_fx( Decoder_State *st, /* i/o: coder memory state */ @@ -1936,9 +1941,17 @@ void ivas_mdct_core_invQ_fx( Word16 fUseTns[CPE_CHANNELS][NB_DIV], /* i : flag TNS enabled */ STnsData tnsData[CPE_CHANNELS][NB_DIV], /* i : TNS parameter */ Word32 *x_0[CPE_CHANNELS][NB_DIV], /* i/o: signal buffer */ +#ifdef OPT_SBA_DEC_V2_NBE + Word16 x_0_e, +#else /* OPT_SBA_DEC_V2_NBE */ Word16 x_0_e[CPE_CHANNELS][NB_DIV], +#endif /* OPT_SBA_DEC_V2_NBE */ Word32 *x[CPE_CHANNELS][NB_DIV], /* i/o: signal buffer */ +#ifdef OPT_SBA_DEC_V2_NBE + Word16 x_e, +#else /* OPT_SBA_DEC_V2_NBE */ Word16 x_e[CPE_CHANNELS][NB_DIV], +#endif /* OPT_SBA_DEC_V2_NBE */ Word16 x_len[CPE_CHANNELS][NB_DIV], Word16 Aq[CPE_CHANNELS][( NB_SUBFR16k + 1 ) * ( M + 1 )], /* i : LP coefficients */ Word16 ms_mask[NB_DIV][MAX_SFB], /* i : M/S mask */ diff --git a/lib_com/options.h b/lib_com/options.h index baac02d0d..450b94c16 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -78,6 +78,7 @@ /* Note: each compile switch (FIX_1101_...) is independent from the other ones */ #define OPT_MCT_ENC_V2_NBE +#define OPT_SBA_DEC_V2_NBE #define OPT_MCT_ENC_V1_NBE #define OPT_MCT_ENC_V1_BE #define OPT_SBA_REND_V1_BE diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 666484359..3144c16dd 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -6412,9 +6412,13 @@ void TonalMDCTConceal_Apply( ); void TonalMDCTConceal_Apply_ivas_fx( - TonalMDCTConcealPtr hTonalMDCTConc, /*IN */ - Word32 *mdctSpectrum, /*IN/OUT*/ + TonalMDCTConcealPtr hTonalMDCTConc, /*IN */ + Word32 *mdctSpectrum, /*IN/OUT*/ +#ifdef OPT_SBA_DEC_V2_NBE + Word16 mdctSpectrum_exp, /*IN */ +#else /* OPT_SBA_DEC_V2_NBE */ Word16 mdctSpectrum_exp[L_FRAME48k], /*IN */ +#endif /* OPT_SBA_DEC_V2_NBE */ const PsychoacousticParameters *psychParamsCurrent ); void TonalMDCTConceal_InsertNoise_ivas_fx( diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index 41c3f9740..6590d4b43 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -4761,14 +4761,19 @@ void decoder_tcx_noiseshaping_igf_fx( test(); IF( bfi && st->tonal_mdct_plc_active && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { +#ifndef OPT_SBA_DEC_V2_NBE Word16 tmp_x_fx_exp[L_FRAME48k], temp; temp = -MAX_16; move16(); set16_fx( tmp_x_fx_exp, *x_e, L_frameTCX ); TonalMDCTConceal_Apply_ivas_fx( st->hTonalMDCTConc, x_fx, tmp_x_fx_exp, st->hTcxCfg->psychParamsCurrent ); +#else /* OPT_SBA_DEC_V2_NBE */ + TonalMDCTConceal_Apply_ivas_fx( st->hTonalMDCTConc, x_fx, *x_e, st->hTcxCfg->psychParamsCurrent ); +#endif /* OPT_SBA_DEC_V2_NBE */ /* If exponent has been updated after TonalMDCTConceal_Apply, then shift the spectrum to common exponent. */ +#ifndef OPT_SBA_DEC_V2_NBE FOR( i = 0; i < L_frameTCX; i++ ) { temp = s_max( temp, tmp_x_fx_exp[i] ); @@ -4783,6 +4788,7 @@ void decoder_tcx_noiseshaping_igf_fx( move32(); } } +#endif /* OPT_SBA_DEC_V2_NBE */ } test(); diff --git a/lib_dec/ivas_dirac_output_synthesis_cov_fx.c b/lib_dec/ivas_dirac_output_synthesis_cov_fx.c index 532ca0358..4869f8d1c 100644 --- a/lib_dec/ivas_dirac_output_synthesis_cov_fx.c +++ b/lib_dec/ivas_dirac_output_synthesis_cov_fx.c @@ -591,10 +591,14 @@ void ivas_dirac_dec_output_synthesis_cov_param_mc_synthesise_slot_fx( /* apply residual mixing */ { Word16 shifter; +#ifdef OPT_SBA_DEC_V2_NBE + shifter = sub( mixing_matrix_res_smooth_e, 32 ); +#else /* OPT_SBA_DEC_V2_NBE */ #ifdef OPT_SBA_DEC_V2_BE shifter = sub( mixing_matrix_res_smooth_e, 31 ); #else /* OPT_SBA_DEC_V2_BE */ shifter = 31 - mixing_matrix_res_smooth_e; +#endif /* OPT_SBA_DEC_V2_NBE */ #endif /* OPT_SBA_DEC_V2_BE */ FOR( ch_idx = 0; ch_idx < nY; ch_idx++ ) { @@ -610,8 +614,13 @@ void ivas_dirac_dec_output_synthesis_cov_param_mc_synthesise_slot_fx( move64(); for ( i = 0; i < nY; i++ ) { +#ifdef OPT_SBA_DEC_V2_NBE + temp_real = W_mac_32_32( temp_real, mixing_matrix_res_smooth_fx[idx], diff_f_real_fx[i] ); + temp_imag = W_mac_32_32( temp_imag, mixing_matrix_res_smooth_fx[idx], diff_f_imag_fx[i] ); +#else /* OPT_SBA_DEC_V2_NBE */ temp_real = W_add( temp_real, W_mult0_32_32( mixing_matrix_res_smooth_fx[idx], diff_f_real_fx[i] ) ); temp_imag = W_add( temp_imag, W_mult0_32_32( mixing_matrix_res_smooth_fx[idx], diff_f_imag_fx[i] ) ); +#endif /* OPT_SBA_DEC_V2_NBE */ idx += nY; } #ifdef OPT_SBA_DEC_V2_BE diff --git a/lib_dec/ivas_mct_core_dec_fx.c b/lib_dec/ivas_mct_core_dec_fx.c index 08359826a..87c139f9c 100644 --- a/lib_dec/ivas_mct_core_dec_fx.c +++ b/lib_dec/ivas_mct_core_dec_fx.c @@ -256,7 +256,11 @@ void ivas_mct_core_dec( move16(); x_fx[ch][0] = signal_out_fx[ch]; x_fx[ch][1] = signal_out_fx[ch] + ( L_FRAME48k / 2 ); +#ifdef OPT_SBA_DEC_V2_NBE + q_x[ch] = Q11; +#else /* OPT_SBA_DEC_V2_NBE */ q_x[ch] = Q12; +#endif /* OPT_SBA_DEC_V2_NBE */ move16(); } @@ -332,7 +336,7 @@ void ivas_mct_core_dec( move16(); } } -#else /* OPT_SBA_DEC_PATH */ +#else /* OPT_SBA_DEC_PATH */ IF( EQ_16( st->core, TCX_10_CORE ) ) { nSubframes = NB_DIV; @@ -362,10 +366,18 @@ void ivas_mct_core_dec( move16(); FOR( i = 0; i < x_len; i++ ) { +#ifdef OPT_SBA_DEC_V2_NBE + x_fx[ch][k][i] = L_shr( x_fx[ch][k][i], sub( q_x[ch], Q11 ) ); +#else /* OPT_SBA_DEC_V2_NBE */ x_fx[ch][k][i] = L_shr( x_fx[ch][k][i], sub( q_x[ch], Q12 ) ); +#endif /* OPT_SBA_DEC_V2_NBE */ move32(); } +#ifdef OPT_SBA_DEC_V2_NBE + q_x[ch] = Q11; +#else /* OPT_SBA_DEC_V2_NBE */ q_x[ch] = Q12; +#endif /* OPT_SBA_DEC_V2_NBE */ move16(); } #endif /* OPT_SBA_DEC_PATH */ @@ -385,18 +397,27 @@ void ivas_mct_core_dec( #ifdef OPT_SBA_DEC_PATH apply_MCT_dec_fx( hMCT, sts, x_fx ); -#else /* OPT_SBA_DEC_PATH */ +#else /* OPT_SBA_DEC_PATH */ apply_MCT_dec_fx( hMCT, sts, x_fx, q_x ); FOR( ch = 0; ch < nChannels; ch++ ) { FOR( i = 0; i < L_FRAME48k / 2; i++ ) { +#ifdef OPT_SBA_DEC_V2_NBE + x_fx[ch][0][i] = L_shr( x_fx[ch][0][i], sub( q_x[ch], Q11 ) ); + x_fx[ch][1][i] = L_shr( x_fx[ch][1][i], sub( q_x[ch], Q11 ) ); +#else /* OPT_SBA_DEC_V2_NBE */ x_fx[ch][0][i] = L_shr( x_fx[ch][0][i], sub( q_x[ch], Q12 ) ); x_fx[ch][1][i] = L_shr( x_fx[ch][1][i], sub( q_x[ch], Q12 ) ); +#endif /* OPT_SBA_DEC_V2_NBE */ move32(); move32(); } +#ifdef OPT_SBA_DEC_V2_NBE + q_x[ch] = Q11; +#else /* OPT_SBA_DEC_V2_NBE */ q_x[ch] = Q12; +#endif /* OPT_SBA_DEC_V2_NBE */ move16(); } #endif /* OPT_SBA_DEC_PATH */ diff --git a/lib_dec/ivas_mct_dec_fx.c b/lib_dec/ivas_mct_dec_fx.c index ec7b8c697..ccc515b03 100644 --- a/lib_dec/ivas_mct_dec_fx.c +++ b/lib_dec/ivas_mct_dec_fx.c @@ -64,7 +64,7 @@ ivas_error ivas_mct_dec_fx( const Word16 nb_bits_metadata /* i : number of metadata bits */ ) { - Word16 ch, nCPE, cpe_id; + Word16 nCPE, cpe_id; MCT_DEC_HANDLE hMCT; CPE_DEC_HANDLE hCPE; Word16 param[MCT_MAX_BLOCKS][CPE_CHANNELS][DEC_NPRM_DIV * NB_DIV]; @@ -76,10 +76,13 @@ ivas_error ivas_mct_dec_fx( Word16 Aq_fx[MCT_MAX_BLOCKS][CPE_CHANNELS][( NB_SUBFR16k + 1 ) * ( M + 1 )]; // Q12 Word32 output_lfe_ch_fx[L_FRAME48k]; Word16 q_output = 11; - Word16 n, k, i; + Word16 n, i; Word32 *x_fx[CPE_CHANNELS][NB_DIV]; //(Q(31 - x_e) +#ifndef OPT_SBA_DEC_V2_NBE Word16 x_e[MAX_CICP_CHANNELS][NB_DIV]; + Word16 ch, k; +#endif /* OPT_SBA_DEC_V2_NBE */ Word16 x_len[CPE_CHANNELS][NB_DIV]; set16_fx( x_len[0], 0, NB_DIV ); set16_fx( x_len[1], 0, NB_DIV ); @@ -182,21 +185,31 @@ ivas_error ivas_mct_dec_fx( FOR( n = 0; n < CPE_CHANNELS; n++ ) { x_fx[n][0] = output_fx[n + ( cpe_id * CPE_CHANNELS )]; // Q11 +#ifndef OPT_SBA_DEC_V2_NBE x_e[n][0] = 20; move16(); +#endif /* OPT_SBA_DEC_V2_NBE */ move16(); x_fx[n][1] = output_fx[n + ( cpe_id * CPE_CHANNELS )] + ( L_FRAME48k / 2 ); // Q11 +#ifndef OPT_SBA_DEC_V2_NBE x_e[n][1] = 20; move16(); +#endif /* OPT_SBA_DEC_V2_NBE */ move16(); set32_fx( x_fx[n][0], 0, L_FRAME48k / 2 ); set32_fx( x_fx[n][1], 0, L_FRAME48k / 2 ); } +#ifndef OPT_SBA_DEC_V2_NBE ivas_mdct_core_invQ_fx( st_ivas->hCPE[cpe_id], nTnsBitsTCX10[cpe_id], p_param[cpe_id], param_lpc[cpe_id], param[cpe_id], fUseTns[cpe_id], tnsData[cpe_id], x_fx, x_e, x_fx, x_e, x_len, Aq_fx[cpe_id], NULL, 1 ); +#else /* OPT_SBA_DEC_V2_NBE */ + ivas_mdct_core_invQ_fx( st_ivas->hCPE[cpe_id], nTnsBitsTCX10[cpe_id], p_param[cpe_id], param_lpc[cpe_id], param[cpe_id], + fUseTns[cpe_id], tnsData[cpe_id], x_fx, 20, x_fx, 20, x_len, Aq_fx[cpe_id], NULL, 1 ); +#endif /* OPT_SBA_DEC_V2_NBE */ +#ifndef OPT_SBA_DEC_V2_NBE FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) { Word16 subFrames; @@ -214,6 +227,7 @@ ivas_error ivas_mct_dec_fx( Scale_sig32( x_fx[ch][k], shr( L_FRAME48k, sub( subFrames, 1 ) ), sub( x_e[ch][k], 20 ) ); // Scaling back to Q11 } } +#endif /* OPT_SBA_DEC_V2_NBE */ st_ivas->BER_detect = s_or( st_ivas->BER_detect, st_ivas->hCPE[cpe_id]->hCoreCoder[0]->BER_detect ); move16(); @@ -224,18 +238,22 @@ ivas_error ivas_mct_dec_fx( /* MCT core decoder */ Word16 q_x[MAX_TRANSPORT_CHANNELS]; +#ifndef OPT_SBA_DEC_V2_NBE set16_fx( q_x, Q12, MAX_TRANSPORT_CHANNELS ); // Scaling output buffer to q_x FOR( i = 0; i < hMCT->nchan_out_woLFE; ++i ) { Scale_sig32( output_fx[i], L_FRAME48k, sub( q_x[i], Q11 ) ); // Q11 -> Q12 } +#endif /* OPT_SBA_DEC_V2_NBE */ ivas_mct_core_dec( hMCT, st_ivas->hCPE, nCPE, output_fx, q_x ); // Scaling output buffer back to Q11 +#ifndef OPT_SBA_DEC_V2_NBE FOR( i = 0; i < hMCT->nchan_out_woLFE; ++i ) { Scale_sig32( output_fx[i], L_FRAME48k, sub( Q11, q_x[i] ) ); // Q12 -> Q11 } +#endif /* OPT_SBA_DEC_V2_NBE */ /* for sba to stereo output disable any further processing for TCs > 2 as it is not needed*/ @@ -263,16 +281,25 @@ ivas_error ivas_mct_dec_fx( Copy_Scale_sig_16_32_DEPREC( Aq_fx[cpe_id][n], Aq_fx_32[cpe_id][n], 102, Q16 - Q12 ); // Q16 x_fx[n][0] = output_fx[n + ( cpe_id * CPE_CHANNELS )]; // Q11 x_fx[n][1] = output_fx[n + ( cpe_id * CPE_CHANNELS )] + ( L_FRAME48k / 2 ); // Q11 +#ifndef OPT_SBA_DEC_V2_NBE x_e[n][0] = 20; move16(); +#endif /* OPT_SBA_DEC_V2_NBE */ move16(); move16(); +#ifndef OPT_SBA_DEC_V2_NBE x_e[n][1] = 20; move16(); +#endif /* OPT_SBA_DEC_V2_NBE */ } +#ifndef OPT_SBA_DEC_V2_NBE ivas_mdct_core_tns_ns_fx( hCPE, fUseTns[cpe_id], tnsData[cpe_id], x_fx, Aq_fx_32[cpe_id], 1, x_e ); +#else /* OPT_SBA_DEC_V2_NBE */ + ivas_mdct_core_tns_ns_fx( hCPE, fUseTns[cpe_id], tnsData[cpe_id], x_fx, Aq_fx_32[cpe_id], 1, 20 ); +#endif /* OPT_SBA_DEC_V2_NBE */ +#ifndef OPT_SBA_DEC_V2_NBE FOR( Word16 ind = 0; ind < 2; ind++ ) { Word16 nSubFrames; @@ -291,6 +318,7 @@ ivas_error ivas_mct_dec_fx( Scale_sig32( x_fx[ind][1], shr( L_FRAME48k, 1 ), sub( x_e[ind][1], 20 ) ); // Q11 } } +#endif /* OPT_SBA_DEC_V2_NBE */ } diff --git a/lib_dec/ivas_mct_dec_mct_fx_fx.c b/lib_dec/ivas_mct_dec_mct_fx_fx.c index 0d998b355..f470ac9cd 100644 --- a/lib_dec/ivas_mct_dec_mct_fx_fx.c +++ b/lib_dec/ivas_mct_dec_mct_fx_fx.c @@ -323,8 +323,13 @@ void mctStereoIGF_dec_fx( move16(); // Using input Q-factor as 12 +#ifdef OPT_SBA_DEC_V2_NBE + set16_fx( p_x_e[0], 31 - Q11, CPE_CHANNELS ); // Q12 + set16_fx( p_x_e[1], 31 - Q11, CPE_CHANNELS ); // Q12 +#else /* OPT_SBA_DEC_V2_NBE */ set16_fx( p_x_e[0], 31 - Q12, CPE_CHANNELS ); // Q12 set16_fx( p_x_e[1], 31 - Q12, CPE_CHANNELS ); // Q12 +#endif /* OPT_SBA_DEC_V2_NBE */ FOR( k = 0; k < nSubframes; k++ ) { @@ -353,13 +358,21 @@ void mctStereoIGF_dec_fx( decoder_tcx_IGF_stereo_fx( sts, hMCT->hBlockData[b]->hStereoMdct, hMCT->hBlockData[b]->mask, p_x, p_x_e, p_x_len, L_frame[0], left_rect[0], k, bfi, 1 /* MCT_flag */ ); // Shifting output with variable exponent back to Q12 +#ifdef OPT_SBA_DEC_V2_NBE + shr_k = sub( 31 - Q11, p_x_e[0][k] ); +#else /* OPT_SBA_DEC_V2_NBE */ shr_k = sub( 31 - Q12, p_x_e[0][k] ); +#endif /* OPT_SBA_DEC_V2_NBE */ FOR( Word16 i = 0; i < p_x_len[0][k]; i++ ) { p_x[0][k][i] = L_shr( p_x[0][k][i], shr_k ); move32(); } +#ifdef OPT_SBA_DEC_V2_NBE + shr_k = sub( 31 - Q11, p_x_e[1][k] ); +#else /* OPT_SBA_DEC_V2_NBE */ shr_k = sub( 31 - Q12, p_x_e[1][k] ); +#endif /* OPT_SBA_DEC_V2_NBE */ FOR( Word16 i = 0; i < p_x_len[1][k]; i++ ) { p_x[1][k][i] = L_shr( p_x[1][k][i], shr_k ); @@ -392,7 +405,11 @@ void mctStereoIGF_dec_fx( /* mono or dual mono IGF decoding */ +#ifdef OPT_SBA_DEC_V2_NBE + x_e = 31 - Q11; // input q-factor of x[p_ch[ch]][k] is Q12 +#else /* OPT_SBA_DEC_V2_NBE */ x_e = 31 - Q12; // input q-factor of x[p_ch[ch]][k] is Q12 +#endif /* OPT_SBA_DEC_V2_NBE */ move16(); decoder_tcx_IGF_mono_fx( st, x[p_ch[ch]][k], &x_e, &x_len, L_frame[ch], left_rect[ch], bfi, k ); @@ -400,7 +417,11 @@ void mctStereoIGF_dec_fx( FOR( Word16 i = 0; i < x_len; i++ ) { // Converting from variable exponent to Fixed q-factor (Q12) +#ifdef OPT_SBA_DEC_V2_NBE + x[p_ch[ch]][k][i] = L_shr( x[p_ch[ch]][k][i], sub( 31 - Q11, x_e ) ); +#else /* OPT_SBA_DEC_V2_NBE */ x[p_ch[ch]][k][i] = L_shr( x[p_ch[ch]][k][i], sub( 31 - Q12, x_e ) ); +#endif /* OPT_SBA_DEC_V2_NBE */ move32(); } } @@ -452,7 +473,11 @@ void mctStereoIGF_dec_fx( init_tcx_info_fx( st, L_frame_nSubframe, L_frameTCX_nSubframe, k, bfi, &tcx_offset[0], &tcx_offsetFB[0], &L_frame[0], &L_frameTCX[0], &left_rect[0], &L_spec[0] ); /* mono or dual mono IGF decoding */ +#ifdef OPT_SBA_DEC_V2_NBE + x_e = 31 - Q11; // Input Q-factor is Q12. +#else /* OPT_SBA_DEC_V2_NBE */ x_e = 31 - Q12; // Input Q-factor is Q12. +#endif /* OPT_SBA_DEC_V2_NBE */ move16(); decoder_tcx_IGF_mono_fx( st, x[ch][k], &x_e, &x_len, L_frame[0], left_rect[0], bfi, k ); @@ -460,7 +485,11 @@ void mctStereoIGF_dec_fx( FOR( Word16 i = 0; i < x_len; i++ ) { // Converting from variable exponent to Fixed q-factor (Q12) +#ifdef OPT_SBA_DEC_V2_NBE + x[ch][k][i] = L_shr( x[ch][k][i], sub( 31 - Q11, x_e ) ); +#else /* OPT_SBA_DEC_V2_NBE */ x[ch][k][i] = L_shr( x[ch][k][i], sub( 31 - Q12, x_e ) ); +#endif /* OPT_SBA_DEC_V2_NBE */ move32(); } } diff --git a/lib_dec/ivas_mdct_core_dec_fx.c b/lib_dec/ivas_mdct_core_dec_fx.c index 4e90792fb..5f529be55 100644 --- a/lib_dec/ivas_mdct_core_dec_fx.c +++ b/lib_dec/ivas_mdct_core_dec_fx.c @@ -630,9 +630,17 @@ void ivas_mdct_core_invQ_fx( Word16 fUseTns[CPE_CHANNELS][NB_DIV], /* i : flag TNS enabled */ STnsData tnsData[CPE_CHANNELS][NB_DIV], /* i : TNS parameter */ Word32 *x_0[CPE_CHANNELS][NB_DIV], /* i/o: signal buffer */ +#ifdef OPT_SBA_DEC_V2_NBE + Word16 x_0_e, +#else /* OPT_SBA_DEC_V2_NBE */ Word16 x_0_e[CPE_CHANNELS][NB_DIV], +#endif /* OPT_SBA_DEC_V2_NBE */ Word32 *x[CPE_CHANNELS][NB_DIV], /* i/o: signal buffer */ +#ifdef OPT_SBA_DEC_V2_NBE + Word16 x_e, +#else /* OPT_SBA_DEC_V2_NBE */ Word16 x_e[CPE_CHANNELS][NB_DIV], +#endif /* OPT_SBA_DEC_V2_NBE */ Word16 x_len[CPE_CHANNELS][NB_DIV], Word16 Aq[CPE_CHANNELS][( NB_SUBFR16k + 1 ) * ( M + 1 )], /* i : LP coefficients Q12*/ Word16 ms_mask[NB_DIV][MAX_SFB], /* i : M/S mask */ @@ -963,9 +971,11 @@ void ivas_mdct_core_invQ_fx( IF( EQ_32( st->mct_chan_mode, MCT_CHAN_MODE_IGNORE ) ) { +#ifndef OPT_SBA_DEC_V2_NBE set32_fx( x[ch][0], 0, st->hTcxCfg->tcx_coded_lines ); x_e[ch][0] = 31; move16(); +#endif /* OPT_SBA_DEC_V2_NBE */ /* usually set in decoder_tcx_invQ(), needed for concealment */ st->hTcxDec->damping = 0; move16(); @@ -997,6 +1007,10 @@ void ivas_mdct_core_invQ_fx( FOR( k = 0; k < nSubframes[ch]; k++ ) { +#ifdef OPT_SBA_DEC_V2_NBE + Word16 x_e_local = x_e; + Word16 j, diff; +#endif /* OPT_SBA_DEC_V2_NBE */ /* Stability Factor */ IF( !bfi ) { @@ -1031,17 +1045,38 @@ void ivas_mdct_core_invQ_fx( nf_seed = 0; move16(); - decoder_tcx_invQ_fx( st, prm[ch], Aq[ch], Aind[ch], L_spec[ch], L_frame[ch], L_frameTCX[ch], x[ch][k], &x_e[ch][k], NULL, NULL, xn_buf, &fUseTns[ch][k], &tnsData[ch][k], &gain_tcx, &gain_tcx_e, &prm_sqQ, &nf_seed, bfi, k ); +#ifdef OPT_SBA_DEC_V2_NBE + decoder_tcx_invQ_fx( st, prm[ch], Aq[ch], Aind[ch], L_spec[ch], L_frame[ch], L_frameTCX[ch], x[ch][k], &x_e_local, NULL, NULL, xn_buf, &fUseTns[ch][k], &tnsData[ch][k], &gain_tcx, &gain_tcx_e, &prm_sqQ, &nf_seed, bfi, k ); + diff = sub( x_e_local, x_0_e ); + IF( diff != 0 ) + { + FOR( j = 0; j < L_frameTCX[ch]; j++ ) + { + x_0[ch][k][j] = L_shl_sat( x[ch][k][j], diff ); + move32(); + } + } + ELSE + { + Copy32( x[ch][k], x_0[ch][k], L_frameTCX[ch] ); + } +#else /* OPT_SBA_DEC_V2_NBE */ + decoder_tcx_invQ_fx( st, prm[ch], Aq[ch], Aind[ch], L_spec[ch], L_frame[ch], L_frameTCX[ch], x[ch][k], &x_e[ch][k], NULL, NULL, xn_buf, &fUseTns[ch][k], &tnsData[ch][k], &gain_tcx, &gain_tcx_e, &prm_sqQ, &nf_seed, bfi, k ); +#endif /* OPT_SBA_DEC_V2_NBE */ shift = Find_Max_Norm32( x[ch][k], L_frameTCX[ch] ); move16(); Scale_sig32( x[ch][k], L_frameTCX[ch], shift ); +#ifdef OPT_SBA_DEC_V2_NBE + x_e_local = sub( x_e_local, shift ); +#else /* OPT_SBA_DEC_V2_NBE */ x_e[ch][k] = sub( x_e[ch][k], shift ); move16(); Copy32( x[ch][k], x_0[ch][k], L_frameTCX[ch] ); x_0_e[ch][k] = x_e[ch][k]; move16(); +#endif /* OPT_SBA_DEC_V2_NBE */ // PLC to be done test(); @@ -1050,15 +1085,29 @@ void ivas_mdct_core_invQ_fx( TonalMdctConceal_create_concealment_noise_ivas_fx( concealment_noise_fx[ch], &concealment_noise_e[ch], hCPE, L_frameTCX[ch], L_frame[ch], ch, k, st->core, st->hTcxDec->cummulative_damping_tcx, noise_gen_mode_bfi ); } +#ifdef OPT_SBA_DEC_V2_NBE + decoder_tcx_noisefilling_fx( st, concealment_noise_fx[ch], concealment_noise_e[ch], Aq[ch], L_frameTCX_global[ch], L_spec[ch], L_frame[ch], L_frameTCX[ch], x[ch][k], &x_e_local, NULL, NULL, &tmp_concealment_method, gain_tcx, gain_tcx_e, prm_sqQ, nf_seed, bfi, MCT_flag, k ); +#else /* OPT_SBA_DEC_V2_NBE */ decoder_tcx_noisefilling_fx( st, concealment_noise_fx[ch], concealment_noise_e[ch], Aq[ch], L_frameTCX_global[ch], L_spec[ch], L_frame[ch], L_frameTCX[ch], x[ch][k], &x_e[ch][k], NULL, NULL, &tmp_concealment_method, gain_tcx, gain_tcx_e, prm_sqQ, nf_seed, bfi, MCT_flag, k ); +#endif /* OPT_SBA_DEC_V2_NBE */ shift = Find_Max_Norm32( x[ch][k], L_frameTCX[ch] ); move16(); Scale_sig32( x[ch][k], L_frameTCX[ch], shift ); +#ifdef OPT_SBA_DEC_V2_NBE + x_e_local = sub( x_e_local, shift ); +#else /* OPT_SBA_DEC_V2_NBE */ x_e[ch][k] = sub( x_e[ch][k], shift ); +#endif /* OPT_SBA_DEC_V2_NBE */ move16(); +#ifdef OPT_SBA_DEC_V2_NBE + decoder_tcx_noiseshaping_igf_fx( st, L_spec[ch], L_frame[ch], L_frameTCX[ch], left_rect[ch], x[ch][k], &x_e_local, &x_len[ch][k], NULL, NULL, &tmp_concealment_method, bfi ); + + Scale_sig32( x[ch][k], L_frameTCX[ch], sub( x_e_local, x_e ) ); +#else /* OPT_SBA_DEC_V2_NBE */ decoder_tcx_noiseshaping_igf_fx( st, L_spec[ch], L_frame[ch], L_frameTCX[ch], left_rect[ch], x[ch][k], &x_e[ch][k], &x_len[ch][k], NULL, NULL, &tmp_concealment_method, bfi ); +#endif /* OPT_SBA_DEC_V2_NBE */ } } } @@ -1458,7 +1507,11 @@ void ivas_mdct_core_tns_ns_fx( Word32 *x_fx[CPE_CHANNELS][NB_DIV], /* o : synthesis @internal_FS Q(31 - x_e)*/ Word32 Aq_fx[CPE_CHANNELS][( NB_SUBFR16k + 1 ) * ( M + 1 )], /* o : LP coefficients Q16*/ const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) */ +#ifdef OPT_SBA_DEC_V2_NBE + Word16 x_e ) +#else /* OPT_SBA_DEC_V2_NBE */ Word16 x_e[CPE_CHANNELS][NB_DIV] ) +#endif /* OPT_SBA_DEC_V2_NBE */ { Word16 ch, k, bfi; Decoder_State **sts, *st; @@ -1532,7 +1585,11 @@ void ivas_mdct_core_tns_ns_fx( &tcx_offsetFB[ch], &L_frame[ch], &L_frameTCX[ch], &left_rect[ch], &L_spec[ch] ); Word16 q_x; +#ifdef OPT_SBA_DEC_V2_NBE + q_x = sub( 31, x_e ); +#else /* OPT_SBA_DEC_V2_NBE */ q_x = sub( 31, x_e[ch][k] ); +#endif /* OPT_SBA_DEC_V2_NBE */ IF( bfi == 0 ) { sns_interpolate_scalefactors_fx( sns_int_scf_fx, &Aq_fx[ch][k * M], DEC ); // Q16 @@ -1551,7 +1608,11 @@ void ivas_mdct_core_tns_ns_fx( scf_e[ind] = sub( 15, q_shift ); move16(); } +#ifdef OPT_SBA_DEC_V2_NBE + TonalMDCTConceal_SaveFreqSignal_ivas_fx( st->hTonalMDCTConc, x_fx[ch][k], x_e, L_frameTCX[ch], L_frame[ch], &scf_fx[0], scf_e, 0, get_igf_startline( st, L_frame[ch], L_frameTCX[ch] ) ); +#else /* OPT_SBA_DEC_V2_NBE */ TonalMDCTConceal_SaveFreqSignal_ivas_fx( st->hTonalMDCTConc, x_fx[ch][k], x_e[ch][k], L_frameTCX[ch], L_frame[ch], &scf_fx[0], scf_e, 0, get_igf_startline( st, L_frame[ch], L_frameTCX[ch] ) ); +#endif /* OPT_SBA_DEC_V2_NBE */ } } ELSE @@ -1613,8 +1674,10 @@ void ivas_mdct_core_tns_ns_fx( norm_x = getScaleFactor32( &x_fx[ch][k][0], length ); Scale_sig32( &x_fx[ch][k][0], length, norm_x ); q_x = add( q_x, norm_x ); +#ifndef OPT_SBA_DEC_V2_NBE x_e[ch][k] = sub( 31, q_x ); move16(); +#endif /* OPT_SBA_DEC_V2_NBE */ Word16 q_sns_int_scf; Word16 q_2; @@ -1641,8 +1704,10 @@ void ivas_mdct_core_tns_ns_fx( Scale_sig32( &x_fx[ch][k][0] + length, sub( length2, length ), sub( add( q_x, 1 ), q_2 ) ); q_x = add( q_x, 1 ); } +#ifndef OPT_SBA_DEC_V2_NBE x_e[ch][k] = sub( 31, q_x ); move16(); +#endif /* OPT_SBA_DEC_V2_NBE */ v_multc_fixed( x_fx[ch][k] + st->hTcxCfg->psychParamsCurrent->nBins, sns_int_scf_fx[FDNS_NPTS - 1], x_fx[ch][k] + st->hTcxCfg->psychParamsCurrent->nBins, sub( L_spec[ch], st->hTcxCfg->psychParamsCurrent->nBins ) ); @@ -1650,8 +1715,10 @@ void ivas_mdct_core_tns_ns_fx( Scale_sig32( &x_fx[ch][k][0], st->hTcxCfg->psychParamsCurrent->nBins, sub( q_2, q_x ) ); q_x = q_2; move16(); +#ifndef OPT_SBA_DEC_V2_NBE x_e[ch][k] = sub( 31, q_x ); move16(); +#endif /* OPT_SBA_DEC_V2_NBE */ q_x = sub( q_x, 5 ); length = L_frameTCX[ch]; @@ -1668,25 +1735,37 @@ void ivas_mdct_core_tns_ns_fx( } Scale_sig32( &x_fx[ch][k][0], length, -5 ); decoder_tcx_tns_fx( st, L_frame_global[ch], L_spec[ch], L_frame[ch], L_frameTCX[ch], &x_fx[ch][k][0], fUseTns[ch][k], &tnsData[ch][k], bfi, k, 0, &length ); +#ifndef OPT_SBA_DEC_V2_NBE norm_x = getScaleFactor32( &x_fx[ch][k][0], length ); Scale_sig32( &x_fx[ch][k][0], length, norm_x ); q_x = add( q_x, norm_x ); x_e[ch][k] = sub( 31, q_x ); move16(); +#else /* OPT_SBA_DEC_V2_NBE */ + Scale_sig32( &x_fx[ch][k][0], length, sub( sub( 31, q_x ), x_e ) ); +#endif /* OPT_SBA_DEC_V2_NBE */ } IF( ( bfi != 0 ) && ( st->tonal_mdct_plc_active != 0 ) ) { - Word16 tmp_x_fx_exp[L_FRAME48k], temp = -MAX_16, i; +#ifndef OPT_SBA_DEC_V2_NBE + Word16 tmp_x_fx_exp[L_FRAME48k], temp = -MAX_16; move16(); +#endif /* OPT_SBA_DEC_V2_NBE */ + Word16 i; FOR( i = 0; i < FDNS_NPTS; i++ ) { st->hTonalMDCTConc->secondLastBlockData.scaleFactors_max_e = s_max( st->hTonalMDCTConc->secondLastBlockData.scaleFactors_max_e, st->hTonalMDCTConc->secondLastBlockData.scaleFactors_exp[i] ); } +#ifndef OPT_SBA_DEC_V2_NBE set16_fx( tmp_x_fx_exp, x_e[ch][0], L_FRAME48k ); TonalMDCTConceal_Apply_ivas_fx( st->hTonalMDCTConc, x_fx[ch][0], tmp_x_fx_exp, st->hTcxCfg->psychParamsCurrent ); +#else /* OPT_SBA_DEC_V2_NBE */ + TonalMDCTConceal_Apply_ivas_fx( st->hTonalMDCTConc, x_fx[ch][0], x_e, st->hTcxCfg->psychParamsCurrent ); +#endif /* OPT_SBA_DEC_V2_NBE */ +#ifndef OPT_SBA_DEC_V2_NBE FOR( i = 0; i < L_FRAME48k; i++ ) { temp = s_max( temp, tmp_x_fx_exp[i] ); @@ -1701,6 +1780,7 @@ void ivas_mdct_core_tns_ns_fx( move32(); } } +#endif /* OPT_SBA_DEC_V2_NBE */ } test(); diff --git a/lib_dec/ivas_stereo_mdct_core_dec_fx.c b/lib_dec/ivas_stereo_mdct_core_dec_fx.c index 85ae00c90..b52d04951 100644 --- a/lib_dec/ivas_stereo_mdct_core_dec_fx.c +++ b/lib_dec/ivas_stereo_mdct_core_dec_fx.c @@ -178,7 +178,9 @@ void stereo_mdct_core_dec_fx( /*needed to allocate N_MAX to prevent stereo switching crash */ Word32 x_0_buf_fx[CPE_CHANNELS][N_MAX]; Word32 *x_0_fx[CPE_CHANNELS][NB_DIV]; +#ifndef OPT_SBA_DEC_V2_NBE Word16 x_0_e[CPE_CHANNELS][NB_DIV]; +#endif /* OPT_SBA_DEC_V2_NBE */ /* Concealment */ Word16 bfi; @@ -289,15 +291,24 @@ void stereo_mdct_core_dec_fx( { FOR( j = 0; j < NB_DIV; ++j ) { +#ifndef OPT_SBA_DEC_V2_NBE x_e[i][j] = 31; +#else /* OPT_SBA_DEC_V2_NBE */ + x_e[i][j] = 20; +#endif /* OPT_SBA_DEC_V2_NBE */ move16(); x_len[i][j] = 0; move16(); +#ifndef OPT_SBA_DEC_V2_NBE x_0_e[i][j] = 31; move16(); +#endif /* OPT_SBA_DEC_V2_NBE */ } } +#ifdef OPT_SBA_DEC_V2_NBE + ivas_mdct_core_invQ_fx( hCPE, nTnsBitsTCX10, p_param, param_lpc, param, fUseTns, tnsData, x_0_fx, 20, x_fx, 20, x_len, Aq_fx, ms_mask, 0 ); +#else /* OPT_SBA_DEC_V2_NBE */ ivas_mdct_core_invQ_fx( hCPE, nTnsBitsTCX10, p_param, param_lpc, param, fUseTns, tnsData, x_0_fx, x_0_e, x_fx, x_e, x_len, Aq_fx, ms_mask, 0 ); FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) @@ -323,6 +334,7 @@ void stereo_mdct_core_dec_fx( move16(); } } +#endif /* OPT_SBA_DEC_V2_NBE */ FOR( ch = 0; ch < nChannels; ch++ ) { @@ -471,6 +483,8 @@ void stereo_mdct_core_dec_fx( move16(); #endif /* OPT_SBA_DEC_PATH */ +#ifndef OPT_SBA_DEC_V2_NBE + FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) { if ( NE_16( hCPE->hCoreCoder[ch]->core, TCX_20_CORE ) ) @@ -479,6 +493,7 @@ void stereo_mdct_core_dec_fx( move16(); } } +#endif /* OPT_SBA_DEC_V2_NBE */ #ifdef OPT_SBA_DEC_PATH stereo_decoder_tcx_fx( hCPE->hStereoMdct, ms_mask, x_0_fx[1], x_fx[0], x_fx[1], &hCPE->hStereoMdct->mdct_stereo_mode[0], sts[0]->core, sts[1]->core, sts[0]->igf, L_frameTCX[0], L_frameTCX[1], 0, sts[0]->last_core, sts[1]->last_core, 0 ); #else /* OPT_SBA_DEC_PATH */ @@ -486,6 +501,10 @@ void stereo_mdct_core_dec_fx( #endif /* OPT_SBA_DEC_PATH */ } +#ifdef OPT_SBA_DEC_V2_NBE + ivas_mdct_core_tns_ns_fx( hCPE, fUseTns, tnsData, x_fx, Aq_fx_32, 0, 20 ); +#else /* OPT_SBA_DEC_V2_NBE */ + ivas_mdct_core_tns_ns_fx( hCPE, fUseTns, tnsData, x_fx, Aq_fx_32, 0, x_e ); FOR( Word16 ind = 0; ind < 2; ind++ ) @@ -511,7 +530,7 @@ void stereo_mdct_core_dec_fx( move16(); } } - +#endif /* OPT_SBA_DEC_V2_NBE */ test(); test(); IF( EQ_16( st_ivas->renderer_type, RENDERER_MC_PARAMMC ) && ( EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_MONO ) || EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_STEREO ) ) ) diff --git a/lib_dec/tonalMDCTconcealment_fx.c b/lib_dec/tonalMDCTconcealment_fx.c index f61fe276e..9582463eb 100644 --- a/lib_dec/tonalMDCTconcealment_fx.c +++ b/lib_dec/tonalMDCTconcealment_fx.c @@ -2587,9 +2587,13 @@ void TonalMDCTConceal_Apply( } void TonalMDCTConceal_Apply_ivas_fx( - TonalMDCTConcealPtr hTonalMDCTConc, /*IN */ - Word32 *mdctSpectrum, // Q31-*mdctSpectrum_exp /*IN/OUT*/ - Word16 mdctSpectrum_exp[L_FRAME_MAX], /*IN */ + TonalMDCTConcealPtr hTonalMDCTConc, /*IN */ + Word32 *mdctSpectrum, // Q31-*mdctSpectrum_exp /*IN/OUT*/ +#ifdef OPT_SBA_DEC_V2_NBE + Word16 mdctSpectrum_exp, /*IN */ +#else /* OPT_SBA_DEC_V2_NBE */ + Word16 mdctSpectrum_exp[L_FRAME_MAX], /*IN */ +#endif /* OPT_SBA_DEC_V2_NBE */ const PsychoacousticParameters *psychParamsCurrent ) { @@ -2755,8 +2759,12 @@ void TonalMDCTConceal_Apply_ivas_fx( /* getCosWord16 returns 1Q14*/ mdctSpectrum[l] = Mpy_32_16_1( powerSpectrum[l], getCosWord16( extract_l( currentPhase ) ) ); move32(); +#ifdef OPT_SBA_DEC_V2_NBE + mdctSpectrum[l] = L_shr( mdctSpectrum[l], sub( mdctSpectrum_exp, add( powerSpectrum_exp, 1 ) ) ); +#else /* OPT_SBA_DEC_V2_NBE */ mdctSpectrum_exp[l] = add( powerSpectrum_exp, 1 ); // getCosWord16 returns Q14 (exp is 1)d move16(); +#endif /* OPT_SBA_DEC_V2_NBE */ } } } -- GitLab From 27ed4d5cb64596422a8690816f45956ae3def7e6 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Tue, 1 Jul 2025 11:58:19 +0530 Subject: [PATCH 2/2] Q update in mct core dec --- lib_dec/ivas_mct_core_dec_fx.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib_dec/ivas_mct_core_dec_fx.c b/lib_dec/ivas_mct_core_dec_fx.c index 87c139f9c..bc2471e24 100644 --- a/lib_dec/ivas_mct_core_dec_fx.c +++ b/lib_dec/ivas_mct_core_dec_fx.c @@ -300,14 +300,22 @@ void ivas_mct_core_dec( /* mono or dual mono IGF decoding */ x_e = sub( 31, q_x[ch] ); decoder_tcx_IGF_mono_fx( st, x_fx[ch][k], &x_e, &x_len, L_frame, left_rect, bfi, k ); +#ifdef OPT_SBA_DEC_V2_NBE + q_x[ch] = sub( 31 - 11, x_e ); // Shift to bring x to Q12 +#else /* OPT_SBA_DEC_V2_NBE */ q_x[ch] = sub( 31 - 12, x_e ); // Shift to bring x to Q12 +#endif /* OPT_SBA_DEC_V2_NBE */ move16(); FOR( i = 0; i < x_len; i++ ) { x_fx[ch][k][i] = L_shr( x_fx[ch][k][i], q_x[ch] ); move32(); } +#ifdef OPT_SBA_DEC_V2_NBE + q_x[ch] = Q11; +#else /* OPT_SBA_DEC_V2_NBE */ q_x[ch] = Q12; +#endif /* OPT_SBA_DEC_V2_NBE */ move16(); } } @@ -325,14 +333,22 @@ void ivas_mct_core_dec( /* mono or dual mono IGF decoding */ x_e = sub( 31, q_x[ch] ); decoder_tcx_IGF_mono_fx( st, x_fx[ch][0], &x_e, &x_len, L_frame, left_rect, bfi, 0 ); +#ifdef OPT_SBA_DEC_V2_NBE + q_x[ch] = sub( 31 - 11, x_e ); // Shift to bring x to Q12 +#else /* OPT_SBA_DEC_V2_NBE */ q_x[ch] = sub( 31 - 12, x_e ); // Shift to bring x to Q12 +#endif /* OPT_SBA_DEC_V2_NBE */ move16(); FOR( i = 0; i < x_len; i++ ) { x_fx[ch][0][i] = L_shr( x_fx[ch][0][i], q_x[ch] ); move32(); } +#ifdef OPT_SBA_DEC_V2_NBE + q_x[ch] = Q11; +#else /* OPT_SBA_DEC_V2_NBE */ q_x[ch] = Q12; +#endif /* OPT_SBA_DEC_V2_NBE */ move16(); } } -- GitLab