From 2cb7815d84d0cecfbaf2c0247ada152377aa0778 Mon Sep 17 00:00:00 2001 From: Manuel Jander Date: Mon, 4 May 2026 09:50:35 +0200 Subject: [PATCH 1/4] Fix saturation crash in LTV test cases in mem_preemph16k_fx. --- lib_com/options.h | 1 + lib_enc/ivas_core_pre_proc_front_fx.c | 3 +++ 2 files changed, 4 insertions(+) diff --git a/lib_com/options.h b/lib_com/options.h index 9ce33d497..9e0b33417 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -126,6 +126,7 @@ #define FIX_BASOP_2517_CLICK_IN_OMASA_LTV /* FhG: BASOP #2517: preserve precision by removing one-bit headroom from Q_min and allowing saturation during buffer scaling */ #define NONBE_FIX_ISSUE_2518 /* FhG: Fix issue 2518, noise during ACELP switching from 16KHz to 12k8Hz by improving Q_new calculation. */ #define NONBE_FIX_ISSUE_2518_TRANSENC_SAT_FIX /* FhG: Fix issue 2518, fix wrong amplitude because of saturation of x_tran in transf_cdbk_enc_fx() for transient signals. */ +#define NONBE_FIX_ISSUE_2569 /* FhG: Fix issue 2569, overflow of mem_preemph16k_fx in LTV test. */ #define FIX_BASOP_2559_Q_SYNTH_HISTORY_RESET /* FhG: BASOP issue 2559: reset hTcxDec->q_synth_history_fx in allocate_CoreCoder_TCX_fx() */ #define FIX_FLOAT_1578_OMASA_REND_SPIKES /* Nokia: Float issue 1578: Fix spikes and collapsed perception in OMASA/MASA rendering to FOA/HOA */ #define FIX_1521_SBA_LOUDNESS_STEREO /* FhG: issue 1521: Fix loudness for SBA to stereo rendering */ diff --git a/lib_enc/ivas_core_pre_proc_front_fx.c b/lib_enc/ivas_core_pre_proc_front_fx.c index 77be7fe6d..623ebd07e 100644 --- a/lib_enc/ivas_core_pre_proc_front_fx.c +++ b/lib_enc/ivas_core_pre_proc_front_fx.c @@ -755,6 +755,9 @@ void pre_proc_front_ivas_fx( /* Avoid saturation of resampling/delay decimation buffer. */ shift = s_min( shift, st->q_mem_decim16k_fx ); +#ifdef NONBE_FIX_ISSUE_2569 + shift = s_min( shift, add( -1, norm_s( st->mem_preemph16k_fx ) ) ); +#endif /* Limit Q_new here to st->q_inp because inside ivas_compute_core_buffers_fx() st->input is rescaled to Q_new */ shift = s_min( shift, st->q_inp ); -- GitLab From af4daa02f9bcb29de4b2a4229435fb11549bec32 Mon Sep 17 00:00:00 2001 From: Manuel Jander Date: Mon, 4 May 2026 11:22:14 +0200 Subject: [PATCH 2/4] Rescale st->buf_speech_enc in case of IVAS_CPE_TD the same as for IVAS_CPE_DFT case to avoid saturation. Remove st->q_mem_decim16k_fx from Q_new calculation in case resampling was already done and its consideration does not apply anymore. --- lib_enc/ivas_core_pre_proc_fx.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib_enc/ivas_core_pre_proc_fx.c b/lib_enc/ivas_core_pre_proc_fx.c index 014ea9ea7..5973a3be4 100644 --- a/lib_enc/ivas_core_pre_proc_fx.c +++ b/lib_enc/ivas_core_pre_proc_fx.c @@ -1271,7 +1271,19 @@ void ivas_compute_core_buffers_fx( IF( EQ_16( st->L_frame, L_FRAME16k ) ) { #ifdef NONBE_FIX_ISSUE_2206 +#ifdef NONBE_FIX_ISSUE_2569 + Word16 buf_speech_enc_q; + + buf_speech_enc_q = s_min( sub( Q15, st->exp_buf_speech_enc ), Q_old_inp_16k ); + Copy_Scale_sig_nosat( new_inp_16k_fx - lMemRecalc_16k, st->buf_speech_enc + sub( L_FRAME16k - L_FILT16k, lMemRecalc_16k ), add( lMemRecalc_16k, L_FRAME16k + L_FILT16k ), sub( buf_speech_enc_q, Q_old_inp_16k ) ); + // L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k + scale_sig( st->buf_speech_enc, sub( L_FRAME16k - L_FILT16k, lMemRecalc_16k ), sub( buf_speech_enc_q, sub( Q15, st->exp_buf_speech_enc ) ) ); + scale_sig( st->buf_speech_enc + L_FRAME16k + L_FRAME16k, L_PAST_MAX_32k + L_NEXT_MAX_32k, sub( buf_speech_enc_q, sub( Q15, st->exp_buf_speech_enc ) ) ); + st->exp_buf_speech_enc = sub( Q15, buf_speech_enc_q ); + move16(); +#else Copy_Scale_sig_nosat( new_inp_16k_fx - lMemRecalc_16k, st->buf_speech_enc + sub( L_FRAME16k - L_FILT16k, lMemRecalc_16k ), add( lMemRecalc_16k, L_FRAME16k + L_FILT16k ), sub( sub( Q15, st->exp_buf_speech_enc ), Q_old_inp_16k ) ); /* Q_new - 1 */ +#endif #else Copy( new_inp_16k_fx - lMemRecalc_16k, st->buf_speech_enc + sub( L_FRAME16k - L_FILT16k, lMemRecalc_16k ), add( lMemRecalc_16k, L_FRAME16k + L_FILT16k ) ); /* Q_new - 1 */ #endif @@ -1320,8 +1332,10 @@ void ivas_compute_core_buffers_fx( shift = s_min( shift, norm_arr( old_inp_16k_fx, (Word16) ( preemp_start_idx - old_inp_16k_fx ) ) ); shift = add( shift, Q_old_inp_16k ); +#ifndef NONBE_FIX_ISSUE_2569 /* Avoid saturation of resampling/delay decimation buffer. */ shift = s_min( shift, add( st->q_mem_decim16k_fx, 1 ) ); +#endif IF( st->hLPDmem != NULL ) { -- GitLab From c86cf6c03e69b8441eef93c77bb93f7b1951abbb Mon Sep 17 00:00:00 2001 From: Manuel Jander Date: Mon, 4 May 2026 12:09:56 +0200 Subject: [PATCH 3/4] Fix crash because Q_new runs away because hLPDmem->mem_w0 is 0 and norm_s returns 0. Use norm_arr( , 1 ) instead. --- lib_enc/updt_enc_fx.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib_enc/updt_enc_fx.c b/lib_enc/updt_enc_fx.c index 9224b1081..d7f205fad 100644 --- a/lib_enc/updt_enc_fx.c +++ b/lib_enc/updt_enc_fx.c @@ -55,7 +55,11 @@ void updt_enc_fx( tmp = s_min( tmp, norm_arr( hLPDmem->mem_syn2, M ) ); tmp = s_min( tmp, norm_arr( hLPDmem->mem_syn3, M ) ); tmp = s_min( tmp, norm_arr( hLPDmem->mem_syn_r, L_SYN_MEM ) ); +#ifdef NONBE_FIX_ISSUE_2569 + tmp = s_min( tmp, norm_arr( &hLPDmem->mem_w0, 1 ) ); +#else tmp = s_min( tmp, norm_s( hLPDmem->mem_w0 ) ); +#endif tmp = s_min( tmp, sub( 15, hLPDmem->q_mem_syn ) ); // tmp = sub( tmp, 1 ); scale_sig( hLPDmem->mem_syn, M, tmp ); -- GitLab From ec64607a844de55a90c7f015bfd81e3cd7d3c0fa Mon Sep 17 00:00:00 2001 From: Manuel Jander Date: Mon, 4 May 2026 13:31:20 +0200 Subject: [PATCH 4/4] Fix another 2 cases of norm_s( 0 ) returns 0. Use norm_arr( , 1 ) instead. --- lib_enc/ivas_core_pre_proc_front_fx.c | 2 +- lib_enc/ivas_core_pre_proc_fx.c | 4 ++++ lib_enc/updt_enc_fx.c | 1 - 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib_enc/ivas_core_pre_proc_front_fx.c b/lib_enc/ivas_core_pre_proc_front_fx.c index 623ebd07e..92f753704 100644 --- a/lib_enc/ivas_core_pre_proc_front_fx.c +++ b/lib_enc/ivas_core_pre_proc_front_fx.c @@ -756,7 +756,7 @@ void pre_proc_front_ivas_fx( /* Avoid saturation of resampling/delay decimation buffer. */ shift = s_min( shift, st->q_mem_decim16k_fx ); #ifdef NONBE_FIX_ISSUE_2569 - shift = s_min( shift, add( -1, norm_s( st->mem_preemph16k_fx ) ) ); + shift = s_min( shift, add( -1, norm_arr( &st->mem_preemph16k_fx, 1 ) ) ); #endif /* Limit Q_new here to st->q_inp because inside ivas_compute_core_buffers_fx() st->input is rescaled to Q_new */ diff --git a/lib_enc/ivas_core_pre_proc_fx.c b/lib_enc/ivas_core_pre_proc_fx.c index 5973a3be4..f315da04b 100644 --- a/lib_enc/ivas_core_pre_proc_fx.c +++ b/lib_enc/ivas_core_pre_proc_fx.c @@ -706,7 +706,11 @@ void pre_proc_ivas_fx( #ifdef NONBE_FIX_ISSUE_2206 // L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k + 320 ); tmp = add( norm_arr( wsp_fx, L_FRAME + L_LOOK_12k8 ), sub( Q15, e_old_wsp ) ); +#ifdef NONBE_FIX_ISSUE_2569 + tmp = s_min( tmp, add( norm_arr( &st->mem_wsp_enc, 1 ), sub( Q15, st->exp_buf_wspeech_enc ) ) ); +#else tmp = s_min( tmp, add( norm_s( st->mem_wsp_enc ), sub( Q15, st->exp_buf_wspeech_enc ) ) ); +#endif tmp = s_min( tmp, add( norm_arr( st->buf_wspeech_enc, (Word16) ( st->wspeech_enc - st->buf_wspeech_enc ) ), sub( Q15, st->exp_buf_wspeech_enc ) ) ); tmp = s_min( tmp, add( norm_arr( st->wspeech_enc + L_FRAME + L_LOOK_12k8, /* L_NEXT_MAX_16k + */ 320 ), sub( Q15, st->exp_buf_wspeech_enc ) ) ); tmp = s_min( Q15, tmp ); diff --git a/lib_enc/updt_enc_fx.c b/lib_enc/updt_enc_fx.c index d7f205fad..bc48bfb7b 100644 --- a/lib_enc/updt_enc_fx.c +++ b/lib_enc/updt_enc_fx.c @@ -61,7 +61,6 @@ void updt_enc_fx( tmp = s_min( tmp, norm_s( hLPDmem->mem_w0 ) ); #endif tmp = s_min( tmp, sub( 15, hLPDmem->q_mem_syn ) ); - // tmp = sub( tmp, 1 ); scale_sig( hLPDmem->mem_syn, M, tmp ); scale_sig( hLPDmem->mem_syn1_fx, M, tmp ); scale_sig( hLPDmem->mem_syn2, M, tmp ); -- GitLab