From 8af79d34f37cbfbb046564fd59830f7d69c6da9c Mon Sep 17 00:00:00 2001 From: Tapani Pihlajakuja Date: Fri, 11 Aug 2023 10:50:43 +0300 Subject: [PATCH] Cleanup on Nokia Todos in various places --- lib_com/ivas_cnst.h | 4 +- lib_com/ivas_masa_com.c | 8 ++ lib_com/ivas_prot.h | 8 ++ lib_com/ivas_stat_com.h | 5 + lib_com/options.h | 1 + lib_dec/ivas_dec.c | 4 + lib_dec/ivas_dirac_dec.c | 9 ++ lib_dec/ivas_masa_dec.c | 77 ++++++++++-- lib_dec/ivas_stat_dec.h | 3 + lib_enc/ivas_init_enc.c | 4 +- lib_enc/ivas_masa_enc.c | 121 +++++++++++++++++-- lib_enc/ivas_omasa_enc.c | 2 +- lib_enc/ivas_qmetadata_enc.c | 13 ++ lib_enc/ivas_stat_enc.h | 3 + lib_rend/ivas_dirac_ana.c | 2 + lib_rend/ivas_dirac_dec_binaural_functions.c | 10 ++ lib_rend/ivas_dirac_output_synthesis_dec.c | 2 + 17 files changed, 256 insertions(+), 20 deletions(-) diff --git a/lib_com/ivas_cnst.h b/lib_com/ivas_cnst.h index a6ad6440c9..332ea0a279 100644 --- a/lib_com/ivas_cnst.h +++ b/lib_com/ivas_cnst.h @@ -116,8 +116,8 @@ typedef enum AUDIO_CONFIG_ISM2, /* ISM2 */ AUDIO_CONFIG_ISM3, /* ISM3 */ AUDIO_CONFIG_ISM4, /* ISM4 */ - AUDIO_CONFIG_MASA1, /* MASA1 */ // TODO: seems not to be used - AUDIO_CONFIG_MASA2, /* MASA2 */ // TODO: seems not to be used + AUDIO_CONFIG_MASA1, /* MASA1 */ + AUDIO_CONFIG_MASA2, /* MASA2 */ AUDIO_CONFIG_EXTERNAL /* external renderer */ } AUDIO_CONFIG; diff --git a/lib_com/ivas_masa_com.c b/lib_com/ivas_masa_com.c index 0ca65e4da3..a45c7fd673 100644 --- a/lib_com/ivas_masa_com.c +++ b/lib_com/ivas_masa_com.c @@ -897,6 +897,10 @@ void reconstruct_ism_ratios( void ivas_omasa_modify_masa_energy_ratios( IVAS_QMETADATA_HANDLE hQMetaData /* i/o: q_metadata handle */ +#ifdef FIX_672_NOKIA_TODO + , + float masa_to_total_energy_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_MAXIMUM_CODING_SUBBANDS] +#endif ) { int16_t i, m, d, b; @@ -916,7 +920,11 @@ void ivas_omasa_modify_masa_energy_ratios( { for ( d = 0; d < hQMetaData->no_directions; d++ ) { +#ifdef FIX_672_NOKIA_TODO + hQMetaData->q_direction[d].band_data[b].energy_ratio[m] = hQMetaData->q_direction[d].band_data[b].energy_ratio[m] * masa_to_total_energy_ratio[i][b]; +#else hQMetaData->q_direction[d].band_data[b].energy_ratio[m] = hQMetaData->q_direction[d].band_data[b].energy_ratio[m] * hQMetaData->masa_to_total_energy_ratio[i][b]; +#endif } } } diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 98229a668d..cf36d4facd 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -5914,7 +5914,11 @@ void ivas_omasa_set_edited_objects( ); #endif void ivas_omasa_encode_masa_to_total( +#ifdef FIX_672_NOKIA_TODO + float masa_to_total_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], +#else IVAS_QMETADATA_HANDLE hQMetaData, +#endif BSTR_ENC_HANDLE hMetaData, const int16_t low_bitrate_mode, const int16_t nbands, @@ -5931,6 +5935,10 @@ void ivas_omasa_decode_masa_to_total( void ivas_omasa_modify_masa_energy_ratios( IVAS_QMETADATA_HANDLE hQMetaData /* i/o: q_metadata handle */ +#ifdef FIX_672_NOKIA_TODO + , + float masa_to_total_energy_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_MAXIMUM_CODING_SUBBANDS] +#endif ); #endif diff --git a/lib_com/ivas_stat_com.h b/lib_com/ivas_stat_com.h index 975fb77a71..476dae42ab 100644 --- a/lib_com/ivas_stat_com.h +++ b/lib_com/ivas_stat_com.h @@ -484,6 +484,9 @@ typedef struct ivas_masa_config_struct uint8_t useCoherence; uint8_t coherencePresent; uint8_t mergeRatiosOverSubframes; +#ifdef FIX_672_NOKIA_TODO + IVAS_FORMAT input_ivas_format; +#endif } MASA_CODEC_CONFIG; @@ -576,9 +579,11 @@ typedef struct ivas_masa_qmetadata_frame_struct int16_t ec_flag; float dir_comp_ratio; uint8_t is_masa_ivas_format; +#ifndef FIX_672_NOKIA_TODO #ifdef MASA_AND_OBJECTS float masa_to_total_energy_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; /* TODO Nokia: This should be moved to some other place and reserved only when needed. */ #endif +#endif } IVAS_QMETADATA, *IVAS_QMETADATA_HANDLE; diff --git a/lib_com/options.h b/lib_com/options.h index 5774d4a8b2..359a1e719a 100755 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -221,6 +221,7 @@ #define FIX_613_DIRAC_NULL_PTR_USAN /* Nokia: Issue #613: USAN in DirAC decoder setup */ #define FIX_647_SILENT_W_PARAMBIN /* Nokia: Issue #647: Fix silent W SH inputs in parametric binauralizer */ +#define FIX_672_NOKIA_TODO /* Nokia: Issue #672: Resolve Nokia TODOs */ #define MASA_AND_OBJECTS /* Nokia: Combination of MASA and objects */ #define TD_REND_TUNING_RENAME /* Eri: Tuning of TD renderer model as part of contribution 25 and renaming for default HRIR set */ diff --git a/lib_dec/ivas_dec.c b/lib_dec/ivas_dec.c index 95c7f19e60..ab76af5fec 100644 --- a/lib_dec/ivas_dec.c +++ b/lib_dec/ivas_dec.c @@ -543,7 +543,11 @@ ivas_error ivas_dec( /* Set the number of objects for the parametric rendering */ dirac_bs_md_write_idx = 0; +#ifdef FIX_672_NOKIA_TODO + if ( st_ivas->hSpatParamRendCom != NULL ) +#else if ( st_ivas->hDirAC != NULL ) /* TODO: should this check for st_ivas->hSpatParamRendCom != NULL ? */ +#endif { st_ivas->hSpatParamRendCom->numIsmDirections = 0; if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC && st_ivas->ism_mode != ISM_MASA_MODE_MASA_ONE_OBJ ) diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index 04f7a72ce1..35f67bb908 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -1802,8 +1802,13 @@ void ivas_dirac_dec_render_sf( float Cldfb_ImagBuffer_Binaural[BINAURAL_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX]; #endif #ifdef MASA_AND_OBJECTS +#ifdef FIX_672_NOKIA_TODO + float Cldfb_RealBuffer_Temp[2][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; + float Cldfb_ImagBuffer_Temp[2][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; +#else float Cldfb_RealBuffer_Temp[2][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; /* Todo Nokia: Temporary, to be removed once function calls have been refactored to accept another size */ float Cldfb_ImagBuffer_Temp[2][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; /* Todo Nokia: Temporary, to be removed once function calls have been refactored to accept another size */ +#endif #endif int16_t index, num_freq_bands; @@ -2003,7 +2008,9 @@ void ivas_dirac_dec_render_sf( } #ifdef MASA_AND_OBJECTS +#ifndef FIX_672_NOKIA_TODO // Todo OMASA JBM: This might need adjustments +#endif if ( st_ivas->ivas_format == MASA_ISM_FORMAT && nchan_transport == 2 ) { for ( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ ) @@ -2049,7 +2056,9 @@ void ivas_dirac_dec_render_sf( } } #ifdef MASA_AND_OBJECTS +#ifndef FIX_672_NOKIA_TODO // Todo OMASA JBM: This might need adjustments +#endif else if ( st_ivas->ivas_format == MASA_ISM_FORMAT && nchan_transport == 2 ) { for ( ch = 0; ch < nchan_transport; ch++ ) diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index 5090cf8a0d..442b133611 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -77,9 +77,11 @@ static ivas_error ivas_masa_dec_config( Decoder_Struct *st_ivas ); static int16_t ivas_decode_masaism_metadata( IVAS_QMETADATA_HANDLE hQMetaData, MASA_DECODER_HANDLE hMasa, MASA_ISM_DATA_HANDLE hMasaIsmData, const int16_t nchan_ism, uint16_t *bit_stream, int16_t *next_bit_pos, const int16_t idx_separated_object, const int16_t ism_imp, const int16_t dirac_bs_md_write_idx, const int16_t dirac_md_buffer_length ); static void decode_index_slice( int16_t index, int16_t *ratio_idx_ism, const int16_t nchan_ism, const int16_t K ); - +#ifdef FIX_672_NOKIA_TODO +static void decode_ism_ratios( uint16_t *bit_stream, int16_t *next_bit_pos, float masa_to_total_energy_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], float ratio_ism[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], const int16_t nchan_ism, const int16_t nbands, const int16_t nblocks, const int16_t idx_separated_object ); +#else static void decode_ism_ratios( uint16_t *bit_stream, int16_t *next_bit_pos, IVAS_QMETADATA_HANDLE hQMetaData, float ratio_ism[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], const int16_t nchan_ism, const int16_t nbands, const int16_t nblocks, const int16_t idx_separated_object ); - +#endif static void read_ism_ratio_index( int16_t ratio_ism_idx[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], const int16_t nchan_ism, const int16_t numCodingBands, const int16_t sf, int16_t ratio_ism_idx_prev_sf[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], uint16_t *bit_stream, int16_t *next_bit_pos, float *masa_to_total_energy_ratio, const int16_t idx_sep_obj, int16_t *num_zeros ); #endif @@ -257,9 +259,25 @@ ivas_error ivas_masa_decode( } } #endif + +#ifdef FIX_672_NOKIA_TODO + /* read the MASA_ISM_FORMAT bit */ + byteBuffer = st->bit_stream[( st->next_bit_pos )--]; + if ( byteBuffer == 1 ) + { + hMasa->config.input_ivas_format = MASA_ISM_FORMAT; + } + else + { + hMasa->config.input_ivas_format = MASA_FORMAT; + } + /* reserved bit */ + byteBuffer = st->bit_stream[( st->next_bit_pos )--]; +#else /* Placeholder for descriptive metadata content */ byteBuffer = st->bit_stream[( st->next_bit_pos )--]; byteBuffer += st->bit_stream[( st->next_bit_pos )--]; +#endif *nb_bits_read += MASA_HEADER_BITS; /* read number of directions */ @@ -383,7 +401,12 @@ ivas_error ivas_masa_decode( if ( st_ivas->ivas_format == MASA_ISM_FORMAT && st_ivas->ism_mode != ISM_MASA_MODE_DISC && st_ivas->ism_mode != ISM_MASA_MODE_MASA_ONE_OBJ ) { /* Modify spatial metadata based on the MASA-to-total energy ratios */ - ivas_omasa_modify_masa_energy_ratios( hQMetaData ); + ivas_omasa_modify_masa_energy_ratios( hQMetaData +#ifdef FIX_672_NOKIA_TODO + , + st_ivas->hMasaIsmData->masa_to_total_energy_ratio +#endif + ); } #endif @@ -473,7 +496,9 @@ ivas_error ivas_masa_decode( if ( st_ivas->hDirAC != NULL ) { #ifdef MASA_AND_OBJECTS +#ifndef FIX_672_NOKIA_TODO // Todo OMASA JBM: This might need adjustments +#endif dirac_bs_md_write_idx = st_ivas->hSpatParamRendCom->dirac_bs_md_write_idx; /* Store the write-index for this frame */ #endif ivas_qmetadata_to_dirac( hQMetaData, st_ivas->hDirAC, hMasa, st_ivas->hSpatParamRendCom, ivas_total_brate, ivas_format, 0, 0 ); @@ -500,7 +525,9 @@ ivas_error ivas_masa_decode( { for ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ ) { +#ifndef FIX_672_NOKIA_TODO // Todo OMASA JBM: This might need adjustments +#endif meta_write_index = ( dirac_bs_md_write_idx + block ) % st_ivas->hSpatParamRendCom->dirac_md_buffer_length; for ( b = 0; b < st_ivas->hSpatParamRendCom->num_freq_bands; b++ ) @@ -1408,7 +1435,9 @@ ivas_error ivas_masa_dec_reconfigure( sts = st_ivas->hCPE[cpe_id]->hCoreCoder; sts[0]->bit_stream = bit_stream + num_bits; num_bits += (int16_t) ( st_ivas->hCPE[cpe_id]->element_brate / FRAMES_PER_SEC ); +#ifndef FIX_672_NOKIA_TODO /* Todo: Nokia make for MASA_ISM*/ +#endif if ( ( ivas_total_brate < MASA_STEREO_MIN_BITRATE && last_ivas_total_brate >= MASA_STEREO_MIN_BITRATE ) || ( ivas_total_brate < MASA_STEREO_MIN_BITRATE && last_ivas_total_brate == FRAME_NO_DATA ) ) { @@ -1658,7 +1687,11 @@ void ivas_spar_param_to_masa_param_mapping( #endif hSpatParamRendCom->numSimultaneousDirections = 1; #ifdef SPLIT_REND_WITH_HEAD_ROT_PARAMBIN +#ifdef FIX_672_NOKIA_TODO + hDiffuseDist = st_ivas->hDiracDecBin[0]->hDiffuseDist; +#else hDiffuseDist = st_ivas->hDiracDecBin[0]->hDiffuseDist; /* TODO: this may need to use different pose indices */ +#endif #else hDiffuseDist = st_ivas->hDiracDecBin->hDiffuseDist; #endif @@ -2033,7 +2066,9 @@ static void create_masa_ext_out_meta( } #ifdef MASA_AND_OBJECTS +#ifndef FIX_672_NOKIA_TODO // Todo OMASA JBM: There is a lot of metadata access here via dirac indices, they could be wrong post JBM. +#endif static void decode_index_slice( int16_t index, /* i : index to decode */ int16_t *ratio_idx_ism, /* o : decodec array of integers */ @@ -2358,9 +2393,13 @@ static void read_ism_ratio_index( static void decode_ism_ratios( - uint16_t *bit_stream, /* i : bitstream */ - int16_t *next_bit_pos, /* i/o: position in bitstream */ - IVAS_QMETADATA_HANDLE hQMetaData, /* i : Metadata handle */ + uint16_t *bit_stream, /* i : bitstream */ + int16_t *next_bit_pos, /* i/o: position in bitstream */ +#ifdef FIX_672_NOKIA_TODO + float masa_to_total_energy_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i: masa_to_total energy ratios */ +#else + IVAS_QMETADATA_HANDLE hQMetaData, /* i : Metadata handle */ +#endif float ratio_ism[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], /* o : ISM ratios */ const int16_t n_ism, /* i : number of objects */ const int16_t nbands, /* i : number of subbands */ @@ -2379,8 +2418,11 @@ static void decode_ism_ratios( for ( sf = 0; sf < numSf; sf++ ) { /* read ism ratio indexes */ +#ifdef FIX_672_NOKIA_TODO + read_ism_ratio_index( ratio_ism_idx, n_ism, nbands, sf, ratio_ism_idx_prev_sf, bit_stream, next_bit_pos, masa_to_total_energy_ratio[sf], idx_separated_object, &num_zeros ); +#else read_ism_ratio_index( ratio_ism_idx, n_ism, nbands, sf, ratio_ism_idx_prev_sf, bit_stream, next_bit_pos, hQMetaData->masa_to_total_energy_ratio[sf], idx_separated_object, &num_zeros ); - +#endif /* save previous subframe index values */ if ( sf < numSf - 1 ) { @@ -2401,7 +2443,11 @@ static void decode_ism_ratios( /* rotate */ for ( band = 0; band < nbands; band++ ) { +#ifdef FIX_672_NOKIA_TODO + if ( masa_to_total_energy_ratio[sf][band] < MASA2TOTAL_THR ) +#else if ( hQMetaData->masa_to_total_energy_ratio[sf][band] < MASA2TOTAL_THR ) +#endif { tmp = ratio_ism[sf][band][n_ism - 1]; ratio_ism[sf][band][n_ism - 1] = ratio_ism[sf][band][0]; @@ -2462,11 +2508,19 @@ static int16_t ivas_decode_masaism_metadata( nblocks = hQMetaData->q_direction->cfg.nblocks; /* Read MASA-to-total energy ratios */ +#ifdef FIX_672_NOKIA_TODO + ivas_omasa_decode_masa_to_total( bit_stream, next_bit_pos, hMasaIsmData->masa_to_total_energy_ratio, nbands, nblocks ); +#else ivas_omasa_decode_masa_to_total( bit_stream, next_bit_pos, hQMetaData->masa_to_total_energy_ratio, nbands, nblocks ); +#endif if ( nchan_ism > 1 ) { /* read ISM ratios */ +#ifdef FIX_672_NOKIA_TODO + decode_ism_ratios( bit_stream, next_bit_pos, hMasaIsmData->masa_to_total_energy_ratio, energy_ratio_ism, nchan_ism, nbands, nblocks, idx_separated_object ); +#else decode_ism_ratios( bit_stream, next_bit_pos, hQMetaData, energy_ratio_ism, nchan_ism, nbands, nblocks, idx_separated_object ); +#endif } else { @@ -2480,8 +2534,11 @@ static int16_t ivas_decode_masaism_metadata( } /* read ISM metadata */ +#ifdef FIX_672_NOKIA_TODO + calculate_nbits_meta( nchan_ism, energy_ratio_ism, hMasaIsmData->masa_to_total_energy_ratio, nblocks, nbands, bits_ism, idx_separated_object, ism_imp ); +#else calculate_nbits_meta( nchan_ism, energy_ratio_ism, hQMetaData->masa_to_total_energy_ratio, nblocks, nbands, bits_ism, idx_separated_object, ism_imp ); - +#endif for ( obj = 0; obj < nchan_ism; obj++ ) { index = 0; @@ -2547,7 +2604,11 @@ static int16_t ivas_decode_masaism_metadata( { for ( dir = 0; dir < nchan_ism; dir++ ) { +#ifdef FIX_672_NOKIA_TODO + energy_ratio_ism[sf][band][dir] *= ( 1.0f - hMasaIsmData->masa_to_total_energy_ratio[sf][band] ); +#else energy_ratio_ism[sf][band][dir] *= ( 1.0f - hQMetaData->masa_to_total_energy_ratio[sf][band] ); +#endif } } } diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h index 7848e09fe0..fa59698e47 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -854,6 +854,9 @@ typedef struct ivas_masa_ism_data_structure int16_t azimuth_ism[MAX_NUM_OBJECTS][MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_MASA_PARAM_DEC_SFR]; int16_t elevation_ism[MAX_NUM_OBJECTS][MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_MASA_PARAM_DEC_SFR]; float energy_ratio_ism[MAX_NUM_OBJECTS][MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_MASA_PARAM_DEC_SFR][CLDFB_NO_CHANNELS_MAX]; +#ifdef FIX_672_NOKIA_TODO + float masa_to_total_energy_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; +#endif int16_t azimuth_ism_edited[MAX_NUM_OBJECTS]; int16_t elevation_ism_edited[MAX_NUM_OBJECTS]; diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index 330046a5cd..28797733e8 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -601,12 +601,12 @@ ivas_error ivas_init_encoder( { return error; } - +#ifndef FIX_672_NOKIA_TODO for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) { set_f( st_ivas->hQMetaData->masa_to_total_energy_ratio[i], 0, MASA_FREQUENCY_BANDS ); } - +#endif if ( ( error = ivas_masa_enc_open( st_ivas ) ) != IVAS_ERR_OK ) { return error; diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index d41711b81f..cbc5b14572 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -188,7 +188,12 @@ ivas_error ivas_masa_enc_open( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for OMASA data encoder\n" ) ); } - +#ifdef FIX_672_NOKIA_TODO + for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + { + set_f( hOmasaData->masa_to_total_energy_ratio[i], 0, MASA_FREQUENCY_BANDS ); + } +#endif hOmasaData->lp_noise_CPE = -1; hOmasaData->omasa_stereo_sw_cnt = OMASA_STEREO_SW_CNT_MAX; @@ -500,10 +505,27 @@ ivas_error ivas_masa_encode( } #endif +#ifdef FIX_672_NOKIA_TODO + if ( ivas_format == MASA_ISM_FORMAT && ism_mode == ISM_MODE_NONE ) + { + /* signal MASA_ISM_FORMAT to decoder */ + push_next_indice( hMetaData, 1, 1 ); + /* write reserved bit */ + push_next_indice( hMetaData, 0, MASA_HEADER_BITS - 1 ); + hQMetaData->metadata_max_bits -= MASA_HEADER_BITS; + } + else + { + /* the MASA_ISM_FORMAT is not signalled here */ + /* write reserved bits */ + push_next_indice( hMetaData, 0, MASA_HEADER_BITS ); + hQMetaData->metadata_max_bits -= MASA_HEADER_BITS; + } +#else /* write placeholder data for descriptive metadata */ push_next_indice( hMetaData, 0, MASA_HEADER_BITS ); hQMetaData->metadata_max_bits -= MASA_HEADER_BITS; - +#endif /* write number of directions */ push_next_indice( hMetaData, hQMetaData->no_directions - 1, 1 ); hQMetaData->metadata_max_bits -= 1; @@ -555,7 +577,14 @@ ivas_error ivas_masa_encode( } else { +#ifdef FIX_672_NOKIA_TODO + if ( ivas_format == MASA_ISM_FORMAT ) + { + hMasa->data.hOmasaData->masa_to_total_energy_ratio[0][0] = -1; /* signals NOT to adjust the energy ratios */ + } +#else hQMetaData->masa_to_total_energy_ratio[0][0] = -1; /* signals NOT to adjust the energy ratios */ +#endif } #endif @@ -600,7 +629,11 @@ ivas_error ivas_masa_encode( if ( ivas_format == MASA_ISM_FORMAT && ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) { /* Modify spatial metadata based on the MASA-to-total energy ratios */ +#ifdef FIX_672_NOKIA_TODO + ivas_omasa_modify_masa_energy_ratios( hQMetaData, hMasa->data.hOmasaData->masa_to_total_energy_ratio ); +#else ivas_omasa_modify_masa_energy_ratios( hQMetaData ); +#endif } #endif @@ -2740,10 +2773,14 @@ void ivas_merge_masa_metadata( float energyTimesRatioISM; float energyTimesRatioMASA[2]; float total_diff_nrg; +#ifndef FIX_672_NOKIA_TODO int16_t brange[2]; +#endif float eneBand; float energyMerged[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; +#ifndef FIX_672_NOKIA_TODO int16_t bin; +#endif numCodingBands = hMasa->config.numCodingBands; numDirections = hMasa->config.numberOfDirections; @@ -2757,9 +2794,11 @@ void ivas_merge_masa_metadata( int16_t merge_dest; float dir_sum; uint8_t band_n_dirs; +#ifndef FIX_672_NOKIA_TODO brange[0] = band; brange[1] = band + 1; /* TODO: if this stays, remove the unnecessary range loop from the code */ +#endif if ( numDirections == 1 || ( numDirections == 2 && hMasa->data.twoDirBands[band] == 0 ) ) { band_n_dirs = 1; @@ -2770,12 +2809,16 @@ void ivas_merge_masa_metadata( } /* Compute energies */ +#ifdef FIX_672_NOKIA_TODO + eneBand = hMasa->data.energy[sf][band]; +#else /* MASA energy is in the full 24 band resolution, whereas the ISM energy is already in the coding band resolution */ eneBand = 0.0f; for ( bin = brange[0]; bin < brange[1]; bin++ ) { eneBand += hMasa->data.energy[sf][bin]; } +#endif energyMerged[sf][band] = eneBand + hMasa->data.hOmasaData->energy_ism[sf][band]; /* Compute weights */ @@ -2816,7 +2859,7 @@ void ivas_merge_masa_metadata( hMeta->directional_meta[merge_dest].energy_ratio[sf][band] = min( dir_sum, hOMasaMeta->directional_meta[0].energy_ratio[sf][band] ); /* clip with original ISM dir */ hMeta->common_meta.diffuse_to_total_ratio[sf][band] = 1.0f - hMeta->directional_meta[merge_dest].energy_ratio[sf][band]; - if ( hMasa->config.useCoherence ) /* TODO: is this correct condition? */ + if ( hMasa->config.useCoherence ) { hMeta->directional_meta[merge_dest].spread_coherence[sf][band] = hOMasaMeta->directional_meta[0].spread_coherence[sf][band]; hMeta->common_meta.surround_coherence[sf][band] = hOMasaMeta->common_meta.surround_coherence[sf][band]; @@ -3548,7 +3591,11 @@ static void ivas_encode_masaism_metadata( { if ( sum_f( hOmasaData->energy_ism[sf], omasa_nbands ) == 0.0f ) { +#ifdef FIX_672_NOKIA_TODO + hOmasaData->masa_to_total_energy_ratio[sf][0] = 1.0f; +#else hQMetaData->masa_to_total_energy_ratio[sf][0] = 1.0f; +#endif } else { @@ -3579,7 +3626,11 @@ static void ivas_encode_masaism_metadata( { hOmasaData->energy_ratio_ism[sf][0][obj] = energy_ism_ind[obj] / energy_ism; } +#ifdef FIX_672_NOKIA_TODO + hOmasaData->masa_to_total_energy_ratio[sf][0] = eneBand / ( eneBand + energy_ism + EPSILON ); +#else hQMetaData->masa_to_total_energy_ratio[sf][0] = eneBand / ( eneBand + energy_ism + EPSILON ); +#endif } } } @@ -3614,7 +3665,11 @@ static void ivas_encode_masaism_metadata( if ( energy_ism == 0.0f ) { +#ifdef FIX_672_NOKIA_TODO + hOmasaData->masa_to_total_energy_ratio[0][band] = 1.0f; +#else hQMetaData->masa_to_total_energy_ratio[0][band] = 1.0f; +#endif } else { @@ -3633,13 +3688,21 @@ static void ivas_encode_masaism_metadata( eneBand += hMasa->data.energy[sf][bin]; } } +#ifdef FIX_672_NOKIA_TODO + hOmasaData->masa_to_total_energy_ratio[0][band] = eneBand / ( eneBand + energy_ism + EPSILON ); +#else hQMetaData->masa_to_total_energy_ratio[0][band] = eneBand / ( eneBand + energy_ism + EPSILON ); +#endif } } #ifdef FIX_675_WB_OMASA for ( band = nbands_work; band < numCodingBands; band++ ) { +#ifdef FIX_672_NOKIA_TODO + hOmasaData->masa_to_total_energy_ratio[0][band] = 1.0f; +#else hQMetaData->masa_to_total_energy_ratio[0][band] = 1.0f; +#endif for ( obj = 0; obj < nchan_ism; obj++ ) { @@ -3660,7 +3723,11 @@ static void ivas_encode_masaism_metadata( { if ( hOmasaData->energy_ism[sf][band] == 0.0f ) { +#ifdef FIX_672_NOKIA_TODO + hOmasaData->masa_to_total_energy_ratio[sf][band] = 1.0f; +#else hQMetaData->masa_to_total_energy_ratio[sf][band] = 1.0f; +#endif } else { @@ -3672,13 +3739,21 @@ static void ivas_encode_masaism_metadata( { eneBand += hMasa->data.energy[sf][bin]; } +#ifdef FIX_672_NOKIA_TODO + hOmasaData->masa_to_total_energy_ratio[sf][band] = eneBand / ( eneBand + hOmasaData->energy_ism[sf][band] + EPSILON ); +#else hQMetaData->masa_to_total_energy_ratio[sf][band] = eneBand / ( eneBand + hOmasaData->energy_ism[sf][band] + EPSILON ); +#endif } } #ifdef FIX_675_WB_OMASA for ( band = nbands_work; band < numCodingBands; band++ ) { +#ifdef FIX_672_NOKIA_TODO + hOmasaData->masa_to_total_energy_ratio[sf][band] = 1.0f; +#else hQMetaData->masa_to_total_energy_ratio[sf][band] = 1.0f; +#endif for ( obj = 0; obj < nchan_ism; obj++ ) { @@ -3688,8 +3763,11 @@ static void ivas_encode_masaism_metadata( #endif } } - +#ifdef FIX_672_NOKIA_TODO + ivas_omasa_encode_masa_to_total( hOmasaData->masa_to_total_energy_ratio, hMetaData, low_bitrate_mode, numCodingBands, numSf ); +#else ivas_omasa_encode_masa_to_total( hQMetaData, hMetaData, low_bitrate_mode, numCodingBands, numSf ); +#endif /* quantize ism_ratios */ if ( nchan_ism > 1 ) @@ -3711,9 +3789,16 @@ static void ivas_encode_masaism_metadata( } /* Quantize ISM ratios */ +#ifdef FIX_672_NOKIA_TODO + quantize_ratio_ism_vector( ratio_ism[band], ratio_ism_idx[band], nchan_ism, hOmasaData->masa_to_total_energy_ratio[sf][band], idx_separated_object ); +#else quantize_ratio_ism_vector( ratio_ism[band], ratio_ism_idx[band], nchan_ism, hQMetaData->masa_to_total_energy_ratio[sf][band], idx_separated_object ); - +#endif +#ifdef FIX_672_NOKIA_TODO + if ( n_ism_tmp == numCodingBands && ratio_ism_idx[band][idx_separated_object] != 0 && hOmasaData->masa_to_total_energy_ratio[sf][band] < MASA2TOTAL_THR ) +#else if ( n_ism_tmp == numCodingBands && ratio_ism_idx[band][idx_separated_object] != 0 && hQMetaData->masa_to_total_energy_ratio[sf][band] < MASA2TOTAL_THR ) +#endif { i = 0; while ( ratio_ism_idx[band][idx_separated_object] > 0 ) @@ -3741,7 +3826,11 @@ static void ivas_encode_masaism_metadata( rotate = 1; for ( band = 0; band < numCodingBands; band++ ) { +#ifdef FIX_672_NOKIA_TODO + if ( hOmasaData->masa_to_total_energy_ratio[sf][band] < MASA2TOTAL_THR ) +#else if ( hQMetaData->masa_to_total_energy_ratio[sf][band] < MASA2TOTAL_THR ) +#endif { tmp = ratio_ism_idx[band][nchan_ism - 1]; ratio_ism_idx[band][nchan_ism - 1] = ratio_ism_idx[band][0]; @@ -3764,7 +3853,11 @@ static void ivas_encode_masaism_metadata( { for ( band = 0; band < numCodingBands; band++ ) { +#ifdef FIX_672_NOKIA_TODO + if ( hOmasaData->masa_to_total_energy_ratio[sf][band] < MASA2TOTAL_THR ) +#else if ( hQMetaData->masa_to_total_energy_ratio[sf][band] < MASA2TOTAL_THR ) +#endif { if ( ratio_ism_idx[band][idx_separated_object] == 0 && sf == 0 ) { @@ -3778,11 +3871,19 @@ static void ivas_encode_masaism_metadata( /* encode data for current subframe */ if ( sf > 0 && n_ism_tmp == numCodingBands ) { +#ifdef FIX_672_NOKIA_TODO + encode_ratio_ism_subframe( ratio_ism_idx, nchan_ism, numCodingBands, sf, ratio_ism_idx_prev_sf, hMetaData, hOmasaData->masa_to_total_energy_ratio[sf], 1, idx_separated_object ); +#else encode_ratio_ism_subframe( ratio_ism_idx, nchan_ism, numCodingBands, sf, ratio_ism_idx_prev_sf, hMetaData, hQMetaData->masa_to_total_energy_ratio[sf], 1, idx_separated_object ); +#endif } else { +#ifdef FIX_672_NOKIA_TODO + encode_ratio_ism_subframe( ratio_ism_idx, nchan_ism, numCodingBands, sf, ratio_ism_idx_prev_sf, hMetaData, hOmasaData->masa_to_total_energy_ratio[sf], 0, idx_separated_object ); +#else encode_ratio_ism_subframe( ratio_ism_idx, nchan_ism, numCodingBands, sf, ratio_ism_idx_prev_sf, hMetaData, hQMetaData->masa_to_total_energy_ratio[sf], 0, idx_separated_object ); +#endif } /* calculate quantized ISM ratios */ @@ -3796,7 +3897,11 @@ static void ivas_encode_masaism_metadata( { for ( band = 0; band < numCodingBands; band++ ) { +#ifdef FIX_672_NOKIA_TODO + if ( hOmasaData->masa_to_total_energy_ratio[sf][band] < MASA2TOTAL_THR ) +#else if ( hQMetaData->masa_to_total_energy_ratio[sf][band] < MASA2TOTAL_THR ) +#endif { tmp = ratio_ism_idx[band][nchan_ism - 1]; ratio_ism_idx[band][nchan_ism - 1] = ratio_ism_idx[band][0]; @@ -3806,9 +3911,11 @@ static void ivas_encode_masaism_metadata( } } } - +#ifdef FIX_672_NOKIA_TODO + calculate_nbits_meta( nchan_ism, hOmasaData->q_energy_ratio_ism, hOmasaData->masa_to_total_energy_ratio, numSf, numCodingBands, bits_ism, idx_separated_object, ism_imp ); +#else calculate_nbits_meta( nchan_ism, hOmasaData->q_energy_ratio_ism, hQMetaData->masa_to_total_energy_ratio, numSf, numCodingBands, bits_ism, idx_separated_object, ism_imp ); - +#endif /* quantize directions */ for ( obj = 0; obj < nchan_ism; obj++ ) { diff --git a/lib_enc/ivas_omasa_enc.c b/lib_enc/ivas_omasa_enc.c index 4d013c623a..3006a0d6eb 100644 --- a/lib_enc/ivas_omasa_enc.c +++ b/lib_enc/ivas_omasa_enc.c @@ -523,7 +523,7 @@ void ivas_omasa_enc( uint8_t numCodingBands_orig, joinedSubframes_orig; hOMasaMeta = &OMasaMeta; - hOMasaMeta->num_dirs = 1; /* TODO: hard-coding for now */ + hOMasaMeta->num_dirs = 1; /* merge MASA directions before adding ISM to the mixture */ if ( hMasa->config.numberOfDirections == 2 ) diff --git a/lib_enc/ivas_qmetadata_enc.c b/lib_enc/ivas_qmetadata_enc.c index bb89a61995..176aba8f54 100644 --- a/lib_enc/ivas_qmetadata_enc.c +++ b/lib_enc/ivas_qmetadata_enc.c @@ -6401,7 +6401,11 @@ static int16_t write_stream_dct_coeffs_omasa( *------------------------------------------------------------------------*/ void ivas_omasa_encode_masa_to_total( +#ifdef FIX_672_NOKIA_TODO + float masa_to_total_energy_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], +#else IVAS_QMETADATA_HANDLE hQMetaData, +#endif BSTR_ENC_HANDLE hMetaData, const int16_t low_bitrate_mode, const int16_t nbands, @@ -6434,7 +6438,11 @@ void ivas_omasa_encode_masa_to_total( { for ( j = 0; j < nblocks; j++ ) { +#ifdef FIX_672_NOKIA_TODO + data[k] = masa_to_total_energy_ratio[j][i]; +#else data[k] = hQMetaData->masa_to_total_energy_ratio[j][i]; +#endif k++; } } @@ -6575,8 +6583,13 @@ void ivas_omasa_encode_masa_to_total( { for ( j = 0; j < nbands; j++ ) { +#ifdef FIX_672_NOKIA_TODO + masa_to_total_energy_ratio[i][j] = max( 0.0f, q_dct_data[k] ); + masa_to_total_energy_ratio[i][j] = min( 1.0f, masa_to_total_energy_ratio[i][j] ); +#else hQMetaData->masa_to_total_energy_ratio[i][j] = max( 0.0f, q_dct_data[k] ); hQMetaData->masa_to_total_energy_ratio[i][j] = min( 1.0f, hQMetaData->masa_to_total_energy_ratio[i][j] ); +#endif k++; } } diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h index 6a7dd965fd..00661141bd 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -804,6 +804,9 @@ typedef struct ivas_omasa_encoder_one_data_struct float energy_ism[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; float energy_ratio_ism[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS]; float q_energy_ratio_ism[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS]; +#ifdef FIX_672_NOKIA_TODO + float masa_to_total_energy_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; +#endif float lp_noise_CPE; /* LP filtered total noise estimation */ int16_t omasa_stereo_sw_cnt; diff --git a/lib_rend/ivas_dirac_ana.c b/lib_rend/ivas_dirac_ana.c index 6d2b8861bb..a0d1a5ab94 100644 --- a/lib_rend/ivas_dirac_ana.c +++ b/lib_rend/ivas_dirac_ana.c @@ -364,7 +364,9 @@ static void ivas_dirac_param_est_ana( energyRatio[block_m_idx][band_m_idx] = 1.0f - diffuseness_m[band_m_idx]; } +#ifndef FIX_672_NOKIA_TODO /* Todo Nokia: Implement coherence analysis */ +#endif for ( band_m_idx = 0; band_m_idx < hDirAC->nbands; band_m_idx++ ) { spreadCoherence[block_m_idx][band_m_idx] = 0.0f; diff --git a/lib_rend/ivas_dirac_dec_binaural_functions.c b/lib_rend/ivas_dirac_dec_binaural_functions.c index 35ad979487..e898c5cc2e 100644 --- a/lib_rend/ivas_dirac_dec_binaural_functions.c +++ b/lib_rend/ivas_dirac_dec_binaural_functions.c @@ -1090,8 +1090,10 @@ static void ivas_dirac_dec_binaural_internal( /* update this counter only after the last rendering of split directions */ #endif +#ifndef FIX_672_NOKIA_TODO #ifdef MASA_AND_OBJECTS // Todo OMASA JBM: This change could have some side effects +#endif #endif hSpatParamRendCom->slots_rendered += hSpatParamRendCom->subframe_nbslots[subframe]; hSpatParamRendCom->subframes_rendered++; @@ -2438,7 +2440,11 @@ static void ivas_dirac_dec_binaural_determine_processing_matrices( if ( ivas_format == MASA_ISM_FORMAT ) { +#ifdef FIX_672_NOKIA_TODO + gainFactor = 0.7943f * sqrtf( hDiracDecBin->earlyPartEneCorrection[bin] ); +#else gainFactor = 0.7943f * sqrtf( hDiracDecBin->earlyPartEneCorrection[bin] ); /* Todo Nokia: Temporary gain for roughly matching the loudness of other processing paths. */ +#endif } else { @@ -3457,7 +3463,9 @@ float configure_reqularization_factor( * *-------------------------------------------------------------------*/ +#ifndef FIX_672_NOKIA_TODO // Todo OMASA JBM: This might need further adjustments +#endif void ivas_omasa_preProcessStereoTransportsForMovedObjects( Decoder_Struct *st_ivas, float inRe[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], @@ -3502,7 +3510,9 @@ void ivas_omasa_preProcessStereoTransportsForMovedObjects( } /* Perform object-movement based processing */ +#ifndef FIX_672_NOKIA_TODO // Todo OMASA JBM: Fixed but might be still wrong somehow +#endif nSlots = hSpatParamRendCom->subframe_nbslots[subframe]; dirac_read_idx = hSpatParamRendCom->render_to_md_map[subframe]; diff --git a/lib_rend/ivas_dirac_output_synthesis_dec.c b/lib_rend/ivas_dirac_output_synthesis_dec.c index b4b9f71e01..ff81b05264 100644 --- a/lib_rend/ivas_dirac_output_synthesis_dec.c +++ b/lib_rend/ivas_dirac_output_synthesis_dec.c @@ -1361,8 +1361,10 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls( indexFast = min( l, alphaMaxBinFast ); /* Estimate the smoothness of the directions based on the diffuseness parameter */ +#ifndef FIX_672_NOKIA_TODO /* TODO: check this, seems buggy in the case of parame estim on the decoder side, because the pointer here points already to the following subframe, ist this intended?*/ +#endif instDirectionSmoothness = 1.0f - diffuseness_vector[l]; instDirectionSmoothness = min( max( instDirectionSmoothness, 0.0f ), 1.0f ); -- GitLab