From 5b650bb017712e3f0ea12379f26d3704182806e7 Mon Sep 17 00:00:00 2001 From: Eleni Fotopoulou Date: Fri, 25 Nov 2022 14:40:38 +0100 Subject: [PATCH 1/4] [fix] for issue 221, uninitialized tcx config values when switching from TD to MDCT stereo --- lib_com/options.h | 3 ++- lib_dec/ivas_stereo_switching_dec.c | 14 +++++++++++++- lib_enc/ivas_stereo_switching_enc.c | 9 +++++++-- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index edc0d9ae06..cdf098506c 100755 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -41,7 +41,7 @@ /* ################### Start compiler switches ######################## */ #define SUPPORT_JBM_TRACEFILE /* support for JBM tracefile, which is needed for 3GPP objective/subjective testing, but not relevant for real-world implementations */ -#define RAM_COUNTING_TOOL /* tool to automatically count the dynamically alocated static memory consumption */ +//#define RAM_COUNTING_TOOL /* tool to automatically count the dynamically alocated static memory consumption */ /* #################### End compiler switches ######################### */ @@ -164,6 +164,7 @@ #define BRATE_SWITCHING_FRAMEWORK /* Bitrate switching changes related to the general framework */ #define BRATE_SWITCHING_RENDERING /* Bitrate switching changes related to the renderers */ #define FIX_185_REDUCE_MD_BITS /* Issue 185: Crash in SBA encoder for 24.4 kbps HOA3 input with longer testvector */ +#define FIX_221_BR_SWITCH_STEREO /* Issue 221: Fix missing initialization when switchin from TD to MDCT stereo*/ /* ################## End DEVELOPMENT switches ######################### */ /* clang-format on */ diff --git a/lib_dec/ivas_stereo_switching_dec.c b/lib_dec/ivas_stereo_switching_dec.c index 355eed3906..cab870415f 100644 --- a/lib_dec/ivas_stereo_switching_dec.c +++ b/lib_dec/ivas_stereo_switching_dec.c @@ -1467,7 +1467,6 @@ void stereo_switching_dec( mvr2r( sts[0]->old_exc, sts[1]->old_exc, L_EXC_MEM_DEC ); mvr2r( sts[0]->lsf_old, sts[1]->lsf_old, M ); mvr2r( sts[0]->lsp_old, sts[1]->lsp_old, M ); - if ( hCPE->element_mode == IVAS_CPE_MDCT ) { sts[1]->last_core = sts[0]->last_core; @@ -1493,6 +1492,19 @@ void stereo_switching_dec( set_f( sts[0]->old_exc, 0.0f, L_EXC_MEM_DEC ); set_f( sts[1]->old_exc, 0.0f, L_EXC_MEM_DEC ); } +#ifdef FIX_221_BR_SWITCH_STEREO + else if ( hCPE->element_mode == IVAS_CPE_MDCT && hCPE->last_element_mode == IVAS_CPE_TD ) + { + sts[1]->hTcxCfg->last_aldo = sts[0]->hTcxCfg->last_aldo; + sts[1]->hTcxCfg->tcx_curr_overlap_mode = sts[0]->hTcxCfg->tcx_curr_overlap_mode; + sts[1]->fscale = sts[0]->fscale; + sts[1]->hTcxCfg->tcx_mdct_window_length = sts[0]->hTcxCfg->tcx_mdct_window_length; + sts[1]->pit_res_max = sts[0]->pit_res_max; + sts[1]->pit_res_max_past = sts[0]->pit_res_max_past; + sts[1]->hTcxDec->L_frameTCX = sts[0]->hTcxDec->L_frameTCX; + sts[1]->hTcxDec->conceal_eof_gain = sts[0]->hTcxDec->conceal_eof_gain; + } +#endif return; } diff --git a/lib_enc/ivas_stereo_switching_enc.c b/lib_enc/ivas_stereo_switching_enc.c index d0201784a6..535d73e7ba 100644 --- a/lib_enc/ivas_stereo_switching_enc.c +++ b/lib_enc/ivas_stereo_switching_enc.c @@ -803,7 +803,6 @@ void stereo_switching_enc( mvr2r( sts[0]->lsp_old1, sts[1]->lsp_old1, M ); sts[1]->GSC_noisy_speech = 0; - if ( hCPE->element_mode == IVAS_CPE_MDCT ) { /* cross-fade overlap region of DFT Stereo downmix and original stereo channels */ @@ -828,6 +827,12 @@ void stereo_switching_enc( set_f( sts[0]->hLPDmem->old_exc, 0.0f, L_EXC_MEM ); set_f( sts[1]->hLPDmem->old_exc, 0.0f, L_EXC_MEM ); } - +#ifdef FIX_221_BR_SWITCH_STEREO + else if ( hCPE->element_mode == IVAS_CPE_MDCT && hCPE->last_element_mode == IVAS_CPE_TD ) + { + sts[1]->hTcxCfg->last_aldo = sts[0]->hTcxCfg->last_aldo; + sts[1]->hTcxCfg->tcx_curr_overlap_mode = sts[0]->hTcxCfg->tcx_curr_overlap_mode; + } +#endif return; } -- GitLab From bead3686768364150530556f43dc6f799cf45058 Mon Sep 17 00:00:00 2001 From: vaclav Date: Fri, 25 Nov 2022 15:41:34 +0100 Subject: [PATCH 2/4] merge two same code blocks into one --- lib_dec/ivas_stereo_switching_dec.c | 8 +++++++- lib_enc/ivas_stereo_switching_enc.c | 7 ++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib_dec/ivas_stereo_switching_dec.c b/lib_dec/ivas_stereo_switching_dec.c index cab870415f..87a12fa3b8 100644 --- a/lib_dec/ivas_stereo_switching_dec.c +++ b/lib_dec/ivas_stereo_switching_dec.c @@ -1471,20 +1471,24 @@ void stereo_switching_dec( { sts[1]->last_core = sts[0]->last_core; sts[1]->last_coder_type = sts[0]->last_coder_type; +#ifndef FIX_221_BR_SWITCH_STEREO sts[1]->hTcxCfg->last_aldo = sts[0]->hTcxCfg->last_aldo; sts[1]->hTcxCfg->tcx_curr_overlap_mode = sts[0]->hTcxCfg->tcx_curr_overlap_mode; +#endif mvr2r( sts[0]->hHQ_core->old_out, sts[1]->hHQ_core->old_out, L_FRAME48k ); mvr2r( sts[0]->delay_buf_out, sts[1]->delay_buf_out, HQ_DELTA_MAX * HQ_DELAY_COMP ); mvr2r( sts[0]->hTcxDec->old_syn_Overl, sts[1]->hTcxDec->old_syn_Overl, 256 ); /* Todo: apply panning to buffers instead of simply using dmx in left and right channel */ +#ifndef FIX_221_BR_SWITCH_STEREO sts[1]->fscale = sts[0]->fscale; sts[1]->hTcxCfg->tcx_mdct_window_length = sts[0]->hTcxCfg->tcx_mdct_window_length; sts[1]->pit_res_max = sts[0]->pit_res_max; sts[1]->pit_res_max_past = sts[0]->pit_res_max_past; sts[1]->hTcxDec->L_frameTCX = sts[0]->hTcxDec->L_frameTCX; sts[1]->hTcxDec->conceal_eof_gain = sts[0]->hTcxDec->conceal_eof_gain; +#endif } } else if ( hCPE->element_mode == IVAS_CPE_TD && hCPE->last_element_mode == IVAS_CPE_MDCT ) @@ -1492,8 +1496,10 @@ void stereo_switching_dec( set_f( sts[0]->old_exc, 0.0f, L_EXC_MEM_DEC ); set_f( sts[1]->old_exc, 0.0f, L_EXC_MEM_DEC ); } + #ifdef FIX_221_BR_SWITCH_STEREO - else if ( hCPE->element_mode == IVAS_CPE_MDCT && hCPE->last_element_mode == IVAS_CPE_TD ) + /* TD/DFT -> MDCT stereo switching (there is no TCX in the TD stereo secondary channel, or DFT stereo) */ + if ( hCPE->element_mode == IVAS_CPE_MDCT && hCPE->last_element_mode != IVAS_CPE_MDCT ) { sts[1]->hTcxCfg->last_aldo = sts[0]->hTcxCfg->last_aldo; sts[1]->hTcxCfg->tcx_curr_overlap_mode = sts[0]->hTcxCfg->tcx_curr_overlap_mode; diff --git a/lib_enc/ivas_stereo_switching_enc.c b/lib_enc/ivas_stereo_switching_enc.c index 535d73e7ba..2f5c06b6c9 100644 --- a/lib_enc/ivas_stereo_switching_enc.c +++ b/lib_enc/ivas_stereo_switching_enc.c @@ -818,8 +818,10 @@ void stereo_switching_enc( sts[1]->last_core = sts[0]->last_core; sts[1]->last_coder_type = sts[0]->last_coder_type; sts[1]->last_bwidth = sts[0]->last_bwidth; +#ifndef FIX_221_BR_SWITCH_STEREO sts[1]->hTcxCfg->last_aldo = sts[0]->hTcxCfg->last_aldo; sts[1]->hTcxCfg->tcx_curr_overlap_mode = sts[0]->hTcxCfg->tcx_curr_overlap_mode; +#endif } } else if ( hCPE->element_mode == IVAS_CPE_TD && hCPE->last_element_mode == IVAS_CPE_MDCT ) @@ -827,12 +829,15 @@ void stereo_switching_enc( set_f( sts[0]->hLPDmem->old_exc, 0.0f, L_EXC_MEM ); set_f( sts[1]->hLPDmem->old_exc, 0.0f, L_EXC_MEM ); } + #ifdef FIX_221_BR_SWITCH_STEREO - else if ( hCPE->element_mode == IVAS_CPE_MDCT && hCPE->last_element_mode == IVAS_CPE_TD ) + /* TD/DFT -> MDCT stereo switching (there is no TCX in the TD stereo secondary channel, or DFT stereo) */ + if ( hCPE->element_mode == IVAS_CPE_MDCT && hCPE->last_element_mode != IVAS_CPE_MDCT ) { sts[1]->hTcxCfg->last_aldo = sts[0]->hTcxCfg->last_aldo; sts[1]->hTcxCfg->tcx_curr_overlap_mode = sts[0]->hTcxCfg->tcx_curr_overlap_mode; } #endif + return; } -- GitLab From 46c9a56ad07103b69d734c006a01949ca55c7e6f Mon Sep 17 00:00:00 2001 From: vaclav Date: Fri, 25 Nov 2022 15:42:39 +0100 Subject: [PATCH 3/4] clean out a commented code --- lib_dec/ivas_stereo_switching_dec.c | 2 -- lib_enc/ivas_stereo_switching_enc.c | 5 +---- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/lib_dec/ivas_stereo_switching_dec.c b/lib_dec/ivas_stereo_switching_dec.c index 87a12fa3b8..83eb0c23e4 100644 --- a/lib_dec/ivas_stereo_switching_dec.c +++ b/lib_dec/ivas_stereo_switching_dec.c @@ -1424,7 +1424,6 @@ void stereo_switching_dec( sts[0]->tilt_code = 0.0f; sts[0]->gc_threshold = 0.0f; - /*init_gp_clip( sts[1]->clip_var );*/ set_f( sts[0]->mem_syn1, 0, M ); set_f( sts[0]->mem_syn2, 0, M ); @@ -1454,7 +1453,6 @@ void stereo_switching_dec( sts[1]->tilt_code = 0.0f; sts[1]->gc_threshold = 0.0f; - /*init_gp_clip( sts[1]->clip_var );*/ set_f( sts[1]->mem_syn1, 0, M ); set_f( sts[1]->mem_syn2, 0, M ); diff --git a/lib_enc/ivas_stereo_switching_enc.c b/lib_enc/ivas_stereo_switching_enc.c index 2f5c06b6c9..66f7c8fcd9 100644 --- a/lib_enc/ivas_stereo_switching_enc.c +++ b/lib_enc/ivas_stereo_switching_enc.c @@ -758,11 +758,8 @@ void stereo_switching_enc( /* no secondary channel in the previous frame -> memory resets */ set_zero( sts[1]->old_inp_12k8, L_INP_MEM ); - /*set_zero( sts[1]->old_inp_16k, L_INP_MEM );*/ set_zero( sts[1]->mem_decim, 2 * L_FILT_MAX ); - /*set_zero( sts[1]->mem_decim16k, 2*L_FILT_MAX );*/ sts[1]->mem_preemph = 0; - /*sts[1]->mem_preemph16k = 0;*/ set_zero( sts[1]->buf_speech_enc, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); set_zero( sts[1]->buf_speech_enc_pe, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); @@ -812,7 +809,7 @@ void stereo_switching_enc( sts[1]->input[-sts[0]->encoderLookahead_FB + i] = ( ( sts[0]->encoderLookahead_FB - i ) * sts[0]->input[-sts[0]->encoderLookahead_FB + i] + i * sts[1]->input[-sts[0]->encoderLookahead_FB + i] ) * tmpF; sts[0]->input[-sts[0]->encoderLookahead_FB + i] = ( ( sts[0]->encoderLookahead_FB - i ) * sts[0]->input[-sts[0]->encoderLookahead_FB + i] + i * sts[1]->input[-2 * sts[0]->encoderLookahead_FB + i] ) * tmpF; } - /* restore continous signal in right channel (part of old_output was used to store original left channel) */ + /* restore continuous signal in right channel (part of old_output was used to store original left channel) */ mvr2r( sts[0]->input - sts[0]->hTcxEnc->L_frameTCX, sts[1]->input - sts[0]->hTcxEnc->L_frameTCX, sts[0]->hTcxEnc->L_frameTCX - sts[0]->encoderLookahead_FB ); sts[1]->last_core = sts[0]->last_core; -- GitLab From 674caa7d0e562c0f7f94d0fdfed0c61427474988 Mon Sep 17 00:00:00 2001 From: Eleni Fotopoulou Date: Fri, 25 Nov 2022 15:53:52 +0100 Subject: [PATCH 4/4] re-enable RAM_COUNTING_TOOL --- lib_com/options.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_com/options.h b/lib_com/options.h index 189f489480..6c7e089ec9 100755 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -41,7 +41,7 @@ /* ################### Start compiler switches ######################## */ #define SUPPORT_JBM_TRACEFILE /* support for JBM tracefile, which is needed for 3GPP objective/subjective testing, but not relevant for real-world implementations */ -//#define RAM_COUNTING_TOOL /* tool to automatically count the dynamically alocated static memory consumption */ +#define RAM_COUNTING_TOOL /* tool to automatically count the dynamically alocated static memory consumption */ /* #################### End compiler switches ######################### */ -- GitLab