From 49b57e88e184a4b9ea2719990c770c271c666446 Mon Sep 17 00:00:00 2001 From: vaclav Date: Wed, 1 Apr 2026 17:25:42 +0200 Subject: [PATCH 1/4] FIX_1563_FIX_STEREO_SW --- lib_com/ivas_prot_fx.h | 2 +- lib_com/options.h | 1 + lib_dec/ivas_cpe_dec_fx.c | 2 +- lib_dec/ivas_stereo_switching_dec_fx.c | 33 +++++++++++++------------- 4 files changed, 20 insertions(+), 18 deletions(-) diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index f9dd86e4c..cd2d69903 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -6116,7 +6116,7 @@ void mvc2c( const Word16 n /* i : vector size */ ); -void stereo_switching_dec( +void stereo_switching_dec_fx( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ const Word32 ivas_total_brate /* i : IVAS total bitrate Q0*/ ); diff --git a/lib_com/options.h b/lib_com/options.h index 7976d55ed..e85cb34a0 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -103,6 +103,7 @@ #define FIX_1547_ISMDTX_HANDLE /* VA: float issue 1547: fix use of 'hISMDTX' handle */ #define FIX_1540_EXPOSE_PT_IN_RTP_HEADER_API /* Expose Payload Type setting in RTP Header */ #define FIX_BASOP_2491_MDCT_JBM_CLICK /* FhG: BASOP #2491: Fix Q_synth after TCX concealment (using ACELP concealment) */ +#define FIX_1563_FIX_STEREO_SW /* VA: float issue 1563: fix clicks in stereo switching */ /* ##################### End NON-BE switches ########################### */ diff --git a/lib_dec/ivas_cpe_dec_fx.c b/lib_dec/ivas_cpe_dec_fx.c index 28133aaa9..9db1333c4 100644 --- a/lib_dec/ivas_cpe_dec_fx.c +++ b/lib_dec/ivas_cpe_dec_fx.c @@ -202,7 +202,7 @@ ivas_error ivas_cpe_dec_fx( * Resets/updates in case of stereo switching *----------------------------------------------------------------*/ - stereo_switching_dec( hCPE, ivas_total_brate ); + stereo_switching_dec_fx( hCPE, ivas_total_brate ); /*----------------------------------------------------------------* * Configuration of stereo decoder diff --git a/lib_dec/ivas_stereo_switching_dec_fx.c b/lib_dec/ivas_stereo_switching_dec_fx.c index 63e9e792e..45504b8d9 100644 --- a/lib_dec/ivas_stereo_switching_dec_fx.c +++ b/lib_dec/ivas_stereo_switching_dec_fx.c @@ -46,6 +46,15 @@ #define DFT2TD_CORR_THRESH_FX 1932735283 +static Word32 side_gain_table[32 + 1] = { + -ONE_IN_Q31, -2040109440, -1932735232, -1825361152, -1717986944, + -1610612736, -1503238528, -1395864320, -1288490240, -1181115904, -1073741824, + -966367616, -858993408, -751619200, -644245120, -536870912, -429496704, + -322122496, -214748288, -107374208, 0, 107374336, 214748416, + 322122496, 429496832, 536870912, 644245248, 751619328, 858993408, + 966367744, 1073741824, 1181116160, 1288490240 +}; + /*-------------------------------------------------------------------* * Function allocate_CoreCoder_TCX() @@ -1689,16 +1698,7 @@ void synchro_synthesis_fx( * Handling of memories in case of CPE modes switching *-------------------------------------------------------------------*/ -static Word32 side_gain_table[32 + 1] = { - -ONE_IN_Q31, -2040109440, -1932735232, -1825361152, -1717986944, - -1610612736, -1503238528, -1395864320, -1288490240, -1181115904, -1073741824, - -966367616, -858993408, -751619200, -644245120, -536870912, -429496704, - -322122496, -214748288, -107374208, 0, 107374336, 214748416, - 322122496, 429496832, 536870912, 644245248, 751619328, 858993408, - 966367744, 1073741824, 1181116160, 1288490240 -}; - -void stereo_switching_dec( +void stereo_switching_dec_fx( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ const Word32 ivas_total_brate /* i : IVAS total bitrate Q0*/ ) @@ -1891,13 +1891,11 @@ void stereo_switching_dec( sts[0]->mem_deemph_fx = 0; move16(); - sts[0]->tilt_code_fx = 0; move16(); sts[0]->gc_threshold_fx = 0; move16(); - set16_fx( sts[0]->mem_syn1_fx, 0, M ); set16_fx( sts[0]->mem_syn2_fx, 0, M ); set16_fx( sts[0]->mem_syn3_fx, 0, M ); @@ -1906,7 +1904,6 @@ void stereo_switching_dec( sts[1]->last_L_frame = sts[0]->last_L_frame; /* Q0 */ move16(); - set16_fx( sts[0]->old_exc_fx, 0, L_EXC_MEM_DEC ); set16_fx( sts[0]->lsf_old_fx, 0, M ); set16_fx( sts[0]->lsp_old_fx, 0, M ); @@ -1917,14 +1914,12 @@ void stereo_switching_dec( sts[1]->prev_bfi = sts[0]->prev_bfi; /* Q0 */ move16(); - // fix need to do correctly set32_fx( sts[1]->old_pitch_buf_fx, L_deposit_h( L_SUBFR ), 2 * NB_SUBFR16k ); sts[1]->old_fpitchFB = L_deposit_h( 2 * L_SUBFR ); /* 15Q16 */ move32(); /* reset CLDFB memories */ - cldfb_reset_memory_fx( sts[1]->cldfbAna ); cldfb_reset_memory_fx( sts[1]->cldfbBPF ); cldfb_reset_memory_fx( sts[1]->cldfbSyn ); @@ -1937,7 +1932,6 @@ void stereo_switching_dec( sts[1]->gc_threshold_fx = 0; move16(); - set16_fx( sts[1]->mem_syn1_fx, 0, M ); set16_fx( sts[1]->mem_syn2_fx, 0, M ); set16_fx( sts[1]->mem_syn3_fx, 0, M ); @@ -2015,6 +2009,13 @@ void stereo_switching_dec( Copy( sts[0]->hTcxDec->old_syn_Overl, sts[1]->hTcxDec->old_syn_Overl, 256 ); /* Q_old_syn_Overl*/ sts[1]->hTcxDec->Q_old_syn_Overl = sts[0]->hTcxDec->Q_old_syn_Overl; } +#ifdef FIX_1563_FIX_STEREO_SW + ELSE IF ( hCPE->element_mode == IVAS_CPE_TD ) + { + sts[1]->last_core = ACELP_CORE; + move16(); + } +#endif } ELSE IF( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) && EQ_16( hCPE->last_element_mode, IVAS_CPE_MDCT ) ) { -- GitLab From d0ff8768b0a58c61493c980624ac4cf91c9411d6 Mon Sep 17 00:00:00 2001 From: vaclav Date: Wed, 1 Apr 2026 17:27:36 +0200 Subject: [PATCH 2/4] clang-format --- lib_dec/ivas_stereo_switching_dec_fx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_dec/ivas_stereo_switching_dec_fx.c b/lib_dec/ivas_stereo_switching_dec_fx.c index 45504b8d9..336bd75f4 100644 --- a/lib_dec/ivas_stereo_switching_dec_fx.c +++ b/lib_dec/ivas_stereo_switching_dec_fx.c @@ -2010,7 +2010,7 @@ void stereo_switching_dec_fx( sts[1]->hTcxDec->Q_old_syn_Overl = sts[0]->hTcxDec->Q_old_syn_Overl; } #ifdef FIX_1563_FIX_STEREO_SW - ELSE IF ( hCPE->element_mode == IVAS_CPE_TD ) + ELSE IF( hCPE->element_mode == IVAS_CPE_TD ) { sts[1]->last_core = ACELP_CORE; move16(); -- GitLab From c5040f950ffab219939662b3c3a01db29af5de76 Mon Sep 17 00:00:00 2001 From: vaclav Date: Thu, 2 Apr 2026 10:03:19 +0200 Subject: [PATCH 3/4] FIX_1563_FIX_STEREO_SW to encoder --- lib_dec/ivas_stereo_switching_dec_fx.c | 2 +- lib_enc/ivas_stereo_switching_enc_fx.c | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/lib_dec/ivas_stereo_switching_dec_fx.c b/lib_dec/ivas_stereo_switching_dec_fx.c index 336bd75f4..77b98ff96 100644 --- a/lib_dec/ivas_stereo_switching_dec_fx.c +++ b/lib_dec/ivas_stereo_switching_dec_fx.c @@ -2010,7 +2010,7 @@ void stereo_switching_dec_fx( sts[1]->hTcxDec->Q_old_syn_Overl = sts[0]->hTcxDec->Q_old_syn_Overl; } #ifdef FIX_1563_FIX_STEREO_SW - ELSE IF( hCPE->element_mode == IVAS_CPE_TD ) + ELSE IF( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) ) { sts[1]->last_core = ACELP_CORE; move16(); diff --git a/lib_enc/ivas_stereo_switching_enc_fx.c b/lib_enc/ivas_stereo_switching_enc_fx.c index 211033756..96aedabaf 100644 --- a/lib_enc/ivas_stereo_switching_enc_fx.c +++ b/lib_enc/ivas_stereo_switching_enc_fx.c @@ -515,15 +515,17 @@ ivas_error stereo_memory_enc_fx( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hTcxEnc\n" ) ); } - // st->hTcxEnc->spectrum[0] = st->hTcxEnc->spectrum_long; - // st->hTcxEnc->spectrum[1] = st->hTcxEnc->spectrum_long + N_TCX10_MAX; st->hTcxEnc->spectrum_fx[0] = st->hTcxEnc->spectrum_long_fx; /* Q31-st->hTcxEnc->spectrum_e[0] */ st->hTcxEnc->spectrum_fx[1] = st->hTcxEnc->spectrum_long_fx + N_TCX10_MAX; /* Q31-st->hTcxEnc->spectrum_e[1] */ st->hTcxEnc->spectrum_e[0] = st->hTcxEnc->spectrum_e[1] = 0; move16(); move16(); +#ifdef FIX_1563_FIX_STEREO_SW + set_f( st->hTcxEnc->old_out_fx, 0, L_FRAME32k ); +#else // set_f( st->hTcxEnc->old_out, 0, L_FRAME32k ); // set_f( st->hTcxEnc->spectrum_long, 0, N_MAX ); +#endif set32_fx( st->hTcxEnc->spectrum_long_fx, 0, N_MAX ); st->hTcxEnc->spectrum_long_e = 0; st->hTcxEnc->tfm_mem_fx = 1610612736; /* 0.75 in Q31 */ @@ -557,7 +559,6 @@ ivas_error stereo_memory_enc_fx( #ifdef DEBUGGING hCPE->hStereoMdct->mdct_stereo_mode_cmdl = SMDCT_MS_DECISION; #endif - initMdctStereoEncData_fx( hCPE->hStereoMdct, ivas_format, hCPE->element_mode, hCPE->element_brate, hCPE->hCoreCoder[0]->max_bwidth, 0, NULL, 1 ); test(); @@ -630,6 +631,7 @@ ivas_error stereo_memory_enc_fx( return error; } + /*-------------------------------------------------------------------* * Function stereo_switching_enc() * @@ -673,7 +675,6 @@ void stereo_switching_enc_fx( Copy32( sts[1]->input32_fx + sub( extract_l( Mpy_32_32( sts[1]->input_Fs, 42949673 /* 1/50 in Q31*/ ) ), sts[1]->encoderLookahead_FB ), sts[1]->input32_fx - sts[1]->encoderLookahead_FB, sts[1]->encoderLookahead_FB ); /* sts[1]->q_inp32 */ } - /* TD/MDCT -> DFT stereo switching */ test(); IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) && NE_16( hCPE->last_element_mode, IVAS_CPE_DFT ) ) @@ -937,6 +938,13 @@ void stereo_switching_enc_fx( sts[1]->last_bwidth = sts[0]->last_bwidth; /* Q0 */ move16(); } +#ifdef FIX_1563_FIX_STEREO_SW + ELSE IF( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) ) + { + sts[1]->last_core = ACELP_CORE; + move16(); + } +#endif } ELSE IF( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) && EQ_16( hCPE->last_element_mode, IVAS_CPE_MDCT ) ) { -- GitLab From 17fdab7c17e3021db88f285a5ffc79e846633ab2 Mon Sep 17 00:00:00 2001 From: vaclav Date: Thu, 2 Apr 2026 10:18:49 +0200 Subject: [PATCH 4/4] fix build --- lib_enc/ivas_stereo_switching_enc_fx.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib_enc/ivas_stereo_switching_enc_fx.c b/lib_enc/ivas_stereo_switching_enc_fx.c index 96aedabaf..4706422dc 100644 --- a/lib_enc/ivas_stereo_switching_enc_fx.c +++ b/lib_enc/ivas_stereo_switching_enc_fx.c @@ -521,7 +521,9 @@ ivas_error stereo_memory_enc_fx( move16(); move16(); #ifdef FIX_1563_FIX_STEREO_SW - set_f( st->hTcxEnc->old_out_fx, 0, L_FRAME32k ); + set16_fx( st->hTcxEnc->old_out_fx, 0, L_FRAME32k ); + st->hTcxEnc->Q_old_out = 0; + move16(); #else // set_f( st->hTcxEnc->old_out, 0, L_FRAME32k ); // set_f( st->hTcxEnc->spectrum_long, 0, N_MAX ); -- GitLab