From bf90ce95679e97d2f4b3476de4adb11d45855442 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Mon, 29 Apr 2024 16:43:27 +0530 Subject: [PATCH] SPAR MD functions clean up, integration --- lib_com/ivas_cnst.h | 7 +- lib_com/ivas_prot.h | 36 +- lib_com/ivas_prot_fx.h | 70 +- lib_com/ivas_spar_com.c | 1339 ++++++++++-- lib_com/ivas_spar_com_quant_util.c | 160 +- lib_com/ivas_stat_com.h | 3 + lib_dec/ivas_dirac_dec.c | 1 + lib_dec/ivas_init_dec.c | 30 +- lib_dec/ivas_ism_dec.c | 6 +- lib_dec/ivas_jbm_dec.c | 172 +- lib_dec/ivas_masa_dec.c | 12 +- lib_dec/ivas_mct_dec.c | 6 +- lib_dec/ivas_omasa_dec.c | 36 - lib_dec/ivas_osba_dec.c | 128 +- lib_dec/ivas_sba_dec.c | 848 +++++++- lib_dec/ivas_sba_dirac_stereo_dec_fx.c | 8 +- lib_dec/ivas_sba_rendering_internal.c | 4 +- lib_dec/ivas_spar_decoder.c | 874 ++++---- lib_dec/ivas_spar_md_dec.c | 1907 ++++++++++++------ lib_dec/ivas_stat_dec.h | 8 +- lib_rend/ivas_dirac_dec_binaural_functions.c | 46 +- lib_rend/ivas_sba_rendering.c | 3 +- 22 files changed, 4164 insertions(+), 1540 deletions(-) diff --git a/lib_com/ivas_cnst.h b/lib_com/ivas_cnst.h index 5f5d16e7c..f3bbf79d2 100644 --- a/lib_com/ivas_cnst.h +++ b/lib_com/ivas_cnst.h @@ -1046,14 +1046,15 @@ typedef enum /* Common SPAR metadata constants */ #define IVAS_ACTIVEW_DM_F_SCALE 0.5f -#define IVAS_ACTIVEW_DM_F_SCALE_FX ONE_IN_Q30 +#define IVAS_ACTIVEW_DM_F_SCALE_FX IVAS_ACTIVEW_DM_F_SCALE * ONE_IN_Q31 #define IVAS_ACTIVEW_DM_F_SCALE_DTX 0.25f -#define IVAS_ACTIVEW_DM_F_SCALE_DTX_FX ONE_IN_Q29 +#define IVAS_ACTIVEW_DM_F_SCALE_DTX_FX IVAS_ACTIVEW_DM_F_SCALE_DTX * ONE_IN_Q31 #define IVAS_ACTIVEW_DM_F_SCALE_VLBR 0.25f -#define IVAS_ACTIVEW_DM_F_SCALE_VLBR_FX ONE_IN_Q29 +#define IVAS_ACTIVEW_DM_F_SCALE_VLBR_FX IVAS_ACTIVEW_DM_F_SCALE_VLBR * ONE_IN_Q31 #define IVAS_SPAR_FOA_DFLT_FREQ_PER_CHAN 24000 #define IVAS_SPAR_DYN_ACTIVEW_THRESH (0.0039f) +#define IVAS_SPAR_DYN_ACTIVEW_THRESH_FX IVAS_SPAR_DYN_ACTIVEW_THRESH * ONE_IN_Q31 #define IVAS_SPAR_SIDE_CH_DYN_ACTIVEW_THRESH (32.0f) #define MAX_QUANT_STRATS 3 diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index ddaddc3e1..c3a997af0 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -5466,6 +5466,23 @@ void ivas_create_fullr_dmx_mat( ivas_spar_md_com_cfg *hMdCfg ); +#ifdef IVAS_FLOAT_FIXED +void ivas_create_fullr_dmx_mat_fx( + Word32 pred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + Word16 q_pred_coeffs_re, + Word32 dm_fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + Word16 q_dm_fv_re, + Word32 ***mixer_mat, + Word16 *q_mixer_mat, + const Word16 in_chans, + const Word16 start_band, + const Word16 end_band, + const Word16 active_w, + ivas_spar_md_com_cfg *hMdCfg +); +#endif // IVAS_FLOAT_FIXED + + void ivas_calc_c_p_coeffs( ivas_spar_md_t *pSparMd, float *pppCov_mat_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], @@ -5480,18 +5497,18 @@ void ivas_calc_c_p_coeffs( ); #ifdef IVAS_FLOAT_FIXED void ivas_get_spar_md_from_dirac_fx( - float azi_dirac[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES], - float ele_dirac[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES], - float diffuseness[IVAS_MAX_NUM_BANDS], + Word32 azi_dirac[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES], + Word32 ele_dirac[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES], + Word32 diffuseness[IVAS_MAX_NUM_BANDS], const int16_t n_ts, - float ***mixer_mat, + Word32 ***mixer_mat, ivas_spar_md_t *hSpar_md, ivas_spar_md_com_cfg *hSpar_md_cfg, const int16_t start_band, const int16_t end_band, const int16_t order, const int16_t dtx_vad, - float Wscale_d[IVAS_MAX_NUM_BANDS], + Word32 Wscale_d[IVAS_MAX_NUM_BANDS], const uint8_t useLowerRes, const int16_t active_w_vlbr, const int16_t dyn_active_w_flag @@ -5595,7 +5612,14 @@ void ivas_spar_to_dirac( const int16_t bw, /* i : band joining factor */ const int16_t dyn_active_w_flag /* i : dynamic active W flag */ ); - +void ivas_spar_to_dirac_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ + const int16_t dtx_vad, /* i : DTX frame flag */ + const int16_t num_bands_out, /* i : number of output bands */ + const int16_t bw, /* i : band joining factor */ + const int16_t dyn_active_w_flag /* i : dynamic active W flag */ +); void ivas_spar_update_md_hist( ivas_spar_md_dec_state_t *hMdDec /* i/o: SPAR MD decoder handle */ ); diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index bc8288f74..c5f92d81c 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -687,22 +687,26 @@ Word16 masa_sq_fx( ); void ivas_compute_spar_params_fx( - Word32 * pppCov_mat_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - Word32 dm_fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], - const int16_t i_ts, - float ***mixer_mat, - const int16_t start_band, - const int16_t end_band, - const int16_t dtx_vad, - const int16_t num_ch, - const int16_t bands_bw, - const int16_t active_w, - const int16_t active_w_vlbr, - ivas_spar_md_com_cfg * hSparCfg, - ivas_spar_md_t * hSparMd, - float *pWscale, - const int16_t from_dirac, - const int16_t dyn_active_w_flag + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word16 q_cov_real, + Word32 dm_fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + Word16 *q_dm_fv_re, + const Word16 i_ts, + Word32 ***mixer_mat_fx, + Word16 *q_mixer_mat, + const Word16 start_band, + const Word16 end_band, + const Word16 dtx_vad, + const Word16 num_ch, + const Word16 bands_bw, + const Word16 active_w, + const Word16 active_w_vlbr, + ivas_spar_md_com_cfg *hSparCfg, + ivas_spar_md_t *hSparMd, + Word32 *pWscale_fx, + Word16 *q_pWscale, + const Word16 from_dirac, + const Word16 dyn_active_w_flag ); ivas_error ivas_ism_metadata_dec_fx( @@ -1416,6 +1420,14 @@ void ivas_sba_dirac_stereo_dec_fx( const Word16 mcmasa /* i : McMASA flag */ ); +ivas_error ivas_osba_render_sf_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + const UWord16 nSamplesAsked, /* i : number of CLDFB slots requested */ + UWord16 *nSamplesRendered, /* o : number of CLDFB slots rendered */ + UWord16 *nSamplesAvailableNext, /* o : number of CLDFB slots still to render */ + Word32 *p_output[] /* o : rendered time signal */ +); + void ivas_hq_core_dec_fx( Decoder_State *st_fx, /* i/o: decoder state structure fx */ Word16 synth[], /* o : output synthesis */ @@ -1943,6 +1955,13 @@ ivas_error ivas_spar_dec_fx( Word16 *nb_bits_read /* o : number of MD bits read */ ); +void ivas_spar_md_dec_process_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + Decoder_State *st0, /* i/o: decoder state structure - for bitstream handling */ + const Word16 num_bands_out, /* i : number of output bands */ + const Word16 sba_order /* i : Ambisonic (SBA) order */ +); + ivas_error TDREND_Update_object_positions_fx( BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd, /* i/o: TD Renderer handle */ const Word16 num_src, /* i : number of sources to render */ @@ -2114,4 +2133,23 @@ ivas_error ivas_ism_metadata_dec_create_fx( const Word16 n_ISms, /* i : number of objects */ Word32 element_brate_tmp[] /* o : element bitrate per object */ ); +ivas_error ivas_sba_dec_reconfigure_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + uint16_t *nSamplesFlushed, /* o : number of samples flushed */ + int16_t *data /* o : output synthesis signal */ +); + +ivas_error ivas_spar_md_dec_matrix_open_fx( + ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ + const int16_t num_channels, /* i : number of internal channels */ + const int16_t num_md_sub_frames /* i : number of MD subframes */ +); +void ivas_spar_md_dec_matrix_close_fx( + ivas_spar_md_dec_state_t *hMdDecoder, /* i/o: SPAR MD decoder handle */ + const int16_t num_channels /* i : number of internal channels */ +); +ivas_error ivas_spar_dec_open_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + const int16_t spar_reconfig_flag /* i : SPAR reconfiguration flag */ +); #endif diff --git a/lib_com/ivas_spar_com.c b/lib_com/ivas_spar_com.c index 743a70635..d7ccff598 100644 --- a/lib_com/ivas_spar_com.c +++ b/lib_com/ivas_spar_com.c @@ -71,7 +71,9 @@ #define IVAS_LIN_ACTIVEW_QUAD_ACTIVEW_THRESH_Q29 ( 1610612736 ) #define IVAS_P_NORM_SCALING ( 1.0f ) +#define IVAS_P_NORM_SCALING_FX ( ONE_IN_Q31 ) // Q31 #define IVAS_P_NORM_SCALING_DTX ( 0.75f ) +#define IVAS_P_NORM_SCALING_DTX_FX ( 1610612736 ) // Q31 #define IVAS_MAT_DIM_3 ( 3 ) #define IVAS_MAT_DIM_2 ( 2 ) @@ -99,16 +101,21 @@ static void ivas_get_pred_coeffs_fx( const Word16 res_ind, Word16 *q_pred_coeffs, Word16 *q_dm_fv_re ); + static void ivas_reorder_array( float in_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS], const int16_t in_chans, const int16_t order[IVAS_SPAR_MAX_CH], float ***mixer_mat, const int16_t start_band, const int16_t end_band ); +static void ivas_reorder_array_fx(Word32 in_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS], const Word16 in_chans, const Word16 order[IVAS_SPAR_MAX_CH], Word32 ***mixer_mat, const Word16 start_band, const Word16 end_band); static void ivas_get_Wscaling_factor( float *pppCov_mat_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], float pred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], float ***mixer_mat, const int16_t start_band, const int16_t end_band, const int16_t dtx_vad, const int16_t num_ch, const int16_t *pNum_dmx, const int16_t bands_bw, const int16_t active_w, const int16_t active_w_vlbr, float *pWscale, const int16_t dyn_active_w_flag ); +static void ivas_get_Wscaling_factor_fx(Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], Word16 q_cov_real, Word32 pred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], Word16 q_pred_coeffs_re, Word32 ***mixer_mat, Word16 q_mixer_mat, const Word16 start_band, const Word16 end_band, const Word16 dtx_vad, const Word16 num_ch, const Word16 *pNum_dmx, const Word16 bands_bw, const Word16 active_w, const Word16 active_w_vlbr, Word32 *pWscale, Word16 *q_pWscale, const Word16 dyn_active_w_flag ); static void ivas_calc_post_pred_per_band( float *pppCov_mat_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], float ***mixer_mat, const int16_t num_ch, const int16_t band_idx, float postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH] ); +static void ivas_calc_post_pred_per_band_fx(Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], Word16 q_cov_real, Word32 ***mixer_mat, Word16 q_mixer_mat, const Word16 num_ch, const Word16 band_idx, Word32 postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], Word16 *q_postpred_cov_re); static int16_t ivas_is_mat_inv( float in_re[MAX_MAT_DIM][MAX_MAT_DIM], const int16_t dim ); +static Word16 ivas_is_mat_inv_fx(Word32 in_re[MAX_MAT_DIM][MAX_MAT_DIM], Word16 q_in_re, const Word16 dim); static void ivas_calc_mat_inv( float in_re[MAX_MAT_DIM][MAX_MAT_DIM], const int16_t dim, float out_re[MAX_MAT_DIM][MAX_MAT_DIM] ); - +static void ivas_calc_mat_inv_fx(Word32 in_re[MAX_MAT_DIM][MAX_MAT_DIM], Word16 q_in_re, const Word16 dim, Word32 out_re[MAX_MAT_DIM][MAX_MAT_DIM], Word16 *q_out_re); /*-----------------------------------------------------------------------------------------* * Function ivas_get_bw_idx_from_sample_rate() @@ -1020,6 +1027,120 @@ static void ivas_get_Wscaling_factor( } +#ifdef IVAS_FLOAT_FIXED + +static void ivas_get_Wscaling_factor_fx( + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word16 q_cov_real, + Word32 pred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + Word16 q_pred_coeffs_re, + Word32 ***mixer_mat, + Word16 q_mixer_mat, + const Word16 start_band, + const Word16 end_band, + const Word16 dtx_vad, + const Word16 num_ch, + const Word16 *pNum_dmx, + const Word16 bands_bw, + const Word16 active_w, + const Word16 active_w_vlbr, + Word32 *pWscale, + Word16 *q_pWscale, + const Word16 dyn_active_w_flag ) +{ + Word16 b, ch, q_tmp, q_postpred_cov_re; + Word32 dm_f_local, abs_val; + Word32 postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; + + q_postpred_cov_re = 0; move16(); + + FOR ( ch = 0; ch < IVAS_SPAR_MAX_CH; ch++ ) + { + set32_fx( postpred_cov_re[ch], 0, IVAS_SPAR_MAX_CH ); + } + + IF ( EQ_16(dtx_vad, 0) ) + { + dm_f_local = IVAS_ACTIVEW_DM_F_SCALE_DTX_FX; // Q31 + move32(); + } + ELSE IF( NE_16(active_w_vlbr, 0) ) + { + dm_f_local = IVAS_ACTIVEW_DM_F_SCALE_VLBR_FX; // Q31 + move32(); + } + ELSE + { + dm_f_local = IVAS_ACTIVEW_DM_F_SCALE_FX; // Q31 + move32(); + } + + FOR ( b = start_band; b < end_band; b++ ) + { + pWscale[b] = 1; + move32(); + + test(); + IF ( EQ_16( active_w, 1 ) && EQ_16( dyn_active_w_flag, 0 ) ) + { + Word16 guard_bits, q_Gw_sq, q_g_sq, q_min, tmp_exp; + Word32 Gw_sq, g_sq, tmp; + + g_sq = 0; + move32(); + + IF ( NE_16(num_ch, pNum_dmx[i_mult( b, bands_bw)]) ) + { + ivas_calc_post_pred_per_band_fx( cov_real, q_cov_real, mixer_mat, q_mixer_mat, num_ch, b, postpred_cov_re, &q_postpred_cov_re); + } + + Gw_sq = BASOP_Util_Divide3232_Scale(cov_real[0][0][b], L_max( postpred_cov_re[0][0], IVAS_FIX_EPS ), &tmp_exp); + q_Gw_sq = add(sub(15, tmp_exp), sub(q_cov_real, q_postpred_cov_re)); + + guard_bits = find_guarded_bits_fx(num_ch); + + FOR ( ch = 0; ch < num_ch - 1; ch++ ) + { + abs_val = L_shr(Mpy_32_32(pred_coeffs_re[ch][b], pred_coeffs_re[ch][b]), guard_bits); + g_sq = L_add(g_sq, abs_val); + } + q_g_sq = sub(add(q_pred_coeffs_re, q_pred_coeffs_re), add(31, guard_bits)); + + tmp_exp = sub(31, q_Gw_sq); + Gw_sq = Sqrt32(Gw_sq, &tmp_exp); + q_Gw_sq = sub(31, tmp_exp); + + tmp = Mpy_32_32( ONE_IN_Q31 /*4 in Q28*/, Mpy_32_32(dm_f_local, g_sq) ); + q_tmp = sub(q_g_sq, 3); + + q_min = s_min(q_Gw_sq, q_tmp); + Gw_sq = L_shr(Gw_sq, sub(q_Gw_sq, q_min)); + q_Gw_sq = q_min; move16(); + tmp = L_shr(tmp, sub(q_tmp, q_min)); + + tmp = L_add(Gw_sq, tmp); + + tmp_exp = sub(31, q_min); + tmp = Sqrt32(tmp, &tmp_exp); + q_tmp = sub(31, tmp_exp); + + q_min = s_min(q_Gw_sq, q_tmp); + Gw_sq = L_shr(Gw_sq, sub(q_Gw_sq, q_min)); + q_Gw_sq = q_min; move16(); + tmp = L_shr(tmp, sub(q_tmp, q_min)); + + pWscale[b] = Mpy_32_32(L_add(Gw_sq, tmp), ONE_IN_Q30 /* 0.5 in Q31*/); + q_pWscale[b] = q_Gw_sq; + move16(); + } + } + + return; +} + +#endif + + /*-----------------------------------------------------------------------------------------* * Function ivas_create_fullr_dmx_mat() * @@ -1131,6 +1252,134 @@ void ivas_create_fullr_dmx_mat( return; } +#ifdef IVAS_FLOAT_FIXED + +void ivas_create_fullr_dmx_mat_fx( + Word32 pred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + Word16 q_pred_coeffs_re, + Word32 dm_fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + Word16 q_dm_fv_re, + Word32 ***mixer_mat, + Word16 *q_mixer_mat, + const Word16 in_chans, + const Word16 start_band, + const Word16 end_band, + const Word16 active_w, + ivas_spar_md_com_cfg *hMdCfg) +{ + Word16 i, j, k, b; + const Word16 *order; + Word32 max_val_tmp_p2; + Word32 tmp_p1_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS]; + Word32 tmp_p2_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS]; + Word32 down_mix_mat1_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS]; + Word16 remix_unmix_order; + Word16 nbands; + + max_val_tmp_p2 = 0; move32(); + + nbands = sub(end_band, start_band); + remix_unmix_order = hMdCfg->remix_unmix_order; move16(); + + order = remix_order_set[remix_unmix_order]; move16(); + + FOR (i = 0; i < in_chans; i++) + { + FOR (j = 0; j < in_chans; j++) + { + set32_fx(&tmp_p1_re[i][j][start_band], 0, nbands); + set32_fx(&tmp_p2_re[i][j][start_band], 0, nbands); + set32_fx(&down_mix_mat1_re[i][j][start_band], 0, nbands); + } + } + + FOR (j = 0; j < in_chans; j++) + { + FOR (b = start_band; b < end_band; b++) + { + tmp_p2_re[j][j][b] = L_shl(1, q_pred_coeffs_re); move32(); + max_val_tmp_p2 = L_max(max_val_tmp_p2, L_abs(tmp_p2_re[j][j][b])); + } + } + + FOR (j = 1; j < in_chans; j++) + { + FOR (b = start_band; b < end_band; b++) + { + tmp_p2_re[j][0][b] = -pred_coeffs_re[j - 1][b]; move32(); + max_val_tmp_p2 = L_max(max_val_tmp_p2, L_abs(tmp_p2_re[j][0][b])); + } + } + + IF (EQ_16(active_w, 1)) + { + Word16 guard_bits; + Word32 max_val, tmp_re; + + max_val = 0; move32(); + + FOR (j = 0; j < in_chans; j++) + { + FOR (b = start_band; b < end_band; b++) + { + tmp_p1_re[j][j][b] = L_shl(1, q_dm_fv_re); move32(); + max_val = L_max(max_val, L_abs(tmp_p1_re[j][j][b])); + } + } + + FOR (j = 1; j < in_chans; j++) + { + FOR (b = start_band; b < end_band; b++) + { + tmp_p1_re[0][j][b] = dm_fv_re[j - 1][b]; move32(); + max_val = L_max(max_val, L_abs(tmp_p1_re[0][j][b])); + } + } + + guard_bits = add(norm_l(max_val), norm_l(max_val_tmp_p2)); + guard_bits = s_max(sub(find_guarded_bits_fx(sub(end_band, start_band)), guard_bits), 0); + /* 4x4 mult */ + FOR (i = 0; i < in_chans; i++) + { + FOR (j = 0; j < in_chans; j++) + { + FOR (k = 0; k < in_chans; k++) + { + FOR (b = start_band; b < end_band; b++) + { + tmp_re = L_shr(Mpy_32_32(tmp_p2_re[i][k][b], tmp_p1_re[k][j][b]), guard_bits); + down_mix_mat1_re[i][j][b] = L_add(down_mix_mat1_re[i][j][b], tmp_re); move32(); + } + } + } + } + *q_mixer_mat = sub(add(q_dm_fv_re, q_pred_coeffs_re), add(31, guard_bits)); + } + ELSE + { + FOR (j = 0; j < in_chans; j++) + { + FOR (k = 0; k < in_chans; k++) + { + FOR (b = start_band; b < end_band; b++) + { + down_mix_mat1_re[j][k][b] = tmp_p2_re[j][k][b]; move32(); + } + } + } + *q_mixer_mat = q_pred_coeffs_re; + } + + IF (NE_16(remix_unmix_order, 3)) + { + ivas_reorder_array_fx(down_mix_mat1_re, in_chans, order, mixer_mat, start_band, end_band); + } + + return; +} + +#endif // IVAS_FLOAT_FIXED + /*-----------------------------------------------------------------------------------------* * Function ivas_reorder_array() @@ -1164,6 +1413,34 @@ static void ivas_reorder_array( return; } +#ifdef IVAS_FLOAT_FIXED +static void ivas_reorder_array_fx( + Word32 in_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS], + const Word16 in_chans, + const Word16 order[IVAS_SPAR_MAX_CH], + Word32 ***mixer_mat, + const Word16 start_band, + const Word16 end_band ) +{ + Word16 i, j, b, idx; + + FOR ( i = 0; i < in_chans; i++ ) + { + idx = order[i]; move16(); + + FOR ( j = 0; j < in_chans; j++ ) + { + FOR ( b = start_band; b < end_band; b++ ) + { + mixer_mat[i][j][b] = in_re[idx][j][b]; + move32(); + } + } + } + + return; +} +#endif /*-----------------------------------------------------------------------------------------* * Function ivas_calc_post_pred_per_band() @@ -1235,6 +1512,129 @@ static void ivas_calc_post_pred_per_band( } +#ifdef IVAS_FLOAT_FIXED + +static void ivas_calc_post_pred_per_band_fx( + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word16 q_cov_real, + Word32 ***mixer_mat, + Word16 q_mixer_mat, + const Word16 num_ch, + const Word16 band_idx, + Word32 postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word16 *q_postpred_cov_re ) +{ + Word16 i, j, k, guard_bits, tmp, q_temp_mat; + Word32 dmx_mat_conj[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; + Word32 temp_mat[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; + Word32 max_val; + Word64 tmp_re; + + max_val = 1; + move32(); + FOR ( i = 0; i < num_ch; i++ ) + { + FOR ( j = 0; j < num_ch; j++ ) + { + dmx_mat_conj[i][j] = mixer_mat[j][i][band_idx]; + move32(); + max_val = L_max(max_val, L_abs(dmx_mat_conj[i][j])); + } + } + + guard_bits = find_guarded_bits_fx(num_ch); + + tmp = norm_l(max_val); + IF(LT_16(tmp, guard_bits)) + { + guard_bits = sub(guard_bits, tmp); + } + ELSE + { + guard_bits = 0; + move16(); + } + + FOR ( i = 0; i < num_ch; i++ ) + { + set32_fx( temp_mat[i], 0, num_ch ); + set32_fx( postpred_cov_re[i], 0, num_ch ); + } + + max_val = 1; + move32(); + /* num_ch x num_ch mult */ + FOR ( i = 0; i < num_ch; i++ ) + { + FOR ( j = 0; j < num_ch; j++ ) + { + tmp_re = 0; + FOR ( k = 0; k < num_ch; k++ ) + { + tmp_re = W_add(tmp_re, W_shr(W_mult0_32_32(cov_real[i][k][band_idx], dmx_mat_conj[k][j]), guard_bits)); + } + IF(LT_64(W_abs(tmp_re), L_shl(IVAS_FIX_EPS, guard_bits))) + { + tmp_re = 0; + } + temp_mat[i][j] = W_extract_l(W_shr(tmp_re, q_mixer_mat)); // Q = (q_cov_real - guard_bits) + move32(); + max_val = L_max(max_val, L_abs(temp_mat[i][j])); + } + } + q_temp_mat = sub(q_cov_real, guard_bits); + + guard_bits = find_guarded_bits_fx(num_ch); + + tmp = norm_l(max_val); + IF(LT_16(tmp, guard_bits)) + { + guard_bits = sub(guard_bits, tmp); + } + ELSE + { + guard_bits = 0; + move16(); + } + + /* num_ch x num_ch mult */ + FOR ( i = 0; i < num_ch; i++ ) + { + FOR ( j = i; j < num_ch; j++ ) + { + tmp_re = 0; move64(); + FOR ( k = 0; k < num_ch; k++ ) + { + tmp_re = W_add(tmp_re, W_shr(W_mult0_32_32(mixer_mat[i][k][band_idx], temp_mat[k][j]), guard_bits)); + } + + IF(LT_64(W_abs(tmp_re), L_shl(IVAS_FIX_EPS, guard_bits))) + { + tmp_re = 0; move64(); + } + + postpred_cov_re[i][j] = W_extract_l(W_shr(tmp_re, q_mixer_mat)); + move32(); + } + } + + *q_postpred_cov_re = sub(q_temp_mat, guard_bits); + + FOR ( i = 0; i < num_ch; i++ ) + { + FOR ( j = 0; j < i; j++ ) + { + postpred_cov_re[i][j] = postpred_cov_re[j][i]; + move32(); + } + } + + return; +} + +#endif + + /*-----------------------------------------------------------------------------------------* * Function ivas_calc_p_coeffs_per_band() * @@ -1421,13 +1821,233 @@ static void ivas_calc_p_coeffs_per_band( if ( i == j ) { pSparMd->band_coeffs[b_ts_idx].P_re[j - num_dmx] = cov_uu_re[i - num_dmx][j - num_dmx]; +#ifdef IVAS_FLOAT_FIXED + pSparMd->band_coeffs[b_ts_idx].P_re_fx[j - num_dmx] =(Word32) (pSparMd->band_coeffs[b_ts_idx].P_re[j - num_dmx] *ONE_IN_Q22); +#endif + } + } + } + } + + return; +} + +#ifdef IVAS_FLOAT_FIXED + +static void ivas_calc_p_coeffs_per_band_fx( + ivas_spar_md_t *pSparMd, + const Word16 i_ts, + Word32 postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word16 q_postpred_cov_re, + const Word16 num_ch, + const Word16 dtx_vad, + const Word16 num_dmx, + const Word16 band_idx ) +{ + Word16 i, j, k; + Word16 m; + Word32 factor; + Word32 recon_uu_re[IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS][IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS]; + Word32 trace; + Word32 p_norm_scaling; + Word16 q_cov_uu_re; + Word32 cov_dd_re[IVAS_SPAR_MAX_CH - 1][IVAS_SPAR_MAX_CH - 1]; + Word32 cov_uu_re[IVAS_SPAR_MAX_CH - 1][IVAS_SPAR_MAX_CH - 1]; + Word16 b_ts_idx; + + b_ts_idx = add(band_idx, imult1616(i_ts, IVAS_MAX_NUM_BANDS)); + + IF( NE_16( num_dmx, num_ch ) ) + { + set32_fx( pSparMd->band_coeffs[b_ts_idx].P_re_fx, 0, IVAS_SPAR_MAX_CH - 1 ); + pSparMd->band_coeffs[b_ts_idx].q_P_re_fx = 0;move16(); + FOR ( i = 0; i < IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS; i++ ) + { + set32_fx( recon_uu_re[i], 0, IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS ); + } + + FOR ( i = num_dmx; i < num_ch; i++ ) + { + FOR ( j = num_dmx; j < num_ch; j++ ) + { + cov_uu_re[i - num_dmx][j - num_dmx] = postpred_cov_re[i][j]; + move32(); + } + } + q_cov_uu_re = q_postpred_cov_re; + move16(); + + IF ( dtx_vad == 1 ) + { + FOR ( i = 1; i < num_dmx; i++ ) + { + FOR ( j = 1; j < num_dmx; j++ ) + { + cov_dd_re[i - 1][j - 1] = postpred_cov_re[i][j]; + move32(); + } + } + + Word16 q_C_re = pSparMd->band_coeffs[b_ts_idx].q_C_re_fx; move16(); + + IF ( EQ_16( num_dmx, 2 ) ) + { + Word32 re1, re2; + + re1 = W_extract_l(W_shr( W_mult0_32_32(pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], cov_dd_re[0][0]), q_C_re)); + re2 = W_extract_l(W_shr(W_mult0_32_32(pSparMd->band_coeffs[b_ts_idx].C_re_fx[1][0], cov_dd_re[0][0]), q_C_re)); + + recon_uu_re[0][0] = W_extract_l(W_shr(W_mult0_32_32(pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], re1), q_C_re)); + recon_uu_re[0][1] = W_extract_l(W_shr(W_mult0_32_32(pSparMd->band_coeffs[b_ts_idx].C_re_fx[1][0], re1), q_C_re)); + recon_uu_re[1][0] = W_extract_l(W_shr(W_mult0_32_32(pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], re2), q_C_re)); + recon_uu_re[1][1] = W_extract_l(W_shr(W_mult0_32_32(pSparMd->band_coeffs[b_ts_idx].C_re_fx[1][0], re2), q_C_re)); + + FOR ( i = 0; i < 2; i++ ) + { + FOR ( j = 0; j < 2; j++ ) + { + cov_uu_re[i][j] = L_sub(cov_uu_re[i][j], recon_uu_re[i][j]); + move32(); + } + } + } + ELSE IF ( EQ_16( num_dmx, 3 ) ) + { + Word32 re1[2], re2; + set32_fx( re1, 0, 2 ); + + FOR ( j = 0; j < 2; j++ ) + { + FOR ( k = 0; k < 2; k++ ) + { + Word32 re; + re = W_extract_l(W_shr(W_mult0_32_32(pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][k], cov_dd_re[k][j]), q_C_re)); + re1[j] = L_add(re1[j], re); + move32(); + } + } + + re2 = W_extract_l(W_shr(W_mult0_32_32(pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], re1[0]), q_C_re)); + recon_uu_re[0][0] = re2; move32(); + re2 = W_extract_l(W_shr(W_mult0_32_32(pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][1], re1[1]), q_C_re)); + recon_uu_re[0][0] = L_add(recon_uu_re[0][0], re2); + + cov_uu_re[0][0] = L_sub(cov_uu_re[0][0], recon_uu_re[0][0]); + } + ELSE IF ( EQ_16( num_dmx, 4 ) ) + { + /* Step 1: Multiply C * cov_dd * C' */ + Word32 re1[3], re; + + FOR ( i = 0; i < num_ch - num_dmx; i++ ) + { + set32_fx( re1, 0, 3 ); + FOR ( m = 0; m < num_dmx - 1; m++ ) + { + FOR ( k = 0; k < num_dmx - 1; k++ ) + { + re = W_extract_l(W_shr(W_mult0_32_32(pSparMd->band_coeffs[b_ts_idx].C_re_fx[i][k], cov_dd_re[k][m]), q_C_re)); + re1[m] = L_add(re1[m], re); + move32(); + } + } + FOR ( j = 0; j < num_ch - num_dmx; j++ ) + { + FOR ( m = 0; m < num_dmx - 1; m++ ) + { + re = W_extract_l(W_shr(W_mult0_32_32(pSparMd->band_coeffs[b_ts_idx].C_re_fx[j][m], re1[m]), q_C_re)); + recon_uu_re[i][j] = L_add(recon_uu_re[i][j], re); + move32(); + } + } + } + + /* Step 2: cov_uu - recon_uu */ + FOR ( i = 0; i < num_ch - num_dmx; i++ ) + { + FOR ( j = 0; j < num_ch - num_dmx; j++ ) + { + cov_uu_re[i][j] = L_sub(cov_uu_re[i][j], recon_uu_re[i][j]); + move32(); + } + } + } + } + + p_norm_scaling = IVAS_P_NORM_SCALING_FX; + move32(); + + test(); + IF ( EQ_16( dtx_vad, 0 ) && EQ_16( num_dmx, 1 ) ) + { + p_norm_scaling = IVAS_P_NORM_SCALING_DTX_FX; + move32(); + } + + trace = 0; + move32(); + + FOR ( i = num_dmx; i < num_ch; i++ ) + { + trace = L_add(trace, L_abs(cov_uu_re[i - num_dmx][i - num_dmx])); + } + + factor = L_max( IVAS_FIX_EPS, postpred_cov_re[0][0] ); + factor = L_max( factor, Mpy_32_32( p_norm_scaling, trace ) ); + + Word16 factor_exp = 0; move16(); + factor = BASOP_Util_Divide3232_Scale(L_shl(1, q_postpred_cov_re), factor, &factor_exp); + factor = L_shl_sat(factor, factor_exp); + + /* normalise Hermitian (except for rounding) cov_uu */ + FOR ( i = num_dmx; i < num_ch; i++ ) + { + FOR ( j = num_dmx; j < num_ch; j++ ) + { + IF ( EQ_16(i, j) ) + { + /* force diagonal to be real */ + cov_uu_re[i - num_dmx][j - num_dmx] = W_extract_l(W_shr(W_mult0_32_32(cov_uu_re[i - num_dmx][j - num_dmx], factor), 15)); + move32(); + } + ELSE + { + /* set off-diag elements to zero */ + cov_uu_re[i - num_dmx][j - num_dmx] = 0; + move32(); } } } + + Word16 cov_uu_re_exp; + /* take sqrt of max of diags and zero */ + FOR ( i = num_dmx; i < num_ch; i++ ) + { + cov_uu_re_exp = sub(31, q_cov_uu_re); + cov_uu_re[i - num_dmx][i - num_dmx] = Sqrt32( L_max( 0, cov_uu_re[i - num_dmx][i - num_dmx] ), &cov_uu_re_exp ); + cov_uu_re[i - num_dmx][i - num_dmx] = L_shl(cov_uu_re[i - num_dmx][i - num_dmx], sub( q_cov_uu_re, sub(31, cov_uu_re_exp))); + move32(); move32(); + } + + /* save into MD struct */ + FOR ( i = num_dmx; i < num_ch; i++ ) + { + FOR ( j = num_dmx; j < num_ch; j++ ) + { + IF ( EQ_16(i, j) ) + { + pSparMd->band_coeffs[b_ts_idx].P_re_fx[j - num_dmx] = cov_uu_re[i - num_dmx][j - num_dmx]; + move32(); + } + } + } + pSparMd->band_coeffs[b_ts_idx].q_P_re_fx = q_cov_uu_re; + move16(); } return; } +#endif // IVAS_FLOAT_FIXED /*-----------------------------------------------------------------------------------------* @@ -1525,6 +2145,130 @@ static void ivas_calc_c_coeffs_per_band( return; } +#ifdef IVAS_FLOAT_FIXED + +static void ivas_calc_c_coeffs_per_band_fx( + ivas_spar_md_t *pSparMd, + const Word16 i_ts, + Word32 postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word16 q_post_pred_cov_re, + const Word16 num_ch, + const Word16 num_dmx, + const Word16 band_idx, + const Word16 dtx_vad) +{ + Word16 i, j, k; + + /* worst case for cov_ud is actually 12 x 3 */ + Word32 cov_ud_re[IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS][IVAS_SPAR_MAX_DMX_CHS - 1]; + Word32 cov_dd_re[FOA_CHANNELS - 1][FOA_CHANNELS - 1]; + Word32 cov_dd_re_inv[FOA_CHANNELS - 1][FOA_CHANNELS - 1]; + Word16 q_cov_dd_re_inv; + Word32 trace_cov_dd_re; + Word32 abs_trace; + Word16 b_ts_idx; + + b_ts_idx = add(band_idx, imult1616(i_ts, IVAS_MAX_NUM_BANDS)); + + IF (EQ_16(dtx_vad, 0)) + { + set32_fx(&pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], 0, (IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS) * (IVAS_SPAR_MAX_DMX_CHS - 1)); + pSparMd->band_coeffs[b_ts_idx].q_C_re_fx = 0; move16(); + return; + } + + FOR (i = num_dmx; i < num_ch; i++) + { + FOR (j = 1; j < num_dmx; j++) + { + cov_ud_re[i - num_dmx][j - 1] = postpred_cov_re[i][j]; + move32(); + } + } + + FOR (i = 1; i < num_dmx; i++) + { + FOR (j = 1; j < num_dmx; j++) + { + cov_dd_re[i - 1][j - 1] = postpred_cov_re[i][j]; + } + } + + trace_cov_dd_re = 0; + move32(); + + FOR (i = 0; i < num_dmx - 1; i++) + { + trace_cov_dd_re = L_add(trace_cov_dd_re, cov_dd_re[i][i]); + } + trace_cov_dd_re = Mpy_32_32(trace_cov_dd_re, 10737418 /* 0.005f in Q31*/); + + abs_trace = L_abs(trace_cov_dd_re); + + IF (LE_32( abs_trace , IVAS_FIX_EPS)) + { + /* protection from cases when variance of residual channels is very small */ + set32_fx(&pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], 0, (IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS) * (IVAS_SPAR_MAX_DMX_CHS - 1)); + pSparMd->band_coeffs[b_ts_idx].q_C_re_fx = 0; move16(); + } + ELSE + { + FOR (i = 0; i < num_dmx - 1; i++) + { + cov_dd_re[i][i] = L_add(trace_cov_dd_re, cov_dd_re[i][i]); + move32(); + } + test(); + IF (EQ_16( ivas_is_mat_inv_fx(cov_dd_re, q_post_pred_cov_re, num_dmx - 1), 1) && LT_16(num_dmx, FOA_CHANNELS)) + { + set32_fx(&pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], 0, (IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS) * (IVAS_SPAR_MAX_DMX_CHS - 1)); + pSparMd->band_coeffs[b_ts_idx].q_C_re_fx = 0; move16(); + } + ELSE + { + ivas_calc_mat_inv_fx(cov_dd_re, q_post_pred_cov_re, num_dmx - 1, cov_dd_re_inv, &q_cov_dd_re_inv); + + Word16 tmp; + Word64 max_val = 1; move64(); + Word64 C_re_fx[IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS][IVAS_SPAR_MAX_DMX_CHS - 1]; + + FOR (i = 0; i < num_ch - num_dmx; i++) + { + FOR (j = 0; j < num_dmx - 1; j++) + { + C_re_fx[i][j] = 0; + move64(); + FOR (k = 0; k < num_dmx - 1; k++) + { + C_re_fx[i][j] = W_add_nosat(C_re_fx[i][j], W_mult0_32_32(cov_ud_re[i][k], cov_dd_re_inv[k][j])); + move64(); + } + IF(LT_64(max_val, W_abs(C_re_fx[i][j]))) + { + max_val = W_abs(C_re_fx[i][j]); + } + } + } + + tmp = s_max(sub(32, W_norm(max_val)), 0); + + FOR(i = 0; i < num_ch - num_dmx; i++) + { + FOR(j = 0; j < num_dmx - 1; j++) + { + pSparMd->band_coeffs[b_ts_idx].C_re_fx[i][j] = W_extract_l(W_shr(C_re_fx[i][j], tmp)); + move32(); + } + } + pSparMd->band_coeffs[b_ts_idx].q_C_re_fx = sub(add(q_cov_dd_re_inv, q_post_pred_cov_re), tmp); + } + } + + return; +} + +#endif // IVAS_FLOAT_FIXED + /*-----------------------------------------------------------------------------------------* * Function ivas_calc_c_p_coeffs() @@ -1563,6 +2307,9 @@ void ivas_calc_c_p_coeffs( for ( j = 0; j < num_dmx - 1; j++ ) { pSparMd->band_coeffs[band_idx + i_ts * IVAS_MAX_NUM_BANDS].C_re[i][j] = 0.0f; +#ifdef IVAS_FLOAT_FIXED + pSparMd->band_coeffs[band_idx + i_ts * IVAS_MAX_NUM_BANDS].C_re_fx[i][j] = 0; +#endif } } } @@ -1576,14 +2323,79 @@ void ivas_calc_c_p_coeffs( for ( i = num_dmx; i < num_ch; i++ ) { pSparMd->band_coeffs[band_idx + i_ts * IVAS_MAX_NUM_BANDS].P_re[i - num_dmx] = 0; +#ifdef IVAS_FLOAT_FIXED + pSparMd->band_coeffs[band_idx + i_ts * IVAS_MAX_NUM_BANDS].P_re_fx[i - num_dmx] = 0; +#endif + } + } + } + + return; +} + +#ifdef IVAS_FLOAT_FIXED + +void ivas_calc_c_p_coeffs_fx( + ivas_spar_md_t *pSparMd, + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word16 q_cov_real, + const Word16 i_ts, + Word32 ***mixer_mat, + Word16 q_mixer_mat, + const Word16 num_ch, + const Word16 num_dmx, + const Word16 band_idx, + const Word16 dtx_vad, + const Word16 compute_p_flag, + const Word16 dyn_active_w_flag ) +{ + Word16 i, j, q_postpred_cov_re; + Word32 postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; + + IF ( NE_16( num_dmx, num_ch )) + { + ivas_calc_post_pred_per_band_fx( cov_real, q_cov_real, mixer_mat, q_mixer_mat, num_ch, band_idx, postpred_cov_re, &q_postpred_cov_re ); + + IF ( NE_16(num_dmx, 1 )) + { + ivas_calc_c_coeffs_per_band_fx( pSparMd, i_ts, postpred_cov_re, q_postpred_cov_re, num_ch, num_dmx, band_idx, dtx_vad ); + } + + IF ( dyn_active_w_flag ) + { + FOR ( i = 0; i < num_ch - num_dmx; i++ ) + { + FOR ( j = 0; j < num_dmx - 1; j++ ) + { + pSparMd->band_coeffs[band_idx + i_ts * IVAS_MAX_NUM_BANDS].C_re_fx[i][j] = 0; + move32(); + } + } + pSparMd->band_coeffs[band_idx + i_ts * IVAS_MAX_NUM_BANDS].q_C_re_fx = 0; + move16(); + } + IF ( EQ_16( compute_p_flag, 1 ) ) + { + ivas_calc_p_coeffs_per_band_fx( pSparMd, i_ts, postpred_cov_re, q_postpred_cov_re, num_ch, dtx_vad, num_dmx, band_idx ); + } + + IF ( dyn_active_w_flag ) + { + FOR ( i = num_dmx; i < num_ch; i++ ) + { pSparMd->band_coeffs[band_idx + i_ts * IVAS_MAX_NUM_BANDS].P_re_fx[i - num_dmx] = 0; + move32(); } + pSparMd->band_coeffs[band_idx + i_ts * IVAS_MAX_NUM_BANDS].q_P_re_fx = 0; + move16(); } } return; } +#endif // IVAS_FLOAT_FIXED + static void ivas_calc_mat_det( double in_re[MAX_MAT_DIM][MAX_MAT_DIM], @@ -1636,6 +2448,71 @@ static void ivas_calc_mat_det( return; } +#ifdef IVAS_FLOAT_FIXED + +static void ivas_calc_mat_det_fx( + Word32 in_re[MAX_MAT_DIM][MAX_MAT_DIM], + Word16 q_in_re, + const Word16 dim, + Word64 *det_re, + Word16 *q_det_re +) +{ + IF ( EQ_16( dim, IVAS_MAT_DIM_3)) + { + Word64 re1, re2, re; + re1 = W_mult0_32_32(in_re[1][1], in_re[2][2]); + re2 = W_mult0_32_32(in_re[1][2], in_re[2][1]); + re = W_sub_nosat(re1, re2); + + re1 = W_mult0_32_32(in_re[0][0], W_extract_h(re)); + + *det_re = re1; + move64(); + + re1 = W_mult0_32_32(in_re[1][0], in_re[2][2]); + re2 = W_mult0_32_32(in_re[1][2], in_re[2][0]); + re = W_sub_nosat(re1, re2); + + re1 = W_mult0_32_32(in_re[0][1], W_extract_h(re)); + + *det_re = W_sub_nosat(*det_re, re1); + + re1 = W_mult0_32_32(in_re[1][0], in_re[2][1]); + re2 = W_mult0_32_32(in_re[1][1], in_re[2][0]); + re = W_sub_nosat(re1, re2); + + re1 = W_mult0_32_32(in_re[0][2], W_extract_h(re)); + + *det_re = W_add_nosat(*det_re, re1); + + *q_det_re = add(q_in_re, sub(add(q_in_re, q_in_re), 32)); + } + ELSE IF(EQ_16(dim, IVAS_MAT_DIM_2)) + { + Word64 re1, re2; + re1 = W_mult0_32_32(in_re[0][0], in_re[1][1]); + re2 = W_mult0_32_32(in_re[0][1], in_re[1][0]); + *det_re = W_sub_nosat(re1, re2); + *q_det_re = add(q_in_re, q_in_re); + } + ELSE IF( EQ_16( dim, IVAS_MAT_DIM_1)) + { + *det_re = in_re[0][0]; + move32(); + *q_det_re = q_in_re; + move16(); + } + ELSE + { + assert(!"matrix dimention not supported!"); + } + + return; +} + +#endif // IVAS_FLOAT_FIXED + /*-----------------------------------------------------------------------------------------* * Function ivas_get_mat_cofactor() @@ -1673,6 +2550,44 @@ static void ivas_get_mat_cofactor( } +#ifdef IVAS_FLOAT_FIXED + +static void ivas_get_mat_cofactor_fx( + Word32 in_re[MAX_MAT_DIM][MAX_MAT_DIM], + Word32 out_re[MAX_MAT_DIM][MAX_MAT_DIM], + const Word16 row, + const Word16 col ) +{ + Word16 i, j; + Word16 r = 0, c = 0; + move16(); move16(); + + FOR ( i = 0; i < MAX_MAT_DIM; i++ ) + { + FOR ( j = 0; j < MAX_MAT_DIM; j++ ) + { + test(); + IF ( NE_16(i, row) && NE_16(j, col) ) + { + out_re[r][c] = in_re[i][j]; + move64(); + c = add(c, 1); + } + } + IF ( EQ_16(c, 2 )) + { + r = add(r, 1); + c = 0; + move16(); + } + } + + return; +} + +#endif + + /*-----------------------------------------------------------------------------------------* * Function ivas_calc_mat_inv() * @@ -1772,6 +2687,118 @@ static void ivas_calc_mat_inv( return; } +#ifdef IVAS_FLOAT_FIXED + +static void ivas_calc_mat_inv_fx( + Word32 in_re[MAX_MAT_DIM][MAX_MAT_DIM], + Word16 q_in_re, + const Word16 dim, + Word32 out_re[MAX_MAT_DIM][MAX_MAT_DIM], + Word16 *q_out_re) +{ + Word64 det; + Word16 one_by_det, q_one_by_det; + Word16 i, j, q_tmp; + + IF ( EQ_16(dim, IVAS_MAT_DIM_1)) + { + det = W_mult0_32_32(in_re[0][0], in_re[0][0]); + /* assert to catch cases when input is singular matrix*/ + assert(det > 0); + + //det = (dbl_in_re[0][0] * dbl_in_re[0][0]); + //det = 1 / det = 1 / (dbl_in_re[0][0] * dbl_in_re[0][0]); + //dbl_out_re[0][0] = dbl_in_re[0][0] * det = dbl_in_re[0][0] * (1 / (dbl_in_re[0][0] * dbl_in_re[0][0])); + //dbl_out_re[0][0] = 1 / dbl_in_re[0][0]; + + one_by_det = BASOP_Util_Divide3232_Scale(1, in_re[0][0], &q_tmp); + q_one_by_det = sub(15, add(q_tmp, q_in_re)); + + out_re[0][0] = one_by_det; move32(); + *q_out_re = q_one_by_det; move16(); + } + ELSE IF(EQ_16(dim, IVAS_MAT_DIM_2)) + { + Word64 det_re; + Word16 q_det_re; + + ivas_calc_mat_det_fx(in_re, q_in_re, dim, &det_re, &q_det_re); + q_tmp = W_norm(det_re); + q_tmp = s_max(sub(32, q_tmp),0); + + det_re = W_shr(det_re, q_tmp); + q_det_re = sub(q_det_re, q_tmp); + + det = W_mult0_32_32(W_extract_l(det_re), W_extract_l(det_re)); + /* assert to catch cases when input is singular matrix*/ + assert(det > 0); + + one_by_det = BASOP_Util_Divide3232_Scale(1, W_extract_l(det_re), &q_tmp); //Q = (15 - (q_tmp + q_det_re)) + + out_re[0][0] = Mpy_32_16_1(in_re[1][1], one_by_det); + + out_re[0][1] = -Mpy_32_16_1(in_re[0][1], one_by_det); + + out_re[1][0] = -Mpy_32_16_1(in_re[1][0], one_by_det); + + out_re[1][1] = Mpy_32_16_1(in_re[0][0], one_by_det); + + *q_out_re = sub(q_in_re, add(q_tmp, q_det_re)); // Q = (15-(q_tmp + q_det_re)) + q_in_re - 15 + } + ELSE IF(EQ_16(dim, IVAS_MAT_DIM_3)) + { + Word32 fac_re[IVAS_MAT_DIM_3][IVAS_MAT_DIM_3]; + Word64 det_re, W_tmp; + Word16 q_det_re, q_W_tmp = 0; move16(); + Word16 sign = 1; move16(); + + ivas_calc_mat_det_fx(in_re, q_in_re, dim, &det_re, &q_det_re); + q_tmp = W_norm(det_re); + q_tmp = s_max(sub(32, q_tmp), 0); + + det_re = W_shr(det_re, q_tmp); + q_det_re = sub(q_det_re, q_tmp); + + IF(EQ_64(det_re, 0)) + { + det_re = 1; move64(); + } + + one_by_det = BASOP_Util_Divide3232_Scale(1, W_extract_l(det_re), &q_tmp); + q_one_by_det = sub(15, add(q_tmp, q_det_re)); + + FOR (i = 0; i < dim; i++) + { + FOR (j = 0; j < dim; j++) + { + ivas_get_mat_cofactor_fx(in_re, fac_re, i, j); + ivas_calc_mat_det_fx(fac_re, q_in_re, IVAS_MAT_DIM_2, &W_tmp, &q_W_tmp); + + out_re[j][i] = Mpy_32_16_1(W_extract_h(W_tmp), one_by_det); move32(); + out_re[j][i] = W_extract_l(W_mult0_32_32(out_re[j][i], sign)); move32(); + + IF ( s_and(add(i, j), 1) == 0) + { + sign = -1; move16(); + } + ELSE + { + sign = 1; move16(); + } + } + } + *q_out_re = sub(add(sub(q_W_tmp, 32), q_one_by_det), 15); + } + ELSE + { + assert(!"matrix dimension not supported!"); + } + + return; +} + +#endif // IVAS_FLOAT_FIXED + /*-----------------------------------------------------------------------------------------* * Function ivas_is_mat_inv() @@ -1808,6 +2835,35 @@ static int16_t ivas_is_mat_inv( return is_det_zero; } +#ifdef IVAS_FLOAT_FIXED + +static Word16 ivas_is_mat_inv_fx( + Word32 in_re[MAX_MAT_DIM][MAX_MAT_DIM], + Word16 q_in_re, + const Word16 dim) +{ + Word16 is_det_zero = 0, q_det_re = 0, tmp; move16(); move16(); + Word64 det, det_re; + + ivas_calc_mat_det_fx(in_re, q_in_re, dim, &det_re, &q_det_re); + + tmp = W_norm(det_re); + tmp = s_max(sub(32, tmp), 0); + + det_re = W_shr(det_re, tmp); + q_det_re = sub(q_det_re, tmp); + + det = W_mult0_32_32(W_extract_l(det_re), W_extract_l(det_re)); + + IF (LE_64( det, IVAS_FIX_EPS)) + { + is_det_zero = 1; move16(); + } + + return is_det_zero; +} +#endif // IVAS_FLOAT_FIXED + /*-----------------------------------------------------------------------------------------* * Function ivas_compute_spar_params() @@ -1872,81 +2928,97 @@ void ivas_compute_spar_params( #ifdef IVAS_FLOAT_FIXED void ivas_compute_spar_params_fx( Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word16 q_cov_real, Word32 dm_fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], - const int16_t i_ts, - float ***mixer_mat, - const int16_t start_band, - const int16_t end_band, - const int16_t dtx_vad, - const int16_t num_ch, - const int16_t bands_bw, - const int16_t active_w, - const int16_t active_w_vlbr, + Word16 *q_dm_fv_re, + const Word16 i_ts, + Word32 ***mixer_mat_fx, + Word16 *q_mixer_mat, + const Word16 start_band, + const Word16 end_band, + const Word16 dtx_vad, + const Word16 num_ch, + const Word16 bands_bw, + const Word16 active_w, + const Word16 active_w_vlbr, ivas_spar_md_com_cfg *hSparCfg, ivas_spar_md_t *hSparMd, - float *pWscale, - const int16_t from_dirac, - const int16_t dyn_active_w_flag ) + Word32 *pWscale_fx, + Word16 *q_pWscale, + const Word16 from_dirac, + const Word16 dyn_active_w_flag ) { Word32 pred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; - float pred_coeffs_re_flt[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; - float dm_fv_re_flt[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; - int16_t b, i, ndm; - int16_t q_pred_coeffs; - int16_t q_dm_fv_re; - float cov_real_flt[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][12]; - float *p_cov_real_flt[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; - for ( i = 0; i < num_ch; i++ ) - { - for ( int j = 0; j < num_ch; j++ ) + Word16 b, i, ndm; + Word16 q_pred_coeffs; + + ivas_get_pred_coeffs_fx( cov_real, pred_coeffs_re, dm_fv_re, num_ch, start_band, end_band, active_w, active_w_vlbr, dtx_vad, from_dirac, dyn_active_w_flag, hSparMd->res_ind, &q_pred_coeffs, q_dm_fv_re ); + + ivas_create_fullr_dmx_mat_fx( pred_coeffs_re, q_pred_coeffs, dm_fv_re, *q_dm_fv_re, mixer_mat_fx, q_mixer_mat, num_ch, start_band, end_band, active_w, hSparCfg ); + + ivas_get_Wscaling_factor_fx( cov_real, q_cov_real, pred_coeffs_re, q_pred_coeffs, mixer_mat_fx, *q_mixer_mat, start_band, end_band, dtx_vad, num_ch, hSparCfg->num_dmx_chans_per_band, bands_bw, active_w, active_w_vlbr, pWscale_fx, q_pWscale, dyn_active_w_flag ); + + FOR (b = start_band; b < end_band; b++) + { + Word16 tmp_exp, q_tmp, tmp; + Word16 onebyscale_fx = BASOP_Util_Divide3232_Scale(L_shl(1, q_pWscale[b]), pWscale_fx[b], &tmp_exp); + q_tmp = sub(15, tmp_exp); + + tmp = sub(add(q_pred_coeffs, q_tmp), 15); + FOR (i = 0; i < num_ch - 1; i++) + { + hSparMd->band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].pred_re_fx[i] = Mpy_32_16_1(pred_coeffs_re[i][b], onebyscale_fx); + move32(); + IF (LT_16( tmp, 0)) + { + tmp = -tmp;move16(); + hSparMd->band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].pred_re_fx[i] = L_shl(hSparMd->band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].pred_re_fx[i], add(tmp, 22)); + move32(); + } + ELSE { + hSparMd->band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].pred_re_fx[i] = L_shr(hSparMd->band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].pred_re_fx[i], sub(tmp, 22)); + move32(); + } + } + // hSparMd->band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].q_pred_re_fx = sub(add(q_pred_coeffs, q_tmp), 15); + hSparMd->band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].q_pred_re_fx = Q22; move16(); + + FOR (i = 0; i < num_ch; i++) + { + mixer_mat_fx[0][i][b] = W_extract_l(W_shr(W_mult0_32_32(mixer_mat_fx[0][i][b], pWscale_fx[b]), q_pWscale[b])); + move32(); + } + } + + FOR ( b = start_band; b < end_band; b++ ) + { + ndm = hSparCfg->num_dmx_chans_per_band[b * bands_bw]; move16(); + + IF ( NE_16( ndm, num_ch ) ) { - for ( int k = 0; k < 12; k++ ) + ivas_calc_c_p_coeffs_fx( hSparMd, cov_real, q_cov_real, i_ts, mixer_mat_fx, *q_mixer_mat, num_ch, ndm, b, dtx_vad, 1, dyn_active_w_flag ); + + Word16 q_tmp = hSparMd->band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].q_C_re_fx; + IF( NE_16(ndm, 1 )) { - cov_real_flt[i][j][k] = (float) cov_real[i][j][k] / ONE_IN_Q30; + for (i = 0; i < IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS; i++) + { + for (int j = 0; j < IVAS_SPAR_MAX_DMX_CHS - 1; j++) + { + hSparMd->band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].C_re_fx[i][j] = L_shr(hSparMd->band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].C_re_fx[i][j], sub(q_tmp, 22)); + } + } + hSparMd->band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].q_C_re_fx = Q22; } - p_cov_real_flt[i][j] = cov_real_flt[i][j]; - } - } - - ivas_get_pred_coeffs_fx( cov_real, pred_coeffs_re, dm_fv_re, num_ch, start_band, end_band, active_w, active_w_vlbr, dtx_vad, from_dirac, dyn_active_w_flag, hSparMd->res_ind, &q_pred_coeffs, &q_dm_fv_re ); - for ( b = start_band; b < end_band; b++ ) - { - for ( i = 0; i < num_ch - 1; i++ ) - { - pred_coeffs_re_flt[i][b] = (float) pred_coeffs_re[i][b] / ( 1 << q_pred_coeffs ); - dm_fv_re_flt[i][b] = (float) dm_fv_re[i][b] / ( 1 << q_dm_fv_re ); - } - } - - ivas_create_fullr_dmx_mat( pred_coeffs_re_flt, dm_fv_re_flt, mixer_mat, num_ch, start_band, end_band, active_w, hSparCfg ); + q_tmp = hSparMd->band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].q_P_re_fx; - ivas_get_Wscaling_factor( p_cov_real_flt, pred_coeffs_re_flt, mixer_mat, start_band, end_band, dtx_vad, num_ch, hSparCfg->num_dmx_chans_per_band, bands_bw, active_w, active_w_vlbr, pWscale, dyn_active_w_flag ); - - for ( b = start_band; b < end_band; b++ ) - { - float onebyscale = 1.0f / pWscale[b]; - Word32 onebyscale_fx = (Word32) ( onebyscale * ( (UWord32) 1 << ( 53 - q_pred_coeffs ) ) ); - for ( i = 0; i < num_ch - 1; i++ ) - { - hSparMd->band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].pred_re[i] = pred_coeffs_re_flt[i][b] * onebyscale; - hSparMd->band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].pred_re_fx[i] = Mpy_32_32( pred_coeffs_re[i][b], onebyscale_fx ); // q_pred_coeffs + (53 - q_pred_coeffs) - 31 = Q22 - } - - for ( i = 0; i < num_ch; i++ ) - { - mixer_mat[0][i][b] *= pWscale[b]; - } - } - - for ( b = start_band; b < end_band; b++ ) - { - ndm = hSparCfg->num_dmx_chans_per_band[b * bands_bw]; - - if ( ndm != num_ch ) - { - ivas_calc_c_p_coeffs( hSparMd, p_cov_real_flt, i_ts, mixer_mat, num_ch, ndm, b, dtx_vad, 1, dyn_active_w_flag ); + for (int j = 0; j < IVAS_SPAR_MAX_CH - 1; j++) + { + hSparMd->band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].P_re_fx[j] = L_shr(hSparMd->band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].P_re_fx[j], sub(q_tmp, 22)); + } + hSparMd->band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].q_P_re_fx = Q22; } } @@ -1969,36 +3041,23 @@ Word32 diff_norm_order3_table[8] = { 0, 1879048192, 939524096, 626349376, 469762 #define ONE_BY_FIVE_Q31 429496729 #define ONE_BY_SEVEN_Q31 306783378 void ivas_get_spar_md_from_dirac_fx( - float azi_dirac[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES], - float ele_dirac[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES], - float diffuseness[IVAS_MAX_NUM_BANDS], + Word32 azi_dirac_fx[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES], + Word32 ele_dirac_fx[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES], + Word32 diffuseness_fx[IVAS_MAX_NUM_BANDS], const int16_t n_ts, - float ***mixer_mat, + Word32 ***mixer_mat_fx, ivas_spar_md_t *hSpar_md, ivas_spar_md_com_cfg *hSpar_md_cfg, const int16_t start_band, const int16_t end_band, const int16_t order, const int16_t dtx_vad, - float Wscale_d[IVAS_MAX_NUM_BANDS], + Word32 Wscale_d[IVAS_MAX_NUM_BANDS], const uint8_t useLowerRes, const int16_t active_w_vlbr, const int16_t dyn_active_w_flag ) { - Word32 azi_dirac_fx[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES]; - Word32 ele_dirac_fx[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES]; - Word32 diffuseness_fx[IVAS_MAX_NUM_BANDS]; - for ( int i = 0; i < IVAS_MAX_NUM_BANDS; i++ ) - { - for ( int j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ ) - { - azi_dirac_fx[i][j] = (Word32)(azi_dirac[i][j] * ( 1 << 22 )); - ele_dirac_fx[i][j] = (Word32)(ele_dirac[i][j] * ( 1 << 22 )); - } - diffuseness_fx[i] = (Word32)(diffuseness[i] * ( 1 << 30 )); - } - int16_t num_ch, band, i, j; int16_t block, ch; @@ -2013,20 +3072,23 @@ void ivas_get_spar_md_from_dirac_fx( Word32 *pCov_real_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; //float dm_fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; Word32 dm_fv_re_fx[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; - float Wscale[IVAS_MAX_NUM_BANDS]; - //Word32 Wscale_fx[IVAS_MAX_NUM_BANDS]; - float mixer_mat_local[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH][IVAS_MAX_NUM_BANDS]; + Word16 q_dm_fv_re_fx = 0; + //float Wscale[IVAS_MAX_NUM_BANDS]; + Word16 q_Wscale[IVAS_MAX_NUM_BANDS] = { 0 }; + Word32 Wscale_fx[IVAS_MAX_NUM_BANDS] = { 0 }; + //float mixer_mat_local[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH][IVAS_MAX_NUM_BANDS]; Word32 mixer_mat_local_fx[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH][IVAS_MAX_NUM_BANDS]; - float **ppMixer_mat[IVAS_MAX_FB_MIXER_OUT_CH]; + //float **ppMixer_mat[IVAS_MAX_FB_MIXER_OUT_CH]; Word32 **ppMixer_mat_fx[IVAS_MAX_FB_MIXER_OUT_CH]; - float *pMixer_mat[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH]; + //float *pMixer_mat[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH]; Word32 *pMixer_mat_fx[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH]; + Word16 q_ppMixer_mat = 0; //float en_ratio_fac, diff_norm_order1, diff_norm_order2, diff_norm_order3; Word32 en_ratio_fac_fx, diff_norm_order1_fx, diff_norm_order2_fx, diff_norm_order3_fx; int16_t active_w; int16_t ndm, foa_ch, hoa2_ch; - float P_dir_fact[IVAS_SPAR_MAX_CH - 1]; + //float P_dir_fact[IVAS_SPAR_MAX_CH - 1]; Word32 P_dir_fact_fx[IVAS_SPAR_MAX_CH - 1]; const int16_t *remix_order; @@ -2049,38 +3111,38 @@ void ivas_get_spar_md_from_dirac_fx( { for ( j = 0; j < IVAS_MAX_SPAR_FB_MIXER_IN_CH; j++ ) { - pMixer_mat[i][j] = mixer_mat_local[i][j]; + //pMixer_mat[i][j] = mixer_mat_local[i][j]; pMixer_mat_fx[i][j] = mixer_mat_local_fx[i][j]; } - ppMixer_mat[i] = pMixer_mat[i]; + //ppMixer_mat[i] = pMixer_mat[i]; ppMixer_mat_fx[i] = pMixer_mat_fx[i]; } if ( ( start_band >= 6 && hSpar_md_cfg->nchan_transport <= 2 && ( dtx_vad == 1 ) ) || ( useLowerRes && start_band >= 3 && hSpar_md_cfg->nchan_transport <= 2 && ( dtx_vad == 1 ) ) ) { - float P_norm[3]; + //float P_norm[3]; Word32 P_norm_fx[3]; int16_t idx; ndm = hSpar_md_cfg->num_dmx_chans_per_band[start_band - 1]; // ndm max value of 4 - P_norm[0] = 0.0f; + //P_norm[0] = 0.0f; P_norm_fx[0] = 0; for ( i = 0; i < max( 0, foa_ch - ndm ); i++ ) { // use 64bit if low precission - P_norm[0] += hSpar_md->band_coeffs[start_band - 1].P_re[i] * hSpar_md->band_coeffs[start_band - 1].P_re[i]; + //P_norm[0] += hSpar_md->band_coeffs[start_band - 1].P_re[i] * hSpar_md->band_coeffs[start_band - 1].P_re[i]; P_norm_fx[0] = P_norm_fx[0] + Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ); } //P_norm[0] *= diff_norm_order1 / min( diff_norm_order1, max( 0, foa_ch - ndm ) ); // P_norm_fx[0] *= diff_norm_order1 / min( diff_norm_order1, max( 0, foa_ch - ndm ) ); P_norm_fx[0] = Mpy_32_32( L_shl( P_norm_fx[0], 3 ), diff_norm_order1_table[min( diff_norm_order1_fx, max( 0, foa_ch - ndm ) )] ); - P_norm[1] = 0.0f; + // P_norm[1] = 0.0f; P_norm_fx[1] = 0; for ( ; i < max( 0, min( num_ch, hoa2_ch ) - ndm ); i++ ) { - P_norm[1] += hSpar_md->band_coeffs[start_band - 1].P_re[i] * hSpar_md->band_coeffs[start_band - 1].P_re[i]; + //P_norm[1] += hSpar_md->band_coeffs[start_band - 1].P_re[i] * hSpar_md->band_coeffs[start_band - 1].P_re[i]; P_norm_fx[1] = P_norm_fx[1] + Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ); } //P_norm[1] *= diff_norm_order2 / min( diff_norm_order2, max( 0, min( num_ch, hoa2_ch ) - ndm ) ); @@ -2088,11 +3150,11 @@ void ivas_get_spar_md_from_dirac_fx( P_norm_fx[1] = Mpy_32_32( L_shl( P_norm_fx[1], 3 ), diff_norm_order2_table[min( diff_norm_order2_fx, max( 0, min( num_ch, hoa2_ch ) - ndm ) )] ); - P_norm[2] = 0.0f; + //P_norm[2] = 0.0f; P_norm_fx[2] = 0; for ( ; i < num_ch - ndm; i++ ) { - P_norm[2] += hSpar_md->band_coeffs[start_band - 1].P_re[i] * hSpar_md->band_coeffs[start_band - 1].P_re[i]; + //P_norm[2] += hSpar_md->band_coeffs[start_band - 1].P_re[i] * hSpar_md->band_coeffs[start_band - 1].P_re[i]; P_norm_fx[2] = P_norm_fx[2] + Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ); } //P_norm[2] *= diff_norm_order3 / min( diff_norm_order3, max( 0, num_ch - ndm ) ); @@ -2102,9 +3164,9 @@ void ivas_get_spar_md_from_dirac_fx( for ( i = 0; i < max( 0, foa_ch - ndm ); i++ ) { idx = remix_order[i + ndm] - ndm; - P_dir_fact[idx] = hSpar_md->band_coeffs[start_band - 1].P_re[i] * hSpar_md->band_coeffs[start_band - 1].P_re[i]; + //P_dir_fact[idx] = hSpar_md->band_coeffs[start_band - 1].P_re[i] * hSpar_md->band_coeffs[start_band - 1].P_re[i]; P_dir_fact_fx[idx] = Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ); - P_dir_fact[idx] = P_dir_fact[idx] / max( IVAS_FLT_EPS, P_norm[0] ); + //P_dir_fact[idx] = P_dir_fact[idx] / max( IVAS_FLT_EPS, P_norm[0] ); if ( P_dir_fact_fx[idx] == 0 ) { P_dir_fact_fx[idx] = 0; @@ -2118,9 +3180,9 @@ void ivas_get_spar_md_from_dirac_fx( for ( ; i < max( 0, min( num_ch, hoa2_ch ) - ndm ); i++ ) { idx = remix_order[i + ndm] - ndm; - P_dir_fact[idx] = hSpar_md->band_coeffs[start_band - 1].P_re[i] * hSpar_md->band_coeffs[start_band - 1].P_re[i]; + //P_dir_fact[idx] = hSpar_md->band_coeffs[start_band - 1].P_re[i] * hSpar_md->band_coeffs[start_band - 1].P_re[i]; P_dir_fact_fx[idx] = ( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ); - P_dir_fact[idx] = P_dir_fact[idx] / max( IVAS_FLT_EPS, P_norm[1] ); + //P_dir_fact[idx] = P_dir_fact[idx] / max( IVAS_FLT_EPS, P_norm[1] ); if ( P_dir_fact_fx[idx] == 0 ) { P_dir_fact_fx[idx] = 0; @@ -2134,9 +3196,9 @@ void ivas_get_spar_md_from_dirac_fx( for ( ; i < num_ch - ndm; i++ ) { idx = remix_order[i + ndm] - ndm; - P_dir_fact[idx] = hSpar_md->band_coeffs[start_band - 1].P_re[i] * hSpar_md->band_coeffs[start_band - 1].P_re[i]; + //P_dir_fact[idx] = hSpar_md->band_coeffs[start_band - 1].P_re[i] * hSpar_md->band_coeffs[start_band - 1].P_re[i]; P_dir_fact_fx[idx] = ( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ); - P_dir_fact[idx] = P_dir_fact[idx] / max( IVAS_FLT_EPS, P_norm[2] ); + //P_dir_fact[idx] = P_dir_fact[idx] / max( IVAS_FLT_EPS, P_norm[2] ); if ( P_dir_fact_fx[idx] == 0 ) { P_dir_fact_fx[idx] = 0; @@ -2162,7 +3224,7 @@ void ivas_get_spar_md_from_dirac_fx( if ( n_ts > 1 ) { //ivas_dirac_dec_get_response( (int16_t) azi_dirac[band][i_ts], (int16_t) ele_dirac[band][i_ts], response_avg, order ); - ivas_dirac_dec_get_response_fx( (int16_t) azi_dirac[band][i_ts], (int16_t) ele_dirac[band][i_ts], response_avg_fx, order ); + ivas_dirac_dec_get_response_fx( (int16_t) L_shr(azi_dirac_fx[band][i_ts], Q22), (int16_t) L_shr(ele_dirac_fx[band][i_ts], Q22), response_avg_fx, order ); /*for ( int l = 0; l < MAX_OUTPUT_CHANNELS; l++ ) { response_avg[l] = (float) response_avg_fx[l] / ( 1 << 30 ); @@ -2171,7 +3233,7 @@ void ivas_get_spar_md_from_dirac_fx( else if ( useLowerRes ) { //ivas_dirac_dec_get_response( (int16_t) azi_dirac[band][0], (int16_t) ele_dirac[band][0], response_avg, order ); - ivas_dirac_dec_get_response_fx( (int16_t) azi_dirac[band][0], (int16_t) ele_dirac[band][0], response_avg_fx, order ); + ivas_dirac_dec_get_response_fx( (int16_t) L_shr(azi_dirac_fx[band][0], Q22), (int16_t) L_shr(ele_dirac_fx[band][0], Q22), response_avg_fx, order ); /*for ( int l = 0; l < MAX_OUTPUT_CHANNELS; l++ ) { response_avg[l] = (float) response_avg_fx[l] / ( 1 << 30 ); @@ -2182,7 +3244,7 @@ void ivas_get_spar_md_from_dirac_fx( for ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ ) { //ivas_dirac_dec_get_response( (int16_t) azi_dirac[band][block], (int16_t) ele_dirac[band][block], &( response[block][0] ), order ); - ivas_dirac_dec_get_response_fx( (int16_t) azi_dirac[band][block], (int16_t) ele_dirac[band][block], &( response_fx[block][0] ), order ); + ivas_dirac_dec_get_response_fx( (int16_t) L_shr(azi_dirac_fx[band][block], Q22), (int16_t) L_shr(ele_dirac_fx[band][block], Q22), &( response_fx[block][0] ), order ); /*for ( int l = 0; l < MAX_OUTPUT_CHANNELS; l++ ) { response[block][l] = (float) response_fx[block][l] / ( 1 << 30 ); @@ -2191,7 +3253,7 @@ void ivas_get_spar_md_from_dirac_fx( /* average responses in all subframes*/ { - float norm; + //float norm; Word32 norm_fx; Word16 norm_q; int16_t num_ch_order, hoa2_ch_order; @@ -2212,7 +3274,7 @@ void ivas_get_spar_md_from_dirac_fx( } /*normalize 1st order*/ - norm = 0.0f; + //norm = 0.0f; norm_fx = 0; norm_q = 0; for ( ch = 1; ch < foa_ch; ch++ ) @@ -2222,7 +3284,7 @@ void ivas_get_spar_md_from_dirac_fx( } norm_q = 31 - ( 30 + 30 - 31 ); - norm = max( EPSILON, sqrtf( norm ) ); + //norm = max( EPSILON, sqrtf( norm ) ); if ( norm_fx ) { norm_fx = Sqrt32( norm_fx, &norm_q ); @@ -2261,7 +3323,7 @@ void ivas_get_spar_md_from_dirac_fx( } /*normalize 2nd order*/ - norm = 0.0f; + //norm = 0.0f; norm_fx = 0; for ( ch = foa_ch; ch < min( hoa2_ch_order, num_ch_order ); ch++ ) { @@ -2269,7 +3331,7 @@ void ivas_get_spar_md_from_dirac_fx( norm_fx = norm_fx + Mpy_32_32( response_avg_fx[ch], response_avg_fx[ch] ); } norm_q = 31 - ( 29 + 29 - 31 ); - norm = max( EPSILON, sqrtf( norm ) ); + //norm = max( EPSILON, sqrtf( norm ) ); if ( norm_fx ) { norm_fx = Sqrt32( norm_fx, &norm_q ); @@ -2305,14 +3367,14 @@ void ivas_get_spar_md_from_dirac_fx( } /*normalize 3rd order*/ - norm = 0.0f; + //norm = 0.0f; for ( ch = hoa2_ch_order; ch < num_ch_order; ch++ ) { //norm += response_avg[ch] * response_avg[ch]; norm_fx = norm_fx + Mpy_32_32( response_avg_fx[ch], response_avg_fx[ch] ); } norm_q = 31 - ( 29 + 29 - 31 ); - norm = max( EPSILON, sqrtf( norm ) ); + //norm = max( EPSILON, sqrtf( norm ) ); if ( norm_fx ) { norm_fx = Sqrt32( norm_fx, &norm_q ); @@ -2450,33 +3512,36 @@ void ivas_get_spar_md_from_dirac_fx( pCov_real_fx[i][j] = cov_real_dirac_fx[i][j]; } } - static int frame_counter; + /*static int frame_counter; frame_counter++; if (frame_counter > 500) { frame_counter = frame_counter; - } + }*/ active_w = ( dyn_active_w_flag == 1 ) || ( hSpar_md_cfg->active_w == 1 ); -#ifdef IVAS_FLOAT_FIXED - ivas_compute_spar_params_fx( pCov_real_fx, dm_fv_re_fx, i_ts, ppMixer_mat, start_band, end_band, dtx_vad, num_ch, 1, active_w, active_w_vlbr, hSpar_md_cfg, hSpar_md, Wscale, 1, dyn_active_w_flag ); -#else - for (int i = 0; i < num_ch; i++) - { - for (int j = 0; j < num_ch; j++) - { - for (int k = start_band; k < end_band; k++) - { - cov_real_dirac[i][j][k] = (float)cov_real_dirac_fx[i][j][k] / (1 << 30); - } - } - } +// #ifdef IVAS_FLOAT_FIXED - ivas_compute_spar_params( pCov_real, dm_fv_re, i_ts, ppMixer_mat, start_band, end_band, dtx_vad, num_ch, 1, active_w, active_w_vlbr, hSpar_md_cfg, hSpar_md, Wscale, 1, dyn_active_w_flag ); -#endif // IVAS_FLOAT_FIXED + ivas_compute_spar_params_fx( pCov_real_fx, Q30, dm_fv_re_fx, &q_dm_fv_re_fx, i_ts, ppMixer_mat_fx, &q_ppMixer_mat, start_band, end_band, dtx_vad, num_ch, 1, active_w, active_w_vlbr, hSpar_md_cfg, hSpar_md, Wscale_fx, q_Wscale, 1, dyn_active_w_flag ); - if ( mixer_mat != NULL ) +// #else +// for (int i = 0; i < num_ch; i++) +// { +// for (int j = 0; j < num_ch; j++) +// { +// for (int k = start_band; k < end_band; k++) +// { +// cov_real_dirac[i][j][k] = (float)cov_real_dirac_fx[i][j][k] / (1 << 30); +// } +// } +// } + +// ivas_compute_spar_params( pCov_real, dm_fv_re, i_ts, ppMixer_mat, start_band, end_band, dtx_vad, num_ch, 1, active_w, active_w_vlbr, hSpar_md_cfg, hSpar_md, Wscale, 1, dyn_active_w_flag ); +// +//#endif // IVAS_FLOAT_FIXED + + if ( mixer_mat_fx != NULL ) { for ( band = start_band; band < end_band; band++ ) { @@ -2486,7 +3551,7 @@ void ivas_get_spar_md_from_dirac_fx( { for ( j = 0; j < num_ch; j++ ) { - mixer_mat[i][j][band + i_ts * IVAS_MAX_NUM_BANDS] = ppMixer_mat[i][j][band]; + mixer_mat_fx[i][j][band + i_ts * IVAS_MAX_NUM_BANDS] = ppMixer_mat_fx[i][j][band]; } } @@ -2494,7 +3559,7 @@ void ivas_get_spar_md_from_dirac_fx( { for ( j = 0; j < num_ch; j++ ) { - mixer_mat[i][j][band + i_ts * IVAS_MAX_NUM_BANDS] = 0.0f; + mixer_mat_fx[i][j][band + i_ts * IVAS_MAX_NUM_BANDS] = 0; } } @@ -2502,7 +3567,7 @@ void ivas_get_spar_md_from_dirac_fx( { for ( j = 0; j < num_ch; j++ ) { - mixer_mat[0][j][band + i_ts * IVAS_MAX_NUM_BANDS] *= Wscale_d[band]; + mixer_mat_fx[0][j][band + i_ts * IVAS_MAX_NUM_BANDS] = Mpy_32_32(mixer_mat_fx[0][j][band + i_ts * IVAS_MAX_NUM_BANDS], Wscale_d[band]); } } } @@ -5568,8 +6633,8 @@ void ivas_spar_set_bitrate_config_fx( pSpar_md_cfg->active_w = ivas_spar_br_table_consts[table_idx].active_w; pSpar_md_cfg->agc_bits_ch_idx = ivas_spar_br_table_consts[table_idx].agc_bits_ch_idx; -#if 0 //Some issues - ivas_spar_get_uniform_quant_strat_fx(pSpar_md_cfg, table_idx); +#if 1 //Some issues + ivas_spar_get_uniform_quant_strat(pSpar_md_cfg, table_idx); #endif pSpar_md_cfg->quant_strat_bits = ivas_get_bits_to_encode(MAX_QUANT_STRATS); diff --git a/lib_com/ivas_spar_com_quant_util.c b/lib_com/ivas_spar_com_quant_util.c index c1933745d..763eb9d84 100644 --- a/lib_com/ivas_spar_com_quant_util.c +++ b/lib_com/ivas_spar_com_quant_util.c @@ -41,6 +41,8 @@ #include #include "wmc_auto.h" #include "prot_fx1.h" + + /*-----------------------------------------------------------------------------------------* * Function ivas_quantise_real_values() * @@ -133,6 +135,7 @@ void ivas_quantise_real_values_fx( } +#ifndef IVAS_FLOAT_FIXED /*-----------------------------------------------------------------------------------------* * Function ivas_spar_get_uniform_quant_strat() * @@ -160,67 +163,59 @@ void ivas_spar_get_uniform_quant_strat( pSpar_md_com_cfg->quant_strat[i].PR.q_levels[0] = PQ_q_lvl; pSpar_md_com_cfg->quant_strat[i].PR.q_levels[1] = PQ_q_lvl; pSpar_md_com_cfg->quant_strat[i].PR.min = -1.2f; - pSpar_md_com_cfg->quant_strat[i].PR.min_fx = -644245094/2; pSpar_md_com_cfg->quant_strat[i].PR.max = 1.2f; - pSpar_md_com_cfg->quant_strat[i].PR.max_fx = 644245094/2; + pSpar_md_com_cfg->quant_strat[i].C.q_levels[0] = C_q_lvl; pSpar_md_com_cfg->quant_strat[i].C.q_levels[1] = C_q_lvl; pSpar_md_com_cfg->quant_strat[i].C.min = -0.8f; - pSpar_md_com_cfg->quant_strat[i].C.min_fx = -429496729/2; pSpar_md_com_cfg->quant_strat[i].C.max = 0.8f; - pSpar_md_com_cfg->quant_strat[i].C.max_fx = 429496729/2; + pSpar_md_com_cfg->quant_strat[i].P_r.q_levels[0] = Pr_q_lvl; pSpar_md_com_cfg->quant_strat[i].P_r.q_levels[1] = Pr_q_lvl; pSpar_md_com_cfg->quant_strat[i].P_r.min = 0; - pSpar_md_com_cfg->quant_strat[i].P_r.min_fx = 0; pSpar_md_com_cfg->quant_strat[i].P_r.max = 0.8f; - pSpar_md_com_cfg->quant_strat[i].P_r.max_fx = 429496729/2; + pSpar_md_com_cfg->quant_strat[i].P_c.q_levels[0] = Pc_q_lvl; pSpar_md_com_cfg->quant_strat[i].P_c.q_levels[1] = Pc_q_lvl; pSpar_md_com_cfg->quant_strat[i].P_c.min = -0.8f; - pSpar_md_com_cfg->quant_strat[i].P_c.min_fx = -429496729/2; pSpar_md_com_cfg->quant_strat[i].P_c.max = 0.8f; - pSpar_md_com_cfg->quant_strat[i].P_c.max_fx = 429496729/2; + } else { pSpar_md_com_cfg->quant_strat[i].PR.q_levels[0] = PQ_q_lvl; pSpar_md_com_cfg->quant_strat[i].PR.q_levels[1] = PQ_q_lvl; pSpar_md_com_cfg->quant_strat[i].PR.max = 1; - pSpar_md_com_cfg->quant_strat[i].PR.max_fx = 536870912/2; pSpar_md_com_cfg->quant_strat[i].PR.min = -1; - pSpar_md_com_cfg->quant_strat[i].PR.min_fx = -536870912/2; + pSpar_md_com_cfg->quant_strat[i].C.q_levels[0] = C_q_lvl; pSpar_md_com_cfg->quant_strat[i].C.q_levels[1] = C_q_lvl; pSpar_md_com_cfg->quant_strat[i].C.max = 2; - pSpar_md_com_cfg->quant_strat[i].C.max_fx = 1073741824/2; pSpar_md_com_cfg->quant_strat[i].C.min = -2; - pSpar_md_com_cfg->quant_strat[i].C.min_fx = -1073741824/2; + pSpar_md_com_cfg->quant_strat[i].P_r.q_levels[0] = Pr_q_lvl; pSpar_md_com_cfg->quant_strat[i].P_r.q_levels[1] = Pr_q_lvl; pSpar_md_com_cfg->quant_strat[i].P_r.max = 1.0f; - pSpar_md_com_cfg->quant_strat[i].P_r.max_fx = 536870912/2; pSpar_md_com_cfg->quant_strat[i].P_r.min = 0; - pSpar_md_com_cfg->quant_strat[i].P_r.min_fx = 0; + pSpar_md_com_cfg->quant_strat[i].P_c.q_levels[0] = Pc_q_lvl; pSpar_md_com_cfg->quant_strat[i].P_c.q_levels[1] = Pc_q_lvl; pSpar_md_com_cfg->quant_strat[i].P_c.max = 0.5; - pSpar_md_com_cfg->quant_strat[i].P_c.max_fx = 268435456/2; pSpar_md_com_cfg->quant_strat[i].P_c.min = -0.5; - pSpar_md_com_cfg->quant_strat[i].P_c.min_fx = -268435456/2; + } } return; } -#if 0 -void ivas_spar_get_uniform_quant_strat_fx( +#else +void ivas_spar_get_uniform_quant_strat( ivas_spar_md_com_cfg *pSpar_md_com_cfg, const Word16 table_idx) { @@ -230,58 +225,58 @@ void ivas_spar_get_uniform_quant_strat_fx( pSpar_md_com_cfg->num_quant_strats = MAX_QUANT_STRATS; - FOR (i = 0; i < pSpar_md_com_cfg->num_quant_strats; i++) + for ( i = 0; i < pSpar_md_com_cfg->num_quant_strats; i++ ) { - PQ_q_lvl = ivas_spar_br_table_consts[table_idx].q_lvls[i][0]; - C_q_lvl = ivas_spar_br_table_consts[table_idx].q_lvls[i][1]; - Pr_q_lvl = ivas_spar_br_table_consts[table_idx].q_lvls[i][2]; - Pc_q_lvl = ivas_spar_br_table_consts[table_idx].q_lvls[i][3]; - - IF (active_w) - { - pSpar_md_com_cfg->quant_strat[i].PR.q_levels[0] = PQ_q_lvl; - pSpar_md_com_cfg->quant_strat[i].PR.q_levels[1] = PQ_q_lvl; - pSpar_md_com_cfg->quant_strat[i].PR.min_fx = -1288490188;//Q30 - pSpar_md_com_cfg->quant_strat[i].PR.max_fx = 1288490188;//Q30 - - pSpar_md_com_cfg->quant_strat[i].C.q_levels[0] = C_q_lvl; - pSpar_md_com_cfg->quant_strat[i].C.q_levels[1] = C_q_lvl; - pSpar_md_com_cfg->quant_strat[i].C.min_fx = -858993459;//Q30 - pSpar_md_com_cfg->quant_strat[i].C.max_fx = 858993459;//Q30 - - pSpar_md_com_cfg->quant_strat[i].P_r.q_levels[0] = Pr_q_lvl; - pSpar_md_com_cfg->quant_strat[i].P_r.q_levels[1] = Pr_q_lvl; - pSpar_md_com_cfg->quant_strat[i].P_r.min_fx = 0; - pSpar_md_com_cfg->quant_strat[i].P_r.max_fx = 858993459;//Q30 - - pSpar_md_com_cfg->quant_strat[i].P_c.q_levels[0] = Pc_q_lvl; - pSpar_md_com_cfg->quant_strat[i].P_c.q_levels[1] = Pc_q_lvl; - pSpar_md_com_cfg->quant_strat[i].P_c.min_fx = -858993459;//Q30 - pSpar_md_com_cfg->quant_strat[i].P_c.max_fx = 858993459;//Q30 - } - ELSE - { - pSpar_md_com_cfg->quant_strat[i].PR.q_levels[0] = PQ_q_lvl; - pSpar_md_com_cfg->quant_strat[i].PR.q_levels[1] = PQ_q_lvl; - pSpar_md_com_cfg->quant_strat[i].PR.max_fx = ONE_IN_Q30;//Q30 - pSpar_md_com_cfg->quant_strat[i].PR.min_fx = -ONE_IN_Q30;//Q30 - - pSpar_md_com_cfg->quant_strat[i].C.q_levels[0] = C_q_lvl; - pSpar_md_com_cfg->quant_strat[i].C.q_levels[1] = C_q_lvl; - pSpar_md_com_cfg->quant_strat[i].C.max_fx = 2147483648;//Q30 - pSpar_md_com_cfg->quant_strat[i].C.min_fx = -2147483648;//Q30 - - pSpar_md_com_cfg->quant_strat[i].P_r.q_levels[0] = Pr_q_lvl; - pSpar_md_com_cfg->quant_strat[i].P_r.q_levels[1] = Pr_q_lvl; - pSpar_md_com_cfg->quant_strat[i].P_r.max_fx = ONE_IN_Q30;//Q30 - pSpar_md_com_cfg->quant_strat[i].P_r.min_fx = 0; - - pSpar_md_com_cfg->quant_strat[i].P_c.q_levels[0] = Pc_q_lvl; - pSpar_md_com_cfg->quant_strat[i].P_c.q_levels[1] = Pc_q_lvl; - pSpar_md_com_cfg->quant_strat[i].P_c.max_fx = 536870912;//Q30 - pSpar_md_com_cfg->quant_strat[i].P_c.min_fx = -536870912;//Q30 - } - } + PQ_q_lvl = ivas_spar_br_table_consts[table_idx].q_lvls[i][0]; + C_q_lvl = ivas_spar_br_table_consts[table_idx].q_lvls[i][1]; + Pr_q_lvl = ivas_spar_br_table_consts[table_idx].q_lvls[i][2]; + Pc_q_lvl = ivas_spar_br_table_consts[table_idx].q_lvls[i][3]; + + if ( active_w ) + { + pSpar_md_com_cfg->quant_strat[i].PR.q_levels[0] = PQ_q_lvl; + pSpar_md_com_cfg->quant_strat[i].PR.q_levels[1] = PQ_q_lvl; + pSpar_md_com_cfg->quant_strat[i].PR.min_fx = -322122547;//1.2*Q28 + pSpar_md_com_cfg->quant_strat[i].PR.max_fx = 322122547;//1.2*Q28 + + pSpar_md_com_cfg->quant_strat[i].C.q_levels[0] = C_q_lvl; + pSpar_md_com_cfg->quant_strat[i].C.q_levels[1] = C_q_lvl; + pSpar_md_com_cfg->quant_strat[i].C.min_fx = -214748364; + pSpar_md_com_cfg->quant_strat[i].C.max_fx = 214748364;//.8*Q28 + + pSpar_md_com_cfg->quant_strat[i].P_r.q_levels[0] = Pr_q_lvl; + pSpar_md_com_cfg->quant_strat[i].P_r.q_levels[1] = Pr_q_lvl; + pSpar_md_com_cfg->quant_strat[i].P_r.min_fx = 0; + pSpar_md_com_cfg->quant_strat[i].P_r.max_fx = 214748364;//.8*Q28 + + pSpar_md_com_cfg->quant_strat[i].P_c.q_levels[0] = Pc_q_lvl; + pSpar_md_com_cfg->quant_strat[i].P_c.q_levels[1] = Pc_q_lvl; + pSpar_md_com_cfg->quant_strat[i].P_c.min_fx = -214748364;//.8*Q28 + pSpar_md_com_cfg->quant_strat[i].P_c.max_fx = 214748364; //.8*Q28 + } + else + { + pSpar_md_com_cfg->quant_strat[i].PR.q_levels[0] = PQ_q_lvl; + pSpar_md_com_cfg->quant_strat[i].PR.q_levels[1] = PQ_q_lvl; + pSpar_md_com_cfg->quant_strat[i].PR.max_fx = ONE_IN_Q28; + pSpar_md_com_cfg->quant_strat[i].PR.min_fx = -ONE_IN_Q28; + + pSpar_md_com_cfg->quant_strat[i].C.q_levels[0] = C_q_lvl; + pSpar_md_com_cfg->quant_strat[i].C.q_levels[1] = C_q_lvl; + pSpar_md_com_cfg->quant_strat[i].C.max_fx = 2 *ONE_IN_Q28; + pSpar_md_com_cfg->quant_strat[i].C.min_fx = -2*ONE_IN_Q28; + + pSpar_md_com_cfg->quant_strat[i].P_r.q_levels[0] = Pr_q_lvl; + pSpar_md_com_cfg->quant_strat[i].P_r.q_levels[1] = Pr_q_lvl; + pSpar_md_com_cfg->quant_strat[i].P_r.max_fx = ONE_IN_Q28; + pSpar_md_com_cfg->quant_strat[i].P_r.min_fx = 0; + + pSpar_md_com_cfg->quant_strat[i].P_c.q_levels[0] = Pc_q_lvl; + pSpar_md_com_cfg->quant_strat[i].P_c.q_levels[1] = Pc_q_lvl; + pSpar_md_com_cfg->quant_strat[i].P_c.max_fx = ONE_IN_Q27; //.5* Q28 + pSpar_md_com_cfg->quant_strat[i].P_c.min_fx = -ONE_IN_Q27;//.5* Q28 + } + } return; } @@ -402,22 +397,11 @@ void ivas_map_prior_coeffs_quant( } #endif -void ivas_spar_quant_dtx_init_fx( - ivas_spar_md_t *spar_md, - Word32 *min_max) -{ - spar_md->min_max_fx[0] = min_max[0]; - spar_md->min_max_fx[1] = min_max[1]; - - return; -} - /*-----------------------------------------------------------------------------------------* * Function ivas_spar_quant_dtx_init() * * Init SPAR MD with minmax vals *-----------------------------------------------------------------------------------------*/ - void ivas_spar_quant_dtx_init( ivas_spar_md_t *spar_md, float *min_max ) @@ -427,7 +411,7 @@ void ivas_spar_quant_dtx_init( return; } -#if 0 + void ivas_spar_quant_dtx_init_fx( ivas_spar_md_t *spar_md, Word32 *min_max) @@ -437,7 +421,7 @@ void ivas_spar_quant_dtx_init_fx( return; } -#endif + /*-----------------------------------------------------------------------------------------* * Function ivas_copy_band_coeffs_idx_to_arr() * @@ -496,7 +480,6 @@ void ivas_copy_band_coeffs_idx_to_arr( * * clear band coeffs array in SPAR MD *-----------------------------------------------------------------------------------------*/ - void ivas_clear_band_coeffs( ivas_band_coeffs_t *pband_coeffs, const uint16_t num_bands ) @@ -506,22 +489,17 @@ void ivas_clear_band_coeffs( for ( i = 0; i < num_bands; i++ ) { set_zero( (float *) pband_coeffs[i].C_re, ( IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS ) * ( IVAS_SPAR_MAX_DMX_CHS - 1 ) ); - set32_fx( (Word32 *) pband_coeffs[i].C_re_fx, 0, ( IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS ) * ( IVAS_SPAR_MAX_DMX_CHS - 1 ) ); set_zero( (float *) pband_coeffs[i].P_re, ( IVAS_SPAR_MAX_CH - 1 ) ); - set32_fx( (Word32 *) pband_coeffs[i].P_re_fx, 0, ( IVAS_SPAR_MAX_CH - 1 ) ); set_zero( (float *) pband_coeffs[i].C_quant_re, ( IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS ) * ( IVAS_SPAR_MAX_DMX_CHS - 1 ) ); - set32_fx( (Word32 *) pband_coeffs[i].C_quant_re_fx, 0, ( IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS ) * ( IVAS_SPAR_MAX_DMX_CHS - 1 ) ); set_zero( (float *) pband_coeffs[i].P_quant_re, ( IVAS_SPAR_MAX_CH - 1 ) ); - set32_fx( (Word32 *) pband_coeffs[i].P_quant_re_fx, 0, ( IVAS_SPAR_MAX_CH - 1 ) ); set_zero( pband_coeffs[i].pred_re, ( IVAS_SPAR_MAX_CH - 1 ) ); - set32_fx( pband_coeffs[i].pred_re_fx, 0, ( IVAS_SPAR_MAX_CH - 1 ) ); set_zero( pband_coeffs[i].pred_quant_re, ( IVAS_SPAR_MAX_CH - 1 ) ); - set32_fx( pband_coeffs[i].pred_quant_re_fx, 0, ( IVAS_SPAR_MAX_CH - 1 ) ); + } return; } -#if 0 + void ivas_clear_band_coeffs_fx( ivas_band_coeffs_t *pband_coeffs, const UWord16 num_bands) @@ -540,7 +518,7 @@ void ivas_clear_band_coeffs_fx( return; } -#endif + /*-----------------------------------------------------------------------------------------* * Function ivas_clear_band_coeff_idx() * diff --git a/lib_com/ivas_stat_com.h b/lib_com/ivas_stat_com.h index 5636c4b64..3b70fb63b 100644 --- a/lib_com/ivas_stat_com.h +++ b/lib_com/ivas_stat_com.h @@ -187,8 +187,11 @@ typedef struct ivas_band_coeffs_t float C_quant_re[IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS][IVAS_SPAR_MAX_DMX_CHS - 1]; float P_quant_re[IVAS_SPAR_MAX_CH - 1]; + Word16 q_pred_re_fx; Word32 pred_re_fx[IVAS_SPAR_MAX_CH - 1]; + 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 C_quant_re_fx[IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS][IVAS_SPAR_MAX_DMX_CHS - 1]; diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index 34be75e2e..23ad8c10c 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -3673,6 +3673,7 @@ void ivas_dirac_dec_render_sf_fx( IF( EQ_16( hDirAC->hConfig->dec_param_estim, FALSE ) ) { mvr2r( hSpatParamRendCom->diffuseness_vector[hSpatParamRendCom->render_to_md_map[hSpatParamRendCom->subframes_rendered]], diffuseness_vector, hSpatParamRendCom->num_freq_bands ); + //Copy32( hSpatParamRendCom->diffuseness_vector_fx[hSpatParamRendCom->render_to_md_map[hSpatParamRendCom->subframes_rendered]], diffuseness_vector_fx, hSpatParamRendCom->num_freq_bands ); floatToFixed_arrL32( diffuseness_vector, hSpatParamRendCom->diffuseness_vector_fx[hSpatParamRendCom->render_to_md_map[hSpatParamRendCom->subframes_rendered]], Q30, hSpatParamRendCom->num_freq_bands ); md_idx = hSpatParamRendCom->render_to_md_map[hSpatParamRendCom->subframes_rendered]; } diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index b962184bb..53e5ce546 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -182,7 +182,11 @@ ivas_error ivas_dec_setup( num_bits_read = add(num_bits_read, SBA_ORDER_BITS); IF ( GT_16(st_ivas->ini_frame , 0) && NE_32(ivas_total_brate, st_ivas->last_active_ivas_total_brate) && GT_32(ivas_total_brate, IVAS_SID_5k2 )) { +#ifndef IVAS_FLOAT_FIXED IF ( ( error = ivas_sba_dec_reconfigure( st_ivas, nSamplesRendered, data ) ) != IVAS_ERR_OK ) +#else + IF ( ( error = ivas_sba_dec_reconfigure_fx( st_ivas, nSamplesRendered, data ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -267,7 +271,7 @@ ivas_error ivas_dec_setup( numch_out = hSpar->hFbMixer->fb_cfg->num_out_chans; numch_in = hSpar->hFbMixer->fb_cfg->num_in_chans; num_md_sub_frames = ivas_get_spar_dec_md_num_subframes( st_ivas->sba_order, hDecoderConfig->ivas_total_brate, st_ivas->last_active_ivas_total_brate ); - +#if 0 for ( int l = 0; l < numch_out; l++ ) { for ( int j = 0; j < numch_in; j++ ) @@ -291,6 +295,7 @@ ivas_error ivas_dec_setup( } } } +#endif for ( Word16 in_ch = 0; in_ch < numch_in; in_ch++ ) { for ( Word16 i = 0; i < st_ivas->cldfbAnaDec[in_ch]->p_filter_length - st_ivas->cldfbAnaDec[in_ch]->no_channels; i++ ) @@ -351,6 +356,7 @@ ivas_error ivas_dec_setup( st_ivas->cldfbAnaDec[in_ch]->cldfb_state[i] = ((float)(st_ivas->cldfbAnaDec[in_ch]->cldfb_state_fx[i]) / (1LL << (Q11))); /*Rounding off*/ } } +#if 0 FOR(int m = 0; m < MAX_PARAM_SPATIAL_SUBFRAMES + 1; m++) { FOR(int j = 0; j < IVAS_MAX_FB_MIXER_OUT_CH; j++) @@ -364,6 +370,7 @@ ivas_error ivas_dec_setup( } } } +#endif // fix2float (to be cleaned) IF((LT_32(hDecoderConfig->ivas_total_brate, IVAS_24k4)) && ((EQ_16(hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_HOA2)) || (EQ_16(hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_HOA3)))) { @@ -683,7 +690,11 @@ ivas_error ivas_dec_setup( IF ( GT_16(st_ivas->ini_frame, 0) && NE_32(ivas_total_brate, st_ivas->last_active_ivas_total_brate )) { +#ifndef IVAS_FLOAT_FIXED IF ( ( error = ivas_sba_dec_reconfigure( st_ivas, nSamplesRendered, data ) ) != IVAS_ERR_OK ) +#else + IF ( ( error = ivas_sba_dec_reconfigure_fx( st_ivas, nSamplesRendered, data ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -810,7 +821,11 @@ ivas_error ivas_dec_setup( st_ivas->hDecoderConfig->ivas_total_brate = IVAS_24k4; } +#ifndef IVAS_FLOAT_FIXED IF ( ( error = ivas_sba_dec_reconfigure( st_ivas, nSamplesRendered, data ) ) != IVAS_ERR_OK ) +#else + IF ( ( error = ivas_sba_dec_reconfigure_fx( st_ivas, nSamplesRendered, data ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -1552,7 +1567,7 @@ ivas_error ivas_init_decoder_fx( return error; } - IF ( ( error = ivas_spar_dec_open( st_ivas, 0 ) ) != IVAS_ERR_OK ) + IF ( ( error = ivas_spar_dec_open_fx( st_ivas, 0 ) ) != IVAS_ERR_OK ) { return error; } @@ -1705,7 +1720,7 @@ ivas_error ivas_init_decoder_fx( return error; } - IF ( ( error = ivas_spar_dec_open( st_ivas, 0 ) ) != IVAS_ERR_OK ) + IF ( ( error = ivas_spar_dec_open_fx( st_ivas, 0 ) ) != IVAS_ERR_OK ) { return error; } @@ -3630,7 +3645,14 @@ void destroy_core_dec( ) { #ifdef IVAS_FLOAT_FIXED - destroy_cldfb_decoder_ivas_fx( hCoreCoder ); + IF( EQ_16( hCoreCoder->element_mode, EVS_MONO ) ) + { + destroy_cldfb_decoder_fx( hCoreCoder ); + } + ELSE + { + destroy_cldfb_decoder_ivas_fx( hCoreCoder ); + } #else destroy_cldfb_decoder_flt( hCoreCoder ); #endif // IVAS_FLOAT_FIXED diff --git a/lib_dec/ivas_ism_dec.c b/lib_dec/ivas_ism_dec.c index f684450d4..399e6508d 100644 --- a/lib_dec/ivas_ism_dec.c +++ b/lib_dec/ivas_ism_dec.c @@ -515,7 +515,8 @@ static ivas_error ivas_ism_bitrate_switching_dec( numch_out = hSpar->hFbMixer->fb_cfg->num_out_chans; numch_in = hSpar->hFbMixer->fb_cfg->num_in_chans; num_md_sub_frames = ivas_get_spar_dec_md_num_subframes( st_ivas->sba_order, hDecoderConfig->ivas_total_brate, st_ivas->last_active_ivas_total_brate ); - + hSpar->hMdDec->Q_mixer_mat = q1; +#if 0 for ( int l = 0; l < numch_out; l++ ) { for ( int j = 0; j < numch_in; j++ ) @@ -539,6 +540,7 @@ static ivas_error ivas_ism_bitrate_switching_dec( } } } +#endif for ( Word16 in_ch = 0; in_ch < numch_in; in_ch++ ) { for ( Word16 i = 0; i < st_ivas->cldfbAnaDec[in_ch]->p_filter_length - st_ivas->cldfbAnaDec[in_ch]->no_channels; i++ ) @@ -591,6 +593,7 @@ static ivas_error ivas_ism_bitrate_switching_dec( st_ivas->cldfbAnaDec[in_ch]->cldfb_state[i] = ( (float) ( st_ivas->cldfbAnaDec[in_ch]->cldfb_state_fx[i] ) / ( 1LL << ( Q11 ) ) ); /*Rounding off*/ } } +#if 0 FOR( int m = 0; m < MAX_PARAM_SPATIAL_SUBFRAMES + 1; m++ ) { FOR( int j = 0; j < IVAS_MAX_FB_MIXER_OUT_CH; j++ ) @@ -604,6 +607,7 @@ static ivas_error ivas_ism_bitrate_switching_dec( } } } +#endif // fix2float (to be cleaned) IF( ( LT_32( hDecoderConfig->ivas_total_brate, IVAS_24k4 ) ) && ( ( EQ_16( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_HOA2 ) ) || ( EQ_16( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_HOA3 ) ) ) ) { diff --git a/lib_dec/ivas_jbm_dec.c b/lib_dec/ivas_jbm_dec.c index 385c0505b..86b499d06 100644 --- a/lib_dec/ivas_jbm_dec.c +++ b/lib_dec/ivas_jbm_dec.c @@ -622,6 +622,7 @@ ivas_error ivas_jbm_dec_tc( hSpar->hMdDec->Q_mixer_mat = 31; Word16 num_in_ch; num_in_ch = hSpar->hMdDec->spar_md_cfg.num_umx_chs; +#if 0 FOR( i_ts = 0; i_ts < num_md_sub_frames; i_ts++ ) { FOR( i = 0; i < num_out_ch; i++ ) @@ -695,6 +696,7 @@ ivas_error ivas_jbm_dec_tc( } } } +#endif #endif ivas_agc_dec_process_fx( st_ivas->hSpar->hAgcDec, ( p_output_fx ), ( p_output_fx ), st_ivas->hSpar->hMdDec->spar_md_cfg.nchan_transport, output_frame ); @@ -704,7 +706,7 @@ ivas_error ivas_jbm_dec_tc( } ivas_spar_dec_gen_umx_mat_fx( st_ivas->hSpar->hMdDec, st_ivas->nchan_transport, IVAS_MAX_NUM_BANDS, st_ivas->bfi, num_md_sub_frames ); -#if 1 /*Fixed to float changes */ +#if 0 /*Fixed to float changes */ FOR( i_ts = 0; i_ts < num_md_sub_frames; i_ts++ ) { @@ -814,19 +816,10 @@ ivas_error ivas_jbm_dec_tc( hCPE->hStereoDft->q_ap_fade_mem_fx = hCPE->hStereoDft->q_dft; floatToFixed_arrL( &hCPE->hStereoDft->td_gain[0], &hCPE->hStereoDft->td_gain_fx[0], Q31, sizeof( hCPE->hStereoDft->td_gain_fx ) / sizeof( hCPE->hStereoDft->td_gain_fx[0] ) ); - floatToFixed_arrL( &st_ivas->hSpar->hMdDec->mixer_mat_prev[0][0][0][0], &st_ivas->hSpar->hMdDec->mixer_mat_prev_fx[0][0][0][0], Q31, sizeof( st_ivas->hSpar->hMdDec->mixer_mat_prev_fx ) / sizeof( st_ivas->hSpar->hMdDec->mixer_mat_prev_fx[0][0][0][0] ) ); - } - for ( int ii = 0; ii < st_ivas->hSpar->hMdDec->mix_mat_dim_0_1; ii++ ) - { - for ( int jj = 0; jj < st_ivas->hSpar->hMdDec->mix_mat_dim_0_1; jj++ ) - { - floatToFixed_arrL( &st_ivas->hSpar->hMdDec->mixer_mat[ii][jj][0], - &st_ivas->hSpar->hMdDec->mixer_mat_fx[ii][jj][0], - Q31, - st_ivas->hSpar->hMdDec->mix_mat_dim_2 ); - } + //floatToFixed_arrL( &st_ivas->hSpar->hMdDec->mixer_mat_prev[0][0][0][0], &st_ivas->hSpar->hMdDec->mixer_mat_prev_fx[0][0][0][0], Q31, sizeof( st_ivas->hSpar->hMdDec->mixer_mat_prev_fx ) / sizeof( st_ivas->hSpar->hMdDec->mixer_mat_prev_fx[0][0][0][0] ) ); } - FOR( int ii = 0; ii < CPE_CHANNELS; ii++ ) + st_ivas->hSpar->hMdDec->Q_mixer_mat = 30; + for ( int ii = 0; ii < CPE_CHANNELS; ii++ ) { scale_sig32( hCPE->output_mem_fx[ii], NS2SA_fx2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); hCPE->q_output_mem_fx[ii] = hCPE->hStereoDft->q_dft; @@ -834,6 +827,7 @@ ivas_error ivas_jbm_dec_tc( floatToFixed_arrL( &hCPE->prev_synth[0][0], &hCPE->prev_synth_fx[0][0], hCPE->q_prev_synth_fx, sizeof( hCPE->prev_synth ) / sizeof( hCPE->prev_synth[0][0] ) ); ivas_sba_dirac_stereo_dec_fx( st_ivas, p_output_fx, output_frame, st_ivas->ivas_format == MC_FORMAT ); + FOR( i = 0; i < 2; i++ ) { Scale_sig32( p_output_fx[i], L_FRAME48k, negate( s ) ); @@ -878,19 +872,9 @@ ivas_error ivas_jbm_dec_tc( hCPE->hStereoDft->q_ap_fade_mem_fx = Q11; fixedToFloat_arrL( &hCPE->hStereoDft->td_gain_fx[0], &hCPE->hStereoDft->td_gain[0], Q31, sizeof( hCPE->hStereoDft->td_gain_fx ) / sizeof( hCPE->hStereoDft->td_gain_fx[0] ) ); - fixedToFloat_arrL( &st_ivas->hSpar->hMdDec->mixer_mat_prev_fx[0][0][0][0], &st_ivas->hSpar->hMdDec->mixer_mat_prev[0][0][0][0], Q31, sizeof( st_ivas->hSpar->hMdDec->mixer_mat_prev_fx ) / sizeof( st_ivas->hSpar->hMdDec->mixer_mat_prev_fx[0][0][0][0] ) ); } - for ( int ii = 0; ii < st_ivas->hSpar->hMdDec->mix_mat_dim_0_1; ii++ ) - { - for ( int jj = 0; jj < st_ivas->hSpar->hMdDec->mix_mat_dim_0_1; jj++ ) - { - fixedToFloat_arrL( &st_ivas->hSpar->hMdDec->mixer_mat_fx[ii][jj][0], - &st_ivas->hSpar->hMdDec->mixer_mat[ii][jj][0], - Q31, - st_ivas->hSpar->hMdDec->mix_mat_dim_2 ); - } - } - FOR( int ii = 0; ii < CPE_CHANNELS; ii++ ) + st_ivas->hSpar->hMdDec->Q_mixer_mat = 30; + for ( int ii = 0; ii < CPE_CHANNELS; ii++ ) { scale_sig32( hCPE->output_mem_fx[ii], NS2SA_fx2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); hCPE->q_output_mem_fx[ii] = Q11; @@ -935,6 +919,7 @@ ivas_error ivas_jbm_dec_tc( hSpar->hMdDec->Q_mixer_mat = 31; Word16 num_in_ch; num_in_ch = hSpar->hMdDec->spar_md_cfg.num_umx_chs; +#if 0 FOR( i_ts = 0; i_ts < num_md_sub_frames; i_ts++ ) { FOR( i = 0; i < num_out_ch; i++ ) @@ -1008,9 +993,11 @@ ivas_error ivas_jbm_dec_tc( } } } +#endif #endif ivas_sba_mix_matrix_determiner_fx( st_ivas->hSpar, p_output_fx, st_ivas->bfi, nchan_remapped, output_frame, num_md_sub_frames ); #if 1 /*Fixed to float changes */ +#if 0 FOR( i_ts = 0; i_ts < num_md_sub_frames; i_ts++ ) { FOR( i = 0; i < num_out_ch; i++ ) @@ -1024,6 +1011,7 @@ ivas_error ivas_jbm_dec_tc( } } } +#endif FOR( Word16 c = 0; c < nchan_transport; c++ ) { Scale_sig32( p_output_fx[c], output_frame, 11 ); @@ -1515,6 +1503,7 @@ ivas_error ivas_jbm_dec_tc( hSpar->hMdDec->Q_mixer_mat = 31; Word16 num_in_ch; num_in_ch = hSpar->hMdDec->spar_md_cfg.num_umx_chs; +#if 0 FOR( i_ts = 0; i_ts < num_md_sub_frames; i_ts++ ) { FOR( i = 0; i < num_out_ch; i++ ) @@ -1588,6 +1577,7 @@ ivas_error ivas_jbm_dec_tc( } } } +#endif #endif ivas_agc_dec_process_fx( st_ivas->hSpar->hAgcDec, ( p_output_fx + sba_ch_idx ), ( p_output_fx + sba_ch_idx ), st_ivas->hSpar->hMdDec->spar_md_cfg.nchan_transport, output_frame ); @@ -1596,9 +1586,12 @@ ivas_error ivas_jbm_dec_tc( ivas_pca_dec_fx( st_ivas->hSpar->hPCA, output_frame, st_ivas->hSpar->hMdDec->spar_md_cfg.nchan_transport, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->hDecoderConfig->last_ivas_total_brate, st_ivas->bfi, &p_output_fx[sba_ch_idx] ); } +#ifndef IVAS_FLOAT_FIXED + ivas_spar_dec_gen_umx_mat( st_ivas->hSpar->hMdDec, st_ivas->nchan_transport, IVAS_MAX_NUM_BANDS, st_ivas->bfi, ivas_get_spar_dec_md_num_subframes( st_ivas->sba_order, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->last_active_ivas_total_brate ) ); +#else ivas_spar_dec_gen_umx_mat_fx( st_ivas->hSpar->hMdDec, st_ivas->nchan_transport, IVAS_MAX_NUM_BANDS, st_ivas->bfi, ivas_get_spar_dec_md_num_subframes( st_ivas->sba_order, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->last_active_ivas_total_brate ) ); -#if 1 /*Fixed to float changes */ - +#endif +#if 0 /* Fixed to float changes*/ FOR( i_ts = 0; i_ts < num_md_sub_frames; i_ts++ ) { FOR( i = 0; i < num_out_ch; i++ ) @@ -1703,9 +1696,11 @@ ivas_error ivas_jbm_dec_tc( hCPE->hStereoDft->q_ap_fade_mem_fx = hCPE->hStereoDft->q_dft; floatToFixed_arrL( &hCPE->hStereoDft->td_gain[0], &hCPE->hStereoDft->td_gain_fx[0], Q31, sizeof( hCPE->hStereoDft->td_gain_fx ) / sizeof( hCPE->hStereoDft->td_gain_fx[0] ) ); - floatToFixed_arrL( &st_ivas->hSpar->hMdDec->mixer_mat_prev[0][0][0][0], &st_ivas->hSpar->hMdDec->mixer_mat_prev_fx[0][0][0][0], Q31, sizeof( st_ivas->hSpar->hMdDec->mixer_mat_prev_fx ) / sizeof( st_ivas->hSpar->hMdDec->mixer_mat_prev_fx[0][0][0][0] ) ); + //floatToFixed_arrL( &st_ivas->hSpar->hMdDec->mixer_mat_prev[0][0][0][0], &st_ivas->hSpar->hMdDec->mixer_mat_prev_fx[0][0][0][0], Q31, sizeof( st_ivas->hSpar->hMdDec->mixer_mat_prev_fx ) / sizeof( st_ivas->hSpar->hMdDec->mixer_mat_prev_fx[0][0][0][0] ) ); } - for ( int ii = 0; ii < st_ivas->hSpar->hMdDec->mix_mat_dim_0_1; ii++ ) + st_ivas->hSpar->hMdDec->Q_mixer_mat = Q30; +#if 0 + for (int ii = 0; ii < st_ivas->hSpar->hMdDec->mix_mat_dim_0_1; ii++) { for ( int jj = 0; jj < st_ivas->hSpar->hMdDec->mix_mat_dim_0_1; jj++ ) { @@ -1715,6 +1710,7 @@ ivas_error ivas_jbm_dec_tc( st_ivas->hSpar->hMdDec->mix_mat_dim_2 ); } } +#endif FOR( int ii = 0; ii < CPE_CHANNELS; ii++ ) { scale_sig32( hCPE->output_mem_fx[ii], NS2SA_fx2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); @@ -1764,19 +1760,10 @@ ivas_error ivas_jbm_dec_tc( hCPE->hStereoDft->q_ap_fade_mem_fx = Q11; fixedToFloat_arrL( &hCPE->hStereoDft->td_gain_fx[0], &hCPE->hStereoDft->td_gain[0], Q31, sizeof( hCPE->hStereoDft->td_gain_fx ) / sizeof( hCPE->hStereoDft->td_gain_fx[0] ) ); - fixedToFloat_arrL( &st_ivas->hSpar->hMdDec->mixer_mat_prev_fx[0][0][0][0], &st_ivas->hSpar->hMdDec->mixer_mat_prev[0][0][0][0], Q31, sizeof( st_ivas->hSpar->hMdDec->mixer_mat_prev_fx ) / sizeof( st_ivas->hSpar->hMdDec->mixer_mat_prev_fx[0][0][0][0] ) ); + //fixedToFloat_arrL( &st_ivas->hSpar->hMdDec->mixer_mat_prev_fx[0][0][0][0], &st_ivas->hSpar->hMdDec->mixer_mat_prev[0][0][0][0], Q31, sizeof( st_ivas->hSpar->hMdDec->mixer_mat_prev_fx ) / sizeof( st_ivas->hSpar->hMdDec->mixer_mat_prev_fx[0][0][0][0] ) ); } - for ( int ii = 0; ii < st_ivas->hSpar->hMdDec->mix_mat_dim_0_1; ii++ ) - { - for ( int jj = 0; jj < st_ivas->hSpar->hMdDec->mix_mat_dim_0_1; jj++ ) - { - fixedToFloat_arrL( &st_ivas->hSpar->hMdDec->mixer_mat_fx[ii][jj][0], - &st_ivas->hSpar->hMdDec->mixer_mat[ii][jj][0], - Q31, - st_ivas->hSpar->hMdDec->mix_mat_dim_2 ); - } - } - FOR( int ii = 0; ii < CPE_CHANNELS; ii++ ) + st_ivas->hSpar->hMdDec->Q_mixer_mat = 30; + FOR (int ii = 0; ii < CPE_CHANNELS; ii++) { scale_sig32( hCPE->output_mem_fx[ii], NS2SA_fx2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); hCPE->q_output_mem_fx[ii] = Q11; @@ -1816,6 +1803,7 @@ ivas_error ivas_jbm_dec_tc( hSpar->hMdDec->Q_mixer_mat = 31; Word16 num_in_ch; num_in_ch = hSpar->hMdDec->spar_md_cfg.num_umx_chs; +#if 0 FOR( i_ts = 0; i_ts < num_md_sub_frames; i_ts++ ) { FOR( i = 0; i < num_out_ch; i++ ) @@ -1889,9 +1877,10 @@ ivas_error ivas_jbm_dec_tc( } } } +#endif #endif ivas_sba_mix_matrix_determiner_fx( st_ivas->hSpar, &p_output_fx[sba_ch_idx], st_ivas->bfi, nchan_remapped, output_frame, num_md_sub_frames ); -#if 1 /*Fixed to float changes */ +#if 0 /*Fixed to float changes */ FOR( i_ts = 0; i_ts < num_md_sub_frames; i_ts++ ) { FOR( i = 0; i < num_out_ch; i++ ) @@ -1905,6 +1894,8 @@ ivas_error ivas_jbm_dec_tc( } } } +#endif +#if 1 FOR( Word16 c = 0; c < nchan_transport; c++ ) { Scale_sig32( p_output_fx[sba_ch_idx + c], output_frame, Q11 ); @@ -2847,17 +2838,20 @@ ivas_error ivas_jbm_dec_tc( } IF( st_ivas->hSpar != NULL ) { - floatToFixed_arrL( &st_ivas->hSpar->hMdDec->mixer_mat_prev[0][0][0][0], &st_ivas->hSpar->hMdDec->mixer_mat_prev_fx[0][0][0][0], Q31, sizeof( st_ivas->hSpar->hMdDec->mixer_mat_prev_fx ) / sizeof( st_ivas->hSpar->hMdDec->mixer_mat_prev_fx[0][0][0][0] ) ); - for ( int ii = 0; ii < st_ivas->hSpar->hMdDec->mix_mat_dim_0_1; ii++ ) + //floatToFixed_arrL(&st_ivas->hSpar->hMdDec->mixer_mat_prev[0][0][0][0], &st_ivas->hSpar->hMdDec->mixer_mat_prev_fx[0][0][0][0], Q31, sizeof(st_ivas->hSpar->hMdDec->mixer_mat_prev_fx) / sizeof(st_ivas->hSpar->hMdDec->mixer_mat_prev_fx[0][0][0][0])); + st_ivas->hSpar->hMdDec->Q_mixer_mat = 30; +#if 0 + for (int ii = 0; ii < st_ivas->hSpar->hMdDec->mix_mat_dim_0_1; ii++) { - for ( int jj = 0; jj < st_ivas->hSpar->hMdDec->mix_mat_dim_0_1; jj++ ) - { - floatToFixed_arrL( &st_ivas->hSpar->hMdDec->mixer_mat[ii][jj][0], + for (int jj = 0; jj < st_ivas->hSpar->hMdDec->mix_mat_dim_0_1; jj++) + { + floatToFixed_arrL(&st_ivas->hSpar->hMdDec->mixer_mat[ii][jj][0], &st_ivas->hSpar->hMdDec->mixer_mat_fx[ii][jj][0], Q31, st_ivas->hSpar->hMdDec->mix_mat_dim_2 ); } } +#endif } FOR( int ii = 0; ii < CPE_CHANNELS; ii++ ) { @@ -2912,11 +2906,13 @@ ivas_error ivas_jbm_dec_tc( } IF( st_ivas->hSpar != NULL ) { - fixedToFloat_arrL( &st_ivas->hSpar->hMdDec->mixer_mat_prev_fx[0][0][0][0], &st_ivas->hSpar->hMdDec->mixer_mat_prev[0][0][0][0], Q31, sizeof( st_ivas->hSpar->hMdDec->mixer_mat_prev_fx ) / sizeof( st_ivas->hSpar->hMdDec->mixer_mat_prev_fx[0][0][0][0] ) ); - for ( int ii = 0; ii < st_ivas->hSpar->hMdDec->mix_mat_dim_0_1; ii++ ) + //fixedToFloat_arrL(&st_ivas->hSpar->hMdDec->mixer_mat_prev_fx[0][0][0][0], &st_ivas->hSpar->hMdDec->mixer_mat_prev[0][0][0][0], Q31, sizeof(st_ivas->hSpar->hMdDec->mixer_mat_prev_fx) / sizeof(st_ivas->hSpar->hMdDec->mixer_mat_prev_fx[0][0][0][0])); + st_ivas->hSpar->hMdDec->Q_mixer_mat = 31; + for (int ii = 0; ii < st_ivas->hSpar->hMdDec->mix_mat_dim_0_1; ii++) { fixedToFloat_arrL( &hCPE->hStereoDft->td_gain_fx[0], &hCPE->hStereoDft->td_gain[0], Q31, sizeof( hCPE->hStereoDft->td_gain_fx ) / sizeof( hCPE->hStereoDft->td_gain_fx[0] ) ); } +#if 0 IF( st_ivas->hSpar != NULL ) { fixedToFloat_arrL( &st_ivas->hSpar->hMdDec->mixer_mat_prev_fx[0][0][0][0], &st_ivas->hSpar->hMdDec->mixer_mat_prev[0][0][0][0], Q31, sizeof( st_ivas->hSpar->hMdDec->mixer_mat_prev_fx ) / sizeof( st_ivas->hSpar->hMdDec->mixer_mat_prev_fx[0][0][0][0] ) ); @@ -2931,6 +2927,7 @@ ivas_error ivas_jbm_dec_tc( } } } +#endif FOR( int ii = 0; ii < CPE_CHANNELS; ii++ ) { scale_sig32( hCPE->output_mem_fx[ii], NS2SA_fx2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); @@ -3803,10 +3800,10 @@ ivas_error ivas_jbm_dec_tc( *--------------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED void ivas_jbm_dec_feed_tc_to_renderer( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - const int16_t nSamplesForRendering, /* i : number of TC samples available for rendering */ - int16_t *nSamplesResidual, /* o : number of samples not fitting into the renderer grid and buffer for the next call*/ - float *data /* i : transport channels */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const int16_t nSamplesForRendering, /* i : number of TC samples available for rendering */ + int16_t *nSamplesResidual, /* o : number of samples not fitting into the renderer grid and buffer for the next call*/ + float *data /* i : transport channels */ ) { float data_f[MAX_CLDFB_DIGEST_CHANNELS][MAX_JBM_L_FRAME48k] = { 0 }; /* 'float' buffer for transport channels that will be directly converted with the CLDFB */ @@ -3929,6 +3926,7 @@ void ivas_jbm_dec_feed_tc_to_renderer( Word16 Q_C_re_fx = 31, Q_P_re_fx = 31; hSpar->hMdDec->Q_mixer_mat = 31; num_in_ch = hSpar->hMdDec->spar_md_cfg.num_umx_chs; +#if 0 FOR( i_ts = 0; i_ts < num_md_sub_frames; i_ts++ ) { FOR( i = 0; i < num_out_ch; i++ ) @@ -4002,6 +4000,7 @@ void ivas_jbm_dec_feed_tc_to_renderer( } } } +#endif IF( hSpar->hMdDec->td_decorr_flag && !( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) ) @@ -4075,6 +4074,7 @@ void ivas_jbm_dec_feed_tc_to_renderer( #if 1 if (st_ivas->ivas_format == SBA_FORMAT || st_ivas->ivas_format == SBA_ISM_FORMAT) { +#if 0 //ndef IVAS_FLOAT_FIXED_TO_BE_REMOVED FOR(i_ts = 0; i_ts < num_md_sub_frames; i_ts++) { FOR(i = 0; i < num_out_ch; i++) @@ -4088,6 +4088,7 @@ void ivas_jbm_dec_feed_tc_to_renderer( } } } +#endif IF(hSpar->hMdDec->td_decorr_flag && !(EQ_16(st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC) || EQ_16(st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM))) { @@ -4180,6 +4181,7 @@ void ivas_jbm_dec_feed_tc_to_renderer( Word16 Q_C_re_fx = 31, Q_P_re_fx = 31; hSpar->hMdDec->Q_mixer_mat = 31; num_in_ch = hSpar->hMdDec->spar_md_cfg.num_umx_chs; +#if 0 FOR( i_ts = 0; i_ts < num_md_sub_frames; i_ts++ ) { FOR( i = 0; i < num_out_ch; i++ ) @@ -4253,6 +4255,7 @@ void ivas_jbm_dec_feed_tc_to_renderer( } } } +#endif IF( hSpar->hMdDec->td_decorr_flag && !( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) ) @@ -4325,6 +4328,7 @@ void ivas_jbm_dec_feed_tc_to_renderer( #if 1 if ( st_ivas->ivas_format == SBA_FORMAT || st_ivas->ivas_format == SBA_ISM_FORMAT ) { +#if 0 FOR( i_ts = 0; i_ts < num_md_sub_frames; i_ts++ ) { FOR( i = 0; i < num_out_ch; i++ ) @@ -4338,6 +4342,7 @@ void ivas_jbm_dec_feed_tc_to_renderer( } } } +#endif IF( hSpar->hMdDec->td_decorr_flag && !( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) ) { @@ -4406,6 +4411,7 @@ void ivas_jbm_dec_feed_tc_to_renderer( Word16 Q_C_re_fx = 31, Q_P_re_fx = 31; hSpar->hMdDec->Q_mixer_mat = 31; num_in_ch = hSpar->hMdDec->spar_md_cfg.num_umx_chs; +#if 0 FOR( i_ts = 0; i_ts < num_md_sub_frames; i_ts++ ) { FOR( i = 0; i < num_out_ch; i++ ) @@ -4479,6 +4485,7 @@ void ivas_jbm_dec_feed_tc_to_renderer( } } } +#endif IF( hSpar->hMdDec->td_decorr_flag && !( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) ) @@ -4551,6 +4558,7 @@ void ivas_jbm_dec_feed_tc_to_renderer( #if 1 if ( st_ivas->ivas_format == SBA_FORMAT || st_ivas->ivas_format == SBA_ISM_FORMAT ) { +#if 0 FOR( i_ts = 0; i_ts < num_md_sub_frames; i_ts++ ) { FOR( i = 0; i < num_out_ch; i++ ) @@ -4564,6 +4572,7 @@ void ivas_jbm_dec_feed_tc_to_renderer( } } } +#endif IF( hSpar->hMdDec->td_decorr_flag && !( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) ) { @@ -4634,6 +4643,7 @@ void ivas_jbm_dec_feed_tc_to_renderer( Word16 Q_C_re_fx = 31, Q_P_re_fx = 31; hSpar->hMdDec->Q_mixer_mat = 31; num_in_ch = hSpar->hMdDec->spar_md_cfg.num_umx_chs; +#if 0 FOR( i_ts = 0; i_ts < num_md_sub_frames; i_ts++ ) { FOR( i = 0; i < num_out_ch; i++ ) @@ -4707,6 +4717,7 @@ void ivas_jbm_dec_feed_tc_to_renderer( } } } +#endif IF( hSpar->hMdDec->td_decorr_flag && !( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) ) @@ -4779,6 +4790,7 @@ void ivas_jbm_dec_feed_tc_to_renderer( #if 1 if ( st_ivas->ivas_format == SBA_FORMAT || st_ivas->ivas_format == SBA_ISM_FORMAT ) { +#if 0 FOR( i_ts = 0; i_ts < num_md_sub_frames; i_ts++ ) { FOR( i = 0; i < num_out_ch; i++ ) @@ -4792,6 +4804,7 @@ void ivas_jbm_dec_feed_tc_to_renderer( } } } +#endif IF( hSpar->hMdDec->td_decorr_flag && !( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) ) { @@ -4985,6 +4998,7 @@ void ivas_jbm_dec_feed_tc_to_renderer( Word16 Q_C_re_fx = 31, Q_P_re_fx = 31; hSpar->hMdDec->Q_mixer_mat = 31; num_in_ch = hSpar->hMdDec->spar_md_cfg.num_umx_chs; +#if 0 FOR( i_ts = 0; i_ts < num_md_sub_frames; i_ts++ ) { FOR( i = 0; i < num_out_ch; i++ ) @@ -5058,6 +5072,7 @@ void ivas_jbm_dec_feed_tc_to_renderer( } } } +#endif IF( hSpar->hMdDec->td_decorr_flag && !( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) ) @@ -5130,6 +5145,7 @@ void ivas_jbm_dec_feed_tc_to_renderer( #if 1 if ( st_ivas->ivas_format == SBA_FORMAT || st_ivas->ivas_format == SBA_ISM_FORMAT ) { +#if 0 FOR( i_ts = 0; i_ts < num_md_sub_frames; i_ts++ ) { FOR( i = 0; i < num_out_ch; i++ ) @@ -5143,6 +5159,7 @@ void ivas_jbm_dec_feed_tc_to_renderer( } } } +#endif IF( hSpar->hMdDec->td_decorr_flag && !( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) ) { @@ -5827,6 +5844,8 @@ ivas_error ivas_jbm_dec_render( floatToFixed_arr32( st_ivas->hTcBuffer->tc[i], st_ivas->hTcBuffer->tc_fx[i], Q11, st_ivas->hTcBuffer->n_samples_available ); } Word16 q1 = 30, q2 = 30; + hSpar->hMdDec->Q_mixer_mat = 30; +#if 0 for ( int l = 0; l < numch_out; l++ ) { for ( j = 0; j < numch_in; j++ ) @@ -5850,6 +5869,7 @@ ivas_error ivas_jbm_dec_render( } } } +#endif for ( Word16 in_ch = 0; in_ch < numch_in; in_ch++ ) { for ( i = 0; i < st_ivas->cldfbAnaDec[in_ch]->p_filter_length - st_ivas->cldfbAnaDec[in_ch]->no_channels; i++ ) @@ -5857,14 +5877,14 @@ ivas_error ivas_jbm_dec_render( st_ivas->cldfbAnaDec[in_ch]->cldfb_state_fx[i] = (Word32) ( st_ivas->cldfbAnaDec[in_ch]->cldfb_state[i] * ( 1LL << ( Q11 ) ) ); } } - if ( ( hDecoderConfig->ivas_total_brate < IVAS_24k4 ) && ( ( hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_HOA2 ) || ( hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_HOA3 ) ) ) - { - for ( i = 0; i < IVAS_MAX_NUM_BANDS; i++ ) - { - floatToFixed_arrL( hSpar->hMdDec->smooth_buf[i], hSpar->hMdDec->smooth_buf_fx[i], 0, 2 * SBA_DIRAC_NRG_SMOOTH_LONG + 1 ); - } - floatToFixed_arr( hSpar->hMdDec->smooth_fac, hSpar->hMdDec->smooth_fac_fx, Q15, IVAS_MAX_NUM_BANDS ); - } + //if ( ( hDecoderConfig->ivas_total_brate < IVAS_24k4 ) && ( ( hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_HOA2 ) || ( hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_HOA3 ) ) ) + //{ + // for ( i = 0; i < IVAS_MAX_NUM_BANDS; i++ ) + // { + // floatToFixed_arrL( hSpar->hMdDec->smooth_buf[i], hSpar->hMdDec->smooth_buf_fx[i], 0, 2 * SBA_DIRAC_NRG_SMOOTH_LONG + 1 ); + // } + // floatToFixed_arr( hSpar->hMdDec->smooth_fac, hSpar->hMdDec->smooth_fac_fx, Q15, IVAS_MAX_NUM_BANDS ); + //} FOR( Word16 out_ch = 0; out_ch < numch_out_dirac; out_ch++ ) { IF( st_ivas->cldfbSynDec[out_ch] ) @@ -5892,6 +5912,7 @@ ivas_error ivas_jbm_dec_render( st_ivas->cldfbAnaDec[in_ch]->cldfb_state[i] = ( (float) ( st_ivas->cldfbAnaDec[in_ch]->cldfb_state_fx[i] ) / ( 1LL << ( Q11 ) ) ); /*Rounding off*/ } } +#if 0 FOR( int m = 0; m < MAX_PARAM_SPATIAL_SUBFRAMES + 1; m++ ) { FOR( j = 0; j < IVAS_MAX_FB_MIXER_OUT_CH; j++ ) @@ -5905,6 +5926,7 @@ ivas_error ivas_jbm_dec_render( } } } +#endif // fix2float (to be cleaned) IF( ( LT_32( hDecoderConfig->ivas_total_brate, IVAS_24k4 ) ) && ( ( EQ_16( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_HOA2 ) ) || ( EQ_16( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_HOA3 ) ) ) ) { @@ -5982,6 +6004,8 @@ ivas_error ivas_jbm_dec_render( floatToFixed_arr32( st_ivas->hTcBuffer->tc[i], st_ivas->hTcBuffer->tc_fx[i], Q11, st_ivas->hTcBuffer->n_samples_available ); } Word16 q1 = 30, q2 = 30; + hSpar->hMdDec->Q_mixer_mat = 30; +#if 0 for ( int l = 0; l < numch_out; l++ ) { for ( j = 0; j < numch_in; j++ ) @@ -6005,6 +6029,7 @@ ivas_error ivas_jbm_dec_render( } } } +#endif for ( Word16 in_ch = 0; in_ch < numch_in; in_ch++ ) { for ( i = 0; i < st_ivas->cldfbAnaDec[in_ch]->p_filter_length - st_ivas->cldfbAnaDec[in_ch]->no_channels; i++ ) @@ -6061,6 +6086,7 @@ ivas_error ivas_jbm_dec_render( st_ivas->cldfbAnaDec[in_ch]->cldfb_state[i] = ( (float) ( st_ivas->cldfbAnaDec[in_ch]->cldfb_state_fx[i] ) / ( 1LL << ( Q11 ) ) ); } } +#if 0 FOR( Word16 m = 0; m < MAX_PARAM_SPATIAL_SUBFRAMES + 1; m++ ) { FOR( j = 0; j < IVAS_MAX_FB_MIXER_OUT_CH; j++ ) @@ -6074,6 +6100,7 @@ ivas_error ivas_jbm_dec_render( } } } +#endif // fix2float (to be cleaned) IF( ( LT_32( hDecoderConfig->ivas_total_brate, IVAS_24k4 ) ) && ( ( EQ_16( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_HOA2 ) ) || ( EQ_16( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_HOA3 ) ) ) ) { @@ -6160,7 +6187,6 @@ ivas_error ivas_jbm_dec_render( } else if ( st_ivas->renderer_type == RENDERER_OSBA_AMBI || st_ivas->renderer_type == RENDERER_OSBA_LS || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) { -#ifdef IVAS_FLOAT_FIXED Word16 q = 15; FOR(Word16 ind1 = 0; ind1 < s_max(st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe, s_max(st_ivas->nchan_transport, st_ivas->nchan_ism)); ind1++) { @@ -6190,6 +6216,7 @@ ivas_error ivas_jbm_dec_render( { return error; } + q = Q11; FOR(Word16 ind1 = 0; ind1 < s_max(st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe, s_max(st_ivas->nchan_transport, st_ivas->nchan_ism)); ind1++) { FOR(Word16 ind2 = 0; ind2 < L_FRAME48k; ind2++) @@ -6197,12 +6224,6 @@ ivas_error ivas_jbm_dec_render( p_output[ind1][ind2] = (float)(p_output_fx[ind1][ind2]) / (float)(1 << q); } } -#else - if ( ( error = ivas_osba_render_sf( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output ) ) != IVAS_ERR_OK ) - { - return error; - } -#endif } else if ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_EXTERNAL ) /*EXT output = individual objects + HOA3*/ { @@ -6228,6 +6249,8 @@ ivas_error ivas_jbm_dec_render( floatToFixed_arr32( st_ivas->hTcBuffer->tc[i], st_ivas->hTcBuffer->tc_fx[i], Q11, st_ivas->hTcBuffer->n_samples_available ); } Word16 q1 = 30, q2 = 30; + hSpar->hMdDec->Q_mixer_mat = 30; +#if 0 for ( int l = 0; l < numch_out; l++ ) { for ( j = 0; j < numch_in; j++ ) @@ -6251,6 +6274,7 @@ ivas_error ivas_jbm_dec_render( } } } +#endif for ( Word16 in_ch = 0; in_ch < numch_in; in_ch++ ) { for ( i = 0; i < st_ivas->cldfbAnaDec[in_ch]->p_filter_length - st_ivas->cldfbAnaDec[in_ch]->no_channels; i++ ) @@ -6293,6 +6317,7 @@ ivas_error ivas_jbm_dec_render( st_ivas->cldfbAnaDec[in_ch]->cldfb_state[i] = ( (float) ( st_ivas->cldfbAnaDec[in_ch]->cldfb_state_fx[i] ) / ( 1LL << ( Q11 ) ) ); } } +#if 0 FOR( int m = 0; m < MAX_PARAM_SPATIAL_SUBFRAMES + 1; m++ ) { FOR( j = 0; j < IVAS_MAX_FB_MIXER_OUT_CH; j++ ) @@ -6306,6 +6331,7 @@ ivas_error ivas_jbm_dec_render( } } } +#endif // fix2float (to be cleaned) IF( ( LT_32( hDecoderConfig->ivas_total_brate, IVAS_24k4 ) ) && ( ( EQ_16( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_HOA2 ) ) || ( EQ_16( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_HOA3 ) ) ) ) { @@ -6357,6 +6383,8 @@ ivas_error ivas_jbm_dec_render( floatToFixed_arr32( st_ivas->hTcBuffer->tc[i], st_ivas->hTcBuffer->tc_fx[i], Q11, st_ivas->hTcBuffer->n_samples_available ); } Word16 q1 = 30, q2 = 30; + hSpar->hMdDec->Q_mixer_mat = 30; +#if 0 for ( int l = 0; l < numch_out; l++ ) { for ( j = 0; j < numch_in; j++ ) @@ -6380,6 +6408,7 @@ ivas_error ivas_jbm_dec_render( } } } +#endif for ( Word16 in_ch = 0; in_ch < numch_in; in_ch++ ) { for ( i = 0; i < st_ivas->cldfbAnaDec[in_ch]->p_filter_length - st_ivas->cldfbAnaDec[in_ch]->no_channels; i++ ) @@ -6422,6 +6451,7 @@ ivas_error ivas_jbm_dec_render( st_ivas->cldfbAnaDec[in_ch]->cldfb_state[i] = ( (float) ( st_ivas->cldfbAnaDec[in_ch]->cldfb_state_fx[i] ) / ( 1LL << ( Q11 ) ) ); /*Rounding off*/ } } +#if 0 FOR( int m = 0; m < MAX_PARAM_SPATIAL_SUBFRAMES + 1; m++ ) { FOR( j = 0; j < IVAS_MAX_FB_MIXER_OUT_CH; j++ ) @@ -6435,6 +6465,7 @@ ivas_error ivas_jbm_dec_render( } } } +#endif // fix2float (to be cleaned) IF( ( LT_32( hDecoderConfig->ivas_total_brate, IVAS_24k4 ) ) && ( ( EQ_16( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_HOA2 ) ) || ( EQ_16( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_HOA3 ) ) ) ) { @@ -6486,6 +6517,8 @@ ivas_error ivas_jbm_dec_render( floatToFixed_arr32( st_ivas->hTcBuffer->tc[i], st_ivas->hTcBuffer->tc_fx[i], Q11, st_ivas->hTcBuffer->n_samples_available ); } Word16 q1 = 30, q2 = 30; +#if 0 //ndef IVAS_FLOAT_FIXED_TO_BE_REMOVED + hSpar->hMdDec->Q_mixer_mat = 30; for ( int l = 0; l < numch_out; l++ ) { for ( j = 0; j < numch_in; j++ ) @@ -6509,6 +6542,7 @@ ivas_error ivas_jbm_dec_render( } } } +#endif for ( Word16 in_ch = 0; in_ch < numch_in; in_ch++ ) { for ( i = 0; i < st_ivas->cldfbAnaDec[in_ch]->p_filter_length - st_ivas->cldfbAnaDec[in_ch]->no_channels; i++ ) @@ -6551,6 +6585,7 @@ ivas_error ivas_jbm_dec_render( st_ivas->cldfbAnaDec[in_ch]->cldfb_state[i] = ( (float) ( st_ivas->cldfbAnaDec[in_ch]->cldfb_state_fx[i] ) / ( 1LL << ( Q11 ) ) ); /*Rounding off*/ } } +#if 0 //ndef IVAS_FLOAT_FIXED_TO_BE_REMOVED FOR( Word16 m = 0; m < MAX_PARAM_SPATIAL_SUBFRAMES + 1; m++ ) { FOR( j = 0; j < IVAS_MAX_FB_MIXER_OUT_CH; j++ ) @@ -6564,6 +6599,7 @@ ivas_error ivas_jbm_dec_render( } } } +#endif IF( ( LT_32( hDecoderConfig->ivas_total_brate, IVAS_24k4 ) ) && ( ( EQ_16( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_HOA2 ) ) || ( EQ_16( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_HOA3 ) ) ) ) { fixedToFloat_arr( hSpar->hMdDec->smooth_fac_fx, hSpar->hMdDec->smooth_fac, Q15, IVAS_MAX_NUM_BANDS ); diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index 083909963..2aba53751 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -3307,7 +3307,8 @@ ivas_error ivas_masa_dec_reconfigure( numch_out = hSpar->hFbMixer->fb_cfg->num_out_chans; numch_in = hSpar->hFbMixer->fb_cfg->num_in_chans; num_md_sub_frames = ivas_get_spar_dec_md_num_subframes( st_ivas->sba_order, hDecoderConfig->ivas_total_brate, st_ivas->last_active_ivas_total_brate ); - + hSpar->hMdDec->Q_mixer_mat = 30; +#if 0 for ( int l = 0; l < numch_out; l++ ) { for ( int j = 0; j < numch_in; j++ ) @@ -3331,6 +3332,7 @@ ivas_error ivas_masa_dec_reconfigure( } } } +#endif for ( Word16 in_ch = 0; in_ch < numch_in; in_ch++ ) { for ( Word16 i = 0; i < st_ivas->cldfbAnaDec[in_ch]->p_filter_length - st_ivas->cldfbAnaDec[in_ch]->no_channels; i++ ) @@ -3383,6 +3385,7 @@ ivas_error ivas_masa_dec_reconfigure( st_ivas->cldfbAnaDec[in_ch]->cldfb_state[i] = ( (float) ( st_ivas->cldfbAnaDec[in_ch]->cldfb_state_fx[i] ) / ( 1LL << ( Q11 ) ) ); } } +#if 0 FOR( int m = 0; m < MAX_PARAM_SPATIAL_SUBFRAMES + 1; m++ ) { FOR( int j = 0; j < IVAS_MAX_FB_MIXER_OUT_CH; j++ ) @@ -3396,6 +3399,7 @@ ivas_error ivas_masa_dec_reconfigure( } } } +#endif // fix2float (to be cleaned) IF( ( LT_32( hDecoderConfig->ivas_total_brate, IVAS_24k4 ) ) && ( ( EQ_16( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_HOA2 ) ) || ( EQ_16( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_HOA3 ) ) ) ) { @@ -3830,7 +3834,7 @@ ivas_error ivas_masa_dec_reconfigure_fx( } #endif - +#ifdef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * ivas_spar_param_to_masa_param_mapping() * @@ -3850,7 +3854,7 @@ void fixedToFloat_arrL_check (Word32 *i, float *f, Word16 Q, Word16 l) } } } -#ifdef IVAS_FLOAT_FIXED + void ivas_spar_param_to_masa_param_mapping_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder struct */ Word32 inRe_fx[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* i : Input audio in CLDFB domain, real */ @@ -6085,4 +6089,4 @@ static Word16 rint_fx( /* returns in Q0 */ res = negate( res ); } return res; -} \ No newline at end of file +} diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c index 31047a2c0..2ed47f58f 100644 --- a/lib_dec/ivas_mct_dec.c +++ b/lib_dec/ivas_mct_dec.c @@ -1507,7 +1507,8 @@ static ivas_error ivas_mc_dec_reconfig( numch_out = hSpar->hFbMixer->fb_cfg->num_out_chans; numch_in = hSpar->hFbMixer->fb_cfg->num_in_chans; num_md_sub_frames = ivas_get_spar_dec_md_num_subframes( st_ivas->sba_order, hDecoderConfig->ivas_total_brate, st_ivas->last_active_ivas_total_brate ); - + hSpar->hMdDec->Q_mixer_mat = 30; +#if 0 for ( int l = 0; l < numch_out; l++ ) { for ( int j = 0; j < numch_in; j++ ) @@ -1531,6 +1532,7 @@ static ivas_error ivas_mc_dec_reconfig( } } } +#endif for ( Word16 in_ch = 0; in_ch < numch_in; in_ch++ ) { for ( Word16 i = 0; i < st_ivas->cldfbAnaDec[in_ch]->p_filter_length - st_ivas->cldfbAnaDec[in_ch]->no_channels; i++ ) @@ -1583,6 +1585,7 @@ static ivas_error ivas_mc_dec_reconfig( st_ivas->cldfbAnaDec[in_ch]->cldfb_state[i] = ( (float) ( st_ivas->cldfbAnaDec[in_ch]->cldfb_state_fx[i] ) / ( 1LL << ( Q11 ) ) ); } } +#if 0 FOR( int m = 0; m < MAX_PARAM_SPATIAL_SUBFRAMES + 1; m++ ) { FOR( int j = 0; j < IVAS_MAX_FB_MIXER_OUT_CH; j++ ) @@ -1596,6 +1599,7 @@ static ivas_error ivas_mc_dec_reconfig( } } } +#endif // fix2float (to be cleaned) IF( ( LT_32( hDecoderConfig->ivas_total_brate, IVAS_24k4 ) ) && ( ( EQ_16( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_HOA2 ) ) || ( EQ_16( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_HOA3 ) ) ) ) { diff --git a/lib_dec/ivas_omasa_dec.c b/lib_dec/ivas_omasa_dec.c index e2f467250..98af89d37 100644 --- a/lib_dec/ivas_omasa_dec.c +++ b/lib_dec/ivas_omasa_dec.c @@ -383,29 +383,6 @@ ivas_error ivas_omasa_dec_config_fx( numch_in = hSpar->hFbMixer->fb_cfg->num_in_chans; num_md_sub_frames = ivas_get_spar_dec_md_num_subframes(st_ivas->sba_order, hDecoderConfig->ivas_total_brate, st_ivas->last_active_ivas_total_brate); - for (int l = 0; l < numch_out; l++) - { - for (int j = 0; j < numch_in; j++) - { - for (int n = 0; n < num_md_sub_frames * IVAS_MAX_NUM_BANDS; n++) - { - hSpar->hMdDec->mixer_mat_fx[l][j][n] = floatToFixed(hSpar->hMdDec->mixer_mat[l][j][n], q1); - } - } - } - for (int m = 0; m < MAX_PARAM_SPATIAL_SUBFRAMES + 1; m++) - { - for (int j = 0; j < IVAS_MAX_FB_MIXER_OUT_CH; j++) - { - for (int n = 0; n < IVAS_MAX_SPAR_FB_MIXER_IN_CH; n++) - { - for (int l = 0; l < IVAS_MAX_NUM_BANDS; l++) - { - hSpar->hMdDec->mixer_mat_prev_fx[m][j][n][l] = floatToFixed(hSpar->hMdDec->mixer_mat_prev[m][j][n][l], q2); - } - } - } - } for (Word16 in_ch = 0; in_ch < numch_in; in_ch++) { for (Word16 i = 0; i < st_ivas->cldfbAnaDec[in_ch]->p_filter_length - st_ivas->cldfbAnaDec[in_ch]->no_channels; i++) @@ -462,19 +439,6 @@ ivas_error ivas_omasa_dec_config_fx( st_ivas->cldfbAnaDec[in_ch]->cldfb_state[i] = ((float)(st_ivas->cldfbAnaDec[in_ch]->cldfb_state_fx[i]) / (1LL << (Q11))); /*Rounding off*/ } } - FOR(int m = 0; m < MAX_PARAM_SPATIAL_SUBFRAMES + 1; m++) - { - FOR(int j = 0; j < IVAS_MAX_FB_MIXER_OUT_CH; j++) - { - FOR(int n = 0; n < IVAS_MAX_SPAR_FB_MIXER_IN_CH; n++) - { - FOR(int l = 0; l < IVAS_MAX_NUM_BANDS; l++) - { - hSpar->hMdDec->mixer_mat_prev[m][j][n][l] = ((float)hSpar->hMdDec->mixer_mat_prev_fx[m][j][n][l] / (1 << q2)); - } - } - } - } // fix2float (to be cleaned) IF((LT_32(hDecoderConfig->ivas_total_brate, IVAS_24k4)) && ((EQ_16(hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_HOA2)) || (EQ_16(hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_HOA3)))) { diff --git a/lib_dec/ivas_osba_dec.c b/lib_dec/ivas_osba_dec.c index 54a1c45fd..f8616e486 100644 --- a/lib_dec/ivas_osba_dec.c +++ b/lib_dec/ivas_osba_dec.c @@ -208,10 +208,33 @@ ivas_error ivas_osba_dirac_td_binaural_jbm( channel_offset = st_ivas->nchan_ism; +#ifndef IVAS_FLOAT_FIXED if ( ( error = ivas_sba_dec_render( st_ivas, nSamplesAsked, nSamplesRendered, nSamplesAvailable, &output_f[channel_offset] ) ) != IVAS_ERR_OK ) { return error; } +#else + { + Word32 output_fx[MAX_OUTPUT_CHANNELS][L_FRAME48k]; + Word32 *output_f_fx[MAX_OUTPUT_CHANNELS]; + for (int i = 0; i < MAX_OUTPUT_CHANNELS; i++) + { + output_f_fx[i] = &output_fx[0][0]; + } + for ( n = 0; n < channel_offset; n++ ) + { + floatToFixed_arr32( output_f[n], output_fx[n], Q8, 960 ); + } + if ((error = ivas_sba_dec_render_fx(st_ivas, nSamplesAsked, nSamplesRendered, nSamplesAvailable, &output_f_fx[channel_offset], 960)) != IVAS_ERR_OK) + { + return error; + } + for ( n = 0; n < channel_offset; n++ ) + { + fixedToFloat_arrL( output_fx[n], output_f[n], Q8, 960 ); + } + } +#endif if ( ( error = ivas_td_binaural_renderer_sf( st_ivas, p_sepobj, *nSamplesRendered ) ) != IVAS_ERR_OK ) { @@ -293,11 +316,11 @@ ivas_error ivas_osba_ism_metadata_dec( *-------------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED ivas_error ivas_osba_render_sf_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ const UWord16 nSamplesAsked, /* i : number of CLDFB slots requested */ UWord16 *nSamplesRendered, /* o : number of CLDFB slots rendered */ UWord16 *nSamplesAvailableNext, /* o : number of CLDFB slots still to render */ - Word32 *p_output[] /* o : rendered time signal */ + Word32 *p_output[] /* o : rendered time signal */ ) { Word16 n; @@ -312,36 +335,87 @@ ivas_error ivas_osba_render_sf_fx( FOR(n = 0; n < st_ivas->nchan_ism; n++) { - Copy32(p_output[n], output_ism[n], nSamplesAsked); + v_shr(p_output[n], sub(Q15, Q11), output_ism[n], nSamplesAsked); } -#ifndef IVAS_FLOAT_TO_BE_REMOVED - // Not converted - // Do fixed to float - Word16 q = Q15; - float *p_output_flt[MAX_OUTPUT_CHANNELS]; - FOR(Word16 ind1 = 0; ind1 < st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe; ind1++) - { - p_output_flt[ind1] = (float *)malloc(L_FRAME48k * sizeof(float)); - FOR(Word16 ind2 = 0; ind2 < L_FRAME48k; ind2++) - { - p_output_flt[ind1][ind2] = (float)(p_output[ind1][ind2]) / (float)(1 << q); - } - } -#endif - IF((error = ivas_sba_dec_render(st_ivas, nSamplesAsked, nSamplesRendered, nSamplesAvailableNext, p_output_flt)) != IVAS_ERR_OK) +#if 1 /*Float to fixed conversion*/ + SPAR_DEC_HANDLE hSpar; + hSpar = st_ivas->hSpar; + uint16_t nchan_internal; + nchan_internal = ivas_sba_get_nchan_metadata( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); + Word16 numch_out = hSpar->hFbMixer->fb_cfg->num_out_chans; + Word16 numch_in = hSpar->hFbMixer->fb_cfg->num_in_chans; + DECODER_CONFIG_HANDLE hDecoderConfig; + hDecoderConfig = st_ivas->hDecoderConfig; + Word16 numch_out_dirac = hDecoderConfig->nchan_out; + + Word16 num_md_sub_frames = ivas_get_spar_dec_md_num_subframes( st_ivas->sba_order, hDecoderConfig->ivas_total_brate, st_ivas->last_active_ivas_total_brate ); + + for ( int i = 0; i < s_max( st_ivas->nchan_ism, 0 ) + nchan_internal; i++ ) + { + floatToFixed_arr32( st_ivas->hTcBuffer->tc[i], st_ivas->hTcBuffer->tc_fx[i], Q11, st_ivas->hTcBuffer->n_samples_available ); + } + Word16 q1 = 30, q2 = 30; + hSpar->hMdDec->Q_mixer_mat = 30; + for ( Word16 in_ch = 0; in_ch < numch_in; in_ch++ ) + { + for ( int i = 0; i < st_ivas->cldfbAnaDec[in_ch]->p_filter_length - st_ivas->cldfbAnaDec[in_ch]->no_channels; i++ ) + { + st_ivas->cldfbAnaDec[in_ch]->cldfb_state_fx[i] = (Word32) ( st_ivas->cldfbAnaDec[in_ch]->cldfb_state[i] * ( 1LL << ( Q11 ) ) ); + } + } + if ( ( hDecoderConfig->ivas_total_brate < IVAS_24k4 ) && ( ( hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_HOA2 ) || ( hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_HOA3 ) ) ) + { + for ( int i = 0; i < IVAS_MAX_NUM_BANDS; i++ ) + { + floatToFixed_arrL( hSpar->hMdDec->smooth_buf[i], hSpar->hMdDec->smooth_buf_fx[i], 0, 2 * SBA_DIRAC_NRG_SMOOTH_LONG + 1 ); + } + floatToFixed_arr( hSpar->hMdDec->smooth_fac, hSpar->hMdDec->smooth_fac_fx, Q15, IVAS_MAX_NUM_BANDS ); + } + FOR( Word16 out_ch = 0; out_ch < numch_out_dirac; out_ch++ ) + { + IF( st_ivas->cldfbSynDec[out_ch] ) + { + FOR( int i = 0; i < st_ivas->cldfbSynDec[out_ch]->p_filter_length; i++ ) + { + st_ivas->cldfbSynDec[out_ch]->cldfb_state_fx[i] = float_to_fix( st_ivas->cldfbSynDec[out_ch]->cldfb_state[i], Q11 ); + } + } + } +#endif // + + IF((error = ivas_sba_dec_render_fx(st_ivas, nSamplesAsked, nSamplesRendered, nSamplesAvailableNext, p_output, 960)) != IVAS_ERR_OK) { return error; } -#ifndef IVAS_FLOAT_TO_BE_REMOVED - FOR(Word16 ind1 = 0; ind1 < st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe; ind1++) - { - FOR(Word16 ind2 = 0; ind2 < L_FRAME48k; ind2++) - { - p_output[ind1][ind2] = (Word32)(p_output_flt[ind1][ind2] * (1 << q)); - } - free(p_output_flt[ind1]); - } +#if 1 /*Fixed to float */ + FOR( Word16 in_ch = 0; in_ch < numch_in; in_ch++ ) + { + FOR( int i = 0; i < st_ivas->cldfbAnaDec[in_ch]->p_filter_length - st_ivas->cldfbAnaDec[in_ch]->no_channels; i++ ) + { + st_ivas->cldfbAnaDec[in_ch]->cldfb_state[i] = ( (float) ( st_ivas->cldfbAnaDec[in_ch]->cldfb_state_fx[i] ) / ( 1LL << ( Q11 ) ) ); /*Rounding off*/ + } + } + // fix2float (to be cleaned) + IF( ( LT_32( hDecoderConfig->ivas_total_brate, IVAS_24k4 ) ) && ( ( EQ_16( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_HOA2 ) ) || ( EQ_16( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_HOA3 ) ) ) ) + { + fixedToFloat_arr( hSpar->hMdDec->smooth_fac_fx, hSpar->hMdDec->smooth_fac, Q15, IVAS_MAX_NUM_BANDS ); + FOR( int i = 0; i < IVAS_MAX_NUM_BANDS; i++ ) + { + fixedToFloat_arrL( hSpar->hMdDec->smooth_buf_fx[i], hSpar->hMdDec->smooth_buf[i], 0, 2 * SBA_DIRAC_NRG_SMOOTH_LONG + 1 ); + } + } + // fix2float end + FOR( Word16 out_ch = 0; out_ch < numch_out_dirac; out_ch++ ) + { + IF( st_ivas->cldfbSynDec[out_ch] ) + { + FOR( int i = 0; i < st_ivas->cldfbSynDec[out_ch]->p_filter_length; i++ ) + { + st_ivas->cldfbSynDec[out_ch]->cldfb_state[i] = ( (float) ( st_ivas->cldfbSynDec[out_ch]->cldfb_state_fx[i] ) / (float) ( 1LL << ( Q11 ) ) ); + } + } + } #endif IF(st_ivas->renderer_type != RENDERER_BINAURAL_FASTCONV_ROOM) diff --git a/lib_dec/ivas_sba_dec.c b/lib_dec/ivas_sba_dec.c index dbf60af77..bc9814a9c 100644 --- a/lib_dec/ivas_sba_dec.c +++ b/lib_dec/ivas_sba_dec.c @@ -131,6 +131,7 @@ void ivas_sba_set_cna_cng_flag( } #endif +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * ivas_sba_dec_reconfigure() * @@ -281,30 +282,802 @@ ivas_error ivas_sba_dec_reconfigure( numch_out = hSpar->hFbMixer->fb_cfg->num_out_chans; numch_in = hSpar->hFbMixer->fb_cfg->num_in_chans; num_md_sub_frames = ivas_get_spar_dec_md_num_subframes( st_ivas->sba_order, hDecoderConfig->ivas_total_brate, st_ivas->last_active_ivas_total_brate ); + hSpar->hMdDec->Q_mixer_mat = 30; + //for ( int l = 0; l < numch_out; l++ ) + //{ + // for ( int j = 0; j < numch_in; j++ ) + // { + // for ( int k = 0; k < num_md_sub_frames * IVAS_MAX_NUM_BANDS; k++ ) + // { + // hSpar->hMdDec->mixer_mat_fx[l][j][k] = floatToFixed( hSpar->hMdDec->mixer_mat[l][j][k], q1 ); + // } + // } + //} + //for ( int m = 0; m < MAX_PARAM_SPATIAL_SUBFRAMES + 1; m++ ) + //{ + // for ( int j = 0; j < IVAS_MAX_FB_MIXER_OUT_CH; j++ ) + // { + // for ( int k = 0; k < IVAS_MAX_SPAR_FB_MIXER_IN_CH; k++ ) + // { + // for ( int l = 0; l < IVAS_MAX_NUM_BANDS; l++ ) + // { + // hSpar->hMdDec->mixer_mat_prev_fx[m][j][k][l] = floatToFixed( hSpar->hMdDec->mixer_mat_prev[m][j][k][l], q2 ); + // } + // } + // } + //} + for ( Word16 in_ch = 0; in_ch < numch_in; in_ch++ ) + { + for ( Word16 i = 0; i < st_ivas->cldfbAnaDec[in_ch]->p_filter_length - st_ivas->cldfbAnaDec[in_ch]->no_channels; i++ ) + { + st_ivas->cldfbAnaDec[in_ch]->cldfb_state_fx[i] = (Word32) ( st_ivas->cldfbAnaDec[in_ch]->cldfb_state[i] * ( 1LL << ( Q11 ) ) ); + } + } + if ( ( hDecoderConfig->ivas_total_brate < IVAS_24k4 ) && ( ( hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_HOA2 ) || ( hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_HOA3 ) ) ) + { + for ( Word16 i = 0; i < IVAS_MAX_NUM_BANDS; i++ ) + { + floatToFixed_arrL( hSpar->hMdDec->smooth_buf[i], hSpar->hMdDec->smooth_buf_fx[i], 0, 2 * SBA_DIRAC_NRG_SMOOTH_LONG + 1 ); + } + floatToFixed_arr( hSpar->hMdDec->smooth_fac, hSpar->hMdDec->smooth_fac_fx, Q15, IVAS_MAX_NUM_BANDS ); + } + FOR( Word16 out_ch = 0; out_ch < numch_out_dirac; out_ch++ ) + { + IF( st_ivas->cldfbSynDec[out_ch] ) + { + FOR( Word16 i = 0; i < st_ivas->cldfbSynDec[out_ch]->p_filter_length; i++ ) + { + st_ivas->cldfbSynDec[out_ch]->cldfb_state_fx[i] = float_to_fix( st_ivas->cldfbSynDec[out_ch]->cldfb_state[i] , Q11 ); + } + } + } + } + Word16 n_tc; + if (st_ivas->ivas_format == MASA_ISM_FORMAT || st_ivas->ivas_format == SBA_ISM_FORMAT) + n_tc = st_ivas->nchan_ism; + else + n_tc = st_ivas->hTcBuffer->nchan_transport_internal; + for (int ch = 0; ch < n_tc; ch++) + { + floatToFixed_arrL(st_ivas->hTcBuffer->tc[ch], st_ivas->hTcBuffer->tc_fx[ch], Q11, L_FRAME48k); + } +#endif + if ( ( error = ivas_jbm_dec_flush_renderer_fx( st_ivas, granularity_new, st_ivas->renderer_type, st_ivas->intern_config, &st_ivas->hIntSetup, st_ivas->mc_mode, ism_mode_old, nSamplesFlushed, data ) ) != IVAS_ERR_OK ) + { + return error; + } +#if 1 /*Fixed to float */ + if ( hTcBuffer->tc_buffer ) + fixedToFloat_arrL( hTcBuffer->tc_buffer_fx, hTcBuffer->tc_buffer, Q11, hTcBuffer->tc_buff_len ); + IF( hSpar ) + { + FOR( Word16 in_ch = 0; in_ch < numch_in; in_ch++ ) + { + FOR( Word16 i = 0; i < st_ivas->cldfbAnaDec[in_ch]->p_filter_length - st_ivas->cldfbAnaDec[in_ch]->no_channels; i++ ) + { + st_ivas->cldfbAnaDec[in_ch]->cldfb_state[i] = ( (float) ( st_ivas->cldfbAnaDec[in_ch]->cldfb_state_fx[i] ) / ( 1LL << ( Q11 ) ) ); + } + } + /*FOR( int m = 0; m < MAX_PARAM_SPATIAL_SUBFRAMES + 1; m++ ) + { + FOR( int j = 0; j < IVAS_MAX_FB_MIXER_OUT_CH; j++ ) + { + FOR( int k = 0; k < IVAS_MAX_SPAR_FB_MIXER_IN_CH; k++ ) + { + FOR( int l = 0; l < IVAS_MAX_NUM_BANDS; l++ ) + { + hSpar->hMdDec->mixer_mat_prev[m][j][k][l] = ( (float) hSpar->hMdDec->mixer_mat_prev_fx[m][j][k][l] / ( 1 << q2 ) ); + } + } + } + }*/ + // fix2float (to be cleaned) + IF( ( LT_32( hDecoderConfig->ivas_total_brate, IVAS_24k4 ) ) && ( ( EQ_16( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_HOA2 ) ) || ( EQ_16( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_HOA3 ) ) ) ) + { + fixedToFloat_arr( hSpar->hMdDec->smooth_fac_fx, hSpar->hMdDec->smooth_fac, Q15, IVAS_MAX_NUM_BANDS ); + FOR( Word16 i = 0; i < IVAS_MAX_NUM_BANDS; i++ ) + { + fixedToFloat_arrL( hSpar->hMdDec->smooth_buf_fx[i], hSpar->hMdDec->smooth_buf[i], 0, 2 * SBA_DIRAC_NRG_SMOOTH_LONG + 1 ); + } + } + // fix2float end + FOR( Word16 out_ch = 0; out_ch < numch_out_dirac; out_ch++ ) + { + IF( st_ivas->cldfbSynDec[out_ch] ) + { + FOR( Word16 i = 0; i < st_ivas->cldfbSynDec[out_ch]->p_filter_length; i++ ) + { + st_ivas->cldfbSynDec[out_ch]->cldfb_state[i] = ( (float) ( st_ivas->cldfbSynDec[out_ch]->cldfb_state_fx[i] ) / (float) ( 1LL << ( Q11 ) ) ); + } + } + } + } +#endif +#else + if ( ( error = ivas_jbm_dec_flush_renderer( st_ivas, granularity_new, st_ivas->renderer_type, st_ivas->intern_config, &st_ivas->hIntSetup, st_ivas->mc_mode, ism_mode_old, nSamplesFlushed, data ) ) != IVAS_ERR_OK ) + { + return error; + } +#endif // IVAS_FLOAT_FIXED + + /* restore correct values for the current frame*/ + st_ivas->sba_analysis_order = ivas_sba_get_analysis_order( ivas_total_brate, st_ivas->sba_order ); + st_ivas->hDecoderConfig->ivas_total_brate = ivas_total_brate; + } + else if ( granularity_new > st_ivas->hTcBuffer->n_samples_granularity ) + { + if ( ( error = ivas_jbm_dec_set_discard_samples( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + + /* make sure the changed number of slots in the last subframe is not lost in the following steps */ + if ( st_ivas->hSpatParamRendCom != NULL ) + { + st_ivas->hSpatParamRendCom->subframe_nbslots[st_ivas->hSpatParamRendCom->nb_subframes - 1] = st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->nb_subframes - 1]; + } + st_ivas->hSpar->subframe_nbslots[st_ivas->hSpar->nb_subframes - 1] = st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->nb_subframes - 1]; + } + } + + /* save old */ + if ( ism_mode_old != ISM_SBA_MODE_DISC ) + { + if ( st_ivas->hDirAC == NULL && st_ivas->hSpar != NULL ) + { + st_ivas->hTcBuffer->num_slots = st_ivas->hSpar->num_slots; + st_ivas->hTcBuffer->nb_subframes = st_ivas->hSpar->nb_subframes; + st_ivas->hTcBuffer->slots_rendered = st_ivas->hSpar->slots_rendered; + st_ivas->hTcBuffer->subframes_rendered = st_ivas->hSpar->subframes_rendered; + mvs2s( st_ivas->hSpar->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); + } + else if ( st_ivas->hSpatParamRendCom != NULL ) + { + st_ivas->hTcBuffer->num_slots = st_ivas->hSpatParamRendCom->num_slots; + st_ivas->hTcBuffer->nb_subframes = st_ivas->hSpatParamRendCom->nb_subframes; + st_ivas->hTcBuffer->slots_rendered = st_ivas->hSpatParamRendCom->slots_rendered; + st_ivas->hTcBuffer->subframes_rendered = st_ivas->hSpatParamRendCom->subframes_rendered; + mvs2s( st_ivas->hSpatParamRendCom->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); + } + } + + /*-----------------------------------------------------------------* + * Allocate, initialize, and configure SBA handles + *-----------------------------------------------------------------*/ + + int16_t sba_order_internal; + SPAR_DEC_HANDLE hSpar; + hSpar = st_ivas->hSpar; + + sba_order_internal = min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ); + + if ( hSpar != NULL ) + { + if ( ( hSpar->hPCA != NULL ) && ( ( hDecoderConfig->ivas_total_brate != PCA_BRATE ) || ( st_ivas->sba_order != 1 ) ) ) + { + free( st_ivas->hSpar->hPCA ); + hSpar->hPCA = NULL; + } + + if ( nchan_transport_old != ivas_get_sba_num_TCs( ivas_total_brate, sba_order_internal ) || ( last_ivas_total_brate >= IVAS_512k && ivas_total_brate < IVAS_512k ) || ( last_ivas_total_brate < IVAS_512k && ivas_total_brate >= IVAS_512k ) ) + { + ivas_spar_dec_close( &( st_ivas->hSpar ), hDecoderConfig->output_Fs, 1 ); + +#ifdef IVAS_FLOAT_FIXED + if ( ( error = ivas_spar_dec_open_fx( st_ivas, 1 ) ) != IVAS_ERR_OK ) +#else + if ( ( error = ivas_spar_dec_open( st_ivas, 1 ) ) != IVAS_ERR_OK ) +#endif + { + return error; + } + } + else if ( last_ivas_total_brate < IVAS_24k4 && ivas_total_brate >= IVAS_24k4 ) + { + num_channels = st_ivas->hSpar->hMdDec->spar_md_cfg.num_umx_chs; + ivas_spar_md_dec_matrix_close( st_ivas->hSpar->hMdDec, num_channels ); + + num_md_sub_frames = ivas_get_spar_dec_md_num_subframes( sba_order_internal, ivas_total_brate, st_ivas->last_active_ivas_total_brate ); + if ( ( error = ivas_spar_md_dec_matrix_open( st_ivas->hSpar->hMdDec, num_channels, num_md_sub_frames ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + if ( hSpar->hPCA == NULL && st_ivas->hDecoderConfig->ivas_total_brate == PCA_BRATE && st_ivas->sba_order == 1 && st_ivas->ivas_format == SBA_FORMAT ) + { + if ( ( hSpar->hPCA = (PCA_DEC_STATE *) malloc( sizeof( PCA_DEC_STATE ) ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for PCA decoder" ); + } + + ivas_pca_dec_init( hSpar->hPCA ); +#ifdef IVAS_FLOAT_FIXED + ivas_pca_dec_init_fx(hSpar->hPCA); +#endif + + } + + ivas_spar_config( ivas_total_brate, sba_order_internal, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &hSpar->core_nominal_brate, st_ivas->sid_format ); + } + else + { +#ifdef IVAS_FLOAT_FIXED + if ( ( error = ivas_spar_dec_open_fx( st_ivas, 0 ) ) != IVAS_ERR_OK ) +#else + if ( ( error = ivas_spar_dec_open( st_ivas, 0 ) ) != IVAS_ERR_OK ) +#endif + { + return error; + } + } + + hSpar = st_ivas->hSpar; + st_ivas->sba_dirac_stereo_flag = ivas_get_sba_dirac_stereo_flag( st_ivas ); + + if ( st_ivas->nchan_transport == 1 ) + { + st_ivas->element_mode_init = IVAS_SCE; + } + else + { + st_ivas->element_mode_init = IVAS_CPE_MDCT; + } + + /*-----------------------------------------------------------------* + * Renderer selection + *-----------------------------------------------------------------*/ + + /* renderer might have changed */ + intern_config_old = st_ivas->intern_config; + ivas_renderer_select( st_ivas ); + + /* side effect of the renderer selection can be a changed internal config */ + if ( st_ivas->intern_config != intern_config_old ) + { + ivas_output_init( &( st_ivas->hIntSetup ), st_ivas->intern_config ); + } + + /*-------------------------------------------------------------------* + * Reallocate and initialize binaural rendering handles + *--------------------------------------------------------------------*/ + + if ( st_ivas->hBinRenderer == NULL && ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) ) + { + /* open fastconv binaural renderer */ + if ( ( error = ivas_binRenderer_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else if ( st_ivas->hBinRenderer != NULL && ( st_ivas->renderer_type != RENDERER_BINAURAL_FASTCONV && st_ivas->renderer_type != RENDERER_BINAURAL_FASTCONV_ROOM ) ) + { + ivas_binRenderer_close( &st_ivas->hBinRenderer ); + } + + if ( st_ivas->renderer_type == RENDERER_MONO_DOWNMIX && st_ivas->hMonoDmxRenderer == NULL ) + { + if ( ( error = ivas_mono_dmx_renderer_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + if ( st_ivas->renderer_type != RENDERER_MONO_DOWNMIX ) + { + ivas_mono_dmx_renderer_close( &st_ivas->hMonoDmxRenderer ); + } + + if ( ( error = ivas_dirac_sba_config( st_ivas->hQMetaData, &st_ivas->element_mode_init, ivas_total_brate, st_ivas->sba_analysis_order, ivas_get_hodirac_flag( ivas_total_brate, st_ivas->sba_analysis_order ) ? IVAS_MAX_NUM_BANDS : ( IVAS_MAX_NUM_BANDS - SPAR_DIRAC_SPLIT_START_BAND ) + , + st_ivas->ivas_format + ) ) != IVAS_ERR_OK ) + { + return error; + } + + if ( ( ( st_ivas->renderer_type != RENDERER_DISABLE ) && ( st_ivas->renderer_type != RENDERER_SBA_LINEAR_DEC ) ) || ( ( hDecoderConfig->output_config != IVAS_AUDIO_CONFIG_FOA ) && ( st_ivas->hDecoderConfig->output_config != IVAS_AUDIO_CONFIG_STEREO ) && ( st_ivas->hDecoderConfig->output_config != IVAS_AUDIO_CONFIG_MONO ) ) ) + { + DIRAC_CONFIG_FLAG flag_config; + + flag_config = DIRAC_OPEN; + if ( st_ivas->hDirAC != NULL ) + { + flag_config = DIRAC_RECONFIGURE_MODE; + } + +#ifdef IVAS_FLOAT_FIXED + if ( ( error = ivas_dirac_dec_config_fx( st_ivas, flag_config ) ) != IVAS_ERR_OK ) +#else + if ( ( error = ivas_dirac_dec_config( st_ivas, flag_config ) ) != IVAS_ERR_OK ) +#endif + { + return error; + } + } + else + { + int16_t band_grouping[IVAS_MAX_NUM_BANDS + 1]; + + st_ivas->hSpar->enc_param_start_band = min( IVAS_MAX_NUM_BANDS, SPAR_DIRAC_SPLIT_START_BAND ); + if ( ivas_get_hodirac_flag( ivas_total_brate, st_ivas->sba_analysis_order ) ) + { + st_ivas->hSpar->enc_param_start_band = 0; + + set_c( (int8_t *) st_ivas->hQMetaData->twoDirBands, (int8_t) 1, st_ivas->hQMetaData->q_direction[0].cfg.nbands ); + st_ivas->hQMetaData->numTwoDirBands = (uint8_t) st_ivas->hQMetaData->q_direction[0].cfg.nbands; + } + + ivas_dirac_config_bands( band_grouping, IVAS_MAX_NUM_BANDS, (int16_t) ( st_ivas->hDecoderConfig->output_Fs * INV_CLDFB_BANDWIDTH + 0.5f ), + st_ivas->hSpar->dirac_to_spar_md_bands, st_ivas->hQMetaData->useLowerBandRes, st_ivas->hSpar->enc_param_start_band, 0 ); + + if ( st_ivas->hDirAC ) + { + st_ivas->hDirAC->hConfig->enc_param_start_band = st_ivas->hSpar->enc_param_start_band; + } + } + + if ( st_ivas->renderer_type == RENDERER_DISABLE ) + { +#ifdef IVAS_FLOAT_FIXED + ivas_dirac_rend_close_fx(&(st_ivas->hDirACRend)); + ivas_spat_hSpatParamRendCom_close_fx(&(st_ivas->hSpatParamRendCom)); + ivas_dirac_dec_close_fx(&(st_ivas->hDirAC)); + vbap_free_data_fx(&(st_ivas->hVBAPdata)); +#else + ivas_dirac_rend_close( &( st_ivas->hDirACRend ) ); + ivas_spat_hSpatParamRendCom_close(&(st_ivas->hSpatParamRendCom)); + ivas_dirac_dec_close(&(st_ivas->hDirAC)); + vbap_free_data( &( st_ivas->hVBAPdata ) ); +#endif + } + + if ( st_ivas->hDirAC != NULL ) + { + st_ivas->hSpar->enc_param_start_band = st_ivas->hDirAC->hConfig->enc_param_start_band; + } + + /*-----------------------------------------------------------------* + * Allocate, initialize, and configure SCE/CPE/MCT handles + *-----------------------------------------------------------------*/ + + if ( st_ivas->ivas_format == SBA_ISM_FORMAT ) + { + if ( ism_mode_old == ISM_MODE_NONE && st_ivas->ism_mode == ISM_SBA_MODE_DISC ) + { + int32_t temp_brate[MAX_SCE]; + + st_ivas->ism_mode = ISM_SBA_MODE_DISC; +#ifdef IVAS_FLOAT_FIXED + IF ( ( error = ivas_ism_metadata_dec_create_fx( st_ivas, st_ivas->nchan_ism, temp_brate ) ) != IVAS_ERR_OK ) +#else + if ( ( error = ivas_ism_metadata_dec_create( st_ivas, st_ivas->nchan_ism, temp_brate ) ) != IVAS_ERR_OK ) +#endif + { + return error; + } + + if ( ( st_ivas->renderer_type == RENDERER_TD_PANNING || + st_ivas->renderer_type == RENDERER_NON_DIEGETIC_DOWNMIX || + st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC || + st_ivas->renderer_type == RENDERER_OSBA_STEREO || + st_ivas->renderer_type == RENDERER_OSBA_AMBI || + st_ivas->renderer_type == RENDERER_OSBA_LS || + st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || + st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM || + st_ivas->renderer_type == RENDERER_BINAURAL_MIXER_CONV_ROOM ) ) + { +#ifdef IVAS_FLOAT_FIXED + IF ( ( error = ivas_ism_renderer_open_fx( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } +#else + if ( ( error = ivas_ism_renderer_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } +#endif + } + + if ( st_ivas->renderer_type == RENDERER_MONO_DOWNMIX ) + { + if ( st_ivas->hMonoDmxRenderer == NULL ) + { + if ( ( error = ivas_mono_dmx_renderer_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } + else + { + ivas_mono_dmx_renderer_close( &st_ivas->hMonoDmxRenderer ); + } + + if ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV ) + { + /* Allocate TD renderer for the objects in DISC mode */ + if ( st_ivas->hBinRendererTd == NULL ) + { + if ( ( error = ivas_td_binaural_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } + + /* Allocate memory for OSBA delay buffer */ + if ( ( error = ivas_osba_data_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + + st_ivas->nCPE += ( st_ivas->nchan_ism + 1 ) >> 1; + } + else if ( ism_mode_old == ISM_SBA_MODE_DISC && st_ivas->ism_mode == ISM_MODE_NONE ) + { + /* ISM renderer handle */ + ivas_ism_renderer_close( &st_ivas->hIsmRendererData ); + ivas_ism_metadata_close( st_ivas->hIsmMetaData, 0 ); + ivas_osba_data_close( &st_ivas->hSbaIsmData ); + + /* Time Domain binaural renderer handle */ + if ( st_ivas->hBinRendererTd != NULL ) + { + if ( st_ivas->hBinRendererTd->HrFiltSet_p->ModelParams.modelROM == TRUE ) + { + ivas_td_binaural_close( &st_ivas->hBinRendererTd ); + st_ivas->hHrtfTD = NULL; + } + } + nchan_transport_old += st_ivas->nchan_ism; + st_ivas->ism_mode = ISM_MODE_NONE; + } + else if ( st_ivas->ism_mode == ISM_SBA_MODE_DISC ) + { + st_ivas->nCPE += ( st_ivas->nchan_ism + 1 ) >> 1; + nCPE_old = st_ivas->nCPE; + nchan_transport_old = st_ivas->nchan_transport; + nchan_transport_old += st_ivas->nchan_ism; + } + } + +#ifdef IVAS_FLOAT_FIXED + IF ( ( error = ivas_corecoder_dec_reconfig_fx( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, sba_dirac_stereo_flag_old, st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport, ( st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS ) ) != IVAS_ERR_OK ) + { + return error; + } +#else + if ( ( error = ivas_corecoder_dec_reconfig( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, sba_dirac_stereo_flag_old, st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport, ( st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS ) ) != IVAS_ERR_OK ) + { + return error; + } +#endif + + /*-----------------------------------------------------------------* + * HP20 memories + *-----------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED + if ((error = ivas_hp20_dec_reconfig_fx(st_ivas, nchan_hp20_old)) != IVAS_ERR_OK) + { + return error; + } +#endif // IVAS_FLOAT_FIXED + if ( ( error = ivas_hp20_dec_reconfig( st_ivas, nchan_hp20_old ) ) != IVAS_ERR_OK ) + { + return error; + } + + /*-----------------------------------------------------------------* + * TD Decorrelator + *-----------------------------------------------------------------*/ + + if ( st_ivas->hDiracDecBin != NULL ) + { + if ( ( error = ivas_td_decorr_reconfig_dec( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->hDecoderConfig->output_Fs, &( st_ivas->hDiracDecBin->hTdDecorr ), &( st_ivas->hDiracDecBin->useTdDecorr ) ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + /*-----------------------------------------------------------------* + * CLDFB instances + *-----------------------------------------------------------------*/ + + if ( ( error = ivas_cldfb_dec_reconfig( st_ivas, nchan_transport_old, numCldfbAnalyses_old, numCldfbSyntheses_old ) ) != IVAS_ERR_OK ) + { + return error; + } + + /*-----------------------------------------------------------------* + * JBM TC buffers + *-----------------------------------------------------------------*/ + + { + int16_t tc_nchan_to_allocate; + int16_t tc_nchan_tc; + TC_BUFFER_MODE tc_buffer_mode; + + tc_buffer_mode = TC_BUFFER_MODE_RENDERER; + tc_nchan_tc = ivas_jbm_dec_get_num_tc_channels( st_ivas ); + tc_nchan_to_allocate = tc_nchan_tc; + if ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_STEREO || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_MONO ) + { + if ( ( st_ivas->ivas_format == SBA_ISM_FORMAT && st_ivas->ism_mode == ISM_SBA_MODE_DISC && st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_STEREO ) ) + { + tc_nchan_tc = st_ivas->hDecoderConfig->nchan_out + st_ivas->nchan_ism; + tc_nchan_to_allocate = tc_nchan_tc; + } + else + { + tc_buffer_mode = TC_BUFFER_MODE_BUFFER; + tc_nchan_tc = st_ivas->hDecoderConfig->nchan_out; + tc_nchan_to_allocate = tc_nchan_tc; + } + } + else if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) + { + tc_nchan_to_allocate = 2 * BINAURAL_CHANNELS; + } + else if ( st_ivas->ivas_format == SBA_FORMAT || st_ivas->ivas_format == SBA_ISM_FORMAT ) + { + tc_nchan_to_allocate = ivas_sba_get_nchan_metadata( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); + + if ( st_ivas->ism_mode == ISM_SBA_MODE_DISC ) + { + tc_nchan_to_allocate += st_ivas->nchan_ism; + } + } + else + { + if ( st_ivas->nchan_transport == 1 && ( ( st_ivas->renderer_type == RENDERER_DIRAC && st_ivas->hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) || ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) ) + { + tc_nchan_to_allocate++; /* we need a channel for the CNG in this case*/ + } + } + + if ( tc_nchan_tc != st_ivas->hTcBuffer->nchan_transport_jbm || tc_nchan_to_allocate != st_ivas->hTcBuffer->nchan_transport_internal || tc_buffer_mode != st_ivas->hTcBuffer->tc_buffer_mode || granularity_new != st_ivas->hTcBuffer->n_samples_granularity ) + { + if ( ( error = ivas_jbm_dec_tc_buffer_reconfigure( st_ivas, tc_buffer_mode, tc_nchan_tc, tc_nchan_to_allocate, tc_nchan_to_allocate, granularity_new ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } + + /* resync SPAR and DirAC JBM info from TC Buffer */ + if ( st_ivas->hSpatParamRendCom != NULL && st_ivas->hSpatParamRendCom->slot_size == st_ivas->hTcBuffer->n_samples_granularity ) + { + mvs2s( st_ivas->hTcBuffer->subframe_nbslots, st_ivas->hSpatParamRendCom->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); + st_ivas->hSpatParamRendCom->nb_subframes = st_ivas->hTcBuffer->nb_subframes; + st_ivas->hSpatParamRendCom->subframes_rendered = st_ivas->hTcBuffer->subframes_rendered; + } + mvs2s( st_ivas->hTcBuffer->subframe_nbslots, st_ivas->hSpar->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); + st_ivas->hSpar->nb_subframes = st_ivas->hTcBuffer->nb_subframes; + st_ivas->hSpar->subframes_rendered = st_ivas->hTcBuffer->subframes_rendered; + + if ( st_ivas->ivas_format == SBA_ISM_FORMAT && st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV && st_ivas->ism_mode == ISM_SBA_MODE_DISC ) + { + int16_t granularityMultiplier = st_ivas->hTcBuffer->n_samples_granularity / st_ivas->hSpatParamRendCom->slot_size; + int16_t n; + for ( n = 0; n < MAX_JBM_SUBFRAMES_5MS; n++ ) + { + st_ivas->hSpatParamRendCom->subframe_nbslots[n] = st_ivas->hTcBuffer->subframe_nbslots[n] * granularityMultiplier; + st_ivas->hSpar->subframe_nbslots[n] = st_ivas->hSpatParamRendCom->subframe_nbslots[n]; + } + } + + /*-----------------------------------------------------------------* + * floating-point output audio buffers + *-----------------------------------------------------------------*/ + + nchan_out_buff = ivas_get_nchan_buffers_dec( st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); + + if ( ( error = ivas_output_buff_dec( st_ivas->p_output_f, nchan_out_buff_old, nchan_out_buff ) ) != IVAS_ERR_OK ) + { + return error; + } +#ifdef IVAS_FLOAT_FIXED + if ( ( error = ivas_output_buff_dec_fx( st_ivas->p_output_fx, nchan_out_buff_old, nchan_out_buff ) ) != IVAS_ERR_OK ) + { + return error; + } +#endif // IVAS_FLOAT_FIXED + + return error; +} +#else +/*-------------------------------------------------------------------* + * ivas_sba_dec_reconfigure_fx() + * + * Reconfigure IVAS SBA decoder + *-------------------------------------------------------------------*/ + +ivas_error ivas_sba_dec_reconfigure_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + uint16_t *nSamplesFlushed, /* o : number of samples flushed */ + int16_t *data /* o : output synthesis signal */ +) +{ + int16_t nchan_transport_old, nSCE_old, nCPE_old, nchan_hp20_old; + AUDIO_CONFIG intern_config_old; + int16_t numCldfbAnalyses_old, numCldfbSyntheses_old; + int16_t sba_dirac_stereo_flag_old; + int32_t ivas_total_brate; + int32_t last_ivas_total_brate; + int16_t num_channels, num_md_sub_frames; + int16_t nchan_out_buff, nchan_out_buff_old; + int16_t sba_analysis_order_old_flush; + DECODER_CONFIG_HANDLE hDecoderConfig; + ivas_error error; + ISM_MODE ism_mode_old; + int16_t granularity_new; + + ism_mode_old = st_ivas->ism_mode; + hDecoderConfig = st_ivas->hDecoderConfig; + ivas_total_brate = hDecoderConfig->ivas_total_brate; + last_ivas_total_brate = st_ivas->last_active_ivas_total_brate; + sba_analysis_order_old_flush = st_ivas->sba_analysis_order; + + /*-----------------------------------------------------------------* + * Set SBA high-level parameters + * Save old SBA high-level parameters + *-----------------------------------------------------------------*/ + + nchan_out_buff_old = ivas_get_nchan_buffers_dec( st_ivas, sba_analysis_order_old_flush, last_ivas_total_brate ); + + ivas_init_dec_get_num_cldfb_instances( st_ivas, &numCldfbAnalyses_old, &numCldfbSyntheses_old ); + nchan_hp20_old = getNumChanSynthesis( st_ivas ); + + if ( st_ivas->ivas_format == SBA_ISM_FORMAT ) + { + if ( ivas_total_brate >= IVAS_256k ) + { + st_ivas->ism_mode = ISM_SBA_MODE_DISC; + } + else + { + st_ivas->ism_mode = ISM_MODE_NONE; + } + } + else + { + st_ivas->ism_mode = ISM_MODE_NONE; + } + + nSCE_old = st_ivas->nSCE; + nCPE_old = st_ivas->nCPE; + nchan_transport_old = st_ivas->nchan_transport; + sba_dirac_stereo_flag_old = st_ivas->sba_dirac_stereo_flag; + + st_ivas->sba_analysis_order = ivas_sba_get_analysis_order( ivas_total_brate, st_ivas->sba_order ); + + *nSamplesFlushed = 0; + granularity_new = st_ivas->hTcBuffer->n_samples_granularity; + + /* we may need to flush only for binaural and OSBA and TSM */ + if ( st_ivas->ivas_format == SBA_ISM_FORMAT && ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) + { + RENDERER_TYPE renderer_type_new; + int16_t sba_order_internal; + + sba_order_internal = min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ); + + /* get new renderer type */ + /* copy the logic from ivas_renderer_select(), because calling this function has too many side effects that would affect the flushing */ + if ( ivas_get_sba_num_TCs( ivas_total_brate, sba_order_internal ) <= 2 ) + { + if ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL ) + { + renderer_type_new = RENDERER_BINAURAL_PARAMETRIC; + } + else + { + renderer_type_new = RENDERER_BINAURAL_PARAMETRIC_ROOM; + } + } + else + { + if ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB + ) + { + renderer_type_new = RENDERER_BINAURAL_FASTCONV; + } + else + { + renderer_type_new = RENDERER_BINAURAL_FASTCONV_ROOM; + } + } + + /* determine new granularity */ + granularity_new = NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ); + + /* this will change anyway only with binaural */ + if ( renderer_type_new == RENDERER_BINAURAL_FASTCONV && st_ivas->ism_mode == ISM_SBA_MODE_DISC ) + { + granularity_new *= JBM_CLDFB_SLOTS_IN_SUBFRAME; + } + + /* flush renderer on granularity change form 5ms to 1.25ms, again only possible for binaural rendering */ + if ( granularity_new < st_ivas->hTcBuffer->n_samples_granularity ) + { + /* write back info for correct rendering of the flushable samples */ + st_ivas->sba_analysis_order = sba_analysis_order_old_flush; + st_ivas->hDecoderConfig->ivas_total_brate = last_ivas_total_brate; - for ( int l = 0; l < numch_out; l++ ) +#ifdef IVAS_FLOAT_FIXED +#if 1 /*Float to fixed conversion*/ + DECODER_TC_BUFFER_HANDLE hTcBuffer; + hTcBuffer = st_ivas->hTcBuffer; + if ( st_ivas->hIsmRendererData ) + { + FOR( Word16 ind1 = 0; ind1 < st_ivas->hIsmRendererData->interpolator_len; ind1++ ) { - for ( int j = 0; j < numch_in; j++ ) - { - for ( int k = 0; k < num_md_sub_frames * IVAS_MAX_NUM_BANDS; k++ ) - { - hSpar->hMdDec->mixer_mat_fx[l][j][k] = floatToFixed( hSpar->hMdDec->mixer_mat[l][j][k], q1 ); - } - } + st_ivas->hIsmRendererData->interpolator_fx[ind1] = (Word16) L_min( 32767, floatToFixed( st_ivas->hIsmRendererData->interpolator_fx[ind1], 15 ) ); } - for ( int m = 0; m < MAX_PARAM_SPATIAL_SUBFRAMES + 1; m++ ) + } + FOR( Word16 ind1 = 0; ind1 < MAX_NUM_OBJECTS; ind1++ ) + { + if ( st_ivas->hIsmMetaData[ind1] ) { - for ( int j = 0; j < IVAS_MAX_FB_MIXER_OUT_CH; j++ ) - { - for ( int k = 0; k < IVAS_MAX_SPAR_FB_MIXER_IN_CH; k++ ) - { - for ( int l = 0; l < IVAS_MAX_NUM_BANDS; l++ ) - { - hSpar->hMdDec->mixer_mat_prev_fx[m][j][k][l] = floatToFixed( hSpar->hMdDec->mixer_mat_prev[m][j][k][l], q2 ); - } - } - } + st_ivas->hIsmMetaData[ind1]->azimuth_fx = (Word32) ( st_ivas->hIsmMetaData[ind1]->azimuth * ( 1 << 22 ) ); + st_ivas->hIsmMetaData[ind1]->elevation_fx = (Word32) ( st_ivas->hIsmMetaData[ind1]->elevation * ( 1 << 22 ) ); + } + } + IF( st_ivas->hCombinedOrientationData ) + FOR( Word16 ind1 = 0; ind1 < 3; ind1++ ) + { + FOR( Word16 ind2 = 0; ind2 < 3; ind2++ ) + { + st_ivas->hCombinedOrientationData->Rmat_fx[0][ind1][ind2] = (Word32) ( st_ivas->hCombinedOrientationData->Rmat[0][ind1][ind2] * ( 1 << 15 ) ); + } + } + if ( st_ivas->hSbaIsmData ) + { + for ( Word16 ch_idx = 0; ch_idx < st_ivas->hSbaIsmData->delayBuffer_nchan; ch_idx++ ) + { + floatToFixed_arr32( st_ivas->hSbaIsmData->delayBuffer[ch_idx], st_ivas->hSbaIsmData->delayBuffer_fx[ch_idx], Q11, st_ivas->hSbaIsmData->delayBuffer_size ); } + } + SPAR_DEC_HANDLE hSpar; + hSpar = st_ivas->hSpar; + uint16_t nchan_internal; + nchan_internal = ivas_sba_get_nchan_metadata( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); + DECODER_CONFIG_HANDLE hDecoderConfig; + hDecoderConfig = st_ivas->hDecoderConfig; + Word16 numch_in, numch_out, num_md_sub_frames, q1 = 30, q2 = 30; + ; + Word16 numch_out_dirac = hDecoderConfig->nchan_out; + IF( hSpar ) + { + numch_out = hSpar->hFbMixer->fb_cfg->num_out_chans; + numch_in = hSpar->hFbMixer->fb_cfg->num_in_chans; + num_md_sub_frames = ivas_get_spar_dec_md_num_subframes( st_ivas->sba_order, hDecoderConfig->ivas_total_brate, st_ivas->last_active_ivas_total_brate ); + hSpar->hMdDec->Q_mixer_mat = 30; + //for ( int l = 0; l < numch_out; l++ ) + //{ + // for ( int j = 0; j < numch_in; j++ ) + // { + // for ( int k = 0; k < num_md_sub_frames * IVAS_MAX_NUM_BANDS; k++ ) + // { + // hSpar->hMdDec->mixer_mat_fx[l][j][k] = floatToFixed( hSpar->hMdDec->mixer_mat[l][j][k], q1 ); + // } + // } + //} + //for ( int m = 0; m < MAX_PARAM_SPATIAL_SUBFRAMES + 1; m++ ) + //{ + // for ( int j = 0; j < IVAS_MAX_FB_MIXER_OUT_CH; j++ ) + // { + // for ( int k = 0; k < IVAS_MAX_SPAR_FB_MIXER_IN_CH; k++ ) + // { + // for ( int l = 0; l < IVAS_MAX_NUM_BANDS; l++ ) + // { + // hSpar->hMdDec->mixer_mat_prev_fx[m][j][k][l] = floatToFixed( hSpar->hMdDec->mixer_mat_prev[m][j][k][l], q2 ); + // } + // } + // } + //} for ( Word16 in_ch = 0; in_ch < numch_in; in_ch++ ) { for ( Word16 i = 0; i < st_ivas->cldfbAnaDec[in_ch]->p_filter_length - st_ivas->cldfbAnaDec[in_ch]->no_channels; i++ ) @@ -357,7 +1130,7 @@ ivas_error ivas_sba_dec_reconfigure( st_ivas->cldfbAnaDec[in_ch]->cldfb_state[i] = ( (float) ( st_ivas->cldfbAnaDec[in_ch]->cldfb_state_fx[i] ) / ( 1LL << ( Q11 ) ) ); } } - FOR( int m = 0; m < MAX_PARAM_SPATIAL_SUBFRAMES + 1; m++ ) + /*FOR( int m = 0; m < MAX_PARAM_SPATIAL_SUBFRAMES + 1; m++ ) { FOR( int j = 0; j < IVAS_MAX_FB_MIXER_OUT_CH; j++ ) { @@ -369,7 +1142,7 @@ ivas_error ivas_sba_dec_reconfigure( } } } - } + }*/ // fix2float (to be cleaned) IF( ( LT_32( hDecoderConfig->ivas_total_brate, IVAS_24k4 ) ) && ( ( EQ_16( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_HOA2 ) ) || ( EQ_16( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_HOA3 ) ) ) ) { @@ -391,6 +1164,14 @@ ivas_error ivas_sba_dec_reconfigure( } } } + FOR( Word16 ind1 = 0; ind1 < MAX_NUM_OBJECTS; ind1++ ) + { + if ( st_ivas->hIsmMetaData[ind1] ) + { + st_ivas->hIsmMetaData[ind1]->azimuth = (float) ( st_ivas->hIsmMetaData[ind1]->azimuth_fx ) / (float) ( 1 << 22 ); + st_ivas->hIsmMetaData[ind1]->elevation = (float) ( st_ivas->hIsmMetaData[ind1]->elevation_fx ) / (float) ( 1 << 22 ); + } + } #endif #else if ( ( error = ivas_jbm_dec_flush_renderer( st_ivas, granularity_new, st_ivas->renderer_type, st_ivas->intern_config, &st_ivas->hIntSetup, st_ivas->mc_mode, ism_mode_old, nSamplesFlushed, data ) ) != IVAS_ERR_OK ) @@ -462,7 +1243,7 @@ ivas_error ivas_sba_dec_reconfigure( { ivas_spar_dec_close( &( st_ivas->hSpar ), hDecoderConfig->output_Fs, 1 ); - if ( ( error = ivas_spar_dec_open( st_ivas, 1 ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_spar_dec_open_fx( st_ivas, 1 ) ) != IVAS_ERR_OK ) { return error; } @@ -470,10 +1251,10 @@ ivas_error ivas_sba_dec_reconfigure( else if ( last_ivas_total_brate < IVAS_24k4 && ivas_total_brate >= IVAS_24k4 ) { num_channels = st_ivas->hSpar->hMdDec->spar_md_cfg.num_umx_chs; - ivas_spar_md_dec_matrix_close( st_ivas->hSpar->hMdDec, num_channels ); + ivas_spar_md_dec_matrix_close_fx( st_ivas->hSpar->hMdDec, num_channels ); num_md_sub_frames = ivas_get_spar_dec_md_num_subframes( sba_order_internal, ivas_total_brate, st_ivas->last_active_ivas_total_brate ); - if ( ( error = ivas_spar_md_dec_matrix_open( st_ivas->hSpar->hMdDec, num_channels, num_md_sub_frames ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_spar_md_dec_matrix_open_fx( st_ivas->hSpar->hMdDec, num_channels, num_md_sub_frames ) ) != IVAS_ERR_OK ) { return error; } @@ -497,7 +1278,7 @@ ivas_error ivas_sba_dec_reconfigure( } else { - if ( ( error = ivas_spar_dec_open( st_ivas, 0 ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_spar_dec_open_fx( st_ivas, 0 ) ) != IVAS_ERR_OK ) { return error; } @@ -879,6 +1660,9 @@ ivas_error ivas_sba_dec_reconfigure( return error; } +#endif + + #ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * ivas_sba_dec_digest_tc() @@ -1341,7 +2125,8 @@ ivas_error ivas_sba_dec_render_fx( return IVAS_ERR_OK; } -#endif // IVAS_FLOAT_FIXED + +#else ivas_error ivas_sba_dec_render( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ @@ -1369,6 +2154,7 @@ ivas_error ivas_sba_dec_render( output_f_local[ch] = output_f[ch]; } + slot_size = NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ); /* loop for synthesis, assume we always have to render in multiples of 5ms subframes with spills */ @@ -1402,6 +2188,8 @@ ivas_error ivas_sba_dec_render( { floatToFixed_arr32( st_ivas->hTcBuffer->tc[i], st_ivas->hTcBuffer->tc_fx[i], Q11, st_ivas->hTcBuffer->n_samples_available ); } +#endif +#if 0 Word16 q1 = 30, q2 = 30; for ( int l = 0; l < numch_out; l++ ) { @@ -1426,6 +2214,8 @@ ivas_error ivas_sba_dec_render( } } } +#endif +#if 1 for ( Word16 in_ch = 0; in_ch < numch_in; in_ch++ ) { for ( Word16 i = 0; i < st_ivas->cldfbAnaDec[in_ch]->p_filter_length - st_ivas->cldfbAnaDec[in_ch]->no_channels; i++ ) @@ -1442,7 +2232,7 @@ ivas_error ivas_sba_dec_render( floatToFixed_arr( hSpar->hMdDec->smooth_fac, hSpar->hMdDec->smooth_fac_fx, Q15, IVAS_MAX_NUM_BANDS ); } #endif // - ivas_spar_dec_upmixer_sf_fx( st_ivas, output_f_local, nchan_internal ); + ivas_spar_dec_upmixer_sf_fx( st_ivas, output_f_local_fx, nchan_internal ); #ifdef IVAS_FLOAT_FIXED /*Fixed to float */ FOR( Word16 in_ch = 0; in_ch < numch_in; in_ch++ ) { @@ -1451,6 +2241,7 @@ ivas_error ivas_sba_dec_render( st_ivas->cldfbAnaDec[in_ch]->cldfb_state[i] = ( (float) ( st_ivas->cldfbAnaDec[in_ch]->cldfb_state_fx[i] ) / ( 1LL << ( Q11 ) ) ); /*Rounding off*/ } } +#if 0 FOR( int m = 0; m < MAX_PARAM_SPATIAL_SUBFRAMES + 1; m++ ) { FOR( int j = 0; j < IVAS_MAX_FB_MIXER_OUT_CH; j++ ) @@ -1464,6 +2255,7 @@ ivas_error ivas_sba_dec_render( } } } +#endif // fix2float (to be cleaned) IF( ( LT_32( hDecoderConfig->ivas_total_brate, IVAS_24k4 ) ) && ( ( EQ_16( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_HOA2 ) ) || ( EQ_16( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_HOA3 ) ) ) ) { @@ -1521,3 +2313,5 @@ ivas_error ivas_sba_dec_render( return IVAS_ERR_OK; } +#endif // IVAS_FLOAT_FIXED + diff --git a/lib_dec/ivas_sba_dirac_stereo_dec_fx.c b/lib_dec/ivas_sba_dirac_stereo_dec_fx.c index 4bf0e8807..b6929edf8 100644 --- a/lib_dec/ivas_sba_dirac_stereo_dec_fx.c +++ b/lib_dec/ivas_sba_dirac_stereo_dec_fx.c @@ -1170,7 +1170,8 @@ void ivas_sba_dirac_stereo_smooth_parameters_fx( { FOR ( b = 0; b < hStereoDft->nbands; b++ ) { - hStereoDft->mixer_mat_smooth_fx[i][j][b + k * IVAS_MAX_NUM_BANDS] = hMdDec->mixer_mat_fx[i][j][b]; + // The Q format of mixer_mat_fx is Q30 so applying the left shift. + hStereoDft->mixer_mat_smooth_fx[i][j][b + k * IVAS_MAX_NUM_BANDS] = L_shl_sat(hMdDec->mixer_mat_fx[i][j][b], 1); move32(); } FOR ( ; b < IVAS_MAX_NUM_BANDS; b++ ) @@ -1191,9 +1192,10 @@ void ivas_sba_dirac_stereo_smooth_parameters_fx( { Word16 beta = hStereoDft->smooth_fac_fx[k][b]; move16(); + // The Q format of mixer_mat_prev_fx is Q30 so applying the left shift. hStereoDft->mixer_mat_smooth_fx[i][j][b + k * IVAS_MAX_NUM_BANDS] = - Madd_32_16(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[i][j][b + k * IVAS_MAX_NUM_BANDS], beta), - hMdDec->mixer_mat_prev_fx[i_hist][i][j][b], sub((Word16)0x7FFF, beta)); + L_add(Mpy_32_16_1(hStereoDft->mixer_mat_smooth_fx[i][j][b + k * IVAS_MAX_NUM_BANDS], beta), + L_shl(Mpy_32_16_1(hMdDec->mixer_mat_prev_fx[i_hist][i][j][b], sub((Word16)0x7FFF, beta)), Q1)); move32(); } } diff --git a/lib_dec/ivas_sba_rendering_internal.c b/lib_dec/ivas_sba_rendering_internal.c index ec9da41ac..7ef0a5f8b 100644 --- a/lib_dec/ivas_sba_rendering_internal.c +++ b/lib_dec/ivas_sba_rendering_internal.c @@ -997,6 +997,7 @@ void ivas_sba_mix_matrix_determiner( hSpar->hMdDec->Q_mixer_mat = 31; Word16 num_in_ch; num_in_ch = hSpar->hMdDec->spar_md_cfg.num_umx_chs; +#if 0 FOR ( i_ts = 0; i_ts < num_md_sub_frames; i_ts++ ) { FOR( i = 0; i < num_out_ch; i++ ) @@ -1070,9 +1071,10 @@ void ivas_sba_mix_matrix_determiner( } } } +#endif #endif ivas_spar_dec_gen_umx_mat_fx( hSpar->hMdDec, nchan_transport, num_bands_out, bfi, num_md_sub_frames); -#if 1 /*Fixed to float changes */ +#if 0 /*Fixed to float changes */ FOR( i_ts = 0; i_ts < num_md_sub_frames; i_ts++ ) { FOR( i = 0; i < num_out_ch; i++ ) diff --git a/lib_dec/ivas_spar_decoder.c b/lib_dec/ivas_spar_decoder.c index 2fc6f2fac..af6840a9f 100644 --- a/lib_dec/ivas_spar_decoder.c +++ b/lib_dec/ivas_spar_decoder.c @@ -61,10 +61,12 @@ #ifdef IVAS_FLOAT_FIXED static ivas_error ivas_spar_dec_MD_fx( Decoder_Struct *st_ivas, Decoder_State *st0 ); -#endif +#else static ivas_error ivas_spar_dec_MD( Decoder_Struct *st_ivas, Decoder_State *st0 ); +#endif +#ifndef IVAS_FLOAT_FIXED /*------------------------------------------------------------------------- * ivas_spar_dec_open() * @@ -111,6 +113,212 @@ ivas_error ivas_spar_dec_open( num_decor_chs = num_channels_internal - 1; } + /* TD decorr. */ + if ( ( st_ivas->ivas_format == SBA_FORMAT ) && ( ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_MONO || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_STEREO ) || ( st_ivas->hDecoderConfig->ivas_total_brate >= IVAS_256k && st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_FOA ) ) ) + { + hSpar->hTdDecorr = NULL; + } + else + { + if ( ( error = ivas_td_decorr_dec_open( &hSpar->hTdDecorr, output_Fs, num_decor_chs + 1, 1 ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + /* MD handle */ + if ( ( error = ivas_spar_md_dec_open( &hSpar->hMdDec, st_ivas->hDecoderConfig, num_channels_internal, sba_order_internal, st_ivas->sid_format, st_ivas->last_active_ivas_total_brate ) ) != IVAS_ERR_OK ) + { + return error; + } + hSpar->hMdDec->td_decorr_flag = 1; + if ( hSpar->hTdDecorr ) + { + hSpar->hTdDecorr->ducking_flag = ivas_spar_br_table_consts[hSpar->hMdDec->table_idx].td_ducking; + } + + /* set FB config. */ + active_w_mixing = -1; + if ( ( error = ivas_fb_set_cfg( &fb_cfg, SBA_FORMAT, num_channels_internal, num_channels_internal, active_w_mixing, output_Fs, 0 ) ) != IVAS_ERR_OK ) + { + return error; + } + fb_cfg->pcm_offset = NS2SA( output_Fs, DELAY_FB_1_NS + IVAS_ENC_DELAY_NS + IVAS_DEC_DELAY_NS ); + fb_cfg->remix_order = remix_order_set[hSpar->hMdDec->spar_md_cfg.remix_unmix_order]; + + /* FB mixer handle */ + if ( ( error = ivas_FB_mixer_open( &hSpar->hFbMixer, output_Fs, fb_cfg, spar_reconfig_flag ) ) != IVAS_ERR_OK ) + { + return error; + } + + /* AGC handle */ + if ( ( error = ivas_spar_agc_dec_open( &hSpar->hAgcDec, output_Fs ) ) != IVAS_ERR_OK ) + { + return error; + } + + /* PCA handle */ + hSpar->hPCA = NULL; + if ( st_ivas->hDecoderConfig->ivas_total_brate == PCA_BRATE && sba_order_internal == 1 ) + { + if ( ( hSpar->hPCA = (PCA_DEC_STATE *) malloc( sizeof( PCA_DEC_STATE ) ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for PCA decoder" ); + } + + ivas_pca_dec_init( hSpar->hPCA ); + } + + /* mixer_mat intitialization */ + for ( i = 0; i < num_channels_internal; i++ ) + { + for ( j = 0; j < num_channels_internal; j++ ) + { + for ( b = 0; b < IVAS_MAX_NUM_BANDS; b++ ) + { + hSpar->hMdDec->mixer_mat[i][j][b] = 0.0f; + for ( int16_t i_ts = 0; i_ts < ( MAX_PARAM_SPATIAL_SUBFRAMES + 1 ); i_ts++ ) + { + hSpar->hMdDec->mixer_mat_prev[i_ts][i][j][b] = 0.0f; + } + } + } + } + hSpar->i_subframe = 0; + hSpar->AGC_flag = 0; + + /*-----------------------------------------------------------------* + * Configuration - set SPAR high-level parameters + *-----------------------------------------------------------------*/ + + ivas_spar_config( st_ivas->hDecoderConfig->ivas_total_brate, sba_order_internal, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &hSpar->core_nominal_brate, st_ivas->sid_format ); + + switch ( sba_order_internal ) + { + case 1: + st_ivas->transport_config = IVAS_AUDIO_CONFIG_FOA; + break; + case 2: + st_ivas->transport_config = IVAS_AUDIO_CONFIG_HOA2; + break; + case 3: + st_ivas->transport_config = IVAS_AUDIO_CONFIG_HOA3; + break; + } + + ivas_output_init( &( st_ivas->hTransSetup ), st_ivas->transport_config ); + + set_s( hSpar->subframe_nbslots, 0, MAX_JBM_SUBFRAMES_5MS ); + set_s( hSpar->subframe_nbslots, JBM_CLDFB_SLOTS_IN_SUBFRAME, DEFAULT_JBM_SUBFRAMES_5MS ); + hSpar->nb_subframes = DEFAULT_JBM_SUBFRAMES_5MS; + hSpar->subframes_rendered = 0; + hSpar->slots_rendered = 0; + hSpar->num_slots = DEFAULT_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME; + + /* init render timeslot mapping */ + set_s( hSpar->render_to_md_map, 0, MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME ); + for ( map_idx = 0; map_idx < DEFAULT_JBM_CLDFB_TIMESLOTS; map_idx++ ) + { + hSpar->render_to_md_map[map_idx] = map_idx; + } + + /* allocate transport channels*/ + if ( st_ivas->hTcBuffer == NULL ) + { + int16_t nchan_to_allocate; + int16_t nchan_tc; + TC_BUFFER_MODE buffer_mode; + int16_t granularity; + + buffer_mode = TC_BUFFER_MODE_RENDERER; + nchan_tc = ivas_jbm_dec_get_num_tc_channels( st_ivas ); + nchan_to_allocate = num_channels_internal; + + if ( st_ivas->ivas_format == SBA_ISM_FORMAT && st_ivas->ism_mode == ISM_SBA_MODE_DISC ) + { + nchan_to_allocate += st_ivas->nchan_ism; + } + + granularity = NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ); + + if ( ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_STEREO || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_MONO ) ) + { + if ( ( st_ivas->ivas_format == SBA_ISM_FORMAT && st_ivas->ism_mode == ISM_SBA_MODE_DISC && st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_STEREO ) ) + { + nchan_tc = st_ivas->hDecoderConfig->nchan_out + st_ivas->nchan_ism; + nchan_to_allocate = nchan_tc; + } + else + { + buffer_mode = TC_BUFFER_MODE_BUFFER; + nchan_tc = st_ivas->hDecoderConfig->nchan_out; + nchan_to_allocate = nchan_tc; + } + } + else if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) + { + nchan_to_allocate = 2 * BINAURAL_CHANNELS; + } + + if ( st_ivas->ivas_format == SBA_ISM_FORMAT && ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) && st_ivas->ism_mode == ISM_SBA_MODE_DISC ) + { + /* get correct granularity in case of binaural rendering of the discrete objects with the td obj renderer */ + granularity = (int16_t) ( st_ivas->hDecoderConfig->output_Fs / ( FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES ) ); + } + + if ( ( error = ivas_jbm_dec_tc_buffer_open( st_ivas, buffer_mode, nchan_tc, nchan_to_allocate, nchan_to_allocate, granularity ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + st_ivas->hSpar = hSpar; + + return error; +} + +#else +ivas_error ivas_spar_dec_open_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + const int16_t spar_reconfig_flag /* i : SPAR reconfiguration flag */ +) +{ + SPAR_DEC_HANDLE hSpar; + ivas_error error; + int16_t sba_order_internal, num_channels_internal; + IVAS_FB_CFG *fb_cfg; + int16_t i, j, b, active_w_mixing; + int32_t output_Fs; + int16_t num_decor_chs, map_idx; + + error = IVAS_ERR_OK; + + sba_order_internal = min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ); + + num_channels_internal = ivas_sba_get_nchan_metadata( sba_order_internal, st_ivas->hDecoderConfig->ivas_total_brate ); + + hSpar = st_ivas->hSpar; + + if ( !spar_reconfig_flag ) + { + /* SPAR decoder handle */ + if ( ( hSpar = (SPAR_DEC_HANDLE) malloc( sizeof( SPAR_DEC_DATA ) ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR decoder" ); + } + } + + output_Fs = st_ivas->hDecoderConfig->output_Fs; + if ( num_channels_internal > ( SBA_HOA2_ORDER + 1 ) * ( SBA_HOA2_ORDER + 1 ) ) + { + num_decor_chs = IVAS_HBR_MAX_DECOR_CHS; + } + else + { + num_decor_chs = num_channels_internal - 1; + } + /* TD decorr. */ if ( ( st_ivas->ivas_format == SBA_FORMAT ) && ( ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_MONO || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_STEREO ) || ( st_ivas->hDecoderConfig->ivas_total_brate >= IVAS_256k && st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_FOA ) ) ) { @@ -187,10 +395,10 @@ ivas_error ivas_spar_dec_open( { for ( b = 0; b < IVAS_MAX_NUM_BANDS; b++ ) { - hSpar->hMdDec->mixer_mat[i][j][b] = 0.0f; + hSpar->hMdDec->mixer_mat_fx[i][j][b] = 0; for ( int16_t i_ts = 0; i_ts < ( MAX_PARAM_SPATIAL_SUBFRAMES + 1 ); i_ts++ ) { - hSpar->hMdDec->mixer_mat_prev[i_ts][i][j][b] = 0.0f; + hSpar->hMdDec->mixer_mat_prev_fx[i_ts][i][j][b] = 0; } } } @@ -291,7 +499,7 @@ ivas_error ivas_spar_dec_open( return error; } - +#endif /*------------------------------------------------------------------------- * ivas_spar_dec_close() @@ -381,6 +589,12 @@ ivas_error ivas_spar_dec_fx( { FOR( k = 0; k < MAX_PARAM_SPATIAL_SUBFRAMES; k++ ) { + Word32 tmp = 0; + tmp = (Word32) ( q_direction->band_data[j].elevation[k] * ( 1 << 22 ) ); + if (GT_32(L_abs(sub(tmp, q_direction->band_data[j].elevation_fx[k])), 1 << Q5)) + { + assert(0); + } q_direction->band_data[j].elevation_fx[k] = (Word32) ( q_direction->band_data[j].elevation[k] * ( 1 << 22 ) ); q_direction->band_data[j].azimuth_fx[k] = (Word32) ( q_direction->band_data[j].azimuth[k] * ( 1 << 22 ) ); q_direction->band_data[j].energy_ratio_fx[k] = (Word32) ( q_direction->band_data[j].energy_ratio[k] * ( 1 << 30 ) ); @@ -536,7 +750,7 @@ ivas_error ivas_spar_dec_fx( return error; } -#endif +#else ivas_error ivas_spar_dec( Decoder_Struct *st_ivas, /* i/o: IVAS decoder struct */ int16_t *nb_bits_read /* o : number of MD bits read */ @@ -569,49 +783,8 @@ ivas_error ivas_spar_dec( /* read DirAC bitstream */ if ( st_ivas->hQMetaData != NULL ) - { -#ifdef IVAS_FLOAT_FIXED - // To do remove this code once ivas_spar_dec_MD is done - for ( int d = 0; d < st_ivas->hQMetaData->no_directions; d++ ) - { - IVAS_QDIRECTION *q_direction; - q_direction = &st_ivas->hQMetaData->q_direction[d]; - int nbands = q_direction->cfg.nbands; - FOR( Word16 j = 0; j < nbands; j++ ) - { - FOR( Word16 k = 0; k < MAX_PARAM_SPATIAL_SUBFRAMES; k++ ) - { - q_direction->band_data[j].elevation_fx[k] = (Word32) ( q_direction->band_data[j].elevation[k] * ( 1 << 22 ) ); - q_direction->band_data[j].azimuth_fx[k] = (Word32) ( q_direction->band_data[j].azimuth[k] * ( 1 << 22 ) ); - q_direction->band_data[j].energy_ratio_fx[k] = (Word32) ( q_direction->band_data[j].energy_ratio[k] * ( 1 << 30 ) ); - } - } - } -#endif -#ifdef IVAS_FLOAT_FIXED - ivas_dirac_dec_read_BS_fx( hDecoderConfig->ivas_total_brate, st0, st_ivas->hDirAC, st_ivas->hSpatParamRendCom, st_ivas->hQMetaData, nb_bits_read, last_bit_pos, ivas_get_hodirac_flag( hDecoderConfig->ivas_total_brate, st_ivas->sba_analysis_order ), st_ivas->hSpar->dirac_to_spar_md_bands ); -#else + { ivas_dirac_dec_read_BS( hDecoderConfig->ivas_total_brate, st0, st_ivas->hDirAC, st_ivas->hSpatParamRendCom, st_ivas->hQMetaData, nb_bits_read, last_bit_pos, ivas_get_hodirac_flag( hDecoderConfig->ivas_total_brate, st_ivas->sba_analysis_order ), st_ivas->hSpar->dirac_to_spar_md_bands ); -#endif -#ifdef IVAS_FLOAT_FIXED - // To do remove this code once ivas_spar_dec_MD is done - for ( int d = 0; d < st_ivas->hQMetaData->no_directions; d++ ) - { - IVAS_QDIRECTION *q_direction; - q_direction = &st_ivas->hQMetaData->q_direction[d]; - int nbands = q_direction->cfg.nbands; - FOR( Word16 j = 0; j < nbands; j++ ) - { - FOR( Word16 k = 0; k < MAX_PARAM_SPATIAL_SUBFRAMES; k++ ) - { - - q_direction->band_data[j].elevation[k] = ( (float) q_direction->band_data[j].elevation_fx[k] / ( 1 << 22 ) ); - q_direction->band_data[j].azimuth[k] = ( (float) q_direction->band_data[j].azimuth_fx[k] / ( 1 << 22 ) ); - q_direction->band_data[j].energy_ratio[k] = ( (float) q_direction->band_data[j].energy_ratio_fx[k] / ( 1 << 30 ) ); - } - } - } -#endif } if ( st_ivas->ivas_format == SBA_ISM_FORMAT ) @@ -670,6 +843,7 @@ ivas_error ivas_spar_dec( return error; } +#endif /*---------------------------------------------------------------------* @@ -1429,10 +1603,10 @@ static ivas_error ivas_spar_dec_MD_fx( * Decode MD *---------------------------------------------------------------------*/ - ivas_spar_md_dec_process( st_ivas, st0, num_bands_out, sba_order ); + ivas_spar_md_dec_process_fx( st_ivas, st0, num_bands_out, sba_order ); // Till here TBD -#ifndef IVAS_FLOAT_FIXED_TO_BE_REMOVED +#if 0 //ndef IVAS_FLOAT_FIXED_TO_BE_REMOVED // float to fix Word16 num_channels_tmp = hSpar->hMdDec->spar_md_cfg.num_umx_chs; FOR( i = 0; i < num_channels_tmp; i++ ) @@ -1493,8 +1667,9 @@ static ivas_error ivas_spar_dec_MD_fx( ivas_spar_update_md_hist_fx( hSpar->hMdDec ); } -#ifndef IVAS_FLOAT_FIXED_TO_BE_REMOVED +#if 0 //ndef IVAS_FLOAT_FIXED_TO_BE_REMOVED // fix to float + Word16 num_channels_tmp = hSpar->hMdDec->spar_md_cfg.num_umx_chs; FOR( i = 0; i < num_channels_tmp; i++ ) { FOR( j = 0; j < num_channels_tmp; j++ ) @@ -1514,7 +1689,7 @@ static ivas_error ivas_spar_dec_MD_fx( } ELSE { -#ifndef IVAS_FLOAT_FIXED_TO_BE_REMOVED +#if 0 //ndef IVAS_FLOAT_FIXED_TO_BE_REMOVED // float to fix Word16 num_channels_tmp = hSpar->hMdDec->spar_md_cfg.num_umx_chs; FOR( i = 0; i < num_channels_tmp; i++ ) @@ -1540,7 +1715,8 @@ static ivas_error ivas_spar_dec_MD_fx( } set_s( hSpar->hMdDec->valid_bands, 0, IVAS_MAX_NUM_BANDS ); -#ifndef IVAS_FLOAT_FIXED_TO_BE_REMOVED +#if 0 //ndef IVAS_FLOAT_FIXED_TO_BE_REMOVED + Word16 num_channels_tmp = hSpar->hMdDec->spar_md_cfg.num_umx_chs; FOR( i = 0; i < num_channels_tmp; i++ ) { FOR( j = 0; j < num_channels_tmp; j++ ) @@ -1563,7 +1739,7 @@ static ivas_error ivas_spar_dec_MD_fx( pop_wmops(); return IVAS_ERR_OK; } -#endif +#else static ivas_error ivas_spar_dec_MD( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ Decoder_State *st0 /* i/o: decoder state structure - for bitstream handling*/ @@ -1632,12 +1808,7 @@ static ivas_error ivas_spar_dec_MD( if ( hSpar->hPCA != NULL ) { -#ifdef IVAS_FLOAT_FIXED - ivas_pca_read_bits_fx(st0, hSpar->hPCA); -#else - ivas_pca_read_bits(st0, hSpar->hPCA); -#endif - + ivas_pca_read_bits( st0, hSpar->hPCA ); } /*---------------------------------------------------------------------* @@ -1651,12 +1822,7 @@ static ivas_error ivas_spar_dec_MD( hSpar->AGC_flag = get_next_indice( st0, 1 ); } -#ifndef IVAS_FLOAT_FIXED ivas_agc_read_bits( hSpar->hAgcDec, st0, hSpar->hMdDec->spar_md_cfg.nchan_transport, hSpar->AGC_flag ); -#else - ivas_agc_read_bits_fx( hSpar->hAgcDec, st0, hSpar->hMdDec->spar_md_cfg.nchan_transport, hSpar->AGC_flag ); -#endif // IVAS_FLOAT_FIXED - } /*---------------------------------------------------------------------* @@ -1685,6 +1851,7 @@ static ivas_error ivas_spar_dec_MD( pop_wmops(); return IVAS_ERR_OK; } +#endif /*-------------------------------------------------------------------* @@ -1780,7 +1947,7 @@ static Word16 ivas_spar_get_cldfb_slot_gain_fx( return weight_fx; } -#endif +#else static float ivas_spar_get_cldfb_slot_gain( SPAR_DEC_HANDLE hSpar, /* i/o: SPAR decoder handle */ const DECODER_CONFIG_HANDLE hDecoderConfig, /* i : configuration structure */ @@ -1789,47 +1956,48 @@ static float ivas_spar_get_cldfb_slot_gain( int16_t *time_slot_idx1, float *weight_lowfreq) { - float weight; - float output_Fs, encfb_delay, decfb_delay; - float xfade_start_ns; - int16_t xfade_delay_subframes; - int16_t i_hist; - int16_t split_band; + float weight; + float output_Fs, encfb_delay, decfb_delay; + float xfade_start_ns; + int16_t xfade_delay_subframes; + int16_t i_hist; + int16_t split_band; - *weight_lowfreq = hSpar->hFbMixer->cldfb_cross_fade[time_slot_idx]; + *weight_lowfreq = hSpar->hFbMixer->cldfb_cross_fade[time_slot_idx]; - output_Fs = (float)hDecoderConfig->output_Fs; - encfb_delay = IVAS_FB_ENC_DELAY_NS; - decfb_delay = IVAS_FB_DEC_DELAY_NS; - xfade_start_ns = hSpar->hFbMixer->cross_fade_start_offset / output_Fs * 1000000000.f - encfb_delay + decfb_delay * 0.5f; - xfade_delay_subframes = (int16_t)(xfade_start_ns / (FRAME_SIZE_NS / MAX_PARAM_SPATIAL_SUBFRAMES)); + output_Fs = (float) hDecoderConfig->output_Fs; + encfb_delay = IVAS_FB_ENC_DELAY_NS; + decfb_delay = IVAS_FB_DEC_DELAY_NS; + xfade_start_ns = hSpar->hFbMixer->cross_fade_start_offset / output_Fs * 1000000000.f - encfb_delay + decfb_delay * 0.5f; + xfade_delay_subframes = (int16_t) ( xfade_start_ns / ( FRAME_SIZE_NS / MAX_PARAM_SPATIAL_SUBFRAMES ) ); - i_hist = 4 - xfade_delay_subframes; - split_band = SPAR_DIRAC_SPLIT_START_BAND; + i_hist = 4 - xfade_delay_subframes; + split_band = SPAR_DIRAC_SPLIT_START_BAND; - if (split_band < IVAS_MAX_NUM_BANDS) - { - if (hSpar->i_subframe > 3) + if ( split_band < IVAS_MAX_NUM_BANDS ) { - weight = (float)(time_slot_idx % MAX_PARAM_SPATIAL_SUBFRAMES) / (float)MAX_PARAM_SPATIAL_SUBFRAMES; + if ( hSpar->i_subframe > 3 ) + { + weight = (float) ( time_slot_idx % MAX_PARAM_SPATIAL_SUBFRAMES ) / (float) MAX_PARAM_SPATIAL_SUBFRAMES; + } + else + { + weight = 0.0f; + } + *time_slot_idx0 = i_hist; + *time_slot_idx1 = i_hist + 1; } else { - weight = 0.0f; + /* determine cross-fade gain for current frame Parameters*/ + *time_slot_idx0 = hSpar->hFbMixer->cldfb_cross_fade_start; + *time_slot_idx1 = hSpar->hFbMixer->cldfb_cross_fade_end; + weight = *weight_lowfreq; } - *time_slot_idx0 = i_hist; - *time_slot_idx1 = i_hist + 1; - } - else - { - /* determine cross-fade gain for current frame Parameters*/ - *time_slot_idx0 = hSpar->hFbMixer->cldfb_cross_fade_start; - *time_slot_idx1 = hSpar->hFbMixer->cldfb_cross_fade_end; - weight = *weight_lowfreq; - } - return weight; + return weight; } +#endif /*-------------------------------------------------------------------* @@ -1849,11 +2017,69 @@ void ivas_spar_get_parameters_fx( ) { int16_t spar_band, out_ch, in_ch; - Word16 weight_fx, weight_20ms_fx; + Word16 weight_fx, weight_20ms_fx; + int16_t ts0, ts1, split_band; + + //weight = ivas_spar_get_cldfb_slot_gain(hSpar, hDecoderConfig, ts, &ts0, &ts1, &weight_20ms); + weight_fx = ivas_spar_get_cldfb_slot_gain_fx( hSpar, hDecoderConfig, ts, &ts0, &ts1, &weight_20ms_fx); + + split_band = SPAR_DIRAC_SPLIT_START_BAND; + for ( spar_band = 0; spar_band < num_spar_bands; spar_band++ ) + { + for ( out_ch = 0; out_ch < num_ch_out; out_ch++ ) + { + if ( split_band < IVAS_MAX_NUM_BANDS + /* 20ms cross-fade for Transport channels in all frequency bands */ + && ( 0 == ivas_is_res_channel( out_ch, hSpar->hMdDec->spar_md_cfg.nchan_transport ) ) /* sub-frame processing for missing channels in all frequency bands*/ + ) + { + for ( in_ch = 0; in_ch < num_ch_in; in_ch++ ) + { + if ( hSpar->i_subframe > 3 ) + { + + par_mat_fx[out_ch][in_ch][spar_band] = L_add_sat(Mpy_32_16_1(hSpar->hMdDec->mixer_mat_prev_fx[ts0][out_ch][in_ch][spar_band], sub(MAX_WORD16, weight_fx)), + Mpy_32_16_1(hSpar->hMdDec->mixer_mat_prev_fx[ts1][out_ch][in_ch][spar_band], weight_fx)); + } + else + { + par_mat_fx[out_ch][in_ch][spar_band] = hSpar->hMdDec->mixer_mat_fx[out_ch][in_ch][spar_band]; + } + + } + } + else + { + for ( in_ch = 0; in_ch < num_ch_in; in_ch++ ) + { + /* 20ms Transport channel reconstruction with matching encoder/decoder processing */ + int16_t prev_idx = SPAR_DIRAC_SPLIT_START_BAND < IVAS_MAX_NUM_BANDS ? 1 : 0; /* if SPAR_DIRAC_SPLIT_START_BAND == IVAS_MAX_NUM_BANDS, then the sub-frame mixer_mat delay line is not active */ + par_mat_fx[out_ch][in_ch][spar_band] = L_add_sat(Mpy_32_16_1(hSpar->hMdDec->mixer_mat_prev_fx[prev_idx][out_ch][in_ch][spar_band], sub(MAX_WORD16, weight_20ms_fx)) + ,Mpy_32_16_1(hSpar->hMdDec->mixer_mat_fx[out_ch][in_ch][spar_band], weight_20ms_fx)); + + } + } + } + } + + return; +} +#else + +void ivas_spar_get_parameters( + SPAR_DEC_HANDLE hSpar, /* i/o: SPAR decoder handle */ + const DECODER_CONFIG_HANDLE hDecoderConfig, /* i : configuration structure */ + const int16_t ts, + const int16_t num_ch_out, + const int16_t num_ch_in, + const int16_t num_spar_bands, + float par_mat[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS]) +{ + int16_t spar_band, out_ch, in_ch; + float weight, weight_20ms; int16_t ts0, ts1, split_band; - //weight = ivas_spar_get_cldfb_slot_gain(hSpar, hDecoderConfig, ts, &ts0, &ts1, &weight_20ms); - weight_fx = ivas_spar_get_cldfb_slot_gain_fx( hSpar, hDecoderConfig, ts, &ts0, &ts1, &weight_20ms_fx); + weight = ivas_spar_get_cldfb_slot_gain( hSpar, hDecoderConfig, ts, &ts0, &ts1, &weight_20ms ); split_band = SPAR_DIRAC_SPLIT_START_BAND; for ( spar_band = 0; spar_band < num_spar_bands; spar_band++ ) @@ -1869,15 +2095,13 @@ void ivas_spar_get_parameters_fx( { if ( hSpar->i_subframe > 3 ) { - - par_mat_fx[out_ch][in_ch][spar_band] = L_add_sat(Mpy_32_16_1(hSpar->hMdDec->mixer_mat_prev_fx[ts0][out_ch][in_ch][spar_band], sub(MAX_WORD16, weight_fx)), - Mpy_32_16_1(hSpar->hMdDec->mixer_mat_prev_fx[ts1][out_ch][in_ch][spar_band], weight_fx)); + par_mat[out_ch][in_ch][spar_band] = ( 1.0f - weight ) * hSpar->hMdDec->mixer_mat_prev[ts0][out_ch][in_ch][spar_band] + + weight * hSpar->hMdDec->mixer_mat_prev[ts1][out_ch][in_ch][spar_band]; } else { - par_mat_fx[out_ch][in_ch][spar_band] = hSpar->hMdDec->mixer_mat_fx[out_ch][in_ch][spar_band]; + par_mat[out_ch][in_ch][spar_band] = hSpar->hMdDec->mixer_mat[out_ch][in_ch][spar_band]; } - } } else @@ -1886,9 +2110,7 @@ void ivas_spar_get_parameters_fx( { /* 20ms Transport channel reconstruction with matching encoder/decoder processing */ int16_t prev_idx = SPAR_DIRAC_SPLIT_START_BAND < IVAS_MAX_NUM_BANDS ? 1 : 0; /* if SPAR_DIRAC_SPLIT_START_BAND == IVAS_MAX_NUM_BANDS, then the sub-frame mixer_mat delay line is not active */ - par_mat_fx[out_ch][in_ch][spar_band] = L_add_sat(Mpy_32_16_1(hSpar->hMdDec->mixer_mat_prev_fx[prev_idx][out_ch][in_ch][spar_band], sub(MAX_WORD16, weight_20ms_fx)) - ,Mpy_32_16_1(hSpar->hMdDec->mixer_mat_fx[out_ch][in_ch][spar_band], weight_20ms_fx)); - + par_mat[out_ch][in_ch][spar_band] = ( 1.0f - weight_20ms ) * hSpar->hMdDec->mixer_mat_prev[prev_idx][out_ch][in_ch][spar_band] + weight_20ms * hSpar->hMdDec->mixer_mat[out_ch][in_ch][spar_band]; } } } @@ -1897,58 +2119,6 @@ void ivas_spar_get_parameters_fx( return; } #endif -void ivas_spar_get_parameters( - SPAR_DEC_HANDLE hSpar, /* i/o: SPAR decoder handle */ - const DECODER_CONFIG_HANDLE hDecoderConfig, /* i : configuration structure */ - const int16_t ts, - const int16_t num_ch_out, - const int16_t num_ch_in, - const int16_t num_spar_bands, - float par_mat[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS]) -{ - int16_t spar_band, out_ch, in_ch; - float weight, weight_20ms; - int16_t ts0, ts1, split_band; - - weight = ivas_spar_get_cldfb_slot_gain(hSpar, hDecoderConfig, ts, &ts0, &ts1, &weight_20ms); - - split_band = SPAR_DIRAC_SPLIT_START_BAND; - for (spar_band = 0; spar_band < num_spar_bands; spar_band++) - { - for (out_ch = 0; out_ch < num_ch_out; out_ch++) - { - if (split_band < IVAS_MAX_NUM_BANDS - /* 20ms cross-fade for Transport channels in all frequency bands */ - && (0 == ivas_is_res_channel(out_ch, hSpar->hMdDec->spar_md_cfg.nchan_transport)) /* sub-frame processing for missing channels in all frequency bands*/ - ) - { - for (in_ch = 0; in_ch < num_ch_in; in_ch++) - { - if (hSpar->i_subframe > 3) - { - par_mat[out_ch][in_ch][spar_band] = (1.0f - weight) * hSpar->hMdDec->mixer_mat_prev[ts0][out_ch][in_ch][spar_band] + - weight * hSpar->hMdDec->mixer_mat_prev[ts1][out_ch][in_ch][spar_band]; - } - else - { - par_mat[out_ch][in_ch][spar_band] = hSpar->hMdDec->mixer_mat[out_ch][in_ch][spar_band]; - } - } - } - else - { - for (in_ch = 0; in_ch < num_ch_in; in_ch++) - { - /* 20ms Transport channel reconstruction with matching encoder/decoder processing */ - int16_t prev_idx = SPAR_DIRAC_SPLIT_START_BAND < IVAS_MAX_NUM_BANDS ? 1 : 0; /* if SPAR_DIRAC_SPLIT_START_BAND == IVAS_MAX_NUM_BANDS, then the sub-frame mixer_mat delay line is not active */ - par_mat[out_ch][in_ch][spar_band] = (1.0f - weight_20ms) * hSpar->hMdDec->mixer_mat_prev[prev_idx][out_ch][in_ch][spar_band] + weight_20ms * hSpar->hMdDec->mixer_mat[out_ch][in_ch][spar_band]; - } - } - } - } - - return; -} /*-------------------------------------------------------------------* * ivas_spar_get_skip_mat() @@ -1956,6 +2126,7 @@ void ivas_spar_get_parameters( * *-------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED static void ivas_spar_get_skip_mat( SPAR_DEC_HANDLE hSpar, /* i/o: SPAR decoder handle */ const int16_t num_ch_out, @@ -2017,7 +2188,7 @@ static void ivas_spar_get_skip_mat( return; } -#ifdef IVAS_FLOAT_FIXED +#else static void ivas_spar_get_skip_mat_fx( SPAR_DEC_HANDLE hSpar, /* i/o: SPAR decoder handle */ const Word16 num_ch_out, @@ -2295,6 +2466,7 @@ static void ivas_spar_calc_smooth_facs( * *-------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED void ivas_spar_dec_agc_pca( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ float *output[], /* i/o: input/output audio channels */ @@ -2338,42 +2510,7 @@ void ivas_spar_dec_agc_pca( * AGC *---------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED ivas_agc_dec_process( hSpar->hAgcDec, output, output, nchan_transport, output_frame ); -#ifdef DUMPS_ENABLED - dbgwrite_txt( &output[0][0], output_frame, "flt_ivas_agc_dec_process_output.txt", NULL ); -#endif // DUMPS_ENABLED -#else - Word32 *output_fx[20]; - FOR( Word16 i = 0; i < nchan_transport; i++ ) - { - output_fx[i] = malloc( ( 48000 / FRAMES_PER_SEC ) * sizeof( Word32 ) ); - FOR( Word16 j = 0; j < output_frame; j++ ) - { - output_fx[i][j] = (Word32) ( output[i][j] * ONE_IN_Q14 ); - } - } - - ivas_agc_dec_process_fx( hSpar->hAgcDec, ( output_fx ), ( output_fx ), nchan_transport, output_frame ); - - FOR( Word16 i = 0; i < nchan_transport; i++ ) - { - FOR( Word16 j = 0; j < output_frame; j++ ) - { - output[i][j] = (float) output_fx[i][j] / ONE_IN_Q11; - } - } - -#ifdef DUMPS_ENABLED - dbgwrite_txt( &output[0][0], output_frame, "fix_ivas_agc_dec_process_output.txt", NULL ); -#endif // DUMPS_ENABLED - - FOR( Word16 i = 0; i < nchan_transport; i++ ) - { - free( output_fx[i] ); - } - -#endif // !IVAS_FLOAT_FIXED if ( hSpar->hPCA != NULL ) { @@ -2384,7 +2521,7 @@ void ivas_spar_dec_agc_pca( return; } -#ifdef IVAS_FLOAT_FIXED +#else void ivas_spar_dec_agc_pca_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ Word32 *output[], /* i/o: input/output audio channels */ @@ -2447,7 +2584,7 @@ void ivas_spar_dec_agc_pca_fx( * * *-------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED void ivas_spar_dec_set_render_map( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const int16_t nCldfbTs /* i : number of CLDFB time slots */ @@ -2477,7 +2614,7 @@ void ivas_spar_dec_set_render_map( return; } -#ifdef IVAS_FLOAT_FIXED +#else void ivas_spar_dec_set_render_map_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const Word16 nCldfbTs /* i : number of CLDFB time slots */ @@ -2509,6 +2646,7 @@ void ivas_spar_dec_set_render_map_fx( } #endif +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * ivas_spar_dec_upmixer() * @@ -2533,7 +2671,7 @@ void ivas_spar_dec_set_render_params( return; } -#ifdef IVAS_FLOAT_FIXED +#else void ivas_spar_dec_set_render_params_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ const Word16 n_cldfb_slots /* i : number of cldfb slots in this frame */ @@ -2559,7 +2697,7 @@ void ivas_spar_dec_set_render_params_fx( * * *-------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED void ivas_spar_dec_digest_tc( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ const int16_t nchan_transport, /* i : number of transport channels */ @@ -2605,40 +2743,7 @@ void ivas_spar_dec_digest_tc( if ( hSpar->hTdDecorr ) { -#ifndef IVAS_FLOAT_FIXED ivas_td_decorr_process( hSpar->hTdDecorr, p_tc, pPcm_tmp, nSamplesToDecorr ); -#else - { - Word32 *pPcm_tmp_fx[MAX_SPAR_INTERNAL_CHANNELS]; - Word32 *p_tc_fx[MAX_SPAR_INTERNAL_CHANNELS]; - Word32 pcm_tmp_fx[MAX_SPAR_INTERNAL_CHANNELS][L_FRAME48k]; - Word32 tc_fx[MAX_SPAR_INTERNAL_CHANNELS][L_FRAME48k]; - Word32 i, j; - Word16 q_format = Q14; - - FOR( i = 0; i < nchan_internal; i++ ) - { - pPcm_tmp_fx[i] = pcm_tmp_fx[i]; - p_tc_fx[i] = tc_fx[i]; - } - FOR( j = 0; j < nSamplesToDecorr; j++ ) - { - p_tc_fx[0][j] = (Word32) ( p_tc[0][j] * ( 1 << q_format ) ); - } - ivas_td_decorr_process_fx( hSpar->hTdDecorr, p_tc_fx, pPcm_tmp_fx, nSamplesToDecorr, &q_format ); - - FOR( i = 0; i < hSpar->hTdDecorr->num_apd_outputs; i++ ) - { - FOR( j = 0; j < nSamplesToDecorr; j++ ) - { - pPcm_tmp[i][j] = ( pPcm_tmp_fx[i][j] ) / (float) ( 1 << q_format ); - } -#ifdef DUMPS_ENABLED - dbgwrite_txt( decorr_signal[i], nSamplesToDecorr, "fixed.txt", NULL ); -#endif - } - } -#endif if ( hSpar->hTdDecorr->num_apd_outputs >= ( nchan_internal - nchan_transport ) ) { for ( ch = 0; ch < nchan_internal - nchan_transport; ch++ ) @@ -2671,7 +2776,7 @@ void ivas_spar_dec_digest_tc( return; } -#ifdef IVAS_FLOAT_FIXED +#else void ivas_spar_dec_digest_tc_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ const Word16 nchan_transport, /* i : number of transport channels */ @@ -2756,6 +2861,7 @@ void ivas_spar_dec_digest_tc_fx( } #endif +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * ivas_spar_dec_upmixer() * @@ -2816,41 +2922,8 @@ void ivas_spar_dec_upmixer( { if ( hSpar->hTdDecorr ) { -#ifndef IVAS_FLOAT_FIXED ivas_td_decorr_process( hSpar->hTdDecorr, output_f_local, pPcm_tmp, output_frame ); -#else - { - Word32 *output_f_local_fx[MAX_OUTPUT_CHANNELS]; - Word32 *pPcm_tmp_fx[MAX_OUTPUT_CHANNELS]; - Word32 arr_output_f_local_fx[MAX_OUTPUT_CHANNELS][L_FRAME48k]; - Word32 pcm_tmp_fx[MAX_OUTPUT_CHANNELS][L_FRAME48k]; - Word32 j; - Word16 q_format = Q14; - - FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++ ) - { - pPcm_tmp_fx[i] = pcm_tmp_fx[i]; - output_f_local_fx[i] = arr_output_f_local_fx[i]; - } - - FOR( j = 0; j < output_frame; j++ ) - { - output_f_local_fx[0][j] = (Word32) ( output_f_local[0][j] * ( 1 << q_format ) ); - } - ivas_td_decorr_process_fx( hSpar->hTdDecorr, output_f_local_fx, pPcm_tmp_fx, output_frame, &q_format ); - FOR( i = 0; i < hSpar->hTdDecorr->num_apd_outputs; i++ ) - { - FOR( j = 0; j < output_frame; j++ ) - { - pPcm_tmp[i][j] = ( pPcm_tmp_fx[i][j] ) / (float) ( 1 << q_format ); - } -#ifdef DUMPS_ENABLED - dbgwrite_txt( decorr_signal[i], nSamplesToDecorr, "fixed.txt", NULL ); -#endif - } - } -#endif if ( hSpar->hTdDecorr->num_apd_outputs >= ( nchan_internal - nchan_transport ) ) { for ( i = 0; i < nchan_internal - nchan_transport; i++ ) @@ -2877,116 +2950,12 @@ void ivas_spar_dec_upmixer( if ( st_ivas->hDirAC != 0 ) { -#ifdef IVAS_FLOAT_FIXED - ivas_dirac_dec_set_md_map_fx( st_ivas, DEFAULT_JBM_CLDFB_TIMESLOTS ); -#else ivas_dirac_dec_set_md_map( st_ivas, DEFAULT_JBM_CLDFB_TIMESLOTS ); -#endif } for ( subframe_idx = 0; subframe_idx < MAX_PARAM_SPATIAL_SUBFRAMES; subframe_idx++ ) { -#ifdef IVAS_FLOAT_FIXED1 -#if 1 /*Float to fixed conversion*/ - Word16 numch_out = hSpar->hFbMixer->fb_cfg->num_out_chans; - Word16 numch_in = hSpar->hFbMixer->fb_cfg->num_in_chans; - Word16 num_spar_bands = hSpar->hFbMixer->pFb->filterbank_num_bands; - DECODER_CONFIG_HANDLE hDecoderConfig; - hDecoderConfig = st_ivas->hDecoderConfig; - Word16 numch_out_dirac = hDecoderConfig->nchan_out; - - Word16 num_md_sub_frames = ivas_get_spar_dec_md_num_subframes( st_ivas->sba_order, hDecoderConfig->ivas_total_brate, st_ivas->last_active_ivas_total_brate ); - - for ( int i = 0; i < s_max( st_ivas->nchan_ism, 0 ) + nchan_internal; i++ ) - { - floatToFixed_arr32( st_ivas->hTcBuffer->tc[i], st_ivas->hTcBuffer->tc_fx[i], Q11, st_ivas->hTcBuffer->n_samples_available ); - } - Word16 q1 = 30, q2 = 30; - for ( int l = 0; l < numch_out; l++ ) - { - for ( int j = 0; j < numch_in; j++ ) - { - for ( int k = 0; k < num_md_sub_frames * IVAS_MAX_NUM_BANDS; k++ ) - { - hSpar->hMdDec->mixer_mat_fx[l][j][k] = floatToFixed( hSpar->hMdDec->mixer_mat[l][j][k] , q1 ); - } - } - } - for ( int m = 0; m < MAX_PARAM_SPATIAL_SUBFRAMES + 1; m++ ) - { - for ( int j = 0; j < IVAS_MAX_FB_MIXER_OUT_CH; j++ ) - { - for ( int k = 0; k < IVAS_MAX_SPAR_FB_MIXER_IN_CH; k++ ) - { - for ( int l = 0; l < IVAS_MAX_NUM_BANDS; l++ ) - { - hSpar->hMdDec->mixer_mat_prev_fx[m][j][k][l] = floatToFixed(hSpar->hMdDec->mixer_mat_prev[m][j][k][l] , q2 ); - } - } - } - } - for ( Word16 in_ch = 0; in_ch < numch_in; in_ch++ ) - { - for ( Word16 i = 0; i < st_ivas->cldfbAnaDec[in_ch]->p_filter_length - st_ivas->cldfbAnaDec[in_ch]->no_channels; i++ ) - { - st_ivas->cldfbAnaDec[in_ch]->cldfb_state_fx[i] = (Word32) ( st_ivas->cldfbAnaDec[in_ch]->cldfb_state[i] * ( 1LL << ( Q11 ) ) ); - } - } - if ( ( hDecoderConfig->ivas_total_brate < IVAS_24k4 ) && ( ( hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_HOA2 ) || ( hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_HOA3 ) ) ) - { - for ( Word16 i = 0; i < IVAS_MAX_NUM_BANDS; i++ ) - { - floatToFixed_arrL( hSpar->hMdDec->smooth_buf[i], hSpar->hMdDec->smooth_buf_fx[i], 0, 2 * SBA_DIRAC_NRG_SMOOTH_LONG + 1 ); - } - floatToFixed_arr( hSpar->hMdDec->smooth_fac, hSpar->hMdDec->smooth_fac_fx, Q15, IVAS_MAX_NUM_BANDS ); - } -#endif // - ivas_spar_dec_upmixer_sf_fx( st_ivas, output_f_local, nchan_internal ); -#ifdef IVAS_FLOAT_FIXED /*Fixed to float */ - FOR( Word16 in_ch = 0; in_ch < numch_in; in_ch++ ) - { - FOR( Word16 i = 0; i < st_ivas->cldfbAnaDec[in_ch]->p_filter_length - st_ivas->cldfbAnaDec[in_ch]->no_channels; i++ ) - { - st_ivas->cldfbAnaDec[in_ch]->cldfb_state[i] = ( (float) ( st_ivas->cldfbAnaDec[in_ch]->cldfb_state_fx[i] ) / ( 1LL << ( Q11 ) ) ); /*Rounding off*/ - } - } - FOR( int m = 0; m < MAX_PARAM_SPATIAL_SUBFRAMES + 1; m++ ) - { - FOR( int j = 0; j < IVAS_MAX_FB_MIXER_OUT_CH; j++ ) - { - FOR( int k = 0; k < IVAS_MAX_SPAR_FB_MIXER_IN_CH; k++ ) - { - FOR( int l = 0; l < IVAS_MAX_NUM_BANDS; l++ ) - { - hSpar->hMdDec->mixer_mat_prev[m][j][k][l] = ( (float) hSpar->hMdDec->mixer_mat_prev_fx[m][j][k][l] / ( 1 << q2 ) ); - } - } - } - } - // fix2float (to be cleaned) - IF( ( LT_32( hDecoderConfig->ivas_total_brate, IVAS_24k4 ) ) && ( ( EQ_16( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_HOA2 ) ) || ( EQ_16( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_HOA3 ) ) ) ) - { - fixedToFloat_arr( hSpar->hMdDec->smooth_fac_fx, hSpar->hMdDec->smooth_fac, Q15, IVAS_MAX_NUM_BANDS ); - FOR( i = 0; i < IVAS_MAX_NUM_BANDS; i++ ) - { - fixedToFloat_arrL( hSpar->hMdDec->smooth_buf_fx[i], hSpar->hMdDec->smooth_buf[i], 0, 2 * SBA_DIRAC_NRG_SMOOTH_LONG + 1 ); - } - } - // fix2float end - FOR( Word16 out_ch = 0; out_ch < numch_out_dirac; out_ch++ ) - { - IF( st_ivas->cldfbSynDec[out_ch] ) - { - FOR( Word16 i = 0; i < st_ivas->cldfbSynDec[out_ch]->p_filter_length; i++ ) - { - st_ivas->cldfbSynDec[out_ch]->cldfb_state[i] = ( (float) ( st_ivas->cldfbSynDec[out_ch]->cldfb_state_fx[i] ) / (float) ( 1LL << ( Q11 ) ) ); /*Rounding off*/ - } - } - } -#endif -#else ivas_spar_dec_upmixer_sf( st_ivas, output_f_local, nchan_internal ); -#endif // IVAS_FLOAT_FIXED for ( n = 0; n < nchan_out; n++ ) { @@ -3017,13 +2986,7 @@ void ivas_spar_dec_upmixer( return; } - - -/*-------------------------------------------------------------------* - * ivas_spar_dec_upmixer_sf() - * - * IVAS SPAR upmixer - *-------------------------------------------------------------------*/ +#endif #ifdef IVAS_FLOAT_FIXED void ivas_spar_dec_upmixer_sf_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ @@ -3220,20 +3183,9 @@ void ivas_spar_dec_upmixer_sf_fx( st_ivas->cldfbAnaDec[in_ch]->cldfb_state[i] = ( (float) ( st_ivas->cldfbAnaDec[in_ch]->cldfb_state_fx[i] ) / ( 1LL << ( Q11 ) ) ); /*Rounding off*/ } } - FOR( int m = 0; m < MAX_PARAM_SPATIAL_SUBFRAMES + 1; m++ ) - { - FOR( int j = 0; j < IVAS_MAX_FB_MIXER_OUT_CH; j++ ) - { - FOR( int k = 0; k < IVAS_MAX_SPAR_FB_MIXER_IN_CH; k++ ) - { - FOR( int l = 0; l < IVAS_MAX_NUM_BANDS; l++ ) - { - hSpar->hMdDec->mixer_mat_prev[m][j][k][l] = ( (float) hSpar->hMdDec->mixer_mat_prev_fx[m][j][k][l] / ( 1 << q2 ) ); - } - } - } - } - FOR( out_ch = 0; out_ch < numch_out_dirac; out_ch++ ) +#endif +#if 1 + FOR( Word16 out_ch = 0; out_ch < numch_out_dirac; out_ch++ ) { IF( st_ivas->cldfbSynDec[out_ch] ) { @@ -3244,18 +3196,9 @@ void ivas_spar_dec_upmixer_sf_fx( } } #endif - ivas_spar_get_parameters( hSpar, hDecoderConfig, md_idx, numch_out, numch_in, num_spar_bands, mixer_mat ); - FOR ( i = 0; i < numch_out; i++ ) - { - FOR ( int j = 0; j < numch_in; j++ ) - { - FOR ( int k = 0; k < num_spar_bands; k++ ) - { - mixer_mat_fx[i][j][k] = floatToFixed( mixer_mat[i][j][k], q1 ); - hSpar->hMdDec->mixer_mat_prev2_fx[i][j][k] = floatToFixed( hSpar->hMdDec->mixer_mat_prev2[i][j][k], q1 ); - } - } - } + floatToFixed_arr( hSpar->hFbMixer->cldfb_cross_fade, hSpar->hFbMixer->cldfb_cross_fade_fx, Q15, CLDFB_NO_COL_MAX ); + ivas_spar_get_parameters_fx( hSpar, hDecoderConfig, md_idx, numch_out, numch_in, num_spar_bands, mixer_mat_fx ); + IF ( ( LT_32(hDecoderConfig->ivas_total_brate , IVAS_24k4) ) && ( ( EQ_16(hDecoderConfig->output_config , IVAS_AUDIO_CONFIG_HOA2) ) || ( EQ_16(hDecoderConfig->output_config , IVAS_AUDIO_CONFIG_HOA3) ) ) ) { FOR ( spar_band = 0; spar_band < num_spar_bands; spar_band++ ) @@ -3341,19 +3284,6 @@ void ivas_spar_dec_upmixer_sf_fx( hSpar->i_subframe = s_min( hSpar->i_subframe, MAX_PARAM_SPATIAL_SUBFRAMES ); } } -#if 1 /*TODO: To be removed when ivas_spar_get_parameters is integerated*/ - FOR( i = 0; i < numch_out; i++ ) - { - FOR( int j = 0; j < numch_in; j++ ) - { - FOR( int k = 0; k < num_spar_bands; k++ ) - { - mixer_mat[i][j][k] = fixedToFloat( mixer_mat_fx[i][j][k], q1 ); - hSpar->hMdDec->mixer_mat_prev2[i][j][k] = fixedToFloat( hSpar->hMdDec->mixer_mat_prev2_fx[i][j][k], q1 ); - } - } - } -#endif } #ifdef IVAS_FLOAT_FIXED /*Fixed to float */ @@ -3462,7 +3392,7 @@ void ivas_spar_dec_upmixer_sf_fx( return; } -#endif // IVAS_FLOAT_FIXED +#else void ivas_spar_dec_upmixer_sf( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ @@ -3473,10 +3403,6 @@ void ivas_spar_dec_upmixer_sf( int16_t cldfb_band, num_cldfb_bands, numch_in, numch_out; float *cldfb_in_ts_re[MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS][CLDFB_NO_COL_MAX]; float *cldfb_in_ts_im[MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS][CLDFB_NO_COL_MAX]; -#ifdef IVAS_FLOAT_FIXED - Word32 *cldfb_in_ts_re_fx[MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS][CLDFB_NO_COL_MAX]; - Word32 *cldfb_in_ts_im_fx[MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS][CLDFB_NO_COL_MAX]; -#endif int16_t i, b, ts, out_ch, in_ch; int16_t num_spar_bands, spar_band, nchan_transport; int16_t num_in_ingest, split_band; @@ -3484,10 +3410,6 @@ void ivas_spar_dec_upmixer_sf( float *p_tc[MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS]; int16_t md_idx; float Pcm_tmp[MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS][L_FRAME48k]; -#ifdef IVAS_FLOAT_FIXED - Word32 *p_tc_fx[MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS]; - Word32 Pcm_tmp_fx[MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS][L_FRAME48k]; -#endif int16_t numch_out_dirac; float mixer_mat[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS]; int16_t b_skip_mat[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; @@ -3513,6 +3435,7 @@ void ivas_spar_dec_upmixer_sf( floatToFixed_arr32( st_ivas->hTcBuffer->tc[i], st_ivas->hTcBuffer->tc_fx[i], Q11, st_ivas->hTcBuffer->n_samples_available ); } #endif // IVAS_FLOAT_FIXED + if ( st_ivas->ivas_format == SBA_ISM_FORMAT && st_ivas->ism_mode == ISM_SBA_MODE_DISC ) { int16_t nchan_ism; @@ -3521,9 +3444,6 @@ void ivas_spar_dec_upmixer_sf( for ( i = 0; i < nchan_internal; i++ ) { -#ifdef IVAS_FLOAT_FIXED - p_tc_fx[i] = st_ivas->hTcBuffer->tc_fx[i + nchan_ism] + slot_idx_start * slot_size; -#endif // IVAS_FLOAT_FIXED p_tc[i] = st_ivas->hTcBuffer->tc[i + nchan_ism] + slot_idx_start * slot_size; } @@ -3531,9 +3451,6 @@ void ivas_spar_dec_upmixer_sf( { for ( i = 0; i < nchan_ism; i++ ) { -#ifdef IVAS_FLOAT_FIXED - p_tc_fx[i + nchan_internal] = st_ivas->hTcBuffer->tc_fx[i] + slot_idx_start * slot_size; -#endif // IVAS_FLOAT_FIXED p_tc[i + nchan_internal] = st_ivas->hTcBuffer->tc[i] + slot_idx_start * slot_size; } } @@ -3542,9 +3459,6 @@ void ivas_spar_dec_upmixer_sf( { for ( i = 0; i < nchan_internal; i++ ) { -#ifdef IVAS_FLOAT_FIXED - p_tc_fx[i] = st_ivas->hTcBuffer->tc_fx[i] + slot_idx_start * slot_size; -#endif // IVAS_FLOAT_FIXED p_tc[i] = st_ivas->hTcBuffer->tc[i] + slot_idx_start * slot_size; } } @@ -3584,10 +3498,6 @@ void ivas_spar_dec_upmixer_sf( { cldfb_in_ts_re[in_ch][ts] = &Pcm_tmp[in_ch][ts * num_cldfb_bands]; cldfb_in_ts_im[in_ch][ts] = &Pcm_tmp[in_ch][ts * num_cldfb_bands + 4 * num_cldfb_bands]; -#ifdef IVAS_FLOAT_FIXED - cldfb_in_ts_re_fx[in_ch][ts] = &Pcm_tmp_fx[in_ch][ts * num_cldfb_bands]; - cldfb_in_ts_im_fx[in_ch][ts] = &Pcm_tmp_fx[in_ch][ts * num_cldfb_bands + 4 * num_cldfb_bands]; -#endif } } } @@ -3599,10 +3509,6 @@ void ivas_spar_dec_upmixer_sf( { cldfb_in_ts_re[in_ch][ts] = &Pcm_tmp[in_ch][ts * num_cldfb_bands]; cldfb_in_ts_im[in_ch][ts] = &Pcm_tmp[in_ch][ts * num_cldfb_bands + 4 * num_cldfb_bands]; -#ifdef IVAS_FLOAT_FIXED - cldfb_in_ts_re_fx[in_ch][ts] = &Pcm_tmp_fx[in_ch][ts * num_cldfb_bands]; - cldfb_in_ts_im_fx[in_ch][ts] = &Pcm_tmp_fx[in_ch][ts * num_cldfb_bands + 4 * num_cldfb_bands]; -#endif } } } @@ -3615,49 +3521,7 @@ void ivas_spar_dec_upmixer_sf( /* apply parameters */ /* determine if we can skip certain data */ -#ifdef IVAS_FLOAT_FIXED - Word16 q1 = 31; - for (int l = 0; l < numch_out; l++) { - for (int j = 0; j < numch_in; j++) { - for (int k = 0; k < num_md_sub_frames * IVAS_MAX_NUM_BANDS; k++) { - if (abs((Word32)hSpar->hMdDec->mixer_mat[l][j][k]) != 0) { - q1 = min(norm_l((Word32)(hSpar->hMdDec->mixer_mat[l][j][k])), q1); - } - } - } - } - for (int l = 0; l < numch_out; l++) { - for (int j = 0; j < numch_in; j++) { - for (int k = 0; k < num_md_sub_frames * IVAS_MAX_NUM_BANDS; k++) { - hSpar->hMdDec->mixer_mat_fx[l][j][k] = (Word32)(hSpar->hMdDec->mixer_mat[l][j][k] * (1 << q1)); - } - } - } - Word16 q2 = 31; - for (int m = 0; m < MAX_PARAM_SPATIAL_SUBFRAMES + 1; m++) { - for (int j = 0; j < IVAS_MAX_FB_MIXER_OUT_CH; j++) { - for (int k = 0; k < IVAS_MAX_SPAR_FB_MIXER_IN_CH; k++) { - for (int l = 0; l < IVAS_MAX_NUM_BANDS; l++) { - if (abs((Word32)hSpar->hMdDec->mixer_mat_prev[m][j][k][l]) != 0) { - q2 = min(norm_l((Word32)hSpar->hMdDec->mixer_mat_prev[m][j][k][l]), q2); - } - } - } - } - } - for (int m = 0; m < MAX_PARAM_SPATIAL_SUBFRAMES + 1; m++) { - for (int j = 0; j < IVAS_MAX_FB_MIXER_OUT_CH; j++) { - for (int k = 0; k < IVAS_MAX_SPAR_FB_MIXER_IN_CH; k++) { - for (int l = 0; l < IVAS_MAX_NUM_BANDS; l++) { - hSpar->hMdDec->mixer_mat_prev_fx[m][j][k][l] = (Word32) (hSpar->hMdDec->mixer_mat_prev[m][j][k][l] * (1 << q2)); - } - } - } - } - ivas_spar_get_skip_mat_fx( hSpar, numch_out, numch_in, num_spar_bands, b_skip_mat, num_md_sub_frames ); /* this can be precomputed based on bitrate and format*/ -#else ivas_spar_get_skip_mat( hSpar, numch_out, numch_in, num_spar_bands, b_skip_mat, num_md_sub_frames ); /* this can be precomputed based on bitrate and format*/ -#endif numch_out_dirac = hDecoderConfig->nchan_out; @@ -3676,12 +3540,7 @@ void ivas_spar_dec_upmixer_sf( { for ( ts = 0; ts < hSpar->subframe_nbslots[hSpar->subframes_rendered]; ts++ ) { -#ifdef IVAS_FLOAT_FIXED - Word16 q_cldfb = 11; - cldfbAnalysis_ts_fx_fixed_q( &p_tc_fx[in_ch][ts * num_cldfb_bands], cldfb_in_ts_re_fx[in_ch][ts], cldfb_in_ts_im_fx[in_ch][ts], num_cldfb_bands, st_ivas->cldfbAnaDec[in_ch], &q_cldfb ); -#else cldfbAnalysis_ts_ivas( &p_tc[in_ch][ts * num_cldfb_bands], cldfb_in_ts_re[in_ch][ts], cldfb_in_ts_im[in_ch][ts], num_cldfb_bands, st_ivas->cldfbAnaDec[in_ch] ); -#endif // IVAS_FLOAT_FIXED } } @@ -3691,12 +3550,7 @@ void ivas_spar_dec_upmixer_sf( { for ( ts = 0; ts < hSpar->subframe_nbslots[hSpar->subframes_rendered]; ts++ ) { -#ifdef IVAS_FLOAT_FIXED - Word16 q_cldfb = 11; - cldfbAnalysis_ts_fx_fixed_q( &p_tc_fx[in_ch][ts * num_cldfb_bands], cldfb_in_ts_re_fx[in_ch][ts], cldfb_in_ts_im_fx[in_ch][ts], num_cldfb_bands, st_ivas->cldfbAnaDec[in_ch] ,&q_cldfb); -#else cldfbAnalysis_ts_ivas( &p_tc[in_ch][ts * num_cldfb_bands], cldfb_in_ts_re[in_ch][ts], cldfb_in_ts_im[in_ch][ts], num_cldfb_bands, st_ivas->cldfbAnaDec[in_ch] ); -#endif } } } @@ -3720,38 +3574,7 @@ void ivas_spar_dec_upmixer_sf( #endif if ( ( hDecoderConfig->ivas_total_brate < IVAS_24k4 ) && ( ( hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_HOA2 ) || ( hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_HOA3 ) ) ) { -#ifdef IVAS_FLOAT_FIXED - //float2fix (to be cleaned) - Word16 q_cldfb = 31; - for (ts = 0; ts < MAX_PARAM_SPATIAL_SUBFRAMES; ts++) - { - Word16 q_ts_re = Q_factor_arrL(cldfb_in_ts_re[0][ts], CLDFB_NO_CHANNELS_MAX); - Word16 q_ts_im = Q_factor_arrL(cldfb_in_ts_im[0][ts], CLDFB_NO_CHANNELS_MAX); - q_cldfb = min(q_cldfb, min(q_ts_re, q_ts_im)); - } - for (ts = 0; ts < MAX_PARAM_SPATIAL_SUBFRAMES; ts++) - { - floatToFixed_arrL(cldfb_in_ts_re[0][ts], cldfb_in_ts_re_fx[0][ts], q_cldfb, CLDFB_NO_CHANNELS_MAX); - floatToFixed_arrL(cldfb_in_ts_im[0][ts], cldfb_in_ts_im_fx[0][ts], q_cldfb, CLDFB_NO_CHANNELS_MAX); - } - for (i = 0; i < IVAS_MAX_NUM_BANDS; i++) { - floatToFixed_arrL(hSpar->hMdDec->smooth_buf[i], hSpar->hMdDec->smooth_buf_fx[i], 0, 2 * SBA_DIRAC_NRG_SMOOTH_LONG + 1); - } - floatToFixed_arr(hSpar->hMdDec->smooth_fac, hSpar->hMdDec->smooth_fac_fx, Q15, IVAS_MAX_NUM_BANDS); - //float2fix end - - ivas_spar_calc_smooth_facs_fx( cldfb_in_ts_re_fx[0], cldfb_in_ts_im_fx[0], q_cldfb, num_spar_bands, hSpar->subframe_nbslots[hSpar->subframes_rendered], - hSpar->subframes_rendered == 0, &hSpar->hFbMixer->pFb->fb_bin_to_band, hSpar->hMdDec->smooth_fac_fx, hSpar->hMdDec->smooth_buf_fx ); - - //fix2float (to be cleaned) - fixedToFloat_arr(hSpar->hMdDec->smooth_fac_fx, hSpar->hMdDec->smooth_fac, Q15, IVAS_MAX_NUM_BANDS); - for (i = 0; i < IVAS_MAX_NUM_BANDS; i++) { - fixedToFloat_arrL(hSpar->hMdDec->smooth_buf_fx[i], hSpar->hMdDec->smooth_buf[i], 0, 2 * SBA_DIRAC_NRG_SMOOTH_LONG + 1); - } - //fix2float end -#else ivas_spar_calc_smooth_facs( cldfb_in_ts_re[0], cldfb_in_ts_im[0], num_spar_bands, hSpar->subframe_nbslots[hSpar->subframes_rendered], hSpar->subframes_rendered == 0, &hSpar->hFbMixer->pFb->fb_bin_to_band, hSpar->hMdDec->smooth_fac, hSpar->hMdDec->smooth_buf ); -#endif } for ( ts = 0; ts < hSpar->subframe_nbslots[hSpar->subframes_rendered]; ts++ ) @@ -3908,3 +3731,4 @@ void ivas_spar_dec_upmixer_sf( return; } +#endif // IVAS_FLOAT_FIXED diff --git a/lib_dec/ivas_spar_md_dec.c b/lib_dec/ivas_spar_md_dec.c index 4b92c2468..5ec2167a7 100644 --- a/lib_dec/ivas_spar_md_dec.c +++ b/lib_dec/ivas_spar_md_dec.c @@ -65,7 +65,11 @@ static const int16_t ivas_spar_dec_plc_spatial_target[IVAS_SPAR_MAX_CH] = { 1, 0 * Static functions declaration *------------------------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +static void ivas_get_spar_matrices_fx( ivas_spar_md_dec_state_t *hMdDec, const int16_t num_bands_out, const int16_t n_ts, const int16_t bw, const int16_t dtx_vad, const int16_t nB, const int16_t numch_out, const int16_t active_w_vlbr, const int16_t dyn_active_w_flag ); +#else static void ivas_get_spar_matrices( ivas_spar_md_dec_state_t *hMdDec, const int16_t num_bands_out, const int16_t n_ts, const int16_t bw, const int16_t dtx_vad, const int16_t nB, const int16_t numch_out, const int16_t active_w_vlbr, const int16_t dyn_active_w_flag ); +#endif static void ivas_decode_arith_bs( ivas_spar_md_dec_state_t *hMdDec, Decoder_State *st, const uint16_t qsi, const int16_t nB, const int16_t bands_bw, int16_t *pDo_diff, const int16_t strat, const int32_t ivas_total_brate ); @@ -73,7 +77,11 @@ static void ivas_decode_huffman_bs( ivas_spar_md_dec_state_t *hMdDec, Decoder_St static void ivas_fill_band_coeffs_idx( ivas_band_coeffs_ind_t *pBands_idx, const int16_t nB, int16_t *pSymbol_re, ivas_cell_dim_t *pCell_dims, ivas_coeffs_type_t coeff_type ); +#ifndef IVAS_FLOAT_FIXED static void ivas_mat_col_rearrange( float in_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], const int16_t order[IVAS_SPAR_MAX_CH], const int16_t i_ts, float ***mixer_mat, const int16_t bands, const int16_t num_ch ); +#else +static void ivas_mat_col_rearrange_fx( Word32 in_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], const int16_t order[IVAS_SPAR_MAX_CH], const int16_t i_ts, Word32 ***mixer_mat, const int16_t bands, const int16_t num_ch ); +#endif static void ivas_spar_dec_compute_ramp_down_post_matrix( ivas_spar_md_dec_state_t *hMdDec, const int16_t num_bands, const int16_t bfi, const int16_t num_md_sub_frames ); @@ -81,6 +89,9 @@ static void ivas_spar_dec_compute_ramp_down_post_matrix( ivas_spar_md_dec_state_ static void ivas_spar_dec_compute_ramp_down_post_matrix_fx(ivas_spar_md_dec_state_t *hMdDec, const Word16 num_bands, const Word16 bfi, const Word16 num_md_sub_frames); #endif // IVAS_FLOAT_FIXED +#ifdef IVAS_FLOAT_FIXED +static void ivas_spar_md_fill_invalid_bands_fx(ivas_spar_dec_matrices_t *pSpar_coeffs, ivas_spar_dec_matrices_t *pSpar_coeffs_prev, const Word16 *valid_bands, Word16 *base_band_age, const Word16 num_bands, const Word16 num_channels, const Word16 num_md_sub_frames); +#endif static void ivas_spar_md_fill_invalid_bands( ivas_spar_dec_matrices_t *pSpar_coeffs, ivas_spar_dec_matrices_t *pSpar_coeffs_prev, const int16_t *valid_bands, int16_t *base_band_age, const int16_t num_bands, const int16_t numch_out, const int16_t num_md_sub_frames ); static void ivas_spar_md_fill_invalid_bandcoeffs( ivas_band_coeffs_t *pBand_coeffs, ivas_band_coeffs_t *pBand_coeffs_prev, const int16_t *valid_bands, int16_t *base_band_age, int16_t *first_valid_frame, const int16_t num_bands ); @@ -93,12 +104,20 @@ static ivas_error ivas_spar_set_dec_config( ivas_spar_md_dec_state_t *hMdDec, co static void ivas_parse_parameter_bitstream_dtx( ivas_spar_md_t *pSpar_md, Decoder_State *st, const int16_t bw, const int16_t num_bands, int16_t *num_dmx_per_band, int16_t *num_dec_per_band ); static ivas_error ivas_deindex_real_index( const int16_t *index, const int16_t q_levels, const float min_value, const float max_value, float *quant, const int16_t num_ch_dim2 ); +#ifdef IVAS_FLOAT_FIXED static ivas_error ivas_deindex_real_index_fx( const int16_t *index, const int16_t q_levels, const Word32 min_value, const Word32 max_value, Word32 *quant, const int16_t num_ch_dim2 ); +#endif +#ifdef IVAS_FLOAT_FIXED +static void ivas_spar_dec_parse_md_bs_fx( ivas_spar_md_dec_state_t *hMdDec, Decoder_State *st, int16_t *nB, int16_t *bands_bw, int16_t *dtx_vad, const int32_t ivas_total_brate, const int16_t sba_inactive_mode +); +#else static void ivas_spar_dec_parse_md_bs( ivas_spar_md_dec_state_t *hMdDec, Decoder_State *st, int16_t *nB, int16_t *bands_bw, int16_t *dtx_vad, const int32_t ivas_total_brate, const int16_t sba_inactive_mode ); +#endif +#ifndef IVAS_FLOAT_FIXED /*------------------------------------------------------------------------- * ivas_spar_md_dec_matrix_open() * @@ -140,286 +159,269 @@ ivas_error ivas_spar_md_dec_matrix_open( } } -#ifdef IVAS_FLOAT_FIXED - if ( ( hMdDec->mixer_mat_fx = (Word32 ***) malloc( num_channels * sizeof( Word32 ** ) ) ) == NULL ) + if ( ( hMdDec->spar_coeffs.C_re = (float ***) malloc( num_channels * sizeof( float ** ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } for ( i = 0; i < num_channels; i++ ) { - if ( ( hMdDec->mixer_mat_fx[i] = (Word32 **) malloc( num_channels * sizeof( Word32 * ) ) ) == NULL ) + if ( ( hMdDec->spar_coeffs.C_re[i] = (float **) malloc( num_channels * sizeof( float * ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } for ( j = 0; j < num_channels; j++ ) { - if ( ( hMdDec->mixer_mat_fx[i][j] = (Word32 *) malloc( num_md_sub_frames * IVAS_MAX_NUM_BANDS * sizeof( Word32 ) ) ) == NULL ) + if ( ( hMdDec->spar_coeffs.C_re[i][j] = (float *) malloc( num_md_sub_frames * IVAS_MAX_NUM_BANDS * sizeof( float ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } } } - hMdDec->mix_mat_dim_0_1 = num_channels; - hMdDec->mix_mat_dim_2 = num_md_sub_frames * IVAS_MAX_NUM_BANDS; -#endif -#ifdef IVAS_FLOAT_FIXED - if ( ( hMdDec->spar_coeffs.C_re_fx = (Word32 ***) malloc( num_channels * sizeof(Word32 ** ) ) ) == NULL ) + + if ( ( hMdDec->spar_coeffs.P_re = (float ***) malloc( num_channels * sizeof( float ** ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } for ( i = 0; i < num_channels; i++ ) { - if ( ( hMdDec->spar_coeffs.C_re_fx[i] = (Word32 **) malloc( num_channels * sizeof(Word32 * ) ) ) == NULL ) + if ( ( hMdDec->spar_coeffs.P_re[i] = (float **) malloc( num_channels * sizeof( float * ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } for ( j = 0; j < num_channels; j++ ) { - if ( ( hMdDec->spar_coeffs.C_re_fx[i][j] = (Word32 *) malloc( num_md_sub_frames * IVAS_MAX_NUM_BANDS * sizeof(Word32) ) ) == NULL ) + if ( ( hMdDec->spar_coeffs.P_re[i][j] = (float *) malloc( num_md_sub_frames * IVAS_MAX_NUM_BANDS * sizeof( float ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } } } - if ( ( hMdDec->spar_coeffs.P_re_fx = (Word32 ***) malloc( num_channels * sizeof(Word32 ** ) ) ) == NULL ) + if ( ( hMdDec->spar_coeffs_prev.C_re = (float ***) malloc( num_channels * sizeof( float ** ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } for ( i = 0; i < num_channels; i++ ) { - if ( ( hMdDec->spar_coeffs.P_re_fx[i] = (Word32 **) malloc( num_channels * sizeof(Word32 * ) ) ) == NULL ) + if ( ( hMdDec->spar_coeffs_prev.C_re[i] = (float **) malloc( num_channels * sizeof( float * ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } for ( j = 0; j < num_channels; j++ ) { - if ( ( hMdDec->spar_coeffs.P_re_fx[i][j] = (Word32 *) malloc( num_md_sub_frames * IVAS_MAX_NUM_BANDS * sizeof(Word32) ) ) == NULL ) + if ( ( hMdDec->spar_coeffs_prev.C_re[i][j] = (float *) malloc( IVAS_MAX_NUM_BANDS * sizeof( float ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } } } -#endif // IVAS_FLOAT_FIXED - if ( ( hMdDec->spar_coeffs.C_re = (float ***) malloc( num_channels * sizeof( float ** ) ) ) == NULL ) + + if ( ( hMdDec->spar_coeffs_prev.P_re = (float ***) malloc( num_channels * sizeof( float ** ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } for ( i = 0; i < num_channels; i++ ) { - if ( ( hMdDec->spar_coeffs.C_re[i] = (float **) malloc( num_channels * sizeof( float * ) ) ) == NULL ) + if ( ( hMdDec->spar_coeffs_prev.P_re[i] = (float **) malloc( num_channels * sizeof( float * ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } for ( j = 0; j < num_channels; j++ ) { - if ( ( hMdDec->spar_coeffs.C_re[i][j] = (float *) malloc( num_md_sub_frames * IVAS_MAX_NUM_BANDS * sizeof( float ) ) ) == NULL ) + if ( ( hMdDec->spar_coeffs_prev.P_re[i][j] = (float *) malloc( IVAS_MAX_NUM_BANDS * sizeof( float ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } } } - //Fix_memory - /*if ((hMdDec->spar_coeffs.C_re_fx = (Word32 ***)malloc(num_channels * sizeof(Word32 **))) == NULL) + + if ( ( hMdDec->spar_coeffs_tar.C_re = (float ***) malloc( num_channels * sizeof( float ** ) ) ) == NULL ) { return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix"); } for (i = 0; i < num_channels; i++) { - if ((hMdDec->spar_coeffs.C_re_fx[i] = (Word32 **)malloc(num_channels * sizeof(Word32 *))) == NULL) + if ( ( hMdDec->spar_coeffs_tar.C_re[i] = (float **) malloc( num_channels * sizeof( float * ) ) ) == NULL ) { return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix"); } for (j = 0; j < num_channels; j++) { - if ((hMdDec->spar_coeffs.C_re_fx[i][j] = (Word32 *)malloc(num_md_sub_frames * IVAS_MAX_NUM_BANDS * sizeof(Word32))) == NULL) + if ( ( hMdDec->spar_coeffs_tar.C_re[i][j] = (float *) malloc( IVAS_MAX_NUM_BANDS * sizeof( float ) ) ) == NULL ) { return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix"); } } - }*/ - + } - if ( ( hMdDec->spar_coeffs.P_re = (float ***) malloc( num_channels * sizeof( float ** ) ) ) == NULL ) + if ( ( hMdDec->spar_coeffs_tar.P_re = (float ***) malloc( num_channels * sizeof( float ** ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } for ( i = 0; i < num_channels; i++ ) { - if ( ( hMdDec->spar_coeffs.P_re[i] = (float **) malloc( num_channels * sizeof( float * ) ) ) == NULL ) + if ( ( hMdDec->spar_coeffs_tar.P_re[i] = (float **) malloc( num_channels * sizeof( float * ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } for ( j = 0; j < num_channels; j++ ) { - if ( ( hMdDec->spar_coeffs.P_re[i][j] = (float *) malloc( num_md_sub_frames * IVAS_MAX_NUM_BANDS * sizeof( float ) ) ) == NULL ) + if ( ( hMdDec->spar_coeffs_tar.P_re[i][j] = (float *) malloc( IVAS_MAX_NUM_BANDS * sizeof( float ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } } } - //Fix memory - /*if ((hMdDec->spar_coeffs.P_re_fx = (Word32 ***)malloc(num_channels * sizeof(Word32 **))) == NULL) - { - return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix"); - } for (i = 0; i < num_channels; i++) { - if ((hMdDec->spar_coeffs.P_re_fx[i] = (Word32 **)malloc(num_channels * sizeof(Word32 *))) == NULL) - { - return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix"); - } for (j = 0; j < num_channels; j++) { - if ((hMdDec->spar_coeffs.P_re_fx[i][j] = (Word32 *)malloc(num_md_sub_frames * IVAS_MAX_NUM_BANDS * sizeof(Word32))) == NULL) + for ( k = 0; k < IVAS_MAX_NUM_BANDS; k++ ) { - return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix"); + hMdDec->spar_coeffs_prev.C_re[i][j][k] = 0.0f; + hMdDec->spar_coeffs_prev.P_re[i][j][k] = 0.0f; + hMdDec->spar_coeffs_tar.C_re[i][j][k] = 0.0f; + hMdDec->spar_coeffs_tar.P_re[i][j][k] = 0.0f; + } } } - }*/ - if ( ( hMdDec->spar_coeffs_prev.C_re = (float ***) malloc( num_channels * sizeof( float ** ) ) ) == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); + return IVAS_ERR_OK; } - for ( i = 0; i < num_channels; i++ ) + +#else +ivas_error ivas_spar_md_dec_matrix_open_fx( + ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ + const int16_t num_channels, /* i : number of internal channels */ + const int16_t num_md_sub_frames /* i : number of MD subframes */ +) { - if ( ( hMdDec->spar_coeffs_prev.C_re[i] = (float **) malloc( num_channels * sizeof( float * ) ) ) == NULL ) + int16_t i, j; + int16_t k; + if ( ( hMdDec->spar_md.band_coeffs = (ivas_band_coeffs_t *) malloc( IVAS_MAX_NUM_BANDS * num_md_sub_frames * sizeof( ivas_band_coeffs_t ) ) ) == NULL ) { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for band_coeffs in SPAR MD" ); } - for ( j = 0; j < num_channels; j++ ) - { - if ( ( hMdDec->spar_coeffs_prev.C_re[i][j] = (float *) malloc( IVAS_MAX_NUM_BANDS * sizeof( float ) ) ) == NULL ) + if ( ( hMdDec->band_coeffs_prev = (ivas_band_coeffs_t *) malloc( IVAS_MAX_NUM_BANDS * sizeof( ivas_band_coeffs_t ) ) ) == NULL ) { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); - } - } + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for band_coeffs in SPAR MD" ); } - - //Fix Memory -#ifdef IVAS_FLOAT_FIXED - if ((hMdDec->spar_coeffs_prev.C_re_fx = (Word32 ***)malloc(num_channels * sizeof(Word32 **))) == NULL) + if ( ( hMdDec->mixer_mat_fx = (Word32 ***) malloc( num_channels * sizeof( Word32 ** ) ) ) == NULL ) { return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix"); } for (i = 0; i < num_channels; i++) { - if ((hMdDec->spar_coeffs_prev.C_re_fx[i] = (Word32 **)malloc(num_channels * sizeof(Word32 *))) == NULL) + if ( ( hMdDec->mixer_mat_fx[i] = (Word32 **) malloc( num_channels * sizeof( Word32 * ) ) ) == NULL ) { return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix"); } for (j = 0; j < num_channels; j++) { - if ((hMdDec->spar_coeffs_prev.C_re_fx[i][j] = (Word32 *)malloc(IVAS_MAX_NUM_BANDS * sizeof(Word32))) == NULL) + if ( ( hMdDec->mixer_mat_fx[i][j] = (Word32 *) malloc( num_md_sub_frames * IVAS_MAX_NUM_BANDS * sizeof( Word32 ) ) ) == NULL ) { return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix"); } } } -#endif - if ( ( hMdDec->spar_coeffs_prev.P_re = (float ***) malloc( num_channels * sizeof( float ** ) ) ) == NULL ) + hMdDec->mix_mat_dim_0_1 = num_channels; + hMdDec->mix_mat_dim_2 = num_md_sub_frames * IVAS_MAX_NUM_BANDS; + + if ( ( hMdDec->spar_coeffs.C_re_fx = (Word32 ***) malloc( num_channels * sizeof(Word32 ** ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } for ( i = 0; i < num_channels; i++ ) { - if ( ( hMdDec->spar_coeffs_prev.P_re[i] = (float **) malloc( num_channels * sizeof( float * ) ) ) == NULL ) + if ( ( hMdDec->spar_coeffs.C_re_fx[i] = (Word32 **) malloc( num_channels * sizeof(Word32 * ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } for ( j = 0; j < num_channels; j++ ) { - if ( ( hMdDec->spar_coeffs_prev.P_re[i][j] = (float *) malloc( IVAS_MAX_NUM_BANDS * sizeof( float ) ) ) == NULL ) + if ( ( hMdDec->spar_coeffs.C_re_fx[i][j] = (Word32 *) malloc( num_md_sub_frames * IVAS_MAX_NUM_BANDS * sizeof(Word32) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } } } -#ifdef IVAS_FLOAT_FIXED - //Fix Memory - if ((hMdDec->spar_coeffs_prev.P_re_fx = (Word32 ***)malloc(num_channels * sizeof(Word32 **))) == NULL) + if ( ( hMdDec->spar_coeffs.P_re_fx = (Word32 ***) malloc( num_channels * sizeof(Word32 ** ) ) ) == NULL ) { return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix"); } for (i = 0; i < num_channels; i++) { - if ((hMdDec->spar_coeffs_prev.P_re_fx[i] = (Word32 **)malloc(num_channels * sizeof(Word32 *))) == NULL) + if ( ( hMdDec->spar_coeffs.P_re_fx[i] = (Word32 **) malloc( num_channels * sizeof(Word32 * ) ) ) == NULL ) { return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix"); } for (j = 0; j < num_channels; j++) { - if ((hMdDec->spar_coeffs_prev.P_re_fx[i][j] = (Word32 *)malloc(IVAS_MAX_NUM_BANDS * sizeof(Word32))) == NULL) + if ( ( hMdDec->spar_coeffs.P_re_fx[i][j] = (Word32 *) malloc( num_md_sub_frames * IVAS_MAX_NUM_BANDS * sizeof(Word32) ) ) == NULL ) { return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix"); } } } -#endif - if ( ( hMdDec->spar_coeffs_tar.C_re = (float ***) malloc( num_channels * sizeof( float ** ) ) ) == NULL ) + if ((hMdDec->spar_coeffs_prev.C_re_fx = (Word32 ***)malloc(num_channels * sizeof(Word32 **))) == NULL) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } for ( i = 0; i < num_channels; i++ ) { - if ( ( hMdDec->spar_coeffs_tar.C_re[i] = (float **) malloc( num_channels * sizeof( float * ) ) ) == NULL ) + if ((hMdDec->spar_coeffs_prev.C_re_fx[i] = (Word32 **)malloc(num_channels * sizeof(Word32 *))) == NULL) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } for ( j = 0; j < num_channels; j++ ) { - if ( ( hMdDec->spar_coeffs_tar.C_re[i][j] = (float *) malloc( IVAS_MAX_NUM_BANDS * sizeof( float ) ) ) == NULL ) + if ((hMdDec->spar_coeffs_prev.C_re_fx[i][j] = (Word32 *)malloc(IVAS_MAX_NUM_BANDS * sizeof(Word32))) == NULL) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } } } -#ifdef IVAS_FLOAT_FIXED //Fix Memory - if ((hMdDec->spar_coeffs_tar.C_re_fx = (Word32 ***)malloc(num_channels * sizeof(Word32 **))) == NULL) + if ((hMdDec->spar_coeffs_prev.P_re_fx = (Word32 ***)malloc(num_channels * sizeof(Word32 **))) == NULL) { return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix"); } for (i = 0; i < num_channels; i++) { - if ((hMdDec->spar_coeffs_tar.C_re_fx[i] = (Word32 **)malloc(num_channels * sizeof(Word32 *))) == NULL) + if ((hMdDec->spar_coeffs_prev.P_re_fx[i] = (Word32 **)malloc(num_channels * sizeof(Word32 *))) == NULL) { return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix"); } for (j = 0; j < num_channels; j++) { - if ((hMdDec->spar_coeffs_tar.C_re_fx[i][j] = (Word32 *)malloc(IVAS_MAX_NUM_BANDS * sizeof(Word32))) == NULL) + if ((hMdDec->spar_coeffs_prev.P_re_fx[i][j] = (Word32 *)malloc(IVAS_MAX_NUM_BANDS * sizeof(Word32))) == NULL) { return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix"); } } } -#endif - - if ( ( hMdDec->spar_coeffs_tar.P_re = (float ***) malloc( num_channels * sizeof( float ** ) ) ) == NULL ) + //Fix Memory + if ((hMdDec->spar_coeffs_tar.C_re_fx = (Word32 ***)malloc(num_channels * sizeof(Word32 **))) == NULL) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } for ( i = 0; i < num_channels; i++ ) { - if ( ( hMdDec->spar_coeffs_tar.P_re[i] = (float **) malloc( num_channels * sizeof( float * ) ) ) == NULL ) + if ((hMdDec->spar_coeffs_tar.C_re_fx[i] = (Word32 **)malloc(num_channels * sizeof(Word32 *))) == NULL) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } for ( j = 0; j < num_channels; j++ ) { - if ( ( hMdDec->spar_coeffs_tar.P_re[i][j] = (float *) malloc( IVAS_MAX_NUM_BANDS * sizeof( float ) ) ) == NULL ) + if ((hMdDec->spar_coeffs_tar.C_re_fx[i][j] = (Word32 *)malloc(IVAS_MAX_NUM_BANDS * sizeof(Word32))) == NULL) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } } } - -#ifdef IVAS_FLOAT_FIXED //Fix Memory if ((hMdDec->spar_coeffs_tar.P_re_fx = (Word32 ***)malloc(num_channels * sizeof(Word32 **))) == NULL) { @@ -439,7 +441,6 @@ ivas_error ivas_spar_md_dec_matrix_open( } } } -#endif for ( i = 0; i < num_channels; i++ ) { @@ -447,23 +448,17 @@ ivas_error ivas_spar_md_dec_matrix_open( { for ( k = 0; k < IVAS_MAX_NUM_BANDS; k++ ) { - hMdDec->spar_coeffs_prev.C_re[i][j][k] = 0.0f; - hMdDec->spar_coeffs_prev.P_re[i][j][k] = 0.0f; - hMdDec->spar_coeffs_tar.C_re[i][j][k] = 0.0f; - hMdDec->spar_coeffs_tar.P_re[i][j][k] = 0.0f; -#ifdef IVAS_FLOAT_FIXED hMdDec->spar_coeffs_prev.C_re_fx[i][j][k] = 0; hMdDec->spar_coeffs_prev.P_re_fx[i][j][k] = 0; hMdDec->spar_coeffs_tar.C_re_fx[i][j][k] = 0; hMdDec->spar_coeffs_tar.P_re_fx[i][j][k] = 0; -#endif } } } return IVAS_ERR_OK; } - +#endif /*------------------------------------------------------------------------- * ivas_get_spar_dec_md_num_subframes() @@ -560,7 +555,11 @@ ivas_error ivas_spar_md_dec_open( num_md_sub_frames = ivas_get_spar_dec_md_num_subframes( sba_order, hDecoderConfig->ivas_total_brate, last_active_ivas_total_brate ); +#ifndef IVAS_FLOAT_FIXED if ( ( error = ivas_spar_md_dec_matrix_open( hMdDec, num_channels, num_md_sub_frames ) ) != IVAS_ERR_OK ) +#else + if ( ( error = ivas_spar_md_dec_matrix_open_fx( hMdDec, num_channels, num_md_sub_frames ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -598,6 +597,7 @@ ivas_error ivas_spar_md_dec_open( * Deallocate SPAR MD decoder matrices *------------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED void ivas_spar_md_dec_matrix_close( ivas_spar_md_dec_state_t *hMdDecoder, /* i/o: SPAR MD decoder handle */ const int16_t num_channels /* i : number of internal channels */ @@ -629,167 +629,169 @@ void ivas_spar_md_dec_matrix_close( free( hMdDecoder->mixer_mat ); } -#ifdef IVAS_FLOAT_FIXED - if ( hMdDecoder->mixer_mat_fx != NULL ) + if ( hMdDecoder->spar_coeffs.C_re != NULL ) { for ( i = 0; i < num_channels; i++ ) { for ( j = 0; j < num_channels; j++ ) { - free( hMdDecoder->mixer_mat_fx[i][j] ); + free( hMdDecoder->spar_coeffs.C_re[i][j] ); } - free( hMdDecoder->mixer_mat_fx[i] ); + free( hMdDecoder->spar_coeffs.C_re[i] ); } - free( hMdDecoder->mixer_mat_fx ); + free( hMdDecoder->spar_coeffs.C_re ); } -#endif -#ifdef IVAS_FLOAT_FIXED - if ( hMdDecoder->spar_coeffs.C_re_fx != NULL ) + + if ( hMdDecoder->spar_coeffs.P_re != NULL ) { for ( i = 0; i < num_channels; i++ ) { for ( j = 0; j < num_channels; j++ ) { - free( hMdDecoder->spar_coeffs.C_re_fx[i][j] ); + free( hMdDecoder->spar_coeffs.P_re[i][j] ); } - free( hMdDecoder->spar_coeffs.C_re_fx[i] ); + free( hMdDecoder->spar_coeffs.P_re[i] ); } - free( hMdDecoder->spar_coeffs.C_re_fx ); + free( hMdDecoder->spar_coeffs.P_re ); } - if ( hMdDecoder->spar_coeffs.P_re_fx != NULL ) + + if ( hMdDecoder->spar_coeffs_prev.C_re != NULL ) { for ( i = 0; i < num_channels; i++ ) { for ( j = 0; j < num_channels; j++ ) { - free( hMdDecoder->spar_coeffs.P_re_fx[i][j] ); + free( hMdDecoder->spar_coeffs_prev.C_re[i][j] ); } - free( hMdDecoder->spar_coeffs.P_re_fx[i] ); + free( hMdDecoder->spar_coeffs_prev.C_re[i] ); } - free( hMdDecoder->spar_coeffs.P_re_fx ); + free( hMdDecoder->spar_coeffs_prev.C_re ); } -#endif // IVAS_FLOAT_FIXED - if ( hMdDecoder->spar_coeffs.C_re != NULL ) + if ( hMdDecoder->spar_coeffs_prev.P_re != NULL ) { for ( i = 0; i < num_channels; i++ ) { for ( j = 0; j < num_channels; j++ ) { - free( hMdDecoder->spar_coeffs.C_re[i][j] ); + free( hMdDecoder->spar_coeffs_prev.P_re[i][j] ); } - free( hMdDecoder->spar_coeffs.C_re[i] ); + free( hMdDecoder->spar_coeffs_prev.P_re[i] ); } - free( hMdDecoder->spar_coeffs.C_re ); + free( hMdDecoder->spar_coeffs_prev.P_re ); } - /*if (hMdDecoder->spar_coeffs.C_re_fx != NULL) + + if ( hMdDecoder->spar_coeffs_tar.C_re != NULL ) { for (i = 0; i < num_channels; i++) { for (j = 0; j < num_channels; j++) { - free(hMdDecoder->spar_coeffs.C_re_fx[i][j]); + free( hMdDecoder->spar_coeffs_tar.C_re[i][j] ); + } + free( hMdDecoder->spar_coeffs_tar.C_re[i] ); } - free(hMdDecoder->spar_coeffs.C_re_fx[i]); + free( hMdDecoder->spar_coeffs_tar.C_re ); } - free(hMdDecoder->spar_coeffs.C_re_fx); - }*/ - if ( hMdDecoder->spar_coeffs.P_re != NULL ) + if ( hMdDecoder->spar_coeffs_tar.P_re != NULL ) { for ( i = 0; i < num_channels; i++ ) { for ( j = 0; j < num_channels; j++ ) { - free( hMdDecoder->spar_coeffs.P_re[i][j] ); + free( hMdDecoder->spar_coeffs_tar.P_re[i][j] ); } - free( hMdDecoder->spar_coeffs.P_re[i] ); + free( hMdDecoder->spar_coeffs_tar.P_re[i] ); } - free( hMdDecoder->spar_coeffs.P_re ); + free( hMdDecoder->spar_coeffs_tar.P_re ); } - /*if (hMdDecoder->spar_coeffs.P_re_fx != NULL) - { - for (i = 0; i < num_channels; i++) + return; +} + +#else +void ivas_spar_md_dec_matrix_close_fx( + ivas_spar_md_dec_state_t *hMdDecoder, /* i/o: SPAR MD decoder handle */ + const int16_t num_channels /* i : number of internal channels */ +) { - for (j = 0; j < num_channels; j++) + int16_t i, j; + + if ( hMdDecoder->spar_md.band_coeffs != NULL ) { - free(hMdDecoder->spar_coeffs.P_re_fx[i][j]); + free( hMdDecoder->spar_md.band_coeffs ); + hMdDecoder->spar_md.band_coeffs = NULL; } - free(hMdDecoder->spar_coeffs.P_re_fx[i]); + if ( hMdDecoder->band_coeffs_prev != NULL ) + { + free( hMdDecoder->band_coeffs_prev ); + hMdDecoder->band_coeffs_prev = NULL; } - free(hMdDecoder->spar_coeffs.P_re_fx); - }*/ - if ( hMdDecoder->spar_coeffs_prev.C_re != NULL ) + if ( hMdDecoder->mixer_mat_fx != NULL ) { for ( i = 0; i < num_channels; i++ ) { for ( j = 0; j < num_channels; j++ ) { - free( hMdDecoder->spar_coeffs_prev.C_re[i][j] ); + free( hMdDecoder->mixer_mat_fx[i][j] ); } - free( hMdDecoder->spar_coeffs_prev.C_re[i] ); + free( hMdDecoder->mixer_mat_fx[i] ); } - free( hMdDecoder->spar_coeffs_prev.C_re ); + free( hMdDecoder->mixer_mat_fx ); } -#ifdef IVAS_FLOAT_FIXED - if (hMdDecoder->spar_coeffs_prev.C_re_fx != NULL) + if ( hMdDecoder->spar_coeffs.C_re_fx != NULL ) { for (i = 0; i < num_channels; i++) { for (j = 0; j < num_channels; j++) { - free(hMdDecoder->spar_coeffs_prev.C_re_fx[i][j]); + free( hMdDecoder->spar_coeffs.C_re_fx[i][j] ); } - free(hMdDecoder->spar_coeffs_prev.C_re_fx[i]); + free( hMdDecoder->spar_coeffs.C_re_fx[i] ); } - free(hMdDecoder->spar_coeffs_prev.C_re_fx); + free( hMdDecoder->spar_coeffs.C_re_fx ); } -#endif - - if ( hMdDecoder->spar_coeffs_prev.P_re != NULL ) + if ( hMdDecoder->spar_coeffs.P_re_fx != NULL ) { for ( i = 0; i < num_channels; i++ ) { for ( j = 0; j < num_channels; j++ ) { - free( hMdDecoder->spar_coeffs_prev.P_re[i][j] ); + free( hMdDecoder->spar_coeffs.P_re_fx[i][j] ); } - free( hMdDecoder->spar_coeffs_prev.P_re[i] ); + free( hMdDecoder->spar_coeffs.P_re_fx[i] ); } - free( hMdDecoder->spar_coeffs_prev.P_re ); + free( hMdDecoder->spar_coeffs.P_re_fx ); } -#ifdef IVAS_FLOAT_FIXED - if (hMdDecoder->spar_coeffs_prev.P_re_fx != NULL) + if (hMdDecoder->spar_coeffs_prev.C_re_fx != NULL) { for (i = 0; i < num_channels; i++) { for (j = 0; j < num_channels; j++) { - free(hMdDecoder->spar_coeffs_prev.P_re_fx[i][j]); + free(hMdDecoder->spar_coeffs_prev.C_re_fx[i][j]); } - free(hMdDecoder->spar_coeffs_prev.P_re_fx[i]); + free(hMdDecoder->spar_coeffs_prev.C_re_fx[i]); } - free(hMdDecoder->spar_coeffs_prev.P_re_fx); + free(hMdDecoder->spar_coeffs_prev.C_re_fx); } -#endif - if ( hMdDecoder->spar_coeffs_tar.C_re != NULL ) + if (hMdDecoder->spar_coeffs_prev.P_re_fx != NULL) { for ( i = 0; i < num_channels; i++ ) { for ( j = 0; j < num_channels; j++ ) { - free( hMdDecoder->spar_coeffs_tar.C_re[i][j] ); + free(hMdDecoder->spar_coeffs_prev.P_re_fx[i][j]); } - free( hMdDecoder->spar_coeffs_tar.C_re[i] ); + free(hMdDecoder->spar_coeffs_prev.P_re_fx[i]); } - free( hMdDecoder->spar_coeffs_tar.C_re ); + free(hMdDecoder->spar_coeffs_prev.P_re_fx); } -#ifdef IVAS_FLOAT_FIXED if (hMdDecoder->spar_coeffs_tar.C_re_fx != NULL) { for (i = 0; i < num_channels; i++) @@ -802,21 +804,6 @@ void ivas_spar_md_dec_matrix_close( } free(hMdDecoder->spar_coeffs_tar.C_re_fx); } -#endif - - if ( hMdDecoder->spar_coeffs_tar.P_re != NULL ) - { - for ( i = 0; i < num_channels; i++ ) - { - for ( j = 0; j < num_channels; j++ ) - { - free( hMdDecoder->spar_coeffs_tar.P_re[i][j] ); - } - free( hMdDecoder->spar_coeffs_tar.P_re[i] ); - } - free( hMdDecoder->spar_coeffs_tar.P_re ); - } -#ifdef IVAS_FLOAT_FIXED if (hMdDecoder->spar_coeffs_tar.P_re_fx != NULL) { for (i = 0; i < num_channels; i++) @@ -829,11 +816,10 @@ void ivas_spar_md_dec_matrix_close( } free(hMdDecoder->spar_coeffs_tar.P_re_fx); } -#endif return; } - +#endif /*------------------------------------------------------------------------- * ivas_spar_md_dec_close() @@ -851,7 +837,11 @@ void ivas_spar_md_dec_close( hMdDecoder = *hMdDec; num_channels = hMdDecoder->spar_md_cfg.num_umx_chs; +#ifndef IVAS_FLOAT_FIXED ivas_spar_md_dec_matrix_close( hMdDecoder, num_channels ); +#else + ivas_spar_md_dec_matrix_close_fx( hMdDecoder, num_channels ); +#endif free( *hMdDec ); *hMdDec = NULL; @@ -865,6 +855,7 @@ Word32 pFC_16k[IVAS_MAX_NUM_BANDS] = { 66, 200, 333, 466, 600, 733, 866, 1133, 1 Word32 pFC_32k[IVAS_MAX_NUM_BANDS] = { 133, 400, 666, 933, 1200, 1466, 1733, 2266, 3466, 5333, 8133, 12933 }; Word32 pFC_48k[IVAS_MAX_NUM_BANDS] = { 199, 600, 1000, 1400, 1800, 2200, 2600, 3400, 5200, 8000, 12200, 19400 }; +#ifndef IVAS_FLOAT_FIXED /*-----------------------------------------------------------------------------------------* * Function ivas_spar_md_dec_init() * @@ -881,7 +872,6 @@ ivas_error ivas_spar_md_dec_init( int16_t i, j; int16_t nchan_transport; float pFC[IVAS_MAX_NUM_BANDS], PR_minmax[2]; - Word32 *pFC_fx=NULL, PR_minmax_fx[2]; ivas_error error; ivas_sba_get_spar_hoa_md_flag( sba_order, hDecoderConfig->ivas_total_brate, &hMdDec->spar_hoa_md_flag, &hMdDec->spar_hoa_dirac2spar_md_flag ); @@ -900,23 +890,117 @@ ivas_error ivas_spar_md_dec_init( pFC[i] = ivas_fb_fcs_12band_1ms[i] * hDecoderConfig->output_Fs * 0.5f; } - if (hDecoderConfig->output_Fs == 8000) + if ( ( error = ivas_spar_set_dec_config( hMdDec, nchan_transport, pFC ) ) != IVAS_ERR_OK ) + { + return error; + } + + if ( nchan_transport != 2 && ( ( hMdDec->spar_md_cfg.remix_unmix_order == 2 ) || ( hMdDec->spar_md_cfg.remix_unmix_order == 1 ) ) ) + { + return IVAS_ERR_INTERNAL; + } + + /* DTX quant init */ + PR_minmax[0] = hMdDec->spar_md_cfg.quant_strat[0].PR.min; + PR_minmax[1] = hMdDec->spar_md_cfg.quant_strat[0].PR.max; + ivas_spar_quant_dtx_init( &hMdDec->spar_md, PR_minmax ); + + ivas_spar_arith_coeffs_com_init( &hMdDec->arith_coeffs, &hMdDec->spar_md_cfg, hMdDec->table_idx, DEC ); + ivas_spar_huff_coeffs_com_init( &hMdDec->huff_coeffs, &hMdDec->spar_md_cfg, hMdDec->table_idx, DEC ); + + hMdDec->spar_md_cfg.prev_quant_idx = -1; + + /* initialize PLC state */ + set_s( hMdDec->valid_bands, 0, IVAS_MAX_NUM_BANDS ); + set_s( hMdDec->base_band_age, 0, IVAS_MAX_NUM_BANDS ); + set_s( hMdDec->base_band_coeffs_age, 0, IVAS_MAX_NUM_BANDS ); + hMdDec->spar_plc_num_lost_frames = 0; + hMdDec->spar_plc_enable_fadeout_flag = 1; + hMdDec->dtx_md_smoothing_cntr = 1; + + ivas_clear_band_coeffs( hMdDec->spar_md.band_coeffs, IVAS_MAX_NUM_BANDS ); + ivas_clear_band_coeffs( hMdDec->band_coeffs_prev, IVAS_MAX_NUM_BANDS ); + ivas_clear_band_coeff_idx( hMdDec->spar_md.band_coeffs_idx, IVAS_MAX_NUM_BANDS ); + ivas_clear_band_coeff_idx( hMdDec->spar_md_prev.band_coeffs_idx, IVAS_MAX_NUM_BANDS ); + ivas_clear_band_coeff_idx( hMdDec->spar_md_prev.band_coeffs_idx_mapped, IVAS_MAX_NUM_BANDS ); + + hMdDec->spar_md.dtx_vad = 0; + hMdDec->td_decorr_flag = 1; + + set_f( hMdDec->spar_md.en_ratio_slow, 0.0f, IVAS_MAX_NUM_BANDS ); + set_f( hMdDec->spar_md.ref_pow_slow, 0.0f, IVAS_MAX_NUM_BANDS ); + + set_zero( hMdDec->smooth_fac, IVAS_MAX_NUM_BANDS ); + for ( i = 0; i < IVAS_MAX_NUM_BANDS; i++ ) + { + set_zero( hMdDec->smooth_buf[i], 2 * SBA_DIRAC_NRG_SMOOTH_LONG + 1 ); + } + + for ( i = 0; i < IVAS_SPAR_MAX_CH; i++ ) + { + for ( j = 0; j < IVAS_SPAR_MAX_CH; j++ ) + { + set_zero( hMdDec->mixer_mat_prev2[i][j], IVAS_MAX_NUM_BANDS ); + } + } + hMdDec->first_valid_frame = 1; + + return IVAS_ERR_OK; +} +#else +/*-----------------------------------------------------------------------------------------* +* Function ivas_spar_md_dec_init() +* +* SPAR MD decoder initialization +*-----------------------------------------------------------------------------------------*/ +ivas_error ivas_spar_md_dec_init( + ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ + const DECODER_CONFIG_HANDLE hDecoderConfig, /* i : configuration structure */ + const int16_t num_channels, /* i : number of internal channels */ + const int16_t sba_order /* i : SBA order */ +) +{ + int16_t i, j; + int16_t nchan_transport; + Word32 pFC[IVAS_MAX_NUM_BANDS], PR_minmax[2]; + Word32 *pFC_fx=NULL, PR_minmax_fx[2]; + ivas_error error; + + ivas_sba_get_spar_hoa_md_flag( sba_order, hDecoderConfig->ivas_total_brate, &hMdDec->spar_hoa_md_flag, &hMdDec->spar_hoa_dirac2spar_md_flag ); + + ivas_sba_get_spar_hoa_ch_ind( num_channels, hDecoderConfig->ivas_total_brate, hMdDec->HOA_md_ind ); + + hMdDec->spar_md.num_bands = ( hMdDec->spar_hoa_md_flag ) ? IVAS_MAX_NUM_BANDS : min( IVAS_MAX_NUM_BANDS, SPAR_DIRAC_SPLIT_START_BAND ); + + ivas_spar_set_bitrate_config_fx(&hMdDec->spar_md_cfg, hMdDec->table_idx, hMdDec->spar_md.num_bands, hMdDec->spar_hoa_dirac2spar_md_flag, 0, 0, 0 ); + + nchan_transport = hMdDec->spar_md_cfg.nchan_transport; + + + + /* get FB coefficients */ + FOR (i = 0; i < IVAS_MAX_NUM_BANDS; i++) + { + pFC[i] = L_shr(Mpy_32_32(ivas_fb_fcs_12band_1ms_fx[i], hDecoderConfig->output_Fs), 1); //Q0 + } + + IF (EQ_32 (hDecoderConfig->output_Fs, 8000)) { pFC_fx = pFC_8k; } - else if (hDecoderConfig->output_Fs == 12800) + ELSE IF(EQ_32(hDecoderConfig->output_Fs, 12800)) { pFC_fx = pFC_12k; } - else if (hDecoderConfig->output_Fs == 16000) + ELSE IF (EQ_32(hDecoderConfig->output_Fs, 16000)) { pFC_fx = pFC_16k; } - else if (hDecoderConfig->output_Fs == 32000) + ELSE IF (EQ_32(hDecoderConfig->output_Fs, 32000)) { pFC_fx = pFC_32k; } - else if (hDecoderConfig->output_Fs == 48000) + ELSE IF (EQ_32(hDecoderConfig->output_Fs, 48000)) { pFC_fx = pFC_48k; } @@ -940,11 +1024,8 @@ ivas_error ivas_spar_md_dec_init( } /* DTX quant init */ - PR_minmax[0] = hMdDec->spar_md_cfg.quant_strat[0].PR.min; PR_minmax_fx[0] = hMdDec->spar_md_cfg.quant_strat[0].PR.min_fx; - PR_minmax[1] = hMdDec->spar_md_cfg.quant_strat[0].PR.max; PR_minmax_fx[1] = hMdDec->spar_md_cfg.quant_strat[0].PR.max_fx; - ivas_spar_quant_dtx_init( &hMdDec->spar_md, PR_minmax ); ivas_spar_quant_dtx_init_fx( &hMdDec->spar_md, PR_minmax_fx ); ivas_spar_arith_coeffs_com_init( &hMdDec->arith_coeffs, &hMdDec->spar_md_cfg, hMdDec->table_idx, DEC ); @@ -960,8 +1041,13 @@ ivas_error ivas_spar_md_dec_init( hMdDec->spar_plc_enable_fadeout_flag = 1; hMdDec->dtx_md_smoothing_cntr = 1; +#ifndef IVAS_FLOAT_FIXED ivas_clear_band_coeffs( hMdDec->spar_md.band_coeffs, IVAS_MAX_NUM_BANDS ); ivas_clear_band_coeffs( hMdDec->band_coeffs_prev, IVAS_MAX_NUM_BANDS ); +#else + ivas_clear_band_coeffs_fx( hMdDec->spar_md.band_coeffs, IVAS_MAX_NUM_BANDS ); + ivas_clear_band_coeffs_fx( hMdDec->band_coeffs_prev, IVAS_MAX_NUM_BANDS ); +#endif ivas_clear_band_coeff_idx( hMdDec->spar_md.band_coeffs_idx, IVAS_MAX_NUM_BANDS ); ivas_clear_band_coeff_idx( hMdDec->spar_md_prev.band_coeffs_idx, IVAS_MAX_NUM_BANDS ); ivas_clear_band_coeff_idx( hMdDec->spar_md_prev.band_coeffs_idx_mapped, IVAS_MAX_NUM_BANDS ); @@ -969,20 +1055,21 @@ ivas_error ivas_spar_md_dec_init( hMdDec->spar_md.dtx_vad = 0; hMdDec->td_decorr_flag = 1; - set_f( hMdDec->spar_md.en_ratio_slow, 0.0f, IVAS_MAX_NUM_BANDS ); + set32_fx( hMdDec->spar_md.en_ratio_slow_fx, 0, IVAS_MAX_NUM_BANDS ); - set_f( hMdDec->spar_md.ref_pow_slow, 0.0f, IVAS_MAX_NUM_BANDS ); set32_fx( hMdDec->spar_md.ref_pow_slow_fx, 0, IVAS_MAX_NUM_BANDS ); + set16_fx( hMdDec->smooth_fac_fx,0, IVAS_MAX_NUM_BANDS ); +#ifndef IVAS_FLOAT_FIXED + set_f( hMdDec->spar_md.en_ratio_slow, 0.0f, IVAS_MAX_NUM_BANDS ); + set_f( hMdDec->spar_md.ref_pow_slow, 0.0f, IVAS_MAX_NUM_BANDS ); set_zero( hMdDec->smooth_fac, IVAS_MAX_NUM_BANDS ); -#ifdef IVAS_FLOAT_FIXED - set16_fx( hMdDec->smooth_fac_fx,0, IVAS_MAX_NUM_BANDS ); #endif for ( i = 0; i < IVAS_MAX_NUM_BANDS; i++ ) { - set_zero( hMdDec->smooth_buf[i], 2 * SBA_DIRAC_NRG_SMOOTH_LONG + 1 ); -#ifdef IVAS_FLOAT_FIXED set32_fx(hMdDec->smooth_buf_fx[i], 0, 2 * SBA_DIRAC_NRG_SMOOTH_LONG + 1); +#ifndef IVAS_FLOAT_FIXED + set_zero( hMdDec->smooth_buf[i], 2 * SBA_DIRAC_NRG_SMOOTH_LONG + 1 ); #endif } @@ -990,9 +1077,9 @@ ivas_error ivas_spar_md_dec_init( { for ( j = 0; j < IVAS_SPAR_MAX_CH; j++ ) { - set_zero( hMdDec->mixer_mat_prev2[i][j], IVAS_MAX_NUM_BANDS ); -#ifdef IVAS_FLOAT_FIXED set32_fx(hMdDec->mixer_mat_prev2_fx[i][j], 0, IVAS_MAX_NUM_BANDS); +#ifndef IVAS_FLOAT_FIXED + set_zero( hMdDec->mixer_mat_prev2[i][j], IVAS_MAX_NUM_BANDS ); #endif } } @@ -1001,6 +1088,8 @@ ivas_error ivas_spar_md_dec_init( return IVAS_ERR_OK; } +#endif + /*-----------------------------------------------------------------------------------------* * Function ivas_spar_set_dec_config() @@ -1120,12 +1209,12 @@ static ivas_error ivas_spar_set_dec_config( * * *-----------------------------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED static void ivas_dec_mono_sba_handling( Decoder_Struct *st_ivas /* i/o: IVAS decoder handle */ ) { - Word16 mono_flag, b, block; + int16_t mono_flag, b, block; mono_flag = 1; @@ -1136,11 +1225,6 @@ static void ivas_dec_mono_sba_handling( float azimuth = st_ivas->hQMetaData->q_direction[0].band_data[b].azimuth[block]; float elevation = st_ivas->hQMetaData->q_direction[0].band_data[b].azimuth[block]; float energy_ratio = st_ivas->hQMetaData->q_direction[0].band_data[0].energy_ratio[block]; -#ifdef IVAS_FLOAT_FIXED - Word32 azimuth_fx = st_ivas->hQMetaData->q_direction[0].band_data[b].azimuth_fx[block]; - Word32 elevation_fx = st_ivas->hQMetaData->q_direction[0].band_data[b].azimuth_fx[block]; - Word32 energy_ratio_fx = st_ivas->hQMetaData->q_direction[0].band_data[0].energy_ratio_fx[block]; -#endif if ( ( azimuth != 0.0f ) || ( elevation != 0.0f ) || @@ -1148,7 +1232,55 @@ static void ivas_dec_mono_sba_handling( { mono_flag = 0; } -#ifdef IVAS_FLOAT_FIXED + } + } + + /* Combine the SPAR prediction coefs flag with the azimuth, elevation and energy ratio flag.*/ + mono_flag = mono_flag && ivas_spar_chk_zero_coefs( st_ivas ); + + if ( mono_flag ) + { + /* Set Energy Ratio values to be zero */ + for ( b = 0; b < st_ivas->hQMetaData->q_direction[0].cfg.nbands; b++ ) + { + set_zero( st_ivas->hQMetaData->q_direction[0].band_data[b].energy_ratio, MAX_PARAM_SPATIAL_SUBFRAMES ); + } + if ( st_ivas->hDirAC != NULL ) + { + for ( block = 0; block < st_ivas->hSpatParamRendCom->dirac_md_buffer_length; ++block ) + { + /* Set directional Energy Ratio values to be zero */ + set_zero( st_ivas->hSpatParamRendCom->energy_ratio1[block], st_ivas->hSpatParamRendCom->num_freq_bands ); + if ( st_ivas->hQMetaData->no_directions == 2 ) + { + set_zero( st_ivas->hSpatParamRendCom->energy_ratio2[block], st_ivas->hSpatParamRendCom->num_freq_bands ); + } + /* Set Diffuseness values to be 1.0 */ + set_f( st_ivas->hSpatParamRendCom->diffuseness_vector[block], 1.0f, st_ivas->hSpatParamRendCom->num_freq_bands ); + } + } + } + + return; +} +#else +static void ivas_dec_mono_sba_handling_fx( + Decoder_Struct *st_ivas /* i/o: IVAS decoder handle */ +) +{ + Word16 mono_flag, b, block; + + mono_flag = 1; + + FOR ( b = 0; b < st_ivas->hQMetaData->q_direction[0].cfg.nbands; b++ ) + { + FOR( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; ++block ) + { + + Word32 azimuth_fx = st_ivas->hQMetaData->q_direction[0].band_data[b].azimuth_fx[block]; + Word32 elevation_fx = st_ivas->hQMetaData->q_direction[0].band_data[b].azimuth_fx[block]; + Word32 energy_ratio_fx = st_ivas->hQMetaData->q_direction[0].band_data[0].energy_ratio_fx[block]; + IF ( ( NE_32(azimuth_fx, 0) ) || (NE_32(elevation_fx, 0) ) || @@ -1156,7 +1288,6 @@ static void ivas_dec_mono_sba_handling( { mono_flag = 0; } -#endif } } @@ -1170,9 +1301,9 @@ static void ivas_dec_mono_sba_handling( for ( b = 0; b < st_ivas->hQMetaData->q_direction[0].cfg.nbands; b++ ) { set_zero( st_ivas->hQMetaData->q_direction[0].band_data[b].energy_ratio, MAX_PARAM_SPATIAL_SUBFRAMES ); -#ifdef IVAS_FLOAT_FIXED + set32_fx( st_ivas->hQMetaData->q_direction[0].band_data[b].energy_ratio_fx,0, MAX_PARAM_SPATIAL_SUBFRAMES ); -#endif + } if ( st_ivas->hDirAC != NULL ) { @@ -1180,21 +1311,21 @@ static void ivas_dec_mono_sba_handling( { /* Set directional Energy Ratio values to be zero */ set_zero( st_ivas->hSpatParamRendCom->energy_ratio1[block], st_ivas->hSpatParamRendCom->num_freq_bands ); -#ifdef IVAS_FLOAT_FIXED + set32_fx( st_ivas->hSpatParamRendCom->energy_ratio1_fx[block],0, st_ivas->hSpatParamRendCom->num_freq_bands ); -#endif + if ( st_ivas->hQMetaData->no_directions == 2 ) { set_zero( st_ivas->hSpatParamRendCom->energy_ratio2[block], st_ivas->hSpatParamRendCom->num_freq_bands ); -#ifdef IVAS_FLOAT_FIXED + set32_fx( st_ivas->hSpatParamRendCom->energy_ratio2_fx[block],0, st_ivas->hSpatParamRendCom->num_freq_bands ); -#endif + } /* Set Diffuseness values to be 1.0 */ set_f( st_ivas->hSpatParamRendCom->diffuseness_vector[block], 1.0f, st_ivas->hSpatParamRendCom->num_freq_bands ); -#ifdef IVAS_FLOAT_FIXED + set32_fx( st_ivas->hSpatParamRendCom->diffuseness_vector_fx[block], ONE_IN_Q30, st_ivas->hSpatParamRendCom->num_freq_bands ); -#endif + } } } @@ -1202,26 +1333,27 @@ static void ivas_dec_mono_sba_handling( return; } - +#endif +#ifdef IVAS_FLOAT_FIXED /*-----------------------------------------------------------------------------------------* - * Function ivas_spar_md_dec_process() + * Function ivas_spar_md_dec_process_fx() * * SPAR Meta Data decoder process *-----------------------------------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED -void ivas_spar_md_dec_process( + +void ivas_spar_md_dec_process_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ Decoder_State *st0, /* i/o: decoder state structure - for bitstream handling */ - const int16_t num_bands_out, /* i : number of output bands */ - const int16_t sba_order /* i : Ambisonic (SBA) order */ + const Word16 num_bands_out, /* i : number of output bands */ + const Word16 sba_order /* i : Ambisonic (SBA) order */ ) { - int16_t j, k, b, bw, dtx_vad, nB, i_ts; + Word16 j, k, b, bw, dtx_vad, nB, i_ts; ivas_spar_md_dec_state_t *hMdDec; - int16_t num_md_chs; - int16_t num_md_sub_frames; - int16_t dyn_active_w_flag; - int16_t active_w_vlbr; + Word16 num_md_chs; + Word16 num_md_sub_frames; + Word16 dyn_active_w_flag; + Word16 active_w_vlbr; hMdDec = st_ivas->hSpar->hMdDec; @@ -1231,48 +1363,55 @@ void ivas_spar_md_dec_process( num_md_sub_frames = ivas_get_spar_dec_md_num_subframes( sba_order, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->last_active_ivas_total_brate ); - if ( hMdDec->spar_md_cfg.nchan_transport > 1 && hMdDec->spar_md_cfg.nchan_transport <= 3 ) + test(); + IF ( GT_16(hMdDec->spar_md_cfg.nchan_transport , 1) && LE_16(hMdDec->spar_md_cfg.nchan_transport , 3) ) { - hMdDec->spar_md.res_ind = 0; - dyn_active_w_flag = get_next_indice( st0, 1 ); - if ( dyn_active_w_flag == 1 ) + hMdDec->spar_md.res_ind = 0; move16(); + dyn_active_w_flag = get_next_indice_fx( st0, 1 ); + IF ( EQ_16(dyn_active_w_flag , 1) ) { - if ( hMdDec->spar_md_cfg.nchan_transport == 2 ) + IF ( EQ_16(hMdDec->spar_md_cfg.nchan_transport , 2) ) { - hMdDec->spar_md.res_ind = get_next_indice( st0, 1 ); - hMdDec->spar_md.res_ind += hMdDec->spar_md_cfg.nchan_transport; + hMdDec->spar_md.res_ind = get_next_indice_fx( st0, 1 ); + move16(); + hMdDec->spar_md.res_ind = add(hMdDec->spar_md_cfg.nchan_transport, hMdDec->spar_md.res_ind); + move16(); } - else if ( hMdDec->spar_md_cfg.nchan_transport == 3 ) + ELSE IF ( EQ_16(hMdDec->spar_md_cfg.nchan_transport , 3) ) { hMdDec->spar_md.res_ind = remix_order_set[hMdDec->spar_md_cfg.remix_unmix_order][hMdDec->spar_md_cfg.nchan_transport]; + move16(); } } } else { dyn_active_w_flag = 0; - if ( hMdDec->spar_md_cfg.nchan_transport == FOA_CHANNELS ) + move16(); + IF ( EQ_16(hMdDec->spar_md_cfg.nchan_transport , FOA_CHANNELS) ) { - get_next_indice( st0, 1 ); + get_next_indice_fx( st0, 1 ); } } - for (int i = 0; i < IVAS_MAX_NUM_BANDS; i++) +#if 0 //ndef IVAS_FLOAT_FIXED_TO_BE_REMOVED + FOR (Word16 i = 0; i < IVAS_MAX_NUM_BANDS; i++) { - for (int ii = 0; ii < IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS; ii++) + FOR (Word16 ii = 0; ii < IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS; ii++) { - for (int jj = 0; jj < IVAS_SPAR_MAX_DMX_CHS - 1; jj++) + FOR (Word16 jj = 0; jj < IVAS_SPAR_MAX_DMX_CHS - 1; jj++) { hMdDec->spar_md.band_coeffs[i].C_re_fx[ii][jj] = (Word32)(hMdDec->spar_md.band_coeffs[i].C_re[ii][jj] * (1 << 22)); } } - for (int jj = 0; jj < IVAS_SPAR_MAX_DMX_CHS - 1; jj++) + FOR (Word16 jj = 0; jj < IVAS_SPAR_MAX_DMX_CHS - 1; jj++) { hMdDec->spar_md.band_coeffs[i].pred_re_fx[jj] = (Word32)(hMdDec->spar_md.band_coeffs[i].pred_re[jj] * (1 << 22)); hMdDec->spar_md.band_coeffs[i].P_re_fx[jj] = (Word32)(hMdDec->spar_md.band_coeffs[i].P_re[jj] * (1 << 22)); } } - ivas_spar_dec_parse_md_bs( hMdDec, st0, &nB, &bw, &dtx_vad, st_ivas->hDecoderConfig->ivas_total_brate, +#endif + ivas_spar_dec_parse_md_bs_fx( hMdDec, st0, &nB, &bw, &dtx_vad, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->hQMetaData->sba_inactive_mode ); @@ -1285,6 +1424,7 @@ void ivas_spar_md_dec_process( &hMdDec->base_band_coeffs_age[0], &hMdDec->first_valid_frame, nB ); +#if 0 //ndef IVAS_FLOAT_FIXED_TO_BE_REMOVED for (int i = 0; i < IVAS_MAX_NUM_BANDS; i++) { for (int ii = 0; ii < IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS; ii++) @@ -1300,16 +1440,18 @@ void ivas_spar_md_dec_process( hMdDec->spar_md.band_coeffs[i].P_re[jj] = (float)hMdDec->spar_md.band_coeffs[i].P_re_fx[jj] / (1 << 22); } } - ivas_dec_mono_sba_handling( st_ivas ); +#endif + ivas_dec_mono_sba_handling_fx( st_ivas ); /* SPAR to DirAC conversion */ - if ( hMdDec->spar_hoa_dirac2spar_md_flag == 1 ) + IF ( EQ_16(hMdDec->spar_hoa_dirac2spar_md_flag , 1) ) { - ivas_spar_to_dirac( st_ivas, hMdDec, dtx_vad, num_bands_out, bw, dyn_active_w_flag ); + ivas_spar_to_dirac_fx( st_ivas, hMdDec, dtx_vad, num_bands_out, bw, dyn_active_w_flag ); } /* set correct number of bands*/ nB = IVAS_MAX_NUM_BANDS; + move16(); /* expand DirAC MD to all time slots */ for ( i_ts = 1; i_ts < num_md_sub_frames; i_ts++ ) @@ -1318,28 +1460,37 @@ void ivas_spar_md_dec_process( { for ( j = 0; j < IVAS_SPAR_MAX_CH - 1; j++ ) { +#if 0 //ndef IVAS_FLOAT_FIXED_TO_BE_REMOVED hMdDec->spar_md.band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].pred_re[j] = hMdDec->spar_md.band_coeffs[b].pred_re[j]; +#endif hMdDec->spar_md.band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].pred_re_fx[j] = hMdDec->spar_md.band_coeffs[b].pred_re_fx[j]; + move32(); } for ( j = 0; j < IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS; j++ ) { for ( k = 0; k < IVAS_SPAR_MAX_DMX_CHS - 1; k++ ) { +#if 0 //ndef IVAS_FLOAT_FIXED_TO_BE_REMOVED hMdDec->spar_md.band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].C_re[j][k] = hMdDec->spar_md.band_coeffs[b].C_re[j][k]; +#endif hMdDec->spar_md.band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].C_re_fx[j][k] = hMdDec->spar_md.band_coeffs[b].C_re_fx[j][k]; + move32(); } } for ( j = 0; j < IVAS_SPAR_MAX_CH - 1; j++ ) { +#if 0 //ndef IVAS_FLOAT_FIXED_TO_BE_REMOVED hMdDec->spar_md.band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].P_re[j] = hMdDec->spar_md.band_coeffs[b].P_re[j]; +#endif hMdDec->spar_md.band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].P_re_fx[j] = hMdDec->spar_md.band_coeffs[b].P_re_fx[j]; + move32(); } } } - ivas_get_spar_matrices( hMdDec, num_bands_out, num_md_sub_frames, bw, dtx_vad, nB, num_md_chs, active_w_vlbr, dyn_active_w_flag ); + ivas_get_spar_matrices_fx( hMdDec, num_bands_out, num_md_sub_frames, bw, dtx_vad, nB, num_md_chs, active_w_vlbr, dyn_active_w_flag ); #ifdef DEBUG_SPAR_DIRAC_WRITE_OUT_PRED_PARS { @@ -1352,15 +1503,20 @@ void ivas_spar_md_dec_process( fprintf( fid, "%.6f\n", hMdDec->mixer_mat[1][0][band] ); } #endif - ivas_spar_md_fill_invalid_bands( &hMdDec->spar_coeffs, &hMdDec->spar_coeffs_prev, &hMdDec->valid_bands[0], &hMdDec->base_band_age[0], num_bands_out, num_md_chs, num_md_sub_frames ); + ivas_spar_md_fill_invalid_bands_fx( &hMdDec->spar_coeffs, &hMdDec->spar_coeffs_prev, &hMdDec->valid_bands[0], &hMdDec->base_band_age[0], num_bands_out, num_md_chs, num_md_sub_frames ); hMdDec->dtx_md_smoothing_cntr = 1; return; } - #else +/*-----------------------------------------------------------------------------------------* + * Function ivas_spar_md_dec_process() + * + * SPAR Meta Data decoder process + *-----------------------------------------------------------------------------------------*/ + void ivas_spar_md_dec_process( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ Decoder_State *st0, /* i/o: decoder state structure - for bitstream handling */ @@ -1481,6 +1637,8 @@ void ivas_spar_md_dec_process( } #endif + +#ifndef IVAS_FLOAT_FIXED /*-----------------------------------------------------------------------------------------* * Function ivas_spar_chk_zero_coefs() * @@ -1530,6 +1688,7 @@ int16_t ivas_spar_chk_zero_coefs( return mono; } +#else Word16 ivas_spar_chk_zero_coefs_fx( Decoder_Struct *st_ivas /* i/o: IVAS decoder handle */ @@ -1574,6 +1733,7 @@ Word16 ivas_spar_chk_zero_coefs_fx( return mono; } +#endif /*-----------------------------------------------------------------------------------------* @@ -1663,7 +1823,7 @@ void ivas_spar_smooth_md_dtx_fx( return; } -#endif +#else void ivas_spar_smooth_md_dtx( ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ const int16_t num_bands_out, /* i : number of output bands */ @@ -1732,6 +1892,7 @@ void ivas_spar_smooth_md_dtx( return; } +#endif /*-----------------------------------------------------------------------------------------* @@ -1805,7 +1966,7 @@ void ivas_spar_setup_md_smoothing_fx( return; } -#endif +#else void ivas_spar_setup_md_smoothing( ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ const int16_t num_bands_out, /* i : number of output bands */ @@ -1865,6 +2026,7 @@ void ivas_spar_setup_md_smoothing( return; } +#endif /*-----------------------------------------------------------------------------------------* @@ -1933,7 +2095,7 @@ void ivas_spar_update_md_hist_fx( return; } -#endif +#else void ivas_spar_update_md_hist( ivas_spar_md_dec_state_t *hMdDec /* i/o: SPAR MD decoder handle */ ) @@ -1988,14 +2150,14 @@ void ivas_spar_update_md_hist( return; } - +#endif /*-----------------------------------------------------------------------------------------* * Function ivas_get_spar_matrices() * * Get SPAR matrices *-----------------------------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED static void ivas_get_spar_matrices( ivas_spar_md_dec_state_t *hMdDec, const int16_t num_bands_out, @@ -2048,10 +2210,6 @@ static void ivas_get_spar_matrices( { set_zero( &hMdDec->spar_coeffs.C_re[i][j][i_ts * IVAS_MAX_NUM_BANDS], IVAS_MAX_NUM_BANDS ); set_zero( &hMdDec->spar_coeffs.P_re[i][j][i_ts * IVAS_MAX_NUM_BANDS], IVAS_MAX_NUM_BANDS ); -#ifdef IVAS_FLOAT_FIXED - set32_fx(&hMdDec->spar_coeffs.C_re_fx[i][j][i_ts * IVAS_MAX_NUM_BANDS], 0, IVAS_MAX_NUM_BANDS); - set32_fx(&hMdDec->spar_coeffs.P_re_fx[i][j][i_ts * IVAS_MAX_NUM_BANDS], 0, IVAS_MAX_NUM_BANDS); -#endif } } num_bands = min( num_bands, nB ); @@ -2226,8 +2384,265 @@ static void ivas_get_spar_matrices( return; } +#else +static void ivas_get_spar_matrices_fx( + ivas_spar_md_dec_state_t *hMdDec, + const int16_t num_bands_out, + const int16_t n_ts, + const int16_t bw, + const int16_t dtx_vad, + const int16_t nB, + const int16_t numch_out, + const int16_t active_w_vlbr, + const int16_t dyn_active_w_flag ) +{ + Word16 num_bands, dmx_ch, split_band; + Word16 i, j, k, m, b, i_ts, active_w; + const Word16 *order; + Word32 active_w_dm_fac_fx, re_fx,re_fx1; + + num_bands = num_bands_out; + order = remix_order_set[hMdDec->spar_md_cfg.remix_unmix_order]; + + split_band = SPAR_DIRAC_SPLIT_START_BAND; + + //Dead code as SPAR_DIRAC_SPLIT_START_BAND = 8 and IVAS_MAX_NUM_BANDS = 12 + IF( GE_16( split_band, IVAS_MAX_NUM_BANDS ) ) + { + /*store previous 4x4 parameters for linear interpolation to current*/ + + FOR( i = 0; i < numch_out; i++ ) + { + FOR( j = 0; j < numch_out; j++ ) + { + FOR( b = 0; b < num_bands; b++ ) + { + hMdDec->mixer_mat_prev_fx[0][i][j][b] = hMdDec->mixer_mat_fx[i][j][b]; + move32(); + } + } + } + } + + IF( bw == IVAS_RED_BAND_FACT ) + { + num_bands = shl( num_bands, 1 ); + } + + active_w = EQ_16( dyn_active_w_flag, 1 ) || EQ_16( hMdDec->spar_md_cfg.active_w, 1 ); + active_w_dm_fac_fx = EQ_16( dtx_vad, 0 ) ? IVAS_ACTIVEW_DM_F_SCALE_DTX_FX : ( EQ_16( active_w_vlbr, 1 ) ? IVAS_ACTIVEW_DM_F_SCALE_VLBR_FX : IVAS_ACTIVEW_DM_F_SCALE_FX ); + + move16(); + FOR( i_ts = 0; i_ts < n_ts; i_ts++ ) + { + FOR( i = 0; i < numch_out; i++ ) + { + FOR( j = 0; j < numch_out; j++ ) + { + + set32_fx( &hMdDec->spar_coeffs.C_re_fx[i][j][i_ts * IVAS_MAX_NUM_BANDS], 0, IVAS_MAX_NUM_BANDS ); + set32_fx( &hMdDec->spar_coeffs.P_re_fx[i][j][i_ts * IVAS_MAX_NUM_BANDS], 0, IVAS_MAX_NUM_BANDS ); + } + } + num_bands = min( num_bands, nB ); + + FOR( b = 0; b < num_bands; b++ ) + { + Word32 tmp_C1_re_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; + Word32 tmp_C2_re_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; + Word32 tmp_dm_re_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; + dmx_ch = hMdDec->spar_md_cfg.num_dmx_chans_per_band[bw * b]; + + FOR( j = 0; j < numch_out; j++ ) + { + set_zero_fx( tmp_C1_re_fx[j], numch_out ); + set_zero_fx( tmp_C2_re_fx[j], numch_out ); + set_zero_fx( tmp_dm_re_fx[j], numch_out ); + + tmp_C1_re_fx[j][j] = ONE_IN_Q22; + tmp_C2_re_fx[j][j] = ONE_IN_Q22; + tmp_dm_re_fx[j][j] = ONE_IN_Q22; + move32(); + move32(); + move32(); + } + + FOR( j = 1; j < numch_out; j++ ) + { + tmp_C1_re_fx[j][0] = hMdDec->spar_md.band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].pred_re_fx[j - 1]; // Q.22 + move32(); + } + + IF( EQ_16( active_w, 1 ) ) + { + FOR( j = 1; j < numch_out; j++ ) + { + + tmp_C2_re_fx[0][j] = Mpy_32_32( active_w_dm_fac_fx, -hMdDec->spar_md.band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].pred_re_fx[j - 1] ); // Q31 *Q22=Q22 + move32(); + } + re_fx = Mpy_32_32( tmp_C2_re_fx[0][1], tmp_C1_re_fx[1][0] ); // Q22 *Q22 =Q13 + re_fx1 = L_add( ONE_IN_Q13, re_fx ); // Q13+Q13 + + re_fx = Mpy_32_32( tmp_C2_re_fx[0][2], tmp_C1_re_fx[2][0] ); // Q22 *Q22 =Q13 + re_fx1 = L_add( re_fx1, re_fx ); // Q13+Q13 + + re_fx = Mpy_32_32( tmp_C2_re_fx[0][3], tmp_C1_re_fx[3][0] ); // Q22 *Q22 =Q13 + tmp_dm_re_fx[0][0] = L_shl(L_add( re_fx1, re_fx ), Q9); // (Q13+Q13) << Q9 = Q22; + move32(); + + if ( EQ_16( dyn_active_w_flag, 1 ) ) + { + tmp_dm_re_fx[0][0] =L_shl(Mpy_32_32( tmp_dm_re_fx[0][0], IVAS_SPAR_DYN_ACTIVEW_THRESH_FX ),Q9); // Q13 *Q31 =Q13 << Q9=Q.22 + move32(); + } + + tmp_dm_re_fx[0][1] = tmp_C2_re_fx[0][1]; + + tmp_dm_re_fx[0][2] = tmp_C2_re_fx[0][2]; + + tmp_dm_re_fx[0][3] = tmp_C2_re_fx[0][3]; + + tmp_dm_re_fx[1][0] = tmp_C1_re_fx[1][0]; + + tmp_dm_re_fx[2][0] = tmp_C1_re_fx[2][0]; + + tmp_dm_re_fx[3][0] = tmp_C1_re_fx[3][0]; + + IF( NE_16( hMdDec->spar_md_cfg.remix_unmix_order, 3 ) ) + { + ivas_mat_col_rearrange_fx( tmp_dm_re_fx, order, i_ts, hMdDec->mixer_mat_fx, b, numch_out ); + } + } + ELSE + { + IF( NE_16( hMdDec->spar_md_cfg.remix_unmix_order, 3 ) ) + { + + ivas_mat_col_rearrange_fx( tmp_C1_re_fx, order, i_ts, hMdDec->mixer_mat_fx, b, numch_out ); + } + } + + IF( GT_16( dmx_ch, 0 ) ) + { + Word32 tmpC_re_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; + Word32 tmpP_re_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; + + FOR( j = 0; j < numch_out; j++ ) + { + set32_fx( tmpC_re_fx[j], 0, numch_out ); + set32_fx( tmpP_re_fx[j], 0, numch_out ); + } + + FOR( j = 0; j < numch_out; j++ ) + { + set32_fx( tmpC_re_fx[j], 0, numch_out ); + } + + FOR( k = 0; k < dmx_ch; k++ ) + { + tmpC_re_fx[k][k] = ONE_IN_Q22; + move32(); + } + + FOR( j = dmx_ch; j < numch_out; j++ ) + { + FOR( k = 1; k < dmx_ch; k++ ) + { + tmpC_re_fx[j][k] = hMdDec->spar_md.band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].C_re_fx[j - dmx_ch][k - 1]; // Q22 + move32(); + } + } + + FOR( j = dmx_ch; j < numch_out; j++ ) + { + FOR( k = dmx_ch; k < numch_out; k++ ) + { + IF( EQ_16( sub( j, dmx_ch ), sub( k, dmx_ch ) ) ) + { + tmpP_re_fx[j][k] = hMdDec->spar_md.band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].P_re_fx[k - dmx_ch]; // Q22 + move32(); + } + ELSE + { + tmpP_re_fx[j][k] = 0; + move32(); + } + } + } + + + FOR( j = 1; j < numch_out; j++ ) + { + FOR( k = dmx_ch; k < numch_out; k++ ) + { + FOR( m = 0; m < numch_out; m++ ) + { + re_fx = Mpy_32_32( hMdDec->mixer_mat_fx[j][m][b + i_ts * IVAS_MAX_NUM_BANDS], tmpP_re_fx[m][k] ); // Q30*Q22 + re_fx = L_shl( re_fx, 1 ); + hMdDec->spar_coeffs.P_re_fx[j][k][( b * bw ) + i_ts * IVAS_MAX_NUM_BANDS] = L_add( hMdDec->spar_coeffs.P_re_fx[j][k][( b * bw ) + i_ts * IVAS_MAX_NUM_BANDS], re_fx ); + move32(); + } + } + } + + + FOR( j = 0; j < numch_out; j++ ) + { + FOR( k = 0; k < dmx_ch; k++ ) + { + FOR( m = 0; m < numch_out; m++ ) + { + re_fx = Mpy_32_32( hMdDec->mixer_mat_fx[j][m][b + i_ts * IVAS_MAX_NUM_BANDS], tmpC_re_fx[m][k] ); // Q30* Q22 + re_fx = L_shl( re_fx, 1 ); + hMdDec->spar_coeffs.C_re_fx[j][k][( b * bw ) + i_ts * IVAS_MAX_NUM_BANDS] = L_add( hMdDec->spar_coeffs.C_re_fx[j][k][( b * bw ) + i_ts * IVAS_MAX_NUM_BANDS], re_fx ); + move32(); + } + } + } + + hMdDec->spar_coeffs.C_re_fx[0][0][( b * bw ) + i_ts * IVAS_MAX_NUM_BANDS] = + max( 0, hMdDec->spar_coeffs.C_re_fx[0][0][( b * bw ) + i_ts * IVAS_MAX_NUM_BANDS] ); + } + } + + /* band mixing */ + IF( EQ_16( bw, IVAS_RED_BAND_FACT ) ) + { + FOR( b = 0; b < num_bands_out; b = b + bw ) + { + dmx_ch = hMdDec->spar_md_cfg.num_dmx_chans_per_band[b]; + move16(); + FOR( j = 0; j < numch_out; j++ ) + { + FOR( k = dmx_ch; k < numch_out; k++ ) + { + + hMdDec->spar_coeffs.P_re_fx[j][k][( b + 1 ) + i_ts * IVAS_MAX_NUM_BANDS] = hMdDec->spar_coeffs.P_re_fx[j][k][b + i_ts * IVAS_MAX_NUM_BANDS]; + move32(); + } + } + + FOR( j = 0; j < numch_out; j++ ) + { + FOR( k = 0; k < dmx_ch; k++ ) + { + + hMdDec->spar_coeffs.C_re_fx[j][k][( b + 1 ) + i_ts * IVAS_MAX_NUM_BANDS] = hMdDec->spar_coeffs.C_re_fx[j][k][b + i_ts * IVAS_MAX_NUM_BANDS]; + + move32(); + } + } + } + } + } + + return; +} +#endif +#ifndef IVAS_FLOAT_FIXED /*-----------------------------------------------------------------------------------------* * Function ivas_mat_col_rearrange() * @@ -2256,7 +2671,39 @@ static void ivas_mat_col_rearrange( return; } +#else +/*-----------------------------------------------------------------------------------------* +* Function ivas_mat_col_rearrange() +* +* reorders the input matrix based on order +*-----------------------------------------------------------------------------------------*/ + +static void ivas_mat_col_rearrange_fx( + Word32 in_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + const Word16 order[IVAS_SPAR_MAX_CH], + const Word16 i_ts, + Word32 ***mixer_mat, + const Word16 bands, + const Word16 num_ch +) +{ + Word16 i, j, idx; + FOR( i = 0; i < num_ch; i++ ) + { + idx = order[i]; + move16(); + + FOR( j = 0; j < num_ch; j++ ) + { + mixer_mat[j][i][bands + i_ts * IVAS_MAX_NUM_BANDS] = L_shl_sat(in_re[j][idx], Q8); + move32(); + } + } + + return; +} +#endif /*-----------------------------------------------------------------------------------------* * Function ivas_spar_dec_gen_umx_mat() @@ -2284,7 +2731,7 @@ void ivas_spar_dec_gen_umx_mat_fx( { FOR ( b = 0; b < num_bands_out; b++ ) { - hMdDec->mixer_mat_fx[i][j][b + i_ts * IVAS_MAX_NUM_BANDS] = hMdDec->spar_coeffs.C_re_fx[i][j][b + i_ts * IVAS_MAX_NUM_BANDS]; + hMdDec->mixer_mat_fx[i][j][b + i_ts * IVAS_MAX_NUM_BANDS] = L_shl_sat(hMdDec->spar_coeffs.C_re_fx[i][j][b + i_ts * IVAS_MAX_NUM_BANDS], Q8); move32(); } } @@ -2295,7 +2742,7 @@ void ivas_spar_dec_gen_umx_mat_fx( { FOR ( b = 0; b < num_bands_out; b++ ) { - hMdDec->mixer_mat_fx[i][j][b + i_ts * IVAS_MAX_NUM_BANDS] = hMdDec->spar_coeffs.P_re_fx[i][j][b + i_ts * IVAS_MAX_NUM_BANDS]; + hMdDec->mixer_mat_fx[i][j][b + i_ts * IVAS_MAX_NUM_BANDS] = L_shl_sat(hMdDec->spar_coeffs.P_re_fx[i][j][b + i_ts * IVAS_MAX_NUM_BANDS], Q8); move32(); } } @@ -2309,7 +2756,7 @@ void ivas_spar_dec_gen_umx_mat_fx( { FOR ( b = 0; b < num_bands_out; b++ ) { - hMdDec->mixer_mat_fx[i][j][b + i_ts * IVAS_MAX_NUM_BANDS] = hMdDec->spar_coeffs.C_re_fx[i][j][b + i_ts * IVAS_MAX_NUM_BANDS]; + hMdDec->mixer_mat_fx[i][j][b + i_ts * IVAS_MAX_NUM_BANDS] = L_shl_sat(hMdDec->spar_coeffs.C_re_fx[i][j][b + i_ts * IVAS_MAX_NUM_BANDS], Q8); move32(); } } @@ -2319,7 +2766,7 @@ void ivas_spar_dec_gen_umx_mat_fx( ivas_spar_dec_compute_ramp_down_post_matrix_fx( hMdDec, num_bands_out, bfi, num_md_sub_frames); return; } -#endif // IVAS_FLOAT_FIXED +#else // IVAS_FLOAT_FIXED void ivas_spar_dec_gen_umx_mat( ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ @@ -2378,6 +2825,7 @@ void ivas_spar_dec_gen_umx_mat( return; } +#endif static void ivas_spar_md_band_upmix( ivas_band_coeffs_t *band_coeffs, @@ -2390,55 +2838,296 @@ static void ivas_spar_md_band_upmix( { int16_t i, ii, jj, b, idx, bw_fact; - bw_fact = *bands_bw / bw_final; - for ( i = *nB - 1; i >= 0; i-- ) + bw_fact = *bands_bw / bw_final; + for ( i = *nB - 1; i >= 0; i-- ) + { + + for ( b = bw_fact - 1; b >= 0; b-- ) + { + idx = i * bw_fact + b; + for ( ii = 0; ii < ndec + ndm - 1; ii++ ) + { +#if 0 //ndef IVAS_FLOAT_FIXED_TO_BE_REMOVED + band_coeffs[idx].pred_re[ii] = band_coeffs[i].pred_re[ii]; +#endif + band_coeffs[idx].pred_re_fx[ii] = band_coeffs[i].pred_re_fx[ii]; + } + for ( ii = 0; ii < ndec; ii++ ) + { + for ( jj = 0; jj < ndm - 1; jj++ ) + { +#if 0 //ndef IVAS_FLOAT_FIXED_TO_BE_REMOVED + band_coeffs[idx].C_re[ii][jj] = band_coeffs[i].C_re[ii][jj]; +#endif + band_coeffs[idx].C_re_fx[ii][jj] = band_coeffs[i].C_re_fx[ii][jj]; + } + } + for ( jj = 0; jj < ndec; jj++ ) + { +#if 0 //ndef IVAS_FLOAT_FIXED_TO_BE_REMOVED + band_coeffs[idx].P_re[jj] = band_coeffs[i].P_re[jj]; +#endif + band_coeffs[idx].P_re_fx[jj] = band_coeffs[i].P_re_fx[jj]; + } + valid_bands[idx] = valid_bands[i]; + } + } + *nB = ( *nB ) * ( *bands_bw ) / bw_final; + *bands_bw = bw_final; + + return; +} + +/*-----------------------------------------------------------------------------------------* + * Function ivas_spar_dec_parse_md_bs() + * + * Parse SPAR MD bitstream + *-----------------------------------------------------------------------------------------*/ + +#ifndef IVAS_FLOAT_FIXED +static void ivas_spar_dec_parse_md_bs( + ivas_spar_md_dec_state_t *hMdDec, + Decoder_State *st0, + int16_t *nB, + int16_t *bands_bw, + int16_t *dtx_vad, + const int32_t ivas_total_brate, + const int16_t sba_inactive_mode +) +{ + int16_t i, j, k, num_bands; + int16_t ii, jj, ndec, ndm; + uint16_t qsi; + ivas_quant_strat_t qs; + int16_t strat, no_ec; + int16_t do_diff[IVAS_MAX_NUM_BANDS]; + float quant[IVAS_SPAR_MAX_C_COEFF]; + int16_t do_repeat[IVAS_MAX_NUM_BANDS]; + *dtx_vad = 1; + *bands_bw = 1; + qsi = 0; + num_bands = hMdDec->spar_md.num_bands; + + if ( ivas_total_brate > IVAS_SID_5k2 ) + { + if ( hMdDec->spar_md_cfg.quant_strat_bits > 0 ) + { + if ( ivas_total_brate >= BRATE_SPAR_Q_STRAT ) + { + /*only one bit written for quantization strategy to indicate either a fixed quantization strategy or dtx_vad==0 */ + qsi = get_next_indice( st0, 1 ); + if ( qsi == 1 ) + { + *dtx_vad = 0; + } + } + else + { + if ( sba_inactive_mode == 1 ) + { + *dtx_vad = 0; + qsi = hMdDec->spar_md_cfg.quant_strat_bits + 1; + } + else + { + qsi = get_next_indice( st0, hMdDec->spar_md_cfg.quant_strat_bits ); + } + } + } + else + { + qsi = 0; + } + } + else + { + *dtx_vad = 0; + } + + hMdDec->dtx_vad = *dtx_vad; + + if ( *dtx_vad == 0 ) + { + *nB = SPAR_DTX_BANDS; + *bands_bw = num_bands / *nB; + + for ( i = 0; i < *nB; i++ ) + { + for ( j = 0; j < IVAS_SPAR_MAX_CH - 1; j++ ) + { + hMdDec->spar_md.band_coeffs[i].pred_re[j] = 0; + hMdDec->spar_md.band_coeffs[i].P_re[j] = 0; + } + hMdDec->valid_bands[i] = 1; + } + + for ( i = 0; i < num_bands; i++ ) + { + for ( j = 0; j < ( IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS ); j++ ) + { + for ( k = 0; k < ( IVAS_SPAR_MAX_DMX_CHS - 1 ); k++ ) + { + hMdDec->spar_md.band_coeffs[i].C_re[j][k] = 0; + } + } + } + + ivas_parse_parameter_bitstream_dtx( &hMdDec->spar_md, st0, *bands_bw, *nB, hMdDec->spar_md_cfg.num_dmx_chans_per_band, hMdDec->spar_md_cfg.num_decorr_per_band ); + + if ( *bands_bw != 1 ) + { + ndec = hMdDec->spar_md_cfg.num_decorr_per_band[0]; + ndm = hMdDec->spar_md_cfg.num_dmx_chans_per_band[0]; + ivas_spar_md_band_upmix( + hMdDec->spar_md.band_coeffs, + nB, + bands_bw, + hMdDec->valid_bands, + 1, + ndec, + ndm ); + } + + return; + } + + qs = hMdDec->spar_md_cfg.quant_strat[qsi]; + + strat = get_next_indice( st0, 3 ); + + no_ec = 0; + + if ( strat < 2 ) + { + *bands_bw = strat + 1; + *nB = num_bands / *bands_bw; + for ( i = 0; i < *nB; i++ ) + { + do_diff[i] = 0; + do_repeat[i] = 0; + } + } + else if ( strat < 4 ) + { + *bands_bw = strat - 1; + *nB = num_bands / *bands_bw; + for ( i = 0; i < *nB; i++ ) + { + do_diff[i] = 0; + do_repeat[i] = 0; + } + no_ec = 1; + } + else if ( ivas_total_brate < IVAS_24k4 ) + { + *bands_bw = 2; + *nB = num_bands / *bands_bw; + + for ( i = 0; i < *nB; i++ ) + { + do_diff[i] = 0; + do_repeat[i] = ( ( strat % 2 ) == ( ( i + 1 ) % 2 ) ); + } + } + else + { + *bands_bw = 1; + *nB = num_bands; + + for ( i = 0; i < *nB; i++ ) + { + do_diff[i] = ( ( ( i + 1 ) & 3 ) != strat - 4 ); + do_repeat[i] = 0; + } + if ( hMdDec->spar_md_cfg.prev_quant_idx >= 0 ) + { + ivas_map_prior_coeffs_quant( &hMdDec->spar_md_prev, &hMdDec->spar_md_cfg, qsi, *nB ); + } + } + hMdDec->spar_md_cfg.prev_quant_idx = qsi; + + if ( no_ec == 0 ) + { + ivas_decode_arith_bs( hMdDec, st0, qsi, *nB, *bands_bw, do_diff, strat, ivas_total_brate ); + } + else + { + ivas_decode_huffman_bs( hMdDec, st0, qsi, *nB, *bands_bw ); + } + + for ( i = 0; i < *nB; i++ ) { + ndec = hMdDec->spar_md_cfg.num_decorr_per_band[( *bands_bw ) * i]; + ndm = hMdDec->spar_md_cfg.num_dmx_chans_per_band[( *bands_bw ) * i]; - for ( b = bw_fact - 1; b >= 0; b-- ) + ivas_deindex_real_index( hMdDec->spar_md.band_coeffs_idx[i].pred_index_re, qs.PR.q_levels[0], qs.PR.min, qs.PR.max, hMdDec->spar_md.band_coeffs[i].pred_re, ndm + ndec - 1 ); + + j = 0; + for ( ii = 0; ii < ndec; ii++ ) { - idx = i * bw_fact + b; - for ( ii = 0; ii < ndec + ndm - 1; ii++ ) - { - band_coeffs[idx].pred_re[ii] = band_coeffs[i].pred_re[ii]; - band_coeffs[idx].pred_re_fx[ii] = band_coeffs[i].pred_re_fx[ii]; - } - for ( ii = 0; ii < ndec; ii++ ) + for ( jj = 0; jj < ndm - 1; jj++ ) { - for ( jj = 0; jj < ndm - 1; jj++ ) - { - band_coeffs[idx].C_re[ii][jj] = band_coeffs[i].C_re[ii][jj]; - band_coeffs[idx].C_re_fx[ii][jj] = band_coeffs[i].C_re_fx[ii][jj]; - } + quant[j] = hMdDec->spar_md.band_coeffs[i].C_re[ii][jj]; + j++; } - for ( jj = 0; jj < ndec; jj++ ) + } + + ivas_deindex_real_index( hMdDec->spar_md.band_coeffs_idx[i].drct_index_re, qs.C.q_levels[0], qs.C.min, qs.C.max, quant, ndec * ( ndm - 1 ) ); + + j = 0; + for ( ii = 0; ii < ndec; ii++ ) + { + for ( jj = 0; jj < ndm - 1; jj++ ) { - band_coeffs[idx].P_re[jj] = band_coeffs[i].P_re[jj]; - band_coeffs[idx].P_re_fx[jj] = band_coeffs[i].P_re_fx[jj]; + hMdDec->spar_md.band_coeffs[i].C_re[ii][jj] = quant[j]; + j++; } - valid_bands[idx] = valid_bands[i]; } + + ivas_deindex_real_index( hMdDec->spar_md.band_coeffs_idx[i].decd_index_re, qs.P_r.q_levels[0], qs.P_r.min, qs.P_r.max, hMdDec->spar_md.band_coeffs[i].P_re, ndm + ndec - 1 ); + + /* Store prior coefficient indices */ + for ( j = 0; j < ndm + ndec - 1; j++ ) + { + hMdDec->spar_md_prev.band_coeffs_idx[i].pred_index_re[j] = hMdDec->spar_md.band_coeffs_idx[i].pred_index_re[j]; + } + for ( j = 0; j < ndec * ( ndm - 1 ); j++ ) + { + hMdDec->spar_md_prev.band_coeffs_idx[i].drct_index_re[j] = hMdDec->spar_md.band_coeffs_idx[i].drct_index_re[j]; + } + for ( j = 0; j < ndec; j++ ) + { + hMdDec->spar_md_prev.band_coeffs_idx[i].decd_index_re[j] = hMdDec->spar_md.band_coeffs_idx[i].decd_index_re[j]; + } + hMdDec->valid_bands[i] |= ( do_diff[i] == 0 && do_repeat[i] == 0 ) ? 1 : 0; } - *nB = ( *nB ) * ( *bands_bw ) / bw_final; - *bands_bw = bw_final; - return; -} + ndec = hMdDec->spar_md_cfg.num_decorr_per_band[0]; + ndm = hMdDec->spar_md_cfg.num_dmx_chans_per_band[0]; + if ( *bands_bw != 1 ) + { + ivas_spar_md_band_upmix( + hMdDec->spar_md.band_coeffs, + nB, + bands_bw, + hMdDec->valid_bands, + 1, + ndec, + ndm ); + } -/*-----------------------------------------------------------------------------------------* - * Function ivas_spar_dec_parse_md_bs() - * - * Parse SPAR MD bitstream - *-----------------------------------------------------------------------------------------*/ -static void ivas_spar_dec_parse_md_bs( + return; +} +#else +static void ivas_spar_dec_parse_md_bs_fx( ivas_spar_md_dec_state_t *hMdDec, Decoder_State *st0, int16_t *nB, int16_t *bands_bw, int16_t *dtx_vad, const int32_t ivas_total_brate, - const int16_t sba_inactive_mode -) + const int16_t sba_inactive_mode) { int16_t i, j, k, num_bands; int16_t ii, jj, ndec, ndm; @@ -2446,7 +3135,7 @@ static void ivas_spar_dec_parse_md_bs( ivas_quant_strat_t qs; int16_t strat, no_ec; int16_t do_diff[IVAS_MAX_NUM_BANDS]; - float quant[IVAS_SPAR_MAX_C_COEFF]; + //float quant[IVAS_SPAR_MAX_C_COEFF]; Word32 quant_fx[IVAS_SPAR_MAX_C_COEFF]; int16_t do_repeat[IVAS_MAX_NUM_BANDS]; *dtx_vad = 1; @@ -2501,9 +3190,9 @@ static void ivas_spar_dec_parse_md_bs( { for ( j = 0; j < IVAS_SPAR_MAX_CH - 1; j++ ) { - hMdDec->spar_md.band_coeffs[i].pred_re[j] = 0; + //hMdDec->spar_md.band_coeffs[i].pred_re[j] = 0; hMdDec->spar_md.band_coeffs[i].pred_re_fx[j] = 0; - hMdDec->spar_md.band_coeffs[i].P_re[j] = 0; + //hMdDec->spar_md.band_coeffs[i].P_re[j] = 0; hMdDec->spar_md.band_coeffs[i].P_re_fx[j] = 0; } hMdDec->valid_bands[i] = 1; @@ -2515,7 +3204,7 @@ static void ivas_spar_dec_parse_md_bs( { for ( k = 0; k < ( IVAS_SPAR_MAX_DMX_CHS - 1 ); k++ ) { - hMdDec->spar_md.band_coeffs[i].C_re[j][k] = 0; + //hMdDec->spar_md.band_coeffs[i].C_re[j][k] = 0; hMdDec->spar_md.band_coeffs[i].C_re_fx[j][k] = 0; } } @@ -2609,7 +3298,7 @@ static void ivas_spar_dec_parse_md_bs( ndec = hMdDec->spar_md_cfg.num_decorr_per_band[( *bands_bw ) * i]; ndm = hMdDec->spar_md_cfg.num_dmx_chans_per_band[( *bands_bw ) * i]; - ivas_deindex_real_index( hMdDec->spar_md.band_coeffs_idx[i].pred_index_re, qs.PR.q_levels[0], qs.PR.min, qs.PR.max, hMdDec->spar_md.band_coeffs[i].pred_re, ndm + ndec - 1 ); + //ivas_deindex_real_index( hMdDec->spar_md.band_coeffs_idx[i].pred_index_re, qs.PR.q_levels[0], qs.PR.min, qs.PR.max, hMdDec->spar_md.band_coeffs[i].pred_re, ndm + ndec - 1 ); ivas_deindex_real_index_fx( hMdDec->spar_md.band_coeffs_idx[i].pred_index_re, qs.PR.q_levels[0], qs.PR.min_fx, qs.PR.max_fx, hMdDec->spar_md.band_coeffs[i].pred_re_fx, ndm + ndec - 1 ); j = 0; @@ -2617,13 +3306,13 @@ static void ivas_spar_dec_parse_md_bs( { for ( jj = 0; jj < ndm - 1; jj++ ) { - quant[j] = hMdDec->spar_md.band_coeffs[i].C_re[ii][jj]; + //quant[j] = hMdDec->spar_md.band_coeffs[i].C_re[ii][jj]; quant_fx[j] = hMdDec->spar_md.band_coeffs[i].C_re_fx[ii][jj]; j++; } } - ivas_deindex_real_index( hMdDec->spar_md.band_coeffs_idx[i].drct_index_re, qs.C.q_levels[0], qs.C.min, qs.C.max, quant, ndec * ( ndm - 1 ) ); + //ivas_deindex_real_index( hMdDec->spar_md.band_coeffs_idx[i].drct_index_re, qs.C.q_levels[0], qs.C.min, qs.C.max, quant, ndec * ( ndm - 1 ) ); ivas_deindex_real_index_fx( hMdDec->spar_md.band_coeffs_idx[i].drct_index_re, qs.C.q_levels[0], qs.C.min_fx, qs.C.max_fx, quant_fx, ndec * ( ndm - 1 ) ); j = 0; @@ -2631,13 +3320,13 @@ static void ivas_spar_dec_parse_md_bs( { for ( jj = 0; jj < ndm - 1; jj++ ) { - hMdDec->spar_md.band_coeffs[i].C_re[ii][jj] = quant[j]; + //hMdDec->spar_md.band_coeffs[i].C_re[ii][jj] = quant[j]; hMdDec->spar_md.band_coeffs[i].C_re_fx[ii][jj] = quant_fx[j]; j++; } } - ivas_deindex_real_index( hMdDec->spar_md.band_coeffs_idx[i].decd_index_re, qs.P_r.q_levels[0], qs.P_r.min, qs.P_r.max, hMdDec->spar_md.band_coeffs[i].P_re, ndm + ndec - 1 ); + //ivas_deindex_real_index( hMdDec->spar_md.band_coeffs_idx[i].decd_index_re, qs.P_r.q_levels[0], qs.P_r.min, qs.P_r.max, hMdDec->spar_md.band_coeffs[i].P_re, ndm + ndec - 1 ); ivas_deindex_real_index_fx( hMdDec->spar_md.band_coeffs_idx[i].decd_index_re, qs.P_r.q_levels[0], qs.P_r.min_fx, qs.P_r.max_fx, hMdDec->spar_md.band_coeffs[i].P_re_fx, ndm + ndec - 1 ); /* Store prior coefficient indices */ @@ -2673,6 +3362,7 @@ static void ivas_spar_dec_parse_md_bs( return; } +#endif /*-----------------------------------------------------------------------------------------* @@ -3048,6 +3738,92 @@ static void ivas_spar_get_plc_interp_weights_fx( return; } +#ifdef IVAS_FLOAT_FIXED +/*-----------------------------------------------------------------------------------------* + * Function ivas_spar_md_fill_invalid_bands_fx() + * + * Fill invalid bands in interpolation/extrapolation of valid bands + * when PLC is to be done with partial time differential coding + *-----------------------------------------------------------------------------------------*/ +static void ivas_spar_md_fill_invalid_bands_fx( + ivas_spar_dec_matrices_t *pSpar_coeffs, + ivas_spar_dec_matrices_t *pSpar_coeffs_prev, + const Word16 *valid_bands, + Word16 *base_band_age, + const Word16 num_bands, + const Word16 num_channels, + const Word16 num_md_sub_frames ) +{ + Word16 i, j, b, all_valid; + Word16 valid_band_idx[IVAS_MAX_NUM_BANDS], idx = -1; + Word16 last_valid_band_idx[IVAS_MAX_NUM_BANDS]; + Word16 w_fx = 0; + ivas_spar_plc_get_band_age( valid_bands, base_band_age, num_bands, + last_valid_band_idx, valid_band_idx, &all_valid, &idx ); + assert( idx > 0 ); /* some bands should be valid */ + + IF ( EQ_16(all_valid , 0) ) + { + FOR ( b = 0; b < num_bands; b++ ) + { + /* check against non zero in if and else if */ + + IF ( GT_16(base_band_age[b] , 3) ) /* old invalid bands */ + { + Word16 id0, id1; + ivas_spar_get_plc_interp_weights_fx( valid_band_idx, last_valid_band_idx[b], + idx, b, &w_fx, &id0, &id1); + FOR ( i = 0; i < num_channels; i++ ) + { + FOR ( j = 0; j < num_channels; j++ ) + { + pSpar_coeffs->C_re_fx[i][j][b] = L_add(Mpy_32_16_1(pSpar_coeffs->C_re_fx[i][j][id0], sub(MAX_WORD16, w_fx)), Mpy_32_16_1(pSpar_coeffs->C_re_fx[i][j][id1], w_fx)); + move32(); + pSpar_coeffs->P_re_fx[i][j][b] = L_add(Mpy_32_16_1(pSpar_coeffs->P_re_fx[i][j][id0], sub(MAX_WORD16, w_fx)), Mpy_32_16_1(pSpar_coeffs->P_re_fx[i][j][id1], w_fx)); + move32(); + } + } + } + ELSE /* young invalid bands */ + { + IF ( EQ_16(valid_bands[b] , 0) ) + { + FOR ( i = 0; i < num_channels; i++ ) + { + FOR ( j = 0; j < num_channels; j++ ) + { + pSpar_coeffs->C_re_fx[i][j][b] = pSpar_coeffs_prev->C_re_fx[i][j][b]; + move32(); + pSpar_coeffs->P_re_fx[i][j][b] = pSpar_coeffs_prev->P_re_fx[i][j][b]; + move32(); + } + } + } + } + + IF ( EQ_16(valid_bands[b] , 0) ) + { + Word16 i_ts; + FOR ( i = 0; i < num_channels; i++ ) + { + FOR ( j = 0; j < num_channels; j++ ) + { + FOR ( i_ts = 1; i_ts < num_md_sub_frames; i_ts++ ) + { + pSpar_coeffs->C_re_fx[i][j][add(b , i_ts * IVAS_MAX_NUM_BANDS)] = pSpar_coeffs->C_re_fx[i][j][b]; + move32(); + pSpar_coeffs->P_re_fx[i][j][add(b , i_ts * IVAS_MAX_NUM_BANDS)] = pSpar_coeffs->P_re_fx[i][j][b]; + move32(); + } + } + } + } + } + } + + return; +} +#else /*-----------------------------------------------------------------------------------------* * Function ivas_spar_md_fill_invalid_bands() * @@ -3067,7 +3843,6 @@ static void ivas_spar_md_fill_invalid_bands( int16_t valid_band_idx[IVAS_MAX_NUM_BANDS], idx = -1; int16_t last_valid_band_idx[IVAS_MAX_NUM_BANDS]; float w = 0; - Word16 w_fx = 0; ivas_spar_plc_get_band_age( valid_bands, base_band_age, num_bands, last_valid_band_idx, valid_band_idx, &all_valid, &idx ); assert( idx > 0 ); /* some bands should be valid */ @@ -3077,24 +3852,17 @@ static void ivas_spar_md_fill_invalid_bands( for ( b = 0; b < num_bands; b++ ) { /* check against non zero in if and else if */ - if ( base_band_age[b] > 3 ) /* old invalid bands */ { int16_t id0, id1; ivas_spar_get_plc_interp_weights( valid_band_idx, last_valid_band_idx[b], idx, b, &w, &id0, &id1 ); - ivas_spar_get_plc_interp_weights_fx(valid_band_idx, last_valid_band_idx[b], - idx, b, &w_fx, &id0, &id1); for ( i = 0; i < num_channels; i++ ) { for ( j = 0; j < num_channels; j++ ) { pSpar_coeffs->C_re[i][j][b] = ( 1 - w ) * pSpar_coeffs->C_re[i][j][id0] + w * pSpar_coeffs->C_re[i][j][id1]; pSpar_coeffs->P_re[i][j][b] = ( 1 - w ) * pSpar_coeffs->P_re[i][j][id0] + w * pSpar_coeffs->P_re[i][j][id1]; -#ifdef IVAS_FLOAT_FIXED - pSpar_coeffs->C_re_fx[i][j][b] = L_add(Mpy_32_16_1(pSpar_coeffs->C_re_fx[i][j][id0], sub(MAX_WORD16, w_fx)), Mpy_32_16_1(pSpar_coeffs->C_re_fx[i][j][id1], w_fx)); - pSpar_coeffs->P_re_fx[i][j][b] = L_add(Mpy_32_16_1(pSpar_coeffs->P_re_fx[i][j][id0], sub(MAX_WORD16, w_fx)), Mpy_32_16_1(pSpar_coeffs->P_re_fx[i][j][id1], w_fx)); -#endif } } } @@ -3108,10 +3876,6 @@ static void ivas_spar_md_fill_invalid_bands( { pSpar_coeffs->C_re[i][j][b] = pSpar_coeffs_prev->C_re[i][j][b]; pSpar_coeffs->P_re[i][j][b] = pSpar_coeffs_prev->P_re[i][j][b]; -#ifdef IVAS_FLOAT_FIXED - pSpar_coeffs->C_re_fx[i][j][b] = pSpar_coeffs_prev->C_re_fx[i][j][b]; - pSpar_coeffs->P_re_fx[i][j][b] = pSpar_coeffs_prev->P_re_fx[i][j][b]; -#endif } } } @@ -3128,10 +3892,6 @@ static void ivas_spar_md_fill_invalid_bands( { pSpar_coeffs->C_re[i][j][b + i_ts * IVAS_MAX_NUM_BANDS] = pSpar_coeffs->C_re[i][j][b]; pSpar_coeffs->P_re[i][j][b + i_ts * IVAS_MAX_NUM_BANDS] = pSpar_coeffs->P_re[i][j][b]; -#ifdef IVAS_FLOAT_FIXED - pSpar_coeffs->C_re_fx[i][j][b + i_ts * IVAS_MAX_NUM_BANDS] = pSpar_coeffs->C_re_fx[i][j][b]; - pSpar_coeffs->P_re_fx[i][j][b + i_ts * IVAS_MAX_NUM_BANDS] = pSpar_coeffs->P_re_fx[i][j][b]; -#endif } } } @@ -3141,6 +3901,7 @@ static void ivas_spar_md_fill_invalid_bands( return; } +#endif static void ivas_spar_md_fill_invalid_bandcoeffs( ivas_band_coeffs_t *pBand_coeffs, @@ -3153,7 +3914,7 @@ static void ivas_spar_md_fill_invalid_bandcoeffs( int16_t j, k, b, all_valid; int16_t valid_band_idx[IVAS_MAX_NUM_BANDS], idx = -1; int16_t last_valid_band_idx[IVAS_MAX_NUM_BANDS]; - float w = 0; + //float w = 0; Word16 w_fx = 0; ivas_spar_plc_get_band_age( valid_bands, base_band_age, num_bands, @@ -3169,14 +3930,14 @@ static void ivas_spar_md_fill_invalid_bandcoeffs( if ( ( base_band_age[b] > 3 ) || ( *first_valid_frame == 0 ) ) /* old invalid bands */ { int16_t id0, id1; - ivas_spar_get_plc_interp_weights( valid_band_idx, last_valid_band_idx[b], - idx, b, &w, &id0, &id1 ); + //ivas_spar_get_plc_interp_weights( valid_band_idx, last_valid_band_idx[b], + // idx, b, &w, &id0, &id1 ); ivas_spar_get_plc_interp_weights_fx(valid_band_idx, last_valid_band_idx[b], idx, b, &w_fx, &id0, &id1); for ( j = 0; j < IVAS_SPAR_MAX_CH - 1; j++ ) { - pBand_coeffs[b].pred_re[j] = ( 1 - w ) * pBand_coeffs[id0].pred_re[j] + w * pBand_coeffs[id1].pred_re[j]; + //pBand_coeffs[b].pred_re[j] = ( 1 - w ) * pBand_coeffs[id0].pred_re[j] + w * pBand_coeffs[id1].pred_re[j]; pBand_coeffs[b].pred_re_fx[j] = L_add(Mpy_32_16_1(pBand_coeffs[id0].pred_re_fx[j], sub(MAX_WORD16, w_fx)), Mpy_32_16_1(pBand_coeffs[id1].pred_re_fx[j],w_fx)); } @@ -3184,14 +3945,14 @@ static void ivas_spar_md_fill_invalid_bandcoeffs( { for ( k = 0; k < IVAS_SPAR_MAX_DMX_CHS - 1; k++ ) { - pBand_coeffs[b].C_re[j][k] = ( 1 - w ) * pBand_coeffs[id0].C_re[j][k] + w * pBand_coeffs[id1].C_re[j][k]; + // pBand_coeffs[b].C_re[j][k] = ( 1 - w ) * pBand_coeffs[id0].C_re[j][k] + w * pBand_coeffs[id1].C_re[j][k]; pBand_coeffs[b].C_re_fx[j][k] = L_add(Mpy_32_16_1(pBand_coeffs[id0].C_re_fx[j][k], sub(MAX_WORD16, w_fx)), Mpy_32_16_1(pBand_coeffs[id1].C_re_fx[j][k],w_fx)); } } for ( j = 0; j < IVAS_SPAR_MAX_CH - 1; j++ ) { - pBand_coeffs[b].P_re[j] = ( 1 - w ) * pBand_coeffs[id0].P_re[j] + w * pBand_coeffs[id1].P_re[j]; + //pBand_coeffs[b].P_re[j] = ( 1 - w ) * pBand_coeffs[id0].P_re[j] + w * pBand_coeffs[id1].P_re[j]; pBand_coeffs[b].P_re_fx[j] = L_add(Mpy_32_16_1(pBand_coeffs[id0].P_re_fx[j], sub(MAX_WORD16, w_fx)), Mpy_32_16_1(pBand_coeffs[id1].P_re_fx[j], w_fx)); } } @@ -3201,7 +3962,7 @@ static void ivas_spar_md_fill_invalid_bandcoeffs( { for ( j = 0; j < IVAS_SPAR_MAX_CH - 1; j++ ) { - pBand_coeffs[b].pred_re[j] = pBand_coeffs_prev[b].pred_re[j]; + //pBand_coeffs[b].pred_re[j] = pBand_coeffs_prev[b].pred_re[j]; pBand_coeffs[b].pred_re_fx[j] = pBand_coeffs_prev[b].pred_re_fx[j]; } @@ -3209,14 +3970,14 @@ static void ivas_spar_md_fill_invalid_bandcoeffs( { for ( k = 0; k < IVAS_SPAR_MAX_DMX_CHS - 1; k++ ) { - pBand_coeffs[b].C_re[j][k] = pBand_coeffs_prev[b].C_re[j][k]; + //pBand_coeffs[b].C_re[j][k] = pBand_coeffs_prev[b].C_re[j][k]; pBand_coeffs[b].C_re_fx[j][k] = pBand_coeffs_prev[b].C_re_fx[j][k]; } } for ( j = 0; j < IVAS_SPAR_MAX_CH - 1; j++ ) { - pBand_coeffs[b].P_re[j] = pBand_coeffs_prev[b].P_re[j]; + //pBand_coeffs[b].P_re[j] = pBand_coeffs_prev[b].P_re[j]; pBand_coeffs[b].P_re_fx[j] = pBand_coeffs_prev[b].P_re_fx[j]; } } @@ -3305,7 +4066,7 @@ static void ivas_spar_dec_compute_ramp_down_post_matrix_fx( return; } -#endif // IVAS_FLOAT_FIXED +#else static void ivas_spar_dec_compute_ramp_down_post_matrix( ivas_spar_md_dec_state_t *hMdDec, @@ -3368,6 +4129,8 @@ static void ivas_spar_dec_compute_ramp_down_post_matrix( return; } +#endif // IVAS_FLOAT_FIXED + /*-----------------------------------------------------------------------------------------* @@ -3409,7 +4172,9 @@ static void ivas_spar_unquant_dtx_indicies( idx = pSpar_md->band_coeffs_idx[b].pred_index_re[i]; ivas_deindex_real_index_fx(&idx, q_lvl, pr_min_max_fx[0], pr_min_max_fx[1], &val_fx, 1); pSpar_md->band_coeffs[b].pred_re_fx[i] = val_fx; +#if 0 //ndef IVAS_FLOAT_FIXED_TO_BE_REMOVED pSpar_md->band_coeffs[b].pred_re[i] = (float)val_fx / (1 << 22); +#endif } for ( i = 0; i < FOA_CHANNELS - ndm_per_band[bw * b]; i++ ) @@ -3423,7 +4188,9 @@ static void ivas_spar_unquant_dtx_indicies( idx = pSpar_md->band_coeffs_idx[b].decd_index_re[i]; ivas_deindex_real_index_fx(&idx, q_lvl, dtx_pd_real_min_max_fx[0], dtx_pd_real_min_max_fx[1], &val_fx, 1); pSpar_md->band_coeffs[b].P_re_fx[i] = val_fx; +#if 0 //ndef IVAS_FLOAT_FIXED_TO_BE_REMOVED pSpar_md->band_coeffs[b].P_re[i] = (float)val_fx / (1 << 22); +#endif } } @@ -3667,6 +4434,7 @@ static void ivas_parse_parameter_bitstream_dtx( * Deindex real index *-----------------------------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED static ivas_error ivas_deindex_real_index( const int16_t *index, const int16_t q_levels, @@ -3701,6 +4469,7 @@ static ivas_error ivas_deindex_real_index( return IVAS_ERR_OK; } +#else static ivas_error ivas_deindex_real_index_fx( const int16_t *index, @@ -3736,14 +4505,16 @@ static ivas_error ivas_deindex_real_index_fx( return IVAS_ERR_OK; } +#endif +#ifndef IVAS_FLOAT_FIXED /*-----------------------------------------------------------------------------------------* * Function ivas_spar_to_dirac() * * *-----------------------------------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED + void ivas_spar_to_dirac( Decoder_Struct *st_ivas, ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ @@ -3757,26 +4528,18 @@ void ivas_spar_to_dirac( int16_t block, b; int16_t *band_grouping; float diffuseness[IVAS_MAX_NUM_BANDS]; - Word32 diffuseness_fx[IVAS_MAX_NUM_BANDS]; int16_t sba_order_internal; float azi_dirac[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES]; - Word32 azi_dirac_fx[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES]; float ele_dirac[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES]; - Word32 ele_dirac_fx[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES]; int16_t azi[IVAS_MAX_NUM_BANDS]; int16_t ele[IVAS_MAX_NUM_BANDS]; float dvx[IVAS_MAX_NUM_BANDS], dvy[IVAS_MAX_NUM_BANDS], dvz[IVAS_MAX_NUM_BANDS]; - Word32 dvx_fx[IVAS_MAX_NUM_BANDS], dvy_fx[IVAS_MAX_NUM_BANDS], dvz_fx[IVAS_MAX_NUM_BANDS]; float radius; - Word32 radius_fx; float en_ratio, res_pow; - Word32 en_ratio_fx, res_pow_fx; - Word32 res_pow_q; int16_t num_slots_in_subfr; int16_t tmp_write_idx_param_band; int16_t tmp_write_idx_band; float pred_re_20ms[IVAS_MAX_NUM_BANDS][IVAS_SPAR_MAX_CH - 1]; - Word32 pred_re_20ms_fx[IVAS_MAX_NUM_BANDS][IVAS_SPAR_MAX_CH - 1]; int16_t pred_idx; int16_t *dirac_to_spar_md_bands; int16_t enc_param_start_band; @@ -3805,204 +4568,70 @@ void ivas_spar_to_dirac( for ( band = start_band; band < end_band; band++ ) { float PR[3], Pd[3], dvnorm, g_pred; - Word32 PR_fx[3], Pd_fx[3], dvnorm_fx, g_pred_fx; - Word16 q_g_pred; - Word16 q_dvnorm; + PR[0] = hMdDec->spar_md.band_coeffs[band].pred_re[2]; - PR_fx[0] = hMdDec->spar_md.band_coeffs[band].pred_re_fx[2]; PR[1] = hMdDec->spar_md.band_coeffs[band].pred_re[0]; - PR_fx[1] = hMdDec->spar_md.band_coeffs[band].pred_re_fx[0]; PR[2] = hMdDec->spar_md.band_coeffs[band].pred_re[1]; - PR_fx[2] = hMdDec->spar_md.band_coeffs[band].pred_re_fx[1]; g_pred = PR[0] * PR[0] + PR[1] * PR[1] + PR[2] * PR[2]; - g_pred_fx = Mpy_32_32(PR_fx[0], PR_fx[0]) + Mpy_32_32(PR_fx[1], PR_fx[1]) + Mpy_32_32(PR_fx[2], PR_fx[2]); - q_g_pred = 22 + 22 - 31; - q_g_pred = 31 - q_g_pred; - q_dvnorm = q_g_pred; if ( g_pred <= EPSILON ) { dvx[band] = 1.0f; dvy[band] = 0.0f; dvz[band] = 0.0f; - - azi[band] = 0; - ele[band] = 0; - q_g_pred = 0; - q_dvnorm = 0; } else { g_pred = sqrtf( g_pred ); dvnorm = 1.0f / g_pred; - dvnorm_fx = ISqrt32(g_pred_fx, &q_dvnorm); - g_pred_fx = Sqrt32(g_pred_fx, &q_g_pred); - if (q_g_pred < 0) - { - g_pred_fx = L_shr(g_pred_fx, (-1 * q_g_pred)); - q_g_pred = 0; - } - dvx[band] = PR[0] * dvnorm; dvy[band] = PR[1] * dvnorm; dvz[band] = PR[2] * dvnorm; - - dvx_fx[band] = Mpy_32_32(PR_fx[0], dvnorm_fx); - dvy_fx[band] = Mpy_32_32(PR_fx[1], dvnorm_fx); - dvz_fx[band] = Mpy_32_32(PR_fx[2], dvnorm_fx); - Word16 q_1 = (22) + (31 - q_dvnorm) - 31; - - Word32 temp = Mpy_32_32(dvx_fx[band], dvx_fx[band]) + Mpy_32_32(dvy_fx[band], dvy_fx[band] ); - Word16 q2 = q_1 + q_1 - 31; - Word16 q_temp = 31 - q2; - radius_fx = Sqrt32(temp, &q_temp); - radius = sqrtf(dvx[band] * dvx[band] + dvy[band] * dvy[band]); - - - Word16 check_azi_fx = BASOP_util_atan2(dvy_fx[band], dvx_fx[band],0); - Word32 check_azi_fx_32 = L_shl(check_azi_fx,16); - Word16 check_azi_fx_res; - if (check_azi_fx_32 < 0) - { - check_azi_fx_res = negate(divide3232(L_negate(check_azi_fx_32), 1686629760)); - } - else - { - check_azi_fx_res = divide3232(check_azi_fx_32, 1686629760); } - Word32 azi_intermediate = Mpy_32_16_1(DEGREE_180_Q_22, check_azi_fx_res); - azi_intermediate = azi_intermediate + ONE_IN_Q21; - //Word16 azi_res = L_shr_r(azi_intermediate, 22); - Word16 azi_res = extract_l(azi_intermediate / (1 << 22)); - - Word16 check_ele_fx = BASOP_util_atan2(dvz_fx[band], radius_fx, (9+ q_dvnorm)-q_temp); - Word32 check_ele_fx_32 = L_shl(check_ele_fx, 16); - Word16 check_ele_fx_res; - if (check_azi_fx_32 < 0) - { - check_ele_fx_res = negate(divide3232(L_negate(check_ele_fx_32), 1686629760)); - } - else - { - check_ele_fx_res = divide3232(check_ele_fx_32, 1686629760); - } - Word32 ele_intermediate = Mpy_32_16_1(DEGREE_180_Q_22, check_ele_fx_res); - ele_intermediate = ele_intermediate + ONE_IN_Q21; - //Word16 ele_res = L_shr_r(ele_intermediate, 22); - Word16 ele_res = extract_l(ele_intermediate/(1<<22)); - + radius = sqrtf( dvx[band] * dvx[band] + dvy[band] * dvy[band] ); azi[band] = (int16_t)(max(-180.0f, min(180.0f, atan2f(dvy[band], dvx[band]) / EVS_PI * 180.0f)) + 0.5f); - azi[band] = max(-180, min(180, azi_res)); ele[band] = (int16_t)(max(-90.0f, min(180.0f, atan2f(dvz[band], radius) / EVS_PI * 180.0f)) + 0.5f); - ele[band] = max(-90, min(180, ele_res)); - } - Word16 en_ratio_q = 0; if ( st_ivas->nchan_transport == 1 ) { float w_en_norm, f_scale; - Word32 w_en_norm_fx, f_scale_fx; - Word16 q_w_en_norm_fx; if ( active_w ) { if ( dtx_vad == 0 ) { f_scale = IVAS_ACTIVEW_DM_F_SCALE_DTX; - f_scale_fx = IVAS_ACTIVEW_DM_F_SCALE_DTX_FX; } else { f_scale = ( active_w_vlbr ) ? IVAS_ACTIVEW_DM_F_SCALE_VLBR : IVAS_ACTIVEW_DM_F_SCALE; - f_scale_fx = ( active_w_vlbr ) ? IVAS_ACTIVEW_DM_F_SCALE_VLBR_FX : IVAS_ACTIVEW_DM_F_SCALE_FX; } } else { f_scale = 0.0f; - f_scale_fx = 0; } w_en_norm = ( 1.0f - ( f_scale * g_pred * g_pred ) ); - Word32 temp_result = Mpy_32_32(Mpy_32_32(f_scale_fx, g_pred_fx), g_pred_fx); - temp_result = L_sub(L_shr(ONE_IN_Q31, q_g_pred), temp_result); w_en_norm *= w_en_norm; - w_en_norm_fx = Mpy_32_32(temp_result, temp_result); - q_w_en_norm_fx = q_g_pred + q_g_pred; + Pd[0] = hMdDec->spar_md.band_coeffs[band].P_re[1]; Pd[1] = hMdDec->spar_md.band_coeffs[band].P_re[0]; Pd[2] = hMdDec->spar_md.band_coeffs[band].P_re[2]; - Pd_fx[0] = hMdDec->spar_md.band_coeffs[band].P_re_fx[1]; - Pd_fx[1] = hMdDec->spar_md.band_coeffs[band].P_re_fx[0]; - Pd_fx[2] = hMdDec->spar_md.band_coeffs[band].P_re_fx[2]; en_ratio = PR[0] * PR[0] + PR[1] * PR[1] + PR[2] * PR[2]; - en_ratio_fx = Mpy_32_32(PR_fx[0], PR_fx[0]) + Mpy_32_32(PR_fx[1], PR_fx[1]) + Mpy_32_32(PR_fx[2], PR_fx[2]); //22+22-31 = 13 - Word32 Pd_temp_res = Mpy_32_32(Pd_fx[0], Pd_fx[0]) + Mpy_32_32(Pd_fx[1], Pd_fx[1]) + Mpy_32_32(Pd_fx[2], Pd_fx[2]);//q = 22+22-31 = 13 res_pow = w_en_norm + en_ratio + ( Pd[0] * Pd[0] + Pd[1] * Pd[1] + Pd[2] * Pd[2] ); - res_pow_fx = L_shr(w_en_norm_fx, (31- q_w_en_norm_fx)-13) + en_ratio_fx + Pd_temp_res; - res_pow_q = 13; - res_pow_fx = L_shr(res_pow_fx, 1); res_pow *= 0.5f; hMdDec->spar_md.en_ratio_slow[band] = 0.75f * hMdDec->spar_md.en_ratio_slow[band] + 0.25f * en_ratio; - hMdDec->spar_md.en_ratio_slow_fx[band] = Mpy_32_32(1610612736, hMdDec->spar_md.en_ratio_slow_fx[band]) + Mpy_32_32(536870912, en_ratio_fx); hMdDec->spar_md.ref_pow_slow[band] = 0.75f * hMdDec->spar_md.ref_pow_slow[band] + 0.25f * res_pow; - hMdDec->spar_md.ref_pow_slow_fx[band] = Mpy_32_32(1610612736, hMdDec->spar_md.ref_pow_slow_fx[band]) + Mpy_32_32(536870912, res_pow_fx); en_ratio = sqrtf( hMdDec->spar_md.en_ratio_slow[band] ) / ( hMdDec->spar_md.ref_pow_slow[band] + EPSILON ); - en_ratio_q = 31 - 13; - en_ratio_fx = Sqrt32(hMdDec->spar_md.en_ratio_slow_fx[band], &en_ratio_q); - if (en_ratio_q < 0) - { - en_ratio_fx = L_shr(en_ratio_fx, -1 * (en_ratio_q)); - en_ratio_q = 0; - } - Word32 en_ratio_fx_scaled = L_shr(en_ratio_fx, (31 - en_ratio_q - 13)); - if (en_ratio_fx_scaled > hMdDec->spar_md.ref_pow_slow_fx[band]) - { - diffuseness_fx[band] = 0; - } - else if(en_ratio_fx_scaled == 0) - { - diffuseness_fx[band] = ONE_IN_Q30; - } - else if (en_ratio_fx_scaled == hMdDec->spar_md.ref_pow_slow_fx[band]) - { - diffuseness_fx[band] = ONE_IN_Q30; - } - else - { - en_ratio_fx = divide3232(en_ratio_fx_scaled, (hMdDec->spar_md.ref_pow_slow_fx[band] + EPSILON_FX)); - en_ratio_fx = L_shl(en_ratio_fx, 15); - diffuseness_fx[band] = ONE_IN_Q30 - en_ratio_fx; - } - } else { en_ratio = PR[0] * PR[0] + PR[1] * PR[1] + PR[2] * PR[2]; - en_ratio_fx = Mpy_32_32(PR_fx[0] , PR_fx[0]) + Mpy_32_32(PR_fx[1] , PR_fx[1])+ Mpy_32_32(PR_fx[2] , PR_fx[2]); hMdDec->spar_md.en_ratio_slow[band] = 0.75f * hMdDec->spar_md.en_ratio_slow[band] + 0.25f * en_ratio; - hMdDec->spar_md.en_ratio_slow_fx[band] = Mpy_32_32(1610612736, hMdDec->spar_md.en_ratio_slow_fx[band]) + Mpy_32_32(536870912, en_ratio_fx); en_ratio = sqrtf( hMdDec->spar_md.en_ratio_slow[band] ); - en_ratio_q = 31 - 13; - en_ratio_fx = Sqrt32( hMdDec->spar_md.en_ratio_slow_fx[band], &en_ratio_q); - if (en_ratio_q < 0) - { - en_ratio_fx = L_shr(en_ratio_fx, -1 * (en_ratio_q)); - en_ratio_q = 0; - } - Word32 en_ratio_fx_scaled = L_shr(en_ratio_fx, 1); - if (en_ratio_fx_scaled > ONE_IN_Q30) - { - diffuseness_fx[band] = 0; - } - else - { - diffuseness_fx[band] = ONE_IN_Q30 - en_ratio_fx_scaled; - } - } diffuseness[band] = 1.0f - en_ratio; /*compute diffuseness*/ diffuseness[band] = ( ( diffuseness[band] < 1.0f ) ? ( ( diffuseness[band] < 0.0f ) ? 0.f : diffuseness[band] ) : 1.0f ); - diffuseness[band] = (float)diffuseness_fx[band] / (1 << 30); } for ( band = start_band; band < end_band; band++ ) @@ -4011,13 +4640,7 @@ void ivas_spar_to_dirac( tmp_write_idx_param_band = hDirAC->spar_to_dirac_write_idx; en_ratio = 1.0f - diffuseness[band]; - en_ratio_fx = ONE_IN_Q30 - diffuseness_fx[band]; - en_ratio = (float)en_ratio_fx / (1 << 30); - //cam delete the below function call masa_sq( 1.0f - en_ratio, diffuseness_thresholds, DIRAC_DIFFUSE_LEVELS ); -#ifdef IVAS_FLOAT_FIXED - masa_sq_fx(ONE_IN_Q30 - en_ratio_fx, diffuseness_thresholds_fx, DIRAC_DIFFUSE_LEVELS ); -#endif qmf_band_start = band_grouping[band]; qmf_band_end = band_grouping[band + 1]; @@ -4035,9 +4658,6 @@ void ivas_spar_to_dirac( ele_dith = ele[band]; hSpatParamRendCom->energy_ratio1[block][b] = en_ratio; -#ifdef IVAS_FLOAT_FIXED - hSpatParamRendCom->energy_ratio1_fx[block][b] = en_ratio_fx; -#endif tmp_write_idx_band = tmp_write_idx_param_band; if ( hDirAC->hConfig->dec_param_estim == FALSE ) @@ -4045,9 +4665,6 @@ void ivas_spar_to_dirac( hSpatParamRendCom->elevation[tmp_write_idx_band][b] = ele_dith; hSpatParamRendCom->azimuth[tmp_write_idx_band][b] = azi_dith; hSpatParamRendCom->diffuseness_vector[tmp_write_idx_band][b] = diffuseness[band]; -#ifdef IVAS_FLOAT_FIXED - hSpatParamRendCom->diffuseness_vector_fx[tmp_write_idx_band][b] = diffuseness_fx[band]; -#endif } else { @@ -4056,9 +4673,6 @@ void ivas_spar_to_dirac( hSpatParamRendCom->elevation[tmp_write_idx_band][b] = ele_dith; hSpatParamRendCom->azimuth[tmp_write_idx_band][b] = azi_dith; hSpatParamRendCom->diffuseness_vector[tmp_write_idx_band][b] = diffuseness[band]; -#ifdef IVAS_FLOAT_FIXED - hSpatParamRendCom->diffuseness_vector_fx[tmp_write_idx_band][b] = diffuseness_fx[band]; -#endif tmp_write_idx_band = ( tmp_write_idx_band + 1 ) % hSpatParamRendCom->dirac_md_buffer_length; } } @@ -4103,26 +4717,15 @@ void ivas_spar_to_dirac( } azi_dirac[band][block] = st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].azimuth[block]; ele_dirac[band][block] = st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].elevation[block]; -#ifdef IVAS_FLOAT_FIXED - azi_dirac_fx[band][block] = st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].azimuth_fx[block]; - ele_dirac_fx[band][block] = st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].elevation_fx[block]; -#endif } diffuseness[band] = 1.0f - st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].energy_ratio[0]; -#ifdef IVAS_FLOAT_FIXED - diffuseness_fx[band] = ONE_IN_Q30 - st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].energy_ratio_fx[0]; -#endif } /* DirAC MD averaged over 4 subframes and converted to SPAR format similar to encoder processing */ if ( hMdDec->spar_md_cfg.nchan_transport > 1 ) { -#ifdef IVAS_FLOAT_FIXED - ivas_get_spar_md_from_dirac_fx( azi_dirac, ele_dirac, diffuseness, 1, NULL, &hMdDec->spar_md, &hMdDec->spar_md_cfg, end_band, num_bands_out, ( hMdDec->spar_hoa_md_flag ) ? 1 : sba_order_internal, dtx_vad, NULL, st_ivas->hQMetaData->useLowerRes, active_w_vlbr, dyn_active_w_flag ); -#else ivas_get_spar_md_from_dirac( azi_dirac, ele_dirac, diffuseness, 1, NULL, &hMdDec->spar_md, &hMdDec->spar_md_cfg, end_band, num_bands_out, ( hMdDec->spar_hoa_md_flag ) ? 1 : sba_order_internal, dtx_vad, NULL, st_ivas->hQMetaData->useLowerRes, active_w_vlbr, dyn_active_w_flag ); -#endif /* temporarily copy frame-wise prediction coefficients in DirAC bands*/ for ( pred_idx = 0; pred_idx < FOA_CHANNELS - 1; pred_idx++ ) @@ -4130,18 +4733,14 @@ void ivas_spar_to_dirac( for ( band = SPAR_DIRAC_SPLIT_START_BAND; band < IVAS_MAX_NUM_BANDS; band++ ) { pred_re_20ms[band][pred_idx] = hMdDec->spar_md.band_coeffs[band].pred_re[pred_idx]; - pred_re_20ms_fx[band][pred_idx] = hMdDec->spar_md.band_coeffs[band].pred_re_fx[pred_idx]; } } } int16_t num_md_sub_frames; num_md_sub_frames = ivas_get_spar_dec_md_num_subframes( sba_order_internal, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->last_active_ivas_total_brate ); -#ifdef IVAS_FLOAT_FIXED - ivas_get_spar_md_from_dirac_fx( azi_dirac, ele_dirac, diffuseness, num_md_sub_frames, NULL, &hMdDec->spar_md, &hMdDec->spar_md_cfg, end_band, num_bands_out / bw, ( hMdDec->spar_hoa_md_flag ) ? 1 : sba_order_internal, dtx_vad, NULL, st_ivas->hQMetaData->useLowerRes, active_w_vlbr, dyn_active_w_flag ); -#else ivas_get_spar_md_from_dirac( azi_dirac, ele_dirac, diffuseness, num_md_sub_frames, NULL, &hMdDec->spar_md, &hMdDec->spar_md_cfg, end_band, num_bands_out / bw, ( hMdDec->spar_hoa_md_flag ) ? 1 : sba_order_internal, dtx_vad, NULL, st_ivas->hQMetaData->useLowerRes, active_w_vlbr, dyn_active_w_flag ); -#endif + if ( st_ivas->hQMetaData->useLowerRes && dtx_vad ) { for ( band = SPAR_DIRAC_SPLIT_START_BAND; band < IVAS_MAX_NUM_BANDS; band++ ) @@ -4151,12 +4750,10 @@ void ivas_spar_to_dirac( for ( i = 0; i < FOA_CHANNELS - 1; i++ ) /* pred coefficient index (index 0, 1, 2 predicts Y, Z, X respectively) */ { hMdDec->spar_md.band_coeffs[band + block * IVAS_MAX_NUM_BANDS].pred_re[i] = hMdDec->spar_md.band_coeffs[band].pred_re[i]; - hMdDec->spar_md.band_coeffs[band + block * IVAS_MAX_NUM_BANDS].pred_re_fx[i] = hMdDec->spar_md.band_coeffs[band].pred_re_fx[i]; } for ( i = 0; i < FOA_CHANNELS - 1; i++ ) /* pred coefficient index (index 0, 1, 2 predicts Y, Z, X respectively) */ { hMdDec->spar_md.band_coeffs[band + block * IVAS_MAX_NUM_BANDS].P_re[i] = hMdDec->spar_md.band_coeffs[band].P_re[i]; - hMdDec->spar_md.band_coeffs[band + block * IVAS_MAX_NUM_BANDS].P_re_fx[i] = hMdDec->spar_md.band_coeffs[band].P_re_fx[i]; } } } @@ -4173,7 +4770,6 @@ void ivas_spar_to_dirac( { /* use 20ms coefficients only for residual channels */ hMdDec->spar_md.band_coeffs[band + block * IVAS_MAX_NUM_BANDS].pred_re[pred_idx] = pred_re_20ms[band][pred_idx]; - hMdDec->spar_md.band_coeffs[band + block * IVAS_MAX_NUM_BANDS].pred_re_fx[pred_idx] = pred_re_20ms_fx[band][pred_idx]; } } } @@ -4188,7 +4784,7 @@ void ivas_spar_to_dirac( } #else -void ivas_spar_to_dirac( +void ivas_spar_to_dirac_fx( Decoder_Struct *st_ivas, ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ const int16_t dtx_vad, /* i : DTX frame flag */ @@ -4200,19 +4796,28 @@ void ivas_spar_to_dirac( int16_t start_band, end_band, band, qmf_band_start, qmf_band_end; int16_t block, b; int16_t *band_grouping; - float diffuseness[IVAS_MAX_NUM_BANDS]; + //float diffuseness[IVAS_MAX_NUM_BANDS]; + Word32 diffuseness_fx[IVAS_MAX_NUM_BANDS]; int16_t sba_order_internal; - float azi_dirac[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES]; - float ele_dirac[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES]; + //float azi_dirac[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES]; + Word32 azi_dirac_fx[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES]; + //float ele_dirac[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES]; + Word32 ele_dirac_fx[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES]; int16_t azi[IVAS_MAX_NUM_BANDS]; int16_t ele[IVAS_MAX_NUM_BANDS]; - float dvx[IVAS_MAX_NUM_BANDS], dvy[IVAS_MAX_NUM_BANDS], dvz[IVAS_MAX_NUM_BANDS]; - float radius; - float en_ratio, res_pow; + //float dvx[IVAS_MAX_NUM_BANDS], dvy[IVAS_MAX_NUM_BANDS], dvz[IVAS_MAX_NUM_BANDS]; + Word32 dvx_q, dvy_q, dvz_q; + Word32 dvx_fx[IVAS_MAX_NUM_BANDS], dvy_fx[IVAS_MAX_NUM_BANDS], dvz_fx[IVAS_MAX_NUM_BANDS]; + //float radius; + Word32 radius_fx,radius_q; + //float en_ratio, res_pow; + Word32 en_ratio_fx, res_pow_fx; + Word32 en_ratio_q, res_pow_q; int16_t num_slots_in_subfr; int16_t tmp_write_idx_param_band; int16_t tmp_write_idx_band; - float pred_re_20ms[IVAS_MAX_NUM_BANDS][IVAS_SPAR_MAX_CH - 1]; + //float pred_re_20ms[IVAS_MAX_NUM_BANDS][IVAS_SPAR_MAX_CH - 1]; + Word32 pred_re_20ms_fx[IVAS_MAX_NUM_BANDS][IVAS_SPAR_MAX_CH - 1]; int16_t pred_idx; int16_t *dirac_to_spar_md_bands; int16_t enc_param_start_band; @@ -4240,71 +4845,207 @@ void ivas_spar_to_dirac( for (band = start_band; band < end_band; band++) { - float PR[3], Pd[3], dvnorm, g_pred; - - PR[0] = hMdDec->spar_md.band_coeffs[band].pred_re[2]; - PR[1] = hMdDec->spar_md.band_coeffs[band].pred_re[0]; - PR[2] = hMdDec->spar_md.band_coeffs[band].pred_re[1]; - g_pred = PR[0] * PR[0] + PR[1] * PR[1] + PR[2] * PR[2]; - if (g_pred <= EPSILON) - { - dvx[band] = 1.0f; - dvy[band] = 0.0f; - dvz[band] = 0.0f; + //float PR[3], Pd[3], dvnorm, g_pred; + Word32 PR_fx[3], Pd_fx[3], dvnorm_fx, g_pred_fx; + Word16 q_g_pred; + Word16 q_dvnorm; + //PR[0] = hMdDec->spar_md.band_coeffs[band].pred_re[2]; + PR_fx[0] = hMdDec->spar_md.band_coeffs[band].pred_re_fx[2]; + //PR[1] = hMdDec->spar_md.band_coeffs[band].pred_re[0]; + PR_fx[1] = hMdDec->spar_md.band_coeffs[band].pred_re_fx[0]; + //PR[2] = hMdDec->spar_md.band_coeffs[band].pred_re[1]; + PR_fx[2] = hMdDec->spar_md.band_coeffs[band].pred_re_fx[1]; + //g_pred = PR[0] * PR[0] + PR[1] * PR[1] + PR[2] * PR[2]; + g_pred_fx = Mpy_32_32(PR_fx[0], PR_fx[0]) + Mpy_32_32(PR_fx[1], PR_fx[1]) + Mpy_32_32(PR_fx[2], PR_fx[2]); + q_g_pred = Q22 + Q22 - Q31; + q_dvnorm = Q31 - q_g_pred; + q_g_pred = q_dvnorm; + IF ( LE_32 (g_pred_fx, EPSILON_FIX ) ) + { + dvx_fx[band] = ONE_IN_Q22; + dvy_fx[band] = 0; + dvz_fx[band] = 0; + + azi[band] = 0; + ele[band] = 0; + q_g_pred = Q22; + q_dvnorm = Q22; } else { - g_pred = sqrtf(g_pred); - dvnorm = 1.0f / g_pred; - dvx[band] = PR[0] * dvnorm; + //g_pred = Sqrt32( g_pred, ); + //dvnorm = 1.0f / g_pred; + dvnorm_fx = ISqrt32(g_pred_fx, &q_dvnorm); + g_pred_fx = Sqrt32(g_pred_fx, &q_g_pred); + if (q_g_pred < 0) + { + g_pred_fx = L_shr(g_pred_fx, (-1 * q_g_pred)); + q_g_pred = 0; + } + + /*dvx[band] = PR[0] * dvnorm; dvy[band] = PR[1] * dvnorm; - dvz[band] = PR[2] * dvnorm; + dvz[band] = PR[2] * dvnorm;*/ + + dvx_fx[band] = Mpy_32_32(PR_fx[0], dvnorm_fx); + dvy_fx[band] = Mpy_32_32(PR_fx[1], dvnorm_fx); + dvz_fx[band] = Mpy_32_32(PR_fx[2], dvnorm_fx); + Word16 q_1 = (22) + (31 - q_dvnorm) - 31; + + Word32 temp = Mpy_32_32(dvx_fx[band], dvx_fx[band]) + Mpy_32_32(dvy_fx[band], dvy_fx[band] ); + Word16 q2 = q_1 + q_1 - 31; + Word16 q_temp = 31 - q2; + radius_fx = Sqrt32(temp, &q_temp); + //radius = sqrtf(dvx[band] * dvx[band] + dvy[band] * dvy[band]); + + + //float check_qzi = atan2f(dvy[band], dvx[band]); + Word16 check_azi_fx = BASOP_util_atan2(dvy_fx[band], dvx_fx[band],0); + Word32 check_azi_fx_32 = L_shl(check_azi_fx,16); + Word16 check_azi_fx_res; + IF (LT_32(check_azi_fx_32 ,0)) + { + check_azi_fx_res = negate(divide3232(L_negate(check_azi_fx_32), 1686629760)); + } + ELSE + { + check_azi_fx_res = divide3232(check_azi_fx_32, 1686629760); } - - radius = sqrtf(dvx[band] * dvx[band] + dvy[band] * dvy[band]); - azi[band] = (int16_t)(max(-180.0f, min(180.0f, atan2f(dvy[band], dvx[band]) / EVS_PI * 180.0f)) + 0.5f); - ele[band] = (int16_t)(max(-90.0f, min(180.0f, atan2f(dvz[band], radius) / EVS_PI * 180.0f)) + 0.5f); - + Word32 azi_intermediate = Mpy_32_16_1(DEGREE_180_Q_22, check_azi_fx_res); + azi_intermediate = azi_intermediate + ONE_IN_Q21; + //Word16 azi_res = L_shr_r(azi_intermediate, 22); + Word16 azi_res = extract_l(azi_intermediate / (1 << 22)); + + Word16 check_ele_fx = BASOP_util_atan2(dvz_fx[band], radius_fx, (9+ q_dvnorm)-q_temp); + Word32 check_ele_fx_32 = L_shl(check_ele_fx, 16); + Word16 check_ele_fx_res; + IF (LT_32(check_azi_fx_32 ,0)) + { + check_ele_fx_res = negate(divide3232(L_negate(check_ele_fx_32), 1686629760)); + } + else + { + check_ele_fx_res = divide3232(check_ele_fx_32, 1686629760); + } + Word32 ele_intermediate = Mpy_32_16_1(DEGREE_180_Q_22, check_ele_fx_res); + ele_intermediate = ele_intermediate + ONE_IN_Q21; + //Word16 ele_res = L_shr_r(ele_intermediate, 22); + Word16 ele_res = extract_l(ele_intermediate/(1<<22)); + + + + //azi[band] = (int16_t)(max(-180.0f, min(180.0f, atan2f(dvy[band], dvx[band]) / EVS_PI * 180.0f)) + 0.5f); + azi[band] = max(-180, min(180, azi_res)); + //ele[band] = (int16_t)(max(-90.0f, min(180.0f, atan2f(dvz[band], radius) / EVS_PI * 180.0f)) + 0.5f); + ele[band] = max(-90, min(180, ele_res)); + } + + Word16 en_ratio_q = 0; if (st_ivas->nchan_transport == 1) { - float w_en_norm, f_scale; + //float w_en_norm, f_scale; + Word32 w_en_norm_fx, f_scale_fx; + Word16 q_w_en_norm_fx; if (active_w) { if (dtx_vad == 0) { - f_scale = IVAS_ACTIVEW_DM_F_SCALE_DTX; + //f_scale = IVAS_ACTIVEW_DM_F_SCALE_DTX; + f_scale_fx = IVAS_ACTIVEW_DM_F_SCALE_DTX_FX; } else { - f_scale = (active_w_vlbr) ? IVAS_ACTIVEW_DM_F_SCALE_VLBR : IVAS_ACTIVEW_DM_F_SCALE; + //f_scale = ( active_w_vlbr ) ? IVAS_ACTIVEW_DM_F_SCALE_VLBR : IVAS_ACTIVEW_DM_F_SCALE; + f_scale_fx = ( active_w_vlbr ) ? IVAS_ACTIVEW_DM_F_SCALE_VLBR_FX : IVAS_ACTIVEW_DM_F_SCALE_FX; } } else { - f_scale = 0.0f; - } + //f_scale = 0.0f; + f_scale_fx = 0; + } + + //w_en_norm = ( 1.0f - ( f_scale * g_pred * g_pred ) ); + Word32 temp_result = Mpy_32_32(Mpy_32_32(f_scale_fx, g_pred_fx), g_pred_fx); + temp_result = L_sub(L_shr(ONE_IN_Q31, q_g_pred), temp_result); + //w_en_norm *= w_en_norm; + w_en_norm_fx = Mpy_32_32(temp_result, temp_result); + q_w_en_norm_fx = q_g_pred + q_g_pred; + //Pd[0] = hMdDec->spar_md.band_coeffs[band].P_re[1]; + //Pd[1] = hMdDec->spar_md.band_coeffs[band].P_re[0]; + //Pd[2] = hMdDec->spar_md.band_coeffs[band].P_re[2]; + Pd_fx[0] = hMdDec->spar_md.band_coeffs[band].P_re_fx[1]; + Pd_fx[1] = hMdDec->spar_md.band_coeffs[band].P_re_fx[0]; + Pd_fx[2] = hMdDec->spar_md.band_coeffs[band].P_re_fx[2]; + //en_ratio = PR[0] * PR[0] + PR[1] * PR[1] + PR[2] * PR[2]; + en_ratio_fx = Mpy_32_32(PR_fx[0], PR_fx[0]) + Mpy_32_32(PR_fx[1], PR_fx[1]) + Mpy_32_32(PR_fx[2], PR_fx[2]); //22+22-31 = 13 + Word32 Pd_temp_res = Mpy_32_32(Pd_fx[0], Pd_fx[0]) + Mpy_32_32(Pd_fx[1], Pd_fx[1]) + Mpy_32_32(Pd_fx[2], Pd_fx[2]);//q = 22+22-31 = 13 + //res_pow = w_en_norm + en_ratio + ( Pd[0] * Pd[0] + Pd[1] * Pd[1] + Pd[2] * Pd[2] ); + res_pow_fx = L_shr(w_en_norm_fx, (31- q_w_en_norm_fx)-13) + en_ratio_fx + Pd_temp_res; + res_pow_q = 13; + res_pow_fx = L_shr(res_pow_fx, 1); + //res_pow *= 0.5f; + //hMdDec->spar_md.en_ratio_slow[band] = 0.75f * hMdDec->spar_md.en_ratio_slow[band] + 0.25f * en_ratio; + hMdDec->spar_md.en_ratio_slow_fx[band] = Mpy_32_32(1610612736, hMdDec->spar_md.en_ratio_slow_fx[band]) + Mpy_32_32(536870912, en_ratio_fx); + //hMdDec->spar_md.ref_pow_slow[band] = 0.75f * hMdDec->spar_md.ref_pow_slow[band] + 0.25f * res_pow; + hMdDec->spar_md.ref_pow_slow_fx[band] = Mpy_32_32(1610612736, hMdDec->spar_md.ref_pow_slow_fx[band]) + Mpy_32_32(536870912, res_pow_fx); + //en_ratio = sqrtf( hMdDec->spar_md.en_ratio_slow[band] ) / ( hMdDec->spar_md.ref_pow_slow[band] + EPSILON ); + en_ratio_q = 31 - 13; + en_ratio_fx = Sqrt32(hMdDec->spar_md.en_ratio_slow_fx[band], &en_ratio_q); + if (en_ratio_q < 0) + { + en_ratio_fx = L_shr(en_ratio_fx, -1 * (en_ratio_q)); + en_ratio_q = 0; + } + Word32 en_ratio_fx_scaled = L_shr(en_ratio_fx, (31 - en_ratio_q - 13)); + if (en_ratio_fx_scaled > hMdDec->spar_md.ref_pow_slow_fx[band]) + { + diffuseness_fx[band] = 0; + } + else if(en_ratio_fx_scaled == 0) + { + diffuseness_fx[band] = ONE_IN_Q30; + } + else if (en_ratio_fx_scaled == hMdDec->spar_md.ref_pow_slow_fx[band]) + { + diffuseness_fx[band] = ONE_IN_Q30; + } + else + { + en_ratio_fx = divide3232(en_ratio_fx_scaled, (hMdDec->spar_md.ref_pow_slow_fx[band] + EPSILON_FX)); + en_ratio_fx = L_shl(en_ratio_fx, 15); + diffuseness_fx[band] = ONE_IN_Q30 - en_ratio_fx; + } - w_en_norm = (1.0f - (f_scale * g_pred * g_pred)); - w_en_norm *= w_en_norm; - - Pd[0] = hMdDec->spar_md.band_coeffs[band].P_re[1]; - Pd[1] = hMdDec->spar_md.band_coeffs[band].P_re[0]; - Pd[2] = hMdDec->spar_md.band_coeffs[band].P_re[2]; - en_ratio = PR[0] * PR[0] + PR[1] * PR[1] + PR[2] * PR[2]; - res_pow = w_en_norm + en_ratio + (Pd[0] * Pd[0] + Pd[1] * Pd[1] + Pd[2] * Pd[2]); - res_pow *= 0.5f; - hMdDec->spar_md.en_ratio_slow[band] = 0.75f * hMdDec->spar_md.en_ratio_slow[band] + 0.25f * en_ratio; - hMdDec->spar_md.ref_pow_slow[band] = 0.75f * hMdDec->spar_md.ref_pow_slow[band] + 0.25f * res_pow; - en_ratio = sqrtf(hMdDec->spar_md.en_ratio_slow[band]) / (hMdDec->spar_md.ref_pow_slow[band] + EPSILON); } else { - en_ratio = PR[0] * PR[0] + PR[1] * PR[1] + PR[2] * PR[2]; - hMdDec->spar_md.en_ratio_slow[band] = 0.75f * hMdDec->spar_md.en_ratio_slow[band] + 0.25f * en_ratio; - en_ratio = sqrtf(hMdDec->spar_md.en_ratio_slow[band]); + //en_ratio = PR[0] * PR[0] + PR[1] * PR[1] + PR[2] * PR[2]; + en_ratio_fx = Mpy_32_32(PR_fx[0] , PR_fx[0]) + Mpy_32_32(PR_fx[1] , PR_fx[1])+ Mpy_32_32(PR_fx[2] , PR_fx[2]); + //hMdDec->spar_md.en_ratio_slow[band] = 0.75f * hMdDec->spar_md.en_ratio_slow[band] + 0.25f * en_ratio; + hMdDec->spar_md.en_ratio_slow_fx[band] = Mpy_32_32(1610612736, hMdDec->spar_md.en_ratio_slow_fx[band]) + Mpy_32_32(536870912, en_ratio_fx); + //en_ratio = sqrtf( hMdDec->spar_md.en_ratio_slow[band] ); + en_ratio_q = 31 - 13; + en_ratio_fx = Sqrt32( hMdDec->spar_md.en_ratio_slow_fx[band], &en_ratio_q); + if (en_ratio_q < 0) + { + en_ratio_fx = L_shr(en_ratio_fx, -1 * (en_ratio_q)); + en_ratio_q = 0; } - diffuseness[band] = 1.0f - en_ratio; /*compute diffuseness*/ - diffuseness[band] = ((diffuseness[band] < 1.0f) ? ((diffuseness[band] < 0.0f) ? 0.f : diffuseness[band]) : 1.0f); + Word32 en_ratio_fx_scaled = L_shr(en_ratio_fx, 1); + if (en_ratio_fx_scaled > ONE_IN_Q30) + { + diffuseness_fx[band] = 0; + } + else + { + diffuseness_fx[band] = ONE_IN_Q30 - en_ratio_fx_scaled; + } + + } + //diffuseness[band] = 1.0f - en_ratio; /*compute diffuseness*/ + // diffuseness[band] = ( ( diffuseness[band] < 1.0f ) ? ( ( diffuseness[band] < 0.0f ) ? 0.f : diffuseness[band] ) : 1.0f ); + //diffuseness[band] = (float)diffuseness_fx[band] / (1 << 30); } for (band = start_band; band < end_band; band++) @@ -4312,8 +5053,14 @@ void ivas_spar_to_dirac( int16_t azi_dith, ele_dith; tmp_write_idx_param_band = hDirAC->spar_to_dirac_write_idx; - en_ratio = 1.0f - diffuseness[band]; - masa_sq(1.0f - en_ratio, diffuseness_thresholds, DIRAC_DIFFUSE_LEVELS); + //en_ratio = 1.0f - diffuseness[band]; + en_ratio_fx = ONE_IN_Q30 - diffuseness_fx[band]; + //en_ratio = (float)en_ratio_fx / (1 << 30); + //cam delete the below function call + //masa_sq( 1.0f - en_ratio, diffuseness_thresholds, DIRAC_DIFFUSE_LEVELS ); +//#ifdef IVAS_FLOAT_FIXED + masa_sq_fx(ONE_IN_Q30 - en_ratio_fx, diffuseness_thresholds_fx, DIRAC_DIFFUSE_LEVELS ); +//#endif qmf_band_start = band_grouping[band]; qmf_band_end = band_grouping[band + 1]; @@ -4330,14 +5077,19 @@ void ivas_spar_to_dirac( azi_dith = azi[band]; ele_dith = ele[band]; - hSpatParamRendCom->energy_ratio1[block][b] = en_ratio; + hSpatParamRendCom->energy_ratio1[block][b] = en_ratio_fx / ((float)ONE_IN_Q30); + + hSpatParamRendCom->energy_ratio1_fx[block][b] = en_ratio_fx; tmp_write_idx_band = tmp_write_idx_param_band; if (hDirAC->hConfig->dec_param_estim == FALSE) { hSpatParamRendCom->elevation[tmp_write_idx_band][b] = ele_dith; hSpatParamRendCom->azimuth[tmp_write_idx_band][b] = azi_dith; - hSpatParamRendCom->diffuseness_vector[tmp_write_idx_band][b] = diffuseness[band]; + hSpatParamRendCom->diffuseness_vector[tmp_write_idx_band][b] = diffuseness_fx[band] / ((float)ONE_IN_Q30); + + hSpatParamRendCom->diffuseness_vector_fx[tmp_write_idx_band][b] = diffuseness_fx[band]; + } else { @@ -4345,7 +5097,9 @@ void ivas_spar_to_dirac( { hSpatParamRendCom->elevation[tmp_write_idx_band][b] = ele_dith; hSpatParamRendCom->azimuth[tmp_write_idx_band][b] = azi_dith; - hSpatParamRendCom->diffuseness_vector[tmp_write_idx_band][b] = diffuseness[band]; + hSpatParamRendCom->diffuseness_vector[tmp_write_idx_band][b] = diffuseness_fx[band] / ((float)ONE_IN_Q30); + + hSpatParamRendCom->diffuseness_vector_fx[tmp_write_idx_band][b] = diffuseness_fx[band]; tmp_write_idx_band = (tmp_write_idx_band + 1) % hSpatParamRendCom->dirac_md_buffer_length; } } @@ -4384,36 +5138,56 @@ void ivas_spar_to_dirac( for (block = 0; block < num_subframes; block++) { - if (st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].azimuth[block] < 0.f) - { - st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].azimuth[block] += 360.f; - } - azi_dirac[band][block] = st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].azimuth[block]; - ele_dirac[band][block] = st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].elevation[block]; - } - - diffuseness[band] = 1.0f - st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].energy_ratio[0]; + //if ( st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].azimuth[block] < 0.f ) + //{ + // st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].azimuth[block] += 360.f; + //} + if ( st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].azimuth_fx[block] < 0 ) + { + st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].azimuth_fx[block] = + L_add(L_shl(360, 22), st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].azimuth_fx[block]); + } + //azi_dirac[band][block] = st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].azimuth[block]; + //ele_dirac[band][block] = st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].elevation[block]; +//#ifdef IVAS_FLOAT_FIXED + azi_dirac_fx[band][block] = st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].azimuth_fx[block]; + ele_dirac_fx[band][block] = st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].elevation_fx[block]; +//#endif + } + + //diffuseness[band] = 1.0f - st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].energy_ratio[0]; +//#ifdef IVAS_FLOAT_FIXED + diffuseness_fx[band] = ONE_IN_Q30 - st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].energy_ratio_fx[0]; +//#endif } /* DirAC MD averaged over 4 subframes and converted to SPAR format similar to encoder processing */ if (hMdDec->spar_md_cfg.nchan_transport > 1) { +#ifdef IVAS_FLOAT_FIXED + ivas_get_spar_md_from_dirac_fx( azi_dirac_fx, ele_dirac_fx, diffuseness_fx, 1, NULL, &hMdDec->spar_md, &hMdDec->spar_md_cfg, end_band, num_bands_out, ( hMdDec->spar_hoa_md_flag ) ? 1 : sba_order_internal, dtx_vad, NULL, st_ivas->hQMetaData->useLowerRes, active_w_vlbr, dyn_active_w_flag ); +#else ivas_get_spar_md_from_dirac(azi_dirac, ele_dirac, diffuseness, 1, NULL, &hMdDec->spar_md, &hMdDec->spar_md_cfg, end_band, num_bands_out, (hMdDec->spar_hoa_md_flag) ? 1 : sba_order_internal, dtx_vad, NULL, st_ivas->hQMetaData->useLowerRes, active_w_vlbr, dyn_active_w_flag); +#endif /* temporarily copy frame-wise prediction coefficients in DirAC bands*/ for (pred_idx = 0; pred_idx < FOA_CHANNELS - 1; pred_idx++) { for (band = SPAR_DIRAC_SPLIT_START_BAND; band < IVAS_MAX_NUM_BANDS; band++) { - pred_re_20ms[band][pred_idx] = hMdDec->spar_md.band_coeffs[band].pred_re[pred_idx]; + //pred_re_20ms[band][pred_idx] = hMdDec->spar_md.band_coeffs[band].pred_re[pred_idx]; + pred_re_20ms_fx[band][pred_idx] = hMdDec->spar_md.band_coeffs[band].pred_re_fx[pred_idx]; } } } int16_t num_md_sub_frames; num_md_sub_frames = ivas_get_spar_dec_md_num_subframes(sba_order_internal, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->last_active_ivas_total_brate); - ivas_get_spar_md_from_dirac(azi_dirac, ele_dirac, diffuseness, num_md_sub_frames, NULL, &hMdDec->spar_md, &hMdDec->spar_md_cfg, end_band, num_bands_out / bw, (hMdDec->spar_hoa_md_flag) ? 1 : sba_order_internal, dtx_vad, NULL, st_ivas->hQMetaData->useLowerRes, active_w_vlbr, dyn_active_w_flag); - +//#ifdef IVAS_FLOAT_FIXED + ivas_get_spar_md_from_dirac_fx( azi_dirac_fx, ele_dirac_fx, diffuseness_fx, num_md_sub_frames, NULL, &hMdDec->spar_md, &hMdDec->spar_md_cfg, end_band, num_bands_out / bw, ( hMdDec->spar_hoa_md_flag ) ? 1 : sba_order_internal, dtx_vad, NULL, st_ivas->hQMetaData->useLowerRes, active_w_vlbr, dyn_active_w_flag ); +//#else +// ivas_get_spar_md_from_dirac( azi_dirac, ele_dirac, diffuseness, num_md_sub_frames, NULL, &hMdDec->spar_md, &hMdDec->spar_md_cfg, end_band, num_bands_out / bw, ( hMdDec->spar_hoa_md_flag ) ? 1 : sba_order_internal, dtx_vad, NULL, st_ivas->hQMetaData->useLowerRes, active_w_vlbr, dyn_active_w_flag ); +//#endif if (st_ivas->hQMetaData->useLowerRes && dtx_vad) { for (band = SPAR_DIRAC_SPLIT_START_BAND; band < IVAS_MAX_NUM_BANDS; band++) @@ -4422,11 +5196,13 @@ void ivas_spar_to_dirac( { for (i = 0; i < FOA_CHANNELS - 1; i++) /* pred coefficient index (index 0, 1, 2 predicts Y, Z, X respectively) */ { - hMdDec->spar_md.band_coeffs[band + block * IVAS_MAX_NUM_BANDS].pred_re[i] = hMdDec->spar_md.band_coeffs[band].pred_re[i]; + //hMdDec->spar_md.band_coeffs[band + block * IVAS_MAX_NUM_BANDS].pred_re[i] = hMdDec->spar_md.band_coeffs[band].pred_re[i]; + hMdDec->spar_md.band_coeffs[band + block * IVAS_MAX_NUM_BANDS].pred_re_fx[i] = hMdDec->spar_md.band_coeffs[band].pred_re_fx[i]; } for (i = 0; i < FOA_CHANNELS - 1; i++) /* pred coefficient index (index 0, 1, 2 predicts Y, Z, X respectively) */ { - hMdDec->spar_md.band_coeffs[band + block * IVAS_MAX_NUM_BANDS].P_re[i] = hMdDec->spar_md.band_coeffs[band].P_re[i]; + //hMdDec->spar_md.band_coeffs[band + block * IVAS_MAX_NUM_BANDS].P_re[i] = hMdDec->spar_md.band_coeffs[band].P_re[i]; + hMdDec->spar_md.band_coeffs[band + block * IVAS_MAX_NUM_BANDS].P_re_fx[i] = hMdDec->spar_md.band_coeffs[band].P_re_fx[i]; } } } @@ -4442,7 +5218,8 @@ void ivas_spar_to_dirac( if (ivas_is_res_channel(pred_idx + 1, hMdDec->spar_md_cfg.nchan_transport)) { /* use 20ms coefficients only for residual channels */ - hMdDec->spar_md.band_coeffs[band + block * IVAS_MAX_NUM_BANDS].pred_re[pred_idx] = pred_re_20ms[band][pred_idx]; + //hMdDec->spar_md.band_coeffs[band + block * IVAS_MAX_NUM_BANDS].pred_re[pred_idx] = pred_re_20ms[band][pred_idx]; + hMdDec->spar_md.band_coeffs[band + block * IVAS_MAX_NUM_BANDS].pred_re_fx[pred_idx] = pred_re_20ms_fx[band][pred_idx]; } } } @@ -4455,5 +5232,5 @@ void ivas_spar_to_dirac( return; } +#endif -#endif \ No newline at end of file diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h index 7685ba8a2..589f269d1 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -930,9 +930,10 @@ typedef struct ivas_mc_paramupmix_dec_data_structure /* SPAR MD structure */ typedef struct ivas_spar_dec_matrices_t { +#ifndef IVAS_FLOAT_FIXED float ***C_re; float ***P_re; -#ifdef IVAS_FLOAT_FIXED +#else Word32 ***C_re_fx; Word32 ***P_re_fx; #endif // DEBUG @@ -953,8 +954,10 @@ typedef struct ivas_spar_md_dec_state_t int16_t num_decorr; int16_t td_decorr_flag; int16_t spar_plc_enable_fadeout_flag; +#ifndef IVAS_FLOAT_FIXED float ***mixer_mat; float mixer_mat_prev[MAX_PARAM_SPATIAL_SUBFRAMES + 1][IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH][IVAS_MAX_NUM_BANDS]; +#endif ivas_spar_md_com_cfg spar_md_cfg; ivas_arith_coeffs_t arith_coeffs; ivas_huff_coeffs_t huff_coeffs; @@ -963,13 +966,16 @@ typedef struct ivas_spar_md_dec_state_t int16_t spar_hoa_md_flag; int16_t spar_hoa_dirac2spar_md_flag; int16_t HOA_md_ind[IVAS_SPAR_MAX_CH]; + float smooth_buf[IVAS_MAX_NUM_BANDS][2 * SBA_DIRAC_NRG_SMOOTH_LONG + 1]; float smooth_fac[IVAS_MAX_NUM_BANDS]; #ifdef IVAS_FLOAT_FIXED Word32 smooth_buf_fx[IVAS_MAX_NUM_BANDS][2 * SBA_DIRAC_NRG_SMOOTH_LONG + 1]; Word16 smooth_fac_fx[IVAS_MAX_NUM_BANDS]; #endif +#ifndef IVAS_FLOAT_FIXED float mixer_mat_prev2[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS]; +#endif int16_t first_valid_frame; ivas_band_coeffs_t *band_coeffs_prev; int16_t base_band_coeffs_age[IVAS_MAX_NUM_BANDS]; diff --git a/lib_rend/ivas_dirac_dec_binaural_functions.c b/lib_rend/ivas_dirac_dec_binaural_functions.c index 5cdfcabad..dda58984b 100644 --- a/lib_rend/ivas_dirac_dec_binaural_functions.c +++ b/lib_rend/ivas_dirac_dec_binaural_functions.c @@ -1318,17 +1318,18 @@ static void ivas_dirac_dec_binaural_internal( } if (st_ivas->hSpar != NULL) { - floatToFixed_arrL(&st_ivas->hSpar->hMdDec->mixer_mat_prev[0][0][0][0], &st_ivas->hSpar->hMdDec->mixer_mat_prev_fx[0][0][0][0], Q30, sizeof(st_ivas->hSpar->hMdDec->mixer_mat_prev_fx) / sizeof(st_ivas->hSpar->hMdDec->mixer_mat_prev_fx[0][0][0][0])); - for (int ii = 0; ii < st_ivas->hSpar->hMdDec->mix_mat_dim_0_1; ii++) - { - for (int jj = 0; jj < st_ivas->hSpar->hMdDec->mix_mat_dim_0_1; jj++) - { - floatToFixed_arrL(&st_ivas->hSpar->hMdDec->mixer_mat[ii][jj][0], - &st_ivas->hSpar->hMdDec->mixer_mat_fx[ii][jj][0], - Q30, - st_ivas->hSpar->hMdDec->mix_mat_dim_2); - } - } + //floatToFixed_arrL(&st_ivas->hSpar->hMdDec->mixer_mat_prev[0][0][0][0], &st_ivas->hSpar->hMdDec->mixer_mat_prev_fx[0][0][0][0], Q30, sizeof(st_ivas->hSpar->hMdDec->mixer_mat_prev_fx) / sizeof(st_ivas->hSpar->hMdDec->mixer_mat_prev_fx[0][0][0][0])); + //st_ivas->hSpar->hMdDec->Q_mixer_mat = 30; + //for (int ii = 0; ii < st_ivas->hSpar->hMdDec->mix_mat_dim_0_1; ii++) + //{ + // for (int jj = 0; jj < st_ivas->hSpar->hMdDec->mix_mat_dim_0_1; jj++) + // { + // floatToFixed_arrL(&st_ivas->hSpar->hMdDec->mixer_mat[ii][jj][0], + // &st_ivas->hSpar->hMdDec->mixer_mat_fx[ii][jj][0], + // Q30, + // st_ivas->hSpar->hMdDec->mix_mat_dim_2); + // } + //} } ////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -1357,17 +1358,18 @@ static void ivas_dirac_dec_binaural_internal( if (st_ivas->hSpar != NULL) { - fixedToFloat_arrL(&st_ivas->hSpar->hMdDec->mixer_mat_prev_fx[0][0][0][0], &st_ivas->hSpar->hMdDec->mixer_mat_prev[0][0][0][0], Q30, sizeof(st_ivas->hSpar->hMdDec->mixer_mat_prev_fx) / sizeof(st_ivas->hSpar->hMdDec->mixer_mat_prev_fx[0][0][0][0])); - for (int ii = 0; ii < st_ivas->hSpar->hMdDec->mix_mat_dim_0_1; ii++) - { - for (int jj = 0; jj < st_ivas->hSpar->hMdDec->mix_mat_dim_0_1; jj++) - { - fixedToFloat_arrL(&st_ivas->hSpar->hMdDec->mixer_mat_fx[ii][jj][0], - &st_ivas->hSpar->hMdDec->mixer_mat[ii][jj][0], - Q30, - st_ivas->hSpar->hMdDec->mix_mat_dim_2); - } - } + //fixedToFloat_arrL(&st_ivas->hSpar->hMdDec->mixer_mat_prev_fx[0][0][0][0], &st_ivas->hSpar->hMdDec->mixer_mat_prev[0][0][0][0], Q30, sizeof(st_ivas->hSpar->hMdDec->mixer_mat_prev_fx) / sizeof(st_ivas->hSpar->hMdDec->mixer_mat_prev_fx[0][0][0][0])); + //st_ivas->hSpar->hMdDec->Q_mixer_mat = 30; + //for (int ii = 0; ii < st_ivas->hSpar->hMdDec->mix_mat_dim_0_1; ii++) + //{ + // for (int jj = 0; jj < st_ivas->hSpar->hMdDec->mix_mat_dim_0_1; jj++) + // { + // fixedToFloat_arrL(&st_ivas->hSpar->hMdDec->mixer_mat_fx[ii][jj][0], + // &st_ivas->hSpar->hMdDec->mixer_mat[ii][jj][0], + // Q30, + // st_ivas->hSpar->hMdDec->mix_mat_dim_2); + // } + //} } FOR(Word16 cha = 0; cha < 6; cha++) FOR(slot = 0; slot < 4; slot++) diff --git a/lib_rend/ivas_sba_rendering.c b/lib_rend/ivas_sba_rendering.c index 34b325877..5d7adc221 100644 --- a/lib_rend/ivas_sba_rendering.c +++ b/lib_rend/ivas_sba_rendering.c @@ -42,7 +42,6 @@ #include #include "wmc_auto.h" - /*-------------------------------------------------------------------* * ivas_sba_prototype_renderer() * @@ -408,4 +407,4 @@ void ivas_sba_prototype_renderer( return; } -#endif \ No newline at end of file +#endif -- GitLab