diff --git a/lib_com/options.h b/lib_com/options.h index b9a0076452eabd29ed16a4d8879329127d7120c7..50e287e8ac07a55b98d20038562698e2317e1204 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -196,6 +196,7 @@ #define NONBE_FIX_MC_LFE_LPF /* Dlb: Adding the LFE LPF filter back for MC content. */ #define NONBE_FIX_1052_SBA_EXT /* Dlb: SBA external output support */ #define FIX_1082_INSTRUM_FAILED_LC3PLUS /* VoiceAge: issue 1082: fix ambiguous syntax in LC3Plus code leading to fails of instrumented builds */ +#define NONBE_FIX_1074_NOBJ_SIGNAL_OMASA_LBR /* Nok: issue 1074 fixing number of objects signaling in OMASA low rate */ /* #################### End BASOP porting switches ############################ */ diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index 9492517f1d7a5164ec3403a88e939460c78b5cbf..5e3c10c830f9a2eb27012483937fdece8e52e8e2 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -385,12 +385,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 156a8ce77d589d2e28430bf12a56a28b1e1222cf..b4ea4dbecd596429c3fe71800dffaa49396f0d00 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 f5b4b49f3951d11ad1920aa41d70a2260c0645ad..6255712ec3aa028dd41f9895c9e26a48608ea5bf 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 );