diff --git a/lib_com/core_com_config.c b/lib_com/core_com_config.c index a3af3148735d5a4217e917fa9c8fdf64f23e167b..77f904055bb148de8d127a0a057ae1ad70a8ddef 100644 --- a/lib_com/core_com_config.c +++ b/lib_com/core_com_config.c @@ -808,6 +808,7 @@ float getTcxBandwidth_flt( return tcxBandwidth; } +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * getIgfPresent() * @@ -905,7 +906,7 @@ int16_t getIgfPresent( return igfPresent; } - +#else Word16 getIgfPresent_fx( const Word16 element_mode, /* i : IVAS element mode */ const Word32 total_brate, /* i : total bitrate */ @@ -1009,6 +1010,8 @@ Word16 getIgfPresent_fx( return igfPresent; } +#endif + /*-------------------------------------------------------------------* * getCnaPresent() * diff --git a/lib_com/ivas_cnst.h b/lib_com/ivas_cnst.h index 36d75a7c828a70d8289a605bb68b51ca557644c9..5fef6581695d157454575cc93298568726f9aca1 100644 --- a/lib_com/ivas_cnst.h +++ b/lib_com/ivas_cnst.h @@ -1263,7 +1263,7 @@ enum #endif #define BITS_MASA2TOTTAL_DCT0 6 #define STEP_M2T 0.1f -#define STEP_M2T_FX 214748364 +#define STEP_M2T_FX 214748365 #define MASA_HEADER_BITS 2 #define MASA_SUBFRAME_BITS 1 #define MASA_LOWBITRATE_MODE_BITS 1 @@ -1648,6 +1648,13 @@ typedef enum #define LFE_PLC_LENANA LFE_PLC_BUFLEN #define LFE_PLC_FDEL 300 +/*----------------------------------------------------------------------------------* + * HO Dirac Constants + *----------------------------------------------------------------------------------*/ +#define HODIRAC_BETA (214748368) /* 0.2f in Q30 */ +#define HODIRAC_FAC1 (951579008) /* 1.772454f in Q29 */ +#define HODIRAC_FAC2 (549393984) /* 1.023326f in Q29 */ +#define HODIRAC_FAC3 (317192992) /* 0.590818f in Q29 */ /*----------------------------------------------------------------------------------* * Amplitude Panning (EFAP, VBAP) constants diff --git a/lib_com/ivas_dirac_com.c b/lib_com/ivas_dirac_com.c index b775d8ccf134cf6a08f64b4ff5f775aaa77f22f3..01a6d4828d28898d691277a4ee28dc2e8f664802 100644 --- a/lib_com/ivas_dirac_com.c +++ b/lib_com/ivas_dirac_com.c @@ -1787,6 +1787,377 @@ void deindex_spherical_component_fx( * *-----------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void calculate_hodirac_sector_parameters_fx( + DIRAC_ENC_HANDLE hDirAC, /* i : DirAC handle */ + Word32 RealBuffer_fx[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], /* i : signal vector (L+1)^2 x N_bins, real part */ + Word32 ImagBuffer_fx[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], /* i : signal vector, imaginary part */ + Word16 Qfac, /* i : Q-factor of signal vector */ + const Word32 beta_fx, /* i : forgetting factor for average filtering, Q30 */ + const Word16 *band_grouping, /* i : indices of band groups */ + const Word16 N_bands, /* i : number of bands (groups) */ + const Word16 enc_param_start_band, /* i : first band to process */ + Word32 *azi_fx, /* o : array of sector azimuth angles, flat, Q23 */ + Word32 *ele_fx, /* o : array of sector elevation angles, flat, Q23 */ + Word32 *diff_fx, /* o : array of sector diffuseness values, flat */ + Word16 *diff_exp, /* o : array of sector diffuseness exponents, flat */ + Word32 *ene_fx, /* o : array of sector energy values, flat */ + Word16 *ene_exp /* o : array of sector energy exponents, flat */ +) +{ + Word16 i_sec, i_bin, i_band; + Word32 p_real_fx, p_imag_fx, normI_fx, energy_fx, tmp_diff_fx; + Word16 energy_exp, normI_exp, tmp_diff_exp; + + Word32 sec_I_vec_x_fx[NUM_ANA_SECTORS]; + Word32 sec_I_vec_y_fx[NUM_ANA_SECTORS]; + Word32 sec_I_vec_z_fx[NUM_ANA_SECTORS]; + Word16 sec_I_vec_x_exp[NUM_ANA_SECTORS]; + Word16 sec_I_vec_y_exp[NUM_ANA_SECTORS]; + Word16 sec_I_vec_z_exp[NUM_ANA_SECTORS]; + + FOR( i_sec = 0; i_sec < NUM_ANA_SECTORS; i_sec++ ) + { + Word32 *p_sec_I_vec_x_fx = &sec_I_vec_x_fx[i_sec]; + Word32 *p_sec_I_vec_y_fx = &sec_I_vec_y_fx[i_sec]; + Word32 *p_sec_I_vec_z_fx = &sec_I_vec_z_fx[i_sec]; + Word16 *p_sec_I_vec_x_exp = &sec_I_vec_x_exp[i_sec]; + Word16 *p_sec_I_vec_y_exp = &sec_I_vec_y_exp[i_sec]; + Word16 *p_sec_I_vec_z_exp = &sec_I_vec_z_exp[i_sec]; + + const Word32 *p_c_weights_fx = c_weights_fx; // Q30 + + Word32 *p_ImagBuffer_0_fx = ImagBuffer_fx[0]; + Word32 *p_ImagBuffer_1_fx = ImagBuffer_fx[1]; + Word32 *p_ImagBuffer_2_fx = ImagBuffer_fx[2]; + Word32 *p_ImagBuffer_3_fx = ImagBuffer_fx[3]; + Word32 *p_ImagBuffer_4_fx = ImagBuffer_fx[4]; + Word32 *p_ImagBuffer_5_fx = ImagBuffer_fx[5]; + Word32 *p_ImagBuffer_6_fx = ImagBuffer_fx[6]; + Word32 *p_ImagBuffer_8_fx = ImagBuffer_fx[8]; + + Word32 *p_RealBuffer_0_fx = RealBuffer_fx[0]; + Word32 *p_RealBuffer_1_fx = RealBuffer_fx[1]; + Word32 *p_RealBuffer_2_fx = RealBuffer_fx[2]; + Word32 *p_RealBuffer_3_fx = RealBuffer_fx[3]; + Word32 *p_RealBuffer_4_fx = RealBuffer_fx[4]; + Word32 *p_RealBuffer_5_fx = RealBuffer_fx[5]; + Word32 *p_RealBuffer_6_fx = RealBuffer_fx[6]; + Word32 *p_RealBuffer_8_fx = RealBuffer_fx[8]; + + FOR( i_band = enc_param_start_band; i_band < N_bands; i_band++ ) + { + Word32 *p_azi_fx = &azi_fx[i_sec * N_bands + i_band]; + Word32 *p_ele_fx = &ele_fx[i_sec * N_bands + i_band]; + Word32 *p_ene_fx = &ene_fx[i_sec * N_bands + i_band]; + Word16 *p_ene_exp = &ene_exp[i_sec * N_bands + i_band]; + + Word32 *p_diff_fx = &diff_fx[i_sec * N_bands + i_band]; + Word16 *p_diff_exp = &diff_exp[i_sec * N_bands + i_band]; + Word32 *p_azi_prev_fx = &hDirAC->azi_prev_fx[i_sec * N_bands + i_band]; + Word32 *p_ele_prev_fx = &hDirAC->ele_prev_fx[i_sec * N_bands + i_band]; + + Word32 *p_energy_smth_fx = &hDirAC->energy_smth_fx[i_sec][i_band]; + Word16 *p_energy_smth_exp = &hDirAC->energy_smth_exp[i_sec][i_band]; + Word32 *p_sec_I_vec_smth_x_fx = &hDirAC->sec_I_vec_smth_x_fx[i_sec][i_band]; + Word32 *p_sec_I_vec_smth_y_fx = &hDirAC->sec_I_vec_smth_y_fx[i_sec][i_band]; + Word32 *p_sec_I_vec_smth_z_fx = &hDirAC->sec_I_vec_smth_z_fx[i_sec][i_band]; + Word16 *p_sec_I_vec_smth_x_exp = &hDirAC->sec_I_vec_smth_x_exp[i_sec][i_band]; + Word16 *p_sec_I_vec_smth_y_exp = &hDirAC->sec_I_vec_smth_y_exp[i_sec][i_band]; + Word16 *p_sec_I_vec_smth_z_exp = &hDirAC->sec_I_vec_smth_z_exp[i_sec][i_band]; + *p_sec_I_vec_x_fx = 0; + move32(); + *p_sec_I_vec_x_exp = 0; + move16(); + *p_sec_I_vec_y_fx = 0; + move32(); + *p_sec_I_vec_y_exp = 0; + move16(); + *p_sec_I_vec_z_fx = 0; + move32(); + *p_sec_I_vec_z_exp = 0; + move16(); + energy_fx = 0; + move32(); + energy_exp = 0; + move16(); + + IF( i_sec == 0 ) + { + FOR( i_bin = band_grouping[i_band]; i_bin < band_grouping[i_band + 1]; i_bin++ ) + { + Word32 w_fx = *( p_c_weights_fx++ ); // Q30 + move32(); + Word32 sec_w_imag_fx, sec_x_imag_fx, sec_y_imag_fx, sec_z_imag_fx; + Word32 sec_w_real_fx, sec_x_real_fx, sec_y_real_fx, sec_z_real_fx; + + sec_w_imag_fx = L_add( Mpy_32_32( HODIRAC_FAC1, *( p_ImagBuffer_0_fx ) ), Mpy_32_32( HODIRAC_FAC1, *( p_ImagBuffer_1_fx ) ) ); // Qfac - 2 + sec_x_imag_fx = L_add( Mpy_32_32( HODIRAC_FAC1, *( p_ImagBuffer_3_fx++ ) ), Mpy_32_32( HODIRAC_FAC2, *( p_ImagBuffer_4_fx++ ) ) ); // Qfac - 2 + sec_y_imag_fx = L_sub( L_sub( L_add( Mpy_32_32( HODIRAC_FAC3, *( p_ImagBuffer_0_fx++ ) ), Mpy_32_32( HODIRAC_FAC1, *( p_ImagBuffer_1_fx++ ) ) ), Mpy_32_32( HODIRAC_FAC3, *( p_ImagBuffer_6_fx++ ) ) ), Mpy_32_32( HODIRAC_FAC2, *( p_ImagBuffer_8_fx++ ) ) ); // Qfac - 2 + sec_z_imag_fx = L_add( Mpy_32_32( HODIRAC_FAC1, *( p_ImagBuffer_2_fx++ ) ), Mpy_32_32( HODIRAC_FAC2, *( p_ImagBuffer_5_fx++ ) ) ); // Qfac - 2 + + sec_w_real_fx = L_add( Mpy_32_32( HODIRAC_FAC1, *( p_RealBuffer_0_fx ) ), Mpy_32_32( HODIRAC_FAC1, *( p_RealBuffer_1_fx ) ) ); // Qfac - 2 + sec_x_real_fx = L_add( Mpy_32_32( HODIRAC_FAC1, *( p_RealBuffer_3_fx++ ) ), Mpy_32_32( HODIRAC_FAC2, *( p_RealBuffer_4_fx++ ) ) ); // Qfac - 2 + sec_y_real_fx = L_sub( L_sub( L_add( Mpy_32_32( HODIRAC_FAC3, *( p_RealBuffer_0_fx++ ) ), Mpy_32_32( HODIRAC_FAC1, *( p_RealBuffer_1_fx++ ) ) ), Mpy_32_32( HODIRAC_FAC3, *( p_RealBuffer_6_fx++ ) ) ), Mpy_32_32( HODIRAC_FAC2, *( p_RealBuffer_8_fx++ ) ) ); // Qfac - 2 + sec_z_real_fx = L_add( Mpy_32_32( HODIRAC_FAC1, *( p_RealBuffer_2_fx++ ) ), Mpy_32_32( HODIRAC_FAC2, *( p_RealBuffer_5_fx++ ) ) ); // Qfac - 2 + + Word16 p_q; + Word32 tmp_x, tmp_y, tmp_z; + Word16 n, n1, n2; + + p_real_fx = Mpy_32_32( sec_w_real_fx, w_fx ); // ( Qfac - 2 ) + 30 - 31 = Qfac - 3 + p_imag_fx = Mpy_32_32( sec_w_imag_fx, w_fx ); // ( Qfac - 2 ) + 30 - 31 = Qfac - 3 + + n1 = norm_l( p_real_fx ); + n2 = norm_l( p_imag_fx ); + + n = s_min( n1, n2 ); + p_real_fx = L_shl( p_real_fx, n ); + p_imag_fx = L_shl( p_imag_fx, n ); + + p_q = add( sub( Qfac, 3 ), n ); + + Word16 tmp_exp, sec_sum_exp; + tmp_exp = sub( 66, add( p_q, Qfac ) ); // 31 - ( p_q + Qfac - 35 ) + + tmp_x = L_add( L_shr( Mpy_32_32( p_real_fx, sec_x_real_fx ), 2 ), L_shr( Mpy_32_32( p_imag_fx, sec_x_imag_fx ), 2 ) ); // p_q + ( Qfac - 2 ) - 31 - 2 = p_q + Qfac - 35 + tmp_y = L_add( L_shr( Mpy_32_32( p_real_fx, sec_y_real_fx ), 2 ), L_shr( Mpy_32_32( p_imag_fx, sec_y_imag_fx ), 2 ) ); // p_q + ( Qfac - 2 ) - 31 - 2 = p_q + Qfac - 35 + tmp_z = L_add( L_shr( Mpy_32_32( p_real_fx, sec_z_real_fx ), 2 ), L_shr( Mpy_32_32( p_imag_fx, sec_z_imag_fx ), 2 ) ); // p_q + ( Qfac - 2 ) - 31 - 2 = p_q + Qfac - 35 + + *p_sec_I_vec_x_fx = BASOP_Util_Add_Mant32Exp( *p_sec_I_vec_x_fx, *p_sec_I_vec_x_exp, tmp_x, tmp_exp, p_sec_I_vec_x_exp ); + move32(); + *p_sec_I_vec_y_fx = BASOP_Util_Add_Mant32Exp( *p_sec_I_vec_y_fx, *p_sec_I_vec_y_exp, tmp_y, tmp_exp, p_sec_I_vec_y_exp ); + move32(); + *p_sec_I_vec_z_fx = BASOP_Util_Add_Mant32Exp( *p_sec_I_vec_z_fx, *p_sec_I_vec_z_exp, tmp_z, tmp_exp, p_sec_I_vec_z_exp ); + move32(); + + Word32 tmp1; + Word64 tmp2, tmp3, tmp4, sec_sum64; + Word32 tmp5, sec_sum; + tmp_exp = sub( 62, add( p_q, p_q ) ); + + tmp1 = BASOP_Util_Add_Mant32Exp( Mpy_32_32( p_real_fx, p_real_fx ), tmp_exp, Mpy_32_32( p_imag_fx, p_imag_fx ), tmp_exp, &tmp_exp ); + tmp2 = W_add( W_mult0_32_32( sec_x_real_fx, sec_x_real_fx ), W_mult0_32_32( sec_x_imag_fx, sec_x_imag_fx ) ); // 2 * (Qfac - 2) + tmp3 = W_add( W_mult0_32_32( sec_y_real_fx, sec_y_real_fx ), W_mult0_32_32( sec_y_imag_fx, sec_y_imag_fx ) ); // 2 * (Qfac - 2) + tmp4 = W_add( W_mult0_32_32( sec_z_real_fx, sec_z_real_fx ), W_mult0_32_32( sec_z_imag_fx, sec_z_imag_fx ) ); // 2 * (Qfac - 2) + sec_sum64 = W_add( W_add( tmp2, tmp3 ), tmp4 ); // 2 * (Qfac - 2) + n = W_norm( sec_sum64 ); + sec_sum64 = W_shl( sec_sum64, n ); // 2 * (Qfac - 2) + n + sec_sum = W_extract_h( sec_sum64 ); // 2 * (Qfac - 2) + n - 32 = 2 * Qfac + n - 36 + sec_sum_exp = sub( 67, add( shl( Qfac, 1 ), n ) ); + + // divide by 2: + tmp1 = L_shr( tmp1, 1 ); + sec_sum = L_shr( sec_sum, 1 ); + + tmp5 = BASOP_Util_Add_Mant32Exp( tmp1, tmp_exp, sec_sum, sec_sum_exp, &tmp_exp ); + energy_fx = BASOP_Util_Add_Mant32Exp( energy_fx, energy_exp, tmp5, tmp_exp, &energy_exp ); + } + } + ELSE + { + FOR( i_bin = band_grouping[i_band]; i_bin < band_grouping[i_band + 1]; i_bin++ ) + { + Word32 w_fx = *( p_c_weights_fx++ ); // Q30 + move32(); + Word32 sec_w_imag_fx, sec_x_imag_fx, sec_y_imag_fx, sec_z_imag_fx; + Word32 sec_w_real_fx, sec_x_real_fx, sec_y_real_fx, sec_z_real_fx; + + sec_w_imag_fx = L_sub( Mpy_32_32( HODIRAC_FAC1, *( p_ImagBuffer_0_fx ) ), Mpy_32_32( HODIRAC_FAC1, *( p_ImagBuffer_1_fx ) ) ); // Qfac - 2 + sec_x_imag_fx = L_sub( Mpy_32_32( HODIRAC_FAC1, *( p_ImagBuffer_3_fx++ ) ), Mpy_32_32( HODIRAC_FAC2, *( p_ImagBuffer_4_fx++ ) ) ); // Qfac - 2 + sec_y_imag_fx = L_add( L_add( L_add( Mpy_32_32( -HODIRAC_FAC3, *( p_ImagBuffer_0_fx++ ) ), Mpy_32_32( HODIRAC_FAC1, *( p_ImagBuffer_1_fx++ ) ) ), Mpy_32_32( HODIRAC_FAC3, *( p_ImagBuffer_6_fx++ ) ) ), Mpy_32_32( HODIRAC_FAC2, *( p_ImagBuffer_8_fx++ ) ) ); // Qfac - 2 + sec_z_imag_fx = L_sub( Mpy_32_32( HODIRAC_FAC1, *( p_ImagBuffer_2_fx++ ) ), Mpy_32_32( HODIRAC_FAC2, *( p_ImagBuffer_5_fx++ ) ) ); // Qfac - 2 + + sec_w_real_fx = L_sub( Mpy_32_32( HODIRAC_FAC1, *( p_RealBuffer_0_fx ) ), Mpy_32_32( HODIRAC_FAC1, *( p_RealBuffer_1_fx ) ) ); // Qfac - 2 + sec_x_real_fx = L_sub( Mpy_32_32( HODIRAC_FAC1, *( p_RealBuffer_3_fx++ ) ), Mpy_32_32( HODIRAC_FAC2, *( p_RealBuffer_4_fx++ ) ) ); // Qfac - 2 + sec_y_real_fx = L_add( L_add( L_add( Mpy_32_32( -HODIRAC_FAC3, *( p_RealBuffer_0_fx++ ) ), Mpy_32_32( HODIRAC_FAC1, *( p_RealBuffer_1_fx++ ) ) ), Mpy_32_32( HODIRAC_FAC3, *( p_RealBuffer_6_fx++ ) ) ), Mpy_32_32( HODIRAC_FAC2, *( p_RealBuffer_8_fx++ ) ) ); // Qfac - 2 + sec_z_real_fx = L_sub( Mpy_32_32( HODIRAC_FAC1, *( p_RealBuffer_2_fx++ ) ), Mpy_32_32( HODIRAC_FAC2, *( p_RealBuffer_5_fx++ ) ) ); // Qfac - 2 + + Word16 p_q; + + p_real_fx = Mpy_32_32( sec_w_real_fx, w_fx ); // ( Qfac - 2 ) + 30 - 31 = Qfac - 3 + p_imag_fx = Mpy_32_32( sec_w_imag_fx, w_fx ); // ( Qfac - 2 ) + 30 - 31 = Qfac - 3 + + Word32 tmp_x, tmp_y, tmp_z; + Word16 n, n1, n2; + + n1 = norm_l( p_real_fx ); + n2 = norm_l( p_imag_fx ); + + n = s_min( n1, n2 ); + + p_real_fx = L_shl( p_real_fx, n ); + p_imag_fx = L_shl( p_imag_fx, n ); + + p_q = add( sub( Qfac, 3 ), n ); + + Word16 tmp_exp, sec_sum_exp; + tmp_exp = sub( 66, add( p_q, Qfac ) ); // 31 - ( p_q + Qfac - 35 ) + + tmp_x = L_add( L_shr( Mpy_32_32( p_real_fx, sec_x_real_fx ), 2 ), L_shr( Mpy_32_32( p_imag_fx, sec_x_imag_fx ), 2 ) ); // p_q + ( Qfac - 2 ) - 31 - 2 = p_q + Qfac - 35 + tmp_y = L_add( L_shr( Mpy_32_32( p_real_fx, sec_y_real_fx ), 2 ), L_shr( Mpy_32_32( p_imag_fx, sec_y_imag_fx ), 2 ) ); // p_q + ( Qfac - 2 ) - 31 - 2 = p_q + Qfac - 35 + tmp_z = L_add( L_shr( Mpy_32_32( p_real_fx, sec_z_real_fx ), 2 ), L_shr( Mpy_32_32( p_imag_fx, sec_z_imag_fx ), 2 ) ); // p_q + ( Qfac - 2 ) - 31 - 2 = p_q + Qfac - 35 + *p_sec_I_vec_x_fx = BASOP_Util_Add_Mant32Exp( *p_sec_I_vec_x_fx, *p_sec_I_vec_x_exp, tmp_x, tmp_exp, p_sec_I_vec_x_exp ); + move32(); + *p_sec_I_vec_y_fx = BASOP_Util_Add_Mant32Exp( *p_sec_I_vec_y_fx, *p_sec_I_vec_y_exp, tmp_y, tmp_exp, p_sec_I_vec_y_exp ); + move32(); + *p_sec_I_vec_z_fx = BASOP_Util_Add_Mant32Exp( *p_sec_I_vec_z_fx, *p_sec_I_vec_z_exp, tmp_z, tmp_exp, p_sec_I_vec_z_exp ); + move32(); + + Word32 tmp1; + Word64 tmp2, tmp3, tmp4, sec_sum64; + Word32 tmp5, sec_sum; + tmp_exp = sub( 62, add( p_q, p_q ) ); + + tmp1 = BASOP_Util_Add_Mant32Exp( Mpy_32_32( p_real_fx, p_real_fx ), tmp_exp, Mpy_32_32( p_imag_fx, p_imag_fx ), tmp_exp, &tmp_exp ); + tmp2 = W_add( W_mult0_32_32( sec_x_real_fx, sec_x_real_fx ), W_mult0_32_32( sec_x_imag_fx, sec_x_imag_fx ) ); // 2 * (Qfac - 2) + tmp3 = W_add( W_mult0_32_32( sec_y_real_fx, sec_y_real_fx ), W_mult0_32_32( sec_y_imag_fx, sec_y_imag_fx ) ); // 2 * (Qfac - 2) + tmp4 = W_add( W_mult0_32_32( sec_z_real_fx, sec_z_real_fx ), W_mult0_32_32( sec_z_imag_fx, sec_z_imag_fx ) ); // 2 * (Qfac - 2) + sec_sum64 = W_add( W_add( tmp2, tmp3 ), tmp4 ); // 2 * (Qfac - 2) + n = W_norm( sec_sum64 ); + sec_sum64 = W_shl( sec_sum64, n ); // 2 * (Qfac - 2) + n + sec_sum = W_extract_h( sec_sum64 ); // 2 * (Qfac - 2) + n - 32 = 2 * Qfac + n - 36 + sec_sum_exp = sub( 67, add( shl( Qfac, 1 ), n ) ); + + // divide by 2: + tmp1 = L_shr( tmp1, 1 ); + sec_sum = L_shr( sec_sum, 1 ); + + tmp5 = BASOP_Util_Add_Mant32Exp( tmp1, tmp_exp, sec_sum, sec_sum_exp, &tmp_exp ); + energy_fx = BASOP_Util_Add_Mant32Exp( energy_fx, energy_exp, tmp5, tmp_exp, &energy_exp ); + } + } + + IF( hDirAC->firstrun_sector_params ) + { + *p_sec_I_vec_smth_x_fx = *p_sec_I_vec_x_fx; + move32(); + *p_sec_I_vec_smth_y_fx = *p_sec_I_vec_y_fx; + move32(); + *p_sec_I_vec_smth_z_fx = *p_sec_I_vec_z_fx; + move32(); + *p_energy_smth_fx = energy_fx; + move32(); + *p_sec_I_vec_smth_x_exp = *p_sec_I_vec_x_exp; + move16(); + *p_sec_I_vec_smth_y_exp = *p_sec_I_vec_y_exp; + move16(); + *p_sec_I_vec_smth_z_exp = *p_sec_I_vec_z_exp; + move16(); + *p_energy_smth_exp = energy_exp; + move16(); + } + ELSE + { + Word32 w_fx = L_sub( ONE_IN_Q30, beta_fx ); // Q30 + + *p_sec_I_vec_smth_x_fx = BASOP_Util_Add_Mant32Exp( Mpy_32_32( w_fx, *p_sec_I_vec_x_fx ), add( *p_sec_I_vec_x_exp, 1 ), Mpy_32_32( beta_fx, *p_sec_I_vec_smth_x_fx ), add( *p_sec_I_vec_smth_x_exp, 1 ), p_sec_I_vec_smth_x_exp ); + move32(); + *p_sec_I_vec_smth_y_fx = BASOP_Util_Add_Mant32Exp( Mpy_32_32( w_fx, *p_sec_I_vec_y_fx ), add( *p_sec_I_vec_y_exp, 1 ), Mpy_32_32( beta_fx, *p_sec_I_vec_smth_y_fx ), add( *p_sec_I_vec_smth_y_exp, 1 ), p_sec_I_vec_smth_y_exp ); + move32(); + *p_sec_I_vec_smth_z_fx = BASOP_Util_Add_Mant32Exp( Mpy_32_32( w_fx, *p_sec_I_vec_z_fx ), add( *p_sec_I_vec_z_exp, 1 ), Mpy_32_32( beta_fx, *p_sec_I_vec_smth_z_fx ), add( *p_sec_I_vec_smth_z_exp, 1 ), p_sec_I_vec_smth_z_exp ); + move32(); + *p_energy_smth_fx = BASOP_Util_Add_Mant32Exp( Mpy_32_32( w_fx, energy_fx ), add( energy_exp, 1 ), Mpy_32_32( beta_fx, *p_energy_smth_fx ), add( *p_energy_smth_exp, 1 ), p_energy_smth_exp ); + } + + IF( LT_32( energy_fx, EPSILON_FX_SMALL ) ) + { + *p_azi_fx = 0; + move32(); + *p_ele_fx = 0; + move32(); + *p_ene_fx = 0; + move32(); + *p_ene_exp = 0; + move16(); + *p_diff_fx = ONE_IN_Q30; + move32(); + *p_diff_exp = 1; + move16(); + } + ELSE + { + Word32 tmp_x, tmp_y, tmp_z, tmp_xy_hypo, tmp32; + Word16 tmp16, tmp_e; + tmp_x = Mpy_32_32( *p_sec_I_vec_smth_x_fx, *p_sec_I_vec_smth_x_fx ); + tmp_y = Mpy_32_32( *p_sec_I_vec_smth_y_fx, *p_sec_I_vec_smth_y_fx ); + tmp_z = Mpy_32_32( *p_sec_I_vec_smth_z_fx, *p_sec_I_vec_smth_z_fx ); + tmp32 = BASOP_Util_Add_Mant32Exp( tmp_x, shl( *p_sec_I_vec_smth_x_exp, 1 ), tmp_y, shl( *p_sec_I_vec_smth_y_exp, 1 ), &tmp_e ); + normI_fx = BASOP_Util_Add_Mant32Exp( tmp32, tmp_e, tmp_z, shl( *p_sec_I_vec_smth_z_exp, 1 ), &normI_exp ); + normI_fx = Sqrt32( normI_fx, &normI_exp ); + + tmp_xy_hypo = Sqrt32( tmp32, &tmp_e ); // sqrt(x^2 + y^2) + + tmp16 = BASOP_util_atan2( *p_sec_I_vec_smth_y_fx, *p_sec_I_vec_smth_x_fx, sub( *p_sec_I_vec_smth_y_exp, *p_sec_I_vec_smth_x_exp ) ); // Q13 + *p_azi_fx = Mpy_32_32( L_deposit_h( tmp16 ), _180_OVER_PI_Q25 ); // (Q13 + 16) + Q25 - 31 = 54 - 31 = Q23 + tmp16 = BASOP_util_atan2( *p_sec_I_vec_smth_z_fx, tmp_xy_hypo, sub( *p_sec_I_vec_smth_z_exp, tmp_e ) ); // Q13 + *p_ele_fx = Mpy_32_32( L_deposit_h( tmp16 ), _180_OVER_PI_Q25 ); // (Q13 + 16) + Q25 - 31 = 54 - 31 = Q23 + *p_ene_fx = *p_energy_smth_fx; + move32(); + *p_ene_exp = *p_energy_smth_exp; + move16(); + + tmp32 = L_deposit_h( BASOP_Util_Divide3232_Scale( normI_fx, *p_energy_smth_fx, &tmp_e ) ); + tmp_e = add( tmp_e, sub( normI_exp, *p_energy_smth_exp ) ); + tmp32 = BASOP_Util_Add_Mant32Exp( ONE_IN_Q30, 1, L_negate( tmp32 ), tmp_e, &tmp_e ); + *p_diff_fx = tmp32; + move32(); + *p_diff_exp = tmp_e; + move16(); + } + + tmp_diff_fx = *p_diff_fx; + move32(); + tmp_diff_exp = *p_diff_exp; + move16(); + // NOTE: here, assuming abs(tmp_diff) <= 1.0. --> Q30 + tmp_diff_fx = L_shr( tmp_diff_fx, sub( 1, tmp_diff_exp ) ); + tmp_diff_exp = 1; + move16(); + + IF( tmp_diff_fx < 0 ) + { + *p_diff_fx = 0; + move32(); + } + IF( GT_32( tmp_diff_fx, ( ONE_IN_Q30 / 2 ) ) ) + { + IF( hDirAC->firstrun_sector_params ) + { + *p_azi_fx = 0; + move32(); + *p_ele_fx = 0; + move32(); + } + ELSE + { + *p_azi_fx = L_shl( L_add( Mpy_32_32( L_sub( ONE_IN_Q30, tmp_diff_fx ), *p_azi_fx ), Mpy_32_32( L_sub( tmp_diff_fx, ONE_IN_Q30 / 2 ), *p_azi_prev_fx ) ), 1 ); // Q30 + Q23 - 31 = Q22 + move32(); + *p_ele_fx = L_shl( L_add( Mpy_32_32( L_sub( ONE_IN_Q30, tmp_diff_fx ), *p_ele_fx ), Mpy_32_32( L_sub( tmp_diff_fx, ONE_IN_Q30 / 2 ), *p_ele_prev_fx ) ), 1 ); // Q30 + Q23 - 31 = Q22 + move32(); + *p_azi_fx = L_shl( *p_azi_fx, 1 ); // Q22 -> Q23; + move32(); + *p_ele_fx = L_shl( *p_ele_fx, 1 ); // Q22 -> Q23; + move32(); + } + } + ELSE + { + *p_azi_prev_fx = *p_azi_fx; + move32(); + *p_ele_prev_fx = *p_ele_fx; + move32(); + } + } + } + + hDirAC->firstrun_sector_params = 0; + move16(); + + return; +} +#endif + void calculate_hodirac_sector_parameters( DIRAC_ENC_HANDLE hDirAC, /* i : DirAC handle */ float RealBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], /* i : signal vector (L+1)^2 x N_bins, real part */ diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 6005aa67c6054ea54dd31477e523c957f5cdaf95..cbd4b6ce991a039bf71f0115380d20cb1606bcf2 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -70,9 +70,11 @@ void stereo_dmx_evs_enc( ); /*! r: number of channels to be analysed */ +#ifndef IVAS_FLOAT_FIXED int16_t getNumChanAnalysis( Encoder_Struct *st_ivas /* i : IVAS encoder structure */ ); +#endif void copy_encoder_config( Encoder_Struct *st_ivas, /* i : IVAS encoder structure */ @@ -2318,7 +2320,7 @@ int16_t stereo_dft_band_config( const int16_t NFFT, /* i : analysis/synthesis window length */ const int16_t enc_dec /* i : flag to indicate enc vs dec */ ); - +#ifndef IVAS_FLOAT_FIXED void stereo_td_itd( ITD_DATA *hITD, /* i/o: ITD data structure */ float input_mem_itd[CPE_CHANNELS][STEREO_DFT_OVL_MAX], /* o : ITD memory (only used in DFT Stereo) */ @@ -2328,6 +2330,7 @@ void stereo_td_itd( const int16_t input_frame, /* i : input frame length */ float *input_mem[CPE_CHANNELS] /* i/o: input buffer memory */ ); +#endif void stereo_dft_dmx_out_reset( STEREO_DFT_DMX_DATA_HANDLE hStereoDftDmx /* i/o: DFT stereo DMX decoder */ @@ -2537,9 +2540,9 @@ void stereo_tca_dec( ); void stereo_tca_dec_fx( - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - Word32 *synth[CPE_CHANNELS], /* i/o: output synth */ - const Word16 output_frame /* i : length of a frame per channel */ + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + Word32 *synth[CPE_CHANNELS], /* i/o: output synth qsynth*/ + const Word16 output_frame /* i : length of a frame per channel Q0*/ ); void stereo_tca_scale_R_channel( @@ -2549,9 +2552,9 @@ void stereo_tca_scale_R_channel( ); void stereo_tca_scale_R_channel_fx( - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - Word32 *output_fx, /* i/o: output synthesis, R channel */ - const Word16 output_frame /* i : frame length */ + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + Word32 *output_fx, /* i/o: output synthesis, R channel q_out*/ + const Word16 output_frame /* i : frame length Q0*/ ); void adjustTargetSignal( @@ -2633,13 +2636,15 @@ int16_t select_stereo_mode( const IVAS_FORMAT ivas_format /* i : IVAS format */ ); +#ifndef IVAS_FLOAT_FIXED void stereo_classifier_init( STEREO_CLASSIF_HANDLE hStereoClassif /* i/o: stereo classifier structure */ ); - +#else void stereo_classifier_init_fx( STEREO_CLASSIF_HANDLE hStereoClassif /* i/o: stereo classifier structure */ ); +#endif void stereo_classifier_features( STEREO_CLASSIF_HANDLE hStereoClassif, /* i/o: stereo classifier structure */ @@ -2888,6 +2893,7 @@ void tdm_bit_alloc( const int16_t tdm_inst_ratio_idx /* i : instantaneous correlation ratio index */ ); +#ifndef IVAS_FLOAT_FIXED void td_stereo_param_updt( const float lsp_old_PCh[], /* i : primary channel old LSPs */ const float lsf_old_PCh[], /* i : primary channel old LSFs */ @@ -2898,6 +2904,7 @@ void td_stereo_param_updt( const int16_t flag_ACELP16k, /* i : ACELP@16kHz flag */ const int16_t tdm_use_IAWB_Ave_lpc /* i : flag to indicate the usage of mean inactive LP coefficients */ ); +#endif void gsc_enc( Encoder_State *st, /* i/o: State structure */ @@ -2998,19 +3005,7 @@ void tdm_SCh_lsf_reuse_fx( const Word16 lsf_wgts_fx[M], /* i : LSF weights */ Word16 *beta_index /* i/o: quantization index */ ); -#endif - - -void tdm_SCh_lsf_reuse_ivas_fx( - const Word16 enc_dec, /* i : encoder/decoder flag */ - const Word32 element_brate, /* i : element bitrate */ - Word16 lsf_new[M], /* i/o: LSFs at the end of the frame */ - Word16 lsp_new[M], /* i/o: LSPs at the end of the frame */ - const Word16 tdm_lsfQ_PCh[M], /* i : primary channel LSFs (log2(2.56)) */ - const Word16 lsf_wgts[M], /* i : LSF weights Q15? */ - Word16 *beta_index /* i/o: quantization index */ -); - +#else void tdm_SCh_lsf_reuse( const int16_t enc_dec, /* i : encoder/decoder flag */ const int32_t element_brate, /* i : element bitrate */ @@ -3020,6 +3015,7 @@ void tdm_SCh_lsf_reuse( const float lsf_wgts[M], /* i : LSF weights */ int16_t *beta_index /* i/o: quantization index */ ); +#endif void first_VQstages( const float *const *cb, @@ -5141,6 +5137,26 @@ void ivas_dirac_dec_get_response_fx( Word16 Q_out); #endif + +#ifdef IVAS_FLOAT_FIXED +void calculate_hodirac_sector_parameters_fx( + DIRAC_ENC_HANDLE hDirAC, /* i : DirAC handle */ + Word32 RealBuffer_fx[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], /* i : signal vector (L+1)^2 x N_bins, real part */ + Word32 ImagBuffer_fx[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], /* i : signal vector, imaginary part */ + Word16 Qfac, /* i : Q-factor of signal vector */ + const Word32 beta_fx, /* i : forgetting factor for average filtering, Q30 */ + const Word16 *band_grouping, /* i : indices of band groups */ + const Word16 N_bands, /* i : number of bands (groups) */ + const Word16 enc_param_start_band, /* i : first band to process */ + Word32 *azi_fx, /* o : array of sector azimuth angles, flat Q23 */ + Word32 *ele_fx, /* o : array of sector elevation angles, flat Q23 */ + Word32 *diff_fx, /* o : array of sector diffuseness values, flat */ + Word16 *diff_exp, /* o : array of sector diffuseness exponents, flat */ + Word32 *ene_fx, /* o : array of sector energy values, flat */ + Word16 *ene_exp /* o : array of sector energy exponents, flat */ +); +#endif + void calculate_hodirac_sector_parameters( DIRAC_ENC_HANDLE hDirAC, float RealBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX],/* i : signal vector (L+1)^2 x N_bins, real part */ diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index 5f13befaa59d5f95dc8ec3ee90e30f3115e278cf..72f26cd92b76b7add33fe88bf5bbf75ec6e27c94 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -3461,4 +3461,10 @@ void stereo_dmx_evs_close_encoder_fx( STEREO_DMX_EVS_ENC_HANDLE *hStereoDmxEVS /* i/o: Stereo downmix for EVS encoder handle */ ); +void ivas_omasa_encode_masa_to_total_fx( + Word32 masa_to_total_energy_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* Q30 */ + BSTR_ENC_HANDLE hMetaData, + const Word16 low_bitrate_mode, + const Word16 nbands, + const Word16 nblocks ); #endif diff --git a/lib_com/ivas_rom_com.c b/lib_com/ivas_rom_com.c index 4b9d3984237cb96c900c7ccfde32eaf50212c571..9f08e3dfe16148821e3f94a9f8c079400b9df52f 100644 --- a/lib_com/ivas_rom_com.c +++ b/lib_com/ivas_rom_com.c @@ -1041,6 +1041,9 @@ const int16_t DirAC_block_grouping_5ms_MDFT[MAX_PARAM_SPATIAL_SUBFRAMES + 1] = 0, 1, 2, 3, 4 }; +#ifdef IVAS_FLOAT_FIXED +const Word32 c_weights_fx[DIRAC_NO_FB_BANDS_MAX] /* Q30 */ = { 106970960, 1033798336, 1065867776, 1071704704, 1073381888, 1073741824, 1073494016, 1072883072, 1072012032, 1070930560, 1069665600, 1068232640, 1066641792, 1064899968, 1063012224, 1060982464, 1058814144, 1056510016, 1054072832, 1051505280, 1048809664, 1045988480, 1043044160, 1039979072, 1036795776, 1033496576, 1030084096, 1026560960, 1022929600, 1019192512, 1015352576, 1011412416, 1007374720, 1003242112, 999017472, 994703488, 990302976, 985818688, 981253568, 976610304, 971891712, 967100672, 962240064, 957312576, 952321088, 947268224, 942156992, 936990080, 931770048, 926499840, 921182016, 915819200, 910414208, 904969344, 899487488, 893970944, 888422272, 882843840, 877238144, 871607552, 865954432, 860280896, 854589184, 848881728, 843160384, 837427328, 831684672, 825934208, 820178240, 814418240, 808656320, 802894208, 797133568, 791376192, 785623744, 779877568, 774139520, 768410880, 762693184, 756987904, 751296064, 745619328, 739958784, 734315584, 728691008, 723086208, 717502016, 711939712, 706400064, 700884096, 695392768, 689926912, 684487232, 679074688, 673689856, 668333504, 663006464, 657709056, 652442176, 647206144, 642001600, 636828992, 631688896, 626581696, 621507776, 616467520, 611461184, 606489344, 601552064, 596649792, 591782528, 586950784, 582154560, 577394112, 572669696, 567981312, 563329088, 558713152, 554133568, 549590464, 545083840, 540613760, 536180160, 531783104, 527422528, 523098464, 518810784, 514559520, 510344672, 506165856, 502023360, 497916832, 493846304, 489811488, 485812448, 481848832, 477920672, 474027808, 470169952, 466347008, 462558848, 458805152, 455085920, 451400736, 447749600, 444132160, 440548320, 436997792, 433480416, 429995904, 426544032, 423124608, 419737376, 416382144, 413058720, 409766720, 406505984, 403276288, 400077280, 396908768, 393770656, 390662496, 387584064, 384535200, 381515616, 378525024, 375563200, 372629952, 369724864, 366847872, 363998592, 361176672, 358382176, 355614592, 352873760, 350159456, 347471328, 344809216, 342172864, 339562048, 336976384, 334415808, 331879840, 329368576, 326881472, 324418432, 321979104, 319563392, 317170976, 314801664, 312455232, 310131328, 307829856, 305550528, 303293088, 301057440, 298843168, 296650176, 294478304, 292327168, 290196672, 288086432, 285996512, 283926432, 281876224, 279845472, 277834016, 275841792, 273868480, 271913856, 269977792, 268059968, 266160304, 264278672, 262414768, 260568368, 258739360, 256927520, 255132768, 253354752, 251593392, 249848448, 248119936, 246407424, 244710816, 243030080, 241364928, 239715120, 238080672, 236461248, 234856752, 233267088, 231692016, 230131440, 228585136, 227053024, 225534848, 224030544, 222539872, 221062832 }; +#endif const float c_weights[DIRAC_NO_FB_BANDS_MAX] = { 9.962447e-02f, 9.627997e-01f, 9.926667e-01f, 9.981028e-01f, 9.996648e-01f, 1.000000e+00f, 9.997692e-01f, 9.992002e-01f, 9.983890e-01f, 9.973818e-01f, 9.962037e-01f, 9.948692e-01f, 9.933876e-01f, 9.917654e-01f, 9.900073e-01f, 9.881169e-01f, 9.860975e-01f, 9.839516e-01f, 9.816818e-01f, 9.792906e-01f, 9.767801e-01f, 9.741527e-01f, 9.714106e-01f, 9.685560e-01f, 9.655913e-01f, 9.625187e-01f, 9.593406e-01f, 9.560594e-01f, 9.526774e-01f, 9.491970e-01f, 9.456208e-01f, 9.419512e-01f, 9.381908e-01f, 9.343420e-01f, 9.304075e-01f, 9.263898e-01f, 9.222915e-01f, 9.181152e-01f, 9.138636e-01f, 9.095392e-01f, 9.051447e-01f, 9.006827e-01f, 8.961559e-01f, 8.915668e-01f, 8.869181e-01f, 8.822123e-01f, 8.774521e-01f, 8.726400e-01f, 8.677785e-01f, 8.628702e-01f, 8.579176e-01f, 8.529231e-01f, 8.478893e-01f, 8.428184e-01f, 8.377130e-01f, 8.325753e-01f, 8.274077e-01f, 8.222124e-01f, 8.169917e-01f, 8.117478e-01f, 8.064829e-01f, 8.011990e-01f, 7.958982e-01f, 7.905827e-01f, 7.852543e-01f, 7.799150e-01f, 7.745667e-01f, 7.692112e-01f, 7.638505e-01f, 7.584861e-01f, 7.531199e-01f, 7.477535e-01f, 7.423885e-01f, 7.370265e-01f, 7.316691e-01f, 7.263176e-01f, 7.209736e-01f, 7.156384e-01f, 7.103134e-01f, 7.049999e-01f, 6.996990e-01f, 6.944121e-01f, 6.891403e-01f, 6.838847e-01f, 6.786464e-01f, 6.734265e-01f, 6.682258e-01f, 6.630455e-01f, 6.578863e-01f, 6.527492e-01f, 6.476350e-01f, 6.425445e-01f, 6.374784e-01f, 6.324376e-01f, 6.274226e-01f, 6.224341e-01f, 6.174729e-01f, 6.125393e-01f, 6.076341e-01f, 6.027577e-01f, 5.979106e-01f, 5.930932e-01f, 5.883061e-01f, 5.835497e-01f, 5.788242e-01f, 5.741301e-01f, 5.694676e-01f, 5.648372e-01f, 5.602390e-01f, 5.556734e-01f, 5.511404e-01f, 5.466405e-01f, 5.421737e-01f, 5.377402e-01f, 5.333402e-01f, 5.289738e-01f, 5.246411e-01f, 5.203422e-01f, 5.160771e-01f, 5.118460e-01f, 5.076489e-01f, 5.034858e-01f, 4.993567e-01f, 4.952616e-01f, 4.912005e-01f, 4.871734e-01f, 4.831802e-01f, 4.792209e-01f, 4.752955e-01f, 4.714037e-01f, 4.675457e-01f, 4.637212e-01f, 4.599302e-01f, 4.561725e-01f, 4.524481e-01f, 4.487567e-01f, 4.450983e-01f, 4.414728e-01f, 4.378799e-01f, 4.343195e-01f, 4.307915e-01f, 4.272956e-01f, 4.238318e-01f, 4.203997e-01f, 4.169993e-01f, 4.136303e-01f, 4.102926e-01f, 4.069859e-01f, 4.037101e-01f, 4.004649e-01f, 3.972501e-01f, 3.940655e-01f, 3.909109e-01f, 3.877861e-01f, 3.846909e-01f, 3.816250e-01f, 3.785882e-01f, 3.755803e-01f, 3.726010e-01f, 3.696501e-01f, 3.667275e-01f, 3.638328e-01f, 3.609658e-01f, 3.581263e-01f, 3.553141e-01f, 3.525289e-01f, 3.497705e-01f, 3.470387e-01f, 3.443331e-01f, 3.416537e-01f, 3.390001e-01f, 3.363720e-01f, 3.337694e-01f, 3.311919e-01f, 3.286393e-01f, 3.261114e-01f, 3.236079e-01f, 3.211286e-01f, 3.186733e-01f, 3.162418e-01f, 3.138337e-01f, 3.114490e-01f, 3.090872e-01f, 3.067484e-01f, 3.044321e-01f, 3.021382e-01f, 2.998664e-01f, 2.976166e-01f, 2.953885e-01f, 2.931819e-01f, 2.909966e-01f, 2.888323e-01f, 2.866889e-01f, 2.845661e-01f, 2.824637e-01f, 2.803816e-01f, 2.783194e-01f, 2.762770e-01f, 2.742543e-01f, 2.722509e-01f, 2.702667e-01f, 2.683014e-01f, 2.663550e-01f, 2.644271e-01f, 2.625177e-01f, 2.606264e-01f, 2.587531e-01f, 2.568977e-01f, 2.550599e-01f, 2.532395e-01f, 2.514364e-01f, 2.496503e-01f, 2.478811e-01f, 2.461287e-01f, 2.443928e-01f, 2.426732e-01f, 2.409698e-01f, 2.392824e-01f, 2.376109e-01f, 2.359550e-01f, 2.343146e-01f, 2.326895e-01f, 2.310797e-01f, 2.294848e-01f, 2.279047e-01f, 2.263394e-01f, 2.247886e-01f, 2.232521e-01f, 2.217299e-01f, 2.202217e-01f, 2.187274e-01f, 2.172469e-01f, 2.157800e-01f, 2.143266e-01f, 2.128865e-01f, 2.114596e-01f, 2.100457e-01f, 2.086447e-01f, 2.072564e-01f, 2.058808e-01f }; /*----------------------------------------------------------------------* diff --git a/lib_com/ivas_rom_com.h b/lib_com/ivas_rom_com.h index ff79170198cd26371eefe34a31b2b31e798ad93d..6d1648c4e1de524dc08de8f169bccc326fb759d6 100644 --- a/lib_com/ivas_rom_com.h +++ b/lib_com/ivas_rom_com.h @@ -179,6 +179,9 @@ extern const int16_t DirAC_band_grouping_5[5 + 1]; extern const int16_t DirAC_block_grouping[MAX_PARAM_SPATIAL_SUBFRAMES + 1]; extern const int16_t DirAC_block_grouping_5ms_MDFT[MAX_PARAM_SPATIAL_SUBFRAMES + 1]; +#ifdef IVAS_FLOAT_FIXED +extern const Word32 c_weights_fx[DIRAC_NO_FB_BANDS_MAX]; // Q30 +#endif extern const float c_weights[DIRAC_NO_FB_BANDS_MAX]; extern const float w_nm[NUM_ANA_SECTORS][9]; diff --git a/lib_com/ivas_rom_com_fx.c b/lib_com/ivas_rom_com_fx.c index e7d6600c132fee81f8fa71e5365c7b394855ba5f..269c62d281fbd9149ce1f38fe8cdac4a3c5e6e6f 100644 --- a/lib_com/ivas_rom_com_fx.c +++ b/lib_com/ivas_rom_com_fx.c @@ -1704,14 +1704,14 @@ const Word16 cb_azi_chan_16fx[] = { 0, 1920, 7040, 8640 }; // Q6 * MASA and ISM (OMASA) combined format ROM tables *----------------------------------------------------------------------------------*/ -const Word32 dct4_fx[4 * 4] = { +const Word32 dct4_fx[4 * 4] = { // Q31 1073741824, 1402951040, 1073741824, 581109056, 1073741824, 581109056, -1073741824, -1402951040, 1073741824, -581109056, -1073741824, 1402951040, 1073741824, -1402951040, 1073741824, -581109056 }; -const Word32 dct5_fx[5 * 5] = { +const Word32 dct5_fx[5 * 5] = { // Q31 960354688, 1291711360, 1098867328, 798219648, 419618304, 960354688, 798219648, -419618304, -1291711360, -1098867328, 960354688, 0, -1358283392, 0, 1358283392, @@ -1719,7 +1719,7 @@ const Word32 dct5_fx[5 * 5] = { 960354688, -1291711360, 1098867328, -798219648, 419618304 }; -const Word32 dct8_fx[8 * 8] = { +const Word32 dct8_fx[8 * 8] = { // Q31 759350208, 1053125952, 991922688, 892708928, 759350208, 596570944, 410813632, 209379648, 759350208, 892708928, 410813632, -209379648, -759350208, -1053125952, -991922688, -596570944, 759350208, 596570944, -410813632, -1053125952, -759350208, 209379648, 991922688, 892708928, @@ -1730,7 +1730,7 @@ const Word32 dct8_fx[8 * 8] = { 759350208, -1053125952, 991922688, -892708928, 759350208, -596570944, 410813632, -209379648 }; -const Word32 dct12_fx[12 * 12] = { +const Word32 dct12_fx[12 * 12] = { // Q31 619978560, 869301376, 846752832, 810030848, 759350208, 695569984, 619978560, 533649696, 438301408, 335436960, 226989024, 114460880, 619978560, 810030848, 619978560, 335436960, 0, -335436960, -619978560, -810030848, -876602816, -810030848, -619978560, -335436960, 619978560, 695569984, 226989024, -335436960, -759350208, -869301376, -619978560, -114460880, 438301408, 810030848, 846752832, 533649696, diff --git a/lib_com/ivas_stereo_td_bit_alloc.c b/lib_com/ivas_stereo_td_bit_alloc.c index 995c70ed2148105d11b944643f60ccd837e5c482..4d8f90e9d6f58cc8dd60af07648a3dc3df9f9c9d 100644 --- a/lib_com/ivas_stereo_td_bit_alloc.c +++ b/lib_com/ivas_stereo_td_bit_alloc.c @@ -918,7 +918,7 @@ return; * * copy certain TD stereo parameters from primary channel to secondary channel *-------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED void td_stereo_param_updt( const float lsp_old_PCh[], /* i : primary channel old LSPs */ const float lsf_old_PCh[], /* i : primary channel old LSFs */ @@ -966,8 +966,7 @@ void td_stereo_param_updt( return; } - -#ifdef IVAS_FLOAT_FIXED +#else void td_stereo_param_updt_fx( const Word16 lsp_old_PCh_fx[], /* i : primary channel old LSPs Q15 */ const Word16 lsf_old_PCh_fx[], /* i : primary channel old LSFs Qlog2(2.56) */ @@ -1334,7 +1333,7 @@ static void tdm_SCh_LSF_intra_pred_one_bit_dec_fx( return; } -#endif +#else /*-------------------------------------------------------------------* * tdm_SCh_LSF_intra_pred_one_bit_dec() * @@ -1362,6 +1361,7 @@ static void tdm_SCh_LSF_intra_pred_one_bit_dec( return; } +#endif #ifdef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* @@ -1425,7 +1425,7 @@ static void tdm_SCh_LSF_intra_pred_one_bit_enc_fx( return; } -#endif +#else /*-------------------------------------------------------------------* * tdm_SCh_LSF_intra_pred_one_bit_enc() * @@ -1474,6 +1474,7 @@ static void tdm_SCh_LSF_intra_pred_one_bit_enc( return; } +#endif #ifdef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* @@ -1526,8 +1527,7 @@ void tdm_SCh_lsf_reuse_fx( return; } -#endif - +#else /*-------------------------------------------------------------------* * tdm_SCh_lsf_reuse() * @@ -1578,3 +1578,4 @@ void tdm_SCh_lsf_reuse( return; } +#endif diff --git a/lib_com/prot.h b/lib_com/prot.h index a5bfa721e819130df6279666472abd856a50efb4..c430c9c3dee77e62aa0071b14a547fac4768ab1d 100644 --- a/lib_com/prot.h +++ b/lib_com/prot.h @@ -2354,6 +2354,7 @@ void MDCT_selector( const float enerBuffer[] /* i : energy buffer */ ); +#ifndef IVAS_FLOAT_FIXED void MDCT_selector_reset( TCX_ENC_HANDLE hTcxEnc /* i/o: TCX Encoder Handle */ ); @@ -2362,7 +2363,6 @@ void MDCT_classifier_reset( TCX_ENC_HANDLE hTcxEnc /* i/o: TCX Encoder Handle */ ); -#ifndef IVAS_FLOAT_FIXED ivas_error acelp_core_enc( Encoder_State *st, /* i/o: encoder state structure */ const float inp[], /* i : input signal of the current frame */ @@ -9305,6 +9305,7 @@ ivas_error config_acelp1_IVAS( /*! r: ACELP16k flag */ +#ifndef IVAS_FLOAT_FIXED int16_t set_ACELP_flag_IVAS( const int16_t element_mode, /* i : element mode */ const int32_t element_brate, /* i : element bitrate */ @@ -9314,6 +9315,7 @@ int16_t set_ACELP_flag_IVAS( const int16_t bwidth, /* i : audio bandwidth */ const int16_t cng_type /* i : CNG type */ ); +#endif void FEC_clas_estim( const float *syn, @@ -9984,12 +9986,14 @@ float getTcxBandwidth_flt( const int16_t bwidth /* i : audio bandwidth */ ); +#ifndef IVAS_FLOAT_FIXED int16_t getIgfPresent( const int16_t element_mode, /* i : IVAS element mode */ const int32_t total_brate, /* i : total bitrate */ const int16_t bwidth, /* i : audio bandwidth */ const int16_t rf_mode /* i : flag to signal the RF mode */ ); +#endif int16_t getCnaPresent( const int16_t element_mode, /* i : element mode */ diff --git a/lib_dec/ivas_stereo_ica_dec.c b/lib_dec/ivas_stereo_ica_dec.c index 892df2868417a94640c82961b4376f2ca95dc586..94e17583e295e84f57630158af55dd05697f3387 100644 --- a/lib_dec/ivas_stereo_ica_dec.c +++ b/lib_dec/ivas_stereo_ica_dec.c @@ -56,9 +56,9 @@ #ifdef IVAS_FLOAT_FIXED void stereo_tca_dec_fx( - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - Word32 *synth_fx[CPE_CHANNELS], /* i/o: output synth */ - const Word16 output_frame /* i : length of a frame per channel */ + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + Word32 *synth_fx[CPE_CHANNELS], /* i/o: output synth qsynth*/ + const Word16 output_frame /* i : length of a frame per channel Q0*/ ) { /* Buffers, input Left and right channels @ input_Fs*/ @@ -77,10 +77,11 @@ void stereo_tca_dec_fx( Word16 bothChannelShift; Word32 output_Fs; STEREO_TCA_DEC_HANDLE hStereoTCA; + Word16 exp_ds; hStereoTCA = hCPE->hStereoTCA; - output_Fs = hCPE->hCoreCoder[0]->output_Fs; + output_Fs = hCPE->hCoreCoder[0]->output_Fs; /* Q0 */ move32(); test(); @@ -90,12 +91,12 @@ void stereo_tca_dec_fx( { IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) ) { - hCPE->hStereoDftDmx->targetGain_fx = ONE_IN_Q29; + hCPE->hStereoDftDmx->targetGain_fx = ONE_IN_Q29; /* Q29 */ move32(); } /* save the target gain for next frame */ - hCPE->hStereoDftDmx->prevTargetGain_fx = hCPE->hStereoDftDmx->targetGain_fx; + hCPE->hStereoDftDmx->prevTargetGain_fx = hCPE->hStereoDftDmx->targetGain_fx; /* Q29 */ move32(); } @@ -107,25 +108,27 @@ void stereo_tca_dec_fx( } /* populate L/R memories into current buffers */ - Copy32( hStereoTCA->memChanL_fx, bufChanL_fx, L_DEC_MEM_LEN_ICA ); - Copy32( hStereoTCA->memChanR_fx, bufChanR_fx, L_DEC_MEM_LEN_ICA ); + Copy32( hStereoTCA->memChanL_fx, bufChanL_fx, L_DEC_MEM_LEN_ICA ); /* memChan_q */ + Copy32( hStereoTCA->memChanR_fx, bufChanR_fx, L_DEC_MEM_LEN_ICA ); /* memChan_q */ /* pointers to the current frame */ - ptrChanL_fx = bufChanL_fx + L_DEC_MEM_LEN_ICA; - ptrChanR_fx = bufChanR_fx + L_DEC_MEM_LEN_ICA; + ptrChanL_fx = bufChanL_fx + L_DEC_MEM_LEN_ICA; /* memChan_q */ + ptrChanR_fx = bufChanR_fx + L_DEC_MEM_LEN_ICA; /* memChan_q */ /* copy interleaved stereo data to two channels, e.g., L, R */ - Copy32( synth_fx[0], ptrChanL_fx, output_frame ); - Copy32( synth_fx[1], ptrChanR_fx, output_frame ); + Copy32( synth_fx[0], ptrChanL_fx, output_frame ); /* qsynth */ + Copy32( synth_fx[1], ptrChanR_fx, output_frame ); /* qsynth */ /* back up the L/R target synth for next frame */ - Copy32( bufChanL_fx + output_frame, hStereoTCA->memChanL_fx, L_DEC_MEM_LEN_ICA ); - Copy32( bufChanR_fx + output_frame, hStereoTCA->memChanR_fx, L_DEC_MEM_LEN_ICA ); + Copy32( bufChanL_fx + output_frame, hStereoTCA->memChanL_fx, L_DEC_MEM_LEN_ICA ); /* memChan_q */ + Copy32( bufChanR_fx + output_frame, hStereoTCA->memChanR_fx, L_DEC_MEM_LEN_ICA ); /* memChan_q */ /* TCA parameter de-quantize */ - dsFactor = extract_l( output_Fs / 8000 ); - tempMax = NS2SA( output_Fs, L_NCSHIFT_NS ); - hStereoTCA->corrLagStats = s_min( hStereoTCA->indx_ica_NCShift * dsFactor, tempMax ); + dsFactor = BASOP_Util_Divide3232_Scale( output_Fs, 8000, &exp_ds ); + dsFactor = shr( dsFactor, sub( 15, exp_ds ) ); /* Q0 */ + + tempMax = NS2SA( output_Fs, L_NCSHIFT_NS ); /* Q0 */ + hStereoTCA->corrLagStats = s_min( hStereoTCA->indx_ica_NCShift * dsFactor, tempMax ); /* Q0 */ bothChannelShift = 0; move16(); @@ -134,22 +137,22 @@ void stereo_tca_dec_fx( { hStereoTCA->corrLagStats = 0; move16(); - hStereoTCA->refChanIndx = L_CH_INDX; + hStereoTCA->refChanIndx = L_CH_INDX; /* Q0 */ move16(); - hStereoTCA->targetGain_fx = ONE_IN_Q29; + hStereoTCA->targetGain_fx = ONE_IN_Q29; /* Q29 */ move16(); IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) ) { - hStereoTCA->corrLagStats = extract_l( L_shr( L_abs( hCPE->hStereoDft->itd_fx[1] ), Q15 ) ); + hStereoTCA->corrLagStats = extract_l( L_shr( L_abs( hCPE->hStereoDft->itd_fx[1] ), Q15 ) ); /* Q0 */ IF( hCPE->hStereoDft->itd_fx[1] >= 0 ) { - hStereoTCA->refChanIndx = ( L_CH_INDX ); + hStereoTCA->refChanIndx = ( L_CH_INDX ); /* Q0 */ } ELSE { - hStereoTCA->refChanIndx = ( R_CH_INDX ); + hStereoTCA->refChanIndx = ( R_CH_INDX ); /* Q0 */ } move16(); move16(); @@ -160,15 +163,15 @@ void stereo_tca_dec_fx( itd = hCPE->hStereoMdct->itd_fx; move32(); - hStereoTCA->corrLagStats = extract_l( L_shr( L_abs( itd ), Q15 ) ); + hStereoTCA->corrLagStats = extract_l( L_shr( L_abs( itd ), Q15 ) ); /* Q0 */ IF( GE_32( itd, 0 ) ) { - hStereoTCA->refChanIndx = ( L_CH_INDX ); + hStereoTCA->refChanIndx = ( L_CH_INDX ); /* Q0 */ } ELSE { - hStereoTCA->refChanIndx = ( R_CH_INDX ); + hStereoTCA->refChanIndx = ( R_CH_INDX ); /* Q0 */ } move16(); } @@ -181,8 +184,8 @@ void stereo_tca_dec_fx( } } - prevNCShift = abs_s( hStereoTCA->prevCorrLagStats ); - currentNCShift = abs_s( hStereoTCA->corrLagStats ); + prevNCShift = abs_s( hStereoTCA->prevCorrLagStats ); /* Q0 */ + currentNCShift = abs_s( hStereoTCA->corrLagStats ); /* Q0 */ test(); IF( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) && EQ_16( hCPE->last_element_mode, IVAS_CPE_TD ) ) @@ -201,24 +204,24 @@ void stereo_tca_dec_fx( IF( currentNCShift != 0 ) { - currentNCShift = add( mult( 19660 /* 0.6 in Q15 */, prevNCShift ), mult( 13106 /* 0.4 in Q15 */, currentNCShift ) ); + currentNCShift = add( mult( 19660 /* 0.6 in Q15 */, prevNCShift ), mult( 13106 /* 0.4 in Q15 */, currentNCShift ) ); /* Q0 */ } - prevNCShift = hStereoTCA->interp_dec_prevNCShift; + prevNCShift = hStereoTCA->interp_dec_prevNCShift; /* Q0 */ move16(); - hStereoTCA->interp_dec_prevNCShift = currentNCShift; + hStereoTCA->interp_dec_prevNCShift = currentNCShift; /* Q0 */ move16(); } ELSE { - hStereoTCA->interp_dec_prevNCShift = currentNCShift; + hStereoTCA->interp_dec_prevNCShift = currentNCShift; /* Q0 */ move16(); hStereoTCA->interp_dec_switch_to_zero_diff = 0; move16(); } - ref_fx = ptrChanL_fx; - target_fx = ptrChanR_fx; + ref_fx = ptrChanL_fx; /* qsynth */ + target_fx = ptrChanR_fx; /* qsynth */ target_idx = R_CH_INDX; move16(); /* identify target signal to adjust for shift variations */ @@ -226,22 +229,22 @@ void stereo_tca_dec_fx( test(); IF( ( ( prevNCShift == 0 ) && EQ_16( hStereoTCA->refChanIndx, R_CH_INDX ) ) || EQ_16( hStereoTCA->prevRefChanIndx, R_CH_INDX ) ) { - ref_fx = ptrChanR_fx; - target_fx = ptrChanL_fx; + ref_fx = ptrChanR_fx; /* qsynth */ + target_fx = ptrChanL_fx; /* qsynth */ target_idx = L_CH_INDX; move16(); } IF( EQ_16( bothChannelShift, 1 ) ) { - ref_fx = ptrChanL_fx; - target_fx = ptrChanR_fx; + ref_fx = ptrChanL_fx; /* qsynth */ + target_fx = ptrChanR_fx; /* qsynth */ target_idx = R_CH_INDX; move16(); IF( EQ_16( hStereoTCA->refChanIndx, R_CH_INDX ) ) { - ref_fx = ptrChanR_fx; - target_fx = ptrChanL_fx; + ref_fx = ptrChanR_fx; /* qsynth */ + target_fx = ptrChanL_fx; /* qsynth */ target_idx = L_CH_INDX; move16(); } @@ -257,14 +260,14 @@ void stereo_tca_dec_fx( move16(); IF( GT_32( output_Fs, 16000 ) ) { - l_shift_adapt = L_SHIFT_ADAPT_MAX; + l_shift_adapt = L_SHIFT_ADAPT_MAX; /* Q0 */ move16(); } test(); IF( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) && EQ_16( hCPE->last_element_mode, IVAS_CPE_DFT ) ) { - l_shift_adapt = shr( l_shift_adapt, 1 ); + l_shift_adapt = shr( l_shift_adapt, 1 ); /* Q0 */ } test(); @@ -287,9 +290,9 @@ void stereo_tca_dec_fx( } /* temporal channel adjustment */ - Copy32( target_fx - currentNCShift, synth_fx[target_idx], output_frame ); + Copy32( target_fx - currentNCShift, synth_fx[target_idx], output_frame ); /* qsynth */ - Copy32( ref_fx, synth_fx[!target_idx], output_frame ); + Copy32( ref_fx, synth_fx[!target_idx], output_frame ); /* qsynth */ /* Scale the Right channel with the gain */ stereo_tca_scale_R_channel_fx( hCPE, synth_fx[1], output_frame ); @@ -299,15 +302,15 @@ void stereo_tca_dec_fx( *-----------------------------------------------------------------*/ /* save the reference channel index for next frame */ - hStereoTCA->prevRefChanIndx = hStereoTCA->refChanIndx; + hStereoTCA->prevRefChanIndx = hStereoTCA->refChanIndx; /* Q0 */ move16(); /* save the corr lag stats for next frame */ - hStereoTCA->prevCorrLagStats = hStereoTCA->corrLagStats; + hStereoTCA->prevCorrLagStats = hStereoTCA->corrLagStats; /* Q0 */ move16(); /* save the target gain for next frame */ - hStereoTCA->prevTargetGain_fx = hStereoTCA->targetGain_fx; + hStereoTCA->prevTargetGain_fx = hStereoTCA->targetGain_fx; /* qsynth */ move32(); return; } @@ -591,9 +594,9 @@ void stereo_tca_scale_R_channel( #else #define MAX_TARGET_GAIN_Q29 1904890240 void stereo_tca_scale_R_channel_fx( - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - Word32 *output_fx, /* i/o: output synthesis, R channel */ - const Word16 output_frame /* i : frame length */ + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + Word32 *output_fx, /* i/o: output synthesis, R channel q_out*/ + const Word16 output_frame /* i : frame length Q0*/ ) { STEREO_TCA_DEC_HANDLE hStereoTCA; @@ -604,7 +607,7 @@ void stereo_tca_scale_R_channel_fx( move16(); hStereoTCA = hCPE->hStereoTCA; - output_Fs = hCPE->hCoreCoder[0]->output_Fs; + output_Fs = hCPE->hCoreCoder[0]->output_Fs; /* Q0 */ move32(); test(); @@ -613,14 +616,14 @@ void stereo_tca_scale_R_channel_fx( return; } /* Scale the Right channel with the gain */ - l_ica_ovl = NS2SA( output_Fs, STEREO_L_TCA_OVLP_NS ); + l_ica_ovl = NS2SA( output_Fs, STEREO_L_TCA_OVLP_NS ); /* Q0 */ move16(); test(); IF( EQ_16( hCPE->nchan_out, 1 ) ) { /* in mono DMX, the scaling is done before synchro_synthesis() */ - flat_old = NS2SA( output_Fs, ACELP_LOOK_NS + IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS ); + flat_old = NS2SA( output_Fs, ACELP_LOOK_NS + IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS ); /* Q0 */ move16(); test(); @@ -630,23 +633,23 @@ void stereo_tca_scale_R_channel_fx( // to be deleted next MR // hCPE->hStereoDftDmx->prevTargetGain *= 2.0f; // hCPE->hStereoDftDmx->prevTargetGain = min( hCPE->hStereoDftDmx->prevTargetGain, powf( 10, ( ( 1 << STEREO_BITS_TCA_GD ) - 1 ) * STEREO_TCA_GDSTEP + STEREO_TCA_GDMIN ) ); - local_value = W_shl( hCPE->hStereoDftDmx->prevTargetGain_fx, 1 ); - hCPE->hStereoDftDmx->prevTargetGain_fx = (Word32) min( local_value, MAX_TARGET_GAIN_Q29 ); - hCPE->hStereoDftDmx->targetGain_fx = ONE_IN_Q29; + local_value = W_shl( hCPE->hStereoDftDmx->prevTargetGain_fx, 1 ); /* Q29 */ + hCPE->hStereoDftDmx->prevTargetGain_fx = (Word32) min( local_value, MAX_TARGET_GAIN_Q29 ); /* Q29 */ + hCPE->hStereoDftDmx->targetGain_fx = ONE_IN_Q29; /* Q29 */ move32(); - flat_old = NS2SA( output_Fs, IVAS_DEC_DELAY_NS ); + flat_old = NS2SA( output_Fs, IVAS_DEC_DELAY_NS ); /* Q0 */ move16(); } } ELSE IF( EQ_16( hCPE->last_element_mode, IVAS_CPE_TD ) && EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) ) { - flat_old = NS2SA( output_Fs, IVAS_DEC_DELAY_NS ); + flat_old = NS2SA( output_Fs, IVAS_DEC_DELAY_NS ); /* Q0 */ move16(); } ELSE { - flat_old = NS2SA( output_Fs, ACELP_LOOK_NS + IVAS_DEC_DELAY_NS ); + flat_old = NS2SA( output_Fs, ACELP_LOOK_NS + IVAS_DEC_DELAY_NS ); /* Q0 */ move16(); } @@ -654,30 +657,30 @@ void stereo_tca_scale_R_channel_fx( { IF( EQ_32( hCPE->hStereoDftDmx->targetGain_fx, ONE_IN_Q29 ) ) { - tempF1_fx = ONE_IN_Q27; + tempF1_fx = ONE_IN_Q27; /* Q27 */ move32(); } ELSE { - Word16 temp_a = (Word16) L_shr( hCPE->hStereoDftDmx->targetGain_fx, (Word16) 16 ); + Word16 temp_a = (Word16) L_shr( hCPE->hStereoDftDmx->targetGain_fx, (Word16) 16 ); /* Q13 */ Word16 temp_a_q = 2; move16(); - tempF1_fx = Inv16( temp_a, &temp_a_q ); - tempF1_fx = L_shl( tempF1_fx, sub( ( 31 - 4 ), sub( 15, temp_a_q ) ) ); + tempF1_fx = Inv16( temp_a, &temp_a_q ); /* Q13 */ + tempF1_fx = L_shl( tempF1_fx, sub( ( 31 - 4 ), sub( 15, temp_a_q ) ) ); /* Q27 */ } IF( EQ_32( hCPE->hStereoDftDmx->prevTargetGain_fx, ONE_IN_Q29 ) ) { - tempF_fx = ONE_IN_Q27; + tempF_fx = ONE_IN_Q27; /* Q27 */ move32(); } ELSE { - Word16 temp_b = (Word16) L_shr( hCPE->hStereoDftDmx->prevTargetGain_fx, 16 ); + Word16 temp_b = (Word16) L_shr( hCPE->hStereoDftDmx->prevTargetGain_fx, 16 ); /* Q13 */ Word16 temp_b_q = 2; move16(); - tempF_fx = Inv16( temp_b, &temp_b_q ); - tempF_fx = L_shl( tempF_fx, sub( ( 31 - 4 ), sub( 15, temp_b_q ) ) ); + tempF_fx = Inv16( temp_b, &temp_b_q ); /* Q13 */ + tempF_fx = L_shl( tempF_fx, sub( ( 31 - 4 ), sub( 15, temp_b_q ) ) ); /* Q27 */ } } ELSE @@ -685,45 +688,45 @@ void stereo_tca_scale_R_channel_fx( IF( EQ_32( hStereoTCA->targetGain_fx, ONE_IN_Q29 ) ) { - tempF1_fx = ONE_IN_Q27; + tempF1_fx = ONE_IN_Q27; /* Q27 */ move32(); } ELSE { - Word16 temp_a = (Word16) L_shr( hStereoTCA->targetGain_fx, (Word16) 16 ); + Word16 temp_a = (Word16) L_shr( hStereoTCA->targetGain_fx, (Word16) 16 ); /* Q13 */ Word16 temp_a_q = 2; move16(); - tempF1_fx = Inv16( temp_a, &temp_a_q ); - tempF1_fx = L_shl( tempF1_fx, sub( ( 31 - 4 ), sub( 15, temp_a_q ) ) ); + tempF1_fx = Inv16( temp_a, &temp_a_q ); /* Q13 */ + tempF1_fx = L_shl( tempF1_fx, sub( ( 31 - 4 ), sub( 15, temp_a_q ) ) ); /* Q27 */ } IF( EQ_32( hStereoTCA->prevTargetGain_fx, ONE_IN_Q29 ) ) { - tempF_fx = ONE_IN_Q27; + tempF_fx = ONE_IN_Q27; /* Q27 */ move32(); } ELSE { - Word16 temp_b = (Word16) L_shr( hStereoTCA->prevTargetGain_fx, (Word16) 16 ); + Word16 temp_b = (Word16) L_shr( hStereoTCA->prevTargetGain_fx, (Word16) 16 ); /* Q13 */ Word16 temp_b_q = 2; move16(); - tempF_fx = Inv16( temp_b, &temp_b_q ); - tempF_fx = L_shl( tempF_fx, sub( ( 31 - 4 ), sub( 15, temp_b_q ) ) ); + tempF_fx = Inv16( temp_b, &temp_b_q ); /* Q13 */ + tempF_fx = L_shl( tempF_fx, sub( ( 31 - 4 ), sub( 15, temp_b_q ) ) ); /* Q27 */ } } SWITCH( output_Fs ) { case 16000: - winSlope_fx = 26843546; + winSlope_fx = 26843546; // 0.0125 in Q31 move32(); BREAK; case 32000: - winSlope_fx = 13421773; + winSlope_fx = 13421773; // 0.00625 in Q30 move32(); BREAK; case 48000: - winSlope_fx = 8947849; + winSlope_fx = 8947849; // 0.00416 in Q30 move32(); BREAK; } @@ -732,7 +735,7 @@ void stereo_tca_scale_R_channel_fx( { FOR( i_fx = 0; i_fx < flat_old; i_fx++ ) { - output_fx[i_fx] = output_fx[i_fx]; + output_fx[i_fx] = output_fx[i_fx]; /* q_out */ move32(); } } @@ -740,7 +743,7 @@ void stereo_tca_scale_R_channel_fx( { FOR( i_fx = 0; i_fx < flat_old; i_fx++ ) { - output_fx[i_fx] = L_shl_sat( Mpy_32_32( output_fx[i_fx], tempF_fx ), 4 ); + output_fx[i_fx] = L_shl_sat( Mpy_32_32( output_fx[i_fx], tempF_fx ), 4 ); /* q_out */ move32(); } } @@ -750,11 +753,11 @@ void stereo_tca_scale_R_channel_fx( { FOR( j = 0; i_fx < flat_old + l_ica_ovl; ( i_fx++, j++ ) ) { - Word32 slope_gain_decend = L_sub( ONE_IN_Q31, j * winSlope_fx ); - Word32 slope_gain_ascend = ( j * winSlope_fx ); - Word32 left_res = Mpy_32_32( slope_gain_decend, output_fx[i_fx] ); - Word32 right_res = Mpy_32_32( slope_gain_ascend, output_fx[i_fx] ); - output_fx[i_fx] = L_add( left_res, right_res ); + Word32 slope_gain_decend = L_sub( ONE_IN_Q31, imult3216( winSlope_fx, j ) ); /* Q31 */ + Word32 slope_gain_ascend = imult3216( winSlope_fx, j ); /* Q31 */ + Word32 left_res = Mpy_32_32( slope_gain_decend, output_fx[i_fx] ); /* q_out */ + Word32 right_res = Mpy_32_32( slope_gain_ascend, output_fx[i_fx] ); /* q_out */ + output_fx[i_fx] = L_add( left_res, right_res ); /* q_out */ move32(); } } @@ -762,11 +765,11 @@ void stereo_tca_scale_R_channel_fx( { FOR( j = 0; i_fx < flat_old + l_ica_ovl; ( i_fx++, j++ ) ) { - Word32 slope_gain_decend = L_sub( ONE_IN_Q31, j * winSlope_fx ); - Word32 slope_gain_ascend = imult3216( winSlope_fx, j ); - Word32 left_res = Mpy_32_32( slope_gain_decend, output_fx[i_fx] ); - Word32 right_res = Mpy_32_32( slope_gain_ascend, output_fx[i_fx] ); - output_fx[i_fx] = L_add_sat( L_shl_sat( Mpy_32_32( tempF_fx, left_res ), 4 ), L_shl_sat( Mpy_32_32( right_res, tempF1_fx ), 4 ) ); + Word32 slope_gain_decend = L_sub( ONE_IN_Q31, imult3216( winSlope_fx, j ) ); /* Q31 */ + Word32 slope_gain_ascend = imult3216( winSlope_fx, j ); /* Q31 */ + Word32 left_res = Mpy_32_32( slope_gain_decend, output_fx[i_fx] ); /* q_out */ + Word32 right_res = Mpy_32_32( slope_gain_ascend, output_fx[i_fx] ); /* q_out */ + output_fx[i_fx] = L_add_sat( L_shl_sat( Mpy_32_32( tempF_fx, left_res ), 4 ), L_shl_sat( Mpy_32_32( right_res, tempF1_fx ), 4 ) ); /* q_out */ move32(); } } @@ -775,7 +778,7 @@ void stereo_tca_scale_R_channel_fx( { FOR( ; i_fx < output_frame; i_fx++ ) { - output_fx[i_fx] = output_fx[i_fx]; + output_fx[i_fx] = output_fx[i_fx]; /* q_out */ move32(); } } @@ -783,7 +786,7 @@ void stereo_tca_scale_R_channel_fx( { FOR( ; i_fx < output_frame; i_fx++ ) { - output_fx[i_fx] = L_shl_sat( Mpy_32_32( output_fx[i_fx], tempF1_fx ), 4 ); + output_fx[i_fx] = L_shl_sat( Mpy_32_32( output_fx[i_fx], tempF1_fx ), 4 ); /* q_out */ move32(); } } @@ -812,9 +815,9 @@ void stereo_tca_init_dec_fx( move16(); hStereoTCA->indx_ica_gD = 0; move16(); - hStereoTCA->targetGain_fx = ONE_IN_Q29; + hStereoTCA->targetGain_fx = ONE_IN_Q29; /* Q29 */ move32(); - hStereoTCA->prevTargetGain_fx = ONE_IN_Q29; + hStereoTCA->prevTargetGain_fx = ONE_IN_Q29; /* Q29 */ move32(); hStereoTCA->corrLagStats = 0; diff --git a/lib_dec/ivas_stereo_icbwe_dec.c b/lib_dec/ivas_stereo_icbwe_dec.c index 5540db7a3f81abc948f062e50c9f106c273719f9..32751a338a44f28d609cbc125b6d4c221b84feac 100644 --- a/lib_dec/ivas_stereo_icbwe_dec.c +++ b/lib_dec/ivas_stereo_icbwe_dec.c @@ -530,8 +530,8 @@ void stereo_icBWE_dec( } #else static Word16 FindScale( - Word32 *buff, - Word16 len, + Word32 *buff, /* Q_buff */ + Word16 len, /* Q0 */ Word16 Q_buff, Word16 Q_prev ) { @@ -553,16 +553,16 @@ static Word16 FindScale( void stereo_icBWE_dec_fx( - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - Word32 *synthRef_fx, /* i/o: Reference channel HB synthesis at output Fs Q11 */ - Word32 *synth_fx, /* o : Non reference channel HB synthesis at output Fs Q11 */ - const Word16 *fb_synth_ref_fx, /* i : ref. high-band synthesis 16-20 kHz fb_synth_ref_fx */ - const Word16 *voice_factors_fx, /* i : voicing factors Q15 */ - const Word16 output_frame, /* i : frame length */ - Word16 *Q_syn /* i : Q of synth and synthRef buffers */ + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + Word32 *synthRef_fx, /* i/o: Reference channel HB synthesis at output Fs Q11 */ + Word32 *synth_fx, /* o : Non reference channel HB synthesis at output Fs Q11 */ + const Word16 *fb_synth_ref_fx, /* i : ref. high-band synthesis 16-20 kHz Q_white_exc*/ + const Word16 *voice_factors_fx, /* i : voicing factors Q15 */ + const Word16 output_frame, /* i : frame length Q0 */ + Word16 *Q_syn /* i : Q of synth and synthRef buffers */ #ifdef FIX_839_FB_CONTENT_SOMETIME_MISSING , - const Word16 Q_white_exc /* i : Q of fb_synth_ref_fx */ + const Word16 Q_white_exc /* i : Q of fb_synth_ref_fx */ #endif ) { @@ -606,7 +606,7 @@ void stereo_icBWE_dec_fx( test(); IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) && EQ_16( hCPE->nchan_out, 1 ) && GT_16( hCPE->hStereoDft->hConfig->res_cod_mode, STEREO_DFT_RES_COD_OFF ) ) { - hCPE->hStereoDft->core_hist[0] = st->core; + hCPE->hStereoDft->core_hist[0] = st->core; /* Q0 */ move16(); return; @@ -658,20 +658,20 @@ void stereo_icBWE_dec_fx( move64(); tmp = shl_sat( 1, synthRef_shift ); #endif - FOR( i = 0; i < shr( output_frame, 1 ); i++ ) + FOR( i = 0; i < output_frame / 2; i++ ) { // needed to be adjusted for q #ifndef FIX_826_PRECISION_LOST_AND_COMPL L_tmp = L_shl( synthRef_fx[i], synthRef_shift ); hb_nrg2_fx = L_add( hb_nrg2_fx, Mpy_32_32( L_tmp, L_tmp ) ); // 2*(Qx + SynthRef_shift) - 31 #else - L_tmp = Mpy_32_16_1( synthRef_fx[i], tmp ); - W_tmp = W_mac_32_32( W_tmp, L_tmp, L_tmp ); + L_tmp = Mpy_32_16_1( synthRef_fx[i], tmp ); /* Qsyn + SynthRef_shift - 15 */ + W_tmp = W_mac_32_32( W_tmp, L_tmp, L_tmp ); /* 2 * (Qsyn + SynthRef_shift) - 29 */ #endif } #ifdef FIX_826_PRECISION_LOST_AND_COMPL - hb_nrg_fx = W_round48_L( W_tmp ); - hCPE->hStereoDft->hb_nrg_subr_fx[0] = hb_nrg_fx; + hb_nrg_fx = W_round48_L( W_tmp ); /* 2 * (Qsyn + SynthRef_shift) - 45 */ + hCPE->hStereoDft->hb_nrg_subr_fx[0] = hb_nrg_fx; /* 2 * (Qsyn + SynthRef_shift) - 45 */ move32(); hStereoDft->q_hb_nrg_subr = sub( shl( add( *Q_syn, synthRef_shift ), 1 ), 45 ); move16(); @@ -679,12 +679,12 @@ void stereo_icBWE_dec_fx( move64(); FOR( ; i < output_frame; i++ ) { - L_tmp = Mpy_32_16_1( synthRef_fx[i], tmp ); - W_tmp = W_mac_32_32( W_tmp, L_tmp, L_tmp ); + L_tmp = Mpy_32_16_1( synthRef_fx[i], tmp ); /* Qsyn + SynthRef_shift - 15 */ + W_tmp = W_mac_32_32( W_tmp, L_tmp, L_tmp ); /* 2 * (Qsyn + SynthRef_shift) - 45 */ } - hCPE->hStereoDft->hb_nrg_subr_fx[1] = W_round48_L( W_tmp ); // 2*(Qx + SynthRef_shift) - 45 - hb_nrg_fx = L_add( hCPE->hStereoDft->hb_nrg_subr_fx[0], hCPE->hStereoDft->hb_nrg_subr_fx[1] ); + hCPE->hStereoDft->hb_nrg_subr_fx[1] = W_round48_L( W_tmp ); // 2 * (Qsyn + SynthRef_shift) - 45 + hb_nrg_fx = L_add( hCPE->hStereoDft->hb_nrg_subr_fx[0], hCPE->hStereoDft->hb_nrg_subr_fx[1] ); // 2 * (Qsyn + SynthRef_shift) - 45 #else hCPE->hStereoDft->hb_nrg_subr_fx[0] = hb_nrg2_fx; move32(); @@ -705,7 +705,7 @@ void stereo_icBWE_dec_fx( #endif - Copy32( synthRef_fx, hCPE->hStereoDft->hb_stefi_sig_fx + hCPE->hStereoDft->hb_stefi_delay, output_frame ); + Copy32( synthRef_fx, hCPE->hStereoDft->hb_stefi_sig_fx + hCPE->hStereoDft->hb_stefi_delay, output_frame ); /* Qsynth */ #ifndef FIX_826_PRECISION_LOST_AND_COMPL Scale_sig32( hCPE->hStereoDft->hb_stefi_sig_fx + hCPE->hStereoDft->hb_stefi_delay, output_frame, -5 ); #endif @@ -720,9 +720,9 @@ void stereo_icBWE_dec_fx( move32(); #endif // MSAN_FIX } - hCPE->hStereoDft->hb_nrg_subr_fx[0] = ( Mpy_32_16_1( hCPE->hStereoDft->hb_nrg_subr_fx[0], shl( hCPE->hStereoDft->NFFT / 2, 6 ) ) ); // 2 * (Qx + SynthRef_shift) - 40 // 2 * (Qx + SynthRef_shift) - 31 - 15 + hCPE->hStereoDft->hb_nrg_subr_fx[0] = ( Mpy_32_16_1( hCPE->hStereoDft->hb_nrg_subr_fx[0], shl( shr( hCPE->hStereoDft->NFFT, 1 ), 6 ) ) ); // 2 * (Qsynth + SynthRef_shift) - 40 // 2 * (Qx + SynthRef_shift) - 31 - 15 move32(); - hCPE->hStereoDft->hb_nrg_subr_fx[1] = ( Mpy_32_16_1( hCPE->hStereoDft->hb_nrg_subr_fx[1], shl( hCPE->hStereoDft->NFFT / 2, 6 ) ) ); // 2 * (Qx + SynthRef_shift) - 40 + hCPE->hStereoDft->hb_nrg_subr_fx[1] = ( Mpy_32_16_1( hCPE->hStereoDft->hb_nrg_subr_fx[1], shl( shr( hCPE->hStereoDft->NFFT, 1 ), 6 ) ) ); // 2 * (Qsynth + SynthRef_shift) - 40 move32(); #ifndef FIX_826_PRECISION_LOST_AND_COMPL hCPE->hStereoDft->q_hb_nrg_subr = sub( shl( ( *Q_syn + synthRef_shift ), 1 ), 40 ); @@ -750,7 +750,7 @@ void stereo_icBWE_dec_fx( } ELSE IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) && LE_32( st->core_brate, SID_2k40 ) ) { - Copy32( synthRef_fx, synth_fx, output_frame ); + Copy32( synthRef_fx, synth_fx, output_frame ); /* Qsynth */ return; } @@ -767,9 +767,9 @@ void stereo_icBWE_dec_fx( { hStereoICBWE->prevSpecMapping_fx = 0; move16(); - hStereoICBWE->prevgsMapping_fx = 16384; + hStereoICBWE->prevgsMapping_fx = 16384; /* 1.f in Q14 */ move16(); - hStereoICBWE->icbweM2Ref_prev_fx = 16384; + hStereoICBWE->icbweM2Ref_prev_fx = 16384; /* 1.f in Q14 */ move16(); } @@ -782,9 +782,9 @@ void stereo_icBWE_dec_fx( { hStereoICBWE->prevSpecMapping_fx = 0; move16(); - hStereoICBWE->prevgsMapping_fx = 16384; + hStereoICBWE->prevgsMapping_fx = 16384; /* 1.f in Q14 */ move16(); - hStereoICBWE->icbweM2Ref_prev_fx = 16384; + hStereoICBWE->icbweM2Ref_prev_fx = 16384; /* 1.f in Q14 */ move16(); } ELSE IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) ) @@ -797,12 +797,12 @@ void stereo_icBWE_dec_fx( prevgsMapping_fx = hStereoICBWE->prevgsMapping_fx; move16(); temp1_fx = shr( extract_h( hStereoDft->side_gain_fx[2 * STEREO_DFT_BAND_MAX + hStereoDft->nbands - 1] ), 1 ); - icbweM2Ref_fx = add( 16384, temp1_fx ); - gsMapping_fx = sub( 16384, temp1_fx ); + icbweM2Ref_fx = add( 16384 /*1.f in Q14*/, temp1_fx ); /* Q14 */ + gsMapping_fx = sub( 16384 /*1.f in Q14*/, temp1_fx ); /* Q14 */ - winLen_fx = extract_l( Mpy_32_16_1( st->output_Fs, 41 ) ); //(int16_t)((SHB_OVERLAP_LEN * st->output_Fs) / 16000); - winSlope_fx = div_s( 1, winLen_fx ); - alpha_fx = winSlope_fx; + winLen_fx = extract_l( Mpy_32_16_1( st->output_Fs, 41 ) ); //(int16_t)((SHB_OVERLAP_LEN * st->output_Fs) / 16000); Q0 + winSlope_fx = div_s( 1, winLen_fx ); /* Q15 */ + alpha_fx = winSlope_fx; /* Q15 */ move16(); FOR( i = 0; i < winLen_fx; i++ ) { @@ -823,29 +823,29 @@ void stereo_icBWE_dec_fx( } #else /*synthRef[i] *= ( alpha * ( icbweM2Ref ) + ( 1.0f - alpha ) * ( hStereoICBWE->icbweM2Ref_prev ) );*/ - temp1_fx = sub( 32767, alpha_fx ); + temp1_fx = sub( 32767, alpha_fx ); /* 1.f in Q15 */ L_tmp = L_mult( alpha_fx, icbweM2Ref_fx ); // Q15 + Q14 + 1 - L_tmp = L_mac( L_tmp, temp1_fx, hStereoICBWE->icbweM2Ref_prev_fx ); // Q15 + Q14 +1 ; - synthRef_fx[i] = L_shl( Mpy_32_32( synthRef_fx[i], L_tmp ), 1 ); + L_tmp = L_mac( L_tmp, temp1_fx, hStereoICBWE->icbweM2Ref_prev_fx ); // Q15 + Q14 + 1 + synthRef_fx[i] = L_shl( Mpy_32_32( synthRef_fx[i], L_tmp ), 1 ); // Qsynth move32(); /*synth[i] *= ( alpha * ( gsMapping ) + ( 1.0f - alpha ) * ( prevgsMapping ) );*/ - L_tmp = L_mult( alpha_fx, gsMapping_fx ); - L_tmp = L_mac( L_tmp, temp1_fx, prevgsMapping_fx ); - synth_fx[i] = L_shl( Mpy_32_32( synth_fx[i], L_tmp ), 1 ); + L_tmp = L_mult( alpha_fx, gsMapping_fx ); // Q15 + Q14 + 1 + L_tmp = L_mac( L_tmp, temp1_fx, prevgsMapping_fx ); // Q15 + Q14 +1 + synth_fx[i] = L_shl( Mpy_32_32( synth_fx[i], L_tmp ), 1 ); // Qsynth move32(); - alpha_fx = add_sat( alpha_fx, winSlope_fx ); + alpha_fx = add_sat( alpha_fx, winSlope_fx ); /* Q15 */ #endif } FOR( ; i < NS2SA( st->output_Fs, FRAME_SIZE_NS ); i++ ) { - synthRef_fx[i] = Mpy_32_16_1( synthRef_fx[i], icbweM2Ref_fx ); + synthRef_fx[i] = Mpy_32_16_1( synthRef_fx[i], icbweM2Ref_fx ); // Qsyth - 1 move32(); - synth_fx[i] = Mpy_32_16_1( synth_fx[i], gsMapping_fx ); + synth_fx[i] = Mpy_32_16_1( synth_fx[i], gsMapping_fx ); // Qsynth - 1 move32(); } - hStereoICBWE->icbweM2Ref_prev_fx = icbweM2Ref_fx; + hStereoICBWE->icbweM2Ref_prev_fx = icbweM2Ref_fx; // Q14 move16(); - hStereoICBWE->prevgsMapping_fx = gsMapping_fx; + hStereoICBWE->prevgsMapping_fx = gsMapping_fx; // Q14 move16(); *Q_syn = sub( *Q_syn, 1 ); @@ -860,7 +860,7 @@ void stereo_icBWE_dec_fx( hStereoICBWE->refChanIndx_bwe = get_next_indice_fx( st, STEREO_ICBWE_REFBITS ); IF( EQ_16( st->flag_ACELP16k, 1 ) ) { - spIndx = get_next_indice_fx( st, STEREO_ICBWE_SPBITS ); + spIndx = get_next_indice_fx( st, STEREO_ICBWE_SPBITS ); /* Q0 */ } ELSE { @@ -869,33 +869,33 @@ void stereo_icBWE_dec_fx( } IF( EQ_16( st->element_mode, IVAS_CPE_TD ) ) { - gsIndx = get_next_indice_fx( st, STEREO_ICBWE_GSBITS ); + gsIndx = get_next_indice_fx( st, STEREO_ICBWE_GSBITS ); /* Q0 */ } ELSE { - gsIndx = get_next_indice_fx( st, STEREO_ICBWE_GSBITS_DFT ); + gsIndx = get_next_indice_fx( st, STEREO_ICBWE_GSBITS_DFT ); /* Q0 */ } /* Store indices in case of frame loss */ - hStereoICBWE->prev_spIndx = spIndx; + hStereoICBWE->prev_spIndx = spIndx; /* Q0 */ move16(); - hStereoICBWE->prev_gsIndx = gsIndx; + hStereoICBWE->prev_gsIndx = gsIndx; /* Q0 */ move16(); } ELSE /*bfi*/ { /* Retrieve last decoded indices */ - spIndx = hStereoICBWE->prev_spIndx; + spIndx = hStereoICBWE->prev_spIndx; /* Q0 */ move16(); - gsIndx = hStereoICBWE->prev_gsIndx; + gsIndx = hStereoICBWE->prev_gsIndx; /* Q0 */ move16(); - hStereoICBWE->refChanIndx_bwe = hStereoICBWE->prev_refChanIndx_bwe; + hStereoICBWE->refChanIndx_bwe = hStereoICBWE->prev_refChanIndx_bwe; /* Q0 */ move16(); } /* IC-BWE parameter de-quant */ /* sp Mapping */ - hStereoICBWE->prevSpecMapping_fx = usdequant_fx( spIndx, -19661, 3277 ); // Q15 + hStereoICBWE->prevSpecMapping_fx = usdequant_fx( spIndx, -19661 /* -0.6 in Q15 */, 3277 /* 0.2 in Q14 */ ); // Q15 /* gs Mapping */ prevgsMapping_fx = hStereoICBWE->prevgsMapping_fx; // Q14 @@ -903,12 +903,12 @@ void stereo_icBWE_dec_fx( IF( EQ_16( st->element_mode, IVAS_CPE_TD ) ) { - hStereoICBWE->prevgsMapping_fx = pow_10_icbwe_gsMapping_tbl_fx[gsIndx]; + hStereoICBWE->prevgsMapping_fx = pow_10_icbwe_gsMapping_tbl_fx[gsIndx]; /* Q14 */ move16(); } ELSE { - hStereoICBWE->prevgsMapping_fx = pow_10_icbwe_gsMappingDFT_tbl_fx[gsIndx]; + hStereoICBWE->prevgsMapping_fx = pow_10_icbwe_gsMappingDFT_tbl_fx[gsIndx]; /* Q14 */ move16(); } @@ -927,17 +927,17 @@ void stereo_icBWE_dec_fx( IF( hCPE->hStereoDftDmx != NULL ) { test(); - IF( LT_32( hCPE->hStereoDftDmx->targetGain_fx, 268435456 ) || GT_32( hCPE->hStereoDftDmx->targetGain_fx, 1073741824 ) ) + IF( LT_32( hCPE->hStereoDftDmx->targetGain_fx, 268435456 /* 0.5 in Q29 */ ) || GT_32( hCPE->hStereoDftDmx->targetGain_fx, 1073741824 /* 2.0 in Q29 */ ) ) { - v_multc_fixed_16_16( voice_factors_fx, 16384, nlMixFac_fx, NB_SUBFR16k ); + v_multc_fixed_16_16( voice_factors_fx, 16384 /* 0.5 in Q15 */, nlMixFac_fx, NB_SUBFR16k ); } } ELSE { test(); - IF( LT_32( hCPE->hStereoTCA->targetGain_fx, 268435456 ) || GT_32( hCPE->hStereoTCA->targetGain_fx, 1073741824 ) ) + IF( LT_32( hCPE->hStereoTCA->targetGain_fx, 268435456 /* 0.5 in Q29 */ ) || GT_32( hCPE->hStereoTCA->targetGain_fx, 1073741824 /* 2.0 in Q29 */ ) ) { - v_multc_fixed_16_16( voice_factors_fx, 16384, nlMixFac_fx, NB_SUBFR16k ); + v_multc_fixed_16_16( voice_factors_fx, 16384 /* 0.5 in Q15 */, nlMixFac_fx, NB_SUBFR16k ); } } @@ -960,7 +960,7 @@ void stereo_icBWE_dec_fx( { temp1_fx = 0; move16(); - temp2_fx = 32767; + temp2_fx = 32767; /* 1.0f in Q15 */ move16(); } ELSE @@ -974,7 +974,7 @@ void stereo_icBWE_dec_fx( } tmp = 0; move16(); - temp2_fx = Sqrt16( sub( 32767, nlMixFac_fx[i] ), &tmp ); + temp2_fx = Sqrt16( sub( 32767 /* 1.0f in Q15 */, nlMixFac_fx[i] ), &tmp ); IF( LT_16( tmp, 0 ) ) { temp2_fx = shl( temp2_fx, tmp ); @@ -1009,13 +1009,13 @@ void stereo_icBWE_dec_fx( Q_syn_shb = sub( Q_syn_shb, 3 ); // gaurded bits - Scale_sig32( hStereoICBWE->lpSHBRef_fx, LPC_SHB_ORDER + 1, sub( Q_syn_shb, 12 ) ); - Scale_sig32( excSHB_nonref_fx, L_FRAME16k, sub( Q_syn_shb, Q_icBWE ) ); - Scale_sig32( hStereoICBWE->mem_lpc_shbsynth_nonref_fx, LPC_SHB_ORDER, sub( Q_syn_shb, hStereoICBWE->prev_Q_lpc_shbsynth_nonref ) ); - Scale_sig32( hStereoICBWE->mem_syn_shb_nonref_fx, L_SHB_LAHEAD, sub( Q_syn_shb, hStereoICBWE->prev_Q_syn_shb_nonref ) ); + Scale_sig32( hStereoICBWE->lpSHBRef_fx, LPC_SHB_ORDER + 1, sub( Q_syn_shb, 12 ) ); // Q_syn_shb + Scale_sig32( excSHB_nonref_fx, L_FRAME16k, sub( Q_syn_shb, Q_icBWE ) ); // Q_syn_shb + Scale_sig32( hStereoICBWE->mem_lpc_shbsynth_nonref_fx, LPC_SHB_ORDER, sub( Q_syn_shb, hStereoICBWE->prev_Q_lpc_shbsynth_nonref ) ); // Q_syn_shb + Scale_sig32( hStereoICBWE->mem_syn_shb_nonref_fx, L_SHB_LAHEAD, sub( Q_syn_shb, hStereoICBWE->prev_Q_syn_shb_nonref ) ); // Q_syn_shb - Copy32( hStereoICBWE->mem_syn_shb_nonref_fx, shb_synth_nonref_fx, L_SHB_LAHEAD ); + Copy32( hStereoICBWE->mem_syn_shb_nonref_fx, shb_synth_nonref_fx, L_SHB_LAHEAD ); // Q_syn_shb E_UTIL_synthesis_fx( 0, hStereoICBWE->lpSHBRef_fx, excSHB_nonref_fx, shb_synth_nonref_fx + L_SHB_LAHEAD, L_FRAME16k, hStereoICBWE->mem_lpc_shbsynth_nonref_fx, 1, LPC_SHB_ORDER ); @@ -1032,13 +1032,13 @@ void stereo_icBWE_dec_fx( move32(); FOR( i = 0; i < L_SHB_LAHEAD + 10; i++ ) { - L_tmp = L_shl( shb_synth_nonref_fx[i], shift_prev_pow ); - prev_pow_fx = L_add( prev_pow_fx, Mpy_32_32( L_tmp, L_tmp ) ); + L_tmp = L_shl( shb_synth_nonref_fx[i], shift_prev_pow ); // Qsyn_shb + shift_prev_pow + prev_pow_fx = L_add( prev_pow_fx, Mpy_32_32( L_tmp, L_tmp ) ); /* 2 * ( Qsyn_shb + shift_prev_pow ) - 31 */ } FOR( i = 0; i < L_SHB_LAHEAD + 10; i++ ) { - L_tmp = L_shl( shb_synth_nonref_fx[L_SHB_LAHEAD + 10 + i], shift_prev_pow ); - curr_pow_fx = L_add( curr_pow_fx, Mpy_32_32( L_tmp, L_tmp ) ); + L_tmp = L_shl( shb_synth_nonref_fx[L_SHB_LAHEAD + 10 + i], shift_prev_pow ); // Qsyn_shb + shift_prev_pow + curr_pow_fx = L_add( curr_pow_fx, Mpy_32_32( L_tmp, L_tmp ) ); /* 2 * ( Qsyn_shb + shift_prev_pow ) - 31 */ } IF( prev_pow_fx == 0 ) @@ -1057,42 +1057,42 @@ void stereo_icBWE_dec_fx( } IF( e_scale_fx < 0 ) { - scale_fx = shl( scale_fx, e_scale_fx ); + scale_fx = shl( scale_fx, e_scale_fx ); /* exp(e_scale_fx) */ e_scale_fx = 0; move16(); } FOR( i = 0; i < L_SHB_LAHEAD; i++ ) { - shb_synth_nonref_fx[i] = Mpy_32_16_1( shb_synth_nonref_fx[i], scale_fx ); + shb_synth_nonref_fx[i] = Mpy_32_16_1( shb_synth_nonref_fx[i], scale_fx ); // Qsyn_shb move32(); } - tmp = 3276; + tmp = 3276; /* 0.1 in Q15 */ move16(); FOR( ; i < L_SHB_LAHEAD + 10; i++ ) { IF( EQ_16( e_scale_fx, 0 ) ) { - temp1_fx = 32767; + temp1_fx = 32767; /* 1.0f in Q15 */ move16(); } ELSE { - temp1_fx = shl( 1, sub( 15, e_scale_fx ) ); + temp1_fx = shl( 1, sub( 15, e_scale_fx ) ); /* 15 - e_scale_fx */ move16(); } - L_tmp = L_mult0( tmp, temp1_fx ); - L_tmp = L_mac0( L_tmp, sub( 32767, tmp ), scale_fx ); - shb_synth_nonref_fx[i] = Mpy_32_16_1( shb_synth_nonref_fx[i], shl( round_fx( L_tmp ), 1 ) ); + L_tmp = L_mult0( tmp, temp1_fx ); /* Q15 + Q15 - e_scale_fx */ + L_tmp = L_mac0( L_tmp, sub( 32767 /* 1.0f in Q15 */, tmp ), scale_fx ); /* Q15 + Q15 - e_scale_fx */ + shb_synth_nonref_fx[i] = Mpy_32_16_1( shb_synth_nonref_fx[i], shl( round_fx( L_tmp ), 1 ) ); // Q_syn_shb - e_scale_fx move32(); - IF( LT_16( tmp, 29492 ) ) + IF( LT_16( tmp, 29492 /* 0.9f in Q15 */ ) ) { - tmp = add( tmp, 3276 ); + tmp = add( tmp, 3276 /* 0.1f in Q15 */ ); } } /* spec and gs adjustment */ Q_syn_shb = sub( Q_syn_shb, e_scale_fx ); - Scale_sig32( shb_synth_nonref_fx + L_SHB_LAHEAD + 10, L_FRAME16k - 10, -e_scale_fx ); + Scale_sig32( shb_synth_nonref_fx + L_SHB_LAHEAD + 10, L_FRAME16k - 10, -e_scale_fx ); /* Q_syn_shb */ tmp = 31; move16(); @@ -1108,8 +1108,8 @@ void stereo_icBWE_dec_fx( tmp = sub( tmp, 9 ); - Scale_sig32( shb_synth_nonref_fx, L_FRAME16k + L_SHB_LAHEAD, tmp - Q_syn_shb ); - hStereoICBWE->memShbSpecMapping_fx = L_shl( hStereoICBWE->memShbSpecMapping_fx, sub( tmp, hStereoICBWE->prev_Q_memshbspec ) ); + Scale_sig32( shb_synth_nonref_fx, L_FRAME16k + L_SHB_LAHEAD, sub( tmp, Q_syn_shb ) ); /* tmp */ + hStereoICBWE->memShbSpecMapping_fx = L_shl( hStereoICBWE->memShbSpecMapping_fx, sub( tmp, hStereoICBWE->prev_Q_memshbspec ) ); /* tmp */ hStereoICBWE->prev_Q_memshbspec = tmp; move16(); @@ -1119,7 +1119,7 @@ void stereo_icBWE_dec_fx( deemph_fx_32( 0, shb_synth_nonref_fx + L_SHB_LAHEAD, specMapping_fx, L_FRAME16k, &( hStereoICBWE->memShbSpecMapping_fx ) ); hStereoICBWE->prev_Q_memshbspec = Q_syn_shb; move16(); - Copy32( shb_synth_nonref_fx + L_FRAME16k, hStereoICBWE->mem_syn_shb_nonref_fx, L_SHB_LAHEAD ); + Copy32( shb_synth_nonref_fx + L_FRAME16k, hStereoICBWE->mem_syn_shb_nonref_fx, L_SHB_LAHEAD ); /* Q_syn_shb */ hStereoICBWE->prev_Q_syn_shb_nonref = Q_syn_shb; move16(); @@ -1130,10 +1130,10 @@ void stereo_icBWE_dec_fx( tmp = sub( tmp, 3 ); - Scale_sig32( shb_synth_nonref_fx, L_FRAME16k + L_SHB_LAHEAD, tmp - Q_syn_shb ); - Scale_sig32( hStereoICBWE->mem_syn_shb_ola_nonref_fx, L_SHB_LAHEAD, tmp - hStereoICBWE->prev_Q_syn_shb_ola_nonref ); + Scale_sig32( shb_synth_nonref_fx, L_FRAME16k + L_SHB_LAHEAD, sub( tmp, Q_syn_shb ) ); /* tmp */ + Scale_sig32( hStereoICBWE->mem_syn_shb_ola_nonref_fx, L_SHB_LAHEAD, sub( tmp, hStereoICBWE->prev_Q_syn_shb_ola_nonref ) ); /* tmp */ - ScaleShapedSHB_32( SHB_OVERLAP_LEN, shb_synth_nonref_fx, hStereoICBWE->mem_syn_shb_ola_nonref_fx, hStereoICBWE->gshapeRef_fx, ( Mpy_32_16_1( L_shl( hStereoICBWE->gFrameRef_fx, 1 ), mult_r( gsMapping_fx, 29492 ) ) ), window_shb_fx, subwin_shb_fx, &tmp, &temp1_fx ); + ScaleShapedSHB_32( SHB_OVERLAP_LEN, shb_synth_nonref_fx, hStereoICBWE->mem_syn_shb_ola_nonref_fx, hStereoICBWE->gshapeRef_fx, ( Mpy_32_16_1( L_shl( hStereoICBWE->gFrameRef_fx, 1 ), mult_r( gsMapping_fx, 29492 /* 0.9 in Q15 */ ) ) ), window_shb_fx, subwin_shb_fx, &tmp, &temp1_fx ); hStereoICBWE->prev_Q_syn_shb_ola_nonref = tmp; move16(); @@ -1155,9 +1155,9 @@ void stereo_icBWE_dec_fx( tmp = sub( tmp, 3 ); - Scale_sig32( shb_synth_nonref_fx, L_FRAME16k + L_SHB_LAHEAD, sub( tmp, Q_syn_shb ) ); - Scale_sig32( hStereoICBWE->memShbHilbert_nonref_fx, HILBERT_MEM_SIZE, sub( tmp, hStereoICBWE->prev_Q_hilb ) ); - Scale_sig32( hStereoICBWE->memShbInterp_nonref_fx, 2 * ALLPASSSECTIONS_STEEP + 1, sub( tmp, hStereoICBWE->prev_Q_interp ) ); + Scale_sig32( shb_synth_nonref_fx, L_FRAME16k + L_SHB_LAHEAD, sub( tmp, Q_syn_shb ) ); /* tmp */ + Scale_sig32( hStereoICBWE->memShbHilbert_nonref_fx, HILBERT_MEM_SIZE, sub( tmp, hStereoICBWE->prev_Q_hilb ) ); /* tmp */ + Scale_sig32( hStereoICBWE->memShbInterp_nonref_fx, 2 * ALLPASSSECTIONS_STEEP + 1, sub( tmp, hStereoICBWE->prev_Q_interp ) ); /* tmp */ hStereoICBWE->prev_Q_hilb = tmp; move16(); @@ -1171,43 +1171,43 @@ void stereo_icBWE_dec_fx( } ELSE { - Copy32( synthRef_fx, synth_fx, output_frame ); + Copy32( synthRef_fx, synth_fx, output_frame ); /* Q_syn */ - winLen_fx = extract_l( Mpy_32_16_1( st->output_Fs, 41 ) ); - winSlope_fx = div_s( 1, winLen_fx ); - alpha_fx = winSlope_fx; + winLen_fx = extract_l( Mpy_32_16_1( st->output_Fs, 41 ) ); /* Q0 */ + winSlope_fx = div_s( 1, winLen_fx ); /* Q15 */ + alpha_fx = winSlope_fx; /* Q15 */ move16(); IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) ) { - ratio_L_fx = 16384; + ratio_L_fx = 16384; /* 0.5 in Q15 */ move16(); } ELSE { - ratio_L_fx = extract_h( tdm_ratio_tabl_fx[hCPE->hStereoTD->tdm_last_ratio_idx] ); + ratio_L_fx = extract_h( tdm_ratio_tabl_fx[hCPE->hStereoTD->tdm_last_ratio_idx] ); /* Q15 */ move16(); } - icbweM2Ref_fx = gsMapping_fx; + icbweM2Ref_fx = gsMapping_fx; /* Q14 */ move16(); IF( hStereoICBWE->refChanIndx_bwe == L_CH_INDX ) { - IF( GE_16( ratio_L_fx, 3276 ) ) + IF( GE_16( ratio_L_fx, 3276 /* 0.1 in Q15 */ ) ) { - tmp = mult_r( sub( 32767, ratio_L_fx ), sub( 32767, ratio_L_fx ) ); // Q15 - tmp = mult_r( tmp, gsMapping_fx ); // Q14 - tmp = mult_r( tmp, gsMapping_fx ); // Q13 - IF( LT_16( tmp, 4096 ) ) + tmp = mult_r( sub( 32767 /* 1.0 in Q15 */, ratio_L_fx ), sub( 32767 /* 1.0 in Q15 */, ratio_L_fx ) ); // Q15 + tmp = mult_r( tmp, gsMapping_fx ); // Q14 + tmp = mult_r( tmp, gsMapping_fx ); // Q13 + IF( LT_16( tmp, 4096 /* 0.5 in Q13*/ ) ) { temp1_fx = 0; move16(); temp2_fx = 0; move16(); - tmp = shl( tmp, 2 ); - icbweM2Ref_fx = Sqrt16( sub( 16384, tmp ), &temp1_fx ); + tmp = shl( tmp, 2 ); /* Q13 + Q2 */ + icbweM2Ref_fx = Sqrt16( sub( 16384 /* 0.5 in Q15 */, tmp ), &temp1_fx ); icbweM2Ref_fx = BASOP_Util_Divide1616_Scale( icbweM2Ref_fx, ratio_L_fx, &temp2_fx ); #ifdef FIX_860_FER_CRASH icbweM2Ref_fx = shl_sat( icbweM2Ref_fx, add( temp2_fx, sub( temp1_fx, 1 ) ) ); // Q14 @@ -1224,7 +1224,7 @@ void stereo_icBWE_dec_fx( } ELSE { - IF( LE_16( ratio_L_fx, 29490 ) ) + IF( LE_16( ratio_L_fx, 29490 /* 0.9 in Q15*/ ) ) { #ifdef FIX_TMP_714 tmp = mult_r( ratio_L_fx, ratio_L_fx ); // Q15 @@ -1233,14 +1233,14 @@ void stereo_icBWE_dec_fx( #endif tmp = mult_r( tmp, gsMapping_fx ); // Q14 tmp = mult_r( tmp, gsMapping_fx ); // Q13 - IF( LT_16( tmp, 4096 ) ) + IF( LT_16( tmp, 4096 /* 0.5 in Q13*/ ) ) { temp1_fx = 0; move16(); temp2_fx = 0; move16(); tmp = shl( tmp, 2 ); - icbweM2Ref_fx = Sqrt16( sub( 16384, tmp ), &temp1_fx ); + icbweM2Ref_fx = Sqrt16( sub( 16384 /* 0.5 in Q15 */, tmp ), &temp1_fx ); icbweM2Ref_fx = BASOP_Util_Divide1616_Scale( icbweM2Ref_fx, sub( 32767, ratio_L_fx ), &temp2_fx ); #ifdef FIX_860_FER_CRASH icbweM2Ref_fx = shl_sat( icbweM2Ref_fx, add( temp2_fx, sub( temp1_fx, 1 ) ) ); // Q14 @@ -1260,29 +1260,29 @@ void stereo_icBWE_dec_fx( FOR( i = 0; i < winLen_fx; i++ ) { - L_tmp = L_mult0( alpha_fx, icbweM2Ref_fx ); - L_tmp = L_mac0( L_tmp, sub( 32767, alpha_fx ), hStereoICBWE->icbweM2Ref_prev_fx ); - tmp = shl( round_fx( L_tmp ), 1 ); - synthRef_fx[i] = Mpy_32_16_1( synthRef_fx[i], tmp ); + L_tmp = L_mult0( alpha_fx, icbweM2Ref_fx ); /* Q29 */ + L_tmp = L_mac0( L_tmp, sub( 32767 /* 1.0 in Q15*/, alpha_fx ), hStereoICBWE->icbweM2Ref_prev_fx ); /* Q29 */ + tmp = shl( round_fx( L_tmp ), 1 ); /* Q14 */ + synthRef_fx[i] = Mpy_32_16_1( synthRef_fx[i], tmp ); /* Qsyn - 1*/ move32(); - L_tmp = L_mult0( alpha_fx, gsMapping_fx ); - L_tmp = L_mac0( L_tmp, sub( 32767, alpha_fx ), prevgsMapping_fx ); - tmp = shl( round_fx( L_tmp ), 1 ); - synth_fx[i] = Mpy_32_16_1( synth_fx[i], tmp ); + L_tmp = L_mult0( alpha_fx, gsMapping_fx ); /* Q29 */ + L_tmp = L_mac0( L_tmp, sub( 32767 /* 1.0 in Q15*/, alpha_fx ), prevgsMapping_fx ); /* Q29 */ + tmp = shl( round_fx( L_tmp ), 1 ); /* Q14 */ + synth_fx[i] = Mpy_32_16_1( synth_fx[i], tmp ); /* Qsyn - 1 */ move32(); - IF( LE_16( alpha_fx, sub( 32767, winSlope_fx ) ) ) + IF( LE_16( alpha_fx, sub( 32767 /* 1.0 in Q15*/, winSlope_fx ) ) ) { - alpha_fx = add( alpha_fx, winSlope_fx ); + alpha_fx = add( alpha_fx, winSlope_fx ); /* Q15 */ } } FOR( ; i < NS2SA( st->output_Fs, FRAME_SIZE_NS ); i++ ) { - synthRef_fx[i] = Mpy_32_16_1( synthRef_fx[i], icbweM2Ref_fx ); + synthRef_fx[i] = Mpy_32_16_1( synthRef_fx[i], icbweM2Ref_fx ); /* Qsyn - 1 */ move32(); - synth_fx[i] = Mpy_32_16_1( synth_fx[i], gsMapping_fx ); + synth_fx[i] = Mpy_32_16_1( synth_fx[i], gsMapping_fx ); /* Qsyn - 1 */ move32(); } - hStereoICBWE->icbweM2Ref_prev_fx = icbweM2Ref_fx; + hStereoICBWE->icbweM2Ref_prev_fx = icbweM2Ref_fx; /* Q14 */ move16(); ic_bwe_dec_reset_fx( hStereoICBWE ); @@ -1298,7 +1298,7 @@ void stereo_icBWE_dec_fx( /* resample to output FS */ - IF( EQ_32( st->output_Fs, 48000 ) ) + IF( EQ_32( st->output_Fs, 48000 /* Q0 */ ) ) { tmp = 31; move16(); @@ -1306,17 +1306,17 @@ void stereo_icBWE_dec_fx( tmp = FindScale( hStereoICBWE->memShb_fsout_nonref_fx, INTERP_3_2_MEM_LEN, hStereoICBWE->prev_Q_fsout, tmp ); tmp = sub( tmp, 4 ); - Scale_sig32( error_fx, L_FRAME32k, sub( tmp, Q_syn_shb ) ); - Scale_sig32( hStereoICBWE->memShb_fsout_nonref_fx, INTERP_3_2_MEM_LEN, sub( tmp, hStereoICBWE->prev_Q_fsout ) ); + Scale_sig32( error_fx, L_FRAME32k, sub( tmp, Q_syn_shb ) ); /* tmp */ + Scale_sig32( hStereoICBWE->memShb_fsout_nonref_fx, INTERP_3_2_MEM_LEN, sub( tmp, hStereoICBWE->prev_Q_fsout ) ); /* tmp */ interpolate_3_over_2_allpass_32( error_fx, L_FRAME32k, synth_fx, hStereoICBWE->memShb_fsout_nonref_fx ); hStereoICBWE->prev_Q_fsout = tmp; move16(); } - ELSE IF( EQ_32( st->output_Fs, 32000 ) ) + ELSE IF( EQ_32( st->output_Fs, 32000 /* Q0 */ ) ) { - Copy32( error_fx, synth_fx, L_FRAME32k ); + Copy32( error_fx, synth_fx, L_FRAME32k ); /* tmp */ } - ELSE IF( EQ_32( st->output_Fs, 16000 ) ) + ELSE IF( EQ_32( st->output_Fs, 16000 /* Q0 */ ) ) { tmp = 31; move16(); @@ -1324,8 +1324,8 @@ void stereo_icBWE_dec_fx( tmp = FindScale( hStereoICBWE->memShb_fsout_nonref_fx, INTERP_3_2_MEM_LEN, hStereoICBWE->prev_Q_fsout, tmp ); tmp = sub( tmp, 4 ); - Scale_sig32( error_fx, L_FRAME32k, sub( tmp, Q_syn_shb ) ); - Scale_sig32( hStereoICBWE->memShb_fsout_nonref_fx, INTERP_3_2_MEM_LEN, sub( tmp, hStereoICBWE->prev_Q_fsout ) ); + Scale_sig32( error_fx, L_FRAME32k, sub( tmp, Q_syn_shb ) ); /* tmp */ + Scale_sig32( hStereoICBWE->memShb_fsout_nonref_fx, INTERP_3_2_MEM_LEN, sub( tmp, hStereoICBWE->prev_Q_fsout ) ); /* tmp */ Decimate_allpass_steep_fx32( error_fx, hStereoICBWE->memShb_fsout_nonref_fx, L_FRAME32k, synth_fx ); hStereoICBWE->prev_Q_fsout = tmp; move16(); @@ -1333,23 +1333,23 @@ void stereo_icBWE_dec_fx( #ifndef MSAN_FIX Scale_sig32( synth_fx, L_FRAME48k, sub( *Q_syn, add( 1, tmp ) ) ); #else - Scale_sig32( synth_fx, output_frame, sub( *Q_syn, add( 1, tmp ) ) ); + Scale_sig32( synth_fx, output_frame, sub( *Q_syn, add( 1, tmp ) ) ); /* Qsyn - 1 */ #endif *Q_syn = sub( *Q_syn, 1 ); test(); - IF( EQ_16( st->extl, FB_TBE ) && EQ_32( st->output_Fs, 48000 ) ) + IF( EQ_16( st->extl, FB_TBE ) && EQ_32( st->output_Fs, 48000 /* Q0*/ ) ) { // v_add( fb_synth_nonref_fx, synth_fx, synth_fx, L_FRAME48k, 0 ); #ifdef FIX_839_FB_CONTENT_SOMETIME_MISSING - tmp = shl_sat( 1, sub( Q11 + 15, Q_white_exc ) ); + tmp = shl_sat( 1, sub( Q11 + 15, Q_white_exc ) ); /* 29 - Q_white_exc */ IF( tmp != 0 ) { FOR( i = 0; i < L_FRAME48k; i++ ) { - synth_fx[i] = L_mac( synth_fx[i], fb_synth_nonref_fx[i], tmp ); + synth_fx[i] = L_mac( synth_fx[i], fb_synth_nonref_fx[i], tmp ); /* Q_syn */ } } #else @@ -1365,12 +1365,12 @@ void stereo_icBWE_dec_fx( IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) ) { - ratio_L_fx = 16384; + ratio_L_fx = 16384; /* 1.0 in Q15 */ move16(); } ELSE { - ratio_L_fx = extract_h( tdm_ratio_tabl_fx[hCPE->hStereoTD->tdm_last_ratio_idx] ); + ratio_L_fx = extract_h( tdm_ratio_tabl_fx[hCPE->hStereoTD->tdm_last_ratio_idx] ); /* Q15 */ move16(); } @@ -1378,19 +1378,19 @@ void stereo_icBWE_dec_fx( move16(); IF( hStereoICBWE->refChanIndx_bwe == L_CH_INDX ) { - IF( GE_16( ratio_L_fx, 3276 ) ) + IF( GE_16( ratio_L_fx, 3276 /* 0.1 in Q15*/ ) ) { - tmp = mult_r( sub( 32767, ratio_L_fx ), sub( 32767, ratio_L_fx ) ); // Q15 - tmp = mult_r( tmp, gsMapping_fx ); // Q14 - tmp = mult_r( tmp, gsMapping_fx ); // Q13 - IF( LT_16( tmp, 4096 ) ) + tmp = mult_r( sub( 32767 /* 1.0 in Q15*/, ratio_L_fx ), sub( 32767, ratio_L_fx ) ); // Q15 + tmp = mult_r( tmp, gsMapping_fx ); // Q14 + tmp = mult_r( tmp, gsMapping_fx ); // Q13 + IF( LT_16( tmp, 4096 /* 0.5 in Q13*/ ) ) { temp1_fx = 0; move16(); temp2_fx = 0; move16(); tmp = shl( tmp, 2 ); - icbweM2Ref_fx = Sqrt16( sub( 16384, tmp ), &temp1_fx ); + icbweM2Ref_fx = Sqrt16( sub( 16384 /* 0.5 in Q15*/, tmp ), &temp1_fx ); icbweM2Ref_fx = BASOP_Util_Divide1616_Scale( icbweM2Ref_fx, ratio_L_fx, &temp2_fx ); icbweM2Ref_fx = shl_sat( icbweM2Ref_fx, add( temp1_fx, sub( temp2_fx, 1 ) ) ); // Q14 } @@ -1403,7 +1403,7 @@ void stereo_icBWE_dec_fx( } ELSE { - IF( LE_16( ratio_L_fx, 29490 ) ) + IF( LE_16( ratio_L_fx, 29490 /* 0.9 in Q15*/ ) ) { #ifdef FIX_TMP_714 tmp = mult_r( ratio_L_fx, ratio_L_fx ); // Q15 @@ -1412,14 +1412,14 @@ void stereo_icBWE_dec_fx( #endif tmp = mult_r( tmp, gsMapping_fx ); // Q14 tmp = mult_r( tmp, gsMapping_fx ); // Q13 - IF( LT_16( tmp, 4096 ) ) + IF( LT_16( tmp, 4096 /* 0.5 in Q13*/ ) ) { temp1_fx = 0; move16(); temp2_fx = 0; move16(); tmp = shl( tmp, 2 ); - icbweM2Ref_fx = Sqrt16( sub( 16384, tmp ), &temp1_fx ); + icbweM2Ref_fx = Sqrt16( sub( 16384 /* 0.5 in Q15*/, tmp ), &temp1_fx ); icbweM2Ref_fx = BASOP_Util_Divide1616_Scale( icbweM2Ref_fx, sub( 32767, ratio_L_fx ), &temp2_fx ); icbweM2Ref_fx = shl_sat( icbweM2Ref_fx, add( temp2_fx, sub( temp1_fx, 1 ) ) ); // Q14 } @@ -1431,32 +1431,32 @@ void stereo_icBWE_dec_fx( } } - icbweM2Ref_fx = s_max( gsMapping_fx, icbweM2Ref_fx ); + icbweM2Ref_fx = s_max( gsMapping_fx, icbweM2Ref_fx ); /* Q14 */ - winLen_fx = extract_l( Mpy_32_16_1( st->output_Fs, 41 ) ); - winSlope_fx = div_s( 1, winLen_fx ); - alpha_fx = winSlope_fx; + winLen_fx = extract_l( Mpy_32_16_1( st->output_Fs, 41 ) ); /* Q0 */ + winSlope_fx = div_s( 1, winLen_fx ); /* Q15 */ + alpha_fx = winSlope_fx; /* Q15 */ move16(); FOR( i = 0; i < winLen_fx; i++ ) { - L_tmp = L_mult0( alpha_fx, icbweM2Ref_fx ); - L_tmp = L_mac0( L_tmp, sub( 32767, alpha_fx ), hStereoICBWE->icbweM2Ref_prev_fx ); - tmp = shl( round_fx( L_tmp ), 1 ); - synthRef_fx[i] = Mpy_32_16_1( synthRef_fx[i], tmp ); + L_tmp = L_mult0( alpha_fx, icbweM2Ref_fx ); /* Q29 */ + L_tmp = L_mac0( L_tmp, sub( 32767 /* 1.0 in Q15*/, alpha_fx ), hStereoICBWE->icbweM2Ref_prev_fx ); /* Q29 */ + tmp = shl( round_fx( L_tmp ), 1 ); /* Q14 */ + synthRef_fx[i] = Mpy_32_16_1( synthRef_fx[i], tmp ); /* Qsyn - 1 */ move32(); - IF( LE_16( alpha_fx, sub( 32767, winSlope_fx ) ) ) + IF( LE_16( alpha_fx, sub( 32767 /* 1.0 in Q15*/, winSlope_fx ) ) ) { - alpha_fx = add( alpha_fx, winSlope_fx ); + alpha_fx = add( alpha_fx, winSlope_fx ); /* Q15 */ } } FOR( ; i < NS2SA( st->output_Fs, FRAME_SIZE_NS ); i++ ) { - synthRef_fx[i] = Mpy_32_16_1( synthRef_fx[i], icbweM2Ref_fx ); + synthRef_fx[i] = Mpy_32_16_1( synthRef_fx[i], icbweM2Ref_fx ); /* Qsyn - 1 */ move32(); } - hStereoICBWE->icbweM2Ref_prev_fx = icbweM2Ref_fx; + hStereoICBWE->icbweM2Ref_prev_fx = icbweM2Ref_fx; /* Q14 */ move16(); return; @@ -1753,11 +1753,11 @@ void stereo_icBWE_decproc( #else void stereo_icBWE_decproc_fx( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - Word32 *output[CPE_CHANNELS], /* i/o: output synthesis */ - Word32 outputHB[CPE_CHANNELS][L_FRAME48k], /* i : HB synthesis */ - const Word16 last_core, /* i : last core, primary channel */ - const Word16 last_bwidth, /* i : last bandwidth */ - const Word16 output_frame /* i : frame length */ + Word32 *output[CPE_CHANNELS], /* i/o: output synthesis Q11*/ + Word32 outputHB[CPE_CHANNELS][L_FRAME48k], /* i : HB synthesis Q11*/ + const Word16 last_core, /* i : last core, primary channel Q0*/ + const Word16 last_bwidth, /* i : last bandwidth Q0*/ + const Word16 output_frame /* i : frame length Q0*/ #ifndef FIX_826_PRECISION_LOST_AND_COMPL , Word16 q_output /* i : Q-fac of output */ @@ -1816,14 +1816,14 @@ void stereo_icBWE_decproc_fx( * IC-BWE processing * -------------------------------------------------------------------*/ - core = hCPE->hCoreCoder[0]->core; + core = hCPE->hCoreCoder[0]->core; /* Q0 */ move16(); - extl_brate = hCPE->hCoreCoder[0]->extl_brate; + extl_brate = hCPE->hCoreCoder[0]->extl_brate; /* Q0 */ move32(); - output_Fs = hCPE->hCoreCoder[0]->output_Fs; + output_Fs = hCPE->hCoreCoder[0]->output_Fs; /* Q0 */ move32(); - memOffset = NS2SA( output_Fs, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ); + memOffset = NS2SA( output_Fs, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ); /* Q0 */ /* LRTD stereo mode - 2xBWEs used */ test(); @@ -1832,10 +1832,10 @@ void stereo_icBWE_decproc_fx( /* delay HB synth */ FOR( n = 0; n < CPE_CHANNELS; n++ ) { - Copy32( outputHB[n] + output_frame - memOffset, temp0_fx, memOffset ); - Copy32( outputHB[n], outputHB[n] + memOffset, output_frame - memOffset ); - Copy32( hCPE->prev_hb_synth_fx[n], outputHB[n], memOffset ); - Copy32( temp0_fx, hCPE->prev_hb_synth_fx[n], memOffset ); + Copy32( outputHB[n] + output_frame - memOffset, temp0_fx, memOffset ); /* Q11 */ + Copy32( outputHB[n], outputHB[n] + memOffset, output_frame - memOffset ); /* Q11 */ + Copy32( hCPE->prev_hb_synth_fx[n], outputHB[n], memOffset ); /* Q11 */ + Copy32( temp0_fx, hCPE->prev_hb_synth_fx[n], memOffset ); /* Q11 */ } IF( EQ_16( hCPE->nchan_out, 1 ) ) @@ -1844,7 +1844,7 @@ void stereo_icBWE_decproc_fx( FOR( i = 0; i < output_frame; i++ ) { #ifdef FIX_826_PRECISION_LOST_AND_COMPL - outputHB[0][i] = W_extract_l( W_shr( W_mac_32_16( W_mult_32_16( outputHB[0][i], 16384 ), outputHB[1][i], 16384 ), Q16 ) ); + outputHB[0][i] = W_extract_l( W_shr( W_mac_32_16( W_mult_32_16( outputHB[0][i], 16384 ), outputHB[1][i], 16384 ), Q16 ) ); /* Q11 */ #else outputHB[0][i] = L_shr( ( outputHB[0][i] + outputHB[1][i] ), 1 ); #endif @@ -1904,15 +1904,15 @@ void stereo_icBWE_decproc_fx( { #if defined FIX_826_PRECISION_LOST_AND_COMPL case 15: - winSlope_fx = 2185; + winSlope_fx = 2185; /* 0.06 in Q15 */ move32(); BREAK; case 30: - winSlope_fx = 1092; + winSlope_fx = 1092; /* 0.03 in Q15 */ move32(); BREAK; case 45: - winSlope_fx = 728; + winSlope_fx = 728; /* 0.02 in Q15 */ move32(); BREAK; #else @@ -1944,8 +1944,8 @@ void stereo_icBWE_decproc_fx( FOR( i = 0; i < memOffset; i++ ) { #if defined FIX_826_PRECISION_LOST_AND_COMPL - alpha_fx = add_sat( alpha_fx, winSlope_fx ); - outputHB[refChanIndx_bwe][i] = W_round48_L( W_mult_32_16( outputHB[refChanIndx_bwe][i] /* Q11 + Q15 + 1 - 16 = Q11)*/, winSlope_fx ) ); // + alpha_fx = add_sat( alpha_fx, winSlope_fx ); /* Q15 */ + outputHB[refChanIndx_bwe][i] = W_round48_L( W_mult_32_16( outputHB[refChanIndx_bwe][i] /* Q11 + Q15 + 1 - 16 = Q11)*/, winSlope_fx ) ); // Q11 #else Word32 mul_win = Mpy_32_16_1( winSlope_fx, ( i + 1 ) ); // Q30 + Q0 - 15 = Q15 mul_win = L_shl( mul_win, 15 ); // Q30 @@ -1955,16 +1955,16 @@ void stereo_icBWE_decproc_fx( } } /* Resampled LB and HB offset */ - Copy32( outputHB[refChanIndx_bwe], temp0_fx + memOffset, sub( output_frame, memOffset ) ); - Copy32( outputHB[!refChanIndx_bwe], temp1_fx + memOffset, sub( output_frame, memOffset ) ); + Copy32( outputHB[refChanIndx_bwe], temp0_fx + memOffset, sub( output_frame, memOffset ) ); /* Q11 */ + Copy32( outputHB[!refChanIndx_bwe], temp1_fx + memOffset, sub( output_frame, memOffset ) ); /* Q11 */ - decoderDelay = NS2SA( output_Fs, IVAS_DEC_DELAY_NS ); + decoderDelay = NS2SA( output_Fs, IVAS_DEC_DELAY_NS ); /* Q0 */ test(); IF( last_core != ACELP_CORE && EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) ) { /* hb_synth of mid band is faded out in the 1.25 ms prior to DFT analysis and the icbwe is faded in time domain */ - icbweOLASize = NS2SA( output_Fs, STEREO_DFT_DELAY_DEC_BWE_NS ); + icbweOLASize = NS2SA( output_Fs, STEREO_DFT_DELAY_DEC_BWE_NS ); /* Q0 */ FOR( i = 0; i < decoderDelay; i++ ) { @@ -1979,15 +1979,15 @@ void stereo_icBWE_decproc_fx( { #if defined FIX_826_PRECISION_LOST_AND_COMPL case 60: - winSlope_fx = 546; + winSlope_fx = 546; /* 0.0166 in Q15 */ move16(); BREAK; case 40: - winSlope_fx = 819; + winSlope_fx = 819; /* 0.025 in Q15 */ move16(); BREAK; case 20: - winSlope_fx = 1638; + winSlope_fx = 1638; /* 0.05 in Q15 */ move16(); BREAK; default: @@ -2009,16 +2009,16 @@ void stereo_icBWE_decproc_fx( BREAK; #endif } - alpha_fx = winSlope_fx; // Q30 + alpha_fx = winSlope_fx; // Q15 move32(); FOR( ; i < add( decoderDelay, icbweOLASize ); i++ ) { #if defined FIX_826_PRECISION_LOST_AND_COMPL temp0_fx[i] = W_round48_L( W_mult_32_16( temp0_fx[i], alpha_fx ) ); // Q11 move32(); - temp1_fx[i] = W_round48_L( W_mult_32_16( temp1_fx[i], alpha_fx ) ); + temp1_fx[i] = W_round48_L( W_mult_32_16( temp1_fx[i], alpha_fx ) ); // Q11 move32(); - alpha_fx = add_sat( alpha_fx, winSlope_fx ); + alpha_fx = add_sat( alpha_fx, winSlope_fx ); // Q15 #else temp0_fx[i] = L_shl_sat( Mpy_32_32( temp0_fx[i], alpha_fx ), 1 ); // Q11 move32(); @@ -2038,15 +2038,15 @@ void stereo_icBWE_decproc_fx( { #if defined FIX_826_PRECISION_LOST_AND_COMPL case 15: - winSlope_fx = 2185; + winSlope_fx = 2185; /* 0.06 in Q15 */ move16(); BREAK; case 30: - winSlope_fx = 1092; + winSlope_fx = 1092; /* 0.03 in Q15 */ move16(); BREAK; case 45: - winSlope_fx = 728; + winSlope_fx = 728; /* 0.022 in Q15 */ move16(); BREAK; #else @@ -2087,18 +2087,18 @@ void stereo_icBWE_decproc_fx( temp1_fx[i] = L_add( L_shl( Mpy_32_32( Mpy_32_16_1( winSlope_fx, ( i + 1 ) ), hStereoICBWE->memOutHB_fx[hStereoICBWE->prev_refChanIndx_bwe][i] ), 16 ), L_shl( Mpy_32_32( Mpy_32_16_1( winSlope_fx, ( 1 - ( i + 1 ) ) ), hStereoICBWE->memOutHB_fx[refChanIndx_bwe][i] ), 16 ) ); #else - Incr = add_sat( Incr, winSlope_fx ); - Decr = sub( Decr, winSlope_fx ); - temp0_fx[i] = W_round48_L( W_mac_32_16( W_mult_32_16( hStereoICBWE->memOutHB_fx[refChanIndx_bwe][i], Incr ), hStereoICBWE->memOutHB_fx[hStereoICBWE->prev_refChanIndx_bwe][i], Decr ) ); - temp1_fx[i] = W_round48_L( W_mac_32_16( W_mult_32_16( hStereoICBWE->memOutHB_fx[hStereoICBWE->prev_refChanIndx_bwe][i], Incr ), hStereoICBWE->memOutHB_fx[refChanIndx_bwe][i], Decr ) ); + Incr = add_sat( Incr, winSlope_fx ); /* Q15 */ + Decr = sub( Decr, winSlope_fx ); /* Q15 */ + temp0_fx[i] = W_round48_L( W_mac_32_16( W_mult_32_16( hStereoICBWE->memOutHB_fx[refChanIndx_bwe][i], Incr ), hStereoICBWE->memOutHB_fx[hStereoICBWE->prev_refChanIndx_bwe][i], Decr ) ); /* Q11 */ + temp1_fx[i] = W_round48_L( W_mac_32_16( W_mult_32_16( hStereoICBWE->memOutHB_fx[hStereoICBWE->prev_refChanIndx_bwe][i], Incr ), hStereoICBWE->memOutHB_fx[refChanIndx_bwe][i], Decr ) ); /* Q11 */ #endif move32(); } } ELSE { - Copy32( hStereoICBWE->memOutHB_fx[refChanIndx_bwe], temp0_fx, memOffset ); - Copy32( hStereoICBWE->memOutHB_fx[!refChanIndx_bwe], temp1_fx, memOffset ); + Copy32( hStereoICBWE->memOutHB_fx[refChanIndx_bwe], temp0_fx, memOffset ); /* Q11 */ + Copy32( hStereoICBWE->memOutHB_fx[!refChanIndx_bwe], temp1_fx, memOffset ); /* Q11 */ } } @@ -2117,9 +2117,9 @@ void stereo_icBWE_decproc_fx( move32(); output[0][i] = L_add( output[0][i], temp0_fx[i] ); #else - W_tmp = W_mult_32_16( output[0][i], 32767 ); - W_tmp = W_mac_32_16( W_tmp, temp0_fx[i], 16384 ); - output[0][i] = W_round48_L( W_mac_32_16( W_tmp, temp1_fx[i], 16384 ) ); + W_tmp = W_mult_32_16( output[0][i], 32767 /* 1.0 in Q15*/ ); /* Q11 */ + W_tmp = W_mac_32_16( W_tmp, temp0_fx[i], 16384 /* 0.5 in Q15*/ ); /* Q11*/ + output[0][i] = W_round48_L( W_mac_32_16( W_tmp, temp1_fx[i], 16384 /* 0.5 in Q15*/ ) ); /* Q11 */ move32(); #endif @@ -2132,14 +2132,14 @@ void stereo_icBWE_decproc_fx( v_add_32( temp1_fx, output[1], output[1], output_frame ); } - Copy32( outputHB[0] + output_frame - memOffset, hStereoICBWE->memOutHB_fx[0], memOffset ); - Copy32( outputHB[1] + output_frame - memOffset, hStereoICBWE->memOutHB_fx[1], memOffset ); + Copy32( outputHB[0] + output_frame - memOffset, hStereoICBWE->memOutHB_fx[0], memOffset ); /* Q11*/ + Copy32( outputHB[1] + output_frame - memOffset, hStereoICBWE->memOutHB_fx[1], memOffset ); /* Q11 */ IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) ) { /*win_dft = hCPE->hStereoDft->win32ms;*/ - win_dft_fx = hCPE->hStereoDft->win32ms_fx; - dftOvlLen = hCPE->hStereoDft->dft32ms_ovl; + win_dft_fx = hCPE->hStereoDft->win32ms_fx; /* Q15 */ + dftOvlLen = hCPE->hStereoDft->dft32ms_ovl; /* Q0 */ move16(); /* Preparing buffers in anticipation of an ACELP to TCX switch */ @@ -2161,9 +2161,9 @@ void stereo_icBWE_decproc_fx( j = add( j, 1 ); #else Word16 tmp_mul = i_mult( STEREO_DFT32MS_STEP, j ); - hStereoICBWE->memTransitionHB_fx[0][i] = Mpy_32_16_1( hStereoICBWE->memOutHB_fx[0][i], win_dft_fx[tmp_mul] ); + hStereoICBWE->memTransitionHB_fx[0][i] = Mpy_32_16_1( hStereoICBWE->memOutHB_fx[0][i], win_dft_fx[tmp_mul] ); /* Q11 */ move32(); - hStereoICBWE->memTransitionHB_fx[1][i] = Mpy_32_16_1( hStereoICBWE->memOutHB_fx[1][i], win_dft_fx[tmp_mul] ); + hStereoICBWE->memTransitionHB_fx[1][i] = Mpy_32_16_1( hStereoICBWE->memOutHB_fx[1][i], win_dft_fx[tmp_mul] ); /* Q11 */ move32(); j = sub( j, 1 ); #endif @@ -2177,9 +2177,9 @@ void stereo_icBWE_decproc_fx( { #if !defined FIX_826_PRECISION_LOST_AND_COMPL || defined FIX_833_CORRECTION_to_826 Word16 tmp_mul = mult0( STEREO_DFT32MS_STEP, ( sub( dftOvlLen, add( 1, j ) ) ) ); - hStereoICBWE->memTransitionHB_fx[0][memOffset + i] = Mpy_32_16_1( outputHB[0][output_frame - i - 1], win_dft_fx[tmp_mul] ); + hStereoICBWE->memTransitionHB_fx[0][memOffset + i] = Mpy_32_16_1( outputHB[0][output_frame - i - 1], win_dft_fx[tmp_mul] ); /* Q11 */ move32(); - hStereoICBWE->memTransitionHB_fx[1][memOffset + i] = Mpy_32_16_1( outputHB[1][output_frame - i - 1], win_dft_fx[tmp_mul] ); + hStereoICBWE->memTransitionHB_fx[1][memOffset + i] = Mpy_32_16_1( outputHB[1][output_frame - i - 1], win_dft_fx[tmp_mul] ); /* Q11 */ move32(); j = add( j, 1 ); #else @@ -2250,8 +2250,8 @@ void stereo_icBWE_decproc_fx( #else Word32 win_in_fx, win_out_fx, tmp_fx, gain0_fx, gain1_fx; #endif - win_dft_fx = hCPE->hStereoDft->win32ms_fx; - dftOvlLen = hCPE->hStereoDft->dft32ms_ovl; + win_dft_fx = hCPE->hStereoDft->win32ms_fx; /* Q15 */ + dftOvlLen = hCPE->hStereoDft->dft32ms_ovl; /* Q0 */ move16(); // Scale_sig32(hCPE->hStereoDft->td_gain_fx, STEREO_DFT_CORE_HIST_MAX, -12); @@ -2265,22 +2265,22 @@ void stereo_icBWE_decproc_fx( /* hCPE->hStereoDft->q_hb_stefi_sig_fx is always 31 here */ /* tmp = ( win_in * hCPE->hStereoDft->td_gain[0] + win_out * hCPE->hStereoDft->td_gain[1] ) * hCPE->hStereoDft->hb_stefi_sig[i]; */ - W_tmp = W_mult_32_32( hCPE->hStereoDft->td_gain_fx[0], win_in_fx ); + W_tmp = W_mult_32_32( hCPE->hStereoDft->td_gain_fx[0], win_in_fx ); /* q_td_gain + Q31 + 1 */ if ( hCPE->hStereoDft->q_td_gain[0] != 0 ) { - W_tmp = W_shl( W_tmp, sub( 31, hCPE->hStereoDft->q_td_gain[0] ) ); + W_tmp = W_shl( W_tmp, sub( 31, hCPE->hStereoDft->q_td_gain[0] ) ); /* Q63 */ } - W_tmp1 = W_mult_32_32( hCPE->hStereoDft->td_gain_fx[1], win_out_fx ); + W_tmp1 = W_mult_32_32( hCPE->hStereoDft->td_gain_fx[1], win_out_fx ); /* q_td_gain + Q31 + 1 */ if ( hCPE->hStereoDft->q_td_gain[1] != 0 ) { - W_tmp1 = W_shl( W_tmp1, sub( 31, hCPE->hStereoDft->q_td_gain[1] ) ); + W_tmp1 = W_shl( W_tmp1, sub( 31, hCPE->hStereoDft->q_td_gain[1] ) ); /* Q63 */ } - tmp_fx = W_extract_h( W_add_nosat( W_tmp, W_tmp1 ) ); - tmp_fx = W_extract_h( W_mult_32_32( tmp_fx, hCPE->hStereoDft->hb_stefi_sig_fx[i] ) ); + tmp_fx = W_extract_h( W_add_nosat( W_tmp, W_tmp1 ) ); /* Q31 */ + tmp_fx = W_extract_h( W_mult_32_32( tmp_fx, hCPE->hStereoDft->hb_stefi_sig_fx[i] ) ); /* Q11 */ - output[0][i] = L_add_sat( output[0][i], tmp_fx ); + output[0][i] = L_add_sat( output[0][i], tmp_fx ); /* Q11 */ move32(); - output[1][i] = L_sub_sat( output[1][i], tmp_fx ); + output[1][i] = L_sub_sat( output[1][i], tmp_fx ); /* Q11 */ move32(); #else win_in_fx = L_mult( win_dft_fx[mult0( STEREO_DFT32MS_STEP, i )], win_dft_fx[mult0( STEREO_DFT32MS_STEP, i )] ); /* Q31 */ @@ -2315,9 +2315,9 @@ void stereo_icBWE_decproc_fx( tmp_fx = (Word32) W_shr( ( (Word64) hCPE->hStereoDft->td_gain_fx[0] * hCPE->hStereoDft->hb_stefi_sig_fx[i] ), sub( add( (Word16) hCPE->hStereoDft->q_td_gain[0], hCPE->hStereoDft->q_hb_stefi_sig_fx ), q_output ) ); /* Q --> q_output */ #endif #endif - output[0][i] = L_add_sat( output[0][i], tmp_fx ); + output[0][i] = L_add_sat( output[0][i], tmp_fx ); /* Q11 */ move32(); - output[1][i] = L_sub_sat( output[1][i], tmp_fx ); + output[1][i] = L_sub_sat( output[1][i], tmp_fx ); /* Q11 */ move32(); } } @@ -2385,9 +2385,9 @@ void stereo_icBWE_init_dec_fx( /* inter-channel BWE spectral shape adj. */ hStereoICBWE->prevSpecMapping_fx = 0; move16(); - hStereoICBWE->prevgsMapping_fx = 16384; + hStereoICBWE->prevgsMapping_fx = 16384; /* 1.0 in Q14 */ move16(); - hStereoICBWE->icbweM2Ref_prev_fx = 16384; + hStereoICBWE->icbweM2Ref_prev_fx = 16384; /* 1.0 in Q14 */ move16(); hStereoICBWE->prev_spIndx = 0; diff --git a/lib_dec/ivas_stereo_mdct_core_dec_fx.c b/lib_dec/ivas_stereo_mdct_core_dec_fx.c index 22ad71a41e268a141291455889e7d30bebfa7b5b..6731b8b0d24484154bd1fcf6fb6d00d3c178116d 100644 --- a/lib_dec/ivas_stereo_mdct_core_dec_fx.c +++ b/lib_dec/ivas_stereo_mdct_core_dec_fx.c @@ -56,7 +56,7 @@ * Local function prototypes *-------------------------------------------------------------------------*/ -static void apply_dmx_weights_fx( CPE_DEC_HANDLE hCPE, Word32 *x[CPE_CHANNELS][NB_DIV], int16_t transform_type_left[NB_DIV], int16_t transform_type_right[NB_DIV] ); +static void apply_dmx_weights_fx( CPE_DEC_HANDLE hCPE, Word32 *x[CPE_CHANNELS][NB_DIV], Word16 transform_type_left[NB_DIV], Word16 transform_type_right[NB_DIV] ); static void run_min_stats_fx( Decoder_State **sts, Word32 *x[CPE_CHANNELS][NB_DIV], Word16 x_e[CPE_CHANNELS][NB_DIV] ); @@ -69,10 +69,10 @@ static void run_min_stats_fx( Decoder_State **sts, Word32 *x[CPE_CHANNELS][NB_DI *-------------------------------------------------------------------*/ void convert_coeffs_to_higher_res_fx( - const Word32 *in1, /* i : first subframe input */ - const Word32 *in2, /* i : second subframe input */ - Word32 *out, /* o : converted output */ - const Word16 len /* i : length of subframes */ + const Word32 *in1, /* i : first subframe input Qx*/ + const Word32 *in2, /* i : second subframe input Qx*/ + Word32 *out, /* o : converted output Qx*/ + const Word16 len /* i : length of subframes Q0*/ ) { Word16 i; @@ -82,17 +82,17 @@ void convert_coeffs_to_higher_res_fx( { FOR( i = 0; i < len; i += 2 ) { - tmp1 = Mpy_32_32( POINT_5_Q31, ( L_add( in2[i], in1[i] ) ) ); - tmp2 = Mpy_32_32( POINT_5_Q31, ( L_sub( in2[i], in1[i] ) ) ); - out[2 * i] = tmp1; + tmp1 = Mpy_32_32( POINT_5_Q31, ( L_add( in2[i], in1[i] ) ) ); /* Qx */ + tmp2 = Mpy_32_32( POINT_5_Q31, ( L_sub( in2[i], in1[i] ) ) ); /* Qx */ + out[2 * i] = tmp1; /* Qx */ move32(); - out[2 * i + 1] = tmp2; + out[2 * i + 1] = tmp2; /* Qx */ move32(); - tmp1 = Mpy_32_32( POINT_5_Q31, ( L_sub( in2[i], in1[i] ) ) ); - tmp2 = Mpy_32_32( POINT_5_Q31, ( L_add( in2[i], in1[i] ) ) ); - out[2 * i + 2] = tmp1; + tmp1 = Mpy_32_32( POINT_5_Q31, ( L_sub( in2[i], in1[i] ) ) ); /* Qx */ + tmp2 = Mpy_32_32( POINT_5_Q31, ( L_add( in2[i], in1[i] ) ) ); /* Qx */ + out[2 * i + 2] = tmp1; /* Qx */ move32(); - out[2 * i + 3] = tmp2; + out[2 * i + 3] = tmp2; /* Qx */ move32(); } } @@ -100,13 +100,13 @@ void convert_coeffs_to_higher_res_fx( { FOR( i = 0; i < len; i += 2 ) { - out[2 * i] = Mpy_32_32( POINT_5_Q31, ( L_add( in2[i], in1[i] ) ) ); + out[2 * i] = Mpy_32_32( POINT_5_Q31, ( L_add( in2[i], in1[i] ) ) ); /* Qx */ move32(); - out[2 * i + 1] = Mpy_32_32( POINT_5_Q31, ( L_sub( in2[i], in1[i] ) ) ); + out[2 * i + 1] = Mpy_32_32( POINT_5_Q31, ( L_sub( in2[i], in1[i] ) ) ); /* Qx */ move32(); - out[2 * i + 2] = Mpy_32_32( POINT_5_Q31, ( L_sub( in2[i + 1], in1[i + 1] ) ) ); + out[2 * i + 2] = Mpy_32_32( POINT_5_Q31, ( L_sub( in2[i + 1], in1[i + 1] ) ) ); /* Qx */ move32(); - out[2 * i + 3] = Mpy_32_32( POINT_5_Q31, ( L_add( in2[i + 1], in1[i + 1] ) ) ); + out[2 * i + 3] = Mpy_32_32( POINT_5_Q31, ( L_add( in2[i + 1], in1[i + 1] ) ) ); /* Qx */ move32(); } } @@ -122,8 +122,8 @@ void convert_coeffs_to_higher_res_fx( *-------------------------------------------------------------------*/ static void stereo_mdct_dec_stereo_fx( - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - Word16 ms_mask[2][MAX_SFB] /* o : bandwise MS mask */ + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + Word16 ms_mask[2][MAX_SFB] /* o : bandwise MS mask Q0*/ ) { Word16 availableBits; @@ -134,16 +134,16 @@ static void stereo_mdct_dec_stereo_fx( parse_stereo_from_bitstream( hCPE->hStereoMdct, hCPE->hCoreCoder, 0, hCPE->hStereoMdct->isSBAStereoMode, hCPE->hCoreCoder[0], ms_mask ); /*Split available bits between channels */ - availableBits = sub( sub( sub( add( sts[0]->bits_frame_channel, sts[1]->bits_frame_channel ), sts[0]->next_bit_pos ), i_mult( sts[0]->core, ( NF_GAIN_BITS + SMDCT_MINIMUM_ARITH_BITS ) ) ), i_mult( sts[1]->core, ( NF_GAIN_BITS + SMDCT_MINIMUM_ARITH_BITS ) ) ); + availableBits = sub( sub( sub( add( sts[0]->bits_frame_channel, sts[1]->bits_frame_channel ), sts[0]->next_bit_pos ), i_mult( sts[0]->core, ( NF_GAIN_BITS + SMDCT_MINIMUM_ARITH_BITS ) ) ), i_mult( sts[1]->core, ( NF_GAIN_BITS + SMDCT_MINIMUM_ARITH_BITS ) ) ); /* Q0 */ splitAvailableBits_fx( availableBits, hCPE->hStereoMdct->split_ratio, hCPE->hStereoMdct->isSBAStereoMode, &sts[0]->bits_frame_channel, &sts[1]->bits_frame_channel ); - sts[0]->bits_frame_channel = add( sts[0]->bits_frame_channel, i_mult( sts[0]->core, SMDCT_MINIMUM_ARITH_BITS ) ); + sts[0]->bits_frame_channel = add( sts[0]->bits_frame_channel, i_mult( sts[0]->core, SMDCT_MINIMUM_ARITH_BITS ) ); /* Q0 */ move16(); - sts[1]->bits_frame_channel = add( sts[1]->bits_frame_channel, i_mult( sts[1]->core, SMDCT_MINIMUM_ARITH_BITS ) ); + sts[1]->bits_frame_channel = add( sts[1]->bits_frame_channel, i_mult( sts[1]->core, SMDCT_MINIMUM_ARITH_BITS ) ); /* Q0 */ move16(); - sts[1]->bit_stream = &sts[0]->bit_stream[add( add( sts[0]->next_bit_pos, sts[0]->bits_frame_channel ), i_mult( sts[0]->core, NF_GAIN_BITS ) )]; + sts[1]->bit_stream = &sts[0]->bit_stream[sts[0]->next_bit_pos + sts[0]->bits_frame_channel + sts[0]->core * NF_GAIN_BITS]; /* Q0 */ return; } @@ -158,8 +158,8 @@ static void stereo_mdct_dec_stereo_fx( void stereo_mdct_core_dec_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - Word32 *signal_out_fx[CPE_CHANNELS], /* o : synthesis @internal_FS */ - Word16 signal_outFB_fx[CPE_CHANNELS][L_FRAME48k], /* o : synthesis @output_FS */ + Word32 *signal_out_fx[CPE_CHANNELS], /* o : synthesis @internal_FS Q11*/ + Word16 signal_outFB_fx[CPE_CHANNELS][L_FRAME48k], /* o : synthesis @output_FS exp(e_sigFB)*/ Word16 e_sigFB[CPE_CHANNELS] /* o : exponent of synthesis @output_FS */ ) { @@ -213,8 +213,8 @@ void stereo_mdct_core_dec_fx( sts = hCPE->hCoreCoder; st = NULL; - nChannels = CPE_CHANNELS; - bfi = sts[0]->bfi; + nChannels = CPE_CHANNELS; /* Q0 */ + bfi = sts[0]->bfi; /* Q0 */ move16(); FOR( ch = 0; ch < nChannels; ch++ ) @@ -245,7 +245,7 @@ void stereo_mdct_core_dec_fx( set16_fx( ms_mask[1], 0, MAX_SFB ); initMdctStereoDecData_fx( hCPE->hStereoMdct, sts[0]->igf, sts[0]->hIGFDec->igfData.igfInfo.grid, hCPE->element_brate, sts[0]->bwidth ); - hCPE->hStereoMdct->isSBAStereoMode = ( ( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) || EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) && EQ_16( st_ivas->nchan_transport, 2 ) ); + hCPE->hStereoMdct->isSBAStereoMode = ( ( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) || EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) && EQ_16( st_ivas->nchan_transport, 2 ) ); /* Q0 */ move16(); IF( bfi == 0 ) @@ -265,25 +265,25 @@ void stereo_mdct_core_dec_fx( } ELSE { - Copy( hCPE->hStereoMdct->prev_ms_mask[0], ms_mask[0], MAX_SFB ); - Copy( hCPE->hStereoMdct->prev_ms_mask[1], ms_mask[1], MAX_SFB ); + Copy( hCPE->hStereoMdct->prev_ms_mask[0], ms_mask[0], MAX_SFB ); /* Q0 */ + Copy( hCPE->hStereoMdct->prev_ms_mask[1], ms_mask[1], MAX_SFB ); /* Q0 */ test(); test(); IF( NE_16( sts[0]->core, TCX_10_CORE ) && NE_16( sts[1]->core, TCX_10_CORE ) ) { - hCPE->hStereoMdct->mdct_stereo_mode[1] = SMDCT_DUAL_MONO; + hCPE->hStereoMdct->mdct_stereo_mode[1] = SMDCT_DUAL_MONO; /* Q0 */ move16(); - hCPE->hStereoMdct->IGFStereoMode[1] = SMDCT_DUAL_MONO; + hCPE->hStereoMdct->IGFStereoMode[1] = SMDCT_DUAL_MONO; /* Q0 */ move16(); } ELSE IF( EQ_16( sts[0]->core, TCX_10_CORE ) && EQ_16( sts[1]->core, TCX_10_CORE ) ) { - hCPE->hStereoMdct->global_ild[0] = hCPE->hStereoMdct->global_ild[1]; + hCPE->hStereoMdct->global_ild[0] = hCPE->hStereoMdct->global_ild[1]; /* Q0 */ move16(); - hCPE->hStereoMdct->mdct_stereo_mode[0] = hCPE->hStereoMdct->mdct_stereo_mode[1]; + hCPE->hStereoMdct->mdct_stereo_mode[0] = hCPE->hStereoMdct->mdct_stereo_mode[1]; /* Q0 */ move16(); - hCPE->hStereoMdct->IGFStereoMode[0] = hCPE->hStereoMdct->IGFStereoMode[1]; + hCPE->hStereoMdct->IGFStereoMode[0] = hCPE->hStereoMdct->IGFStereoMode[1]; /* Q0 */ move16(); } } @@ -309,19 +309,19 @@ void stereo_mdct_core_dec_fx( // Word16 subFrames = ( hCPE->hCoreCoder[ch]->core == TCX_10_CORE ) ? NB_DIV : 1; IF( ( hCPE->hCoreCoder[ch]->core == TCX_10_CORE ) ) { - subFrames = NB_DIV; + subFrames = NB_DIV; /* Q0 */ } ELSE { - subFrames = 1; + subFrames = 1; /* Q0 */ } move16(); FOR( k = 0; k < subFrames; ++k ) { - Scale_sig32( x_fx[ch][k], x_len[ch][k], sub( x_e[ch][k], 20 ) ); + Scale_sig32( x_fx[ch][k], x_len[ch][k], sub( x_e[ch][k], 20 ) ); /* exp(20) */ x_e[ch][k] = 20; move16(); - Scale_sig32( x_0_fx[ch][k], x_len[ch][k], sub( x_0_e[ch][k], 20 ) ); + Scale_sig32( x_0_fx[ch][k], x_len[ch][k], sub( x_0_e[ch][k], 20 ) ); /* exp(20) */ x_0_e[ch][k] = 20; move16(); } @@ -329,12 +329,12 @@ void stereo_mdct_core_dec_fx( FOR( ch = 0; ch < nChannels; ch++ ) { - nSubframes[ch] = EQ_16( sts[ch]->core, TCX_10_CORE ) ? NB_DIV : 1; + nSubframes[ch] = EQ_16( sts[ch]->core, TCX_10_CORE ) ? NB_DIV : 1; /* Q0 */ move16(); FOR( k = 0; k < nSubframes[ch]; k++ ) { - L_spec[ch] = idiv1616( sts[ch]->hTcxCfg->tcx_coded_lines, nSubframes[ch] ); + L_spec[ch] = idiv1616( sts[ch]->hTcxCfg->tcx_coded_lines, nSubframes[ch] ); /* Q0 */ move16(); init_tcx_info_fx( sts[ch], sts[ch]->L_frame / nSubframes[ch], sts[ch]->hTcxDec->L_frameTCX / nSubframes[ch], k, bfi, &tcx_offset[ch], &tcx_offsetFB[ch], &L_frame[ch], &L_frameTCX[ch], &left_rect[ch], &L_spec[ch] ); @@ -358,7 +358,7 @@ void stereo_mdct_core_dec_fx( { /* mono or dual mono IGF decoding */ decoder_tcx_IGF_mono_fx( st, x_fx[ch][k], &x_e[ch][k], &x_len[ch][k], L_frame[ch], left_rect[ch], bfi, k ); - Scale_sig32( x_fx[ch][k], x_len[ch][k], sub( x_e[ch][k], 20 ) ); + Scale_sig32( x_fx[ch][k], x_len[ch][k], sub( x_e[ch][k], 20 ) ); /* exp(20) */ x_e[ch][k] = 20; move16(); } @@ -379,8 +379,8 @@ void stereo_mdct_core_dec_fx( /* stereo IGF decoding */ decoder_tcx_IGF_stereo_fx( sts, hCPE->hStereoMdct, ms_mask, x_fx, x_e, x_len, L_frame[0], left_rect[0], k, bfi, 0 /* MCT_flag */ ); - Scale_sig32( x_fx[0][k], x_len[0][k], sub( x_e[0][k], 20 ) ); - Scale_sig32( x_fx[1][k], x_len[1][k], sub( x_e[1][k], 20 ) ); + Scale_sig32( x_fx[0][k], x_len[0][k], sub( x_e[0][k], 20 ) ); /* exp(20) */ + Scale_sig32( x_fx[1][k], x_len[1][k], sub( x_e[1][k], 20 ) ); /* exp(20) */ x_e[0][k] = 20; x_e[1][k] = 20; move16(); @@ -393,7 +393,7 @@ void stereo_mdct_core_dec_fx( st = sts[ch]; /* mono or dual mono IGF decoding */ decoder_tcx_IGF_mono_fx( st, x_fx[ch][k], &x_e[ch][k], &x_len[ch][k], L_frame[ch], left_rect[ch], bfi, k ); - Scale_sig32( x_fx[ch][k], x_len[ch][k], sub( x_e[ch][k], 20 ) ); + Scale_sig32( x_fx[ch][k], x_len[ch][k], sub( x_e[ch][k], 20 ) ); /* exp(20) */ x_e[ch][k] = 20; move16(); } @@ -404,7 +404,7 @@ void stereo_mdct_core_dec_fx( FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) { - Copy_Scale_sig_16_32( Aq_fx[ch], Aq_fx_32[ch], ( NB_SUBFR16k + 1 ) * ( M + 1 ), sub( Q16, Q12 ) ); + Copy_Scale_sig_16_32( Aq_fx[ch], Aq_fx_32[ch], ( NB_SUBFR16k + 1 ) * ( M + 1 ), sub( Q16, Q12 ) ); /* Q16 */ } /*--------------------------------------------------------------------------------* @@ -439,15 +439,15 @@ void stereo_mdct_core_dec_fx( move16(); } Word16 s = getScaleFactor32( x_fx[ch][k], L_frameTCX[ch] ); - Scale_sig32( x_fx[ch][k], L_frameTCX[ch], s ); + Scale_sig32( x_fx[ch][k], L_frameTCX[ch], s ); /* exp(x_e + 31 - s) */ TonalMDCTConceal_SaveFreqSignal_ivas_fx( st->hTonalMDCTConc, x_fx[ch][k], sub( x_e[ch][k], s ), L_frameTCX[ch], L_frame[ch], &scf_fx[0], scf_e, 0, get_igf_startline( st, L_frame[ch], L_frameTCX[ch] ) ); - Scale_sig32( x_fx[ch][k], L_frameTCX[ch], negate( s ) ); + Scale_sig32( x_fx[ch][k], L_frameTCX[ch], negate( s ) ); /* exp(x_e) */ } } IF( ( st->hTcxDec->tcxltp_last_gain_unmodified > 0 ) ) { - L_tmp = st->old_fpitch; + L_tmp = st->old_fpitch; /* 15Q16 */ } ELSE { @@ -459,8 +459,8 @@ void stereo_mdct_core_dec_fx( TonalMDCTConceal_UpdateState( st->hTonalMDCTConc, L_frameTCX[ch], L_tmp, bfi, bfi && st->tonal_mdct_plc_active ); } - Copy( ms_mask[0], hCPE->hStereoMdct->prev_ms_mask[0], MAX_SFB ); - Copy( ms_mask[1], hCPE->hStereoMdct->prev_ms_mask[1], MAX_SFB ); + Copy( ms_mask[0], hCPE->hStereoMdct->prev_ms_mask[0], MAX_SFB ); /* Q0 */ + Copy( ms_mask[1], hCPE->hStereoMdct->prev_ms_mask[1], MAX_SFB ); /* Q0 */ } test(); @@ -490,12 +490,12 @@ void stereo_mdct_core_dec_fx( nSubFrames = NB_DIV; } move16(); - Scale_sig32( x_fx[ind][0], shr( L_FRAME_MAX, sub( nSubFrames, 1 ) ), sub( x_e[ind][0], 20 ) ); + Scale_sig32( x_fx[ind][0], shr( L_FRAME_MAX, sub( nSubFrames, 1 ) ), sub( x_e[ind][0], 20 ) ); /* exp(20) */ x_e[ind][0] = 20; move16(); IF( EQ_16( nSubFrames, 2 ) ) { - Scale_sig32( x_fx[ind][1], shr( L_FRAME_MAX, 1 ), sub( x_e[ind][1], 20 ) ); + Scale_sig32( x_fx[ind][1], shr( L_FRAME_MAX, 1 ), sub( x_e[ind][1], 20 ) ); /* exp(20) */ x_e[ind][1] = 20; move16(); } @@ -531,34 +531,34 @@ void stereo_mdct_core_dec_fx( s = sub( sts[ch]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, 4 ); move16(); } - scale_sig32( sts[ch]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, s ); + scale_sig32( sts[ch]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, s ); /* s */ sts[ch]->hFdCngDec->hFdCngCom->cngNoiseLevelExp = sub( sts[ch]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, s ); } test(); IF( sts[ch]->hFdCngDec && sts[ch]->hFdCngDec->hFdCngCom ) { - sts[ch]->hFdCngDec->hFdCngCom->likelihood_noisy_speech = extract_h( sts[ch]->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx ); + sts[ch]->hFdCngDec->hFdCngCom->likelihood_noisy_speech = extract_h( sts[ch]->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx ); /* 16 - q_likelihood_noisy_speech */ } test(); test(); IF( sts[ch]->igf != 0 && sts[ch]->hIGFDec && sts[ch]->hIGFDec->virtualSpec_fx ) { - Scale_sig32( sts[ch]->hIGFDec->virtualSpec_fx + sub( sts[ch]->hIGFDec->infoIGFStartLine, IGF_START_MN ), s_min( sub( sts[ch]->hIGFDec->infoIGFStopLine, sts[ch]->hIGFDec->infoIGFStartLine ), 856 ), sub( sts[ch]->hIGFDec->virtualSpec_e, x_e[ch][0] ) ); + Scale_sig32( sts[ch]->hIGFDec->virtualSpec_fx + sub( sts[ch]->hIGFDec->infoIGFStartLine, IGF_START_MN ), s_min( sub( sts[ch]->hIGFDec->infoIGFStopLine, sts[ch]->hIGFDec->infoIGFStartLine ), 856 ), sub( sts[ch]->hIGFDec->virtualSpec_e, x_e[ch][0] ) ); /* x_e */ sts[ch]->hIGFDec->virtualSpec_e = x_e[ch][0]; move16(); } } - Copy_Scale_sig_16_32( hCPE->hCoreCoder[0]->old_Aq_12_8_fx, hCPE->hCoreCoder[0]->old_Aq_12_8_fx_32, M + 1, ( 28 - norm_s( hCPE->hCoreCoder[0]->old_Aq_12_8_fx[0] - 1 ) ) ); - Copy_Scale_sig_16_32( hCPE->hCoreCoder[1]->old_Aq_12_8_fx, hCPE->hCoreCoder[1]->old_Aq_12_8_fx_32, M + 1, ( 28 - norm_s( hCPE->hCoreCoder[1]->old_Aq_12_8_fx[0] - 1 ) ) ); + Copy_Scale_sig_16_32( hCPE->hCoreCoder[0]->old_Aq_12_8_fx, hCPE->hCoreCoder[0]->old_Aq_12_8_fx_32, M + 1, ( 28 - norm_s( hCPE->hCoreCoder[0]->old_Aq_12_8_fx[0] - 1 ) ) ); /* Q28 */ + Copy_Scale_sig_16_32( hCPE->hCoreCoder[1]->old_Aq_12_8_fx, hCPE->hCoreCoder[1]->old_Aq_12_8_fx_32, M + 1, ( 28 - norm_s( hCPE->hCoreCoder[1]->old_Aq_12_8_fx[0] - 1 ) ) ); /* Q28 */ ivas_mdct_core_reconstruct_fx( hCPE, x_fx, signal_outFB_tmp_fx, fUseTns, 0, Q11, e_sigFB ); - Copy32( signal_out_tmp_fx[0], signal_out_fx[0], L_FRAME48k ); - Copy32( signal_out_tmp_fx[1], signal_out_fx[1], L_FRAME48k ); + Copy32( signal_out_tmp_fx[0], signal_out_fx[0], L_FRAME48k ); /* Q11 */ + Copy32( signal_out_tmp_fx[1], signal_out_fx[1], L_FRAME48k ); /* Q11 */ - Copy( signal_outFB_tmp_fx[0], signal_outFB_fx[0], hCPE->hCoreCoder[0]->hTcxDec->L_frameTCX ); - Copy( signal_outFB_tmp_fx[1], signal_outFB_fx[1], hCPE->hCoreCoder[1]->hTcxDec->L_frameTCX ); + Copy( signal_outFB_tmp_fx[0], signal_outFB_fx[0], hCPE->hCoreCoder[0]->hTcxDec->L_frameTCX ); /* exp(e_sigFB) */ + Copy( signal_outFB_tmp_fx[1], signal_outFB_fx[1], hCPE->hCoreCoder[1]->hTcxDec->L_frameTCX ); /* exp(e_sigFB) */ pop_wmops(); return; @@ -573,9 +573,9 @@ void stereo_mdct_core_dec_fx( static void apply_dmx_weights_fx( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - Word32 *x[CPE_CHANNELS][NB_DIV], /* i/o: MDCT Spectrum */ - Word16 transform_type_left[NB_DIV], /* i : indicate TCX5 for left ch */ - Word16 transform_type_right[NB_DIV] /* i : indicate TCX5 for right ch */ + Word32 *x[CPE_CHANNELS][NB_DIV], /* i/o: MDCT Spectrum Q11*/ + Word16 transform_type_left[NB_DIV], /* i : indicate TCX5 for left ch Q0*/ + Word16 transform_type_right[NB_DIV] /* i : indicate TCX5 for right ch Q0*/ ) { Word16 b, k, l, i, ch; @@ -589,18 +589,18 @@ static void apply_dmx_weights_fx( Word32 convertRes[CPE_CHANNELS][L_FRAME48k]; Word32 *sig[CPE_CHANNELS][NB_DIV], *pTmp[CPE_CHANNELS][NB_DIV]; - nChannels = CPE_CHANNELS; + nChannels = CPE_CHANNELS; /* Q0 */ move16(); - frameSize = hCPE->hStereoMdct->stbParamsTCX20.sfbOffset[hCPE->hStereoMdct->stbParamsTCX20.sfbCnt]; + frameSize = hCPE->hStereoMdct->stbParamsTCX20.sfbOffset[hCPE->hStereoMdct->stbParamsTCX20.sfbCnt]; /* Q0 */ move16(); - transform_type[0][0] = transform_type_left[0]; + transform_type[0][0] = transform_type_left[0]; /* Q0 */ move16(); - transform_type[0][1] = transform_type_left[1]; + transform_type[0][1] = transform_type_left[1]; /* Q0 */ move16(); - transform_type[1][0] = transform_type_right[0]; + transform_type[1][0] = transform_type_right[0]; /* Q0 */ move16(); - transform_type[1][1] = transform_type_right[1]; + transform_type[1][1] = transform_type_right[1]; /* Q0 */ move16(); /* set overall frequency resolution of (sub)frame to maximum of (sub)frame, requires conversion if both channels are not the same */ @@ -610,7 +610,7 @@ static void apply_dmx_weights_fx( { /* use TCX20 band config for TCX20 in both channels and mixed frames */ sfbConf = &hCPE->hStereoMdct->stbParamsTCX20; - nsub = nsub2[0] = nsub2[1] = 1; /* overall TCX 20 */ + nsub = nsub2[0] = nsub2[1] = 1; /* overall TCX 20 Q0*/ move16(); move16(); move16(); @@ -621,34 +621,34 @@ static void apply_dmx_weights_fx( { /* use TCX10 band config only if none of the channels is TCX20 */ sfbConf = &hCPE->hStereoMdct->stbParamsTCX10; - nsub = 2; + nsub = 2; /* Q0 */ move16(); /* set resolution per subframe, subdivide again if subframe is TCX5 in both channels */ // nsub2[0] = ( transform_type[0][0] == TCX_5 && transform_type[1][0] == TCX_5 ) ? 2 : 1; test(); IF( EQ_16( transform_type[0][0], TCX_5 ) && EQ_16( transform_type[1][0], TCX_5 ) ) { - nsub2[0] = 2; + nsub2[0] = 2; /* Q0 */ move16(); } ELSE { - nsub2[0] = 1; + nsub2[0] = 1; /* Q0 */ move16(); } // nsub2[1] = ( transform_type[0][1] == TCX_5 && transform_type[1][1] == TCX_5 ) ? 2 : 1; test(); IF( EQ_16( transform_type[0][1], TCX_5 ) && EQ_16( transform_type[1][1], TCX_5 ) ) { - nsub2[1] = 2; + nsub2[1] = 2; /* Q0 */ move16(); } ELSE { - nsub2[1] = 1; + nsub2[1] = 1; /* Q0 */ move16(); } - tcx_10_only = 1; + tcx_10_only = 1; /* Q0 */ move16(); } @@ -656,26 +656,26 @@ static void apply_dmx_weights_fx( // numCoeffs[0] = ( nsub2[0] == 1 ) ? sfbConf->sfbOffset[sfbConf->sfbCnt] : sfbConf->sfbOffset[sfbConf->sfbCnt] / 2; IF( EQ_16( nsub2[0], 1 ) ) { - numCoeffs[0] = sfbConf->sfbOffset[sfbConf->sfbCnt]; + numCoeffs[0] = sfbConf->sfbOffset[sfbConf->sfbCnt]; /* Q0 */ } ELSE { - numCoeffs[0] = shr( sfbConf->sfbOffset[sfbConf->sfbCnt], 1 ); + numCoeffs[0] = shr( sfbConf->sfbOffset[sfbConf->sfbCnt], 1 ); /* Q0 */ } // numCoeffs[1] = ( nsub2[1] == 1 ) ? sfbConf->sfbOffset[sfbConf->sfbCnt] : sfbConf->sfbOffset[sfbConf->sfbCnt] / 2; IF( EQ_16( nsub2[1], 1 ) ) { - numCoeffs[1] = sfbConf->sfbOffset[sfbConf->sfbCnt]; + numCoeffs[1] = sfbConf->sfbOffset[sfbConf->sfbCnt]; /* Q0 */ } ELSE { - numCoeffs[1] = shr( sfbConf->sfbOffset[sfbConf->sfbCnt], 1 ); + numCoeffs[1] = shr( sfbConf->sfbOffset[sfbConf->sfbCnt], 1 ); /* Q0 */ } /* initially, set pointers to input; if conversion occurs in (sub)frame, set to convertRes */ - sig[0][0] = pTmp[0][0] = x[0][0]; - sig[0][1] = pTmp[0][1] = x[0][1]; - sig[1][0] = pTmp[1][0] = x[1][0]; - sig[1][1] = pTmp[1][1] = x[1][1]; + sig[0][0] = pTmp[0][0] = x[0][0]; /* Q11 */ + sig[0][1] = pTmp[0][1] = x[0][1]; /* Q11 */ + sig[1][0] = pTmp[1][0] = x[1][0]; /* Q11 */ + sig[1][1] = pTmp[1][1] = x[1][1]; /* Q11 */ /* convert (sub)frames to higher frequency resolution */ FOR( ch = 0; ch < nChannels; ch++ ) @@ -686,7 +686,7 @@ static void apply_dmx_weights_fx( IF( EQ_16( transform_type[ch][k], TCX_5 ) && EQ_16( nsub2[k], 1 ) ) { /* subframe is TCX5, but TCX10 or TCX20 in other channel -> convert channel with TCX5 to TCX10 resolution */ - pTmp[ch][k] = sig[ch][k] = convertRes[ch] + i_mult( k, shr( frameSize, 1 ) ); + pTmp[ch][k] = sig[ch][k] = convertRes[ch] + i_mult( k, shr( frameSize, 1 ) ); /* Q11 */ convert_coeffs_to_higher_res_fx( x[ch][k], x[ch][k] + shr( frameSize, 2 ), pTmp[ch][k], shr( frameSize, 2 ) ); } } @@ -695,7 +695,7 @@ static void apply_dmx_weights_fx( IF( NE_16( transform_type[ch][0], TCX_20 ) && EQ_16( nsub, 1 ) ) { /* TCX20 and TCX10 in same frame -> convert channel with TCX10 to TCX20 resolution */ - sig[ch][0] = convertRes[ch]; + sig[ch][0] = convertRes[ch]; /* Q11 */ convert_coeffs_to_higher_res_fx( pTmp[ch][0], pTmp[ch][1], sig[ch][0], shr( frameSize, 1 ) ); } } @@ -708,12 +708,12 @@ static void apply_dmx_weights_fx( FOR( l = 0; l < nsub2[k]; l++ ) { // mdst[ch][k][l * numCoeffs[k]] = mdst[ch][k][( l + 1 ) * numCoeffs[k] - 1] = 0.f; - mdst[ch][k][i_mult( l, numCoeffs[k] )] = mdst[ch][k][sub( i_mult( add( l, 1 ), numCoeffs[k] ), 1 )] = 0; + mdst[ch][k][l * numCoeffs[k]] = mdst[ch][k][( l + 1 ) * numCoeffs[k] - 1] = 0; /* Q11 */ move32(); move32(); FOR( i = l * numCoeffs[k] + 1; i < ( l + 1 ) * numCoeffs[k] - 1; i++ ) { - mdst[ch][k][i] = L_sub( sig[ch][k][i + 1], sig[ch][k][i - 1] ); + mdst[ch][k][i] = L_sub( sig[ch][k][i + 1], sig[ch][k][i - 1] ); /* Q11 */ move32(); } } @@ -748,10 +748,10 @@ static void apply_dmx_weights_fx( } ELSE { - val_div = idiv1616( sfbConf->sfbOffset[b], nsub2[k] ); + val_div = idiv1616( sfbConf->sfbOffset[b], nsub2[k] ); /* Q0 */ move16(); } - start = add( i_mult( l, numCoeffs[k] ), val_div ); + start = add( i_mult( l, numCoeffs[k] ), val_div ); /* Q0 */ IF( sfbConf->sfbOffset[b + 1] == 0 ) { @@ -760,19 +760,19 @@ static void apply_dmx_weights_fx( } ELSE { - val_div = idiv1616( sfbConf->sfbOffset[b + 1], nsub2[k] ); + val_div = idiv1616( sfbConf->sfbOffset[b + 1], nsub2[k] ); /* Q0 */ move16(); } - stop = add( i_mult( l, numCoeffs[k] ), val_div ); + stop = add( i_mult( l, numCoeffs[k] ), val_div ); /* Q0 */ /* compute band energies and cross correlation */ FOR( i = start; i < stop; i++ ) { - sum_nrg_L = W_add( sum_nrg_L, W_add( W_mult_32_32( sig[0][k][i], sig[0][k][i] ), W_mult_32_32( mdst[0][k][i], mdst[0][k][i] ) ) ); - sum_nrg_R = W_add( sum_nrg_R, W_add( W_mult_32_32( sig[1][k][i], sig[1][k][i] ), W_mult_32_32( mdst[1][k][i], mdst[1][k][i] ) ) ); - dot_prod_real = W_add( dot_prod_real, W_add( W_mult_32_32( sig[0][k][i], sig[1][k][i] ), W_mult_32_32( mdst[0][k][i], mdst[1][k][i] ) ) ); - dot_prod_imag = W_add( dot_prod_imag, W_sub( W_mult_32_32( mdst[0][k][i], sig[1][k][i] ), W_mult_32_32( sig[0][k][i], mdst[1][k][i] ) ) ); + sum_nrg_L = W_add( sum_nrg_L, W_add( W_mult_32_32( sig[0][k][i], sig[0][k][i] ), W_mult_32_32( mdst[0][k][i], mdst[0][k][i] ) ) ); /* Q23 */ + sum_nrg_R = W_add( sum_nrg_R, W_add( W_mult_32_32( sig[1][k][i], sig[1][k][i] ), W_mult_32_32( mdst[1][k][i], mdst[1][k][i] ) ) ); /* Q23 */ + dot_prod_real = W_add( dot_prod_real, W_add( W_mult_32_32( sig[0][k][i], sig[1][k][i] ), W_mult_32_32( mdst[0][k][i], mdst[1][k][i] ) ) ); /* Q23 */ + dot_prod_imag = W_add( dot_prod_imag, W_sub( W_mult_32_32( mdst[0][k][i], sig[1][k][i] ), W_mult_32_32( sig[0][k][i], mdst[1][k][i] ) ) ); /* Q23 */ } Word16 norm_sum_nrg_L = Q31; @@ -803,10 +803,10 @@ static void apply_dmx_weights_fx( Word16 guard_bit = find_guarded_bits_fx( 4 ); Word16 min_norm = sub( s_min( s_min( s_min( norm_sum_nrg_L, norm_sum_nrg_R ), norm_dot_prod_real ), norm_dot_prod_imag ), guard_bit ); - Word32 sum_nrg_L_32 = W_extract_h( W_shl( sum_nrg_L, min_norm ) ); - Word32 sum_nrg_R_32 = W_extract_h( W_shl( sum_nrg_R, min_norm ) ); - Word32 dot_prod_real_32 = W_extract_h( W_shl( dot_prod_real, min_norm ) ); - Word32 dot_prod_imag_32 = W_extract_h( W_shl( dot_prod_imag, min_norm ) ); + Word32 sum_nrg_L_32 = W_extract_h( W_shl( sum_nrg_L, min_norm ) ); /* Q23 + min_norm - 32 */ + Word32 sum_nrg_R_32 = W_extract_h( W_shl( sum_nrg_R, min_norm ) ); /* Q23 + min_norm - 32 */ + Word32 dot_prod_real_32 = W_extract_h( W_shl( dot_prod_real, min_norm ) ); /* Q23 + min_norm - 32 */ + Word32 dot_prod_imag_32 = W_extract_h( W_shl( dot_prod_imag, min_norm ) ); /* Q23 + min_norm - 32 */ Word16 q_sum_nrg_L = sub( add( 23, min_norm ), 32 ); Word16 q_sum_nrg_R = sub( add( 23, min_norm ), 32 ); @@ -816,7 +816,7 @@ static void apply_dmx_weights_fx( Word16 E_sum_nrg_R = sub( 31, q_sum_nrg_R ); Word16 E_dot_prod_abs = sub( 31, sub( shl( q_dot_prod_real, 1 ), 31 ) ); Word16 E_sum_nrg_Mid = sub( 31, q_sum_nrg_L ); - sum_nrg_Mid = L_max( 0, L_add( L_add( sum_nrg_L_32, sum_nrg_R_32 ), L_shl( dot_prod_real_32, 1 ) ) ); + sum_nrg_Mid = L_max( 0, L_add( L_add( sum_nrg_L_32, sum_nrg_R_32 ), L_shl( dot_prod_real_32, 1 ) ) ); /* Q23 + min_norm - 32 */ Word32 tmp_nrg_L = Sqrt32( sum_nrg_L_32, &E_sum_nrg_l ); Word32 tmp_nrg_R = Sqrt32( sum_nrg_R_32, &E_sum_nrg_R ); Word16 max_e_sum_abs = E_sum_nrg_l; @@ -827,9 +827,9 @@ static void apply_dmx_weights_fx( move16(); } max_e_sum_abs = add( max_e_sum_abs, 1 ); - sum_abs = L_add( L_shr( tmp_nrg_L, max_e_sum_abs - E_sum_nrg_l ), L_shr( tmp_nrg_R, max_e_sum_abs - E_sum_nrg_R ) ); - dot_prod_abs = Sqrt32( L_add( Mpy_32_32( dot_prod_real_32, dot_prod_real_32 ), Mpy_32_32( dot_prod_imag_32, dot_prod_imag_32 ) ), &E_dot_prod_abs ); - Word32 num = L_add( L_shr( L_add( sum_nrg_L_32, sum_nrg_R_32 ), 1 ), L_shr( dot_prod_abs, ( 31 - E_dot_prod_abs ) - q_sum_nrg_L ) ); + sum_abs = L_add( L_shr( tmp_nrg_L, max_e_sum_abs - E_sum_nrg_l ), L_shr( tmp_nrg_R, max_e_sum_abs - E_sum_nrg_R ) ); /* E_sum_nrg_R */ + dot_prod_abs = Sqrt32( L_add( Mpy_32_32( dot_prod_real_32, dot_prod_real_32 ), Mpy_32_32( dot_prod_imag_32, dot_prod_imag_32 ) ), &E_dot_prod_abs ); /* E_dot_prod_abs */ + Word32 num = L_add( L_shr( L_add( sum_nrg_L_32, sum_nrg_R_32 ), 1 ), L_shr( dot_prod_abs, ( 31 - E_dot_prod_abs ) - q_sum_nrg_L ) ); /* 31 - q_sum_nrg_L */ Word16 E_num = sub( 31, q_sum_nrg_L ); Word32 num_sqrt = Sqrt32( num, &E_num ); @@ -855,7 +855,7 @@ static void apply_dmx_weights_fx( } ELSE { - full_w_up = shr( divide3232( L_shr( num_sqrt, sub( e_full_w, E_num ) ), L_shr( sum_abs, sub( e_full_w, max_e_sum_abs ) ) ), 2 ); + full_w_up = shr( divide3232( L_shr( num_sqrt, sub( e_full_w, E_num ) ), L_shr( sum_abs, sub( e_full_w, max_e_sum_abs ) ) ), 2 ); // Q13 } Word32 sum_nrg_Mid_sqrt = Sqrt32( sum_nrg_Mid, &E_sum_nrg_Mid ); @@ -872,7 +872,7 @@ static void apply_dmx_weights_fx( test(); IF( sum_nrg_Mid_sqrt == 0 && sum_abs == 0 ) { - full_w_down = 16384; + full_w_down = 16384; /* 1.0f in Q14 */ move16(); } ELSE IF( sum_nrg_Mid_sqrt == 0 && sum_abs != 0 ) @@ -882,21 +882,21 @@ static void apply_dmx_weights_fx( } ELSE { - full_w_down = shr( divide3232( L_shr( sum_nrg_Mid_sqrt, sub( e_full_down, E_sum_nrg_Mid ) ), L_shr( sum_abs, sub( e_full_down, max_e_sum_abs ) ) ), 1 ); + full_w_down = shr( divide3232( L_shr( sum_nrg_Mid_sqrt, sub( e_full_down, E_sum_nrg_Mid ) ), L_shr( sum_abs, sub( e_full_down, max_e_sum_abs ) ) ), 1 ); /* Q14 */ } IF( hCPE->hStereoMdct->reverse_dmx == 0 ) { - w[1][add( 2 * k, l )] = full_w_up; + w[1][2 * k + l] = full_w_up; /* Q13 */ move16(); - w[0][add( 2 * k, l )] = add( w[1][add( 2 * k, l )], mult( 23170 /*sqrt(2.0f in Q14)*/, sub( 16384 /* 1.0f in Q14 */, full_w_down ) ) ); + w[0][2 * k + l] = add( w[1][2 * k + l], mult( 23170 /*sqrt(2.0f in Q14)*/, sub( 16384 /* 1.0f in Q14 */, full_w_down ) ) ); /* Q13 */ move16(); } ELSE { - w[0][add( 2 * k, l )] = full_w_up; + w[0][2 * k + l] = full_w_up; /* Q13 */ move16(); - w[1][add( 2 * k, l )] = add( w[0][add( 2 * k, l )], mult( 23170 /*sqrt(2.0f in Q14)*/, sub( 16384 /* 1.0f in Q14 */, full_w_down ) ) ); + w[1][2 * k + l] = add( w[0][2 * k + l], mult( 23170 /*sqrt(2.0f in Q14)*/, sub( 16384 /* 1.0f in Q14 */, full_w_down ) ) ); /* Q13 */ move16(); } } @@ -909,20 +909,20 @@ static void apply_dmx_weights_fx( { FOR( i = sfbConf->sfbOffset[b]; i < sfbConf->sfbOffset[b + 1]; i++ ) { - x[ch][0][i] = L_shl( Mpy_32_16_1( x[ch][0][i], w[ch][0] ), 2 ); + x[ch][0][i] = L_shl( Mpy_32_16_1( x[ch][0][i], w[ch][0] ), 2 ); /* Q11 */ move32(); } } ELSE { - start = sfbConf->sfbOffset[b]; + start = sfbConf->sfbOffset[b]; /* Q0 */ move16(); - stop = sfbConf->sfbOffset[b + 1]; + stop = sfbConf->sfbOffset[b + 1]; /* Q0 */ move16(); IF( !tcx_10_only ) /* TCX20 band config is used */ { - start = shr( start, 1 ); - stop = shr( stop, 1 ); + start = shr( start, 1 ); /* Q0 */ + stop = shr( stop, 1 ); /* Q0 */ } FOR( k = 0; k < NB_DIV; k++ ) @@ -935,7 +935,7 @@ static void apply_dmx_weights_fx( } ELSE { - w_idx = shl( k, 1 ); + w_idx = shl( k, 1 ); /* Q0 */ move16(); } @@ -943,30 +943,30 @@ static void apply_dmx_weights_fx( { FOR( i = start; i < stop; i++ ) { - x[ch][k][i] = L_shl( Mpy_32_16_1( x[ch][k][i], w[ch][w_idx] ), 2 ); + x[ch][k][i] = L_shl( Mpy_32_16_1( x[ch][k][i], w[ch][w_idx] ), 2 ); /* Q11 */ move32(); } } ELSE /* TCX_5 */ { - start_tcx5 = stop_tcx5; + start_tcx5 = stop_tcx5; /* Q0 */ move16(); - stop_tcx5 = shr( add( stop, 1 ), 1 ); + stop_tcx5 = shr( add( stop, 1 ), 1 ); /* Q0 */ FOR( i = start_tcx5; i < stop_tcx5; i++ ) { - x[ch][k][i] = L_shl( Mpy_32_16_1( x[ch][k][i], w[ch][w_idx] ), 2 ); + x[ch][k][i] = L_shl( Mpy_32_16_1( x[ch][k][i], w[ch][w_idx] ), 2 ); /* Q11 */ move32(); } IF( EQ_16( nsub2[k], 2 ) ) { - w_idx = add( w_idx, 1 ); + w_idx = add( w_idx, 1 ); /* Q0 */ } FOR( i = start_tcx5; i < stop_tcx5; i++ ) { - x[ch][k][add( i, shr( frameSize, 2 ) )] = L_shl( Mpy_32_16_1( x[ch][k][add( i, shr( frameSize, 2 ) )], w[ch][w_idx] ), 2 ); + x[ch][k][i + ( frameSize >> 2 )] = L_shl( Mpy_32_16_1( x[ch][k][i + ( frameSize >> 2 )], w[ch][w_idx] ), 2 ); /* Q11 */ move32(); } } @@ -988,7 +988,7 @@ static void apply_dmx_weights_fx( static void run_min_stats_fx( Decoder_State **sts, - Word32 *x[CPE_CHANNELS][NB_DIV], /* i/o: MDCT Spectrum */ + Word32 *x[CPE_CHANNELS][NB_DIV], /* i/o: MDCT Spectrum exp(x_e)*/ Word16 x_e[CPE_CHANNELS][NB_DIV] ) { Word16 ch, will_estimate_noise_on_channel[CPE_CHANNELS], save_VAD[CPE_CHANNELS]; @@ -1000,16 +1000,16 @@ static void run_min_stats_fx( /* Check if the minimum statistics would run on the respective channels. They are run on inactive TCX20 channels */ test(); test(); - will_estimate_noise_on_channel[0] = EQ_16( sts[0]->core, TCX_20_CORE ) && !sts[0]->VAD; - will_estimate_noise_on_channel[1] = EQ_16( sts[1]->core, TCX_20_CORE ) && !sts[1]->VAD; + will_estimate_noise_on_channel[0] = EQ_16( sts[0]->core, TCX_20_CORE ) && !sts[0]->VAD; /* Q0 */ + will_estimate_noise_on_channel[1] = EQ_16( sts[1]->core, TCX_20_CORE ) && !sts[1]->VAD; /* Q0 */ test(); test(); move16(); move16(); - save_VAD[0] = sts[0]->VAD; + save_VAD[0] = sts[0]->VAD; /* Q0 */ move16(); - save_VAD[1] = sts[1]->VAD; + save_VAD[1] = sts[1]->VAD; /* Q0 */ move16(); /* The first loop calculates the power spectra needed in the minimum statistics (MS) noise estimation. This is only needed if the MS @@ -1030,13 +1030,13 @@ static void run_min_stats_fx( otherwise, use other channel's signal */ IF( will_estimate_noise_on_channel[ch] ) { - spec_in = &x[ch][0][0]; + spec_in = &x[ch][0][0]; /* exp(x_e) */ spec_e = x_e[ch][0]; move16(); } ELSE { - spec_in = &x[( ch + 1 ) % 2][0][0]; + spec_in = &x[( ch + 1 ) % 2][0][0]; /* exp(x_e) */ spec_e = x_e[( ch + 1 ) % 2][0]; move16(); /* patch VAD to zero so that estimation runs, will later be restored */ @@ -1062,15 +1062,15 @@ static void run_min_stats_fx( power_spec_e = sub( add( 4, shl( spec_e, 1 ) ), tmp16 ); } - Copy_Scale_sig32_16( power_spec, power_spec_16, L_FRAME16k, 0 ); + Copy_Scale_sig32_16( power_spec, power_spec_16, L_FRAME16k, 0 ); /* exp(power_spec_e) */ noisy_speech_detection_fx( st->hFdCngDec, st->VAD && st->m_frame_type == ACTIVE_FRAME, power_spec_16, sub( 15, power_spec_e ) ); - st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx = L_add( Mpy_32_32( Q31_0_99, st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx ), Mpy_32_32( st->hFdCngDec->hFdCngCom->flag_noisy_speech, Q31_0_01 ) ); - st->hFdCngDec->hFdCngCom->likelihood_noisy_speech = extract_h( st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx ); + st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx = L_add( Mpy_32_32( Q31_0_99, st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx ), Mpy_32_32( st->hFdCngDec->hFdCngCom->flag_noisy_speech, Q31_0_01 ) ); /* q_likelihood_noisy_speech */ + st->hFdCngDec->hFdCngCom->likelihood_noisy_speech = extract_h( st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx ); /* q_likelihood_noisy_speech - 16 */ move32(); move32(); - st->lp_noise = st->hFdCngDec->lp_noise; + st->lp_noise = st->hFdCngDec->lp_noise; /* Q9.23 */ move32(); } @@ -1092,7 +1092,7 @@ static void run_min_stats_fx( } /* restore VAD (see above) */ - st->VAD = save_VAD[ch]; + st->VAD = save_VAD[ch]; /* Q0 */ move16(); } diff --git a/lib_enc/SNR_calc_fx.c b/lib_enc/SNR_calc_fx.c index 674467cf4f6b249b5805f5a9865f11aeea324d88..320a68d255f539a42d1f543642c5abcd85a10863 100644 --- a/lib_enc/SNR_calc_fx.c +++ b/lib_enc/SNR_calc_fx.c @@ -72,15 +72,15 @@ void calc_lf_snr_fx( * *-------------------------------------------------------------------*/ void calc_lt_snr_fx( - VAD_CLDFB_HANDLE_FX hVAD_CLDFB, /* i/o: CLDFB VAD state */ - Word32 *lt_snr_org_fp, /* o : original long time SNR*/ - Word32 *lt_snr_fp, /* o : long time SNR calculated by fg_energy and bg_energy*/ - Word32 fg_energy, /* i : foreground energy sum */ - Word16 fg_energy_count, /* i : amount of the foreground energy frame */ - Word32 bg_energy, /* i : background energy sum */ - Word16 bg_energy_count, /* i : amount of the background energy frame */ - Word16 bw_index, /* i : band width index*/ - Word16 lt_noise_sp_center0 /* i : long time noise spectral center by 0*/ + VAD_CLDFB_HANDLE hVAD_CLDFB, /* i/o: CLDFB VAD state */ + Word32 *lt_snr_org_fp, /* o : original long time SNR*/ + Word32 *lt_snr_fp, /* o : long time SNR calculated by fg_energy and bg_energy*/ + Word32 fg_energy, /* i : foreground energy sum */ + Word16 fg_energy_count, /* i : amount of the foreground energy frame */ + Word32 bg_energy, /* i : background energy sum */ + Word16 bg_energy_count, /* i : amount of the background energy frame */ + Word16 bw_index, /* i : band width index*/ + Word16 lt_noise_sp_center0 /* i : long time noise spectral center by 0*/ ) { Word16 tmp_lt_noise_sp_center; @@ -229,12 +229,12 @@ void calc_snr_flux_fx( * *-------------------------------------------------------------------*/ void snr_calc( - VAD_CLDFB_HANDLE_FX hVAD_CLDFB, /* i/o: CLDFB VAD state */ - const Word16 sacle_sbpower, /* i : the Scaling of sbpower*/ - Word32 *snr, /* o : frequency domain SNR */ - Word32 *tsnr, /* o : time domain SNR */ - const Word32 frame_energy, /* i : current frame energy */ - const Word32 bwidth /* i : audio band width*/ + VAD_CLDFB_HANDLE hVAD_CLDFB, /* i/o: CLDFB VAD state */ + const Word16 sacle_sbpower, /* i : the Scaling of sbpower*/ + Word32 *snr, /* o : frequency domain SNR */ + Word32 *tsnr, /* o : time domain SNR */ + const Word32 frame_energy, /* i : current frame energy */ + const Word32 bwidth /* i : audio band width*/ ) { Word32 i; diff --git a/lib_enc/comvad_decision_fx.c b/lib_enc/comvad_decision_fx.c index 98816e768d91e0666a6fade90f54a9201054fa04..505e18326fb3483811fef7a6904da7b22a9d68b4 100644 --- a/lib_enc/comvad_decision_fx.c +++ b/lib_enc/comvad_decision_fx.c @@ -394,7 +394,7 @@ static Word16 comvad_hangover( Word16 comvad_decision_fx( - VAD_CLDFB_HANDLE_FX hVAD_CLDFB, /* i/o: CLDFB VAD state */ + VAD_CLDFB_HANDLE hVAD_CLDFB, /* i/o: CLDFB VAD state */ const Word32 l_snr, /* i : long time frequency domain*/ const Word32 lt_snr_org, /* i : original long time SNR*/ const Word32 lt_snr, /* i : long time SNR calculated by fg_energy and bg_energy*/ diff --git a/lib_enc/core_enc_init.c b/lib_enc/core_enc_init.c index 4599d1d113ebc989ee35e4aff47b04e617874fdb..8c01fae3ba09d4fa482e53cc958000473d655948 100644 --- a/lib_enc/core_enc_init.c +++ b/lib_enc/core_enc_init.c @@ -386,6 +386,11 @@ void init_coder_ace_plus( st->acelpFramesCount = 0; #ifndef IVAS_FLOAT_FIXED st->prevTempFlatness = 1.0f; +#endif +#ifdef IVAS_FLOAT_FIXED +#ifdef MSAN_FIX + st->prevTempFlatness_fx = 128; // Q7 +#endif #endif } diff --git a/lib_enc/energy_fx.c b/lib_enc/energy_fx.c index 4bd16df2e21b8f85a1bf87ca66e6e568b0ef80fd..054245a6d288b432c1c5b5107d52f713ce9ed4d6 100644 --- a/lib_enc/energy_fx.c +++ b/lib_enc/energy_fx.c @@ -212,11 +212,11 @@ static void update_sb_bg_energy( * *-------------------------------------------------------------------*/ void background_update_fx( - VAD_CLDFB_HANDLE_FX hVAD_CLDFB, /* i/o: CLDFB VAD state */ - Word16 scale, /* i : the scaling of frame energy*/ - Word32 frame_energy, /* i : current frame energy*/ - Word32 update_flag, /* i : update flag*/ - Word16 music_backgound_f, /* i : background music flag*/ + VAD_CLDFB_HANDLE hVAD_CLDFB, /* i/o: CLDFB VAD state */ + Word16 scale, /* i : the scaling of frame energy*/ + Word32 frame_energy, /* i : current frame energy*/ + Word32 update_flag, /* i : update flag*/ + Word16 music_backgound_f, /* i : background music flag*/ Word32 snr ) { Word32 tmp; diff --git a/lib_enc/frame_spec_dif_cor_rate_fx.c b/lib_enc/frame_spec_dif_cor_rate_fx.c index c7fa5eb1cab5d0ca8b4c15038cb232529d6ffc05..117ced6baf87ef4209f4d88104b659e4b4c84856 100644 --- a/lib_enc/frame_spec_dif_cor_rate_fx.c +++ b/lib_enc/frame_spec_dif_cor_rate_fx.c @@ -20,10 +20,10 @@ * *-------------------------------------------------------------------*/ void frame_spec_dif_cor_rate_fx( - VAD_CLDFB_HANDLE_FX hVAD_CLDFB, /* i/o: CLDFB VAD state */ - Word32 *spec_amp, /* i : spectral amplitude*/ - Word16 sacle, /* i : the scaling of spec_amp*/ - Word16 f_tonality_rate[3] /* o : tonality rate*/ + VAD_CLDFB_HANDLE hVAD_CLDFB, /* i/o: CLDFB VAD state */ + Word32 *spec_amp, /* i : spectral amplitude*/ + Word16 sacle, /* i : the scaling of spec_amp*/ + Word16 f_tonality_rate[3] /* o : tonality rate*/ ) { diff --git a/lib_enc/init_enc.c b/lib_enc/init_enc.c index 31fa376de14ed1f33added6c9553abdc2e38aff1..5c23fee656b6aa5ef6ab41054bd7b2400e2fee2e 100644 --- a/lib_enc/init_enc.c +++ b/lib_enc/init_enc.c @@ -482,7 +482,11 @@ ivas_error init_encoder( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for CLDFB VAD\n" ) ); } +#ifndef IVAS_FLOAT_FIXED vad_init( st->hVAD_CLDFB ); +#else + vad_init_fx( st->hVAD_CLDFB ); +#endif } else { @@ -1628,15 +1632,16 @@ ivas_error init_encoder_ivas_fx( /* CLDFB-based VAD */ IF( st->element_mode == EVS_MONO ) { - IF( ( st->hVAD_CLDFB = (VAD_CLDFB_HANDLE) malloc( sizeof( T_CldfbVadState ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for CLDFB VAD\n" ) ); - } + /* This is done to as in EVS T_CldfbVadState structure is present in Encoder State */ + /* + if ( ( st->hVAD_CLDFB = (VAD_CLDFB_HANDLE) malloc( sizeof( T_CldfbVadState ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for CLDFB VAD\n" ) ); + } + */ + st->hVAD_CLDFB = &st->vad_st; - vad_init_ivas_fx( st->hVAD_CLDFB ); -#if 1 - vad_init( st->hVAD_CLDFB ); -#endif + vad_init_fx( st->hVAD_CLDFB ); } ELSE { diff --git a/lib_enc/ivas_core_pre_proc_front.c b/lib_enc/ivas_core_pre_proc_front.c index d23b068e8a6c5dbe276151ab403d16eeae4c2f2a..f7659715c5075cb100ff2a0818fa196a9afad38c 100644 --- a/lib_enc/ivas_core_pre_proc_front.c +++ b/lib_enc/ivas_core_pre_proc_front.c @@ -1854,11 +1854,17 @@ ivas_error pre_proc_front_ivas_fx( Word16 q_band_energies_LR = Q_factor_arrL( band_energies_LR, 2 * NB_BANDS ); band_energies_LR_fx_exp = 31 - q_band_energies_LR; floatToFixed_arrL( band_energies_LR, band_energies_LR_fx, ( 31 - band_energies_LR_fx_exp ), 2 * NB_BANDS ); - +#ifdef MSAN_FIX + Word16 q_enerBuffer = Q_factor_arrL( enerBuffer, st->cldfbAnaEnc->no_channels ); +#else Word16 q_enerBuffer = Q_factor_arrL( enerBuffer, CLDFB_NO_CHANNELS_MAX ); +#endif enerBuffer_fx_exp = 31 - q_enerBuffer; +#ifdef MSAN_FIX + floatToFixed_arrL( enerBuffer, enerBuffer_fx_loc, ( 31 - enerBuffer_fx_exp ), st->cldfbAnaEnc->no_channels ); +#else floatToFixed_arrL( enerBuffer, enerBuffer_fx_loc, ( 31 - enerBuffer_fx_exp ), CLDFB_NO_CHANNELS_MAX ); - +#endif Word16 normmsPeriodog = Q_factor_arrL( st->hFdCngEnc->msPeriodog, NPART ); st->hFdCngEnc->msPeriodog_fx_exp = 31 - normmsPeriodog; st->hFdCngEnc->msPeriodog_fx_exp_cldfb = 31 - normmsPeriodog; @@ -1869,7 +1875,11 @@ ivas_error pre_proc_front_ivas_fx( Word16 normmsNoiseEst = Q_factor_arrL( st->hFdCngEnc->msNoiseEst, NPART ); st->hFdCngEnc->msNoiseEst_fx_exp = 31 - normmsNoiseEst; floatToFixed_arrL( st->hFdCngEnc->msNoiseEst, st->hFdCngEnc->msNoiseEst_fx, 31 - st->hFdCngEnc->msNoiseEst_fx_exp, NPART ); +#ifdef MSAN_FIX + floatToFixed_arr( st->hFdCngEnc->hFdCngCom->CLDFBpsize_inv_flt, st->hFdCngEnc->hFdCngCom->CLDFBpsize_inv, 15, st->hFdCngEnc->hFdCngCom->nCLDFBpart ); +#else floatToFixed_arr( st->hFdCngEnc->hFdCngCom->CLDFBpsize_inv_flt, st->hFdCngEnc->hFdCngCom->CLDFBpsize_inv, 15, NPARTCLDFB ); +#endif #endif perform_noise_estimation_enc_ivas_fx( band_energies_LR_fx, band_energies_LR_fx_exp, enerBuffer_fx_loc, enerBuffer_fx_exp, st->hFdCngEnc, input_Fs, hCPE ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS @@ -1888,12 +1898,17 @@ ivas_error pre_proc_front_ivas_fx( Word16 q_band_energies = Q_factor_arrL( band_energies, 2 * NB_BANDS ); band_energies_fx_exp = 31 - q_band_energies; floatToFixed_arrL( band_energies, band_energies_fx, ( 31 - band_energies_fx_exp ), 2 * NB_BANDS ); - - +#ifdef MSAN_FIX + Word16 q_enerBuffer = Q_factor_arrL( enerBuffer, st->cldfbAnaEnc->no_channels ); +#else Word16 q_enerBuffer = Q_factor_arrL( enerBuffer, CLDFB_NO_CHANNELS_MAX ); +#endif enerBuffer_fx_exp = 31 - q_enerBuffer; +#ifdef MSAN_FIX + floatToFixed_arrL( enerBuffer, enerBuffer_fx_loc, ( 31 - enerBuffer_fx_exp ), st->cldfbAnaEnc->no_channels ); +#else floatToFixed_arrL( enerBuffer, enerBuffer_fx_loc, ( 31 - enerBuffer_fx_exp ), CLDFB_NO_CHANNELS_MAX ); - +#endif Word16 normmsPeriodog = Q_factor_arrL( st->hFdCngEnc->msPeriodog, NPART ); st->hFdCngEnc->msPeriodog_fx_exp = 31 - normmsPeriodog; st->hFdCngEnc->msPeriodog_fx_exp_cldfb = 31 - normmsPeriodog; @@ -1904,8 +1919,11 @@ ivas_error pre_proc_front_ivas_fx( Word16 normmsNoiseEst = Q_factor_arrL( st->hFdCngEnc->msNoiseEst, NPART ); st->hFdCngEnc->msNoiseEst_fx_exp = 31 - normmsNoiseEst; floatToFixed_arrL( st->hFdCngEnc->msNoiseEst, st->hFdCngEnc->msNoiseEst_fx, 31 - st->hFdCngEnc->msNoiseEst_fx_exp, NPART ); +#ifdef MSAN_FIX + floatToFixed_arr( st->hFdCngEnc->hFdCngCom->CLDFBpsize_inv_flt, st->hFdCngEnc->hFdCngCom->CLDFBpsize_inv, 15, st->hFdCngEnc->hFdCngCom->nCLDFBpart ); +#else floatToFixed_arr( st->hFdCngEnc->hFdCngCom->CLDFBpsize_inv_flt, st->hFdCngEnc->hFdCngCom->CLDFBpsize_inv, 15, NPARTCLDFB ); - +#endif Word16 normmsperiodog = Q_factor_arrL( st->hFdCngEnc->hFdCngCom->periodog_flt, PERIODOGLEN ); st->hFdCngEnc->hFdCngCom->exp_cldfb_periodog = 31 - normmsperiodog; // floatToFixed_arrL( st->hFdCngEnc->hFdCngCom->periodog_flt, st->hFdCngEnc->hFdCngCom->periodog, 31 - st->hFdCngEnc->hFdCngCom->exp_cldfb_periodog, PERIODOGLEN); diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index 97f13701f738c9a77dcae57f8aa99bcfc4398f88..8ba98f4fda362c670fa243d8e15a9e4463bf4c7c 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -707,7 +707,6 @@ ivas_error ivas_cpe_enc( floatToFixed_arr( &hCPE->hStereoDft->input_mem_itd[i][0], &hCPE->hStereoDft->input_mem_itd_fx[i][0], hCPE->hStereoDft->q_input_mem_itd[i], STEREO_DFT_OVL_MAX ); #endif // MSAN_FIX } - floatToFixed_arrL( hCPE->hStereoDft->hItd->itd, hCPE->hStereoDft->hItd->itd_fx, 16, STEREO_DFT_ENC_DFT_NB ); #ifndef MSAN_FIX hCPE->hStereoClassif->xtalk_score_fx = floatToFixed( hCPE->hStereoClassif->xtalk_score, 31 ); #endif // !MSAN_FIX @@ -853,8 +852,6 @@ ivas_error ivas_cpe_enc( floatToFixed_arr( sts[i]->old_input_signal, sts[i]->old_input_signal_fx, sts[i]->q_inp, 1965 ); floatToFixed_arr( &hCPE->input_mem[i][0], &hCPE->input_mem_fx[i][0], hCPE->q_input_mem[i], NS2SA( input_Fs, STEREO_DFT_OVL_NS ) ); } - floatToFixed_arrL( hCPE->hStereoMdct->hItd->itd, hCPE->hStereoMdct->hItd->itd_fx, 16, STEREO_DFT_ENC_DFT_NB ); - floatToFixed_arrL( hCPE->hStereoMdct->hItd->deltaItd, hCPE->hStereoMdct->hItd->deltaItd_fx, 16, STEREO_DFT_ENC_DFT_NB ); floatToFixed_arr( hCPE->hCoreCoder[0]->voicing, hCPE->hCoreCoder[0]->voicing_fx, 15, 3 ); if ( hCPE->element_mode == IVAS_CPE_DFT && hCPE->hStereoDft->res_cod_mode[STEREO_DFT_OFFSET] ) { @@ -866,7 +863,6 @@ ivas_error ivas_cpe_enc( #ifdef IVAS_FLOAT_FIXED_CONVERSIONS if ( hCPE->hStereoMdct != NULL && hCPE->hStereoMdct->hItd != NULL ) { - fixedToFloat_arrL( hCPE->hStereoMdct->hItd->itd_fx, hCPE->hStereoMdct->hItd->itd, 16, STEREO_DFT_ENC_DFT_NB ); FOR( int16_t i = 0; i < CPE_CHANNELS; i++ ) { fixedToFloat_arr( &hCPE->input_mem_fx[i][0], &hCPE->input_mem[i][0], hCPE->q_input_mem[i], NS2SA( input_Fs, STEREO_DFT_OVL_NS ) ); @@ -939,8 +935,6 @@ ivas_error ivas_cpe_enc( fixedToFloat_arr( &hCPE->input_mem_fx[i][0], &hCPE->input_mem[i][0], hCPE->q_input_mem[i], NS2SA( input_Fs, STEREO_DFT_OVL_NS ) ); me2f_buf( hCPE->hStereoDft->DFT_fx[i], hCPE->hStereoDft->DFT_fx_e[i], hCPE->hStereoDft->DFT[i], STEREO_DFT_N_MAX_ENC ); } - fixedToFloat_arrL( hCPE->hStereoDft->hItd->itd_fx, hCPE->hStereoDft->hItd->itd, 16, STEREO_DFT_ENC_DFT_NB ); - /*local fix2flt*/ for ( i = 0; i < STEREO_DFT_BAND_MAX; i++ ) @@ -2333,8 +2327,9 @@ ivas_error create_cpe_enc( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for stereo classifier structure\n" ) ); } +#ifndef IVAS_FLOAT_FIXED stereo_classifier_init( hCPE->hStereoClassif ); -#ifdef IVAS_FLOAT_FIXED +#else stereo_classifier_init_fx( hCPE->hStereoClassif ); #endif @@ -2361,7 +2356,11 @@ ivas_error create_cpe_enc( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for CoreCoder structure\n" ) ); } +#ifdef IVAS_FLOAT_FIXED + copy_encoder_config_fx( st_ivas, st, 1 ); +#else copy_encoder_config( st_ivas, st, 1 ); +#endif st->total_brate = hCPE->element_brate / ( st_ivas->nCPE > 1 ? 1 : CPE_CHANNELS ); /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ st->mct_chan_mode = MCT_CHAN_MODE_REGULAR; @@ -2615,9 +2614,10 @@ ivas_error create_cpe_enc_fx( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for stereo classifier structure\n" ) ); } - stereo_classifier_init_fx( hCPE->hStereoClassif ); -#if 1 // TODO: To be removed later +#ifndef IVAS_FLOAT_FIXED stereo_classifier_init( hCPE->hStereoClassif ); +#else + stereo_classifier_init_fx( hCPE->hStereoClassif ); #endif /*-----------------------------------------------------------------* diff --git a/lib_enc/ivas_dirac_enc.c b/lib_enc/ivas_dirac_enc.c index 14125546c2959f8c50c353ed7af29bc4cc23798a..1738910de7056978e46077276f04e4d1f0303543 100644 --- a/lib_enc/ivas_dirac_enc.c +++ b/lib_enc/ivas_dirac_enc.c @@ -1523,13 +1523,18 @@ void ivas_dirac_param_est_enc( Word32 azi_secs_fx[2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS]; Word32 ele_secs_fx[2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS]; Word32 diff_secs_fx[2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS]; + Word16 diff_secs_exp[2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS]; Word32 ene_secs_fx[2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS]; + Word16 ene_secs_exp[2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS]; push_wmops( "dirac_enc_param_est" ); num_freq_bands = hDirAC->hConfig->nbands; move16(); /* Initialization */ + cldfb_q = 0; + move16(); + l_ts = idiv1616( input_frame, MAX_PARAM_SPATIAL_SUBFRAMES ); IF( useLowerRes ) { @@ -1553,7 +1558,9 @@ void ivas_dirac_param_est_enc( set_zero_fx( azi_secs_fx, 2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS ); set_zero_fx( ele_secs_fx, 2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS ); set_zero_fx( diff_secs_fx, 2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS ); + set16_zero_fx( diff_secs_exp, 2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS ); set_zero_fx( ene_secs_fx, 2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS ); + set16_zero_fx( ene_secs_exp, 2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS ); /* Copy current frame to memory for delay compensation */ #ifdef IVAS_FLOAT_FIXED_CONVERSIONS @@ -1986,6 +1993,61 @@ void ivas_dirac_param_est_enc( if ( hodirac_flag ) { +#ifdef IVAS_FLOAT_FIXED + +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + for ( i = 0; i < NUM_ANA_SECTORS; i++ ) + { + for ( int j = 0; j < IVAS_MAX_NUM_BANDS; j++ ) + { + f2me( hDirAC->sec_I_vec_smth_x[i][j], &hDirAC->sec_I_vec_smth_x_fx[i][j], &hDirAC->sec_I_vec_smth_x_exp[i][j] ); + f2me( hDirAC->sec_I_vec_smth_y[i][j], &hDirAC->sec_I_vec_smth_y_fx[i][j], &hDirAC->sec_I_vec_smth_y_exp[i][j] ); + f2me( hDirAC->sec_I_vec_smth_z[i][j], &hDirAC->sec_I_vec_smth_z_fx[i][j], &hDirAC->sec_I_vec_smth_z_exp[i][j] ); + } + } + for ( i = 0; i < NUM_ANA_SECTORS * IVAS_MAX_NUM_BANDS; i++ ) + { + hDirAC->azi_prev_fx[i] = float_to_fix( hDirAC->azi_prev[i], Q23 ); + hDirAC->ele_prev_fx[i] = float_to_fix( hDirAC->ele_prev[i], Q23 ); + } +#endif + calculate_hodirac_sector_parameters_fx( + hDirAC, + Cldfb_RealBuffer_fx, + Cldfb_ImagBuffer_fx, + cldfb_q, + HODIRAC_BETA, + hDirAC->band_grouping, + hDirAC->hConfig->nbands, + hDirAC->hConfig->enc_param_start_band, + azi_secs_fx, + ele_secs_fx, + diff_secs_fx, + diff_secs_exp, + ene_secs_fx, + ene_secs_exp ); + +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + const int N_bands = hDirAC->hConfig->nbands; + for ( int i_sec = 0; i_sec < NUM_ANA_SECTORS; i_sec++ ) + { + for ( int i_band = hDirAC->hConfig->enc_param_start_band; i_band < N_bands; i_band++ ) + { + hDirAC->azi_prev[i_sec * N_bands + i_band] = fix_to_float( hDirAC->azi_prev_fx[i_sec * N_bands + i_band], Q23 ); + hDirAC->ele_prev[i_sec * N_bands + i_band] = fix_to_float( hDirAC->ele_prev_fx[i_sec * N_bands + i_band], Q23 ); + azi_secs[i_sec * N_bands + i_band] = fix_to_float( azi_secs_fx[i_sec * N_bands + i_band], Q23 ); + ele_secs[i_sec * N_bands + i_band] = fix_to_float( ele_secs_fx[i_sec * N_bands + i_band], Q23 ); + ene_secs[i_sec * N_bands + i_band] = me2f( ene_secs_fx[i_sec * N_bands + i_band], ene_secs_exp[i_sec * N_bands + i_band] ); + hDirAC->sec_I_vec_smth_x[i_sec][i_band] = me2f( hDirAC->sec_I_vec_smth_x_fx[i_sec][i_band], hDirAC->sec_I_vec_smth_x_exp[i_sec][i_band] ); + hDirAC->sec_I_vec_smth_y[i_sec][i_band] = me2f( hDirAC->sec_I_vec_smth_y_fx[i_sec][i_band], hDirAC->sec_I_vec_smth_y_exp[i_sec][i_band] ); + hDirAC->sec_I_vec_smth_z[i_sec][i_band] = me2f( hDirAC->sec_I_vec_smth_z_fx[i_sec][i_band], hDirAC->sec_I_vec_smth_z_exp[i_sec][i_band] ); + hDirAC->energy_smth[i_sec][i_band] = me2f( hDirAC->energy_smth_fx[i_sec][i_band], hDirAC->energy_smth_exp[i_sec][i_band] ); + diff_secs[i_sec * N_bands + i_band] = me2f( diff_secs_fx[i_sec * N_bands + i_band], diff_secs_exp[i_sec * N_bands + i_band] ); + } + } +#endif + +#else calculate_hodirac_sector_parameters( hDirAC, Cldfb_RealBuffer, @@ -1998,6 +2060,7 @@ void ivas_dirac_param_est_enc( ele_secs, diff_secs, ene_secs ); +#endif } if ( hodirac_flag ) diff --git a/lib_enc/ivas_front_vad.c b/lib_enc/ivas_front_vad.c index e7b20b757f475c59550d5e253d197d7f69393b85..61e8f6e62c1288611e6622d63a47d230ee3903b8 100644 --- a/lib_enc/ivas_front_vad.c +++ b/lib_enc/ivas_front_vad.c @@ -1034,7 +1034,9 @@ ivas_error front_vad_spar( floatToFixed_arr( wsp, wsp_fx, Q8, 368 ); floatToFixed_arr( st->old_wsp2, st->old_wsp2_fx, Q8, 115 ); floatToFixed_arr( st->mem_decim2, st->mem_decim2_fx, Q8, 3 ); - // st->old_corr_fx = (Word16)floatToFixed( st->old_corr, Q15 ); +#ifdef MSAN_FIX + st->old_corr_fx = (Word16) floatToFixed( st->old_corr, Q15 ); +#endif corr_shift_fx = (Word16) floatToFixed( corr_shift, Q15 ); // st->old_thres_fx = (Word16) floatToFixed( st->old_thres, Q15 ); relE_fx = (Word16) floatToFixed( relE, Q8 ); diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index e48d2983dada813492b6517c5b4c114faa20bf97..215ede7165668612b009bc8379f06c80ca7a055f 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -373,6 +373,7 @@ void ivas_write_format_sid_fx( *-------------------------------------------------------------------*/ /*! r: number of channels to be analysed */ +#ifndef IVAS_FLOAT_FIXED int16_t getNumChanAnalysis( Encoder_Struct *st_ivas /* i : IVAS encoder structure */ ) @@ -407,8 +408,7 @@ int16_t getNumChanAnalysis( return n; } - -#ifdef IVAS_FLOAT_FIXED +#else Word16 getNumChanAnalysis_fx( Encoder_Struct *st_ivas /* i : IVAS encoder structure */ ) @@ -492,6 +492,12 @@ void copy_encoder_config( return; } #ifdef IVAS_FLOAT_FIXED +/*-------------------------------------------------------------------* + * copy_encoder_config_fx() + * + * Copy configuration structrue to the state structrure + *-------------------------------------------------------------------*/ + void copy_encoder_config_fx( Encoder_Struct *st_ivas, /* i : IVAS encoder structure */ Encoder_State *st_fx, /* o : encoder state structure */ @@ -1224,7 +1230,11 @@ ivas_error ivas_init_encoder( *-----------------------------------------------------------------*/ /* set number of input channels used for analysis/coding */ +#ifndef IVAS_FLOAT_FIXED n = getNumChanAnalysis( st_ivas ); +#else + n = getNumChanAnalysis_fx( st_ivas ); +#endif if ( n > 0 ) { @@ -1972,7 +1982,8 @@ void destroy_core_enc( IF( hCoreCoder->hVAD_CLDFB != NULL ) { - free( hCoreCoder->hVAD_CLDFB ); + /* This is not required as we are not allocating memory dynamically */ + // free( hCoreCoder->hVAD_CLDFB ); hCoreCoder->hVAD_CLDFB = NULL; } diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index 302f263afb05ebc79af54502d9954c62cb4748bd..e867ae327ae1fbcd393b3e86c9a903692e345f63 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -41,6 +41,7 @@ #include "prot.h" #ifdef IVAS_FLOAT_FIXED #include "prot_fx.h" +#include "prot_fx_enc.h" #include "ivas_prot_fx.h" #endif #ifdef IVAS_FLOAT_FIXED @@ -87,15 +88,16 @@ static void compensate_energy_ratios( MASA_ENCODER_HANDLE hMasa ); #ifdef IVAS_FLOAT_FIXED static Word16 encode_lfe_to_total_energy_ratio_fx( MASA_ENCODER_HANDLE hMasa, BSTR_ENC_HANDLE hMetaData, const Word32 ivas_total_brate ); + +static void ivas_encode_masaism_metadata_fx( MASA_ENCODER_HANDLE hMasa, IVAS_QMETADATA_HANDLE hQMetaData, BSTR_ENC_HANDLE hMetaData, ISM_METADATA_HANDLE hIsmMeta[], const Word16 nchan_ism, const Word16 low_bitrate_mode, const Word16 omasa_nbands, const Word16 omasa_nblocks, const Word16 idx_separated_object, const Word16 ism_imp ); + +static void reduce_metadata_further_fx( MASA_ENCODER_HANDLE hMasa, IVAS_QMETADATA_HANDLE hqmetadata, const IVAS_FORMAT ivas_format ); #else static int16_t encode_lfe_to_total_energy_ratio( MASA_ENCODER_HANDLE hMasa, BSTR_ENC_HANDLE hMetaData, const int32_t ivas_total_brate ); -#endif static void ivas_encode_masaism_metadata( MASA_ENCODER_HANDLE hMasa, IVAS_QMETADATA_HANDLE hQMetaData, BSTR_ENC_HANDLE hMetaData, ISM_METADATA_HANDLE hIsmMeta[], const int16_t nchan_ism, const int16_t low_bitrate_mode, const int16_t omasa_nbands, const int16_t omasa_nblocks, const int16_t idx_separated_object, const int16_t ism_imp ); -#ifndef IVAS_FLOAT_FIXED + static void reduce_metadata_further( MASA_ENCODER_HANDLE hMasa, IVAS_QMETADATA_HANDLE hqmetadata, const IVAS_FORMAT ivas_format ); -#else -static void reduce_metadata_further_fx( MASA_ENCODER_HANDLE hMasa, IVAS_QMETADATA_HANDLE hqmetadata, const IVAS_FORMAT ivas_format ); #endif #ifdef IVAS_FLOAT_FIXED @@ -828,7 +830,7 @@ ivas_error ivas_masa_encode( #ifdef IVAS_FLOAT_FIXED test(); - IF( hMasa->config.max_metadata_bits < MINIMUM_BIT_BUDGET_NORMAL_META && !hMasa->config.joinedSubframes ) + IF( LT_16( hMasa->config.max_metadata_bits, MINIMUM_BIT_BUDGET_NORMAL_META ) && !hMasa->config.joinedSubframes ) { reduce_metadata_further_fx( hMasa, hQMetaData, ivas_format ); @@ -838,6 +840,55 @@ ivas_error ivas_masa_encode( push_next_indice( hMetaData, hQMetaData->q_direction[0].cfg.nblocks == 1 ? 1 : 0, MASA_LOWBITRATE_MODE_BITS ); hQMetaData->metadata_max_bits = sub( hQMetaData->metadata_max_bits, MASA_LOWBITRATE_MODE_BITS ); } +#else + if ( hMasa->config.max_metadata_bits < MINIMUM_BIT_BUDGET_NORMAL_META && !hMasa->config.joinedSubframes ) + { + reduce_metadata_further( hMasa, hQMetaData, ivas_format ); + + low_bitrate_mode = ( ivas_total_brate <= 32000 ); + + /* Write low bitrate mode. 1 signals that we have merged through time, 0 signals merge through frequency. */ + push_next_indice( hMetaData, hQMetaData->q_direction[0].cfg.nblocks == 1 ? 1 : 0, MASA_LOWBITRATE_MODE_BITS ); + hQMetaData->metadata_max_bits -= MASA_LOWBITRATE_MODE_BITS; + } +#endif +#ifdef IVAS_FLOAT_FIXED +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + if ( EQ_32( ivas_format, MASA_ISM_FORMAT ) && EQ_32( ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) ) + { + for ( int sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; ++sf ) + { + for ( int band = 0; band < MASA_FREQUENCY_BANDS; ++band ) + { + hMasa->data.hOmasaData->masa_to_total_energy_ratio_fx[sf][band] = floatToFixed_32( hMasa->data.hOmasaData->masa_to_total_energy_ratio[sf][band], Q30 ); + } + } + } + for ( int obj = 0; obj < nchan_ism; obj++ ) + { + hIsmMetaData[obj]->elevation_fx = floatToFixed( hIsmMetaData[obj]->elevation, Q22 ); + hIsmMetaData[obj]->azimuth_fx = floatToFixed( hIsmMetaData[obj]->azimuth, Q22 ); + hIsmMetaData[obj]->q_elevation_old_fx = floatToFixed( hIsmMetaData[obj]->q_elevation_old, Q22 ); + hIsmMetaData[obj]->q_azimuth_old_fx = floatToFixed( hIsmMetaData[obj]->q_azimuth_old, Q22 ); + } +#endif + + /* Encode MASA+ISM metadata */ + test(); + IF( EQ_32( ivas_format, MASA_ISM_FORMAT ) && EQ_32( ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) ) + { + /* encode MASA/ISM energy ratios */ + ivas_encode_masaism_metadata_fx( hMasa, hQMetaData, hMetaData, hIsmMetaData, nchan_ism, low_bitrate_mode, hOMasa->nCodingBands, hOMasa->nSubframes, idx_separated_object, ism_imp ); + } + ELSE + { + if ( EQ_32( ivas_format, MASA_ISM_FORMAT ) ) + { + hMasa->data.hOmasaData->masa_to_total_energy_ratio_fx[0][0] = -ONE_IN_Q30; /* signals NOT to adjust the energy ratios */ + move32(); + } + } + #ifdef IVAS_FLOAT_FIXED_CONVERSIONS for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) { @@ -855,19 +906,46 @@ ivas_error ivas_masa_encode( } } } -#endif -#else - if ( hMasa->config.max_metadata_bits < MINIMUM_BIT_BUDGET_NORMAL_META && !hMasa->config.joinedSubframes ) + if ( EQ_32( ivas_format, MASA_ISM_FORMAT ) && EQ_32( ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) ) { - reduce_metadata_further( hMasa, hQMetaData, ivas_format ); - - low_bitrate_mode = ( ivas_total_brate <= 32000 ); - - /* Write low bitrate mode. 1 signals that we have merged through time, 0 signals merge through frequency. */ - push_next_indice( hMetaData, hQMetaData->q_direction[0].cfg.nblocks == 1 ? 1 : 0, MASA_LOWBITRATE_MODE_BITS ); - hQMetaData->metadata_max_bits -= MASA_LOWBITRATE_MODE_BITS; + for ( int sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; ++sf ) + { + for ( int band = 0; band < MASA_FREQUENCY_BANDS; ++band ) + { + fixedToFloat_arrL( hMasa->data.hOmasaData->q_energy_ratio_ism_fx[sf][band], hMasa->data.hOmasaData->q_energy_ratio_ism[sf][band], Q30, nchan_ism ); + } + } + for ( int block_m_idx = 0; block_m_idx < hOMasa->nSubframes; block_m_idx++ ) + { + for ( i = 0; i < hOMasa->nbands; i++ ) + { + for ( int k = 0; k < nchan_ism; k++ ) + { + hMasa->data.hOmasaData->energy_ratio_ism[block_m_idx][i][k] = fixedToFloat( hMasa->data.hOmasaData->energy_ratio_ism_fx[block_m_idx][i][k], Q30 ); + } + } + } + } + if ( EQ_32( ivas_format, MASA_ISM_FORMAT ) ) + { + for ( int sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; ++sf ) + { + for ( int band = 0; band < MASA_FREQUENCY_BANDS; ++band ) + { + fixedToFloat_arrL( hMasa->data.hOmasaData->q_energy_ratio_ism_fx[sf][band], hMasa->data.hOmasaData->q_energy_ratio_ism[sf][band], Q30, nchan_ism ); + hMasa->data.hOmasaData->masa_to_total_energy_ratio[sf][band] = fixedToFloat_32( hMasa->data.hOmasaData->masa_to_total_energy_ratio_fx[sf][band], Q30 ); + } + } + } + for ( int obj = 0; obj < nchan_ism; obj++ ) + { + hIsmMetaData[obj]->elevation = fixedToFloat( hIsmMetaData[obj]->elevation_fx, Q22 ); + hIsmMetaData[obj]->azimuth = fixedToFloat( hIsmMetaData[obj]->azimuth_fx, Q22 ); + hIsmMetaData[obj]->q_elevation_old = fixedToFloat( hIsmMetaData[obj]->q_elevation_old_fx, Q22 ); + hIsmMetaData[obj]->q_azimuth_old = fixedToFloat( hIsmMetaData[obj]->q_azimuth_old_fx, Q22 ); } #endif +#else /* Encode MASA+ISM metadata */ if ( ivas_format == MASA_ISM_FORMAT && ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) { @@ -881,6 +959,7 @@ ivas_error ivas_masa_encode( hMasa->data.hOmasaData->masa_to_total_energy_ratio[0][0] = -1; /* signals NOT to adjust the energy ratios */ } } +#endif /* Encode metadata */ masa_total_brate = ivas_total_brate; @@ -4867,7 +4946,11 @@ void ivas_masa_enc_reconfigure( { for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) { +#ifdef IVAS_FLOAT_FIXED + copy_encoder_config_fx( st_ivas, st_ivas->hSCE[sce_id]->hCoreCoder[0], 0 ); +#else copy_encoder_config( st_ivas, st_ivas->hSCE[sce_id]->hCoreCoder[0], 0 ); +#endif st_ivas->hSCE[sce_id]->element_brate = ivas_total_brate / st_ivas->nchan_transport; st_ivas->hSCE[sce_id]->hCoreCoder[0]->total_brate = st_ivas->hSCE[sce_id]->element_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ } @@ -4879,7 +4962,11 @@ void ivas_masa_enc_reconfigure( /* prepare bitstream buffers */ for ( n = 0; n < CPE_CHANNELS; n++ ) { +#ifdef IVAS_FLOAT_FIXED + copy_encoder_config_fx( st_ivas, st_ivas->hCPE[cpe_id]->hCoreCoder[n], 0 ); +#else copy_encoder_config( st_ivas, st_ivas->hCPE[cpe_id]->hCoreCoder[n], 0 ); +#endif st_ivas->hCPE[cpe_id]->hCoreCoder[n]->total_brate = st_ivas->hCPE[cpe_id]->element_brate / ( st_ivas->nCPE > 1 ? 1 : CPE_CHANNELS ); /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ } @@ -6859,7 +6946,7 @@ static void quantize_ratio_ism_vector( return; } #endif - +#ifndef IVAS_FLOAT_FIXED static int16_t index_slice_enum( const int16_t *ratio_ism_idx, const int16_t nchan_ism ) @@ -6901,8 +6988,52 @@ static int16_t index_slice_enum( return index; } +#else +static Word16 index_slice_enum_fx( + const Word16 *ratio_ism_idx, + const Word16 nchan_ism ) +{ + Word16 i; + Word16 x, index; + Word16 base; + + IF( EQ_16( nchan_ism, 2 ) ) + { + index = ratio_ism_idx[0]; + move16(); + } + ELSE + { + x = ratio_ism_idx[nchan_ism - 2]; + base = 10; + move16(); + move16(); + FOR( i = nchan_ism - 3; i >= 0; i-- ) + { + x = add( x, imult1616( ratio_ism_idx[i], base ) ); + base = imult1616( base, 10 ); + } + + index = 0; + i = 0; + move16(); + move16(); + WHILE( LE_16( i, x ) ) + { + IF( valid_ratio_index_fx( i, 7, nchan_ism - 1 ) ) + { + index = add( index, 1 ); + } + i = add( i, 1 ); + } + index = sub( index, 1 ); + } + return index; +} +#endif +#ifndef IVAS_FLOAT_FIXED static void transform_difference_index( const int16_t *diff_idx, int16_t *idx, @@ -6923,7 +7054,7 @@ static void transform_difference_index( return; } - +#else static void transform_difference_index_ivas_fx( const Word16 *diff_idx, Word16 *idx, @@ -6946,8 +7077,8 @@ static void transform_difference_index_ivas_fx( return; } - - +#endif +#ifndef IVAS_FLOAT_FIXED static void transform_index_and_GR_encode( int16_t *diff_idx, /* i : differenc eindex to encode */ const int16_t len, /* i : input length */ @@ -6969,7 +7100,7 @@ static void transform_index_and_GR_encode( return; } - +#else static void transform_index_and_GR_encode_ivas_fx( Word16 *diff_idx, /* i : differenc eindex to encode */ const Word16 len, /* i : input length */ @@ -6991,8 +7122,63 @@ static void transform_index_and_GR_encode_ivas_fx( return; } +#endif +#ifdef IVAS_FLOAT_FIXED +static Word16 try_differential_fx( + const Word16 numCodingBands, + const Word32 *masa_to_total_energy_ratio, /* Q30 */ + Word16 ratio_ism_idx[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], + const Word16 nchan_ism, + const Word16 bits_index, + Word16 *p_b_signif ) +{ + Word16 b, i; + Word16 nbits0; + Word16 b_signif; + Word16 ratio_ism_idx_ref[MAX_NUM_OBJECTS]; + Word16 diff_idx[MAX_NUM_OBJECTS]; + + b_signif = 0; + move16(); + WHILE( LT_16( b_signif, numCodingBands ) && GE_32( masa_to_total_energy_ratio[b_signif], MASA2TOTAL_THR_Q30 ) ) + { + test(); + b_signif = add( b_signif, 1 ); + } + + nbits0 = 0; + move16(); + + IF( LT_16( b_signif, numCodingBands ) ) + { + nbits0 = bits_index; + move16(); + Copy( ratio_ism_idx[b_signif], ratio_ism_idx_ref, nchan_ism ); + + FOR( b = b_signif + 1; b < numCodingBands; b++ ) + { + IF( LT_32( masa_to_total_energy_ratio[b], MASA2TOTAL_THR_Q30 ) ) + { + v_sub_s16_fx( ratio_ism_idx[b], ratio_ism_idx_ref, diff_idx, nchan_ism ); + Copy( ratio_ism_idx[b], ratio_ism_idx_ref, nchan_ism ); + + /* transform difference index into positive */ + transform_difference_index_ivas_fx( diff_idx, diff_idx, sub( nchan_ism, 1 ) ); + /* GR encoding */ + FOR( i = 0; i < nchan_ism - 1; i++ ) + { + nbits0 = add( nbits0, ivas_qmetadata_encode_extended_gr_length( diff_idx[i], 100, 0 ) ); + } + } + } + } + *p_b_signif = b_signif; + move16(); + return nbits0; +} +#else static int16_t try_differential( const int16_t numCodingBands, const float *masa_to_total_energy_ratio, @@ -7042,6 +7228,7 @@ static int16_t try_differential( return nbits0; } +#endif #ifndef IVAS_FLOAT_FIXED static void differential_coding_first_subframe( @@ -7101,7 +7288,7 @@ static void differential_coding_first_subframe_ivas_fx( IF( LT_16( b_signif, numCodingBands ) ) { - index = index_slice_enum( ratio_ism_idx[b_signif], nchan_ism ); + index = index_slice_enum_fx( ratio_ism_idx[b_signif], nchan_ism ); push_next_indice( hMetaData, index, bits_index ); Copy( ratio_ism_idx[b_signif], ratio_ism_idx_ref, nchan_ism ); @@ -7122,7 +7309,7 @@ static void differential_coding_first_subframe_ivas_fx( return; } #endif - +#ifndef IVAS_FLOAT_FIXED static void independent_coding_ratio_ism_idx( int16_t ratio_ism_idx[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], /* i : ISM ratios */ const float *masa_to_total_energy_ratio, /* i : MASA to total ratios */ @@ -7145,8 +7332,32 @@ static void independent_coding_ratio_ism_idx( return; } +#else +static void independent_coding_ratio_ism_idx_fx( + Word16 ratio_ism_idx[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], /* i : ISM ratios */ + const Word32 *masa_to_total_energy_ratio, /* i : MASA to total ratios, Q30 */ + const Word16 nchan_ism, /* i : number of objects */ + const Word16 numCodingBands, /* i : number of subbands */ + const Word16 bits_index, /* i : number of bits per index */ + BSTR_ENC_HANDLE hMetaData /* i/o: metadata bitstream handle */ +) +{ + Word16 b, index; + + FOR( b = 0; b < numCodingBands; b++ ) + { + IF( LT_32( masa_to_total_energy_ratio[b], MASA2TOTAL_THR_Q30 ) ) + { + index = index_slice_enum_fx( ratio_ism_idx[b], nchan_ism ); + push_next_indice( hMetaData, index, bits_index ); + } + } + return; +} +#endif +#ifndef IVAS_FLOAT_FIXED static void remove_sep_obj( int16_t *diff_idx, /* i/o: array of difference of indexes */ const int16_t nchan_ism, /* i : number of objects */ @@ -7162,8 +7373,26 @@ static void remove_sep_obj( return; } +#else +static void remove_sep_obj_fx( + Word16 *diff_idx, /* i/o: array of difference of indexes */ + const Word16 nchan_ism, /* i : number of objects */ + const Word16 idx_sep_obj /* i : index of separated object, to be taken out of array */ +) +{ + Word16 i; + + FOR( i = idx_sep_obj; i < nchan_ism - 1; i++ ) + { + diff_idx[i] = diff_idx[i + 1]; + move16(); + } + return; +} +#endif +#ifndef IVAS_FLOAT_FIXED static void estimate_bits_subband_ism_ratio( const int16_t *ratio_ism_idx, const int16_t *ratio_ism_idx_ref, /* ( i/o ) */ @@ -7203,8 +7432,53 @@ static void estimate_bits_subband_ism_ratio( return; } +#else +static void estimate_bits_subband_ism_ratio_fx( + const Word16 *ratio_ism_idx, + const Word16 *ratio_ism_idx_ref, /* ( i/o ) */ + const Word16 nchan_ism, + const Word16 shift_one, + const Word16 idx_sep_obj, + Word16 *p_nbits0, + Word16 *p_nbits1 ) +{ + Word16 diff_idx[MAX_NUM_OBJECTS]; + Word16 nbits0, nbits1; + Word16 i; + + nbits0 = 0; + nbits1 = 0; + move16(); + move16(); + + /* take difference with respect to previous subframe */ + v_sub_s16_fx( ratio_ism_idx, ratio_ism_idx_ref, diff_idx, nchan_ism ); + + IF( shift_one ) + { + remove_sep_obj_fx( diff_idx, nchan_ism, idx_sep_obj ); + } + + /* transform difference index into positive */ + transform_difference_index_ivas_fx( diff_idx, diff_idx, sub( sub( nchan_ism, 1 ), shift_one ) ); + + /* GR encoding */ + FOR( i = 0; i < nchan_ism - 1 - shift_one; i++ ) + { + nbits0 = add( nbits0, ivas_qmetadata_encode_extended_gr_length( diff_idx[i], 100, 0 ) ); + nbits1 = add( nbits1, ivas_qmetadata_encode_extended_gr_length( diff_idx[i], 100, 1 ) ); + } + + *p_nbits0 = nbits0; + *p_nbits1 = nbits1; + move16(); + move16(); + return; +} +#endif +#ifndef IVAS_FLOAT_FIXED static int16_t encode_ratio_ism_subframe( int16_t ratio_ism_idx[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], const int16_t nchan_ism, @@ -7456,16 +7730,283 @@ static int16_t encode_ratio_ism_subframe( return nbits; } +#else +static Word16 encode_ratio_ism_subframe_fx( + Word16 ratio_ism_idx[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], + const Word16 nchan_ism, + const UWord8 numCodingBands, + const Word16 sf, + Word16 ratio_ism_idx_prev_sf[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], + BSTR_ENC_HANDLE hMetaData, + const Word32 *masa_to_total_energy_ratio, /* Q30 */ + const Word16 shift_one, + const Word16 idx_separated_obj ) +{ + Word16 b, b_signif; + Word16 diff_idx[MAX_NUM_OBJECTS]; + Word16 nbits, nbits0, nbits1, GR_order, GR_order_sb; + Word16 differential_subframe; + Word16 ratio_ism_idx_ref[MAX_NUM_OBJECTS]; + Word16 bits_index; + Word16 nbits00, nbits11; + Word16 idx_sep_obj_local; + idx_sep_obj_local = idx_separated_obj; + move16(); + IF( GT_16( idx_separated_obj, -1 ) ) + { + if ( EQ_16( idx_separated_obj, sub( nchan_ism, 1 ) ) ) + { + idx_sep_obj_local = 0; + move16(); + } + } + nbits = 0; + nbits0 = 0; + nbits1 = 0; + move16(); + move16(); + move16(); -static void ivas_encode_masaism_metadata( - MASA_ENCODER_HANDLE hMasa, - IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata handle */ - BSTR_ENC_HANDLE hMetaData, /* i/o: metadata bitstream handle */ - ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */ - const int16_t nchan_ism, /* i : number of ISM channels */ - const int16_t low_bitrate_mode, /* i : is low bitrate more? 1/0 */ - const int16_t omasa_nbands, + differential_subframe = 1; /* the differences are taken with respect to previous subframe */ + move16(); + + /* first subframe */ + bits_index = 0; + move16(); + IF( sf == 0 ) + { + bits_index = bits_index_ism_ratio_fx( nchan_ism ); + + nbits = 0; + move16(); + FOR( b = 0; b < numCodingBands; b++ ) + { + IF( LT_32( masa_to_total_energy_ratio[b], MASA2TOTAL_THR_Q30 ) ) + { + nbits = add( nbits, bits_index ); + } + } + + nbits0 = try_differential_fx( numCodingBands, masa_to_total_energy_ratio, ratio_ism_idx, nchan_ism, bits_index, &b_signif ); + + test(); + IF( LE_16( nbits, nbits0 ) && nbits > 0 ) + { + /* independent encoding */ + push_next_indice( hMetaData, 1, 1 ); + independent_coding_ratio_ism_idx_fx( ratio_ism_idx, masa_to_total_energy_ratio, nchan_ism, numCodingBands, bits_index, hMetaData ); + nbits = add( nbits, 1 ); + } + ELSE + { + IF( nbits > 0 ) + { + differential_coding_first_subframe_ivas_fx( hMetaData, masa_to_total_energy_ratio, b_signif, ratio_ism_idx, nchan_ism, numCodingBands, bits_index ); + + nbits = add( nbits0, 1 ); + } + } + } + ELSE + { + /* not first subframe */ + test(); + IF( EQ_16( shift_one, 1 ) && EQ_16( nchan_ism, 2 ) ) + { + nbits = 0; + move16(); + } + ELSE + { + nbits0 = 0; + nbits1 = 0; + move16(); + move16(); + + FOR( b = 0; b < numCodingBands; b++ ) + { + IF( LT_32( masa_to_total_energy_ratio[b], MASA2TOTAL_THR_Q30 ) ) + { + estimate_bits_subband_ism_ratio_fx( ratio_ism_idx[b], ratio_ism_idx_prev_sf[b], nchan_ism, shift_one, idx_sep_obj_local, &nbits00, &nbits11 ); + nbits0 = add( nbits0, nbits00 ); + nbits1 = add( nbits1, nbits11 ); + } + } + IF( LT_16( nbits0, nbits1 ) ) + { + GR_order = 0; + nbits = nbits0; + move16(); + move16(); + } + ELSE + { + GR_order = 1; + nbits = nbits1; + move16(); + move16(); + } + + IF( GT_16( numCodingBands, 1 ) ) + { + /* try the difference from subband to subband; first subband is compared to previous subframe first subband*/ + /* take difference with respect to previous subframe only for first subband */ + nbits0 = 0; + nbits1 = 0; + b_signif = 0; + move16(); + move16(); + move16(); + WHILE( LT_16( b_signif, numCodingBands ) && GE_32( masa_to_total_energy_ratio[b_signif], MASA2TOTAL_THR_Q30 ) ) + { + test(); + b_signif = add( b_signif, 1 ); + } + + IF( LT_16( b_signif, numCodingBands ) ) + { + estimate_bits_subband_ism_ratio_fx( ratio_ism_idx[b_signif], ratio_ism_idx_prev_sf[b_signif], nchan_ism, shift_one, idx_sep_obj_local, &nbits0, &nbits1 ); + + Copy( ratio_ism_idx[b_signif], ratio_ism_idx_ref, nchan_ism ); + + FOR( b = b_signif + 1; b < numCodingBands; b++ ) + { + IF( LT_32( masa_to_total_energy_ratio[b], MASA2TOTAL_THR_Q30 ) ) + { + estimate_bits_subband_ism_ratio_fx( ratio_ism_idx[b], ratio_ism_idx_ref, nchan_ism, shift_one, idx_sep_obj_local, &nbits00, &nbits11 ); + nbits0 = add( nbits0, nbits00 ); + nbits1 = add( nbits1, nbits11 ); + Copy( ratio_ism_idx[b], ratio_ism_idx_ref, nchan_ism ); + } + } + + IF( LT_16( nbits0, nbits1 ) ) + { + GR_order_sb = 0; + move16(); + } + ELSE + { + GR_order_sb = 1; + nbits0 = nbits1; + move16(); + move16(); + } + + IF( LT_16( nbits0, nbits ) ) + { + differential_subframe = 0; + nbits = nbits0; + GR_order = GR_order_sb; + move16(); + move16(); + move16(); + } + + IF( nbits > 0 ) + { + /* write prediction type */ + push_next_indice( hMetaData, differential_subframe, 1 ); + /* write GR order */ + push_next_indice( hMetaData, GR_order, 1 ); + nbits = add( nbits, 1 ); /* for the prediction type */ + nbits = add( nbits, 1 ); /* for GR_order */ + + /* write data */ + IF( differential_subframe ) + { + FOR( b = 0; b < numCodingBands; b++ ) + { + IF( LT_32( masa_to_total_energy_ratio[b], MASA2TOTAL_THR_Q30 ) ) + { + /* take difference with respect to previous subframe */ + v_sub_s16_fx( ratio_ism_idx[b], ratio_ism_idx_prev_sf[b], diff_idx, nchan_ism ); + + IF( shift_one ) + { + remove_sep_obj_fx( diff_idx, nchan_ism, idx_sep_obj_local ); + } + + transform_index_and_GR_encode_ivas_fx( diff_idx, sub( sub( nchan_ism, 1 ), shift_one ), GR_order, hMetaData ); + } + } + } + ELSE + { + v_sub_s16_fx( ratio_ism_idx[b_signif], ratio_ism_idx_prev_sf[b_signif], diff_idx, nchan_ism ); + + IF( shift_one ) + { + remove_sep_obj_fx( diff_idx, nchan_ism, idx_sep_obj_local ); + } + + transform_index_and_GR_encode_ivas_fx( diff_idx, sub( sub( nchan_ism, 1 ), shift_one ), GR_order, hMetaData ); + + Copy( ratio_ism_idx[b_signif], ratio_ism_idx_ref, sub( nchan_ism, shift_one ) ); + + FOR( b = b_signif + 1; b < numCodingBands; b++ ) + { + /* take difference with respect to previous subband */ + IF( LT_32( masa_to_total_energy_ratio[b], MASA2TOTAL_THR_Q30 ) ) + { + v_sub_s16_fx( ratio_ism_idx[b], ratio_ism_idx_ref, diff_idx, nchan_ism ); + + IF( shift_one ) + { + remove_sep_obj_fx( diff_idx, nchan_ism, idx_sep_obj_local ); + } + + transform_index_and_GR_encode_ivas_fx( diff_idx, sub( sub( nchan_ism, 1 ), shift_one ), GR_order, hMetaData ); + + Copy( ratio_ism_idx[b], ratio_ism_idx_ref, sub( nchan_ism, shift_one ) ); + } + } + } + } + } + } + ELSE + { + /* only differential wrt previous subframe is possible */ + /* write the differential to subframe case and no bit to signal the difference type */ + + IF( nbits > 0 ) + { + /* write GR order */ + push_next_indice( hMetaData, GR_order, 1 ); + nbits = add( nbits, 1 ); /* for GR_order */ + /* write data */ + /* only one subband */ + IF( LT_32( masa_to_total_energy_ratio[0], MASA2TOTAL_THR_Q30 ) ) + { + /* take difference with respect to previous subframe */ + v_sub_s16_fx( ratio_ism_idx[0], ratio_ism_idx_prev_sf[0], diff_idx, nchan_ism ); + + IF( shift_one ) + { + remove_sep_obj_fx( diff_idx, nchan_ism, idx_sep_obj_local ); + } + + transform_index_and_GR_encode_ivas_fx( diff_idx, sub( sub( nchan_ism, 1 ), shift_one ), GR_order, hMetaData ); + } + } + } + } + } + + return nbits; +} +#endif +#ifndef IVAS_FLOAT_FIXED +static void ivas_encode_masaism_metadata( + MASA_ENCODER_HANDLE hMasa, + IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata handle */ + BSTR_ENC_HANDLE hMetaData, /* i/o: metadata bitstream handle */ + ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */ + const int16_t nchan_ism, /* i : number of ISM channels */ + const int16_t low_bitrate_mode, /* i : is low bitrate more? 1/0 */ + const int16_t omasa_nbands, const int16_t omasa_nblocks, const int16_t idx_separated_object, const int16_t ism_imp ) @@ -7622,6 +8163,7 @@ static void ivas_encode_masaism_metadata( } } } + ivas_omasa_encode_masa_to_total( hOmasaData->masa_to_total_energy_ratio, hMetaData, low_bitrate_mode, numCodingBands, numSf ); /* quantize ism_ratios */ @@ -7817,7 +8359,451 @@ static void ivas_encode_masaism_metadata( return; } +#else +static void ivas_encode_masaism_metadata_fx( + MASA_ENCODER_HANDLE hMasa, + IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata handle */ + BSTR_ENC_HANDLE hMetaData, /* i/o: metadata bitstream handle */ + ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */ + const Word16 nchan_ism, /* i : number of ISM channels */ + const Word16 low_bitrate_mode, /* i : is low bitrate more? 1/0 */ + const Word16 omasa_nbands, + const Word16 omasa_nblocks, + const Word16 idx_separated_object, + const Word16 ism_imp ) +{ + Word16 sf, band; + UWord8 numCodingBands; + UWord8 numSf; + Word16 brange[2]; + Word32 eneBand; + Word16 bin; + Word16 obj; + Word16 bits_ism[MAX_NUM_OBJECTS]; + UWord16 idx_sph; + Word32 theta_q, phi_q; + UWord16 index_theta, index_phi; + Word16 ratio_ism_fx[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS]; + Word16 ratio_ism_idx[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], ratio_ism_idx_prev_sf[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS]; + Word16 step; + Word32 energy_ism, energy_ism_ind[MAX_NUM_OBJECTS]; + Word16 tmp, rotate, energy_ism_e, energy_ism_ind_e[MAX_NUM_OBJECTS]; + Word16 n_ism_tmp, i; + OMASA_ENCODER_DATA_HANDLE hOmasaData = hMasa->data.hOmasaData; + Word16 nbands_work; + Word32 L_tmp; + Word16 L_tmp_e; + /* use the values from hQMetaData */ + numCodingBands = (UWord8) hQMetaData->q_direction->cfg.nbands; + numSf = (Word8) hQMetaData->q_direction->cfg.nblocks; + nbands_work = s_min( numCodingBands, omasa_nbands ); + move16(); + move16(); + IF( EQ_16( numCodingBands, 1 ) ) + { + FOR( sf = 0; sf < numSf; sf++ ) + { + L_tmp = 0; + L_tmp_e = 0; + move32(); + move16(); + FOR( i = 0; i < omasa_nbands; i++ ) + { + L_tmp = BASOP_Util_Add_Mant32Exp( L_tmp, L_tmp_e, hOmasaData->energy_ism_fx[sf][i], hOmasaData->energy_ism_fx_e[sf][i], &L_tmp_e ); + } + /* if ( sum_f( hOmasaData->energy_ism[sf], omasa_nbands ) == 0.0f ) */ + IF( L_tmp == 0 ) + { + hOmasaData->masa_to_total_energy_ratio_fx[sf][0] = ONE_IN_Q30; // 1.0f in Q30 + move32(); + } + ELSE + { + brange[0] = hMasa->data.band_mapping[0]; + brange[1] = hMasa->data.band_mapping[omasa_nbands]; + eneBand = 0; + move16(); + move16(); + move32(); + FOR( bin = brange[0]; bin < brange[1]; bin++ ) + { + eneBand = L_add( eneBand, hMasa->data.energy_fx[sf][bin] ); // hMasa->data.q_energy + } + + energy_ism = 0; + energy_ism_e = 0; + move32(); + move16(); + FOR( obj = 0; obj < nchan_ism; obj++ ) + { + energy_ism_ind[obj] = 0; + energy_ism_ind_e[obj] = 0; + move32(); + move16(); + } + + FOR( band = 0; band < omasa_nbands; band++ ) + { + energy_ism = BASOP_Util_Add_Mant32Exp( energy_ism, energy_ism_e, hOmasaData->energy_ism_fx[sf][band], hOmasaData->energy_ism_fx_e[sf][band], &energy_ism_e ); + FOR( obj = 0; obj < nchan_ism; obj++ ) + { + L_tmp = Mpy_32_32( hOmasaData->energy_ism_fx[sf][band], hOmasaData->energy_ratio_ism_fx[sf][band][obj] ); // Q = (31 - hOmasaData->energy_ism_fx_e[sf][band]) + Q30 - 31 + L_tmp_e = sub( 30, hOmasaData->energy_ism_fx_e[sf][band] ); + energy_ism_ind[obj] = BASOP_Util_Add_Mant32Exp( energy_ism_ind[obj], energy_ism_ind_e[obj], L_tmp, L_tmp_e, &energy_ism_ind_e[obj] ); + move32(); + } + } + + FOR( obj = 0; obj < nchan_ism; obj++ ) + { + hOmasaData->energy_ratio_ism_fx[sf][0][obj] = BASOP_Util_Divide3232_Scale_cadence( energy_ism_ind[obj], energy_ism, &L_tmp_e ); + move32(); + L_tmp_e = add( L_tmp_e, sub( energy_ism_ind_e[obj], energy_ism_e ) ); + /* Scaling to Q30 */ + hOmasaData->energy_ratio_ism_fx[sf][0][obj] = L_shl( hOmasaData->energy_ratio_ism_fx[sf][0][obj], sub( L_tmp_e, 1 ) ); // Q30 + move32(); + } + + L_tmp = BASOP_Util_Add_Mant32Exp( eneBand, sub( 31, hMasa->data.q_energy ), energy_ism, energy_ism_e, &L_tmp_e ); + IF( L_tmp != 0 ) + { + hOmasaData->masa_to_total_energy_ratio_fx[sf][0] = BASOP_Util_Divide3232_Scale_cadence( eneBand, L_tmp, &tmp ); + move32(); + tmp = add( tmp, sub( sub( 31, hMasa->data.q_energy ), L_tmp_e ) ); + /* Scaling to Q30 */ + hOmasaData->masa_to_total_energy_ratio_fx[sf][0] = L_shl( hOmasaData->masa_to_total_energy_ratio_fx[sf][0], sub( tmp, 1 ) ); // Q30 + move32(); + } + ELSE + { + hOmasaData->masa_to_total_energy_ratio_fx[sf][0] = MAX_32; + move32(); + } + } + } + } + ELSE IF( EQ_16( numSf, 1 ) ) + { + FOR( band = 0; band < nbands_work; band++ ) + { + energy_ism = 0; /* ISM energy for current subband */ + energy_ism_e = 0; /* ISM energy for current subband */ + move32(); + move16(); + FOR( obj = 0; obj < nchan_ism; obj++ ) + { + energy_ism_ind[obj] = 0; + energy_ism_ind_e[obj] = 0; + move32(); + move16(); + } + FOR( sf = 0; sf < omasa_nblocks; sf++ ) + { + energy_ism = BASOP_Util_Add_Mant32Exp( energy_ism, energy_ism_e, hOmasaData->energy_ism_fx[sf][band], hOmasaData->energy_ism_fx_e[sf][band], &energy_ism_e ); + FOR( obj = 0; obj < nchan_ism; obj++ ) + { + L_tmp = Mpy_32_32( hOmasaData->energy_ism_fx[sf][band], hOmasaData->energy_ratio_ism_fx[sf][band][obj] ); // Q = (31 - hOmasaData->energy_ism_fx_e[sf][band]) + Q30 - 31 + L_tmp_e = add( 1, hOmasaData->energy_ism_fx_e[sf][band] ); + energy_ism_ind[obj] = BASOP_Util_Add_Mant32Exp( energy_ism_ind[obj], energy_ism_ind_e[obj], L_tmp, L_tmp_e, &energy_ism_ind_e[obj] ); + move32(); + } + } + + IF( energy_ism == 0 ) + { + hOmasaData->masa_to_total_energy_ratio_fx[0][band] = ONE_IN_Q30; // 1.0f in Q30 + move32(); + } + ELSE + { + FOR( obj = 0; obj < nchan_ism; obj++ ) + { + hOmasaData->energy_ratio_ism_fx[0][band][obj] = BASOP_Util_Divide3232_Scale_cadence( energy_ism_ind[obj], energy_ism, &L_tmp_e ); + move32(); + L_tmp_e = add( L_tmp_e, sub( energy_ism_ind_e[obj], energy_ism_e ) ); + /* Scaling to Q30 */ + hOmasaData->energy_ratio_ism_fx[0][band][obj] = L_shl( hOmasaData->energy_ratio_ism_fx[0][band][obj], sub( L_tmp_e, 1 ) ); // Q30 + move32(); + } + brange[0] = hMasa->data.band_mapping[band]; + brange[1] = hMasa->data.band_mapping[band + 1]; + move16(); + move16(); + + eneBand = 0; + move32(); + FOR( sf = 0; sf < omasa_nblocks; sf++ ) + { + FOR( bin = brange[0]; bin < brange[1]; bin++ ) + { + eneBand = L_add( eneBand, hMasa->data.energy_fx[sf][bin] ); // hMasa->data.q_energy + } + } + + L_tmp = BASOP_Util_Add_Mant32Exp( eneBand, sub( 31, hMasa->data.q_energy ), energy_ism, energy_ism_e, &L_tmp_e ); + IF( L_tmp != 0 ) + { + hOmasaData->masa_to_total_energy_ratio_fx[0][band] = BASOP_Util_Divide3232_Scale_cadence( eneBand, L_tmp, &tmp ); + move32(); + tmp = add( tmp, sub( sub( 31, hMasa->data.q_energy ), L_tmp_e ) ); + /* Scaling to Q30 */ + hOmasaData->masa_to_total_energy_ratio_fx[0][band] = L_shl( hOmasaData->masa_to_total_energy_ratio_fx[0][band], sub( tmp, 1 ) ); // Q30 + move32(); + } + ELSE + { + hOmasaData->masa_to_total_energy_ratio_fx[0][band] = MAX_32; + move32(); + } + } + } + FOR( band = nbands_work; band < numCodingBands; band++ ) + { + hOmasaData->masa_to_total_energy_ratio_fx[0][band] = ONE_IN_Q30; + move32(); + + FOR( obj = 0; obj < nchan_ism; obj++ ) + { + hOmasaData->energy_ratio_ism_fx[0][band][obj] = hOmasaData->energy_ratio_ism_fx[0][nbands_work - 1][obj]; + move32(); + } + } + } + ELSE + { + FOR( sf = 0; sf < numSf; sf++ ) + { + FOR( band = 0; band < nbands_work; band++ ) + { + IF( hOmasaData->energy_ism_fx[sf][band] == 0 ) + { + hOmasaData->masa_to_total_energy_ratio_fx[sf][band] = ONE_IN_Q30; + move32(); + } + ELSE + { + brange[0] = hMasa->data.band_mapping[band]; + brange[1] = hMasa->data.band_mapping[band + 1]; + move16(); + move16(); + + eneBand = 0; + move32(); + FOR( bin = brange[0]; bin < brange[1]; bin++ ) + { + eneBand = L_add( eneBand, hMasa->data.energy_fx[sf][bin] ); // hMasa->data.q_energy + } + + L_tmp = BASOP_Util_Add_Mant32Exp( eneBand, sub( 31, hMasa->data.q_energy ), hOmasaData->energy_ism_fx[sf][band], hOmasaData->energy_ism_fx_e[sf][band], &L_tmp_e ); + IF( L_tmp != 0 ) + { + hOmasaData->masa_to_total_energy_ratio_fx[sf][band] = BASOP_Util_Divide3232_Scale_cadence( eneBand, L_tmp, &tmp ); + move32(); + tmp = add( tmp, sub( sub( 31, hMasa->data.q_energy ), L_tmp_e ) ); + /* Scaling to Q30 */ + hOmasaData->masa_to_total_energy_ratio_fx[sf][band] = L_shl( hOmasaData->masa_to_total_energy_ratio_fx[sf][band], sub( tmp, 1 ) ); // Q30 + move32(); + } + ELSE + { + hOmasaData->masa_to_total_energy_ratio_fx[sf][band] = MAX_32; + move32(); + } + } + } + FOR( band = nbands_work; band < numCodingBands; band++ ) + { + hOmasaData->masa_to_total_energy_ratio_fx[sf][band] = ONE_IN_Q30; + move32(); + + FOR( obj = 0; obj < nchan_ism; obj++ ) + { + hOmasaData->energy_ratio_ism_fx[sf][band][obj] = hOmasaData->energy_ratio_ism_fx[sf][nbands_work - 1][obj]; + move32(); + } + } + } + } + + ivas_omasa_encode_masa_to_total_fx( hOmasaData->masa_to_total_energy_ratio_fx, hMetaData, low_bitrate_mode, numCodingBands, numSf ); + + /* quantize ism_ratios */ + IF( GT_16( nchan_ism, 1 ) ) + { + /* inv_step = ( ( 1 << PARAM_ISM_POW_RATIO_NBITS ) - 1 ); * + * step = 1.0f / inv_step; */ + step = 4681; // 1.f / ( ( 1 << PARAM_ISM_POW_RATIO_NBITS ) - 1 ) => 1.f / 7 in Q15 + move16(); + + rotate = 0; + n_ism_tmp = 0; + move16(); + move16(); + + FOR( sf = 0; sf < numSf; sf++ ) + { + FOR( band = 0; band < numCodingBands; band++ ) + { + FOR( obj = 0; obj < nchan_ism; obj++ ) + { + assert( ( hOmasaData->energy_ratio_ism[sf][band][obj] >= 0 ) && ( hOmasaData->energy_ratio_ism[sf][band][obj] <= 1 ) ); + ratio_ism_fx[band][obj] = extract_h( hOmasaData->energy_ratio_ism_fx[sf][band][obj] ); // Q14 + move16(); + } + + /* Quantize ISM ratios */ + quantize_ratio_ism_vector_ivas_fx( ratio_ism_fx[band], 1 /* Q14 */, ratio_ism_idx[band], nchan_ism, hOmasaData->masa_to_total_energy_ratio_fx[sf][band], idx_separated_object ); + + test(); + test(); + IF( EQ_16( n_ism_tmp, numCodingBands ) && ratio_ism_idx[band][idx_separated_object] != 0 && LT_32( hOmasaData->masa_to_total_energy_ratio_fx[sf][band], MASA2TOTAL_THR_Q30 ) ) + { + i = 0; + move16(); + WHILE( ratio_ism_idx[band][idx_separated_object] > 0 ) + { + IF( NE_16( i, idx_separated_object ) ) + { + ratio_ism_idx[band][i] = add( ratio_ism_idx[band][i], 1 ); + ratio_ism_idx[band][idx_separated_object] = sub( ratio_ism_idx[band][idx_separated_object], 1 ); + move16(); + move16(); + } + i = add( i, 1 ); + if ( EQ_16( i, nchan_ism ) ) + { + i = 0; + move16(); + } + } + } + + /* reconstructed values */ + reconstruct_ism_ratios_fx( ratio_ism_idx[band], nchan_ism, step, hMasa->data.hOmasaData->q_energy_ratio_ism_fx[sf][band] ); + } + test(); + IF( GT_16( nchan_ism, 2 ) && EQ_16( idx_separated_object, sub( nchan_ism, 1 ) ) ) + { + /* rotate components */ + rotate = 1; + move16(); + FOR( band = 0; band < numCodingBands; band++ ) + { + IF( LT_32( hOmasaData->masa_to_total_energy_ratio_fx[sf][band], MASA2TOTAL_THR_Q30 ) ) + { + tmp = ratio_ism_idx[band][nchan_ism - 1]; + ratio_ism_idx[band][nchan_ism - 1] = ratio_ism_idx[band][0]; + ratio_ism_idx[band][0] = tmp; + move16(); + move16(); + move16(); + test(); + IF( sf == 0 && tmp == 0 ) + { + n_ism_tmp = add( n_ism_tmp, 1 ); + } + + if ( EQ_16( n_ism_tmp, numCodingBands ) ) + { + assert( tmp == 0 ); + } + } + } + } + ELSE + { + IF( GT_16( idx_separated_object, -1 ) ) + { + FOR( band = 0; band < numCodingBands; band++ ) + { + IF( LT_32( hOmasaData->masa_to_total_energy_ratio_fx[sf][band], MASA2TOTAL_THR_Q30 ) ) + { + test(); + IF( ratio_ism_idx[band][idx_separated_object] == 0 && sf == 0 ) + { + n_ism_tmp = add( n_ism_tmp, 1 ); + } + } + } + } + } + + /* encode data for current subframe */ + test(); + IF( sf > 0 && EQ_16( n_ism_tmp, numCodingBands ) ) + { + encode_ratio_ism_subframe_fx( ratio_ism_idx, nchan_ism, numCodingBands, sf, ratio_ism_idx_prev_sf, hMetaData, hOmasaData->masa_to_total_energy_ratio_fx[sf], 1, idx_separated_object ); + } + ELSE + { + encode_ratio_ism_subframe_fx( ratio_ism_idx, nchan_ism, numCodingBands, sf, ratio_ism_idx_prev_sf, hMetaData, hOmasaData->masa_to_total_energy_ratio_fx[sf], 0, idx_separated_object ); + } + + /* calculate quantized ISM ratios */ + /* save previous subframe indexes */ + FOR( band = 0; band < numCodingBands; band++ ) + { + Copy( ratio_ism_idx[band], ratio_ism_idx_prev_sf[band], nchan_ism ); + } + + IF( rotate ) + { + FOR( band = 0; band < numCodingBands; band++ ) + { + IF( LT_32( hOmasaData->masa_to_total_energy_ratio_fx[sf][band], MASA2TOTAL_THR_Q30 ) ) + { + tmp = ratio_ism_idx[band][nchan_ism - 1]; + ratio_ism_idx[band][nchan_ism - 1] = ratio_ism_idx[band][0]; + ratio_ism_idx[band][0] = tmp; + move16(); + move16(); + move16(); + } + } + } + } + } + + calculate_nbits_meta_fx( nchan_ism, hOmasaData->q_energy_ratio_ism_fx, hOmasaData->masa_to_total_energy_ratio_fx, numSf, numCodingBands, bits_ism, idx_separated_object, ism_imp ); + + /* quantize directions */ + FOR( obj = 0; obj < nchan_ism; obj++ ) + { + IF( LT_16( bits_ism[obj], 8 ) ) + { + /* check is same as previous */ + test(); + IF( LT_32( L_abs( L_sub( hIsmMeta[obj]->elevation_fx, hIsmMeta[obj]->q_elevation_old_fx ) ), 41943 /* 0.01f in Q22 */ ) && LT_32( L_abs( L_sub( hIsmMeta[obj]->azimuth_fx, hIsmMeta[obj]->q_azimuth_old_fx ) ), 41943 /* 0.01f in Q22 */ ) ) + { + push_next_indice( hMetaData, 1, 1 ); + /* the old stays the same */ + } + ELSE + { + push_next_indice( hMetaData, 0, 1 ); + idx_sph = quantize_direction_fx( hIsmMeta[obj]->elevation_fx, hIsmMeta[obj]->azimuth_fx, bits_ism[obj], &theta_q, &phi_q, &index_theta, &index_phi, MC_LS_SETUP_INVALID ); + push_next_indice( hMetaData, idx_sph, bits_ism[obj] ); + hIsmMeta[obj]->q_elevation_old_fx = hIsmMeta[obj]->elevation_fx; + hIsmMeta[obj]->q_azimuth_old_fx = hIsmMeta[obj]->azimuth_fx; + move32(); + move32(); + } + } + ELSE + { + idx_sph = quantize_direction_fx( hIsmMeta[obj]->elevation_fx, hIsmMeta[obj]->azimuth_fx, bits_ism[obj], &theta_q, &phi_q, &index_theta, &index_phi, MC_LS_SETUP_INVALID ); + push_next_indice( hMetaData, idx_sph, bits_ism[obj] ); + hIsmMeta[obj]->q_elevation_old_fx = hIsmMeta[obj]->elevation_fx; + hIsmMeta[obj]->q_azimuth_old_fx = hIsmMeta[obj]->azimuth_fx; + move32(); + move32(); + } + } + + return; +} +#endif /*-------------------------------------------------------------------* * ivas_merge_masa_transports() diff --git a/lib_enc/ivas_mct_enc.c b/lib_enc/ivas_mct_enc.c index 8a5928b66720c258517f72d87a945c1e2bebeb0b..748bf6423338e0a174453c968f7358c54ad23fba 100644 --- a/lib_enc/ivas_mct_enc.c +++ b/lib_enc/ivas_mct_enc.c @@ -615,15 +615,6 @@ ivas_error ivas_mct_enc( } } } - - FOR( Word16 pair = hMCT->currBlockDataCnt - 1; pair >= 0; pair-- ) - { - IF( hMCT->hBlockData[pair]->hStereoMdct->hItd ) - { - hMCT->hBlockData[pair]->hStereoMdct->hItd->itd_fx[1] = float_to_fix( hMCT->hBlockData[pair]->hStereoMdct->hItd->itd[1], Q23 ); - } - } - #ifdef IVAS_FLOAT_FIXED_CONVERSIONS Encoder_State *sts_tmp[MCT_MAX_CHANNELS]; Encoder_State *st; diff --git a/lib_enc/ivas_qmetadata_enc.c b/lib_enc/ivas_qmetadata_enc.c index bfc3155c85f7097757459a6d540f6cd8cda325df..48b1a7a444d2738d4cf58013ae8d0328ff511a6c 100644 --- a/lib_enc/ivas_qmetadata_enc.c +++ b/lib_enc/ivas_qmetadata_enc.c @@ -306,6 +306,12 @@ static void ivas_qmetadata_quantize_diffuseness_nrg_ratios_hr_512( IVAS_QMETADAT static int16_t ivas_qmetadata_quantize_coherence_hr_512( IVAS_QMETADATA *hQMetaData, const int16_t idx_d, const int16_t all_coherence_zero, BSTR_ENC_HANDLE hMetaData, const int16_t bits_coh ); static int16_t encode_surround_coherence_hr( IVAS_QMETADATA *hQMetaData, BSTR_ENC_HANDLE hMetaData ); + +static int16_t write_stream_dct_coeffs_omasa( int16_t *q_idx, const int16_t len_stream, BSTR_ENC_HANDLE hMetaData, const int16_t first_line, const int16_t low_bitrate_mode ); + +static int16_t find_optimal_GR_order( const int16_t *q_idx, const int16_t len, int16_t *GR ); + +static int16_t find_optimal_GR_orders( const int16_t *q_idx, const int16_t len, const int16_t len_max_GR1, int16_t *GR1, int16_t *GR2, int16_t *i_min ); #else static Word16 ivas_qmetadata_quantize_coherence_hr_512_fx( IVAS_QMETADATA *hQMetaData, const Word16 idx_d, const Word16 all_coherence_zero, BSTR_ENC_HANDLE hMetaData, const Word16 bits_coh ); @@ -314,13 +320,13 @@ static void ivas_qmetadata_quantize_diffuseness_nrg_ratios_hr_512_fx( IVAS_QMETA static Word16 calc_var_azi_fx( const IVAS_QDIRECTION *q_direction, const Word16 diffuseness_index_max_ec_frame, const Word32 avg_azimuth, Word32 *avg_azimuth_out ); static Word16 encode_surround_coherence_hr_fx( IVAS_QMETADATA *hQMetaData, BSTR_ENC_HANDLE hMetaData ); -#endif -static int16_t write_stream_dct_coeffs_omasa( int16_t *q_idx, const int16_t len_stream, BSTR_ENC_HANDLE hMetaData, const int16_t first_line, const int16_t low_bitrate_mode ); +static Word16 write_stream_dct_coeffs_omasa_fx( Word16 *q_idx, const Word16 len_stream, BSTR_ENC_HANDLE hMetaData, const Word16 first_line, const Word16 low_bitrate_mode ); -static int16_t find_optimal_GR_order( const int16_t *q_idx, const int16_t len, int16_t *GR ); +static Word16 find_optimal_GR_order_fx( const Word16 *q_idx, const Word16 len, Word16 *GR ); -static int16_t find_optimal_GR_orders( const int16_t *q_idx, const int16_t len, const int16_t len_max_GR1, int16_t *GR1, int16_t *GR2, int16_t *i_min ); +static Word16 find_optimal_GR_orders_fx( const Word16 *q_idx, const Word16 len, const Word16 len_max_GR1, Word16 *GR1, Word16 *GR2, Word16 *i_min ); +#endif /*-----------------------------------------------------------------------* @@ -11223,7 +11229,7 @@ static void transform_azimuth_dir2( return; } #endif - +#ifndef IVAS_FLOAT_FIXED static int16_t divide_GR_orders( const int16_t *q_idx, const int16_t GR1, @@ -11498,13 +11504,331 @@ static int16_t write_stream_dct_coeffs_omasa( return nb_bits; } +#else +static Word16 divide_GR_orders_fx( + const Word16 *q_idx, + const Word16 GR1, + const Word16 GR2, + const Word16 len, + const Word16 len_max_GR1, + Word16 *i_min ) +{ + Word16 nb_GR_min; + Word16 i, j, nb_GR; + nb_GR_min = 1000; + *i_min = -1; + move16(); + move16(); + FOR( i = 0; i < s_min( len_max_GR1, len ); i++ ) + { + nb_GR = 0; + move16(); + + FOR( j = 0; j <= i; j++ ) + { + nb_GR = add( nb_GR, ivas_qmetadata_encode_extended_gr_length( q_idx[j], 100, GR1 ) ); + } + FOR( j = i + 1; j < len; j++ ) + { + nb_GR = add( nb_GR, ivas_qmetadata_encode_extended_gr_length( q_idx[j], 100, GR2 ) ); + } + + IF( LT_16( nb_GR, nb_GR_min ) ) + { + nb_GR_min = nb_GR; + *i_min = add( i, 1 ); + move16(); + move16(); + } + } + + return nb_GR_min; +} + + +static Word16 find_optimal_GR_order_fx( + const Word16 *q_idx, + const Word16 len, + Word16 *GR ) +{ + Word16 nb_GR_0, nb_GR_1; + Word16 i; + /* find optimum length of the part encoded with GR2 */ + nb_GR_0 = 0; + nb_GR_1 = 0; + move16(); + move16(); + FOR( i = 0; i < len; i++ ) + { + nb_GR_0 = add( nb_GR_0, ivas_qmetadata_encode_extended_gr_length( q_idx[i], 100, 0 ) ); + nb_GR_1 = add( nb_GR_1, ivas_qmetadata_encode_extended_gr_length( q_idx[i], 100, 1 ) ); + } + + IF( LT_16( nb_GR_0, nb_GR_1 ) ) + { + *GR = 0; + move16(); + return nb_GR_0; + } + ELSE + { + *GR = 1; + move16(); + + return nb_GR_1; + } +} + + +static Word16 find_optimal_GR_orders_fx( + const Word16 *q_idx, + const Word16 len, + const Word16 len_max_GR1, + Word16 *GR1, + Word16 *GR2, + Word16 *i_min ) +{ + Word16 nb_GR_20, nb_GR_21, nb_GR_10, nb_GR_min; + Word16 i_min_20, i_min_21, i_min_10; + /* find optimum length of the part encoded with GR2 */ + nb_GR_20 = divide_GR_orders_fx( q_idx, 2, 0, len, len_max_GR1, &i_min_20 ); + nb_GR_21 = divide_GR_orders_fx( q_idx, 2, 1, len, len_max_GR1, &i_min_21 ); + nb_GR_10 = divide_GR_orders_fx( q_idx, 1, 0, len, len_max_GR1, &i_min_10 ); + + test(); + IF( LT_16( nb_GR_20, nb_GR_21 ) && LT_16( nb_GR_20, nb_GR_10 ) ) + { + *GR1 = 2; + *GR2 = 0; + nb_GR_min = nb_GR_20; + *i_min = i_min_20; + move16(); + move16(); + move16(); + move16(); + } + ELSE + { + test(); + IF( LT_16( nb_GR_21, nb_GR_20 ) && LT_16( nb_GR_21, nb_GR_10 ) ) + { + *GR1 = 2; + *GR2 = 1; + nb_GR_min = nb_GR_21; + *i_min = i_min_21; + move16(); + move16(); + move16(); + move16(); + } + ELSE + { + *GR1 = 1; + *GR2 = 0; + nb_GR_min = nb_GR_10; + *i_min = i_min_10; + move16(); + move16(); + move16(); + move16(); + } + } + + return nb_GR_min; +} + + +static Word16 write_stream_dct_coeffs_omasa_fx( + Word16 *q_idx, /* i : array of indexes to be written */ + const Word16 len_stream, /* i : array length */ + BSTR_ENC_HANDLE hMetaData, /* i/o: metadata bitstream */ + const Word16 first_line, /* i : is first line of the matrix? 1/0 */ + const Word16 low_bitrate_mode /* i : is low bitrate mode? if yes, limit the number of bits written */ +) +{ + Word16 nb_bits = 0, bits_pos; + UWord16 nb_GR_min; + Word16 i, j; + Word16 changed, update_needed; + move16(); + Word16 GR1, GR2, i_min; + Word16 max_bits; + + bits_pos = hMetaData->nb_bits_tot; + move16(); + IF( EQ_16( low_bitrate_mode, 1 ) ) + { + max_bits = 50; + move16(); + } + ELSE + { + max_bits = 1000; + move16(); + } + + /* write DCT 0 component */ + /* write sign only if not the very first DCT coeff */ + IF( first_line == 0 ) + { + IF( q_idx[0] > 0 ) + { + push_next_indice( hMetaData, 1, 1 ); + push_next_indice( hMetaData, q_idx[0], BITS_MASA2TOTTAL_DCT0 ); + } + ELSE + { + push_next_indice( hMetaData, 0, 1 ); + push_next_indice( hMetaData, negate( q_idx[0] ), BITS_MASA2TOTTAL_DCT0 ); + } + nb_bits = add( nb_bits, BITS_MASA2TOTTAL_DCT0 + 1 ); + } + ELSE + { + push_next_indice( hMetaData, q_idx[0], BITS_MASA2TOTTAL_DCT0 ); + nb_bits = add( nb_bits, BITS_MASA2TOTTAL_DCT0 ); + } + + IF( q_idx[0] != 0 ) + { + i_min = 1; + GR2 = 0; + move16(); + move16(); + IF( GE_16( len_stream, 8 ) ) + { + nb_GR_min = find_optimal_GR_orders_fx( &q_idx[1], sub( len_stream, 1 ), 15, &GR1, &GR2, &i_min ); + } + ELSE + { + nb_GR_min = find_optimal_GR_order_fx( &q_idx[1], sub( len_stream, 1 ), &GR1 ); + } + + assert( nb_GR_min < 1000 ); + changed = 1; + update_needed = 0; + move16(); + move16(); + WHILE( GE_16( len_stream, 8 ) && GT_16( nb_GR_min, max_bits ) && GE_16( changed, 1 ) ) + { + test(); + test(); + update_needed = 1; + changed = 0; + move16(); + move16(); + FOR( j = len_stream - 1; j > 6; j-- ) + { + IF( GE_16( q_idx[j], 2 ) ) + { + + IF( GT_16( j, i_min ) ) + { + changed = 1; + move16(); + nb_GR_min = sub( nb_GR_min, ivas_qmetadata_encode_extended_gr_length( q_idx[j], 100, GR2 ) ); + q_idx[j] = sub( q_idx[j], 2 ); + move16(); + nb_GR_min = add( nb_GR_min, ivas_qmetadata_encode_extended_gr_length( q_idx[j], 100, GR2 ) ); + } + ELSE + { + changed = 1; + move16(); + nb_GR_min = sub( nb_GR_min, ivas_qmetadata_encode_extended_gr_length( q_idx[j], 100, GR1 ) ); + q_idx[j] = sub( q_idx[j], 2 ); + move16(); + nb_GR_min = add( nb_GR_min, ivas_qmetadata_encode_extended_gr_length( q_idx[j], 100, 0 ) ); + } + } + ELSE IF( EQ_16( q_idx[j], 1 ) ) + { + IF( GT_16( j, i_min ) ) + { + changed = 1; + move16(); + nb_GR_min = sub( nb_GR_min, ivas_qmetadata_encode_extended_gr_length( q_idx[j], 100, GR2 ) ); + q_idx[j] = sub( q_idx[j], 1 ); + move16(); + + nb_GR_min = add( nb_GR_min, ivas_qmetadata_encode_extended_gr_length( q_idx[j], 100, GR2 ) ); + } + ELSE + { + changed = 1; + move16(); + nb_GR_min = sub( nb_GR_min, ivas_qmetadata_encode_extended_gr_length( q_idx[j], 100, GR1 ) ); + q_idx[j] = sub( q_idx[j], 1 ); + move16(); + nb_GR_min = add( nb_GR_min, ivas_qmetadata_encode_extended_gr_length( q_idx[j], 100, 0 ) ); + } + } + IF( LT_16( nb_GR_min, max_bits ) ) + { + BREAK; + } + } + } + + IF( EQ_16( update_needed, 1 ) ) + { + /* re-calculate */ + /* find optimum length of the part encoded with GR2 */ + nb_GR_min = find_optimal_GR_orders_fx( &q_idx[1], sub( len_stream, 1 ), 15, &GR1, &GR2, &i_min ); + } + + IF( GE_16( len_stream, 8 ) ) + { + /* write number of indexes encoded with GR2 on 4 bits */ + push_next_indice( hMetaData, i_min, 4 ); + nb_bits = add( nb_bits, 4 ); + /* write GR orders */ + push_next_indice( hMetaData, sub( GR1, 1 ), 1 ); + nb_bits = add( nb_bits, 1 ); + IF( EQ_16( GR1, 2 ) ) + { + push_next_indice( hMetaData, GR2, 1 ); + nb_bits = add( nb_bits, 1 ); + } + + /* write GR data */ + FOR( i = 1; i <= i_min; i++ ) + { + ivas_qmetadata_encode_extended_gr( hMetaData, q_idx[i], 100, GR1 ); + } + + FOR( i = i_min + 1; i < len_stream; i++ ) + { + ivas_qmetadata_encode_extended_gr( hMetaData, q_idx[i], 100, GR2 ); + } + } + ELSE + { + /* len_stream <= 8 */ + /* write GR order */ + push_next_indice( hMetaData, GR1, 1 ); + nb_bits = add( nb_bits, 1 ); + FOR( i = 1; i < len_stream; i++ ) + { + ivas_qmetadata_encode_extended_gr( hMetaData, q_idx[i], 100, GR1 ); + } + } + + nb_bits = add( nb_bits, nb_GR_min ); + + assert( nb_bits == ( hMetaData->nb_bits_tot - bits_pos ) ); + } + + return nb_bits; +} +#endif /*------------------------------------------------------------------------- * ivas_omasa_encode_masa_to_total() * *------------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED void ivas_omasa_encode_masa_to_total( float masa_to_total_energy_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], BSTR_ENC_HANDLE hMetaData, @@ -11686,3 +12010,228 @@ void ivas_omasa_encode_masa_to_total( return; } +#else +void ivas_omasa_encode_masa_to_total_fx( + Word32 masa_to_total_energy_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* Q30 */ + BSTR_ENC_HANDLE hMetaData, + const Word16 low_bitrate_mode, + const Word16 nbands, + const Word16 nblocks ) +{ + Word16 i, j, k; + Word32 data[MAX_PARAM_SPATIAL_SUBFRAMES * MASA_FREQUENCY_BANDS]; // Q30 + Word32 q_dct_data[MAX_PARAM_SPATIAL_SUBFRAMES * MASA_FREQUENCY_BANDS]; + Word32 step = STEP_M2T_FX; + Word16 q_idx[MAX_PARAM_SPATIAL_SUBFRAMES * MASA_FREQUENCY_BANDS]; + Word32 dct_data_tmp[MAX_PARAM_SPATIAL_SUBFRAMES * MASA_FREQUENCY_BANDS]; + Word32 dct_data[MAX_PARAM_SPATIAL_SUBFRAMES * MASA_FREQUENCY_BANDS]; + Word16 dct_data_e = 0, dct_data_tmp_e, q_dct_data_e; + Word16 bits_pos, nb_bits; + Word16 n_streams, len_stream, tmp_e; + Word32 L_tmp; + move32(); + move16(); + + set32_fx( q_dct_data, 0, MAX_PARAM_SPATIAL_SUBFRAMES * MASA_FREQUENCY_BANDS ); + bits_pos = hMetaData->nb_bits_tot; + k = 0; + move16(); + move16(); + FOR( i = 0; i < nbands; i++ ) + { + FOR( j = 0; j < nblocks; j++ ) + { + data[k] = masa_to_total_energy_ratio[j][i]; + move32(); + k = add( k, 1 ); + } + } + + /* DCT2 transform */ + n_streams = 1; + move16(); + len_stream = imult1616( nbands, nblocks ); + SWITCH( len_stream ) + { + case 4: + matrix_product_mant_exp_fx( dct4_fx, 0 /* Q31 */, nblocks, nblocks, 0, data, 1 /* Q30*/, 1, nblocks, 1, dct_data, &dct_data_e ); + n_streams = 1; + len_stream = 4; + move16(); + BREAK; + case 5: + matrix_product_mant_exp_fx( dct5_fx, 0 /* Q31 */, nbands, nbands, 0, data, 1 /* Q30 */, 1, nbands, 1, dct_data, &dct_data_e ); + n_streams = 1; + len_stream = nbands; + move16(); + move16(); + BREAK; + case 8: + matrix_product_mant_exp_fx( dct8_fx, 0 /* Q31 */, nbands, nbands, 0, data, 1 /* Q30 */, 1, nbands, 1, dct_data, &dct_data_e ); + n_streams = 1; + len_stream = nbands; + move16(); + BREAK; + case 12: + matrix_product_mant_exp_fx( dct12_fx, 0 /* Q31 */, nbands, nbands, 0, data, 1 /* Q30 */, 1, nbands, 1, dct_data, &dct_data_e ); + n_streams = 1; + len_stream = nbands; + move16(); + move16(); + BREAK; + case 20: + matrix_product_mant_exp_fx( dct5_fx, 0 /* Q31 */, nbands, nbands, 0, data, 1 /* Q30 */, nblocks, nbands, 1, dct_data_tmp, &dct_data_e ); + matrix_product_mant_exp_fx( dct_data_tmp, dct_data_e, nbands, nblocks, 0, dct4_fx, 0 /* Q31 */, nblocks, nblocks, 1, dct_data, &dct_data_e ); + n_streams = 1; + len_stream = imult1616( nbands, nblocks ); + move16(); + move16(); + BREAK; + case 32: + matrix_product_mant_exp_fx( dct8_fx, 0 /* Q31 */, nbands, nbands, 0, data, 1 /* Q30 */, nblocks, nbands, 1, dct_data_tmp, &dct_data_e ); + matrix_product_mant_exp_fx( dct_data_tmp, dct_data_e, nbands, nblocks, 0, dct4_fx, 0 /* Q31 */, nblocks, nblocks, 1, dct_data, &dct_data_e ); + n_streams = nblocks; + len_stream = nbands; + move16(); + move16(); + BREAK; + default: + printf( "Incorrect number of coefficients for OMASA.\n" ); + BREAK; + } + + FOR( k = 0; k < n_streams; k++ ) + { + j = imult1616( k, len_stream ); + /* quantize with fixed common step */ + L_tmp = BASOP_Util_Divide3232_Scale_cadence( dct_data[j], step, &tmp_e ); + tmp_e = add( tmp_e, dct_data_e ); + q_idx[j] = rint_new_fx( L_shr( L_tmp, sub( 15, tmp_e ) ) /* Q16 */ ); // Q0 + move16(); + + IF( GT_16( q_idx[j], ( ( 1 << BITS_MASA2TOTTAL_DCT0 ) - 1 ) ) ) /* limit DCT0 to BITS_MASA2TOTTAL_DCT0 bit representation */ + { + q_idx[j] = ( ( 1 << BITS_MASA2TOTTAL_DCT0 ) - 1 ); + move16(); + } + + q_dct_data[j] = Mpy_32_16_1( step, shl( q_idx[j], 9 ) /* Q9 */ ); // Q25 + move16(); + + IF( q_idx[j] == 0 ) + { + set16_fx( &q_idx[j], 0, len_stream ); + set32_fx( &q_dct_data[j], 0, len_stream ); + } + ELSE + { + FOR( i = 1; i < len_stream; i++ ) + { + L_tmp = BASOP_Util_Divide3232_Scale_cadence( dct_data[j + i], step, &tmp_e ); + tmp_e = add( tmp_e, dct_data_e ); + q_idx[j + i] = rint_new_fx( L_shr( L_tmp, sub( 15, tmp_e ) ) ); + move16(); + q_dct_data[j + i] = Mpy_32_16_1( step, shl( q_idx[j + i], 9 ) /* Q9 */ ); // Q25 + move32(); + IF( q_idx[j + i] <= 0 ) + { + q_idx[j + i] = imult1616( -2, q_idx[j + i] ); + move16(); + } + ELSE + { + q_idx[j + i] = sub( imult1616( 2, q_idx[j + i] ), 1 ); + move16(); + } + } + } + } + + /* write data */ + nb_bits = 0; + move16(); + FOR( i = 0; i < n_streams; i++ ) + { + nb_bits = add( nb_bits, write_stream_dct_coeffs_omasa_fx( &q_idx[i * len_stream], len_stream, hMetaData, ( i == 0 ), low_bitrate_mode ) ); + } + + /* reconstruct masa2total */ + q_dct_data[0] = Mpy_32_16_1( step, shl( q_idx[0], 9 ) /* Q9 */ ); // Q25 + move32(); + FOR( i = 1; i < len_stream; i++ ) + { + IF( ( q_idx[i] % 2 ) == 0 ) + { + q_dct_data[i] = L_negate( Mpy_32_16_1( step, shl( q_idx[i], 8 ) /* Q9 */ ) ); // Q25 + move32(); + } + ELSE + { + q_dct_data[i] = Mpy_32_16_1( step, shl( add( q_idx[i], 1 ), 8 ) /* Q9 */ ); // Q25 + move32(); + } + } + + q_dct_data_e = 6; // Q25 + move16(); + /* inverse DCT2 transform */ + SWITCH( len_stream ) + { + case 4: + matrix_product_mant_exp_fx( dct4_fx, 0 /* Q31 */, nblocks, nblocks, 1, q_dct_data, q_dct_data_e, nblocks, 1, 0, dct_data_tmp, &dct_data_tmp_e ); + Copy32( dct_data_tmp, q_dct_data, nblocks ); + q_dct_data_e = dct_data_tmp_e; + move16(); + BREAK; + case 5: + matrix_product_mant_exp_fx( dct5_fx, 0 /* Q31 */, nbands, nbands, 1, q_dct_data, q_dct_data_e, nbands, 1, 0, dct_data_tmp, &dct_data_tmp_e ); + Copy32( dct_data_tmp, q_dct_data, nbands ); + q_dct_data_e = dct_data_tmp_e; + move16(); + BREAK; + case 8: + matrix_product_mant_exp_fx( dct8_fx, 0 /* Q31 */, nbands, nbands, 1, q_dct_data, q_dct_data_e, nbands, 1, 0, dct_data_tmp, &dct_data_tmp_e ); + Copy32( dct_data_tmp, q_dct_data, nbands ); + q_dct_data_e = dct_data_tmp_e; + move16(); + BREAK; + case 12: + matrix_product_mant_exp_fx( dct12_fx, 0 /* Q31 */, nbands, nbands, 1, q_dct_data, q_dct_data_e, nbands, 1, 0, dct_data_tmp, &dct_data_tmp_e ); + Copy32( dct_data_tmp, q_dct_data, nbands ); + q_dct_data_e = dct_data_tmp_e; + move16(); + BREAK; + case 20: + matrix_product_mant_exp_fx( dct5_fx, 0 /* Q31 */, nbands, nbands, 1, q_dct_data, q_dct_data_e, nbands, nblocks, 0, dct_data_tmp, &dct_data_tmp_e ); + matrix_product_mant_exp_fx( dct_data_tmp, dct_data_tmp_e, nbands, nblocks, 0, dct4_fx, 0 /* Q31 */, nblocks, nblocks, 0, q_dct_data, &q_dct_data_e ); /* reuse of variable*/ + BREAK; + case 32: + matrix_product_mant_exp_fx( dct8_fx, 0 /* Q31 */, nbands, nbands, 1, q_dct_data, q_dct_data_e, nbands, nblocks, 0, dct_data_tmp, &dct_data_tmp_e ); + matrix_product_mant_exp_fx( dct_data_tmp, dct_data_tmp_e, nbands, nblocks, 0, dct4_fx, 0 /* Q31 */, nblocks, nblocks, 0, q_dct_data, &q_dct_data_e ); + BREAK; + default: + printf( "Incorrect number of coefficients for OMASA.\n" ); + BREAK; + } + + scale_sig32( q_dct_data, MAX_PARAM_SPATIAL_SUBFRAMES * MASA_FREQUENCY_BANDS, sub( Q30, sub( 31, q_dct_data_e ) ) ); // Scaling to Q30 + + k = 0; + move16(); + FOR( i = 0; i < nblocks; i++ ) + { + FOR( j = 0; j < nbands; j++ ) + { + masa_to_total_energy_ratio[i][j] = L_max( 0, q_dct_data[k] ); + masa_to_total_energy_ratio[i][j] = L_min( ONE_IN_Q30, masa_to_total_energy_ratio[i][j] ); + move32(); + move32(); + k = add( k, 1 ); + } + } + assert( nb_bits == ( hMetaData->nb_bits_tot - bits_pos ) ); + + + return; +} +#endif diff --git a/lib_enc/ivas_qspherical_enc.c b/lib_enc/ivas_qspherical_enc.c index 879cccf6a8dc3d48f30f7496abeac24e38eba7bd..ee3d4a1e119c971baec083f4a2cbab140e18619d 100644 --- a/lib_enc/ivas_qspherical_enc.c +++ b/lib_enc/ivas_qspherical_enc.c @@ -1055,7 +1055,20 @@ static Word16 direction_distance_cp_fx( // Q14 // d = st * st1 + ct * ( sqrtf( 1 - st1 * st1 ) ) * cosf( ( phi - phi_hat ) * PI_OVER_180 ); /*( phi - phi_hat ) * PI_OVER_180 */ - tmp_phi = extract_l( Mpy_32_32( L_sub( phi, phi_hat ), PI_OVER_180_Q22 ) ); // (Q22 + Q22 - 31) = Q13 + IF( GT_32( L_sub( phi, phi_hat ), _180_IN_Q22 ) ) + { + // cos(360 - theta) = cos(theta) + tmp_phi = extract_l( Mpy_32_32( L_sub( _360_IN_Q22, L_sub( phi, phi_hat ) ), PI_OVER_180_Q22 ) ); // (Q22 + Q22 - 31) = Q13 + } + ELSE IF( LT_32( L_sub( phi, phi_hat ), -_180_IN_Q22 ) ) + { + // cos(360 + theta) = cos(theta) + tmp_phi = extract_l( Mpy_32_32( L_add( _360_IN_Q22, L_sub( phi, phi_hat ) ), PI_OVER_180_Q22 ) ); // (Q22 + Q22 - 31) = Q13 + } + ELSE + { + tmp_phi = extract_l( Mpy_32_32( L_sub( phi, phi_hat ), PI_OVER_180_Q22 ) ); // (Q22 + Q22 - 31) = Q13 + } tmp_e = 0; move16(); @@ -1067,13 +1080,26 @@ static Word16 direction_distance_cp_fx( // Q14 tmp = add_sat( tmp, shr( mult( st, st1 ), 1 ) /* Q14 */ ); // Q14 - d = tmp; // Q15 + d = tmp; // Q14 move16(); // *d1 = st * st2 + ct * ( sqrtf( 1 - st2 * st2 ) ) * cosf( ( phi - phi_hat1 ) * PI_OVER_180 ); /*( phi - phi_hat1 ) * PI_OVER_180 */ - tmp_phi = extract_l( Mpy_32_32( L_sub( phi, phi_hat1 ), PI_OVER_180_Q22 ) ); // (Q22 + Q22 - 31) = Q13 + IF( GT_32( L_sub( phi, phi_hat1 ), _180_IN_Q22 ) ) + { + // cos(360 - theta) = cos(theta) + tmp_phi = extract_l( Mpy_32_32( L_sub( _360_IN_Q22, L_sub( phi, phi_hat1 ) ), PI_OVER_180_Q22 ) ); // (Q22 + Q22 - 31) = Q13 + } + ELSE IF( LT_32( L_sub( phi, phi_hat1 ), -_180_IN_Q22 ) ) + { + // cos(360 + theta) = cos(theta) + tmp_phi = extract_l( Mpy_32_32( L_add( _360_IN_Q22, L_sub( phi, phi_hat1 ) ), PI_OVER_180_Q22 ) ); // (Q22 + Q22 - 31) = Q13 + } + ELSE + { + tmp_phi = extract_l( Mpy_32_32( L_sub( phi, phi_hat1 ), PI_OVER_180_Q22 ) ); // (Q22 + Q22 - 31) = Q13 + } tmp_e = 0; move16(); diff --git a/lib_enc/ivas_sns_enc.c b/lib_enc/ivas_sns_enc.c index a6cc6f22505674296c14597d86aaa8ec8098076e..bab1cbde47b10c85bd827c0150f470987adc242a 100644 --- a/lib_enc/ivas_sns_enc.c +++ b/lib_enc/ivas_sns_enc.c @@ -816,7 +816,7 @@ Word16 quantize_sns_fx( Word16 *zero_side_flag, /* Q0 */ Word16 *sns_stereo_mode ) /* Q0 */ { - Word16 nSubframes, k, ch, i; + Word16 nSubframes = 0, k, ch, i; Word16 nbits, idxIndices; Encoder_State *st; diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h index 0184f55fcd5d7ac15658a9be5644768fb3057a08..1e2eea3d7c66436930400815da1b56ccc6eada85 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -47,33 +47,43 @@ typedef struct stereo_itd_data_struct { int16_t prev_itd; +#ifndef IVAS_FLOAT_FIXED float itd[STEREO_DFT_ENC_DFT_NB]; float deltaItd[STEREO_DFT_ENC_DFT_NB]; +#endif int16_t td_itd[STEREO_DFT_ENC_DFT_NB]; int16_t td_itd_32k[STEREO_DFT_ENC_DFT_NB]; int16_t itd_index[STEREO_DFT_ENC_DFT_NB]; +#ifndef IVAS_FLOAT_FIXED float xcorr_smooth[STEREO_DFT_N_32k_ENC]; - float lp_phat_peak; /* low-pass GCC PHAT peak value */ + float lp_phat_peak; /* low-pass GCC PHAT peak value */ +#endif int16_t itd_hangover; /* ITD hangover counter */ int16_t itd_cnt; /* Consecutive valid ITD counter */ +#ifndef IVAS_FLOAT_FIXED float prev_sum_nrg_L_lb; float prev_xcorr_lb[STEREO_DFT_XCORR_LB_MAX]; float E_band_n[STEREO_DFT_ITD_VAD_BAND_NUM]; +#endif int16_t vad_frm_cnt; int16_t pre_vad; int16_t itd_nonzero_cnt; +#ifndef IVAS_FLOAT_FIXED float acorr_L[STEREO_DFT_BAND_MAX]; float acorr_R[STEREO_DFT_BAND_MAX]; float cohSNR; float itd_thres; +#endif int16_t valid_itd_cnt; /* Extra variable to store value of itd_cnt for fine-control decision making */ int16_t detected_itd_flag; int16_t itd_tracking; +#ifndef IVAS_FLOAT_FIXED float prev_max; + float prev_avg_max; +#endif Word32 prev_max_fx; // Q31 int16_t prev_index; - float prev_avg_max; Word32 prev_avg_max_fx; Word16 prev_avg_max_fx_e; #ifndef IVAS_FLOAT_FIXED @@ -82,9 +92,11 @@ typedef struct stereo_itd_data_struct Word16 currFlatness_fx; /* Xtalk classifier */ +#ifndef IVAS_FLOAT_FIXED float prev_m1; - Word32 prev_m1_fx; // Q31 float prev_m2; +#endif + Word32 prev_m1_fx; // Q31 Word32 prev_m2_fx; // Q31 int16_t prev_itd1; int16_t prev_itd2; @@ -122,9 +134,11 @@ typedef struct dft_ana_struct int16_t dft_ovl; /* Overlap size */ int16_t dft_zp; /* Zero padding */ +#ifndef IVAS_FLOAT_FIXED const float *win_ana; /* DFT analysis window */ const float *dft_trigo; const float *dft_trigo_32k; +#endif const Word16 *win_ana_fx; /* DFT analysis window */ const Word16 *dft_trigo_fx; @@ -854,7 +868,7 @@ typedef struct ivas_stereo_classifier_data_structure Word32 xtalk_wscore_fx; // Q31 Word32 xtalk_score_fx; // Q31 Word32 xtalk_score_wrelE_fx; // Q31 - Word32 is_speech_fx; // Q9 + Word32 is_speech_fx; // Q25 } STEREO_CLASSIF_DATA, *STEREO_CLASSIF_HANDLE; @@ -938,10 +952,24 @@ typedef struct ivas_dirac_enc_data_structure float sec_I_vec_smth_x[NUM_ANA_SECTORS][IVAS_MAX_NUM_BANDS]; float sec_I_vec_smth_y[NUM_ANA_SECTORS][IVAS_MAX_NUM_BANDS]; float sec_I_vec_smth_z[NUM_ANA_SECTORS][IVAS_MAX_NUM_BANDS]; +#ifdef IVAS_FLOAT_FIXED + Word32 sec_I_vec_smth_x_fx[NUM_ANA_SECTORS][IVAS_MAX_NUM_BANDS]; + Word16 sec_I_vec_smth_x_exp[NUM_ANA_SECTORS][IVAS_MAX_NUM_BANDS]; + Word32 sec_I_vec_smth_y_fx[NUM_ANA_SECTORS][IVAS_MAX_NUM_BANDS]; + Word16 sec_I_vec_smth_y_exp[NUM_ANA_SECTORS][IVAS_MAX_NUM_BANDS]; + Word32 sec_I_vec_smth_z_fx[NUM_ANA_SECTORS][IVAS_MAX_NUM_BANDS]; + Word16 sec_I_vec_smth_z_exp[NUM_ANA_SECTORS][IVAS_MAX_NUM_BANDS]; +#endif float energy_smth[NUM_ANA_SECTORS][IVAS_MAX_NUM_BANDS]; float azi_prev[NUM_ANA_SECTORS * IVAS_MAX_NUM_BANDS]; float ele_prev[NUM_ANA_SECTORS * IVAS_MAX_NUM_BANDS]; +#ifdef IVAS_FLOAT_FIXED + Word32 energy_smth_fx[NUM_ANA_SECTORS][IVAS_MAX_NUM_BANDS]; + Word16 energy_smth_exp[NUM_ANA_SECTORS][IVAS_MAX_NUM_BANDS]; + Word32 azi_prev_fx[NUM_ANA_SECTORS * IVAS_MAX_NUM_BANDS]; + Word32 ele_prev_fx[NUM_ANA_SECTORS * IVAS_MAX_NUM_BANDS]; +#endif /* diffuseness */ diff --git a/lib_enc/ivas_stereo_classifier.c b/lib_enc/ivas_stereo_classifier.c index 1b1d27c34f638a067902e63be97058e4e3c96786..a0872c08e45777919f7479150bce8120b0d37333 100644 --- a/lib_enc/ivas_stereo_classifier.c +++ b/lib_enc/ivas_stereo_classifier.c @@ -249,8 +249,9 @@ Word16 select_stereo_mode( move16(); /* reset stereo classifier when switching from MDCT stereo to Unified stereo */ +#ifndef IVAS_FLOAT_FIXED stereo_classifier_init( hCPE->hStereoClassif ); -#ifdef IVAS_FLOAT_FIXED +#else stereo_classifier_init_fx( hCPE->hStereoClassif ); #endif hStereoClassif->lrtd_mode = lrtd_mode; @@ -381,9 +382,6 @@ int16_t select_stereo_mode( /* reset stereo classifier when switching from MDCT stereo to Unified stereo */ stereo_classifier_init( hCPE->hStereoClassif ); -#ifdef IVAS_FLOAT_FIXED - stereo_classifier_init_fx( hCPE->hStereoClassif ); -#endif hStereoClassif->lrtd_mode = lrtd_mode; } @@ -408,6 +406,7 @@ int16_t select_stereo_mode( } #endif +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * Function stereo_classifier_init() * @@ -421,7 +420,6 @@ void stereo_classifier_init( /* initialization of features for xtalk classifier and UNCLR classifier */ hStereoClassif->clas_ch1 = 0; set_s( hStereoClassif->pitch_ch1, 0, 3 ); -#ifndef IVAS_FLOAT_FIXED set_f( hStereoClassif->voicing_ch1, 0.0f, 3 ); hStereoClassif->cor_map_sum_ch1 = 0.0f; set_f( hStereoClassif->lsf_ch1, 0.0f, M ); @@ -439,46 +437,38 @@ void stereo_classifier_init( hStereoClassif->prev_g_IPD = 0.5f; hStereoClassif->prev_IPD = 0.0f; hStereoClassif->prev_ratio_m1_m2 = 0.0f; -#endif -#ifndef IVAS_FLOAT_FIXED set_f( hStereoClassif->xtalk_score_buf, 0.0f, XTALK_SCORE_BUF_LEN ); hStereoClassif->ratio_L = 0.5f; -#endif hStereoClassif->vad_flag_glob = 0; hStereoClassif->vad_relE = 0; + hStereoClassif->is_speech = 0.0f; set_s( hStereoClassif->aEn_raw, 0, CPE_CHANNELS ); -#ifndef IVAS_FLOAT_FIXED - hStereoClassif->is_speech = 0.0f; + hStereoClassif->Etot_dn = 0.0f; hStereoClassif->Etot_up = 0.0f; + set_f( hStereoClassif->relE_buf, 0.0f, UNCLR_L_RELE ); set_f( hStereoClassif->Etot_buf, 0.0f, UNCLR_L_ETOT ); -#endif -#ifndef IVAS_FLOAT_FIXED set_f( hStereoClassif->unclr_relE_0_1_LT, 0.0f, UNCLR_RC_ORDER ); -#endif + hStereoClassif->unclr_sw_enable_cnt[0] = 0; hStereoClassif->unclr_sw_enable_cnt[1] = 0; hStereoClassif->unclr_decision = 0; -#ifndef IVAS_FLOAT_FIXED hStereoClassif->unclr_wscore = 0.0f; + set_f( hStereoClassif->unclr_fv, -1.0f, SSC_MAX_NFEA ); -#endif hStereoClassif->unclr_corrLagMax_prev = 0; -#ifndef IVAS_FLOAT_FIXED hStereoClassif->ave_ener_L = 0; hStereoClassif->ave_ener_R = 0; hStereoClassif->relE_0_1 = 0.01f; hStereoClassif->relE_0_1_LT = 0.01f; -#endif -#ifndef IVAS_FLOAT_FIXED + set_f( hStereoClassif->xtalk_fv, -1.0f, SSC_MAX_NFEA ); hStereoClassif->xtalk_wscore = 0.0f; - hStereoClassif->xtalk_score_wrelE = 0.0f; -#endif hStereoClassif->xtalk_decision = 0; + hStereoClassif->xtalk_score_wrelE = 0.0f; hStereoClassif->lrtd_mode = 0; hStereoClassif->prev_lrtd_mode = 0; @@ -487,7 +477,13 @@ void stereo_classifier_init( return; } -#ifdef IVAS_FLOAT_FIXED +#else +/*-------------------------------------------------------------------* + * Function stereo_classifier_init_fx() + * + * Initialize stereo classifier handle + *-------------------------------------------------------------------*/ + void stereo_classifier_init_fx( STEREO_CLASSIF_HANDLE hStereoClassif /* i/o: stereo classifier structure */ ) @@ -546,12 +542,12 @@ void stereo_classifier_init_fx( move16(); hStereoClassif->prev_g_IPD_fx = ONE_IN_Q28; // 0.5f in Q29 move32(); - hStereoClassif->prev_IPD_fx = 0; + hStereoClassif->prev_IPD_fx = 0; // Q29 move32(); - hStereoClassif->prev_ratio_m1_m2_fx = 0; + hStereoClassif->prev_ratio_m1_m2_fx = 0; // Q31 move32(); set_zero_fx( hStereoClassif->xtalk_score_buf_fx, XTALK_SCORE_BUF_LEN ); - hStereoClassif->ratio_L_fx = 1073741824; // Q31 + hStereoClassif->ratio_L_fx = ONE_IN_Q30; // 0.5f in Q31 move32(); hStereoClassif->ratio_L_e = 0; // Q31 move16(); @@ -559,7 +555,7 @@ void stereo_classifier_init_fx( move16(); hStereoClassif->vad_relE = 0; move16(); - hStereoClassif->is_speech_fx = 0; // Q31 + hStereoClassif->is_speech_fx = 0; // Q25 move32(); set16_fx( hStereoClassif->aEn_raw, 0, CPE_CHANNELS ); @@ -591,7 +587,7 @@ void stereo_classifier_init_fx( hStereoClassif->unclr_wscore_fx = 0; move32(); - set32_fx( hStereoClassif->unclr_fv_fx, -32768, SSC_MAX_NFEA ); // Q15 + set32_fx( hStereoClassif->unclr_fv_fx, -ONE_IN_Q15, SSC_MAX_NFEA ); // Q15 hStereoClassif->unclr_corrLagMax_prev = 0; move16(); hStereoClassif->ave_ener_L_fx = 0; @@ -607,12 +603,12 @@ void stereo_classifier_init_fx( hStereoClassif->relE_0_1_LT_fx = 21474836; // 0.01f in Q31 move32(); - set32_fx( hStereoClassif->xtalk_fv_fx, -32768, SSC_MAX_NFEA ); // Q15 - hStereoClassif->xtalk_wscore_fx = 0; + set32_fx( hStereoClassif->xtalk_fv_fx, -ONE_IN_Q15, SSC_MAX_NFEA ); // Q15 + hStereoClassif->xtalk_wscore_fx = 0; // Q31 move32(); hStereoClassif->xtalk_decision = 0; move16(); - hStereoClassif->xtalk_score_wrelE_fx = 0; + hStereoClassif->xtalk_score_wrelE_fx = 0; // Q31 move32(); hStereoClassif->lrtd_mode = 0; @@ -626,6 +622,8 @@ void stereo_classifier_init_fx( return; } #endif + + /*-----------------------------------------------------------------* * stereo_classifier_features() * diff --git a/lib_enc/ivas_stereo_dft_enc.c b/lib_enc/ivas_stereo_dft_enc.c index 95be17fb57f2f1d791eb78937f6ab7824a6b0064..f4afc47ab1b9145e03dbbcb33ae6d06b4bd0855a 100644 --- a/lib_enc/ivas_stereo_dft_enc.c +++ b/lib_enc/ivas_stereo_dft_enc.c @@ -1074,8 +1074,10 @@ void stereo_dft_enc_reset( hStereoDft->coh_fade_counter = 0; /* Xtalk classifier */ +#ifndef IVAS_FLOAT_FIXED hStereoDft->hItd->prev_m1 = 0; hStereoDft->hItd->prev_m2 = 0; +#endif hStereoDft->hItd->prev_itd1 = 0; hStereoDft->hItd->prev_itd2 = 0; @@ -1270,38 +1272,46 @@ void stereo_enc_itd_init( ) { hItd->prev_itd = 0; +#ifndef IVAS_FLOAT_FIXED set_zero( hItd->itd, STEREO_DFT_ENC_DFT_NB ); set_zero( hItd->deltaItd, STEREO_DFT_ENC_DFT_NB ); +#endif set_s( hItd->td_itd, 0, STEREO_DFT_ENC_DFT_NB ); set_s( hItd->td_itd_32k, 0, STEREO_DFT_ENC_DFT_NB ); set_s( hItd->itd_index, 0, STEREO_DFT_ENC_DFT_NB ); +#ifndef IVAS_FLOAT_FIXED set_zero( hItd->xcorr_smooth, STEREO_DFT_N_32k_ENC ); hItd->lp_phat_peak = 0.f; +#endif hItd->itd_hangover = 0; hItd->itd_cnt = 0; +#ifndef IVAS_FLOAT_FIXED hItd->prev_sum_nrg_L_lb = 0.f; set_zero( hItd->prev_xcorr_lb, STEREO_DFT_XCORR_LB_MAX ); set_f( hItd->E_band_n, (float) ITD_VAD_E_BAND_N_INIT, STEREO_DFT_ITD_VAD_BAND_NUM ); +#endif hItd->vad_frm_cnt = 0; hItd->pre_vad = 0; hItd->itd_nonzero_cnt = 0; +#ifndef IVAS_FLOAT_FIXED set_zero( hItd->acorr_L, STEREO_DFT_BAND_MAX ); set_zero( hItd->acorr_R, STEREO_DFT_BAND_MAX ); hItd->cohSNR = 15.f; hItd->itd_thres = 0.f; +#endif hItd->valid_itd_cnt = 0; hItd->detected_itd_flag = 0; hItd->itd_tracking = 0; - hItd->prev_max = 0.f; hItd->prev_index = 0; - hItd->prev_avg_max = 0.f; #ifndef IVAS_FLOAT_FIXED + hItd->prev_max = 0.f; + hItd->prev_avg_max = 0.f; hItd->currFlatness = 0.f; -#endif /* Xtalk classifier */ hItd->prev_m1 = 0; hItd->prev_m2 = 0; +#endif hItd->prev_itd1 = 0; hItd->prev_itd2 = 0; diff --git a/lib_enc/ivas_stereo_dft_td_itd.c b/lib_enc/ivas_stereo_dft_td_itd.c index 5c7b73a015153d7b22a90266cf773e68a218eb04..a61ee2250a45c69da0b95122a669b6f5637a5005 100644 --- a/lib_enc/ivas_stereo_dft_td_itd.c +++ b/lib_enc/ivas_stereo_dft_td_itd.c @@ -89,6 +89,7 @@ const Word16 wac_swb_l_fx[LPC_SHB_ORDER + 1] = { * * ---------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED static void stereo_td_get_td_itd( int16_t *td_itd, /* o : td_itd in samples at sampling frequency */ int16_t *td_itd_32, /* o : td_itd in samples at 32kHz */ @@ -114,8 +115,7 @@ static void stereo_td_get_td_itd( return; } - -#ifdef IVAS_FLOAT_FIXED +#else static void stereo_td_get_td_itd_fx( Word16 *td_itd, /* o : td_itd in samples at sampling frequency */ Word16 *td_itd_32, /* o : td_itd in samples at 32kHz */ @@ -160,6 +160,7 @@ static void stereo_td_get_td_itd_fx( * * ---------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED static void stereo_td_channel_extrapolate( Encoder_State **sts, const int16_t dft_ovl, @@ -287,8 +288,7 @@ static void stereo_td_channel_extrapolate( return; } - -#ifdef IVAS_FLOAT_FIXED +#else static void stereo_td_channel_extrapolate_fx( Encoder_State **sts, const Word16 dft_ovl, @@ -477,6 +477,7 @@ static void stereo_td_channel_extrapolate_fx( * * ---------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED void stereo_td_itd( ITD_DATA *hITD, /* i/o: ITD data structure */ float input_mem_itd[CPE_CHANNELS][STEREO_DFT_OVL_MAX], /* o : ITD memory (only used in DFT Stereo) */ @@ -600,8 +601,7 @@ void stereo_td_itd( return; } - -#ifdef IVAS_FLOAT_FIXED +#else void stereo_td_itd_fx( ITD_DATA *hITD, /* i/o: ITD data structure */ Word16 input_mem_itd[CPE_CHANNELS][STEREO_DFT_OVL_MAX], /* o : ITD memory (only used in DFT Stereo) */ diff --git a/lib_enc/ivas_stereo_mdct_core_enc.c b/lib_enc/ivas_stereo_mdct_core_enc.c index dc927331afe29b67fd8c15f734cac20c5d002e74..3b8f329cc60145c6e84cea65a0b23a0b265ee86a 100644 --- a/lib_enc/ivas_stereo_mdct_core_enc.c +++ b/lib_enc/ivas_stereo_mdct_core_enc.c @@ -1483,10 +1483,6 @@ void stereo_mdct_core_enc( sts[0]->side_bits_frame_channel -= SMDCT_NBBITS_SPLIT_RATIO; if ( !hStereoMdct->isSBAStereoMode ) { -#ifdef IVAS_FLOAT_FIXED - IF( hStereoMdct->hItd ) - hStereoMdct->hItd->itd_fx[1] = float_to_fix( hStereoMdct->hItd->itd[1], Q23 ); -#endif stereo_bits = write_stereo_to_bitstream( hStereoMdct, sts, ms_mask, 0, hBstr ); } else diff --git a/lib_enc/ivas_stereo_mdct_stereo_enc.c b/lib_enc/ivas_stereo_mdct_stereo_enc.c index 5019512ebd2aae6c472f993f128f436cc85f47bc..da0cff0fe2b2f1dbe9906acc275bf3c41e8c485d 100644 --- a/lib_enc/ivas_stereo_mdct_stereo_enc.c +++ b/lib_enc/ivas_stereo_mdct_stereo_enc.c @@ -159,25 +159,6 @@ static void dft_ana_init( hDft_ana->win_ana_fx = win_ana_48k_fx; } -#if 1 // TODO: To be removed later - hDft_ana->dft_trigo_32k = dft_trigo_32k; - if ( input_Fs == 16000 ) - { - hDft_ana->dft_trigo = dft_trigo_32k; - hDft_ana->win_ana = win_ana_16k; - } - else if ( input_Fs == 32000 ) - { - hDft_ana->dft_trigo = dft_trigo_32k; - hDft_ana->win_ana = win_ana_32k; - } - else - { - hDft_ana->dft_trigo = dft_trigo_48k; - hDft_ana->win_ana = win_ana_48k; - } -#endif - return; } #endif @@ -250,7 +231,7 @@ static void write_itd_data_fx( k_offset = 1; move16(); - push_next_indice( hBstr, ( hItd->itd[k_offset] != 0 ), STEREO_DFT_ITD_MODE_NBITS ); + push_next_indice( hBstr, ( hItd->itd_fx[k_offset] != 0 ), STEREO_DFT_ITD_MODE_NBITS ); IF( hItd->itd_fx[k_offset] != 0 ) { @@ -2309,9 +2290,6 @@ ivas_error initMdctItdHandling( /*Initialize ITD parameters*/ stereo_enc_itd_init_fx( hStereoMdct->hItd ); -#if 1 // TODO: To be removed later - stereo_enc_itd_init( hStereoMdct->hItd ); -#endif /*Initialize DFT analysis parameters*/ dft_ana_init( hStereoMdct->hDft_ana, input_Fs ); diff --git a/lib_enc/ivas_stereo_switching_enc.c b/lib_enc/ivas_stereo_switching_enc.c index f6417d7244170387e40cb070dcd35c26e333d144..0dadad6693945dd3f4d016a2ed1dbaa73068178a 100644 --- a/lib_enc/ivas_stereo_switching_enc.c +++ b/lib_enc/ivas_stereo_switching_enc.c @@ -325,8 +325,8 @@ ivas_error stereo_memory_enc_fx( test(); IF( hCPE->hStereoTCA != NULL && EQ_16( hCPE->last_element_mode, IVAS_CPE_DFT ) ) { - set16_fx( hCPE->hStereoTCA->prevCorrLagStats, (Word16) hCPE->hStereoDft->hItd->itd[1], 3 ); - IF( hCPE->hStereoDft->hItd->itd[1] >= 0 ) + set16_fx( hCPE->hStereoTCA->prevCorrLagStats, (Word16) hCPE->hStereoDft->hItd->itd_fx[1], 3 ); + IF( hCPE->hStereoDft->hItd->itd_fx[1] >= 0 ) { hCPE->hStereoTCA->prevRefChanIndx = L_CH_INDX; } diff --git a/lib_enc/lib_enc.c b/lib_enc/lib_enc.c index 16e8868d69aaacfb14c94b2ff0e4565a0a3711db..7a60a2e1afdba0435297fed0932473762c7e84fe 100644 --- a/lib_enc/lib_enc.c +++ b/lib_enc/lib_enc.c @@ -1698,14 +1698,7 @@ ivas_error IVAS_ENC_EncodeFrameToSerial( IF( hIvasEnc->switchingActive && EQ_16( hEncoderConfig->ivas_format, MONO_FORMAT ) ) { test(); - IF( NE_16( st_ivas->hEncoderConfig->element_mode_init, EVS_MONO ) ) - { - copy_encoder_config( st_ivas, hCoreCoder, 0 ); - } - ELSE - { - copy_encoder_config_fx( st_ivas, hCoreCoder, 0 ); - } + copy_encoder_config_fx( st_ivas, hCoreCoder, 0 ); hEncoderConfig->last_ivas_total_brate = hEncoderConfig->ivas_total_brate; move32(); } diff --git a/lib_enc/ltd_stable_fx.c b/lib_enc/ltd_stable_fx.c index 5006202735a83f73d36e283c25e466b855296137..63ade58a8ce9eddacd3fb3d852aa0415ca57b67b 100644 --- a/lib_enc/ltd_stable_fx.c +++ b/lib_enc/ltd_stable_fx.c @@ -19,11 +19,11 @@ *-------------------------------------------------------------------*/ void ltd_stable_fx( - VAD_CLDFB_HANDLE_FX hVAD_CLDFB, /* i/o: CLDFB VAD state */ - Word16 *ltd_stable_rate, /* o : time-domain stable rate*/ - const Word32 frame_energy, /* i : current frame energy*/ - const Word16 frameloop, /* i : amount of frames*/ - const Word16 Q_frames_power /* i : the Scaling of frames_power*/ + VAD_CLDFB_HANDLE hVAD_CLDFB, /* i/o: CLDFB VAD state */ + Word16 *ltd_stable_rate, /* o : time-domain stable rate*/ + const Word32 frame_energy, /* i : current frame energy*/ + const Word16 frameloop, /* i : amount of frames*/ + const Word16 Q_frames_power /* i : the Scaling of frames_power*/ ) { diff --git a/lib_enc/mdct_selector_fx.c b/lib_enc/mdct_selector_fx.c index bb9de2fb922fb6395e55364847e3d7d5a56139ca..bcca279fcf2cb5cecd04c26d62d4fce20fcf3cd7 100644 --- a/lib_enc/mdct_selector_fx.c +++ b/lib_enc/mdct_selector_fx.c @@ -393,8 +393,9 @@ void MDCT_classifier_reset_fx( ) { hTcxEnc->clas_sec_old_fx = 8192; /* 1.0f in Q13 */ - ; + move16(); hTcxEnc->clas_final_old = 1; /* Q0 */ + move16(); hTcxEnc->last_gain1 = 0; move32(); hTcxEnc->last_gain2 = 0; diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 0fdab4955e64964c3cf58d9dd009ecf790890ba7..d113f7c4cffbf83766908b152e48c563b6ef902c 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -2354,11 +2354,7 @@ void IGFEncSetMode_fx( const Word16 rf_mode /* i : flag to signal the RF mode */ ); -Word16 vad_init_fx( T_CldfbVadState_fx *vad_state ); - -Word16 vad_init_ivas_fx( - VAD_CLDFB_HANDLE hVAD_CLDFB /* i/o: CLDFB VAD state */ -); +Word16 vad_init_fx( VAD_CLDFB_HANDLE vad_state ); void init_PLC_enc_fx( PLC_ENC_EVS_HANDLE hPlcExt, @@ -2853,7 +2849,7 @@ void midlsf_enc_fx( const Word16 coder_type ); Word16 vad_proc_fx( - VAD_CLDFB_HANDLE_FX hVAD_CLDFB, /* i/o: CLDFB VAD state */ + VAD_CLDFB_HANDLE hVAD_CLDFB, /* i/o: CLDFB VAD state */ Word32 realBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i : real values */ Word32 imagBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i : imag values */ Word16 riBuffer_exp, /* i : exponent of real & imag Buffer */ @@ -2878,15 +2874,15 @@ void calc_lf_snr_fx( ); void calc_lt_snr_fx( - VAD_CLDFB_HANDLE_FX hVAD_CLDFB, /* i/o: CLDFB VAD state */ - Word32 *lt_snr_org_fp, /* o : original long time SNR*/ - Word32 *lt_snr_fp, /* o : long time SNR calculated by fg_energy and bg_energy*/ - Word32 fg_energy, /* i : foreground energy sum */ - Word16 fg_energy_count, /* i : amount of the foreground energy frame */ - Word32 bg_energy, /* i : background energy sum */ - Word16 bg_energy_count, /* i : amount of the background energy frame */ - Word16 bw_index, /* i : band width index*/ - Word16 lt_noise_sp_center0 /* i : long time noise spectral center by 0*/ + VAD_CLDFB_HANDLE hVAD_CLDFB, /* i/o: CLDFB VAD state */ + Word32 *lt_snr_org_fp, /* o : original long time SNR*/ + Word32 *lt_snr_fp, /* o : long time SNR calculated by fg_energy and bg_energy*/ + Word32 fg_energy, /* i : foreground energy sum */ + Word16 fg_energy_count, /* i : amount of the foreground energy frame */ + Word32 bg_energy, /* i : background energy sum */ + Word16 bg_energy_count, /* i : amount of the background energy frame */ + Word16 bw_index, /* i : band width index*/ + Word16 lt_noise_sp_center0 /* i : long time noise spectral center by 0*/ ); void calc_snr_flux_fx( Word32 tsnr_fix, /*(i) time-domain SNR*/ @@ -2903,24 +2899,24 @@ Word16 vlpc_2st_cod_fx( /* o : number of allocated bits ); Word16 update_decision_fx( - VAD_CLDFB_HANDLE_FX hVAD_CLDFB, /* i/o: CLDFB VAD state */ - const Word32 frame_energy, /* i : current frame energy*/ - Word32 HB_Power, /* i : current frame high frequency energy*/ - const Word16 frameloop, /* i : amount of frames*/ - const Word16 bw, /* i : band width index*/ - const Word16 frame_energy_Q, /* i : the Scaling of current frame energy*/ - const Word16 HB_Power_Q, /* i : the Scaling of current frame high frequency energy*/ - const Word32 snr, /* i : frequency domain SNR */ - const Word32 tsnr, /* i : time domain SNR */ - const Word16 vad_flag, /* i : VAD flag */ - const Word16 music_backgound_f /* i : background music flag*/ + VAD_CLDFB_HANDLE hVAD_CLDFB, /* i/o: CLDFB VAD state */ + const Word32 frame_energy, /* i : current frame energy*/ + Word32 HB_Power, /* i : current frame high frequency energy*/ + const Word16 frameloop, /* i : amount of frames*/ + const Word16 bw, /* i : band width index*/ + const Word16 frame_energy_Q, /* i : the Scaling of current frame energy*/ + const Word16 HB_Power_Q, /* i : the Scaling of current frame high frequency energy*/ + const Word32 snr, /* i : frequency domain SNR */ + const Word32 tsnr, /* i : time domain SNR */ + const Word16 vad_flag, /* i : VAD flag */ + const Word16 music_backgound_f /* i : background music flag*/ ); void bg_music_decision_fx( - VAD_CLDFB_HANDLE_FX hVAD_CLDFB, /* i/o: CLDFB VAD state */ - Word16 *music_backgound_f, /*(i) background music flag*/ - Word32 frame_energy, /*(i) current frame energy 1*/ - Word16 frame_energy_Q /*(i) the Scaling of current frame energy*/ + VAD_CLDFB_HANDLE hVAD_CLDFB, /* i/o: CLDFB VAD state */ + Word16 *music_backgound_f, /*(i) background music flag*/ + Word32 frame_energy, /*(i) current frame energy 1*/ + Word16 frame_energy_Q /*(i) the Scaling of current frame energy*/ ); void spec_center_fx( @@ -2958,11 +2954,11 @@ void MDCT_classifier_reset_fx( ); void ltd_stable_fx( - VAD_CLDFB_HANDLE_FX hVAD_CLDFB, /* i/o: CLDFB VAD state */ - Word16 *ltd_stable_rate, /* o : time-domain stable rate*/ - const Word32 frame_energy, /* i : current frame energy*/ - const Word16 frameloop, /* i : amount of frames*/ - const Word16 Q_frames_power /* i : the Scaling of frames_power*/ + VAD_CLDFB_HANDLE hVAD_CLDFB, /* i/o: CLDFB VAD state */ + Word16 *ltd_stable_rate, /* o : time-domain stable rate*/ + const Word32 frame_energy, /* i : current frame energy*/ + const Word16 frameloop, /* i : amount of frames*/ + const Word16 Q_frames_power /* i : the Scaling of frames_power*/ ); /* IGFSCFEncoder.c */ void IGFSCFEncoderOpen_fx( @@ -2998,10 +2994,10 @@ void IGFSCFEncoderRestoreContextState_fx( ); void frame_spec_dif_cor_rate_fx( - VAD_CLDFB_HANDLE_FX hVAD_CLDFB, /* i/o: CLDFB VAD state */ - Word32 *spec_amp, /* i : spectral amplitude*/ - Word16 sacle, /* i : the scaling of spec_amp*/ - Word16 f_tonality_rate[3] /* o : tonality rate*/ + VAD_CLDFB_HANDLE hVAD_CLDFB, /* i/o: CLDFB VAD state */ + Word32 *spec_amp, /* i : spectral amplitude*/ + Word16 sacle, /* i : the scaling of spec_amp*/ + Word16 f_tonality_rate[3] /* o : tonality rate*/ ); void est_energy_fx( @@ -3020,11 +3016,11 @@ void est_energy_fx( ); void background_update_fx( - VAD_CLDFB_HANDLE_FX hVAD_CLDFB, /* i/o: CLDFB VAD state */ - Word16 scale, /* i : the scaling of frame energy*/ - Word32 frame_energy, /* i : current frame energy*/ - Word32 update_flag, /* i : update flag*/ - Word16 music_backgound_f, /* i : background music flag*/ + VAD_CLDFB_HANDLE hVAD_CLDFB, /* i/o: CLDFB VAD state */ + Word16 scale, /* i : the scaling of frame energy*/ + Word32 frame_energy, /* i : current frame energy*/ + Word32 update_flag, /* i : update flag*/ + Word16 music_backgound_f, /* i : background music flag*/ Word32 snr ); /* enc_gain.c */ @@ -3057,7 +3053,7 @@ void core_acelp_tcx20_switching_fx( Word16 shift ); Word16 comvad_decision_fx( - VAD_CLDFB_HANDLE_FX hVAD_CLDFB, /* i/o: CLDFB VAD state */ + VAD_CLDFB_HANDLE hVAD_CLDFB, /* i/o: CLDFB VAD state */ const Word32 l_snr, /*(i) long time frequency domain*/ const Word32 lt_snr_org, /*(i) original long time SNR*/ const Word32 lt_snr, /*(i) long time SNR calculated by fg_energy and bg_energy*/ @@ -3074,12 +3070,12 @@ void amr_wb_enc_init_fx( ); void snr_calc( - VAD_CLDFB_HANDLE_FX hVAD_CLDFB, /* i/o: CLDFB VAD state */ - const Word16 sacle_sbpower, /* i : the Scaling of sbpower*/ - Word32 *snr, /* o : frequency domain SNR */ - Word32 *tsnr, /* o : time domain SNR */ - const Word32 frame_energy, /* i : current frame energy */ - const Word32 bwidth /* i : audio band width*/ + VAD_CLDFB_HANDLE hVAD_CLDFB, /* i/o: CLDFB VAD state */ + const Word16 sacle_sbpower, /* i : the Scaling of sbpower*/ + Word32 *snr, /* o : frequency domain SNR */ + Word32 *tsnr, /* o : time domain SNR */ + const Word32 frame_energy, /* i : current frame energy */ + const Word32 bwidth /* i : audio band width*/ ); void FEC_encode_fx( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ @@ -4342,11 +4338,13 @@ ivas_error init_encoder_fx( Encoder_State *st_fx /* i/o: Encoder static variables structure */ ); +#ifdef IVAS_FLOAT_FIXED void copy_encoder_config_fx( Encoder_Struct *st_ivas, /* i : IVAS encoder structure */ Encoder_State *st, /* o : encoder state structure */ const Word16 flag_all /* i : flag 1==update all, 0=partial update*/ ); +#endif void destroy_encoder_fx( Encoder_State *st_fx /* i/o: Encoder static variables structure */ diff --git a/lib_enc/stat_enc.h b/lib_enc/stat_enc.h index 2efcd9aa7978c838815560dd7f173bb285455b63..b1a97be46b9f32badb36964d04f61772a13d2159 100644 --- a/lib_enc/stat_enc.h +++ b/lib_enc/stat_enc.h @@ -275,79 +275,98 @@ typedef struct cldfb_vad_structure int16_t bw_index; /* index of band width */ /* feature */ - float sp_center[SP_CENTER_NUM]; /* spectral center*/ - float ltd_stable_rate[STABLE_NUM]; /* time-domain stable rate*/ - - float sfm[SFM_NUM]; /* spectral flatness*/ - - float f_tonality_rate[TONA_NUM]; /* tonality rate*/ - float frame_sb_energy[BG_ENG_NUM]; /* energy of sub-band divided non-uniformly*/ - float frames_power[POWER_NUM]; /* energy of several frames*/ - +#ifndef IVAS_FLOAT_FIXED + float sp_center[SP_CENTER_NUM]; /* spectral center*/ + float ltd_stable_rate[STABLE_NUM]; /* time-domain stable rate*/ + float sfm[SFM_NUM]; /* spectral flatness*/ + float f_tonality_rate[TONA_NUM]; /* tonality rate*/ + float frame_sb_energy[BG_ENG_NUM]; /* energy of sub-band divided non-uniformly*/ + float frames_power[POWER_NUM]; /* energy of several frames*/ float pre_spec_low_dif[PRE_SPEC_DIF_NUM]; /* low frequency spectral different*/ - - float t_bg_energy; /* time background energy of several frames*/ - Word32 t_bg_energy_fx; /* time background energy of several frames*/ - float t_bg_energy_sum; /* number of time background energy*/ - Word32 t_bg_energy_sum_fx; /* number of time background energy*/ - int16_t tbg_energy_count; /* sum of time background energy of several frames*/ - int16_t bg_update_count; /* time of background update*/ - float frame_energy_smooth; /* smoothed energy of several frames*/ - Word32 frame_energy_smooth_fx; /* smoothed energy of several frames*/ + float t_bg_energy; /* time background energy of several frames*/ + float t_bg_energy_sum; /* number of time background energy*/ +#else + Word16 sp_center[SP_CENTER_NUM]; /* spectral center*/ + Word16 ltd_stable_rate[STABLE_NUM]; /* time-domain stable rate*/ + Word16 sfm[SFM_NUM]; /* spectral flatness*/ + Word16 f_tonality_rate[TONA_NUM]; /* tonality rate*/ + Word16 pre_spec_low_dif[PRE_SPEC_DIF_NUM]; /* low frequency spectral different*/ + Word16 scale_spec_low_dif; /* the Scaling of spec_low_dif*/ + Word32 frames_power_32[POWER_NUM]; /* energy of several frames*/ + Word16 Q_frames_power_32; /* the Scaling of frames_power_32*/ + Word32 frame_sb_energy[BG_ENG_NUM]; /* energy of sub-band divided non-uniformly*/ + Word16 frame_sb_energy_scale; /* the Scaling of frame_sb_energy*/ + Word32 t_bg_energy; /* time background energy of several frames*/ + Word16 scale_t_bg_energy; /* the Scaling of t_bg_energy*/ + T_VAD_EXP t_bg_energy_sum; /* number of time background energy*/ +#endif + int16_t tbg_energy_count; /* sum of time background energy of several frames*/ + int16_t bg_update_count; /* time of background update*/ +#ifndef IVAS_FLOAT_FIXED + float frame_energy_smooth; /* smoothed energy of several frames*/ +#else + Word32 frame_energy_smooth; /* smoothed energy of several frames*/ + Word16 frame_energy_smooth_scale; /* the Scaling of frame_energy_smooth*/ +#endif /* history parameters */ +#ifndef IVAS_FLOAT_FIXED float smooth_spec_amp[SPEC_AMP_NUM]; /* smoothed spectral amplitude*/ float sb_bg_energy[BG_ENG_NUM]; /* sub-band background energy*/ float pre_snr[PRE_SNR_NUM]; /* previous time SNR*/ - - float lt_snr_org; /* original long time SNR*/ - float lf_snr_smooth; /* smoothed lf_snr*/ - float l_silence_snr; /* sum of snr's of non active frames*/ - float l_speech_snr; /* sum of snr's of active frames*/ - Word32 lt_snr_org_fx; /* original long time SNR*/ - Word32 lf_snr_smooth_fx; /* smoothed lf_snr*/ - Word16 l_silence_snr_fx; /* sum of snr's of non active frames*/ - Word32 l_speech_snr_fx; /* sum of snr's of active frames*/ - int16_t l_silence_snr_count; /* number of non active frames*/ - int16_t l_speech_snr_count; /* number of active frames*/ - float fg_energy; /* foreground energy sum */ - float bg_energy; /* background energy sum */ - Word32 fg_energy_fx; /* foreground energy sum */ - Word32 bg_energy_fx; /* background energy sum */ - int16_t fg_energy_count; /* number of the foreground energy frame */ - int16_t bg_energy_count; /* number of the background energy frame */ - int16_t fg_energy_est_start; /* flag by that indicate whether if estimate energy*/ - int16_t speech_flag; /* residual number of hangover 1 */ - int16_t continuous_noise_num; /* time of continuous noise frames*/ - int16_t continuous_speech_num; /* time of continuous speech frames*/ - int16_t continuous_speech_num2; /* time 2 of continuous speech frames*/ - int16_t frameloop; /* number of frame*/ - float tonality_rate3; /* tonality rate*/ - float music_background_rate; /* music background rate*/ - float lt_noise_sp_center_diff_sum; /* different sum of long time noise sp_center*/ - float lt_noise_sp_center_diff_counter; /* number of the member lt_noise_sp_center_diff_sum*/ - float lt_noise_sp_center0; /* long time noise sp_center0*/ - float lt_noise_sp_center3; /* long time noise sp_center3*/ - float lt_bg_highf_eng; /* average of long time high frequency energy*/ - Word16 f_tonality_rate_fx[TONA_NUM]; /* tonality rate*/ - Word32 frame_sb_energy_fx[BG_ENG_NUM]; /* energy of sub-band divided non-uniformly*/ - Word32 frames_power_fx[POWER_NUM]; /* energy of several frames*/ - Word16 pre_spec_low_dif_fx[PRE_SPEC_DIF_NUM]; /* low frequency spectral different*/ - Word32 smooth_spec_amp_fx[SPEC_AMP_NUM]; /* smoothed spectral amplitude*/ - Word32 sb_bg_energy_fx[BG_ENG_NUM]; /* sub-band background energy*/ - Word32 pre_snr_fx[PRE_SNR_NUM]; /* previous time SNR*/ - Word16 sfm_fx[SFM_NUM]; /* spectral flatness*/ - Word16 sp_center_fx[SP_CENTER_NUM]; /* spectral center*/ - Word16 ltd_stable_rate_fx[STABLE_NUM]; /* time-domain stable rate*/ - Word16 tonality_rate3_fx; /* tonality rate*/ - Word16 music_background_rate_fx; /* music background rate*/ - Word16 lt_noise_sp_center_diff_sum_fx; /* different sum of long time noise sp_center*/ - Word32 lt_noise_sp_center_diff_counter_fx; /* number of the member lt_noise_sp_center_diff_sum*/ - Word16 lt_noise_sp_center0_fx; /* long time noise sp_center0*/ - Word16 lt_noise_sp_center3_fx; /* long time noise sp_center3*/ - Word32 lt_bg_highf_eng_fx; /* average of long time high frequency energy*/ - int16_t update_num_with_snr_fx; /* the number of the background update with SNR*/ - + float lt_snr_org; /* original long time SNR*/ + float lf_snr_smooth; /* smoothed lf_snr*/ + float l_silence_snr; /* sum of snr's of non active frames*/ + float l_speech_snr; /* sum of snr's of active frames*/ + int16_t l_silence_snr_count; /* number of non active frames*/ + int16_t l_speech_snr_count; /* number of active frames*/ + float fg_energy; /* foreground energy sum */ + float bg_energy; /* background energy sum */ +#else + Word32 smooth_spec_amp[SPEC_AMP_NUM]; /* smoothed spectral amplitude*/ + Word32 sb_bg_energy[BG_ENG_NUM]; /* sub-band background energy*/ + Word16 sb_bg_energy_scale; /* the Scaling of sb_bg_energy*/ + Word32 pre_snr[PRE_SNR_NUM]; /* previous time SNR*/ + Word32 lt_snr_org; /* original long time SNR*/ + Word32 lf_snr_smooth; /* smoothed lf_snr*/ + Word32 l_silence_snr; /* sum of snr's of non active frames*/ + Word32 l_speech_snr; /* sum of snr's of active frames*/ + Word32 l_silence_snr_count; /* number of non active frames*/ + Word32 l_speech_snr_count; /* number of active frames*/ + Word32 fg_energy; /* foreground energy sum */ + Word16 fg_energy_scale; /* the Scaling of fg_energy*/ + Word32 bg_energy; /* background energy sum */ + Word16 bg_energy_scale; /* the Scaling of bg_energy*/ +#endif + int16_t fg_energy_count; /* number of the foreground energy frame */ + int16_t bg_energy_count; /* number of the background energy frame */ +#ifndef IVAS_FLOAT_FIXED + int16_t fg_energy_est_start; /* flag by that indicate whether if estimate energy*/ +#else + Word32 fg_energy_est_start; /* flag by that indicate whether if estimate energy*/ +#endif + int16_t speech_flag; /* residual number of hangover 1 */ + int16_t continuous_noise_num; /* time of continuous noise frames*/ + int16_t continuous_speech_num; /* time of continuous speech frames*/ + int16_t continuous_speech_num2; /* time 2 of continuous speech frames*/ + int16_t frameloop; /* number of frame*/ +#ifndef IVAS_FLOAT_FIXED + float tonality_rate3; /* tonality rate*/ + float music_background_rate; /* music background rate*/ + float lt_noise_sp_center_diff_sum; /* different sum of long time noise sp_center*/ + float lt_noise_sp_center_diff_counter; /* number of the member lt_noise_sp_center_diff_sum*/ + float lt_noise_sp_center0; /* long time noise sp_center0*/ + float lt_noise_sp_center3; /* long time noise sp_center3*/ + float lt_bg_highf_eng; /* average of long time high frequency energy*/ +#else + Word16 tonality_rate3; /* tonality rate*/ + Word16 music_background_rate; /* music background rate*/ + Word32 lt_noise_sp_center_diff_sum; /* different sum of long time noise sp_center*/ + Word32 lt_noise_sp_center_diff_counter; /* number of the member lt_noise_sp_center_diff_sum*/ + Word16 lt_noise_sp_center0; /* long time noise sp_center0*/ + Word16 lt_noise_sp_center3; /* long time noise sp_center3*/ + Word32 lt_bg_highf_eng; /* average of long time high frequency energy*/ +#endif int16_t update_num_with_snr; /* the number of the background update with SNR*/ int16_t update_count; int16_t warm_hang_num; /* the number of hangover for warm up*/ @@ -355,68 +374,6 @@ typedef struct cldfb_vad_structure } T_CldfbVadState, *VAD_CLDFB_HANDLE; -typedef struct -{ - Word16 bw_index; /* index of band width */ - - /* feature */ - Word16 sp_center[SP_CENTER_NUM]; /* spectral center*/ - Word16 ltd_stable_rate[STABLE_NUM]; /* time-domain stable rate*/ - Word16 sfm[SFM_NUM]; /* spectral flatness*/ - Word16 f_tonality_rate[TONA_NUM]; /* tonality rate*/ - Word16 pre_spec_low_dif[PRE_SPEC_DIF_NUM]; /* low frequency spectral different*/ - Word32 frames_power_32[POWER_NUM]; /* energy of several frames*/ - Word32 frame_sb_energy[BG_ENG_NUM]; /* energy of sub-band divided non-uniformly*/ - Word32 t_bg_energy; /* time background energy of several frames*/ - T_VAD_EXP t_bg_energy_sum; /* number of time background energy*/ - Word16 tbg_energy_count; /* sum of time background energy of several frames*/ - Word16 bg_update_count; /* time of background update*/ - Word32 frame_energy_smooth; /* smoothed energy of several frames*/ - - /************************************************************************/ - /* history parameters */ - /************************************************************************/ - Word32 smooth_spec_amp[SPEC_AMP_NUM]; /* smoothed spectral amplitude*/ - Word32 pre_snr[PRE_SNR_NUM]; /* previous time SNR*/ - Word32 sb_bg_energy[BG_ENG_NUM]; /* sub-band background energy*/ - Word16 continuous_noise_num; /* time of continuous noise frames*/ - Word16 continuous_speech_num; /* time of continuous speech frames*/ - Word16 continuous_speech_num2; /* time 2 of continuous speech frames*/ - Word32 fg_energy_est_start; /* flag by that indicate whether if estimate energy*/ - Word16 speech_flag; /* residual number of hangover 1 */ - Word32 lt_noise_sp_center_diff_counter; /* number of the member lt_noise_sp_center_diff_sum*/ - Word32 fg_energy; /* foreground energy sum */ - Word32 bg_energy; /* background energy sum */ - Word32 lt_bg_highf_eng; /* average of long time high frequency energy*/ - Word32 lt_noise_sp_center_diff_sum; /* different sum of long time noise sp_center*/ - Word32 lt_snr_org; /* original long time SNR*/ - Word32 l_speech_snr; /* sum of snr's of active frames*/ - Word32 l_silence_snr; /* sum of snr's of non active frames*/ - Word32 l_speech_snr_count; /* number of active frames*/ - Word32 l_silence_snr_count; /* number of non active frames*/ - Word32 lf_snr_smooth; /* smoothed lf_snr*/ - Word16 frameloop; /* number of frame*/ - Word16 lt_noise_sp_center0; /* long time noise sp_center0*/ - Word16 lt_noise_sp_center3; /* long time noise sp_center3*/ - Word16 music_background_rate; /* music background rate*/ - Word16 tonality_rate3; /* tonality rate*/ - Word16 bg_energy_count; /* number of the background energy frame */ - Word16 fg_energy_count; /* number of the foreground energy frame */ - Word16 Q_frames_power_32; /* the Scaling of frames_power_fix32*/ - Word16 scale_spec_low_dif; /* the Scaling of spec_low_dif*/ - Word16 sb_bg_energy_scale; /* the Scaling of sb_bg_energy*/ - Word16 frame_sb_energy_scale; /* the Scaling of frame_sb_energy*/ - Word16 scale_t_bg_energy; /* the Scaling of t_bg_energy*/ - Word16 frame_energy_smooth_scale; /* the Scaling of frame_energy_smooth*/ - Word16 bg_energy_scale; /* the Scaling of bg_energy*/ - Word16 fg_energy_scale; /* the Scaling of fg_energy*/ - Word16 updateNumWithSnr; /* the number of the background update with SNR*/ - Word16 update_count; /* the number of the background update*/ - Word16 warm_hang_num; /* the number of hangover for warm up*/ - Word16 vad_flag_for_bk_update; -} T_CldfbVadState_fx, *VAD_CLDFB_HANDLE_FX; - - /*------------------------------------------------------------------------------------------* * DTX and TD CNG structure *------------------------------------------------------------------------------------------*/ @@ -2329,8 +2286,7 @@ typedef struct enc_core_structure VAD_HANDLE hVAD; VAD_CLDFB_HANDLE hVAD_CLDFB; - VAD_CLDFB_HANDLE_FX hVAD_CLDFB_fx; - T_CldfbVadState_fx vad_st; + T_CldfbVadState vad_st; int16_t vad_flag; /* i : VAD flag */ int16_t sharpFlag; @@ -2896,7 +2852,7 @@ typedef struct enc_core_structure // // VAD_HANDLE hVAD; // -// VAD_CLDFB_HANDLE_FX hVAD_CLDFB; +// VAD_CLDFB_HANDLE hVAD_CLDFB; // Word16 lp_speech_fx; // Word16 Opt_HE_SAD_ON_fx; // Word16 nb_active_frames_HE_SAD_fx; diff --git a/lib_enc/update_decision.c b/lib_enc/update_decision.c index 25e7a14d8eb59be0f95d9ddabb31b9f02e7d5ea2..5a31bc31407502ec6fc7f6dd400a73d17c75b125 100644 --- a/lib_enc/update_decision.c +++ b/lib_enc/update_decision.c @@ -41,6 +41,7 @@ #include "wmc_auto.h" +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * bg_music_decision() * @@ -285,3 +286,4 @@ int16_t update_decision( return update_flag; } +#endif diff --git a/lib_enc/update_decision_fx.c b/lib_enc/update_decision_fx.c index c161ac2563bbe1c976a7deccb8c1219d1b99374e..7fda8e5d2047fbc60d3bccab140d6b336b54c85c 100644 --- a/lib_enc/update_decision_fx.c +++ b/lib_enc/update_decision_fx.c @@ -16,10 +16,10 @@ * * -------------------------------------------------------------------*/ void bg_music_decision_fx( - VAD_CLDFB_HANDLE_FX hVAD_CLDFB, /* i/o: CLDFB VAD state */ - Word16 *music_backgound_f, /* i : background music flag*/ - Word32 frame_energy, /* i : current frame energy 1*/ - Word16 frame_energy_Q /* i : the Scaling of current frame energy*/ + VAD_CLDFB_HANDLE hVAD_CLDFB, /* i/o: CLDFB VAD state */ + Word16 *music_backgound_f, /* i : background music flag*/ + Word32 frame_energy, /* i : current frame energy 1*/ + Word16 frame_energy_Q /* i : the Scaling of current frame energy*/ ) { @@ -97,17 +97,17 @@ void bg_music_decision_fx( *-------------------------------------------------------------------*/ Word16 update_decision_fx( - VAD_CLDFB_HANDLE_FX hVAD_CLDFB, /* i/o: CLDFB VAD state */ - const Word32 frame_energy, /* i : current frame energy*/ - Word32 HB_Power, /* i : current frame high frequency energy*/ - const Word16 frameloop, /* i : amount of frames*/ - const Word16 bw, /* i : band width index*/ - const Word16 frame_energy_Q, /* i : the Scaling of current frame energy*/ - const Word16 HB_Power_Q, /* i : the Scaling of current frame high frequency energy*/ - const Word32 snr, /* i : frequency domain SNR */ - const Word32 tsnr, /* i : time domain SNR */ - const Word16 vad_flag, /* i : VAD flag */ - const Word16 music_backgound_f /* i : background music flag*/ + VAD_CLDFB_HANDLE hVAD_CLDFB, /* i/o: CLDFB VAD state */ + const Word32 frame_energy, /* i : current frame energy*/ + Word32 HB_Power, /* i : current frame high frequency energy*/ + const Word16 frameloop, /* i : amount of frames*/ + const Word16 bw, /* i : band width index*/ + const Word16 frame_energy_Q, /* i : the Scaling of current frame energy*/ + const Word16 HB_Power_Q, /* i : the Scaling of current frame high frequency energy*/ + const Word32 snr, /* i : frequency domain SNR */ + const Word32 tsnr, /* i : time domain SNR */ + const Word16 vad_flag, /* i : VAD flag */ + const Word16 music_backgound_f /* i : background music flag*/ ) { Word16 *sp_center = hVAD_CLDFB->sp_center; @@ -358,17 +358,17 @@ Word16 update_decision_fx( IF( update_flag == 0 ) { - hVAD_CLDFB->updateNumWithSnr = 0; + hVAD_CLDFB->update_num_with_snr = 0; } ELSE { test(); test(); - IF( vad_flag && GT_32( snr, 100663293 /* 3.0 Q25 */ ) && LT_16( hVAD_CLDFB->updateNumWithSnr, 10 ) ) + IF( vad_flag && GT_32( snr, 100663293 /* 3.0 Q25 */ ) && LT_16( hVAD_CLDFB->update_num_with_snr, 10 ) ) { update_flag = 0; move16(); - hVAD_CLDFB->updateNumWithSnr = add( hVAD_CLDFB->updateNumWithSnr, 1 ); + hVAD_CLDFB->update_num_with_snr = add( hVAD_CLDFB->update_num_with_snr, 1 ); } } diff --git a/lib_enc/vad_proc.c b/lib_enc/vad_proc.c index 8d9c02f3730ca66b7702626a41fe88f1b9a3e376..630b6b58c999ddd6b4a9851b300efe7168b532d2 100644 --- a/lib_enc/vad_proc.c +++ b/lib_enc/vad_proc.c @@ -42,6 +42,7 @@ #include "wmc_auto.h" +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * vad_init() * @@ -142,7 +143,6 @@ int16_t vad_init( } -#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * UpdateState() * diff --git a/lib_enc/vad_proc_fx.c b/lib_enc/vad_proc_fx.c index cf235d96df85522ef26ea0524d55c1dd6ce9c644..2c12ec9963d302a67c8be4af01c4e3d35b1563cd 100644 --- a/lib_enc/vad_proc_fx.c +++ b/lib_enc/vad_proc_fx.c @@ -21,7 +21,7 @@ * *-------------------------------------------------------------------*/ Word16 vad_init_fx( - VAD_CLDFB_HANDLE_FX hVAD_CLDFB /* i/o: CLDFB VAD state */ + VAD_CLDFB_HANDLE hVAD_CLDFB /* i/o: CLDFB VAD state */ ) { Word16 i = 0; @@ -33,261 +33,159 @@ Word16 vad_init_fx( hVAD_CLDFB->frameloop = 0; move16(); - hVAD_CLDFB->continuous_noise_num = 0; - move16(); - hVAD_CLDFB->continuous_speech_num = 0; - move16(); - hVAD_CLDFB->continuous_speech_num2 = 0; - move16(); - hVAD_CLDFB->fg_energy_est_start = L_deposit_l( 0 ); - hVAD_CLDFB->speech_flag = 0; - move16(); - hVAD_CLDFB->frame_sb_energy_scale = 0; - move16(); - hVAD_CLDFB->updateNumWithSnr = 0; - move16(); - hVAD_CLDFB->update_count = 0; - move16(); - hVAD_CLDFB->warm_hang_num = 0; - move16(); - - FOR( i = 0; i < SPEC_AMP_NUM; i++ ) - { - hVAD_CLDFB->smooth_spec_amp[i] = L_deposit_l( 0 ); - } - - FOR( i = 0; i < PRE_SNR_NUM; i++ ) - { - hVAD_CLDFB->pre_snr[i] = L_deposit_l( 0 ); - } - - FOR( i = 0; i < BG_ENG_NUM; i++ ) - { - hVAD_CLDFB->frame_sb_energy[i] = L_deposit_l( 0 ); - } - - hVAD_CLDFB->sfm[0] = 28835 /* 0.88 Q15 */; - move16(); - hVAD_CLDFB->sfm[1] = 30146 /* 0.92 Q15 */; - move16(); - hVAD_CLDFB->sfm[2] = 30146 /* 0.92 Q15 */; - move16(); - hVAD_CLDFB->l_silence_snr_count = L_deposit_l( 1 ); - hVAD_CLDFB->l_speech_snr_count = L_deposit_l( 1 ); hVAD_CLDFB->lt_snr_org = 33554432; move32(); hVAD_CLDFB->lf_snr_smooth = 167772155 /* 5.0 Q25 */; move32(); + hVAD_CLDFB->l_silence_snr = 32768 /* 0.5 Q16 */; + move32(); + hVAD_CLDFB->l_speech_snr = 327675 /* 5.0 Q16 */; + move32(); + hVAD_CLDFB->l_silence_snr_count = L_deposit_l( 1 ); + move32(); + hVAD_CLDFB->l_speech_snr_count = L_deposit_l( 1 ); + move32(); hVAD_CLDFB->fg_energy = 1073741824; move32(); hVAD_CLDFB->fg_energy_scale = 41; move16(); - hVAD_CLDFB->bg_energy = 1073741824; move32(); hVAD_CLDFB->bg_energy_scale = 57; move16(); + hVAD_CLDFB->fg_energy_count = 16; + move16(); + hVAD_CLDFB->bg_energy_count = 16; + move16(); + hVAD_CLDFB->tonality_rate3 = 15073 /* 0.46 Q15 */; + move16(); + hVAD_CLDFB->music_background_rate = 15073 /* 0.46 Q15 */; + move16(); + hVAD_CLDFB->lt_noise_sp_center_diff_sum = 409 /* 0.4 Q10 */; + move32(); hVAD_CLDFB->lt_noise_sp_center_diff_counter = L_deposit_l( 4 ); - + move32(); + hVAD_CLDFB->lt_noise_sp_center0 = 1841 /* 0.4 Q10 */; + move16(); + hVAD_CLDFB->lt_noise_sp_center3 = 2046 /* 0.4 Q10 */; + move16(); + hVAD_CLDFB->lt_bg_highf_eng = 131070 /* 2.0 Q16 */; + move32(); hVAD_CLDFB->t_bg_energy = 1374389535; move32(); hVAD_CLDFB->scale_t_bg_energy = 37; move16(); - hVAD_CLDFB->t_bg_energy_sum.s16Exp = 37; move16(); hVAD_CLDFB->t_bg_energy_sum.s32Mantissa = 1374389535; move32(); hVAD_CLDFB->tbg_energy_count = 1; move16(); - hVAD_CLDFB->fg_energy_count = 16; - move16(); - hVAD_CLDFB->bg_energy_count = 16; - move16(); - hVAD_CLDFB->bg_update_count = 0; move16(); hVAD_CLDFB->frame_energy_smooth = 1073741824; move32(); hVAD_CLDFB->frame_energy_smooth_scale = 30; move16(); - hVAD_CLDFB->Q_frames_power_32 = 31; + hVAD_CLDFB->fg_energy_est_start = L_deposit_l( 0 ); + move32(); + hVAD_CLDFB->speech_flag = 0; move16(); - hVAD_CLDFB->lt_bg_highf_eng = 131070 /* 2.0 Q16 */; + hVAD_CLDFB->continuous_noise_num = 0; move16(); - hVAD_CLDFB->lt_noise_sp_center0 = 1841 /* 0.4 Q10 */; + hVAD_CLDFB->continuous_speech_num = 0; move16(); - hVAD_CLDFB->lt_noise_sp_center3 = 2046 /* 0.4 Q10 */; + hVAD_CLDFB->continuous_speech_num2 = 0; move16(); - hVAD_CLDFB->music_background_rate = 15073 /* 0.46 Q15 */; + hVAD_CLDFB->update_num_with_snr = 0; /* the number of the background update with SNR*/ move16(); - hVAD_CLDFB->tonality_rate3 = 15073 /* 0.46 Q15 */; + hVAD_CLDFB->update_count = 0; move16(); - hVAD_CLDFB->lt_noise_sp_center_diff_sum = 409 /* 0.4 Q10 */; - move32(); - hVAD_CLDFB->l_silence_snr = 32768 /* 0.5 Q16 */; - move32(); - hVAD_CLDFB->l_speech_snr = 327675 /* 5.0 Q16 */; - move32(); - - FOR( i = 0; i < SP_CENTER_NUM; i++ ) - { - hVAD_CLDFB->sp_center[i] = 1228 /* 1.2 Q10 */; - move16(); - } - - FOR( i = 0; i < STABLE_NUM; i++ ) - { - hVAD_CLDFB->ltd_stable_rate[i] = 2294 /* 0.07 Q15 */; - move16(); - } - - FOR( i = 0; i < BG_ENG_NUM; i++ ) - { - hVAD_CLDFB->sb_bg_energy[i] = 1374389535; - move32(); - } - hVAD_CLDFB->sb_bg_energy_scale = 37; + hVAD_CLDFB->warm_hang_num = 0; move16(); - hVAD_CLDFB->f_tonality_rate[0] = 7864 /* 0.48 Q14 */; - move16(); - hVAD_CLDFB->f_tonality_rate[1] = 7864 /* 0.48 Q14 */; - move16(); - hVAD_CLDFB->f_tonality_rate[2] = 7864 /* 0.48 Q14 */; + hVAD_CLDFB->frame_sb_energy_scale = 0; move16(); - - FOR( i = 0; i < PRE_SPEC_DIF_NUM; i++ ) + FOR( i = 0; i < PRE_SNR_NUM; i++ ) { - hVAD_CLDFB->pre_spec_low_dif[i] = 4095; - move16(); + hVAD_CLDFB->pre_snr[i] = L_deposit_l( 0 ); + move32(); } - hVAD_CLDFB->scale_spec_low_dif = 12; - move16(); FOR( i = 0; i < 56; i++ ) { hVAD_CLDFB->frames_power_32[i] = L_deposit_l( 0 ); + move32(); } - - return 0; -} - -Word16 vad_init_ivas_fx( - VAD_CLDFB_HANDLE hVAD_CLDFB /* i/o: CLDFB VAD state */ -) -{ - Word16 i = 0; - - IF( hVAD_CLDFB == NULL ) - { - return -1; - } - - hVAD_CLDFB->frameloop = 0; - hVAD_CLDFB->lt_snr_org_fx = 33554432; /*Q26 */ - hVAD_CLDFB->lf_snr_smooth_fx = 167772155 /* 5.0 Q25 */; - hVAD_CLDFB->l_silence_snr_fx = 32767 /* 0.5 Q16 */; - hVAD_CLDFB->l_speech_snr_fx = 327675 /* 5.0 Q16 */; - hVAD_CLDFB->l_silence_snr_count = 1; - hVAD_CLDFB->l_speech_snr_count = 1; - hVAD_CLDFB->fg_energy_fx = 1073741824; - hVAD_CLDFB->bg_energy_fx = 1073741824; - hVAD_CLDFB->fg_energy_count = 16; - hVAD_CLDFB->bg_energy_count = 16; - hVAD_CLDFB->tonality_rate3_fx = 15073 /* 0.46 Q15 */; - hVAD_CLDFB->music_background_rate_fx = 15073 /* 0.46 Q15 */; - hVAD_CLDFB->lt_noise_sp_center_diff_sum_fx = 409 /* 0.4 Q10 */; - hVAD_CLDFB->lt_noise_sp_center_diff_counter_fx = L_deposit_l( 4 ); - hVAD_CLDFB->lt_noise_sp_center0_fx = 1841 /* 0.4 Q10 */; - hVAD_CLDFB->lt_noise_sp_center3_fx = 2046 /* 0.4 Q10 */; - hVAD_CLDFB->lt_bg_highf_eng_fx = 131070 /* 2.0 Q16 */; - hVAD_CLDFB->t_bg_energy_fx = 1374389535; - hVAD_CLDFB->t_bg_energy_sum_fx = 1374389535; - hVAD_CLDFB->tbg_energy_count = 1; - hVAD_CLDFB->bg_update_count = 0; - hVAD_CLDFB->frame_energy_smooth_fx = 1073741824; - hVAD_CLDFB->fg_energy_est_start = 0; - hVAD_CLDFB->speech_flag = 0; - hVAD_CLDFB->continuous_noise_num = 0; - hVAD_CLDFB->continuous_speech_num = 0; - hVAD_CLDFB->continuous_speech_num2 = 0; - hVAD_CLDFB->update_num_with_snr = 0; /* the number of the background update with SNR*/ - hVAD_CLDFB->update_count = 0; - hVAD_CLDFB->warm_hang_num = 0; - - FOR( i = 0; i < PRE_SNR_NUM; i++ ) - { - hVAD_CLDFB->pre_snr_fx[i] = L_deposit_l( 0 ); - } - - FOR( i = 0; i < POWER_NUM; i++ ) - { - hVAD_CLDFB->frames_power_fx[i] = L_deposit_l( 0 ); - } + hVAD_CLDFB->Q_frames_power_32 = 31; + move16(); FOR( i = 0; i < SPEC_AMP_NUM; i++ ) { - hVAD_CLDFB->smooth_spec_amp_fx[i] = L_deposit_l( 0 ); + hVAD_CLDFB->smooth_spec_amp[i] = L_deposit_l( 0 ); + move32(); } - hVAD_CLDFB->sfm_fx[0] = 28835 /* 0.88 Q15 */; + hVAD_CLDFB->sfm[0] = 28835 /* 0.88 Q15 */; move16(); - hVAD_CLDFB->sfm_fx[1] = 30146 /* 0.92 Q15 */; + hVAD_CLDFB->sfm[1] = 30146 /* 0.92 Q15 */; move16(); - hVAD_CLDFB->sfm_fx[2] = 30146 /* 0.92 Q15 */; + hVAD_CLDFB->sfm[2] = 30146 /* 0.92 Q15 */; move16(); FOR( i = 0; i < SP_CENTER_NUM; i++ ) { - hVAD_CLDFB->sp_center_fx[i] = 1228 /* 1.2 Q10 */; + hVAD_CLDFB->sp_center[i] = 1228 /* 1.2 Q10 */; move16(); } FOR( i = 0; i < STABLE_NUM; i++ ) { - hVAD_CLDFB->ltd_stable_rate_fx[i] = 2294 /* 0.07 Q15 */; + hVAD_CLDFB->ltd_stable_rate[i] = 2294 /* 0.07 Q15 */; move16(); } FOR( i = 0; i < BG_ENG_NUM; i++ ) { - hVAD_CLDFB->sb_bg_energy_fx[i] = 1374389535; + hVAD_CLDFB->sb_bg_energy[i] = 1374389535; + move32(); + hVAD_CLDFB->frame_sb_energy[i] = L_deposit_l( 0 ); move32(); } - FOR( i = 0; i < BG_ENG_NUM; i++ ) - { - hVAD_CLDFB->frame_sb_energy_fx[i] = L_deposit_l( 0 ); - } + hVAD_CLDFB->sb_bg_energy_scale = 37; + move16(); - hVAD_CLDFB->f_tonality_rate_fx[0] = 7864 /* 0.48 Q14 */; + hVAD_CLDFB->f_tonality_rate[0] = 7864 /* 0.48 Q14 */; move16(); - hVAD_CLDFB->f_tonality_rate_fx[1] = 7864 /* 0.48 Q14 */; + hVAD_CLDFB->f_tonality_rate[1] = 7864 /* 0.48 Q14 */; move16(); - hVAD_CLDFB->f_tonality_rate_fx[2] = 7864 /* 0.48 Q14 */; + hVAD_CLDFB->f_tonality_rate[2] = 7864 /* 0.48 Q14 */; move16(); - FOR( i = 0; i < PRE_SPEC_DIF_NUM; i++ ) { - hVAD_CLDFB->pre_spec_low_dif_fx[i] = 4095; + hVAD_CLDFB->pre_spec_low_dif[i] = 4095; move16(); } + hVAD_CLDFB->scale_spec_low_dif = 12; + move16(); + return 0; } + static void UpdateState( - VAD_CLDFB_HANDLE_FX hVAD_CLDFB, /* i/o: CLDFB VAD state */ - Word16 vad_flag, /* i : VAD flag */ - Word32 frame_energy, /* i : current frame energy */ - Word16 sacle_sbpower, /* i : the Scaling of current frame energy */ - Word32 update_flag, /* i : current frame update flag */ - Word16 music_backgound_f, /* i : background music flag */ - Word32 HB_Power, /* i : current frame high frequency energy */ - Word16 HB_Power_Q, /* i : the Scaling of current frame high frequency energy*/ + VAD_CLDFB_HANDLE hVAD_CLDFB, /* i/o: CLDFB VAD state */ + Word16 vad_flag, /* i : VAD flag */ + Word32 frame_energy, /* i : current frame energy */ + Word16 sacle_sbpower, /* i : the Scaling of current frame energy */ + Word32 update_flag, /* i : current frame update flag */ + Word16 music_backgound_f, /* i : background music flag */ + Word32 HB_Power, /* i : current frame high frequency energy */ + Word16 HB_Power_Q, /* i : the Scaling of current frame high frequency energy*/ Word32 snr ) { Word16 lt_bg_energy_scal; @@ -361,7 +259,7 @@ static void UpdateState( Word16 vad_proc_fx( - VAD_CLDFB_HANDLE_FX hVAD_CLDFB, /* i/o: CLDFB VAD state */ + VAD_CLDFB_HANDLE hVAD_CLDFB, /* i/o: CLDFB VAD state */ Word32 realBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i : real values */ Word32 imagBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i : imag values */ Word16 riBuffer_exp, /* i : exponent of real & imag Buffer */