From 65bf6c33fe201a1ba754c228ba95bc88804e265d Mon Sep 17 00:00:00 2001 From: vaclav Date: Wed, 20 Sep 2023 17:49:03 +0200 Subject: [PATCH 1/4] #define NONBE_FIX_788_SBA_DTX_BR_SWITCHING /* VA: issue 787: fix Msan error in SBA BR switching with dtx in FOA encoding */ --- lib_com/ivas_prot.h | 3 +++ lib_com/options.h | 1 + lib_enc/ivas_core_pre_proc.c | 7 ++++++- lib_enc/ivas_core_pre_proc_front.c | 12 +++++++++++- lib_enc/ivas_cpe_enc.c | 4 ++++ lib_enc/ivas_ism_enc.c | 4 ++++ lib_enc/ivas_sce_enc.c | 4 ++++ 7 files changed, 33 insertions(+), 2 deletions(-) diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 624494d24a..4d03784110 100755 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -204,6 +204,9 @@ ivas_error pre_proc_front_ivas( const int16_t force_front_vad, /* i : flag to force VAD decision */ const int16_t front_vad_dtx_flag, /* i : front-VAD DTX flag to overwrite VAD decision*/ const IVAS_FORMAT ivas_format, /* i : IVAS format */ +#ifdef NONBE_FIX_788_SBA_DTX_BR_SWITCHING + const int16_t MCT_flag, /* i : hMCT handle allocated (1) or not (0) */ +#endif const int32_t ivas_total_brate /* i : IVAS total bitrate */ ); diff --git a/lib_com/options.h b/lib_com/options.h index f00d747592..48a492eb31 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -204,6 +204,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_778_TNS_UNFIED_STEREO_MSAN /* FhG: Issue 778: MSAN error due to uninitialized TNS configuration */ #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 */ +#define NONBE_FIX_788_SBA_DTX_BR_SWITCHING /* VA: issue 787: fix Msan error in SBA BR switching with dtx in FOA encoding */ /* ##################### End NON-BE switches ########################### */ diff --git a/lib_enc/ivas_core_pre_proc.c b/lib_enc/ivas_core_pre_proc.c index 63b103086e..59a1c769fe 100644 --- a/lib_enc/ivas_core_pre_proc.c +++ b/lib_enc/ivas_core_pre_proc.c @@ -283,7 +283,12 @@ ivas_error pre_proc_ivas( } else if ( element_brate != last_element_brate ) { - SetModeIndex( st, st->bits_frame_nominal * FRAMES_PER_SEC, element_mode, MCT_flag ); +#ifdef NONBE_FIX_788_SBA_DTX_BR_SWITCHING + if ( st->core_brate != FRAME_NO_DATA ) +#endif + { + SetModeIndex( st, st->bits_frame_nominal * FRAMES_PER_SEC, element_mode, MCT_flag ); + } if ( st->extl != -1 && st->extl != IGF_BWE && st->igf == 1 ) { diff --git a/lib_enc/ivas_core_pre_proc_front.c b/lib_enc/ivas_core_pre_proc_front.c index 92c66f0de3..72abc87f48 100644 --- a/lib_enc/ivas_core_pre_proc_front.c +++ b/lib_enc/ivas_core_pre_proc_front.c @@ -108,7 +108,10 @@ ivas_error pre_proc_front_ivas( const int16_t force_front_vad, /* i : flag to force VAD decision */ const int16_t front_vad_dtx_flag, /* i : front-VAD DTX flag to overwrite VAD decision*/ const IVAS_FORMAT ivas_format, /* i : IVAS format */ - const int32_t ivas_total_brate /* i : IVAS total bitrate - for setting the DTX */ +#ifdef NONBE_FIX_788_SBA_DTX_BR_SWITCHING + const int16_t MCT_flag, /* i : hMCT handle allocated (1) or not (0) */ +#endif + const int32_t ivas_total_brate /* i : IVAS total bitrate - for setting the DTX */ ) { float *inp_12k8, *new_inp_12k8; /* pointers to current frame and new data */ @@ -780,6 +783,13 @@ ivas_error pre_proc_front_ivas( /* SNR-based speech/music classification */ if ( ( element_mode >= IVAS_CPE_DFT && element_brate >= IVAS_24k4 ) || ( element_mode == IVAS_SCE && element_brate >= SCE_SMC_THR ) ) { +#ifdef NONBE_FIX_788_SBA_DTX_BR_SWITCHING + if ( ivas_format == SBA_FORMAT && st->core_brate != FRAME_NO_DATA && st->last_core_brate == FRAME_NO_DATA ) + { + SetModeIndex( st, st->bits_frame_nominal * FRAMES_PER_SEC, element_mode, MCT_flag ); + } +#endif + if ( flag_16k_smc ) { /* Compute core-coder buffers at internal sampling rate */ diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index 18a609ccd6..a6251cb210 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -473,7 +473,11 @@ ivas_error ivas_cpe_enc( error = pre_proc_front_ivas( NULL, hCPE, hCPE->element_brate, nb_bits_metadata, input_frame, n, old_inp_12k8[n], old_inp_16k[n], &ener[n], &relE[n], A[n], Aw[n], epsP[n], lsp_new[n], lsp_mid[n], &vad_hover_flag[n], &attack_flag[n], realBuffer[n], imagBuffer[n], old_wsp[n], pitch_fr[n], voicing_fr[n], &loc_harm[n], &cor_map_sum[n], &vad_flag_dtx[n], enerBuffer[n], +#ifdef NONBE_FIX_788_SBA_DTX_BR_SWITCHING + fft_buff[n], A[0], lsp_new[0], currFlatness[n], tdm_ratio_idx, fr_bands, Etot_LR, lf_E, localVAD_HE_SAD, band_energies_LR, 0, st_ivas->hSpar != NULL ? st_ivas->hSpar->front_vad_flag : 0, 0, 0, ivas_format, st_ivas->hMCT != NULL, ivas_total_brate ); +#else fft_buff[n], A[0], lsp_new[0], currFlatness[n], tdm_ratio_idx, fr_bands, Etot_LR, lf_E, localVAD_HE_SAD, band_energies_LR, 0, st_ivas->hSpar != NULL ? st_ivas->hSpar->front_vad_flag : 0, 0, 0, ivas_format, ivas_total_brate ); +#endif if ( error != IVAS_ERR_OK ) { return error; diff --git a/lib_enc/ivas_ism_enc.c b/lib_enc/ivas_ism_enc.c index ec224f24bc..f1b1468d9c 100644 --- a/lib_enc/ivas_ism_enc.c +++ b/lib_enc/ivas_ism_enc.c @@ -175,7 +175,11 @@ ivas_error ivas_ism_enc( error = pre_proc_front_ivas( hSCE, NULL, hSCE->element_brate, nb_bits_metadata[sce_id], input_frame, 0, old_inp_12k8[sce_id][0], old_inp_16k[sce_id][0], &ener[sce_id][0], &relE[sce_id][0], A[sce_id][0], Aw[sce_id][0], epsP[sce_id][0], lsp_new[sce_id][0], lsp_mid[sce_id][0], &vad_hover_flag[sce_id][0], &attack_flag[sce_id][0], realBuffer[sce_id][0], imagBuffer[sce_id][0], old_wsp[sce_id][0], pitch_fr[sce_id][0], voicing_fr[sce_id][0], &loc_harm[sce_id][0], &cor_map_sum[sce_id][0], &vad_flag_dtx[sce_id][0], enerBuffer[sce_id][0], +#ifdef NONBE_FIX_788_SBA_DTX_BR_SWITCHING + fft_buff[sce_id][0], A[sce_id][0], lsp_new[sce_id][0], currFlatness[0], 0, fr_bands, Etot_LR, lf_E, localVAD_HE_SAD, NULL, 0, 0, 0, 0, ISM_FORMAT, 0, st_ivas->hEncoderConfig->ivas_total_brate ); +#else fft_buff[sce_id][0], A[sce_id][0], lsp_new[sce_id][0], currFlatness[0], 0, fr_bands, Etot_LR, lf_E, localVAD_HE_SAD, NULL, 0, 0, 0, 0, ISM_FORMAT, st_ivas->hEncoderConfig->ivas_total_brate ); +#endif if ( error != IVAS_ERR_OK ) { return error; diff --git a/lib_enc/ivas_sce_enc.c b/lib_enc/ivas_sce_enc.c index 8567693244..5ccf10dd25 100644 --- a/lib_enc/ivas_sce_enc.c +++ b/lib_enc/ivas_sce_enc.c @@ -184,7 +184,11 @@ ivas_error ivas_sce_enc( &ener[0], &relE[0], A[0], Aw[0], epsP[0], lsp_new[0], lsp_mid[0], &vad_hover_flag[0], &attack_flag[0], realBuffer[0], imagBuffer[0], old_wsp[0], pitch_fr[0], voicing_fr[0], &loc_harm[0], &cor_map_sum[0], &vad_flag_dtx[0], enerBuffer[0], fft_buff[0], A[0], lsp_new[0], currFlatness[0], 0, fr_bands, Etot_LR, lf_E, localVAD_HE_SAD, NULL, flag_16k_smc, +#ifdef NONBE_FIX_788_SBA_DTX_BR_SWITCHING + st_ivas->hSpar != NULL ? st_ivas->hSpar->front_vad_flag : 0, st_ivas->hSpar != NULL ? st_ivas->hSpar->force_front_vad : 0, st_ivas->hSpar != NULL ? st_ivas->hSpar->front_vad_dtx_flag : 0, ivas_format, 0, st_ivas->hEncoderConfig->ivas_total_brate ); +#else st_ivas->hSpar != NULL ? st_ivas->hSpar->front_vad_flag : 0, st_ivas->hSpar != NULL ? st_ivas->hSpar->force_front_vad : 0, st_ivas->hSpar != NULL ? st_ivas->hSpar->front_vad_dtx_flag : 0, ivas_format, st_ivas->hEncoderConfig->ivas_total_brate ); +#endif if ( error != IVAS_ERR_OK ) { return error; -- GitLab From 3b73c432c57cbcd17055325bf27bfa1e7fbddf92 Mon Sep 17 00:00:00 2001 From: rhb Date: Thu, 9 Nov 2023 15:28:04 +0100 Subject: [PATCH 2/4] amend fix to only trigger reconfig after NO_DATA frames if there was a bitrate switch in the meantime --- lib_enc/init_enc.c | 3 +++ lib_enc/ivas_core_pre_proc_front.c | 11 ++++++++++- lib_enc/stat_enc.h | 4 ++++ 3 files changed, 17 insertions(+), 1 deletion(-) mode change 100644 => 100755 lib_enc/init_enc.c mode change 100644 => 100755 lib_enc/stat_enc.h diff --git a/lib_enc/init_enc.c b/lib_enc/init_enc.c old mode 100644 new mode 100755 index b813a2730d..5833ee4ca6 --- a/lib_enc/init_enc.c +++ b/lib_enc/init_enc.c @@ -100,6 +100,9 @@ ivas_error init_encoder( st->low_rate_mode = 0; st->ini_frame = 0; st->inactive_coder_type_flag = 0; +#ifdef NONBE_FIX_788_SBA_DTX_BR_SWITCHING + st->sba_br_sw_while_no_data = 0; +#endif st->coder_type_raw = VOICED; st->last_coder_type_raw = st->coder_type_raw; diff --git a/lib_enc/ivas_core_pre_proc_front.c b/lib_enc/ivas_core_pre_proc_front.c index aee5031a68..8c874d859d 100755 --- a/lib_enc/ivas_core_pre_proc_front.c +++ b/lib_enc/ivas_core_pre_proc_front.c @@ -193,7 +193,11 @@ ivas_error pre_proc_front_ivas( st = hSCE->hCoreCoder[n]; signal_in = hSCE->hCoreCoder[n]->input; element_mode = IVAS_SCE; +#ifdef NONBE_FIX_788_SBA_DTX_BR_SWITCHING + last_element_brate = hSCE->last_element_brate; +#else last_element_brate = hSCE->element_brate; /* hack - the past parameter is not really needed */ +#endif hStereoClassif = NULL; lr_vad_enabled = 0; } @@ -791,9 +795,14 @@ ivas_error pre_proc_front_ivas( if ( ( element_mode >= IVAS_CPE_DFT && element_brate >= IVAS_24k4 ) || ( element_mode == IVAS_SCE && element_brate >= SCE_SMC_THR ) ) { #ifdef NONBE_FIX_788_SBA_DTX_BR_SWITCHING - if ( ivas_format == SBA_FORMAT && st->core_brate != FRAME_NO_DATA && st->last_core_brate == FRAME_NO_DATA ) + if ( ivas_format == SBA_FORMAT && st->core_brate != FRAME_NO_DATA && st->last_core_brate == FRAME_NO_DATA && st->sba_br_sw_while_no_data ) { SetModeIndex( st, st->bits_frame_nominal * FRAMES_PER_SEC, element_mode, MCT_flag ); + st->sba_br_sw_while_no_data = 0; + } + else if ( ivas_format == SBA_FORMAT && st->core_brate == FRAME_NO_DATA && element_brate != last_element_brate ) + { + st->sba_br_sw_while_no_data = 1; } #endif diff --git a/lib_enc/stat_enc.h b/lib_enc/stat_enc.h old mode 100644 new mode 100755 index 9a1dd27135..b4dda7da78 --- a/lib_enc/stat_enc.h +++ b/lib_enc/stat_enc.h @@ -1556,6 +1556,10 @@ typedef struct enc_core_structure int16_t dtx_sce_sba; /* enable use of FD CNG with transform domain cores in SCE SBA */ +#ifdef NONBE_FIX_788_SBA_DTX_BR_SWITCHING + int16_t sba_br_sw_while_no_data; /* Indicator for SBA bitrate switch while in FRAME_NO_DATA mode */ +#endif + } Encoder_State, *ENC_CORE_HANDLE; -- GitLab From 37c386b0063d0b9c60f11e06041c340ca8257f1c Mon Sep 17 00:00:00 2001 From: rhb Date: Thu, 9 Nov 2023 15:35:16 +0100 Subject: [PATCH 3/4] clang format --- lib_enc/ivas_core_pre_proc_front.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) mode change 100755 => 100644 lib_enc/ivas_core_pre_proc_front.c diff --git a/lib_enc/ivas_core_pre_proc_front.c b/lib_enc/ivas_core_pre_proc_front.c old mode 100755 new mode 100644 index 8c874d859d..f55f0e966b --- a/lib_enc/ivas_core_pre_proc_front.c +++ b/lib_enc/ivas_core_pre_proc_front.c @@ -118,7 +118,7 @@ ivas_error pre_proc_front_ivas( #ifdef NONBE_FIX_788_SBA_DTX_BR_SWITCHING const int16_t MCT_flag, /* i : hMCT handle allocated (1) or not (0) */ #endif - const int32_t ivas_total_brate /* i : IVAS total bitrate - for setting the DTX */ + const int32_t ivas_total_brate /* i : IVAS total bitrate - for setting the DTX */ ) { float *inp_12k8, *new_inp_12k8; /* pointers to current frame and new data */ @@ -196,7 +196,7 @@ ivas_error pre_proc_front_ivas( #ifdef NONBE_FIX_788_SBA_DTX_BR_SWITCHING last_element_brate = hSCE->last_element_brate; #else - last_element_brate = hSCE->element_brate; /* hack - the past parameter is not really needed */ + last_element_brate = hSCE->element_brate; /* hack - the past parameter is not really needed */ #endif hStereoClassif = NULL; lr_vad_enabled = 0; -- GitLab From d0d4779ada7653d12551884335daa36ddb7262c1 Mon Sep 17 00:00:00 2001 From: rhb Date: Thu, 9 Nov 2023 15:45:21 +0100 Subject: [PATCH 4/4] clang format --- lib_enc/ivas_core_pre_proc_front.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) mode change 100755 => 100644 lib_enc/ivas_core_pre_proc_front.c diff --git a/lib_enc/ivas_core_pre_proc_front.c b/lib_enc/ivas_core_pre_proc_front.c old mode 100755 new mode 100644 index 8e5e94cab5..65e1b4ddba --- a/lib_enc/ivas_core_pre_proc_front.c +++ b/lib_enc/ivas_core_pre_proc_front.c @@ -98,16 +98,16 @@ ivas_error pre_proc_front_ivas( const float tdm_lsp_new_PCh[M], /* i : unq. LSPs of primary channel */ const float currFlatness, /* i : flatness parameter */ const int16_t tdm_ratio_idx, /* i : Current Ratio_L index */ - float fr_bands_LR[][2 * NB_BANDS], /* i : energy in frequency bands */ - const float Etot_LR[], /* i : total energy Left & Right channel */ - float lf_E_LR[][2 * VOIC_BINS], /* i : per bin spectrum energy in lf, LR channels */ - const int16_t localVAD_HE_SAD_LR[], /* i : HE-SAD flag without hangover, LR channels */ - float band_energies_LR[2 * NB_BANDS], /* o : energy in critical bands without minimum noise floor E_MIN */ - const int16_t flag_16k_smc, /* i : flag to indicate if the OL SMC is run at 16 kHz */ - const int16_t front_vad_flag, /* i : front-VAD flag to overwrite VAD decision */ - const int16_t force_front_vad, /* i : flag to force VAD decision */ - const int16_t front_vad_dtx_flag, /* i : front-VAD DTX flag to overwrite VAD decision*/ - const IVAS_FORMAT ivas_format, /* i : IVAS format */ + float fr_bands_LR[][2 * NB_BANDS], /* i : energy in frequency bands */ + const float Etot_LR[], /* i : total energy Left & Right channel */ + float lf_E_LR[][2 * VOIC_BINS], /* i : per bin spectrum energy in lf, LR channels */ + const int16_t localVAD_HE_SAD_LR[], /* i : HE-SAD flag without hangover, LR channels */ + float band_energies_LR[2 * NB_BANDS], /* o : energy in critical bands without minimum noise floor E_MIN */ + const int16_t flag_16k_smc, /* i : flag to indicate if the OL SMC is run at 16 kHz */ + const int16_t front_vad_flag, /* i : front-VAD flag to overwrite VAD decision */ + const int16_t force_front_vad, /* i : flag to force VAD decision */ + const int16_t front_vad_dtx_flag, /* i : front-VAD DTX flag to overwrite VAD decision*/ + const IVAS_FORMAT ivas_format, /* i : IVAS format */ #ifdef NONBE_FIX_788_SBA_DTX_BR_SWITCHING const int16_t MCT_flag, /* i : hMCT handle allocated (1) or not (0) */ #endif @@ -189,7 +189,7 @@ ivas_error pre_proc_front_ivas( #ifdef NONBE_FIX_788_SBA_DTX_BR_SWITCHING last_element_brate = hSCE->last_element_brate; #else - last_element_brate = hSCE->element_brate; /* hack - the past parameter is not really needed */ + last_element_brate = hSCE->element_brate; /* hack - the past parameter is not really needed */ #endif hStereoClassif = NULL; lr_vad_enabled = 0; -- GitLab