From 121988a44eaf8522bdd6cb45cae44ed0a0425c4e Mon Sep 17 00:00:00 2001 From: Eleni Fotopoulou Date: Fri, 27 Jun 2025 19:27:59 +0200 Subject: [PATCH 1/4] fix for issue 1329 --- lib_com/options.h | 9 +++++---- lib_enc/ivas_stereo_mdct_stereo_enc.c | 24 ++++++++++++++++++------ 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 9473a7cc22..a1488d8662 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -48,7 +48,7 @@ /* ################### Start DEBUGGING switches ########################### */ #ifndef RELEASE -/*#define DEBUGGING*/ /* Activate debugging part of the code */ +#define DEBUGGING /* Activate debugging part of the code */ #endif /*#define WMOPS*/ /* Activate complexity and memory counters */ /*#define WMOPS_PER_FRAME*/ /* Output per-frame complexity (writes one float value per frame to the file "wmops_analysis") */ @@ -58,14 +58,14 @@ #ifdef DEBUGGING /*#define DBG_BITSTREAM_ANALYSIS*/ /* Write bitstream with annotations to a text file */ -/*#define DEBUG_MODE_INFO*/ /* output most important parameters to the subdirectory "res/" */ +#define DEBUG_MODE_INFO /* output most important parameters to the subdirectory "res/" */ #ifdef DEBUG_MODE_INFO /*#define DEBUG_MODE_ACELP*/ /* output most important ACELP core parameters to the subdirectory "res/" */ /*#define DEBUG_MODE_TCX*/ /* output most important TCX core parameters to the subdirectory "res/" */ /*#define DEBUG_MODE_DFT*/ /* output most important DFT stereo parameters to the subdirectory "res/" */ /*#define DEBUG_MODE_TD*/ /* output most important TD stereo parameters to the subdirectory "res/ */ /*#define DEBUG_MODE_DIRAC*/ /* output most important DIRAC parameters to the subdirectory "res/" */ -/*#define DEBUG_MODE_MDCT*/ /* output most important MDCT parameters to the subdirectory "res/" */ +#define DEBUG_MODE_MDCT /* output most important MDCT parameters to the subdirectory "res/" */ /*#define DEBUG_MODE_PARAM_MC*/ /* output Parametric MC paramters to the subdirectory "res/" */ /*#define DEBUG_MODE_PARAM_ISM*/ /* output Parametric ISM paramters to the subdirectory "res/" */ /*#define DEBUG_MODE_INFO_TWEAK*/ /* enable command line switch to specify subdirectory for debug info output inside "./res/" */ @@ -77,7 +77,7 @@ #endif #ifdef DEBUG_MODE_MDCT -/*#define DEBUG_PLOT_BITS*/ +#define DEBUG_PLOT_BITS #endif #ifdef DEBUG_MODE_DFT @@ -176,6 +176,7 @@ #define NONBE_1250_MCMASA_LS_OUTPUT /* VA: issue 1250: fix crash in McMASA to custom LS output decoding */ #define NONBE_1302_FIX_OMASA_JBM_FLUSH /* VA: issue 1302: fix OMASA JBM bitrate switching flush in binaural output */ #define NONBE_1324_TC_BUFFER_MEMOERY_KEEP /* VA: issue 1324: do not reset TSM memory in JBM bitrate switching */ +#define NONBE_1329_FIX_OSBA_CRASH /* FhG: issue 1329: prevent assert when bit budget is low*/ /* ##################### End NON-BE switches ########################### */ diff --git a/lib_enc/ivas_stereo_mdct_stereo_enc.c b/lib_enc/ivas_stereo_mdct_stereo_enc.c index fa97984539..455ac54a85 100755 --- a/lib_enc/ivas_stereo_mdct_stereo_enc.c +++ b/lib_enc/ivas_stereo_mdct_stereo_enc.c @@ -411,17 +411,29 @@ void stereo_coder_tcx( nAvailBitsMS[k] = ( ( mct_on ? 2 * sts[0]->bits_frame_channel : sts[0]->bits_frame_nominal ) - sts[0]->side_bits_frame_channel - sts[1]->side_bits_frame_channel - ( nSubframes == 2 ? OFFSET_BITS_TCX10 : OFFSET_BITS_TCX20 ) ) / nSubframes; - MsStereoDecision( sfbConf, sts[0]->hTcxEnc->spectrum[k], sts[1]->hTcxEnc->spectrum[k], inv_spectrum[0][k], inv_spectrum[1][k], &hStereoMdct->mdct_stereo_mode[k], &ms_mask[k][0], nAvailBitsMS[k] ); - - if ( sts[0]->igf ) +#ifdef NONBE_1329_FIX_OSBA_CRASH + if ( mct_on && nAvailBitsMS[k] < 0 ) /*Force M/S when bit-budget is low for MCT*/ { - IGFEncStereoEncoder( sfbConf, sts[0]->hIGFEnc, sts[0]->hTcxEnc->spectrum[k], sts[1]->hTcxEnc->spectrum[k], &ms_mask[k][0], - &hStereoMdct->IGFStereoMode[k], hStereoMdct->mdct_stereo_mode[k], sts[0]->core == TCX_20_CORE, sts[0]->last_core == ACELP_CORE ); + hStereoMdct->mdct_stereo_mode[k] = 1; + hStereoMdct->IGFStereoMode[k] = 1; } else { - hStereoMdct->IGFStereoMode[k] = hStereoMdct->mdct_stereo_mode[k]; +#endif + MsStereoDecision( sfbConf, sts[0]->hTcxEnc->spectrum[k], sts[1]->hTcxEnc->spectrum[k], inv_spectrum[0][k], inv_spectrum[1][k], &hStereoMdct->mdct_stereo_mode[k], &ms_mask[k][0], nAvailBitsMS[k] ); + + if ( sts[0]->igf ) + { + IGFEncStereoEncoder( sfbConf, sts[0]->hIGFEnc, sts[0]->hTcxEnc->spectrum[k], sts[1]->hTcxEnc->spectrum[k], &ms_mask[k][0], + &hStereoMdct->IGFStereoMode[k], hStereoMdct->mdct_stereo_mode[k], sts[0]->core == TCX_20_CORE, sts[0]->last_core == ACELP_CORE ); + } + else + { + hStereoMdct->IGFStereoMode[k] = hStereoMdct->mdct_stereo_mode[k]; + } +#ifdef NONBE_1329_FIX_OSBA_CRASH } +#endif if ( hStereoMdct->mdct_stereo_mode[k] != SMDCT_DUAL_MONO || hStereoMdct->IGFStereoMode[k] != SMDCT_DUAL_MONO ) { -- GitLab From 2d7d6c17210e0a51eb7372225400d0245daeceb7 Mon Sep 17 00:00:00 2001 From: Eleni Fotopoulou Date: Fri, 27 Jun 2025 20:29:26 +0200 Subject: [PATCH 2/4] disable debugging --- lib_com/options.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 6f2d9ecfea..9709db8833 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -48,7 +48,7 @@ /* ################### Start DEBUGGING switches ########################### */ #ifndef RELEASE -#define DEBUGGING /* Activate debugging part of the code */ +/*#define DEBUGGING*/ /* Activate debugging part of the code */ #endif /*#define WMOPS*/ /* Activate complexity and memory counters */ /*#define WMOPS_PER_FRAME*/ /* Output per-frame complexity (writes one float value per frame to the file "wmops_analysis") */ @@ -58,14 +58,14 @@ #ifdef DEBUGGING /*#define DBG_BITSTREAM_ANALYSIS*/ /* Write bitstream with annotations to a text file */ -#define DEBUG_MODE_INFO /* output most important parameters to the subdirectory "res/" */ +/*#define DEBUG_MODE_INFO*/ /* output most important parameters to the subdirectory "res/" */ #ifdef DEBUG_MODE_INFO /*#define DEBUG_MODE_ACELP*/ /* output most important ACELP core parameters to the subdirectory "res/" */ /*#define DEBUG_MODE_TCX*/ /* output most important TCX core parameters to the subdirectory "res/" */ /*#define DEBUG_MODE_DFT*/ /* output most important DFT stereo parameters to the subdirectory "res/" */ /*#define DEBUG_MODE_TD*/ /* output most important TD stereo parameters to the subdirectory "res/ */ /*#define DEBUG_MODE_DIRAC*/ /* output most important DIRAC parameters to the subdirectory "res/" */ -#define DEBUG_MODE_MDCT /* output most important MDCT parameters to the subdirectory "res/" */ +/*#define DEBUG_MODE_MDCT*/ /* output most important MDCT parameters to the subdirectory "res/" */ /*#define DEBUG_MODE_PARAM_MC*/ /* output Parametric MC paramters to the subdirectory "res/" */ /*#define DEBUG_MODE_PARAM_ISM*/ /* output Parametric ISM paramters to the subdirectory "res/" */ /*#define DEBUG_MODE_INFO_TWEAK*/ /* enable command line switch to specify subdirectory for debug info output inside "./res/" */ -- GitLab From 70ac9fcdd4982e5a6a54e96bfc46948a3ea3f7a5 Mon Sep 17 00:00:00 2001 From: Eleni Fotopoulou Date: Wed, 2 Jul 2025 10:41:17 +0200 Subject: [PATCH 3/4] add some debugging info for bit consumption --- lib_com/options.h | 1 + lib_enc/enc_prm.c | 15 +++++++++++++++ lib_enc/ivas_enc.c | 5 +++++ lib_enc/ivas_mct_core_enc.c | 8 ++++++++ lib_enc/ivas_mdct_core_enc.c | 8 ++++++++ 5 files changed, 37 insertions(+) diff --git a/lib_com/options.h b/lib_com/options.h index 9709db8833..cbed29f488 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -78,6 +78,7 @@ #ifdef DEBUG_MODE_MDCT #define DEBUG_PLOT_BITS +#define DEBUG_OSBA_MD_BITS #endif #ifdef DEBUG_MODE_DFT diff --git a/lib_enc/enc_prm.c b/lib_enc/enc_prm.c index fb1a338ee6..951ae35b70 100644 --- a/lib_enc/enc_prm.c +++ b/lib_enc/enc_prm.c @@ -565,6 +565,12 @@ void writeTCXparam( nbits_tcx, NPRM_RESQ * st->hTcxCfg->resq, flag_ctx_hm ? &hm_cfg[k] : NULL ); } } +#ifdef DEBUG_PLOT_BITS + if ( core == TCX_10_CORE ) + { + dbgwrite( &nbits_tcx, sizeof( int16_t ), 1, 1, "./res/bits_RC" ); + } +#endif } } #ifdef DEBUG_PLOT_BITS @@ -576,6 +582,15 @@ void writeTCXparam( dbgwrite( &tmp, sizeof( int16_t ), 1, 1, "./res/bits_TNS" ); } } + else + { + if ( nSubframes == 1 ) + { + tmp = 0; + dbgwrite( &nbits_tcx, sizeof( int16_t ), 1, 1, "./res/bits_RC" ); + dbgwrite( &tmp, sizeof( int16_t ), 1, 1, "./res/bits_RC" ); + } + } #endif return; diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index db2e60fada..8f6eb68b96 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -412,6 +412,11 @@ ivas_error ivas_enc( /* get SBA TCs */ ivas_sba_getTCs( &data_f[n], st_ivas, input_frame ); } +#ifdef DEBUG_OSBA_MD_BITS + { + dbgwrite( &nb_bits_metadata[0], sizeof( int16_t ), hEncoderConfig->nchan_ism + 1, 1, "./res/osba_md_bits" ); + } +#endif /* core-coding of transport channels */ if ( st_ivas->nSCE == 1 ) diff --git a/lib_enc/ivas_mct_core_enc.c b/lib_enc/ivas_mct_core_enc.c index 27f1a0ad3c..4a46bd7b2f 100644 --- a/lib_enc/ivas_mct_core_enc.c +++ b/lib_enc/ivas_mct_core_enc.c @@ -471,6 +471,10 @@ void ivas_mct_core_enc( /*write IGF data to bitstream*/ for ( ch = 0; ch < nChannels; ch++ ) { +#ifdef DEBUG_PLOT_BITS + int16_t tmp = hBstr->nb_bits_tot; +#endif + st = sts[ch]; if ( sts[ch]->mct_chan_mode == MCT_CHAN_MODE_IGNORE ) @@ -478,6 +482,10 @@ void ivas_mct_core_enc( continue; } enc_prm_igf_mdct( st, hBstr ); +#ifdef DEBUG_PLOT_BITS + tmp = hBstr->nb_bits_tot - tmp; + dbgwrite( &tmp, sizeof( int16_t ), 1, 1, "./res/bits_IGF" ); +#endif } } diff --git a/lib_enc/ivas_mdct_core_enc.c b/lib_enc/ivas_mdct_core_enc.c index 8085fea231..0c669b581a 100644 --- a/lib_enc/ivas_mdct_core_enc.c +++ b/lib_enc/ivas_mdct_core_enc.c @@ -1146,6 +1146,9 @@ void ivas_mdct_core_whitening_enc( skipped_first_channel = 0; for ( ch = 0; ch < CPE_CHANNELS; ch++ ) { +#ifdef DEBUG_PLOT_BITS + int16_t tmp = hBstr->nb_bits_tot; +#endif st = sts[ch]; if ( st->mct_chan_mode == MCT_CHAN_MODE_IGNORE ) @@ -1170,6 +1173,11 @@ void ivas_mdct_core_whitening_enc( } encode_lpc_avq( hBstr, num_sns, param_lpc[ch], st->core, st->element_mode ); +#ifdef DEBUG_PLOT_BITS + tmp = hBstr->nb_bits_tot - tmp; + dbgwrite( &tmp, sizeof( int16_t ), 1, 1, "./res/bits_SNS" ); +#endif + st->side_bits_frame_channel += hBstr->nb_bits_tot - nbits_start_sns; } } -- GitLab From 6fcf59bace4a1e0ab9deefcf882b736f092f1292 Mon Sep 17 00:00:00 2001 From: Eleni Fotopoulou Date: Wed, 2 Jul 2025 10:57:02 +0200 Subject: [PATCH 4/4] add correct ms mask --- lib_enc/ivas_stereo_mdct_stereo_enc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib_enc/ivas_stereo_mdct_stereo_enc.c b/lib_enc/ivas_stereo_mdct_stereo_enc.c index 455ac54a85..d7cdd4786a 100755 --- a/lib_enc/ivas_stereo_mdct_stereo_enc.c +++ b/lib_enc/ivas_stereo_mdct_stereo_enc.c @@ -412,10 +412,11 @@ void stereo_coder_tcx( nAvailBitsMS[k] = ( ( mct_on ? 2 * sts[0]->bits_frame_channel : sts[0]->bits_frame_nominal ) - sts[0]->side_bits_frame_channel - sts[1]->side_bits_frame_channel - ( nSubframes == 2 ? OFFSET_BITS_TCX10 : OFFSET_BITS_TCX20 ) ) / nSubframes; #ifdef NONBE_1329_FIX_OSBA_CRASH - if ( mct_on && nAvailBitsMS[k] < 0 ) /*Force M/S when bit-budget is low for MCT*/ + if ( mct_on && nAvailBitsMS[k] <= 0 ) /*Force M/S when bit-budget is low for MCT*/ { hStereoMdct->mdct_stereo_mode[k] = 1; hStereoMdct->IGFStereoMode[k] = 1; + set_s( ms_mask[k], 1, sfbConf->sfbCnt ); } else { -- GitLab