From 726fb15a279e5610dc5091d462429848b766205e Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Mon, 7 Oct 2024 18:28:50 -0400 Subject: [PATCH 1/4] fix proposal for 907, LF issue when switching from TD stereo to FD stereo during a FER at 24.4 kbps --- lib_com/options.h | 1 + lib_com/syn_filt_fx.c | 38 ++++++++++++++++++++++++++++++ lib_dec/acelp_core_dec_ivas_fx.c | 4 ++++ lib_dec/acelp_core_switch_dec_fx.c | 12 ++++++++-- 4 files changed, 53 insertions(+), 2 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index d49cf2670..8aea03a09 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -182,6 +182,7 @@ #define FIX_871_REMOVE_UNNECESSARY_CONDITION /* VA: remove a condition that is not needed and prevented correct frame classification of the secondary channel of the TD stereo */ #define FIX_875_SATURATION_DURING_ROUNDING /* VA: fix a possible saturation when rounding */ #define FIX_882_LOW_LEVEL_DISCONTINUITIES /* VA: Fix 882, discontinuities for low level signal by adding a scaling function that uses rounding, this function is more complex than normal one, has to be used only when necessary*/ +#define FIX_907_MEM_UPDATE_ISSUE /* VA: fix for 907, multiples issues surrounding mem_syn_r and update of mem_syn2 when FS is changing */ /* ################## End DEVELOPMENT switches ######################### */ diff --git a/lib_com/syn_filt_fx.c b/lib_com/syn_filt_fx.c index e3a3024ba..3086ee8eb 100644 --- a/lib_com/syn_filt_fx.c +++ b/lib_com/syn_filt_fx.c @@ -442,6 +442,7 @@ void ivas_synth_mem_updt2_fx( { lerp( old_exc + L_EXC_MEM - last_L_frame, old_exc + L_EXC_MEM - L_frame, L_frame, last_L_frame ); } +#ifndef FIX_907_MEM_UPDATE_ISSUE IF( EQ_16( dec, DEC_IVAS ) ) { IF( EQ_16( L_frame, L_FRAME16k ) ) @@ -477,6 +478,7 @@ void ivas_synth_mem_updt2_fx( } } } +#endif /*Resamp memory*/ /*Size of LPC syn memory*/ /* 1.25/20.0 = 1.0/16.0 -> shift 4 to the right. */ @@ -484,7 +486,43 @@ void ivas_synth_mem_updt2_fx( mem_syn_r_size_new = shr( L_frame, 4 ); lerp( mem_syn_r + L_SYN_MEM - mem_syn_r_size_old, mem_syn_r + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); +#ifdef FIX_907_MEM_UPDATE_ISSUE + IF( EQ_16( dec, DEC_IVAS ) ) + { + IF( EQ_16( L_frame, L_FRAME16k ) ) + { + /* find scaling factor */ + // en1 = 1.25f * sum2_f( mem_syn2, M ); + en1 = Mpy_32_32( 1342177280 /*1.25f in Q30*/, sum2_f_16_fx( mem_syn2, M ) ); /* 2 * Q - 1 */ + en2 = L_shr( sum2_f_16_fx( mem_syn_r + L_SYN_MEM - M, M ), 1 ); /* 2 * Q - 1 */ + // loc_rat = sqrtf( en2 ) / ( sqrtf( en1 ) + 0.01f ); + IF( EQ_32( en1, 0 ) ) + { + loc_rat = 0; + move16(); + } + ELSE + { + en2_e = norm_l( en2 ); + en1_e = sub( norm_l( en1 ), 1 ); + tmp = div_l( L_shl( en1, en1_e ), extract_h( L_shl( en2, en2_e ) ) ); + en1_e = sub( en2_e, en1_e ); + tmp1 = L_shl( tmp, sub( 16 + 1, en1_e ) ); /* Q14 because of norm - 1 for the num */ + tmp2 = Isqrt( tmp1 ); /* Q16 */ + loc_rat = round_fx_sat( L_shl_sat( tmp2, sub( 16, en1_e ) ) ); /* loc_rat in Q15 */ + } + + /* scale synthesis filter memory */ + FOR( i = 0; i < M; i++ ) + { + // mem_syn_r[L_SYN_MEM - M + i] *= loc_rat; + mem_syn_r[L_SYN_MEM - M + i] = mult_r( mem_syn_r[L_SYN_MEM - M + i], loc_rat ); + move16(); + } + } + } +#endif Copy( mem_syn_r + L_SYN_MEM - M, mem_syn2, M ); IF( mem_syn != NULL ) diff --git a/lib_dec/acelp_core_dec_ivas_fx.c b/lib_dec/acelp_core_dec_ivas_fx.c index ef8670388..43f89bb70 100644 --- a/lib_dec/acelp_core_dec_ivas_fx.c +++ b/lib_dec/acelp_core_dec_ivas_fx.c @@ -460,7 +460,11 @@ ivas_error acelp_core_dec_ivas_fx( dec = DEC_IVAS; move16(); } +#ifndef FIX_907_MEM_UPDATE_ISSUE synth_mem_updt2( st->L_frame, st->last_L_frame, st->old_exc_fx, st->mem_syn_r, st->mem_syn2_fx, NULL, dec ); +#else + ivas_synth_mem_updt2_fx( st->L_frame, st->last_L_frame, st->old_exc_fx, st->mem_syn_r, st->mem_syn2_fx, NULL, dec, st->Q_syn ); +#endif Copy( st->old_exc_fx, old_exc_fx, L_EXC_MEM_DEC ); Copy_Scale_sig( st->mem_syn2_fx, st->mem_syn1_fx, M, sub( -1, st->Q_syn ) ); /*Q-1*/ Copy( st->mem_syn2_fx, st->mem_syn3_fx, M ); diff --git a/lib_dec/acelp_core_switch_dec_fx.c b/lib_dec/acelp_core_switch_dec_fx.c index 6eab8f07d..81f58bd27 100644 --- a/lib_dec/acelp_core_switch_dec_fx.c +++ b/lib_dec/acelp_core_switch_dec_fx.c @@ -635,7 +635,9 @@ ivas_error acelp_core_switch_dec_bfi_ivas_fx( MUSIC_POSTFILT_HANDLE hMusicPF; BPF_DEC_HANDLE hBPF; ivas_error error; - +#ifdef FIX_907_MEM_UPDATE_ISSUE + Word16 Prev_Q_syn_r; +#endif hMusicPF = st_fx->hMusicPF; hBPF = st_fx->hBPF; error = IVAS_ERR_OK; @@ -762,9 +764,15 @@ ivas_error acelp_core_switch_dec_bfi_ivas_fx( /*------------------------------------------------------------------* * Synthesis *-----------------------------------------------------------------*/ - +#ifdef FIX_907_MEM_UPDATE_ISSUE + Prev_Q_syn_r = st_fx->Q_syn; + move16(); +#endif Rescale_mem( Q_exc, &st_fx->prev_Q_syn, &st_fx->Q_syn, st_fx->mem_syn2_fx, st_fx->mem_syn_clas_estim_fx, 4, &st_fx->mem_deemph_fx, hBPF->pst_old_syn_fx, &hBPF->pst_mem_deemp_err_fx, &st_fx->agc_mem_fx[1], st_fx->hPFstat, 1, 0, NULL ); +#ifdef FIX_907_MEM_UPDATE_ISSUE + Scale_sig( st_fx->mem_syn_r, L_SYN_MEM, sub( st_fx->Q_syn, Prev_Q_syn_r ) ); +#endif Copy( st_fx->mem_syn2_fx, tmp1, M ); syn_12k8_fx( st_fx->L_frame, Aq, exc2, syn, tmp1, 1, Q_exc, st_fx->Q_syn ); -- GitLab From 478602914806dc0b94572580d3e070a57ed5fadc Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Mon, 7 Oct 2024 18:35:00 -0400 Subject: [PATCH 2/4] fix GCC --- lib_com/prot_fx.h | 8 ++++++-- lib_com/syn_filt_fx.c | 12 ++++++++++-- lib_dec/acelp_core_dec_ivas_fx.c | 2 +- lib_dec/core_dec_init_fx.c | 4 ++++ 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index a468fe607..af957784c 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -2386,8 +2386,12 @@ void ivas_synth_mem_updt2_fx( Word16 mem_syn_r[], /* i/o: synthesis filter memory */ Word16 mem_syn2[], /* o : synthesis filter memory for find_target */ Word16 mem_syn[], /* o : synthesis filter memory for find_target */ - const Word16 dec, /* i : flag for decoder indication */ - Word16 Q ); + const Word16 dec +#ifndef FIX_907_MEM_UPDATE_ISSUE + , /* i : flag for decoder indication */ + Word16 Q +#endif + ); #endif diff --git a/lib_com/syn_filt_fx.c b/lib_com/syn_filt_fx.c index 3086ee8eb..1555f2c3f 100644 --- a/lib_com/syn_filt_fx.c +++ b/lib_com/syn_filt_fx.c @@ -425,12 +425,20 @@ void ivas_synth_mem_updt2_fx( Word16 mem_syn_r[], /* i/o: synthesis filter memory */ Word16 mem_syn2[], /* o : synthesis filter memory for find_target */ Word16 mem_syn[], /* o : synthesis filter memory for find_target */ - const Word16 dec, /* i : flag for decoder indication */ - Word16 Q ) + const Word16 dec +#ifndef FIX_907_MEM_UPDATE_ISSUE + , /* i : flag for decoder indication */ + Word16 Q +#endif +) { Word16 mem_syn_r_size_old, mem_syn_r_size_new; Word32 en1, en2; +#ifndef FIX_907_MEM_UPDATE_ISSUE Word16 en1_e, en2_e, loc_rat, loc_rat_e, tmp, tmp_e, i; +#else + Word16 en1_e, en2_e, loc_rat, tmp, i; +#endif Word32 tmp1, tmp2; /* Residual and update old_exc */ diff --git a/lib_dec/acelp_core_dec_ivas_fx.c b/lib_dec/acelp_core_dec_ivas_fx.c index 43f89bb70..0827e4504 100644 --- a/lib_dec/acelp_core_dec_ivas_fx.c +++ b/lib_dec/acelp_core_dec_ivas_fx.c @@ -463,7 +463,7 @@ ivas_error acelp_core_dec_ivas_fx( #ifndef FIX_907_MEM_UPDATE_ISSUE synth_mem_updt2( st->L_frame, st->last_L_frame, st->old_exc_fx, st->mem_syn_r, st->mem_syn2_fx, NULL, dec ); #else - ivas_synth_mem_updt2_fx( st->L_frame, st->last_L_frame, st->old_exc_fx, st->mem_syn_r, st->mem_syn2_fx, NULL, dec, st->Q_syn ); + ivas_synth_mem_updt2_fx( st->L_frame, st->last_L_frame, st->old_exc_fx, st->mem_syn_r, st->mem_syn2_fx, NULL, dec ); #endif Copy( st->old_exc_fx, old_exc_fx, L_EXC_MEM_DEC ); Copy_Scale_sig( st->mem_syn2_fx, st->mem_syn1_fx, M, sub( -1, st->Q_syn ) ); /*Q-1*/ diff --git a/lib_dec/core_dec_init_fx.c b/lib_dec/core_dec_init_fx.c index 98113e16e..3fc9f7203 100644 --- a/lib_dec/core_dec_init_fx.c +++ b/lib_dec/core_dec_init_fx.c @@ -1673,7 +1673,11 @@ void open_decoder_LPD_ivas_fx( move16(); IF( !st->last_con_tcx ) { +#ifndef FIX_907_MEM_UPDATE_ISSUE ivas_synth_mem_updt2_fx( st->L_frame, st->last_L_frame, st->old_exc_fx, st->mem_syn_r, st->mem_syn2_fx, NULL, DEC, st->Q_syn ); +#else + ivas_synth_mem_updt2_fx( st->L_frame, st->last_L_frame, st->old_exc_fx, st->mem_syn_r, st->mem_syn2_fx, NULL, DEC ); +#endif } /*mem of deemphasis stayed unchanged.*/ -- GitLab From 9953aa1ea42f83150658433fb8aae3aa90c400f2 Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Mon, 7 Oct 2024 18:38:12 -0400 Subject: [PATCH 3/4] fix clang --- lib_com/prot_fx.h | 2 +- lib_com/syn_filt_fx.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index af957784c..10c8a8fb7 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -2391,7 +2391,7 @@ void ivas_synth_mem_updt2_fx( , /* i : flag for decoder indication */ Word16 Q #endif - ); +); #endif diff --git a/lib_com/syn_filt_fx.c b/lib_com/syn_filt_fx.c index 1555f2c3f..6edf75f2b 100644 --- a/lib_com/syn_filt_fx.c +++ b/lib_com/syn_filt_fx.c @@ -427,8 +427,8 @@ void ivas_synth_mem_updt2_fx( Word16 mem_syn[], /* o : synthesis filter memory for find_target */ const Word16 dec #ifndef FIX_907_MEM_UPDATE_ISSUE - , /* i : flag for decoder indication */ - Word16 Q + , /* i : flag for decoder indication */ + Word16 Q #endif ) { -- GitLab From ea9df0f48f83fd882e0f4b2952b22820e7b8b5c7 Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Tue, 8 Oct 2024 06:44:44 -0400 Subject: [PATCH 4/4] fix crash issue --- lib_com/syn_filt_fx.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib_com/syn_filt_fx.c b/lib_com/syn_filt_fx.c index 6edf75f2b..c348776e9 100644 --- a/lib_com/syn_filt_fx.c +++ b/lib_com/syn_filt_fx.c @@ -505,13 +505,15 @@ void ivas_synth_mem_updt2_fx( en2 = L_shr( sum2_f_16_fx( mem_syn_r + L_SYN_MEM - M, M ), 1 ); /* 2 * Q - 1 */ // loc_rat = sqrtf( en2 ) / ( sqrtf( en1 ) + 0.01f ); - IF( EQ_32( en1, 0 ) ) + IF( EQ_32( en2, 0 ) ) { loc_rat = 0; move16(); } ELSE { + + en1 = L_max( en1, 1 ); en2_e = norm_l( en2 ); en1_e = sub( norm_l( en1 ), 1 ); tmp = div_l( L_shl( en1, en1_e ), extract_h( L_shl( en2, en2_e ) ) ); -- GitLab