From e590e5b1c72bc5271619b0ed500711021df171d1 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Mon, 14 Oct 2024 12:03:09 +0530 Subject: [PATCH 1/2] MASA, PARAM-MC, SBA paths functions conversion and integration, cleanup of intermediate float conversions [x] masa_combine_directions, encode_lfe_to_total_energy_ratio function conversion [x] stereo_tca_enc, ivas_core_pre_proc_front and pre_proc_ivas cleanup [x] ivas_param_mc_quantize_iccs, ivas_param_mc_quantize_ildx conversion [x] Fixed point conversion of functions related to quantization of P and pred coeffs, ivas_dirac_param_est_enc [x] Q documentation for decoder and renderer files --- lib_com/frame_ener.c | 2 + lib_com/ivas_cnst.h | 9 + lib_com/ivas_cov_smooth.c | 24 +- lib_com/ivas_mc_param_com.c | 24 + lib_com/ivas_prot.h | 16 + lib_com/ivas_prot_fx.h | 41 +- lib_com/ivas_qspherical_com.c | 4 +- lib_com/ivas_rom_com_fx.c | 3 +- lib_com/ivas_spar_com_quant_util.c | 54 ++ lib_com/ivas_stat_com.h | 10 +- lib_com/prot.h | 6 +- lib_com/prot_fx.h | 11 + lib_com/stat_com.h | 4 +- lib_com/tools_fx.c | 81 ++ lib_dec/FEC_HQ_phase_ecu_fx.c | 142 ++-- lib_dec/FEC_scale_syn_fx.c | 188 ++-- lib_dec/amr_wb_dec_fx.c | 184 ++-- lib_dec/ari_dec_fx.c | 17 +- lib_dec/ivas_agc_dec_fx.c | 41 +- lib_dec/ivas_binRenderer_internal.c | 46 +- lib_dec/ivas_entropy_decoder.c | 37 +- lib_dec/ivas_init_dec.c | 85 +- lib_enc/acelp_core_enc.c | 8 - lib_enc/amr_wb_enc.c | 76 +- lib_enc/core_enc_init.c | 24 +- lib_enc/core_switching_enc.c | 10 + lib_enc/detect_transient.c | 2 + lib_enc/dtx.c | 9 + lib_enc/dtx_fx.c | 2 +- lib_enc/enc_amr_wb.c | 2 + lib_enc/enc_gen_voic_rf.c | 2 + lib_enc/enc_nelp.c | 2 + lib_enc/gain_enc.c | 2 + lib_enc/hq_core_enc.c | 9 + lib_enc/hq_lr_enc.c | 2 + lib_enc/init_enc.c | 48 +- lib_enc/ivas_core_enc.c | 29 - lib_enc/ivas_core_pre_proc_front.c | 54 +- lib_enc/ivas_cpe_enc.c | 46 +- lib_enc/ivas_dirac_enc.c | 304 ++++++- lib_enc/ivas_enc.c | 2 +- lib_enc/ivas_enc_cov_handler.c | 10 + lib_enc/ivas_front_vad.c | 5 - lib_enc/ivas_masa_enc.c | 719 +++++++++++++++- lib_enc/ivas_mc_param_enc.c | 576 ++++++++++++- lib_enc/ivas_omasa_enc.c | 60 ++ lib_enc/ivas_qmetadata_enc.c | 1082 +++++++++++++++--------- lib_enc/ivas_qspherical_enc.c | 118 ++- lib_enc/ivas_spar_md_enc.c | 270 +++++- lib_enc/ivas_stat_enc.h | 36 +- lib_enc/ivas_stereo_ica_enc.c | 715 ++++++++-------- lib_enc/ivas_stereo_switching_enc.c | 2 +- lib_enc/nelp_enc.c | 2 + lib_enc/pitch_ol.c | 10 +- lib_enc/stat_enc.h | 311 ++++--- lib_enc/swb_bwe_enc.c | 10 +- lib_enc/swb_bwe_enc_hr.c | 2 + lib_enc/swb_bwe_enc_lr.c | 2 + lib_enc/swb_tbe_enc.c | 47 + lib_enc/swb_tbe_enc_fx.c | 2 +- lib_enc/voiced_enc.c | 19 + lib_rend/ivas_dirac_decorr_dec.c | 95 ++- lib_rend/ivas_dirac_onsets_dec.c | 18 +- lib_rend/ivas_prot_rend.h | 13 +- lib_rend/ivas_reverb.c | 3 + lib_rend/ivas_rom_TdBinauralRenderer.c | 24 +- lib_rend/ivas_rom_TdBinauralRenderer.h | 16 +- lib_rend/ivas_rom_binauralRenderer.c | 44 +- lib_rend/ivas_rom_binauralRenderer.h | 44 +- 69 files changed, 4224 insertions(+), 1693 deletions(-) diff --git a/lib_com/frame_ener.c b/lib_com/frame_ener.c index 6666c856f..ece0418c6 100644 --- a/lib_com/frame_ener.c +++ b/lib_com/frame_ener.c @@ -143,6 +143,7 @@ void fer_energy_fx( } #endif // IVAS_FLOAT_FIXED +#ifndef IVAS_FLOAT_FIXED /*------------------------------------------------------------------------* * frame_energy() * @@ -183,6 +184,7 @@ float frame_energy( return enern; } +#endif #if 0 diff --git a/lib_com/ivas_cnst.h b/lib_com/ivas_cnst.h index 9ac7c79fa..0ce50e11e 100644 --- a/lib_com/ivas_cnst.h +++ b/lib_com/ivas_cnst.h @@ -50,6 +50,7 @@ #define _180_OVER_PI ( 180.0f / EVS_PI ) #ifdef IVAS_FLOAT_FIXED #define _180_OVER_PI_Q25 1922521886 +#define PI_OVER_180_Q25 ( 585635 ) #define _180_IN_Q22 (754974720) #define _360_IN_Q22 (1509949440) #define _180_OVER_PI_FX (Word32) (( 180.0f / EVS_PI ) *ONE_IN_Q10) @@ -1392,6 +1393,11 @@ typedef enum #define MCMASA_LFE_1BIT_THRES 0.03f #define MCMASA_LFE_ALPHA 0.67f #define MCMASA_LFE_BETA 0.09f +#ifdef IVAS_FLOAT_FIXED +#define MCMASA_LFE_1BIT_THRES_Q31 64424509 /* 0.03f in Q31 */ +#define MCMASA_LFE_ALPHA_Q31 1438814044 /* 0.67f in Q31 */ +#define MCMASA_LFE_BETA_Q31 193273528 /* 0.09f in Q31 */ +#endif #define MCMASA_LFE_THETA 1.3f #define MCMASA_LFE_SYNTH_ALPHA 0.95f /* Smoothing coefficient for LFE synthesis */ #ifdef IVAS_FLOAT_FIXED @@ -1547,8 +1553,11 @@ typedef enum #define PARAM_MC_MAX_PARAM_BAND_ABS_COV_ENC 10 #define PARAM_MC_MAX_BAND_ABS_COV_DEC 10 #define PARAM_MC_ENER_LIMIT_INTRAFRAME (1.5f) +#define PARAM_MC_ENER_LIMIT_INTRAFRAME_FX_Q21 3145728 #define PARAM_MC_ENER_LIMIT_INTERFRAME (2.0f) +#define PARAM_MC_ENER_LIMIT_INTERFRAME_FX_Q21 4194304 #define PARAM_MC_ENER_LIMIT_MAX_DELTA_FAC (15.0f) +#define PARAM_MC_ENER_LIMIT_MAX_DELTA_FAC_FX_Q21 31457280 #define PARAM_MC_NUM_ATTACK_ILD_THRESH (3) #define PARAM_MC_LFE_ON_THRESH (8000.0f) #define PARAM_MC_LFE_ON_THRESH_FX 8000 //Q0 diff --git a/lib_com/ivas_cov_smooth.c b/lib_com/ivas_cov_smooth.c index ebf4e1564..143ac2290 100644 --- a/lib_com/ivas_cov_smooth.c +++ b/lib_com/ivas_cov_smooth.c @@ -316,6 +316,11 @@ ivas_error ivas_spar_covar_smooth_enc_open_fx( return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR COV encoder Fixed" ); } set16_fx( hCovState->q_cov_real_per_band[i][j], Q31, cov_smooth_cfg->max_bands ); + IF( ( hCovState->q_prior_cov_real_per_band[i][j] = (Word16 *) malloc( sizeof( Word16 ) * cov_smooth_cfg->max_bands ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR COV encoder Fixed" ); + } + set16_fx( hCovState->q_prior_cov_real_per_band[i][j], Q31, cov_smooth_cfg->max_bands ); } } @@ -404,6 +409,8 @@ void ivas_spar_covar_smooth_enc_close_fx( hCovState->pPrior_cov_real_fx[i][j] = NULL; free( hCovState->q_cov_real_per_band[i][j] ); hCovState->q_cov_real_per_band[i][j] = NULL; + free( hCovState->q_prior_cov_real_per_band[i][j] ); + hCovState->q_prior_cov_real_per_band[i][j] = NULL; } } @@ -493,7 +500,7 @@ static void ivas_compute_smooth_cov_fx( { FOR( j = 0; j < num_ch; j++ ) { - set16_fx( hCovState->q_cov_real_per_band[i][j], q_cov[i][j], pFb->filterbank_num_bands ); + set16_fx( hCovState->q_cov_real_per_band[i][j], q_cov[i][j], sub( end_band, start_band ) ); } } FOR( i = 0; i < num_ch; i++ ) @@ -529,7 +536,7 @@ static void ivas_compute_smooth_cov_fx( { L_tmp = Mpy_32_32( hCovState->pSmoothing_factor_fx[k], pCov_buf[i][j][k] ); // (Q31, q_cov[i][j]) -> q_cov[i][j] L_tmp1 = Mpy_32_32( L_sub( ONE_IN_Q31, hCovState->pSmoothing_factor_fx[k] ), pPrior_cov_buf[i][j][k] ); // (Q31, hCovState->q_cov_real_per_band[i][j][k]) -> hCovState->q_cov_real_per_band[i][j][k] - pCov_buf[i][j][k] = BASOP_Util_Add_Mant32Exp( L_tmp, sub( Q31, q_cov[i][j] ), L_tmp1, sub( Q31, hCovState->q_cov_real_per_band[i][j][k] ), &q_tmp[k] ); + pCov_buf[i][j][k] = BASOP_Util_Add_Mant32Exp( L_tmp, sub( Q31, q_cov[i][j] ), L_tmp1, sub( Q31, hCovState->q_prior_cov_real_per_band[i][j][k] ), &q_tmp[k] ); move32(); q_tmp[k] = sub( Q31, q_tmp[k] ); move16(); @@ -537,7 +544,7 @@ static void ivas_compute_smooth_cov_fx( pCov_buf[i][j][k] = L_add( pCov_buf[i][j][k], L_tmp ); move32(); } - Copy( q_tmp, hCovState->q_cov_real_per_band[i][j], pFb->filterbank_num_bands ); + Copy( q_tmp, hCovState->q_cov_real_per_band[i][j], sub( end_band, start_band ) ); } } FOR( i = 0; i < num_ch; i++ ) @@ -571,7 +578,7 @@ static void ivas_compute_smooth_cov_fx( { L_tmp = Mpy_32_32( hCovState->pSmoothing_factor_fx[k], pCov_buf[i][j][k] ); // (Q31, q_cov[i][j]) -> q_cov[i][j] L_tmp1 = Mpy_32_32( L_sub( ONE_IN_Q31, hCovState->pSmoothing_factor_fx[k] ), pPrior_cov_buf[i][j][k] ); // (Q31, hCovState->q_cov_real_per_band[i][j][k]) -> hCovState->q_cov_real_per_band[i][j][k] - pCov_buf[i][j][k] = BASOP_Util_Add_Mant32Exp( L_tmp, sub( Q31, q_cov[i][j] ), L_tmp1, sub( Q31, hCovState->q_cov_real_per_band[i][j][k] ), &q_tmp[k] ); + pCov_buf[i][j][k] = BASOP_Util_Add_Mant32Exp( L_tmp, sub( Q31, q_cov[i][j] ), L_tmp1, sub( Q31, hCovState->q_prior_cov_real_per_band[i][j][k] ), &q_tmp[k] ); move32(); q_tmp[k] = sub( Q31, q_tmp[k] ); move16(); @@ -579,7 +586,7 @@ static void ivas_compute_smooth_cov_fx( pCov_buf[i][j][k] = L_add( pCov_buf[i][j][k], L_tmp ); move32(); } - Copy( q_tmp, hCovState->q_cov_real_per_band[i][j], pFb->filterbank_num_bands ); + Copy( q_tmp, hCovState->q_cov_real_per_band[i][j], sub( end_band, start_band ) ); } } } @@ -698,7 +705,7 @@ void ivas_cov_smooth_process_fx( const Word16 transient_det[2], Word16 *q_cov[IVAS_SPAR_MAX_CH] ) { - Word16 i, j; + Word16 i, j, k; Word16 num_bands = sub( end_band, start_band ); ivas_compute_smooth_cov_fx( hCovState, pFb, cov_real, hCovState->pPrior_cov_real_fx, 0, start_band, end_band, num_ch, transient_det, q_cov ); @@ -708,6 +715,11 @@ void ivas_cov_smooth_process_fx( FOR( j = 0; j < num_ch; j++ ) { Copy32( &cov_real[i][j][start_band], &hCovState->pPrior_cov_real_fx[i][j][start_band], num_bands ); + FOR( k = 0; k < num_bands; k++ ) + { + hCovState->q_prior_cov_real_per_band[i][j][start_band + k] = hCovState->q_cov_real_per_band[i][j][start_band + k]; + move16(); + } } } diff --git a/lib_com/ivas_mc_param_com.c b/lib_com/ivas_mc_param_com.c index 2af6a9cc5..064677bbd 100644 --- a/lib_com/ivas_mc_param_com.c +++ b/lib_com/ivas_mc_param_com.c @@ -942,6 +942,9 @@ static void ivas_param_mc_set_coding_scheme( hMetadataPMC->icc_coding.sym_freq_delta = &ivas_param_mc_sym_freq_icc_delta_cicp6_48_16bits[0]; hMetadataPMC->icc_coding.quantizer = &ivas_param_mc_quant_icc[0]; hMetadataPMC->icc_coding.quantizer_size = PARAM_MC_SZ_ICC_QUANTIZER; +#ifdef IVAS_FLOAT_FIXED + hMetadataPMC->icc_coding.quantizer_fx = &ivas_param_mc_quant_icc_fx[0]; +#endif hMetadataPMC->icc_coding.uni_bits = PARAM_MC_NUM_BITS_ICC_SCALAR_QUANT; /* ILD */ hMetadataPMC->ild_coding.cum_freq = &ivas_param_mc_cum_freq_ild_cicp6_48_16bits[0]; @@ -949,6 +952,9 @@ static void ivas_param_mc_set_coding_scheme( hMetadataPMC->ild_coding.cum_freq_delta = &ivas_param_mc_cum_freq_ild_delta_cicp6_48_16bits[0]; hMetadataPMC->ild_coding.sym_freq_delta = &ivas_param_mc_sym_freq_ild_delta_cicp6_48_16bits[0]; hMetadataPMC->ild_coding.quantizer = &ivas_param_mc_quant_ild_5d1_48[0]; +#ifdef IVAS_FLOAT_FIXED + hMetadataPMC->ild_coding.quantizer_fx = &ivas_param_mc_quant_ild_5d1_48_fx[0]; +#endif hMetadataPMC->ild_coding.quantizer_size = PARAM_MC_SZ_ILD_QUANTIZER_4BITS; hMetadataPMC->ild_coding.uni_bits = PARAM_MC_NUM_BITS_ILD_SCALAR_QUANT; break; @@ -959,6 +965,9 @@ static void ivas_param_mc_set_coding_scheme( hMetadataPMC->icc_coding.cum_freq_delta = &ivas_param_mc_cum_freq_icc_delta_cicp12_48_16bits[0]; hMetadataPMC->icc_coding.sym_freq_delta = &ivas_param_mc_sym_freq_icc_delta_cicp12_48_16bits[0]; hMetadataPMC->icc_coding.quantizer = &ivas_param_mc_quant_icc[0]; +#ifdef IVAS_FLOAT_FIXED + hMetadataPMC->icc_coding.quantizer_fx = &ivas_param_mc_quant_icc_fx[0]; +#endif hMetadataPMC->icc_coding.quantizer_size = PARAM_MC_SZ_ICC_QUANTIZER; hMetadataPMC->icc_coding.uni_bits = PARAM_MC_NUM_BITS_ICC_SCALAR_QUANT; /* ILD */ @@ -967,6 +976,9 @@ static void ivas_param_mc_set_coding_scheme( hMetadataPMC->ild_coding.cum_freq_delta = &ivas_param_mc_cum_freq_ild_delta_cicp12_48_16bits[0]; hMetadataPMC->ild_coding.sym_freq_delta = &ivas_param_mc_sym_freq_ild_delta_cicp12_48_16bits[0]; hMetadataPMC->ild_coding.quantizer = &ivas_param_mc_quant_ild_5d1_48[0]; +#ifdef IVAS_FLOAT_FIXED + hMetadataPMC->ild_coding.quantizer_fx = &ivas_param_mc_quant_ild_5d1_48_fx[0]; +#endif hMetadataPMC->ild_coding.quantizer_size = PARAM_MC_SZ_ILD_QUANTIZER_4BITS; hMetadataPMC->ild_coding.uni_bits = PARAM_MC_NUM_BITS_ILD_SCALAR_QUANT; break; @@ -977,6 +989,9 @@ static void ivas_param_mc_set_coding_scheme( hMetadataPMC->icc_coding.cum_freq_delta = &ivas_param_mc_cum_freq_icc_delta_cicp14_48_16bits[0]; hMetadataPMC->icc_coding.sym_freq_delta = &ivas_param_mc_sym_freq_icc_delta_cicp14_48_16bits[0]; hMetadataPMC->icc_coding.quantizer = &ivas_param_mc_quant_icc[0]; +#ifdef IVAS_FLOAT_FIXED + hMetadataPMC->icc_coding.quantizer_fx = &ivas_param_mc_quant_icc_fx[0]; +#endif hMetadataPMC->icc_coding.quantizer_size = PARAM_MC_SZ_ICC_QUANTIZER; hMetadataPMC->icc_coding.uni_bits = PARAM_MC_NUM_BITS_ICC_SCALAR_QUANT; /* ILD */ @@ -985,6 +1000,9 @@ static void ivas_param_mc_set_coding_scheme( hMetadataPMC->ild_coding.cum_freq_delta = &ivas_param_mc_cum_freq_ild_delta_cicp14_48_16bits[0]; hMetadataPMC->ild_coding.sym_freq_delta = &ivas_param_mc_sym_freq_ild_delta_cicp14_48_16bits[0]; hMetadataPMC->ild_coding.quantizer = &ivas_param_mc_quant_ild_5d1_48[0]; +#ifdef IVAS_FLOAT_FIXED + hMetadataPMC->ild_coding.quantizer_fx = &ivas_param_mc_quant_ild_5d1_48_fx[0]; +#endif hMetadataPMC->ild_coding.quantizer_size = PARAM_MC_SZ_ILD_QUANTIZER_4BITS; hMetadataPMC->ild_coding.uni_bits = PARAM_MC_NUM_BITS_ILD_SCALAR_QUANT; break; @@ -996,6 +1014,9 @@ static void ivas_param_mc_set_coding_scheme( hMetadataPMC->icc_coding.cum_freq_delta = &ivas_param_mc_cum_freq_icc_delta_combined_48_16bits[0]; hMetadataPMC->icc_coding.sym_freq_delta = &ivas_param_mc_sym_freq_icc_delta_combined_48_16bits[0]; hMetadataPMC->icc_coding.quantizer = &ivas_param_mc_quant_icc[0]; +#ifdef IVAS_FLOAT_FIXED + hMetadataPMC->icc_coding.quantizer_fx = &ivas_param_mc_quant_icc_fx[0]; +#endif hMetadataPMC->icc_coding.quantizer_size = PARAM_MC_SZ_ICC_QUANTIZER; hMetadataPMC->icc_coding.uni_bits = PARAM_MC_NUM_BITS_ICC_SCALAR_QUANT; /* ILD */ @@ -1004,6 +1025,9 @@ static void ivas_param_mc_set_coding_scheme( hMetadataPMC->ild_coding.cum_freq_delta = &ivas_param_mc_cum_freq_ild_delta_combined_48_16bits[0]; hMetadataPMC->ild_coding.sym_freq_delta = &ivas_param_mc_sym_freq_ild_delta_combined_48_16bits[0]; hMetadataPMC->ild_coding.quantizer = &ivas_param_mc_quant_ild_5d1_48[0]; +#ifdef IVAS_FLOAT_FIXED + hMetadataPMC->ild_coding.quantizer_fx = &ivas_param_mc_quant_ild_5d1_48_fx[0]; +#endif hMetadataPMC->ild_coding.quantizer_size = PARAM_MC_SZ_ILD_QUANTIZER_4BITS; hMetadataPMC->ild_coding.uni_bits = PARAM_MC_NUM_BITS_ILD_SCALAR_QUANT; break; diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 54ed0a26b..2af3c52eb 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -6928,6 +6928,16 @@ void ivas_quantise_real_values_fx( Word32 *quant_fx, const Word16 dim); +void ivas_quantise_real_values_enc_fx( + const Word32 *values_fx,//Q28 + const Word16 q_levels, + const Word32 min_value_fx,//Q28 + const Word32 max_value_fx,//Q28 + Word16 *index, + Word32 *quant_fx,//Q28 + const Word16 dim); + + void ivas_spar_get_uniform_quant_strat( ivas_spar_md_com_cfg *pSpar_md_com_cfg, const int16_t table_idx @@ -7134,9 +7144,15 @@ void ivas_merge_masa_metadata( OMASA_SPATIAL_META_HANDLE hOMasaMeta /* i : ISM-object metadata to be merged with the MASA metadata */ ); +#ifdef IVAS_FLOAT_FIXED +void ivas_masa_combine_directions_fx( + MASA_ENCODER_HANDLE hMasa /* i/o: MASA encoder handle */ +); +#else void ivas_masa_combine_directions( MASA_ENCODER_HANDLE hMasa /* i/o: MASA encoder handle */ ); +#endif /*!r : number of bits for ISM ratio index */ int16_t bits_index_ism_ratio( diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index 008aa1b2e..d7a70af1b 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -321,6 +321,11 @@ void sns_shape_spectrum_fx( Word32 ECSQ_dequantize_gain_fx( const Word16 index ); +void stereo_tca_enc_fx( + CPE_ENC_HANDLE hCPE, /* i : CPE encoder structure */ + const Word16 input_frame /* i : length of a frame per channel */ +); + void ECSQ_dequantize_vector_fx( const Word16 *input, const Word32 global_gain, @@ -3117,7 +3122,6 @@ void tdm_ol_pitch_comparison_fx( Word16 voicing_fr[CPE_CHANNELS][NB_SUBFR] /* i/o: fractional pitch gains, Q15 */ ); -#ifdef IVAS_FLOAT_FIXED void xtalk_classifier_td_fx( CPE_ENC_HANDLE hCPE /* i/o: CPE encoder structure */ ); @@ -3125,7 +3129,34 @@ void xtalk_classifier_td_fx( void unclr_classifier_td_fx( CPE_ENC_HANDLE hCPE /* i/o: CPE encoder structure */ ); -#endif + +void quantize_direction_frame2D_fx( + IVAS_QDIRECTION *q_direction, /* i/o: quantized direction structure */ + Word32 azimuth_orig[MASA_MAXIMUM_CODING_SUBBANDS][MAX_PARAM_SPATIAL_SUBFRAMES], // Q22 + Word32 elevation_orig[MASA_MAXIMUM_CODING_SUBBANDS][MAX_PARAM_SPATIAL_SUBFRAMES] // Q22 +); + +Word16 quantize_direction2D_fx( + Word32 phi, /* i : input azimuth value Q22 */ + const Word16 no_cw, /* i : number of bits */ + Word32 *phi_q, /* o : quantized azimuth value Q22 */ + UWord16 *index_phi, /* o : quantized azimuth index */ + const MC_LS_SETUP mc_format /* i : channel format if in MC-mode */ +); + +void restore_metadata_buffer_fx( + BSTR_ENC_HANDLE hMetaData, + const Word16 next_ind_start, + const Word16 bit_pos_start ); + + +void small_requantize_direction_frame_fx( + IVAS_QDIRECTION *q_direction, /* i/o: quantized direction structure */ + Word32 azimuth_orig[MASA_MAXIMUM_CODING_SUBBANDS][MAX_PARAM_SPATIAL_SUBFRAMES], // Q22 + Word32 elevation_orig[MASA_MAXIMUM_CODING_SUBBANDS][MAX_PARAM_SPATIAL_SUBFRAMES], // Q22 + const Word16 raw_flag[MASA_MAXIMUM_CODING_SUBBANDS], + Word16 bits_dir_bands[MASA_MAXIMUM_CODING_SUBBANDS], + Word16 *diff ); #ifdef IVAS_FLOAT_FIXED @@ -3327,6 +3358,12 @@ void quantize_direction_frame_fx( const Word16 hrmasa_flag /* i : flag indicating high-rate MASA MD coding */ ); +ivas_error ivas_qmetadata_enc_encode_fx( + BSTR_ENC_HANDLE hMetaData, /* i/o: metadata bitstream handle */ + IVAS_QMETADATA *hQMetaData, /* i/o: metadata handle */ + const Word16 hodirac_flag /* i : flag to indicate HO-DirAC mode */ +); + ivas_error ivas_qmetadata_enc_encode_hr_384_512_fx( BSTR_ENC_HANDLE hMetaData, /* i/o: metadata bitstream handle */ IVAS_QMETADATA *hQMetaData, /* i/o: metadata handle */ diff --git a/lib_com/ivas_qspherical_com.c b/lib_com/ivas_qspherical_com.c index 38a108a9c..4832a4fd9 100644 --- a/lib_com/ivas_qspherical_com.c +++ b/lib_com/ivas_qspherical_com.c @@ -833,8 +833,8 @@ Word16 quantize_phi_chan_lbr_fx( return 0; } - id_phi = squant_fx( extract_l( L_shr( L_abs( phi ), 22 ) ) /* Q0 */, &phi_hat_16 /* Q0 */, cb_azi_chan_16fx, shr( n, 1 ) ); - *phi_hat = L_shl( L_deposit_l( phi_hat_16 ), Q22 ); // Q0 -> Q22 + id_phi = squant_fx( round_fx( L_abs( phi ) ) /* Q6 */, &phi_hat_16 /* Q6 */, cb_azi_chan_16fx, shr( n, 1 ) ); + *phi_hat = L_deposit_h( phi_hat_16 ); // Q6 -> Q22 move32(); test(); diff --git a/lib_com/ivas_rom_com_fx.c b/lib_com/ivas_rom_com_fx.c index 1ede70308..6722a87f2 100644 --- a/lib_com/ivas_rom_com_fx.c +++ b/lib_com/ivas_rom_com_fx.c @@ -1527,6 +1527,7 @@ const Word32 azimuth_cb_fx[8] = { 0, -754974720, -377487360, 377487360, -188743680, 188743680, -566231040, 566231040 }; +// Q22 const Word32 delta_theta_masa_fx[NO_SPHERICAL_GRIDS - 2] = { 188743680, 188743680, 150994944, 106954752, 83886080, 62914560, 45214596, 28101836, 20971520 }; @@ -1675,7 +1676,7 @@ const Word32 dd_val[90] = { }; const Word32 cb_azi_chan_fx[] = { 0, 125829120, 461373440, 566231040 }; // Q22 -const Word16 cb_azi_chan_16fx[] = { 0, 30, 110, 135 }; // Q0 +const Word16 cb_azi_chan_16fx[] = { 0, 1920, 7040, 8640 }; // Q6 /*----------------------------------------------------------------------------------* * MASA and ISM (OMASA) combined format ROM tables diff --git a/lib_com/ivas_spar_com_quant_util.c b/lib_com/ivas_spar_com_quant_util.c index 5f14acfe7..d26cd9bb8 100644 --- a/lib_com/ivas_spar_com_quant_util.c +++ b/lib_com/ivas_spar_com_quant_util.c @@ -141,6 +141,60 @@ void ivas_quantise_real_values_fx( } return; } + +#ifdef IVAS_FLOAT_FIXED +void ivas_quantise_real_values_enc_fx( + const Word32 *values_fx, // Q28 + const Word16 q_levels, + const Word32 min_value_fx, // Q28 + const Word32 max_value_fx, // Q28 + Word16 *index, + Word32 *quant_fx, // Q28 + const Word16 dim ) +{ + Word16 i; + Word32 q_step_fx, one_by_q_step_fx; + test(); + IF( EQ_16( q_levels, 1 ) ) + { + FOR( i = 0; i < dim; i++ ) + { + quant_fx[i] = 0; + move32(); + index[i] = 0; + move16(); + } + } + ELSE IF( q_levels && NE_32( max_value_fx, min_value_fx ) ) + { + Word16 nor_q_level = norm_l( sub( q_levels, 1 ) ); + Word32 one_by_q_levels = divide3232( L_shl( 1, ( nor_q_level ) ), L_shl( sub( q_levels, 1 ), ( nor_q_level ) ) ); // Q15 + one_by_q_levels = L_shl( one_by_q_levels, 16 ); // Q31 + q_step_fx = Mpy_32_32( L_sub( max_value_fx, min_value_fx ), one_by_q_levels ); // Q28 + Word16 exp; + Word16 one_by_max_min = BASOP_Util_Divide3232_Scale( ONE_IN_Q28, L_sub( max_value_fx, min_value_fx ), &exp ); // Q(15-exp) + one_by_q_step_fx = L_mult0( sub( q_levels, 1 ), one_by_max_min ); // Q(15-exp) + Word32 val_fx; + FOR( i = 0; i < dim; i++ ) + { + val_fx = L_max( min_value_fx, L_min( values_fx[i], max_value_fx ) ); // Q28 + index[i] = round_fx( L_shl( Mpy_32_32( one_by_q_step_fx, val_fx ), add( Q4, exp ) ) ); //(Q(15-exp)+Q28-Q31)+Q4+Q(exp)=Q0 + move16(); + quant_fx[i] = imult3216( q_step_fx, index[i] ); // Q28 + move32(); + } + } + ELSE + { + FOR( i = 0; i < dim; i++ ) + { + quant_fx[i] = values_fx[i]; // Q28 + move32(); + } + } + return; +} +#endif #endif /*-----------------------------------------------------------------------------------------* diff --git a/lib_com/ivas_stat_com.h b/lib_com/ivas_stat_com.h index ed28e35ea..3c9e2ee74 100644 --- a/lib_com/ivas_stat_com.h +++ b/lib_com/ivas_stat_com.h @@ -195,14 +195,14 @@ typedef struct ivas_band_coeffs_t float P_quant_re[IVAS_SPAR_MAX_CH - 1]; Word16 q_pred_re_fx; - Word32 pred_re_fx[IVAS_SPAR_MAX_CH - 1]; + Word32 pred_re_fx[IVAS_SPAR_MAX_CH - 1]; // Q28 Word16 q_C_re_fx; Word32 C_re_fx[IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS][IVAS_SPAR_MAX_DMX_CHS - 1]; Word16 q_P_re_fx; - Word32 P_re_fx[IVAS_SPAR_MAX_CH - 1]; - Word32 pred_quant_re_fx[IVAS_SPAR_MAX_CH - 1]; + Word32 P_re_fx[IVAS_SPAR_MAX_CH - 1]; // Q28 + Word32 pred_quant_re_fx[IVAS_SPAR_MAX_CH - 1]; // Q28 Word32 C_quant_re_fx[IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS][IVAS_SPAR_MAX_DMX_CHS - 1]; - Word32 P_quant_re_fx[IVAS_SPAR_MAX_CH - 1]; + Word32 P_quant_re_fx[IVAS_SPAR_MAX_CH - 1]; // Q28 } ivas_band_coeffs_t; typedef struct ivas_band_coeffs_ind_t @@ -377,6 +377,7 @@ typedef struct ivas_cov_smooth_state_t #ifdef IVAS_FLOAT_FIXED Word32 *pPrior_cov_real_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; Word16 *q_cov_real_per_band[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; + Word16 *q_prior_cov_real_per_band[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; #else float *pPrior_cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; #endif @@ -665,6 +666,7 @@ typedef struct ivas_parametric_mc_metadata_value_coding_info_struct const float *quantizer; #ifdef IVAS_FLOAT_FIXED const Word16 *quantizer_fx; + Word16 Q_quant; #endif int16_t quantizer_size; int16_t uni_bits; diff --git a/lib_com/prot.h b/lib_com/prot.h index e30269296..60413a1d2 100644 --- a/lib_com/prot.h +++ b/lib_com/prot.h @@ -3721,7 +3721,11 @@ void find_wsp( ); void pitch_ol_init( - float *old_thres, /* o : threshold for reinforcement of past pitch influence */ +#ifndef IVAS_FLOAT_FIXED + float *old_thres, /* o : threshold for reinforcement of past pitch influence */ +#else + Word16 *old_thres, /* o : threshold for reinforcement of past pitch influence */ +#endif int16_t *old_pitch, /* o : pitch of the 2nd half-frame of previous frame */ int16_t *delta_pit, /* o : pitch evolution extrapolation */ float *old_corr /* o : correlation */ diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 6bce3e265..27af7caa1 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -10009,6 +10009,17 @@ void Vr_subt( Word16 N /* i : Vector lenght */ ); +#ifdef IVAS_FLOAT_FIXED +Word16 vquant_ivas_fx( /* o: index of the winning codevector */ + Word16 x[], /* i: vector to quantize Q13 */ + const Word16 x_mean[], /* i: vector mean to subtract (0 if none) Q13 */ + Word16 xq[], /* o: quantized vector Q13 */ + const Word16 cb[], /* i: codebook Q13 */ + const Word16 dim, /* i: dimension of codebook vectors */ + const Word16 cbsize /* i: codebook size */ +); +#endif + Word16 vquant_fx( /* o: index of the winning codevector */ Word16 x[], /* i: vector to quantize Q13 */ const Word16 x_mean[], /* i: vector mean to subtract (0 if none)Q13*/ diff --git a/lib_com/stat_com.h b/lib_com/stat_com.h index 39265617e..50869066c 100644 --- a/lib_com/stat_com.h +++ b/lib_com/stat_com.h @@ -56,8 +56,8 @@ typedef struct { float a[MAXLAG_WI]; float b[MAXLAG_WI]; - Word16 a_fx[MAXLAG_WI]; - Word16 b_fx[MAXLAG_WI]; + Word16 a_fx[MAXLAG_WI]; /* Q(DTFS_STRUCTURE.Q) */ + Word16 b_fx[MAXLAG_WI]; /* Q(DTFS_STRUCTURE.Q) */ int16_t lag; int16_t nH; int16_t nH_4kHz; diff --git a/lib_com/tools_fx.c b/lib_com/tools_fx.c index 92b4048d4..9d3681b6e 100644 --- a/lib_com/tools_fx.c +++ b/lib_com/tools_fx.c @@ -1679,6 +1679,87 @@ void Vr_subt( * Searches a given codebook to find the nearest neighbour in Euclidean space. * Index of the winning codevector and the winning vector itself are returned. *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +Word16 vquant_ivas_fx( /* o: index of the winning codevector */ + Word16 x[], /* i: vector to quantize Q13 */ + const Word16 x_mean[], /* i: vector mean to subtract (0 if none) Q13 */ + Word16 xq[], /* o: quantized vector Q13 */ + const Word16 cb[], /* i: codebook Q13 */ + const Word16 dim, /* i: dimension of codebook vectors */ + const Word16 cbsize /* i: codebook size */ +) +{ + Word16 tmp; + Word16 c, d, idx, j; + Word32 L_dist, /*L_tmp,*/ L_mindist; +#ifdef BASOP_NOGLOB_DECLARE_LOCAL + Flag Overflow = 0; + move32(); +#endif + + idx = 0; + move16(); + L_mindist = MAX_32; + move32(); + IF( x_mean != 0 ) + { + FOR( d = 0; d < dim; d++ ) + { + /*x[d] -= x_mean[d]; */ + x[d] = sub( x[d], x_mean[d] ); + move16(); /*Qx */ + } + } + j = 0; + move16(); + FOR( c = 0; c < cbsize; c++ ) + { + L_dist = 0; + move32(); + + FOR( d = 0; d < dim; d++ ) + { + /*tmp = x[d] - cb[j++];*/ +#ifdef BASOP_NOGLOB + tmp = sub_o( x[d], cb[j++], &Overflow ); /*Qx */ + L_dist = L_mac0_o( L_dist, tmp, tmp, &Overflow ); +#else + tmp = sub( x[d], cb[j++] ); /*Qx */ + L_dist = L_mac0( L_dist, tmp, tmp ); +#endif + } + if ( LT_32( L_dist, L_mindist ) ) + { + idx = c; + move16(); + } + L_mindist = L_min( L_mindist, L_dist ); + } + IF( xq == 0 ) + { + return idx; + } + + /*j = idx*dim;*/ + j = i_mult2( idx, dim ); + FOR( d = 0; d < dim; d++ ) + { + xq[d] = cb[j++]; + move16(); + } + IF( x_mean != 0 ) + { + FOR( d = 0; d < dim; d++ ) + { + /*xq[d] += x_mean[d]; */ + xq[d] = add( xq[d], x_mean[d] ); + move16(); + } + } + + return idx; +} +#endif Word16 vquant_fx( /* o: index of the winning codevector */ Word16 x[], /* i: vector to quantize Q13 */ diff --git a/lib_dec/FEC_HQ_phase_ecu_fx.c b/lib_dec/FEC_HQ_phase_ecu_fx.c index 1508b8668..7d4cfd9ae 100644 --- a/lib_dec/FEC_HQ_phase_ecu_fx.c +++ b/lib_dec/FEC_HQ_phase_ecu_fx.c @@ -106,13 +106,13 @@ static float imax2_jacobsen_mag( const float *y_re, const float *y_im ); * randomized phase in form of sin and cos components *------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED -static Word16 rand_phase_fx( const Word16 seed, Word16 *sin_F, Word16 *cos_F ) +static Word16 rand_phase_fx( const Word16 seed, Word16 *sin_F /*Q15*/, Word16 *cos_F /*Q15*/ ) { - const Word16 *sincos = sincos_t_ext_fx + 128; + const Word16 *sincos = sincos_t_ext_fx + 128; // Q15 Word16 seed2 = own_random2_fx( seed ); Word16 seed2_shift = shr( seed2, 8 ); - *sin_F = negate( *( sincos + seed2_shift ) ); + *sin_F = negate( *( sincos + seed2_shift ) ); // Q15 move16(); if ( s_and( seed2, 0x40 ) != 0 ) { @@ -120,7 +120,7 @@ static Word16 rand_phase_fx( const Word16 seed, Word16 *sin_F, Word16 *cos_F ) move16(); } - *cos_F = negate( *( sincos - seed2_shift ) ); + *cos_F = negate( *( sincos - seed2_shift ) ); // Q15 move16(); if ( s_and( seed2, 0x80 ) != 0 ) { @@ -135,11 +135,11 @@ static Word16 rand_phase_fx( const Word16 seed, Word16 *sin_F, Word16 *cos_F ) #ifdef IVAS_FLOAT_FIXED /*! r: The location, relative to the middle of the 3 given data point, of the maximum. (Q15)*/ static Word16 ivas_imax2_jacobsen_mag_fx( - const Word16 *y_re, /* i : The 3 given data points. real part order -1 0 1 */ - const Word16 *y_im /* i : The 3 given data points. imag part order 1 0 -1 (from FFT) */ + const Word16 *y_re, /* i : The 3 given data points. real part order -1 0 1 Qx */ + const Word16 *y_im /* i : The 3 given data points. imag part order 1 0 -1 (from FFT) Qx */ ) { - Word16 posi; + Word16 posi; // Q15 const Word16 *pY; Word16 y_m1_re, y_0_re, y_p1_re; Word16 y_m1_im, y_0_im, y_p1_im; @@ -284,8 +284,8 @@ static float imax2_jacobsen_mag( * Square magnitude of fft spectrum *----------------------------------------------------------------------------*/ static void fft_spec2_fx( - const Word16 x[], /* i : Input vector: complex spectrum */ - Word32 xMagSq[], /* o : Magnitude square spectrum */ + const Word16 x[], /* i : Input vector: complex spectrum Q0*/ + Word32 xMagSq[], /* o : Magnitude square spectrum Q0*/ const Word16 N /* i : Input vector length */ ) { @@ -335,7 +335,7 @@ static void trans_ana_fx( const Word16 last_fec, /* i : signal that previous frame was concealed with fec_alg */ Word16 *alpha, /* o : Magnitude modification factors for fade to average */ Word16 *beta, /* o : Magnitude modification factors for fade to average */ - Word16 *beta_mute, /* o : Factor for long-term mute */ + Word16 *beta_mute, /* o : Factor for long-term mute Q15 */ Word16 *Xavg /* o : Frequency group average gain to fade to */ ) { @@ -1438,7 +1438,7 @@ static void ivas_spec_ana_fx( const Word16 bwidth_fx, /* i : Encoded bandwidth index Q0 */ Word16 *Q, /* o : Q value of the fft spectrum */ const Word16 element_mode, /* i : IVAS element mode */ - Word16 *noise_fac, /* o : for few peaks zeroing valleys decision making */ + Word16 *noise_fac, /* o : for few peaks zeroing valleys decision making Q15*/ const Word16 pcorr ) { Word16 Lprot, LprotLog2Minus1 = 0, hamm_len2 = 0, Lprot2, Lprot2_1, m, n; @@ -1526,7 +1526,7 @@ static void ivas_spec_ana_fx( { xfp[i] = mult_r( shl( prevsynth[i], *Q ), sub( w_hamm[i], window_corr ) ); move16(); - xfp[sub( sub( Lprot, i ), 1 )] = mult_r( shl( prevsynth[sub( sub( Lprot, i ), 1 )], *Q ), sub( w_hamm[i], window_corr ) ); + xfp[Lprot - i - 1] = mult_r( shl( prevsynth[Lprot - i - 1], *Q ), sub( w_hamm[i], window_corr ) ); move16(); window_corr = sub( window_corr, window_corr_step ); } @@ -1551,7 +1551,7 @@ static void ivas_spec_ana_fx( { xfp[i] = mult_r( shl( prevsynth[i], *Q ), sub( w_hamm[i], window_corr ) ); move16(); - xfp[sub( sub( Lprot, i ), 1 )] = mult_r( shl( prevsynth[sub( sub( Lprot, i ), 1 )], *Q ), sub( w_hamm[i], window_corr ) ); + xfp[Lprot - i - 1] = mult_r( shl( prevsynth[Lprot - i - 1], *Q ), sub( w_hamm[i], window_corr ) ); move16(); window_corr = sub( window_corr, window_corr_step ); } @@ -1722,14 +1722,14 @@ static void ivas_spec_ana_fx( { nJacob = n; move16(); - if ( sub( endPlocs, plocs[sub( *num_plocs, 1 )] ) <= 0 ) + if ( sub( endPlocs, plocs[*num_plocs - 1] ) <= 0 ) { nJacob = sub( nJacob, 1 ); } FOR( k = 0; k < nJacob; k++ ) { - fraction = ivas_imax2_jacobsen_mag_fx( &( X_sav[currPlocs - 1] ), &( X_sav[sub( sub( Lprot, 1 ), currPlocs )] ) ); /* in Q15 */ + fraction = ivas_imax2_jacobsen_mag_fx( &( X_sav[currPlocs - 1] ), &( X_sav[Lprot - 1 - currPlocs] ) ); /* in Q15 */ acc = L_deposit_h( currPlocs ); *pPlocsi++ = L_mac( acc, fraction, 1 ); move32(); @@ -2996,8 +2996,8 @@ static void ivas_rec_wtda_fx( const Word16 Lprot, /* i : Prototype frame length */ const Word16 old_dec[270], /* i : end of last decoded for OLA before tda and itda */ const Word16 element_mode, /* i : IVAS element mode */ - const Word16 *num_p, /* i : Number of peaks */ - const Word16 *plocs /* i : Peak locations */ + const Word16 *num_p, /* i : Number of peaks Q0 */ + const Word16 *plocs /* i : Peak locations Q0 */ ) { Word16 timesh; @@ -3112,10 +3112,10 @@ static void ivas_rec_wtda_fx( p_ecu = xsubst_ + add( sub( shl( output_frame, 1 ), Lprot ), timesh ); FOR( i = 0; i < xf_len; ( i++, p_ecu++ ) ) { - idx = extract_l( L_shr( L_mult0( i, tbl_delta ), 12 ) ); - g = sincos_t_fx[idx]; + idx = extract_l( L_shr( L_mult0( i, tbl_delta ), 12 ) ); // Q0 + g = sincos_t_fx[idx]; // Q15 move16(); - g = mult( g, g ); + g = mult( g, g ); // Q15 *p_ecu = mult( g, ( *p_ecu ) ); move16(); p_ecu++; @@ -3458,7 +3458,7 @@ static void fir_dwn_fx( FOR( j = 1; j <= i; j++ ) { #ifdef BASOP_NOGLOB - s = L_mac0_sat( s, *ptr_h++, *ptr_x-- ); + s = L_mac0_sat( s, *ptr_h++, *ptr_x-- ); // Q(h_Q) + Q(x_q) #else s = L_mac0( s, *ptr_h++, *ptr_x-- ); #endif @@ -3481,7 +3481,7 @@ static void fir_dwn_fx( FOR( j = 1; j <= K; j++ ) { #ifdef BASOP_NOGLOB - s = L_mac0_sat( s, *ptr_h++, *ptr_x-- ); + s = L_mac0_sat( s, *ptr_h++, *ptr_x-- ); // Q(h_Q) + Q(x_q) #else s = L_mac0( s, *ptr_h++, *ptr_x-- ); #endif @@ -3503,7 +3503,7 @@ static void fir_dwn_fx( ptr_x = x + sub( L, 1 ); move16(); - FOR( j = add( sub( i, L ), 1 ); j <= K; j++ ) + FOR( j = i - L + 1; j <= K; j++ ) { #ifdef BASOP_NOGLOB s = L_mac0_sat( s, *ptr_h++, *ptr_x-- ); @@ -4013,7 +4013,7 @@ static void sin_cos_est_fx( Word32 phi, Word16 *cosfreq, Word16 *sinfreq ) return; } -static Word16 abs_iter_fx( Word16 re, Word16 im, Word16 N ) +static Word16 abs_iter_fx( Word16 re /*Qx*/, Word16 im /*Qx*/, Word16 N ) { Word16 A, tmp, L_tmp1, L_tmp2; Word16 i, exp; @@ -4315,8 +4315,8 @@ static void fec_ecu_dft_fx( static void singenerator_fx( const Word16 L, /* i : size of output */ - const Word16 cosfreq, /* i : cosine of 1-sample dephasing at the given frequency */ - const Word16 sinfreq, /* i : sine of 1-sample dephasing at the given frequency */ + const Word16 cosfreq, /* i : cosine of 1-sample dephasing at the given frequency Q15*/ + const Word16 sinfreq, /* i : sine of 1-sample dephasing at the given frequency Q15*/ const Word16 a_re, /* i : real part of complex spectral coefficient at the given frequency */ /*Qin */ const Word16 a_im, @@ -4435,7 +4435,7 @@ static void sinusoidal_synthesis_fx( move16(); glued = 1; move16(); - new_s = Tf_abs[1]; + new_s = Tf_abs[1]; // Qin move16(); if ( flag ) { @@ -4461,9 +4461,9 @@ static void sinusoidal_synthesis_fx( nb_pulses++; move16(); } - old = Tf_abs[add( cpt, PL )]; + old = Tf_abs[cpt + PL]; move16(); - new_s = Tf_abs[add( add( cpt, 2 ), PL )]; + new_s = Tf_abs[cpt + 2 + PL]; move16(); cpt = add( add( cpt, PL ), 1 ); move16(); @@ -4474,7 +4474,7 @@ static void sinusoidal_synthesis_fx( { old = Tf_abs[cpt]; move16(); - new_s = Tf_abs[add( cpt, 2 )]; + new_s = Tf_abs[cpt + 2]; move16(); cpt++; glued = 0; @@ -4491,7 +4491,7 @@ static void sinusoidal_synthesis_fx( cumsum = L_deposit_l( 0 ); - L_tmp = Mult_32_16( sum_Tf_abs, 22938 ); + L_tmp = Mult_32_16( sum_Tf_abs, 22938 ); // Qin pt1 = a_re; pt2 = a_im; @@ -4550,7 +4550,7 @@ static void sinusoidal_synthesis_fx( mmax = s_max( Tf_abs[tmp], mmax ); } - cumsum = L_mac0( cumsum, mmax, 1 ); + cumsum = L_mac0( cumsum, mmax, 1 ); // Qin *pt1++ = Tfr[indmax]; move16(); /*L_shr(Tfr[indmax], sN); //instead shr -> scaling of a_re is Qin+sN */ @@ -5086,13 +5086,13 @@ static void fec_alg_fx( #ifdef IVAS_FLOAT_FIXED static void ivas_hq_phase_ecu_fx( - const Word16 *prevsynth, /* i : buffer of previously synthesized signal */ + const Word16 *prevsynth, /* i : buffer of previously synthesized signal Q0 */ Word32 *ecu_rec, /* o : reconstructed frame in tda domain */ - Word16 *time_offs, /* i/o: Sample offset for consecutive frame losses*/ + Word16 *time_offs, /* i/o: Sample offset for consecutive frame losses Q0*/ Word16 *X_sav, /* i/o: Stored spectrum of prototype frame */ Word16 *Q_spec, /* i/o: Q value of stored spectrum */ - Word16 *num_p, /* i/o: Number of identified peaks */ - Word16 *plocs, /* i/o: Peak locations */ + Word16 *num_p, /* i/o: Number of identified peaks Q0 */ + Word16 *plocs, /* i/o: Peak locations Q0 */ Word32 *plocsi, /* i/o: Interpolated peak locations Q16 */ const Word16 env_stab, /* i : Envelope stability parameter */ Word16 *last_fec, /* i/o: Flag for usage of pitch dependent ECU */ @@ -5100,8 +5100,8 @@ static void ivas_hq_phase_ecu_fx( const Word16 prev_bfi, /* i : indicating burst frame error */ const Word16 old_is_transient[2], /* i : flags indicating previous transient frames */ Word16 *mag_chg_1st, /* i/o: per band magnitude modifier for transients*/ - Word16 *Xavg, /* i/o: Frequency group average gain to fade to */ - Word16 *beta_mute, /* o : Factor for long-term mute */ + Word16 *Xavg, /* i/o: Frequency group average gain to fade to Q0 */ + Word16 *beta_mute, /* o : Factor for long-term mute Q15 */ const Word16 bwidth_fx, /* i : Encoded bandwidth */ const Word16 output_frame, /* i : frame length */ const Word16 pcorr, @@ -5194,7 +5194,7 @@ static void ivas_hq_phase_ecu_fx( move16(); IF( *num_p > 0 ) { - seed = extract_l( L_add( L_deposit_l( seed ), L_deposit_l( plocs[sub( *num_p, 1 )] ) ) ); + seed = extract_l( L_add( L_deposit_l( seed ), L_deposit_l( plocs[*num_p - 1] ) ) ); } ivas_subst_spec_fx( plocs, plocsi, num_p, *time_offs, X, mag_chg, ph_dith, old_is_transient, output_frame, &seed, @@ -5212,13 +5212,13 @@ static void ivas_hq_phase_ecu_fx( #endif static void hq_phase_ecu_fx( - const Word16 *prevsynth, /* i : buffer of previously synthesized signal */ + const Word16 *prevsynth, /* i : buffer of previously synthesized signal Q0 */ Word32 *ecu_rec, /* o : reconstructed frame in tda domain */ - Word16 *time_offs, /* i/o: Sample offset for consecutive frame losses*/ + Word16 *time_offs, /* i/o: Sample offset for consecutive frame losses Q0*/ Word16 *X_sav, /* i/o: Stored spectrum of prototype frame */ Word16 *Q_spec, /* i/o: Q value of stored spectrum */ - Word16 *num_p, /* i/o: Number of identified peaks */ - Word16 *plocs, /* i/o: Peak locations */ + Word16 *num_p, /* i/o: Number of identified peaks Q0 */ + Word16 *plocs, /* i/o: Peak locations Q0 */ Word32 *plocsi, /* i/o: Interpolated peak locations Q16 */ const Word16 env_stab, /* i : Envelope stability parameter */ Word16 *last_fec, /* i/o: Flag for usage of pitch dependent ECU */ @@ -5226,8 +5226,8 @@ static void hq_phase_ecu_fx( const Word16 prev_bfi, /* i : indicating burst frame error */ const Word16 old_is_transient[2], /* i : flags indicating previous transient frames */ Word16 *mag_chg_1st, /* i/o: per band magnitude modifier for transients*/ - Word16 *Xavg, /* i/o: Frequency group average gain to fade to */ - Word16 *beta_mute, /* o : Factor for long-term mute */ + Word16 *Xavg, /* i/o: Frequency group average gain to fade to Q0 */ + Word16 *beta_mute, /* o : Factor for long-term mute Q15 */ const Word16 bwidth_fx, /* i : Encoded bandwidth */ const Word16 output_frame /* i : frame length */ #ifdef IVAS_FEC_ECU_TO_COMPLETE @@ -5335,7 +5335,7 @@ static void hq_phase_ecu_fx( move16(); IF( *num_p > 0 ) { - seed = add( seed, plocs[sub( *num_p, 1 )] ); + seed = add( seed, plocs[*num_p - 1] ); } subst_spec_fx( plocs, plocsi, num_p, *time_offs, X, mag_chg, ph_dith, old_is_transient, output_frame, &seed, @@ -5372,13 +5372,13 @@ static void hq_phase_ecu_fx( #ifdef IVAS_FLOAT_FIXED void ivas_hq_ecu_fx( - const Word16 *prevsynth, /* i : buffer of previously synthesized signal */ + const Word16 *prevsynth, /* i : buffer of previously synthesized signal Q0 */ Word32 *ecu_rec, /* o : reconstructed frame in tda domain */ - Word16 *time_offs, /* i/o: Sample offset for consecutive frame losses */ + Word16 *time_offs, /* i/o: Sample offset for consecutive frame losses Q0 */ Word16 *X_sav, /* i/o: Stored spectrum of prototype frame */ Word16 *Q_spec, /* i/o: Q value of stored spectrum */ - Word16 *num_p, /* i/o: Number of identified peaks */ - Word16 *plocs, /* i/o: Peak locations */ + Word16 *num_p, /* i/o: Number of identified peaks Q0 */ + Word16 *plocs, /* i/o: Peak locations Q0 */ Word32 *plocsi, /* i/o: Interpolated peak locations Q16 */ const Word16 env_stab, /* i : Envelope stability parameter */ Word16 *last_fec, /* i/o: Flag for usage of pitch dependent ECU */ @@ -5388,8 +5388,8 @@ void ivas_hq_ecu_fx( const Word16 prev_bfi, /* i : indicating burst frame error */ const Word16 old_is_transient[2], /* i : flags indicating previous transient frames */ Word16 *mag_chg_1st, /* i/o: per band magnitude modifier for transients */ - Word16 *Xavg, /* i/o: Frequency group average gain to fade to */ - Word16 *beta_mute, /* o : Factor for long-term mute */ + Word16 *Xavg, /* i/o: Frequency group average gain to fade to Q0 */ + Word16 *beta_mute, /* o : Factor for long-term mute Q15 */ const Word16 output_frame, /* i : frame length */ Decoder_State *st_fx /* i/o: decoder state structure */ ) @@ -5485,13 +5485,13 @@ void ivas_hq_ecu_fx( #endif void hq_ecu_fx( - const Word16 *prevsynth, /* i : buffer of previously synthesized signal */ + const Word16 *prevsynth, /* i : buffer of previously synthesized signal Q0 */ Word32 *ecu_rec, /* o : reconstructed frame in tda domain */ - Word16 *time_offs, /* i/o: Sample offset for consecutive frame losses */ + Word16 *time_offs, /* i/o: Sample offset for consecutive frame losses Q0 */ Word16 *X_sav, /* i/o: Stored spectrum of prototype frame */ Word16 *Q_spec, /* i/o: Q value of stored spectrum */ - Word16 *num_p, /* i/o: Number of identified peaks */ - Word16 *plocs, /* i/o: Peak locations */ + Word16 *num_p, /* i/o: Number of identified peaks Q0 */ + Word16 *plocs, /* i/o: Peak locations Q0 */ Word32 *plocsi, /* i/o: Interpolated peak locations Q16 */ const Word16 env_stab, /* i : Envelope stability parameter */ Word16 *last_fec, /* i/o: Flag for usage of pitch dependent ECU */ @@ -5501,8 +5501,8 @@ void hq_ecu_fx( const Word16 prev_bfi, /* i : indicating burst frame error */ const Word16 old_is_transient[2], /* i : flags indicating previous transient frames */ Word16 *mag_chg_1st, /* i/o: per band magnitude modifier for transients */ - Word16 *Xavg, /* i/o: Frequency group average gain to fade to */ - Word16 *beta_mute, /* o : Factor for long-term mute */ + Word16 *Xavg, /* i/o: Frequency group average gain to fade to Q0 */ + Word16 *beta_mute, /* o : Factor for long-term mute Q15 */ const Word16 output_frame, /* i : frame length */ Decoder_State *st_fx /* i/o: decoder state structure */ ) @@ -5657,9 +5657,9 @@ static Word16 sqrt2ndOrder( /* o: in Q15 (2nd order least square * window. *--------------------------------------------------------------------------- */ static void windowing( - const Word16 *x, /* i: Input signal */ - Word16 *y, /* o: Windowed output */ - const Word16 *win, /* i: Window coefficients */ + const Word16 *x, /* i: Input signal Qx*/ + Word16 *y, /* o: Windowed output Qx*/ + const Word16 *win, /* i: Window coefficients Q15*/ const Word16 rectLength, /* i: Offset in between the 1st and 2nd symmetric halves of the Hamming window */ const Word16 halfLength /* i: Half of the total length of a complete Hamming window. */ ) @@ -5700,8 +5700,8 @@ static void windowing( * 5. 2nd half of the right half of the Hamming window *----------------------------------------------------------------------------*/ static void windowing_ROM_optimized( - const Word16 *x, /* i: Input signal */ - Word16 *y, /* o: Windowed output */ + const Word16 *x, /* i: Input signal Qin*/ + Word16 *y, /* o: Windowed output Qin*/ const Word16 downSamples, /* i: Offset in accessing the sine table. */ const Word16 rectLength, /* i: Length of the rectangular portion (excluding the Hamming window part) */ const Word16 halfLength /* i: Half of the total length of the Hamming (excluding rectangular part) window */ @@ -5714,17 +5714,17 @@ static void windowing_ROM_optimized( quarterLen = shr( halfLength, 1 ); /* 1/4 length of the entire Hamming (excluding the rectangular part) window. */ initOffset = add( T_SIN_PI_2, shr( downSamples, 1 ) ); - pSine = sincos_t_rad3_fx + initOffset; + pSine = sincos_t_rad3_fx + initOffset; // Q15 pX = x; pY = y; /* 1st half of the left half of the Hamming window. */ FOR( i = 0; i < quarterLen; i++ ) { - pSine -= downSamples; /* Decrement address counter */ - acc = L_deposit_h( FEC_HQ_WIN_A0 ); /* Derive the Hamming window coefficient from the sine table. */ - hamm = msu_r( acc, *pSine, FEC_HQ_WIN_A1 ); - *pY++ = mult_r( hamm, *pX++ ); + pSine -= downSamples; /* Decrement address counter */ + acc = L_deposit_h( FEC_HQ_WIN_A0 ); /* Derive the Hamming window coefficient from the sine table. Q31*/ + hamm = msu_r( acc, *pSine, FEC_HQ_WIN_A1 ); // Q15 + *pY++ = mult_r( hamm, *pX++ ); // Qin move16(); } @@ -5752,10 +5752,10 @@ static void windowing_ROM_optimized( /* 1st half of the right half of the Hamming window. */ FOR( i = 0; i < quarterLen; i++ ) { - pSine -= downSamples; /* Decrement address counter */ - acc = L_deposit_h( FEC_HQ_WIN_A0 ); + pSine -= downSamples; /* Decrement address counter */ + acc = L_deposit_h( FEC_HQ_WIN_A0 ); // Q31 #ifdef BASOP_NOGLOB - hamm = mac_r_sat( acc, *pSine, FEC_HQ_WIN_A1 ); + hamm = mac_r_sat( acc, *pSine, FEC_HQ_WIN_A1 ); // Q15 #else hamm = mac_r( acc, *pSine, FEC_HQ_WIN_A1 ); #endif diff --git a/lib_dec/FEC_scale_syn_fx.c b/lib_dec/FEC_scale_syn_fx.c index 7d29586b6..1de166612 100644 --- a/lib_dec/FEC_scale_syn_fx.c +++ b/lib_dec/FEC_scale_syn_fx.c @@ -56,25 +56,25 @@ void FEC_scale_syn_fx( Word16 *update_flg, /* o: flag indicating re-synthesis after scaling*/ Word16 clas, /* i/o: frame classification */ const Word16 last_good, /* i: last good frame classification */ - Word16 *synth, /* i/o: synthesized speech at Fs = 12k8 Hz */ - const Word16 *pitch, /* i: pitch values for each subframe */ + Word16 *synth, /* i/o: synthesized speech at Fs = 12k8 Hz Q_syn*/ + const Word16 *pitch, /* i: pitch values for each subframe Q0*/ Word32 L_enr_old, /* i: energy at the end of previous frame */ Word32 L_enr_q, /* i: transmitted energy for current frame */ const Word16 coder_type, /* i: coder type */ const Word16 LSF_Q_prediction, /* i : LSF prediction mode */ Word16 *scaling_flag, /* i/o: flag to indicate energy control of syn */ - Word32 *lp_ener_FEC_av, /* i/o: averaged voiced signal energy */ - Word32 *lp_ener_FEC_max, /* i/o: averaged voiced signal energy */ + Word32 *lp_ener_FEC_av, /* i/o: averaged voiced signal energy Q0*/ + Word32 *lp_ener_FEC_max, /* i/o: averaged voiced signal energy Q0*/ const Word16 bfi, /* i: current frame BFI */ const Word32 total_brate, /* i: total bitrate */ const Word16 prev_bfi, /* i: previous frame BFI */ const Word32 last_core_brate, /* i: previous frame core bitrate */ Word16 *exc, /* i/o: excitation signal without enhancement */ Word16 *exc2, /* i/o: excitation signal with enhancement */ - Word16 Aq[], /* i/o: LP filter coefs (can be modified if BR) */ - Word16 *old_enr_LP, /* i/o: LP filter E of last good voiced frame */ - const Word16 *mem_tmp, /* i: temp. initial synthesis filter states */ - Word16 *mem_syn, /* o: initial synthesis filter states */ + Word16 Aq[], /* i/o: LP filter coefs (can be modified if BR) Q12*/ + Word16 *old_enr_LP, /* i/o: LP filter E of last good voiced frame Q3*/ + const Word16 *mem_tmp, /* i: temp. initial synthesis filter states Q_syn*/ + Word16 *mem_syn, /* o: initial synthesis filter states Q_syn*/ Word16 Q_exc, Word16 Q_syn, const Word16 avoid_lpc_burst_on_recovery, /* i : if true the excitation energy is limited if LP has big gain */ @@ -172,7 +172,7 @@ void FEC_scale_syn_fx( * Find the energy/gain at the end of the frame *-----------------------------------------------------------------*/ - frame_ener_fx( L_frame, clas, synth, pitch[sub( shr( L_frame, 6 ), 1 )], &L_enr2 /*Q0*/, 1, Q_syn, 3, 0 ); + frame_ener_fx( L_frame, clas, synth, pitch[( L_frame >> 6 ) - 1], &L_enr2 /*Q0*/, 1, Q_syn, 3, 0 ); test(); @@ -213,15 +213,15 @@ void FEC_scale_syn_fx( #endif /*if( gain1 > 1.0f )gain1 = 1.0f;*/ - gain1 = s_min( gain1, 16384 ); + gain1 = s_min( gain1, 16384 ); /*Q14*/ } ELSE /* good frame */ { IF( L_enr_q == 0 ) /* If E info (FEC protection bits) is not available in the bitstream */ { - L_enr_q = L_enr2; + L_enr_q = L_enr2; /*Q0*/ set16_fx( h1, 0, L_FRAME / 2 ); - h1[0] = 1024; + h1[0] = 1024; /*1.0f in Q10*/ move16(); /*syn_filt( Aq+(3*(M+1)), M, h1, h1, L_FRAME/2, h1+(M+1), 0 );*/ E_UTIL_synthesis( 1, Aq + ( 3 * ( M + 1 ) ), h1, h1, L_FRAME / 2, h1 + ( M + 1 ), 0, M ); @@ -231,22 +231,22 @@ void FEC_scale_syn_fx( /*rr1 = dotp( h1, h1+1, L_FRAME/2-1 );*/ /*tilt = rr1 / rr0;*/ #ifdef BASOP_NOGLOB - tilt = extract_h( L_shl_sat( get_gain( h1 + 1, h1, L_FRAME / 2 - 1 ), 15 ) ); + tilt = extract_h( L_shl_sat( get_gain( h1 + 1, h1, L_FRAME / 2 - 1 ), 15 ) ); /*Q15*/ #else tilt = extract_h( L_shl( get_gain( h1 + 1, h1, L_FRAME / 2 - 1 ), 15 ) ); #endif pitch_dist = 0; move16(); - L_mean_pitch = L_mult( pitch[0], 8192 ); + L_mean_pitch = L_mult( pitch[0], 8192 /*1.0f in Q13*/ ); /*Q14*/ FOR( k = 0; k < ( NB_SUBFR - 1 ); k++ ) { - pitch_dist = add( pitch_dist, abs_s( sub( pitch[k + 1], pitch[k] ) ) ); - L_mean_pitch = L_mac( L_mean_pitch, pitch[k + 1], 8192 ); + pitch_dist = add( pitch_dist, abs_s( sub( pitch[k + 1], pitch[k] ) ) ); /*Q0*/ + L_mean_pitch = L_mac( L_mean_pitch, pitch[k + 1], 8192 ); /*Q14*/ } /*pitch_dist /= (float)(NB_SUBFR-1); */ - pitch_dist = mult_r( shl( pitch_dist, 4 ), 10923 ); + pitch_dist = mult_r( shl( pitch_dist, 4 ), 10923 /*1/(float)(NB_SUBFR-1) in Q15*/ ); /*Q4*/ /*mean_pitch /= (float)(NB_SUBFR);*/ - mean_pitch = extract_h( L_shl( L_mean_pitch, 4 ) ); + mean_pitch = extract_h( L_shl( L_mean_pitch, 4 ) ); /*Q4*/ test(); @@ -268,12 +268,12 @@ void FEC_scale_syn_fx( } ELSE { - ener_max = *lp_ener_FEC_max; + ener_max = *lp_ener_FEC_max; /*Q0*/ move32(); test(); if ( EQ_16( clas, VOICED_TRANSITION ) || ( GE_16( clas, INACTIVE_CLAS ) ) ) { - ener_max = *lp_ener_FEC_av; + ener_max = *lp_ener_FEC_av; /*Q0*/ move32(); } /*if( enr_old > ener_max )ener_max = enr_old;*/ @@ -308,7 +308,7 @@ void FEC_scale_syn_fx( { /* voiced -> unvoiced signal transition */ /* CNG -> active signal transition */ - gain1 = gain2; + gain1 = gain2; /*Q14*/ move16(); } ELSE @@ -329,20 +329,20 @@ void FEC_scale_syn_fx( /*if( gain1 > 1.2f )gain1 = 1.2f;*/ /* prevent clipping */ - gain1 = s_min( gain1, 19661 ); + gain1 = s_min( gain1, 19661 /*1.2f in Q14*/ ); /* prevent amplifying the unvoiced or inactive part of the frame in case an offset is followed by an onset */ test(); test(); if ( EQ_16( clas, ONSET ) && GT_16( gain1, gain2 ) && prev_bfi ) { - gain1 = gain2; + gain1 = gain2; /*Q14*/ move16(); } } - L_enr2 = L_enr_q; - move32(); /* Set the end frame energy to the scaled energy, to be used in the lp_ener_FEC */ + L_enr2 = L_enr_q; /*Q0*/ + move32(); /* Set the end frame energy to the scaled energy, to be used in the lp_ener_FEC */ } /*------------------------------------------------------------------------------* @@ -350,7 +350,7 @@ void FEC_scale_syn_fx( *------------------------------------------------------------------------------*/ /*gain2 *= ( 1.0f - AGC );*/ - L_tmp = L_mult( gain2, (Word16) ( 32768 - AGC_FX ) ); + L_tmp = L_mult( gain2, (Word16) ( 32768 /*Q15*/ - AGC_FX ) ); /*Q30*/ FOR( i = 0; i < L_frame; i++ ) { /*gain1 = gain1 * AGC + gain2;*/ @@ -367,7 +367,7 @@ void FEC_scale_syn_fx( move16(); } /* smoothing is done in excitation domain, so redo synthesis */ - Copy( mem_tmp, mem_syn, M ); + Copy( mem_tmp, mem_syn, M ); /* Q_syn */ syn_12k8_fx( L_frame, Aq, exc2, synth, mem_syn, 1, Q_exc, Q_syn ); *update_flg = 1; move16(); @@ -383,7 +383,7 @@ void FEC_scale_syn_fx( { L_enr_q = L_max( 1, L_enr2 ); /* sets to 'L_enr2' in 1 clock */ set16_fx( h1, 0, L_FRAME / 2 ); - h1[0] = 1024; + h1[0] = 1024; /*1.0f in Q10*/ move16(); /*syn_filt( Aq+(3*(M+1)), M, h1, h1, L_FRAME/2, h1+(M+1), 0 );*/ E_UTIL_synthesis( 1, Aq + ( 3 * ( M + 1 ) ), h1, h1, L_FRAME / 2, h1 + ( M + 1 ), 0, M ); @@ -392,7 +392,7 @@ void FEC_scale_syn_fx( /*rr1 = dotp( h1, h1+1, L_FRAME/2-1 );*/ /*tilt = rr1 / rr0;*/ #ifdef BASOP_NOGLOB - tilt = extract_h( L_shl_sat( get_gain( h1 + 1, h1, L_FRAME / 2 - 1 ), 15 ) ); + tilt = extract_h( L_shl_sat( get_gain( h1 + 1, h1, L_FRAME / 2 - 1 ), 15 ) ); /*Q15*/ #else tilt = extract_h( L_shl( get_gain( h1 + 1, h1, L_FRAME / 2 - 1 ), 15 ) ); #endif @@ -450,7 +450,7 @@ void FEC_scale_syn_fx( ELSE { test(); - IF( avoid_lpc_burst_on_recovery && GT_16( enr_LP, 160 ) ) + IF( avoid_lpc_burst_on_recovery && GT_16( enr_LP, 160 /*20.0f in Q3*/ ) ) { exp = norm_s( enr_LP ); tmp = shl( enr_LP, exp ); @@ -482,7 +482,7 @@ void FEC_scale_syn_fx( IF( GT_32( L_enr_q, L_enr_old ) ) /* Prevent energy to increase on voiced */ { - L_enr_q = L_add( Mpy_32_16_1( L_enr_old, 32767 - SCLSYN_LAMBDA ), Mpy_32_16_1( L_enr_q, SCLSYN_LAMBDA ) ); + L_enr_q = L_add( Mpy_32_16_1( L_enr_old, 32767 - SCLSYN_LAMBDA ), Mpy_32_16_1( L_enr_q, SCLSYN_LAMBDA ) ); /*Q0*/ } } } @@ -518,10 +518,10 @@ void FEC_scale_syn_fx( * Clipping of the smoothing gain at the frame end *-----------------------------------------------------------------*/ - gain2 = s_min( gain2, 19661 ); /* Gain modification clipping */ + gain2 = s_min( gain2, 19661 /*1.2f in Q14*/ ); /* Gain modification clipping */ if ( LT_32( L_enr_q, 2 ) ) { - gain2 = s_min( gain2, 16384 ); /* Gain modification clipping */ + gain2 = s_min( gain2, 16384 /*1.0f in Q14*/ ); /* Gain modification clipping */ } /*-----------------------------------------------------------------* @@ -536,7 +536,7 @@ void FEC_scale_syn_fx( test(); IF( EQ_16( clas, SIN_ONSET ) ) /* slow increase */ { - gain1 = shr( gain2, 1 ); + gain1 = shr( gain2, 1 ); /*0.5f * gain2*/ } /*------------------------------------------------------------* * voiced->unvoiced transition recovery @@ -544,7 +544,7 @@ void FEC_scale_syn_fx( ELSE IF( ( GE_16( last_good, VOICED_TRANSITION ) && LT_16( last_good, INACTIVE_CLAS ) && ( clas == UNVOICED_CLAS || EQ_16( clas, INACTIVE_CLAS ) ) ) || /* voiced->unvoiced transition recovery */ EQ_32( last_core_brate, SID_1k75 ) || EQ_32( last_core_brate, SID_2k40 ) || last_core_brate == FRAME_NO_DATA ) /* CNG -> active signal transition */ { - gain1 = gain2; + gain1 = gain2; /*Q14*/ move16(); } ELSE @@ -581,13 +581,13 @@ void FEC_scale_syn_fx( #endif /* exp2 is always <= 1 */ - gain1 = s_min( gain1, 19661 ); + gain1 = s_min( gain1, 19661 /*1.2F in Q14*/ ); test(); test(); if ( avoid_lpc_burst_on_recovery && ( GT_16( enr_LP, 160 ) ) && ( LE_16( enr_LP, shl_sat( *old_enr_LP, 1 ) ) ) ) { - gain1 = s_min( gain1, 16384 ); + gain1 = s_min( gain1, 16384 /*1.0f in Q14*/ ); } /*--------------------------------------------------------* @@ -596,7 +596,7 @@ void FEC_scale_syn_fx( test(); if ( ( EQ_16( clas, ONSET ) ) && ( GT_16( gain1, gain2 ) ) ) { - gain1 = gain2; + gain1 = gain2; /*Q14*/ move16(); } } @@ -605,7 +605,7 @@ void FEC_scale_syn_fx( * gain1 to gain2 *-----------------------------------------------------------------*/ - L_tmp = L_mult( gain2, (Word16) ( 32768 - AGC_FX ) ); + L_tmp = L_mult( gain2, (Word16) ( 32768 /*Q15*/ - AGC_FX ) ); FOR( i = 0; i < L_frame; i++ ) { @@ -622,7 +622,7 @@ void FEC_scale_syn_fx( move16(); } - Copy( mem_tmp, mem_syn, M ); + Copy( mem_tmp, mem_syn, M ); /* Q_syn */ syn_12k8_fx( L_frame, Aq, exc2, synth, mem_syn, 1, Q_exc, Q_syn ); *update_flg = 1; move16(); @@ -638,22 +638,22 @@ void FEC_scale_syn_fx( { IF( EQ_16( clas, VOICED_TRANSITION ) ) { - L_enr2_av = L_enr2; + L_enr2_av = L_enr2; /*Q0*/ move32(); frame_ener_fx( L_frame, VOICED_CLAS, synth, pitch[sub( shr( L_frame, 6 ), 1 )], &L_ener2_max /*Q0*/, 1, Q_syn, 3, 0 ); } ELSE { - L_ener2_max = L_enr2; + L_ener2_max = L_enr2; /*Q0*/ move32(); frame_ener_fx( L_frame, UNVOICED_CLAS, synth, pitch[sub( shr( L_frame, 6 ), 1 )], &L_enr2_av /*Q0*/, 1, Q_syn, 3, 0 ); } /**lp_ener_FEC_av = 0.2f * enr2_av + 0.8f * *lp_ener_FEC_av; move32();*/ - *lp_ener_FEC_av = Madd_32_16( Mult_32_16( *lp_ener_FEC_av, 31130 ), L_enr2_av, 1638 ); + *lp_ener_FEC_av = Madd_32_16( Mult_32_16( *lp_ener_FEC_av, 31130 /*0.95f in Q15*/ ), L_enr2_av, 1638 /*0.05F Q15*/ ); /*Q0*/ move32(); /**lp_ener_FEC_max = 0.2f * enr2_max + 0.8f * *lp_ener_FEC_max; move32();*/ - *lp_ener_FEC_max = Madd_32_16( Mult_32_16( *lp_ener_FEC_max, 31130 ), L_ener2_max, 1638 ); + *lp_ener_FEC_max = Madd_32_16( Mult_32_16( *lp_ener_FEC_max, 31130 /*0.95f in Q15*/ ), L_ener2_max, 1638 /*0.05F Q15*/ ); /*Q0*/ move32(); } @@ -663,7 +663,7 @@ void FEC_scale_syn_fx( test(); if ( GE_16( clas, VOICED_TRANSITION ) && LT_16( clas, INACTIVE_CLAS ) ) { - *old_enr_LP = enr_LP; + *old_enr_LP = enr_LP; /*Q3*/ move16(); } @@ -675,25 +675,25 @@ void FEC_scale_syn_ivas_fx( Word16 *update_flg, /* o: flag indicating re-synthesis after scaling*/ Word16 clas, /* i/o: frame classification */ const Word16 last_good, /* i: last good frame classification */ - Word16 *synth, /* i/o: synthesized speech at Fs = 12k8 Hz */ - const Word16 *pitch, /* i: pitch values for each subframe */ + Word16 *synth, /* i/o: synthesized speech at Fs = 12k8 Hz Q_syn*/ + const Word16 *pitch, /* i: pitch values for each subframe Q0*/ Word32 L_enr_old, /* i: energy at the end of previous frame */ Word32 L_enr_q, /* i: transmitted energy for current frame */ const Word16 coder_type, /* i: coder type */ const Word16 LSF_Q_prediction, /* i : LSF prediction mode */ Word16 *scaling_flag, /* i/o: flag to indicate energy control of syn */ - Word32 *lp_ener_FEC_av, /* i/o: averaged voiced signal energy */ - Word32 *lp_ener_FEC_max, /* i/o: averaged voiced signal energy */ + Word32 *lp_ener_FEC_av, /* i/o: averaged voiced signal energy Q0*/ + Word32 *lp_ener_FEC_max, /* i/o: averaged voiced signal energy Q0*/ const Word16 bfi, /* i: current frame BFI */ const Word32 total_brate, /* i: total bitrate */ const Word16 prev_bfi, /* i: previous frame BFI */ const Word32 last_core_brate, /* i: previous frame core bitrate */ Word16 *exc, /* i/o: excitation signal without enhancement */ Word16 *exc2, /* i/o: excitation signal with enhancement */ - Word16 Aq[], /* i/o: LP filter coefs (can be modified if BR) */ - Word16 *old_enr_LP, /* i/o: LP filter E of last good voiced frame */ - const Word16 *mem_tmp, /* i: temp. initial synthesis filter states */ - Word16 *mem_syn, /* o: initial synthesis filter states */ + Word16 Aq[], /* i/o: LP filter coefs (can be modified if BR) Q12*/ + Word16 *old_enr_LP, /* i/o: LP filter E of last good voiced frame Q3*/ + const Word16 *mem_tmp, /* i: temp. initial synthesis filter states Q_syn*/ + Word16 *mem_syn, /* o: initial synthesis filter states Q_syn*/ Word16 Q_exc, Word16 Q_syn, const Word16 avoid_lpc_burst_on_recovery, /* i : if true the excitation energy is limited if LP has big gain */ @@ -822,7 +822,7 @@ void FEC_scale_syn_ivas_fx( #endif /*if( gain2 > 1.0f )gain2 = 1.0f;*/ - gain2 = s_min( gain2, 16384 ); + gain2 = s_min( gain2, 16384 /*1.0f in Q14*/ ); /*Q14*/ /* find the energy/gain at the beginning of the frame */ frame_ener_fx( L_frame, clas, synth, pitch[0], &L_enr1 /*Q0*/, 1, Q_syn, 3, 0 ); @@ -839,15 +839,15 @@ void FEC_scale_syn_ivas_fx( #endif /*if( gain1 > 1.0f )gain1 = 1.0f;*/ - gain1 = s_min( gain1, 16384 ); + gain1 = s_min( gain1, 16384 /*1.0f in Q14*/ ); /*Q14*/ } ELSE /* good frame */ { IF( L_enr_q == 0 ) /* If E info (FEC protection bits) is not available in the bitstream */ { - L_enr_q = L_enr2; + L_enr_q = L_enr2; /*Q0*/ set16_fx( h1, 0, L_FRAME / 2 ); - h1[0] = 1024; + h1[0] = 1024; /*1.0F in Q10*/ move16(); /*syn_filt( Aq+(3*(M+1)), M, h1, h1, L_FRAME/2, h1+(M+1), 0 );*/ E_UTIL_synthesis( 1, Aq + ( 3 * ( M + 1 ) ), h1, h1, L_FRAME / 2, h1 + ( M + 1 ), 0, M ); @@ -857,22 +857,22 @@ void FEC_scale_syn_ivas_fx( /*rr1 = dotp( h1, h1+1, L_FRAME/2-1 );*/ /*tilt = rr1 / rr0;*/ #ifdef BASOP_NOGLOB - tilt = extract_h( L_shl_sat( get_gain( h1 + 1, h1, L_FRAME / 2 - 1 ), 15 ) ); + tilt = extract_h( L_shl_sat( get_gain( h1 + 1, h1, L_FRAME / 2 - 1 ), 15 ) ); /*Q15*/ #else tilt = extract_h( L_shl( get_gain( h1 + 1, h1, L_FRAME / 2 - 1 ), 15 ) ); #endif pitch_dist = 0; move16(); - L_mean_pitch = L_mult( pitch[0], 8192 ); + L_mean_pitch = L_mult( pitch[0], 8192 ); /*Q14*/ FOR( k = 0; k < ( NB_SUBFR - 1 ); k++ ) { - pitch_dist = add( pitch_dist, abs_s( sub( pitch[k + 1], pitch[k] ) ) ); - L_mean_pitch = L_mac( L_mean_pitch, pitch[k + 1], 8192 ); + pitch_dist = add( pitch_dist, abs_s( sub( pitch[k + 1], pitch[k] ) ) ); /*Q0*/ + L_mean_pitch = L_mac( L_mean_pitch, pitch[k + 1], 8192 ); /*Q14*/ } /*pitch_dist /= (float)(NB_SUBFR-1); */ - pitch_dist = mult_r( shl( pitch_dist, 4 ), 10923 ); + pitch_dist = mult_r( shl( pitch_dist, 4 ), 10923 /*1/(float)(NB_SUBFR-1) in Q15*/ ); /*Q4*/ /*mean_pitch /= (float)(NB_SUBFR);*/ - mean_pitch = extract_h( L_shl( L_mean_pitch, 4 ) ); + mean_pitch = extract_h( L_shl( L_mean_pitch, 4 ) ); /*Q4*/ test(); @@ -894,12 +894,12 @@ void FEC_scale_syn_ivas_fx( } ELSE { - ener_max = *lp_ener_FEC_max; + ener_max = *lp_ener_FEC_max; /*Q0*/ move32(); test(); if ( EQ_16( clas, VOICED_TRANSITION ) || ( GE_16( clas, INACTIVE_CLAS ) ) ) { - ener_max = *lp_ener_FEC_av; + ener_max = *lp_ener_FEC_av; /*Q0*/ move32(); } /*if( enr_old > ener_max )ener_max = enr_old;*/ @@ -934,7 +934,7 @@ void FEC_scale_syn_ivas_fx( { /* voiced -> unvoiced signal transition */ /* CNG -> active signal transition */ - gain1 = gain2; + gain1 = gain2; /*Q14*/ move16(); } ELSE @@ -955,20 +955,20 @@ void FEC_scale_syn_ivas_fx( /*if( gain1 > 1.2f )gain1 = 1.2f;*/ /* prevent clipping */ - gain1 = s_min( gain1, 19661 ); + gain1 = s_min( gain1, 19661 /*1.2F in Q14*/ ); /* prevent amplifying the unvoiced or inactive part of the frame in case an offset is followed by an onset */ test(); test(); if ( EQ_16( clas, ONSET ) && GT_16( gain1, gain2 ) && prev_bfi ) { - gain1 = gain2; + gain1 = gain2; /*Q14*/ move16(); } } - L_enr2 = L_enr_q; - move32(); /* Set the end frame energy to the scaled energy, to be used in the lp_ener_FEC */ + L_enr2 = L_enr_q; /*Q0*/ + move32(); /* Set the end frame energy to the scaled energy, to be used in the lp_ener_FEC */ } /*------------------------------------------------------------------------------* @@ -976,7 +976,7 @@ void FEC_scale_syn_ivas_fx( *------------------------------------------------------------------------------*/ /*gain2 *= ( 1.0f - AGC );*/ - L_tmp = L_mult( gain2, (Word16) ( 32768 - AGC_FX ) ); + L_tmp = L_mult( gain2, (Word16) ( 32768 /*Q15*/ - AGC_FX ) ); FOR( i = 0; i < L_frame; i++ ) { /*gain1 = gain1 * AGC + gain2;*/ @@ -993,7 +993,7 @@ void FEC_scale_syn_ivas_fx( move16(); } /* smoothing is done in excitation domain, so redo synthesis */ - Copy( mem_tmp, mem_syn, M ); + Copy( mem_tmp, mem_syn, M ); /* Q_syn */ syn_12k8_fx( L_frame, Aq, exc2, synth, mem_syn, 1, Q_exc, Q_syn ); *update_flg = 1; move16(); @@ -1009,7 +1009,7 @@ void FEC_scale_syn_ivas_fx( { L_enr_q = L_max( 1, L_enr2 ); /* sets to 'L_enr2' in 1 clock */ set16_fx( h1, 0, L_FRAME / 2 ); - h1[0] = 1024; + h1[0] = 1024; /*1.0f in Q10*/ move16(); /*syn_filt( Aq+(3*(M+1)), M, h1, h1, L_FRAME/2, h1+(M+1), 0 );*/ E_UTIL_synthesis( 1, Aq + ( 3 * ( M + 1 ) ), h1, h1, L_FRAME / 2, h1 + ( M + 1 ), 0, M ); @@ -1018,7 +1018,7 @@ void FEC_scale_syn_ivas_fx( /*rr1 = dotp( h1, h1+1, L_FRAME/2-1 );*/ /*tilt = rr1 / rr0;*/ #ifdef BASOP_NOGLOB - tilt = extract_h( L_shl_sat( get_gain( h1 + 1, h1, L_FRAME / 2 - 1 ), 15 ) ); + tilt = extract_h( L_shl_sat( get_gain( h1 + 1, h1, L_FRAME / 2 - 1 ), 15 ) ); /*Q15*/ #else tilt = extract_h( L_shl( get_gain( h1 + 1, h1, L_FRAME / 2 - 1 ), 15 ) ); #endif @@ -1067,16 +1067,16 @@ void FEC_scale_syn_ivas_fx( tmp = shr( tmp, 1 ); exp = add( exp, 1 ); } - tmp = div_s( tmp, tmp2 ); + tmp = div_s( tmp, tmp2 ); /*Q15*/ /* L_enr_q *= 2 * *old_enr_LP */ - L_enr_q = L_shl( L_mult( tmp, shl( *old_enr_LP, 1 ) ), exp ); + L_enr_q = L_shl( L_mult( tmp, shl( *old_enr_LP, 1 ) ), exp ); /*Q0*/ } ELSE { test(); - IF( avoid_lpc_burst_on_recovery && GT_16( enr_LP, 160 ) ) + IF( avoid_lpc_burst_on_recovery && GT_16( enr_LP, 160 /*20.0f in Q3*/ ) ) { exp = norm_s( enr_LP ); tmp = shl( enr_LP, exp ); @@ -1092,9 +1092,9 @@ void FEC_scale_syn_ivas_fx( tmp = shr( tmp, 1 ); exp = add( exp, 1 ); } - tmp = div_s( tmp, tmp2 ); /* tmp*2^exp = enr_LP/20.0 */ - L_tmp = Isqrt_lc( L_deposit_h( tmp ), &exp ); /* L_tmp*2^exp = sqrt(20.0/enr_LP) */ - L_enr_q = L_shl( Mpy_32_32( L_enr_q, L_tmp ), exp ); + tmp = div_s( tmp, tmp2 ); /* tmp*2^exp = enr_LP/20.0 */ + L_tmp = Isqrt_lc( L_deposit_h( tmp ), &exp ); /* L_tmp*2^exp = sqrt(20.0/enr_LP) */ + L_enr_q = L_shl( Mpy_32_32( L_enr_q, L_tmp ), exp ); /*Q0*/ } } } @@ -1108,7 +1108,7 @@ void FEC_scale_syn_ivas_fx( IF( GT_32( L_enr_q, L_enr_old ) ) /* Prevent energy to increase on voiced */ { - L_enr_q = L_add( Mpy_32_16_1( L_enr_old, 32767 - SCLSYN_LAMBDA ), Mpy_32_16_1( L_enr_q, SCLSYN_LAMBDA ) ); + L_enr_q = L_add( Mpy_32_16_1( L_enr_old, 32767 - SCLSYN_LAMBDA ), Mpy_32_16_1( L_enr_q, SCLSYN_LAMBDA ) ); /*Q0*/ } } } @@ -1144,10 +1144,10 @@ void FEC_scale_syn_ivas_fx( * Clipping of the smoothing gain at the frame end *-----------------------------------------------------------------*/ - gain2 = s_min( gain2, 19661 ); /* Gain modification clipping */ + gain2 = s_min( gain2, 19661 /*1.2f in Q14*/ ); /* Gain modification clipping */ if ( LT_32( L_enr_q, 2 ) ) { - gain2 = s_min( gain2, 16384 ); /* Gain modification clipping */ + gain2 = s_min( gain2, 16384 /*1.0f in Q14*/ ); /* Gain modification clipping */ } /*-----------------------------------------------------------------* @@ -1170,7 +1170,7 @@ void FEC_scale_syn_ivas_fx( ELSE IF( ( GE_16( last_good, VOICED_TRANSITION ) && LT_16( last_good, INACTIVE_CLAS ) && ( clas == UNVOICED_CLAS || EQ_16( clas, INACTIVE_CLAS ) ) ) || /* voiced->unvoiced transition recovery */ EQ_32( last_core_brate, SID_1k75 ) || EQ_32( last_core_brate, SID_2k40 ) || last_core_brate == FRAME_NO_DATA ) /* CNG -> active signal transition */ { - gain1 = gain2; + gain1 = gain2; /*Q14*/ move16(); } ELSE @@ -1207,13 +1207,13 @@ void FEC_scale_syn_ivas_fx( #endif /* exp2 is always <= 1 */ - gain1 = s_min( gain1, 19661 ); + gain1 = s_min( gain1, 19661 /*1.2f in Q14*/ ); /*Q14*/ test(); test(); if ( avoid_lpc_burst_on_recovery && ( GT_16( enr_LP, 160 ) ) && ( LE_16( enr_LP, shl_sat( *old_enr_LP, 1 ) ) ) ) { - gain1 = s_min( gain1, 16384 ); + gain1 = s_min( gain1, 16384 /*1.0f in Q14*/ ); /*Q14*/ } /*--------------------------------------------------------* @@ -1222,7 +1222,7 @@ void FEC_scale_syn_ivas_fx( test(); if ( ( EQ_16( clas, ONSET ) ) && ( GT_16( gain1, gain2 ) ) ) { - gain1 = gain2; + gain1 = gain2; /*Q14*/ move16(); } } @@ -1231,7 +1231,7 @@ void FEC_scale_syn_ivas_fx( * gain1 to gain2 *-----------------------------------------------------------------*/ - L_tmp = L_mult( gain2, (Word16) ( 32768 - AGC_FX ) ); + L_tmp = L_mult( gain2, (Word16) ( 32768 /*Q15*/ - AGC_FX ) ); FOR( i = 0; i < L_frame; i++ ) { @@ -1248,7 +1248,7 @@ void FEC_scale_syn_ivas_fx( move16(); } - Copy( mem_tmp, mem_syn, M ); + Copy( mem_tmp, mem_syn, M ); /* Q_syn */ syn_12k8_fx( L_frame, Aq, exc2, synth, mem_syn, 1, Q_exc, Q_syn ); *update_flg = 1; move16(); @@ -1264,22 +1264,22 @@ void FEC_scale_syn_ivas_fx( { IF( EQ_16( clas, VOICED_TRANSITION ) ) { - L_enr2_av = L_enr2; + L_enr2_av = L_enr2; /*Q0*/ move32(); frame_ener_fx( L_frame, VOICED_CLAS, synth, pitch[sub( shr( L_frame, 6 ), 1 )], &L_ener2_max /*Q0*/, 1, Q_syn, 3, 0 ); } ELSE { - L_ener2_max = L_enr2; + L_ener2_max = L_enr2; /*Q0*/ move32(); frame_ener_fx( L_frame, UNVOICED_CLAS, synth, pitch[sub( shr( L_frame, 6 ), 1 )], &L_enr2_av /*Q0*/, 1, Q_syn, 3, 0 ); } /**lp_ener_FEC_av = 0.2f * enr2_av + 0.8f * *lp_ener_FEC_av; move32();*/ - *lp_ener_FEC_av = Madd_32_16( Mult_32_16( *lp_ener_FEC_av, 31130 ), L_enr2_av, 1638 ); + *lp_ener_FEC_av = Madd_32_16( Mult_32_16( *lp_ener_FEC_av, 31130 /*0.95F in Q15*/ ), L_enr2_av, 1638 /*0.05 in Q15*/ ); move32(); /**lp_ener_FEC_max = 0.2f * enr2_max + 0.8f * *lp_ener_FEC_max; move32();*/ - *lp_ener_FEC_max = Madd_32_16( Mult_32_16( *lp_ener_FEC_max, 31130 ), L_ener2_max, 1638 ); + *lp_ener_FEC_max = Madd_32_16( Mult_32_16( *lp_ener_FEC_max, 31130 /*0.95F in Q15*/ ), L_ener2_max, 1638 /*0.05 in Q15*/ ); move32(); } @@ -1289,7 +1289,7 @@ void FEC_scale_syn_ivas_fx( test(); if ( GE_16( clas, VOICED_TRANSITION ) && LT_16( clas, INACTIVE_CLAS ) ) { - *old_enr_LP = enr_LP; + *old_enr_LP = enr_LP; /*Q3*/ move16(); } diff --git a/lib_dec/amr_wb_dec_fx.c b/lib_dec/amr_wb_dec_fx.c index ef5b4299e..bb1da6f82 100644 --- a/lib_dec/amr_wb_dec_fx.c +++ b/lib_dec/amr_wb_dec_fx.c @@ -16,7 +16,7 @@ *-------------------------------------------------------------------*/ ivas_error amr_wb_dec_fx( - Word16 output_sp[], /* o : synthesis output */ + Word16 output_sp[], /* o : synthesis output Q_syn2*/ Decoder_State *st_fx /* o : Decoder static variables structure */ ) { @@ -28,25 +28,25 @@ ivas_error amr_wb_dec_fx( Word16 tmps; Word16 synth_out_fx[L_FRAME48k]; - Word16 class_para_fx, hf_gain_fx[NB_SUBFR], voice_factors_fx[NB_SUBFR]; + Word16 class_para_fx, hf_gain_fx[NB_SUBFR] /*Q0*/, voice_factors_fx[NB_SUBFR] /*Q15*/; Word16 delay_comp; Word16 last_core_ori; Word16 tmp_buffer_fx[L_FRAME48k]; - Word16 dct_buffer_fx[DCT_L_POST]; + Word16 dct_buffer_fx[DCT_L_POST]; /*Qdct*/ Word16 frame_e_fx; - Word16 exc_buffer_fx[DCT_L_POST]; - Word16 lsp_new_fx[M]; /* LSPs at the end of the frame */ - Word16 lsf_new_fx[M]; /* LSFs at the end of the frame */ + Word16 exc_buffer_fx[DCT_L_POST]; /*Q_exc*/ + Word16 lsp_new_fx[M]; /* LSPs at the end of the frame Q15 */ + Word16 lsf_new_fx[M]; /* LSFs at the end of the frame Qlog2(2.56)*/ Word16 xsp_tmp[M]; - Word16 Aq_fx[NB_SUBFR * ( M + 1 )]; /* A(q) quantized for the 4 subframes */ - Word16 exc2_fx[L_FRAME]; /* total excitation buffer */ - Word16 mem_tmp_fx[M]; /* temporary synthesis filter memory */ + Word16 Aq_fx[NB_SUBFR * ( M + 1 )]; /* A(q) quantized for the 4 subframes Q12*/ + Word16 exc2_fx[L_FRAME]; /* total excitation buffer Q_exc*/ + Word16 mem_tmp_fx[M]; /* temporary synthesis filter memory Q_syn*/ Word32 L_enr_q_fx; /* E information for FER protection */ Word16 tmp_noise_fx; /* Long term temporary noise energy */ Word16 FEC_pitch_fx; /* FEC pitch */ - Word16 dummy_buf_fx[L_FRAME32k]; /* dummy buffer - no usage */ - Word16 old_exc_fx[L_EXC_DEC], *exc_fx; /* excitation signal buffer */ - Word16 syn_tmp_fx[L_FRAME + 2], *syn_fx; /* synthesis signal buffer */ + Word16 dummy_buf_fx[L_FRAME32k]; /* dummy buffer - no usage Q_syn*/ + Word16 old_exc_fx[L_EXC_DEC], *exc_fx; /* excitation signal buffer Q_exc*/ + Word16 syn_tmp_fx[L_FRAME + 2], *syn_fx; /* synthesis signal buffer Q_syn*/ Word32 L_tmp, L_tmp1; Word16 pitch_buf_fx[NB_SUBFR], Qdct, tmp_coder_type; /* Word16 pitch for each subframe (Q6) */ Word16 tmp16; @@ -55,18 +55,18 @@ ivas_error amr_wb_dec_fx( Word32 L_Ng_ener; Word16 exp2, ng_ener; - Word16 bpf_error_signal[L_FRAME]; + Word16 bpf_error_signal[L_FRAME]; /*Q_syn*/ CLDFB_SCALE_FACTOR scaleFactor; Word32 workBuffer[128 * 3]; Word32 q_env[20]; - Word16 exc3[L_FRAME]; - Word16 gain_buf[NB_SUBFR16k]; + Word16 exc3[L_FRAME]; /*Q_exc*/ + Word16 gain_buf[NB_SUBFR16k]; /*Q14*/ Word32 *realBuffer[CLDFB_NO_COL_MAX], *imagBuffer[CLDFB_NO_COL_MAX]; Word32 realBufferTmp[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], imagBufferTmp[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; - Word16 syn_fx_tmp2[L_FRAME]; + Word16 syn_fx_tmp2[L_FRAME]; /*Q0*/ - Word16 pitch_buf_tmp[NB_SUBFR]; + Word16 pitch_buf_tmp[NB_SUBFR]; /*Q6*/ Word16 update_flg; Word8 flag_cna; @@ -137,8 +137,8 @@ ivas_error amr_wb_dec_fx( move16(); st_fx->coder_type = GENERIC; move16(); - output_frame = st_fx->output_frame_fx; - move16(); /* frame length of the input signal */ + output_frame = st_fx->output_frame_fx; /*Q0*/ + move16(); /* frame length of the input signal */ st_fx->bpf_off = 0; move16(); @@ -152,7 +152,7 @@ ivas_error amr_wb_dec_fx( st_fx->igf = 0; move16(); - st_fx->sr_core = i_mult( st_fx->L_frame, 50 ); + st_fx->sr_core = i_mult( st_fx->L_frame, 50 /*FRAMES_PER_SEC*/ ); st_fx->fscale_old = st_fx->fscale; move16(); st_fx->fscale = sr2fscale_fx( st_fx->sr_core ); @@ -162,7 +162,7 @@ ivas_error amr_wb_dec_fx( { st_fx->last_core = AMR_WB_CORE; move16(); - Copy( mean_isf_amr_wb_fx, st_fx->lsf_old_fx, M ); + Copy( mean_isf_amr_wb_fx, st_fx->lsf_old_fx, M ); /*Qlog2(2.56)*/ E_LPC_isf_isp_conversion( st_fx->lsf_old_fx, st_fx->lsp_old_fx, M ); } @@ -188,10 +188,10 @@ ivas_error amr_wb_dec_fx( tmp_noise_fx = 0; move16(); - Copy( st_fx->old_exc_fx, old_exc_fx, L_EXC_MEM_DEC ); + Copy( st_fx->old_exc_fx, old_exc_fx, L_EXC_MEM_DEC ); /*Q_exc*/ exc_fx = old_exc_fx + L_EXC_MEM_DEC; /* reset post-filter in case of switching */ - if ( st_fx->hPFstat->on == 0 ) + IF( st_fx->hPFstat->on == 0 ) { st_fx->hPFstat->reset = 1; move16(); @@ -228,7 +228,7 @@ ivas_error amr_wb_dec_fx( move16(); test(); test(); - if ( st_fx->last_con_tcx && ( NE_16( st_fx->L_frameTCX_past, st_fx->L_frame ) ) && ( st_fx->last_core != 0 ) ) + IF( st_fx->last_con_tcx && ( NE_16( st_fx->L_frameTCX_past, st_fx->L_frame ) ) && ( st_fx->last_core != 0 ) ) { avoid_lpc_burst_on_recovery = 1; move16(); @@ -260,23 +260,23 @@ ivas_error amr_wb_dec_fx( lsp2lsf_fx( st_fx->lsp_old_fx, st_fx->lsf_old_fx, M, INT_FS_FX ); /* FEC - update adaptive LSF mean vector */ - Copy( st_fx->lsf_old_fx, st_fx->lsfoldbfi1_fx, M ); - Copy( st_fx->lsf_old_fx, st_fx->lsfoldbfi0_fx, M ); - Copy( st_fx->lsf_old_fx, st_fx->lsf_adaptive_mean_fx, M ); + Copy( st_fx->lsf_old_fx, st_fx->lsfoldbfi1_fx, M ); /*Qlog2(2.56)*/ + Copy( st_fx->lsf_old_fx, st_fx->lsfoldbfi0_fx, M ); /*Qlog2(2.56)*/ + Copy( st_fx->lsf_old_fx, st_fx->lsf_adaptive_mean_fx, M ); /*Qlog2(2.56)*/ /* Reset LPC mem */ - Copy( GEWB_Ave_fx, st_fx->mem_AR_fx, M ); + Copy( GEWB_Ave_fx, st_fx->mem_AR_fx, M ); /*Qlog2(2.56)*/ set16_fx( st_fx->mem_MA_fx, 0, M ); /* update synthesis filter memories */ synth_mem_updt2( L_FRAME, st_fx->last_L_frame, st_fx->old_exc_fx, st_fx->mem_syn_r, st_fx->mem_syn2_fx, NULL, DEC ); - Copy( st_fx->old_exc_fx, old_exc_fx, L_EXC_MEM_DEC ); + Copy( st_fx->old_exc_fx, old_exc_fx, L_EXC_MEM_DEC ); /*Q_exc*/ Copy_Scale_sig( st_fx->mem_syn2_fx, st_fx->mem_syn1_fx, M, sub( -1, st_fx->Q_syn ) ); /*Q-1*/ - Copy( st_fx->mem_syn2_fx, st_fx->mem_syn3_fx, M ); + Copy( st_fx->mem_syn2_fx, st_fx->mem_syn3_fx, M ); /*Q_syn*/ /* LSP -> ISP */ - Copy( stable_ISP_fx, xsp_tmp, M ); - lsp2isp_fx( st_fx->lsp_old_fx, st_fx->lsp_old_fx, xsp_tmp, M ); + Copy( stable_ISP_fx, xsp_tmp, M ); /*Q15*/ + lsp2isp_fx( st_fx->lsp_old_fx, st_fx->lsp_old_fx, xsp_tmp, M ); /*Q15*/ } /* update buffer of old subframe pitch values */ @@ -286,31 +286,31 @@ ivas_error amr_wb_dec_fx( IF( EQ_16( st_fx->last_L_frame, L_FRAME32k ) ) { /* (float)12800/(float)32000; */ - tmp16 = 13107; + tmp16 = 13107; /*Q15*/ move16(); } ELSE IF( EQ_16( st_fx->last_L_frame, 512 ) ) { /* (float)12800/(float)25600; */ - tmp16 = 16384; + tmp16 = 16384; /*Q15*/ move16(); } ELSE /* st->last_L_frame == L_FRAME16k */ { /* (float)12800/(float)16000; */ - tmp16 = 26214; + tmp16 = 26214; /*Q15*/ move16(); } FOR( i = sub( NB_SUBFR16k, NB_SUBFR ); i < NB_SUBFR16k; i++ ) { - st_fx->old_pitch_buf_fx[i - 1] = Mpy_32_16_1( st_fx->old_pitch_buf_fx[i], tmp16 ); + st_fx->old_pitch_buf_fx[i - 1] = Mpy_32_16_1( st_fx->old_pitch_buf_fx[i], tmp16 ); /*15Q16*/ move32(); } FOR( i = sub( shl( NB_SUBFR16k, 1 ), NB_SUBFR ); i < shl( NB_SUBFR16k, 1 ); i++ ) { - st_fx->old_pitch_buf_fx[i - 2] = Mpy_32_16_1( st_fx->old_pitch_buf_fx[i], tmp16 ); + st_fx->old_pitch_buf_fx[i - 2] = Mpy_32_16_1( st_fx->old_pitch_buf_fx[i], tmp16 ); /*15Q16*/ move32(); } } @@ -321,22 +321,22 @@ ivas_error amr_wb_dec_fx( IF( EQ_16( st_fx->bfi_pitch_frame, L_FRAME32k ) ) { /* (float)12800/(float)32000; */ - tmp16 = 13107; + tmp16 = 13107; /*Q15*/ move16(); } ELSE IF( EQ_16( st_fx->bfi_pitch_frame, 512 ) ) { /* (float)12800/(float)25600; */ - tmp16 = 16384; + tmp16 = 16384; /*Q15*/ move16(); } ELSE /* st->bfi_pitch_frame == L_FRAME16k */ { /* (float)12800/(float)16000; */ - tmp16 = 26214; + tmp16 = 26214; /*Q15*/ move16(); } - st_fx->bfi_pitch_fx = mult_r( tmp16, st_fx->bfi_pitch_fx ); + st_fx->bfi_pitch_fx = mult_r( tmp16, st_fx->bfi_pitch_fx ); /*Q0*/ move16(); st_fx->bfi_pitch_frame = L_FRAME; move16(); @@ -348,9 +348,9 @@ ivas_error amr_wb_dec_fx( { /* reset the unvoiced/audio signal improvement memories */ E_LPC_f_isp_a_conversion( st_fx->lsp_old_fx, st_fx->hAmrwb_IO->old_Aq_fx, M ); - Copy( st_fx->hAmrwb_IO->old_Aq_fx, st_fx->hAmrwb_IO->old_Aq_fx + M + 1, M + 1 ); - Copy( st_fx->hAmrwb_IO->old_Aq_fx, st_fx->hAmrwb_IO->old_Aq_fx + i_mult( 2, M + 1 ), M + 1 ); - Copy( st_fx->hAmrwb_IO->old_Aq_fx, st_fx->hAmrwb_IO->old_Aq_fx + i_mult( 3, M + 1 ), M + 1 ); + Copy( st_fx->hAmrwb_IO->old_Aq_fx, st_fx->hAmrwb_IO->old_Aq_fx + M + 1, M + 1 ); /*Q12*/ + Copy( st_fx->hAmrwb_IO->old_Aq_fx, st_fx->hAmrwb_IO->old_Aq_fx + i_mult( 2, M + 1 ), M + 1 ); /*Q12*/ + Copy( st_fx->hAmrwb_IO->old_Aq_fx, st_fx->hAmrwb_IO->old_Aq_fx + i_mult( 3, M + 1 ), M + 1 ); /*Q12*/ } /*End of _DIFF_FLOAT_FIX_*/ test(); @@ -382,14 +382,14 @@ ivas_error amr_wb_dec_fx( &st_fx->first_CNG, &st_fx->hTdCngDec->cng_ener_seed, dummy_buf_fx, allow_cn_step, &st_fx->hTdCngDec->last_allow_cn_step, st_fx->prev_Q_exc, st_fx->Q_exc, st_fx->hTdCngDec->num_ho, q_env, st_fx->hTdCngDec->lp_env_fx, st_fx->hTdCngDec->old_env_fx, st_fx->hTdCngDec->exc_mem_fx, st_fx->hTdCngDec->exc_mem1_fx, &sid_bw, &st_fx->hTdCngDec->cng_ener_seed1, exc3, st_fx->Opt_AMR_WB, st_fx->element_mode ); - set16_fx( voice_factors_fx, 32767, NB_SUBFR ); + set16_fx( voice_factors_fx, 32767 /*1.0f in Q15*/, NB_SUBFR ); class_para_fx = 0; move16(); delta_mem_scale = 3; move16(); - if ( LT_32( st_fx->lp_ener_fx, 40 ) ) /* very low energy frames, less than 0.3125 */ + IF( LT_32( st_fx->lp_ener_fx, 40 ) ) /* very low energy frames, less than 0.3125 */ { delta_mem_scale = 0; move16(); @@ -404,8 +404,8 @@ ivas_error amr_wb_dec_fx( Copy_Scale_sig( exc2_fx, exc2_fx, st_fx->L_frame, sub( st_fx->Q_exc, i ) ); /* update past excitation signals for LD music post-filter */ - Copy( hMusicPF->dct_post_old_exc_fx + L_FRAME, hMusicPF->dct_post_old_exc_fx, DCT_L_POST - L_FRAME - OFFSET2 ); - Copy( exc2_fx, hMusicPF->dct_post_old_exc_fx + ( DCT_L_POST - L_FRAME - OFFSET2 ), L_FRAME ); + Copy( hMusicPF->dct_post_old_exc_fx + L_FRAME, hMusicPF->dct_post_old_exc_fx, DCT_L_POST - L_FRAME - OFFSET2 ); /*Q_exc*/ + Copy( exc2_fx, hMusicPF->dct_post_old_exc_fx + ( DCT_L_POST - L_FRAME - OFFSET2 ), L_FRAME ); /*Q_exc*/ /* synthesis at 12k8 Hz sampling rate */ syn_12k8_fx( L_FRAME, Aq_fx, exc2_fx, syn_fx, st_fx->mem_syn2_fx, 1, st_fx->Q_exc, st_fx->Q_syn ); @@ -425,18 +425,18 @@ ivas_error amr_wb_dec_fx( move16(); frame_energy_fx( L_FRAME, pitch_temp, syn_fx, 0, &frame_e_fx, st_fx->Q_syn ); /*st->psf_lp_noise = 0.99f * st->psf_lp_noise + 0.01f * frame_e; */ - st_fx->psf_lp_noise_fx = round_fx( L_mac( L_mult( 32440, st_fx->psf_lp_noise_fx ), 328, frame_e_fx ) ); /*Q8*/ + st_fx->psf_lp_noise_fx = round_fx( L_mac( L_mult( 32440 /*Q15*/, st_fx->psf_lp_noise_fx ), 328 /*Q15*/, frame_e_fx ) ); /*Q8*/ move16(); } /* update old synthesis for classification */ - Copy( syn_fx + L_FRAME - L_SYN_MEM_CLAS_ESTIM, st_fx->mem_syn_clas_estim_fx, L_SYN_MEM_CLAS_ESTIM ); + Copy( syn_fx + L_FRAME - L_SYN_MEM_CLAS_ESTIM, st_fx->mem_syn_clas_estim_fx, L_SYN_MEM_CLAS_ESTIM ); /*Q_syn*/ /* Update music post processing values */ /* Filter energies update */ FOR( i = 0; i < DCT_L_POST; i++ ) { /*st->filt_lfE[i] = 0.3f + 0.7f * st->filt_lfE[i];*/ - hMusicPF->filt_lfE_fx[i] = round_fx( L_mac( L_deposit_h( 1229 ), 22938, hMusicPF->filt_lfE_fx[i] ) ); + hMusicPF->filt_lfE_fx[i] = round_fx( L_mac( L_deposit_h( 1229 /*Q12*/ ), 22938 /*Q15*/, hMusicPF->filt_lfE_fx[i] ) ); /*Q12*/ } vad_flag = 0; @@ -456,8 +456,8 @@ ivas_error amr_wb_dec_fx( test(); IF( EQ_32( st_fx->last_core_brate, FRAME_NO_DATA ) || EQ_32( st_fx->last_core_brate, SID_1k75 ) ) { - Copy( st_fx->lspCNG_fx, st_fx->lsp_old_fx, M ); - E_LPC_isp_isf_conversion( st_fx->lspCNG_fx, st_fx->lsf_old_fx, M ); + Copy( st_fx->lspCNG_fx, st_fx->lsp_old_fx, M ); /*Q15*/ + E_LPC_isp_isf_conversion( st_fx->lspCNG_fx, st_fx->lsf_old_fx, M ); /*Qx1.28*/ set16_fx( old_exc_fx, 0, L_EXC_MEM_DEC ); } @@ -470,7 +470,7 @@ ivas_error amr_wb_dec_fx( st_fx->coder_type = GENERIC; move16(); - if ( vad_flag == 0 ) + IF( vad_flag == 0 ) { st_fx->coder_type = INACTIVE; move16(); @@ -508,8 +508,8 @@ ivas_error amr_wb_dec_fx( move32(); FOR( i = 0; i < M; i++ ) { - L_tmp = L_mult( 3277, lsp_new_fx[i] ); - st_fx->lspCNG_fx[i] = round_fx( L_mac( L_tmp, 29491, st_fx->lspCNG_fx[i] ) ); + L_tmp = L_mult( 3277 /*0.1f in Q15*/, lsp_new_fx[i] ); + st_fx->lspCNG_fx[i] = round_fx( L_mac( L_tmp, 29491 /*0.9f in Q15*/, st_fx->lspCNG_fx[i] ) ); /*Q15*/ move16(); } } @@ -535,14 +535,14 @@ ivas_error amr_wb_dec_fx( move16(); test(); test(); - if ( EQ_16( st_fx->coder_type, INACTIVE ) && st_fx->flag_cna && GE_16( st_fx->psf_lp_noise_fx, shl( 15, 7 ) ) ) + IF( EQ_16( st_fx->coder_type, INACTIVE ) && st_fx->flag_cna && GE_16( st_fx->psf_lp_noise_fx, shl( 15, 7 ) ) ) { tmp16 = 1; move16(); } Rescale_mem( st_fx->Q_exc, &st_fx->prev_Q_syn, &st_fx->Q_syn, st_fx->mem_syn2_fx, st_fx->mem_syn_clas_estim_fx, 5, &st_fx->mem_deemph_fx, hBPF->pst_old_syn_fx, &hBPF->pst_mem_deemp_err_fx, &st_fx->agc_mem_fx[1], st_fx->hPFstat, vad_flag, tmp16, tmp_buffer_fx ); - Copy( st_fx->mem_syn2_fx, mem_tmp_fx, M ); + Copy( st_fx->mem_syn2_fx, mem_tmp_fx, M ); /*Q_syn*/ syn_12k8_fx( L_FRAME, Aq_fx, exc2_fx, syn_fx, st_fx->mem_syn2_fx, 1, st_fx->Q_exc, st_fx->Q_syn ); /*------------------------------------------------------------* @@ -563,9 +563,9 @@ ivas_error amr_wb_dec_fx( 0, 0, 0, st_fx->last_core_brate, -1 ); #endif /* update past excitation signals for LD music post-filter */ - Copy( hMusicPF->dct_post_old_exc_fx + L_FRAME, hMusicPF->dct_post_old_exc_fx, DCT_L_POST - L_FRAME - OFFSET2 ); - Copy( exc2_fx, hMusicPF->dct_post_old_exc_fx + ( DCT_L_POST - L_FRAME - OFFSET2 ), L_FRAME ); - Copy( hMusicPF->dct_post_old_exc_fx, exc_buffer_fx, DCT_L_POST - OFFSET2 ); + Copy( hMusicPF->dct_post_old_exc_fx + L_FRAME, hMusicPF->dct_post_old_exc_fx, DCT_L_POST - L_FRAME - OFFSET2 ); /*Q_exc*/ + Copy( exc2_fx, hMusicPF->dct_post_old_exc_fx + ( DCT_L_POST - L_FRAME - OFFSET2 ), L_FRAME ); /*Q_exc*/ + Copy( hMusicPF->dct_post_old_exc_fx, exc_buffer_fx, DCT_L_POST - OFFSET2 ); /*Q_exc*/ IF( NE_16( output_frame, L_FRAME8k ) ) { @@ -585,7 +585,7 @@ ivas_error amr_wb_dec_fx( tmp_coder_type = AUDIO; move16(); test(); - if ( EQ_16( st_fx->last_coder_type, INACTIVE ) || EQ_16( st_fx->last_coder_type, UNVOICED ) ) + IF( EQ_16( st_fx->last_coder_type, INACTIVE ) || EQ_16( st_fx->last_coder_type, UNVOICED ) ) { tmp_coder_type = INACTIVE; move16(); @@ -613,7 +613,7 @@ ivas_error amr_wb_dec_fx( FOR( i = 0; i < DCT_L_POST; i++ ) { /*st->filt_lfE[i] = 0.3f + 0.7f * st->filt_lfE[i] ;*/ - hMusicPF->filt_lfE_fx[i] = round_fx( L_mac( L_deposit_h( 1229 ), 22938, hMusicPF->filt_lfE_fx[i] ) ); + hMusicPF->filt_lfE_fx[i] = round_fx( L_mac( L_deposit_h( 1229 /*0.3f in Q12*/ ), 22938 /*Q15*/, hMusicPF->filt_lfE_fx[i] ) ); /*Q12*/ move16(); } } @@ -632,7 +632,7 @@ ivas_error amr_wb_dec_fx( FOR( i = 0; i < NB_SUBFR; i++ ) { - pitch_buf_tmp[i] = mult_r( pitch_buf_fx[i], 512 ); + pitch_buf_tmp[i] = mult_r( pitch_buf_fx[i], 512 ); /*Q0*/ move16(); } @@ -652,7 +652,7 @@ ivas_error amr_wb_dec_fx( { /* long burst frame erasures */ test(); - if ( GT_16( st_fx->nbLostCmpt, 5 ) && GE_16( st_fx->clas_dec, VOICED_CLAS ) ) + IF( GT_16( st_fx->nbLostCmpt, 5 ) && GE_16( st_fx->clas_dec, VOICED_CLAS ) ) { st_fx->last_good = VOICED_TRANSITION; move16(); @@ -678,8 +678,8 @@ ivas_error amr_wb_dec_fx( syn_12k8_fx( L_FRAME, Aq_fx, exc_fx, tmp_buffer_fx, st_fx->mem_syn1_fx, 1, st_fx->Q_exc, -1 ); /* update past excitation signals */ - Copy( hMusicPF->dct_post_old_exc_fx + L_FRAME, hMusicPF->dct_post_old_exc_fx, DCT_L_POST - L_FRAME - OFFSET2 ); - Copy( exc2_fx, hMusicPF->dct_post_old_exc_fx + ( DCT_L_POST - L_FRAME - OFFSET2 ), L_FRAME ); + Copy( hMusicPF->dct_post_old_exc_fx + L_FRAME, hMusicPF->dct_post_old_exc_fx, DCT_L_POST - L_FRAME - OFFSET2 ); /*Q_exc*/ + Copy( exc2_fx, hMusicPF->dct_post_old_exc_fx + ( DCT_L_POST - L_FRAME - OFFSET2 ), L_FRAME ); /*Q_exc*/ /* Update music post processing values */ /* Update circular buffer, keep last energy difference unchanged */ @@ -698,17 +698,17 @@ ivas_error amr_wb_dec_fx( Rescale_mem( st_fx->Q_exc, &st_fx->prev_Q_syn, &st_fx->Q_syn, st_fx->mem_syn2_fx, st_fx->mem_syn_clas_estim_fx, 4, &st_fx->mem_deemph_fx, hBPF->pst_old_syn_fx, &hBPF->pst_mem_deemp_err_fx, &st_fx->agc_mem_fx[1], st_fx->hPFstat, 1, 0, tmp_buffer_fx ); - Copy( st_fx->mem_syn2_fx, mem_tmp_fx, M ); + Copy( st_fx->mem_syn2_fx, mem_tmp_fx, M ); /*Q_syn*/ /* synthesis at 12k8 Hz sampling rate */ syn_12k8_fx( L_FRAME, Aq_fx, exc2_fx, syn_fx, st_fx->mem_syn2_fx, 1, st_fx->Q_exc, st_fx->Q_syn ); /* update old synthesis for classification */ - Copy( syn_fx + L_FRAME - L_SYN_MEM_CLAS_ESTIM, st_fx->mem_syn_clas_estim_fx, L_SYN_MEM_CLAS_ESTIM ); + Copy( syn_fx + L_FRAME - L_SYN_MEM_CLAS_ESTIM, st_fx->mem_syn_clas_estim_fx, L_SYN_MEM_CLAS_ESTIM ); /*Q_syn*/ FOR( i = 0; i < NB_SUBFR; i++ ) { - pitch_buf_tmp[i] = mult_r( pitch_buf_fx[i], 512 ); + pitch_buf_tmp[i] = mult_r( pitch_buf_fx[i], 512 ); /*Q0*/ move16(); } @@ -734,7 +734,7 @@ ivas_error amr_wb_dec_fx( { FOR( i = 0; i < NB_SUBFR; i++ ) { - pitch_buf_tmp[i] = mult_r( pitch_buf_fx[i], 512 ); + pitch_buf_tmp[i] = mult_r( pitch_buf_fx[i], 512 ); /*Q0*/ move16(); } IF( EQ_16( output_frame, L_FRAME8k ) ) @@ -756,22 +756,22 @@ ivas_error amr_wb_dec_fx( *-----------------------------------------------------------------*/ /* update old synthesis buffer - needed for ACELP internal sampling rate switching */ - Copy( syn_fx + L_FRAME - L_SYN_MEM, st_fx->mem_syn_r, L_SYN_MEM ); + Copy( syn_fx + L_FRAME - L_SYN_MEM, st_fx->mem_syn_r, L_SYN_MEM ); /*Q_syn*/ deemph_fx( syn_fx, PREEMPH_FAC, L_FRAME, &( st_fx->mem_deemph_fx ) ); unscale_AGC( syn_fx, st_fx->Q_syn, syn_fx_tmp2, st_fx->agc_mem_fx, L_FRAME ); - Copy( syn_fx_tmp2, syn_fx, L_FRAME ); + Copy( syn_fx_tmp2, syn_fx, L_FRAME ); /*Q0*/ /* TCX=Q-1, ACELP2 Q0 */ - Copy_Scale_sig( syn_fx + L_FRAME / 2, hTcxDec->old_syn_Overl, L_FRAME / 2, sub( -1, st_fx->Q_syn ) ); /*Q_syn*/ - Copy_Scale_sig( syn_fx + L_FRAME - M - 1, st_fx->syn, M + 1, sub( 0, st_fx->Q_syn ) ); /*Q0*/ + Copy_Scale_sig( syn_fx + L_FRAME / 2, hTcxDec->old_syn_Overl, L_FRAME / 2, sub( -1, st_fx->Q_syn ) ); + Copy_Scale_sig( syn_fx + L_FRAME - M - 1, st_fx->syn, M + 1, sub( 0, st_fx->Q_syn ) ); /*------------------------------------------------------------------* * Formant post-filter *-----------------------------------------------------------------*/ - Copy( syn_fx, tmp_buffer_fx + L_SYN_MEM, L_FRAME ); + Copy( syn_fx, tmp_buffer_fx + L_SYN_MEM, L_FRAME ); /*Q0*/ IF( NE_16( output_frame, L_FRAME8k ) && NE_16( st_fx->last_bwidth, NB ) ) { st_fx->hPFstat->on = 1; @@ -850,7 +850,7 @@ ivas_error amr_wb_dec_fx( { FOR( i = 0; i < L_FRAME / 2; i++ ) { - syn_fx[i] = add( syn_fx[i], shr_r( st_fx->hFdCngDec->hFdCngCom->olapBufferSynth2[add( i, shr( i_mult( 5, L_FRAME ), 2 ) )], -st_fx->Q_syn ) ); + syn_fx[i] = add( syn_fx[i], shr_r( st_fx->hFdCngDec->hFdCngCom->olapBufferSynth2[( i + shr( ( 5 * L_FRAME ), 2 ) )], -st_fx->Q_syn ) ); /*Q_syn*/ move16(); } } @@ -933,9 +933,9 @@ ivas_error amr_wb_dec_fx( tmp16 = norm_l( L_Ng_ener ); exp2 = Log2_norm_lc( L_shl( L_Ng_ener, tmp16 ) ); tmp16 = sub( 30, tmp16 ); - ng_ener = mac_r( L_shl( L_mac( -1233858L, tmp16, 24660 ), 10 ), exp2, 771 ); + ng_ener = mac_r( L_shl( L_mac( -1233858L, tmp16, 24660 /*10/log2(10) in Q13*/ ), 10 ), exp2, 771 ); /*Q8*/ /* st_fx->ng_ener_ST = 0.7f * st_fx->ng_ener_ST + 0.3f * ng_ener; */ - st_fx->Ng_ener_ST_fx = mac_r( L_mult( st_fx->Ng_ener_ST_fx, 22938 ), ng_ener, 9830 ); + st_fx->Ng_ener_ST_fx = mac_r( L_mult( st_fx->Ng_ener_ST_fx, 22938 /*0.7f in Q15*/ ), ng_ener, 9830 /*0.3f in Q15*/ ); /*Q8*/ move16(); /*-----------------------------------------------------------------* @@ -962,7 +962,7 @@ ivas_error amr_wb_dec_fx( updt_dec_fx( st_fx, old_exc_fx, pitch_buf_fx, 0, Aq_fx, lsf_new_fx, lsp_new_fx, voice_factors_fx, dummy_buf_fx, gain_buf ); /* update old_Aq[] - needed in improv_amr_wb_gs_fx() */ - Copy( Aq_fx, st_fx->hAmrwb_IO->old_Aq_fx, NB_SUBFR * ( M + 1 ) ); + Copy( Aq_fx, st_fx->hAmrwb_IO->old_Aq_fx, NB_SUBFR * ( M + 1 ) ); /*Q12*/ test(); test(); @@ -972,7 +972,7 @@ ivas_error amr_wb_dec_fx( test(); test(); - if ( !st_fx->bfi && st_fx->prev_bfi && GE_32( st_fx->last_total_brate, HQ_48k ) && EQ_16( st_fx->last_codec_mode, MODE2 ) && ( EQ_16( st_fx->last_core_bfi, TCX_20_CORE ) || EQ_16( st_fx->last_core_bfi, TCX_10_CORE ) ) && EQ_16( st_fx->plcInfo.concealment_method, TCX_NONTONAL ) && LT_32( st_fx->plcInfo.nbLostCmpt, 4 ) ) + IF( !st_fx->bfi && st_fx->prev_bfi && GE_32( st_fx->last_total_brate, HQ_48k ) && EQ_16( st_fx->last_codec_mode, MODE2 ) && ( EQ_16( st_fx->last_core_bfi, TCX_20_CORE ) || EQ_16( st_fx->last_core_bfi, TCX_10_CORE ) ) && EQ_16( st_fx->plcInfo.concealment_method, TCX_NONTONAL ) && LT_32( st_fx->plcInfo.nbLostCmpt, 4 ) ) { waveadj_rec = 1; move16(); @@ -1025,7 +1025,7 @@ ivas_error amr_wb_dec_fx( } delay_comp = NS2SA_FX2( st_fx->output_Fs, DELAY_CLDFB_NS ); - Scale_sig( st_fx->delay_buf_out_fx, delay_comp, sub( st_fx->Q_syn2, hHQ_core->Q_old_postdec ) ); + Scale_sig( st_fx->delay_buf_out_fx, delay_comp, sub( st_fx->Q_syn2, hHQ_core->Q_old_postdec ) ); /*Q_syn2 - Q_old_postdec*/ hHQ_core->Q_old_postdec = st_fx->Q_syn2; move16(); IF( EQ_16( last_core_ori, HQ_CORE ) ) @@ -1036,7 +1036,7 @@ ivas_error amr_wb_dec_fx( hHQ_core->Q_old_wtda = st_fx->Q_syn2; move16(); - Copy( st_fx->delay_buf_out_fx, synth_out_fx, delay_comp ); /* copy the HQ/ACELP delay synchroniation buffer at the beginning of ACELP frame */ + Copy( st_fx->delay_buf_out_fx, synth_out_fx, delay_comp ); /* copy the HQ/ACELP delay synchroniation buffer at the beginning of ACELP frame Q0*/ i = 15; move16(); @@ -1056,7 +1056,7 @@ ivas_error amr_wb_dec_fx( FOR( i = 0; i < tmps; i++ ) { #ifdef BASOP_NOGLOB - synth_out_fx[add( i, delay_comp )] = msu_r_sat( L_mult( synth_out_fx[add( i, delay_comp )], alpha ), hHQ_core->old_out_fx[add( i, nz )], add( alpha, -32768 ) ); + synth_out_fx[( i + delay_comp )] = msu_r_sat( L_mult( synth_out_fx[( i + delay_comp )], alpha ), hHQ_core->old_out_fx[( i + nz )], add( alpha, -32768 ) ); #else synth_out_fx[i + delay_comp] = msu_r( L_mult( synth_out_fx[i + delay_comp], alpha ), hHQ_core->old_out_fx[i + nz], add( alpha, -32768 ) ); #endif @@ -1110,7 +1110,7 @@ ivas_error amr_wb_dec_fx( Scale_sig( hTcxLtpDec->tcxltp_mem_out, output_frame, sub( st_fx->Q_syn2, st_fx->Qprev_synth_buffer_fx ) ); tcx_ltp_post( st_fx, hTcxLtpDec, ACELP_CORE, output_frame, 0, synth_out_fx, NULL ); } - + assert( 0 ); /* final output of synthesis signal */ syn_output_fx( st_fx->codec_mode, synth_out_fx, output_frame, output_sp, st_fx->Q_syn2 ); @@ -1132,23 +1132,23 @@ void amr_wb_dec_init_fx( /* gain quantization memory (used in AMR-WB IO mode) */ FOR( i = 0; i < GAIN_PRED_ORDER; i++ ) { - hAmrwb_IO->past_qua_en_fx[i] = -14336; - move16(); /* Q10; */ /* gain quantization memory (used also in AMR-WB IO mode) */ + hAmrwb_IO->past_qua_en_fx[i] = -14336; /*-14.0f in Q10*/ + move16(); /* Q10; */ /* gain quantization memory (used also in AMR-WB IO mode) */ } /* Improvement of unvoiced and audio signals in AMR-WB IO mode */ hAmrwb_IO->UV_cnt_fx = 30; move16(); - hAmrwb_IO->LT_UV_cnt_fx = ( 60 << 6 ); + hAmrwb_IO->LT_UV_cnt_fx = ( 60 << 6 ); /*Q6*/ move16(); set16_fx( hAmrwb_IO->lt_diff_etot_fx, 0, MAX_LT ); hAmrwb_IO->Last_ener_fx = 0; move16(); set16_fx( hAmrwb_IO->old_Aq_fx, 0, i_mult( NB_SUBFR, M + 1 ) ); - hAmrwb_IO->old_Aq_fx[0] = 16384; - hAmrwb_IO->old_Aq_fx[M + 1] = 16384; - hAmrwb_IO->old_Aq_fx[2 * ( M + 1 )] = 16384; - hAmrwb_IO->old_Aq_fx[3 * ( M + 1 )] = 16384; + hAmrwb_IO->old_Aq_fx[0] = 16384; /*1.0f in Q14*/ + hAmrwb_IO->old_Aq_fx[M + 1] = 16384; /*1.0f in Q14*/ + hAmrwb_IO->old_Aq_fx[2 * ( M + 1 )] = 16384; /*1.0f in Q14*/ + hAmrwb_IO->old_Aq_fx[3 * ( M + 1 )] = 16384; /*1.0f in Q14*/ move16(); move16(); move16(); diff --git a/lib_dec/ari_dec_fx.c b/lib_dec/ari_dec_fx.c index 294bffc6a..3681568f2 100644 --- a/lib_dec/ari_dec_fx.c +++ b/lib_dec/ari_dec_fx.c @@ -41,7 +41,7 @@ void ari_start_decoding_14bits_fx( } Word16 ari_start_decoding_14bits_prm_fx( - const Word16 *ptr, + const Word16 *ptr, /* Q0 */ Word16 bp, Tastat *s ) { @@ -51,7 +51,7 @@ Word16 ari_start_decoding_14bits_prm_fx( val = L_deposit_l( 0 ); - p = ptr + bp; + p = ptr + bp; /* Q0 */ FOR( i = 0; i < cbitsnew; i++ ) { @@ -74,7 +74,8 @@ Word16 ari_start_decoding_14bits_prm_fx( static Word16 ari_lookup_s17_fx( Word32 cum, Word32 range, - UWord16 const *cum_freq ) + UWord16 const *cum_freq /* Q0 */ +) { Word32 tmp; const UWord16 *p; @@ -131,7 +132,8 @@ static Word16 ari_lookup_s17_fx( static Word16 ari_lookup_s27_fx( Word32 cum, Word32 range, - UWord16 const *cum_freq ) + UWord16 const *cum_freq /* Q0 */ +) { Word32 tmp; Word16 range_l, range_h; @@ -229,7 +231,8 @@ static Word16 ari_lookup_s27_fx( static Word16 ari_lookup_bit_fx( Word32 cum, Word32 range, - UWord16 const *cum_freq ) + UWord16 const *cum_freq /* Q0 */ +) { Word16 symbol = 0; /* initialize just to avoid compiler warning */ move16(); @@ -256,7 +259,7 @@ static Word16 ari_lookup_bit_fx( static Word16 ari_decode_14bits_ext_fx( Decoder_State *st, Tastat *s, - UWord16 const *cum_freq, + UWord16 const *cum_freq, /* Q0 */ Word16 ( *lookup_fn )( Word32 cum, Word32 range, UWord16 const *cum_freq ) ) { Word32 cum; @@ -457,7 +460,7 @@ static Word16 ari_lookup_sign_fx( Tastat *s, Word16 base ) } static Word16 ari_decode_14bits_notbl_fx( - Word16 *ptr, + Word16 *ptr, /* Q0 */ Word16 bp, Word16 bits, Word16 *res, diff --git a/lib_dec/ivas_agc_dec_fx.c b/lib_dec/ivas_agc_dec_fx.c index f4a7c7e9c..f620f59f3 100644 --- a/lib_dec/ivas_agc_dec_fx.c +++ b/lib_dec/ivas_agc_dec_fx.c @@ -147,7 +147,7 @@ void ivas_spar_agc_dec_close_fx( ivas_agc_dec_state_t *hAgc; test(); - if ( hAgcDec == NULL || *hAgcDec == NULL ) + IF( hAgcDec == NULL || *hAgcDec == NULL ) { return; } @@ -178,8 +178,8 @@ void ivas_spar_agc_dec_close_fx( void ivas_agc_dec_process_fx( ivas_agc_dec_state_t *hAgcDec, /* i/o: AGC decoder handle */ - Word32 *pcm_in[], /* i : input audio channels */ - Word32 *pcm_out[], /* o : output audio channels */ + Word32 *pcm_in[], /* i : input audio channels Qx*/ + Word32 *pcm_out[], /* o : output audio channels Q_pcm_in - 3*/ const Word16 n_channels, /* i : number of channels */ const Word16 output_frame /* i : output frame length */ ) @@ -198,7 +198,8 @@ void ivas_agc_dec_process_fx( move16(); test(); - IF( GT_16( pState->gain_state[i].gainExpVal, ( pState->agc_com.maxAttExp + 1 ) ) || LT_16( pState->gain_state[i].gainExpVal, -1 ) ) + + IF( GT_16( pState->gain_state[i].gainExpVal, add( pState->agc_com.maxAttExp, 1 ) ) || LT_16( pState->gain_state[i].gainExpVal, -1 ) ) { /* Such conditions indicate packet loss, better reset and do nothing*/ pState->gain_data[i].absGainExp = pState->agc_com.absEmin; @@ -211,11 +212,12 @@ void ivas_agc_dec_process_fx( // gainLast = 1.f / pState->gain_state[i].lastGain; tmp = negate( sub( pState->gain_data[i].absGainExp, pState->agc_com.absEmin ) ); + IF( tmp < 0 ) { tmp_2 = MAX_16; move16(); - FOR( idx = 0; idx < negate( tmp ); idx++ ) + FOR( idx = 0; idx < -tmp; idx++ ) { tmp_2 = mult( pState->agc_com.winFunc_fx[offset - 1], tmp_2 ); } @@ -227,10 +229,10 @@ void ivas_agc_dec_process_fx( move16(); FOR( idx = 0; idx < ( tmp ); idx++ ) { - tmp_2 = mult( pState->agc_com.winFunc_fx[offset - 1], tmp_2 ); + tmp_2 = mult( pState->agc_com.winFunc_fx[offset - 1], tmp_2 ); // Q15(15+15-15) } } - pState->gain_state[i].lastGain_fx = tmp_2; + pState->gain_state[i].lastGain_fx = tmp_2; // Q15 move16(); gainLast = div_l( ONE_IN_Q29, pState->gain_state[i].lastGain_fx ); // Q13 @@ -247,9 +249,9 @@ void ivas_agc_dec_process_fx( { tmp_2 = MAX_16; move16(); - FOR( j = 0; j < negate( tmp ); j++ ) + FOR( j = 0; j < -tmp; j++ ) { - tmp_2 = mult( pState->agc_com.winFunc_fx[idx - pState->agc_com.in_delay], tmp_2 ); + tmp_2 = mult( pState->agc_com.winFunc_fx[idx - pState->agc_com.in_delay], tmp_2 ); // Q14(15+14-15) } IF( tmp_2 < 0 ) { @@ -267,7 +269,7 @@ void ivas_agc_dec_process_fx( move16(); FOR( j = 0; j < ( tmp ); j++ ) { - tmp_2 = mult( pState->agc_com.winFunc_fx[sub( idx, pState->agc_com.in_delay )], tmp_2 ); + tmp_2 = mult( pState->agc_com.winFunc_fx[idx - pState->agc_com.in_delay], tmp_2 ); // Q15 (15+15-15) } tmp_2 = shr( tmp_2, 1 ); // Q14 } @@ -289,11 +291,11 @@ void ivas_agc_dec_process_fx( { tmp_2 = MAX_16; move16(); - FOR( idx = 0; idx < negate( tmp ); idx++ ) + FOR( idx = 0; idx < -tmp; idx++ ) { - tmp_2 = mult( pState->agc_com.winFunc_fx[offset - 1], tmp_2 ); + tmp_2 = mult( pState->agc_com.winFunc_fx[offset - 1], tmp_2 ); // Q14 (14+15-15) } - tmp_2 = div_l( ONE_IN_Q30, tmp_2 ); + tmp_2 = div_l( ONE_IN_Q30, tmp_2 ); // Q14 } ELSE { @@ -301,11 +303,11 @@ void ivas_agc_dec_process_fx( move16(); FOR( idx = 0; idx < ( tmp ); idx++ ) { - tmp_2 = mult( pState->agc_com.winFunc_fx[offset - 1], tmp_2 ); + tmp_2 = mult( pState->agc_com.winFunc_fx[offset - 1], tmp_2 ); // Q15 } tmp_2 = shr( tmp_2, 1 ); // Q14 } - pState->gain_state[i].lastGain_fx = mult( pState->gain_state[i].lastGain_fx, tmp_2 ); + pState->gain_state[i].lastGain_fx = mult( pState->gain_state[i].lastGain_fx, tmp_2 ); // Q14 move16(); } ELSE @@ -356,11 +358,12 @@ void ivas_agc_read_bits_fx( IF( EQ_16( per_ch_bit[i], 1 ) ) { pState->gain_data[i].absGainExpCurr = get_next_indice_fx( st0, (Word16) pState->agc_com.betaE ); + move16(); } ELSE { - pState->gain_data[i].absGainExpCurr = (Word32) pState->agc_com.absEmin; - move32(); + pState->gain_data[i].absGainExpCurr = (Word16) pState->agc_com.absEmin; + move16(); } } } @@ -368,8 +371,8 @@ void ivas_agc_read_bits_fx( { FOR( i = 0; i < n_channels; i++ ) { - pState->gain_data[i].absGainExpCurr = (Word32) pState->agc_com.absEmin; - move32(); + pState->gain_data[i].absGainExpCurr = (Word16) pState->agc_com.absEmin; + move16(); } } diff --git a/lib_dec/ivas_binRenderer_internal.c b/lib_dec/ivas_binRenderer_internal.c index 1a6961108..f38fe4612 100644 --- a/lib_dec/ivas_binRenderer_internal.c +++ b/lib_dec/ivas_binRenderer_internal.c @@ -127,10 +127,10 @@ static void ivas_binRenderer_filterModule( *-------------------------------------------------------------------------*/ static void ivas_binRenderer_filterModule_fx( - Word64 out_Conv_CLDFB_real[BINAURAL_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* o : real part of Binaural signals */ - Word64 out_Conv_CLDFB_imag[BINAURAL_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* o : imag part of Binaural signals */ - Word32 CLDFB_real[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i : real part of LS signals */ - Word32 CLDFB_imag[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i : imag part of LS signals */ + Word64 out_Conv_CLDFB_real[BINAURAL_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* o : real part of Binaural signals Q29 */ + Word64 out_Conv_CLDFB_imag[BINAURAL_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* o : imag part of Binaural signals Q29 */ + Word32 CLDFB_real[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i : real part of LS signals Q_curr*/ + Word32 CLDFB_imag[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i : imag part of LS signals Q_curr*/ const Word16 numTimeSlots, /* i : number of time slots to process */ BINAURAL_RENDERER_HANDLE hBinRenderer, /* i/o: fastconv binaural renderer handle */ Word16 Q_curr ) @@ -269,11 +269,13 @@ static ivas_error ivas_binRenderer_convModuleOpen( IF( !isLoudspeaker ) { hBinRenderer->nInChannels = audioCfg2channels( input_config ); + move16(); } ELSE { /* Note: needs to be revisited if multiple LFE support is required */ hBinRenderer->nInChannels = sub( audioCfg2channels( input_config ), isLoudspeaker ); + move16(); } IF( EQ_16( renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) @@ -904,7 +906,7 @@ void ivas_init_binaural_hrtf( *-------------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED static ivas_error ivas_alloc_pppMem_fx( - Word32 ****pppMem, + Word32 ****pppMem, /*Qx*/ const Word16 dim1, const Word16 dim2, const Word16 dim3, @@ -1671,10 +1673,10 @@ static void ivas_binaural_obtain_DMX( static void ivas_binaural_obtain_DMX_fx( const Word16 numTimeSlots, BINAURAL_RENDERER_HANDLE hBinRenderer, /* i/o: fastconv binaural renderer handle */ - Word32 RealBuffer[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* i : Contains the LS signals */ - Word32 ImagBuffer[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* i : Contains the LS signals */ - Word32 realDMX[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], - Word32 imagDMX[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX] ) + Word32 RealBuffer[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* i : Contains the LS signals Q_in */ + Word32 ImagBuffer[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* i : Contains the LS signals Q_in */ + Word32 realDMX[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /*Q_in-1*/ + Word32 imagDMX[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX] ) /*Q_in-1*/ { Word16 chIdx, bandIdx, k; @@ -1737,7 +1739,7 @@ static void ivas_binaural_obtain_DMX_fx( test(); IF( ( P_in_fx[bandIdx] <= 0 ) || ( P_out_fx <= 0 ) ) { - factEQ_fx = 0x40000000; + factEQ_fx = 0x40000000; // 1.0f in Q30 move32(); } ELSE @@ -1749,11 +1751,11 @@ static void ivas_binaural_obtain_DMX_fx( } if ( factEQ_fx <= 0 ) { - factEQ_fx = 0x40000000; + factEQ_fx = 0x40000000; // 1.0f in Q30 move32(); } - factEQ_fx = L_max( L_min( factEQ_fx, 0x7fffffff ), 0x20000000 ); // Q30 + factEQ_fx = L_max( L_min( factEQ_fx, 0x7fffffff ), 0x20000000 ); // Q30 , 0x7fffffff -> (1.0f in Q31)-1, 0x20000000 ->1.0f in Q29 FOR( k = 0; k < numTimeSlots; k++ ) { realDMX[chOutIdx][k][bandIdx] = Mpy_32_32( realDMX[chOutIdx][k][bandIdx], factEQ_fx ); // Q_in - 1 @@ -1860,6 +1862,8 @@ ivas_error ivas_binRenderer_open_fx( move32(); } hBinRenderer->max_band = extract_l( Mpy_32_32( Mpy_32_32( BINAURAL_MAXBANDS_Q25, L_shl( st_ivas->hDecoderConfig->output_Fs, Q6 ) ), ONE_BY_48000_Q31 ) ); + move16(); + convBand = hBinRenderer->max_band; move16(); @@ -2429,7 +2433,7 @@ void ivas_binRenderer_close( *------------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED static void ivas_free_pppHrtfMem_fx( - Word32 ****ppppHRIR, + Word32 ****ppppHRIR, /*Qx*/ const Word16 dim, const Word16 alloc_init ) { @@ -2631,8 +2635,8 @@ void ivas_binaural_add_LFE( void ivas_binaural_add_LFE_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ Word16 output_frame, /* i : length of input frame */ - Word32 *input_fx[], /* i : transport channels */ - Word32 *output_fx[] /* o : synthesized core-coder transport channels/DirAC output */ + Word32 *input_fx[], /* i : transport channels Q11*/ + Word32 *output_fx[] /* o : synthesized core-coder transport channels/DirAC output Q11*/ ) { Word16 render_lfe, idx_lfe, gain_fx; @@ -2701,10 +2705,10 @@ void ivas_binRenderer_fx( BINAURAL_RENDERER_HANDLE hBinRenderer, /* i/o: binaural renderer handle */ COMBINED_ORIENTATION_HANDLE hCombinedOrientationData, /* i : combined head and external orientation handle*/ const Word16 numTimeSlots, /* i : number of time slots to render */ - Word32 Cldfb_RealBuffer_Binaural_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* o : Binaural signals */ - Word32 Cldfb_ImagBuffer_Binaural_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* o : Binaural signals */ - Word32 RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i : LS signals */ - Word32 ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i : LS signals */ + Word32 Cldfb_RealBuffer_Binaural_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* o : Binaural signals Q_in*/ + Word32 Cldfb_ImagBuffer_Binaural_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* o : Binaural signals Q_in*/ + Word32 RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i : LS signals Q_in*/ + Word32 ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i : LS signals Q_in*/ Word16 *Q_in /* i : LS signals exp */ ) { @@ -2819,8 +2823,8 @@ void ivas_binRenderer_fx( FOR( k = 0; k < numTimeSlots; k++ ) { /* Combine first and second parts to generate binaural output signal with room effect */ - v_add_32( Cldfb_RealBuffer_Binaural_fx[chIdx][k], reverbRe_fx[chIdx][k], Cldfb_RealBuffer_Binaural_fx[chIdx][k], hBinRenderer->conv_band ); - v_add_32( Cldfb_ImagBuffer_Binaural_fx[chIdx][k], reverbIm_fx[chIdx][k], Cldfb_ImagBuffer_Binaural_fx[chIdx][k], hBinRenderer->conv_band ); + v_add_32( Cldfb_RealBuffer_Binaural_fx[chIdx][k], reverbRe_fx[chIdx][k], Cldfb_RealBuffer_Binaural_fx[chIdx][k], hBinRenderer->conv_band ); // Q_in + v_add_32( Cldfb_ImagBuffer_Binaural_fx[chIdx][k], reverbIm_fx[chIdx][k], Cldfb_ImagBuffer_Binaural_fx[chIdx][k], hBinRenderer->conv_band ); // Q_in } } } diff --git a/lib_dec/ivas_entropy_decoder.c b/lib_dec/ivas_entropy_decoder.c index a3530dd40..56a2ec358 100644 --- a/lib_dec/ivas_entropy_decoder.c +++ b/lib_dec/ivas_entropy_decoder.c @@ -61,7 +61,8 @@ static void ivas_arith_decode_array( ivas_arith_t *pArith, Decoder_State *st0, /* i/o: decoder state structure - for bitstream handling*/ const Word16 in_len, - Word16 *pSymbols ) + Word16 *pSymbols /*Q0*/ +) { Word16 i, ind, model_idx; Word16 *pCum_freq = NULL; @@ -125,10 +126,11 @@ static void ivas_arith_decode_array( static void ivas_arithCoder_decode_array_diff( ivas_arith_t *pArith, ivas_arith_t *pArith_diff, - Word16 *pSymbol_old, + Word16 *pSymbol_old, /*Q0*/ const Word16 length, Decoder_State *st0, /* i/o: decoder state structure - for bitstream handling*/ - Word16 *pOutput_arr ) + Word16 *pOutput_arr /*Q0*/ +) { Word16 n; Word16 offset = pArith->vals[0]; @@ -145,11 +147,7 @@ static void ivas_arithCoder_decode_array_diff( move16(); } -#ifndef IVAS_FLOAT_FIXED - ivas_wrap_arround( pOutput_arr, 0, sub( pArith_diff->range, 1 ), length ); -#else ivas_wrap_arround_fx( pOutput_arr, 0, sub( pArith_diff->range, 1 ), length ); -#endif FOR( n = 0; n < length; n++ ) { @@ -168,7 +166,7 @@ static void ivas_arithCoder_decode_array_diff( *-----------------------------------------------------------------------------------------*/ static Word16 ivas_huffman_code_bits_present( - const Word16 *codebook, + const Word16 *codebook, /*Q0*/ const Word16 code, const Word16 bits, const Word16 len ) @@ -178,7 +176,7 @@ static Word16 ivas_huffman_code_bits_present( move16(); Word16 ind_t, code_t, bits_t; - WHILE( LT_16( i, len ) ) + WHILE( i < len ) { ind_t = codebook[0]; move16(); @@ -219,7 +217,7 @@ ivas_error ivas_huffman_decode( ind = ivas_huffman_code_bits_present( huff_cfg->codebook, code, num_bits_read, huff_cfg->sym_len ); - WHILE( GT_16( ind, huff_cfg->sym_len ) ) + WHILE( ind > huff_cfg->sym_len ) { bit = get_next_indice_fx( st0, 1 ); num_bits_read = add( num_bits_read, 1 ); @@ -248,7 +246,8 @@ static void arith_decode_cell_array( Decoder_State *st0, /* i/o: decoder state structure - for bitstream handling*/ Word16 num_bands, ivas_arith_t *pArith, - Word16 *pSymbol ) + Word16 *pSymbol /*Q0*/ +) { Word16 total_symbol_len = 0; move16(); @@ -279,8 +278,9 @@ static void arith_decode_cell_array_diff( Word16 num_bands, ivas_arith_t *pArith, ivas_arith_t *pArith_diff, - Word16 *pSymbol, - Word16 *pSymbol_old ) + Word16 *pSymbol, /*Q0*/ + Word16 *pSymbol_old /*Q0*/ +) { Word16 total_symbol_len = 0; move16(); @@ -309,10 +309,11 @@ void ivas_arith_decode_cmplx_cell_array( ivas_arith_t *pArith_re_diff, Decoder_State *st0, /* i/o: decoder state structure - for bitstream handling*/ ivas_cell_dim_t *pCell_dims, - Word16 *pDo_diff, + Word16 *pDo_diff, /*Q0*/ const Word16 num_bands, - Word16 *pSymbol_re, - Word16 *pSymbol_re_old ) + Word16 *pSymbol_re, /*Q0*/ + Word16 *pSymbol_re_old /*Q0*/ +) { Word16 i, j, len, all_diff = 1, any_diff = 0; move16(); @@ -407,7 +408,7 @@ void ivas_arith_decode_cmplx_cell_array( { IF( pDo_diff[i] != 0 ) { - FOR( j = 0; j < imult1616( cell_dims_diff[i].dim1, cell_dims_diff[i].dim2 ); j++ ) + FOR( j = 0; j < cell_dims_diff[i].dim1 * cell_dims_diff[i].dim2; j++ ) { pSymbol_re[idx] = cell_arr_diff_out[idx2]; move16(); @@ -417,7 +418,7 @@ void ivas_arith_decode_cmplx_cell_array( } ELSE { - FOR( j = 0; j < imult1616( cell_dims[i].dim1, cell_dims[i].dim2 ); j++ ) + FOR( j = 0; j < cell_dims[i].dim1 * cell_dims[i].dim2; j++ ) { pSymbol_re[idx] = cell_arr_no_diff[idx1]; move16(); diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index deaf84d4e..1206d0ed1 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -87,7 +87,7 @@ ivas_error ivas_dec_setup( move16(); ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; - move16(); + move32(); /*-------------------------------------------------------------------* * Read IVAS format @@ -129,8 +129,7 @@ ivas_error ivas_dec_setup( iDiv_and_mod_32( ivas_total_brate, FRAMES_PER_SEC, &res_dec, &res_frac, 0 ); k = extract_l( L_sub( res_dec, 1 ) ); - test(); - WHILE( st_ivas->bit_stream[k] && LT_16( nchan_ism, MAX_NUM_OBJECTS ) ) + WHILE( st_ivas->bit_stream[k] && ( nchan_ism < MAX_NUM_OBJECTS ) ) { nchan_ism = add( nchan_ism, 1 ); k = sub( k, 1 ); @@ -235,7 +234,7 @@ ivas_error ivas_dec_setup( Word32 res_dec, res_frac; iDiv_and_mod_32( ivas_total_brate, FRAMES_PER_SEC, &res_dec, &res_frac, 0 ); - st_ivas->nchan_ism = add( add( shl( st_ivas->bit_stream[L_sub( res_dec, 1 )], 1 ), st_ivas->bit_stream[L_sub( res_dec, 2 )] ), 1 ); + st_ivas->nchan_ism = add( add( shl( st_ivas->bit_stream[res_dec - 1], 1 ), st_ivas->bit_stream[res_dec - 2] ), 1 ); move16(); st_ivas->ism_mode = ivas_omasa_ism_mode_select_fx( ivas_total_brate, st_ivas->nchan_ism ); move16(); @@ -258,7 +257,7 @@ ivas_error ivas_dec_setup( /* the number of objects is written at the end of the bitstream, in the SBA metadata */ Word32 res_dec, res_frac; iDiv_and_mod_32( ivas_total_brate, FRAMES_PER_SEC, &res_dec, &res_frac, 0 ); - st_ivas->nchan_ism = add( add( shl( st_ivas->bit_stream[L_sub( res_dec, 1 )], 1 ), st_ivas->bit_stream[L_sub( res_dec, 2 )] ), 1 ); + st_ivas->nchan_ism = add( add( shl( st_ivas->bit_stream[res_dec - 1], 1 ), st_ivas->bit_stream[res_dec - 2] ), 1 ); move16(); test(); @@ -326,7 +325,7 @@ ivas_error ivas_dec_setup( move16(); FOR( k = 0; k < MC_LS_SETUP_BITS; k++ ) { - IF( st_ivas->bit_stream[add( num_bits_read, k )] ) + IF( st_ivas->bit_stream[num_bits_read + k] ) { idx = add( idx, shl( 1, sub( ( MC_LS_SETUP_BITS - 1 ), k ) ) ); } @@ -393,7 +392,7 @@ ivas_error ivas_dec_setup( case SID_MASA_2TC:; // empyt statement for declaration Word32 res_dec, res_frac; iDiv_and_mod_32( ivas_total_brate, FRAMES_PER_SEC, &res_dec, &res_frac, 0 ); - IF( EQ_16( st_ivas->bit_stream[L_sub( L_sub( res_dec, 1 ), SID_FORMAT_NBITS )], 1 ) ) + IF( EQ_16( st_ivas->bit_stream[( res_dec - 1 ) - SID_FORMAT_NBITS], 1 ) ) { st_ivas->element_mode_init = IVAS_CPE_MDCT; move16(); @@ -471,8 +470,8 @@ ivas_error ivas_dec_setup( iDiv_and_mod_32( ivas_total_brate, FRAMES_PER_SEC, &res_dec, &res_frac, 0 ); k = extract_l( L_sub( L_sub( res_dec, 1 ), SID_FORMAT_NBITS ) ); move16(); - test(); - WHILE( st_ivas->bit_stream[k] && LT_16( nchan_ism, MAX_NUM_OBJECTS ) ) + + WHILE( st_ivas->bit_stream[k] && ( nchan_ism < MAX_NUM_OBJECTS ) ) { nchan_ism = add( nchan_ism, 1 ); k = sub( k, 1 ); @@ -480,7 +479,7 @@ ivas_error ivas_dec_setup( k = sub( k, 1 ); test(); - if ( st_ivas->ini_frame > 0 && NE_16( nchan_ism, st_ivas->nchan_ism ) ) + IF( st_ivas->ini_frame > 0 && NE_16( nchan_ism, st_ivas->nchan_ism ) ) { return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "wrong number of objects signalled!" ); } @@ -516,8 +515,8 @@ ivas_error ivas_dec_setup( * Initialize decoder in the first good frame based on IVAS format * and number of transport channels *-------------------------------------------------------------------*/ - - IF( st_ivas->ini_frame == 0 && st_ivas->ivas_format != UNDEFINED_FORMAT ) + test(); + IF( st_ivas->ini_frame == 0 && NE_32( st_ivas->ivas_format, UNDEFINED_FORMAT ) ) { IF( NE_32( ( error = doSanityChecks_IVAS( st_ivas ) ), IVAS_ERR_OK ) ) { @@ -983,6 +982,7 @@ static ivas_error ivas_read_format( *num_bits_read = 0; move16(); test(); + test(); IF( !st_ivas->bfi && is_DTXrate( ivas_total_brate ) == 0 ) { /* read IVAS format */ @@ -1049,13 +1049,13 @@ static ivas_error ivas_read_format( st_ivas->ivas_format = SBA_FORMAT; move32(); /* read Ambisonic (SBA) planar flag */ - st_ivas->sba_planar = st_ivas->bit_stream[add( ( *num_bits_read ), 1 )]; + st_ivas->sba_planar = st_ivas->bit_stream[( *num_bits_read ) + 1]; move16(); /* read Ambisonic (SBA) order */ - st_ivas->sba_order = st_ivas->bit_stream[add( add( ( *num_bits_read ), 2 ), SBA_PLANAR_BITS )]; + st_ivas->sba_order = st_ivas->bit_stream[( *num_bits_read ) + 2 + SBA_PLANAR_BITS]; move16(); - st_ivas->sba_order = add( st_ivas->sba_order, shl( st_ivas->bit_stream[add( add( ( *num_bits_read ), 1 ), SBA_PLANAR_BITS )], 1 ) ); + st_ivas->sba_order = add( st_ivas->sba_order, shl( st_ivas->bit_stream[( *num_bits_read ) + 1 + SBA_PLANAR_BITS], 1 ) ); move16(); if ( st_ivas->sba_order == 0 ) { @@ -1076,7 +1076,7 @@ static ivas_error ivas_read_format( move16(); FOR( k = 0; k < SID_FORMAT_NBITS; k++ ) { - idx = add( idx, shl( st_ivas->bit_stream[k], sub( sub( SID_FORMAT_NBITS, 1 ), k ) ) ); + idx += st_ivas->bit_stream[k] << ( SID_FORMAT_NBITS - 1 - k ); } ( *num_bits_read ) = add( *num_bits_read, SID_FORMAT_NBITS ); @@ -1484,7 +1484,7 @@ ivas_error ivas_init_decoder_front( st_ivas->mc_mode = MC_MODE_NONE; move32(); st_ivas->sba_dirac_stereo_flag = 0; - move32(); + move16(); /* HRTF binauralization latency in ns */ st_ivas->binaural_latency_ns = 0; @@ -1577,7 +1577,8 @@ ivas_error ivas_init_decoder_front( /*-------------------------------------------------------------------* * Allocate and initialize Binaural Renderer configuration handle *--------------------------------------------------------------------*/ - + test(); + test(); IF( EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL ) || EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) || EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) { IF( NE_32( ( error = ivas_render_config_open( &( st_ivas->hRenderConfig ) ) ), IVAS_ERR_OK ) ) @@ -1773,11 +1774,11 @@ ivas_error ivas_init_decoder_fx( ELSE IF( !EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) ) { hDecoderConfig->nchan_out = st_ivas->nchan_transport; - move32(); + move16(); } st_ivas->hOutSetup.nchan_out_woLFE = hDecoderConfig->nchan_out; - move32(); + move16(); } /*-----------------------------------------------------------------* @@ -1791,12 +1792,13 @@ ivas_error ivas_init_decoder_fx( IF( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) && EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) ) { st_ivas->hOutSetup.ambisonics_order = SBA_HOA3_ORDER; - move32(); + move16(); st_ivas->intern_config = IVAS_AUDIO_CONFIG_7_1_4; move32(); st_ivas->hOutSetup.output_config = st_ivas->intern_config; move32(); st_ivas->hOutSetup.nchan_out_woLFE = audioCfg2channels( st_ivas->intern_config ); + move16(); } test(); IF( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) && EQ_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) @@ -2231,7 +2233,6 @@ ivas_error ivas_init_decoder_fx( } - test(); test(); test(); IF( NE_32( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_FOA ) && NE_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_STEREO ) && NE_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_MONO ) ) @@ -2301,6 +2302,7 @@ ivas_error ivas_init_decoder_fx( } /* create CPE element for DFT Stereo like upmix */ + test(); IF( st_ivas->sba_dirac_stereo_flag && st_ivas->nCPE == 0 ) { Word32 res_dec, res_frac; @@ -2353,9 +2355,9 @@ ivas_error ivas_init_decoder_fx( k = 0; move16(); ism_total_brate = 0; - move16(); - test(); - WHILE( LT_16( k, SIZE_IVAS_BRATE_TBL ) && NE_32( ivas_total_brate, ivas_brate_tbl[k] ) ) + move32(); + + WHILE( ( k < SIZE_IVAS_BRATE_TBL ) && ( ivas_total_brate != ivas_brate_tbl[k] ) ) { k = add( k, 1 ); } @@ -2387,7 +2389,7 @@ ivas_error ivas_init_decoder_fx( FOR( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) { temp_brate[sce_id] = sep_object_brate[k - 2][st_ivas->nSCE - 1]; - move16(); + move32(); ism_total_brate = L_add( ism_total_brate, temp_brate[sce_id] ); IF( NE_32( ( error = create_sce_dec( st_ivas, sce_id, temp_brate[sce_id] ) ), IVAS_ERR_OK ) ) @@ -2586,14 +2588,14 @@ ivas_error ivas_init_decoder_fx( st_ivas->sba_dirac_stereo_flag = ivas_get_sba_dirac_stereo_flag( st_ivas ); move16(); test(); - IF( st_ivas->renderer_type != RENDERER_DISABLE && NE_32( st_ivas->renderer_type, RENDERER_MCMASA_MONO_STEREO ) ) + IF( NE_32( st_ivas->renderer_type, RENDERER_DISABLE ) && NE_32( st_ivas->renderer_type, RENDERER_MCMASA_MONO_STEREO ) ) { IF( NE_32( ( error = ivas_dirac_dec_config_fx( st_ivas, DIRAC_OPEN ) ), IVAS_ERR_OK ) ) { return error; } } - + test(); test(); IF( EQ_32( st_ivas->hOutSetup.output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && st_ivas->hOutSetup.separateChannelEnabled && !st_ivas->hLsSetupCustom->separate_ch_found ) { @@ -2605,7 +2607,7 @@ ivas_error ivas_init_decoder_fx( move16(); IF( EQ_16( st_ivas->hLsSetupCustom->num_spk, 1 ) ) { - inv_sqr = 32767; + inv_sqr = 32767; // (1.0f in Q15)-1 move16(); } ELSE @@ -2615,11 +2617,11 @@ ivas_error ivas_init_decoder_fx( exp_sqr = sub( exp_sqr, exp ); IF( ( exp < 0 ) ) { - inv_sqr = shr( inv_sqr, exp ); + inv_sqr = shr( inv_sqr, exp ); // exp_sqr } ELSE { - inv_sqr = shl( inv_sqr, exp ); + inv_sqr = shl( inv_sqr, exp ); // exp_sqr } } set16_fx( st_ivas->hLsSetupCustom->separate_ch_gains_fx, inv_sqr, st_ivas->hLsSetupCustom->num_spk ); @@ -2669,6 +2671,8 @@ ivas_error ivas_init_decoder_fx( } /* set CNA/CNG flags */ + test(); + test(); IF( EQ_16( st_ivas->nchan_transport, 1 ) && ( ( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) ) ) { st_ivas->hSCE[0]->hCoreCoder[0]->cna_dirac_flag = 1; @@ -2777,7 +2781,7 @@ ivas_error ivas_init_decoder_fx( } granularity = NS2SA( st_ivas->hDecoderConfig->output_Fs, FRAME_SIZE_NS / MAX_PARAM_SPATIAL_SUBFRAMES ); - move16(); + n_channels_transport_jbm = ivas_jbm_dec_get_num_tc_channels_fx( st_ivas ); @@ -2827,7 +2831,7 @@ ivas_error ivas_init_decoder_fx( IF( ( EQ_32( st_ivas->ivas_format, MC_FORMAT ) ) && ( EQ_32( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) ) ) { granularity = NS2SA_FX2( output_Fs, CLDFB_SLOT_NS ); - move16(); + n_channels_transport_jbm = ivas_jbm_dec_get_num_tc_channels_fx( st_ivas ); @@ -2839,7 +2843,7 @@ ivas_error ivas_init_decoder_fx( ELSE { granularity = NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, FRAME_SIZE_NS / MAX_PARAM_SPATIAL_SUBFRAMES ); - move16(); + n_channels_transport_jbm = ivas_jbm_dec_get_num_tc_channels_fx( st_ivas ); IF( NE_32( ( error = ivas_jbm_dec_tc_buffer_open_fx( st_ivas, TC_BUFFER_MODE_RENDERER, n_channels_transport_jbm, n_channels_transport_jbm, n_channels_transport_jbm, granularity ) ), IVAS_ERR_OK ) ) @@ -2867,7 +2871,6 @@ ivas_error ivas_init_decoder_fx( if ( EQ_32( st_ivas->ivas_format, MC_FORMAT ) && NE_32( st_ivas->transport_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) { nchan_rend = sub( nchan_rend, 1 ); /* Skip LFE channel -- added to the others */ - move16(); } FOR( Word16 nS = 0; nS < nchan_rend; nS++ ) { @@ -3044,14 +3047,14 @@ ivas_error ivas_init_decoder_fx( FOR( i = 0; i < st_ivas->cldfbAnaDec[0]->cldfb_state_length; i++ ) { st_ivas->cldfbAnaDec[0]->cldfb_state_fx[i] = L_shr( st_ivas->cldfbAnaDec[0]->cldfb_state_fx[i], 16 ); // Scaling down from 27 to 11 - move16(); + move32(); } st_ivas->cldfbAnaDec[0]->Q_cldfb_state = Q11; move16(); FOR( i = 0; i < st_ivas->cldfbSynDec[0]->cldfb_state_length; i++ ) { st_ivas->cldfbSynDec[0]->cldfb_state_fx[i] = L_shr( st_ivas->cldfbSynDec[0]->cldfb_state_fx[i], sub( 21, Q_cldfbSynDec ) ); // Scaling down from 21 to Q_cldfbSynDec - move16(); + move32(); } st_ivas->cldfbSynDec[0]->Q_cldfb_state = Q11; move16(); @@ -3080,7 +3083,6 @@ ivas_error ivas_init_decoder_fx( { return error; } - move16(); // For NS2SA } IF( st_ivas->hTcBuffer == NULL ) @@ -4759,7 +4761,8 @@ void ivas_destroy_dec_fx( IF( st_ivas->hCPE[i] != NULL ) { /* set pointer to NULL as core coder already deallocated in destroy_sce_dec() */ - IF( st_ivas->sba_dirac_stereo_flag && st_ivas->nchan_transport == 1 ) + test(); + IF( st_ivas->sba_dirac_stereo_flag && EQ_16( st_ivas->nchan_transport, 1 ) ) { st_ivas->hCPE[i]->hCoreCoder[0] = NULL; st_ivas->hCPE[i]->hCoreCoder[1] = NULL; @@ -5201,7 +5204,7 @@ void ivas_init_dec_get_num_cldfb_instances( move16(); } - IF( ivas_format == SBA_ISM_FORMAT ) + IF( EQ_32( ivas_format, SBA_ISM_FORMAT ) ) { IF( EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) { @@ -5665,7 +5668,7 @@ static ivas_error doSanityChecks_IVAS( /* Verify output configuration compatible with non-diegetic panning */ test(); test(); - IF( st_ivas->hDecoderConfig->Opt_non_diegetic_pan && ( st_ivas->ivas_format != MONO_FORMAT ) && ( st_ivas->transport_config != IVAS_AUDIO_CONFIG_ISM1 ) ) + IF( st_ivas->hDecoderConfig->Opt_non_diegetic_pan && NE_32( st_ivas->ivas_format, MONO_FORMAT ) && NE_32( st_ivas->transport_config, IVAS_AUDIO_CONFIG_ISM1 ) ) { return IVAS_ERROR( IVAS_ERR_INVALID_OUTPUT_FORMAT, "Error: Non-diegetic panning not supported in this IVAS format" ); } diff --git a/lib_enc/acelp_core_enc.c b/lib_enc/acelp_core_enc.c index f13ac41ff..0b3ec7709 100644 --- a/lib_enc/acelp_core_enc.c +++ b/lib_enc/acelp_core_enc.c @@ -1549,15 +1549,7 @@ ivas_error acelp_core_enc( #ifndef IVAS_FLOAT_FIXED update_average_rate( st->hSC_VBR, st->core_brate ); #else -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - // performing float to fix conversions - st->hSC_VBR->SNR_THLD_fx = float_to_fix16( st->hSC_VBR->SNR_THLD, 8 ); -#endif update_average_rate_fx( st->hSC_VBR, st->core_brate ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - // performing fix to float conversions - st->hSC_VBR->SNR_THLD = fix16_to_float( st->hSC_VBR->SNR_THLD_fx, 8 ); -#endif #endif } } diff --git a/lib_enc/amr_wb_enc.c b/lib_enc/amr_wb_enc.c index 02a5152f7..e6b872d46 100644 --- a/lib_enc/amr_wb_enc.c +++ b/lib_enc/amr_wb_enc.c @@ -522,87 +522,12 @@ void amr_wb_enc( updt_enc( st, old_exc_flt, pitch_buf, 0, Aq, isf_new, isp_new, dummy_buf ); /* update main codec paramaters */ -#ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - f2me_buf_16( st->buf_speech_enc_pe_flt, st->buf_speech_enc_pe, &st->exp_buf_speech_enc_pe, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); - f2me_buf_16( st->buf_speech_enc_flt, st->buf_speech_enc, &st->exp_buf_speech_enc, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); - f2me_buf_16( st->buf_synth_flt, st->buf_synth, &st->exp_buf_synth, OLD_SYNTH_SIZE_ENC + L_FRAME32k ); - IF( st->hTcxEnc != NULL ) - { - f2me_buf_16( st->buf_wspeech_enc_flt, st->buf_wspeech_enc, &st->exp_buf_wspeech_enc, L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k ); - f2me_buf_16( st->hTcxEnc->buf_speech_ltp_flt, st->hTcxEnc->buf_speech_ltp, &st->hTcxEnc->exp_buf_speech_ltp, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); - } - IF( st->element_mode > EVS_MONO && st->hTcxEnc != NULL ) - { - st->hTcxEnc->tcxltp_norm_corr_past = float_to_fix16( st->hTcxEnc->tcxltp_norm_corr_past_flt, 15 ); - } -#endif - - updt_enc_common_ivas_fx( st ); - -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - me2f_buf_16( st->buf_speech_enc_pe, st->exp_buf_speech_enc_pe, st->buf_speech_enc_pe_flt, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); - me2f_buf_16( st->buf_speech_enc, st->exp_buf_speech_enc, st->buf_speech_enc_flt, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); - me2f_buf_16( st->buf_synth, st->exp_buf_synth, st->buf_synth_flt, OLD_SYNTH_SIZE_ENC + L_FRAME32k ); - IF( st->hTcxEnc != NULL ) - { - me2f_buf_16( st->buf_wspeech_enc, st->exp_buf_wspeech_enc, st->buf_wspeech_enc_flt, L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k ); - me2f_buf_16( st->hTcxEnc->buf_speech_ltp, st->hTcxEnc->exp_buf_speech_ltp, st->hTcxEnc->buf_speech_ltp_flt, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); - } - - IF( ( st->Opt_DTX_ON && LE_32( st->core_brate, SID_2k40 ) && EQ_16( st->cng_type, FD_CNG ) ) || ( st->tcxonly && ( EQ_16( st->codec_mode, MODE2 ) || GT_16( st->element_mode, EVS_MONO ) ) ) ) - { - set_zero( st->mem_MA, M ); - mvr2r( GEWB_Ave, st->mem_AR, M ); - } - - IF( st->hTcxEnc != NULL ) - { - IF( st->element_mode != IVAS_CPE_MDCT ) - { - st->hTcxEnc->kernel_switch_corr_past_flt = 0.f; - } - } - - IF( st->element_mode > EVS_MONO && st->hTcxEnc != NULL ) - { - st->hTcxEnc->tcxltp_norm_corr_mem_flt = fixedToFloat( st->hTcxEnc->tcxltp_norm_corr_mem, 31 ); - } - - IF( EQ_16( st->element_mode, EVS_MONO ) && EQ_16( st->mdct_sw, MODE2 ) ) - { - IF( EQ_32( st->sr_core, INT_FS_12k8 ) ) - { - st->preemph_fac_flt = PREEMPH_FAC_FLT; - st->gamma_flt = GAMMA1_FLT; - } - ELSE - { - st->preemph_fac_flt = PREEMPH_FAC_16k_FLT; - st->gamma_flt = GAMMA16k_FLT; - } - } - - IF( st->Opt_DTX_ON && st->hTdCngEnc != NULL ) - { - IF( EQ_16( st->element_mode, IVAS_SCE ) || EQ_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_CPE_TD ) || EQ_16( st->hDtxEnc->first_CNG, 1 ) ) - { - IF( ( EQ_16( st->element_mode, IVAS_SCE ) || EQ_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_CPE_TD ) ) && GE_16( st->hTdCngEnc->act_cnt2, MIN_ACT_CNG_UPD ) ) - { - st->hTdCngEnc->CNG_att = fix16_to_float( st->hTdCngEnc->CNG_att_fx, Q7 ); - } - } - } -#endif -#else updt_enc_common( st ); -#endif pop_wmops(); return; } -#endif /*---------------------------------------------------------------------* * amr_wb_enc_init() @@ -628,3 +553,4 @@ void amr_wb_enc_init( return; } +#endif diff --git a/lib_enc/core_enc_init.c b/lib_enc/core_enc_init.c index a3dfe262a..a8959b652 100644 --- a/lib_enc/core_enc_init.c +++ b/lib_enc/core_enc_init.c @@ -94,15 +94,8 @@ void init_coder_ace_plus_ivas_fx( } } - IF( st->ini_frame == 0 ) - { - st->prevTempFlatness = 1.0f; - } - IF( st->hBWE_TD != NULL ) { - set_f( st->hBWE_TD->prev_lsf_diff, 0.5f, LPC_SHB_ORDER - 2 ); - st->hBWE_TD->prev_tilt_para = 0.0f; set_zero( st->hBWE_TD->cur_sub_Aq, M + 1 ); } @@ -391,12 +384,6 @@ void init_coder_ace_plus_ivas_fx( move16(); st->glr_idx[1] = 0; move16(); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - st->mean_gc_flt[0] = 0.0f; - st->mean_gc_flt[1] = 0.0f; - st->prev_lsf4_mean_flt = 0.0f; - st->last_stab_fac_flt = 0.0f; -#endif st->mean_gc[0] = 0; move16(); st->mean_gc[1] = 0; @@ -469,15 +456,23 @@ void init_coder_ace_plus( if ( st->ini_frame == 0 ) { st->acelpFramesCount = 0; +#ifndef IVAS_FLOAT_FIXED st->prevTempFlatness = 1.0f; +#endif } /* Initialize TBE */ if ( st->hBWE_TD != NULL ) { st->hBWE_TD->prev_coder_type = GENERIC; +#ifndef IVAS_FLOAT_FIXED set_f( st->hBWE_TD->prev_lsf_diff, 0.5f, LPC_SHB_ORDER - 2 ); st->hBWE_TD->prev_tilt_para = 0.0f; +#else + set16_fx( st->hBWE_TD->prev_lsf_diff_fx, 16384, LPC_SHB_ORDER - 2 ); + st->hBWE_TD->prev_tilt_para_fx = 0; + move16(); +#endif set_zero( st->hBWE_TD->cur_sub_Aq, M + 1 ); } @@ -640,11 +635,12 @@ void init_coder_ace_plus( st->glr_idx[0] = 0; st->glr_idx[1] = 0; +#ifndef IVAS_FLOAT_FIXED st->mean_gc_flt[0] = 0.0f; st->mean_gc_flt[1] = 0.0f; st->prev_lsf4_mean_flt = 0.0f; st->last_stab_fac_flt = 0.0f; -#ifdef IVAS_FLOAT_FIXED +#else st->mean_gc[0] = 0; st->mean_gc[1] = 0; st->prev_lsf4_mean = 0; diff --git a/lib_enc/core_switching_enc.c b/lib_enc/core_switching_enc.c index 3362ca589..fc9c3a017 100644 --- a/lib_enc/core_switching_enc.c +++ b/lib_enc/core_switching_enc.c @@ -101,8 +101,13 @@ void core_switching_pre_enc( if ( hHQ_core != NULL ) { +#ifndef IVAS_FLOAT_FIXED set_f( hHQ_core->last_ni_gain, 0, BANDS_MAX ); set_f( hHQ_core->last_env, 0, BANDS_MAX ); +#else + set32_fx( hHQ_core->last_ni_gain_fx, 0, BANDS_MAX ); + set16_fx( hHQ_core->last_env_fx, 0, BANDS_MAX ); +#endif hHQ_core->last_max_pos_pulse = 0; @@ -138,8 +143,13 @@ void core_switching_pre_enc( if ( st->core == HQ_CORE && ( st->last_core == ACELP_CORE || st->last_core == AMR_WB_CORE ) ) /* HQ init */ { +#ifndef IVAS_FLOAT_FIXED set_f( hHQ_core->last_ni_gain, 0, BANDS_MAX ); set_f( hHQ_core->last_env, 0, BANDS_MAX ); +#else + set32_fx( hHQ_core->last_ni_gain_fx, 0, BANDS_MAX ); + set16_fx( hHQ_core->last_env_fx, 0, BANDS_MAX ); +#endif hHQ_core->last_max_pos_pulse = 0; hHQ_core->mode_count = 0; diff --git a/lib_enc/detect_transient.c b/lib_enc/detect_transient.c index 6ffa4173e..72068c54b 100644 --- a/lib_enc/detect_transient.c +++ b/lib_enc/detect_transient.c @@ -41,6 +41,7 @@ #include "rom_com.h" #include "wmc_auto.h" +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------------- * hp_filter() * @@ -259,3 +260,4 @@ int16_t detect_transient( return IsTransient; } +#endif diff --git a/lib_enc/dtx.c b/lib_enc/dtx.c index f47d87bd1..a466e10a9 100644 --- a/lib_enc/dtx.c +++ b/lib_enc/dtx.c @@ -62,6 +62,7 @@ #define MAX_BRATE_DTX_EVS ACELP_24k40 /* maximum bitrate to which the default DTX is applied in EVS; otherwise DTX is applied only in silence */ #define MAX_BRATE_DTX_IVAS IVAS_80k /* maximum bitrate to which the default DTX is applied in IVAS; otherwise DTX is applied only in silence */ +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * Local function prototypes *-------------------------------------------------------------------*/ @@ -540,6 +541,7 @@ static void update_SID_cnt( return; } +#endif /*-------------------------------------------------------------------* @@ -914,10 +916,17 @@ void dtx_enc_init( mvr2r( st->lsp_old1, hDtxEnc->lspCNG, M ); hDtxEnc->VarDTX_cnt_voiced = 0; hDtxEnc->VarDTX_cnt_noise = 0; +#ifndef IVAS_FLOAT_FIXED hDtxEnc->lt_ener_voiced = 0.0f; hDtxEnc->lt_ener_noise = 0.0f; hDtxEnc->frame_ener = 0.0f; hDtxEnc->lt_ener_last_SID = 0.0f; +#else + hDtxEnc->lt_ener_voiced_fx = 0; + hDtxEnc->lt_ener_noise_fx = 0; + hDtxEnc->frame_ener_fx = 0; + hDtxEnc->lt_ener_last_SID_fx = 0; +#endif hDtxEnc->last_CNG_L_frame = L_FRAME; hDtxEnc->var_SID_rate_flag = var_SID_rate_flag; hDtxEnc->last_active_brate = ACELP_7k20; diff --git a/lib_enc/dtx_fx.c b/lib_enc/dtx_fx.c index d0ebfddf3..843b37318 100644 --- a/lib_enc/dtx_fx.c +++ b/lib_enc/dtx_fx.c @@ -1203,7 +1203,7 @@ static void update_SID_cnt( ELSE { /* If SID frame was sent, update long-term energy */ - hDtxEnc->lt_ener_last_SID_fx = hDtxEnc->lt_ener_noise_fx; + hDtxEnc->lt_ener_last_SID_fx = hDtxEnc->lt_ener_noise_fx; /* Q(-7) */ move32(); } hDtxEnc->cnt_SID = add( hDtxEnc->cnt_SID, 1 ); diff --git a/lib_enc/enc_amr_wb.c b/lib_enc/enc_amr_wb.c index cff2930b1..eae23b150 100644 --- a/lib_enc/enc_amr_wb.c +++ b/lib_enc/enc_amr_wb.c @@ -41,6 +41,7 @@ #include "rom_com.h" #include "wmc_auto.h" +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * encod_amr_wb() * @@ -236,3 +237,4 @@ void encod_amr_wb( return; } +#endif diff --git a/lib_enc/enc_gen_voic_rf.c b/lib_enc/enc_gen_voic_rf.c index 7c38a433d..ed0867eb2 100644 --- a/lib_enc/enc_gen_voic_rf.c +++ b/lib_enc/enc_gen_voic_rf.c @@ -107,6 +107,7 @@ void reset_rf_indices( } +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * coder_acelp_rf() * @@ -397,3 +398,4 @@ void coder_acelp_rf( return; } +#endif diff --git a/lib_enc/enc_nelp.c b/lib_enc/enc_nelp.c index f151bc085..8dcf7e032 100644 --- a/lib_enc/enc_nelp.c +++ b/lib_enc/enc_nelp.c @@ -41,6 +41,7 @@ #include "prot.h" #include "wmc_auto.h" +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * encod_nelp() * @@ -146,3 +147,4 @@ void encod_nelp( return; } +#endif diff --git a/lib_enc/gain_enc.c b/lib_enc/gain_enc.c index d0e1d8c7a..02113735a 100644 --- a/lib_enc/gain_enc.c +++ b/lib_enc/gain_enc.c @@ -158,6 +158,7 @@ void Es_pred_enc( } +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * gain_enc_amr_wb() * @@ -296,6 +297,7 @@ void gain_enc_amr_wb( return; } +#endif /*---------------------------------------------------------------------* * gain_enc_mless() diff --git a/lib_enc/hq_core_enc.c b/lib_enc/hq_core_enc.c index b2e599e1d..317f59eae 100644 --- a/lib_enc/hq_core_enc.c +++ b/lib_enc/hq_core_enc.c @@ -676,11 +676,20 @@ void HQ_core_enc_init( set_s( hHQ_core->prev_frm_index, -1, NB_SWB_SUBBANDS_HAR_SEARCH_SB ); hHQ_core->prev_frm_hfe2 = 0; hHQ_core->prev_stab_hfe2 = 0; +#ifndef IVAS_FLOAT_FIXED hHQ_core->prev_ni_ratio = 0.5f; +#else + hHQ_core->prev_ni_ratio_fx = 16384; +#endif set_f( hHQ_core->prev_En_sb, 0.0f, NB_SWB_SUBBANDS ); set_s( hHQ_core->last_bitalloc_max_band, 0, 2 ); +#ifndef IVAS_FLOAT_FIXED set_f( hHQ_core->last_ni_gain, 0, BANDS_MAX ); set_f( hHQ_core->last_env, 0, BANDS_MAX ); +#else + set32_fx( hHQ_core->last_ni_gain_fx, 0, BANDS_MAX ); + set16_fx( hHQ_core->last_env_fx, 0, BANDS_MAX ); +#endif #ifdef IVAS_FLOAT_FIXED set32_fx( hHQ_core->last_ni_gain_fx, 0, BANDS_MAX ); diff --git a/lib_enc/hq_lr_enc.c b/lib_enc/hq_lr_enc.c index b34224223..8e860af39 100644 --- a/lib_enc/hq_lr_enc.c +++ b/lib_enc/hq_lr_enc.c @@ -46,6 +46,7 @@ #include "wmc_auto.h" +#ifndef IVAS_FLOAT_FIXED /*--------------------------------------------------------------------------* * Local function prototypes *--------------------------------------------------------------------------*/ @@ -1770,3 +1771,4 @@ static void mdct_spectrum_fine_gain_enc( return; } +#endif diff --git a/lib_enc/init_enc.c b/lib_enc/init_enc.c index 30b05f580..0e63098c6 100644 --- a/lib_enc/init_enc.c +++ b/lib_enc/init_enc.c @@ -155,7 +155,13 @@ ivas_error init_encoder( set_f( st->mem_MA, 0, M ); init_gp_clip( st->clip_var ); - pitch_ol_init( &st->old_thres, &st->old_pitch, &st->delta_pit, &st->old_corr ); + pitch_ol_init( +#ifndef IVAS_FLOAT_FIXED + &st->old_thres, +#else + &st->old_thres_fx, +#endif + &st->old_pitch, &st->delta_pit, &st->old_corr ); set_f( st->old_wsp, 0, L_WSP_MEM ); #ifdef IVAS_FLOAT_FIXED set16_fx( st->old_wsp_fx, 0, L_WSP_MEM ); @@ -530,8 +536,9 @@ ivas_error init_encoder( st->flag_noisy_speech_snr = 0; st->fd_cng_reset_flag = 0; st->cng_type = -1; +#ifndef IVAS_FLOAT_FIXED st->bckr_tilt_lt_flt = 0.f; -#ifdef IVAS_FLOAT_FIXED +#else st->bckr_tilt_lt = 0; #endif st->active_cnt = 0; @@ -660,7 +667,11 @@ ivas_error init_encoder( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for AMR-WB IO\n" ) ); } +#ifndef IVAS_FLOAT_FIXED amr_wb_enc_init( st->hAmrwb_IO ); +#else + amr_wb_enc_init_fx( st->hAmrwb_IO ); +#endif } else { @@ -774,10 +785,18 @@ ivas_error init_encoder( } /* init memory for detect_transient(), used by HQ core and swb_bwe_enc */ +#ifndef IVAS_FLOAT_FIXED st->old_hpfilt_in = 0.0f; st->old_hpfilt_out = 0.0f; st->EnergyLT = 0.0f; st->Energy_Old = 0; +#else + st->old_hpfilt_in_fx = 0; + st->old_hpfilt_out_fx = 0; + st->EnergyLT_fx = 0; + st->Energy_Old_fx = 0; + st->EnergyLT_fx_exp = 30; +#endif st->TransientHangOver = 0; #ifdef IVAS_FLOAT_FIXED st->last_enerBuffer_exp = 0; @@ -957,12 +976,12 @@ ivas_error init_encoder( } /* Init Mode 2 core coder */ + +#ifndef IVAS_FLOAT_FIXED st->last_totalNoise = 0.f; -#ifdef IVAS_FLOAT_FIXED - st->last_totalNoise_fx = 0; -#endif set_f( st->totalNoise_increase_hist, 0.f, TOTALNOISE_HIST_SIZE ); -#ifdef IVAS_FLOAT_FIXED +#else + st->last_totalNoise_fx = 0; set16_fx( st->totalNoise_increase_hist_fx, 0, TOTALNOISE_HIST_SIZE ); #endif st->totalNoise_increase_len = 0; @@ -1167,7 +1186,13 @@ ivas_error init_encoder_ivas_fx( init_gp_clip( st->clip_var ); set_zero( st->mem_MA, M ); st->streaklimit = 1.0f; - pitch_ol_init( &st->old_thres, &st->old_pitch, &st->delta_pit, &st->old_corr ); + pitch_ol_init( +#ifndef IVAS_FLOAT_FIXED + &st->old_thres, +#else + &st->old_thres_fx, +#endif + &st->old_pitch, &st->delta_pit, &st->old_corr ); #endif st->next_force_safety_net = 0; @@ -1239,15 +1264,14 @@ ivas_error init_encoder_ivas_fx( st->lt_mean_SWB = 0; st->lp_speech = 45.0f; /* Initialize the long-term active speech level in dB */ st->lp_noise = 0.0f; - st->bckr_tilt_lt_flt = 0.f; st->active_cnt = 0; st->currEnergyLookAhead = 6.1e-5f; +#ifndef IVAS_FLOAT_FIXED st->old_hpfilt_in = 0.0f; st->old_hpfilt_out = 0.0f; st->EnergyLT = 0.0f; st->Energy_Old = 0; - st->last_totalNoise = 0.f; - set_f( st->totalNoise_increase_hist, 0.f, TOTALNOISE_HIST_SIZE ); +#endif st->min_alpha = 1; #ifndef IVAS_FLOAT_FIXED st->prev_fmerit_flt = 0; @@ -1814,7 +1838,7 @@ ivas_error init_encoder_ivas_fx( } amr_wb_enc_init_fx( st->hAmrwb_IO ); -#if 1 +#ifndef IVAS_FLOAT_FIXED amr_wb_enc_init( st->hAmrwb_IO ); #endif } @@ -1958,6 +1982,8 @@ ivas_error init_encoder_ivas_fx( move32(); st->TransientHangOver = 0; move16(); + st->EnergyLT_fx_exp = 30; + move16(); st->last_enerBuffer_exp = 0; move16(); diff --git a/lib_enc/ivas_core_enc.c b/lib_enc/ivas_core_enc.c index ecf48f8d6..ee5bef140 100644 --- a/lib_enc/ivas_core_enc.c +++ b/lib_enc/ivas_core_enc.c @@ -871,7 +871,6 @@ ivas_error ivas_core_enc( if ( st->hBWE_TD != NULL ) { - st->hBWE_TD->prev_wb_GainShape = float_to_fix16( st->hBWE_TD->prev_wb_GainShape_flt, Q15 ); floatToFixed_arr16( st->hBWE_TD->decim_state1, st->hBWE_TD->decim_state1_fx, -1, 2 * ALLPASSSECTIONS_STEEP + 1 ); floatToFixed_arr16( st->hBWE_TD->decim_state2, st->hBWE_TD->decim_state2_fx, -1, 2 * ALLPASSSECTIONS_STEEP + 1 ); floatToFixed_arr16( st->hBWE_TD->old_speech_wb, st->hBWE_TD->old_speech_wb_fx, -1, ( L_LOOK_12k8 + L_SUBFR ) * 5 / 16 ); @@ -921,7 +920,6 @@ ivas_error ivas_core_enc( if ( st->hBWE_TD != NULL ) { - st->hBWE_TD->prev_wb_GainShape_flt = fix_to_float( st->hBWE_TD->prev_wb_GainShape, Q15 ); fixedToFloat_arr( st->hBWE_TD->decim_state1_fx, st->hBWE_TD->decim_state1, -1, 2 * ALLPASSSECTIONS_STEEP + 1 ); fixedToFloat_arr( st->hBWE_TD->decim_state2_fx, st->hBWE_TD->decim_state2, -1, 2 * ALLPASSSECTIONS_STEEP + 1 ); fixedToFloat_arr( st->hBWE_TD->old_speech_wb_fx, st->hBWE_TD->old_speech_wb, -1, ( L_LOOK_12k8 + L_SUBFR ) * 5 / 16 ); @@ -1030,7 +1028,6 @@ ivas_error ivas_core_enc( } fixedToFloat_arrL32( (Word32 *) &realBuffer_fx[0][0], (float *) &realBuffer[n][0][0], q_realImagBuffer, CLDFB_NO_COL_MAX * CLDFB_NO_CHANNELS_MAX ); fixedToFloat_arrL32( (Word32 *) &imagBuffer_fx[0][0], (float *) &imagBuffer[n][0][0], q_realImagBuffer, CLDFB_NO_COL_MAX * CLDFB_NO_CHANNELS_MAX ); - st->hBWE_TD->cldfbHBLT_flt = fix16_to_float( st->hBWE_TD->cldfbHBLT, Q13 ); if ( st->element_mode == IVAS_CPE_DFT ) { @@ -1108,24 +1105,12 @@ ivas_error ivas_core_enc( { floatToFixed_arr16( st->hBWE_TD->old_speech_shb, st->hBWE_TD->old_speech_shb_fx, Q_shb_spch, L_LOOK_16k + L_SUBFR16k ); floatToFixed_arr16( st->hBWE_TD->shb_inv_filt_mem, st->hBWE_TD->shb_inv_filt_mem_fx, Q_shb_spch, LPC_SHB_ORDER ); // Check - floatToFixed_arr16( st->hBWE_TD->prev_lsp_shb, st->hBWE_TD->prev_lsp_shb_fx, Q15, LPC_SHB_ORDER ); - floatToFixed_arr16( st->hBWE_TD->lsp_shb_spacing, st->hBWE_TD->lsp_shb_spacing_fx, Q15, 3 ); - floatToFixed_arr16( st->hBWE_TD->lsp_shb_slow_interpl, st->hBWE_TD->lsp_shb_slow_interpl_fx, Q15, LPC_SHB_ORDER ); - floatToFixed_arr16( st->hBWE_TD->lsp_shb_fast_interpl, st->hBWE_TD->lsp_shb_fast_interpl_fx, Q15, LPC_SHB_ORDER ); - floatToFixed_arr16( st->hBWE_TD->swb_lsp_prev_interp, st->hBWE_TD->swb_lsp_prev_interp_fx, Q15, LPC_SHB_ORDER ); - floatToFixed_arr16( st->hBWE_TD->prev_lsf_diff, st->hBWE_TD->prev_lsf_diff_fx, Q15, LPC_SHB_ORDER - 2 ); floatToFixed_arr16( st->hBWE_TD->cur_sub_Aq, st->hBWE_TD->cur_sub_Aq_fx, Q12, M + 1 ); - st->hBWE_TD->prev_tilt_para_fx = float_to_fix16( st->hBWE_TD->prev_tilt_para, Q10 ); st->hBWE_TD->prev_pow_exc16kWhtnd_fx32 = floatToFixed( st->hBWE_TD->prev_pow_exc16kWhtnd, 0 ); floatToFixed_arr16( st->hBWE_TD->state_lpc_syn, st->hBWE_TD->state_lpc_syn_fx, ( st->prev_Q_bwe_exc - 16 ), LPC_SHB_ORDER ); floatToFixed_arr32( st->hBWE_TD->mem_csfilt, st->hBWE_TD->mem_csfilt_fx, st->prev_Q_bwe_exc, 2 ); st->hBWE_TD->gain_prec_swb_fx = float_to_fix16( st->hBWE_TD->gain_prec_swb, Q14 ); - st->hBWE_TD->cldfbHBLT = float_to_fix16( st->hBWE_TD->cldfbHBLT_flt, Q13 ); - st->hBWE_TD->prev_mix_factor_fx = float_to_fix16( st->hBWE_TD->prev_mix_factor, Q15 ); - st->hBWE_TD->prev_gainFr_SHB_fx = floatToFixed( st->hBWE_TD->prev_gainFr_SHB, Q18 ); // Satruation conversion used. Need to look into this - st->hBWE_TD->old_mean_EnvSHBres_fx = float_to_fix16( st->hBWE_TD->old_mean_EnvSHBres, Q15 ); floatToFixed_arr16( st->hBWE_TD->mem_stp_swb, st->hBWE_TD->mem_stp_swb_fx, st->prev_Q_bwe_syn, LPC_SHB_ORDER ); - st->hBWE_TD->prev_swb_GainShape_fx = float_to_fix16( st->hBWE_TD->prev_swb_GainShape, Q15 ); floatToFixed_arr( &st->hBWE_TD->tbe_demph, &st->hBWE_TD->tbe_demph_fx, st->prev_Q_bwe_exc - 16 - NOISE_QADJ, 1 ); // Satruation conversion used as -ve Q not handled floatToFixed_arr( &st->hBWE_TD->tbe_premph, &st->hBWE_TD->tbe_premph_fx, st->prev_Q_bwe_exc - 16, 1 ); // Satruation conversion used as -ve Q not handled } @@ -1136,24 +1121,12 @@ ivas_error ivas_core_enc( { fixedToFloat_arr( st->hBWE_TD->old_speech_shb_fx, st->hBWE_TD->old_speech_shb, Q_shb_spch, L_LOOK_16k + L_SUBFR16k ); fixedToFloat_arr( st->hBWE_TD->shb_inv_filt_mem_fx, st->hBWE_TD->shb_inv_filt_mem, Q_shb_spch, LPC_SHB_ORDER ); // Check - fixedToFloat_arr( st->hBWE_TD->prev_lsp_shb_fx, st->hBWE_TD->prev_lsp_shb, Q15, LPC_SHB_ORDER ); - fixedToFloat_arr( st->hBWE_TD->lsp_shb_spacing_fx, st->hBWE_TD->lsp_shb_spacing, Q15, 3 ); - fixedToFloat_arr( st->hBWE_TD->lsp_shb_slow_interpl_fx, st->hBWE_TD->lsp_shb_slow_interpl, Q15, LPC_SHB_ORDER ); - fixedToFloat_arr( st->hBWE_TD->lsp_shb_fast_interpl_fx, st->hBWE_TD->lsp_shb_fast_interpl, Q15, LPC_SHB_ORDER ); - fixedToFloat_arr( st->hBWE_TD->swb_lsp_prev_interp_fx, st->hBWE_TD->swb_lsp_prev_interp, Q15, LPC_SHB_ORDER ); - fixedToFloat_arr( st->hBWE_TD->prev_lsf_diff_fx, st->hBWE_TD->prev_lsf_diff, Q15, LPC_SHB_ORDER - 2 ); fixedToFloat_arr( st->hBWE_TD->cur_sub_Aq_fx, st->hBWE_TD->cur_sub_Aq, Q12, M + 1 ); - st->hBWE_TD->prev_tilt_para = fixedToFloat( st->hBWE_TD->prev_tilt_para_fx, Q10 ); st->hBWE_TD->prev_pow_exc16kWhtnd = fixedToFloat( st->hBWE_TD->prev_pow_exc16kWhtnd_fx32, 0 ); fixedToFloat_arr( st->hBWE_TD->state_lpc_syn_fx, st->hBWE_TD->state_lpc_syn, ( st->prev_Q_bwe_exc - 16 ), LPC_SHB_ORDER ); fixedToFloat_arrL( st->hBWE_TD->mem_csfilt_fx, st->hBWE_TD->mem_csfilt, st->prev_Q_bwe_exc, 2 ); st->hBWE_TD->gain_prec_swb = fixedToFloat( st->hBWE_TD->gain_prec_swb_fx, Q14 ); - st->hBWE_TD->cldfbHBLT_flt = fixedToFloat( st->hBWE_TD->cldfbHBLT, Q13 ); - st->hBWE_TD->prev_mix_factor = fixedToFloat( st->hBWE_TD->prev_mix_factor_fx, Q15 ); - st->hBWE_TD->prev_gainFr_SHB = fixedToFloat( st->hBWE_TD->prev_gainFr_SHB_fx, Q18 ); - st->hBWE_TD->old_mean_EnvSHBres = fixedToFloat( st->hBWE_TD->old_mean_EnvSHBres_fx, Q15 ); fixedToFloat_arr( st->hBWE_TD->mem_stp_swb_fx, st->hBWE_TD->mem_stp_swb, st->prev_Q_bwe_syn, LPC_SHB_ORDER ); - st->hBWE_TD->prev_swb_GainShape = fixedToFloat( st->hBWE_TD->prev_swb_GainShape_fx, Q15 ); st->hBWE_TD->tbe_demph = fixedToFloat( st->hBWE_TD->tbe_demph_fx, st->prev_Q_bwe_exc - 16 - NOISE_QADJ ); st->hBWE_TD->tbe_premph = fixedToFloat( st->hBWE_TD->tbe_premph_fx, st->prev_Q_bwe_exc - 16 ); } @@ -1254,7 +1227,6 @@ ivas_error ivas_core_enc( { st->hBWE_FD->old_input[ii] = (float) st->hBWE_FD->old_input_fx[ii]; } - st->EnergyLT = fixedToFloat( st->EnergyLT_fx, st->EnergyLT_fx_exp ); #endif #else /* SWB(FB) BWE encoder */ @@ -1311,7 +1283,6 @@ ivas_error ivas_core_enc( hCPE->hStereoICBWE->dataChan_fx[0] = inp0_fx; hCPE->hStereoICBWE->dataChan_fx[1] = inp1_fx; - hCPE->hStereoTCA->targetGain_fx = floatToFixed( hCPE->hStereoTCA->targetGain, Q29 ); Word16 scale_factor = Q_factor_arr( hCPE->hStereoICBWE->dataChan[0], input_frame ); scale_factor = min( scale_factor, Q_factor_arr( hCPE->hStereoICBWE->dataChan[1], input_frame ) ); diff --git a/lib_enc/ivas_core_pre_proc_front.c b/lib_enc/ivas_core_pre_proc_front.c index d661fe7bc..00bfb0953 100644 --- a/lib_enc/ivas_core_pre_proc_front.c +++ b/lib_enc/ivas_core_pre_proc_front.c @@ -1832,20 +1832,10 @@ ivas_error pre_proc_front_ivas_fx( if ( st->hFdCngEnc != NULL ) { #ifdef IVAS_FLOAT_FIXED - -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - st->last_totalNoise_fx = float_to_fix16( st->last_totalNoise, Q8 ); - FOR( Word16 j = 0; j < TOTALNOISE_HIST_SIZE; j++ ) - { - st->totalNoise_increase_hist_fx[j] = float_to_fix16( st->totalNoise_increase_hist[j], Q8 ); - move16(); - } -#endif resetFdCngEnc_fx( st ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS Word16 totalNoiseIncrease_fx = st->hNoiseEst->totalNoise_fx - st->last_totalNoise_fx; - st->last_totalNoise = fix16_to_float( st->last_totalNoise_fx, Q8 ); IF( ( totalNoiseIncrease_fx > 5 * 256 && st->totalNoise_increase_len == TOTALNOISE_HIST_SIZE && st->ini_frame > 150 ) || ( st->input_bwidth > st->last_input_bwidth ) || @@ -1854,23 +1844,6 @@ ivas_error pre_proc_front_ivas_fx( st->hFdCngEnc->hFdCngCom->init_old_flt = fix16_to_float( st->hFdCngEnc->hFdCngCom->init_old, Q15 ); move16(); } - - IF( totalNoiseIncrease_fx > 0 ) - { - IF( EQ_16( st->totalNoise_increase_len, TOTALNOISE_HIST_SIZE ) ) - { - FOR( Word16 ind = 0; i < TOTALNOISE_HIST_SIZE; ind++ ) - { - st->totalNoise_increase_hist[ind] = fix16_to_float( st->totalNoise_increase_hist_fx[ind + 1], Q8 ); - move16(); - } - } - ELSE - { - st->totalNoise_increase_hist[st->totalNoise_increase_len] = fix16_to_float( st->totalNoise_increase_hist_fx[st->totalNoise_increase_len], Q8 ); - move16(); - } - } #endif #else resetFdCngEnc( st ); @@ -1984,12 +1957,6 @@ ivas_error pre_proc_front_ivas_fx( st->lp_noise_fx = float_to_fix16( st->lp_noise, Q8 ); #endif dtx_ivas_fx( st, ivas_total_brate, *vad_flag_dtx, inp_12k8_fx, Q_inp_12k8 ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - IF( st->Opt_DTX_ON ) - { - st->hDtxEnc->frame_ener = fixedToFloat( st->hDtxEnc->frame_ener_fx, -7 ); - } -#endif #endif if ( hCPE != NULL && hCPE->hStereoDft != NULL && st->core_brate == SID_2k40 ) { @@ -2227,8 +2194,7 @@ ivas_error pre_proc_front_ivas_fx( IF( EQ_16( st->vad_flag, 0 ) ) { - st->old_thres = (float) ( st->old_thres_fx ); // no Q-factor used here since it's initialised to 0. - st->old_corr = (float) ( st->old_corr_fx ); // no Q-factor used here since it's initialised to 0. + st->old_corr = (float) ( st->old_corr_fx ); // no Q-factor used here since it's initialised to 0. } #endif @@ -2252,7 +2218,6 @@ ivas_error pre_proc_front_ivas_fx( floatToFixed_arr( st->old_wsp, st->old_wsp_fx, Q_factor_arr( st->old_wsp, L_WSP_MEM ), L_WSP_MEM ); Copy( st->old_wsp_fx, old_wsp_fx, L_WSP_MEM ); wsp_fx = old_wsp_fx + L_WSP_MEM; - st->old_thres_fx = (Word16) floatToFixed( st->old_thres, Q15 ); st->old_corr_fx = (Word16) floatToFixed( st->old_corr, Q15 ); floatToFixed_arr( st->voicing, st->voicing_fx, Q15, 3 ); corr_shift_fx = (Word16) floatToFixed( corr_shift, Q15 ); @@ -2269,7 +2234,6 @@ ivas_error pre_proc_front_ivas_fx( &st->delta_pit, st->old_wsp2_fx, wsp_fx, st->mem_decim2_fx, relE_fx, st->clas, st->input_bwidth, st->Opt_SC_VBR ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - st->old_thres = fixedToFloat( st->old_thres_fx, Q15 ); st->old_corr = fixedToFloat( st->old_corr_fx, Q15 ); fixedToFloat_arr( st->voicing_fx, st->voicing, Q15, 3 ); corr_shift = fixedToFloat( corr_shift_fx, Q15 ); @@ -2303,15 +2267,6 @@ ivas_error pre_proc_front_ivas_fx( corr_shiftL_fx = float_to_fix16( corr_shiftL, Q15 ); corr_shiftR_fx = float_to_fix16( corr_shiftR, Q15 ); - if ( (Word32) st->bckr_tilt_lt_flt == 32768 ) - { - st->bckr_tilt_lt = MAX_32; // Q16 - } - else - { - st->bckr_tilt_lt = float_to_fix( st->bckr_tilt_lt_flt, Q16 ); - } - Word16 q_fr_bands = Q30; q_fr_bands = min( q_fr_bands, Q_factor_arrL( tmpN, NB_BANDS ) ); q_fr_bands = min( q_fr_bands, Q_factor_arrL( tmpE, NB_BANDS ) ); @@ -2403,10 +2358,6 @@ ivas_error pre_proc_front_ivas_fx( } } - if ( st->hSC_VBR != NULL ) - { - st->hSC_VBR->vadnoise_fx = float_to_fix16( st->hSC_VBR->vadnoise, Q8 ); - } st->lp_noise_fx = float_to_fix16( st->lp_noise, Q8 ); st->hNoiseEst->Etot_last_fx = float_to_fix16( st->hNoiseEst->Etot_last, Q8 ); @@ -2498,7 +2449,6 @@ ivas_error pre_proc_front_ivas_fx( fixedToFloat_arrL32( ee_fx, ee, Q6, 2 ); fixedToFloat_arrL32( hp_E_fx, hp_E, q_fr_bands, 2 ); - st->bckr_tilt_lt_flt = fixedToFloat_32( st->bckr_tilt_lt, Q16 ); fixedToFloat_arrL32( st->old_enr_ssf_fx, st->old_enr_ssf, 0, 2 * NB_SSF ); @@ -2920,7 +2870,6 @@ ivas_error pre_proc_front_ivas_fx( { res_cod_SNR_M[i] = me2f( res_cod_SNR_M_fx[i], res_cod_SNR_M_fx_e[i] ); } - st->prevTempFlatness = fix16_to_float( st->prevTempFlatness_fx, Q7 ); #endif #else smc_dec = ivas_acelp_tcx20_switching( st, st->speech_enc_flt, st->wspeech_enc_flt, non_staX, pitch_fr, voicing_fr, currFlatness, lsp_mid, stab_fac, res_cod_SNR_M, flag_16k_smc ); @@ -2949,7 +2898,6 @@ ivas_error pre_proc_front_ivas_fx( #endif smc_dec = ivas_acelp_tcx20_switching_fx( st, inp_12k8_fx, Q_new, wsp_fx_l, non_staX16_fx, pitch_fr_fx, voicing_fr_fx, currFlatness_fx, lsp_mid_fx_1, stab_fac_fx, res_cod_SNR_M_fx, res_cod_SNR_M_fx_e, tcx_mdct_window_fx, flag_16k_smc ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - st->prevTempFlatness = fix16_to_float( st->prevTempFlatness_fx, Q7 ); // st->prevTempFlatness = currFlatness; for ( i = 0; i < 7; i++ ) { diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index bdf6f5f24..c48f9bf7f 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -243,14 +243,6 @@ ivas_error ivas_cpe_enc( Q_buffer[n] = 15; move16(); } - if ( sts[0]->hFdCngEnc != NULL ) - { - sts[0]->last_totalNoise_fx = (Word16) float_to_fix16( sts[0]->last_totalNoise, Q8 ); - for ( int i = 0; i < TOTALNOISE_HIST_SIZE - 1; i++ ) - { - sts[0]->totalNoise_increase_hist_fx[n] = (Word16) float_to_fix16( sts[0]->totalNoise_increase_hist[n], Q8 ); - } - } if ( hCPE->hFrontVad[0] != NULL && hCPE->element_mode != IVAS_CPE_MDCT ) { Word16 Qband = -1; @@ -284,11 +276,6 @@ ivas_error ivas_cpe_enc( #ifdef IVAS_FLOAT_FIXED_CONVERSIONS if ( sts[0]->hFdCngEnc != NULL ) { - sts[0]->last_totalNoise = fix16_to_float( sts[0]->last_totalNoise_fx, Q8 ); - for ( int i = 0; i < TOTALNOISE_HIST_SIZE - 1; i++ ) - { - sts[0]->totalNoise_increase_hist[n] = fix16_to_float( sts[0]->totalNoise_increase_hist_fx[n], Q8 ); - } sts[0]->hFdCngEnc->hFdCngCom->init_old_flt = ( sts[0]->hFdCngEnc->hFdCngCom->init_old == 32767 ) ? FLT_MAX : sts[0]->hFdCngEnc->hFdCngCom->init_old_flt; } if ( hCPE->hFrontVad[0] != NULL && hCPE->element_mode != IVAS_CPE_MDCT ) @@ -419,9 +406,36 @@ ivas_error ivas_cpe_enc( /*----------------------------------------------------------------* * Temporal inter-channel alignment, stereo adjustment *----------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + Word16 q_com = L_get_q_buf1( sts[0]->input_buff, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ); + q_com = min( q_com, L_get_q_buf1( sts[1]->input_buff, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ) ) - 10; - stereo_tca_enc( hCPE, input_frame ); + floatToFixed_arrL32( sts[0]->input_buff, sts[0]->input_buff32_fx, q_com, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ); + floatToFixed_arrL32( sts[1]->input_buff, sts[1]->input_buff32_fx, q_com, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ); + sts[0]->q_inp32 = sts[1]->q_inp32 = q_com; +#endif + + stereo_tca_enc_fx( hCPE, input_frame ); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + fixedToFloat_arrL32( sts[0]->input_buff32_fx, sts[0]->input_buff, sts[0]->q_inp32, 1965 ); + fixedToFloat_arrL32( sts[1]->input_buff32_fx, sts[1]->input_buff, sts[1]->q_inp32, 1965 ); + if ( EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) || NE_16( hCPE->element_mode, IVAS_CPE_TD ) ) + { + } + else + { + if ( hCPE->hStereoICBWE != NULL ) + { + fixedToFloat_arr( hCPE->hStereoICBWE->icbwe_inp_mem_fx[0], hCPE->hStereoICBWE->icbwe_inp_mem[0], hCPE->hStereoICBWE->q_dataChan_fx, NS2SA( input_Fs, L_MEM_RECALC_TBE_NS ) ); + fixedToFloat_arr( hCPE->hStereoICBWE->icbwe_inp_mem_fx[1], hCPE->hStereoICBWE->icbwe_inp_mem[1], hCPE->hStereoICBWE->q_dataChan_fx, NS2SA( input_Fs, L_MEM_RECALC_TBE_NS ) ); + } + } +#endif +#else + stereo_tca_enc( hCPE, input_frame ); +#endif /*----------------------------------------------------------------* * Input signal buffering - needed in IC-BWE and TD ITD in MDCT stereo *----------------------------------------------------------------*/ @@ -1156,7 +1170,6 @@ ivas_error ivas_cpe_enc( floatToFixed_arr( hCPE->hCoreCoder[0]->voicing, hCPE->hCoreCoder[0]->voicing_fx, Q15, 3 ); floatToFixed_arr( hCPE->hCoreCoder[1]->voicing, hCPE->hCoreCoder[1]->voicing_fx, Q15, 3 ); hCPE->hCoreCoder[0]->old_corr_fx = float_to_fix16( hCPE->hCoreCoder[0]->old_corr, Q15 ); - hCPE->hCoreCoder[0]->old_thres_fx = float_to_fix16( hCPE->hCoreCoder[0]->old_thres, Q15 ); #endif tdm_ol_pitch_comparison_fx( hCPE, pitch_fr_fx, voicing_fr_fx ); @@ -1169,7 +1182,6 @@ ivas_error ivas_cpe_enc( fixedToFloat_arr( hCPE->hCoreCoder[0]->voicing_fx, hCPE->hCoreCoder[0]->voicing, Q15, 3 ); fixedToFloat_arr( hCPE->hCoreCoder[1]->voicing_fx, hCPE->hCoreCoder[1]->voicing, Q15, 3 ); hCPE->hCoreCoder[1]->old_corr = fix16_to_float( hCPE->hCoreCoder[1]->old_corr_fx, Q15 ); - hCPE->hCoreCoder[1]->old_thres = fix16_to_float( hCPE->hCoreCoder[1]->old_thres_fx, Q15 ); #endif #else tdm_ol_pitch_comparison( hCPE, pitch_fr, voicing_fr ); @@ -2424,7 +2436,7 @@ ivas_error create_cpe_enc( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo TCA\n" ) ); } - stereo_tca_init_enc( hCPE->hStereoTCA, input_Fs ); + stereo_tca_init_enc_fx( hCPE->hStereoTCA, input_Fs ); } /*-----------------------------------------------------------------* diff --git a/lib_enc/ivas_dirac_enc.c b/lib_enc/ivas_dirac_enc.c index 4e79d4e2d..c68d585bb 100644 --- a/lib_enc/ivas_dirac_enc.c +++ b/lib_enc/ivas_dirac_enc.c @@ -498,7 +498,7 @@ ivas_error ivas_dirac_enc( } } #endif - if ( ( error = ivas_qmetadata_enc_encode( hMetaData, hQMetaData, hodirac_flag ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_qmetadata_enc_encode_fx( hMetaData, hQMetaData, hodirac_flag ) ) != IVAS_ERR_OK ) { return error; } @@ -1001,23 +1001,185 @@ void computeReferencePower_enc_fx( void ivas_dirac_param_est_enc( DIRAC_ENC_HANDLE hDirAC, IVAS_QDIRECTION *q_direction, - const uint8_t useLowerRes, + const UWord8 useLowerRes, float *data_f[], float **pp_fr_real, float **pp_fr_imag, - const int16_t input_frame, + const Word16 input_frame, const IVAS_FORMAT ivas_format, - const int16_t hodirac_flag, - const int16_t nchan_fb_in, - int16_t *mono_frame_count, - int16_t *dirac_mono_flag ) + const Word16 hodirac_flag, + const Word16 nchan_fb_in, + Word16 *mono_frame_count, + Word16 *dirac_mono_flag ) { - int16_t i, d, ts, index, l_ts, num_freq_bands; - int16_t band_m_idx, block_m_idx; +#ifdef IVAS_FLOAT_FIXED + Word32 *data_f_fx[DIRAC_MAX_ANA_CHANS]; + Word32 **pp_fr_real_fx; + Word32 **pp_fr_imag_fx; +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + /* Assign memory */ + Word16 nblocks = useLowerRes ? 1 : MAX_PARAM_SPATIAL_SUBFRAMES; + hDirAC->direction_vector_m_fx[0] = (Word32 **) malloc( nblocks * sizeof( Word32 * ) ); + hDirAC->direction_vector_m_fx[1] = (Word32 **) malloc( nblocks * sizeof( Word32 * ) ); + hDirAC->direction_vector_m_fx[2] = (Word32 **) malloc( nblocks * sizeof( Word32 * ) ); + for ( int block_m_idx = 0; block_m_idx < nblocks; block_m_idx++ ) + { + hDirAC->direction_vector_m_fx[0][block_m_idx] = (Word32 *) malloc( hDirAC->hConfig->nbands * sizeof( Word32 ) ); + hDirAC->direction_vector_m_fx[1][block_m_idx] = (Word32 *) malloc( hDirAC->hConfig->nbands * sizeof( Word32 ) ); + hDirAC->direction_vector_m_fx[2][block_m_idx] = (Word32 *) malloc( hDirAC->hConfig->nbands * sizeof( Word32 ) ); + } + + /* Find Q-factor */ + Word16 pcm_q; + Word16 pp_fr_q; + float max_val = 0; + for ( int i = 0; i < nchan_fb_in; i++ ) + { + for ( int j = 0; j < input_frame; j++ ) + { + max_val = max( max_val, (float) fabs( data_f[i][j] ) ); + } + } + pcm_q = Q_factor_L( max_val ); + + max_val = 0; + for ( int i = 0; i < nchan_fb_in; i++ ) + { + for ( int j = 0; j < input_frame; j++ ) + { + max_val = max( max_val, (float) fabs( pp_fr_real[i][j] ) ); + max_val = max( max_val, (float) fabs( pp_fr_imag[i][j] ) ); + } + } + pp_fr_q = Q_factor_L( max_val ); + + /* Float to fixed */ + pp_fr_real_fx = (Word32 **) calloc( nchan_fb_in, sizeof( Word32 * ) ); + pp_fr_imag_fx = (Word32 **) calloc( nchan_fb_in, sizeof( Word32 * ) ); + for ( int i = 0; i < nchan_fb_in; i++ ) + { + data_f_fx[i] = (Word32 *) calloc( input_frame, sizeof( Word32 ) ); + pp_fr_real_fx[i] = (Word32 *) calloc( input_frame, sizeof( Word32 ) ); + pp_fr_imag_fx[i] = (Word32 *) calloc( input_frame, sizeof( Word32 ) ); + for ( int j = 0; j < input_frame; j++ ) + { + data_f_fx[i][j] = float_to_fix( data_f[i][j], pcm_q ); + pp_fr_real_fx[i][j] = float_to_fix( pp_fr_real[i][j], pp_fr_q ); + pp_fr_imag_fx[i][j] = float_to_fix( pp_fr_imag[i][j], pp_fr_q ); + } + } +#endif + + Word16 i, d, ts, index, l_ts, num_freq_bands; + Word16 band_m_idx, block_m_idx; float dir_v[DIRAC_NUM_DIMS]; #ifdef IVAS_FLOAT_FIXED_ Word32 dir_v_fx[DIRAC_NUM_DIMS]; #endif + float *pcm_in[DIRAC_MAX_ANA_CHANS]; + float Cldfb_RealBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX]; + float Cldfb_ImagBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX]; + float *p_Cldfb_RealBuffer[DIRAC_MAX_ANA_CHANS]; + float *p_Cldfb_ImagBuffer[DIRAC_MAX_ANA_CHANS]; + Word32 *pcm_in_fx[DIRAC_MAX_ANA_CHANS]; + Word32 Cldfb_RealBuffer_fx[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX]; + Word32 Cldfb_ImagBuffer_fx[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX]; + Word32 *p_Cldfb_RealBuffer_fx[DIRAC_MAX_ANA_CHANS]; + Word32 *p_Cldfb_ImagBuffer_fx[DIRAC_MAX_ANA_CHANS]; + Word16 cldfb_q; + float intensity_real[DIRAC_NUM_DIMS][DIRAC_MAX_NBANDS]; + float direction_vector[DIRAC_NUM_DIMS][DIRAC_MAX_NBANDS]; + float diffuseness_vector[DIRAC_MAX_NBANDS]; + float renormalization_factor[DIRAC_MAX_NBANDS]; + float renormalization_factor_diff[DIRAC_MAX_NBANDS]; + Word32 renormalization_factor_fx[DIRAC_MAX_NBANDS]; + Word32 renormalization_factor_diff_fx[DIRAC_MAX_NBANDS]; + float norm_tmp; + Word16 mrange[2]; + Word16 num_blocks; + float reference_power[CLDFB_NO_COL_MAX][DIRAC_NO_FB_BANDS_MAX]; + Word32 reference_power_fx[CLDFB_NO_COL_MAX][DIRAC_NO_FB_BANDS_MAX]; + Word16 reference_power_exp; + float azi_secs[2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS]; + float ele_secs[2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS]; + float diff_secs[2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS]; + float ene_secs[2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS]; + 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]; + Word32 ene_secs_fx[2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS]; + + push_wmops( "dirac_enc_param_est" ); + num_freq_bands = hDirAC->hConfig->nbands; + move16(); + + /* Initialization */ + l_ts = idiv1616( input_frame, MAX_PARAM_SPATIAL_SUBFRAMES ); + IF( useLowerRes ) + { + q_direction->cfg.nblocks = 1; + move16(); + num_blocks = 1; + move16(); + } + ELSE + { + q_direction->cfg.nblocks = MAX_PARAM_SPATIAL_SUBFRAMES; + move16(); + num_blocks = MAX_PARAM_SPATIAL_SUBFRAMES; + move16(); + } + + /* Need to initialize renormalization_factors, direction_m and diffuseness_m */ + set_zero_fx( hDirAC->diffuseness_m_fx, hDirAC->hConfig->nbands ); + set_zero_fx( renormalization_factor_diff_fx, hDirAC->hConfig->nbands ); + + 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 ); + set_zero_fx( ene_secs_fx, 2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS ); + + /* Copy current frame to memory for delay compensation */ +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + /* assign memory */ + for ( i = 0; i < nchan_fb_in; i++ ) + { + pcm_in[i] = data_f[i]; + p_Cldfb_RealBuffer[i] = &Cldfb_RealBuffer[i][0]; + p_Cldfb_ImagBuffer[i] = &Cldfb_ImagBuffer[i][0]; + } +#endif + FOR( i = 0; i < nchan_fb_in; i++ ) + { + pcm_in_fx[i] = data_f_fx[i]; + p_Cldfb_RealBuffer_fx[i] = &Cldfb_RealBuffer_fx[i][0]; + p_Cldfb_ImagBuffer_fx[i] = &Cldfb_ImagBuffer_fx[i][0]; + } +#if 1 + /* using void temporarily to avoid null */ + (void) p_Cldfb_RealBuffer_fx; + (void) p_Cldfb_ImagBuffer_fx; + (void) p_Cldfb_RealBuffer; + (void) p_Cldfb_ImagBuffer; + (void) pcm_in_fx; + (void) pcm_in; +#endif + +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + /* Fixed to float */ + fixedToFloat_arrL( azi_secs_fx, azi_secs, 0, 2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS ); + fixedToFloat_arrL( ele_secs_fx, ele_secs, 0, 2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS ); + fixedToFloat_arrL( diff_secs_fx, diff_secs, 0, 2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS ); + fixedToFloat_arrL( ene_secs_fx, ene_secs, 0, 2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS ); + + fixedToFloat_arrL( hDirAC->diffuseness_m_fx, hDirAC->diffuseness_m, 0, hDirAC->hConfig->nbands ); + fixedToFloat_arrL( renormalization_factor_diff_fx, renormalization_factor_diff, 0, hDirAC->hConfig->nbands ); +#endif + +#else + int16_t i, d, ts, index, l_ts, num_freq_bands; + int16_t band_m_idx, block_m_idx; + float dir_v[DIRAC_NUM_DIMS]; float *pcm_in[DIRAC_MAX_ANA_CHANS]; float Cldfb_RealBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX]; float Cldfb_ImagBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX]; @@ -1072,10 +1234,30 @@ void ivas_dirac_param_est_enc( p_Cldfb_RealBuffer[i] = &Cldfb_RealBuffer[i][0]; p_Cldfb_ImagBuffer[i] = &Cldfb_ImagBuffer[i][0]; } +#endif /* ifdef IVAS_FLOAT_FIXED */ /* do processing over all CLDFB time slots */ for ( block_m_idx = 0; block_m_idx < num_blocks; block_m_idx++ ) { +#ifdef IVAS_FLOAT_FIXED + mrange[0] = hDirAC->block_grouping[block_m_idx]; + move16(); + mrange[1] = hDirAC->block_grouping[add( block_m_idx, 1 )]; + move16(); + + set32_fx( renormalization_factor_fx, EPSILON_FX, hDirAC->hConfig->nbands ); + set_zero_fx( hDirAC->direction_vector_m_fx[0][block_m_idx], hDirAC->hConfig->nbands ); + set_zero_fx( hDirAC->direction_vector_m_fx[1][block_m_idx], hDirAC->hConfig->nbands ); + set_zero_fx( hDirAC->direction_vector_m_fx[2][block_m_idx], hDirAC->hConfig->nbands ); + +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + set_f( renormalization_factor, EPSILON, hDirAC->hConfig->nbands ); + fixedToFloat_arrL( hDirAC->direction_vector_m_fx[0][block_m_idx], hDirAC->direction_vector_m[0][block_m_idx], 0, hDirAC->hConfig->nbands ); + fixedToFloat_arrL( hDirAC->direction_vector_m_fx[1][block_m_idx], hDirAC->direction_vector_m[1][block_m_idx], 0, hDirAC->hConfig->nbands ); + fixedToFloat_arrL( hDirAC->direction_vector_m_fx[2][block_m_idx], hDirAC->direction_vector_m[2][block_m_idx], 0, hDirAC->hConfig->nbands ); +#endif + +#else mrange[0] = hDirAC->block_grouping[block_m_idx]; mrange[1] = hDirAC->block_grouping[block_m_idx + 1]; @@ -1086,11 +1268,22 @@ void ivas_dirac_param_est_enc( hDirAC->direction_vector_m[1][block_m_idx][band_m_idx] = 0; hDirAC->direction_vector_m[2][block_m_idx][band_m_idx] = 0; } +#endif for ( ts = mrange[0]; ts < mrange[1]; ts++ ) { if ( hDirAC->hFbMixer ) { +#ifdef IVAS_FLOAT_FIXED + ivas_fb_mixer_get_windowed_fr_fx( hDirAC->hFbMixer, pcm_in_fx, p_Cldfb_RealBuffer_fx, p_Cldfb_ImagBuffer_fx, l_ts, l_ts, hDirAC->hFbMixer->fb_cfg->num_in_chans, 0 ); + + ivas_fb_mixer_update_prior_input_fx( hDirAC->hFbMixer, pcm_in_fx, l_ts, hDirAC->hFbMixer->fb_cfg->num_in_chans ); + + FOR( i = 0; i < nchan_fb_in; i++ ) + { + pcm_in_fx[i] += l_ts; + } +#else ivas_fb_mixer_get_windowed_fr( hDirAC->hFbMixer, pcm_in, p_Cldfb_RealBuffer, p_Cldfb_ImagBuffer, l_ts, l_ts, hDirAC->hFbMixer->fb_cfg->num_in_chans ); ivas_fb_mixer_update_prior_input( hDirAC->hFbMixer, pcm_in, l_ts, hDirAC->hFbMixer->fb_cfg->num_in_chans ); @@ -1099,14 +1292,37 @@ void ivas_dirac_param_est_enc( { pcm_in[i] += l_ts; } +#endif } else { +#ifdef IVAS_FLOAT_FIXED + for ( i = 0; i < nchan_fb_in; i++ ) + { + mvr2r( &pp_fr_real[i][ts * l_ts], Cldfb_RealBuffer[i], l_ts ); + mvr2r( &pp_fr_imag[i][ts * l_ts], Cldfb_ImagBuffer[i], l_ts ); + } + FOR( i = 0; i < nchan_fb_in; i++ ) + { + Copy32( &pp_fr_real_fx[i][imult1616( ts, l_ts )], Cldfb_RealBuffer_fx[i], l_ts ); + Copy32( &pp_fr_imag_fx[i][imult1616( ts, l_ts )], Cldfb_ImagBuffer_fx[i], l_ts ); + } + cldfb_q = pp_fr_q; + move16(); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + FOR( i = 0; i < nchan_fb_in; i++ ) + { + fixedToFloat_arrL( Cldfb_ImagBuffer_fx[i], Cldfb_ImagBuffer[i], cldfb_q, l_ts ); + fixedToFloat_arrL( Cldfb_RealBuffer_fx[i], Cldfb_RealBuffer[i], cldfb_q, l_ts ); + } +#endif +#else for ( i = 0; i < nchan_fb_in; i++ ) { mvr2r( &pp_fr_real[i][ts * l_ts], Cldfb_RealBuffer[i], l_ts ); mvr2r( &pp_fr_imag[i][ts * l_ts], Cldfb_ImagBuffer[i], l_ts ); } +#endif } computeReferencePower_enc( @@ -1143,6 +1359,51 @@ void ivas_dirac_param_est_enc( direction_vector[2] ); } +#ifdef IVAS_FLOAT_FIXED +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS +#define MAX_NUM_INDEX_INTENSITY ( 10 ) /* NOTE: arbitrary value. need to check exact max value of "index"*/ + Word32 buffer_intensity_real_fx[DIRAC_NUM_DIMS][MAX_NUM_INDEX_INTENSITY][DIRAC_MAX_NBANDS]; + Word32 buffer_energy_fx[MAX_NUM_INDEX_INTENSITY * DIRAC_MAX_NBANDS]; + Word32 intensity_real_fx[DIRAC_NUM_DIMS][DIRAC_MAX_NBANDS]; + max_val = 0; + Word32 tmp32; + for ( i = 0; i < DIRAC_NUM_DIMS; i++ ) + { + float tmpf; + maximumAbs( intensity_real[i], num_freq_bands, &tmpf ); + max_val = fmaxf( max_val, tmpf ); + } + Word16 intensity_real_exp; + f2me( max_val, &tmp32, &intensity_real_exp ); + for ( i = 0; i < DIRAC_NUM_DIMS; i++ ) + { + for ( int j = 0; j < num_freq_bands; j++ ) + { + intensity_real_fx[i][j] = (Word32) ( intensity_real[i][j] * powf( 2, 31.f - intensity_real_exp ) ); + } + } + f2me_buf( reference_power[ts], reference_power_fx[ts], &reference_power_exp, num_freq_bands ); +#endif + /* fill buffers of length "averaging_length" time slots for intensity and energy */ + hDirAC->index_buffer_intensity = add( ( hDirAC->index_buffer_intensity % hDirAC->no_col_avg_diff ), 1 ); /* averaging_length = 32 */ + move16(); + index = hDirAC->index_buffer_intensity; + move16(); + assert( index <= MAX_NUM_INDEX_INTENSITY ); + FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) + { + /* only real part needed */ + Copy32( intensity_real_fx[i], &( buffer_intensity_real_fx[i][sub( index, 1 )][0] ), num_freq_bands ); + } + Copy32( reference_power_fx[ts], &( buffer_energy_fx[imult1616( sub( index, 1 ), num_freq_bands )] ), num_freq_bands ); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) + { + me2f_buf( &buffer_intensity_real_fx[i][index - 1][0], intensity_real_exp, &hDirAC->buffer_intensity_real[i][index - 1][0], num_freq_bands ); + } + me2f_buf( &buffer_energy_fx[( index - 1 ) * num_freq_bands], reference_power_exp, &hDirAC->buffer_energy[( index - 1 ) * num_freq_bands], num_freq_bands ); +#endif +#else /* fill buffers of length "averaging_length" time slots for intensity and energy */ hDirAC->index_buffer_intensity = ( hDirAC->index_buffer_intensity % hDirAC->no_col_avg_diff ) + 1; /* averaging_length = 32 */ index = hDirAC->index_buffer_intensity; @@ -1152,6 +1413,7 @@ void ivas_dirac_param_est_enc( mvr2r( intensity_real[i], &( hDirAC->buffer_intensity_real[i][index - 1][0] ), num_freq_bands ); } mvr2r( reference_power[ts], &( hDirAC->buffer_energy[( index - 1 ) * num_freq_bands] ), num_freq_bands ); +#endif computeDiffuseness_mdft( hDirAC->buffer_intensity_real, hDirAC->buffer_energy, num_freq_bands, hDirAC->no_col_avg_diff, diffuseness_vector ); @@ -1268,6 +1530,19 @@ void ivas_dirac_param_est_enc( } } + +#ifdef IVAS_FLOAT_FIXED + for ( block_m_idx = 0; block_m_idx < num_blocks; block_m_idx++ ) + { + free( hDirAC->direction_vector_m_fx[0][block_m_idx] ); + free( hDirAC->direction_vector_m_fx[1][block_m_idx] ); + free( hDirAC->direction_vector_m_fx[2][block_m_idx] ); + } + free( hDirAC->direction_vector_m_fx[0] ); + free( hDirAC->direction_vector_m_fx[1] ); + free( hDirAC->direction_vector_m_fx[2] ); +#endif + /* Diffuseness */ for ( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ ) { @@ -1293,6 +1568,17 @@ void ivas_dirac_param_est_enc( } } +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + for ( i = 0; i < nchan_fb_in; i++ ) + { + free( data_f_fx[i] ); + free( pp_fr_real_fx[i] ); + free( pp_fr_imag_fx[i] ); + } + free( pp_fr_real_fx ); + free( pp_fr_imag_fx ); +#endif + pop_wmops(); return; } diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index 191d3e97e..d6d900b86 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -1230,7 +1230,7 @@ ivas_error ivas_enc( #ifdef IVAS_FLOAT_FIXED_CONVERSIONS FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) { - st_ivas->hMasa->data.lfeToTotalEnergyRatio[i] = st_ivas->hMasa->data.lfeToTotalEnergyRatio_fx[i] / (float) ( 1 << ( Q31 - st_ivas->hMasa->data.lfeToTotalEnergyRatio_e[i] ) ); + st_ivas->hMasa->data.lfeToTotalEnergyRatio[i] = st_ivas->hMasa->data.lfeToTotalEnergyRatio_fx[i] / (float) ( 1 << ( Q15 - st_ivas->hMasa->data.lfeToTotalEnergyRatio_e[i] ) ); } for ( i = 0; i < nchan_inp; i++ ) { diff --git a/lib_enc/ivas_enc_cov_handler.c b/lib_enc/ivas_enc_cov_handler.c index 06691ff51..f2ee3a9d6 100644 --- a/lib_enc/ivas_enc_cov_handler.c +++ b/lib_enc/ivas_enc_cov_handler.c @@ -655,6 +655,11 @@ void ivas_enc_cov_handler_process_fx( FOR( j = 0; j < num_ch; j++ ) { Copy32( cov_real[i][j], hCovEnc->pCov_dtx_state->pPrior_cov_real_fx[i][j], pFb->filterbank_num_bands ); + FOR( k = 0; k < pFb->filterbank_num_bands; k++ ) + { + hCovEnc->pCov_dtx_state->q_prior_cov_real_per_band[i][j][k] = hCovEnc->pCov_state->q_cov_real_per_band[i][j][k]; + move16(); + } Copy32( cov_real[i][j], cov_dtx_real[i][j], pFb->filterbank_num_bands ); Copy( hCovEnc->pCov_state->q_cov_real_per_band[i][j], hCovEnc->pCov_dtx_state->q_cov_real_per_band[i][j], pFb->filterbank_num_bands ); } @@ -685,6 +690,11 @@ void ivas_enc_cov_handler_process_fx( FOR( j = 0; j < num_ch; j++ ) { Copy32( hCovEnc->pCov_dtx_state->pPrior_cov_real_fx[i][j], cov_dtx_real[i][j], pFb->filterbank_num_bands ); + FOR( k = 0; k < pFb->filterbank_num_bands; k++ ) + { + hCovEnc->pCov_dtx_state->q_cov_real_per_band[i][j][k] = hCovEnc->pCov_dtx_state->q_prior_cov_real_per_band[i][j][k]; + move16(); + } } } hCovEnc->prior_dtx_present = 1; diff --git a/lib_enc/ivas_front_vad.c b/lib_enc/ivas_front_vad.c index de7711853..d2cada5f9 100644 --- a/lib_enc/ivas_front_vad.c +++ b/lib_enc/ivas_front_vad.c @@ -966,10 +966,6 @@ ivas_error front_vad_spar( // Q_lp_noise = Q_factor( st->lp_noise ); st->lp_noise_fx = float_to_fix16( st->lp_noise, Q8 ); dtx_ivas_fx( st, hEncoderConfig->ivas_total_brate, vad_flag_dtx[0], inp_12k8_fx, Q_inp_12k8 ); - IF( st->Opt_DTX_ON ) - { - st->hDtxEnc->frame_ener = fixedToFloat( st->hDtxEnc->frame_ener_fx, -7 ); - } #else dtx( st, hEncoderConfig->ivas_total_brate, vad_flag_dtx[0], inp_12k8 ); #endif @@ -1051,7 +1047,6 @@ ivas_error front_vad_spar( fixedToFloat_arr( st->mem_decim2_fx, st->mem_decim2, Q8, 3 ); st->old_corr = fixedToFloat( st->old_corr_fx, Q15 ); // corr_shift_fx = floatToFixed( corr_shift, Q15 ); - st->old_thres = fixedToFloat( st->old_thres_fx, Q15 ); // st->old_thres_fx = floatToFixed( relE, Q8 ); /*for ( Word16 i = 0; i < 3; i++ ) { diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index 2f0326232..412ec99c9 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -58,7 +58,11 @@ static void combine_freqbands_and_subframes_fx( MASA_ENCODER_HANDLE hMasa ); static void combine_freqbands_and_subframes( MASA_ENCODER_HANDLE hMasa ); #endif +#ifdef IVAS_FLOAT_FIXED +static void find_n_largest_fx( const Word32 *input_fx, Word16 exp_input, Word16 *largestIndices, const Word16 numElements, const Word16 numLargest ); +#else static void find_n_largest( const float *input, int16_t *largestIndices, const int16_t numElements, const int16_t numLargest ); +#endif static void move_metadata_to_qmetadata( const MASA_ENCODER_HANDLE hMasa, IVAS_QMETADATA_HANDLE hQMeta ); @@ -70,7 +74,11 @@ static void compensate_energy_ratios_fx( MASA_ENCODER_HANDLE hMasa ); static void compensate_energy_ratios( MASA_ENCODER_HANDLE hMasa ); #endif +#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 ); +#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 ); @@ -477,7 +485,69 @@ ivas_error ivas_masa_encode( if ( ( ivas_format == MASA_ISM_FORMAT && ism_mode != ISM_MODE_NONE && ism_mode != ISM_MASA_MODE_MASA_ONE_OBJ ) || ( ivas_format != MASA_ISM_FORMAT ) ) { /* Combine directions */ +#ifdef IVAS_FLOAT_FIXED +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + Word16 numCodingBands = hMasa->config.numCodingBands; + Word16 numDirections = hMasa->config.numberOfDirections; + Word16 numSf = hMasa->config.joinedSubframes == TRUE ? 1 : MAX_PARAM_SPATIAL_SUBFRAMES; + Word16 computeCoherence = hMasa->config.useCoherence && hMasa->config.coherencePresent; + MASA_METADATA_HANDLE hMeta; + hMeta = &( hMasa->masaMetadata ); + for ( i = 0; i < numDirections; i++ ) + { + for ( j = 0; j < numSf; j++ ) + { + for ( int k = 0; k < hMasa->config.numCodingBands; k++ ) + { + hMeta->directional_meta[i].energy_ratio_fx[j][k] = floatToFixed( hMeta->directional_meta[i].energy_ratio[j][k], Q30 ); + hMeta->directional_meta[i].azimuth_fx[j][k] = floatToFixed( hMeta->directional_meta[i].azimuth[j][k], Q22 ); + hMeta->directional_meta[i].elevation_fx[j][k] = floatToFixed( hMeta->directional_meta[i].elevation[j][k], Q22 ); + } + } + } + /* Combine directions on the remaining bands */ + for ( i = 0; i < hMasa->config.numCodingBands; i++ ) + { + for ( j = 0; j < numSf; j++ ) + { + hMeta->directional_meta[0].spread_coherence_fx[j][i] = (Word16) floatToFixed( hMeta->directional_meta[0].spread_coherence[j][i], Q15 ); + hMeta->directional_meta[1].spread_coherence_fx[j][i] = (Word16) floatToFixed( hMeta->directional_meta[1].spread_coherence[j][i], Q15 ); + hMeta->common_meta.surround_coherence_fx[j][i] = (Word16) floatToFixed( hMeta->common_meta.surround_coherence[j][i], Q14 ); + } + } + + /* Estimate the importance of having two directions instead of one */ + for ( i = 0; i < MASA_FREQUENCY_BANDS; i++ ) + { + hMasa->data.importanceWeight_fx[i] = floatToFixed( hMasa->data.importanceWeight[i], Q30 ); + } +#endif + + ivas_masa_combine_directions_fx( hMasa ); + +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + for ( i = 0; i < numCodingBands; i++ ) + { + if ( hMasa->data.twoDirBands[i] == 0 ) + { + for ( j = 0; j < numSf; j++ ) + { + hMeta->directional_meta[0].azimuth[j][i] = fixedToFloat( hMeta->directional_meta[0].azimuth_fx[j][i], Q22 ); + hMeta->directional_meta[0].elevation[j][i] = fixedToFloat( hMeta->directional_meta[0].elevation_fx[j][i], Q22 ); + if ( computeCoherence ) + { + hMeta->directional_meta[0].spread_coherence[j][i] = fixedToFloat( hMeta->directional_meta[0].spread_coherence_fx[j][i], Q15 ); + hMeta->common_meta.surround_coherence[j][i] = fixedToFloat( hMeta->common_meta.surround_coherence_fx[j][i], Q14 ); + } + hMeta->directional_meta[0].energy_ratio[j][i] = fixedToFloat( hMeta->directional_meta[0].energy_ratio_fx[j][i], Q30 ); + hMeta->directional_meta[1].energy_ratio[j][i] = fixedToFloat( hMeta->directional_meta[1].energy_ratio_fx[j][i], Q30 ); + } + } + } +#endif +#else ivas_masa_combine_directions( hMasa ); +#endif } /* If we joined all bands, then metadata is now one directional. */ @@ -618,7 +688,21 @@ ivas_error ivas_masa_encode( if ( ivas_format == MC_FORMAT ) { int16_t lfeBitsWritten; +#ifdef IVAS_FLOAT_FIXED +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + { + f2me( hMasa->data.lfeToTotalEnergyRatio[i], &hMasa->data.lfeToTotalEnergyRatio_fx[i], &hMasa->data.lfeToTotalEnergyRatio_e[i] ); + } + hMasa->data.prevq_lfeToTotalEnergyRatio_fx = floatToFixed( hMasa->data.prevq_lfeToTotalEnergyRatio, Q31 ); +#endif + lfeBitsWritten = encode_lfe_to_total_energy_ratio_fx( hMasa, hMetaData, ivas_total_brate ); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + hMasa->data.prevq_lfeToTotalEnergyRatio = fixedToFloat( hMasa->data.prevq_lfeToTotalEnergyRatio_fx, Q31 ); +#endif +#else lfeBitsWritten = encode_lfe_to_total_energy_ratio( hMasa, hMetaData, ivas_total_brate ); +#endif hQMetaData->metadata_max_bits -= lfeBitsWritten; } @@ -761,7 +845,7 @@ ivas_error ivas_masa_encode( } } #endif - if ( ( error = ivas_qmetadata_enc_encode( hMetaData, hQMetaData, 0 ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_qmetadata_enc_encode_fx( hMetaData, hQMetaData, 0 ) ) != IVAS_ERR_OK ) { return error; } @@ -968,7 +1052,67 @@ ivas_error ivas_masa_encode( if ( hMasa->config.numberOfDirections == 2 && hMasa->config.numTwoDirBands < hMasa->config.numCodingBands ) { /* Combine directions */ +#ifdef IVAS_FLOAT_FIXED +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + numCodingBands = hMasa->config.numCodingBands; + Word16 numDirections = hMasa->config.numberOfDirections; + numSf = hMasa->config.joinedSubframes == TRUE ? 1 : MAX_PARAM_SPATIAL_SUBFRAMES; + Word16 computeCoherence = hMasa->config.useCoherence && hMasa->config.coherencePresent; + hMeta = &( hMasa->masaMetadata ); + for ( i = 0; i < numDirections; i++ ) + { + for ( j = 0; j < numSf; j++ ) + { + for ( int k = 0; k < hMasa->config.numCodingBands; k++ ) + { + hMeta->directional_meta[i].energy_ratio_fx[j][k] = floatToFixed( hMeta->directional_meta[i].energy_ratio[j][k], Q30 ); + hMeta->directional_meta[i].azimuth_fx[j][k] = floatToFixed( hMeta->directional_meta[i].azimuth[j][k], Q22 ); + hMeta->directional_meta[i].elevation_fx[j][k] = floatToFixed( hMeta->directional_meta[i].elevation[j][k], Q22 ); + } + } + } + /* Combine directions on the remaining bands */ + for ( i = 0; i < hMasa->config.numCodingBands; i++ ) + { + for ( j = 0; j < numSf; j++ ) + { + hMeta->directional_meta[0].spread_coherence_fx[j][i] = (Word16) floatToFixed( hMeta->directional_meta[0].spread_coherence[j][i], Q15 ); + hMeta->directional_meta[1].spread_coherence_fx[j][i] = (Word16) floatToFixed( hMeta->directional_meta[1].spread_coherence[j][i], Q15 ); + hMeta->common_meta.surround_coherence_fx[j][i] = (Word16) floatToFixed( hMeta->common_meta.surround_coherence[j][i], Q14 ); + } + } + + /* Estimate the importance of having two directions instead of one */ + for ( i = 0; i < MASA_FREQUENCY_BANDS; i++ ) + { + hMasa->data.importanceWeight_fx[i] = floatToFixed( hMasa->data.importanceWeight[i], Q30 ); + } +#endif + ivas_masa_combine_directions_fx( hMasa ); + +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + for ( i = 0; i < numCodingBands; i++ ) + { + if ( hMasa->data.twoDirBands[i] == 0 ) + { + for ( j = 0; j < numSf; j++ ) + { + hMeta->directional_meta[0].azimuth[j][i] = fixedToFloat( hMeta->directional_meta[0].azimuth_fx[j][i], Q22 ); + hMeta->directional_meta[0].elevation[j][i] = fixedToFloat( hMeta->directional_meta[0].elevation_fx[j][i], Q22 ); + if ( computeCoherence ) + { + hMeta->directional_meta[0].spread_coherence[j][i] = fixedToFloat( hMeta->directional_meta[0].spread_coherence_fx[j][i], Q15 ); + hMeta->common_meta.surround_coherence[j][i] = fixedToFloat( hMeta->common_meta.surround_coherence_fx[j][i], Q14 ); + } + hMeta->directional_meta[0].energy_ratio[j][i] = fixedToFloat( hMeta->directional_meta[0].energy_ratio_fx[j][i], Q30 ); + hMeta->directional_meta[1].energy_ratio[j][i] = fixedToFloat( hMeta->directional_meta[1].energy_ratio_fx[j][i], Q30 ); + } + } + } +#endif +#else ivas_masa_combine_directions( hMasa ); +#endif /* If we joined all bands, then metadata is now one directional. */ if ( hMasa->config.numTwoDirBands == 0 ) @@ -2303,7 +2447,298 @@ static void combine_freqbands_and_subframes( * * *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void ivas_masa_combine_directions_fx( + MASA_ENCODER_HANDLE hMasa ) +{ + Word16 i, j, k; + UWord8 numCodingBands; + UWord8 numSf; + UWord8 numDirections; + UWord8 computeCoherence; + MASA_METADATA_HANDLE hMeta; + + Word16 aziRad_fx; + Word16 eleRad_fx; + Word32 x_fx[MASA_MAXIMUM_DIRECTIONS][MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; + Word32 y_fx[MASA_MAXIMUM_DIRECTIONS][MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; + Word32 z_fx[MASA_MAXIMUM_DIRECTIONS][MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; + Word32 vecLen_fx; + Word32 xSum_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; + Word32 ySum_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; + Word32 zSum_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; + Word32 sumVecLen_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; + Word16 exp_sumVecLen_buff[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], exp_sumVecLen = MIN16B_FLT_FX; + move16(); + Word32 tempImportance_fx; + Word16 exp_tmp_importance = 0; + move16(); + Word32 importance_fx[MASA_FREQUENCY_BANDS]; + Word16 exp_importance_buff[MASA_FREQUENCY_BANDS], exp_importance = MIN16B_FLT_FX; + move16(); + Word16 indicesOfLargest[MASA_FREQUENCY_BANDS]; + + Word32 ratioSum_fx; + Word32 ambience1dir_fx; + Word32 ambience2dir_fx; + Word32 ambienceIncrease_fx; + Word32 origSurrCohEne_fx; + Word32 newSurrCohEne_fx; + + numCodingBands = hMasa->config.numCodingBands; + numDirections = hMasa->config.numberOfDirections; + move16(); + move16(); + + IF( EQ_16( hMasa->config.joinedSubframes, TRUE ) ) + { + numSf = 1; + } + ELSE + { + numSf = MAX_PARAM_SPATIAL_SUBFRAMES; + } + move16(); + hMeta = &( hMasa->masaMetadata ); + + computeCoherence = hMasa->config.useCoherence && hMasa->config.coherencePresent; + move16(); + Word16 azi_cos = 0, azi_sine = 0, ele_cos = 0, ele_sine = 0; + move16(); + move16(); + move16(); + move16(); + FOR( i = 0; i < numDirections; i++ ) + { + FOR( j = 0; j < numSf; j++ ) + { + FOR( k = 0; k < numCodingBands; k++ ) + { + aziRad_fx = extract_l( L_shr( Mpy_32_32( hMeta->directional_meta[i].azimuth_fx[j][k], PI_OVER_180_Q25 ), 3 ) ); // (Q22 + Q25 - 31) - 3 = Q13 + azi_cos = getCosWord16( aziRad_fx ); // Q14 + azi_sine = getSinWord16( aziRad_fx ); // Q15 + + eleRad_fx = extract_l( L_shr( Mpy_32_32( hMeta->directional_meta[i].elevation_fx[j][k], PI_OVER_180_Q25 ), 3 ) ); // (Q22 + Q25 - 31) - 3 = Q13 + ele_sine = getSinWord16( eleRad_fx ); // Q15 + ele_cos = getCosWord16( eleRad_fx ); // Q14 + + vecLen_fx = hMeta->directional_meta[i].energy_ratio_fx[j][k]; + move32(); + + x_fx[i][j][k] = L_mult0( azi_cos, ele_cos ); // Q14+Q14 + x_fx[i][j][k] = Mpy_32_32( x_fx[i][j][k], vecLen_fx ); // Q28+Q30-31 + y_fx[i][j][k] = L_mult0( azi_sine, ele_cos ); // Q15+Q14 + y_fx[i][j][k] = Mpy_32_32( y_fx[i][j][k], vecLen_fx ); // Q29+Q30-31 + z_fx[i][j][k] = Mpy_32_32( L_deposit_h( ele_sine ), vecLen_fx ); // Q16+Q15+Q30 - 31 + move32(); + move32(); + move32(); + move32(); + move32(); + } + } + } + + /* Compute sum vector */ + FOR( j = 0; j < numSf; j++ ) + { + FOR( k = 0; k < numCodingBands; k++ ) + { + xSum_fx[j][k] = L_add( x_fx[0][j][k], x_fx[1][j][k] ); // Q27 + ySum_fx[j][k] = L_add( y_fx[0][j][k], y_fx[1][j][k] ); // Q28 + zSum_fx[j][k] = L_add( z_fx[0][j][k], z_fx[1][j][k] ); // Q30 + move32(); + move32(); + move32(); + + Word32 var1 = Mpy_32_32( xSum_fx[j][k], xSum_fx[j][k] ); // Q27 + Q27 - 31 //Q23 + Word32 var2 = Mpy_32_32( ySum_fx[j][k], ySum_fx[j][k] ); // Q28 + Q28 - 31 //Q25 + Word32 var3 = Mpy_32_32( zSum_fx[j][k], zSum_fx[j][k] ); // Q30 + Q30 - 31 //Q29 + Word32 var4 = L_add( L_add( var1, L_shr( var2, 2 ) ), L_shr( var3, 6 ) ); // Q23 + Word16 exp_var4 = 31 - Q23; + move16(); + + Word16 exp_var5 = exp_var4; + move16(); + Word32 var5 = 0; + move32(); + + IF( var4 != 0 ) + { + var5 = Sqrt32( var4, &exp_var5 ); + } + sumVecLen_fx[j][k] = var5; + move32(); + exp_sumVecLen_buff[j][k] = exp_var5; + move16(); + } + } + + /*make commen exp for sumVecLen_fx buffer*/ + FOR( j = 0; j < numSf; j++ ) + { + FOR( k = 0; k < numCodingBands; k++ ) + { + exp_sumVecLen = s_max( exp_sumVecLen_buff[j][k], exp_sumVecLen ); + } + } + + FOR( j = 0; j < numSf; j++ ) + { + FOR( k = 0; k < numCodingBands; k++ ) + { + sumVecLen_fx[j][k] = L_shr( sumVecLen_fx[j][k], sub( exp_sumVecLen, exp_sumVecLen_buff[j][k] ) ); + move32(); + } + } + + /* Estimate the importance of having two directions instead of one */ + FOR( i = 0; i < numCodingBands; i++ ) + { + importance_fx[i] = 0; + move32(); + FOR( j = 0; j < numSf; j++ ) + { + tempImportance_fx = L_add( hMeta->directional_meta[0].energy_ratio_fx[j][i], hMeta->directional_meta[1].energy_ratio_fx[j][i] ); + exp_tmp_importance = 0; + move16(); + tempImportance_fx = BASOP_Util_Add_Mant32Exp( tempImportance_fx, 31 - Q30, L_negate( sumVecLen_fx[j][i] ), exp_sumVecLen, &exp_tmp_importance ); + importance_fx[i] = BASOP_Util_Add_Mant32Exp( importance_fx[i], exp_importance_buff[i], tempImportance_fx, exp_tmp_importance, &exp_importance_buff[i] ); + move32(); + } + + if ( numSf != 1 ) + { + importance_fx[i] = L_shr( importance_fx[i], 2 ); + move32(); + } + importance_fx[i] = Mpy_32_32( importance_fx[i], hMasa->data.importanceWeight_fx[i] ); + move32(); + exp_importance_buff[i] = add( exp_importance_buff[i], 1 ); + move16(); + } + + /*make commen exp for importance_fx buffer*/ + FOR( i = 0; i < numCodingBands; i++ ) + { + exp_importance = s_max( exp_importance_buff[i], exp_importance ); + } + FOR( i = 0; i < numCodingBands; i++ ) + { + importance_fx[i] = L_shr( importance_fx[i], sub( exp_importance, exp_importance_buff[i] ) ); + move32(); + } + + /* Determine bands where to use two directions */ + find_n_largest_fx( importance_fx, exp_importance, indicesOfLargest, numCodingBands, hMasa->config.numTwoDirBands ); + + FOR( i = 0; i < numCodingBands; i++ ) + { + hMasa->data.twoDirBands[i] = 0; + move16(); + } + + FOR( i = 0; i < hMasa->config.numTwoDirBands; i++ ) + { + hMasa->data.twoDirBands[indicesOfLargest[i]] = 1; + move16(); + } + + /* Combine directions on the remaining bands */ + FOR( i = 0; i < numCodingBands; i++ ) + { + IF( hMasa->data.twoDirBands[i] == 0 ) + { + FOR( j = 0; j < numSf; j++ ) + { + aziRad_fx = BASOP_util_atan2( ySum_fx[j][i], xSum_fx[j][i], Q27 - Q28 ); // Q13 + Word32 tmp1 = Mpy_32_32( xSum_fx[j][i], xSum_fx[j][i] ); // Q27+Q27-31 //Q23 + Word32 tmp2 = Mpy_32_32( ySum_fx[j][i], ySum_fx[j][i] ); // Q28+Q28-31 //Q25 + Word32 tmp3 = L_add( tmp1, L_shr( tmp2, 2 ) ); // Q23 + Word16 exp_tmp3 = 31 - Q23; + move16(); + Word32 tmp4 = Sqrt32( tmp3, &exp_tmp3 ); + eleRad_fx = BASOP_util_atan2( zSum_fx[j][i], tmp4, sub( sub( 31, Q30 ), exp_tmp3 ) ); + + Word16 exp_tmp5 = 0; + move16(); + Word16 tmp5 = BASOP_Util_Divide1616_Scale( aziRad_fx, EVS_PI_FX, &exp_tmp5 ); + Word16 Q_tmp6 = 0; + move16(); + Word32 tmp6 = L_mult( tmp5, 23040 /*180.0f in Q7*/ ); + Q_tmp6 = sub( 31, add( exp_tmp5, 8 ) ); + + Word16 exp_tmp7 = 0; + move16(); + Word16 tmp7 = BASOP_Util_Divide1616_Scale( eleRad_fx, EVS_PI_FX, &exp_tmp7 ); + Word16 Q_tmp8 = 0; + move16(); + Word32 tmp8 = L_mult( tmp7, 23040 /*180.0f in Q7*/ ); + Q_tmp8 = sub( 31, add( exp_tmp7, 8 ) ); + + Scale_sig32( &tmp6, 1, Q22 - Q_tmp6 ); + Scale_sig32( &tmp8, 1, Q22 - Q_tmp8 ); + + hMeta->directional_meta[0].azimuth_fx[j][i] = tmp6; // Q22 + hMeta->directional_meta[0].elevation_fx[j][i] = tmp8; // Q22 + move32(); + move32(); + ratioSum_fx = L_add( hMeta->directional_meta[0].energy_ratio_fx[j][i], hMeta->directional_meta[1].energy_ratio_fx[j][i] ); // Q30 + IF( computeCoherence ) + { + Word32 var1 = Mpy_32_16_1( hMeta->directional_meta[0].energy_ratio_fx[j][i], hMeta->directional_meta[0].spread_coherence_fx[j][i] ); + Word32 var2 = Mpy_32_16_1( hMeta->directional_meta[1].energy_ratio_fx[j][i], hMeta->directional_meta[1].spread_coherence_fx[j][i] ); + Word32 var3 = L_add( var1, var2 ); // Q30 + Word16 exp_var4 = 0; + move16(); + Word32 var4 = BASOP_Util_Add_Mant32Exp( ratioSum_fx, 31 - Q30, EPSILON_FX_M, EPSILON_FX_E, &exp_var4 ); + Word16 exp_var5 = 0; + move16(); + Word16 var5 = BASOP_Util_Divide3232_Scale( var3, var4, &exp_var5 ); + exp_var5 = add( exp_var5, ( sub( sub( 31, Q30 ), exp_var4 ) ) ); + Scale_sig( &var5, 1, sub( Q15, sub( 15, exp_var5 ) ) ); + hMeta->directional_meta[0].spread_coherence_fx[j][i] = var5; // Q15 + move16(); + } + + ambience2dir_fx = L_sub( ONE_IN_Q30, ratioSum_fx ); // Q30 + Word32 ambience2dir_fx_by_2 = L_shr( ambience2dir_fx, 1 ); + Word32 var_a = L_add( L_add( hMeta->directional_meta[0].energy_ratio_fx[j][i], hMeta->directional_meta[1].energy_ratio_fx[j][i] ), ambience2dir_fx_by_2 ); // Q30 + Word16 exp_var_b = 0; + move16(); + Word16 var_b = BASOP_Util_Divide3232_Scale( sumVecLen_fx[j][i], var_a, &exp_var_b ); + exp_var_b = add( exp_var_b, sub( exp_sumVecLen, 1 ) ); + Word32 var_b_32 = L_deposit_h( var_b ); + hMeta->directional_meta[0].energy_ratio_fx[j][i] = L_shr( var_b_32, 1 - exp_var_b ); // Q30 + hMeta->directional_meta[1].energy_ratio_fx[j][i] = 0; // Q30 + move16(); + move16(); + IF( computeCoherence ) + { + ambience1dir_fx = L_sub( ONE_IN_Q30, hMeta->directional_meta[0].energy_ratio_fx[j][i] ); // Q30 + ambienceIncrease_fx = L_max( L_sub( ambience1dir_fx, ambience2dir_fx ), 0 ); // Q30 + origSurrCohEne_fx = Mpy_32_16_1( ambience2dir_fx /*Q30*/, hMeta->common_meta.surround_coherence_fx[j][i] /*Q14*/ ); // Q29 + newSurrCohEne_fx = Mpy_32_16_1( ambienceIncrease_fx /*Q30*/, hMeta->directional_meta[0].spread_coherence_fx[j][i] /*Q15*/ ); // Q30 + + Word16 exp_y = 0, exp_z = 0; + move16(); + move16(); + Word32 x = L_add( origSurrCohEne_fx, L_shr( newSurrCohEne_fx, 1 ) ); // Q29 + Word32 y = BASOP_Util_Add_Mant32Exp( ambience1dir_fx, 1, EPSILON_FX_M, EPSILON_FX_E, &exp_y ); + Word16 z = BASOP_Util_Divide3232_Scale( x, y, &exp_z ); + exp_z = add( exp_z, ( sub( sub( 31, Q29 ), exp_y ) ) ); + z = shr( z, sub( 1, exp_z ) ); // Q14 + hMeta->common_meta.surround_coherence_fx[j][i] = s_min( ONE_IN_Q14, z ); + move16(); + } + } + } + } + + return; +} +#else void ivas_masa_combine_directions( MASA_ENCODER_HANDLE hMasa ) { @@ -2436,8 +2871,60 @@ void ivas_masa_combine_directions( return; } +#endif + +#ifdef IVAS_FLOAT_FIXED +static void find_n_largest_fx( + const Word32 *input_fx, + Word16 exp_input, + Word16 *largestIndices, + const Word16 numElements, + const Word16 numLargest ) +{ + Word16 i, j; + Word32 largestValue; + Word16 largestIndex; + Word32 values[MASA_FREQUENCY_BANDS]; + FOR( j = 0; j < numElements; j++ ) + { + values[j] = input_fx[j]; + move32(); + } + + FOR( i = 0; i < numLargest; i++ ) + { + largestValue = values[0]; + move32(); + largestIndex = 0; + move16(); + FOR( j = 1; j < numElements; j++ ) + { + IF( GT_32( values[j], largestValue ) ) + { + largestValue = values[j]; + largestIndex = j; + move32(); + move16(); + } + } + largestIndices[i] = largestIndex; + move16(); + IF( exp_input != 0 ) + { + values[largestIndex] = L_negate( 1 << ( sub( 31, exp_input ) ) ); + move32(); + } + ELSE + { + values[largestIndex] = 1 << ( sub( 31, exp_input ) ); + move32(); + } + } + return; +} +#else static void find_n_largest( const float *input, int16_t *largestIndices, @@ -2472,6 +2959,7 @@ static void find_n_largest( return; } +#endif static void move_metadata_to_qmetadata( @@ -3024,6 +3512,234 @@ static void reduce_metadata_further( } +#ifdef IVAS_FLOAT_FIXED +static Word16 encode_lfe_to_total_energy_ratio_fx( + MASA_ENCODER_HANDLE hMasa, /* i/o: MASA encoder structure */ + BSTR_ENC_HANDLE hMetaData, /* i/o: Metadata bitstream handle */ + const Word32 ivas_total_brate /* i : IVAS total bitrate */ +) +{ + Word16 i; + Word16 xq; + Word16 VQLevels; + Word32 maxLFESubFrameEner; + Word16 maxLFESubFrameEner_e; + Word32 log2LFEaverage; + Word32 log2LFEratio[4]; + Word16 log2LFEratio_16[4]; + Word16 xqv[4]; + Word32 linearLFEaverage; + Word16 linearLFEaverage_e; + Word16 lfeToTotalEnergyRatioIndices[3]; + Word16 lfeAdaptiveVQBits; + Word16 lfeBitsWritten; + Word32 maxVal; + Word16 maxVal_e; +#ifdef BASOP_NOGLOB_DECLARE_LOCAL + Flag Overflow = 0; + move32(); +#endif + + VQLevels = 0; + move16(); + lfeAdaptiveVQBits = 0; + move16(); + + /* Determine maximum amount of LFE energy in any subframe */ + maxLFESubFrameEner = 0; + move32(); + maxLFESubFrameEner_e = 0; + move16(); + FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + { + IF( BASOP_Util_Cmp_Mant32Exp( hMasa->data.lfeToTotalEnergyRatio_fx[i], hMasa->data.lfeToTotalEnergyRatio_e[i], maxLFESubFrameEner, maxLFESubFrameEner_e ) > 0 ) + { + maxLFESubFrameEner = hMasa->data.lfeToTotalEnergyRatio_fx[i]; + move32(); + maxLFESubFrameEner_e = hMasa->data.lfeToTotalEnergyRatio_e[i]; + move16(); + } + } + + /* Set default values for the indices */ + FOR( i = 0; i < 3; i++ ) + { + lfeToTotalEnergyRatioIndices[i] = 0; + move16(); + } + + /* Check if there is enough energy in any subframe. If not, send only 1 bit (0) and abort. */ + /* If there is enough LFE energy at least in one subframe, quantize it. */ + IF( BASOP_Util_Cmp_Mant32Exp( maxLFESubFrameEner, maxLFESubFrameEner_e, 10737418 /* 0.005f in Q31 */, 0 ) > 0 ) + { + /* Convert energy to log2 domain, and clamp it to reasonable values */ + log2LFEaverage = 0; // Q25 + move32(); + FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + { + // log2LFEratio[i] = log2f( max( 0.001f, hMasa->data.lfeToTotalEnergyRatio[i] ) ); + maxVal = 2147484 /* 0.001f in Q31 */; + move32(); + maxVal_e = 0; + move16(); + IF( BASOP_Util_Cmp_Mant32Exp( hMasa->data.lfeToTotalEnergyRatio_fx[i], hMasa->data.lfeToTotalEnergyRatio_e[i], maxVal, maxVal_e ) > 0 ) + { + maxVal = hMasa->data.lfeToTotalEnergyRatio_fx[i]; + move32(); + maxVal_e = hMasa->data.lfeToTotalEnergyRatio_e[i]; + move16(); + } + log2LFEratio[i] = L_add( BASOP_Util_Log2( maxVal ), L_shl( maxVal_e, Q25 ) ); // Q25 + move32(); + IF( GT_32( log2LFEratio[i], ONE_IN_Q25 ) ) /* Corresponds to linear value 2.0f */ + { + log2LFEratio[i] = ONE_IN_Q25; // Q25 + move32(); + } + ELSE IF( LT_32( log2LFEratio[i], -301989888 /* -9.0f in Q25 */ ) ) + { + log2LFEratio[i] = -301989888 /* -9.0f in Q25 */; // Q25 + move32(); + } + log2LFEaverage = L_add( log2LFEaverage, Mpy_32_32( 536870912 /* 0.25f in Q31 */, log2LFEratio[i] ) ); // Q25 + } + + IF( EQ_32( ivas_total_brate, IVAS_13k2 ) ) + { + /* Calculate adaptive 1-bit LFE quantizer index */ + // linearLFEaverage = exp2f( log2LFEaverage ); /* Convert back to linear domain */ + linearLFEaverage = BASOP_util_Pow2( log2LFEaverage, Q31 - Q25, &linearLFEaverage_e ); /* Convert back to linear domain */ + linearLFEaverage = L_shl( linearLFEaverage, linearLFEaverage_e ); // Q31 + test(); + IF( GT_32( linearLFEaverage, MCMASA_LFE_1BIT_THRES_Q31 ) && + GT_32( linearLFEaverage, L_add( L_add( MCMASA_LFE_BETA_Q31 >> Q1, L_shr( hMasa->data.prevq_lfeToTotalEnergyRatio_fx, Q1 ) ), + L_shr( Mpy_32_32( MCMASA_LFE_ALPHA_Q31, hMasa->data.prevq_lfeToTotalEnergyRatio_fx ), Q1 ) ) ) ) + { + lfeToTotalEnergyRatioIndices[0] = 1; + move16(); + IF( EQ_16( hMasa->data.prevq_lfeIndex, 1 ) ) + { +#ifdef BASOP_NOGLOB + hMasa->data.prevq_lfeToTotalEnergyRatio_fx = L_add_o( hMasa->data.prevq_lfeToTotalEnergyRatio_fx, 251255587 /* MCMASA_LFE_THETA * MCMASA_LFE_BETA in Q31 */, &Overflow ); /* larger "bump-up" to LFE-to-total energy ratio */ // Q31 +#else + hMasa->data.prevq_lfeToTotalEnergyRatio_fx = L_add( hMasa->data.prevq_lfeToTotalEnergyRatio_fx, 251255587 /* MCMASA_LFE_THETA * MCMASA_LFE_BETA in Q31 */ ); /* larger "bump-up" to LFE-to-total energy ratio */ // Q31 +#endif + move32(); + } + ELSE + { +#ifdef BASOP_NOGLOB + hMasa->data.prevq_lfeToTotalEnergyRatio_fx = L_add_o( hMasa->data.prevq_lfeToTotalEnergyRatio_fx, MCMASA_LFE_BETA_Q31, &Overflow ); /* default "bump-up" to LFE-to-total energy ratio */ // Q31 +#else + hMasa->data.prevq_lfeToTotalEnergyRatio_fx = L_add( hMasa->data.prevq_lfeToTotalEnergyRatio_fx, MCMASA_LFE_BETA_Q31 ); /* default "bump-up" to LFE-to-total energy ratio */ // Q31 +#endif + move32(); + } + } + ELSE + { + hMasa->data.prevq_lfeToTotalEnergyRatio_fx = Mpy_32_32( MCMASA_LFE_ALPHA_Q31, hMasa->data.prevq_lfeToTotalEnergyRatio_fx ); /* exponential decay */ // Q31 + move32(); + } + + if ( GT_32( hMasa->data.prevq_lfeToTotalEnergyRatio_fx, ONE_IN_Q31 ) ) + { + hMasa->data.prevq_lfeToTotalEnergyRatio_fx = ONE_IN_Q31; + move32(); + } + hMasa->data.prevq_lfeIndex = lfeToTotalEnergyRatioIndices[0]; /* Update to previous frame's index memories */ + move16(); + } + ELSE /* Bitrate >= 16.4 kbps */ + { + /* Do 1st stage scalar quantization */ + lfeToTotalEnergyRatioIndices[0] = 1; + move16(); + lfeToTotalEnergyRatioIndices[1] = usquant_fx( extract_l( L_shr( log2LFEaverage, Q13 ) ), &xq, MCMASA_LFE_QLOW_Q12, MCMASA_LFE_DELTA_Q11, 8 ); + move16(); + + IF( GE_32( ivas_total_brate, IVAS_24k4 ) ) /* Vector quantization is applied if bitrate >= 24.4 kbps */ + { + /* Remove scalar value from the vector*/ + FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + { + log2LFEratio[i] = L_sub( log2LFEratio[i], L_shl( xq, Q13 ) ); // Q25 + move32(); + } + + /* Vector quantize residual with energy adaptive bit allocation */ + SWITCH( lfeToTotalEnergyRatioIndices[1] ) + { + case 0: + case 1: + VQLevels = 0; + move16(); + lfeAdaptiveVQBits = 0; + move16(); + BREAK; + case 2: + VQLevels = 2; + move16(); + lfeAdaptiveVQBits = 1; + move16(); + BREAK; + case 3: + VQLevels = 4; + move16(); + lfeAdaptiveVQBits = 2; + move16(); + BREAK; + case 4: + VQLevels = 8; + move16(); + lfeAdaptiveVQBits = 3; + move16(); + BREAK; + default: + VQLevels = 16; + move16(); + lfeAdaptiveVQBits = 4; + move16(); + } + + IF( VQLevels > 0 ) + { + Copy_Scale_sig32_16( log2LFEratio, log2LFEratio_16, 4, Q16 + Q13 - Q25 ); // Q13 + lfeToTotalEnergyRatioIndices[2] = vquant_ivas_fx( log2LFEratio_16, 0, xqv, McMASA_LFEGain_vectors_fx_q13, 4, VQLevels ); + move16(); + } + } + } + } + + /* Write first LFE bit */ + lfeBitsWritten = 0; + move16(); + push_next_indice( hMetaData, lfeToTotalEnergyRatioIndices[0], 1 ); + lfeBitsWritten = add( lfeBitsWritten, 1 ); + + test(); + IF( EQ_16( lfeToTotalEnergyRatioIndices[0], 1 ) && GE_32( ivas_total_brate, IVAS_16k4 ) ) + { + /* If bitrate >= 16.4kbit/s, send 1-bit on/off + 3-bit scalar */ + push_next_indice( hMetaData, lfeToTotalEnergyRatioIndices[1], 3 ); + lfeBitsWritten = add( lfeBitsWritten, 3 ); + + /* If bitrate >= 24.4kbit/s, use adaptive 1 + (3.. 7) bit quantizer */ + IF( GE_32( ivas_total_brate, IVAS_24k4 ) ) + { + /* Vector quantize residual with energy adaptive bit allocation */ + IF( lfeAdaptiveVQBits > 0 ) + { + push_next_indice( hMetaData, lfeToTotalEnergyRatioIndices[2], lfeAdaptiveVQBits ); + lfeBitsWritten = add( lfeBitsWritten, lfeAdaptiveVQBits ); + } + } + } + + return lfeBitsWritten; +} +#else static int16_t encode_lfe_to_total_energy_ratio( MASA_ENCODER_HANDLE hMasa, /* i/o: MASA encoder structure */ BSTR_ENC_HANDLE hMetaData, /* i/o: Metadata bitstream handle */ @@ -3180,6 +3896,7 @@ static int16_t encode_lfe_to_total_energy_ratio( return lfeBitsWritten; } +#endif /*-------------------------------------------------------------------* diff --git a/lib_enc/ivas_mc_param_enc.c b/lib_enc/ivas_mc_param_enc.c index 3e9f14f46..1404d215d 100644 --- a/lib_enc/ivas_mc_param_enc.c +++ b/lib_enc/ivas_mc_param_enc.c @@ -55,16 +55,11 @@ *------------------------------------------------------------------------*/ -static void ivas_param_mc_parameter_quantizer( const float *x, const int16_t L, const int16_t sz_quantizer, const float *quantizer, int16_t *quant_idx, float *y ); - - #ifndef FIX_901_PARAMMC_DEAD_CODE static void ivas_param_mc_enc_find_icc_map( PARAM_MC_ENC_HANDLE hParamMC, float Cx_sum[][PARAM_MC_MAX_TRANSPORT_CHANS][PARAM_MC_MAX_TRANSPORT_CHANS], float Cy_sum[][MAX_CICP_CHANNELS][MAX_CICP_CHANNELS], float ILD_q[PARAM_MC_MAX_PARAMETER_BANDS][PARAM_MC_SZ_ILD_MAP], const int16_t nchan_input, const int16_t nchan_transport ); #endif -static void ivas_param_mc_quantize_iccs( PARAM_MC_ENC_HANDLE hParamMC, float Cy[MAX_CICP_CHANNELS][MAX_CICP_CHANNELS], const int16_t freq_idx, const int16_t nchan_input, int16_t *ICC_idx_out ); -static void ivas_param_mc_quantize_ilds( PARAM_MC_ENC_HANDLE hParamMC, float Cy[MAX_CICP_CHANNELS][MAX_CICP_CHANNELS], float Cx[PARAM_MC_MAX_TRANSPORT_CHANS][PARAM_MC_MAX_TRANSPORT_CHANS], const int16_t freq_idx, const int16_t nchan_input, const int16_t nchan_transport, int16_t *ILD_idx_out, float ILD_q[PARAM_MC_SZ_ILD_MAP] ); static void ivas_param_mc_write_bs( const PARAM_MC_ENC_HANDLE hParamMC, int16_t *ILD_idx, int16_t *ICC_idx, uint16_t bit_buffer[PARAM_MC_MAX_BITS], int16_t *bit_pos ); @@ -77,6 +72,11 @@ static void ivas_param_mc_range_encoder( const int16_t *seq_in, const int16_t nu #ifdef IVAS_FLOAT_FIXED #define ATTACKTHRESHOLD_E 4 +static void ivas_param_mc_quantize_ilds_fx( PARAM_MC_ENC_HANDLE hParamMC, Word32 Cy_fx[MAX_CICP_CHANNELS][MAX_CICP_CHANNELS], Word16 Cy_e[MAX_CICP_CHANNELS][MAX_CICP_CHANNELS], Word32 Cx[PARAM_MC_MAX_TRANSPORT_CHANS][PARAM_MC_MAX_TRANSPORT_CHANS], Word16 Cx_fx[PARAM_MC_MAX_TRANSPORT_CHANS][PARAM_MC_MAX_TRANSPORT_CHANS], const Word16 freq_idx, const Word16 nchan_input, const Word16 nchan_transport, Word16 *ILD_idx_out, Word16 ILD_q[PARAM_MC_SZ_ILD_MAP] ); + +static void ivas_param_mc_parameter_quantizer_fx( const Word32 *x, const Word16 *x_e, const Word16 L, const Word16 sz_quantizer, const Word16 *quantizer_fx, const Word16 Q_quant, Word16 *quant_idx, Word16 *y ); + +static void ivas_param_mc_quantize_iccs_fx( PARAM_MC_ENC_HANDLE hParamMC, Word32 Cy_fx[MAX_CICP_CHANNELS][MAX_CICP_CHANNELS], Word16 Cy_e[MAX_CICP_CHANNELS][MAX_CICP_CHANNELS], const Word16 freq_idx, const Word16 nchan_input, Word16 *ICC_idx_out ); static void ivas_param_mc_dmx_fx( PARAM_MC_ENC_HANDLE hParamMC, Word32 *data_f_fx[], Word32 data_dmx_fx[][L_FRAME48k], const Word16 input_frame, const Word16 nchan_input, const Word16 nchan_transport ); @@ -86,12 +86,18 @@ static void ivas_param_mc_param_est_enc_fx( PARAM_MC_ENC_HANDLE hParamMC, Word32 #else +static void ivas_param_mc_quantize_ilds( PARAM_MC_ENC_HANDLE hParamMC, float Cy[MAX_CICP_CHANNELS][MAX_CICP_CHANNELS], float Cx[PARAM_MC_MAX_TRANSPORT_CHANS][PARAM_MC_MAX_TRANSPORT_CHANS], const int16_t freq_idx, const int16_t nchan_input, const int16_t nchan_transport, int16_t *ILD_idx_out, float ILD_q[PARAM_MC_SZ_ILD_MAP] ); + +static void ivas_param_mc_quantize_iccs( PARAM_MC_ENC_HANDLE hParamMC, float Cy[MAX_CICP_CHANNELS][MAX_CICP_CHANNELS], const int16_t freq_idx, const int16_t nchan_input, int16_t *ICC_idx_out ); + static void ivas_param_mc_dmx( PARAM_MC_ENC_HANDLE hParamMC, float *data_f[], float data_dmx[][L_FRAME48k], const int16_t input_frame, const int16_t nchan_input, const int16_t nchan_transport ); static void ivas_param_mc_transient_detection( PARAM_MC_ENC_HANDLE hParamMC, TRAN_DET_HANDLE hTranDet, int16_t *bAttackPresent, int16_t *attackIdx ); static void ivas_param_mc_param_est_enc( PARAM_MC_ENC_HANDLE hParamMC, float *data_f[], float Cy_sum[][MAX_CICP_CHANNELS][MAX_CICP_CHANNELS], float Cx_sum[][PARAM_MC_MAX_TRANSPORT_CHANS][PARAM_MC_MAX_TRANSPORT_CHANS], const int16_t input_frame, const int16_t nchan_input, const int16_t nchan_transport ); +static void ivas_param_mc_parameter_quantizer( const float *x, const int16_t L, const int16_t sz_quantizer, const float *quantizer, int16_t *quant_idx, float *y ); + #endif /*------------------------------------------------------------------------- @@ -237,10 +243,16 @@ ivas_error ivas_param_mc_enc_open( /* Init total/dmx ener factors */ set_f( hParamMC->ener_fac, 0.0f, PARAM_MC_MAX_PARAMETER_BANDS ); +#ifdef IVAS_FLOAT_FIXED + set32_fx( hParamMC->ener_fac_fx, 0, PARAM_MC_MAX_PARAMETER_BANDS ); +#endif /* init previous ILDs */ for ( i = 0; i < PARAM_MC_MAX_PARAMETER_BANDS; i++ ) { +#ifdef IVAS_FLOAT_FIXED + set32_fx( hParamMC->prev_ilds_fx[i], 0, PARAM_MC_SZ_ILD_MAP ); +#endif set_zero( hParamMC->prev_ilds[i], PARAM_MC_SZ_ILD_MAP ); } @@ -386,6 +398,9 @@ ivas_error ivas_param_mc_enc_reconfig( /* Init total/dmx ener factors */ set_f( hParamMC->ener_fac, 0.0f, PARAM_MC_MAX_PARAMETER_BANDS ); +#ifdef IVAS_FLOAT_FIXED + set32_fx( hParamMC->ener_fac_fx, 0, PARAM_MC_MAX_PARAMETER_BANDS ); +#endif return error; @@ -452,10 +467,12 @@ void ivas_param_mc_enc( float data_dmx[PARAM_MC_MAX_TRANSPORT_CHANS][L_FRAME48k]; #ifdef IVAS_FLOAT_FIXED Word32 data_dmx_fx[PARAM_MC_MAX_TRANSPORT_CHANS][L_FRAME48k]; + Word16 data_dmx_fx16[PARAM_MC_MAX_TRANSPORT_CHANS][L_FRAME48k]; Word32 Cy_sum_fx[PARAM_MC_MAX_PARAMETER_BANDS][MAX_CICP_CHANNELS][MAX_CICP_CHANNELS]; Word16 Cy_sum_e[PARAM_MC_MAX_PARAMETER_BANDS][MAX_CICP_CHANNELS][MAX_CICP_CHANNELS]; Word32 Cx_sum_fx[PARAM_MC_MAX_PARAMETER_BANDS][PARAM_MC_MAX_TRANSPORT_CHANS][PARAM_MC_MAX_TRANSPORT_CHANS]; Word16 Cx_sum_e[PARAM_MC_MAX_PARAMETER_BANDS][PARAM_MC_MAX_TRANSPORT_CHANS][PARAM_MC_MAX_TRANSPORT_CHANS]; + Word16 ILD_q_fx[PARAM_MC_MAX_PARAMETER_BANDS][PARAM_MC_SZ_ILD_MAP]; #endif int16_t ch; int16_t band; @@ -543,7 +560,61 @@ void ivas_param_mc_enc( { Word16 cpe_idx = ch / 2; +#ifdef IVAS_FLOAT_FIXED +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.firState1 = (Word16) floatToFixed( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.firState1_flt, -1 ); + st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.firState2 = (Word16) floatToFixed( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.firState2_flt, -1 ); + + FOR( i = 0; i < NSUBBLOCKS + MAX_TD_DELAY + 1; i++ ) + { + st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.accSubblockNrg[i] = floatToFixed( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.accSubblockNrg_flt[i], 7 ); + } + + FOR( i = 0; i < NSUBBLOCKS + MAX_TD_DELAY; i++ ) + { + st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.subblockNrg[i] = floatToFixed( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.subblockNrg_flt[i], 7 ); + st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.subblockNrgChange[i] = (Word16) floatToFixed( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.subblockNrgChange_flt[i], 7 ); + } + + + FOR( i = 0; i < L_FRAME_MAX / NSUBBLOCKS; i++ ) + { + st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->delayBuffer.buffer[i] = (Word16) floatToFixed( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->delayBuffer.buffer_flt[i], 7 ); + } + st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->transientDetector.attackRatioThreshold = (Word16) floatToFixed( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->transientDetector.attackRatioThreshold_flt, 11 ); + + floatToFixed_arr16( data_dmx[ch], data_dmx_fx16[ch], -1, input_frame ); + st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.facAccSubblockNrg = float_to_fix16( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.facAccSubblockNrg_flt, 15 ); + +#endif + + RunTransientDetection_ivas_fx( data_dmx_fx16[ch], input_frame, st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet ); + +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + + st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.firState1_flt = fixedToFloat( (Word32) st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.firState1, -1 ); + st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.firState2_flt = fixedToFloat( (Word32) st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.firState2, -1 ); + + + FOR( i = 0; i < NSUBBLOCKS + MAX_TD_DELAY; i++ ) + { + st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.subblockNrg_flt[i] = fixedToFloat( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.subblockNrg[i], 7 ); + st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.subblockNrgChange_flt[i] = fixedToFloat( (Word32) st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.subblockNrgChange[i], 7 ); + } + + FOR( i = 0; i < NSUBBLOCKS + MAX_TD_DELAY + 1; i++ ) + { + st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.accSubblockNrg_flt[i] = fixedToFloat( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.accSubblockNrg[i], 7 ); + } + + FOR( i = 0; i < L_FRAME_MAX / NSUBBLOCKS; i++ ) + { + st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->delayBuffer.buffer_flt[i] = fixedToFloat( (Word32) st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->delayBuffer.buffer[i], -1 ); + } +#endif +#else RunTransientDetection( data_dmx[ch], input_frame, st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet ); +#endif #ifdef IVAS_FLOAT_FIXED #ifdef IVAS_FLOAT_FIXED_CONVERSIONS f2me_buf( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.subblockNrg_flt, st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.subblockNrg, &st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.subblockNrg_e, NSUBBLOCKS + MAX_TD_DELAY ); @@ -623,7 +694,14 @@ void ivas_param_mc_enc( /* ILD parameter quantization */ for ( k = 0; k < hParamMC->hMetadataPMC.nbands_coded; k += band_step ) { +#ifdef IVAS_FLOAT_FIXED + ivas_param_mc_quantize_ilds_fx( hParamMC, Cy_sum_fx[k], Cy_sum_e[k], Cx_sum_fx[k], Cx_sum_e[k], k, nchan_inp, st_ivas->nchan_transport, ILD_idx, ILD_q_fx[k] ); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + fixedToFloat_arrL( hParamMC->prev_ilds_fx[i], hParamMC->prev_ilds[i], Q21, PARAM_MC_SZ_ILD_MAP ); +#endif +#else ivas_param_mc_quantize_ilds( hParamMC, Cy_sum[k], Cx_sum[k], k, nchan_inp, st_ivas->nchan_transport, ILD_idx, ILD_q[k] ); +#endif } #ifndef FIX_901_PARAMMC_DEAD_CODE @@ -641,7 +719,11 @@ void ivas_param_mc_enc( /* ICC parameter quantization */ for ( k = 0; k < hParamMC->hMetadataPMC.nbands_coded; k += band_step ) { +#ifdef IVAS_FLOAT_FIXED + ivas_param_mc_quantize_iccs_fx( hParamMC, Cy_sum_fx[k], Cy_sum_e[k], k, nchan_inp, ICC_idx ); +#else ivas_param_mc_quantize_iccs( hParamMC, Cy_sum[k], k, nchan_inp, ICC_idx ); +#endif } /* time domain DMX generation*/ @@ -661,7 +743,66 @@ void ivas_param_mc_enc( set_zero( data_f[ch], input_frame ); +#ifdef IVAS_FLOAT_FIXED +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + Word16 data_fx[L_FRAME48k]; + st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.firState1 = (Word16) floatToFixed( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.firState1_flt, -1 ); + st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.firState2 = (Word16) floatToFixed( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.firState2_flt, -1 ); + + FOR( i = 0; i < NSUBBLOCKS + MAX_TD_DELAY + 1; i++ ) + { + st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.accSubblockNrg[i] = floatToFixed( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.accSubblockNrg_flt[i], 7 ); + } + + FOR( i = 0; i < NSUBBLOCKS + MAX_TD_DELAY; i++ ) + { + st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.subblockNrg[i] = floatToFixed( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.subblockNrg_flt[i], 7 ); + st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.subblockNrgChange[i] = (Word16) floatToFixed( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.subblockNrgChange_flt[i], 7 ); + } + + + FOR( i = 0; i < L_FRAME_MAX / NSUBBLOCKS; i++ ) + { + st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->delayBuffer.buffer[i] = (Word16) floatToFixed( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->delayBuffer.buffer_flt[i], -1 ); + } + + + st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->transientDetector.attackRatioThreshold = (Word16) floatToFixed( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->transientDetector.attackRatioThreshold_flt, 11 ); + + floatToFixed_arr16( data_f[ch], data_fx, -1, input_frame ); + + + st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.facAccSubblockNrg = float_to_fix16( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.facAccSubblockNrg_flt, 15 ); + +#endif + + RunTransientDetection_ivas_fx( data_fx, input_frame, st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet ); + +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + + st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.firState1_flt = fixedToFloat( (Word32) st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.firState1, -1 ); + st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.firState2_flt = fixedToFloat( (Word32) st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.firState2, -1 ); + + FOR( i = 0; i < NSUBBLOCKS + MAX_TD_DELAY; i++ ) + { + st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.subblockNrg_flt[i] = fixedToFloat( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.subblockNrg[i], 7 ); + st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.subblockNrgChange_flt[i] = fixedToFloat( (Word32) st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.subblockNrgChange[i], 7 ); + } + + FOR( i = 0; i < NSUBBLOCKS + MAX_TD_DELAY + 1; i++ ) + { + st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.accSubblockNrg_flt[i] = fixedToFloat( st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->subblockEnergies.accSubblockNrg[i], 7 ); + } + + FOR( i = 0; i < L_FRAME_MAX / NSUBBLOCKS; i++ ) + { + st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->delayBuffer.buffer_flt[i] = fixedToFloat( (Word32) st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet->delayBuffer.buffer[i], -1 ); + } + +#endif +#else RunTransientDetection( data_f[ch], input_frame, st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet ); +#endif } } @@ -1108,7 +1249,7 @@ static void ivas_param_mc_param_est_enc_fx( push_wmops( "param_mc_prm_est" ); /* initializations */ - l_ts = Mpy_32_16_1( input_frame, INV_PARAM_MC_MDFT_NO_SLOTS_FX ); + l_ts = extract_l( Mpy_32_16_1( input_frame, INV_PARAM_MC_MDFT_NO_SLOTS_FX ) ); num_time_slots = PARAM_MC_MDFT_NO_SLOTS; move16(); IF( hParamMC->hMetadataPMC.bAttackPresent ) @@ -1564,7 +1705,7 @@ static void ivas_param_mc_param_est_enc_fx( real_part_fx = Mpy_32_32( real_part_fx, real_part_fx ); imag_part_fx = Mpy_32_32( imag_part_fx, imag_part_fx ); - L_tmp = BASOP_Util_Add_Mant32Exp( real_part_fx, L_shl( real_part_e, 1 ), imag_part_fx, L_shl( imag_part_e, 1 ), &tmp_e ); + L_tmp = BASOP_Util_Add_Mant32Exp( real_part_fx, shl( real_part_e, 1 ), imag_part_fx, shl( imag_part_e, 1 ), &tmp_e ); /* (a-ib)(c+id) = ac + bd + i(ad-bc) */ L_tmp = Sqrt32( L_tmp, &tmp_e ); @@ -1592,7 +1733,7 @@ static void ivas_param_mc_param_est_enc_fx( real_part_fx = Mpy_32_32( real_part_fx, real_part_fx ); imag_part_fx = Mpy_32_32( imag_part_fx, imag_part_fx ); - L_tmp = BASOP_Util_Add_Mant32Exp( real_part_fx, L_shl( real_part_e, 1 ), imag_part_fx, L_shl( imag_part_e, 1 ), &tmp_e ); + L_tmp = BASOP_Util_Add_Mant32Exp( real_part_fx, shl( real_part_e, 1 ), imag_part_fx, shl( imag_part_e, 1 ), &tmp_e ); L_tmp = Sqrt32( L_tmp, &tmp_e ); Cy_sum_fx[cur_param_band][ch_idx1][ch_idx2] = L_tmp; @@ -2224,6 +2365,241 @@ static void ivas_param_mc_enc_find_icc_map( * Quantize the ILD parameters *------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +static void ivas_param_mc_quantize_ilds_fx( + PARAM_MC_ENC_HANDLE hParamMC, /* i/o: Parametric MC encoder handle */ + Word32 Cy_fx[MAX_CICP_CHANNELS][MAX_CICP_CHANNELS], /* i : Covariance matrix of the input */ + Word16 Cy_e[MAX_CICP_CHANNELS][MAX_CICP_CHANNELS], /* i : Covariance matrix of the input */ + Word32 Cx_fx[PARAM_MC_MAX_TRANSPORT_CHANS][PARAM_MC_MAX_TRANSPORT_CHANS], /* i : Covariance matrix of the dmx */ + Word16 Cx_e[PARAM_MC_MAX_TRANSPORT_CHANS][PARAM_MC_MAX_TRANSPORT_CHANS], /* i : Covariance matrix of the dmx */ + const Word16 freq_idx, /* i : frequency index being processed */ + const Word16 nchan_input, /* i : number of input channels */ + const Word16 nchan_transport, /* i : number of transport channels */ + Word16 *ILD_idx_out, /* o : ILD indices */ + Word16 ILD_q[PARAM_MC_SZ_ILD_MAP] /* o : Quanzited ILD matrix */ +) +{ + Word16 i, k; + Word16 Ny; + Word16 num_ilds_to_code; + Word16 ild_map_size; + Word32 Nrg_fx[MAX_CICP_CHANNELS]; + Word16 Nrg_e[MAX_CICP_CHANNELS]; + Word32 ILD_fx[PARAM_MC_SZ_ILD_MAP]; + Word16 ILD_e[PARAM_MC_SZ_ILD_MAP]; + const PARAM_MC_ILD_MAPPING *h_ild_mapping; + Word32 tot_ener_fx, dmx_ener_fx, ener_fac_fx, delta_fac_fx; + Word16 tot_ener_e, dmx_ener_e; + Word16 ILD_idx[PARAM_MC_SZ_ILD_MAP]; + Word32 L_tmp; + Word16 tmp_e; + + push_wmops( "param_mc_prm_q" ); + + /* Initialization */ + set32_fx( Nrg_fx, 0, MAX_CICP_CHANNELS ); + set32_fx( ILD_fx, 0, PARAM_MC_SZ_ILD_MAP ); + + Ny = nchan_input; + move16(); + + h_ild_mapping = hParamMC->hMetadataPMC.ild_mapping_conf; + ild_map_size = hParamMC->hMetadataPMC.ild_mapping_conf->ild_map_size_lfe; + move16(); + IF( GE_16( freq_idx, PARAM_MC_MAX_BAND_LFE ) ) + { + num_ilds_to_code = hParamMC->hMetadataPMC.ild_mapping_conf->ild_map_size_wo_lfe; + move16(); + } + ELSE + { + num_ilds_to_code = hParamMC->hMetadataPMC.ild_mapping_conf->ild_map_size_lfe; + move16(); + } + + /* Downsampling */ + test(); + IF( ( hParamMC->hMetadataPMC.bAttackPresent == 0 ) && NE_16( hParamMC->hMetadataPMC.param_frame_idx, hParamMC->hMetadataPMC.coding_band_mapping[freq_idx] ) ) + { + pop_wmops(); + + return; + } + + /* get ICLDs */ + FOR( k = 0; k < Ny; ++k ) + { + Nrg_fx[k] = Cy_fx[k][k]; + move32(); + Nrg_e[k] = Cy_e[k][k]; + move16(); + } + + /* limit ILDs if DMX energy is lower than sum of channel energies */ + tot_ener_fx = 0; + move32(); + tot_ener_e = 0; + move16(); + dmx_ener_fx = 0; + move32(); + dmx_ener_e = 0; + move16(); + + FOR( k = 0; k < ild_map_size; k++ ) + { + test(); + IF( NE_16( k, hParamMC->lfe_index ) || hParamMC->hMetadataPMC.lfe_on ) + { + tot_ener_fx = BASOP_Util_Add_Mant32Exp( tot_ener_fx, tot_ener_e, Nrg_fx[k], Nrg_e[k], &tot_ener_e ); + } + } + + FOR( k = 0; k < nchan_transport; k++ ) + { + dmx_ener_fx = BASOP_Util_Add_Mant32Exp( dmx_ener_fx, dmx_ener_e, Cx_fx[k][k], Cx_e[k][k], &dmx_ener_e ); + } + /*ener_fac = 10.0f * log10f( ( tot_ener + EPSILON ) / ( dmx_ener + EPSILON ) )*/ + tot_ener_fx = BASOP_Util_Add_Mant32Exp( tot_ener_fx, tot_ener_e, EPSILON_FX, 0, &tot_ener_e ); + dmx_ener_fx = BASOP_Util_Add_Mant32Exp( dmx_ener_fx, dmx_ener_e, EPSILON_FX, 0, &dmx_ener_e ); + L_tmp = L_deposit_h( BASOP_Util_Divide3232_Scale( tot_ener_fx, dmx_ener_fx, &tmp_e ) ); + tmp_e = add( sub( tot_ener_e, dmx_ener_e ), tmp_e ); + ener_fac_fx = BASOP_Util_Log10( L_tmp, tmp_e ); // Q25 + /*10 in Q21 = 1342177280*/ + ener_fac_fx = Mpy_32_32( 1342177280, ener_fac_fx ); // Q25 + Q27 - Q31 = Q21; + + IF( GT_32( ener_fac_fx, PARAM_MC_ENER_LIMIT_INTRAFRAME_FX_Q21 ) ) + { + L_tmp = L_sub( ener_fac_fx, PARAM_MC_ENER_LIMIT_INTRAFRAME_FX_Q21 - ONE_IN_Q21 ); // Q21 + L_tmp = BASOP_Util_Loge( L_tmp, 31 - Q21 ); // Q25 + /*0.3 in Q31 = 644245094*/ + L_tmp = L_sub( L_shr( Mpy_32_32( 644245094, L_tmp ), 4 ), L_sub( ener_fac_fx, PARAM_MC_ENER_LIMIT_INTRAFRAME_FX_Q21 ) ); + /*0.1 in Q31 = 214748365*/ + L_tmp = Mpy_32_32( L_tmp, 214748365 ); + L_tmp = BASOP_util_Pow2( Mpy_32_32( L_tmp, LOG2_10_Q29 ), 31 - 19, &tmp_e ); + + /*v_multc( Nrg, limit_fac, Nrg, num_ilds_to_code );*/ + FOR( i = 0; i < num_ilds_to_code; i++ ) + { + Nrg_fx[i] = Mpy_32_32( Nrg_fx[i], L_tmp ); + move32(); + Nrg_e[i] = add( tmp_e, Nrg_e[i] ); + move16(); + Nrg_fx[i] = BASOP_Util_Add_Mant32Exp( Nrg_fx[i], Nrg_e[i], 0, 0, &Nrg_e[i] ); + move32(); + } + } + + /* limit ILD jumps in non-tranient frames */ + tot_ener_fx = 0; + move32(); + dmx_ener_fx = 0; + move32(); + + FOR( k = 0; k < ild_map_size; k++ ) + { + test(); + IF( NE_16( k, hParamMC->lfe_index ) || hParamMC->hMetadataPMC.lfe_on ) + { + tot_ener_fx = BASOP_Util_Add_Mant32Exp( tot_ener_fx, tot_ener_e, Nrg_fx[k], Nrg_e[k], &tot_ener_e ); + } + } + + FOR( k = 0; k < nchan_transport; k++ ) + { + dmx_ener_fx = BASOP_Util_Add_Mant32Exp( dmx_ener_fx, dmx_ener_e, Cx_fx[k][k], Cx_e[k][k], &dmx_ener_e ); + } + + tot_ener_fx = BASOP_Util_Add_Mant32Exp( tot_ener_fx, tot_ener_e, EPSILON_FX, 0, &tot_ener_e ); + dmx_ener_fx = BASOP_Util_Add_Mant32Exp( dmx_ener_fx, dmx_ener_e, EPSILON_FX, 0, &dmx_ener_e ); + L_tmp = L_deposit_h( BASOP_Util_Divide3232_Scale( tot_ener_fx, dmx_ener_fx, &tmp_e ) ); + tmp_e = add( sub( tot_ener_e, dmx_ener_e ), tmp_e ); + ener_fac_fx = BASOP_Util_Log10( L_tmp, tmp_e ); // Q25 + /*10 in Q21 = 1342177280*/ + ener_fac_fx = Mpy_32_32( 1342177280, ener_fac_fx ); // Q25 + Q27 - Q31 = Q21; + delta_fac_fx = L_sub( ener_fac_fx, hParamMC->ener_fac_fx[freq_idx] ); + + test(); + test(); + IF( !hParamMC->hMetadataPMC.bAttackPresent && GT_32( delta_fac_fx, PARAM_MC_ENER_LIMIT_INTERFRAME_FX_Q21 ) && LT_32( delta_fac_fx, PARAM_MC_ENER_LIMIT_MAX_DELTA_FAC_FX_Q21 ) ) + { + L_tmp = L_sub( delta_fac_fx, PARAM_MC_ENER_LIMIT_INTERFRAME_FX_Q21 - ONE_IN_Q21 ); // Q21 + L_tmp = BASOP_Util_Loge( L_tmp, 31 - Q21 ); // Q25 + /*0.3 in Q31 = 644245094*/ + L_tmp = L_sub( L_shr( Mpy_32_32( 644245094, L_tmp ), 4 ), L_sub( delta_fac_fx, PARAM_MC_ENER_LIMIT_INTERFRAME_FX_Q21 ) ); + /*0.1 in Q31 = 214748365*/ + L_tmp = Mpy_32_32( L_tmp, 214748365 ); + L_tmp = BASOP_util_Pow2( Mpy_32_32( L_tmp, LOG2_10_Q29 ), 31 - 19, &tmp_e ); + + FOR( i = 0; i < num_ilds_to_code; i++ ) + { + Nrg_fx[i] = Mpy_32_32( Nrg_fx[i], L_tmp ); + move32(); + Nrg_e[i] = add( tmp_e, Nrg_e[i] ); + move16(); + Nrg_fx[i] = BASOP_Util_Add_Mant32Exp( Nrg_fx[i], Nrg_e[i], 0, 0, &Nrg_e[i] ); + move32(); + } + + /*10 in Q21 = 1342177280*/ + ener_fac_fx = L_add( ener_fac_fx, Mpy_32_32( 1342177280, BASOP_Util_Log10( L_tmp, tmp_e ) ) ); + } + + hParamMC->ener_fac_fx[freq_idx] = ener_fac_fx; // Q21 + move32(); + + /* update also combined bands ener_fac when in transient frame */ + test(); + if ( hParamMC->hMetadataPMC.bAttackPresent && LT_16( add( freq_idx, 1 ), hParamMC->hMetadataPMC.nbands_coded ) ) + { + hParamMC->ener_fac_fx[freq_idx + 1] = ener_fac_fx; // Q21 + move32(); + } + + FOR( k = 0; k < num_ilds_to_code; ++k ) + { + Word32 ref_ener_fx = 0; + move32(); + Word16 ref_ener_e = 0; + move16(); + Word16 ref_channel_cnt; + Word16 ref_channel_idx; + + FOR( ref_channel_cnt = 0; ref_channel_cnt < h_ild_mapping->num_ref_channels[k]; ref_channel_cnt++ ) + { + ref_channel_idx = h_ild_mapping->ref_channel_idx[k][ref_channel_cnt]; + move16(); + ref_ener_fx = BASOP_Util_Add_Mant32Exp( ref_ener_fx, ref_ener_e, Cx_fx[ref_channel_idx][ref_channel_idx], Cx_e[ref_channel_idx][ref_channel_idx], &ref_ener_e ); + } + ref_ener_fx = Mpy_32_16_1( ref_ener_fx, hParamMC->hMetadataPMC.ild_factors_fx[k] ); + L_tmp = L_deposit_h( BASOP_Util_Divide3232_Scale( Nrg_fx[h_ild_mapping->ild_index[k]], ref_ener_fx, &tmp_e ) ); + tmp_e = add( sub( Nrg_e[h_ild_mapping->ild_index[k]], ref_ener_e ), tmp_e ); + /*10 in Q21 = 1342177280*/ + ILD_fx[k] = Mpy_32_32( 1342177280, BASOP_Util_Log10( L_tmp, tmp_e ) ); // Q21 + move32(); + ILD_e[k] = 31 - 21; + move16(); + hParamMC->prev_ilds_fx[freq_idx][k] = ILD_fx[k]; + move32(); + test(); + IF( hParamMC->hMetadataPMC.bAttackPresent && LT_16( add( freq_idx, 1 ), hParamMC->hMetadataPMC.nbands_coded ) ) + { + hParamMC->prev_ilds_fx[freq_idx + 1][k] = ILD_fx[k]; + move32(); + } + } + + + /* quantize parameters */ + ivas_param_mc_parameter_quantizer_fx( ILD_fx, ILD_e, num_ilds_to_code, hParamMC->hMetadataPMC.ild_coding.quantizer_size, hParamMC->hMetadataPMC.ild_coding.quantizer_fx, Q8, ILD_idx, ILD_q ); + + /* Save current quantized ICLDs */ + Copy( ILD_idx, ILD_idx_out + freq_idx * ild_map_size, num_ilds_to_code ); + + pop_wmops(); + + return; +} +#else static void ivas_param_mc_quantize_ilds( PARAM_MC_ENC_HANDLE hParamMC, /* i/o: Parametric MC encoder handle */ float Cy[MAX_CICP_CHANNELS][MAX_CICP_CHANNELS], /* i : Covariance matrix of the input */ @@ -2369,6 +2745,7 @@ static void ivas_param_mc_quantize_ilds( return; } +#endif /*------------------------------------------------------------------------- @@ -2377,6 +2754,133 @@ static void ivas_param_mc_quantize_ilds( * Quantize the ILD parameters *------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +static void ivas_param_mc_quantize_iccs_fx( + PARAM_MC_ENC_HANDLE hParamMC, /* i/o: Parametric MC encoder handle */ + Word32 Cy_fx[MAX_CICP_CHANNELS][MAX_CICP_CHANNELS], /* i : Covariance matrix of the input */ + Word16 Cy_e[MAX_CICP_CHANNELS][MAX_CICP_CHANNELS], /* i : Covariance matrix of the input */ + const Word16 freq_idx, /* i : frequency index being processed */ + const Word16 nchan_input, /* i : number of input channels */ + Word16 *ICC_idx_out /* o : quantizer indices */ +) +{ + Word16 i, k; + Word16 Ny; + Word16 num_iccs_to_code; + Word16 icc_map_size; + Word16 tmp_map[2]; + Word16 ICC_idx[PARAM_MC_SZ_ICC_MAP]; + + /* Initialization */ + Word32 a_fx; + Word32 Nrg_fx[MAX_CICP_CHANNELS]; + Word16 Nrg_e; + Word32 ICC_vect_fx[PARAM_MC_SZ_ICC_MAP]; + Word16 ICC_vect_e[PARAM_MC_SZ_ICC_MAP]; + Word16 ICC_vect_q_fx[PARAM_MC_SZ_ICC_MAP]; + + set32_fx( Nrg_fx, 0, MAX_CICP_CHANNELS ); + set32_fx( ICC_vect_fx, 0, PARAM_MC_SZ_ICC_MAP ); + set16_fx( ICC_vect_q_fx, 0, PARAM_MC_SZ_ICC_MAP ); + + + Ny = nchan_input; + move16(); + + /* Downsampling */ + test(); + IF( ( hParamMC->hMetadataPMC.bAttackPresent == 0 ) && NE_16( hParamMC->hMetadataPMC.param_frame_idx, hParamMC->hMetadataPMC.coding_band_mapping[freq_idx] ) ) + { + return; + } + + icc_map_size = hParamMC->hMetadataPMC.icc_mapping_conf->icc_map_size_lfe; + move16(); + num_iccs_to_code = icc_map_size; + move16(); + + if ( GE_16( freq_idx, PARAM_MC_MAX_BAND_LFE ) ) + { + num_iccs_to_code = hParamMC->hMetadataPMC.icc_mapping_conf->icc_map_size_wo_lfe; + move16(); + } + + /* Get ICC matrix from Cy */ + FOR( k = 0; k < Ny; ++k ) + { + Nrg_fx[k] = Cy_fx[k][k]; + move32(); + Nrg_e = Cy_e[k][k]; + move16(); + a_fx = ISqrt32( L_add( Nrg_fx[k], EPSILLON_FX ), &Nrg_e ); + + FOR( i = k; i < Ny; ++i ) + { + Cy_fx[k][i] = Mpy_32_32( Cy_fx[k][i], a_fx ); + move32(); + Cy_fx[k][i] = BASOP_Util_Add_Mant32Exp( Cy_fx[k][i], add( Cy_e[k][i], Nrg_e ), 0, 0, &Cy_e[k][i] ); + move32(); + } + + FOR( i = 0; i <= k; i++ ) + { + Cy_fx[i][k] = Mpy_32_32( Cy_fx[i][k], a_fx ); + move32(); + Cy_fx[i][k] = BASOP_Util_Add_Mant32Exp( Cy_fx[i][k], add( Cy_e[i][k], Nrg_e ), 0, 0, &Cy_e[i][k] ); + move32(); + } + } + + /* set ICCs for zero channels to 1 to avoid artifacts in the decoded signal */ + FOR( k = 0; k < Ny; ++k ) + { + IF( Nrg_fx[k] == 0 ) + { + FOR( i = k; i < Ny; ++i ) + { + Cy_fx[k][i] = ONE_IN_Q31; + move32(); + Cy_e[k][i] = 0; + move16(); + } + + FOR( i = 0; i <= k; ++i ) + { + Cy_fx[i][k] = ONE_IN_Q31; + move32(); + Cy_e[i][k] = 0; + move16(); + } + } + } + + /* Reduce set of parameters and quantize them */ + FOR( k = 0; k < num_iccs_to_code; ++k ) + { +#ifndef FIX_901_PARAMMC_DEAD_CODE + tmp_map[0] = hParamMC->hMetadataPMC.icc_mapping[hParamMC->hMetadataPMC.param_frame_idx][k][0]; + tmp_map[1] = hParamMC->hMetadataPMC.icc_mapping[hParamMC->hMetadataPMC.param_frame_idx][k][1]; +#else + tmp_map[0] = hParamMC->hMetadataPMC.icc_mapping_conf->icc_mapping[k][0]; + move16(); + tmp_map[1] = hParamMC->hMetadataPMC.icc_mapping_conf->icc_mapping[k][1]; + move16(); +#endif + ICC_vect_fx[k] = Cy_fx[tmp_map[0]][tmp_map[1]]; + move32(); + ICC_vect_e[k] = Cy_e[tmp_map[0]][tmp_map[1]]; + move16(); + } + + /* Quantization */ + ivas_param_mc_parameter_quantizer_fx( ICC_vect_fx, ICC_vect_e, num_iccs_to_code, hParamMC->hMetadataPMC.icc_coding.quantizer_size, hParamMC->hMetadataPMC.icc_coding.quantizer_fx, Q15, ICC_idx, ICC_vect_q_fx ); + + /* Save current quantized ICCs */ + Copy( ICC_idx, ICC_idx_out + freq_idx * icc_map_size, num_iccs_to_code ); + + return; +} +#else static void ivas_param_mc_quantize_iccs( PARAM_MC_ENC_HANDLE hParamMC, /* i/o: Parametric MC encoder handle */ float Cy[MAX_CICP_CHANNELS][MAX_CICP_CHANNELS], /* i : Covariance matrix of the input */ @@ -2472,6 +2976,7 @@ static void ivas_param_mc_quantize_iccs( return; } +#endif /*------------------------------------------------------------------------- @@ -2480,6 +2985,60 @@ static void ivas_param_mc_quantize_iccs( * Parameter Quantization *------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +static void ivas_param_mc_parameter_quantizer_fx( + const Word32 *x, /* i : input sequence */ + const Word16 *x_e, /* i : input sequence */ + const Word16 L, /* i : input length */ + const Word16 sz_quantizer, /* i : quantizer size */ + const Word16 *quantizer_fx, /* i : quantizer table Q_quant */ + const Word16 Q_quant, /* i : quantizer table */ + Word16 *quant_idx, /* o : quant indices */ + Word16 *y_fx /* o : output sequence Q_quant */ +) +{ + Word16 idx, i; + Word16 idx_min; + Word32 tmp_min_fx; + Word16 tmp_min_e; + Word32 tmp_val; + Word16 tmp_e; + + set16_fx( y_fx, 0, L ); + idx_min = 0; + move16(); + + FOR( idx = 0; idx < L; ++idx ) + { + tmp_min_fx = 1000; + move32(); + tmp_min_e = 31; + move16(); + + FOR( i = 0; i < sz_quantizer; ++i ) + { + tmp_val = BASOP_Util_Add_Mant32Exp( x[idx], x_e[idx], L_negate( L_deposit_h( quantizer_fx[i] ) ), sub( 15, Q_quant ), &tmp_e ); + tmp_val = L_abs( tmp_val ); + IF( EQ_16( BASOP_Util_Cmp_Mant32Exp( tmp_val, tmp_e, tmp_min_fx, tmp_min_e ), -1 ) ) + { + tmp_min_fx = tmp_val; + move32(); + tmp_min_e = tmp_e; + move16(); + idx_min = i; + move16(); + } + } + + y_fx[idx] = quantizer_fx[idx_min]; + move32(); + quant_idx[idx] = idx_min; + move16(); + } + + return; +} +#else static void ivas_param_mc_parameter_quantizer( const float *x, /* i : input sequence */ const int16_t L, /* i : input length */ @@ -2514,6 +3073,7 @@ static void ivas_param_mc_parameter_quantizer( return; } +#endif /*------------------------------------------------------------------------- diff --git a/lib_enc/ivas_omasa_enc.c b/lib_enc/ivas_omasa_enc.c index 9083a5a08..fbd04aa2a 100644 --- a/lib_enc/ivas_omasa_enc.c +++ b/lib_enc/ivas_omasa_enc.c @@ -760,8 +760,68 @@ void ivas_omasa_enc( { n_bands_orig = hMasa->config.numCodingBands; hMasa->config.numCodingBands = MASA_FREQUENCY_BANDS; +#ifdef IVAS_FLOAT_FIXED +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + Word16 numCodingBands = hMasa->config.numCodingBands; + Word16 numDirections = hMasa->config.numberOfDirections; + Word16 numSf = hMasa->config.joinedSubframes == TRUE ? 1 : MAX_PARAM_SPATIAL_SUBFRAMES; + Word16 computeCoherence = hMasa->config.useCoherence && hMasa->config.coherencePresent; + MASA_METADATA_HANDLE hMeta; + hMeta = &( hMasa->masaMetadata ); + for ( i = 0; i < numDirections; i++ ) + { + for ( j = 0; j < numSf; j++ ) + { + for ( int k = 0; k < hMasa->config.numCodingBands; k++ ) + { + hMeta->directional_meta[i].energy_ratio_fx[j][k] = floatToFixed( hMeta->directional_meta[i].energy_ratio[j][k], Q30 ); + hMeta->directional_meta[i].azimuth_fx[j][k] = floatToFixed( hMeta->directional_meta[i].azimuth[j][k], Q22 ); + hMeta->directional_meta[i].elevation_fx[j][k] = floatToFixed( hMeta->directional_meta[i].elevation[j][k], Q22 ); + } + } + } + /* Combine directions on the remaining bands */ + for ( i = 0; i < hMasa->config.numCodingBands; i++ ) + { + for ( j = 0; j < numSf; j++ ) + { + hMeta->directional_meta[0].spread_coherence_fx[j][i] = (Word16) floatToFixed( hMeta->directional_meta[0].spread_coherence[j][i], Q15 ); + hMeta->directional_meta[1].spread_coherence_fx[j][i] = (Word16) floatToFixed( hMeta->directional_meta[1].spread_coherence[j][i], Q15 ); + hMeta->common_meta.surround_coherence_fx[j][i] = (Word16) floatToFixed( hMeta->common_meta.surround_coherence[j][i], Q14 ); + } + } + + /* Estimate the importance of having two directions instead of one */ + for ( i = 0; i < MASA_FREQUENCY_BANDS; i++ ) + { + hMasa->data.importanceWeight_fx[i] = floatToFixed( hMasa->data.importanceWeight[i], Q30 ); + } +#endif + ivas_masa_combine_directions_fx( hMasa ); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + for ( i = 0; i < numCodingBands; i++ ) + { + if ( hMasa->data.twoDirBands[i] == 0 ) + { + for ( j = 0; j < numSf; j++ ) + { + hMeta->directional_meta[0].azimuth[j][i] = fixedToFloat( hMeta->directional_meta[0].azimuth_fx[j][i], Q22 ); + hMeta->directional_meta[0].elevation[j][i] = fixedToFloat( hMeta->directional_meta[0].elevation_fx[j][i], Q22 ); + if ( computeCoherence ) + { + hMeta->directional_meta[0].spread_coherence[j][i] = fixedToFloat( hMeta->directional_meta[0].spread_coherence_fx[j][i], Q15 ); + hMeta->common_meta.surround_coherence[j][i] = fixedToFloat( hMeta->common_meta.surround_coherence_fx[j][i], Q14 ); + } + hMeta->directional_meta[0].energy_ratio[j][i] = fixedToFloat( hMeta->directional_meta[0].energy_ratio_fx[j][i], Q30 ); + hMeta->directional_meta[1].energy_ratio[j][i] = fixedToFloat( hMeta->directional_meta[1].energy_ratio_fx[j][i], Q30 ); + } + } + } +#endif +#else ivas_masa_combine_directions( hMasa ); +#endif hMasa->config.numCodingBands = (int8_t) n_bands_orig; } diff --git a/lib_enc/ivas_qmetadata_enc.c b/lib_enc/ivas_qmetadata_enc.c index bdea2aeb6..86b41c04d 100644 --- a/lib_enc/ivas_qmetadata_enc.c +++ b/lib_enc/ivas_qmetadata_enc.c @@ -82,11 +82,40 @@ static Word16 ivas_qmetadata_entropy_encode_df_ratio_fx( static int16_t ivas_qmetadata_entropy_encode_df_ratio( BSTR_ENC_HANDLE hMetaData, IVAS_QDIRECTION *q_direction, int16_t *df_ratio_bits ); #endif +#ifdef IVAS_FLOAT_FIXED +static Word16 ivas_qmetadata_entropy_encode_dir_fx( + BSTR_ENC_HANDLE hMetaData, + IVAS_QDIRECTION *q_direction, + const UWord16 diffuseness_index_max_ec_frame, + const Word16 nbands, + const Word16 start_band, + const Word16 direction_bits_raw, + Word16 max_bits, + const Word16 hrmasa_flag ); +#else static int16_t ivas_qmetadata_entropy_encode_dir( BSTR_ENC_HANDLE hMetaData, IVAS_QDIRECTION *q_direction, const uint16_t diffuseness_index_max_ec_frame, const int16_t nbands, const int16_t start_band, const int16_t direction_bits_raw, int16_t max_bits, const int16_t hrmasa_flag ); +#endif +#ifdef IVAS_FLOAT_FIXED +static Word16 ivas_qmetadata_raw_encode_dir_fx( + BSTR_ENC_HANDLE hMetaData, + IVAS_QDIRECTION *q_direction, + const Word16 nbands, + const Word16 start_band ); +#else static int16_t ivas_qmetadata_raw_encode_dir( BSTR_ENC_HANDLE hMetaData, IVAS_QDIRECTION *q_direction, const int16_t nbands, const int16_t start_band ); +#endif + +#ifdef IVAS_FLOAT_FIXED +static Word16 ivas_qmetadata_get_optimal_gr_param_fx( + UWord16 *unsigned_data, + const Word16 count, + const Word16 gr_param_count, + Word16 *opt_gr_size ); +#else static int16_t ivas_qmetadata_get_optimal_gr_param( uint16_t *unsigned_data, const int16_t count, const int16_t gr_param_count, int16_t *opt_gr_size ); +#endif #ifdef IVAS_FLOAT_FIXED Word16 ivas_qmetadata_encode_extended_gr_length( const UWord16 value, const UWord16 alphabet_size, const Word16 gr_param ); @@ -102,9 +131,23 @@ static int16_t ivas_qmetadata_encode_quasi_uniform_length( const uint16_t value, static void ivas_qmetadata_encode_quasi_uniform( BSTR_ENC_HANDLE hMetaData, const uint16_t value, const uint16_t alphabet_size ); #endif +#ifdef IVAS_FLOAT_FIXED +static Word16 ivas_qmetadata_reorder_elevation_index_fx( + const Word16 elevation_index, + const Word16 avg_elevation_index, + const Word16 elevation_alphabet ); +#else static int16_t ivas_qmetadata_reorder_elevation_index( const int16_t elevation_index, const int16_t avg_elevation_index, const int16_t elevation_alphabet ); +#endif +#ifdef IVAS_FLOAT_FIXED +static Word16 ivas_qmetadata_reorder_azimuth_index_fx( + const Word16 azimuth_index, + const Word16 avg_azimuth_index, + const Word16 azimuth_alphabet ); +#else static int16_t ivas_qmetadata_reorder_azimuth_index( const int16_t azimuth_index, const int16_t avg_azimuth_index, const int16_t azimuth_alphabet ); +#endif static ivas_error requantize_direction_EC_3( int16_t *extra_bits, IVAS_QDIRECTION *q_direction, const int16_t coding_subbands, BSTR_ENC_HANDLE hMetaData, float elevation_orig[MASA_MAXIMUM_CODING_SUBBANDS][MAX_PARAM_SPATIAL_SUBFRAMES], float azimuth_orig[MASA_MAXIMUM_CODING_SUBBANDS][MAX_PARAM_SPATIAL_SUBFRAMES], int16_t *ind_order ); @@ -260,10 +303,10 @@ static int16_t find_optimal_GR_orders( const int16_t *q_idx, const int16_t len, *-----------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED -ivas_error ivas_qmetadata_enc_encode( +ivas_error ivas_qmetadata_enc_encode_fx( BSTR_ENC_HANDLE hMetaData, /* i/o: metadata bitstream handle */ IVAS_QMETADATA *hQMetaData, /* i/o: metadata handle */ - const int16_t hodirac_flag /* i : flag to indicate HO-DirAC mode */ + const Word16 hodirac_flag /* i : flag to indicate HO-DirAC mode */ ) { Word16 i, bit_pos_start, bit_pos_start_coh; @@ -294,25 +337,32 @@ ivas_error ivas_qmetadata_enc_encode( ivas_error error; error = IVAS_ERR_OK; - + move32(); /* Save initial position in bitstream */ bit_pos_0 = hMetaData->nb_bits_tot; + move16(); bit_pos_start = bit_pos_0; + move16(); ndirections = hQMetaData->no_directions; + move16(); extra_bits = 0; + move16(); /* Check if coherence should be encoded */ all_coherence_zero = 1; + move16(); bits_no_dirs_coh = 0; + move16(); IF( hQMetaData->coherence_flag ) { all_coherence_zero = hQMetaData->all_coherence_zero; + move16(); push_next_indice( hMetaData, all_coherence_zero, 1 ); /* signal coherence */ - bits_no_dirs_coh += 1; + bits_no_dirs_coh = add( bits_no_dirs_coh, 1 ); } IF( GT_16( ndirections, 1 ) ) @@ -321,35 +371,29 @@ ivas_error ivas_qmetadata_enc_encode( IF( !hodirac_flag ) { ivas_qmetadata_reorder_2dir_bands_fx( hQMetaData ); -#if 0 // def IVAS_FLOAT_FIXED_CONVERSIONS - for (i = 0; i < ndirections; i++) { - for (int j = hQMetaData->q_direction[i].cfg.start_band; j < hQMetaData->q_direction[i].cfg.nbands; ++j) - { - floatToFixed_arrL(hQMetaData->q_direction[i].band_data[j].energy_ratio, hQMetaData->q_direction[i].band_data[j].energy_ratio_fx, Q30, MAX_PARAM_SPATIAL_SUBFRAMES); - } - } -#endif } d = 0; + move16(); FOR( i = hQMetaData->q_direction[1].cfg.start_band; i < hQMetaData->q_direction[1].cfg.nbands; i++ ) { - IF( hQMetaData->twoDirBands[i] == 1 ) + IF( EQ_16( hQMetaData->twoDirBands[i], 1 ) ) { Copy32( hQMetaData->q_direction[1].band_data[i].azimuth_fx, hQMetaData->q_direction[1].band_data[d].azimuth_fx, hQMetaData->q_direction[1].cfg.nblocks ); Copy32( hQMetaData->q_direction[1].band_data[i].elevation_fx, hQMetaData->q_direction[1].band_data[d].elevation_fx, hQMetaData->q_direction[1].cfg.nblocks ); Copy32( hQMetaData->q_direction[1].band_data[i].energy_ratio_fx, hQMetaData->q_direction[1].band_data[d].energy_ratio_fx, hQMetaData->q_direction[1].cfg.nblocks ); dir2_bands[d] = i; + move16(); IF( hQMetaData->coherence_flag ) { mvc2c( hQMetaData->q_direction[1].coherence_band_data[i].spread_coherence, hQMetaData->q_direction[1].coherence_band_data[d].spread_coherence, hQMetaData->q_direction[1].cfg.nblocks ); } - d++; + d = add( d, 1 ); } } - bits_no_dirs_coh += write_2dir_info( hMetaData, hQMetaData->twoDirBands, hQMetaData->q_direction[0].cfg.nbands, hQMetaData->numTwoDirBands ); + bits_no_dirs_coh = add( bits_no_dirs_coh, write_2dir_info( hMetaData, hQMetaData->twoDirBands, hQMetaData->q_direction[0].cfg.nbands, hQMetaData->numTwoDirBands ) ); FOR( i = d; i < hQMetaData->q_direction[0].cfg.nbands; i++ ) { @@ -357,33 +401,38 @@ ivas_error ivas_qmetadata_enc_encode( } hQMetaData->q_direction[1].cfg.nbands = hQMetaData->numTwoDirBands; + move16(); } /*Quantization of the Diffuseness */ ivas_qmetadata_quantize_diffuseness_nrg_ratios_fx( hQMetaData, bits_dir_raw_pre, bits_diff, dfRatio_bits, hodirac_flag ); bits_diff_sum = 0; + move16(); // TODO bits_diff[0] = ivas_qmetadata_entropy_encode_diffuseness_fx( hMetaData, &( hQMetaData->q_direction[0] ), &diffuseness_index_max_ec_frame_pre[0] ); - bits_diff_sum += bits_diff[0]; + move16(); + bits_diff_sum = add( bits_diff_sum, bits_diff[0] ); IF( EQ_16( ndirections, 2 ) ) { bits_diff[1] = ivas_qmetadata_entropy_encode_df_ratio_fx( hMetaData, &( hQMetaData->q_direction[1] ), dfRatio_bits ); - bits_diff_sum += bits_diff[1]; + move16(); + bits_diff_sum = add( bits_diff_sum, bits_diff[1] ); } /* 2dir energy ratio encoding reuses index memory. Now that diffRatio and dFRatio have been encoded, * we retrieve index_dirRatio1Inv and index_dirRatio1Inv for further parameter encoding. This is * necessary only for bands that have two concurrent directions. */ - IF( hQMetaData->no_directions == 2 ) + IF( EQ_16( hQMetaData->no_directions, 2 ) ) { Word16 j, k, dir2band, index_dirRatio1Inv, index_dirRatio2Inv; dir2band = 0; + move16(); FOR( j = hQMetaData->q_direction[0].cfg.start_band; j < hQMetaData->q_direction[0].cfg.nbands; ++j ) { - IF( hQMetaData->twoDirBands[j] == 1 ) + IF( EQ_16( hQMetaData->twoDirBands[j], 1 ) ) { index_dirRatio1Inv = masa_sq_fx( L_sub( ONE_IN_Q30, hQMetaData->q_direction[0].band_data[j].energy_ratio_fx[0] ), diffuseness_thresholds_fx, DIRAC_DIFFUSE_LEVELS ); index_dirRatio2Inv = masa_sq_fx( L_sub( ONE_IN_Q30, hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_fx[0] ), diffuseness_thresholds_fx, DIRAC_DIFFUSE_LEVELS ); @@ -391,67 +440,68 @@ ivas_error ivas_qmetadata_enc_encode( FOR( k = 0; k < hQMetaData->q_direction[0].cfg.nblocks; k++ ) { hQMetaData->q_direction[0].band_data[j].energy_ratio_index[k] = index_dirRatio1Inv; + move16(); } FOR( k = 0; k < hQMetaData->q_direction[1].cfg.nblocks; k++ ) { hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_index[k] = index_dirRatio2Inv; + move16(); } - dir2band++; + dir2band = add( dir2band, 1 ); } } } -#if 0 // def IVAS_FLOAT_FIXED_CONVERSIONS - for (i = 0; i < ndirections; i++) { - for (int j = hQMetaData->q_direction[i].cfg.start_band; j < hQMetaData->q_direction[i].cfg.nbands; ++j) - { - fixedToFloat_arrL(hQMetaData->q_direction[i].band_data[j].energy_ratio_fx, hQMetaData->q_direction[i].band_data[j].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES); - } - } -#endif /* Encode surround coherence */ IF( EQ_16( ndirections, 2 ) ) { no_TF = add( imult1616( hQMetaData->q_direction[0].cfg.nbands, hQMetaData->q_direction[0].cfg.nblocks ), imult1616( hQMetaData->q_direction[1].cfg.nbands, hQMetaData->q_direction[1].cfg.nblocks ) ); - IF( EQ_16( all_coherence_zero, 0 ) && ( hQMetaData->metadata_max_bits - bits_no_dirs_coh - ( ( 43 * no_TF ) / 10 ) - sum_s( bits_diff, ndirections ) >= MASA_MIN_BITS_SURR_COH ) ) + test(); + IF( EQ_16( all_coherence_zero, 0 ) && GE_16( sub( sub( sub( hQMetaData->metadata_max_bits, bits_no_dirs_coh ), idiv1616( imult1616( 43, no_TF ), 10 ) ), sum16_fx( bits_diff, ndirections ) ), MASA_MIN_BITS_SURR_COH ) ) { bits_surround_coh = encode_surround_coherence_fx( hQMetaData, hMetaData ); } ELSE { bits_surround_coh = 0; + move16(); FOR( i = 0; i < hQMetaData->q_direction[0].cfg.nbands; i++ ) { IF( hQMetaData->surcoh_band_data != NULL ) { - set_c( (int8_t *) hQMetaData->surcoh_band_data[i].surround_coherence, 0, hQMetaData->q_direction[0].cfg.nblocks ); + set8_fx( (Word8 *) hQMetaData->surcoh_band_data[i].surround_coherence, 0, hQMetaData->q_direction[0].cfg.nblocks ); } } } - bits_no_dirs_coh += bits_surround_coh; - total_bits_1dir = ( ( hQMetaData->metadata_max_bits - bits_no_dirs_coh ) * hQMetaData->q_direction[0].cfg.nbands * hQMetaData->q_direction[0].cfg.nblocks ) / no_TF; + bits_no_dirs_coh = add( bits_no_dirs_coh, bits_surround_coh ); + // total_bits_1dir = ( ( hQMetaData->metadata_max_bits - bits_no_dirs_coh ) * hQMetaData->q_direction[0].cfg.nbands * hQMetaData->q_direction[0].cfg.nblocks ) / no_TF; + Word32 tmp_quo, tmp_mod; + iDiv_and_mod_32( imult3216( L_mult0( sub( hQMetaData->metadata_max_bits, bits_no_dirs_coh ), hQMetaData->q_direction[0].cfg.nbands ), hQMetaData->q_direction[0].cfg.nblocks ), no_TF, &tmp_quo, &tmp_mod, 0 ); + total_bits_1dir = extract_l( tmp_quo ); } ELSE { - no_TF = hQMetaData->q_direction[0].cfg.nbands * hQMetaData->q_direction[0].cfg.nblocks; - IF( EQ_16( all_coherence_zero, 0 ) && ( hQMetaData->metadata_max_bits - bits_no_dirs_coh - ( ( 43 * no_TF ) / 10 ) - bits_diff[0] >= MASA_MIN_BITS_SURR_COH ) ) + no_TF = imult1616( hQMetaData->q_direction[0].cfg.nbands, hQMetaData->q_direction[0].cfg.nblocks ); + test(); + IF( EQ_16( all_coherence_zero, 0 ) && GE_16( sub( sub( sub( hQMetaData->metadata_max_bits, bits_no_dirs_coh ), idiv1616( imult1616( 43, no_TF ), 10 ) ), bits_diff[0] ), MASA_MIN_BITS_SURR_COH ) ) { bits_surround_coh = encode_surround_coherence_fx( hQMetaData, hMetaData ); } ELSE { bits_surround_coh = 0; + move16(); FOR( i = 0; i < hQMetaData->q_direction[0].cfg.nbands; i++ ) { IF( hQMetaData->surcoh_band_data != NULL ) { - set_c( (int8_t *) hQMetaData->surcoh_band_data[i].surround_coherence, 0, hQMetaData->q_direction[0].cfg.nblocks ); + set8_fx( (Word8 *) hQMetaData->surcoh_band_data[i].surround_coherence, 0, hQMetaData->q_direction[0].cfg.nblocks ); } } } - total_bits_1dir = hQMetaData->metadata_max_bits - bits_no_dirs_coh - bits_surround_coh; + total_bits_1dir = sub( sub( hQMetaData->metadata_max_bits, bits_no_dirs_coh ), bits_surround_coh ); } /* Loop over number of directions*/ @@ -465,153 +515,154 @@ ivas_error ivas_qmetadata_enc_encode( } nbands = q_direction->cfg.nbands; + move16(); nblocks = q_direction->cfg.nblocks; + move16(); start_band = q_direction->cfg.start_band; + move16(); diffuseness_index_max_ec_frame = diffuseness_index_max_ec_frame_pre[0]; + move16(); bits_dir_raw = bits_dir_raw_pre[d]; + move16(); /* This sets bit budget correctly for the second direction */ IF( EQ_16( d, 0 ) ) { bits_diff[d] = bits_diff_sum; + move16(); } ELSE { bits_diff[d] = 0; + move16(); } - bits_signaling[d] = 0; + move16(); /*Coherence */ bits_coherence[d] = 0; + move16(); bit_pos_start_coh = hMetaData->nb_bits_tot; + move16(); - IF( EQ_16( all_coherence_zero, 0 ) ) + IF( all_coherence_zero == 0 ) { bits_coherence[d] = ivas_qmetadata_quantize_coherence_fx( hQMetaData, d, all_coherence_zero, hMetaData, 0, &indice_coherence, 0 ); move16(); } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( int j = hQMetaData->q_direction[0].cfg.start_band; j < hQMetaData->q_direction[0].cfg.nbands; ++j ) - { - fixedToFloat_arrL( hQMetaData->q_direction[d].band_data[j].azimuth_fx, hQMetaData->q_direction[d].band_data[j].azimuth, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - fixedToFloat_arrL( hQMetaData->q_direction[d].band_data[j].elevation_fx, hQMetaData->q_direction[d].band_data[j].elevation, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - } -#endif - - IF( q_direction->cfg.mc_ls_setup == MC_LS_SETUP_5_1 || q_direction->cfg.mc_ls_setup == MC_LS_SETUP_7_1 ) + test(); + IF( EQ_32( q_direction->cfg.mc_ls_setup, MC_LS_SETUP_5_1 ) || EQ_32( q_direction->cfg.mc_ls_setup, MC_LS_SETUP_7_1 ) ) { q_direction->not_in_2D = 0; + move16(); /* Quantize directions*/ // TODO : Remove azimuth_orig_flt and elevation_orig_flt once full fixed point - quantize_direction_frame2D( q_direction, azimuth_orig_flt, elevation_orig_flt ); + quantize_direction_frame2D_fx( q_direction, azimuth_orig, elevation_orig ); } ELSE { -#ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = q_direction->cfg.start_band; i < q_direction->cfg.nbands; i++ ) - { - for ( Word16 j = 0; j < q_direction->cfg.nblocks; j++ ) - { - q_direction->band_data[i].elevation_fx[j] = float_to_fix( q_direction->band_data[i].elevation[j], Q22 ); - q_direction->band_data[i].azimuth_fx[j] = float_to_fix( q_direction->band_data[i].azimuth[j], Q22 ); - } - } -#endif // IVAS_FLOAT_FIXED_CONVERSIONS /* Quantize directions*/ quantize_direction_frame_fx( q_direction, azimuth_orig, elevation_orig, 0 ); - -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = q_direction->cfg.start_band; i < q_direction->cfg.nbands; i++ ) - { - for ( Word16 j = 0; j < q_direction->cfg.nblocks; j++ ) - { - azimuth_orig_flt[i][j] = fix_to_float( azimuth_orig[i][j], Q22 ); - elevation_orig_flt[i][j] = fix_to_float( elevation_orig[i][j], Q22 ); - q_direction->band_data[i].elevation[j] = fix_to_float( q_direction->band_data[i].elevation_fx[j], Q22 ); - q_direction->band_data[i].azimuth[j] = fix_to_float( q_direction->band_data[i].azimuth_fx[j], Q22 ); - } - } -#endif // IVAS_FLOAT_FIXED_CONVERSIONS -#else - /* Quantize directions*/ - quantize_direction_frame( q_direction, azimuth_orig_flt, elevation_orig_flt, 0 ); -#endif // IVAS_FLOAT_FIXED } /* Signalling 2D*/ push_next_indice( hMetaData, ( q_direction->not_in_2D > 0 ), 1 ); /*2D flag*/ bits_signaling[d] = 1; + move16(); /* Save state of metadata bitstream buffer after writing energy ratios, number of dirs and save space for coherence*/ bit_pos_start = hMetaData->nb_bits_tot; + move16(); next_ind_start = hMetaData->nb_ind_tot; + move16(); /* Encode quantized directions with EC frame-wise*/ - IF( LE_16( ( total_bits_1dir + bits_surround_coh ), hQMetaData->qmetadata_max_bit_req ) ) + IF( LE_16( add( total_bits_1dir, bits_surround_coh ), hQMetaData->qmetadata_max_bit_req ) ) { push_next_indice( hMetaData, 0, 1 ); /*Write 1 bit to signal EC frame-wise (EC1)*/ - bits_signaling[d]++; + bits_signaling[d] = add( bits_signaling[d], 1 ); + move16(); } next_ind_raw_flag = hMetaData->nb_ind_tot; + move16(); push_next_indice( hMetaData, 0, 1 ); /* Raw coding flag*/ - bits_dir_bands[0] = ivas_qmetadata_raw_encode_dir( NULL, q_direction, q_direction->cfg.nbands, q_direction->cfg.start_band ); + bits_dir_bands[0] = ivas_qmetadata_raw_encode_dir_fx( NULL, q_direction, q_direction->cfg.nbands, q_direction->cfg.start_band ); + move16(); - reduce_bits = hQMetaData->is_masa_ivas_format ? ( total_bits_1dir - ( bits_diff[d] + bits_coherence[d] + bits_signaling[d] ) - 1 ) : MASA_MAX_BITS; - bits_ec = ivas_qmetadata_entropy_encode_dir( hMetaData, q_direction, diffuseness_index_max_ec_frame, q_direction->cfg.nbands, q_direction->cfg.start_band, bits_dir_bands[0], reduce_bits, 0 ); + // reduce_bits = hQMetaData->is_masa_ivas_format ? ( total_bits_1dir - ( bits_diff[d] + bits_coherence[d] + bits_signaling[d] ) - 1 ) : MASA_MAX_BITS; + IF( hQMetaData->is_masa_ivas_format ) + { + reduce_bits = sub( sub( total_bits_1dir, add( add( bits_diff[d], bits_coherence[d] ), bits_signaling[d] ) ), 1 ); + } + ELSE + { + reduce_bits = MASA_MAX_BITS; + move16(); + } + bits_ec = ivas_qmetadata_entropy_encode_dir_fx( hMetaData, q_direction, diffuseness_index_max_ec_frame, q_direction->cfg.nbands, q_direction->cfg.start_band, bits_dir_bands[0], reduce_bits, 0 ); - IF( LT_16( bits_ec, 0 ) ) + IF( bits_ec < 0 ) { hMetaData->ind_list[next_ind_raw_flag].value = 1; /*rewrite flag*/ - bits_ec = ivas_qmetadata_raw_encode_dir( hMetaData, q_direction, q_direction->cfg.nbands, q_direction->cfg.start_band ); + move16(); + bits_ec = ivas_qmetadata_raw_encode_dir_fx( hMetaData, q_direction, q_direction->cfg.nbands, q_direction->cfg.start_band ); } - bits_dir[d] = bits_ec + 1; - extra_bits = hQMetaData->metadata_max_bits - ( hMetaData->nb_bits_tot - bit_pos_0 ); + bits_dir[d] = add( bits_ec, 1 ); + move16(); + extra_bits = sub( hQMetaData->metadata_max_bits, sub( hMetaData->nb_bits_tot, bit_pos_0 ) ); /* Encode quantized directions with EC band-wise */ - IF( LE_16( ( total_bits_1dir + bits_surround_coh ), hQMetaData->qmetadata_max_bit_req ) && GT_16( ( bits_dir[d] + bits_diff[d] + bits_coherence[d] + bits_signaling[d] ), total_bits_1dir ) && GT_16( q_direction->cfg.nblocks, 1 ) ) + test(); + test(); + IF( LE_16( add( total_bits_1dir, bits_surround_coh ), hQMetaData->qmetadata_max_bit_req ) && GT_16( add( add( add( bits_dir[d], bits_diff[d] ), bits_coherence[d] ), bits_signaling[d] ), total_bits_1dir ) && GT_16( q_direction->cfg.nblocks, 1 ) ) { - restore_metadata_buffer( hMetaData, next_ind_start, bit_pos_start ); + restore_metadata_buffer_fx( hMetaData, next_ind_start, bit_pos_start ); /* Write signaling */ push_next_indice( hMetaData, 1, 1 ); /*Write 1 bit to signal no EC frame-wise (EC1)*/ push_next_indice( hMetaData, 0, 1 ); /*Write 1 bit to signal EC band-wise (EC2)*/ bits_signaling[d] = 3; + move16(); /* Write raw flags */ next_ind_raw_flag = hMetaData->nb_ind_tot; + move16(); FOR( i = start_band; i < nbands; i++ ) { push_next_indice( hMetaData, 0, 1 ); /* Raw coding flag*/ } bits_dir[d] = 0; - diff_bits = bits_diff[d] + bits_coherence[d] + bits_signaling[d] - total_bits_1dir; + move16(); + diff_bits = sub( add( add( bits_diff[d], bits_coherence[d] ), bits_signaling[d] ), total_bits_1dir ); FOR( i = start_band; i < nbands; i++ ) { - bits_dir_bands[i] = ivas_qmetadata_raw_encode_dir( NULL, q_direction, i + 1, i ); + bits_dir_bands[i] = ivas_qmetadata_raw_encode_dir_fx( NULL, q_direction, add( i, 1 ), i ); + move16(); /* Write ec bits */ - bits_ec = ivas_qmetadata_entropy_encode_dir( hMetaData, q_direction, diffuseness_index_max_ec_frame, i + 1, i, bits_dir_bands[i], MASA_MAX_BITS, 0 ); + bits_ec = ivas_qmetadata_entropy_encode_dir_fx( hMetaData, q_direction, diffuseness_index_max_ec_frame, add( i, 1 ), i, bits_dir_bands[i], MASA_MAX_BITS, 0 ); - IF( GE_16( bits_ec, 0 ) ) + IF( bits_ec >= 0 ) { bits_dir_bands[i] = bits_ec; + move16(); raw_flag[i] = 0; + move16(); } ELSE { raw_flag[i] = 1; + move16(); } - diff_bits += bits_dir_bands[i] + 1; + diff_bits = add( diff_bits, add( bits_dir_bands[i], 1 ) ); } - small_requantize_direction_frame( q_direction, azimuth_orig_flt, elevation_orig_flt, raw_flag, bits_dir_bands, &diff_bits ); + small_requantize_direction_frame_fx( q_direction, azimuth_orig, elevation_orig, raw_flag, bits_dir_bands, &diff_bits ); FOR( i = start_band; i < nbands; i++ ) { @@ -619,34 +670,52 @@ ivas_error ivas_qmetadata_enc_encode( { /* Rewrite raw flag value */ hMetaData->ind_list[next_ind_raw_flag + i - start_band].value = 1; + move16(); /* Write ec bits */ - bits_ec = ivas_qmetadata_raw_encode_dir( hMetaData, q_direction, i + 1, i ); + bits_ec = ivas_qmetadata_raw_encode_dir_fx( hMetaData, q_direction, add( i, 1 ), i ); } - bits_dir[d] += bits_dir_bands[i] + 1; + bits_dir[d] = add( bits_dir[d], add( bits_dir_bands[i], 1 ) ); + move16(); } - extra_bits = hQMetaData->metadata_max_bits - ( hMetaData->nb_bits_tot - bit_pos_0 ); + extra_bits = sub( hQMetaData->metadata_max_bits, sub( hMetaData->nb_bits_tot, bit_pos_0 ) ); + } + +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + for ( int j = hQMetaData->q_direction[0].cfg.start_band; j < hQMetaData->q_direction[0].cfg.nbands; ++j ) + { + fixedToFloat_arrL( hQMetaData->q_direction[d].band_data[j].azimuth_fx, hQMetaData->q_direction[d].band_data[j].azimuth, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); + fixedToFloat_arrL( hQMetaData->q_direction[d].band_data[j].elevation_fx, hQMetaData->q_direction[d].band_data[j].elevation, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); + } + for ( i = start_band; i < nbands; i++ ) + { + fixedToFloat_arrL( azimuth_orig[i], azimuth_orig_flt[i], Q22, nblocks ); + fixedToFloat_arrL( elevation_orig[i], elevation_orig_flt[i], Q22, nblocks ); } +#endif /* Requantized directions */ - IF( LE_16( ( total_bits_1dir + bits_surround_coh ), hQMetaData->qmetadata_max_bit_req ) && GT_16( ( bits_dir[d] + bits_diff[d] + bits_coherence[d] + bits_signaling[d] ), total_bits_1dir ) ) + IF( LE_16( add( total_bits_1dir, bits_surround_coh ), hQMetaData->qmetadata_max_bit_req ) && GT_16( add( add( add( bits_dir[d], bits_diff[d] ), bits_coherence[d] ), bits_signaling[d] ), total_bits_1dir ) ) { /*Bit budget exceeded, bit reduction strategy?*/ extra_bits = 0; + move16(); - restore_metadata_buffer( hMetaData, next_ind_start, bit_pos_start ); + restore_metadata_buffer_fx( hMetaData, next_ind_start, bit_pos_start ); push_next_indice( hMetaData, 1, 1 ); /*Write 1 bit to signal no EC frame-wise (EC1)*/ IF( GT_16( nblocks, 1 ) ) { push_next_indice( hMetaData, 1, 1 ); /*Write 1 bit to signal requantization stage (EC3)*/ bits_signaling[d] = 3; + move16(); } ELSE { bits_signaling[d] = 2; + move16(); } IF( hQMetaData->is_masa_ivas_format == 0 ) @@ -2121,6 +2190,45 @@ void reset_metadata_spatial( * * *------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +/*! r: quantized spherical index */ +Word16 quantize_direction2D_fx( + Word32 phi, /* i : input azimuth value Q22 */ + const Word16 no_cw, /* i : number of bits */ + Word32 *phi_q, /* o : quantized azimuth value Q22 */ + UWord16 *index_phi, /* o : quantized azimuth index */ + const MC_LS_SETUP mc_format /* i : channel format if in MC-mode */ +) +{ + Word16 idx_sph; + UWord16 id_phi; + IF( LT_16( no_cw, 2 ) ) + { + *phi_q = 0; + move32(); + + return 0; + } + + IF( NE_32( mc_format, MC_LS_SETUP_INVALID ) ) + { + id_phi = quantize_phi_chan_compand_fx( L_add( phi, 180 << Q22 ), phi_q, no_cw, 0, mc_format ); + } + ELSE + { + id_phi = quantize_phi_fx( L_add( phi, 180 << Q22 ), 0, phi_q, no_cw ); + } + *phi_q = L_sub( *phi_q, 180 << Q22 ); + move32(); + *index_phi = ivas_qmetadata_reorder_generic( sub( id_phi, shr( no_cw, 1 ) ) ); + move16(); + + idx_sph = id_phi; + move16(); + + return idx_sph; +} +#endif /*! r: quantized spherical index */ int16_t quantize_direction2D( @@ -3394,7 +3502,27 @@ static int16_t ivas_qmetadata_entropy_encode_df_ratio( * * Restore metadata buffer *------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void restore_metadata_buffer_fx( + BSTR_ENC_HANDLE hMetaData, + const Word16 next_ind_start, + const Word16 bit_pos_start ) +{ + Word16 i; + FOR( i = next_ind_start; i < hMetaData->nb_ind_tot; i++ ) + { + hMetaData->ind_list[i].nb_bits = -1; + move16(); + } + hMetaData->nb_bits_tot = bit_pos_start; + move16(); + hMetaData->nb_ind_tot = next_ind_start; + move16(); + + return; +} +#else void restore_metadata_buffer( BSTR_ENC_HANDLE hMetaData, const int16_t next_ind_start, @@ -3411,7 +3539,7 @@ void restore_metadata_buffer( return; } - +#endif /*------------------------------------------------------------------------- * ivas_qmetadata_encode_quasi_uniform() @@ -3829,506 +3957,483 @@ static int16_t ivas_qmetadata_encode_quasi_uniform_length( *------------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED -static int16_t ivas_qmetadata_entropy_encode_dir( +static Word16 ivas_qmetadata_entropy_encode_dir_fx( BSTR_ENC_HANDLE hMetaData, IVAS_QDIRECTION *q_direction, - const uint16_t diffuseness_index_max_ec_frame, - const int16_t nbands, - const int16_t start_band, - const int16_t direction_bits_raw, - int16_t max_bits, - const int16_t hrmasa_flag ) + const UWord16 diffuseness_index_max_ec_frame, + const Word16 nbands, + const Word16 start_band, + const Word16 direction_bits_raw, + Word16 max_bits, + const Word16 hrmasa_flag ) { - uint16_t diff_idx_min; - int16_t i, j; - int16_t nblocks; - - float avg_direction_vector[3], direction_vector[3], avg_azimuth, avg_elevation; -#ifdef IVAS_FLOAT_FIXED - Word32 /*avg_direction_vector_fx[3],*/ direction_vector_fx[3] /*, avg_azimuth_fx, avg_elevation_fx*/; -#endif - int16_t avg_azimuth_alphabet, avg_elevation_alphabet; - uint16_t avg_azimuth_index, avg_elevation_index; - int16_t avg_elevation_index_projected; - int16_t avg_azimuth_index_projected; - uint16_t avg_elevation_index_initial, avg_elevation_offset; - uint16_t avg_azimuth_index_initial, avg_azimuth_offset; - int16_t elevation_bits_ec_best, azimuth_bits_ec_best; - - int16_t gr_param_elevation_best = 0, avg_elevation_index_best = 0; - uint16_t dist_elevation_indexes_best[MAX_PARAM_SPATIAL_SUBFRAMES * MASA_MAXIMUM_CODING_SUBBANDS]; - int16_t gr_param_azimuth_best, avg_azimuth_index_best; + UWord16 diff_idx_min; + Word16 i, j; + Word16 nblocks; + + Word32 avg_direction_vector[3], direction_vector[3], avg_azimuth, avg_elevation; + Word16 avg_azimuth_alphabet, avg_elevation_alphabet; + UWord16 avg_azimuth_index, avg_elevation_index; + Word16 avg_elevation_index_projected; + Word16 avg_azimuth_index_projected; + UWord16 avg_elevation_index_initial, avg_elevation_offset; + UWord16 avg_azimuth_index_initial, avg_azimuth_offset; + Word16 elevation_bits_ec_best, azimuth_bits_ec_best; + + Word16 gr_param_elevation_best = 0, avg_elevation_index_best = 0; + move16(); + move16(); + UWord16 dist_elevation_indexes_best[MAX_PARAM_SPATIAL_SUBFRAMES * MASA_MAXIMUM_CODING_SUBBANDS]; + Word16 gr_param_azimuth_best, avg_azimuth_index_best; uint16_t dist_azimuth_indexes_best[MAX_PARAM_SPATIAL_SUBFRAMES * MASA_MAXIMUM_CODING_SUBBANDS]; - uint16_t idx, dist_count; - int16_t direction_bits_ec; + UWord16 idx, dist_count; + Word16 direction_bits_ec; - uint16_t dist_elevation_indexes[MAX_PARAM_SPATIAL_SUBFRAMES * MASA_MAXIMUM_CODING_SUBBANDS]; - uint16_t dist_elevation_alphabets[MAX_PARAM_SPATIAL_SUBFRAMES * MASA_MAXIMUM_CODING_SUBBANDS]; - uint16_t dist_azimuth_indexes[MAX_PARAM_SPATIAL_SUBFRAMES * MASA_MAXIMUM_CODING_SUBBANDS]; - uint16_t dist_azimuth_alphabets[MAX_PARAM_SPATIAL_SUBFRAMES * MASA_MAXIMUM_CODING_SUBBANDS]; - int16_t all_zero_dist_elevation_indexes = 1, all_zero_dist_azimuth_indexes = 1; - int16_t gr_param_elevation, gr_size_elevation, egr_size_elevation, gr_param_azimuth, gr_size_azimuth; - int16_t egr_size_azimuth, elevation_bits_ec, azimuth_bits_ec; + UWord16 dist_elevation_indexes[MAX_PARAM_SPATIAL_SUBFRAMES * MASA_MAXIMUM_CODING_SUBBANDS]; + UWord16 dist_elevation_alphabets[MAX_PARAM_SPATIAL_SUBFRAMES * MASA_MAXIMUM_CODING_SUBBANDS]; + UWord16 dist_azimuth_indexes[MAX_PARAM_SPATIAL_SUBFRAMES * MASA_MAXIMUM_CODING_SUBBANDS]; + UWord16 dist_azimuth_alphabets[MAX_PARAM_SPATIAL_SUBFRAMES * MASA_MAXIMUM_CODING_SUBBANDS]; + Word16 all_zero_dist_elevation_indexes = 1, all_zero_dist_azimuth_indexes = 1; + move16(); + move16(); + Word16 gr_param_elevation, gr_size_elevation, egr_size_elevation, gr_param_azimuth, gr_size_azimuth; + Word16 egr_size_azimuth, elevation_bits_ec, azimuth_bits_ec; - float abs_theta; - float theta_cb[MAX_NO_THETA]; - int16_t sign_th, no_th; - int16_t avg_azimuth_index_upd = 0, use_adapt_avg; - int16_t make_gain = 0; - int16_t bits_gained = 0; + Word32 abs_theta; + Word16 theta_cb[MAX_NO_THETA]; // Q22-Q16 = Q6 + Word16 sign_th, no_th; + Word16 avg_azimuth_index_upd = 0, use_adapt_avg; + move16(); + Word16 make_gain = 0; + move16(); + Word16 bits_gained = 0; + move16(); nblocks = q_direction->cfg.nblocks; + move16(); /* estimate the number of bits for entropy coding of the direction values */ direction_bits_ec = 0; + move16(); diff_idx_min = DIRAC_DIFFUSE_LEVELS; + move16(); idx = 0; + move16(); dist_count = 0; - set_zero( avg_direction_vector, 3 ); + move16(); + set_zero_fx( avg_direction_vector, 3 ); - for ( i = start_band; i < nbands; i++ ) + FOR( i = start_band; i < nbands; i++ ) { - if ( hrmasa_flag ) + IF( hrmasa_flag ) { diff_idx_min = 0; // min( q_direction->band_data[i].energy_ratio_index_mod[0]>>1, diff_idx_min ); + move16(); } - else + ELSE { - diff_idx_min = min( q_direction->band_data[i].energy_ratio_index_mod[0], diff_idx_min ); + diff_idx_min = s_min( q_direction->band_data[i].energy_ratio_index_mod[0], diff_idx_min ); } - if ( q_direction->band_data[i].energy_ratio_index_mod[0] > diffuseness_index_max_ec_frame ) + IF( GT_32( q_direction->band_data[i].energy_ratio_index_mod[0], diffuseness_index_max_ec_frame ) ) { /* estimate the raw part */ - if ( q_direction->not_in_2D > 0 ) + IF( q_direction->not_in_2D > 0 ) { - for ( j = 0; j < nblocks; j++ ) + FOR( j = 0; j < nblocks; j++ ) { - direction_bits_ec += q_direction->band_data[i].bits_sph_idx[j]; + direction_bits_ec = add( direction_bits_ec, q_direction->band_data[i].bits_sph_idx[j] ); } } - else + ELSE { - for ( j = 0; j < nblocks; j++ ) + FOR( j = 0; j < nblocks; j++ ) { - direction_bits_ec += ivas_qmetadata_encode_quasi_uniform_length( q_direction->band_data[i].azimuth_index[j], q_direction->band_data[i].azimuth_m_alphabet[j] ); + direction_bits_ec = add( direction_bits_ec, ivas_qmetadata_encode_quasi_uniform_length( q_direction->band_data[i].azimuth_index[j], q_direction->band_data[i].azimuth_m_alphabet[j] ) ); } } } - else + ELSE { - dist_count += nblocks; + dist_count = add( dist_count, nblocks ); - for ( j = 0; j < nblocks; j++ ) + FOR( j = 0; j < nblocks; j++ ) { /*compute the average direction */ -#ifdef IVAS_FLOAT_FIXED - /*==========================================flt-2-fix======================================================*/ - q_direction->band_data[i].azimuth_fx[j] = floatToFixed( q_direction->band_data[i].azimuth[j], Q22 ); - q_direction->band_data[i].elevation_fx[j] = floatToFixed( q_direction->band_data[i].elevation[j], Q22 ); - /*==========================================flt-2-fix======================================================*/ - - ivas_qmetadata_azimuth_elevation_to_direction_vector_fx( q_direction->band_data[i].azimuth_fx[j], q_direction->band_data[i].elevation_fx[j], direction_vector_fx ); - - /*==========================================fix-2-flt======================================================*/ - fixedToFloat_arrL( direction_vector_fx, direction_vector, Q30, 3 ); - /*==========================================fix-2-flt======================================================*/ -#else - ivas_qmetadata_azimuth_elevation_to_direction_vector( q_direction->band_data[i].azimuth[j], q_direction->band_data[i].elevation[j], direction_vector ); -#endif - v_add( avg_direction_vector, direction_vector, avg_direction_vector, 3 ); + ivas_qmetadata_azimuth_elevation_to_direction_vector_fx( q_direction->band_data[i].azimuth_fx[j], q_direction->band_data[i].elevation_fx[j], direction_vector ); + scale_sig32( direction_vector, 3, -8 ); // Q30 -> Q22 + v_add_fixed( avg_direction_vector, direction_vector, avg_direction_vector, 3, 0 ); } } } /* quantize average elevation and azimuth angles using the best angle spacing and equatorial precision */ -#ifdef IVAS_FLOAT_FIXED_ - /*==========================================flt-2-fix======================================================*/ - Word16 q_dir_e = 0; - f2me_buf( avg_direction_vector, avg_direction_vector_fx, &q_dir_e, 3 ); - Scale_sig32( avg_direction_vector_fx, 3, -1 ); - /*==========================================flt-2-fix======================================================*/ - - ivas_qmetadata_direction_vector_to_azimuth_elevation_fx( avg_direction_vector_fx, Q30, &avg_azimuth_fx, &avg_elevation_fx ); - - /*==========================================fix-2-flt======================================================*/ - avg_azimuth = fixedToFloat( avg_azimuth_fx, Q22 ); - avg_elevation = fixedToFloat( avg_elevation_fx, Q22 ); - /*==========================================fix-2-flt======================================================*/ -#else - ivas_qmetadata_direction_vector_to_azimuth_elevation( avg_direction_vector, &avg_azimuth, &avg_elevation ); -#endif + ivas_qmetadata_direction_vector_to_azimuth_elevation_fx( avg_direction_vector, Q22, &avg_azimuth, &avg_elevation ); - if ( q_direction->cfg.mc_ls_setup != MC_LS_SETUP_INVALID ) + IF( NE_32( q_direction->cfg.mc_ls_setup, MC_LS_SETUP_INVALID ) ) { avg_elevation_alphabet = no_theta_masa[bits_direction_masa[diff_idx_min] - 3]; + move16(); avg_azimuth_alphabet = no_phi_masa[bits_direction_masa[diff_idx_min] - 1][0]; /* average azimuth is quantized on the equatorial plane */ + move16(); } - else + ELSE { - avg_elevation_alphabet = no_theta_masa[bits_direction_masa[diff_idx_min] - 3] * 2 - 1; + avg_elevation_alphabet = sub( shl( no_theta_masa[bits_direction_masa[diff_idx_min] - 3], 1 ), 1 ); avg_azimuth_alphabet = no_phi_masa[bits_direction_masa[diff_idx_min] - 1][0]; /* average azimuth is quantized on the equatorial plane */ + move16(); } no_th = no_theta_masa[bits_direction_masa[diff_idx_min] - 3]; + move16(); - for ( i = 0; i < no_th; i++ ) + FOR( i = 0; i < no_th; i++ ) { - theta_cb[i] = i * delta_theta_masa[bits_direction_masa[diff_idx_min] - 3]; + theta_cb[i] = imult1616( i, round_fx( delta_theta_masa_fx[bits_direction_masa[diff_idx_min] - 3] ) ); + move16(); } - if ( theta_cb[i - 1] > 90 ) + if ( GT_32( theta_cb[i - 1], 90 << Q6 ) ) { - theta_cb[i - 1] = 90; + theta_cb[i - 1] = 90 << Q6; + move16(); } - if ( avg_elevation < 0 ) + IF( avg_elevation < 0 ) { - abs_theta = -avg_elevation; + abs_theta = L_negate( avg_elevation ); sign_th = -1; + move16(); } - else + ELSE { abs_theta = avg_elevation; + move32(); sign_th = 1; + move16(); } - avg_elevation_index = squant( abs_theta, &avg_elevation, theta_cb, no_th ); + Word16 tmp; + avg_elevation_index = squant_fx( round_fx( abs_theta ), &tmp, theta_cb, no_th ); + avg_elevation = L_deposit_h( tmp ); // Q22 - if ( q_direction->cfg.mc_ls_setup != MC_LS_SETUP_INVALID ) + IF( NE_32( q_direction->cfg.mc_ls_setup, MC_LS_SETUP_INVALID ) ) { assert( avg_elevation >= 0 ); } - else + ELSE { - if ( sign_th < 0 ) + IF( sign_th < 0 ) { - avg_elevation_index = ( avg_elevation_alphabet >> 1 ) - avg_elevation_index; + avg_elevation_index = sub( shr( avg_elevation_alphabet, 1 ), avg_elevation_index ); } - else + ELSE { - avg_elevation_index += ( avg_elevation_alphabet >> 1 ); + avg_elevation_index = add( avg_elevation_index, shr( avg_elevation_alphabet, 1 ) ); + } + // avg_elevation *= sign_th; + if ( sign_th < 0 ) + { + avg_elevation = L_negate( avg_elevation ); } - avg_elevation *= sign_th; } - avg_azimuth_index = (uint16_t) ( quantize_phi( avg_azimuth + 180, 0, &avg_azimuth, avg_azimuth_alphabet ) ); + avg_azimuth_index = (UWord16) ( quantize_phi_fx( L_add( avg_azimuth, 180 << Q22 ), 0, &avg_azimuth, avg_azimuth_alphabet ) ); /* Elevation only if not 2D */ - if ( q_direction->not_in_2D > 0 ) + IF( q_direction->not_in_2D > 0 ) { avg_elevation_index_initial = avg_elevation_index; + move16(); elevation_bits_ec_best = MAX16B; + move16(); avg_elevation_index_best = -1; /* out of range value */ - gr_param_elevation_best = -1; /* out of range value */ + move16(); + gr_param_elevation_best = -1; /* out of range value */ + move16(); - for ( avg_elevation_offset = 0; avg_elevation_offset < q_direction->cfg.search_effort; avg_elevation_offset++ ) + FOR( avg_elevation_offset = 0; avg_elevation_offset < q_direction->cfg.search_effort; avg_elevation_offset++ ) { - if ( q_direction->cfg.mc_ls_setup != MC_LS_SETUP_INVALID ) + IF( NE_32( q_direction->cfg.mc_ls_setup, MC_LS_SETUP_INVALID ) ) { - avg_elevation_index = avg_elevation_index_initial + avg_elevation_offset; + avg_elevation_index = u_extract_l( UL_addNsD( avg_elevation_index_initial, avg_elevation_offset ) ); } - else + ELSE { - avg_elevation_index = (uint16_t) ( avg_elevation_index_initial + ivas_qmetadata_dereorder_generic( avg_elevation_offset ) ); + avg_elevation_index = u_extract_l( UL_addNsD( avg_elevation_index_initial, ivas_qmetadata_dereorder_generic( avg_elevation_offset ) ) ); } - avg_elevation_index = (uint16_t) ( ( avg_elevation_index + avg_elevation_alphabet ) % avg_elevation_alphabet ); + // avg_elevation_index = (uint16_t) ( ( avg_elevation_index + avg_elevation_alphabet ) % avg_elevation_alphabet ); + avg_elevation_index = u_extract_l( UL_addNsD( avg_elevation_index, avg_elevation_alphabet ) % avg_elevation_alphabet ); all_zero_dist_elevation_indexes = 1; - if ( q_direction->cfg.mc_ls_setup != MC_LS_SETUP_INVALID ) + move16(); + IF( NE_32( q_direction->cfg.mc_ls_setup, MC_LS_SETUP_INVALID ) ) { elevation_bits_ec = ivas_qmetadata_encode_quasi_uniform_length( avg_elevation_index, avg_elevation_alphabet ); } - else + ELSE { - elevation_bits_ec = ivas_qmetadata_encode_quasi_uniform_length( ivas_qmetadata_reorder_generic( avg_elevation_index - ( avg_elevation_alphabet >> 1 ) ), avg_elevation_alphabet ); + elevation_bits_ec = ivas_qmetadata_encode_quasi_uniform_length( ivas_qmetadata_reorder_generic( sub( avg_elevation_index, shr( avg_elevation_alphabet, 1 ) ) ), avg_elevation_alphabet ); } idx = 0; - for ( i = start_band; i < nbands; i++ ) + move16(); + FOR( i = start_band; i < nbands; i++ ) { - if ( q_direction->band_data[i].energy_ratio_index_mod[0] <= diffuseness_index_max_ec_frame ) + IF( LE_16( q_direction->band_data[i].energy_ratio_index_mod[0], diffuseness_index_max_ec_frame ) ) { - for ( j = 0; j < nblocks; j++ ) + FOR( j = 0; j < nblocks; j++ ) { /* project the quantized average elevation to the same grid as the current sample */ - if ( q_direction->cfg.mc_ls_setup != MC_LS_SETUP_INVALID ) + IF( NE_32( q_direction->cfg.mc_ls_setup, MC_LS_SETUP_INVALID ) ) { avg_elevation_index_projected = ivas_chan_project_elevation_index( avg_elevation_index, avg_elevation_alphabet, q_direction->band_data[i].elevation_m_alphabet[j] ); } - else + ELSE { avg_elevation_index_projected = ivas_dirac_project_elevation_index( avg_elevation_index, avg_elevation_alphabet, q_direction->band_data[i].elevation_m_alphabet[j] ); } - if ( q_direction->cfg.mc_ls_setup != MC_LS_SETUP_INVALID ) + IF( NE_32( q_direction->cfg.mc_ls_setup, MC_LS_SETUP_INVALID ) ) { - if ( q_direction->band_data[i].elevation_index[j] - avg_elevation_index_projected > 0 ) + IF( L_sub( q_direction->band_data[i].elevation_index[j], avg_elevation_index_projected ) > 0 ) { - dist_elevation_indexes[idx] = 2 * ( q_direction->band_data[i].elevation_index[j] - avg_elevation_index_projected ) - 1; + // dist_elevation_indexes[idx] = 2 * ( q_direction->band_data[i].elevation_index[j] - avg_elevation_index_projected ) - 1; + dist_elevation_indexes[idx] = sub( shl( sub( q_direction->band_data[i].elevation_index[j], avg_elevation_index_projected ), 1 ), 1 ); + move16(); } - else + ELSE { - dist_elevation_indexes[idx] = -2 * ( q_direction->band_data[i].elevation_index[j] - avg_elevation_index_projected ); + // dist_elevation_indexes[idx] = -2 * ( q_direction->band_data[i].elevation_index[j] - avg_elevation_index_projected ); + dist_elevation_indexes[idx] = imult1616( -2, sub( q_direction->band_data[i].elevation_index[j], avg_elevation_index_projected ) ); + move16(); } } - else + ELSE { - dist_elevation_indexes[idx] = ivas_qmetadata_reorder_elevation_index( q_direction->band_data[i].elevation_index[j], avg_elevation_index_projected, q_direction->band_data[i].elevation_m_alphabet[j] ); + dist_elevation_indexes[idx] = ivas_qmetadata_reorder_elevation_index_fx( q_direction->band_data[i].elevation_index[j], avg_elevation_index_projected, q_direction->band_data[i].elevation_m_alphabet[j] ); + move16(); } - if ( q_direction->cfg.mc_ls_setup != MC_LS_SETUP_INVALID ) + IF( NE_32( q_direction->cfg.mc_ls_setup, MC_LS_SETUP_INVALID ) ) { - dist_elevation_alphabets[idx] = 2 * q_direction->band_data[i].elevation_m_alphabet[j] - 1; + dist_elevation_alphabets[idx] = sub( shl( q_direction->band_data[i].elevation_m_alphabet[j], 1 ), 1 ); + move16(); } - else + ELSE { dist_elevation_alphabets[idx] = q_direction->band_data[i].elevation_m_alphabet[j]; + move16(); } if ( dist_elevation_indexes[idx] != 0 ) { all_zero_dist_elevation_indexes = 0; + move16(); } - idx++; + idx = add( idx, 1 ); } } } - if ( all_zero_dist_elevation_indexes ) + IF( all_zero_dist_elevation_indexes ) { egr_size_elevation = 0; + move16(); gr_param_elevation = 4; + move16(); } - else + ELSE { - gr_param_elevation = ivas_qmetadata_get_optimal_gr_param( dist_elevation_indexes, idx, 4, &gr_size_elevation ); + gr_param_elevation = ivas_qmetadata_get_optimal_gr_param_fx( dist_elevation_indexes, idx, 4, &gr_size_elevation ); egr_size_elevation = 0; - for ( i = 0; i < idx; i++ ) + move16(); + FOR( i = 0; i < idx; i++ ) { - egr_size_elevation += ivas_qmetadata_encode_extended_gr_length( dist_elevation_indexes[i], dist_elevation_alphabets[i], gr_param_elevation ); + egr_size_elevation = add( egr_size_elevation, ivas_qmetadata_encode_extended_gr_length( dist_elevation_indexes[i], dist_elevation_alphabets[i], gr_param_elevation ) ); } } - elevation_bits_ec += ivas_qmetadata_encode_quasi_uniform_length( gr_param_elevation, 4 + 1 ) + egr_size_elevation; + elevation_bits_ec = add( elevation_bits_ec, add( ivas_qmetadata_encode_quasi_uniform_length( gr_param_elevation, 4 + 1 ), egr_size_elevation ) ); - if ( elevation_bits_ec < elevation_bits_ec_best ) + IF( LT_16( elevation_bits_ec, elevation_bits_ec_best ) ) { elevation_bits_ec_best = elevation_bits_ec; + move16(); avg_elevation_index_best = avg_elevation_index; + move16(); gr_param_elevation_best = gr_param_elevation; - for ( idx = 0; idx < dist_count; idx++ ) + move16(); + FOR( idx = 0; idx < dist_count; idx++ ) { dist_elevation_indexes_best[idx] = dist_elevation_indexes[idx]; + move16(); } } } - direction_bits_ec += elevation_bits_ec_best; + direction_bits_ec = add( direction_bits_ec, elevation_bits_ec_best ); } /*Azimuth*/ use_adapt_avg = 0; - if ( ( nbands - start_band >= 5 ) && ( q_direction->cfg.mc_ls_setup != MC_LS_SETUP_INVALID ) && ( nblocks > 1 ) ) + move16(); + test(); + test(); + IF( GE_16( sub( nbands, start_band ), 5 ) && NE_32( q_direction->cfg.mc_ls_setup, MC_LS_SETUP_INVALID ) && GT_16( nblocks, 1 ) ) { -#ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word32 avg_azimuth_fx; // Q22 - avg_azimuth_fx = float_to_fix( avg_azimuth, Q22 ); - for ( i = 0; i < q_direction->cfg.nbands; i++ ) - { - if ( q_direction->band_data[i].energy_ratio_index_mod[0] < diffuseness_index_max_ec_frame ) - { - for ( j = 0; j < q_direction->cfg.nblocks; j++ ) - { - q_direction->band_data[i].azimuth_fx[j] = floatToFixed( q_direction->band_data[i].azimuth[j], Q22 ); - q_direction->band_data[i].elevation_fx[j] = floatToFixed( q_direction->band_data[i].elevation[j], Q22 ); - } - } - } - -#endif - use_adapt_avg = calc_var_azi_fx( q_direction, diffuseness_index_max_ec_frame, L_sub( avg_azimuth_fx, 754974720 ), &avg_azimuth_fx ); // 180.Q22 + use_adapt_avg = calc_var_azi_fx( q_direction, diffuseness_index_max_ec_frame, L_sub( avg_azimuth, 180 << Q22 ), &avg_azimuth ); // 180.Q22 -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - avg_azimuth = fix_to_float( avg_azimuth_fx, Q22 ); - for ( i = 0; i < q_direction->cfg.nbands; i++ ) - { - if ( q_direction->band_data[i].energy_ratio_index_mod[0] < diffuseness_index_max_ec_frame ) - { - for ( j = 0; j < q_direction->cfg.nblocks; j++ ) - { - q_direction->band_data[i].azimuth[j] = fixedToFloat( q_direction->band_data[i].azimuth_fx[j], Q22 ); - q_direction->band_data[i].elevation[j] = fixedToFloat( q_direction->band_data[i].elevation_fx[j], Q22 ); - } - } - } -#endif -#else - use_adapt_avg = calc_var_azi( q_direction, diffuseness_index_max_ec_frame, avg_azimuth - 180, &avg_azimuth ); -#endif - avg_azimuth_index = (uint16_t) ( quantize_phi( avg_azimuth + 180, 0, &avg_azimuth, avg_azimuth_alphabet ) ); + avg_azimuth_index = (UWord16) ( quantize_phi_fx( L_add( avg_azimuth, 180 << Q22 ), 0, &avg_azimuth, avg_azimuth_alphabet ) ); } avg_azimuth_index_initial = avg_azimuth_index; /* avg_azimuth_index;*/ + move16(); azimuth_bits_ec_best = MAX16B; + move16(); avg_azimuth_index_best = -1; /* out of range value */ - gr_param_azimuth_best = -1; /* out of range value */ + move16(); + gr_param_azimuth_best = -1; /* out of range value */ + move16(); - for ( avg_azimuth_offset = 0; avg_azimuth_offset < q_direction->cfg.search_effort; avg_azimuth_offset++ ) + FOR( avg_azimuth_offset = 0; avg_azimuth_offset < q_direction->cfg.search_effort; avg_azimuth_offset++ ) { - set_zero( avg_direction_vector, 3 ); - avg_azimuth_index = (uint16_t) ( avg_azimuth_index_initial + ivas_qmetadata_dereorder_generic( avg_azimuth_offset ) ); - avg_azimuth_index = (uint16_t) ( ( avg_azimuth_index + avg_azimuth_alphabet ) % avg_azimuth_alphabet ); + set_zero_fx( avg_direction_vector, 3 ); + avg_azimuth_index = (UWord16) add( avg_azimuth_index_initial, ivas_qmetadata_dereorder_generic( avg_azimuth_offset ) ); + avg_azimuth_index = (UWord16) ( add( avg_azimuth_index, avg_azimuth_alphabet ) % avg_azimuth_alphabet ); all_zero_dist_azimuth_indexes = 1; - azimuth_bits_ec = ivas_qmetadata_encode_quasi_uniform_length( ivas_qmetadata_reorder_generic( avg_azimuth_index - ( avg_azimuth_alphabet >> 1 ) ), avg_azimuth_alphabet ); + move16(); + azimuth_bits_ec = ivas_qmetadata_encode_quasi_uniform_length( ivas_qmetadata_reorder_generic( sub( avg_azimuth_index, shr( avg_azimuth_alphabet, 1 ) ) ), avg_azimuth_alphabet ); idx = 0; - for ( i = start_band; i < nbands; i++ ) + move16(); + FOR( i = start_band; i < nbands; i++ ) { - if ( q_direction->band_data[i].energy_ratio_index_mod[0] <= diffuseness_index_max_ec_frame ) + IF( LE_16( q_direction->band_data[i].energy_ratio_index_mod[0], diffuseness_index_max_ec_frame ) ) { - for ( j = 0; j < nblocks; j++ ) + FOR( j = 0; j < nblocks; j++ ) { - - if ( ( idx > MASA_LIMIT_IDX_AVG_AZI ) && ( q_direction->cfg.mc_ls_setup != MC_LS_SETUP_INVALID ) && ( use_adapt_avg == 1 ) ) + test(); + test(); + IF( GT_16( idx, MASA_LIMIT_IDX_AVG_AZI ) && NE_32( q_direction->cfg.mc_ls_setup, MC_LS_SETUP_INVALID ) && EQ_16( use_adapt_avg, 1 ) ) { avg_azimuth_index_projected = ivas_dirac_project_azimuth_index( avg_azimuth_index_upd, avg_azimuth_alphabet, q_direction->band_data[i].azimuth_m_alphabet[j] ); } - else + ELSE { - if ( ( q_direction->cfg.mc_ls_setup != MC_LS_SETUP_INVALID ) && ( use_adapt_avg == 1 ) ) + test(); + IF( NE_32( q_direction->cfg.mc_ls_setup, MC_LS_SETUP_INVALID ) && ( use_adapt_avg == 1 ) ) { -#ifdef IVAS_FLOAT_FIXED - /*==========================================flt-2-fix======================================================*/ - q_direction->band_data[i].azimuth_fx[j] = floatToFixed( q_direction->band_data[i].azimuth[j], Q22 ); - q_direction->band_data[i].elevation_fx[j] = floatToFixed( q_direction->band_data[i].elevation[j], Q22 ); - /*==========================================flt-2-fix======================================================*/ + ivas_qmetadata_azimuth_elevation_to_direction_vector_fx( q_direction->band_data[i].azimuth_fx[j], q_direction->band_data[i].elevation_fx[j], direction_vector ); + scale_sig32( direction_vector, 3, -8 ); // Q30 -> Q22 - ivas_qmetadata_azimuth_elevation_to_direction_vector_fx( q_direction->band_data[i].azimuth_fx[j], q_direction->band_data[i].elevation_fx[j], direction_vector_fx ); - - /*==========================================fix-2-flt======================================================*/ - fixedToFloat_arrL( direction_vector_fx, direction_vector, Q30, 3 ); - /*==========================================fix-2-flt======================================================*/ -#else - ivas_qmetadata_azimuth_elevation_to_direction_vector( q_direction->band_data[i].azimuth[j], q_direction->band_data[i].elevation[j], direction_vector ); -#endif - if ( idx < 4 ) + IF( LT_16( idx, 4 ) ) { - v_add( avg_direction_vector, direction_vector, avg_direction_vector, 3 ); + v_add_fixed( avg_direction_vector, direction_vector, avg_direction_vector, 3, 0 ); } } /* project the quantized average azimuth angle to the same grid as the current sample */ avg_azimuth_index_projected = ivas_dirac_project_azimuth_index( avg_azimuth_index, avg_azimuth_alphabet, q_direction->band_data[i].azimuth_m_alphabet[j] ); } - dist_azimuth_indexes[idx] = ivas_qmetadata_reorder_azimuth_index( ivas_qmetadata_dereorder_generic( q_direction->band_data[i].azimuth_index[j] ) + ( q_direction->band_data[i].azimuth_m_alphabet[j] >> 1 ), avg_azimuth_index_projected, q_direction->band_data[i].azimuth_m_alphabet[j] ); + dist_azimuth_indexes[idx] = ivas_qmetadata_reorder_azimuth_index_fx( add( ivas_qmetadata_dereorder_generic( q_direction->band_data[i].azimuth_index[j] ), shr( q_direction->band_data[i].azimuth_m_alphabet[j], 1 ) ), avg_azimuth_index_projected, q_direction->band_data[i].azimuth_m_alphabet[j] ); + move16(); dist_azimuth_alphabets[idx] = q_direction->band_data[i].azimuth_m_alphabet[j]; + move16(); if ( dist_azimuth_indexes[idx] != 0 ) { all_zero_dist_azimuth_indexes = 0; + move16(); } - if ( ( idx >= MASA_LIMIT_IDX_AVG_AZI ) && ( q_direction->cfg.mc_ls_setup != MC_LS_SETUP_INVALID ) && ( use_adapt_avg == 1 ) ) + test(); + test(); + IF( GE_16( idx, MASA_LIMIT_IDX_AVG_AZI ) && NE_32( q_direction->cfg.mc_ls_setup, MC_LS_SETUP_INVALID ) && EQ_16( use_adapt_avg, 1 ) ) { - if ( idx % nblocks == 0 ) + IF( idx % nblocks == 0 ) { - v_multc( avg_direction_vector, 0.5f, avg_direction_vector, 3 ); + // v_multc( avg_direction_vector, 0.5f, avg_direction_vector, 3 ); + scale_sig32( avg_direction_vector, 3, -1 ); } /*compute the average direction per already coded subband */ -#ifdef IVAS_FLOAT_FIXED - /*==========================================flt-2-fix======================================================*/ - q_direction->band_data[i].azimuth_fx[j] = floatToFixed( q_direction->band_data[i].azimuth[j], Q22 ); - q_direction->band_data[i].elevation_fx[j] = floatToFixed( q_direction->band_data[i].elevation[j], Q22 ); - /*==========================================flt-2-fix======================================================*/ + ivas_qmetadata_azimuth_elevation_to_direction_vector_fx( q_direction->band_data[i].azimuth_fx[j], q_direction->band_data[i].elevation_fx[j], direction_vector ); + scale_sig32( direction_vector, 3, -8 ); // Q30 -> Q22 - ivas_qmetadata_azimuth_elevation_to_direction_vector_fx( q_direction->band_data[i].azimuth_fx[j], q_direction->band_data[i].elevation_fx[j], direction_vector_fx ); + v_add_fixed( avg_direction_vector, direction_vector, avg_direction_vector, 3, 0 ); + ivas_qmetadata_direction_vector_to_azimuth_elevation_fx( avg_direction_vector, Q22, &avg_azimuth, &avg_elevation ); - /*==========================================fix-2-flt======================================================*/ - fixedToFloat_arrL( direction_vector_fx, direction_vector, Q30, 3 ); - /*==========================================fix-2-flt======================================================*/ -#else - ivas_qmetadata_azimuth_elevation_to_direction_vector( q_direction->band_data[i].azimuth[j], q_direction->band_data[i].elevation[j], direction_vector ); -#endif - v_add( avg_direction_vector, direction_vector, avg_direction_vector, 3 ); -#ifdef IVAS_FLOAT_FIXED_ - /*==========================================flt-2-fix======================================================*/ - q_dir_e = 0; - f2me_buf( avg_direction_vector, avg_direction_vector_fx, &q_dir_e, 3 ); - Scale_sig32( avg_direction_vector_fx, 3, -1 ); - /*==========================================flt-2-fix======================================================*/ - - ivas_qmetadata_direction_vector_to_azimuth_elevation_fx( avg_direction_vector_fx, Q30, &avg_azimuth_fx, &avg_elevation_fx ); - - /*==========================================fix-2-flt======================================================*/ - avg_azimuth = fixedToFloat( avg_azimuth_fx, Q22 ); - avg_elevation = fixedToFloat( avg_elevation_fx, Q22 ); - /*==========================================fix-2-flt======================================================*/ -#else - ivas_qmetadata_direction_vector_to_azimuth_elevation( avg_direction_vector, &avg_azimuth, &avg_elevation ); -#endif - avg_azimuth_index_upd = quantize_phi( avg_azimuth + 180, 0, &avg_azimuth, avg_azimuth_alphabet ); + avg_azimuth_index_upd = quantize_phi_fx( L_add( avg_azimuth, 180 << Q22 ), 0, &avg_azimuth, avg_azimuth_alphabet ); } - idx++; + idx = add( idx, 1 ); } } } - if ( all_zero_dist_azimuth_indexes ) + IF( all_zero_dist_azimuth_indexes ) { egr_size_azimuth = 0; + move16(); gr_param_azimuth = 5; + move16(); } - else + ELSE { /* estimate the ExtendedGR part for azimuth */ - gr_param_azimuth = ivas_qmetadata_get_optimal_gr_param( dist_azimuth_indexes, idx, 5, &gr_size_azimuth ); + gr_param_azimuth = ivas_qmetadata_get_optimal_gr_param_fx( dist_azimuth_indexes, idx, 5, &gr_size_azimuth ); egr_size_azimuth = 0; - for ( i = 0; i < idx; i++ ) + move16(); + FOR( i = 0; i < idx; i++ ) { - egr_size_azimuth += ivas_qmetadata_encode_extended_gr_length( dist_azimuth_indexes[i], dist_azimuth_alphabets[i], gr_param_azimuth ); + egr_size_azimuth = add( egr_size_azimuth, ivas_qmetadata_encode_extended_gr_length( dist_azimuth_indexes[i], dist_azimuth_alphabets[i], gr_param_azimuth ) ); } } - azimuth_bits_ec += ivas_qmetadata_encode_quasi_uniform_length( gr_param_azimuth, 5 + 1 ) + egr_size_azimuth; + azimuth_bits_ec = add( azimuth_bits_ec, add( ivas_qmetadata_encode_quasi_uniform_length( gr_param_azimuth, 5 + 1 ), egr_size_azimuth ) ); - if ( azimuth_bits_ec < azimuth_bits_ec_best ) + IF( LT_16( azimuth_bits_ec, azimuth_bits_ec_best ) ) { azimuth_bits_ec_best = azimuth_bits_ec; + move16(); avg_azimuth_index_best = avg_azimuth_index; + move16(); gr_param_azimuth_best = gr_param_azimuth; + move16(); - for ( idx = 0; idx < dist_count; idx++ ) + FOR( idx = 0; idx < dist_count; idx++ ) { dist_azimuth_indexes_best[idx] = dist_azimuth_indexes[idx]; + move16(); } } } - if ( ( q_direction->cfg.mc_ls_setup != MC_LS_SETUP_INVALID ) && ( dist_count > 4 ) && ( gr_param_azimuth_best != 5 ) && ( nblocks > 1 ) ) + test(); + test(); + test(); + if ( NE_32( q_direction->cfg.mc_ls_setup, MC_LS_SETUP_INVALID ) && GT_16( dist_count, 4 ) && NE_16( gr_param_azimuth_best, 5 ) && GT_16( nblocks, 1 ) ) { - azimuth_bits_ec_best += 1; + azimuth_bits_ec_best = add( azimuth_bits_ec_best, 1 ); } - direction_bits_ec += azimuth_bits_ec_best; + direction_bits_ec = add( direction_bits_ec, azimuth_bits_ec_best ); /*Decision raw or EC*/ /* one bit is used to indicate whether the direction values are entropy coded or coded raw */ - if ( direction_bits_ec < direction_bits_raw ) /* entropy coding is better */ + IF( LT_16( direction_bits_ec, direction_bits_raw ) ) /* entropy coding is better */ { /* encode the raw part first */ - for ( i = start_band; i < nbands; i++ ) + FOR( i = start_band; i < nbands; i++ ) { - if ( q_direction->band_data[i].energy_ratio_index_mod[0] > diffuseness_index_max_ec_frame ) + IF( GT_16( q_direction->band_data[i].energy_ratio_index_mod[0], diffuseness_index_max_ec_frame ) ) { - if ( q_direction->not_in_2D > 0 ) + IF( q_direction->not_in_2D > 0 ) { - for ( j = 0; j < nblocks; j++ ) + FOR( j = 0; j < nblocks; j++ ) { push_next_indice( hMetaData, q_direction->band_data[i].spherical_index[j], q_direction->band_data[i].bits_sph_idx[j] ); } } - else + ELSE { - for ( j = 0; j < nblocks; j++ ) + FOR( j = 0; j < nblocks; j++ ) { ivas_qmetadata_encode_quasi_uniform( hMetaData, q_direction->band_data[i].azimuth_index[j], q_direction->band_data[i].azimuth_m_alphabet[j] ); } @@ -4336,28 +4441,31 @@ static int16_t ivas_qmetadata_entropy_encode_dir( } } - if ( nbands > 1 && direction_bits_ec - max_bits > 0 && direction_bits_ec - max_bits < nblocks * nbands ) + test(); + test(); + if ( GT_16( nbands, 1 ) && sub( direction_bits_ec, max_bits ) > 0 && LT_16( sub( direction_bits_ec, max_bits ), imult1616( nblocks, nbands ) ) ) { make_gain = 1; + move16(); } - if ( q_direction->not_in_2D > 0 ) + IF( q_direction->not_in_2D > 0 ) { /* encode the ExtendedGR part for elevation */ - if ( q_direction->cfg.mc_ls_setup != MC_LS_SETUP_INVALID ) + IF( NE_32( q_direction->cfg.mc_ls_setup, MC_LS_SETUP_INVALID ) ) { ivas_qmetadata_encode_quasi_uniform( hMetaData, avg_elevation_index_best, avg_elevation_alphabet ); } - else + ELSE { - ivas_qmetadata_encode_quasi_uniform( hMetaData, ivas_qmetadata_reorder_generic( avg_elevation_index_best - ( avg_elevation_alphabet >> 1 ) ), avg_elevation_alphabet ); + ivas_qmetadata_encode_quasi_uniform( hMetaData, ivas_qmetadata_reorder_generic( sub( avg_elevation_index_best, shr( avg_elevation_alphabet, 1 ) ) ), avg_elevation_alphabet ); } ivas_qmetadata_encode_quasi_uniform( hMetaData, gr_param_elevation_best, 4 + 1 ); - if ( gr_param_elevation_best != 4 ) /* not all zero */ + IF( NE_16( gr_param_elevation_best, 4 ) ) /* not all zero */ { - for ( idx = 0; idx < dist_count; idx++ ) + FOR( idx = 0; idx < dist_count; idx++ ) { ivas_qmetadata_encode_extended_gr( hMetaData, dist_elevation_indexes_best[idx], dist_elevation_alphabets[idx], gr_param_elevation_best ); } @@ -4365,67 +4473,72 @@ static int16_t ivas_qmetadata_entropy_encode_dir( } /* encode the ExtendedGR part for azimuth */ - ivas_qmetadata_encode_quasi_uniform( hMetaData, ivas_qmetadata_reorder_generic( avg_azimuth_index_best - ( avg_azimuth_alphabet >> 1 ) ), avg_azimuth_alphabet ); + ivas_qmetadata_encode_quasi_uniform( hMetaData, ivas_qmetadata_reorder_generic( sub( avg_azimuth_index_best, shr( avg_azimuth_alphabet, 1 ) ) ), avg_azimuth_alphabet ); ivas_qmetadata_encode_quasi_uniform( hMetaData, gr_param_azimuth_best, 5 + 1 ); - if ( gr_param_azimuth_best != 5 ) /* not all zero */ + IF( NE_16( gr_param_azimuth_best, 5 ) ) /* not all zero */ { - for ( idx = 0; idx < min( nblocks, dist_count ); idx++ ) + FOR( idx = 0; idx < min( nblocks, dist_count ); idx++ ) { - if ( make_gain == 1 && bits_gained < direction_bits_ec - max_bits && dist_azimuth_alphabets[idx] > 40 ) + test(); + test(); + IF( EQ_16( make_gain, 1 ) && LT_16( bits_gained, sub( direction_bits_ec, max_bits ) ) && GT_16( dist_azimuth_alphabets[idx], 40 ) ) { - if ( dist_azimuth_indexes_best[idx] > 1 ) + IF( GT_16( dist_azimuth_indexes_best[idx], 1 ) ) { - ivas_qmetadata_encode_extended_gr( hMetaData, dist_azimuth_indexes_best[idx] - 2, dist_azimuth_alphabets[idx], gr_param_azimuth_best ); - bits_gained += ivas_qmetadata_encode_extended_gr_length( dist_azimuth_indexes_best[idx], dist_azimuth_alphabets[idx], gr_param_azimuth_best ) - - ivas_qmetadata_encode_extended_gr_length( dist_azimuth_indexes_best[idx] - 2, dist_azimuth_alphabets[idx], gr_param_azimuth_best ); + ivas_qmetadata_encode_extended_gr( hMetaData, sub( dist_azimuth_indexes_best[idx], 2 ), dist_azimuth_alphabets[idx], gr_param_azimuth_best ); + bits_gained = add( bits_gained, sub( ivas_qmetadata_encode_extended_gr_length( dist_azimuth_indexes_best[idx], dist_azimuth_alphabets[idx], gr_param_azimuth_best ), + ivas_qmetadata_encode_extended_gr_length( sub( dist_azimuth_indexes_best[idx], 2 ), dist_azimuth_alphabets[idx], gr_param_azimuth_best ) ) ); } - else if ( dist_azimuth_indexes_best[idx] == 1 ) + ELSE IF( EQ_16( dist_azimuth_indexes_best[idx], 1 ) ) { - ivas_qmetadata_encode_extended_gr( hMetaData, dist_azimuth_indexes_best[idx] - 1, dist_azimuth_alphabets[idx], gr_param_azimuth_best ); - bits_gained += ivas_qmetadata_encode_extended_gr_length( dist_azimuth_indexes_best[idx], dist_azimuth_alphabets[idx], gr_param_azimuth_best ) - - ivas_qmetadata_encode_extended_gr_length( dist_azimuth_indexes_best[idx] - 1, dist_azimuth_alphabets[idx], gr_param_azimuth_best ); + ivas_qmetadata_encode_extended_gr( hMetaData, sub( dist_azimuth_indexes_best[idx], 1 ), dist_azimuth_alphabets[idx], gr_param_azimuth_best ); + bits_gained = add( bits_gained, sub( ivas_qmetadata_encode_extended_gr_length( dist_azimuth_indexes_best[idx], dist_azimuth_alphabets[idx], gr_param_azimuth_best ), + ivas_qmetadata_encode_extended_gr_length( sub( dist_azimuth_indexes_best[idx], 1 ), dist_azimuth_alphabets[idx], gr_param_azimuth_best ) ) ); } - else + ELSE { ivas_qmetadata_encode_extended_gr( hMetaData, dist_azimuth_indexes_best[idx], dist_azimuth_alphabets[idx], gr_param_azimuth_best ); } } - else + ELSE { ivas_qmetadata_encode_extended_gr( hMetaData, dist_azimuth_indexes_best[idx], dist_azimuth_alphabets[idx], gr_param_azimuth_best ); } } - if ( dist_count > nblocks ) + IF( GT_16( dist_count, nblocks ) ) { - if ( ( q_direction->cfg.mc_ls_setup != MC_LS_SETUP_INVALID ) && ( nblocks > 1 ) ) + test(); + IF( NE_32( q_direction->cfg.mc_ls_setup, MC_LS_SETUP_INVALID ) && GT_16( nblocks, 1 ) ) { push_next_indice( hMetaData, use_adapt_avg, 1 ); } - for ( idx = nblocks; idx < dist_count; idx++ ) + FOR( idx = nblocks; idx < dist_count; idx++ ) { - if ( make_gain == 1 && bits_gained < direction_bits_ec - max_bits && dist_azimuth_alphabets[idx] > 40 ) + test(); + test(); + IF( EQ_16( make_gain, 1 ) && LT_16( bits_gained, sub( direction_bits_ec, max_bits ) ) && GT_16( dist_azimuth_alphabets[idx], 40 ) ) { - if ( dist_azimuth_indexes_best[idx] > 1 ) + IF( GT_16( dist_azimuth_indexes_best[idx], 1 ) ) { - ivas_qmetadata_encode_extended_gr( hMetaData, dist_azimuth_indexes_best[idx] - 2, dist_azimuth_alphabets[idx], gr_param_azimuth_best ); - bits_gained += ivas_qmetadata_encode_extended_gr_length( dist_azimuth_indexes_best[idx], dist_azimuth_alphabets[idx], gr_param_azimuth_best ) - - ivas_qmetadata_encode_extended_gr_length( dist_azimuth_indexes_best[idx] - 2, dist_azimuth_alphabets[idx], gr_param_azimuth_best ); + ivas_qmetadata_encode_extended_gr( hMetaData, sub( dist_azimuth_indexes_best[idx], 2 ), dist_azimuth_alphabets[idx], gr_param_azimuth_best ); + bits_gained = add( bits_gained, sub( ivas_qmetadata_encode_extended_gr_length( dist_azimuth_indexes_best[idx], dist_azimuth_alphabets[idx], gr_param_azimuth_best ), + ivas_qmetadata_encode_extended_gr_length( sub( dist_azimuth_indexes_best[idx], 2 ), dist_azimuth_alphabets[idx], gr_param_azimuth_best ) ) ); } - else if ( dist_azimuth_indexes_best[idx] == 1 ) + ELSE IF( EQ_16( dist_azimuth_indexes_best[idx], 1 ) ) { - ivas_qmetadata_encode_extended_gr( hMetaData, dist_azimuth_indexes_best[idx] - 1, dist_azimuth_alphabets[idx], gr_param_azimuth_best ); - bits_gained += ivas_qmetadata_encode_extended_gr_length( dist_azimuth_indexes_best[idx], dist_azimuth_alphabets[idx], gr_param_azimuth_best ) - - ivas_qmetadata_encode_extended_gr_length( dist_azimuth_indexes_best[idx] - 1, dist_azimuth_alphabets[idx], gr_param_azimuth_best ); + ivas_qmetadata_encode_extended_gr( hMetaData, sub( dist_azimuth_indexes_best[idx], 1 ), dist_azimuth_alphabets[idx], gr_param_azimuth_best ); + bits_gained = add( bits_gained, sub( ivas_qmetadata_encode_extended_gr_length( dist_azimuth_indexes_best[idx], dist_azimuth_alphabets[idx], gr_param_azimuth_best ), + ivas_qmetadata_encode_extended_gr_length( sub( dist_azimuth_indexes_best[idx], 1 ), dist_azimuth_alphabets[idx], gr_param_azimuth_best ) ) ); } - else + ELSE { ivas_qmetadata_encode_extended_gr( hMetaData, dist_azimuth_indexes_best[idx], dist_azimuth_alphabets[idx], gr_param_azimuth_best ); } } - else + ELSE { ivas_qmetadata_encode_extended_gr( hMetaData, dist_azimuth_indexes_best[idx], dist_azimuth_alphabets[idx], gr_param_azimuth_best ); } @@ -4433,11 +4546,12 @@ static int16_t ivas_qmetadata_entropy_encode_dir( } } - direction_bits_ec -= bits_gained; + direction_bits_ec = sub( direction_bits_ec, bits_gained ); } - else + ELSE { direction_bits_ec = -1; + move16(); } return direction_bits_ec; @@ -4957,7 +5071,70 @@ static int16_t ivas_qmetadata_entropy_encode_dir( * * Main function for raw coding of the directions (writing and bit estimation) *------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +static Word16 ivas_qmetadata_raw_encode_dir_fx( + BSTR_ENC_HANDLE hMetaData, + IVAS_QDIRECTION *q_direction, + const Word16 nbands, + const Word16 start_band ) +{ + Word16 i, j; + Word16 direction_bits_raw; + Word16 start_bits = 0; /*To avoid compiler warning*/ + move16(); + + direction_bits_raw = 0; + move16(); + if ( hMetaData != NULL ) + { + start_bits = hMetaData->nb_bits_tot; + move16(); + } + + IF( q_direction->not_in_2D > 0 ) + { + FOR( i = start_band; i < nbands; i++ ) + { + IF( hMetaData != NULL ) + { + FOR( j = 0; j < q_direction->cfg.nblocks; j++ ) + { + push_next_indice( hMetaData, q_direction->band_data[i].spherical_index[j], q_direction->band_data[i].bits_sph_idx[j] ); + } + } + ELSE + { + direction_bits_raw = add( direction_bits_raw, imult1616( q_direction->cfg.nblocks, q_direction->band_data[i].bits_sph_idx[0] ) ); + } + } + } + ELSE + { + FOR( i = start_band; i < nbands; i++ ) + { + FOR( j = 0; j < q_direction->cfg.nblocks; j++ ) + { + IF( hMetaData != NULL ) + { + ivas_qmetadata_encode_quasi_uniform( hMetaData, q_direction->band_data[i].azimuth_index[j], q_direction->band_data[i].azimuth_m_alphabet[j] ); + } + ELSE + { + direction_bits_raw = add( direction_bits_raw, + ivas_qmetadata_encode_quasi_uniform_length( q_direction->band_data[i].azimuth_index[j], q_direction->band_data[i].azimuth_m_alphabet[j] ) ); + } + } + } + } + + if ( hMetaData != NULL ) + { + direction_bits_raw = sub( hMetaData->nb_bits_tot, start_bits ); + } + return direction_bits_raw; +} +#else static int16_t ivas_qmetadata_raw_encode_dir( BSTR_ENC_HANDLE hMetaData, IVAS_QDIRECTION *q_direction, @@ -5017,14 +5194,52 @@ static int16_t ivas_qmetadata_raw_encode_dir( return direction_bits_raw; } - +#endif /*------------------------------------------------------------------------- * ivas_qmetadata_get_optimal_gr_param() * * *------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +static Word16 ivas_qmetadata_get_optimal_gr_param_fx( + UWord16 *unsigned_data, + const Word16 count, + const Word16 gr_param_count, + Word16 *opt_gr_size ) +{ + Word16 opt_bits, bits, idx; + Word16 opt_gr_param; + Word16 p; + opt_bits = MAX16B; + move16(); + opt_gr_param = -1; + move16(); + + FOR( p = 0; p < gr_param_count; p++ ) + { + bits = imult1616( count, add( 1, p ) ); /* terminating zero bit and the lsb bits */ + FOR( idx = 0; idx < count; idx++ ) + { + bits = add( bits, extract_l( L_shr( unsigned_data[idx], p ) ) ); /* leading one bits */ + } + + IF( LT_16( bits, opt_bits ) ) + { + opt_gr_param = p; + move16(); + opt_bits = bits; + move16(); + } + } + + *opt_gr_size = opt_bits; + move16(); + + return opt_gr_param; +} +#else static int16_t ivas_qmetadata_get_optimal_gr_param( uint16_t *unsigned_data, const int16_t count, @@ -5057,7 +5272,7 @@ static int16_t ivas_qmetadata_get_optimal_gr_param( return opt_gr_param; } - +#endif /*------------------------------------------------------------------------- * ivas_qmetadata_encode_extended_gr_length() @@ -5146,7 +5361,34 @@ ivas_qmetadata_encode_extended_gr_length( * * *------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +static Word16 ivas_qmetadata_reorder_elevation_index_fx( + const Word16 elevation_index, + const Word16 avg_elevation_index, + const Word16 elevation_alphabet ) +{ + Word16 elevation_alphabet_half; + Word16 elevation_index_reordered; + + elevation_alphabet_half = shr( elevation_alphabet, 1 ); + elevation_index_reordered = sub( elevation_index, avg_elevation_index ); + /* reduce the distance for the index elevation to the range [-elevation_alphabet_half, elevation_alphabet_half] */ + IF( LT_16( elevation_index_reordered, negate( elevation_alphabet_half ) ) ) + { + elevation_index_reordered = add( elevation_index_reordered, elevation_alphabet ); + } + ELSE IF( GT_16( elevation_index_reordered, elevation_alphabet_half ) ) + { + elevation_index_reordered = sub( elevation_index_reordered, elevation_alphabet ); + } + + /* fold reduced signed distance value for converting to unsigned */ + elevation_index_reordered = ivas_qmetadata_reorder_generic( elevation_index_reordered ); + + return elevation_index_reordered; +} +#else static int16_t ivas_qmetadata_reorder_elevation_index( const int16_t elevation_index, const int16_t avg_elevation_index, @@ -5173,14 +5415,54 @@ static int16_t ivas_qmetadata_reorder_elevation_index( return elevation_index_reordered; } - +#endif /*------------------------------------------------------------------------- * ivas_qmetadata_reorder_azimuth_index() * * *------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +static Word16 ivas_qmetadata_reorder_azimuth_index_fx( + const Word16 azimuth_index, + const Word16 avg_azimuth_index, + const Word16 azimuth_alphabet ) +{ + Word16 azimuth_alphabet_half; + Word16 azimuth_index_reordered; + azimuth_index_reordered = sub( azimuth_index, avg_azimuth_index ); + + test(); + IF( NE_16( azimuth_alphabet, 1 ) && EQ_16( s_and( azimuth_alphabet, 0x01 ), 1 ) ) + { + return ( ivas_qmetadata_reorder_elevation_index_fx( azimuth_index, avg_azimuth_index, azimuth_alphabet ) ); + } + ELSE IF( NE_16( azimuth_alphabet, 1 ) ) + { + azimuth_alphabet_half = shr( azimuth_alphabet, 1 ); + /* reduce the distance for the index azimuth to the range [-azimuth_alphabet_half, azimuth_alphabet_half - 1] */ + IF( LT_16( azimuth_index_reordered, negate( azimuth_alphabet_half ) ) ) + { + azimuth_index_reordered = add( azimuth_index_reordered, azimuth_alphabet ); + } + ELSE IF( GT_16( azimuth_index_reordered, sub( azimuth_alphabet_half, 1 ) ) ) + { + azimuth_index_reordered = sub( azimuth_index_reordered, azimuth_alphabet ); + } + /* fold reduced signed distance value for converting to unsigned */ + azimuth_index_reordered = ivas_qmetadata_reorder_generic( azimuth_index_reordered ); + } + ELSE + { + /* for North and South poles, a single azimuth direction exists */ + azimuth_index_reordered = 0; + move16(); + } + + return azimuth_index_reordered; +} +#else static int16_t ivas_qmetadata_reorder_azimuth_index( const int16_t azimuth_index, const int16_t avg_azimuth_index, @@ -5218,7 +5500,7 @@ static int16_t ivas_qmetadata_reorder_azimuth_index( return azimuth_index_reordered; } - +#endif /*------------------------------------------------------------------------- * ivas_qmetadata_encode_extended_gr() diff --git a/lib_enc/ivas_qspherical_enc.c b/lib_enc/ivas_qspherical_enc.c index ccfda56b6..879cccf6a 100644 --- a/lib_enc/ivas_qspherical_enc.c +++ b/lib_enc/ivas_qspherical_enc.c @@ -289,7 +289,52 @@ void quantize_direction_frame_fx( * * *----------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void quantize_direction_frame2D_fx( + IVAS_QDIRECTION *q_direction, /* i/o: quantized direction structure */ + Word32 azimuth_orig[MASA_MAXIMUM_CODING_SUBBANDS][MAX_PARAM_SPATIAL_SUBFRAMES], // Q22 + Word32 elevation_orig[MASA_MAXIMUM_CODING_SUBBANDS][MAX_PARAM_SPATIAL_SUBFRAMES] ) // Q22 +{ + Word16 i, j; + UWord16 idx; + /* Quantize directions */ + q_direction->not_in_2D = 0; + move16(); + FOR( i = q_direction->cfg.start_band; i < q_direction->cfg.nbands; i++ ) + { + idx = q_direction->band_data[i].energy_ratio_index[0]; + move16(); + FOR( j = 0; j < q_direction->cfg.nblocks; j++ ) + { + if ( azimuth_orig != NULL ) + { + azimuth_orig[i][j] = q_direction->band_data[i].azimuth_fx[j]; + move32(); + } + if ( elevation_orig != NULL ) + { + elevation_orig[i][j] = q_direction->band_data[i].elevation_fx[j]; + move32(); + } + q_direction->band_data[i].azimuth_m_alphabet[j] = no_phi_masa[bits_direction_masa[idx] - 1][0]; + move16(); + + /* requantize the direction */ + q_direction->band_data[i].spherical_index[j] = quantize_direction2D_fx( q_direction->band_data[i].azimuth_fx[j], + q_direction->band_data[i].azimuth_m_alphabet[j], + &q_direction->band_data[i].azimuth_fx[j], + &q_direction->band_data[i].azimuth_index[j], + q_direction->cfg.mc_ls_setup ); + move16(); + + q_direction->band_data[i].elevation_m_alphabet[j] = 1; + move16(); + } + } + return; +} +#else void quantize_direction_frame2D( IVAS_QDIRECTION *q_direction, /* i/o: quantized direction structure */ float azimuth_orig[MASA_MAXIMUM_CODING_SUBBANDS][MAX_PARAM_SPATIAL_SUBFRAMES], @@ -327,14 +372,77 @@ void quantize_direction_frame2D( return; } - +#endif /*-------------------------------------------------------------------* * small_requantize_direction_frame() * * *----------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void small_requantize_direction_frame_fx( + IVAS_QDIRECTION *q_direction, /* i/o: quantized direction structure */ + Word32 azimuth_orig[MASA_MAXIMUM_CODING_SUBBANDS][MAX_PARAM_SPATIAL_SUBFRAMES], // Q22 + Word32 elevation_orig[MASA_MAXIMUM_CODING_SUBBANDS][MAX_PARAM_SPATIAL_SUBFRAMES], // Q22 + const Word16 raw_flag[MASA_MAXIMUM_CODING_SUBBANDS], + Word16 bits_dir_bands[MASA_MAXIMUM_CODING_SUBBANDS], + Word16 *diff ) +{ + Word16 i, j; + UWord16 bits_dir[MASA_MAXIMUM_CODING_SUBBANDS][MAX_PARAM_SPATIAL_SUBFRAMES]; + test(); + IF( ( *diff > 0 ) && ( q_direction->not_in_2D > 0 ) ) + { + FOR( i = q_direction->cfg.start_band; i < q_direction->cfg.nbands; i++ ) + { + FOR( j = 0; j < q_direction->cfg.nblocks; j++ ) + { + bits_dir[i][j] = q_direction->band_data[i].bits_sph_idx[j]; + move16(); + } + } + + small_reduction_direction( q_direction, bits_dir, raw_flag, diff ); + + IF( *diff <= 0 ) + { + FOR( i = q_direction->cfg.start_band; i < q_direction->cfg.nbands; i++ ) + { + IF( EQ_16( raw_flag[i], 1 ) ) + { + bits_dir_bands[i] = 0; + move16(); + FOR( j = 0; j < q_direction->cfg.nblocks; j++ ) + { + bits_dir_bands[i] = add( bits_dir_bands[i], bits_dir[i][j] ); + move16(); + q_direction->band_data[i].bits_sph_idx[j] = bits_dir[i][j]; + move16(); + + /* requantize the direction */ + q_direction->band_data[i].spherical_index[j] = quantize_direction_fx( + elevation_orig[i][j], azimuth_orig[i][j], + q_direction->band_data[i].bits_sph_idx[j], + &q_direction->band_data[i].elevation_fx[j], &q_direction->band_data[i].azimuth_fx[j], + &q_direction->band_data[i].elevation_index[j], &q_direction->band_data[i].azimuth_index[j], + q_direction->cfg.mc_ls_setup ); + move16(); + + if ( EQ_32( q_direction->band_data[i].azimuth_index[j], MASA_NO_INDEX ) ) + { + q_direction->band_data[i].azimuth_index[j] = 0; + move16(); + } + } + } + } + } + } + + return; +} +#else void small_requantize_direction_frame( IVAS_QDIRECTION *q_direction, /* i/o: quantized direction structure */ float azimuth_orig[MASA_MAXIMUM_CODING_SUBBANDS][MAX_PARAM_SPATIAL_SUBFRAMES], @@ -390,7 +498,7 @@ void small_requantize_direction_frame( return; } - +#endif /*-------------------------------------------------------------------* * quantize_direction() @@ -1155,11 +1263,11 @@ static Word32 quantize_theta_phi_fx( // Q22 IF( LT_16( id_th, sub( no_th, 1 ) ) ) { - Copy_Scale_sig32_16( theta_cb, theta_cb16, MAX_NO_THETA, -( Q22 - Q16 ) ); + Copy_Scale_sig32_16( theta_cb, theta_cb16, MAX_NO_THETA, 0 ); // Q6 - id_th = add( id_th, squant_fx( extract_l( L_shr( abs_theta, Q22 ) ), &theta_hat16, &theta_cb16[id_th], 2 ) ); + id_th = add( id_th, squant_fx( round_fx( abs_theta ), &theta_hat16, &theta_cb16[id_th], 2 ) ); - theta_hat = L_shl( L_deposit_l( theta_hat16 ), Q22 ); // Q0 -> Q22 + theta_hat = L_deposit_h( theta_hat16 ); // Q6 -> Q22 } IF( GT_16( no_th, 1 ) ) diff --git a/lib_enc/ivas_spar_md_enc.c b/lib_enc/ivas_spar_md_enc.c index 3dfa3ba70..6d1d81ecb 100644 --- a/lib_enc/ivas_spar_md_enc.c +++ b/lib_enc/ivas_spar_md_enc.c @@ -40,14 +40,21 @@ #include "ivas_prot_fx.h" #include "math.h" #include "ivas_rom_com.h" +#ifdef IVAS_FLOAT_FIXED +#include "ivas_rom_com_fx.h" +#endif #include #include "wmc_auto.h" /*------------------------------------------------------------------------------------------* * PreProcessor *------------------------------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED static const float pr_boost_range[2] = { 0.1f, 0.4f }; +#else +/*Q28*/ +static const Word32 pr_boost_range_fx[2] = { 26843546, 107374182 }; +#endif typedef enum ivas_strats_t { @@ -82,22 +89,35 @@ static void ivas_spar_set_enc_config_fx( ivas_spar_md_enc_state_t *hMdEnc, Word1 static void ivas_select_next_strat( ivas_strats_t prior_strat, ivas_strats_t cs[MAX_QUANT_STRATS], const int16_t dmx_switch, const int16_t dtx_vad ); +#ifdef IVAS_FLOAT_FIXED +static void ivas_store_prior_coeffs_fx( ivas_spar_md_enc_state_t *hMdEnc, const Word16 num_bands, const Word16 strat, const Word16 dtx_vad, const Word16 qsi ); +#else static void ivas_store_prior_coeffs( ivas_spar_md_enc_state_t *hMdEnc, const int16_t num_bands, const int16_t strat, const int16_t dtx_vad, const int16_t qsi ); - +#endif static void ivas_write_spar_md_bitstream( ivas_spar_md_enc_state_t *hMdEnc, const int16_t nB, const int16_t bands_bw, BSTR_ENC_HANDLE hMetaData, const int32_t ivas_total_brate, const int16_t strat, const int16_t qsi ); -static void ivas_spar_quant_pred_coeffs_dtx( ivas_spar_md_t *pSpar_md, const float *pValues, const int16_t ndm, int16_t *pIndex, const int16_t dim1, float *pQuant ); +#ifndef IVAS_FLOAT_FIXED +static void ivas_spar_quant_pred_coeffs_dtx( ivas_spar_md_t *pSpar_md, const float *pValues, const int16_t ndm, int16_t *pIndex, const int16_t dim1, float *pQuant ); static void ivas_quant_p_per_band_dtx( float *pP_mat, const int16_t num_dec, const int16_t num_dmx, int16_t *ppIdx_pd, float *pP_out, const int16_t num_ch ); - +#else +static void ivas_spar_quant_pred_coeffs_dtx_fx( ivas_spar_md_t *pSpar_md, const Word32 *pValues, const Word16 ndm, Word16 *pIndex, const Word16 dim1, Word32 *pQuant ); +static void ivas_quant_p_per_band_dtx_fx( Word32 *pP_mat, const Word16 num_dec, const Word16 num_dmx, Word16 *ppIdx_pd, Word32 *pP_out, const Word16 num_ch ); +#endif static void ivas_write_parameter_bitstream_dtx( ivas_spar_md_t *pSpar_md, BSTR_ENC_HANDLE hMetaData, int16_t *num_dmx, int16_t *num_dec, const int16_t num_bands ); +#ifndef IVAS_FLOAT_FIXED static void ivas_quant_p_per_band( ivas_band_coeffs_t *pband_coeffs, ivas_band_coeffs_ind_t *pBand_coeffs_idx, ivas_quant_strat_t *pQs, const int16_t num_ch ); - +#else +static void ivas_quant_p_per_band_fx( ivas_band_coeffs_t *pband_coeffs, ivas_band_coeffs_ind_t *pBand_coeffs_idx, ivas_quant_strat_t *pQs, const Word16 num_ch ); +#endif static void ivas_quant_c_per_band( ivas_band_coeffs_t *pband_coeffs, ivas_band_coeffs_ind_t *pBand_coeffs_idx, ivas_quant_strat_t *pQs, const int16_t ndec, const int16_t ndm ); +#ifndef IVAS_FLOAT_FIXED static void ivas_quant_pred_coeffs_per_band( ivas_band_coeffs_t *pband_coeffs, ivas_band_coeffs_ind_t *pBand_coeffs_idx, ivas_quant_strat_t *pQs, const int16_t num_ch ); - +#else +static void ivas_quant_pred_coeffs_per_band_fx( ivas_band_coeffs_t *pband_coeffs, ivas_band_coeffs_ind_t *pBand_coeffs_idx, ivas_quant_strat_t *pQs, const Word16 num_ch ); +#endif /*------------------------------------------------------------------------- * ivas_spar_md_enc_open() @@ -629,7 +649,11 @@ static void write_metadata_buffer( if ( hMetaData->nb_bits_tot > 0 ) { +#ifdef IVAS_FLOAT_FIXED + restore_metadata_buffer_fx( hMetaData, next_ind_start, bit_pos_start ); +#else restore_metadata_buffer( hMetaData, next_ind_start, bit_pos_start ); +#endif } for ( i = 0; i < hMetaData_tmp->nb_ind_tot; i++ ) @@ -864,72 +888,113 @@ ivas_error ivas_spar_md_enc_process_fx( } } code_strat = 0; - for ( qsi = 0; qsi < num_quant_strats; qsi++ ) + move16(); + FOR( qsi = 0; qsi < num_quant_strats; qsi++ ) { +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + hMdEnc->spar_md_cfg.quant_strat[qsi].P_r.min_fx = float_to_fix( hMdEnc->spar_md_cfg.quant_strat[qsi].P_r.min, Q28 ); + hMdEnc->spar_md_cfg.quant_strat[qsi].P_r.max_fx = float_to_fix( hMdEnc->spar_md_cfg.quant_strat[qsi].P_r.max, Q28 ); + hMdEnc->spar_md_cfg.quant_strat[qsi].PR.min_fx = float_to_fix( hMdEnc->spar_md_cfg.quant_strat[qsi].PR.min, Q28 ); + hMdEnc->spar_md_cfg.quant_strat[qsi].PR.max_fx = float_to_fix( hMdEnc->spar_md_cfg.quant_strat[qsi].PR.max, Q28 ); for ( b = 0; b < num_bands; b++ ) + { + for ( int ii = 0; ii < IVAS_SPAR_MAX_CH - 1; ii++ ) + { + hMdEnc->spar_md.band_coeffs[b].pred_re_fx[ii] = float_to_fix( hMdEnc->spar_md.band_coeffs[b].pred_re[ii], Q28 ); + hMdEnc->spar_md.band_coeffs[b].P_re_fx[ii] = float_to_fix( hMdEnc->spar_md.band_coeffs[b].P_re[ii], Q28 ); + } + } +#endif + FOR( b = 0; b < num_bands; b++ ) { ndm = hMdEnc->spar_md_cfg.num_dmx_chans_per_band[b * bands_bw]; + move16(); ndec = hMdEnc->spar_md_cfg.num_decorr_per_band[b * bands_bw]; + move16(); - if ( dtx_vad == 1 ) + IF( EQ_16( dtx_vad, 1 ) ) { - if ( ndm != num_ch ) + IF( NE_16( ndm, num_ch ) ) { - ivas_quant_p_per_band( &hMdEnc->spar_md.band_coeffs[b], &hMdEnc->spar_md.band_coeffs_idx[b], &hMdEnc->spar_md_cfg.quant_strat[qsi], num_ch ); + ivas_quant_p_per_band_fx( &hMdEnc->spar_md.band_coeffs[b], &hMdEnc->spar_md.band_coeffs_idx[b], &hMdEnc->spar_md_cfg.quant_strat[qsi], num_ch ); } - ivas_quant_pred_coeffs_per_band( &hMdEnc->spar_md.band_coeffs[b], &hMdEnc->spar_md.band_coeffs_idx[b], &hMdEnc->spar_md_cfg.quant_strat[qsi], num_ch ); - if ( active_w_vlbr ) + ivas_quant_pred_coeffs_per_band_fx( &hMdEnc->spar_md.band_coeffs[b], &hMdEnc->spar_md.band_coeffs_idx[b], &hMdEnc->spar_md_cfg.quant_strat[qsi], num_ch ); + IF( active_w_vlbr ) { - for ( i = 0; i < 3; i++ ) + FOR( i = 0; i < 3; i++ ) { - int16_t i2; + Word16 i2; i2 = 0; - switch ( i ) /* PRED (Y,Z,X) and DECD (Y,X,Z) coeffs are in different orders */ + move16(); + SWITCH( i ) /* PRED (Y,Z,X) and DECD (Y,X,Z) coeffs are in different orders */ { case 0: i2 = 0; - break; + move16(); + BREAK; case 1: i2 = 2; - break; + move16(); + BREAK; case 2: i2 = 1; - break; + move16(); + BREAK; } - if ( ( hMdEnc->spar_md.band_coeffs_idx[b].pred_index_re[i] == 0 ) && ( hMdEnc->spar_md.band_coeffs_idx[b].decd_index_re[i2] == 0 ) && ( hMdEnc->spar_md.band_coeffs[b].pred_re[i] != 0.0f ) && ( cov_real[i + 1][i + 1][b] != 0.0f ) ) + test(); + test(); + test(); + IF( ( hMdEnc->spar_md.band_coeffs_idx[b].pred_index_re[i] == 0 ) && ( hMdEnc->spar_md.band_coeffs_idx[b].decd_index_re[i2] == 0 ) && ( hMdEnc->spar_md.band_coeffs[b].pred_re_fx[i] != 0 ) && ( cov_real_fx[i + 1][i + 1][b] != 0 ) ) { /* bump up the Pred coeff */ - float PR_uq, PR_step; + Word32 PR_uq; + Word16 PR_step; ivas_quant_strat_t qs; + Word16 PR_step_e; qs = hMdEnc->spar_md_cfg.quant_strat[qsi]; - PR_uq = hMdEnc->spar_md.band_coeffs[b].pred_re[i]; - PR_step = ( qs.PR.max - qs.PR.min ) / ( qs.PR.q_levels[0] - 1 ); + PR_uq = hMdEnc->spar_md.band_coeffs[b].pred_re_fx[i]; + move32(); + PR_step = BASOP_Util_Divide3216_Scale( L_sub( qs.PR.max_fx, qs.PR.min_fx ), sub( qs.PR.q_levels[0], 1 ), &PR_step_e ); + PR_step_e = sub( PR_step_e, Q12 ); - int16_t PR_sign; - PR_sign = ( PR_uq > 0 ) - ( PR_uq < 0 ); + Word16 PR_sign; + PR_sign = sub( (Word16) ( GT_32( PR_uq, 0 ) ), (Word16) ( LT_32( PR_uq, 0 ) ) ); hMdEnc->spar_md.band_coeffs_idx[b].pred_index_re[i] = PR_sign; + move16(); /* deindex the modified coefficient */ - hMdEnc->spar_md.band_coeffs[b].pred_quant_re[i] = PR_sign * PR_step; + hMdEnc->spar_md.band_coeffs[b].pred_quant_re_fx[i] = L_shl( L_mult0( PR_sign, PR_step ), add( Q13, PR_step_e ) ); // Q28 + move32(); } } } } - else + ELSE { - if ( ndm != num_ch ) + IF( NE_16( ndm, num_ch ) ) { - ivas_quant_p_per_band_dtx( hMdEnc->spar_md.band_coeffs[b].P_re, ndec, ndm, &hMdEnc->spar_md.band_coeffs_idx[b].decd_index_re[0], hMdEnc->spar_md.band_coeffs[b].P_quant_re, num_ch ); + ivas_quant_p_per_band_dtx_fx( hMdEnc->spar_md.band_coeffs[b].P_re_fx, ndec, ndm, &hMdEnc->spar_md.band_coeffs_idx[b].decd_index_re[0], hMdEnc->spar_md.band_coeffs[b].P_quant_re_fx, num_ch ); } - for ( i = 0; i < num_ch - 1; i++ ) + FOR( i = 0; i < num_ch - 1; i++ ) { - hMdEnc->spar_md.band_coeffs[b].pred_quant_re[i] = 0; + hMdEnc->spar_md.band_coeffs[b].pred_quant_re_fx[i] = 0; + move32(); } - ivas_spar_quant_pred_coeffs_dtx( &hMdEnc->spar_md, hMdEnc->spar_md.band_coeffs[b].pred_re, ndm, hMdEnc->spar_md.band_coeffs_idx[b].pred_index_re, num_ch - 1, hMdEnc->spar_md.band_coeffs[b].pred_quant_re ); + ivas_spar_quant_pred_coeffs_dtx_fx( &hMdEnc->spar_md, hMdEnc->spar_md.band_coeffs[b].pred_re_fx, ndm, hMdEnc->spar_md.band_coeffs_idx[b].pred_index_re, sub( num_ch, 1 ), hMdEnc->spar_md.band_coeffs[b].pred_quant_re_fx ); } } +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + for ( b = 0; b < num_bands; b++ ) + { + for ( int ii = 0; ii < IVAS_SPAR_MAX_CH - 1; ii++ ) + { + hMdEnc->spar_md.band_coeffs[b].pred_quant_re[ii] = fix_to_float( hMdEnc->spar_md.band_coeffs[b].pred_quant_re_fx[ii], Q28 ); + hMdEnc->spar_md.band_coeffs[b].P_quant_re[ii] = fix_to_float( hMdEnc->spar_md.band_coeffs[b].P_quant_re_fx[ii], Q28 ); + } + } +#endif for ( i = 0; i < num_ch - 1; i++ ) { @@ -1068,10 +1133,12 @@ ivas_error ivas_spar_md_enc_process_fx( } } - ivas_store_prior_coeffs( hMdEnc, num_bands, code_strat, dtx_vad, qsi ); + ivas_store_prior_coeffs_fx( hMdEnc, num_bands, code_strat, dtx_vad, qsi ); hMdEnc->spar_md.dtx_vad = dtx_vad; + move16(); hMdEnc->spar_md.num_bands = num_bands; + move16(); free( ind_list_tmp ); @@ -2009,7 +2076,51 @@ static void ivas_select_next_strat( * * Store prior coeffs *-----------------------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +static void ivas_store_prior_coeffs_fx( + ivas_spar_md_enc_state_t *hMdEnc, + const Word16 num_bands, + const Word16 strat, + const Word16 dtx_vad, + const Word16 qsi ) +{ + Word16 i, j, b; + IF( dtx_vad == 0 ) + { + hMdEnc->spar_md_cfg.prior_strat = START; + move16(); + } + ELSE + { + hMdEnc->spar_md_cfg.prior_strat = strat; + move16(); + } + + hMdEnc->spar_md_cfg.prev_quant_idx = qsi; + move16(); + FOR( i = 0; i < num_bands; i++ ) + { + b = i; + move16(); + + FOR( j = 0; j < IVAS_SPAR_MAX_CH - 1; j++ ) + { + hMdEnc->spar_md_prior.band_coeffs_idx[i].pred_index_re[j] = hMdEnc->spar_md.band_coeffs_idx[b].pred_index_re[j]; + move16(); + hMdEnc->spar_md_prior.band_coeffs_idx[i].decd_index_re[j] = hMdEnc->spar_md.band_coeffs_idx[b].decd_index_re[j]; + move16(); + } + FOR( j = 0; j < IVAS_SPAR_MAX_C_COEFF; j++ ) + { + hMdEnc->spar_md_prior.band_coeffs_idx[i].drct_index_re[j] = hMdEnc->spar_md.band_coeffs_idx[b].drct_index_re[j]; + move16(); + } + } + + return; +} +#else static void ivas_store_prior_coeffs( ivas_spar_md_enc_state_t *hMdEnc, const int16_t num_bands, @@ -2046,14 +2157,42 @@ static void ivas_store_prior_coeffs( return; } - +#endif /*-----------------------------------------------------------------------------------------* * Function ivas_spar_quant_pred_coeffs_dtx() * * Calculate quantization pred coeffs *-----------------------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +static void ivas_spar_quant_pred_coeffs_dtx_fx( + ivas_spar_md_t *pSpar_md, + const Word32 *pValues, // Q28 + const Word16 ndm, + Word16 *pIndex, + const Word16 dim1, + Word32 *pQuant // Q28 +) +{ + Word16 i; + Word16 q_lvl; + Word32 pr_min_max[2]; + pr_min_max[0] = pSpar_md->min_max_fx[0]; // Q28 + move32(); + pr_min_max[1] = pSpar_md->min_max_fx[1]; // Q28 + move32(); + + FOR( i = 0; i < dim1; i++ ) + { + q_lvl = dtx_pr_real_q_levels[ndm - 1][i]; + move16(); + ivas_quantise_real_values_enc_fx( &pValues[i], q_lvl, pr_min_max[0], pr_min_max[1], &pIndex[i], &pQuant[i], 1 ); + } + + return; +} +#else static void ivas_spar_quant_pred_coeffs_dtx( ivas_spar_md_t *pSpar_md, const float *pValues, @@ -2077,6 +2216,7 @@ static void ivas_spar_quant_pred_coeffs_dtx( return; } +#endif /*-----------------------------------------------------------------------------------------* @@ -2084,7 +2224,7 @@ static void ivas_spar_quant_pred_coeffs_dtx( * * Calculate quantization p *-----------------------------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED static void ivas_quant_p_per_band_dtx( float *pP_mat, const int16_t num_dec, @@ -2119,7 +2259,44 @@ static void ivas_quant_p_per_band_dtx( return; } +#else +static void ivas_quant_p_per_band_dtx_fx( + Word32 *pP_mat, // Q28 + const Word16 num_dec, + const Word16 num_dmx, + Word16 *ppIdx_pd, + Word32 *pP_out, // Q28 + const Word16 num_ch ) +{ + Word16 i; + Word16 dim = sub( num_ch, num_dmx ); + IF( EQ_16( num_dec, sub( num_ch, 1 ) ) ) + { + FOR( i = 0; i < dim; i++ ) + { + test(); + IF( LT_32( pP_mat[i], pr_boost_range_fx[1] ) && GT_32( pP_mat[i], pr_boost_range_fx[0] ) ) + { + pP_mat[i] = pr_boost_range_fx[1]; // Q28 + move32(); + } + } + } + + IF( NE_16( dim, num_dec ) ) + { + assert( !"Not Supported!" ); + } + + FOR( i = 0; i < dim; i++ ) + { + ivas_quantise_real_values_enc_fx( &pP_mat[i], dtx_pd_real_q_levels[num_ch - num_dec - 1][i], dtx_pd_real_min_max_fx[0], dtx_pd_real_min_max_fx[1], &ppIdx_pd[i], &pP_out[i], 1 ); + } + + return; +} +#endif /*-----------------------------------------------------------------------------------------* * Function ivas_write_parameter_bitstream_dtx() * @@ -2216,7 +2393,18 @@ static void ivas_write_parameter_bitstream_dtx( * * Quantization of prediction coefficients *-----------------------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +static void ivas_quant_pred_coeffs_per_band_fx( + ivas_band_coeffs_t *pband_coeffs, + ivas_band_coeffs_ind_t *pBand_coeffs_idx, + ivas_quant_strat_t *pQs, + const Word16 num_ch ) +{ + ivas_quantise_real_values_enc_fx( pband_coeffs->pred_re_fx, pQs->PR.q_levels[0], pQs->PR.min_fx, pQs->PR.max_fx, pBand_coeffs_idx->pred_index_re, pband_coeffs->pred_quant_re_fx, sub( num_ch, 1 ) ); + return; +} +#else static void ivas_quant_pred_coeffs_per_band( ivas_band_coeffs_t *pband_coeffs, ivas_band_coeffs_ind_t *pBand_coeffs_idx, @@ -2227,7 +2415,7 @@ static void ivas_quant_pred_coeffs_per_band( return; } - +#endif /*-----------------------------------------------------------------------------------------* * Function ivas_quant_c_per_band() @@ -2274,7 +2462,18 @@ static void ivas_quant_c_per_band( * * Quantization of decorrelation p coeffs for each band *-----------------------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +static void ivas_quant_p_per_band_fx( + ivas_band_coeffs_t *pband_coeffs, + ivas_band_coeffs_ind_t *pBand_coeffs_idx, + ivas_quant_strat_t *pQs, + const Word16 num_ch ) +{ + ivas_quantise_real_values_enc_fx( pband_coeffs->P_re_fx, pQs->P_r.q_levels[0], pQs->P_r.min_fx, pQs->P_r.max_fx, pBand_coeffs_idx->decd_index_re, pband_coeffs->P_quant_re_fx, sub( num_ch, 1 ) ); + return; +} +#else static void ivas_quant_p_per_band( ivas_band_coeffs_t *pband_coeffs, ivas_band_coeffs_ind_t *pBand_coeffs_idx, @@ -2285,3 +2484,4 @@ static void ivas_quant_p_per_band( return; } +#endif diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h index c17621b8f..62d220da1 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -571,22 +571,20 @@ typedef struct stereo_td_enc_data_structure typedef struct stereo_tca_enc_data_structure { - Word16 refChanIndx; /* reference channel index in current frame */ - Word16 prevRefChanIndx; /* reference channel index in previous frame */ - Word16 indx_ica_NCShift; /* ICA target channel inter-channel corrstats */ - Word16 indx_ica_gD; /* ICA target gain */ + Word16 refChanIndx; /* reference channel index in current frame */ + Word16 prevRefChanIndx; /* reference channel index in previous frame */ + Word16 indx_ica_NCShift; /* ICA target channel inter-channel corrstats */ + Word16 indx_ica_gD; /* ICA target gain */ +#ifndef IVAS_FLOAT_FIXED float targetGain; /* gain norm applied on target (or right) channel in current frame */ float instTargetGain; /* instantaneous gain norm applied on target (or right) channel in current frame */ float prevTargetGain; /* gain norm applied on target (or right) channel in previous frame */ float corrStatsSmoothFac; /* gD/corrStats smoothing based on corrStats */ - +#endif Word32 targetGain_fx; /* gain norm applied on target (or right) channel in current frame //Q29 take from decoder*/ Word32 instTargetGain_fx; /* instantaneous gain norm applied on target (or right) channel in current frame //Q29*/ Word32 prevTargetGain_fx; /* gain norm applied on target (or right) channel in previous frame //Q29 taken from decoder*/ Word16 corrStatsSmoothFac_fx; /* gD/corrStats smoothing based on corrStats //Q15*/ - Word16 targetGain_fx_e; - Word16 instTargetGain_fx_e; - Word16 prevTargetGain_fx_e; Word16 lMemRecalc; Word16 lMemRecalc_12k8; @@ -595,22 +593,17 @@ typedef struct stereo_tca_enc_data_structure Word16 corrLagStats[3]; /* corr lag stats in current frame */ Word16 prevCorrLagStats[3]; /* corr lag stats in previous frame */ +#ifndef IVAS_FLOAT_FIXED float memChanL[L_MEM_RECALC_48K + L_MEM_RECALC_48k_SCH]; /* left channel input to correct at the cross-over */ float memChanR[L_MEM_RECALC_48K + L_MEM_RECALC_48k_SCH]; /* right channel input to correct at the cross-over */ float memChanL_DS[ADDED_MEM_DS]; /* left channel input speech memory for downmix */ float memChanR_DS[ADDED_MEM_DS]; /* right channel input speech memory for downmix */ -#ifndef IVAS_FLOAT_FIXED float mem_tempF; -#endif - float memdecim[12]; /* memory for pre-rmphasis filter for resampling */ -#ifndef IVAS_FLOAT_FIXED + float memdecim[12]; /* memory for pre-rmphasis filter for resampling */ float corrEstPrev[3][2 * L_NCSHIFT_DS + 1]; /* Prev correlation vector */ float corrEstLT[2 * L_NCSHIFT_DS + 1]; /* Long term correlation vector smoothed */ float ica_envVarLT; -#endif - -#ifndef IVAS_FLOAT_FIXED float C_mem[2 * L_NCSHIFT_DS + 1]; float E1_mem, E2_mem; float delay_0_mem[MAX_DELAYREGLEN]; @@ -619,9 +612,10 @@ typedef struct stereo_tca_enc_data_structure Word32 memChanL_fx[L_MEM_RECALC_48K + L_MEM_RECALC_48k_SCH]; /* left channel input to correct at the cross-over */ Word32 memChanR_fx[L_MEM_RECALC_48K + L_MEM_RECALC_48k_SCH]; /* right channel input to correct at the cross-over */ - + Word16 memChan_q; Word32 memChanL_DS_fx[ADDED_MEM_DS]; /* left channel input speech memory for downmix */ Word32 memChanR_DS_fx[ADDED_MEM_DS]; /* right channel input speech memory for downmix */ + Word16 memChan_DS_q; Word32 mem_tempF_fx; Word16 mem_tempF_exp; Word32 memdecim_fx[12]; /* memory for pre-rmphasis filter for resampling */ @@ -933,6 +927,10 @@ typedef struct ivas_dirac_enc_data_structure float **direction_vector[DIRAC_NUM_DIMS]; float **direction_vector_m[DIRAC_NUM_DIMS]; /* Average direction vector */ float diffuseness_m[DIRAC_MAX_NBANDS]; +#ifdef IVAS_FLOAT_FIXED + Word32 **direction_vector_m_fx[DIRAC_NUM_DIMS]; /* Average direction vector */ + Word32 diffuseness_m_fx[DIRAC_MAX_NBANDS]; +#endif int16_t band_grouping[DIRAC_MAX_NBANDS + 1]; int16_t block_grouping[5]; int16_t firstrun_sector_params; @@ -1100,6 +1098,8 @@ typedef struct ivas_param_mc_enc_data_structure float ener_fac[PARAM_MC_MAX_PARAMETER_BANDS]; + Word32 ener_fac_fx[PARAM_MC_MAX_PARAMETER_BANDS]; /*Q21*/ + } PARAM_MC_ENC_DATA, *PARAM_MC_ENC_HANDLE; /*----------------------------------------------------------------------------------* @@ -1238,10 +1238,14 @@ typedef struct ivas_masa_encoder_data_struct SPHERICAL_GRID_DATA Sph_Grid16; float lfeToTotalEnergyRatio[MAX_PARAM_SPATIAL_SUBFRAMES]; #ifdef IVAS_FLOAT_FIXED + Word32 importanceWeight_fx[MASA_FREQUENCY_BANDS]; Word32 lfeToTotalEnergyRatio_fx[MAX_PARAM_SPATIAL_SUBFRAMES]; Word16 lfeToTotalEnergyRatio_e[MAX_PARAM_SPATIAL_SUBFRAMES]; #endif float prevq_lfeToTotalEnergyRatio; +#ifdef IVAS_FLOAT_FIXED + Word32 prevq_lfeToTotalEnergyRatio_fx; // Q31 +#endif int16_t prevq_lfeIndex; float onset_detector_1; diff --git a/lib_enc/ivas_stereo_ica_enc.c b/lib_enc/ivas_stereo_ica_enc.c index 1bbd497e5..6cad92d83 100644 --- a/lib_enc/ivas_stereo_ica_enc.c +++ b/lib_enc/ivas_stereo_ica_enc.c @@ -1814,7 +1814,7 @@ static void estDownmixGain_fx( { currentGain_e = norm_l( hStereoTCA->prevTargetGain_fx ); currentGain = extract_h( L_shl( hStereoTCA->prevTargetGain_fx, currentGain_e ) ); - currentGain_e = add( currentGain_e, hStereoTCA->prevTargetGain_fx_e ); + currentGain_e = add( currentGain_e, 2 ); } ELSE { @@ -1824,12 +1824,10 @@ static void estDownmixGain_fx( } currentGain = s_max( EPSILON_FX, currentGain ); - hStereoTCA->instTargetGain_fx = L_deposit_h( currentGain ); + hStereoTCA->instTargetGain_fx = L_shl_sat( L_deposit_h( currentGain ), sub( currentGain_e, 2 ) ); move32(); - hStereoTCA->instTargetGain_fx_e = currentGain_e; - move16(); - prevTargetGain_log10 = BASOP_Util_Log10( hStereoTCA->prevTargetGain_fx, hStereoTCA->prevTargetGain_fx_e ); // Output in Q25 - currentGain_log10 = BASOP_Util_Log10( L_deposit_h( currentGain ), currentGain_e ); // Output in Q25 + prevTargetGain_log10 = BASOP_Util_Log10( hStereoTCA->prevTargetGain_fx, 2 ); // Output in Q25 + currentGain_log10 = BASOP_Util_Log10( L_deposit_h( currentGain ), currentGain_e ); // Output in Q25 // multiplication result will be Q25 should be fit to Q15 hence right shift by 10. // Q25 - Q10 = Q15 currentGain = extract_l( L_shr( Madd_32_16( Mpy_32_16_1( prevTargetGain_log10, alpha ), currentGain_log10, sub( MAX_16, alpha ) ), Q10 ) ); @@ -1892,9 +1890,12 @@ static void estDownmixGain_fx( // 10 ^ temp = 2 ^ (3.32192809488 * temp) // 3.32192809488 in Q13 27213 // exponent of power function input will be 2 more since constant is in Q13 - hStereoTCA->targetGain_fx = BASOP_util_Pow2( L_mult( temp, 27213 ), add( currentGain_e, 2 ), &hStereoTCA->targetGain_fx_e ); + exp = 2; + move16(); + hStereoTCA->targetGain_fx = BASOP_util_Pow2( L_mult( temp, 27213 ), add( currentGain_e, 2 ), &exp ); + move32(); + hStereoTCA->targetGain_fx = L_shl( hStereoTCA->targetGain_fx, sub( exp, 2 ) ); // Q29 move32(); - return; } #else @@ -2249,27 +2250,18 @@ static void icaMemUpdate( * Downmix, convert L/R to M/S. * ---------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED -void stereo_tca_enc( - CPE_ENC_HANDLE hCPE, /* i : CPE encoder structure */ - const int16_t input_frame /* i : length of a frame per channel */ +void stereo_tca_enc_fx( + CPE_ENC_HANDLE hCPE, /* i : CPE encoder structure */ + const Word16 input_frame /* i : length of a frame per channel */ ) { /* temp variables */ - int16_t i, dsFactor, lMemRecalc; + Word16 i, dsFactor, lMemRecalc; Encoder_State **sts; STEREO_TCA_ENC_HANDLE hStereoTCA; /* Buffers, input Left and right channels @ input_Fs*/ - int16_t lMemRecalc_SCh; - float bufChanL[L_MEM_RECALC_48K + L_MEM_RECALC_48k_SCH + L_FRAME48k + L_NCSHIFTMAX]; - float bufChanR[L_MEM_RECALC_48K + L_MEM_RECALC_48k_SCH + L_FRAME48k + L_NCSHIFTMAX]; - float input_mem_loc[2][NS2SA( 48000, L_MEM_RECALC_NS + L_MEM_RECALC_SCH_NS )]; - float *ptrChanL, *ptrChanR; -#ifdef IVAS_FLOAT_FIXED - set_f( bufChanL, 0.0, L_MEM_RECALC_48K + L_MEM_RECALC_48k_SCH + L_FRAME48k + L_NCSHIFTMAX ); - set_f( bufChanR, 0.0, L_MEM_RECALC_48K + L_MEM_RECALC_48k_SCH + L_FRAME48k + L_NCSHIFTMAX ); - set_f( input_mem_loc[0], 0.0, NS2SA( 48000, L_MEM_RECALC_NS + L_MEM_RECALC_SCH_NS ) ); - set_f( input_mem_loc[1], 0.0, NS2SA( 48000, L_MEM_RECALC_NS + L_MEM_RECALC_SCH_NS ) ); + Word16 lMemRecalc_SCh; Word32 input_mem_loc_fx[2][NS2SA( 48000, L_MEM_RECALC_NS + L_MEM_RECALC_SCH_NS )]; Word32 bufChanL_fx[L_MEM_RECALC_48K + L_MEM_RECALC_48k_SCH + L_FRAME48k + L_NCSHIFTMAX]; Word32 bufChanR_fx[L_MEM_RECALC_48K + L_MEM_RECALC_48k_SCH + L_FRAME48k + L_NCSHIFTMAX]; @@ -2279,335 +2271,324 @@ void stereo_tca_enc( set32_fx( bufChanR_fx, 0, L_MEM_RECALC_48K + L_MEM_RECALC_48k_SCH + L_FRAME48k + L_NCSHIFTMAX ); set32_fx( input_mem_loc_fx[0], 0, NS2SA( 48000, L_MEM_RECALC_NS + L_MEM_RECALC_SCH_NS ) ); set32_fx( input_mem_loc_fx[1], 0, NS2SA( 48000, L_MEM_RECALC_NS + L_MEM_RECALC_SCH_NS ) ); -#endif /* Buffers at internal sampling rate, i.e., CORR_INTER_FS */ - float bufChanL_DS[L_FRAME_DS + ADDED_MEM_DS]; - float bufChanR_DS[L_FRAME_DS + ADDED_MEM_DS]; - float *ptrChanL_DS, *ptrChanR_DS; -#ifdef IVAS_FLOAT_FIXED Word32 bufChanL_DS_fx[L_FRAME_DS + ADDED_MEM_DS]; Word32 bufChanR_DS_fx[L_FRAME_DS + ADDED_MEM_DS]; Word32 *ptrChanL_DS_fx, *ptrChanR_DS_fx; -#endif - float *target; -#ifdef IVAS_FLOAT_FIXED Word32 *target_fx; -#endif - int16_t target_idx; + Word16 target_idx; - int16_t prevNCShift, currentNCShift; - int16_t tempLag[2]; - float corrEstStage2[N_MAX_SHIFT_CHANGE + 1]; -#ifdef IVAS_FLOAT_FIXED + Word16 prevNCShift, currentNCShift; + Word16 tempLag[2]; Word32 corrEstStage2_fx[N_MAX_SHIFT_CHANGE + 1]; Word16 corrEstStage2_exp; - Word16 q_com; -#endif -#ifdef IVAS_FLOAT_FIXED - Word16 q_target; -#endif + Word16 q_com, bufChan_q, input_mem_loc_q; /* temp variables */ - float tempF, tempF1; -#ifdef IVAS_FLOAT_FIXED - Word32 tempF1_fx; + Word32 tempF1_fx, tempF_fx; Word16 tempF1_exp; -#endif - int16_t tempS, tempS_buff[3]; - int16_t maxCorrStatsDev, L_shift_adapt; - int16_t musicMode = 0, neighborLimit; - int32_t input_Fs; - int16_t prev_ICA_flag; + Word16 tempS, tempS_buff[3]; + Word16 maxCorrStatsDev, L_shift_adapt; + Word16 musicMode = 0, neighborLimit; + move16(); + Word32 input_Fs; + Word16 prev_ICA_flag; /* initialization */ sts = hCPE->hCoreCoder; hStereoTCA = hCPE->hStereoTCA; input_Fs = sts[0]->input_Fs; + move32(); + + q_com = sts[0]->q_inp32; + move16(); lMemRecalc = NS2SA( input_Fs, L_MEM_RECALC_NS ); + move16(); lMemRecalc_SCh = NS2SA( input_Fs, L_MEM_RECALC_SCH_NS ); + move16(); - if ( hCPE->element_mode == IVAS_CPE_MDCT ) + IF( EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) ) { return; } /* populate L/R memories into current buffers */ - mvr2r( hStereoTCA->memChanL, bufChanL, lMemRecalc + lMemRecalc_SCh ); - mvr2r( hStereoTCA->memChanR, bufChanR, lMemRecalc + lMemRecalc_SCh ); - + Word16 tempp_scale = getScaleFactor32( hStereoTCA->memChanL_fx, L_MEM_RECALC_48K + L_MEM_RECALC_48k_SCH ); + tempp_scale = s_min( tempp_scale, getScaleFactor32( hStereoTCA->memChanR_fx, L_MEM_RECALC_48K + L_MEM_RECALC_48k_SCH ) ); + scale_sig32( hStereoTCA->memChanL_fx, L_MEM_RECALC_48K + L_MEM_RECALC_48k_SCH, tempp_scale ); + scale_sig32( hStereoTCA->memChanR_fx, L_MEM_RECALC_48K + L_MEM_RECALC_48k_SCH, tempp_scale ); + hStereoTCA->memChan_q = add( hStereoTCA->memChan_q, tempp_scale ); + move16(); + Copy32( hStereoTCA->memChanL_fx, bufChanL_fx, add( lMemRecalc, lMemRecalc_SCh ) ); + Copy32( hStereoTCA->memChanR_fx, bufChanR_fx, add( lMemRecalc, lMemRecalc_SCh ) ); + bufChan_q = hStereoTCA->memChan_q; + move16(); /* pointers to the current frame */ - ptrChanL = bufChanL + lMemRecalc + lMemRecalc_SCh; - ptrChanR = bufChanR + lMemRecalc + lMemRecalc_SCh; -#ifdef IVAS_FLOAT_FIXED - ptrChanL_fx = bufChanL_fx + lMemRecalc + lMemRecalc_SCh; - ptrChanR_fx = bufChanR_fx + lMemRecalc + lMemRecalc_SCh; -#endif + ptrChanL_fx = bufChanL_fx + add( lMemRecalc, lMemRecalc_SCh ); // Q:bufChan_q + ptrChanR_fx = bufChanR_fx + add( lMemRecalc, lMemRecalc_SCh ); // Q:bufChan_q + /* copy interleaved stereo data to two channels, e.g., L, R */ - mvr2r( sts[0]->input, ptrChanL, input_frame ); - mvr2r( sts[1]->input, ptrChanR, input_frame ); + Copy32( sts[0]->input32_fx, ptrChanL_fx, input_frame ); + Copy32( sts[1]->input32_fx, ptrChanR_fx, input_frame ); + /* Scaling buffers to common Q*/ + scale_sig32( ptrChanL_fx, input_frame, sub( s_min( q_com, bufChan_q ), q_com ) ); + scale_sig32( ptrChanR_fx, input_frame, sub( s_min( q_com, bufChan_q ), q_com ) ); + scale_sig32( bufChanL_fx, add( lMemRecalc, lMemRecalc_SCh ), sub( s_min( q_com, bufChan_q ), bufChan_q ) ); + scale_sig32( bufChanR_fx, add( lMemRecalc, lMemRecalc_SCh ), sub( s_min( q_com, bufChan_q ), bufChan_q ) ); + bufChan_q = s_min( q_com, bufChan_q ); + q_com = bufChan_q; + move16(); /* UNCLR classifier update */ - if ( hCPE->hStereoClassif->lrtd_mode == 0 ) /* Normal TD mode, no attenuation */ + IF( hCPE->hStereoClassif->lrtd_mode == 0 ) /* Normal TD mode, no attenuation */ { hStereoTCA->LRTD_G_ATT_cnt = 1; + move16(); } - else if ( hCPE->hStereoTD != NULL ) + ELSE IF( hCPE->hStereoTD != NULL ) { - if ( hCPE->hStereoTD->tdm_LRTD_flag == 0 ) /* lrtd_mode == 1, but in td section */ + IF( hCPE->hStereoTD->tdm_LRTD_flag == 0 ) /* lrtd_mode == 1, but in td section */ { - hStereoTCA->LRTD_G_ATT_cnt++; - hStereoTCA->LRTD_G_ATT_cnt = min( 1000, hStereoTCA->LRTD_G_ATT_cnt ); + hStereoTCA->LRTD_G_ATT_cnt = add( hStereoTCA->LRTD_G_ATT_cnt, 1 ); + move16(); + hStereoTCA->LRTD_G_ATT_cnt = s_min( 1000, hStereoTCA->LRTD_G_ATT_cnt ); + move16(); } } - if ( hCPE->element_mode != IVAS_CPE_TD ) + IF( NE_16( hCPE->element_mode, IVAS_CPE_TD ) ) { hStereoTCA->refChanIndx = L_CH_INDX; - hStereoTCA->corrStatsSmoothFac = 0.7f; -#ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - q_com = L_get_q_buf1( ptrChanL, input_frame ); - // worst case input_frame value is 960 so taking 10 as guard bits - q_com = s_min( q_com, L_get_q_buf1( ptrChanR, input_frame ) ) - 10; - - floatToFixed_arrL32( ptrChanL, ptrChanL_fx, q_com, input_frame ); // not modified - floatToFixed_arrL32( ptrChanR, ptrChanR_fx, q_com, input_frame ); - q_target = L_get_q_buf1( &hStereoTCA->prevTargetGain, 1 ); - hStereoTCA->prevTargetGain_fx = float_to_fix( hStereoTCA->prevTargetGain, q_target ); - hStereoTCA->prevTargetGain_fx_e = Q31 - q_target; - hStereoTCA->corrStatsSmoothFac_fx = float_to_fix16( hStereoTCA->corrStatsSmoothFac, Q15 ); -#endif + move16(); + hStereoTCA->corrStatsSmoothFac_fx = 22938 /*0.7 in Q15 */; + move16(); estDownmixGain_fx( hStereoTCA, ptrChanL_fx, ptrChanR_fx, q_com, 0, input_frame, hCPE->element_mode, NULL, 0 ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - hStereoTCA->instTargetGain = fix_to_float( hStereoTCA->instTargetGain_fx, Q31 - hStereoTCA->instTargetGain_fx_e ); - hStereoTCA->targetGain = fix_to_float( hStereoTCA->targetGain_fx, Q31 - hStereoTCA->targetGain_fx_e ); -#endif -#else - estDownmixGain( hStereoTCA, ptrChanL, ptrChanR, 0, input_frame, hCPE->element_mode, NULL, 0 ); -#endif - - hStereoTCA->prevTargetGain = hStereoTCA->targetGain; -#ifdef DEBUG_MODE_INFO - hStereoTCA->indx_ica_NCShift = 0; -#endif + hStereoTCA->prevTargetGain_fx = hStereoTCA->targetGain_fx; + move16(); /* back up the L/R missing target */ - mvr2r( bufChanL + input_frame, hStereoTCA->memChanL, lMemRecalc + lMemRecalc_SCh ); - mvr2r( bufChanR + input_frame, hStereoTCA->memChanR, lMemRecalc + lMemRecalc_SCh ); - + Copy32( bufChanL_fx + input_frame, hStereoTCA->memChanL_fx, add( lMemRecalc, lMemRecalc_SCh ) ); // bufChan_q + Copy32( bufChanR_fx + input_frame, hStereoTCA->memChanR_fx, add( lMemRecalc, lMemRecalc_SCh ) ); // bufChan_q + hStereoTCA->memChan_q = q_com; + move16(); hStereoTCA->lMemRecalc = 0; + move16(); hStereoTCA->lMemRecalc_12k8 = 0; + move16(); hStereoTCA->lMemRecalc_16k = 0; + move16(); return; } - else if ( hCPE->last_element_mode != IVAS_CPE_TD ) + ELSE IF( NE_16( hCPE->last_element_mode, IVAS_CPE_TD ) ) { - tempF = hStereoTCA->targetGain; - tempF1 = hStereoTCA->prevTargetGain; + tempF_fx = hStereoTCA->targetGain_fx; // Q29 + move32(); + tempF1_fx = hStereoTCA->prevTargetGain_fx; // Q29 + move32(); tempS = hStereoTCA->prevRefChanIndx; - mvs2s( hStereoTCA->prevCorrLagStats, tempS_buff, 3 ); - stereo_tca_init_enc( hStereoTCA, input_Fs ); -#ifdef IVAS_FLOAT_FIXED + move16(); + + Copy( hStereoTCA->prevCorrLagStats, tempS_buff, 3 ); + stereo_tca_init_enc_fx( hStereoTCA, input_Fs ); -#endif - hStereoTCA->targetGain = tempF; - hStereoTCA->prevTargetGain = tempF1; - if ( hCPE->hStereoClassif->lrtd_mode == 1 ) + hStereoTCA->targetGain_fx = tempF_fx; // Q29 + move32(); + hStereoTCA->prevTargetGain_fx = tempF1_fx; // Q29 + move32(); + + IF( EQ_16( hCPE->hStereoClassif->lrtd_mode, 1 ) ) { - hStereoTCA->targetGain = min( hStereoTCA->targetGain, 1.0f ); - hStereoTCA->prevTargetGain = min( hStereoTCA->prevTargetGain, 1.0f ); + hStereoTCA->targetGain_fx = L_min( hStereoTCA->targetGain_fx, ONE_IN_Q29 ); // Q29 + move32(); + hStereoTCA->prevTargetGain_fx = L_min( hStereoTCA->prevTargetGain_fx, ONE_IN_Q29 ); // Q29 + move32(); - hStereoTCA->prevTargetGain = 1; + hStereoTCA->prevTargetGain_fx = ONE_IN_Q29; // Q29 + move32(); } hStereoTCA->prevRefChanIndx = tempS; - mvs2s( tempS_buff, hStereoTCA->prevCorrLagStats, 3 ); + move16(); + Copy( tempS_buff, hStereoTCA->prevCorrLagStats, 3 ); /* populate memory */ - if ( hCPE->last_element_mode == IVAS_CPE_MDCT ) + IF( EQ_16( hCPE->last_element_mode, IVAS_CPE_MDCT ) ) { - mvr2r( sts[0]->input - lMemRecalc - lMemRecalc_SCh, bufChanL, lMemRecalc + lMemRecalc_SCh ); - mvr2r( sts[1]->input - lMemRecalc - lMemRecalc_SCh, bufChanR, lMemRecalc + lMemRecalc_SCh ); + Copy32( sts[0]->input32_fx - add( lMemRecalc, lMemRecalc_SCh ), bufChanL_fx, add( lMemRecalc, lMemRecalc_SCh ) ); + Copy32( sts[1]->input32_fx - add( lMemRecalc, lMemRecalc_SCh ), bufChanR_fx, add( lMemRecalc, lMemRecalc_SCh ) ); } } /* populate L/R DS memories into current buffers */ - mvr2r( hStereoTCA->memChanL_DS, bufChanL_DS, ADDED_MEM_DS ); - mvr2r( hStereoTCA->memChanR_DS, bufChanR_DS, ADDED_MEM_DS ); + Copy32( hStereoTCA->memChanL_DS_fx, bufChanL_DS_fx, ADDED_MEM_DS ); // hStereoTCA->memChan_DS_q + Copy32( hStereoTCA->memChanR_DS_fx, bufChanR_DS_fx, ADDED_MEM_DS ); // hStereoTCA->memChan_DS_q + + scale_sig32( bufChanL_fx, L_MEM_RECALC_48K + L_MEM_RECALC_48k_SCH + L_FRAME48k + L_NCSHIFTMAX, sub( s_min( hStereoTCA->memChan_DS_q, bufChan_q ), bufChan_q ) ); // s_min( hStereoTCA->memChan_DS_q, bufChan_q ) + scale_sig32( bufChanR_fx, L_MEM_RECALC_48K + L_MEM_RECALC_48k_SCH + L_FRAME48k + L_NCSHIFTMAX, sub( s_min( hStereoTCA->memChan_DS_q, bufChan_q ), bufChan_q ) ); // s_min( hStereoTCA->memChan_DS_q, bufChan_q ) + + scale_sig32( bufChanL_DS_fx, ADDED_MEM_DS, sub( s_min( hStereoTCA->memChan_DS_q, bufChan_q ), hStereoTCA->memChan_DS_q ) ); // s_min( hStereoTCA->memChan_DS_q, bufChan_q ) + scale_sig32( bufChanR_DS_fx, ADDED_MEM_DS, sub( s_min( hStereoTCA->memChan_DS_q, bufChan_q ), hStereoTCA->memChan_DS_q ) ); // s_min( hStereoTCA->memChan_DS_q, bufChan_q ) + + bufChan_q = s_min( hStereoTCA->memChan_DS_q, bufChan_q ); + q_com = bufChan_q; + move16(); + hStereoTCA->memChan_DS_q = bufChan_q; + move16(); /* pointers to the current frame of DS */ - ptrChanL_DS = bufChanL_DS + ADDED_MEM_DS; - ptrChanR_DS = bufChanR_DS + ADDED_MEM_DS; -#ifdef IVAS_FLOAT_FIXED + ptrChanL_DS_fx = bufChanL_DS_fx + ADDED_MEM_DS; ptrChanR_DS_fx = bufChanR_DS_fx + ADDED_MEM_DS; -#endif + /* resample factor */ - dsFactor = (int16_t) ( input_Fs / CORR_INTER_FS ); + dsFactor = (Word16) Mpy_32_32( input_Fs, 268436 /* 1/CORR_INTER_FS in Q31*/ ); // Q0 /* resample the stereo channels */ -#ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - q_com = L_get_q_buf1( ptrChanL, input_frame ); - q_com = min( q_com, L_get_q_buf1( ptrChanR, input_frame ) ); - q_com = min( q_com, L_get_q_buf1( hStereoTCA->memdecim, 12 ) ) - 4; - - floatToFixed_arrL32( ptrChanL, ptrChanL_fx, q_com, input_frame ); - floatToFixed_arrL32( ptrChanR, ptrChanR_fx, q_com, input_frame ); - floatToFixed_arrL32( hStereoTCA->memdecim, hStereoTCA->memdecim_fx, q_com, 12 ); -#endif - deEmphResample( hStereoTCA, ptrChanL_fx, ptrChanR_fx, ptrChanL_DS_fx, ptrChanR_DS_fx, input_frame, dsFactor ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arrL32( ptrChanL_DS_fx, ptrChanL_DS, q_com, input_frame / dsFactor ); - fixedToFloat_arrL32( ptrChanR_DS_fx, ptrChanR_DS, q_com, input_frame / dsFactor ); - fixedToFloat_arrL32( hStereoTCA->memdecim_fx, hStereoTCA->memdecim, q_com, 12 ); -#endif -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - -#endif -#else - deEmphResample( hStereoTCA, ptrChanL, ptrChanR, ptrChanL_DS, ptrChanR_DS, input_frame, dsFactor ); -#endif /**********************NEED to Allign first 40 index in each channel ************************************/ /* inter-channel corrStats estimation */ -#ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - q_com = L_get_q_buf1( bufChanL_DS, L_FRAME_DS + ADDED_MEM_DS ); - q_com = min( q_com, L_get_q_buf1( bufChanR_DS, L_FRAME_DS + ADDED_MEM_DS ) ) - 4; - - floatToFixed_arrL32( bufChanL_DS, bufChanL_DS_fx, q_com, L_FRAME_DS + ADDED_MEM_DS ); - floatToFixed_arrL32( bufChanR_DS, bufChanR_DS_fx, q_com, L_FRAME_DS + ADDED_MEM_DS ); - hStereoTCA->prevTargetGain_fx = floatToFixed_32( hStereoTCA->prevTargetGain, Q29 ); -#endif - corrStatsEst_fx( hStereoTCA, bufChanL_DS_fx + ADDED_MEM_DS, bufChanR_DS_fx + ADDED_MEM_DS, q_com, ( L_FRAME_DS + L_XCORRMEM_DS ), dsFactor, hCPE->hCoreCoder[0]->vad_flag, hCPE->hCoreCoder[1]->vad_flag, hCPE->hStereoClassif ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - hStereoTCA->corrStatsSmoothFac = me2f_16( hStereoTCA->corrStatsSmoothFac_fx, 0 ); -#endif -#else - corrStatsEst( hStereoTCA, bufChanL_DS + ADDED_MEM_DS, bufChanR_DS + ADDED_MEM_DS, ( L_FRAME_DS + L_XCORRMEM_DS ), dsFactor, hCPE->hCoreCoder[0]->vad_flag, hCPE->hCoreCoder[1]->vad_flag, hCPE->hStereoClassif ); -#endif /*-----------------------------------------------------------------* * refine the ICA stats *-----------------------------------------------------------------*/ prev_ICA_flag = 0; + move16(); + test(); if ( hCPE->hStereoTD->prev_fr_LRTD_TD_dec && abs( hStereoTCA->prevCorrLagStats[2] ) != 0 ) { prev_ICA_flag = 1; + move16(); } - if ( hCPE->hStereoTD->prev_fr_LRTD_TD_dec == 0 || prev_ICA_flag == 1 ) + test(); + IF( hCPE->hStereoTD->prev_fr_LRTD_TD_dec == 0 || EQ_16( prev_ICA_flag, 1 ) ) { /* initialize the refinement search for NC-shift */ hStereoTCA->corrLagStats[2] = hStereoTCA->corrLagStats[1]; - + move16(); maxCorrStatsDev = N_MAX_SHIFT_CHANGE; - if ( hStereoTCA->corrStatsSmoothFac <= 0.7f ) + move16(); + if ( LE_16( hStereoTCA->corrStatsSmoothFac_fx, 22938 /*0.7f*/ ) ) { maxCorrStatsDev = 160; /* L_NCSHIFT_MAX @ 32kHz */ + move16(); } - if ( input_Fs < 32000 ) + IF( LT_32( input_Fs, 32000 ) ) { - maxCorrStatsDev = (int16_t) ( maxCorrStatsDev * input_Fs / 32000.0f ); + maxCorrStatsDev = (Word16) Mpy_32_32( imult3216( input_Fs, maxCorrStatsDev ), 67109 /* 1/32000.0f in Q31*/ ); // Q0 } musicMode = ( hCPE->hCoreCoder[0]->sp_aud_decision0 == 1 || sts[0]->last_core > ACELP_CORE ); - if ( musicMode ) + move16(); + + IF( musicMode ) { maxCorrStatsDev = 1; - set_s( hStereoTCA->corrLagStats + 1, 0, 2 ); + move16(); + set16_fx( hStereoTCA->corrLagStats + 1, 0, 2 ); } - tempS = ( hStereoTCA->corrLagStats[1] - hStereoTCA->prevCorrLagStats[2] ); - if ( abs( tempS ) > maxCorrStatsDev ) + tempS = sub( hStereoTCA->corrLagStats[1], hStereoTCA->prevCorrLagStats[2] ); + + IF( GT_16( abs_s( tempS ), maxCorrStatsDev ) ) { - hStereoTCA->corrLagStats[2] = hStereoTCA->prevCorrLagStats[2] + ( ( tempS > 0 ) ? maxCorrStatsDev : -maxCorrStatsDev ); + IF( tempS > 0 ) + { + hStereoTCA->corrLagStats[2] = add( hStereoTCA->prevCorrLagStats[2], maxCorrStatsDev ); + } + ELSE + { + hStereoTCA->corrLagStats[2] = add( hStereoTCA->prevCorrLagStats[2], -maxCorrStatsDev ); + } + move16(); } neighborLimit = maxCorrStatsDev; - + move16(); /* refine and search based on the corrlag stats */ - if ( tempS != 0 && dsFactor != 1 && prev_ICA_flag == 0 ) + test(); + test(); + IF( tempS != 0 && NE_16( dsFactor, 1 ) && prev_ICA_flag == 0 ) { - tempF = 0; - if ( !musicMode ) + tempF_fx = 0; + move32(); + IF( !musicMode ) { - tempLag[0] = min( hStereoTCA->corrLagStats[2], hStereoTCA->prevCorrLagStats[2] ); - tempLag[1] = max( hStereoTCA->corrLagStats[2], hStereoTCA->prevCorrLagStats[2] ); + tempLag[0] = s_min( hStereoTCA->corrLagStats[2], hStereoTCA->prevCorrLagStats[2] ); + move16(); + tempLag[1] = s_max( hStereoTCA->corrLagStats[2], hStereoTCA->prevCorrLagStats[2] ); + move16(); - neighborLimit = min( 3, maxCorrStatsDev ); - if ( hStereoTCA->prevCorrLagStats[2] < hStereoTCA->corrLagStats[2] ) + neighborLimit = s_min( 3, maxCorrStatsDev ); + + IF( LT_16( hStereoTCA->prevCorrLagStats[2], hStereoTCA->corrLagStats[2] ) ) { - tempLag[1] = min( tempLag[1], tempLag[0] + neighborLimit ); + tempLag[1] = s_min( tempLag[1], add( tempLag[0], neighborLimit ) ); } - else + ELSE { - tempLag[0] = max( tempLag[0], tempLag[1] - neighborLimit ); + tempLag[0] = s_max( tempLag[0], sub( tempLag[1], neighborLimit ) ); } -#ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 ptrChanL_q = Q_factor_arrL( ptrChanL, L_MEM_RECALC_48K + L_MEM_RECALC_48k_SCH + L_FRAME48k + L_NCSHIFTMAX - ( lMemRecalc + lMemRecalc_SCh ) ); - Word16 ptrChanR_q = Q_factor_arrL( ptrChanR, L_MEM_RECALC_48K + L_MEM_RECALC_48k_SCH + L_FRAME48k + L_NCSHIFTMAX - ( lMemRecalc + lMemRecalc_SCh ) ); - floatToFixed_arrL( ptrChanL, ptrChanL_fx, ptrChanL_q, L_MEM_RECALC_48K + L_MEM_RECALC_48k_SCH + L_FRAME48k + L_NCSHIFTMAX - ( lMemRecalc + lMemRecalc_SCh ) ); - floatToFixed_arrL( ptrChanR, ptrChanR_fx, ptrChanR_q, L_MEM_RECALC_48K + L_MEM_RECALC_48k_SCH + L_FRAME48k + L_NCSHIFTMAX - ( lMemRecalc + lMemRecalc_SCh ) ); -#endif - utilCrossCorr_fx( ptrChanL_fx, ptrChanL_q, ptrChanR_fx, ptrChanR_q, NULL, corrEstStage2_fx, &corrEstStage2_exp, tempLag, input_frame, 0 ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arrL32( corrEstStage2_fx, corrEstStage2, ( Q31 - corrEstStage2_exp ), N_MAX_SHIFT_CHANGE + 1 ); -#endif -#else - utilCrossCorr( ptrChanL, ptrChanR, NULL, corrEstStage2, tempLag, input_frame, 0 ); -#endif - hStereoTCA->corrLagStats[2] = maximum( corrEstStage2, ( tempLag[1] - tempLag[0] + 1 ), &tempF ); - hStereoTCA->corrLagStats[2] += tempLag[0]; + move16(); + utilCrossCorr_fx( ptrChanL_fx, q_com, ptrChanR_fx, q_com, NULL, corrEstStage2_fx, &corrEstStage2_exp, tempLag, input_frame, 0 ); + + hStereoTCA->corrLagStats[2] = maximum_l( corrEstStage2_fx, add( sub( tempLag[1], tempLag[0] ), 1 ), &tempF_fx ); + move16(); + hStereoTCA->corrLagStats[2] = add( hStereoTCA->corrLagStats[2], tempLag[0] ); + move16(); } - if ( abs( tempS ) > neighborLimit ) + IF( GT_16( abs_s( tempS ), neighborLimit ) ) { tempLag[0] = hStereoTCA->corrLagStats[1]; + move16(); tempLag[1] = hStereoTCA->corrLagStats[1]; -#ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 ptrChanL_q = Q_factor_arrL( ptrChanL, L_MEM_RECALC_48K + L_MEM_RECALC_48k_SCH + L_FRAME48k + L_NCSHIFTMAX - ( lMemRecalc + lMemRecalc_SCh ) ); - Word16 ptrChanR_q = Q_factor_arrL( ptrChanR, L_MEM_RECALC_48K + L_MEM_RECALC_48k_SCH + L_FRAME48k + L_NCSHIFTMAX - ( lMemRecalc + lMemRecalc_SCh ) ); - floatToFixed_arrL( ptrChanL, ptrChanL_fx, ptrChanL_q, L_MEM_RECALC_48K + L_MEM_RECALC_48k_SCH + L_FRAME48k + L_NCSHIFTMAX - ( lMemRecalc + lMemRecalc_SCh ) ); - floatToFixed_arrL( ptrChanR, ptrChanR_fx, ptrChanR_q, L_MEM_RECALC_48K + L_MEM_RECALC_48k_SCH + L_FRAME48k + L_NCSHIFTMAX - ( lMemRecalc + lMemRecalc_SCh ) ); -#endif - utilCrossCorr_fx( ptrChanL_fx, ptrChanL_q, ptrChanR_fx, ptrChanR_q, NULL, &tempF1_fx, &tempF1_exp, tempLag, input_frame, 0 ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - tempF1 = fixedToFloat( tempF1_fx, Q31 - tempF1_exp ); -#endif -#else - utilCrossCorr( ptrChanL, ptrChanR, NULL, &tempF1, tempLag, input_frame, 0 ); -#endif - if ( tempF1 > tempF || musicMode ) + move16(); + utilCrossCorr_fx( ptrChanL_fx, q_com, ptrChanR_fx, q_com, NULL, &tempF1_fx, &tempF1_exp, tempLag, input_frame, 0 ); + + test(); + IF( GT_32( tempF1_fx, tempF_fx ) || musicMode ) { - hStereoTCA->corrLagStats[2] = hStereoTCA->prevCorrLagStats[2] + ( ( tempS > 0 ) ? min( (int16_t) abs( tempS ), maxCorrStatsDev ) : max( (int16_t) -abs( tempS ), -maxCorrStatsDev ) ); + IF( tempS > 0 ) + { + hStereoTCA->corrLagStats[2] = add( hStereoTCA->prevCorrLagStats[2], s_min( abs_s( tempS ), maxCorrStatsDev ) ); + } + ELSE + { + hStereoTCA->corrLagStats[2] = add( hStereoTCA->prevCorrLagStats[2], s_max( -abs_s( tempS ), -maxCorrStatsDev ) ); + } + move16(); } } /* restrict the reference channel for +/- variation */ + test(); + test(); + test(); if ( ( hStereoTCA->corrLagStats[2] < 0 && hStereoTCA->prevCorrLagStats[2] > 0 ) || ( hStereoTCA->corrLagStats[2] > 0 && hStereoTCA->prevCorrLagStats[2] < 0 ) ) { hStereoTCA->corrLagStats[2] = 0; + move16(); } } - if ( hCPE->hStereoTD->prev_fr_LRTD_TD_dec /*hCPE->hStereoClassif->lrtd_mode*/ == 1 ) /* Content is considered as uncorrelated -> ICA shift is turned off */ + IF( EQ_16( hCPE->hStereoTD->prev_fr_LRTD_TD_dec /*hCPE->hStereoClassif->lrtd_mode*/, 1 ) ) /* Content is considered as uncorrelated -> ICA shift is turned off */ { hStereoTCA->corrLagStats[2] = 0; + move16(); - if ( hCPE->hStereoTD->tdm_LRTD_flag == 1 && prev_ICA_flag == 0 ) + test(); + if ( EQ_16( hCPE->hStereoTD->tdm_LRTD_flag, 1 ) && prev_ICA_flag == 0 ) { hStereoTCA->prevCorrLagStats[2] = 0; + move16(); } } @@ -2615,156 +2596,137 @@ void stereo_tca_enc( 1. adjust samples, 2. interp shift variation, 3. gain estimation */ - prevNCShift = (int16_t) abs( hStereoTCA->prevCorrLagStats[2] ); - currentNCShift = (int16_t) abs( hStereoTCA->corrLagStats[2] ); + prevNCShift = abs_s( hStereoTCA->prevCorrLagStats[2] ); + currentNCShift = abs_s( hStereoTCA->corrLagStats[2] ); - if ( hStereoTCA->prevRefChanIndx == L_CH_INDX ) + IF( EQ_16( hStereoTCA->prevRefChanIndx, L_CH_INDX ) ) { - mvr2r( ptrChanL - lMemRecalc - lMemRecalc_SCh, input_mem_loc[0], lMemRecalc + lMemRecalc_SCh ); - v_multc( ptrChanR + prevNCShift - lMemRecalc - lMemRecalc_SCh, hStereoTCA->prevTargetGain, input_mem_loc[1], lMemRecalc + lMemRecalc_SCh ); + v_multc_fixed( bufChanL_fx, ONE_IN_Q29, bufChanL_fx, L_MEM_RECALC_48K + L_MEM_RECALC_48k_SCH + L_FRAME48k + L_NCSHIFTMAX ); /* TO make in common Q*/ + Copy32( ptrChanL_fx - add( lMemRecalc, lMemRecalc_SCh ), input_mem_loc_fx[0], add( lMemRecalc, lMemRecalc_SCh ) ); // bufChan_q - 2 + v_multc_fixed( ptrChanR_fx + sub( prevNCShift, add( lMemRecalc, lMemRecalc_SCh ) ), hStereoTCA->prevTargetGain_fx, input_mem_loc_fx[1], add( lMemRecalc, lMemRecalc_SCh ) ); // bufChan_q-2 + v_multc_fixed( bufChanR_fx, ONE_IN_Q29, bufChanR_fx, L_MEM_RECALC_48K + L_MEM_RECALC_48k_SCH + L_FRAME48k + L_NCSHIFTMAX ); /* TO make in common Q bufChan_q -2 */ } - else + ELSE { - mvr2r( ptrChanL + prevNCShift - lMemRecalc - lMemRecalc_SCh, input_mem_loc[0], lMemRecalc + lMemRecalc_SCh ); - v_multc( ptrChanR - lMemRecalc - lMemRecalc_SCh, hStereoTCA->prevTargetGain, input_mem_loc[1], lMemRecalc + lMemRecalc_SCh ); + v_multc_fixed( bufChanL_fx, ONE_IN_Q29, bufChanL_fx, L_MEM_RECALC_48K + L_MEM_RECALC_48k_SCH + L_FRAME48k + L_NCSHIFTMAX ); /* TO make in common Q*/ + Copy32( ptrChanL_fx + add( prevNCShift, sub( lMemRecalc, lMemRecalc_SCh ) ), input_mem_loc_fx[0], add( lMemRecalc, lMemRecalc_SCh ) ); // bufChan_q -2 + v_multc_fixed( ptrChanR_fx - add( lMemRecalc, lMemRecalc_SCh ), hStereoTCA->prevTargetGain_fx, input_mem_loc_fx[1], add( lMemRecalc, lMemRecalc_SCh ) ); // bufChan_q -2 + v_multc_fixed( bufChanR_fx, ONE_IN_Q29, bufChanR_fx, L_MEM_RECALC_48K + L_MEM_RECALC_48k_SCH + L_FRAME48k + L_NCSHIFTMAX ); /* TO make in common Q*/ } - - target = ptrChanR; -#ifdef IVAS_FLOAT_FIXED + bufChan_q = sub( bufChan_q, 2 ); + q_com = bufChan_q; + move16(); + input_mem_loc_q = bufChan_q; + move16(); target_fx = ptrChanR_fx; -#endif target_idx = R_CH_INDX; + move16(); /* identify target signal to correct for shift variations */ - if ( ( prevNCShift == 0 && hStereoTCA->corrLagStats[2] < 0 ) || ( hStereoTCA->prevRefChanIndx == R_CH_INDX ) ) + test(); + test(); + IF( ( prevNCShift == 0 && hStereoTCA->corrLagStats[2] < 0 ) || EQ_16( hStereoTCA->prevRefChanIndx, R_CH_INDX ) ) { - target = ptrChanL; -#ifdef IVAS_FLOAT_FIXED target_fx = ptrChanL_fx; -#endif target_idx = L_CH_INDX; + move16(); } /* target signal adjustment for temporal shift variations */ - if ( ( prevNCShift - currentNCShift ) != 0 ) + IF( sub( prevNCShift, currentNCShift ) != 0 ) { L_shift_adapt = L_SHIFT_ADAPT_16k; - if ( input_Fs > INT_FS_16k ) + move16(); + if ( GT_32( input_Fs, INT_FS_16k ) ) { L_shift_adapt = L_SHIFT_ADAPT_MAX; + move16(); } /* Note!! : Always keep the assert (prevNCShift>>1) below according to the equation used here to get tempS */ - tempS = ( currentNCShift >> 1 ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 q_com1 = L_get_q_buf1( bufChanR, L_MEM_RECALC_48K + L_MEM_RECALC_48k_SCH + L_FRAME48k + L_NCSHIFTMAX ) - 4; - Word16 q_com2 = L_get_q_buf1( bufChanL, L_MEM_RECALC_48K + L_MEM_RECALC_48k_SCH + L_FRAME48k + L_NCSHIFTMAX ) - 4; - floatToFixed_arrL32( bufChanR, bufChanR_fx, q_com1, L_MEM_RECALC_48K + L_MEM_RECALC_48k_SCH + L_FRAME48k + L_NCSHIFTMAX ); - floatToFixed_arrL32( bufChanL, bufChanL_fx, q_com2, L_MEM_RECALC_48K + L_MEM_RECALC_48k_SCH + L_FRAME48k + L_NCSHIFTMAX ); -#endif - if ( abs( currentNCShift - prevNCShift ) <= min( N_MAX_SHIFT_CHANGE, N_MAX_SHIFT_CHANGE * input_Fs / 32000.0f ) ) + tempS = shr( currentNCShift, 1 ); + + IF( LE_32( abs( sub( currentNCShift, prevNCShift ) ), L_min( N_MAX_SHIFT_CHANGE, Mpy_32_32( imult3216( input_Fs, N_MAX_SHIFT_CHANGE ), 67109 /* 1/32000.0f in Q31*/ ) ) ) ) { -#ifdef IVAS_FLOAT_FIXED adjustTargetSignal_fx( ( target_fx - tempS ), prevNCShift, currentNCShift, L_shift_adapt, 0 ); -#else - adjustTargetSignal( ( target - tempS ), prevNCShift, currentNCShift, L_shift_adapt, 0 ); -#endif } - else + ELSE { - tempS = min( max( tempS, prevNCShift - currentNCShift + L_shift_adapt - input_frame ), prevNCShift - currentNCShift + lMemRecalc ); -#ifdef IVAS_FLOAT_FIXED + tempS = s_min( s_max( tempS, add( sub( prevNCShift, currentNCShift ), sub( L_shift_adapt, input_frame ) ) ), add( sub( prevNCShift, currentNCShift ), lMemRecalc ) ); + adjustTargetSignal_fx( ( target_fx - tempS ), prevNCShift, currentNCShift, L_shift_adapt, 1 ); -#else - adjustTargetSignal( ( target - tempS ), prevNCShift, currentNCShift, L_shift_adapt, 1 ); -#endif } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arrL32( bufChanR_fx, bufChanR, q_com1, L_MEM_RECALC_48K + L_MEM_RECALC_48k_SCH + L_FRAME48k + L_NCSHIFTMAX ); - fixedToFloat_arrL32( bufChanL_fx, bufChanL, q_com2, L_MEM_RECALC_48K + L_MEM_RECALC_48k_SCH + L_FRAME48k + L_NCSHIFTMAX ); -#endif - if ( target_idx == L_CH_INDX ) + + IF( target_idx == L_CH_INDX ) { - mvr2r( target - tempS, &( input_mem_loc[target_idx][lMemRecalc + lMemRecalc_SCh - tempS - currentNCShift] ), currentNCShift + tempS ); + Copy32( target_fx - tempS, &( input_mem_loc_fx[target_idx][lMemRecalc + lMemRecalc_SCh - tempS - currentNCShift] ), add( currentNCShift, tempS ) ); } - else + ELSE { - v_multc( target - tempS, hStereoTCA->prevTargetGain, &( input_mem_loc[target_idx][lMemRecalc + lMemRecalc_SCh - tempS - currentNCShift] ), currentNCShift + tempS ); + v_multc_fixed( target_fx - tempS, hStereoTCA->prevTargetGain_fx, &( input_mem_loc_fx[target_idx][lMemRecalc + lMemRecalc_SCh - tempS - currentNCShift] ), add( currentNCShift, tempS ) ); } } /* reference channel index */ - if ( hStereoTCA->corrLagStats[2] >= 0 ) + IF( hStereoTCA->corrLagStats[2] >= 0 ) { hStereoTCA->refChanIndx = L_CH_INDX; } - else + ELSE { hStereoTCA->refChanIndx = R_CH_INDX; } + move16(); /* Estimate and quantize the gain for scaling */ -#ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - q_com = L_get_q_buf1( ptrChanL, input_frame ); - // worst case input_frame value is 960 so taking 10 as guard bits - q_com = s_min( q_com, L_get_q_buf1( ptrChanR, input_frame ) ) - 10; - - floatToFixed_arrL32( ptrChanL, ptrChanL_fx, q_com, input_frame ); // not modified - floatToFixed_arrL32( ptrChanR, ptrChanR_fx, q_com, input_frame ); - q_target = L_get_q_buf1( &hStereoTCA->prevTargetGain, 1 ); - hStereoTCA->prevTargetGain_fx = float_to_fix( hStereoTCA->prevTargetGain, q_target ); - hStereoTCA->prevTargetGain_fx_e = Q31 - q_target; - hStereoTCA->corrStatsSmoothFac_fx = float_to_fix16( hStereoTCA->corrStatsSmoothFac, Q15 ); -#endif - estDownmixGain_fx( hStereoTCA, ptrChanL_fx, ptrChanR_fx, q_com, currentNCShift, ( input_frame - currentNCShift ), hCPE->element_mode, hCPE->hStereoClassif, hCPE->hStereoTD->tdm_LRTD_flag ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - hStereoTCA->instTargetGain = fix_to_float( hStereoTCA->instTargetGain_fx, Q31 - hStereoTCA->instTargetGain_fx_e ); - hStereoTCA->targetGain = fix_to_float( hStereoTCA->targetGain_fx, Q31 - hStereoTCA->targetGain_fx_e ); -#endif -#else - estDownmixGain( hStereoTCA, ptrChanL, ptrChanR, currentNCShift, ( input_frame - currentNCShift ), hCPE->element_mode, hCPE->hStereoClassif, hCPE->hStereoTD->tdm_LRTD_flag ); -#endif + estDownmixGain_fx( hStereoTCA, ptrChanL_fx, ptrChanR_fx, q_com, currentNCShift, sub( input_frame, currentNCShift ), hCPE->element_mode, hCPE->hStereoClassif, hCPE->hStereoTD->tdm_LRTD_flag ); /* quantize the corrStats */ - hStereoTCA->indx_ica_NCShift = (int16_t) usquant( ( (float) currentNCShift ) / dsFactor, &tempF, 0, 1.0f, 1 << STEREO_BITS_TCA_CORRSTATS ); + + Word16 temp_exp, tempF_16fx; + Word16 scalar_value = BASOP_Util_Divide3232_Scale( currentNCShift, dsFactor, &temp_exp ); + if ( scalar_value == 0 ) + { + temp_exp = 14; + move16(); + } + hStereoTCA->indx_ica_NCShift = usquant_fx( scalar_value, &tempF_16fx, 0, shl( 1, sub( 14, temp_exp ) ), 1 << STEREO_BITS_TCA_CORRSTATS ); + move16(); + tempF_fx = tempF_16fx; + move32(); } - else + ELSE { hStereoTCA->refChanIndx = L_CH_INDX; + move16(); hStereoTCA->corrLagStats[2] = 0; + move16(); hStereoTCA->prevCorrLagStats[2] = 0; + move16(); hStereoTCA->indx_ica_NCShift = 0; + move16(); - currentNCShift = 0; /* only to avoid compilation warning */ - target = ptrChanL; /* only to avoid compilation warning */ + currentNCShift = 0; /* only to avoid compilation warning */ + move16(); + target_fx = ptrChanL_fx; /* only to avoid compilation warning */ + move16(); target_idx = L_CH_INDX; /* only to avoid compilation warning */ + move16(); - mvr2r( ptrChanL - lMemRecalc - lMemRecalc_SCh, input_mem_loc[0], lMemRecalc + lMemRecalc_SCh ); - v_multc( ptrChanR - lMemRecalc - lMemRecalc_SCh, hStereoTCA->prevTargetGain, input_mem_loc[1], lMemRecalc + lMemRecalc_SCh ); + v_multc_fixed( bufChanL_fx, ONE_IN_Q29, bufChanL_fx, L_MEM_RECALC_48K + L_MEM_RECALC_48k_SCH + L_FRAME48k + L_NCSHIFTMAX ); /* TO make in common Q bufChan_q -2*/ + Copy32( ptrChanL_fx - add( lMemRecalc, lMemRecalc_SCh ), input_mem_loc_fx[0], add( lMemRecalc, lMemRecalc_SCh ) ); // bufChan_q -2 + v_multc_fixed( ptrChanR_fx - add( lMemRecalc, lMemRecalc_SCh ), hStereoTCA->prevTargetGain_fx, input_mem_loc_fx[1], add( lMemRecalc, lMemRecalc_SCh ) ); // bufChan_q -2 + + v_multc_fixed( bufChanR_fx, ONE_IN_Q29, bufChanR_fx, L_MEM_RECALC_48K + L_MEM_RECALC_48k_SCH + L_FRAME48k + L_NCSHIFTMAX ); /* TO make in common Q bufChan_q -2 */ + bufChan_q = sub( bufChan_q, 2 ); + q_com = bufChan_q; + move16(); + input_mem_loc_q = bufChan_q; + move16(); /* Estimate and quantize the gain for scaling */ -#ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - q_com = L_get_q_buf1( ptrChanL, input_frame ); - // worst case input_frame value is 960 so taking 10 as guard bits - q_com = s_min( q_com, L_get_q_buf1( ptrChanR, input_frame ) ) - 10; - - floatToFixed_arrL32( ptrChanL, ptrChanL_fx, q_com, input_frame ); // not modified - floatToFixed_arrL32( ptrChanR, ptrChanR_fx, q_com, input_frame ); - q_target = L_get_q_buf1( &hStereoTCA->prevTargetGain, 1 ); - hStereoTCA->prevTargetGain_fx = float_to_fix( hStereoTCA->prevTargetGain, q_target ); - hStereoTCA->prevTargetGain_fx_e = Q31 - q_target; - hStereoTCA->corrStatsSmoothFac_fx = float_to_fix16( hStereoTCA->corrStatsSmoothFac, Q15 ); -#endif + estDownmixGain_fx( hStereoTCA, ptrChanL_fx, ptrChanR_fx, q_com, 0, input_frame, hCPE->element_mode, hCPE->hStereoClassif, hCPE->hStereoTD->tdm_LRTD_flag ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - hStereoTCA->instTargetGain = fix_to_float( hStereoTCA->instTargetGain_fx, Q31 - hStereoTCA->instTargetGain_fx_e ); - hStereoTCA->targetGain = fix_to_float( hStereoTCA->targetGain_fx, Q31 - hStereoTCA->targetGain_fx_e ); -#endif -#else - estDownmixGain( hStereoTCA, ptrChanL, ptrChanR, 0, input_frame, hCPE->element_mode, hCPE->hStereoClassif, hCPE->hStereoTD->tdm_LRTD_flag ); -#endif } /*-----------------------------------------------------------------* @@ -2772,97 +2734,97 @@ void stereo_tca_enc( *-----------------------------------------------------------------*/ /* back up the L/R missing target */ - mvr2r( bufChanL + input_frame, hStereoTCA->memChanL, lMemRecalc + lMemRecalc_SCh ); - mvr2r( bufChanR + input_frame, hStereoTCA->memChanR, lMemRecalc + lMemRecalc_SCh ); + Copy32( bufChanL_fx + input_frame, hStereoTCA->memChanL_fx, add( lMemRecalc, lMemRecalc_SCh ) ); + Copy32( bufChanR_fx + input_frame, hStereoTCA->memChanR_fx, add( lMemRecalc, lMemRecalc_SCh ) ); + hStereoTCA->memChan_q = bufChan_q; IF( currentNCShift != 0 ) { -#ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - q_com = L_get_q_buf1( ptrChanL, input_frame + NS2SA( L_mult0( input_frame, FRAMES_PER_SEC ), L_SAMPLES_LA_NS ) ); - q_com = s_min( q_com, L_get_q_buf1( ptrChanR, input_frame + NS2SA( L_mult0( input_frame, FRAMES_PER_SEC ), L_SAMPLES_LA_NS ) ) ) - 4; - floatToFixed_arrL32( ptrChanL, ptrChanL_fx, q_com, input_frame + NS2SA( L_mult0( input_frame, FRAMES_PER_SEC ), L_SAMPLES_LA_NS ) ); - floatToFixed_arrL32( ptrChanR, ptrChanR_fx, q_com, input_frame + NS2SA( L_mult0( input_frame, FRAMES_PER_SEC ), L_SAMPLES_LA_NS ) ); -#endif /* Temporal channel adjustment of the LA samples based on the NC shift */ tcaTargetCh_LA_fx( hStereoTCA, ptrChanL_fx, ptrChanR_fx, &q_com, currentNCShift, input_frame ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arrL32( ptrChanL_fx, ptrChanL, q_com, input_frame + NS2SA( L_mult0( input_frame, FRAMES_PER_SEC ), L_SAMPLES_LA_NS ) ); - fixedToFloat_arrL32( ptrChanR_fx, ptrChanR, q_com, input_frame + NS2SA( L_mult0( input_frame, FRAMES_PER_SEC ), L_SAMPLES_LA_NS ) ); -#endif + Word16 additional_length = NS2SA( L_mult0( input_frame, FRAMES_PER_SEC ), L_SAMPLES_LA_NS ); + move16(); + scale_sig32( bufChanL_fx, add( lMemRecalc, lMemRecalc_SCh ), sub( s_min( q_com, bufChan_q ), bufChan_q ) ); // s_min( q_com, bufChan_q ) + scale_sig32( bufChanL_fx + add( lMemRecalc, lMemRecalc_SCh ), add( input_frame, additional_length ), sub( s_min( q_com, bufChan_q ), q_com ) ); // s_min( q_com, bufChan_q ) + scale_sig32( bufChanL_fx + add( add( lMemRecalc, lMemRecalc_SCh ), add( input_frame, additional_length ) ), sub( L_MEM_RECALC_48K + L_MEM_RECALC_48k_SCH + L_FRAME48k + L_NCSHIFTMAX, add( add( lMemRecalc, lMemRecalc_SCh ), add( input_frame, additional_length ) ) ), sub( s_min( q_com, bufChan_q ), bufChan_q ) ); // s_min( q_com, bufChan_q ) + + /* Scaling to common Q*/ + scale_sig32( bufChanR_fx, add( lMemRecalc, lMemRecalc_SCh ), sub( s_min( q_com, bufChan_q ), bufChan_q ) ); // s_min( q_com, bufChan_q ) + scale_sig32( bufChanR_fx + add( lMemRecalc, lMemRecalc_SCh ), add( input_frame, additional_length ), sub( s_min( q_com, bufChan_q ), q_com ) ); // s_min( q_com, bufChan_q ) + scale_sig32( bufChanR_fx + add( add( lMemRecalc, lMemRecalc_SCh ), add( input_frame, additional_length ) ), sub( L_MEM_RECALC_48K + L_MEM_RECALC_48k_SCH + L_FRAME48k + L_NCSHIFTMAX, add( add( lMemRecalc, lMemRecalc_SCh ), add( input_frame, additional_length ) ) ), sub( s_min( q_com, bufChan_q ), bufChan_q ) ); // s_min( q_com, bufChan_q ) + bufChan_q = s_min( q_com, bufChan_q ); + q_com = bufChan_q; } -#else - if ( currentNCShift != 0 ) - { - /* Temporal channel adjustment of the LA samples based on the NC shift */ - tcaTargetCh_LA( hStereoTCA, ptrChanL, ptrChanR, currentNCShift, input_frame ); - } -#endif + /* Update of changed samples corresponding to the memory */ -#ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - q_com = L_get_q_buf1( input_mem_loc[0], NS2SA( 48000, L_MEM_RECALC_NS + L_MEM_RECALC_SCH_NS ) ); - q_com = s_min( q_com, L_get_q_buf1( input_mem_loc[1], NS2SA( 48000, L_MEM_RECALC_NS + L_MEM_RECALC_SCH_NS ) ) ) - 4; - floatToFixed_arrL32( input_mem_loc[0], input_mem_loc_fx[0], q_com, NS2SA( 48000, L_MEM_RECALC_NS + L_MEM_RECALC_SCH_NS ) ); - floatToFixed_arrL32( input_mem_loc[1], input_mem_loc_fx[1], q_com, NS2SA( 48000, L_MEM_RECALC_NS + L_MEM_RECALC_SCH_NS ) ); - - floatToFixed_arrL32( sts[0]->input_buff, sts[0]->input_buff32_fx, q_com, 1965 ); - floatToFixed_arrL32( sts[1]->input_buff, sts[1]->input_buff32_fx, q_com, 1965 ); -#endif + /* Scaling to common Q*/ + scale_sig32( input_mem_loc_fx[0], NS2SA( 48000, L_MEM_RECALC_NS + L_MEM_RECALC_SCH_NS ), sub( s_min( input_mem_loc_q, sts[0]->q_inp32 ), input_mem_loc_q ) ); // s_min( input_mem_loc_q, sts[0]->q_inp32 ) + scale_sig32( input_mem_loc_fx[1], NS2SA( 48000, L_MEM_RECALC_NS + L_MEM_RECALC_SCH_NS ), sub( s_min( input_mem_loc_q, sts[0]->q_inp32 ), input_mem_loc_q ) ); // s_min( input_mem_loc_q, sts[0]->q_inp32 ) + scale_sig32( sts[0]->input_buff32_fx, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), sub( s_min( input_mem_loc_q, sts[0]->q_inp32 ), sts[0]->q_inp32 ) ); // s_min( input_mem_loc_q, sts[0]->q_inp32 ) + scale_sig32( sts[1]->input_buff32_fx, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), sub( s_min( input_mem_loc_q, sts[1]->q_inp32 ), sts[1]->q_inp32 ) ); // s_min( input_mem_loc_q, sts[0]->q_inp32 ) + + input_mem_loc_q = s_min( input_mem_loc_q, sts[0]->q_inp32 ); + sts[0]->q_inp32 = input_mem_loc_q; + move16(); + sts[1]->q_inp32 = input_mem_loc_q; + move16(); + icaMemUpdate_fx( sts, hCPE, input_mem_loc_fx[0], input_mem_loc_fx[1], q_com, lMemRecalc, lMemRecalc_SCh, input_frame ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arrL32( sts[0]->input_buff32_fx, sts[0]->input_buff, q_com, 1965 ); - fixedToFloat_arrL32( sts[1]->input_buff32_fx, sts[1]->input_buff, q_com, 1965 ); - if ( hCPE->hStereoICBWE != NULL ) - { - fixedToFloat_arr( hCPE->hStereoICBWE->icbwe_inp_mem_fx[0], hCPE->hStereoICBWE->icbwe_inp_mem[0], hCPE->hStereoICBWE->q_dataChan_fx, NS2SA( input_Fs, L_MEM_RECALC_TBE_NS ) ); - fixedToFloat_arr( hCPE->hStereoICBWE->icbwe_inp_mem_fx[1], hCPE->hStereoICBWE->icbwe_inp_mem[1], hCPE->hStereoICBWE->q_dataChan_fx, NS2SA( input_Fs, L_MEM_RECALC_TBE_NS ) ); - } -#endif -#else - icaMemUpdate( sts, hCPE, input_mem_loc[0], input_mem_loc[1], lMemRecalc, lMemRecalc_SCh, input_frame ); -#endif /* populate the st->input target buffer */ - if ( hCPE->hStereoTD->prev_fr_LRTD_TD_dec == 0 || prev_ICA_flag == 1 ) + test(); + IF( hCPE->hStereoTD->prev_fr_LRTD_TD_dec == 0 || EQ_16( prev_ICA_flag, 1 ) ) { - mvr2r( target + currentNCShift, sts[target_idx]->input, input_frame ); + Copy32( target_fx + currentNCShift, sts[target_idx]->input32_fx, input_frame ); } - if ( hCPE->element_mode != IVAS_CPE_DFT ) + IF( NE_16( hCPE->element_mode, IVAS_CPE_DFT ) ) { /* Scale the Right channel with the gain */ - int16_t j; - int16_t l_ica_ovl = NS2SA( input_Fs, STEREO_L_TCA_OVLP_NS ); - float winSlope = 1.0f / (float) l_ica_ovl; + Word16 j; + Word16 l_ica_ovl = NS2SA( input_Fs, STEREO_L_TCA_OVLP_NS ); - tempF1 = hStereoTCA->targetGain; - tempF = hStereoTCA->prevTargetGain; + Word16 winSlope = div_s( 1, l_ica_ovl ); // Q15 - for ( i = 0, j = 0; i < l_ica_ovl; i++, j++ ) + tempF1_fx = hStereoTCA->targetGain_fx; // Q29 + move32(); + tempF_fx = hStereoTCA->prevTargetGain_fx; // Q29 + move32(); + + FOR( ( i = 0, j = 0 ); i < l_ica_ovl; ( i++, j++ ) ) { - sts[1]->input[i] = ( 1.0f - j * winSlope ) * tempF * sts[1]->input[i] + ( j * winSlope ) * tempF1 * sts[1]->input[i]; + sts[1]->input32_fx[i] = L_add( Mpy_32_32( sts[1]->input32_fx[i], Mpy_32_16_1( tempF_fx, sub( MAX_16, imult1616( j, winSlope ) ) ) ), Mpy_32_32( sts[1]->input32_fx[i], Mpy_32_16_1( tempF1_fx, imult1616( j, winSlope ) ) ) ); // inpq-2 + move32(); } - for ( ; i < input_frame; i++ ) + + FOR( ; i < input_frame; i++ ) { - sts[1]->input[i] *= tempF1; + sts[1]->input32_fx[i] = Mpy_32_32( sts[1]->input32_fx[i], tempF1_fx ); // inpq-2 + move32(); } + + scale_sig32( sts[1]->input_buff32_fx, (Word16) Mpy_32_32( input_Fs, 42949673 ) /* 1/50 in Q31*/, -2 ); // inpq-2 + scale_sig32( sts[0]->input_buff32_fx, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), -2 ); // inpq-2 + sts[0]->q_inp32 = sub( sts[0]->q_inp32, 2 ); + move16(); + sts[1]->q_inp32 = sub( sts[1]->q_inp32, 2 ); + move16(); } /* update L/R DS memories */ - mvr2r( bufChanL_DS + L_FRAME_DS, hStereoTCA->memChanL_DS, ADDED_MEM_DS ); - mvr2r( bufChanR_DS + L_FRAME_DS, hStereoTCA->memChanR_DS, ADDED_MEM_DS ); + Copy32( bufChanL_DS_fx + L_FRAME_DS, hStereoTCA->memChanL_DS_fx, ADDED_MEM_DS ); + Copy32( bufChanR_DS_fx + L_FRAME_DS, hStereoTCA->memChanR_DS_fx, ADDED_MEM_DS ); /* save the reference channel index for next frame */ hStereoTCA->prevRefChanIndx = hStereoTCA->refChanIndx; - + move16(); /* save the corr lag stats for next frame */ - mvs2s( hStereoTCA->corrLagStats, hStereoTCA->prevCorrLagStats, 3 ); + Copy( hStereoTCA->corrLagStats, hStereoTCA->prevCorrLagStats, 3 ); /* save the target gain for next frame */ - hStereoTCA->prevTargetGain = hStereoTCA->targetGain; - + hStereoTCA->prevTargetGain_fx = hStereoTCA->targetGain_fx; // Q29 + move32(); return; } #else @@ -3256,7 +3218,7 @@ void stereo_tca_enc( * * Stereo temporal inter-channel adjustment (ICA) encoder initialization *-------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED void stereo_tca_init_enc( STEREO_TCA_ENC_HANDLE hStereoTCA, /* i/o: Stereo ICA handle */ const int32_t input_Fs /* i : input sampling frequency */ @@ -3306,7 +3268,7 @@ void stereo_tca_init_enc( move16(); return; } - +#endif void stereo_tca_init_enc_fx( STEREO_TCA_ENC_HANDLE hStereoTCA, /* i/o: Stereo ICA handle */ const Word32 input_Fs /* i : input sampling frequency */ @@ -3335,14 +3297,7 @@ void stereo_tca_init_enc_fx( move32(); move32(); move32(); - hStereoTCA->targetGain_fx_e = Q2; // Q31 - Q29 - hStereoTCA->prevTargetGain_fx_e = Q2; // Q31 - Q29 - hStereoTCA->instTargetGain_fx_e = Q2; // Q31 - Q29 - move16(); - move16(); - move16(); - - hStereoTCA->corrStatsSmoothFac_fx = 22937; // Q15 + hStereoTCA->corrStatsSmoothFac_fx = 22938; // Q15 move16(); set16_fx( hStereoTCA->corrLagStats, 0, 3 ); @@ -3350,8 +3305,12 @@ void stereo_tca_init_enc_fx( set32_fx( hStereoTCA->memChanL_fx, 0, add( L_MEM_RECALC_48K, L_MEM_RECALC_48k_SCH ) ); set32_fx( hStereoTCA->memChanR_fx, 0, add( L_MEM_RECALC_48K, L_MEM_RECALC_48k_SCH ) ); + hStereoTCA->memChan_q = 31; + move16(); set32_fx( hStereoTCA->memChanL_DS_fx, 0, ADDED_MEM_DS ); set32_fx( hStereoTCA->memChanR_DS_fx, 0, ADDED_MEM_DS ); + hStereoTCA->memChan_DS_q = Q31; + move16(); hStereoTCA->mem_tempF_fx = 0; move32(); hStereoTCA->mem_tempF_exp = 0; diff --git a/lib_enc/ivas_stereo_switching_enc.c b/lib_enc/ivas_stereo_switching_enc.c index c7f07245d..d308534f0 100644 --- a/lib_enc/ivas_stereo_switching_enc.c +++ b/lib_enc/ivas_stereo_switching_enc.c @@ -487,7 +487,7 @@ ivas_error stereo_memory_enc_fx( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo TCA\n" ) ); } - stereo_tca_init_enc( hCPE->hStereoTCA, input_Fs ); + stereo_tca_init_enc_fx( hCPE->hStereoTCA, input_Fs ); st = hCPE->hCoreCoder[0]; diff --git a/lib_enc/nelp_enc.c b/lib_enc/nelp_enc.c index 9ec0187b6..050202c12 100644 --- a/lib_enc/nelp_enc.c +++ b/lib_enc/nelp_enc.c @@ -42,6 +42,7 @@ #include "rom_com.h" #include "wmc_auto.h" +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * quantize_uvg() * @@ -442,3 +443,4 @@ void nelp_encoder( return; } +#endif diff --git a/lib_enc/pitch_ol.c b/lib_enc/pitch_ol.c index faa54c90d..15051574e 100644 --- a/lib_enc/pitch_ol.c +++ b/lib_enc/pitch_ol.c @@ -86,13 +86,21 @@ static void lp_decim2( const float x[], float y[], const int16_t l, float *mem ) *-----------------------------------------------------------------*/ void pitch_ol_init( - float *old_thres, /* o : threshold for reinforcement of past pitch influence */ +#ifndef IVAS_FLOAT_FIXED + float *old_thres, /* o : threshold for reinforcement of past pitch influence */ +#else + Word16 *old_thres, /* o : threshold for reinforcement of past pitch influence */ +#endif int16_t *old_pitch, /* o : pitch of the 1st half-frame of previous frame */ int16_t *delta_pit, /* o : pitch evolution extrapolation */ float *old_corr /* o : correlation */ ) { +#ifndef IVAS_FLOAT_FIXED *old_thres = 0.0f; +#else + *old_thres = 0; +#endif *old_pitch = 0; *delta_pit = 0; *old_corr = 0.0f; diff --git a/lib_enc/stat_enc.h b/lib_enc/stat_enc.h index 97c5a2ec1..d9fb96f24 100644 --- a/lib_enc/stat_enc.h +++ b/lib_enc/stat_enc.h @@ -641,20 +641,25 @@ typedef struct dtx_enc_structure Word16 lspCNG_fx[M]; /* CNG and DTX - LP filtered lsps */ int16_t VarDTX_cnt_voiced; /* CNG and DTX - counter for variable DTX activation (speech) */ int16_t VarDTX_cnt_noise; /* CNG and DTX - counter for variable DTX activation (noise) */ - float lt_ener_voiced; /* CNG and DTX - long-term energy of signal (measured on voiced parts) */ - float lt_ener_noise; /* CNG and DTX - long-term energy of background noise */ +#ifndef IVAS_FLOAT_FIXED + float lt_ener_voiced; /* CNG and DTX - long-term energy of signal (measured on voiced parts) */ + float lt_ener_noise; /* CNG and DTX - long-term energy of background noise */ float frame_ener; - Word32 lt_ener_voiced_fx; /* CNG and DTX - long-term energy of signal (measured on voiced parts) Q(-7) */ - Word32 lt_ener_noise_fx; /* CNG and DTX - long-term energy of background noise Q(-7) */ - - Word32 frame_ener_fx; /* Q(-7) */ - int16_t cng_hist_size; /* CNG and DTX - size of CNG history buffer for averaging, <0,DTX_HIST_SIZE> */ - float lt_ener_last_SID; /* CNG and DTX - long-term energy of last SID frame */ - Word32 lt_ener_last_SID_fx; /* CNG and DTX - long-term energy of last SID frame */ - int16_t last_CNG_L_frame; /* CNG and DTX - last CNG frame length */ - int16_t var_SID_rate_flag; /* CNG and DTX - flag for variable SID rate */ - int16_t interval_SID; /* CNG and DTX - interval of SID update, default 8 */ - int32_t last_active_brate; /* CNG and DTX - last active frame bitrate used for CNG_mode control */ +#else + Word32 lt_ener_voiced_fx; /* CNG and DTX - long-term energy of signal (measured on voiced parts) Q(-7) */ + Word32 lt_ener_noise_fx; /* CNG and DTX - long-term energy of background noise Q(-7) */ + Word32 frame_ener_fx; /* Q(-7) */ +#endif + int16_t cng_hist_size; /* CNG and DTX - size of CNG history buffer for averaging, <0,DTX_HIST_SIZE> */ +#ifndef IVAS_FLOAT_FIXED + float lt_ener_last_SID; /* CNG and DTX - long-term energy of last SID frame */ +#else + Word32 lt_ener_last_SID_fx; /* CNG and DTX - long-term energy of last SID frame Q(-7) */ +#endif + int16_t last_CNG_L_frame; /* CNG and DTX - last CNG frame length */ + int16_t var_SID_rate_flag; /* CNG and DTX - flag for variable SID rate */ + int16_t interval_SID; /* CNG and DTX - interval of SID update, default 8 */ + int32_t last_active_brate; /* CNG and DTX - last active frame bitrate used for CNG_mode control */ } DTX_ENC_DATA, *DTX_ENC_HANDLE; @@ -1068,8 +1073,8 @@ typedef struct sp_mus_clas_structure float LT_sparse; #else Word16 sparse_buf_fx[HANG_LEN_INIT]; - Word16 hf_spar_buf_fx[HANG_LEN_INIT]; /* Q15 */ - Word16 LT_sparse_fx; /* Q8 */ + Word16 hf_spar_buf_fx[HANG_LEN_INIT]; /* Q15 */ + Word16 LT_sparse_fx; /* Q8 */ #endif int16_t gsc_cnt; @@ -1081,9 +1086,9 @@ typedef struct sp_mus_clas_structure float lt_corr_flt; float lt_tonality_flt; #else - Word16 lt_voicing; /* Q15 */ - Word16 lt_corr; /* Q15 */ - Word32 lt_tonality; /* Q15 */ + Word16 lt_voicing; /* Q15 */ + Word16 lt_corr; /* Q15 */ + Word32 lt_tonality; /* Q15 */ #endif int16_t lt_corr_pitch[3]; int16_t lt_hangover; @@ -1093,8 +1098,8 @@ typedef struct sp_mus_clas_structure float tdm_lt_Etot; float var_cor_t[VAR_COR_LEN]; #else - Word16 tdm_lt_Etot_fx; /* Q8 */ - Word16 var_cor_t_fx[VAR_COR_LEN]; /* Q11 */ + Word16 tdm_lt_Etot_fx; /* Q8 */ + Word16 var_cor_t_fx[VAR_COR_LEN]; /* Q11 */ #endif int16_t high_stable_cor; @@ -1103,9 +1108,9 @@ typedef struct sp_mus_clas_structure float lpm; float lpn; #else - Word16 lps_fx; /* Q7 */ - Word16 lpm_fx; /* Q7 */ - Word16 lpn_fx; /* Q7 */ + Word16 lps_fx; /* Q7 */ + Word16 lpm_fx; /* Q7 */ + Word16 lpn_fx; /* Q7 */ #endif @@ -1146,10 +1151,10 @@ typedef struct lpd_state_structure Word16 e_mem_syn; float tilt_code_flt; - float gc_threshold_flt; /* Noise enhancer - threshold for gain_code */ - float dispMem_flt[8]; /* Noise enhancer - phase dispersion algorithm memory */ - Word32 dispMem[8]; /* Noise enhancer - phase dispersion algorithm memory */ - Word16 tilt_code; + float gc_threshold_flt; /* Noise enhancer - threshold for gain_code */ + float dispMem_flt[8]; /* Noise enhancer - phase dispersion algorithm memory */ + Word32 dispMem[8]; /* Noise enhancer - phase dispersion algorithm memory */ + Word16 tilt_code; /* Q15 */ Word32 gc_threshold; /* exponent = 15, 15Q16 */ struct dispMem_fx dm_fx; /* Noise enhancer - phase dispersion algorithm memory */ @@ -1239,16 +1244,22 @@ typedef struct hq_enc_structure int16_t prev_frm_index[NB_SWB_SUBBANDS_HAR_SEARCH_SB]; int16_t prev_frm_hfe2; int16_t prev_stab_hfe2; +#ifndef IVAS_FLOAT_FIXED float prev_ni_ratio; +#else + Word16 prev_ni_ratio_fx; /* Q15 */ +#endif float prev_En_sb[NB_SWB_SUBBANDS]; - Word16 prev_ni_ratio_fx; /* 15 */ Word16 prev_En_sb_fx[NB_SWB_SUBBANDS]; /* QsEn(4) */ int16_t last_bitalloc_max_band[2]; +#ifndef IVAS_FLOAT_FIXED float last_ni_gain[BANDS_MAX]; float last_env[BANDS_MAX]; - Word32 last_ni_gain_fx[BANDS_MAX]; - Word16 last_env_fx[BANDS_MAX]; +#else + Word32 last_ni_gain_fx[BANDS_MAX]; /* Q17 */ + Word16 last_env_fx[BANDS_MAX]; /* Q1 */ +#endif int16_t last_max_pos_pulse; @@ -1275,12 +1286,16 @@ typedef struct pvq_enc_structure typedef struct sc_vbr_enc_structure { +#ifndef IVAS_FLOAT_FIXED float vadsnr; float vadnoise; - Word16 vadsnr_fx; /*Q7*/ - Word16 vadnoise_fx; +#else + Word16 vadsnr_fx; /* Q7 */ + Word16 vadnoise_fx; /* Q8 */ +#endif /* NELP variables */ +#ifndef IVAS_FLOAT_FIXED float shape1_filt_mem[20]; float shape2_filt_mem[20]; float shape3_filt_mem[20]; @@ -1288,24 +1303,32 @@ typedef struct sc_vbr_enc_structure float txlpf1_filt2_mem[20]; float txhpf1_filt1_mem[20]; float txhpf1_filt2_mem[20]; - Word16 shape1_filt_mem_fx[10]; - Word16 shape2_filt_mem_fx[10]; - Word16 shape3_filt_mem_fx[10]; - Word16 txlpf1_filt1_mem_fx[10]; - Word16 txlpf1_filt2_mem_fx[10]; - Word16 txhpf1_filt1_mem_fx[10]; - Word16 txhpf1_filt2_mem_fx[10]; +#else + Word16 shape1_filt_mem_fx[10]; /* Q(qprevGain_fx) */ + Word16 shape2_filt_mem_fx[10]; /* Q(qprevGain_fx) */ + Word16 shape3_filt_mem_fx[10]; /* Q(qprevGain_fx) */ + Word16 txlpf1_filt1_mem_fx[10]; /* Q(qprevGain_fx) */ + Word16 txlpf1_filt2_mem_fx[10]; /* Q(qprevGain_fx) */ + Word16 txhpf1_filt1_mem_fx[10]; /* Q(qprevGain_fx) */ + Word16 txhpf1_filt2_mem_fx[10]; /* Q(qprevGain_fx) */ +#endif +#ifndef IVAS_FLOAT_FIXED float bp1_filt_mem_wb[8]; float nelp_lp_fit_mem_flt[NELP_LP_ORDER * 2]; float bp1_filt_mem_nb[14]; - Word16 bp1_filt_mem_wb_fx[8]; - Word16 nelp_lp_fit_mem[NELP_LP_ORDER * 2]; - Word32 bp1_filt_mem_nb_fx[14]; +#else + Word16 bp1_filt_mem_wb_fx[8]; /* Q(qprevGain_fx) */ + Word16 nelp_lp_fit_mem[NELP_LP_ORDER * 2]; /* Q(prev_Q_new) */ + Word32 bp1_filt_mem_nb_fx[14]; /* Q(qprevGain_fx) */ +#endif int16_t nelp_enc_seed; +#ifndef IVAS_FLOAT_FIXED float nelp_gain_mem; - Word16 nelp_gain_mem_fx; +#else + Word16 nelp_gain_mem_fx; /* Q0 */ +#endif int16_t last_nelp_mode; int16_t nelp_mode; @@ -1320,43 +1343,55 @@ typedef struct sc_vbr_enc_structure int16_t ppp_mode; float prev_ppp_gain_pit; float prev_tilt_code; - Word16 prev_ppp_gain_pit_fx; /*Q14*/ - Word16 prev_tilt_code_fx; + Word16 prev_ppp_gain_pit_fx; /* Q14 */ + Word16 prev_tilt_code_fx; /* Q15 */ /* voiced encoder variables */ int16_t firstTime_voicedenc; /* DTFS variables */ +#ifndef IVAS_FLOAT_FIXED float dtfs_enc_a[MAXLAG_WI]; float dtfs_enc_b[MAXLAG_WI]; - Word16 dtfs_enc_a_fx[MAXLAG_WI]; /*Q0*/ - Word16 dtfs_enc_b_fx[MAXLAG_WI]; /*Q0*/ +#else + Word16 dtfs_enc_a_fx[MAXLAG_WI]; /* Q(dtfs_enc_Q) */ + Word16 dtfs_enc_b_fx[MAXLAG_WI]; /* Q(dtfs_enc_Q) */ +#endif int16_t dtfs_enc_lag; int16_t dtfs_enc_nH; int16_t dtfs_enc_nH_4kHz; +#ifndef IVAS_FLOAT_FIXED float dtfs_enc_upper_cut_off_freq_of_interest; float dtfs_enc_upper_cut_off_freq; - Word16 dtfs_enc_upper_cut_off_freq_of_interest_fx; - Word16 dtfs_enc_upper_cut_off_freq_fx; +#else + Word16 dtfs_enc_upper_cut_off_freq_of_interest_fx; /* Q0 */ + Word16 dtfs_enc_upper_cut_off_freq_fx; /* Q0 */ +#endif Word16 dtfs_enc_Q; +#ifndef IVAS_FLOAT_FIXED float prev_cw_en; float ph_offset_E; - float lastLgainE; /* Previous gain value for the low band */ - float lastHgainE; /* Previous gain value for the high band */ - float lasterbE[NUM_ERB_WB]; /* Previous Amplitude spectrum (ERB) */ - Word32 prev_cw_en_fx; /*Q_prev_cw_en_fx*/ - Word16 ph_offset_E_fx; /*Q15 normalized y 2*Pi */ - Word16 lastLgainE_fx; /*Q11 Previous gain value for the low band */ - Word16 lastHgainE_fx; /*Q11 Previous gain value for the high band */ - Word16 lasterbE_fx[NUM_ERB_WB]; /*Q13 Previous Amplitude spectrum (ERB) */ + float lastLgainE; /* Previous gain value for the low band */ + float lastHgainE; /* Previous gain value for the high band */ + float lasterbE[NUM_ERB_WB]; /* Previous Amplitude spectrum (ERB) */ +#else + Word32 prev_cw_en_fx; /* Q(Q_prev_cw_en_fx) */ + Word16 ph_offset_E_fx; /* normalized y 2*Pi Q15 */ + Word16 lastLgainE_fx; /* Previous gain value for the low band Q11 */ + Word16 lastHgainE_fx; /* Previous gain value for the high band Q11 */ + Word16 lasterbE_fx[NUM_ERB_WB]; /* Previous Amplitude spectrum (ERB) Q13 */ +#endif Word16 Q_prev_cw_en_fx; int16_t mode_QQF; int16_t rate_control; +#ifndef IVAS_FLOAT_FIXED float SNR_THLD; - Word16 SNR_THLD_fx; +#else + Word16 SNR_THLD_fx; /* Q8 */ +#endif int16_t Q_to_F; int16_t pattern_m; int16_t patterncount; @@ -1366,8 +1401,8 @@ typedef struct sc_vbr_enc_structure float sum_of_rates; /* sum of the rates of past 600 active frames */ float global_avr_rate; /* global rate up to current time. recorded a (rate in kbps) * 6000 */ #else - Word32 sum_of_rates_fx; /*Q=13 sum of the rates of past 600 active frames*/ - Word32 global_avr_rate_fx; /*Q=13 global rate upto current time. recorded a (rate in kbps) *6000*/ + Word32 sum_of_rates_fx; /*Q=13 sum of the rates of past 600 active frames*/ + Word32 global_avr_rate_fx; /*Q=13 global rate upto current time. recorded a (rate in kbps) *6000*/ #endif int16_t global_frame_cnt; /* 600 active frame block count. Used to update the global rate */ int16_t set_ppp_generic; @@ -1388,20 +1423,26 @@ typedef struct sc_vbr_enc_structure typedef struct amrwb_io_enc_structure { - float past_qua_en[4]; /* gain quantization memory (used also in AMR-WB IO mode) */ - Word16 past_qua_en_fx[4]; /* gain quantization memory (used also in AMR-WB IO mode) */ +#ifndef IVAS_FLOAT_FIXED + float past_qua_en[4]; /* gain quantization memory (used also in AMR-WB IO mode) */ +#else + Word16 past_qua_en_fx[4]; /* gain quantization memory (used also in AMR-WB IO mode) Q10 */ +#endif /* HF WB BWE for AMR-WB IO mode at 23.85 kbps */ +#ifndef IVAS_FLOAT_FIXED float gain_alpha; float mem_hf2_enc[L_FIR - 1]; float mem_hp400_enc[4]; float mem_hf_enc[L_FIR - 1]; float mem_syn_hf_enc[M]; - Word16 gain_alpha_fx; +#else + Word16 gain_alpha_fx; /* Q14 */ Word16 mem_hf2_enc_fx[L_FIR - 1]; Word16 mem_hp400_enc_fx[6]; Word16 mem_hf_enc_fx[L_FIR - 1]; Word16 mem_syn_hf_enc_fx[M]; +#endif int16_t seed2_enc; } AMRWB_IO_ENC_DATA, *AMRWB_IO_ENC_HANDLE; @@ -1420,12 +1461,18 @@ typedef struct td_bwe_enc_structure Word16 old_input_fhb_fx[NS2SA( 48000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ) - L_FRAME48k / 2]; Word16 old_input_fhb_fx_Q; +#ifndef IVAS_FLOAT_FIXED float prev_lsp_shb[LPC_SHB_ORDER]; - Word16 prev_lsp_shb_fx[LPC_SHB_ORDER]; /* Q15 */ +#else + Word16 prev_lsp_shb_fx[LPC_SHB_ORDER]; /* Q15 */ +#endif float state_ana_filt_shb[2 * ALLPASSSECTIONS_STEEP + 1]; /* states for the analysis filters */ - float cldfbHBLT_flt; Word16 state_ana_filt_shb_fx[( 2 * ALLPASSSECTIONS_STEEP + 1 )]; - Word16 cldfbHBLT; /* Q13 */ +#ifndef IVAS_FLOAT_FIXED + float cldfbHBLT_flt; +#else + Word16 cldfbHBLT; /* Q13 */ +#endif /* states for the filters used in generating SHB excitation from WB excitation*/ float mem_csfilt[2]; Word32 mem_csfilt_fx[2]; /* Q(prev_Q_bwe_exc) */ @@ -1434,10 +1481,13 @@ typedef struct td_bwe_enc_structure Word32 mem_shb_res_32_fx[MAX_LEN_MA_FILTER]; /* old SHB residual signal */ float old_EnvSHBres[L_FRAME4k]; /* old TD envelope of the SHB residual signal */ Word16 old_EnvSHBres_fx[L_FRAME4k]; /* old TD envelope of the SHB residual signal */ - float old_mean_EnvSHBres; /* energy of the last subframe of the SHB residual signal from previous frame */ - Word16 old_mean_EnvSHBres_fx; /* energy of the last subframe of the SHB residual signal from previous frame Q15 */ - float prev_enr_EnvSHBres; /* energy of the residual SHB envelope from the previous frame */ - Word32 prev_enr_EnvSHBres_fx; /* energy of the residual SHB envelope from the previous frame Q(31 - prev_enr_EnvSHBres_e) */ +#ifndef IVAS_FLOAT_FIXED + float old_mean_EnvSHBres; /* energy of the last subframe of the SHB residual signal from previous frame */ +#else + Word16 old_mean_EnvSHBres_fx; /* energy of the last subframe of the SHB residual signal from previous frame Q15 */ +#endif + float prev_enr_EnvSHBres; /* energy of the residual SHB envelope from the previous frame */ + Word32 prev_enr_EnvSHBres_fx; /* energy of the residual SHB envelope from the previous frame Q(31 - prev_enr_EnvSHBres_e) */ Word16 prev_enr_EnvSHBres_e; float prev_shb_env_tilt; /* tilt of the residual SHB envelope from the previous frame */ Word16 prev_shb_env_tilt_fx; /* tilt of the residual SHB envelope from the previous frame Q(prev_shb_env_tilt_q) */ @@ -1445,10 +1495,13 @@ typedef struct td_bwe_enc_structure float prev_pow_exc16kWhtnd; /* power of the LB excitation signal in the previous frame */ Word16 prev_pow_exc16kWhtnd_fx; /* power of the LB excitation signal in the previous frame */ Word32 prev_pow_exc16kWhtnd_fx32; /* Use this power of the LB excitation signal in the previous frame Q0 */ - float prev_mix_factor; /* mixing factor in the previous frame */ - Word16 prev_mix_factor_fx; /* mixing factor in the previous frame Q15 */ - float prev_Env_error; /* error in SHB envelope modelling */ - Word16 prev_Env_error_fx; /* error in SHB envelope modelling */ +#ifndef IVAS_FLOAT_FIXED + float prev_mix_factor; /* mixing factor in the previous frame */ +#else + Word16 prev_mix_factor_fx; /* mixing factor in the previous frame Q15 */ +#endif + float prev_Env_error; /* error in SHB envelope modelling */ + Word16 prev_Env_error_fx; /* error in SHB envelope modelling */ /* states for the filters used in generating SHB signal from SHB excitation*/ float state_syn_shbexc[L_SHB_LAHEAD]; @@ -1477,42 +1530,58 @@ typedef struct td_bwe_enc_structure float elliptic_bpf_2_48k_mem[4][4]; float prev_fb_energy; + Word32 elliptic_bpf_2_48k_mem_fx[4][4]; /*elliptic_bpf_2_48k_mem_fx_Q[4]*/ + Word16 elliptic_bpf_2_48k_mem_fx_Q[4]; + Word32 prev_fb_energy_fx; /*prev_fb_energy_fx_Q*/ + Word16 prev_fb_energy_fx_Q; +#ifndef IVAS_FLOAT_FIXED float prev_gainFr_SHB; float lsp_shb_slow_interpl[LPC_SHB_ORDER]; float lsp_shb_fast_interpl[LPC_SHB_ORDER]; +#else + Word32 prev_gainFr_SHB_fx; /* Q18 */ + Word16 lsp_shb_slow_interpl_fx[LPC_SHB_ORDER]; /* Q15 */ + Word16 lsp_shb_fast_interpl_fx[LPC_SHB_ORDER]; /* Q15 */ +#endif float shb_inv_filt_mem[LPC_SHB_ORDER]; + Word16 shb_inv_filt_mem_fx[LPC_SHB_ORDER]; +#ifndef IVAS_FLOAT_FIXED float lsp_shb_spacing[3]; float prev_swb_GainShape; - Word32 elliptic_bpf_2_48k_mem_fx[4][4]; /*elliptic_bpf_2_48k_mem_fx_Q[4]*/ - Word16 elliptic_bpf_2_48k_mem_fx_Q[4]; - Word32 prev_fb_energy_fx; /*prev_fb_energy_fx_Q*/ - Word16 prev_fb_energy_fx_Q; - Word32 prev_gainFr_SHB_fx; /* Q18 */ - Word16 lsp_shb_slow_interpl_fx[LPC_SHB_ORDER]; /* Q15 */ - Word16 lsp_shb_fast_interpl_fx[LPC_SHB_ORDER]; /* Q15 */ - Word16 shb_inv_filt_mem_fx[LPC_SHB_ORDER]; - Word16 lsp_shb_spacing_fx[3]; /* Q15 */ - Word16 prev_swb_GainShape_fx; /* Q15 */ +#else + Word16 lsp_shb_spacing_fx[3]; /* Q15 */ + Word16 prev_swb_GainShape_fx; /* Q15 */ +#endif + int16_t prev_frGainAtten; +#ifndef IVAS_FLOAT_FIXED float prev_wb_GainShape_flt; float swb_lsp_prev_interp[LPC_SHB_ORDER]; +#else + Word16 prev_wb_GainShape; /* Q15 */ + Word16 swb_lsp_prev_interp_fx[LPC_SHB_ORDER]; /* Q15 */ +#endif float fb_state_lpc_syn[LPC_SHB_ORDER]; float fb_tbe_demph; - float tilt_mem; - Word16 prev_wb_GainShape; /* Q15 */ - Word16 swb_lsp_prev_interp_fx[LPC_SHB_ORDER]; /* Q15 */ Word16 fb_state_lpc_syn_fx[LPC_SHB_ORDER]; Word16 prev_Q_bwe_exc_fb; Word16 fb_tbe_demph_fx; - Word16 tilt_mem_fx; +#ifndef IVAS_FLOAT_FIXED + float tilt_mem; +#else + Word16 tilt_mem_fx; /* Q12 */ +#endif int16_t prev_coder_type; +#ifndef IVAS_FLOAT_FIXED float prev_lsf_diff[LPC_SHB_ORDER - 2]; float prev_tilt_para; +#else + Word16 prev_lsf_diff_fx[LPC_SHB_ORDER - 2]; /* Q15 */ + Word16 prev_tilt_para_fx; /* Q10 */ +#endif float cur_sub_Aq[M + 1]; - Word16 prev_lsf_diff_fx[LPC_SHB_ORDER - 2]; - Word16 prev_tilt_para_fx; /* Q10 */ Word16 cur_sub_Aq_fx[M + 1]; /* Q12 */ /* quantized data */ @@ -1934,8 +2003,8 @@ typedef struct enc_core_structure float prev_fmerit_flt; /* previous signal classification score*/ float fmerit_dt_flt; /* signal classification score difference */ #else - Word16 prev_fmerit; /* previous signal classification score Q15 */ - Word16 fmerit_dt; /* signal classification score difference Q15 */ + Word16 prev_fmerit; /* previous signal classification score Q15 */ + Word16 fmerit_dt; /* signal classification score difference Q15 */ #endif int16_t Nb_ACELP_frames; @@ -2029,13 +2098,16 @@ typedef struct enc_core_structure int16_t coder_type_raw; /* raw coder_type (before UNVOICED is lost) */ int16_t last_coder_type_raw; /* raw last_coder_type (coming from the sigal classification) */ int16_t last_coder_type; /* previous coding type */ - float old_thres; /* normalized correlation weighting in open-loop pitch */ - float old_corr; /* normalized correlation in previous frame (mean value) */ - Word16 old_thres_fx; /* normalized correlation weighting in open-loop pitch Q15 */ - Word16 old_corr_fx; /* normalized correlation in previous frame (mean value) Q15 */ - int16_t old_pitch; /* previous pitch for open-loop pitch search */ - int16_t delta_pit; /* open-loop pitch extrapolation correction */ - float ee_old; /* previous frame low/high frequency energy ratio */ +#ifndef IVAS_FLOAT_FIXED + float old_thres; /* normalized correlation weighting in open-loop pitch */ +#else + Word16 old_thres_fx; /* normalized correlation weighting in open-loop pitch Q15 */ +#endif + float old_corr; /* normalized correlation in previous frame (mean value) */ + Word16 old_corr_fx; /* normalized correlation in previous frame (mean value) Q15 */ + int16_t old_pitch; /* previous pitch for open-loop pitch search */ + int16_t delta_pit; /* open-loop pitch extrapolation correction */ + float ee_old; /* previous frame low/high frequency energy ratio */ Word32 ee_old_fx; int16_t min_band; /* minimum critical band of useful bandwidth */ @@ -2107,6 +2179,7 @@ typedef struct enc_core_structure Word32 *input_buff32_fx; Word16 *input_fx; Word32 *input32_fx; + Word16 q_inp32; Word16 q_inp; Word16 *old_input_signal_fx; // Word16 q_old_inp; @@ -2175,7 +2248,11 @@ typedef struct enc_core_structure int16_t sharpFlag; int16_t localVAD; /* i : local VAD flag */ +#ifndef IVAS_FLOAT_FIXED float bckr_tilt_lt_flt; +#else + Word32 bckr_tilt_lt; /* Q16 */ +#endif float lp_speech; float lp_noise; /* CNG and DTX - LP filtered total noise estimation */ Word16 lp_speech_fx; // Q8 @@ -2185,8 +2262,7 @@ typedef struct enc_core_structure Word16 lp_noise_fx; /* CNG and DTX - LP filtered total noise estimation Q8 */ Word16 var_SID_rate_flag_fx; /* CNG and DTX - flag for variable SID rate */ Word16 interval_SID_fx; - Word32 bckr_tilt_lt; // Q16 - int16_t active_cnt; /* counter of active frames */ + int16_t active_cnt; /* counter of active frames */ TD_CNG_ENC_HANDLE hTdCngEnc; @@ -2214,10 +2290,13 @@ typedef struct enc_core_structure HANDLE_FD_CNG_ENC hFdCngEnc; int16_t fd_cng_reset_flag; +#ifndef IVAS_FLOAT_FIXED float last_totalNoise; float totalNoise_increase_hist[TOTALNOISE_HIST_SIZE]; - Word16 last_totalNoise_fx; - Word16 totalNoise_increase_hist_fx[TOTALNOISE_HIST_SIZE]; +#else + Word16 last_totalNoise_fx; /* Q8 */ + Word16 totalNoise_increase_hist_fx[TOTALNOISE_HIST_SIZE]; /* Q8 */ +#endif int16_t totalNoise_increase_len; /*----------------------------------------------------------------------------------* @@ -2231,14 +2310,17 @@ typedef struct enc_core_structure *----------------------------------------------------------------------------------*/ /* Memory for detect_transient() */ +#ifndef IVAS_FLOAT_FIXED float old_hpfilt_in; float old_hpfilt_out; float EnergyLT; float Energy_Old; +#else Word16 old_hpfilt_in_fx; Word16 old_hpfilt_out_fx; - Word32 EnergyLT_fx; + Word32 EnergyLT_fx; /* Q(EnergyLT_fx_exp) */ Word32 Energy_Old_fx; +#endif int16_t TransientHangOver; HQ_ENC_HANDLE hHQ_core; /* HQ core encoder handle */ @@ -2352,16 +2434,19 @@ typedef struct enc_core_structure #ifndef IVAS_FLOAT_FIXED float gamma_flt; #else - Word16 gamma; /* Q15 */ - Word16 inv_gamma; /* Q14 */ + Word16 gamma; /* Q15 */ + Word16 inv_gamma; /* Q14 */ #endif TRAN_DET_HANDLE hTranDet; TransientDetection transientDetection; Word16 transient_info[3]; int16_t acelpFramesCount; +#ifndef IVAS_FLOAT_FIXED float prevTempFlatness; - Word16 prevTempFlatness_fx; /* exponent is AVG_FLAT_E */ +#else + Word16 prevTempFlatness_fx; /* exponent is AVG_FLAT_E Q7 */ +#endif float prevEnergyHF; float currEnergyHF; @@ -2425,14 +2510,20 @@ typedef struct enc_core_structure int16_t glr; int16_t glr_idx[2]; +#ifndef IVAS_FLOAT_FIXED float mean_gc_flt[2]; float prev_lsf4_mean_flt; - Word32 mean_gc[2]; - Word16 prev_lsf4_mean; +#else + Word32 mean_gc[2]; /* Q15 */ + Word16 prev_lsf4_mean; /* Qlog2(2.56) */ +#endif int16_t glr_reset; int32_t last_sr_core; +#ifndef IVAS_FLOAT_FIXED float last_stab_fac_flt; - Word16 last_stab_fac; +#else + Word16 last_stab_fac; /* Q15 */ +#endif Word32 gain_code[NB_SUBFR16k]; diff --git a/lib_enc/swb_bwe_enc.c b/lib_enc/swb_bwe_enc.c index e7a802c98..82302f1cf 100644 --- a/lib_enc/swb_bwe_enc.c +++ b/lib_enc/swb_bwe_enc.c @@ -45,6 +45,7 @@ #include "basop_proto_func.h" #include "wmc_auto.h" +#ifndef IVAS_FLOAT_FIXED /*---------------------------------------------------------------------* * Local function prototypes *---------------------------------------------------------------------*/ @@ -54,9 +55,7 @@ static void MSVQ_Interpol_Tran( float *SWB_env_energy, int16_t *indice ); static void calculate_tonality( const float *org, const float *gen, float *SFM_org, float *SFM_gen, const int16_t length ); static int16_t WB_BWE_encoding( Encoder_State *st, const float *yos, float *WB_fenv ); static void energy_control( Encoder_State *st, const int16_t core, const int16_t mode, const int16_t coder_type, const float *org, const int16_t offset, float *energy_factor ); -#ifndef IVAS_FLOAT_FIXED static int16_t decision_hq_generic_class( const float *coefs, const int16_t hq_generic_offset ); -#endif /*-------------------------------------------------------------------* @@ -1040,7 +1039,7 @@ static void msvq_interpol( return; } -#ifndef IVAS_FLOAT_FIXED + /*-------------------------------------------------------------------* * msvq_interpol_2() * @@ -1147,7 +1146,7 @@ static void msvq_interpol_2( return; } -#endif + /*-------------------------------------------------------------------* * calculate_tonality() * @@ -1595,7 +1594,6 @@ static int16_t SWB_BWE_encoding( return mode; } -#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * decision_hq_generic_class() * @@ -1840,8 +1838,8 @@ void hq_generic_hf_encoding( return; } - #endif + /*-------------------------------------------------------------------* * fd_bwe_enc_init() * diff --git a/lib_enc/swb_bwe_enc_hr.c b/lib_enc/swb_bwe_enc_hr.c index acdfc95e0..6b7748eef 100644 --- a/lib_enc/swb_bwe_enc_hr.c +++ b/lib_enc/swb_bwe_enc_hr.c @@ -41,6 +41,7 @@ #include "rom_com.h" #include "wmc_auto.h" +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * en_band_quant() * @@ -503,3 +504,4 @@ void swb_bwe_enc_hr( return; } +#endif diff --git a/lib_enc/swb_bwe_enc_lr.c b/lib_enc/swb_bwe_enc_lr.c index f48d8c63b..6ee7ea75a 100644 --- a/lib_enc/swb_bwe_enc_lr.c +++ b/lib_enc/swb_bwe_enc_lr.c @@ -43,6 +43,7 @@ #include "stat_com.h" #include "wmc_auto.h" +#ifndef IVAS_FLOAT_FIXED /*--------------------------------------------------------------------------* * GetSubbandCorrIndex2_har() * @@ -696,3 +697,4 @@ void swb_bwe_enc_lr( return; } +#endif diff --git a/lib_enc/swb_tbe_enc.c b/lib_enc/swb_tbe_enc.c index 2818df555..3db7b0439 100644 --- a/lib_enc/swb_tbe_enc.c +++ b/lib_enc/swb_tbe_enc.c @@ -121,6 +121,7 @@ void InitSWBencBuffer( InitSWBencBufferStates( hBWE_TD, NULL ); #endif +#ifndef IVAS_FLOAT_FIXED for ( i = 0; i < LPC_SHB_ORDER; i++ ) { hBWE_TD->prev_lsp_shb[i] = i / 20.0f; @@ -130,28 +131,66 @@ void InitSWBencBuffer( hBWE_TD->prev_gainFr_SHB = 0; set_f( hBWE_TD->lsp_shb_slow_interpl, 0, LPC_SHB_ORDER ); set_f( hBWE_TD->lsp_shb_fast_interpl, 0, LPC_SHB_ORDER ); +#else + FOR( i = 0; i < LPC_SHB_ORDER; i++ ) + { + hBWE_TD->prev_lsp_shb_fx[i] = lsp_shb_prev_tbl_fx[i]; + } + + hBWE_TD->cldfbHBLT = 8192; + hBWE_TD->prev_gainFr_SHB_fx = 0; + set16_fx( hBWE_TD->lsp_shb_slow_interpl_fx, 0, LPC_SHB_ORDER ); + set16_fx( hBWE_TD->lsp_shb_fast_interpl_fx, 0, LPC_SHB_ORDER ); +#endif set_f( hBWE_TD->shb_inv_filt_mem, 0, LPC_SHB_ORDER ); +#ifndef IVAS_FLOAT_FIXED set_f( hBWE_TD->lsp_shb_spacing, 0.1f, 3 ); hBWE_TD->prev_swb_GainShape = 0; +#else + set16_fx( hBWE_TD->lsp_shb_spacing_fx, 3277, 3 ); + hBWE_TD->prev_swb_GainShape_fx = 0; +#endif hBWE_TD->prev_frGainAtten = 0; +#ifndef IVAS_FLOAT_FIXED hBWE_TD->prev_wb_GainShape_flt = 0; +#else + hBWE_TD->prev_wb_GainShape = 0; +#endif set_f( hBWE_TD->fb_state_lpc_syn, 0, LPC_SHB_ORDER ); hBWE_TD->fb_tbe_demph = 0.0f; +#ifndef IVAS_FLOAT_FIXED hBWE_TD->tilt_mem = 0.0f; +#else + hBWE_TD->tilt_mem_fx = 0; + move16(); +#endif hBWE_TD->prev_coder_type = GENERIC; +#ifndef IVAS_FLOAT_FIXED set_f( hBWE_TD->prev_lsf_diff, 0.5f, LPC_SHB_ORDER - 2 ); hBWE_TD->prev_tilt_para = 0.0f; +#else + set16_fx( hBWE_TD->prev_lsf_diff_fx, 16384, LPC_SHB_ORDER - 2 ); + hBWE_TD->prev_tilt_para_fx = 0; + move16(); +#endif set_f( hBWE_TD->cur_sub_Aq, 0.0f, M + 1 ); /* TD BWE post-processing */ hBWE_TD->ptr_mem_stp_swb = hBWE_TD->mem_stp_swb + LPC_SHB_ORDER - 1; set_f( hBWE_TD->mem_zero_swb, 0, LPC_SHB_ORDER ); +#ifndef IVAS_FLOAT_FIXED for ( i = 0; i < LPC_SHB_ORDER; i++ ) { hBWE_TD->swb_lsp_prev_interp[i] = (float) cos( (float) i * EVS_PI / (float) 10.0f ); } +#else + FOR( i = 0; i < LPC_SHB_ORDER; i++ ) + { + hBWE_TD->swb_lsp_prev_interp_fx[i] = swb_lsp_prev_interp_init[i]; + } +#endif set_f( hBWE_TD->dec_2_over_3_mem, 0.0f, L_FILT_2OVER3 ); set_f( hBWE_TD->dec_2_over_3_mem_lp, 0.0f, L_FILT_2OVER3_LP ); @@ -185,11 +224,19 @@ void InitSWBencBufferStates( set16_fx( hBWE_TD->mem_shb_res_fx, 0, MAX_LEN_MA_FILTER ); set32_fx( hBWE_TD->mem_shb_res_32_fx, 0, MAX_LEN_MA_FILTER ); set_f( hBWE_TD->old_EnvSHBres, 0.0f, L_FRAME4k ); +#ifndef IVAS_FLOAT_FIXED hBWE_TD->old_mean_EnvSHBres = 0.0f; +#else + hBWE_TD->old_mean_EnvSHBres_fx = 0; +#endif hBWE_TD->prev_enr_EnvSHBres = 1.0f; hBWE_TD->prev_shb_env_tilt = 0.0f; hBWE_TD->prev_pow_exc16kWhtnd = 1.0f; +#ifndef IVAS_FLOAT_FIXED hBWE_TD->prev_mix_factor = 1.0f; +#else + hBWE_TD->prev_mix_factor_fx = 32767; +#endif hBWE_TD->prev_Env_error = 0.0f; return; diff --git a/lib_enc/swb_tbe_enc_fx.c b/lib_enc/swb_tbe_enc_fx.c index b7901de5b..7226719ed 100644 --- a/lib_enc/swb_tbe_enc_fx.c +++ b/lib_enc/swb_tbe_enc_fx.c @@ -3966,7 +3966,7 @@ void swb_tbe_enc_ivas_fx( test(); test(); test(); - IF( st_fx->element_mode > EVS_MONO && NE_16( st_fx->L_frame, st_fx->last_L_frame ) && hBWE_TD->prev_gainFr_SHB != 0 && ( EQ_16( st_fx->last_extl, SWB_TBE ) || EQ_16( st_fx->last_extl, FB_TBE ) ) && EQ_16( st_fx->coder_type, TRANSITION ) && NE_16( st_fx->coder_type_raw, VOICED ) && EQ_16( st_fx->clas, VOICED_CLAS ) && EQ_16( st_fx->last_clas, VOICED_CLAS ) && LT_16( mult( 24576 /* 3.0f in Q13 */, voice_factors_fx[0] ), shr( voice_factors_fx[( st_fx->L_frame >> 6 ) - 1], 2 ) ) ) + IF( st_fx->element_mode > EVS_MONO && NE_16( st_fx->L_frame, st_fx->last_L_frame ) && hBWE_TD->prev_gainFr_SHB_fx != 0 && ( EQ_16( st_fx->last_extl, SWB_TBE ) || EQ_16( st_fx->last_extl, FB_TBE ) ) && EQ_16( st_fx->coder_type, TRANSITION ) && NE_16( st_fx->coder_type_raw, VOICED ) && EQ_16( st_fx->clas, VOICED_CLAS ) && EQ_16( st_fx->last_clas, VOICED_CLAS ) && LT_16( mult( 24576 /* 3.0f in Q13 */, voice_factors_fx[0] ), shr( voice_factors_fx[( st_fx->L_frame >> 6 ) - 1], 2 ) ) ) { // float fac = GainFrame / hBWE_TD->prev_gainFr_SHB; Word16 fac = BASOP_Util_Divide3232_Scale( GainFrame_fx, hBWE_TD->prev_gainFr_SHB_fx, &tmp_e ); diff --git a/lib_enc/voiced_enc.c b/lib_enc/voiced_enc.c index 183ec8481..3a0382268 100644 --- a/lib_enc/voiced_enc.c +++ b/lib_enc/voiced_enc.c @@ -41,7 +41,11 @@ #include "cnst.h" #include "rom_com.h" #include "wmc_auto.h" +#ifdef IVAS_FLOAT_FIXED +#include "prot_fx.h" +#endif +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * Local function prototypes *--------------------------------------------------------------------*/ @@ -1126,6 +1130,7 @@ static void SynthesisFilter( return; } +#endif /*---------------------------------------------------------------------* @@ -1168,9 +1173,14 @@ void sc_vbr_enc_init( hSC_VBR->global_frame_cnt = 0; /* 600 active frame block count. Used to update the global rate*/ hSC_VBR->rate_control = 0; +#ifndef IVAS_FLOAT_FIXED hSC_VBR->SNR_THLD = 67.0f; +#else + hSC_VBR->SNR_THLD_fx = SNR_THLD_FX_Q8; +#endif hSC_VBR->mode_QQF = 1; +#ifndef IVAS_FLOAT_FIXED set_f( hSC_VBR->shape1_filt_mem, 0, 20 ); set_f( hSC_VBR->shape2_filt_mem, 0, 20 ); set_f( hSC_VBR->shape3_filt_mem, 0, 20 ); @@ -1178,6 +1188,15 @@ void sc_vbr_enc_init( set_f( hSC_VBR->txlpf1_filt2_mem, 0, 20 ); set_f( hSC_VBR->txhpf1_filt1_mem, 0, 20 ); set_f( hSC_VBR->txhpf1_filt2_mem, 0, 20 ); +#else + set16_fx( hSC_VBR->shape1_filt_mem_fx, 0, 20 ); + set16_fx( hSC_VBR->shape2_filt_mem_fx, 0, 20 ); + set16_fx( hSC_VBR->shape3_filt_mem_fx, 0, 20 ); + set16_fx( hSC_VBR->txlpf1_filt1_mem_fx, 0, 20 ); + set16_fx( hSC_VBR->txlpf1_filt2_mem_fx, 0, 20 ); + set16_fx( hSC_VBR->txhpf1_filt1_mem_fx, 0, 20 ); + set16_fx( hSC_VBR->txhpf1_filt2_mem_fx, 0, 20 ); +#endif hSC_VBR->last_7k2_coder_type = GENERIC; hSC_VBR->vbr_generic_ho = 0; diff --git a/lib_rend/ivas_dirac_decorr_dec.c b/lib_rend/ivas_dirac_decorr_dec.c index b1281b6a2..01bd6edab 100644 --- a/lib_rend/ivas_dirac_decorr_dec.c +++ b/lib_rend/ivas_dirac_decorr_dec.c @@ -328,13 +328,13 @@ ivas_error ivas_dirac_dec_decorr_open( ivas_error ivas_dirac_dec_decorr_open_fx( DIRAC_DECORR_PARAMS **ph_freq_domain_decorr_ap_params, DIRAC_DECORR_STATE **ph_freq_domain_decorr_ap_state, - const Word16 num_freq_bands, - Word16 num_outputs_diff, - const Word16 num_protos_diff, + const Word16 num_freq_bands, // Q0 + Word16 num_outputs_diff, // Q0 + const Word16 num_protos_diff, // Q0 const DIRAC_SYNTHESIS_CONFIG synthesisConf, - Word16 *frequency_axis, - const Word16 nchan_transport, /* i : number of transport channels*/ - const Word32 output_Fs /* i : output sampling rate */ + Word16 *frequency_axis, // Q0 + const Word16 nchan_transport, /* i : number of transport channels Q0*/ + const Word32 output_Fs /* i : output sampling rate Q0*/ ) { Word16 k, l, m, n; @@ -375,7 +375,7 @@ ivas_error ivas_dirac_dec_decorr_open_fx( if ( EQ_16( synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) { - num_outputs_diff = sub( num_outputs_diff, nchan_transport ); + num_outputs_diff = sub( num_outputs_diff, nchan_transport ); // Q0 } assert( ( num_outputs_diff >= 0 ) && ( num_outputs_diff <= DIRAC_MAX_NUM_DECORR_FILTERS ) && "Error: Number of channels <= 0 or > DIRAC_MAX_NUM_DECORR_FILTERS" ); @@ -466,7 +466,7 @@ ivas_error ivas_dirac_dec_decorr_open_fx( { temp = mult( CLDFB_NO_CHANNELS_MAX_FX, ap_split_frequencies_fx[k] ); // Q8 temp = add( temp, ONE_IN_Q7 /*0.5 Q8*/ ); - split_freq_ptr[k] = sub( temp, ONE_IN_Q8 ); + split_freq_ptr[k] = sub( temp, ONE_IN_Q8 ); // Q8 move16(); } split_band_index_start = 0; @@ -482,7 +482,7 @@ ivas_error ivas_dirac_dec_decorr_open_fx( move16(); IF( GE_16( split_frequencies_bands[k], shl( freq_domain_decorr_ap_params->max_band_decorr, Q8 ) ) ) { - split_frequencies_bands[k] = shl( freq_domain_decorr_ap_params->max_band_decorr, Q8 ); + split_frequencies_bands[k] = shl( freq_domain_decorr_ap_params->max_band_decorr, Q8 ); // Q8 move16(); break; } @@ -491,7 +491,7 @@ ivas_error ivas_dirac_dec_decorr_open_fx( /*make it Q0*/ FOR( k = 1; k < DIRAC_DECORR_NUM_SPLIT_BANDS; k++ ) { - split_frequencies_bands[k] = shr( split_frequencies_bands[k], Q8 ); + split_frequencies_bands[k] = shr( split_frequencies_bands[k], Q8 ); // Q8 move16(); } @@ -599,19 +599,19 @@ ivas_error ivas_dirac_dec_decorr_open_fx( WHILE( GT_16( cur_lattice_delta_phi_fx, ONE_IN_Q11 - 1 ) ) { - cur_lattice_delta_phi_fx = sub( cur_lattice_delta_phi_fx, 3217 ); + cur_lattice_delta_phi_fx = sub( cur_lattice_delta_phi_fx, 3217 ); // Q11 } WHILE( LT_16( cur_lattice_delta_phi_fx, -ONE_IN_Q11 ) ) { - cur_lattice_delta_phi_fx = add( cur_lattice_delta_phi_fx, 3217 ); + cur_lattice_delta_phi_fx = add( cur_lattice_delta_phi_fx, 3217 ); // Q11 } - cur_lattice_delta_phi_fx = shl( cur_lattice_delta_phi_fx, 4 ); + cur_lattice_delta_phi_fx = shl( cur_lattice_delta_phi_fx, 4 ); // Q15 Word16 temp_a = getCosWord16( cur_lattice_delta_phi_fx ); Word16 temp_b = negate( getCosWord16( sub( 12868 /*PI/2 in Q13*/, cur_lattice_delta_phi_fx ) ) ); - freq_domain_decorr_ap_params->phase_coeff_real_fx[add( imult1616( l, freq_domain_decorr_ap_params->max_band_decorr ), n )] = temp_a; - freq_domain_decorr_ap_params->phase_coeff_imag_fx[add( imult1616( l, freq_domain_decorr_ap_params->max_band_decorr ), n )] = temp_b; + freq_domain_decorr_ap_params->phase_coeff_real_fx[add( imult1616( l, freq_domain_decorr_ap_params->max_band_decorr ), n )] = temp_a; // Q14 + freq_domain_decorr_ap_params->phase_coeff_imag_fx[add( imult1616( l, freq_domain_decorr_ap_params->max_band_decorr ), n )] = temp_b; // Q14 move16(); move16(); @@ -920,18 +920,19 @@ void ivas_dirac_dec_decorr_process( } #else void ivas_dirac_dec_decorr_process_fx( - const Word16 num_freq_bands, - Word16 num_channels, - const Word16 num_protos_diff, + const Word16 num_freq_bands, // Q0 + Word16 num_channels, // Q0 + const Word16 num_protos_diff, // Q0 const DIRAC_SYNTHESIS_CONFIG synthesisConf, - const Word16 nchan_transport, /* i : number of transport channels*/ - const Word32 *input_frame_fx, - Word16 q_input_frame, - const Word16 num_protos_dir, - const Word16 *proto_index_dir, - Word32 *frame_dec_fx, - Word16 *q_frame_dec, - Word32 *onset_filter_fx, + const Word16 nchan_transport, + /* i : number of transport channels*/ // Q0 + const Word32 *input_frame_fx, // q_input_frame + Word16 q_input_frame, // Q0 + const Word16 num_protos_dir, // Q0 + const Word16 *proto_index_dir, // Q0 + Word32 *frame_dec_fx, // q_frame_dec + Word16 *q_frame_dec, // Q0 + Word32 *onset_filter_fx, // Q0 HANDLE_DIRAC_DECORR_PARAMS h_freq_domain_decorr_ap_params, HANDLE_DIRAC_DECORR_STATE h_freq_domain_decorr_ap_state ) { @@ -1014,17 +1015,17 @@ void ivas_dirac_dec_decorr_process_fx( } FOR( ch_idx = 0; ch_idx < num_protos_dir; ch_idx++ ) { - v_shr( &input_frame_fx[imult1616( 2, imult1616( ch_idx, num_freq_bands ) )], negate( q_shift ), &aux_buffer_fx[imult1616( 2, imult1616( ch_idx, num_freq_bands ) )], imult1616( 2, num_freq_bands ) ); + v_shr( &input_frame_fx[imult1616( 2, imult1616( ch_idx, num_freq_bands ) )], negate( q_shift ), &aux_buffer_fx[imult1616( 2, imult1616( ch_idx, num_freq_bands ) )], imult1616( 2, num_freq_bands ) ); // Q - q_shift } FOR( ch_idx = 0; ch_idx < num_protos_dir; ch_idx++ ) { - v_mult_fixed( &aux_buffer_fx[imult1616( 2, imult1616( ch_idx, num_freq_bands ) )], &aux_buffer_fx[imult1616( 2, imult1616( ch_idx, num_freq_bands ) )], &aux_buffer_fx[imult1616( 2, imult1616( ch_idx, max_band_decorr_temp ) )], imult1616( 2, max_band_decorr_temp ) ); + v_mult_fixed( &aux_buffer_fx[imult1616( 2, imult1616( ch_idx, num_freq_bands ) )], &aux_buffer_fx[imult1616( 2, imult1616( ch_idx, num_freq_bands ) )], &aux_buffer_fx[imult1616( 2, imult1616( ch_idx, max_band_decorr_temp ) )], imult1616( 2, max_band_decorr_temp ) ); // q_aux_buffer } q_aux_buffer = sub( add( add( add( q_input_frame, q_input_frame ), q_shift ), q_shift ), 31 ); FOR( ch_idx = 0; ch_idx < num_protos_dir; ch_idx++ ) { - v_add_inc_fx( &aux_buffer_fx[imult1616( 2, imult1616( ch_idx, max_band_decorr_temp ) )], 2, &aux_buffer_fx[add( imult1616( 2, imult1616( ch_idx, max_band_decorr_temp ) ), 1 )], 2, &aux_buffer_fx[imult1616( ch_idx, max_band_decorr_temp )], 1, max_band_decorr_temp ); + v_add_inc_fx( &aux_buffer_fx[imult1616( 2, imult1616( ch_idx, max_band_decorr_temp ) )], 2, &aux_buffer_fx[add( imult1616( 2, imult1616( ch_idx, max_band_decorr_temp ) ), 1 )], 2, &aux_buffer_fx[imult1616( ch_idx, max_band_decorr_temp )], 1, max_band_decorr_temp ); // q_aux_buffer } /* compute onset filter */ max_band_decorr = h_freq_domain_decorr_ap_params->max_band_decorr; @@ -1038,8 +1039,8 @@ void ivas_dirac_dec_decorr_process_fx( { FOR( Word16 i = 0; i < imult1616( num_protos_diff, max_band_decorr_temp ); i++ ) { - h_freq_domain_decorr_ap_state->h_onset_detection_power_state.onset_detector_2_fx[i] = L_shr( h_freq_domain_decorr_ap_state->h_onset_detection_power_state.onset_detector_2_fx[i], sub( q_onset_dec, q_temp ) ); - h_freq_domain_decorr_ap_state->h_onset_detection_power_state.onset_detector_1_fx[i] = L_shr( h_freq_domain_decorr_ap_state->h_onset_detection_power_state.onset_detector_1_fx[i], sub( q_onset_dec, q_temp ) ); + h_freq_domain_decorr_ap_state->h_onset_detection_power_state.onset_detector_2_fx[i] = L_shr( h_freq_domain_decorr_ap_state->h_onset_detection_power_state.onset_detector_2_fx[i], sub( q_onset_dec, q_temp ) ); // q_temp + h_freq_domain_decorr_ap_state->h_onset_detection_power_state.onset_detector_1_fx[i] = L_shr( h_freq_domain_decorr_ap_state->h_onset_detection_power_state.onset_detector_1_fx[i], sub( q_onset_dec, q_temp ) ); // q_temp move32(); move32(); } @@ -1048,7 +1049,7 @@ void ivas_dirac_dec_decorr_process_fx( { FOR( Word16 i = 0; i < shl( imult1616( num_protos_diff, max_band_decorr_temp ), 1 ); i++ ) { - aux_buffer_fx[i] = L_shr( aux_buffer_fx[i], sub( q_aux_buffer, q_temp ) ); + aux_buffer_fx[i] = L_shr( aux_buffer_fx[i], sub( q_aux_buffer, q_temp ) ); // q_temp move32(); } } @@ -1066,9 +1067,9 @@ void ivas_dirac_dec_decorr_process_fx( FOR( ch_idx = 0; ch_idx < num_protos_dir; ch_idx++ ) { //** this might effect when max_band_decorr is not equal to max_band_decorr_temp// - v_mult_inc_fixed( &input_frame_fx[2 * ch_idx * num_freq_bands], 2, &onset_filter_fx[ch_idx * num_freq_bands], 1, &aux_buffer_fx[2 * ch_idx * max_band_decorr], 2, max_band_decorr ); + v_mult_inc_fixed( &input_frame_fx[2 * ch_idx * num_freq_bands], 2, &onset_filter_fx[ch_idx * num_freq_bands], 1, &aux_buffer_fx[2 * ch_idx * max_band_decorr], 2, max_band_decorr ); // q_input_frame - v_mult_inc_fixed( &input_frame_fx[2 * ch_idx * num_freq_bands + 1], 2, &onset_filter_fx[ch_idx * num_freq_bands], 1, &aux_buffer_fx[2 * ch_idx * max_band_decorr + 1], 2, max_band_decorr ); + v_mult_inc_fixed( &input_frame_fx[2 * ch_idx * num_freq_bands + 1], 2, &onset_filter_fx[ch_idx * num_freq_bands], 1, &aux_buffer_fx[2 * ch_idx * max_band_decorr + 1], 2, max_band_decorr ); // q_input_frame } q_aux_buffer = q_input_frame; move16(); @@ -1093,9 +1094,9 @@ void ivas_dirac_dec_decorr_process_fx( /* final phase rotation */ FOR( k = 0; k < max_band_decorr; k++ ) { - *p_frame_dec_fx = L_sub( Mpy_32_16_1( ( *decorr_buffer_fx ), ( *phase_coeff_real_fx ) ), Mpy_32_16_1( ( *( decorr_buffer_fx + 1 ) ), ( *phase_coeff_imag_fx ) ) ); + *p_frame_dec_fx = L_sub( Mpy_32_16_1( ( *decorr_buffer_fx ), ( *phase_coeff_real_fx ) ), Mpy_32_16_1( ( *( decorr_buffer_fx + 1 ) ), ( *phase_coeff_imag_fx ) ) ); // sub( q_decorr_buf, 1 ) p_frame_dec_fx++; - *p_frame_dec_fx = L_add( Mpy_32_16_1( ( *decorr_buffer_fx ), ( *phase_coeff_imag_fx ) ), Mpy_32_16_1( ( *( decorr_buffer_fx + 1 ) ), ( *phase_coeff_real_fx ) ) ); + *p_frame_dec_fx = L_add( Mpy_32_16_1( ( *decorr_buffer_fx ), ( *phase_coeff_imag_fx ) ), Mpy_32_16_1( ( *( decorr_buffer_fx + 1 ) ), ( *phase_coeff_real_fx ) ) ); // sub( q_decorr_buf, 1 ) p_frame_dec_fx++; phase_coeff_imag_fx++; phase_coeff_real_fx++; @@ -1131,7 +1132,7 @@ void ivas_dirac_dec_decorr_process_fx( FOR( Word16 j = 0; j < shl( imult1616( num_protos_dir, max_band_decorr_temp ), 1 ); j++ ) { - aux_buffer_fx[j] = L_shl( aux_buffer_fx[j], q_shift ); + aux_buffer_fx[j] = L_shl( aux_buffer_fx[j], q_shift ); // add( q_aux_buffer, q_shift ) move32(); } q_aux_buffer = add( q_aux_buffer, q_shift ); @@ -1146,7 +1147,7 @@ void ivas_dirac_dec_decorr_process_fx( { IF( GT_16( sub( q_aux_buffer, q_decorr_buf ), 3 ) ) { - Scale_sig32( aux_buffer_fx, shl( imult1616( num_protos_dir, max_band_decorr_temp ), 1 ), negate( sub( sub( q_aux_buffer, q_decorr_buf ), 3 ) ) ); + Scale_sig32( aux_buffer_fx, shl( imult1616( num_protos_dir, max_band_decorr_temp ), 1 ), negate( sub( sub( q_aux_buffer, q_decorr_buf ), 3 ) ) ); // add( q_decorr_buf, 3 ) } ELSE { @@ -1780,16 +1781,16 @@ static void get_lattice_coeffs( } #else static void get_lattice_coeffs_fx( - const Word16 band_index, - const Word16 channel_index, - Word16 *lattice_coeffs ) + const Word16 band_index, // Q0 + const Word16 channel_index, // Q0 + Word16 *lattice_coeffs ) // Q12 { Word16 k; FOR( k = 0; k < ap_filter_length[band_index]; k++ ) { - Word16 cur_lattice_coeff = ap_lattice_coeffs_fx[band_index][add( imult1616( channel_index, ap_filter_length[band_index] ), k )]; - lattice_coeffs[k] = cur_lattice_coeff; + Word16 cur_lattice_coeff = ap_lattice_coeffs_fx[band_index][add( imult1616( channel_index, ap_filter_length[band_index] ), k )]; // Q12 + lattice_coeffs[k] = cur_lattice_coeff; // Q12 move16(); move16(); } @@ -1846,10 +1847,10 @@ static void lattice2allpass( } #else static void lattice2allpass_fx( - const int16_t filter_length, - const Word16 *lattice_coeffs_fx, - Word16 *filter_coeffs_num_real_fx, - Word16 *filter_coeffs_den_real_fx ) + const int16_t filter_length, // Q0 + const Word16 *lattice_coeffs_fx, // Q15 + Word16 *filter_coeffs_num_real_fx, // Q12 + Word16 *filter_coeffs_den_real_fx ) // Q12 { Word16 i, p; diff --git a/lib_rend/ivas_dirac_onsets_dec.c b/lib_rend/ivas_dirac_onsets_dec.c index 3c884dd7d..160678f7e 100644 --- a/lib_rend/ivas_dirac_onsets_dec.c +++ b/lib_rend/ivas_dirac_onsets_dec.c @@ -191,9 +191,9 @@ ivas_error ivas_dirac_dec_onset_detection_open( } #else ivas_error ivas_dirac_dec_onset_detection_open_fx( - const Word16 num_protos_diff, - const Word16 num_freq_bands, - const Word16 max_band_decorr, + const Word16 num_protos_diff, // Q0 + const Word16 num_freq_bands, // Q0 + const Word16 max_band_decorr, // Q0 DIRAC_ONSET_DETECTION_PARAMS *ph_dirac_onset_detection_params, DIRAC_ONSET_DETECTION_STATE *ph_dirac_onset_detection_state ) { @@ -222,7 +222,7 @@ ivas_error ivas_dirac_dec_onset_detection_open_fx( /* init to zero */ set32_fx( dirac_onset_detection_state->onset_detector_1_fx, 0, imult1616( num_protos_diff, dirac_onset_detection_params->max_band_decorr ) ); set32_fx( dirac_onset_detection_state->onset_detector_2_fx, 0, imult1616( num_protos_diff, dirac_onset_detection_params->max_band_decorr ) ); - dirac_onset_detection_state->q_onset_detector = Q31; + dirac_onset_detection_state->q_onset_detector = Q31; // Q31 move16(); return IVAS_ERR_OK; @@ -281,8 +281,8 @@ void ivas_dirac_dec_onset_detection_process( } #else void ivas_dirac_dec_onset_detection_process_fx( - const Word32 *input_power_f, - Word32 *onset_filter, + const Word32 *input_power_f, // Qx + Word32 *onset_filter, // Qx const Word16 num_protos_diff, DIRAC_ONSET_DETECTION_PARAMS h_dirac_onset_detection_params, DIRAC_ONSET_DETECTION_STATE h_dirac_onset_detection_state ) @@ -320,19 +320,19 @@ void ivas_dirac_dec_onset_detection_process_fx( move32(); IF( LT_32( *p_onset_detector_2_fx, *p_onset_detector_1_fx ) ) { - *p_onset_detector_2_fx = *p_onset_detector_2_fx; + *p_onset_detector_2_fx = *p_onset_detector_2_fx; /* Q(q_onset_detector) */ move32(); } ELSE { - *p_onset_detector_2_fx = *p_onset_detector_1_fx; + *p_onset_detector_2_fx = *p_onset_detector_1_fx; /* Q(q_onset_detector) */ move32(); } IF( *p_onset_detector_1_fx == 0 ) { - *p_onset_detector_1_fx = L_add( *p_onset_detector_1_fx, EPSILON_FX ); + *p_onset_detector_1_fx = L_add( *p_onset_detector_1_fx, EPSILON_FX ); /* Q(q_onset_detector) */ move32(); } /*onset filter limited between 0 and 1*/ diff --git a/lib_rend/ivas_prot_rend.h b/lib_rend/ivas_prot_rend.h index 7e7d93588..b3dde9603 100644 --- a/lib_rend/ivas_prot_rend.h +++ b/lib_rend/ivas_prot_rend.h @@ -711,12 +711,11 @@ ivas_error ivas_dirac_dec_onset_detection_open( #ifdef IVAS_FLOAT_FIXED ivas_error ivas_dirac_dec_onset_detection_open_fx( - const Word16 num_protos_diff, - const Word16 num_freq_bands, - const Word16 max_band_decorr, + const Word16 num_protos_diff, //Q0 + const Word16 num_freq_bands, //Q0 + const Word16 max_band_decorr, //Q0 DIRAC_ONSET_DETECTION_PARAMS *ph_dirac_onset_detection_params, - DIRAC_ONSET_DETECTION_STATE *ph_dirac_onset_detection_state -); + DIRAC_ONSET_DETECTION_STATE *ph_dirac_onset_detection_state ); ivas_error ivas_dirac_dec_decorr_open_fx( DIRAC_DECORR_PARAMS **ph_freq_domain_decorr_ap_params, @@ -741,8 +740,8 @@ void ivas_dirac_dec_onset_detection_process( #ifdef IVAS_FLOAT_FIXED void ivas_dirac_dec_onset_detection_process_fx( - const Word32 *input_power_f, - Word32 *onset_filter, + const Word32 *input_power_f, /* Q(0) */ + Word32 *onset_filter, /* Q(0) */ const Word16 num_protos_diff, DIRAC_ONSET_DETECTION_PARAMS h_dirac_onset_detection_params, DIRAC_ONSET_DETECTION_STATE h_dirac_onset_detection_state diff --git a/lib_rend/ivas_reverb.c b/lib_rend/ivas_reverb.c index 544f4310c..ae388897f 100644 --- a/lib_rend/ivas_reverb.c +++ b/lib_rend/ivas_reverb.c @@ -2489,6 +2489,9 @@ ivas_error ivas_reverb_open_fx( params.pDsr_fx = params.pRt60_fx + nr_fc_fft_filter; params.pFc_fx = &pState->fft_filter_color_0.fft_spectrum_fx[0]; params.pHrtf_inter_aural_coherence_fx = &pState->fft_filter_color_1.fft_spectrum_fx[0]; +#ifdef MSAN_FIX + set32_fx( pState->fft_filter_color_1.fft_spectrum_fx, 0, RV_FILTER_MAX_FFT_SIZE ); +#endif /* Note: these temp buffers can only be used before the final step of the FFT filter design : */ /* before calls to ivas_reverb_calc_correl_filters(...) or to ivas_reverb_calc_color_filters(...) */ diff --git a/lib_rend/ivas_rom_TdBinauralRenderer.c b/lib_rend/ivas_rom_TdBinauralRenderer.c index 2fb147ee5..5cfb13deb 100644 --- a/lib_rend/ivas_rom_TdBinauralRenderer.c +++ b/lib_rend/ivas_rom_TdBinauralRenderer.c @@ -48,22 +48,22 @@ const float defaultHRIR_rom_latency_s = 0.000020834f; #endif const Word32 defaultHRIR_rom_latency_s_fx = 44741; /* Q31 */ -const int16_t defaultHRIR_rom_azimDim2[15] = { +const Word16 defaultHRIR_rom_azimDim2[15] = { 1, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 1, }; -const int16_t defaultHRIR_rom_azimDim3[15] = { +const Word16 defaultHRIR_rom_azimDim3[15] = { 1, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 1, }; -const int16_t defaultHRIR_rom_azim_start_idx[15] = { +const Word16 defaultHRIR_rom_azim_start_idx[15] = { 0, 1, 37, 73, 109, 145, 181, 217, 253, 289, 325, 361, 397, 433, 469, }; -const int16_t defaultHRIR_rom_azimSegSamples[1] = { +const Word16 defaultHRIR_rom_azimSegSamples[1] = { 10, }; -const int16_t defaultHRIR_rom_azimShapeIdx[15] = { +const Word16 defaultHRIR_rom_azimShapeIdx[15] = { -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, }; -const int16_t defaultHRIR_rom_azimShapeSampFactor[15] = { +const Word16 defaultHRIR_rom_azimShapeSampFactor[15] = { -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, }; @@ -90,7 +90,7 @@ const Word32 defaultHRIR_rom_azimBsShape_fx[21]/*Q30*/ = { #endif #ifdef IVAS_FLOAT_FIXED -const UWord32 defaultHRIR_rom_AlphaL48_fx[470 * 128] = { +const UWord32 defaultHRIR_rom_AlphaL48_fx[470 * 128] /*Q30*/= { 0x08946b90,0x01b51044,0x0a3be7e0,0x08059140,0x08956970,0x08977810,0x0902edf0,0x092d8070,0x09514fc0,0x09037030,0x08d22420,0x089c8890,0x086fde70,0x084b4aa0,0x0835ecf0,0x08249b70,0x08116dd0,0x08085020,0x07e77410,0x0773bf10,0x095b7f10,0x01583d2c,0xfee45aca,0xfbd573d8,0x02d72514, 0xff01b3a9,0xfc39200c,0xfc096278,0xfc3dc844,0xfd17e024,0xfc2228c0,0xfbd986e0,0xfc0bded8,0xff02a7ec,0x03e2cc90,0xfc372258,0xfe92ec80,0xfe04a288,0x08e19d20,0x0a0943f0,0x09fe5830,0x0a947bb0,0x0bc07e70,0x0c4e2300,0x0c63c590,0x0ba72080,0x0af61460,0x0a475af0,0x09bd4da0,0x09633a90, 0x0933ee10,0x0906f870,0x08c19050,0x08b9f000,0x08125690,0x0850f510,0x06f136a8,0xfecea9ee,0x041a5f78,0x0324e7d4,0x0320b0d8,0x02092f50,0x03aa0f60,0x0410f470,0x037ff800,0x01f8011c,0x03dc8dbc,0x05a77198,0x03c94958,0x04436480,0x0298d478,0x0237f498,0x068949c8,0x0242ea64,0x07d952a0, @@ -2499,7 +2499,7 @@ const UWord32 defaultHRIR_rom_AlphaL48_fx[470 * 128] = { 0xffff05ed,0xffff0401,0xfffef94c,0xfffee868,0xfffedde9,0xfffedc62,0xfffeb004,0xfffe8b7f,0xfffe6cde,0xfffe4910,0xfffe30fb,0xfffe0fdf,0xfffe2852,0xfffe31ed,0xfffe3b22,0xfffe4b08,0xfffe4c27,0xfffe89e7,0xfffe14e1,0xfffe389c,0xfffd9736,0x0000caca,0x0000795b,0x000077ad,0x00007a6e, 0x000079db,0x000079d5,0x000079d9,0x00007a6c,0x000077c2,0x00007981,0x0000c58b,0xfffdc44c,0xfffe8035,0xfffe5828 }; -const UWord32 defaultHRIR_rom_AlphaR48_fx[470 * 128] = { +const UWord32 defaultHRIR_rom_AlphaR48_fx[470 * 128] /*Q30*/= { 0x08945950,0x08070b50,0x0a49d6a0,0x01bd7c0a,0xfe8e8ea8,0xfc2f2da0,0x03d9eadc,0xff0186c2,0xfc122c50,0xfbe0a0e8,0xfc206c28,0xfd11f02c,0xfc3abd38,0xfc07e728,0xfc3b9950,0xff036bd6,0x02d4bca0,0xfbdbc558,0xfef1f73c,0x015de0c6,0x095c18c0,0x0773d5b8,0x07e73000,0x080876d0,0x081163c0, 0x0824a330,0x0835f7f0,0x084b5f70,0x086feee0,0x089c88a0,0x08d20e60,0x090371e0,0x09517940,0x092d8530,0x09028ae0,0x08987f90,0x08931f20,0x0a0e8e20,0x08b90d00,0xfdf48fbc,0x0693d930,0x02488cdc,0x02b07554,0x04443188,0x03bbc4f4,0x0594cd00,0x03e35c18,0x0205e0c8,0x0385d814,0x04150620, 0x03a53d84,0x0201923c,0x032afa50,0x03171178,0x03f60448,0xfec67ca4,0x06ee54d8,0x0851b610,0x0812b5e0,0x08b99090,0x08c1d7a0,0x0906cf10,0x0933fa90,0x0962ff70,0x09bd4010,0x0a475770,0x0af66880,0x0ba70470,0x0c63a8e0,0x0c4da000,0x0bc22ab0,0x0a9207f0,0x0a00d410,0x0ba14f60,0x082f2360, @@ -4908,7 +4908,7 @@ const UWord32 defaultHRIR_rom_AlphaR48_fx[470 * 128] = { 0xfffea403,0xfffe8046,0xfffdc451,0x0000c589,0x00007983,0x000077c3,0x00007a6d,0x000079da,0x000079d6,0x000079db,0x00007a70,0x000077ad,0x00007957,0x0000caeb,0xfffd96db,0xfffe38c4,0xfffe17ea,0xfffe8d40,0xfffe4caf,0xfffe4a9f,0xfffe3b3c,0xfffe31ec,0xfffe284d,0xfffe0fda,0xfffe30ff, 0xfffe4917,0xfffe6ce4,0xfffe8b83,0xfffeb014,0xfffedc7c,0xfffede07,0xfffee879,0xfffef944,0xffff0401,0xfffe5825, }; -const UWord32 defaultHRIR_rom_AlphaL32_fx[470 * 86] = { +const UWord32 defaultHRIR_rom_AlphaL32_fx[470 * 86] /*Q30*/= { 0x100cd6e0,0x03ada060,0x1363aec0,0x0eeb9f60,0x101f3420,0x0ffc18c0,0x10e4c040,0x113b8380,0x117faa40,0x10f36460,0x109615e0,0x1029fa80,0x0fd129a0,0x0f89b9a0,0x0f672bf0,0x0f4293d0,0x0f1fca20,0x0f0cc6c0,0x0edc4f60,0x0de07780,0x11af0240,0x02fb58f8,0xfd048398,0xf50b7dc0,0x06155418, 0xfd68e604,0xf5f7de90,0xf5a34550,0xf5febb10,0xf7c14d10,0xf5e3f200,0xf56df070,0xf5e14d60,0xfd7c6ae4,0x0836d5d0,0xf5ceff80,0xfc4e19a0,0xfa81c158,0x11195200,0x12a23f40,0x12b60200,0x13902ca0,0x1610a420,0x17304340,0x175cbae0,0x16139d80,0x14bec2c0,0x135466e0,0x123a1600,0x118c51c0, 0x1147b520,0x10ed2ba0,0x10739900,0x1066d060,0x0f427540,0x0f908120,0x0d5b2440,0xfc723054,0x07825ef8,0x05f29028,0x05698548,0x035f134c,0x06fd5468,0x07d6dce0,0x070d2a78,0x03aefedc,0x07bd4520,0x0acd1e20,0x06d3d4d0,0x07f90c48,0x04391780,0x03b60b90,0x0c5eb790,0x03ee4574,0x0ec7ef40, @@ -6527,7 +6527,7 @@ const UWord32 defaultHRIR_rom_AlphaL32_fx[470 * 86] = { 0xffffc40c,0xffffc4b2,0xffffbada,0xffffcd42,0xffffd596,0xfffffcd9,0x00007843,0x0000740d,0xfffed1d5,0xffff4a9e,0xffff440e,0xffff3e6d,0xffff34fd,0xffff2752,0xffff1e63,0xffff18a6,0xffff01af,0xfffeeb5a,0xfffeda7f,0xfffec55c,0xfffeb9a5,0xfffea925,0xfffeb804,0xfffebd16,0xfffec275, 0xfffeca6b,0xfffec8a8,0xffff02a2,0xfffe5abf,0xfffe87fd,0xfffe61a0,0x00008947,0x00004c91,0x00009b73,0x00009b06,0x000097a3,0x00009869,0x00009728,0x00009918,0x000093ea,0x000056c5,0x0000849f,0xfffe9273,0xfffed20a,0xfffec5f7, }; -const UWord32 defaultHRIR_rom_AlphaR32_fx[470 * 86] = { +const UWord32 defaultHRIR_rom_AlphaR32_fx[470 * 86] /*Q30*/= { 0x100cb860,0x0eef8620,0x13822fa0,0x03bfbf7c,0xfc41efd4,0xf5ba68d0,0x0822d810,0xfd7a6134,0xf5eecc80,0xf57c62e0,0xf5e038f0,0xf7b60930,0xf5f98590,0xf5a102c0,0xf5fd0030,0xfd6bb708,0x060f7ee0,0xf515aa30,0xfd1b6c7c,0x030560c0,0x11b23540,0x0de148b0,0x0edb67d0,0x0f0d2c70,0x0f1faf20, 0x0f42a240,0x0f674600,0x0f89e680,0x0fd14ea0,0x1029fb20,0x1095f420,0x10f36760,0x117ff400,0x113b8180,0x10e3f6e0,0x0ffe4180,0x101a20a0,0x12abb7e0,0x10c05ec0,0xfa5f0c98,0x0c7b5470,0x03e36f60,0x046c52a0,0x07fa7bf8,0x06b65ea0,0x0aa712f0,0x07cc00b8,0x03c8cd8c,0x07173000,0x07dd44e8, 0x06f32888,0x03515f80,0x058072f8,0x05db9da8,0x0744ab60,0xfc64e6dc,0x0d4f09e0,0x0f91bbc0,0x0f43d870,0x1065b780,0x10745600,0x10ecc420,0x1147ca40,0x118bce20,0x1239ed60,0x13545de0,0x14bf5420,0x16135d00,0x175ca760,0x172f3020,0x16143f40,0x138ab280,0x12bc2cc0,0x15e153c0,0x0f8672c0, @@ -8146,7 +8146,7 @@ const UWord32 defaultHRIR_rom_AlphaR32_fx[470 * 86] = { 0xfffeda4a,0xfffeea0d,0xfffeeb27,0xfffeeb7d,0xfffefb02,0xffff0ca9,0xffff0919,0xffff2b05,0xffff43fe,0xffff4afb,0xfffed1ec,0xfffed1af,0xfffe92a1,0x000084ec,0x000056b8,0x000093e9,0x0000991b,0x00009728,0x0000986b,0x000097a4,0x00009b07,0x00009b74,0x00004c8e,0x0000895e,0xfffe615a, 0xfffe87fe,0xfffe5cdc,0xffff0514,0xfffec90e,0xfffeca1c,0xfffec288,0xfffebd15,0xfffeb802,0xfffea922,0xfffeb9a9,0xfffec560,0xfffeda7f,0xfffeeb5e,0xffff01ba,0xffff18b4,0xffff1e73,0xffff275b,0xffff3500,0xffff3e52,0xfffec5f4, }; -const UWord32 defaultHRIR_rom_AlphaL16_fx[470 * 43] = { +const UWord32 defaultHRIR_rom_AlphaL16_fx[470 * 43] /*Q30*/= { 0x20bc6cc0,0x187d2c60,0x20d0fb40,0x1e5b58c0,0x1ff07300,0x208f6ec0,0x21e21e40,0x227fff40,0x231b98c0,0x22400500,0x21bce580,0x2129dc80,0x2085a440,0x1feba500,0x1f50d8e0,0x1ee88420,0x1e7a2340,0x1e1bc600,0x1dad7840,0x1c7fbbe0,0x1ee2e620,0x1708c780,0x121adb20,0x0748b300,0x18c877a0, 0x1233e240,0x080e9a60,0x081de920,0x086274f0,0x09c7ed60,0x08fd8b60,0x08f8e8d0,0x096fa820,0x12b862c0,0x1aa86160,0x091d3490,0x12a28f40,0x116ccd00,0x22d41740,0x23937f00,0x25cc5200,0x2848be40,0x2c640fc0,0x2e780f40,0x2f0c1840,0x2cc1b4c0,0x2aad3400,0x28b2fcc0,0x26c3ec40,0x25066fc0, 0x23681900,0x222a5040,0x20f05480,0x20256780,0x1e7ab1e0,0x1d7eaac0,0x1c6be460,0x0eca8780,0x167cc5c0,0x15e0e960,0x13f86880,0x11fb2fc0,0x1541d600,0x157fc3a0,0x15c64020,0x134c6ba0,0x16410020,0x18031d00,0x15a6af40,0x176efbc0,0x15265380,0x15a5b600,0x1c7263a0,0x169b7620,0x1ff14a80, @@ -8957,7 +8957,7 @@ const UWord32 defaultHRIR_rom_AlphaL16_fx[470 * 43] = { 0xfff93aa6,0xfff92570,0xfff8f7a2,0xfff8848a,0xfff847dc,0xfff803e1,0xfff77ff2,0xfff6f7d2,0xfff6a07c,0xfff62c9c,0xfff5fd96,0xfff5ada6,0xfff63a65,0xfff685ba,0xfff6c4f9,0xfff72f17,0xfff756e1,0xfff8219c,0xfff7b122,0xfff7784f,0xfff68a1f,0xfffcae7b,0xfffcb53a,0xfffd35e7,0xfffd11bc, 0xfffd0522,0xfffcf930,0xfffcff01,0xfffcfd89,0xfffcff41,0xfffc9a53,0xfffceec8,0xfff60ae3,0xfff6eb5a,0xfff60a41, }; -const UWord32 defaultHRIR_rom_AlphaR16_fx[470 * 43] = { +const UWord32 defaultHRIR_rom_AlphaR16_fx[470 * 43]/*Q30*/ = { 0x20bc5600,0x1e5ed260,0x20e8da40,0x188db140,0x12958b20,0x0906c690,0x1a999ee0,0x12ba4920,0x097dce40,0x0906b8e0,0x08f8ab10,0x09bc0990,0x085c3450,0x081bb920,0x08157b10,0x123510e0,0x18bd42a0,0x07506690,0x1230f920,0x1711f640,0x1ee77fa0,0x1c814cc0,0x1dac1bc0,0x1e1c44c0,0x1e7a0b40, 0x1ee88080,0x1f50d220,0x1febad40,0x2085ba80,0x2129d500,0x21bca140,0x22401bc0,0x231c2200,0x227fd880,0x21e17340,0x2090c740,0x1fec8d80,0x239775c0,0x22918780,0x1148e780,0x1c908300,0x15dcf3e0,0x1546c9e0,0x176b49a0,0x15864820,0x17de99a0,0x1652d300,0x13666440,0x15d3e660,0x15857380, 0x1533c000,0x11ef5f40,0x141e81e0,0x15ce7080,0x163fb3a0,0x0ec15720,0x1c5a3ce0,0x1d7f55c0,0x1e7d0be0,0x2023db80,0x20f12d40,0x2229f440,0x236884c0,0x25063640,0x26c3e400,0x28b2f780,0x2aae0480,0x2cc17d40,0x2f0af400,0x2e77cec0,0x2c671ec0,0x284489c0,0x25d28c00,0x25b2b200,0x207c4f40, diff --git a/lib_rend/ivas_rom_TdBinauralRenderer.h b/lib_rend/ivas_rom_TdBinauralRenderer.h index cc7510a6f..8f3f13a2b 100644 --- a/lib_rend/ivas_rom_TdBinauralRenderer.h +++ b/lib_rend/ivas_rom_TdBinauralRenderer.h @@ -41,14 +41,14 @@ /* TD renderer default HRIR model */ #ifdef IVAS_FLOAT_FIXED -extern const Word32 defaultHRIR_rom_latency_s_fx; -extern const Word16 defaultHRIR_rom_azimDim2[15]; -extern const Word16 defaultHRIR_rom_azimDim3[15]; -extern const Word16 defaultHRIR_rom_azim_start_idx[15]; -extern const Word16 defaultHRIR_rom_azimSegSamples[1]; -extern const Word16 defaultHRIR_rom_azimShapeIdx[15]; -extern const Word16 defaultHRIR_rom_azimShapeSampFactor[15]; -extern const Word32 defaultHRIR_rom_elevKSeq_fx[13]; +extern const Word32 defaultHRIR_rom_latency_s_fx; /* Q31 */ +extern const Word16 defaultHRIR_rom_azimDim2[15]; /* Q0 */ +extern const Word16 defaultHRIR_rom_azimDim3[15]; /* Q0 */ +extern const Word16 defaultHRIR_rom_azim_start_idx[15]; /* Q0 */ +extern const Word16 defaultHRIR_rom_azimSegSamples[1]; /* Q0 */ +extern const Word16 defaultHRIR_rom_azimShapeIdx[15]; /* Q0 */ +extern const Word16 defaultHRIR_rom_azimShapeSampFactor[15]; /* Q0 */ +extern const Word32 defaultHRIR_rom_elevKSeq_fx[13]; /* Q22 */ #else extern const float defaultHRIR_rom_latency_s; extern const int16_t defaultHRIR_rom_azimDim2[15]; diff --git a/lib_rend/ivas_rom_binauralRenderer.c b/lib_rend/ivas_rom_binauralRenderer.c index f79e4ce64..fa39b67b3 100644 --- a/lib_rend/ivas_rom_binauralRenderer.c +++ b/lib_rend/ivas_rom_binauralRenderer.c @@ -60,7 +60,7 @@ const float FASTCONV_HOA3_latency_s = 0.000020833f; #endif #ifdef IVAS_FLOAT_FIXED -const Word32 leftHRIRReal_HOA3_fx[BINAURAL_CONVBANDS][HOA3_CHANNELS][BINAURAL_NTAPS_SBA]= +const Word32 leftHRIRReal_HOA3_fx[BINAURAL_CONVBANDS][HOA3_CHANNELS][BINAURAL_NTAPS_SBA] /* Q29 */= { { { 189679184, 304322592, 107436456, }, @@ -1870,7 +1870,7 @@ const float leftHRIRReal_HOA3[BINAURAL_CONVBANDS][HOA3_CHANNELS][BINAURAL_NTAPS_ #endif #ifdef IVAS_FLOAT_FIXED -const Word32 leftHRIRImag_HOA3_fx[BINAURAL_CONVBANDS][HOA3_CHANNELS][BINAURAL_NTAPS_SBA]= +const Word32 leftHRIRImag_HOA3_fx[BINAURAL_CONVBANDS][HOA3_CHANNELS][BINAURAL_NTAPS_SBA] /* Q29 */= { { { -102715752, 295527040, -88424248, }, @@ -3680,7 +3680,7 @@ const float leftHRIRImag_HOA3[BINAURAL_CONVBANDS][HOA3_CHANNELS][BINAURAL_NTAPS_ #endif #ifdef IVAS_FLOAT_FIXED -const Word32 rightHRIRReal_HOA3_fx[BINAURAL_CONVBANDS][HOA3_CHANNELS][BINAURAL_NTAPS_SBA]= +const Word32 rightHRIRReal_HOA3_fx[BINAURAL_CONVBANDS][HOA3_CHANNELS][BINAURAL_NTAPS_SBA] /* Q29 */= { { { 189679184, 304322592, 107436456, }, @@ -5490,7 +5490,7 @@ const float rightHRIRReal_HOA3[BINAURAL_CONVBANDS][HOA3_CHANNELS][BINAURAL_NTAPS #endif #ifdef IVAS_FLOAT_FIXED -const Word32 rightHRIRImag_HOA3_fx[BINAURAL_CONVBANDS][HOA3_CHANNELS][BINAURAL_NTAPS_SBA]= +const Word32 rightHRIRImag_HOA3_fx[BINAURAL_CONVBANDS][HOA3_CHANNELS][BINAURAL_NTAPS_SBA] /* Q29 */= { { { -102715752, 295527040, -88424248, }, @@ -7306,7 +7306,7 @@ const float FASTCONV_HOA2_latency_s = 0.000020833f; #endif #ifdef IVAS_FLOAT_FIXED -const Word32 leftHRIRReal_HOA2_fx[BINAURAL_CONVBANDS][HOA2_CHANNELS][BINAURAL_NTAPS_SBA]= +const Word32 leftHRIRReal_HOA2_fx[BINAURAL_CONVBANDS][HOA2_CHANNELS][BINAURAL_NTAPS_SBA] /* Q29 */= { { { 9749039, 528896224, 129120672, }, @@ -8416,7 +8416,7 @@ const float leftHRIRReal_HOA2[BINAURAL_CONVBANDS][HOA2_CHANNELS][BINAURAL_NTAPS_ #endif #ifdef IVAS_FLOAT_FIXED -const Word32 leftHRIRImag_HOA2_fx[BINAURAL_CONVBANDS][HOA2_CHANNELS][BINAURAL_NTAPS_SBA]= +const Word32 leftHRIRImag_HOA2_fx[BINAURAL_CONVBANDS][HOA2_CHANNELS][BINAURAL_NTAPS_SBA] /* Q29 */= { { { -36158792, 332589920, -120427664, }, @@ -9526,7 +9526,7 @@ const float leftHRIRImag_HOA2[BINAURAL_CONVBANDS][HOA2_CHANNELS][BINAURAL_NTAPS_ #endif #ifdef IVAS_FLOAT_FIXED -const Word32 rightHRIRReal_HOA2_fx[BINAURAL_CONVBANDS][HOA2_CHANNELS][BINAURAL_NTAPS_SBA]= +const Word32 rightHRIRReal_HOA2_fx[BINAURAL_CONVBANDS][HOA2_CHANNELS][BINAURAL_NTAPS_SBA] /* Q29 */= { { { 9749039, 528896224, 129120672, }, @@ -10636,7 +10636,7 @@ const float rightHRIRReal_HOA2[BINAURAL_CONVBANDS][HOA2_CHANNELS][BINAURAL_NTAPS #endif #ifdef IVAS_FLOAT_FIXED -const Word32 rightHRIRImag_HOA2_fx[BINAURAL_CONVBANDS][HOA2_CHANNELS][BINAURAL_NTAPS_SBA]= +const Word32 rightHRIRImag_HOA2_fx[BINAURAL_CONVBANDS][HOA2_CHANNELS][BINAURAL_NTAPS_SBA] /* Q29 */= { { { -36158792, 332589920, -120427664, }, @@ -11752,7 +11752,7 @@ const float FASTCONV_FOA_latency_s = 0.000020833f; #endif #ifdef IVAS_FLOAT_FIXED -const Word32 leftHRIRReal_FOA_fx[BINAURAL_CONVBANDS][FOA_CHANNELS][BINAURAL_NTAPS_SBA]= +const Word32 leftHRIRReal_FOA_fx[BINAURAL_CONVBANDS][FOA_CHANNELS][BINAURAL_NTAPS_SBA] /* Q29 */= { { { 97523672, 405096480, 117391120, }, @@ -12362,7 +12362,7 @@ const float leftHRIRReal_FOA[BINAURAL_CONVBANDS][FOA_CHANNELS][BINAURAL_NTAPS_SB #endif #ifdef IVAS_FLOAT_FIXED -const Word32 leftHRIRImag_FOA_fx[BINAURAL_CONVBANDS][FOA_CHANNELS][BINAURAL_NTAPS_SBA]= +const Word32 leftHRIRImag_FOA_fx[BINAURAL_CONVBANDS][FOA_CHANNELS][BINAURAL_NTAPS_SBA] /* Q29 */= { { { -91827472, 317236480, -98863704, }, @@ -12972,7 +12972,7 @@ const float leftHRIRImag_FOA[BINAURAL_CONVBANDS][FOA_CHANNELS][BINAURAL_NTAPS_SB #endif #ifdef IVAS_FLOAT_FIXED -const Word32 rightHRIRReal_FOA_fx[BINAURAL_CONVBANDS][FOA_CHANNELS][BINAURAL_NTAPS_SBA]= +const Word32 rightHRIRReal_FOA_fx[BINAURAL_CONVBANDS][FOA_CHANNELS][BINAURAL_NTAPS_SBA] /* Q29 */= { { { 97523672, 405096480, 117391120, }, @@ -13582,7 +13582,7 @@ const float rightHRIRReal_FOA[BINAURAL_CONVBANDS][FOA_CHANNELS][BINAURAL_NTAPS_S #endif #ifdef IVAS_FLOAT_FIXED -const Word32 rightHRIRImag_FOA_fx[BINAURAL_CONVBANDS][FOA_CHANNELS][BINAURAL_NTAPS_SBA]= +const Word32 rightHRIRImag_FOA_fx[BINAURAL_CONVBANDS][FOA_CHANNELS][BINAURAL_NTAPS_SBA] /* Q29 */= { { { -91827472, 317236480, -98863704, }, @@ -14198,7 +14198,7 @@ const float FASTCONV_HRIR_latency_s = 0.000666667f; #endif #ifdef IVAS_FLOAT_FIXED -const Word32 leftHRIRReal_fx[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS]= +const Word32 leftHRIRReal_fx[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS] /* Q29 */= { { { 625042304, -38326140, 24910274, }, @@ -15908,7 +15908,7 @@ const float leftHRIRReal[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS]= #endif #ifdef IVAS_FLOAT_FIXED -const Word32 leftHRIRImag_fx[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS]= +const Word32 leftHRIRImag_fx[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS] /* Q29 */= { { { 5232344, 17252346, -539555, }, @@ -17618,7 +17618,7 @@ const float leftHRIRImag[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS]= #endif #ifdef IVAS_FLOAT_FIXED -const Word32 rightHRIRReal_fx[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS]= +const Word32 rightHRIRReal_fx[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS] /* Q29 */= { { { 335878240, 171201152, 7902740, }, @@ -19328,7 +19328,7 @@ const float rightHRIRReal[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS]= #endif #ifdef IVAS_FLOAT_FIXED -const Word32 rightHRIRImag_fx[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS]= +const Word32 rightHRIRImag_fx[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS] /* Q29 */= { { { -135520176, 194871264, -54369992, }, @@ -21894,7 +21894,7 @@ const float FASTCONV_BRIR_latency_s = 0.000937500f; #endif #ifdef IVAS_FLOAT_FIXED -const Word32 leftBRIRReal_fx[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS_MAX]= +const Word32 leftBRIRReal_fx[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS_MAX] /* Q29 */= { { { @@ -40104,7 +40104,7 @@ const float leftBRIRReal[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS_MA #endif #ifdef IVAS_FLOAT_FIXED -const Word32 leftBRIRImag_fx[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS_MAX]= +const Word32 leftBRIRImag_fx[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS_MAX] /* Q29 */= { { { @@ -58314,7 +58314,7 @@ const float leftBRIRImag[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS_MA #endif #ifdef IVAS_FLOAT_FIXED -const Word32 rightBRIRReal_fx[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS_MAX]= +const Word32 rightBRIRReal_fx[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS_MAX] /* Q29 */= { { { @@ -76524,7 +76524,7 @@ const float rightBRIRReal[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS_M #endif #ifdef IVAS_FLOAT_FIXED -const Word32 rightBRIRImag_fx[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS_MAX]= +const Word32 rightBRIRImag_fx[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS_MAX] /* Q29 */= { { { @@ -94734,7 +94734,7 @@ const float rightBRIRImag[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS_M #endif #ifdef IVAS_FLOAT_FIXED -const Word32 fastconvReverberationTimes_fx[CLDFB_NO_CHANNELS_MAX] = +const Word32 fastconvReverberationTimes_fx[CLDFB_NO_CHANNELS_MAX] /* Q31 */= { 921702144, 440470368, 434517536, 447499072, 463134912, 507976512, 495205440, 490485280, 488481664, 470204416, 485509536, 473953952, 475669760, 479900320, 480402816, 487614080, 489409376, 479041312, 472446400, 469403424, 473341888, 468688320, 457950880, 451686688, 445424608, 426812384, 421443680, 418581056, 408736992, 396210720, 387262176, 378315744, 379030848, 381356576, 394241504, 420728544, 436476064, 447572096, 460993888, 472446400, 478710624, 494816736, 502356544, 501753120, 507521248, 509872736, 518894336, 517796960, 512920032, 520515680, 528908032, 528169312, 528495712, 526983904, 523880768, 524250144, 513828416, 518561472, 504280704, 543399232 }; @@ -94747,7 +94747,7 @@ const float fastconvReverberationTimes[CLDFB_NO_CHANNELS_MAX] = #ifdef IVAS_FLOAT_FIXED -const Word32 fastconvReverberationEneCorrections_fx[CLDFB_NO_CHANNELS_MAX] = +const Word32 fastconvReverberationEneCorrections_fx[CLDFB_NO_CHANNELS_MAX] /* Q31 */= { 1254130, 450971, 500363, 455266, 551903, 3259880, 2478196, 2355789, 2716566, 2787433, 4982162, 5222680, 5768141, 5802501, 5652177, 5506148, 5866925, 5856188, 5602785, 5420248, 7337951, 3828963, 2119566, 1501091, 1301375, 1151051, 1097364, 1221918, 1288490, 1166083, 2699387, 2596307, 2055141, 1290637, 588410, 227633, 154618, 109521, 85899, 64424, 51539, 38654, 30064, 27917, 25769, 23622, 19327, 19327, 17179, 17179, 15032, 12884, 10737, 6442, 4294, 4294, 2147, 2147, 0, 0 }; diff --git a/lib_rend/ivas_rom_binauralRenderer.h b/lib_rend/ivas_rom_binauralRenderer.h index 4d731ee43..fa9c6267f 100644 --- a/lib_rend/ivas_rom_binauralRenderer.h +++ b/lib_rend/ivas_rom_binauralRenderer.h @@ -56,18 +56,18 @@ extern float rightHRIRReal_FOA[BINAURAL_CONVBANDS][FOA_CHANNELS][BINAURAL_NTAPS_ extern float rightHRIRImag_FOA[BINAURAL_CONVBANDS][FOA_CHANNELS][BINAURAL_NTAPS_SBA]; #else extern const Word32 FASTCONV_HRIR_latency_s_fx; -extern Word32 leftHRIRReal_HOA3_fx[BINAURAL_CONVBANDS][HOA3_CHANNELS][BINAURAL_NTAPS_SBA]; -extern Word32 leftHRIRImag_HOA3_fx[BINAURAL_CONVBANDS][HOA3_CHANNELS][BINAURAL_NTAPS_SBA]; -extern Word32 rightHRIRReal_HOA3_fx[BINAURAL_CONVBANDS][HOA3_CHANNELS][BINAURAL_NTAPS_SBA]; -extern Word32 rightHRIRImag_HOA3_fx[BINAURAL_CONVBANDS][HOA3_CHANNELS][BINAURAL_NTAPS_SBA]; -extern Word32 leftHRIRReal_HOA2_fx[BINAURAL_CONVBANDS][HOA2_CHANNELS][BINAURAL_NTAPS_SBA]; -extern Word32 leftHRIRImag_HOA2_fx[BINAURAL_CONVBANDS][HOA2_CHANNELS][BINAURAL_NTAPS_SBA]; -extern Word32 rightHRIRReal_HOA2_fx[BINAURAL_CONVBANDS][HOA2_CHANNELS][BINAURAL_NTAPS_SBA]; -extern Word32 rightHRIRImag_HOA2_fx[BINAURAL_CONVBANDS][HOA2_CHANNELS][BINAURAL_NTAPS_SBA]; -extern Word32 leftHRIRReal_FOA_fx[BINAURAL_CONVBANDS][FOA_CHANNELS][BINAURAL_NTAPS_SBA]; -extern Word32 leftHRIRImag_FOA_fx[BINAURAL_CONVBANDS][FOA_CHANNELS][BINAURAL_NTAPS_SBA]; -extern Word32 rightHRIRReal_FOA_fx[BINAURAL_CONVBANDS][FOA_CHANNELS][BINAURAL_NTAPS_SBA]; -extern Word32 rightHRIRImag_FOA_fx[BINAURAL_CONVBANDS][FOA_CHANNELS][BINAURAL_NTAPS_SBA]; +extern Word32 leftHRIRReal_HOA3_fx[BINAURAL_CONVBANDS][HOA3_CHANNELS][BINAURAL_NTAPS_SBA]; /* Q29 */ +extern Word32 leftHRIRImag_HOA3_fx[BINAURAL_CONVBANDS][HOA3_CHANNELS][BINAURAL_NTAPS_SBA]; /* Q29 */ +extern Word32 rightHRIRReal_HOA3_fx[BINAURAL_CONVBANDS][HOA3_CHANNELS][BINAURAL_NTAPS_SBA]; /* Q29 */ +extern Word32 rightHRIRImag_HOA3_fx[BINAURAL_CONVBANDS][HOA3_CHANNELS][BINAURAL_NTAPS_SBA]; /* Q29 */ +extern Word32 leftHRIRReal_HOA2_fx[BINAURAL_CONVBANDS][HOA2_CHANNELS][BINAURAL_NTAPS_SBA]; /* Q29 */ +extern Word32 leftHRIRImag_HOA2_fx[BINAURAL_CONVBANDS][HOA2_CHANNELS][BINAURAL_NTAPS_SBA]; /* Q29 */ +extern Word32 rightHRIRReal_HOA2_fx[BINAURAL_CONVBANDS][HOA2_CHANNELS][BINAURAL_NTAPS_SBA]; /* Q29 */ +extern Word32 rightHRIRImag_HOA2_fx[BINAURAL_CONVBANDS][HOA2_CHANNELS][BINAURAL_NTAPS_SBA]; /* Q29 */ +extern Word32 leftHRIRReal_FOA_fx[BINAURAL_CONVBANDS][FOA_CHANNELS][BINAURAL_NTAPS_SBA]; /* Q29 */ +extern Word32 leftHRIRImag_FOA_fx[BINAURAL_CONVBANDS][FOA_CHANNELS][BINAURAL_NTAPS_SBA]; /* Q29 */ +extern Word32 rightHRIRReal_FOA_fx[BINAURAL_CONVBANDS][FOA_CHANNELS][BINAURAL_NTAPS_SBA]; /* Q29 */ +extern Word32 rightHRIRImag_FOA_fx[BINAURAL_CONVBANDS][FOA_CHANNELS][BINAURAL_NTAPS_SBA]; /* Q29 */ #endif #ifndef IVAS_FLOAT_FIXED extern float leftHRIRReal[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS]; @@ -75,10 +75,10 @@ extern float leftHRIRImag[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS]; extern float rightHRIRReal[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS]; extern float rightHRIRImag[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS]; #else -extern Word32 leftHRIRReal_fx[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS]; -extern Word32 leftHRIRImag_fx[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS]; -extern Word32 rightHRIRReal_fx[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS]; -extern Word32 rightHRIRImag_fx[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS]; +extern Word32 leftHRIRReal_fx[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS]; /* Q29 */ +extern Word32 leftHRIRImag_fx[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS]; /* Q29 */ +extern Word32 rightHRIRReal_fx[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS]; /* Q29 */ +extern Word32 rightHRIRImag_fx[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS]; /* Q29 */ #endif #ifndef IVAS_FLOAT_FIXED extern float FASTCONV_HOA3_latency_s; @@ -98,10 +98,10 @@ extern Word16 hrtfShCoeffsIm_fx[BINAURAL_CHANNELS][HRTF_SH_CHANNELS][HRTF_NUM_BI /* Binaural rendering data set based on BRIRs */ #ifdef IVAS_FLOAT_FIXED extern const Word32 FASTCONV_BRIR_latency_s_fx; -extern Word32 leftBRIRReal_fx[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS_MAX]; -extern Word32 leftBRIRImag_fx[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS_MAX]; -extern Word32 rightBRIRReal_fx[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS_MAX]; -extern Word32 rightBRIRImag_fx[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS_MAX]; +extern Word32 leftBRIRReal_fx[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS_MAX]; /* Q29 */ +extern Word32 leftBRIRImag_fx[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS_MAX]; /* Q29 */ +extern Word32 rightBRIRReal_fx[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS_MAX]; /* Q29 */ +extern Word32 rightBRIRImag_fx[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS_MAX]; /* Q29 */ #else extern float leftBRIRReal[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS_MAX]; extern float leftBRIRImag[BINAURAL_CONVBANDS][HRTF_LS_CHANNELS][BINAURAL_NTAPS_MAX]; @@ -112,8 +112,8 @@ extern const float FASTCONV_BRIR_latency_s; /* Reverberation parameters based on BRIRs for fastconv */ #ifdef IVAS_FLOAT_FIXED -extern Word32 fastconvReverberationTimes_fx[CLDFB_NO_CHANNELS_MAX]; -extern Word32 fastconvReverberationEneCorrections_fx[CLDFB_NO_CHANNELS_MAX]; +extern Word32 fastconvReverberationTimes_fx[CLDFB_NO_CHANNELS_MAX]; /* Q31 */ +extern Word32 fastconvReverberationEneCorrections_fx[CLDFB_NO_CHANNELS_MAX]; /* Q31 */ #else extern float fastconvReverberationTimes[CLDFB_NO_CHANNELS_MAX]; extern float fastconvReverberationEneCorrections[CLDFB_NO_CHANNELS_MAX]; -- GitLab From 398f6a52c39b1fc0767734d65aba270af7715d72 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Mon, 14 Oct 2024 12:33:51 +0530 Subject: [PATCH 2/2] Remove test code --- lib_dec/amr_wb_dec_fx.c | 1 - 1 file changed, 1 deletion(-) diff --git a/lib_dec/amr_wb_dec_fx.c b/lib_dec/amr_wb_dec_fx.c index bb1da6f82..201347eb9 100644 --- a/lib_dec/amr_wb_dec_fx.c +++ b/lib_dec/amr_wb_dec_fx.c @@ -1110,7 +1110,6 @@ ivas_error amr_wb_dec_fx( Scale_sig( hTcxLtpDec->tcxltp_mem_out, output_frame, sub( st_fx->Q_syn2, st_fx->Qprev_synth_buffer_fx ) ); tcx_ltp_post( st_fx, hTcxLtpDec, ACELP_CORE, output_frame, 0, synth_out_fx, NULL ); } - assert( 0 ); /* final output of synthesis signal */ syn_output_fx( st_fx->codec_mode, synth_out_fx, output_frame, output_sp, st_fx->Q_syn2 ); -- GitLab