From e69fb98b93916e69d179d67405783379d74f8f12 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Tue, 16 Jul 2024 10:52:16 +0530 Subject: [PATCH] Functions in ivas_ism_metadata_enc.c converted to fixed point --- lib_com/ivas_prot.h | 56 +- lib_com/ivas_stat_com.h | 7 + lib_enc/ivas_enc.c | 58 +- lib_enc/ivas_ism_enc.c | 134 ++++ lib_enc/ivas_ism_metadata_enc.c | 1199 ++++++++++++++++++++++++------- lib_enc/ivas_omasa_enc.c | 73 +- lib_enc/ivas_stat_enc.h | 5 +- lib_enc/lib_enc.c | 18 +- 8 files changed, 1278 insertions(+), 272 deletions(-) diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 437e88399..5dcff25ea 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -1226,6 +1226,17 @@ void ivas_ism_reset_metadata_API( ); /*! r: index of the winning codeword */ +#ifdef IVAS_FLOAT_FIXED +Word16 ism_quant_meta_fx( + const Word32 val, /* i : scalar value to quantize */ + Word32 *valQ, /* o : quantized value */ + const Word32 borders_fx[], /* i : level borders */ + const Word32 q_step_fx, /* i : quantization step */ + const Word32 q_step_border_fx, /* i : quantization step at the border */ + const Word16 cbsize /* i : codebook size */ +); +#endif + int16_t ism_quant_meta( const float val, /* i : scalar value to quantize */ float *valQ, /* o : quantized value */ @@ -1244,6 +1255,17 @@ float ism_dequant_meta( const int16_t cbsize /* i : codebook size */ ); +#ifdef IVAS_FLOAT_FIXED +ivas_error ivas_set_ism_metadata_fx( + ISM_METADATA_HANDLE hIsmMeta, /* o : ISM metadata handle */ + const Word32 azimuth, /* i : azimuth value */ + const Word32 elevation, /* i : elevation value */ + const Word16 radius_meta, /* i : radius */ + const Word32 yaw, /* i : yaw */ + const Word32 pitch, /* i : pitch */ + const Word16 non_diegetic_flag /* i : non-diegetic object flag */ +); +#else ivas_error ivas_set_ism_metadata( ISM_METADATA_HANDLE hIsmMeta, /* o : ISM metadata handle */ const float azimuth, /* i : azimuth value */ @@ -1253,7 +1275,7 @@ ivas_error ivas_set_ism_metadata( const float pitch, /* i : pitch */ const int16_t non_diegetic_flag /* i : non-diegetic object flag */ ); - +#endif ivas_error ivas_ism_metadata_enc_create( Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ const int16_t n_ISms, /* i : number of objects */ @@ -1274,6 +1296,25 @@ ivas_error ivas_ism_enc( const int16_t flag_omasa_ener_brate /* i : less bitrate for objects in OMASA flag */ ); +#ifdef IVAS_FLOAT_FIXED +ivas_error ivas_ism_metadata_enc( + Word32 *ism_total_brate, /* i/o: ISM total bitrate */ + const Word16 nchan_ism, /* i : number of ISM channels */ + const Word16 nchan_transport, /* i : number of transport channels */ + ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */ + SCE_ENC_HANDLE hSCE[], /* i/o: SCE encoder handles */ + BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */ + Word16 nb_bits_metadata[], /* o : number of metadata bits */ + const Word16 localVAD[], /* i : VAD flag */ + const Word16 ism_mode, /* i : ISM mode */ + const PARAM_ISM_CONFIG_HANDLE hParamIsm, /* i : Param ISM Config Handle */ + const Word16 ism_extended_metadata_flag, /* i : Extended metadata flag */ + const Word32 lp_noise_CPE, /* i : LP filtered total noise estimation */ + const Word16 flag_omasa_ener_brate, /* i : less bitrate for objects in OMASA flag */ + Word16 *omasa_stereo_sw_cnt, + const Word16 ini_frame +); +#else ivas_error ivas_ism_metadata_enc( int32_t *ism_total_brate, /* i/o: ISM total bitrate */ const int16_t nchan_ism, /* i : number of ISM channels */ @@ -1291,7 +1332,7 @@ ivas_error ivas_ism_metadata_enc( int16_t *omasa_stereo_sw_cnt, const int16_t ini_frame ); - +#endif ivas_error ivas_ism_metadata_dec( const int32_t ism_total_brate, /* i : ISM total bitrate */ const int16_t nchan_ism, /* i : number of ISM channels */ @@ -7589,6 +7630,17 @@ void ivas_set_surplus_brate_dec( int32_t *ism_total_brate /* i : ISM total bitrate */ ); +#ifdef IVAS_FLOAT_FIXED +void ivas_set_ism_importance_interformat_fx( + const Word32 ism_total_brate, /* i/o: ISms total bitrate */ + const Word16 nchan_transport, /* i : number of transported channels */ + ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */ + SCE_ENC_HANDLE hSCE[], /* i/o: SCE encoder handles */ + const Word32 lp_noise_CPE_fx, /* i : LP filtered total noise estimation */ + Word16 ism_imp[] /* o : ISM importance flags */ +); +#endif + void ivas_set_ism_importance_interformat( const int32_t ism_total_brate, /* i/o: ISms total bitrate */ const int16_t nchan_transport, /* i : number of transported channels */ diff --git a/lib_com/ivas_stat_com.h b/lib_com/ivas_stat_com.h index 67b03df52..0b7519f44 100644 --- a/lib_com/ivas_stat_com.h +++ b/lib_com/ivas_stat_com.h @@ -93,10 +93,17 @@ typedef struct 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 */ float last_true_radius; /* last true Q radius value */ +#ifdef IVAS_FLOAT_FIXED + Word16 last_true_radius_fx; /* last true Q radius value */ +#endif int16_t ism_imp; /* ISM importance flag */ int16_t ism_md_null_flag; int16_t ism_md_lowrate_flag; +#ifdef IVAS_FLOAT_FIXED + Word32 q_azimuth_old_fx; + Word32 q_elevation_old_fx; +#endif float q_azimuth_old; float q_elevation_old; diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index cdcdadb8e..d7e2d24b2 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -407,12 +407,68 @@ ivas_error ivas_enc( { n = hEncoderConfig->nchan_ism; hMetaData = st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData; +#ifdef IVAS_FLOAT_FIXED + /*===============================flt-to-fix=============================================*/ + IF( NE_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) || NE_16( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) + { + FOR( int ch = 0; ch < st_ivas->hEncoderConfig->nchan_ism; ch++ ) + { + IF( EQ_16( st_ivas->ism_mode, ISM_MODE_DISC ) || EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) || EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) + { + IF( EQ_16( st_ivas->hIsmMetaData[ch]->ism_metadata_flag, 1 ) ) + { + /*IF( NE_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) + { + hSCE[ch]->hCoreCoder[0]->lp_noise_fx = float_to_fix16( hSCE[ch]->hCoreCoder[0]->lp_noise, Q8 ); + }*/ + IF( st_ivas->hIsmMetaData[ch]->ism_metadata_flag == 0 ) + { + st_ivas->hIsmMetaData[ch]->azimuth_fx = float_to_fix( st_ivas->hIsmMetaData[ch]->azimuth, Q22 ); + st_ivas->hIsmMetaData[ch]->last_true_azimuth_fx = float_to_fix( st_ivas->hIsmMetaData[ch]->last_true_azimuth, Q22 ); + st_ivas->hIsmMetaData[ch]->elevation_fx = float_to_fix( st_ivas->hIsmMetaData[ch]->elevation, Q22 ); + st_ivas->hIsmMetaData[ch]->last_true_elevation_fx = float_to_fix( st_ivas->hIsmMetaData[ch]->last_true_elevation, Q22 ); + st_ivas->hIsmMetaData[ch]->radius_fx = float_to_fix16( st_ivas->hIsmMetaData[ch]->radius, Q9 ); + st_ivas->hIsmMetaData[ch]->last_true_radius_fx = float_to_fix16( st_ivas->hIsmMetaData[ch]->last_true_radius, Q9 ); + } + } + } + } + } + IF( st_ivas->hIsmMetaData != NULL ) + { + FOR( int ch = 0; ch < st_ivas->hEncoderConfig->nchan_ism; ch++ ) + { + st_ivas->hIsmMetaData[ch]->azimuth_fx = floatToFixed( st_ivas->hIsmMetaData[ch]->azimuth, Q22 ); + st_ivas->hIsmMetaData[ch]->elevation_fx = floatToFixed( st_ivas->hIsmMetaData[ch]->elevation, Q22 ); + st_ivas->hIsmMetaData[ch]->yaw_fx = floatToFixed( st_ivas->hIsmMetaData[ch]->yaw, Q22 ); + st_ivas->hIsmMetaData[ch]->pitch_fx = floatToFixed( st_ivas->hIsmMetaData[ch]->pitch, Q22 ); + st_ivas->hIsmMetaData[ch]->radius_fx = float_to_fix16( st_ivas->hIsmMetaData[ch]->radius, Q9 ); + } + } + /*===============================flt-to-fix=============================================*/ - if ( ( error = ivas_ism_metadata_enc( &st_ivas->hEncoderConfig->ivas_total_brate, n, st_ivas->hEncoderConfig->nchan_ism, st_ivas->hIsmMetaData, NULL, hMetaData, &nb_bits_metadata[1], 0, st_ivas->ism_mode, NULL, st_ivas->hEncoderConfig->ism_extended_metadata_flag, -1, 0, NULL, st_ivas->hCPE[0]->hCoreCoder[0]->ini_frame ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_ism_metadata_enc( &st_ivas->hEncoderConfig->ivas_total_brate, n, st_ivas->hEncoderConfig->nchan_ism, st_ivas->hIsmMetaData, NULL, hMetaData, &nb_bits_metadata[1], 0, st_ivas->ism_mode, NULL, st_ivas->hEncoderConfig->ism_extended_metadata_flag, L_negate( ONE_IN_Q8 ), 0, NULL, st_ivas->hCPE[0]->hCoreCoder[0]->ini_frame ) ) != IVAS_ERR_OK ) { return error; } + /*===============================flt-2-fix======================================*/ + IF( st_ivas->hIsmMetaData != NULL ) + { + FOR( int ch = 0; ch < st_ivas->hEncoderConfig->nchan_ism; ch++ ) + { + st_ivas->hIsmMetaData[ch]->last_true_azimuth = fix_to_float( st_ivas->hIsmMetaData[ch]->last_true_azimuth_fx, Q22 ); + st_ivas->hIsmMetaData[ch]->last_true_elevation = fix_to_float( st_ivas->hIsmMetaData[ch]->last_true_elevation_fx, Q22 ); + st_ivas->hIsmMetaData[ch]->last_true_radius = fix16_to_float( st_ivas->hIsmMetaData[ch]->last_true_radius_fx, Q9 ); + } + } + /*===============================fix-2-flt======================================*/ +#else + if ( ( error = ivas_ism_metadata_enc( &st_ivas->hEncoderConfig->ivas_total_brate, n, st_ivas->hEncoderConfig->nchan_ism, st_ivas->hIsmMetaData, NULL, hMetaData, &nb_bits_metadata[1], 0, st_ivas->ism_mode, NULL, st_ivas->hEncoderConfig->ism_extended_metadata_flag, -1, 0, NULL, st_ivas->hCPE[0]->hCoreCoder[0]->ini_frame ) ) != IVAS_ERR_OK ) + { + return error; + } +#endif /* SBA metadata encoding and SBA metadata bitstream writing */ if ( ( error = ivas_spar_enc( st_ivas, &data_f[n], input_frame, nb_bits_metadata, hMetaData ) ) != IVAS_ERR_OK ) { diff --git a/lib_enc/ivas_ism_enc.c b/lib_enc/ivas_ism_enc.c index 7a819965b..45e4f6534 100644 --- a/lib_enc/ivas_ism_enc.c +++ b/lib_enc/ivas_ism_enc.c @@ -39,6 +39,7 @@ #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED #include "ivas_prot_fx.h" +#include "prot_fx1.h" #include "prot_fx2.h" #endif @@ -259,15 +260,86 @@ ivas_error ivas_ism_enc( if ( dtx_flag ) { +#ifdef IVAS_FLOAT_FIXED + /*================flt-to-fix===================================*/ + IF( sid_flag ) + { + IF( GT_16( st_ivas->nchan_transport, 1 ) ) + { + /* write sce id */ + /* quantize and write coherence */ + floatToFixed_arr16( st_ivas->hISMDTX->coh, st_ivas->hISMDTX->coh_fx, Q15, st_ivas->nchan_transport ); + } + } + /*================flt-to-fix===================================*/ +#endif ivas_ism_metadata_sid_enc( st_ivas->hISMDTX, flag_noisy_speech, nchan_ism, st_ivas->nchan_transport, st_ivas->ism_mode, st_ivas->hIsmMetaData, sid_flag, md_diff_flag, st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData, nb_bits_metadata ); } else if ( st_ivas->ism_mode == ISM_MODE_PARAM ) { +#ifdef IVAS_FLOAT_FIXED + /*===============================flt-to-fix=============================================*/ + IF( NE_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) || NE_16( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) + { + FOR( int ch = 0; ch < st_ivas->hEncoderConfig->nchan_ism; ch++ ) + { + IF( EQ_16( st_ivas->ism_mode, ISM_MODE_DISC ) || EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) || EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) + { + IF( EQ_16( st_ivas->hIsmMetaData[ch]->ism_metadata_flag, 1 ) ) + { + IF( NE_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) + { + st_ivas->hSCE[ch]->hCoreCoder[0]->lp_noise_fx = float_to_fix16( st_ivas->hSCE[ch]->hCoreCoder[0]->lp_noise, Q8 ); + } + IF( st_ivas->hIsmMetaData[ch]->ism_metadata_flag == 0 ) + { + st_ivas->hIsmMetaData[ch]->azimuth_fx = float_to_fix( st_ivas->hIsmMetaData[ch]->azimuth, Q22 ); + st_ivas->hIsmMetaData[ch]->last_true_azimuth_fx = float_to_fix( st_ivas->hIsmMetaData[ch]->last_true_azimuth, Q22 ); + st_ivas->hIsmMetaData[ch]->elevation_fx = float_to_fix( st_ivas->hIsmMetaData[ch]->elevation, Q22 ); + st_ivas->hIsmMetaData[ch]->last_true_elevation_fx = float_to_fix( st_ivas->hIsmMetaData[ch]->last_true_elevation, Q22 ); + st_ivas->hIsmMetaData[ch]->radius_fx = float_to_fix16( st_ivas->hIsmMetaData[ch]->radius, Q9 ); + st_ivas->hIsmMetaData[ch]->last_true_radius_fx = float_to_fix16( st_ivas->hIsmMetaData[ch]->last_true_radius, Q9 ); + } + } + } + } + } + IF( st_ivas->hIsmMetaData != NULL ) + { + FOR( int ch = 0; ch < st_ivas->hEncoderConfig->nchan_ism; ch++ ) + { + st_ivas->hIsmMetaData[ch]->azimuth_fx = floatToFixed( st_ivas->hIsmMetaData[ch]->azimuth, Q22 ); + st_ivas->hIsmMetaData[ch]->elevation_fx = floatToFixed( st_ivas->hIsmMetaData[ch]->elevation, Q22 ); + st_ivas->hIsmMetaData[ch]->yaw_fx = floatToFixed( st_ivas->hIsmMetaData[ch]->yaw, Q22 ); + st_ivas->hIsmMetaData[ch]->pitch_fx = floatToFixed( st_ivas->hIsmMetaData[ch]->pitch, Q22 ); + st_ivas->hIsmMetaData[ch]->radius_fx = float_to_fix16( st_ivas->hIsmMetaData[ch]->radius, Q9 ); + } + } + /*===============================flt-to-fix=============================================*/ + IF( ( error = ivas_ism_metadata_enc( &st_ivas->hEncoderConfig->ivas_total_brate, nchan_ism, nchan_transport_ism, st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData, + nb_bits_metadata, vad_flag, st_ivas->ism_mode, st_ivas->hParamIsm, st_ivas->hEncoderConfig->ism_extended_metadata_flag, L_negate( ONE_IN_Q8 ), 0, NULL, st_ivas->hSCE[0]->hCoreCoder[0]->ini_frame ) ) != IVAS_ERR_OK ) + { + return error; + } + + /*===============================flt-2-fix======================================*/ + IF( st_ivas->hIsmMetaData != NULL ) + { + FOR( int ch = 0; ch < st_ivas->hEncoderConfig->nchan_ism; ch++ ) + { + st_ivas->hIsmMetaData[ch]->last_true_azimuth = fix_to_float( st_ivas->hIsmMetaData[ch]->last_true_azimuth_fx, Q22 ); + st_ivas->hIsmMetaData[ch]->last_true_elevation = fix_to_float( st_ivas->hIsmMetaData[ch]->last_true_elevation_fx, Q22 ); + st_ivas->hIsmMetaData[ch]->last_true_radius = fix16_to_float( st_ivas->hIsmMetaData[ch]->last_true_radius_fx, Q9 ); + } + } + /*===============================fix-2-flt======================================*/ +#else if ( ( error = ivas_ism_metadata_enc( &st_ivas->hEncoderConfig->ivas_total_brate, nchan_ism, nchan_transport_ism, st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData, nb_bits_metadata, vad_flag, st_ivas->ism_mode, st_ivas->hParamIsm, st_ivas->hEncoderConfig->ism_extended_metadata_flag, -1, 0, NULL, st_ivas->hSCE[0]->hCoreCoder[0]->ini_frame ) ) != IVAS_ERR_OK ) { return error; } +#endif } else /* ISM_MODE_DISC */ { @@ -285,12 +357,74 @@ ivas_error ivas_ism_enc( } ism_total_brate_ref = ism_total_brate; +#ifdef IVAS_FLOAT_FIXED + IF( st_ivas->hMasa != NULL ) + { + st_ivas->hMasa->data.hOmasaData->lp_noise_CPE_fx = floatToFixed( st_ivas->hMasa->data.hOmasaData->lp_noise_CPE, Q8 ); + } + /*===============================flt-to-fix=============================================*/ + IF( NE_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) || NE_16( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) + { + FOR( int ch = 0; ch < st_ivas->hEncoderConfig->nchan_ism; ch++ ) + { + IF( EQ_16( st_ivas->ism_mode, ISM_MODE_DISC ) || EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) || EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) + { + IF( EQ_16( st_ivas->hIsmMetaData[ch]->ism_metadata_flag, 1 ) ) + { + IF( NE_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) + { + st_ivas->hSCE[ch]->hCoreCoder[0]->lp_noise_fx = float_to_fix16( st_ivas->hSCE[ch]->hCoreCoder[0]->lp_noise, Q8 ); + } + IF( st_ivas->hIsmMetaData[ch]->ism_metadata_flag == 0 ) + { + st_ivas->hIsmMetaData[ch]->azimuth_fx = float_to_fix( st_ivas->hIsmMetaData[ch]->azimuth, Q22 ); + st_ivas->hIsmMetaData[ch]->last_true_azimuth_fx = float_to_fix( st_ivas->hIsmMetaData[ch]->last_true_azimuth, Q22 ); + st_ivas->hIsmMetaData[ch]->elevation_fx = float_to_fix( st_ivas->hIsmMetaData[ch]->elevation, Q22 ); + st_ivas->hIsmMetaData[ch]->last_true_elevation_fx = float_to_fix( st_ivas->hIsmMetaData[ch]->last_true_elevation, Q22 ); + st_ivas->hIsmMetaData[ch]->radius_fx = float_to_fix16( st_ivas->hIsmMetaData[ch]->radius, Q9 ); + st_ivas->hIsmMetaData[ch]->last_true_radius_fx = float_to_fix16( st_ivas->hIsmMetaData[ch]->last_true_radius, Q9 ); + } + } + } + } + } + IF( st_ivas->hIsmMetaData != NULL ) + { + FOR( int ch = 0; ch < st_ivas->hEncoderConfig->nchan_ism; ch++ ) + { + st_ivas->hIsmMetaData[ch]->azimuth_fx = floatToFixed( st_ivas->hIsmMetaData[ch]->azimuth, Q22 ); + st_ivas->hIsmMetaData[ch]->elevation_fx = floatToFixed( st_ivas->hIsmMetaData[ch]->elevation, Q22 ); + st_ivas->hIsmMetaData[ch]->yaw_fx = floatToFixed( st_ivas->hIsmMetaData[ch]->yaw, Q22 ); + st_ivas->hIsmMetaData[ch]->pitch_fx = floatToFixed( st_ivas->hIsmMetaData[ch]->pitch, Q22 ); + st_ivas->hIsmMetaData[ch]->radius_fx = float_to_fix16( st_ivas->hIsmMetaData[ch]->radius, Q9 ); + } + } + /*===============================flt-to-fix=============================================*/ + + IF( ( error = ivas_ism_metadata_enc( &ism_total_brate, nchan_ism, nchan_transport_ism, st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData, + nb_bits_metadata, vad_flag, st_ivas->ism_mode, NULL, st_ivas->hEncoderConfig->ism_extended_metadata_flag, st_ivas->hMasa != NULL ? st_ivas->hMasa->data.hOmasaData->lp_noise_CPE_fx : 0, flag_omasa_ener_brate, st_ivas->hMasa != NULL ? &( st_ivas->hMasa->data.hOmasaData->omasa_stereo_sw_cnt ) : NULL, st_ivas->hSCE[0]->hCoreCoder[0]->ini_frame ) ) != IVAS_ERR_OK ) + { + return error; + } + /*===============================flt-2-fix======================================*/ + IF( st_ivas->hIsmMetaData != NULL ) + { + FOR( int ch = 0; ch < st_ivas->hEncoderConfig->nchan_ism; ch++ ) + { + st_ivas->hIsmMetaData[ch]->last_true_azimuth = fix_to_float( st_ivas->hIsmMetaData[ch]->last_true_azimuth_fx, Q22 ); + st_ivas->hIsmMetaData[ch]->last_true_elevation = fix_to_float( st_ivas->hIsmMetaData[ch]->last_true_elevation_fx, Q22 ); + st_ivas->hIsmMetaData[ch]->last_true_radius = fix16_to_float( st_ivas->hIsmMetaData[ch]->last_true_radius_fx, Q9 ); + } + } + /*===============================fix-2-flt======================================*/ +#else if ( ( error = ivas_ism_metadata_enc( &ism_total_brate, nchan_ism, nchan_transport_ism, st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData, nb_bits_metadata, vad_flag, st_ivas->ism_mode, NULL, st_ivas->hEncoderConfig->ism_extended_metadata_flag, st_ivas->hMasa != NULL ? st_ivas->hMasa->data.hOmasaData->lp_noise_CPE : 0, flag_omasa_ener_brate, st_ivas->hMasa != NULL ? &( st_ivas->hMasa->data.hOmasaData->omasa_stereo_sw_cnt ) : NULL, st_ivas->hSCE[0]->hCoreCoder[0]->ini_frame ) ) != IVAS_ERR_OK ) { return error; } +#endif if ( st_ivas->hEncoderConfig->ivas_format == MASA_ISM_FORMAT ) { diff --git a/lib_enc/ivas_ism_metadata_enc.c b/lib_enc/ivas_ism_metadata_enc.c index 8eaf2d7a0..dd90f0711 100644 --- a/lib_enc/ivas_ism_metadata_enc.c +++ b/lib_enc/ivas_ism_metadata_enc.c @@ -45,12 +45,15 @@ #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED #include "ivas_prot_fx.h" +#include "prot_fx1.h" +#include "prot_fx2.h" +#include "ivas_rom_com_fx.h" +#define IVAS_FLOAT_FIXED_TO_BE_REMOVED #endif #ifdef IVAS_FLOAT_FIXED #include "ivas_rom_com_fx.h" #endif - /*-----------------------------------------------------------------------* * Local constants *-----------------------------------------------------------------------*/ @@ -61,11 +64,14 @@ #define ISM_MAX_ELEVATION_DIFF_IDX ( ISM_ELEVATION_NBITS - 1 /*zero*/ - 1 /*sign*/ ) #define ISM_MAX_RADIUS_DIFF_IDX ( ISM_RADIUS_NBITS - 1 /*zero*/ - 1 /*sign*/ ) -#define ISM_FEC_MAX 10 -#define ISM_MD_FEC_DIFF 10 -#define ISM_MD_INC_DIFF_CNT_MAX 6 -#define ISM_MD_FEC_CNT_MAX 25 -#define ISM_MD_RAD_FEC_DIFF 1 +#define ISM_FEC_MAX 10 +#define ISM_MD_FEC_DIFF 10 +#define ISM_MD_FEC_DIFF_Q22 41943040 +#define ISM_MD_INC_DIFF_CNT_MAX 6 +#define ISM_MD_FEC_CNT_MAX 25 +#define ISM_MD_RAD_FEC_DIFF 1 +#define ISM_MD_RAD_FEC_DIFF_Q9 ONE_IN_Q9 + #define INTER_OBJECT_PARAM_CHECK ( ( ISM_FEC_MAX / 2 ) - 2 ) /* note: constant must be less than (ISM_FEC_MAX / number of coded parameters) */ @@ -83,7 +89,43 @@ static void encode_radius( BSTR_ENC_HANDLE hBstr, int16_t *last_radius_idx, int1 * * Set metadata of one ISM MD handle *-------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +ivas_error ivas_set_ism_metadata_fx( + ISM_METADATA_HANDLE hIsmMeta, /* o : ISM metadata handle */ + const Word32 azimuth, /* i : azimuth value */ + const Word32 elevation, /* i : elevation */ + const Word16 radius_meta, /* i : radius */ + const Word32 yaw, /* i : yaw */ + const Word32 pitch, /* i : pitch */ + const Word16 non_diegetic_flag /* i : non-diegetic object flag*/ +) +{ + + IF( hIsmMeta == NULL ) + { + return IVAS_ERR_UNEXPECTED_NULL_POINTER; + } + + hIsmMeta->ism_metadata_flag = 1; + move16(); + + /* save read metadata parameters to the internal codec structure */ + hIsmMeta->azimuth_fx = azimuth; + move32(); + hIsmMeta->elevation_fx = elevation; + move32(); + hIsmMeta->radius_fx = radius_meta; + move16(); + hIsmMeta->yaw_fx = yaw; + move16(); + hIsmMeta->pitch_fx = pitch; + move16(); + hIsmMeta->non_diegetic_flag = non_diegetic_flag; + move16(); + return IVAS_ERR_OK; +} +#else ivas_error ivas_set_ism_metadata( ISM_METADATA_HANDLE hIsmMeta, /* o : ISM metadata handle */ const float azimuth, /* i : azimuth value */ @@ -111,7 +153,7 @@ ivas_error ivas_set_ism_metadata( return IVAS_ERR_OK; } - +#endif /*-------------------------------------------------------------------------* * rate_ism_importance() @@ -119,6 +161,63 @@ ivas_error ivas_set_ism_metadata( * Rate importance of particular ISM streams *-------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +static void rate_ism_importance( + const Word16 nchan_transport, /* i : number of transported channels */ + ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */ + SCE_ENC_HANDLE hSCE[], /* i/o: SCE encoder handles */ + const Word16 lowrate_metadata_flag[MAX_NUM_OBJECTS], /* i : low-rate MD flag */ + Word16 ism_imp[] /* o : ISM importance flags */ +) +{ + Word16 ch, ctype; + + FOR( ch = 0; ch < nchan_transport; ch++ ) + { + ctype = hSCE[ch]->hCoreCoder[0]->coder_type_raw; + + IF( hSCE[ch]->hCoreCoder[0]->tcxonly ) + { + IF( EQ_16( hSCE[ch]->hCoreCoder[0]->localVAD, 0 ) ) + { + ctype = INACTIVE; + move16(); + } + ELSE IF( EQ_16( ctype, UNVOICED ) ) + { + ctype = GENERIC; + move16(); + } + } + + test(); + test(); + test(); + IF( ( EQ_16( hIsmMeta[ch]->ism_metadata_flag, 0 ) || EQ_16( lowrate_metadata_flag[ch], 1 ) ) && EQ_16( hSCE[ch]->hCoreCoder[0]->localVAD, 0 ) ) + { + ism_imp[ch] = ISM_NO_META; + move16(); + } + ELSE IF( EQ_16( ctype, INACTIVE ) || EQ_16( ctype, UNVOICED ) ) + { + ism_imp[ch] = ISM_LOW_IMP; + move16(); + } + ELSE IF( EQ_16( ctype, VOICED ) ) + { + ism_imp[ch] = ISM_MEDIUM_IMP; + move16(); + } + ELSE /* GENERIC */ + { + ism_imp[ch] = ISM_HIGH_IMP; + move16(); + } + } + + return; +} +#else static void rate_ism_importance( const int16_t nchan_transport, /* i : number of transported channels */ ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */ @@ -165,7 +264,7 @@ static void rate_ism_importance( return; } - +#endif /*-------------------------------------------------------------------------* * ivas_ism_metadata_enc() @@ -175,42 +274,43 @@ static void rate_ism_importance( #ifdef IVAS_FLOAT_FIXED ivas_error ivas_ism_metadata_enc( - int32_t *ism_total_brate, /* i/o: ISM total bitrate */ - const int16_t nchan_ism, /* i : number of ISM channels */ - const int16_t nchan_transport, /* i : number of transport channels */ - ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */ - SCE_ENC_HANDLE hSCE[], /* i/o: SCE encoder handles */ - BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */ - int16_t nb_bits_metadata[], /* o : number of metadata bits */ - const int16_t vad_flag[], /* i : VAD flag */ - const int16_t ism_mode, /* i : ISM mode */ - const PARAM_ISM_CONFIG_HANDLE hParamIsm, /* i : Param ISM Enc Handle */ - const int16_t ism_extended_metadata_flag, /* i : Extended metadata flag */ - const float lp_noise_CPE, - const int16_t flag_omasa_ener_brate, /* i : less bitrate for objects in OMASA flag */ - int16_t *omasa_stereo_sw_cnt, - const int16_t ini_frame ) + Word32 *ism_total_brate, /* i/o: ISM total bitrate */ + const Word16 nchan_ism, /* i : number of ISM channels */ + const Word16 nchan_transport, /* i : number of transport channels */ + ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */ + SCE_ENC_HANDLE hSCE[], /* i/o: SCE encoder handles */ + BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */ + Word16 nb_bits_metadata[], /* o : number of metadata bits */ + const Word16 vad_flag[], /* i : VAD flag */ + const Word16 ism_mode, /* i : ISM mode */ + const PARAM_ISM_CONFIG_HANDLE hParamIsm, /* i : Param ISM Enc Handle */ + const Word16 ism_extended_metadata_flag, /* i : Extended metadata flag */ + const Word32 lp_noise_CPE_fx, + const Word16 flag_omasa_ener_brate, /* i : less bitrate for objects in OMASA flag */ + Word16 *omasa_stereo_sw_cnt, + const Word16 ini_frame ) { - int16_t i, ch, nb_bits_start = 0; - int16_t flag_abs_azimuth[MAX_NUM_OBJECTS]; - int16_t flag_abs_elevation[MAX_NUM_OBJECTS]; - int16_t idx_angle1_abs = 0; - int16_t idx_angle2_abs = 0; - int16_t flag_abs_yaw[MAX_NUM_OBJECTS]; - int16_t flag_abs_pitch[MAX_NUM_OBJECTS]; - int16_t idx_radius_abs = 0, flag_abs_radius[MAX_NUM_OBJECTS]; - float valQ; -#ifdef IVAS_FLOAT_FIXED + Word16 i, ch, nb_bits_start = 0; + move16(); + Word16 flag_abs_azimuth[MAX_NUM_OBJECTS]; + Word16 flag_abs_elevation[MAX_NUM_OBJECTS]; + Word16 idx_angle1_abs = 0; + move16(); + Word16 idx_angle2_abs = 0; + move16(); + Word16 flag_abs_yaw[MAX_NUM_OBJECTS]; + Word16 flag_abs_pitch[MAX_NUM_OBJECTS]; + Word16 idx_radius_abs = 0, flag_abs_radius[MAX_NUM_OBJECTS]; + move16(); Word32 valQ_fx; -#endif ISM_METADATA_HANDLE hIsmMetaData; int32_t element_brate[MAX_NUM_OBJECTS], total_brate[MAX_NUM_OBJECTS]; - int16_t ism_metadata_flag_global; - int16_t non_diegetic_flag_global; - int16_t ism_imp[MAX_NUM_OBJECTS]; - int16_t null_metadata_flag[MAX_NUM_OBJECTS]; - int16_t lowrate_metadata_flag[MAX_NUM_OBJECTS]; - int16_t nbands, nblocks; + Word16 ism_metadata_flag_global; + Word16 non_diegetic_flag_global; + Word16 ism_imp[MAX_NUM_OBJECTS]; + Word16 null_metadata_flag[MAX_NUM_OBJECTS]; + Word16 lowrate_metadata_flag[MAX_NUM_OBJECTS]; + Word16 nbands, nblocks; ivas_error error; error = IVAS_ERR_OK; @@ -219,6 +319,8 @@ ivas_error ivas_ism_metadata_enc( /* initialization */ ism_metadata_flag_global = 0; non_diegetic_flag_global = 0; + move16(); + move16(); set_s( nb_bits_metadata, 0, nchan_transport ); set_s( flag_abs_azimuth, 0, nchan_ism ); set_s( flag_abs_elevation, 0, nchan_ism ); @@ -228,69 +330,82 @@ ivas_error ivas_ism_metadata_enc( set_s( null_metadata_flag, 0, nchan_ism ); set_s( lowrate_metadata_flag, 0, nchan_ism ); - if ( ism_mode == ISM_MASA_MODE_DISC || ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) + test(); + + IF( EQ_16( ism_mode, ISM_MASA_MODE_DISC ) || EQ_16( ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) { /*----------------------------------------------------------------* * Rate importance of particular ISM streams in combined format coding *----------------------------------------------------------------*/ - - ivas_set_ism_importance_interformat( *ism_total_brate, nchan_transport, hIsmMeta, hSCE, lp_noise_CPE, ism_imp ); + ivas_set_ism_importance_interformat_fx( *ism_total_brate, nchan_transport, hIsmMeta, hSCE, lp_noise_CPE_fx, ism_imp ); } - else + ELSE { /*----------------------------------------------------------------* * Set Metadata presence / importance flag *----------------------------------------------------------------*/ - for ( ch = 0; ch < nchan_ism; ch++ ) + FOR( ch = 0; ch < nchan_ism; ch++ ) { - if ( ism_mode == ISM_MODE_PARAM ) + test(); + test(); + IF( EQ_16( ism_mode, ISM_MODE_PARAM ) ) { hIsmMeta[ch]->ism_metadata_flag = 1; + move16(); } - else if ( ism_mode == ISM_MODE_DISC || ism_mode == ISM_MASA_MODE_DISC || ism_mode == ISM_SBA_MODE_DISC ) + ELSE IF( EQ_16( ism_mode, ISM_MODE_DISC ) || EQ_16( ism_mode, ISM_MASA_MODE_DISC ) || EQ_16( ism_mode, ISM_SBA_MODE_DISC ) ) { null_metadata_flag[ch] = !hIsmMeta[ch]->ism_metadata_flag; + move16(); - if ( hIsmMeta[ch]->ism_metadata_flag == 1 ) + IF( EQ_16( hIsmMeta[ch]->ism_metadata_flag, 1 ) ) { - if ( ism_mode != ISM_SBA_MODE_DISC ) + IF( NE_16( ism_mode, ISM_SBA_MODE_DISC ) ) { /* In case of low level noise for low bitrate inactive frames, do not sent metadata */ - hIsmMeta[ch]->ism_metadata_flag = vad_flag[ch] || hSCE[ch]->hCoreCoder[0]->lp_noise > 10 || hSCE[ch]->hCoreCoder[0]->tcxonly; + hIsmMeta[ch]->ism_metadata_flag = vad_flag[ch] || GT_16( hSCE[ch]->hCoreCoder[0]->lp_noise_fx, 2560 /*10 Q8*/ ) || hSCE[ch]->hCoreCoder[0]->tcxonly; + move16(); } /* 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( 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 ) || ( fabsf( hIsmMeta[ch]->radius - hIsmMeta[ch]->last_true_radius ) > ISM_MD_RAD_FEC_DIFF ) ) + test(); + test(); + IF( ( GT_32( L_abs( L_sub( hIsmMeta[ch]->azimuth_fx, hIsmMeta[ch]->last_true_azimuth_fx ) ), ISM_MD_FEC_DIFF_Q22 ) ) || + ( GT_32( L_abs( L_sub( hIsmMeta[ch]->elevation_fx, hIsmMeta[ch]->last_true_elevation_fx ) ), ISM_MD_FEC_DIFF_Q22 ) ) || ( GT_16( abs_s( sub( hIsmMeta[ch]->radius_fx, hIsmMeta[ch]->last_true_radius_fx ) ), ISM_MD_RAD_FEC_DIFF_Q9 ) ) ) { lowrate_metadata_flag[ch] = 1; + move16(); hIsmMeta[ch]->ism_md_inc_diff_cnt = 0; + move16(); } - else if ( hIsmMeta[ch]->ism_md_inc_diff_cnt < ISM_MD_INC_DIFF_CNT_MAX ) + ELSE IF( LT_16( hIsmMeta[ch]->ism_md_inc_diff_cnt, ISM_MD_INC_DIFF_CNT_MAX ) ) { lowrate_metadata_flag[ch] = 1; - - if ( hIsmMeta[ch]->ism_md_inc_diff_cnt % 2 == 0 ) + move16(); + IF( hIsmMeta[ch]->ism_md_inc_diff_cnt % 2 == 0 ) { hIsmMeta[ch]->position_angle.angle1_diff_cnt = ISM_FEC_MAX; + move16(); } - else + ELSE { hIsmMeta[ch]->position_angle.angle2_diff_cnt = ISM_FEC_MAX; + move16(); } } - else if ( hIsmMeta[ch]->ism_md_fec_cnt_enc == ISM_MD_FEC_CNT_MAX ) + ELSE IF( EQ_16( hIsmMeta[ch]->ism_md_fec_cnt_enc, ISM_MD_FEC_CNT_MAX ) ) { lowrate_metadata_flag[ch] = 1; - + move16(); hIsmMeta[ch]->position_angle.angle1_diff_cnt = ISM_FEC_MAX; + move16(); } } } @@ -301,7 +416,7 @@ ivas_error ivas_ism_metadata_enc( * Rate importance of particular ISM streams *----------------------------------------------------------------*/ - if ( ism_mode != ISM_SBA_MODE_DISC ) + IF( NE_16( ism_mode, ISM_SBA_MODE_DISC ) ) { rate_ism_importance( nchan_transport, hIsmMeta, hSCE, lowrate_metadata_flag, ism_imp ); } @@ -310,18 +425,19 @@ ivas_error ivas_ism_metadata_enc( /*----------------------------------------------------------------* * Write ISM common signaling *----------------------------------------------------------------*/ - - if ( ism_mode != ISM_MASA_MODE_DISC && ism_mode != ISM_MASA_MODE_MASA_ONE_OBJ && ism_mode != ISM_SBA_MODE_DISC ) + test(); + test(); + IF( NE_16( ism_mode, ISM_MASA_MODE_DISC ) && NE_16( ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) && NE_16( ism_mode, ISM_SBA_MODE_DISC ) ) { /* write number of objects - unary coding */ - for ( ch = 1; ch < nchan_ism; ch++ ) + FOR( ch = 1; ch < nchan_ism; ch++ ) { push_indice( hBstr, IND_ISM_NUM_OBJECTS, 1, 1 ); } push_indice( hBstr, IND_ISM_NUM_OBJECTS, 0, 1 ); } - for ( ch = 0; ch < nchan_ism; ch++ ) + FOR( ch = 0; ch < nchan_ism; ch++ ) { ism_metadata_flag_global |= hIsmMeta[ch]->ism_metadata_flag; ism_metadata_flag_global |= lowrate_metadata_flag[ch]; @@ -329,50 +445,56 @@ ivas_error ivas_ism_metadata_enc( } /* write extended metadata presence flag */ - if ( ( ism_mode == ISM_MODE_DISC || ism_mode == ISM_SBA_MODE_DISC ) && *ism_total_brate >= ISM_EXTENDED_METADATA_BRATE ) + test(); + test(); + IF( ( EQ_16( ism_mode, ISM_MODE_DISC ) || EQ_16( ism_mode, ISM_SBA_MODE_DISC ) ) && GE_32( *ism_total_brate, ISM_EXTENDED_METADATA_BRATE ) ) { push_indice( hBstr, IND_ISM_EXTENDED_FLAG, ism_extended_metadata_flag, ISM_EXTENDED_METADATA_BITS ); /* Write global non-diegetic object flag */ - if ( ism_extended_metadata_flag ) + IF( ism_extended_metadata_flag ) { push_indice( hBstr, IND_ISM_EXTENDED_NDP_FLAG, non_diegetic_flag_global, ISM_EXTENDED_METADATA_BITS ); } } /* write ISM metadata flag (one per object) */ - for ( ch = 0; ch < nchan_transport; ch++ ) + FOR( ch = 0; ch < nchan_transport; ch++ ) { - if ( ism_mode == ISM_MASA_MODE_DISC || ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) + test(); + IF( EQ_16( ism_mode, ISM_MASA_MODE_DISC ) || EQ_16( ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) { /* flags will be written in ivas_masa_encode() */ hIsmMeta[ch]->ism_imp = ism_imp[ch]; + move16(); hIsmMeta[ch]->ism_md_null_flag = null_metadata_flag[ch]; + move16(); hIsmMeta[ch]->ism_md_lowrate_flag = lowrate_metadata_flag[ch]; + move16(); } - else + ELSE { - if ( null_metadata_flag[ch] ) + IF( null_metadata_flag[ch] ) { /* signal NULL metadata frame */ push_indice( hBstr, IND_ISM_MD_NULL_FLAG, 1, ISM_METADATA_MD_FLAG_BITS ); /* write the ISM class to ISM_NO_META and again the true ISM class */ - if ( ism_mode != ISM_SBA_MODE_DISC ) + IF( NE_16( ism_mode, ISM_SBA_MODE_DISC ) ) { push_indice( hBstr, IND_ISM_METADATA_FLAG, ISM_NO_META, ISM_METADATA_FLAG_BITS ); push_indice( hBstr, IND_ISM_MD_INACTIVE_FLAG, ism_imp[ch], ISM_METADATA_FLAG_BITS ); } - else + ELSE { push_indice( hBstr, IND_ISM_METADATA_FLAG, ISM_NO_META, 1 ); } } - else if ( ism_mode != ISM_SBA_MODE_DISC ) + ELSE IF( NE_16( ism_mode, ISM_SBA_MODE_DISC ) ) { push_indice( hBstr, IND_ISM_METADATA_FLAG, ism_imp[ch], ISM_METADATA_FLAG_BITS ); - if ( ism_imp[ch] == ISM_NO_META ) + IF( EQ_16( ism_imp[ch], ISM_NO_META ) ) { /* signal low-rate ISM_NO_META frame */ push_indice( hBstr, IND_ISM_MD_NULL_FLAG, 0, ISM_METADATA_MD_FLAG_BITS ); @@ -381,7 +503,7 @@ ivas_error ivas_ism_metadata_enc( push_indice( hBstr, IND_ISM_MD_INACTIVE_FLAG, lowrate_metadata_flag[ch], ISM_METADATA_INACTIVE_FLAG_BITS ); } } - else /*ism_mode == ISM_SBA_MODE_DISC*/ + ELSE /*ism_mode == ISM_SBA_MODE_DISC*/ { /* all objects are considered active*/ push_indice( hBstr, IND_ISM_METADATA_FLAG, 1, 1 ); @@ -390,129 +512,134 @@ ivas_error ivas_ism_metadata_enc( } - if ( ism_metadata_flag_global ) + IF( ism_metadata_flag_global ) { /*----------------------------------------------------------------* * Metadata quantization and coding, loop over all objects *----------------------------------------------------------------*/ - int16_t total_bits_metadata = 0; - int16_t bits_metadata_ism = 0; - int16_t nb_bits_objcod_written; + Word16 total_bits_metadata = 0; + move16(); + Word16 bits_metadata_ism = 0; + move16(); + Word16 nb_bits_objcod_written; - if ( ism_mode == ISM_MODE_PARAM ) + IF( EQ_16( ism_mode, ISM_MODE_PARAM ) ) { nb_bits_start = hBstr->nb_bits_tot; + move16(); } - for ( ch = 0; ch < nchan_ism; ch++ ) + FOR( ch = 0; ch < nchan_ism; ch++ ) { hIsmMetaData = hIsmMeta[ch]; - if ( ism_mode == ISM_MODE_DISC || ism_mode == ISM_MASA_MODE_DISC || ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || ism_mode == ISM_SBA_MODE_DISC ) + test(); + test(); + test(); + IF( EQ_16( ism_mode, ISM_MODE_DISC ) || EQ_16( ism_mode, ISM_MASA_MODE_DISC ) || EQ_16( ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) || EQ_16( ism_mode, ISM_SBA_MODE_DISC ) ) { nb_bits_start = hBstr->nb_bits_tot; + move16(); } - - if ( hIsmMeta[ch]->ism_metadata_flag || lowrate_metadata_flag[ch] ) + test(); + IF( hIsmMeta[ch]->ism_metadata_flag || lowrate_metadata_flag[ch] ) { /*----------------------------------------------------------------* * Quantize and encode azimuth and elevation *----------------------------------------------------------------*/ - - if ( ism_extended_metadata_flag && non_diegetic_flag_global ) + test(); + IF( ism_extended_metadata_flag && non_diegetic_flag_global ) { /* Write non-diegetic flag for each object */ push_indice( hBstr, IND_ISM_NDP_FLAG, hIsmMeta[ch]->non_diegetic_flag, ISM_METADATA_IS_NDP_BITS ); } - - if ( hIsmMeta[ch]->non_diegetic_flag && ism_extended_metadata_flag ) + test(); + IF( hIsmMeta[ch]->non_diegetic_flag && ism_extended_metadata_flag ) { /* Map azimuth to panning range [-90:90] */ - if ( hIsmMetaData->azimuth > 90.0f ) + IF( GT_32( hIsmMetaData->azimuth_fx, 377487360 /*90.0f Q22*/ ) ) { - hIsmMetaData->azimuth = 180.0f - hIsmMetaData->azimuth; + hIsmMetaData->azimuth_fx = L_sub( 754974720 /*180.0f Q22*/, hIsmMetaData->azimuth_fx ); + move32(); } - if ( hIsmMetaData->azimuth < -90.0f ) + IF( LT_32( hIsmMetaData->azimuth_fx, L_negate( 377487360 ) ) ) { - hIsmMetaData->azimuth = -180.0f - hIsmMetaData->azimuth; + hIsmMetaData->azimuth_fx = L_sub( L_negate( 754974720 ), hIsmMetaData->azimuth_fx ); + move32(); } #ifdef IVAS_FLOAT_FIXED - /*===============================flt-2-fix======================================*/ - hIsmMetaData->azimuth_fx = floatToFixed( hIsmMetaData->azimuth, Q22 ); - /*===============================flt-2-fix======================================*/ idx_angle1_abs = ism_quant_meta_fx( hIsmMetaData->azimuth_fx, &valQ_fx, ism_azimuth_borders_fx, ISM_Q_STEP_FX, ISM_Q_STEP_BORDER_FX, 1 << ISM_AZIMUTH_NBITS ); - /*===============================fix-2-flt======================================*/ - valQ = fixedToFloat( valQ_fx, Q22 ); - /*===============================fix-2-flt======================================*/ #else idx_angle1_abs = ism_quant_meta( hIsmMetaData->azimuth, &valQ, ism_azimuth_borders, ISM_Q_STEP, ISM_Q_STEP_BORDER, 1 << ISM_AZIMUTH_NBITS ); #endif encode_angle_indices( hBstr, &( hIsmMetaData->position_angle ), hIsmMetaData->last_ism_metadata_flag, hSCE[0]->hCoreCoder[0]->ini_frame, idx_angle1_abs, 0, &flag_abs_azimuth[ch], NULL ); } - else + ELSE { - if ( ism_mode == ISM_MODE_DISC || ism_mode == ISM_MASA_MODE_DISC || ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || ism_mode == ISM_SBA_MODE_DISC ) + test(); + test(); + test(); + IF( EQ_16( ism_mode, ISM_MODE_DISC ) || EQ_16( ism_mode, ISM_MASA_MODE_DISC ) || EQ_16( ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) || EQ_16( ism_mode, ISM_SBA_MODE_DISC ) ) { #ifdef IVAS_FLOAT_FIXED - /*===============================flt-2-fix======================================*/ - hIsmMetaData->azimuth_fx = floatToFixed( hIsmMetaData->azimuth, Q22 ); - hIsmMetaData->elevation_fx = floatToFixed( hIsmMetaData->elevation, Q22 ); - /*===============================flt-2-fix======================================*/ idx_angle1_abs = ism_quant_meta_fx( hIsmMetaData->azimuth_fx, &valQ_fx, ism_azimuth_borders_fx, ISM_Q_STEP_FX, ISM_Q_STEP_BORDER_FX, 1 << ISM_AZIMUTH_NBITS ); idx_angle2_abs = ism_quant_meta_fx( hIsmMetaData->elevation_fx, &valQ_fx, ism_elevation_borders_fx, ISM_Q_STEP_FX, ISM_Q_STEP_BORDER_FX, 1 << ISM_ELEVATION_NBITS ); - /*===============================fix-2-flt======================================*/ - valQ = fixedToFloat( valQ_fx, Q22 ); - /*===============================fix-2-flt======================================*/ + // valQ = fixedToFloat( valQ_fx, Q22 ); #else idx_angle1_abs = ism_quant_meta( hIsmMetaData->azimuth, &valQ, ism_azimuth_borders, ISM_Q_STEP, ISM_Q_STEP_BORDER, 1 << ISM_AZIMUTH_NBITS ); idx_angle2_abs = ism_quant_meta( hIsmMetaData->elevation, &valQ, ism_elevation_borders, ISM_Q_STEP, ISM_Q_STEP_BORDER, 1 << ISM_ELEVATION_NBITS ); #endif } - else /* ISM_MODE_PARAM */ + ELSE /* ISM_MODE_PARAM */ { idx_angle1_abs = hParamIsm->azi_index[ch]; + move16(); idx_angle2_abs = hParamIsm->ele_index[ch]; + move16(); } encode_angle_indices( hBstr, &( hIsmMetaData->position_angle ), hIsmMetaData->last_ism_metadata_flag, ini_frame, idx_angle1_abs, idx_angle2_abs, &flag_abs_azimuth[ch], &flag_abs_elevation[ch] ); - /*----------------------------------------------------------------* * Quantize and encode radius, yaw, and pitch *----------------------------------------------------------------*/ - if ( ( ism_mode == ISM_MODE_DISC || ism_mode == ISM_SBA_MODE_DISC ) && ism_extended_metadata_flag ) + test(); + test(); + IF( ( EQ_16( ism_mode, ISM_MODE_DISC ) || EQ_16( ism_mode, ISM_SBA_MODE_DISC ) ) && ism_extended_metadata_flag ) { #ifdef IVAS_FLOAT_FIXED - /*===============================flt-2-fix======================================*/ - hIsmMetaData->yaw_fx = floatToFixed( hIsmMetaData->yaw, Q22 ); - hIsmMetaData->pitch_fx = floatToFixed( hIsmMetaData->pitch, Q22 ); - /*===============================flt-2-fix======================================*/ idx_angle1_abs = ism_quant_meta_fx( hIsmMetaData->yaw_fx, &valQ_fx, ism_azimuth_borders_fx, ISM_Q_STEP_FX, ISM_Q_STEP_BORDER_FX, 1 << ISM_AZIMUTH_NBITS ); idx_angle2_abs = ism_quant_meta_fx( hIsmMetaData->pitch_fx, &valQ_fx, ism_elevation_borders_fx, ISM_Q_STEP_FX, ISM_Q_STEP_BORDER_FX, 1 << ISM_ELEVATION_NBITS ); - /*===============================fix-2-flt======================================*/ - valQ = fixedToFloat( valQ_fx, Q22 ); - /*===============================fix-2-flt======================================*/ + Word16 valQ_fx_tmp = extract_h( valQ_fx ); // 22 - 16 = 6 + idx_radius_abs = usquant_fx( hIsmMetaData->radius_fx, &valQ_fx_tmp, ISM_RADIUS_MIN_Q9, ISM_RADIUS_DELTA_Q8, 1 << ISM_RADIUS_NBITS ); + valQ_fx = L_shr( L_deposit_h( valQ_fx_tmp ), 3 ); // Q22 + // valQ = fixedToFloat( valQ_fx, Q22 ); #else 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 ); -#endif idx_radius_abs = usquant( hIsmMetaData->radius, &valQ, ISM_RADIUS_MIN, ISM_RADIUS_DELTA, 1 << ISM_RADIUS_NBITS ); - +#endif encode_angle_indices( hBstr, &( hIsmMetaData->orientation_angle ), hIsmMetaData->last_ism_metadata_flag, 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] ); } } /* save number of metadata bits written */ - if ( ism_mode == ISM_MODE_DISC || ism_mode == ISM_MASA_MODE_DISC || ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || ism_mode == ISM_SBA_MODE_DISC ) + test(); + test(); + test(); + IF( EQ_16( ism_mode, ISM_MODE_DISC ) || EQ_16( ism_mode, ISM_MASA_MODE_DISC ) || EQ_16( ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) || EQ_16( ism_mode, ISM_SBA_MODE_DISC ) ) { nb_bits_metadata[ch] = hBstr->nb_bits_tot - nb_bits_start; } /* Updates */ - hIsmMeta[ch]->last_true_azimuth = hIsmMeta[ch]->azimuth; - hIsmMeta[ch]->last_true_elevation = hIsmMeta[ch]->elevation; - hIsmMeta[ch]->last_true_radius = hIsmMeta[ch]->radius; + hIsmMeta[ch]->last_true_azimuth_fx = hIsmMeta[ch]->azimuth_fx; + move32(); + hIsmMeta[ch]->last_true_elevation_fx = hIsmMeta[ch]->elevation_fx; + move32(); + hIsmMeta[ch]->last_true_radius_fx = hIsmMeta[ch]->radius_fx; + move16(); } } @@ -522,61 +649,64 @@ ivas_error ivas_ism_metadata_enc( *----------------------------------------------------------------*/ i = 0; - while ( i == 0 || i < nchan_ism / INTER_OBJECT_PARAM_CHECK ) + WHILE( i == 0 || i < nchan_ism / INTER_OBJECT_PARAM_CHECK ) { - int16_t num, abs_num, abs_first, abs_next, pos_zero; - int16_t abs_matrice[INTER_OBJECT_PARAM_CHECK * ISM_NUM_PARAM]; + Word16 num, abs_num, abs_first, abs_next, pos_zero; + Word16 abs_matrice[INTER_OBJECT_PARAM_CHECK * ISM_NUM_PARAM]; num = min( INTER_OBJECT_PARAM_CHECK, nchan_ism - i * INTER_OBJECT_PARAM_CHECK ); i++; set_s( abs_matrice, 0, INTER_OBJECT_PARAM_CHECK * ISM_NUM_PARAM ); - for ( ch = 0; ch < num; ch++ ) + FOR( ch = 0; ch < num; ch++ ) { - if ( flag_abs_azimuth[ch] == 1 ) + IF( EQ_16( flag_abs_azimuth[ch], 1 ) ) { abs_matrice[ch * ISM_NUM_PARAM] = 1; + move16(); } - if ( flag_abs_elevation[ch] == 1 ) + IF( EQ_16( flag_abs_elevation[ch], 1 ) ) { abs_matrice[ch * ISM_NUM_PARAM + 1] = 1; + move16(); } } abs_num = sum_s( abs_matrice, INTER_OBJECT_PARAM_CHECK * ISM_NUM_PARAM ); abs_first = 0; - while ( abs_num > 1 ) + move16(); + WHILE( GT_16( abs_num, 1 ) ) { /* find first "1" entry */ - while ( abs_matrice[abs_first] == 0 ) + WHILE( abs_matrice[abs_first] == 0 ) { abs_first++; } /* find next "1" entry */ abs_next = abs_first + 1; - while ( abs_matrice[abs_next] == 0 ) + WHILE( abs_matrice[abs_next] == 0 ) { abs_next++; } /* find "0" position */ pos_zero = 0; - while ( abs_matrice[pos_zero] == 1 ) + WHILE( abs_matrice[pos_zero] == 1 ) { pos_zero++; } ch = abs_next / ISM_NUM_PARAM; - if ( abs_next % ISM_NUM_PARAM == 0 ) + IF( abs_next % ISM_NUM_PARAM == 0 ) { hIsmMeta[ch]->position_angle.angle1_diff_cnt = abs_num - 1; } - if ( abs_next % ISM_NUM_PARAM == 1 ) + IF( abs_next % ISM_NUM_PARAM == 1 ) { hIsmMeta[ch]->position_angle.angle2_diff_cnt = abs_num - 1; /*hIsmMeta[ch]->elevation_diff_cnt = min( hIsmMeta[ch]->elevation_diff_cnt, ISM_FEC_MAX );*/ @@ -587,22 +717,23 @@ ivas_error ivas_ism_metadata_enc( } } - if ( ism_mode == ISM_SBA_MODE_DISC ) + IF( EQ_16( ism_mode, ISM_SBA_MODE_DISC ) ) { - int16_t md_diff_flag[MAX_NUM_OBJECTS]; + Word16 md_diff_flag[MAX_NUM_OBJECTS]; set_s( md_diff_flag, 1, nchan_ism ); - for ( ch = 0; ch < nchan_ism; ch++ ) + FOR( ch = 0; ch < nchan_ism; ch++ ) { hIsmMeta[ch]->last_ism_metadata_flag = hIsmMeta[ch]->ism_metadata_flag; - if ( hIsmMeta[ch]->ism_metadata_flag == 0 ) + IF( hIsmMeta[ch]->ism_metadata_flag == 0 ) { hIsmMeta[ch]->ism_md_fec_cnt_enc++; } - else + ELSE { hIsmMeta[ch]->ism_md_fec_cnt_enc = 0; + move16(); } 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 ); @@ -613,18 +744,18 @@ ivas_error ivas_ism_metadata_enc( pop_wmops(); return error; } - if ( ism_mode == ISM_MODE_PARAM ) + IF( EQ_16( ism_mode, ISM_MODE_PARAM ) ) { /* Keep the metdata transmission as is during active parts */ /* But send the flag with 1 bit */ push_next_indice( hBstr, hParamIsm->flag_noisy_speech, 1 ); /* Loop over multiwave to write the object indices into bitstream */ - for ( ch = 0; ch < MAX_PARAM_ISM_WAVE; ch++ ) + FOR( ch = 0; ch < MAX_PARAM_ISM_WAVE; ch++ ) { - for ( nbands = 0; nbands < hParamIsm->nbands; nbands++ ) + FOR( nbands = 0; nbands < hParamIsm->nbands; nbands++ ) { - for ( nblocks = 0; nblocks < hParamIsm->nblocks[nbands]; nblocks++ ) + FOR( nblocks = 0; nblocks < hParamIsm->nblocks[nbands]; nblocks++ ) { push_next_indice( hBstr, hParamIsm->obj_indices[nbands][nblocks][ch], PARAM_ISM_OBJ_IND_NBITS ); } @@ -632,29 +763,29 @@ ivas_error ivas_ism_metadata_enc( } /* Loop over bands to write the power ratio's indices into bitstream */ - for ( nbands = 0; nbands < hParamIsm->nbands; nbands++ ) + FOR( nbands = 0; nbands < hParamIsm->nbands; nbands++ ) { - for ( nblocks = 0; nblocks < hParamIsm->nblocks[nbands]; nblocks++ ) + FOR( nblocks = 0; nblocks < hParamIsm->nblocks[nbands]; nblocks++ ) { push_next_indice( hBstr, hParamIsm->power_ratios_idx[nbands][nblocks], PARAM_ISM_POW_RATIO_NBITS ); } } /* total metadata bits */ - total_bits_metadata = hBstr->nb_bits_tot - nb_bits_start; + total_bits_metadata = sub( hBstr->nb_bits_tot, nb_bits_start ); /* bits per ISM*/ - bits_metadata_ism = (int16_t) ( total_bits_metadata / nchan_transport ); + bits_metadata_ism = (Word16) ( total_bits_metadata / nchan_transport ); /* Divide the metadata bits into n_Isms*/ nb_bits_objcod_written = 0; - for ( ch = 0; ch < nchan_transport; ch++ ) + FOR( ch = 0; ch < nchan_transport; ch++ ) { - if ( ch == nchan_transport - 1 ) + IF( EQ_16( ch, sub( nchan_transport, 1 ) ) ) { nb_bits_metadata[ch] = total_bits_metadata - nb_bits_objcod_written; } - else + ELSE { nb_bits_metadata[ch] = bits_metadata_ism; nb_bits_objcod_written += bits_metadata_ism; @@ -662,7 +793,7 @@ ivas_error ivas_ism_metadata_enc( } } } - else if ( ism_mode == ISM_SBA_MODE_DISC ) + ELSE IF( EQ_16( ism_mode, ISM_SBA_MODE_DISC ) ) { pop_wmops(); return error; @@ -671,12 +802,12 @@ ivas_error ivas_ism_metadata_enc( /*----------------------------------------------------------------* * Take into account the combined format bit-budget distribution *----------------------------------------------------------------*/ - - if ( ism_mode == ISM_MASA_MODE_DISC || ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) + test(); + IF( EQ_16( ism_mode, ISM_MASA_MODE_DISC ) || EQ_16( ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) { - int16_t bits_ism, bits_element[MAX_NUM_OBJECTS]; - int16_t brate_limit_flag; - int32_t ism_total_brate_ref; + Word16 bits_ism, bits_element[MAX_NUM_OBJECTS]; + Word16 brate_limit_flag; + Word32 ism_total_brate_ref; ism_total_brate_ref = *ism_total_brate; #ifndef IVAS_FLOAT_FIXED brate_limit_flag = calculate_brate_limit_flag( ism_imp, nchan_ism ); @@ -684,44 +815,44 @@ ivas_error ivas_ism_metadata_enc( brate_limit_flag = calculate_brate_limit_flag_fx( ism_imp, nchan_ism ); #endif - bits_ism = (int16_t) ( *ism_total_brate / FRAMES_PER_SEC ); + bits_ism = (Word16) ( *ism_total_brate / FRAMES_PER_SEC ); set_s( bits_element, bits_ism / nchan_ism, nchan_ism ); bits_element[nchan_ism - 1] += bits_ism % nchan_ism; bitbudget_to_brate( bits_element, element_brate, nchan_ism ); *ism_total_brate = 0; - for ( ch = 0; ch < nchan_ism; ch++ ) + FOR( ch = 0; ch < nchan_ism; ch++ ) { #ifndef IVAS_FLOAT_FIXED *ism_total_brate += ivas_interformat_brate( ism_mode, nchan_ism, hSCE[ch]->element_brate, ism_imp[ch], brate_limit_flag ); #else *ism_total_brate = L_add( *ism_total_brate, ivas_interformat_brate_fx( ism_mode, nchan_ism, hSCE[ch]->element_brate, ism_imp[ch], brate_limit_flag ) ); - move32(); #endif - - if ( ism_imp[ch] > 1 && flag_omasa_ener_brate == 1 && brate_limit_flag >= 0 ) + IF( GT_16( ism_imp[ch], 1 ) && EQ_16( flag_omasa_ener_brate, 1 ) && brate_limit_flag >= 0 ) { *ism_total_brate -= ADJUST_ISM_BRATE_NEG; } - if ( brate_limit_flag == -1 && ism_imp[ch] >= 1 && nchan_ism >= 3 && ( ism_total_brate_ref - *ism_total_brate > IVAS_48k ) ) + IF( EQ_16( brate_limit_flag, -1 ) && GE_16( ism_imp[ch], 1 ) && GE_16( nchan_ism, 3 ) && ( GT_32( L_sub( ism_total_brate_ref, *ism_total_brate ), IVAS_48k ) ) ) { *ism_total_brate += ADJUST_ISM_BRATE_POS; } } ism_metadata_flag_global = 1; + move16(); - if ( ism_mode == ISM_MASA_MODE_DISC ) + IF( EQ_16( ism_mode, ISM_MASA_MODE_DISC ) ) { brate_limit_flag = 0; - for ( int16_t n = 0; n < nchan_ism; n++ ) + FOR( Word16 n = 0; n < nchan_ism; n++ ) { brate_limit_flag += ism_imp[n]; } - if ( brate_limit_flag >= nchan_ism * ISM_HIGH_IMP - 2 ) + IF( brate_limit_flag >= nchan_ism * ISM_HIGH_IMP - 2 ) { *omasa_stereo_sw_cnt = OMASA_STEREO_SW_CNT_MAX; + move16(); } } } @@ -730,62 +861,69 @@ ivas_error ivas_ism_metadata_enc( * Configuration and decision about bitrates per channel *----------------------------------------------------------------*/ - if ( ism_mode == ISM_MASA_MODE_DISC || ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) + IF( EQ_16( ism_mode, ISM_MASA_MODE_DISC ) || EQ_16( ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) { - if ( ( error = ivas_ism_config( *ism_total_brate, nchan_transport, nchan_ism, hIsmMeta, ism_extended_metadata_flag, null_metadata_flag, ism_imp, element_brate, total_brate, nb_bits_metadata, 1 ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_ism_config( *ism_total_brate, nchan_transport, nchan_ism, hIsmMeta, ism_extended_metadata_flag, null_metadata_flag, ism_imp, element_brate, total_brate, nb_bits_metadata, 1 ) ) != IVAS_ERR_OK ) { return error; } } - else + ELSE { - if ( ( error = ivas_ism_config( *ism_total_brate, nchan_transport, nchan_ism, hIsmMeta, ism_extended_metadata_flag, null_metadata_flag, ism_imp, element_brate, total_brate, nb_bits_metadata, 0 ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_ism_config( *ism_total_brate, nchan_transport, nchan_ism, hIsmMeta, ism_extended_metadata_flag, null_metadata_flag, ism_imp, element_brate, total_brate, nb_bits_metadata, 0 ) ) != IVAS_ERR_OK ) { return error; } } - for ( ch = 0; ch < nchan_ism; ch++ ) + FOR( ch = 0; ch < nchan_ism; ch++ ) { hIsmMeta[ch]->last_ism_metadata_flag = hIsmMeta[ch]->ism_metadata_flag; + move16(); - if ( hIsmMeta[ch]->ism_metadata_flag == 0 ) + IF( hIsmMeta[ch]->ism_metadata_flag == 0 ) { hIsmMeta[ch]->ism_md_fec_cnt_enc++; } - else + ELSE { hIsmMeta[ch]->ism_md_fec_cnt_enc = 0; + move16(); } 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 ); + hIsmMeta[ch]->ism_md_inc_diff_cnt = s_min( hIsmMeta[ch]->ism_md_inc_diff_cnt, ISM_MD_INC_DIFF_CNT_MAX ); } - for ( ch = 0; ch < nchan_transport; ch++ ) + FOR( ch = 0; ch < nchan_transport; ch++ ) { hSCE[ch]->hCoreCoder[0]->low_rate_mode = 0; - if ( ism_mode == ISM_MODE_DISC ) + move16(); + IF( EQ_16( ism_mode, ISM_MODE_DISC ) ) { - if ( ism_imp[ch] == ISM_NO_META && ( ( total_brate[ch] < ACELP_8k00 && element_brate[ch] < SCE_CORE_16k_LOW_LIMIT ) || - ( total_brate[ch] <= ACELP_16k_LOW_LIMIT && element_brate[ch] >= SCE_CORE_16k_LOW_LIMIT ) ) ) + IF( EQ_16( ism_imp[ch], ISM_NO_META ) && ( ( LT_32( total_brate[ch], ACELP_8k00 ) && LT_32( element_brate[ch], SCE_CORE_16k_LOW_LIMIT ) ) || + ( LE_32( total_brate[ch], ACELP_16k_LOW_LIMIT ) && GE_32( element_brate[ch], SCE_CORE_16k_LOW_LIMIT ) ) ) ) { hSCE[ch]->hCoreCoder[0]->low_rate_mode = 1; + move16(); } hSCE[ch]->element_brate = element_brate[ch]; + move32(); } - else if ( ism_mode == ISM_MASA_MODE_DISC || ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) + ELSE IF( EQ_16( ism_mode, ISM_MASA_MODE_DISC ) || EQ_16( ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) { - if ( ism_imp[ch] == ISM_INACTIVE_IMP ) + IF( EQ_16( ism_imp[ch], ISM_INACTIVE_IMP ) ) { hSCE[ch]->hCoreCoder[0]->low_rate_mode = 1; + move16(); } } hSCE[ch]->hCoreCoder[0]->total_brate = total_brate[ch]; + move32(); /* write metadata only in active frames */ - if ( hSCE[0]->hCoreCoder[0]->core_brate > SID_2k40 ) + IF( GT_32( hSCE[0]->hCoreCoder[0]->core_brate, SID_2k40 ) ) { reset_indices_enc( hSCE[ch]->hMetaData, hSCE[ch]->hMetaData->nb_ind_tot ); } @@ -1374,24 +1512,25 @@ ivas_error ivas_ism_metadata_enc( } #endif - /*------------------------------------------------------------------------- * ivas_ism_metadata_enc_create() * * Create, allocate, initialize and configure IVAS encoder ISM metadata handles *-------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED ivas_error ivas_ism_metadata_enc_create( - Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ - const int16_t n_ISms, /* i : number of objects */ - int32_t element_brate_tmp[] /* o : element bitrate per object */ + Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ + const int16_t n_ISms, /* i : number of objects */ + Word32 element_brate_tmp[] /* o : element bitrate per object */ ) { - int16_t ch, nchan_transport; + Word16 ch, nchan_transport; ivas_error error; nchan_transport = st_ivas->nchan_transport; - if ( st_ivas->hEncoderConfig->ivas_format == MASA_ISM_FORMAT ) + move16(); + IF( st_ivas->hEncoderConfig->ivas_format == MASA_ISM_FORMAT ) { nchan_transport = MAX_PARAM_ISM_WAVE; #ifndef IVAS_FLOAT_FIXED @@ -1400,65 +1539,97 @@ ivas_error ivas_ism_metadata_enc_create( ivas_set_omasa_TC_fx( st_ivas->ism_mode, n_ISms, &st_ivas->nSCE, &st_ivas->nCPE ); #endif } - else if ( st_ivas->hEncoderConfig->ivas_format == SBA_ISM_FORMAT ) + ELSE IF( st_ivas->hEncoderConfig->ivas_format == SBA_ISM_FORMAT ) { nchan_transport = n_ISms; } - else + ELSE { - if ( st_ivas->ism_mode == ISM_MODE_NONE ) + IF( st_ivas->ism_mode == ISM_MODE_NONE ) { nchan_transport = st_ivas->nchan_transport; + move16(); - if ( nchan_transport == 1 ) + IF( nchan_transport == 1 ) { st_ivas->nSCE = 1; + move16(); st_ivas->nCPE = 0; + move16(); } - else + ELSE { st_ivas->nSCE = 0; + move16(); st_ivas->nCPE = 1; + move16(); } } - else if ( st_ivas->ism_mode == ISM_MODE_PARAM ) + ELSE IF( st_ivas->ism_mode == ISM_MODE_PARAM ) { nchan_transport = 2; + move16(); } - else + ELSE { nchan_transport = n_ISms; + move16(); } st_ivas->nchan_transport = nchan_transport; st_ivas->nSCE = nchan_transport; st_ivas->nCPE = 0; + move16(); + move16(); + move16(); } /* allocate ISM metadata handles */ - for ( ch = 0; ch < n_ISms; ch++ ) + FOR( ch = 0; ch < n_ISms; ch++ ) { - if ( ( st_ivas->hIsmMetaData[ch] = (ISM_METADATA_HANDLE) malloc( sizeof( ISM_METADATA_FRAME ) ) ) == NULL ) + IF( ( st_ivas->hIsmMetaData[ch] = (ISM_METADATA_HANDLE) malloc( sizeof( ISM_METADATA_FRAME ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for ISM MetaData\n" ) ); } st_ivas->hIsmMetaData[ch]->position_angle.last_angle1_idx = 0; + move16(); st_ivas->hIsmMetaData[ch]->position_angle.angle1_diff_cnt = ISM_FEC_MAX; + move16(); st_ivas->hIsmMetaData[ch]->position_angle.last_angle2_idx = 0; + move16(); st_ivas->hIsmMetaData[ch]->position_angle.angle2_diff_cnt = ISM_FEC_MAX - 1; + move16(); st_ivas->hIsmMetaData[ch]->orientation_angle.last_angle1_idx = 0; + move16(); st_ivas->hIsmMetaData[ch]->orientation_angle.angle1_diff_cnt = ISM_FEC_MAX - 2; + move16(); st_ivas->hIsmMetaData[ch]->orientation_angle.last_angle2_idx = 0; + move16(); st_ivas->hIsmMetaData[ch]->orientation_angle.angle2_diff_cnt = ISM_FEC_MAX - 2; + move16(); st_ivas->hIsmMetaData[ch]->last_radius_idx = 0; + move16(); st_ivas->hIsmMetaData[ch]->radius_diff_cnt = ISM_FEC_MAX - 2; + move16(); st_ivas->hIsmMetaData[ch]->last_ism_metadata_flag = 0; + move16(); st_ivas->hIsmMetaData[ch]->ism_imp = -1; + move16(); st_ivas->hIsmMetaData[ch]->ism_md_null_flag = 0; + move16(); st_ivas->hIsmMetaData[ch]->ism_md_lowrate_flag = 0; - st_ivas->hIsmMetaData[ch]->q_azimuth_old = 0.0f; - st_ivas->hIsmMetaData[ch]->q_elevation_old = 0.0f; + move16(); + + st_ivas->hIsmMetaData[ch]->q_azimuth_old_fx = 0; + move16(); + st_ivas->hIsmMetaData[ch]->q_elevation_old_fx = 0; + move16(); + /*===============fix-to-flt====================*/ + st_ivas->hIsmMetaData[ch]->q_azimuth_old = fix_to_float( st_ivas->hIsmMetaData[ch]->q_azimuth_old_fx, Q22 ); + st_ivas->hIsmMetaData[ch]->q_elevation_old = fix_to_float( st_ivas->hIsmMetaData[ch]->q_elevation_old_fx, Q22 ); + /*===============fix-to-flt====================*/ + #ifdef IVAS_FLOAT_FIXED ivas_ism_reset_metadata_enc( st_ivas->hIsmMetaData[ch] ); @@ -1466,36 +1637,48 @@ ivas_error ivas_ism_metadata_enc_create( ivas_ism_reset_metadata( st_ivas->hIsmMetaData[ch] ); #endif - st_ivas->hIsmMetaData[ch]->last_azimuth = 0.0f; - st_ivas->hIsmMetaData[ch]->last_elevation = 0.0f; - st_ivas->hIsmMetaData[ch]->last_true_azimuth = 0.0f; - st_ivas->hIsmMetaData[ch]->last_true_elevation = 0.0f; + st_ivas->hIsmMetaData[ch]->last_azimuth_fx = 0; + st_ivas->hIsmMetaData[ch]->last_elevation_fx = 0; + + st_ivas->hIsmMetaData[ch]->last_true_azimuth_fx = 0; + st_ivas->hIsmMetaData[ch]->last_true_elevation_fx = 0; + 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; - st_ivas->hIsmMetaData[ch]->last_true_radius = 1.0f; + st_ivas->hIsmMetaData[ch]->last_true_radius_fx = ONE_IN_Q9; + + /*===============fix-to-flt====================*/ + st_ivas->hIsmMetaData[ch]->last_azimuth = fix_to_float( st_ivas->hIsmMetaData[ch]->last_azimuth_fx, Q22 ); + st_ivas->hIsmMetaData[ch]->last_elevation = fix_to_float( st_ivas->hIsmMetaData[ch]->last_elevation_fx, Q22 ); + + st_ivas->hIsmMetaData[ch]->last_true_azimuth = fix_to_float( st_ivas->hIsmMetaData[ch]->last_true_azimuth_fx, Q22 ); + st_ivas->hIsmMetaData[ch]->last_true_elevation = fix_to_float( st_ivas->hIsmMetaData[ch]->last_true_elevation_fx, Q22 ); + st_ivas->hIsmMetaData[ch]->last_true_radius = fix16_to_float( st_ivas->hIsmMetaData[ch]->last_true_radius_fx, Q9 ); + /*===============fix-to-flt====================*/ } - if ( st_ivas->hEncoderConfig->ivas_format == MASA_ISM_FORMAT ) + IF( EQ_16( st_ivas->hEncoderConfig->ivas_format, MASA_ISM_FORMAT ) ) { - if ( st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) + test(); + IF( st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) { - if ( ( error = ivas_ism_config( st_ivas->hEncoderConfig->ivas_total_brate, nchan_transport, 1, NULL, 0, NULL, NULL, element_brate_tmp, NULL, NULL, 1 ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_ism_config_fx( st_ivas->hEncoderConfig->ivas_total_brate, nchan_transport, 1, NULL, 0, NULL, NULL, element_brate_tmp, NULL, NULL, 1 ) ) != IVAS_ERR_OK ) { return error; } } - else if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) + ELSE IF( EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) { - if ( ( error = ivas_ism_config( st_ivas->hEncoderConfig->ivas_total_brate, nchan_transport, n_ISms, NULL, 0, NULL, NULL, element_brate_tmp, NULL, NULL, 1 ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_ism_config_fx( st_ivas->hEncoderConfig->ivas_total_brate, nchan_transport, n_ISms, NULL, 0, NULL, NULL, element_brate_tmp, NULL, NULL, 1 ) ) != IVAS_ERR_OK ) { return error; } } } - else + ELSE { - if ( ( error = ivas_ism_config( st_ivas->hEncoderConfig->ivas_total_brate, nchan_transport, n_ISms, NULL, 0, NULL, NULL, element_brate_tmp, NULL, NULL, 0 ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_ism_config_fx( st_ivas->hEncoderConfig->ivas_total_brate, nchan_transport, n_ISms, NULL, 0, NULL, NULL, element_brate_tmp, NULL, NULL, 0 ) ) != IVAS_ERR_OK ) { return error; } @@ -1503,14 +1686,243 @@ ivas_error ivas_ism_metadata_enc_create( return IVAS_ERR_OK; } - - -/*------------------------------------------------------------------------- - * encode_radius() - * - * Radius index encoding +#else +ivas_error ivas_ism_metadata_enc_create( + Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ + const int16_t n_ISms, /* i : number of objects */ + int32_t element_brate_tmp[] /* o : element bitrate per object */ +) +{ + int16_t ch, nchan_transport; + ivas_error error; + + nchan_transport = st_ivas->nchan_transport; + if ( st_ivas->hEncoderConfig->ivas_format == MASA_ISM_FORMAT ) + { + nchan_transport = MAX_PARAM_ISM_WAVE; +#ifndef IVAS_FLOAT_FIXED + ivas_set_omasa_TC( st_ivas->ism_mode, n_ISms, &st_ivas->nSCE, &st_ivas->nCPE ); +#else + ivas_set_omasa_TC_fx( st_ivas->ism_mode, n_ISms, &st_ivas->nSCE, &st_ivas->nCPE ); +#endif + } + else if ( st_ivas->hEncoderConfig->ivas_format == SBA_ISM_FORMAT ) + { + nchan_transport = n_ISms; + } + else + { + if ( st_ivas->ism_mode == ISM_MODE_NONE ) + { + nchan_transport = st_ivas->nchan_transport; + + if ( nchan_transport == 1 ) + { + st_ivas->nSCE = 1; + st_ivas->nCPE = 0; + } + else + { + st_ivas->nSCE = 0; + st_ivas->nCPE = 1; + } + } + else if ( st_ivas->ism_mode == ISM_MODE_PARAM ) + { + nchan_transport = 2; + } + else + { + nchan_transport = n_ISms; + } + + st_ivas->nchan_transport = nchan_transport; + st_ivas->nSCE = nchan_transport; + st_ivas->nCPE = 0; + } + + /* allocate ISM metadata handles */ + for ( ch = 0; ch < n_ISms; ch++ ) + { + if ( ( st_ivas->hIsmMetaData[ch] = (ISM_METADATA_HANDLE) malloc( sizeof( ISM_METADATA_FRAME ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for ISM MetaData\n" ) ); + } + st_ivas->hIsmMetaData[ch]->position_angle.last_angle1_idx = 0; + st_ivas->hIsmMetaData[ch]->position_angle.angle1_diff_cnt = ISM_FEC_MAX; + st_ivas->hIsmMetaData[ch]->position_angle.last_angle2_idx = 0; + st_ivas->hIsmMetaData[ch]->position_angle.angle2_diff_cnt = ISM_FEC_MAX - 1; + st_ivas->hIsmMetaData[ch]->orientation_angle.last_angle1_idx = 0; + st_ivas->hIsmMetaData[ch]->orientation_angle.angle1_diff_cnt = ISM_FEC_MAX - 2; + st_ivas->hIsmMetaData[ch]->orientation_angle.last_angle2_idx = 0; + st_ivas->hIsmMetaData[ch]->orientation_angle.angle2_diff_cnt = ISM_FEC_MAX - 2; + st_ivas->hIsmMetaData[ch]->last_radius_idx = 0; + st_ivas->hIsmMetaData[ch]->radius_diff_cnt = ISM_FEC_MAX - 2; + st_ivas->hIsmMetaData[ch]->last_ism_metadata_flag = 0; + + st_ivas->hIsmMetaData[ch]->ism_imp = -1; + st_ivas->hIsmMetaData[ch]->ism_md_null_flag = 0; + st_ivas->hIsmMetaData[ch]->ism_md_lowrate_flag = 0; + st_ivas->hIsmMetaData[ch]->q_azimuth_old = 0.0f; + st_ivas->hIsmMetaData[ch]->q_elevation_old = 0.0f; + +#ifdef IVAS_FLOAT_FIXED + ivas_ism_reset_metadata_enc( st_ivas->hIsmMetaData[ch] ); +#else + ivas_ism_reset_metadata( st_ivas->hIsmMetaData[ch] ); +#endif + + st_ivas->hIsmMetaData[ch]->last_azimuth = 0.0f; + st_ivas->hIsmMetaData[ch]->last_elevation = 0.0f; + + 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; + st_ivas->hIsmMetaData[ch]->last_true_radius = 1.0f; + } + + if ( st_ivas->hEncoderConfig->ivas_format == MASA_ISM_FORMAT ) + { + if ( st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) + { + if ( ( error = ivas_ism_config( st_ivas->hEncoderConfig->ivas_total_brate, nchan_transport, 1, NULL, 0, NULL, NULL, element_brate_tmp, NULL, NULL, 1 ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) + { + if ( ( error = ivas_ism_config( st_ivas->hEncoderConfig->ivas_total_brate, nchan_transport, n_ISms, NULL, 0, NULL, NULL, element_brate_tmp, NULL, NULL, 1 ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } + else + { + if ( ( error = ivas_ism_config( st_ivas->hEncoderConfig->ivas_total_brate, nchan_transport, n_ISms, NULL, 0, NULL, NULL, element_brate_tmp, NULL, NULL, 0 ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + return IVAS_ERR_OK; +} +#endif + +/*------------------------------------------------------------------------- + * encode_radius() + * + * Radius index encoding *-------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +static void encode_radius( + BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */ + Word16 *last_radius_idx, /* i/o: last radius index */ + Word16 *radius_diff_cnt, /* i/o: radius diff coding counter */ + const Word16 last_ism_metadata_flag, /* last frame ism_metadata_flag */ + const Word16 idx_radius_abs, /* i : Azimuth index */ + Word16 *flag_abs_radius /* o : Radius encoding mode */ +) +{ + Word16 idx_radius, nbits_diff_radius, diff; + idx_radius = idx_radius_abs; + nbits_diff_radius = 0; + move16(); + *flag_abs_radius = 0; /* differential coding by default */ + move16(); + + test(); + IF( EQ_16( *radius_diff_cnt, ISM_FEC_MAX ) /* make differential encoding in ISM_FEC_MAX consecutive frames at maximum (in order to control the decoding in FEC) */ + || last_ism_metadata_flag == 0 /* If last frame had no metadata coded, do not use differential coding */ + ) + { + *flag_abs_radius = 1; + move16(); + } + + diff = sub( idx_radius_abs, *last_radius_idx ); + + /* try differential coding */ + IF( EQ_16( *flag_abs_radius, 0 ) ) + { + IF( EQ_16( diff, 0 ) ) + { + idx_radius = 0; + move16(); + nbits_diff_radius = 1; + move16(); + } + ELSE IF( LE_16( ABSVAL( diff ), ISM_MAX_RADIUS_DIFF_IDX ) ) + { + idx_radius = shl( 1, 1 ); + nbits_diff_radius = 1; + move16(); + + IF( LT_16( diff, 0 ) ) + { + idx_radius = add( idx_radius, 1 ); /* negative sign */ + diff = imult1616( diff, -1 ); + } + ELSE + { + idx_radius = add( idx_radius, 0 ); /* positive sign */ + } + + idx_radius = shl( idx_radius, diff ); + nbits_diff_radius = add( nbits_diff_radius, 1 ); + + /* unary coding of "diff */ + idx_radius = add( idx_radius, sub( shl( 1, diff ), 1 ) ); + nbits_diff_radius = add( nbits_diff_radius, diff ); + + IF( LT_16( nbits_diff_radius, ISM_RADIUS_NBITS ) ) + { + /* add stop bit */ + idx_radius = shl( idx_radius, 1 ); + nbits_diff_radius = add( nbits_diff_radius, 1 ); + } + } + ELSE + { + *flag_abs_radius = 1; + move16(); + } + } + + /* update counter */ + IF( EQ_16( *flag_abs_radius, 0 ) ) + { + ( *radius_diff_cnt )++; + *radius_diff_cnt = min( *radius_diff_cnt, ISM_FEC_MAX ); + } + ELSE + { + *radius_diff_cnt = 0; + move16(); + } + + /* Write radius */ + push_indice( hBstr, IND_ISM_RADIUS_DIFF_FLAG, *flag_abs_radius, 1 ); + + IF( *flag_abs_radius ) + { + push_indice( hBstr, IND_ISM_RADIUS, idx_radius, ISM_RADIUS_NBITS ); + } + ELSE + { + push_indice( hBstr, IND_ISM_RADIUS, idx_radius, nbits_diff_radius ); + } + + /* Updates */ + *last_radius_idx = idx_radius_abs; + move16(); + + return; +} +#else static void encode_radius( BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */ int16_t *last_radius_idx, /* i/o: last radius index */ @@ -1606,7 +2018,7 @@ static void encode_radius( return; } - +#endif /*----------------------------------------------------------------* * encode_angle_indices() @@ -1614,6 +2026,268 @@ static void encode_radius( * Encoding of an angle *----------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +static void encode_angle_indices( + BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */ + ISM_METADATA_ANGLE_HANDLE angle, /* i/o: angle handle */ + const Word16 last_ism_metadata_flag, /* i : last frame ism_metadata_flag */ + const Word16 ini_frame, /* i : initialization frames counter */ + const Word16 idx_angle1_abs, /* i : Azimuth index */ + const Word16 idx_angle2_abs, /* i : Elevation index */ + Word16 *flag_abs_angle1, /* o : Azimuth/yaw encoding mode */ + Word16 *flag_abs_angle2 /* o : Elevation/pitch encoding mode */ +) +{ + Word16 idx_angle1, nbits_diff_angle1, diff; + Word16 idx_angle2, nbits_diff_angle2; + + /*----------------------------------------------------------------* + * Azimuth/yaw index encoding + *----------------------------------------------------------------*/ + + idx_angle1 = idx_angle1_abs; + + nbits_diff_angle1 = 0; + move16(); + *flag_abs_angle1 = 0; /* differential coding by default */ + test(); + if ( EQ_16( angle->angle1_diff_cnt, ISM_FEC_MAX ) /* make differential encoding in ISM_FEC_MAX consecutive frames at maximum (in order to control the decoding in FEC) */ + || last_ism_metadata_flag == 0 /* If last frame had no metadata coded, do not use differential coding */ + ) + { + *flag_abs_angle1 = 1; + move16(); + } + + /* try differential coding */ + IF( *flag_abs_angle1 == 0 ) + { + diff = sub( idx_angle1_abs, angle->last_angle1_idx ); + + /* azimuth is on a circle - check for diff coding for -180° -> 180° and vice versa changes */ + IF( abs( diff ) > ( ( 1 << ISM_AZIMUTH_NBITS ) - 1 ) - ISM_MAX_AZIMUTH_DIFF_IDX ) + { + IF( diff > 0 ) + { + diff = sub( diff, ( 1 << ISM_AZIMUTH_NBITS ) - 1 ); + } + ELSE + { + diff = add( diff, ( 1 << ISM_AZIMUTH_NBITS ) - 1 ); + } + } + + IF( diff == 0 ) + { + idx_angle1 = 0; + move16(); + nbits_diff_angle1 = 1; + move16(); + } + ELSE IF( LT_16( ABSVAL( diff ), ISM_MAX_AZIMUTH_DIFF_IDX ) ) /* when diff bits >= abs bits, prefer abs */ + { + idx_angle1 = shl( 1, 1 ); + nbits_diff_angle1 = 1; + move16(); + + IF( diff < 0 ) + { + idx_angle1 = add( idx_angle1, 1 ); /* negative sign */ + diff = imult1616( diff, -1 ); + } + ELSE + { + idx_angle1 = add( idx_angle1, 0 ); /* positive sign */ + } + + idx_angle1 = shl( idx_angle1, diff ); + nbits_diff_angle1 = add( nbits_diff_angle1, 1 ); + + /* unary coding of "diff */ + idx_angle1 = add( idx_angle1, sub( shl( 1, diff ), 1 ) ); + nbits_diff_angle1 = add( nbits_diff_angle1, diff ); + + IF( LT_16( nbits_diff_angle1, ( ISM_AZIMUTH_NBITS - 1 ) ) ) + { + /* add stop bit - only for codewords shorter than ISM_AZIMUTH_NBITS */ + idx_angle1 = shl( idx_angle1, 1 ); + nbits_diff_angle1 = add( nbits_diff_angle1, 1 ); + } + } + ELSE + { + *flag_abs_angle1 = 1; + move16(); + } + } + + /* update counter */ + IF( *flag_abs_angle1 == 0 ) + { + angle->angle1_diff_cnt = add( angle->angle1_diff_cnt, 1 ); + angle->angle1_diff_cnt = s_min( angle->angle1_diff_cnt, ISM_FEC_MAX ); + } + ELSE + { + angle->angle1_diff_cnt = 0; + move16(); + } + + /* Write azimuth/yaw */ + push_indice( hBstr, IND_ISM_AZIMUTH_DIFF_FLAG, *flag_abs_angle1, 1 ); + + IF( *flag_abs_angle1 ) + { + push_indice( hBstr, IND_ISM_AZIMUTH, idx_angle1, ISM_AZIMUTH_NBITS ); + } + ELSE + { + push_indice( hBstr, IND_ISM_AZIMUTH, idx_angle1, nbits_diff_angle1 ); + } + + /*----------------------------------------------------------------* + * Elevation/pitch index encoding + *----------------------------------------------------------------*/ + + IF( flag_abs_angle2 ) + { + idx_angle2 = idx_angle2_abs; + move16(); + nbits_diff_angle2 = 0; + move16(); + *flag_abs_angle2 = 0; /* differential coding by default */ + move16(); + IF( EQ_16( angle->angle2_diff_cnt, ISM_FEC_MAX ) /* make differential encoding in ISM_FEC_MAX consecutive frames at maximum (in order to control the decoding in FEC) */ + || last_ism_metadata_flag == 0 /* If last frame had no metadata coded, do not use differential coding */ + ) + { + *flag_abs_angle2 = 1; + move16(); + } + + /* note: elevation/pitch is coded starting from the second frame only (it is meaningless in the init_frame) */ + IF( ini_frame == 0 ) + { + *flag_abs_angle2 = 1; + move16(); + angle->last_angle2_idx = idx_angle2_abs; + move16(); + } + + diff = sub( idx_angle2_abs, angle->last_angle2_idx ); + + /* avoid absolute coding of elevation/pitch if absolute coding was already used for azimuth/yaw */ + IF( EQ_16( *flag_abs_angle1, 1 ) ) + { + Word16 diff_orig = diff; + + *flag_abs_angle2 = 0; + move16(); + + + IF( diff >= 0 ) + { + diff = min( diff, ISM_MAX_ELEVATION_DIFF_IDX ); + } + ELSE + { + diff = imult1616( -1, min( -diff, ISM_MAX_ELEVATION_DIFF_IDX ) ); + } + + IF( last_ism_metadata_flag == 0 || abs( diff_orig - diff ) > ISM_MAX_ELEVATION_DIFF_IDX ) + { + angle->angle2_diff_cnt = ISM_FEC_MAX - 1; + move16(); + } + } + + /* try differential coding */ + IF( *flag_abs_angle2 == 0 ) + { + IF( diff == 0 ) + { + idx_angle2 = 0; + move16(); + nbits_diff_angle2 = 1; + move16(); + } + ELSE IF( LE_16( ABSVAL( diff ), ISM_MAX_ELEVATION_DIFF_IDX ) ) + { + idx_angle2 = shl( 1, 1 ); + nbits_diff_angle2 = 1; + move16(); + + IF( diff < 0 ) + { + idx_angle2 = add( idx_angle2, 1 ); /* negative sign */ + diff = imult1616( diff, -1 ); + } + ELSE + { + idx_angle2 = add( idx_angle2, 0 ); /* positive sign */ + } + + idx_angle2 = shl( idx_angle2, diff ); + nbits_diff_angle2 = add( nbits_diff_angle2, 1 ); + + /* unary coding of "diff */ + idx_angle2 = add( idx_angle2, sub( shl( 1, diff ), 1 ) ); + nbits_diff_angle2 = add( nbits_diff_angle2, diff ); + + IF( LT_16( nbits_diff_angle2, ISM_ELEVATION_NBITS ) ) + { + /* add stop bit */ + idx_angle2 = shl( idx_angle2, 1 ); + nbits_diff_angle2 = add( nbits_diff_angle2, 1 ); + } + } + ELSE + { + *flag_abs_angle2 = 1; + move16(); + } + } + + /* update counter */ + IF( *flag_abs_angle2 == 0 ) + { + angle->angle2_diff_cnt = add( angle->angle2_diff_cnt, 1 ); + angle->angle2_diff_cnt = s_min( angle->angle2_diff_cnt, ISM_FEC_MAX ); + } + ELSE + { + angle->angle2_diff_cnt = 0; + move16(); + } + + /* Write elevation */ + IF( *flag_abs_angle1 == 0 ) /* do not write "flag_abs_elevation/pitch" if "flag_abs_azimuth/yaw == 1" */ + { + push_indice( hBstr, IND_ISM_ELEVATION_DIFF_FLAG, *flag_abs_angle2, 1 ); + } + + IF( *flag_abs_angle2 ) + { + push_indice( hBstr, IND_ISM_ELEVATION, idx_angle2, ISM_ELEVATION_NBITS ); + } + ELSE + { + push_indice( hBstr, IND_ISM_ELEVATION, idx_angle2, nbits_diff_angle2 ); + } + } + + /*----------------------------------------------------------------* + * Updates + *----------------------------------------------------------------*/ + + angle->last_angle1_idx = idx_angle1_abs; + move16(); + angle->last_angle2_idx = idx_angle2_abs; + move16(); + + return; +} +#else static void encode_angle_indices( BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */ ISM_METADATA_ANGLE_HANDLE angle, /* i/o: angle handle */ @@ -1852,7 +2526,7 @@ static void encode_angle_indices( return; } - +#endif /*-------------------------------------------------------------------* * ivas_ism_metadata_sid_enc() @@ -1862,34 +2536,30 @@ static void encode_angle_indices( #ifdef IVAS_FLOAT_FIXED void ivas_ism_metadata_sid_enc( - ISM_DTX_HANDLE hISMDTX, /* i/o: ISM DTX handle */ - const int16_t flag_noisy_speech, /* i : noisy speech flag */ - const int16_t nchan_ism, /* i : number of objects */ - const int16_t nchan_transport, /* i : number of transport channels */ - const ISM_MODE ism_mode, /* i : ISM mode */ - ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */ - const int16_t sid_flag, /* i : indication of SID frame */ - const int16_t md_diff_flag[], /* i : metadata differental flag */ - BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */ - int16_t nb_bits_metadata[] /* o : number of metadata bits */ + ISM_DTX_HANDLE hISMDTX, /* i/o: ISM DTX handle */ + const Word16 flag_noisy_speech, /* i : noisy speech flag */ + const Word16 nchan_ism, /* i : number of objects */ + const Word16 nchan_transport, /* i : number of transport channels */ + const ISM_MODE ism_mode, /* i : ISM mode */ + ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */ + const Word16 sid_flag, /* i : indication of SID frame */ + const Word16 md_diff_flag[], /* i : metadata differental flag */ + BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */ + Word16 nb_bits_metadata[] /* o : number of metadata bits */ ) { - int16_t i, ch, nBits, nBits_start, nBits_unused; - float q_step, q_step_border; -#ifdef IVAS_FLOAT_FIXED + Word16 i, ch, nBits, nBits_start, nBits_unused; Word32 q_step_fx, q_step_border_fx; -#endif - int16_t idx, idx_azimuth, idx_elevation; - int16_t nBits_azimuth, nBits_elevation, nBits_coh, nBits_sce_id; -#ifdef IVAS_FLOAT_FIXED + Word16 idx, idx_azimuth, idx_elevation; + Word16 nBits_azimuth, nBits_elevation, nBits_coh, nBits_sce_id; Word32 valQ_fx; -#endif + ISM_METADATA_HANDLE hIsmMetaData; - if ( sid_flag ) + IF( sid_flag ) { nBits = ( IVAS_SID_5k2 - SID_2k40 ) / FRAMES_PER_SEC; - nBits -= SID_FORMAT_NBITS; + nBits = sub( nBits, SID_FORMAT_NBITS ); nBits_start = hBstr->nb_bits_tot; /*----------------------------------------------------------------* @@ -1897,14 +2567,14 @@ void ivas_ism_metadata_sid_enc( *----------------------------------------------------------------*/ /* write number of objects - unary coding */ - for ( ch = 1; ch < nchan_ism; ch++ ) + FOR( ch = 1; ch < nchan_ism; ch++ ) { push_indice( hBstr, IND_ISM_NUM_OBJECTS, 1, 1 ); } push_indice( hBstr, IND_ISM_NUM_OBJECTS, 0, 1 ); /* write SID metadata flag (one per object) */ - for ( ch = 0; ch < nchan_ism; ch++ ) + FOR( ch = 0; ch < nchan_ism; ch++ ) { push_indice( hBstr, IND_ISM_METADATA_FLAG, md_diff_flag[ch], 1 ); } @@ -1913,25 +2583,25 @@ void ivas_ism_metadata_sid_enc( * Set quantization bits based on the number of coded objects *----------------------------------------------------------------*/ - ivas_get_ism_sid_quan_bitbudget( nchan_ism, &nBits_azimuth, &nBits_elevation, &q_step, &q_step_border, &nBits_coh, &nBits_sce_id ); + ivas_get_ism_sid_quan_bitbudget_fx( nchan_ism, &nBits_azimuth, &nBits_elevation, &q_step_fx, &q_step_border_fx, &nBits_coh, &nBits_sce_id ); /*----------------------------------------------------------------* * Spatial parameters, loop over TCs - 1 *----------------------------------------------------------------*/ /* write ISM mode flag to explicitly signal number of spatial parameters */ - if ( nchan_ism > 2 ) + IF( GT_16( nchan_ism, 2 ) ) { - if ( ism_mode == ISM_MODE_DISC ) + IF( EQ_16( ism_mode, ISM_MODE_DISC ) ) { push_indice( hBstr, IND_ISM_MD_INACTIVE_FLAG, 0, 1 ); } - else + ELSE { push_indice( hBstr, IND_ISM_MD_INACTIVE_FLAG, 1, 1 ); } - if ( ism_mode == ISM_MODE_PARAM ) + IF( EQ_16( ism_mode, ISM_MODE_PARAM ) ) { /* write noisy speech flag */ push_indice( hBstr, IND_ISM_NOISY_SPEECH_FLAG, flag_noisy_speech, 1 ); @@ -1939,20 +2609,22 @@ void ivas_ism_metadata_sid_enc( } } - if ( nchan_transport > 1 ) + IF( GT_16( nchan_transport, 1 ) ) { /* write sce id */ push_indice( hBstr, IND_ISM_SCE_ID_DTX, hISMDTX->sce_id_dtx, nBits_sce_id ); /* quantize and write coherence */ - for ( ch = 0; ch < nchan_transport; ch++ ) + FOR( ch = 0; ch < nchan_transport; ch++ ) { - if ( ch == hISMDTX->sce_id_dtx ) + IF( EQ_16( ch, hISMDTX->sce_id_dtx ) ) { continue; } - - idx = (int16_t) ( hISMDTX->coh[ch] * ( ( 1 << nBits_coh ) - 1 ) + 0.5f ); + Word32 tmp = Mpy_32_32( L_shr( L_deposit_h( hISMDTX->coh_fx[ch] ), 1 ) /*Q30*/, L_deposit_h( sub( shl( 1, nBits_coh ), 1 ) ) ); // Q15 + Word32 tmp_2 = L_add( tmp, 16384 /*0.5f in Q15*/ ); + idx = (Word16) L_shr( tmp_2, Q15 ); + // idx = (Word16) ( hISMDTX->coh[ch] * sub( shl( 1, nBits_coh ), 1 ) + 0.5f ); assert( ( idx >= 0 ) && ( idx <= ( ( 1 << nBits_coh ) - 1 ) ) ); push_indice( hBstr, IND_ISM_DTX_COH_SCA, idx, nBits_coh ); } @@ -1962,9 +2634,9 @@ void ivas_ism_metadata_sid_enc( * Metadata quantization and coding, loop over all objects *----------------------------------------------------------------*/ - for ( ch = 0; ch < nchan_ism; ch++ ) + FOR( ch = 0; ch < nchan_ism; ch++ ) { - if ( md_diff_flag[ch] == 1 ) + IF( md_diff_flag[ch] == 1 ) { hIsmMetaData = hIsmMeta[ch]; @@ -1972,8 +2644,6 @@ void ivas_ism_metadata_sid_enc( /*===============================flt-2-fix======================================*/ hIsmMetaData->azimuth_fx = floatToFixed( hIsmMetaData->azimuth, Q22 ); hIsmMetaData->elevation_fx = floatToFixed( hIsmMetaData->elevation, Q22 ); - q_step_fx = floatToFixed( q_step, Q22 ); - q_step_border_fx = floatToFixed( q_step_border, Q22 ); /*===============================flt-2-fix======================================*/ idx_azimuth = ism_quant_meta_fx( hIsmMetaData->azimuth_fx, &valQ_fx, ism_azimuth_borders_fx, q_step_fx, q_step_border_fx, 1 << nBits_azimuth ); idx_elevation = ism_quant_meta_fx( hIsmMetaData->elevation_fx, &valQ_fx, ism_elevation_borders_fx, q_step_fx, q_step_border_fx, 1 << nBits_elevation ); @@ -1981,20 +2651,19 @@ void ivas_ism_metadata_sid_enc( idx_azimuth = ism_quant_meta( hIsmMetaData->azimuth, &valQ, ism_azimuth_borders, q_step, q_step_border, 1 << nBits_azimuth ); idx_elevation = ism_quant_meta( hIsmMetaData->elevation, &valQ, ism_elevation_borders, q_step, q_step_border, 1 << nBits_elevation ); #endif - push_indice( hBstr, IND_ISM_AZIMUTH, idx_azimuth, nBits_azimuth ); push_indice( hBstr, IND_ISM_ELEVATION, idx_elevation, nBits_elevation ); /* update last indexes to correspond to active frames coding */ - if ( nBits_azimuth > ISM_AZIMUTH_NBITS ) + IF( GT_16( nBits_azimuth, ISM_AZIMUTH_NBITS ) ) { - hIsmMetaData->position_angle.last_angle1_idx = idx_azimuth >> ( nBits_azimuth - ISM_AZIMUTH_NBITS ); - hIsmMetaData->position_angle.last_angle2_idx = idx_elevation >> ( nBits_elevation - ISM_ELEVATION_NBITS ); + hIsmMetaData->position_angle.last_angle1_idx = shr( idx_azimuth, sub( nBits_azimuth, ISM_AZIMUTH_NBITS ) ); + hIsmMetaData->position_angle.last_angle2_idx = shr( idx_elevation, sub( nBits_elevation, ISM_ELEVATION_NBITS ) ); } - else + ELSE { - 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 ); + hIsmMetaData->position_angle.last_angle1_idx = shl( idx_azimuth, sub( ISM_AZIMUTH_NBITS, nBits_azimuth ) ); + hIsmMetaData->position_angle.last_angle2_idx = shl( idx_elevation, sub( ISM_ELEVATION_NBITS, nBits_elevation ) ); } hIsmMetaData->ism_md_fec_cnt_enc = 0; @@ -2003,15 +2672,15 @@ void ivas_ism_metadata_sid_enc( } /* Write unused (padding) bits */ - nBits_unused = nBits - hBstr->nb_bits_tot; - while ( nBits_unused > 0 ) + nBits_unused = sub( nBits, hBstr->nb_bits_tot ); + WHILE( nBits_unused > 0 ) { i = min( nBits_unused, 16 ); push_indice( hBstr, IND_UNUSED, 0, i ); - nBits_unused -= i; + nBits_unused = sub( nBits_unused, i ); } - nb_bits_metadata[0] = hBstr->nb_bits_tot - nBits_start; + nb_bits_metadata[0] = sub( hBstr->nb_bits_tot, nBits_start ); } return; diff --git a/lib_enc/ivas_omasa_enc.c b/lib_enc/ivas_omasa_enc.c index 9598804d9..8f3d726a5 100644 --- a/lib_enc/ivas_omasa_enc.c +++ b/lib_enc/ivas_omasa_enc.c @@ -613,6 +613,78 @@ void ivas_omasa_enc( * * Set the importance of particular ISM streams in combined-format coding *-------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void ivas_set_ism_importance_interformat_fx( + const Word32 ism_total_brate, /* i/o: ISms total bitrate */ + const Word16 nchan_transport, /* i : number of transported channels */ + ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */ + SCE_ENC_HANDLE hSCE[], /* i/o: SCE encoder handles */ + const Word32 lp_noise_CPE_fx, /* i : LP filtered total noise estimation Q8*/ + Word16 ism_imp[] /* o : ISM importance flags */ +) +{ + Encoder_State *st; + Word16 ch, ctype, active_flag; + + FOR( ch = 0; ch < nchan_transport; ch++ ) + { + st = hSCE[ch]->hCoreCoder[0]; + + active_flag = st->vad_flag; + move16(); + + IF( active_flag == 0 ) + { + if ( GT_32( st->lp_noise_fx, 3840 /*15 in Q8*/ ) || LT_32( L_sub( lp_noise_CPE_fx, st->lp_noise_fx ), 7680 /*30*/ ) ) + { + active_flag = 1; + move16(); + } + } + + Word32 quo, rem; + iDiv_and_mod_32( ism_total_brate, nchan_transport, &quo, &rem, 0 ); + + /* do not use the low-rate core-coder mode at highest bit-rates */ + if ( GT_32( quo, IVAS_48k ) ) + { + active_flag = 1; + move16(); + } + + ctype = hSCE[ch]->hCoreCoder[0]->coder_type_raw; + + st->low_rate_mode = 0; + IF( active_flag == 0 ) + { + ism_imp[ch] = ISM_INACTIVE_IMP; + move16(); + st->low_rate_mode = 1; + move16(); + } + ELSE IF( EQ_16( ctype, INACTIVE ) || EQ_16( ctype, UNVOICED ) ) + { + ism_imp[ch] = ISM_LOW_IMP; + move16(); + } + ELSE IF( EQ_16( ctype, VOICED ) ) + { + ism_imp[ch] = ISM_MEDIUM_IMP; + move16(); + } + ELSE /* GENERIC */ + { + ism_imp[ch] = ISM_HIGH_IMP; + move16(); + } + + hIsmMeta[ch]->ism_metadata_flag = active_flag; /* flag is needed for the MD coding */ + move16(); + } + + return; +} +#endif void ivas_set_ism_importance_interformat( const int32_t ism_total_brate, /* i/o: ISms total bitrate */ @@ -673,7 +745,6 @@ void ivas_set_ism_importance_interformat( return; } - /*--------------------------------------------------------------------------* * ivas_set_surplus_brate_enc() * diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h index ec2dbd2be..fa8970e00 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -751,7 +751,6 @@ typedef struct float long_term_energy_stereo_dmx_enc[MAX_NUM_OBJECTS][PARAM_ISM_HYS_BUF_SIZE]; float coh[MAX_NUM_OBJECTS]; - } ISM_DTX_DATA, *ISM_DTX_HANDLE; /*----------------------------------------------------------------------------------* @@ -1034,7 +1033,9 @@ typedef struct ivas_omasa_encoder_one_data_struct Word32 q_energy_ratio_ism_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS]; /* Q30 */ Word32 masa_to_total_energy_ratio_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; /* Q30 */ #endif - float lp_noise_CPE; /* LP filtered total noise estimation */ + float lp_noise_CPE; /* LP filtered total noise estimation */ + Word32 lp_noise_CPE_fx; /* LP filtered total noise estimation */ /*Q8*/ + int16_t omasa_stereo_sw_cnt; } OMASA_ENCODER_DATA_STATE, *OMASA_ENCODER_DATA_HANDLE; diff --git a/lib_enc/lib_enc.c b/lib_enc/lib_enc.c index 8d61700e4..b35609ce1 100644 --- a/lib_enc/lib_enc.c +++ b/lib_enc/lib_enc.c @@ -472,8 +472,24 @@ ivas_error IVAS_ENC_FeedObjectMetadata( { return IVAS_ERR_INVALID_INDEX; } - +#ifdef IVAS_FLOAT_FIXED + Word32 azimuth_fx = float_to_fix( metadata.azimuth, Q22 ); /* Q22 */ + Word32 elevation_fx = float_to_fix( metadata.elevation, Q22 ); /* Q22 */ + Word16 radius_fx = float_to_fix16( metadata.radius, Q9 ); /* Q9 */ + Word32 yaw_fx = float_to_fix( metadata.yaw, Q22 ); /* Q22 */ + Word32 pitch_fx = float_to_fix( metadata.pitch, Q22 ); /* Q22 */ + error = ivas_set_ism_metadata_fx( hIvasEnc->st_ivas->hIsmMetaData[ismIndex], azimuth_fx, elevation_fx, radius_fx, yaw_fx, pitch_fx, metadata.non_diegetic_flag ); + + /*================fix-to-flt====================*/ + hIvasEnc->st_ivas->hIsmMetaData[ismIndex]->azimuth = fix_to_float( azimuth_fx, Q22 ); + hIvasEnc->st_ivas->hIsmMetaData[ismIndex]->elevation = fix_to_float( elevation_fx, Q22 ); + hIvasEnc->st_ivas->hIsmMetaData[ismIndex]->radius = fix_to_float( radius_fx, Q9 ); + hIvasEnc->st_ivas->hIsmMetaData[ismIndex]->yaw = fix_to_float( yaw_fx, Q22 ); + hIvasEnc->st_ivas->hIsmMetaData[ismIndex]->pitch = fix_to_float( pitch_fx, Q22 ); + /*================fix-to-flt====================*/ +#else error = ivas_set_ism_metadata( hIvasEnc->st_ivas->hIsmMetaData[ismIndex], metadata.azimuth, metadata.elevation, metadata.radius, metadata.yaw, metadata.pitch, metadata.non_diegetic_flag ); +#endif if ( error != IVAS_ERR_OK ) { -- GitLab