From 8b6bd6f85d49f254f3d648a84661097e19c07634 Mon Sep 17 00:00:00 2001 From: vaclav Date: Fri, 9 Jan 2026 17:52:22 +0100 Subject: [PATCH 01/18] HARM_CORE_SW, decoder step 1 --- lib_com/options.h | 2 + lib_com/prot_fx.h | 34 +- lib_dec/amr_wb_dec_fx.c | 4 + lib_dec/core_switching_dec_fx.c | 588 +++++++++++++++++++++++--------- lib_dec/evs_dec_fx.c | 8 + lib_dec/ivas_core_dec_fx.c | 24 ++ 6 files changed, 495 insertions(+), 165 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index a24403788..9518e3168 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -117,6 +117,8 @@ #define CLEANUP_ACELP_ENC /* VA: basop issue 2304: Remove duplicated code in excitation encoding in the ACELP core */ #define CLEANUP_VBR_CAM_ENC /* VA: basop issue 2299: Remove unused core-encoder VBR and CAM code */ +#define HARM_CORE_SW + /* #################### End BE switches ################################## */ /* #################### Start NON-BE switches ############################ */ diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index abb050c02..41d1ad5ae 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -7794,19 +7794,41 @@ void hq_configure_bfi_fx( void bandwidth_switching_detect_fx( Decoder_State *st_fx /* i/o: encoder state structure */ ); +#ifndef HARM_CORE_SW void bandwidth_switching_detect_ivas_fx( Decoder_State *st_fx /* i/o: encoder state structure */ ); - +#endif void bw_switching_pre_proc_fx( +#ifdef HARM_CORE_SW + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word32 last_element_brate, /* i : last element bitrate */ + const Word16 nchan_out, /* i : number of output channels */ + Word16 *old_syn_12k8_16k_fx16, + Word32 *old_syn_12k8_16k_fx32, + Word16 Q +#else const Word16 *old_syn_12k8_16k_fx, /* i : ACELP core synthesis at 12.8kHz or 16kHz Qx*/ Decoder_State *st_fx /* i/o: decoder state structure */ +#endif ); ivas_error core_switching_pre_dec_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 output_frame /* i : frame length Q0*/ +#ifdef HARM_CORE_SWaa + Decoder_State *st, /* i/o: decoder state structure */ + const Word16 output_frame, /* i : frame length */ + const Word32 last_core_brate_st0, /* i : channel 0 last core bitrate */ + const Word16 nchan_out, /* i : number of output channels */ + const Word16 last_element_mode, /* i : last_element_mode */ + const Word32 last_element_brate, /* i : last element bitrate */ + const Word16 Q_old_synthFB, + Word16 *Q_olapBufferSynth, + Word16 *Q_olapBufferSynth2 +#else + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 output_frame /* i : frame length Q0*/ +#endif ); ivas_error core_switching_post_dec_fx( @@ -9548,6 +9570,7 @@ void stereo_dft_dec_open( const Word16 nchan_transport /* i : number of transport channels */ ); +#ifndef HARM_CORE_SW void ivas_bw_switching_pre_proc_fx( Decoder_State *st, /* i/o: decoder state structure */ const Word32 last_element_brate, /* i : last element bitrate */ @@ -9555,7 +9578,7 @@ void ivas_bw_switching_pre_proc_fx( Word32 *old_syn_12k8_16k_fx, Word16 Q, Word16 Q_audio ); - +#endif UWord32 mvl2s_r( const Word32 x[], /* i : input vector */ const Word16 q, @@ -10411,6 +10434,7 @@ void wtda_fx32( const Word16 L /* i : length */ ); +#ifndef HARM_CORE_SWaa ivas_error core_switching_pre_dec_ivas_fx( Decoder_State *st, /* i/o: decoder state structure */ const Word16 output_frame, /* i : frame length */ @@ -10421,7 +10445,7 @@ ivas_error core_switching_pre_dec_ivas_fx( Word16 Q_old_synthFB, Word16 *Q_olapBufferSynth, Word16 *Q_olapBufferSynth2 ); - +#endif void hp20_fx_32( Word32 signal_fx[], const Word16 lg, diff --git a/lib_dec/amr_wb_dec_fx.c b/lib_dec/amr_wb_dec_fx.c index d7dcf5b03..8a6917374 100644 --- a/lib_dec/amr_wb_dec_fx.c +++ b/lib_dec/amr_wb_dec_fx.c @@ -172,7 +172,11 @@ ivas_error amr_wb_dec_fx( } /* Updates in case of EVS -> AMR-WB IO switching */ +#ifdef HARM_CORE_SWaa + IF( NE_32( ( error = core_switching_pre_dec_fx( st_fx, output_frame, -1, 1, EVS_MONO, EVS_MONO, -1, &tmp16, &tmp16) ), IVAS_ERR_OK ) ) +#else IF( NE_32( ( error = core_switching_pre_dec_fx( st_fx, output_frame ) ), IVAS_ERR_OK ) ) +#endif { return error; } diff --git a/lib_dec/core_switching_dec_fx.c b/lib_dec/core_switching_dec_fx.c index d1040cb80..695ddb64f 100644 --- a/lib_dec/core_switching_dec_fx.c +++ b/lib_dec/core_switching_dec_fx.c @@ -11,6 +11,15 @@ #include "ivas_prot_fx.h" +#ifdef HARM_CORE_SW +/*---------------------------------------------------------------------* + * Local prototypes + *---------------------------------------------------------------------*/ + +static void smoothTransitionDtxToTcx_fx( Word16 synth[], const Word16 output_frame, const Word16 delay_comp ); +static void core_switch_lb_upsamp_fx( Decoder_State *st, Word32 *output ); + +#else /*---------------------------------------------------------------------* * bandwidth_switching_detect_fx() * @@ -134,6 +143,7 @@ void bandwidth_switching_detect_fx( return; } +#endif /*---------------------------------------------------------------------* * Calc_freq_ener_fx() @@ -167,6 +177,7 @@ static Word32 Calc_freq_ener_fx( return enerLL_fx; } + /*---------------------------------------------------------------------* * bw_switching_pre_proc_fx() * @@ -174,8 +185,17 @@ static Word32 Calc_freq_ener_fx( *---------------------------------------------------------------------*/ void bw_switching_pre_proc_fx( - const Word16 *old_syn_12k8_16k_fx, /* i : ACELP core synthesis at 12.8kHz or 16kHz Qx*/ - Decoder_State *st_fx /* i/o: decoder state structure */ +#ifdef HARM_CORE_SW + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word32 last_element_brate, /* i : last element bitrate */ + const Word16 nchan_out, /* i : number of output channels */ + Word16 *old_syn_12k8_16k_fx16, + Word32 *old_syn_12k8_16k_fx32, + Word16 Q +#else + const Word16 *old_syn_12k8_16k_fx, /* i : ACELP core synthesis at 12.8kHz or 16kHz Qx*/ + Decoder_State *st_fx /* i/o: decoder state structure */ +#endif ) { Word16 i; @@ -184,6 +204,28 @@ void bw_switching_pre_proc_fx( IF( st_fx->element_mode > EVS_MONO ) { +#ifdef HARM_CORE_SW + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( st_fx->core == ACELP_CORE ) && !( EQ_16( st_fx->bfi, 1 ) && EQ_16( st_fx->con_tcx, 1 ) ) && st_fx->hBWE_FD != NULL && !( LE_32( st_fx->core_brate, SID_2k40 ) && EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) && EQ_16( nchan_out, 2 ) ) && !( EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) && EQ_16( nchan_out, 1 ) && EQ_16( st_fx->idchan, 1 ) && LE_32( last_element_brate, IVAS_SID_5k2 ) ) ) + { + /* Calculate tilt of the ACELP core synthesis - needed in SWB BWE decoding */ + Word16 old_syn_12k8_16k_tmp_16fx[L_FRAME16k]; + Copy_Scale_sig_32_16( old_syn_12k8_16k_fx32, old_syn_12k8_16k_tmp_16fx, st_fx->L_frame, sub( -1, Q ) ); + st_fx->tilt_wb_fx = round_fx_sat( L_shl_sat( calc_tilt_bwe_fx( old_syn_12k8_16k_tmp_16fx, -1, st_fx->L_frame ), sub( Q, 8 ) ) ); // Q24+(Q-8) - 16 + move16(); + } + + return; +#endif } test(); @@ -194,13 +236,22 @@ void bw_switching_pre_proc_fx( * Calculate tilt of the ACELP core synthesis *----------------------------------------------------------------------*/ +#ifdef HARM_CORE_SW + st_fx->tilt_wb_fx = round_fx_sat( L_shl_sat( calc_tilt_bwe_fx( old_syn_12k8_16k_fx16, -1, st_fx->L_frame ), 3 ) ); /* Q11 */ +#else st_fx->tilt_wb_fx = round_fx_sat( L_shl_sat( calc_tilt_bwe_fx( old_syn_12k8_16k_fx, -1, st_fx->L_frame ), 3 ) ); /* Q11 */ +#endif move16(); + /*-------------------------------------------------------------------------------* * Calculate frequency energy of 0~3.2kHz and 3.2~6.4kHz the ACELP core synthesis *-------------------------------------------------------------------------------*/ +#ifdef HARM_CORE_SW + edct_16fx( old_syn_12k8_16k_fx16, syn_dct_fx, L_FRAME, 6, st_fx->element_mode ); +#else edct_16fx( old_syn_12k8_16k_fx, syn_dct_fx, L_FRAME, 6, st_fx->element_mode ); +#endif L_tmp = L_deposit_l( 0 ); FOR( i = 0; i < L_FRAME / 2; i++ ) @@ -294,7 +345,7 @@ void bw_switching_pre_proc_fx( return; } - +#ifndef HARM_CORE_SWaa /*---------------------------------------------------------------------* * core_switching_pre_dec_fx() * @@ -866,6 +917,7 @@ ivas_error core_switching_pre_dec_fx( return error; } +#endif /*---------------------------------------------------------------------* * core_switching_post_dec() @@ -2164,22 +2216,48 @@ static void smoothTransitionDtxToTcx_fx( * * Preprocessing/preparation for ACELP/HQ core switching *---------------------------------------------------------------------*/ + +#ifdef HARM_CORE_SWaa +ivas_error core_switching_pre_dec_fx( +#else ivas_error core_switching_pre_dec_ivas_fx( +#endif Decoder_State *st, /* i/o: decoder state structure */ const Word16 output_frame, /* i : frame length */ const Word32 last_core_brate_st0, /* i : channel 0 last core bitrate */ const Word16 nchan_out, /* i : number of output channels */ const Word16 last_element_mode, /* i : last_element_mode */ const Word32 last_element_brate, /* i : last element bitrate */ +#ifdef HARM_CORE_SWaa + const Word16 Q_old_synthFB, +#else Word16 Q_old_synthFB, +#endif Word16 *Q_olapBufferSynth, Word16 *Q_olapBufferSynth2 ) { Word32 tmp_fx; /*Q-12*/ Word16 i, oldLenClasBuff, newLenClasBuff; ivas_error error; +#ifdef HARM_CORE_SW + Word16 tmp, exp = Q25; + Word32 L_tmp; +#else Word16 exp = 25; +#endif move16(); + BPF_DEC_HANDLE hBPF; + TD_BWE_DEC_HANDLE hBWE_TD; + FD_BWE_DEC_HANDLE hBWE_FD; + HQ_DEC_HANDLE hHQ_core; + TCX_DEC_HANDLE hTcxDec; + + hBWE_TD = st->hBWE_TD; + hBWE_FD = st->hBWE_FD; + hHQ_core = st->hHQ_core; + hBPF = st->hBPF; + hTcxDec = st->hTcxDec; + error = IVAS_ERR_OK; move32(); @@ -2189,9 +2267,9 @@ ivas_error core_switching_pre_dec_ivas_fx( test(); IF( EQ_16( st->last_codec_mode, MODE2 ) || ( ( EQ_16( st->last_core, TCX_20_CORE ) || EQ_16( st->last_core, TCX_10_CORE ) ) && ( st->element_mode > EVS_MONO ) ) ) { - st->mem_deemph_fx = st->syn[M]; + st->mem_deemph_fx = st->syn[M]; /* Q_syn */ move16(); - set16_fx( st->agc_mem_fx, 0, 2 ); + set16_fx( st->agc_mem_fx, 0, 2 ); /* Q0 */ Scale_sig( &( st->mem_deemph_fx ), 1, st->Q_syn ); /* Brings mem_deemph to Qsyn */ Copy_Scale_sig( st->mem_syn2_fx, st->mem_syn1_fx, M, sub( -1, st->Q_syn ) ); /*Q-1*/ @@ -2203,12 +2281,12 @@ ivas_error core_switching_pre_dec_ivas_fx( Scale_sig( st->hPFstat->mem_pf_in, L_SUBFR, st->Q_syn ); /* Post_filter mem ,Q_syn*/ Scale_sig( st->hPFstat->mem_res2, DECMEM_RES2, st->Q_syn ); /* NB post_filter mem , Q_syn*/ Scale_sig( st->hPFstat->mem_stp, L_SUBFR, st->Q_syn ); /* Post_filter mem ,Q_syn*/ - set16_fx( st->hBPF->pst_old_syn_fx, 0, NBPSF_PIT_MAX ); /* BPF mem*/ + set16_fx( hBPF->pst_old_syn_fx, 0, NBPSF_PIT_MAX ); /* BPF mem*/ } - IF( st->hBPF != NULL ) + IF( hBPF != NULL ) { - st->hBPF->pst_lp_ener_fx = round_fx( L_shl( Mpy_32_16_1( st->lp_error_ener, 0x6054 ), 2 + 8 ) ); /* convert from 15Q16, log2 -> 7Q8 10*log10 */ - st->hBPF->pst_mem_deemp_err_fx = 0; + hBPF->pst_lp_ener_fx = round_fx( L_shl( Mpy_32_16_1( st->lp_error_ener, 0x6054 ), 2 + 8 ) ); /* convert from 15Q16, log2 -> 7Q8 10*log10 */ + hBPF->pst_mem_deemp_err_fx = 0; move16(); move16(); } @@ -2218,23 +2296,23 @@ ivas_error core_switching_pre_dec_ivas_fx( /* reset old HB synthesis buffer */ IF( EQ_16( st->last_L_frame, L_FRAME ) ) { - st->old_bwe_delay = NS2SA( st->output_Fs, MAX_DELAY_TBE_NS - DELAY_SWB_TBE_12k8_NS ); + st->old_bwe_delay = NS2SA_FX2( st->output_Fs, MAX_DELAY_TBE_NS - DELAY_SWB_TBE_12k8_NS ); } ELSE { - st->old_bwe_delay = NS2SA( st->output_Fs, MAX_DELAY_TBE_NS - DELAY_SWB_TBE_16k_NS ); + st->old_bwe_delay = NS2SA_FX2( st->output_Fs, MAX_DELAY_TBE_NS - DELAY_SWB_TBE_16k_NS ); } move16(); set16_fx( st->hb_prev_synth_buffer_fx, 0, NS2SA( 48000, DELAY_BWE_TOTAL_NS ) ); test(); - IF( st->hBWE_TD != NULL && ( st->last_core != ACELP_CORE ) ) + IF( hBWE_TD != NULL && ( st->last_core != ACELP_CORE ) ) { - st->hBWE_TD->prev_hb_synth_fx_exp = 31; + hBWE_TD->prev_hb_synth_fx_exp = 31; move16(); /* reset BWE memories */ - set16_fx( st->hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2 ); - st->hBWE_TD->bwe_non_lin_prev_scale_fx = 0; + set16_fx( hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2 ); /* Q_exc */ + hBWE_TD->bwe_non_lin_prev_scale_fx = 0; move32(); } @@ -2246,35 +2324,42 @@ ivas_error core_switching_pre_dec_ivas_fx( move16(); test(); +#ifdef HARM_CORE_SWaa // !!!!! + IF( GE_32( st->output_Fs, 16000 ) && st->hBWE_zero != NULL ) +#else IF( GT_32( st->output_Fs, 16000 ) && st->hBWE_zero != NULL ) +#endif { hf_synth_reset_fx( st->hBWE_zero ); +#ifdef HARM_CORE_SW + IF( NE_16( st->element_mode, EVS_MONO ) ) // VE: TBV: tmp hack - it is a bug in EVS but condition is here to keep EVS bit-exact for the moment +#endif set16_fx( st->hBWE_zero->mem_hp400_fx, 0, 6 ); } - IF( st->hBWE_FD != NULL ) + IF( hBWE_FD != NULL ) { - set16_fx( st->hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); + set16_fx( hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); } - IF( st->hHQ_core != NULL ) + IF( hHQ_core != NULL ) { - set32_fx( st->hHQ_core->prev_env_fx, 0, SFM_N_WB ); - set32_fx( st->hHQ_core->prev_normq_fx, 0, SFM_N_WB ); + set32_fx( hHQ_core->prev_env_fx, 0, SFM_N_WB ); + set32_fx( hHQ_core->prev_normq_fx, 0, SFM_N_WB ); - set32_fx( st->hHQ_core->last_ni_gain_fx, 0, BANDS_MAX ); - set16_fx( st->hHQ_core->last_env_fx, 0, BANDS_MAX ); + set32_fx( hHQ_core->last_ni_gain_fx, 0, BANDS_MAX ); + set16_fx( hHQ_core->last_env_fx, 0, BANDS_MAX ); - st->hHQ_core->last_max_pos_pulse = 0; + hHQ_core->last_max_pos_pulse = 0; move16(); IF( GT_32( st->output_Fs, 16000 ) ) { - set32_fx( st->hHQ_core->prev_coeff_out_fx, 0, L_HQ_WB_BWE ); + set32_fx( hHQ_core->prev_coeff_out_fx, 0, L_HQ_WB_BWE ); } /* pre-echo */ - st->hHQ_core->pastpre = 0; + hHQ_core->pastpre = 0; move16(); } @@ -2293,20 +2378,24 @@ ivas_error core_switching_pre_dec_ivas_fx( st->last_core = HQ_CORE; move16(); - Copy32( st->hTcxDec->FBTCXdelayBuf_32, st->prev_synth_buffer32_fx, NS2SA( st->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ) ); - // Copy_Scale_sig_32_16( st->hTcxDec->FBTCXdelayBuf_32, st->prev_synth_buffer_fx, NS2SA( st->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ), -11 ); //Q11 -> Q0 +#ifdef HARM_CORE_SW + Copy( hTcxDec->FBTCXdelayBuf, st->prev_synth_buffer_fx, NS2SA_FX2( st->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ) ); /* st->q_prev_synth_buffer_fx */ +#else + Copy32( hTcxDec->FBTCXdelayBuf_32, st->prev_synth_buffer32_fx, NS2SA( st->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ) ); + // Copy_Scale_sig_32_16( hTcxDec->FBTCXdelayBuf_32, st->prev_synth_buffer_fx, NS2SA( st->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ), -11 ); //Q11 -> Q0 +#endif } - IF( st->hHQ_core != NULL ) + IF( hHQ_core != NULL ) { - set32_fx( st->hHQ_core->last_ni_gain_fx, 0, BANDS_MAX ); - set16_fx( st->hHQ_core->last_env_fx, 0, BANDS_MAX ); - st->hHQ_core->last_max_pos_pulse = 0; + set32_fx( hHQ_core->last_ni_gain_fx, 0, BANDS_MAX ); + set16_fx( hHQ_core->last_env_fx, 0, BANDS_MAX ); + hHQ_core->last_max_pos_pulse = 0; move16(); - set16_fx( st->hHQ_core->prev_SWB_peak_pos_fx, 0, SPT_SHORTEN_SBNUM ); - st->hHQ_core->prev_frm_hfe2 = 0; - st->hHQ_core->prev_stab_hfe2 = 0; + set16_fx( hHQ_core->prev_SWB_peak_pos_fx, 0, SPT_SHORTEN_SBNUM ); + hHQ_core->prev_frm_hfe2 = 0; + hHQ_core->prev_stab_hfe2 = 0; move16(); move16(); } @@ -2317,66 +2406,116 @@ ivas_error core_switching_pre_dec_ivas_fx( Word16 delay_comp; /*switch off Hq Voicing as it was not updated in MODE2*/ - IF( st->hHQ_core != NULL ) + IF( hHQ_core != NULL ) { - st->hHQ_core->oldHqVoicing = 0; - st->hHQ_core->HqVoicing = 0; + hHQ_core->oldHqVoicing = 0; + hHQ_core->HqVoicing = 0; move16(); move16(); } - delay_comp = NS2SA( st->output_Fs, DELAY_CLDFB_NS ); - /*TODO To be tested:control not entering the block*/ - test(); - test(); - IF( !st->last_con_tcx && ( st->last_core_bfi == ACELP_CORE ) && EQ_16( st->core, HQ_CORE ) ) + delay_comp = NS2SA_FX2( st->output_Fs, DELAY_CLDFB_NS ); + +#ifdef HARM_CORE_SW + IF( EQ_16( st->element_mode, EVS_MONO ) ) { - /*TODO None of the test dtreams are entering this block,hence enabled assert(0)*/ - assert( 0 ); - Word32 *realBuffer_fx[CLDFB_NO_COL_MAX_SWITCH], *imagBuffer_fx[CLDFB_NO_COL_MAX_SWITCH]; - Word32 realBufferTmp_fx[CLDFB_NO_COL_MAX_SWITCH][CLDFB_NO_CHANNELS_MAX], imagBufferTmp_fx[CLDFB_NO_COL_MAX_SWITCH][CLDFB_NO_CHANNELS_MAX]; - Word32 syn_Overl_fx[320]; - Word32 fer_samples_fx[960]; - Copy_Scale_sig_16_32_DEPREC( st->hTcxDec->syn_Overl, syn_Overl_fx, 320, 15 ); - Copy_Scale_sig_16_32_DEPREC( st->hHQ_core->fer_samples_fx, fer_samples_fx, 960, 15 ); + test(); + test(); + IF( !st->last_con_tcx && st->last_core_bfi == ACELP_CORE && EQ_16( st->core, HQ_CORE ) ) + { + Word16 no_col; + Word32 *realBuffer[CLDFB_NO_COL_MAX_SWITCH], *imagBuffer[CLDFB_NO_COL_MAX_SWITCH]; + Word32 realBufferTmp[CLDFB_NO_COL_MAX_SWITCH][CLDFB_NO_CHANNELS_MAX], imagBufferTmp[CLDFB_NO_COL_MAX_SWITCH][CLDFB_NO_CHANNELS_MAX]; + CLDFB_SCALE_FACTOR scaleFactor; + Word32 workBuffer[128 * 3]; + FOR( i = 0; i < CLDFB_NO_COL_MAX_SWITCH; i++ ) + { + set32_fx( realBufferTmp[i], 0, CLDFB_NO_CHANNELS_MAX ); + set32_fx( imagBufferTmp[i], 0, CLDFB_NO_CHANNELS_MAX ); + realBuffer[i] = realBufferTmp[i]; + move32(); + imagBuffer[i] = imagBufferTmp[i]; + move32(); + } - FOR( i = 0; i < CLDFB_NO_COL_MAX_SWITCH; i++ ) - { - set32_fx( realBufferTmp_fx[i], 0, CLDFB_NO_CHANNELS_MAX ); - set32_fx( imagBufferTmp_fx[i], 0, CLDFB_NO_CHANNELS_MAX ); - realBuffer_fx[i] = realBufferTmp_fx[i]; - imagBuffer_fx[i] = imagBufferTmp_fx[i]; - } + no_col = s_min( st->cldfbAna->no_col, idiv1616( sub( add( delay_comp, st->cldfbAna->no_channels ), 1 ), st->cldfbAna->no_channels ) ); /* Q0 */ - /* CLDFB analysis of the synthesis at internal sampling rate */ - IF( NE_32( ( error = cldfb_save_memory_ivas_fx( st->cldfbAna ) ), IVAS_ERR_OK ) ) - { - return error; - } + /* CLDFB analysis of the synthesis at internal sampling rate */ + IF( ( error = cldfb_save_memory( st->cldfbAna ) ) != IVAS_ERR_OK ) + { + return error; + } + cldfbAnalysis_fx( st->cldfbAna, realBuffer, imagBuffer, &scaleFactor, hTcxDec->syn_Overl, 0, no_col, workBuffer ); + cldfb_restore_memory( st->cldfbAna ); - cldfbAnalysis_ivas_fx( syn_Overl_fx, realBuffer_fx, imagBuffer_fx, delay_comp, st->cldfbAna ); - cldfb_restore_memory_ivas_fx( st->cldfbAna ); /*Assuming Q10*/ + scaleFactor.hb_scale = scaleFactor.lb_scale; + move16(); - /* CLDFB synthesis of the combined signal */ - IF( NE_32( ( error = cldfb_save_memory_ivas_fx( st->cldfbSyn ) ), IVAS_ERR_OK ) ) - { - return error; + /* CLDFB synthesis of the combined signal */ + IF( ( error = cldfb_save_memory( st->cldfbSyn ) ) != IVAS_ERR_OK ) + { + return error; + } + cldfbSynthesis_fx( st->cldfbSyn, realBuffer, imagBuffer, &scaleFactor, hHQ_core->fer_samples_fx, 0, no_col, workBuffer ); + cldfb_restore_memory( st->cldfbSyn ); } - - cldfbSynthesis_ivas_fx( realBuffer_fx, imagBuffer_fx, fer_samples_fx, delay_comp, 0, 0, st->cldfbSyn ); - cldfb_restore_memory_ivas_fx( st->cldfbSyn ); - Copy_Scale_sig_32_16( syn_Overl_fx, st->hTcxDec->syn_Overl, 320, 15 ); - Copy_Scale_sig_32_16( fer_samples_fx, st->hHQ_core->fer_samples_fx, 960, 9 ); } - - test(); - test(); - IF( !st->last_con_tcx && ( st->last_core_bfi == ACELP_CORE ) && EQ_16( st->core, HQ_CORE ) ) + ELSE +#endif { - lerp( st->hTcxDec->syn_Overl, st->hHQ_core->fer_samples_fx + delay_comp, shr( output_frame, 1 ), shr( st->last_L_frame, 1 ) ); - /*Set to zero the remaining part*/ - set16_fx( st->hHQ_core->fer_samples_fx + delay_comp + output_frame / 2, 0, sub( shr( output_frame, 1 ), delay_comp ) ); + /*TODO To be tested:control not entering the block*/ + test(); + test(); + IF( !st->last_con_tcx && ( st->last_core_bfi == ACELP_CORE ) && EQ_16( st->core, HQ_CORE ) ) + { + /*TODO None of the test dtreams are entering this block,hence enabled assert(0)*/ + assert( 0 ); + Word32 *realBuffer_fx[CLDFB_NO_COL_MAX_SWITCH], *imagBuffer_fx[CLDFB_NO_COL_MAX_SWITCH]; + Word32 realBufferTmp_fx[CLDFB_NO_COL_MAX_SWITCH][CLDFB_NO_CHANNELS_MAX], imagBufferTmp_fx[CLDFB_NO_COL_MAX_SWITCH][CLDFB_NO_CHANNELS_MAX]; + Word32 syn_Overl_fx[320]; + Word32 fer_samples_fx[960]; + Copy_Scale_sig_16_32_DEPREC( hTcxDec->syn_Overl, syn_Overl_fx, 320, 15 ); + Copy_Scale_sig_16_32_DEPREC( hHQ_core->fer_samples_fx, fer_samples_fx, 960, 15 ); + + + FOR( i = 0; i < CLDFB_NO_COL_MAX_SWITCH; i++ ) + { + set32_fx( realBufferTmp_fx[i], 0, CLDFB_NO_CHANNELS_MAX ); + set32_fx( imagBufferTmp_fx[i], 0, CLDFB_NO_CHANNELS_MAX ); + realBuffer_fx[i] = realBufferTmp_fx[i]; + imagBuffer_fx[i] = imagBufferTmp_fx[i]; + } + + /* CLDFB analysis of the synthesis at internal sampling rate */ + IF( NE_32( ( error = cldfb_save_memory_ivas_fx( st->cldfbAna ) ), IVAS_ERR_OK ) ) + { + return error; + } + + cldfbAnalysis_ivas_fx( syn_Overl_fx, realBuffer_fx, imagBuffer_fx, delay_comp, st->cldfbAna ); + cldfb_restore_memory_ivas_fx( st->cldfbAna ); /*Assuming Q10*/ + + /* CLDFB synthesis of the combined signal */ + IF( NE_32( ( error = cldfb_save_memory_ivas_fx( st->cldfbSyn ) ), IVAS_ERR_OK ) ) + { + return error; + } + + cldfbSynthesis_ivas_fx( realBuffer_fx, imagBuffer_fx, fer_samples_fx, delay_comp, 0, 0, st->cldfbSyn ); + cldfb_restore_memory_ivas_fx( st->cldfbSyn ); + Copy_Scale_sig_32_16( syn_Overl_fx, hTcxDec->syn_Overl, 320, 15 ); + Copy_Scale_sig_32_16( fer_samples_fx, hHQ_core->fer_samples_fx, 960, 9 ); + } + + test(); + test(); + IF( !st->last_con_tcx && ( st->last_core_bfi == ACELP_CORE ) && EQ_16( st->core, HQ_CORE ) ) + { + lerp( hTcxDec->syn_Overl, hHQ_core->fer_samples_fx + delay_comp, shr( output_frame, 1 ), shr( st->last_L_frame, 1 ) ); + /*Set to zero the remaining part*/ + set16_fx( hHQ_core->fer_samples_fx + delay_comp + output_frame / 2, 0, sub( shr( output_frame, 1 ), delay_comp ) ); + } } } @@ -2394,17 +2533,37 @@ ivas_error core_switching_pre_dec_ivas_fx( { IF( NE_16( st->L_frame, st->last_L_frame ) ) { - IF( GT_16( st->L_frame, st->last_L_frame ) ) +#ifdef HARM_CORE_SW + IF( EQ_16( st->element_mode, EVS_MONO ) ) { - oldLenClasBuff = mult_r( L_SYN_MEM_CLAS_ESTIM, div_s( st->last_L_frame, st->L_frame ) ); - newLenClasBuff = L_SYN_MEM_CLAS_ESTIM; - move16(); + IF( GT_16( st->L_frame, st->last_L_frame ) ) + { + oldLenClasBuff = extract_l( L_shr( Mpy_32_16_1( L_mult0( st->last_L_frame, getInvFrameLen( st->L_frame ) /*Q21*/ ) /*Q21*/, L_SYN_MEM_CLAS_ESTIM /*Q0*/ ) /*Q6*/, 6 ) /*Q0*/ ); + newLenClasBuff = L_SYN_MEM_CLAS_ESTIM; + move16(); + } + ELSE + { + oldLenClasBuff = L_SYN_MEM_CLAS_ESTIM; + move16(); + newLenClasBuff = extract_l( L_shr( Mpy_32_16_1( L_mult0( st->L_frame, getInvFrameLen( st->last_L_frame ) /*Q21*/ ) /*Q21*/, L_SYN_MEM_CLAS_ESTIM /*Q0*/ ) /*Q6*/, 6 ) /*Q0*/ ); + } } ELSE +#endif { - oldLenClasBuff = L_SYN_MEM_CLAS_ESTIM; - move16(); - newLenClasBuff = mult_r( L_SYN_MEM_CLAS_ESTIM, div_s( st->L_frame, st->last_L_frame ) ); + IF( GT_16( st->L_frame, st->last_L_frame ) ) + { + oldLenClasBuff = mult_r( L_SYN_MEM_CLAS_ESTIM, div_s( st->last_L_frame, st->L_frame ) ); + newLenClasBuff = L_SYN_MEM_CLAS_ESTIM; + move16(); + } + ELSE + { + oldLenClasBuff = L_SYN_MEM_CLAS_ESTIM; + move16(); + newLenClasBuff = mult_r( L_SYN_MEM_CLAS_ESTIM, div_s( st->L_frame, st->last_L_frame ) ); + } } lerp( &st->mem_syn_clas_estim_fx[L_SYN_MEM_CLAS_ESTIM - oldLenClasBuff], &st->mem_syn_clas_estim_fx[L_SYN_MEM_CLAS_ESTIM - newLenClasBuff], newLenClasBuff, oldLenClasBuff ); } @@ -2489,7 +2648,7 @@ ivas_error core_switching_pre_dec_ivas_fx( IF( ( EQ_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_CPE_TD ) ) && EQ_16( nchan_out, 2 ) && GT_32( st->core_brate, SID_2k40 ) && ( ( last_core_brate_st0 == FRAME_NO_DATA ) || EQ_32( last_core_brate_st0, SID_2k40 ) ) && st->hTcxDec != NULL ) { /* Last frame was Stereo CNG and the synthesis memory is outdated -- reset */ - set16_fx( st->hTcxDec->old_syn_Overl, 0, L_FRAME32k / 2 ); + set16_fx( hTcxDec->old_syn_Overl, 0, L_FRAME32k / 2 ); set16_fx( st->hFdCngDec->hFdCngCom->olapBufferAna_fx, 0, FFTLEN ); set16_fx( st->agc_mem_fx, 0, 2 ); } @@ -2500,9 +2659,9 @@ ivas_error core_switching_pre_dec_ivas_fx( set16_fx( st->mem_syn2_fx, 0, M ); } set16_fx( st->mem_syn1_fx, 0, M ); - if ( st->hBWE_TD != NULL ) + if ( hBWE_TD != NULL ) { - st->hBWE_TD->bwe_non_lin_prev_scale_fx = 0; + hBWE_TD->bwe_non_lin_prev_scale_fx = 0; move32(); } @@ -2511,11 +2670,11 @@ ivas_error core_switching_pre_dec_ivas_fx( IF( EQ_32( st->sr_core, INT_FS_16k ) ) { - Copy( GEWB2_Ave_fx, st->mem_AR_fx, M ); + Copy( GEWB2_Ave_fx, st->mem_AR_fx, M ); /* Q2.56 */ } ELSE { - Copy( GEWB_Ave_fx, st->mem_AR_fx, M ); + Copy( GEWB_Ave_fx, st->mem_AR_fx, M ); /* Q2.56 */ } st->tilt_code_fx = 0; @@ -2531,13 +2690,38 @@ ivas_error core_switching_pre_dec_ivas_fx( st->last_coder_type = GENERIC; move16(); - fer_energy_fx( output_frame, UNVOICED_CLAS, st->previoussynth_fx_32, 0, -1, &st->enr_old_fx, 1 ); /*Q-0*/ - st->lp_gainp_fx = 0; - move16(); - st->lp_gainc_fx = extract_h( Sqrt32( st->lp_ener_fx, &exp ) ); /*Q=15-exp*/ - move16(); - st->lp_gainc_fx = shr( st->lp_gainc_fx, sub( 12, exp ) ); /*Q3*/ - move16(); +#ifdef HARM_CORE_SW + IF( EQ_16( st->element_mode, EVS_MONO ) ) + { + frame_ener_fx( output_frame, UNVOICED_CLAS, st->previoussynth_fx, -1, &st->enr_old_fx, 1, 0, 0, 0 ); + st->lp_gainp_fx = 0; + move16(); + + IF( st->lp_ener_fx != 0 ) + { + exp = norm_l( st->lp_ener_fx ); /* In Q6 */ + tmp = extract_h( L_shl( st->lp_ener_fx, exp ) ); + exp = sub( exp, 30 - 6 ); + + tmp = div_s( 16384, tmp ); + L_tmp = L_deposit_h( tmp ); + L_tmp = Isqrt_lc( L_tmp, &exp ); + + st->lp_gainc_fx = round_fx( L_shl( L_tmp, sub( exp, 12 ) ) ); /* In Q3 */ + move16(); + } + } + ELSE +#endif + { + fer_energy_fx( output_frame, UNVOICED_CLAS, st->previoussynth_fx_32, 0, -1, &st->enr_old_fx, 1 ); /*Q-0*/ + st->lp_gainp_fx = 0; + move16(); + st->lp_gainc_fx = extract_h( Sqrt32( st->lp_ener_fx, &exp ) ); /*Q=15-exp*/ + move16(); + st->lp_gainc_fx = shr( st->lp_gainc_fx, sub( 12, exp ) ); /*Q3*/ + move16(); + } st->last_voice_factor_fx = 0; st->Last_GSC_noisy_speech_flag = 0; @@ -2545,9 +2729,20 @@ ivas_error core_switching_pre_dec_ivas_fx( move16(); /* reset CLDFB memories */ - cldfb_reset_memory_fx( st->cldfbAna ); - cldfb_reset_memory_fx( st->cldfbBPF ); - cldfb_reset_memory_fx( st->cldfbSyn ); +#ifdef HARM_CORE_SW + IF( EQ_16( st->element_mode, EVS_MONO ) ) + { + cldfb_reset_memory( st->cldfbAna ); + cldfb_reset_memory( st->cldfbBPF ); + cldfb_reset_memory( st->cldfbSyn ); + } + ELSE +#endif + { + cldfb_reset_memory_fx( st->cldfbAna ); + cldfb_reset_memory_fx( st->cldfbBPF ); + cldfb_reset_memory_fx( st->cldfbSyn ); + } /* reset TBE memories */ test(); @@ -2562,21 +2757,28 @@ ivas_error core_switching_pre_dec_ivas_fx( synth_mem_updt2( st->L_frame, L_FRAME16k, st->old_exc_fx, st->mem_syn_r, st->mem_syn2_fx, NULL, DEC ); } - IF( st->hBWE_TD != NULL ) + IF( hBWE_TD != NULL ) { - set16_fx( st->hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2 ); + set16_fx( hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2 ); } test(); +#ifdef HARM_CORE_SWaa // !!!!! + IF( GE_32( st->output_Fs, 16000 ) && st->hBWE_zero != NULL ) +#else IF( GT_32( st->output_Fs, 16000 ) && st->hBWE_zero != NULL ) +#endif { hf_synth_reset_fx( st->hBWE_zero ); +#ifdef HARM_CORE_SW + IF( NE_16( st->element_mode, EVS_MONO ) ) // VE: TBV: tmp hack - it is a bug in EVS but condition is here to keep EVS bit-exact for the moment +#endif set16_fx( st->hBWE_zero->mem_hp400_fx, 0, 6 ); } - IF( st->hBWE_FD != NULL ) + IF( hBWE_FD != NULL ) { - set16_fx( st->hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); + set16_fx( hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA_FX2( 16000, DELAY_FD_BWE_ENC_NS ) ); } } @@ -2585,11 +2787,11 @@ ivas_error core_switching_pre_dec_ivas_fx( test(); IF( ( ( st->core == ACELP_CORE ) || EQ_16( st->core, AMR_WB_CORE ) ) && ( EQ_16( st->last_core, TCX_20_CORE ) || EQ_16( st->last_core, TCX_10_CORE ) ) ) { - IF( st->hBWE_TD != NULL ) + IF( hBWE_TD != NULL ) { - st->hBWE_TD->bwe_non_lin_prev_scale_fx = 0; + hBWE_TD->bwe_non_lin_prev_scale_fx = 0; move32(); - set16_fx( st->hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2 ); + set16_fx( hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2 ); } st->tilt_code_fx = 0; @@ -2624,9 +2826,9 @@ ivas_error core_switching_pre_dec_ivas_fx( set16_fx( st->hBWE_zero->mem_hp400_fx, 0, 6 ); } - IF( st->hBWE_FD != NULL ) + IF( hBWE_FD != NULL ) { - set16_fx( st->hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); + set16_fx( hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); } test(); @@ -2637,17 +2839,23 @@ ivas_error core_switching_pre_dec_ivas_fx( /* update cldbf state with previous frame TCX synthesis when going from a bitrate with residual coding to a bitrate without it */ Word16 offset; offset = sub( st->cldfbAna->p_filter_length, st->cldfbAna->no_channels ); +#ifdef HARM_CORE_SW + Word32 old_synthFB_fx[L_FRAME_PLUS * 2]; +#else Word32 *old_synthFB_fx; - IF( ( old_synthFB_fx = (Word32 *) malloc( st->hTcxDec->old_synth_lenFB * sizeof( Word32 ) ) ) == NULL ) + IF( ( old_synthFB_fx = (Word32 *) malloc( hTcxDec->old_synth_lenFB * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for old_synth_lenFB (32 bit) \n" ) ); } - Copy_Scale_sig_16_32_no_sat( st->hTcxDec->old_synthFB_fx, old_synthFB_fx, st->hTcxDec->old_synth_lenFB, sub( Q10, Q_old_synthFB ) ); // Q10 - Copy32( old_synthFB_fx + st->hTcxDec->old_synth_lenFB - offset, st->cldfbAna->cldfb_state_fx, offset ); +#endif + Copy_Scale_sig_16_32_no_sat( hTcxDec->old_synthFB_fx, old_synthFB_fx, hTcxDec->old_synth_lenFB, sub( Q10, Q_old_synthFB ) ); // Q10 + Copy32( old_synthFB_fx + hTcxDec->old_synth_lenFB - offset, st->cldfbAna->cldfb_state_fx, offset ); st->cldfbAna->Q_cldfb_state = Q10; move16(); +#ifndef HARM_CORE_SW IF( old_synthFB_fx ) free( old_synthFB_fx ); +#endif } } @@ -2657,22 +2865,22 @@ ivas_error core_switching_pre_dec_ivas_fx( test(); IF( EQ_16( st->core, HQ_CORE ) && ( ( st->last_core == ACELP_CORE ) || EQ_16( st->last_core, AMR_WB_CORE ) || ( ( ( st->element_mode != EVS_MONO ) ) && ( NE_16( st->last_core, HQ_CORE ) ) ) ) ) { - set32_fx( st->hHQ_core->prev_env_fx, 0, SFM_N_WB ); - set32_fx( st->hHQ_core->prev_normq_fx, 0, SFM_N_WB ); + set32_fx( hHQ_core->prev_env_fx, 0, SFM_N_WB ); + set32_fx( hHQ_core->prev_normq_fx, 0, SFM_N_WB ); - set32_fx( st->hHQ_core->last_ni_gain_fx, 0, BANDS_MAX ); - set16_fx( st->hHQ_core->last_env_fx, 0, BANDS_MAX ); - st->hHQ_core->last_max_pos_pulse = 0; + set32_fx( hHQ_core->last_ni_gain_fx, 0, BANDS_MAX ); + set16_fx( hHQ_core->last_env_fx, 0, BANDS_MAX ); + hHQ_core->last_max_pos_pulse = 0; move16(); - set16_fx( st->hHQ_core->prev_SWB_peak_pos_fx, 0, SPT_SHORTEN_SBNUM ); - st->hHQ_core->prev_frm_hfe2 = 0; - st->hHQ_core->prev_stab_hfe2 = 0; + set16_fx( hHQ_core->prev_SWB_peak_pos_fx, 0, SPT_SHORTEN_SBNUM ); + hHQ_core->prev_frm_hfe2 = 0; + hHQ_core->prev_stab_hfe2 = 0; move16(); move16(); IF( GT_32( st->output_Fs, 16000 ) ) { - set32_fx( st->hHQ_core->prev_coeff_out_fx, 0, L_HQ_WB_BWE ); + set32_fx( hHQ_core->prev_coeff_out_fx, 0, L_HQ_WB_BWE ); } IF( st->element_mode != EVS_MONO ) @@ -2680,46 +2888,46 @@ ivas_error core_switching_pre_dec_ivas_fx( /* Estimate mem_env_delta to reinit env_stab */ tmp_fx = L_max( 0, L_add( ENV_STAB_EST1_FX, L_add( Mult_32_16( st->stab_fac_smooth_lt_fx, ENV_STAB_EST2_FX ), Mult_32_16( st->log_energy_diff_lt_fx, ENV_STAB_EST3_FX ) ) ) ); /*Q12*/ - st->hHQ_core->mem_env_delta = extract_l( L_min( MAX16B, tmp_fx ) ); /* Convert to Q12 and handle saturation */ + hHQ_core->mem_env_delta = extract_l( L_min( MAX16B, tmp_fx ) ); /* Convert to Q12 and handle saturation */ move16(); test(); IF( NE_16( st->last_core, TCX_20_CORE ) && NE_16( st->last_core, TCX_10_CORE ) ) { - set16_fx( st->hHQ_core->old_out_fx, 0, output_frame ); - set32_fx( st->hHQ_core->old_out_LB_fx32, 0, L_FRAME16k ); - set16_fx( st->hHQ_core->old_out_LB_fx, 0, L_FRAME16k ); + set16_fx( hHQ_core->old_out_fx, 0, output_frame ); + set32_fx( hHQ_core->old_out_LB_fx32, 0, L_FRAME16k ); + set16_fx( hHQ_core->old_out_LB_fx, 0, L_FRAME16k ); } - st->hHQ_core->no_att_hangover = 0; + hHQ_core->no_att_hangover = 0; move16(); - st->hHQ_core->energy_lt_fx = 2457600; /*300.0f Q13*/ + hHQ_core->energy_lt_fx = 2457600; /*300.0f Q13*/ move32(); - set16_fx( st->hHQ_core->old_is_transient, 0, 3 ); - set16_fx( st->hHQ_core->prev_noise_level_fx, 0, 2 ); - st->hHQ_core->prev_R = 0; + set16_fx( hHQ_core->old_is_transient, 0, 3 ); + set16_fx( hHQ_core->prev_noise_level_fx, 0, 2 ); + hHQ_core->prev_R = 0; move16(); - set16_fx( st->hHQ_core->mem_norm + 1, 39, SFM_N_ENV_STAB - 1 ); - st->hHQ_core->prev_hqswb_clas = HQ_NORMAL; - st->hHQ_core->prev_ni_ratio_fx = 16384; /*Q15*/ + set16_fx( hHQ_core->mem_norm + 1, 39, SFM_N_ENV_STAB - 1 ); + hHQ_core->prev_hqswb_clas = HQ_NORMAL; + hHQ_core->prev_ni_ratio_fx = 16384; /*Q15*/ move16(); move16(); - set16_fx( st->hHQ_core->prev_En_sb_fx, 0, NB_SWB_SUBBANDS ); + set16_fx( hHQ_core->prev_En_sb_fx, 0, NB_SWB_SUBBANDS ); } ELSE { - set16_fx( st->hHQ_core->old_out_fx, 0, output_frame ); - set32_fx( st->hHQ_core->old_out_LB_fx32, 0, L_FRAME16k ); + set16_fx( hHQ_core->old_out_fx, 0, output_frame ); + set32_fx( hHQ_core->old_out_LB_fx32, 0, L_FRAME16k ); } } /* handle switching cases where preecho_sb was not called in the last frame (memory not up to date) */ - IF( st->hHQ_core != NULL ) + IF( hHQ_core != NULL ) { - st->hHQ_core->pastpre = sub( st->hHQ_core->pastpre, 1 ); + hHQ_core->pastpre = sub( hHQ_core->pastpre, 1 ); move16(); - IF( st->hHQ_core->pastpre < 0 ) + IF( hHQ_core->pastpre < 0 ) { - reset_preecho_dec_fx( st->hHQ_core ); + reset_preecho_dec_fx( hHQ_core ); } } test(); @@ -2739,10 +2947,8 @@ ivas_error core_switching_pre_dec_ivas_fx( st->m_frame_type = ACTIVE_FRAME; } - move16(); - move16(); /*switch on CNA on active frames*/ - IF( ( st->element_mode == EVS_MONO ) ) /* for IVAS modes, st->flag_cna is set earlier */ + IF( st->element_mode == EVS_MONO ) /* for IVAS modes, st->flag_cna is set earlier */ { test(); test(); @@ -2778,6 +2984,25 @@ ivas_error core_switching_pre_dec_ivas_fx( /* || st->last_core == AMR_WB_CORE || st->last_codec_mode == MODE2)){*/ IF( NE_16( st->core, AMR_WB_CORE ) ) { +#ifdef HARM_CORE_SW + L_tmp = st->total_brate; + move32(); + test(); + if ( EQ_16( st->rf_flag, 1 ) && EQ_32( st->total_brate, ACELP_13k20 ) ) + { + L_tmp = ACELP_9k60; + move32(); + } + + IF( EQ_16( st->element_mode, EVS_MONO ) ) + { + configureFdCngDec_fx( st->hFdCngDec, st->bwidth, L_tmp, st->L_frame, st->last_L_frame, st->element_mode ); + } + ELSE + { + configureFdCngDec_ivas_fx( st->hFdCngDec, st->bwidth, st->total_brate, st->L_frame, st->last_L_frame, st->element_mode ); + } +#else test(); IF( EQ_16( st->rf_flag, 1 ) && EQ_32( st->total_brate, ACELP_13k20 ) ) { @@ -2787,10 +3012,15 @@ ivas_error core_switching_pre_dec_ivas_fx( { configureFdCngDec_ivas_fx( st->hFdCngDec, st->bwidth, st->total_brate, st->L_frame, st->last_L_frame, st->element_mode ); } +#endif } ELSE { +#ifdef HARM_CORE_SW + configureFdCngDec_fx( st->hFdCngDec, WB, ACELP_8k00, st->L_frame, st->last_L_frame, st->element_mode ); +#else configureFdCngDec_ivas_fx( st->hFdCngDec, WB, ACELP_8k00, st->L_frame, st->last_L_frame, st->element_mode ); +#endif if ( st->VAD ) { @@ -2808,27 +3038,57 @@ ivas_error core_switching_pre_dec_ivas_fx( lerp( st->hFdCngDec->hFdCngCom->olapBufferAna_fx + st->last_L_frame, st->hFdCngDec->hFdCngCom->olapBufferAna_fx + st->L_frame, st->L_frame, st->last_L_frame ); } - L_lerp_fx( st->hFdCngDec->hFdCngCom->olapBufferSynth2_fx, st->hFdCngDec->hFdCngCom->olapBufferSynth2_fx, shl( st->L_frame, 1 ), shl( st->last_L_frame, 1 ), Q_olapBufferSynth2 ); - - test(); - IF( LE_32( st->total_brate, SID_2k40 ) && LE_32( st->last_total_brate, SID_2k40 ) ) +#ifdef HARM_CORE_SW + IF( EQ_16( st->element_mode, EVS_MONO ) ) { - L_lerp_fx( st->hFdCngDec->hFdCngCom->olapBufferSynth_fx, st->hFdCngDec->hFdCngCom->olapBufferSynth_fx, shl( st->L_frame, 1 ), shl( st->last_L_frame, 1 ), Q_olapBufferSynth ); - - IF( EQ_16( st->L_frame, L_FRAME ) ) + lerp( st->hFdCngDec->hFdCngCom->olapBufferSynth2, st->hFdCngDec->hFdCngCom->olapBufferSynth2, shl( st->L_frame, 1 ), shl( st->last_L_frame, 1 ) ); + test(); + IF( LE_32( st->total_brate, SID_2k40 ) && LE_32( st->last_total_brate, SID_2k40 ) ) { - FOR( i = 0; i < ( st->L_frame * 2 ); i++ ) + lerp( st->hFdCngDec->hFdCngCom->olapBufferSynth, st->hFdCngDec->hFdCngCom->olapBufferSynth, shl( st->L_frame, 1 ), shl( st->last_L_frame, 1 ) ); + IF( EQ_16( st->L_frame, L_FRAME ) ) { - st->hFdCngDec->hFdCngCom->olapBufferSynth_fx[i] = Mult_32_16( st->hFdCngDec->hFdCngCom->olapBufferSynth_fx[i], (Word16) 20480 /* 0.6250f in Q15 */ ); - move32(); + FOR( i = 0; i < shl( st->L_frame, 1 ); i++ ) + { + st->hFdCngDec->hFdCngCom->olapBufferSynth[i] = mult_r( st->hFdCngDec->hFdCngCom->olapBufferSynth[i], 20480 /* Q15*/ ); /* q_olapBuffer */ + move16(); + } + } + ELSE + { + FOR( i = 0; i < shl( st->L_frame, 1 ); i++ ) + { + st->hFdCngDec->hFdCngCom->olapBufferSynth[i] = mult_r( shl( st->hFdCngDec->hFdCngCom->olapBufferSynth[i], 1 ), 26214 /* Q14*/ ); /* q_olapBuffer */ + move16(); + } } } - ELSE + } + ELSE +#endif + { + L_lerp_fx( st->hFdCngDec->hFdCngCom->olapBufferSynth2_fx, st->hFdCngDec->hFdCngCom->olapBufferSynth2_fx, shl( st->L_frame, 1 ), shl( st->last_L_frame, 1 ), Q_olapBufferSynth2 ); + + test(); + IF( LE_32( st->total_brate, SID_2k40 ) && LE_32( st->last_total_brate, SID_2k40 ) ) { - FOR( i = 0; i < ( st->L_frame * 2 ); i++ ) + L_lerp_fx( st->hFdCngDec->hFdCngCom->olapBufferSynth_fx, st->hFdCngDec->hFdCngCom->olapBufferSynth_fx, shl( st->L_frame, 1 ), shl( st->last_L_frame, 1 ), Q_olapBufferSynth ); + + IF( EQ_16( st->L_frame, L_FRAME ) ) { - st->hFdCngDec->hFdCngCom->olapBufferSynth_fx[i] = Mult_32_16( L_shl( st->hFdCngDec->hFdCngCom->olapBufferSynth_fx[i], 1 ), (Word16) 26214 /* 1.6f in Q14 */ ); - move32(); + FOR( i = 0; i < ( st->L_frame * 2 ); i++ ) + { + st->hFdCngDec->hFdCngCom->olapBufferSynth_fx[i] = Mult_32_16( st->hFdCngDec->hFdCngCom->olapBufferSynth_fx[i], (Word16) 20480 /* 0.6250f in Q15 */ ); + move32(); + } + } + ELSE + { + FOR( i = 0; i < ( st->L_frame * 2 ); i++ ) + { + st->hFdCngDec->hFdCngCom->olapBufferSynth_fx[i] = Mult_32_16( L_shl( st->hFdCngDec->hFdCngCom->olapBufferSynth_fx[i], 1 ), (Word16) 26214 /* 1.6f in Q14 */ ); + move32(); + } } } } @@ -2837,12 +3097,15 @@ ivas_error core_switching_pre_dec_ivas_fx( return error; } + +#ifndef HARM_CORE_SW /*---------------------------------------------------------------------* * core_switching_hq_prepare_dec() * * Preprocessing in the first HQ frame after ACELP frame * Modify bit allocation for HQ core by removing ACELP subframe budget *---------------------------------------------------------------------*/ +#endif /*---------------------------------------------------------------------* * bandwidth_switching_detect() @@ -2850,7 +3113,11 @@ ivas_error core_switching_pre_dec_ivas_fx( * Classification for band-width switching *---------------------------------------------------------------------*/ +#ifdef HARM_CORE_SW +void bandwidth_switching_detect_fx( +#else void bandwidth_switching_detect_ivas_fx( +#endif Decoder_State *st_fx /* i/o: encoder state structure */ ) { @@ -2966,7 +3233,7 @@ void bandwidth_switching_detect_ivas_fx( return; } - +#ifndef HARM_CORE_SW /*---------------------------------------------------------------------* * bw_switching_pre_proc() * @@ -3153,3 +3420,4 @@ void ivas_bw_switching_pre_proc_fx( return; } +#endif diff --git a/lib_dec/evs_dec_fx.c b/lib_dec/evs_dec_fx.c index a358cbe8a..e40f276f4 100644 --- a/lib_dec/evs_dec_fx.c +++ b/lib_dec/evs_dec_fx.c @@ -315,7 +315,11 @@ ivas_error evs_dec_fx( * Preprocessing (preparing) for ACELP/HQ core switching *---------------------------------------------------------------------*/ +#ifdef HARM_CORE_SWaa + IF( ( error = core_switching_pre_dec_fx( st_fx, output_frame, -1, 1, EVS_MONO, EVS_MONO, -1, &tmp16, &tmp16 ) ) != IVAS_ERR_OK ) +#else IF( ( error = core_switching_pre_dec_fx( st_fx, output_frame ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -355,7 +359,11 @@ ivas_error evs_dec_fx( * Pre-processing for bandwidth switching *---------------------------------------------------------------------*/ +#ifdef HARM_CORE_SW + bw_switching_pre_proc_fx( st_fx, -1, 1, old_syn_12k8_16k_fx, NULL, 0 ); +#else bw_switching_pre_proc_fx( old_syn_12k8_16k_fx, st_fx ); +#endif /*---------------------------------------------------------------------* * WB TBE decoding diff --git a/lib_dec/ivas_core_dec_fx.c b/lib_dec/ivas_core_dec_fx.c index bf1f75333..81059c6c6 100644 --- a/lib_dec/ivas_core_dec_fx.c +++ b/lib_dec/ivas_core_dec_fx.c @@ -81,6 +81,9 @@ ivas_error ivas_core_dec_fx( Word16 core_switching_flag[CPE_CHANNELS]; Word16 pitch_buf_fx[CPE_CHANNELS][NB_SUBFR16k]; // Q6 +#ifdef HARM_CORE_SW + Word16 old_syn_12k8_16k_fx_16[CPE_CHANNELS][L_FRAME16k]; +#endif Word32 old_syn_12k8_16k_fx[CPE_CHANNELS][L_FRAME16k]; Word16 unbits[CPE_CHANNELS]; @@ -439,7 +442,11 @@ ivas_error ivas_core_dec_fx( * Detect bandwidth switching *---------------------------------------------------------------------*/ +#ifdef HARM_CORE_SW + bandwidth_switching_detect_fx( st ); +#else bandwidth_switching_detect_ivas_fx( st ); +#endif /*---------------------------------------------------------------------* * Preprocessing (preparing) for ACELP/HQ core switching @@ -454,7 +461,11 @@ ivas_error ivas_core_dec_fx( Copy_Scale_sig_16_32_DEPREC( st->previoussynth_fx, st->previoussynth_fx_32, L_FRAME48k, 0 ); // Q0 +#ifdef HARM_CORE_SWaa + IF( NE_32( ( error = core_switching_pre_dec_fx( st, output_frame, sts[0]->last_core_brate, nchan_out, last_element_mode, last_element_brate, st->Q_syn, &Q_olapBufferSynth, &Q_olapBufferSynth2 ) ), IVAS_ERR_OK ) ) +#else IF( NE_32( ( error = core_switching_pre_dec_ivas_fx( st, output_frame, sts[0]->last_core_brate, nchan_out, last_element_mode, last_element_brate, st->Q_syn, &Q_olapBufferSynth, &Q_olapBufferSynth2 ) ), IVAS_ERR_OK ) ) +#endif { return error; } @@ -478,7 +489,9 @@ ivas_error ivas_core_dec_fx( IF( st->core == ACELP_CORE ) { /* ACELP core decoder */ +#ifndef HARM_CORE_SW Word16 old_syn_12k8_16k_fx_16[L_FRAME16k]; +#endif Word16 save_hb_synth_fx_arr[L_FRAME48k], *save_hb_synth_16_fx; IF( save_hb_synth_32_fx ) @@ -529,7 +542,11 @@ ivas_error ivas_core_dec_fx( st->Q_syn_factor = 0; move16(); +#ifdef HARM_CORE_SW + IF( NE_32( ( error = acelp_core_dec_fx( st, output_16_fx[n], synth_16_fx[n], save_hb_synth_16_fx, bwe_exc_extended_fx[n], voice_factors_fx[n], old_syn_12k8_16k_fx_16[n], sharpFlag[n], pitch_buf_fx[n], &unbits[n], &sid_bw[n], hStereoTD, tdm_lsfQ_PCh_fx, use_cldfb_for_dft, last_element_mode, last_element_brate, flag_sec_CNA, nchan_out, hStereoCng, read_sid_info ) ), IVAS_ERR_OK ) ) +#else IF( NE_32( ( error = acelp_core_dec_fx( st, output_16_fx[n], synth_16_fx[n], save_hb_synth_16_fx, bwe_exc_extended_fx[n], voice_factors_fx[n], old_syn_12k8_16k_fx_16, sharpFlag[n], pitch_buf_fx[n], &unbits[n], &sid_bw[n], hStereoTD, tdm_lsfQ_PCh_fx, use_cldfb_for_dft, last_element_mode, last_element_brate, flag_sec_CNA, nchan_out, hStereoCng, read_sid_info ) ), IVAS_ERR_OK ) ) +#endif { return error; } @@ -567,6 +584,9 @@ ivas_error ivas_core_dec_fx( { Copy_Scale_sig_16_32_DEPREC( old_syn_12k8_16k_fx_16, old_syn_12k8_16k_fx[n], st->L_frame, Q11 - ( -Q1 ) ); // Q(11 - (-1)) } +#else +#ifdef HARM_CORE_SW + Copy_Scale_sig_16_32_DEPREC( old_syn_12k8_16k_fx_16[n], old_syn_12k8_16k_fx[n], L_FRAME16k, Q11 - ( -Q1 ) ); // Q(11 - (-1)) #else Copy_Scale_sig_16_32_DEPREC( old_syn_12k8_16k_fx_16, old_syn_12k8_16k_fx[n], L_FRAME16k, Q11 - ( -Q1 ) ); // Q(11 - (-1)) #endif @@ -937,7 +957,11 @@ ivas_error ivas_core_dec_fx( * Pre-processing for bandwidth switching *---------------------------------------------------------------------*/ +#ifdef HARM_CORE_SW + bw_switching_pre_proc_fx( st, last_element_brate, nchan_out, old_syn_12k8_16k_fx_16[n], old_syn_12k8_16k_fx[n], old_syn_fx ); +#else ivas_bw_switching_pre_proc_fx( st, last_element_brate, nchan_out, old_syn_12k8_16k_fx[n], old_syn_fx, q_audio ); +#endif IF( st->hHQ_core == NULL ) { -- GitLab From 400ca96d7ae7bd84eeec5ddc34eeefa821c18f90 Mon Sep 17 00:00:00 2001 From: vaclav Date: Fri, 9 Jan 2026 18:13:22 +0100 Subject: [PATCH 02/18] clang-format --- lib_dec/amr_wb_dec_fx.c | 2 +- lib_dec/core_switching_dec_fx.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib_dec/amr_wb_dec_fx.c b/lib_dec/amr_wb_dec_fx.c index 8a6917374..d4b671e63 100644 --- a/lib_dec/amr_wb_dec_fx.c +++ b/lib_dec/amr_wb_dec_fx.c @@ -173,7 +173,7 @@ ivas_error amr_wb_dec_fx( /* Updates in case of EVS -> AMR-WB IO switching */ #ifdef HARM_CORE_SWaa - IF( NE_32( ( error = core_switching_pre_dec_fx( st_fx, output_frame, -1, 1, EVS_MONO, EVS_MONO, -1, &tmp16, &tmp16) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = core_switching_pre_dec_fx( st_fx, output_frame, -1, 1, EVS_MONO, EVS_MONO, -1, &tmp16, &tmp16 ) ), IVAS_ERR_OK ) ) #else IF( NE_32( ( error = core_switching_pre_dec_fx( st_fx, output_frame ) ), IVAS_ERR_OK ) ) #endif diff --git a/lib_dec/core_switching_dec_fx.c b/lib_dec/core_switching_dec_fx.c index 695ddb64f..0d56a5154 100644 --- a/lib_dec/core_switching_dec_fx.c +++ b/lib_dec/core_switching_dec_fx.c @@ -2506,7 +2506,7 @@ ivas_error core_switching_pre_dec_ivas_fx( cldfb_restore_memory_ivas_fx( st->cldfbSyn ); Copy_Scale_sig_32_16( syn_Overl_fx, hTcxDec->syn_Overl, 320, 15 ); Copy_Scale_sig_32_16( fer_samples_fx, hHQ_core->fer_samples_fx, 960, 9 ); - } + } test(); test(); -- GitLab From 38ab79b14f37b9da88f138749bfe763d503f7c35 Mon Sep 17 00:00:00 2001 From: vaclav Date: Fri, 9 Jan 2026 18:43:51 +0100 Subject: [PATCH 03/18] HARM_CORE_SW, decoder step 2 (core_switching_pre_dec_fx) --- lib_com/options.h | 2 +- lib_com/prot_fx.h | 4 +-- lib_dec/amr_wb_dec_fx.c | 2 +- lib_dec/core_switching_dec_fx.c | 45 +++++++++++++++++++++++++-------- lib_dec/evs_dec_fx.c | 2 +- lib_dec/ivas_core_dec_fx.c | 9 ++++--- 6 files changed, 44 insertions(+), 20 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 9518e3168..d841c2920 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -117,7 +117,7 @@ #define CLEANUP_ACELP_ENC /* VA: basop issue 2304: Remove duplicated code in excitation encoding in the ACELP core */ #define CLEANUP_VBR_CAM_ENC /* VA: basop issue 2299: Remove unused core-encoder VBR and CAM code */ -#define HARM_CORE_SW +#define HARM_CORE_SW /* VA: basop issue 2314: Remove duplicated code in the core switching */ /* #################### End BE switches ################################## */ diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 41d1ad5ae..2daf792a4 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -7815,7 +7815,7 @@ void bw_switching_pre_proc_fx( ); ivas_error core_switching_pre_dec_fx( -#ifdef HARM_CORE_SWaa +#ifdef HARM_CORE_SW Decoder_State *st, /* i/o: decoder state structure */ const Word16 output_frame, /* i : frame length */ const Word32 last_core_brate_st0, /* i : channel 0 last core bitrate */ @@ -10434,7 +10434,7 @@ void wtda_fx32( const Word16 L /* i : length */ ); -#ifndef HARM_CORE_SWaa +#ifndef HARM_CORE_SW ivas_error core_switching_pre_dec_ivas_fx( Decoder_State *st, /* i/o: decoder state structure */ const Word16 output_frame, /* i : frame length */ diff --git a/lib_dec/amr_wb_dec_fx.c b/lib_dec/amr_wb_dec_fx.c index d4b671e63..8f6229794 100644 --- a/lib_dec/amr_wb_dec_fx.c +++ b/lib_dec/amr_wb_dec_fx.c @@ -172,7 +172,7 @@ ivas_error amr_wb_dec_fx( } /* Updates in case of EVS -> AMR-WB IO switching */ -#ifdef HARM_CORE_SWaa +#ifdef HARM_CORE_SW IF( NE_32( ( error = core_switching_pre_dec_fx( st_fx, output_frame, -1, 1, EVS_MONO, EVS_MONO, -1, &tmp16, &tmp16 ) ), IVAS_ERR_OK ) ) #else IF( NE_32( ( error = core_switching_pre_dec_fx( st_fx, output_frame ) ), IVAS_ERR_OK ) ) diff --git a/lib_dec/core_switching_dec_fx.c b/lib_dec/core_switching_dec_fx.c index 0d56a5154..65d6e3ab2 100644 --- a/lib_dec/core_switching_dec_fx.c +++ b/lib_dec/core_switching_dec_fx.c @@ -345,7 +345,7 @@ void bw_switching_pre_proc_fx( return; } -#ifndef HARM_CORE_SWaa +#ifndef HARM_CORE_SW /*---------------------------------------------------------------------* * core_switching_pre_dec_fx() * @@ -2217,7 +2217,7 @@ static void smoothTransitionDtxToTcx_fx( * Preprocessing/preparation for ACELP/HQ core switching *---------------------------------------------------------------------*/ -#ifdef HARM_CORE_SWaa +#ifdef HARM_CORE_SW ivas_error core_switching_pre_dec_fx( #else ivas_error core_switching_pre_dec_ivas_fx( @@ -2228,7 +2228,7 @@ ivas_error core_switching_pre_dec_ivas_fx( const Word16 nchan_out, /* i : number of output channels */ const Word16 last_element_mode, /* i : last_element_mode */ const Word32 last_element_brate, /* i : last element bitrate */ -#ifdef HARM_CORE_SWaa +#ifdef HARM_CORE_SW const Word16 Q_old_synthFB, #else Word16 Q_old_synthFB, @@ -2324,11 +2324,7 @@ ivas_error core_switching_pre_dec_ivas_fx( move16(); test(); -#ifdef HARM_CORE_SWaa // !!!!! - IF( GE_32( st->output_Fs, 16000 ) && st->hBWE_zero != NULL ) -#else IF( GT_32( st->output_Fs, 16000 ) && st->hBWE_zero != NULL ) -#endif { hf_synth_reset_fx( st->hBWE_zero ); #ifdef HARM_CORE_SW @@ -2337,6 +2333,16 @@ ivas_error core_switching_pre_dec_ivas_fx( set16_fx( st->hBWE_zero->mem_hp400_fx, 0, 6 ); } +#ifdef HARM_CORE_SW // temp hack to keep EVS BE - see basop issue 2313 + IF( st->element_mode == EVS_MONO ) + { + IF( st->output_Fs == 16000 && st->hBWE_zero != NULL ) + { + hf_synth_reset_fx( st->hBWE_zero ); + } + } + +#endif IF( hBWE_FD != NULL ) { set16_fx( hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); @@ -2571,6 +2577,10 @@ ivas_error core_switching_pre_dec_ivas_fx( ELSE { set16_fx( st->mem_syn_clas_estim_fx, 0, L_SYN_MEM_CLAS_ESTIM ); +#ifdef HARM_CORE_SW + st->classifier_Q_mem_syn = 0; + move16(); +#endif } } @@ -2763,11 +2773,7 @@ ivas_error core_switching_pre_dec_ivas_fx( } test(); -#ifdef HARM_CORE_SWaa // !!!!! - IF( GE_32( st->output_Fs, 16000 ) && st->hBWE_zero != NULL ) -#else IF( GT_32( st->output_Fs, 16000 ) && st->hBWE_zero != NULL ) -#endif { hf_synth_reset_fx( st->hBWE_zero ); #ifdef HARM_CORE_SW @@ -2776,6 +2782,16 @@ ivas_error core_switching_pre_dec_ivas_fx( set16_fx( st->hBWE_zero->mem_hp400_fx, 0, 6 ); } +#ifdef HARM_CORE_SW // temp hack to keep EVS BE - see basop issue 2313 + IF( st->element_mode == EVS_MONO ) + { + IF( st->output_Fs == 16000 && st->hBWE_zero != NULL ) + { + hf_synth_reset_fx( st->hBWE_zero ); + } + } + +#endif IF( hBWE_FD != NULL ) { set16_fx( hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA_FX2( 16000, DELAY_FD_BWE_ENC_NS ) ); @@ -2915,8 +2931,15 @@ ivas_error core_switching_pre_dec_ivas_fx( } ELSE { +#ifdef HARM_CORE_SW + set16_fx( hHQ_core->old_out_fx, 0, output_frame ); + hHQ_core->Q_old_wtda_LB = 15; + hHQ_core->Q_old_wtda = 15; + move16(); +#else set16_fx( hHQ_core->old_out_fx, 0, output_frame ); set32_fx( hHQ_core->old_out_LB_fx32, 0, L_FRAME16k ); +#endif } } diff --git a/lib_dec/evs_dec_fx.c b/lib_dec/evs_dec_fx.c index e40f276f4..e5c8c47a6 100644 --- a/lib_dec/evs_dec_fx.c +++ b/lib_dec/evs_dec_fx.c @@ -315,7 +315,7 @@ ivas_error evs_dec_fx( * Preprocessing (preparing) for ACELP/HQ core switching *---------------------------------------------------------------------*/ -#ifdef HARM_CORE_SWaa +#ifdef HARM_CORE_SW IF( ( error = core_switching_pre_dec_fx( st_fx, output_frame, -1, 1, EVS_MONO, EVS_MONO, -1, &tmp16, &tmp16 ) ) != IVAS_ERR_OK ) #else IF( ( error = core_switching_pre_dec_fx( st_fx, output_frame ) ) != IVAS_ERR_OK ) diff --git a/lib_dec/ivas_core_dec_fx.c b/lib_dec/ivas_core_dec_fx.c index 81059c6c6..fa8f193fb 100644 --- a/lib_dec/ivas_core_dec_fx.c +++ b/lib_dec/ivas_core_dec_fx.c @@ -461,7 +461,7 @@ ivas_error ivas_core_dec_fx( Copy_Scale_sig_16_32_DEPREC( st->previoussynth_fx, st->previoussynth_fx_32, L_FRAME48k, 0 ); // Q0 -#ifdef HARM_CORE_SWaa +#ifdef HARM_CORE_SW IF( NE_32( ( error = core_switching_pre_dec_fx( st, output_frame, sts[0]->last_core_brate, nchan_out, last_element_mode, last_element_brate, st->Q_syn, &Q_olapBufferSynth, &Q_olapBufferSynth2 ) ), IVAS_ERR_OK ) ) #else IF( NE_32( ( error = core_switching_pre_dec_ivas_fx( st, output_frame, sts[0]->last_core_brate, nchan_out, last_element_mode, last_element_brate, st->Q_syn, &Q_olapBufferSynth, &Q_olapBufferSynth2 ) ), IVAS_ERR_OK ) ) @@ -582,11 +582,12 @@ ivas_error ivas_core_dec_fx( #ifdef FIX_2290_COPY_OF_UNINIT_DATA IF( st->hBWE_FD != NULL ) { +#ifdef HARM_CORE_SW + Copy_Scale_sig_16_32_DEPREC( old_syn_12k8_16k_fx_16[n], old_syn_12k8_16k_fx[n], st->L_frame, Q11 - ( -Q1 ) ); // Q(11 - (-1)) +#else Copy_Scale_sig_16_32_DEPREC( old_syn_12k8_16k_fx_16, old_syn_12k8_16k_fx[n], st->L_frame, Q11 - ( -Q1 ) ); // Q(11 - (-1)) +#endif } -#else -#ifdef HARM_CORE_SW - Copy_Scale_sig_16_32_DEPREC( old_syn_12k8_16k_fx_16[n], old_syn_12k8_16k_fx[n], L_FRAME16k, Q11 - ( -Q1 ) ); // Q(11 - (-1)) #else Copy_Scale_sig_16_32_DEPREC( old_syn_12k8_16k_fx_16, old_syn_12k8_16k_fx[n], L_FRAME16k, Q11 - ( -Q1 ) ); // Q(11 - (-1)) #endif -- GitLab From 89641aa6604d2f23f24be7a40bc1f24e6ff22803 Mon Sep 17 00:00:00 2001 From: vaclav Date: Fri, 9 Jan 2026 18:57:24 +0100 Subject: [PATCH 04/18] clang-format --- lib_dec/core_switching_dec_fx.c | 12 ++++++++---- lib_dec/ivas_core_dec_fx.c | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/lib_dec/core_switching_dec_fx.c b/lib_dec/core_switching_dec_fx.c index 65d6e3ab2..2c1da3f12 100644 --- a/lib_dec/core_switching_dec_fx.c +++ b/lib_dec/core_switching_dec_fx.c @@ -2933,8 +2933,9 @@ ivas_error core_switching_pre_dec_ivas_fx( { #ifdef HARM_CORE_SW set16_fx( hHQ_core->old_out_fx, 0, output_frame ); - hHQ_core->Q_old_wtda_LB = 15; - hHQ_core->Q_old_wtda = 15; + set16_fx( hHQ_core->old_out_LB_fx, 0, L_FRAME16k ); + hHQ_core->Q_old_wtda_LB = Q15; + hHQ_core->Q_old_wtda = Q15; move16(); #else set16_fx( hHQ_core->old_out_fx, 0, output_frame ); @@ -2953,6 +2954,7 @@ ivas_error core_switching_pre_dec_ivas_fx( reset_preecho_dec_fx( hHQ_core ); } } + test(); IF( st->core_brate == FRAME_NO_DATA ) { @@ -3051,6 +3053,7 @@ ivas_error core_switching_pre_dec_ivas_fx( move32(); } } + test(); test(); IF( NE_16( st->last_L_frame, st->L_frame ) && LE_16( st->L_frame, L_FRAME16k ) && LE_16( st->last_L_frame, L_FRAME16k ) ) @@ -3069,6 +3072,7 @@ ivas_error core_switching_pre_dec_ivas_fx( IF( LE_32( st->total_brate, SID_2k40 ) && LE_32( st->last_total_brate, SID_2k40 ) ) { lerp( st->hFdCngDec->hFdCngCom->olapBufferSynth, st->hFdCngDec->hFdCngCom->olapBufferSynth, shl( st->L_frame, 1 ), shl( st->last_L_frame, 1 ) ); + IF( EQ_16( st->L_frame, L_FRAME ) ) { FOR( i = 0; i < shl( st->L_frame, 1 ); i++ ) @@ -3099,7 +3103,7 @@ ivas_error core_switching_pre_dec_ivas_fx( IF( EQ_16( st->L_frame, L_FRAME ) ) { - FOR( i = 0; i < ( st->L_frame * 2 ); i++ ) + FOR( i = 0; i < shl( st->L_frame, 1 ); i++ ) { st->hFdCngDec->hFdCngCom->olapBufferSynth_fx[i] = Mult_32_16( st->hFdCngDec->hFdCngCom->olapBufferSynth_fx[i], (Word16) 20480 /* 0.6250f in Q15 */ ); move32(); @@ -3107,7 +3111,7 @@ ivas_error core_switching_pre_dec_ivas_fx( } ELSE { - FOR( i = 0; i < ( st->L_frame * 2 ); i++ ) + FOR( i = 0; i < shl( st->L_frame, 1 ); i++ ) { st->hFdCngDec->hFdCngCom->olapBufferSynth_fx[i] = Mult_32_16( L_shl( st->hFdCngDec->hFdCngCom->olapBufferSynth_fx[i], 1 ), (Word16) 26214 /* 1.6f in Q14 */ ); move32(); diff --git a/lib_dec/ivas_core_dec_fx.c b/lib_dec/ivas_core_dec_fx.c index fa8f193fb..a10fc81ed 100644 --- a/lib_dec/ivas_core_dec_fx.c +++ b/lib_dec/ivas_core_dec_fx.c @@ -583,7 +583,7 @@ ivas_error ivas_core_dec_fx( IF( st->hBWE_FD != NULL ) { #ifdef HARM_CORE_SW - Copy_Scale_sig_16_32_DEPREC( old_syn_12k8_16k_fx_16[n], old_syn_12k8_16k_fx[n], st->L_frame, Q11 - ( -Q1 ) ); // Q(11 - (-1)) + Copy_Scale_sig_16_32_DEPREC( old_syn_12k8_16k_fx_16[n], old_syn_12k8_16k_fx[n], st->L_frame, Q11 - ( -Q1 ) ); // Q(11 - (-1)) #else Copy_Scale_sig_16_32_DEPREC( old_syn_12k8_16k_fx_16, old_syn_12k8_16k_fx[n], st->L_frame, Q11 - ( -Q1 ) ); // Q(11 - (-1)) #endif -- GitLab From bc1c38680c6ae71b264c8116541aa796df5a7e48 Mon Sep 17 00:00:00 2001 From: vaclav Date: Fri, 9 Jan 2026 19:03:55 +0100 Subject: [PATCH 05/18] clang-format --- lib_dec/core_switching_dec_fx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_dec/core_switching_dec_fx.c b/lib_dec/core_switching_dec_fx.c index 2c1da3f12..c4a39fe0d 100644 --- a/lib_dec/core_switching_dec_fx.c +++ b/lib_dec/core_switching_dec_fx.c @@ -3072,7 +3072,7 @@ ivas_error core_switching_pre_dec_ivas_fx( IF( LE_32( st->total_brate, SID_2k40 ) && LE_32( st->last_total_brate, SID_2k40 ) ) { lerp( st->hFdCngDec->hFdCngCom->olapBufferSynth, st->hFdCngDec->hFdCngCom->olapBufferSynth, shl( st->L_frame, 1 ), shl( st->last_L_frame, 1 ) ); - + IF( EQ_16( st->L_frame, L_FRAME ) ) { FOR( i = 0; i < shl( st->L_frame, 1 ); i++ ) -- GitLab From 1c932cde13b34e31613a563bc51c17b2517f107f Mon Sep 17 00:00:00 2001 From: vaclav Date: Fri, 9 Jan 2026 19:17:44 +0100 Subject: [PATCH 06/18] remove unused parameter --- lib_com/prot_fx.h | 3 +-- lib_dec/core_switching_dec_fx.c | 7 +++---- lib_dec/evs_dec_fx.c | 2 +- lib_dec/ivas_core_dec_fx.c | 5 ++++- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 2daf792a4..079876573 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -7806,8 +7806,7 @@ void bw_switching_pre_proc_fx( const Word32 last_element_brate, /* i : last element bitrate */ const Word16 nchan_out, /* i : number of output channels */ Word16 *old_syn_12k8_16k_fx16, - Word32 *old_syn_12k8_16k_fx32, - Word16 Q + Word32 *old_syn_12k8_16k_fx32 #else const Word16 *old_syn_12k8_16k_fx, /* i : ACELP core synthesis at 12.8kHz or 16kHz Qx*/ Decoder_State *st_fx /* i/o: decoder state structure */ diff --git a/lib_dec/core_switching_dec_fx.c b/lib_dec/core_switching_dec_fx.c index c4a39fe0d..d96e97617 100644 --- a/lib_dec/core_switching_dec_fx.c +++ b/lib_dec/core_switching_dec_fx.c @@ -190,8 +190,7 @@ void bw_switching_pre_proc_fx( const Word32 last_element_brate, /* i : last element bitrate */ const Word16 nchan_out, /* i : number of output channels */ Word16 *old_syn_12k8_16k_fx16, - Word32 *old_syn_12k8_16k_fx32, - Word16 Q + Word32 *old_syn_12k8_16k_fx32 #else const Word16 *old_syn_12k8_16k_fx, /* i : ACELP core synthesis at 12.8kHz or 16kHz Qx*/ Decoder_State *st_fx /* i/o: decoder state structure */ @@ -219,8 +218,8 @@ void bw_switching_pre_proc_fx( { /* Calculate tilt of the ACELP core synthesis - needed in SWB BWE decoding */ Word16 old_syn_12k8_16k_tmp_16fx[L_FRAME16k]; - Copy_Scale_sig_32_16( old_syn_12k8_16k_fx32, old_syn_12k8_16k_tmp_16fx, st_fx->L_frame, sub( -1, Q ) ); - st_fx->tilt_wb_fx = round_fx_sat( L_shl_sat( calc_tilt_bwe_fx( old_syn_12k8_16k_tmp_16fx, -1, st_fx->L_frame ), sub( Q, 8 ) ) ); // Q24+(Q-8) - 16 + Copy_Scale_sig_32_16( old_syn_12k8_16k_fx32, old_syn_12k8_16k_tmp_16fx, st_fx->L_frame, sub( -1, Q11 ) ); + st_fx->tilt_wb_fx = round_fx_sat( L_shl_sat( calc_tilt_bwe_fx( old_syn_12k8_16k_tmp_16fx, -1, st_fx->L_frame ), sub( Q11, 8 ) ) ); // Q24+(Q11-8) - 16 move16(); } diff --git a/lib_dec/evs_dec_fx.c b/lib_dec/evs_dec_fx.c index e5c8c47a6..0410dd62e 100644 --- a/lib_dec/evs_dec_fx.c +++ b/lib_dec/evs_dec_fx.c @@ -360,7 +360,7 @@ ivas_error evs_dec_fx( *---------------------------------------------------------------------*/ #ifdef HARM_CORE_SW - bw_switching_pre_proc_fx( st_fx, -1, 1, old_syn_12k8_16k_fx, NULL, 0 ); + bw_switching_pre_proc_fx( st_fx, -1, 1, old_syn_12k8_16k_fx, NULL ); #else bw_switching_pre_proc_fx( old_syn_12k8_16k_fx, st_fx ); #endif diff --git a/lib_dec/ivas_core_dec_fx.c b/lib_dec/ivas_core_dec_fx.c index a10fc81ed..bd6e8fdb9 100644 --- a/lib_dec/ivas_core_dec_fx.c +++ b/lib_dec/ivas_core_dec_fx.c @@ -872,11 +872,14 @@ ivas_error ivas_core_dec_fx( move16(); } +#ifndef HARM_CORE_SW Word16 q_audio, old_syn_fx; old_syn_fx = Q11; move16(); q_audio = Q12; move16(); +#endif + test(); test(); test(); @@ -959,7 +962,7 @@ ivas_error ivas_core_dec_fx( *---------------------------------------------------------------------*/ #ifdef HARM_CORE_SW - bw_switching_pre_proc_fx( st, last_element_brate, nchan_out, old_syn_12k8_16k_fx_16[n], old_syn_12k8_16k_fx[n], old_syn_fx ); + bw_switching_pre_proc_fx( st, last_element_brate, nchan_out, old_syn_12k8_16k_fx_16[n], old_syn_12k8_16k_fx[n] ); #else ivas_bw_switching_pre_proc_fx( st, last_element_brate, nchan_out, old_syn_12k8_16k_fx[n], old_syn_fx, q_audio ); #endif -- GitLab From 3923f6f414112462006e804556c02ad6b85682e5 Mon Sep 17 00:00:00 2001 From: vaclav Date: Sat, 10 Jan 2026 13:21:39 +0100 Subject: [PATCH 07/18] HARM_CORE_SW, decoder step 3 (core_switching_pre_dec_fx) - move buffer old_syn_12k8_16k_fx[][] --- lib_com/prot_fx.h | 29 +++++++++++---------- lib_dec/core_switching_dec_fx.c | 46 ++++++++++++++++----------------- lib_dec/evs_dec_fx.c | 2 +- lib_dec/ivas_core_dec_fx.c | 15 +++++------ lib_dec/swb_tbe_dec_fx.c | 17 +++++++++--- 5 files changed, 60 insertions(+), 49 deletions(-) diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 079876573..7cb2ef504 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -7802,14 +7802,13 @@ void bandwidth_switching_detect_ivas_fx( #endif void bw_switching_pre_proc_fx( #ifdef HARM_CORE_SW - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word32 last_element_brate, /* i : last element bitrate */ - const Word16 nchan_out, /* i : number of output channels */ - Word16 *old_syn_12k8_16k_fx16, - Word32 *old_syn_12k8_16k_fx32 + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word32 last_element_brate, /* i : last element bitrate */ + const Word16 nchan_out, /* i : number of output channels */ + const Word16 *old_syn_12k8_16k_fx /* i : ACELP core synthesis at 12.8kHz or 16kHz Qx*/ #else - const Word16 *old_syn_12k8_16k_fx, /* i : ACELP core synthesis at 12.8kHz or 16kHz Qx*/ - Decoder_State *st_fx /* i/o: decoder state structure */ + const Word16 *old_syn_12k8_16k_fx, /* i : ACELP core synthesis at 12.8kHz or 16kHz Qx*/ + Decoder_State *st_fx /* i/o: decoder state structure */ #endif ); @@ -7825,8 +7824,8 @@ ivas_error core_switching_pre_dec_fx( Word16 *Q_olapBufferSynth, Word16 *Q_olapBufferSynth2 #else - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 output_frame /* i : frame length Q0*/ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 output_frame /* i : frame length Q0*/ #endif ); @@ -10385,11 +10384,15 @@ void ivas_swb_tbe_dec_fx( STEREO_ICBWE_DEC_HANDLE hStereoICBWE, /* i/o: IC-BWE state structure */ const Word32 *bwe_exc_extended_fx, /* i : bandwidth extended excitation : Q_exc */ Word16 Q_exc, - const Word16 voice_factors_fx[], /* i : voicing factors : Q15 */ + const Word16 voice_factors_fx[], /* i : voicing factors : Q15 */ +#ifdef FIX_2290_COPY_OF_UNINIT_DATA + const Word16 old_syn_12k8_16k_fx16[], /* i : low band synthesis : old_syn_fx */ +#else const Word32 old_syn_12k8_16k_fx[], /* i : low band synthesis : old_syn_fx */ - Word16 *White_exc16k_fx, /* o : shaped white excitation for the FB TBE : Q_white_exc*/ - Word32 *synth_fx, /* o : SHB synthesis/final synthesis : Qx */ - Word16 *pitch_buf_fx, /* i : Q6 */ +#endif + Word16 *White_exc16k_fx, /* o : shaped white excitation for the FB TBE : Q_white_exc*/ + Word32 *synth_fx, /* o : SHB synthesis/final synthesis : Qx */ + Word16 *pitch_buf_fx, /* i : Q6 */ Word16 *Q_white_exc ); Word16 swb_bwe_dec_fx32( diff --git a/lib_dec/core_switching_dec_fx.c b/lib_dec/core_switching_dec_fx.c index d96e97617..98c38171d 100644 --- a/lib_dec/core_switching_dec_fx.c +++ b/lib_dec/core_switching_dec_fx.c @@ -186,11 +186,10 @@ static Word32 Calc_freq_ener_fx( void bw_switching_pre_proc_fx( #ifdef HARM_CORE_SW - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word32 last_element_brate, /* i : last element bitrate */ - const Word16 nchan_out, /* i : number of output channels */ - Word16 *old_syn_12k8_16k_fx16, - Word32 *old_syn_12k8_16k_fx32 + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word32 last_element_brate, /* i : last element bitrate */ + const Word16 nchan_out, /* i : number of output channels */ + const Word16 *old_syn_12k8_16k_fx /* i : ACELP core synthesis at 12.8kHz or 16kHz Qx*/ #else const Word16 *old_syn_12k8_16k_fx, /* i : ACELP core synthesis at 12.8kHz or 16kHz Qx*/ Decoder_State *st_fx /* i/o: decoder state structure */ @@ -218,7 +217,9 @@ void bw_switching_pre_proc_fx( { /* Calculate tilt of the ACELP core synthesis - needed in SWB BWE decoding */ Word16 old_syn_12k8_16k_tmp_16fx[L_FRAME16k]; - Copy_Scale_sig_32_16( old_syn_12k8_16k_fx32, old_syn_12k8_16k_tmp_16fx, st_fx->L_frame, sub( -1, Q11 ) ); + Word32 old_syn_12k8_16k_tmp_32fx[L_FRAME16k]; + Copy_Scale_sig_16_32_DEPREC( old_syn_12k8_16k_fx, old_syn_12k8_16k_tmp_32fx, st_fx->L_frame, Q11 - ( -Q1 ) ); // Q(11 - (-1)) + Copy_Scale_sig_32_16( old_syn_12k8_16k_tmp_32fx, old_syn_12k8_16k_tmp_16fx, st_fx->L_frame, sub( -1, Q11 ) ); st_fx->tilt_wb_fx = round_fx_sat( L_shl_sat( calc_tilt_bwe_fx( old_syn_12k8_16k_tmp_16fx, -1, st_fx->L_frame ), sub( Q11, 8 ) ) ); // Q24+(Q11-8) - 16 move16(); } @@ -235,22 +236,14 @@ void bw_switching_pre_proc_fx( * Calculate tilt of the ACELP core synthesis *----------------------------------------------------------------------*/ -#ifdef HARM_CORE_SW - st_fx->tilt_wb_fx = round_fx_sat( L_shl_sat( calc_tilt_bwe_fx( old_syn_12k8_16k_fx16, -1, st_fx->L_frame ), 3 ) ); /* Q11 */ -#else st_fx->tilt_wb_fx = round_fx_sat( L_shl_sat( calc_tilt_bwe_fx( old_syn_12k8_16k_fx, -1, st_fx->L_frame ), 3 ) ); /* Q11 */ -#endif move16(); /*-------------------------------------------------------------------------------* * Calculate frequency energy of 0~3.2kHz and 3.2~6.4kHz the ACELP core synthesis *-------------------------------------------------------------------------------*/ -#ifdef HARM_CORE_SW - edct_16fx( old_syn_12k8_16k_fx16, syn_dct_fx, L_FRAME, 6, st_fx->element_mode ); -#else edct_16fx( old_syn_12k8_16k_fx, syn_dct_fx, L_FRAME, 6, st_fx->element_mode ); -#endif L_tmp = L_deposit_l( 0 ); FOR( i = 0; i < L_FRAME / 2; i++ ) @@ -341,6 +334,7 @@ void bw_switching_pre_proc_fx( st_fx->prev_fractive = 0; move16(); } + return; } @@ -2280,10 +2274,15 @@ ivas_error core_switching_pre_dec_ivas_fx( Scale_sig( st->hPFstat->mem_pf_in, L_SUBFR, st->Q_syn ); /* Post_filter mem ,Q_syn*/ Scale_sig( st->hPFstat->mem_res2, DECMEM_RES2, st->Q_syn ); /* NB post_filter mem , Q_syn*/ Scale_sig( st->hPFstat->mem_stp, L_SUBFR, st->Q_syn ); /* Post_filter mem ,Q_syn*/ - set16_fx( hBPF->pst_old_syn_fx, 0, NBPSF_PIT_MAX ); /* BPF mem*/ +#ifndef HARM_CORE_SW + set16_fx( hBPF->pst_old_syn_fx, 0, NBPSF_PIT_MAX ); /* BPF mem*/ +#endif } IF( hBPF != NULL ) { +#ifdef HARM_CORE_SW + set16_fx( hBPF->pst_old_syn_fx, 0, NBPSF_PIT_MAX ); /* BPF mem*/ +#endif hBPF->pst_lp_ener_fx = round_fx( L_shl( Mpy_32_16_1( st->lp_error_ener, 0x6054 ), 2 + 8 ) ); /* convert from 15Q16, log2 -> 7Q8 10*log10 */ hBPF->pst_mem_deemp_err_fx = 0; move16(); @@ -2512,15 +2511,15 @@ ivas_error core_switching_pre_dec_ivas_fx( Copy_Scale_sig_32_16( syn_Overl_fx, hTcxDec->syn_Overl, 320, 15 ); Copy_Scale_sig_32_16( fer_samples_fx, hHQ_core->fer_samples_fx, 960, 9 ); } + } - test(); - test(); - IF( !st->last_con_tcx && ( st->last_core_bfi == ACELP_CORE ) && EQ_16( st->core, HQ_CORE ) ) - { - lerp( hTcxDec->syn_Overl, hHQ_core->fer_samples_fx + delay_comp, shr( output_frame, 1 ), shr( st->last_L_frame, 1 ) ); - /*Set to zero the remaining part*/ - set16_fx( hHQ_core->fer_samples_fx + delay_comp + output_frame / 2, 0, sub( shr( output_frame, 1 ), delay_comp ) ); - } + test(); + test(); + IF( !st->last_con_tcx && ( st->last_core_bfi == ACELP_CORE ) && EQ_16( st->core, HQ_CORE ) ) + { + lerp( hTcxDec->syn_Overl, hHQ_core->fer_samples_fx + delay_comp, shr( output_frame, 1 ), shr( st->last_L_frame, 1 ) ); + /*Set to zero the remaining part*/ + set16_fx( hHQ_core->fer_samples_fx + delay_comp + output_frame / 2, 0, sub( shr( output_frame, 1 ), delay_comp ) ); } } @@ -2934,6 +2933,7 @@ ivas_error core_switching_pre_dec_ivas_fx( set16_fx( hHQ_core->old_out_fx, 0, output_frame ); set16_fx( hHQ_core->old_out_LB_fx, 0, L_FRAME16k ); hHQ_core->Q_old_wtda_LB = Q15; + move16(); hHQ_core->Q_old_wtda = Q15; move16(); #else diff --git a/lib_dec/evs_dec_fx.c b/lib_dec/evs_dec_fx.c index 0410dd62e..6686099b8 100644 --- a/lib_dec/evs_dec_fx.c +++ b/lib_dec/evs_dec_fx.c @@ -360,7 +360,7 @@ ivas_error evs_dec_fx( *---------------------------------------------------------------------*/ #ifdef HARM_CORE_SW - bw_switching_pre_proc_fx( st_fx, -1, 1, old_syn_12k8_16k_fx, NULL ); + bw_switching_pre_proc_fx( st_fx, -1, 1, old_syn_12k8_16k_fx ); #else bw_switching_pre_proc_fx( old_syn_12k8_16k_fx, st_fx ); #endif diff --git a/lib_dec/ivas_core_dec_fx.c b/lib_dec/ivas_core_dec_fx.c index bd6e8fdb9..cbf005b95 100644 --- a/lib_dec/ivas_core_dec_fx.c +++ b/lib_dec/ivas_core_dec_fx.c @@ -82,9 +82,10 @@ ivas_error ivas_core_dec_fx( Word16 pitch_buf_fx[CPE_CHANNELS][NB_SUBFR16k]; // Q6 #ifdef HARM_CORE_SW - Word16 old_syn_12k8_16k_fx_16[CPE_CHANNELS][L_FRAME16k]; -#endif + Word16 old_syn_12k8_16k_fx[CPE_CHANNELS][L_FRAME16k]; +#else Word32 old_syn_12k8_16k_fx[CPE_CHANNELS][L_FRAME16k]; +#endif Word16 unbits[CPE_CHANNELS]; Word16 sid_bw[CPE_CHANNELS]; @@ -543,7 +544,7 @@ ivas_error ivas_core_dec_fx( move16(); #ifdef HARM_CORE_SW - IF( NE_32( ( error = acelp_core_dec_fx( st, output_16_fx[n], synth_16_fx[n], save_hb_synth_16_fx, bwe_exc_extended_fx[n], voice_factors_fx[n], old_syn_12k8_16k_fx_16[n], sharpFlag[n], pitch_buf_fx[n], &unbits[n], &sid_bw[n], hStereoTD, tdm_lsfQ_PCh_fx, use_cldfb_for_dft, last_element_mode, last_element_brate, flag_sec_CNA, nchan_out, hStereoCng, read_sid_info ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = acelp_core_dec_fx( st, output_16_fx[n], synth_16_fx[n], save_hb_synth_16_fx, bwe_exc_extended_fx[n], voice_factors_fx[n], old_syn_12k8_16k_fx[n], sharpFlag[n], pitch_buf_fx[n], &unbits[n], &sid_bw[n], hStereoTD, tdm_lsfQ_PCh_fx, use_cldfb_for_dft, last_element_mode, last_element_brate, flag_sec_CNA, nchan_out, hStereoCng, read_sid_info ) ), IVAS_ERR_OK ) ) #else IF( NE_32( ( error = acelp_core_dec_fx( st, output_16_fx[n], synth_16_fx[n], save_hb_synth_16_fx, bwe_exc_extended_fx[n], voice_factors_fx[n], old_syn_12k8_16k_fx_16, sharpFlag[n], pitch_buf_fx[n], &unbits[n], &sid_bw[n], hStereoTD, tdm_lsfQ_PCh_fx, use_cldfb_for_dft, last_element_mode, last_element_brate, flag_sec_CNA, nchan_out, hStereoCng, read_sid_info ) ), IVAS_ERR_OK ) ) #endif @@ -579,17 +580,15 @@ ivas_error ivas_core_dec_fx( hSCE->q_save_hb_synth_fx = Q11; move16(); } +#ifndef HARM_CORE_SW #ifdef FIX_2290_COPY_OF_UNINIT_DATA IF( st->hBWE_FD != NULL ) { -#ifdef HARM_CORE_SW - Copy_Scale_sig_16_32_DEPREC( old_syn_12k8_16k_fx_16[n], old_syn_12k8_16k_fx[n], st->L_frame, Q11 - ( -Q1 ) ); // Q(11 - (-1)) -#else Copy_Scale_sig_16_32_DEPREC( old_syn_12k8_16k_fx_16, old_syn_12k8_16k_fx[n], st->L_frame, Q11 - ( -Q1 ) ); // Q(11 - (-1)) -#endif } #else Copy_Scale_sig_16_32_DEPREC( old_syn_12k8_16k_fx_16, old_syn_12k8_16k_fx[n], L_FRAME16k, Q11 - ( -Q1 ) ); // Q(11 - (-1)) +#endif #endif } @@ -962,7 +961,7 @@ ivas_error ivas_core_dec_fx( *---------------------------------------------------------------------*/ #ifdef HARM_CORE_SW - bw_switching_pre_proc_fx( st, last_element_brate, nchan_out, old_syn_12k8_16k_fx_16[n], old_syn_12k8_16k_fx[n] ); + bw_switching_pre_proc_fx( st, last_element_brate, nchan_out, old_syn_12k8_16k_fx[n] ); #else ivas_bw_switching_pre_proc_fx( st, last_element_brate, nchan_out, old_syn_12k8_16k_fx[n], old_syn_fx, q_audio ); #endif diff --git a/lib_dec/swb_tbe_dec_fx.c b/lib_dec/swb_tbe_dec_fx.c index c61e4ddf3..f3f85d5cc 100644 --- a/lib_dec/swb_tbe_dec_fx.c +++ b/lib_dec/swb_tbe_dec_fx.c @@ -5473,11 +5473,15 @@ void ivas_swb_tbe_dec_fx( STEREO_ICBWE_DEC_HANDLE hStereoICBWE, /* i/o: IC-BWE state structure */ const Word32 *bwe_exc_extended_fx, /* i : bandwidth extended excitation : Q_exc */ Word16 Q_exc, - const Word16 voice_factors_fx[], /* i : voicing factors : Q15 */ + const Word16 voice_factors_fx[], /* i : voicing factors : Q15 */ +#ifdef FIX_2290_COPY_OF_UNINIT_DATA + const Word16 old_syn_12k8_16k_fx16[], /* i : low band synthesis : old_syn_fx */ +#else const Word32 old_syn_12k8_16k_fx[], /* i : low band synthesis : old_syn_fx */ - Word16 *White_exc16k_fx, /* o : shaped white excitation for the FB TBE : Q_white_exc*/ - Word32 *synth_fx, /* o : SHB synthesis/final synthesis : Qx */ - Word16 *pitch_buf_fx, /* i : Q6 */ +#endif + Word16 *White_exc16k_fx, /* o : shaped white excitation for the FB TBE : Q_white_exc*/ + Word32 *synth_fx, /* o : SHB synthesis/final synthesis : Qx */ + Word16 *pitch_buf_fx, /* i : Q6 */ Word16 *Q_white_exc ) { Word16 i, j, cnt, n; @@ -5545,6 +5549,11 @@ void ivas_swb_tbe_dec_fx( hBWE_TD = st->hBWE_TD; +#ifdef FIX_2290_COPY_OF_UNINIT_DATA + Word32 old_syn_12k8_16k_fx[L_FRAME16k]; + Copy_Scale_sig_16_32_DEPREC( old_syn_12k8_16k_fx16, old_syn_12k8_16k_fx, st->L_frame, Q11 - ( -Q1 ) ); // Q(11 - (-1)) +#endif + /* initializations */ GainFrame_fx = 0; move32(); -- GitLab From cd43a380df66453efddc115589636ee7d9b74629 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 12 Jan 2026 09:00:20 +0100 Subject: [PATCH 08/18] clang-format --- lib_dec/core_switching_dec_fx.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib_dec/core_switching_dec_fx.c b/lib_dec/core_switching_dec_fx.c index 98c38171d..b07c9ac6b 100644 --- a/lib_dec/core_switching_dec_fx.c +++ b/lib_dec/core_switching_dec_fx.c @@ -17,6 +17,7 @@ *---------------------------------------------------------------------*/ static void smoothTransitionDtxToTcx_fx( Word16 synth[], const Word16 output_frame, const Word16 delay_comp ); + static void core_switch_lb_upsamp_fx( Decoder_State *st, Word32 *output ); #else @@ -191,8 +192,8 @@ void bw_switching_pre_proc_fx( const Word16 nchan_out, /* i : number of output channels */ const Word16 *old_syn_12k8_16k_fx /* i : ACELP core synthesis at 12.8kHz or 16kHz Qx*/ #else - const Word16 *old_syn_12k8_16k_fx, /* i : ACELP core synthesis at 12.8kHz or 16kHz Qx*/ - Decoder_State *st_fx /* i/o: decoder state structure */ + const Word16 *old_syn_12k8_16k_fx, /* i : ACELP core synthesis at 12.8kHz or 16kHz Qx*/ + Decoder_State *st_fx /* i/o: decoder state structure */ #endif ) { @@ -1303,7 +1304,7 @@ ivas_error core_switching_post_dec_fx( ivas_error core_switching_post_dec_ivas_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ Word16 *synth, /* i/o: output synthesis Qsynth*/ - Word32 *output_fx, /* i/o: LB synth/upsampled LB synth Q4*/ + Word32 *output_fx, /* i/o: LB synth/upsampled LB synth Q4*/ Word16 output_mem_fx[], /* i : OLA memory from last TCX/HQ frame Qx*/ const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo Q0*/ const Word16 output_frame, /* i : frame length Q0*/ -- GitLab From a310704f2f866876a815e8b58f14eda23bc0ed2b Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 12 Jan 2026 10:02:29 +0100 Subject: [PATCH 09/18] HARM_CORE_SW, decoder step 4 (core_switching_post_dec) --- lib_dec/core_switching_dec_fx.c | 78 +++++++++++++++++++++++---------- 1 file changed, 55 insertions(+), 23 deletions(-) diff --git a/lib_dec/core_switching_dec_fx.c b/lib_dec/core_switching_dec_fx.c index b07c9ac6b..2a1518500 100644 --- a/lib_dec/core_switching_dec_fx.c +++ b/lib_dec/core_switching_dec_fx.c @@ -1348,10 +1348,22 @@ ivas_error core_switching_post_dec_ivas_fx( test(); IF( st_fx->core == ACELP_CORE && st_fx->bfi && hHQ_core != NULL && !st_fx->con_tcx ) { - if ( ( error = acelp_core_switch_dec_bfi_ivas_fx( st_fx, hHQ_core->fer_samples_fx, st_fx->coder_type ) ) != IVAS_ERR_OK ) +#ifdef HARM_CORE_SW + IF( EQ_16( st_fx->element_mode, EVS_MONO ) ) { - return error; - } /*the output at Q0*/ + IF( ( error = acelp_core_switch_dec_bfi_fx( st_fx, hHQ_core->fer_samples_fx, st_fx->coder_type ) ) != IVAS_ERR_OK ) + { + return error; + } /*the output at Q0*/ + } + ELSE +#endif + { + IF( ( error = acelp_core_switch_dec_bfi_ivas_fx( st_fx, hHQ_core->fer_samples_fx, st_fx->coder_type ) ) != IVAS_ERR_OK ) + { + return error; + } /*the output at Q0*/ + } } /* set multiplication factor according to the sampling rate */ @@ -1360,14 +1372,14 @@ ivas_error core_switching_post_dec_ivas_fx( delta = 1; move16(); - IF( GE_16( output_frame, L_FRAME16k ) ) + if ( GE_16( output_frame, L_FRAME16k ) ) { delta = shr( Fs_kHz, 3 ); } /* set delay compensation between HQ synthesis and ACELP synthesis */ delay_comp = i_mult2( delta, HQ_DELAY_COMP ); /* Q0 */ - /*needed to add more condition in if*/ + test(); test(); test(); @@ -1384,11 +1396,13 @@ ivas_error core_switching_post_dec_ivas_fx( { st_fx->use_acelp_preq = 0; move16(); - /* rescaling to the min exp of the 2 */ - /* Qtmp=s_min(*Qsynth,st_fx->Q_old_postdec); - Scale_sig(synth, output_frame, sub(Qtmp,*Qsynth)); - Scale_sig(st_fx->delay_buf_out_fx, delay_comp, sub(Qtmp,st_fx->Q_old_postdec));*/ + +#ifdef HARM_CORE_SW + test(); + if ( EQ_16( st_fx->element_mode, EVS_MONO ) && st_fx->hBWE_FD != NULL ) +#else IF( st_fx->hBWE_FD != NULL ) +#endif { hBWE_FD->mem_deemph_old_syn_fx = 0; move16(); @@ -1417,27 +1431,34 @@ ivas_error core_switching_post_dec_ivas_fx( move16(); } } + /* delay HQ synthesis to synchronize with ACELP synthesis */ /* rescaling to the min exp of the 2 */ - Word16 NonZero = 1; - move16(); - FOR( i = 0; i < delay_comp; i++ ) +#ifdef HARM_CORE_SW + IF( NE_16( st_fx->element_mode, EVS_MONO ) ) +#endif { - IF( st_fx->delay_buf_out_fx[i] != 0 ) + Word16 NonZero = 1; + move16(); + FOR( i = 0; i < delay_comp; i++ ) + { + IF( st_fx->delay_buf_out_fx[i] != 0 ) + { + NonZero = 0; + move16(); + break; + } + } + test(); + IF( hHQ_core->Q_old_postdec >= 0 || EQ_16( NonZero, 1 ) ) { - NonZero = 0; + Scale_sig( st_fx->delay_buf_out_fx, delay_comp, negate( hHQ_core->Q_old_postdec ) ); /* Q0 */ + hHQ_core->Q_old_postdec = 0; move16(); - break; } - } - test(); - IF( hHQ_core->Q_old_postdec >= 0 || EQ_16( NonZero, 1 ) ) - { - Scale_sig( st_fx->delay_buf_out_fx, delay_comp, negate( hHQ_core->Q_old_postdec ) ); /* Q0 */ - hHQ_core->Q_old_postdec = 0; move16(); + } - move16(); Qtmp = s_min( *Qsynth, hHQ_core->Q_old_postdec ); Scale_sig( synth, output_frame, sub( Qtmp, *Qsynth ) ); /* Qtmp */ *Qsynth = Qtmp; @@ -1602,7 +1623,6 @@ ivas_error core_switching_post_dec_ivas_fx( } ELSE IF( st_fx->element_mode != EVS_MONO ) { - /*needed to be filled with ivas specific code*/ /* Reset memories of CLDFBs */ IF( st_fx->cldfbAna != NULL ) { @@ -1650,6 +1670,7 @@ ivas_error core_switching_post_dec_ivas_fx( move16(); } } + IF( st_fx->hBWE_TD != NULL ) { hBWE_TD->bwe_non_lin_prev_scale_fx = L_deposit_l( 0 ); @@ -1768,6 +1789,17 @@ ivas_error core_switching_post_dec_ivas_fx( hHQ_core->oldHqVoicing = 0; move16(); } + +#ifdef HARM_CORE_SW + IF( EQ_16( st_fx->element_mode, EVS_MONO ) ) + { + set16_fx( hHQ_core->prev_SWB_peak_pos_fx, 0, SPT_SHORTEN_SBNUM ); + hHQ_core->prev_frm_hfe2 = 0; + move16(); + hHQ_core->prev_stab_hfe2 = 0; + move16(); + } +#endif } } ELSE -- GitLab From 30d03cfeb32a60b5ae4495c6730ff5f20379ab13 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 12 Jan 2026 10:29:47 +0100 Subject: [PATCH 10/18] HARM_CORE_SW, fix --- lib_dec/core_switching_dec_fx.c | 10 ++++++++-- lib_dec/evs_dec_fx.c | 4 ++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib_dec/core_switching_dec_fx.c b/lib_dec/core_switching_dec_fx.c index 2a1518500..522f69588 100644 --- a/lib_dec/core_switching_dec_fx.c +++ b/lib_dec/core_switching_dec_fx.c @@ -1457,7 +1457,6 @@ ivas_error core_switching_post_dec_ivas_fx( move16(); } move16(); - } Qtmp = s_min( *Qsynth, hHQ_core->Q_old_postdec ); Scale_sig( synth, output_frame, sub( Qtmp, *Qsynth ) ); /* Qtmp */ @@ -2339,7 +2338,7 @@ ivas_error core_switching_pre_dec_ivas_fx( test(); IF( hBWE_TD != NULL && ( st->last_core != ACELP_CORE ) ) { - hBWE_TD->prev_hb_synth_fx_exp = 31; + hBWE_TD->prev_hb_synth_fx_exp = Q31; move16(); /* reset BWE memories */ set16_fx( hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2 ); /* Q_exc */ @@ -2693,6 +2692,13 @@ ivas_error core_switching_pre_dec_ivas_fx( set16_fx( st->hFdCngDec->hFdCngCom->olapBufferAna_fx, 0, FFTLEN ); set16_fx( st->agc_mem_fx, 0, 2 ); } + +#ifdef HARM_CORE_SW + IF( EQ_16( st->element_mode, EVS_MONO ) ) + { + set16_fx( st->agc_mem_fx, 0, 2 ); + } +#endif st->mem_deemph_fx = 0; move16(); IF( !st->last_con_tcx ) diff --git a/lib_dec/evs_dec_fx.c b/lib_dec/evs_dec_fx.c index 6686099b8..0b59cccaa 100644 --- a/lib_dec/evs_dec_fx.c +++ b/lib_dec/evs_dec_fx.c @@ -350,7 +350,11 @@ ivas_error evs_dec_fx( * Postprocessing for ACELP/HQ core switching *---------------------------------------------------------------------*/ +#ifdef HARM_CORE_SW + if ( ( error = core_switching_post_dec_ivas_fx( st_fx, synth_fx, NULL, NULL, 0, output_frame, core_switching_flag, 0, 1, EVS_MONO, &Qpostd ) ) != IVAS_ERR_OK ) +#else if ( ( error = core_switching_post_dec_fx( st_fx, synth_fx, output_frame, core_switching_flag, EVS_MONO, &Qpostd ) ) != IVAS_ERR_OK ) +#endif { return error; } -- GitLab From fe38daf81e7c6fe4461e6e8aa4fb09c6ff14b4c8 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 12 Jan 2026 13:00:12 +0100 Subject: [PATCH 11/18] HARM_CORE_SW, decoder step 5 (core_switching_post_dec) --- lib_com/prot_fx.h | 2 ++ lib_dec/core_switching_dec_fx.c | 7 ++++++- lib_dec/evs_dec_fx.c | 2 +- lib_dec/ivas_core_dec_fx.c | 4 ++++ lib_dec/ivas_mct_dec_fx.c | 5 +++++ 5 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 7cb2ef504..c4623fc1c 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -7830,6 +7830,7 @@ ivas_error core_switching_pre_dec_fx( ); ivas_error core_switching_post_dec_fx( +#ifndef HARM_CORE_SW Decoder_State *st_fx, /* i/o: decoder state structure */ Word16 *synth, /* i/o: output synthesis Qsynth Qsynth*/ const Word16 output_frame, /* i : frame length Q0*/ @@ -7839,6 +7840,7 @@ ivas_error core_switching_post_dec_fx( ); ivas_error core_switching_post_dec_ivas_fx( +#endif Decoder_State *st_fx, /* i/o: decoder state structure */ Word16 *synth, /* i/o: output synthesis Qsynth*/ Word32 *output_fx, /* i/o: LB synth/upsampled LB synth Q4*/ diff --git a/lib_dec/core_switching_dec_fx.c b/lib_dec/core_switching_dec_fx.c index 522f69588..187cb1d18 100644 --- a/lib_dec/core_switching_dec_fx.c +++ b/lib_dec/core_switching_dec_fx.c @@ -911,7 +911,7 @@ ivas_error core_switching_pre_dec_fx( return error; } -#endif + /*---------------------------------------------------------------------* * core_switching_post_dec() @@ -1300,8 +1300,13 @@ ivas_error core_switching_post_dec_fx( return error; } +#endif +#ifdef HARM_CORE_SW +ivas_error core_switching_post_dec_fx( +#else ivas_error core_switching_post_dec_ivas_fx( +#endif Decoder_State *st_fx, /* i/o: decoder state structure */ Word16 *synth, /* i/o: output synthesis Qsynth*/ Word32 *output_fx, /* i/o: LB synth/upsampled LB synth Q4*/ diff --git a/lib_dec/evs_dec_fx.c b/lib_dec/evs_dec_fx.c index 0b59cccaa..7042f2519 100644 --- a/lib_dec/evs_dec_fx.c +++ b/lib_dec/evs_dec_fx.c @@ -351,7 +351,7 @@ ivas_error evs_dec_fx( *---------------------------------------------------------------------*/ #ifdef HARM_CORE_SW - if ( ( error = core_switching_post_dec_ivas_fx( st_fx, synth_fx, NULL, NULL, 0, output_frame, core_switching_flag, 0, 1, EVS_MONO, &Qpostd ) ) != IVAS_ERR_OK ) + if ( ( error = core_switching_post_dec_fx( st_fx, synth_fx, NULL, NULL, 0, output_frame, core_switching_flag, 0, 1, EVS_MONO, &Qpostd ) ) != IVAS_ERR_OK ) #else if ( ( error = core_switching_post_dec_fx( st_fx, synth_fx, output_frame, core_switching_flag, EVS_MONO, &Qpostd ) ) != IVAS_ERR_OK ) #endif diff --git a/lib_dec/ivas_core_dec_fx.c b/lib_dec/ivas_core_dec_fx.c index cbf005b95..d449921ba 100644 --- a/lib_dec/ivas_core_dec_fx.c +++ b/lib_dec/ivas_core_dec_fx.c @@ -930,7 +930,11 @@ ivas_error ivas_core_dec_fx( Copy_Scale_sig_16_32_no_sat( synth_16_fx[n], hSCE->save_synth_fx, output_frame, sub( hSCE->q_save_synth_fx, Q_synth ) ); // q_save_synth_fx } +#ifdef HARM_CORE_SW + IF( NE_32( ( error = core_switching_post_dec_fx( st, synth_16_fx[n], output_32_fx[n], p_output_mem_16, use_cldfb_for_dft, output_frame, 0 /*core_switching_flag*/, sba_dirac_stereo_flag, nchan_out, last_element_mode, &Q_synth ) ), IVAS_ERR_OK ) ) +#else IF( NE_32( ( error = core_switching_post_dec_ivas_fx( st, synth_16_fx[n], output_32_fx[n], p_output_mem_16, use_cldfb_for_dft, output_frame, 0 /*core_switching_flag*/, sba_dirac_stereo_flag, nchan_out, last_element_mode, &Q_synth ) ), IVAS_ERR_OK ) ) +#endif { return error; } diff --git a/lib_dec/ivas_mct_dec_fx.c b/lib_dec/ivas_mct_dec_fx.c index 5c5b0ac52..4f06158da 100644 --- a/lib_dec/ivas_mct_dec_fx.c +++ b/lib_dec/ivas_mct_dec_fx.c @@ -363,7 +363,12 @@ ivas_error ivas_mct_dec_fx( { dirac_stereo_flag = 0; } + +#ifdef HARM_CORE_SW + IF( NE_32( ( error = core_switching_post_dec_fx( sts[n], synth_fx[n], output_fx[( cpe_id * CPE_CHANNELS ) + n], output_mem_fx, 0, output_frame, 0 /*core_switching_flag*/, dirac_stereo_flag, -1, hCPE->last_element_mode, &Q_synth ) ), IVAS_ERR_OK ) ) +#else IF( NE_32( ( error = core_switching_post_dec_ivas_fx( sts[n], synth_fx[n], output_fx[( cpe_id * CPE_CHANNELS ) + n], output_mem_fx, 0, output_frame, 0 /*core_switching_flag*/, dirac_stereo_flag, -1, hCPE->last_element_mode, &Q_synth ) ), IVAS_ERR_OK ) ) +#endif { return error; } -- GitLab From 0239404206523add62117dccbd41c4196b46cd52 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 12 Jan 2026 13:08:43 +0100 Subject: [PATCH 12/18] HARM_CORE_SW, decoder step 5 (acelp_core_switch_dec_bfi_fx) --- lib_com/prot_fx.h | 3 +- lib_dec/acelp_core_switch_dec_fx.c | 101 +++++++++++++++++++++-------- lib_dec/core_switching_dec_fx.c | 18 ++--- 3 files changed, 82 insertions(+), 40 deletions(-) diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index c4623fc1c..035885800 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -7197,12 +7197,13 @@ ivas_error acelp_core_switch_dec_bfi_fx( const Word16 coder_type /* i : coder type */ ); +#ifndef HARM_CORE_SW ivas_error acelp_core_switch_dec_bfi_ivas_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ Word16 synth_out[], /* o : synthesis Q_syn */ const Word16 coder_type /* i : coder type */ ); - +#endif void pred_lt4( const Word16 excI[], /* in : excitation buffer Q_exc*/ Word16 excO[], /* out: excitation buffer Q_exc*/ diff --git a/lib_dec/acelp_core_switch_dec_fx.c b/lib_dec/acelp_core_switch_dec_fx.c index 049626e59..22d63d4b0 100644 --- a/lib_dec/acelp_core_switch_dec_fx.c +++ b/lib_dec/acelp_core_switch_dec_fx.c @@ -351,7 +351,7 @@ ivas_error acelp_core_switch_dec_fx( * * ACELP core decoder in the first ACELP->HQ switching frame in case of BAD frame *-------------------------------------------------------------------*/ - +#ifndef HARM_CORE_SW ivas_error acelp_core_switch_dec_bfi_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ Word16 synth_out[], /* o : synthesis Q_syn */ @@ -594,8 +594,13 @@ ivas_error acelp_core_switch_dec_bfi_fx( return error; } +#endif +#ifdef HARM_CORE_SW +ivas_error acelp_core_switch_dec_bfi_fx( +#else ivas_error acelp_core_switch_dec_bfi_ivas_fx( +#endif Decoder_State *st_fx, /* i/o: decoder state structure */ Word16 synth_out[], /* o : synthesis Q_syn */ const Word16 coder_type /* i : coder type */ @@ -647,6 +652,7 @@ ivas_error acelp_core_switch_dec_bfi_ivas_fx( /*----------------------------------------------------------------* * Initialization *----------------------------------------------------------------*/ + Q_exc = st_fx->Q_exc; move16(); st_fx->bpf_off = 1; @@ -757,11 +763,17 @@ ivas_error acelp_core_switch_dec_bfi_ivas_fx( /*------------------------------------------------------------------* * Synthesis *-----------------------------------------------------------------*/ + Prev_Q_syn_r = st_fx->Q_syn; move16(); 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 ); - Scale_sig( st_fx->mem_syn_r, L_SYN_MEM, sub( st_fx->Q_syn, Prev_Q_syn_r ) ); // Q_syn +#ifdef HARM_CORE_SW + IF( NE_16( st_fx->element_mode, EVS_MONO ) ) +#endif + { + Scale_sig( st_fx->mem_syn_r, L_SYN_MEM, sub( st_fx->Q_syn, Prev_Q_syn_r ) ); // Q_syn + } 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 ); @@ -772,6 +784,7 @@ ivas_error acelp_core_switch_dec_bfi_ivas_fx( /*------------------------------------------------------------------* * Perform fixed deemphasis through 1/(1 - g*z^-1) *-----------------------------------------------------------------*/ + tmp1[0] = st_fx->mem_deemph_fx; move16(); /*if in acelp_core_dec_fx deemph_fx is used*/ /*tmp1 = shr(st_fx->mem_deemph_fx, sub(st_fx->Q_syn,1)); if in acelp_core_dec_fx Deemph2 is used*/ @@ -810,36 +823,70 @@ ivas_error acelp_core_switch_dec_bfi_ivas_fx( Copy( tmp6, hBPF->vibrato_hist, L_TRACK_HIST ); hBPF->psf_att_fx = tmp7; move16(); + /*----------------------------------------------------------------* * Resamping to the output sampling frequency *----------------------------------------------------------------*/ - /* CLDFB analysis of the synthesis at internal sampling rate */ - Qtmp = sub( 11, st_fx->Q_syn ); - Copy_Scale_sig_16_32_no_sat( syn, syn32, L_FRAME16k, Qtmp ); // Q(11) - IF( NE_32( ( error = cldfb_save_memory_ivas_fx( st_fx->cldfbAna ) ), IVAS_ERR_OK ) ) - { - return error; - } - /*cldfbAnalysis_fx( st_fx->cldfbAna, realBuffer, imagBuffer, &scaleFactor, syn, - negate(st_fx->Q_syn), CLDFB_NO_COL_MAX_SWITCH_BFI, workBuffer);*/ - cldfbAnalysis_ivas_fx( syn32, realBuffer, imagBuffer, shr( st_fx->L_frame, 1 ), st_fx->cldfbAna ); - cldfb_restore_memory_ivas_fx( st_fx->cldfbAna ); - /* CLDFB synthesis of the combined signal */ - IF( NE_32( ( error = cldfb_save_memory_ivas_fx( st_fx->cldfbSyn ) ), IVAS_ERR_OK ) ) +#ifdef HARM_CORE_SW + IF( NE_16( st_fx->element_mode, EVS_MONO ) ) { - return error; + CLDFB_SCALE_FACTOR scaleFactor; + Word32 workBuffer[128 * 3]; + + IF( NE_32( ( error = cldfb_save_memory( st_fx->cldfbAna ) ), IVAS_ERR_OK ) ) + { + return error; + } + cldfbAnalysis_fx( st_fx->cldfbAna, realBuffer, imagBuffer, &scaleFactor, syn, negate( st_fx->Q_syn ), CLDFB_NO_COL_MAX_SWITCH_BFI, workBuffer ); + cldfb_restore_memory( st_fx->cldfbAna ); + + scaleFactor.hb_scale = scaleFactor.lb_scale; + move16(); + + /* CLDFB synthesis of the combined signal */ + IF( NE_32( ( error = cldfb_save_memory( st_fx->cldfbSyn ) ), IVAS_ERR_OK ) ) + { + return error; + } + cldfbSynthesis_fx( st_fx->cldfbSyn, realBuffer, imagBuffer, &scaleFactor, synth_out, + negate( st_fx->Q_syn ), CLDFB_NO_COL_MAX_SWITCH_BFI, workBuffer ); + + /* output to Q0 */ + Scale_sig( synth_out, L_FRAME48k, negate( st_fx->Q_syn ) ); // Q0 + + cldfb_restore_memory( st_fx->cldfbSyn ); } - /*cldfbSynthesis_fx( st_fx->cldfbSyn, realBuffer, imagBuffer, &scaleFactor, synth_out, - negate(st_fx->Q_syn), CLDFB_NO_COL_MAX_SWITCH_BFI, workBuffer );*/ - Word16 out_len = extract_l( Mpy_32_16_1( st_fx->output_Fs, 328 ) ); - cldfbSynthesis_ivas_fx( realBuffer, imagBuffer, synth32, out_len, -1, 0, st_fx->cldfbSyn ); - Copy_Scale_sig_32_16( synth32, synth_out, out_len, -4 ); + ELSE +#endif + { + /* CLDFB analysis of the synthesis at internal sampling rate */ + Qtmp = sub( 11, st_fx->Q_syn ); + Copy_Scale_sig_16_32_no_sat( syn, syn32, L_FRAME16k, Qtmp ); // Q(11) + IF( NE_32( ( error = cldfb_save_memory_ivas_fx( st_fx->cldfbAna ) ), IVAS_ERR_OK ) ) + { + return error; + } + /*cldfbAnalysis_fx( st_fx->cldfbAna, realBuffer, imagBuffer, &scaleFactor, syn, + negate(st_fx->Q_syn), CLDFB_NO_COL_MAX_SWITCH_BFI, workBuffer);*/ + cldfbAnalysis_ivas_fx( syn32, realBuffer, imagBuffer, shr( st_fx->L_frame, 1 ), st_fx->cldfbAna ); + cldfb_restore_memory_ivas_fx( st_fx->cldfbAna ); + /* CLDFB synthesis of the combined signal */ + IF( NE_32( ( error = cldfb_save_memory_ivas_fx( st_fx->cldfbSyn ) ), IVAS_ERR_OK ) ) + { + return error; + } + /*cldfbSynthesis_fx( st_fx->cldfbSyn, realBuffer, imagBuffer, &scaleFactor, synth_out, + negate(st_fx->Q_syn), CLDFB_NO_COL_MAX_SWITCH_BFI, workBuffer );*/ + Word16 out_len = extract_l( Mpy_32_16_1( st_fx->output_Fs, 328 ) ); + cldfbSynthesis_ivas_fx( realBuffer, imagBuffer, synth32, out_len, -1, 0, st_fx->cldfbSyn ); + Copy_Scale_sig_32_16( synth32, synth_out, out_len, -4 ); - // Scale_sig( synth_out, L_FRAME48k, negate( st_fx->Q_syn ) ); + // Scale_sig( synth_out, L_FRAME48k, negate( st_fx->Q_syn ) ); - cldfb_restore_memory_ivas_fx( st_fx->cldfbSyn ); + cldfb_restore_memory_ivas_fx( st_fx->cldfbSyn ); + } return error; } @@ -854,8 +901,8 @@ static void decod_gen_voic_core_switch_fx( Decoder_State *st_fx, /* i/o: decoder static memory */ const Word16 L_frame, /* i : length of the frame */ const Word16 sharpFlag, /* i : flag for formant sharpening */ - const Word16 *Aq, /* i : LP filter coefficient Q_12 */ - Word16 *exc, /* i/o: adapt. excitation exc Q_exc */ + const Word16 *Aq, /* i : LP filter coefficient Q_12 */ + Word16 *exc, /* i/o: adapt. excitation exc Q_exc */ const Word32 core_brate, /* i : switching frame bit-rate */ Word16 *Q_exc ) { @@ -873,7 +920,6 @@ static void decod_gen_voic_core_switch_fx( GSC_DEC_HANDLE hGSCDec; hGSCDec = st_fx->hGSCDec; - /*----------------------------------------------------------------------* * initializations *----------------------------------------------------------------------*/ @@ -902,6 +948,7 @@ static void decod_gen_voic_core_switch_fx( /*--------------------------------------------------------------* * Find the adaptive codebook vector. *--------------------------------------------------------------*/ + IF( st_fx->element_mode != EVS_MONO ) { pred_lt4_ivas_fx( &exc[0], &exc[0], T0, T0_frac, L_SUBFR + 1, L_pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); @@ -910,6 +957,7 @@ static void decod_gen_voic_core_switch_fx( { pred_lt4( &exc[0], &exc[0], T0, T0_frac, L_SUBFR + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); } + /*--------------------------------------------------------------* * LP filtering of the adaptive excitation *--------------------------------------------------------------*/ @@ -977,6 +1025,7 @@ static void decod_gen_voic_core_switch_fx( /*-----------------------------------------------------------------* * long term prediction on the 2nd sub frame *-----------------------------------------------------------------*/ + IF( st_fx->element_mode != EVS_MONO ) { pred_lt4_ivas_fx( &exc[L_SUBFR], &exc[L_SUBFR], T0, T0_frac, L_SUBFR + 1, L_pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); diff --git a/lib_dec/core_switching_dec_fx.c b/lib_dec/core_switching_dec_fx.c index 187cb1d18..3c64c6e16 100644 --- a/lib_dec/core_switching_dec_fx.c +++ b/lib_dec/core_switching_dec_fx.c @@ -1354,21 +1354,13 @@ ivas_error core_switching_post_dec_ivas_fx( IF( st_fx->core == ACELP_CORE && st_fx->bfi && hHQ_core != NULL && !st_fx->con_tcx ) { #ifdef HARM_CORE_SW - IF( EQ_16( st_fx->element_mode, EVS_MONO ) ) - { - IF( ( error = acelp_core_switch_dec_bfi_fx( st_fx, hHQ_core->fer_samples_fx, st_fx->coder_type ) ) != IVAS_ERR_OK ) - { - return error; - } /*the output at Q0*/ - } - ELSE + IF( ( error = acelp_core_switch_dec_bfi_fx( st_fx, hHQ_core->fer_samples_fx, st_fx->coder_type ) ) != IVAS_ERR_OK ) +#else + IF( ( error = acelp_core_switch_dec_bfi_ivas_fx( st_fx, hHQ_core->fer_samples_fx, st_fx->coder_type ) ) != IVAS_ERR_OK ) #endif { - IF( ( error = acelp_core_switch_dec_bfi_ivas_fx( st_fx, hHQ_core->fer_samples_fx, st_fx->coder_type ) ) != IVAS_ERR_OK ) - { - return error; - } /*the output at Q0*/ - } + return error; + } /*the output at Q0*/ } /* set multiplication factor according to the sampling rate */ -- GitLab From 46d3f18dd364806ecd750e6378532bea5ac32c51 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 12 Jan 2026 14:03:27 +0100 Subject: [PATCH 13/18] HARM_CORE_SW, decoder step 6 (core_switching_post_enc) --- lib_dec/acelp_core_switch_dec_fx.c | 2 +- lib_enc/core_switching_enc_fx.c | 31 ++++++++++++++++++++++++++---- lib_enc/ivas_core_enc_fx.c | 4 ++++ lib_enc/prot_fx_enc.h | 4 ++-- 4 files changed, 34 insertions(+), 7 deletions(-) diff --git a/lib_dec/acelp_core_switch_dec_fx.c b/lib_dec/acelp_core_switch_dec_fx.c index 22d63d4b0..5447f954c 100644 --- a/lib_dec/acelp_core_switch_dec_fx.c +++ b/lib_dec/acelp_core_switch_dec_fx.c @@ -829,7 +829,7 @@ ivas_error acelp_core_switch_dec_bfi_ivas_fx( *----------------------------------------------------------------*/ #ifdef HARM_CORE_SW - IF( NE_16( st_fx->element_mode, EVS_MONO ) ) + IF( EQ_16( st_fx->element_mode, EVS_MONO ) ) { CLDFB_SCALE_FACTOR scaleFactor; Word32 workBuffer[128 * 3]; diff --git a/lib_enc/core_switching_enc_fx.c b/lib_enc/core_switching_enc_fx.c index 2d44ba36a..523672d4a 100644 --- a/lib_enc/core_switching_enc_fx.c +++ b/lib_enc/core_switching_enc_fx.c @@ -386,13 +386,14 @@ void core_switching_pre_enc_fx( * * Postprocessing for ACELP/HQ core switching *---------------------------------------------------------------------*/ + void core_switching_post_enc_fx( Encoder_State *st_fx, /* i/o: encoder state structure */ const Word16 old_inp_12k8[], /* i : input signal @12.8 kHz Qinp */ const Word16 old_inp_16k[], /* i : input signal @16 kHz Qinp */ const Word16 A[], /* i : unquant. LP filter coefs. (Q12) */ - Word16 Qshift, - Word16 Q_new, + const Word16 Qshift, + const Word16 Q_new, const Word16 Qsp, /* i/o : Q from acelp synthsis */ Word16 *Qmus /* i/o : Q from mdct synthsis / Q of output synthesis */ ) @@ -419,8 +420,14 @@ void core_switching_post_enc_fx( } ELSE { - *Qmus = Qsp; /* Write Qout */ - move16(); +#ifdef HARM_CORE_SW + IF( EQ_16( st_fx->element_mode, EVS_MONO ) ) +#endif + { + *Qmus = Qsp; /* Write Qout */ + move16(); + } + IF( hBWE_TD == NULL ) { return; @@ -483,6 +490,7 @@ void core_switching_post_enc_fx( { TBEreset_enc_fx( st_fx->hBWE_TD, st_fx->last_core, st_fx->bwidth ); } + test(); test(); test(); @@ -493,6 +501,18 @@ void core_switching_post_enc_fx( hBWE_TD->fb_tbe_demph_fx = 0; fb_tbe_reset_enc_fx( hBWE_TD->elliptic_bpf_2_48k_mem_fx, &hBWE_TD->prev_fb_energy_fx, hBWE_TD->elliptic_bpf_2_48k_mem_fx_Q, &hBWE_TD->prev_fb_energy_fx_Q ); } + +#ifdef HARM_CORE_SW + /* Fade towards init value for non HQ_CORE */ + test(); + IF( NE_16( st_fx->element_mode, EVS_MONO ) && st_fx->hHQ_core != NULL ) + { + st_fx->hHQ_core->crest_lp_fx = L_add( Mpy_32_32( HQ_CREST_FAC_SM_FX, st_fx->hHQ_core->crest_lp_fx ), Mpy_32_32( L_sub( ONE_IN_Q31, HQ_CREST_FAC_SM_FX ), L_shr( HQ_CREST_THRESHOLD_FX, sub( Q28, st_fx->hHQ_core->crest_lp_q ) ) ) ); /*crest_lp_q*/ + move32(); + st_fx->hHQ_core->crest_mod_lp_fx = L_add( Mpy_32_32( HQ_CREST_FAC_SM_FX, st_fx->hHQ_core->crest_mod_lp_fx ), Mpy_32_32( L_sub( ONE_IN_Q31, HQ_CREST_FAC_SM_FX ), L_shr( HQ_CREST_MOD_THRESHOLD_FX, sub( Q29, st_fx->hHQ_core->crest_mod_lp_q ) ) ) ); /*crest_mod_lp_q*/ + move32(); + } +#endif } return; @@ -1016,9 +1036,11 @@ void core_switching_pre_enc_ivas_fx( st_fx->EnergyLT_fx_exp = 30; move16(); /* Set to a High Exponent so it is 1^-30 */ } + /*---------------------------------------------------------------------* * band-width switching from WB -> SWB/FB *---------------------------------------------------------------------*/ + IF( st_fx->element_mode > EVS_MONO ) { IF( st_fx->bwidth_sw_cnt == 0 ) @@ -1045,6 +1067,7 @@ void core_switching_pre_enc_ivas_fx( return; } + /*---------------------------------------------------------------------* * core_switching_post_enc() * diff --git a/lib_enc/ivas_core_enc_fx.c b/lib_enc/ivas_core_enc_fx.c index c19ec47db..6d5988bbe 100644 --- a/lib_enc/ivas_core_enc_fx.c +++ b/lib_enc/ivas_core_enc_fx.c @@ -648,7 +648,11 @@ ivas_error ivas_core_enc_fx( *---------------------------------------------------------------------*/ #ifdef CLEANUP_ACELP_ENC +#ifdef HARM_CORE_SWaaa + core_switching_post_enc_fx( st, NULL, NULL, NULL, 0, 0, 0, NULL ); +#else core_switching_post_enc_ivas_fx( st ); +#endif #else core_switching_post_enc_ivas_fx( st, old_inp_12k8_fx[n], old_inp_16k_fx[n], A_fx[n], Q_new[n] ); #endif diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index e16ae844b..dd0c2e441 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -118,8 +118,8 @@ void core_switching_post_enc_fx( const Word16 inp12k8[], /* i : i signal @12.8 kHz Qinp*/ const Word16 inp16k[], /* i : i signal @16 kHz Qinp*/ const Word16 A[], /* i : unquant. LP filter coefs. (Q12) */ - Word16 Qshift, - Word16 Q_new, + const Word16 Qshift, + const Word16 Q_new, const Word16 Qsp, /* i/o : Q from acelp synthsis */ Word16 *Qmus /* i/o : Q from mdct synthsis / Q of output synthesis */ ); -- GitLab From c2e5c89cba9816b2cdbd6f712aef0f1d43f96a72 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 12 Jan 2026 14:14:40 +0100 Subject: [PATCH 14/18] clang-format --- lib_dec/acelp_core_switch_dec_fx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_dec/acelp_core_switch_dec_fx.c b/lib_dec/acelp_core_switch_dec_fx.c index 5447f954c..650f92ab1 100644 --- a/lib_dec/acelp_core_switch_dec_fx.c +++ b/lib_dec/acelp_core_switch_dec_fx.c @@ -859,7 +859,7 @@ ivas_error acelp_core_switch_dec_bfi_ivas_fx( } ELSE #endif - { + { /* CLDFB analysis of the synthesis at internal sampling rate */ Qtmp = sub( 11, st_fx->Q_syn ); Copy_Scale_sig_16_32_no_sat( syn, syn32, L_FRAME16k, Qtmp ); // Q(11) -- GitLab From 0f159366c394324463e76ff1f4d5f812d4573f8a Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 12 Jan 2026 16:51:55 +0100 Subject: [PATCH 15/18] HARM_CORE_SW, decoder step 7 (core_switching_pre_enc) --- lib_com/prot_fx.h | 3 +- lib_enc/amr_wb_enc_fx.c | 4 + lib_enc/core_switching_enc_fx.c | 126 +++++++++++++++++++++++++++++--- lib_enc/evs_enc_fx.c | 4 + lib_enc/ivas_core_enc_fx.c | 2 +- lib_enc/prot_fx_enc.h | 12 ++- 6 files changed, 134 insertions(+), 17 deletions(-) diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 035885800..b09bf6732 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -10945,6 +10945,7 @@ ivas_error IGF_Reconfig_fx( const Word16 rf_mode /* i : flag to signal the RF mode */ ); +#ifndef HARM_CORE_SW void core_switching_post_enc_ivas_fx( Encoder_State *st /* i/o: encoder state structure */ #ifndef CLEANUP_ACELP_ENC @@ -10955,7 +10956,7 @@ void core_switching_post_enc_ivas_fx( Word16 Q_new #endif ); - +#endif void residu_ivas_fx( const Word16 *a, /* i : LP filter coefficients Q31-a_exp*/ const Word16 a_exp, diff --git a/lib_enc/amr_wb_enc_fx.c b/lib_enc/amr_wb_enc_fx.c index 9b20100ba..5f7a13824 100644 --- a/lib_enc/amr_wb_enc_fx.c +++ b/lib_enc/amr_wb_enc_fx.c @@ -136,7 +136,11 @@ void amr_wb_enc_fx( /* Updates in case of HQ -> AMR-WB IO mode switching */ Q_new = 0; move16(); /* prevent compiler warning only*/ +#ifdef HARM_CORE_SW + core_switching_pre_enc_fx( st, NULL, 0, NULL, 0, 0, 0 ); +#else core_switching_pre_enc_fx( st, NULL, NULL, 0, 0 ); +#endif set16_fx( hf_gain_fx, 0, NB_SUBFR ); set16_fx( old_inp, 0, L_INP_12k8 ); diff --git a/lib_enc/core_switching_enc_fx.c b/lib_enc/core_switching_enc_fx.c index 523672d4a..beee43d5f 100644 --- a/lib_enc/core_switching_enc_fx.c +++ b/lib_enc/core_switching_enc_fx.c @@ -19,9 +19,15 @@ *---------------------------------------------------------------------*/ void core_switching_pre_enc_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word16 *old_inp_12k8, /* i : old input signal @12.8kHz Qx*/ - const Word16 *old_inp_16k, /* i : old input signal @16kHz Qx*/ + Encoder_State *st_fx, /* i/o: encoder state structure */ + const Word16 *old_inp_12k8, /* i : old input signal @12.8kHz Qx*/ +#ifdef HARM_CORE_SW + const Word16 q_old_inp_12k8, /* i : Q old input signal @12.8kHz */ +#endif + const Word16 *old_inp_16k, /* i : old input signal @16kHz Qx*/ +#ifdef HARM_CORE_SW + const Word16 q_old_inp_16k, /* i : Q old input signal @16kHz */ +#endif const Word16 active_cnt, /* i : active frame counter Q0*/ const Word16 last_element_mode /* i : last_element_mode Q0*/ ) @@ -112,7 +118,7 @@ void core_switching_pre_enc_fx( test(); test(); test(); - IF( EQ_16( st_fx->last_core, -1 ) && ( EQ_16( st_fx->core, HQ_CORE ) || EQ_16( st_fx->core, TCX_20_CORE ) || EQ_16( st_fx->core, TCX_10_CORE ) ) ) + if ( EQ_16( st_fx->last_core, -1 ) && ( EQ_16( st_fx->core, HQ_CORE ) || EQ_16( st_fx->core, TCX_20_CORE ) || EQ_16( st_fx->core, TCX_10_CORE ) ) ) { /* very first frame is HQ_CORE */ st_fx->last_core = HQ_CORE; @@ -237,7 +243,16 @@ void core_switching_pre_enc_fx( } Copy( st_fx->old_pitch_buf_fx + tmp16, st_fx->old_pitch_buf_fx, tmp16 ); /*Q6*/ - set16_fx( st_fx->old_pitch_buf_fx + tmp16, L_SUBFR, tmp16 ); +#ifdef HARM_CORE_SW + IF( NE_16( st_fx->element_mode, EVS_MONO ) ) + { + set16_fx( st_fx->old_pitch_buf_fx + tmp16, L_SUBFR << 6, tmp16 ); + } + ELSE +#endif + { + set16_fx( st_fx->old_pitch_buf_fx + tmp16, L_SUBFR, tmp16 ); + } /* Reset old ACELP buffers */ test(); @@ -251,6 +266,7 @@ void core_switching_pre_enc_fx( /* reset BWE memories */ hBWE_TD->bwe_non_lin_prev_scale_fx = 0; + move32(); } IF( hBWE_FD != NULL ) { @@ -292,7 +308,7 @@ void core_switching_pre_enc_fx( { set16_fx( hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2 ); hBWE_TD->bwe_non_lin_prev_scale_fx = 0; - move16(); + move32(); } /* reset BWE memories */ @@ -301,6 +317,7 @@ void core_switching_pre_enc_fx( set16_fx( hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); } } + test(); test(); test(); @@ -341,7 +358,27 @@ void core_switching_pre_enc_fx( } Sample_Delay_HP = sub( Sample_Delay_HP, NS2SA( 16000, DELAY_FIR_RESAMPL_NS ) ); } - Copy( old_inp_12k8 + sub( L_INP_MEM + L_FRAME, Sample_Delay_LP ), hBWE_FD->old_input_lp_fx, Sample_Delay_LP ); /*Qx*/ + +#ifdef HARM_CORE_SW + IF( NE_16( st_fx->element_mode, EVS_MONO ) ) + { + IF( GT_16( q_old_inp_12k8, hBWE_FD->prev_Q_input_lp ) ) + { + Copy_Scale_sig( old_inp_12k8 + sub( L_INP_MEM + L_FRAME, Sample_Delay_LP ), hBWE_FD->old_input_lp_fx, Sample_Delay_LP, sub( hBWE_FD->prev_Q_input_lp, q_old_inp_12k8 ) ); // prev_Q_input_lp + } + ELSE + { + Scale_sig( hBWE_FD->old_input_lp_fx, NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_NS ), sub( q_old_inp_12k8, hBWE_FD->prev_Q_input_lp ) ); // q_old_inp_12k8 + hBWE_FD->prev_Q_input_lp = q_old_inp_12k8; + move16(); + Copy( old_inp_12k8 + sub( L_INP_MEM + L_FRAME, Sample_Delay_LP ), hBWE_FD->old_input_lp_fx, Sample_Delay_LP ); + } + } + ELSE +#endif + { + Copy( old_inp_12k8 + sub( L_INP_MEM + L_FRAME, Sample_Delay_LP ), hBWE_FD->old_input_lp_fx, Sample_Delay_LP ); /*Qx*/ + } } ELSE { @@ -356,12 +393,36 @@ void core_switching_pre_enc_fx( Sample_Delay_HP = sub( Sample_Delay_HP, NS2SA( 16000, DELAY_FIR_RESAMPL_NS ) ); } - Copy( old_inp_16k + sub( L_INP_MEM + L_FRAME, Sample_Delay_LP ), hBWE_FD->old_input_lp_fx, Sample_Delay_LP ); /*Qx*/ +#ifdef HARM_CORE_SW + IF( NE_16( st_fx->element_mode, EVS_MONO ) ) + { + IF( GT_16( q_old_inp_16k, hBWE_FD->prev_Q_input_lp ) ) + { + Copy_Scale_sig( old_inp_16k + sub( L_INP_MEM + L_FRAME, Sample_Delay_LP ), hBWE_FD->old_input_lp_fx, Sample_Delay_LP, sub( hBWE_FD->prev_Q_input_lp, q_old_inp_16k ) ); // prev_Q_input_lp + } + ELSE + { + Scale_sig( hBWE_FD->old_input_lp_fx, NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_NS ), sub( q_old_inp_16k, hBWE_FD->prev_Q_input_lp ) ); // q_old_inp_16k + hBWE_FD->prev_Q_input_lp = q_old_inp_16k; + move16(); + Copy( old_inp_16k + sub( L_INP_MEM + L_FRAME, Sample_Delay_LP ), hBWE_FD->old_input_lp_fx, Sample_Delay_LP ); + } + } + ELSE +#endif + { + Copy( old_inp_16k + sub( L_INP_MEM + L_FRAME, Sample_Delay_LP ), hBWE_FD->old_input_lp_fx, Sample_Delay_LP ); /*Qx*/ + } } tmp = sub( L_LOOK_16k + L_SUBFR16k, Sample_Delay_HP ); Copy( &hBWE_TD->old_speech_shb_fx[tmp], hBWE_FD->new_input_hp_fx, Sample_Delay_HP ); /*Q(Q_shb_spch)*/ +#ifdef HARM_CORE_SW + hBWE_FD->Q_new_input_hp = 0; + move16(); +#else add( 0, 0 ); +#endif IF( NE_16( st_fx->last_extl, WB_BWE ) ) { @@ -417,6 +478,13 @@ void core_switching_post_enc_fx( hBWE_TD->bwe_non_lin_prev_scale_fx = L_deposit_l( 0 ); hBWE_FD->mem_deemph_old_syn_fx = 0; move16(); +#ifdef HARM_CORE_SW + IF( NE_16( st_fx->element_mode, EVS_MONO ) ) + { + hBWE_FD->q_mem_deemph_old_syn = 0; + move16(); + } +#endif } ELSE { @@ -461,23 +529,56 @@ void core_switching_post_enc_fx( test(); test(); test(); +#ifdef HARM_CORE_SW + test(); + test(); + test(); + test(); + test(); + test(); + test(); +#endif IF( ( EQ_16( st_fx->extl, SWB_TBE ) || EQ_16( st_fx->extl, FB_TBE ) ) && ( EQ_16( st_fx->last_core, HQ_CORE ) || NE_16( st_fx->L_frame, st_fx->last_L_frame ) || ( NE_16( st_fx->last_extl, SWB_TBE ) && NE_16( st_fx->last_extl, FB_TBE ) && NE_16( st_fx->last_core, TCX_20_CORE ) && NE_16( st_fx->last_core, TCX_10_CORE ) ) ) ) { set16_fx( hBWE_TD->state_ana_filt_shb_fx, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); - set16_fx( hBWE_TD->old_speech_shb_fx, 0, L_LOOK_16k + L_SUBFR16k ); +#ifdef HARM_CORE_SW + IF( NE_16( st_fx->element_mode, EVS_MONO ) ) + { + InitSWBencBufferStates_fx( st_fx->hBWE_TD, NULL ); + } + ELSE +#endif + { + set16_fx( hBWE_TD->old_speech_shb_fx, 0, L_LOOK_16k + L_SUBFR16k ); + } swb_tbe_reset_fx( hBWE_TD->mem_csfilt_fx, hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->state_lpc_syn_fx, hBWE_TD->syn_overlap_fx, hBWE_TD->state_syn_shbexc_fx, &( hBWE_TD->tbe_demph_fx ), &( hBWE_TD->tbe_premph_fx ), hBWE_TD->mem_stp_swb_fx, &( hBWE_TD->gain_prec_swb_fx ) ); - set16_fx( hBWE_TD->dec_2_over_3_mem_fx, 0, 12 ); - set16_fx( hBWE_TD->dec_2_over_3_mem_lp_fx, 0, 6 ); + set16_fx( hBWE_TD->dec_2_over_3_mem_fx, 0, L_FILT_2OVER3 ); +#ifdef HARM_CORE_SW + IF( NE_16( st_fx->element_mode, EVS_MONO ) ) + { + set16_fx( st_fx->hBWE_TD->dec_2_over_3_mem_lp_fx, 0, L_FILT_2OVER3_LP ); + } + ELSE +#endif + { + set16_fx( hBWE_TD->dec_2_over_3_mem_lp_fx, 0, 6 ); + } } +#ifdef HARM_CORE_SW + ELSE IF( ( EQ_16( st_fx->extl, SWB_TBE ) || EQ_16( st_fx->extl, FB_TBE ) ) && + ( ( EQ_16( st_fx->element_mode, IVAS_CPE_TD ) && NE_16( st_fx->last_extl, SWB_TBE ) && NE_16( st_fx->last_extl, FB_TBE ) ) || ( NE_16( st_fx->element_mode, IVAS_CPE_TD ) && NE_32( st_fx->last_total_brate, st_fx->total_brate ) ) || + ( NE_16( st_fx->last_bwidth, st_fx->bwidth ) ) || ( NE_16( st_fx->last_codec_mode, MODE1 ) ) || ( NE_16( st_fx->rf_mode_last, st_fx->rf_mode ) ) ) ) +#else ELSE IF( ( EQ_16( st_fx->extl, SWB_TBE ) || EQ_16( st_fx->extl, FB_TBE ) ) && ( NE_32( st_fx->last_total_brate, st_fx->total_brate ) || NE_16( st_fx->last_bwidth, st_fx->bwidth ) || NE_16( st_fx->last_codec_mode, MODE1 ) || NE_16( st_fx->rf_mode, st_fx->rf_mode_last ) ) ) +#endif { set16_fx( hBWE_TD->state_lpc_syn_fx, 0, LPC_SHB_ORDER ); set16_fx( hBWE_TD->state_syn_shbexc_fx, 0, L_SHB_LAHEAD ); @@ -1066,7 +1167,7 @@ void core_switching_pre_enc_ivas_fx( return; } - +#ifndef HARM_CORE_SW /*---------------------------------------------------------------------* * core_switching_post_enc() @@ -1208,3 +1309,4 @@ void core_switching_post_enc_ivas_fx( return; } +#endif diff --git a/lib_enc/evs_enc_fx.c b/lib_enc/evs_enc_fx.c index 416c2f4e9..34eda1c20 100644 --- a/lib_enc/evs_enc_fx.c +++ b/lib_enc/evs_enc_fx.c @@ -260,7 +260,11 @@ ivas_error evs_enc_fx( * Preprocessing (preparing) for ACELP/HQ core switching *---------------------------------------------------------------------*/ +#ifdef HARM_CORE_SW + core_switching_pre_enc_fx( st, old_inp_12k8, 0, old_inp_16k, 0, 0, 0 ); +#else core_switching_pre_enc_fx( st, old_inp_12k8, old_inp_16k, 0, 0 ); +#endif /*---------------------------------------------------------------------* * ACELP core encoding diff --git a/lib_enc/ivas_core_enc_fx.c b/lib_enc/ivas_core_enc_fx.c index 6d5988bbe..a340fc4d0 100644 --- a/lib_enc/ivas_core_enc_fx.c +++ b/lib_enc/ivas_core_enc_fx.c @@ -648,7 +648,7 @@ ivas_error ivas_core_enc_fx( *---------------------------------------------------------------------*/ #ifdef CLEANUP_ACELP_ENC -#ifdef HARM_CORE_SWaaa +#ifdef HARM_CORE_SW core_switching_post_enc_fx( st, NULL, NULL, NULL, 0, 0, 0, NULL ); #else core_switching_post_enc_ivas_fx( st ); diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index dd0c2e441..ede39b497 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -125,9 +125,15 @@ void core_switching_post_enc_fx( ); void core_switching_pre_enc_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word16 *old_inp_12k8, /* i : old i signal @12.8kHz Qx*/ - const Word16 *old_inp_16k, /* i : old i signal @16kHz Qx*/ + Encoder_State *st_fx, /* i/o: encoder state structure */ + const Word16 *old_inp_12k8, /* i : old input signal @12.8kHz Qx*/ +#ifdef HARM_CORE_SW + const Word16 q_old_inp_12k8, /* i : Q old input signal @12.8kHz */ +#endif + const Word16 *old_inp_16k, /* i : old i signal @16kHz Qx*/ +#ifdef HARM_CORE_SW + const Word16 q_old_inp_16k, /* i : Q old input signal @16kHz */ +#endif const Word16 active_cnt, /* i : active frame counter Q0*/ const Word16 last_element_mode /* i : last_element_mode Q0*/ ); -- GitLab From 90d9274ec35e09522057d7b52108bccbee0a48e2 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 12 Jan 2026 18:03:29 +0100 Subject: [PATCH 16/18] HARM_CORE_SW, decoder step 8 (core_switching_pre_enc) --- lib_com/ivas_prot_fx.h | 3 ++- lib_enc/core_switching_enc_fx.c | 41 +++++++++++++++++++++++++++++++-- lib_enc/ivas_core_enc_fx.c | 6 ++++- 3 files changed, 46 insertions(+), 4 deletions(-) diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index fee62ca4c..b86e5281c 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -2963,6 +2963,7 @@ void stereo_icBWE_preproc_fx( Word16 shb_speech_nonref[], /* o : SHB speech non-ref channel */ Word16 q_shb_speech_nonref /* i : Q SHB speech non-ref channel */ ); +#ifndef HARM_CORE_SW void core_switching_pre_enc_ivas_fx( Encoder_State *st_fx, /* i/o: encoder state structure */ @@ -2973,7 +2974,7 @@ void core_switching_pre_enc_ivas_fx( const Word16 active_cnt, /* i : active frame counter */ const Word16 last_element_mode /* i : last_element_mode */ ); - +#endif Word16 ivas_acelp_tcx20_switching_fx( Encoder_State *st, /* i/o: encoder state structure */ Word16 *inp_fx, /* i : new input signal */ diff --git a/lib_enc/core_switching_enc_fx.c b/lib_enc/core_switching_enc_fx.c index beee43d5f..881c070b6 100644 --- a/lib_enc/core_switching_enc_fx.c +++ b/lib_enc/core_switching_enc_fx.c @@ -70,6 +70,7 @@ void core_switching_pre_enc_fx( set16_fx( hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); } + test(); IF( EQ_16( st_fx->last_core, TCX_20_CORE ) || EQ_16( st_fx->last_core, TCX_10_CORE ) ) { @@ -206,12 +207,17 @@ void core_switching_pre_enc_fx( /* Reset ACELP parameters */ IF( hLPDmem != NULL ) { - move16(); hLPDmem->syn[M] = 0; move16(); set16_fx( hLPDmem->mem_syn2, 0, M ); set16_fx( hLPDmem->mem_syn, 0, M ); set16_fx( hLPDmem->mem_syn1_fx, 0, M ); +#ifdef HARM_CORE_SW + IF( NE_16( st_fx->element_mode, EVS_MONO ) ) + { + hLPDmem->q_mem_syn = Q15; + } +#endif hLPDmem->mem_w0 = 0; move16(); hLPDmem->tilt_code = 0; @@ -273,6 +279,7 @@ void core_switching_pre_enc_fx( set16_fx( hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); } } + test(); test(); test(); @@ -438,6 +445,35 @@ void core_switching_pre_enc_fx( move16(); /* Set to a High Exponent so it is 1^-30 */ } +#ifdef HARM_CORE_SW + /*---------------------------------------------------------------------* + * band-width switching from WB -> SWB/FB + *---------------------------------------------------------------------*/ + + IF( st_fx->element_mode > EVS_MONO ) + { + IF( st_fx->bwidth_sw_cnt == 0 ) + { + test(); + IF( GE_16( st_fx->bwidth, SWB ) && EQ_16( st_fx->last_bwidth, WB ) ) + { + st_fx->bwidth_sw_cnt = add( st_fx->bwidth_sw_cnt, 1 ); + move16(); + } + } + ELSE + { + st_fx->bwidth_sw_cnt = add( st_fx->bwidth_sw_cnt, 1 ); + move16(); + IF( EQ_16( st_fx->bwidth_sw_cnt, BWS_TRAN_PERIOD ) ) + { + st_fx->bwidth_sw_cnt = 0; + move16(); + } + } + } + +#endif return; } @@ -748,6 +784,7 @@ void core_switching_hq_prepare_enc_fx( } return; } +#ifndef HARM_CORE_SW void core_switching_pre_enc_ivas_fx( Encoder_State *st_fx, /* i/o: encoder state structure */ @@ -1167,7 +1204,7 @@ void core_switching_pre_enc_ivas_fx( return; } -#ifndef HARM_CORE_SW + /*---------------------------------------------------------------------* * core_switching_post_enc() diff --git a/lib_enc/ivas_core_enc_fx.c b/lib_enc/ivas_core_enc_fx.c index a340fc4d0..d95a9ce1c 100644 --- a/lib_enc/ivas_core_enc_fx.c +++ b/lib_enc/ivas_core_enc_fx.c @@ -306,7 +306,11 @@ ivas_error ivas_core_enc_fx( * Preprocessing (preparing) for ACELP/HQ core switching *---------------------------------------------------------------------*/ +#ifdef HARM_CORE_SW + core_switching_pre_enc_fx( st, old_inp_12k8_fx[n], sub( Q_new[n], 1 ), old_inp_16k_fx[n], sub( Q_new[n], 1 ), sts[0]->active_cnt, last_element_mode ); +#else core_switching_pre_enc_ivas_fx( st, old_inp_12k8_fx[n], sub( Q_new[n], 1 ), old_inp_16k_fx[n], sub( Q_new[n], 1 ), sts[0]->active_cnt, last_element_mode ); +#endif /*---------------------------------------------------------------------* * ACELP core encoding @@ -637,7 +641,7 @@ ivas_error ivas_core_enc_fx( q_inp[0] = st->q_old_inp; q_inp[1] = st->q_inp; - Scale_sig( st->input_fx - input_frame, 2 * input_frame, sub( -1, st->q_inp ) ); + Scale_sig( st->input_fx - input_frame, shl( input_frame, 1 ), sub( -1, st->q_inp ) ); st->q_inp = -1; move16(); st->q_old_inp = -1; -- GitLab From 4663ed8661bf10feb6a25eba4ab6207596777944 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 13 Jan 2026 14:40:48 +0100 Subject: [PATCH 17/18] fix to restore IVAS BE --- lib_dec/core_switching_dec_fx.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/lib_dec/core_switching_dec_fx.c b/lib_dec/core_switching_dec_fx.c index 3c64c6e16..08afdcabe 100644 --- a/lib_dec/core_switching_dec_fx.c +++ b/lib_dec/core_switching_dec_fx.c @@ -1394,12 +1394,7 @@ ivas_error core_switching_post_dec_ivas_fx( st_fx->use_acelp_preq = 0; move16(); -#ifdef HARM_CORE_SW - test(); - if ( EQ_16( st_fx->element_mode, EVS_MONO ) && st_fx->hBWE_FD != NULL ) -#else IF( st_fx->hBWE_FD != NULL ) -#endif { hBWE_FD->mem_deemph_old_syn_fx = 0; move16(); -- GitLab From ec27c09b8d01fb2a2b279a90fbe3c8adc3d7b8f4 Mon Sep 17 00:00:00 2001 From: vaclav Date: Thu, 15 Jan 2026 16:58:48 +0100 Subject: [PATCH 18/18] clang-format --- lib_dec/acelp_core_switch_dec_fx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_dec/acelp_core_switch_dec_fx.c b/lib_dec/acelp_core_switch_dec_fx.c index a16143727..d2353fd73 100644 --- a/lib_dec/acelp_core_switch_dec_fx.c +++ b/lib_dec/acelp_core_switch_dec_fx.c @@ -878,7 +878,7 @@ ivas_error acelp_core_switch_dec_bfi_ivas_fx( Word16 out_len = extract_l( Mpy_32_16_1( st_fx->output_Fs, 328 ) ); cldfbSynthesis_ivas_fx( realBuffer, imagBuffer, synth32, out_len, -1, 0, st_fx->cldfbSyn ); - + Copy_Scale_sig_32_16( synth32, synth_out, out_len, -4 ); cldfb_restore_memory_ivas_fx( st_fx->cldfbSyn ); } -- GitLab