From c802b313ca7f30055fa734c5996afc25a7529207 Mon Sep 17 00:00:00 2001 From: Tapani Pihlajakuja Date: Mon, 4 Aug 2025 13:50:47 +0300 Subject: [PATCH 1/2] Port float MR 1542 to float reference --- lib_com/options.h | 2 + lib_dec/ivas_init_dec.c | 18 ++++ lib_dec/ivas_masa_dec.c | 209 +++++++++++++++++++++++++--------------- lib_enc/ivas_masa_enc.c | 39 +++++++- 4 files changed, 185 insertions(+), 83 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 9df46ff77..b83bd6276 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -196,6 +196,8 @@ #define NONBE_FIX_SBA_SIGNALING_BITS_B /* FhG: issue 1061: option B: signal sba order additionally in OSBA */ #define NONBE_FIX_984_OMASA_EXT_OUTPUT /* Nok: issue 1497 - porting OMASA EXT MR */ +#define NONBE_FIX_1074_NOBJ_SIGNAL_OMASA_LBR /* Nok: issue 1074 fixing number of objects signaling in OMASA low rate */ + /* #################### End BASOP porting switches ############################ */ /* clang-format on */ diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index 32e851d4e..695c68828 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -349,12 +349,30 @@ ivas_error ivas_dec_setup( if ( st_ivas->nchan_ism > 0 ) { +#ifdef NONBE_FIX_1074_NOBJ_SIGNAL_OMASA_LBR + /* the input_ivas_format should be MASA_ISM_FORMAT, but we cannot initialize it now */ + /* info about the number of objects: + '00' - MASA format at the encoder + '01' - MASA_ISM_FORMAT at the encoder, with 4 objects + '10' - MASA_ISM_FORMAT at the encoder, with 3 objects + '11' - MASA_ISM_FORMAT at the encoder, with 1 or 2 objects + reading if 1 or 2 objects is performed later + */ + st_ivas->nchan_ism = 5 - st_ivas->nchan_ism; + if ( st_ivas->nchan_transport == 1 && st_ivas->nchan_ism == 2 ) + { + st_ivas->nchan_ism = 1; + } + /* for MASA_ISM_FORMAT at input the number of MASA transport channels is always 2 and the corresponding bit is not used here*/ +#else /* the input_ivas_format should be MASA_ISM_FORMAT, but we cannot initialize it now */ if ( st_ivas->nchan_transport == 2 && st_ivas->nchan_ism == 3 ) { st_ivas->nchan_ism = 4; } + /* for MASA_ISM_FORMAT at input the number of MASA transport channels is always 2 */ +#endif st_ivas->nchan_transport = 2; element_mode_flag = 1; } diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index 722edf53e..9cbcd1e4f 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -151,73 +151,94 @@ ivas_error ivas_masa_decode( { if ( !( ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_MCMASA ) ) { - if ( ivas_format != MASA_ISM_FORMAT ) +#ifdef NONBE_FIX_1074_NOBJ_SIGNAL_OMASA_LBR + if ( ivas_format == MASA_FORMAT ) { - /* number of transport channels is always 2 for MASA_ISM format */ - /* the number of MASA transport channels was read in ivas_dec_setup() */ - st->next_bit_pos -= MASA_TRANSP_BITS; - *nb_bits_read += MASA_TRANSP_BITS; + /* re-read the number of objects, needed in case of bad frame */ + st_ivas->nchan_ism = 5 - ( st_ivas->bit_stream[( ivas_total_brate / FRAMES_PER_SEC ) - 3] + 2 * st_ivas->bit_stream[( ivas_total_brate / FRAMES_PER_SEC ) - 2] ); } - - if ( ivas_format == MASA_ISM_FORMAT && st_ivas->ism_mode != ISM_MODE_NONE ) + if ( ivas_format == MASA_FORMAT && st_ivas->nchan_ism != 5 ) { - /* the number of objects was read */ - st->next_bit_pos -= NO_BITS_MASA_ISM_NO_OBJ; - *nb_bits_read += NO_BITS_MASA_ISM_NO_OBJ; - - if ( st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) + /* there was OMASA in the input */ + hMasa->config.input_ivas_format = MASA_ISM_FORMAT; + if ( st_ivas->nchan_ism < 3 ) { - /* read index of separated object */ - /* nchan_ism should be > 1*/ + /* was read in ivas_init_dec() to distinguish between 1 and 2 objects */ + if ( st_ivas->bit_stream[( ivas_total_brate / FRAMES_PER_SEC ) - 1] == 0 ) + { + st_ivas->nchan_ism = 1; + } + st->next_bit_pos -= MASA_TRANSP_BITS; + *nb_bits_read += MASA_TRANSP_BITS; + + /* the two reserved bits were already read in ivas_init_dec()*/ + byteBuffer = st->bit_stream[( st->next_bit_pos )--]; + byteBuffer = st->bit_stream[( st->next_bit_pos )--]; + *nb_bits_read += MASA_HEADER_BITS; + /* read number of directions */ byteBuffer = st->bit_stream[( st->next_bit_pos )--]; ( *nb_bits_read )++; - st_ivas->hMasaIsmData->idx_separated_ism = 2 * byteBuffer + st->bit_stream[( st->next_bit_pos )--]; - ( *nb_bits_read )++; + hMasa->config.numberOfDirections = (uint8_t) ( byteBuffer + 1 ); } else { - st_ivas->hMasaIsmData->idx_separated_ism = -1; - } + /* if there are 3 or 4 objects the number of transport channels bit is given to MASA format + and used to read number of directions*/ + byteBuffer = st->bit_stream[( st->next_bit_pos )--]; + ( *nb_bits_read )++; + hMasa->config.numberOfDirections = (uint8_t) ( byteBuffer + 1 ); - /* read ISM importance flag (one per object) */ - if ( st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) + /* the two reserved bits were already read in ivas_init_dec()*/ + byteBuffer = st->bit_stream[( st->next_bit_pos )--]; + byteBuffer = st->bit_stream[( st->next_bit_pos )--]; + *nb_bits_read += MASA_HEADER_BITS; + } + } + else + { +#endif + if ( ivas_format != MASA_ISM_FORMAT ) { - ism_imp = 0; - for ( i = 0; i < ISM_METADATA_FLAG_BITS; i++ ) - { - byteBuffer = st->bit_stream[( st->next_bit_pos )--]; - ( *nb_bits_read )++; - ism_imp = ( ism_imp << 1 ) + byteBuffer; - } - st_ivas->hIsmMetaData[0]->ism_imp = ism_imp; + /* number of transport channels is always 2 for MASA_ISM format */ + /* the number of MASA transport channels was read in ivas_dec_setup() */ + st->next_bit_pos -= MASA_TRANSP_BITS; + *nb_bits_read += MASA_TRANSP_BITS; } - if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) + if ( ivas_format == MASA_ISM_FORMAT && st_ivas->ism_mode != ISM_MODE_NONE ) { - ism_imp = 0; - for ( i = 0; i < ISM_METADATA_FLAG_BITS; i++ ) + /* the number of objects was read */ + st->next_bit_pos -= NO_BITS_MASA_ISM_NO_OBJ; + *nb_bits_read += NO_BITS_MASA_ISM_NO_OBJ; + + if ( st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) { + /* read index of separated object */ + /* nchan_ism should be > 1*/ byteBuffer = st->bit_stream[( st->next_bit_pos )--]; ( *nb_bits_read )++; - ism_imp = ( ism_imp << 1 ) + byteBuffer; + st_ivas->hMasaIsmData->idx_separated_ism = 2 * byteBuffer + st->bit_stream[( st->next_bit_pos )--]; + ( *nb_bits_read )++; + } + else + { + st_ivas->hMasaIsmData->idx_separated_ism = -1; } - st_ivas->hIsmMetaData[0]->ism_imp = ism_imp; - /* reset */ - st_ivas->hIsmMetaData[0]->ism_md_null_flag = 0; - st_ivas->hIsmMetaData[0]->ism_md_lowrate_flag = 0; - if ( st_ivas->hIsmMetaData[0]->ism_imp == ISM_NO_META ) + /* read ISM importance flag (one per object) */ + if ( st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) { - /* read flags */ - st_ivas->hIsmMetaData[0]->ism_md_null_flag = st->bit_stream[( st->next_bit_pos )--]; - ( *nb_bits_read ) += ISM_METADATA_MD_FLAG_BITS; - st_ivas->hIsmMetaData[0]->ism_md_lowrate_flag = st->bit_stream[( st->next_bit_pos )--]; - ( *nb_bits_read ) += ISM_METADATA_INACTIVE_FLAG_BITS; + ism_imp = 0; + for ( i = 0; i < ISM_METADATA_FLAG_BITS; i++ ) + { + byteBuffer = st->bit_stream[( st->next_bit_pos )--]; + ( *nb_bits_read )++; + ism_imp = ( ism_imp << 1 ) + byteBuffer; + } + st_ivas->hIsmMetaData[0]->ism_imp = ism_imp; } - } - else if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) - { - for ( ch = 0; ch < st_ivas->nchan_ism; ch++ ) + + if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) { ism_imp = 0; for ( i = 0; i < ISM_METADATA_FLAG_BITS; i++ ) @@ -226,49 +247,76 @@ ivas_error ivas_masa_decode( ( *nb_bits_read )++; ism_imp = ( ism_imp << 1 ) + byteBuffer; } - st_ivas->hIsmMetaData[ch]->ism_imp = ism_imp; + st_ivas->hIsmMetaData[0]->ism_imp = ism_imp; /* reset */ - st_ivas->hIsmMetaData[ch]->ism_md_null_flag = 0; - st_ivas->hIsmMetaData[ch]->ism_md_lowrate_flag = 0; - if ( st_ivas->hIsmMetaData[ch]->ism_imp == ISM_NO_META ) + st_ivas->hIsmMetaData[0]->ism_md_null_flag = 0; + st_ivas->hIsmMetaData[0]->ism_md_lowrate_flag = 0; + if ( st_ivas->hIsmMetaData[0]->ism_imp == ISM_NO_META ) { /* read flags */ - st_ivas->hIsmMetaData[ch]->ism_md_null_flag = st->bit_stream[( st->next_bit_pos )--]; + st_ivas->hIsmMetaData[0]->ism_md_null_flag = st->bit_stream[( st->next_bit_pos )--]; ( *nb_bits_read ) += ISM_METADATA_MD_FLAG_BITS; - st_ivas->hIsmMetaData[ch]->ism_md_lowrate_flag = st->bit_stream[( st->next_bit_pos )--]; + st_ivas->hIsmMetaData[0]->ism_md_lowrate_flag = st->bit_stream[( st->next_bit_pos )--]; ( *nb_bits_read ) += ISM_METADATA_INACTIVE_FLAG_BITS; } } - st_ivas->flag_omasa_brate = 0; - if ( st_ivas->nchan_ism >= 3 && ivas_total_brate == IVAS_128k ) + else if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) { - st_ivas->flag_omasa_brate = st->bit_stream[( st->next_bit_pos )--]; - ( *nb_bits_read ) += 1; + for ( ch = 0; ch < st_ivas->nchan_ism; ch++ ) + { + ism_imp = 0; + for ( i = 0; i < ISM_METADATA_FLAG_BITS; i++ ) + { + byteBuffer = st->bit_stream[( st->next_bit_pos )--]; + ( *nb_bits_read )++; + ism_imp = ( ism_imp << 1 ) + byteBuffer; + } + st_ivas->hIsmMetaData[ch]->ism_imp = ism_imp; + + /* reset */ + st_ivas->hIsmMetaData[ch]->ism_md_null_flag = 0; + st_ivas->hIsmMetaData[ch]->ism_md_lowrate_flag = 0; + if ( st_ivas->hIsmMetaData[ch]->ism_imp == ISM_NO_META ) + { + /* read flags */ + st_ivas->hIsmMetaData[ch]->ism_md_null_flag = st->bit_stream[( st->next_bit_pos )--]; + ( *nb_bits_read ) += ISM_METADATA_MD_FLAG_BITS; + st_ivas->hIsmMetaData[ch]->ism_md_lowrate_flag = st->bit_stream[( st->next_bit_pos )--]; + ( *nb_bits_read ) += ISM_METADATA_INACTIVE_FLAG_BITS; + } + } + st_ivas->flag_omasa_brate = 0; + if ( st_ivas->nchan_ism >= 3 && ivas_total_brate == IVAS_128k ) + { + st_ivas->flag_omasa_brate = st->bit_stream[( st->next_bit_pos )--]; + ( *nb_bits_read ) += 1; + } } } - } #ifdef NONBE_FIX_984_OMASA_EXT_OUTPUT - /* read 2 bits: - '00' - MASA format at the encoder - '01' - MASA_ISM_FORMAT at the encoder, with 1 object - '10' - MASA_ISM_FORMAT at the encoder, with 2 objects - '11' - MASA_ISM_FORMAT at the encoder, with 3 or 4 objects - reading if 3 or 4 object is performed later - */ - byteBuffer = st->bit_stream[( st->next_bit_pos )--]; - byteBuffer = byteBuffer + 2 * st->bit_stream[( st->next_bit_pos )--]; +#ifndef NONBE_FIX_1074_NOBJ_SIGNAL_OMASA_LBR + /* read 2 bits: + '00' - MASA format at the encoder + '01' - MASA_ISM_FORMAT at the encoder, with 1 object + '10' - MASA_ISM_FORMAT at the encoder, with 2 objects + '11' - MASA_ISM_FORMAT at the encoder, with 3 or 4 objects + reading if 3 or 4 object is performed later + */ +#endif + byteBuffer = st->bit_stream[( st->next_bit_pos )--]; + byteBuffer = byteBuffer + 2 * st->bit_stream[( st->next_bit_pos )--]; - if ( byteBuffer == 0 && ivas_format == MASA_FORMAT ) - { - hMasa->config.input_ivas_format = MASA_FORMAT; - } - else - { - hMasa->config.input_ivas_format = MASA_ISM_FORMAT; - } + if ( byteBuffer == 0 && ivas_format == MASA_FORMAT ) + { + hMasa->config.input_ivas_format = MASA_FORMAT; + } + else + { + hMasa->config.input_ivas_format = MASA_ISM_FORMAT; + } #else /* read the MASA_ISM_FORMAT bit */ byteBuffer = st->bit_stream[( st->next_bit_pos )--]; @@ -283,12 +331,15 @@ ivas_error ivas_masa_decode( /* reserved bit */ byteBuffer = st->bit_stream[( st->next_bit_pos )--]; #endif - *nb_bits_read += MASA_HEADER_BITS; + *nb_bits_read += MASA_HEADER_BITS; - /* read number of directions */ - byteBuffer = st->bit_stream[( st->next_bit_pos )--]; - ( *nb_bits_read )++; - hMasa->config.numberOfDirections = (uint8_t) ( byteBuffer + 1 ); + /* read number of directions */ + byteBuffer = st->bit_stream[( st->next_bit_pos )--]; + ( *nb_bits_read )++; + hMasa->config.numberOfDirections = (uint8_t) ( byteBuffer + 1 ); +#ifdef NONBE_FIX_1074_NOBJ_SIGNAL_OMASA_LBR + } +#endif } else { diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index 3c9eb20d2..6c4567b55 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -421,6 +421,18 @@ ivas_error ivas_masa_encode( #ifdef NONBE_FIX_984_OMASA_EXT_OUTPUT if ( ivas_format == MASA_ISM_FORMAT && ism_mode == ISM_MODE_NONE ) { +#ifdef NONBE_FIX_1074_NOBJ_SIGNAL_OMASA_LBR + /* use the MASA number of transport channels bit to signal if there are 1 or 2 objects */ + if ( nchan_ism == 1 || nchan_ism == 2 ) + { + push_next_indice( hMetaData, nchan_ism - 1, MASA_TRANSP_BITS ); + } + else + { + /* for 3 or 4 objects write already the number of MASA directions */ + push_next_indice( hMetaData, hQMetaData->no_directions - 1, MASA_TRANSP_BITS ); + } +#else /* use the MASA number of transport channels bit to signal if there are 3 or 4 objects */ if ( nchan_ism == 4 ) { @@ -430,6 +442,7 @@ ivas_error ivas_masa_encode( { push_next_indice( hMetaData, 0, MASA_TRANSP_BITS ); } +#endif } else { @@ -445,6 +458,16 @@ ivas_error ivas_masa_encode( if ( ivas_format == MASA_ISM_FORMAT && ism_mode == ISM_MODE_NONE ) { #ifdef NONBE_FIX_984_OMASA_EXT_OUTPUT +#ifdef NONBE_FIX_1074_NOBJ_SIGNAL_OMASA_LBR + if ( nchan_ism >= 3 ) /* if 3 or 4 objects */ + { + push_next_indice( hMetaData, 5 - nchan_ism, MASA_HEADER_BITS ); + } + else + { + push_next_indice( hMetaData, 3, MASA_HEADER_BITS ); + } +#else if ( nchan_ism <= 3 ) { push_next_indice( hMetaData, nchan_ism, MASA_HEADER_BITS ); @@ -453,6 +476,7 @@ ivas_error ivas_masa_encode( { push_next_indice( hMetaData, nchan_ism - 1, MASA_HEADER_BITS ); } +#endif hQMetaData->metadata_max_bits -= MASA_HEADER_BITS; #else /* signal MASA_ISM_FORMAT to decoder */ @@ -469,9 +493,16 @@ ivas_error ivas_masa_encode( push_next_indice( hMetaData, 0, MASA_HEADER_BITS ); hQMetaData->metadata_max_bits -= MASA_HEADER_BITS; } - /* write number of directions */ - push_next_indice( hMetaData, hQMetaData->no_directions - 1, 1 ); - hQMetaData->metadata_max_bits -= 1; +#ifdef NONBE_FIX_1074_NOBJ_SIGNAL_OMASA_LBR + if ( !( ivas_format == MASA_ISM_FORMAT && ism_mode == ISM_MODE_NONE && nchan_ism > 2 ) ) + { +#endif + /* write number of directions */ + push_next_indice( hMetaData, hQMetaData->no_directions - 1, 1 ); + hQMetaData->metadata_max_bits -= 1; +#ifdef NONBE_FIX_1074_NOBJ_SIGNAL_OMASA_LBR + } +#endif /* write subframe mode */ push_next_indice( hMetaData, hQMetaData->q_direction[0].cfg.nblocks == 1 ? 1 : 0, MASA_SUBFRAME_BITS ); @@ -2603,7 +2634,7 @@ static void masa_metadata_direction_alignment( prev_ele_dir2_sin = sin_ele2; } } /* sf */ - } /* band */ + } /* band */ return; } -- GitLab From 5d71c445f3045cd020c63aba010e5c5032ad207f Mon Sep 17 00:00:00 2001 From: Tapani Pihlajakuja Date: Mon, 4 Aug 2025 13:57:43 +0300 Subject: [PATCH 2/2] Clang format --- lib_enc/ivas_masa_enc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index 6c4567b55..285b47aae 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -2634,7 +2634,7 @@ static void masa_metadata_direction_alignment( prev_ele_dir2_sin = sin_ele2; } } /* sf */ - } /* band */ + } /* band */ return; } -- GitLab