diff --git a/lib_com/ivas_stat_com.h b/lib_com/ivas_stat_com.h index 7fceb7941f00f1fe9926765c7dc1eb69ff129550..22feb9b1648dc6d19e735024acf1587ef55cafa8 100644 --- a/lib_com/ivas_stat_com.h +++ b/lib_com/ivas_stat_com.h @@ -71,6 +71,11 @@ typedef struct float last_true_azimuth; /* MD smoothing in DTX- last true Q azimuth value */ float last_true_elevation; /* MD smoothing in DTX- last true Q elevation value */ +#ifdef FIX_387_ISM_MD_FEC + int16_t ism_md_fec_cnt_enc; /* counter of continuous frames where MD are not transmitted */ + int16_t ism_md_inc_diff_cnt; /* counter of continuous frames where MD are transmitted in inactive segments when MD significantly changes */ +#endif + } ISM_METADATA_FRAME, *ISM_METADATA_HANDLE; diff --git a/lib_com/options.h b/lib_com/options.h index 7e23e2a4a707c273b63b1ca1c428c5d2292af474..0a37aa0fe3defe3853f55a37f0541cbde74052e3 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -64,7 +64,7 @@ /*#define DEBUG_MODE_TCX*/ /* output most important TCX core parameters to the subdirectory "res/" */ /*#define DEBUG_MODE_DFT*/ /* output most important DFT stereo parameters to the subdirectory "res/" */ /*#define DEBUG_MODE_TD*/ /* output most important TD stereo parameters to the subdirectory "res/ */ -//#define DEBUG_MODE_DIRAC /* output most important DIRAC parameters to the subdirectory "res/" */ +/*#define DEBUG_MODE_DIRAC*/ /* output most important DIRAC parameters to the subdirectory "res/" */ /*#define DEBUG_MODE_MDCT*/ /* output most important MDCT parameters to the subdirectory "res/" */ /*#define DEBUG_MODE_PARAM_MC */ /* output Parametric MC paramters to the subdirectory "res/" */ /*#define DEBUG_MODE_PARAM_ISM*/ /* output Parametric ISM paramters to the subdirectory "res/" */ @@ -149,6 +149,7 @@ #define SNS_MSVQ /* FhG: contribution 33 - MSVQ for SNS parameters at stereo mid bitrates */ #define FIX_379_GAININTP /* Eri: Adds a gain interpolation for directional/distance gain to handle abrupt changes in metadata (Non BE) */ +#define FIX_387_ISM_MD_FEC /* VA: Issue 387: fix MD discontinuity in ISM FEC */ #define FIX_418_SID_BITRATE /* Eri: Issue 418: Using the correct bitrate for unified stereo SID */ #define PARAMMC_SHORT_ENC_MDFT /* FhG: Issue 410: complexity optimization for parametric Multichannel modes */ diff --git a/lib_enc/ivas_ism_metadata_enc.c b/lib_enc/ivas_ism_metadata_enc.c index e5e1e991562b717c77bf2abb9e0b748a9816133a..e9e40a574c92de18d8412efd64ff842f1755e1f7 100644 --- a/lib_enc/ivas_ism_metadata_enc.c +++ b/lib_enc/ivas_ism_metadata_enc.c @@ -56,6 +56,11 @@ #define ISM_MAX_RADIUS_DIFF_IDX ( ISM_RADIUS_NBITS - 1 /*zero*/ - 1 /*sign*/ ) #define ISM_FEC_MAX 10 +#ifdef FIX_387_ISM_MD_FEC +#define ISM_MD_FEC_DIFF 10 +#define ISM_MD_INC_DIFF_CNT_MAX 6 +#define ISM_MD_FEC_CNT_MAX 25 +#endif #define INTER_OBJECT_PARAM_CHECK ( ( ISM_FEC_MAX / 2 ) - 2 ) /* note: constant must be less than (ISM_FEC_MAX / number of coded parameters) */ @@ -195,7 +200,6 @@ ivas_error ivas_ism_metadata_enc( push_wmops( "ism_meta_enc" ); - /* initialization */ ism_metadata_flag_global = 0; set_s( nb_bits_metadata, 0, nchan_transport ); @@ -218,6 +222,37 @@ ivas_error ivas_ism_metadata_enc( else if ( ism_mode == ISM_MODE_DISC ) { hIsmMeta[ch]->ism_metadata_flag = localVAD[ch] || hSCE[ch]->hCoreCoder[0]->lp_noise > 10; + +#ifdef FIX_387_ISM_MD_FEC + /* in inactive frames, send MD 1) in ISM_MD_INC_DIFF_CNT_MAX consecutive frames when MD significantly change, 2) at least every ISM_MD_FEC_DIFF frames */ + if ( hIsmMeta[ch]->ism_metadata_flag == 0 ) + { + if ( ( fabsf( hIsmMeta[ch]->azimuth - hIsmMeta[ch]->last_true_azimuth ) > ISM_MD_FEC_DIFF ) || + ( fabsf( hIsmMeta[ch]->elevation - hIsmMeta[ch]->last_true_elevation ) > ISM_MD_FEC_DIFF ) ) + { + hIsmMeta[ch]->ism_metadata_flag = 1; + hIsmMeta[ch]->ism_md_inc_diff_cnt = 0; + } + else if ( hIsmMeta[ch]->ism_md_inc_diff_cnt < ISM_MD_INC_DIFF_CNT_MAX ) + { + hIsmMeta[ch]->ism_metadata_flag = 1; + + if ( hIsmMeta[ch]->ism_md_inc_diff_cnt % 2 == 0 ) + { + hIsmMeta[ch]->position_angle.angle1_diff_cnt = ISM_FEC_MAX; + } + else + { + hIsmMeta[ch]->position_angle.angle2_diff_cnt = ISM_FEC_MAX; + } + } + else if ( hIsmMeta[ch]->ism_md_fec_cnt_enc == ISM_MD_FEC_CNT_MAX ) + { + hIsmMeta[ch]->ism_metadata_flag = 1; + hIsmMeta[ch]->position_angle.angle1_diff_cnt = ISM_FEC_MAX; + } + } +#endif } } @@ -307,7 +342,9 @@ ivas_error ivas_ism_metadata_enc( idx_angle1_abs = hParamIsm->azi_index[ch]; idx_angle2_abs = hParamIsm->ele_index[ch]; } + encode_angle_indices( hBstr, &( hIsmMetaData->position_angle ), hIsmMetaData->last_ism_metadata_flag, hSCE[0]->hCoreCoder[0]->ini_frame, idx_angle1_abs, idx_angle2_abs, &flag_abs_azimuth[ch], &flag_abs_elevation[ch] ); + /*----------------------------------------------------------------* * Quantize and encode radius, yaw, and pitch *----------------------------------------------------------------*/ @@ -317,6 +354,7 @@ ivas_error ivas_ism_metadata_enc( idx_angle1_abs = ism_quant_meta( hIsmMetaData->yaw, &valQ, ism_azimuth_borders, ISM_Q_STEP, ISM_Q_STEP_BORDER, 1 << ISM_AZIMUTH_NBITS ); idx_angle2_abs = ism_quant_meta( hIsmMetaData->pitch, &valQ, ism_elevation_borders, ISM_Q_STEP, ISM_Q_STEP_BORDER, 1 << ISM_ELEVATION_NBITS ); idx_radius_abs = usquant( hIsmMetaData->radius, &valQ, ISM_RADIUS_MIN, ISM_RADIUS_DELTA, 1 << ISM_RADIUS_NBITS ); + encode_angle_indices( hBstr, &( hIsmMetaData->orientation_angle ), hIsmMetaData->last_ism_metadata_flag, hSCE[0]->hCoreCoder[0]->ini_frame, idx_angle1_abs, idx_angle2_abs, &flag_abs_yaw[ch], &flag_abs_pitch[ch] ); encode_radius( hBstr, &hIsmMetaData->last_radius_idx, &hIsmMetaData->radius_diff_cnt, hIsmMetaData->last_ism_metadata_flag, idx_radius_abs, &flag_abs_radius[ch] ); } @@ -326,6 +364,12 @@ ivas_error ivas_ism_metadata_enc( { nb_bits_metadata[ch] = hBstr->nb_bits_tot - nb_bits_start; } + +#ifdef FIX_387_ISM_MD_FEC + /* Updates */ + hIsmMeta[ch]->last_true_azimuth = hIsmMeta[ch]->azimuth; + hIsmMeta[ch]->last_true_elevation = hIsmMeta[ch]->elevation; +#endif } } @@ -462,6 +506,19 @@ ivas_error ivas_ism_metadata_enc( for ( ch = 0; ch < nchan_ism; ch++ ) { hIsmMeta[ch]->last_ism_metadata_flag = hIsmMeta[ch]->ism_metadata_flag; + +#ifdef FIX_387_ISM_MD_FEC + if ( hIsmMeta[ch]->ism_metadata_flag == 0 ) + { + hIsmMeta[ch]->ism_md_fec_cnt_enc++; + } + else + { + hIsmMeta[ch]->ism_md_fec_cnt_enc = 0; + } + hIsmMeta[ch]->ism_md_inc_diff_cnt++; + hIsmMeta[ch]->ism_md_inc_diff_cnt = min( hIsmMeta[ch]->ism_md_inc_diff_cnt, ISM_MD_INC_DIFF_CNT_MAX ); +#endif } for ( ch = 0; ch < nchan_transport; ch++ ) @@ -547,6 +604,13 @@ ivas_error ivas_ism_metadata_enc_create( st_ivas->hIsmMetaData[ch]->last_azimuth = 0.0f; st_ivas->hIsmMetaData[ch]->last_elevation = 0.0f; + +#ifdef FIX_387_ISM_MD_FEC + st_ivas->hIsmMetaData[ch]->last_true_azimuth = 0.0f; + st_ivas->hIsmMetaData[ch]->last_true_elevation = 0.0f; + st_ivas->hIsmMetaData[ch]->ism_md_fec_cnt_enc = 0; + st_ivas->hIsmMetaData[ch]->ism_md_inc_diff_cnt = ISM_MD_INC_DIFF_CNT_MAX; +#endif } if ( ( error = ivas_ism_config( st_ivas->hEncoderConfig->ivas_total_brate, nchan_transport, n_ISms, NULL, NULL, NULL, element_brate_tmp, NULL, NULL ) ) != IVAS_ERR_OK ) @@ -667,14 +731,14 @@ static void encode_radius( * Encoding of an angle *----------------------------------------------------------------*/ static void encode_angle_indices( - BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */ + BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */ ISM_METADATA_ANGLE_HANDLE angle, /* i/o: angle handle */ - const int16_t last_ism_metadata_flag, /* i : last frame ism_metadata_flag */ - const int16_t ini_frame, /* i : initialization frames counter */ - const int16_t idx_angle1_abs, /* i : Azimuth index */ - const int16_t idx_angle2_abs, /* i : Elevation index */ - int16_t *flag_abs_angle1, /* o : Azimuth/yaw encoding mode */ - int16_t *flag_abs_angle2 /* o : Elevation/pitch encoding mode */ + const int16_t last_ism_metadata_flag, /* i : last frame ism_metadata_flag */ + const int16_t ini_frame, /* i : initialization frames counter */ + const int16_t idx_angle1_abs, /* i : Azimuth index */ + const int16_t idx_angle2_abs, /* i : Elevation index */ + int16_t *flag_abs_angle1, /* o : Azimuth/yaw encoding mode */ + int16_t *flag_abs_angle2 /* o : Elevation/pitch encoding mode */ ) { int16_t idx_angle1, nbits_diff_angle1, diff; @@ -1032,6 +1096,11 @@ void ivas_ism_metadata_sid_enc( hIsmMetaData->position_angle.last_angle1_idx = idx_azimuth << ( ISM_AZIMUTH_NBITS - nBits_azimuth ); hIsmMetaData->position_angle.last_angle2_idx = idx_elevation << ( ISM_ELEVATION_NBITS - nBits_elevation ); } + +#ifdef FIX_387_ISM_MD_FEC + hIsmMetaData->ism_md_fec_cnt_enc = 0; + hIsmMeta[ch]->ism_md_inc_diff_cnt = ISM_MD_INC_DIFF_CNT_MAX; +#endif } }