diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index 068d7c1f1f100b30e4bcdba7b728b33a71625bae..85bbcb4b10d2624ab6bd18289af66c0ca77c0f4f 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -1884,6 +1884,7 @@ void GenShapedWBExcitation_ivas_fx( Word16 *mem_genSHBexc_filt_down3, /* i/o : memory Q_bwe_exc*/ Word16 *state_lpc_syn, /* i/o : memory Q_bwe_exc*/ const Word16 coder_type, /* i : coding type */ + const Word16 element_mode, /* i : element mode */ const Word16 *bwe_exc_extended, /* i : bwidth extended exciatation Q_bwe_exc*/ const Word16 Q_bwe_exc, Word16 bwe_seed[], /* i/o : random number generator seed */ diff --git a/lib_com/options.h b/lib_com/options.h index cabe32178030e50c1dd94055f320036967949335..64f0ce3aa63dd252d1d008136679ef8e5a2cbb95 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -98,6 +98,7 @@ #define FIX_1461_CNG_BW_SWITCHING /* Eri: float issue 1461: Stereo parameters are not updated when SID/NODATA forces BW to stay the same */ #define FIX_2041_SPECTRAL_GAPS_FOR_INACTIVE_FRAMES /* FhG: Using rounding in multiplication to improve precision in cngNoiseLevel[] */ #define FIX_2264_OUT_OF_BOUND_READING_IN_LOG2_NORM_LC /* VA: Fix issue 2264 by adding a proper safeguard in log2 and by adding a missing normalization in swb_pre_proc_ivas_fx()*/ +#define FIX_2250_LARGE_DIFFERENCES_BETWEEN_BASOP_AND_FLOAT /* Dolby: Issue 2250: random vector generation in GenShapedSHBExcitation() */ /* ##################### End NON-BE switches ########################### */ diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index bf24d493e29618fcce60ee39e5fcd9933a62dbb0..bba113ec0430e25ac92fbab05b02909dd86356f7 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -2992,6 +2992,7 @@ void GenShapedWBExcitation_fx( Word16 *mem_genSHBexc_filt_down3, /* i/o : memory */ Word16 *state_lpc_syn, /* i/o : memory */ const Word16 coder_type, /* i : coding type */ + const Word16 element_mode, /* i : element mode */ const Word16 *bwe_exc_extended, /* i : bandwidth extended exciatation */ const Word16 Q_bwe_exc, Word16 bwe_seed[], /* i/o : random number generator seed */ @@ -3014,6 +3015,7 @@ void GenShapedSHBExcitation_fx( Word16 *mem_genSHBexc_filt_down_shb, /* i/o: memory */ Word16 *state_lpc_syn, /* i/o: memory */ const Word16 coder_type, /* i : coding type */ + const Word16 element_mode, /* i : element mode */ const Word16 *bwe_exc_extended, /* i : bandwidth extended excitation */ Word16 bwe_seed[], /* i/o: random number generator seed */ Word16 voice_factors[], /* i : voicing factor*/ diff --git a/lib_com/swb_tbe_com_fx.c b/lib_com/swb_tbe_com_fx.c index e63dc471ebd194f07d9a62648460c6ad02d96846..c9d307ef26b0bd5fefabb8f24f3d9941581893cc 100644 --- a/lib_com/swb_tbe_com_fx.c +++ b/lib_com/swb_tbe_com_fx.c @@ -26,7 +26,7 @@ * Local function prototypes *-----------------------------------------------------------------*/ -static void create_random_vector_fx( Word16 output[], const Word16 length, Word16 seed[] ); +static void create_random_vector_fx( Word16 output[], const Word16 length, Word16 seed[], Word16 element_mode ); static void flip_spectrum_fx( const Word16 input[], Word16 output[], const Word16 length ); static void Calc_st_filt_tbe( Word16 *apond2, Word16 *apond1, Word16 *parcor0, Word16 *sig_ltp_ptr, Word16 *mem_zero ); static void Hilbert_transform_fx( Word32 tmp_R[], Word32 tmp_I[], Word32 *tmpi_R, Word32 *tmpi_I, const Word16 length, const Word16 HB_stage_id ); @@ -1415,6 +1415,7 @@ void GenShapedWBExcitation_ivas_fx( Word16 *mem_genSHBexc_filt_down3, /* i/o : memory Q_bwe_exc*/ Word16 *state_lpc_syn, /* i/o : memory Q_bwe_exc*/ const Word16 coder_type, /* i : coding type */ + const Word16 element_mode, /* i : element mode */ const Word16 *bwe_exc_extended, /* i : bwidth extended exciatation Q_bwe_exc*/ const Word16 Q_bwe_exc, Word16 bwe_seed[], /* i/o : random number generator seed */ @@ -1478,7 +1479,7 @@ void GenShapedWBExcitation_ivas_fx( IF( uv_flag ) { - create_random_vector_fx( exc4kWhtnd, L_FRAME16k / 4, bwe_seed ); + create_random_vector_fx( exc4kWhtnd, L_FRAME16k / 4, bwe_seed, element_mode ); IF( LT_16( Q_bwe_exc, 5 ) ) { @@ -1554,7 +1555,7 @@ void GenShapedWBExcitation_ivas_fx( move32(); /* Q_bwe_exc+16 */ } - create_random_vector_fx( exc4k, L_FRAME16k / 4, bwe_seed ); + create_random_vector_fx( exc4k, L_FRAME16k / 4, bwe_seed, element_mode ); /* Ensure pow22 is greater than zero when computing normalization */ Lmax = 0; @@ -1661,6 +1662,7 @@ void GenShapedWBExcitation_fx( Word16 *mem_genSHBexc_filt_down3, /* i/o : memory Q(Q_bwe_exc) */ Word16 *state_lpc_syn, /* i/o : memory Q(Q_bwe_exc) */ const Word16 coder_type, /* i : coding type */ + const Word16 element_mode, /* i : element mode */ const Word16 *bwe_exc_extended, /* i : bwidth extended exciatation Q(Q_bwe_exc) */ const Word16 Q_bwe_exc, /* i : Q for memories */ Word16 bwe_seed[], /* i/o : random number generator seed */ @@ -1727,7 +1729,7 @@ void GenShapedWBExcitation_fx( IF( uv_flag ) { - create_random_vector_fx( exc4kWhtnd, L_FRAME16k / 4, bwe_seed ); + create_random_vector_fx( exc4kWhtnd, L_FRAME16k / 4, bwe_seed, element_mode ); IF( LT_16( Q_bwe_exc, 5 ) ) { FOR( i = 0; i < L_FRAME16k / 4; i++ ) @@ -1802,7 +1804,7 @@ void GenShapedWBExcitation_fx( move32(); /* Q_bwe_exc+16 */ } - create_random_vector_fx( exc4k, L_FRAME16k / 4, bwe_seed ); + create_random_vector_fx( exc4k, L_FRAME16k / 4, bwe_seed, element_mode ); /* Ensure pow22 is greater than zero when computing normalization */ Lmax = 0; @@ -2074,6 +2076,7 @@ void GenShapedSHBExcitation_fx( Word16 *mem_genSHBexc_filt_down_shb, /* i/o: memory */ Word16 *state_lpc_syn, /* i/o: memory */ const Word16 coder_type, /* i : coding type */ + const Word16 element_mode, /* i : element mode */ const Word16 *bwe_exc_extended, /* i : bwidth extended excitation */ Word16 bwe_seed[], /* i/o: random number generator seed */ Word16 voice_factors[], /* i : voicing factor*/ @@ -2293,8 +2296,8 @@ void GenShapedSHBExcitation_fx( { /* create a random excitation - Reuse exc16k memory */ White_exc16k = exc16k; - create_random_vector_fx( White_exc16k, L_FRAME, bwe_seed ); - create_random_vector_fx( White_exc16k + L_FRAME, L_FRAME16k - L_FRAME, bwe_seed ); + create_random_vector_fx( White_exc16k, L_FRAME, bwe_seed, element_mode ); + create_random_vector_fx( White_exc16k + L_FRAME, L_FRAME16k - L_FRAME, bwe_seed, element_mode ); L_tmp = L_deposit_l( 0 ); tmp = add( *Q_bwe_exc, 1 ); @@ -2978,8 +2981,8 @@ void GenShapedSHBExcitation_ivas_enc_fx( ELSE { /* create a random excitation - Reuse exc16k memory */ - create_random_vector_fx( White_exc16k, L_FRAME, bwe_seed ); // Q5 - create_random_vector_fx( White_exc16k + L_FRAME, L_FRAME16k - L_FRAME, bwe_seed ); // Q5 + create_random_vector_fx( White_exc16k, L_FRAME, bwe_seed, element_mode ); // Q5 + create_random_vector_fx( White_exc16k + L_FRAME, L_FRAME16k - L_FRAME, bwe_seed, element_mode ); // Q5 L_tmp = L_deposit_l( 0 ); tmp = add( *Q_bwe_exc, 1 ); @@ -4006,8 +4009,8 @@ void GenShapedSHBExcitation_ivas_dec_fx( /* create a random excitation - Reuse exc16k memory */ White_exc16k = exc16k; move16(); - create_random_vector_fx( White_exc16k, L_FRAME, bwe_seed ); // Q5 - create_random_vector_fx( White_exc16k + L_FRAME, L_FRAME16k - L_FRAME, bwe_seed ); // Q5 + create_random_vector_fx( White_exc16k, L_FRAME, bwe_seed, element_mode ); // Q5 + create_random_vector_fx( White_exc16k + L_FRAME, L_FRAME16k - L_FRAME, bwe_seed, element_mode ); // Q5 L_tmp = L_deposit_l( 0 ); tmp = add( *Q_bwe_exc, 1 ); @@ -6109,24 +6112,68 @@ void non_linearity_ivas_fx( void create_random_vector_fx( Word16 output[], /* o : output random vector Q5*/ const Word16 length, /* i : length of random vector */ - Word16 seed[] /* i/o: start seed */ + Word16 seed[], /* i/o: start seed */ + Word16 element_mode /* i : element mode */ ) { Word16 i, j, k; Word16 scale1, scale2; Word32 L_tmp; + /* + Note: the constant 2144047674 is 0.0078f in Q38 from the float reference. + It should read 0.0078125f, which is 1/128.Since 0.0078f is nor exactly + depictable in fixed point, rounding has to be performed to get the same + j and k values for any input (e.g. if Random() returns 5000) + */ + +#ifdef FIX_2250_LARGE_DIFFERENCES_BETWEEN_BASOP_AND_FLOAT + if ( element_mode != EVS_MONO ) + { + L_tmp = L_abs( Mpy_32_16_r( 2144047674, Random( &seed[0] ) ) ); /*Q23 */ + } + else + { + L_tmp = L_abs( Mult_32_16( 2144047674, Random( &seed[0] ) ) ); /*Q23 */ + } +#else + L_tmp = L_abs( Mult_32_16( 2144047674, Random( &seed[0] ) ) ); /*Q23 */ +#endif - L_tmp = L_abs( Mult_32_16( 2144047674, Random( &seed[0] ) ) ); /*Q23 */ j = extract_l( L_shr( L_tmp, 23 ) ); j = s_and( j, 0xff ); - L_tmp = L_abs( Mult_32_16( 2144047674, Random( &seed[1] ) ) ); /*Q23 */ +#ifdef FIX_2250_LARGE_DIFFERENCES_BETWEEN_BASOP_AND_FLOAT + if ( element_mode != EVS_MONO ) + { + L_tmp = L_abs( Mpy_32_16_r( 2144047674, Random( &seed[1] ) ) ); /*Q23 */ + } + else + { + L_tmp = L_abs( Mult_32_16( 2144047674, Random( &seed[1] ) ) ); /*Q23 */ + } + +#else + L_tmp = L_abs( Mult_32_16( 2144047674, Random( &seed[1] ) ) ); /*Q23 */ +#endif + k = extract_l( L_shr( L_tmp, 23 ) ); k = s_and( k, 0xff ); WHILE( EQ_16( k, j ) ) { +#ifdef FIX_2250_LARGE_DIFFERENCES_BETWEEN_BASOP_AND_FLOAT + if ( element_mode != EVS_MONO ) + { + L_tmp = L_abs( Mpy_32_16_r( 2144047674, Random( &seed[1] ) ) ); /*Q23 */ + } + else + { + L_tmp = L_abs( Mult_32_16( 2144047674, Random( &seed[1] ) ) ); /*Q23 */ + } +#else L_tmp = L_abs( Mult_32_16( 2144047674, Random( &seed[1] ) ) ); /*Q23 */ +#endif + k = extract_l( L_shr( L_tmp, 23 ) ); k = s_and( k, 0xff ); } diff --git a/lib_dec/swb_tbe_dec_fx.c b/lib_dec/swb_tbe_dec_fx.c index 5ca7ba1f640bc7d7c015c0833efcd0d66a6a4f57..c61e4ddf31c40ee60b9fe0624ce1300cbdcbd23e 100644 --- a/lib_dec/swb_tbe_dec_fx.c +++ b/lib_dec/swb_tbe_dec_fx.c @@ -895,7 +895,7 @@ void ivas_wb_tbe_dec_fx( GenShapedWBExcitation_ivas_fx( shaped_wb_excitation + L_SHB_LAHEAD / 4, lpc_wb, exc4kWhtnd, hBWE_TD->mem_csfilt_fx, hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, - hBWE_TD->mem_genSHBexc_filt_down_wb3_fx, hBWE_TD->state_lpc_syn_fx, coder_type, + hBWE_TD->mem_genSHBexc_filt_down_wb3_fx, hBWE_TD->state_lpc_syn_fx, coder_type, st_fx->element_mode, bwe_exc_extended_16, Q_bwe_exc_ext, hBWE_TD->bwe_seed, vf_modified, uv_flag, st_fx->igf ); curr_pow = 0; @@ -1535,7 +1535,7 @@ void wb_tbe_dec_fx( GenShapedWBExcitation_fx( shaped_wb_excitation + L_SHB_LAHEAD / 4, lpc_wb, exc4kWhtnd, hBWE_TD->mem_csfilt_fx, hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, - hBWE_TD->mem_genSHBexc_filt_down_wb3_fx, hBWE_TD->state_lpc_syn_fx, coder_type, + hBWE_TD->mem_genSHBexc_filt_down_wb3_fx, hBWE_TD->state_lpc_syn_fx, coder_type, st_fx->element_mode, bwe_exc_extended_16, Q_bwe_exc_ext, hBWE_TD->bwe_seed, vf_modified, uv_flag, st_fx->igf ); curr_pow = 0; @@ -2653,7 +2653,7 @@ void swb_tbe_dec_fx( /* Calculate the 6 to 14 kHz (or 7.5 - 15.5 kHz) SHB excitation signal from the low band ACELP core excitation */ GenShapedSHBExcitation_fx( shaped_shb_excitation + L_SHB_LAHEAD, lpc_shb, White_exc16k, hBWE_TD->mem_csfilt_fx, hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->state_lpc_syn_fx, - coder_type, bwe_exc_extended_16, hBWE_TD->bwe_seed, vf_modified, st_fx->extl, + coder_type, st_fx->element_mode, bwe_exc_extended_16, hBWE_TD->bwe_seed, vf_modified, st_fx->extl, &( hBWE_TD->tbe_demph_fx ), &( hBWE_TD->tbe_premph_fx ), lpc_shb_sf, shb_ener_sf_32, shb_res_gshape, shb_res_dummy, &vind, formant_fac, hBWE_TD->fb_state_lpc_syn_fx, &( hBWE_TD->fb_tbe_demph_fx ), &Q_bwe_exc, &Q_bwe_exc_fb, Q_shb, n_mem2, hBWE_TD->prev_Q_bwe_syn, st_fx->total_brate, st_fx->prev_bfi ); diff --git a/lib_enc/swb_tbe_enc_fx.c b/lib_enc/swb_tbe_enc_fx.c index e2e66dd5f0d1fa10fcc1f91600433f240696412d..7de83621a5cc1158f55c2aec57a360c4a28ac41d 100644 --- a/lib_enc/swb_tbe_enc_fx.c +++ b/lib_enc/swb_tbe_enc_fx.c @@ -986,7 +986,7 @@ void wb_tbe_enc_fx( GenShapedWBExcitation_fx( shaped_wb_excitation + L_SHB_LAHEAD / 4, lpc_wb, exc4kWhtnd, hBWE_TD->mem_csfilt_fx, hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, hBWE_TD->mem_genSHBexc_filt_down_wb3_fx, - hBWE_TD->state_lpc_syn_fx, coder_type, bwe_exc_extended_16, Q_bwe_exc_ext, hBWE_TD->bwe_seed, + hBWE_TD->state_lpc_syn_fx, coder_type, st_fx->element_mode, bwe_exc_extended_16, Q_bwe_exc_ext, hBWE_TD->bwe_seed, vf_modified_fx, uv_flag, st_fx->igf ); curr_pow = 0; @@ -1592,7 +1592,7 @@ void wb_tbe_enc_ivas_fx( GenShapedWBExcitation_ivas_fx( shaped_wb_excitation + L_SHB_LAHEAD / 4, lpc_wb, exc4kWhtnd, hBWE_TD->mem_csfilt_fx, hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, hBWE_TD->mem_genSHBexc_filt_down_wb3_fx, - hBWE_TD->state_lpc_syn_fx, st_fx->coder_type, bwe_exc_extended_16, Q_bwe_exc_ext, hBWE_TD->bwe_seed, + hBWE_TD->state_lpc_syn_fx, st_fx->coder_type, st_fx->element_mode, bwe_exc_extended_16, Q_bwe_exc_ext, hBWE_TD->bwe_seed, vf_modified_fx, uv_flag, st_fx->igf ); curr_pow = 0; @@ -2393,7 +2393,7 @@ void swb_tbe_enc_fx( GenShapedSHBExcitation_fx( shaped_shb_excitation_fx + L_SHB_LAHEAD, lpc_shb_fx, White_exc16k_fx, hBWE_TD->mem_csfilt_fx, hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->state_lpc_syn_fx, - coder_type, bwe_exc_extended_16, hBWE_TD->bwe_seed, vf_modified_fx, st_fx->extl, + coder_type, st_fx->element_mode, bwe_exc_extended_16, hBWE_TD->bwe_seed, vf_modified_fx, st_fx->extl, &( hBWE_TD->tbe_demph_fx ), &( hBWE_TD->tbe_premph_fx ), lpc_shb_sf_fx, shb_ener_sf_Q31, shb_res_gshape_fx, shb_res_fx, &vf_ind_fx, formant_fac_fx, hBWE_TD->fb_state_lpc_syn_fx, &( hBWE_TD->fb_tbe_demph_fx ), &Q_bwe_exc, &Q_bwe_exc_fb, Q_shb, n_mem2, hBWE_TD->prev_Q_bwe_syn, st_fx->total_brate, 0 );