diff --git a/lib_com/options.h b/lib_com/options.h index c9207fb3c54d7ab520e539978daa4298b9a79a71..ccaeca46a2cb3f0d49e9cea01bb545fc753cd27c 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -175,4 +175,5 @@ #define NONBE_FIX_1402_WAVEADJUST /* VA: BASOP iisue 1402: fix waveform adjustment decoder PLC */ #define FIX_ISSUE_1376 /* VA: Fix for issue 1376 (issue with GSC excitation) */ #define OPT_SBA_AVOID_SPAR_RESCALE /* Optimization made to spar decoder and IGF */ +#define NONBE_FIX_1386_STEREO_DMX_EVS_PHA /* Orange: Fix for stereo DMX / PHA mode : Change the filter taps resolution (Q31->Q30), improve precision for the IR window, for the ILD & IPD smoothing in sub-bands, for the ISD counters and for ICCr. */ #endif diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h index 918acc41711f5135bfa0ede33d664e6d43363de2..ef278d188b609f35b793256ba5f628e45323f588 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -1183,7 +1183,11 @@ typedef struct stereo_dmx_evs_correlation_filter_structure { Word16 init_frmCntr; +#ifdef NONBE_FIX_1386_STEREO_DMX_EVS_PHA + Word32 isd_rate_s_fx; // Q31 +#else Word16 isd_rate_s_fx; // Q15 +#endif Word32 iccr_s_fx; // Q31 Word32 ipd_ff_fx[STEREO_DMX_EVS_NB_SUBBAND_MAX]; // Q31 Word32 Pr_fx[STEREO_DMX_EVS_NB_SUBBAND_MAX]; // Q31 @@ -1224,8 +1228,11 @@ typedef struct stereo_dmx_evs_enc_data_structure STEREO_DMX_EVS_POC_HANDLE hPOC; STEREO_DMX_EVS_PHA_HANDLE hPHA; - - Word32 itd_fx; // Q16 +#ifdef NONBE_FIX_1386_STEREO_DMX_EVS_PHA + Word16 itd_fx; // Q0 +#else + Word32 itd_fx; // Q16 +#endif Word32 pre_dmx_energy_fx[1]; Word16 pre_dmx_energy_fx_e[1]; diff --git a/lib_enc/ivas_stereo_dmx_evs_fx.c b/lib_enc/ivas_stereo_dmx_evs_fx.c index ae8a8203e815b5597d27cb4d6ffeb44070301274..933270c33bc82cb77288383a88c3e29d42e39683 100644 --- a/lib_enc/ivas_stereo_dmx_evs_fx.c +++ b/lib_enc/ivas_stereo_dmx_evs_fx.c @@ -65,12 +65,20 @@ #define Q_BAND_FX 536870912 /*Q31*/ -#define STEREO_DMX_EVS_ISD_FORGETTING_Q15 31129 #define STEREO_DMX_EVS_ISD_THRES_L_Q31 1932735283 #define STEREO_DMX_EVS_ISD_DIST_THRES_IPD_Q15 ONE_IN_Q14 +#ifdef NONBE_FIX_1386_STEREO_DMX_EVS_PHA +#define STEREO_DMX_EVS_ISD_FORGETTING_Q31 2040109465 +#define STEREO_DMX_EVS_ISD_1MFORGETTING_Q15 1638 +#define STEREO_DMX_EVS_ISD_DIST_HYST_L_Q31 773094113 +#define STEREO_DMX_EVS_ISD_DIST_HYST_H_Q31 923417968 +#define STEREO_DMX_EVS_ISD_INVTHRES_H 1270700383 +#else +#define STEREO_DMX_EVS_ISD_FORGETTING_Q15 31129 #define STEREO_DMX_EVS_ISD_DIST_HYST_L_Q15 11796 #define STEREO_DMX_EVS_ISD_DIST_HYST_H_Q15 14090 +#endif #define STEREO_DMX_EVS_ICCR_FORGETTING_Q31 1503238554 #define STEREO_DMX_EVS_ICCR_HYST_L_Q31 1610612736 @@ -153,8 +161,12 @@ static ivas_error estimate_itd_fx( STEREO_DMX_EVS_PHA_HANDLE hPHA, /* i/o: correlation filter structure */ const Word32 srcL[], /* i : Lch input signal Q16 */ const Word32 srcR[], /* i : Rch input signal Q16 */ - Word32 itd[], /* o : estimated itd Q16 */ - const Word16 input_frame /* i : input frame length per channel */ +#ifdef NONBE_FIX_1386_STEREO_DMX_EVS_PHA + Word16 itd[], /* o : estimated itd Q0 */ +#else + Word32 itd[], /* o : estimated itd Q16 */ +#endif + const Word16 input_frame /* i : input frame length per channel */ ); static void adapt_gain_fx( const Word32 src_fx[], /* i : input signal Q16 */ @@ -196,9 +208,13 @@ static void create_M_signal_fx( ); static Word32 find_poc_peak_fx( STEREO_DMX_EVS_POC_HANDLE hPOC, /* i/o: phase only correlation structure */ - Word32 itd_fx[], /* o : estimated itd */ - const Word16 input_frame, /* i : input frame length per channel */ - const Word32 ratio_fixed /* i : adapting ratio */ +#ifdef NONBE_FIX_1386_STEREO_DMX_EVS_PHA + Word16 itd_fx[], /* o : estimated itd */ +#else + Word32 itd_fx[], /* o : estimated itd */ +#endif + const Word16 input_frame, /* i : input frame length per channel */ + const Word32 ratio_fixed /* i : adapting ratio */ ); /*-------------------------------------------------------------------* * estimate_itd_wnd_fft() @@ -604,12 +620,21 @@ static void calc_poc_fx( Ni = L_sub( specLi[i], specRi[i] ); // spec_e Dr = L_add( specLr[i], specRr[i] ); // spec_e Di = L_add( specLi[i], specRi[i] ); // spec_e - // if ( ( Nr * Nr + Ni * Ni ) > STEREO_DMX_EVS_ISD_THRES_H * ( Dr * Dr + Di * Di ) ) + // if ( ( Nr * Nr + Ni * Ni ) > STEREO_DMX_EVS_ISD_THRES_H * ( Dr * Dr + Di * Di ) ) +#ifdef NONBE_FIX_1386_STEREO_DMX_EVS_PHA + IF( GT_32( Mpy_32_32_r( L_add( Mpy_32_32_r( Nr, Nr ), Mpy_32_32_r( Ni, Ni ) ), STEREO_DMX_EVS_ISD_INVTHRES_H ), L_add( Mpy_32_32_r( Dr, Dr ), Mpy_32_32_r( Di, Di ) ) ) ) +#else IF( GT_32( Mpy_32_32_r( L_add( Mpy_32_32_r( Nr, Nr ), Mpy_32_32_r( Ni, Ni ) ), 1270700383 /*1/STEREO_DMX_EVS_ISD_THRES_H in Q31*/ ), L_add( Mpy_32_32_r( Dr, Dr ), Mpy_32_32_r( Di, Di ) ) ) ) +#endif { isd_cnt_h = add( isd_cnt_h, 1 ); } +#ifdef NONBE_FIX_1386_STEREO_DMX_EVS_PHA + W_tmp = W_add( W_mult0_32_32( Mpy_32_32_r( Dr, STEREO_DMX_EVS_ISD_THRES_L_Q31 ), Dr ), W_mult0_32_32( Mpy_32_32_r( Di, STEREO_DMX_EVS_ISD_THRES_L_Q31 ), Di ) ); // Q62 + IF( LT_64( W_add( W_mult0_32_32( Nr, Nr ), W_mult0_32_32( Ni, Ni ) ), W_tmp ) ) // Q62 +#else IF( LT_32( L_add( Mpy_32_32_r( Nr, Nr ), Mpy_32_32_r( Ni, Ni ) ), Mpy_32_32_r( STEREO_DMX_EVS_ISD_THRES_L_Q31, L_add( Mpy_32_32_r( Dr, Dr ), Mpy_32_32_r( Di, Di ) ) ) ) ) +#endif { isd_cnt_l = add( isd_cnt_l, 1 ); } @@ -618,10 +643,19 @@ static void calc_poc_fx( isd_rate = BASOP_Util_Divide1616_Scale( isd_cnt_h, freq_8k, &isd_rate_e ); // Saturation to handle values close to 1.0f isd_rate = shl_sat( isd_rate, isd_rate_e ); // Q15 +#ifdef NONBE_FIX_1386_STEREO_DMX_EVS_PHA + hPHA->isd_rate_s_fx = L_add( Mpy_32_32_r( STEREO_DMX_EVS_ISD_FORGETTING_Q31, hPHA->isd_rate_s_fx ), L_mult( STEREO_DMX_EVS_ISD_1MFORGETTING_Q15, isd_rate ) ); + move32(); +#else hPHA->isd_rate_s_fx = add( mult_r( STEREO_DMX_EVS_ISD_FORGETTING_Q15, hPHA->isd_rate_s_fx ), mult_r( MAX_16 - STEREO_DMX_EVS_ISD_FORGETTING_Q15, isd_rate ) ); move16(); +#endif +#ifdef NONBE_FIX_1386_STEREO_DMX_EVS_PHA + IF( GT_32( hPHA->isd_rate_s_fx, STEREO_DMX_EVS_ISD_DIST_HYST_H_Q31 ) ) +#else IF( GT_16( hPHA->isd_rate_s_fx, STEREO_DMX_EVS_ISD_DIST_HYST_H_Q15 ) ) +#endif { IF( NE_32( hPHA->curr_pha, STEREO_DMX_EVS_PHA_IPD ) ) { @@ -646,7 +680,11 @@ static void calc_poc_fx( hPHA->prev_pha = STEREO_DMX_EVS_PHA_IPD; move32(); } +#ifdef NONBE_FIX_1386_STEREO_DMX_EVS_PHA + ELSE IF( LT_32( hPHA->isd_rate_s_fx, STEREO_DMX_EVS_ISD_DIST_HYST_L_Q31 ) ) +#else ELSE IF( LT_16( hPHA->isd_rate_s_fx, STEREO_DMX_EVS_ISD_DIST_HYST_L_Q15 ) ) +#endif { IF( NE_32( hPHA->curr_pha, STEREO_DMX_EVS_PHA_IPD2 ) ) { @@ -711,11 +749,36 @@ static void calc_poc_fx( FOR( j = 0; j < STEREO_DMX_EVS_SUBBAND_SIZE; ( j++, i++ ) ) { + /* Energy */ + +#ifdef NONBE_FIX_1386_STEREO_DMX_EVS_PHA + + // Left + W_tmp = W_add( W_mult0_32_32( specLr[i], specLr[i] ), W_mult0_32_32( specLi[i], specLi[i] ) ); // Q(62-(2*specL_e)) -> Q(63 - ((2*specL_e) +1)) + L_tmp_e = W_norm( W_tmp ); + IF( L_tmp_e != 0 ) + { + W_tmp = W_shl( W_tmp, L_tmp_e ); // Q(63 - ((2*spec_e) - (L_tmp_e - 1)) + } + tEl[n] = BASOP_Util_Add_Mant32Exp( tEl[n], tEl_e[n], W_round64_L( W_tmp ), sub( shl( spec_e, 1 ), sub( L_tmp_e, 1 ) ), &tEl_e[n] ); + move32(); + + // Right + W_tmp = W_add( W_mult0_32_32( specRr[i], specRr[i] ), W_mult0_32_32( specRi[i], specRi[i] ) ); // Q(62-(2*specR_e)) -> Q(63 - ((2*specR_e) +1)) + L_tmp_e = W_norm( W_tmp ); + IF( L_tmp_e != 0 ) + { + W_tmp = W_shl( W_tmp, L_tmp_e ); // Q(63 - ((2*spec_e) - (L_tmp_e - 1)) + } + tEr[n] = BASOP_Util_Add_Mant32Exp( tEr[n], tEr_e[n], W_round64_L( W_tmp ), sub( shl( spec_e, 1 ), sub( L_tmp_e, 1 ) ), &tEr_e[n] ); + move32(); +#else tEl[n] = BASOP_Util_Add_Mant32Exp( tEl[n], tEl_e[n], L_add( Mpy_32_32_r( specLr[i], specLr[i] ), Mpy_32_32_r( specLi[i], specLi[i] ) ), shl( spec_e, 1 ), &tEl_e[n] ); move32(); tEr[n] = BASOP_Util_Add_Mant32Exp( tEr[n], tEr_e[n], L_add( Mpy_32_32_r( specRr[i], specRr[i] ), Mpy_32_32_r( specRi[i], specRi[i] ) ), shl( spec_e, 1 ), &tEr_e[n] ); move32(); +#endif /* IPD */ // IPDr = L_add(Mpy_32_32_r(specLr[i], specRr[i]), Mpy_32_32_r(specLi[i], specRi[i])); //2*spec_e @@ -746,11 +809,35 @@ static void calc_poc_fx( tIPDr = L_sub( Mpy_32_32_r( specRr[i], IPDr ), Mpy_32_32_r( specRi[i], IPDi ) ); // spec_e tIPDi = L_add( Mpy_32_32_r( specRr[i], IPDi ), Mpy_32_32_r( specRi[i], IPDr ) ); // spec_e +#ifdef NONBE_FIX_1386_STEREO_DMX_EVS_PHA + + Nr = BASOP_Util_Add_Mant32Exp( Nr, Nr_e, L_add( Mpy_32_32_r( specLr[i], tIPDr ), Mpy_32_32_r( specLi[i], tIPDi ) ), 0, &Nr_e ); + Ni = BASOP_Util_Add_Mant32Exp( Ni, Ni_e, L_sub( Mpy_32_32_r( specLi[i], tIPDr ), Mpy_32_32_r( specLr[i], tIPDi ) ), 0, &Ni_e ); + + // eneL = BASOP_Util_Add_Mant32Exp( eneL, eneL_e, L_add( Mpy_32_32_r( specLr[i], specLr[i] ), Mpy_32_32_r( specLi[i], specLi[i] ) ), 0, &eneL_e ); + W_tmp = W_add( W_mult0_32_32( specLr[i], specLr[i] ), W_mult0_32_32( specLi[i], specLi[i] ) ); + L_tmp_e = W_norm( W_tmp ); + IF( L_tmp_e != 0 ) + { + W_tmp = W_shl( W_tmp, L_tmp_e ); + } + eneL = BASOP_Util_Add_Mant32Exp( eneL, eneL_e, W_round64_L( W_tmp ), sub( 1, L_tmp_e ), &eneL_e ); + + // eneR = BASOP_Util_Add_Mant32Exp( eneR, eneR_e, L_add( Mpy_32_32_r( specRr[i], specRr[i] ), Mpy_32_32_r( specRi[i], specRi[i] ) ), 0, &eneR_e ); + W_tmp = W_add( W_mult0_32_32( specRr[i], specRr[i] ), W_mult0_32_32( specRi[i], specRi[i] ) ); + L_tmp_e = W_norm( W_tmp ); + IF( L_tmp_e != 0 ) + { + W_tmp = W_shl( W_tmp, L_tmp_e ); + } + eneR = BASOP_Util_Add_Mant32Exp( eneR, eneR_e, W_round64_L( W_tmp ), sub( 1, L_tmp_e ), &eneR_e ); +#else Nr = BASOP_Util_Add_Mant32Exp( Nr, Nr_e, L_add( Mpy_32_32_r( specLr[i], tIPDr ), Mpy_32_32_r( specLi[i], tIPDi ) ), shl( spec_e, 1 ), &Nr_e ); Ni = BASOP_Util_Add_Mant32Exp( Ni, Ni_e, L_sub( Mpy_32_32_r( specLi[i], tIPDr ), Mpy_32_32_r( specLr[i], tIPDi ) ), shl( spec_e, 1 ), &Ni_e ); eneL = BASOP_Util_Add_Mant32Exp( eneL, eneL_e, L_add( Mpy_32_32_r( specLr[i], specLr[i] ), Mpy_32_32_r( specLi[i], specLi[i] ) ), shl( spec_e, 1 ), &eneL_e ); eneR = BASOP_Util_Add_Mant32Exp( eneR, eneR_e, L_add( Mpy_32_32_r( specRr[i], specRr[i] ), Mpy_32_32_r( specRi[i], specRi[i] ) ), shl( spec_e, 1 ), &eneR_e ); +#endif } // Pn = (float) inv_sqrt( ( tPr * tPr + tPi * tPi ) + EPSILON ); @@ -768,7 +855,13 @@ static void calc_poc_fx( move32(); Pi[n] = L_add( Mpy_32_32_r( ipd_ff[n], Pi[n] ), Mpy_32_32_r( L_sub( MAX_32, ipd_ff[n] ), tPi ) ); move32(); + // Pn = (float) inv_sqrt( ( Pr[n] * Pr[n] + Pi[n] * Pi[n] ) + EPSILON ); +#ifdef NONBE_FIX_1386_STEREO_DMX_EVS_PHA + Pn = L_add( L_shr( Mpy_32_32_r( Pr[n], Pr[n] ), 1 ), L_shr( Mpy_32_32_r( Pi[n], Pi[n] ), 1 ) ); + Pn = BASOP_Util_Add_Mant32Exp( Pn, 1, EPSILON_FX_M, EPSILON_FX_E, &Pn_e ); + Pn = Isqrt_lc( Pn, &Pn_e ); +#else L_tmp = L_add( L_shr( Mpy_32_32_r( Pr[n], Pr[n] ), 1 ), L_shr( Mpy_32_32_r( Pi[n], Pi[n] ), 1 ) ); L_tmp_e = 1; move16(); @@ -776,6 +869,8 @@ static void calc_poc_fx( Pn_e = L_tmp_e; move16(); Pn = ISqrt32( L_tmp, &Pn_e ); +#endif + Pr[n] = L_shl_sat( Mpy_32_32_r( Pr[n], Pn ), Pn_e ); // Q31 move32(); Pi[n] = L_shl_sat( Mpy_32_32_r( Pi[n], Pn ), Pn_e ); // Q31 @@ -981,11 +1076,17 @@ static void calc_poc_fx( FOR( i = 0; i < hPHA->pha_len; i++ ) { // hPHA->p_curr_taps[n][i] *= hPHA->win[i]; +#ifdef NONBE_FIX_1386_STEREO_DMX_EVS_PHA + hPHA->p_curr_taps_fx[n][i] = Mpy_32_16_1( hPHA->p_curr_taps_fx[n][i], hPHA->win_fx[i] ); // Q30 +#else + #ifdef FIX_ISSUE_1153 hPHA->p_curr_taps_fx[n][i] = Mpy_32_16_1( hPHA->p_curr_taps_fx[n][i], hPHA->win_fx[i] ); // Q30 #else hPHA->p_curr_taps_fx[n][i] = L_shl( Mpy_32_16_1( hPHA->p_curr_taps_fx[n][i], hPHA->win_fx[i] ), 1 ); // Q31 #endif + +#endif // NONBE_FIX_1386_STEREO_DMX_EVS_PHA move32(); } @@ -993,6 +1094,7 @@ static void calc_poc_fx( move32(); energy_e = 0; move16(); +#ifndef NONBE_FIX_1386_STEREO_DMX_EVS_PHA #ifdef FIX_ISSUE_1153 Word16 shift = L_norm_arr( hPHA->p_curr_taps_fx[n], hPHA->pha_len ); IF( shift ) @@ -1002,20 +1104,29 @@ static void calc_poc_fx( move16(); } #endif +#endif // NONBE_FIX_1386_STEREO_DMX_EVS_PHA FOR( i = 0; i < hPHA->pha_len; i++ ) { +#ifdef NONBE_FIX_1386_STEREO_DMX_EVS_PHA + energy = BASOP_Util_Add_Mant32Exp( energy, energy_e, Mpy_32_32_r( hPHA->p_curr_taps_fx[n][i], hPHA->p_curr_taps_fx[n][i] ), 0, &energy_e ); +#else #ifdef FIX_ISSUE_1153 energy = BASOP_Util_Add_Mant32Exp( energy, energy_e, Mpy_32_32_r( hPHA->p_curr_taps_fx[n][i], hPHA->p_curr_taps_fx[n][i] ), shl( sub( 1, shift ), 1 ), &energy_e ); #else energy = BASOP_Util_Add_Mant32Exp( energy, energy_e, Mpy_32_32_r( hPHA->p_curr_taps_fx[n][i], hPHA->p_curr_taps_fx[n][i] ), 0, &energy_e ); #endif +#endif // NONBE_FIX_1386_STEREO_DMX_EVS_PHA } // energy = (float) inv_sqrt( energy + EPSILON ); energy = BASOP_Util_Add_Mant32Exp( energy, energy_e, EPSILON_FX_M, EPSILON_FX_E, &energy_e ); energy = ISqrt32( energy, &energy_e ); FOR( i = 0; i < hPHA->pha_len; i++ ) { +#ifdef NONBE_FIX_1386_STEREO_DMX_EVS_PHA + hPHA->p_curr_taps_fx[n][i] = L_shl_r( Mpy_32_32_r( hPHA->p_curr_taps_fx[n][i], energy ), sub( energy_e, 1 ) ); // Q30 +#else hPHA->p_curr_taps_fx[n][i] = L_shl_r( Mpy_32_32_r( hPHA->p_curr_taps_fx[n][i], energy ), energy_e ); // Q31 +#endif move32(); } } @@ -1118,9 +1229,13 @@ static void calc_poc_fx( *-------------------------------------------------------------------*/ static Word32 find_poc_peak_fx( STEREO_DMX_EVS_POC_HANDLE hPOC, /* i/o: phase only correlation structure */ - Word32 itd_fx[], /* o : estimated itd Q16 */ - const Word16 input_frame, /* i : input frame length per channel */ - const Word32 ratio_fixed /* i : adapting ratio Q31 */ +#ifdef NONBE_FIX_1386_STEREO_DMX_EVS_PHA + Word16 itd_fx[], /* o : estimated itd Q0 */ +#else + Word32 itd_fx[], /* o : estimated itd Q16 */ +#endif + const Word16 input_frame, /* i : input frame length per channel */ + const Word32 ratio_fixed /* i : adapting ratio Q31 */ ) { Word16 itd_cand[CPE_CHANNELS], i, n, cnt[CPE_CHANNELS], Lh, peak_range, *on, *itdLR, prev_off[CPE_CHANNELS], eps_fx; @@ -1430,8 +1545,12 @@ static ivas_error estimate_itd_fx( STEREO_DMX_EVS_PHA_HANDLE hPHA, /* i/o: correlation filter structure */ const Word32 srcL[], /* i : Lch input signal Q16 */ const Word32 srcR[], /* i : Rch input signal Q16 */ - Word32 itd[], /* o : estimated itd Q16 */ - const Word16 input_frame /* i : input frame length per channel */ +#ifdef NONBE_FIX_1386_STEREO_DMX_EVS_PHA + Word16 itd[], /* o : estimated itd Q0 */ +#else + Word32 itd[], /* o : estimated itd Q16 */ +#endif + const Word16 input_frame /* i : input frame length per channel */ ) { Word32 specLr[L_FRAME48k / 2 + 1], specLi[L_FRAME48k / 2 + 1], specRr[L_FRAME48k / 2 + 1], specRi[L_FRAME48k / 2 + 1]; @@ -1938,9 +2057,9 @@ void stereo_dmx_evs_enc_fx( hStereoDmxEVS->dmx_weight_fx, hStereoDmxEVS->pre_dmx_energy_fx, hStereoDmxEVS->pre_dmx_energy_fx_e, hStereoDmxEVS->aux_dmx_energy_fx, hStereoDmxEVS->aux_dmx_energy_fx_e ); // Downscaling signals to avoid accumulation overflows - scale_sig32( data_fx[0], input_frame, -5 ); // Q16->Q11 - scale_sig32( data_fx[1], input_frame, -5 ); // Q16->Q11 - scale_sig32( dmx_poc_data, input_frame, -5 ); // Q16->Q11 + scale_sig32( data_fx[0], input_frame, -5 ); // Q31->Q26 + scale_sig32( data_fx[1], input_frame, -5 ); // Q31->Q26 + scale_sig32( dmx_poc_data, input_frame, -5 ); // Q31->Q26 /* pha */ @@ -1969,9 +2088,11 @@ void stereo_dmx_evs_enc_fx( FOR( ( fx_tmp = 0, m = 0 ); m < pha_len; m++ ) { // ftmp += p_data_mem[n - m] * p_prev_taps[m]; - // fx_tmp = BASOP_Util_Add_Mant32Exp(fx_tmp, fx_tmp_e, Mpy_32_32(p_data_mem[n - m], p_prev_taps[m]),15,&fx_tmp_e); - fx_tmp = L_add( fx_tmp, Mpy_32_32( p_data_mem[n - m], p_prev_taps[m] ) ); // Q11 + fx_tmp = L_add( fx_tmp, Mpy_32_32( p_data_mem[n - m], p_prev_taps[m] ) ); // Q25 } +#ifdef NONBE_FIX_1386_STEREO_DMX_EVS_PHA + fx_tmp = L_shl( fx_tmp, 1 ); // Q26 +#endif mem_prev[n] = L_add( mem_prev[n], Mpy_32_32( fx_tmp, INV_SQRT_2_Q31 ) ); move32(); } @@ -1981,7 +2102,7 @@ void stereo_dmx_evs_enc_fx( FOR( n = 0; n < fad_len; n++ ) { // mem_prev[n] += p_data[n] * INV_SQRT_2; - mem_prev[n] = L_add( mem_prev[n], Mpy_32_32( p_data[n], INV_SQRT_2_Q31 ) ); // Q11 + mem_prev[n] = L_add( mem_prev[n], Mpy_32_32( p_data[n], INV_SQRT_2_Q31 ) ); // Q26 move32(); } } @@ -1994,10 +2115,13 @@ void stereo_dmx_evs_enc_fx( FOR( ( fx_tmp = 0, m = 0 ); m < pha_len; m++ ) { // ftmp += p_data_mem[n - m] * p_curr_taps[m]; - fx_tmp = L_add( fx_tmp, Mpy_32_32( p_data_mem[n - m], p_curr_taps[m] ) ); // Q11 + fx_tmp = L_add( fx_tmp, Mpy_32_32( p_data_mem[n - m], p_curr_taps[m] ) ); // Q25 } +#ifdef NONBE_FIX_1386_STEREO_DMX_EVS_PHA + fx_tmp = L_shl( fx_tmp, 1 ); // Q26 +#endif // dmx_pha_data[n] += ftmp * INV_SQRT_2; - dmx_pha_data[n] = L_add( dmx_pha_data[n], Mpy_32_32( fx_tmp, INV_SQRT_2_Q31 ) ); // Q11 + dmx_pha_data[n] = L_add( dmx_pha_data[n], Mpy_32_32( fx_tmp, INV_SQRT_2_Q31 ) ); // Q26 move32(); } } @@ -2006,7 +2130,7 @@ void stereo_dmx_evs_enc_fx( FOR( n = 0; n < n_samples; n++ ) { // dmx_pha_data[n] += p_data[n] * INV_SQRT_2; - dmx_pha_data[n] = L_add( dmx_pha_data[n], Mpy_32_32( p_data[n], INV_SQRT_2_Q31 ) ); // Q11 + dmx_pha_data[n] = L_add( dmx_pha_data[n], Mpy_32_32( p_data[n], INV_SQRT_2_Q31 ) ); // Q26 move32(); } } @@ -2016,7 +2140,7 @@ void stereo_dmx_evs_enc_fx( { dmx_pha_data[n] = Mpy_32_32( dmx_pha_data[n], fad_g[n] ); move32(); - dmx_pha_data[n] = L_add( dmx_pha_data[n], Mpy_32_32( mem_prev[n], fad_g[m] ) ); // Q11 + dmx_pha_data[n] = L_add( dmx_pha_data[n], Mpy_32_32( mem_prev[n], fad_g[m] ) ); // Q26 move32(); } @@ -2025,7 +2149,11 @@ void stereo_dmx_evs_enc_fx( curr_prc = hStereoDmxEVS->hPHA->curr_prc; move32(); // if ( abs( (int16_t) hStereoDmxEVS->itd ) > hStereoDmxEVS->hPHA->prc_thres ) +#ifdef NONBE_FIX_1386_STEREO_DMX_EVS_PHA + IF( GT_16( abs_s( hStereoDmxEVS->itd_fx ), hStereoDmxEVS->hPHA->prc_thres ) ) +#else IF( GT_16( abs_s( round_fx( hStereoDmxEVS->itd_fx ) ), hStereoDmxEVS->hPHA->prc_thres ) ) +#endif { IF( NE_32( hStereoDmxEVS->hPHA->curr_prc, STEREO_DMX_EVS_PRC_POC ) ) { @@ -2102,9 +2230,9 @@ void stereo_dmx_evs_enc_fx( FOR( ( n = 0, m = ( fad_len - 1 ) ); n < fad_len; ( n++, m-- ) ) { - p_dmx_data[n] = Mpy_32_32( p_dmx_data[n], fad_g[n] ); // Q11 + p_dmx_data[n] = Mpy_32_32( p_dmx_data[n], fad_g[n] ); // Q26 move32(); - p_dmx_data[n] = L_add( p_dmx_data[n], Mpy_32_32( fad_g[m], dmx_pha_data[n] ) ); // Q11 + p_dmx_data[n] = L_add( p_dmx_data[n], Mpy_32_32( fad_g[m], dmx_pha_data[n] ) ); // Q26 move32(); } } @@ -2121,16 +2249,15 @@ void stereo_dmx_evs_enc_fx( FOR( ( n = 0, m = ( fad_len - 1 ) ); n < fad_len; ( n++, m-- ) ) { - p_dmx_data[n] = Mpy_32_32( p_dmx_data[n], fad_g[n] ); // Q11 + p_dmx_data[n] = Mpy_32_32( p_dmx_data[n], fad_g[n] ); // Q26 move32(); - p_dmx_data[n] = L_add( p_dmx_data[n], Mpy_32_32( fad_g[m], dmx_poc_data[n] ) ); // Q11 + p_dmx_data[n] = L_add( p_dmx_data[n], Mpy_32_32( fad_g[m], dmx_poc_data[n] ) ); // Q26 move32(); } } } - Copy_Scale_sig32_16( p_dmx_data, data, n_samples, 5 ); // Q11->Q0 - + Copy_Scale_sig32_16( p_dmx_data, data, n_samples, 5 ); // Q26->Q15 return; } @@ -2149,9 +2276,15 @@ ivas_error stereo_dmx_evs_init_encoder_fx( STEREO_DMX_EVS_ENC_HANDLE hStereoDmxEVS; Word16 n, input_frame; +#ifdef NONBE_FIX_1386_STEREO_DMX_EVS_PHA + Word16 m, len, pha_len, fad_len, fad_len2, rfft_ipd_coef_step, n0, input_frame_pha; + Word32 *fad_g, fad_r, *ipd_ff; + Word16 *win; +#else Word16 m, len, pha_len, fad_len, fad_len2, trans_len /*, itrh*/, rfft_ipd_coef_step, n0, input_frame_pha; Word32 *fad_g, fad_r /*, a_min, a_max, a_step*/, *ipd_ff; Word16 *win, tmp_r; +#endif const Word16 *p_ipd_w; Word16 tmp_e; @@ -2383,6 +2516,23 @@ ivas_error stereo_dmx_evs_init_encoder_fx( fad_len = hStereoDmxEVS->hPHA->fad_len; move16(); +#ifdef NONBE_FIX_1386_STEREO_DMX_EVS_PHA + set16_fx( hStereoDmxEVS->hPHA->win_fx, 29491 /*1.8f in Q14*/, pha_len ); + hStereoDmxEVS->hPHA->win_fx[0] = ONE_IN_Q14; + move16(); + IF( EQ_32( input_Fs, 16000 ) ) + { + hStereoDmxEVS->hPHA->win_fx[pha_len - 1] = 7373; /*0.45f in Q14*/ + move16(); + } + ELSE IF( EQ_32( input_Fs, 32000 ) || EQ_32( input_Fs, 48000 ) ) + { + hStereoDmxEVS->hPHA->win_fx[sub( pha_len, 2 )] = 19302; /*1.1781f in Q14*/ + move16(); + hStereoDmxEVS->hPHA->win_fx[sub( pha_len, 1 )] = 2816; /*0.1718f in Q14*/ + move16(); + } +#else trans_len = idiv1616( pha_len, 20 ); set16_fx( hStereoDmxEVS->hPHA->win_fx, 29491 /*1.8f in Q15*/, sub( pha_len, trans_len ) ); hStereoDmxEVS->hPHA->win_fx[0] = ONE_IN_Q14; @@ -2396,6 +2546,7 @@ ivas_error stereo_dmx_evs_init_encoder_fx( win[n] = mult_r( add( ONE_IN_Q14, getCosWord16R2( imult1616( add( n, 1 ), tmp_r ) ) ), 29491 /*1.8/2 in Q15*/ ); move16(); } +#endif fad_g = hStereoDmxEVS->hPHA->fad_g_fx; // fad_r = 1.0f / (float) ( fad_len + 1 );