From f94c6dcbe7cf92be4d73aa8d6ac68deb630476ce Mon Sep 17 00:00:00 2001 From: Markus Multrus Date: Fri, 5 Sep 2025 19:15:40 +0200 Subject: [PATCH 1/4] fix for scaling problem in apa_exec_ivas_fx() --- lib_com/options.h | 1 + lib_dec/jbm_pcmdsp_apa_fx.c | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib_com/options.h b/lib_com/options.h index 1226491d1..b3fbecfb0 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -91,6 +91,7 @@ #define FIX_1990_SANITIZER_IN_REVERB_LOAD /* Nokia: Fix issue part of issue 1990 by introducing missing free of structure. */ #define FIX_1995_REVERB_INIT /* VA/Nokia: issue 1995: Fix use-of-uninitialized-value in ivas_binaural_reverb_init() */ #define FIX_1996_MASKING_NOISE /* Dlb: Heavy precision loss in ola buffers causing discontinuity*/ +#define FIX1998_APA_EXEC_SCALING /* FhG: fix scaling of apa_exec_ivas_fx(); avoid continuously worse scaling with previous data */ /* #################### Start BASOP porting switches ############################ */ diff --git a/lib_dec/jbm_pcmdsp_apa_fx.c b/lib_dec/jbm_pcmdsp_apa_fx.c index 0fde6543f..6004f2592 100644 --- a/lib_dec/jbm_pcmdsp_apa_fx.c +++ b/lib_dec/jbm_pcmdsp_apa_fx.c @@ -964,8 +964,13 @@ UWord8 apa_exec_ivas_fx( { Word16 a_tmp[APA_BUF]; Word16 *buf_out_ptr = &( ps->buf_out_fx[ps->l_buf_out - ps->l_frm] ); +#ifdef FIX1998_APA_EXEC_SCALING + Word16 Q_buf_out_tmp = norm_arr( ps->buf_out_fx, ps->buf_out_capacity ); + Q_a_out = s_min( Q_a_out, Q_buf_out_tmp ); +#else Q_a_out = s_min( Q_a_out, ps->Q_buf_out ); +#endif Scale_sig( ps->buf_out_fx, ps->buf_out_capacity, sub( Q_a_out, ps->Q_buf_out ) ); // Q_buf_out -> Q_a_out IF( EQ_32( ps->scale, 100 ) ) { @@ -983,7 +988,7 @@ UWord8 apa_exec_ivas_fx( FOR( i = 0; i < ps->num_channels * APA_BUF_PER_CHANNEL; i++ ) { - a_tmp[i] = extract_h( L_shl( a_in[i], add( Q_a_out, Q5 ) ) ); // Q_a_out + a_tmp[i] = extract_h( L_shl( a_in[i], add( Q_a_out, Q16 - Q11 ) ) ); // Q_a_out move16(); } /* fill input frame */ -- GitLab From 7074dfe2376463cb831bfa09820a6eb572c2e3c2 Mon Sep 17 00:00:00 2001 From: Markus Multrus Date: Fri, 5 Sep 2025 20:09:29 +0200 Subject: [PATCH 2/4] add 1 bit extra headroom (as for Q_a_out) --- lib_dec/jbm_pcmdsp_apa_fx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_dec/jbm_pcmdsp_apa_fx.c b/lib_dec/jbm_pcmdsp_apa_fx.c index 6004f2592..629b6ada8 100644 --- a/lib_dec/jbm_pcmdsp_apa_fx.c +++ b/lib_dec/jbm_pcmdsp_apa_fx.c @@ -965,7 +965,7 @@ UWord8 apa_exec_ivas_fx( Word16 a_tmp[APA_BUF]; Word16 *buf_out_ptr = &( ps->buf_out_fx[ps->l_buf_out - ps->l_frm] ); #ifdef FIX1998_APA_EXEC_SCALING - Word16 Q_buf_out_tmp = norm_arr( ps->buf_out_fx, ps->buf_out_capacity ); + Word16 Q_buf_out_tmp = sub( norm_arr( ps->buf_out_fx, ps->buf_out_capacity ), Q1 ); Q_a_out = s_min( Q_a_out, Q_buf_out_tmp ); #else -- GitLab From dbfda4bba3e54f29641cfe303904e2d7cf620659 Mon Sep 17 00:00:00 2001 From: Markus Multrus Date: Fri, 5 Sep 2025 20:48:32 +0200 Subject: [PATCH 3/4] fix q-calculation --- lib_dec/jbm_pcmdsp_apa_fx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_dec/jbm_pcmdsp_apa_fx.c b/lib_dec/jbm_pcmdsp_apa_fx.c index 629b6ada8..37934d13f 100644 --- a/lib_dec/jbm_pcmdsp_apa_fx.c +++ b/lib_dec/jbm_pcmdsp_apa_fx.c @@ -965,7 +965,7 @@ UWord8 apa_exec_ivas_fx( Word16 a_tmp[APA_BUF]; Word16 *buf_out_ptr = &( ps->buf_out_fx[ps->l_buf_out - ps->l_frm] ); #ifdef FIX1998_APA_EXEC_SCALING - Word16 Q_buf_out_tmp = sub( norm_arr( ps->buf_out_fx, ps->buf_out_capacity ), Q1 ); + Word16 Q_buf_out_tmp = sub( add( norm_arr( ps->buf_out_fx, ps->buf_out_capacity ), ps->Q_buf_out ), Q1 ); Q_a_out = s_min( Q_a_out, Q_buf_out_tmp ); #else -- GitLab From 5cea852418aba6108d7e242076a5f18bb642c910 Mon Sep 17 00:00:00 2001 From: Markus Multrus Date: Fri, 5 Sep 2025 22:09:24 +0200 Subject: [PATCH 4/4] add norm_arr2(), which runs across a big number of samples --- lib_com/prot_fx.h | 3 +++ lib_com/tools_fx.c | 22 ++++++++++++++++++++++ lib_dec/jbm_pcmdsp_apa_fx.c | 2 +- 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index ddd0bfdcc..17840b611 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -4556,6 +4556,9 @@ Word16 find_guarded_bits_fx( Word32 n ); Word16 L_norm_arr( const Word32 *arr, Word16 size ); Word16 norm_arr( Word16 *arr, Word16 size ); +#ifdef FIX1998_APA_EXEC_SCALING +Word16 norm_arr2( Word16 *arr, Word32 size ); +#endif Word16 W_norm_arr( Word64 *arr, Word16 size ); Word16 get_min_scalefactor( Word32 x, Word32 y ); diff --git a/lib_com/tools_fx.c b/lib_com/tools_fx.c index f175f14b6..da5fa3bce 100644 --- a/lib_com/tools_fx.c +++ b/lib_com/tools_fx.c @@ -4864,6 +4864,28 @@ Word16 norm_arr( Word16 *arr, Word16 size ) return q; } +#ifdef FIX1998_APA_EXEC_SCALING +Word16 norm_arr2( Word16 *arr, Word32 size ) +{ + Word16 q = 15; + Word16 exp = 0; + move16(); + move16(); + FOR( Word32 i = 0; i < size; i++ ) + { + if ( arr[i] != 0 ) + { + exp = norm_s( arr[i] ); + } + if ( arr[i] != 0 ) + { + q = s_min( q, exp ); + } + } + return q; +} +#endif + Word16 W_norm_arr( Word64 *arr, Word16 size ) { Word16 q = 63; diff --git a/lib_dec/jbm_pcmdsp_apa_fx.c b/lib_dec/jbm_pcmdsp_apa_fx.c index 37934d13f..410a4778a 100644 --- a/lib_dec/jbm_pcmdsp_apa_fx.c +++ b/lib_dec/jbm_pcmdsp_apa_fx.c @@ -965,7 +965,7 @@ UWord8 apa_exec_ivas_fx( Word16 a_tmp[APA_BUF]; Word16 *buf_out_ptr = &( ps->buf_out_fx[ps->l_buf_out - ps->l_frm] ); #ifdef FIX1998_APA_EXEC_SCALING - Word16 Q_buf_out_tmp = sub( add( norm_arr( ps->buf_out_fx, ps->buf_out_capacity ), ps->Q_buf_out ), Q1 ); + Word16 Q_buf_out_tmp = sub( add( norm_arr2( ps->buf_out_fx, ps->buf_out_capacity ), ps->Q_buf_out ), Q1 ); Q_a_out = s_min( Q_a_out, Q_buf_out_tmp ); #else -- GitLab