diff --git a/lib_com/options.h b/lib_com/options.h index 1226491d10e2f56176913942bc9e905ad1fde580..b3fbecfb0ce2b33a8c1bb76f5a28822ec22538a6 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_com/prot_fx.h b/lib_com/prot_fx.h index ddd0bfdcc51c73c5048c67f73151a6456d451501..17840b6116d1b1ff5e711a42a963e7e8b7c4d78d 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 f175f14b644b782859475161298002d10f123d95..da5fa3bcedf1ef3537eb2fb22ff9e279af8d56f6 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 0fde6543fc8d7204163a0e83800fca78cb37bdda..410a4778a56f51afab19f43973c4e0835263eb90 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 = 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 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 */