From be825bd16b290b12747e2c6e046adf1ea160abef Mon Sep 17 00:00:00 2001 From: advasila Date: Fri, 11 Aug 2023 22:46:29 +0300 Subject: [PATCH 1/5] modify bit alloc in masa 1 obj --- lib_com/ivas_omasa_com.c | 17 +++++++++++++++++ lib_com/options.h | 1 + 2 files changed, 18 insertions(+) diff --git a/lib_com/ivas_omasa_com.c b/lib_com/ivas_omasa_com.c index 8e385537c3..e8d3b30e54 100644 --- a/lib_com/ivas_omasa_com.c +++ b/lib_com/ivas_omasa_com.c @@ -253,6 +253,23 @@ int32_t ivas_interformat_brate( nBits = (int16_t) ( nBits * GAMMA_ISM_HIGH_IMP3 ); } } +#ifdef FIX_694_OMASA_EXTREME + else if ( ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ && element_brate == 16000 ) + { + if ( ism_imp == ISM_LOW_IMP ) + { + nBits = (int16_t) ( nBits * GAMMA_ISM_LOW_IMP4 ); + } + else if ( ism_imp == ISM_MEDIUM_IMP ) + { + nBits = (int16_t) ( nBits * GAMMA_ISM_MEDIUM_IMP4 ); + } + else /* ISM_HIGH_IMP */ + { + nBits = (int16_t) ( nBits * GAMMA_ISM_HIGH_IMP3 ); + } + } +#endif else { if ( ism_imp == ISM_LOW_IMP ) diff --git a/lib_com/options.h b/lib_com/options.h index b644c2f4db..da3465aaf6 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -247,6 +247,7 @@ #define FIX_685_BER_IN_HVQ /* Eri: Fix for issue 685. Invalid configuration in EVS now happening in IVAS with variable rate core. Remove BER warning for IVAS. */ #define FIX_674_MISSING_TABLES_FOR_TDREND_REVERB /* Eri: add tables for 32kHz, 16kHz (and update 48kHz) for left/right energies and coherence for late reverb in TD renderer path. Also read tables from binary when hrtf binaries are used. */ +#define FIX_694_OMASA_EXTREME /* Nokia: fix for crach in OMASA on extreme sample */ /* ################## End BE DEVELOPMENT switches ######################### */ -- GitLab From 22fc24c3e337faffcd9b5eed3fba360f91374285 Mon Sep 17 00:00:00 2001 From: advasila Date: Sat, 12 Aug 2023 09:54:35 +0300 Subject: [PATCH 2/5] fix crash on 2 objects in OMASA --- lib_com/ivas_prot.h | 4 ++++ lib_enc/ivas_cpe_enc.c | 12 ++++++++++++ lib_enc/ivas_stereo_classifier.c | 7 +++++++ 3 files changed, 23 insertions(+) diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index c299e999cf..22847b37fd 100755 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -1929,6 +1929,10 @@ int16_t select_stereo_mode( CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ const IVAS_FORMAT ivas_format, /* i : IVAS format */ const int32_t ivas_total_brate /* i : IVAS total brate */ +#ifdef FIX_694_OMASA_EXTREME + , + const int32_t real_brate /* i : real available brate */ +#endif ); void stereo_classifier_init( diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index fe3ac5535b..b56bc4474d 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -181,7 +181,19 @@ ivas_error ivas_cpe_enc( if ( sts[0]->ini_frame > 0 && st_ivas->hMCT == NULL ) { +#ifdef FIX_694_OMASA_EXTREME + if ( ivas_format == MASA_ISM_FORMAT && st_ivas->nSCE > 0 ) + { + hCPE->element_mode = select_stereo_mode( hCPE, ivas_format, ivas_total_brate, element_brate_ref + hCPE->brate_surplus - nb_bits_metadata * FRAMES_PER_SEC ); + } + else + { + hCPE->element_mode = select_stereo_mode( hCPE, ivas_format, ivas_total_brate, ivas_total_brate ); + } +#else hCPE->element_mode = select_stereo_mode( hCPE, ivas_format, ivas_total_brate ); +#endif + } #ifdef MASA_AND_OBJECTS diff --git a/lib_enc/ivas_stereo_classifier.c b/lib_enc/ivas_stereo_classifier.c index cedccea00e..c4f59f018e 100644 --- a/lib_enc/ivas_stereo_classifier.c +++ b/lib_enc/ivas_stereo_classifier.c @@ -90,6 +90,10 @@ int16_t select_stereo_mode( CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ const IVAS_FORMAT ivas_format, /* i : IVAS format */ const int32_t ivas_total_brate /* i : IVAS total brate */ +#ifdef FIX_694_OMASA_EXTREME + , + const int32_t real_brate /* i : bitrate surplus in MASA_ISM_FORMAT */ +#endif ) { int16_t element_mode; @@ -112,6 +116,9 @@ int16_t select_stereo_mode( stereo_switching_flag = 1; if ( hCPE->element_brate >= MIN_BRATE_MDCT_STEREO || ( ivas_format >= MASA_FORMAT && ivas_total_brate < MASA_STEREO_MIN_BITRATE ) +#ifdef FIX_694_OMASA_EXTREME + || ( ivas_format >= MASA_FORMAT && real_brate < MASA_STEREO_MIN_BITRATE ) /* both conditions should stay such that the second one is activated only when the surplus bitrate is negative*/ +#endif #ifdef DEBUGGING || ( hCPE->stereo_mode_cmdl == IVAS_CPE_DFT || hCPE->stereo_mode_cmdl == IVAS_CPE_TD ) #endif -- GitLab From 9ed56c08a97ee94c3823e63d0da944facbd3395d Mon Sep 17 00:00:00 2001 From: advasila Date: Sun, 13 Aug 2023 20:28:21 +0300 Subject: [PATCH 3/5] fix clang --- lib_com/ivas_omasa_com.c | 2 +- lib_enc/ivas_cpe_enc.c | 1 - lib_enc/ivas_stereo_classifier.c | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/lib_com/ivas_omasa_com.c b/lib_com/ivas_omasa_com.c index e8d3b30e54..00ff3580ae 100644 --- a/lib_com/ivas_omasa_com.c +++ b/lib_com/ivas_omasa_com.c @@ -253,7 +253,7 @@ int32_t ivas_interformat_brate( nBits = (int16_t) ( nBits * GAMMA_ISM_HIGH_IMP3 ); } } -#ifdef FIX_694_OMASA_EXTREME +#ifdef FIX_694_OMASA_EXTREME else if ( ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ && element_brate == 16000 ) { if ( ism_imp == ISM_LOW_IMP ) diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index d0bdda7e9b..7eb171ead2 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -193,7 +193,6 @@ ivas_error ivas_cpe_enc( #else hCPE->element_mode = select_stereo_mode( hCPE, ivas_format, ivas_total_brate ); #endif - } #ifdef MASA_AND_OBJECTS diff --git a/lib_enc/ivas_stereo_classifier.c b/lib_enc/ivas_stereo_classifier.c index c4f59f018e..feff92e20b 100644 --- a/lib_enc/ivas_stereo_classifier.c +++ b/lib_enc/ivas_stereo_classifier.c @@ -92,7 +92,7 @@ int16_t select_stereo_mode( const int32_t ivas_total_brate /* i : IVAS total brate */ #ifdef FIX_694_OMASA_EXTREME , - const int32_t real_brate /* i : bitrate surplus in MASA_ISM_FORMAT */ + const int32_t real_brate /* i : bitrate surplus in MASA_ISM_FORMAT */ #endif ) { -- GitLab From 8a3a120b84f1d4ce92bd45a622c49a8ffb1081fd Mon Sep 17 00:00:00 2001 From: advasila Date: Sun, 13 Aug 2023 21:56:50 +0300 Subject: [PATCH 4/5] alternative solution without touching the stereo selection --- lib_com/ivas_omasa_com.c | 42 ++++++++++++++++++++++++-------- lib_com/ivas_prot.h | 4 --- lib_com/options.h | 2 +- lib_enc/ivas_cpe_enc.c | 11 --------- lib_enc/ivas_stereo_classifier.c | 7 ------ 5 files changed, 33 insertions(+), 33 deletions(-) diff --git a/lib_com/ivas_omasa_com.c b/lib_com/ivas_omasa_com.c index 00ff3580ae..bee378307b 100644 --- a/lib_com/ivas_omasa_com.c +++ b/lib_com/ivas_omasa_com.c @@ -240,29 +240,51 @@ int32_t ivas_interformat_brate( ( ism_mode == ISM_MASA_MODE_DISC && element_brate == 9600 ) /* this condition corresponds to the ivas_total_brate = 24400 and 1 object */ ) { - if ( ism_imp == ISM_LOW_IMP ) - { - nBits = (int16_t) ( nBits * GAMMA_ISM_LOW_IMP3 ); - } - else if ( ism_imp == ISM_MEDIUM_IMP ) +#ifdef FIX_694_OMASA_EXTREME + if ( ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ && element_brate == IVAS_13k2 ) { - nBits = (int16_t) ( nBits * GAMMA_ISM_MEDIUM_IMP3 ); + if ( ism_imp == ISM_LOW_IMP ) + { + nBits = (int16_t) ( nBits * GAMMA_ISM_LOW_IMP3 ); + } + else if ( ism_imp == ISM_MEDIUM_IMP ) + { + nBits = (int16_t) ( nBits * GAMMA_ISM_MEDIUM_IMP3 ); + } + else /* ISM_HIGH_IMP */ + { + nBits = (int16_t) ( nBits * GAMMA_ISM_HIGH_IMP4 ); + } } - else /* ISM_HIGH_IMP */ + else { - nBits = (int16_t) ( nBits * GAMMA_ISM_HIGH_IMP3 ); +#endif + if ( ism_imp == ISM_LOW_IMP ) + { + nBits = (int16_t) ( nBits * GAMMA_ISM_LOW_IMP3 ); + } + else if ( ism_imp == ISM_MEDIUM_IMP ) + { + nBits = (int16_t) ( nBits * GAMMA_ISM_MEDIUM_IMP3 ); + } + else /* ISM_HIGH_IMP */ + { + nBits = (int16_t) ( nBits * GAMMA_ISM_HIGH_IMP3 ); + } +#ifdef FIX_694_OMASA_EXTREME } +#endif } #ifdef FIX_694_OMASA_EXTREME else if ( ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ && element_brate == 16000 ) { if ( ism_imp == ISM_LOW_IMP ) { - nBits = (int16_t) ( nBits * GAMMA_ISM_LOW_IMP4 ); + nBits = (int16_t) ( nBits * GAMMA_ISM_LOW_IMP ); } else if ( ism_imp == ISM_MEDIUM_IMP ) { - nBits = (int16_t) ( nBits * GAMMA_ISM_MEDIUM_IMP4 ); + nBits = (int16_t) ( nBits * GAMMA_ISM_MEDIUM_IMP ); } else /* ISM_HIGH_IMP */ { diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 83102247c9..02bdaa5d0b 100755 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -1978,10 +1978,6 @@ int16_t select_stereo_mode( CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ const IVAS_FORMAT ivas_format, /* i : IVAS format */ const int32_t ivas_total_brate /* i : IVAS total brate */ -#ifdef FIX_694_OMASA_EXTREME - , - const int32_t real_brate /* i : real available brate */ -#endif ); void stereo_classifier_init( diff --git a/lib_com/options.h b/lib_com/options.h index bd0586f9ac..2328affbe0 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -169,7 +169,7 @@ #define FIX_264_AUDIO_CHANNELS_TO_HEAP /* VA: issue 243: Move audio channels memory from stack to heap */ -#define FIX_694_OMASA_EXTREME /* Nokia: fix for crach in OMASA on extreme sample */ +#define FIX_694_OMASA_EXTREME /* Nokia: fix for crash in OMASA on extreme sample */ /* ################## End BE DEVELOPMENT switches ######################### */ diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index 7eb171ead2..0ef6072187 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -181,18 +181,7 @@ ivas_error ivas_cpe_enc( if ( sts[0]->ini_frame > 0 && st_ivas->hMCT == NULL ) { -#ifdef FIX_694_OMASA_EXTREME - if ( ivas_format == MASA_ISM_FORMAT && st_ivas->nSCE > 0 ) - { - hCPE->element_mode = select_stereo_mode( hCPE, ivas_format, ivas_total_brate, element_brate_ref + hCPE->brate_surplus - nb_bits_metadata * FRAMES_PER_SEC ); - } - else - { - hCPE->element_mode = select_stereo_mode( hCPE, ivas_format, ivas_total_brate, ivas_total_brate ); - } -#else hCPE->element_mode = select_stereo_mode( hCPE, ivas_format, ivas_total_brate ); -#endif } #ifdef MASA_AND_OBJECTS diff --git a/lib_enc/ivas_stereo_classifier.c b/lib_enc/ivas_stereo_classifier.c index feff92e20b..cedccea00e 100644 --- a/lib_enc/ivas_stereo_classifier.c +++ b/lib_enc/ivas_stereo_classifier.c @@ -90,10 +90,6 @@ int16_t select_stereo_mode( CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ const IVAS_FORMAT ivas_format, /* i : IVAS format */ const int32_t ivas_total_brate /* i : IVAS total brate */ -#ifdef FIX_694_OMASA_EXTREME - , - const int32_t real_brate /* i : bitrate surplus in MASA_ISM_FORMAT */ -#endif ) { int16_t element_mode; @@ -116,9 +112,6 @@ int16_t select_stereo_mode( stereo_switching_flag = 1; if ( hCPE->element_brate >= MIN_BRATE_MDCT_STEREO || ( ivas_format >= MASA_FORMAT && ivas_total_brate < MASA_STEREO_MIN_BITRATE ) -#ifdef FIX_694_OMASA_EXTREME - || ( ivas_format >= MASA_FORMAT && real_brate < MASA_STEREO_MIN_BITRATE ) /* both conditions should stay such that the second one is activated only when the surplus bitrate is negative*/ -#endif #ifdef DEBUGGING || ( hCPE->stereo_mode_cmdl == IVAS_CPE_DFT || hCPE->stereo_mode_cmdl == IVAS_CPE_TD ) #endif -- GitLab From 3c77cfde4aac453bbc4f5effe240021b8b3cf1d1 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 14 Aug 2023 07:04:53 +0200 Subject: [PATCH 5/5] sanity check to ensure the secondary channel always gets the minimal bitrate it needs --- lib_com/ivas_stereo_td_bit_alloc.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib_com/ivas_stereo_td_bit_alloc.c b/lib_com/ivas_stereo_td_bit_alloc.c index 823c1b1944..f77a0a0933 100644 --- a/lib_com/ivas_stereo_td_bit_alloc.c +++ b/lib_com/ivas_stereo_td_bit_alloc.c @@ -313,6 +313,10 @@ void tdm_bit_alloc( else { *total_brate_sec = min( *total_brate_sec, element_brate_wo_meta - ( 5900 + BWE_brate ) ); + +#ifdef FIX_694_OMASA_EXTREME + *total_brate_sec = max( *total_brate_sec, tdm_bit_allc_tbl[idx][coder_type] ); /* sanity check to ensure the secondary channel always gets the minimal bitrate it needs */ +#endif } /* Secondary channel bitrate adjusment */ -- GitLab