From 42a79f491c4a211be260c638d78e85ae80b5c9ac Mon Sep 17 00:00:00 2001 From: advasila Date: Wed, 13 Sep 2023 21:09:43 +0300 Subject: [PATCH 01/11] fix for very mow number of bits in MASA metadata --- lib_com/options.h | 1 + lib_dec/ivas_masa_dec.c | 10 ++++++++++ lib_enc/ivas_enc.c | 11 ++++++++++- lib_enc/ivas_masa_enc.c | 10 ++++++++++ 4 files changed, 31 insertions(+), 1 deletion(-) diff --git a/lib_com/options.h b/lib_com/options.h index 7e314469c2..f3b004b801 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -183,6 +183,7 @@ #define NONBE_FIX_738_SBA_BR_SW_ASAN /* FhG: issue 738: fixes bug when switching to an MCT bitrate and previous frame was ACELP */ #define NONBE_CR_FIX_735_SBA_HP20_BRATE_SWITCHING /* VA: Issue 735: Resolve "HP20 filtering bug in SBA/OSBA bitrate switching" */ +#define FIX /* ##################### End NON-BE switches ########################### */ diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index c5a7c881be..5231c2c259 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -363,6 +363,16 @@ ivas_error ivas_masa_decode( else { *nb_bits_read += ivas_qmetadata_dec_decode( hQMetaData, st->bit_stream, &st->next_bit_pos, 0 ); +#ifdef FIX + if ( st_ivas->ivas_format == MASA_ISM_FORMAT && st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ && st_ivas->hIsmMetaData[0]->ism_imp == ISM_INACTIVE_IMP ) + { + while ( *nb_bits_read < 32 ) + { + byteBuffer = st->bit_stream[( st->next_bit_pos )--]; + ( *nb_bits_read )++; + } + } +#endif } 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 ) diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index 7e0d245b4a..9650fbf7e4 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -363,7 +363,16 @@ ivas_error ivas_enc( hMetaData->ind_list = st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData->ind_list + st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData->nb_ind_tot; st_ivas->hCPE[0]->hCoreCoder[0]->hBstr->ind_list = st_ivas->hSCE[st_ivas->nSCE - 1]->hCoreCoder[0]->hBstr->ind_list + st_ivas->hSCE[st_ivas->nSCE - 1]->hCoreCoder[0]->hBstr->nb_ind_tot; } - +#ifdef FIX + if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) + { + if ( st_ivas->hIsmMetaData[0]->ism_imp == ISM_INACTIVE_IMP ) + { + /* set minimum bitrate for metadata */ + nb_bits_metadata[0] = 32; + } + } +#endif /* Encode MASA parameters and write MASA metadata bitstream */ if ( ( error = ivas_masa_encode( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, nb_bits_metadata, st_ivas->nchan_transport, ivas_format, ivas_total_brate, st_ivas->hEncoderConfig->Opt_DTX_ON, st_ivas->nchan_transport == 2 ? st_ivas->hCPE[0]->element_mode : -1, st_ivas->ism_mode, hEncoderConfig->nchan_ism, st_ivas->hIsmMetaData, idx_separated_object, st_ivas->hOMasa, st_ivas->hIsmMetaData[0]->ism_imp, flag_omasa_ener_brate ) ) != IVAS_ERR_OK ) diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index a98e42739b..98c480e889 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -506,7 +506,17 @@ ivas_error ivas_masa_encode( } else { + ivas_qmetadata_enc_encode( hMetaData, hQMetaData, 0 ); + #ifdef FIX + if ( ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) + { + if ( hMetaData->nb_bits_tot < nb_bits_metadata[0] ) + { + push_next_indice( hMetaData, 0, nb_bits_metadata[0] - hMetaData->nb_bits_tot ); + } + } + #endif } if ( ivas_format == MASA_ISM_FORMAT && ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) -- GitLab From 2582f79bb7ef8299f80ffd623c3f9222f2637557 Mon Sep 17 00:00:00 2001 From: advasila Date: Fri, 15 Sep 2023 08:44:04 +0300 Subject: [PATCH 02/11] fix omasa inactive separated object --- lib_com/ivas_cnst.h | 3 +++ lib_com/options.h | 2 +- lib_dec/ivas_masa_dec.c | 4 ++-- lib_enc/ivas_enc.c | 11 +---------- lib_enc/ivas_masa_enc.c | 10 +++++----- 5 files changed, 12 insertions(+), 18 deletions(-) diff --git a/lib_com/ivas_cnst.h b/lib_com/ivas_cnst.h index ec8674238c..168611d5b2 100755 --- a/lib_com/ivas_cnst.h +++ b/lib_com/ivas_cnst.h @@ -1234,6 +1234,9 @@ enum #define MASA_MAXIMUM_TWO_DIR_BANDS 24 #define NBITS_HR_COH 4 +#ifdef NONBE_FIX_797_OMASA_INACTIVE_SEP_OBJ +#define MINIMUM_MASA_BITS_OMASA_INACTIVE 32 +#endif typedef enum { MASA_STEREO_NOT_DEFINED, diff --git a/lib_com/options.h b/lib_com/options.h index f3b004b801..81f29670fc 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -183,8 +183,8 @@ #define NONBE_FIX_738_SBA_BR_SW_ASAN /* FhG: issue 738: fixes bug when switching to an MCT bitrate and previous frame was ACELP */ #define NONBE_CR_FIX_735_SBA_HP20_BRATE_SWITCHING /* VA: Issue 735: Resolve "HP20 filtering bug in SBA/OSBA bitrate switching" */ +#define NONBE_FIX_797_OMASA_INACTIVE_SEP_OBJ /* Nokia: issue 797: fix crash when the separated object is inactive and the MASA metadata is using very few bits */ #define FIX - /* ##################### End NON-BE switches ########################### */ /* ################## End DEVELOPMENT switches ######################### */ diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index 5231c2c259..1d3875e3fb 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -363,10 +363,10 @@ ivas_error ivas_masa_decode( else { *nb_bits_read += ivas_qmetadata_dec_decode( hQMetaData, st->bit_stream, &st->next_bit_pos, 0 ); -#ifdef FIX +#ifdef NONBE_FIX_797_OMASA_INACTIVE_SEP_OBJ if ( st_ivas->ivas_format == MASA_ISM_FORMAT && st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ && st_ivas->hIsmMetaData[0]->ism_imp == ISM_INACTIVE_IMP ) { - while ( *nb_bits_read < 32 ) + while ( *nb_bits_read < MINIMUM_MASA_BITS_OMASA_INACTIVE ) { byteBuffer = st->bit_stream[( st->next_bit_pos )--]; ( *nb_bits_read )++; diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index 9650fbf7e4..7e0d245b4a 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -363,16 +363,7 @@ ivas_error ivas_enc( hMetaData->ind_list = st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData->ind_list + st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData->nb_ind_tot; st_ivas->hCPE[0]->hCoreCoder[0]->hBstr->ind_list = st_ivas->hSCE[st_ivas->nSCE - 1]->hCoreCoder[0]->hBstr->ind_list + st_ivas->hSCE[st_ivas->nSCE - 1]->hCoreCoder[0]->hBstr->nb_ind_tot; } -#ifdef FIX - if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) - { - if ( st_ivas->hIsmMetaData[0]->ism_imp == ISM_INACTIVE_IMP ) - { - /* set minimum bitrate for metadata */ - nb_bits_metadata[0] = 32; - } - } -#endif + /* Encode MASA parameters and write MASA metadata bitstream */ if ( ( error = ivas_masa_encode( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, nb_bits_metadata, st_ivas->nchan_transport, ivas_format, ivas_total_brate, st_ivas->hEncoderConfig->Opt_DTX_ON, st_ivas->nchan_transport == 2 ? st_ivas->hCPE[0]->element_mode : -1, st_ivas->ism_mode, hEncoderConfig->nchan_ism, st_ivas->hIsmMetaData, idx_separated_object, st_ivas->hOMasa, st_ivas->hIsmMetaData[0]->ism_imp, flag_omasa_ener_brate ) ) != IVAS_ERR_OK ) diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index 98c480e889..24746917f2 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -508,15 +508,15 @@ ivas_error ivas_masa_encode( { ivas_qmetadata_enc_encode( hMetaData, hQMetaData, 0 ); - #ifdef FIX - if ( ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) +#ifdef NONBE_FIX_797_OMASA_INACTIVE_SEP_OBJ + if ( ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ && hIsmMetaData[0]->ism_imp == ISM_INACTIVE_IMP ) { - if ( hMetaData->nb_bits_tot < nb_bits_metadata[0] ) + if ( hMetaData->nb_bits_tot < MINIMUM_MASA_BITS_OMASA_INACTIVE ) { - push_next_indice( hMetaData, 0, nb_bits_metadata[0] - hMetaData->nb_bits_tot ); + push_next_indice( hMetaData, 0, MINIMUM_MASA_BITS_OMASA_INACTIVE - hMetaData->nb_bits_tot ); } } - #endif +#endif } if ( ivas_format == MASA_ISM_FORMAT && ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) -- GitLab From abee896c83082513467d16cc78b7d589676e56c6 Mon Sep 17 00:00:00 2001 From: advasila Date: Sun, 17 Sep 2023 16:56:45 +0300 Subject: [PATCH 03/11] clean fix --- lib_com/options.h | 2 +- lib_enc/ivas_masa_enc.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 81f29670fc..a75cb0a65b 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -184,7 +184,7 @@ #define NONBE_CR_FIX_735_SBA_HP20_BRATE_SWITCHING /* VA: Issue 735: Resolve "HP20 filtering bug in SBA/OSBA bitrate switching" */ #define NONBE_FIX_797_OMASA_INACTIVE_SEP_OBJ /* Nokia: issue 797: fix crash when the separated object is inactive and the MASA metadata is using very few bits */ -#define FIX + /* ##################### End NON-BE switches ########################### */ /* ################## End DEVELOPMENT switches ######################### */ diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index 24746917f2..7e6998c757 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -513,7 +513,7 @@ ivas_error ivas_masa_encode( { if ( hMetaData->nb_bits_tot < MINIMUM_MASA_BITS_OMASA_INACTIVE ) { - push_next_indice( hMetaData, 0, MINIMUM_MASA_BITS_OMASA_INACTIVE - hMetaData->nb_bits_tot ); + push_next_indice( hMetaData, 0, MINIMUM_MASA_BITS_OMASA_INACTIVE - hMetaData->nb_bits_tot ); } } #endif -- GitLab From 2e8d572f690da0569b19d6ad3e561f1c3d4eb7c3 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 18 Sep 2023 14:28:29 +0200 Subject: [PATCH 04/11] alternative fix NONBE_FIX_797_OMASA_INACTIVE_SEP_OBJ_ALT --- lib_com/options.h | 4 ++-- lib_dec/acelp_core_dec.c | 4 ++++ lib_enc/acelp_core_enc.c | 4 ++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index a75cb0a65b..595db54feb 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -182,8 +182,8 @@ #define NONBE_FIX_ISM_DTX_INFINITE_CNG_ON_TRAILING_SILENCE /* FhG: fix for cng in ISM DTX on sudden silence periods - JBM addon (issue 552) */ #define NONBE_FIX_738_SBA_BR_SW_ASAN /* FhG: issue 738: fixes bug when switching to an MCT bitrate and previous frame was ACELP */ #define NONBE_CR_FIX_735_SBA_HP20_BRATE_SWITCHING /* VA: Issue 735: Resolve "HP20 filtering bug in SBA/OSBA bitrate switching" */ - -#define NONBE_FIX_797_OMASA_INACTIVE_SEP_OBJ /* Nokia: issue 797: fix crash when the separated object is inactive and the MASA metadata is using very few bits */ +/*#define NONBE_FIX_797_OMASA_INACTIVE_SEP_OBJ*/ /* Nokia: issue 797: fix crash when the separated object is inactive and the MASA metadata is using very few bits */ +#define NONBE_FIX_797_OMASA_INACTIVE_SEP_OBJ_ALT /* VA: issue 797: alternative fix of crash when the separated object is inactive and the MASA metadata is using very few bits */ /* ##################### End NON-BE switches ########################### */ diff --git a/lib_dec/acelp_core_dec.c b/lib_dec/acelp_core_dec.c index f686381d54..fb57a65e94 100644 --- a/lib_dec/acelp_core_dec.c +++ b/lib_dec/acelp_core_dec.c @@ -803,7 +803,11 @@ ivas_error acelp_core_dec( { decod_tran( st, st->L_frame, tc_subfr, Aq, Es_pred, pitch_buf, voice_factors, exc, exc2, bwe_exc, unbits, sharpFlag, gain_buf ); } +#ifdef NONBE_FIX_797_OMASA_INACTIVE_SEP_OBJ_ALT + else if ( st->coder_type == AUDIO || ( st->coder_type == INACTIVE && ( st->core_brate + st->extl_brate < MAX_GSC_INACTIVE_BRATE ) ) ) +#else else if ( st->coder_type == AUDIO || ( st->coder_type == INACTIVE && st->total_brate <= MAX_GSC_INACTIVE_BRATE ) ) +#endif { /* AUDIO and INACTIVE frames (coded by GSC technology) */ decod_audio( st, dct_exc_tmp, Aq, &tmp_noise, pitch_buf, voice_factors, exc, exc2, bwe_exc, lsf_new, gain_buf, tdm_lp_reuse_flag, tdm_low_rate_mode, tdm_Pitch_reuse_flag, p_tdm_Pri_pitch_buf ); diff --git a/lib_enc/acelp_core_enc.c b/lib_enc/acelp_core_enc.c index 42c5907229..48233de47a 100644 --- a/lib_enc/acelp_core_enc.c +++ b/lib_enc/acelp_core_enc.c @@ -563,7 +563,11 @@ ivas_error acelp_core_enc( encod_gen_voic( st, inp, Aw, Aq, Es_pred, res, syn, exc, exc2, pitch_buf, voice_factors, bwe_exc, unbits, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf ); } } +#ifdef NONBE_FIX_797_OMASA_INACTIVE_SEP_OBJ_ALT + else if ( st->coder_type == AUDIO || ( st->coder_type == INACTIVE && ( st->core_brate + st->extl_brate < MAX_GSC_INACTIVE_BRATE ) ) ) +#else else if ( st->coder_type == AUDIO || ( st->coder_type == INACTIVE && st->total_brate <= MAX_GSC_INACTIVE_BRATE ) ) +#endif { /* AUDIO and INACTIVE frames (coded by GSC technology) */ encod_audio( st, inp, Aw, Aq, res, syn, exc, pitch_buf, voice_factors, bwe_exc, attack_flag, lsf_new, &tmp_noise, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf ); -- GitLab From c10c063da02a5e509d9aeb9c1938b4b1dfaa6d60 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 18 Sep 2023 16:02:35 +0200 Subject: [PATCH 05/11] fix inside NONBE_FIX_797_OMASA_INACTIVE_SEP_OBJ_ALT --- lib_dec/acelp_core_dec.c | 2 +- lib_enc/acelp_core_enc.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib_dec/acelp_core_dec.c b/lib_dec/acelp_core_dec.c index fb57a65e94..d88056f281 100644 --- a/lib_dec/acelp_core_dec.c +++ b/lib_dec/acelp_core_dec.c @@ -804,7 +804,7 @@ ivas_error acelp_core_dec( decod_tran( st, st->L_frame, tc_subfr, Aq, Es_pred, pitch_buf, voice_factors, exc, exc2, bwe_exc, unbits, sharpFlag, gain_buf ); } #ifdef NONBE_FIX_797_OMASA_INACTIVE_SEP_OBJ_ALT - else if ( st->coder_type == AUDIO || ( st->coder_type == INACTIVE && ( st->core_brate + st->extl_brate < MAX_GSC_INACTIVE_BRATE ) ) ) + else if ( st->coder_type == AUDIO || ( st->coder_type == INACTIVE && ( st->core_brate + st->extl_brate <= MAX_GSC_INACTIVE_BRATE ) ) ) #else else if ( st->coder_type == AUDIO || ( st->coder_type == INACTIVE && st->total_brate <= MAX_GSC_INACTIVE_BRATE ) ) #endif diff --git a/lib_enc/acelp_core_enc.c b/lib_enc/acelp_core_enc.c index 48233de47a..834ae9b5f3 100644 --- a/lib_enc/acelp_core_enc.c +++ b/lib_enc/acelp_core_enc.c @@ -564,7 +564,7 @@ ivas_error acelp_core_enc( } } #ifdef NONBE_FIX_797_OMASA_INACTIVE_SEP_OBJ_ALT - else if ( st->coder_type == AUDIO || ( st->coder_type == INACTIVE && ( st->core_brate + st->extl_brate < MAX_GSC_INACTIVE_BRATE ) ) ) + else if ( st->coder_type == AUDIO || ( st->coder_type == INACTIVE && ( st->core_brate + st->extl_brate <= MAX_GSC_INACTIVE_BRATE ) ) ) #else else if ( st->coder_type == AUDIO || ( st->coder_type == INACTIVE && st->total_brate <= MAX_GSC_INACTIVE_BRATE ) ) #endif -- GitLab From f4e468fa12a98bc718cdb82eca98bd3bad74f749 Mon Sep 17 00:00:00 2001 From: advasila Date: Tue, 19 Sep 2023 09:25:24 +0300 Subject: [PATCH 06/11] 797 leave one switch --- lib_com/ivas_cnst.h | 3 --- lib_com/options.h | 3 +-- lib_dec/acelp_core_dec.c | 2 +- lib_dec/ivas_masa_dec.c | 10 ---------- lib_enc/acelp_core_enc.c | 2 +- lib_enc/ivas_masa_enc.c | 10 ---------- 6 files changed, 3 insertions(+), 27 deletions(-) diff --git a/lib_com/ivas_cnst.h b/lib_com/ivas_cnst.h index d9f673286b..df48167c01 100755 --- a/lib_com/ivas_cnst.h +++ b/lib_com/ivas_cnst.h @@ -1236,9 +1236,6 @@ enum #define MASA_MAXIMUM_TWO_DIR_BANDS 24 #define NBITS_HR_COH 4 -#ifdef NONBE_FIX_797_OMASA_INACTIVE_SEP_OBJ -#define MINIMUM_MASA_BITS_OMASA_INACTIVE 32 -#endif typedef enum { MASA_STEREO_NOT_DEFINED, diff --git a/lib_com/options.h b/lib_com/options.h index 04f48506a4..c71c7d3a5a 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -200,8 +200,7 @@ #define NONBE_FIX_738_SBA_BR_SW_ASAN /* FhG: issue 738: fixes bug when switching to an MCT bitrate and previous frame was ACELP */ #define NONBE_CR_FIX_735_SBA_HP20_BRATE_SWITCHING /* VA: Issue 735: Resolve "HP20 filtering bug in SBA/OSBA bitrate switching" */ #define NONBE_FIX_588_UPDATE_FASTCONV_SD /* FhG: issue 588: update FastConv SD HRTFs in CLDFB domain with new conversion method */ -/*#define NONBE_FIX_797_OMASA_INACTIVE_SEP_OBJ*/ /* Nokia: issue 797: fix crash when the separated object is inactive and the MASA metadata is using very few bits */ -#define NONBE_FIX_797_OMASA_INACTIVE_SEP_OBJ_ALT /* VA: issue 797: alternative fix of crash when the separated object is inactive and the MASA metadata is using very few bits */ +#define NONBE_FIX_797_OMASA_INACTIVE_SEP_OBJ /* VA: issue 797: fix of crash when the separated object is inactive and the MASA metadata is using very few bits */ /* ##################### End NON-BE switches ########################### */ diff --git a/lib_dec/acelp_core_dec.c b/lib_dec/acelp_core_dec.c index d88056f281..f638a6abda 100644 --- a/lib_dec/acelp_core_dec.c +++ b/lib_dec/acelp_core_dec.c @@ -803,7 +803,7 @@ ivas_error acelp_core_dec( { decod_tran( st, st->L_frame, tc_subfr, Aq, Es_pred, pitch_buf, voice_factors, exc, exc2, bwe_exc, unbits, sharpFlag, gain_buf ); } -#ifdef NONBE_FIX_797_OMASA_INACTIVE_SEP_OBJ_ALT +#ifdef NONBE_FIX_797_OMASA_INACTIVE_SEP_OBJ else if ( st->coder_type == AUDIO || ( st->coder_type == INACTIVE && ( st->core_brate + st->extl_brate <= MAX_GSC_INACTIVE_BRATE ) ) ) #else else if ( st->coder_type == AUDIO || ( st->coder_type == INACTIVE && st->total_brate <= MAX_GSC_INACTIVE_BRATE ) ) diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index 8578c156f1..af152d2a8d 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -363,16 +363,6 @@ ivas_error ivas_masa_decode( else { *nb_bits_read += ivas_qmetadata_dec_decode( hQMetaData, st->bit_stream, &st->next_bit_pos, 0 ); -#ifdef NONBE_FIX_797_OMASA_INACTIVE_SEP_OBJ - if ( st_ivas->ivas_format == MASA_ISM_FORMAT && st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ && st_ivas->hIsmMetaData[0]->ism_imp == ISM_INACTIVE_IMP ) - { - while ( *nb_bits_read < MINIMUM_MASA_BITS_OMASA_INACTIVE ) - { - byteBuffer = st->bit_stream[( st->next_bit_pos )--]; - ( *nb_bits_read )++; - } - } -#endif } 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 ) diff --git a/lib_enc/acelp_core_enc.c b/lib_enc/acelp_core_enc.c index 834ae9b5f3..98efc50db4 100644 --- a/lib_enc/acelp_core_enc.c +++ b/lib_enc/acelp_core_enc.c @@ -563,7 +563,7 @@ ivas_error acelp_core_enc( encod_gen_voic( st, inp, Aw, Aq, Es_pred, res, syn, exc, exc2, pitch_buf, voice_factors, bwe_exc, unbits, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf ); } } -#ifdef NONBE_FIX_797_OMASA_INACTIVE_SEP_OBJ_ALT +#ifdef NONBE_FIX_797_OMASA_INACTIVE_SEP_OBJ else if ( st->coder_type == AUDIO || ( st->coder_type == INACTIVE && ( st->core_brate + st->extl_brate <= MAX_GSC_INACTIVE_BRATE ) ) ) #else else if ( st->coder_type == AUDIO || ( st->coder_type == INACTIVE && st->total_brate <= MAX_GSC_INACTIVE_BRATE ) ) diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index 7e6998c757..a98e42739b 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -506,17 +506,7 @@ ivas_error ivas_masa_encode( } else { - ivas_qmetadata_enc_encode( hMetaData, hQMetaData, 0 ); -#ifdef NONBE_FIX_797_OMASA_INACTIVE_SEP_OBJ - if ( ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ && hIsmMetaData[0]->ism_imp == ISM_INACTIVE_IMP ) - { - if ( hMetaData->nb_bits_tot < MINIMUM_MASA_BITS_OMASA_INACTIVE ) - { - push_next_indice( hMetaData, 0, MINIMUM_MASA_BITS_OMASA_INACTIVE - hMetaData->nb_bits_tot ); - } - } -#endif } if ( ivas_format == MASA_ISM_FORMAT && ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) -- GitLab From 0c934c43ead51530fe88665789a4479eccdfa71a Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 19 Sep 2023 12:59:43 +0200 Subject: [PATCH 07/11] update NONBE_FIX_797_OMASA_INACTIVE_SEP_OBJ - take into account also 'icbwe_brate' --- Makefile | 2 +- lib_dec/acelp_core_dec.c | 2 +- lib_dec/decision_matrix_dec.c | 4 +++- lib_dec/init_dec.c | 3 +++ lib_dec/ivas_decision_matrix_dec.c | 3 +++ lib_dec/stat_dec.h | 29 ++++++++++++++------------ lib_enc/acelp_core_enc.c | 2 +- lib_enc/decision_matrix_enc.c | 3 +++ lib_enc/evs_enc.c | 3 +++ lib_enc/init_enc.c | 3 +++ lib_enc/ivas_decision_matrix_enc.c | 3 +++ lib_enc/stat_enc.h | 33 ++++++++++++++++-------------- 12 files changed, 58 insertions(+), 32 deletions(-) diff --git a/Makefile b/Makefile index 5cf9df3e29..f4654e41fe 100644 --- a/Makefile +++ b/Makefile @@ -67,7 +67,7 @@ LDLIBS += -lm CCCLANG = clang ifeq "$(CLANG)" "1" CC = $(CCCLANG) -CFLAGS += -fsanitize=memory +CFLAGS += -fsanitize=memory -fsanitize-memory-track-origins LDFLAGS += -fsanitize=memory endif ifeq "$(CLANG)" "2" diff --git a/lib_dec/acelp_core_dec.c b/lib_dec/acelp_core_dec.c index f638a6abda..6317574b2f 100644 --- a/lib_dec/acelp_core_dec.c +++ b/lib_dec/acelp_core_dec.c @@ -804,7 +804,7 @@ ivas_error acelp_core_dec( decod_tran( st, st->L_frame, tc_subfr, Aq, Es_pred, pitch_buf, voice_factors, exc, exc2, bwe_exc, unbits, sharpFlag, gain_buf ); } #ifdef NONBE_FIX_797_OMASA_INACTIVE_SEP_OBJ - else if ( st->coder_type == AUDIO || ( st->coder_type == INACTIVE && ( st->core_brate + st->extl_brate <= MAX_GSC_INACTIVE_BRATE ) ) ) + else if ( st->coder_type == AUDIO || ( st->coder_type == INACTIVE && ( st->core_brate + st->extl_brate + st->icbwe_brate <= MAX_GSC_INACTIVE_BRATE ) ) ) #else else if ( st->coder_type == AUDIO || ( st->coder_type == INACTIVE && st->total_brate <= MAX_GSC_INACTIVE_BRATE ) ) #endif diff --git a/lib_dec/decision_matrix_dec.c b/lib_dec/decision_matrix_dec.c index 84e6e9573e..4765b5b5f2 100644 --- a/lib_dec/decision_matrix_dec.c +++ b/lib_dec/decision_matrix_dec.c @@ -405,7 +405,9 @@ void decision_matrix_dec( /* set core bitrate */ st->core_brate = st->total_brate - st->extl_brate; - +#ifdef NONBE_FIX_797_OMASA_INACTIVE_SEP_OBJ + st->icbwe_brate = 0; +#endif /*-----------------------------------------------------------------* * Read HQ signaling bits from the bitstream diff --git a/lib_dec/init_dec.c b/lib_dec/init_dec.c index a094710f06..85dcdc4f14 100644 --- a/lib_dec/init_dec.c +++ b/lib_dec/init_dec.c @@ -82,6 +82,9 @@ ivas_error init_decoder( st->bwidth = NB; st->last_bwidth = NB; st->extl_brate = 0; +#ifdef NONBE_FIX_797_OMASA_INACTIVE_SEP_OBJ + st->icbwe_brate = 0; +#endif st->coder_type = GENERIC; st->last_coder_type = GENERIC; diff --git a/lib_dec/ivas_decision_matrix_dec.c b/lib_dec/ivas_decision_matrix_dec.c index d238d43df7..e98f72520f 100644 --- a/lib_dec/ivas_decision_matrix_dec.c +++ b/lib_dec/ivas_decision_matrix_dec.c @@ -344,6 +344,9 @@ void ivas_decision_matrix_dec( /* set core bitrate */ st->core_brate = st->total_brate - st->extl_brate - icbwe_brate; +#ifdef NONBE_FIX_797_OMASA_INACTIVE_SEP_OBJ + st->icbwe_brate = icbwe_brate; +#endif /*-----------------------------------------------------------------* * Read transform core (TCX vs. HQ) signaling bit from the bitstream diff --git a/lib_dec/stat_dec.h b/lib_dec/stat_dec.h index c971cf0e21..89998dafba 100644 --- a/lib_dec/stat_dec.h +++ b/lib_dec/stat_dec.h @@ -923,19 +923,22 @@ typedef struct Decoder_State int16_t coder_type; /* coder type */ int16_t transform_type[2]; /* TCX20/10/5 mode in each subframe */ int32_t core_brate; /* core bitrate */ - int32_t last_core_brate; /* previous frame core bitrate */ - int16_t extl; /* extension layer */ - int16_t extl_orig; /* extension layer */ - int16_t last_extl; /* previous extension layer */ - int32_t extl_brate; /* extension layer bitrate */ - int32_t extl_brate_orig; /* extension layer bitrate */ - int16_t L_frame; /* ACELP core internal frame length */ - int16_t bwidth; /* encoded signal bandwidth */ - int16_t Opt_AMR_WB; /* flag indicating AMR-WB IO mode */ - int16_t ini_frame; /* initialization frames counter */ - int16_t prev_coder_type; /* coding type of last frame */ - int16_t low_rate_mode; /* low-rate mode flag */ - int16_t last_low_rate_mode; /* previous frame low-rate mode flag */ +#ifdef NONBE_FIX_797_OMASA_INACTIVE_SEP_OBJ + int32_t icbwe_brate; /* IC-BWE bitrate */ +#endif + int32_t last_core_brate; /* previous frame core bitrate */ + int16_t extl; /* extension layer */ + int16_t extl_orig; /* extension layer */ + int16_t last_extl; /* previous extension layer */ + int32_t extl_brate; /* extension layer bitrate */ + int32_t extl_brate_orig; /* extension layer bitrate */ + int16_t L_frame; /* ACELP core internal frame length */ + int16_t bwidth; /* encoded signal bandwidth */ + int16_t Opt_AMR_WB; /* flag indicating AMR-WB IO mode */ + int16_t ini_frame; /* initialization frames counter */ + int16_t prev_coder_type; /* coding type of last frame */ + int16_t low_rate_mode; /* low-rate mode flag */ + int16_t last_low_rate_mode; /* previous frame low-rate mode flag */ /*----------------------------------------------------------------------------------* * ACELP core parameters diff --git a/lib_enc/acelp_core_enc.c b/lib_enc/acelp_core_enc.c index 98efc50db4..a473237c6a 100644 --- a/lib_enc/acelp_core_enc.c +++ b/lib_enc/acelp_core_enc.c @@ -564,7 +564,7 @@ ivas_error acelp_core_enc( } } #ifdef NONBE_FIX_797_OMASA_INACTIVE_SEP_OBJ - else if ( st->coder_type == AUDIO || ( st->coder_type == INACTIVE && ( st->core_brate + st->extl_brate <= MAX_GSC_INACTIVE_BRATE ) ) ) + else if ( st->coder_type == AUDIO || ( st->coder_type == INACTIVE && ( st->core_brate + st->extl_brate + st->icbwe_brate <= MAX_GSC_INACTIVE_BRATE ) ) ) #else else if ( st->coder_type == AUDIO || ( st->coder_type == INACTIVE && st->total_brate <= MAX_GSC_INACTIVE_BRATE ) ) #endif diff --git a/lib_enc/decision_matrix_enc.c b/lib_enc/decision_matrix_enc.c index 9fc2bd17c9..6bf8850fc2 100644 --- a/lib_enc/decision_matrix_enc.c +++ b/lib_enc/decision_matrix_enc.c @@ -318,6 +318,9 @@ void decision_matrix_enc( /* set core bitrate */ st->core_brate = st->total_brate - st->extl_brate; +#ifdef NONBE_FIX_797_OMASA_INACTIVE_SEP_OBJ + st->icbwe_brate = 0; +#endif if ( st->ini_frame == 0 ) { diff --git a/lib_enc/evs_enc.c b/lib_enc/evs_enc.c index cc01594b79..476391d897 100644 --- a/lib_enc/evs_enc.c +++ b/lib_enc/evs_enc.c @@ -347,6 +347,9 @@ ivas_error evs_enc( } st->core_brate = st->total_brate - st->extl_brate; +#ifdef NONBE_FIX_797_OMASA_INACTIVE_SEP_OBJ + st->icbwe_brate = 0; +#endif if ( st->tec_tfa == 1 ) { diff --git a/lib_enc/init_enc.c b/lib_enc/init_enc.c index c7b8ab3190..40361aa07e 100644 --- a/lib_enc/init_enc.c +++ b/lib_enc/init_enc.c @@ -97,6 +97,9 @@ ivas_error init_encoder( st->last_core_brate = st->total_brate; st->dtx_sce_sba = 0; st->extl = -1; +#ifdef NONBE_FIX_797_OMASA_INACTIVE_SEP_OBJ + st->icbwe_brate = -1; +#endif st->last_extl = -1; st->last_L_frame = L_FRAME; st->rate_switching_reset = 0; diff --git a/lib_enc/ivas_decision_matrix_enc.c b/lib_enc/ivas_decision_matrix_enc.c index bc9968dcb5..2b4cd31fc0 100644 --- a/lib_enc/ivas_decision_matrix_enc.c +++ b/lib_enc/ivas_decision_matrix_enc.c @@ -356,6 +356,9 @@ void ivas_decision_matrix_enc( /* set core bitrate */ st->core_brate = st->total_brate - st->extl_brate - icbwe_brate; +#ifdef NONBE_FIX_797_OMASA_INACTIVE_SEP_OBJ + st->icbwe_brate = icbwe_brate; +#endif if ( st->ini_frame == 0 ) { diff --git a/lib_enc/stat_enc.h b/lib_enc/stat_enc.h index ee30669e3d..ecd2128c8b 100644 --- a/lib_enc/stat_enc.h +++ b/lib_enc/stat_enc.h @@ -1150,21 +1150,24 @@ typedef struct enc_core_structure int16_t extl; /* extension layer */ int16_t last_extl; /* previous extension layer */ int32_t extl_brate; /* extension layer bitrate */ - int16_t input_bwidth; /* input signal bandwidth */ - int16_t bwidth; /* encoded bandwidth NB, WB, SWB or FB */ - int16_t max_bwidth; /* maximum encoded bandwidth */ - int16_t last_input_bwidth; /* input signal bandwidth in the previous frame */ - int16_t last_bwidth; /* coded bandwidth in the previous frame */ - int16_t last_bwidth_cng; /* coded bandwidth in the previous inactive frame */ - int16_t bwidth_sw_cnt; /* bandwidth switching counter */ - int16_t L_frame; /* ACELP core internal frame length */ - int16_t Opt_AMR_WB; /* flag indicating AMR-WB IO mode */ - int16_t Opt_DTX_ON; /* flag indicating DTX operation */ - int16_t cng_type; /* flag indicating LP or CLDFB based SID/CNG */ - int16_t cng_sba_flag; /* flag indicating CNG/SID for SBA 2TC */ - int16_t Opt_SC_VBR; /* flag indicating SC-VBR mode */ - int16_t last_Opt_SC_VBR; /* flag indicating prev frame's SC-VBR mode */ - int16_t low_rate_mode; /* low-rate mode flag */ +#ifdef NONBE_FIX_797_OMASA_INACTIVE_SEP_OBJ + int32_t icbwe_brate; /* IC-BWE bitrate */ +#endif + int16_t input_bwidth; /* input signal bandwidth */ + int16_t bwidth; /* encoded bandwidth NB, WB, SWB or FB */ + int16_t max_bwidth; /* maximum encoded bandwidth */ + int16_t last_input_bwidth; /* input signal bandwidth in the previous frame */ + int16_t last_bwidth; /* coded bandwidth in the previous frame */ + int16_t last_bwidth_cng; /* coded bandwidth in the previous inactive frame */ + int16_t bwidth_sw_cnt; /* bandwidth switching counter */ + int16_t L_frame; /* ACELP core internal frame length */ + int16_t Opt_AMR_WB; /* flag indicating AMR-WB IO mode */ + int16_t Opt_DTX_ON; /* flag indicating DTX operation */ + int16_t cng_type; /* flag indicating LP or CLDFB based SID/CNG */ + int16_t cng_sba_flag; /* flag indicating CNG/SID for SBA 2TC */ + int16_t Opt_SC_VBR; /* flag indicating SC-VBR mode */ + int16_t last_Opt_SC_VBR; /* flag indicating prev frame's SC-VBR mode */ + int16_t low_rate_mode; /* low-rate mode flag */ #ifdef DEBUGGING int16_t force; /* flag indicating specific signal type (0 = speech, 1 = music, -1 = N/A) */ #endif -- GitLab From c1c6612c7e9f4d8e041c7a625702d7179bfdb066 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 19 Sep 2023 13:19:08 +0200 Subject: [PATCH 08/11] alternative to st->icbwe_brate: new flag 'inactive_coder_type_flag' --- lib_com/options.h | 1 + lib_dec/acelp_core_dec.c | 2 +- lib_dec/decision_matrix_dec.c | 15 +++++++++++--- lib_dec/init_dec.c | 6 +++--- lib_dec/ivas_decision_matrix_dec.c | 15 +++++++++++--- lib_dec/stat_dec.h | 28 +++++++++++++------------- lib_enc/acelp_core_enc.c | 2 +- lib_enc/decision_matrix_enc.c | 16 ++++++++++++--- lib_enc/evs_enc.c | 3 --- lib_enc/init_enc.c | 6 +++--- lib_enc/ivas_decision_matrix_enc.c | 15 +++++++++++--- lib_enc/stat_enc.h | 32 +++++++++++++++--------------- 12 files changed, 88 insertions(+), 53 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index c71c7d3a5a..b4285538c9 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -202,6 +202,7 @@ #define NONBE_FIX_588_UPDATE_FASTCONV_SD /* FhG: issue 588: update FastConv SD HRTFs in CLDFB domain with new conversion method */ #define NONBE_FIX_797_OMASA_INACTIVE_SEP_OBJ /* VA: issue 797: fix of crash when the separated object is inactive and the MASA metadata is using very few bits */ + /* ##################### End NON-BE switches ########################### */ /* ################## End DEVELOPMENT switches ######################### */ diff --git a/lib_dec/acelp_core_dec.c b/lib_dec/acelp_core_dec.c index 6317574b2f..fb2d6277e7 100644 --- a/lib_dec/acelp_core_dec.c +++ b/lib_dec/acelp_core_dec.c @@ -804,7 +804,7 @@ ivas_error acelp_core_dec( decod_tran( st, st->L_frame, tc_subfr, Aq, Es_pred, pitch_buf, voice_factors, exc, exc2, bwe_exc, unbits, sharpFlag, gain_buf ); } #ifdef NONBE_FIX_797_OMASA_INACTIVE_SEP_OBJ - else if ( st->coder_type == AUDIO || ( st->coder_type == INACTIVE && ( st->core_brate + st->extl_brate + st->icbwe_brate <= MAX_GSC_INACTIVE_BRATE ) ) ) + else if ( st->coder_type == AUDIO || ( st->coder_type == INACTIVE && st->inactive_coder_type_flag ) ) #else else if ( st->coder_type == AUDIO || ( st->coder_type == INACTIVE && st->total_brate <= MAX_GSC_INACTIVE_BRATE ) ) #endif diff --git a/lib_dec/decision_matrix_dec.c b/lib_dec/decision_matrix_dec.c index 4765b5b5f2..5f4bcb9812 100644 --- a/lib_dec/decision_matrix_dec.c +++ b/lib_dec/decision_matrix_dec.c @@ -405,9 +405,6 @@ void decision_matrix_dec( /* set core bitrate */ st->core_brate = st->total_brate - st->extl_brate; -#ifdef NONBE_FIX_797_OMASA_INACTIVE_SEP_OBJ - st->icbwe_brate = 0; -#endif /*-----------------------------------------------------------------* * Read HQ signaling bits from the bitstream @@ -561,5 +558,17 @@ void decision_matrix_dec( st->last_extl = st->extl; } +#ifdef NONBE_FIX_797_OMASA_INACTIVE_SEP_OBJ + /*-----------------------------------------------------------------* + * set inactive coder_type flag in ACELP core + *-----------------------------------------------------------------*/ + + st->inactive_coder_type_flag = 0; /* AVQ by default */ + if ( st->total_brate <= MAX_GSC_INACTIVE_BRATE ) + { + st->inactive_coder_type_flag = 1; /* GSC */ + } +#endif + return; } diff --git a/lib_dec/init_dec.c b/lib_dec/init_dec.c index 85dcdc4f14..aaf78c1532 100644 --- a/lib_dec/init_dec.c +++ b/lib_dec/init_dec.c @@ -82,12 +82,12 @@ ivas_error init_decoder( st->bwidth = NB; st->last_bwidth = NB; st->extl_brate = 0; -#ifdef NONBE_FIX_797_OMASA_INACTIVE_SEP_OBJ - st->icbwe_brate = 0; -#endif st->coder_type = GENERIC; st->last_coder_type = GENERIC; +#ifdef NONBE_FIX_797_OMASA_INACTIVE_SEP_OBJ + st->inactive_coder_type_flag = 0; +#endif st->last_L_frame = st->L_frame; st->last_core_brate = st->core_brate; st->last_core = -1; diff --git a/lib_dec/ivas_decision_matrix_dec.c b/lib_dec/ivas_decision_matrix_dec.c index e98f72520f..cb1f9de0b7 100644 --- a/lib_dec/ivas_decision_matrix_dec.c +++ b/lib_dec/ivas_decision_matrix_dec.c @@ -344,9 +344,6 @@ void ivas_decision_matrix_dec( /* set core bitrate */ st->core_brate = st->total_brate - st->extl_brate - icbwe_brate; -#ifdef NONBE_FIX_797_OMASA_INACTIVE_SEP_OBJ - st->icbwe_brate = icbwe_brate; -#endif /*-----------------------------------------------------------------* * Read transform core (TCX vs. HQ) signaling bit from the bitstream @@ -438,6 +435,18 @@ void ivas_decision_matrix_dec( st->nb_subfr = NB_SUBFR; } +#ifdef NONBE_FIX_797_OMASA_INACTIVE_SEP_OBJ + /*-----------------------------------------------------------------* + * set inactive coder_type flag in ACELP core + *-----------------------------------------------------------------*/ + + st->inactive_coder_type_flag = 0; /* AVQ by default */ + if ( st->total_brate <= MAX_GSC_INACTIVE_BRATE ) + { + st->inactive_coder_type_flag = 1; /* GSC */ + } +#endif + /*-----------------------------------------------------------------* * Reconfigure in case when output_Fs < input_Fs *-----------------------------------------------------------------*/ diff --git a/lib_dec/stat_dec.h b/lib_dec/stat_dec.h index 89998dafba..9bc85d844b 100644 --- a/lib_dec/stat_dec.h +++ b/lib_dec/stat_dec.h @@ -923,22 +923,22 @@ typedef struct Decoder_State int16_t coder_type; /* coder type */ int16_t transform_type[2]; /* TCX20/10/5 mode in each subframe */ int32_t core_brate; /* core bitrate */ + int32_t last_core_brate; /* previous frame core bitrate */ + int16_t extl; /* extension layer */ + int16_t extl_orig; /* extension layer */ + int16_t last_extl; /* previous extension layer */ + int32_t extl_brate; /* extension layer bitrate */ + int32_t extl_brate_orig; /* extension layer bitrate */ + int16_t L_frame; /* ACELP core internal frame length */ + int16_t bwidth; /* encoded signal bandwidth */ + int16_t Opt_AMR_WB; /* flag indicating AMR-WB IO mode */ + int16_t ini_frame; /* initialization frames counter */ + int16_t prev_coder_type; /* coding type of last frame */ + int16_t low_rate_mode; /* low-rate mode flag */ + int16_t last_low_rate_mode; /* previous frame low-rate mode flag */ #ifdef NONBE_FIX_797_OMASA_INACTIVE_SEP_OBJ - int32_t icbwe_brate; /* IC-BWE bitrate */ + int16_t inactive_coder_type_flag; /* inactive coder type flag (0 = AVQ / 1 = GSC) */ #endif - int32_t last_core_brate; /* previous frame core bitrate */ - int16_t extl; /* extension layer */ - int16_t extl_orig; /* extension layer */ - int16_t last_extl; /* previous extension layer */ - int32_t extl_brate; /* extension layer bitrate */ - int32_t extl_brate_orig; /* extension layer bitrate */ - int16_t L_frame; /* ACELP core internal frame length */ - int16_t bwidth; /* encoded signal bandwidth */ - int16_t Opt_AMR_WB; /* flag indicating AMR-WB IO mode */ - int16_t ini_frame; /* initialization frames counter */ - int16_t prev_coder_type; /* coding type of last frame */ - int16_t low_rate_mode; /* low-rate mode flag */ - int16_t last_low_rate_mode; /* previous frame low-rate mode flag */ /*----------------------------------------------------------------------------------* * ACELP core parameters diff --git a/lib_enc/acelp_core_enc.c b/lib_enc/acelp_core_enc.c index a473237c6a..d18ef939b2 100644 --- a/lib_enc/acelp_core_enc.c +++ b/lib_enc/acelp_core_enc.c @@ -564,7 +564,7 @@ ivas_error acelp_core_enc( } } #ifdef NONBE_FIX_797_OMASA_INACTIVE_SEP_OBJ - else if ( st->coder_type == AUDIO || ( st->coder_type == INACTIVE && ( st->core_brate + st->extl_brate + st->icbwe_brate <= MAX_GSC_INACTIVE_BRATE ) ) ) + else if ( st->coder_type == AUDIO || ( st->coder_type == INACTIVE && st->inactive_coder_type_flag ) ) #else else if ( st->coder_type == AUDIO || ( st->coder_type == INACTIVE && st->total_brate <= MAX_GSC_INACTIVE_BRATE ) ) #endif diff --git a/lib_enc/decision_matrix_enc.c b/lib_enc/decision_matrix_enc.c index 6bf8850fc2..69c082b548 100644 --- a/lib_enc/decision_matrix_enc.c +++ b/lib_enc/decision_matrix_enc.c @@ -318,9 +318,6 @@ void decision_matrix_enc( /* set core bitrate */ st->core_brate = st->total_brate - st->extl_brate; -#ifdef NONBE_FIX_797_OMASA_INACTIVE_SEP_OBJ - st->icbwe_brate = 0; -#endif if ( st->ini_frame == 0 ) { @@ -330,9 +327,22 @@ void decision_matrix_enc( st->last_extl = st->extl; } +#ifdef NONBE_FIX_797_OMASA_INACTIVE_SEP_OBJ + /*-----------------------------------------------------------------* + * set inactive coder_type flag in ACELP core + *-----------------------------------------------------------------*/ + + st->inactive_coder_type_flag = 0; /* AVQ by default */ + if ( st->total_brate <= MAX_GSC_INACTIVE_BRATE ) + { + st->inactive_coder_type_flag = 1; /* GSC */ + } +#endif + return; } + /*---------------------------------------------------------------------* * signaling_mode1_tcx20_enc() * diff --git a/lib_enc/evs_enc.c b/lib_enc/evs_enc.c index 476391d897..cc01594b79 100644 --- a/lib_enc/evs_enc.c +++ b/lib_enc/evs_enc.c @@ -347,9 +347,6 @@ ivas_error evs_enc( } st->core_brate = st->total_brate - st->extl_brate; -#ifdef NONBE_FIX_797_OMASA_INACTIVE_SEP_OBJ - st->icbwe_brate = 0; -#endif if ( st->tec_tfa == 1 ) { diff --git a/lib_enc/init_enc.c b/lib_enc/init_enc.c index 40361aa07e..54bd64d13c 100644 --- a/lib_enc/init_enc.c +++ b/lib_enc/init_enc.c @@ -97,9 +97,6 @@ ivas_error init_encoder( st->last_core_brate = st->total_brate; st->dtx_sce_sba = 0; st->extl = -1; -#ifdef NONBE_FIX_797_OMASA_INACTIVE_SEP_OBJ - st->icbwe_brate = -1; -#endif st->last_extl = -1; st->last_L_frame = L_FRAME; st->rate_switching_reset = 0; @@ -107,6 +104,9 @@ ivas_error init_encoder( st->clas = UNVOICED_CLAS; st->low_rate_mode = 0; st->ini_frame = 0; +#ifdef NONBE_FIX_797_OMASA_INACTIVE_SEP_OBJ + st->inactive_coder_type_flag = 0; +#endif st->coder_type_raw = VOICED; st->last_coder_type_raw = st->coder_type_raw; diff --git a/lib_enc/ivas_decision_matrix_enc.c b/lib_enc/ivas_decision_matrix_enc.c index 2b4cd31fc0..cfaa7dfe49 100644 --- a/lib_enc/ivas_decision_matrix_enc.c +++ b/lib_enc/ivas_decision_matrix_enc.c @@ -356,9 +356,6 @@ void ivas_decision_matrix_enc( /* set core bitrate */ st->core_brate = st->total_brate - st->extl_brate - icbwe_brate; -#ifdef NONBE_FIX_797_OMASA_INACTIVE_SEP_OBJ - st->icbwe_brate = icbwe_brate; -#endif if ( st->ini_frame == 0 ) { @@ -368,6 +365,18 @@ void ivas_decision_matrix_enc( st->last_extl = st->extl; } +#ifdef NONBE_FIX_797_OMASA_INACTIVE_SEP_OBJ + /*-----------------------------------------------------------------* + * set inactive coder_type flag in ACELP core + *-----------------------------------------------------------------*/ + + st->inactive_coder_type_flag = 0; /* AVQ by default */ + if ( st->total_brate <= MAX_GSC_INACTIVE_BRATE ) + { + st->inactive_coder_type_flag = 1; /* GSC */ + } +#endif + return; } diff --git a/lib_enc/stat_enc.h b/lib_enc/stat_enc.h index ecd2128c8b..09bffbd2a5 100644 --- a/lib_enc/stat_enc.h +++ b/lib_enc/stat_enc.h @@ -1150,24 +1150,24 @@ typedef struct enc_core_structure int16_t extl; /* extension layer */ int16_t last_extl; /* previous extension layer */ int32_t extl_brate; /* extension layer bitrate */ + int16_t input_bwidth; /* input signal bandwidth */ + int16_t bwidth; /* encoded bandwidth NB, WB, SWB or FB */ + int16_t max_bwidth; /* maximum encoded bandwidth */ + int16_t last_input_bwidth; /* input signal bandwidth in the previous frame */ + int16_t last_bwidth; /* coded bandwidth in the previous frame */ + int16_t last_bwidth_cng; /* coded bandwidth in the previous inactive frame */ + int16_t bwidth_sw_cnt; /* bandwidth switching counter */ + int16_t L_frame; /* ACELP core internal frame length */ + int16_t Opt_AMR_WB; /* flag indicating AMR-WB IO mode */ + int16_t Opt_DTX_ON; /* flag indicating DTX operation */ + int16_t cng_type; /* flag indicating LP or CLDFB based SID/CNG */ + int16_t cng_sba_flag; /* flag indicating CNG/SID for SBA 2TC */ + int16_t Opt_SC_VBR; /* flag indicating SC-VBR mode */ + int16_t last_Opt_SC_VBR; /* flag indicating prev frame's SC-VBR mode */ + int16_t low_rate_mode; /* low-rate mode flag */ #ifdef NONBE_FIX_797_OMASA_INACTIVE_SEP_OBJ - int32_t icbwe_brate; /* IC-BWE bitrate */ + int16_t inactive_coder_type_flag; /* inactive coder type flag (0 = AVQ / 1 = GSC) */ #endif - int16_t input_bwidth; /* input signal bandwidth */ - int16_t bwidth; /* encoded bandwidth NB, WB, SWB or FB */ - int16_t max_bwidth; /* maximum encoded bandwidth */ - int16_t last_input_bwidth; /* input signal bandwidth in the previous frame */ - int16_t last_bwidth; /* coded bandwidth in the previous frame */ - int16_t last_bwidth_cng; /* coded bandwidth in the previous inactive frame */ - int16_t bwidth_sw_cnt; /* bandwidth switching counter */ - int16_t L_frame; /* ACELP core internal frame length */ - int16_t Opt_AMR_WB; /* flag indicating AMR-WB IO mode */ - int16_t Opt_DTX_ON; /* flag indicating DTX operation */ - int16_t cng_type; /* flag indicating LP or CLDFB based SID/CNG */ - int16_t cng_sba_flag; /* flag indicating CNG/SID for SBA 2TC */ - int16_t Opt_SC_VBR; /* flag indicating SC-VBR mode */ - int16_t last_Opt_SC_VBR; /* flag indicating prev frame's SC-VBR mode */ - int16_t low_rate_mode; /* low-rate mode flag */ #ifdef DEBUGGING int16_t force; /* flag indicating specific signal type (0 = speech, 1 = music, -1 = N/A) */ #endif -- GitLab From 62bc8ce929da2975a3664b3778d9ff861424f2f1 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 19 Sep 2023 11:51:25 +0000 Subject: [PATCH 09/11] Revert unintentional change. --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index f4654e41fe..5cf9df3e29 100644 --- a/Makefile +++ b/Makefile @@ -67,7 +67,7 @@ LDLIBS += -lm CCCLANG = clang ifeq "$(CLANG)" "1" CC = $(CCCLANG) -CFLAGS += -fsanitize=memory -fsanitize-memory-track-origins +CFLAGS += -fsanitize=memory LDFLAGS += -fsanitize=memory endif ifeq "$(CLANG)" "2" -- GitLab From f02e9918928f60360ba050bd5ae02d1fa4b6e18d Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 19 Sep 2023 21:12:24 +0200 Subject: [PATCH 10/11] updates within NONBE_FIX_797_OMASA_INACTIVE_SEP_OBJ --- lib_com/ivas_omasa_com.c | 30 ++++++++++++++++++++++++++++-- lib_com/ivas_prot.h | 6 ++++++ lib_dec/ivas_core_dec.c | 4 ++++ lib_enc/ivas_core_enc.c | 4 ++++ 4 files changed, 42 insertions(+), 2 deletions(-) diff --git a/lib_com/ivas_omasa_com.c b/lib_com/ivas_omasa_com.c index 14236c919d..cbf15dde4f 100644 --- a/lib_com/ivas_omasa_com.c +++ b/lib_com/ivas_omasa_com.c @@ -335,11 +335,22 @@ int32_t ivas_interformat_brate( void ivas_combined_format_brate_sanity( const int32_t element_brate, /* i : element bitrate */ const int16_t core, /* i : core */ - int32_t *core_brate, /* i/o: core bitrate */ - int16_t *diff_nBits /* o : number of differential bits */ +#ifdef NONBE_FIX_797_OMASA_INACTIVE_SEP_OBJ + const int32_t total_brate, /* i : total bitrate */ +#endif + int32_t *core_brate, /* i/o: core bitrate */ +#ifdef NONBE_FIX_797_OMASA_INACTIVE_SEP_OBJ + int16_t *inactive_coder_type_flag, /* o : inactive coder_type flag */ +#endif + int16_t *diff_nBits /* o : number of differential bits */ ) { int16_t limit_high, nBits; +#ifdef NONBE_FIX_797_OMASA_INACTIVE_SEP_OBJ + int32_t brate_diff; + + brate_diff = total_brate - *core_brate; +#endif /* sanity check: at lowest IVAS bit-rates and one ISM channel coded by low-rate core-coder mode, it can happen that the CPE (MASA) bit-budget @@ -364,6 +375,21 @@ void ivas_combined_format_brate_sanity( } } +#ifdef NONBE_FIX_797_OMASA_INACTIVE_SEP_OBJ + /*-----------------------------------------------------------------* + * set inactive coder_type flag in ACELP core + *-----------------------------------------------------------------*/ + + if ( core == ACELP_CORE ) + { + *inactive_coder_type_flag = 0; /* AVQ by default */ + if ( *core_brate + brate_diff <= MAX_GSC_INACTIVE_BRATE ) + { + *inactive_coder_type_flag = 1; /* GSC */ + } + } +#endif + return; } diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 328f19c2c3..267bf5ec50 100755 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -5805,7 +5805,13 @@ int32_t ivas_interformat_brate( void ivas_combined_format_brate_sanity( const int32_t element_brate, /* i : element bitrate */ const int16_t core, /* i : core */ +#ifdef NONBE_FIX_797_OMASA_INACTIVE_SEP_OBJ + const int32_t total_brate, /* i : total bitrate */ +#endif int32_t *core_brate, /* i/o: core bitrate */ +#ifdef NONBE_FIX_797_OMASA_INACTIVE_SEP_OBJ + int16_t *inactive_coder_type_flag, /* o : inactive coder_type flag */ +#endif int16_t *diff_nBits /* o : number of differential bits */ ); diff --git a/lib_dec/ivas_core_dec.c b/lib_dec/ivas_core_dec.c index ee949f8665..b9925a2a0a 100644 --- a/lib_dec/ivas_core_dec.c +++ b/lib_dec/ivas_core_dec.c @@ -280,7 +280,11 @@ ivas_error ivas_core_dec( if ( hCPE != NULL && hCPE->element_mode == IVAS_CPE_DFT && hCPE->brate_surplus > 0 ) { +#ifdef NONBE_FIX_797_OMASA_INACTIVE_SEP_OBJ + ivas_combined_format_brate_sanity( hCPE->element_brate, sts[0]->core, sts[0]->total_brate, &( sts[0]->core_brate ), &( sts[0]->inactive_coder_type_flag ), &tmps ); +#else ivas_combined_format_brate_sanity( hCPE->element_brate, sts[0]->core, &( sts[0]->core_brate ), &tmps ); +#endif } /*------------------------------------------------------------------* diff --git a/lib_enc/ivas_core_enc.c b/lib_enc/ivas_core_enc.c index 3fdb704672..fec16a8a9e 100644 --- a/lib_enc/ivas_core_enc.c +++ b/lib_enc/ivas_core_enc.c @@ -196,7 +196,11 @@ ivas_error ivas_core_enc( diff_nBits = 0; if ( hCPE != NULL && hCPE->element_mode == IVAS_CPE_DFT && hCPE->brate_surplus > 0 ) { +#ifdef NONBE_FIX_797_OMASA_INACTIVE_SEP_OBJ + ivas_combined_format_brate_sanity( hCPE->element_brate, sts[0]->core, sts[0]->total_brate, &( sts[0]->core_brate ), &( sts[0]->inactive_coder_type_flag ), &diff_nBits ); +#else ivas_combined_format_brate_sanity( hCPE->element_brate, sts[0]->core, &( sts[0]->core_brate ), &diff_nBits ); +#endif } /*---------------------------------------------------------------------* -- GitLab From 2d8aeb761a1c8890f6628280b2e9aff77eb60e00 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 19 Sep 2023 21:53:24 +0200 Subject: [PATCH 11/11] fix EVS VBR mode within NONBE_FIX_797_OMASA_INACTIVE_SEP_OBJ --- lib_enc/decision_matrix_enc.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib_enc/decision_matrix_enc.c b/lib_enc/decision_matrix_enc.c index 69c082b548..d21fa934f1 100644 --- a/lib_enc/decision_matrix_enc.c +++ b/lib_enc/decision_matrix_enc.c @@ -156,7 +156,6 @@ void decision_matrix_enc( } else if ( ( ( st->coder_type == UNVOICED || st->coder_type == TRANSITION ) && !st->sp_aud_decision1 ) || st->bwidth != NB ) { - if ( st->coder_type == UNVOICED && st->vad_flag == 1 && ( ( st->last_bwidth >= SWB && st->last_Opt_SC_VBR ) || st->last_bwidth < SWB ) && ( st->last_core != HQ_CORE || st->bwidth != NB ) ) { /* NELP mode */ @@ -171,6 +170,11 @@ void decision_matrix_enc( } } +#ifdef NONBE_FIX_797_OMASA_INACTIVE_SEP_OBJ + /* set inactive coder_type flag in ACELP core to GSC */ + st->inactive_coder_type_flag = 1; +#endif + return; } -- GitLab