From 32a76b95f15c3fa39268c8e88cc232f4d40d4664 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Tue, 16 Jul 2024 21:44:37 +0530 Subject: [PATCH 1/2] Fix for LTV crash for stereo at 13.2 kbps, 32kHz in, 32kHz out, DTX on, random FER at 5%, bandwidth switching --- lib_com/prot_fx2.h | 10 +++ lib_dec/dec_gen_voic_fx.c | 2 +- lib_dec/dec_pit_exc_fx.c | 4 +- lib_dec/dec_tran_fx.c | 8 +- lib_dec/dec_uv_fx.c | 2 +- lib_dec/gain_dec_fx.c | 141 +++++++++++++++++++++++++++++++++ lib_dec/gaus_dec_fx.c | 9 ++- lib_dec/ivas_td_low_rate_dec.c | 4 +- 8 files changed, 170 insertions(+), 10 deletions(-) diff --git a/lib_com/prot_fx2.h b/lib_com/prot_fx2.h index fc488f233..8185faf56 100644 --- a/lib_com/prot_fx2.h +++ b/lib_com/prot_fx2.h @@ -6392,6 +6392,16 @@ void lp_gain_updt_fx( Word16 *lp_gainc, /* i/o: LP-filtered code gain (FEC) Q3 */ const Word16 L_frame /* i : length of the frame */ ); + +void lp_gain_updt_ivas_fx( + const Word16 i_subfr, /* i : subframe number Q0 */ + const Word16 gain_pit, /* i : Decoded gain pitch Q14 */ + const Word32 norm_gain_code, /* i : Normalised gain code Q16 */ + Word16 *lp_gainp, /* i/o: LP-filtered pitch gain(FEC) Q14 */ + Word16 *lp_gainc, /* i/o: LP-filtered code gain (FEC) Q3 */ + const Word16 L_frame /* i : length of the frame */ +); + Word32 gain_dec_gaus_fx( /* o : quantized codebook gain Q16 */ Word16 index, /* i : quantization index */ const Word16 bits, /* i : number of bits to quantize */ diff --git a/lib_dec/dec_gen_voic_fx.c b/lib_dec/dec_gen_voic_fx.c index 1fd514e1c..e48c4aae2 100644 --- a/lib_dec/dec_gen_voic_fx.c +++ b/lib_dec/dec_gen_voic_fx.c @@ -708,7 +708,7 @@ ivas_error decod_gen_voic_ivas_fx( } /* update LP filtered gains for the case of frame erasures */ - lp_gain_updt_fx( i_subfr_fx, gain_pit_fx, L_add( norm_gain_code_fx, norm_gain_preQ_fx ), &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, L_frame ); + lp_gain_updt_ivas_fx( i_subfr_fx, gain_pit_fx, L_add( norm_gain_code_fx, norm_gain_preQ_fx ), &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, L_frame ); /*----------------------------------------------------------------------* * Find the total excitation diff --git a/lib_dec/dec_pit_exc_fx.c b/lib_dec/dec_pit_exc_fx.c index aba8af9b2..6b56f264a 100644 --- a/lib_dec/dec_pit_exc_fx.c +++ b/lib_dec/dec_pit_exc_fx.c @@ -150,7 +150,7 @@ void dec_pit_exc_fx( test(); test(); test(); - IF( ( ( GE_32( st_fx->core_brate, MIN_RATE_FCB ) || ( EQ_16( st_fx->GSC_noisy_speech, 1 ) && ( ( EQ_16( st_fx->L_frame, L_FRAME ) && GE_32( st_fx->core_brate, ACELP_13k20 ) ) || ( EQ_16( st_fx->L_frame, L_FRAME16k ) && GE_32( st_fx->core_brate, GSC_H_RATE_STG ) ) || st_fx->GSC_IVAS_mode == 0 ) ) ) && EQ_16( L_subfr_fx, L_SUBFR ) ) ) + IF ( ( ( GE_32( st_fx->core_brate, MIN_RATE_FCB ) || ( EQ_16( st_fx->GSC_noisy_speech, 1 ) && ( ( EQ_16( st_fx->L_frame, L_FRAME ) && GE_32( st_fx->core_brate, ACELP_13k20 ) ) || ( EQ_16( st_fx->L_frame, L_FRAME16k ) && GE_32( st_fx->core_brate, GSC_H_RATE_STG ) ) || st_fx->GSC_IVAS_mode == 0 ) ) ) && EQ_16( L_subfr_fx, L_SUBFR ) ) ) { use_fcb = 1; move16(); @@ -864,7 +864,7 @@ void dec_pit_exc_ivas_fx( move16(); pt_gain++; - lp_gain_updt_fx( i_subfr_fx, gain_pit_fx, 0, &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, st_fx->L_frame ); + lp_gain_updt_ivas_fx( i_subfr_fx, gain_pit_fx, 0, &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, st_fx->L_frame ); } } diff --git a/lib_dec/dec_tran_fx.c b/lib_dec/dec_tran_fx.c index 85497cc84..95c0fb1ce 100644 --- a/lib_dec/dec_tran_fx.c +++ b/lib_dec/dec_tran_fx.c @@ -160,15 +160,17 @@ void decod_tran_fx( } /* update LP filtered gains for the case of frame erasures */ - lp_gain_updt_fx( i_subfr, gain_pit_fx, L_add( norm_gain_code_fx, norm_gain_preQ_fx ), &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, L_frame_fx ); - - IF( EQ_16( st_fx->element_mode, EVS_MONO ) ) + IF( st_fx->element_mode == EVS_MONO ) { + lp_gain_updt_fx( i_subfr, gain_pit_fx, L_add( norm_gain_code_fx, norm_gain_preQ_fx ), &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, L_frame_fx ); + st_fx->tilt_code_fx = est_tilt_fx( exc_fx + i_subfr, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, st_fx->Q_exc ); move16(); } ELSE { + lp_gain_updt_ivas_fx( i_subfr, gain_pit_fx, L_add( norm_gain_code_fx, norm_gain_preQ_fx ), &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, L_frame_fx ); + st_fx->tilt_code_fx = est_tilt_ivas_fx( exc_fx + i_subfr, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, st_fx->Q_exc, L_SUBFR, 0 ); move16(); } diff --git a/lib_dec/dec_uv_fx.c b/lib_dec/dec_uv_fx.c index cbdb9407f..1b6c4b424 100644 --- a/lib_dec/dec_uv_fx.c +++ b/lib_dec/dec_uv_fx.c @@ -205,7 +205,7 @@ void decod_unvoiced_ivas_fx( /* update LP filtered gains for the case of frame erasures */ // lp_gain_updt(i_subfr, gain_pit, norm_gain_code, &st->lp_gainp, &st->lp_gainc, L_FRAME); - lp_gain_updt_fx( i_subfr_fx, gain_pit_fx, norm_gain_code_fx, &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, L_FRAME ); + lp_gain_updt_ivas_fx( i_subfr_fx, gain_pit_fx, norm_gain_code_fx, &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, L_FRAME ); /*-------------------------------------------------------* * - Find the total excitation. * diff --git a/lib_dec/gain_dec_fx.c b/lib_dec/gain_dec_fx.c index ff97e81cd..ae4a95966 100644 --- a/lib_dec/gain_dec_fx.c +++ b/lib_dec/gain_dec_fx.c @@ -1109,6 +1109,147 @@ void lp_gain_updt_fx( return; } +/*====================================================================== */ +/* FUNCTION : lp_gain_updt_ivas_fx() */ +/*-----------------------------------------------------------------------*/ +/* PURPOSE : Update of LP pitch and code gains (FEC) */ +/* */ +/*-----------------------------------------------------------------------*/ +/* INPUT ARGUMENTS : */ +/* _ (Word16) i_subfr : subframe number Q0 */ +/* _ (Word16) gain_pit : Decoded gain pitch Q14 */ +/* _ (Word32) norm_gain_code : Normalised gain code Q16 */ +/* _ (Word16) L_frame : length of the frame Q0 */ +/*-----------------------------------------------------------------------*/ +/* OUTPUT ARGUMENTS : */ +/* _ (Word16 *) T0 : close loop integer pitch */ +/* _ (Word16 *) T0_frac : close loop fractional part of the pitch */ +/* _ (Word16 ) pitch : pitch value Q6 */ +/*-----------------------------------------------------------------------*/ +/* INPUT OUTPUT ARGUMENTS */ +/* _ (Word16 *) lp_gainp : LP-filtered pitch gain(FEC) Q14 */ +/* _ (Word16 *) lp_gainc : LP-filtered code gain (FEC) Q3 */ +/*-----------------------------------------------------------------------*/ + +/*-----------------------------------------------------------------------*/ +/* RETURN ARGUMENTS : */ +/* _ None */ +/*=======================================================================*/ + + +void lp_gain_updt_ivas_fx( + const Word16 i_subfr, /* i : subframe number Q0 */ + const Word16 gain_pit, /* i : Decoded gain pitch Q14 */ + const Word32 norm_gain_code, /* i : Normalised gain code Q16 */ + Word16 *lp_gainp, /* i/o: LP-filtered pitch gain(FEC) Q14 */ + Word16 *lp_gainc, /* i/o: LP-filtered code gain (FEC) Q3 */ + const Word16 L_frame /* i : length of the frame */ +) +{ + Word16 tmp; + +#ifdef BASOP_NOGLOB + tmp = extract_h( L_shl_sat( norm_gain_code, 3 ) ); /*(16+3)-16 -> Q3*/ +#else + tmp = extract_h( L_shl( norm_gain_code, 3 ) ); /*(16+3)-16 -> Q3*/ +#endif + /* To handle extremely low values */ + test(); + if ( norm_gain_code != 0 && tmp == 0 ) + { + tmp = 1; + move16(); + } + + IF( EQ_16( L_frame, L_FRAME ) ) + { + IF( EQ_16( i_subfr, 0 ) ) + { + *lp_gainp = mult( 3277, gain_pit ); + move16(); /*0.1 in Q15 = 3277 , (15+14)-15 -> Q14*/ + *lp_gainc = mult_r( 3277, tmp ); + move16(); /* (15+3)-15 -> Q3*/ + } + ELSE IF( EQ_16( i_subfr, L_SUBFR ) ) + { + *lp_gainp = add( *lp_gainp, mult( 6554, gain_pit ) ); + move16(); /*Q14 (0.2 in Q15 = 6554)*/ + *lp_gainc = mac_r( L_deposit_h( *lp_gainc ), 6554, tmp ); + move16(); /*Q3*/ + } + ELSE IF( EQ_16( i_subfr, 2 * L_SUBFR ) ) + { + *lp_gainp = add( *lp_gainp, mult( 9830, gain_pit ) ); + move16(); /*Q14 (0.3 in Q15 = 9830)*/ + *lp_gainc = mac_r( L_deposit_h( *lp_gainc ), 9830, tmp ); + move16(); /*Q3*/ + } + ELSE /* i_subfr == 3*L_SUBFR */ + { + *lp_gainp = add( *lp_gainp, mult( 13107, gain_pit ) ); + move16(); /*Q14 (0.4 in Q15 = 13107)*/ +#ifdef BASOP_NOGLOB + *lp_gainc = mac_r_sat( L_deposit_h( *lp_gainc ), 13107, tmp ); +#else + *lp_gainc = mac_r( L_deposit_h( *lp_gainc ), 13107, tmp ); +#endif + move16(); /*Q3*/ + } + } + ELSE + { + IF( i_subfr == 0 ) + { + *lp_gainp = mult( 2185, gain_pit ); + move16(); /*(1.0/15.0) in Q15 = 2185 , (15+14)-15 -> Q14*/ + *lp_gainc = mult_r( 2185, tmp ); + move16(); /* (15+3)-15 -> Q3*/ + } + ELSE IF( EQ_16( i_subfr, L_SUBFR ) ) + { + *lp_gainp = add( *lp_gainp, mult( 4369, gain_pit ) ); + move16(); /*Q14 (2.0/15.0 in Q15 = 4369)*/ + *lp_gainc = mac_r( L_deposit_h( *lp_gainc ), 4369, tmp ); + move16(); /*Q3*/ + } + ELSE IF( EQ_16( i_subfr, 2 * L_SUBFR ) ) + { + *lp_gainp = add( *lp_gainp, mult( 6554, gain_pit ) ); + move16(); /*Q14 (3.0/15.0 in Q15 = 6554)*/ + *lp_gainc = mac_r( L_deposit_h( *lp_gainc ), 6554, tmp ); + move16(); /*Q3*/ + } + ELSE IF( EQ_16( i_subfr, 3 * L_SUBFR ) ) + { + *lp_gainp = add( *lp_gainp, mult( 8738, gain_pit ) ); + move16(); /*Q14 (4.0/15.0 in Q15 = 8738)*/ + *lp_gainc = mac_r( L_deposit_h( *lp_gainc ), 8738, tmp ); + move16(); /*Q3*/ + } + ELSE /* i_subfr == 4*L_SUBFR */ + { + *lp_gainp = add( *lp_gainp, mult( 10923, gain_pit ) ); + move16(); /*Q14 (5.0/15.0 in Q15 = 10923)*/ +#ifdef BASOP_NOGLOB + *lp_gainc = mac_r_sat( L_deposit_h( *lp_gainc ), 10923, tmp ); +#else + *lp_gainc = mac_r( L_deposit_h( *lp_gainc ), 10923, tmp ); +#endif + move16(); /*Q3*/ + } + } + + /* To handle extremely low values */ + test(); + if ( tmp != 0 && *lp_gainc == 0 ) + { + *lp_gainc = 1; + move16(); + } + + return; +} + /*-------------------------------------------------* * Gain_dec_gaus_vbr * diff --git a/lib_dec/gaus_dec_fx.c b/lib_dec/gaus_dec_fx.c index dc999e3f0..516dfc498 100644 --- a/lib_dec/gaus_dec_fx.c +++ b/lib_dec/gaus_dec_fx.c @@ -87,7 +87,14 @@ void gaus_dec_fx( move32(); /* update LP filtered gains for the case of frame erasures */ - lp_gain_updt_fx( i_subfr, 0, *L_norm_gain_code, lp_gainp, lp_gainc, L_FRAME ); /* supposes that gain_dec_gaus() is used for ACELP@12k8 only */ + IF( st_fx->element_mode == EVS_MONO ) + { + lp_gain_updt_fx( i_subfr, 0, *L_norm_gain_code, lp_gainp, lp_gainc, L_FRAME ); /* supposes that gain_dec_gaus() is used for ACELP@12k8 only */ + } + ELSE + { + lp_gain_updt_ivas_fx( i_subfr, 0, *L_norm_gain_code, lp_gainp, lp_gainc, L_FRAME ); /* supposes that gain_dec_gaus() is used for ACELP@12k8 only */ + } /*------------------------------------------------------------------------------------------* * Updates diff --git a/lib_dec/ivas_td_low_rate_dec.c b/lib_dec/ivas_td_low_rate_dec.c index feae9373c..bdaa26ebc 100644 --- a/lib_dec/ivas_td_low_rate_dec.c +++ b/lib_dec/ivas_td_low_rate_dec.c @@ -639,8 +639,8 @@ void decod_gen_2sbfr_ivas_fx( /* update LP filtered gains for the case of frame erasures */ // lp_gain_updt(i_subfr, gain_pit, norm_gain_code, &st->lp_gainp, &st->lp_gainc, L_frame); // lp_gain_updt(i_subfr + L_SUBFR, gain_pit, norm_gain_code, &st->lp_gainp, &st->lp_gainc, L_frame); - lp_gain_updt_fx( i_subfr, gain_pit, norm_gain_code, &st->lp_gainp_fx, &st->lp_gainc_fx, L_frame ); - lp_gain_updt_fx( i_subfr + L_SUBFR, gain_pit, norm_gain_code, &st->lp_gainp_fx, &st->lp_gainc_fx, L_frame ); + lp_gain_updt_ivas_fx( i_subfr, gain_pit, norm_gain_code, &st->lp_gainp_fx, &st->lp_gainc_fx, L_frame ); + lp_gain_updt_ivas_fx( i_subfr + L_SUBFR, gain_pit, norm_gain_code, &st->lp_gainp_fx, &st->lp_gainc_fx, L_frame ); /*----------------------------------------------------------------------* * Find the total excitation -- GitLab From 6e7a2aae2cd783fe949fda2a814eb0ff8f83b4f8 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Tue, 16 Jul 2024 21:48:21 +0530 Subject: [PATCH 2/2] Clang formatting --- lib_dec/dec_pit_exc_fx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_dec/dec_pit_exc_fx.c b/lib_dec/dec_pit_exc_fx.c index 6b56f264a..0197fe36d 100644 --- a/lib_dec/dec_pit_exc_fx.c +++ b/lib_dec/dec_pit_exc_fx.c @@ -150,7 +150,7 @@ void dec_pit_exc_fx( test(); test(); test(); - IF ( ( ( GE_32( st_fx->core_brate, MIN_RATE_FCB ) || ( EQ_16( st_fx->GSC_noisy_speech, 1 ) && ( ( EQ_16( st_fx->L_frame, L_FRAME ) && GE_32( st_fx->core_brate, ACELP_13k20 ) ) || ( EQ_16( st_fx->L_frame, L_FRAME16k ) && GE_32( st_fx->core_brate, GSC_H_RATE_STG ) ) || st_fx->GSC_IVAS_mode == 0 ) ) ) && EQ_16( L_subfr_fx, L_SUBFR ) ) ) + IF( ( ( GE_32( st_fx->core_brate, MIN_RATE_FCB ) || ( EQ_16( st_fx->GSC_noisy_speech, 1 ) && ( ( EQ_16( st_fx->L_frame, L_FRAME ) && GE_32( st_fx->core_brate, ACELP_13k20 ) ) || ( EQ_16( st_fx->L_frame, L_FRAME16k ) && GE_32( st_fx->core_brate, GSC_H_RATE_STG ) ) || st_fx->GSC_IVAS_mode == 0 ) ) ) && EQ_16( L_subfr_fx, L_SUBFR ) ) ) { use_fcb = 1; move16(); -- GitLab