From 01f89d090af89f2972645a95225c40ef625d9b80 Mon Sep 17 00:00:00 2001 From: knj Date: Wed, 12 Apr 2023 13:10:59 +0200 Subject: [PATCH 1/6] fix incorrect bandwidth in ISM comfort noise --- lib_com/options.h | 1 + lib_dec/ivas_decision_matrix_dec.c | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/lib_com/options.h b/lib_com/options.h index ba44aa63b9..35ae8db953 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -165,6 +165,7 @@ #define FIX_392_LATE_REVERB /* DLB : Issue 392: keep late reverb by default off when output config is not BINAURAL_ROOM*/ #define FIX_ISM_DTX_CLICKS /* FhG: fix for clicks in ISM DTX for inactive to active TCX transitions */ +#define FIX_ISM_DTX_CNG_BWIDTH /* FhG: fix for bw changes on CNG frames in ISM DTX for objects that use the decoder-side noise estimation */ /* ################## End DEVELOPMENT switches ######################### */ /* clang-format on */ diff --git a/lib_dec/ivas_decision_matrix_dec.c b/lib_dec/ivas_decision_matrix_dec.c index e5be65ae24..77814881a8 100644 --- a/lib_dec/ivas_decision_matrix_dec.c +++ b/lib_dec/ivas_decision_matrix_dec.c @@ -89,7 +89,18 @@ void ivas_decision_matrix_dec( if ( st->cng_type == FD_CNG ) { +#ifdef FIX_ISM_DTX_CNG_BWIDTH + int16_t bwidth; + + /* do not set bandwidth for objects in ISM DTX that run their noise estimation in the decoder */ + bwidth = get_next_indice( st, 2 ); + if ( st->read_sid_info ) + { + st->bwidth = bwidth; + } +#else st->bwidth = get_next_indice( st, 2 ); +#endif } } if ( get_next_indice( st, 1 ) ) -- GitLab From c9464483316f94da9eac4aaf415248e1a203c07c Mon Sep 17 00:00:00 2001 From: vaclav Date: Wed, 12 Apr 2023 14:54:59 +0200 Subject: [PATCH 2/6] issue 396 - alternative fix for bw changes on CNG frames in ISM DTX for objects that use the decoder-side noise estimation; under FIX_ISM_DTX_CNG_BWIDTH_ALT --- lib_com/options.h | 5 +++-- lib_dec/ivas_sce_dec.c | 28 +++++++++++++++++++++++++--- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 35ae8db953..2cee738275 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -164,8 +164,9 @@ #define FIX_390_EXT_REND_MASA_META_COPY /* Nokia: Issue 390: Fixes MASA metadata copying to renderer. */ #define FIX_392_LATE_REVERB /* DLB : Issue 392: keep late reverb by default off when output config is not BINAURAL_ROOM*/ -#define FIX_ISM_DTX_CLICKS /* FhG: fix for clicks in ISM DTX for inactive to active TCX transitions */ -#define FIX_ISM_DTX_CNG_BWIDTH /* FhG: fix for bw changes on CNG frames in ISM DTX for objects that use the decoder-side noise estimation */ +#define FIX_ISM_DTX_CLICKS /* FhG: issue 394 - fix for clicks in ISM DTX for inactive to active TCX transitions */ +//#define FIX_ISM_DTX_CNG_BWIDTH /* FhG: issue 396 - fix for bw changes on CNG frames in ISM DTX for objects that use the decoder-side noise estimation */ +#define FIX_ISM_DTX_CNG_BWIDTH_ALT /* VA: issue 396 - alternative fix for bw changes on CNG frames in ISM DTX for objects that use the decoder-side noise estimation */ /* ################## End DEVELOPMENT switches ######################### */ /* clang-format on */ diff --git a/lib_dec/ivas_sce_dec.c b/lib_dec/ivas_sce_dec.c index 064cdbb4e0..8a1da04d41 100755 --- a/lib_dec/ivas_sce_dec.c +++ b/lib_dec/ivas_sce_dec.c @@ -91,14 +91,25 @@ ivas_error ivas_sce_dec( *-----------------------------------------------------------------*/ /* set total_brate - needed in DTX */ - if ( !st_ivas->bfi && ( ivas_total_brate == IVAS_SID_5k2 ) ) + if ( !st_ivas->bfi && ivas_total_brate == IVAS_SID_5k2 ) { st->total_brate = ivas_total_brate - nb_bits_metadata * FRAMES_PER_SEC; assert( st->total_brate == SID_2k40 && "SCE SID must be 2.4kbps!" ); + +#ifdef FIX_ISM_DTX_CNG_BWIDTH_ALT + if ( st_ivas->ivas_format == ISM_FORMAT && st->read_sid_info == 0 ) + { + st->total_brate = FRAME_NO_DATA; + } +#endif } +#ifdef FIX_ISM_DTX_CNG_BWIDTH_ALT + else if ( !st_ivas->bfi && ivas_total_brate == FRAME_NO_DATA ) +#else else if ( !st_ivas->bfi && ivas_total_brate <= SID_2k40 ) +#endif { - st->total_brate = ivas_total_brate; + st->total_brate = FRAME_NO_DATA; } #ifdef DISCRETE_ISM_DTX_CNG else if ( !st_ivas->bfi && st_ivas->ivas_format != ISM_FORMAT && last_ivas_total_brate <= IVAS_SID_5k2 ) @@ -181,11 +192,22 @@ ivas_error ivas_sce_dec( } /* set "total_brate" */ - if ( !st_ivas->bfi && ( ivas_total_brate == IVAS_SID_5k2 ) ) + if ( !st_ivas->bfi && ivas_total_brate == IVAS_SID_5k2 ) { st->total_brate = ivas_total_brate - nb_bits_metadata * FRAMES_PER_SEC; + +#ifdef FIX_ISM_DTX_CNG_BWIDTH_ALT + if ( st_ivas->ivas_format == ISM_FORMAT && st->read_sid_info == 0 ) + { + st->total_brate = FRAME_NO_DATA; + } +#endif } +#ifdef FIX_ISM_DTX_CNG_BWIDTH_ALT + else if ( !st_ivas->bfi && ivas_total_brate == FRAME_NO_DATA ) +#else else if ( !st_ivas->bfi && ivas_total_brate <= SID_2k40 ) +#endif { st->total_brate = ivas_total_brate; } -- GitLab From 7defce0bf2957e787ada6b6943bee2ae95e9a5ff Mon Sep 17 00:00:00 2001 From: vaclav Date: Wed, 12 Apr 2023 17:45:39 +0200 Subject: [PATCH 3/6] get rid of parameter st->read_sid_info; under FIX_ISM_DTX_CNG_BWIDTH_ALT --- lib_com/prot.h | 4 ++++ lib_dec/acelp_core_dec.c | 13 +++++++++++++ lib_dec/evs_dec.c | 4 ++++ lib_dec/init_dec.c | 2 ++ lib_dec/ivas_core_dec.c | 19 +++++++++++++++++++ lib_dec/ivas_ism_dtx_dec.c | 14 ++++++++++++-- lib_dec/ivas_ism_metadata_dec.c | 4 +++- lib_dec/ivas_sce_dec.c | 4 ++-- lib_dec/stat_dec.h | 4 +++- 9 files changed, 62 insertions(+), 6 deletions(-) diff --git a/lib_com/prot.h b/lib_com/prot.h index 51d1cb1e20..ad788b413a 100644 --- a/lib_com/prot.h +++ b/lib_com/prot.h @@ -4502,6 +4502,10 @@ ivas_error acelp_core_dec( const int16_t flag_sec_CNA, /* i : CNA flag for secondary channel */ const int16_t nchan_out, /* i : number of output channels */ STEREO_CNG_DEC_HANDLE hStereoCng /* i : stereo CNG handle */ +#ifdef FIX_ISM_DTX_CNG_BWIDTH_ALT + , + const int16_t read_sid_info /* i : read SID info flag */ +#endif ); void bass_psfilter_init( diff --git a/lib_dec/acelp_core_dec.c b/lib_dec/acelp_core_dec.c index eb53379d66..fea9cfdfce 100644 --- a/lib_dec/acelp_core_dec.c +++ b/lib_dec/acelp_core_dec.c @@ -77,6 +77,10 @@ ivas_error acelp_core_dec( const int16_t flag_sec_CNA, /* i : CNA flag for secondary channel */ const int16_t nchan_out, /* i : number of output channels */ STEREO_CNG_DEC_HANDLE hStereoCng /* i : stereo CNG handle */ +#ifdef FIX_ISM_DTX_CNG_BWIDTH_ALT + , + const int16_t read_sid_info /* i : read SID info flag */ +#endif ) { float old_exc[L_EXC_DEC], *exc; /* excitation signal buffer */ @@ -512,7 +516,11 @@ ivas_error acelp_core_dec( } else { +#ifdef FIX_ISM_DTX_CNG_BWIDTH_ALT + if ( st->core_brate == SID_2k40 && st->element_mode != IVAS_CPE_MDCT && read_sid_info ) +#else if ( st->core_brate == SID_2k40 && st->element_mode != IVAS_CPE_MDCT && st->read_sid_info ) +#endif { FdCng_decodeSID( st ); *sid_bw = 0; @@ -528,8 +536,13 @@ ivas_error acelp_core_dec( } ApplyFdCng( syn, NULL, realBuffer, imagBuffer, st, 0, ( st->coder_type == AUDIO && !st->GSC_noisy_speech ) ); } + +#ifdef FIX_ISM_DTX_CNG_BWIDTH_ALT + if ( !read_sid_info ) +#else if ( !st->read_sid_info ) // if (!st->read_sid_info && st->cng_ism_flag) /* read_sid_info can only be 0 in ParamISM mode */ +#endif { float noise_lvl_highest; diff --git a/lib_dec/evs_dec.c b/lib_dec/evs_dec.c index 0dbc0feafc..dbe92efd68 100644 --- a/lib_dec/evs_dec.c +++ b/lib_dec/evs_dec.c @@ -261,7 +261,11 @@ ivas_error evs_dec( if ( st->core == ACELP_CORE ) { /* ACELP core decoder */ +#ifdef FIX_ISM_DTX_CNG_BWIDTH_ALT + if ( ( error = acelp_core_dec( st, NULL, synth, NULL, bwe_exc_extended, voice_factors, old_syn_12k8_16k, sharpFlag, pitch_buf, &unbits, &sid_bw, NULL, NULL, NULL, 0, EVS_MONO, 0, 0, 1, NULL, 1 ) ) != IVAS_ERR_OK ) +#else if ( ( error = acelp_core_dec( st, NULL, synth, NULL, bwe_exc_extended, voice_factors, old_syn_12k8_16k, sharpFlag, pitch_buf, &unbits, &sid_bw, NULL, NULL, NULL, 0, EVS_MONO, 0, 0, 1, NULL ) ) != IVAS_ERR_OK ) +#endif { return error; } diff --git a/lib_dec/init_dec.c b/lib_dec/init_dec.c index 34ee7a3cec..4f612ba675 100644 --- a/lib_dec/init_dec.c +++ b/lib_dec/init_dec.c @@ -739,7 +739,9 @@ ivas_error init_decoder( st->cna_dirac_flag = 0; st->cng_sba_flag = 0; st->cng_ism_flag = 0; +#ifndef FIX_ISM_DTX_CNG_BWIDTH_ALT st->read_sid_info = 1; /* by default read the sid info from bitstream */ +#endif #ifdef DISCRETE_ISM_DTX_CNG st->is_ism_format = 0; #endif diff --git a/lib_dec/ivas_core_dec.c b/lib_dec/ivas_core_dec.c index 05c1f41727..e94ec31f3b 100644 --- a/lib_dec/ivas_core_dec.c +++ b/lib_dec/ivas_core_dec.c @@ -90,6 +90,9 @@ ivas_error ivas_core_dec( int16_t use_cldfb_for_dft; float *p_output_mem; int16_t flag_sec_CNA; +#ifdef FIX_ISM_DTX_CNG_BWIDTH_ALT + int16_t read_sid_info; +#endif int16_t last_element_mode; int16_t nchan_out; float *save_hb_synth; @@ -105,6 +108,9 @@ ivas_error ivas_core_dec( use_cldfb_for_dft = 0; tdm_LRTD_flag = -1; +#ifdef FIX_ISM_DTX_CNG_BWIDTH_ALT + read_sid_info = 1; /* read SID by default */ +#endif if ( hSCE != NULL ) { @@ -116,6 +122,15 @@ ivas_error ivas_core_dec( hStereoTD = NULL; p_output_mem = NULL; nchan_out = 1; +#ifdef FIX_ISM_DTX_CNG_BWIDTH_ALT + if ( st_ivas != NULL && st_ivas->ivas_format == ISM_FORMAT ) + { + if ( st_ivas->hISMDTX.sce_id_dtx != hSCE->sce_id ) + { + read_sid_info = 0; + } + } +#endif } else { @@ -332,7 +347,11 @@ ivas_error ivas_core_dec( if ( st->core == ACELP_CORE ) { /* ACELP core decoder */ +#ifdef FIX_ISM_DTX_CNG_BWIDTH_ALT + if ( ( error = acelp_core_dec( st, output[n], synth[n], save_hb_synth, bwe_exc_extended[n], voice_factors[n], old_syn_12k8_16k[n], sharpFlag[n], pitch_buf[n], &unbits[n], &sid_bw[n], hStereoTD, tdm_lspQ_PCh, tdm_lsfQ_PCh, use_cldfb_for_dft, last_element_mode, last_element_brate, flag_sec_CNA, nchan_out, hCPE == NULL ? NULL : hCPE->hStereoCng, read_sid_info ) ) != IVAS_ERR_OK ) +#else if ( ( error = acelp_core_dec( st, output[n], synth[n], save_hb_synth, bwe_exc_extended[n], voice_factors[n], old_syn_12k8_16k[n], sharpFlag[n], pitch_buf[n], &unbits[n], &sid_bw[n], hStereoTD, tdm_lspQ_PCh, tdm_lsfQ_PCh, use_cldfb_for_dft, last_element_mode, last_element_brate, flag_sec_CNA, nchan_out, hCPE == NULL ? NULL : hCPE->hStereoCng ) ) != IVAS_ERR_OK ) +#endif { return error; } diff --git a/lib_dec/ivas_ism_dtx_dec.c b/lib_dec/ivas_ism_dtx_dec.c index ef52c082b7..1863ea6a84 100644 --- a/lib_dec/ivas_ism_dtx_dec.c +++ b/lib_dec/ivas_ism_dtx_dec.c @@ -39,7 +39,7 @@ #endif #include "wmc_auto.h" - +#ifndef FIX_ISM_DTX_CNG_BWIDTH_ALT /*-------------------------------------------------------------------* * ivas_ism_preprocessing() * @@ -90,7 +90,7 @@ static void ivas_ism_preprocessing( return; } - +#endif /*-------------------------------------------------------------------* * ivas_ism_dtx_dec() @@ -111,6 +111,9 @@ ivas_error ivas_ism_dtx_dec( ISM_MODE last_ism_mode, ism_mode_bstr; ivas_error error; #endif +#ifdef FIX_ISM_DTX_CNG_BWIDTH_ALT + Decoder_State *st; +#endif ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; @@ -262,7 +265,14 @@ ivas_error ivas_ism_dtx_dec( { for ( ch = 0; ch < st_ivas->nchan_transport; ch++ ) { +#ifdef FIX_ISM_DTX_CNG_BWIDTH_ALT + st = st_ivas->hSCE[ch]->hCoreCoder[0]; + st->bit_stream = st_ivas->hSCE[0]->hCoreCoder[0]->bit_stream; + st->next_bit_pos = 0; /* note: needed in paramISM -> discISM switching */ + st->cng_ism_flag = 1; +#else ivas_ism_preprocessing( st_ivas, ch ); // VE: after the acceptance of switches, replace the function call by its content +#endif } } diff --git a/lib_dec/ivas_ism_metadata_dec.c b/lib_dec/ivas_ism_metadata_dec.c index feccbc9766..dd595b52c0 100644 --- a/lib_dec/ivas_ism_metadata_dec.c +++ b/lib_dec/ivas_ism_metadata_dec.c @@ -1157,7 +1157,7 @@ void ivas_ism_metadata_sid_dec( *flag_noisy_speech = 0; *sce_id_dtx = 0; - /* write ISM mode flag to explicitly signal number of spatial parameters */ + /* read ISM mode flag to explicitly signal number of spatial parameters */ if ( nchan_ism > 2 ) { idx = get_next_indice( st0, 1 ); @@ -1190,10 +1190,12 @@ void ivas_ism_metadata_sid_dec( hSCE[ch]->hCoreCoder[0]->hFdCngDec->hFdCngCom->coherence = (float) ( idx ) / (float) ( ( 1 << nBits_coh ) - 1 ); } } +#ifndef FIX_ISM_DTX_CNG_BWIDTH_ALT else { *sce_id_dtx = 0; } +#endif if ( ism_mode == ISM_MODE_PARAM ) { diff --git a/lib_dec/ivas_sce_dec.c b/lib_dec/ivas_sce_dec.c index 8a1da04d41..c38787f87c 100755 --- a/lib_dec/ivas_sce_dec.c +++ b/lib_dec/ivas_sce_dec.c @@ -97,7 +97,7 @@ ivas_error ivas_sce_dec( assert( st->total_brate == SID_2k40 && "SCE SID must be 2.4kbps!" ); #ifdef FIX_ISM_DTX_CNG_BWIDTH_ALT - if ( st_ivas->ivas_format == ISM_FORMAT && st->read_sid_info == 0 ) + if ( st_ivas->ivas_format == ISM_FORMAT && st_ivas->hISMDTX.sce_id_dtx != sce_id ) { st->total_brate = FRAME_NO_DATA; } @@ -197,7 +197,7 @@ ivas_error ivas_sce_dec( st->total_brate = ivas_total_brate - nb_bits_metadata * FRAMES_PER_SEC; #ifdef FIX_ISM_DTX_CNG_BWIDTH_ALT - if ( st_ivas->ivas_format == ISM_FORMAT && st->read_sid_info == 0 ) + if ( st_ivas->ivas_format == ISM_FORMAT && st_ivas->hISMDTX.sce_id_dtx != sce_id ) { st->total_brate = FRAME_NO_DATA; } diff --git a/lib_dec/stat_dec.h b/lib_dec/stat_dec.h index 1a82d45587..2a3c7dff9d 100644 --- a/lib_dec/stat_dec.h +++ b/lib_dec/stat_dec.h @@ -1345,8 +1345,10 @@ typedef struct Decoder_State /* MCT Channel mode indication: LFE, ignore channel? */ MCT_CHAN_MODE mct_chan_mode; - int16_t cng_ism_flag; /* CNG in Param-ISM flag */ + int16_t cng_ism_flag; /* CNG in ISM format flag */ +#ifndef FIX_ISM_DTX_CNG_BWIDTH_ALT int16_t read_sid_info; /* For ParamISM, use the transmitted noise */ +#endif #ifdef DISCRETE_ISM_DTX_CNG int16_t is_ism_format; /* Indication whether the codec operates in ISM format */ #endif -- GitLab From c867f8bc40cddc491556d58171e787931aef9614 Mon Sep 17 00:00:00 2001 From: vaclav Date: Wed, 12 Apr 2023 17:55:51 +0200 Subject: [PATCH 4/6] fix MSAN error --- lib_dec/ivas_init_dec.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index 73f2acb2db..875749a22c 100755 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -923,6 +923,10 @@ ivas_error ivas_init_decoder( #endif } +#ifdef FIX_ISM_DTX_CNG_BWIDTH_ALT + st_ivas->hISMDTX.sce_id_dtx = 0; +#endif + if ( st_ivas->ism_mode == ISM_MODE_PARAM ) { st_ivas->hSCE[1]->hCoreCoder[0]->hFdCngDec->hFdCngCom->seed3 = st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->seed2; -- GitLab From 307a9c1a144f3543533b8519e3923b79b9e8c0ce Mon Sep 17 00:00:00 2001 From: knj Date: Thu, 13 Apr 2023 16:12:46 +0200 Subject: [PATCH 5/6] change one condition --- lib_dec/acelp_core_dec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_dec/acelp_core_dec.c b/lib_dec/acelp_core_dec.c index fea9cfdfce..922510efed 100644 --- a/lib_dec/acelp_core_dec.c +++ b/lib_dec/acelp_core_dec.c @@ -517,7 +517,7 @@ ivas_error acelp_core_dec( else { #ifdef FIX_ISM_DTX_CNG_BWIDTH_ALT - if ( st->core_brate == SID_2k40 && st->element_mode != IVAS_CPE_MDCT && read_sid_info ) + if ( st->core_brate == SID_2k40 && st->element_mode != IVAS_CPE_MDCT ) #else if ( st->core_brate == SID_2k40 && st->element_mode != IVAS_CPE_MDCT && st->read_sid_info ) #endif -- GitLab From 2b18efb412cff865718143cdfdc9b11a43a6981e Mon Sep 17 00:00:00 2001 From: knj Date: Fri, 21 Apr 2023 12:50:54 +0200 Subject: [PATCH 6/6] remove old fix --- lib_com/options.h | 1 - lib_dec/ivas_decision_matrix_dec.c | 11 ----------- 2 files changed, 12 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 7517074144..ab7b1f3cc1 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -166,7 +166,6 @@ #define FIX_392_LATE_REVERB /* DLB : Issue 392: keep late reverb by default off when output config is not BINAURAL_ROOM*/ #define FIX_ISM_DTX_CLICKS /* FhG: issue 394 - fix for clicks in ISM DTX for inactive to active TCX transitions */ -//#define FIX_ISM_DTX_CNG_BWIDTH /* FhG: issue 396 - fix for bw changes on CNG frames in ISM DTX for objects that use the decoder-side noise estimation */ #define FIX_ISM_DTX_CNG_BWIDTH_ALT /* VA: issue 396 - alternative fix for bw changes on CNG frames in ISM DTX for objects that use the decoder-side noise estimation */ #define ISSUE_24_CLEANUP_MCT_LFE /* Issue 24: Cleanup LFE path withing MCT */ diff --git a/lib_dec/ivas_decision_matrix_dec.c b/lib_dec/ivas_decision_matrix_dec.c index 77814881a8..e5be65ae24 100644 --- a/lib_dec/ivas_decision_matrix_dec.c +++ b/lib_dec/ivas_decision_matrix_dec.c @@ -89,18 +89,7 @@ void ivas_decision_matrix_dec( if ( st->cng_type == FD_CNG ) { -#ifdef FIX_ISM_DTX_CNG_BWIDTH - int16_t bwidth; - - /* do not set bandwidth for objects in ISM DTX that run their noise estimation in the decoder */ - bwidth = get_next_indice( st, 2 ); - if ( st->read_sid_info ) - { - st->bwidth = bwidth; - } -#else st->bwidth = get_next_indice( st, 2 ); -#endif } } if ( get_next_indice( st, 1 ) ) -- GitLab