From c30db7ccc5f31879c9bc68d757c2a5973fb8bffe Mon Sep 17 00:00:00 2001 From: naghibza Date: Thu, 3 Apr 2025 10:21:57 +0200 Subject: [PATCH 001/113] Fix for 3GPP issue 1348: Increased noise level in BASOP decoder for band-limited input from float encoder Link #1348 --- lib_com/options.h | 3 +- lib_dec/dec_tcx_fx.c | 79 ++++++++++++++++++++++++++++++++- lib_dec/hq_core_dec_fx.c | 4 ++ lib_dec/ivas_mdct_core_dec_fx.c | 12 +++++ lib_dec/stat_dec.h | 4 ++ 5 files changed, 99 insertions(+), 3 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 4f818e0c3..8fb6cf9df 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -69,6 +69,5 @@ /* Note: each compile switch (FIX_1101_...) is independent from the other ones */ //#define OPT_STEREO_32KBPS_V1 /* Optimization made in stereo decoding path for 32kbps decoding */ -#define FIX_1310_SPEEDUP_ivas_dirac_dec_get_response_fx /*FhG: WMOPS tuning, nonbe*/ -#define FIX_1310_SPEEDUP_ivas_dirac_dec_output_synthesis_process_slot /*FhG: WMOPS tuning, nonbe*/ +#define FIX_1348_BIT_PRECISION_IMPROVEMENT #endif diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index af80ee1f5..7a8a24185 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -2601,6 +2601,9 @@ void IMDCT_ivas_fx( const Word16 frame_cnt, const Word16 bfi, Word16 *old_out_fx, // Q(-2) +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT + Word16 *q_old_out_fx, +#endif const Word16 FB_flag, Decoder_State *st, const Word16 fullbandScale, @@ -2862,9 +2865,16 @@ void IMDCT_ivas_fx( move16(); Word16 diff = sub( q_tmp_fx_32, q_win ); +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT + Word16 q_old_out_diff = sub( q_tmp_fx_32, *q_old_out_fx ); +#endif FOR( Word16 ind = 0; ind < L_frame; ind++ ) { +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT + old_out_fx_32[ind] = L_shl( old_out_fx[ind], q_old_out_diff ); +#else old_out_fx_32[ind] = L_shl( old_out_fx[ind], diff ); +#endif move32(); } @@ -2872,7 +2882,11 @@ void IMDCT_ivas_fx( FOR( Word16 ind = 0; ind < L_frame; ind++ ) { +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT + old_out_fx[ind] = extract_l( L_shr( old_out_fx_32[ind], q_old_out_diff ) ); +#else old_out_fx[ind] = extract_l( L_shr( old_out_fx_32[ind], diff ) ); +#endif xn_buf_fx[ind] = extract_l( L_shr( xn_buf_fx_32[ind], diff ) ); move16(); move16(); @@ -2880,7 +2894,12 @@ void IMDCT_ivas_fx( } ELSE { +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT + Scale_sig32( x_fx, L_frame, 1 ); + q_xn_buf_fx_32 ++; +#else Word16 q_old_out = q_win; +#endif move16(); edct_fx( x_fx, xn_buf_fx_32 + add( shr( overlap, 1 ), nz ), L_frame, &q_xn_buf_fx_32 ); Word16 res_m, res_e; @@ -2904,15 +2923,21 @@ void IMDCT_ivas_fx( move16(); } +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT + window_ola_fx( tmp_fx_32, xn_buf_fx, &q_tmp_fx_32, old_out_fx, q_old_out_fx, L_frame, hTcxCfg->tcx_last_overlap_mode, hTcxCfg->tcx_curr_overlap_mode, 0, 0, NULL ); +#else window_ola_fx( tmp_fx_32, xn_buf_fx, &q_tmp_fx_32, old_out_fx, &q_old_out, L_frame, hTcxCfg->tcx_last_overlap_mode, hTcxCfg->tcx_curr_overlap_mode, 0, 0, NULL ); q_diff = sub( q_old_out, q_win ); +#endif Word16 diff = sub( q_tmp_fx_32, q_win ); FOR( Word16 ind = 0; ind < L_frame; ind++ ) { +#ifndef FIX_1348_BIT_PRECISION_IMPROVEMENT old_out_fx[ind] = shr_sat( old_out_fx[ind], q_diff ); move16(); +#endif xn_buf_fx[ind] = shr_sat( xn_buf_fx[ind], diff ); move16(); } @@ -3004,9 +3029,18 @@ void IMDCT_ivas_fx( IF( hTcxCfg->last_aldo != 0 ) { +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT + Word16 tmp_old_out; + Word16 q_diff = sub( *q_old_out_fx, q_win ); +#endif FOR( i = 0; i < sub( overlap, tcx_mdct_window_min_length ); i++ ) { +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT + tmp_old_out = shr_sat( old_out_fx[( i + nz )], q_diff ); + xn_buf_fx[( i + ( ( overlap / 2 ) - tcx_offset ) )] = add_sat( xn_buf_fx[( i + ( ( overlap / 2 ) - tcx_offset ) )], tmp_old_out ); // Q(-2) +#else xn_buf_fx[( i + ( ( overlap / 2 ) - tcx_offset ) )] = add_sat( xn_buf_fx[( i + ( ( overlap / 2 ) - tcx_offset ) )], old_out_fx[( i + nz )] ); // Q(-2) +#endif move16(); } @@ -3019,17 +3053,32 @@ void IMDCT_ivas_fx( // tested FOR( ; i < overlap; i++ ) /* perfectly reconstructing ALDO shortening */ { +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT + tmp_old_out = shr_sat( old_out_fx[( i + nz )], q_diff ); + xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )] = add_sat( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], tmp_old_out ); // Q(-2) +#else xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )] = add_sat( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], old_out_fx[( i + nz )] ); // Q(-2) +#endif move16(); } FOR( i = 0; i < ( tcx_mdct_window_min_length / 2 ); i++ ) { +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT + tmp_old_out = shr_sat( old_out_fx[( ( i + nz ) + overlap )], q_diff ); + xn_buf_fx[( ( ( i + ( overlap / 2 ) ) - tcx_offset ) + overlap )] = add_sat( xn_buf_fx[( ( ( i + ( overlap / 2 ) ) - tcx_offset ) + overlap )], mult_r( tmp_old_out, tcx_mdct_window_minimum_fx[i].v.re ) ); // Q(-2) +#else xn_buf_fx[( ( ( i + ( overlap / 2 ) ) - tcx_offset ) + overlap )] = add_sat( xn_buf_fx[( ( ( i + ( overlap / 2 ) ) - tcx_offset ) + overlap )], mult_r( old_out_fx[( ( i + nz ) + overlap )], tcx_mdct_window_minimum_fx[i].v.re ) ); // Q(-2) +#endif move16(); } FOR( ; i < tcx_mdct_window_min_length; i++ ) { +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT + tmp_old_out = shr_sat( old_out_fx[( ( i + nz ) + overlap )], q_diff ); + xn_buf_fx[( ( ( i + ( overlap / 2 ) ) - tcx_offset ) + overlap )] = add_sat( xn_buf_fx[( ( ( i + ( overlap / 2 ) ) - tcx_offset ) + overlap )], mult_r( tmp_old_out, tcx_mdct_window_minimum_fx[( tcx_mdct_window_min_length - ( 1 + i ) )].v.im ) ); // Q(-2) +#else xn_buf_fx[( ( ( i + ( overlap / 2 ) ) - tcx_offset ) + overlap )] = add_sat( xn_buf_fx[( ( ( i + ( overlap / 2 ) ) - tcx_offset ) + overlap )], mult_r( old_out_fx[( ( i + nz ) + overlap )], tcx_mdct_window_minimum_fx[( tcx_mdct_window_min_length - ( 1 + i ) )].v.im ) ); // Q(-2) +#endif move16(); } } @@ -3037,12 +3086,22 @@ void IMDCT_ivas_fx( { FOR( ; i < ( overlap - ( tcx_mdct_window_min_length / 2 ) ); i++ ) { +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT + tmp_old_out = shr_sat( old_out_fx[( i + nz )], q_diff ); + xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )] = add_sat( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], mult_r( tmp_old_out, tcx_mdct_window_minimum_fx[( ( tcx_mdct_window_min_length - overlap ) + i )].v.re ) ); // Q(-2) +#else xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )] = add_sat( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], mult_r( old_out_fx[( i + nz )], tcx_mdct_window_minimum_fx[( ( tcx_mdct_window_min_length - overlap ) + i )].v.re ) ); // Q(-2) +#endif move16(); } FOR( ; i < overlap; i++ ) { +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT + tmp_old_out = shr_sat( old_out_fx[( i + nz )], q_diff ); + xn_buf_fx[( i + ( ( overlap / 2 ) - tcx_offset ) )] = add_sat( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], mult_r( tmp_old_out, tcx_mdct_window_minimum_fx[( overlap - ( 1 + i ) )].v.im ) ); // Q(-2) +#else xn_buf_fx[( i + ( ( overlap / 2 ) - tcx_offset ) )] = add_sat( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], mult_r( old_out_fx[( i + nz )], tcx_mdct_window_minimum_fx[( overlap - ( 1 + i ) )].v.im ) ); // Q(-2) +#endif move16(); } } @@ -3091,7 +3150,9 @@ void IMDCT_ivas_fx( /* Compute windowed synthesis in case of switching to ALDO windows in next frame */ Copy( xn_buf_fx + sub( L_frame, nz ), old_out_fx, add( nz, overlap ) ); set16_fx( old_out_fx + add( nz, overlap ), 0, nz ); - +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT + *q_old_out_fx = q_win; +#endif tcx_windowing_synthesis_past_frame( old_out_fx + nz, tcx_aldo_window_1_trunc_fx, tcx_mdct_window_half_fx, tcx_mdct_window_minimum_fx, overlap, tcx_mdct_window_half_length, tcx_mdct_window_min_length, hTcxCfg->tcx_curr_overlap_mode ); /* If current overlap mode = FULL_OVERLAP -> ALDO_WINDOW */ @@ -5196,7 +5257,11 @@ void decoder_tcx_imdct_fx( IMDCT_ivas_fx( xn_bufFB_fx, q_x, hTcxDec->syn_Overl, hTcxDec->syn_Overl_TDAC, xn_buf_fx, hTcxCfg->tcx_aldo_window_1, hTcxCfg->tcx_aldo_window_1_trunc, hTcxCfg->tcx_aldo_window_2, hTcxCfg->tcx_mdct_window_half, hTcxCfg->tcx_mdct_window_minimum, hTcxCfg->tcx_mdct_window_trans, hTcxCfg->tcx_mdct_window_half_length, hTcxCfg->tcx_mdct_window_min_length, index, +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT + kernelType, left_rect, tcx_offset, overlap, L_frame, L_frameTCX, shr( s_max( L_frameTCX, L_spec ), 1 ), L_frame_glob, frame_cnt, bfi, st->hHQ_core->old_out_LB_fx, &st->hHQ_core->q_old_out_LB_fx, 0, st, 0, acelp_zir_fx, q_win ); +#else kernelType, left_rect, tcx_offset, overlap, L_frame, L_frameTCX, shr( s_max( L_frameTCX, L_spec ), 1 ), L_frame_glob, frame_cnt, bfi, st->hHQ_core->old_out_LB_fx, 0, st, 0, acelp_zir_fx, q_win ); +#endif } /* Generate additional comfort noise to mask potential coding artefacts */ @@ -5218,7 +5283,11 @@ void decoder_tcx_imdct_fx( Copy32( x_fx, xn_bufFB_fx, s_max( L_spec, s_max( L_frame, L_frameTCX ) ) ); // q_x IMDCT_ivas_fx( xn_bufFB_fx, q_x, hTcxDec->syn_Overl, hTcxDec->syn_Overl_TDAC, xn_buf_fx, hTcxCfg->tcx_aldo_window_1, hTcxCfg->tcx_aldo_window_1_trunc, hTcxCfg->tcx_aldo_window_2, hTcxCfg->tcx_mdct_window_half, hTcxCfg->tcx_mdct_window_minimum, hTcxCfg->tcx_mdct_window_trans, hTcxCfg->tcx_mdct_window_half_length, hTcxCfg->tcx_mdct_window_min_length, index, +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT + kernelType, left_rect, tcx_offset, overlap, L_frame, L_frameTCX, shr( s_max( L_frameTCX, L_spec ), 1 ), L_frame_glob, frame_cnt, bfi, st->hHQ_core->old_out_LB_fx, &st->hHQ_core->q_old_out_LB_fx, 0, st, 0, acelp_zir_fx, q_win ); +#else kernelType, left_rect, tcx_offset, overlap, L_frame, L_frameTCX, shr( s_max( L_frameTCX, L_spec ), 1 ), L_frame_glob, frame_cnt, bfi, st->hHQ_core->old_out_LB_fx, 0, st, 0, acelp_zir_fx, q_win ); +#endif } FOR( Word16 ind = 0; ind < L_MDCT_OVLP_MAX + L_FRAME_PLUS + L_MDCT_OVLP_MAX; ind++ ) @@ -5235,13 +5304,21 @@ void decoder_tcx_imdct_fx( { IMDCT_ivas_fx( x_tmp_fx, q_x, hTcxDec->syn_OverlFB, hTcxDec->syn_Overl_TDACFB, xn_bufFB_fx_16, hTcxCfg->tcx_aldo_window_1_FB, hTcxCfg->tcx_aldo_window_1_FB_trunc, hTcxCfg->tcx_aldo_window_2_FB, hTcxCfg->tcx_mdct_window_halfFB, hTcxCfg->tcx_mdct_window_minimumFB, hTcxCfg->tcx_mdct_window_transFB, hTcxCfg->tcx_mdct_window_half_lengthFB, hTcxCfg->tcx_mdct_window_min_lengthFB, index, +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT + kernelType, left_rect, tcx_offsetFB, overlapFB, L_frameTCX, L_frameTCX, shr( s_max( L_frameTCX, L_spec ), 1 ), L_frameTCX_glob, frame_cnt, bfi, st->hHQ_core->old_out_fx, &st->hHQ_core->q_old_out_fx, 1, st, ratio, acelp_zir_fx, q_win ); +#else kernelType, left_rect, tcx_offsetFB, overlapFB, L_frameTCX, L_frameTCX, shr( s_max( L_frameTCX, L_spec ), 1 ), L_frameTCX_glob, frame_cnt, bfi, st->hHQ_core->old_out_fx, 1, st, ratio, acelp_zir_fx, q_win ); +#endif } ELSE { IMDCT_ivas_fx( x_fx, q_x, hTcxDec->syn_OverlFB, hTcxDec->syn_Overl_TDACFB, xn_bufFB_fx_16, hTcxCfg->tcx_aldo_window_1_FB, hTcxCfg->tcx_aldo_window_1_FB_trunc, hTcxCfg->tcx_aldo_window_2_FB, hTcxCfg->tcx_mdct_window_halfFB, hTcxCfg->tcx_mdct_window_minimumFB, hTcxCfg->tcx_mdct_window_transFB, hTcxCfg->tcx_mdct_window_half_lengthFB, hTcxCfg->tcx_mdct_window_min_lengthFB, index, +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT + kernelType, left_rect, tcx_offsetFB, overlapFB, L_frameTCX, L_frameTCX, shr( s_max( L_frameTCX, L_spec ), 1 ), L_frameTCX_glob, frame_cnt, bfi, st->hHQ_core->old_out_fx, &st->hHQ_core->q_old_out_fx, 1, st, ratio, acelp_zir_fx, q_win ); +#else kernelType, left_rect, tcx_offsetFB, overlapFB, L_frameTCX, L_frameTCX, shr( s_max( L_frameTCX, L_spec ), 1 ), L_frameTCX_glob, frame_cnt, bfi, st->hHQ_core->old_out_fx, 1, st, ratio, acelp_zir_fx, q_win ); +#endif } FOR( Word16 ind = 0; ind < L_MDCT_OVLP_MAX + L_FRAME_PLUS + L_MDCT_OVLP_MAX; ind++ ) { diff --git a/lib_dec/hq_core_dec_fx.c b/lib_dec/hq_core_dec_fx.c index 4d1ef6774..c4bbc3128 100644 --- a/lib_dec/hq_core_dec_fx.c +++ b/lib_dec/hq_core_dec_fx.c @@ -1202,6 +1202,10 @@ void HQ_core_dec_init_fx( hHQ_core->Q_old_wtda = 15; hHQ_core->Q_old_postdec = 0; hHQ_core->Q_old_wtda_LB = 0; +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT + hHQ_core->q_old_out_fx = 0; + hHQ_core->q_old_out_LB_fx = 0; +#endif move16(); move16(); move16(); diff --git a/lib_dec/ivas_mdct_core_dec_fx.c b/lib_dec/ivas_mdct_core_dec_fx.c index fabebede4..6126ef44c 100644 --- a/lib_dec/ivas_mdct_core_dec_fx.c +++ b/lib_dec/ivas_mdct_core_dec_fx.c @@ -1098,7 +1098,11 @@ void ivas_mdct_core_reconstruct_fx( Word16 *synthFB_fx; Word16 q_syn = 0; move16(); +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT + Word16 q_win = -1; +#else Word16 q_win = -2; +#endif move16(); /* TCX */ Word16 xn_buf_fx[L_MDCT_OVLP_MAX + L_FRAME_PLUS + L_MDCT_OVLP_MAX]; // Q(-2) @@ -1174,8 +1178,10 @@ void ivas_mdct_core_reconstruct_fx( st->hTcxDec->Q_old_syn_Overl = q_win; Scale_sig( st->hTcxDec->syn_Overl, L_FRAME32k / 2, sub( q_win, st->Q_syn ) ); // Q(st->Q_syn) -> q_win Scale_sig( st->hTcxDec->syn_OverlFB, L_FRAME_MAX / 2, sub( q_win, st->Q_syn ) ); // Q(st->Q_syn) -> q_win +#ifndef FIX_1348_BIT_PRECISION_IMPROVEMENT Scale_sig( st->hHQ_core->old_out_LB_fx, L_FRAME32k, sub( q_win, st->hHQ_core->Q_old_wtda_LB ) ); // Q(st->hHQ_core->Q_old_wtda_LB) -> q_win Scale_sig( st->hHQ_core->old_out_fx, L_FRAME48k, sub( q_win, st->hHQ_core->Q_old_wtda ) ); // Q(st->hHQ_core->Q_old_wtda) -> q_win +#endif Scale_sig( synth_buf_fx, add( add( st->hTcxDec->old_synth_len, L_FRAME_PLUS ), M ), sub( q_win, q_syn ) ); // q_syn -> q_win Scale_sig( synth_bufFB_fx, add( add( st->hTcxDec->old_synth_lenFB, L_FRAME_PLUS ), M ), sub( q_win, q_syn ) ); // q_syn -> q_win Scale_sig( st->syn, M + 1, sub( q_win, st->Q_syn ) ); // st->Q_syn -> q_win @@ -1206,6 +1212,10 @@ void ivas_mdct_core_reconstruct_fx( /* Note: these buffers are not subframe-based, hence no indexing with k */ set16_fx( &st->hHQ_core->old_out_LB_fx[0], 0, L_frame[ch] ); set16_fx( &st->hHQ_core->old_out_fx[0], 0, L_frameTCX[ch] ); +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT + st->hHQ_core->q_old_out_LB_fx = 0; + st->hHQ_core->q_old_out_fx = 0; +#endif set16_fx( &st->hTcxDec->syn_Overl[0], 0, shr( L_frame[ch], 1 ) ); set16_fx( &st->hTcxDec->syn_OverlFB[0], 0, shr( L_frameTCX[ch], 1 ) ); set16_fx( &st->hTcxDec->syn_Overl_TDAC[0], 0, shr( L_frame[ch], 1 ) ); @@ -1246,8 +1256,10 @@ void ivas_mdct_core_reconstruct_fx( Scale_sig( st->syn, M + 1, add( st->Q_syn, 2 ) ); Scale_sig( st->hTcxDec->syn_OverlFB, L_FRAME_MAX / 2, sub( st->Q_syn, q_win ) ); // q_win -> st->Q_syn Scale_sig( st->hTcxDec->syn_Overl, L_FRAME32k / 2, sub( st->Q_syn, q_win ) ); // q_win -> st->Q_syn +#ifndef FIX_1348_BIT_PRECISION_IMPROVEMENT Scale_sig( st->hHQ_core->old_out_LB_fx, L_FRAME32k, sub( st->Q_syn, q_win ) ); // q_win -> st->Q_syn Scale_sig( st->hHQ_core->old_out_fx, L_FRAME48k, sub( st->Q_syn, q_win ) ); // q_win -> st->Q_syn +#endif st->hHQ_core->Q_old_wtda = st->Q_syn; move16(); st->hHQ_core->Q_old_wtda_LB = st->Q_syn; diff --git a/lib_dec/stat_dec.h b/lib_dec/stat_dec.h index fcd5142a4..62ffa15b5 100644 --- a/lib_dec/stat_dec.h +++ b/lib_dec/stat_dec.h @@ -702,6 +702,10 @@ typedef struct hq_dec_structure Word16 exp_old_out; Word16 old_out_LB_fx[L_FRAME32k]; /* HQ core - previous synthesis for OLA for Low Band */ Word32 old_out_LB_fx32[L_FRAME32k]; +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT + Word16 q_old_out_LB_fx; + Word16 q_old_out_fx; +#endif Word16 q_old_outLB_fx; Word16 Q_old_wtda_LB; Word16 Q_old_wtda; -- GitLab From 2a410ea1499da320a900a8317e8ae681cd03719d Mon Sep 17 00:00:00 2001 From: naghibza Date: Thu, 3 Apr 2025 11:43:06 +0200 Subject: [PATCH 002/113] Applied formatting-fix.patch --- lib_dec/dec_tcx_fx.c | 14 +++++++------- lib_dec/ivas_mdct_core_dec_fx.c | 14 +++++++------- lib_dec/stat_dec.h | 2 +- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index 7a8a24185..e0dfcf2cb 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -2872,7 +2872,7 @@ void IMDCT_ivas_fx( { #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT old_out_fx_32[ind] = L_shl( old_out_fx[ind], q_old_out_diff ); -#else +#else old_out_fx_32[ind] = L_shl( old_out_fx[ind], diff ); #endif move32(); @@ -2896,7 +2896,7 @@ void IMDCT_ivas_fx( { #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT Scale_sig32( x_fx, L_frame, 1 ); - q_xn_buf_fx_32 ++; + q_xn_buf_fx_32++; #else Word16 q_old_out = q_win; #endif @@ -3039,7 +3039,7 @@ void IMDCT_ivas_fx( tmp_old_out = shr_sat( old_out_fx[( i + nz )], q_diff ); xn_buf_fx[( i + ( ( overlap / 2 ) - tcx_offset ) )] = add_sat( xn_buf_fx[( i + ( ( overlap / 2 ) - tcx_offset ) )], tmp_old_out ); // Q(-2) #else - xn_buf_fx[( i + ( ( overlap / 2 ) - tcx_offset ) )] = add_sat( xn_buf_fx[( i + ( ( overlap / 2 ) - tcx_offset ) )], old_out_fx[( i + nz )] ); // Q(-2) + xn_buf_fx[( i + ( ( overlap / 2 ) - tcx_offset ) )] = add_sat( xn_buf_fx[( i + ( ( overlap / 2 ) - tcx_offset ) )], old_out_fx[( i + nz )] ); // Q(-2) #endif move16(); } @@ -3057,7 +3057,7 @@ void IMDCT_ivas_fx( tmp_old_out = shr_sat( old_out_fx[( i + nz )], q_diff ); xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )] = add_sat( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], tmp_old_out ); // Q(-2) #else - xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )] = add_sat( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], old_out_fx[( i + nz )] ); // Q(-2) + xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )] = add_sat( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], old_out_fx[( i + nz )] ); // Q(-2) #endif move16(); } @@ -3067,7 +3067,7 @@ void IMDCT_ivas_fx( tmp_old_out = shr_sat( old_out_fx[( ( i + nz ) + overlap )], q_diff ); xn_buf_fx[( ( ( i + ( overlap / 2 ) ) - tcx_offset ) + overlap )] = add_sat( xn_buf_fx[( ( ( i + ( overlap / 2 ) ) - tcx_offset ) + overlap )], mult_r( tmp_old_out, tcx_mdct_window_minimum_fx[i].v.re ) ); // Q(-2) #else - xn_buf_fx[( ( ( i + ( overlap / 2 ) ) - tcx_offset ) + overlap )] = add_sat( xn_buf_fx[( ( ( i + ( overlap / 2 ) ) - tcx_offset ) + overlap )], mult_r( old_out_fx[( ( i + nz ) + overlap )], tcx_mdct_window_minimum_fx[i].v.re ) ); // Q(-2) + xn_buf_fx[( ( ( i + ( overlap / 2 ) ) - tcx_offset ) + overlap )] = add_sat( xn_buf_fx[( ( ( i + ( overlap / 2 ) ) - tcx_offset ) + overlap )], mult_r( old_out_fx[( ( i + nz ) + overlap )], tcx_mdct_window_minimum_fx[i].v.re ) ); // Q(-2) #endif move16(); } @@ -3090,7 +3090,7 @@ void IMDCT_ivas_fx( tmp_old_out = shr_sat( old_out_fx[( i + nz )], q_diff ); xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )] = add_sat( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], mult_r( tmp_old_out, tcx_mdct_window_minimum_fx[( ( tcx_mdct_window_min_length - overlap ) + i )].v.re ) ); // Q(-2) #else - xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )] = add_sat( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], mult_r( old_out_fx[( i + nz )], tcx_mdct_window_minimum_fx[( ( tcx_mdct_window_min_length - overlap ) + i )].v.re ) ); // Q(-2) + xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )] = add_sat( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], mult_r( old_out_fx[( i + nz )], tcx_mdct_window_minimum_fx[( ( tcx_mdct_window_min_length - overlap ) + i )].v.re ) ); // Q(-2) #endif move16(); } @@ -3100,7 +3100,7 @@ void IMDCT_ivas_fx( tmp_old_out = shr_sat( old_out_fx[( i + nz )], q_diff ); xn_buf_fx[( i + ( ( overlap / 2 ) - tcx_offset ) )] = add_sat( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], mult_r( tmp_old_out, tcx_mdct_window_minimum_fx[( overlap - ( 1 + i ) )].v.im ) ); // Q(-2) #else - xn_buf_fx[( i + ( ( overlap / 2 ) - tcx_offset ) )] = add_sat( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], mult_r( old_out_fx[( i + nz )], tcx_mdct_window_minimum_fx[( overlap - ( 1 + i ) )].v.im ) ); // Q(-2) + xn_buf_fx[( i + ( ( overlap / 2 ) - tcx_offset ) )] = add_sat( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], mult_r( old_out_fx[( i + nz )], tcx_mdct_window_minimum_fx[( overlap - ( 1 + i ) )].v.im ) ); // Q(-2) #endif move16(); } diff --git a/lib_dec/ivas_mdct_core_dec_fx.c b/lib_dec/ivas_mdct_core_dec_fx.c index 6126ef44c..7459b3789 100644 --- a/lib_dec/ivas_mdct_core_dec_fx.c +++ b/lib_dec/ivas_mdct_core_dec_fx.c @@ -1176,11 +1176,11 @@ void ivas_mdct_core_reconstruct_fx( Scale_sig( st->hTcxDec->syn_Overl_TDAC, L_FRAME32k / 2, sub( q_win, st->hTcxDec->Q_syn_Overl_TDAC ) ); // st->hTcxDec->Q_syn_Overl_TDAC -> q_win Scale_sig( st->hTcxDec->old_syn_Overl, L_FRAME32k / 2, sub( q_win, st->hTcxDec->Q_old_syn_Overl ) ); // Q(-1 - st->Q_syn) -> q_win st->hTcxDec->Q_old_syn_Overl = q_win; - Scale_sig( st->hTcxDec->syn_Overl, L_FRAME32k / 2, sub( q_win, st->Q_syn ) ); // Q(st->Q_syn) -> q_win - Scale_sig( st->hTcxDec->syn_OverlFB, L_FRAME_MAX / 2, sub( q_win, st->Q_syn ) ); // Q(st->Q_syn) -> q_win + Scale_sig( st->hTcxDec->syn_Overl, L_FRAME32k / 2, sub( q_win, st->Q_syn ) ); // Q(st->Q_syn) -> q_win + Scale_sig( st->hTcxDec->syn_OverlFB, L_FRAME_MAX / 2, sub( q_win, st->Q_syn ) ); // Q(st->Q_syn) -> q_win #ifndef FIX_1348_BIT_PRECISION_IMPROVEMENT - Scale_sig( st->hHQ_core->old_out_LB_fx, L_FRAME32k, sub( q_win, st->hHQ_core->Q_old_wtda_LB ) ); // Q(st->hHQ_core->Q_old_wtda_LB) -> q_win - Scale_sig( st->hHQ_core->old_out_fx, L_FRAME48k, sub( q_win, st->hHQ_core->Q_old_wtda ) ); // Q(st->hHQ_core->Q_old_wtda) -> q_win + Scale_sig( st->hHQ_core->old_out_LB_fx, L_FRAME32k, sub( q_win, st->hHQ_core->Q_old_wtda_LB ) ); // Q(st->hHQ_core->Q_old_wtda_LB) -> q_win + Scale_sig( st->hHQ_core->old_out_fx, L_FRAME48k, sub( q_win, st->hHQ_core->Q_old_wtda ) ); // Q(st->hHQ_core->Q_old_wtda) -> q_win #endif Scale_sig( synth_buf_fx, add( add( st->hTcxDec->old_synth_len, L_FRAME_PLUS ), M ), sub( q_win, q_syn ) ); // q_syn -> q_win Scale_sig( synth_bufFB_fx, add( add( st->hTcxDec->old_synth_lenFB, L_FRAME_PLUS ), M ), sub( q_win, q_syn ) ); // q_syn -> q_win @@ -1213,7 +1213,7 @@ void ivas_mdct_core_reconstruct_fx( set16_fx( &st->hHQ_core->old_out_LB_fx[0], 0, L_frame[ch] ); set16_fx( &st->hHQ_core->old_out_fx[0], 0, L_frameTCX[ch] ); #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT - st->hHQ_core->q_old_out_LB_fx = 0; + st->hHQ_core->q_old_out_LB_fx = 0; st->hHQ_core->q_old_out_fx = 0; #endif set16_fx( &st->hTcxDec->syn_Overl[0], 0, shr( L_frame[ch], 1 ) ); @@ -1257,8 +1257,8 @@ void ivas_mdct_core_reconstruct_fx( Scale_sig( st->hTcxDec->syn_OverlFB, L_FRAME_MAX / 2, sub( st->Q_syn, q_win ) ); // q_win -> st->Q_syn Scale_sig( st->hTcxDec->syn_Overl, L_FRAME32k / 2, sub( st->Q_syn, q_win ) ); // q_win -> st->Q_syn #ifndef FIX_1348_BIT_PRECISION_IMPROVEMENT - Scale_sig( st->hHQ_core->old_out_LB_fx, L_FRAME32k, sub( st->Q_syn, q_win ) ); // q_win -> st->Q_syn - Scale_sig( st->hHQ_core->old_out_fx, L_FRAME48k, sub( st->Q_syn, q_win ) ); // q_win -> st->Q_syn + Scale_sig( st->hHQ_core->old_out_LB_fx, L_FRAME32k, sub( st->Q_syn, q_win ) ); // q_win -> st->Q_syn + Scale_sig( st->hHQ_core->old_out_fx, L_FRAME48k, sub( st->Q_syn, q_win ) ); // q_win -> st->Q_syn #endif st->hHQ_core->Q_old_wtda = st->Q_syn; move16(); diff --git a/lib_dec/stat_dec.h b/lib_dec/stat_dec.h index 62ffa15b5..a32bcfd6e 100644 --- a/lib_dec/stat_dec.h +++ b/lib_dec/stat_dec.h @@ -702,7 +702,7 @@ typedef struct hq_dec_structure Word16 exp_old_out; Word16 old_out_LB_fx[L_FRAME32k]; /* HQ core - previous synthesis for OLA for Low Band */ Word32 old_out_LB_fx32[L_FRAME32k]; -#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT Word16 q_old_out_LB_fx; Word16 q_old_out_fx; #endif -- GitLab From 59c183c9a1a4a3c4aaf4393b2ac487a68e48387f Mon Sep 17 00:00:00 2001 From: naghibza Date: Thu, 3 Apr 2025 12:03:46 +0200 Subject: [PATCH 003/113] Changed IMDCT_ivas_fx() declaration. --- lib_com/prot_fx.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index ffd1d6032..114cc431c 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -9848,6 +9848,9 @@ void IMDCT_ivas_fx( const Word16 frame_cnt, const Word16 bfi, Word16 *old_out_fx, +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT + Word16 *q_old_out_fx, +#endif const Word16 FB_flag, Decoder_State *st, const Word16 fullbandScale, -- GitLab From aafc14a191f2b7d81aaddfd5d10fc71a2b715b6d Mon Sep 17 00:00:00 2001 From: naghibza Date: Thu, 3 Apr 2025 13:52:20 +0200 Subject: [PATCH 004/113] Removed calculations using the dynamic q_old_out to check its effect on the pipeline tests. --- lib_com/options.h | 1 + lib_com/prot_fx.h | 2 +- lib_dec/dec_tcx_fx.c | 39 +++++++++++++++++---------------- lib_dec/hq_core_dec_fx.c | 2 +- lib_dec/ivas_mdct_core_dec_fx.c | 6 ++--- lib_dec/stat_dec.h | 2 +- 6 files changed, 27 insertions(+), 25 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 37634456b..b5a3bbb3e 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -79,4 +79,5 @@ #define HARM_ENC_INIT //#define HARM_SCE_INIT #define FIX_1348_BIT_PRECISION_IMPROVEMENT +//#define FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD #endif diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 114cc431c..78e9f96c9 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -9848,7 +9848,7 @@ void IMDCT_ivas_fx( const Word16 frame_cnt, const Word16 bfi, Word16 *old_out_fx, -#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD Word16 *q_old_out_fx, #endif const Word16 FB_flag, diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index e0dfcf2cb..f3c84770f 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -2601,7 +2601,7 @@ void IMDCT_ivas_fx( const Word16 frame_cnt, const Word16 bfi, Word16 *old_out_fx, // Q(-2) -#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD Word16 *q_old_out_fx, #endif const Word16 FB_flag, @@ -2865,12 +2865,12 @@ void IMDCT_ivas_fx( move16(); Word16 diff = sub( q_tmp_fx_32, q_win ); -#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD Word16 q_old_out_diff = sub( q_tmp_fx_32, *q_old_out_fx ); #endif FOR( Word16 ind = 0; ind < L_frame; ind++ ) { -#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD old_out_fx_32[ind] = L_shl( old_out_fx[ind], q_old_out_diff ); #else old_out_fx_32[ind] = L_shl( old_out_fx[ind], diff ); @@ -2882,7 +2882,7 @@ void IMDCT_ivas_fx( FOR( Word16 ind = 0; ind < L_frame; ind++ ) { -#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD old_out_fx[ind] = extract_l( L_shr( old_out_fx_32[ind], q_old_out_diff ) ); #else old_out_fx[ind] = extract_l( L_shr( old_out_fx_32[ind], diff ) ); @@ -2897,7 +2897,8 @@ void IMDCT_ivas_fx( #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT Scale_sig32( x_fx, L_frame, 1 ); q_xn_buf_fx_32++; -#else +#endif +#ifndef FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD Word16 q_old_out = q_win; #endif move16(); @@ -2923,7 +2924,7 @@ void IMDCT_ivas_fx( move16(); } -#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD window_ola_fx( tmp_fx_32, xn_buf_fx, &q_tmp_fx_32, old_out_fx, q_old_out_fx, L_frame, hTcxCfg->tcx_last_overlap_mode, hTcxCfg->tcx_curr_overlap_mode, 0, 0, NULL ); #else window_ola_fx( tmp_fx_32, xn_buf_fx, &q_tmp_fx_32, old_out_fx, &q_old_out, L_frame, hTcxCfg->tcx_last_overlap_mode, hTcxCfg->tcx_curr_overlap_mode, 0, 0, NULL ); @@ -2934,7 +2935,7 @@ void IMDCT_ivas_fx( Word16 diff = sub( q_tmp_fx_32, q_win ); FOR( Word16 ind = 0; ind < L_frame; ind++ ) { -#ifndef FIX_1348_BIT_PRECISION_IMPROVEMENT +#ifndef FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD old_out_fx[ind] = shr_sat( old_out_fx[ind], q_diff ); move16(); #endif @@ -3029,13 +3030,13 @@ void IMDCT_ivas_fx( IF( hTcxCfg->last_aldo != 0 ) { -#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD Word16 tmp_old_out; Word16 q_diff = sub( *q_old_out_fx, q_win ); #endif FOR( i = 0; i < sub( overlap, tcx_mdct_window_min_length ); i++ ) { -#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD tmp_old_out = shr_sat( old_out_fx[( i + nz )], q_diff ); xn_buf_fx[( i + ( ( overlap / 2 ) - tcx_offset ) )] = add_sat( xn_buf_fx[( i + ( ( overlap / 2 ) - tcx_offset ) )], tmp_old_out ); // Q(-2) #else @@ -3053,7 +3054,7 @@ void IMDCT_ivas_fx( // tested FOR( ; i < overlap; i++ ) /* perfectly reconstructing ALDO shortening */ { -#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD tmp_old_out = shr_sat( old_out_fx[( i + nz )], q_diff ); xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )] = add_sat( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], tmp_old_out ); // Q(-2) #else @@ -3063,7 +3064,7 @@ void IMDCT_ivas_fx( } FOR( i = 0; i < ( tcx_mdct_window_min_length / 2 ); i++ ) { -#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD tmp_old_out = shr_sat( old_out_fx[( ( i + nz ) + overlap )], q_diff ); xn_buf_fx[( ( ( i + ( overlap / 2 ) ) - tcx_offset ) + overlap )] = add_sat( xn_buf_fx[( ( ( i + ( overlap / 2 ) ) - tcx_offset ) + overlap )], mult_r( tmp_old_out, tcx_mdct_window_minimum_fx[i].v.re ) ); // Q(-2) #else @@ -3073,7 +3074,7 @@ void IMDCT_ivas_fx( } FOR( ; i < tcx_mdct_window_min_length; i++ ) { -#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD tmp_old_out = shr_sat( old_out_fx[( ( i + nz ) + overlap )], q_diff ); xn_buf_fx[( ( ( i + ( overlap / 2 ) ) - tcx_offset ) + overlap )] = add_sat( xn_buf_fx[( ( ( i + ( overlap / 2 ) ) - tcx_offset ) + overlap )], mult_r( tmp_old_out, tcx_mdct_window_minimum_fx[( tcx_mdct_window_min_length - ( 1 + i ) )].v.im ) ); // Q(-2) #else @@ -3086,7 +3087,7 @@ void IMDCT_ivas_fx( { FOR( ; i < ( overlap - ( tcx_mdct_window_min_length / 2 ) ); i++ ) { -#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD tmp_old_out = shr_sat( old_out_fx[( i + nz )], q_diff ); xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )] = add_sat( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], mult_r( tmp_old_out, tcx_mdct_window_minimum_fx[( ( tcx_mdct_window_min_length - overlap ) + i )].v.re ) ); // Q(-2) #else @@ -3096,7 +3097,7 @@ void IMDCT_ivas_fx( } FOR( ; i < overlap; i++ ) { -#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD tmp_old_out = shr_sat( old_out_fx[( i + nz )], q_diff ); xn_buf_fx[( i + ( ( overlap / 2 ) - tcx_offset ) )] = add_sat( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], mult_r( tmp_old_out, tcx_mdct_window_minimum_fx[( overlap - ( 1 + i ) )].v.im ) ); // Q(-2) #else @@ -3150,7 +3151,7 @@ void IMDCT_ivas_fx( /* Compute windowed synthesis in case of switching to ALDO windows in next frame */ Copy( xn_buf_fx + sub( L_frame, nz ), old_out_fx, add( nz, overlap ) ); set16_fx( old_out_fx + add( nz, overlap ), 0, nz ); -#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD *q_old_out_fx = q_win; #endif tcx_windowing_synthesis_past_frame( old_out_fx + nz, tcx_aldo_window_1_trunc_fx, tcx_mdct_window_half_fx, tcx_mdct_window_minimum_fx, overlap, tcx_mdct_window_half_length, tcx_mdct_window_min_length, hTcxCfg->tcx_curr_overlap_mode ); @@ -5257,7 +5258,7 @@ void decoder_tcx_imdct_fx( IMDCT_ivas_fx( xn_bufFB_fx, q_x, hTcxDec->syn_Overl, hTcxDec->syn_Overl_TDAC, xn_buf_fx, hTcxCfg->tcx_aldo_window_1, hTcxCfg->tcx_aldo_window_1_trunc, hTcxCfg->tcx_aldo_window_2, hTcxCfg->tcx_mdct_window_half, hTcxCfg->tcx_mdct_window_minimum, hTcxCfg->tcx_mdct_window_trans, hTcxCfg->tcx_mdct_window_half_length, hTcxCfg->tcx_mdct_window_min_length, index, -#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD kernelType, left_rect, tcx_offset, overlap, L_frame, L_frameTCX, shr( s_max( L_frameTCX, L_spec ), 1 ), L_frame_glob, frame_cnt, bfi, st->hHQ_core->old_out_LB_fx, &st->hHQ_core->q_old_out_LB_fx, 0, st, 0, acelp_zir_fx, q_win ); #else kernelType, left_rect, tcx_offset, overlap, L_frame, L_frameTCX, shr( s_max( L_frameTCX, L_spec ), 1 ), L_frame_glob, frame_cnt, bfi, st->hHQ_core->old_out_LB_fx, 0, st, 0, acelp_zir_fx, q_win ); @@ -5283,7 +5284,7 @@ void decoder_tcx_imdct_fx( Copy32( x_fx, xn_bufFB_fx, s_max( L_spec, s_max( L_frame, L_frameTCX ) ) ); // q_x IMDCT_ivas_fx( xn_bufFB_fx, q_x, hTcxDec->syn_Overl, hTcxDec->syn_Overl_TDAC, xn_buf_fx, hTcxCfg->tcx_aldo_window_1, hTcxCfg->tcx_aldo_window_1_trunc, hTcxCfg->tcx_aldo_window_2, hTcxCfg->tcx_mdct_window_half, hTcxCfg->tcx_mdct_window_minimum, hTcxCfg->tcx_mdct_window_trans, hTcxCfg->tcx_mdct_window_half_length, hTcxCfg->tcx_mdct_window_min_length, index, -#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD kernelType, left_rect, tcx_offset, overlap, L_frame, L_frameTCX, shr( s_max( L_frameTCX, L_spec ), 1 ), L_frame_glob, frame_cnt, bfi, st->hHQ_core->old_out_LB_fx, &st->hHQ_core->q_old_out_LB_fx, 0, st, 0, acelp_zir_fx, q_win ); #else kernelType, left_rect, tcx_offset, overlap, L_frame, L_frameTCX, shr( s_max( L_frameTCX, L_spec ), 1 ), L_frame_glob, frame_cnt, bfi, st->hHQ_core->old_out_LB_fx, 0, st, 0, acelp_zir_fx, q_win ); @@ -5304,7 +5305,7 @@ void decoder_tcx_imdct_fx( { IMDCT_ivas_fx( x_tmp_fx, q_x, hTcxDec->syn_OverlFB, hTcxDec->syn_Overl_TDACFB, xn_bufFB_fx_16, hTcxCfg->tcx_aldo_window_1_FB, hTcxCfg->tcx_aldo_window_1_FB_trunc, hTcxCfg->tcx_aldo_window_2_FB, hTcxCfg->tcx_mdct_window_halfFB, hTcxCfg->tcx_mdct_window_minimumFB, hTcxCfg->tcx_mdct_window_transFB, hTcxCfg->tcx_mdct_window_half_lengthFB, hTcxCfg->tcx_mdct_window_min_lengthFB, index, -#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD kernelType, left_rect, tcx_offsetFB, overlapFB, L_frameTCX, L_frameTCX, shr( s_max( L_frameTCX, L_spec ), 1 ), L_frameTCX_glob, frame_cnt, bfi, st->hHQ_core->old_out_fx, &st->hHQ_core->q_old_out_fx, 1, st, ratio, acelp_zir_fx, q_win ); #else kernelType, left_rect, tcx_offsetFB, overlapFB, L_frameTCX, L_frameTCX, shr( s_max( L_frameTCX, L_spec ), 1 ), L_frameTCX_glob, frame_cnt, bfi, st->hHQ_core->old_out_fx, 1, st, ratio, acelp_zir_fx, q_win ); @@ -5314,7 +5315,7 @@ void decoder_tcx_imdct_fx( { IMDCT_ivas_fx( x_fx, q_x, hTcxDec->syn_OverlFB, hTcxDec->syn_Overl_TDACFB, xn_bufFB_fx_16, hTcxCfg->tcx_aldo_window_1_FB, hTcxCfg->tcx_aldo_window_1_FB_trunc, hTcxCfg->tcx_aldo_window_2_FB, hTcxCfg->tcx_mdct_window_halfFB, hTcxCfg->tcx_mdct_window_minimumFB, hTcxCfg->tcx_mdct_window_transFB, hTcxCfg->tcx_mdct_window_half_lengthFB, hTcxCfg->tcx_mdct_window_min_lengthFB, index, -#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD kernelType, left_rect, tcx_offsetFB, overlapFB, L_frameTCX, L_frameTCX, shr( s_max( L_frameTCX, L_spec ), 1 ), L_frameTCX_glob, frame_cnt, bfi, st->hHQ_core->old_out_fx, &st->hHQ_core->q_old_out_fx, 1, st, ratio, acelp_zir_fx, q_win ); #else kernelType, left_rect, tcx_offsetFB, overlapFB, L_frameTCX, L_frameTCX, shr( s_max( L_frameTCX, L_spec ), 1 ), L_frameTCX_glob, frame_cnt, bfi, st->hHQ_core->old_out_fx, 1, st, ratio, acelp_zir_fx, q_win ); diff --git a/lib_dec/hq_core_dec_fx.c b/lib_dec/hq_core_dec_fx.c index c4bbc3128..7d2a3c7a5 100644 --- a/lib_dec/hq_core_dec_fx.c +++ b/lib_dec/hq_core_dec_fx.c @@ -1202,7 +1202,7 @@ void HQ_core_dec_init_fx( hHQ_core->Q_old_wtda = 15; hHQ_core->Q_old_postdec = 0; hHQ_core->Q_old_wtda_LB = 0; -#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD hHQ_core->q_old_out_fx = 0; hHQ_core->q_old_out_LB_fx = 0; #endif diff --git a/lib_dec/ivas_mdct_core_dec_fx.c b/lib_dec/ivas_mdct_core_dec_fx.c index 7459b3789..af37ce751 100644 --- a/lib_dec/ivas_mdct_core_dec_fx.c +++ b/lib_dec/ivas_mdct_core_dec_fx.c @@ -1178,7 +1178,7 @@ void ivas_mdct_core_reconstruct_fx( st->hTcxDec->Q_old_syn_Overl = q_win; Scale_sig( st->hTcxDec->syn_Overl, L_FRAME32k / 2, sub( q_win, st->Q_syn ) ); // Q(st->Q_syn) -> q_win Scale_sig( st->hTcxDec->syn_OverlFB, L_FRAME_MAX / 2, sub( q_win, st->Q_syn ) ); // Q(st->Q_syn) -> q_win -#ifndef FIX_1348_BIT_PRECISION_IMPROVEMENT +#ifndef FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD Scale_sig( st->hHQ_core->old_out_LB_fx, L_FRAME32k, sub( q_win, st->hHQ_core->Q_old_wtda_LB ) ); // Q(st->hHQ_core->Q_old_wtda_LB) -> q_win Scale_sig( st->hHQ_core->old_out_fx, L_FRAME48k, sub( q_win, st->hHQ_core->Q_old_wtda ) ); // Q(st->hHQ_core->Q_old_wtda) -> q_win #endif @@ -1212,7 +1212,7 @@ void ivas_mdct_core_reconstruct_fx( /* Note: these buffers are not subframe-based, hence no indexing with k */ set16_fx( &st->hHQ_core->old_out_LB_fx[0], 0, L_frame[ch] ); set16_fx( &st->hHQ_core->old_out_fx[0], 0, L_frameTCX[ch] ); -#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD st->hHQ_core->q_old_out_LB_fx = 0; st->hHQ_core->q_old_out_fx = 0; #endif @@ -1256,7 +1256,7 @@ void ivas_mdct_core_reconstruct_fx( Scale_sig( st->syn, M + 1, add( st->Q_syn, 2 ) ); Scale_sig( st->hTcxDec->syn_OverlFB, L_FRAME_MAX / 2, sub( st->Q_syn, q_win ) ); // q_win -> st->Q_syn Scale_sig( st->hTcxDec->syn_Overl, L_FRAME32k / 2, sub( st->Q_syn, q_win ) ); // q_win -> st->Q_syn -#ifndef FIX_1348_BIT_PRECISION_IMPROVEMENT +#ifndef FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD Scale_sig( st->hHQ_core->old_out_LB_fx, L_FRAME32k, sub( st->Q_syn, q_win ) ); // q_win -> st->Q_syn Scale_sig( st->hHQ_core->old_out_fx, L_FRAME48k, sub( st->Q_syn, q_win ) ); // q_win -> st->Q_syn #endif diff --git a/lib_dec/stat_dec.h b/lib_dec/stat_dec.h index a32bcfd6e..84f8d83bd 100644 --- a/lib_dec/stat_dec.h +++ b/lib_dec/stat_dec.h @@ -702,7 +702,7 @@ typedef struct hq_dec_structure Word16 exp_old_out; Word16 old_out_LB_fx[L_FRAME32k]; /* HQ core - previous synthesis for OLA for Low Band */ Word32 old_out_LB_fx32[L_FRAME32k]; -#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD Word16 q_old_out_LB_fx; Word16 q_old_out_fx; #endif -- GitLab From c8695f623da545bf0acd7c6deea6cb33b268755e Mon Sep 17 00:00:00 2001 From: naghibza Date: Thu, 3 Apr 2025 14:30:19 +0200 Subject: [PATCH 005/113] Removed scaling of input in IMDCT_ivas_fx(). Activated dynamic q_old_out. Restored q_win to its previous value. --- lib_com/options.h | 4 ++-- lib_dec/dec_tcx_fx.c | 4 ---- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index b5a3bbb3e..2b0a2ad0e 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -78,6 +78,6 @@ #define HARM_PUSH_BIT #define HARM_ENC_INIT //#define HARM_SCE_INIT -#define FIX_1348_BIT_PRECISION_IMPROVEMENT -//#define FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD +//#define FIX_1348_BIT_PRECISION_IMPROVEMENT +#define FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD #endif diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index f3c84770f..f97455c65 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -2894,10 +2894,6 @@ void IMDCT_ivas_fx( } ELSE { -#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT - Scale_sig32( x_fx, L_frame, 1 ); - q_xn_buf_fx_32++; -#endif #ifndef FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD Word16 q_old_out = q_win; #endif -- GitLab From 384150d0cd440d404fa8fc264556268a084144c7 Mon Sep 17 00:00:00 2001 From: naghibza Date: Thu, 3 Apr 2025 15:18:59 +0200 Subject: [PATCH 006/113] Deactivated all changes to check the pipeline results. --- lib_com/options.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_com/options.h b/lib_com/options.h index 2b0a2ad0e..90138fe5e 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -79,5 +79,5 @@ #define HARM_ENC_INIT //#define HARM_SCE_INIT //#define FIX_1348_BIT_PRECISION_IMPROVEMENT -#define FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD +//#define FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD #endif -- GitLab From 7e4ed16664a0de6dbddb31bd5f549d5e9280146e Mon Sep 17 00:00:00 2001 From: naghibza Date: Fri, 4 Apr 2025 08:47:55 +0200 Subject: [PATCH 007/113] Activated q_win modification. --- lib_com/options.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_com/options.h b/lib_com/options.h index 90138fe5e..b5a3bbb3e 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -78,6 +78,6 @@ #define HARM_PUSH_BIT #define HARM_ENC_INIT //#define HARM_SCE_INIT -//#define FIX_1348_BIT_PRECISION_IMPROVEMENT +#define FIX_1348_BIT_PRECISION_IMPROVEMENT //#define FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD #endif -- GitLab From 9d4e2a2efa9dbcf38fd0f3ee9a35b1a4b91f62af Mon Sep 17 00:00:00 2001 From: naghibza Date: Thu, 10 Apr 2025 11:49:14 +0200 Subject: [PATCH 008/113] Fixed an error in the transition from MDCT to ACELP --- lib_dec/ivas_mdct_core_dec_fx.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib_dec/ivas_mdct_core_dec_fx.c b/lib_dec/ivas_mdct_core_dec_fx.c index af37ce751..177f49180 100644 --- a/lib_dec/ivas_mdct_core_dec_fx.c +++ b/lib_dec/ivas_mdct_core_dec_fx.c @@ -1264,6 +1264,9 @@ void ivas_mdct_core_reconstruct_fx( move16(); st->hHQ_core->Q_old_wtda_LB = st->Q_syn; move16(); +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT + Scale_sig( st->mem_syn2_fx, M, -1 ); // -1 should be calculated from q_win. +#endif } ELSE /*ACELP core for ACELP-PLC */ { -- GitLab From 8a71640db2e9a2f8f628f0e8254d0fbfb863c3b8 Mon Sep 17 00:00:00 2001 From: naghibza Date: Thu, 10 Apr 2025 11:54:03 +0200 Subject: [PATCH 009/113] Applied Clang formatting patch. --- lib_dec/ivas_mdct_core_dec_fx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_dec/ivas_mdct_core_dec_fx.c b/lib_dec/ivas_mdct_core_dec_fx.c index 177f49180..77673c3bb 100644 --- a/lib_dec/ivas_mdct_core_dec_fx.c +++ b/lib_dec/ivas_mdct_core_dec_fx.c @@ -1265,7 +1265,7 @@ void ivas_mdct_core_reconstruct_fx( st->hHQ_core->Q_old_wtda_LB = st->Q_syn; move16(); #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT - Scale_sig( st->mem_syn2_fx, M, -1 ); // -1 should be calculated from q_win. + Scale_sig( st->mem_syn2_fx, M, -1 ); // -1 should be calculated from q_win. #endif } ELSE /*ACELP core for ACELP-PLC */ -- GitLab From 8ddf7cffc690abab7f0c07a0f9cd849f8157536a Mon Sep 17 00:00:00 2001 From: naghibza Date: Thu, 17 Apr 2025 10:48:53 +0200 Subject: [PATCH 010/113] Applied rounding to old_out. Deactivated q_win change and dynamic_q_old_out. --- lib_com/options.h | 3 ++- lib_dec/dec_tcx_fx.c | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib_com/options.h b/lib_com/options.h index 8ee484111..e4ee8714b 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -84,6 +84,7 @@ //#define HARM_SCE_INIT #define DIV32_OPT_NEWTON /* FhG: faster 32 by 32 bit division */ #define MERGE_REQUEST_1378_SPEEDUP_ivas_mc_param_enc_fx_NONBE /* FhG: reduce WMOPS of Cy calculation in ivas_param_mc_param_est_enc_fx() by using 64 Bit addition. Obsoletes IMPROVE_HIGH_COMPLEXITY_PARAM_MC_PRM_EST_NONBE. */ -#define FIX_1348_BIT_PRECISION_IMPROVEMENT +//#define FIX_1348_BIT_PRECISION_IMPROVEMENT //#define FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD +#define FIX_1348_BIT_PRECISION_IMPROVEMENT_ROUND_OLD_BUFF #endif diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index f97455c65..e9d34660f 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -2932,7 +2932,12 @@ void IMDCT_ivas_fx( FOR( Word16 ind = 0; ind < L_frame; ind++ ) { #ifndef FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD + +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_ROUND_OLD_BUFF + old_out_fx[ind] = shr_r( old_out_fx[ind], q_diff ); +#else old_out_fx[ind] = shr_sat( old_out_fx[ind], q_diff ); +#endif move16(); #endif xn_buf_fx[ind] = shr_sat( xn_buf_fx[ind], diff ); -- GitLab From c703a1f62500154dc54f176bf33ca1fd69144076 Mon Sep 17 00:00:00 2001 From: naghibza Date: Thu, 17 Apr 2025 11:30:26 +0200 Subject: [PATCH 011/113] Replaced shr_r with shr_r_sat. Deactivated all changes. --- lib_com/options.h | 2 +- lib_dec/dec_tcx_fx.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 5caec3cdf..8540a9300 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -99,5 +99,5 @@ //#define FIX_1348_BIT_PRECISION_IMPROVEMENT //#define FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD -#define FIX_1348_BIT_PRECISION_IMPROVEMENT_ROUND_OLD_BUFF +//#define FIX_1348_BIT_PRECISION_IMPROVEMENT_ROUND_OLD_BUFF #endif diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index e9d34660f..56f2b2e6b 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -2934,7 +2934,7 @@ void IMDCT_ivas_fx( #ifndef FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_ROUND_OLD_BUFF - old_out_fx[ind] = shr_r( old_out_fx[ind], q_diff ); + old_out_fx[ind] = shr_r_sat( old_out_fx[ind], q_diff ); #else old_out_fx[ind] = shr_sat( old_out_fx[ind], q_diff ); #endif -- GitLab From 6c3c58e60b677cdd1a2b4b9dd339c3c4c44f1fcf Mon Sep 17 00:00:00 2001 From: Manuel Jander Date: Wed, 23 Apr 2025 10:42:57 +0200 Subject: [PATCH 012/113] Make q_win dependent on multichannel mode to avoid saturation of downmix signals. --- lib_com/options.h | 4 ++-- lib_com/prot_fx.h | 3 +++ lib_dec/ivas_mct_dec_fx.c | 4 ++++ lib_dec/ivas_mdct_core_dec_fx.c | 10 +++++++++- lib_dec/ivas_stereo_mdct_core_dec_fx.c | 4 ++++ 5 files changed, 22 insertions(+), 3 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 62cf19b7c..1f0f7c641 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -98,7 +98,7 @@ #define TEST_HR #define REMOVE_EVS_DUPLICATES /* remove core-coder duplicated functions, ACELP low-band decoder */ -//#define FIX_1348_BIT_PRECISION_IMPROVEMENT -//#define FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD +#define FIX_1348_BIT_PRECISION_IMPROVEMENT +#define FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD //#define FIX_1348_BIT_PRECISION_IMPROVEMENT_ROUND_OLD_BUFF #endif diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 924a9955b..42fa6da76 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -10004,6 +10004,9 @@ void ivas_mdct_core_reconstruct_fx( /* o : synthesis @output_FS */ // e_sig Word16 fUseTns[CPE_CHANNELS][NB_DIV], /* i : flage TNS enabled */ const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0)*/ +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT + const Word16 isParamMC, +#endif Word16 q_x, Word16 e_sig[CPE_CHANNELS] ); diff --git a/lib_dec/ivas_mct_dec_fx.c b/lib_dec/ivas_mct_dec_fx.c index 32403b11a..058b57593 100644 --- a/lib_dec/ivas_mct_dec_fx.c +++ b/lib_dec/ivas_mct_dec_fx.c @@ -346,7 +346,11 @@ ivas_error ivas_mct_dec_fx( } Copy_Scale_sig_16_32_no_sat( hCPE->hCoreCoder[0]->old_Aq_12_8_fx, hCPE->hCoreCoder[0]->old_Aq_12_8_fx_32, add( M, 1 ), sub( 28, sub( 15, norm_s( sub( hCPE->hCoreCoder[0]->old_Aq_12_8_fx[0], 1 ) ) ) ) ); Copy_Scale_sig_16_32_no_sat( hCPE->hCoreCoder[1]->old_Aq_12_8_fx, hCPE->hCoreCoder[1]->old_Aq_12_8_fx_32, add( M, 1 ), sub( 28, sub( 15, norm_s( sub( hCPE->hCoreCoder[1]->old_Aq_12_8_fx[0], 1 ) ) ) ) ); +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT + ivas_mdct_core_reconstruct_fx( hCPE, x_fx, synth_fx, fUseTns[cpe_id], 1, st_ivas->mc_mode == MC_MODE_PARAMMC, q_output, e_sig ); +#else ivas_mdct_core_reconstruct_fx( hCPE, x_fx, synth_fx, fUseTns[cpe_id], 1, q_output, e_sig ); +#endif Word16 hdrm, sh; hdrm = getScaleFactor16( synth_fx[0], hCPE->hCoreCoder[0]->hTcxDec->L_frameTCX ); diff --git a/lib_dec/ivas_mdct_core_dec_fx.c b/lib_dec/ivas_mdct_core_dec_fx.c index 77673c3bb..6c527e9ce 100644 --- a/lib_dec/ivas_mdct_core_dec_fx.c +++ b/lib_dec/ivas_mdct_core_dec_fx.c @@ -1083,6 +1083,9 @@ void ivas_mdct_core_reconstruct_fx( /* o : synthesis @output_FS */ // e_sig Word16 fUseTns[CPE_CHANNELS][NB_DIV], /* i : flage TNS enabled */ const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0)*/ +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT + const Word16 isParamMC, +#endif Word16 q_x, Word16 e_sig[CPE_CHANNELS] ) { @@ -1122,6 +1125,11 @@ void ivas_mdct_core_reconstruct_fx( bfi = sts[0]->bfi; move16(); +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT + if ( isParamMC ) + q_win = -2; +#endif + /* TNS, ITF, IMDCT and updates */ FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) { @@ -1265,7 +1273,7 @@ void ivas_mdct_core_reconstruct_fx( st->hHQ_core->Q_old_wtda_LB = st->Q_syn; move16(); #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT - Scale_sig( st->mem_syn2_fx, M, -1 ); // -1 should be calculated from q_win. + Scale_sig( st->mem_syn2_fx, M, sub( negate( q_win ), 2 ) ); #endif } ELSE /*ACELP core for ACELP-PLC */ diff --git a/lib_dec/ivas_stereo_mdct_core_dec_fx.c b/lib_dec/ivas_stereo_mdct_core_dec_fx.c index 890e5fc9e..fd9398769 100644 --- a/lib_dec/ivas_stereo_mdct_core_dec_fx.c +++ b/lib_dec/ivas_stereo_mdct_core_dec_fx.c @@ -550,7 +550,11 @@ void stereo_mdct_core_dec_fx( } Copy_Scale_sig_16_32_no_sat( hCPE->hCoreCoder[0]->old_Aq_12_8_fx, hCPE->hCoreCoder[0]->old_Aq_12_8_fx_32, M + 1, sub( 28, sub( 15, norm_s( sub( hCPE->hCoreCoder[0]->old_Aq_12_8_fx[0], 1 ) ) ) ) ); /* Q28 */ Copy_Scale_sig_16_32_no_sat( hCPE->hCoreCoder[1]->old_Aq_12_8_fx, hCPE->hCoreCoder[1]->old_Aq_12_8_fx_32, M + 1, sub( 28, sub( 15, norm_s( sub( hCPE->hCoreCoder[1]->old_Aq_12_8_fx[0], 1 ) ) ) ) ); /* Q28 */ +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT + ivas_mdct_core_reconstruct_fx( hCPE, x_fx, signal_outFB_tmp_fx, fUseTns, 0, st_ivas->mc_mode == MC_MODE_PARAMMC, Q11, e_sigFB ); +#else ivas_mdct_core_reconstruct_fx( hCPE, x_fx, signal_outFB_tmp_fx, fUseTns, 0, Q11, e_sigFB ); +#endif Copy32( signal_out_tmp_fx[0], signal_out_fx[0], L_FRAME48k ); /* Q11 */ Copy32( signal_out_tmp_fx[1], signal_out_fx[1], L_FRAME48k ); /* Q11 */ -- GitLab From 88b7a0ddcb1027f59e41c5fe146c96f0466fd8cb Mon Sep 17 00:00:00 2001 From: Manuel Jander Date: Wed, 23 Apr 2025 19:16:09 +0200 Subject: [PATCH 013/113] Change st->hHQ_core->Q_old_wtda_LB to st->hHQ_core->q_old_out_LB_fx since with FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD active it is not st->Q_syn anymore. Fixes TCX to ACELP transition. --- lib_dec/dec_tcx_fx.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index 56f2b2e6b..070d129c5 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -3686,10 +3686,17 @@ void decoder_tcx_ivas_fx( Scale_sig( synth_fx, L_frame_glob, negate( st->Q_syn ) ); Scale_sig( synthFB_fx, L_frameTCX_glob, negate( st->Q_syn ) ); // Scale_sig( st->hTcxDec->syn_Overl, L_FRAME32k / 2, 1 ); +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD + st->hHQ_core->Q_old_wtda = st->hHQ_core->q_old_out_fx; + // Scale_sig( st->hHQ_core->old_out_LB_fx, L_FRAME32k, ( sub( st->hHQ_core->Q_old_wtda, st->Q_syn ) ) ); + st->hHQ_core->Q_old_wtda_LB = st->hHQ_core->q_old_out_LB_fx; + // Scale_sig( st->hHQ_core->old_out_fx, L_FRAME48k, ( sub( st->hHQ_core->Q_old_wtda, st->Q_syn ) ) ); +#else st->hHQ_core->Q_old_wtda = st->Q_syn; // Scale_sig( st->hHQ_core->old_out_LB_fx, L_FRAME32k, ( sub( st->hHQ_core->Q_old_wtda, st->Q_syn ) ) ); st->hHQ_core->Q_old_wtda_LB = st->Q_syn; // Scale_sig( st->hHQ_core->old_out_fx, L_FRAME48k, ( sub( st->hHQ_core->Q_old_wtda, st->Q_syn ) ) ); +#endif Scale_sig( st->hTcxDec->old_syn_Overl, 320, ( -2 - st->hTcxDec->Q_old_syn_Overl ) ); // Scaling to Q-2 st->hTcxDec->Q_old_syn_Overl = -2; } -- GitLab From 1b02d8c28c0816e04778013bce56b2dcaa8c7144 Mon Sep 17 00:00:00 2001 From: Manuel Jander Date: Thu, 24 Apr 2025 23:54:38 +0200 Subject: [PATCH 014/113] Remove all q_old_out_something variables and use Q_old_wtda/Q_old_wtda_LB instead. Cleanup some not needed rescaling of old_out buffers. Resolves some regression cases. --- lib_dec/dec_tcx_fx.c | 21 +++++++++------------ lib_dec/hq_core_dec_fx.c | 4 ---- lib_dec/ivas_core_dec_fx.c | 2 ++ lib_dec/ivas_cpe_dec_fx.c | 2 ++ lib_dec/ivas_jbm_dec_fx.c | 7 ++++++- lib_dec/ivas_mdct_core_dec_fx.c | 16 ++++++++++------ lib_dec/ivas_post_proc_fx.c | 4 ++++ lib_dec/stat_dec.h | 10 ++++------ 8 files changed, 37 insertions(+), 29 deletions(-) diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index 070d129c5..fc8fda9ad 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -3665,12 +3665,14 @@ void decoder_tcx_ivas_fx( Scale_sig( st->hTcxDec->syn_Overl_TDAC, L_FRAME32k / 2, sub( st->Q_syn, st->hTcxDec->Q_syn_Overl_TDAC ) ); // Scaling to Q_syn st->hTcxDec->Q_syn_Overl_TDAC = st->Q_syn; move16(); - Scale_sig( st->hHQ_core->old_out_fx, L_FRAME48k, negate( st->hHQ_core->Q_old_wtda ) ); // Scaling to Q_syn - Scale_sig( st->hHQ_core->old_out_LB_fx, L_FRAME32k, negate( st->hHQ_core->Q_old_wtda_LB ) ); // Scaling to Q_syn +#ifndef FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD + Scale_sig( st->hHQ_core->old_out_fx, L_FRAME48k, negate( st->hHQ_core->Q_old_wtda ) ); // Scaling to Q0 + Scale_sig( st->hHQ_core->old_out_LB_fx, L_FRAME32k, negate( st->hHQ_core->Q_old_wtda_LB ) ); // Scaling to Q0 st->hHQ_core->Q_old_wtda = 0; move16(); st->hHQ_core->Q_old_wtda_LB = 0; move16(); +#endif Scale_sig( st->hTcxDec->old_syn_Overl, 320, st->Q_syn - st->hTcxDec->Q_old_syn_Overl ); // Scaling to Q_syn st->hTcxDec->Q_old_syn_Overl = st->Q_syn; @@ -3686,12 +3688,7 @@ void decoder_tcx_ivas_fx( Scale_sig( synth_fx, L_frame_glob, negate( st->Q_syn ) ); Scale_sig( synthFB_fx, L_frameTCX_glob, negate( st->Q_syn ) ); // Scale_sig( st->hTcxDec->syn_Overl, L_FRAME32k / 2, 1 ); -#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD - st->hHQ_core->Q_old_wtda = st->hHQ_core->q_old_out_fx; - // Scale_sig( st->hHQ_core->old_out_LB_fx, L_FRAME32k, ( sub( st->hHQ_core->Q_old_wtda, st->Q_syn ) ) ); - st->hHQ_core->Q_old_wtda_LB = st->hHQ_core->q_old_out_LB_fx; - // Scale_sig( st->hHQ_core->old_out_fx, L_FRAME48k, ( sub( st->hHQ_core->Q_old_wtda, st->Q_syn ) ) ); -#else +#ifndef FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD st->hHQ_core->Q_old_wtda = st->Q_syn; // Scale_sig( st->hHQ_core->old_out_LB_fx, L_FRAME32k, ( sub( st->hHQ_core->Q_old_wtda, st->Q_syn ) ) ); st->hHQ_core->Q_old_wtda_LB = st->Q_syn; @@ -5267,7 +5264,7 @@ void decoder_tcx_imdct_fx( IMDCT_ivas_fx( xn_bufFB_fx, q_x, hTcxDec->syn_Overl, hTcxDec->syn_Overl_TDAC, xn_buf_fx, hTcxCfg->tcx_aldo_window_1, hTcxCfg->tcx_aldo_window_1_trunc, hTcxCfg->tcx_aldo_window_2, hTcxCfg->tcx_mdct_window_half, hTcxCfg->tcx_mdct_window_minimum, hTcxCfg->tcx_mdct_window_trans, hTcxCfg->tcx_mdct_window_half_length, hTcxCfg->tcx_mdct_window_min_length, index, #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD - kernelType, left_rect, tcx_offset, overlap, L_frame, L_frameTCX, shr( s_max( L_frameTCX, L_spec ), 1 ), L_frame_glob, frame_cnt, bfi, st->hHQ_core->old_out_LB_fx, &st->hHQ_core->q_old_out_LB_fx, 0, st, 0, acelp_zir_fx, q_win ); + kernelType, left_rect, tcx_offset, overlap, L_frame, L_frameTCX, shr( s_max( L_frameTCX, L_spec ), 1 ), L_frame_glob, frame_cnt, bfi, st->hHQ_core->old_out_LB_fx, &st->hHQ_core->Q_old_wtda_LB, 0, st, 0, acelp_zir_fx, q_win ); #else kernelType, left_rect, tcx_offset, overlap, L_frame, L_frameTCX, shr( s_max( L_frameTCX, L_spec ), 1 ), L_frame_glob, frame_cnt, bfi, st->hHQ_core->old_out_LB_fx, 0, st, 0, acelp_zir_fx, q_win ); #endif @@ -5293,7 +5290,7 @@ void decoder_tcx_imdct_fx( IMDCT_ivas_fx( xn_bufFB_fx, q_x, hTcxDec->syn_Overl, hTcxDec->syn_Overl_TDAC, xn_buf_fx, hTcxCfg->tcx_aldo_window_1, hTcxCfg->tcx_aldo_window_1_trunc, hTcxCfg->tcx_aldo_window_2, hTcxCfg->tcx_mdct_window_half, hTcxCfg->tcx_mdct_window_minimum, hTcxCfg->tcx_mdct_window_trans, hTcxCfg->tcx_mdct_window_half_length, hTcxCfg->tcx_mdct_window_min_length, index, #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD - kernelType, left_rect, tcx_offset, overlap, L_frame, L_frameTCX, shr( s_max( L_frameTCX, L_spec ), 1 ), L_frame_glob, frame_cnt, bfi, st->hHQ_core->old_out_LB_fx, &st->hHQ_core->q_old_out_LB_fx, 0, st, 0, acelp_zir_fx, q_win ); + kernelType, left_rect, tcx_offset, overlap, L_frame, L_frameTCX, shr( s_max( L_frameTCX, L_spec ), 1 ), L_frame_glob, frame_cnt, bfi, st->hHQ_core->old_out_LB_fx, &st->hHQ_core->Q_old_wtda_LB, 0, st, 0, acelp_zir_fx, q_win ); #else kernelType, left_rect, tcx_offset, overlap, L_frame, L_frameTCX, shr( s_max( L_frameTCX, L_spec ), 1 ), L_frame_glob, frame_cnt, bfi, st->hHQ_core->old_out_LB_fx, 0, st, 0, acelp_zir_fx, q_win ); #endif @@ -5314,7 +5311,7 @@ void decoder_tcx_imdct_fx( IMDCT_ivas_fx( x_tmp_fx, q_x, hTcxDec->syn_OverlFB, hTcxDec->syn_Overl_TDACFB, xn_bufFB_fx_16, hTcxCfg->tcx_aldo_window_1_FB, hTcxCfg->tcx_aldo_window_1_FB_trunc, hTcxCfg->tcx_aldo_window_2_FB, hTcxCfg->tcx_mdct_window_halfFB, hTcxCfg->tcx_mdct_window_minimumFB, hTcxCfg->tcx_mdct_window_transFB, hTcxCfg->tcx_mdct_window_half_lengthFB, hTcxCfg->tcx_mdct_window_min_lengthFB, index, #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD - kernelType, left_rect, tcx_offsetFB, overlapFB, L_frameTCX, L_frameTCX, shr( s_max( L_frameTCX, L_spec ), 1 ), L_frameTCX_glob, frame_cnt, bfi, st->hHQ_core->old_out_fx, &st->hHQ_core->q_old_out_fx, 1, st, ratio, acelp_zir_fx, q_win ); + kernelType, left_rect, tcx_offsetFB, overlapFB, L_frameTCX, L_frameTCX, shr( s_max( L_frameTCX, L_spec ), 1 ), L_frameTCX_glob, frame_cnt, bfi, st->hHQ_core->old_out_fx, &st->hHQ_core->Q_old_wtda, 1, st, ratio, acelp_zir_fx, q_win ); #else kernelType, left_rect, tcx_offsetFB, overlapFB, L_frameTCX, L_frameTCX, shr( s_max( L_frameTCX, L_spec ), 1 ), L_frameTCX_glob, frame_cnt, bfi, st->hHQ_core->old_out_fx, 1, st, ratio, acelp_zir_fx, q_win ); #endif @@ -5324,7 +5321,7 @@ void decoder_tcx_imdct_fx( IMDCT_ivas_fx( x_fx, q_x, hTcxDec->syn_OverlFB, hTcxDec->syn_Overl_TDACFB, xn_bufFB_fx_16, hTcxCfg->tcx_aldo_window_1_FB, hTcxCfg->tcx_aldo_window_1_FB_trunc, hTcxCfg->tcx_aldo_window_2_FB, hTcxCfg->tcx_mdct_window_halfFB, hTcxCfg->tcx_mdct_window_minimumFB, hTcxCfg->tcx_mdct_window_transFB, hTcxCfg->tcx_mdct_window_half_lengthFB, hTcxCfg->tcx_mdct_window_min_lengthFB, index, #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD - kernelType, left_rect, tcx_offsetFB, overlapFB, L_frameTCX, L_frameTCX, shr( s_max( L_frameTCX, L_spec ), 1 ), L_frameTCX_glob, frame_cnt, bfi, st->hHQ_core->old_out_fx, &st->hHQ_core->q_old_out_fx, 1, st, ratio, acelp_zir_fx, q_win ); + kernelType, left_rect, tcx_offsetFB, overlapFB, L_frameTCX, L_frameTCX, shr( s_max( L_frameTCX, L_spec ), 1 ), L_frameTCX_glob, frame_cnt, bfi, st->hHQ_core->old_out_fx, &st->hHQ_core->Q_old_wtda, 1, st, ratio, acelp_zir_fx, q_win ); #else kernelType, left_rect, tcx_offsetFB, overlapFB, L_frameTCX, L_frameTCX, shr( s_max( L_frameTCX, L_spec ), 1 ), L_frameTCX_glob, frame_cnt, bfi, st->hHQ_core->old_out_fx, 1, st, ratio, acelp_zir_fx, q_win ); #endif diff --git a/lib_dec/hq_core_dec_fx.c b/lib_dec/hq_core_dec_fx.c index 7d2a3c7a5..4d1ef6774 100644 --- a/lib_dec/hq_core_dec_fx.c +++ b/lib_dec/hq_core_dec_fx.c @@ -1202,10 +1202,6 @@ void HQ_core_dec_init_fx( hHQ_core->Q_old_wtda = 15; hHQ_core->Q_old_postdec = 0; hHQ_core->Q_old_wtda_LB = 0; -#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD - hHQ_core->q_old_out_fx = 0; - hHQ_core->q_old_out_LB_fx = 0; -#endif move16(); move16(); move16(); diff --git a/lib_dec/ivas_core_dec_fx.c b/lib_dec/ivas_core_dec_fx.c index 320d9d4bc..12259f395 100644 --- a/lib_dec/ivas_core_dec_fx.c +++ b/lib_dec/ivas_core_dec_fx.c @@ -578,12 +578,14 @@ ivas_error ivas_core_dec_fx( /* TCX decoder */ Scale_sig( st->hPFstat->mem_stp, L_SUBFR, -Qsyn_temp ); // Q0 Scale_sig( st->hPFstat->mem_pf_in, L_SUBFR, -Qsyn_temp ); // Q0 +#ifndef FIX_1348_BIT_PRECISION_IMPROVEMENT Scale_sig( st->hHQ_core->old_out_LB_fx, L_FRAME32k, -st->hHQ_core->Q_old_wtda_LB ); // Q0 Scale_sig( st->hHQ_core->old_out_fx, L_FRAME48k, -st->hHQ_core->Q_old_wtda ); // Q0 st->hHQ_core->Q_old_wtda_LB = 0; move16(); st->hHQ_core->Q_old_wtda = 0; move16(); +#endif IF( st_ivas == NULL ) { diff --git a/lib_dec/ivas_cpe_dec_fx.c b/lib_dec/ivas_cpe_dec_fx.c index c10c6beda..dcec695f3 100644 --- a/lib_dec/ivas_cpe_dec_fx.c +++ b/lib_dec/ivas_cpe_dec_fx.c @@ -132,7 +132,9 @@ ivas_error ivas_cpe_dec_fx( IF( hCPE->hCoreCoder[ind1]->hHQ_core ) { Copy_Scale_sig_16_32_no_sat( hCPE->hCoreCoder[ind1]->hHQ_core->old_out_LB_fx, hCPE->hCoreCoder[ind1]->hHQ_core->old_out_LB_fx32, L_FRAME32k, sub( Q11, hCPE->hCoreCoder[ind1]->hHQ_core->Q_old_wtda_LB ) ); // Q11 +#ifndef FIX_1348_BIT_PRECISION_IMPROVEMENT hCPE->hCoreCoder[ind1]->hHQ_core->q_old_outLB_fx = Q11; +#endif move16(); } } diff --git a/lib_dec/ivas_jbm_dec_fx.c b/lib_dec/ivas_jbm_dec_fx.c index 3f67962dc..33d11d380 100644 --- a/lib_dec/ivas_jbm_dec_fx.c +++ b/lib_dec/ivas_jbm_dec_fx.c @@ -434,8 +434,10 @@ ivas_error ivas_jbm_dec_tc_fx( { Copy_Scale_sig_16_32_no_sat( hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx, hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx32, L_FRAME32k, q - hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB ); // q Copy_Scale_sig_16_32_no_sat( hCPE->hCoreCoder[0]->hHQ_core->old_out_fx, hCPE->hCoreCoder[0]->hHQ_core->old_out_fx32, L_FRAME48k, q - hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda ); // q +#ifndef FIX_1348_BIT_PRECISION_IMPROVEMENT hCPE->hCoreCoder[0]->hHQ_core->q_old_outLB_fx = q; move16(); +#endif } IF( hCPE->hStereoDft != NULL ) { @@ -950,8 +952,10 @@ ivas_error ivas_jbm_dec_tc_fx( { Copy_Scale_sig_16_32_no_sat( hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx, hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx32, L_FRAME32k, sub( q, hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB ) ); // q Copy_Scale_sig_16_32_no_sat( hCPE->hCoreCoder[0]->hHQ_core->old_out_fx, hCPE->hCoreCoder[0]->hHQ_core->old_out_fx32, L_FRAME48k, sub( q, hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda ) ); // q +#ifndef FIX_1348_BIT_PRECISION_IMPROVEMENT hCPE->hCoreCoder[0]->hHQ_core->q_old_outLB_fx = q; move16(); +#endif } IF( hCPE->hStereoDft != NULL ) { @@ -996,7 +1000,6 @@ ivas_error ivas_jbm_dec_tc_fx( IF( hCPE->hCoreCoder[0] != NULL ) { - Copy_Scale_sig_32_16( hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx32, hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx, L_FRAME32k, sub( hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB, q ) ); // Q_old_wtda_LB Copy_Scale_sig_32_16( hCPE->hCoreCoder[0]->hHQ_core->old_out_fx32, hCPE->hCoreCoder[0]->hHQ_core->old_out_fx, L_FRAME48k, sub( hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda, q ) ); // Q_old_wtda } @@ -1386,8 +1389,10 @@ ivas_error ivas_jbm_dec_tc_fx( { Copy_Scale_sig_16_32_no_sat( hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx, hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx32, L_FRAME32k, q - hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB ); // q Copy_Scale_sig_16_32_no_sat( hCPE->hCoreCoder[0]->hHQ_core->old_out_fx, hCPE->hCoreCoder[0]->hHQ_core->old_out_fx32, L_FRAME48k, q - hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda ); // q +#ifndef FIX_1348_BIT_PRECISION_IMPROVEMENT hCPE->hCoreCoder[0]->hHQ_core->q_old_outLB_fx = q; move16(); +#endif } IF( hCPE->hStereoDft != NULL ) { diff --git a/lib_dec/ivas_mdct_core_dec_fx.c b/lib_dec/ivas_mdct_core_dec_fx.c index 6c527e9ce..243f6733b 100644 --- a/lib_dec/ivas_mdct_core_dec_fx.c +++ b/lib_dec/ivas_mdct_core_dec_fx.c @@ -1186,9 +1186,13 @@ void ivas_mdct_core_reconstruct_fx( st->hTcxDec->Q_old_syn_Overl = q_win; Scale_sig( st->hTcxDec->syn_Overl, L_FRAME32k / 2, sub( q_win, st->Q_syn ) ); // Q(st->Q_syn) -> q_win Scale_sig( st->hTcxDec->syn_OverlFB, L_FRAME_MAX / 2, sub( q_win, st->Q_syn ) ); // Q(st->Q_syn) -> q_win -#ifndef FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD Scale_sig( st->hHQ_core->old_out_LB_fx, L_FRAME32k, sub( q_win, st->hHQ_core->Q_old_wtda_LB ) ); // Q(st->hHQ_core->Q_old_wtda_LB) -> q_win Scale_sig( st->hHQ_core->old_out_fx, L_FRAME48k, sub( q_win, st->hHQ_core->Q_old_wtda ) ); // Q(st->hHQ_core->Q_old_wtda) -> q_win +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD + st->hHQ_core->Q_old_wtda = q_win; + move16(); + st->hHQ_core->Q_old_wtda_LB = q_win; + move16(); #endif Scale_sig( synth_buf_fx, add( add( st->hTcxDec->old_synth_len, L_FRAME_PLUS ), M ), sub( q_win, q_syn ) ); // q_syn -> q_win Scale_sig( synth_bufFB_fx, add( add( st->hTcxDec->old_synth_lenFB, L_FRAME_PLUS ), M ), sub( q_win, q_syn ) ); // q_syn -> q_win @@ -1220,9 +1224,9 @@ void ivas_mdct_core_reconstruct_fx( /* Note: these buffers are not subframe-based, hence no indexing with k */ set16_fx( &st->hHQ_core->old_out_LB_fx[0], 0, L_frame[ch] ); set16_fx( &st->hHQ_core->old_out_fx[0], 0, L_frameTCX[ch] ); -#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD - st->hHQ_core->q_old_out_LB_fx = 0; - st->hHQ_core->q_old_out_fx = 0; +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD_NO + st->hHQ_core->Q_old_wtda = Q15; + st->hHQ_core->Q_old_wtda_LB = Q15; #endif set16_fx( &st->hTcxDec->syn_Overl[0], 0, shr( L_frame[ch], 1 ) ); set16_fx( &st->hTcxDec->syn_OverlFB[0], 0, shr( L_frameTCX[ch], 1 ) ); @@ -1267,12 +1271,12 @@ void ivas_mdct_core_reconstruct_fx( #ifndef FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD Scale_sig( st->hHQ_core->old_out_LB_fx, L_FRAME32k, sub( st->Q_syn, q_win ) ); // q_win -> st->Q_syn Scale_sig( st->hHQ_core->old_out_fx, L_FRAME48k, sub( st->Q_syn, q_win ) ); // q_win -> st->Q_syn -#endif st->hHQ_core->Q_old_wtda = st->Q_syn; move16(); st->hHQ_core->Q_old_wtda_LB = st->Q_syn; move16(); -#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT +#endif +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD Scale_sig( st->mem_syn2_fx, M, sub( negate( q_win ), 2 ) ); #endif } diff --git a/lib_dec/ivas_post_proc_fx.c b/lib_dec/ivas_post_proc_fx.c index c0e69b916..b82cc1d00 100644 --- a/lib_dec/ivas_post_proc_fx.c +++ b/lib_dec/ivas_post_proc_fx.c @@ -588,7 +588,11 @@ void stereo_dft_dec_core_switching_fx( Word32 tmp_fade_fx[max( STEREO_DFT_ALLPASS_FADELEN_12k8, STEREO_DFT_ALLPASS_FADELEN_16k )]; Copy32( st->hHQ_core->old_out_LB_fx32 + numZeros, hCPE->hStereoDft->ap_fade_mem_fx, ap_fade_len ); /*st->hHQ_core->q_old_outLB_fx*/ +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT + hCPE->hStereoDft->q_ap_fade_mem_fx = st->hHQ_core->Q_old_wtda_LB; +#else hCPE->hStereoDft->q_ap_fade_mem_fx = st->hHQ_core->q_old_outLB_fx; +#endif move16(); test(); diff --git a/lib_dec/stat_dec.h b/lib_dec/stat_dec.h index 84f8d83bd..9d6f49436 100644 --- a/lib_dec/stat_dec.h +++ b/lib_dec/stat_dec.h @@ -698,15 +698,13 @@ typedef struct hq_nbfec_structure typedef struct hq_dec_structure { Word32 old_out_fx32[L_FRAME48k]; /* HQ core - previous synthesis for OLA */ - Word16 old_out_fx[L_FRAME48k]; /* HQ core - previous synthesis for OLA */ + Word16 old_out_fx[L_FRAME48k]; /* HQ core - previous synthesis for OLA. Q_old_wtda */ Word16 exp_old_out; - Word16 old_out_LB_fx[L_FRAME32k]; /* HQ core - previous synthesis for OLA for Low Band */ + Word16 old_out_LB_fx[L_FRAME32k]; /* HQ core - previous synthesis for OLA for Low Band. Q_old_wtda_LB */ Word32 old_out_LB_fx32[L_FRAME32k]; -#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD - Word16 q_old_out_LB_fx; - Word16 q_old_out_fx; -#endif +#ifndef FIX_1348_BIT_PRECISION_IMPROVEMENT Word16 q_old_outLB_fx; +#endif Word16 Q_old_wtda_LB; Word16 Q_old_wtda; Word16 Q_old_postdec; /*scaling of the output of core_switching_post_dec_fx() */ -- GitLab From e3ee7268a49054531e72ed23706a7a6596b03920 Mon Sep 17 00:00:00 2001 From: Manuel Jander Date: Fri, 25 Apr 2025 00:41:17 +0200 Subject: [PATCH 015/113] clang format --- lib_dec/ivas_core_dec_fx.c | 4 ++-- lib_dec/ivas_mdct_core_dec_fx.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib_dec/ivas_core_dec_fx.c b/lib_dec/ivas_core_dec_fx.c index 12259f395..e4d54a72c 100644 --- a/lib_dec/ivas_core_dec_fx.c +++ b/lib_dec/ivas_core_dec_fx.c @@ -576,8 +576,8 @@ ivas_error ivas_core_dec_fx( move32(); /* TCX decoder */ - Scale_sig( st->hPFstat->mem_stp, L_SUBFR, -Qsyn_temp ); // Q0 - Scale_sig( st->hPFstat->mem_pf_in, L_SUBFR, -Qsyn_temp ); // Q0 + Scale_sig( st->hPFstat->mem_stp, L_SUBFR, -Qsyn_temp ); // Q0 + Scale_sig( st->hPFstat->mem_pf_in, L_SUBFR, -Qsyn_temp ); // Q0 #ifndef FIX_1348_BIT_PRECISION_IMPROVEMENT Scale_sig( st->hHQ_core->old_out_LB_fx, L_FRAME32k, -st->hHQ_core->Q_old_wtda_LB ); // Q0 Scale_sig( st->hHQ_core->old_out_fx, L_FRAME48k, -st->hHQ_core->Q_old_wtda ); // Q0 diff --git a/lib_dec/ivas_mdct_core_dec_fx.c b/lib_dec/ivas_mdct_core_dec_fx.c index 243f6733b..fc757feec 100644 --- a/lib_dec/ivas_mdct_core_dec_fx.c +++ b/lib_dec/ivas_mdct_core_dec_fx.c @@ -1184,8 +1184,8 @@ void ivas_mdct_core_reconstruct_fx( Scale_sig( st->hTcxDec->syn_Overl_TDAC, L_FRAME32k / 2, sub( q_win, st->hTcxDec->Q_syn_Overl_TDAC ) ); // st->hTcxDec->Q_syn_Overl_TDAC -> q_win Scale_sig( st->hTcxDec->old_syn_Overl, L_FRAME32k / 2, sub( q_win, st->hTcxDec->Q_old_syn_Overl ) ); // Q(-1 - st->Q_syn) -> q_win st->hTcxDec->Q_old_syn_Overl = q_win; - Scale_sig( st->hTcxDec->syn_Overl, L_FRAME32k / 2, sub( q_win, st->Q_syn ) ); // Q(st->Q_syn) -> q_win - Scale_sig( st->hTcxDec->syn_OverlFB, L_FRAME_MAX / 2, sub( q_win, st->Q_syn ) ); // Q(st->Q_syn) -> q_win + Scale_sig( st->hTcxDec->syn_Overl, L_FRAME32k / 2, sub( q_win, st->Q_syn ) ); // Q(st->Q_syn) -> q_win + Scale_sig( st->hTcxDec->syn_OverlFB, L_FRAME_MAX / 2, sub( q_win, st->Q_syn ) ); // Q(st->Q_syn) -> q_win Scale_sig( st->hHQ_core->old_out_LB_fx, L_FRAME32k, sub( q_win, st->hHQ_core->Q_old_wtda_LB ) ); // Q(st->hHQ_core->Q_old_wtda_LB) -> q_win Scale_sig( st->hHQ_core->old_out_fx, L_FRAME48k, sub( q_win, st->hHQ_core->Q_old_wtda ) ); // Q(st->hHQ_core->Q_old_wtda) -> q_win #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD -- GitLab From a0344f22fb0744054e98f0a5c142e302e4cea783 Mon Sep 17 00:00:00 2001 From: Manuel Jander Date: Sun, 27 Apr 2025 11:25:35 +0200 Subject: [PATCH 016/113] Add changes back and forth to q_old_outLB_fx/Q_old_wtda_LB again, the assumption that this does not have an effect was wrong. --- lib_dec/ivas_jbm_dec_fx.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lib_dec/ivas_jbm_dec_fx.c b/lib_dec/ivas_jbm_dec_fx.c index 33d11d380..e313304e2 100644 --- a/lib_dec/ivas_jbm_dec_fx.c +++ b/lib_dec/ivas_jbm_dec_fx.c @@ -434,7 +434,10 @@ ivas_error ivas_jbm_dec_tc_fx( { Copy_Scale_sig_16_32_no_sat( hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx, hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx32, L_FRAME32k, q - hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB ); // q Copy_Scale_sig_16_32_no_sat( hCPE->hCoreCoder[0]->hHQ_core->old_out_fx, hCPE->hCoreCoder[0]->hHQ_core->old_out_fx32, L_FRAME48k, q - hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda ); // q -#ifndef FIX_1348_BIT_PRECISION_IMPROVEMENT +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT + hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB = q; + move16(); +#else hCPE->hCoreCoder[0]->hHQ_core->q_old_outLB_fx = q; move16(); #endif @@ -952,7 +955,10 @@ ivas_error ivas_jbm_dec_tc_fx( { Copy_Scale_sig_16_32_no_sat( hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx, hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx32, L_FRAME32k, sub( q, hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB ) ); // q Copy_Scale_sig_16_32_no_sat( hCPE->hCoreCoder[0]->hHQ_core->old_out_fx, hCPE->hCoreCoder[0]->hHQ_core->old_out_fx32, L_FRAME48k, sub( q, hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda ) ); // q -#ifndef FIX_1348_BIT_PRECISION_IMPROVEMENT +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT + hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB = q; + move16(); +#else hCPE->hCoreCoder[0]->hHQ_core->q_old_outLB_fx = q; move16(); #endif @@ -1389,7 +1395,10 @@ ivas_error ivas_jbm_dec_tc_fx( { Copy_Scale_sig_16_32_no_sat( hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx, hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx32, L_FRAME32k, q - hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB ); // q Copy_Scale_sig_16_32_no_sat( hCPE->hCoreCoder[0]->hHQ_core->old_out_fx, hCPE->hCoreCoder[0]->hHQ_core->old_out_fx32, L_FRAME48k, q - hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda ); // q -#ifndef FIX_1348_BIT_PRECISION_IMPROVEMENT +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT + hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB = q; + move16(); +#else hCPE->hCoreCoder[0]->hHQ_core->q_old_outLB_fx = q; move16(); #endif -- GitLab From f17a648cd92bad1c20c46971eb9fd9b98097f182 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Mon, 28 Apr 2025 17:37:40 +0530 Subject: [PATCH 017/113] Fix for 3GPP issue 1524: BASOP decoder asserts in ivas_dirac_dec_binaural_determine_processing_matrices_fx with OMASA BASOP encoder bitstream using rate switching Link #1524 --- lib_rend/ivas_dirac_dec_binaural_functions_fx.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib_rend/ivas_dirac_dec_binaural_functions_fx.c b/lib_rend/ivas_dirac_dec_binaural_functions_fx.c index 922a4ef12..412b8c226 100644 --- a/lib_rend/ivas_dirac_dec_binaural_functions_fx.c +++ b/lib_rend/ivas_dirac_dec_binaural_functions_fx.c @@ -2096,6 +2096,21 @@ static void ivas_dirac_dec_binaural_determine_processing_matrices_fx( exp = sub( get_min_scalefactor( resultMtxRe_fx[0][0], resultMtxRe_fx[1][1] ), 2 ); tmp2 = L_add( L_shl( resultMtxRe_fx[0][0], exp ), L_shl( resultMtxRe_fx[1][1], exp ) ); q_tmp2 = add( q_res, exp ); + + /*Limiting value to Q63*/ + IF( GT_16( q_tmp2, 63 ) ) + { + tmp2 = L_shl( tmp2, sub( 63, q_tmp2 ) ); + q_tmp2 = 63; + move16(); + IF( EQ_32( tmp2, -1 ) ) + { + tmp2 = 0; + move32(); + q_tmp2 = 31; + move16(); + } + } IF( LT_16( q_CrEne, q_tmp2 ) ) { realizedOutputEne_fx = L_add( tmp1, L_shr( tmp2, sub( q_tmp2, q_CrEne ) ) ); -- GitLab From f612e8ac248e91898b76604b7e77fef0e9f900af Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Mon, 28 Apr 2025 17:23:12 +0530 Subject: [PATCH 018/113] Complexity measure crash fix for ltv48_STEREO_StereoDmxEvs_b07_16_dtx_wb_rs_fer_ep_10pct_fer_g192 --- lib_dec/igf_dec_fx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_dec/igf_dec_fx.c b/lib_dec/igf_dec_fx.c index 0010b9466..aa3f35b26 100644 --- a/lib_dec/igf_dec_fx.c +++ b/lib_dec/igf_dec_fx.c @@ -244,7 +244,7 @@ static void IGF_replaceTCXNoise_2( Word32 *in, /**< in g = getSqrtWord32( L_mult( divide3232( totalNoiseNrg, rE ), 8192 /*1.0f / 4.0f Q15*/ ) ); // ((Q15 + Q15 + Q1) / 2) -> Q15 - g = shl( g, 1 ); // Q16 + g = shl_sat( g, 1 ); // Q16 FOR( sb = start; sb < stop; sb++ ) { -- GitLab From 9da25323dad175bfcd4f8324dfb806f16ec9cc02 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Mon, 28 Apr 2025 17:28:03 +0530 Subject: [PATCH 019/113] Clang formatting changes --- lib_dec/igf_dec_fx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_dec/igf_dec_fx.c b/lib_dec/igf_dec_fx.c index aa3f35b26..511d8a977 100644 --- a/lib_dec/igf_dec_fx.c +++ b/lib_dec/igf_dec_fx.c @@ -244,7 +244,7 @@ static void IGF_replaceTCXNoise_2( Word32 *in, /**< in g = getSqrtWord32( L_mult( divide3232( totalNoiseNrg, rE ), 8192 /*1.0f / 4.0f Q15*/ ) ); // ((Q15 + Q15 + Q1) / 2) -> Q15 - g = shl_sat( g, 1 ); // Q16 + g = shl_sat( g, 1 ); // Q16 FOR( sb = start; sb < stop; sb++ ) { -- GitLab From 46b0f8045f18cf29b007a5a72378eac94f8b9552 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Mon, 28 Apr 2025 19:24:51 +0530 Subject: [PATCH 020/113] Q related fixed for encoder transition and decoder msan fixes --- lib_dec/ivas_mct_dec_fx.c | 2 +- lib_dec/ivas_stereo_dft_dec_dmx_fx.c | 2 ++ lib_enc/acelp_enc_util_fx.c | 12 ++++++------ lib_enc/enc_tran_fx.c | 3 ++- lib_enc/ivas_core_pre_proc_fx.c | 7 ++----- lib_enc/transition_enc_fx.c | 16 ++-------------- 6 files changed, 15 insertions(+), 27 deletions(-) diff --git a/lib_dec/ivas_mct_dec_fx.c b/lib_dec/ivas_mct_dec_fx.c index 058b57593..bb985ac7b 100644 --- a/lib_dec/ivas_mct_dec_fx.c +++ b/lib_dec/ivas_mct_dec_fx.c @@ -402,7 +402,7 @@ ivas_error ivas_mct_dec_fx( test(); IF( ( st_ivas->sba_dirac_stereo_flag != 0 ) && ( NE_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) || GE_16( cpe_id, sub( nCPE, 2 ) ) ) ) { - Copy_Scale_sig_16_32_no_sat( synth_fx[n], synth_fx_32[n], L_FRAME48k, sub( Q11, ( sub( 15, e_sig[n] ) ) ) ); // Q11 + Copy_Scale_sig_16_32_no_sat( synth_fx[n], synth_fx_32[n], output_frame, sub( Q11, ( sub( 15, e_sig[n] ) ) ) ); // Q11 Copy_Scale_sig_16_32_no_sat( hCPE->hCoreCoder[n]->hHQ_core->old_out_fx, hCPE->hCoreCoder[n]->hHQ_core->old_out_fx32, output_frame, sub( Q11, hCPE->hCoreCoder[n]->hHQ_core->Q_old_wtda ) ); ivas_post_proc_fx( NULL, hCPE, n, synth_fx_32[n], NULL, output_frame, 1, Q11 ); Copy_Scale_sig_32_16( synth_fx_32[n], synth_fx[n], output_frame, sub( sub( 15, e_sig[n] ), Q11 ) ); // Q0 diff --git a/lib_dec/ivas_stereo_dft_dec_dmx_fx.c b/lib_dec/ivas_stereo_dft_dec_dmx_fx.c index e82005965..8035af217 100644 --- a/lib_dec/ivas_stereo_dft_dec_dmx_fx.c +++ b/lib_dec/ivas_stereo_dft_dec_dmx_fx.c @@ -102,6 +102,8 @@ void stereo_dft_unify_dmx_fx( Word16 num_plocs; Word32 plocsi[STEREO_DFT_RES_N_PEAKS_MAX]; + set32_fx( DFT_PRED_RES, 0, STEREO_DFT32MS_N_32k ); + output_frame = extract_l( Mult_32_16( st0->output_Fs, INV_FRAME_PER_SEC_Q15 ) ); /* Q0 */ samp_ratio = BASOP_Util_Divide3232_Scale( st0->sr_core, st0->output_Fs, &q_samp_ratio ); samp_ratio = shr( samp_ratio, sub( Q15 - Q12, q_samp_ratio ) ); diff --git a/lib_enc/acelp_enc_util_fx.c b/lib_enc/acelp_enc_util_fx.c index 181583e91..7f57b55da 100644 --- a/lib_enc/acelp_enc_util_fx.c +++ b/lib_enc/acelp_enc_util_fx.c @@ -180,9 +180,9 @@ void E_ACELP_conv( } void E_ACELP_conv_ivas_fx( - const Word16 xn2[], /* i Qx*/ + const Word16 xn2[], /* i Qnew - 1*/ const Word16 h2[], /* i Q12*/ - Word16 cn2[] /* o Q0*/ + Word16 cn2[] /* o Qnew*/ ) { Word16 i, k; @@ -194,14 +194,14 @@ void E_ACELP_conv_ivas_fx( { /*cn2[k] = xn2[k]; */ Word64 L_tmp_64; - L_tmp_64 = W_deposit32_l( L_mult0( xn2[k], 0x800 ) ); /* 4Q11 */ + L_tmp_64 = W_deposit32_l( L_mult0( xn2[k], 0x800 ) ); /* Qnew -1 + 12 */ FOR( i = 0; i < k; i++ ) { /*cn2[k]-=cn2[i]*h2[k-i];*/ - L_tmp_64 = W_msu0_16_16( L_tmp_64, cn2[i], h2[k - i] ); /*h2 4Q11*/ + L_tmp_64 = W_msu0_16_16( L_tmp_64, cn2[i], h2[k - i] ); /*Qnew + 11*/ } - L_tmp = W_sat_l( L_tmp_64 ); /* 4Q11 */ - cn2[k] = round_fx_o( L_shl_o( L_tmp, 5, &Overflow ), &Overflow ); /* Q0*/ + L_tmp = W_sat_l( L_tmp_64 ); /* Qnew + 11 */ + cn2[k] = round_fx_o( L_shl_o( L_tmp, 5, &Overflow ), &Overflow ); /* Qnew*/ move16(); } } diff --git a/lib_enc/enc_tran_fx.c b/lib_enc/enc_tran_fx.c index 394b22c30..f308e9e87 100644 --- a/lib_enc/enc_tran_fx.c +++ b/lib_enc/enc_tran_fx.c @@ -545,7 +545,7 @@ Word16 encod_tran_ivas_fx( Copy( &res_fx[i_subfr], &exc_fx[i_subfr], L_SUBFR ); /* Q_new */ - find_targets_ivas_fx( speech_fx, hLPDmem->mem_syn, i_subfr, &hLPDmem->mem_w0, p_Aq, + find_targets_ivas_new_fx( speech_fx, hLPDmem->mem_syn, i_subfr, &hLPDmem->mem_w0, p_Aq, res_fx, L_SUBFR, p_Aw, st_fx->preemph_fac, xn, cn, h1 ); q_h1 = sub( 14, norm_s( h1[0] ) ); @@ -555,6 +555,7 @@ Word16 encod_tran_ivas_fx( #else Scale_sig( h1, L_SUBFR, sub( 13, q_h1 ) ); #endif + /* scaling of xn[] to limit dynamic at 12 bits */ Scale_sig( xn, L_SUBFR, shift ); diff --git a/lib_enc/ivas_core_pre_proc_fx.c b/lib_enc/ivas_core_pre_proc_fx.c index 6fe6b6720..5853e2739 100644 --- a/lib_enc/ivas_core_pre_proc_fx.c +++ b/lib_enc/ivas_core_pre_proc_fx.c @@ -1174,11 +1174,8 @@ ivas_error ivas_compute_core_buffers_fx( ELSE IF( GT_32( input_Fs, 8000 ) && EQ_32( sr_core, INT_FS_16k ) ) { Copy( &old_inp_16k_fx[L_frame_tmp], st->old_inp_16k_fx, L_INP_MEM ); - IF( Q_new ) - { - st->exp_old_inp_16k = sub( Q16, *Q_new ); //(*Q_new - 1) - move16(); - } + st->exp_old_inp_16k = sub(Q16, *Q_new); //(*Q_new - 1) + move16(); } ELSE IF( GT_32( input_Fs, 8000 ) ) { diff --git a/lib_enc/transition_enc_fx.c b/lib_enc/transition_enc_fx.c index 5e50cac15..c724ffd6c 100644 --- a/lib_enc/transition_enc_fx.c +++ b/lib_enc/transition_enc_fx.c @@ -924,8 +924,6 @@ void transition_enc_ivas_fx( /* set limit_flag to 0 for restrained limits, and 1 for extended limits */ limit_flag = 0; move16(); - Word16 h1_fx_q15[L_SUBFR + ( M + 1 )]; - Copy_Scale_sig( h1_fx, h1_fx_q15, L_SUBFR + ( M + 1 ), 0 ); pit_start = PIT_MIN; move16(); @@ -1443,12 +1441,7 @@ void transition_enc_ivas_fx( *clip_gain = gp_clip_fx( st_fx->element_mode, st_fx->core_brate, st_fx->voicing_fx, i_subfr, TRANSITION, xn_fx, gp_cl_fx, ( Q_new + shift - 1 ) ); move16(); -#ifdef TEST_HR - Copy( h1_fx, h1_fx_q15, L_SUBFR + ( M + 1 ) ); -#else - Copy_Scale_sig( h1_fx, h1_fx_q15, L_SUBFR + ( M + 1 ), 1 ); -#endif - lp_select = lp_filt_exc_enc_ivas_fx( MODE1, TRANSITION, i_subfr, exc_fx, h1_fx_q15, + lp_select = lp_filt_exc_enc_ivas_fx( MODE1, TRANSITION, i_subfr, exc_fx, h1_fx, xn_fx, y1_fx, xn2_fx, L_SUBFR, st_fx->L_frame, g_corr_fx, *clip_gain, gain_pit_fx, &lp_flag ); IF( EQ_16( lp_flag, NORMAL_OPERATION ) ) @@ -1684,12 +1677,7 @@ void transition_enc_ivas_fx( *clip_gain = gp_clip_fx( st_fx->element_mode, st_fx->core_brate, st_fx->voicing_fx, i_subfr, TRANSITION, xn_fx, gp_cl_fx, Q_new ); move16(); -#ifdef TEST_HR - Copy( h1_fx, h1_fx_q15, L_SUBFR + ( M + 1 ) ); -#else - Copy_Scale_sig( h1_fx, h1_fx_q15, L_SUBFR + ( M + 1 ), 1 ); -#endif - lp_select = lp_filt_exc_enc_ivas_fx( MODE1, TRANSITION, i_subfr, exc_fx, h1_fx_q15, + lp_select = lp_filt_exc_enc_ivas_fx( MODE1, TRANSITION, i_subfr, exc_fx, h1_fx, xn_fx, y1_fx, xn2_fx, L_SUBFR, st_fx->L_frame, g_corr_fx, *clip_gain, gain_pit_fx, &lp_flag ); IF( EQ_16( lp_flag, NORMAL_OPERATION ) ) { -- GitLab From a0f7b9ad985fb60dfa47e5057f2afb1b76ccad9d Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Tue, 29 Apr 2025 08:11:58 +0530 Subject: [PATCH 021/113] Clang formatting changes --- lib_dec/ivas_stereo_dft_dec_dmx_fx.c | 2 +- lib_enc/enc_tran_fx.c | 2 +- lib_enc/ivas_core_pre_proc_fx.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib_dec/ivas_stereo_dft_dec_dmx_fx.c b/lib_dec/ivas_stereo_dft_dec_dmx_fx.c index 8035af217..cdb64e46c 100644 --- a/lib_dec/ivas_stereo_dft_dec_dmx_fx.c +++ b/lib_dec/ivas_stereo_dft_dec_dmx_fx.c @@ -103,7 +103,7 @@ void stereo_dft_unify_dmx_fx( Word32 plocsi[STEREO_DFT_RES_N_PEAKS_MAX]; set32_fx( DFT_PRED_RES, 0, STEREO_DFT32MS_N_32k ); - + output_frame = extract_l( Mult_32_16( st0->output_Fs, INV_FRAME_PER_SEC_Q15 ) ); /* Q0 */ samp_ratio = BASOP_Util_Divide3232_Scale( st0->sr_core, st0->output_Fs, &q_samp_ratio ); samp_ratio = shr( samp_ratio, sub( Q15 - Q12, q_samp_ratio ) ); diff --git a/lib_enc/enc_tran_fx.c b/lib_enc/enc_tran_fx.c index f308e9e87..865972819 100644 --- a/lib_enc/enc_tran_fx.c +++ b/lib_enc/enc_tran_fx.c @@ -546,7 +546,7 @@ Word16 encod_tran_ivas_fx( Copy( &res_fx[i_subfr], &exc_fx[i_subfr], L_SUBFR ); /* Q_new */ find_targets_ivas_new_fx( speech_fx, hLPDmem->mem_syn, i_subfr, &hLPDmem->mem_w0, p_Aq, - res_fx, L_SUBFR, p_Aw, st_fx->preemph_fac, xn, cn, h1 ); + res_fx, L_SUBFR, p_Aw, st_fx->preemph_fac, xn, cn, h1 ); q_h1 = sub( 14, norm_s( h1[0] ) ); Copy_Scale_sig( h1, h2_fx, L_SUBFR, sub( 11, q_h1 ) ); /*Q11*/ diff --git a/lib_enc/ivas_core_pre_proc_fx.c b/lib_enc/ivas_core_pre_proc_fx.c index 5853e2739..e2c099cd2 100644 --- a/lib_enc/ivas_core_pre_proc_fx.c +++ b/lib_enc/ivas_core_pre_proc_fx.c @@ -1174,7 +1174,7 @@ ivas_error ivas_compute_core_buffers_fx( ELSE IF( GT_32( input_Fs, 8000 ) && EQ_32( sr_core, INT_FS_16k ) ) { Copy( &old_inp_16k_fx[L_frame_tmp], st->old_inp_16k_fx, L_INP_MEM ); - st->exp_old_inp_16k = sub(Q16, *Q_new); //(*Q_new - 1) + st->exp_old_inp_16k = sub( Q16, *Q_new ); //(*Q_new - 1) move16(); } ELSE IF( GT_32( input_Fs, 8000 ) ) -- GitLab From 9585f03fd4c0c025d93f27d25a928098c5413bc5 Mon Sep 17 00:00:00 2001 From: Jan Kiene Date: Tue, 29 Apr 2025 08:22:37 +0200 Subject: [PATCH 022/113] update CI ref --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 364e522aa..59c8d2b72 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,7 +1,7 @@ variables: # note: GitLab cannot reference variables defined by users in the include ref:, we need to use a YAML anchor for this # see https://docs.gitlab.com/ci/yaml/includes/#use-variables-with-include for more information - IVAS_CODEC_CI_REF: &IVAS_CODEC_CI_REF 4eb4c0dfbdc845280a9994b5f7540f69c737537b + IVAS_CODEC_CI_REF: &IVAS_CODEC_CI_REF 7c6b6f261883e282ebe050e18d48c00ce623b8be include: - local: .gitlab-ci/variables.yml -- GitLab From 7748c9d9bb56bbaedff4f11201382a04a6215546 Mon Sep 17 00:00:00 2001 From: Jan Kiene Date: Tue, 29 Apr 2025 08:50:20 +0200 Subject: [PATCH 023/113] update commit to point to CI repo main --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 59c8d2b72..4b7d05c7b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,7 +1,7 @@ variables: # note: GitLab cannot reference variables defined by users in the include ref:, we need to use a YAML anchor for this # see https://docs.gitlab.com/ci/yaml/includes/#use-variables-with-include for more information - IVAS_CODEC_CI_REF: &IVAS_CODEC_CI_REF 7c6b6f261883e282ebe050e18d48c00ce623b8be + IVAS_CODEC_CI_REF: &IVAS_CODEC_CI_REF f5e61349c22ededcdfe1cc54e533dea477f2d003 include: - local: .gitlab-ci/variables.yml -- GitLab From ac17f4d1fe6fa8764b0b681ccacf6e0fd15a3372 Mon Sep 17 00:00:00 2001 From: Jan Kiene Date: Tue, 29 Apr 2025 08:01:15 +0200 Subject: [PATCH 024/113] add missing reference to common before_script section --- .gitlab-ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 4b7d05c7b..1f5a98321 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1596,6 +1596,7 @@ voip-be-on-merge-request: GET_WMOPS_ARGS: "mem_only" timeout: 3 hours 30 minutes before_script: + - !reference [ .job-linux, before_script ] - bash "${CI_PROJECT_DIR}"/ivas-codec-ci/snippets/print-common-info.sh - bash "${CI_PROJECT_DIR}"/ivas-codec-ci/snippets/basop/update-scripts-repo.sh - bash "${CI_PROJECT_DIR}"/ivas-codec-ci/snippets/update-ltv-repo.sh -- GitLab From d2434f48518de163574aec2ab0e3dc8d9497464f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20M=C3=BCller?= Date: Tue, 29 Apr 2025 01:21:37 +0200 Subject: [PATCH 025/113] Inherit before_script from .test-job-linux --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 1f5a98321..bb2259810 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1596,7 +1596,7 @@ voip-be-on-merge-request: GET_WMOPS_ARGS: "mem_only" timeout: 3 hours 30 minutes before_script: - - !reference [ .job-linux, before_script ] + - !reference [ .test-job-linux, before_script ] - bash "${CI_PROJECT_DIR}"/ivas-codec-ci/snippets/print-common-info.sh - bash "${CI_PROJECT_DIR}"/ivas-codec-ci/snippets/basop/update-scripts-repo.sh - bash "${CI_PROJECT_DIR}"/ivas-codec-ci/snippets/update-ltv-repo.sh -- GitLab From e5640c2b37ba403cd4195e4468de87561facdde4 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Tue, 29 Apr 2025 14:54:13 +0530 Subject: [PATCH 026/113] Fix for 3GPP issue 1525: Second channel of BASOP decoder MASA format output to FOA has missing energy or wrong signal Link #1525 --- lib_rend/ivas_dirac_output_synthesis_dec_fx.c | 33 ++++++++++++++----- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/lib_rend/ivas_dirac_output_synthesis_dec_fx.c b/lib_rend/ivas_dirac_output_synthesis_dec_fx.c index 509eec6e2..37b5f1e05 100644 --- a/lib_rend/ivas_dirac_output_synthesis_dec_fx.c +++ b/lib_rend/ivas_dirac_output_synthesis_dec_fx.c @@ -2134,9 +2134,6 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( move16(); } - subtract_power_y = masa_stereo_type_detect->subtract_power_y_fx; // q_subtract_power_y - move32(); - a = 858993; /* ( 0.0004f in Q31 ); Temporal smoothing coefficient */ move32(); b = L_sub( ONE_IN_Q31, a ); /* Temporal smoothing coefficient */ @@ -2152,24 +2149,42 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( move32(); masa_stereo_type_detect->q_target_power_y_smooth = q_com; move16(); - masa_stereo_type_detect->subtract_power_y_smooth_fx = - L_add( Mpy_32_32( a, subtract_power_y ), - Mpy_32_32( b, masa_stereo_type_detect->subtract_power_y_smooth_fx ) ); //(Q31, q_subtract_power_y) -> q_subtract_power_y + + IF( NE_16( masa_stereo_type_detect->q_subtract_power_y, masa_stereo_type_detect->q_subtract_power_y_smooth ) ) + { + exp = s_min( add( masa_stereo_type_detect->q_subtract_power_y, norm_l( masa_stereo_type_detect->subtract_power_y_fx ) ), add( masa_stereo_type_detect->q_subtract_power_y_smooth, norm_l( masa_stereo_type_detect->subtract_power_y_smooth_fx ) ) ); + masa_stereo_type_detect->subtract_power_y_fx = L_shl( masa_stereo_type_detect->subtract_power_y_fx, sub( exp, masa_stereo_type_detect->q_subtract_power_y ) ); + move32(); + masa_stereo_type_detect->subtract_power_y_smooth_fx = L_shl( masa_stereo_type_detect->subtract_power_y_smooth_fx, sub( exp, masa_stereo_type_detect->q_subtract_power_y_smooth ) ); + move32(); + masa_stereo_type_detect->q_subtract_power_y = exp; + move16(); + masa_stereo_type_detect->q_subtract_power_y_smooth = exp; + move16(); + } + subtract_power_y = masa_stereo_type_detect->subtract_power_y_fx; // q_subtract_power_y move32(); + W_temp = W_add( W_mult0_32_32( a, subtract_power_y ), W_mult0_32_32( b, masa_stereo_type_detect->subtract_power_y_smooth_fx ) ); // Q31 + masa_stereo_type_detect->q_subtract_power_y_smooth + exp = W_norm( W_temp ); + masa_stereo_type_detect->subtract_power_y_smooth_fx = W_extract_h( W_shl( W_temp, exp ) ); // Q31 + masa_stereo_type_detect->q_subtract_power_y_smooth + exp - 32 + move32(); + masa_stereo_type_detect->q_subtract_power_y_smooth = sub( add( masa_stereo_type_detect->q_subtract_power_y_smooth, exp ), 1 ); + move16(); + exp = 0; move16(); IF( masa_stereo_type_detect->target_power_y_smooth_fx != 0 ) { subtract_target_ratio = L_sub( BASOP_Util_Log2( masa_stereo_type_detect->subtract_power_y_smooth_fx ), BASOP_Util_Log2( masa_stereo_type_detect->target_power_y_smooth_fx ) ); // Q25 - exp = sub( masa_stereo_type_detect->q_subtract_power_y, q_com ); + exp = sub( masa_stereo_type_detect->q_subtract_power_y_smooth, q_com ); L_tmp = Mpy_32_32( L_sub( subtract_target_ratio, L_shl( exp, 25 ) ), LOG10_2_Q31 ); // Q25 } ELSE { subtract_target_ratio = BASOP_Util_Log2( masa_stereo_type_detect->subtract_power_y_smooth_fx ); // Q25 - exp = sub( 31, masa_stereo_type_detect->q_subtract_power_y ); + exp = sub( 31, masa_stereo_type_detect->q_subtract_power_y_smooth ); L_tmp = L_sub( Mpy_32_32( L_add( subtract_target_ratio, L_shl( exp, 25 ) ), LOG10_2_Q31 ), -503316480 /* L_shl( -15, 25 ) */ /*log(EPSILON)*/ ); // Q25 } subtract_target_ratio_db = Mpy_32_32( 1342177280 /* 10.0f * in Q27*/, L_tmp ); // (Q27, (Q25, Q31)) -> (Q27, Q25) -> Q21 @@ -2178,6 +2193,8 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( move32(); masa_stereo_type_detect->subtract_power_y_fx = 0; move32(); + masa_stereo_type_detect->q_subtract_power_y = Q31; + move16(); } /*-----------------------------------------------------------------* -- GitLab From 9b20d04ce34cdf85e5e838a3ac26daba4d05e418 Mon Sep 17 00:00:00 2001 From: Manuel Jander Date: Tue, 29 Apr 2025 23:34:46 +0200 Subject: [PATCH 027/113] Correct value of q_ap_fade_mem_fx. Add Q_old_out_fx32 to represent Q of 32 bit versions of out_old buffers and avoid mixing it with 16 bit versions. --- lib_dec/hq_core_dec_fx.c | 4 ++++ lib_dec/ivas_core_dec_fx.c | 8 ++++++++ lib_dec/ivas_cpe_dec_fx.c | 6 ++++-- lib_dec/ivas_jbm_dec_fx.c | 15 ++++++--------- lib_dec/ivas_mdct_core_dec_fx.c | 3 ++- lib_dec/ivas_post_proc_fx.c | 2 +- lib_dec/ivas_stereo_switching_dec_fx.c | 3 +++ lib_dec/stat_dec.h | 4 +++- 8 files changed, 31 insertions(+), 14 deletions(-) diff --git a/lib_dec/hq_core_dec_fx.c b/lib_dec/hq_core_dec_fx.c index 4d1ef6774..453b89924 100644 --- a/lib_dec/hq_core_dec_fx.c +++ b/lib_dec/hq_core_dec_fx.c @@ -1205,6 +1205,10 @@ void HQ_core_dec_init_fx( move16(); move16(); move16(); +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT + hHQ_core->Q_old_out_fx32 = Q11; + move16(); +#endif hHQ_core->last_hq_core_type = -1; /* Q0 */ move16(); diff --git a/lib_dec/ivas_core_dec_fx.c b/lib_dec/ivas_core_dec_fx.c index 6ca2982f5..a27213b6e 100644 --- a/lib_dec/ivas_core_dec_fx.c +++ b/lib_dec/ivas_core_dec_fx.c @@ -337,6 +337,10 @@ ivas_error ivas_core_dec_fx( Copy_Scale_sig_16_32_no_sat( sts[0]->hHQ_core->old_out_LB_fx, sts[0]->hHQ_core->old_out_LB_fx32, L_FRAME32k, sub( Q11, sts[0]->hHQ_core->Q_old_wtda_LB ) ); // Q11 L_lerp_fx_q11( sts[0]->hHQ_core->old_out_LB_fx32, sts[0]->hHQ_core->old_out_LB_fx32, sts[0]->L_frame, sts[0]->last_L_frame ); Copy_Scale_sig_32_16( sts[0]->hHQ_core->old_out_LB_fx32, sts[0]->hHQ_core->old_out_LB_fx, L_FRAME32k, sub( sts[0]->hHQ_core->Q_old_wtda_LB, Q11 ) ); // Q_old_wtda_LB +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT + sts[0]->hHQ_core->Q_old_out_fx32 = Q11; + move16(); +#endif } IF( NE_16( sts[0]->L_frame, L_FRAME16k ) ) { @@ -1403,6 +1407,10 @@ ivas_error ivas_core_dec_fx( { Copy_Scale_sig_16_32_no_sat( st->hHQ_core->old_out_LB_fx, st->hHQ_core->old_out_LB_fx32, L_FRAME32k, sub( Q11, st->hHQ_core->Q_old_wtda_LB ) ); // Q11 Copy_Scale_sig_16_32_no_sat( st->hHQ_core->old_out_fx, st->hHQ_core->old_out_fx32, L_FRAME48k, sub( Q11, st->hHQ_core->Q_old_wtda ) ); // Q11 +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT + st->hHQ_core->Q_old_out_fx32 = Q11; + move16(); +#endif } IF( NE_16( st->element_mode, IVAS_CPE_DFT ) ) diff --git a/lib_dec/ivas_cpe_dec_fx.c b/lib_dec/ivas_cpe_dec_fx.c index dcec695f3..ba63d8e8a 100644 --- a/lib_dec/ivas_cpe_dec_fx.c +++ b/lib_dec/ivas_cpe_dec_fx.c @@ -132,7 +132,9 @@ ivas_error ivas_cpe_dec_fx( IF( hCPE->hCoreCoder[ind1]->hHQ_core ) { Copy_Scale_sig_16_32_no_sat( hCPE->hCoreCoder[ind1]->hHQ_core->old_out_LB_fx, hCPE->hCoreCoder[ind1]->hHQ_core->old_out_LB_fx32, L_FRAME32k, sub( Q11, hCPE->hCoreCoder[ind1]->hHQ_core->Q_old_wtda_LB ) ); // Q11 -#ifndef FIX_1348_BIT_PRECISION_IMPROVEMENT +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT + hCPE->hCoreCoder[ind1]->hHQ_core->Q_old_out_fx32 = Q11; +#else hCPE->hCoreCoder[ind1]->hHQ_core->q_old_outLB_fx = Q11; #endif move16(); @@ -157,7 +159,7 @@ ivas_error ivas_cpe_dec_fx( test(); IF( hCPE->hCoreCoder[ind1] && hCPE->hCoreCoder[ind1]->hHQ_core ) { - Copy_Scale_sig_32_16( hCPE->hCoreCoder[ind1]->hHQ_core->old_out_LB_fx32, hCPE->hCoreCoder[ind1]->hHQ_core->old_out_LB_fx, L_FRAME32k, sub( hCPE->hCoreCoder[ind1]->hHQ_core->Q_old_wtda_LB, Q11 ) ); // Q_old_wtda + Copy_Scale_sig_32_16( hCPE->hCoreCoder[ind1]->hHQ_core->old_out_LB_fx32, hCPE->hCoreCoder[ind1]->hHQ_core->old_out_LB_fx, L_FRAME32k, sub( hCPE->hCoreCoder[ind1]->hHQ_core->Q_old_wtda_LB, Q11 ) ); // Q_old_wtda_LB } } diff --git a/lib_dec/ivas_jbm_dec_fx.c b/lib_dec/ivas_jbm_dec_fx.c index e313304e2..22c9423bf 100644 --- a/lib_dec/ivas_jbm_dec_fx.c +++ b/lib_dec/ivas_jbm_dec_fx.c @@ -435,12 +435,11 @@ ivas_error ivas_jbm_dec_tc_fx( Copy_Scale_sig_16_32_no_sat( hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx, hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx32, L_FRAME32k, q - hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB ); // q Copy_Scale_sig_16_32_no_sat( hCPE->hCoreCoder[0]->hHQ_core->old_out_fx, hCPE->hCoreCoder[0]->hHQ_core->old_out_fx32, L_FRAME48k, q - hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda ); // q #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT - hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB = q; - move16(); + hCPE->hCoreCoder[0]->hHQ_core->Q_old_out_fx32 = q; #else hCPE->hCoreCoder[0]->hHQ_core->q_old_outLB_fx = q; - move16(); #endif + move16(); } IF( hCPE->hStereoDft != NULL ) { @@ -956,12 +955,11 @@ ivas_error ivas_jbm_dec_tc_fx( Copy_Scale_sig_16_32_no_sat( hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx, hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx32, L_FRAME32k, sub( q, hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB ) ); // q Copy_Scale_sig_16_32_no_sat( hCPE->hCoreCoder[0]->hHQ_core->old_out_fx, hCPE->hCoreCoder[0]->hHQ_core->old_out_fx32, L_FRAME48k, sub( q, hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda ) ); // q #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT - hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB = q; - move16(); + hCPE->hCoreCoder[0]->hHQ_core->Q_old_out_fx32 = q; #else hCPE->hCoreCoder[0]->hHQ_core->q_old_outLB_fx = q; - move16(); #endif + move16(); } IF( hCPE->hStereoDft != NULL ) { @@ -1396,12 +1394,11 @@ ivas_error ivas_jbm_dec_tc_fx( Copy_Scale_sig_16_32_no_sat( hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx, hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx32, L_FRAME32k, q - hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB ); // q Copy_Scale_sig_16_32_no_sat( hCPE->hCoreCoder[0]->hHQ_core->old_out_fx, hCPE->hCoreCoder[0]->hHQ_core->old_out_fx32, L_FRAME48k, q - hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda ); // q #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT - hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB = q; - move16(); + hCPE->hCoreCoder[0]->hHQ_core->Q_old_out_fx32 = q; #else hCPE->hCoreCoder[0]->hHQ_core->q_old_outLB_fx = q; - move16(); #endif + move16(); } IF( hCPE->hStereoDft != NULL ) { diff --git a/lib_dec/ivas_mdct_core_dec_fx.c b/lib_dec/ivas_mdct_core_dec_fx.c index fc757feec..c180426f1 100644 --- a/lib_dec/ivas_mdct_core_dec_fx.c +++ b/lib_dec/ivas_mdct_core_dec_fx.c @@ -1277,7 +1277,8 @@ void ivas_mdct_core_reconstruct_fx( move16(); #endif #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD - Scale_sig( st->mem_syn2_fx, M, sub( negate( q_win ), 2 ) ); + Scale_sig( st->mem_syn2_fx, M, sub( -2, q_win ) ); + //Scale_sig( st->mem_syn2_fx, M, sub( st->Q_syn, q_win ) ); // q_win -> Q_syn #endif } ELSE /*ACELP core for ACELP-PLC */ diff --git a/lib_dec/ivas_post_proc_fx.c b/lib_dec/ivas_post_proc_fx.c index b82cc1d00..4232116fa 100644 --- a/lib_dec/ivas_post_proc_fx.c +++ b/lib_dec/ivas_post_proc_fx.c @@ -589,7 +589,7 @@ void stereo_dft_dec_core_switching_fx( Copy32( st->hHQ_core->old_out_LB_fx32 + numZeros, hCPE->hStereoDft->ap_fade_mem_fx, ap_fade_len ); /*st->hHQ_core->q_old_outLB_fx*/ #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT - hCPE->hStereoDft->q_ap_fade_mem_fx = st->hHQ_core->Q_old_wtda_LB; + hCPE->hStereoDft->q_ap_fade_mem_fx = st->hHQ_core->Q_old_out_fx32; #else hCPE->hStereoDft->q_ap_fade_mem_fx = st->hHQ_core->q_old_outLB_fx; #endif diff --git a/lib_dec/ivas_stereo_switching_dec_fx.c b/lib_dec/ivas_stereo_switching_dec_fx.c index 677c91ef0..454395648 100644 --- a/lib_dec/ivas_stereo_switching_dec_fx.c +++ b/lib_dec/ivas_stereo_switching_dec_fx.c @@ -418,6 +418,7 @@ ivas_error stereo_memory_dec_fx( test(); IF( EQ_16( hCPE->last_element_mode, IVAS_CPE_MDCT ) && EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) ) { + assert( hCPE->hCoreCoder[0]->hHQ_core->Q_old_out_fx32 == hCPE->hCoreCoder[1]->hHQ_core->Q_old_out_fx32 ); v_add_32( hCPE->hCoreCoder[0]->hHQ_core->old_out_fx32, hCPE->hCoreCoder[1]->hHQ_core->old_out_fx32, hCPE->hCoreCoder[0]->hHQ_core->old_out_fx32, extract_l( Mpy_32_16_1( output_Fs, INV_FRAME_PER_SEC_Q15 ) ) ); /* exp(exp_old_out) */ v_multc_fixed_16( hCPE->hCoreCoder[0]->hHQ_core->old_out_fx32, 16384 /* 0.5 in Q15 */, hCPE->hCoreCoder[0]->hHQ_core->old_out_fx32, extract_l( Mpy_32_16_1( output_Fs, INV_FRAME_PER_SEC_Q15 ) ) ); /* exp(exp_old_out) */ @@ -2149,6 +2150,8 @@ void stereo_td2dft_update_fx( move16(); /* update buffers used for fading when switching to DFT Stereo */ + assert( sts[0]->hHQ_core->Q_old_out_fx32 == sts[1]->hHQ_core->Q_old_out_fx32 ); + v_add_fx( sts[0]->hHQ_core->old_out_LB_fx32 + nsLB, sts[1]->hHQ_core->old_out_LB_fx32 + nsLB, hCPE->old_outLB_mdct_fx, old_outLB_len ); L_lerp_fx_q11( hCPE->old_outLB_mdct_fx, hCPE->old_outLB_mdct_fx, STEREO_MDCT2DFT_FADE_LEN_48k, old_outLB_len ); FOR( i = 0; i < old_outLB_len; i++ ) diff --git a/lib_dec/stat_dec.h b/lib_dec/stat_dec.h index 9d6f49436..2749c06b4 100644 --- a/lib_dec/stat_dec.h +++ b/lib_dec/stat_dec.h @@ -702,7 +702,9 @@ typedef struct hq_dec_structure Word16 exp_old_out; Word16 old_out_LB_fx[L_FRAME32k]; /* HQ core - previous synthesis for OLA for Low Band. Q_old_wtda_LB */ Word32 old_out_LB_fx32[L_FRAME32k]; -#ifndef FIX_1348_BIT_PRECISION_IMPROVEMENT +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT + Word16 Q_old_out_fx32; /* Q for both old_out_fx32 and old_out_LB_fx32 */ +#else Word16 q_old_outLB_fx; #endif Word16 Q_old_wtda_LB; -- GitLab From aecbdde8f450dfaa1f8d679190175a0f29cf28c8 Mon Sep 17 00:00:00 2001 From: Manuel Jander Date: Tue, 29 Apr 2025 23:40:04 +0200 Subject: [PATCH 028/113] clang format --- lib_dec/ivas_mdct_core_dec_fx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_dec/ivas_mdct_core_dec_fx.c b/lib_dec/ivas_mdct_core_dec_fx.c index c180426f1..d8c64d516 100644 --- a/lib_dec/ivas_mdct_core_dec_fx.c +++ b/lib_dec/ivas_mdct_core_dec_fx.c @@ -1278,7 +1278,7 @@ void ivas_mdct_core_reconstruct_fx( #endif #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD Scale_sig( st->mem_syn2_fx, M, sub( -2, q_win ) ); - //Scale_sig( st->mem_syn2_fx, M, sub( st->Q_syn, q_win ) ); // q_win -> Q_syn + // Scale_sig( st->mem_syn2_fx, M, sub( st->Q_syn, q_win ) ); // q_win -> Q_syn #endif } ELSE /*ACELP core for ACELP-PLC */ -- GitLab From 5c45d51c5ba179a99a9e56f371ab255fcf3f87ac Mon Sep 17 00:00:00 2001 From: Manuel Jander Date: Thu, 8 May 2025 10:52:28 +0200 Subject: [PATCH 029/113] Add macro FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN to make q_win value variable for the ivas_mdct_core_reconstruct_fx() data path, but not decoder_tcx_ivas_fx() for now. --- lib_com/ivas_prot_fx.h | 4 + lib_com/options.h | 1 + lib_com/prot_fx.h | 13 +- lib_dec/dec_tcx_fx.c | 545 ++++++++++++++++++++++++- lib_dec/er_dec_acelp_fx.c | 8 +- lib_dec/er_dec_tcx_fx.c | 10 + lib_dec/ivas_mct_dec_fx.c | 2 +- lib_dec/ivas_mdct_core_dec_fx.c | 42 +- lib_dec/ivas_post_proc_fx.c | 1 + lib_dec/ivas_stereo_mdct_core_dec_fx.c | 2 +- 10 files changed, 617 insertions(+), 11 deletions(-) diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index 17566e3cb..5dd11390a 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -1582,7 +1582,11 @@ void decoder_tcx_imdct_fx( Word32 x_fx[N_MAX], Word16 q_x, Word16 xn_buf_fx[], +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN + Word16 *q_win, +#else Word16 q_win, +#endif const UWord16 kernelType, /* i : TCX transform kernel type */ const Word16 fUseTns, /* i : flag that is set if TNS data is present */ Word16 synth_fx[], /* i/o: synth[-M..L_frame] */ diff --git a/lib_com/options.h b/lib_com/options.h index 63fe353e0..d86502dfd 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -100,6 +100,7 @@ #define REMOVE_EVS_DUPLICATES /* remove core-coder duplicated functions, ACELP low-band decoder */ #define FIX_1348_BIT_PRECISION_IMPROVEMENT +#define FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN #define FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD //#define FIX_1348_BIT_PRECISION_IMPROVEMENT_ROUND_OLD_BUFF #endif diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 3c07b8140..8602a331f 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -9886,8 +9886,15 @@ void IMDCT_fx( Word32 *x, Word16 x_e, Word16 *old_syn_overl, Word16 *syn_Overl_T void IMDCT_ivas_fx( Word32 *x_fx, Word16 q_x, +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN Word16 *old_syn_overl_fx, + Word16 *Q_old_syn_overl_fx, Word16 *syn_Overl_TDAC_fx, + Word16 *Q_syn_Overl_TDAC_fx, +#else + Word16 *old_syn_overl_fx, + Word16 *syn_Overl_TDAC_fx, +#endif Word16 *xn_buf_fx, const Word16 *tcx_aldo_window_1_fx, const PWord16 *tcx_aldo_window_1_trunc_fx, @@ -9916,7 +9923,11 @@ void IMDCT_ivas_fx( Decoder_State *st, const Word16 fullbandScale, Word16 *acelp_zir_fx, +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN + Word16 *q_win); +#else Word16 q_win ); +#endif void v_mult16_fixed( const Word16 x1[], /* i : Input vector 1 */ @@ -10022,7 +10033,7 @@ void ivas_mdct_core_reconstruct_fx( /* o : synthesis @output_FS */ // e_sig Word16 fUseTns[CPE_CHANNELS][NB_DIV], /* i : flage TNS enabled */ const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0)*/ -#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT +#if defined( FIX_1348_BIT_PRECISION_IMPROVEMENT ) && !defined( FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN ) const Word16 isParamMC, #endif Word16 q_x, diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index fc8fda9ad..7bbe93ad8 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -2575,11 +2575,349 @@ void IMDCT_fx( Word32 *x, Word16 x_e, Word16 *old_syn_overl, Word16 *syn_Overl_T } } +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN +static +Word16 IMDCT_ivas_fx_adjust_qwin( + Word16 Q_syn_Overl_TDAC, + Word16 Q_syn_Overl, + Word16 Q_old_syn_Overl, + Word16 Q_old_wtda, + Word16 q_win) +{ + //q_win = s_min( s_min( s_min( s_min( Q_syn_Overl_TDAC , Q_syn_Overl ), Q_old_syn_Overl ), Q_old_wtda ), q_win ); + q_win = s_min( s_min( s_min( Q_syn_Overl_TDAC , Q_syn_Overl ), Q_old_syn_Overl ), Q_old_wtda ); + q_win = s_min ( q_win, -1 ); + q_win = s_max ( q_win, -2 ); + + return q_win; +} + +static +void IMDCT_ivas_fx_rescale( + Word16 *syn_Overl_TDAC, + Word16 *Q_syn_Overl_TDAC, + Word16 *syn_Overl, + Word16 *Q_syn_Overl, + Word16 *old_syn_Overl, + Word16 *Q_old_syn_Overl, + Word16 *old_out_fx, + Word16 *Q_old_wtda, + Word16 q_win, + const Word16 FB_flag +#if 0 + Word16 *synth_buf_fx, + Word16 q_syn +#endif + ) +{ + Word16 oldLength; + + oldLength = L_FRAME32k; + move16(); + if ( FB_flag ) { + oldLength = L_FRAME48k; + move16(); + } + +#if 1 + Scale_sig( syn_Overl, oldLength / 2, sub( q_win, *Q_syn_Overl ) ); // st->hTcxDec->Q_syn_Overl -> q_win + *Q_syn_Overl = q_win; + move16(); + Scale_sig( syn_Overl_TDAC, oldLength / 2, sub( q_win, *Q_syn_Overl_TDAC ) ); // st->hTcxDec->Q_syn_Overl_TDAC -> q_win + *Q_syn_Overl_TDAC = q_win; + move16(); + Scale_sig( old_syn_Overl, oldLength / 2, sub( q_win, *Q_old_syn_Overl ) ); // Q(-1 - st->Q_syn) -> q_win + *Q_old_syn_Overl = q_win; + move16(); + + Scale_sig( old_out_fx, oldLength, sub( q_win, *Q_old_wtda ) ); // Q(st->hHQ_core->Q_old_wtda) -> q_win + *Q_old_wtda = q_win; + move16(); +#endif + //Scale_sig( synth_buf_fx, add( add( old_synth_len, L_FRAME_PLUS ), M ), sub( q_win, q_syn ) ); // q_syn -> q_win +} + +static Word16 TCX_MDCT_Inverse_GetScaleFactor( + const Word16 L, /* Q0 */ + Word16 *factor_e /* Q0 */ +) +{ + + Word16 factor; + + IF( EQ_16( L, NORM_MDCT_FACTOR ) ) + { + factor = 32767; + move16(); + *factor_e = 0; + move16(); + } + ELSE IF( EQ_16( L, 2 * NORM_MDCT_FACTOR ) ) + { + factor = 23170; + move16(); + *factor_e = 1; + move16(); + } + ELSE IF( EQ_16( L, 4 * NORM_MDCT_FACTOR ) ) + { + factor = 32767; + move16(); + *factor_e = 1; + move16(); + } + ELSE + { + factor = mult_r( shl( L, 4 ), 26214 /*128.f / NORM_MDCT_FACTOR*/ ); /* 4Q11 */ + *factor_e = 4; + move16(); + + factor = Sqrt16( factor, factor_e ); + } + + return factor; +} + +static +void TCX_MDCT_Inverse_qwin_fx( + Word32 *x, // Q( 31 - x_e ) + Word16 x_e, + Word16 *y, /* Qy */ + const Word16 l, /* Q0 */ + const Word16 m, /* Q0 */ + const Word16 r, /* Q0 */ + const Word16 element_mode,/* Q0 */ + Word16 *q_win +) +{ + + Word16 i, fac, negfac, s; + Word16 L2 = l, R2 = r; + Word32 tmp_buf[N_MAX + L_MDCT_OVLP_MAX / 2]; + Word16 fac_e; + (void) element_mode; + L2 = shr( l, 1 ); + R2 = shr( r, 1 ); + + x_e = sub( 15, x_e ); + edct_fx( x, tmp_buf + L2, add( add( shr( l, 1 ), m ), shr( r, 1 ) ), &x_e ); + x_e = sub( 15, x_e ); + + fac = TCX_MDCT_Inverse_GetScaleFactor( add( add( shr( l, 1 ), m ), shr( r, 1 ) ), &fac_e ); /* exp(fac_e) */ + x_e = add( x_e, fac_e ); + + negfac = negate( fac ); + +#if 1 + IF ( *q_win == -2 ) { + // x_e + q_win == L_norm_arr(tmp_buf, , *q_win ); + // q_win = L_norm_arr(tmp_buf, , *q_win ) - x_e; + s = L_norm_arr( tmp_buf + L2, m + R2 + L2); + *q_win = s_min( sub( s, x_e ), *q_win ); + } +#else + assert( *q_win == 0 || *q_win == -2 ); +#endif + s = add( x_e, *q_win ); + move16(); + + FOR( i = 0; i < R2; i++ ) + { + y[l + m + R2 + i] = round_fx_sat( L_shl_sat( Mpy_32_16_1( tmp_buf[L2 + i], negfac ), s ) ); /* fold out right end of DCT exp(fac_e)*/ + + move16(); + } + + FOR( i = 0; i < L2; i++ ) + { + y[i] = round_fx_sat( L_shl_sat( Mpy_32_16_1( tmp_buf[L2 + m + R2 + i], fac ), s ) ); /* negate, fold out left end of DCT exp(fac_e)*/ + move16(); + } + + FOR( i = 0; i < ( ( L2 + m + R2 ) >> 1 ); i++ ) + { + Word16 f; + + f = round_fx_sat( L_shl_sat( Mpy_32_16_1( tmp_buf[L2 + i], negfac ), s ) ); + y[L2 + i] = round_fx_sat( L_shl_sat( Mpy_32_16_1( tmp_buf[l + m + R2 - 1 - i], negfac ), s ) ); /* time-reverse mid of DCT exp(fac_e)*/ + move16(); + y[l + m + R2 - 1 - i] = f; + move16(); + } +} + +static +void TCX_MDST_Inverse_qwin_fx( + Word32 *x, /* exp(x_e) */ + Word16 x_e, + Word16 *y, /* Qx */ + const Word16 l, /* Q0 */ + const Word16 m, /* Q0 */ + const Word16 r, /* Q0 */ + Word16 *q_win +) +{ + + Word16 i, fac, negfac, s; + Word16 L2 = l, R2 = r; + move16(); + move16(); + Word32 tmp_buf[N_MAX + L_MDCT_OVLP_MAX / 2]; + Word16 fac_e; + + L2 = shr( l, 1 ); + R2 = shr( r, 1 ); + + x_e = sub( 15, x_e ); + edst_fx( x, tmp_buf + L2, add( add( shr( l, 1 ), m ), shr( r, 1 ) ), &x_e ); + x_e = sub( 15, x_e ); + + fac = TCX_MDCT_Inverse_GetScaleFactor( add( add( shr( l, 1 ), m ), shr( r, 1 ) ), &fac_e ); + x_e = add( x_e, fac_e ); + + negfac = negate( fac ); + +#if 1 + IF ( *q_win == -2 ) { + // x_e + q_win == L_norm_arr(tmp_buf, , *q_win ); + // q_win = L_norm_arr(tmp_buf, , *q_win ) - x_e; + s = L_norm_arr( tmp_buf + L2, m + R2 + L2); + *q_win = s_min( sub( s, x_e ), *q_win ); + } +#else + assert( *q_win == 0 || *q_win == -2 ); +#endif + s = add( x_e, *q_win ); + move16(); + + FOR( i = 0; i < R2; i++ ) + { + y[l + m + R2 + i] = round_fx( L_shl( Mpy_32_16_1( tmp_buf[L2 + i], fac ), s ) ); /* fold out right end of DCT exp(fac_e)*/ + move16(); + } + + FOR( i = 0; i < L2; i++ ) + { + y[i] = round_fx( L_shl( Mpy_32_16_1( tmp_buf[L2 + m + R2 + i], negfac ), s ) ); /* negate, fold out left end of DCT exp(fac_e)*/ + move16(); + } + + FOR( i = 0; i < ( ( L2 + m + R2 ) >> 1 ); i++ ) + { + Word16 f; + f = round_fx( L_shl( Mpy_32_16_1( tmp_buf[L2 + i], fac ), s ) ); + + y[L2 + i] = round_fx( L_shl( Mpy_32_16_1( tmp_buf[l + m + R2 - 1 - i], negfac ), s ) ); /* time-reverse mid of DCT exp(fac_e)*/ + move16(); + + y[l + m + R2 - 1 - i] = negate( f ); + move16(); + } +} + +/*-------------------------------------------------------------------* + * TCX_MDXT_Inverse_fx() + * + * + *-------------------------------------------------------------------*/ +static +void TCX_MDXT_Inverse_qwin_fx( + const Word32 *x, /* exp(x_e) */ + Word16 x_e, + Word16 *y, /* Qx */ + const Word16 l, /* Q0 */ + const Word16 m, /* Q0 */ + const Word16 r, /* Q0 */ + const UWord16 kernel_type,/* Q0 */ + Word16 *q_win +) +{ + Word16 signLeft; + Word16 signRight; + Word16 i, fac, negfac, s, fac_e; + const Word16 L2 = shr( l, 1 ), R2 = shr( r, 1 ); + Word32 tmp_buf[N_MAX + L_MDCT_OVLP_MAX / 2]; + Word16 f; + + set32_fx( tmp_buf, 0, N_MAX + L_MDCT_OVLP_MAX / 2 ); + + edxt_fx( x, tmp_buf + L2, add( add( L2, m ), R2 ), kernel_type, TRUE ); + + fac = TCX_MDCT_Inverse_GetScaleFactor( add( add( shr( l, 1 ), m ), shr( r, 1 ) ), &fac_e ); + x_e = add( x_e, fac_e ); + + negfac = negate( fac ); + IF( GE_16( kernel_type, MDCT_II ) ) + { + signLeft = negfac; + } + ELSE + { + signLeft = fac; + } + // signRight = ( kernel_type & 1 ? fac : negfac ); + IF( L_and( kernel_type, 1 ) ) + { + signRight = fac; + } + ELSE + { + signRight = negfac; + } + +#if 1 + IF ( *q_win == -2 ) { + // x_e + q_win == L_norm_arr(tmp_buf, , *q_win ); + // q_win = L_norm_arr(tmp_buf, , *q_win ) - x_e; + s = L_norm_arr( tmp_buf + L2, m + R2 + L2); + *q_win = s_min( sub( s, x_e ), *q_win ); + } +#else + assert( *q_win == 0 || *q_win == -2 ); +#endif + s = add( x_e, *q_win ); + move16(); + + FOR( i = 0; i < L2; i++ ) + { + y[i] = round_fx( L_shl( Mpy_32_16_1( tmp_buf[L2 + m + R2 + i], signLeft ), s ) ); /* fold out the left end exp(fac_e)*/ + } + + FOR( i = 0; i < R2; i++ ) + { + y[l + m + R2 + i] = round_fx( L_shl( Mpy_32_16_1( tmp_buf[L2 + i], signRight ), s ) ); /* ...and right end exp(fac_e)*/ + move16(); + } + + FOR( i = 0; i < ( ( L2 + m + R2 ) >> 1 ); i++ ) + { + + f = round_fx( L_shl( Mpy_32_16_1( tmp_buf[L2 + i], negfac ), s ) ); + + y[L2 + i] = round_fx( L_shl( Mpy_32_16_1( tmp_buf[l + m + R2 - 1 - i], negfac ), s ) ); /* time-reverse mid of DCT exp(fac_e)*/ + move16(); + + y[l + m + R2 - 1 - i] = f; + move16(); + } + + return; +} + +#endif + void IMDCT_ivas_fx( Word32 *x_fx, // Q(q_x) Word16 q_x, +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN + Word16 *old_syn_overl_fx, // *Q_old_syn_overl_fx + Word16 *Q_old_syn_overl_fx, + Word16 *syn_Overl_TDAC_fx, // *Q_syn_Overl_TDAC_fx + Word16 *Q_syn_Overl_TDAC_fx, +#else Word16 *old_syn_overl_fx, // Q(-2) Word16 *syn_Overl_TDAC_fx, // Q(-2) +#endif Word16 *xn_buf_fx, // Q(-2) const Word16 *tcx_aldo_window_1_fx, // Q(15) const PWord16 *tcx_aldo_window_1_trunc_fx, // Q(15) @@ -2608,7 +2946,11 @@ void IMDCT_ivas_fx( Decoder_State *st, const Word16 fullbandScale, Word16 *acelp_zir_fx, +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN + Word16 *pq_win) +#else Word16 q_win ) // Q(-2) +#endif { Word16 i, nz, aldo, w, L_win, L_ola; Word16 win_fx[( L_FRAME_PLUS + L_MDCT_OVLP_MAX ) / 2]; @@ -2617,7 +2959,16 @@ void IMDCT_ivas_fx( Word16 x_e_hdrm; Word32 c; Word16 exp; +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN + Word16 q_win = *pq_win; + move16(); + x_e_hdrm = sub( Q16, q_x ); + IF ( q_win == -2 ) { + q_win = IMDCT_ivas_fx_adjust_qwin( *Q_syn_Overl_TDAC_fx, *Q_old_syn_overl_fx, hTcxDec->Q_old_syn_Overl, *q_old_out_fx, q_win ); + } +#else x_e_hdrm = add( q_win, sub( Q16, q_x ) ); +#endif aldo = 0; move16(); @@ -2691,11 +3042,37 @@ void IMDCT_ivas_fx( Word16 L_spec_TCX5_tmp = 0; move16(); +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN + Word16 q_win_prev; +#endif + FOR( w = 0; w < 2; w++ ) { test(); test(); L_spec_TCX5_tmp = imult1616( w, L_spec_TCX5 ); +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN + IF( EQ_16( kernel_type, MDST_IV ) || s_and( kernel_type, w ) ) + { + TCX_MDST_Inverse_qwin_fx( x_fx + L_spec_TCX5_tmp, x_e_hdrm, win_fx, L_ola, sub( L_win, L_ola ), L_ola, &q_win ); + } + ELSE IF( ( kernel_type != 0 ) && ( w == 0 ) ) /* type 1 or 2 */ + { + TCX_MDXT_Inverse_qwin_fx( x_fx + L_spec_TCX5_tmp, x_e_hdrm, win_fx, L_ola, sub( L_win, L_ola ), L_ola, kernel_type, &q_win ); + } + ELSE + { + TCX_MDCT_Inverse_qwin_fx( x_fx + L_spec_TCX5_tmp, x_e_hdrm, win_fx, L_ola, sub( L_win, L_ola ), L_ola, st->element_mode, &q_win ); + } + + if ( w > 0 ) { + assert( q_win_prev == q_win ); + } else { + q_win_prev = q_win; + } + + IMDCT_ivas_fx_rescale( syn_Overl_TDAC_fx, Q_syn_Overl_TDAC_fx, old_syn_overl_fx, Q_old_syn_overl_fx, hTcxDec->old_syn_Overl, &hTcxDec->Q_old_syn_Overl, old_out_fx, q_old_out_fx, q_win, FB_flag ); +#else IF( EQ_16( kernel_type, MDST_IV ) || s_and( kernel_type, w ) ) { TCX_MDST_Inverse_fx( x_fx + L_spec_TCX5_tmp, x_e_hdrm, win_fx, L_ola, sub( L_win, L_ola ), L_ola ); @@ -2708,6 +3085,7 @@ void IMDCT_ivas_fx( { TCX_MDCT_Inverse( x_fx + L_spec_TCX5_tmp, x_e_hdrm, win_fx, L_ola, sub( L_win, L_ola ), L_ola, st->element_mode ); } +#endif tcx_windowing_synthesis_current_frame( win_fx, tcx_aldo_window_2_fx, tcx_mdct_window_half_fx, tcx_mdct_window_minimum_fx, L_ola, tcx_mdct_window_half_length, tcx_mdct_window_min_length, ( w > 0 ) ? 0 : left_rect, ( w > 0 ) || ( w == 0 && index == 2 ) ? MIN_OVERLAP : hTcxCfg->tcx_last_overlap_mode, acelp_zir_fx, hTcxDec->old_syn_Overl, syn_Overl_TDAC_fx, st->old_Aq_12_8_fx, tcx_mdct_window_trans_fx, L_win, tcx_offset < 0 ? -tcx_offset : 0, ( w > 0 ) || ( frame_cnt > 0 ) ? 1 : st->last_core, ( w > 0 ) || ( frame_cnt > 0 ) ? 0 : (Word8) st->last_is_cng, fullbandScale ); @@ -2746,6 +3124,23 @@ void IMDCT_ivas_fx( set16_fx( win_fx, 0, shr( add( L_FRAME_PLUS, L_MDCT_OVLP_MAX ), 1 ) ); /* 1st TCX-5 window, special MDCT with minimum overlap on right side */ +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN + Word16 q_win_prev; + + IF( EQ_16( kernel_type, MDST_IV ) ) + { + TCX_MDST_Inverse_qwin_fx( x_fx, x_e_hdrm, win_fx + L_win, 0, sub( L_win, shr( L_ola, 1 ) ), L_ola, &q_win ); + } + ELSE IF( NE_16( kernel_type, MDCT_IV ) ) /* type 1 or 2 */ + { + TCX_MDXT_Inverse_qwin_fx( x_fx, x_e_hdrm, win_fx + L_win, 0, sub( L_win, shr( L_ola, 1 ) ), L_ola, kernel_type, &q_win ); + } + ELSE + { + TCX_MDCT_Inverse_qwin_fx( x_fx, x_e_hdrm, win_fx + L_win, 0, sub( L_win, shr( L_ola, 1 ) ), L_ola, st->element_mode, &q_win ); + } + q_win_prev = q_win; +#else IF( EQ_16( kernel_type, MDST_IV ) ) { TCX_MDST_Inverse_fx( x_fx, x_e_hdrm, win_fx + L_win, 0, sub( L_win, shr( L_ola, 1 ) ), L_ola ); @@ -2758,6 +3153,7 @@ void IMDCT_ivas_fx( { TCX_MDCT_Inverse( x_fx, x_e_hdrm, win_fx + L_win, 0, sub( L_win, shr( L_ola, 1 ) ), L_ola, st->element_mode ); } +#endif set16_fx( xn_buf_fx, 0, shr( overlap, 1 ) ); @@ -2765,6 +3161,20 @@ void IMDCT_ivas_fx( Copy( win_fx + L_win, xn_buf_fx + shr( overlap, 1 ), add( L_win, shr( L_ola, 1 ) ) ); /* 2nd TCX-5 window, regular MDCT with minimum overlap on both sides */ +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN + IF( s_and( kernel_type, 1 ) ) + { + TCX_MDST_Inverse_qwin_fx( x_fx + L_spec_TCX5, x_e_hdrm, win_fx, L_ola, sub( L_win, L_ola ), L_ola, &q_win ); + } + ELSE + { + TCX_MDCT_Inverse_qwin_fx( x_fx + L_spec_TCX5, x_e_hdrm, win_fx, L_ola, sub( L_win, L_ola ), L_ola, st->element_mode, &q_win ); + } + + assert( q_win_prev == q_win ); + + IMDCT_ivas_fx_rescale( syn_Overl_TDAC_fx, Q_syn_Overl_TDAC_fx, old_syn_overl_fx, Q_old_syn_overl_fx, hTcxDec->old_syn_Overl, &hTcxDec->Q_old_syn_Overl, old_out_fx, q_old_out_fx, q_win, FB_flag ); +#else IF( s_and( kernel_type, 1 ) ) { TCX_MDST_Inverse_fx( x_fx + L_spec_TCX5, x_e_hdrm, win_fx, L_ola, sub( L_win, L_ola ), L_ola ); @@ -2773,6 +3183,7 @@ void IMDCT_ivas_fx( { TCX_MDCT_Inverse( x_fx + L_spec_TCX5, x_e_hdrm, win_fx, L_ola, sub( L_win, L_ola ), L_ola, st->element_mode ); } +#endif tcx_windowing_synthesis_current_frame( win_fx, tcx_aldo_window_2_fx, tcx_mdct_window_half_fx, tcx_mdct_window_minimum_fx, L_ola, tcx_mdct_window_half_length, tcx_mdct_window_min_length, 0, /* left_rect */ MIN_OVERLAP, /* left_mode */ acelp_zir_fx, hTcxDec->old_syn_Overl, syn_Overl_TDAC_fx, st->old_Aq_12_8_fx, tcx_mdct_window_trans_fx, L_win, ( tcx_offset < 0 ) ? -tcx_offset : 0, 1, /* st->last_mode_bfi */ 0, /* st->last_is_cng */ fullbandScale ); @@ -2807,6 +3218,22 @@ void IMDCT_ivas_fx( ELSE { /* default, i.e. maximum overlap, single transform, no grouping */ +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN + IF( EQ_16( kernel_type, MDST_IV ) ) + { + TCX_MDST_Inverse_qwin_fx( x_fx, x_e_hdrm, xn_buf_fx, overlap, sub( L_frame, overlap ), overlap, &q_win ); + } + ELSE IF( NE_16( kernel_type, MDCT_IV ) ) /* type 1 or 2 */ + { + TCX_MDXT_Inverse_qwin_fx( x_fx, x_e_hdrm, xn_buf_fx, overlap, sub( L_frame, overlap ), overlap, kernel_type, &q_win ); + } + ELSE + { + TCX_MDCT_Inverse_qwin_fx( x_fx, x_e_hdrm, xn_buf_fx, overlap, sub( L_frame, overlap ), overlap, st->element_mode, &q_win ); + } + + IMDCT_ivas_fx_rescale( syn_Overl_TDAC_fx, Q_syn_Overl_TDAC_fx, old_syn_overl_fx, Q_old_syn_overl_fx, hTcxDec->old_syn_Overl, &hTcxDec->Q_old_syn_Overl, old_out_fx, q_old_out_fx, q_win, FB_flag ); +#else IF( EQ_16( kernel_type, MDST_IV ) ) { TCX_MDST_Inverse_fx( x_fx, x_e_hdrm, xn_buf_fx, overlap, sub( L_frame, overlap ), overlap ); @@ -2819,6 +3246,7 @@ void IMDCT_ivas_fx( { TCX_MDCT_Inverse( x_fx, x_e_hdrm, xn_buf_fx, overlap, sub( L_frame, overlap ), overlap, st->element_mode ); } +#endif tcx_windowing_synthesis_current_frame( xn_buf_fx, tcx_aldo_window_2_fx, tcx_mdct_window_half_fx, tcx_mdct_window_minimum_fx, overlap, tcx_mdct_window_half_length, tcx_mdct_window_min_length, left_rect, !bfi && ( frame_cnt > 0 ) && ( index == 0 ) && NE_16( st->last_core, ACELP_CORE ) ? MIN_OVERLAP : index, acelp_zir_fx, hTcxDec->old_syn_Overl, syn_Overl_TDAC_fx, st->old_Aq_12_8_fx, tcx_mdct_window_trans_fx, shr( L_frame_glob, 1 ), ( tcx_offset < 0 ) ? -tcx_offset : 0, ( frame_cnt > 0 /*|| (st->last_con_tcx )*/ ) ? 1 : st->last_core_bfi, ( frame_cnt > 0 ) ? 0 : (Word8) st->last_is_cng, fullbandScale ); @@ -2864,6 +3292,10 @@ void IMDCT_ivas_fx( q_tmp_fx_32 = q_xn_buf_fx_32; move16(); +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN + IMDCT_ivas_fx_rescale( syn_Overl_TDAC_fx, Q_syn_Overl_TDAC_fx, old_syn_overl_fx, Q_old_syn_overl_fx, hTcxDec->old_syn_Overl, &hTcxDec->Q_old_syn_Overl, old_out_fx, q_old_out_fx, q_win, FB_flag ); +#endif + Word16 diff = sub( q_tmp_fx_32, q_win ); #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD Word16 q_old_out_diff = sub( q_tmp_fx_32, *q_old_out_fx ); @@ -2871,6 +3303,7 @@ void IMDCT_ivas_fx( FOR( Word16 ind = 0; ind < L_frame; ind++ ) { #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD + assert( L_shr(L_shl( old_out_fx[ind], q_old_out_diff ), q_old_out_diff ) == old_out_fx[ind] ); old_out_fx_32[ind] = L_shl( old_out_fx[ind], q_old_out_diff ); #else old_out_fx_32[ind] = L_shl( old_out_fx[ind], diff ); @@ -2884,10 +3317,12 @@ void IMDCT_ivas_fx( { #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD old_out_fx[ind] = extract_l( L_shr( old_out_fx_32[ind], q_old_out_diff ) ); + assert( extract_h( L_shr( old_out_fx_32[ind], q_old_out_diff ) ) == 0 ); #else old_out_fx[ind] = extract_l( L_shr( old_out_fx_32[ind], diff ) ); #endif xn_buf_fx[ind] = extract_l( L_shr( xn_buf_fx_32[ind], diff ) ); + assert( extract_h( L_shr( xn_buf_fx_32[ind], diff ) ) == 0 ); move16(); move16(); } @@ -2896,8 +3331,8 @@ void IMDCT_ivas_fx( { #ifndef FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD Word16 q_old_out = q_win; -#endif move16(); +#endif edct_fx( x_fx, xn_buf_fx_32 + add( shr( overlap, 1 ), nz ), L_frame, &q_xn_buf_fx_32 ); Word16 res_m, res_e; res_e = 0; @@ -2913,9 +3348,15 @@ void IMDCT_ivas_fx( q_tmp_fx_32 = sub( q_xn_buf_fx_32, res_e ); // v_multc_fixed( xn_buf_fx_32 + overlap / 2 + nz, (float) sqrt( (float) L_frame / NORM_MDCT_FACTOR ), tmp_fx_32, L_frame ); +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN + // L_norm_arr( xn_buf_fx, L_frame ) + IMDCT_ivas_fx_rescale( syn_Overl_TDAC_fx, Q_syn_Overl_TDAC_fx, old_syn_overl_fx, Q_old_syn_overl_fx, hTcxDec->old_syn_Overl, &hTcxDec->Q_old_syn_Overl, old_out_fx, q_old_out_fx, q_win, FB_flag ); +#endif + Word16 q_diff = sub( q_xn_buf_fx_32, q_win ); FOR( Word16 ind = 0; ind < L_frame; ind++ ) { + assert( extract_h( L_shr( xn_buf_fx_32[( ind + ( overlap / 2 ) ) + nz], q_diff ) ) == 0 || extract_h( L_shr( xn_buf_fx_32[( ind + ( overlap / 2 ) ) + nz], q_diff ) ) == -1 ); xn_buf_fx[( ind + ( overlap / 2 ) ) + nz] = extract_l( L_shr( xn_buf_fx_32[( ind + ( overlap / 2 ) ) + nz], q_diff ) ); move16(); } @@ -2961,7 +3402,23 @@ void IMDCT_ivas_fx( acelp_mem_len = 0; move16(); } +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN + IF( EQ_16( kernel_type, MDST_IV ) ) + { + TCX_MDST_Inverse_qwin_fx( x_fx, x_e_hdrm, xn_buf_fx, overlap, L_frame - overlap, overlap, &q_win ); + } + ELSE IF( NE_16( kernel_type, MDCT_IV ) ) /* type 1 or 2 */ + { + TCX_MDXT_Inverse_qwin_fx( x_fx, x_e_hdrm, xn_buf_fx, overlap, L_frame - overlap, overlap, kernel_type, &q_win ); + } + ELSE + { + TCX_MDCT_Inverse_qwin_fx( x_fx, x_e_hdrm, xn_buf_fx, overlap, L_frame - overlap, overlap, st->element_mode, &q_win ); + } + // xn_buf_fx, NULL, L_frame, + IMDCT_ivas_fx_rescale( syn_Overl_TDAC_fx, Q_syn_Overl_TDAC_fx, old_syn_overl_fx, Q_old_syn_overl_fx, hTcxDec->old_syn_Overl, &hTcxDec->Q_old_syn_Overl, old_out_fx, q_old_out_fx, q_win, FB_flag ); +#else IF( EQ_16( kernel_type, MDST_IV ) ) { TCX_MDST_Inverse_fx( x_fx, x_e_hdrm, xn_buf_fx, overlap, L_frame - overlap, overlap ); @@ -2974,7 +3431,7 @@ void IMDCT_ivas_fx( { TCX_MDCT_Inverse( x_fx, x_e_hdrm, xn_buf_fx, overlap, L_frame - overlap, overlap, st->element_mode ); } - +#endif /*-----------------------------------------------------------* * Windowing, overlap and add * *-----------------------------------------------------------*/ @@ -3228,6 +3685,10 @@ void IMDCT_ivas_fx( } } } +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN + *pq_win = q_win; + move16(); +#endif return; } @@ -3647,6 +4108,52 @@ void decoder_tcx_ivas_fx( decoder_tcx_tns_fx( st, L_frame_glob, L_spec, L_frame, L_frameTCX, x_fx, fUseTns, &tnsData, bfi, frame_cnt, 0, NULL ); +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN + Scale_sig32( x_fx, N_MAX, sub( x_e, 20 ) ); // Scaling x_fx to Q11 + Scale_sig( xn_buf_fx, L_MDCT_OVLP_MAX + L_FRAME_PLUS + L_MDCT_OVLP_MAX, sub( st->Q_syn, 14 ) ); // Scaling xn_buf_fx to Q_syn + x_e = sub( 31, 11 ); + + IF( st->igf != 0 ) + { + Scale_sig32( st->hIGFDec->virtualSpec, ( N_MAX_TCX - IGF_START_MN ), ( sub( st->hIGFDec->virtualSpec_e, x_e ) ) ); + st->hIGFDec->virtualSpec_e = x_e; + move16(); + } + +#if 1 + /* Scaling down buffers for decoder_tcx_imdct_fx*/ + Scale_sig( st->hTcxDec->syn_Overl_TDACFB, L_FRAME_MAX / 2, sub( st->Q_syn, st->hTcxDec->Q_syn_Overl_TDACFB ) ); // Scaling to Q_syn + st->hTcxDec->Q_syn_Overl_TDACFB = st->Q_syn; + Scale_sig( st->hTcxDec->syn_Overl_TDAC, L_FRAME32k / 2, sub( st->Q_syn, st->hTcxDec->Q_syn_Overl_TDAC ) ); // Scaling to Q_syn + st->hTcxDec->Q_syn_Overl_TDAC = st->Q_syn; + Scale_sig( st->hTcxDec->old_syn_Overl, 320, st->Q_syn - st->hTcxDec->Q_old_syn_Overl ); // Scaling to Q_syn + st->hTcxDec->Q_old_syn_Overl = st->Q_syn; +#endif + +#if 1 + Scale_sig( synth_fx, L_frame_glob, st->Q_syn ); // Scaling to Q_syn + Scale_sig( synthFB_fx, L_frameTCX_glob, st->Q_syn ); // Scaling to Q_syn +#endif + + Copy_Scale_sig_16_32_no_sat( st->old_Aq_12_8_fx, st->old_Aq_12_8_fx_32, M + 1, ( sub( 28, ( sub( 15, norm_s( sub( st->old_Aq_12_8_fx[0], 1 ) ) ) ) ) ) ); + + Word16 q_win; + q_win = st->Q_syn; + + decoder_tcx_imdct_fx( st, L_frame_glob, L_frameTCX_glob, L_spec, tcx_offset, tcx_offsetFB, L_frame, L_frameTCX, left_rect, &x_fx[0], q_x, xn_buf_fx, &q_win, MDCT_IV, + fUseTns, &synth_fx[0], &synthFB_fx[0], bfi, frame_cnt, sba_dirac_stereo_flag ); + + assert( q_win == 0 ); + + /* Scaling up again */ + Scale_sig( synth_fx, L_frame_glob, sub( st->Q_syn, q_win ) ); + Scale_sig( synthFB_fx, L_frameTCX_glob, sub( st->Q_syn, q_win ) ); + // Scale_sig( st->hTcxDec->syn_Overl, L_FRAME32k / 2, 1 ); + + Scale_sig( st->hTcxDec->old_syn_Overl, 320, ( -2 - st->hTcxDec->Q_old_syn_Overl ) ); // Scaling to Q-2 + st->hTcxDec->Q_old_syn_Overl = -2; + +#else Scale_sig32( x_fx, N_MAX, sub( x_e, 20 ) ); // Scaling x_fx to Q11 Scale_sig( xn_buf_fx, L_MDCT_OVLP_MAX + L_FRAME_PLUS + L_MDCT_OVLP_MAX, sub( st->Q_syn, 14 ) ); // Scaling xn_buf_fx to Q_syn x_e = sub( 31, 11 ); @@ -3696,6 +4203,7 @@ void decoder_tcx_ivas_fx( #endif Scale_sig( st->hTcxDec->old_syn_Overl, 320, ( -2 - st->hTcxDec->Q_old_syn_Overl ) ); // Scaling to Q-2 st->hTcxDec->Q_old_syn_Overl = -2; +#endif } /*-------------------------------------------------------------------* @@ -5082,7 +5590,11 @@ void decoder_tcx_imdct_fx( Word32 x_fx[N_MAX], // Q(11) Word16 q_x, Word16 xn_buf_fx[], // Q(-2) +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN + Word16 *q_win, +#else Word16 q_win, +#endif const UWord16 kernelType, /* i : TCX transform kernel type */ const Word16 fUseTns, /* i : flag that is set if TNS data is present */ Word16 synth_fx[], // Q(-2) /* i/o: synth[-M..L_frame] */ @@ -5108,7 +5620,9 @@ void decoder_tcx_imdct_fx( Word16 q_a_itf = 15; Word16 x_e = sub( 31, q_x ); move16(); +#ifndef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN Word16 shift_q = sub( q_x, q_win ); +#endif /*-----------------------------------------------------------------* * Initializations @@ -5261,7 +5775,11 @@ void decoder_tcx_imdct_fx( IF( NE_16( st->element_mode, IVAS_CPE_DFT ) && !sba_dirac_stereo_flag ) { +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN + IMDCT_ivas_fx( xn_bufFB_fx, q_x, hTcxDec->syn_Overl, &hTcxDec->Q_syn_Overl, hTcxDec->syn_Overl_TDAC, &hTcxDec->Q_syn_Overl_TDAC, xn_buf_fx, hTcxCfg->tcx_aldo_window_1, hTcxCfg->tcx_aldo_window_1_trunc, hTcxCfg->tcx_aldo_window_2, +#else IMDCT_ivas_fx( xn_bufFB_fx, q_x, hTcxDec->syn_Overl, hTcxDec->syn_Overl_TDAC, xn_buf_fx, hTcxCfg->tcx_aldo_window_1, hTcxCfg->tcx_aldo_window_1_trunc, hTcxCfg->tcx_aldo_window_2, +#endif hTcxCfg->tcx_mdct_window_half, hTcxCfg->tcx_mdct_window_minimum, hTcxCfg->tcx_mdct_window_trans, hTcxCfg->tcx_mdct_window_half_length, hTcxCfg->tcx_mdct_window_min_length, index, #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD kernelType, left_rect, tcx_offset, overlap, L_frame, L_frameTCX, shr( s_max( L_frameTCX, L_spec ), 1 ), L_frame_glob, frame_cnt, bfi, st->hHQ_core->old_out_LB_fx, &st->hHQ_core->Q_old_wtda_LB, 0, st, 0, acelp_zir_fx, q_win ); @@ -5287,8 +5805,11 @@ void decoder_tcx_imdct_fx( IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) || ( sba_dirac_stereo_flag != 0 ) ) { Copy32( x_fx, xn_bufFB_fx, s_max( L_spec, s_max( L_frame, L_frameTCX ) ) ); // q_x - +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN + IMDCT_ivas_fx( xn_bufFB_fx, q_x, hTcxDec->syn_Overl, &hTcxDec->Q_syn_Overl, hTcxDec->syn_Overl_TDAC, &hTcxDec->Q_syn_Overl_TDAC, xn_buf_fx, hTcxCfg->tcx_aldo_window_1, hTcxCfg->tcx_aldo_window_1_trunc, hTcxCfg->tcx_aldo_window_2, hTcxCfg->tcx_mdct_window_half, hTcxCfg->tcx_mdct_window_minimum, hTcxCfg->tcx_mdct_window_trans, hTcxCfg->tcx_mdct_window_half_length, hTcxCfg->tcx_mdct_window_min_length, index, +#else IMDCT_ivas_fx( xn_bufFB_fx, q_x, hTcxDec->syn_Overl, hTcxDec->syn_Overl_TDAC, xn_buf_fx, hTcxCfg->tcx_aldo_window_1, hTcxCfg->tcx_aldo_window_1_trunc, hTcxCfg->tcx_aldo_window_2, hTcxCfg->tcx_mdct_window_half, hTcxCfg->tcx_mdct_window_minimum, hTcxCfg->tcx_mdct_window_trans, hTcxCfg->tcx_mdct_window_half_length, hTcxCfg->tcx_mdct_window_min_length, index, +#endif #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD kernelType, left_rect, tcx_offset, overlap, L_frame, L_frameTCX, shr( s_max( L_frameTCX, L_spec ), 1 ), L_frame_glob, frame_cnt, bfi, st->hHQ_core->old_out_LB_fx, &st->hHQ_core->Q_old_wtda_LB, 0, st, 0, acelp_zir_fx, q_win ); #else @@ -5296,6 +5817,10 @@ void decoder_tcx_imdct_fx( #endif } +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN + Word16 shift_q = sub( q_x, *q_win ); +#endif + FOR( Word16 ind = 0; ind < L_MDCT_OVLP_MAX + L_FRAME_PLUS + L_MDCT_OVLP_MAX; ind++ ) { xn_bufFB_fx_16[ind] = extract_l( L_shr( xn_bufFB_fx[ind], shift_q ) ); // q_x @@ -5308,7 +5833,11 @@ void decoder_tcx_imdct_fx( IF( st->element_mode != EVS_MONO ) { +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN + IMDCT_ivas_fx( x_tmp_fx, q_x, hTcxDec->syn_OverlFB, &hTcxDec->Q_syn_OverlFB, hTcxDec->syn_Overl_TDACFB, &hTcxDec->Q_syn_Overl_TDACFB, xn_bufFB_fx_16, hTcxCfg->tcx_aldo_window_1_FB, hTcxCfg->tcx_aldo_window_1_FB_trunc, hTcxCfg->tcx_aldo_window_2_FB, +#else IMDCT_ivas_fx( x_tmp_fx, q_x, hTcxDec->syn_OverlFB, hTcxDec->syn_Overl_TDACFB, xn_bufFB_fx_16, hTcxCfg->tcx_aldo_window_1_FB, hTcxCfg->tcx_aldo_window_1_FB_trunc, hTcxCfg->tcx_aldo_window_2_FB, +#endif hTcxCfg->tcx_mdct_window_halfFB, hTcxCfg->tcx_mdct_window_minimumFB, hTcxCfg->tcx_mdct_window_transFB, hTcxCfg->tcx_mdct_window_half_lengthFB, hTcxCfg->tcx_mdct_window_min_lengthFB, index, #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD kernelType, left_rect, tcx_offsetFB, overlapFB, L_frameTCX, L_frameTCX, shr( s_max( L_frameTCX, L_spec ), 1 ), L_frameTCX_glob, frame_cnt, bfi, st->hHQ_core->old_out_fx, &st->hHQ_core->Q_old_wtda, 1, st, ratio, acelp_zir_fx, q_win ); @@ -5318,14 +5847,22 @@ void decoder_tcx_imdct_fx( } ELSE { - +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN + IMDCT_ivas_fx( x_fx, q_x, hTcxDec->syn_OverlFB, &hTcxDec->Q_syn_OverlFB, hTcxDec->syn_Overl_TDACFB, &hTcxDec->Q_syn_Overl_TDACFB, xn_bufFB_fx_16, hTcxCfg->tcx_aldo_window_1_FB, hTcxCfg->tcx_aldo_window_1_FB_trunc, hTcxCfg->tcx_aldo_window_2_FB, hTcxCfg->tcx_mdct_window_halfFB, hTcxCfg->tcx_mdct_window_minimumFB, hTcxCfg->tcx_mdct_window_transFB, hTcxCfg->tcx_mdct_window_half_lengthFB, hTcxCfg->tcx_mdct_window_min_lengthFB, index, +#else IMDCT_ivas_fx( x_fx, q_x, hTcxDec->syn_OverlFB, hTcxDec->syn_Overl_TDACFB, xn_bufFB_fx_16, hTcxCfg->tcx_aldo_window_1_FB, hTcxCfg->tcx_aldo_window_1_FB_trunc, hTcxCfg->tcx_aldo_window_2_FB, hTcxCfg->tcx_mdct_window_halfFB, hTcxCfg->tcx_mdct_window_minimumFB, hTcxCfg->tcx_mdct_window_transFB, hTcxCfg->tcx_mdct_window_half_lengthFB, hTcxCfg->tcx_mdct_window_min_lengthFB, index, +#endif #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD kernelType, left_rect, tcx_offsetFB, overlapFB, L_frameTCX, L_frameTCX, shr( s_max( L_frameTCX, L_spec ), 1 ), L_frameTCX_glob, frame_cnt, bfi, st->hHQ_core->old_out_fx, &st->hHQ_core->Q_old_wtda, 1, st, ratio, acelp_zir_fx, q_win ); #else kernelType, left_rect, tcx_offsetFB, overlapFB, L_frameTCX, L_frameTCX, shr( s_max( L_frameTCX, L_spec ), 1 ), L_frameTCX_glob, frame_cnt, bfi, st->hHQ_core->old_out_fx, 1, st, ratio, acelp_zir_fx, q_win ); #endif } + +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN + shift_q = sub( q_x, *q_win ); +#endif + FOR( Word16 ind = 0; ind < L_MDCT_OVLP_MAX + L_FRAME_PLUS + L_MDCT_OVLP_MAX; ind++ ) { xn_bufFB_fx[ind] = L_shl( L_deposit_l( xn_bufFB_fx_16[ind] ), shift_q ); // Q_x diff --git a/lib_dec/er_dec_acelp_fx.c b/lib_dec/er_dec_acelp_fx.c index e30553d38..e1321d9aa 100644 --- a/lib_dec/er_dec_acelp_fx.c +++ b/lib_dec/er_dec_acelp_fx.c @@ -1057,10 +1057,10 @@ void con_acelp_fx( move16(); } set16_fx( &hHQ_core->old_out_LB_fx[( W1 + n )], 0, n ); - +#ifndef FIX_1348_BIT_PRECISION_IMPROVEMENT hHQ_core->Q_old_wtda = hHQ_core->Q_old_wtda_LB; move16(); - +#endif FOR( i = 0; i < W2; i++ ) { @@ -1105,6 +1105,10 @@ void con_acelp_fx( move16(); lerp( hTcxDec->syn_Overl, hTcxDec->syn_OverlFB, shr( hTcxDec->L_frameTCX, 1 ), shr( st->L_frame, 1 ) ); lerp( hHQ_core->old_out_LB_fx, hHQ_core->old_out_fx, hTcxDec->L_frameTCX, st->L_frame ); +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT + hHQ_core->Q_old_wtda = hHQ_core->Q_old_wtda_LB; + move16(); +#endif /* copy total excitation exc2 as 16kHz for acelp mode1 decoding */ IF( st->hWIDec != NULL ) diff --git a/lib_dec/er_dec_tcx_fx.c b/lib_dec/er_dec_tcx_fx.c index e804d2009..e64eb9c38 100644 --- a/lib_dec/er_dec_tcx_fx.c +++ b/lib_dec/er_dec_tcx_fx.c @@ -1057,6 +1057,10 @@ void con_tcx_fx( hTcxDec->Q_syn_Overl_TDAC = hTcxDec->Q_syn_Overl_TDACFB; move16(); lerp( st->hHQ_core->old_out_fx, st->hHQ_core->old_out_LB_fx, st->L_frame, L_frame ); +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT + hHQ_core->Q_old_wtda_LB = hHQ_core->Q_old_wtda; + move16(); +#endif st->old_enr_LP = Enr_1_Az_fx( A_local, L_SUBFR ); /*Q3*/ move16(); @@ -1947,6 +1951,10 @@ void con_tcx_ivas_fx( lerp( syn + sub( L_frame, shr( L_frame, 1 ) ), hTcxDec->old_syn_Overl, shr( st->L_frame, 1 ), shr( L_frame, 1 ) ); +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT + hTcxDec->Q_old_syn_Overl = Q_syn; + move16(); +#endif Copy( syn + sub( L_frame, n ), hHQ_core->old_out_fx, sub( L_frame, n ) ); /*Q_syn*/ FOR( i = 0; i < W12; i++ ) @@ -2035,8 +2043,10 @@ void con_tcx_ivas_fx( /* update memory for low band */ st->Q_syn = Q_syn; move16(); +#ifndef FIX_1348_BIT_PRECISION_IMPROVEMENT Scale_sig( hTcxDec->old_syn_Overl, shr( st->L_frame, 1 ), sub( -1, Q_syn ) ); /*Q_syn*/ st->hTcxDec->Q_old_syn_Overl = -1; +#endif lerp( hTcxDec->syn_OverlFB, hTcxDec->syn_Overl, shr( st->L_frame, 1 ), shr( L_frame, 1 ) ); lerp( hTcxDec->syn_Overl_TDACFB, hTcxDec->syn_Overl_TDAC, shr( st->L_frame, 1 ), shr( L_frame, 1 ) ); hTcxDec->Q_syn_Overl_TDAC = hTcxDec->Q_syn_Overl_TDACFB; diff --git a/lib_dec/ivas_mct_dec_fx.c b/lib_dec/ivas_mct_dec_fx.c index bb985ac7b..4c3b8b782 100644 --- a/lib_dec/ivas_mct_dec_fx.c +++ b/lib_dec/ivas_mct_dec_fx.c @@ -346,7 +346,7 @@ ivas_error ivas_mct_dec_fx( } Copy_Scale_sig_16_32_no_sat( hCPE->hCoreCoder[0]->old_Aq_12_8_fx, hCPE->hCoreCoder[0]->old_Aq_12_8_fx_32, add( M, 1 ), sub( 28, sub( 15, norm_s( sub( hCPE->hCoreCoder[0]->old_Aq_12_8_fx[0], 1 ) ) ) ) ); Copy_Scale_sig_16_32_no_sat( hCPE->hCoreCoder[1]->old_Aq_12_8_fx, hCPE->hCoreCoder[1]->old_Aq_12_8_fx_32, add( M, 1 ), sub( 28, sub( 15, norm_s( sub( hCPE->hCoreCoder[1]->old_Aq_12_8_fx[0], 1 ) ) ) ) ); -#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT +#if defined( FIX_1348_BIT_PRECISION_IMPROVEMENT ) && !defined( FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN ) ivas_mdct_core_reconstruct_fx( hCPE, x_fx, synth_fx, fUseTns[cpe_id], 1, st_ivas->mc_mode == MC_MODE_PARAMMC, q_output, e_sig ); #else ivas_mdct_core_reconstruct_fx( hCPE, x_fx, synth_fx, fUseTns[cpe_id], 1, q_output, e_sig ); diff --git a/lib_dec/ivas_mdct_core_dec_fx.c b/lib_dec/ivas_mdct_core_dec_fx.c index d8c64d516..e3ece34ed 100644 --- a/lib_dec/ivas_mdct_core_dec_fx.c +++ b/lib_dec/ivas_mdct_core_dec_fx.c @@ -1083,7 +1083,7 @@ void ivas_mdct_core_reconstruct_fx( /* o : synthesis @output_FS */ // e_sig Word16 fUseTns[CPE_CHANNELS][NB_DIV], /* i : flage TNS enabled */ const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0)*/ -#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT +#if defined( FIX_1348_BIT_PRECISION_IMPROVEMENT ) && !defined( FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN ) const Word16 isParamMC, #endif Word16 q_x, @@ -1101,12 +1101,16 @@ void ivas_mdct_core_reconstruct_fx( Word16 *synthFB_fx; Word16 q_syn = 0; move16(); +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN + Word16 q_win = -2; +#else #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT Word16 q_win = -1; #else Word16 q_win = -2; #endif move16(); +#endif /* TCX */ Word16 xn_buf_fx[L_MDCT_OVLP_MAX + L_FRAME_PLUS + L_MDCT_OVLP_MAX]; // Q(-2) Word16 tcx_offset[CPE_CHANNELS]; @@ -1125,9 +1129,11 @@ void ivas_mdct_core_reconstruct_fx( bfi = sts[0]->bfi; move16(); +#ifndef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT if ( isParamMC ) q_win = -2; +#endif #endif /* TNS, ITF, IMDCT and updates */ @@ -1180,10 +1186,16 @@ void ivas_mdct_core_reconstruct_fx( set16_fx( synthFB_fx, 0, L_FRAME_PLUS + M ); IF( st->core != ACELP_CORE ) { +#ifndef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN Scale_sig( st->hTcxDec->syn_Overl_TDACFB, L_FRAME_MAX / 2, sub( q_win, st->hTcxDec->Q_syn_Overl_TDACFB ) ); // st->hTcxDec->Q_syn_Overl_TDACFB -> q_win + st->hTcxDec->Q_syn_Overl_TDACFB = q_win; + move16(); Scale_sig( st->hTcxDec->syn_Overl_TDAC, L_FRAME32k / 2, sub( q_win, st->hTcxDec->Q_syn_Overl_TDAC ) ); // st->hTcxDec->Q_syn_Overl_TDAC -> q_win + st->hTcxDec->Q_syn_Overl_TDAC = q_win; + move16(); Scale_sig( st->hTcxDec->old_syn_Overl, L_FRAME32k / 2, sub( q_win, st->hTcxDec->Q_old_syn_Overl ) ); // Q(-1 - st->Q_syn) -> q_win st->hTcxDec->Q_old_syn_Overl = q_win; + move16(); Scale_sig( st->hTcxDec->syn_Overl, L_FRAME32k / 2, sub( q_win, st->Q_syn ) ); // Q(st->Q_syn) -> q_win Scale_sig( st->hTcxDec->syn_OverlFB, L_FRAME_MAX / 2, sub( q_win, st->Q_syn ) ); // Q(st->Q_syn) -> q_win Scale_sig( st->hHQ_core->old_out_LB_fx, L_FRAME32k, sub( q_win, st->hHQ_core->Q_old_wtda_LB ) ); // Q(st->hHQ_core->Q_old_wtda_LB) -> q_win @@ -1197,6 +1209,13 @@ void ivas_mdct_core_reconstruct_fx( Scale_sig( synth_buf_fx, add( add( st->hTcxDec->old_synth_len, L_FRAME_PLUS ), M ), sub( q_win, q_syn ) ); // q_syn -> q_win Scale_sig( synth_bufFB_fx, add( add( st->hTcxDec->old_synth_lenFB, L_FRAME_PLUS ), M ), sub( q_win, q_syn ) ); // q_syn -> q_win Scale_sig( st->syn, M + 1, sub( q_win, st->Q_syn ) ); // st->Q_syn -> q_win +#endif +#if 0 + Scale_sig( synth_buf_fx, add( add( st->hTcxDec->old_synth_len, L_FRAME_PLUS ), M ), sub( q_win, q_syn ) ); // q_syn -> q_win + Scale_sig( synth_bufFB_fx, add( add( st->hTcxDec->old_synth_lenFB, L_FRAME_PLUS ), M ), sub( q_win, q_syn ) ); // q_syn -> q_win + Scale_sig( st->syn, M + 1, sub( q_win, st->Q_syn ) ); // st->Q_syn -> q_win +#endif + FOR( k = 0; k < nSubframes[ch]; k++ ) { init_tcx_info_fx( st, L_frame_global[ch], L_frame_globalTCX[ch], k, bfi, &tcx_offset[ch], @@ -1206,6 +1225,18 @@ void ivas_mdct_core_reconstruct_fx( { test(); test(); +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN + IF( ( EQ_16( hCPE->nchan_out, 1 ) && EQ_16( st->hTcxDec->kernel_type[k], MDST_IV ) ) || EQ_16( st->hTcxCfg->tcx_last_overlap_mode, TRANSITION_OVERLAP ) ) + { + decoder_tcx_imdct_fx( st, L_frame_global[ch], L_frame_globalTCX[ch], L_spec[ch], tcx_offset[ch], tcx_offsetFB[ch], L_frame[ch], L_frameTCX[ch], left_rect[ch], x_fx[ch][k], q_x, xn_buf_fx, &q_win, + MDCT_IV, fUseTns[ch][k], &synth_fx[k * L_frame[ch]], &synthFB_fx[k * L_frameTCX[ch]], bfi, k, 0 ); + } + ELSE + { + decoder_tcx_imdct_fx( st, L_frame_global[ch], L_frame_globalTCX[ch], L_spec[ch], tcx_offset[ch], tcx_offsetFB[ch], L_frame[ch], L_frameTCX[ch], left_rect[ch], x_fx[ch][k], q_x, xn_buf_fx, &q_win, + st->hTcxDec->kernel_type[k], fUseTns[ch][k], &synth_fx[k * L_frame[ch]], &synthFB_fx[k * L_frameTCX[ch]], bfi, k, 0 ); + } +#else IF( ( EQ_16( hCPE->nchan_out, 1 ) && EQ_16( st->hTcxDec->kernel_type[k], MDST_IV ) ) || EQ_16( st->hTcxCfg->tcx_last_overlap_mode, TRANSITION_OVERLAP ) ) { decoder_tcx_imdct_fx( st, L_frame_global[ch], L_frame_globalTCX[ch], L_spec[ch], tcx_offset[ch], tcx_offsetFB[ch], L_frame[ch], L_frameTCX[ch], left_rect[ch], x_fx[ch][k], q_x, xn_buf_fx, q_win, @@ -1216,9 +1247,14 @@ void ivas_mdct_core_reconstruct_fx( decoder_tcx_imdct_fx( st, L_frame_global[ch], L_frame_globalTCX[ch], L_spec[ch], tcx_offset[ch], tcx_offsetFB[ch], L_frame[ch], L_frameTCX[ch], left_rect[ch], x_fx[ch][k], q_x, xn_buf_fx, q_win, st->hTcxDec->kernel_type[k], fUseTns[ch][k], &synth_fx[k * L_frame[ch]], &synthFB_fx[k * L_frameTCX[ch]], bfi, k, 0 ); } +#endif } ELSE { +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN + q_win = -2; + move16(); +#endif set16_fx( &synth_fx[k * L_frame[ch]], 0, L_frame[ch] ); set16_fx( &synthFB_fx[k * L_frame[ch]], 0, L_frameTCX[ch] ); /* Note: these buffers are not subframe-based, hence no indexing with k */ @@ -1267,7 +1303,9 @@ void ivas_mdct_core_reconstruct_fx( Scale_sig( synth_bufFB_fx, add( add( st->hTcxDec->old_synth_lenFB, L_FRAME_PLUS ), M ), sub( q_syn, q_win ) ); // q_win -> q_syn Scale_sig( st->syn, M + 1, add( st->Q_syn, 2 ) ); Scale_sig( st->hTcxDec->syn_OverlFB, L_FRAME_MAX / 2, sub( st->Q_syn, q_win ) ); // q_win -> st->Q_syn + st->hTcxDec->Q_syn_OverlFB = st->Q_syn; Scale_sig( st->hTcxDec->syn_Overl, L_FRAME32k / 2, sub( st->Q_syn, q_win ) ); // q_win -> st->Q_syn + st->hTcxDec->Q_syn_Overl = st->Q_syn; #ifndef FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD Scale_sig( st->hHQ_core->old_out_LB_fx, L_FRAME32k, sub( st->Q_syn, q_win ) ); // q_win -> st->Q_syn Scale_sig( st->hHQ_core->old_out_fx, L_FRAME48k, sub( st->Q_syn, q_win ) ); // q_win -> st->Q_syn @@ -1278,7 +1316,7 @@ void ivas_mdct_core_reconstruct_fx( #endif #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD Scale_sig( st->mem_syn2_fx, M, sub( -2, q_win ) ); - // Scale_sig( st->mem_syn2_fx, M, sub( st->Q_syn, q_win ) ); // q_win -> Q_syn + //Scale_sig( st->mem_syn2_fx, M, sub( st->Q_syn, q_win ) ); // q_win -> Q_syn #endif } ELSE /*ACELP core for ACELP-PLC */ diff --git a/lib_dec/ivas_post_proc_fx.c b/lib_dec/ivas_post_proc_fx.c index 4232116fa..01182a493 100644 --- a/lib_dec/ivas_post_proc_fx.c +++ b/lib_dec/ivas_post_proc_fx.c @@ -112,6 +112,7 @@ void ivas_post_proc_fx( { Word16 numZeros = (Word16) ( NS2SA_FX2( output_Fs, N_ZERO_MDCT_NS ) ); /*Q0*/ move16(); + assert( sts[n]->hHQ_core->Q_old_out_fx32 == Q11 ); Copy32( sts[n]->hHQ_core->old_out_fx32 + numZeros, sts[n]->hTcxDec->FBTCXdelayBuf_32, delay_comp ); /*Q11*/ } diff --git a/lib_dec/ivas_stereo_mdct_core_dec_fx.c b/lib_dec/ivas_stereo_mdct_core_dec_fx.c index fd9398769..e70b1c137 100644 --- a/lib_dec/ivas_stereo_mdct_core_dec_fx.c +++ b/lib_dec/ivas_stereo_mdct_core_dec_fx.c @@ -550,7 +550,7 @@ void stereo_mdct_core_dec_fx( } Copy_Scale_sig_16_32_no_sat( hCPE->hCoreCoder[0]->old_Aq_12_8_fx, hCPE->hCoreCoder[0]->old_Aq_12_8_fx_32, M + 1, sub( 28, sub( 15, norm_s( sub( hCPE->hCoreCoder[0]->old_Aq_12_8_fx[0], 1 ) ) ) ) ); /* Q28 */ Copy_Scale_sig_16_32_no_sat( hCPE->hCoreCoder[1]->old_Aq_12_8_fx, hCPE->hCoreCoder[1]->old_Aq_12_8_fx_32, M + 1, sub( 28, sub( 15, norm_s( sub( hCPE->hCoreCoder[1]->old_Aq_12_8_fx[0], 1 ) ) ) ) ); /* Q28 */ -#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT +#if defined( FIX_1348_BIT_PRECISION_IMPROVEMENT ) && !defined( FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN ) ivas_mdct_core_reconstruct_fx( hCPE, x_fx, signal_outFB_tmp_fx, fUseTns, 0, st_ivas->mc_mode == MC_MODE_PARAMMC, Q11, e_sigFB ); #else ivas_mdct_core_reconstruct_fx( hCPE, x_fx, signal_outFB_tmp_fx, fUseTns, 0, Q11, e_sigFB ); -- GitLab From 6d0bec24880a27f4ee832068dc59b1df82d6c40c Mon Sep 17 00:00:00 2001 From: Manuel Jander Date: Thu, 8 May 2025 10:59:36 +0200 Subject: [PATCH 030/113] clang format --- lib_com/prot_fx.h | 2 +- lib_dec/dec_tcx_fx.c | 114 ++++++++++++++++---------------- lib_dec/ivas_mdct_core_dec_fx.c | 8 +-- 3 files changed, 62 insertions(+), 62 deletions(-) diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 5d15327a1..a84d0d8dc 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -9840,7 +9840,7 @@ void IMDCT_ivas_fx( const Word16 fullbandScale, Word16 *acelp_zir_fx, #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN - Word16 *q_win); + Word16 *q_win ); #else Word16 q_win ); #endif diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index 63820a2a9..9ea271b39 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -2573,24 +2573,22 @@ void IMDCT_fx( Word32 *x, Word16 x_e, Word16 *old_syn_overl, Word16 *syn_Overl_T } #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN -static -Word16 IMDCT_ivas_fx_adjust_qwin( +static Word16 IMDCT_ivas_fx_adjust_qwin( Word16 Q_syn_Overl_TDAC, Word16 Q_syn_Overl, Word16 Q_old_syn_Overl, Word16 Q_old_wtda, - Word16 q_win) + Word16 q_win ) { - //q_win = s_min( s_min( s_min( s_min( Q_syn_Overl_TDAC , Q_syn_Overl ), Q_old_syn_Overl ), Q_old_wtda ), q_win ); - q_win = s_min( s_min( s_min( Q_syn_Overl_TDAC , Q_syn_Overl ), Q_old_syn_Overl ), Q_old_wtda ); - q_win = s_min ( q_win, -1 ); - q_win = s_max ( q_win, -2 ); + // q_win = s_min( s_min( s_min( s_min( Q_syn_Overl_TDAC , Q_syn_Overl ), Q_old_syn_Overl ), Q_old_wtda ), q_win ); + q_win = s_min( s_min( s_min( Q_syn_Overl_TDAC, Q_syn_Overl ), Q_old_syn_Overl ), Q_old_wtda ); + q_win = s_min( q_win, -1 ); + q_win = s_max( q_win, -2 ); return q_win; } -static -void IMDCT_ivas_fx_rescale( +static void IMDCT_ivas_fx_rescale( Word16 *syn_Overl_TDAC, Word16 *Q_syn_Overl_TDAC, Word16 *syn_Overl, @@ -2605,33 +2603,34 @@ void IMDCT_ivas_fx_rescale( Word16 *synth_buf_fx, Word16 q_syn #endif - ) +) { Word16 oldLength; oldLength = L_FRAME32k; move16(); - if ( FB_flag ) { + if ( FB_flag ) + { oldLength = L_FRAME48k; move16(); } #if 1 - Scale_sig( syn_Overl, oldLength / 2, sub( q_win, *Q_syn_Overl ) ); // st->hTcxDec->Q_syn_Overl -> q_win + Scale_sig( syn_Overl, oldLength / 2, sub( q_win, *Q_syn_Overl ) ); // st->hTcxDec->Q_syn_Overl -> q_win *Q_syn_Overl = q_win; move16(); - Scale_sig( syn_Overl_TDAC, oldLength / 2, sub( q_win, *Q_syn_Overl_TDAC ) ); // st->hTcxDec->Q_syn_Overl_TDAC -> q_win + Scale_sig( syn_Overl_TDAC, oldLength / 2, sub( q_win, *Q_syn_Overl_TDAC ) ); // st->hTcxDec->Q_syn_Overl_TDAC -> q_win *Q_syn_Overl_TDAC = q_win; move16(); - Scale_sig( old_syn_Overl, oldLength / 2, sub( q_win, *Q_old_syn_Overl ) ); // Q(-1 - st->Q_syn) -> q_win + Scale_sig( old_syn_Overl, oldLength / 2, sub( q_win, *Q_old_syn_Overl ) ); // Q(-1 - st->Q_syn) -> q_win *Q_old_syn_Overl = q_win; move16(); - Scale_sig( old_out_fx, oldLength, sub( q_win, *Q_old_wtda ) ); // Q(st->hHQ_core->Q_old_wtda) -> q_win + Scale_sig( old_out_fx, oldLength, sub( q_win, *Q_old_wtda ) ); // Q(st->hHQ_core->Q_old_wtda) -> q_win *Q_old_wtda = q_win; move16(); #endif - //Scale_sig( synth_buf_fx, add( add( old_synth_len, L_FRAME_PLUS ), M ), sub( q_win, q_syn ) ); // q_syn -> q_win + // Scale_sig( synth_buf_fx, add( add( old_synth_len, L_FRAME_PLUS ), M ), sub( q_win, q_syn ) ); // q_syn -> q_win } static Word16 TCX_MDCT_Inverse_GetScaleFactor( @@ -2675,17 +2674,15 @@ static Word16 TCX_MDCT_Inverse_GetScaleFactor( return factor; } -static -void TCX_MDCT_Inverse_qwin_fx( +static void TCX_MDCT_Inverse_qwin_fx( Word32 *x, // Q( 31 - x_e ) Word16 x_e, - Word16 *y, /* Qy */ - const Word16 l, /* Q0 */ - const Word16 m, /* Q0 */ - const Word16 r, /* Q0 */ - const Word16 element_mode,/* Q0 */ - Word16 *q_win -) + Word16 *y, /* Qy */ + const Word16 l, /* Q0 */ + const Word16 m, /* Q0 */ + const Word16 r, /* Q0 */ + const Word16 element_mode, /* Q0 */ + Word16 *q_win ) { Word16 i, fac, negfac, s; @@ -2706,10 +2703,11 @@ void TCX_MDCT_Inverse_qwin_fx( negfac = negate( fac ); #if 1 - IF ( *q_win == -2 ) { + IF( *q_win == -2 ) + { // x_e + q_win == L_norm_arr(tmp_buf, , *q_win ); // q_win = L_norm_arr(tmp_buf, , *q_win ) - x_e; - s = L_norm_arr( tmp_buf + L2, m + R2 + L2); + s = L_norm_arr( tmp_buf + L2, m + R2 + L2 ); *q_win = s_min( sub( s, x_e ), *q_win ); } #else @@ -2743,16 +2741,14 @@ void TCX_MDCT_Inverse_qwin_fx( } } -static -void TCX_MDST_Inverse_qwin_fx( +static void TCX_MDST_Inverse_qwin_fx( Word32 *x, /* exp(x_e) */ Word16 x_e, Word16 *y, /* Qx */ const Word16 l, /* Q0 */ const Word16 m, /* Q0 */ const Word16 r, /* Q0 */ - Word16 *q_win -) + Word16 *q_win ) { Word16 i, fac, negfac, s; @@ -2775,10 +2771,11 @@ void TCX_MDST_Inverse_qwin_fx( negfac = negate( fac ); #if 1 - IF ( *q_win == -2 ) { + IF( *q_win == -2 ) + { // x_e + q_win == L_norm_arr(tmp_buf, , *q_win ); // q_win = L_norm_arr(tmp_buf, , *q_win ) - x_e; - s = L_norm_arr( tmp_buf + L2, m + R2 + L2); + s = L_norm_arr( tmp_buf + L2, m + R2 + L2 ); *q_win = s_min( sub( s, x_e ), *q_win ); } #else @@ -2817,17 +2814,15 @@ void TCX_MDST_Inverse_qwin_fx( * * *-------------------------------------------------------------------*/ -static -void TCX_MDXT_Inverse_qwin_fx( +static void TCX_MDXT_Inverse_qwin_fx( const Word32 *x, /* exp(x_e) */ Word16 x_e, - Word16 *y, /* Qx */ - const Word16 l, /* Q0 */ - const Word16 m, /* Q0 */ - const Word16 r, /* Q0 */ - const UWord16 kernel_type,/* Q0 */ - Word16 *q_win -) + Word16 *y, /* Qx */ + const Word16 l, /* Q0 */ + const Word16 m, /* Q0 */ + const Word16 r, /* Q0 */ + const UWord16 kernel_type, /* Q0 */ + Word16 *q_win ) { Word16 signLeft; Word16 signRight; @@ -2863,10 +2858,11 @@ void TCX_MDXT_Inverse_qwin_fx( } #if 1 - IF ( *q_win == -2 ) { + IF( *q_win == -2 ) + { // x_e + q_win == L_norm_arr(tmp_buf, , *q_win ); // q_win = L_norm_arr(tmp_buf, , *q_win ) - x_e; - s = L_norm_arr( tmp_buf + L2, m + R2 + L2); + s = L_norm_arr( tmp_buf + L2, m + R2 + L2 ); *q_win = s_min( sub( s, x_e ), *q_win ); } #else @@ -2907,13 +2903,13 @@ void IMDCT_ivas_fx( Word32 *x_fx, // Q(q_x) Word16 q_x, #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN - Word16 *old_syn_overl_fx, // *Q_old_syn_overl_fx + Word16 *old_syn_overl_fx, // *Q_old_syn_overl_fx Word16 *Q_old_syn_overl_fx, - Word16 *syn_Overl_TDAC_fx, // *Q_syn_Overl_TDAC_fx + Word16 *syn_Overl_TDAC_fx, // *Q_syn_Overl_TDAC_fx Word16 *Q_syn_Overl_TDAC_fx, #else - Word16 *old_syn_overl_fx, // Q(-2) - Word16 *syn_Overl_TDAC_fx, // Q(-2) + Word16 *old_syn_overl_fx, // Q(-2) + Word16 *syn_Overl_TDAC_fx, // Q(-2) #endif Word16 *xn_buf_fx, // Q(-2) const Word16 *tcx_aldo_window_1_fx, // Q(15) @@ -2944,9 +2940,9 @@ void IMDCT_ivas_fx( const Word16 fullbandScale, Word16 *acelp_zir_fx, #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN - Word16 *pq_win) + Word16 *pq_win ) #else - Word16 q_win ) // Q(-2) + Word16 q_win ) // Q(-2) #endif { Word16 i, nz, aldo, w, L_win, L_ola; @@ -2960,7 +2956,8 @@ void IMDCT_ivas_fx( Word16 q_win = *pq_win; move16(); x_e_hdrm = sub( Q16, q_x ); - IF ( q_win == -2 ) { + IF( q_win == -2 ) + { q_win = IMDCT_ivas_fx_adjust_qwin( *Q_syn_Overl_TDAC_fx, *Q_old_syn_overl_fx, hTcxDec->Q_old_syn_Overl, *q_old_out_fx, q_win ); } #else @@ -3062,9 +3059,12 @@ void IMDCT_ivas_fx( TCX_MDCT_Inverse_qwin_fx( x_fx + L_spec_TCX5_tmp, x_e_hdrm, win_fx, L_ola, sub( L_win, L_ola ), L_ola, st->element_mode, &q_win ); } - if ( w > 0 ) { + if ( w > 0 ) + { assert( q_win_prev == q_win ); - } else { + } + else + { q_win_prev = q_win; } @@ -3300,7 +3300,7 @@ void IMDCT_ivas_fx( FOR( Word16 ind = 0; ind < L_frame; ind++ ) { #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD - assert( L_shr(L_shl( old_out_fx[ind], q_old_out_diff ), q_old_out_diff ) == old_out_fx[ind] ); + assert( L_shr( L_shl( old_out_fx[ind], q_old_out_diff ), q_old_out_diff ) == old_out_fx[ind] ); old_out_fx_32[ind] = L_shl( old_out_fx[ind], q_old_out_diff ); #else old_out_fx_32[ind] = L_shl( old_out_fx[ind], diff ); @@ -3413,7 +3413,7 @@ void IMDCT_ivas_fx( TCX_MDCT_Inverse_qwin_fx( x_fx, x_e_hdrm, xn_buf_fx, overlap, L_frame - overlap, overlap, st->element_mode, &q_win ); } - // xn_buf_fx, NULL, L_frame, + // xn_buf_fx, NULL, L_frame, IMDCT_ivas_fx_rescale( syn_Overl_TDAC_fx, Q_syn_Overl_TDAC_fx, old_syn_overl_fx, Q_old_syn_overl_fx, hTcxDec->old_syn_Overl, &hTcxDec->Q_old_syn_Overl, old_out_fx, q_old_out_fx, q_win, FB_flag ); #else IF( EQ_16( kernel_type, MDST_IV ) ) @@ -4151,8 +4151,8 @@ void decoder_tcx_ivas_fx( st->hTcxDec->Q_old_syn_Overl = -2; #else - Scale_sig32( x_fx, N_MAX, sub( x_e, 20 ) ); // Scaling x_fx to Q11 - Scale_sig( xn_buf_fx, L_MDCT_OVLP_MAX + L_FRAME_PLUS + L_MDCT_OVLP_MAX, sub( st->Q_syn, 14 ) ); // Scaling xn_buf_fx to Q_syn + Scale_sig32( x_fx, N_MAX, sub( x_e, 20 ) ); // Scaling x_fx to Q11 + Scale_sig( xn_buf_fx, L_MDCT_OVLP_MAX + L_FRAME_PLUS + L_MDCT_OVLP_MAX, sub( st->Q_syn, 14 ) ); // Scaling xn_buf_fx to Q_syn x_e = sub( 31, 11 ); IF( st->igf != 0 ) diff --git a/lib_dec/ivas_mdct_core_dec_fx.c b/lib_dec/ivas_mdct_core_dec_fx.c index e3ece34ed..b1a78b1a8 100644 --- a/lib_dec/ivas_mdct_core_dec_fx.c +++ b/lib_dec/ivas_mdct_core_dec_fx.c @@ -1190,10 +1190,10 @@ void ivas_mdct_core_reconstruct_fx( Scale_sig( st->hTcxDec->syn_Overl_TDACFB, L_FRAME_MAX / 2, sub( q_win, st->hTcxDec->Q_syn_Overl_TDACFB ) ); // st->hTcxDec->Q_syn_Overl_TDACFB -> q_win st->hTcxDec->Q_syn_Overl_TDACFB = q_win; move16(); - Scale_sig( st->hTcxDec->syn_Overl_TDAC, L_FRAME32k / 2, sub( q_win, st->hTcxDec->Q_syn_Overl_TDAC ) ); // st->hTcxDec->Q_syn_Overl_TDAC -> q_win + Scale_sig( st->hTcxDec->syn_Overl_TDAC, L_FRAME32k / 2, sub( q_win, st->hTcxDec->Q_syn_Overl_TDAC ) ); // st->hTcxDec->Q_syn_Overl_TDAC -> q_win st->hTcxDec->Q_syn_Overl_TDAC = q_win; move16(); - Scale_sig( st->hTcxDec->old_syn_Overl, L_FRAME32k / 2, sub( q_win, st->hTcxDec->Q_old_syn_Overl ) ); // Q(-1 - st->Q_syn) -> q_win + Scale_sig( st->hTcxDec->old_syn_Overl, L_FRAME32k / 2, sub( q_win, st->hTcxDec->Q_old_syn_Overl ) ); // Q(-1 - st->Q_syn) -> q_win st->hTcxDec->Q_old_syn_Overl = q_win; move16(); Scale_sig( st->hTcxDec->syn_Overl, L_FRAME32k / 2, sub( q_win, st->Q_syn ) ); // Q(st->Q_syn) -> q_win @@ -1304,7 +1304,7 @@ void ivas_mdct_core_reconstruct_fx( Scale_sig( st->syn, M + 1, add( st->Q_syn, 2 ) ); Scale_sig( st->hTcxDec->syn_OverlFB, L_FRAME_MAX / 2, sub( st->Q_syn, q_win ) ); // q_win -> st->Q_syn st->hTcxDec->Q_syn_OverlFB = st->Q_syn; - Scale_sig( st->hTcxDec->syn_Overl, L_FRAME32k / 2, sub( st->Q_syn, q_win ) ); // q_win -> st->Q_syn + Scale_sig( st->hTcxDec->syn_Overl, L_FRAME32k / 2, sub( st->Q_syn, q_win ) ); // q_win -> st->Q_syn st->hTcxDec->Q_syn_Overl = st->Q_syn; #ifndef FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD Scale_sig( st->hHQ_core->old_out_LB_fx, L_FRAME32k, sub( st->Q_syn, q_win ) ); // q_win -> st->Q_syn @@ -1316,7 +1316,7 @@ void ivas_mdct_core_reconstruct_fx( #endif #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD Scale_sig( st->mem_syn2_fx, M, sub( -2, q_win ) ); - //Scale_sig( st->mem_syn2_fx, M, sub( st->Q_syn, q_win ) ); // q_win -> Q_syn + // Scale_sig( st->mem_syn2_fx, M, sub( st->Q_syn, q_win ) ); // q_win -> Q_syn #endif } ELSE /*ACELP core for ACELP-PLC */ -- GitLab From d674b7d856e3957e822e76cb06cc1bca57369820 Mon Sep 17 00:00:00 2001 From: Manuel Jander Date: Thu, 8 May 2025 11:34:54 +0200 Subject: [PATCH 031/113] Correct assert checking for overflow for negative values. --- lib_dec/dec_tcx_fx.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index 9ea271b39..cbc5579b6 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -3314,12 +3314,12 @@ void IMDCT_ivas_fx( { #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD old_out_fx[ind] = extract_l( L_shr( old_out_fx_32[ind], q_old_out_diff ) ); - assert( extract_h( L_shr( old_out_fx_32[ind], q_old_out_diff ) ) == 0 ); + assert( extract_h( L_shr( old_out_fx_32[ind], q_old_out_diff ) ) == 0 || extract_h( L_shr( old_out_fx_32[ind], q_old_out_diff ) ) == -1 ); #else old_out_fx[ind] = extract_l( L_shr( old_out_fx_32[ind], diff ) ); #endif xn_buf_fx[ind] = extract_l( L_shr( xn_buf_fx_32[ind], diff ) ); - assert( extract_h( L_shr( xn_buf_fx_32[ind], diff ) ) == 0 ); + assert( extract_h( L_shr( xn_buf_fx_32[ind], diff ) ) == 0 || extract_h( L_shr( xn_buf_fx_32[ind], diff ) ) == -1 ); move16(); move16(); } -- GitLab From 4b492033ebd8e2f8991d4c4275a86de83889ad41 Mon Sep 17 00:00:00 2001 From: Manuel Jander Date: Thu, 8 May 2025 15:15:42 +0200 Subject: [PATCH 032/113] Avoid throwing assert, the actual problems will be fixed in a next change. --- lib_dec/dec_tcx_fx.c | 130 ++++++++++++++++++++++++++++++++----------- 1 file changed, 98 insertions(+), 32 deletions(-) diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index cbc5579b6..807e39202 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -2588,6 +2588,41 @@ static Word16 IMDCT_ivas_fx_adjust_qwin( return q_win; } +static Word16 IMDCT_ivas_fx_calc_qwin( + Word16 *syn_Overl_TDAC, + Word16 Q_syn_Overl_TDAC, + Word16 *syn_Overl, + Word16 Q_syn_Overl, + Word16 *old_syn_Overl, + Word16 Q_old_syn_Overl, + Word16 *old_out_fx, + Word16 Q_old_out_fx, + const Word16 FB_flag, + Word16 q_win ) +{ + Word16 oldLength; + + oldLength = L_FRAME32k; + move16(); + if ( FB_flag ) + { + oldLength = L_FRAME48k; + move16(); + } + q_win = 2; + move16(); + + // q_win == norm + Q_syn_Overl_TDAC + q_win = s_min( q_win, norm_arr( syn_Overl_TDAC, oldLength / 2 ) + Q_syn_Overl_TDAC); + q_win = s_min( q_win, norm_arr( syn_Overl, oldLength / 2 ) + Q_syn_Overl ); + q_win = s_min( q_win, norm_arr( old_syn_Overl, oldLength / 2 ) + Q_old_syn_Overl ); + q_win = s_min( q_win, norm_arr( old_out_fx, oldLength ) + Q_old_out_fx ); + + //q_win = sub( q_win, 1 ); + + return q_win; +} + static void IMDCT_ivas_fx_rescale( Word16 *syn_Overl_TDAC, Word16 *Q_syn_Overl_TDAC, @@ -2596,7 +2631,7 @@ static void IMDCT_ivas_fx_rescale( Word16 *old_syn_Overl, Word16 *Q_old_syn_Overl, Word16 *old_out_fx, - Word16 *Q_old_wtda, + Word16 *Q_old_out_fx, Word16 q_win, const Word16 FB_flag #if 0 @@ -2616,18 +2651,17 @@ static void IMDCT_ivas_fx_rescale( } #if 1 - Scale_sig( syn_Overl, oldLength / 2, sub( q_win, *Q_syn_Overl ) ); // st->hTcxDec->Q_syn_Overl -> q_win - *Q_syn_Overl = q_win; - move16(); Scale_sig( syn_Overl_TDAC, oldLength / 2, sub( q_win, *Q_syn_Overl_TDAC ) ); // st->hTcxDec->Q_syn_Overl_TDAC -> q_win *Q_syn_Overl_TDAC = q_win; move16(); + Scale_sig( syn_Overl, oldLength / 2, sub( q_win, *Q_syn_Overl ) ); // st->hTcxDec->Q_syn_Overl -> q_win + *Q_syn_Overl = q_win; + move16(); Scale_sig( old_syn_Overl, oldLength / 2, sub( q_win, *Q_old_syn_Overl ) ); // Q(-1 - st->Q_syn) -> q_win *Q_old_syn_Overl = q_win; move16(); - - Scale_sig( old_out_fx, oldLength, sub( q_win, *Q_old_wtda ) ); // Q(st->hHQ_core->Q_old_wtda) -> q_win - *Q_old_wtda = q_win; + Scale_sig( old_out_fx, oldLength, sub( q_win, *Q_old_out_fx ) ); // Q(st->hHQ_core->Q_old_wtda) -> q_win + *Q_old_out_fx = q_win; move16(); #endif // Scale_sig( synth_buf_fx, add( add( old_synth_len, L_FRAME_PLUS ), M ), sub( q_win, q_syn ) ); // q_syn -> q_win @@ -2682,7 +2716,8 @@ static void TCX_MDCT_Inverse_qwin_fx( const Word16 m, /* Q0 */ const Word16 r, /* Q0 */ const Word16 element_mode, /* Q0 */ - Word16 *q_win ) + Word16 *q_win, + Word16 allow_qwin_change ) { Word16 i, fac, negfac, s; @@ -2703,7 +2738,7 @@ static void TCX_MDCT_Inverse_qwin_fx( negfac = negate( fac ); #if 1 - IF( *q_win == -2 ) + IF( allow_qwin_change ) { // x_e + q_win == L_norm_arr(tmp_buf, , *q_win ); // q_win = L_norm_arr(tmp_buf, , *q_win ) - x_e; @@ -2748,7 +2783,8 @@ static void TCX_MDST_Inverse_qwin_fx( const Word16 l, /* Q0 */ const Word16 m, /* Q0 */ const Word16 r, /* Q0 */ - Word16 *q_win ) + Word16 *q_win, + Word16 allow_qwin_change ) { Word16 i, fac, negfac, s; @@ -2771,7 +2807,7 @@ static void TCX_MDST_Inverse_qwin_fx( negfac = negate( fac ); #if 1 - IF( *q_win == -2 ) + IF( allow_qwin_change ) { // x_e + q_win == L_norm_arr(tmp_buf, , *q_win ); // q_win = L_norm_arr(tmp_buf, , *q_win ) - x_e; @@ -2822,7 +2858,8 @@ static void TCX_MDXT_Inverse_qwin_fx( const Word16 m, /* Q0 */ const Word16 r, /* Q0 */ const UWord16 kernel_type, /* Q0 */ - Word16 *q_win ) + Word16 *q_win, + Word16 allow_qwin_change ) { Word16 signLeft; Word16 signRight; @@ -2858,7 +2895,7 @@ static void TCX_MDXT_Inverse_qwin_fx( } #if 1 - IF( *q_win == -2 ) + IF( allow_qwin_change ) { // x_e + q_win == L_norm_arr(tmp_buf, , *q_win ); // q_win = L_norm_arr(tmp_buf, , *q_win ) - x_e; @@ -2954,11 +2991,19 @@ void IMDCT_ivas_fx( Word16 exp; #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN Word16 q_win = *pq_win; + Word16 allow_qwin_change = 1; + move16(); move16(); x_e_hdrm = sub( Q16, q_x ); - IF( q_win == -2 ) + IF( *pq_win == 0 ) { - q_win = IMDCT_ivas_fx_adjust_qwin( *Q_syn_Overl_TDAC_fx, *Q_old_syn_overl_fx, hTcxDec->Q_old_syn_Overl, *q_old_out_fx, q_win ); + allow_qwin_change = 0; + } + IF ( allow_qwin_change ) + { + //q_win = IMDCT_ivas_fx_adjust_qwin( *Q_syn_Overl_TDAC_fx, *Q_old_syn_overl_fx, hTcxDec->Q_old_syn_Overl, *q_old_out_fx, q_win ); + q_win = IMDCT_ivas_fx_calc_qwin( syn_Overl_TDAC_fx, *Q_syn_Overl_TDAC_fx, old_syn_overl_fx, *Q_old_syn_overl_fx, + hTcxDec->old_syn_Overl, hTcxDec->Q_old_syn_Overl, old_out_fx, *q_old_out_fx, FB_flag, q_win ); } #else x_e_hdrm = add( q_win, sub( Q16, q_x ) ); @@ -3038,6 +3083,14 @@ void IMDCT_ivas_fx( move16(); #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN Word16 q_win_prev; +#if 0 + IF ( allow_qwin_change ) { + q_win = -2; + move16(); + allow_qwin_change = 0; + move16(); + } +#endif #endif FOR( w = 0; w < 2; w++ ) @@ -3048,20 +3101,24 @@ void IMDCT_ivas_fx( #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN IF( EQ_16( kernel_type, MDST_IV ) || s_and( kernel_type, w ) ) { - TCX_MDST_Inverse_qwin_fx( x_fx + L_spec_TCX5_tmp, x_e_hdrm, win_fx, L_ola, sub( L_win, L_ola ), L_ola, &q_win ); + TCX_MDST_Inverse_qwin_fx( x_fx + L_spec_TCX5_tmp, x_e_hdrm, win_fx, L_ola, sub( L_win, L_ola ), L_ola, &q_win, allow_qwin_change ); } ELSE IF( ( kernel_type != 0 ) && ( w == 0 ) ) /* type 1 or 2 */ { - TCX_MDXT_Inverse_qwin_fx( x_fx + L_spec_TCX5_tmp, x_e_hdrm, win_fx, L_ola, sub( L_win, L_ola ), L_ola, kernel_type, &q_win ); + TCX_MDXT_Inverse_qwin_fx( x_fx + L_spec_TCX5_tmp, x_e_hdrm, win_fx, L_ola, sub( L_win, L_ola ), L_ola, kernel_type, &q_win, allow_qwin_change ); } ELSE { - TCX_MDCT_Inverse_qwin_fx( x_fx + L_spec_TCX5_tmp, x_e_hdrm, win_fx, L_ola, sub( L_win, L_ola ), L_ola, st->element_mode, &q_win ); + TCX_MDCT_Inverse_qwin_fx( x_fx + L_spec_TCX5_tmp, x_e_hdrm, win_fx, L_ola, sub( L_win, L_ola ), L_ola, st->element_mode, &q_win, allow_qwin_change ); } if ( w > 0 ) { - assert( q_win_prev == q_win ); + //assert( q_win_prev == q_win ); + if ( q_win_prev != q_win ) { + extern int frame; + printf("\nWarning: q_win changed in TCX5. Frame %d, q_win %d %d\n", frame, q_win_prev, q_win ); + } } else { @@ -3126,15 +3183,15 @@ void IMDCT_ivas_fx( IF( EQ_16( kernel_type, MDST_IV ) ) { - TCX_MDST_Inverse_qwin_fx( x_fx, x_e_hdrm, win_fx + L_win, 0, sub( L_win, shr( L_ola, 1 ) ), L_ola, &q_win ); + TCX_MDST_Inverse_qwin_fx( x_fx, x_e_hdrm, win_fx + L_win, 0, sub( L_win, shr( L_ola, 1 ) ), L_ola, &q_win, allow_qwin_change ); } ELSE IF( NE_16( kernel_type, MDCT_IV ) ) /* type 1 or 2 */ { - TCX_MDXT_Inverse_qwin_fx( x_fx, x_e_hdrm, win_fx + L_win, 0, sub( L_win, shr( L_ola, 1 ) ), L_ola, kernel_type, &q_win ); + TCX_MDXT_Inverse_qwin_fx( x_fx, x_e_hdrm, win_fx + L_win, 0, sub( L_win, shr( L_ola, 1 ) ), L_ola, kernel_type, &q_win, allow_qwin_change ); } ELSE { - TCX_MDCT_Inverse_qwin_fx( x_fx, x_e_hdrm, win_fx + L_win, 0, sub( L_win, shr( L_ola, 1 ) ), L_ola, st->element_mode, &q_win ); + TCX_MDCT_Inverse_qwin_fx( x_fx, x_e_hdrm, win_fx + L_win, 0, sub( L_win, shr( L_ola, 1 ) ), L_ola, st->element_mode, &q_win, allow_qwin_change ); } q_win_prev = q_win; #else @@ -3161,11 +3218,11 @@ void IMDCT_ivas_fx( #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN IF( s_and( kernel_type, 1 ) ) { - TCX_MDST_Inverse_qwin_fx( x_fx + L_spec_TCX5, x_e_hdrm, win_fx, L_ola, sub( L_win, L_ola ), L_ola, &q_win ); + TCX_MDST_Inverse_qwin_fx( x_fx + L_spec_TCX5, x_e_hdrm, win_fx, L_ola, sub( L_win, L_ola ), L_ola, &q_win, 0 ); } ELSE { - TCX_MDCT_Inverse_qwin_fx( x_fx + L_spec_TCX5, x_e_hdrm, win_fx, L_ola, sub( L_win, L_ola ), L_ola, st->element_mode, &q_win ); + TCX_MDCT_Inverse_qwin_fx( x_fx + L_spec_TCX5, x_e_hdrm, win_fx, L_ola, sub( L_win, L_ola ), L_ola, st->element_mode, &q_win, 0 ); } assert( q_win_prev == q_win ); @@ -3218,15 +3275,15 @@ void IMDCT_ivas_fx( #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN IF( EQ_16( kernel_type, MDST_IV ) ) { - TCX_MDST_Inverse_qwin_fx( x_fx, x_e_hdrm, xn_buf_fx, overlap, sub( L_frame, overlap ), overlap, &q_win ); + TCX_MDST_Inverse_qwin_fx( x_fx, x_e_hdrm, xn_buf_fx, overlap, sub( L_frame, overlap ), overlap, &q_win, allow_qwin_change ); } ELSE IF( NE_16( kernel_type, MDCT_IV ) ) /* type 1 or 2 */ { - TCX_MDXT_Inverse_qwin_fx( x_fx, x_e_hdrm, xn_buf_fx, overlap, sub( L_frame, overlap ), overlap, kernel_type, &q_win ); + TCX_MDXT_Inverse_qwin_fx( x_fx, x_e_hdrm, xn_buf_fx, overlap, sub( L_frame, overlap ), overlap, kernel_type, &q_win, allow_qwin_change ); } ELSE { - TCX_MDCT_Inverse_qwin_fx( x_fx, x_e_hdrm, xn_buf_fx, overlap, sub( L_frame, overlap ), overlap, st->element_mode, &q_win ); + TCX_MDCT_Inverse_qwin_fx( x_fx, x_e_hdrm, xn_buf_fx, overlap, sub( L_frame, overlap ), overlap, st->element_mode, &q_win, allow_qwin_change ); } IMDCT_ivas_fx_rescale( syn_Overl_TDAC_fx, Q_syn_Overl_TDAC_fx, old_syn_overl_fx, Q_old_syn_overl_fx, hTcxDec->old_syn_Overl, &hTcxDec->Q_old_syn_Overl, old_out_fx, q_old_out_fx, q_win, FB_flag ); @@ -3290,6 +3347,7 @@ void IMDCT_ivas_fx( move16(); #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN + // L_norm_arr(xn_buf_fx_32, ) IMDCT_ivas_fx_rescale( syn_Overl_TDAC_fx, Q_syn_Overl_TDAC_fx, old_syn_overl_fx, Q_old_syn_overl_fx, hTcxDec->old_syn_Overl, &hTcxDec->Q_old_syn_Overl, old_out_fx, q_old_out_fx, q_win, FB_flag ); #endif @@ -3346,7 +3404,16 @@ void IMDCT_ivas_fx( // v_multc_fixed( xn_buf_fx_32 + overlap / 2 + nz, (float) sqrt( (float) L_frame / NORM_MDCT_FACTOR ), tmp_fx_32, L_frame ); #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN - // L_norm_arr( xn_buf_fx, L_frame ) + if ( allow_qwin_change) { +#if 1 + // sub( q_xn_buf_fx_32, q_win ) == 16 - L_norm_arr( xn_buf_fx_32, L_frame ) + // q_xn_buf_fx_32 - q_win == 16 - L_norm_arr( xn_buf_fx_32, L_frame ) + // q_win == - 16 + L_norm_arr( xn_buf_fx_32, L_frame ) + q_xn_buf_fx_32 + q_win = s_min( q_win, add( sub( q_xn_buf_fx_32, 16 ), L_norm_arr( xn_buf_fx_32, L_frame ) ) - 1 ); +#else + q_win = -2; +#endif + } IMDCT_ivas_fx_rescale( syn_Overl_TDAC_fx, Q_syn_Overl_TDAC_fx, old_syn_overl_fx, Q_old_syn_overl_fx, hTcxDec->old_syn_Overl, &hTcxDec->Q_old_syn_Overl, old_out_fx, q_old_out_fx, q_win, FB_flag ); #endif @@ -3402,18 +3469,17 @@ void IMDCT_ivas_fx( #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN IF( EQ_16( kernel_type, MDST_IV ) ) { - TCX_MDST_Inverse_qwin_fx( x_fx, x_e_hdrm, xn_buf_fx, overlap, L_frame - overlap, overlap, &q_win ); + TCX_MDST_Inverse_qwin_fx( x_fx, x_e_hdrm, xn_buf_fx, overlap, L_frame - overlap, overlap, &q_win, allow_qwin_change ); } ELSE IF( NE_16( kernel_type, MDCT_IV ) ) /* type 1 or 2 */ { - TCX_MDXT_Inverse_qwin_fx( x_fx, x_e_hdrm, xn_buf_fx, overlap, L_frame - overlap, overlap, kernel_type, &q_win ); + TCX_MDXT_Inverse_qwin_fx( x_fx, x_e_hdrm, xn_buf_fx, overlap, L_frame - overlap, overlap, kernel_type, &q_win, allow_qwin_change ); } ELSE { - TCX_MDCT_Inverse_qwin_fx( x_fx, x_e_hdrm, xn_buf_fx, overlap, L_frame - overlap, overlap, st->element_mode, &q_win ); + TCX_MDCT_Inverse_qwin_fx( x_fx, x_e_hdrm, xn_buf_fx, overlap, L_frame - overlap, overlap, st->element_mode, &q_win, allow_qwin_change ); } - // xn_buf_fx, NULL, L_frame, IMDCT_ivas_fx_rescale( syn_Overl_TDAC_fx, Q_syn_Overl_TDAC_fx, old_syn_overl_fx, Q_old_syn_overl_fx, hTcxDec->old_syn_Overl, &hTcxDec->Q_old_syn_Overl, old_out_fx, q_old_out_fx, q_win, FB_flag ); #else IF( EQ_16( kernel_type, MDST_IV ) ) -- GitLab From 5efbe4bdf5f5c6bad2f6fcafd3c7ed6e02fb236d Mon Sep 17 00:00:00 2001 From: Manuel Jander Date: Thu, 8 May 2025 15:27:02 +0200 Subject: [PATCH 033/113] clang format --- lib_dec/dec_tcx_fx.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index 807e39202..d506b508e 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -2613,12 +2613,12 @@ static Word16 IMDCT_ivas_fx_calc_qwin( move16(); // q_win == norm + Q_syn_Overl_TDAC - q_win = s_min( q_win, norm_arr( syn_Overl_TDAC, oldLength / 2 ) + Q_syn_Overl_TDAC); + q_win = s_min( q_win, norm_arr( syn_Overl_TDAC, oldLength / 2 ) + Q_syn_Overl_TDAC ); q_win = s_min( q_win, norm_arr( syn_Overl, oldLength / 2 ) + Q_syn_Overl ); q_win = s_min( q_win, norm_arr( old_syn_Overl, oldLength / 2 ) + Q_old_syn_Overl ); q_win = s_min( q_win, norm_arr( old_out_fx, oldLength ) + Q_old_out_fx ); - //q_win = sub( q_win, 1 ); + // q_win = sub( q_win, 1 ); return q_win; } @@ -2999,9 +2999,9 @@ void IMDCT_ivas_fx( { allow_qwin_change = 0; } - IF ( allow_qwin_change ) + IF( allow_qwin_change ) { - //q_win = IMDCT_ivas_fx_adjust_qwin( *Q_syn_Overl_TDAC_fx, *Q_old_syn_overl_fx, hTcxDec->Q_old_syn_Overl, *q_old_out_fx, q_win ); + // q_win = IMDCT_ivas_fx_adjust_qwin( *Q_syn_Overl_TDAC_fx, *Q_old_syn_overl_fx, hTcxDec->Q_old_syn_Overl, *q_old_out_fx, q_win ); q_win = IMDCT_ivas_fx_calc_qwin( syn_Overl_TDAC_fx, *Q_syn_Overl_TDAC_fx, old_syn_overl_fx, *Q_old_syn_overl_fx, hTcxDec->old_syn_Overl, hTcxDec->Q_old_syn_Overl, old_out_fx, *q_old_out_fx, FB_flag, q_win ); } @@ -3114,10 +3114,11 @@ void IMDCT_ivas_fx( if ( w > 0 ) { - //assert( q_win_prev == q_win ); - if ( q_win_prev != q_win ) { + // assert( q_win_prev == q_win ); + if ( q_win_prev != q_win ) + { extern int frame; - printf("\nWarning: q_win changed in TCX5. Frame %d, q_win %d %d\n", frame, q_win_prev, q_win ); + printf( "\nWarning: q_win changed in TCX5. Frame %d, q_win %d %d\n", frame, q_win_prev, q_win ); } } else @@ -3404,7 +3405,8 @@ void IMDCT_ivas_fx( // v_multc_fixed( xn_buf_fx_32 + overlap / 2 + nz, (float) sqrt( (float) L_frame / NORM_MDCT_FACTOR ), tmp_fx_32, L_frame ); #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN - if ( allow_qwin_change) { + if ( allow_qwin_change ) + { #if 1 // sub( q_xn_buf_fx_32, q_win ) == 16 - L_norm_arr( xn_buf_fx_32, L_frame ) // q_xn_buf_fx_32 - q_win == 16 - L_norm_arr( xn_buf_fx_32, L_frame ) -- GitLab From c5db649c54963696a26009fbb76b9997968f0fa0 Mon Sep 17 00:00:00 2001 From: Manuel Jander Date: Thu, 8 May 2025 16:32:39 +0200 Subject: [PATCH 034/113] Fix warning, causing error in pipeline. --- lib_dec/dec_tcx_fx.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index d506b508e..9b45460d5 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -2573,6 +2573,7 @@ void IMDCT_fx( Word32 *x, Word16 x_e, Word16 *old_syn_overl, Word16 *syn_Overl_T } #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN +#if 0 static Word16 IMDCT_ivas_fx_adjust_qwin( Word16 Q_syn_Overl_TDAC, Word16 Q_syn_Overl, @@ -2587,6 +2588,7 @@ static Word16 IMDCT_ivas_fx_adjust_qwin( return q_win; } +#endif static Word16 IMDCT_ivas_fx_calc_qwin( Word16 *syn_Overl_TDAC, -- GitLab From 93c1ca20e5f1379866686d2805462f6fb19d6b17 Mon Sep 17 00:00:00 2001 From: Manuel Jander Date: Thu, 8 May 2025 16:37:24 +0200 Subject: [PATCH 035/113] Fix error in debug printf that happens in pipeline but not locally. --- lib_dec/dec_tcx_fx.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index 9b45460d5..051d03828 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -3116,12 +3116,13 @@ void IMDCT_ivas_fx( if ( w > 0 ) { - // assert( q_win_prev == q_win ); +#if 0 if ( q_win_prev != q_win ) { extern int frame; printf( "\nWarning: q_win changed in TCX5. Frame %d, q_win %d %d\n", frame, q_win_prev, q_win ); } +#endif } else { -- GitLab From 317c692ac28e249f58792b12c4f706958bd711dc Mon Sep 17 00:00:00 2001 From: Manuel Jander Date: Thu, 8 May 2025 16:41:44 +0200 Subject: [PATCH 036/113] Fix warning, causing error in pipeline. --- lib_dec/dec_tcx_fx.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index 051d03828..1702a5fb5 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -3116,13 +3116,12 @@ void IMDCT_ivas_fx( if ( w > 0 ) { -#if 0 if ( q_win_prev != q_win ) { - extern int frame; - printf( "\nWarning: q_win changed in TCX5. Frame %d, q_win %d %d\n", frame, q_win_prev, q_win ); + // extern int frame; + // printf( "\nWarning: q_win changed in TCX5. Frame %d, q_win %d %d\n", frame, q_win_prev, q_win ); + printf( "\nWarning: q_win changed in TCX5. Frame X, q_win %d %d\n", q_win_prev, q_win ); } -#endif } else { -- GitLab From a4db18ff59700dd91b92e6cb01e6b71d396b36f2 Mon Sep 17 00:00:00 2001 From: Manuel Jander Date: Mon, 12 May 2025 10:51:16 +0200 Subject: [PATCH 037/113] Fix assert becaus of ininitialized hTcxDec->Q_syn_OverlFB --- lib_dec/core_dec_init_fx.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib_dec/core_dec_init_fx.c b/lib_dec/core_dec_init_fx.c index eb34e1bc1..3ddecdbd5 100644 --- a/lib_dec/core_dec_init_fx.c +++ b/lib_dec/core_dec_init_fx.c @@ -2090,6 +2090,11 @@ void reset_tcx_overl_buf_fx( set16_fx( hTcxDec->syn_Overl, 0, L_FRAME32k / 2 ); /*HQ-CORE(bfi)->TCX don't need it*/ hTcxDec->Q_syn_Overl = 0; move16(); +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT + set16_fx( hTcxDec->syn_OverlFB, 0, L_FRAME48k / 2 ); /*HQ-CORE(bfi)->TCX don't need it*/ + hTcxDec->Q_syn_OverlFB = 0; + move16(); +#endif set16_fx( hTcxDec->syn_Overl_TDACFB, 0, L_FRAME_MAX / 2 ); /*HQ-CORE(bfi)->TCX don't need it*/ hTcxDec->Q_syn_Overl_TDACFB = 0; move16(); -- GitLab From e6a26d0b423fa365fcea4cb29449b557a48a7176 Mon Sep 17 00:00:00 2001 From: Manuel Jander Date: Mon, 12 May 2025 17:56:28 +0200 Subject: [PATCH 038/113] Add 2 bits headroom to dynamic q_win calculation as the default static value of q_win did. --- lib_dec/dec_tcx_fx.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index 1702a5fb5..0f3688a58 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -2611,7 +2611,7 @@ static Word16 IMDCT_ivas_fx_calc_qwin( oldLength = L_FRAME48k; move16(); } - q_win = 2; + q_win = 4; move16(); // q_win == norm + Q_syn_Overl_TDAC @@ -2620,12 +2620,13 @@ static Word16 IMDCT_ivas_fx_calc_qwin( q_win = s_min( q_win, norm_arr( old_syn_Overl, oldLength / 2 ) + Q_old_syn_Overl ); q_win = s_min( q_win, norm_arr( old_out_fx, oldLength ) + Q_old_out_fx ); - // q_win = sub( q_win, 1 ); + q_win = s_max( -3, sub( q_win, 2 ) ); return q_win; } static void IMDCT_ivas_fx_rescale( + Decoder_State *st, Word16 *syn_Overl_TDAC, Word16 *Q_syn_Overl_TDAC, Word16 *syn_Overl, @@ -2666,6 +2667,8 @@ static void IMDCT_ivas_fx_rescale( *Q_old_out_fx = q_win; move16(); #endif + Scale_sig( st->syn, M + 1, sub( q_win, st->Q_syn ) ); // st->Q_syn -> q_win + // Scale_sig( synth_buf_fx, add( add( old_synth_len, L_FRAME_PLUS ), M ), sub( q_win, q_syn ) ); // q_syn -> q_win } @@ -3084,8 +3087,9 @@ void IMDCT_ivas_fx( Word16 L_spec_TCX5_tmp = 0; move16(); #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN - Word16 q_win_prev; #if 0 + Word16 q_win_prev; +#else IF ( allow_qwin_change ) { q_win = -2; move16(); @@ -3114,6 +3118,7 @@ void IMDCT_ivas_fx( TCX_MDCT_Inverse_qwin_fx( x_fx + L_spec_TCX5_tmp, x_e_hdrm, win_fx, L_ola, sub( L_win, L_ola ), L_ola, st->element_mode, &q_win, allow_qwin_change ); } +#if 0 if ( w > 0 ) { if ( q_win_prev != q_win ) @@ -3122,13 +3127,15 @@ void IMDCT_ivas_fx( // printf( "\nWarning: q_win changed in TCX5. Frame %d, q_win %d %d\n", frame, q_win_prev, q_win ); printf( "\nWarning: q_win changed in TCX5. Frame X, q_win %d %d\n", q_win_prev, q_win ); } + // Rescale both subframes some how ? } else { q_win_prev = q_win; } +#endif - IMDCT_ivas_fx_rescale( syn_Overl_TDAC_fx, Q_syn_Overl_TDAC_fx, old_syn_overl_fx, Q_old_syn_overl_fx, hTcxDec->old_syn_Overl, &hTcxDec->Q_old_syn_Overl, old_out_fx, q_old_out_fx, q_win, FB_flag ); + IMDCT_ivas_fx_rescale( st, syn_Overl_TDAC_fx, Q_syn_Overl_TDAC_fx, old_syn_overl_fx, Q_old_syn_overl_fx, hTcxDec->old_syn_Overl, &hTcxDec->Q_old_syn_Overl, old_out_fx, q_old_out_fx, q_win, FB_flag ); #else IF( EQ_16( kernel_type, MDST_IV ) || s_and( kernel_type, w ) ) { @@ -3230,7 +3237,7 @@ void IMDCT_ivas_fx( assert( q_win_prev == q_win ); - IMDCT_ivas_fx_rescale( syn_Overl_TDAC_fx, Q_syn_Overl_TDAC_fx, old_syn_overl_fx, Q_old_syn_overl_fx, hTcxDec->old_syn_Overl, &hTcxDec->Q_old_syn_Overl, old_out_fx, q_old_out_fx, q_win, FB_flag ); + IMDCT_ivas_fx_rescale( st, syn_Overl_TDAC_fx, Q_syn_Overl_TDAC_fx, old_syn_overl_fx, Q_old_syn_overl_fx, hTcxDec->old_syn_Overl, &hTcxDec->Q_old_syn_Overl, old_out_fx, q_old_out_fx, q_win, FB_flag ); #else IF( s_and( kernel_type, 1 ) ) { @@ -3289,7 +3296,7 @@ void IMDCT_ivas_fx( TCX_MDCT_Inverse_qwin_fx( x_fx, x_e_hdrm, xn_buf_fx, overlap, sub( L_frame, overlap ), overlap, st->element_mode, &q_win, allow_qwin_change ); } - IMDCT_ivas_fx_rescale( syn_Overl_TDAC_fx, Q_syn_Overl_TDAC_fx, old_syn_overl_fx, Q_old_syn_overl_fx, hTcxDec->old_syn_Overl, &hTcxDec->Q_old_syn_Overl, old_out_fx, q_old_out_fx, q_win, FB_flag ); + IMDCT_ivas_fx_rescale( st, syn_Overl_TDAC_fx, Q_syn_Overl_TDAC_fx, old_syn_overl_fx, Q_old_syn_overl_fx, hTcxDec->old_syn_Overl, &hTcxDec->Q_old_syn_Overl, old_out_fx, q_old_out_fx, q_win, FB_flag ); #else IF( EQ_16( kernel_type, MDST_IV ) ) { @@ -3351,7 +3358,7 @@ void IMDCT_ivas_fx( #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN // L_norm_arr(xn_buf_fx_32, ) - IMDCT_ivas_fx_rescale( syn_Overl_TDAC_fx, Q_syn_Overl_TDAC_fx, old_syn_overl_fx, Q_old_syn_overl_fx, hTcxDec->old_syn_Overl, &hTcxDec->Q_old_syn_Overl, old_out_fx, q_old_out_fx, q_win, FB_flag ); + IMDCT_ivas_fx_rescale( st, syn_Overl_TDAC_fx, Q_syn_Overl_TDAC_fx, old_syn_overl_fx, Q_old_syn_overl_fx, hTcxDec->old_syn_Overl, &hTcxDec->Q_old_syn_Overl, old_out_fx, q_old_out_fx, q_win, FB_flag ); #endif Word16 diff = sub( q_tmp_fx_32, q_win ); @@ -3418,7 +3425,7 @@ void IMDCT_ivas_fx( q_win = -2; #endif } - IMDCT_ivas_fx_rescale( syn_Overl_TDAC_fx, Q_syn_Overl_TDAC_fx, old_syn_overl_fx, Q_old_syn_overl_fx, hTcxDec->old_syn_Overl, &hTcxDec->Q_old_syn_Overl, old_out_fx, q_old_out_fx, q_win, FB_flag ); + IMDCT_ivas_fx_rescale( st, syn_Overl_TDAC_fx, Q_syn_Overl_TDAC_fx, old_syn_overl_fx, Q_old_syn_overl_fx, hTcxDec->old_syn_Overl, &hTcxDec->Q_old_syn_Overl, old_out_fx, q_old_out_fx, q_win, FB_flag ); #endif Word16 q_diff = sub( q_xn_buf_fx_32, q_win ); @@ -3484,7 +3491,7 @@ void IMDCT_ivas_fx( TCX_MDCT_Inverse_qwin_fx( x_fx, x_e_hdrm, xn_buf_fx, overlap, L_frame - overlap, overlap, st->element_mode, &q_win, allow_qwin_change ); } - IMDCT_ivas_fx_rescale( syn_Overl_TDAC_fx, Q_syn_Overl_TDAC_fx, old_syn_overl_fx, Q_old_syn_overl_fx, hTcxDec->old_syn_Overl, &hTcxDec->Q_old_syn_Overl, old_out_fx, q_old_out_fx, q_win, FB_flag ); + IMDCT_ivas_fx_rescale( st, syn_Overl_TDAC_fx, Q_syn_Overl_TDAC_fx, old_syn_overl_fx, Q_old_syn_overl_fx, hTcxDec->old_syn_Overl, &hTcxDec->Q_old_syn_Overl, old_out_fx, q_old_out_fx, q_win, FB_flag ); #else IF( EQ_16( kernel_type, MDST_IV ) ) { @@ -4187,7 +4194,7 @@ void decoder_tcx_ivas_fx( move16(); } -#if 1 +#if 0 /* Scaling down buffers for decoder_tcx_imdct_fx*/ Scale_sig( st->hTcxDec->syn_Overl_TDACFB, L_FRAME_MAX / 2, sub( st->Q_syn, st->hTcxDec->Q_syn_Overl_TDACFB ) ); // Scaling to Q_syn st->hTcxDec->Q_syn_Overl_TDACFB = st->Q_syn; @@ -4197,7 +4204,7 @@ void decoder_tcx_ivas_fx( st->hTcxDec->Q_old_syn_Overl = st->Q_syn; #endif -#if 1 +#if 0 Scale_sig( synth_fx, L_frame_glob, st->Q_syn ); // Scaling to Q_syn Scale_sig( synthFB_fx, L_frameTCX_glob, st->Q_syn ); // Scaling to Q_syn #endif -- GitLab From 0b43f51ad30f134bb73ae4218af27bdb0c6b2610 Mon Sep 17 00:00:00 2001 From: Manuel Jander Date: Mon, 12 May 2025 18:04:18 +0200 Subject: [PATCH 039/113] clang format --- lib_dec/dec_tcx_fx.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index 0f3688a58..fd9e0ff30 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -3090,7 +3090,8 @@ void IMDCT_ivas_fx( #if 0 Word16 q_win_prev; #else - IF ( allow_qwin_change ) { + IF( allow_qwin_change ) + { q_win = -2; move16(); allow_qwin_change = 0; -- GitLab From 36bbe074068be90ed62402797f52b1b0ec3b8574 Mon Sep 17 00:00:00 2001 From: Manuel Jander Date: Tue, 13 May 2025 19:36:04 +0200 Subject: [PATCH 040/113] Separate q_win into q_win and q_winFB for low band / high band, because these can be different. Correct q_win calculation for TCX20, which fixes assert fail. --- lib_com/ivas_prot_fx.h | 1 + lib_dec/dec_tcx_fx.c | 87 ++++++++++----------------------- lib_dec/ivas_mdct_core_dec_fx.c | 51 ++++++++++++++++--- 3 files changed, 72 insertions(+), 67 deletions(-) diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index 5a19dcc41..904aaf090 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -1584,6 +1584,7 @@ void decoder_tcx_imdct_fx( Word16 xn_buf_fx[], #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN Word16 *q_win, + Word16 *q_winFB, #else Word16 q_win, #endif diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index fd9e0ff30..037f2e3cb 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -2626,7 +2626,6 @@ static Word16 IMDCT_ivas_fx_calc_qwin( } static void IMDCT_ivas_fx_rescale( - Decoder_State *st, Word16 *syn_Overl_TDAC, Word16 *Q_syn_Overl_TDAC, Word16 *syn_Overl, @@ -2637,10 +2636,6 @@ static void IMDCT_ivas_fx_rescale( Word16 *Q_old_out_fx, Word16 q_win, const Word16 FB_flag -#if 0 - Word16 *synth_buf_fx, - Word16 q_syn -#endif ) { Word16 oldLength; @@ -2660,16 +2655,15 @@ static void IMDCT_ivas_fx_rescale( Scale_sig( syn_Overl, oldLength / 2, sub( q_win, *Q_syn_Overl ) ); // st->hTcxDec->Q_syn_Overl -> q_win *Q_syn_Overl = q_win; move16(); - Scale_sig( old_syn_Overl, oldLength / 2, sub( q_win, *Q_old_syn_Overl ) ); // Q(-1 - st->Q_syn) -> q_win - *Q_old_syn_Overl = q_win; - move16(); + if ( FB_flag == 0 ) { + Scale_sig( old_syn_Overl, oldLength / 2, sub( q_win, *Q_old_syn_Overl ) ); // Q(-1 - st->Q_syn) -> q_win + *Q_old_syn_Overl = q_win; + move16(); + } Scale_sig( old_out_fx, oldLength, sub( q_win, *Q_old_out_fx ) ); // Q(st->hHQ_core->Q_old_wtda) -> q_win *Q_old_out_fx = q_win; move16(); #endif - Scale_sig( st->syn, M + 1, sub( q_win, st->Q_syn ) ); // st->Q_syn -> q_win - - // Scale_sig( synth_buf_fx, add( add( old_synth_len, L_FRAME_PLUS ), M ), sub( q_win, q_syn ) ); // q_syn -> q_win } static Word16 TCX_MDCT_Inverse_GetScaleFactor( @@ -3087,9 +3081,6 @@ void IMDCT_ivas_fx( Word16 L_spec_TCX5_tmp = 0; move16(); #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN -#if 0 - Word16 q_win_prev; -#else IF( allow_qwin_change ) { q_win = -2; @@ -3097,7 +3088,6 @@ void IMDCT_ivas_fx( allow_qwin_change = 0; move16(); } -#endif #endif FOR( w = 0; w < 2; w++ ) @@ -3119,24 +3109,7 @@ void IMDCT_ivas_fx( TCX_MDCT_Inverse_qwin_fx( x_fx + L_spec_TCX5_tmp, x_e_hdrm, win_fx, L_ola, sub( L_win, L_ola ), L_ola, st->element_mode, &q_win, allow_qwin_change ); } -#if 0 - if ( w > 0 ) - { - if ( q_win_prev != q_win ) - { - // extern int frame; - // printf( "\nWarning: q_win changed in TCX5. Frame %d, q_win %d %d\n", frame, q_win_prev, q_win ); - printf( "\nWarning: q_win changed in TCX5. Frame X, q_win %d %d\n", q_win_prev, q_win ); - } - // Rescale both subframes some how ? - } - else - { - q_win_prev = q_win; - } -#endif - - IMDCT_ivas_fx_rescale( st, syn_Overl_TDAC_fx, Q_syn_Overl_TDAC_fx, old_syn_overl_fx, Q_old_syn_overl_fx, hTcxDec->old_syn_Overl, &hTcxDec->Q_old_syn_Overl, old_out_fx, q_old_out_fx, q_win, FB_flag ); + IMDCT_ivas_fx_rescale( syn_Overl_TDAC_fx, Q_syn_Overl_TDAC_fx, old_syn_overl_fx, Q_old_syn_overl_fx, hTcxDec->old_syn_Overl, &hTcxDec->Q_old_syn_Overl, old_out_fx, q_old_out_fx, q_win, FB_flag ); #else IF( EQ_16( kernel_type, MDST_IV ) || s_and( kernel_type, w ) ) { @@ -3238,7 +3211,7 @@ void IMDCT_ivas_fx( assert( q_win_prev == q_win ); - IMDCT_ivas_fx_rescale( st, syn_Overl_TDAC_fx, Q_syn_Overl_TDAC_fx, old_syn_overl_fx, Q_old_syn_overl_fx, hTcxDec->old_syn_Overl, &hTcxDec->Q_old_syn_Overl, old_out_fx, q_old_out_fx, q_win, FB_flag ); + IMDCT_ivas_fx_rescale( syn_Overl_TDAC_fx, Q_syn_Overl_TDAC_fx, old_syn_overl_fx, Q_old_syn_overl_fx, hTcxDec->old_syn_Overl, &hTcxDec->Q_old_syn_Overl, old_out_fx, q_old_out_fx, q_win, FB_flag ); #else IF( s_and( kernel_type, 1 ) ) { @@ -3297,7 +3270,7 @@ void IMDCT_ivas_fx( TCX_MDCT_Inverse_qwin_fx( x_fx, x_e_hdrm, xn_buf_fx, overlap, sub( L_frame, overlap ), overlap, st->element_mode, &q_win, allow_qwin_change ); } - IMDCT_ivas_fx_rescale( st, syn_Overl_TDAC_fx, Q_syn_Overl_TDAC_fx, old_syn_overl_fx, Q_old_syn_overl_fx, hTcxDec->old_syn_Overl, &hTcxDec->Q_old_syn_Overl, old_out_fx, q_old_out_fx, q_win, FB_flag ); + IMDCT_ivas_fx_rescale( syn_Overl_TDAC_fx, Q_syn_Overl_TDAC_fx, old_syn_overl_fx, Q_old_syn_overl_fx, hTcxDec->old_syn_Overl, &hTcxDec->Q_old_syn_Overl, old_out_fx, q_old_out_fx, q_win, FB_flag ); #else IF( EQ_16( kernel_type, MDST_IV ) ) { @@ -3358,8 +3331,9 @@ void IMDCT_ivas_fx( move16(); #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN - // L_norm_arr(xn_buf_fx_32, ) - IMDCT_ivas_fx_rescale( st, syn_Overl_TDAC_fx, Q_syn_Overl_TDAC_fx, old_syn_overl_fx, Q_old_syn_overl_fx, hTcxDec->old_syn_Overl, &hTcxDec->Q_old_syn_Overl, old_out_fx, q_old_out_fx, q_win, FB_flag ); + // q_win < norm + q_tmp_fx_32 - 16 + q_win = s_min( q_win, L_norm_arr( tmp_fx_32, L_frame ) + q_tmp_fx_32 - 16 ); + IMDCT_ivas_fx_rescale( syn_Overl_TDAC_fx, Q_syn_Overl_TDAC_fx, old_syn_overl_fx, Q_old_syn_overl_fx, hTcxDec->old_syn_Overl, &hTcxDec->Q_old_syn_Overl, old_out_fx, q_old_out_fx, q_win, FB_flag ); #endif Word16 diff = sub( q_tmp_fx_32, q_win ); @@ -3370,7 +3344,7 @@ void IMDCT_ivas_fx( { #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD assert( L_shr( L_shl( old_out_fx[ind], q_old_out_diff ), q_old_out_diff ) == old_out_fx[ind] ); - old_out_fx_32[ind] = L_shl( old_out_fx[ind], q_old_out_diff ); + old_out_fx_32[ind] = L_shl( L_deposit_l( old_out_fx[ind] ), q_old_out_diff ); #else old_out_fx_32[ind] = L_shl( old_out_fx[ind], diff ); #endif @@ -3382,9 +3356,10 @@ void IMDCT_ivas_fx( FOR( Word16 ind = 0; ind < L_frame; ind++ ) { #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD - old_out_fx[ind] = extract_l( L_shr( old_out_fx_32[ind], q_old_out_diff ) ); assert( extract_h( L_shr( old_out_fx_32[ind], q_old_out_diff ) ) == 0 || extract_h( L_shr( old_out_fx_32[ind], q_old_out_diff ) ) == -1 ); + old_out_fx[ind] = extract_l( L_shr( old_out_fx_32[ind], q_old_out_diff ) ); #else + assert( extract_h( L_shr( old_out_fx_32[ind], diff ) ) == 0 || extract_h( L_shr( old_out_fx_32[ind], diff ) ) == -1 ); old_out_fx[ind] = extract_l( L_shr( old_out_fx_32[ind], diff ) ); #endif xn_buf_fx[ind] = extract_l( L_shr( xn_buf_fx_32[ind], diff ) ); @@ -3426,7 +3401,7 @@ void IMDCT_ivas_fx( q_win = -2; #endif } - IMDCT_ivas_fx_rescale( st, syn_Overl_TDAC_fx, Q_syn_Overl_TDAC_fx, old_syn_overl_fx, Q_old_syn_overl_fx, hTcxDec->old_syn_Overl, &hTcxDec->Q_old_syn_Overl, old_out_fx, q_old_out_fx, q_win, FB_flag ); + IMDCT_ivas_fx_rescale( syn_Overl_TDAC_fx, Q_syn_Overl_TDAC_fx, old_syn_overl_fx, Q_old_syn_overl_fx, hTcxDec->old_syn_Overl, &hTcxDec->Q_old_syn_Overl, old_out_fx, q_old_out_fx, q_win, FB_flag ); #endif Word16 q_diff = sub( q_xn_buf_fx_32, q_win ); @@ -3492,7 +3467,7 @@ void IMDCT_ivas_fx( TCX_MDCT_Inverse_qwin_fx( x_fx, x_e_hdrm, xn_buf_fx, overlap, L_frame - overlap, overlap, st->element_mode, &q_win, allow_qwin_change ); } - IMDCT_ivas_fx_rescale( st, syn_Overl_TDAC_fx, Q_syn_Overl_TDAC_fx, old_syn_overl_fx, Q_old_syn_overl_fx, hTcxDec->old_syn_Overl, &hTcxDec->Q_old_syn_Overl, old_out_fx, q_old_out_fx, q_win, FB_flag ); + IMDCT_ivas_fx_rescale( syn_Overl_TDAC_fx, Q_syn_Overl_TDAC_fx, old_syn_overl_fx, Q_old_syn_overl_fx, hTcxDec->old_syn_Overl, &hTcxDec->Q_old_syn_Overl, old_out_fx, q_old_out_fx, q_win, FB_flag ); #else IF( EQ_16( kernel_type, MDST_IV ) ) { @@ -4195,30 +4170,21 @@ void decoder_tcx_ivas_fx( move16(); } -#if 0 - /* Scaling down buffers for decoder_tcx_imdct_fx*/ - Scale_sig( st->hTcxDec->syn_Overl_TDACFB, L_FRAME_MAX / 2, sub( st->Q_syn, st->hTcxDec->Q_syn_Overl_TDACFB ) ); // Scaling to Q_syn - st->hTcxDec->Q_syn_Overl_TDACFB = st->Q_syn; - Scale_sig( st->hTcxDec->syn_Overl_TDAC, L_FRAME32k / 2, sub( st->Q_syn, st->hTcxDec->Q_syn_Overl_TDAC ) ); // Scaling to Q_syn - st->hTcxDec->Q_syn_Overl_TDAC = st->Q_syn; - Scale_sig( st->hTcxDec->old_syn_Overl, 320, st->Q_syn - st->hTcxDec->Q_old_syn_Overl ); // Scaling to Q_syn - st->hTcxDec->Q_old_syn_Overl = st->Q_syn; -#endif - -#if 0 - Scale_sig( synth_fx, L_frame_glob, st->Q_syn ); // Scaling to Q_syn - Scale_sig( synthFB_fx, L_frameTCX_glob, st->Q_syn ); // Scaling to Q_syn -#endif - Copy_Scale_sig_16_32_no_sat( st->old_Aq_12_8_fx, st->old_Aq_12_8_fx_32, M + 1, ( sub( 28, ( sub( 15, norm_s( sub( st->old_Aq_12_8_fx[0], 1 ) ) ) ) ) ) ); - Word16 q_win; + Word16 q_win, q_winFB; q_win = st->Q_syn; + move16(); + q_winFB = st->Q_syn; + move16(); + + assert( q_win == 0 ); - decoder_tcx_imdct_fx( st, L_frame_glob, L_frameTCX_glob, L_spec, tcx_offset, tcx_offsetFB, L_frame, L_frameTCX, left_rect, &x_fx[0], q_x, xn_buf_fx, &q_win, MDCT_IV, + decoder_tcx_imdct_fx( st, L_frame_glob, L_frameTCX_glob, L_spec, tcx_offset, tcx_offsetFB, L_frame, L_frameTCX, left_rect, &x_fx[0], q_x, xn_buf_fx, &q_win, &q_winFB, MDCT_IV, fUseTns, &synth_fx[0], &synthFB_fx[0], bfi, frame_cnt, sba_dirac_stereo_flag ); assert( q_win == 0 ); + assert( q_win == q_winFB ); /* Scaling up again */ Scale_sig( synth_fx, L_frame_glob, sub( st->Q_syn, q_win ) ); @@ -5667,6 +5633,7 @@ void decoder_tcx_imdct_fx( Word16 xn_buf_fx[], // Q(-2) #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN Word16 *q_win, + Word16 *q_winFB, #else Word16 q_win, #endif @@ -5915,7 +5882,7 @@ void decoder_tcx_imdct_fx( #endif hTcxCfg->tcx_mdct_window_halfFB, hTcxCfg->tcx_mdct_window_minimumFB, hTcxCfg->tcx_mdct_window_transFB, hTcxCfg->tcx_mdct_window_half_lengthFB, hTcxCfg->tcx_mdct_window_min_lengthFB, index, #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD - kernelType, left_rect, tcx_offsetFB, overlapFB, L_frameTCX, L_frameTCX, shr( s_max( L_frameTCX, L_spec ), 1 ), L_frameTCX_glob, frame_cnt, bfi, st->hHQ_core->old_out_fx, &st->hHQ_core->Q_old_wtda, 1, st, ratio, acelp_zir_fx, q_win ); + kernelType, left_rect, tcx_offsetFB, overlapFB, L_frameTCX, L_frameTCX, shr( s_max( L_frameTCX, L_spec ), 1 ), L_frameTCX_glob, frame_cnt, bfi, st->hHQ_core->old_out_fx, &st->hHQ_core->Q_old_wtda, 1, st, ratio, acelp_zir_fx, q_winFB ); #else kernelType, left_rect, tcx_offsetFB, overlapFB, L_frameTCX, L_frameTCX, shr( s_max( L_frameTCX, L_spec ), 1 ), L_frameTCX_glob, frame_cnt, bfi, st->hHQ_core->old_out_fx, 1, st, ratio, acelp_zir_fx, q_win ); #endif @@ -5928,7 +5895,7 @@ void decoder_tcx_imdct_fx( IMDCT_ivas_fx( x_fx, q_x, hTcxDec->syn_OverlFB, hTcxDec->syn_Overl_TDACFB, xn_bufFB_fx_16, hTcxCfg->tcx_aldo_window_1_FB, hTcxCfg->tcx_aldo_window_1_FB_trunc, hTcxCfg->tcx_aldo_window_2_FB, hTcxCfg->tcx_mdct_window_halfFB, hTcxCfg->tcx_mdct_window_minimumFB, hTcxCfg->tcx_mdct_window_transFB, hTcxCfg->tcx_mdct_window_half_lengthFB, hTcxCfg->tcx_mdct_window_min_lengthFB, index, #endif #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD - kernelType, left_rect, tcx_offsetFB, overlapFB, L_frameTCX, L_frameTCX, shr( s_max( L_frameTCX, L_spec ), 1 ), L_frameTCX_glob, frame_cnt, bfi, st->hHQ_core->old_out_fx, &st->hHQ_core->Q_old_wtda, 1, st, ratio, acelp_zir_fx, q_win ); + kernelType, left_rect, tcx_offsetFB, overlapFB, L_frameTCX, L_frameTCX, shr( s_max( L_frameTCX, L_spec ), 1 ), L_frameTCX_glob, frame_cnt, bfi, st->hHQ_core->old_out_fx, &st->hHQ_core->Q_old_wtda, 1, st, ratio, acelp_zir_fx, q_winFB ); #else kernelType, left_rect, tcx_offsetFB, overlapFB, L_frameTCX, L_frameTCX, shr( s_max( L_frameTCX, L_spec ), 1 ), L_frameTCX_glob, frame_cnt, bfi, st->hHQ_core->old_out_fx, 1, st, ratio, acelp_zir_fx, q_win ); #endif diff --git a/lib_dec/ivas_mdct_core_dec_fx.c b/lib_dec/ivas_mdct_core_dec_fx.c index b1a78b1a8..3ae1a5036 100644 --- a/lib_dec/ivas_mdct_core_dec_fx.c +++ b/lib_dec/ivas_mdct_core_dec_fx.c @@ -1103,6 +1103,7 @@ void ivas_mdct_core_reconstruct_fx( move16(); #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN Word16 q_win = -2; + Word16 q_winFB = -2; #else #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT Word16 q_win = -1; @@ -1210,11 +1211,6 @@ void ivas_mdct_core_reconstruct_fx( Scale_sig( synth_bufFB_fx, add( add( st->hTcxDec->old_synth_lenFB, L_FRAME_PLUS ), M ), sub( q_win, q_syn ) ); // q_syn -> q_win Scale_sig( st->syn, M + 1, sub( q_win, st->Q_syn ) ); // st->Q_syn -> q_win #endif -#if 0 - Scale_sig( synth_buf_fx, add( add( st->hTcxDec->old_synth_len, L_FRAME_PLUS ), M ), sub( q_win, q_syn ) ); // q_syn -> q_win - Scale_sig( synth_bufFB_fx, add( add( st->hTcxDec->old_synth_lenFB, L_FRAME_PLUS ), M ), sub( q_win, q_syn ) ); // q_syn -> q_win - Scale_sig( st->syn, M + 1, sub( q_win, st->Q_syn ) ); // st->Q_syn -> q_win -#endif FOR( k = 0; k < nSubframes[ch]; k++ ) { @@ -1228,14 +1224,16 @@ void ivas_mdct_core_reconstruct_fx( #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN IF( ( EQ_16( hCPE->nchan_out, 1 ) && EQ_16( st->hTcxDec->kernel_type[k], MDST_IV ) ) || EQ_16( st->hTcxCfg->tcx_last_overlap_mode, TRANSITION_OVERLAP ) ) { - decoder_tcx_imdct_fx( st, L_frame_global[ch], L_frame_globalTCX[ch], L_spec[ch], tcx_offset[ch], tcx_offsetFB[ch], L_frame[ch], L_frameTCX[ch], left_rect[ch], x_fx[ch][k], q_x, xn_buf_fx, &q_win, + decoder_tcx_imdct_fx( st, L_frame_global[ch], L_frame_globalTCX[ch], L_spec[ch], tcx_offset[ch], tcx_offsetFB[ch], L_frame[ch], L_frameTCX[ch], left_rect[ch], x_fx[ch][k], q_x, xn_buf_fx, &q_win, &q_winFB, MDCT_IV, fUseTns[ch][k], &synth_fx[k * L_frame[ch]], &synthFB_fx[k * L_frameTCX[ch]], bfi, k, 0 ); } ELSE { - decoder_tcx_imdct_fx( st, L_frame_global[ch], L_frame_globalTCX[ch], L_spec[ch], tcx_offset[ch], tcx_offsetFB[ch], L_frame[ch], L_frameTCX[ch], left_rect[ch], x_fx[ch][k], q_x, xn_buf_fx, &q_win, + decoder_tcx_imdct_fx( st, L_frame_global[ch], L_frame_globalTCX[ch], L_spec[ch], tcx_offset[ch], tcx_offsetFB[ch], L_frame[ch], L_frameTCX[ch], left_rect[ch], x_fx[ch][k], q_x, xn_buf_fx, &q_win, &q_winFB, st->hTcxDec->kernel_type[k], fUseTns[ch][k], &synth_fx[k * L_frame[ch]], &synthFB_fx[k * L_frameTCX[ch]], bfi, k, 0 ); } + + Scale_sig( st->syn, M + 1, sub( q_win, st->Q_syn ) ); // st->Q_syn -> q_win #else IF( ( EQ_16( hCPE->nchan_out, 1 ) && EQ_16( st->hTcxDec->kernel_type[k], MDST_IV ) ) || EQ_16( st->hTcxCfg->tcx_last_overlap_mode, TRANSITION_OVERLAP ) ) { @@ -1254,6 +1252,8 @@ void ivas_mdct_core_reconstruct_fx( #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN q_win = -2; move16(); + q_winFB = -2; + move16(); #endif set16_fx( &synth_fx[k * L_frame[ch]], 0, L_frame[ch] ); set16_fx( &synthFB_fx[k * L_frame[ch]], 0, L_frameTCX[ch] ); @@ -1270,7 +1270,43 @@ void ivas_mdct_core_reconstruct_fx( set16_fx( &st->hTcxDec->syn_Overl_TDACFB[0], 0, shr( L_frameTCX[ch], 1 ) ); } } +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN + test(); + IF( ( bfi == 0 ) && st->hTonalMDCTConc != NULL ) + { + TonalMDCTConceal_SaveTimeSignal_ivas_fx( st->hTonalMDCTConc, synthFB_fx, q_winFB, L_frameTCX[ch] ); + } + decoder_tcx_post_ivas_fx( st, synth_fx, synthFB_fx, q_winFB, NULL, bfi, MCT_flag ); + + sf = s_min( getScaleFactor16( synth_buf_fx, add( add( st->hTcxDec->old_synth_len, L_FRAME_PLUS ), M ) ), getScaleFactor16( synth_bufFB_fx, add( add( st->hTcxDec->old_synth_lenFB, L_FRAME_PLUS ), M ) ) ); + IF( LT_16( sf, 2 ) ) + { + q_syn = sub( sf, 2 ); + st->Q_syn = q_syn; + move16(); + } + sf = s_min( getScaleFactor16( st->hHQ_core->old_out_fx, L_FRAME48k ), getScaleFactor16( st->hHQ_core->old_out_LB_fx, L_FRAME32k ) ); + IF( LT_16( sf, sub( st->Q_syn, q_win ) ) ) + { + st->Q_syn = add( q_win, sf ); + } + Scale_sig( st->hTcxDec->syn_Overl_TDACFB, L_FRAME_MAX / 2, sub( sub( -1, st->Q_syn ), st->hTcxDec->Q_syn_Overl_TDACFB ) ); // q_winFB -> Q(-1 - st->Q_syn) + st->hTcxDec->Q_syn_Overl_TDACFB = sub( -1, st->Q_syn ); + move16(); + Scale_sig( st->hTcxDec->syn_Overl_TDAC, L_FRAME32k / 2, sub( sub( -1, st->Q_syn ), st->hTcxDec->Q_syn_Overl_TDAC ) ); // q_win -> Q(-1 - st->Q_syn) + st->hTcxDec->Q_syn_Overl_TDAC = sub( -1, st->Q_syn ); + move16(); + Scale_sig( st->hTcxDec->old_syn_Overl, L_FRAME32k / 2, sub( sub( -1, st->Q_syn ), st->hTcxDec->Q_old_syn_Overl ) ); // q_win -> Q(-1 - st->Q_syn) + st->hTcxDec->Q_old_syn_Overl = sub( -1, st->Q_syn ); + Scale_sig( synth_buf_fx, add( add( st->hTcxDec->old_synth_len, L_FRAME_PLUS ), M ), sub( q_syn, q_win ) ); // q_win -> q_syn + Scale_sig( synth_bufFB_fx, add( add( st->hTcxDec->old_synth_lenFB, L_FRAME_PLUS ), M ), sub( q_syn, q_winFB ) ); // q_win -> q_syn + Scale_sig( st->syn, M + 1, add( st->Q_syn, 2 ) ); + Scale_sig( st->hTcxDec->syn_OverlFB, L_FRAME_MAX / 2, sub( st->Q_syn, st->hTcxDec->Q_syn_OverlFB ) ); // q_winFB -> st->Q_syn + st->hTcxDec->Q_syn_OverlFB = st->Q_syn; + Scale_sig( st->hTcxDec->syn_Overl, L_FRAME32k / 2, sub( st->Q_syn, st->hTcxDec->Q_syn_Overl ) ); // q_win -> st->Q_syn + st->hTcxDec->Q_syn_Overl = st->Q_syn; +#else test(); IF( ( bfi == 0 ) && st->hTonalMDCTConc != NULL ) { @@ -1314,6 +1350,7 @@ void ivas_mdct_core_reconstruct_fx( st->hHQ_core->Q_old_wtda_LB = st->Q_syn; move16(); #endif +#endif #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD Scale_sig( st->mem_syn2_fx, M, sub( -2, q_win ) ); // Scale_sig( st->mem_syn2_fx, M, sub( st->Q_syn, q_win ) ); // q_win -> Q_syn -- GitLab From dd49640f2b28b53196c4ba39266ba19aaeb0e9f1 Mon Sep 17 00:00:00 2001 From: Manuel Jander Date: Tue, 13 May 2025 19:38:32 +0200 Subject: [PATCH 041/113] clang format --- lib_dec/dec_tcx_fx.c | 6 +++--- lib_dec/ivas_mdct_core_dec_fx.c | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index 037f2e3cb..2f8bf396f 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -2635,8 +2635,7 @@ static void IMDCT_ivas_fx_rescale( Word16 *old_out_fx, Word16 *Q_old_out_fx, Word16 q_win, - const Word16 FB_flag -) + const Word16 FB_flag ) { Word16 oldLength; @@ -2655,7 +2654,8 @@ static void IMDCT_ivas_fx_rescale( Scale_sig( syn_Overl, oldLength / 2, sub( q_win, *Q_syn_Overl ) ); // st->hTcxDec->Q_syn_Overl -> q_win *Q_syn_Overl = q_win; move16(); - if ( FB_flag == 0 ) { + if ( FB_flag == 0 ) + { Scale_sig( old_syn_Overl, oldLength / 2, sub( q_win, *Q_old_syn_Overl ) ); // Q(-1 - st->Q_syn) -> q_win *Q_old_syn_Overl = q_win; move16(); diff --git a/lib_dec/ivas_mdct_core_dec_fx.c b/lib_dec/ivas_mdct_core_dec_fx.c index 3ae1a5036..995aa70e1 100644 --- a/lib_dec/ivas_mdct_core_dec_fx.c +++ b/lib_dec/ivas_mdct_core_dec_fx.c @@ -1233,7 +1233,7 @@ void ivas_mdct_core_reconstruct_fx( st->hTcxDec->kernel_type[k], fUseTns[ch][k], &synth_fx[k * L_frame[ch]], &synthFB_fx[k * L_frameTCX[ch]], bfi, k, 0 ); } - Scale_sig( st->syn, M + 1, sub( q_win, st->Q_syn ) ); // st->Q_syn -> q_win + Scale_sig( st->syn, M + 1, sub( q_win, st->Q_syn ) ); // st->Q_syn -> q_win #else IF( ( EQ_16( hCPE->nchan_out, 1 ) && EQ_16( st->hTcxDec->kernel_type[k], MDST_IV ) ) || EQ_16( st->hTcxCfg->tcx_last_overlap_mode, TRANSITION_OVERLAP ) ) { @@ -1299,7 +1299,7 @@ void ivas_mdct_core_reconstruct_fx( move16(); Scale_sig( st->hTcxDec->old_syn_Overl, L_FRAME32k / 2, sub( sub( -1, st->Q_syn ), st->hTcxDec->Q_old_syn_Overl ) ); // q_win -> Q(-1 - st->Q_syn) st->hTcxDec->Q_old_syn_Overl = sub( -1, st->Q_syn ); - Scale_sig( synth_buf_fx, add( add( st->hTcxDec->old_synth_len, L_FRAME_PLUS ), M ), sub( q_syn, q_win ) ); // q_win -> q_syn + Scale_sig( synth_buf_fx, add( add( st->hTcxDec->old_synth_len, L_FRAME_PLUS ), M ), sub( q_syn, q_win ) ); // q_win -> q_syn Scale_sig( synth_bufFB_fx, add( add( st->hTcxDec->old_synth_lenFB, L_FRAME_PLUS ), M ), sub( q_syn, q_winFB ) ); // q_win -> q_syn Scale_sig( st->syn, M + 1, add( st->Q_syn, 2 ) ); Scale_sig( st->hTcxDec->syn_OverlFB, L_FRAME_MAX / 2, sub( st->Q_syn, st->hTcxDec->Q_syn_OverlFB ) ); // q_winFB -> st->Q_syn -- GitLab From d6a5545a87cf88d7866d7e4bb7db26f9e4efee29 Mon Sep 17 00:00:00 2001 From: Manuel Jander Date: Wed, 14 May 2025 14:39:40 +0200 Subject: [PATCH 042/113] Correct scaling of synth_buf_fx/synth_bufFB_fx. Cleanup of obsolete code. --- lib_com/prot_fx.h | 3 - lib_dec/dec_tcx_fx.c | 79 +++++++++++++------------- lib_dec/ivas_mct_dec_fx.c | 4 -- lib_dec/ivas_mdct_core_dec_fx.c | 22 +++---- lib_dec/ivas_stereo_mdct_core_dec_fx.c | 4 -- 5 files changed, 46 insertions(+), 66 deletions(-) diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index a84d0d8dc..704049d9f 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -9949,9 +9949,6 @@ void ivas_mdct_core_reconstruct_fx( /* o : synthesis @output_FS */ // e_sig Word16 fUseTns[CPE_CHANNELS][NB_DIV], /* i : flage TNS enabled */ const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0)*/ -#if defined( FIX_1348_BIT_PRECISION_IMPROVEMENT ) && !defined( FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN ) - const Word16 isParamMC, -#endif Word16 q_x, Word16 e_sig[CPE_CHANNELS] ); diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index 2f8bf396f..1eee95a3b 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -2573,22 +2573,6 @@ void IMDCT_fx( Word32 *x, Word16 x_e, Word16 *old_syn_overl, Word16 *syn_Overl_T } #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN -#if 0 -static Word16 IMDCT_ivas_fx_adjust_qwin( - Word16 Q_syn_Overl_TDAC, - Word16 Q_syn_Overl, - Word16 Q_old_syn_Overl, - Word16 Q_old_wtda, - Word16 q_win ) -{ - // q_win = s_min( s_min( s_min( s_min( Q_syn_Overl_TDAC , Q_syn_Overl ), Q_old_syn_Overl ), Q_old_wtda ), q_win ); - q_win = s_min( s_min( s_min( Q_syn_Overl_TDAC, Q_syn_Overl ), Q_old_syn_Overl ), Q_old_wtda ); - q_win = s_min( q_win, -1 ); - q_win = s_max( q_win, -2 ); - - return q_win; -} -#endif static Word16 IMDCT_ivas_fx_calc_qwin( Word16 *syn_Overl_TDAC, @@ -2599,9 +2583,12 @@ static Word16 IMDCT_ivas_fx_calc_qwin( Word16 Q_old_syn_Overl, Word16 *old_out_fx, Word16 Q_old_out_fx, - const Word16 FB_flag, - Word16 q_win ) + Word16 q_win, + const Word16 L_frame, + const Word16 L_frameTCX, + const Word16 FB_flag ) { +#if 0 Word16 oldLength; oldLength = L_FRAME32k; @@ -2611,6 +2598,18 @@ static Word16 IMDCT_ivas_fx_calc_qwin( oldLength = L_FRAME48k; move16(); } +#else + Word16 oldLength; + + oldLength = L_frame; + move16(); + if ( FB_flag ) + { + oldLength = L_frameTCX; + move16(); + } +#endif + q_win = 4; move16(); @@ -2736,7 +2735,6 @@ static void TCX_MDCT_Inverse_qwin_fx( negfac = negate( fac ); -#if 1 IF( allow_qwin_change ) { // x_e + q_win == L_norm_arr(tmp_buf, , *q_win ); @@ -2744,9 +2742,7 @@ static void TCX_MDCT_Inverse_qwin_fx( s = L_norm_arr( tmp_buf + L2, m + R2 + L2 ); *q_win = s_min( sub( s, x_e ), *q_win ); } -#else - assert( *q_win == 0 || *q_win == -2 ); -#endif + s = add( x_e, *q_win ); move16(); @@ -2805,7 +2801,6 @@ static void TCX_MDST_Inverse_qwin_fx( negfac = negate( fac ); -#if 1 IF( allow_qwin_change ) { // x_e + q_win == L_norm_arr(tmp_buf, , *q_win ); @@ -2813,9 +2808,7 @@ static void TCX_MDST_Inverse_qwin_fx( s = L_norm_arr( tmp_buf + L2, m + R2 + L2 ); *q_win = s_min( sub( s, x_e ), *q_win ); } -#else - assert( *q_win == 0 || *q_win == -2 ); -#endif + s = add( x_e, *q_win ); move16(); @@ -2893,7 +2886,6 @@ static void TCX_MDXT_Inverse_qwin_fx( signRight = negfac; } -#if 1 IF( allow_qwin_change ) { // x_e + q_win == L_norm_arr(tmp_buf, , *q_win ); @@ -2901,9 +2893,7 @@ static void TCX_MDXT_Inverse_qwin_fx( s = L_norm_arr( tmp_buf + L2, m + R2 + L2 ); *q_win = s_min( sub( s, x_e ), *q_win ); } -#else - assert( *q_win == 0 || *q_win == -2 ); -#endif + s = add( x_e, *q_win ); move16(); @@ -2932,7 +2922,6 @@ static void TCX_MDXT_Inverse_qwin_fx( return; } - #endif void IMDCT_ivas_fx( @@ -3002,7 +2991,7 @@ void IMDCT_ivas_fx( { // q_win = IMDCT_ivas_fx_adjust_qwin( *Q_syn_Overl_TDAC_fx, *Q_old_syn_overl_fx, hTcxDec->Q_old_syn_Overl, *q_old_out_fx, q_win ); q_win = IMDCT_ivas_fx_calc_qwin( syn_Overl_TDAC_fx, *Q_syn_Overl_TDAC_fx, old_syn_overl_fx, *Q_old_syn_overl_fx, - hTcxDec->old_syn_Overl, hTcxDec->Q_old_syn_Overl, old_out_fx, *q_old_out_fx, FB_flag, q_win ); + hTcxDec->old_syn_Overl, hTcxDec->Q_old_syn_Overl, old_out_fx, *q_old_out_fx, q_win, L_frame, L_frameTCX, FB_flag ); } #else x_e_hdrm = add( q_win, sub( Q16, q_x ) ); @@ -3083,6 +3072,7 @@ void IMDCT_ivas_fx( #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN IF( allow_qwin_change ) { + /* Use fixed q_win to avoid the need to adapt scaling of two TCX5 blocks (less effort with maybe not ideal scaling) */ q_win = -2; move16(); allow_qwin_change = 0; @@ -3165,6 +3155,17 @@ void IMDCT_ivas_fx( #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN Word16 q_win_prev; +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN + IF( allow_qwin_change ) + { + /* Use fixed q_win to avoid the need to adapt scaling of two TCX5 blocks (less effort with maybe not ideal scaling) */ + q_win = -2; + move16(); + allow_qwin_change = 0; + move16(); + } +#endif + IF( EQ_16( kernel_type, MDST_IV ) ) { TCX_MDST_Inverse_qwin_fx( x_fx, x_e_hdrm, win_fx + L_win, 0, sub( L_win, shr( L_ola, 1 ) ), L_ola, &q_win, allow_qwin_change ); @@ -3202,11 +3203,11 @@ void IMDCT_ivas_fx( #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN IF( s_and( kernel_type, 1 ) ) { - TCX_MDST_Inverse_qwin_fx( x_fx + L_spec_TCX5, x_e_hdrm, win_fx, L_ola, sub( L_win, L_ola ), L_ola, &q_win, 0 ); + TCX_MDST_Inverse_qwin_fx( x_fx + L_spec_TCX5, x_e_hdrm, win_fx, L_ola, sub( L_win, L_ola ), L_ola, &q_win, allow_qwin_change ); } ELSE { - TCX_MDCT_Inverse_qwin_fx( x_fx + L_spec_TCX5, x_e_hdrm, win_fx, L_ola, sub( L_win, L_ola ), L_ola, st->element_mode, &q_win, 0 ); + TCX_MDCT_Inverse_qwin_fx( x_fx + L_spec_TCX5, x_e_hdrm, win_fx, L_ola, sub( L_win, L_ola ), L_ola, st->element_mode, &q_win, allow_qwin_change ); } assert( q_win_prev == q_win ); @@ -3392,14 +3393,10 @@ void IMDCT_ivas_fx( #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN if ( allow_qwin_change ) { -#if 1 // sub( q_xn_buf_fx_32, q_win ) == 16 - L_norm_arr( xn_buf_fx_32, L_frame ) // q_xn_buf_fx_32 - q_win == 16 - L_norm_arr( xn_buf_fx_32, L_frame ) // q_win == - 16 + L_norm_arr( xn_buf_fx_32, L_frame ) + q_xn_buf_fx_32 q_win = s_min( q_win, add( sub( q_xn_buf_fx_32, 16 ), L_norm_arr( xn_buf_fx_32, L_frame ) ) - 1 ); -#else - q_win = -2; -#endif } IMDCT_ivas_fx_rescale( syn_Overl_TDAC_fx, Q_syn_Overl_TDAC_fx, old_syn_overl_fx, Q_old_syn_overl_fx, hTcxDec->old_syn_Overl, &hTcxDec->Q_old_syn_Overl, old_out_fx, q_old_out_fx, q_win, FB_flag ); #endif @@ -4188,7 +4185,7 @@ void decoder_tcx_ivas_fx( /* Scaling up again */ Scale_sig( synth_fx, L_frame_glob, sub( st->Q_syn, q_win ) ); - Scale_sig( synthFB_fx, L_frameTCX_glob, sub( st->Q_syn, q_win ) ); + Scale_sig( synthFB_fx, L_frameTCX_glob, sub( st->Q_syn, q_winFB ) ); // Scale_sig( st->hTcxDec->syn_Overl, L_FRAME32k / 2, 1 ); Scale_sig( st->hTcxDec->old_syn_Overl, 320, ( -2 - st->hTcxDec->Q_old_syn_Overl ) ); // Scaling to Q-2 @@ -5860,7 +5857,7 @@ void decoder_tcx_imdct_fx( } #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN - Word16 shift_q = sub( q_x, *q_win ); + Word16 shift_q = sub( q_x, *q_winFB ); #endif FOR( Word16 ind = 0; ind < L_MDCT_OVLP_MAX + L_FRAME_PLUS + L_MDCT_OVLP_MAX; ind++ ) @@ -5902,7 +5899,7 @@ void decoder_tcx_imdct_fx( } #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN - shift_q = sub( q_x, *q_win ); + shift_q = sub( q_x, *q_winFB ); #endif FOR( Word16 ind = 0; ind < L_MDCT_OVLP_MAX + L_FRAME_PLUS + L_MDCT_OVLP_MAX; ind++ ) diff --git a/lib_dec/ivas_mct_dec_fx.c b/lib_dec/ivas_mct_dec_fx.c index 4c3b8b782..b34ce0c56 100644 --- a/lib_dec/ivas_mct_dec_fx.c +++ b/lib_dec/ivas_mct_dec_fx.c @@ -346,11 +346,7 @@ ivas_error ivas_mct_dec_fx( } Copy_Scale_sig_16_32_no_sat( hCPE->hCoreCoder[0]->old_Aq_12_8_fx, hCPE->hCoreCoder[0]->old_Aq_12_8_fx_32, add( M, 1 ), sub( 28, sub( 15, norm_s( sub( hCPE->hCoreCoder[0]->old_Aq_12_8_fx[0], 1 ) ) ) ) ); Copy_Scale_sig_16_32_no_sat( hCPE->hCoreCoder[1]->old_Aq_12_8_fx, hCPE->hCoreCoder[1]->old_Aq_12_8_fx_32, add( M, 1 ), sub( 28, sub( 15, norm_s( sub( hCPE->hCoreCoder[1]->old_Aq_12_8_fx[0], 1 ) ) ) ) ); -#if defined( FIX_1348_BIT_PRECISION_IMPROVEMENT ) && !defined( FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN ) - ivas_mdct_core_reconstruct_fx( hCPE, x_fx, synth_fx, fUseTns[cpe_id], 1, st_ivas->mc_mode == MC_MODE_PARAMMC, q_output, e_sig ); -#else ivas_mdct_core_reconstruct_fx( hCPE, x_fx, synth_fx, fUseTns[cpe_id], 1, q_output, e_sig ); -#endif Word16 hdrm, sh; hdrm = getScaleFactor16( synth_fx[0], hCPE->hCoreCoder[0]->hTcxDec->L_frameTCX ); diff --git a/lib_dec/ivas_mdct_core_dec_fx.c b/lib_dec/ivas_mdct_core_dec_fx.c index 995aa70e1..56cd70609 100644 --- a/lib_dec/ivas_mdct_core_dec_fx.c +++ b/lib_dec/ivas_mdct_core_dec_fx.c @@ -1083,9 +1083,6 @@ void ivas_mdct_core_reconstruct_fx( /* o : synthesis @output_FS */ // e_sig Word16 fUseTns[CPE_CHANNELS][NB_DIV], /* i : flage TNS enabled */ const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0)*/ -#if defined( FIX_1348_BIT_PRECISION_IMPROVEMENT ) && !defined( FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN ) - const Word16 isParamMC, -#endif Word16 q_x, Word16 e_sig[CPE_CHANNELS] ) { @@ -1103,7 +1100,9 @@ void ivas_mdct_core_reconstruct_fx( move16(); #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN Word16 q_win = -2; + move16(); Word16 q_winFB = -2; + move16(); #else #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT Word16 q_win = -1; @@ -1130,13 +1129,6 @@ void ivas_mdct_core_reconstruct_fx( bfi = sts[0]->bfi; move16(); -#ifndef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN -#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT - if ( isParamMC ) - q_win = -2; -#endif -#endif - /* TNS, ITF, IMDCT and updates */ FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) { @@ -1233,7 +1225,9 @@ void ivas_mdct_core_reconstruct_fx( st->hTcxDec->kernel_type[k], fUseTns[ch][k], &synth_fx[k * L_frame[ch]], &synthFB_fx[k * L_frameTCX[ch]], bfi, k, 0 ); } - Scale_sig( st->syn, M + 1, sub( q_win, st->Q_syn ) ); // st->Q_syn -> q_win + // Need to rescale for each subframe, because q_win/q_winFB might change for the next subframe. Other OLA buffers are rescaled each time. + Scale_sig( &synth_fx[k * L_frame[ch]], add( L_frame[ch], M ), sub( st->hTcxDec->q_old_synth, q_win ) ); // q_win -> st->hTcxDec->q_old_synth + Scale_sig( &synthFB_fx[k * L_frameTCX[ch]], add( L_frameTCX[ch], M ), sub( st->hTcxDec->q_old_synth, q_winFB ) ); // q_winFB -> st->hTcxDec->q_old_synth #else IF( ( EQ_16( hCPE->nchan_out, 1 ) && EQ_16( st->hTcxDec->kernel_type[k], MDST_IV ) ) || EQ_16( st->hTcxCfg->tcx_last_overlap_mode, TRANSITION_OVERLAP ) ) { @@ -1299,13 +1293,13 @@ void ivas_mdct_core_reconstruct_fx( move16(); Scale_sig( st->hTcxDec->old_syn_Overl, L_FRAME32k / 2, sub( sub( -1, st->Q_syn ), st->hTcxDec->Q_old_syn_Overl ) ); // q_win -> Q(-1 - st->Q_syn) st->hTcxDec->Q_old_syn_Overl = sub( -1, st->Q_syn ); - Scale_sig( synth_buf_fx, add( add( st->hTcxDec->old_synth_len, L_FRAME_PLUS ), M ), sub( q_syn, q_win ) ); // q_win -> q_syn - Scale_sig( synth_bufFB_fx, add( add( st->hTcxDec->old_synth_lenFB, L_FRAME_PLUS ), M ), sub( q_syn, q_winFB ) ); // q_win -> q_syn - Scale_sig( st->syn, M + 1, add( st->Q_syn, 2 ) ); Scale_sig( st->hTcxDec->syn_OverlFB, L_FRAME_MAX / 2, sub( st->Q_syn, st->hTcxDec->Q_syn_OverlFB ) ); // q_winFB -> st->Q_syn st->hTcxDec->Q_syn_OverlFB = st->Q_syn; Scale_sig( st->hTcxDec->syn_Overl, L_FRAME32k / 2, sub( st->Q_syn, st->hTcxDec->Q_syn_Overl ) ); // q_win -> st->Q_syn st->hTcxDec->Q_syn_Overl = st->Q_syn; + Scale_sig( synth_buf_fx, add( add( st->hTcxDec->old_synth_len, L_FRAME_PLUS ), M ), sub( q_syn, st->hTcxDec->q_old_synth ) ); // st->hTcxDec->q_old_synth -> q_syn + Scale_sig( synth_bufFB_fx, add( add( st->hTcxDec->old_synth_lenFB, L_FRAME_PLUS ), M ), sub( q_syn, st->hTcxDec->q_old_synth ) ); // st->hTcxDec->q_old_synth -> q_syn + Scale_sig( st->syn, M + 1, add( st->Q_syn, 2 ) ); #else test(); IF( ( bfi == 0 ) && st->hTonalMDCTConc != NULL ) diff --git a/lib_dec/ivas_stereo_mdct_core_dec_fx.c b/lib_dec/ivas_stereo_mdct_core_dec_fx.c index e70b1c137..890e5fc9e 100644 --- a/lib_dec/ivas_stereo_mdct_core_dec_fx.c +++ b/lib_dec/ivas_stereo_mdct_core_dec_fx.c @@ -550,11 +550,7 @@ void stereo_mdct_core_dec_fx( } Copy_Scale_sig_16_32_no_sat( hCPE->hCoreCoder[0]->old_Aq_12_8_fx, hCPE->hCoreCoder[0]->old_Aq_12_8_fx_32, M + 1, sub( 28, sub( 15, norm_s( sub( hCPE->hCoreCoder[0]->old_Aq_12_8_fx[0], 1 ) ) ) ) ); /* Q28 */ Copy_Scale_sig_16_32_no_sat( hCPE->hCoreCoder[1]->old_Aq_12_8_fx, hCPE->hCoreCoder[1]->old_Aq_12_8_fx_32, M + 1, sub( 28, sub( 15, norm_s( sub( hCPE->hCoreCoder[1]->old_Aq_12_8_fx[0], 1 ) ) ) ) ); /* Q28 */ -#if defined( FIX_1348_BIT_PRECISION_IMPROVEMENT ) && !defined( FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN ) - ivas_mdct_core_reconstruct_fx( hCPE, x_fx, signal_outFB_tmp_fx, fUseTns, 0, st_ivas->mc_mode == MC_MODE_PARAMMC, Q11, e_sigFB ); -#else ivas_mdct_core_reconstruct_fx( hCPE, x_fx, signal_outFB_tmp_fx, fUseTns, 0, Q11, e_sigFB ); -#endif Copy32( signal_out_tmp_fx[0], signal_out_fx[0], L_FRAME48k ); /* Q11 */ Copy32( signal_out_tmp_fx[1], signal_out_fx[1], L_FRAME48k ); /* Q11 */ -- GitLab From 85a0fa2eae5acd675c251603a3f733ce51244dfb Mon Sep 17 00:00:00 2001 From: Manuel Jander Date: Wed, 14 May 2025 14:43:03 +0200 Subject: [PATCH 043/113] clang format --- lib_dec/ivas_mdct_core_dec_fx.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib_dec/ivas_mdct_core_dec_fx.c b/lib_dec/ivas_mdct_core_dec_fx.c index 56cd70609..bd20c26d0 100644 --- a/lib_dec/ivas_mdct_core_dec_fx.c +++ b/lib_dec/ivas_mdct_core_dec_fx.c @@ -1226,7 +1226,7 @@ void ivas_mdct_core_reconstruct_fx( } // Need to rescale for each subframe, because q_win/q_winFB might change for the next subframe. Other OLA buffers are rescaled each time. - Scale_sig( &synth_fx[k * L_frame[ch]], add( L_frame[ch], M ), sub( st->hTcxDec->q_old_synth, q_win ) ); // q_win -> st->hTcxDec->q_old_synth + Scale_sig( &synth_fx[k * L_frame[ch]], add( L_frame[ch], M ), sub( st->hTcxDec->q_old_synth, q_win ) ); // q_win -> st->hTcxDec->q_old_synth Scale_sig( &synthFB_fx[k * L_frameTCX[ch]], add( L_frameTCX[ch], M ), sub( st->hTcxDec->q_old_synth, q_winFB ) ); // q_winFB -> st->hTcxDec->q_old_synth #else IF( ( EQ_16( hCPE->nchan_out, 1 ) && EQ_16( st->hTcxDec->kernel_type[k], MDST_IV ) ) || EQ_16( st->hTcxCfg->tcx_last_overlap_mode, TRANSITION_OVERLAP ) ) @@ -1297,7 +1297,7 @@ void ivas_mdct_core_reconstruct_fx( st->hTcxDec->Q_syn_OverlFB = st->Q_syn; Scale_sig( st->hTcxDec->syn_Overl, L_FRAME32k / 2, sub( st->Q_syn, st->hTcxDec->Q_syn_Overl ) ); // q_win -> st->Q_syn st->hTcxDec->Q_syn_Overl = st->Q_syn; - Scale_sig( synth_buf_fx, add( add( st->hTcxDec->old_synth_len, L_FRAME_PLUS ), M ), sub( q_syn, st->hTcxDec->q_old_synth ) ); // st->hTcxDec->q_old_synth -> q_syn + Scale_sig( synth_buf_fx, add( add( st->hTcxDec->old_synth_len, L_FRAME_PLUS ), M ), sub( q_syn, st->hTcxDec->q_old_synth ) ); // st->hTcxDec->q_old_synth -> q_syn Scale_sig( synth_bufFB_fx, add( add( st->hTcxDec->old_synth_lenFB, L_FRAME_PLUS ), M ), sub( q_syn, st->hTcxDec->q_old_synth ) ); // st->hTcxDec->q_old_synth -> q_syn Scale_sig( st->syn, M + 1, add( st->Q_syn, 2 ) ); #else -- GitLab From 3292aa1527b10f3dce273c9393a3ffe2dc54a4b6 Mon Sep 17 00:00:00 2001 From: Manuel Jander Date: Wed, 14 May 2025 17:22:24 +0200 Subject: [PATCH 044/113] Small improvement of synth_buf scaling and get rid of some magic constants that are not the right ones anymore. --- lib_dec/ivas_mdct_core_dec_fx.c | 75 +++++++++++++++++++++++---------- 1 file changed, 53 insertions(+), 22 deletions(-) diff --git a/lib_dec/ivas_mdct_core_dec_fx.c b/lib_dec/ivas_mdct_core_dec_fx.c index bd20c26d0..5720da8bb 100644 --- a/lib_dec/ivas_mdct_core_dec_fx.c +++ b/lib_dec/ivas_mdct_core_dec_fx.c @@ -1099,10 +1099,8 @@ void ivas_mdct_core_reconstruct_fx( Word16 q_syn = 0; move16(); #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN - Word16 q_win = -2; - move16(); - Word16 q_winFB = -2; - move16(); + Word16 q_win; + Word16 q_winFB; #else #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT Word16 q_win = -1; @@ -1171,15 +1169,19 @@ void ivas_mdct_core_reconstruct_fx( st->hTcxDec->q_old_synth = 0; move16(); } +#ifndef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN Copy( st->hTcxDec->old_synth, synth_buf_fx, st->hTcxDec->old_synth_len ); // Q = st->hTcxDec->q_old_synth Copy_Scale_sig( st->hTcxDec->old_synthFB_fx, synth_bufFB_fx, st->hTcxDec->old_synth_lenFB, sub( st->hTcxDec->q_old_synth, st->Q_syn ) ); // Q = st->hTcxDec->q_old_synth +#endif q_syn = st->hTcxDec->q_old_synth; move16(); set16_fx( synth_fx, 0, L_FRAME_PLUS + M ); set16_fx( synthFB_fx, 0, L_FRAME_PLUS + M ); IF( st->core != ACELP_CORE ) { -#ifndef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN + Word16 q_win0, q_winFB0; +#else Scale_sig( st->hTcxDec->syn_Overl_TDACFB, L_FRAME_MAX / 2, sub( q_win, st->hTcxDec->Q_syn_Overl_TDACFB ) ); // st->hTcxDec->Q_syn_Overl_TDACFB -> q_win st->hTcxDec->Q_syn_Overl_TDACFB = q_win; move16(); @@ -1209,11 +1211,23 @@ void ivas_mdct_core_reconstruct_fx( init_tcx_info_fx( st, L_frame_global[ch], L_frame_globalTCX[ch], k, bfi, &tcx_offset[ch], &tcx_offsetFB[ch], &L_frame[ch], &L_frameTCX[ch], &left_rect[ch], &L_spec[ch] ); +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN + assert( nSubframes[ch] <= 2 ); + q_win0 = q_win; + move16(); + q_winFB0 = q_winFB; + move16(); + q_win = -2; + move16(); + q_winFB = -2; + move16(); +#endif + IF( !skip_decoding ) { +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN test(); test(); -#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN IF( ( EQ_16( hCPE->nchan_out, 1 ) && EQ_16( st->hTcxDec->kernel_type[k], MDST_IV ) ) || EQ_16( st->hTcxCfg->tcx_last_overlap_mode, TRANSITION_OVERLAP ) ) { decoder_tcx_imdct_fx( st, L_frame_global[ch], L_frame_globalTCX[ch], L_spec[ch], tcx_offset[ch], tcx_offsetFB[ch], L_frame[ch], L_frameTCX[ch], left_rect[ch], x_fx[ch][k], q_x, xn_buf_fx, &q_win, &q_winFB, @@ -1224,11 +1238,9 @@ void ivas_mdct_core_reconstruct_fx( decoder_tcx_imdct_fx( st, L_frame_global[ch], L_frame_globalTCX[ch], L_spec[ch], tcx_offset[ch], tcx_offsetFB[ch], L_frame[ch], L_frameTCX[ch], left_rect[ch], x_fx[ch][k], q_x, xn_buf_fx, &q_win, &q_winFB, st->hTcxDec->kernel_type[k], fUseTns[ch][k], &synth_fx[k * L_frame[ch]], &synthFB_fx[k * L_frameTCX[ch]], bfi, k, 0 ); } - - // Need to rescale for each subframe, because q_win/q_winFB might change for the next subframe. Other OLA buffers are rescaled each time. - Scale_sig( &synth_fx[k * L_frame[ch]], add( L_frame[ch], M ), sub( st->hTcxDec->q_old_synth, q_win ) ); // q_win -> st->hTcxDec->q_old_synth - Scale_sig( &synthFB_fx[k * L_frameTCX[ch]], add( L_frameTCX[ch], M ), sub( st->hTcxDec->q_old_synth, q_winFB ) ); // q_winFB -> st->hTcxDec->q_old_synth #else + test(); + test(); IF( ( EQ_16( hCPE->nchan_out, 1 ) && EQ_16( st->hTcxDec->kernel_type[k], MDST_IV ) ) || EQ_16( st->hTcxCfg->tcx_last_overlap_mode, TRANSITION_OVERLAP ) ) { decoder_tcx_imdct_fx( st, L_frame_global[ch], L_frame_globalTCX[ch], L_spec[ch], tcx_offset[ch], tcx_offsetFB[ch], L_frame[ch], L_frameTCX[ch], left_rect[ch], x_fx[ch][k], q_x, xn_buf_fx, q_win, @@ -1265,6 +1277,26 @@ void ivas_mdct_core_reconstruct_fx( } } #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN + + IF ( nSubframes[ch] > 1 ) { + Word16 q_winN, q_winFBN; + + q_winN = s_min( q_win, q_win0 ); + q_winFBN = s_min( q_winFB, q_winFB0 ); + // Need to rescale for each subframe, because q_win/q_winFB might had changed for the next subframe. Other OLA buffers are rescaled each time. + Scale_sig( synth_fx, L_frame[ch], sub( q_winN, q_win0 ) ); // q_win -> st->hTcxDec->q_old_synth + Scale_sig( synthFB_fx, L_frameTCX[ch], sub( q_winFBN, q_winFB0 ) ); // q_winFB -> st->hTcxDec->q_old_synth + Scale_sig( synth_fx + L_frame[ch], add( L_frame[ch], M ), sub( q_winN, q_win ) ); // q_win -> st->hTcxDec->q_old_synth + Scale_sig( synthFB_fx + L_frameTCX[ch], add( L_frameTCX[ch], M ), sub( q_winFBN, q_winFB ) ); // q_winFB -> st->hTcxDec->q_old_synth + q_win = q_winN; + move16(); + q_winFB = q_winFBN; + move16(); + } + + Copy_Scale_sig( st->hTcxDec->old_synth, synth_buf_fx, st->hTcxDec->old_synth_len, sub( q_win, st->hTcxDec->q_old_synth ) ); // Q = st->hTcxDec->q_old_synth + Copy_Scale_sig( st->hTcxDec->old_synthFB_fx, synth_bufFB_fx, st->hTcxDec->old_synth_lenFB, sub( q_winFB, st->Q_syn ) ); + test(); IF( ( bfi == 0 ) && st->hTonalMDCTConc != NULL ) { @@ -1272,18 +1304,17 @@ void ivas_mdct_core_reconstruct_fx( } decoder_tcx_post_ivas_fx( st, synth_fx, synthFB_fx, q_winFB, NULL, bfi, MCT_flag ); + // norm(synth_buf) >= q_syn - q_win + // norm(synth_buf) + q_win >= q_syn sf = s_min( getScaleFactor16( synth_buf_fx, add( add( st->hTcxDec->old_synth_len, L_FRAME_PLUS ), M ) ), getScaleFactor16( synth_bufFB_fx, add( add( st->hTcxDec->old_synth_lenFB, L_FRAME_PLUS ), M ) ) ); - IF( LT_16( sf, 2 ) ) - { - q_syn = sub( sf, 2 ); - st->Q_syn = q_syn; - move16(); - } + q_syn = add( sf, s_min( q_win, q_winFB ) ); + st->Q_syn = q_syn; + move16(); + + // norm(old_out) >= st->Q_syn - q_win + // norm(old_out) + q_win >= st->Q_syn sf = s_min( getScaleFactor16( st->hHQ_core->old_out_fx, L_FRAME48k ), getScaleFactor16( st->hHQ_core->old_out_LB_fx, L_FRAME32k ) ); - IF( LT_16( sf, sub( st->Q_syn, q_win ) ) ) - { - st->Q_syn = add( q_win, sf ); - } + st->Q_syn = add( sf, s_min( q_win, q_winFB ) ); Scale_sig( st->hTcxDec->syn_Overl_TDACFB, L_FRAME_MAX / 2, sub( sub( -1, st->Q_syn ), st->hTcxDec->Q_syn_Overl_TDACFB ) ); // q_winFB -> Q(-1 - st->Q_syn) st->hTcxDec->Q_syn_Overl_TDACFB = sub( -1, st->Q_syn ); @@ -1297,8 +1328,8 @@ void ivas_mdct_core_reconstruct_fx( st->hTcxDec->Q_syn_OverlFB = st->Q_syn; Scale_sig( st->hTcxDec->syn_Overl, L_FRAME32k / 2, sub( st->Q_syn, st->hTcxDec->Q_syn_Overl ) ); // q_win -> st->Q_syn st->hTcxDec->Q_syn_Overl = st->Q_syn; - Scale_sig( synth_buf_fx, add( add( st->hTcxDec->old_synth_len, L_FRAME_PLUS ), M ), sub( q_syn, st->hTcxDec->q_old_synth ) ); // st->hTcxDec->q_old_synth -> q_syn - Scale_sig( synth_bufFB_fx, add( add( st->hTcxDec->old_synth_lenFB, L_FRAME_PLUS ), M ), sub( q_syn, st->hTcxDec->q_old_synth ) ); // st->hTcxDec->q_old_synth -> q_syn + Scale_sig( synth_buf_fx, add( add( st->hTcxDec->old_synth_len, L_FRAME_PLUS ), M ), sub( q_syn, q_win ) ); // st->hTcxDec->q_old_synth -> q_syn + Scale_sig( synth_bufFB_fx, add( add( st->hTcxDec->old_synth_lenFB, L_FRAME_PLUS ), M ), sub( q_syn, q_winFB ) ); // st->hTcxDec->q_old_synth -> q_syn Scale_sig( st->syn, M + 1, add( st->Q_syn, 2 ) ); #else test(); -- GitLab From c1f1d26f60d97674df28fbe160514a335cca2ad6 Mon Sep 17 00:00:00 2001 From: Manuel Jander Date: Wed, 14 May 2025 17:25:01 +0200 Subject: [PATCH 045/113] clang format --- lib_dec/ivas_mdct_core_dec_fx.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lib_dec/ivas_mdct_core_dec_fx.c b/lib_dec/ivas_mdct_core_dec_fx.c index 5720da8bb..0e36179e4 100644 --- a/lib_dec/ivas_mdct_core_dec_fx.c +++ b/lib_dec/ivas_mdct_core_dec_fx.c @@ -1278,15 +1278,16 @@ void ivas_mdct_core_reconstruct_fx( } #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN - IF ( nSubframes[ch] > 1 ) { + IF( nSubframes[ch] > 1 ) + { Word16 q_winN, q_winFBN; q_winN = s_min( q_win, q_win0 ); q_winFBN = s_min( q_winFB, q_winFB0 ); // Need to rescale for each subframe, because q_win/q_winFB might had changed for the next subframe. Other OLA buffers are rescaled each time. - Scale_sig( synth_fx, L_frame[ch], sub( q_winN, q_win0 ) ); // q_win -> st->hTcxDec->q_old_synth - Scale_sig( synthFB_fx, L_frameTCX[ch], sub( q_winFBN, q_winFB0 ) ); // q_winFB -> st->hTcxDec->q_old_synth - Scale_sig( synth_fx + L_frame[ch], add( L_frame[ch], M ), sub( q_winN, q_win ) ); // q_win -> st->hTcxDec->q_old_synth + Scale_sig( synth_fx, L_frame[ch], sub( q_winN, q_win0 ) ); // q_win -> st->hTcxDec->q_old_synth + Scale_sig( synthFB_fx, L_frameTCX[ch], sub( q_winFBN, q_winFB0 ) ); // q_winFB -> st->hTcxDec->q_old_synth + Scale_sig( synth_fx + L_frame[ch], add( L_frame[ch], M ), sub( q_winN, q_win ) ); // q_win -> st->hTcxDec->q_old_synth Scale_sig( synthFB_fx + L_frameTCX[ch], add( L_frameTCX[ch], M ), sub( q_winFBN, q_winFB ) ); // q_winFB -> st->hTcxDec->q_old_synth q_win = q_winN; move16(); @@ -1294,7 +1295,7 @@ void ivas_mdct_core_reconstruct_fx( move16(); } - Copy_Scale_sig( st->hTcxDec->old_synth, synth_buf_fx, st->hTcxDec->old_synth_len, sub( q_win, st->hTcxDec->q_old_synth ) ); // Q = st->hTcxDec->q_old_synth + Copy_Scale_sig( st->hTcxDec->old_synth, synth_buf_fx, st->hTcxDec->old_synth_len, sub( q_win, st->hTcxDec->q_old_synth ) ); // Q = st->hTcxDec->q_old_synth Copy_Scale_sig( st->hTcxDec->old_synthFB_fx, synth_bufFB_fx, st->hTcxDec->old_synth_lenFB, sub( q_winFB, st->Q_syn ) ); test(); @@ -1328,7 +1329,7 @@ void ivas_mdct_core_reconstruct_fx( st->hTcxDec->Q_syn_OverlFB = st->Q_syn; Scale_sig( st->hTcxDec->syn_Overl, L_FRAME32k / 2, sub( st->Q_syn, st->hTcxDec->Q_syn_Overl ) ); // q_win -> st->Q_syn st->hTcxDec->Q_syn_Overl = st->Q_syn; - Scale_sig( synth_buf_fx, add( add( st->hTcxDec->old_synth_len, L_FRAME_PLUS ), M ), sub( q_syn, q_win ) ); // st->hTcxDec->q_old_synth -> q_syn + Scale_sig( synth_buf_fx, add( add( st->hTcxDec->old_synth_len, L_FRAME_PLUS ), M ), sub( q_syn, q_win ) ); // st->hTcxDec->q_old_synth -> q_syn Scale_sig( synth_bufFB_fx, add( add( st->hTcxDec->old_synth_lenFB, L_FRAME_PLUS ), M ), sub( q_syn, q_winFB ) ); // st->hTcxDec->q_old_synth -> q_syn Scale_sig( st->syn, M + 1, add( st->Q_syn, 2 ) ); #else -- GitLab From 0f73e249c0a13909a13d4814b07640956c66c1fe Mon Sep 17 00:00:00 2001 From: Manuel Jander Date: Wed, 14 May 2025 18:03:21 +0200 Subject: [PATCH 046/113] Fix uninitialized memory in BFI case. --- lib_dec/ivas_mdct_core_dec_fx.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib_dec/ivas_mdct_core_dec_fx.c b/lib_dec/ivas_mdct_core_dec_fx.c index 0e36179e4..1776f82e8 100644 --- a/lib_dec/ivas_mdct_core_dec_fx.c +++ b/lib_dec/ivas_mdct_core_dec_fx.c @@ -1384,6 +1384,10 @@ void ivas_mdct_core_reconstruct_fx( } ELSE /*ACELP core for ACELP-PLC */ { +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN + Copy( st->hTcxDec->old_synth, synth_buf_fx, st->hTcxDec->old_synth_len ); // Q = st->hTcxDec->q_old_synth + Copy_Scale_sig( st->hTcxDec->old_synthFB_fx, synth_bufFB_fx, st->hTcxDec->old_synth_lenFB, sub( st->hTcxDec->q_old_synth, st->Q_syn ) ); // Q = st->hTcxDec->q_old_synth +#endif assert( EQ_16( st->bfi, 1 ) ); /* PLC: [TCX: TD PLC] */ IF( MCT_flag != 0 ) -- GitLab From 0bab7023b415c556ad5ba898472b6ce2cad2347f Mon Sep 17 00:00:00 2001 From: Manuel Jander Date: Thu, 15 May 2025 10:40:04 +0200 Subject: [PATCH 047/113] Increase headroom for ACELP ZIR in TCX/ACELP transition. --- lib_dec/dec_tcx_fx.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index 1eee95a3b..1553664d5 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -3450,7 +3450,18 @@ void IMDCT_ivas_fx( acelp_mem_len = 0; move16(); } + #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN + IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && ( LE_32( st->last_core_brate, SID_2k40 ) || st->last_core == ACELP_CORE ) && ( fullbandScale == 0 ) ) + { + /* Increase headroom because if the ACELP ZIR is used below, the synthesis filter gain is unknown. */ + IF ( allow_qwin_change ) { + allow_qwin_change = 0; + move16(); + q_win = s_max( -2, sub( q_win, 2 ) ); + } + } + IF( EQ_16( kernel_type, MDST_IV ) ) { TCX_MDST_Inverse_qwin_fx( x_fx, x_e_hdrm, xn_buf_fx, overlap, L_frame - overlap, overlap, &q_win, allow_qwin_change ); -- GitLab From f67e5519cf5d942a4064961c1cc638d8a12b7215 Mon Sep 17 00:00:00 2001 From: Manuel Jander Date: Thu, 15 May 2025 10:47:14 +0200 Subject: [PATCH 048/113] clang format --- lib_dec/dec_tcx_fx.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index 1553664d5..2637f52d7 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -3455,7 +3455,8 @@ void IMDCT_ivas_fx( IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && ( LE_32( st->last_core_brate, SID_2k40 ) || st->last_core == ACELP_CORE ) && ( fullbandScale == 0 ) ) { /* Increase headroom because if the ACELP ZIR is used below, the synthesis filter gain is unknown. */ - IF ( allow_qwin_change ) { + IF( allow_qwin_change ) + { allow_qwin_change = 0; move16(); q_win = s_max( -2, sub( q_win, 2 ) ); -- GitLab From 3fa130bab9a069fe719266955e142002ab8e3253 Mon Sep 17 00:00:00 2001 From: Manuel Jander Date: Thu, 15 May 2025 15:17:39 +0200 Subject: [PATCH 049/113] Correct asignments of Q_syn_OverlFB which was wrong or missing at some places. --- lib_dec/core_dec_init_fx.c | 17 ++++++++++++++++- lib_dec/er_dec_acelp_fx.c | 4 ++++ lib_dec/er_dec_tcx_fx.c | 20 ++++++++++++++++++++ lib_dec/evs_dec_fx.c | 2 +- lib_dec/ivas_core_dec_fx.c | 3 ++- lib_dec/ivas_mdct_core_dec_fx.c | 12 ++++++------ lib_dec/ivas_stereo_switching_dec_fx.c | 4 ++++ 7 files changed, 53 insertions(+), 9 deletions(-) diff --git a/lib_dec/core_dec_init_fx.c b/lib_dec/core_dec_init_fx.c index 3ddecdbd5..b83fa8398 100644 --- a/lib_dec/core_dec_init_fx.c +++ b/lib_dec/core_dec_init_fx.c @@ -396,8 +396,15 @@ void open_decoder_LPD_fx( move16(); Copy( hHQ_core->fer_samples_fx + delay_comp, hTcxDec->syn_OverlFB, shr( hTcxDec->L_frameTCX, 1 ) ); /* hHQ_core->Q_fer_samples*/ - +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT + hTcxDec->Q_syn_OverlFB = hHQ_core->Q_fer_samples; + move16(); +#endif lerp( hHQ_core->fer_samples_fx + delay_comp, hTcxDec->syn_Overl, shr( st->L_frame, 1 ), shr( hTcxDec->L_frameTCX, 1 ) ); /*Q0: ACELP(bfi)->TCX(rect)*/ +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT + hTcxDec->Q_syn_Overl = hHQ_core->Q_fer_samples; + move16(); +#endif /*old_out needed for MODE1 routine and syn_Overl_TDAC for MODE2 routine*/ hHQ_core->Q_old_wtda = -1; @@ -1070,7 +1077,15 @@ void acelp_plc_mdct_transition_fx( move16(); /*CLDFB delay*/ Copy( st->hHQ_core->fer_samples_fx + delay_comp, st->hTcxDec->syn_OverlFB, shr( st->hTcxDec->L_frameTCX, 1 ) ); /* Q_fer_samples */ +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT + st->hTcxDec->Q_syn_OverlFB = st->hHQ_core->Q_fer_samples; + move16(); +#endif lerp( st->hHQ_core->fer_samples_fx + delay_comp, st->hTcxDec->syn_Overl, shr( st->L_frame, 1 ), shr( st->hTcxDec->L_frameTCX, 1 ) ); /*ACELP(bfi)->TCX(rect)*/ +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT + st->hTcxDec->Q_syn_Overl = st->hHQ_core->Q_fer_samples; + move16(); +#endif /*old_out needed for MODE1 routine and syn_Overl_TDAC for MODE2 routine*/ st->hHQ_core->Q_old_wtda = -1; move16(); diff --git a/lib_dec/er_dec_acelp_fx.c b/lib_dec/er_dec_acelp_fx.c index e1321d9aa..bcbff9b76 100644 --- a/lib_dec/er_dec_acelp_fx.c +++ b/lib_dec/er_dec_acelp_fx.c @@ -1104,6 +1104,10 @@ void con_acelp_fx( st->hTcxDec->Q_syn_Overl_TDACFB = st->hTcxDec->Q_syn_Overl_TDAC; move16(); lerp( hTcxDec->syn_Overl, hTcxDec->syn_OverlFB, shr( hTcxDec->L_frameTCX, 1 ), shr( st->L_frame, 1 ) ); +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT + hTcxDec->Q_syn_OverlFB = hTcxDec->Q_syn_Overl; + move16(); +#endif lerp( hHQ_core->old_out_LB_fx, hHQ_core->old_out_fx, hTcxDec->L_frameTCX, st->L_frame ); #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT hHQ_core->Q_old_wtda = hHQ_core->Q_old_wtda_LB; diff --git a/lib_dec/er_dec_tcx_fx.c b/lib_dec/er_dec_tcx_fx.c index f5b8a1359..912bd9e9d 100644 --- a/lib_dec/er_dec_tcx_fx.c +++ b/lib_dec/er_dec_tcx_fx.c @@ -910,7 +910,13 @@ void con_tcx_fx( bufferCopyFx( syn, synth, L_frame, Q_syn, 0, 0, 0 ); /*Q_syn*/ BASOP_SATURATE_WARNING_ON_EVS +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT + Copy_Scale_sig( syn + L_frame, hTcxDec->syn_OverlFB, shr( L_frame, 1 ), sub( 0, Q_syn ) ); /*Q0*/ + hTcxDec->Q_syn_OverlFB = 0; + move16(); +#else Copy_Scale_sig( syn + L_frame, hTcxDec->syn_OverlFB, shr( L_frame, 1 ), negate( Q_syn ) ); /*Q0*/ +#endif /* copy total excitation exc2 as 16kHz for acelp mode1 decoding */ IF( st->hWIDec != NULL ) @@ -973,6 +979,10 @@ void con_tcx_fx( /* update memory for low band */ Scale_sig( hTcxDec->old_syn_Overl, shr( st->L_frame, 1 ), sub( -1, Q_syn ) ); /*Q_syn*/ lerp( hTcxDec->syn_OverlFB, hTcxDec->syn_Overl, shr( st->L_frame, 1 ), shr( L_frame, 1 ) ); +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT + hTcxDec->Q_syn_Overl = hTcxDec->Q_syn_OverlFB; + move16(); +#endif lerp( hTcxDec->syn_Overl_TDACFB, hTcxDec->syn_Overl_TDAC, shr( st->L_frame, 1 ), shr( L_frame, 1 ) ); hTcxDec->Q_syn_Overl_TDAC = hTcxDec->Q_syn_Overl_TDACFB; move16(); @@ -1865,7 +1875,13 @@ void con_tcx_ivas_fx( bufferCopyFx( syn, synth, L_frame, Q_syn, 0, 0, 0 ); /*Q_syn*/ BASOP_SATURATE_WARNING_ON_EVS +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT + Copy_Scale_sig( syn + L_frame, hTcxDec->syn_OverlFB, shr( L_frame, 1 ), sub( 0, Q_syn ) ); /*Q0*/ + hTcxDec->Q_syn_OverlFB = 0; + move16(); +#else Copy_Scale_sig( syn + L_frame, hTcxDec->syn_OverlFB, shr( L_frame, 1 ), negate( Q_syn ) ); /*Q0*/ +#endif /* copy total excitation exc2 as 16kHz for acelp mode1 decoding */ IF( st->hWIDec != NULL ) @@ -1934,6 +1950,10 @@ void con_tcx_ivas_fx( st->hTcxDec->Q_old_syn_Overl = -1; #endif lerp( hTcxDec->syn_OverlFB, hTcxDec->syn_Overl, shr( st->L_frame, 1 ), shr( L_frame, 1 ) ); +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT + hTcxDec->Q_syn_Overl = hTcxDec->Q_syn_OverlFB; + move16(); +#endif lerp( hTcxDec->syn_Overl_TDACFB, hTcxDec->syn_Overl_TDAC, shr( st->L_frame, 1 ), shr( L_frame, 1 ) ); hTcxDec->Q_syn_Overl_TDAC = hTcxDec->Q_syn_Overl_TDACFB; move16(); diff --git a/lib_dec/evs_dec_fx.c b/lib_dec/evs_dec_fx.c index 9f08a281b..38bd7de24 100644 --- a/lib_dec/evs_dec_fx.c +++ b/lib_dec/evs_dec_fx.c @@ -167,7 +167,7 @@ ivas_error evs_dec_fx( tmp1 = extract_l( L_shr_r( f, s ) ); /*Q14 - s*/ FOR( i = 0; i < st_fx->hTcxCfg->tcx_mdct_window_lengthFB; i++ ) { - hTcxDec->syn_OverlFB[i] = shl_sat( mult_sat( tmp1, hTcxDec->syn_OverlFB[i] ), add( s, 1 ) ); /*hTcxDec->Q_syn_Overl*/ + hTcxDec->syn_OverlFB[i] = shl_sat( mult_sat( tmp1, hTcxDec->syn_OverlFB[i] ), add( s, 1 ) ); /*hTcxDec->Q_syn_OverlFB*/ move16(); } s = norm_l( f ); diff --git a/lib_dec/ivas_core_dec_fx.c b/lib_dec/ivas_core_dec_fx.c index a27213b6e..e4fb48f4a 100644 --- a/lib_dec/ivas_core_dec_fx.c +++ b/lib_dec/ivas_core_dec_fx.c @@ -707,6 +707,7 @@ ivas_error ivas_core_dec_fx( st->hHQ_core->Q_fer_samples = 0; move16(); } +#ifndef FIX_1348_BIT_PRECISION_IMPROVEMENT IF( NE_16( st->core, st->last_core ) ) { IF( st->hTcxDec ) @@ -716,7 +717,7 @@ ivas_error ivas_core_dec_fx( st->Q_syn = 0; move16(); } - +#endif st->prev_Q_syn = st->Q_syn; move16(); diff --git a/lib_dec/ivas_mdct_core_dec_fx.c b/lib_dec/ivas_mdct_core_dec_fx.c index 1776f82e8..e66704cd2 100644 --- a/lib_dec/ivas_mdct_core_dec_fx.c +++ b/lib_dec/ivas_mdct_core_dec_fx.c @@ -1295,8 +1295,8 @@ void ivas_mdct_core_reconstruct_fx( move16(); } - Copy_Scale_sig( st->hTcxDec->old_synth, synth_buf_fx, st->hTcxDec->old_synth_len, sub( q_win, st->hTcxDec->q_old_synth ) ); // Q = st->hTcxDec->q_old_synth - Copy_Scale_sig( st->hTcxDec->old_synthFB_fx, synth_bufFB_fx, st->hTcxDec->old_synth_lenFB, sub( q_winFB, st->Q_syn ) ); + Copy_Scale_sig( st->hTcxDec->old_synth, synth_buf_fx, st->hTcxDec->old_synth_len, sub( q_win, st->hTcxDec->q_old_synth ) ); // q_win + Copy_Scale_sig( st->hTcxDec->old_synthFB_fx, synth_bufFB_fx, st->hTcxDec->old_synth_lenFB, sub( q_winFB, st->Q_syn ) ); // q_winFB test(); IF( ( bfi == 0 ) && st->hTonalMDCTConc != NULL ) @@ -1331,7 +1331,8 @@ void ivas_mdct_core_reconstruct_fx( st->hTcxDec->Q_syn_Overl = st->Q_syn; Scale_sig( synth_buf_fx, add( add( st->hTcxDec->old_synth_len, L_FRAME_PLUS ), M ), sub( q_syn, q_win ) ); // st->hTcxDec->q_old_synth -> q_syn Scale_sig( synth_bufFB_fx, add( add( st->hTcxDec->old_synth_lenFB, L_FRAME_PLUS ), M ), sub( q_syn, q_winFB ) ); // st->hTcxDec->q_old_synth -> q_syn - Scale_sig( st->syn, M + 1, add( st->Q_syn, 2 ) ); + //Scale_sig( st->syn, M + 1, add( st->Q_syn, 2 ) ); + Scale_sig( st->syn, M + 1, sub( st->Q_syn, q_win ) ); #else test(); IF( ( bfi == 0 ) && st->hTonalMDCTConc != NULL ) @@ -1377,9 +1378,8 @@ void ivas_mdct_core_reconstruct_fx( move16(); #endif #endif -#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD - Scale_sig( st->mem_syn2_fx, M, sub( -2, q_win ) ); - // Scale_sig( st->mem_syn2_fx, M, sub( st->Q_syn, q_win ) ); // q_win -> Q_syn +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD_NO + Scale_sig( st->mem_syn2_fx, M, sub( st->Q_syn, q_win ) ); // q_win -> Q_syn #endif } ELSE /*ACELP core for ACELP-PLC */ diff --git a/lib_dec/ivas_stereo_switching_dec_fx.c b/lib_dec/ivas_stereo_switching_dec_fx.c index 454395648..706b9b568 100644 --- a/lib_dec/ivas_stereo_switching_dec_fx.c +++ b/lib_dec/ivas_stereo_switching_dec_fx.c @@ -68,6 +68,10 @@ static ivas_error allocate_CoreCoder_TCX_fx( reset_tcx_overl_buf_fx( st->hTcxDec ); // st->hTcxDec->CngLevelBackgroundTrace_bfi = 0; //initializing to avoid garbage overflow; set16_fx( st->hTcxDec->syn_OverlFB, 0, L_FRAME48k / 2 ); +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT + st->hTcxDec->Q_syn_OverlFB = 0; + move16(); +#endif set16_fx( st->hTcxDec->old_synth, 0, OLD_SYNTH_INTERNAL_DEC ); st->hTcxDec->q_old_synth = 0; move16(); -- GitLab From dfc50802bda62c6b840317904bc9b11c45ff1c16 Mon Sep 17 00:00:00 2001 From: Manuel Jander Date: Thu, 15 May 2025 15:20:32 +0200 Subject: [PATCH 050/113] clang format --- lib_dec/core_dec_init_fx.c | 2 +- lib_dec/ivas_mdct_core_dec_fx.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib_dec/core_dec_init_fx.c b/lib_dec/core_dec_init_fx.c index b83fa8398..d5a1dfeb0 100644 --- a/lib_dec/core_dec_init_fx.c +++ b/lib_dec/core_dec_init_fx.c @@ -1076,7 +1076,7 @@ void acelp_plc_mdct_transition_fx( delay_comp = NS2SA_FX2( st->output_Fs, DELAY_CLDFB_NS ); move16(); /*CLDFB delay*/ - Copy( st->hHQ_core->fer_samples_fx + delay_comp, st->hTcxDec->syn_OverlFB, shr( st->hTcxDec->L_frameTCX, 1 ) ); /* Q_fer_samples */ + Copy( st->hHQ_core->fer_samples_fx + delay_comp, st->hTcxDec->syn_OverlFB, shr( st->hTcxDec->L_frameTCX, 1 ) ); /* Q_fer_samples */ #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT st->hTcxDec->Q_syn_OverlFB = st->hHQ_core->Q_fer_samples; move16(); diff --git a/lib_dec/ivas_mdct_core_dec_fx.c b/lib_dec/ivas_mdct_core_dec_fx.c index e66704cd2..2940a169b 100644 --- a/lib_dec/ivas_mdct_core_dec_fx.c +++ b/lib_dec/ivas_mdct_core_dec_fx.c @@ -1331,7 +1331,7 @@ void ivas_mdct_core_reconstruct_fx( st->hTcxDec->Q_syn_Overl = st->Q_syn; Scale_sig( synth_buf_fx, add( add( st->hTcxDec->old_synth_len, L_FRAME_PLUS ), M ), sub( q_syn, q_win ) ); // st->hTcxDec->q_old_synth -> q_syn Scale_sig( synth_bufFB_fx, add( add( st->hTcxDec->old_synth_lenFB, L_FRAME_PLUS ), M ), sub( q_syn, q_winFB ) ); // st->hTcxDec->q_old_synth -> q_syn - //Scale_sig( st->syn, M + 1, add( st->Q_syn, 2 ) ); + // Scale_sig( st->syn, M + 1, add( st->Q_syn, 2 ) ); Scale_sig( st->syn, M + 1, sub( st->Q_syn, q_win ) ); #else test(); -- GitLab From 9794aa2354b81a26a823e6d62f76051849667e8b Mon Sep 17 00:00:00 2001 From: Manuel Jander Date: Thu, 15 May 2025 17:28:28 +0200 Subject: [PATCH 051/113] Increase headroom in q_win calculation. Fixes regression for MASA_2dir_2TC_bitrate_switching_from_13_2_kbps_to_512_kbps_48kHz_in_48kHz_out_EXT_out_JBM_Prof_5 --- lib_dec/dec_tcx_fx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index 2637f52d7..b51493262 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -3396,7 +3396,7 @@ void IMDCT_ivas_fx( // sub( q_xn_buf_fx_32, q_win ) == 16 - L_norm_arr( xn_buf_fx_32, L_frame ) // q_xn_buf_fx_32 - q_win == 16 - L_norm_arr( xn_buf_fx_32, L_frame ) // q_win == - 16 + L_norm_arr( xn_buf_fx_32, L_frame ) + q_xn_buf_fx_32 - q_win = s_min( q_win, add( sub( q_xn_buf_fx_32, 16 ), L_norm_arr( xn_buf_fx_32, L_frame ) ) - 1 ); + q_win = s_min( q_win, add( sub( q_xn_buf_fx_32, 16 ), L_norm_arr( xn_buf_fx_32, L_frame ) ) - 2 ); } IMDCT_ivas_fx_rescale( syn_Overl_TDAC_fx, Q_syn_Overl_TDAC_fx, old_syn_overl_fx, Q_old_syn_overl_fx, hTcxDec->old_syn_Overl, &hTcxDec->Q_old_syn_Overl, old_out_fx, q_old_out_fx, q_win, FB_flag ); #endif -- GitLab From 5203c88f1e2dde214c63cb3811ff6160652c3042 Mon Sep 17 00:00:00 2001 From: Manuel Jander Date: Tue, 20 May 2025 10:04:03 +0200 Subject: [PATCH 052/113] Increase headroom for Q_syn, fixes regression in +10dB case Multi_channel_5_1_at_384_kbps_48kHz_in_48kHz_out_7_1_4_out_JBM_Prof_5. --- lib_dec/ivas_mdct_core_dec_fx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_dec/ivas_mdct_core_dec_fx.c b/lib_dec/ivas_mdct_core_dec_fx.c index 2940a169b..0cec3dd72 100644 --- a/lib_dec/ivas_mdct_core_dec_fx.c +++ b/lib_dec/ivas_mdct_core_dec_fx.c @@ -1308,7 +1308,7 @@ void ivas_mdct_core_reconstruct_fx( // norm(synth_buf) >= q_syn - q_win // norm(synth_buf) + q_win >= q_syn sf = s_min( getScaleFactor16( synth_buf_fx, add( add( st->hTcxDec->old_synth_len, L_FRAME_PLUS ), M ) ), getScaleFactor16( synth_bufFB_fx, add( add( st->hTcxDec->old_synth_lenFB, L_FRAME_PLUS ), M ) ) ); - q_syn = add( sf, s_min( q_win, q_winFB ) ); + q_syn = add( sub( sf, 1 ), s_min( q_win, q_winFB ) ); st->Q_syn = q_syn; move16(); -- GitLab From e8218c37649e47fd0e6579797e0a522c86f85c6c Mon Sep 17 00:00:00 2001 From: vaclav Date: Thu, 17 Apr 2025 15:49:28 +0200 Subject: [PATCH 053/113] accept REMOVE_EVS_DUPLICATES --- Workspace_msvc/lib_dec.vcxproj | 3 - Workspace_msvc/lib_dec.vcxproj.filters | 3 - lib_com/bits_alloc_fx.c | 1313 +-------------- lib_com/gs_inact_switching_fx.c | 134 +- lib_com/gs_noisefill_fx.c | 10 +- lib_com/ivas_prot_fx.h | 2 +- lib_com/lsf_tools_fx.c | 220 +-- lib_com/options.h | 2 +- lib_com/prot_fx.h | 577 ++----- lib_com/swb_tbe_com_fx.c | 247 +-- lib_dec/FEC_fx.c | 15 +- lib_dec/FEC_scale_syn_fx.c | 574 +------ lib_dec/acelp_core_dec_fx.c | 2075 +++++++++++++++++------- lib_dec/acelp_core_dec_ivas_fx.c | 107 +- lib_dec/acelp_core_switch_dec_fx.c | 12 +- lib_dec/amr_wb_dec_fx.c | 33 +- lib_dec/cng_dec_fx.c | 683 +------- lib_dec/dec_LPD_fx.c | 4 - lib_dec/dec_ace_fx.c | 22 +- lib_dec/dec_amr_wb_fx.c | 6 +- lib_dec/dec_gen_voic_fx.c | 534 +----- lib_dec/dec_pit_exc_fx.c | 432 +---- lib_dec/dec_post_fx.c | 241 +-- lib_dec/dec_ppp_fx.c | 17 +- lib_dec/dec_tran_fx.c | 12 +- lib_dec/dec_uv_fx.c | 100 +- lib_dec/evs_dec_fx.c | 12 +- lib_dec/fd_cng_dec_fx.c | 485 +----- lib_dec/gain_dec_fx.c | 390 +---- lib_dec/gs_dec_fx.c | 693 +------- lib_dec/ivas_core_dec_fx.c | 2 +- lib_dec/ivas_stereo_mdct_core_dec_fx.c | 4 +- lib_dec/ivas_tcx_core_dec_fx.c | 7 +- lib_dec/ivas_td_low_rate_dec_fx.c | 20 +- lib_dec/lsf_dec_fx.c | 276 +--- lib_dec/pit_dec_fx.c | 256 +-- lib_dec/post_dec_fx.c | 18 +- lib_enc/acelp_core_enc_fx.c | 40 +- lib_enc/acelp_core_switch_enc_fx.c | 37 +- lib_enc/analy_lp_fx.c | 150 +- lib_enc/cod_ace_fx.c | 11 +- lib_enc/enc_gen_voic_fx.c | 23 +- lib_enc/enc_tran_fx.c | 15 +- lib_enc/ivas_core_pre_proc_front_fx.c | 7 +- lib_enc/ivas_core_pre_proc_fx.c | 13 +- lib_enc/ivas_front_vad_fx.c | 6 +- lib_enc/ivas_td_low_rate_enc_fx.c | 4 +- lib_enc/lsf_enc_fx.c | 7 +- lib_enc/pre_proc_fx.c | 14 +- lib_enc/prot_fx_enc.h | 104 +- lib_enc/transition_enc_fx.c | 41 +- 51 files changed, 2129 insertions(+), 7884 deletions(-) diff --git a/Workspace_msvc/lib_dec.vcxproj b/Workspace_msvc/lib_dec.vcxproj index 2d06d29aa..2839a5812 100644 --- a/Workspace_msvc/lib_dec.vcxproj +++ b/Workspace_msvc/lib_dec.vcxproj @@ -139,9 +139,6 @@ false - - false - diff --git a/Workspace_msvc/lib_dec.vcxproj.filters b/Workspace_msvc/lib_dec.vcxproj.filters index 8a4fc4605..ebf15bd4c 100644 --- a/Workspace_msvc/lib_dec.vcxproj.filters +++ b/Workspace_msvc/lib_dec.vcxproj.filters @@ -119,9 +119,6 @@ decoder_all_c - - decoder_all_c - decoder_all_c diff --git a/lib_com/bits_alloc_fx.c b/lib_com/bits_alloc_fx.c index e9abb7651..3bfcd0c20 100644 --- a/lib_com/bits_alloc_fx.c +++ b/lib_com/bits_alloc_fx.c @@ -434,174 +434,12 @@ static Word16 fcb_table( } /*-------------------------------------------------------------------* - * acelp_FCB_allocator() + * acelp_FCB_allocator_fx() * * Routine to allocate fixed innovation codebook bit-budget *--------------------------------------------------------------------*/ -#ifndef REMOVE_EVS_DUPLICATES -static ivas_error acelp_FCB_allocator( - Word16 *nBits, /* i/o: available bit-budget */ - Word16 fixed_cdk_index[], /* o : codebook index Q0 */ - Word16 nb_subfr, /* i : number of subframes */ - const Word16 L_subfr, /* i : subframe length */ - const Word16 coder_type, /* i : coder type */ - const Word16 tc_subfr, /* i : TC subframe index */ - const Word16 fix_first /* i : flag to indicate whether the first subframe bit-budget was fixed */ -) -{ - Word16 cdbk, sfr, step; - Word16 nBits_tmp; - Word16 *p_fixed_cdk_index; - Word16 max_n; - ivas_error error; - // PMT("Not floating point computation, but fixed point operator are still missing ") - - error = IVAS_ERR_OK; - move32(); - - cdbk = coder_type; /* just to avoid warning when DEBUGGING is deactivated */ - move16(); - - p_fixed_cdk_index = fixed_cdk_index; - - /* TRANSITION coding: first subframe bit-budget was already fixed, glottal pulse not in the first subframe */ - test(); - IF( GE_16( tc_subfr, L_SUBFR ) && fix_first ) - { - Word16 i; - - FOR( i = 0; i < nb_subfr; i++ ) - { - *nBits = sub( *nBits, ACELP_FIXED_CDK_BITS( fixed_cdk_index[i] ) ); - move16(); - } - return error; - } - - /* TRANSITION coding: first subframe bit-budget was already fixed, glottal pulse in the first subframe */ - sfr = 0; - move16(); - IF( fix_first ) - { - *nBits = sub( *nBits, ACELP_FIXED_CDK_BITS( fixed_cdk_index[0] ) ); - move16(); - sfr = 1; - move16(); - p_fixed_cdk_index++; - nb_subfr = 3; - move16(); - } - - /* distribute the bit-budget equally between subframes */ - IF( GT_16( L_subfr, L_SUBFR ) ) /* access fast_FCB_bits_2sfr */ - { - max_n = 6; - move16(); - } - ELSE - { - max_n = ACELP_FIXED_CDK_NB; - move16(); - } - FOR( cdbk = 0; cdbk < max_n; cdbk++ ) - { - IF( GT_32( L_mult0( fcb_table( cdbk, L_subfr ), nb_subfr ), L_deposit_l( *nBits ) ) ) - { - BREAK; - } - } - cdbk = sub( cdbk, 1 ); - -#ifdef DEBUGGING - if ( cdbk < 0 && coder_type != TRANSITION ) - { - return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Error: Too low bit-budget for fixed innovation codebook (frame = %d). Exiting! \n" ); - } - if ( ( L_subfr == L_SUBFR && cdbk >= ACELP_FIXED_CDK_NB ) || ( L_subfr == 2 * L_SUBFR && fcb_table( cdbk, L_subfr ) == 128 /*stop value*/ ) ) - { - return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Error: Too high bit-budget for fixed innovation codebook (frame = %d). Exiting! \n" ); - } -#endif - - set16_fx( p_fixed_cdk_index, cdbk, nb_subfr ); - nBits_tmp = 0; - move16(); - IF( cdbk >= 0 ) - { - nBits_tmp = fcb_table( cdbk, L_subfr ); - } - ELSE - { - nBits_tmp = 0; - move16(); - } - *nBits = sub( *nBits, i_mult( nBits_tmp, nb_subfr ) ); - move16(); - - /* try to increase the FCB bit-budget of the first subframe(s) */ - IF( LT_16( cdbk, ACELP_FIXED_CDK_NB - 1 ) ) - { - step = sub( fcb_table( add( cdbk, 1 ), L_subfr ), nBits_tmp ); - WHILE( *nBits >= step ) - { - ( *p_fixed_cdk_index )++; - *nBits = sub( *nBits, step ); - move16(); - p_fixed_cdk_index++; - } - - /* try to increase the FCB of the first subframe in cases when the next step is lower than the current step */ - step = sub( fcb_table( add( fixed_cdk_index[sfr], 1 ), L_subfr ), fcb_table( fixed_cdk_index[sfr], L_subfr ) ); - test(); - IF( GE_16( *nBits, step ) && cdbk >= 0 ) - { - fixed_cdk_index[sfr] = add( fixed_cdk_index[sfr], 1 ); - move16(); - *nBits = sub( *nBits, step ); - move16(); - test(); - IF( GE_16( *nBits, step ) && EQ_16( fixed_cdk_index[sfr + 1], sub( fixed_cdk_index[sfr], 1 ) ) ) - { - sfr = add( sfr, 1 ); - fixed_cdk_index[sfr] = add( fixed_cdk_index[sfr], 1 ); - move16(); - *nBits = sub( *nBits, step ); - move16(); - } - } - } - /* TRANSITION coding: allocate highest FCBQ bit-budget to the subframe with the glottal-shape codebook */ - IF( GE_16( tc_subfr, L_SUBFR ) ) - { - Word16 tempr; - - SWAP( fixed_cdk_index[0], fixed_cdk_index[tc_subfr / L_SUBFR] ); - - /* TRANSITION coding: allocate second highest FCBQ bit-budget to the last subframe */ - IF( idiv1616( tc_subfr, L_SUBFR ) < sub( nb_subfr, 1 ) ) - { - SWAP( fixed_cdk_index[( tc_subfr - L_SUBFR ) / L_SUBFR], fixed_cdk_index[nb_subfr - 1] ); - } - } - - /* when subframe length > L_SUBFR, number of bits instead of codebook index is signalled */ - IF( GT_16( L_subfr, L_SUBFR ) ) - { - Word16 i, j; - FOR( i = 0; i < nb_subfr; i++ ) - { - j = fixed_cdk_index[i]; - move16(); - fixed_cdk_index[i] = fast_FCB_bits_2sfr[j]; - move16(); - } - } - - return error; -} -#endif -static ivas_error acelp_FCB_allocator_ivas( +static ivas_error acelp_FCB_allocator_fx( Word16 *nBits, /* i/o: available bit-budget */ Word16 fixed_cdk_index[], /* o : codebook index Q0 */ Word16 nb_subfr, /* i : number of subframes */ @@ -754,1141 +592,16 @@ static ivas_error acelp_FCB_allocator_ivas( return error; } + /*-------------------------------------------------------------------* - * config_acelp1() + * config_acelp1_fx() * * Configure ACELP bit allocation * - should be in range of <6700; 24350> for ACELP@12.8kHz * - per channel bitrate minimum is 13250 kbps for ACELP@16kHz *--------------------------------------------------------------------*/ -#ifndef REMOVE_EVS_DUPLICATES -ivas_error config_acelp1( - const Word16 enc_dec, /* i : encoder/decoder flag */ - const Word32 total_brate, /* i : total bitrate */ - const Word32 core_brate_inp, /* i : core bitrate */ - const Word16 core, /* i : core */ - const Word16 extl, /* i : extension layer */ - const Word32 extl_brate, /* i : extension layer bitrate */ - const Word16 L_frame, /* i : frame length at internal Fs */ - const Word16 GSC_noisy_speech, /* i : GSC on SWB noisy speech flag */ - ACELP_config *acelp_cfg, /* i : ACELP bit-allocation */ - const Word16 signalling_bits, /* i : number of signalling bits */ - const Word16 coder_type, /* i : coder type */ - const Word16 inactive_coder_type_flag, /* i : AVQ (0) or GSC (1) IC flag */ - const Word16 tc_subfr, /* i : TC subfr ID */ - const Word16 tc_call, /* i : TC call number (0,1,2,3,5(DEC)) */ - Word16 *nBits_es_Pred, /* o : number of bits for Es_pred Q */ - Word16 *unbits, /* o : number of unused bits */ - const Word16 element_mode, /* i : element mode */ - Word16 *uc_two_stage_flag, /* o : flag undicating two-stage UC */ - const Word16 tdm_lp_reuse_flag, /* i : LPC reuse flag (can be 1 only with secondary channel */ - const Word16 tdm_low_rate_mode, /* i : secondary channel low rate mode flag */ - const Word16 idchan, /* i : stereo channel ID */ - const Word16 active_cnt, /* i : Active frame counter */ - const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag*/ - const Word16 tdm_LRTD_flag, /* i : LRTD stereo mode flag */ - const Word16 GSC_IVAS_mode /* i : GSC IVAS mode */ -) -{ - Word16 i, bits, nb_subfr; - Word16 flag_hardcoded, coder_type_sw, fix_first; - Word32 core_brate; -#ifdef DEBUGGING - (void) active_cnt; -#endif - ivas_error error; - - error = IVAS_ERR_OK; - move32(); - // PMT("Not floating point computation, but fixed point operator are still missing ") - /*-----------------------------------------------------------------* - * Set the flag indicating two-stage Unvoiced (UC) frame - *-----------------------------------------------------------------*/ - - *uc_two_stage_flag = 0; - move16(); - IF( EQ_16( coder_type, UNVOICED ) ) - { - test(); - test(); - test(); - test(); - test(); - if ( GE_32( total_brate, MIN_UNVOICED_TWO_STAGE_BRATE ) && element_mode > EVS_MONO && ( idchan == 0 || ( ( GE_32( total_brate, 8500 ) || extl_brate == 0 ) && EQ_16( tdm_LRTD_flag, 1 ) ) ) ) - { - *uc_two_stage_flag = 1; - move16(); - } - } - - /*-----------------------------------------------------------------* - * Set the number of subframes - *-----------------------------------------------------------------*/ - - IF( EQ_16( L_frame, L_FRAME ) ) - { - nb_subfr = NB_SUBFR; - move16(); - -#ifdef DEBUGGING - if ( ( ( core_brate_inp < 5900 && coder_type > UNVOICED ) && !( core_brate_inp < MIN_TC_BRATE && coder_type == TRANSITION ) ) && !( idchan > 0 && element_mode == IVAS_CPE_TD ) && !( element_mode == IVAS_SCE && tdm_low_rate_mode ) ) - { - return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Error: Too low bitrate (%d bps) for ACELP@12k8 in frame %d. Exiting!\n", core_brate_inp ); - } - - if ( core_brate_inp > ACELP_12k8_HIGH_LIMIT && core == ACELP_CORE ) - { - return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Error: Too high bitrate (%d bps) for ACELP@12k8 in frame %d. Exiting!\n", core_brate_inp ); - } -#endif - } - ELSE /* L_frame == L_FRAME16k */ - { - nb_subfr = NB_SUBFR16k; - move16(); - -#ifdef DEBUGGING - if ( core_brate_inp < ACELP_16k_LOW_LIMIT && core == ACELP_CORE ) - { - return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Error: Too low bitrate (%d bps) for ACELP@16k in frame %d. Exiting!\n", core_brate_inp ); - } -#endif - } - - coder_type_sw = coder_type; - move16(); - IF( core != ACELP_CORE ) - { - /* used in acelp_core_switch_enc() */ - nb_subfr = 1; - move16(); - if ( EQ_16( L_frame, L_FRAME ) ) - { - coder_type_sw = TRANSITION; - move16(); - } - } - - /*-----------------------------------------------------------------* - * Check if the core_brate is hard coded (to keep BE for mono core) or not - *-----------------------------------------------------------------*/ - - flag_hardcoded = 0; - move16(); - i = 0; - move16(); - - WHILE( i < SIZE_BRATE_INTERMED_TBL ) - { - IF( EQ_32( core_brate_inp, brate_intermed_tbl[i] ) ) - { - flag_hardcoded = 1; - move16(); - BREAK; - } - - IF( LT_32( core_brate_inp, brate_intermed_tbl[i] ) ) - { - flag_hardcoded = 0; - move16(); - BREAK; - } - - i = add( i, 1 ); - } - - test(); - test(); - test(); - IF( EQ_16( element_mode, IVAS_CPE_TD ) && EQ_16( coder_type, AUDIO ) && - LE_32( core_brate_inp, STEREO_GSC_BIT_RATE_ALLOC ) && EQ_32( brate_intermed_tbl[i], ACELP_9k60 ) ) /* Bit allocation should be mapped to 8 kb/s instead of 9.6 kb/s in this case */ - { - i = sub( i, 1 ); - } - - core_brate = brate_intermed_tbl[i]; - move32(); - - if ( element_mode > EVS_MONO ) - { - flag_hardcoded = 0; /* use automatic and flexible ACELP bit-budget allocation */ - move16(); - } - - test(); - if ( ( core != ACELP_CORE ) && ( element_mode == EVS_MONO ) ) /* needed for mode1 core switching in EVS mono */ - { - flag_hardcoded = 1; - move16(); - } - - /*-----------------------------------------------------------------* - * ACELP bit allocation - *-----------------------------------------------------------------*/ - test(); - test(); - IF( !( EQ_16( coder_type, TRANSITION ) && NE_16( tc_subfr, -1 ) ) || EQ_16( enc_dec, DEC ) ) - { - /* Set the bit-budget */ - bits = extract_l( Mpy_32_32( core_brate_inp, ONE_BY_FRAMES_PER_SEC_Q31 ) ); // Q0 - - test(); - test(); - IF( EQ_16( coder_type, TRANSITION ) && EQ_16( enc_dec, DEC ) && EQ_16( tc_call, 1 ) ) - { - bits = add( bits, *nBits_es_Pred ); /* equalize for 4th signaling bit estimated at the encoder in TC_0_192 */ - } - - /* Subtract signalling bits */ - test(); - test(); - IF( EQ_16( enc_dec, DEC ) && EQ_16( idchan, 1 ) && element_mode > EVS_MONO ) - { - bits = sub( bits, TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS ); - - IF( EQ_16( tdm_LRTD_flag, 1 ) ) - { - bits = add( bits, STEREO_BITS_TCA ); - } - - /* subtract TBE/BWE flag */ - test(); - test(); - test(); - test(); - test(); - test(); - IF( extl_brate > 0 && ( EQ_16( extl, WB_TBE ) || EQ_16( extl, SWB_TBE ) || EQ_16( extl, FB_TBE ) || EQ_16( extl, WB_BWE ) || EQ_16( extl, SWB_BWE ) || EQ_16( extl, FB_BWE ) ) ) - { - bits = sub( bits, 1 ); - } - } - ELSE - { - /* Subtract signalling bits */ - bits = sub( bits, signalling_bits ); - } - - test(); - test(); - test(); - test(); - test(); - test(); - IF( extl_brate > 0 && ( EQ_16( extl, WB_TBE ) || EQ_16( extl, SWB_TBE ) || EQ_16( extl, FB_TBE ) || EQ_16( extl, WB_BWE ) || EQ_16( extl, SWB_BWE ) || EQ_16( extl, FB_BWE ) ) ) - { - /* extension layer signalling bit is counted in the extension layer bitbudget */ - bits = add( bits, 1 ); - } - - /*-----------------------------------------------------------------* - * LSF Q bit-budget - *-----------------------------------------------------------------*/ - test(); - test(); - test(); - IF( !tdm_lp_reuse_flag || idchan == 0 ) - { - /* LSF Q bit-budget */ - acelp_cfg->lsf_bits = LSF_bits_tbl[LSF_BIT_ALLOC_IDX_fx( core_brate, coder_type )]; - move16(); - - IF( !flag_hardcoded ) - { - IF( EQ_16( L_frame, L_FRAME ) ) - { - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( EQ_16( element_mode, IVAS_SCE ) && tdm_low_rate_mode ) - { - acelp_cfg->lsf_bits = LSF_bits_tbl[LSF_BIT_ALLOC_IDX_fx( core_brate, coder_type )]; - move16(); - } - ELSE IF( ( LT_32( total_brate, 7200 ) || coder_type == INACTIVE || EQ_16( coder_type, AUDIO ) ) && EQ_16( idchan, 1 ) ) - { - /* TD stereo, secondary channel: do nothing */ - acelp_cfg->lsf_bits = LSF_bits_tbl[LSF_BIT_ALLOC_IDX_fx( core_brate, coder_type )]; - move16(); - } - ELSE IF( element_mode > EVS_MONO && EQ_16( coder_type, AUDIO ) && LT_32( brate_intermed_tbl[i], ACELP_9k60 ) ) - { - /* primary channel: do nothing */ - } - ELSE IF( element_mode > EVS_MONO && EQ_16( coder_type, AUDIO ) /*&& brate_intermed_tbl[i] >= ACELP_9k60*/ ) - { - acelp_cfg->lsf_bits = 42; - move16(); - } - ELSE IF( LE_32( total_brate, 9600 ) || EQ_16( coder_type, UNVOICED ) ) - { - acelp_cfg->lsf_bits = 31; - move16(); - } - ELSE IF( LE_32( total_brate, 20000 ) ) - { - acelp_cfg->lsf_bits = 36; - move16(); - } - ELSE - { - acelp_cfg->lsf_bits = 41; - move16(); - } - } - ELSE /* L_frame == L_FRAME16k */ - { - acelp_cfg->lsf_bits = 41; - move16(); - } - } - - bits = sub( bits, acelp_cfg->lsf_bits ); - - /* mid-LSF Q bit-budget */ - acelp_cfg->mid_lsf_bits = mid_LSF_bits_tbl[LSF_BIT_ALLOC_IDX_fx( core_brate, coder_type )]; - move16(); - - test(); - if ( element_mode > EVS_MONO && EQ_16( coder_type, AUDIO ) /*&& brate_intermed_tbl[i] < ACELP_9k60*/ ) - { - acelp_cfg->mid_lsf_bits = 5; - move16(); - /* primary channel: do nothing */ - } - - bits = sub( bits, acelp_cfg->mid_lsf_bits ); - } - ELSE IF( EQ_16( tdm_lp_reuse_flag, 1 ) && EQ_16( idchan, 1 ) && NE_16( active_cnt, 1 ) ) - { - bits = sub( bits, TDM_IC_LSF_PRED_BITS ); - } - /* gain Q bit-budget - part 1: 'Es_pred' of memory-less gain Q */ - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( NE_16( coder_type, UNVOICED ) && NE_16( coder_type, AUDIO ) && coder_type != INACTIVE && !( LE_32( core_brate, ACELP_8k00 ) && NE_16( coder_type, TRANSITION ) ) ) /* mid bitrates in GC and VC, low+mid bitrates in TC */ || - ( coder_type == INACTIVE && !inactive_coder_type_flag ) /* AVQ inactive */ - ) - { - *nBits_es_Pred = Es_pred_bits_tbl[BIT_ALLOC_IDX_fx( core_brate, coder_type, -1, -1 )]; - move16(); - bits = sub( bits, *nBits_es_Pred ); - } - ELSE IF( *uc_two_stage_flag ) - { - *nBits_es_Pred = 4; - move16(); - bits = sub( bits, *nBits_es_Pred ); - } - } - ELSE - { - bits = *unbits; - move16(); - } - - test(); - IF( EQ_16( coder_type, TRANSITION ) && tc_call == 0 ) - { - *unbits = bits; - return error; - } - - /*-----------------------------------------------------------------* - * Low-rate mode - bits are allocated in tdm_low_rate_enc() - *-----------------------------------------------------------------*/ - test(); - IF( EQ_16( element_mode, IVAS_SCE ) && tdm_low_rate_mode ) - { - acelp_cfg->FEC_mode = 0; - acelp_cfg->ltf_mode = FULL_BAND; - *nBits_es_Pred = 0; - *unbits = 0; - acelp_cfg->ubits = 0; - move16(); - move16(); - move16(); - move16(); - move16(); - - return error; - } - - /*-----------------------------------------------------------------* - * Supplementary information for FEC - *-----------------------------------------------------------------*/ - - acelp_cfg->FEC_mode = 0; - move16(); - test(); - test(); - IF( GE_32( core_brate, ACELP_11k60 ) && ( idchan == 0 || element_mode == EVS_MONO ) ) - { - acelp_cfg->FEC_mode = 1; - move16(); - - test(); - test(); - IF( GT_16( coder_type, UNVOICED ) && LT_16( coder_type, AUDIO ) && NE_16( coder_type, VOICED ) ) - { - bits = sub( bits, FEC_BITS_CLS ); - } - - IF( NE_16( coder_type, TRANSITION ) ) - { - IF( GE_32( total_brate, ACELP_16k40 ) ) - { - acelp_cfg->FEC_mode = 2; - move16(); - test(); - IF( GT_16( coder_type, UNVOICED ) && LT_16( coder_type, AUDIO ) ) - { - bits = sub( bits, FEC_BITS_ENR ); - } - } - - IF( GE_32( total_brate, ACELP_32k ) ) - { - acelp_cfg->FEC_mode = 3; - move16(); - - test(); - IF( GT_16( coder_type, UNVOICED ) && LT_16( coder_type, AUDIO ) ) - { - bits = sub( bits, FEC_BITS_POS ); - } - } - } - } - - /*-----------------------------------------------------------------* - * LP filtering of the adaptive excitation - *-----------------------------------------------------------------*/ - test(); - test(); - test(); - test(); - test(); - test(); - IF( idchan > 0 && element_mode > EVS_MONO ) - { - acelp_cfg->ltf_mode = FULL_BAND; - move16(); - } - ELSE IF( EQ_16( coder_type, UNVOICED ) ) - { - acelp_cfg->ltf_mode = FULL_BAND; - move16(); - } - ELSE IF( ( EQ_16( coder_type, GENERIC ) || EQ_16( coder_type, TRANSITION ) ) && LT_32( core_brate, ACELP_11k60 ) ) - { - acelp_cfg->ltf_mode = LOW_PASS; - move16(); - } - ELSE IF( GE_32( core_brate, ACELP_11k60 ) && ( NE_16( coder_type, AUDIO ) && !( coder_type == INACTIVE && EQ_16( L_frame, L_FRAME ) ) ) ) - { - test(); - test(); - IF( coder_type == INACTIVE && EQ_16( L_frame, L_FRAME16k ) && inactive_coder_type_flag ) /* GSC Inactive @16kHz */ - { - acelp_cfg->ltf_mode = FULL_BAND; - move16(); - } - ELSE - { - acelp_cfg->ltf_mode = NORMAL_OPERATION; - move16(); - IF( coder_type != TRANSITION ) - { - bits = sub( bits, nb_subfr ); - } - } - } - ELSE - { - acelp_cfg->ltf_mode = FULL_BAND; - move16(); - } - - /*-----------------------------------------------------------------* - * UC bit-budget - *-----------------------------------------------------------------*/ - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( ( EQ_16( coder_type, UNVOICED ) && !( *uc_two_stage_flag ) ) || ( coder_type == INACTIVE && LE_32( core_brate, ACELP_9k60 ) ) ) && ( idchan == 0 || element_mode == EVS_MONO ) ) - { - bits = sub( bits, NBITS_NOISENESS ); /* noiseness */ - } - IF( EQ_16( coder_type, UNVOICED ) && !( *uc_two_stage_flag ) ) - { - bits = sub( bits, 3 * NB_SUBFR ); /* tilt factor */ - } - - /*-----------------------------------------------------------------* - * TC bit-budget - *-----------------------------------------------------------------*/ - - fix_first = 0; - move16(); - IF( EQ_16( coder_type, TRANSITION ) ) - { - if ( EQ_16( tc_call, 2 ) ) - { - fix_first = 1; - move16(); - } - - /* TC signalling */ - IF( EQ_16( L_frame, L_FRAME ) ) - { - IF( EQ_16( tc_subfr, TC_0_0 ) ) - { - IF( enc_dec == ENC ) - { - bits = sub( bits, 1 ); /* TC signalling */ - } - - IF( EQ_16( acelp_cfg->ltf_mode, NORMAL_OPERATION ) ) - { - bits = sub( bits, 3 ); /* LP filtering flag */ - } - } - ELSE IF( EQ_16( tc_subfr, TC_0_64 ) ) - { - IF( enc_dec == ENC ) - { - bits = sub( bits, 4 ); /* TC signalling */ - } - - IF( EQ_16( acelp_cfg->ltf_mode, NORMAL_OPERATION ) ) - { - bits = sub( bits, 3 ); /* LP filtering flag */ - } - } - ELSE IF( EQ_16( tc_subfr, TC_0_128 ) ) - { - IF( enc_dec == ENC ) - { - bits = sub( bits, 4 ); /* TC signalling */ - } - - IF( EQ_16( acelp_cfg->ltf_mode, NORMAL_OPERATION ) ) - { - bits = sub( bits, 2 ); /* LP filtering flag */ - } - } - ELSE IF( EQ_16( tc_subfr, TC_0_192 ) ) - { - IF( enc_dec == ENC ) - { - bits = sub( bits, 3 ); /* TC signalling */ - } - - IF( EQ_16( acelp_cfg->ltf_mode, NORMAL_OPERATION ) ) - { - bits = sub( bits, 1 ); /* LP filtering flag */ - } - } - ELSE IF( EQ_16( tc_subfr, L_SUBFR ) ) - { - IF( enc_dec == ENC ) - { - bits = sub( bits, 3 ); /* TC signalling */ - } - - IF( EQ_16( acelp_cfg->ltf_mode, NORMAL_OPERATION ) ) - { - bits = sub( bits, idiv1616( sub( L_FRAME - L_SUBFR, tc_subfr ), L_SUBFR ) ); /* LP filtering flag */ - } - } - ELSE - { - IF( enc_dec == ENC ) - { - bits = sub( bits, 4 ); /* TC signalling */ - } - - IF( EQ_16( acelp_cfg->ltf_mode, NORMAL_OPERATION ) ) - { - bits = sub( bits, idiv1616_1( sub( L_FRAME - L_SUBFR, tc_subfr ), L_SUBFR ) ); /* LP filtering flag */ - } - } - } - ELSE /* L_frame == L_FRAME16k */ - { - IF( enc_dec == ENC ) - { - IF( LE_16( tc_subfr, 2 * L_SUBFR ) ) - { - bits = sub( bits, 2 ); /* TC signalling */ - } - ELSE - { - bits = sub( bits, 3 ); /* TC signalling */ - } - } - - // bits -= ( L_FRAME16k - tc_subfr - L_SUBFR ) / L_SUBFR; /* LP filtering flag */ - bits = sub( bits, idiv1616_1( sub( L_FRAME16k - L_SUBFR, tc_subfr ), L_SUBFR ) ); /* LP filtering flag */ - } - - /* glottal-shape codebook bits */ - bits = sub( bits, 3 + 6 + 1 + 3 ); - } - - /*-----------------------------------------------------------------* - * pitch, innovation, gains bit-budget - *-----------------------------------------------------------------*/ - - acelp_cfg->fcb_mode = 0; - move16(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( EQ_16( element_mode, IVAS_CPE_TD ) && EQ_16( tdm_low_rate_mode, 1 ) && ( coder_type != INACTIVE ) && NE_16( coder_type, UNVOICED ) ) /* GENERIC low rate mode for secondary channel */ - { - set16_fx( acelp_cfg->pitch_bits, 0, NB_SUBFR16k ); - set16_fx( acelp_cfg->gains_mode, 0, NB_SUBFR16k ); - - FOR( i = 0; i < 2; i++ ) - { - acelp_cfg->pitch_bits[i] = 0; - move16(); - IF( tdm_Pitch_reuse_flag == 0 ) - { - acelp_cfg->pitch_bits[i] = ACB_bits_tbl[BIT_ALLOC_IDX_fx( ACELP_7k20, GENERIC, i_mult( 2 * L_SUBFR, i ), TC_SUBFR2IDX_fx( tc_subfr ) )]; - move16(); - bits = sub( bits, acelp_cfg->pitch_bits[i] ); - } - acelp_cfg->gains_mode[i] = gain_bits_tbl[BIT_ALLOC_IDX_fx( ACELP_7k20, GENERIC, i_mult( i, L_SUBFR ), TC_SUBFR2IDX_fx( tc_subfr ) )]; - move16(); - bits = sub( bits, acelp_cfg->gains_mode[i] ); - } - acelp_cfg->fcb_mode = 1; - move16(); - -#ifdef DEBUGGING - if ( bits >= 55 ) - { - printf( "too much bits -> %d, LPC = %d and pitch = %d\n", bits, tdm_lp_reuse_flag, tdm_Pitch_reuse_flag ); - acelp_FCB_allocator( &bits, acelp_cfg->fixed_cdk_index, 2, 2 * L_SUBFR, GENERIC, -1, 0 ); - } - else -#endif - IF( GE_16( bits, 16 ) ) - { - acelp_FCB_allocator( &bits, acelp_cfg->fixed_cdk_index, 2, 2 * L_SUBFR, GENERIC, -1, 0 ); - } - ELSE - { - acelp_FCB_allocator( &bits, acelp_cfg->fixed_cdk_index, 2, 2 * L_SUBFR, GENERIC, -1, 0 ); - acelp_cfg->fixed_cdk_index[1] = -1; - move16(); - } - acelp_cfg->fixed_cdk_index[2] = -1; - move16(); - acelp_cfg->fixed_cdk_index[3] = -1; - move16(); - } - ELSE IF( ( coder_type != INACTIVE && EQ_16( nb_subfr, NB_SUBFR ) && NE_16( coder_type, AUDIO ) ) || /* @12.8kHz core except of GSC */ - ( EQ_16( nb_subfr, NB_SUBFR16k ) && ( !inactive_coder_type_flag || coder_type != INACTIVE ) ) /* @16kHz core GC, TC, AVQ inactive */ || - EQ_16( core, HQ_CORE ) /* ACELP -> HQ switching in EVS */ - ) - { - /* pitch Q & gain Q bit-budget - part 2*/ - FOR( i = 0; i < nb_subfr; i++ ) - { - IF( EQ_16( L_frame, L_FRAME ) ) - { - test(); - IF( EQ_16( tdm_Pitch_reuse_flag, 1 ) && EQ_16( idchan, 1 ) ) - { - acelp_cfg->pitch_bits[i] = 0; - move16(); - } - ELSE - { - acelp_cfg->pitch_bits[i] = ACB_bits_tbl[BIT_ALLOC_IDX_fx( core_brate, coder_type, i_mult( i, L_SUBFR ), TC_SUBFR2IDX_fx( tc_subfr ) )]; - move16(); - } - acelp_cfg->gains_mode[i] = gain_bits_tbl[BIT_ALLOC_IDX_fx( core_brate, coder_type_sw, i_mult( i, L_SUBFR ), TC_SUBFR2IDX_fx( tc_subfr ) )]; - move16(); - } - ELSE /* L_frame == L_FRAME16k */ - { - test(); - IF( EQ_16( tdm_Pitch_reuse_flag, 1 ) && EQ_16( idchan, 1 ) ) - { - acelp_cfg->pitch_bits[i] = 0; - move16(); - } - ELSE - { - acelp_cfg->pitch_bits[i] = ACB_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ_fx( core_brate, coder_type, i_mult( i, L_SUBFR ), TC_SUBFR2IDX_16KHZ_fx( tc_subfr ) )]; - move16(); - } - acelp_cfg->gains_mode[i] = gain_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ_fx( core_brate, coder_type_sw, i_mult( i, L_SUBFR ), TC_SUBFR2IDX_16KHZ_fx( tc_subfr ) )]; - move16(); - } - - bits = sub( bits, acelp_cfg->pitch_bits[i] ); - - test(); - IF( coder_type == INACTIVE && EQ_16( acelp_cfg->gains_mode[i], 6 ) /* VQ vs. SQ threshold @32 kbps */ ) - { - bits = sub( bits, 5 ); - } - ELSE - { - if ( EQ_16( *uc_two_stage_flag, 1 ) ) - { - acelp_cfg->gains_mode[i] = 7; - move16(); - } - - bits = sub( bits, acelp_cfg->gains_mode[i] ); - } - } - - /* algebraic codebook bit-budget */ - test(); - test(); - test(); - test(); - test(); - test(); - IF( flag_hardcoded /* EVS */ || - ( GE_32( core_brate_inp, MIN_BRATE_AVQ_EXC ) && coder_type != INACTIVE ) /* high-birate ACELP except IC */ || - ( !inactive_coder_type_flag && coder_type == INACTIVE ) /* AVQ inactive */ ) - { - FOR( i = 0; i < nb_subfr; i++ ) - { - IF( EQ_16( L_frame, L_FRAME ) ) - { - acelp_cfg->fixed_cdk_index[i] = FCB_bits_tbl[BIT_ALLOC_IDX_fx( core_brate, coder_type, i_mult( i, L_SUBFR ), TC_SUBFR2IDX_fx( tc_subfr ) )]; - move16(); - } - ELSE /* L_frame == L_FRAME16k */ - { - acelp_cfg->fixed_cdk_index[i] = FCB_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ_fx( core_brate, coder_type, i_mult( i, L_SUBFR ), TC_SUBFR2IDX_16KHZ_fx( tc_subfr ) )]; - move16(); - } - bits = sub( bits, acelp_cfg->fixed_cdk_index[i] ); - } - } - ELSE IF( !( EQ_16( coder_type, UNVOICED ) && EQ_16( tdm_low_rate_mode, 1 ) && EQ_16( element_mode, IVAS_CPE_TD ) ) ) - { - test(); - IF( EQ_16( coder_type, UNVOICED ) && !( *uc_two_stage_flag ) ) - { - i = idiv1616( bits, NB_SUBFR ); - IF( s_and( i, 1 ) == 0 ) - { - i = sub( i, 1 ); /* must be odd */ - } - i = s_min( i, 13 ); -#ifdef DEBUG_MODE_TD - if ( i < 0 ) - IVAS_ERROR( IVAS_ERR_INTERNAL, "ERROR::: UC negative index should not happen at frame %d\n" ); -#endif - i = s_max( i, 0 ); /* If i == 0-> random noise generator will be used as FCB */ - set16_fx( acelp_cfg->fixed_cdk_index, i, NB_SUBFR ); - bits = sub( bits, i_mult( i, NB_SUBFR ) ); - } - ELSE - { - - acelp_cfg->fcb_mode = 1; - move16(); - test(); - test(); - IF( EQ_16( element_mode, IVAS_CPE_TD ) ) - { - IF( GE_16( bits, i_mult( ACELP_FIXED_CDK_BITS( 0 ), ( nb_subfr ) ) ) ) /* enough bits for all fcb */ - { - acelp_FCB_allocator( &bits, acelp_cfg->fixed_cdk_index, nb_subfr, L_SUBFR, coder_type, tc_subfr, fix_first ); - } - ELSE IF( GE_16( bits, i_mult( ACELP_FIXED_CDK_BITS( 0 ), sub( nb_subfr, 1 ) ) ) ) - { - acelp_FCB_allocator( &bits, acelp_cfg->fixed_cdk_index, nb_subfr - 1, L_SUBFR, coder_type, tc_subfr, fix_first ); - acelp_cfg->fixed_cdk_index[3] = -1; - move16(); - } - ELSE IF( GE_16( bits, i_mult( ACELP_FIXED_CDK_BITS( 0 ), sub( nb_subfr, 2 ) ) ) ) - { - acelp_FCB_allocator( &bits, acelp_cfg->fixed_cdk_index, sub( nb_subfr, 2 ), L_SUBFR, coder_type, tc_subfr, fix_first ); - acelp_cfg->fixed_cdk_index[2] = acelp_cfg->fixed_cdk_index[1]; - move16(); - acelp_cfg->fixed_cdk_index[1] = -1; - move16(); - acelp_cfg->fixed_cdk_index[3] = -1; - move16(); - } - ELSE IF( GE_16( bits, ACELP_FIXED_CDK_BITS( 0 ) ) ) - { - acelp_FCB_allocator( &bits, acelp_cfg->fixed_cdk_index, 1, L_SUBFR, coder_type, tc_subfr, fix_first ); - acelp_cfg->fixed_cdk_index[1] = acelp_cfg->fixed_cdk_index[0]; - move16(); - acelp_cfg->fixed_cdk_index[0] = -1; - move16(); - acelp_cfg->fixed_cdk_index[2] = -1; - move16(); - acelp_cfg->fixed_cdk_index[3] = -1; - move16(); - } - ELSE /* No FCB */ - { -#ifdef DEBUGGING - IVAS_ERROR( IVAS_ERR_INTERNAL, "WARNING!!!, No bit allocated to FCB, check frame %d\n" ); -#endif - acelp_cfg->fixed_cdk_index[0] = -1; - move16(); - acelp_cfg->fixed_cdk_index[1] = -1; - move16(); - acelp_cfg->fixed_cdk_index[2] = -1; - move16(); - acelp_cfg->fixed_cdk_index[3] = -1; - move16(); - } - } - ELSE IF( NE_16( element_mode, IVAS_CPE_TD ) && GSC_IVAS_mode > 0 && EQ_16( L_frame, L_FRAME16k ) ) - { - bits = 100; /* 9 kbps for fcb */ - move16(); - acelp_FCB_allocator( &bits, acelp_cfg->fixed_cdk_index, nb_subfr, L_SUBFR, coder_type, tc_subfr, fix_first ); - } - ELSE - { - acelp_FCB_allocator( &bits, acelp_cfg->fixed_cdk_index, nb_subfr, L_SUBFR, coder_type, tc_subfr, fix_first ); - } - } - } - - /* AVQ codebook */ - test(); - test(); - test(); - IF( ( GE_32( core_brate_inp, MIN_BRATE_AVQ_EXC ) && coder_type != INACTIVE ) /* high-birate ACELP except IC */ || - ( !inactive_coder_type_flag && coder_type == INACTIVE ) /* AVQ inactive */ ) - { - FOR( i = 0; i < nb_subfr; i++ ) - { - IF( flag_hardcoded ) - { - acelp_cfg->AVQ_cdk_bits[i] = AVQ_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ_fx( core_brate, coder_type, i_mult( i, L_SUBFR ), TC_SUBFR2IDX_16KHZ_fx( tc_subfr ) )]; - move16(); - { - bits = sub( bits, acelp_cfg->AVQ_cdk_bits[i] ); - } - } - - bits = sub( bits, G_AVQ_BITS ); - } - - test(); - test(); - IF( GE_32( core_brate_inp, MIN_BRATE_AVQ_EXC ) && LE_32( core_brate_inp, MAX_BRATE_AVQ_EXC_TD ) && EQ_16( coder_type, GENERIC ) ) - { - /* harm. flag ACELP AVQ */ - bits = sub( bits, 1 ); - } - - IF( !flag_hardcoded ) - { - Word16 bit_tmp; - - bit_tmp = idiv1616( bits, nb_subfr ); - set16_fx( acelp_cfg->AVQ_cdk_bits, bit_tmp, nb_subfr ); - bits = sub( bits, i_mult( bit_tmp, nb_subfr ) ); - - bit_tmp = bits % nb_subfr; - move16(); - acelp_cfg->AVQ_cdk_bits[0] = add( acelp_cfg->AVQ_cdk_bits[0], bit_tmp ); - move16(); - bits = sub( bits, bit_tmp ); - } - } - } - ELSE IF( ( EQ_16( coder_type, UNVOICED ) && EQ_16( tdm_low_rate_mode, 1 ) && EQ_16( element_mode, IVAS_CPE_TD ) ) /* LBR secondary channel in TD stereo */ || - ( ( coder_type == INACTIVE || EQ_16( coder_type, AUDIO ) ) && EQ_16( nb_subfr, NB_SUBFR ) ) /* GSC @12.8kHz */ || - ( coder_type == INACTIVE && inactive_coder_type_flag ) /* AVQ inactive */ ) - { - Word32 Local_BR, Pitch_BR; - Word16 Pitch_CT; - - /* as defined at the beginning of [enc,dec]_pit_exc() */ - test(); - test(); - IF( GSC_IVAS_mode > 0 && ( GSC_noisy_speech || GT_32( core_brate, GSC_H_RATE_STG ) ) ) - { - Local_BR = ACELP_8k00; - move32(); - Pitch_CT = GENERIC; - move16(); - Pitch_BR = ACELP_8k00; - move32(); - IF( EQ_16( L_frame, L_FRAME16k ) ) - { - Local_BR = ACELP_14k80; - move32(); - test(); - if ( GSC_IVAS_mode > 0 && LT_32( core_brate, IVAS_24k4 ) ) - { - Local_BR = ACELP_9k60; - move32(); - } - Pitch_BR = core_brate; - move32(); - } - } - ELSE IF( GSC_noisy_speech ) - { - Local_BR = ACELP_7k20; - move32(); - Pitch_CT = GENERIC; - move16(); - Pitch_BR = ACELP_7k20; - move32(); - if ( EQ_16( L_frame, L_FRAME16k ) ) - { - Pitch_BR = core_brate; - move32(); - } - } - ELSE - { - Local_BR = ACELP_7k20; - move32(); - Pitch_CT = AUDIO; - move16(); - Pitch_BR = core_brate; - move32(); - - IF( EQ_16( L_frame, L_FRAME16k ) ) - { - Local_BR = ACELP_13k20; - move32(); - Pitch_CT = GENERIC; - move16(); - } - } - - FOR( i = 0; i < nb_subfr; i++ ) - { - IF( EQ_16( L_frame, L_FRAME16k ) ) - { - acelp_cfg->pitch_bits[i] = ACB_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ_fx( Pitch_BR, Pitch_CT, i_mult( i, L_SUBFR ), 0 )]; - move16(); - acelp_cfg->fixed_cdk_index[i] = FCB_bits_tbl[BIT_ALLOC_IDX_fx( Local_BR, LOCAL_CT, i_mult( i, L_SUBFR ), 0 )]; - move16(); - } - ELSE - { - acelp_cfg->pitch_bits[i] = ACB_bits_tbl[BIT_ALLOC_IDX_fx( Pitch_BR, Pitch_CT, i_mult( i, L_SUBFR ), 0 )]; - move16(); - acelp_cfg->fixed_cdk_index[i] = FCB_bits_tbl[BIT_ALLOC_IDX_fx( Local_BR, LOCAL_CT, i_mult( i, L_SUBFR ), 0 )]; - move16(); - acelp_cfg->gains_mode[i] = gain_bits_tbl[BIT_ALLOC_IDX_fx( ACELP_7k20, LOCAL_CT, i_mult( i, L_SUBFR ), 0 )]; - move16(); - } - } - } - - test(); - test(); - test(); - IF( EQ_16( coder_type, TRANSITION ) && ( EQ_16( tc_call, 1 ) && tc_subfr == 0 && EQ_16( L_frame, L_FRAME ) ) ) - { - return error; - } - - /*-----------------------------------------------------------------* - * unused bits handling - *-----------------------------------------------------------------*/ - - acelp_cfg->ubits = 0; /* these bits could be reused for something else */ - move16(); - - test(); - IF( flag_hardcoded && NE_32( core_brate, PPP_NELP_2k80 ) ) - { - test(); - test(); - /* unused bits */ - IF( EQ_16( coder_type, AUDIO ) || ( coder_type == INACTIVE && LE_32( core_brate, ACELP_24k40 ) ) ) - { - acelp_cfg->ubits = 0; - move16(); - } - ELSE IF( EQ_16( L_frame, L_FRAME ) ) - { - acelp_cfg->ubits = reserved_bits_tbl[BIT_ALLOC_IDX_fx( core_brate, coder_type, -1, TC_SUBFR2IDX_fx( tc_subfr ) )]; - move16(); - } - ELSE - { - acelp_cfg->ubits = 0; - move16(); - } - - bits = sub( bits, acelp_cfg->ubits ); - } - - /* sanity check */ - test(); - test(); - test(); - IF( ( coder_type != INACTIVE && EQ_16( nb_subfr, NB_SUBFR ) && NE_16( coder_type, AUDIO ) ) || EQ_16( nb_subfr, NB_SUBFR16k ) ) - { - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( EQ_16( L_frame, L_FRAME16k ) && coder_type == INACTIVE && inactive_coder_type_flag ) /* GSC Inactive @16kHz */ || - ( GSC_IVAS_mode > 0 && EQ_16( L_frame, L_FRAME16k ) ) ) /* IVAS GSC @16kHz */ - { - acelp_cfg->ubits = 0; - move16(); - } - ELSE IF( flag_hardcoded && core == ACELP_CORE && bits != 0 ) - { -#ifdef DEBUGGING - IVAS_ERROR( IVAS_ERR_INTERNAL, "ERROR: bit-budget incorrect (%d bits) in frame %d.\n", (Word32) bits ); -#endif - } - ELSE IF( bits > 0 && !( EQ_16( coder_type, UNVOICED ) && EQ_16( tdm_low_rate_mode, 1 ) && EQ_16( element_mode, IVAS_CPE_TD ) ) ) - { - test(); - test(); - test(); - test(); - IF( idchan > 0 && EQ_16( element_mode, IVAS_CPE_TD ) ) - { - IF( !tdm_lp_reuse_flag ) - { - acelp_cfg->lsf_bits = add( acelp_cfg->lsf_bits, bits ); /* increase LSF Q bits */ - move16(); - bits = 0; - move16(); - } - ELSE - { - Word16 nb_prm = 4; - move16(); - if ( EQ_16( tdm_low_rate_mode, 1 ) ) - { - nb_prm = 2; - move16(); - } - /* First add remaining bits on gains */ - bits = sub( bits, allocate_unused( core_brate, coder_type, bits, nb_prm, 0, GAINSPRM, acelp_cfg->gains_mode ) ); - - /* Then, Increase pitch bit budget */ - test(); - IF( tdm_Pitch_reuse_flag == 0 && bits > 0 ) - { - bits = sub( bits, allocate_unused( core_brate, coder_type, bits, nb_prm, 0, PITCHPRM, acelp_cfg->pitch_bits ) ); - } - - /* Increase mid-lsf bit budget */ - test(); - IF( tdm_lp_reuse_flag == 0 && bits > 0 ) - { - bits = sub( bits, allocate_unused( core_brate, coder_type, bits, 1, 0, MID_LSFSPRM, &acelp_cfg->mid_lsf_bits ) ); - bits = sub( bits, allocate_unused( core_brate, coder_type, bits, 1, 0, LSFPRM, &acelp_cfg->lsf_bits ) ); - } - } - -#ifdef DEBUGGING - if ( idchan > 0 && bits > 0 && ( coder_type > UNVOICED || tdm_low_rate_mode == 0 ) ) - { - IVAS_ERROR( IVAS_ERR_INTERNAL, "WARNING !! Unused bits in secondary channel at frame %d\n" ); - } -#endif - } - - ELSE IF( core == ACELP_CORE && GE_16( coder_type, UNVOICED ) && LE_16( coder_type, GENERIC ) && EQ_16( L_frame, L_FRAME ) ) - { - acelp_cfg->lsf_bits = add( acelp_cfg->lsf_bits, bits ); /* increase LSF Q bits */ - move16(); - - test(); - IF( GT_16( acelp_cfg->lsf_bits, 46 ) ) - { - acelp_cfg->ubits = sub( acelp_cfg->lsf_bits, 46 ); - move16(); - acelp_cfg->lsf_bits = 46; - move16(); - } - ELSE IF( GT_16( acelp_cfg->lsf_bits, 42 ) && EQ_16( L_frame, L_FRAME ) ) - { - acelp_cfg->ubits = sub( acelp_cfg->lsf_bits, 42 ); - move16(); - acelp_cfg->lsf_bits = 42; - move16(); - } - } - ELSE - { - acelp_cfg->ubits = bits; - move16(); - } - } - ELSE IF( bits < 0 && !( EQ_16( coder_type, UNVOICED ) && EQ_16( tdm_low_rate_mode, 1 ) && EQ_16( element_mode, IVAS_CPE_TD ) ) ) - { -#ifdef DEBUGGING - IVAS_ERROR( IVAS_ERR_INTERNAL, "ERROR: bit-budget incorrect (%d bits) in frame %d.\n", (Word32) bits ); -#endif - } - } - - return error; -} - -/*-------------------------------------------------------------------* - * config_acelp1_IVAS() - * - * Configure ACELP bit allocation - * - should be in range of <6700; 24350> for ACELP@12.8kHz - * - per channel bitrate minimum is 13250 kbps for ACELP@16kHz - *--------------------------------------------------------------------*/ -#endif -ivas_error config_acelp1_IVAS( +ivas_error config_acelp1_fx( const Word16 enc_dec, /* i : encoder/decoder flag */ const Word32 total_brate, /* i : total bitrate */ const Word32 core_brate_inp, /* i : core bitrate */ @@ -2511,11 +1224,11 @@ ivas_error config_acelp1_IVAS( IF( GE_16( bits, 16 ) ) { - acelp_FCB_allocator_ivas( &bits, acelp_cfg->fixed_cdk_index, 2, 2 * L_SUBFR, GENERIC, -1, 0 ); + acelp_FCB_allocator_fx( &bits, acelp_cfg->fixed_cdk_index, 2, 2 * L_SUBFR, GENERIC, -1, 0 ); } ELSE { - acelp_FCB_allocator_ivas( &bits, acelp_cfg->fixed_cdk_index, 2, 2 * L_SUBFR, GENERIC, -1, 0 ); + acelp_FCB_allocator_fx( &bits, acelp_cfg->fixed_cdk_index, 2, 2 * L_SUBFR, GENERIC, -1, 0 ); acelp_cfg->fixed_cdk_index[1] = -1; move16(); } @@ -2634,17 +1347,17 @@ ivas_error config_acelp1_IVAS( { IF( GE_16( bits, imult1616( ACELP_FIXED_CDK_BITS( 0 ), nb_subfr ) ) ) /* enough bits for all fcb */ { - acelp_FCB_allocator_ivas( &bits, acelp_cfg->fixed_cdk_index, nb_subfr, L_SUBFR, coder_type, tc_subfr, fix_first ); + acelp_FCB_allocator_fx( &bits, acelp_cfg->fixed_cdk_index, nb_subfr, L_SUBFR, coder_type, tc_subfr, fix_first ); } ELSE IF( GE_16( bits, imult1616( ACELP_FIXED_CDK_BITS( 0 ), sub( nb_subfr, 1 ) ) ) ) { - acelp_FCB_allocator_ivas( &bits, acelp_cfg->fixed_cdk_index, sub( nb_subfr, 1 ), L_SUBFR, coder_type, tc_subfr, fix_first ); + acelp_FCB_allocator_fx( &bits, acelp_cfg->fixed_cdk_index, sub( nb_subfr, 1 ), L_SUBFR, coder_type, tc_subfr, fix_first ); acelp_cfg->fixed_cdk_index[3] = -1; move16(); } ELSE IF( GE_32( bits, imult1616( ACELP_FIXED_CDK_BITS( 0 ), sub( nb_subfr, 2 ) ) ) ) { - acelp_FCB_allocator_ivas( &bits, acelp_cfg->fixed_cdk_index, sub( nb_subfr, 2 ), L_SUBFR, coder_type, tc_subfr, fix_first ); + acelp_FCB_allocator_fx( &bits, acelp_cfg->fixed_cdk_index, sub( nb_subfr, 2 ), L_SUBFR, coder_type, tc_subfr, fix_first ); acelp_cfg->fixed_cdk_index[2] = acelp_cfg->fixed_cdk_index[1]; move16(); acelp_cfg->fixed_cdk_index[1] = -1; @@ -2654,7 +1367,7 @@ ivas_error config_acelp1_IVAS( } ELSE IF( GE_32( bits, ACELP_FIXED_CDK_BITS( 0 ) ) ) { - acelp_FCB_allocator_ivas( &bits, acelp_cfg->fixed_cdk_index, 1, L_SUBFR, coder_type, tc_subfr, fix_first ); + acelp_FCB_allocator_fx( &bits, acelp_cfg->fixed_cdk_index, 1, L_SUBFR, coder_type, tc_subfr, fix_first ); acelp_cfg->fixed_cdk_index[1] = acelp_cfg->fixed_cdk_index[0]; move16(); acelp_cfg->fixed_cdk_index[0] = -1; @@ -2680,11 +1393,11 @@ ivas_error config_acelp1_IVAS( { bits = 100; /* 9 kbps for fcb */ move16(); - acelp_FCB_allocator_ivas( &bits, acelp_cfg->fixed_cdk_index, nb_subfr, L_SUBFR, coder_type, tc_subfr, fix_first ); + acelp_FCB_allocator_fx( &bits, acelp_cfg->fixed_cdk_index, nb_subfr, L_SUBFR, coder_type, tc_subfr, fix_first ); } ELSE { - acelp_FCB_allocator_ivas( &bits, acelp_cfg->fixed_cdk_index, nb_subfr, L_SUBFR, coder_type, tc_subfr, fix_first ); + acelp_FCB_allocator_fx( &bits, acelp_cfg->fixed_cdk_index, nb_subfr, L_SUBFR, coder_type, tc_subfr, fix_first ); } } } diff --git a/lib_com/gs_inact_switching_fx.c b/lib_com/gs_inact_switching_fx.c index 582fd3c8a..119811275 100644 --- a/lib_com/gs_inact_switching_fx.c +++ b/lib_com/gs_inact_switching_fx.c @@ -33,144 +33,24 @@ /*------------------------------------------------------------------------*/ /* OUTPUT ARGUMENTS : */ /*------------------------------------------------------------------------*/ - /*------------------------------------------------------------------------*/ /* RETURN ARGUMENTS : */ /* _ None */ /*========================================================================*/ -#ifndef REMOVE_EVS_DUPLICATES -void Inac_swtch_ematch_fx( - Word16 exc2[], /* i/o: CELP/GSC excitation buffer Q_exc*/ - Word16 dct_exc_tmp[], /* i : GSC excitation in DCT domain */ - Word16 lt_ener_per_band[], /* i/o: Long term energy per band Q12 */ - const Word16 coder_type, /* i : Coding mode */ - const Word16 L_frame, /* i : Frame lenght */ - const Word32 core_brate, /* i : Core bit rate */ - const Word16 Q_exc /* i : input and output format of exc2 */ - , - const Word16 bfi /* i : frame lost indicator */ - , - const Word16 last_core, /* i : Last core used */ - const Word16 last_codec_mode /* i : Last codec mode */ -) -{ - Word16 Ener_per_bd[MBANDS_GN]; - Word16 ftmp; - Word16 *pt_exc; - Word16 j, i; - - Word16 exp, frac; - Word32 L_tmp; - - /*-------------------------------------------------------------------------- - * average energy per band - *--------------------------------------------------------------------------*/ - - test(); - test(); - test(); - test(); - test(); - test(); - IF( EQ_16( coder_type, AUDIO ) && bfi == 0 ) - { - Ener_per_band_comp_fx( dct_exc_tmp, Ener_per_bd, Q_exc, MBANDS_GN, 1 ); - - /* reset long-term energy per band */ - FOR( i = 0; i < MBANDS_GN; i++ ) - { - lt_ener_per_band[i] = Ener_per_bd[i]; - move16(); - } - } - ELSE IF( EQ_16( coder_type, VOICED ) || EQ_16( coder_type, GENERIC ) || EQ_16( coder_type, TRANSITION ) || ( last_core != ACELP_CORE ) || NE_16( last_codec_mode, MODE1 ) ) - { - /* Find spectrum and energy per band for GC and VC frames */ - edct_16fx( exc2, dct_exc_tmp, L_frame, 5, EVS_MONO ); - - Ener_per_band_comp_fx( dct_exc_tmp, Ener_per_bd, Q_exc, MBANDS_GN, 1 ); - - /* reset long-term energy per band */ - FOR( i = 0; i < MBANDS_GN; i++ ) - { - lt_ener_per_band[i] = Ener_per_bd[i]; - move16(); - } - } - ELSE IF( ( coder_type == INACTIVE ) && LE_32( core_brate, ACELP_24k40 ) ) - { - /* Find spectrum and energy per band for inactive frames */ - edct_16fx( exc2, dct_exc_tmp, L_frame, 5, EVS_MONO ); - Ener_per_band_comp_fx( dct_exc_tmp, Ener_per_bd, Q_exc, MBANDS_GN, 1 ); - - /* More agressive smoothing in the first 50 frames */ - pt_exc = dct_exc_tmp; - move16(); - FOR( i = 0; i < MBANDS_GN; i++ ) - { - /* Compute smoothing gain to apply with gain limitation */ - L_tmp = L_mult( ALPHA0_FX, lt_ener_per_band[i] ); /*Q(15+12+1)=Q(28) */ - L_tmp = L_mac( L_tmp, BETA0_FX, Ener_per_bd[i] ); /*Q28 */ - lt_ener_per_band[i] = round_fx( L_tmp ); /*Q12 */ - move16(); - - ftmp = sub( lt_ener_per_band[i], Ener_per_bd[i] ); /*Q12 */ - - /* ftmp = (float)pow(10, ftmp);= pow(2,3.321928*ftmp);*/ - - L_tmp = L_mult( 27213, ftmp ); /*Q(13+12+1)=Q26 ; 27213=3.321928 in Q13 */ - L_tmp = L_shr( L_tmp, 10 ); /* From Q26 to Q16 */ - frac = L_Extract_lc( L_tmp, &exp ); /* Extract exponent of ftmp */ - ftmp = extract_l( Pow2( 14, frac ) ); /* Put 14 as exponent so that */ - /* output of Pow2() will be: */ - /* 16384 < Pow2() <= 32767 */ - - exp = sub( exp, 14 ); - IF( LT_16( i, 2 ) ) - { - FOR( j = 0; j < 8; j++ ) - { - L_tmp = L_mult( *pt_exc, ftmp ); /* Q_exc*Q0 -> Q(Q_exc+1) */ - L_tmp = L_shl_sat( L_tmp, add( exp, 15 ) ); /* Q(Q_exc+1) -> Q(16+Q_exc)*/ - *pt_exc = round_fx_sat( L_tmp ); - move16(); - pt_exc++; - } - } - ELSE - { - FOR( j = 0; j < 16; j++ ) - { - L_tmp = L_mult( *pt_exc, ftmp ); /* Q_exc*Q0 -> Q(Q_exc+1) */ - L_tmp = L_shl_sat( L_tmp, add( exp, 15 ) ); /* Q(Q_exc+1) -> Q(16+Q_exc)*/ - *pt_exc = round_fx_sat( L_tmp ); /*Q_exc*/ - move16(); - pt_exc++; - } - } - } - - /* Going back to time */ - edct_16fx( dct_exc_tmp, exc2, L_frame, 5, EVS_MONO ); - } - - return; -} -#endif -void Inac_switch_ematch_ivas_fx( +void Inac_switch_ematch_fx( Word16 exc2[], /* i/o: CELP/GSC excitation buffer Q_exc*/ Word16 dct_exc_tmp[], /* i : GSC excitation in DCT domain */ Word16 lt_ener_per_band[], /* i/o: Long term energy per band Q12 */ const Word16 coder_type, /* i : Coding mode */ - const Word16 inactive_coder_type_flag, /* i : AVQ (0) or GSC (1) IC flag */ + const Word16 inactive_coder_type_flag, /* i : AVQ (0) or GSC (1) IC flag */ const Word16 L_frame, /* i : Frame lenght */ const Word16 Q_exc, /* i : input and output format of exc2 */ const Word16 bfi, /* i : frame lost indicator */ const Word16 last_core, /* i : Last core used */ const Word16 last_codec_mode, /* i : Last codec mode */ - const Word16 tdm_low_rate_mode, /* i : secondary channel low rate mode flag*/ - const Word16 element_mode /* i : element mode */ + const Word16 tdm_low_rate_mode, /* i : secondary channel low rate mode flag */ + const Word16 element_mode /* i : element mode */ ) { Word16 Ener_per_bd[MBANDS_GN16k]; @@ -251,7 +131,6 @@ void Inac_switch_ematch_ivas_fx( exp = sub( exp, 14 ); IF( LT_16( i, 2 ) ) { -#ifdef REMOVE_EVS_DUPLICATES IF( EQ_16( element_mode, EVS_MONO ) ) { FOR( j = 0; j < 8; j++ ) @@ -264,7 +143,6 @@ void Inac_switch_ematch_ivas_fx( } } ELSE -#endif { FOR( j = 0; j < 8; j++ ) { @@ -278,7 +156,6 @@ void Inac_switch_ematch_ivas_fx( } ELSE { -#ifdef REMOVE_EVS_DUPLICATES IF( EQ_16( element_mode, EVS_MONO ) ) { FOR( j = 0; j < 16; j++ ) @@ -291,7 +168,6 @@ void Inac_switch_ematch_ivas_fx( } } ELSE -#endif { FOR( j = 0; j < 16; j++ ) { @@ -306,9 +182,7 @@ void Inac_switch_ematch_ivas_fx( } /* Going back to time */ -#ifdef REMOVE_EVS_DUPLICATES IF( GT_16( element_mode, EVS_MONO ) ) -#endif { Scale_sig( dct_exc_tmp, 240, 1 ); // Q_exc Scale_sig( exc2, 240, 1 ); // Q_exc diff --git a/lib_com/gs_noisefill_fx.c b/lib_com/gs_noisefill_fx.c index 1198fb793..208f20569 100644 --- a/lib_com/gs_noisefill_fx.c +++ b/lib_com/gs_noisefill_fx.c @@ -1332,8 +1332,6 @@ void highband_exc_dct_in_ivas_fx( } } - -#ifdef REMOVE_EVS_DUPLICATES IF( EQ_16( element_mode, EVS_MONO ) ) { Comp_and_apply_gain_fx( exc_diffQ, Ener_per_bd_iQ, Ener_per_bd_yQ, last_bin, 0, Qexc_diffQ, *Q_exc ); @@ -1346,7 +1344,6 @@ void highband_exc_dct_in_ivas_fx( } ELSE { -#endif Word16 Q_tmp = *Q_exc; move16(); Word16 Q_old = *Q_exc; @@ -1373,9 +1370,7 @@ void highband_exc_dct_in_ivas_fx( { Scale_sig( exc_dct_in, L_frame, sub( *Q_exc, Q_old ) ); } -#ifdef REMOVE_EVS_DUPLICATES } -#endif /*--------------------------------------------------------------------------------------* * add the correction layer to the LF bins, @@ -1416,13 +1411,10 @@ void highband_exc_dct_in_ivas_fx( Q_hb_exc = 0; move16(); envelop_modify_fx( exc_diffQ, seed_tcx, last_bin, Ener_per_bd_iQ, *Q_exc, &Q_hb_exc ); -#ifdef REMOVE_EVS_DUPLICATES + test(); test(); IF( GT_16( *Q_exc, Q_hb_exc ) && GT_16( element_mode, EVS_MONO ) && exc_wo_nf != NULL ) -#else - IF( GT_16( *Q_exc, Q_hb_exc ) ) -#endif { Scale_sig( exc_wo_nf, L_frame, sub( Q_hb_exc, *Q_exc ) ); *Q_exc = Q_hb_exc; diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index 48a28a397..e6afe35a2 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -3973,7 +3973,7 @@ ivas_error ivas_core_dec_fx( const Word16 sba_dirac_stereo_flag /* i : signal stereo output for SBA DirAC */ ); -void decod_gen_2sbfr_ivas_fx( +void decod_gen_2sbfr_fx( Decoder_State *st, /* i/o: decoder static memory */ const Word16 sharpFlag, /* i : formant sharpening flag `Q0*/ const Word16 *Aq, /* i : LP filter coefficient Q12*/ diff --git a/lib_com/lsf_tools_fx.c b/lib_com/lsf_tools_fx.c index d60d0e999..a41e10713 100644 --- a/lib_com/lsf_tools_fx.c +++ b/lib_com/lsf_tools_fx.c @@ -2863,40 +2863,39 @@ Word16 qlsf_ARSN_tcvq_Dec_16k_fx( } /*======================================================================*/ -/* FUNCTION : lsf_syn_mem_backup_fx */ +/* FUNCTION : lsf_syn_mem_backup_fx */ /*----------------------------------------------------------------------*/ /* PURPOSE : back-up synthesis filter memory and LSF qunatizer memories */ /*----------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16*) lsp_new : LSP vector to quantize */ -/* _ (Word16*) lsf_new : quantized LSF vector */ -/* _ (Word16*) lsp_mid : mid-frame LSP vector */ -/* _ (Encoder_State) st_fx : Encoder state Structure */ -/*-----------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _None */ -/*-----------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16) clip_var : pitch clipping state var */ -/* _ (Word16*) mem_AR : quantizer memory for AR model */ -/* _ (Word16*) mem_MA : quantizer memory for MA model */ -/* _ (Word16*) lsp_new_bck : LSP vector to quantize- backup */ -/* _ (Word16*) lsf_new_bck : quantized LSF vector - backup */ -/* _ (Word16*) lsp_mid_bck : mid-frame LSP vector - backup */ +/* INPUT ARGUMENTS : */ +/* _ (Word16*) lsp_new : LSP vector to quantize */ +/* _ (Word16*) lsf_new : quantized LSF vector */ +/* _ (Word16*) lsp_mid : mid-frame LSP vector */ +/* _ (Encoder_State) st_fx : Encoder state Structure */ +/*----------------------------------------------------------------------*/ +/* INPUT/OUTPUT ARGUMENTS : */ +/* _None */ +/*----------------------------------------------------------------------*/ +/* OUTPUT ARGUMENTS : */ +/* _ (Word16) clip_var : pitch clipping state var */ +/* _ (Word16*) mem_AR : quantizer memory for AR model */ +/* _ (Word16*) mem_MA : quantizer memory for MA model */ +/* _ (Word16*) lsp_new_bck : LSP vector to quantize- backup */ +/* _ (Word16*) lsf_new_bck : quantized LSF vector - backup */ +/* _ (Word16*) lsp_mid_bck : mid-frame LSP vector - backup */ /* _ (Word16) mCb1 :counter for stationary frame after a transition frame */ -/* _ (Word32*) Bin_E : FFT Bin energy 128 *2 sets */ -/* _ (Word32*) Bin_E_old : FFT Bin energy 128 *2 sets */ -/* _ (Word16*) mem_syn_bck : synthesis filter memory */ -/* _ (Word16) mem_w0_bck : memory of the weighting filter */ -/* _ (Word16) streaklimit : LSF quantizer */ -/* _ (Word16) pstreaklen : LSF quantizer */ -/*-----------------------------------------------------------------------*/ - -/* _ None */ -/*-----------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*=======================================================================*/ +/* _ (Word32*) Bin_E : FFT Bin energy 128 *2 sets */ +/* _ (Word32*) Bin_E_old : FFT Bin energy 128 *2 sets */ +/* _ (Word16*) mem_syn_bck : synthesis filter memory */ +/* _ (Word16) mem_w0_bck : memory of the weighting filter */ +/* _ (Word16) streaklimit : LSF quantizer */ +/* _ (Word16) pstreaklen : LSF quantizer */ +/*----------------------------------------------------------------------*/ +/* _ None */ +/*----------------------------------------------------------------------*/ +/* RETURN ARGUMENTS : */ +/* _ None */ +/*======================================================================*/ void lsf_syn_mem_backup_fx( Encoder_State *st_fx, /* o: state structure */ @@ -2904,23 +2903,22 @@ void lsf_syn_mem_backup_fx( Word32 *gc_threshold_fx, /* i: Q16 */ Word16 *clip_var_bck_fx, /* i: Q(2.56), Q14, Q7, Q0, Q14, Q14 */ Word16 *next_force_sf_bck_fx, /* i: */ - - Word16 *lsp_new, /* o: LSP vector to quantize Q15 */ - Word16 *lsf_new, /* i: quantized LSF vector Q15 */ - Word16 *lsp_mid, /* o: mid-frame LSP vector Q15 */ - Word16 *clip_var, /* i: pitch clipping state var Q(2.56) */ - Word16 *mem_AR, /* i: quantizer memory for AR model 2.56 */ - Word16 *mem_MA, /* i: quantizer memory for MA model 2.56 */ - Word16 *lsp_new_bck, /* i: LSP vector to quantize- backup Q15 */ - Word16 *lsf_new_bck, /* o: quantized LSF vector - backup Q15 */ - Word16 *lsp_mid_bck, /* i: mid-frame LSP vector - backup Q15 */ - Word16 *mCb1, /* o: counter for stationary frame after a transition frame */ - Word32 *Bin_E, /* i: FFT Bin energy 128 *2 sets q_bin */ - Word32 *Bin_E_old, /* i: FFT Bin energy 128 sets q_bin */ - Word16 *mem_syn_bck, /* i: synthesis filter memory q */ - Word16 *mem_w0_bck, /* i: memory of the weighting filter q */ - Word16 *streaklimit, /* i:LSF quantizer Q15 */ - Word16 *pstreaklen /* i:LSF quantizer */ + Word16 *lsp_new, /* o: LSP vector to quantize Q15 */ + Word16 *lsf_new, /* i: quantized LSF vector Q15 */ + Word16 *lsp_mid, /* o: mid-frame LSP vector Q15 */ + Word16 *clip_var, /* i: pitch clipping state var Q(2.56) */ + Word16 *mem_AR, /* i: quantizer memory for AR model 2.56 */ + Word16 *mem_MA, /* i: quantizer memory for MA model 2.56 */ + Word16 *lsp_new_bck, /* i: LSP vector to quantize- backup Q15 */ + Word16 *lsf_new_bck, /* o: quantized LSF vector - backup Q15 */ + Word16 *lsp_mid_bck, /* i: mid-frame LSP vector - backup Q15 */ + Word16 *mCb1, /* o: counter for stationary frame after a transition frame */ + Word32 *Bin_E, /* i: FFT Bin energy 128 *2 sets q_bin */ + Word32 *Bin_E_old, /* i: FFT Bin energy 128 sets q_bin */ + Word16 *mem_syn_bck, /* i: synthesis filter memory q */ + Word16 *mem_w0_bck, /* i: memory of the weighting filter q */ + Word16 *streaklimit, /* i:LSF quantizer Q15 */ + Word16 *pstreaklen /* i:LSF quantizer */ ) { Word16 i; @@ -2985,25 +2983,31 @@ void lsf_syn_mem_backup_fx( return; } + +/*-------------------------------------------------------------------* + * lsf_syn_mem_backup_fx() + * + * + *--------------------------------------------------------------------*/ + void lsf_syn_mem_backup_ivas_fx( Encoder_State *st_fx, /* i: state structure */ Word16 *btilt_code_fx, /* i: tilt code Q15 */ Word32 *gc_threshold_fx, /* i: Q16 */ Word16 *clip_var_bck_fx, /* o: Q(2.56), Q14, Q7, Q0, Q14, Q14 */ Word16 *next_force_sf_bck_fx, /* o: */ - - Word16 *lsp_new, /* i: LSP vector to quantize Q15 */ - Word16 *lsp_mid, /* i: mid-frame LSP vector Q15 */ - Word16 *clip_var, /* o: pitch clipping state var Q(2.56) */ - Word16 *mem_AR, /* o: quantizer memory for AR model Q(2.56) */ - Word16 *mem_MA, /* o: quantizer memory for AR model Q(2.56) */ - Word16 *lsp_new_bck, /* o: LSP vector to quantize- backup Q15 */ - Word16 *lsp_mid_bck, /* o: mid-frame LSP vector - backup Q15 */ - Word32 *Bin_E, /* o: FFT Bin energy 128 *2 sets Q_new + Q_SCALE - 2 */ - Word32 *Bin_E_old, /* o: FFT Bin energy 128 sets Q_new + Q_SCALE - 2 */ - Word16 *mem_syn_bck, /* o: synthesis filter memory ( 15 - st_fx->hLPDmem->e_mem_syn ) */ - Word16 *mem_w0_bck, /* o: memory of the weighting filter ( 15 - st_fx->hLPDmem->e_mem_syn ) */ - Word16 *streaklimit, /* Q15 */ + Word16 *lsp_new, /* i: LSP vector to quantize Q15 */ + Word16 *lsp_mid, /* i: mid-frame LSP vector Q15 */ + Word16 *clip_var, /* o: pitch clipping state var Q(2.56) */ + Word16 *mem_AR, /* o: quantizer memory for AR model Q(2.56) */ + Word16 *mem_MA, /* o: quantizer memory for AR model Q(2.56) */ + Word16 *lsp_new_bck, /* o: LSP vector to quantize- backup Q15 */ + Word16 *lsp_mid_bck, /* o: mid-frame LSP vector - backup Q15 */ + Word32 *Bin_E, /* o: FFT Bin energy 128 *2 sets Q_new + Q_SCALE - 2 */ + Word32 *Bin_E_old, /* o: FFT Bin energy 128 sets Q_new + Q_SCALE - 2 */ + Word16 *mem_syn_bck, /* o: synthesis filter memory ( 15 - st_fx->hLPDmem->e_mem_syn ) */ + Word16 *mem_w0_bck, /* o: memory of the weighting filter ( 15 - st_fx->hLPDmem->e_mem_syn ) */ + Word16 *streaklimit, /* Q15 */ Word16 *pstreaklen ) { Word16 i; @@ -3079,66 +3083,68 @@ void lsf_update_memory( move16(); mem_MA[i] = sub( sub( qlsf[i], lsf_means[narrowband][i] ), mult_r( MU_MA_FX, old_mem_MA[i] ) ); } + + return; } + /*======================================================================*/ -/* FUNCTION : lsf_syn_mem_restore_fx */ +/* FUNCTION : lsf_syn_mem_restore_fx */ /*----------------------------------------------------------------------*/ /* PURPOSE : restore synthesis filter memory and LSF quantizer memories*/ /*----------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16) clip_var : pitch clipping state var */ -/* _ (Word16*) mem_AR : quantizer memory for AR model */ -/* _ (Word16*) mem_MA : quantizer memory for MA model */ -/* _ (Word16*) lsp_new_bck : LSP vector to quantize- backup */ -/* _ (Word16*) lsf_new_bck : quantized LSF vector - backup */ -/* _ (Word16*) lsp_mid_bck : mid-frame LSP vector - backup */ +/* INPUT ARGUMENTS : */ +/* _ (Word16) clip_var : pitch clipping state var */ +/* _ (Word16*) mem_AR : quantizer memory for AR model */ +/* _ (Word16*) mem_MA : quantizer memory for MA model */ +/* _ (Word16*) lsp_new_bck : LSP vector to quantize- backup */ +/* _ (Word16*) lsf_new_bck : quantized LSF vector - backup */ +/* _ (Word16*) lsp_mid_bck : mid-frame LSP vector - backup */ /* _ (Word16) mCb1 :counter for stationary frame after a transition frame */ -/* _ (Word32*) Bin_E : FFT Bin energy 128 *2 sets */ -/* _ (Word32*) Bin_E_old : FFT Bin energy 128 *2 sets */ -/* _ (Word16*) mem_syn_bck : synthesis filter memory */ -/* _ (Word16) mem_w0_bck : memory of the weighting filter */ -/* _ (Word16) streaklimit : LSF quantizer */ -/* _ (Word16) pstreaklen : LSF quantizer */ -/*-----------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _None */ -/*-----------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16*) lsp_new : LSP vector to quantize */ -/* _ (Word16*) lsf_new : quantized LSF vector */ -/* _ (Word16*) lsp_mid : mid-frame LSP vector */ -/* _ (Encoder_State) st_fx : Encoder state Structure */ -/*-----------------------------------------------------------------------*/ - -/* _ None */ -/*-----------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*=======================================================================*/ +/* _ (Word32*) Bin_E : FFT Bin energy 128 *2 sets */ +/* _ (Word32*) Bin_E_old : FFT Bin energy 128 *2 sets */ +/* _ (Word16*) mem_syn_bck : synthesis filter memory */ +/* _ (Word16) mem_w0_bck : memory of the weighting filter */ +/* _ (Word16) streaklimit : LSF quantizer */ +/* _ (Word16) pstreaklen : LSF quantizer */ +/*----------------------------------------------------------------------*/ +/* INPUT/OUTPUT ARGUMENTS : */ +/* _None */ +/*----------------------------------------------------------------------*/ +/* OUTPUT ARGUMENTS : */ +/* _ (Word16*) lsp_new : LSP vector to quantize */ +/* _ (Word16*) lsf_new : quantized LSF vector */ +/* _ (Word16*) lsp_mid : mid-frame LSP vector */ +/* _ (Encoder_State) st_fx : Encoder state Structure */ +/*----------------------------------------------------------------------*/ +/* _ None */ +/*----------------------------------------------------------------------*/ +/* RETURN ARGUMENTS : */ +/* _ None */ +/*======================================================================*/ + void lsf_syn_mem_restore_fx( Encoder_State *st_fx, /* o: state structure */ Word16 btilt_code_fx, /* i: Q15 */ Word32 gc_threshold_fx, /* i: Q16 */ Word16 *clip_var_bck_fx, /* i: Q(2.56), Q14, Q7, Q0, Q14, Q14 */ Word16 next_force_sf_bck_fx, /* i: */ - - Word16 *lsp_new, /* o: LSP vector to quantize Q15 */ - Word16 *lsf_new, /* o: quantized LSF vector Q15 */ - Word16 *lsp_mid, /* o: mid-frame LSP vector Q15 */ - Word16 clip_var, /* i: pitch clipping state var Q(2.56) */ - Word16 *mem_AR, /* i: quantizer memory for AR model Q15 */ - Word16 *mem_MA, /* i: quantizer memory for MA model Q15 */ - Word16 *lsp_new_bck, /* i: LSP vector to quantize- backup Q15 */ - Word16 *lsf_new_bck, /* i: quantized LSF vector - backup Q15 */ - Word16 *lsp_mid_bck, /* i: mid-frame LSP vector - backup Q15 */ - Word16 mCb1, /* i: counter for stationary frame after a transition frame */ - Word32 *Bin_E, /* i: FFT Bin energy 128 *2 sets Q_new + Q_SCALE - 2 */ - Word32 *Bin_E_old, /* i: FFT Bin energy 128 sets Q_new + Q_SCALE - 2 */ - Word16 *mem_syn_bck, /* i: synthesis filter memory ( 15 - st_fx->hLPDmem->e_mem_syn ) */ - Word16 mem_w0_bck, /* i: memory of the weighting filter ( 15 - st_fx->hLPDmem->e_mem_syn ) */ - Word16 streaklimit, /* i:LSF quantizer Q15 */ - Word16 pstreaklen /* i:LSF quantizer */ + Word16 *lsp_new, /* o: LSP vector to quantize Q15 */ + Word16 *lsf_new, /* o: quantized LSF vector Q15 */ + Word16 *lsp_mid, /* o: mid-frame LSP vector Q15 */ + Word16 clip_var, /* i: pitch clipping state var Q(2.56) */ + Word16 *mem_AR, /* i: quantizer memory for AR model Q15 */ + Word16 *mem_MA, /* i: quantizer memory for MA model Q15 */ + Word16 *lsp_new_bck, /* i: LSP vector to quantize- backup Q15 */ + Word16 *lsf_new_bck, /* i: quantized LSF vector - backup Q15 */ + Word16 *lsp_mid_bck, /* i: mid-frame LSP vector - backup Q15 */ + Word16 mCb1, /* i: counter for stationary frame after a transition frame */ + Word32 *Bin_E, /* i: FFT Bin energy 128 *2 sets Q_new + Q_SCALE - 2 */ + Word32 *Bin_E_old, /* i: FFT Bin energy 128 sets Q_new + Q_SCALE - 2 */ + Word16 *mem_syn_bck, /* i: synthesis filter memory ( 15 - st_fx->hLPDmem->e_mem_syn ) */ + Word16 mem_w0_bck, /* i: memory of the weighting filter ( 15 - st_fx->hLPDmem->e_mem_syn ) */ + Word16 streaklimit, /* i:LSF quantizer Q15 */ + Word16 pstreaklen /* i:LSF quantizer */ ) { Word16 i; diff --git a/lib_com/options.h b/lib_com/options.h index 921d05b1c..bcee4b8fe 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -99,10 +99,10 @@ #define FIX_1486_IND_SHB_RES /* VA: Fix for issue 1486: align the usage of IND_SHB_RES_GS indices with float code */ #define TEST_HR -#define REMOVE_EVS_DUPLICATES /* remove core-coder duplicated functions, ACELP low-band decoder */ #define FIX_1348_BIT_PRECISION_IMPROVEMENT #define FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN #define FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD //#define FIX_1348_BIT_PRECISION_IMPROVEMENT_ROUND_OLD_BUFF + #endif diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 36cb671cc..43010af04 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -3284,52 +3284,33 @@ void synthesise_fb_high_band_fx( #endif ); -#ifndef REMOVE_EVS_DUPLICATES void prep_tbe_exc_fx( - const Word16 L_frame_fx, /* i : length of the frame */ - const Word16 i_subfr_fx, /* i : subframe index */ - const Word16 gain_pit_fx, /* i : Pitch gain Q14*/ - const Word32 gain_code_fx, /* i : algebraic codebook gain 16+Q_exc*/ - const Word16 code_fx[], /* i : algebraic excitation Q9*/ - const Word16 voice_fac_fx, /* i : voicing factor Q15*/ - Word16 *voice_factors_fx, /* o : TBE voicing factor Q15*/ - Word16 bwe_exc_fx[], /* i/o: excitation for TBE Q_exc*/ - const Word16 gain_preQ_fx, /* i : prequantizer excitation gain */ - const Word16 code_preQ_fx[], /* i : prequantizer excitation */ - const Word16 Q_exc, /* i : Excitation, bwe_exc Q-factor */ - Word16 T0, /* i : integer pitch variables Q0 */ - Word16 T0_frac, /* i : Fractional pitch variables Q0*/ - const Word16 coder_type, /* i : coding type */ - Word32 core_brate /* i :core bitrate */ -); -#endif - -void prep_tbe_exc_ivas_fx( - const Word16 L_frame_fx, /* i : length of the frame */ - const Word16 L_subfr, - const Word16 i_subfr_fx, /* i : subframe index */ - const Word16 gain_pit_fx, /* i : Pitch gain Q14*/ - const Word32 gain_code_fx, /* i : algebraic codebook gain 16+Q_exc*/ - const Word16 code_fx[], /* i : algebraic excitation Q9*/ - const Word16 voice_fac_fx, /* i : voicing factor Q15*/ - Word16 *voice_factors_fx, /* o : TBE voicing factor Q15*/ - Word16 bwe_exc_fx[], /* i/o: excitation for TBE Q_exc*/ - const Word16 gain_preQ_fx, /* i : prequantizer excitation gain */ - const Word16 code_preQ_fx[], /* i : prequantizer excitation */ - const Word16 Q_exc, /* i : Excitation, bwe_exc Q-factor */ - Word16 T0, /* i : integer pitch variables Q0 */ - Word16 T0_frac, /* i : Fractional pitch variables Q0*/ - const Word16 coder_type, /* i : coding type */ - Word32 core_brate, /* i : core bitrate */ - const Word16 element_mode, /* i : element mode */ - const Word16 idchan, /* i : channel ID */ - const Word16 flag_TD_BWE, /* i : flag indicating whether hTD_BWE exists */ - const Word16 tdm_LRTD_flag /* i : LRTD stereo mode flag */ -); - -Word16 swb_formant_fac_fx( /* o : Formant filter strength [0,1] */ - const Word16 lpc_shb2, /* Q12 i : 2nd HB LPC coefficient */ - Word16 *tilt_mem /* i/o: Tilt smoothing memory */ + const Word16 L_frame_fx, /* i : length of the frame */ + const Word16 L_subfr, /* i : subframe length */ + const Word16 i_subfr_fx, /* i : subframe index */ + const Word16 gain_pit_fx, /* i : Pitch gain Q14*/ + const Word32 gain_code_fx, /* i : algebraic codebook gain 16+Q_exc*/ + const Word16 code_fx[], /* i : algebraic excitation Q9*/ + const Word16 voice_fac_fx, /* i : voicing factor Q15*/ + Word16 *voice_factors_fx, /* o : TBE voicing factor Q15*/ + Word16 bwe_exc_fx[], /* i/o: excitation for TBE Q_exc*/ + const Word16 gain_preQ_fx, /* i : prequantizer excitation gain */ + const Word16 code_preQ_fx[], /* i : prequantizer excitation */ + const Word16 Q_exc, /* i : Excitation, bwe_exc Q-factor */ + Word16 T0, /* i : integer pitch variables Q0 */ + Word16 T0_frac, /* i : Fractional pitch variables Q0*/ + const Word16 coder_type, /* i : coding type */ + const Word32 core_brate, /* i : core bitrate */ + const Word16 element_mode, /* i : element mode */ + const Word16 idchan, /* i : channel ID */ + const Word16 flag_TD_BWE, /* i : flag indicating whether hTD_BWE exists */ + const Word16 tdm_LRTD_flag /* i : LRTD stereo mode flag */ +); + +/*! r: Formant filter strength [0,1] */ +Word16 swb_formant_fac_fx( + const Word16 lpc_shb2, /* Q12 i : 2nd HB LPC coefficient */ + Word16 *tilt_mem /* i/o: Tilt smoothing memory */ ); void wb_tbe_extras_reset_fx( @@ -4833,35 +4814,6 @@ Word16 BITS_ALLOC_config_acelp( const Word16 narrowband, const Word16 nb_subfr ); -#ifndef REMOVE_EVS_DUPLICATES -ivas_error config_acelp1( - const Word16 enc_dec, /* i : encoder/decoder flag */ - const Word32 total_brate, /* i : total bitrate */ - const Word32 core_brate_inp, /* i : core bitrate */ - const Word16 core, /* i : core */ - const Word16 extl, /* i : extension layer */ - const Word32 extl_brate, /* i : extension layer bitrate */ - const Word16 L_frame, /* i : frame length at internal Fs */ - const Word16 GSC_noisy_speech, /* i : GSC on SWB noisy speech flag */ - ACELP_config *acelp_cfg, /* i : ACELP bit-allocation */ - const Word16 signalling_bits, /* i : number of signalling bits */ - const Word16 coder_type, /* i : coder type */ - const Word16 inactive_coder_type_flag, /* i : AVQ (0) or GSC (1) IC flag */ - const Word16 tc_subfr, /* i : TC subfr ID */ - const Word16 tc_call, /* i : TC call number (0,1,2,3,5(DEC)) */ - Word16 *nBits_es_Pred, /* o : number of bits for Es_pred Q */ - Word16 *unbits, /* o : number of unused bits */ - const Word16 element_mode, /* i : element mode */ - Word16 *uc_two_stage_flag, /* o : flag undicating two-stage UC */ - const Word16 tdm_lp_reuse_flag, /* i : LPC reuse flag (can be 1 only with secondary channel */ - const Word16 tdm_low_rate_mode, /* i : secondary channel low rate mode flag */ - const Word16 idchan, /* i : stereo channel ID */ - const Word16 active_cnt, /* i : Active frame counter */ - const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag*/ - const Word16 tdm_LRTD_flag, /* i : LRTD stereo mode flag */ - const Word16 GSC_IVAS_mode /* i : GSC IVAS mode */ -); -#endif Word16 set_ACELP_flag( const Word16 element_mode, /* i : element mode */ const Word32 element_brate, /* i : element bitrate */ @@ -5808,35 +5760,19 @@ void tcx_ltp_post_fx32( Word32 *tcx_buf, /* sig_q */ Word16 sig_q ); -#ifndef REMOVE_EVS_DUPLICATES -// gs_inact_switching_fx.c -void Inac_swtch_ematch_fx( - Word16 exc2[], /* i/o: CELP/GSC excitation buffer Q_exc*/ - Word16 dct_exc_tmp[], /* i : GSC excitation in DCT domain */ - Word16 lt_ener_per_band[], /* i/o: Long term energy per band Q12 */ - const Word16 coder_type, /* i : Coding mode */ - const Word16 L_frame, /* i : Frame lenght */ - const Word32 core_brate, /* i : Core bit rate */ - const Word16 Q_exc, /* i : i and output format of exc2 */ - const Word16 bfi, /* i : frame lost indicator */ - const short last_core, /* i : Last core used */ - const short last_codec_mode /* i : Last codec mode */ -); -#endif - -void Inac_switch_ematch_ivas_fx( +void Inac_switch_ematch_fx( Word16 exc2[], /* i/o: CELP/GSC excitation buffer Q_exc*/ Word16 dct_exc_tmp[], /* i : GSC excitation in DCT domain */ Word16 lt_ener_per_band[], /* i/o: Long term energy per band Q12 */ const Word16 coder_type, /* i : Coding mode */ - const Word16 inactive_coder_type_flag, /* i : AVQ (0) or GSC (1) IC flag */ + const Word16 inactive_coder_type_flag, /* i : AVQ (0) or GSC (1) IC flag */ const Word16 L_frame, /* i : Frame lenght */ const Word16 Q_exc, /* i : input and output format of exc2 */ const Word16 bfi, /* i : frame lost indicator */ const Word16 last_core, /* i : Last core used */ const Word16 last_codec_mode, /* i : Last codec mode */ - const Word16 tdm_low_rate_mode, /* i : secondary channel low rate mode flag*/ - const Word16 element_mode /* i : element mode */ + const Word16 tdm_low_rate_mode, /* i : secondary channel low rate mode flag */ + const Word16 element_mode /* i : element mode */ ); // igf_base_fx.c @@ -6069,32 +6005,16 @@ void td_bwe_dec_init_fx( const Word32 output_Fs /* i : output sampling rate */ ); -#ifndef REMOVE_EVS_DUPLICATES -// lsf_dec_fx.c void lsf_dec_fx( - Decoder_State *st_fx, /* i/o: State structure */ - const Word16 tc_subfr, /* i : TC subframe index Q0*/ - Word16 *Aq, /* o : quantized A(z) for 4 subframes Q12*/ - Word16 *LSF_Q_prediction, /* o : LSF prediction mode Q0*/ - Word16 *lsf_new, /* o : de-quantized LSF vector Q(x2.56)*/ - Word16 *lsp_new, /* o : de-quantized LSP vector Q15*/ - Word16 *lsp_mid, /* o : de-quantized mid-frame LSP vector Q15*/ - const Word16 tdm_low_rate_mode /* i : secondary channel low rate mode flag Q0*/ - , - const Word16 tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel Qx*/ -); -#endif -void lsf_dec_ivas_fx( - Decoder_State *st_fx, /* i/o: State structure */ - const Word16 tc_subfr, /* i : TC subframe index Q0*/ - Word16 *Aq, /* o : quantized A(z) for 4 subframes Q12*/ - Word16 *LSF_Q_prediction, /* o : LSF prediction mode Q0*/ - Word16 *lsf_new, /* o : de-quantized LSF vector Q(x2.56)*/ - Word16 *lsp_new, /* o : de-quantized LSP vector Q15*/ - Word16 *lsp_mid, /* o : de-quantized mid-frame LSP vector Q15*/ - const Word16 tdm_low_rate_mode /* i : secondary channel low rate mode flag Q0*/ - , - const Word16 tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel Qx*/ + Decoder_State *st_fx, /* i/o: State structure */ + const Word16 tc_subfr, /* i : TC subframe index Q0*/ + Word16 *Aq, /* o : quantized A(z) for 4 subframes Q12*/ + Word16 *LSF_Q_prediction, /* o : LSF prediction mode Q0*/ + Word16 *lsf_new, /* o : de-quantized LSF vector Q(x2.56)*/ + Word16 *lsp_new, /* o : de-quantized LSP vector Q15*/ + Word16 *lsp_mid, /* o : de-quantized mid-frame LSP vector Q15*/ + const Word16 tdm_low_rate_mode, /* i : secondary channel low rate mode flag Q0*/ + const Word16 tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel Qx*/ ); /*! r: index of the maximum value in the input vector */ @@ -6257,21 +6177,9 @@ void lsf_mid_dec_fx( Word16 lsp_mid[] /* o : quantized LSPs Q15*/ ); -#ifndef REMOVE_EVS_DUPLICATES -// cng_dec_fx.c void CNG_dec_fx( Decoder_State *st_fx, /* i/o: State structure */ - const Word16 last_element_mode, /* i : last element mode Q0 */ - Word16 Aq[], /* o : LP coefficients Q12 */ - Word16 *lsp_new, /* i/o: current frame LSPs Q15 */ - Word16 *lsf_new, /* i/o: current frame LSFs Qlog2(2.56) */ - Word16 *allow_cn_step, /* o : allow CN step Q0 */ - Word16 *sid_bw, /* i : 0-NB/WB, 1-SWB SID Q0 */ - Word32 *q_env ); -#endif -void CNG_dec_ivas_fx( - Decoder_State *st_fx, /* i/o: State structure */ - const Word16 last_element_mode, /* i : last element mode Q0 */ + const Word16 last_element_mode, /* i : last element mode Q0 */ Word16 Aq[], /* o : LP coefficients Q12 */ Word16 *lsp_new, /* i/o: current frame LSPs Q15 */ Word16 *lsf_new, /* i/o: current frame LSFs Qlog2(2.56) */ @@ -6656,12 +6564,12 @@ void hf_synth_amr_wb_fx( // dec_post_fx void Init_post_filter_fx( PFSTAT_HANDLE hPFstat /* i : core decoder parameters */ -); /* (i) : core decoder parameters */ +); /* i : core decoder parameters */ void nb_post_filt_fx( const Word16 L_frame, /* i : frame length */ - PFSTAT_HANDLE hPFstat, /* i : core decoder parameters */ + PFSTAT_HANDLE hPFstat, /* i : core decoder parameters */ Word16 *psf_lp_noise, /* i : Long term noise Q8 */ const Word16 tmp_noise, /* i : noise energy Q0 */ Word16 *Synth, /* i : 12k8 synthesis Qsyn */ @@ -6672,27 +6580,15 @@ void nb_post_filt_fx( const Word16 disable_hpf /* i : flag to diabled HPF */ ); -#ifndef REMOVE_EVS_DUPLICATES void formant_post_filt_fx( - PFSTAT_HANDLE hPFstat, /* i : core decoder parameters */ + PFSTAT_HANDLE hPFstat, /* i : core decoder parameters */ Word16 *synth_in, /* i : 12k8 synthesis */ - Word16 *Aq, /* i : LP filter coefficient */ - Word16 *synth_out, /* i/o: i signal */ - Word16 L_frame, - Word32 lp_noise, /* (i) : background noise energy (15Q16) */ - Word32 rate, /* (i) : bit-rate */ - const Word16 off_flag /* i : off flag */ -); -#endif -void formant_post_filt_ivas_fx( - PFSTAT_HANDLE hPFstat, /* i : core decoder parameters */ - Word16 *synth_in, /* i : 12k8 synthesis */ - Word16 *Aq, /* i : LP filter coefficient */ - Word16 *synth_out, /* i/o: i signal */ - Word16 L_frame, - Word32 lp_noise, /* (i) : background noise energy (15Q16) */ - Word32 rate, /* (i) : bit-rate */ - const Word16 off_flag /* i : off flag */ + Word16 *Aq, /* i : LP filter coefficient Q12 */ + Word16 *synth_out, /* i/o: input signal */ + const Word16 L_frame, /* i : frame length */ + const Word32 lp_noise, /* (i) : background noise energy (15Q16) */ + const Word32 brate, /* (i) : bit-rate */ + const Word16 off_flag /* i : off flag */ ); void Filt_mu_fx( Word16 *sig_in, /* i : signal (beginning at sample -1) */ @@ -6858,65 +6754,34 @@ void PulseResynchronization_fx( Word32 /*float*/ const pitchEnd /*i Q16*/ ); -#ifndef REMOVE_EVS_DUPLICATES -// gs_dec_fx.c void decod_audio_fx( - Decoder_State *st_fx, /* i/o: decoder static memory */ - Word16 dct_epit[], /* o : GSC excitation in DCT domain Qx*/ - const Word16 *Aq, /* i : LP filter coefficient Q12*/ - Word16 *pitch_buf, /* o : floating pitch values for each subframe Q6*/ - Word16 *voice_factors, /* o : voicing factors Q15*/ - Word16 *exc, /* i/o: adapt. excitation exc Q_exc*/ - Word16 *exc2, /* i/o: adapt. excitation/total exc Q_exc*/ - Word16 *bwe_exc, /* o : excitation for SWB TBE Q_exc*/ - Word16 *lsf_new /* i : ISFs at the end of the frame Qx*/ - , - Word16 *gain_buf /*Q14*/ -); -#endif -void decod_audio_ivas_fx( - Decoder_State *st_fx, /* i/o: decoder static memory */ - Word16 dct_epit[], /* o : GSC excitation in DCT domain Qx*/ - const Word16 *Aq, /* i : LP filter coefficient Q12*/ - Word16 *pitch_buf, /* o : Word16 pitch values for each subframe Q6*/ - Word16 *voice_factors, /* o : voicing factors Q15*/ - Word16 *exc, /* i/o: adapt. excitation exc Q_exc*/ - Word16 *exc2, /* i/o: adapt. excitation/total exc Q_exc*/ - Word16 *bwe_exc, /* o : excitation for SWB TBE Q_exc*/ - Word16 *lsf_new /* i : ISFs at the end of the frame Qx*/ - , - Word16 *gain_buf, /*Q14*/ + Decoder_State *st_fx, /* i/o: decoder static memory */ + Word16 dct_epit[], /* o : GSC excitation in DCT domain Qx*/ + const Word16 *Aq, /* i : LP filter coefficient Q12*/ + Word16 *pitch_buf, /* o : Word16 pitch values for each subframe Q6*/ + Word16 *voice_factors, /* o : voicing factors Q15*/ + Word16 *exc, /* i/o: adapt. excitation exc Q_exc*/ + Word16 *exc2, /* i/o: adapt. excitation/total exc Q_exc*/ + Word16 *bwe_exc, /* o : excitation for SWB TBE Q_exc*/ + Word16 *lsf_new, /* i : ISFs at the end of the frame Qx*/ + Word16 *gain_buf, /* o : Word16 pitch gain for each subframe Q14*/ const Word16 tdm_lp_reuse_flag, /* i : LPC reuse flag Q0*/ const Word16 tdm_low_rate_mode, /* i : secondary channel low rate mode flag Q0*/ const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag Q0*/ const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer Q6*/ ); -#ifndef REMOVE_EVS_DUPLICATES void gsc_dec_fx( - Decoder_State *st_fx, /* i/o: State structure */ - Word16 exc_dct_in[], /* i/o: dct of pitch-only excitation / total excitation Q_exc*/ - const Word16 pit_band_idx, /* i : bin position of the cut-off frequency Q0*/ - const Word16 Diff_len, /* i : Lenght of the difference signal (before pure spectral) Q0*/ - const Word16 bits_used, /* i : Number of bit used before frequency Q Q0*/ - const Word16 nb_subfr, /* i : Number of subframe considered Q0*/ - const Word16 coder_type, /* i : coding type Q0*/ - Word16 *last_bin, /* i : last bin of bit allocation Q0*/ - const Word16 *lsf_new, /* i : ISFs at the end of the frame Qx*/ - Word16 *exc_wo_nf, /* o : excitation (in f domain) without noisefill Q_exc*/ - Word16 Q_exc ); -#endif -void gsc_dec_ivas_fx( - Decoder_State *st_fx, /* i/o: State structure */ - Word16 exc_dct_in[], /* i/o: dct of pitch-only excitation / total excitation Q_exc*/ + Decoder_State *st_fx, /* i/o: State structure */ + Word16 exc_dct_in[], /* i/o: dct of pitch-only excitation / total excitation Q_exc*/ const Word16 pit_band_idx, /* i : bin position of the cut-off frequency ` Q0*/ const Word16 Diff_len, /* i : Lenght of the difference signal (before pure spectral) Q0*/ const Word16 bits_used, /* i : Number of bit used before frequency Q Q0*/ const Word16 nb_subfr, /* i : Number of subframe considered Q0*/ const Word16 coder_type, /* i : coding type Q0*/ Word16 *last_bin, /* i : last bin of bit allocation Q0*/ - const Word16 *lsf_new, /* i : ISFs at the end of the frame Qx*/ - Word16 *exc_wo_nf, /* o : excitation (in f domain) without noisefill Q_exc*/ + const Word16 *lsf_new, /* i : ISFs at the end of the frame Qx*/ + Word16 *exc_wo_nf, /* o : excitation (in f domain) without noisefill Q_exc*/ Word16 *Q_exc ); void GSC_dec_init( @@ -6927,18 +6792,15 @@ void GSC_dec_init_ivas_fx( GSC_DEC_HANDLE hGSCDec /* i/o: GSC data handle */ ); - -// gain_dec_fx.c - void Es_pred_dec_fx( - Word16 *Es_pred, /* o : predicited scaled innovation energy Q8*/ - const Word16 enr_idx, /* i : indice */ - const Word16 nb_bits, /* i : number of bits */ - const Word16 no_ltp /* i : no LTP flag */ + Word16 *Es_pred, /* o : predicited scaled innovation energy Q8*/ + const Word16 enr_idx, /* i : indice */ + const Word16 nb_bits, /* i : number of bits */ + const Word16 no_ltp /* i : no LTP flag */ ); void gain_dec_tc_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ + Decoder_State *st_fx, /* i/o: decoder state structure */ const Word16 *code_fx, /* i : algebraic code excitation */ const Word16 i_subfr_fx, /* i : subframe number */ const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ @@ -6973,7 +6835,6 @@ void gain_dec_mless_fx( Word32 *norm_gain_code_fx /* o : norm. gain of the codebook excitation Q16*/ ); -#ifndef REMOVE_EVS_DUPLICATES void gain_dec_lbr_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ const Word16 coder_type, /* i : coding type */ @@ -6984,25 +6845,8 @@ void gain_dec_lbr_fx( Word16 *gain_inov_fx, /* o : gain of the innovation (used for normalization) Q12*/ Word32 *norm_gain_code_fx, /* o : norm. gain of the codebook excitation Q16*/ Word32 gc_mem[], /* i/o: gain_code from previous subframes */ - Word16 gp_mem[] /* i/o: gain_pitch from previous subframes */ - , - const Word16 L_subfr /* i : subfr lenght */ -); -#endif - -void gain_dec_lbr_ivas_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 coder_type, /* i : coding type */ - const Word16 i_subfr, /* i : subframe index */ - const Word16 *code_fx, /* i : algebraic excitation Q9 */ - Word16 *gain_pit_fx, /* o : quantized pitch gain Q14*/ - Word32 *gain_code_fx, /* o : quantized codebook gain Q16*/ - Word16 *gain_inov_fx, /* o : gain of the innovation (used for normalization) Q12*/ - Word32 *norm_gain_code_fx, /* o : norm. gain of the codebook excitation Q16*/ - Word32 gc_mem[], /* i/o: gain_code from previous subframes */ - Word16 gp_mem[] /* i/o: gain_pitch from previous subframes */ - , - const Word16 L_subfr /* i : subfr lenght */ + Word16 gp_mem[], /* i/o: gain_pitch from previous subframes */ + const Word16 L_subfr /* i : subfr lenght */ ); void lp_gain_updt_fx( @@ -7023,13 +6867,14 @@ void lp_gain_updt_ivas_fx( const Word16 L_frame /* i : length of the frame */ ); -Word32 gain_dec_gaus_fx( /* o : quantized codebook gain Q16 */ - Word16 index, /* i : quantization index */ - const Word16 bits, /* i : number of bits to quantize */ - const Word16 lowBound, /* i : lower bound of quantizer (dB) */ - const Word16 topBound, /* i : upper bound of quantizer (dB) */ - const Word16 inv_gain_inov, /* o : unscaled innovation gain Q12 */ - Word32 *L_norm_gain_code /* o : gain of normalized gaussian excitation Q16 */ +/*! r: quantized codebook gain Q16 */ +Word32 gain_dec_gaus_fx( + Word16 index, /* i : quantization index */ + const Word16 bits, /* i : number of bits to quantize */ + const Word16 lowBound, /* i : lower bound of quantizer (dB) */ + const Word16 topBound, /* i : upper bound of quantizer (dB) */ + const Word16 inv_gain_inov, /* o : unscaled innovation gain Q12 */ + Word32 *L_norm_gain_code /* o : gain of normalized gaussian excitation Q16 */ ); void gain_dec_SQ_fx( @@ -7123,23 +6968,7 @@ void re8_PPV_fx( Word16 y[] /* o : point in RE8 (8-dimensional integer vector) Q0 */ ); -#ifndef REMOVE_EVS_DUPLICATES -// dec_pit_exc_fx.c void dec_pit_exc_fx( - Decoder_State *st_fx, /* i/o: decoder static memory */ - const Word16 *Aq_fx, /* i : LP filter coefficient */ - const Word16 coder_type, /* i : coding type */ - const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ - Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe */ - Word16 *code_fx, /* o : innovation */ - Word16 *exc_fx, /* i/o: adapt. excitation exc */ - Word16 *bwe_exc_fx, /* o : excitation for SWB TBE */ - const Word16 nb_subfr_fx /* i : Number of subframe considered */ - , - Word16 *gain_buf /*Q14*/ -); -#endif -void dec_pit_exc_ivas_fx( Decoder_State *st_fx, /* i/o: decoder static memory */ const Word16 *Aq_fx, /* i : LP filter coefficient */ const Word16 coder_type, /* i : coding type */ @@ -7149,7 +6978,7 @@ void dec_pit_exc_ivas_fx( Word16 *exc_fx, /* i/o: adapt. excitation exc */ Word16 *bwe_exc_fx, /* o : excitation for SWB TBE */ const Word16 nb_subfr_fx, /* i : Number of subframe considered */ - Word16 *gain_buf, /*Q14*/ + Word16 *gain_buf, /* o : Word16 pitch gain for each subframe Q14*/ const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer */ ); @@ -7193,24 +7022,8 @@ void Mode2_delta_pit_dec( Word16 **pt_indice /* i/o: pointer to Vector of Q indexes */ ); -#ifndef REMOVE_EVS_DUPLICATES -Word16 pit_decode_fx( /* o : floating pitch value */ - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - const Word16 L_frame, /* i : length of the frame */ - Word16 i_subfr, /* i : subframe index */ - const Word16 coder_type, /* i : coding type */ - Word16 *limit_flag, /* i/o: restrained(0) or extended(1) Q limits */ - Word16 *T0, /* o : close loop integer pitch */ - Word16 *T0_frac, /* o : close loop fractional part of the pitch */ - Word16 *T0_min, /* i/o: delta search min for sf 2 & 4 */ - Word16 *T0_max, /* i/o: delta search max for sf 2 & 4 */ - const Word16 L_subfr /* i : subframe length */ -); -#endif /* o : floating pitch value */ -Word16 pit_decode_ivas_fx( +Word16 pit_decode_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ const Word32 core_brate, /* i : core bitrate */ const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ @@ -7571,9 +7384,8 @@ void configureFdCngDec_fx( const Word16 Last_L_frame, const Word16 element_mode ); -#ifndef REMOVE_EVS_DUPLICATES -/* Apply the CLDFB-based CNG */ Word16 ApplyFdCng_fx( +<<<<<<< HEAD Word16 *timeDomainInput, /* i : pointer to time domain i */ Word16 Q, Word32 **cldfbBufferReal, /* i/o: real part of the CLDFB buffer */ @@ -7584,6 +7396,8 @@ Word16 ApplyFdCng_fx( Word16 is_music ); #endif Word16 ApplyFdCng_ivas_fx( +======= +>>>>>>> 2afc0761 (accept REMOVE_EVS_DUPLICATES) Word16 *timeDomainInput, /* i : pointer to time domain input */ Word16 Q, Word32 *powerSpectrum, @@ -8172,14 +7986,11 @@ void FEC_pitch_estim_fx( const Word32 old_pitch_buf[], /* i : buffer of old subframe pitch values 15Q16 */ Word16 *bfi_pitch, /* i/o: update of the estimated pitch for FEC */ Word16 *bfi_pitch_frame, /* o : frame length when pitch was updated */ - Word16 *upd_cnt /* i/o: update counter */ - , - const Word16 coder_type, /* i : coder_type */ - Word16 element_mode /* i : element mode */ + Word16 *upd_cnt, /* i/o: update counter */ + const Word16 coder_type, /* i : coder_type */ + Word16 element_mode /* i : element mode */ ); -#ifndef REMOVE_EVS_DUPLICATES -// FEC_scale_sync_fx.c void FEC_scale_syn_fx( const Word16 L_frame, /* i : length of the frame */ Word16 *update_flg, /* o: flag indicating re-synthesis after scaling*/ @@ -8206,69 +8017,37 @@ void FEC_scale_syn_fx( Word16 *mem_syn, /* o: initial synthesis filter states */ Word16 Q_exc, Word16 Q_syn, + const Word16 element_mode, /* i : element mode */ const Word16 avoid_lpc_burst_on_recovery, /* i : if true the excitation energy is limited if LP has big gain */ - const Word16 force_scaling /* i: force scaling */ -); -#endif -void FEC_scale_syn_ivas_fx( - const Word16 L_frame, /* i : length of the frame */ - Word16 *update_flg, /* o: flag indicating re-synthesis after scaling*/ - Word16 clas, /* i/o: frame classification */ - const Word16 last_good, /* i: last good frame classification */ - Word16 *synth, /* i/o: synthesized speech at Fs = 12k8 Hz */ - const Word16 *pitch, /* i: pitch values for each subframe */ - Word32 L_enr_old, /* i: energy at the end of previous frame */ - Word32 L_enr_q, /* i: transmitted energy for current frame */ - const Word16 coder_type, /* i: coder type */ - const Word16 LSF_Q_prediction, /* i : LSF prediction mode */ - Word16 *scaling_flag, /* i/o: flag to indicate energy control of syn */ - Word32 *lp_ener_FEC_av, /* i/o: averaged voiced signal energy */ - Word32 *lp_ener_FEC_max, /* i/o: averaged voiced signal energy */ - const Word16 bfi, /* i: current frame BFI */ - const Word32 total_brate, /* i: total bitrate */ - const Word16 prev_bfi, /* i: previous frame BFI */ - const Word32 last_core_brate, /* i: previous frame core bitrate */ - Word16 *exc, /* i/o: excitation signal without enhancement */ - Word16 *exc2, /* i/o: excitation signal with enhancement */ - Word16 Aq[], /* i/o: LP filter coefs (can be modified if BR) */ - Word16 *old_enr_LP, /* i/o: LP filter E of last good voiced frame */ - const Word16 *mem_tmp, /* i: temp. initial synthesis filter states */ - Word16 *mem_syn, /* o: initial synthesis filter states */ - Word16 Q_exc, - Word16 Q_syn, -#ifdef REMOVE_EVS_DUPLICATES - const Word16 element_mode, /* i : element mode */ -#endif - const Word16 avoid_lpc_burst_on_recovery, /* i : if true the excitation energy is limited if LP has big gain */ - const Word16 force_scaling /* i: force scaling */ + const Word16 force_scaling /* i : force scaling */ ); // LD_music_post_filter_fx.c void LD_music_post_filter_fx( - MUSIC_POSTFILT_HANDLE hMusicPF, /* i/o: LD music postfilter handle */ - const Word16 dtc_in[], /* i : i synthesis Qdct */ - Word16 dtc_out[], /* o : output synthesis Qdct */ - const Word32 core_brate, /* i : core bitrate Q0 */ - Word16 *Old_ener_Q, /* i/o : Old energy scaling factor */ - const Word16 coder_type, /* i : Coder type : -1 in case of IO Q0 */ - const Word16 Last_coder_type, /* i : i scaling Q0 */ - const Word16 Qdct /* i : i scaling Q0 */ + MUSIC_POSTFILT_HANDLE hMusicPF, /* i/o: LD music postfilter handle */ + const Word16 dtc_in[], /* i : i synthesis Qdct */ + Word16 dtc_out[], /* o : output synthesis Qdct */ + const Word32 core_brate, /* i : core bitrate Q0 */ + Word16 *Old_ener_Q, /* i/o: Old energy scaling factor */ + const Word16 coder_type, /* i : Coder type : -1 in case of IO Q0 */ + const Word16 Last_coder_type, /* i : i scaling Q0 */ + const Word16 Qdct /* i : i scaling Q0 */ ); void Prep_music_postP_fx( - Word16 exc_buffer_in[], /* i/o: excitation buffer Q_exc*/ - Word16 dct_buffer_out[], /* o : DCT output buffer (qdct)*/ - Word16 filt_lfE[], /* i/o: long term spectrum energy Q15 */ - const Word16 last_core, /* i : last core */ - const Word16 element_mode, /* i : element mode */ - const Word16 *pitch_buf, /* i : current frame pitch information Q6*/ - Word16 *LDm_enh_lp_gbin, /* o : smoothed suppression gain, per bin FFT Q15*/ - const Word16 Q_exc, /* i : excitation scaling */ - Word16 *qdct /* o : Scaling factor of dct coefficient */ + Word16 exc_buffer_in[], /* i/o: excitation buffer Q_exc*/ + Word16 dct_buffer_out[], /* o : DCT output buffer (qdct)*/ + Word16 filt_lfE[], /* i/o: long term spectrum energy Q15 */ + const Word16 last_core, /* i : last core */ + const Word16 element_mode, /* i : element mode */ + const Word16 *pitch_buf, /* i : current frame pitch information Q6*/ + Word16 *LDm_enh_lp_gbin, /* o : smoothed suppression gain, per bin FFT Q15*/ + const Word16 Q_exc, /* i : excitation scaling */ + Word16 *qdct /* o : Scaling factor of dct coefficient */ ); void Post_music_postP_fx( - Word16 dct_buffer_in[], /* i/o: excitation buffer */ + Word16 dct_buffer_in[], /* i/o: excitation buffer */ Word16 *exc2, /* i/o: Current excitation to be overwriten */ const Word16 *mem_tmp, /* i : previous frame synthesis memory */ Word16 *st_mem_syn2, /* i/o: current frame synthesis memory */ @@ -8278,15 +8057,14 @@ void Post_music_postP_fx( Word16 *prev_Q_syn, /* i : previsous frame synthesis scaling */ Word16 *Q_syn, /* i : Current frame synthesis scaling */ Word16 *mem_syn_clas_estim_fx, /* i : old 12k8 synthesis used for frame classification*/ - const Word16 IsIO, /* i: Flag to indicate IO mode */ - Word16 *mem_deemph, /* i/o: speech deemph filter memory */ - Word16 *st_pst_old_syn_fx, /* i/o: psfiler */ - Word16 *st_pst_mem_deemp_err_fx, /* i/o: psfiler */ + const Word16 IsIO, /* i : Flag to indicate IO mode */ + Word16 *mem_deemph, /* i/o: speech deemph filter memory */ + Word16 *st_pst_old_syn_fx, /* i/o: psfiler */ + Word16 *st_pst_mem_deemp_err_fx, /* i/o: psfiler */ Word16 *mem_agc, - PFSTAT *pf_stat, /* i/o: All memories related to NB post filter */ - const Word16 *tmp_buffer /* tmp_buffer in Q-1 */ - , - Word16 *mem_tmp2 /* Temporary memory used with scale_syn */ + PFSTAT *pf_stat, /* i/o: All memories related to NB post filter */ + const Word16 *tmp_buffer, /* tmp_buffer in Q-1 */ + Word16 *mem_tmp2 /* Temporary memory used with scale_syn */ ); void music_postfilt_init( @@ -8503,29 +8281,17 @@ Word16 FEC_enhACB_fx( const Word16 puls_pos, /* i : decoder position of the last glottal pulses decoded in the previous frame */ const Word16 bfi_pitch /* i : Q6 pitch used for concealment */ ); -Word16 FEC_synchro_exc_fx( /* o : do_WI flag */ - const Word16 L_frame, /* i : length of the frame */ - Word16 *exc, /* i/o: exc vector to modify */ - const Word16 desire_puls_pos, /* i : Pulse position send by the encoder */ - const Word16 true_puls_pos, /* i : Present pulse location */ - const Word16 Old_pitch /* i : Pitch use to create temporary adaptive codebook */ + +/*! r: do_WI flag */ +Word16 FEC_synchro_exc_fx( + const Word16 L_frame, /* i : length of the frame */ + Word16 *exc, /* i/o: exc vector to modify */ + const Word16 desire_puls_pos, /* i : Pulse position send by the encoder */ + const Word16 true_puls_pos, /* i : Present pulse location */ + const Word16 Old_pitch /* i : Pitch use to create temporary adaptive codebook */ ); -#ifndef REMOVE_EVS_DUPLICATES -// dec_uv_fx.c void decod_unvoiced_fx( - Decoder_State *st_fx, /* i/o: decoder static memory */ - const Word16 *Aq_fx, /* Q12 i : LP filter coefficient */ - const Word16 coder_type, /* Q0 i : coding type */ - Word16 *tmp_noise_fx, /* Q5 o : long term temporary noise energy */ - Word16 *pitch_buf_fx, /* Q6 o : floating pitch values for each subframe */ - Word16 *voice_factors_fx, /* Q15 o : voicing factors */ - Word16 *exc_fx, /* Q_X o : adapt. excitation exc */ - Word16 *exc2_fx, /* Q_X o : adapt. excitation/total exc */ - Word16 *bwe_exc_fx, /* Q_X i/o: excitation for SWB TBE */ - Word16 *gain_buf ); -#endif -void decod_unvoiced_ivas_fx( Decoder_State *st_fx, /* i/o: decoder static memory */ const Word16 *Aq_fx, /* Q12 i : LP filter coefficient */ const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ @@ -8568,38 +8334,20 @@ void gaus_L2_dec( Word16 *seed_acelp /*i/o : random seed Q0 */ ); -#ifndef REMOVE_EVS_DUPLICATES -// dec_gen_voic_fx.c ivas_error decod_gen_voic_fx( - Decoder_State *st_fx, /* i/o: decoder static memory */ - const Word16 L_frame_fx, /* i : length of the frame */ - const Word16 sharpFlag_fx, /* i : formant sharpening flag */ - const Word16 *Aq_fx, /* i : LP filter coefficient */ - const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ - const Word16 do_WI_fx, /* i : do interpolation after a FER */ - Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe */ - Word16 *voice_factors_fx, /* o : voicing factors */ - Word16 *exc_fx, /* i/o: adapt. excitation exc */ - Word16 *exc2_fx, /* i/o: adapt. excitation/total exc */ - Word16 *bwe_exc_fx, /* o : excitation for SWB TBE */ - Word16 *unbits, /* number of unused bits */ - Word16 *gain_buf /*Q14*/ -); -#endif -ivas_error decod_gen_voic_ivas_fx( - Decoder_State *st_fx, /* i/o: decoder static memory */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 sharpFlag_fx, /* i : formant sharpening flag */ - const Word16 *Aq_fx, /* i : LP filter coefficient */ - const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ - const Word16 do_WI_fx, /* i : do interpolation after a FER */ - Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe */ - Word16 *voice_factors_fx, /* o : voicing factors */ - Word16 *exc_fx, /* i/o: adapt. excitation exc */ - Word16 *exc2_fx, /* i/o: adapt. excitation/total exc */ - Word16 *bwe_exc_fx, /* o : excitation for SWB TBE */ - Word16 *unbits, /* number of unused bits */ - Word16 *gain_buf, + Decoder_State *st_fx, /* i/o: decoder static memory */ + const Word16 L_frame, /* i : length of the frame */ + const Word16 sharpFlag_fx, /* i : formant sharpening flag */ + const Word16 *Aq_fx, /* i : LP filter coefficient */ + const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ + const Word16 do_WI_fx, /* i : do interpolation after a FER */ + Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe */ + Word16 *voice_factors_fx, /* o : voicing factors */ + Word16 *exc_fx, /* i/o: adapt. excitation exc */ + Word16 *exc2_fx, /* i/o: adapt. excitation/total exc */ + Word16 *bwe_exc_fx, /* o : excitation for SWB TBE */ + Word16 *unbits, /* number of unused bits */ + Word16 *gain_buf, /* o : Word16 pitch gain for each subframe Q14*/ const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer */ ); @@ -9501,33 +9249,6 @@ void d_gain_pred_fx( Word16 **pt_indice /* i/o: pointer to the buffer of indices */ ); -#ifndef REMOVE_EVS_DUPLICATES -// acelp_core_dec_fx.c -ivas_error acelp_core_dec_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 output[], /* o : synthesis @internal Fs */ - Word16 synth_out[], /* o : synthesis */ - Word16 save_hb_synth[], /* o : HB synthesis */ - Word32 bwe_exc_extended[], /* i/o: bandwidth extended excitation */ - Word16 *voice_factors, /* o : voicing factors */ - Word16 old_syn_12k8_16k[], /* o : intermediate ACELP synthesis for SWB BWE */ - Word16 sharpFlag, - Word16 pitch_buf_fx[NB_SUBFR16k], /* o : floating pitch for each subframe */ - Word16 *unbits, /* o : number of unused bits */ - Word16 *sid_bw /* o : 0-NB/WB, 1-SWB SID */ - , - STEREO_TD_DEC_DATA_HANDLE hStereoTD, /* i/o: TD stereo decoder handle */ - const Word16 tdm_lspQ_PCh[M], /* i : Q LSPs for primary channel */ - const Word16 tdm_lsfQ_PCh[M], /* i : Q LSFs for primary channel */ - const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ - const Word16 last_element_mode, /* i : last element mode */ - const Word32 last_element_brate, /* i : last element bitrate */ - const Word16 flag_sec_CNA, /* i : CNA flag for secondary channel */ - const Word16 nchan_out, /* i : number of output channels */ - STEREO_CNG_DEC_HANDLE hStereoCng, /* i : stereo CNG handle */ - const Word16 read_sid_info /* i : read SID info flag */ -); -#endif // evs_dec_fx.c ivas_error evs_dec_fx( Decoder_State *st_fx, /* i/o : Decoder state structure */ @@ -10617,7 +10338,7 @@ Word16 swb_bwe_dec_fx32( Word16 output_frame /* i : frame length */ ); -ivas_error acelp_core_dec_ivas_fx( +ivas_error acelp_core_dec_fx( Decoder_State *st, /* i/o: decoder state structure */ Word16 output_fx[], /* o : synthesis @internal Fs */ Word16 synth_fx16[], /* o : synthesis */ @@ -10914,6 +10635,7 @@ Word16 ari_decode_14bits_pow_ivas( Word16 *res, Tastat *s, UWord16 base ); + Word16 ari_decode_14bits_sign_ivas( Word16 *ptr, Word16 bp, @@ -10927,22 +10649,21 @@ void lsf_syn_mem_backup_ivas_fx( Word32 *gc_threshold_fx, /* i: Q16 */ Word16 *clip_var_bck_fx, /* o: Q(2.56), Q14, Q7, Q0, Q14, Q14 */ Word16 *next_force_sf_bck_fx, /* o: */ - - Word16 *lsp_new, /* i: LSP vector to quantize Q15 */ - Word16 *lsp_mid, /* i: mid-frame LSP vector Q15 */ - Word16 *clip_var, /* o: pitch clipping state var Q(2.56) */ - Word16 *mem_AR, /* o: quantizer memory for AR model Q(2.56) */ - Word16 *mem_MA, /* o: quantizer memory for AR model Q(2.56) */ - Word16 *lsp_new_bck, /* o: LSP vector to quantize- backup Q15 */ - Word16 *lsp_mid_bck, /* o: mid-frame LSP vector - backup Q15 */ - Word32 *Bin_E, /* o: FFT Bin energy 128 *2 sets Q_new + Q_SCALE - 2 */ - Word32 *Bin_E_old, /* o: FFT Bin energy 128 sets Q_new + Q_SCALE - 2 */ - Word16 *mem_syn_bck, /* o: synthesis filter memory ( 15 - st_fx->hLPDmem->e_mem_syn ) */ - Word16 *mem_w0_bck, /* o: memory of the weighting filter ( 15 - st_fx->hLPDmem->e_mem_syn ) */ - Word16 *streaklimit, /* Q15 */ + Word16 *lsp_new, /* i: LSP vector to quantize Q15 */ + Word16 *lsp_mid, /* i: mid-frame LSP vector Q15 */ + Word16 *clip_var, /* o: pitch clipping state var Q(2.56) */ + Word16 *mem_AR, /* o: quantizer memory for AR model Q(2.56) */ + Word16 *mem_MA, /* o: quantizer memory for AR model Q(2.56) */ + Word16 *lsp_new_bck, /* o: LSP vector to quantize- backup Q15 */ + Word16 *lsp_mid_bck, /* o: mid-frame LSP vector - backup Q15 */ + Word32 *Bin_E, /* o: FFT Bin energy 128 *2 sets Q_new + Q_SCALE - 2 */ + Word32 *Bin_E_old, /* o: FFT Bin energy 128 sets Q_new + Q_SCALE - 2 */ + Word16 *mem_syn_bck, /* o: synthesis filter memory ( 15 - st_fx->hLPDmem->e_mem_syn ) */ + Word16 *mem_w0_bck, /* o: memory of the weighting filter ( 15 - st_fx->hLPDmem->e_mem_syn ) */ + Word16 *streaklimit, /* Q15 */ Word16 *pstreaklen ); -ivas_error config_acelp1_IVAS( +ivas_error config_acelp1_fx( const Word16 enc_dec, /* i : encoder/decoder flag */ const Word32 total_brate, /* i : total bitrate */ const Word32 core_brate_inp, /* i : core bitrate */ diff --git a/lib_com/swb_tbe_com_fx.c b/lib_com/swb_tbe_com_fx.c index d3f671631..08bbd6362 100644 --- a/lib_com/swb_tbe_com_fx.c +++ b/lib_com/swb_tbe_com_fx.c @@ -7023,50 +7023,6 @@ void synthesise_fb_high_band_fx( tmp3 = add( sub( Qout, add( sub( 1, exp ), exp_tmp ) ), 16 ); /*Qout - (1 -exp +exp_tmp) + 16 */ FOR( i = 0; i < L_FRAME48k; i++ ) { -#ifdef FIX_1439_SPEEDUP_synthesise_fb_high_band_fx - L_tmp = Mult_32_16( ratio2, tmp[i] ); /* Q(16-exp+exp_tmp-15 = 1-exp+exp_tmp) */ - Word32 L_tmp32 = L_add( 0, 0 ); - Word16 tmp16 = add( 0, 0 ); - - // if (L_tmp < 0) - if ( L_tmp < 0 ) - { - L_tmp32 = L_negate( L_tmp ); - } - if ( L_tmp < 0 ) - { - L_tmp32 = L_shl_sat( L_tmp32, tmp3 ); - } - if ( L_tmp < 0 ) - { - tmp16 = extract_h( L_tmp32 ); - } - if ( L_tmp < 0 ) - { - tmp16 = negate( tmp16 ); - } - - // if (L_tmp == 0) - if ( L_tmp == 0 ) - { - tmp16 = 0; - move16(); - } - - // if (L_tmp > 0) - if ( L_tmp > 0 ) - { - L_tmp32 = L_shl_sat( L_tmp, tmp3 ); - } - if ( L_tmp > 0 ) - { - tmp16 = extract_h( L_tmp32 ); - } - - output[i] = tmp16; - move16(); - -#else L_tmp = Mult_32_16( ratio2, tmp[i] ); /* Q(16-exp+exp_tmp-15 = 1-exp+exp_tmp) */ IF( L_tmp < 0 ) { @@ -7078,7 +7034,6 @@ void synthesise_fb_high_band_fx( output[i] = extract_h( L_shl_sat( L_tmp, tmp3 ) ); /*Qout*/ move16(); } -#endif } return; } @@ -7253,180 +7208,34 @@ void Estimate_mix_factors_fx( /* INPUT/OUTPUT ARGUMENTS : */ /* _ (Word16[]) bwe_exc_fx : excitation for TBE (Q_exc) */ /*--------------------------------------------------------------------------------------*/ - /* _ None */ /*--------------------------------------------------------------------------------------*/ /* RETURN ARGUMENTS : */ /* _ None */ /*======================================================================================*/ -#ifndef REMOVE_EVS_DUPLICATES void prep_tbe_exc_fx( - const Word16 L_frame_fx, /* i : length of the frame */ - const Word16 i_subfr_fx, /* i : subframe index */ - const Word16 gain_pit_fx, /* i : Pitch gain Q14*/ - const Word32 gain_code_fx, /* i : algebraic codebook gain 16+Q_exc*/ - const Word16 code_fx[], /* i : algebraic excitation Q9*/ - const Word16 voice_fac_fx, /* i : voicing factor Q15*/ - Word16 *voice_factors_fx, /* o : TBE voicing factor Q15*/ - Word16 bwe_exc_fx[], /* i/o: excitation for TBE Q_exc*/ - const Word16 gain_preQ_fx, /* i : prequantizer excitation gain */ - const Word16 code_preQ_fx[], /* i : prequantizer excitation */ - const Word16 Q_exc, /* i : Excitation, bwe_exc Q-factor */ - Word16 T0, /* i : integer pitch variables Q0 */ - Word16 T0_frac, /* i : Fractional pitch variables Q0*/ - const Word16 coder_type, /* i : coding type */ - Word32 core_brate ) -{ - Word16 i; - Word16 tmp_code_fx[2 * L_SUBFR * HIBND_ACB_L_FAC]; - Word16 tmp_code_preInt_fx[L_SUBFR]; - Word16 gain_code16 = 0; - move16(); - Word16 tmp /*, tmp1, tmp2*/; - /*Word16 random_code[L_SUBFR * HIBND_ACB_L_FAC];*/ - Word16 pitch; - - Word32 L_tmp, Ltemp1, Ltemp2; - Word32 tempQ31; - Word16 tempQ15; - Word16 L_subfr = L_SUBFR; - move16(); -#ifdef BASOP_NOGLOB_DECLARE_LOCAL - Flag Overflow = 0; - move32(); -#endif - - /**voice_factors = VF_0th_PARAM + VF_1st_PARAM * voice_fac + VF_2nd_PARAM * voice_fac * voice_fac; - = VF_0th_PARAM + voice_fac * (VF_1st_PARAM + VF_2nd_PARAM * voice_fac ) - *voice_factors = min( max_val(0.0f, *voice_factors), 1.0f); */ - tempQ31 = L_deposit_h( VF_1st_PARAM_FX ); - tempQ15 = mac_r( tempQ31, VF_2nd_PARAM_FX, voice_fac_fx ); - tempQ31 = L_deposit_h( VF_0th_PARAM_FX ); - *voice_factors_fx = mac_r( tempQ31, voice_fac_fx, tempQ15 ); - move16(); - tmp = MAX_16; - move16(); - - pitch = shl_o( add( shl_o( T0, 2, &Overflow ), T0_frac ), 5, &Overflow ); /* Q7 */ + const Word16 L_frame_fx, /* i : length of the frame */ + const Word16 L_subfr, /* i : subframe length */ + const Word16 i_subfr_fx, /* i : subframe index */ + const Word16 gain_pit_fx, /* i : Pitch gain Q14*/ + const Word32 gain_code_fx, /* i : algebraic codebook gain 16+Q_exc*/ + const Word16 code_fx[], /* i : algebraic excitation Q9*/ + const Word16 voice_fac_fx, /* i : voicing factor Q15*/ + Word16 *voice_factors_fx, /* o : TBE voicing factor Q15*/ + Word16 bwe_exc_fx[], /* i/o: excitation for TBE Q_exc*/ + const Word16 gain_preQ_fx, /* i : prequantizer excitation gain */ + const Word16 code_preQ_fx[], /* i : prequantizer excitation */ + const Word16 Q_exc, /* i : Excitation, bwe_exc Q-factor */ + const Word16 T0, /* i : integer pitch variables Q0 */ + const Word16 T0_frac, /* i : Fractional pitch variables Q0*/ + const Word16 coder_type, /* i : coding type */ + const Word32 core_brate, /* i : core bitrate */ + const Word16 element_mode, /* i : element mode */ + const Word16 idchan, /* i : channel ID */ + const Word16 flag_TD_BWE, /* i : flag indicating whether hTD_BWE exists */ + const Word16 tdm_LRTD_flag /* i : LRTD stereo mode flag */ - test(); - test(); - IF( ( ( EQ_16( coder_type, VOICED ) ) || ( GT_16( pitch, 14784 /* 115.5 in Q7 */ ) ) ) && ( GT_32( core_brate, ACELP_8k00 ) ) ) - { - tmp = MAX_16; - move16(); - *voice_factors_fx = mult_r( *voice_factors_fx, tmp ); - move16(); - } - - *voice_factors_fx = s_min( s_max( *voice_factors_fx, 0 ), MAX_16 ); - move16(); - IF( EQ_16( L_frame_fx, L_FRAME ) ) - { - interp_code_5over2_fx( code_fx, tmp_code_fx, L_subfr ); /* code: Q9, tmp_code: Q9 */ - gain_code16 = round_fx_o( L_shl_o( gain_code_fx, Q_exc, &Overflow ), &Overflow ); /*Q_exc */ - FOR( i = 0; i < L_subfr * HIBND_ACB_L_FAC; i++ ) - { - L_tmp = L_mult( gain_code16, tmp_code_fx[i] ); /* Q9 + Q_exc + 1*/ - L_tmp = L_shl_sat( L_tmp, 5 ); /* Q9 + Q_exc + Q6*/ - L_tmp = L_mac_sat( L_tmp, gain_pit_fx, bwe_exc_fx[i + i_subfr_fx * HIBND_ACB_L_FAC] ); /*Q15+Q_exc */ - L_tmp = L_shl_o( L_tmp, 1, &Overflow ); /*16+Q_exc */ /* saturation can occur here */ - bwe_exc_fx[i + i_subfr_fx * HIBND_ACB_L_FAC] = round_fx_o( L_tmp, &Overflow ); /*Q_exc */ - move16(); - } - } - ELSE - { - IF( gain_preQ_fx != 0 ) - { - FOR( i = 0; i < L_subfr; i++ ) - { - /*code in the encoder is Q9 and there is no <<1 with Mult_32_16 Q16 * Q9 -> Q9 */ - Ltemp1 = Mult_32_16( gain_code_fx, code_fx[i] ); /* Q16 + Q9 + 1 - 16 = Q10 */ - Ltemp2 = L_mult( gain_preQ_fx, code_preQ_fx[i] ); /*Q2 * Q10 -> Q12 */ - - Ltemp1 = L_shl_o( Ltemp1, add( Q_exc, 6 ) /*Q_exc+16-19*/, &Overflow ); /*Q_exc+16 */ - Ltemp2 = L_shl_o( Ltemp2, add( Q_exc, 4 ) /*Q_exc+16-13*/, &Overflow ); /*Q_exc+16 */ - - tmp_code_preInt_fx[i] = round_fx_o( L_add_o( Ltemp1, Ltemp2, &Overflow ), &Overflow ); /* Q_exc */ - move16(); - } - } - ELSE - { - FOR( i = 0; i < L_subfr; i++ ) - { - /*code in the encoder is Q9 and there is no <<1 with Mult_32_16 Q16 * Q9 -> Q9 */ - Ltemp1 = Mult_32_16( gain_code_fx, code_fx[i] ); /* Q16 + Q9 + 1 - 16 = Q10 */ - Ltemp1 = L_shl_o( Ltemp1, add( Q_exc, 6 ) /*Q_exc+16-19*/, &Overflow ); /*Q_exc+16 */ - tmp_code_preInt_fx[i] = round_fx_o( Ltemp1, &Overflow ); /* Q_exc */ - move16(); - } - } - - interp_code_4over2_fx( tmp_code_preInt_fx, tmp_code_fx, L_subfr ); /* o: tmp_code in Q_exc */ - FOR( i = 0; i < L_subfr * 2; i++ ) - { - L_tmp = L_mult( gain_pit_fx, bwe_exc_fx[i + i_subfr_fx * 2] ); /*Q14+Q_exc+1 */ - tmp = round_fx_o( L_shl_o( L_tmp, 1 /* (Q_exc+16)-(14+Q_exc+1)*/, &Overflow ), &Overflow ); /* tmp in Q_exc */ - bwe_exc_fx[i + i_subfr_fx * 2] = add_o( tmp, tmp_code_fx[i], &Overflow ); /*Q_exc */ - move16(); - } - } - - return; -} - -/*======================================================================================*/ -/* FUNCTION : prep_tbe_exc_ivas_fx() */ -/*--------------------------------------------------------------------------------------*/ -/* PURPOSE : Prepare TBE excitation */ -/*--------------------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16) L_frame_fx : length of the frame */ -/* _ (Word16) i_subfr_fx : subframe index */ -/* _ (Word16) gain_pit_fx : Pitch gain (14) */ -/* _ (Word32) gain_code_fx : algebraic codebook gain (Q(16+Q_exc)) */ -/* _ (Word16*[]) code_fx : algebraic excitation (Q9) */ -/* _ (Word16) voice_fac_fx : voicing factor (Q15) */ -/* _ (Word16) gain_preQ_fx : prequantizer excitation gain */ -/* _ (Word16[]) code_preQ_fx : prequantizer excitation */ -/*--------------------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16*[]) voice_factors_fx : TBE voicing factor (Q15) */ -/*--------------------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ (Word16[]) bwe_exc_fx : excitation for TBE (Q_exc) */ -/*--------------------------------------------------------------------------------------*/ - -/* _ None */ -/*--------------------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*======================================================================================*/ -#endif -void prep_tbe_exc_ivas_fx( - const Word16 L_frame_fx, /* i : length of the frame */ - const Word16 L_subfr, - const Word16 i_subfr_fx, /* i : subframe index */ - const Word16 gain_pit_fx, /* i : Pitch gain Q14*/ - const Word32 gain_code_fx, /* i : algebraic codebook gain 16+Q_exc*/ - const Word16 code_fx[], /* i : algebraic excitation Q9*/ - const Word16 voice_fac_fx, /* i : voicing factor Q15*/ - Word16 *voice_factors_fx, /* o : TBE voicing factor Q15*/ - Word16 bwe_exc_fx[], /* i/o: excitation for TBE Q_exc*/ - const Word16 gain_preQ_fx, /* i : prequantizer excitation gain */ - const Word16 code_preQ_fx[], /* i : prequantizer excitation */ - const Word16 Q_exc, /* i : Excitation, bwe_exc Q-factor */ - Word16 T0, /* i : integer pitch variables Q0 */ - Word16 T0_frac, /* i : Fractional pitch variables Q0*/ - const Word16 coder_type, /* i : coding type */ - Word32 core_brate, /* i : core bitrate */ - const Word16 element_mode, /* i : element mode */ - const Word16 idchan, /* i : channel ID */ - const Word16 flag_TD_BWE, /* i : flag indicating whether hTD_BWE exists */ - const Word16 tdm_LRTD_flag /* i : LRTD stereo mode flag */ ) { Word16 i; @@ -7543,6 +7352,7 @@ void prep_tbe_exc_ivas_fx( return; } + /*=============================================================================*/ /* FUNCTION : void swb_formant_fac_fx ( ) */ /*------------------------------------------------------------------------------*/ @@ -7562,9 +7372,10 @@ void prep_tbe_exc_ivas_fx( /* CALLED FROM : */ /*==============================================================================*/ -Word16 swb_formant_fac_fx( /* o : Formant filter strength [0,1] */ - const Word16 lpc_shb2, /* Q12 i : 2nd HB LPC coefficient */ - Word16 *tilt_mem /* i/o: Tilt smoothing memory (Q12) */ +/*! r: Formant filter strength [0,1] */ +Word16 swb_formant_fac_fx( + const Word16 lpc_shb2, /* Q12 i : 2nd HB LPC coefficient */ + Word16 *tilt_mem /* i/o: Tilt smoothing memory (Q12) */ ) { Word16 formant_fac; @@ -7584,7 +7395,6 @@ Word16 swb_formant_fac_fx( /* o : Formant filter strength tmp = sub( tmp, SWB_TILT_LOW_FX ); /* Q12 */ formant_fac = mult_r( tmp, SWB_TILT_DELTA_FX ); /* Q12 */ - IF( GT_16( formant_fac, 4096 /* 1 in Q12 */ ) ) { formant_fac = 4096; /* 1 in Q12 */ @@ -7604,6 +7414,12 @@ Word16 swb_formant_fac_fx( /* o : Formant filter strength } +/*-------------------------------------------------------------------* + * wb_tbe_extras_reset_fx() + * + * + *-------------------------------------------------------------------*/ + void wb_tbe_extras_reset_fx( Word16 mem_genSHBexc_filt_down_wb2[], Word16 mem_genSHBexc_filt_down_wb3[] ) @@ -7620,7 +7436,6 @@ void wb_tbe_extras_reset_fx( * Determine TBE bit consumption per frame from bitrate * *-------------------------------------------------------------------*/ - Word16 get_tbe_bits_fx( const Word32 total_brate, /* o : TBE bit consumption per frame */ const Word16 bwidth, /* i : overall bitrate */ diff --git a/lib_dec/FEC_fx.c b/lib_dec/FEC_fx.c index a23c9aa90..48d91a87a 100644 --- a/lib_dec/FEC_fx.c +++ b/lib_dec/FEC_fx.c @@ -510,19 +510,10 @@ void FEC_exc_estim_fx( move16(); /* st_fx->L_frame / L_SUBFR */ tmp = shr( st_fx->L_frame, 6 ); + /* Replication of the last spectrum, with a slight downscaling of its dynamic */ -#ifdef REMOVE_EVS_DUPLICATES - gsc_dec_ivas_fx( st_fx, exc_dct_in, hGSCDec->Last_GSC_pit_band_idx, Diff_len, 0, tmp, st_fx->last_coder_type, &last_bin_fx, lsf_new, NULL, &st_fx->Q_exc ); -#else - IF( st_fx->element_mode == EVS_MONO ) - { - gsc_dec_fx( st_fx, exc_dct_in, hGSCDec->Last_GSC_pit_band_idx, Diff_len, 0, tmp, st_fx->last_coder_type, &last_bin_fx, lsf_new, NULL, st_fx->Q_exc ); - } - ELSE - { - gsc_dec_ivas_fx( st_fx, exc_dct_in, hGSCDec->Last_GSC_pit_band_idx, Diff_len, 0, tmp, st_fx->last_coder_type, &last_bin_fx, lsf_new, NULL, &st_fx->Q_exc ); - } -#endif + gsc_dec_fx( st_fx, exc_dct_in, hGSCDec->Last_GSC_pit_band_idx, Diff_len, 0, tmp, st_fx->last_coder_type, &last_bin_fx, lsf_new, NULL, &st_fx->Q_exc ); + *tmp_noise = shr_r( st_fx->lp_gainc_fx, 3 ); /*Q0*/ move16(); /* Transform back to time domain */ diff --git a/lib_dec/FEC_scale_syn_fx.c b/lib_dec/FEC_scale_syn_fx.c index 714a60166..7f4586083 100644 --- a/lib_dec/FEC_scale_syn_fx.c +++ b/lib_dec/FEC_scale_syn_fx.c @@ -50,7 +50,6 @@ /* _ None */ /*========================================================================*/ -#ifndef REMOVE_EVS_DUPLICATES void FEC_scale_syn_fx( const Word16 L_frame, /* i : length of the frame */ Word16 *update_flg, /* o: flag indicating re-synthesis after scaling*/ @@ -77,574 +76,7 @@ void FEC_scale_syn_fx( Word16 *mem_syn, /* o: initial synthesis filter states Q_syn*/ Word16 Q_exc, Word16 Q_syn, - const Word16 avoid_lpc_burst_on_recovery, /* i : if true the excitation energy is limited if LP has big gain */ - const Word16 force_scaling /* i: force scaling */ -) -{ - Word16 i; - Word32 L_enr1, L_enr2; - Word16 gain1, gain2, enr_LP; - Word16 tmp, tmp2, exp, exp2; - Word16 tmp3; - Word32 L_tmp; - Word16 scaling; - Word32 ener_max, L_enr2_av, L_ener2_max; - Word16 h1[L_FRAME / 2], tilt, pitch_dist, mean_pitch; - Word16 k; - Word32 L_mean_pitch; - - enr_LP = 0; - move16(); - gain2 = 0; - move16(); - gain1 = 0; - move16(); - *update_flg = 0; - move16(); - L_enr_old = L_max( 1, L_enr_old ); /* to avoid division by zero (*L_enr_old is always >= 0) */ - scaling = 16384; - move16(); /* Q14*/ - - /*-----------------------------------------------------------------* - * Find the synthesis filter impulse response on voiced - *-----------------------------------------------------------------*/ - test(); - IF( GE_16( clas, VOICED_TRANSITION ) && LT_16( clas, INACTIVE_CLAS ) ) - { - IF( EQ_16( L_frame, L_FRAME ) ) - { - enr_LP = Enr_1_Az_fx( Aq + ( NB_SUBFR - 1 ) * ( M + 1 ), L_SUBFR ); - } - ELSE /* L_frame == L_FRAME16k */ - { - enr_LP = Enr_1_Az_fx( Aq + ( NB_SUBFR16k - 1 ) * ( M + 1 ), L_SUBFR ); /*Q3*/ - } - } - - /*-----------------------------------------------------------------* - * Define when to scale the synthesis - *-----------------------------------------------------------------*/ - - IF( bfi ) - { - *scaling_flag = 1; - move16(); /* Always check synthesis on bad frames */ - } - ELSE IF( prev_bfi ) - { - test(); - IF( ( EQ_16( LSF_Q_prediction, AUTO_REGRESSIVE ) ) || ( EQ_16( LSF_Q_prediction, MOVING_AVERAGE ) ) ) - { - *scaling_flag = 2; - move16(); /* Decoded LSFs affected */ - } - ELSE IF( NE_16( coder_type, TRANSITION ) ) - { - *scaling_flag = 1; - move16(); /* SN, but not TC mode - LSF still affected by the interpolation */ - } - ELSE - { - *scaling_flag = 0; - move16(); /* LSF still possibly affected due to interpolation */ - } - scaling = 24576; /*1.5 Q14*/ - move16(); - } - ELSE - { - test(); - IF( ( EQ_16( LSF_Q_prediction, AUTO_REGRESSIVE ) ) && ( EQ_16( *scaling_flag, 2 ) ) ) - { - *scaling_flag = 2; - move16(); /* Continue with energy control till the end of AR prediction */ - } - ELSE IF( *scaling_flag > 0 ) - { - ( *scaling_flag ) = sub( *scaling_flag, 1 ); /* If scaling flag was equal to 2, add one control frame to account for the LSF interpolation */ - move16(); - } - scaling = 32767; /*2.0 Q14*/ - move16(); - } - - /*-----------------------------------------------------------------* - * Find the energy/gain at the end of the frame - *-----------------------------------------------------------------*/ - - frame_ener_fx( L_frame, clas, synth, pitch[( L_frame >> 6 ) - 1], &L_enr2 /*Q0*/, 1, Q_syn, 3, 0 ); - - - test(); - test(); - IF( bfi || ( EQ_32( total_brate, ACELP_7k20 ) ) || ( EQ_32( total_brate, ACELP_8k00 ) ) ) - { - /* previous frame erased and no TC frame */ - IF( *scaling_flag > 0 ) - { - /*enr2 += 0.01f;*/ - L_enr2 = L_max( L_enr2, 1 ); /* L_enr2 is in Q0 */ - - IF( bfi ) /* In all bad frames, limit the gain to 1 */ - { - /* gain2 = (float)sqrt( enr_old / enr2 );*/ - L_tmp = Sqrt_Ratio32( L_enr_old, 0, L_enr2, 0, &exp2 ); - gain2 = round_fx_sat( L_shl_sat( L_tmp, sub( exp2, 1 ) ) ); /* in Q14 */ - - /*if( gain2 > 1.0f )gain2 = 1.0f;*/ - gain2 = s_min( gain2, 16384 ); - - /* find the energy/gain at the beginning of the frame */ - frame_ener_fx( L_frame, clas, synth, pitch[0], &L_enr1 /*Q0*/, 1, Q_syn, 3, 0 ); - - /*enr1 += 0.1f;*/ - L_enr1 = L_max( L_enr1, 1 ); /* L_enr2 is in Q0 */ - - /*gain1 = (float)sqrt( enr_old / enr1 );*/ - L_tmp = Sqrt_Ratio32( L_enr_old, 0, L_enr1, 0, &exp2 ); - gain1 = round_fx_sat( L_shl_sat( L_tmp, sub( exp2, 1 ) ) ); /* in Q14 */ - - /*if( gain1 > 1.0f )gain1 = 1.0f;*/ - gain1 = s_min( gain1, 16384 ); /*Q14*/ - } - ELSE /* good frame */ - { - IF( L_enr_q == 0 ) /* If E info (FEC protection bits) is not available in the bitstream */ - { - L_enr_q = L_enr2; /*Q0*/ - set16_fx( h1, 0, L_FRAME / 2 ); - h1[0] = 1024; /*1.0f in Q10*/ - move16(); - /*syn_filt( Aq+(3*(M+1)), M, h1, h1, L_FRAME/2, h1+(M+1), 0 );*/ - E_UTIL_synthesis( 1, Aq + ( 3 * ( M + 1 ) ), h1, h1, L_FRAME / 2, h1 + ( M + 1 ), 0, M ); - - /*Compute tilt */ - /*rr0 = dotp( h1, h1, L_FRAME/2-1 ) + 0.1f;*/ - /*rr1 = dotp( h1, h1+1, L_FRAME/2-1 );*/ - /*tilt = rr1 / rr0;*/ - tilt = extract_h( L_shl_sat( get_gain( h1 + 1, h1, L_FRAME / 2 - 1 ), 15 ) ); /*Q15*/ - pitch_dist = 0; - move16(); - L_mean_pitch = L_mult( pitch[0], 8192 /*1.0f in Q13*/ ); /*Q14*/ - FOR( k = 0; k < ( NB_SUBFR - 1 ); k++ ) - { - pitch_dist = add( pitch_dist, abs_s( sub( pitch[k + 1], pitch[k] ) ) ); /*Q0*/ - L_mean_pitch = L_mac( L_mean_pitch, pitch[k + 1], 8192 ); /*Q14*/ - } - /*pitch_dist /= (float)(NB_SUBFR-1); */ - pitch_dist = mult_r( shl( pitch_dist, 4 ), 10923 /*1/(float)(NB_SUBFR-1) in Q15*/ ); /*Q4*/ - /*mean_pitch /= (float)(NB_SUBFR);*/ - mean_pitch = extract_h( L_shl( L_mean_pitch, 4 ) ); /*Q4*/ - - - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( GT_16( tilt, 22938 ) ) && /* HF resonnant filter */ - ( ( GT_16( pitch_dist, 8 << 4 ) ) || ( LT_16( mean_pitch, PIT_MIN << 4 ) ) ) && /* pitch unstable or very short */ - ( ( prev_bfi ) || ( ( EQ_16( coder_type, GENERIC ) ) && ( EQ_16( LSF_Q_prediction, AUTO_REGRESSIVE ) ) ) ) ) - { - /*if( enr_q > scaling * enr_old ){enr_q = scaling * enr_old;}*/ - L_enr_q = L_min( L_enr_q, L_shl_sat( Mult_32_16( L_enr_old, scaling ), 1 ) ); /* scaling in Q14*/ - } - ELSE - { - ener_max = *lp_ener_FEC_max; /*Q0*/ - move32(); - test(); - if ( EQ_16( clas, VOICED_TRANSITION ) || ( GE_16( clas, INACTIVE_CLAS ) ) ) - { - ener_max = *lp_ener_FEC_av; /*Q0*/ - move32(); - } - /*if( enr_old > ener_max )ener_max = enr_old;*/ - ener_max = L_max( ener_max, L_enr_old ); - - /*if( enr_q > scaling * ener_max ){enr_q = scaling * ener_max;}*/ - L_enr_q = L_min( L_enr_q, L_shl_sat( Mult_32_16( ener_max, scaling ), 1 ) ); /* scaling in Q14*/ - } - } - /*gain2 = (float)sqrt( enr_q / enr2 );*/ - L_enr_q = L_max( L_enr_q, 1 ); /* L_enr2 is in Q0 */ - L_tmp = Sqrt_Ratio32( L_enr_q, 0, L_enr2, 0, &exp2 ); - gain2 = round_fx( L_shl( L_tmp, sub( exp2, 1 ) ) ); /* in Q14 */ - - /*-----------------------------------------------------------------* - * Find the energy/gain at the beginning of the frame to ensure smooth transition after erasure(s) - *-----------------------------------------------------------------*/ - - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( ( GE_16( last_good, VOICED_TRANSITION ) && LT_16( last_good, INACTIVE_CLAS ) && ( clas == UNVOICED_CLAS || EQ_16( clas, INACTIVE_CLAS ) ) ) || - EQ_32( last_core_brate, SID_1k75 ) || EQ_32( last_core_brate, SID_2k40 ) || last_core_brate == FRAME_NO_DATA ) && - prev_bfi ) - { - /* voiced -> unvoiced signal transition */ - /* CNG -> active signal transition */ - gain1 = gain2; /*Q14*/ - move16(); - } - ELSE - { - /* find the energy at the beginning of the frame */ - frame_ener_fx( L_frame, clas, synth, pitch[0], &L_enr1 /*Q0*/, 1, Q_syn, 3, 0 ); - - /*enr1 += 0.1f;*/ - L_enr1 = L_max( L_enr1, 1 ); /* L_enr1 is in Q0 */ - - /*gain1 = (float)sqrt( enr_old / enr1 );*/ - L_tmp = Sqrt_Ratio32( L_enr_old, 0, L_enr1, 0, &exp2 ); - gain1 = round_fx_sat( L_shl_sat( L_tmp, sub( exp2, 1 ) ) ); /* in Q14 */ - - /*if( gain1 > 1.2f )gain1 = 1.2f;*/ - /* prevent clipping */ - gain1 = s_min( gain1, 19661 /*1.2f in Q14*/ ); - - /* prevent amplifying the unvoiced or inactive part of the frame in case an offset is followed by an onset */ - test(); - test(); - if ( EQ_16( clas, ONSET ) && GT_16( gain1, gain2 ) && prev_bfi ) - { - gain1 = gain2; /*Q14*/ - move16(); - } - } - - L_enr2 = L_enr_q; /*Q0*/ - move32(); /* Set the end frame energy to the scaled energy, to be used in the lp_ener_FEC */ - } - - /*------------------------------------------------------------------------------* - * Smooth the energy evolution by exponentially evolving from gain1 to gain2 - *------------------------------------------------------------------------------*/ - - /*gain2 *= ( 1.0f - AGC );*/ - L_tmp = L_mult( gain2, (Word16) ( 32768 /*Q15*/ - AGC_FX ) ); /*Q30*/ - FOR( i = 0; i < L_frame; i++ ) - { - /*gain1 = gain1 * AGC + gain2;*/ - gain1 = mac_r( L_tmp, gain1, AGC_FX ); /* in Q14 */ - /*exc[i] *= gain1;*/ - exc[i] = mac_r( L_mult( exc[i], gain1 ), exc[i], gain1 ); - move16(); - /*exc2[i] *= gain1;*/ - exc2[i] = mac_r_sat( L_mult( exc2[i], gain1 ), exc2[i], gain1 ); - move16(); - } - /* smoothing is done in excitation domain, so redo synthesis */ - Copy( mem_tmp, mem_syn, M ); /* Q_syn */ - syn_12k8_fx( L_frame, Aq, exc2, synth, mem_syn, 1, Q_exc, Q_syn ); - *update_flg = 1; - move16(); - } - } - ELSE - { - /* previous frame erased and no TC frame */ - test(); - IF( prev_bfi && NE_16( coder_type, TRANSITION ) ) - { - IF( L_enr_q == 0 ) - { - L_enr_q = L_max( 1, L_enr2 ); /* sets to 'L_enr2' in 1 clock */ - set16_fx( h1, 0, L_FRAME / 2 ); - h1[0] = 1024; /*1.0f in Q10*/ - move16(); - /*syn_filt( Aq+(3*(M+1)), M, h1, h1, L_FRAME/2, h1+(M+1), 0 );*/ - E_UTIL_synthesis( 1, Aq + ( 3 * ( M + 1 ) ), h1, h1, L_FRAME / 2, h1 + ( M + 1 ), 0, M ); - /*Compute tilt */ - /*rr0 = dotp( h1, h1, L_FRAME/2-1 ) + 0.1f;*/ - /*rr1 = dotp( h1, h1+1, L_FRAME/2-1 );*/ - /*tilt = rr1 / rr0;*/ - tilt = extract_h( L_shl_sat( get_gain( h1 + 1, h1, L_FRAME / 2 - 1 ), 15 ) ); /*Q15*/ - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( ( ( EQ_32( total_brate, ACELP_13k20 ) ) || ( EQ_32( total_brate, ACELP_12k85 ) ) || ( EQ_32( total_brate, ACELP_12k15 ) ) || ( EQ_32( total_brate, ACELP_11k60 ) ) || - ( EQ_32( total_brate, ACELP_9k60 ) ) ) && - ( GT_16( tilt, 22938 ) ) && /* HF resonnant filter */ - ( ( ( clas == UNVOICED_CLAS ) ) || ( EQ_16( clas, INACTIVE_CLAS ) ) ) ) ) /* unvoiced classification */ - { - /*if( enr_q > scaling * enr_old )enr_q = scaling * enr_old;*/ - L_enr_q = L_min( L_enr_q, L_shl_sat( Mult_32_16( L_enr_old, scaling ), 1 ) ); /* scaling in Q14*/ - } - ELSE IF( GE_16( last_good, VOICED_TRANSITION ) && LT_16( last_good, INACTIVE_CLAS ) && GE_16( clas, VOICED_TRANSITION ) && LT_16( clas, INACTIVE_CLAS ) ) - { - /* Voiced-voiced recovery */ - test(); - IF( *old_enr_LP != 0 && GT_16( enr_LP, shl_sat( *old_enr_LP, 1 ) ) ) - { - /* enr_q /= enr_LP */ - exp = norm_l( L_enr_q ); - tmp = extract_h( L_shl( L_enr_q, exp ) ); - - exp2 = norm_s( enr_LP ); - tmp2 = shl( enr_LP, exp2 ); - - exp = sub( exp2, exp ); - - tmp3 = sub( tmp, tmp2 ); - IF( tmp3 > 0 ) - { - tmp = shr( tmp, 1 ); - exp = add( exp, 1 ); - } - tmp = div_s( tmp, tmp2 ); - - /* L_enr_q *= 2 * *old_enr_LP */ - L_enr_q = L_shl( L_mult( tmp, shl( *old_enr_LP, 1 ) ), exp ); - } - - ELSE - { - test(); - IF( avoid_lpc_burst_on_recovery && GT_16( enr_LP, 160 /*20.0f in Q3*/ ) ) - { - exp = norm_s( enr_LP ); - tmp = shl( enr_LP, exp ); - - exp2 = 7; - move16(); - tmp2 = 160 << 7; /* 160 = 20.0f in Q3 */ - move16(); - exp = sub( exp2, exp ); - - IF( GT_16( tmp, tmp2 ) ) - { - tmp = shr( tmp, 1 ); - exp = add( exp, 1 ); - } - tmp = div_s( tmp, tmp2 ); /* tmp*2^exp = enr_LP/20.0 */ - L_tmp = Isqrt_lc( L_deposit_h( tmp ), &exp ); /* L_tmp*2^exp = sqrt(20.0/enr_LP) */ - L_enr_q = L_shl( Mpy_32_32( L_enr_q, L_tmp ), exp ); - } - } - } - - test(); - test(); - test(); - test(); - IF( ( GE_16( last_good, VOICED_TRANSITION ) && LT_16( last_good, INACTIVE_CLAS ) && GE_16( clas, VOICED_TRANSITION ) && LT_16( clas, INACTIVE_CLAS ) ) || force_scaling ) - { - - IF( GT_32( L_enr_q, L_enr_old ) ) /* Prevent energy to increase on voiced */ - { - L_enr_q = L_add( Mpy_32_16_1( L_enr_old, 32767 - SCLSYN_LAMBDA ), Mpy_32_16_1( L_enr_q, SCLSYN_LAMBDA ) ); /*Q0*/ - } - } - } - - L_enr_q = L_max( 1, L_enr_q ); - - /* gain2 = (float)sqrt( enr_q / enr2 );*/ - exp = norm_l( L_enr_q ); - tmp = extract_h( L_shl( L_enr_q, exp ) ); - - exp2 = norm_l( L_enr2 ); - tmp2 = extract_h( L_shl( L_enr2, exp2 ) ); - - exp2 = sub( exp, exp2 ); /* Denormalize and substract */ - - tmp3 = sub( tmp2, tmp ); - IF( tmp3 > 0 ) - { - tmp2 = shr( tmp2, 1 ); - exp2 = add( exp2, 1 ); - } - - tmp = div_s( tmp2, tmp ); - - L_tmp = L_deposit_h( tmp ); - L_tmp = Isqrt_lc( L_tmp, &exp2 ); - gain2 = round_fx_sat( L_shl_sat( L_tmp, sub( exp2, 1 ) ) ); /* in Q14 */ - /*-----------------------------------------------------------------* - * Clipping of the smoothing gain at the frame end - *-----------------------------------------------------------------*/ - - gain2 = s_min( gain2, 19661 /*1.2f in Q14*/ ); /* Gain modification clipping */ - if ( LT_32( L_enr_q, 2 ) ) - { - gain2 = s_min( gain2, 16384 /*1.0f in Q14*/ ); /* Gain modification clipping */ - } - - /*-----------------------------------------------------------------* - * Find the energy/gain at the beginning of the frame to ensure smooth transition after erasure(s) - *-----------------------------------------------------------------*/ - - test(); - test(); - test(); - test(); - test(); - test(); - IF( EQ_16( clas, SIN_ONSET ) ) /* slow increase */ - { - gain1 = shr( gain2, 1 ); /*0.5f * gain2*/ - } - /*------------------------------------------------------------* - * voiced->unvoiced transition recovery - *------------------------------------------------------------*/ - ELSE IF( ( GE_16( last_good, VOICED_TRANSITION ) && LT_16( last_good, INACTIVE_CLAS ) && ( clas == UNVOICED_CLAS || EQ_16( clas, INACTIVE_CLAS ) ) ) || /* voiced->unvoiced transition recovery */ - EQ_32( last_core_brate, SID_1k75 ) || EQ_32( last_core_brate, SID_2k40 ) || last_core_brate == FRAME_NO_DATA ) /* CNG -> active signal transition */ - { - gain1 = gain2; /*Q14*/ - move16(); - } - ELSE - { - /*--------------------------------------------------------* - * Find the energy at the beginning of the frame - *--------------------------------------------------------*/ - tmp = frame_ener_fx( L_frame, clas, synth, pitch[0], &L_enr1, 0, Q_syn, 3, 0 ); - - /*gain1 = (float)sqrt( enr_old / enr1 );*/ - exp = norm_l( L_enr_old ); - tmp = extract_h( L_shl( L_enr_old, exp ) ); - exp2 = norm_l( L_enr1 ); - tmp2 = extract_h( L_shl( L_enr1, exp2 ) ); - - exp2 = sub( exp, exp2 ); /* Denormalize and substract */ - - tmp3 = sub( tmp2, tmp ); - - IF( tmp3 > 0 ) - { - tmp2 = shr( tmp2, 1 ); - exp2 = add( exp2, 1 ); - } - - tmp = div_s( tmp2, tmp ); - - L_tmp = L_deposit_h( tmp ); - L_tmp = Isqrt_lc( L_tmp, &exp2 ); - gain1 = round_fx_sat( L_shl_sat( L_tmp, sub( exp2, 1 ) ) ); /* in Q14 */ - /* exp2 is always <= 1 */ - - gain1 = s_min( gain1, 19661 /*1.2F in Q14*/ ); - - test(); - test(); - if ( avoid_lpc_burst_on_recovery && ( GT_16( enr_LP, 160 ) ) && ( LE_16( enr_LP, shl_sat( *old_enr_LP, 1 ) ) ) ) - { - gain1 = s_min( gain1, 16384 /*1.0f in Q14*/ ); - } - - /*--------------------------------------------------------* - * Prevent a catastrophy in case of offset followed by onset - *--------------------------------------------------------*/ - test(); - if ( ( EQ_16( clas, ONSET ) ) && ( GT_16( gain1, gain2 ) ) ) - { - gain1 = gain2; /*Q14*/ - move16(); - } - } - /*-----------------------------------------------------------------* - * Smooth the energy evolution by exponentially evolving from - * gain1 to gain2 - *-----------------------------------------------------------------*/ - - L_tmp = L_mult( gain2, (Word16) ( 32768 /*Q15*/ - AGC_FX ) ); - - FOR( i = 0; i < L_frame; i++ ) - { - gain1 = mac_r( L_tmp, gain1, AGC_FX ); /* in Q14 */ - exc[i] = mac_r_sat( L_mult_sat( exc[i], gain1 ), exc[i], gain1 ); - move16(); - exc2[i] = mac_r_sat( L_mult_sat( exc2[i], gain1 ), exc2[i], gain1 ); - move16(); - } - - Copy( mem_tmp, mem_syn, M ); /* Q_syn */ - syn_12k8_fx( L_frame, Aq, exc2, synth, mem_syn, 1, Q_exc, Q_syn ); - *update_flg = 1; - move16(); - } - } - /*-----------------------------------------------------------------* - * Update low-pass filtered energy for voiced frames - *-----------------------------------------------------------------*/ - - test(); - test(); - IF( !bfi && ( GE_16( clas, VOICED_TRANSITION ) && LT_16( clas, INACTIVE_CLAS ) ) ) - { - IF( EQ_16( clas, VOICED_TRANSITION ) ) - { - L_enr2_av = L_enr2; /*Q0*/ - move32(); - frame_ener_fx( L_frame, VOICED_CLAS, synth, pitch[sub( shr( L_frame, 6 ), 1 )], &L_ener2_max /*Q0*/, 1, Q_syn, 3, 0 ); - } - ELSE - { - L_ener2_max = L_enr2; /*Q0*/ - move32(); - frame_ener_fx( L_frame, UNVOICED_CLAS, synth, pitch[sub( shr( L_frame, 6 ), 1 )], &L_enr2_av /*Q0*/, 1, Q_syn, 3, 0 ); - } - - /**lp_ener_FEC_av = 0.2f * enr2_av + 0.8f * *lp_ener_FEC_av; move32();*/ - *lp_ener_FEC_av = Madd_32_16( Mult_32_16( *lp_ener_FEC_av, 31130 /*0.95f in Q15*/ ), L_enr2_av, 1638 /*0.05F Q15*/ ); /*Q0*/ - move32(); - /**lp_ener_FEC_max = 0.2f * enr2_max + 0.8f * *lp_ener_FEC_max; move32();*/ - *lp_ener_FEC_max = Madd_32_16( Mult_32_16( *lp_ener_FEC_max, 31130 /*0.95f in Q15*/ ), L_ener2_max, 1638 /*0.05F Q15*/ ); /*Q0*/ - move32(); - } - - /*-----------------------------------------------------------------* - * Update the LP filter energy for voiced frames - *-----------------------------------------------------------------*/ - test(); - if ( GE_16( clas, VOICED_TRANSITION ) && LT_16( clas, INACTIVE_CLAS ) ) - { - *old_enr_LP = enr_LP; /*Q3*/ - move16(); - } - - return; -} -#endif -void FEC_scale_syn_ivas_fx( - const Word16 L_frame, /* i : length of the frame */ - Word16 *update_flg, /* o: flag indicating re-synthesis after scaling*/ - Word16 clas, /* i/o: frame classification */ - const Word16 last_good, /* i: last good frame classification */ - Word16 *synth, /* i/o: synthesized speech at Fs = 12k8 Hz Q_syn*/ - const Word16 *pitch, /* i: pitch values for each subframe Q0*/ - Word32 L_enr_old, /* i: energy at the end of previous frame */ - Word32 L_enr_q, /* i: transmitted energy for current frame */ - const Word16 coder_type, /* i: coder type */ - const Word16 LSF_Q_prediction, /* i : LSF prediction mode */ - Word16 *scaling_flag, /* i/o: flag to indicate energy control of syn */ - Word32 *lp_ener_FEC_av, /* i/o: averaged voiced signal energy Q0*/ - Word32 *lp_ener_FEC_max, /* i/o: averaged voiced signal energy Q0*/ - const Word16 bfi, /* i: current frame BFI */ - const Word32 total_brate, /* i: total bitrate */ - const Word16 prev_bfi, /* i: previous frame BFI */ - const Word32 last_core_brate, /* i: previous frame core bitrate */ - Word16 *exc, /* i/o: excitation signal without enhancement */ - Word16 *exc2, /* i/o: excitation signal with enhancement */ - Word16 Aq[], /* i/o: LP filter coefs (can be modified if BR) Q12*/ - Word16 *old_enr_LP, /* i/o: LP filter E of last good voiced frame Q3*/ - const Word16 *mem_tmp, /* i: temp. initial synthesis filter states Q_syn*/ - Word16 *mem_syn, /* o: initial synthesis filter states Q_syn*/ - Word16 Q_exc, - Word16 Q_syn, -#ifdef REMOVE_EVS_DUPLICATES - const Word16 element_mode, /* i : element mode */ -#endif + const Word16 element_mode, /* i : element mode */ const Word16 avoid_lpc_burst_on_recovery, /* i : if true the excitation energy is limited if LP has big gain */ const Word16 force_scaling /* i: force scaling */ ) @@ -742,12 +174,8 @@ void FEC_scale_syn_ivas_fx( tmp = sub( 3, getScaleFactor16( synth, L_frame ) ); -#ifdef REMOVE_EVS_DUPLICATES test(); IF( tmp > 0 && GT_16( element_mode, EVS_MONO ) ) -#else - IF( tmp > 0 ) -#endif { Word16 synth_tmp[L_FRAME16k]; Copy_Scale_sig( synth, synth_tmp, L_frame, -tmp ); // Q_synth - tmp diff --git a/lib_dec/acelp_core_dec_fx.c b/lib_dec/acelp_core_dec_fx.c index 3570ce86d..32aab2bb0 100644 --- a/lib_dec/acelp_core_dec_fx.c +++ b/lib_dec/acelp_core_dec_fx.c @@ -1,57 +1,72 @@ +/****************************************************************************************************** + + (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., + Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, + Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other + contributors to this repository. All Rights Reserved. + + This software is protected by copyright law and by international treaties. + The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB, + Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., + Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, + Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other + contributors to this repository retain full ownership rights in their respective contributions in + the software. This notice grants no license of any kind, including but not limited to patent + license, nor is any license granted by implication, estoppel or otherwise. + + Contributors are required to enter into the IVAS codec Public Collaboration agreement before making + contributions. + + This software is provided "AS IS", without any express or implied warranties. The software is in the + development stage. It is intended exclusively for experts who have experience with such software and + solely for the purpose of inspection. All implied warranties of non-infringement, merchantability + and fitness for a particular purpose are hereby disclaimed and excluded. + + Any dispute, controversy or claim arising under or in relation to providing this software shall be + submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in + accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and + the United Nations Convention on Contracts on the International Sales of Goods. + +*******************************************************************************************************/ + /*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 + EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0 ====================================================================================*/ - #include #include -#include "options.h" /* Compilation switches */ -#include "rom_com.h" /* Static table prototypes */ -#include "prot_fx.h" /* Function prototypes */ +#include +#include "options.h" +#include "cnst.h" +#include "rom_com.h" +#include "prot_fx.h" +#include "ivas_cnst.h" +#include "ivas_rom_com.h" +#include "wmc_auto.h" #include "ivas_prot_fx.h" -#include "ivas_cnst.h" /* Common constants */ -#include "cnst.h" /* Common constants */ - -#ifndef REMOVE_EVS_DUPLICATES -/*==========================================================================*/ -/* FUNCTION : void acelp_core_dec_fx () */ -/*--------------------------------------------------------------------------*/ -/* PURPOSE : ACELP core decoder */ -/*--------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ Word16 coder_type i : coder type */ - -/*--------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ Word16 *voice_factors o : voicing factors Q15 */ -/* _ Word16 old_syn_12k8_16k[] o : intermediate ACELP Q_syn2-1 */ -/* synthesis at 12.8kHz or 16kHz to be used by SWB BWE */ -/* _ Word16 synth_out[] o : synthesis Q_syn2-1 */ -/*--------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ Decoder_State_fx *st_fx: */ -/* _ Word16 bwe_exc_extended[] i/o: bandwidth extended excitation Q0*/ -/*--------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*--------------------------------------------------------------------------*/ -/* CALLED FROM : RX */ -/*==========================================================================*/ + + +/*-------------------------------------------------------------------* + * acelp_core_dec_fx() + * + * ACELP core decoder + *-------------------------------------------------------------------*/ ivas_error acelp_core_dec_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 output[], /* o : synthesis @internal Fs */ - Word16 synth_out[], /* o : synthesis Q_syn2-1*/ - Word16 save_hb_synth[], /* o : HB synthesis */ - Word32 bwe_exc_extended[], /* i/o: bandwidth extended excitation Q0*/ - Word16 *voice_factors, /* o : voicing factors Q15 */ - Word16 old_syn_12k8_16k[], /* o : intermediate ACELP synthesis for SWB BWE Q_syn2-1*/ - Word16 sharpFlag, - Word16 pitch_buf_fx[NB_SUBFR16k], /* o : floating pitch for each subframe Q6*/ + Decoder_State *st, /* i/o: decoder state structure */ + Word16 output_fx[], /* o : synthesis @internal Fs Q_syn*/ + Word16 synth_fx16[], /* o : synthesis Q_syn2*/ + Word16 save_hb_synth_fx16[], /* o : HB synthesis Q0*/ + Word32 bwe_exc_extended_fx[], /* i/o: bandwidth extended excitation 2*Q_exc*/ + Word16 *voice_factors_fx, /* o : voicing factors Q15*/ + Word16 old_syn_12k8_16k_fx[], /* o : intermediate ACELP synthesis at 12.8kHz or 16kHz to be used by SWB BWE Q_syn2-1*/ + const Word16 sharpFlag, /* i : formant sharpening flag */ + Word16 pitch_buf_fx[NB_SUBFR16k], /* o : Word16 pitch for each subframe Q6*/ Word16 *unbits, /* o : number of unused bits */ Word16 *sid_bw, /* o : 0-NB/WB, 1-SWB SID */ - STEREO_TD_DEC_DATA_HANDLE hStereoTD, /* i/o: TD stereo decoder handle */ - const Word16 tdm_lspQ_PCh[M], /* i : Q LSPs for primary channel */ - const Word16 tdm_lsfQ_PCh[M], /* i : Q LSFs for primary channel */ + STEREO_TD_DEC_DATA_HANDLE hStereoTD, /* i/o: TD stereo decoder handle Qlog2(2.56)*/ + const Word16 tdm_lspQ_PCh_fx[M], /* i : Q LSPs for primary channel Q15*/ + const Word16 tdm_lsfQ_PCh_fx[M], /* i : Q LSFs for primary channel */ const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ const Word16 last_element_mode, /* i : last element mode */ const Word32 last_element_brate, /* i : last element bitrate */ @@ -61,96 +76,158 @@ ivas_error acelp_core_dec_fx( const Word16 read_sid_info /* i : read SID info flag */ ) { - Word16 old_exc_fx[L_EXC_DEC] = { 0 }, *exc_fx; /* excitation signal buffer (Q0) */ - Word16 syn_fx_tmp[L_FRAME_16k + L_SUBFR], *syn_fx; /* synthesis signal buffer */ - Word16 temp_buf[L_FRAME16k + L_SYN_MEM]; + Word32 synth_fx[960], save_hb_synth_fx[960] /*, bwe_exc_extended_fx[L_FRAME32k + NL_BUFF_OFFSET]*/; + Word16 old_exc_fx[L_EXC_DEC], *exc_fx; /* excitation signal buffer */ + Word16 syn_tmp_fx[L_FRAME16k + L_SUBFR], *psyn_fx; /* synthesis signal buffer */ Word16 output_frame; /* frame length at output sampling freq. */ + Word16 lsf_new_fx[M]; /* LSFs at the end of the frame Qlog2(2.56) */ + Word16 lsp_new_fx[M]; /* LSPs at the end of the frame Q15 */ + Word16 lsp_mid_fx[M]; /* LSPs in the middle of the frame */ + Word16 Aq_fx[NB_SUBFR16k * ( M + 1 )]; /* A(q) quantized for the 4 subframes */ + Word16 old_exc2_fx[L_FRAME16k + L_EXC_MEM], *exc2_fx; /* total excitation buffer */ Word16 mem_tmp_fx[M]; /* temporary synthesis filter memory */ Word32 enr_q_fx; /* E information for FER protection */ Word16 tmp_noise_fx; /* Long term temporary noise energy */ - Word16 i, int_fs; - Word16 tc_subfr_fx; - Word16 allow_cn_step_fx; + Word16 Es_pred_fx; /* predicted scaled innov. energy Q8 */ + Word16 FEC_pitch_fx; /* FEC pitch */ + Word16 old_bwe_exc_fx[( ( PIT16k_MAX + ( L_FRAME16k + 1 ) + L_SUBFR16k ) * 2 )]; /* excitation buffer */ + Word16 *bwe_exc_fx; /* Excitation for SWB TBE */ + Word16 i, j, int_fs; + Word16 tc_subfr; + Word16 allow_cn_step; Word16 temp_buf_fx[L_FRAME16k + L_SYN_MEM]; - - Word16 Aq_fx[NB_SUBFR16k * ( M + 1 )] = { 0 }; /*Q12*/ - Word16 Es_pred_fx; /*Q8*/ - Word16 old_bwe_exc_fx[( ( PIT16k_MAX + ( L_FRAME16k + 1 ) + L_SUBFR16k ) * 2 )] = { 0 }; /* excitation buffer Q_exc*/ - Word16 old_exc2_fx[L_FRAME16k + L_EXC_MEM], *exc2_fx; /* total excitation buffer */ - Word16 *bwe_exc_fx; - Word16 lsf_new_fx[M]; /* LSFs at the end of the frame */ - Word16 lsp_new_fx[M]; /* LSPs at the end of the frame */ - Word16 lsp_mid_fx[M]; /* LSPs in the middle of the frame */ - Word16 FEC_pitch_fx; /*Q6*/ Word16 last_pulse_pos; Word16 T0_tmp; - Word16 do_WI_fx; + Word16 do_WI; Word16 dct_buffer_fx[DCT_L_POST]; Word16 exc_buffer_fx[DCT_L_POST]; - Word16 dct_exc_tmp[L_FRAME16k]; - Word16 qdct; - Word16 delta_mem_scale; - Word16 bpf_error_signal[L_FRAME16k]; - CLDFB_SCALE_FACTOR scaleFactor; - Word32 workBuffer[128 * 3]; - Word32 q_env[20]; - Word16 exc3_fx[L_FRAME16k]; - Word16 syn1_fx_tmp[L_FRAME16k + 2], *syn1_fx; - Word32 *realBuffer[CLDFB_NO_COL_MAX], *imagBuffer[CLDFB_NO_COL_MAX]; - Word16 gain_buf[NB_SUBFR16k]; /*Q14*/ + Word16 dct_exc_tmp_fx[L_FRAME16k]; + Word16 nb_bits; /* number of bits */ + Word16 indice; /* parameter indices to write */ + Word16 gain_buf_fx[NB_SUBFR16k]; Word16 syn_fx_tmp2[L_FRAME_16k]; Word16 pitch_buf_tmp[NB_SUBFR16k]; - Word16 k; Word16 update_flg; - Word32 realBufferTmp[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; - Word32 imagBufferTmp[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; - Word16 LSF_Q_prediction; /* o : LSF prediction mode */ + Word32 q_env_fx[20]; + Word16 exc3_fx[L_FRAME16k]; + Word16 syn1_tmp_fx[L_FRAME16k + 2], *syn1_fx; + Word32 *realBuffer_fx[CLDFB_NO_COL_MAX], *imagBuffer_fx[CLDFB_NO_COL_MAX]; + Word32 realBufferTmp_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; + Word32 imagBufferTmp_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; + Word16 LSF_Q_prediction; /* LSF prediction mode */ Word16 avoid_lpc_burst_on_recovery; - Word16 uc_two_stage_flag, dec; - Word16 nb_bits, indice; + Word16 tmpF_fx; + Word16 uc_two_stage_flag; Word16 tdm_lp_reuse_flag, tdm_low_rate_mode, tdm_Pitch_reuse_flag; - MUSIC_POSTFILT_HANDLE hMusicPF; - BPF_DEC_HANDLE hBPF; - TD_BWE_DEC_HANDLE hBWE_TD; - FD_BWE_DEC_HANDLE hBWE_FD; - TCX_DEC_HANDLE hTcxDec; + Word16 *old_exc_s_fx; /* Start of last excitation frame */ + Word16 *p_tdm_Pri_pitch_buf_fx; + Word16 tmp, exp, local_element_mode; ivas_error error; - (void) ( tdm_lspQ_PCh ); - (void) ( tdm_lsfQ_PCh ); - (void) ( use_cldfb_for_dft ); - (void) ( last_element_mode ); - (void) ( last_element_brate ); - (void) ( flag_sec_CNA ); - (void) ( nchan_out ); - (void) ( save_hb_synth ); - (void) ( output ); - (void) ( read_sid_info ); - (void) hStereoCng; - hMusicPF = st_fx->hMusicPF; - hBPF = st_fx->hBPF; - hBWE_TD = st_fx->hBWE_TD; - hBWE_FD = st_fx->hBWE_FD; - hTcxDec = st_fx->hTcxDec; + Word32 bpf_error_signal_fx[L_FRAME16k]; + Word16 bpf_error_signal_16fx[L_FRAME16k]; + Word16 Q_real; + Word32 max_real, max_imag, max_val; + + set32_fx( bpf_error_signal_fx, 0, L_FRAME16k ); + set16_fx( bpf_error_signal_16fx, 0, L_FRAME16k ); + set16_fx( Aq_fx, 0, NB_SUBFR16k * ( M + 1 ) ); + set16_fx( old_bwe_exc_fx, 0, ( ( PIT16k_MAX + ( L_FRAME16k + 1 ) + L_SUBFR16k ) * 2 ) ); + error = IVAS_ERR_OK; move32(); - // IF ( 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_4k4) ) + test(); test(); test(); - IF( 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 ) ) + IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && EQ_16( nchan_out, 1 ) && EQ_16( st->idchan, 1 ) && LE_32( last_element_brate, IVAS_SID_5k2 ) ) { /* In MDCT-Stereo DTX with mono output, we can skip CNG for the second channel, except for the first inactive frame following an active period */ return error; } + push_wmops( "acelp_core_dec" ); + + /* output_frame = (int16_t) ( st->output_Fs / FRAMES_PER_SEC ); */ + output_frame = extract_l( Mpy_32_32( st->output_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ); + + /*----------------------------------------------------------------* + * stereo SID and CNG frames processing + *----------------------------------------------------------------*/ + + test(); + test(); + IF( LE_32( st->core_brate, SID_2k40 ) && EQ_16( st->element_mode, IVAS_CPE_DFT ) && EQ_16( nchan_out, 2 ) ) + { + IF( EQ_16( st->cng_type, FD_CNG ) ) + { + configureFdCngDec_fx( st->hFdCngDec, st->bwidth, ACELP_14k25, st->L_frame, st->last_L_frame, st->element_mode ); + + Word16 old_NoiseEstExp; + old_NoiseEstExp = st->hFdCngDec->hFdCngCom->sidNoiseEstExp; + move16(); + + /* Only run parameter decoding in SID frames */ + IF( EQ_32( st->core_brate, SID_2k40 ) ) + { + FdCng_decodeSID_ivas_fx( st ); + + Word16 n1, n2; + n1 = L_norm_arr( st->hFdCngDec->hFdCngCom->sidNoiseEst, NPART ); + n2 = L_norm_arr( st->hFdCngDec->hFdCngCom->sidNoiseEstLp, NPART ); + + Word16 common_e = s_max( sub( old_NoiseEstExp, n2 ), sub( st->hFdCngDec->hFdCngCom->sidNoiseEstExp, n1 ) ); + scale_sig32( st->hFdCngDec->hFdCngCom->sidNoiseEst, NPART, sub( st->hFdCngDec->hFdCngCom->sidNoiseEstExp, common_e ) ); + scale_sig32( st->hFdCngDec->hFdCngCom->sidNoiseEstLp, NPART, sub( old_NoiseEstExp, common_e ) ); + st->hFdCngDec->hFdCngCom->sidNoiseEstExp = common_e; + move16(); + } + + FOR( i = 0; i < NPART; i++ ) + { + st->hFdCngDec->hFdCngCom->sidNoiseEstLp[i] = Madd_32_32( Mpy_32_32( STEREO_DFT_FD_FILT_Q31, st->hFdCngDec->hFdCngCom->sidNoiseEstLp[i] ), + STEREO_DFT_FD_FILT_COMP_Q31, st->hFdCngDec->hFdCngCom->sidNoiseEst[i] ); + move32(); + } + + ApplyFdCng_fx( NULL, 0, NULL, 0, NULL, NULL, NULL, st, 0, 0 ); + } + ELSE + { + configureFdCngDec_fx( st->hFdCngDec, st->bwidth, ACELP_14k25, st->L_frame, st->last_L_frame, st->element_mode ); + + /* decode CNG parameters */ + CNG_dec_fx( st, last_element_mode, Aq_fx, lsp_new_fx, lsf_new_fx, &allow_cn_step, sid_bw, q_env_fx ); + + /* comfort noise generation */ + CNG_exc_fx( st->core_brate, st->L_frame, &st->hTdCngDec->Enew_fx, &st->hTdCngDec->cng_seed, NULL, NULL, &st->lp_ener_fx, st->last_core_brate, &st->first_CNG, &( st->hTdCngDec->cng_ener_seed ), NULL, allow_cn_step, &st->hTdCngDec->last_allow_cn_step, st->prev_Q_exc, st->Q_exc, st->hTdCngDec->num_ho, q_env_fx, st->hTdCngDec->lp_env_fx, st->hTdCngDec->old_env_fx, st->hTdCngDec->exc_mem_fx, st->hTdCngDec->exc_mem1_fx, sid_bw, &st->hTdCngDec->cng_ener_seed1, NULL, st->Opt_AMR_WB, st->element_mode ); + + Copy( Aq_fx, st->Aq_cng, M + 1 ); /*Q12*/ + + /* update old LSP and LSF vector */ + Copy( lsf_new_fx, st->lsf_old_fx, M ); /*Qlog2(2.56)*/ + Copy( lsp_new_fx, st->lsp_old_fx, M ); /*Q15*/ + } + + set16_fx( output_fx, 0, output_frame ); /* output and synth are not used in DFT domain CNG generation and the decoder output is unaffected if they are left uninitalized */ + set16_fx( synth_fx16, 0, output_frame ); /* They are however read in a few places which causes errors in the valgrind tests. Simplest solution from a code perspective was to set them to zero. */ + + /* CN generation done in DFT domain */ + pop_wmops(); + + return error; + } + + /*----------------------------------------------------------------* + * Active frames processing + *----------------------------------------------------------------*/ + + /* open CLDFB buffer up to CLDFB_NO_CHANNELS_MAX bands for 48kHz */ FOR( i = 0; i < CLDFB_NO_COL_MAX; 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(); + 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]; } /*----------------------------------------------------------------* @@ -159,54 +236,61 @@ ivas_error acelp_core_dec_fx( LSF_Q_prediction = -1; move16(); - set16_fx( syn_fx_tmp, 0, L_SUBFR ); - syn_fx = syn_fx_tmp + L_SUBFR; - syn1_fx_tmp[0] = 0; + set16_fx( syn_tmp_fx, 0, L_SUBFR ); + psyn_fx = syn_tmp_fx + L_SUBFR; + syn1_tmp_fx[0] = 0; move16(); - syn1_fx_tmp[1] = 0; + syn1_tmp_fx[1] = 0; move16(); - syn1_fx = syn1_fx_tmp + 2; - /*output_frame = (Word16)(st_fx->output_Fs_fx / 50); move16();*/ - output_frame = st_fx->output_frame_fx; - move16(); - st_fx->bpf_off = 0; + syn1_fx = syn1_tmp_fx + 2; + st->bpf_off = 0; move16(); + test(); test(); test(); test(); test(); test(); - IF( EQ_16( st_fx->last_core, HQ_CORE ) || EQ_16( st_fx->last_core, TCX_20_CORE ) || EQ_16( st_fx->last_core, TCX_10_CORE ) || ( EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) && LE_32( st_fx->last_core_brate, SID_2k40 ) ) || ( EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) && LE_32( st_fx->last_core_brate, SID_2k40 ) ) ) + IF( EQ_16( st->last_core, HQ_CORE ) || EQ_16( st->last_core, TCX_20_CORE ) || EQ_16( st->last_core, TCX_10_CORE ) || ( EQ_16( st->element_mode, IVAS_CPE_DFT ) && LE_32( st->last_core_brate, SID_2k40 ) ) || ( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && LE_32( st->last_core_brate, SID_2k40 ) ) ) { /* in case of HQ->ACELP switching, do not apply BPF */ - st_fx->bpf_off = 1; + st->bpf_off = 1; move16(); - /* in case of core switching, reset post-filter memories */ - if ( st_fx->hPFstat != NULL ) + if ( st->hPFstat != NULL ) { - st_fx->hPFstat->on = 0; + /* in case of core switching, reset post-filter memories */ + st->hPFstat->on = 0; move16(); } - /* reset the GSC pre echo energy threshold in case of switching */ - if ( st_fx->hGSCDec != NULL ) + if ( st->hGSCDec != NULL ) { - st_fx->hGSCDec->Last_frame_ener_fx = MAX_32; + /* reset the GSC pre echo energy threshold in case of switching */ + st->hGSCDec->Last_frame_ener_fx = MAX_32; move32(); } } - IF( st_fx->prev_bfi > 0 ) + + test(); + if ( st->hGSCDec != NULL && ( st->prev_bfi > 0 ) ) { /* reset the GSC pre echo energy threshold in case of FEC */ - if ( st_fx->hGSCDec != NULL ) - { - st_fx->hGSCDec->Last_frame_ener_fx = MAX_32; + st->hGSCDec->Last_frame_ener_fx = MAX_32; move32(); } + + test(); + test(); + test(); + test(); + IF( st->hFdCngDec != NULL && ( EQ_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_CPE_TD ) ) && ( EQ_32( st->last_core_brate, SID_2k40 ) || st->last_core_brate == FRAME_NO_DATA ) ) + { + set16_fx( st->hFdCngDec->hFdCngCom->olapBufferSynth2, 0, FFTLEN ); + set16_fx( hStereoCng->olapBufferSynth22_fx, 0, FFTLEN ); } - st_fx->clas_dec = st_fx->last_good; + st->clas_dec = st->last_good; move16(); enr_q_fx = 0; move32(); @@ -214,21 +298,22 @@ ivas_error acelp_core_dec_fx( move16(); tmp_noise_fx = 0; move16(); - Copy( st_fx->old_exc_fx, old_exc_fx, L_EXC_MEM_DEC ); // Q_exc + Copy( st->old_exc_fx, old_exc_fx, L_EXC_MEM_DEC ); /*Q_exc*/ exc_fx = old_exc_fx + L_EXC_MEM_DEC; - IF( st_fx->hWIDec != NULL ) + IF( st->hWIDec != NULL ) { - Copy( st_fx->hWIDec->old_exc2_fx, old_exc2_fx, L_EXC_MEM ); + Copy( st->hWIDec->old_exc2_fx, old_exc2_fx, L_EXC_MEM ); } ELSE { set16_fx( old_exc2_fx, 0, L_EXC_MEM ); } exc2_fx = old_exc2_fx + L_EXC_MEM; - IF( st_fx->hBWE_TD != NULL ) + + IF( st->hBWE_TD != NULL ) { - Copy( hBWE_TD->old_bwe_exc_fx, old_bwe_exc_fx, PIT16k_MAX * 2 ); // Q_exc + Copy( st->hBWE_TD->old_bwe_exc_fx, old_bwe_exc_fx, PIT16k_MAX * 2 ); /*Q_exc*/ bwe_exc_fx = old_bwe_exc_fx + PIT16k_MAX * 2; } ELSE @@ -238,271 +323,270 @@ ivas_error acelp_core_dec_fx( last_pulse_pos = 0; move16(); - do_WI_fx = 0; + do_WI = 0; move16(); - st_fx->GSC_noisy_speech = 0; + st->GSC_noisy_speech = 0; move16(); - st_fx->relax_prev_lsf_interp = 0; + st->relax_prev_lsf_interp = 0; move16(); + set16_fx( gain_buf_fx, 0, NB_SUBFR16k ); - set16_fx( gain_buf, 0, NB_SUBFR16k ); - IF( EQ_16( st_fx->L_frame, L_FRAME ) ) + IF( EQ_16( st->L_frame, L_FRAME ) ) { - st_fx->gamma = GAMMA1; + st->gamma = GAMMA1; move16(); - st_fx->preemph_fac = PREEMPH_FAC; + st->inv_gamma = GAMMA1_INV; move16(); - int_fs = INT_FS_FX; + st->preemph_fac = PREEMPH_FAC; + move16(); + int_fs = INT_FS_12k8; move16(); } ELSE { - st_fx->gamma = GAMMA16k; + st->gamma = GAMMA16k; + move16(); + st->inv_gamma = GAMMA16k_INV; move16(); - st_fx->preemph_fac = PREEMPH_FAC_16k; + st->preemph_fac = PREEMPH_FAC_16k; move16(); int_fs = INT_FS_16k; move16(); } - /* reset post-filter in case post-filtering was off in previous frame */ - IF( st_fx->hPFstat != NULL ) - { - if ( st_fx->hPFstat->on == 0 ) + test(); + /* reset post-filter in case of switching */ + if ( st->hPFstat != NULL && ( st->hPFstat->on == 0 ) ) { - st_fx->hPFstat->reset = 1; + st->hPFstat->reset = 1; move16(); } - } + avoid_lpc_burst_on_recovery = 0; move16(); test(); test(); - if ( st_fx->last_con_tcx && NE_16( st_fx->L_frameTCX_past, st_fx->L_frame ) && st_fx->last_core != 0 ) + if ( st->last_con_tcx && NE_16( st->L_frameTCX_past, st->L_frame ) && ( st->last_core != 0 ) ) { avoid_lpc_burst_on_recovery = 1; move16(); } - /* TD stereo parameters */ test(); - IF( EQ_16( st_fx->element_mode, IVAS_CPE_TD ) && st_fx->idchan == 1 ) + + /* TD stereo parameters */ + IF( EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( st->idchan, 1 ) ) { tdm_lp_reuse_flag = hStereoTD->tdm_lp_reuse_flag; - tdm_low_rate_mode = hStereoTD->tdm_low_rate_mode; - tdm_Pitch_reuse_flag = hStereoTD->tdm_Pitch_reuse_flag; - move16(); move16(); + tdm_low_rate_mode = hStereoTD->tdm_low_rate_mode; move16(); + tdm_Pitch_reuse_flag = hStereoTD->tdm_Pitch_reuse_flag; move16(); + p_tdm_Pri_pitch_buf_fx = hStereoTD->tdm_Pri_pitch_buf_fx; } ELSE { tdm_lp_reuse_flag = 0; - tdm_low_rate_mode = 0; move16(); + tdm_low_rate_mode = 0; move16(); test(); - if ( EQ_16( st_fx->element_mode, IVAS_SCE ) && st_fx->low_rate_mode ) + if ( EQ_16( st->element_mode, IVAS_SCE ) && st->low_rate_mode ) { tdm_low_rate_mode = 1; move16(); } tdm_Pitch_reuse_flag = 0; move16(); + p_tdm_Pri_pitch_buf_fx = NULL; } + /*----------------------------------------------------------------* * Updates in case of internal sampling rate switching *----------------------------------------------------------------*/ + test(); test(); - IF( NE_16( st_fx->last_L_frame, st_fx->L_frame ) && ( st_fx->last_core == ACELP_CORE || EQ_16( st_fx->last_core, AMR_WB_CORE ) ) ) + IF( NE_16( st->last_L_frame, st->L_frame ) && ( st->last_core == ACELP_CORE || EQ_16( st->last_core, AMR_WB_CORE ) ) ) { - IF( st_fx->hPFstat->on != 0 ) + Word16 dec; + + IF( ( st->hPFstat->on != 0 ) ) { Word16 mem_syn_r_size_old, mem_syn_r_size_new; - - mem_syn_r_size_old = shr( st_fx->last_L_frame, 4 ); - mem_syn_r_size_new = shr( st_fx->L_frame, 4 ); - lerp( st_fx->hPFstat->mem_stp + L_SYN_MEM - mem_syn_r_size_old, st_fx->hPFstat->mem_stp + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); - lerp( st_fx->hPFstat->mem_pf_in + L_SYN_MEM - mem_syn_r_size_old, st_fx->hPFstat->mem_pf_in + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); + mem_syn_r_size_old = mult_r( 2048, st->last_L_frame ); /* 1.25/20.f = 2048 (Q15)*/ + mem_syn_r_size_new = mult_r( 2048, st->L_frame ); /* 1.25/20.f = 2048 (Q15)*/ + lerp( st->hPFstat->mem_stp + sub( L_SYN_MEM, mem_syn_r_size_old ), st->hPFstat->mem_stp + sub( L_SYN_MEM, mem_syn_r_size_new ), mem_syn_r_size_new, mem_syn_r_size_old ); + lerp( st->hPFstat->mem_pf_in + sub( L_SYN_MEM, mem_syn_r_size_old ), st->hPFstat->mem_pf_in + sub( L_SYN_MEM, mem_syn_r_size_new ), mem_syn_r_size_new, mem_syn_r_size_old ); } + /* convert quantized LSP vector */ - st_fx->rate_switching_reset = lsp_convert_poly_fx( st_fx->lsp_old_fx, st_fx->L_frame, 0 ); + st->rate_switching_reset = lsp_convert_poly_fx( st->lsp_old_fx, st->L_frame, 0 ); move16(); + /* convert old quantized LSF vector */ - lsp2lsf_fx( st_fx->lsp_old_fx, st_fx->lsf_old_fx, M, int_fs ); + lsp2lsf_fx( st->lsp_old_fx, st->lsf_old_fx, M, int_fs ); /* FEC - update adaptive LSF mean vector */ - Copy( st_fx->lsf_old_fx, st_fx->lsfoldbfi1_fx, M ); // Qlog2(2.56) - Copy( st_fx->lsf_old_fx, st_fx->lsfoldbfi0_fx, M ); // Qlog2(2.56) - Copy( st_fx->lsf_old_fx, st_fx->lsf_adaptive_mean_fx, M ); // Qlog2(2.56) + Copy( st->lsf_old_fx, st->lsfoldbfi1_fx, M ); /*Qlog2(2.56)*/ + Copy( st->lsf_old_fx, st->lsfoldbfi0_fx, M ); /*Qlog2(2.56)*/ + Copy( st->lsf_old_fx, st->lsf_adaptive_mean_fx, M ); /*Qlog2(2.56)*/ /* Reset LPC mem */ - IF( EQ_32( st_fx->sr_core, INT_FS_16k ) ) + IF( EQ_32( st->sr_core, INT_FS_16k ) ) { - Copy( GEWB2_Ave_fx, st_fx->mem_AR_fx, M ); // Qlog2(2.56) + Copy( GEWB2_Ave_fx, st->mem_AR_fx, M ); /*Qlog2(2.56)*/ } ELSE { - Copy( GEWB_Ave_fx, st_fx->mem_AR_fx, M ); // Qlog2(2.56) + Copy( GEWB_Ave_fx, st->mem_AR_fx, M ); /*Qlog2(2.56)*/ } - set16_fx( st_fx->mem_MA_fx, 0, M ); + set16_fx( st->mem_MA_fx, 0, M ); + /* update synthesis filter memories */ dec = DEC; move16(); - IF( NE_16( st_fx->element_mode, EVS_MONO ) ) + if ( st->element_mode != EVS_MONO ) { dec = DEC_IVAS; move16(); } - - /* update synthesis filter memories */ - synth_mem_updt2( st_fx->L_frame, st_fx->last_L_frame, st_fx->old_exc_fx, st_fx->mem_syn_r, st_fx->mem_syn2_fx, NULL, dec ); - - Copy( st_fx->old_exc_fx, old_exc_fx, L_EXC_MEM_DEC ); // Q_exc - Copy_Scale_sig( st_fx->mem_syn2_fx, st_fx->mem_syn1_fx, M, sub( -1, st_fx->Q_syn ) ); /*Q-1*/ - - Copy( st_fx->mem_syn2_fx, st_fx->mem_syn3_fx, M ); + ivas_synth_mem_updt2_fx( st->L_frame, st->last_L_frame, st->old_exc_fx, st->mem_syn_r, st->mem_syn2_fx, NULL, dec ); + Copy( st->old_exc_fx, old_exc_fx, L_EXC_MEM_DEC ); /*Q_exc*/ + Copy_Scale_sig( st->mem_syn2_fx, st->mem_syn1_fx, M, sub( -1, st->Q_syn ) ); /*Q-1*/ + Copy( st->mem_syn2_fx, st->mem_syn3_fx, M ); /*Q_syn*/ } - IF( NE_16( st_fx->last_L_frame, st_fx->L_frame ) ) + /* update buffer of old subframe pitch values */ + IF( NE_16( st->last_L_frame, st->L_frame ) ) { - /* update buffer of old subframe pitch values */ - IF( EQ_16( st_fx->L_frame, L_FRAME ) ) + IF( EQ_16( st->L_frame, L_FRAME ) ) { - - IF( EQ_16( st_fx->last_L_frame, L_FRAME32k ) ) + IF( EQ_16( st->last_L_frame, L_FRAME32k ) ) { - /* (float)12800/(float)32000; */ - k = 13107; // Q15 + tmpF_fx = 13107; // Q15 move16(); } - ELSE IF( EQ_16( st_fx->last_L_frame, 512 ) ) + ELSE IF( EQ_16( st->last_L_frame, 512 ) ) { - /* (float)12800/(float)25600; */ - k = 16384; // Q15 + tmpF_fx = 16384; // Q15 move16(); } ELSE /* st->last_L_frame == L_FRAME16k */ { - /* (float)12800/(float)16000; */ - k = 26214; // Q15 + tmpF_fx = 26214; // Q15 move16(); } FOR( i = NB_SUBFR16k - NB_SUBFR; i < NB_SUBFR16k; i++ ) { - st_fx->old_pitch_buf_fx[i - 1] = Mpy_32_16_1( st_fx->old_pitch_buf_fx[i], k ); // Q(15+15+1-16) + st->old_pitch_buf_fx[i - 1] = Mpy_32_16_1( st->old_pitch_buf_fx[i], tmpF_fx ); // Q16 move32(); } FOR( i = 2 * NB_SUBFR16k - NB_SUBFR; i < 2 * NB_SUBFR16k; i++ ) { - st_fx->old_pitch_buf_fx[i - 2] = Mpy_32_16_1( st_fx->old_pitch_buf_fx[i], k ); // Q15 + st->old_pitch_buf_fx[i - 2] = Mpy_32_16_1( st->old_pitch_buf_fx[i], tmpF_fx ); // Q16 move32(); } } ELSE { - - IF( EQ_16( st_fx->last_L_frame, L_FRAME32k ) ) + exp = 0; + move16(); + IF( EQ_16( st->last_L_frame, L_FRAME32k ) ) { - /* (float)16000/(float)32000; */ - k = -16384; // -0.5 in Q15 + tmpF_fx = 16384; // Q15 move16(); } - ELSE IF( EQ_16( st_fx->last_L_frame, 512 ) ) + ELSE IF( EQ_16( st->last_L_frame, 512 ) ) { - /* tmpF = (float)16000/(float)25600; */ - k = -12288; //-0.375 in Q15 + tmpF_fx = 20480; // Q15 move16(); } ELSE /* st->last_L_frame == L_FRAME12k8 */ { - /* tmpF = (float)16000/(float)12800; */ - k = 8192; //.25 in Q15 + tmpF_fx = 20480; // Q14 + move16(); + exp = 1; move16(); } - FOR( i = 2 * NB_SUBFR - 1; i >= NB_SUBFR; i-- ) { - st_fx->old_pitch_buf_fx[i + 2] = L_add( st_fx->old_pitch_buf_fx[i], Mpy_32_16_1( st_fx->old_pitch_buf_fx[i], k ) ); // Q15 + st->old_pitch_buf_fx[i + 2] = Mpy_32_16_1( L_shl( st->old_pitch_buf_fx[i], exp ), tmpF_fx ); // Q15 move32(); } - st_fx->old_pitch_buf_fx[NB_SUBFR + 1] = st_fx->old_pitch_buf_fx[NB_SUBFR + 2]; + st->old_pitch_buf_fx[NB_SUBFR + 1] = st->old_pitch_buf_fx[NB_SUBFR + 2]; move32(); FOR( i = NB_SUBFR - 1; i >= 0; i-- ) { - st_fx->old_pitch_buf_fx[i + 1] = L_add( st_fx->old_pitch_buf_fx[i], Mpy_32_16_1( st_fx->old_pitch_buf_fx[i], k ) ); // Q15 + st->old_pitch_buf_fx[i + 1] = Mpy_32_16_1( L_shl( st->old_pitch_buf_fx[i], exp ), tmpF_fx ); // Q15 move32(); } - st_fx->old_pitch_buf_fx[0] = st_fx->old_pitch_buf_fx[1]; + st->old_pitch_buf_fx[0] = st->old_pitch_buf_fx[1]; move32(); } } - IF( NE_16( st_fx->bfi_pitch_frame, st_fx->L_frame ) ) + IF( NE_16( st->bfi_pitch_frame, st->L_frame ) ) { - IF( EQ_16( st_fx->L_frame, L_FRAME ) ) + IF( EQ_16( st->L_frame, L_FRAME ) ) { - - IF( EQ_16( st_fx->bfi_pitch_frame, L_FRAME32k ) ) + IF( EQ_16( st->bfi_pitch_frame, L_FRAME32k ) ) { - /* (float)12800/(float)32000; */ - k = 13107; // Q15 + tmpF_fx = 13107; // Q15 move16(); } - ELSE IF( EQ_16( st_fx->bfi_pitch_frame, 512 ) ) + ELSE IF( EQ_16( st->bfi_pitch_frame, 512 ) ) { - /* (float)12800/(float)25600; */ - k = 16384; // Q15 + tmpF_fx = 16384; // Q15 move16(); } ELSE /* st->bfi_pitch_frame == L_FRAME16k */ { - /* (float)12800/(float)16000; */ - k = 26214; // Q15 + tmpF_fx = 26214; // Q15 move16(); } - st_fx->bfi_pitch_fx = mult_r( k, st_fx->bfi_pitch_fx ); + st->bfi_pitch_fx = mult_r( st->bfi_pitch_fx, tmpF_fx ); move16(); - st_fx->bfi_pitch_frame = L_FRAME; + st->bfi_pitch_frame = L_FRAME; move16(); } ELSE { - - IF( EQ_16( st_fx->bfi_pitch_frame, L_FRAME32k ) ) + exp = 0; + move16(); + IF( EQ_16( st->bfi_pitch_frame, L_FRAME32k ) ) { - /* (float)16000/(float)32000; */ - k = -16384; //-0.5 in Q15 + tmpF_fx = 16384; // Q15 move16(); } - ELSE IF( EQ_16( st_fx->bfi_pitch_frame, 512 ) ) + ELSE IF( EQ_16( st->bfi_pitch_frame, 512 ) ) { - /* tmpF = (float)16000/(float)25600; */ - k = -12288; // -0.375 in Q15 + tmpF_fx = 20480; // Q15 move16(); } ELSE /* st->bfi_pitch_frame == L_FRAME12k8 */ { - /* tmpF = (float)16000/(float)12800; */ - k = 8192; // .25 in Q15 + tmpF_fx = 20480; // Q14 + move16(); + exp = 1; move16(); } - st_fx->bfi_pitch_fx = add( st_fx->bfi_pitch_fx, mult_r( st_fx->bfi_pitch_fx, k ) ); + + st->bfi_pitch_fx = mult_r( shl_sat( st->bfi_pitch_fx, exp ), tmpF_fx ); move16(); - st_fx->bfi_pitch_frame = L_FRAME16k; + st->bfi_pitch_frame = L_FRAME16k; move16(); } } test(); test(); - if ( EQ_16( st_fx->last_bwidth, NB ) && NE_16( st_fx->bwidth, NB ) && st_fx->ini_frame != 0 ) + if ( EQ_16( st->last_bwidth, NB ) && NE_16( st->bwidth, NB ) && ( st->ini_frame != 0 ) ) { - st_fx->rate_switching_reset = 1; + st->rate_switching_reset = 1; move16(); } @@ -510,36 +594,35 @@ ivas_error acelp_core_dec_fx( * GOOD frame *----------------------------------------------------------------------*/ - IF( !st_fx->bfi ) + IF( !st->bfi ) { /*----------------------------------------------------------------* * Decoding of TC subframe classification *----------------------------------------------------------------*/ - tc_subfr_fx = -1; + tc_subfr = -1; move16(); - IF( EQ_16( st_fx->coder_type, TRANSITION ) ) + IF( EQ_16( st->coder_type, TRANSITION ) ) { - tc_subfr_fx = tc_classif_fx( st_fx, st_fx->L_frame ); + tc_subfr = tc_classif_fx( st, st->L_frame ); } /*----------------------------------------------------------------* * Decoding of GSC IVAS mode *----------------------------------------------------------------*/ - st_fx->GSC_IVAS_mode = 0; - move16(); + test(); test(); test(); test(); - IF( ( st_fx->element_mode > EVS_MONO ) && st_fx->idchan == 0 && !( ( st_fx->core_brate == FRAME_NO_DATA ) || EQ_32( st_fx->core_brate, SID_2k40 ) ) && !tdm_low_rate_mode ) + IF( st->element_mode > EVS_MONO && st->idchan == 0 && !( st->core_brate == FRAME_NO_DATA || EQ_32( st->core_brate, SID_2k40 ) ) && !tdm_low_rate_mode ) { test(); test(); - IF( EQ_16( st_fx->coder_type, AUDIO ) || ( ( st_fx->coder_type == INACTIVE ) && LE_32( st_fx->total_brate, MAX_GSC_INACTIVE_BRATE ) ) ) + IF( EQ_16( st->coder_type, AUDIO ) || ( EQ_16( st->coder_type, INACTIVE ) && EQ_16( st->inactive_coder_type_flag, 1 ) ) ) { - st_fx->GSC_IVAS_mode = get_next_indice( st_fx, 2 ); + st->GSC_IVAS_mode = get_next_indice_fx( st, 2 ); move16(); } } @@ -547,88 +630,215 @@ ivas_error acelp_core_dec_fx( /*----------------------------------------------------------------* * Decoding of inactive CNG frames *----------------------------------------------------------------*/ + test(); - IF( st_fx->core_brate == FRAME_NO_DATA || EQ_32( st_fx->core_brate, SID_2k40 ) ) + IF( st->core_brate == FRAME_NO_DATA || EQ_32( st->core_brate, SID_2k40 ) ) { /* decode CNG parameters */ - IF( st_fx->cng_type == LP_CNG ) + IF( st->cng_type == LP_CNG ) { - - CNG_dec_fx( st_fx, EVS_MONO, Aq_fx, lsp_new_fx, lsf_new_fx, &allow_cn_step_fx, sid_bw, q_env ); + CNG_dec_fx( st, last_element_mode, Aq_fx, lsp_new_fx, lsf_new_fx, &allow_cn_step, sid_bw, q_env_fx ); + Copy( Aq_fx, st->Aq_cng, add( M, 1 ) ); /* comfort noise generation */ - CNG_exc_fx( st_fx->core_brate, st_fx->L_frame, &st_fx->hTdCngDec->Enew_fx, &st_fx->hTdCngDec->cng_seed, exc_fx, exc2_fx, &st_fx->lp_ener_fx, st_fx->last_core_brate, - &st_fx->first_CNG, &( st_fx->hTdCngDec->cng_ener_seed ), bwe_exc_fx, allow_cn_step_fx, &st_fx->hTdCngDec->last_allow_cn_step, st_fx->prev_Q_exc, st_fx->Q_exc, st_fx->hTdCngDec->num_ho, - q_env, st_fx->hTdCngDec->lp_env_fx, st_fx->hTdCngDec->old_env_fx, st_fx->hTdCngDec->exc_mem_fx, st_fx->hTdCngDec->exc_mem1_fx, sid_bw, &st_fx->hTdCngDec->cng_ener_seed1, exc3_fx, st_fx->Opt_AMR_WB, st_fx->element_mode ); + local_element_mode = st->element_mode; + move16(); - Copy( Aq_fx, st_fx->Aq_cng, M + 1 ); // Q12 + test(); + test(); + if ( ( EQ_16( nchan_out, 1 ) && EQ_16( st->element_mode, IVAS_CPE_DFT ) ) || EQ_16( st->masa_sid_format, 1 ) ) + { + local_element_mode = IVAS_SCE; /* For DFT Stereo mono decoding, run CNG_exc as in SCE */ + move16(); + } + CNG_exc_fx( st->core_brate, st->L_frame, &st->hTdCngDec->Enew_fx, &st->hTdCngDec->cng_seed, exc_fx, exc2_fx, &st->lp_ener_fx, st->last_core_brate, &st->first_CNG, &( st->hTdCngDec->cng_ener_seed ), bwe_exc_fx, allow_cn_step, &st->hTdCngDec->last_allow_cn_step, st->prev_Q_exc, st->Q_exc, st->hTdCngDec->num_ho, q_env_fx, st->hTdCngDec->lp_env_fx, st->hTdCngDec->old_env_fx, st->hTdCngDec->exc_mem_fx, st->hTdCngDec->exc_mem1_fx, sid_bw, &st->hTdCngDec->cng_ener_seed1, exc3_fx, st->Opt_AMR_WB, local_element_mode ); } ELSE { test(); - IF( EQ_32( st_fx->core_brate, SID_2k40 ) && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) + IF( EQ_32( st->core_brate, SID_2k40 ) && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) + { + IF( EQ_16( st->element_mode, EVS_MONO ) ) + { + FdCng_decodeSID_fx( st->hFdCngDec->hFdCngCom, st ); + } + ELSE { - FdCng_decodeSID_fx( st_fx->hFdCngDec->hFdCngCom, st_fx ); + Word16 old_NoiseEstExp = st->hFdCngDec->hFdCngCom->sidNoiseEstExp; + move16(); + + FdCng_decodeSID_ivas_fx( st ); + + Scale_sig32( st->hFdCngDec->hFdCngCom->sidNoiseEstLp, NPART, sub( old_NoiseEstExp, st->hFdCngDec->hFdCngCom->sidNoiseEstExp ) ); + Scale_sig( st->hFdCngDec->hFdCngCom->A_cng, M + 1, sub( norm_s( st->hFdCngDec->hFdCngCom->A_cng[0] ), Q2 ) ); // Qx + } + *sid_bw = 0; move16(); } - generate_comfort_noise_dec_fx( NULL, NULL, NULL, st_fx, &( st_fx->Q_exc ), 2, -1 ); + IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) ) + { + assert( nchan_out == 1 ); + + FOR( i = 0; i < NPART; i++ ) + { + st->hFdCngDec->hFdCngCom->sidNoiseEstLp[i] = Madd_32_32( Mpy_32_32( STEREO_DFT_FD_FILT_Q31, st->hFdCngDec->hFdCngCom->sidNoiseEstLp[i] ), + STEREO_DFT_FD_FILT_COMP_Q31, st->hFdCngDec->hFdCngCom->sidNoiseEst[i] ); + move32(); + } + + ApplyFdCng_fx( psyn_fx, st->Q_syn, NULL, 0, realBuffer_fx, imagBuffer_fx, NULL, st, 0, ( st->coder_type == AUDIO && !st->GSC_noisy_speech ) ); + + Word16 new_sidNoiseEstExp = 31 - Q4; + move16(); + Scale_sig32( st->hFdCngDec->hFdCngCom->sidNoiseEstLp, NPART, sub( st->hFdCngDec->hFdCngCom->sidNoiseEstExp, new_sidNoiseEstExp ) ); // Q(31-sidNoiseEstExp) + Scale_sig32( st->hFdCngDec->hFdCngCom->sidNoiseEst, NPART, sub( st->hFdCngDec->hFdCngCom->sidNoiseEstExp, new_sidNoiseEstExp ) ); // Q(31-sidNoiseEstExp) + st->hFdCngDec->hFdCngCom->sidNoiseEstExp = new_sidNoiseEstExp; + move16(); + Word16 new_cngNoiseLevelExp = 31 - Q4; + move16(); + Scale_sig32( st->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, sub( st->hFdCngDec->hFdCngCom->cngNoiseLevelExp, new_cngNoiseLevelExp ) ); // Q(31-cngNoiseLevelExp) + st->hFdCngDec->hFdCngCom->cngNoiseLevelExp = new_cngNoiseLevelExp; + move16(); + + test(); + ApplyFdCng_fx( psyn_fx, st->Q_syn, NULL, 0, realBuffer_fx, imagBuffer_fx, NULL, st, 0, ( EQ_16( st->coder_type, AUDIO ) && !st->GSC_noisy_speech ) ); + + IF( st->hFdCngDec->hFdCngCom->cngNoiseLevelExp < 0 ) + { + Scale_sig32( st->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, st->hFdCngDec->hFdCngCom->cngNoiseLevelExp ); // Q(31-cngNoiseLevelExp) + st->hFdCngDec->hFdCngCom->cngNoiseLevelExp = 0; + move16(); + } + } + + IF( !read_sid_info ) + { + Word32 noise_lvl_highest_fx; + + noise_lvl_highest_fx = st->hFdCngDec->hFdCngCom->cngNoiseLevel[( st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand ) - 1]; + move32(); + + FOR( Word16 b = ( st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand ); b < st->hFdCngDec->hFdCngCom->stopBand; b++ ) + { + st->hFdCngDec->hFdCngCom->cngNoiseLevel[b] = noise_lvl_highest_fx; + move32(); + } + } + + IF( EQ_16( st->element_mode, EVS_MONO ) ) + { + generate_comfort_noise_dec_fx( NULL, NULL, NULL, st, &( st->Q_exc ), 2, -1 ); + } + ELSE + { + generate_comfort_noise_dec_ivas_fx( NULL, NULL, NULL, st, &( st->Q_exc ), 1, nchan_out ); + } - FdCng_exc( st_fx->hFdCngDec->hFdCngCom, &st_fx->CNG_mode, st_fx->L_frame, st_fx->lsp_old_fx, st_fx->first_CNG, st_fx->lspCNG_fx, Aq_fx, lsp_new_fx, lsf_new_fx, exc_fx, exc2_fx, bwe_exc_fx ); + FdCng_exc( st->hFdCngDec->hFdCngCom, &st->CNG_mode, st->L_frame, st->lsp_old_fx, st->first_CNG, st->lspCNG_fx, Aq_fx, lsp_new_fx, lsf_new_fx, exc_fx, exc2_fx, bwe_exc_fx ); - Copy( exc2_fx, exc3_fx, st_fx->L_frame ); + Copy( exc2_fx, exc3_fx, st->L_frame ); } - delta_mem_scale = 3; + Word16 delta_mem_scale = 3; move16(); test(); - if ( LT_32( st_fx->lp_ener_fx, 40 ) && ( st_fx->cng_type == LP_CNG ) ) /* very low energy frames, less than 0.3125 */ + if ( LT_32( st->lp_ener_fx, 40 ) && st->cng_type == LP_CNG ) /* very low energy frames, less than 0.3125 */ { delta_mem_scale = 0; move16(); } - i = st_fx->Q_exc; + i = st->Q_exc; move16(); - Rescale_exc( hMusicPF->dct_post_old_exc_fx, exc_fx, bwe_exc_fx, st_fx->hGSCDec->last_exc_dct_in_fx, st_fx->L_frame, - st_fx->L_frame * HIBND_ACB_L_FAC, 0, &( st_fx->Q_exc ), st_fx->Q_subfr, NULL, 0, INACTIVE ); - Rescale_mem( st_fx->Q_exc, &st_fx->prev_Q_syn, &st_fx->Q_syn, st_fx->mem_syn2_fx, st_fx->mem_syn_clas_estim_fx, delta_mem_scale, - &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, 0, 0, NULL ); - Copy_Scale_sig( exc2_fx, exc2_fx, st_fx->L_frame, sub( st_fx->Q_exc, i ) ); // Q_exc + + test(); + IF( st->hMusicPF && st->hGSCDec ) + { + IF( EQ_16( st->element_mode, EVS_MONO ) ) + { + // VE: TBV: should 'st_fx->L_frame * HIBND_ACB_L_FAC' be corrected in EVS? + Rescale_exc( st->hMusicPF->dct_post_old_exc_fx, exc_fx, bwe_exc_fx, st->hGSCDec->last_exc_dct_in_fx, st->L_frame, + st->L_frame * HIBND_ACB_L_FAC, 0, &( st->Q_exc ), st->Q_subfr, NULL, 0, INACTIVE ); + } + ELSE + { + Rescale_exc( st->hMusicPF->dct_post_old_exc_fx, exc_fx, bwe_exc_fx, st->hGSCDec->last_exc_dct_in_fx, st->L_frame, + L_FRAME32k, 0, &( st->Q_exc ), st->Q_subfr, NULL, 0, INACTIVE ); + } + } + + IF( st->hPFstat != NULL ) + { + Rescale_mem( st->Q_exc, &st->prev_Q_syn, &st->Q_syn, st->mem_syn2_fx, st->mem_syn_clas_estim_fx, delta_mem_scale, + &st->mem_deemph_fx, st->hBPF->pst_old_syn_fx, &st->hBPF->pst_mem_deemp_err_fx, &st->agc_mem_fx[1], st->hPFstat, 0, 0, NULL ); + } + ELSE + { + Rescale_mem( st->Q_exc, &st->prev_Q_syn, &st->Q_syn, st->mem_syn2_fx, st->mem_syn_clas_estim_fx, delta_mem_scale, + &st->mem_deemph_fx, NULL, NULL, &st->agc_mem_fx[1], NULL, 0, 0, NULL ); + } + + Copy_Scale_sig( exc2_fx, exc2_fx, st->L_frame, sub( st->Q_exc, i ) ); // Q_exc /* update past excitation signals for LD music post-filter */ - IF( hMusicPF != NULL ) + IF( st->hMusicPF != NULL ) { - Copy( hMusicPF->dct_post_old_exc_fx + L_FRAME, hMusicPF->dct_post_old_exc_fx, DCT_L_POST - L_FRAME - OFFSET2 ); - Copy( exc2_fx, hMusicPF->dct_post_old_exc_fx + ( DCT_L_POST - L_FRAME - OFFSET2 ), L_FRAME ); + Copy( st->hMusicPF->dct_post_old_exc_fx + L_FRAME, st->hMusicPF->dct_post_old_exc_fx, DCT_L_POST - L_FRAME - OFFSET2 ); + Copy( exc2_fx, st->hMusicPF->dct_post_old_exc_fx + ( DCT_L_POST - L_FRAME - OFFSET2 ), L_FRAME ); + /* Update music post processing values */ /* Filter energies update */ + IF( EQ_16( st->element_mode, EVS_MONO ) ) + { + FOR( i = 0; i < DCT_L_POST; i++ ) + { + st->hMusicPF->filt_lfE_fx[i] = round_fx( L_mac( ( 1228 << ( 16 ) ), 22938, st->hMusicPF->filt_lfE_fx[i] ) ); + move16(); + } + } + ELSE + { FOR( i = 0; i < DCT_L_POST; i++ ) { - /*st_fx->filt_lfE_fx[i] = 0.3f + 0.7f * st_fx->filt_lfE_fx[i];*/ - hMusicPF->filt_lfE_fx[i] = round_fx( L_mac( ( 1228 << ( 16 ) ), 22938, hMusicPF->filt_lfE_fx[i] ) ); + st->hMusicPF->filt_lfE_fx[i] = add( 9830, mult_r( 22937, st->hMusicPF->filt_lfE_fx[i] ) ); // Q15, 9830 =.3f in Q15, 22937=.7f in Q15 move16(); } } + } + /* synthesis at 12.8kHz sampling rate */ - syn_12k8_fx( st_fx->L_frame, Aq_fx, exc2_fx, syn_fx, st_fx->mem_syn2_fx, 1, st_fx->Q_exc, st_fx->Q_syn ); - syn_12k8_fx( st_fx->L_frame, Aq_fx, exc3_fx, syn1_fx, st_fx->mem_syn3_fx, 1, st_fx->Q_exc, st_fx->Q_syn ); + move16(); + syn_12k8_fx( st->L_frame, Aq_fx, exc2_fx, psyn_fx, st->mem_syn2_fx, 1, st->Q_exc, st->Q_syn ); + syn_12k8_fx( st->L_frame, Aq_fx, exc3_fx, syn1_fx, st->mem_syn3_fx, 1, st->Q_exc, st->Q_syn ); /* reset the decoder */ - CNG_reset_dec_fx( st_fx, pitch_buf_fx, voice_factors ); + CNG_reset_dec_fx( st, pitch_buf_fx, voice_factors_fx ); + IF( EQ_16( st->element_mode, EVS_MONO ) ) + { /* update st_fx->mem_syn1 for ACELP core switching */ - Copy( st_fx->mem_syn3_fx, st_fx->mem_syn1_fx, M ); + Copy( st->mem_syn3_fx, st->mem_syn1_fx, M ); + } + ELSE + { + st->Q_syn_cng = st->Q_syn; + move16(); + st->Q_exc_cng = st->Q_exc; + move16(); - /* update old synthesis for classification */ - Copy( syn1_fx + st_fx->L_frame - L_SYN_MEM_CLAS_ESTIM, st_fx->mem_syn_clas_estim_fx, L_SYN_MEM_CLAS_ESTIM ); + /* update st->mem_syn1 for ACELP core switching */ + Copy_Scale_sig( st->mem_syn3_fx, st->mem_syn1_fx, M, sub( -1, st->Q_syn ) ); // Q(-1) + } + /* update old synthesis for classification */ + Copy( syn1_fx + st->L_frame - L_SYN_MEM_CLAS_ESTIM, st->mem_syn_clas_estim_fx, L_SYN_MEM_CLAS_ESTIM ); /* save and delay synthesis to be used by SWB BWE */ - Copy_Scale_sig( syn1_fx, temp_buf_fx, st_fx->L_frame, sub( -1, st_fx->Q_syn ) ); // Q_syn -> Q(-1) - IF( hBWE_FD != NULL ) + Copy_Scale_sig( syn1_fx, temp_buf_fx, st->L_frame, sub( -1, st->Q_syn ) ); // Q_syn -> Q(-1) + IF( st->hBWE_FD != NULL ) { - save_old_syn_fx( st_fx->L_frame, temp_buf_fx, old_syn_12k8_16k, hBWE_FD->old_syn_12k8_16k_fx, st_fx->preemph_fac, &hBWE_FD->mem_deemph_old_syn_fx ); + save_old_syn_fx( st->L_frame, temp_buf_fx, old_syn_12k8_16k_fx, st->hBWE_FD->old_syn_12k8_16k_fx, st->preemph_fac, &st->hBWE_FD->mem_deemph_old_syn_fx ); } } @@ -638,21 +848,24 @@ ivas_error acelp_core_dec_fx( ELSE { + /*-----------------------------------------------------------------* * Configure ACELP bit allocation *-----------------------------------------------------------------*/ + nb_bits = 0; - st_fx->acelp_cfg.FEC_mode = 0; - uc_two_stage_flag = 0; move16(); + st->acelp_cfg.FEC_mode = 0; move16(); + uc_two_stage_flag = 0; move16(); + test(); - IF( !st_fx->nelp_mode_dec && !st_fx->ppp_mode_dec ) + IF( !st->nelp_mode_dec && !st->ppp_mode_dec ) { Word16 tc_subfr_tmp; - tc_subfr_tmp = tc_subfr_fx; + tc_subfr_tmp = tc_subfr; move16(); if ( LT_16( tc_subfr_tmp, L_SUBFR ) ) { @@ -660,19 +873,19 @@ ivas_error acelp_core_dec_fx( move16(); } - if ( EQ_16( tc_subfr_fx, TC_0_192 ) ) + if ( EQ_16( tc_subfr, TC_0_192 ) ) { nb_bits = -1; move16(); } - config_acelp1( DEC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl_orig, st_fx->extl_brate_orig, st_fx->L_frame, st_fx->GSC_noisy_speech, &( st_fx->acelp_cfg ), st_fx->next_bit_pos, st_fx->coder_type, st_fx->inactive_coder_type_flag, tc_subfr_tmp, 1, &nb_bits, unbits, st_fx->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st_fx->idchan, st_fx->active_cnt, tdm_Pitch_reuse_flag, st_fx->tdm_LRTD_flag, st_fx->GSC_IVAS_mode ); + config_acelp1_fx( DEC, st->total_brate, st->core_brate, st->core, st->extl_orig, st->extl_brate_orig, st->L_frame, st->GSC_noisy_speech, &( st->acelp_cfg ), st->next_bit_pos, st->coder_type, st->inactive_coder_type_flag, tc_subfr_tmp, 1, &nb_bits, unbits, st->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st->idchan, st->active_cnt, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); test(); test(); - IF( EQ_16( st_fx->coder_type, TRANSITION ) && LT_16( tc_subfr_fx, L_SUBFR ) && EQ_16( st_fx->L_frame, L_FRAME ) ) + IF( EQ_16( st->coder_type, TRANSITION ) && LT_16( tc_subfr, L_SUBFR ) && EQ_16( st->L_frame, L_FRAME ) ) { - config_acelp1( DEC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl_orig, st_fx->extl_brate_orig, st_fx->L_frame, -1, &( st_fx->acelp_cfg ), st_fx->next_bit_pos, TRANSITION, -1, tc_subfr_fx, 2, &nb_bits, unbits, st_fx->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st_fx->idchan, st_fx->active_cnt, tdm_Pitch_reuse_flag, st_fx->tdm_LRTD_flag, st_fx->GSC_IVAS_mode ); + config_acelp1_fx( DEC, st->total_brate, st->core_brate, st->core, st->extl_orig, st->extl_brate_orig, st->L_frame, -1, &( st->acelp_cfg ), st->next_bit_pos, TRANSITION, -1, tc_subfr, 2, &nb_bits, unbits, st->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st->idchan, st->active_cnt, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); } } @@ -682,51 +895,126 @@ ivas_error acelp_core_dec_fx( test(); test(); - IF( st_fx->hTdCngDec != NULL && ( st_fx->last_core_brate == FRAME_NO_DATA || EQ_32( st_fx->last_core_brate, SID_2k40 ) ) ) + IF( st->hTdCngDec != NULL && ( st->last_core_brate == FRAME_NO_DATA || EQ_32( st->last_core_brate, SID_2k40 ) ) ) { - Copy( st_fx->lspCNG_fx, st_fx->lsp_old_fx, M ); // Q15 - - lsp2lsf_fx( st_fx->lspCNG_fx, st_fx->lsf_old_fx, M, int_fs ); + Copy( st->lspCNG_fx, st->lsp_old_fx, M ); /*Q15*/ + lsp2lsf_fx( st->lspCNG_fx, st->lsf_old_fx, M, int_fs ); } /*-----------------------------------------------------------------* * Reset higher ACELP pre-quantizer in case of switching *-----------------------------------------------------------------*/ - IF( !st_fx->use_acelp_preq ) + IF( !st->use_acelp_preq ) { - st_fx->mem_preemp_preQ_fx = 0; + st->mem_preemp_preQ_fx = 0; + move16(); + st->last_nq_preQ = 0; move16(); - st_fx->last_nq_preQ = 0; + st->last_code_preq = 0; move16(); } - st_fx->use_acelp_preq = 0; + st->use_acelp_preq = 0; move16(); /*-----------------------------------------------------------------* * LSF de-quantization and interpolation *-----------------------------------------------------------------*/ - lsf_dec_fx( st_fx, tc_subfr_fx, Aq_fx, &LSF_Q_prediction, lsf_new_fx, lsp_new_fx, lsp_mid_fx, tdm_low_rate_mode, - tdm_lsfQ_PCh ); + IF( !tdm_lp_reuse_flag ) + { + lsf_dec_fx( st, tc_subfr, Aq_fx, &LSF_Q_prediction, lsf_new_fx, lsp_new_fx, lsp_mid_fx, tdm_low_rate_mode, tdm_lsfQ_PCh_fx ); + } + ELSE + { + const Word16 *pt_interp_2_fx; + + IF( NE_16( st->active_cnt, 1 ) ) + { + Word16 beta_index; + + beta_index = get_next_indice_fx( st, TDM_IC_LSF_PRED_BITS ); + tdm_SCh_lsf_reuse_fx( DEC, st->element_brate, lsf_new_fx, lsp_new_fx, tdm_lsfQ_PCh_fx, NULL, &beta_index ); + } + ELSE + { + Copy( tdm_lspQ_PCh_fx, lsp_new_fx, M ); + Copy( tdm_lsfQ_PCh_fx, lsf_new_fx, M ); + } + + IF( st->rate_switching_reset ) + { + /* extrapolation in case of unstable LSF convert */ + Copy( lsp_new_fx, st->lsp_old_fx, M ); + Copy( lsf_new_fx, st->lsf_old_fx, M ); + } + + pt_interp_2_fx = interpol_frac_fx; + test(); + if ( EQ_16( tdm_low_rate_mode, 1 ) && GT_16( st->coder_type, UNVOICED ) ) + { + pt_interp_2_fx = interpol_frac2_fx; + } + + IF( EQ_16( st->active_cnt, 1 ) ) + { + Copy( lsp_new_fx, st->lsp_old_fx, M ); + lsp2lsf_fx( lsp_new_fx, st->lsf_old_fx, M, st->sr_core ); + } + + /* LSP interpolation and conversion of LSPs to A(z) */ + int_lsp_fx( st->L_frame, st->lsp_old_fx, lsp_new_fx, Aq_fx, M, pt_interp_2_fx, 0 ); + + /* Check LSF stability (distance between old LSFs and current LSFs) */ + st->stab_fac_fx = lsf_stab_ivas_fx( lsf_new_fx, st->lsf_old_fx, 0, st->L_frame ); + move16(); + } + + test(); + IF( EQ_16( st->last_core, HQ_CORE ) && st->element_mode > EVS_MONO ) + { + /* Prepare ACB memory from last HQ frame */ + old_exc_s_fx = st->old_exc_fx + sub( L_EXC_MEM_DEC, st->L_frame ); + tmpF_fx = *old_exc_s_fx; + st->mem_deemph_fx = shl_sat( old_exc_s_fx[st->L_frame - 1], st->Q_syn ); /* Q0 -> Q_syn */ + move16(); + PREEMPH_FX( old_exc_s_fx, st->preemph_fac, L_FRAME16k, &tmpF_fx ); + Copy( old_exc_s_fx + sub( st->L_frame, M ), st->mem_syn2_fx, M ); + Scale_sig( st->mem_syn2_fx, M, st->Q_syn ); /* Q0 -> Q_syn */ + Residu3_fx( Aq_fx, old_exc_s_fx, old_exc_fx + sub( L_EXC_MEM_DEC, st->L_frame ), st->L_frame, 0 ); + Scale_sig( old_exc_fx + sub( L_EXC_MEM_DEC, st->L_frame ), st->L_frame, st->Q_exc ); /* Q0 -> Q_exc */ + } + + test(); + IF( st->last_core != ACELP_CORE && st->element_mode > EVS_MONO ) + { + /* Prepare ACB memory of old_bwe_exc */ + IF( EQ_16( st->L_frame, L_FRAME ) ) + { + lerp( old_exc_fx, old_bwe_exc_fx, L_EXC_MEM_DEC * HIBND_ACB_L_FAC, L_EXC_MEM_DEC ); + } + ELSE + { + lerp( old_exc_fx, old_bwe_exc_fx, L_EXC_MEM_DEC << 1, L_EXC_MEM_DEC ); + } + } /*-----------------------------------------------------------------* * FEC - first good frame after lost frame(s) (possibility to correct the ACB) *-----------------------------------------------------------------*/ - IF( st_fx->acelp_cfg.FEC_mode > 0 ) + IF( st->acelp_cfg.FEC_mode > 0 ) { last_pulse_pos = 0; move16(); /* decode the last glottal pulse position */ - T0_tmp = FEC_pos_dec_fx( st_fx, &last_pulse_pos, &enr_q_fx, nb_bits ); - + T0_tmp = FEC_pos_dec_fx( st, &last_pulse_pos, &enr_q_fx, nb_bits ); test(); test(); - IF( NE_16( st_fx->last_core, HQ_CORE ) || ( EQ_16( st_fx->last_core, HQ_CORE ) && st_fx->last_con_tcx ) ) + IF( NE_16( st->last_core, HQ_CORE ) || ( EQ_16( st->last_core, HQ_CORE ) && st->last_con_tcx ) ) { test(); test(); @@ -734,16 +1022,13 @@ ivas_error acelp_core_dec_fx( test(); test(); test(); - test(); - IF( EQ_16( st_fx->clas_dec, SIN_ONSET ) && last_pulse_pos != 0 && EQ_16( st_fx->prev_bfi, 1 ) ) + IF( EQ_16( st->clas_dec, SIN_ONSET ) && last_pulse_pos != 0 && EQ_16( st->prev_bfi, 1 ) ) { - st_fx->Q_exc = - FEC_SinOnset_fx( old_exc_fx + L_EXC_MEM_DEC - L_EXC_MEM, last_pulse_pos, T0_tmp, enr_q_fx, Aq_fx, st_fx->L_frame, st_fx->Q_exc ); - move16(); + FEC_SinOnset_fx( old_exc_fx + L_EXC_MEM_DEC - L_EXC_MEM, last_pulse_pos, T0_tmp, enr_q_fx, Aq_fx, st->L_frame, st->Q_exc ); } - ELSE IF( ( EQ_16( st_fx->coder_type, GENERIC ) || EQ_16( st_fx->coder_type, VOICED ) ) && last_pulse_pos != 0 && EQ_16( st_fx->old_bfi_cnt, 1 ) && EQ_16( output_frame, L_FRAME16k ) && st_fx->hWIDec != NULL ) + ELSE IF( ( EQ_16( st->coder_type, GENERIC ) || EQ_16( st->coder_type, VOICED ) ) && last_pulse_pos != 0 && EQ_16( st->old_bfi_cnt, 1 ) && st->hWIDec != NULL ) { - do_WI_fx = FEC_enhACB_fx( st_fx->L_frame, st_fx->last_L_frame, old_exc_fx + L_EXC_MEM_DEC - L_EXC_MEM, T0_tmp, last_pulse_pos, st_fx->bfi_pitch_fx ); + do_WI = FEC_enhACB_fx( st->L_frame, st->last_L_frame, old_exc_fx + L_EXC_MEM_DEC - L_EXC_MEM, T0_tmp, last_pulse_pos, st->bfi_pitch_fx ); } } } @@ -752,16 +1037,16 @@ ivas_error acelp_core_dec_fx( * In case of first frame after an erasure and transition from voiced to unvoiced or inactive * redo the LPC interpolation *------------------------------------------------------------*/ + test(); test(); test(); test(); test(); test(); - IF( st_fx->stab_fac_fx == 0 && st_fx->old_bfi_cnt > 0 && NE_16( st_fx->clas_dec, VOICED_CLAS ) && NE_16( st_fx->clas_dec, ONSET ) && - st_fx->relax_prev_lsf_interp == 0 && !( EQ_16( st_fx->element_mode, IVAS_CPE_TD ) && EQ_16( st_fx->idchan, 1 ) ) ) + IF( ( st->stab_fac_fx == 0 ) && ( st->old_bfi_cnt > 0 ) && NE_16( st->clas_dec, VOICED_CLAS ) && NE_16( st->clas_dec, ONSET ) && ( st->relax_prev_lsf_interp == 0 ) && !( EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( st->idchan, 1 ) ) ) { - int_lsp4_fx( st_fx->L_frame, st_fx->lsp_old_fx, lsp_mid_fx, lsp_new_fx, Aq_fx, M, 2 ); + int_lsp4_ivas_fx( st->L_frame, st->lsp_old_fx, lsp_mid_fx, lsp_new_fx, Aq_fx, M, 2 ); } /*---------------------------------------------------------------* @@ -770,7 +1055,7 @@ ivas_error acelp_core_dec_fx( IF( nb_bits > 0 ) { - indice = get_next_indice( st_fx, nb_bits ); + indice = get_next_indice_fx( st, nb_bits ); Es_pred_dec_fx( &Es_pred_fx, indice, nb_bits, uc_two_stage_flag ); } @@ -780,79 +1065,113 @@ ivas_error acelp_core_dec_fx( test(); test(); - IF( EQ_16( st_fx->nelp_mode_dec, 1 ) ) + IF( tdm_low_rate_mode ) /* tdm stereo low rate mode */ { - /* SC-VBR - NELP frames */ - Scale_sig( exc_fx - L_EXC_MEM, L_EXC_MEM, negate( st_fx->Q_exc ) ); // Q0 - st_fx->Q_exc = 0; + IF( LE_16( st->coder_type, UNVOICED ) ) + { + tdm_low_rate_dec_fx( st, dct_exc_tmp_fx /*, &tmp_noise*/, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, lsf_new_fx ); + tmp_noise_fx = shr_r( st->lp_gainc_fx, 3 ); /*Q0*/ + } + ELSE /* GENERIC */ + { + decod_gen_2sbfr_fx( st, sharpFlag, Aq_fx, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, gain_buf_fx, tdm_Pitch_reuse_flag, p_tdm_Pri_pitch_buf_fx ); + + IF( EQ_16( st->element_mode, IVAS_CPE_TD ) ) + { + tmp_noise_fx = shr_r( st->lp_gainc_fx, 3 ); /*Q0*/ + } + } + } + ELSE IF( st->nelp_mode_dec ) + { + Scale_sig( exc_fx - L_EXC_MEM, L_EXC_MEM, negate( st->Q_exc ) ); // Q0 + st->Q_exc = 0; move16(); - decod_nelp_fx( st_fx, &tmp_noise_fx, pitch_buf_fx, exc_fx, exc2_fx, voice_factors, bwe_exc_fx, &st_fx->Q_exc, st_fx->bfi, gain_buf ); - Rescale_exc( hMusicPF->dct_post_old_exc_fx, exc_fx, NULL, st_fx->hGSCDec->last_exc_dct_in_fx, L_FRAME, 0, (Word32) 0, &( st_fx->Q_exc ), st_fx->Q_subfr, exc2_fx, L_FRAME, st_fx->coder_type ); + /* SC-VBR - NELP frames */ + decod_nelp_fx( st, &tmp_noise_fx, pitch_buf_fx, exc_fx, exc2_fx, voice_factors_fx, bwe_exc_fx, &st->Q_exc, st->bfi, gain_buf_fx ); + + Rescale_exc( st->hMusicPF->dct_post_old_exc_fx, exc_fx, NULL, st->hGSCDec->last_exc_dct_in_fx, L_FRAME, 0, (Word32) 0, &( st->Q_exc ), st->Q_subfr, exc2_fx, L_FRAME, st->coder_type ); } - ELSE IF( EQ_16( st_fx->coder_type, UNVOICED ) ) + ELSE IF( EQ_16( st->coder_type, UNVOICED ) ) { /* UNVOICED frames */ - decod_unvoiced_fx( st_fx, Aq_fx, st_fx->coder_type, &tmp_noise_fx, pitch_buf_fx, voice_factors, exc_fx, exc2_fx, bwe_exc_fx, gain_buf ); + decod_unvoiced_fx( st, Aq_fx, Es_pred_fx, uc_two_stage_flag, st->coder_type, &tmp_noise_fx, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, gain_buf_fx ); + + tmp_noise_fx = shr_r( st->lp_gainc_fx, 3 ); /*Q0*/ } - ELSE IF( EQ_16( st_fx->ppp_mode_dec, 1 ) ) + ELSE IF( st->ppp_mode_dec ) { - Scale_sig( exc_fx - L_EXC_MEM, L_EXC_MEM, negate( st_fx->Q_exc ) ); // Q0 - st_fx->Q_exc = 0; + Scale_sig( exc_fx - L_EXC_MEM, L_EXC_MEM, negate( st->Q_exc ) ); // Q0 + st->Q_exc = 0; move16(); + /* SC-VBR - PPP frames */ - IF( NE_32( ( error = decod_ppp_fx( st_fx, Aq_fx, pitch_buf_fx, exc_fx, exc2_fx, st_fx->bfi, gain_buf, voice_factors, bwe_exc_fx ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = decod_ppp_fx( st, Aq_fx, pitch_buf_fx, exc_fx, exc2_fx, st->bfi, gain_buf_fx, voice_factors_fx, bwe_exc_fx ) ), IVAS_ERR_OK ) ) { return error; } - Rescale_exc( hMusicPF->dct_post_old_exc_fx, exc_fx, NULL, st_fx->hGSCDec->last_exc_dct_in_fx, L_FRAME, 0, (Word32) 0, &( st_fx->Q_exc ), st_fx->Q_subfr, exc2_fx, L_FRAME, st_fx->coder_type ); + Rescale_exc( st->hMusicPF->dct_post_old_exc_fx, exc_fx, NULL, st->hGSCDec->last_exc_dct_in_fx, L_FRAME, 0, (Word32) 0, &( st->Q_exc ), st->Q_subfr, exc2_fx, L_FRAME, st->coder_type ); } - ELSE IF( EQ_16( st_fx->coder_type, TRANSITION ) ) + ELSE IF( EQ_16( st->coder_type, TRANSITION ) ) { - decod_tran_fx( st_fx, st_fx->L_frame, tc_subfr_fx, Aq_fx, Es_pred_fx, pitch_buf_fx, voice_factors, exc_fx, exc2_fx, bwe_exc_fx, unbits, sharpFlag, gain_buf ); + decod_tran_fx( st, st->L_frame, tc_subfr, Aq_fx, Es_pred_fx, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, unbits, sharpFlag, gain_buf_fx ); } - ELSE IF( EQ_16( st_fx->coder_type, AUDIO ) || ( ( st_fx->coder_type == INACTIVE ) && LE_32( st_fx->core_brate, MAX_GSC_INACTIVE_BRATE ) ) ) + ELSE IF( EQ_16( st->coder_type, AUDIO ) || ( ( st->coder_type == INACTIVE ) && st->inactive_coder_type_flag ) ) { - decod_audio_fx( st_fx, dct_exc_tmp, Aq_fx, pitch_buf_fx, voice_factors, exc_fx, exc2_fx, bwe_exc_fx, lsf_new_fx, gain_buf ); - tmp_noise_fx = shr_r( st_fx->lp_gainc_fx, 3 ); /*Q0*/ + /* AUDIO and INACTIVE frames (coded by GSC technology) */ + decod_audio_fx( st, dct_exc_tmp_fx, Aq_fx, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, lsf_new_fx, gain_buf_fx, + tdm_lp_reuse_flag, tdm_low_rate_mode, tdm_Pitch_reuse_flag, p_tdm_Pri_pitch_buf_fx ); + + tmp_noise_fx = shr_r( st->lp_gainc_fx, 3 ); /*Q0*/ } ELSE { - IF( NE_32( ( error = decod_gen_voic_fx( st_fx, st_fx->L_frame, sharpFlag, Aq_fx, Es_pred_fx, do_WI_fx, pitch_buf_fx, voice_factors, exc_fx, exc2_fx, bwe_exc_fx, unbits, gain_buf /*, tdm_Pitch_reuse_flag, p_tdm_Pri_pitch_buf*/ ) ), IVAS_ERR_OK ) ) + /* GENERIC, VOICED and INACTIVE frames (coded by AVQ technology) */ + IF( NE_32( ( error = decod_gen_voic_fx( st, st->L_frame, sharpFlag, Aq_fx, Es_pred_fx, do_WI, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, unbits, gain_buf_fx, tdm_Pitch_reuse_flag, p_tdm_Pri_pitch_buf_fx ) ), IVAS_ERR_OK ) ) { return error; } - IF( EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) + IF( EQ_16( st->element_mode, IVAS_CPE_TD ) ) { - tmp_noise_fx = shr_r( st_fx->lp_gainc_fx, 3 ); /*Q0*/ + tmp_noise_fx = shr_r( st->lp_gainc_fx, 3 ); /*Q0*/ } } /* synthesis for ACELP core switching and SWB BWE */ - syn_12k8_fx( st_fx->L_frame, Aq_fx, exc_fx, temp_buf_fx, st_fx->mem_syn1_fx, 1, st_fx->Q_exc, -1 ); + syn_12k8_fx( st->L_frame, Aq_fx, exc_fx, temp_buf_fx, st->mem_syn1_fx, 1, st->Q_exc, -1 ); + /* save and delay synthesis to be used by SWB BWE */ - IF( hBWE_FD != NULL ) + IF( st->hBWE_FD != NULL ) { - save_old_syn_fx( st_fx->L_frame, temp_buf_fx, old_syn_12k8_16k, hBWE_FD->old_syn_12k8_16k_fx, st_fx->preemph_fac, &hBWE_FD->mem_deemph_old_syn_fx ); + save_old_syn_fx( st->L_frame, temp_buf_fx, old_syn_12k8_16k_fx, st->hBWE_FD->old_syn_12k8_16k_fx, st->preemph_fac, &st->hBWE_FD->mem_deemph_old_syn_fx ); } /*-----------------------------------------------------------------* * Apply energy matching when switching to inactive frames *-----------------------------------------------------------------*/ - Inac_swtch_ematch_fx( exc2_fx, dct_exc_tmp, st_fx->hGSCDec->lt_ener_per_band_fx, st_fx->coder_type, st_fx->L_frame, st_fx->core_brate, st_fx->Q_exc, st_fx->bfi, st_fx->last_core, st_fx->last_codec_mode ); + Inac_switch_ematch_fx( exc2_fx, dct_exc_tmp_fx, st->hGSCDec->lt_ener_per_band_fx, st->coder_type, st->inactive_coder_type_flag, st->L_frame, st->Q_exc, st->bfi, st->last_core, st->last_codec_mode, tdm_low_rate_mode, st->element_mode ); + /*------------------------------------------------------------* * Decode information and modify the excitation signal of stationary unvoiced frames *------------------------------------------------------------*/ + test(); test(); test(); test(); - IF( !( EQ_16( st_fx->idchan, 1 ) && EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) && NE_16( st_fx->nelp_mode_dec, 1 ) && !( EQ_16( st_fx->element_mode, IVAS_SCE ) && tdm_low_rate_mode ) ) + IF( !( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) ) && NE_16( st->nelp_mode_dec, 1 ) && !( EQ_16( st->element_mode, IVAS_SCE ) && tdm_low_rate_mode ) ) { - stat_noise_uv_dec_fx( st_fx, lsp_new_fx, lsp_mid_fx, Aq_fx, exc2_fx, uc_two_stage_flag ); + Word16 temp_q_exc = st->Q_exc; + move16(); + stat_noise_uv_dec_fx( st, lsp_new_fx, lsp_mid_fx, Aq_fx, exc2_fx, uc_two_stage_flag ); + IF( NE_16( temp_q_exc, st->Q_exc ) ) + { + scale_sig( exc_fx - L_EXC_MEM, L_EXC_MEM + st->L_frame, sub( st->Q_exc, temp_q_exc ) ); + } } /*------------------------------------------------------------* @@ -861,80 +1180,92 @@ ivas_error acelp_core_dec_fx( *------------------------------------------------------------*/ /* update past excitation signals for LD music post-filter */ - IF( hMusicPF != NULL ) + IF( st->hMusicPF != NULL ) { - Copy( hMusicPF->dct_post_old_exc_fx + L_FRAME, hMusicPF->dct_post_old_exc_fx, DCT_L_POST - L_FRAME - OFFSET2 ); - Copy( exc2_fx, hMusicPF->dct_post_old_exc_fx + ( DCT_L_POST - L_FRAME - OFFSET2 ), L_FRAME ); - Copy( hMusicPF->dct_post_old_exc_fx, exc_buffer_fx, DCT_L_POST - OFFSET2 ); + Copy( st->hMusicPF->dct_post_old_exc_fx + L_FRAME, st->hMusicPF->dct_post_old_exc_fx, DCT_L_POST - L_FRAME - OFFSET2 ); + Copy( exc2_fx, st->hMusicPF->dct_post_old_exc_fx + ( DCT_L_POST - L_FRAME - OFFSET2 ), L_FRAME ); + Copy( st->hMusicPF->dct_post_old_exc_fx, exc_buffer_fx, DCT_L_POST - OFFSET2 ); } + test(); test(); test(); - test(); - IF( hMusicPF != NULL && ( ( EQ_16( st_fx->coder_type, AUDIO ) && st_fx->GSC_noisy_speech == 0 ) || ( GE_16( st_fx->GSC_IVAS_mode, 1 ) && EQ_16( st_fx->L_frame, L_FRAME ) ) ) ) + IF( ( EQ_16( st->coder_type, AUDIO ) && !st->GSC_noisy_speech ) || ( GE_16( st->GSC_IVAS_mode, 1 ) && EQ_16( st->L_frame, L_FRAME ) ) ) { - - Word16 last_coder_type = st_fx->last_coder_type; + Word16 last_coder_type = st->last_coder_type; move16(); + test(); test(); test(); - if ( ( EQ_16( st_fx->idchan, 1 ) && EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) || ( GE_16( st_fx->GSC_IVAS_mode, 1 ) && st_fx->GSC_noisy_speech == 0 ) ) + if ( ( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) ) || ( GE_16( st->GSC_IVAS_mode, 1 ) && ( st->GSC_noisy_speech == 0 ) ) ) { last_coder_type = AUDIO; move16(); } - /* Extrapolation of the last future part, windowing and high resolution DCT transform */ - qdct = 0; + + Word16 qdct = 0; move16(); -#ifdef _DIFF_FLOAT_FIX_ /* FLoat point using last_core which fits with the inner part of the function */ - Prep_music_postP_fx( exc_buffer_fx, dct_buffer_fx, hMusicPF->filt_lfE_fx, st_fx->last_core, st_fx->element_mode, pitch_buf_fx, - hMusicPF->LDm_enh_lp_gbin_fx, st_fx->Q_exc, &qdct ); -#else - Prep_music_postP_fx( exc_buffer_fx, dct_buffer_fx, hMusicPF->filt_lfE_fx, st_fx->last_coder_type, st_fx->element_mode, pitch_buf_fx, - hMusicPF->LDm_enh_lp_gbin_fx, st_fx->Q_exc, &qdct ); -#endif + + /* Extrapolation of the last future part, windowing and high resolution DCT transform */ + IF( EQ_16( st->element_mode, EVS_MONO ) ) + { + // VE: TBV: this is likely a bug in EVS - 'st->last_coder_type' should be replaced by 'st->core_brate' + Prep_music_postP_fx( exc_buffer_fx, dct_buffer_fx, st->hMusicPF->filt_lfE_fx, st->last_coder_type, st->element_mode, pitch_buf_fx, + st->hMusicPF->LDm_enh_lp_gbin_fx, st->Q_exc, &qdct ); + } + ELSE + { + Prep_music_postP_fx( exc_buffer_fx, dct_buffer_fx, st->hMusicPF->filt_lfE_fx, st->last_core, st->element_mode, pitch_buf_fx, st->hMusicPF->LDm_enh_lp_gbin_fx, st->Q_exc, &qdct ); + } + /* LD music post-filter */ - LD_music_post_filter_fx( hMusicPF, dct_buffer_fx, dct_buffer_fx, st_fx->core_brate, - &hMusicPF->Old_ener_Q, AUDIO, last_coder_type, qdct ); + LD_music_post_filter_fx( st->hMusicPF, dct_buffer_fx, dct_buffer_fx, st->core_brate, &st->hMusicPF->Old_ener_Q, AUDIO, last_coder_type, qdct ); /* Inverse DCT transform, retrieval of the aligned excitation, re-synthesis */ - Post_music_postP_fx( dct_buffer_fx, exc2_fx, st_fx->mem_syn2_fx, st_fx->mem_syn2_fx, Aq_fx, syn_fx, &st_fx->Q_exc, &st_fx->prev_Q_syn, - &st_fx->Q_syn, st_fx->mem_syn_clas_estim_fx, 0, &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, temp_buf_fx, mem_tmp_fx ); + IF( NE_16( st->element_mode, EVS_MONO ) ) // VE: TBC whether needed in IVAS + { + Copy( st->mem_syn2_fx, mem_tmp_fx, M ); /*Q_syn*/ + } + + Post_music_postP_fx( dct_buffer_fx, exc2_fx, st->mem_syn2_fx, st->mem_syn2_fx, Aq_fx, psyn_fx, &st->Q_exc, &st->prev_Q_syn, + &st->Q_syn, st->mem_syn_clas_estim_fx, 0, &st->mem_deemph_fx, st->hBPF->pst_old_syn_fx, + &st->hBPF->pst_mem_deemp_err_fx, &st->agc_mem_fx[1], st->hPFstat, temp_buf_fx, mem_tmp_fx ); } ELSE { /* Core synthesis at 12.8kHz or 16kHz */ i = 1; move16(); - if ( st_fx->coder_type == INACTIVE ) + test(); + if ( st->coder_type == INACTIVE && st->element_mode == EVS_MONO ) { i = 0; move16(); } + /* add extra headroom in case a CNA addition is likely (i.e. st_fx->psf_lp_noise_fx is close to the threshold) */ - k = 0; + Word16 k = 0; move16(); test(); test(); - if ( ( st_fx->coder_type == INACTIVE ) && st_fx->flag_cna && GE_16( round_fx( L_shl( st_fx->lp_noise, 1 ) ), 15 << 7 ) ) + if ( st->coder_type == INACTIVE && st->flag_cna && GE_16( round_fx( L_shl( st->lp_noise, 1 ) ), 15 << 7 ) ) { k = 1; move16(); } - Rescale_mem( st_fx->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, i, k, temp_buf_fx ); - Copy( st_fx->mem_syn2_fx, mem_tmp_fx, M ); // Q_syn + Rescale_mem( st->Q_exc, &st->prev_Q_syn, &st->Q_syn, st->mem_syn2_fx, st->mem_syn_clas_estim_fx, 4, &st->mem_deemph_fx, + st->hBPF->pst_old_syn_fx, &st->hBPF->pst_mem_deemp_err_fx, &st->agc_mem_fx[1], st->hPFstat, i, k, temp_buf_fx ); + + Copy( st->mem_syn2_fx, mem_tmp_fx, M ); /*Q_syn*/ + syn_12k8_fx( st->L_frame, Aq_fx, exc2_fx, psyn_fx, st->mem_syn2_fx, 1, st->Q_exc, st->Q_syn ); - syn_12k8_fx( st_fx->L_frame, Aq_fx, exc2_fx, syn_fx, st_fx->mem_syn2_fx, 1, st_fx->Q_exc, st_fx->Q_syn ); - IF( hMusicPF != NULL ) + IF( st->hMusicPF != NULL ) { FOR( i = 0; i < DCT_L_POST; i++ ) { - /*st_fx->filt_lfE_fx[i] = 0.3f + 0.7f * st_fx->filt_lfE_fx[i];*/ - hMusicPF->filt_lfE_fx[i] = round_fx( L_mac( ( 1228 << ( 16 ) ), 22938, hMusicPF->filt_lfE_fx[i] ) ); + st->hMusicPF->filt_lfE_fx[i] = round_fx( L_mac( ( 1228 << ( 16 ) ), 22938, st->hMusicPF->filt_lfE_fx[i] ) ); move16(); } } @@ -944,43 +1275,35 @@ ivas_error acelp_core_dec_fx( * FEC - Estimate the classification information *------------------------------------------------------------*/ - FEC_clas_estim_fx( st_fx, st_fx->Opt_AMR_WB, st_fx->L_frame, &st_fx->clas_dec, st_fx->coder_type, pitch_buf_fx, - syn_fx, &st_fx->lp_ener_FER_fx, &st_fx->decision_hyst, - NULL, NULL, NULL, NULL, 0, NULL, st_fx->Q_syn, temp_buf_fx, - st_fx->mem_syn_clas_estim_fx, &st_fx->classifier_Q_mem_syn, - 0, 0, 0, st_fx->last_core_brate, st_fx->acelp_cfg.FEC_mode ); + FEC_clas_estim_fx( st, st->Opt_AMR_WB, st->L_frame, &st->clas_dec, st->coder_type, pitch_buf_fx, psyn_fx, &st->lp_ener_FER_fx, &st->decision_hyst, + NULL, NULL, NULL, NULL, 0, NULL, st->Q_syn, temp_buf_fx, st->mem_syn_clas_estim_fx, &st->classifier_Q_mem_syn, 0, 0, 0, st->last_core_brate, st->acelp_cfg.FEC_mode ); + /*------------------------------------------------------------* * FEC - Estimate pitch *------------------------------------------------------------*/ - FEC_pitch_estim_fx( st_fx->Opt_AMR_WB, st_fx->last_core, st_fx->L_frame, st_fx->clas_dec, st_fx->last_good, pitch_buf_fx, st_fx->old_pitch_buf_fx, - &st_fx->bfi_pitch_fx, &st_fx->bfi_pitch_frame, &st_fx->upd_cnt, st_fx->coder_type, st_fx->element_mode ); + FEC_pitch_estim_fx( st->Opt_AMR_WB, st->last_core, st->L_frame, st->clas_dec, st->last_good, pitch_buf_fx, st->old_pitch_buf_fx, + &st->bfi_pitch_fx, &st->bfi_pitch_frame, &st->upd_cnt, st->coder_type, st->element_mode ); /*------------------------------------------------------------* * FEC - Smooth the speech energy evolution when recovering after a BAD frame * (smoothing is performed in the excitation domain and signal is resynthesized after) *------------------------------------------------------------*/ - k = 0; - move16(); - FOR( i = 0; i < st_fx->L_frame; i += L_SUBFR ) - { - pitch_buf_tmp[k] = mult_r( pitch_buf_fx[k], 512 ); // Q0(6+9-15) , (512 = 1.0f in Q9) - move16(); - k = add( k, 1 ); - } + Copy_Scale_sig( pitch_buf_fx, pitch_buf_tmp, st->nb_subfr, -Q6 ); // Q0 - FEC_scale_syn_fx( st_fx->L_frame, &update_flg, st_fx->clas_dec, st_fx->last_good, syn_fx, pitch_buf_tmp, st_fx->enr_old_fx, enr_q_fx, st_fx->coder_type, LSF_Q_prediction, - &st_fx->scaling_flag, &st_fx->lp_ener_FEC_av, &st_fx->lp_ener_FEC_max, st_fx->bfi, st_fx->total_brate, st_fx->prev_bfi, st_fx->last_core_brate, - exc_fx, exc2_fx, Aq_fx, &st_fx->old_enr_LP, mem_tmp_fx, st_fx->mem_syn2_fx, st_fx->Q_exc, st_fx->Q_syn, avoid_lpc_burst_on_recovery, 0 ); + FEC_scale_syn_fx( st->L_frame, &update_flg, st->clas_dec, st->last_good, psyn_fx, pitch_buf_tmp, st->enr_old_fx, enr_q_fx, st->coder_type, LSF_Q_prediction, + &st->scaling_flag, &st->lp_ener_FEC_av, &st->lp_ener_FEC_max, st->bfi, st->total_brate, st->prev_bfi, st->last_core_brate, + exc_fx, exc2_fx, Aq_fx, &st->old_enr_LP, mem_tmp_fx, st->mem_syn2_fx, st->Q_exc, st->Q_syn, st->element_mode, avoid_lpc_burst_on_recovery, 0 ); test(); test(); test(); test(); - IF( ( EQ_16( st_fx->idchan, 1 ) && EQ_16( st_fx->element_mode, IVAS_CPE_TD ) && LE_32( st_fx->total_brate, ACELP_7k20 ) ) || ( EQ_32( st_fx->total_brate, ACELP_7k20 ) ) || ( EQ_32( st_fx->total_brate, ACELP_8k00 ) ) ) + /* estimate the pitch-synchronous speech energy per sample to be used when normal operation recovers */ + IF( ( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) && LE_32( st->total_brate, ACELP_7k20 ) ) || EQ_32( st->total_brate, ACELP_7k20 ) || EQ_32( st->total_brate, ACELP_8k00 ) ) { - frame_ener_fx( st_fx->L_frame, st_fx->clas_dec, syn_fx, pitch_buf_tmp[sub( shr( st_fx->L_frame, 6 ), 1 )], &st_fx->enr_old_fx, st_fx->L_frame, st_fx->Q_syn, 3, 0 ); + frame_ener_fx( st->L_frame, st->clas_dec, psyn_fx, pitch_buf_tmp[( ( st->L_frame ) >> 6 ) - 1], &st->enr_old_fx, st->L_frame, st->Q_syn, 3, 0 ); } } @@ -989,206 +1312,188 @@ ivas_error acelp_core_dec_fx( /*----------------------------------------------------------------* * BAD frame *----------------------------------------------------------------*/ + ELSE { /* SC-VBR */ - if ( EQ_16( st_fx->last_nelp_mode_dec, 1 ) ) + if ( EQ_16( st->last_nelp_mode_dec, 1 ) ) { - st_fx->nelp_mode_dec = 1; + st->nelp_mode_dec = 1; move16(); } - /* long burst frame erasures */ test(); test(); - if ( GT_16( st_fx->nbLostCmpt, 5 ) && GE_16( st_fx->clas_dec, VOICED_CLAS ) && LT_16( st_fx->clas_dec, INACTIVE_CLAS ) ) + /* long burst frame erasures */ + if ( GT_16( st->nbLostCmpt, 5 ) && GE_16( st->clas_dec, VOICED_CLAS ) && LT_16( st->clas_dec, INACTIVE_CLAS ) ) { - st_fx->last_good = VOICED_TRANSITION; + st->last_good = VOICED_TRANSITION; move16(); } /* LSF estimation and A(z) calculation */ - lsf_dec_bfi( MODE1, lsf_new_fx, st_fx->lsf_old_fx, st_fx->lsf_adaptive_mean_fx, NULL, st_fx->mem_MA_fx, st_fx->mem_AR_fx, - st_fx->stab_fac_fx, st_fx->last_coder_type, st_fx->L_frame, st_fx->last_good, - st_fx->nbLostCmpt, 0, NULL, NULL, NULL, st_fx->hGSCDec->Last_GSC_pit_band_idx, st_fx->Opt_AMR_WB, 0, st_fx->bwidth ); + lsf_dec_bfi( MODE1, lsf_new_fx, st->lsf_old_fx, st->lsf_adaptive_mean_fx, NULL, st->mem_MA_fx, st->mem_AR_fx, st->stab_fac_fx, st->last_coder_type, st->L_frame, st->last_good, st->nbLostCmpt, 0, NULL, NULL, NULL, st->hGSCDec->Last_GSC_pit_band_idx, st->Opt_AMR_WB, 0, st->bwidth ); - FEC_lsf2lsp_interp( st_fx, st_fx->L_frame, Aq_fx, lsf_new_fx, lsp_new_fx ); - - IF( EQ_16( st_fx->nelp_mode_dec, 1 ) ) + FEC_lsf2lsp_interp( st, st->L_frame, Aq_fx, lsf_new_fx, lsp_new_fx ); + IF( EQ_16( st->nelp_mode_dec, 1 ) ) { /* SC-VBR */ - Scale_sig( exc_fx - L_EXC_MEM, L_EXC_MEM, negate( st_fx->Q_exc ) ); // Q0 - st_fx->Q_exc = 0; + Scale_sig( exc_fx - L_EXC_MEM, L_EXC_MEM, negate( st->Q_exc ) ); // Q0 + st->Q_exc = 0; move16(); - decod_nelp_fx( st_fx, &tmp_noise_fx, pitch_buf_fx, exc_fx, exc2_fx, voice_factors, bwe_exc_fx, &st_fx->Q_exc, st_fx->bfi, gain_buf ); + decod_nelp_fx( st, &tmp_noise_fx, pitch_buf_fx, exc_fx, exc2_fx, voice_factors_fx, bwe_exc_fx, &st->Q_exc, st->bfi, gain_buf_fx ); FEC_pitch_fx = pitch_buf_fx[3]; move16(); - - Rescale_exc( hMusicPF->dct_post_old_exc_fx, exc_fx, NULL, st_fx->hGSCDec->last_exc_dct_in_fx, L_FRAME, 0, (Word32) 0, &( st_fx->Q_exc ), st_fx->Q_subfr, exc2_fx, L_FRAME, st_fx->coder_type ); + Rescale_exc( st->hMusicPF->dct_post_old_exc_fx, exc_fx, NULL, st->hGSCDec->last_exc_dct_in_fx, L_FRAME, 0, (Word32) 0, &( st->Q_exc ), st->Q_subfr, exc2_fx, L_FRAME, st->coder_type ); } ELSE { /* calculation of excitation signal */ + FEC_exc_estim_fx( st, st->L_frame, exc_fx, exc2_fx, dct_exc_tmp_fx, pitch_buf_fx, voice_factors_fx, &FEC_pitch_fx, bwe_exc_fx, lsf_new_fx, &st->Q_exc, &tmp_noise_fx ); - FEC_exc_estim_fx( st_fx, st_fx->L_frame, exc_fx, exc2_fx, dct_exc_tmp, pitch_buf_fx, voice_factors, &FEC_pitch_fx, bwe_exc_fx, lsf_new_fx, &st_fx->Q_exc, &tmp_noise_fx ); - - Rescale_exc( NULL, exc_fx, bwe_exc_fx, st_fx->hGSCDec->last_exc_dct_in_fx, st_fx->L_frame, L_FRAME32k, (Word32) 0, - &( st_fx->Q_exc ), st_fx->Q_subfr, exc2_fx, st_fx->L_frame, st_fx->last_coder_type ); + Rescale_exc( NULL, exc_fx, bwe_exc_fx, st->hGSCDec->last_exc_dct_in_fx, st->L_frame, L_FRAME32k, (Word32) 0, + &( st->Q_exc ), st->Q_subfr, exc2_fx, st->L_frame, st->last_coder_type ); - tmp_noise_fx = shr_r( st_fx->lp_gainc_fx, 3 ); /*Q0*/ + tmp_noise_fx = shr_r( st->lp_gainc_fx, 3 ); /*Q0*/ /* SC-VBR */ - st_fx->prev_gain_pit_dec_fx = st_fx->lp_gainp_fx; - move16(); /*Q14*/ + st->prev_gain_pit_dec_fx = st->lp_gainp_fx; + move16(); } /* synthesis for ACELP core switching and SWB BWE */ - syn_12k8_fx( st_fx->L_frame, Aq_fx, exc_fx, temp_buf_fx, st_fx->mem_syn1_fx, 1, st_fx->Q_exc, -1 ); /*old_syn_12k8_16k directly in q-1*/ + syn_12k8_fx( st->L_frame, Aq_fx, exc_fx, temp_buf_fx, st->mem_syn1_fx, 1, st->Q_exc, -1 ); /* save and delay synthesis to be used by SWB BWE */ - IF( hBWE_FD != NULL ) + IF( st->hBWE_FD != NULL ) { - save_old_syn_fx( st_fx->L_frame, temp_buf_fx, old_syn_12k8_16k, hBWE_FD->old_syn_12k8_16k_fx, st_fx->preemph_fac, &hBWE_FD->mem_deemph_old_syn_fx ); + save_old_syn_fx( st->L_frame, temp_buf_fx, old_syn_12k8_16k_fx, st->hBWE_FD->old_syn_12k8_16k_fx, st->preemph_fac, &st->hBWE_FD->mem_deemph_old_syn_fx ); } + /* Apply energy matching when switching to inactive frames */ - Inac_swtch_ematch_fx( exc2_fx, dct_exc_tmp, st_fx->hGSCDec->lt_ener_per_band_fx, st_fx->coder_type, st_fx->L_frame, st_fx->core_brate, st_fx->Q_exc, st_fx->bfi, st_fx->last_core, st_fx->last_codec_mode ); + Inac_switch_ematch_fx( exc2_fx, dct_exc_tmp_fx, st->hGSCDec->lt_ener_per_band_fx, st->coder_type, st->inactive_coder_type_flag, st->L_frame, st->Q_exc, st->bfi, st->last_core, st->last_codec_mode, tdm_low_rate_mode, st->element_mode ); - /* udate past excitation signals for LD music post-filter */ - IF( hMusicPF != NULL ) + /* update past excitation signals for LD music post-filter */ + IF( st->hMusicPF != NULL ) { - Copy( hMusicPF->dct_post_old_exc_fx + L_FRAME, hMusicPF->dct_post_old_exc_fx, DCT_L_POST - L_FRAME - OFFSET2 ); - Copy( exc2_fx, hMusicPF->dct_post_old_exc_fx + ( DCT_L_POST - L_FRAME - OFFSET2 ), L_FRAME ); + Copy( st->hMusicPF->dct_post_old_exc_fx + L_FRAME, st->hMusicPF->dct_post_old_exc_fx, DCT_L_POST - L_FRAME - OFFSET2 ); + Copy( exc2_fx, st->hMusicPF->dct_post_old_exc_fx + ( DCT_L_POST - L_FRAME - OFFSET2 ), L_FRAME ); + /* Update music post processing values */ /* Filter energies update */ FOR( i = 0; i < DCT_L_POST; i++ ) { - /*st_fx->filt_lfE_fx[i] = 0.3f + 0.7f * st_fx->filt_lfE_fx[i];*/ - hMusicPF->filt_lfE_fx[i] = round_fx( L_mac( ( 1228 << ( 16 ) ), 22938, hMusicPF->filt_lfE_fx[i] ) ); + st->hMusicPF->filt_lfE_fx[i] = round_fx( L_mac( 1228 << 16, 22938, st->hMusicPF->filt_lfE_fx[i] ) ); move16(); } + /* Update circular buffer, keep last energy difference unchanged */ FOR( i = 1; i < MAX_LT; i++ ) { - hMusicPF->LDm_lt_diff_etot_fx[i - 1] = hMusicPF->LDm_lt_diff_etot_fx[i]; + st->hMusicPF->LDm_lt_diff_etot_fx[i - 1] = st->hMusicPF->LDm_lt_diff_etot_fx[i]; move16(); } } + /* synthesis at 12k8 Hz sampling rate */ /* add extra headroom in case a CNA addition is likely (i.e. st_fx->psf_lp_noise_fx is close to the threshold) */ - k = 0; + Word16 k = 0; move16(); test(); test(); - if ( ( st_fx->coder_type == INACTIVE ) && st_fx->flag_cna && GE_16( round_fx( L_shl( st_fx->lp_noise, 1 ) ), 15 << 7 ) ) + if ( st->coder_type == INACTIVE && st->flag_cna && GE_16( round_fx( L_shl( st->lp_noise, 1 ) ), 15 << 7 ) ) { k = 1; move16(); } - Rescale_mem( st_fx->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, k, temp_buf_fx ); + Rescale_mem( st->Q_exc, &st->prev_Q_syn, &st->Q_syn, st->mem_syn2_fx, st->mem_syn_clas_estim_fx, 4, &st->mem_deemph_fx, + st->hBPF->pst_old_syn_fx, &st->hBPF->pst_mem_deemp_err_fx, &st->agc_mem_fx[1], st->hPFstat, 1, k, temp_buf_fx ); test(); - IF( ( EQ_32( st_fx->total_brate, ACELP_7k20 ) ) || ( EQ_32( st_fx->total_brate, ACELP_8k00 ) ) ) + IF( EQ_32( st->total_brate, ACELP_7k20 ) || EQ_32( st->total_brate, ACELP_8k00 ) ) { - Copy( st_fx->mem_syn2_fx, mem_tmp_fx, M ); // Q_syn + Copy( st->mem_syn2_fx, mem_tmp_fx, M ); } - syn_12k8_fx( st_fx->L_frame, Aq_fx, exc2_fx, syn_fx, st_fx->mem_syn2_fx, 1, st_fx->Q_exc, st_fx->Q_syn ); + syn_12k8_fx( st->L_frame, Aq_fx, exc2_fx, psyn_fx, st->mem_syn2_fx, 1, st->Q_exc, st->Q_syn ); /* update buffer for classifier */ - IF( st_fx->hWIDec != NULL ) + IF( st->hWIDec != NULL ) { - Copy( exc2_fx + st_fx->L_frame - L_EXC_MEM, st_fx->hWIDec->old_exc2_fx, L_EXC_MEM ); - Copy( syn_fx + st_fx->L_frame - L_EXC_MEM, st_fx->hWIDec->old_syn2_fx, L_EXC_MEM ); + Copy( exc2_fx + sub( st->L_frame, L_EXC_MEM ), st->hWIDec->old_exc2_fx, L_EXC_MEM ); + Copy( psyn_fx + sub( st->L_frame, L_EXC_MEM ), st->hWIDec->old_syn2_fx, L_EXC_MEM ); } - st_fx->prev_Q_exc_fr = st_fx->Q_exc; - move16(); - st_fx->prev_Q_syn_fr = st_fx->Q_syn; - move16(); - - Copy( syn_fx + st_fx->L_frame - L_SYN_MEM_CLAS_ESTIM, st_fx->mem_syn_clas_estim_fx, L_SYN_MEM_CLAS_ESTIM ); - - test(); - IF( ( EQ_32( st_fx->total_brate, ACELP_7k20 ) ) || ( EQ_32( st_fx->total_brate, ACELP_8k00 ) ) ) - { - k = 0; + st->prev_Q_exc_fr = st->Q_exc; move16(); - FOR( i = 0; i < st_fx->L_frame; i += L_SUBFR ) - { - pitch_buf_tmp[k] = mult_r( pitch_buf_fx[k], 512 ); // Q0(6+9-15) , (512 = 1.0f in Q9) + st->prev_Q_syn_fr = st->Q_syn; move16(); - k = add( k, 1 ); - } + Copy( psyn_fx + sub( st->L_frame, L_SYN_MEM_CLAS_ESTIM ), st->mem_syn_clas_estim_fx, L_SYN_MEM_CLAS_ESTIM ); /*------------------------------------------------------------* * FEC - Smooth the speech energy evolution when recovering after a BAD frame * (smoothing is performed in the excitation domain and signal is resynthesized after) *------------------------------------------------------------*/ - FEC_scale_syn_fx( st_fx->L_frame, &update_flg, st_fx->clas_dec, st_fx->last_good, syn_fx, pitch_buf_tmp, st_fx->enr_old_fx, enr_q_fx, st_fx->coder_type, LSF_Q_prediction, - &st_fx->scaling_flag, &st_fx->lp_ener_FEC_av, &st_fx->lp_ener_FEC_max, st_fx->bfi, st_fx->total_brate, st_fx->prev_bfi, st_fx->last_core_brate, - exc_fx, exc2_fx, Aq_fx, &st_fx->old_enr_LP, mem_tmp_fx, st_fx->mem_syn2_fx, st_fx->Q_exc, st_fx->Q_syn, avoid_lpc_burst_on_recovery, 0 ); + test(); + IF( EQ_32( st->total_brate, ACELP_7k20 ) || EQ_32( st->total_brate, ACELP_8k00 ) ) + { + Copy_Scale_sig( pitch_buf_fx, pitch_buf_tmp, st->nb_subfr, -Q6 ); // Q0 + + FEC_scale_syn_fx( st->L_frame, &update_flg, st->clas_dec, st->last_good, psyn_fx, pitch_buf_tmp, st->enr_old_fx, enr_q_fx, st->coder_type, LSF_Q_prediction, + &st->scaling_flag, &st->lp_ener_FEC_av, &st->lp_ener_FEC_max, st->bfi, st->total_brate, st->prev_bfi, st->last_core_brate, + exc_fx, exc2_fx, Aq_fx, &st->old_enr_LP, mem_tmp_fx, st->mem_syn2_fx, st->Q_exc, st->Q_syn, st->element_mode, avoid_lpc_burst_on_recovery, 0 ); } /* estimate the pitch-synchronous speech energy per sample to be used when normal operation recovers */ - /* fer_energy( st_fx->L_frame, st_fx->last_good, syn_fx, FEC_pitch_fx, &st_fx->enr_old_fx, st_fx->L_frame ); */ - frame_ener_fx( st_fx->L_frame, st_fx->last_good, syn_fx, shr( add( FEC_pitch_fx, 32 ), 6 ), &st_fx->enr_old_fx, st_fx->L_frame, st_fx->Q_syn, 3, 0 ); + frame_ener_fx( st->L_frame, st->last_good, psyn_fx, shr( add( FEC_pitch_fx, 32 ), 6 ), &st->enr_old_fx, st->L_frame, st->Q_syn, 3, 0 ); - IF( st_fx->nelp_mode_dec != 1 ) + IF( NE_16( st->nelp_mode_dec, 1 ) ) { /* modify the excitation signal of stationary unvoiced frames */ - stat_noise_uv_mod_fx( st_fx->coder_type, 0, st_fx->lsp_old_fx, lsp_new_fx, lsp_new_fx, Aq_fx, exc2_fx, st_fx->Q_exc, 1, &st_fx->ge_sm_fx, - &st_fx->uv_count, &st_fx->act_count, st_fx->lspold_s_fx, &st_fx->noimix_seed, &st_fx->min_alpha_fx, - &st_fx->exc_pe_fx, st_fx->core_brate, st_fx->bwidth, &st_fx->Q_stat_noise, &st_fx->Q_stat_noise_ge ); + stat_noise_uv_mod_fx( st->coder_type, 0, st->lsp_old_fx, lsp_new_fx, lsp_new_fx, Aq_fx, exc2_fx, st->Q_exc, 1, &st->ge_sm_fx, + &st->uv_count, &st->act_count, st->lspold_s_fx, &st->noimix_seed, &st->min_alpha_fx, + &st->exc_pe_fx, st->core_brate, st->bwidth, &st->Q_stat_noise, &st->Q_stat_noise_ge ); + } } - /* SC-VBR */ - st_fx->hSC_VBR->FadeScale_fx = mult( st_fx->hSC_VBR->FadeScale_fx, 24576 ); /*24576 in Q15*/ - move16(); - } - IF( hBWE_TD != NULL ) + IF( st->hBWE_TD != NULL ) { - IF( EQ_16( st_fx->L_frame, L_FRAME ) ) + IF( EQ_16( st->L_frame, L_FRAME ) ) { - Copy( Aq_fx + 2 * ( M + 1 ), hBWE_TD->cur_sub_Aq_fx, ( M + 1 ) ); // Q12 + Copy( Aq_fx + 2 * ( M + 1 ), st->hBWE_TD->cur_sub_Aq_fx, ( M + 1 ) ); } ELSE { - Copy( Aq_fx + 3 * ( M + 1 ), hBWE_TD->cur_sub_Aq_fx, ( M + 1 ) ); // Q12 + Copy( Aq_fx + 3 * ( M + 1 ), st->hBWE_TD->cur_sub_Aq_fx, ( M + 1 ) ); } } + /*--------------------------------------------------------* * Apply NB postfilter in case of 8kHz output *--------------------------------------------------------*/ + test(); - IF( EQ_16( st_fx->last_bwidth, NB ) && st_fx->hPFstat != NULL ) + IF( st->last_bwidth == NB && st->hPFstat != NULL ) { - k = 0; - move16(); - FOR( i = 0; i < st_fx->L_frame; i += L_SUBFR ) - { - pitch_buf_tmp[k] = mult_r( pitch_buf_fx[k], 512 ); // Q0(6+9-15) , (512 = 1.0f in Q9) - move16(); - k = add( k, 1 ); - } + Copy_Scale_sig( pitch_buf_fx, pitch_buf_tmp, st->nb_subfr, -Q6 ); // Q0 - IF( EQ_16( st_fx->bwidth, NB ) ) + IF( st->bwidth == NB ) { - st_fx->hPFstat->on = 1; + st->hPFstat->on = 1; move16(); - nb_post_filt_fx( st_fx->L_frame, st_fx->hPFstat, &st_fx->psf_lp_noise_fx, tmp_noise_fx, syn_fx, Aq_fx, pitch_buf_tmp, st_fx->coder_type, st_fx->BER_detect, 0 ); + nb_post_filt_fx( st->L_frame, st->hPFstat, &st->psf_lp_noise_fx, tmp_noise_fx, psyn_fx, Aq_fx, pitch_buf_tmp, st->coder_type, st->BER_detect, 0 ); } ELSE { - st_fx->hPFstat->on = 0; + st->hPFstat->on = 0; move16(); - nb_post_filt_fx( st_fx->L_frame, st_fx->hPFstat, &st_fx->psf_lp_noise_fx, tmp_noise_fx, syn_fx, Aq_fx, pitch_buf_tmp, AUDIO, st_fx->BER_detect, 0 ); + nb_post_filt_fx( st->L_frame, st->hPFstat, &st->psf_lp_noise_fx, tmp_noise_fx, psyn_fx, Aq_fx, pitch_buf_tmp, AUDIO, st->BER_detect, 0 ); } } ELSE { - st_fx->psf_lp_noise_fx = round_fx( L_shl( st_fx->lp_noise, 1 ) ); + st->psf_lp_noise_fx = round_fx( L_shl( st->lp_noise, 1 ) ); move16(); } @@ -1196,137 +1501,255 @@ ivas_error acelp_core_dec_fx( * Perform fixed deemphasis through 1/(1 - g*z^-1) *-----------------------------------------------------------------*/ - /* Update old synthesis buffer - needed for ACELP internal sampling rate switching */ - Copy( syn_fx + st_fx->L_frame - L_SYN_MEM, st_fx->mem_syn_r, L_SYN_MEM ); - deemph_fx( syn_fx, st_fx->preemph_fac, st_fx->L_frame, &( st_fx->mem_deemph_fx ) ); - unscale_AGC( syn_fx, st_fx->Q_syn, syn_fx_tmp2, st_fx->agc_mem_fx, st_fx->L_frame ); - Copy( syn_fx_tmp2, syn_fx, st_fx->L_frame ); - - /* Update MODE2 memories*/ - IF( hTcxDec != NULL ) + /* update old synthesis buffer - needed for ACELP internal sampling rate switching */ + Copy( psyn_fx + sub( st->L_frame, L_SYN_MEM ), st->mem_syn_r, L_SYN_MEM ); + deemph_fx( psyn_fx, st->preemph_fac, st->L_frame, &( st->mem_deemph_fx ) ); + unscale_AGC( psyn_fx, st->Q_syn, syn_fx_tmp2, st->agc_mem_fx, st->L_frame ); + Copy( syn_fx_tmp2, psyn_fx, st->L_frame ); + IF( st->hTcxDec != NULL ) { - Copy_Scale_sig( syn_fx + shr( st_fx->L_frame, 1 ), hTcxDec->old_syn_Overl, shr( st_fx->L_frame, 1 ), sub( -1, st_fx->Q_syn ) ); /*Q-1*/ + Copy_Scale_sig( psyn_fx + shr( st->L_frame, 1 ), st->hTcxDec->old_syn_Overl, shr( st->L_frame, 1 ), sub( -1, st->Q_syn ) ); /*Q-1*/ + st->hTcxDec->Q_old_syn_Overl = -1; } - Copy_Scale_sig( syn_fx + st_fx->L_frame - M - 1, st_fx->syn, M + 1, sub( 0, st_fx->Q_syn ) ); /*Q0*/ + Copy_Scale_sig( psyn_fx + sub( st->L_frame, M + 1 ), st->syn, M + 1, sub( 0, st->Q_syn ) ); /*Q0*/ /*------------------------------------------------------------------* * Formant post-filter *-----------------------------------------------------------------*/ - IF( st_fx->hPFstat != NULL ) - { test(); test(); test(); - IF( GE_16( st_fx->last_bwidth, WB ) && ( GT_32( st_fx->core_brate, ACELP_24k40 ) || ( st_fx->element_mode > EVS_MONO ) ) && LE_32( st_fx->core_brate, ACELP_32k ) ) + test(); + IF( st->hPFstat != NULL && GE_16( st->last_bwidth, WB ) && ( GT_32( st->core_brate, ACELP_24k40 ) || st->element_mode > EVS_MONO ) && LE_32( st->core_brate, ACELP_32k ) ) { - Copy( syn_fx, temp_buf + L_SYN_MEM, L_FRAME16k ); - st_fx->hPFstat->on = 1; + st->hPFstat->on = 1; move16(); - formant_post_filt_fx( st_fx->hPFstat, temp_buf + L_SYN_MEM, Aq_fx, syn_fx, L_FRAME16k, st_fx->lp_noise, st_fx->total_brate, 0 ); + Copy( psyn_fx, temp_buf_fx + L_SYN_MEM, L_FRAME16k ); + set16_fx( st->hPFstat->mem_zero, 0, M ); + + formant_post_filt_fx( st->hPFstat, temp_buf_fx + L_SYN_MEM, Aq_fx, psyn_fx, st->L_frame, st->lp_noise, st->total_brate, 0 ); } - ELSE IF( GE_16( st_fx->last_bwidth, WB ) ) + ELSE IF( st->hPFstat != NULL && GE_16( st->last_bwidth, WB ) ) { - IF( st_fx->hPFstat->on ) + IF( st->hPFstat->on ) { - Copy( st_fx->hPFstat->mem_pf_in + L_SYN_MEM - M, temp_buf, M ); - Copy( syn_fx, temp_buf + M, L_SUBFR ); - Residu3_fx( Aq_fx, temp_buf + M, temp_buf + M + L_SUBFR, L_SUBFR, 1 ); - E_UTIL_synthesis( 1, Aq_fx, temp_buf + M + L_SUBFR, temp_buf, L_SUBFR, st_fx->hPFstat->mem_stp + L_SYN_MEM - M, 0, M ); - scale_st_fx( syn_fx, temp_buf, &st_fx->hPFstat->gain_prec, L_SUBFR ); - Copy( temp_buf, syn_fx, L_SUBFR / 2 ); - blend_subfr2_fx( temp_buf + L_SUBFR / 2, syn_fx + L_SUBFR / 2, syn_fx + L_SUBFR / 2 ); + Copy( st->hPFstat->mem_pf_in + L_SYN_MEM - M, temp_buf_fx, M ); + Copy( psyn_fx, temp_buf_fx + M, L_SUBFR ); + + Residu3_fx( Aq_fx, temp_buf_fx + M, temp_buf_fx + M + L_SUBFR, L_SUBFR, 1 ); + E_UTIL_synthesis( 1, Aq_fx, temp_buf_fx + M + L_SUBFR, temp_buf_fx, L_SUBFR, st->hPFstat->mem_stp + L_SYN_MEM - M, 0, M ); + scale_st_fx( psyn_fx, temp_buf_fx, &st->hPFstat->gain_prec, L_SUBFR ); + Copy( temp_buf_fx, psyn_fx, ( L_SUBFR >> 1 ) ); + blend_subfr2_fx( temp_buf_fx + L_SUBFR / 2, psyn_fx + L_SUBFR / 2, psyn_fx + L_SUBFR / 2 ); } - st_fx->hPFstat->on = 0; + st->hPFstat->on = 0; move16(); } - } + /*----------------------------------------------------------------* * Comfort noise addition *----------------------------------------------------------------*/ test(); test(); - IF( ( st_fx->hFdCngDec != NULL || EQ_16( st_fx->idchan, 1 ) ) && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) + IF( ( st->hFdCngDec != NULL || EQ_16( st->idchan, 1 ) ) && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { test(); test(); test(); test(); test(); - IF( EQ_16( st_fx->element_mode, IVAS_CPE_TD ) || st_fx->flag_cna || ( EQ_16( st_fx->cng_type, FD_CNG ) && LE_32( st_fx->total_brate, ACELP_32k ) ) || ( ( st_fx->cng_type == LP_CNG ) && LE_32( st_fx->total_brate, SID_2k40 ) ) ) + IF( EQ_16( st->element_mode, IVAS_CPE_TD ) || st->flag_cna || ( EQ_16( st->cng_type, FD_CNG ) && LE_32( st->total_brate, ACELP_32k ) ) || ( st->cng_type == LP_CNG && LE_32( st->core_brate, SID_2k40 ) ) ) { /*VAD only for non inactive frame*/ test(); - st_fx->VAD = st_fx->VAD && ( st_fx->coder_type != INACTIVE ); + st->VAD = st->VAD && st->coder_type != INACTIVE; move16(); test(); test(); test(); test(); test(); - IF( st_fx->idchan == 0 && ( st_fx->flag_cna || ( EQ_16( st_fx->cng_type, FD_CNG ) && LE_32( st_fx->total_brate, ACELP_32k ) ) || - ( EQ_16( st_fx->cng_type, LP_CNG ) && LE_32( st_fx->total_brate, SID_2k40 ) ) ) ) + IF( st->idchan == 0 && ( st->flag_cna || ( EQ_16( st->cng_type, FD_CNG ) && LE_32( st->total_brate, ACELP_32k ) ) || ( st->cng_type == LP_CNG && LE_32( st->core_brate, SID_2k40 ) ) ) ) { /*Noisy speech detector*/ - noisy_speech_detection_fx( st_fx->hFdCngDec, st_fx->VAD, syn_fx, st_fx->Q_syn ); + noisy_speech_detection_fx( st->hFdCngDec, st->VAD, psyn_fx, st->Q_syn ); - st_fx->hFdCngDec->hFdCngCom->likelihood_noisy_speech = mult_r( st_fx->hFdCngDec->hFdCngCom->likelihood_noisy_speech, 32440 /*0.99 Q15*/ ); + st->hFdCngDec->hFdCngCom->likelihood_noisy_speech = mult_r( st->hFdCngDec->hFdCngCom->likelihood_noisy_speech, 32440 /*0.99 Q15*/ ); move16(); - IF( st_fx->hFdCngDec->hFdCngCom->flag_noisy_speech != 0 ) + IF( st->hFdCngDec->hFdCngCom->flag_noisy_speech != 0 ) { - st_fx->hFdCngDec->hFdCngCom->likelihood_noisy_speech = add( st_fx->hFdCngDec->hFdCngCom->likelihood_noisy_speech, 328 /*0.01 Q15*/ ); + st->hFdCngDec->hFdCngCom->likelihood_noisy_speech = add( st->hFdCngDec->hFdCngCom->likelihood_noisy_speech, 328 /*0.01 Q15*/ ); move16(); } + move32(); } - if ( st_fx->idchan == 0 ) + + if ( st->idchan == 0 ) { - st_fx->lp_noise = st_fx->hFdCngDec->lp_noise; + st->lp_noise = st->hFdCngDec->lp_noise; move32(); } - /*Noise estimate*/ - IF( NE_16( st_fx->element_mode, IVAS_CPE_TD ) /* && !st->cng_ism_flag IVAS_CODE */ ) + + test(); + IF( NE_16( st->element_mode, IVAS_CPE_TD ) && !st->cng_ism_flag ) { - ApplyFdCng_fx( syn_fx, st_fx->Q_syn, realBuffer, imagBuffer, NULL, st_fx, 0, ( EQ_16( st_fx->coder_type, AUDIO ) && st_fx->GSC_noisy_speech == 0 ) ); - } - /* CNA: Generate additional comfort noise to mask potential coding artefacts */ + /* Noise estimate */ + ApplyFdCng_fx( psyn_fx, st->Q_syn, NULL, 0, realBuffer_fx, imagBuffer_fx, NULL, st, 0, ( st->coder_type == AUDIO && !st->GSC_noisy_speech ) ); } + IF( !st->cna_dirac_flag ) + { + test(); + test(); test(); test(); test(); test(); - IF( st_fx->flag_cna && NE_16( st_fx->coder_type, AUDIO ) ) + test(); + test(); + test(); + /* CNA: Generate additional comfort noise to mask potential coding artefacts */ + IF( st->flag_cna && !( EQ_16( st->coder_type, AUDIO ) && !( st->element_mode > EVS_MONO && st->GSC_noisy_speech ) ) ) + { + test(); + IF( EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( nchan_out, 2 ) ) + { + IF( hStereoCng->flag_cna_fade ) { - generate_masking_noise_fx( syn_fx, st_fx->Q_syn, st_fx->hFdCngDec->hFdCngCom, st_fx->hFdCngDec->hFdCngCom->frameSize, 0 ); + generate_stereo_masking_noise_fx( psyn_fx, st->Q_syn, st, hStereoTD, flag_sec_CNA, 1, hStereoCng, nchan_out ); + hStereoCng->flag_cna_fade = 0; + move16(); } - ELSE IF( st_fx->flag_cna && EQ_16( st_fx->coder_type, AUDIO ) && st_fx->last_core == ACELP_CORE && NE_16( st_fx->last_coder_type, AUDIO ) ) + ELSE + { + test(); + IF( NE_16( st->element_mode, last_element_mode ) && ( st->idchan == 0 ) ) { - FOR( i = 0; i < st_fx->hFdCngDec->hFdCngCom->frameSize / 2; i++ ) + /* Clear memory for secondary channel CNA */ + set16_fx( hStereoCng->olapBufferSynth22_fx, 0, shr( st->hFdCngDec->hFdCngCom->frameSize, 1 ) ); + } + + generate_stereo_masking_noise_fx( psyn_fx, st->Q_syn, st, hStereoTD, flag_sec_CNA, 0, hStereoCng, nchan_out ); + } + } + ELSE IF( NE_16( st->element_mode, IVAS_CPE_DFT ) ) { - syn_fx[i] = add( syn_fx[i], shr_r( mult_r( st_fx->hFdCngDec->hFdCngCom->olapBufferSynth2[i + 5 * st_fx->hFdCngDec->hFdCngCom->frameSize / 4], st_fx->hFdCngDec->hFdCngCom->fftlenFac ), -st_fx->Q_syn ) ); + IF( EQ_16( st->element_mode, EVS_MONO ) ) + { + generate_masking_noise_fx( psyn_fx, st->Q_syn, st->hFdCngDec->hFdCngCom, st->hFdCngDec->hFdCngCom->frameSize, 0 ); + } + ELSE + { + IF( st->idchan == 0 ) + { + IF( NE_16( st->element_mode, last_element_mode ) ) + { + set16_fx( st->hFdCngDec->hFdCngCom->olapBufferSynth2, 0, st->hFdCngDec->hFdCngCom->fftlen ); + } + + Word32 psyn_32_fx[L_FRAME16k]; + Copy_Scale_sig_16_32_no_sat( psyn_fx, psyn_32_fx, st->hFdCngDec->hFdCngCom->frameSize, sub( Q6, st->Q_syn ) ); // Q6 + Copy_Scale_sig_16_32_no_sat( st->hFdCngDec->hFdCngCom->olapBufferSynth2, st->hFdCngDec->hFdCngCom->olapBufferSynth2_fx, shl( st->hFdCngDec->hFdCngCom->frameSize, 1 ), Q15 ); // Q15 + + generate_masking_noise_ivas_fx( psyn_32_fx, &exp, st->hFdCngDec->hFdCngCom, st->hFdCngDec->hFdCngCom->frameSize, 0, 0, 0, st->element_mode, hStereoCng, nchan_out ); + + Copy_Scale_sig_32_16( psyn_32_fx, psyn_fx, st->hFdCngDec->hFdCngCom->frameSize, sub( st->Q_syn, exp ) ); // Q = st->Q_syn + Copy_Scale_sig_32_16( st->hFdCngDec->hFdCngCom->olapBufferSynth2_fx, st->hFdCngDec->hFdCngCom->olapBufferSynth2, shl( st->hFdCngDec->hFdCngCom->frameSize, 1 ), -Q15 ); // Q0 + } + } + } + } + ELSE IF( st->flag_cna && EQ_16( st->coder_type, AUDIO ) && ( ( st->last_core == ACELP_CORE && !( EQ_16( st->last_coder_type, AUDIO ) && !( st->element_mode > EVS_MONO && st->Last_GSC_noisy_speech_flag ) ) ) || EQ_16( st->last_core, TCX_20_CORE ) ) ) + { + test(); + IF( EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( nchan_out, 2 ) ) + { + generate_stereo_masking_noise_fx( psyn_fx, st->Q_syn, st, hStereoTD, flag_sec_CNA, 1, hStereoCng, nchan_out ); + hStereoCng->flag_cna_fade = 1; + move16(); + } + ELSE + { + FOR( i = 0; i < ( st->hFdCngDec->hFdCngCom->frameSize ) / 2; i++ ) + { + psyn_fx[i] = add( psyn_fx[i], shr_r( mult_r( st->hFdCngDec->hFdCngCom->olapBufferSynth2[i + 5 * ( st->hFdCngDec->hFdCngCom->frameSize / 4 )], st->hFdCngDec->hFdCngCom->fftlenFac ), negate( st->Q_syn ) ) ); + move16(); + } + } + } + ELSE + { + IF( hStereoCng != NULL ) + { + hStereoCng->flag_cna_fade = 1; + move16(); + hStereoCng->enableSecCNA = 0; move16(); } } + IF( EQ_16( st->element_mode, IVAS_CPE_TD ) ) + { + test(); + test(); + test(); + /*Noise estimate*/ + IF( ( st->idchan == 0 ) && ( EQ_16( nchan_out, 2 ) || ( st->core_brate != FRAME_NO_DATA && NE_32( st->core_brate, SID_2k40 ) ) ) ) + { + ApplyFdCng_fx( psyn_fx, st->Q_syn, NULL, 0, realBuffer_fx, imagBuffer_fx, NULL, st, 0, ( st->coder_type == AUDIO && !st->GSC_noisy_speech ) ); + } + } + } + } + + IF( !st->cna_dirac_flag ) + { + test(); test(); test(); test(); test(); test(); - IF( st_fx->flag_cna == 0 && EQ_16( st_fx->L_frame, L_FRAME16k ) && EQ_16( st_fx->last_flag_cna, 1 ) && ( ( st_fx->last_core == ACELP_CORE && NE_16( st_fx->last_coder_type, AUDIO ) ) || EQ_16( st_fx->last_core, AMR_WB_CORE ) ) ) + test(); + IF( ( st->flag_cna == 0 ) && EQ_16( st->L_frame, L_FRAME16k ) && EQ_16( st->last_flag_cna, 1 ) && ( ( st->last_core == ACELP_CORE && !( EQ_16( st->last_coder_type, AUDIO ) && !( st->element_mode > EVS_MONO && st->Last_GSC_noisy_speech_flag ) ) ) || EQ_16( st->last_core, AMR_WB_CORE ) ) ) + { + IF( EQ_16( st->element_mode, EVS_MONO ) ) + { + // VE: TBV - is it correct in EVS? in FLP, it is: + // v_multc( st->hFdCngDec->hFdCngCom->olapBufferSynth2 + 5 * st->L_frame / 4, 256.f, temp_buf, st->L_frame / 2 ); + // v_add( temp_buf, syn, syn, st->L_frame / 2 ); + FOR( i = 0; i < st->L_frame / 2; i++ ) + { + psyn_fx[i] = add( psyn_fx[i], shr_r( st->hFdCngDec->hFdCngCom->olapBufferSynth2[i + 5 * st->L_frame / 4], negate( st->Q_syn ) ) ); + move16(); + } + } + ELSE { - FOR( i = 0; i < st_fx->L_frame / 2; i++ ) + FOR( i = 0; i < ( st->hFdCngDec->hFdCngCom->frameSize ) / 2; i++ ) { - syn_fx[i] = add( syn_fx[i], shr_r( st_fx->hFdCngDec->hFdCngCom->olapBufferSynth2[i + 5 * st_fx->L_frame / 4], negate( st_fx->Q_syn ) ) ); + psyn_fx[i] = add( psyn_fx[i], shr_r( mult_r( st->hFdCngDec->hFdCngCom->olapBufferSynth2[i + 5 * ( st->hFdCngDec->hFdCngCom->frameSize / 4 )], st->hFdCngDec->hFdCngCom->fftlenFac ), -st->Q_syn ) ); move16(); } } + } test(); - IF( st_fx->flag_cna == 0 || EQ_16( st_fx->coder_type, AUDIO ) ) + test(); + test(); + IF( ( st->flag_cna == 0 ) || ( EQ_16( st->coder_type, AUDIO ) && !( st->element_mode > EVS_MONO && st->GSC_noisy_speech ) ) ) + { + IF( st->idchan == 0 ) + { + set16_fx( st->hFdCngDec->hFdCngCom->olapBufferSynth2, 0, st->hFdCngDec->hFdCngCom->fftlen ); + } + IF( hStereoCng != NULL && ( st->idchan == 0 ) ) { - set16_fx( st_fx->hFdCngDec->hFdCngCom->olapBufferSynth2, 0, st_fx->hFdCngDec->hFdCngCom->fftlen ); + set16_fx( hStereoCng->olapBufferSynth22_fx, 0, st->hFdCngDec->hFdCngCom->fftlen ); + } + } } } @@ -1335,45 +1758,44 @@ ivas_error acelp_core_dec_fx( * Bass post-filter *----------------------------------------------------------------*/ + IF( EQ_16( st->element_mode, EVS_MONO ) ) + { + CLDFB_SCALE_FACTOR scaleFactor; + Word32 workBuffer[128 * 3]; + /* check if the CLDFB works on the right sample rate */ - IF( ( st_fx->cldfbAna->usb * st_fx->cldfbAna->no_col ) != st_fx->L_frame ) + IF( ( st->cldfbAna->usb * st->cldfbAna->no_col ) != st->L_frame ) { /* resample to ACELP internal sampling rate */ - Word16 newCldfbBands = CLDFB_getNumChannels( L_mult0( st_fx->L_frame, FRAMES_PER_SEC ) ); - resampleCldfb( st_fx->cldfbAna, newCldfbBands, st_fx->L_frame, 0 ); - resampleCldfb( st_fx->cldfbBPF, newCldfbBands, st_fx->L_frame, 0 ); + Word16 newCldfbBands = CLDFB_getNumChannels( L_mult0( st->L_frame, FRAMES_PER_SEC ) ); + resampleCldfb( st->cldfbAna, newCldfbBands, st->L_frame, 0 ); + resampleCldfb( st->cldfbBPF, newCldfbBands, st->L_frame, 0 ); - IF( st_fx->ini_frame > 0 ) + IF( st->ini_frame > 0 ) { - st_fx->cldfbSyn->bandsToZero = sub( st_fx->cldfbSyn->no_channels, st_fx->cldfbAna->no_channels ); + st->cldfbSyn->bandsToZero = sub( st->cldfbSyn->no_channels, st->cldfbAna->no_channels ); move16(); } } test(); - IF( !( EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) && st_fx->bpf_off ) ) + IF( NE_16( st->L_frame, st->last_L_frame ) && NE_16( st->last_codec_mode, MODE2 ) ) { - test(); - IF( NE_16( st_fx->L_frame, st_fx->last_L_frame ) && NE_16( st_fx->last_codec_mode, MODE2 ) ) + IF( EQ_16( st->L_frame, L_FRAME ) ) { - IF( EQ_16( st_fx->L_frame, L_FRAME ) ) - { - retro_interp5_4_fx( hBPF->pst_old_syn_fx ); + retro_interp5_4_fx( st->hBPF->pst_old_syn_fx ); } - ELSE IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) + ELSE IF( EQ_16( st->L_frame, L_FRAME16k ) ) { - retro_interp4_5_fx( syn_fx, hBPF->pst_old_syn_fx ); + retro_interp4_5_fx( psyn_fx, st->hBPF->pst_old_syn_fx ); } } - bass_psfilter_fx( st_fx->hBPF, st_fx->Opt_AMR_WB, syn_fx, st_fx->L_frame, pitch_buf_fx, st_fx->bpf_off, - st_fx->stab_fac_fx, &st_fx->stab_fac_smooth_fx, st_fx->coder_type, st_fx->Q_syn, bpf_error_signal ); - } - test(); - IF( NE_16( st_fx->element_mode, IVAS_CPE_DFT ) || use_cldfb_for_dft ) - { + bass_psfilter_fx( st->hBPF, st->Opt_AMR_WB, psyn_fx, st->L_frame, pitch_buf_fx, st->bpf_off, + st->stab_fac_fx, &st->stab_fac_smooth_fx, st->coder_type, st->Q_syn, bpf_error_signal_16fx ); + /* analysis of the synthesis at internal sampling rate */ - cldfbAnalysis_fx( st_fx->cldfbAna, realBuffer, imagBuffer, &scaleFactor, syn_fx, negate( st_fx->Q_syn ), CLDFB_NO_COL_MAX, workBuffer ); + cldfbAnalysis_fx( st->cldfbAna, realBuffer_fx, imagBuffer_fx, &scaleFactor, psyn_fx, negate( st->Q_syn ), CLDFB_NO_COL_MAX, workBuffer ); scaleFactor.hb_scale = scaleFactor.lb_scale; move16(); @@ -1381,25 +1803,26 @@ ivas_error acelp_core_dec_fx( /* analysis and add the BPF error signal */ i = 0; move16(); - if ( st_fx->bpf_off == 0 ) + if ( st->bpf_off == 0 ) { i = CLDFB_NO_COL_MAX; move16(); } - addBassPostFilter_fx( bpf_error_signal, realBuffer, imagBuffer, st_fx->cldfbBPF, workBuffer, negate( st_fx->Q_syn ), - i, st_fx->cldfbAna->no_col, st_fx->cldfbAna->no_channels, &scaleFactor ); + + addBassPostFilter_fx( bpf_error_signal_16fx, realBuffer_fx, imagBuffer_fx, st->cldfbBPF, workBuffer, negate( st->Q_syn ), + i, st->cldfbAna->no_col, st->cldfbAna->no_channels, &scaleFactor ); /* set output mask for upsampling */ - IF( EQ_16( st_fx->bwidth, NB ) ) + IF( EQ_16( st->bwidth, NB ) ) { /* set NB mask for upsampling */ - st_fx->cldfbSyn->bandsToZero = sub( st_fx->cldfbSyn->no_channels, 10 ); + st->cldfbSyn->bandsToZero = sub( st->cldfbSyn->no_channels, 10 ); move16(); } - ELSE IF( NE_16( st_fx->cldfbSyn->bandsToZero, sub( st_fx->cldfbSyn->no_channels, st_fx->cldfbAna->no_channels ) ) ) + ELSE IF( NE_16( st->cldfbSyn->bandsToZero, sub( st->cldfbSyn->no_channels, st->cldfbAna->no_channels ) ) ) { /* in case of BW switching, re-init to default */ - st_fx->cldfbSyn->bandsToZero = sub( st_fx->cldfbSyn->no_channels, st_fx->cldfbAna->no_channels ); + st->cldfbSyn->bandsToZero = sub( st->cldfbSyn->no_channels, st->cldfbAna->no_channels ); move16(); } @@ -1407,47 +1830,447 @@ ivas_error acelp_core_dec_fx( scaleFactor.hb_scale = scaleFactor.lb_scale; move16(); + test(); + test(); + test(); + IF( ( ( st->core_brate == FRAME_NO_DATA ) || EQ_32( st->core_brate, SID_2k40 ) ) && ( EQ_16( st->cng_type, FD_CNG ) ) && ( LT_16( st->hFdCngDec->hFdCngCom->numCoreBands, st->cldfbSyn->no_channels ) ) ) + { + generate_comfort_noise_dec_hf_fx( realBuffer_fx, imagBuffer_fx, &scaleFactor.hb_scale, st ); + + st->cldfbSyn->bandsToZero = 0; + move16(); + IF( LT_16( st->hFdCngDec->hFdCngCom->regularStopBand, st->cldfbSyn->no_channels ) ) + { + st->cldfbSyn->bandsToZero = sub( st->cldfbSyn->no_channels, st->hFdCngDec->hFdCngCom->regularStopBand ); + move16(); + } + st->cldfbSyn->lsb = st->cldfbAna->no_channels; + move16(); + } + + /* synthesis of the combined signal */ + st->Q_syn2 = st->Q_syn; + move16(); + cldfbSynthesis_fx( st->cldfbSyn, realBuffer_fx, imagBuffer_fx, &scaleFactor, synth_fx16, negate( st->Q_syn2 ), CLDFB_NO_COL_MAX, workBuffer ); + + /* Bring CLDFB output to Q0 */ + Scale_sig( synth_fx16, output_frame, negate( st->Q_syn2 ) ); + st->Q_syn2 = 0; + move16(); + + /* save synthesis - needed in case of core switching */ + Copy( synth_fx16, st->previoussynth_fx, output_frame ); + } + ELSE + { + /* check if the CLDFB works on the right sample rate */ + IF( NE_16( imult1616( st->cldfbAna->no_channels, st->cldfbAna->no_col ), st->L_frame ) ) + { + resampleCldfb_ivas_fx( st->cldfbAna, L_mult0( st->L_frame, FRAMES_PER_SEC ) ); + resampleCldfb_ivas_fx( st->cldfbBPF, L_mult0( st->L_frame, FRAMES_PER_SEC ) ); + + IF( st->ini_frame > 0 ) + { + st->cldfbSyn->bandsToZero = sub( st->cldfbSyn->no_channels, st->cldfbAna->no_channels ); + move16(); + } + } + + /* analyze pitch coherence for bass post-filter */ + Word32 pitch_buf_fx_q20[12]; + Scale_sig32( st->old_pitch_buf_fx, 2 * NB_SUBFR16k + 2, Q4 ); // Q(x+4) + Word16 lim = shr( st->L_frame, 6 ); + FOR( Word16 lp = 0; lp < lim; lp++ ) + { + pitch_buf_fx_q20[lp] = L_shl( pitch_buf_fx[lp], Q14 ); + move32(); + } + bpf_pitch_coherence_ivas_fx( st, pitch_buf_fx_q20 ); + Scale_sig32( st->old_pitch_buf_fx, 2 * NB_SUBFR16k + 2, -Q4 ); // Qx + + test(); + IF( !( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && st->bpf_off ) ) + { + test(); + IF( NE_16( st->L_frame, st->last_L_frame ) && NE_16( st->last_codec_mode, MODE2 ) ) + { + IF( EQ_16( st->L_frame, L_FRAME ) ) + { + retro_interp5_4_fx( st->hBPF->pst_old_syn_fx ); + } + ELSE IF( EQ_16( st->L_frame, L_FRAME16k ) ) + { + retro_interp4_5_fx( psyn_fx, st->hBPF->pst_old_syn_fx ); + } + } + + bass_psfilter_fx( st->hBPF, st->Opt_AMR_WB, psyn_fx, st->L_frame, pitch_buf_fx, st->bpf_off, + st->stab_fac_fx, &st->stab_fac_smooth_fx, st->coder_type, st->Q_syn, bpf_error_signal_16fx ); + } + + Word32 syn_tmp_32_fx[L_FRAME16k + L_SUBFR], *syn_32_fx; + set32_fx( syn_tmp_32_fx, 0, L_FRAME16k + L_SUBFR ); + syn_32_fx = syn_tmp_32_fx + L_SUBFR; + test(); + IF( NE_16( st->element_mode, IVAS_CPE_DFT ) || use_cldfb_for_dft ) + { + /* analysis of the synthesis at internal sampling rate */ + Word32 realBufferSave_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; + Word32 imagBufferSave_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; + Word32 *pRealSave_fx[CLDFB_NO_COL_MAX], *pImagSave_fx[CLDFB_NO_COL_MAX]; + FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) + { + pRealSave_fx[i] = realBufferSave_fx[i]; + pImagSave_fx[i] = imagBufferSave_fx[i]; + } + IF( st->p_bpf_noise_buf_32 ) + { + Copy_Scale_sig_16_32_DEPREC( bpf_error_signal_16fx, bpf_error_signal_fx, st->L_frame, -1 ); // Q_syn-1 + Copy32( bpf_error_signal_fx, st->p_bpf_noise_buf_32, st->L_frame ); + Scale_sig32( st->p_bpf_noise_buf_32, st->L_frame, sub( Q11, sub( st->Q_syn, 1 ) ) ); // Q11 + } + + FOR( i = 0; i < st->L_frame; i++ ) + { + syn_32_fx[i] = L_shr( L_deposit_h( psyn_fx[i] ), add( 4, st->Q_syn ) ); // Q12 + move32(); + } + + Word16 offset = sub( st->cldfbAna->p_filter_length, st->cldfbAna->no_channels ); + Scale_sig32( st->cldfbAna->cldfb_state_fx, offset, 1 ); // Q12 + st->cldfbAna->Q_cldfb_state = Q12; + move16(); + + cldfbAnalysis_ivas_fx( syn_32_fx, realBuffer_fx, imagBuffer_fx, -1, st->cldfbAna ); + + Scale_sig32( st->cldfbAna->cldfb_state_fx, offset, -1 ); // Q11 + st->cldfbAna->Q_cldfb_state = Q11; + move16(); + /* analysis and add the BPF error signal */ + Word32 tmp_bpf_error_signal_fx[L_FRAME16k]; + Word16 q_bpf_error_signal; + Word16 cldfb_state_offset = sub( st->cldfbBPF->p_filter_length, st->cldfbBPF->no_channels ); + + q_bpf_error_signal = Q6; + move16(); + Copy_Scale_sig_16_32_no_sat( bpf_error_signal_16fx, tmp_bpf_error_signal_fx, st->L_frame, sub( q_bpf_error_signal, st->Q_syn ) ); // Q6 + FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) + { + Scale_sig32( realBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, -Q7 ); // Q0 + Scale_sig32( imagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, -Q7 ); // Q0 + } + Scale_sig32( st->cldfbBPF->cldfb_state_fx, cldfb_state_offset, sub( q_bpf_error_signal, Q10 ) ); // q_bpf_error_signal (Q6) + st->cldfbBPF->Q_cldfb_state = q_bpf_error_signal; + move16(); + tmp = -1; + move16(); + if ( st->bpf_off ) + { + tmp = 0; + move16(); + } + + addBassPostFilter_ivas_fx( tmp_bpf_error_signal_fx, tmp, realBuffer_fx, imagBuffer_fx, st->cldfbBPF ); + Scale_sig32( st->cldfbBPF->cldfb_state_fx, cldfb_state_offset, negate( ( sub( q_bpf_error_signal, Q10 ) ) ) ); // Q10 + st->cldfbBPF->Q_cldfb_state = Q10; + move16(); + /* set output mask for upsampling */ + IF( EQ_16( st->bwidth, NB ) ) + { + /* set NB mask for upsampling */ + st->cldfbSyn->bandsToZero = sub( st->cldfbSyn->no_channels, 10 ); + move16(); + } + ELSE IF( NE_16( st->cldfbSyn->bandsToZero, sub( st->cldfbSyn->no_channels, st->cldfbAna->no_channels ) ) ) + { + /* in case of BW switching, re-init to default */ + st->cldfbSyn->bandsToZero = sub( st->cldfbSyn->no_channels, st->cldfbAna->no_channels ); + move16(); + } test(); - IF( !st_fx->cng_sba_flag || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) + IF( !st->cng_sba_flag || EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) { test(); test(); test(); - IF( ( ( st_fx->core_brate == FRAME_NO_DATA ) || EQ_32( st_fx->core_brate, SID_2k40 ) ) && ( EQ_16( st_fx->cng_type, FD_CNG ) ) && ( LT_16( st_fx->hFdCngDec->hFdCngCom->numCoreBands, st_fx->cldfbSyn->no_channels ) ) ) + /*WB/SWB-FD_CNG*/ + IF( ( st->core_brate == FRAME_NO_DATA || EQ_32( st->core_brate, SID_2k40 ) ) && ( EQ_16( st->cng_type, FD_CNG ) ) && ( LT_16( st->hFdCngDec->hFdCngCom->numCoreBands, st->cldfbSyn->no_channels ) ) ) + { + Word16 tmpBufferScale = 0; + move16(); + generate_comfort_noise_dec_hf_ivas_fx( realBuffer_fx, imagBuffer_fx, /*realBuffer, imagBuffer,*/ &tmpBufferScale, st->hFdCngDec->hFdCngCom, st->cng_ism_flag ); + + FOR( i = 0; i < st->hFdCngDec->hFdCngCom->numSlots; i++ ) { - generate_comfort_noise_dec_hf_fx( realBuffer, imagBuffer, &scaleFactor.hb_scale, st_fx ); + Scale_sig32( realBuffer_fx[i] + st->hFdCngDec->hFdCngCom->numCoreBands, sub( st->hFdCngDec->hFdCngCom->regularStopBand, st->hFdCngDec->hFdCngCom->numCoreBands ), sub( add( tmpBufferScale, 15 ), Q31 ) ); // Q0 + Scale_sig32( imagBuffer_fx[i] + st->hFdCngDec->hFdCngCom->numCoreBands, sub( st->hFdCngDec->hFdCngCom->regularStopBand, st->hFdCngDec->hFdCngCom->numCoreBands ), sub( add( tmpBufferScale, 15 ), Q31 ) ); // Q0 + } - st_fx->cldfbSyn->bandsToZero = 0; + IF( LT_16( st->hFdCngDec->hFdCngCom->regularStopBand, st->cldfbSyn->no_channels ) ) + { + st->cldfbSyn->bandsToZero = sub( st->cldfbSyn->no_channels, st->hFdCngDec->hFdCngCom->regularStopBand ); move16(); - IF( LT_16( st_fx->hFdCngDec->hFdCngCom->regularStopBand, st_fx->cldfbSyn->no_channels ) ) + } + ELSE { - st_fx->cldfbSyn->bandsToZero = sub( st_fx->cldfbSyn->no_channels, st_fx->hFdCngDec->hFdCngCom->regularStopBand ); + st->cldfbSyn->bandsToZero = 0; move16(); } - st_fx->cldfbSyn->lsb = st_fx->cldfbAna->no_channels; + } + } + + IF( save_hb_synth_fx16 != NULL ) + { + /* save and then zero-out lowband */ + max_real = 0; + max_imag = 0; + move32(); + move32(); + FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) + { + FOR( j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) + { + max_real = L_max( max_real, L_abs( realBuffer_fx[i][j] ) ); + max_imag = L_max( max_imag, L_abs( imagBuffer_fx[i][j] ) ); + } + } + max_val = L_max( max_real, max_imag ); + Q_real = sub( norm_l( max_val ), 3 ) /* Guard bits */; + FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) + { + scale_sig32( realBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_real ); // Q_real + scale_sig32( imagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_real ); // Q_real + } +#ifndef OPT_AVOID_STATE_BUF_RESCALE +#ifdef OPT_STEREO_32KBPS_V1 + scale_sig32( st->cldfbSynHB->cldfb_state_fx, st->cldfbSynHB->p_filter_length, sub( Q_real, Q11 ) ); // Q10 - > (Q_real-1) +#else /* OPT_STEREO_32KBPS_V1 */ + scale_sig32_r( st->cldfbSynHB->cldfb_state_fx, st->cldfbSynHB->p_filter_length, sub( sub( Q_real, 1 ), Q10 ) ); // (Q_real-1) +#endif /* OPT_STEREO_32KBPS_V1 */ + st->cldfbSynHB->Q_cldfb_state = sub( Q_real, 1 ); move16(); +#endif /* OPT_AVOID_STATE_BUF_RESCALE */ + + FOR( j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) + { + FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) + { + realBufferSave_fx[i][j] = realBuffer_fx[i][j]; + imagBufferSave_fx[i][j] = imagBuffer_fx[i][j]; + move32(); + move32(); + IF( LT_16( j, st->hFdCngDec->hFdCngCom->numCoreBands ) && LT_16( i, st->hFdCngDec->hFdCngCom->numSlots ) ) + { + realBuffer_fx[i][j] = 0; + imagBuffer_fx[i][j] = 0; + move32(); + move32(); + } + } + } + +#ifdef OPT_AVOID_STATE_BUF_RESCALE + cldfbSynthesis_ivas_fx( realBuffer_fx, imagBuffer_fx, save_hb_synth_fx, -1, sub( Q11, Q_real ), -10, st->cldfbSynHB ); +#else /* OPT_AVOID_STATE_BUF_RESCALE */ + cldfbSynthesis_ivas_fx( realBuffer_fx, imagBuffer_fx, save_hb_synth_fx, -1, 0, st->cldfbSynHB ); +#endif /* OPT_AVOID_STATE_BUF_RESCALE */ + +#ifndef OPT_AVOID_STATE_BUF_RESCALE + Scale_sig32( save_hb_synth_fx, L_FRAME48k, negate( ( sub( Q_real, 1 ) ) ) ); // Q0 + Scale_sig32( st->cldfbSynHB->cldfb_state_fx, st->cldfbSynHB->p_filter_length, sub( Q10, sub( Q_real, 1 ) ) ); // Q10 + st->cldfbSynHB->Q_cldfb_state = Q10; + move16(); +#endif /* OPT_AVOID_STATE_BUF_RESCALE */ + /* restore lowband */ + FOR( j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) + { + FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) + { + realBuffer_fx[i][j] = realBufferSave_fx[i][j]; + imagBuffer_fx[i][j] = imagBufferSave_fx[i][j]; + move32(); + move32(); } } +#ifndef OPT_AVOID_STATE_BUF_RESCALE + Scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( sub( Q_real, 1 ), Q10 ) ); // Q_real-1 + st->cldfbSynHB->Q_cldfb_state = sub( Q_real, 1 ); + move16(); +#endif /* OPT_AVOID_STATE_BUF_RESCALE */ + +#ifdef OPT_AVOID_STATE_BUF_RESCALE + cldfbSynthesis_ivas_fx( pRealSave_fx, pImagSave_fx, synth_fx, -1, sub( Q11, Q_real ), -10, st->cldfbSyn ); +#else /* OPT_AVOID_STATE_BUF_RESCALE */ + cldfbSynthesis_ivas_fx( pRealSave_fx, pImagSave_fx, synth_fx, -1, 0, st->cldfbSyn ); + Scale_sig32( synth_fx, L_FRAME48k, negate( sub( Q_real, 1 ) ) ); // Q0 + Scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( Q10, sub( Q_real, 1 ) ) ); // Q10 + st->cldfbSynHB->Q_cldfb_state = Q10; + move16(); +#endif /* OPT_AVOID_STATE_BUF_RESCALE */ + } + ELSE + { /* synthesis of the combined signal */ - st_fx->Q_syn2 = st_fx->Q_syn; + max_real = 0; + max_imag = 0; + move32(); + move32(); + FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) + { + FOR( j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) + { + max_real = L_max( max_real, L_abs( realBuffer_fx[i][j] ) ); + max_imag = L_max( max_imag, L_abs( imagBuffer_fx[i][j] ) ); + } + } + max_val = L_max( max_real, max_imag ); + Q_real = sub( norm_l( max_val ), 3 ) /* Guard bits */; + FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) + { + scale_sig32( realBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_real ); // Q_real + scale_sig32( imagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_real ); // Q_real + } +#ifdef OPT_STEREO_32KBPS_V1 + scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( Q_real, Q11 ) ); // Q10 - > (Q_real-1) +#else /* OPT_STEREO_32KBPS_V1 */ + scale_sig32_r( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( sub( Q_real, 1 ), Q10 ) ); //(Q_real - 1) +#endif /* OPT_STEREO_32KBPS_V1 */ + st->cldfbSyn->Q_cldfb_state = sub( Q_real, 1 ); + move16(); + +#ifdef OPT_AVOID_STATE_BUF_RESCALE + cldfbSynthesis_ivas_fx( realBuffer_fx, imagBuffer_fx, synth_fx, -1, 0, 0, st->cldfbSyn ); +#else /* OPT_AVOID_STATE_BUF_RESCALE */ + cldfbSynthesis_ivas_fx( realBuffer_fx, imagBuffer_fx, synth_fx, -1, 0, st->cldfbSyn ); +#endif /* OPT_AVOID_STATE_BUF_RESCALE */ + scale_sig32( synth_fx, output_frame, negate( sub( Q_real, 1 ) ) ); // Q0 + scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( Q10, sub( Q_real, 1 ) ) ); // Q10 + st->cldfbSyn->Q_cldfb_state = Q10; move16(); + } + + /* save synthesis - needed in case of core switching */ + Copy32( synth_fx, st->previoussynth_fx_32, output_frame ); // Q0 + } + ELSE { - cldfbSynthesis_fx( st_fx->cldfbSyn, realBuffer, imagBuffer, &scaleFactor, synth_out, negate( st_fx->Q_syn2 ), CLDFB_NO_COL_MAX, workBuffer ); + Word16 nSamples = NS2SA_FX2( i_mult( st->L_frame, FRAMES_PER_SEC ), FRAME_SIZE_NS /*DELAY_CLDFB_NS*/ ); /* IVAS-64: optimization is likely possible here (don't resample the whole frame) */ + + /* analysis of the synthesis at internal sampling rate - needed for DFT stereo -> TD stereo switching */ + FOR( i = 0; i < st->L_frame; i++ ) + { + syn_32_fx[i] = L_shr( L_deposit_h( psyn_fx[i] ), add( 4, st->Q_syn ) ); + move32(); } - /* Bring CLDFB output to Q0 */ - Scale_sig( synth_out, output_frame, negate( st_fx->Q_syn2 ) ); - st_fx->Q_syn2 = 0; + + Word16 offset = sub( st->cldfbAna->p_filter_length, st->cldfbAna->no_channels ); + Scale_sig32( st->cldfbAna->cldfb_state_fx, offset, 1 ); // Q12 + st->cldfbAna->Q_cldfb_state = Q12; + move16(); + + cldfbAnalysis_ivas_fx( syn_32_fx + sub( st->L_frame, nSamples ), realBuffer_fx, imagBuffer_fx, nSamples, st->cldfbAna ); + + Scale_sig32( st->cldfbAna->cldfb_state_fx, offset, -1 ); // Q11 + st->cldfbAna->Q_cldfb_state = Q11; + move16(); /* analysis and add the BPF error signal - needed for DFT stereo -> TD stereo switching */ + Word32 tmp_bpf_error_signal_fx[L_FRAME16k]; + Word16 q_bpf_error_signal; + Word16 cldfb_state_offset; + cldfb_state_offset = sub( st->cldfbBPF->p_filter_length, st->cldfbBPF->no_channels ); + + // Get Q-factor + q_bpf_error_signal = Q6; + move16(); + Copy_Scale_sig_16_32_no_sat( bpf_error_signal_16fx, tmp_bpf_error_signal_fx, L_FRAME16k, sub( q_bpf_error_signal, st->Q_syn ) ); // Q6 + FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) + { + Scale_sig32( realBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, -Q7 ); // Q0 + Scale_sig32( imagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, -Q7 ); // Q0 + } + Scale_sig32( st->cldfbBPF->cldfb_state_fx, cldfb_state_offset, sub( q_bpf_error_signal, Q10 ) ); // q_bpf_error_signal (Q6) + st->cldfbBPF->Q_cldfb_state = q_bpf_error_signal; + move16(); + tmp = 0; + move16(); + if ( !st->bpf_off ) + { + tmp = nSamples; + move16(); + } + + addBassPostFilter_ivas_fx( tmp_bpf_error_signal_fx + sub( st->L_frame, nSamples ), tmp, realBuffer_fx, imagBuffer_fx, st->cldfbBPF ); + + Scale_sig32( st->cldfbBPF->cldfb_state_fx, cldfb_state_offset, negate( sub( q_bpf_error_signal, Q10 ) ) ); // Q10 + st->cldfbBPF->Q_cldfb_state = Q10; + move16(); + /* synthesis of the combined signal - needed for DFT stereo -> TD stereo switching */ + max_real = 0; + max_imag = 0; + move32(); + move32(); + FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) + { + FOR( j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) + { + max_real = L_max( max_real, L_abs( realBuffer_fx[i][j] ) ); + max_imag = L_max( max_imag, L_abs( imagBuffer_fx[i][j] ) ); + } + } + max_val = L_max( max_real, max_imag ); + Q_real = sub( norm_l( max_val ), 3 ) /* Guard bits */; + FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) + { + scale_sig32( realBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_real ); // Q_real + scale_sig32( imagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_real ); // Q_real + } +#ifndef OPT_AVOID_STATE_BUF_RESCALE +#ifdef OPT_STEREO_32KBPS_V1 + scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( Q_real, Q11 ) ); // Q10 - > (Q_real-1) +#else /* OPT_STEREO_32KBPS_V1 */ + scale_sig32_r( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( sub( Q_real, 1 ), Q10 ) ); //(Q_real - 1) +#endif /* OPT_STEREO_32KBPS_V1 */ +#endif /* OPT_AVOID_STATE_BUF_RESCALE */ + +#ifdef OPT_AVOID_STATE_BUF_RESCALE + cldfbSynthesis_ivas_fx( realBuffer_fx, imagBuffer_fx, synth_fx /*dummy*/, NS2SA_FX2( st->output_Fs, FRAME_SIZE_NS /*DELAY_CLDFB_NS*/ ), sub( Q10, sub( Q_real, 1 ) ), -10, st->cldfbSyn ); +#else /* OPT_AVOID_STATE_BUF_RESCALE */ + cldfbSynthesis_ivas_fx( realBuffer_fx, imagBuffer_fx, synth_fx /*dummy*/, NS2SA_FX2( st->output_Fs, FRAME_SIZE_NS /*DELAY_CLDFB_NS*/ ), 0, st->cldfbSyn ); +#endif /* OPT_AVOID_STATE_BUF_RESCALE */ + +#ifndef OPT_AVOID_STATE_BUF_RESCALE + Scale_sig32( synth_fx, output_frame, negate( sub( Q_real, 1 ) ) ); // Q0 + Scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( Q10, sub( Q_real, 1 ) ) ); // Q10 + st->cldfbSyn->Q_cldfb_state = Q10; move16(); +#endif /* OPT_AVOID_STATE_BUF_RESCALE */ + IF( st->p_bpf_noise_buf_32 ) + { + Copy_Scale_sig_16_32_DEPREC( bpf_error_signal_16fx, bpf_error_signal_fx, st->L_frame, -1 ); // Q_syn-1 + Copy32( bpf_error_signal_fx, st->p_bpf_noise_buf_32, st->L_frame ); - /* save synthesis - needed in case of core switching */ - Copy( synth_out, st_fx->previoussynth_fx, output_frame ); + Scale_sig32( st->p_bpf_noise_buf_32, st->L_frame, sub( Q11, sub( st->Q_syn, 1 ) ) ); // Q11 + } + + set32_fx( synth_fx, 0, output_frame ); + } + + /* Copy output signal */ + Scale_sig( syn_tmp_fx, add( st->L_frame, L_SUBFR ), negate( st->Q_syn ) ); // Q0 + IF( st->element_mode > EVS_MONO ) + { + Copy( psyn_fx, output_fx, st->L_frame ); /*Q_syn*/ + } + + st->Q_syn2 = 0; + move16(); } /*-----------------------------------------------------------------* * Bandwidth extension 6kHz-7kHz *-----------------------------------------------------------------*/ - IF( st_fx->hBWE_zero != NULL ) + + IF( st->hBWE_zero != NULL ) { test(); test(); @@ -1456,14 +2279,27 @@ ivas_error acelp_core_dec_fx( test(); test(); test(); - IF( ( EQ_16( st_fx->L_frame, L_FRAME ) && NE_16( st_fx->bwidth, NB ) && GE_16( output_frame, L_FRAME16k ) && - ( EQ_16( st_fx->extl, -1 ) || EQ_16( st_fx->extl, SWB_CNG ) || ( EQ_16( st_fx->extl, WB_BWE ) && st_fx->extl_brate == 0 && NE_16( st_fx->coder_type, AUDIO ) ) ) ) ) + IF( ( EQ_16( st->L_frame, L_FRAME ) && ( st->bwidth != NB ) && GE_16( output_frame, L_FRAME16k ) && + ( EQ_16( st->extl, -1 ) || EQ_16( st->extl, SWB_CNG ) || ( EQ_16( st->extl, WB_BWE ) && st->extl_brate == 0 && NE_16( st->coder_type, AUDIO ) ) ) ) ) { - hf_synth_fx( st_fx->hBWE_zero, st_fx->core_brate, output_frame, Aq_fx, exc2_fx, syn_fx, synth_out, st_fx->Q_exc, st_fx->Q_syn2 ); + IF( EQ_16( st->element_mode, EVS_MONO ) ) + { + hf_synth_fx( st->hBWE_zero, st->core_brate, output_frame, Aq_fx, exc2_fx, psyn_fx, synth_fx16, st->Q_exc, st->Q_syn2 ); + } + ELSE + { + Copy_Scale_sig_32_16( synth_fx, synth_fx16, output_frame, 0 ); // Q0 + hf_synth_fx( st->hBWE_zero, st->core_brate, output_frame, Aq_fx, exc2_fx, psyn_fx, synth_fx16, st->Q_exc, st->Q_syn2 ); + Copy_Scale_sig_16_32_DEPREC( synth_fx16, synth_fx, output_frame, 0 ); + } } ELSE { - hf_synth_reset_fx( st_fx->hBWE_zero ); + hf_synth_reset_fx( st->hBWE_zero ); + 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 + { + set16_fx( st->hBWE_zero->mem_hp400_fx, 0, 6 ); + } } } @@ -1471,8 +2307,7 @@ ivas_error acelp_core_dec_fx( * Populate parameters for SWB TBE *-----------------------------------------------------------------*/ - /* Apply a non linearity to the SHB excitation */ - IF( hBWE_TD != NULL ) + IF( st->hBWE_TD != NULL ) { test(); test(); @@ -1486,11 +2321,11 @@ ivas_error acelp_core_dec_fx( test(); test(); test(); - IF( ( !st_fx->bfi && ( st_fx->prev_bfi ) ) || ( ( EQ_16( st_fx->last_vbr_hw_BWE_disable_dec, 1 ) ) && ( st_fx->vbr_hw_BWE_disable_dec == 0 ) ) || ( ( EQ_16( st_fx->extl, SWB_TBE ) || EQ_16( st_fx->extl, WB_TBE ) || EQ_16( st_fx->extl, FB_TBE ) ) && NE_16( st_fx->last_extl, SWB_TBE ) && NE_16( st_fx->last_extl, WB_TBE ) && NE_16( st_fx->last_extl, FB_TBE ) ) || ( EQ_16( st_fx->idchan, 1 ) && EQ_16( st_fx->element_mode, IVAS_CPE_TD ) && !st_fx->tdm_LRTD_flag ) ) + IF( ( !st->bfi && st->prev_bfi ) || ( EQ_16( st->last_vbr_hw_BWE_disable_dec, 1 ) && ( st->vbr_hw_BWE_disable_dec == 0 ) ) || ( ( EQ_16( st->extl, SWB_TBE ) || EQ_16( st->extl, WB_TBE ) || EQ_16( st->extl, FB_TBE ) ) && NE_16( st->last_extl, SWB_TBE ) && NE_16( st->last_extl, WB_TBE ) && NE_16( st->last_extl, FB_TBE ) ) || ( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) && !st->tdm_LRTD_flag ) ) { - hBWE_TD->bwe_non_lin_prev_scale_fx = L_deposit_l( 0 ); + st->hBWE_TD->bwe_non_lin_prev_scale_fx = 0; move32(); - set16_fx( hBWE_TD->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET ); + set16_fx( st->hBWE_TD->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET ); } test(); @@ -1498,42 +2333,70 @@ ivas_error acelp_core_dec_fx( test(); test(); test(); - IF( !st_fx->ppp_mode_dec && ( st_fx->idchan == 0 || NE_16( st_fx->element_mode, IVAS_CPE_TD ) || ( EQ_16( st_fx->idchan, 1 ) && EQ_16( st_fx->element_mode, IVAS_CPE_TD ) && st_fx->tdm_LRTD_flag ) ) ) + IF( !st->ppp_mode_dec && ( st->idchan == 0 || NE_16( st->element_mode, IVAS_CPE_TD ) || ( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) && st->tdm_LRTD_flag ) ) ) + { + IF( EQ_16( st->element_mode, EVS_MONO ) ) + { + non_linearity_fx( bwe_exc_fx, bwe_exc_extended_fx, L_FRAME32k, &st->hBWE_TD->bwe_non_lin_prev_scale_fx, st->Q_exc, st->coder_type, voice_factors_fx, st->L_frame ); + } + ELSE { - non_linearity_fx( bwe_exc_fx, bwe_exc_extended, L_FRAME32k, &hBWE_TD->bwe_non_lin_prev_scale_fx, st_fx->Q_exc, - st_fx->coder_type, voice_factors, st_fx->L_frame ); + Copy_Scale_sig_16_32_no_sat( st->hBWE_TD->old_bwe_exc_extended_fx, bwe_exc_extended_fx, NL_BUFF_OFFSET, ( sub( shl( st->Q_exc, 1 ), sub( st->prev_Q_bwe_exc, 16 ) ) ) ); // prev_Q_bwe_exc + non_linearity_ivas_fx( bwe_exc_fx, bwe_exc_extended_fx + NL_BUFF_OFFSET, L_FRAME32k, &st->hBWE_TD->bwe_non_lin_prev_scale_fx, st->Q_exc, st->coder_type, voice_factors_fx, st->L_frame ); + Copy_Scale_sig_32_16( bwe_exc_extended_fx + L_FRAME32k, st->hBWE_TD->old_bwe_exc_extended_fx, NL_BUFF_OFFSET, negate( sub( shl( st->Q_exc, 1 ), sub( st->prev_Q_bwe_exc, 16 ) ) ) ); // prev_Q_bwe_exc + } } test(); - IF( ( st_fx->core_brate == FRAME_NO_DATA ) || EQ_32( st_fx->core_brate, SID_2k40 ) ) + if ( st->core_brate == FRAME_NO_DATA || EQ_32( st->core_brate, SID_2k40 ) ) { - hBWE_TD->bwe_non_lin_prev_scale_fx = L_deposit_l( 0 ); + st->hBWE_TD->bwe_non_lin_prev_scale_fx = 0; move32(); } } + /*----------------------------------------------------------------------* * Updates *----------------------------------------------------------------------*/ - updt_dec_fx( st_fx, old_exc_fx, pitch_buf_fx, Es_pred_fx, Aq_fx, lsf_new_fx, lsp_new_fx, voice_factors, old_bwe_exc_fx, gain_buf ); + updt_dec_fx( st, old_exc_fx, pitch_buf_fx, Es_pred_fx, Aq_fx, lsf_new_fx, lsp_new_fx, voice_factors_fx, old_bwe_exc_fx, gain_buf_fx ); test(); test(); - IF( GT_32( st_fx->core_brate, SID_2k40 ) && st_fx->hTdCngDec != NULL && st_fx->hFdCngDec != NULL ) + IF( GT_32( st->core_brate, SID_2k40 ) && st->hTdCngDec != NULL && st->hFdCngDec != NULL ) { /* update CNG parameters in active frames */ - cng_params_upd_fx( lsp_new_fx, exc_fx, st_fx->L_frame, &st_fx->hTdCngDec->ho_circ_ptr, st_fx->hTdCngDec->ho_ener_circ_fx, &st_fx->hTdCngDec->ho_circ_size, st_fx->hTdCngDec->ho_lsp_circ_fx, - st_fx->Q_exc, DEC, st_fx->hTdCngDec->ho_env_circ_fx, NULL, NULL, NULL, NULL, st_fx->last_active_brate ); + IF( EQ_16( st->element_mode, EVS_MONO ) ) + { + cng_params_upd_fx( lsp_new_fx, exc_fx, st->L_frame, &st->hTdCngDec->ho_circ_ptr, st->hTdCngDec->ho_ener_circ_fx, &st->hTdCngDec->ho_circ_size, st->hTdCngDec->ho_lsp_circ_fx, + st->Q_exc, DEC, st->hTdCngDec->ho_env_circ_fx, NULL, NULL, NULL, NULL, st->last_active_brate ); + } + ELSE + { + cng_params_upd_ivas_fx( lsp_new_fx, exc_fx, st->L_frame, &st->hTdCngDec->ho_circ_ptr, st->hTdCngDec->ho_ener_circ_fx, &st->hTdCngDec->ho_circ_size, + st->hTdCngDec->ho_lsp_circ_fx, st->Q_exc, DEC, st->hTdCngDec->ho_env_circ_fx, NULL, NULL, NULL, NULL, st->last_active_brate, st->element_mode, + st->hFdCngDec->hFdCngCom->CngBandwidth ); + } + /* Set 16k LSP flag for CNG buffer */ - st_fx->hTdCngDec->ho_16k_lsp[st_fx->hTdCngDec->ho_circ_ptr] = 0; + st->hTdCngDec->ho_16k_lsp[st->hTdCngDec->ho_circ_ptr] = 0; move16(); - if ( NE_16( st_fx->L_frame, L_FRAME ) ) + if ( NE_16( st->L_frame, L_FRAME ) ) { - st_fx->hTdCngDec->ho_16k_lsp[st_fx->hTdCngDec->ho_circ_ptr] = 1; + st->hTdCngDec->ho_16k_lsp[st->hTdCngDec->ho_circ_ptr] = 1; move16(); } } - return IVAS_ERR_OK; + IF( NE_16( st->element_mode, EVS_MONO ) ) + { + IF( save_hb_synth_fx16 ) + { + Copy_Scale_sig_32_16( save_hb_synth_fx, save_hb_synth_fx16, L_FRAME48k, 0 ); // Q0 + } + Copy_Scale_sig_32_16( synth_fx, synth_fx16, output_frame, 0 ); // Q_syn2 + } + + pop_wmops(); + return error; } -#endif diff --git a/lib_dec/acelp_core_dec_ivas_fx.c b/lib_dec/acelp_core_dec_ivas_fx.c index ad8ca9b50..2c72bba78 100644 --- a/lib_dec/acelp_core_dec_ivas_fx.c +++ b/lib_dec/acelp_core_dec_ivas_fx.c @@ -47,12 +47,12 @@ /*-------------------------------------------------------------------* - * acelp_core_dec_ivas_fx() + * acelp_core_dec_fx() * * ACELP core decoder *-------------------------------------------------------------------*/ -ivas_error acelp_core_dec_ivas_fx( +ivas_error acelp_core_dec_fx( Decoder_State *st, /* i/o: decoder state structure */ Word16 output_fx[], /* o : synthesis @internal Fs Q_syn*/ Word16 synth_fx16[], /* o : synthesis Q_syn2*/ @@ -81,14 +81,14 @@ ivas_error acelp_core_dec_ivas_fx( Word16 syn_tmp_fx[L_FRAME16k + L_SUBFR], *psyn_fx; /* synthesis signal buffer */ Word16 output_frame; /* frame length at output sampling freq. */ Word16 lsf_new_fx[M]; /* LSFs at the end of the frame Qlog2(2.56) */ - Word16 lsp_new_fx[M]; /* LSPs at the end of the frame Q15 */ + Word16 lsp_new_fx[M]; /* LSPs at the end of the frame Q15 */ Word16 lsp_mid_fx[M]; /* LSPs in the middle of the frame */ Word16 Aq_fx[NB_SUBFR16k * ( M + 1 )]; /* A(q) quantized for the 4 subframes */ Word16 old_exc2_fx[L_FRAME16k + L_EXC_MEM], *exc2_fx; /* total excitation buffer */ Word16 mem_tmp_fx[M]; /* temporary synthesis filter memory */ Word32 enr_q_fx; /* E information for FER protection */ Word16 tmp_noise_fx; /* Long term temporary noise energy */ - Word16 Es_pred_fx; /* predicted scaled innov. energy Q8 */ + Word16 Es_pred_fx; /* predicted scaled innov. energy Q8 */ Word16 FEC_pitch_fx; /* FEC pitch */ Word16 old_bwe_exc_fx[( ( PIT16k_MAX + ( L_FRAME16k + 1 ) + L_SUBFR16k ) * 2 )]; /* excitation buffer */ Word16 *bwe_exc_fx; /* Excitation for SWB TBE */ @@ -181,6 +181,7 @@ ivas_error acelp_core_dec_ivas_fx( st->hFdCngDec->hFdCngCom->sidNoiseEstExp = common_e; move16(); } + FOR( i = 0; i < NPART; i++ ) { st->hFdCngDec->hFdCngCom->sidNoiseEstLp[i] = Madd_32_32( Mpy_32_32( STEREO_DFT_FD_FILT_Q31, st->hFdCngDec->hFdCngCom->sidNoiseEstLp[i] ), @@ -188,14 +189,14 @@ ivas_error acelp_core_dec_ivas_fx( move32(); } - ApplyFdCng_ivas_fx( NULL, 0, NULL, 0, NULL, NULL, NULL, st, 0, 0 ); + ApplyFdCng_fx( NULL, 0, NULL, 0, NULL, NULL, NULL, st, 0, 0 ); } ELSE { configureFdCngDec_fx( st->hFdCngDec, st->bwidth, ACELP_14k25, st->L_frame, st->last_L_frame, st->element_mode ); /* decode CNG parameters */ - CNG_dec_ivas_fx( st, last_element_mode, Aq_fx, lsp_new_fx, lsf_new_fx, &allow_cn_step, sid_bw, q_env_fx ); + CNG_dec_fx( st, last_element_mode, Aq_fx, lsp_new_fx, lsf_new_fx, &allow_cn_step, sid_bw, q_env_fx ); /* comfort noise generation */ CNG_exc_fx( st->core_brate, st->L_frame, &st->hTdCngDec->Enew_fx, &st->hTdCngDec->cng_seed, NULL, NULL, &st->lp_ener_fx, st->last_core_brate, &st->first_CNG, &( st->hTdCngDec->cng_ener_seed ), NULL, allow_cn_step, &st->hTdCngDec->last_allow_cn_step, st->prev_Q_exc, st->Q_exc, st->hTdCngDec->num_ho, q_env_fx, st->hTdCngDec->lp_env_fx, st->hTdCngDec->old_env_fx, st->hTdCngDec->exc_mem_fx, st->hTdCngDec->exc_mem1_fx, sid_bw, &st->hTdCngDec->cng_ener_seed1, NULL, st->Opt_AMR_WB, st->element_mode ); @@ -636,7 +637,7 @@ ivas_error acelp_core_dec_ivas_fx( /* decode CNG parameters */ IF( st->cng_type == LP_CNG ) { - CNG_dec_ivas_fx( st, last_element_mode, Aq_fx, lsp_new_fx, lsf_new_fx, &allow_cn_step, sid_bw, q_env_fx ); + CNG_dec_fx( st, last_element_mode, Aq_fx, lsp_new_fx, lsf_new_fx, &allow_cn_step, sid_bw, q_env_fx ); Copy( Aq_fx, st->Aq_cng, add( M, 1 ) ); /* comfort noise generation */ @@ -657,13 +658,11 @@ ivas_error acelp_core_dec_ivas_fx( test(); IF( EQ_32( st->core_brate, SID_2k40 ) && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { -#ifdef REMOVE_EVS_DUPLICATES IF( EQ_16( st->element_mode, EVS_MONO ) ) { FdCng_decodeSID_fx( st->hFdCngDec->hFdCngCom, st ); } ELSE -#endif { Word16 old_NoiseEstExp = st->hFdCngDec->hFdCngCom->sidNoiseEstExp; move16(); @@ -689,7 +688,7 @@ ivas_error acelp_core_dec_ivas_fx( move32(); } - ApplyFdCng_ivas_fx( psyn_fx, st->Q_syn, NULL, 0, realBuffer_fx, imagBuffer_fx, NULL, st, 0, ( st->coder_type == AUDIO && !st->GSC_noisy_speech ) ); + ApplyFdCng_fx( psyn_fx, st->Q_syn, NULL, 0, realBuffer_fx, imagBuffer_fx, NULL, st, 0, ( st->coder_type == AUDIO && !st->GSC_noisy_speech ) ); Word16 new_sidNoiseEstExp = 31 - Q4; move16(); @@ -704,7 +703,7 @@ ivas_error acelp_core_dec_ivas_fx( move16(); test(); - ApplyFdCng_ivas_fx( psyn_fx, st->Q_syn, NULL, 0, realBuffer_fx, imagBuffer_fx, NULL, st, 0, ( EQ_16( st->coder_type, AUDIO ) && !st->GSC_noisy_speech ) ); + ApplyFdCng_fx( psyn_fx, st->Q_syn, NULL, 0, realBuffer_fx, imagBuffer_fx, NULL, st, 0, ( EQ_16( st->coder_type, AUDIO ) && !st->GSC_noisy_speech ) ); IF( st->hFdCngDec->hFdCngCom->cngNoiseLevelExp < 0 ) { @@ -728,13 +727,11 @@ ivas_error acelp_core_dec_ivas_fx( } } -#ifdef REMOVE_EVS_DUPLICATES IF( EQ_16( st->element_mode, EVS_MONO ) ) { generate_comfort_noise_dec_fx( NULL, NULL, NULL, st, &( st->Q_exc ), 2, -1 ); } ELSE -#endif { generate_comfort_noise_dec_ivas_fx( NULL, NULL, NULL, st, &( st->Q_exc ), 1, nchan_out ); } @@ -758,7 +755,6 @@ ivas_error acelp_core_dec_ivas_fx( test(); IF( st->hMusicPF && st->hGSCDec ) { -#ifdef REMOVE_EVS_DUPLICATES IF( EQ_16( st->element_mode, EVS_MONO ) ) { // VE: TBV: should 'st_fx->L_frame * HIBND_ACB_L_FAC' be corrected in EVS? @@ -766,7 +762,6 @@ ivas_error acelp_core_dec_ivas_fx( st->L_frame * HIBND_ACB_L_FAC, 0, &( st->Q_exc ), st->Q_subfr, NULL, 0, INACTIVE ); } ELSE -#endif { Rescale_exc( st->hMusicPF->dct_post_old_exc_fx, exc_fx, bwe_exc_fx, st->hGSCDec->last_exc_dct_in_fx, st->L_frame, L_FRAME32k, 0, &( st->Q_exc ), st->Q_subfr, NULL, 0, INACTIVE ); @@ -794,7 +789,6 @@ ivas_error acelp_core_dec_ivas_fx( /* Update music post processing values */ /* Filter energies update */ -#ifdef REMOVE_EVS_DUPLICATES IF( EQ_16( st->element_mode, EVS_MONO ) ) { FOR( i = 0; i < DCT_L_POST; i++ ) @@ -804,7 +798,6 @@ ivas_error acelp_core_dec_ivas_fx( } } ELSE -#endif { FOR( i = 0; i < DCT_L_POST; i++ ) { @@ -822,15 +815,12 @@ ivas_error acelp_core_dec_ivas_fx( /* reset the decoder */ CNG_reset_dec_fx( st, pitch_buf_fx, voice_factors_fx ); - -#ifdef REMOVE_EVS_DUPLICATES IF( EQ_16( st->element_mode, EVS_MONO ) ) { /* update st_fx->mem_syn1 for ACELP core switching */ Copy( st->mem_syn3_fx, st->mem_syn1_fx, M ); } ELSE -#endif { st->Q_syn_cng = st->Q_syn; move16(); @@ -889,13 +879,13 @@ ivas_error acelp_core_dec_ivas_fx( move16(); } - config_acelp1_IVAS( DEC, st->total_brate, st->core_brate, st->core, st->extl_orig, st->extl_brate_orig, st->L_frame, st->GSC_noisy_speech, &( st->acelp_cfg ), st->next_bit_pos, st->coder_type, st->inactive_coder_type_flag, tc_subfr_tmp, 1, &nb_bits, unbits, st->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st->idchan, st->active_cnt, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); + config_acelp1_fx( DEC, st->total_brate, st->core_brate, st->core, st->extl_orig, st->extl_brate_orig, st->L_frame, st->GSC_noisy_speech, &( st->acelp_cfg ), st->next_bit_pos, st->coder_type, st->inactive_coder_type_flag, tc_subfr_tmp, 1, &nb_bits, unbits, st->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st->idchan, st->active_cnt, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); test(); test(); IF( EQ_16( st->coder_type, TRANSITION ) && LT_16( tc_subfr, L_SUBFR ) && EQ_16( st->L_frame, L_FRAME ) ) { - config_acelp1_IVAS( DEC, st->total_brate, st->core_brate, st->core, st->extl_orig, st->extl_brate_orig, st->L_frame, -1, &( st->acelp_cfg ), st->next_bit_pos, TRANSITION, -1, tc_subfr, 2, &nb_bits, unbits, st->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st->idchan, st->active_cnt, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); + config_acelp1_fx( DEC, st->total_brate, st->core_brate, st->core, st->extl_orig, st->extl_brate_orig, st->L_frame, -1, &( st->acelp_cfg ), st->next_bit_pos, TRANSITION, -1, tc_subfr, 2, &nb_bits, unbits, st->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st->idchan, st->active_cnt, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); } } @@ -934,7 +924,7 @@ ivas_error acelp_core_dec_ivas_fx( IF( !tdm_lp_reuse_flag ) { - lsf_dec_ivas_fx( st, tc_subfr, Aq_fx, &LSF_Q_prediction, lsf_new_fx, lsp_new_fx, lsp_mid_fx, tdm_low_rate_mode, tdm_lsfQ_PCh_fx ); + lsf_dec_fx( st, tc_subfr, Aq_fx, &LSF_Q_prediction, lsf_new_fx, lsp_new_fx, lsp_mid_fx, tdm_low_rate_mode, tdm_lsfQ_PCh_fx ); } ELSE { @@ -1084,7 +1074,7 @@ ivas_error acelp_core_dec_ivas_fx( } ELSE /* GENERIC */ { - decod_gen_2sbfr_ivas_fx( st, sharpFlag, Aq_fx, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, gain_buf_fx, tdm_Pitch_reuse_flag, p_tdm_Pri_pitch_buf_fx ); + decod_gen_2sbfr_fx( st, sharpFlag, Aq_fx, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, gain_buf_fx, tdm_Pitch_reuse_flag, p_tdm_Pri_pitch_buf_fx ); IF( EQ_16( st->element_mode, IVAS_CPE_TD ) ) { @@ -1106,7 +1096,7 @@ ivas_error acelp_core_dec_ivas_fx( ELSE IF( EQ_16( st->coder_type, UNVOICED ) ) { /* UNVOICED frames */ - decod_unvoiced_ivas_fx( st, Aq_fx, Es_pred_fx, uc_two_stage_flag, st->coder_type, &tmp_noise_fx, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, gain_buf_fx ); + decod_unvoiced_fx( st, Aq_fx, Es_pred_fx, uc_two_stage_flag, st->coder_type, &tmp_noise_fx, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, gain_buf_fx ); tmp_noise_fx = shr_r( st->lp_gainc_fx, 3 ); /*Q0*/ } @@ -1131,15 +1121,15 @@ ivas_error acelp_core_dec_ivas_fx( ELSE IF( EQ_16( st->coder_type, AUDIO ) || ( ( st->coder_type == INACTIVE ) && st->inactive_coder_type_flag ) ) { /* AUDIO and INACTIVE frames (coded by GSC technology) */ - decod_audio_ivas_fx( st, dct_exc_tmp_fx, Aq_fx, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, lsf_new_fx, gain_buf_fx, - tdm_lp_reuse_flag, tdm_low_rate_mode, tdm_Pitch_reuse_flag, p_tdm_Pri_pitch_buf_fx ); + decod_audio_fx( st, dct_exc_tmp_fx, Aq_fx, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, lsf_new_fx, gain_buf_fx, + tdm_lp_reuse_flag, tdm_low_rate_mode, tdm_Pitch_reuse_flag, p_tdm_Pri_pitch_buf_fx ); tmp_noise_fx = shr_r( st->lp_gainc_fx, 3 ); /*Q0*/ } ELSE { /* GENERIC, VOICED and INACTIVE frames (coded by AVQ technology) */ - IF( NE_32( ( error = decod_gen_voic_ivas_fx( st, st->L_frame, sharpFlag, Aq_fx, Es_pred_fx, do_WI, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, unbits, gain_buf_fx, tdm_Pitch_reuse_flag, p_tdm_Pri_pitch_buf_fx ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = decod_gen_voic_fx( st, st->L_frame, sharpFlag, Aq_fx, Es_pred_fx, do_WI, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, unbits, gain_buf_fx, tdm_Pitch_reuse_flag, p_tdm_Pri_pitch_buf_fx ) ), IVAS_ERR_OK ) ) { return error; } @@ -1163,7 +1153,7 @@ ivas_error acelp_core_dec_ivas_fx( * Apply energy matching when switching to inactive frames *-----------------------------------------------------------------*/ - Inac_switch_ematch_ivas_fx( exc2_fx, dct_exc_tmp_fx, st->hGSCDec->lt_ener_per_band_fx, st->coder_type, st->inactive_coder_type_flag, st->L_frame, st->Q_exc, st->bfi, st->last_core, st->last_codec_mode, tdm_low_rate_mode, st->element_mode ); + Inac_switch_ematch_fx( exc2_fx, dct_exc_tmp_fx, st->hGSCDec->lt_ener_per_band_fx, st->coder_type, st->inactive_coder_type_flag, st->L_frame, st->Q_exc, st->bfi, st->last_core, st->last_codec_mode, tdm_low_rate_mode, st->element_mode ); /*------------------------------------------------------------* * Decode information and modify the excitation signal of stationary unvoiced frames @@ -1212,7 +1202,6 @@ ivas_error acelp_core_dec_ivas_fx( move16(); /* Extrapolation of the last future part, windowing and high resolution DCT transform */ -#ifdef REMOVE_EVS_DUPLICATES IF( EQ_16( st->element_mode, EVS_MONO ) ) { // VE: TBV: this is likely a bug in EVS - 'st->last_coder_type' should be replaced by 'st->core_brate' @@ -1220,7 +1209,6 @@ ivas_error acelp_core_dec_ivas_fx( st->hMusicPF->LDm_enh_lp_gbin_fx, st->Q_exc, &qdct ); } ELSE -#endif { Prep_music_postP_fx( exc_buffer_fx, dct_buffer_fx, st->hMusicPF->filt_lfE_fx, st->last_core, st->element_mode, pitch_buf_fx, st->hMusicPF->LDm_enh_lp_gbin_fx, st->Q_exc, &qdct ); } @@ -1229,9 +1217,7 @@ ivas_error acelp_core_dec_ivas_fx( LD_music_post_filter_fx( st->hMusicPF, dct_buffer_fx, dct_buffer_fx, st->core_brate, &st->hMusicPF->Old_ener_Q, AUDIO, last_coder_type, qdct ); /* Inverse DCT transform, retrieval of the aligned excitation, re-synthesis */ -#ifdef REMOVE_EVS_DUPLICATES IF( NE_16( st->element_mode, EVS_MONO ) ) // VE: TBC whether needed in IVAS -#endif { Copy( st->mem_syn2_fx, mem_tmp_fx, M ); /*Q_syn*/ } @@ -1300,13 +1286,9 @@ ivas_error acelp_core_dec_ivas_fx( Copy_Scale_sig( pitch_buf_fx, pitch_buf_tmp, st->nb_subfr, -Q6 ); // Q0 - FEC_scale_syn_ivas_fx( st->L_frame, &update_flg, st->clas_dec, st->last_good, psyn_fx, pitch_buf_tmp, st->enr_old_fx, enr_q_fx, st->coder_type, LSF_Q_prediction, - &st->scaling_flag, &st->lp_ener_FEC_av, &st->lp_ener_FEC_max, st->bfi, st->total_brate, st->prev_bfi, st->last_core_brate, -#ifdef REMOVE_EVS_DUPLICATES - exc_fx, exc2_fx, Aq_fx, &st->old_enr_LP, mem_tmp_fx, st->mem_syn2_fx, st->Q_exc, st->Q_syn, st->element_mode, avoid_lpc_burst_on_recovery, 0 ); -#else - exc_fx, exc2_fx, Aq_fx, &st->old_enr_LP, mem_tmp_fx, st->mem_syn2_fx, st->Q_exc, st->Q_syn, avoid_lpc_burst_on_recovery, 0 ); -#endif + FEC_scale_syn_fx( st->L_frame, &update_flg, st->clas_dec, st->last_good, psyn_fx, pitch_buf_tmp, st->enr_old_fx, enr_q_fx, st->coder_type, LSF_Q_prediction, + &st->scaling_flag, &st->lp_ener_FEC_av, &st->lp_ener_FEC_max, st->bfi, st->total_brate, st->prev_bfi, st->last_core_brate, + exc_fx, exc2_fx, Aq_fx, &st->old_enr_LP, mem_tmp_fx, st->mem_syn2_fx, st->Q_exc, st->Q_syn, st->element_mode, avoid_lpc_burst_on_recovery, 0 ); test(); test(); @@ -1384,7 +1366,7 @@ ivas_error acelp_core_dec_ivas_fx( } /* Apply energy matching when switching to inactive frames */ - Inac_switch_ematch_ivas_fx( exc2_fx, dct_exc_tmp_fx, st->hGSCDec->lt_ener_per_band_fx, st->coder_type, st->inactive_coder_type_flag, st->L_frame, st->Q_exc, st->bfi, st->last_core, st->last_codec_mode, tdm_low_rate_mode, st->element_mode ); + Inac_switch_ematch_fx( exc2_fx, dct_exc_tmp_fx, st->hGSCDec->lt_ener_per_band_fx, st->coder_type, st->inactive_coder_type_flag, st->L_frame, st->Q_exc, st->bfi, st->last_core, st->last_codec_mode, tdm_low_rate_mode, st->element_mode ); /* update past excitation signals for LD music post-filter */ IF( st->hMusicPF != NULL ) @@ -1452,13 +1434,9 @@ ivas_error acelp_core_dec_ivas_fx( { Copy_Scale_sig( pitch_buf_fx, pitch_buf_tmp, st->nb_subfr, -Q6 ); // Q0 - FEC_scale_syn_ivas_fx( st->L_frame, &update_flg, st->clas_dec, st->last_good, psyn_fx, pitch_buf_tmp, st->enr_old_fx, enr_q_fx, st->coder_type, LSF_Q_prediction, - &st->scaling_flag, &st->lp_ener_FEC_av, &st->lp_ener_FEC_max, st->bfi, st->total_brate, st->prev_bfi, st->last_core_brate, -#ifdef REMOVE_EVS_DUPLICATES - exc_fx, exc2_fx, Aq_fx, &st->old_enr_LP, mem_tmp_fx, st->mem_syn2_fx, st->Q_exc, st->Q_syn, st->element_mode, avoid_lpc_burst_on_recovery, 0 ); -#else - exc_fx, exc2_fx, Aq_fx, &st->old_enr_LP, mem_tmp_fx, st->mem_syn2_fx, st->Q_exc, st->Q_syn, avoid_lpc_burst_on_recovery, 0 ); -#endif + FEC_scale_syn_fx( st->L_frame, &update_flg, st->clas_dec, st->last_good, psyn_fx, pitch_buf_tmp, st->enr_old_fx, enr_q_fx, st->coder_type, LSF_Q_prediction, + &st->scaling_flag, &st->lp_ener_FEC_av, &st->lp_ener_FEC_max, st->bfi, st->total_brate, st->prev_bfi, st->last_core_brate, + exc_fx, exc2_fx, Aq_fx, &st->old_enr_LP, mem_tmp_fx, st->mem_syn2_fx, st->Q_exc, st->Q_syn, st->element_mode, avoid_lpc_burst_on_recovery, 0 ); } /* estimate the pitch-synchronous speech energy per sample to be used when normal operation recovers */ @@ -1544,7 +1522,7 @@ ivas_error acelp_core_dec_ivas_fx( Copy( psyn_fx, temp_buf_fx + L_SYN_MEM, L_FRAME16k ); set16_fx( st->hPFstat->mem_zero, 0, M ); - formant_post_filt_ivas_fx( st->hPFstat, temp_buf_fx + L_SYN_MEM, Aq_fx, psyn_fx, st->L_frame, st->lp_noise, st->total_brate, 0 ); + formant_post_filt_fx( st->hPFstat, temp_buf_fx + L_SYN_MEM, Aq_fx, psyn_fx, st->L_frame, st->lp_noise, st->total_brate, 0 ); } ELSE IF( st->hPFstat != NULL && GE_16( st->last_bwidth, WB ) ) { @@ -1612,7 +1590,7 @@ ivas_error acelp_core_dec_ivas_fx( IF( NE_16( st->element_mode, IVAS_CPE_TD ) && !st->cng_ism_flag ) { /* Noise estimate */ - ApplyFdCng_ivas_fx( psyn_fx, st->Q_syn, NULL, 0, realBuffer_fx, imagBuffer_fx, NULL, st, 0, ( st->coder_type == AUDIO && !st->GSC_noisy_speech ) ); + ApplyFdCng_fx( psyn_fx, st->Q_syn, NULL, 0, realBuffer_fx, imagBuffer_fx, NULL, st, 0, ( st->coder_type == AUDIO && !st->GSC_noisy_speech ) ); } IF( !st->cna_dirac_flag ) @@ -1652,13 +1630,11 @@ ivas_error acelp_core_dec_ivas_fx( } ELSE IF( NE_16( st->element_mode, IVAS_CPE_DFT ) ) { -#ifdef REMOVE_EVS_DUPLICATES IF( EQ_16( st->element_mode, EVS_MONO ) ) { generate_masking_noise_fx( psyn_fx, st->Q_syn, st->hFdCngDec->hFdCngCom, st->hFdCngDec->hFdCngCom->frameSize, 0 ); } ELSE -#endif { IF( st->idchan == 0 ) { @@ -1666,10 +1642,13 @@ ivas_error acelp_core_dec_ivas_fx( { set16_fx( st->hFdCngDec->hFdCngCom->olapBufferSynth2, 0, st->hFdCngDec->hFdCngCom->fftlen ); } + Word32 psyn_32_fx[L_FRAME16k]; Copy_Scale_sig_16_32_no_sat( psyn_fx, psyn_32_fx, st->hFdCngDec->hFdCngCom->frameSize, sub( Q6, st->Q_syn ) ); // Q6 Copy_Scale_sig_16_32_no_sat( st->hFdCngDec->hFdCngCom->olapBufferSynth2, st->hFdCngDec->hFdCngCom->olapBufferSynth2_fx, shl( st->hFdCngDec->hFdCngCom->frameSize, 1 ), Q15 ); // Q15 + generate_masking_noise_ivas_fx( psyn_32_fx, &exp, st->hFdCngDec->hFdCngCom, st->hFdCngDec->hFdCngCom->frameSize, 0, 0, 0, st->element_mode, hStereoCng, nchan_out ); + Copy_Scale_sig_32_16( psyn_32_fx, psyn_fx, st->hFdCngDec->hFdCngCom->frameSize, sub( st->Q_syn, exp ) ); // Q = st->Q_syn Copy_Scale_sig_32_16( st->hFdCngDec->hFdCngCom->olapBufferSynth2_fx, st->hFdCngDec->hFdCngCom->olapBufferSynth2, shl( st->hFdCngDec->hFdCngCom->frameSize, 1 ), -Q15 ); // Q0 } @@ -1713,7 +1692,7 @@ ivas_error acelp_core_dec_ivas_fx( /*Noise estimate*/ IF( ( st->idchan == 0 ) && ( EQ_16( nchan_out, 2 ) || ( st->core_brate != FRAME_NO_DATA && NE_32( st->core_brate, SID_2k40 ) ) ) ) { - ApplyFdCng_ivas_fx( psyn_fx, st->Q_syn, NULL, 0, realBuffer_fx, imagBuffer_fx, NULL, st, 0, ( st->coder_type == AUDIO && !st->GSC_noisy_speech ) ); + ApplyFdCng_fx( psyn_fx, st->Q_syn, NULL, 0, realBuffer_fx, imagBuffer_fx, NULL, st, 0, ( st->coder_type == AUDIO && !st->GSC_noisy_speech ) ); } } } @@ -1730,7 +1709,6 @@ ivas_error acelp_core_dec_ivas_fx( test(); IF( ( st->flag_cna == 0 ) && EQ_16( st->L_frame, L_FRAME16k ) && EQ_16( st->last_flag_cna, 1 ) && ( ( st->last_core == ACELP_CORE && !( EQ_16( st->last_coder_type, AUDIO ) && !( st->element_mode > EVS_MONO && st->Last_GSC_noisy_speech_flag ) ) ) || EQ_16( st->last_core, AMR_WB_CORE ) ) ) { -#ifdef REMOVE_EVS_DUPLICATES IF( EQ_16( st->element_mode, EVS_MONO ) ) { // VE: TBV - is it correct in EVS? in FLP, it is: @@ -1743,7 +1721,6 @@ ivas_error acelp_core_dec_ivas_fx( } } ELSE -#endif { FOR( i = 0; i < ( st->hFdCngDec->hFdCngCom->frameSize ) / 2; i++ ) { @@ -1775,7 +1752,6 @@ ivas_error acelp_core_dec_ivas_fx( * Bass post-filter *----------------------------------------------------------------*/ -#ifdef REMOVE_EVS_DUPLICATES IF( EQ_16( st->element_mode, EVS_MONO ) ) { CLDFB_SCALE_FACTOR scaleFactor; @@ -1880,7 +1856,6 @@ ivas_error acelp_core_dec_ivas_fx( Copy( synth_fx16, st->previoussynth_fx, output_frame ); } ELSE -#endif { /* check if the CLDFB works on the right sample rate */ IF( NE_16( imult1616( st->cldfbAna->no_channels, st->cldfbAna->no_col ), st->L_frame ) ) @@ -1896,9 +1871,7 @@ ivas_error acelp_core_dec_ivas_fx( } /* analyze pitch coherence for bass post-filter */ - Word32 pitch_buf_fx_q20[12]; - Scale_sig32( st->old_pitch_buf_fx, 2 * NB_SUBFR16k + 2, Q4 ); // Q(x+4) Word16 lim = shr( st->L_frame, 6 ); FOR( Word16 lp = 0; lp < lim; lp++ ) @@ -1961,7 +1934,9 @@ ivas_error acelp_core_dec_ivas_fx( Scale_sig32( st->cldfbAna->cldfb_state_fx, offset, 1 ); // Q12 st->cldfbAna->Q_cldfb_state = Q12; move16(); + cldfbAnalysis_ivas_fx( syn_32_fx, realBuffer_fx, imagBuffer_fx, -1, st->cldfbAna ); + Scale_sig32( st->cldfbAna->cldfb_state_fx, offset, -1 ); // Q11 st->cldfbAna->Q_cldfb_state = Q11; move16(); @@ -1990,6 +1965,7 @@ ivas_error acelp_core_dec_ivas_fx( } addBassPostFilter_ivas_fx( tmp_bpf_error_signal_fx, tmp, realBuffer_fx, imagBuffer_fx, st->cldfbBPF ); + Scale_sig32( st->cldfbBPF->cldfb_state_fx, cldfb_state_offset, negate( ( sub( q_bpf_error_signal, Q10 ) ) ) ); // Q10 st->cldfbBPF->Q_cldfb_state = Q10; move16(); @@ -2186,6 +2162,7 @@ ivas_error acelp_core_dec_ivas_fx( Scale_sig32( st->cldfbAna->cldfb_state_fx, offset, 1 ); // Q12 st->cldfbAna->Q_cldfb_state = Q12; move16(); + cldfbAnalysis_ivas_fx( syn_32_fx + sub( st->L_frame, nSamples ), realBuffer_fx, imagBuffer_fx, nSamples, st->cldfbAna ); Scale_sig32( st->cldfbAna->cldfb_state_fx, offset, -1 ); // Q11 @@ -2215,8 +2192,8 @@ ivas_error acelp_core_dec_ivas_fx( tmp = nSamples; move16(); } - addBassPostFilter_ivas_fx( tmp_bpf_error_signal_fx + sub( st->L_frame, nSamples ), tmp, realBuffer_fx, imagBuffer_fx, st->cldfbBPF ); + addBassPostFilter_ivas_fx( tmp_bpf_error_signal_fx + sub( st->L_frame, nSamples ), tmp, realBuffer_fx, imagBuffer_fx, st->cldfbBPF ); Scale_sig32( st->cldfbBPF->cldfb_state_fx, cldfb_state_offset, negate( sub( q_bpf_error_signal, Q10 ) ) ); // Q10 st->cldfbBPF->Q_cldfb_state = Q10; @@ -2299,13 +2276,11 @@ ivas_error acelp_core_dec_ivas_fx( IF( ( EQ_16( st->L_frame, L_FRAME ) && ( st->bwidth != NB ) && GE_16( output_frame, L_FRAME16k ) && ( EQ_16( st->extl, -1 ) || EQ_16( st->extl, SWB_CNG ) || ( EQ_16( st->extl, WB_BWE ) && st->extl_brate == 0 && NE_16( st->coder_type, AUDIO ) ) ) ) ) { -#ifdef REMOVE_EVS_DUPLICATES IF( EQ_16( st->element_mode, EVS_MONO ) ) { hf_synth_fx( st->hBWE_zero, st->core_brate, output_frame, Aq_fx, exc2_fx, psyn_fx, synth_fx16, st->Q_exc, st->Q_syn2 ); } ELSE -#endif { Copy_Scale_sig_32_16( synth_fx, synth_fx16, output_frame, 0 ); // Q0 hf_synth_fx( st->hBWE_zero, st->core_brate, output_frame, Aq_fx, exc2_fx, psyn_fx, synth_fx16, st->Q_exc, st->Q_syn2 ); @@ -2315,9 +2290,7 @@ ivas_error acelp_core_dec_ivas_fx( ELSE { hf_synth_reset_fx( st->hBWE_zero ); -#ifdef REMOVE_EVS_DUPLICATES 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 ); } @@ -2356,13 +2329,11 @@ ivas_error acelp_core_dec_ivas_fx( test(); IF( !st->ppp_mode_dec && ( st->idchan == 0 || NE_16( st->element_mode, IVAS_CPE_TD ) || ( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) && st->tdm_LRTD_flag ) ) ) { -#ifdef REMOVE_EVS_DUPLICATES IF( EQ_16( st->element_mode, EVS_MONO ) ) { non_linearity_fx( bwe_exc_fx, bwe_exc_extended_fx, L_FRAME32k, &st->hBWE_TD->bwe_non_lin_prev_scale_fx, st->Q_exc, st->coder_type, voice_factors_fx, st->L_frame ); } ELSE -#endif { Copy_Scale_sig_16_32_no_sat( st->hBWE_TD->old_bwe_exc_extended_fx, bwe_exc_extended_fx, NL_BUFF_OFFSET, ( sub( shl( st->Q_exc, 1 ), sub( st->prev_Q_bwe_exc, 16 ) ) ) ); // prev_Q_bwe_exc non_linearity_ivas_fx( bwe_exc_fx, bwe_exc_extended_fx + NL_BUFF_OFFSET, L_FRAME32k, &st->hBWE_TD->bwe_non_lin_prev_scale_fx, st->Q_exc, st->coder_type, voice_factors_fx, st->L_frame ); @@ -2389,14 +2360,12 @@ ivas_error acelp_core_dec_ivas_fx( IF( GT_32( st->core_brate, SID_2k40 ) && st->hTdCngDec != NULL && st->hFdCngDec != NULL ) { /* update CNG parameters in active frames */ -#ifdef REMOVE_EVS_DUPLICATES IF( EQ_16( st->element_mode, EVS_MONO ) ) { cng_params_upd_fx( lsp_new_fx, exc_fx, st->L_frame, &st->hTdCngDec->ho_circ_ptr, st->hTdCngDec->ho_ener_circ_fx, &st->hTdCngDec->ho_circ_size, st->hTdCngDec->ho_lsp_circ_fx, st->Q_exc, DEC, st->hTdCngDec->ho_env_circ_fx, NULL, NULL, NULL, NULL, st->last_active_brate ); } ELSE -#endif { cng_params_upd_ivas_fx( lsp_new_fx, exc_fx, st->L_frame, &st->hTdCngDec->ho_circ_ptr, st->hTdCngDec->ho_ener_circ_fx, &st->hTdCngDec->ho_circ_size, st->hTdCngDec->ho_lsp_circ_fx, st->Q_exc, DEC, st->hTdCngDec->ho_env_circ_fx, NULL, NULL, NULL, NULL, st->last_active_brate, st->element_mode, @@ -2413,9 +2382,7 @@ ivas_error acelp_core_dec_ivas_fx( } } -#ifdef REMOVE_EVS_DUPLICATES IF( NE_16( st->element_mode, EVS_MONO ) ) -#endif { IF( save_hb_synth_fx16 ) { diff --git a/lib_dec/acelp_core_switch_dec_fx.c b/lib_dec/acelp_core_switch_dec_fx.c index 6d3d0b381..363db8202 100644 --- a/lib_dec/acelp_core_switch_dec_fx.c +++ b/lib_dec/acelp_core_switch_dec_fx.c @@ -128,11 +128,7 @@ ivas_error acelp_core_switch_dec_fx( * Excitation decoding *----------------------------------------------------------------*/ -#ifdef REMOVE_EVS_DUPLICATES - config_acelp1_IVAS( DEC, st_fx->total_brate, cbrate, st_fx->core, -1, -1, st_fx->last_L_frame, -1, &( st_fx->acelp_cfg ), st_fx->next_bit_pos, GENERIC, st_fx->inactive_coder_type_flag, -1, -1, &decode_bwe /* dummy */, &i, st_fx->element_mode, &i /*dummy*/, 0, 0, st_fx->idchan, st_fx->active_cnt, 0, 0, 0 ); -#else - config_acelp1( DEC, st_fx->total_brate, cbrate, st_fx->core, -1, -1, st_fx->last_L_frame, -1, &( st_fx->acelp_cfg ), st_fx->next_bit_pos, GENERIC, st_fx->inactive_coder_type_flag, -1, -1, &decode_bwe /* dummy */, &i, st_fx->element_mode, &i /*dummy*/, 0, 0, st_fx->idchan, st_fx->active_cnt, 0, 0, 0 ); -#endif + config_acelp1_fx( DEC, st_fx->total_brate, cbrate, st_fx->core, -1, -1, st_fx->last_L_frame, -1, &( st_fx->acelp_cfg ), st_fx->next_bit_pos, GENERIC, st_fx->inactive_coder_type_flag, -1, -1, &decode_bwe /* dummy */, &i, st_fx->element_mode, &i /*dummy*/, 0, 0, st_fx->idchan, st_fx->active_cnt, 0, 0, 0 ); decod_gen_voic_core_switch_fx( st_fx, L_frame_for_cs, 0, Aq, exc, cbrate, &st_fx->Q_exc ); @@ -920,11 +916,7 @@ static void decod_gen_voic_core_switch_fx( * Decode pitch lag *----------------------------------------------------------------------*/ -#ifdef REMOVE_EVS_DUPLICATES - pitch = pit_decode_ivas_fx( st_fx, core_brate, 0, L_frame, 0, GENERIC, &pitch_limit_flag, &T0, &T0_frac, &T0_min, &T0_max, L_SUBFR, 0, NULL ); /*Q6*/ -#else - pitch = pit_decode_fx( st_fx, core_brate, 0, L_frame, 0, GENERIC, &pitch_limit_flag, &T0, &T0_frac, &T0_min, &T0_max, L_SUBFR ); /*Q6*/ -#endif + pitch = pit_decode_fx( st_fx, core_brate, 0, L_frame, 0, GENERIC, &pitch_limit_flag, &T0, &T0_frac, &T0_min, &T0_max, L_SUBFR, 0, NULL ); /*Q6*/ /*--------------------------------------------------------------* * Find the adaptive codebook vector. diff --git a/lib_dec/amr_wb_dec_fx.c b/lib_dec/amr_wb_dec_fx.c index 971af2b56..96ae82dde 100644 --- a/lib_dec/amr_wb_dec_fx.c +++ b/lib_dec/amr_wb_dec_fx.c @@ -373,11 +373,7 @@ ivas_error amr_wb_dec_fx( IF( EQ_32( st_fx->core_brate, FRAME_NO_DATA ) || EQ_32( st_fx->core_brate, SID_1k75 ) ) { /* decode CNG parameters */ -#ifdef REMOVE_EVS_DUPLICATES - CNG_dec_ivas_fx( st_fx, EVS_MONO, Aq_fx, lsp_new_fx, lsf_new_fx, &allow_cn_step, &sid_bw, q_env ); -#else CNG_dec_fx( st_fx, EVS_MONO, Aq_fx, lsp_new_fx, lsf_new_fx, &allow_cn_step, &sid_bw, q_env ); -#endif /* comfort noise generation */ CNG_exc_fx( st_fx->core_brate, L_FRAME, &st_fx->hTdCngDec->Enew_fx, &st_fx->hTdCngDec->cng_seed, exc_fx, exc2_fx, &st_fx->lp_ener_fx, st_fx->last_core_brate, @@ -630,15 +626,9 @@ ivas_error amr_wb_dec_fx( move16(); } -#ifdef REMOVE_EVS_DUPLICATES - FEC_scale_syn_ivas_fx( L_FRAME, &update_flg, st_fx->clas_dec, st_fx->last_good, syn_fx, pitch_buf_tmp, st_fx->enr_old_fx, L_enr_q_fx, -1, MOVING_AVERAGE, - &st_fx->scaling_flag, &st_fx->lp_ener_FEC_av, &st_fx->lp_ener_FEC_max, st_fx->bfi, st_fx->total_brate, st_fx->prev_bfi, st_fx->last_core_brate, - exc_fx, exc2_fx, Aq_fx, &st_fx->old_enr_LP, mem_tmp_fx, st_fx->mem_syn2_fx, st_fx->Q_exc, st_fx->Q_syn, EVS_MONO, avoid_lpc_burst_on_recovery, 0 ); -#else FEC_scale_syn_fx( L_FRAME, &update_flg, st_fx->clas_dec, st_fx->last_good, syn_fx, pitch_buf_tmp, st_fx->enr_old_fx, L_enr_q_fx, -1, MOVING_AVERAGE, &st_fx->scaling_flag, &st_fx->lp_ener_FEC_av, &st_fx->lp_ener_FEC_max, st_fx->bfi, st_fx->total_brate, st_fx->prev_bfi, st_fx->last_core_brate, - exc_fx, exc2_fx, Aq_fx, &st_fx->old_enr_LP, mem_tmp_fx, st_fx->mem_syn2_fx, st_fx->Q_exc, st_fx->Q_syn, avoid_lpc_burst_on_recovery, 0 ); -#endif + exc_fx, exc2_fx, Aq_fx, &st_fx->old_enr_LP, mem_tmp_fx, st_fx->mem_syn2_fx, st_fx->Q_exc, st_fx->Q_syn, EVS_MONO, avoid_lpc_burst_on_recovery, 0 ); frame_ener_fx( L_FRAME, st_fx->clas_dec, syn_fx, pitch_buf_tmp[3], &st_fx->enr_old_fx, L_FRAME, st_fx->Q_syn, 3, 0 ); } @@ -717,17 +707,10 @@ ivas_error amr_wb_dec_fx( * (smoothing is performed in the excitation domain and signal is resynthesized after) *------------------------------------------------------------*/ -#ifdef REMOVE_EVS_DUPLICATES - FEC_scale_syn_ivas_fx( L_FRAME, &update_flg, st_fx->clas_dec, st_fx->last_good, syn_fx, pitch_buf_tmp, st_fx->enr_old_fx, L_enr_q_fx, -1, - MOVING_AVERAGE, &st_fx->scaling_flag, &st_fx->lp_ener_FEC_av, &st_fx->lp_ener_FEC_max, st_fx->bfi, st_fx->total_brate, - st_fx->prev_bfi, st_fx->last_core_brate, exc_fx, exc2_fx, Aq_fx, &st_fx->old_enr_LP, mem_tmp_fx, st_fx->mem_syn2_fx, - st_fx->Q_exc, st_fx->Q_syn, EVS_MONO, 0, 0 ); -#else FEC_scale_syn_fx( L_FRAME, &update_flg, st_fx->clas_dec, st_fx->last_good, syn_fx, pitch_buf_tmp, st_fx->enr_old_fx, L_enr_q_fx, -1, MOVING_AVERAGE, &st_fx->scaling_flag, &st_fx->lp_ener_FEC_av, &st_fx->lp_ener_FEC_max, st_fx->bfi, st_fx->total_brate, st_fx->prev_bfi, st_fx->last_core_brate, exc_fx, exc2_fx, Aq_fx, &st_fx->old_enr_LP, mem_tmp_fx, st_fx->mem_syn2_fx, - st_fx->Q_exc, st_fx->Q_syn, 0, 0 ); -#endif + st_fx->Q_exc, st_fx->Q_syn, EVS_MONO, 0, 0 ); /* estimate the pitch-synchronous speech energy per sample to be used when normal operation recovers */ frame_ener_fx( L_FRAME, st_fx->last_good, syn_fx, shr( FEC_pitch_fx, 6 ), &st_fx->enr_old_fx, L_FRAME, st_fx->Q_syn, 3, 0 ); @@ -785,11 +768,7 @@ ivas_error amr_wb_dec_fx( st_fx->hPFstat->on = 1; move16(); test(); -#ifdef REMOVE_EVS_DUPLICATES - formant_post_filt_ivas_fx( st_fx->hPFstat, tmp_buffer_fx + L_SYN_MEM, Aq_fx, syn_fx, L_FRAME, L_shl( st_fx->psf_lp_noise_fx, 15 ), st_fx->total_brate, sub( amr_io_class, AUDIO_CLAS ) == 0 ); -#else formant_post_filt_fx( st_fx->hPFstat, tmp_buffer_fx + L_SYN_MEM, Aq_fx, syn_fx, L_FRAME, L_shl( st_fx->psf_lp_noise_fx, 15 ), st_fx->total_brate, sub( amr_io_class, AUDIO_CLAS ) == 0 ); -#endif } /*----------------------------------------------------------------* @@ -813,11 +792,9 @@ ivas_error amr_wb_dec_fx( st_fx->VAD = 0; move16(); } -#ifdef REMOVE_EVS_DUPLICATES - ApplyFdCng_ivas_fx( syn_fx, st_fx->Q_syn, NULL, 0, NULL, NULL, NULL, st_fx, 0, 0 ); -#else - ApplyFdCng_fx( syn_fx, st_fx->Q_syn, NULL, NULL, NULL, st_fx, 0, 0 ); -#endif + + ApplyFdCng_fx( syn_fx, st_fx->Q_syn, NULL, 0, NULL, NULL, NULL, st_fx, 0, 0 ); + st_fx->hFdCngDec->hFdCngCom->frame_type_previous = st_fx->m_frame_type; move16(); diff --git a/lib_dec/cng_dec_fx.c b/lib_dec/cng_dec_fx.c index ce6ad6568..fdb6488db 100644 --- a/lib_dec/cng_dec_fx.c +++ b/lib_dec/cng_dec_fx.c @@ -22,19 +22,19 @@ static void shb_CNG_decod_fx( Decoder_State *st_fx, const Word16 *synth_fx, Word static void shb_CNG_decod_ivas_fx( Decoder_State *st_fx, const Word16 *synth_fx, Word16 *shb_synth_fx, const Word16 sid_bw, const Word16 Qsyn ); /*-----------------------------------------------------------------* + * CNG_dec_fx() + * * Decode residual signal energy *-----------------------------------------------------------------*/ -#ifndef REMOVE_EVS_DUPLICATES void CNG_dec_fx( Decoder_State *st_fx, /* i/o: State structure */ - const Word16 last_element_mode, /* i : last element mode Q0 */ + const Word16 last_element_mode, /* i : last element mode Q0 */ Word16 Aq[], /* o : LP coefficients Q12 */ Word16 *lsp_new, /* i/o: current frame LSPs Q15 */ Word16 *lsf_new, /* i/o: current frame LSFs Qlog2(2.56) */ Word16 *allow_cn_step, /* o : allow CN step Q0 */ - Word16 *sid_bw /* i : 0-NB/WB, 1-SWB SID Q0 */ - , + Word16 *sid_bw, /* i : 0-NB/WB, 1-SWB SID Q0 */ Word32 *q_env ) { Word16 istep; @@ -72,7 +72,6 @@ void CNG_dec_fx( Word16 exp_pow; Word16 tmp_loop; Word16 enr_new, Aq_tmp[M + 1]; - Word16 LSF_Q_prediction; /* o : LSF prediction mode - just temporary variable in CNG */ TD_CNG_DEC_HANDLE hTdCngDec; #ifdef BASOP_NOGLOB_DECLARE_LOCAL @@ -108,681 +107,9 @@ void CNG_dec_fx( } ELSE { - lsf_dec_fx( st_fx, 0, Aq, &LSF_Q_prediction, lsf_new, lsp_new, 0, 0, - NULL ); - /* check IF LSPs may trigger too much synthesis energy */ - - E_LPC_f_lsp_a_conversion( lsp_new, Aq_tmp, M ); - enr_new = Enr_1_Az_fx( Aq_tmp, 2 * L_SUBFR ); - - IF( shr( enr_new, 14 ) > 0 ) - { - /* Use old LSP vector */ - Copy( st_fx->lsp_old_fx, lsp_new, M ); /* Q15 */ - Copy( st_fx->lsf_old_fx, lsf_new, M ); /* Q2.56 */ - } - } - } - ELSE - { - /* Use old LSP vector */ - Copy( st_fx->lsp_old_fx, lsp_new, M ); /* Q15 */ - Copy( st_fx->lsf_old_fx, lsf_new, M ); /* Q2.56 */ - } - - /* Initialize the CNG spectral envelope in case of the very first CNG frame */ - IF( st_fx->first_CNG == 0 ) - { - Copy( st_fx->lsp_old_fx, st_fx->lspCNG_fx, M ); /* Q15 */ - } - - /*-----------------------------------------------------------------* - * Decode residual signal energy - *-----------------------------------------------------------------*/ - - *allow_cn_step = 0; - move16(); - test(); - IF( EQ_32( st_fx->core_brate, SID_1k75 ) || EQ_32( st_fx->core_brate, SID_2k40 ) ) - { - istep = ISTEP_AMR_WB_SID_FX; /* Q15 */ - move16(); - if ( EQ_32( st_fx->core_brate, SID_2k40 ) ) - { - istep = ISTEP_SID_FX; /* Q15 */ - move16(); - } - - /* initialize the energy quantization parameters */ - num_bits = 6; - move16(); - if ( st_fx->Opt_AMR_WB == 0 ) - { - num_bits = 7; - move16(); - } - - /* decode the energy index */ - L_enr_index = get_next_indice_fx( st_fx, num_bits ); - - IF( LE_32( st_fx->last_core_brate, SID_2k40 ) || EQ_16( st_fx->prev_bfi, 1 ) ) - { - tmp1 = add( hTdCngDec->old_enr_index, 20 ); - } - ELSE - { - tmp1 = add( hTdCngDec->old_enr_index, 40 ); - } - IF( GT_16( L_enr_index, tmp1 ) && hTdCngDec->old_enr_index >= 0 ) /* Likely bit error and not startup */ - { - L_enr_index = tmp1; - move16(); - L_enr_index = s_min( L_enr_index, 127 ); /* Q0 */ - IF( st_fx->Opt_AMR_WB ) - { - L_enr_index = s_min( L_enr_index, 63 ); /* Q0 */ - } - } - - test(); - test(); - test(); - IF( GT_32( st_fx->last_core_brate, SID_1k75 ) && - NE_16( st_fx->first_CNG, 0 ) && - GE_16( hTdCngDec->old_enr_index, 0 ) && - GT_16( L_enr_index, add( hTdCngDec->old_enr_index, 1 ) ) ) - { - *allow_cn_step = 1; - move16(); - } - - hTdCngDec->old_enr_index = L_enr_index; - move16(); - if ( !L_enr_index ) - { - L_enr_index = -5; - move16(); - } - /* st_fx->Enew = L_enr_index / step - 2.0f;*/ - L_ener = L_mult( L_enr_index, istep ); /* Q16 (0+15) */ - /* subtract by 2 not done to leave Energy in Q2 */ - - /* extract integral and fractional parts */ - ener_fra = L_Extract_lc( L_ener, &ener_int ); - ener_int = add( ener_int, 4 ); /* Q2 to Q6 */ - - /* find the new energy value */ - hTdCngDec->Enew_fx = Pow2( ener_int, ener_fra ); - move32(); - - IF( EQ_32( st_fx->core_brate, SID_2k40 ) ) - { - burst_ho_cnt = get_next_indice_fx( st_fx, 3 ); /* 3bit */ - - *sid_bw = get_next_indice_fx( st_fx, 1 ); - move16(); - IF( *sid_bw == 0 ) - { - env_idx[0] = get_next_indice_fx( st_fx, 6 ); - move16(); - - /* get quantized res_env_details */ - FOR( i = 0; i < NUM_ENV_CNG; i++ ) - { - q_env[i] = L_deposit_l( CNG_details_codebook_fx[env_idx[0]][i] ); - move32(); - } - } - } - /* Reset CNG history IF CNG frame length is changed */ - test(); - test(); - IF( EQ_16( st_fx->bwidth, WB ) && NE_16( st_fx->first_CNG, 0 ) && NE_16( st_fx->L_frame, st_fx->last_CNG_L_frame ) ) - { - hTdCngDec->ho_hist_size = 0; - move16(); - } - } - - /*---------------------------------------------------------------------* - * CNG spectral envelope update - * Find A(z) coefficients - *---------------------------------------------------------------------*/ - test(); - test(); - test(); - IF( LE_32( st_fx->last_core_brate, SID_2k40 ) ) - { - /* Reset hangover counter if not first SID period */ - if ( GT_32( st_fx->core_brate, FRAME_NO_DATA ) ) - { - hTdCngDec->num_ho = 0; - move16(); - } - /* Update LSPs IF last SID energy not outliers or insufficient number of hangover frames */ - test(); - IF( LT_16( hTdCngDec->num_ho, 3 ) || LT_32( Mult_32_16( hTdCngDec->Enew_fx, 21845 /*1/1.5f, Q15*/ ), st_fx->lp_ener_fx ) ) - { - FOR( i = 0; i < M; i++ ) - { - /* AR low-pass filter */ - st_fx->lspCNG_fx[i] = mac_r( L_mult( CNG_ISF_FACT_FX, st_fx->lspCNG_fx[i] ), 32768 - CNG_ISF_FACT_FX, lsp_new[i] ); - move16(); /* Q15 (15+15+1-16) */ - } - } - } - ELSE - { - /* Update CNG_mode IF allowed */ - test(); - test(); - test(); - IF( ( st_fx->Opt_AMR_WB || EQ_16( st_fx->bwidth, WB ) ) && ( !st_fx->first_CNG || GE_16( hTdCngDec->act_cnt2, MIN_ACT_CNG_UPD ) ) ) - { - IF( GT_32( st_fx->last_active_brate, ACELP_16k40 ) ) - { - st_fx->CNG_mode = -1; - move16(); - } - ELSE - { - st_fx->CNG_mode = get_cng_mode( st_fx->last_active_brate ); - move16(); - } - } - - /* If first sid after active burst update LSF history from circ buffer */ - burst_ho_cnt = s_min( burst_ho_cnt, hTdCngDec->ho_circ_size ); /* MODE1_DTX_IN_CODEC_B_FIX Q0*/ - hTdCngDec->act_cnt = 0; - move16(); - s_ptr = add( sub( hTdCngDec->ho_circ_ptr, burst_ho_cnt ), 1 ); - IF( s_ptr < 0 ) - { - s_ptr = add( s_ptr, hTdCngDec->ho_circ_size ); - } - - FOR( ll = burst_ho_cnt; ll > 0; ll-- ) - { - hTdCngDec->ho_hist_ptr = add( hTdCngDec->ho_hist_ptr, 1 ); /* Q0 */ - move16(); - if ( EQ_16( hTdCngDec->ho_hist_ptr, HO_HIST_SIZE ) ) - { - hTdCngDec->ho_hist_ptr = 0; - move16(); - } - - /* Conversion between 12.8k and 16k LSPs */ - test(); - test(); - test(); - IF( ( EQ_16( st_fx->L_frame, L_FRAME16k ) && hTdCngDec->ho_16k_lsp[s_ptr] == 0 ) || ( EQ_16( st_fx->L_frame, L_FRAME ) && EQ_16( hTdCngDec->ho_16k_lsp[s_ptr], 1 ) ) ) - { - /* Conversion from 16k LPSs to 12k8 */ - lsp_convert_poly_fx( &( hTdCngDec->ho_lsp_circ_fx[s_ptr * M] ), st_fx->L_frame, 0 ); - } - /* update the circular buffers */ - Copy( &( hTdCngDec->ho_lsp_circ_fx[s_ptr * M] ), &( hTdCngDec->ho_lsp_hist_fx[hTdCngDec->ho_hist_ptr * M] ), M ); /* Qx */ - Copy32( &( hTdCngDec->ho_ener_circ_fx[s_ptr] ), &( hTdCngDec->ho_ener_hist_fx[hTdCngDec->ho_hist_ptr] ), 1 ); /* Q6 */ - hTdCngDec->ho_sid_bw = L_shl( L_and( hTdCngDec->ho_sid_bw, (Word32) 0x3fffffffL ), 1 ); - move32(); - Copy32( &( hTdCngDec->ho_env_circ_fx[s_ptr * NUM_ENV_CNG] ), &( hTdCngDec->ho_env_hist_fx[hTdCngDec->ho_hist_ptr * NUM_ENV_CNG] ), NUM_ENV_CNG ); /* Qx */ - - hTdCngDec->ho_hist_size = add( hTdCngDec->ho_hist_size, 1 ); - move16(); - - if ( GT_16( hTdCngDec->ho_hist_size, HO_HIST_SIZE ) ) - { - hTdCngDec->ho_hist_size = HO_HIST_SIZE; - move16(); - } - - s_ptr = add( s_ptr, 1 ); - if ( EQ_16( s_ptr, hTdCngDec->ho_circ_size ) ) - { - s_ptr = 0; - move16(); - } - } - - IF( hTdCngDec->ho_hist_size > 0 ) /* can be -1 at init MODE1_DTX_IN_CODEC_B_FIX */ - { - /* *allow_cn_step |= ( st_fx->ho_ener_hist[st_fx->ho_hist_ptr] > 4.0f * st_fx->lp_ener );*/ - L_tmp1 = L_shr( hTdCngDec->ho_ener_hist_fx[hTdCngDec->ho_hist_ptr], 2 ); - L_tmp1 = L_sub( L_tmp1, st_fx->lp_ener_fx ); + lsf_dec_fx( st_fx, 0, Aq, &LSF_Q_prediction, lsf_new, lsp_new, 0, 0, NULL ); - test(); - test(); - IF( ( L_tmp1 > 0 && ( st_fx->first_CNG || st_fx->element_mode == EVS_MONO ) ) ) - { - *allow_cn_step = s_or( *allow_cn_step, 1 ); - move16(); - } - } - IF( EQ_16( last_element_mode, IVAS_CPE_TD ) ) - { - *allow_cn_step = 1; - move16(); - } - test(); - IF( EQ_16( *allow_cn_step, 0 ) && GT_16( hTdCngDec->ho_hist_size, 0 ) ) - { - /* Use average of energies below last energy */ - ptr = hTdCngDec->ho_hist_ptr; - move16(); - Copy( &( hTdCngDec->ho_lsp_hist_fx[ptr * M] ), tmp, M ); /* Qx */ - m1 = 0; - move16(); - IF( L_and( hTdCngDec->ho_sid_bw, (Word32) 0x1 ) == 0 ) - { - Copy32( &hTdCngDec->ho_env_hist_fx[ptr * NUM_ENV_CNG], tmp_env, NUM_ENV_CNG ); - m1 = 1; - move16(); - } - L_enr = Mult_32_16( hTdCngDec->ho_ener_hist_fx[ptr], W_DTX_HO_FX[0] ); /* Q6+15-15->Q6 */ - - weights = W_DTX_HO_FX[0]; /* Q15 */ - move16(); - - m = 1; - move16(); - FOR( k = 1; k < hTdCngDec->ho_hist_size; k++ ) - { - ptr--; - if ( ptr < 0 ) - { - ptr = HO_HIST_SIZE - 1; - move16(); - } - - test(); - IF( LT_32( Mult_32_16( hTdCngDec->ho_ener_hist_fx[ptr], ONE_OVER_BUF_H_NRG_FX ), hTdCngDec->ho_ener_hist_fx[hTdCngDec->ho_hist_ptr] ) && - GT_32( hTdCngDec->ho_ener_hist_fx[ptr], Mult_32_16( hTdCngDec->ho_ener_hist_fx[hTdCngDec->ho_hist_ptr], BUF_L_NRG_FX ) ) ) - { - /*enr += W_DTX_HO[k] * st_fx->ho_ener_hist[ptr];*/ - L_tmp1 = Mult_32_16( hTdCngDec->ho_ener_hist_fx[ptr], W_DTX_HO_FX[k] ); /* Q6+15-15->Q6 */ - L_enr = L_add( L_enr, L_tmp1 ); /* Q6 */ - - /*weights += W_DTX_HO[k];*/ - weights = add( weights, W_DTX_HO_FX[k] ); /* Q15 */ - - Copy( &hTdCngDec->ho_lsp_hist_fx[ptr * M], &tmp[m * M], M ); /* Qx */ - IF( EQ_32( L_and( hTdCngDec->ho_sid_bw, L_shl( (Word32) 0x1, k ) ), 0 ) ) - { - Copy32( &hTdCngDec->ho_env_hist_fx[ptr * NUM_ENV_CNG], &tmp_env[m1 * NUM_ENV_CNG], NUM_ENV_CNG ); /* Qx */ - m1++; - } - m++; - } - } - - /*enr /= weights;*/ - exp = norm_s( weights ); - tmp1 = div_s( shl( 1, sub( 14, exp ) ), weights ); /* Q(15+14-exp-15) */ - L_tmp1 = Mult_32_16( L_enr, tmp1 ); /* Q(14-exp+6-15)->Q(5-exp) */ - L_enr = L_shl( L_tmp1, add( exp, 1 ) ); /* Q6 */ - - st_fx->lp_ener_fx = L_enr; /* Q6 */ - move32(); - set32_fx( max_val, 0, 2 ); - set16_fx( max_idx, 0, 2 ); - - FOR( i = 0; i < m; i++ ) - { - IF( EQ_16( st_fx->L_frame, L_FRAME ) ) - { - lsp2lsf_fx( &tmp[i * M], lsf_tmp, M, INT_FS_FX ); - ftmp_fx = 964; - move16(); /*X2.56 */ - tmpv = sub( 16384, add( lsf_tmp[M - 1], ftmp_fx ) ); /*QX2.56*/ - L_tmp = L_mult0( tmpv, tmpv ); /*QX6.5536*/ - } - ELSE - { - lsp2lsf_fx( &tmp[i * M], lsf_tmp, M, INT_FS_16k_FX ); - ftmp_fx = 1205; - move16(); /*QX2.56*/ - tmpv = sub( 20480, add( lsf_tmp[M - 1], ftmp_fx ) ); /*QX2.56*/ - L_tmp = L_mult0( tmpv, tmpv ); /*QX6.5536*/ - } - - tmpv = sub( lsf_tmp[0], ftmp_fx ); /*QX2.56*/ - L_tmp = L_mac0( L_tmp, tmpv, tmpv ); /*QX6.5536*/ - FOR( j = 0; j < M - 1; j++ ) - { - tmpv = sub( sub( lsf_tmp[j + 1], lsf_tmp[j] ), ftmp_fx ); /*QX2.56*/ - L_tmp = L_mac0( L_tmp, tmpv, tmpv ); /*QX6.5536*/ - } - - C[i] = Mpy_32_16_1( L_tmp, 1928 ); /*QX6.5536*/ - move32(); - - IF( GT_32( C[i], max_val[0] ) ) - { - max_val[1] = max_val[0]; - move32(); - max_idx[1] = max_idx[0]; - move16(); - max_val[0] = C[i]; - move32(); - max_idx[0] = i; - move16(); - } - ELSE IF( GT_32( C[i], max_val[1] ) ) - { - max_val[1] = C[i]; - move32(); - max_idx[1] = i; - move16(); - } - } - - IF( EQ_16( m, 1 ) ) - { - Copy( tmp, lsp_tmp, M ); /* Qx */ - } - ELSE IF( LT_16( m, 4 ) ) - { - FOR( i = 0; i < M; i++ ) - { - L_tmp1 = 0; - move32(); - FOR( j = 0; j < m; j++ ) - { - L_tmp1 = L_add( L_tmp1, L_deposit_l( tmp[j * M + i] ) ); - } - - L_tmp1 = L_sub( L_tmp1, L_deposit_l( tmp[max_idx[0] * M + i] ) ); - tmpv = div_s( 1, sub( m, 1 ) ); /*Q15*/ - L_tmp1 = Mpy_32_16_1( L_tmp1, tmpv ); /*Q15*/ - lsp_tmp[i] = extract_l( L_tmp1 ); /*Q15*/ - move16(); - } - } - ELSE - { - FOR( i = 0; i < M; i++ ) - { - L_tmp1 = 0; - move32(); - FOR( j = 0; j < m; j++ ) - { - L_tmp1 = L_add( L_tmp1, L_deposit_l( tmp[j * M + i] ) ); - } - - L_tmp1 = L_sub( L_tmp1, L_add( L_deposit_l( tmp[max_idx[0] * M + i] ), L_deposit_l( tmp[max_idx[1] * M + i] ) ) ); /*Q15*/ - tmpv = div_s( 1, sub( m, 2 ) ); /*Q15*/ - L_tmp1 = Mpy_32_16_1( L_tmp1, tmpv ); /*Q15*/ - lsp_tmp[i] = extract_l( L_tmp1 ); /*Q15*/ - move16(); - } - } - - dist = 0; - move16(); /*Q15*/ - max_dev = 0; - move16(); /*Q15*/ - FOR( i = 0; i < M; i++ ) - { - dev = abs_s( sub( lsp_tmp[i], lsp_new[i] ) ); /*Q15*/ - dist = add_o( dist, dev, &Overflow ); /*Q15*/ - if ( GT_16( dev, max_dev ) ) - { - max_dev = dev; - move16(); - } - } - - test(); - IF( GT_16( dist, 13107 ) || GT_16( max_dev, 3277 ) ) /* 0.4 and 0.1 in Q15 */ - { - FOR( i = 0; i < M; i++ ) - { - st_fx->lspCNG_fx[i] = lsp_tmp[i]; - move16(); /*Q15*/ - } - } - ELSE - { - FOR( i = 0; i < M; i++ ) - { - /* AR low-pass filter */ - st_fx->lspCNG_fx[i] = add( mult_r( 26214, lsp_tmp[i] ), mult_r( 6554, lsp_new[i] ) ); /* Q15 */ - move16(); - } - } - IF( m1 > 0 ) - { - FOR( i = 0; i < NUM_ENV_CNG; i++ ) - { - L_tmp = L_deposit_l( 0 ); - FOR( j = 0; j < m1; j++ ) - { - /* env[i] += tmp_env[j*NUM_ENV_CNG+i];*/ - L_tmp = L_add_sat( L_tmp, tmp_env[j * NUM_ENV_CNG + i] ); - } - /* env[i] /= (float)m1; */ - /* env[i] = env[i] - 2*st_fx->lp_ener_fx; */ - IF( EQ_16( m1, 1 ) ) - { - L_tmp = L_sub_sat( L_tmp, L_add_sat( st_fx->lp_ener_fx, st_fx->lp_ener_fx ) ); /* Q6 */ - } - ELSE - { - tmp1 = div_s( 1, m1 ); - L_tmp = Mult_32_16( L_tmp, tmp1 ); /* Q6 */ - L_tmp = L_sub_sat( L_tmp, L_add_sat( st_fx->lp_ener_fx, st_fx->lp_ener_fx ) ); /* Q6 */ - } - env[i] = L_tmp; /* Q6 */ - move32(); - } - - Copy32( env, hTdCngDec->lp_env_fx, NUM_ENV_CNG ); /* Q6 */ - } - } - ELSE - { - Copy( lsp_new, st_fx->lspCNG_fx, M ); /* use newly analyzed ISFs */ /* Q15 */ - } - } - - test(); - IF( EQ_32( st_fx->core_brate, SID_1k75 ) || EQ_32( st_fx->core_brate, SID_2k40 ) ) - { - /* Update hangover memory during CNG */ - test(); - IF( ( *allow_cn_step == 0 ) && LT_32( hTdCngDec->Enew_fx, L_add_sat( st_fx->lp_ener_fx, L_shr( st_fx->lp_ener_fx, 1 ) ) ) ) - { - /* update the pointer to circular buffer of old LSP vectors */ - hTdCngDec->ho_hist_ptr++; - move16(); - if ( EQ_16( hTdCngDec->ho_hist_ptr, HO_HIST_SIZE ) ) - { - hTdCngDec->ho_hist_ptr = 0; - move16(); - } - - /* update the circular buffer of old LSP vectors with the new LSP vector */ - Copy( lsp_new, &( hTdCngDec->ho_lsp_hist_fx[( hTdCngDec->ho_hist_ptr ) * M] ), M ); /* Q15 */ - - /* update the hangover energy buffer */ - hTdCngDec->ho_ener_hist_fx[hTdCngDec->ho_hist_ptr] = hTdCngDec->Enew_fx; /* Q6 */ - move32(); - test(); - IF( EQ_32( st_fx->core_brate, SID_2k40 ) && ( *sid_bw == 0 ) ) - { - /* enr1 = (float)log10( st->Enew*L_frame + 0.1f ) / (float)log10( 2.0f );*/ - exp = norm_l( hTdCngDec->Enew_fx ); - L_tmp = L_shl( hTdCngDec->Enew_fx, exp ); /*Q(exp+6)*/ - L_tmp = Mult_32_16( L_tmp, shl( st_fx->L_frame, 5 ) ); /*Q(exp+6+5-15=exp-4)*/ - L_tmp = L_shr_sat( L_tmp, sub( exp, 10 ) ); /*Q6*/ - exp = norm_l( L_tmp ); - fra = Log2_norm_lc( L_shl( L_tmp, exp ) ); - exp = sub( sub( 30, exp ), 6 ); - L_tmp = L_Comp( exp, fra ); - enr1 = L_shr( L_tmp, 10 ); /* Q6 */ - - FOR( i = 0; i < NUM_ENV_CNG; i++ ) - { - /* get quantized envelope */ - /* env[i] = pow(2.0f,(enr1 - q_env[i])) + 2*st->Enew;*/ - L_tmp = L_sub( enr1, q_env[i] ); /* Q6 */ - L_tmp = L_shl( L_tmp, 10 ); /* 16 */ - temp_lo_fx = L_Extract_lc( L_tmp, &temp_hi_fx ); - - exp_pow = sub( 14, temp_hi_fx ); - L_tmp = Pow2( 14, temp_lo_fx ); /* Qexp_pow */ - env[i] = L_shl( L_tmp, sub( 6, exp_pow ) ); /* Q6 */ - move32(); - L_tmp = L_add( hTdCngDec->Enew_fx, hTdCngDec->Enew_fx ); - env[i] = L_add( env[i], L_tmp ); /* Q6 */ - move32(); - } - hTdCngDec->ho_sid_bw = L_shl( L_and( hTdCngDec->ho_sid_bw, (Word32) 0x3fffffffL ), 1 ); /* Q0 */ - move32(); - Copy32( env, &( hTdCngDec->ho_env_hist_fx[hTdCngDec->ho_hist_ptr * NUM_ENV_CNG] ), NUM_ENV_CNG ); /* Q6 */ - } - ELSE IF( ( *sid_bw != 0 ) ) - { - hTdCngDec->ho_sid_bw = L_shl( L_and( hTdCngDec->ho_sid_bw, (Word32) 0x3fffffffL ), 1 ); /* Q0 */ - move32(); - hTdCngDec->ho_sid_bw = L_or( hTdCngDec->ho_sid_bw, 0x1L ); /* Q0 */ - move32(); - } - - hTdCngDec->ho_hist_size = add( hTdCngDec->ho_hist_size, 1 ); - move16(); - if ( GT_16( hTdCngDec->ho_hist_size, HO_HIST_SIZE ) ) - { - hTdCngDec->ho_hist_size = HO_HIST_SIZE; - move16(); - } - } - /* Update the frame length memory */ - st_fx->last_CNG_L_frame = st_fx->L_frame; - move16(); - - if ( NE_32( st_fx->core_brate, SID_1k75 ) ) - { - hTdCngDec->num_ho = m; - move16(); - } - } - - IF( st_fx->element_mode == EVS_MONO ) - { - st_fx->last_CNG_L_frame = st_fx->L_frame; - move16(); - - IF( NE_32( st_fx->core_brate, SID_1k75 ) ) - { - hTdCngDec->num_ho = m; - move16(); - } - } - IF( st_fx->Opt_AMR_WB ) - { - E_LPC_f_isp_a_conversion( st_fx->lspCNG_fx, Aq, M ); - } - ELSE - { - E_LPC_f_lsp_a_conversion( st_fx->lspCNG_fx, Aq, M ); - } - - tmp_loop = shr( st_fx->L_frame, 6 ); - FOR( i = 1; i < tmp_loop; i++ ) /* L_frame/L_SUBFR */ - { - Copy( Aq, &Aq[i * ( M + 1 )], add( M, 1 ) ); /* Q12 */ - } - - return; -} -#endif -void CNG_dec_ivas_fx( - Decoder_State *st_fx, /* i/o: State structure */ - const Word16 last_element_mode, /* i : last element mode Q0 */ - Word16 Aq[], /* o : LP coefficients Q12 */ - Word16 *lsp_new, /* i/o: current frame LSPs Q15 */ - Word16 *lsf_new, /* i/o: current frame LSFs Qlog2(2.56) */ - Word16 *allow_cn_step, /* o : allow CN step Q0 */ - Word16 *sid_bw /* i : 0-NB/WB, 1-SWB SID Q0 */ - , - Word32 *q_env ) -{ - Word16 istep; - Word16 i, L_enr_index; - Word32 L_ener; - Word16 ener_fra, ener_int; - Word16 num_bits; - Word16 weights, ptr, j, k; - Word16 m1; - Word16 m = 0; - move16(); - Word16 tmp[HO_HIST_SIZE * M]; - Word16 burst_ho_cnt = 0; - move16(); - Word16 ll, s_ptr; - Word32 L_enr, L_tmp1; - Word16 tmp1, exp; - Word16 lsf_tmp[M]; - Word32 C[M]; - Word32 max_val[2]; - Word16 max_idx[2]; - Word16 ftmp_fx; - Word16 lsp_tmp[M]; - Word16 dev; - Word16 max_dev; - Word16 dist; - Word16 tmpv; - Word16 env_idx[2]; - Word32 enr1; - Word32 env[NUM_ENV_CNG]; - Word32 tmp_env[HO_HIST_SIZE * NUM_ENV_CNG]; - Word32 L_tmp; - Word16 fra; - Word16 temp_lo_fx, temp_hi_fx; - Word16 exp_pow; - Word16 tmp_loop; - Word16 enr_new, Aq_tmp[M + 1]; - - Word16 LSF_Q_prediction; /* o : LSF prediction mode - just temporary variable in CNG */ - TD_CNG_DEC_HANDLE hTdCngDec; -#ifdef BASOP_NOGLOB_DECLARE_LOCAL - Flag Overflow = 0; - move32(); -#endif - hTdCngDec = st_fx->hTdCngDec; - - m = 0; - move16(); - /*-----------------------------------------------------------------* - * Decode CNG spectral envelope (only in SID frame) - *-----------------------------------------------------------------*/ - test(); - IF( EQ_32( st_fx->core_brate, SID_1k75 ) || EQ_32( st_fx->core_brate, SID_2k40 ) ) - { - /* de-quantize the LSF vector */ - IF( st_fx->Opt_AMR_WB != 0 ) - { - /* Flt function */ - isf_dec_amr_wb_fx( st_fx, Aq, lsf_new, lsp_new ); - /* check IF ISPs may trigger too much synthesis energy */ - - E_LPC_f_isp_a_conversion( lsp_new, Aq_tmp, M ); - enr_new = Enr_1_Az_fx( Aq_tmp, 2 * L_SUBFR ); - - IF( ( shr( enr_new, 14 ) > 0 ) ) - { - /* Use old LSP vector */ - Copy( st_fx->lsp_old_fx, lsp_new, M ); /* Q15 */ - Copy( st_fx->lsf_old_fx, lsf_new, M ); /* Q2.56 */ - } - } - ELSE - { - lsf_dec_ivas_fx( st_fx, 0, Aq, &LSF_Q_prediction, lsf_new, lsp_new, 0, 0, - NULL ); /* check IF LSPs may trigger too much synthesis energy */ - E_LPC_f_lsp_a_conversion( lsp_new, Aq_tmp, M ); enr_new = Enr_1_Az_fx( Aq_tmp, 2 * L_SUBFR ); diff --git a/lib_dec/dec_LPD_fx.c b/lib_dec/dec_LPD_fx.c index c04ee9dc5..b638a36e5 100644 --- a/lib_dec/dec_LPD_fx.c +++ b/lib_dec/dec_LPD_fx.c @@ -556,11 +556,7 @@ void decoder_LPD_fx( move16(); } -#ifdef REMOVE_EVS_DUPLICATES int_lsp4_ivas_fx( L_frame, &lsp[0], lspmid, &lsp[M], Aq, M, st->relax_prev_lsf_interp ); -#else - int_lsp4_fx( L_frame, &lsp[0], lspmid, &lsp[M], Aq, M, st->relax_prev_lsf_interp ); -#endif } ELSE { diff --git a/lib_dec/dec_ace_fx.c b/lib_dec/dec_ace_fx.c index ad89ca556..9c366e3f3 100644 --- a/lib_dec/dec_ace_fx.c +++ b/lib_dec/dec_ace_fx.c @@ -532,27 +532,24 @@ void decoder_acelp_fx( move16(); IF( st->igf != 0 ) { -#ifdef REMOVE_EVS_DUPLICATES - prep_tbe_exc_ivas_fx( st->L_frame, L_SUBFR, i_subfr, gain_pit, gain_code, code, st->voice_fac, &voice_factors[idx], bwe_exc, - gain_preQ, code_preQ, st->Q_exc, T0, T0_frac, st->coder_type, st->core_brate, st->element_mode, st->idchan, st->hBWE_TD != NULL, 0 ); -#else - prep_tbe_exc_fx( st->L_frame, - i_subfr, gain_pit, gain_code, code, st->voice_fac, &voice_factors[idx], bwe_exc, - gain_preQ, code_preQ, st->Q_exc, T0, T0_frac, st->coder_type, st->core_brate ); -#endif + prep_tbe_exc_fx( st->L_frame, L_SUBFR, i_subfr, gain_pit, gain_code, code, st->voice_fac, &voice_factors[idx], bwe_exc, + gain_preQ, code_preQ, st->Q_exc, T0, T0_frac, st->coder_type, st->core_brate, st->element_mode, st->idchan, st->hBWE_TD != NULL, 0 ); } /*---------------------------------------------------------* * Enhance the excitation * *---------------------------------------------------------*/ + E_UTIL_enhancer( st->voice_fac, stab_fac, st->past_gcode, gain_inov, &( st->gc_threshold_fx ), code, &exc2[i_subfr], gain_pit, &st->dm_fx.prev_gain_code, st->dm_fx.prev_gain_pit, &st->dm_fx.prev_state, st->coder_type, acelp_cfg.fixed_cdk_index[idx], L_SUBFR, st->L_frame, st->Q_exc ); } /* !RF_NELP frame partial copy */ + /*----------------------------------------------------------* * - compute the synthesis speech * *----------------------------------------------------------*/ + rescale_mem( &st->Q_exc, &prev_Q_syn, &st->Q_syn, mem_syn, syn, M, i_subfr ); E_UTIL_synthesis( sub( st->Q_exc, st->Q_syn ), p_A, &exc2[i_subfr], &syn[i_subfr], L_SUBFR, mem_syn, 1, M ); @@ -678,16 +675,11 @@ void decoder_acelp_fx( move16(); } -#ifdef REMOVE_EVS_DUPLICATES - FEC_scale_syn_ivas_fx( st->L_frame, &update_flg, st->clas_dec, st->last_good, syn, pBuf_scaleSyn, st->enr_old_fx, 0, - st->coder_type, LSF_Q_prediction, &st->scaling_flag, &st->lp_ener_FEC_av, &st->lp_ener_FEC_max, st->bfi, st->total_brate, st->prev_bfi, st->last_core_brate, - exc, exc2, A, &( st->old_enr_LP ), mem_back, mem_syn, st->Q_exc, st->Q_syn, EVS_MONO, avoid_lpc_burst_on_recovery, force_scale_syn ); -#else FEC_scale_syn_fx( st->L_frame, &update_flg, st->clas_dec, st->last_good, syn, pBuf_scaleSyn, st->enr_old_fx, 0, st->coder_type, LSF_Q_prediction, &st->scaling_flag, &st->lp_ener_FEC_av, &st->lp_ener_FEC_max, st->bfi, st->total_brate, st->prev_bfi, st->last_core_brate, - exc, exc2, A, &( st->old_enr_LP ), mem_back, mem_syn, st->Q_exc, st->Q_syn, avoid_lpc_burst_on_recovery, force_scale_syn ); -#endif + exc, exc2, A, &( st->old_enr_LP ), mem_back, mem_syn, st->Q_exc, st->Q_syn, EVS_MONO, avoid_lpc_burst_on_recovery, force_scale_syn ); } + /* update ACELP synthesis memory */ Copy( mem_syn, st->mem_syn2_fx, M ); Copy( syn + st->L_frame - L_SYN_MEM, st->mem_syn_r, L_SYN_MEM ); diff --git a/lib_dec/dec_amr_wb_fx.c b/lib_dec/dec_amr_wb_fx.c index b03b6d69c..500fe34ba 100644 --- a/lib_dec/dec_amr_wb_fx.c +++ b/lib_dec/dec_amr_wb_fx.c @@ -71,11 +71,7 @@ void decod_amr_wb_fx( * Decode pitch lag *----------------------------------------------------------------------*/ -#ifdef REMOVE_EVS_DUPLICATES - *pt_pitch_fx = pit_decode_ivas_fx( st_fx, st_fx->core_brate, 1, L_FRAME, i_subfr, -1, &pitch_limit_flag, &T0, &T0_frac, &T0_min, &T0_max, L_SUBFR, 0, NULL ); -#else - *pt_pitch_fx = pit_decode_fx( st_fx, st_fx->core_brate, 1, L_FRAME, i_subfr, -1, &pitch_limit_flag, &T0, &T0_frac, &T0_min, &T0_max, L_SUBFR ); -#endif + *pt_pitch_fx = pit_decode_fx( st_fx, st_fx->core_brate, 1, L_FRAME, i_subfr, -1, &pitch_limit_flag, &T0, &T0_frac, &T0_min, &T0_max, L_SUBFR, 0, NULL ); /*--------------------------------------------------------------* * Find the adaptive codebook vector diff --git a/lib_dec/dec_gen_voic_fx.c b/lib_dec/dec_gen_voic_fx.c index 7411d59f2..3e42d9535 100644 --- a/lib_dec/dec_gen_voic_fx.c +++ b/lib_dec/dec_gen_voic_fx.c @@ -18,8 +18,7 @@ /*----------------------------------------------------------------------*/ /* GLOBAL INPUT ARGUMENTS : */ /* _ (Struct) st_fx : decoder static memory */ -/* _ (Word16) L_frame : length of the frame */ - +/* _ (Word16) L_frame : length of the frame */ /* _ (Word16[]) Aq_fx : LP filter coefficient Q12 */ /* _ (Word16) Es_pred_fx : predicted scaled innov. energy Q8 */ /* _ (Word16[]) pitch_buf_fx : floating pitch values for each subframe Q6*/ @@ -29,503 +28,30 @@ /* _ (Word16[]) exc_fx : adapt. excitation exc (Q_exc) */ /* _ (Word16[]) exc2_fx : adapt. excitation/total exc (Q_exc) */ /*----------------------------------------------------------------------*/ - - /*----------------------------------------------------------------------*/ /* RETURN ARGUMENTS : */ /* _ None */ /*======================================================================*/ -#ifndef REMOVE_EVS_DUPLICATES ivas_error decod_gen_voic_fx( - Decoder_State *st_fx, /* i/o: decoder static memory */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 sharpFlag_fx, /* i : formant sharpening flag */ - const Word16 *Aq_fx, /* i : LP filter coefficient Q12 */ - const Word16 Es_pred_fx, /* i : predicted scaled innov. energy Q8 */ - const Word16 do_WI_fx, /* i : do interpolation after a FER */ - Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe Q6 */ - Word16 *voice_factors_fx, /* o : voicing factors Q15 */ - Word16 *exc_fx, /* i/o: adapt. excitation exc Q_exc */ - Word16 *exc2_fx, /* i/o: adapt. excitation/total exc Q_exc */ - Word16 *bwe_exc_fx, /* o : excitation for SWB TBE Q_exc */ - Word16 *unbits, /* number of unused bits */ - Word16 *gain_buf /*Q14*/ -) -{ - - - Word16 T0_fx, T0_frac_fx, T0_min_fx, T0_max_fx; /* integer pitch variables */ - Word16 gain_pit_fx = 0; /* pitch gain Q14 */ - move16(); - Word32 gain_code_fx = 0; /* gain/normalized gain of the algebraic excitation Q16 */ - move32(); - Word32 norm_gain_code_fx = 0; /* normalized gain of the algebraic excitation Q16 */ - move32(); - Word16 gain_inov_fx = 0; /* Innovation gain Q12 */ - move16(); - Word32 gc_mem[NB_SUBFR - 1]; /* gain_code from previous subframes */ - Word16 gp_mem[NB_SUBFR - 1]; /* gain_pitch from previous subframes */ - Word16 voice_fac_fx; /* voicing factor Q15 */ - Word16 code_fx[L_SUBFR]; /* algebraic codevector Q12 */ - - const Word16 *p_Aq_fx; /* Pointer to frame LP coefficient Q12 */ - Word16 *pt_pitch_fx; /* pointer to floating pitch Q6 */ - Word16 i_subfr_fx, i; /* tmp variables */ - Word16 error_fx = 0; - move16(); - Word16 gain_preQ_fx = 0; /* Gain of prequantizer excitation */ - move16(); - Word16 code_preQ_fx[L_SUBFR]; /* Prequantizer excitation */ - Word32 norm_gain_preQ_fx; - Word16 pitch_limit_flag_fx; - - Word16 tmp1_fx, gain_code16; - Word32 L_tmp_GC; - Word32 L_tmp; - - Word16 harm_flag_acelp; - - Word16 shft_prev, ph_offset_fx; - Word32 prev_res_nrg; - Word32 prev_spch_nrg; - Word32 curr_res_nrg; - Word32 curr_spch_nrg; - Word16 rint_bfi_pitch, rint_pitch; - Word16 fraca, fracb, expa, expb, scale, exp1; - Word16 *p_exc; - Word16 mem_tmp_fx[M]; - Word16 syn_tmp_fx[L_FRAME16k]; - Word16 shft_curr; - Word16 *p_syn; - Word16 sp_enratio, Qsp_enratio; - Word16 enratio, Qenratio; - DTFS_STRUCTURE *PREVP, *CURRP; - Word16 S_fx[PIT_MAX * 4 + 1], C_fx[PIT_MAX * 4 + 1]; - Word16 dummy2[2]; - Word16 out_fx[L_FRAME16k]; - - Word16 pf_temp1[MAXLAG_WI]; /*may not need more than MAXLAG_WI/2+1 */ - Word16 pf_temp2[MAXLAG_WI]; - Word16 pf_temp[MAXLAG_WI]; - Word16 pf_n2[MAXLAG_WI]; - MUSIC_POSTFILT_HANDLE hMusicPF; -#ifdef BASOP_NOGLOB_DECLARE_LOCAL - Flag Overflow = 0; - move32(); -#endif - - hMusicPF = st_fx->hMusicPF; - - GSC_DEC_HANDLE hGSCDec; - hGSCDec = st_fx->hGSCDec; - ivas_error error; - - error = IVAS_ERR_OK; - move32(); - - T0_fx = PIT_MIN; - move16(); - T0_frac_fx = 0; - move16(); - - /* read harmonicity flag */ - harm_flag_acelp = 0; - move16(); - test(); - test(); - IF( ( GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) && LE_32( st_fx->core_brate, MAX_BRATE_AVQ_EXC_TD ) ) && EQ_16( st_fx->coder_type, GENERIC ) ) - { - harm_flag_acelp = (Word16) get_next_indice( st_fx, 1 ); - } - - /*------------------------------------------------------------------* - * ACELP subframe loop - *------------------------------------------------------------------*/ - - p_Aq_fx = Aq_fx; /* pointer to interpolated LPC parameters */ - pt_pitch_fx = pitch_buf_fx; /* pointer to the pitch buffer */ - norm_gain_preQ_fx = 0; - move32(); - gain_preQ_fx = 0; - move16(); - set16_fx( code_preQ_fx, 0, L_SUBFR ); - - FOR( i_subfr_fx = 0; i_subfr_fx < L_frame; i_subfr_fx += L_SUBFR ) - { - /*----------------------------------------------------------------------* - * Decode pitch lag - *----------------------------------------------------------------------*/ - - *pt_pitch_fx = pit_decode_fx( st_fx, st_fx->core_brate, 0, L_frame, i_subfr_fx, st_fx->coder_type, &pitch_limit_flag_fx, - &T0_fx, &T0_frac_fx, &T0_min_fx, &T0_max_fx, L_SUBFR ); - move16(); /*Q6*/ - - /*--------------------------------------------------------------* - * Find the adaptive codebook vector - *--------------------------------------------------------------*/ - - pred_lt4( &exc_fx[i_subfr_fx], &exc_fx[i_subfr_fx], T0_fx, T0_frac_fx, L_SUBFR + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); - - tbe_celp_exc( L_frame, i_subfr_fx, T0_fx, T0_frac_fx, &error_fx, bwe_exc_fx ); - - /*--------------------------------------------------------------* - * LP filtering of the adaptive excitation - *--------------------------------------------------------------*/ - lp_filt_exc_dec_fx( st_fx, MODE1, i_subfr_fx, L_SUBFR, L_frame, st_fx->acelp_cfg.ltf_mode, exc_fx ); - /*-----------------------------------------------------------------* - * Transform-domain contribution decoding (active frames) - *-----------------------------------------------------------------*/ - - test(); - IF( GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) && ( st_fx->coder_type != INACTIVE ) ) - { - gain_code_fx = 0; - move16(); - transf_cdbk_dec_fx( st_fx, harm_flag_acelp, i_subfr_fx, Es_pred_fx, gain_code_fx, &gain_preQ_fx, &norm_gain_preQ_fx, code_preQ_fx, unbits ); - } - - /*--------------------------------------------------------------* - * Innovation decoding - *--------------------------------------------------------------*/ - - inov_decode_fx( st_fx, st_fx->core_brate, 0, L_frame, sharpFlag_fx, i_subfr_fx, p_Aq_fx, st_fx->tilt_code_fx, *pt_pitch_fx, code_fx, L_SUBFR ); - - /*--------------------------------------------------------------* - * Gain decoding - * Estimate spectrum tilt and voicing - *--------------------------------------------------------------*/ - - IF( LE_32( st_fx->core_brate, ACELP_8k00 ) ) - { - gain_dec_lbr_fx( st_fx, st_fx->coder_type, i_subfr_fx, code_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx, gc_mem, gp_mem, L_SUBFR ); - } - ELSE IF( GT_32( st_fx->core_brate, ACELP_32k ) ) - { - gain_dec_SQ_fx( st_fx, i_subfr_fx, code_fx, Es_pred_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx ); - } - ELSE - { - gain_dec_mless_fx( st_fx, L_frame, st_fx->coder_type, i_subfr_fx, -1, code_fx, Es_pred_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx ); - } - st_fx->tilt_code_fx = est_tilt_fx( exc_fx + i_subfr_fx, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, st_fx->Q_exc ); // Q15 - move16(); - - /*-----------------------------------------------------------------* - * Transform domain contribution decoding - *-----------------------------------------------------------------*/ - test(); - IF( GE_32( st_fx->core_brate, MAX_GSC_INACTIVE_BRATE ) && ( st_fx->coder_type == INACTIVE ) ) - { - transf_cdbk_dec_fx( st_fx, harm_flag_acelp, i_subfr_fx, Es_pred_fx, gain_code_fx, &gain_preQ_fx, &norm_gain_preQ_fx, code_preQ_fx, unbits ); - } - - /* update LP filtered gains for the case of frame erasures */ - lp_gain_updt_fx( i_subfr_fx, gain_pit_fx, L_add( norm_gain_code_fx, norm_gain_preQ_fx ), &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, L_frame ); - - /*----------------------------------------------------------------------* - * Find the total excitation - *----------------------------------------------------------------------*/ - - IF( EQ_16( L_frame, L_FRAME ) ) /* Rescaling for 12.8k core */ - { - Rescale_exc( hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], &bwe_exc_fx[i_subfr_fx * HIBND_ACB_L_FAC], hGSCDec->last_exc_dct_in_fx, - L_SUBFR, L_SUBFR * HIBND_ACB_L_FAC, gain_code_fx, &( st_fx->Q_exc ), st_fx->Q_subfr, exc2_fx, i_subfr_fx, st_fx->coder_type ); - } - ELSE /* Rescaling for 16k core */ - { - - L_tmp_GC = L_max( gain_code_fx, L_shl( gain_preQ_fx, 16 ) ); /* Chose the maximum of gain_code or the prequantizer excitation x4 to keep some room*/ - Rescale_exc( hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], &bwe_exc_fx[i_subfr_fx * 2], hGSCDec->last_exc_dct_in_fx, - L_SUBFR, L_SUBFR * 2, L_tmp_GC, &( st_fx->Q_exc ), st_fx->Q_subfr, exc2_fx, i_subfr_fx, st_fx->coder_type ); - } - - gain_code16 = round_fx( L_shl( gain_code_fx, st_fx->Q_exc ) ); /*Q_exc*/ - - /*-----------------------------------------------------------------* - * Add the ACELP pre-quantizer contribution - *-----------------------------------------------------------------*/ - - IF( gain_preQ_fx != 0 ) - { - IF( st_fx->element_mode == EVS_MONO ) - { - tmp1_fx = add( 15 - Q_AVQ_OUT_DEC - 2, st_fx->Q_exc ); - } - ELSE - { - tmp1_fx = add( 15 - Q_AVQ_OUT - 2, st_fx->Q_exc ); - } - FOR( i = 0; i < L_SUBFR; i++ ) - { - Word32 Ltmp1; - /* Contribution from AVQ layer */ - Ltmp1 = L_mult( gain_preQ_fx, code_preQ_fx[i] ); /* Q2 + Q6 -> Q9*/ - Ltmp1 = L_shl_sat( Ltmp1, tmp1_fx ); /* Q16 + Q_exc */ - - /* Compute exc2 */ - L_tmp = L_shl_sat( L_mult( gain_pit_fx, exc_fx[i + i_subfr_fx] ), 1 ); // Q_exc+Q14+1+1 - exc2_fx[i + i_subfr_fx] = round_fx_sat( L_add_sat( L_tmp, Ltmp1 ) ); // Q_exc - move16(); - /* gain_pit in Q14 */ - L_tmp = L_mult( gain_code16, code_fx[i] ); // Q_exc+Q9+1 - L_tmp = L_shl_sat( L_tmp, 5 ); // Q_exc+Q9+1+5 - L_tmp = L_mac_sat( L_tmp, exc_fx[i + i_subfr_fx], gain_pit_fx ); // Q_exc+Q15 +1 - L_tmp = L_shl_sat( L_tmp, 1 ); /* saturation can occur here */ - - exc_fx[i + i_subfr_fx] = round_fx_sat( L_add_sat( L_tmp, Ltmp1 ) ); // Q_exc - move16(); - } - } - ELSE - { - Acelp_dec_total_exc( exc_fx, exc2_fx, gain_code16, gain_pit_fx, i_subfr_fx, code_fx, L_SUBFR ); - } - - /*-----------------------------------------------------------------* - * Prepare TBE excitation - *-----------------------------------------------------------------*/ - - Word16 idx = 0; - move16(); - IF( i_subfr_fx != 0 ) - { - idx = idiv1616( i_subfr_fx, L_SUBFR ); - } - - prep_tbe_exc_fx( L_frame, i_subfr_fx, gain_pit_fx, gain_code_fx, code_fx, voice_fac_fx, - &voice_factors_fx[idx], bwe_exc_fx, gain_preQ_fx, code_preQ_fx, - st_fx->Q_exc, T0_fx, T0_frac_fx, st_fx->coder_type, st_fx->core_brate ); - - - /*----------------------------------------------------------------* - * Excitation enhancements (update of total excitation signal) - *----------------------------------------------------------------*/ - - test(); - IF( GT_32( st_fx->core_brate, ACELP_32k ) || ( st_fx->coder_type == INACTIVE ) ) - { - Copy( exc_fx + i_subfr_fx, exc2_fx + i_subfr_fx, L_SUBFR ); - } - ELSE - { - enhancer_fx( st_fx->core_brate, 0, st_fx->coder_type, i_subfr_fx, L_frame, voice_fac_fx, st_fx->stab_fac_fx, - norm_gain_code_fx, gain_inov_fx, &st_fx->gc_threshold_fx, code_fx, exc2_fx, gain_pit_fx, &( st_fx->dm_fx ), st_fx->Q_exc ); - } - - p_Aq_fx += ( M + 1 ); - pt_pitch_fx++; - gain_buf[idx] = gain_pit_fx; // Q14 - move16(); - } - - /* FEC fast recovery */ - - IF( do_WI_fx ) - { - /* shft_prev = L_EXC_MEM - rint_new_fx(st_fx->bfi_pitch_fx);*/ - L_tmp = L_shl( L_deposit_l( st_fx->bfi_pitch_fx ), 10 ); /*Q16*/ - rint_bfi_pitch = rint_new_fx( L_tmp ); /*Q0*/ - shft_prev = sub( L_EXC_MEM, rint_bfi_pitch ); /*Q0*/ - - p_exc = st_fx->hWIDec->old_exc2_fx + shft_prev; - p_syn = st_fx->hWIDec->old_syn2_fx + shft_prev; - move16(); - move16(); - - prev_res_nrg = L_deposit_l( 1 ); - prev_spch_nrg = L_deposit_l( 1 ); - FOR( i = 0; i < rint_bfi_pitch; i++ ) - { - prev_res_nrg = L_mac0_sat( prev_res_nrg, *p_exc, *p_exc ); /* 2*st_fx->prev_Q_exc_fr */ - prev_spch_nrg = L_mac0_sat( prev_spch_nrg, *p_syn, *p_syn ); /* 2*st_fx->prev_Q_syn_fr */ - p_exc++; - p_syn++; - } - - Copy( st_fx->mem_syn2_fx, mem_tmp_fx, M ); - - syn_12k8_fx( st_fx->L_frame, Aq_fx, exc2_fx, syn_tmp_fx, mem_tmp_fx, 1, st_fx->Q_exc, st_fx->Q_syn ); - - L_tmp = L_shl( L_deposit_l( pitch_buf_fx[NB_SUBFR16k - 1] ), 10 ); /*Q16*/ - rint_pitch = rint_new_fx( L_tmp ); /*Q0*/ - shft_curr = sub( st_fx->L_frame, rint_pitch ); /*Q0*/ - - p_exc = exc2_fx + shft_curr; - p_syn = syn_tmp_fx + shft_curr; - - curr_res_nrg = L_deposit_l( 1 ); - curr_spch_nrg = L_deposit_l( 1 ); - FOR( i = 0; i < rint_pitch; i++ ) - { - curr_res_nrg = L_mac0_sat( curr_res_nrg, *p_exc, *p_exc ); /* 2*st_fx->Q_exc */ - curr_spch_nrg = L_mac0_sat( curr_spch_nrg, *p_syn, *p_syn ); /* 2*st_fx->Q_syn */ - p_exc++; - p_syn++; - } - - /* enratio = (curr_res_nrg / prev_res_nrg); */ - IF( prev_res_nrg > 0 ) - { - expa = norm_l( prev_res_nrg ); - fraca = extract_h( L_shl( prev_res_nrg, expa ) ); /* 2*st_fx->prev_Q_exc_fr -16+expa +1*/ - expa = sub( 30, add( expa, ( shl( st_fx->prev_Q_exc_fr, 1 ) ) ) ); - - expb = norm_l( curr_res_nrg ); - fracb = round_fx_sat( L_shl_sat( curr_res_nrg, expb ) ); /* 2*st_fx->Q_exc +expb+1 -16*/ - expb = sub( 30, add( expb, shl( st_fx->Q_exc, 1 ) ) ); - - scale = shr( sub( fraca, fracb ), 15 ); - fracb = shl( fracb, scale ); // Q(15-expb)+scale - expb = sub( expb, scale ); - - enratio = div_s( fracb, fraca ); // Q(15-(expb-expa)) - exp1 = sub( expb, expa ); - Qenratio = sub( 15, exp1 ); - } - ELSE - { - enratio = 0; - move16(); - Qenratio = 0; - move16(); - } - - /* sp_enratio = curr_spch_nrg/prev_spch_nrg */ - IF( prev_spch_nrg > 0 ) - { - expa = norm_l( prev_spch_nrg ); - fraca = extract_h( L_shl( prev_spch_nrg, expa ) ); /* 2*st_fx->prev_Q_syn_fr +expa+1-16*/ - expa = sub( 30, add( expa, shl( st_fx->prev_Q_syn_fr, 1 ) ) ); - - expb = norm_l( curr_spch_nrg ); - fracb = round_fx_sat( L_shl_sat( curr_spch_nrg, expb ) ); /* 2*st_fx->Q_syn +expb-16 */ - expb = sub( 30, add( expb, shl( st_fx->Q_syn, 1 ) ) ); - - scale = shr( sub( fraca, fracb ), 15 ); - fracb = shl( fracb, scale ); // Q(15-expb) +scale - expb = sub( expb, scale ); - - sp_enratio = div_s( fracb, fraca ); // Q(15-(expb-expa)) - exp1 = sub( expb, expa ); - Qsp_enratio = sub( 15, exp1 ); - } - ELSE - { - sp_enratio = 0; - move16(); - Qsp_enratio = 0; - move16(); - } - - test(); - test(); - test(); - test(); - IF( GT_16( shl_ro( enratio, sub( 15, Qenratio ), &Overflow ), 8192 ) && /*compare with 0.25 in Q15*/ - LT_16( shl_ro( enratio, sub( 10, Qenratio ), &Overflow ), 15360 ) && /*compare with 15.0 in Q10*/ - GT_16( shl_ro( sp_enratio, sub( 15, Qsp_enratio ), &Overflow ), 4915 ) && /*compare with 0.15 in Q15*/ - LT_16( st_fx->bfi_pitch_fx, 9600 ) && /*Q6*/ - LT_16( pitch_buf_fx[NB_SUBFR16k - 1], 9600 ) ) /*Q6*/ - { - IF( NE_32( ( error = DTFS_new_fx( &PREVP ) ), IVAS_ERR_OK ) ) - { - return error; - } - - IF( NE_32( ( error = DTFS_new_fx( &CURRP ) ), IVAS_ERR_OK ) ) - { - return error; - } - - GetSinCosTab_fx( rint_bfi_pitch, S_fx, C_fx ); - DTFS_to_fs_fx( st_fx->hWIDec->old_exc2_fx + shft_prev, rint_bfi_pitch, PREVP, (Word16) st_fx->output_Fs, do_WI_fx, S_fx, C_fx ); - PREVP->Q = add( PREVP->Q, st_fx->prev_Q_exc_fr ); - move16(); - - GetSinCosTab_fx( rint_pitch, S_fx, C_fx ); - DTFS_to_fs_fx( exc2_fx + shft_curr, rint_pitch, CURRP, (Word16) st_fx->output_Fs, do_WI_fx, S_fx, C_fx ); - CURRP->Q = add( CURRP->Q, st_fx->Q_exc ); - move16(); - - ph_offset_fx = 0; - move16(); - IF( NE_32( ( error = WIsyn_fx( *PREVP, CURRP, dummy2, &( ph_offset_fx ), out_fx, (Word16) st_fx->L_frame, 1, S_fx, C_fx, pf_temp1, pf_temp2, pf_temp, pf_n2 ) ), IVAS_ERR_OK ) ) - { - return error; - } - - - Copy_Scale_sig( out_fx, exc2_fx, st_fx->L_frame, st_fx->Q_exc ); // Q_exc - Copy_Scale_sig( out_fx, exc_fx, st_fx->L_frame, st_fx->Q_exc ); // Q_exc - - /* update bwe_exc for SWB-TBE */ - FOR( i_subfr_fx = 0; i_subfr_fx < L_frame; i_subfr_fx += L_SUBFR ) - { - interp_code_4over2_fx( exc_fx + i_subfr_fx, bwe_exc_fx + shl( i_subfr_fx, 1 ), L_SUBFR ); - } - - free( PREVP ); - free( CURRP ); - } - } - - /* SC-VBR */ - st_fx->prev_gain_pit_dec_fx = gain_pit_fx; - move16(); /*Q14*/ - st_fx->prev_tilt_code_dec_fx = st_fx->tilt_code_fx; - move16(); /*Q15*/ - - return error; -} - -/*======================================================================*/ -/* FUNCTION : decod_gen_voic_ivas_fx() */ -/*----------------------------------------------------------------------*/ -/* PURPOSE : Decode generic (GC), voiced (VC) and AMR-WB IO frames */ -/* */ -/*----------------------------------------------------------------------*/ -/* GLOBAL INPUT ARGUMENTS : */ -/* _ (Struct) st_fx : decoder static memory */ -/* _ (Word16) L_frame : length of the frame */ - -/* _ (Word16[]) Aq_fx : LP filter coefficient Q12 */ -/* _ (Word16) Es_pred_fx : predicted scaled innov. energy Q8 */ -/* _ (Word16[]) pitch_buf_fx : floating pitch values for each subframe Q6*/ -/* _ (Word16[]) voice_factors_fx: frame error rate Q15 */ -/*----------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16[]) exc_fx : adapt. excitation exc (Q_exc) */ -/* _ (Word16[]) exc2_fx : adapt. excitation/total exc (Q_exc) */ -/*----------------------------------------------------------------------*/ - - -/*----------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*======================================================================*/ -#endif -ivas_error decod_gen_voic_ivas_fx( - Decoder_State *st_fx, /* i/o: decoder static memory */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 sharpFlag_fx, /* i : formant sharpening flag */ - const Word16 *Aq_fx, /* i : LP filter coefficient Q12*/ - const Word16 Es_pred_fx, /* i : predicted scaled innov. energy Q8 */ - const Word16 do_WI_fx, /* i : do interpolation after a FER */ - Word16 *pitch_buf_fx, /* o : Word16 pitch values for each subframe Q6*/ - Word16 *voice_factors_fx, /* o : voicing factors Q15 */ - Word16 *exc_fx, /* i/o: adapt. excitation exc Q_exc */ - Word16 *exc2_fx, /* i/o: adapt. excitation/total exc Q_exc */ - Word16 *bwe_exc_fx, /* o : excitation for SWB TBE Q_exc */ - Word16 *unbits, /* number of unused bits */ - Word16 *gain_buf, - const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ - const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer Q6 */ + Decoder_State *st_fx, /* i/o: decoder static memory */ + const Word16 L_frame, /* i : length of the frame */ + const Word16 sharpFlag_fx, /* i : formant sharpening flag */ + const Word16 *Aq_fx, /* i : LP filter coefficient Q12 */ + const Word16 Es_pred_fx, /* i : predicted scaled innov. energy Q8 */ + const Word16 do_WI_fx, /* i : do interpolation after a FER */ + Word16 *pitch_buf_fx, /* o : Word16 pitch values for each subframe Q6 */ + Word16 *voice_factors_fx, /* o : voicing factors Q15 */ + Word16 *exc_fx, /* i/o: adapt. excitation exc Q_exc */ + Word16 *exc2_fx, /* i/o: adapt. excitation/total exc Q_exc */ + Word16 *bwe_exc_fx, /* o : excitation for SWB TBE Q_exc */ + Word16 *unbits, /* number of unused bits */ + Word16 *gain_buf, /* o : Word16 pitch gain for each subframe Q14 */ + const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ + const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer Q6 */ ) { - - - Word16 T0_fx, T0_frac_fx, T0_min_fx, T0_max_fx; /* integer pitch variables */ + Word16 T0_fx, T0_frac_fx, T0_min_fx, T0_max_fx; /* integer pitch variables */ Word16 gain_pit_fx; /* pitch gain Q14 */ Word32 gain_code_fx; /* gain/normalized gain of the algebraic excitation Q16 */ Word32 norm_gain_code_fx; /* normalized gain of the algebraic excitation Q16 */ @@ -536,7 +62,7 @@ ivas_error decod_gen_voic_ivas_fx( Word16 code_fx[L_SUBFR]; /* algebraic codevector Q12 */ const Word16 *p_Aq_fx; /* Pointer to frame LP coefficient Q12 */ - Word16 *pt_pitch_fx; /* pointer to Word16 pitch Q6 */ + Word16 *pt_pitch_fx; /* pointer to Word16 pitch Q6 */ Word16 i_subfr_fx, i; /* tmp variables */ Word16 error_fx; Word16 gain_preQ_fx; /* Gain of prequantizer excitation */ @@ -633,10 +159,8 @@ ivas_error decod_gen_voic_ivas_fx( * Decode pitch lag *----------------------------------------------------------------------*/ - /**pt_pitch_fx = pit_decode_fx(st_fx, st_fx->core_brate, 0, L_frame, i_subfr_fx, st_fx->coder_type, &pitch_limit_flag_fx, - &T0_fx, &T0_frac_fx, &T0_min_fx, &T0_max_fx, L_SUBFR);*/ - *pt_pitch_fx = pit_decode_ivas_fx( st_fx, st_fx->core_brate, 0, L_frame, i_subfr_fx, st_fx->coder_type, &pitch_limit_flag_fx, - &T0_fx, &T0_frac_fx, &T0_min_fx, &T0_max_fx, L_SUBFR, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf ); + *pt_pitch_fx = pit_decode_fx( st_fx, st_fx->core_brate, 0, L_frame, i_subfr_fx, st_fx->coder_type, &pitch_limit_flag_fx, + &T0_fx, &T0_frac_fx, &T0_min_fx, &T0_max_fx, L_SUBFR, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf ); move16(); /*Q6*/ /*--------------------------------------------------------------* @@ -677,7 +201,7 @@ ivas_error decod_gen_voic_ivas_fx( IF( LE_32( st_fx->core_brate, ACELP_8k00 ) ) { - gain_dec_lbr_ivas_fx( st_fx, st_fx->coder_type, i_subfr_fx, code_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx, gc_mem, gp_mem, L_SUBFR ); + gain_dec_lbr_fx( st_fx, st_fx->coder_type, i_subfr_fx, code_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx, gc_mem, gp_mem, L_SUBFR ); } ELSE IF( GT_32( st_fx->core_brate, ACELP_32k ) ) { @@ -700,13 +224,11 @@ ivas_error decod_gen_voic_ivas_fx( } /* update LP filtered gains for the case of frame erasures */ -#ifdef REMOVE_EVS_DUPLICATES IF( EQ_16( st_fx->element_mode, EVS_MONO ) ) { lp_gain_updt_fx( i_subfr_fx, gain_pit_fx, L_add( norm_gain_code_fx, norm_gain_preQ_fx ), &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, L_frame ); } ELSE -#endif { lp_gain_updt_ivas_fx( i_subfr_fx, gain_pit_fx, L_add( norm_gain_code_fx, norm_gain_preQ_fx ), &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, L_frame ); } @@ -790,10 +312,6 @@ ivas_error decod_gen_voic_ivas_fx( * Prepare TBE excitation *-----------------------------------------------------------------*/ - /*prep_tbe_exc_fx(L_frame, i_subfr_fx, gain_pit_fx, gain_code_fx, code_fx, voice_fac_fx, - &voice_factors_fx[i_subfr_fx / L_SUBFR], bwe_exc_fx, gain_preQ_fx, code_preQ_fx, - st_fx->Q_exc, T0_fx, T0_frac_fx, st_fx->coder_type, st_fx->core_brate);*/ - Word16 idx; idx = 0; move16(); @@ -802,10 +320,10 @@ ivas_error decod_gen_voic_ivas_fx( idx = idiv1616( i_subfr_fx, L_SUBFR ); } - prep_tbe_exc_ivas_fx( L_frame, L_SUBFR, i_subfr_fx, gain_pit_fx, gain_code_fx, code_fx, voice_fac_fx, - &voice_factors_fx[idx], bwe_exc_fx, gain_preQ_fx, code_preQ_fx, - st_fx->Q_exc, T0_fx, T0_frac_fx, st_fx->coder_type, st_fx->core_brate, - st_fx->element_mode, st_fx->idchan, st_fx->hBWE_TD != NULL, st_fx->tdm_LRTD_flag ); + prep_tbe_exc_fx( L_frame, L_SUBFR, i_subfr_fx, gain_pit_fx, gain_code_fx, code_fx, voice_fac_fx, + &voice_factors_fx[idx], bwe_exc_fx, gain_preQ_fx, code_preQ_fx, + st_fx->Q_exc, T0_fx, T0_frac_fx, st_fx->coder_type, st_fx->core_brate, + st_fx->element_mode, st_fx->idchan, st_fx->hBWE_TD != NULL, st_fx->tdm_LRTD_flag ); /*----------------------------------------------------------------* @@ -819,14 +337,12 @@ ivas_error decod_gen_voic_ivas_fx( } ELSE { -#ifdef REMOVE_EVS_DUPLICATES IF( EQ_16( st_fx->element_mode, EVS_MONO ) ) { enhancer_fx( st_fx->core_brate, 0, st_fx->coder_type, i_subfr_fx, L_frame, voice_fac_fx, st_fx->stab_fac_fx, norm_gain_code_fx, gain_inov_fx, &st_fx->gc_threshold_fx, code_fx, exc2_fx, gain_pit_fx, &( st_fx->dm_fx ), st_fx->Q_exc ); } ELSE -#endif { enhancer_ivas_fx2( st_fx->core_brate, 0, st_fx->coder_type, i_subfr_fx, L_frame, voice_fac_fx, st_fx->stab_fac_fx, norm_gain_code_fx, gain_inov_fx, &st_fx->gc_threshold_fx, code_fx, exc2_fx, gain_pit_fx, &( st_fx->dm_fx ), st_fx->Q_exc ); diff --git a/lib_dec/dec_pit_exc_fx.c b/lib_dec/dec_pit_exc_fx.c index fe7d2daaf..a18029cdc 100644 --- a/lib_dec/dec_pit_exc_fx.c +++ b/lib_dec/dec_pit_exc_fx.c @@ -14,13 +14,13 @@ /*--------------------------------------------------------------------------*/ /* INPUT ARGUMENTS : */ /* _ (Word16*) Aq_fx : LP filter coefficient Q12 */ -/* _ (Word16) coder_type : coding type Q0 */ +/* _ (Word16) coder_type : coding type Q0 */ /* _ (Word16) nb_subfr_fx :Number of subframe considered */ /* _ (Word16) Es_pred_fx :predicted scaled innov. energy */ /*--------------------------------------------------------------------------*/ /* OUTPUT ARGUMENTS : */ /* _ (Word16*) pitch_buf_fx : floating pitch values for each subframe Q6 */ -/* _ (Word16*) code_fx : innovation Q12 */ +/* _ (Word16*) code_fx : innovation Q12 */ /*--------------------------------------------------------------------------*/ /* INPUT/OUTPUT ARGUMENTS : */ /* Decoder_State_fx *st_fx : decoder state structure */ @@ -30,438 +30,29 @@ /* _ None */ /*==========================================================================*/ -#ifndef REMOVE_EVS_DUPLICATES void dec_pit_exc_fx( - Decoder_State *st_fx, /* i/o: decoder static memory */ - const Word16 *Aq_fx, /* i : LP filter coefficient */ - const Word16 coder_type, /* i : coding type */ - const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ - Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe */ - Word16 *code_fx, /* o : innovation */ - Word16 *exc_fx, /* i/o: adapt. excitation exc */ - Word16 *bwe_exc_fx, /* o : excitation for SWB TBE */ - const Word16 nb_subfr_fx /* i : Number of subframe considered */ - , - Word16 *gain_buf /*Q14*/ -) -{ - Word16 T0_fx, T0_frac_fx, T0_min_fx, T0_max_fx; /* integer pitch variables */ - Word16 gain_pit_fx; /* pitch gain Q14 */ - Word32 gain_code_fx; /* gain/normalized gain of the algebraic excitation Q16 */ - Word32 norm_gain_code_fx; /* normalized gain of the algebraic excitation Q16 */ - Word16 gain_inov_fx; /* Innovation gain Q12 */ - Word16 voice_fac_fx; /* voicing factor Q15 */ - Word16 L_subfr_fx, pit_idx_fx; - const Word16 *p_Aq_fx; /* Pointer to frame LP coefficient Q12 */ - Word16 *pt_pitch_fx; /* pointer to floating pitch Q6 */ - Word16 i_subfr_fx, i; /* tmp variables */ - Word32 Local_BR_fx, Pitch_BR_fx; - Word16 pitch_limit_flag, Pitch_CT_fx; - Word16 exc2_bidon[L_SUBFR]; - Word16 *pt_gain; /* Pointer to floating gain values for each subframe */ - - Word16 gain_code16, gain_pitx2; - Word32 L_tmp; - Word16 nbits; - GSC_DEC_HANDLE hGSCDec; - gain_pit_fx = 0; - move16(); - hGSCDec = st_fx->hGSCDec; - - MUSIC_POSTFILT_HANDLE hMusicPF; - hMusicPF = st_fx->hMusicPF; - - Word16 use_fcb; - Word32 gc_mem[NB_SUBFR - 1]; /* gain_code from previous subframes */ - Word16 gp_mem[NB_SUBFR - 1]; /* gain_pitch from previous subframes */ -#ifdef BASOP_NOGLOB_DECLARE_LOCAL - Flag Overflow = 0; - move16(); -#endif - - use_fcb = 0; - move16(); - test(); - test(); - IF( ( st_fx->GSC_IVAS_mode > 0 ) && ( EQ_16( st_fx->GSC_noisy_speech, 1 ) || GT_32( st_fx->core_brate, GSC_H_RATE_STG ) ) ) - { - Local_BR_fx = ACELP_8k00; - Pitch_CT_fx = GENERIC; - Pitch_BR_fx = ACELP_8k00; - move32(); - move32(); - move16(); - IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) - { - Local_BR_fx = ACELP_14k80; - move32(); - if ( st_fx->GSC_IVAS_mode > 0 ) - { - Local_BR_fx = ACELP_9k60; - move32(); - } - Pitch_BR_fx = st_fx->core_brate; - move32(); - } - } - ELSE IF( EQ_16( st_fx->GSC_noisy_speech, 1 ) ) - { - Local_BR_fx = ACELP_7k20; - move32(); - Pitch_CT_fx = GENERIC; - move16(); - Pitch_BR_fx = ACELP_7k20; - move32(); - if ( EQ_16( st_fx->L_frame, L_FRAME16k ) ) - { - Pitch_BR_fx = st_fx->core_brate; - move32(); - } - } - ELSE - { - Local_BR_fx = ACELP_7k20; - move32(); - Pitch_CT_fx = AUDIO; - move16(); - Pitch_BR_fx = st_fx->core_brate; - move32(); - IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) - { - Pitch_BR_fx = ACELP_13k20; - move32(); - Pitch_CT_fx = GENERIC; - move16(); - } - } - L_subfr_fx = mult_r( st_fx->L_frame, div_s( 1, nb_subfr_fx ) ); /* TV2Opt : this could be less complex with 2 ifs*/ - - - gain_code_fx = 0; - move16(); - pitch_limit_flag = 1; - move16(); /* always extended pitch Q range */ - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( ( GE_32( st_fx->core_brate, MIN_RATE_FCB ) || ( EQ_16( st_fx->GSC_noisy_speech, 1 ) && ( ( EQ_16( st_fx->L_frame, L_FRAME ) && GE_32( st_fx->core_brate, ACELP_13k20 ) ) || ( EQ_16( st_fx->L_frame, L_FRAME16k ) && GE_32( st_fx->core_brate, GSC_H_RATE_STG ) ) || st_fx->GSC_IVAS_mode == 0 ) ) ) && EQ_16( L_subfr_fx, L_SUBFR ) ) ) - { - use_fcb = 1; - move16(); - } - ELSE IF( ( st_fx->GSC_IVAS_mode > 0 ) && EQ_16( L_subfr_fx, 2 * L_SUBFR ) && LT_16( st_fx->GSC_IVAS_mode, 3 ) ) - { - use_fcb = 2; - st_fx->acelp_cfg.fcb_mode = 1; - move16(); - move16(); - set16_fx( st_fx->acelp_cfg.gains_mode, 6, 4 ); - set16_fx( st_fx->acelp_cfg.pitch_bits, 9, 4 ); - set16_fx( st_fx->acelp_cfg.fixed_cdk_index, 14, 5 ); - } - /*------------------------------------------------------------------* - * ACELP subframe loop - *------------------------------------------------------------------*/ - p_Aq_fx = Aq_fx; /* pointer to interpolated LPC parameters */ - pt_pitch_fx = pitch_buf_fx; /* pointer to the pitch buffer */ - pt_gain = gain_buf; /* pointer to the gain buffer */ - FOR( i_subfr_fx = 0; i_subfr_fx < st_fx->L_frame; i_subfr_fx += L_subfr_fx ) - { - /*----------------------------------------------------------------------* - * Decode pitch lag - *----------------------------------------------------------------------*/ - *pt_pitch_fx = pit_decode_fx( st_fx, Pitch_BR_fx, 0, st_fx->L_frame, i_subfr_fx, Pitch_CT_fx, &pitch_limit_flag, &T0_fx, &T0_frac_fx, &T0_min_fx, &T0_max_fx, L_subfr_fx ); - move16(); - - /*--------------------------------------------------------------* - * Find the adaptive codebook vector. - *--------------------------------------------------------------*/ - - pred_lt4( &exc_fx[i_subfr_fx], &exc_fx[i_subfr_fx], T0_fx, T0_frac_fx, L_subfr_fx + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); - - /*--------------------------------------------------------------* - * Innovation decoding - *--------------------------------------------------------------*/ - - IF( EQ_16( use_fcb, 1 ) ) - { - inov_decode_fx( st_fx, Local_BR_fx, 0, st_fx->L_frame, 1, i_subfr_fx, p_Aq_fx, st_fx->tilt_code_fx, *pt_pitch_fx, code_fx, L_subfr_fx ); - /*--------------------------------------------------------------* - * Gain decoding - * Estimate spectrum tilt and voicing - *--------------------------------------------------------------*/ - - gain_dec_mless_fx( st_fx, st_fx->L_frame, LOCAL_CT, i_subfr_fx, -1, code_fx, Es_pred_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx ); - - st_fx->tilt_code_fx = est_tilt_fx( exc_fx + i_subfr_fx, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, 0 ); - move16(); - } - ELSE IF( EQ_16( use_fcb, 2 ) ) /* IVAS only */ - { - inov_decode_fx( st_fx, Local_BR_fx, 0, st_fx->L_frame, 1, i_subfr_fx, p_Aq_fx, st_fx->tilt_code_fx, *pt_pitch_fx, code_fx, L_subfr_fx ); - /*--------------------------------------------------------------* - * Gain decoding - * Estimate spectrum tilt and voicing - *--------------------------------------------------------------*/ - - gain_dec_lbr_fx( st_fx, GENERIC, i_subfr_fx, code_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx, gc_mem, gp_mem, L_subfr_fx ); - - st_fx->tilt_code_fx = est_tilt_fx( exc_fx + i_subfr_fx, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, 0 ); - move16(); - } - ELSE - { - nbits = 5; - move16(); - if ( LT_32( st_fx->core_brate, MIN_RATE_FCB ) ) - { - nbits = 4; - move16(); - } - - set16_fx( code_fx, 0, L_SUBFR ); - gain_code_fx = L_deposit_l( 0 ); - st_fx->tilt_code_fx = 0; - move16(); - pit_idx_fx = (Word16) get_next_indice( st_fx, nbits ); - move16(); - - gain_pit_fx = add( 9590, dic_gp_fx[pit_idx_fx] ); - move16(); /*Q14 0.5853 in Q14 9590*/ - - if ( st_fx->BER_detect ) /* Bitstream is corrupted, use the past pitch gain */ - { - gain_pit_fx = st_fx->lp_gainp_fx; - move16(); - } - gain_code_fx = L_mult0( s_max( sub( 32767, shl_o( gain_pit_fx, 1, &Overflow ) ), 16384 ), st_fx->lp_gainc_fx ); /* Use gain pitch and past gain code as an indicator to help finding the best scaling value. gain_code_fx used a temp var*/ - } - - /*----------------------------------------------------------------------* - * Find the total excitation - *----------------------------------------------------------------------*/ - - Rescale_exc( hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], &bwe_exc_fx[( i_subfr_fx * ( 2 * HIBND_ACB_L_FAC ) ) / 2], hGSCDec->last_exc_dct_in_fx, - L_subfr_fx, shr( imult1616( L_subfr_fx, 2 * HIBND_ACB_L_FAC ), 1 ), gain_code_fx, &( st_fx->Q_exc ), st_fx->Q_subfr, NULL, i_subfr_fx, coder_type ); - - gain_code16 = round_fx( L_shl( gain_code_fx, st_fx->Q_exc ) ); /*Q_exc*/ - - IF( use_fcb != 0 ) - { - Acelp_dec_total_exc( exc_fx, exc2_bidon - i_subfr_fx, gain_code16, gain_pit_fx, i_subfr_fx, code_fx, L_subfr_fx ); - } - ELSE - { - IF( norm_s( s_or( gain_pit_fx, 1 ) ) == 0 ) - { - FOR( i = 0; i < L_subfr_fx; i++ ) - { - L_tmp = L_shl_sat( L_mult( gain_pit_fx, exc_fx[i + i_subfr_fx] ), 1 ); /*Q16+Q_exc*/ - exc_fx[i + i_subfr_fx] = round_fx_sat( L_tmp ); /*Q_exc*/ - move16(); - } - } - ELSE - { - gain_pitx2 = shl( gain_pit_fx, 1 ); /*Q15*/ - - FOR( i = 0; i < L_subfr_fx; i++ ) - { - L_tmp = L_mult( gain_pitx2, exc_fx[i + i_subfr_fx] ); /*Q16+Q_exc*/ - exc_fx[i + i_subfr_fx] = round_fx_sat( L_tmp ); /*Q_exc*/ - move16(); - } - } - } - - IF( EQ_16( L_subfr_fx, L_FRAME16k ) ) - { - /* update gains for FEC - equivalent to lp_gain_updt() */ - st_fx->lp_gainp_fx = gain_pit_fx; - move16(); - st_fx->lp_gainc_fx = 0; - move32(); - - pt_pitch_fx++; - *pt_pitch_fx = *( pt_pitch_fx - 1 ); - pt_pitch_fx++; - *pt_pitch_fx = *( pt_pitch_fx - 1 ); - pt_pitch_fx++; - *pt_pitch_fx = *( pt_pitch_fx - 1 ); - pt_pitch_fx++; - *pt_pitch_fx = *( pt_pitch_fx - 1 ); - pt_pitch_fx++; - move16(); - move16(); - move16(); - move16(); - p_Aq_fx += 5 * ( M + 1 ); - } - ELSE IF( EQ_16( L_subfr_fx, L_FRAME16k / 2 ) ) - { - IF( i_subfr_fx == 0 ) - { - pt_pitch_fx++; - *pt_pitch_fx = *( pt_pitch_fx - 1 ); - pt_pitch_fx++; - p_Aq_fx += 2 * ( M + 1 ); - move16(); - - /* update gains for FEC - equivalent to lp_gain_updt() */ - st_fx->lp_gainp_fx = extract_h( L_mult( 6554, gain_pit_fx ) ); /*Q14 (3/15 in Q15 9830)*/ - st_fx->lp_gainc_fx = 0; - move16(); - move16(); - } - ELSE - { - pt_pitch_fx++; - *pt_pitch_fx = *( pt_pitch_fx - 1 ); - pt_pitch_fx++; - *pt_pitch_fx = *( pt_pitch_fx - 1 ); - pt_pitch_fx++; - p_Aq_fx += 3 * ( M + 1 ); - move16(); - move16(); - - /* update gains for FEC - equivalent to lp_gain_updt() */ - st_fx->lp_gainp_fx = extract_h( L_mult( 26214, gain_pit_fx ) ); /*Q14 (12/15 in Q15 9830)*/ - st_fx->lp_gainc_fx = 0; - move16(); - move16(); - } - } - ELSE IF( EQ_16( L_subfr_fx, 128 ) ) /*2*L_SUBFR*/ - { - p_Aq_fx += 2 * ( M + 1 ); - pt_pitch_fx++; - *pt_pitch_fx = *( pt_pitch_fx - 1 ); - move16(); - pt_pitch_fx++; - *pt_gain = gain_pit_fx; - move16(); - pt_gain++; - *pt_gain = *( pt_gain - 1 ); - move16(); - pt_gain++; - IF( i_subfr_fx == 0 ) - { - /* update gains for FEC - equivalent to lp_gain_updt() */ - st_fx->lp_gainp_fx = extract_h( L_mult( 9830, gain_pit_fx ) ); /*Q14 (3/10 in Q15 9830)*/ - st_fx->lp_gainc_fx = 0; - move16(); - move16(); - } - ELSE - { - /* update gains for FEC - equivalent to lp_gain_updt() */ - st_fx->lp_gainp_fx = extract_h( L_mult( 22938, gain_pit_fx ) ); /*Q14 (7/10 in Q15 22938)*/ - st_fx->lp_gainc_fx = 0; - move16(); - move16(); - } - } - ELSE IF( EQ_16( L_subfr_fx, 256 ) ) /*4*L_SUBFR*/ - { - pt_pitch_fx++; - *pt_pitch_fx = *( pt_pitch_fx - 1 ); - move16(); - pt_pitch_fx++; - *pt_pitch_fx = *( pt_pitch_fx - 1 ); - move16(); - pt_pitch_fx++; - *pt_pitch_fx = *( pt_pitch_fx - 1 ); - move16(); - pt_pitch_fx++; - *pt_gain = gain_pit_fx; - move16(); - pt_gain++; - *pt_gain = *( pt_gain - 1 ); - move16(); - pt_gain++; - *pt_gain = *( pt_gain - 1 ); - move16(); - pt_gain++; - *pt_gain = *( pt_gain - 1 ); - move16(); - pt_gain++; - p_Aq_fx += 4 * ( M + 1 ); - - /* update gains for FEC - equivalent to lp_gain_updt() */ - st_fx->lp_gainp_fx = gain_pit_fx; - move16(); - st_fx->lp_gainc_fx = 0; - move16(); - } - ELSE - { - p_Aq_fx += ( M + 1 ); - move16(); - pt_pitch_fx++; - move16(); - *pt_gain = gain_pit_fx; - move16(); - pt_gain++; - - lp_gain_updt_fx( i_subfr_fx, gain_pit_fx, 0, &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, st_fx->L_frame ); - } - } - - return; -} - -/*==========================================================================*/ -/* FUNCTION : void dec_pit_exc_ivas_fx() */ -/*--------------------------------------------------------------------------*/ -/* PURPOSE : Decode pitch only contribution */ -/*--------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16*) Aq_fx : LP filter coefficient Q12 */ -/* _ (Word16) coder_type : coding type Q0 */ -/* _ (Word16) nb_subfr_fx :Number of subframe considered */ -/* _ (Word16) Es_pred_fx :predicted scaled innov. energy */ -/*--------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16*) pitch_buf_fx : Word16 pitch values for each subframe Q6 */ -/* _ (Word16*) code_fx : innovation */ -/*--------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* Decoder_State_fx *st_fx : decoder state structure */ -/* _ (Word16*) exc_fx : adapt. excitation exc */ -/*--------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*==========================================================================*/ -#endif -void dec_pit_exc_ivas_fx( Decoder_State *st_fx, /* i/o: decoder static memory */ const Word16 *Aq_fx, /* i : LP filter coefficient */ const Word16 coder_type, /* i : coding type */ const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ - Word16 *pitch_buf_fx, /* o : Word16 pitch values for each subframe */ + Word16 *pitch_buf_fx, /* o : Word16 pitch values for each subframe */ Word16 *code_fx, /* o : innovation */ Word16 *exc_fx, /* i/o: adapt. excitation exc */ Word16 *bwe_exc_fx, /* o : excitation for SWB TBE */ const Word16 nb_subfr_fx, /* i : Number of subframe considered */ - Word16 *gain_buf, /*Q14*/ + Word16 *gain_buf, /* o : Word16 pitch gain for each subframe Q14*/ const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer */ ) { - Word16 T0_fx, T0_frac_fx, T0_min_fx, T0_max_fx; /* integer pitch variables */ - Word16 gain_pit_fx; /* pitch gain Q14 */ - Word32 gain_code_fx; /* gain/normalized gain of the algebraic excitation Q16 */ + Word16 T0_fx, T0_frac_fx, T0_min_fx, T0_max_fx; /* integer pitch variables */ + Word16 gain_pit_fx; /* pitch gain Q14 */ + Word32 gain_code_fx; /* gain/normalized gain of the algebraic excitation Q16 */ Word32 norm_gain_code_fx; /* normalized gain of the algebraic excitation Q16 */ - Word16 gain_inov_fx; /* Innovation gain Q12 */ + Word16 gain_inov_fx; /* Innovation gain Q12 */ Word16 voice_fac_fx; /* voicing factor Q15 */ Word16 L_subfr_fx, pit_idx_fx; - const Word16 *p_Aq_fx; /* Pointer to frame LP coefficient Q12 */ + const Word16 *p_Aq_fx; /* Pointer to frame LP coefficient Q12 */ Word16 *pt_pitch_fx; /* pointer to Word16 pitch Q6 */ Word16 i_subfr_fx, i; /* tmp variables */ Word32 Local_BR_fx, Pitch_BR_fx; @@ -578,13 +169,14 @@ void dec_pit_exc_ivas_fx( p_Aq_fx = Aq_fx; /* pointer to interpolated LPC parameters */ pt_pitch_fx = pitch_buf_fx; /* pointer to the pitch buffer */ pt_gain = gain_buf; /* pointer to the gain buffer */ + FOR( i_subfr_fx = 0; i_subfr_fx < st_fx->L_frame; i_subfr_fx += L_subfr_fx ) { /*----------------------------------------------------------------------* * Decode pitch lag *----------------------------------------------------------------------*/ - *pt_pitch_fx = pit_decode_ivas_fx( st_fx, Pitch_BR_fx, 0, st_fx->L_frame, i_subfr_fx, Pitch_CT_fx, &pitch_limit_flag, &T0_fx, &T0_frac_fx, &T0_min_fx, &T0_max_fx, L_subfr_fx, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf ); + *pt_pitch_fx = pit_decode_fx( st_fx, Pitch_BR_fx, 0, st_fx->L_frame, i_subfr_fx, Pitch_CT_fx, &pitch_limit_flag, &T0_fx, &T0_frac_fx, &T0_min_fx, &T0_max_fx, L_subfr_fx, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf ); move16(); /*--------------------------------------------------------------* @@ -621,7 +213,7 @@ void dec_pit_exc_ivas_fx( * Estimate spectrum tilt and voicing *--------------------------------------------------------------*/ - gain_dec_lbr_ivas_fx( st_fx, GENERIC, i_subfr_fx, code_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx, gc_mem, gp_mem, L_subfr_fx ); + gain_dec_lbr_fx( st_fx, GENERIC, i_subfr_fx, code_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx, gc_mem, gp_mem, L_subfr_fx ); st_fx->tilt_code_fx = est_tilt_ivas_fx( exc_fx + i_subfr_fx, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, 0, L_subfr_fx, 0 ); move16(); diff --git a/lib_dec/dec_post_fx.c b/lib_dec/dec_post_fx.c index 281281ed6..37d088a8f 100644 --- a/lib_dec/dec_post_fx.c +++ b/lib_dec/dec_post_fx.c @@ -33,10 +33,7 @@ static void calc_st_filt_local_fx( Word16 *apond2, Word16 *apond1, Word16 *parco static void modify_pst_param_fx( const Word16 lp_noise, Word16 *g1, Word16 *g2, const Word16 coder_type, Word16 *gain_factor ); -#ifndef REMOVE_EVS_DUPLICATES static void Dec_formant_postfilt_fx( PFSTAT_HANDLE hPFstat, Word16 *signal_ptr, Word16 *coeff, Word16 *sig_out, Word16 gamma1, Word16 gamma2 ); -#endif -static void Dec_formant_postfilt_ivas_fx( PFSTAT_HANDLE hPFstat, Word16 *signal_ptr, Word16 *coeff, Word16 *sig_out, Word16 gamma1, Word16 gamma2 ); static void calc_st_filt_ivas_fx( Word16 *apond2, Word16 *apond1, Word16 *parcor0, Word16 *sig_ltp_ptr, Word16 *mem_zero, const Word16 extl ); @@ -82,7 +79,7 @@ void Init_post_filter_fx( *--------------------------------------------------------------------------*/ void nb_post_filt_fx( const Word16 L_frame, /* i : frame length */ - PFSTAT_HANDLE hPFstat, /* i : core decoder parameters */ + PFSTAT_HANDLE hPFstat, /* i : core decoder parameters */ Word16 *psf_lp_noise, /* i : Long term noise Q8 */ const Word16 tmp_noise, /* i : noise energy Q0 */ Word16 *Synth, /* i : 12k8 synthesis Qsyn */ @@ -257,22 +254,20 @@ static void Dec_postfilt_fx( * Main routine to perform formant post filtering *--------------------------------------------------------------------------*/ -#ifndef REMOVE_EVS_DUPLICATES void formant_post_filt_fx( - PFSTAT_HANDLE hPFstat, /* i : core decoder parameters */ + PFSTAT_HANDLE hPFstat, /* i : core decoder parameters */ Word16 *synth_in, /* i : 12k8 synthesis */ - Word16 *Aq, /* i : LP filter coefficient Q12 */ + Word16 *Aq, /* i : LP filter coefficient Q12 */ Word16 *synth_out, /* i/o: input signal */ - Word16 L_frame, - Word32 lp_noise, /* (i) : background noise energy (15Q16) */ - Word32 brate, /* (i) : bit-rate */ - const Word16 off_flag /* i : off flag */ + const Word16 L_frame, /* i : frame length */ + const Word32 lp_noise, /* (i) : background noise energy (15Q16) */ + const Word32 brate, /* (i) : bit-rate */ + const Word16 off_flag /* i : off flag */ ) { Word16 i_subfr; Word16 *p_Aq; - Word16 post_G1, post_G2; // Q15 - + Word16 post_G1, post_G2; /*default parameter for noisy speech and high bit-rates*/ IF( EQ_16( L_frame, L_FRAME ) ) @@ -381,134 +376,13 @@ void formant_post_filt_fx( Dec_formant_postfilt_fx( hPFstat, &synth_in[i_subfr], p_Aq, &synth_out[i_subfr], post_G1, post_G2 ); p_Aq += ( M + 1 ); } -} -#endif -void formant_post_filt_ivas_fx( - PFSTAT_HANDLE hPFstat, /* i : core decoder parameters */ - Word16 *synth_in, /* i : 12k8 synthesis */ - Word16 *Aq, /* i : LP filter coefficient Q12 */ - Word16 *synth_out, /* i/o: input signal */ - Word16 L_frame, - Word32 lp_noise, /* (i) : background noise energy (15Q16) */ - Word32 brate, /* (i) : bit-rate */ - const Word16 off_flag /* i : off flag */ -) -{ - Word16 i_subfr; - Word16 *p_Aq; - Word16 post_G1, post_G2; - - - /*default parameter for noisy speech and high bit-rates*/ - IF( EQ_16( L_frame, L_FRAME ) ) - { - post_G2 = 22938 /*0.7f Q15*/; - move16(); - IF( LT_32( lp_noise, LP_NOISE_THRESH ) ) - { - /*Clean speech*/ - IF( LT_32( brate, ACELP_13k20 ) ) - { - /*Low rates*/ - - post_G1 = 26214 /*0.8f Q15*/; - move16(); - } - ELSE IF( LT_32( brate, ACELP_24k40 ) ) - { - /*Low rates*/ - - post_G1 = 24576 /*0.75f Q15*/; - move16(); - } - ELSE - { - post_G1 = 23593 /*0.72f Q15*/; - move16(); - } - } - ELSE /*Noisy speech*/ - { - post_G1 = 22938 /*0.7f Q15*/; - move16(); - if ( LT_32( brate, ACELP_15k85 ) ) - { - /*Low rates*/ - post_G1 = 24576 /*0.75f Q15*/; - move16(); - } - } - } - ELSE - { - post_G2 = 24904 /*0.76f Q15*/; - move16(); - test(); - IF( GE_32( lp_noise, LP_NOISE_THRESH ) ) - { - post_G1 = 24904 /*0.76f Q15*/; - } - ELSE IF( EQ_32( brate, ACELP_13k20 ) ) - { - post_G1 = 26870 /*0.82f Q15*/; - move16(); - } - ELSE IF( EQ_32( brate, ACELP_16k40 ) ) - { - post_G1 = 26214 /*0.80f Q15*/; - move16(); - } - ELSE IF( EQ_32( brate, ACELP_24k40 ) || EQ_32( brate, ACELP_32k ) ) - { - post_G1 = 25559 /*0.78f Q15*/; - move16(); - } - ELSE - { - post_G1 = 24904 /*0.76f Q15*/; - move16(); - } - } - /* Switch off post-filter */ - if ( off_flag != 0 ) - { - post_G1 = post_G2; - move16(); - } - - /* Reset post filter */ - IF( hPFstat->reset != 0 ) - { - post_G1 = MAX16B; - move16(); - post_G2 = MAX16B; - move16(); - hPFstat->reset = 0; - move16(); - Copy( &synth_in[L_frame - L_SYN_MEM], hPFstat->mem_pf_in, L_SYN_MEM ); - Copy( &synth_in[L_frame - L_SYN_MEM], hPFstat->mem_stp, L_SYN_MEM ); - hPFstat->gain_prec = 16384; // 1.Q14 - move16(); - Copy( synth_in, synth_out, L_frame ); - - return; - } + return; +} - /* input memory*/ - Copy( hPFstat->mem_pf_in, synth_in - L_SYN_MEM, L_SYN_MEM ); - Copy( &synth_in[L_frame - L_SYN_MEM], hPFstat->mem_pf_in, L_SYN_MEM ); - move16(); - p_Aq = Aq; // Q12 - FOR( i_subfr = 0; i_subfr < L_frame; i_subfr += L_SUBFR ) - { - Dec_formant_postfilt_ivas_fx( hPFstat, &synth_in[i_subfr], p_Aq, &synth_out[i_subfr], post_G1, post_G2 ); - p_Aq += ( M + 1 ); - } -} /*---------------------------------------------------------------------------- - * Dec_formant_postfilt_fx + * Dec_formant_postfilt_fx() * * Post - adaptive postfilter main function * Short term postfilter : @@ -522,93 +396,14 @@ void formant_post_filt_ivas_fx( * k1 = 1st parcor calculated on {hi} * gamma3 = gamma3_minus if k1<0, gamma3_plus if k1>0 *----------------------------------------------------------------------------*/ -#ifndef REMOVE_EVS_DUPLICATES -static void Dec_formant_postfilt_fx( - PFSTAT_HANDLE hPFstat, /* i : core decoder parameters */ - Word16 *signal_ptr, /* i : input signal (pointer to current subframe Q14*/ - Word16 *coeff, /* i : LPC coefficients for current subframe Q12 */ - Word16 *sig_out, /* o : postfiltered output */ - Word16 gamma1, /* i : short term postfilt. den. weighting factor Q15*/ - Word16 gamma2 /* i : short term postfilt. num. weighting factor Q15*/ -) -{ - /* Local variables and arrays */ - Word16 apond1[M + 1]; /* s.t. denominator coeff. Q12*/ - Word16 apond2[LONG_H_ST]; // Q12 - Word16 res2[L_SUBFR]; // Q14 - Word16 resynth[L_SUBFR + 1]; // Qy - Word16 parcor0; // Q15 - Word16 i, max; - Word16 scale_down; - - /* Compute weighted LPC coefficients */ - weight_a_fx( coeff, apond1, gamma1, M ); - weight_a_fx( coeff, apond2, gamma2, M ); - set16_fx( &apond2[M + 1], 0, LONG_H_ST - ( M + 1 ) ); - max = abs_s( signal_ptr[0] ); // Q14 - FOR( i = 1; i < L_SUBFR; i++ ) - { - max = s_max( max, abs_s( signal_ptr[i] ) ); - } - scale_down = 0; - move16(); - if ( GT_16( max, 16384 /*1.Q14*/ ) ) - { - scale_down = 1; - move16(); - } - - /* Compute A(gamma2) residual */ - IF( !scale_down ) - { - Residu3_fx( apond2, signal_ptr, res2, L_SUBFR, 1 ); - } - ELSE - { - Residu3_fx( apond2, signal_ptr, res2, L_SUBFR, 0 ); - Scale_sig( hPFstat->mem_stp, L_SYN_MEM, -1 ); - } - - /* Controls short term pst filter gain and compute parcor0 */ - calc_st_filt_local_fx( apond2, apond1, &parcor0, res2, hPFstat->mem_zero ); - - /* 1/A(gamma1) filtering, mem_stp is updated */ - resynth[0] = *( hPFstat->mem_stp + sub( L_SYN_MEM, 1 ) ); - move16(); - - E_UTIL_synthesis( 1, apond1, res2, &( resynth[1] ), L_SUBFR, hPFstat->mem_stp + L_SYN_MEM - M, 0, M ); - - IF( !scale_down ) - { - Copy( &( resynth[1] ) + L_SUBFR - L_SYN_MEM, hPFstat->mem_stp, L_SYN_MEM ); - } - ELSE - { - Copy_Scale_sig( &( resynth[1] ) + L_SUBFR - L_SYN_MEM, hPFstat->mem_stp, L_SYN_MEM, 1 ); - } - - /* Tilt filtering */ - Filt_mu_fx( resynth, sig_out, parcor0, L_SUBFR ); - IF( scale_down ) - { - Scale_sig( sig_out, L_SUBFR, 1 ); - } - - /* Gain control */ - scale_st_fx( signal_ptr, sig_out, &hPFstat->gain_prec, L_SUBFR ); - - - return; -} -#endif -static void Dec_formant_postfilt_ivas_fx( - PFSTAT_HANDLE hPFstat, /* i : core decoder parameters */ - Word16 *signal_ptr, /* i : input signal (pointer to current subframe Q14*/ - Word16 *coeff, /* i : LPC coefficients for current subframe Q12 */ - Word16 *sig_out, /* o : postfiltered output */ - Word16 gamma1, /* i : short term postfilt. den. weighting factor Q15*/ - Word16 gamma2 /* i : short term postfilt. num. weighting factor Q15*/ +static void Dec_formant_postfilt_fx( + PFSTAT_HANDLE hPFstat, /* i : core decoder parameters */ + Word16 *signal_ptr, /* i : input signal (pointer to current subframe Q14*/ + Word16 *coeff, /* i : LPC coefficients for current subframe Q12 */ + Word16 *sig_out, /* o : postfiltered output */ + Word16 gamma1, /* i : short term postfilt. den. weighting factor Q15*/ + Word16 gamma2 /* i : short term postfilt. num. weighting factor Q15*/ ) { /* Local variables and arrays */ diff --git a/lib_dec/dec_ppp_fx.c b/lib_dec/dec_ppp_fx.c index 4849e147a..4b3f4f554 100644 --- a/lib_dec/dec_ppp_fx.c +++ b/lib_dec/dec_ppp_fx.c @@ -6,6 +6,7 @@ #include #include "options.h" /* Compilation switches */ #include "prot_fx.h" /* Function prototypes */ + /*===================================================================*/ /* FUNCTION : void decod_ppp_fx () */ /*-------------------------------------------------------------------*/ @@ -45,20 +46,20 @@ /*-------------------------------------------------------------------*/ /* CALLED FROM : RX */ /*===================================================================*/ + ivas_error decod_ppp_fx( - Decoder_State *st_fx, /* i/o: state structure */ - const Word16 Aq_fx[], /* i : 12k8 Lp coefficient */ - Word16 *pitch_buf_fx, /* i/o: fixed pitch values for each subframe */ - Word16 *exc_fx, /* i/o: current non-enhanced excitation */ - Word16 *exc2_fx, /* i/o: current enhanced excitation */ - Word16 bfi, /* i : bad frame indicator */ - Word16 *gain_buf, + Decoder_State *st_fx, /* i/o: state structure */ + const Word16 Aq_fx[], /* i : 12k8 Lp coefficient */ + Word16 *pitch_buf_fx, /* i/o: fixed pitch values for each subframe */ + Word16 *exc_fx, /* i/o: current non-enhanced excitation */ + Word16 *exc2_fx, /* i/o: current enhanced excitation */ + Word16 bfi, /* i : bad frame indicator */ + Word16 *gain_buf, /* o : Word16 pitch gain for each subframe Q14*/ Word16 *voice_factors, /* o : voicing factors */ Word16 *bwe_exc_fx /* o : excitation for SWB TBE */ ) { Word16 k; - Word16 LPC_de_curr_fx[M + 1], p_Aq_curr_fx[M], p_Aq_old_fx[M + 1]; Word16 excQ_ppp_fx[L_FRAME], pitch_fx[NB_SUBFR], LPC_de_old_fx[M + 1]; ivas_error error; diff --git a/lib_dec/dec_tran_fx.c b/lib_dec/dec_tran_fx.c index c5b06724a..de3a1ff3f 100644 --- a/lib_dec/dec_tran_fx.c +++ b/lib_dec/dec_tran_fx.c @@ -254,16 +254,10 @@ void decod_tran_fx( tmp_idx_2 = idiv1616( i_subfr, L_SUBFR ); } -#ifdef REMOVE_EVS_DUPLICATES - prep_tbe_exc_ivas_fx( L_frame_fx, L_SUBFR, i_subfr, gain_pit_fx, gain_code_fx, code_fx, voice_fac_fx, - &voice_factors_fx[tmp_idx_2], bwe_exc_fx, gain_preQ_fx, code_preQ_fx, - st_fx->Q_exc, T0, T0_frac, st_fx->coder_type, st_fx->core_brate, - st_fx->element_mode, st_fx->idchan, st_fx->hBWE_TD != NULL, st_fx->tdm_LRTD_flag ); -#else - prep_tbe_exc_fx( L_frame_fx, i_subfr, gain_pit_fx, gain_code_fx, code_fx, voice_fac_fx, + prep_tbe_exc_fx( L_frame_fx, L_SUBFR, i_subfr, gain_pit_fx, gain_code_fx, code_fx, voice_fac_fx, &voice_factors_fx[tmp_idx_2], bwe_exc_fx, gain_preQ_fx, code_preQ_fx, - st_fx->Q_exc, T0, T0_frac, st_fx->coder_type, st_fx->core_brate ); -#endif + st_fx->Q_exc, T0, T0_frac, st_fx->coder_type, st_fx->core_brate, + st_fx->element_mode, st_fx->idchan, st_fx->hBWE_TD != NULL, st_fx->tdm_LRTD_flag ); /*----------------------------------------------------------------* * Excitation enhancements (update of total excitation signal) diff --git a/lib_dec/dec_uv_fx.c b/lib_dec/dec_uv_fx.c index fcc2600a3..f1ba21979 100644 --- a/lib_dec/dec_uv_fx.c +++ b/lib_dec/dec_uv_fx.c @@ -25,96 +25,7 @@ static void gain_dec_gacelp_uv_fx( * Decode unvoiced (UC) frames *-------------------------------------------------------------------*/ -#ifndef REMOVE_EVS_DUPLICATES void decod_unvoiced_fx( - Decoder_State *st_fx, /* i/o: decoder static memory */ - const Word16 *Aq_fx, /* Q12 i : LP filter coefficient */ - const Word16 coder_type, /* Q0 i : coding type */ - Word16 *tmp_noise_fx, /* Q0 o : long term temporary noise energy */ - Word16 *pitch_buf_fx, /* Q6 o : floating pitch values for each subframe*/ - Word16 *voice_factors_fx, /* Q15 o : voicing factors */ - Word16 *exc_fx, /* Q_X o : adapt. excitation exc */ - Word16 *exc2_fx, /* Q_X o : adapt. excitation/total exc */ - Word16 *bwe_exc_fx, /* Q_X i/o: excitation for SWB TBE */ - Word16 *gain_buf ) -{ - Word16 gain_pit_fx; /* Quantized pitch gain */ - Word32 gain_code_fx; /* Quantized algebraic codeebook gain */ - Word16 gain_inov_fx; /* inovation gain */ - Word32 norm_gain_code_fx; /* normalized algebraic codeebook gain */ - Word16 voice_fac_fx; /* Voicing factor */ - Word16 code_fx[L_SUBFR]; /* algebraic codevector */ - Word16 i_subfr_fx; - const Word16 *p_Aq_fx; - Word16 *pt_pitch_fx; - - gain_pit_fx = 0; - move16(); - - test(); - IF( EQ_16( st_fx->last_ppp_mode_dec, 1 ) || EQ_16( st_fx->last_nelp_mode_dec, 1 ) ) - { - /* SC_VBR - reset the decoder, to avoid memory not updated issue for this unrealistic case */ - CNG_reset_dec_fx( st_fx, pitch_buf_fx, voice_factors_fx ); - } - - p_Aq_fx = Aq_fx; - move16(); /*Q12*/ /* pointer to interpolated LPC parameters */ - pt_pitch_fx = pitch_buf_fx; - move16(); /* pointer to the pitch buffer */ - - FOR( i_subfr_fx = 0; i_subfr_fx < L_FRAME; i_subfr_fx += L_SUBFR ) - { - /*----------------------------------------------------------------* - * Unvoiced subframe processing - *----------------------------------------------------------------*/ - - gaus_dec_fx( st_fx, i_subfr_fx, code_fx, &norm_gain_code_fx, &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, &gain_inov_fx, &st_fx->tilt_code_fx, - &voice_fac_fx, &gain_pit_fx, pt_pitch_fx, exc_fx, &gain_code_fx, exc2_fx, bwe_exc_fx, &( st_fx->Q_exc ), st_fx->Q_subfr ); - - *tmp_noise_fx = extract_h( norm_gain_code_fx ); /*Q16*/ - move16(); - - /*----------------------------------------------------------------* - * Excitation enhancements (update of total excitation signal) - *----------------------------------------------------------------*/ - - enhancer_fx( st_fx->core_brate, 0, coder_type, i_subfr_fx, L_FRAME, voice_fac_fx, st_fx->stab_fac_fx, - norm_gain_code_fx, gain_inov_fx, &st_fx->gc_threshold_fx, code_fx, exc2_fx, gain_pit_fx, &( st_fx->dm_fx ), st_fx->Q_exc ); - - Word16 tmp_idx = 0; - move16(); - IF( i_subfr_fx != 0 ) - { - tmp_idx = idiv1616( i_subfr_fx, L_SUBFR ); - } - voice_factors_fx[tmp_idx] = 0; - move16(); - - interp_code_5over2_fx( &exc_fx[i_subfr_fx], &bwe_exc_fx[( ( i_subfr_fx * 2 * HIBND_ACB_L_FAC ) >> 1 )], L_SUBFR ); - - p_Aq_fx += ( M + 1 ); - pt_pitch_fx++; - st_fx->tilt_code_dec_fx[tmp_idx] = st_fx->tilt_code_fx; - move16(); - } - - /* SC-VBR */ - st_fx->prev_gain_pit_dec_fx = gain_pit_fx; - move16(); - - set16_fx( gain_buf, 0, NB_SUBFR ); - - return; -} - -/*-------------------------------------------------------------------* - * decod_unvoiced() - * - * Decode unvoiced (UC) frames - *-------------------------------------------------------------------*/ -#endif -void decod_unvoiced_ivas_fx( Decoder_State *st_fx, /* i/o: decoder static memory */ const Word16 *Aq_fx, /* Q12 i : LP filter coefficient */ const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ @@ -208,13 +119,11 @@ void decod_unvoiced_ivas_fx( move16(); /* update LP filtered gains for the case of frame erasures */ -#ifdef REMOVE_EVS_DUPLICATES IF( EQ_16( st_fx->element_mode, EVS_MONO ) ) { lp_gain_updt_fx( i_subfr_fx, gain_pit_fx, norm_gain_code_fx, &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, L_FRAME ); } ELSE -#endif { lp_gain_updt_ivas_fx( i_subfr_fx, gain_pit_fx, norm_gain_code_fx, &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, L_FRAME ); } @@ -250,6 +159,7 @@ void decod_unvoiced_ivas_fx( } // Scale_sig(code_fx, L_SUBFR, 3); //Q12 } + *tmp_noise_fx = extract_h( norm_gain_code_fx ); /*Q16*/ move16(); @@ -257,14 +167,12 @@ void decod_unvoiced_ivas_fx( * Excitation enhancements (update of total excitation signal) *----------------------------------------------------------------*/ -#ifdef REMOVE_EVS_DUPLICATES IF( EQ_16( st_fx->element_mode, EVS_MONO ) ) { enhancer_fx( st_fx->core_brate, 0, coder_type, i_subfr_fx, L_FRAME, voice_fac_fx, st_fx->stab_fac_fx, norm_gain_code_fx, gain_inov_fx, &st_fx->gc_threshold_fx, code_fx, exc2_fx, gain_pit_fx, &( st_fx->dm_fx ), st_fx->Q_exc ); } ELSE -#endif { enhancer_ivas_fx( MODE1, st_fx->core_brate, uc_two_stage_flag, 0, coder_type, i_subfr_fx, L_FRAME, voice_fac_fx, st_fx->stab_fac_fx, norm_gain_code_fx, gain_inov_fx, &st_fx->gc_threshold_fx, code_fx /*Q9/Q12?*/, exc2_fx, gain_pit_fx, &( st_fx->dm_fx ), st_fx->Q_exc ); @@ -276,12 +184,6 @@ void decod_unvoiced_ivas_fx( IF( i_subfr_fx != 0 ) { tmp_idx = idiv1616( i_subfr_fx, L_SUBFR ); -#ifdef REMOVE_EVS_DUPLICATES - IF( EQ_16( st_fx->element_mode, EVS_MONO ) ) - { - tmp_idx = idiv1616( i_subfr_fx, L_SUBFR ); - } -#endif } voice_factors_fx[tmp_idx] = 0; move16(); diff --git a/lib_dec/evs_dec_fx.c b/lib_dec/evs_dec_fx.c index 38bd7de24..6411eb477 100644 --- a/lib_dec/evs_dec_fx.c +++ b/lib_dec/evs_dec_fx.c @@ -332,11 +332,7 @@ ivas_error evs_dec_fx( IF( EQ_16( st_fx->core, ACELP_CORE ) ) { /* ACELP core decoder */ -#ifdef REMOVE_EVS_DUPLICATES - IF( ( error = acelp_core_dec_ivas_fx( st_fx, NULL, synth_fx, NULL, bwe_exc_extended_fx, voice_factors_fx, old_syn_12k8_16k_fx, sharpFlag, pitch_buf_fx, &unbits, &sid_bw, NULL, NULL, NULL, 0, EVS_MONO, 0, 0, 1, NULL, 1 ) ) != IVAS_ERR_OK ) -#else IF( ( error = acelp_core_dec_fx( st_fx, NULL, synth_fx, NULL, bwe_exc_extended_fx, voice_factors_fx, old_syn_12k8_16k_fx, sharpFlag, pitch_buf_fx, &unbits, &sid_bw, NULL, NULL, NULL, 0, EVS_MONO, 0, 0, 1, NULL, 1 ) ) != IVAS_ERR_OK ) -#endif { return error; } @@ -957,11 +953,9 @@ ivas_error evs_dec_fx( } st_fx->lp_noise = hFdCngDec->lp_noise; /*Q9.23*/ move32(); -#ifdef REMOVE_EVS_DUPLICATES - ApplyFdCng_ivas_fx( output_sp, 0, NULL, 0, realBuffer, imagBuffer, &st_fx->scaleFactor.hb_scale, st_fx, concealWholeFrame, 0 ); -#else - ApplyFdCng_fx( output_sp, 0, realBuffer, imagBuffer, &st_fx->scaleFactor.hb_scale, st_fx, concealWholeFrame, 0 ); -#endif + + ApplyFdCng_fx( output_sp, 0, NULL, 0, realBuffer, imagBuffer, &st_fx->scaleFactor.hb_scale, st_fx, concealWholeFrame, 0 ); + /* Generate additional comfort noise to mask potential coding artefacts */ test(); IF( EQ_16( st_fx->m_frame_type, ACTIVE_FRAME ) && st_fx->flag_cna ) diff --git a/lib_dec/fd_cng_dec_fx.c b/lib_dec/fd_cng_dec_fx.c index 3fe93854e..cc83eeca3 100644 --- a/lib_dec/fd_cng_dec_fx.c +++ b/lib_dec/fd_cng_dec_fx.c @@ -555,463 +555,7 @@ void deleteFdCngDec_fx( HANDLE_FD_CNG_DEC *hFdCngDec ) error */ -#ifndef REMOVE_EVS_DUPLICATES Word16 ApplyFdCng_fx( - Word16 *timeDomainInput, /* i : pointer to time domain input Q*/ - Word16 Q, - Word32 **cldfbBufferReal, /* i/o: real part of the CLDFB buffer cldfbBufferScale*/ - Word32 **cldfbBufferImag, /* i/o: imaginary part of the CLDFB buffer cldfbBufferScale*/ - Word16 *cldfbBufferScale, /* o : pointer to the scalefactor for real and imaginary part of the CLDFB buffer */ - Decoder_State *st, - const Word16 concealWholeFrame, /* i : binary flag indicating frame loss Q0*/ - Word16 is_music /*Q0*/ ) -{ - Word16 j, k, nBins; - Word16 s, s1, s2, num, denom; - Word32 *cngNoiseLevel; - Word16 *cngNoiseLevel_exp; - Word32 L_tmp; - Word16 L_tmp_exp; - Word16 facTab[NPART]; - Word16 facTabExp[NPART]; - Word16 tmp_loop; - Word32 L_c; - Word16 lsp_cng[M]; - HANDLE_FD_CNG_DEC hFdCngDec; - HANDLE_FD_CNG_COM hFdCngCom; -#ifdef BASOP_NOGLOB_DECLARE_LOCAL - Flag Overflow = 0; - Flag Carry = 0; - move16(); - move16(); -#endif - - hFdCngDec = st->hFdCngDec; - hFdCngCom = hFdCngDec->hFdCngCom; - - - if ( EQ_16( hFdCngCom->frame_type_previous, ACTIVE_FRAME ) ) - { - hFdCngCom->inactive_frame_counter = 0; - move16(); - } - IF( EQ_16( st->element_mode, IVAS_CPE_TD ) ) - { - hFdCngDec->flag_dtx_mode = hFdCngDec->flag_dtx_mode || st->first_CNG; - test(); - move16(); - } - cngNoiseLevel = hFdCngCom->cngNoiseLevel; /*Q31 - hFdCngCom->cngNoiseLevelExp*/ - move32(); - cngNoiseLevel_exp = &hFdCngCom->cngNoiseLevelExp; - move16(); - nBins = sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); - - SWITCH( st->m_frame_type ) - { - case ACTIVE_FRAME: - - /************************** - * ACTIVE_FRAME at DECODER * - **************************/ - - hFdCngCom->inactive_frame_counter = 0; - move16(); - hFdCngCom->sid_frame_counter = 0; - move16(); - - /* set noise estimation inactive during concealment, as no update with noise generated by concealment should be performed. */ - /* set noise estimation inactive during concealment, no update with noise generated by concealment should be performed. */ - - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( - ( concealWholeFrame == 0 ) && - ( LT_16( *timeDomainInput, MAXVAL_WORD16 ) ) && GT_16( *timeDomainInput, MINVAL_WORD16 ) && ( LT_16( *( timeDomainInput + sub( hFdCngCom->frameSize, 1 ) ), MAXVAL_WORD16 ) ) && GT_16( *( timeDomainInput + sub( hFdCngCom->frameSize, 1 ) ), MINVAL_WORD16 ) && ( ( ( hFdCngDec->flag_dtx_mode == 0 ) && ( st->VAD != 0 ) ) == 0 ) && ( ( ( st->cng_type == LP_CNG ) && ( hFdCngDec->flag_dtx_mode != 0 ) ) == 0 ) && ( is_music == 0 ) && ( st->BER_detect == 0 ) ) - { - /* Perform noise estimation at the decoder */ - perform_noise_estimation_dec_fx( timeDomainInput, Q, hFdCngDec ); - - /* Update the shaping parameters */ - test(); - IF( NE_16( st->element_mode, IVAS_CPE_TD ) && NE_16( st->element_mode, IVAS_CPE_DFT ) ) - { - scalebands( hFdCngDec->msNoiseEst, hFdCngDec->part_shaping, hFdCngDec->nFFTpart_shaping, hFdCngDec->midband_shaping, hFdCngDec->nFFTpart_shaping, nBins, hFdCngDec->bandNoiseShape, 1 ); - } - hFdCngDec->bandNoiseShape_exp = hFdCngDec->msNoiseEst_exp; - move16(); - - - /* Update CNG levels */ - test(); - IF( hFdCngDec->flag_dtx_mode != 0 && EQ_16( st->cng_type, FD_CNG ) ) - { - /* This needs to be done only once per inactive phase */ - bandcombinepow( - hFdCngDec->bandNoiseShape, - hFdCngDec->bandNoiseShape_exp, - nBins, - hFdCngCom->part, - hFdCngCom->nFFTpart, - hFdCngCom->psize_inv, - hFdCngDec->partNoiseShape, - &hFdCngDec->partNoiseShape_exp ); - - - j = 0; - move16(); - s2 = -( WORD32_BITS - 1 ); - move16(); - FOR( k = 0; k < hFdCngCom->nFFTpart; k++ ) - { - assert( hFdCngDec->partNoiseShape[k] >= 0 ); - assert( hFdCngCom->sidNoiseEst[k] >= 0 ); - - /* add DELTA as it is done in FLC version, in order to avoid num > denom */ - facTab[k] = 0; - move16(); - IF( hFdCngDec->partNoiseShape[k] != 0 ) - { - s1 = norm_l( hFdCngCom->sidNoiseEst[k] ); - L_tmp = L_shl( hFdCngCom->sidNoiseEst[k], s1 ); /*Q31 - hFdCngCom->sidNoiseEstExp + s1*/ - L_tmp_exp = sub( hFdCngCom->sidNoiseEstExp, s1 ); - L_tmp = BASOP_Util_Add_Mant32Exp( L_tmp, L_tmp_exp, DELTA_MANTISSA_W32, DELTA_EXPONENT, &L_tmp_exp ); - L_tmp = L_shr( L_tmp, 1 ); - s = add( L_tmp_exp, 1 ); - num = extract_h( L_tmp ); /*Q15 - L_tmp_exp*/ - - s1 = norm_l( hFdCngDec->partNoiseShape[k] ); - L_tmp = L_shl( hFdCngDec->partNoiseShape[k], s1 ); /*Q31 - hFdCngDec->partNoiseShape_exp + s1*/ - L_tmp_exp = sub( hFdCngDec->partNoiseShape_exp, s1 ); - L_tmp = BASOP_Util_Add_Mant32Exp( L_tmp, L_tmp_exp, DELTA_MANTISSA_W32, DELTA_EXPONENT, &L_tmp_exp ); - s = sub( s, L_tmp_exp ); - denom = extract_h( L_tmp ); /*Q15 - L_tmp_exp*/ - - facTab[k] = div_s( num, denom ); /*Q15 - s*/ - move16(); - facTabExp[k] = s; - move16(); - } - /* Set unique exponent, if mantissa is equal to zero */ - if ( facTab[k] == 0 ) - { - facTabExp[k] = -( WORD32_BITS - 1 ); - move16(); - } - s2 = s_max( s2, facTabExp[k] ); - } - - FOR( k = 0; k < hFdCngCom->nFFTpart; k++ ) - { - s = sub( facTabExp[k], s2 ); - s = s_max( s_min( s, WORD32_BITS - 1 ), -( WORD32_BITS - 1 ) ); - FOR( ; j <= hFdCngCom->part[k]; j++ ) - { - cngNoiseLevel[j] = L_shl( Mpy_32_16_1( hFdCngDec->bandNoiseShape[j], facTab[k] ), s ); /*Q31 - hFdCngDec->bandNoiseShape_exp*/ - move32(); - } - } - - /* adapt scaling for rest of the buffer */ - IF( NE_16( s2, -( WORD32_BITS - 1 ) ) ) - { - s = sub( *cngNoiseLevel_exp, add( hFdCngDec->bandNoiseShape_exp, s2 ) ); - FOR( ; k < hFdCngCom->npart; k++ ) - { - FOR( ; j <= hFdCngCom->part[k]; j++ ) - { - cngNoiseLevel[j] = L_shl( cngNoiseLevel[j], s ); /*Q31 - hFdCngDec->bandNoiseShape_exp + s*/ - move32(); - } - } - - *cngNoiseLevel_exp = add( hFdCngDec->bandNoiseShape_exp, s2 ); - move16(); - } - } - ELSE - { - /* This sets the new CNG levels until a SID update overwrites it */ - test(); - test(); - test(); - IF( !( EQ_16( st->element_mode, IVAS_CPE_TD ) ) || ( EQ_16( st->element_mode, IVAS_CPE_TD ) && !hFdCngDec->flag_dtx_mode && !st->VAD ) ) - { - Copy32( hFdCngDec->bandNoiseShape, cngNoiseLevel, nBins ); /*Q31 - hFdCngDec->bandNoiseShape_exp*/ - *cngNoiseLevel_exp = hFdCngDec->bandNoiseShape_exp; - move16(); - } - } - /*st->cngTDLevel = (float)sqrt( (sumFLOAT(cngNoiseLevel, hFdCngCom->stopFFTbin - hFdCngCom->startBand) / 2 * hFdCngCom->fftlen) / st->Mode2_L_frame);*/ - tmp_loop = sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); - L_tmp = L_deposit_h( 0 ); - L_c = L_deposit_h( 0 ); - FOR( j = 0; j < tmp_loop; j++ ) - { - - Carry = 0; - move16(); - L_tmp = L_add_co( L_tmp, *( cngNoiseLevel + j ), &Carry, &Overflow ); /*Q31*/ - Overflow = 0; - move16(); - - IF( *( cngNoiseLevel + j ) < 0 ) - { - L_c = L_msuNs( L_c, 0, 0 ); /*Q-1*/ - } - IF( *( cngNoiseLevel + j ) >= 0 ) - { - L_c = L_macNs_co( L_c, 0, 0, &Carry, &Overflow ); /*Q-1*/ - } - } - L_tmp = norm_llQ31( L_c, L_tmp, &L_tmp_exp ); /*Q31 - L_tmp_exp*/ - L_tmp_exp = sub( add( L_tmp_exp, *cngNoiseLevel_exp ), 1 ); - - L_tmp = Mpy_32_16_1( L_tmp, hFdCngCom->fftlen ); /*Q16 - L_tmp_exp*/ - - L_tmp = Mpy_32_16_1( L_tmp, T_DIV_L_Frame[L_shl( L_mac( -28000, st->L_frame, 95 ), 1 - 15 )] ); /*Q16,exp -7*/ - L_tmp_exp = add( L_tmp_exp, -7 ); /*->Q16, L_tmp_exp */ - L_tmp_exp = add( L_tmp_exp, 31 - 16 ); /*->Q31, L_tmp_exp*/ - - st->cngTDLevel = round_fx_sat( Sqrt32( L_tmp, &L_tmp_exp ) ); /*Q15 - L_tmp_exp*/ - st->cngTDLevel_e = L_tmp_exp; - move16(); - } - ELSE IF( EQ_16( st->element_mode, IVAS_CPE_TD ) || EQ_16( st->element_mode, IVAS_CPE_DFT ) ) - { - IF( hFdCngCom->active_frame_counter > 0 ) - { - /* Perform noise estimation in active frames in the decoder for downward updates */ - perform_noise_estimation_dec_fx( timeDomainInput, Q, hFdCngDec ); - } - } - test(); - test(); - L_tmp = 0; - FOR( j = hFdCngCom->startBand; j < hFdCngCom->stopFFTbin; j++ ) - { - L_tmp = L_add( L_tmp, L_shr( cngNoiseLevel[j], 16 ) ); - } - L_tmp_exp = add( *cngNoiseLevel_exp, 16 ); - test(); - test(); - IF( EQ_16( concealWholeFrame, 1 ) && EQ_16( st->nbLostCmpt, 1 ) && ( GT_32( L_shl_o( L_tmp, L_tmp_exp, &Overflow ), 21474836 ) /*0.01f Q31*/ ) ) - { - /* update isf cng estimate for concealment. Do that during concealment, in order to avoid addition clean channel complexity*/ - lpc_from_spectrum( hFdCngCom, hFdCngCom->startBand, hFdCngCom->stopFFTbin, 0 ); - E_LPC_a_lsp_conversion( hFdCngCom->A_cng, lsp_cng, st->lspold_cng, M ); - Copy( lsp_cng, st->lspold_cng, M ); /*Q15*/ - - lsp2lsf_fx( lsp_cng, st->lsf_cng, M, st->sr_core ); - st->plcBackgroundNoiseUpdated = 1; - move16(); - } - BREAK; - - case SID_FRAME: - - hFdCngDec->flag_dtx_mode = 1; - move16(); - /* no break */ - - case ZERO_FRAME: - - test(); - IF( st != NULL && st->cng_type == LP_CNG ) - { - /* Perform noise estimation on inactive phase at the decoder */ - perform_noise_estimation_dec_fx( timeDomainInput, Q, hFdCngDec ); - /* Update the shaping parameters */ - - test(); - IF( NE_16( st->element_mode, IVAS_CPE_TD ) && NE_16( st->element_mode, IVAS_CPE_DFT ) ) - { - scalebands( hFdCngDec->msNoiseEst, hFdCngDec->part_shaping, hFdCngDec->nFFTpart_shaping, hFdCngDec->midband_shaping, hFdCngDec->nFFTpart_shaping, sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ), hFdCngDec->bandNoiseShape, 1 ); - } - hFdCngDec->bandNoiseShape_exp = hFdCngDec->msNoiseEst_exp; - move16(); - /* This sets the new CNG levels until a SID update overwrites it */ - Copy32( hFdCngDec->bandNoiseShape, cngNoiseLevel, sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ) ); /* This sets the new CNG levels until a SID update overwrites it Q31 - hFdCngDec->bandNoiseShape_exp*/ - *cngNoiseLevel_exp = hFdCngDec->bandNoiseShape_exp; - move16(); - /*st->cngTDLevel = (float)sqrt( (sumFLOAT(cngNoiseLevel, hFdCngCom->stopFFTbin - hFdCngCom->startBand) / 2 * hFdCngCom->fftlen) / st->Mode2_L_frame);*/ - tmp_loop = sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); - L_tmp = L_deposit_h( 0 ); - L_c = L_deposit_h( 0 ); - FOR( j = 0; j < tmp_loop; j++ ) - { - - Carry = 0; - move16(); - L_tmp = L_add_co( L_tmp, *( cngNoiseLevel + j ), &Carry, &Overflow ); /*Q31*/ - Overflow = 0; - move16(); - - IF( *( cngNoiseLevel + j ) < 0 ) - { - L_c = L_msuNs_co( L_c, 0, 0, &Carry, &Overflow ); /*Q-1*/ - } - IF( *( cngNoiseLevel + j ) >= 0 ) - { - L_c = L_macNs_co( L_c, 0, 0, &Carry, &Overflow ); /*Q-1*/ - } - } - L_tmp = norm_llQ31( L_c, L_tmp, &L_tmp_exp ); /*Q31 - L_tmp_exp*/ - L_tmp_exp = sub( add( L_tmp_exp, *cngNoiseLevel_exp ), 1 ); - - L_tmp = Mpy_32_16_1( L_tmp, hFdCngCom->fftlen ); /*Q16 - L_tmp_exp*/ - - L_tmp = Mpy_32_16_1( L_tmp, T_DIV_L_Frame[L_shl( L_mac( -28000, st->L_frame, 95 ), 1 - 15 )] ); /*Q16,exp -7*/ - L_tmp_exp = add( L_tmp_exp, -7 ); /*->Q16, L_tmp_exp */ - L_tmp_exp = add( L_tmp_exp, 31 - 16 ); /*->Q31, L_tmp_exp*/ - - st->cngTDLevel = round_fx_o( Sqrt32( L_tmp, &L_tmp_exp ), &Overflow ); /*Q15 - L_tmp_exp*/ - move16(); - st->cngTDLevel_e = L_tmp_exp; - move16(); - BREAK; - } - hFdCngCom->inactive_frame_counter = add( hFdCngCom->inactive_frame_counter, 1 ); - move16(); - - /************************************* - * SID_FRAME or ZERO_FRAME at DECODER * - *************************************/ - - /* Detect first non-active frame */ - IF( EQ_16( hFdCngCom->inactive_frame_counter, 1 ) ) - { - /* Compute the fine spectral structure of the comfort noise shape using the decoder-side noise estimates */ - bandcombinepow( - hFdCngDec->bandNoiseShape, - hFdCngDec->bandNoiseShape_exp, - nBins, - hFdCngCom->part, - hFdCngCom->nFFTpart, - hFdCngCom->psize_inv, - hFdCngDec->partNoiseShape, - &hFdCngDec->partNoiseShape_exp ); - } - - IF( EQ_16( st->m_frame_type, SID_FRAME ) ) - { - IF( LT_32( hFdCngCom->msFrCnt_init_counter, L_deposit_l( hFdCngCom->msFrCnt_init_thresh ) ) ) - { - /* At initialization, interpolate the bin/band-wise levels from the partition levels */ - scalebands( hFdCngCom->sidNoiseEst, hFdCngCom->part, hFdCngCom->npart, hFdCngCom->midband, - hFdCngCom->nFFTpart, sub( hFdCngCom->stopBand, hFdCngCom->startBand ), cngNoiseLevel, 1 ); - *cngNoiseLevel_exp = hFdCngCom->sidNoiseEstExp; - move16(); - } - ELSE - { - if ( EQ_16( st->element_mode, IVAS_CPE_DFT ) ) - { - } - - /* Interpolate the CLDFB band levels from the SID (partition) levels */ - IF( GT_16( hFdCngCom->regularStopBand, hFdCngCom->numCoreBands ) ) - { - scalebands( hFdCngCom->sidNoiseEst, hFdCngCom->part, hFdCngCom->npart, hFdCngCom->midband, - hFdCngCom->nFFTpart, sub( hFdCngCom->stopBand, hFdCngCom->startBand ), cngNoiseLevel, 0 ); - *cngNoiseLevel_exp = hFdCngCom->sidNoiseEstExp; - move16(); - } - - s2 = -( WORD32_BITS - 1 ); - move16(); - /* Shape the SID noise levels in each FFT bin */ - j = 0; - move16(); - FOR( k = 0; k < hFdCngCom->nFFTpart; k++ ) - { - assert( hFdCngDec->partNoiseShape[k] >= 0 ); - - /* add DELTA as it is done in FLC version, in order to avoid num > denom */ - facTab[k] = 0; - move16(); - IF( hFdCngDec->partNoiseShape[k] != 0 ) - { - s1 = norm_l( hFdCngCom->sidNoiseEst[k] ); - L_tmp = L_shl( hFdCngCom->sidNoiseEst[k], s1 ); /*Q31 - hFdCngCom->sidNoiseEstExp + s1*/ - L_tmp_exp = sub( hFdCngCom->sidNoiseEstExp, s1 ); - L_tmp = BASOP_Util_Add_Mant32Exp( hFdCngCom->sidNoiseEst[k], hFdCngCom->sidNoiseEstExp, DELTA_MANTISSA_W32, DELTA_EXPONENT, &L_tmp_exp ); - L_tmp = L_shr( L_tmp, 1 ); - s = add( L_tmp_exp, 1 ); - num = extract_h( L_tmp ); /*Q15 - L_tmp_exp*/ - - s1 = norm_l( hFdCngDec->partNoiseShape[k] ); - L_tmp = L_shl( hFdCngDec->partNoiseShape[k], s1 ); /*Q31 - hFdCngDec->partNoiseShape_exp + s1*/ - L_tmp_exp = sub( hFdCngDec->partNoiseShape_exp, s1 ); - L_tmp = BASOP_Util_Add_Mant32Exp( L_tmp, L_tmp_exp, DELTA_MANTISSA_W32, DELTA_EXPONENT, &L_tmp_exp ); - s = sub( s, L_tmp_exp ); - denom = extract_h( L_tmp ); /*Q15 - L_tmp_exp*/ - - facTab[k] = div_s( num, denom ); /*Q15 - s*/ - move16(); - facTabExp[k] = s; - move16(); - } - /* Set unique exponent, if mantissa is equal to zero */ - if ( facTab[k] == 0 ) - { - facTabExp[k] = -( WORD32_BITS - 1 ); - move16(); - } - s2 = s_max( s2, facTabExp[k] ); - } - - FOR( k = 0; k < hFdCngCom->nFFTpart; k++ ) - { - s = sub( facTabExp[k], s2 ); - s = s_max( s_min( s, WORD32_BITS - 1 ), -( WORD32_BITS - 1 ) ); - FOR( ; j <= hFdCngCom->part[k]; j++ ) - { - cngNoiseLevel[j] = L_shl( Mpy_32_16_1( hFdCngDec->bandNoiseShape[j], facTab[k] ), s ); /*Q31 - hFdCngDec->bandNoiseShape_exp*/ - move32(); - } - } - /* adapt scaling for rest of the buffer */ - s = sub( *cngNoiseLevel_exp, add( hFdCngDec->bandNoiseShape_exp, s2 ) ); - FOR( ; k < hFdCngCom->npart; k++ ) - { - FOR( ; j <= hFdCngCom->part[k]; j++ ) - { - cngNoiseLevel[j] = L_shl( cngNoiseLevel[j], s ); /*Q31 - hFdCngDec->bandNoiseShape_exp + s*/ - move32(); - } - } - *cngNoiseLevel_exp = add( hFdCngDec->bandNoiseShape_exp, s2 ); - move16(); - } - } - - IF( EQ_16( st->codec_mode, MODE2 ) ) - { - /* Generate comfort noise during SID or zero frames */ - generate_comfort_noise_dec_fx( cldfbBufferReal, cldfbBufferImag, cldfbBufferScale, st, &( st->Q_exc ), 2, -1 ); - } - - BREAK; - - default: - return -1; - } - - - return 0; -} -#endif -Word16 ApplyFdCng_ivas_fx( Word16 *timeDomainInput, /* i : pointer to time domain input Q*/ Word16 Q, Word32 *powerSpectrum, /*Q_power_spectrum*/ @@ -1113,27 +657,22 @@ Word16 ApplyFdCng_ivas_fx( ( !st->BER_detect ) ) { /* Perform noise estimation at the decoder */ -#ifdef REMOVE_EVS_DUPLICATES IF( EQ_16( st->element_mode, EVS_MONO ) ) { perform_noise_estimation_dec_fx( timeDomainInput, Q, hFdCngDec ); } ELSE -#endif { perform_noise_estimation_dec_ivas_fx( timeDomainInput, Q, powerSpectrum, Q_power_spectrum, hFdCngDec, st->element_mode, st->bwidth, L_frame, last_L_frame, st->last_core_brate, st->VAD ); } /* Update the shaping parameters */ test(); -#ifdef REMOVE_EVS_DUPLICATES IF( EQ_16( st->element_mode, EVS_MONO ) ) { scalebands( hFdCngDec->msNoiseEst, hFdCngDec->part_shaping, hFdCngDec->nFFTpart_shaping, hFdCngDec->midband_shaping, hFdCngDec->nFFTpart_shaping, nBins, hFdCngDec->bandNoiseShape, 1 ); } - ELSE -#endif - IF( NE_16( st->element_mode, IVAS_CPE_TD ) && NE_16( st->element_mode, IVAS_CPE_DFT ) ) + ELSE IF( NE_16( st->element_mode, IVAS_CPE_TD ) && NE_16( st->element_mode, IVAS_CPE_DFT ) ) { scalebands_fx( hFdCngDec->msNoiseEst, hFdCngDec->part_shaping, hFdCngDec->nFFTpart_shaping, hFdCngDec->midband_shaping, hFdCngDec->nFFTpart_shaping, nBins, hFdCngDec->bandNoiseShape, 1 ); } @@ -1369,13 +908,11 @@ Word16 ApplyFdCng_ivas_fx( IF( hFdCngCom->active_frame_counter > 0 ) { /* Perform noise estimation in active frames in the decoder for downward updates */ -#ifdef REMOVE_EVS_DUPLICATES IF( EQ_16( st->element_mode, EVS_MONO ) ) { perform_noise_estimation_dec_fx( timeDomainInput, Q, hFdCngDec ); } ELSE -#endif { perform_noise_estimation_dec_ivas_fx( timeDomainInput, Q, powerSpectrum, Q_power_spectrum, hFdCngDec, st->element_mode, st->bwidth, L_frame, last_L_frame, st->last_core_brate, st->VAD ); } @@ -1436,44 +973,37 @@ Word16 ApplyFdCng_ivas_fx( IF( st != NULL && EQ_16( st->cng_type, LP_CNG ) ) { /* Perform noise estimation on inactive phase at the decoder */ -#ifdef REMOVE_EVS_DUPLICATES IF( EQ_16( st->element_mode, EVS_MONO ) ) { perform_noise_estimation_dec_fx( timeDomainInput, Q, hFdCngDec ); } ELSE -#endif { perform_noise_estimation_dec_ivas_fx( timeDomainInput, Q, powerSpectrum, Q_power_spectrum, hFdCngDec, st->element_mode, st->bwidth, L_frame, last_L_frame, st->last_core_brate, st->VAD ); } /* Update the shaping parameters */ - test(); -#ifdef REMOVE_EVS_DUPLICATES IF( EQ_16( st->element_mode, EVS_MONO ) ) { scalebands( hFdCngDec->msNoiseEst, hFdCngDec->part_shaping, hFdCngDec->nFFTpart_shaping, hFdCngDec->midband_shaping, hFdCngDec->nFFTpart_shaping, sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ), hFdCngDec->bandNoiseShape, 1 ); } - ELSE -#endif - IF( NE_16( st->element_mode, IVAS_CPE_TD ) && NE_16( st->element_mode, IVAS_CPE_DFT ) ) + ELSE IF( NE_16( st->element_mode, IVAS_CPE_TD ) && NE_16( st->element_mode, IVAS_CPE_DFT ) ) { scalebands_fx( hFdCngDec->msNoiseEst, hFdCngDec->part_shaping, hFdCngDec->nFFTpart_shaping, hFdCngDec->midband_shaping, hFdCngDec->nFFTpart_shaping, sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ), hFdCngDec->bandNoiseShape, 1 ); } hFdCngDec->bandNoiseShape_exp = hFdCngDec->msNoiseEst_exp; move16(); + /* This sets the new CNG levels until a SID update overwrites it */ Copy32( hFdCngDec->bandNoiseShape, cngNoiseLevel, sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ) ); /* This sets the new CNG levels until a SID update overwrites it */ /*Q31 - hFdCngDec->bandNoiseShape_exp*/ -#ifdef REMOVE_EVS_DUPLICATES IF( EQ_16( st->element_mode, EVS_MONO ) ) { *cngNoiseLevel_exp = hFdCngDec->bandNoiseShape_exp; move16(); } ELSE -#endif { Word16 shift1 = L_norm_arr( cngNoiseLevel, sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ) ); Word16 shift2 = L_norm_arr( cngNoiseLevel + sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ), sub( FFTCLDFBLEN, sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ) ) ); @@ -1554,16 +1084,15 @@ Word16 ApplyFdCng_ivas_fx( IF( LT_32( hFdCngCom->msFrCnt_init_counter, L_deposit_l( hFdCngCom->msFrCnt_init_thresh ) ) ) { /* At initialization, interpolate the bin/band-wise levels from the partition levels */ -#ifdef REMOVE_EVS_DUPLICATES IF( EQ_16( st->element_mode, EVS_MONO ) ) { scalebands( hFdCngCom->sidNoiseEst, hFdCngCom->part, hFdCngCom->npart, hFdCngCom->midband, hFdCngCom->nFFTpart, sub( hFdCngCom->stopBand, hFdCngCom->startBand ), cngNoiseLevel, 1 ); } ELSE -#endif { scalebands_fx( hFdCngCom->sidNoiseEst, hFdCngCom->part, hFdCngCom->npart, hFdCngCom->midband, hFdCngCom->nFFTpart, sub( hFdCngCom->stopBand, hFdCngCom->startBand ), cngNoiseLevel, 1 ); } + *cngNoiseLevel_exp = hFdCngCom->sidNoiseEstExp; move16(); } @@ -1576,13 +1105,11 @@ Word16 ApplyFdCng_ivas_fx( /* Interpolate the CLDFB band levels from the SID (partition) levels */ IF( GT_16( hFdCngCom->regularStopBand, hFdCngCom->numCoreBands ) ) { -#ifdef REMOVE_EVS_DUPLICATES IF( EQ_16( st->element_mode, EVS_MONO ) ) { scalebands( sidNoiseEst, hFdCngCom->part, hFdCngCom->npart, hFdCngCom->midband, hFdCngCom->nFFTpart, sub( hFdCngCom->stopBand, hFdCngCom->startBand ), cngNoiseLevel, 0 ); } ELSE -#endif { scalebands_fx( sidNoiseEst, hFdCngCom->part, hFdCngCom->npart, hFdCngCom->midband, hFdCngCom->nFFTpart, sub( hFdCngCom->stopBand, hFdCngCom->startBand ), cngNoiseLevel, 0 ); } @@ -1649,7 +1176,6 @@ Word16 ApplyFdCng_ivas_fx( } } -#ifdef REMOVE_EVS_DUPLICATES IF( EQ_16( st->element_mode, EVS_MONO ) ) { /* adapt scaling for rest of the buffer */ @@ -1666,7 +1192,6 @@ Word16 ApplyFdCng_ivas_fx( move16(); } ELSE -#endif { Word16 shift1 = L_norm_arr( cngNoiseLevel, j ); Word16 shift2 = L_norm_arr( &cngNoiseLevel[j], sub( FFTCLDFBLEN, j ) ); @@ -1755,13 +1280,11 @@ Word16 ApplyFdCng_ivas_fx( IF( EQ_16( st->codec_mode, MODE2 ) ) { /* Generate comfort noise during SID or zero frames */ -#ifdef REMOVE_EVS_DUPLICATES IF( EQ_16( st->element_mode, EVS_MONO ) ) { generate_comfort_noise_dec_fx( cldfbBufferReal, cldfbBufferImag, cldfbBufferScale, st, &( st->Q_exc ), 2, -1 ); } ELSE -#endif { generate_comfort_noise_dec_ivas_fx( cldfbBufferReal, cldfbBufferImag, cldfbBufferScale, st, &( st->Q_exc ), 2, -1 ); } diff --git a/lib_dec/gain_dec_fx.c b/lib_dec/gain_dec_fx.c index 00eca187d..db325cd80 100644 --- a/lib_dec/gain_dec_fx.c +++ b/lib_dec/gain_dec_fx.c @@ -602,7 +602,6 @@ void gain_dec_mless_fx( /* _ None */ /*==================================================================================*/ -#ifndef REMOVE_EVS_DUPLICATES void gain_dec_lbr_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ const Word16 coder_type, /* i : coding type */ @@ -653,375 +652,6 @@ void gain_dec_lbr_fx( ctype = shl( sub( coder_type, 1 ), 1 ); - /*-----------------------------------------------------------------* - * calculate prediction of gcode - * search for the best codeword - *-----------------------------------------------------------------*/ - IF( i_subfr == 0 ) - { - b_fx = b_1sfr_fx; - move16(); - n_pred = 2; - move16(); - cdbk_fx = gp_gamma_1sfr_6b_fx; - SWITCH( nBits ) - { - case 8: - { - cdbk_fx = gp_gamma_1sfr_8b_fx; /* Q14/Q9*/ - BREAK; - } - case 7: - { - cdbk_fx = gp_gamma_1sfr_7b_fx; /* Q14/Q9*/ - BREAK; - } - case 6: - { - cdbk_fx = gp_gamma_1sfr_6b_fx; /* Q14/Q9*/ - BREAK; - } - } - - /* calculate predicted gain */ - aux_fx[0] = 4096; /*Q12*/ - move16(); - aux_fx[1] = shl( ctype, 12 ); /*Q12*/ - move16(); - - /* gcode0 = (float)pow(10, dotp(b, aux, n_pred) - 0.5f * (float)log10(Ecode)); - gcode0 = (float)pow(10, dotp(b, aux, n_pred) - 0.05f * 10 * (float)log10(Ecode)); - gcode0 = (float)pow(10, 0.05(20 * dotp(b, aux, n_pred) - 10 * (float)log10(Ecode))); */ - - e_tmp = norm_l( L_tmp2 ); - f_tmp = Log2_norm_lc( L_shl( L_tmp2, e_tmp ) ); /*Q15*/ - e_tmp = sub( expg2, add( 1, e_tmp ) ); - L_tmp1 = Mpy_32_16( e_tmp, f_tmp, 12330 ); /* Q13 */ /* 10*log10(2) in Q12*/ - - L_tmp = Dot_product( b_fx, aux_fx, n_pred ); /*Q25*/ - L_tmp = Mult_32_16( L_tmp, 160 ); /*Q13, 20 in Q3*/ - L_tmp = L_sub( L_tmp, L_tmp1 ); /*Q13*/ - - gcode0_fx = round_fx( L_shl( L_tmp, 11 ) ); /* Q8 */ - - - /*-----------------------------------------------------------------* - * gcode0 = pow(10.0, gcode0/20) - * = pow(2, 3.321928*gcode0/20) - * = pow(2, 0.166096*gcode0) - *-----------------------------------------------------------------*/ - - L_tmp = L_mult( gcode0_fx, 21771 ); /* *0.166096 in Q17 -> Q26 */ - L_tmp = L_shr( L_tmp, 10 ); /* From Q26 to Q16 */ - frac = L_Extract_lc( L_tmp, &exp_gcode0 ); /* Extract exponent of gcode0 */ - - gcode0_fx = extract_l( Pow2( 14, frac ) ); /* Put 14 as exponent so that */ - /* output of Pow2() will be: */ - /* 16384 < Pow2() <= 32767 */ - exp_gcode0 = sub( exp_gcode0, 14 ); - - /* retrieve the codebook index and calculate both gains */ - /*index = (Word16)get_indice( st_fx,"gain", i_subfr, ACELP_CORE);move16();*/ - index = (Word16) get_next_indice_fx( st_fx, nBits ); /*Q0*/ - move16(); - - *gain_pit_fx = cdbk_fx[index * 2]; /*Q14*/ - move16(); - - L_tmp = L_mult( cdbk_fx[( ( index * 2 ) + 1 )], gcode0_fx ); /* Q9*Q0 -> Q10 */ - *gain_code_fx = L_shl_sat( L_tmp, add( exp_gcode0, 6 ) ); /* Q10 -> Q16*/ - move16(); - - gc_mem[0] = *gain_code_fx; /*Q16*/ - move32(); - gp_mem[0] = *gain_pit_fx; /*Q14*/ - move16(); - } - ELSE IF( EQ_16( i_subfr, L_SUBFR ) || EQ_16( L_subfr, 2 * L_SUBFR ) ) - { - b_fx = b_2sfr_fx; /*Q12*/ - move16(); - n_pred = 4; - move16(); - - cdbk_fx = gp_gamma_1sfr_6b_fx; /*Q14/Q9 */ - SWITCH( nBits ) - { - case 7: - { - cdbk_fx = gp_gamma_2sfr_7b_fx; /* Q14/Q9*/ - BREAK; - } - case 6: - { - cdbk_fx = gp_gamma_2sfr_6b_fx; /* Q14/Q9*/ - BREAK; - } - } - - /* calculate predicted gain */ - aux_fx[0] = 4096; /*Q12*/ - move16(); - aux_fx[1] = shl( ctype, 12 ); /*Q12*/ - move16(); - - /*aux_fx[2] = (float)log10(gc_mem[0]); - = log2(gc_mem[0])*log10(2);*/ - e_tmp = norm_l( gc_mem[0] ); - f_tmp = Log2_norm_lc( L_shl( gc_mem[0], e_tmp ) ); /*Q15*/ - e_tmp = sub( sub( 30, e_tmp ), 16 ); /*Q_format(gc_mem[0])=16*/ - L_tmp1 = Mpy_32_16( e_tmp, f_tmp, 9864 ); /* Q16 */ - aux_fx[2] = round_fx( L_shl( L_tmp1, 12 ) ); /* Q12 */ - move16(); - - aux_fx[3] = shr( gp_mem[0], 2 ); /*Q12*/ - move16(); - - /*-----------------------------------------------------------------* - * gcode0 = pow(10.0, dotp(b, aux, n_pred) - * = pow(2, 3.321928*dotp(b, aux, n_pred) - *-----------------------------------------------------------------*/ - L_tmp = Dot_product( b_fx, aux_fx, n_pred ); /*Q25*/ - L_tmp = Mult_32_16( L_tmp, 27213 ); /* *3.321928 in Q13 -> Q23 */ - L_tmp = L_shr( L_tmp, 7 ); /* From Q23 to Q16 */ - frac = L_Extract_lc( L_tmp, &exp_gcode0 ); /* Extract exponent of gcode0 */ - - gcode0_fx = extract_l( Pow2( 14, frac ) ); /* Put 14 as exponent so that */ - /* output of Pow2() will be: */ - /* 16384 < Pow2() <= 32767 */ - exp_gcode0 = sub( exp_gcode0, 14 ); - - /* retrieve the codebook index and calculate both gains */ - index = (Word16) get_next_indice_fx( st_fx, nBits ); /*Q0*/ - move16(); - - *gain_pit_fx = cdbk_fx[index * 2]; /*Q14*/ - move16(); - - L_tmp = L_mult( cdbk_fx[( ( index * 2 ) + 1 )], gcode0_fx ); /* Q9*Q0 -> Q10 */ - *gain_code_fx = L_shl_sat( L_tmp, add( exp_gcode0, 6 ) ); /*Q16*/ - move16(); - - gc_mem[1] = *gain_code_fx; /*Q16*/ - move32(); - gp_mem[1] = *gain_pit_fx; /*Q14*/ - move16(); - } - ELSE IF( EQ_16( i_subfr, 2 * L_SUBFR ) ) - { - b_fx = b_3sfr_fx; - move16(); - n_pred = 6; - move16(); - - cdbk_fx = gp_gamma_3sfr_6b_fx; /*Q14/Q9 */ - - if ( EQ_16( nBits, 7 ) ) - { - cdbk_fx = gp_gamma_3sfr_7b_fx; /*Q14*/ - // PMT("verify if gp_gamma_3sfr_7b_fx is correct") - } - - /* calculate predicted gain */ - aux_fx[0] = 4096; /*Q12*/ - move16(); - aux_fx[1] = shl( ctype, 12 ); /*Q12*/ - move16(); - - /*aux_fx[2] = (float)log10(gc_mem[0]); - = log2(gc_mem[0])*log10(2);*/ - e_tmp = norm_l( gc_mem[0] ); - f_tmp = Log2_norm_lc( L_shl( gc_mem[0], e_tmp ) ); /*Q15*/ - e_tmp = sub( sub( 30, e_tmp ), 16 ); /*Q_format(gc_mem[0])=16*/ - L_tmp1 = Mpy_32_16( e_tmp, f_tmp, 9864 ); /* Q16 */ - aux_fx[2] = round_fx( L_shl( L_tmp1, 12 ) ); /* Q12 */ - move16(); - - /*aux[3] = (float)log10(gc_mem[1]); - = log2(gc_mem[1])*log10(2);*/ - e_tmp = norm_l( gc_mem[1] ); - f_tmp = Log2_norm_lc( L_shl( gc_mem[1], e_tmp ) ); /*Q15*/ - e_tmp = sub( sub( 30, e_tmp ), 16 ); /*Q_format(gc_mem[1])=16*/ - L_tmp1 = Mpy_32_16( e_tmp, f_tmp, 9864 ); /* Q16 */ - aux_fx[3] = round_fx( L_shl( L_tmp1, 12 ) ); /* Q12 */ - move16(); - - aux_fx[4] = shr( gp_mem[0], 2 ); /*Q12*/ - move16(); - aux_fx[5] = shr( gp_mem[1], 2 ); /*Q12*/ - move16(); - - /*-----------------------------------------------------------------* - * gcode0 = pow(10.0, dotp(b, aux, n_pred) - * = pow(2, 3.321928*dotp(b, aux, n_pred) - *-----------------------------------------------------------------*/ - L_tmp = Dot_product( b_fx, aux_fx, n_pred ); /*Q25*/ - L_tmp = Mult_32_16( L_tmp, 27213 ); /* *3.321928 in Q13 -> Q23 */ - L_tmp = L_shr( L_tmp, 7 ); /* From Q23 to Q16 */ - frac = L_Extract_lc( L_tmp, &exp_gcode0 ); /* Extract exponent of gcode0 */ - - gcode0_fx = extract_l( Pow2( 14, frac ) ); /* Put 14 as exponent so that */ - /* output of Pow2() will be: */ - /* 16384 < Pow2() <= 32767 */ - exp_gcode0 = sub( exp_gcode0, 14 ); - - /* retrieve the codebook index and calculate both gains */ - index = (Word16) get_next_indice_fx( st_fx, nBits ); - move16(); - - *gain_pit_fx = cdbk_fx[( index * 2 )]; /*Q14*/ - move16(); - - L_tmp = L_mult( cdbk_fx[( ( index * 2 ) + 1 )], gcode0_fx ); /* Q9*Q0 -> Q10 */ - *gain_code_fx = L_shl_sat( L_tmp, add( exp_gcode0, 6 ) ); /* Q10 -> Q16*/ - move32(); - gc_mem[2] = *gain_code_fx; /*Q16*/ - move32(); - gp_mem[2] = *gain_pit_fx; /*Q14*/ - move16(); - } - ELSE IF( EQ_16( i_subfr, 3 * L_SUBFR ) ) - { - b_fx = b_4sfr_fx; /*Q12*/ - n_pred = 8; - move16(); - - - cdbk_fx = gp_gamma_4sfr_6b_fx; /*Q14*/ -#ifdef IVAS_GAIN_MOD - IF( EQ_16( nBits, 7 ) ) - { - cdbk_fx = gp_gamma_4sfr_7b_fx; - PMT( "verify if gp_gamma_4sfr_7b_fx is correct" ) - } -#endif - - /* calculate predicted gain */ - aux_fx[0] = 4096; /*Q12*/ - move16(); - aux_fx[1] = shl( ctype, 12 ); /*Q12*/ - move16(); - - /*aux[2] = (float)log10(gc_mem[0]); - = log2(gc_mem[0])*log10(2);*/ - e_tmp = norm_l( gc_mem[0] ); - f_tmp = Log2_norm_lc( L_shl( gc_mem[0], e_tmp ) ); /*Q15*/ - e_tmp = sub( sub( 30, e_tmp ), 16 ); /*Q_format(gc_mem[0])=16*/ - L_tmp1 = Mpy_32_16( e_tmp, f_tmp, 9864 ); /* Q16 */ - aux_fx[2] = round_fx( L_shl( L_tmp1, 12 ) ); /* Q12 */ - move16(); - - /*aux[3] = (float)log10(gc_mem[1]); - = log2(gc_mem[1])*log10(2);*/ - e_tmp = norm_l( gc_mem[1] ); - f_tmp = Log2_norm_lc( L_shl( gc_mem[1], e_tmp ) ); /*Q15*/ - e_tmp = sub( sub( 30, e_tmp ), 16 ); /*Q_format(gc_mem[1])=16*/ - L_tmp1 = Mpy_32_16( e_tmp, f_tmp, 9864 ); /* Q16 */ - aux_fx[3] = round_fx( L_shl( L_tmp1, 12 ) ); /* Q12 */ - move16(); - - /*aux[4] = (float)log10(gc_mem[2]); - = log2(gc_mem[2])*log10(2);*/ - e_tmp = norm_l( gc_mem[2] ); - f_tmp = Log2_norm_lc( L_shl( gc_mem[2], e_tmp ) ); /*Q15*/ - e_tmp = sub( sub( 30, e_tmp ), 16 ); /*Q_format(gc_mem[2])=16*/ - L_tmp1 = Mpy_32_16( e_tmp, f_tmp, 9864 ); /* Q16 */ - aux_fx[4] = round_fx( L_shl( L_tmp1, 12 ) ); /* Q12 */ - move16(); - - aux_fx[5] = shr( gp_mem[0], 2 ); /*Q12*/ - move16(); - aux_fx[6] = shr( gp_mem[1], 2 ); /*Q12*/ - move16(); - aux_fx[7] = shr( gp_mem[2], 2 ); /*Q12*/ - move16(); - - /*-----------------------------------------------------------------* - * gcode0 = pow(10.0, dotp(b, aux, n_pred) - * = pow(2, 3.321928*dotp(b, aux, n_pred) - *-----------------------------------------------------------------*/ - L_tmp = Dot_product( b_fx, aux_fx, n_pred ); /*Q25*/ - L_tmp = Mult_32_16( L_tmp, 27213 ); /* *3.321928 in Q13 -> Q23 */ - L_tmp = L_shr( L_tmp, 7 ); /* From Q23 to Q16 */ - frac = L_Extract_lc( L_tmp, &exp_gcode0 ); /* Extract exponent of gcode0 */ - - gcode0_fx = extract_l( Pow2( 14, frac ) ); /* Put 14 as exponent so that */ - /* output of Pow2() will be: */ - /* 16384 < Pow2() <= 32767 */ - exp_gcode0 = sub( exp_gcode0, 14 ); - - /* retrieve the codebook index and calculate both gains */ - index = (Word16) get_next_indice_fx( st_fx, nBits ); /*Q0*/ - move16(); - *gain_pit_fx = cdbk_fx[( index * 2 )]; /*Q14*/ - move16(); - - L_tmp = L_mult( cdbk_fx[( ( index * 2 ) + 1 )], gcode0_fx ); /* Q9*Q0 -> Q10 */ - *gain_code_fx = L_shl_sat( L_tmp, add( exp_gcode0, 6 ) ); /*Q16*/ - move32(); - } - - /* *norm_gain_code = *gain_code / *gain_inov; */ - expg = sub( norm_s( *gain_inov_fx ), 1 ); - expg = s_max( expg, 0 ); - - tmp_fx = div_s( shr( 8192, expg ), *gain_inov_fx ); /*Q15*/ - *norm_gain_code_fx = L_shr( Mult_32_16( *gain_code_fx, tmp_fx ), sub( 1, expg ) ); /*Q16*/ - move32(); - - return; -} -#endif -void gain_dec_lbr_ivas_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 coder_type, /* i : coding type */ - const Word16 i_subfr, /* i : subframe index */ - const Word16 *code_fx, /* i : algebraic excitation Q9 */ - Word16 *gain_pit_fx, /* o : quantized pitch gain Q14*/ - Word32 *gain_code_fx, /* o : quantized codebook gain Q16*/ - Word16 *gain_inov_fx, /* o : gain of the innovation (used for normalization) Q12*/ - Word32 *norm_gain_code_fx, /* o : norm. gain of the codebook excitation Q16*/ - Word32 gc_mem[], /* i/o: gain_code from previous subframes Q16*/ - Word16 gp_mem[], /* i/o: gain_pitch from previous subframes Q14*/ - const Word16 L_subfr /* i : subfr lenght */ -) -{ - Word16 index, nBits, n_pred, ctype; - Word16 gcode0_fx, aux_fx[10]; - Word32 L_tmp, L_tmp1, L_tmp2; - Word16 expg, expg2, e_tmp, exp_gcode0, f_tmp, frac, tmp_fx; - const Word16 *b_fx, *cdbk_fx = 0; - /* Ecode = ( dotp( code, code, L_SUBFR ) + 0.01f ) / L_SUBFR; - *gain_inov = 1.0f / (float)sqrt(Ecode); */ - Word16 shift_L_subfr; - shift_L_subfr = 6; - move16(); // for *cdbk_fx - move16(); - if ( GT_16( L_subfr, L_SUBFR ) ) - { - shift_L_subfr = add( shift_L_subfr, 1 ); - } - L_tmp = Dot_product12( code_fx, code_fx, L_subfr, &expg ); /*Q31 - expg*/ - expg = sub( expg, add( 18, shift_L_subfr ) ); /* exp: -18 (code in Q9), -6 (/L_SUBFR) */ - - expg2 = expg; - move16(); - L_tmp2 = L_tmp; /* sets to 'L_tmp' in 1 clock */ - move32(); - L_tmp = Isqrt_lc( L_tmp, &expg ); /*Q31 - expg*/ - - *gain_inov_fx = extract_h( L_shl_sat( L_tmp, sub( expg, 3 ) ) ); /* gain_inov in Q12 */ - move16(); - - /*-----------------------------------------------------------------* - * select the codebook, size and number of bits - * set the gains searching range - *-----------------------------------------------------------------*/ - nBits = st_fx->acelp_cfg.gains_mode[shr( i_subfr, shift_L_subfr )]; - move16(); - - ctype = shl( sub( coder_type, 1 ), 1 ); - /*-----------------------------------------------------------------* * calculate prediction of gcode * search for the best codeword @@ -1583,24 +1213,28 @@ void lp_gain_updt_ivas_fx( } /*-------------------------------------------------* - * Gain_dec_gaus_vbr + * gain_dec_gaus_fx() * * Decode gains of purely unvoiced sounds *-------------------------------------------------*/ -Word32 gain_dec_gaus_fx( /* o : quantized codebook gain Q16 */ - Word16 index, /* i : quantization index */ - const Word16 bits, /* i : number of bits to quantize */ - const Word16 lowBound, /* i : lower bound of quantizer (dB) */ - const Word16 topBound, /* i : upper bound of quantizer (dB) */ - const Word16 inv_gain_inov, /* o : unscaled innovation gain Q12 */ - Word32 *L_norm_gain_code /* o : gain of normalized gaussian excitation Q16 */ + +/*! r: quantized codebook gain Q16 */ +Word32 gain_dec_gaus_fx( + Word16 index, /* i : quantization index */ + const Word16 bits, /* i : number of bits to quantize */ + const Word16 lowBound, /* i : lower bound of quantizer (dB) */ + const Word16 topBound, /* i : upper bound of quantizer (dB) */ + const Word16 inv_gain_inov, /* o : unscaled innovation gain Q12 */ + Word32 *L_norm_gain_code /* o : gain of normalized gaussian excitation Q16 */ ) { Word16 stepSize, gain, expg, frac, expi, tmp_igi; Word32 L_tmp, L_enr_q, L_gain; Word16 stepSize_Exp; + stepSize_Exp = 14; move16(); + /*------------------------------------------------------------------------------------------* * Quantize linearly the log E *------------------------------------------------------------------------------------------*/ diff --git a/lib_dec/gs_dec_fx.c b/lib_dec/gs_dec_fx.c index cf0fabc76..70639810c 100644 --- a/lib_dec/gs_dec_fx.c +++ b/lib_dec/gs_dec_fx.c @@ -23,7 +23,7 @@ /* _ (Word16[]) voice_factors_fx: frame error rate Q15 */ /*--------------------------------------------------------------------------*/ /* INPUT/OUTPUT ARGUMENTS : */ -/* Decoder_State *st_fx : decoder memory structure */ +/* Decoder_State *st_fx : decoder memory structure */ /* _ (Word16[]) exc_fx : adapt. excitation exc (Q_exc) */ /* _ (Word16[]) exc2_fx : adapt. excitation/total exc (Q_exc) */ /*--------------------------------------------------------------------------*/ @@ -31,439 +31,17 @@ /* _ None */ /*==========================================================================*/ -#ifndef REMOVE_EVS_DUPLICATES void decod_audio_fx( - Decoder_State *st_fx, /* i/o: decoder static memory */ - Word16 dct_epit[], /* o : GSC excitation in DCT domain Qx*/ - const Word16 *Aq, /* i : LP filter coefficient Q12*/ - Word16 *pitch_buf, /* o : floating pitch values for each subframe Q6*/ - Word16 *voice_factors, /* o : voicing factors Q15*/ - Word16 *exc, /* i/o: adapt. excitation exc Q_exc*/ - Word16 *exc2, /* i/o: adapt. excitation/total exc Q_exc*/ - Word16 *bwe_exc, /* o : excitation for SWB TBE Q_exc*/ - Word16 *lsf_new /* i : ISFs at the end of the frame Qx*/ - , - Word16 *gain_buf /*Q14*/ -) -{ - Word16 tmp_nb_bits_tot, pit_band_idx; - Word16 code[4 * L_SUBFR]; - Word16 Diff_len, nb_subfr, i; - Word16 nb_frame_flg; - Word16 Es_pred = 0; - Word16 Len, max_len; - Word16 gsc_attack_flag; - - Word16 low_pit; - Word16 last_bin; - Word16 nbits; - - Word16 exc_wo_nf[L_FRAME16k]; - GSC_DEC_HANDLE hGSCDec; - hGSCDec = st_fx->hGSCDec; - - - /*---------------------------------------------------------------* - * Initialization - *---------------------------------------------------------------*/ - move16(); // corresponding to initialization of Es_pred - Diff_len = 0; - move16(); - - /* decode GSC attack flag (used to reduce possible pre-echo) */ - gsc_attack_flag = (Word16) get_next_indice_fx( st_fx, 1 ); /* Q0 */ - move16(); - - /* decode GSC SWB speech flag */ - test(); - IF( st_fx->coder_type != INACTIVE && GE_32( st_fx->total_brate, ACELP_13k20 ) ) - { - st_fx->GSC_noisy_speech = (Word16) get_next_indice_fx( st_fx, 1 ); /* Q0 */ - move16(); - } - - /* safety check in case of bit errors */ - test(); - test(); - IF( st_fx->GSC_noisy_speech && LT_16( st_fx->bwidth, SWB ) && st_fx->GSC_IVAS_mode == 0 ) - { - st_fx->BER_detect = 1; /* Q0 */ - move16(); - st_fx->GSC_noisy_speech = 0; /* Q0 */ - move16(); - } - - /* set bit-allocation */ -#ifdef REMOVE_EVS_DUPLICATES - config_acelp1_IVAS( DEC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl_orig, st_fx->extl_brate_orig, st_fx->L_frame, st_fx->GSC_noisy_speech, &( st_fx->acelp_cfg ), st_fx->next_bit_pos, st_fx->coder_type, st_fx->inactive_coder_type_flag, -1, 1, &nbits, NULL, st_fx->element_mode, &nbits /*dummy*/, 0, 0, st_fx->idchan, st_fx->active_cnt, 0, st_fx->tdm_LRTD_flag, st_fx->GSC_IVAS_mode ); -#else - config_acelp1( DEC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl_orig, st_fx->extl_brate_orig, st_fx->L_frame, st_fx->GSC_noisy_speech, &( st_fx->acelp_cfg ), st_fx->next_bit_pos, st_fx->coder_type, st_fx->inactive_coder_type_flag, -1, 1, &nbits, NULL, st_fx->element_mode, &nbits /*dummy*/, 0, 0, st_fx->idchan, st_fx->active_cnt, 0, st_fx->tdm_LRTD_flag, st_fx->GSC_IVAS_mode ); -#endif - - /*---------------------------------------------------------------* - * Decode energy dynamics - *---------------------------------------------------------------*/ - - IF( EQ_16( st_fx->GSC_noisy_speech, 1 ) ) - { - nb_subfr = NB_SUBFR; /* Q0 */ - move16(); - hGSCDec->cor_strong_limit = 0; - move16(); - hGSCDec->noise_lev = NOISE_LEVEL_SP3; /* Q0 */ - move16(); - } - ELSE - { - IF( LE_32( st_fx->core_brate, ACELP_8k00 ) ) - { - hGSCDec->noise_lev = add( (Word16) get_next_indice_fx( st_fx, 2 ), NOISE_LEVEL_SP2 ); /* Q0 */ - move16(); - } - ELSE - { - hGSCDec->noise_lev = add( (Word16) get_next_indice_fx( st_fx, 3 ), NOISE_LEVEL_SP0 ); /* Q0 */ - move16(); - } - - /*---------------------------------------------------------------* - * Decode number of subframes - *---------------------------------------------------------------*/ - - - hGSCDec->cor_strong_limit = 1; /* Q0 */ - move16(); - nb_subfr = SWNB_SUBFR; - move16(); - - IF( GE_32( st_fx->core_brate, ACELP_9k60 ) ) - { - nbits = 1; - move16(); - nb_frame_flg = (Word16) get_next_indice_fx( st_fx, nbits ); /* Q0 */ - move16(); - - IF( s_and( nb_frame_flg, 0x1 ) == 0 ) - { - nb_subfr = 2 * SWNB_SUBFR; /* Q0 */ - move16(); - hGSCDec->cor_strong_limit = 0; - move16(); - } - } - } - - /*---------------------------------------------------------------* - * Decode the last band where the adaptive (pitch) contribution is significant - *---------------------------------------------------------------*/ - - IF( LT_32( st_fx->core_brate, CFREQ_BITRATE ) ) - { - nbits = 3; /* Q0 */ - move16(); - test(); - if ( LT_32( st_fx->core_brate, ACELP_9k60 ) && st_fx->coder_type == INACTIVE ) - { - nbits = 1; /* Q0 */ - move16(); - } - } - ELSE - { - nbits = 4; /* Q0 */ - move16(); - } - test(); - IF( LT_32( st_fx->core_brate, ACELP_9k60 ) && st_fx->coder_type != INACTIVE ) - { - pit_band_idx = 1; /* Q0 */ - move16(); - } - ELSE - { - pit_band_idx = (Word16) get_next_indice_fx( st_fx, nbits ); /* Q0 */ - move16(); - } - - IF( pit_band_idx != 0 ) - { - IF( LT_32( st_fx->core_brate, ACELP_9k60 ) ) - { - pit_band_idx = 7 + BAND1k2; /* Q0 */ - move16(); /* At low rate, if pitch model is chosen, then for to be use on extented and constant frequency range */ - } - ELSE - { - pit_band_idx = add( pit_band_idx, BAND1k2 ); /* Q0 */ - } - - /* detect bit errors in the bitstream */ - IF( GT_16( pit_band_idx, 13 ) ) /* The maximum decodable index is 10 + BAND1k2 (3) = 13 */ - { - pit_band_idx = 13; /* Q0 */ - move16(); - st_fx->BER_detect = 1; /* Q0 */ - move16(); - } - Diff_len = mfreq_loc_div_25[pit_band_idx]; /* Q0 */ - move16(); - } - hGSCDec->Last_GSC_pit_band_idx = pit_band_idx; /* Q0 */ - move16(); - - - /*--------------------------------------------------------------------------------------* - * Decode adaptive (pitch) excitation contribution - * Reset unvaluable part of the adaptive (pitch) excitation contribution - *--------------------------------------------------------------------------------------*/ - IF( GT_16( pit_band_idx, BAND1k2 ) ) - { - /*---------------------------------------------------------------* - * Decode adaptive (pitch) excitation contribution - *---------------------------------------------------------------*/ - test(); - IF( EQ_16( st_fx->GSC_noisy_speech, 1 ) && EQ_16( nb_subfr, NB_SUBFR ) ) - { - Word16 indice; - nbits = Es_pred_bits_tbl[BIT_ALLOC_IDX_fx( st_fx->core_brate, GENERIC, -1, -1 )]; /* Q0 */ - move16(); - if ( st_fx->element_mode > EVS_MONO ) - { - nbits = 5; - move16(); - } - - indice = get_next_indice_fx( st_fx, nbits ); /* Q0 */ - - Es_pred_dec_fx( &Es_pred, indice, nbits, 0 ); - } - - dec_pit_exc_fx( st_fx, Aq, st_fx->coder_type, Es_pred, pitch_buf, code, exc, bwe_exc, nb_subfr, gain_buf ); - - IF( LT_32( st_fx->core_brate, ACELP_9k60 ) ) - { - minimum_fx( pitch_buf, shr( st_fx->L_frame, 6 ), &low_pit ); - low_pit = shr( low_pit, 6 ); /*Q6 -> Q0 */ - - IF( LT_16( low_pit, 64 ) ) - { - pit_band_idx = 9 + BAND1k2; /* Q0 */ - move16(); - if ( st_fx->bwidth == NB ) - { - pit_band_idx = 7 + BAND1k2; /* Q0 */ - move16(); - } - } - ELSE IF( LT_16( low_pit, 128 ) ) - { - pit_band_idx = 5 + BAND1k2; /* Q0 */ - move16(); - } - ELSE - { - pit_band_idx = 3 + BAND1k2; /* Q0 */ - move16(); - } - - Diff_len = mfreq_loc_div_25[pit_band_idx]; /* Q0 */ - move16(); - hGSCDec->Last_GSC_pit_band_idx = pit_band_idx; /* Q0 */ - move16(); - } - - /*---------------------------------------------------------------* - * DCT transform - *---------------------------------------------------------------*/ - edct_16fx( exc, dct_epit, st_fx->L_frame, 7, st_fx->element_mode ); - - /*---------------------------------------------------------------* - * Reset unvaluable part of the adaptive (pitch) excitation contribution - *---------------------------------------------------------------*/ - - max_len = sub( st_fx->L_frame, Diff_len ); /* Q0 */ - - if ( st_fx->bwidth == NB ) - { - max_len = sub( 160, Diff_len ); /* Q0 */ - } - - Len = 80; - move16(); - if ( LT_16( max_len, 80 ) ) - { - Len = max_len; /* Q0 */ - move16(); - } - - test(); - IF( EQ_32( st_fx->core_brate, ACELP_8k00 ) && NE_16( st_fx->bwidth, NB ) ) - { - FOR( i = 0; i < max_len; i++ ) - { - dct_epit[i + Diff_len] = 0; - move16(); - } - } - ELSE - { - FOR( i = 0; i < Len; i++ ) - { - dct_epit[i + Diff_len] = mult_r( dct_epit[i + Diff_len], sm_table_fx[i] ); /* Qx */ - move16(); - } - - FOR( ; i < max_len; i++ ) - { - dct_epit[i + Diff_len] = 0; - move16(); - } - } - // PMT("in the rare case of 4 subfr, bfi_pitch_fx might be wrong") - st_fx->bfi_pitch_fx = mean_fx( pitch_buf, nb_subfr ); /* Q6 */ - move16(); - st_fx->bfi_pitch_frame = st_fx->L_frame; /* Q0 */ - move16(); - - Diff_len = add( Diff_len, 1 ); /* Q0 */ - st_fx->bpf_off = 0; - move16(); - } - ELSE - { - /* No adaptive (pitch) excitation contribution */ - st_fx->bpf_off = 1; /* Q0 */ - move16(); - set16_fx( dct_epit, 0, st_fx->L_frame ); - - IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) - { - set16_fx( pitch_buf, L_SUBFR16k * 64, NB_SUBFR16k ); - } - ELSE - { - set16_fx( pitch_buf, L_SUBFR * 64, NB_SUBFR ); - } - - set16_fx( gain_buf, 0, NB_SUBFR16k ); - - st_fx->bfi_pitch_fx = L_SUBFR * 64; - move16(); - st_fx->bfi_pitch_frame = st_fx->L_frame; /* Q0 */ - move16(); - st_fx->lp_gainp_fx = 0; - move16(); - st_fx->lp_gainc_fx = 0; - move16(); - st_fx->tilt_code_fx = 0; - move16(); - pit_band_idx = 0; - move16(); - Diff_len = 0; - move16(); - } - - /*--------------------------------------------------------------------------------------* - * GSC decoder - *--------------------------------------------------------------------------------------*/ - - /* find the current total number of bits used */ - - tmp_nb_bits_tot = st_fx->next_bit_pos; /* Q0 */ - move16(); - - if ( st_fx->extl_brate > 0 ) - { - /* subtract 1 bit for TBE/BWE BWE flag (bit counted in extl_brate) */ - tmp_nb_bits_tot = sub( tmp_nb_bits_tot, 1 ); /* Q0 */ - } - - test(); - if ( st_fx->coder_type == INACTIVE && LE_32( st_fx->core_brate, ACELP_9k60 ) ) - { - tmp_nb_bits_tot = add( tmp_nb_bits_tot, 5 ); /* Q0 */ - } - - gsc_dec_fx( st_fx, dct_epit, pit_band_idx, Diff_len, tmp_nb_bits_tot, nb_subfr, st_fx->coder_type, &last_bin, lsf_new, exc_wo_nf, st_fx->Q_exc ); - /*--------------------------------------------------------------------------------------* - * iDCT transform - *--------------------------------------------------------------------------------------*/ - - edct_16fx( dct_epit, exc, st_fx->L_frame, 7, st_fx->element_mode ); - edct_16fx( exc_wo_nf, exc_wo_nf, st_fx->L_frame, 7, st_fx->element_mode ); - /*----------------------------------------------------------------------* - * Remove potential pre-echo in case an onset has been detected - *----------------------------------------------------------------------*/ - - pre_echo_att_fx( &hGSCDec->Last_frame_ener_fx, exc, gsc_attack_flag, st_fx->Q_exc, st_fx->last_coder_type, st_fx->L_frame ); - - /*--------------------------------------------------------------------------------------* - * Update BWE excitation - *--------------------------------------------------------------------------------------*/ - - IF( st_fx->hBWE_TD != NULL ) - { - set16_fx( voice_factors, 0, NB_SUBFR16k ); - IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) - { - interp_code_4over2_fx( exc, bwe_exc, st_fx->L_frame ); - } - ELSE - { - interp_code_5over2_fx( exc, bwe_exc, L_FRAME ); - } - } - /*--------------------------------------------------------------------------------------* - * Updates - *--------------------------------------------------------------------------------------*/ - - Copy( exc, exc2, st_fx->L_frame ); /* Q_exc */ - Copy( exc_wo_nf, exc, st_fx->L_frame ); /* Q_exc */ - - /*--------------------------------------------------------------------------------------* - * Channel aware mode parameters - *--------------------------------------------------------------------------------------*/ - - set16_fx( st_fx->tilt_code_dec_fx, 0, NB_SUBFR16k ); - - return; -} - -/*=========================================================================*/ -/* FUNCTION : void decod_audio_ivas_fx(); */ -/*-------------------------------------------------------------------------*/ -/* PURPOSE : Decode audio (AC) frames */ -/*-------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16[]) Aq : LP filter coefficient Q12 */ -/* _ (Word16) coder_type : coding type Q0 */ -/* _(Word16) Q_exc :Q format of excitation */ -/*-------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16[]) pitch_buf_fx : Word16 pitch values for each subframe Q6*/ -/* _ (Word16[]) voice_factors_fx: frame error rate Q15 */ -/*--------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* Decoder_State *st_fx : decoder memory structure */ -/* _ (Word16[]) exc_fx : adapt. excitation exc (Q_exc) */ -/* _ (Word16[]) exc2_fx : adapt. excitation/total exc (Q_exc) */ -/*--------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*==========================================================================*/ -#endif -void decod_audio_ivas_fx( - Decoder_State *st_fx, /* i/o: decoder static memory */ - Word16 dct_epit[], /* o : GSC excitation in DCT domain Qx*/ - const Word16 *Aq, /* i : LP filter coefficient Q12*/ - Word16 *pitch_buf, /* o : Word16 pitch values for each subframe Q6*/ - Word16 *voice_factors, /* o : voicing factors Q15*/ - Word16 *exc, /* i/o: adapt. excitation exc Q_exc*/ - Word16 *exc2, /* i/o: adapt. excitation/total exc Q_exc*/ - Word16 *bwe_exc, /* o : excitation for SWB TBE Q_exc*/ - Word16 *lsf_new /* i : ISFs at the end of the frame Qx*/ - , - Word16 *gain_buf, /*Q14*/ + Decoder_State *st_fx, /* i/o: decoder static memory */ + Word16 dct_epit[], /* o : GSC excitation in DCT domain Qx*/ + const Word16 *Aq, /* i : LP filter coefficient Q12*/ + Word16 *pitch_buf, /* o : Word16 pitch values for each subframe Q6*/ + Word16 *voice_factors, /* o : voicing factors Q15*/ + Word16 *exc, /* i/o: adapt. excitation exc Q_exc*/ + Word16 *exc2, /* i/o: adapt. excitation/total exc Q_exc*/ + Word16 *bwe_exc, /* o : excitation for SWB TBE Q_exc*/ + Word16 *lsf_new, /* i : ISFs at the end of the frame Qx*/ + Word16 *gain_buf, /* o : Word16 pitch gain for each subframe Q14*/ const Word16 tdm_lp_reuse_flag, /* i : LPC reuse flag Q0*/ const Word16 tdm_low_rate_mode, /* i : secondary channel low rate mode flag Q0*/ const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag Q0*/ @@ -525,7 +103,7 @@ void decod_audio_ivas_fx( } /* set bit-allocation */ - config_acelp1_IVAS( DEC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl_orig, st_fx->extl_brate_orig, st_fx->L_frame, st_fx->GSC_noisy_speech, &( st_fx->acelp_cfg ), st_fx->next_bit_pos, st_fx->coder_type, st_fx->inactive_coder_type_flag, -1, 1, &nbits, NULL, st_fx->element_mode, &nbits /*dummy*/, tdm_lp_reuse_flag, tdm_low_rate_mode, st_fx->idchan, st_fx->active_cnt, tdm_Pitch_reuse_flag, st_fx->tdm_LRTD_flag, st_fx->GSC_IVAS_mode ); + config_acelp1_fx( DEC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl_orig, st_fx->extl_brate_orig, st_fx->L_frame, st_fx->GSC_noisy_speech, &( st_fx->acelp_cfg ), st_fx->next_bit_pos, st_fx->coder_type, st_fx->inactive_coder_type_flag, -1, 1, &nbits, NULL, st_fx->element_mode, &nbits /*dummy*/, tdm_lp_reuse_flag, tdm_low_rate_mode, st_fx->idchan, st_fx->active_cnt, tdm_Pitch_reuse_flag, st_fx->tdm_LRTD_flag, st_fx->GSC_IVAS_mode ); /*---------------------------------------------------------------* * Decode energy dynamics @@ -735,7 +313,7 @@ void decod_audio_ivas_fx( Es_pred_dec_fx( &Es_pred, indice, nbits, 0 ); } - dec_pit_exc_ivas_fx( st_fx, Aq, st_fx->coder_type, Es_pred, pitch_buf, code, exc, bwe_exc, nb_subfr, gain_buf, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf ); + dec_pit_exc_fx( st_fx, Aq, st_fx->coder_type, Es_pred, pitch_buf, code, exc, bwe_exc, nb_subfr, gain_buf, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf ); IF( LT_32( st_fx->core_brate, ACELP_9k60 ) ) { @@ -894,7 +472,7 @@ void decod_audio_ivas_fx( Word16 Q_exc_old = st_fx->Q_exc; move16(); - gsc_dec_ivas_fx( st_fx, dct_epit, pit_band_idx, Diff_len, tmp_nb_bits_tot, nb_subfr, st_fx->coder_type, &last_bin, lsf_new, exc_wo_nf, &st_fx->Q_exc ); + gsc_dec_fx( st_fx, dct_epit, pit_band_idx, Diff_len, tmp_nb_bits_tot, nb_subfr, st_fx->coder_type, &last_bin, lsf_new, exc_wo_nf, &st_fx->Q_exc ); IF( NE_16( Q_exc_old, st_fx->Q_exc ) ) { @@ -976,250 +554,17 @@ void decod_audio_ivas_fx( /* _None */ /*==========================================================================*/ -#ifndef REMOVE_EVS_DUPLICATES void gsc_dec_fx( - Decoder_State *st_fx, /* i/o: State structure */ - Word16 exc_dct_in[], /* i/o: dct of pitch-only excitation / total excitation Q_exc*/ - const Word16 pit_band_idx, /* i : bin position of the cut-off frequency Q0*/ - const Word16 Diff_len, /* i : Lenght of the difference signal (before pure spectral) Q0*/ - const Word16 bits_used, /* i : Number of bit used before frequency Q Q0*/ - const Word16 nb_subfr, /* i : Number of subframe considered Q0*/ - const Word16 coder_type, /* i : coding type Q0*/ - Word16 *last_bin, /* i : last bin of bit allocation Q0*/ - const Word16 *lsf_new, /* i : ISFs at the end of the frame Qx*/ - Word16 *exc_wo_nf, /* o : excitation (in f domain) without noisefill Q_exc*/ - Word16 Q_exc ) -{ - Word16 i, j, bit, nb_subbands, pvq_len; - Word16 bitallocation_band[MBANDS_GN_BITALLOC16k]; - Word16 bitallocation_exc[2]; - Word16 Ener_per_bd_iQ[MBANDS_GN_BITALLOC16k]; - Word16 max_ener_band[MBANDS_GN_BITALLOC16k]; - Word16 exc_diffQ[L_FRAME16k]; - Word16 bits_per_bands[MBANDS_GN_BITALLOC16k]; - Word16 concat_out[L_FRAME16k]; - Word16 inpulses_fx[NB_SFM]; - Word16 imaxpulse_fx[NB_SFM]; - Word16 mean_gain; - Word16 Mbands_gn = 16; - Word16 Qexc_diffQ = Q_PVQ_OUT; - Word32 L_tmp; - Word16 Q_tmp; - Word16 seed_init; - GSC_DEC_HANDLE hGSCDec; - hGSCDec = st_fx->hGSCDec; - move16(); - move16(); - - move16(); // for Mbands_gn - move16(); // for Qexc_diffQ - set16_fx( inpulses_fx, 0, NB_SFM ); - set16_fx( imaxpulse_fx, 0, NB_SFM ); - - /*--------------------------------------------------------------------------------------* - * Initialization - *--------------------------------------------------------------------------------------*/ - bit = bits_used; - move16(); - - set16_fx( exc_diffQ, 0, st_fx->L_frame ); - - /*--------------------------------------------------------------------------------------* - * Gain decoding - *--------------------------------------------------------------------------------------*/ - - test(); - IF( st_fx->bfi || st_fx->BER_detect ) - { - /* copy old gain */ - Copy( hGSCDec->old_y_gain_fx, Ener_per_bd_iQ, Mbands_gn ); /* Q_old_gain */ - mean_gain = mult_r( st_fx->lp_gainc_fx, 3277 ); /*Q3*/ - FOR( i = 0; i < Mbands_gn; i++ ) - { - Ener_per_bd_iQ[i] = add( Ener_per_bd_iQ[i], shl( mean_gain, 9 ) ); /*Q12*/ - move16(); - } - - st_fx->lp_gainc_fx = mult_r( st_fx->lp_gainc_fx, 32112 ); /*Q3*/ - move16(); - } - ELSE - { - mean_gain = gsc_gaindec_fx( st_fx, Ener_per_bd_iQ, st_fx->core_brate, hGSCDec->old_y_gain_fx, coder_type, st_fx->bwidth ); /* Q12 */ - - st_fx->lp_gainc_fx = mult_r( 640, mean_gain ); /*10 in Q6 x Q12 -> lp_gainc in Q3 */ - move16(); - } - - *last_bin = 0; - move16(); - test(); - IF( EQ_32( st_fx->core_brate, ACELP_8k00 ) && st_fx->bwidth != NB ) - { - bitallocation_exc[0] = 0; - move16(); - bitallocation_exc[1] = 0; - move16(); - } - - set16_fx( bitallocation_band, 0, MBANDS_GN ); - - test(); - IF( ( EQ_16( st_fx->bfi, 1 ) ) || st_fx->BER_detect ) - { - /*--------------------------------------------------------------------------------------* - * Copy old spectrum - * reduce spectral dynamic - * save spectrum - *--------------------------------------------------------------------------------------*/ - - test(); - IF( EQ_16( st_fx->last_good, INACTIVE_CLAS ) || EQ_16( st_fx->Last_GSC_noisy_speech_flag, 1 ) ) - { - FOR( i = 0; i < st_fx->L_frame; i++ ) - { - L_tmp = L_shr( L_mult( Random( &hGSCDec->seed_tcx ), 26214 ), 5 ); /*Q10*/ - L_tmp = L_mac( L_tmp, hGSCDec->Last_GSC_spectrum_fx[i], 6554 ); /* Q10 */ - hGSCDec->Last_GSC_spectrum_fx[i] = round_fx( L_tmp ); /*Q10*/ - move16(); - } - } - - Copy( hGSCDec->Last_GSC_spectrum_fx, exc_diffQ, st_fx->L_frame ); /* Q10 */ - - FOR( i = 0; i < st_fx->L_frame; i++ ) - { - hGSCDec->Last_GSC_spectrum_fx[i] = mult_r( hGSCDec->Last_GSC_spectrum_fx[i], 24576 ); /*Q10*/ - move16(); - } - } - ELSE - { - /*--------------------------------------------------------------------------------------* - * PVQ decoder - *--------------------------------------------------------------------------------------*/ - - bands_and_bit_alloc_fx( hGSCDec->cor_strong_limit, hGSCDec->noise_lev, st_fx->core_brate, Diff_len, bit, &bit, Ener_per_bd_iQ, - max_ener_band, bits_per_bands, &nb_subbands, NULL, NULL, &pvq_len, coder_type, st_fx->bwidth, st_fx->GSC_noisy_speech, - st_fx->L_frame, st_fx->element_mode, st_fx->GSC_IVAS_mode ); - - { - pvq_core_dec_fx( st_fx, gsc_sfm_start, gsc_sfm_end, gsc_sfm_size, concat_out, &Q_tmp, bit, nb_subbands, bits_per_bands, NULL, inpulses_fx, imaxpulse_fx, ACELP_CORE ); - Scale_sig( concat_out, gsc_sfm_end[nb_subbands - 1], sub( Q_PVQ_OUT, Q_tmp ) ); /* Q_PVQ_OUT */ - } - seed_init = 0; - move16(); - - /* Reorder Q bands */ - FOR( j = 0; j < nb_subbands; j++ ) - { - Copy( concat_out + shl( j, 4 ), exc_diffQ + shl( max_ener_band[j], 4 ), 16 ); /* Q_PVQ_OUT */ - - *last_bin = s_max( *last_bin, max_ener_band[j] ); /* Q0 */ - move16(); - - bitallocation_band[max_ener_band[j]] = 1; /* Q0 */ - move16(); - - seed_init = add( seed_init, inpulses_fx[j] ); /* Q0 */ - } - test(); - IF( NE_16( st_fx->last_coder_type, AUDIO ) /* First audio frame */ - && NE_16( st_fx->last_coder_type, UNVOICED ) ) /* last_coder_type == INACTIVE is overwritten in update_dec to UNVOICED */ - { - FOR( j = 0; j < nb_subbands * 16; j++ ) - { - IF( concat_out[j] > 0 ) - { - seed_init = extract_l( L_shl( seed_init, 3 ) ); /* Q0 */ - } - if ( concat_out[j] < 0 ) - { - seed_init = add( seed_init, 3 ); /* Q0 */ - move16(); - } - } - - hGSCDec->seed_tcx = seed_init; /* Q0 */ - move16(); - } - test(); - IF( EQ_32( st_fx->core_brate, ACELP_8k00 ) && st_fx->bwidth != NB ) - { - if ( exc_diffQ[L_FRAME8k - 2] != 0 ) - { - bitallocation_exc[0] = 1; /* Q0 */ - move16(); - } - - if ( exc_diffQ[L_FRAME8k - 1] != 0 ) - { - bitallocation_exc[1] = 1; /* Q0 */ - move16(); - } - } - - Copy( exc_diffQ, hGSCDec->Last_GSC_spectrum_fx, st_fx->L_frame ); /* Q_PVQ_OUT */ - - /*--------------------------------------------------------------------------------------* - * Skip adaptive (pitch) contribution frequency band (no noise added over the time contribution) - * Find x pulses between 1.6-3.2kHz to code in the spectrum of the residual signal - * Gain is based on the inter-correlation gain between the pulses found and residual signal - *--------------------------------------------------------------------------------------*/ - - freq_dnw_scaling_fx( hGSCDec->cor_strong_limit, st_fx->coder_type, hGSCDec->noise_lev, st_fx->core_brate, exc_diffQ, Qexc_diffQ, st_fx->L_frame ); - } - - /*--------------------------------------------------------------------------------------* - * Estimate noise level - *--------------------------------------------------------------------------------------*/ - - highband_exc_dct_in_fx( st_fx->core_brate, mfreq_bindiv_loc, *last_bin, Diff_len, hGSCDec->noise_lev, pit_band_idx, exc_diffQ, - &hGSCDec->seed_tcx, Ener_per_bd_iQ, nb_subfr, exc_dct_in, st_fx->last_coder_type, bitallocation_band, lsf_new, - hGSCDec->last_exc_dct_in_fx, &hGSCDec->last_ener_fx, hGSCDec->last_bitallocation_band, bitallocation_exc, st_fx->bfi, coder_type, - st_fx->bwidth, exc_wo_nf, Qexc_diffQ, Q_exc, st_fx->GSC_noisy_speech, hGSCDec->lt_ener_per_band_fx, st_fx->L_frame, st_fx->element_mode, st_fx->GSC_IVAS_mode ); - - exc_dct_in[0] = 0; - move16(); - - return; -} - -/*==========================================================================*/ -/* FUNCTION : void gsc_dec_ivas_fx () */ -/*--------------------------------------------------------------------------*/ -/* PURPOSE : Generic audio signal decoder */ -/*--------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word16) pit_band_idx : bin position of the cut-off frequency Q0 */ -/* _ (Word16) Diff_len : Lenght of the difference signal Q0 */ -/* _ (Word16) coder_type : coding type Q0 */ -/* _ (Word16) bits_used : Number of bit used before frequency Q Q0 */ -/* _ (Word16) nb_subfr : Number of subframe considered Q0 */ -/* _ (Word16) Qexc : Q format of exc_dct_in */ -/*--------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ None */ -/*--------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* Decoder_State *st_fx:Decoder State Structure */ -/* _ (Word16[]) exc_dct_in : dctof pitch-only excitation / total excitation Qexc*/ -/*--------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _None */ -/*==========================================================================*/ -#endif -void gsc_dec_ivas_fx( - Decoder_State *st_fx, /* i/o: State structure */ - Word16 exc_dct_in[], /* i/o: dct of pitch-only excitation / total excitation Q_exc*/ + Decoder_State *st_fx, /* i/o: State structure */ + Word16 exc_dct_in[], /* i/o: dct of pitch-only excitation / total excitation Q_exc*/ const Word16 pit_band_idx, /* i : bin position of the cut-off frequency ` Q0*/ const Word16 Diff_len, /* i : Lenght of the difference signal (before pure spectral) Q0*/ const Word16 bits_used, /* i : Number of bit used before frequency Q Q0*/ const Word16 nb_subfr, /* i : Number of subframe considered Q0*/ const Word16 coder_type, /* i : coding type Q0*/ Word16 *last_bin, /* i : last bin of bit allocation Q0*/ - const Word16 *lsf_new, /* i : ISFs at the end of the frame Qx*/ - Word16 *exc_wo_nf, /* o : excitation (in f domain) without noisefill Q_exc*/ + const Word16 *lsf_new, /* i : ISFs at the end of the frame Qx*/ + Word16 *exc_wo_nf, /* o : excitation (in f domain) without noisefill Q_exc*/ Word16 *Q_exc ) { Word16 i, j, bit, nb_subbands, pvq_len; @@ -1310,13 +655,11 @@ void gsc_dec_ivas_fx( i--; } -#ifdef REMOVE_EVS_DUPLICATES IF( EQ_16( st_fx->element_mode, EVS_MONO ) ) { mean_gain = gsc_gaindec_fx( st_fx, Ener_per_bd_iQ, brate_intermed_tbl[i], hGSCDec->old_y_gain_fx, coder_type, st_fx->bwidth ); /* Q3 */ } ELSE -#endif { mean_gain = gsc_gaindec_ivas_fx( st_fx, Ener_per_bd_iQ, brate_intermed_tbl[i], hGSCDec->old_y_gain_fx, coder_type, st_fx->bwidth ); /* Q3 */ } diff --git a/lib_dec/ivas_core_dec_fx.c b/lib_dec/ivas_core_dec_fx.c index e4fb48f4a..cf3d8c468 100644 --- a/lib_dec/ivas_core_dec_fx.c +++ b/lib_dec/ivas_core_dec_fx.c @@ -520,7 +520,7 @@ ivas_error ivas_core_dec_fx( Scale_sig( st->hFdCngDec->hFdCngCom->A_cng, add( M, 1 ), sub( norm_s( sub( st->hFdCngDec->hFdCngCom->A_cng[0], 1 ) ), 3 ) ); // Qx } - IF( NE_32( ( error = acelp_core_dec_ivas_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_lspQ_PCh_fx, 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_16, sharpFlag[n], pitch_buf_fx[n], &unbits[n], &sid_bw[n], hStereoTD, tdm_lspQ_PCh_fx, 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 ) ) { return error; } diff --git a/lib_dec/ivas_stereo_mdct_core_dec_fx.c b/lib_dec/ivas_stereo_mdct_core_dec_fx.c index 890e5fc9e..89cb92a4d 100644 --- a/lib_dec/ivas_stereo_mdct_core_dec_fx.c +++ b/lib_dec/ivas_stereo_mdct_core_dec_fx.c @@ -1097,8 +1097,8 @@ static void run_min_stats_fx( { arr_tmp = power_spec; } - ApplyFdCng_ivas_fx( NULL, 0, arr_tmp, power_spec_q, NULL, NULL, NULL, st, st->bfi, 0 ); - /*=================================================*/ + + ApplyFdCng_fx( NULL, 0, arr_tmp, power_spec_q, NULL, NULL, NULL, st, st->bfi, 0 ); } /* restore VAD (see above) */ diff --git a/lib_dec/ivas_tcx_core_dec_fx.c b/lib_dec/ivas_tcx_core_dec_fx.c index aa5a379e8..0be01f7b8 100644 --- a/lib_dec/ivas_tcx_core_dec_fx.c +++ b/lib_dec/ivas_tcx_core_dec_fx.c @@ -875,11 +875,11 @@ void stereo_tcx_core_dec_fx( { Word16 buffer[L_FRAME16k]; lerp( signal_outFB_fx, buffer, st->L_frame, hTcxDec->L_frameTCX ); - ApplyFdCng_ivas_fx( buffer, 0 /* Q of buffer */, NULL, 0, NULL, NULL, NULL, st, st->bfi, 0 ); + ApplyFdCng_fx( buffer, 0 /* Q of buffer */, NULL, 0, NULL, NULL, NULL, st, st->bfi, 0 ); } ELSE { - ApplyFdCng_ivas_fx( signal_out_fx, 0, NULL, 0, NULL, NULL, NULL, st, st->bfi, 0 ); + ApplyFdCng_fx( signal_out_fx, 0, NULL, 0, NULL, NULL, NULL, st, st->bfi, 0 ); } } @@ -915,7 +915,7 @@ void stereo_tcx_core_dec_fx( test(); IF( EQ_16( st->element_mode, IVAS_CPE_TD ) && st->idchan == 0 ) { - ApplyFdCng_ivas_fx( signal_out_fx, 0, NULL, 0, NULL, NULL, NULL, st, st->bfi, 0 ); + ApplyFdCng_fx( signal_out_fx, 0, NULL, 0, NULL, NULL, NULL, st, st->bfi, 0 ); } } @@ -923,6 +923,7 @@ void stereo_tcx_core_dec_fx( return; } + static void stereo_tcx_dec_mode_switch_reconf_ivas_fx( Decoder_State *st, /* i/o: decoder state structure */ const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) Q0*/ diff --git a/lib_dec/ivas_td_low_rate_dec_fx.c b/lib_dec/ivas_td_low_rate_dec_fx.c index 3191a8b4a..8f09c1c7d 100644 --- a/lib_dec/ivas_td_low_rate_dec_fx.c +++ b/lib_dec/ivas_td_low_rate_dec_fx.c @@ -127,7 +127,7 @@ void tdm_low_rate_dec_fx( tmp_nb_bits_tot = sub( tmp_nb_bits_tot, 1 ); /* Q0 */ } - gsc_dec_ivas_fx( st, dct_epit, pit_band_idx, Diff_len, tmp_nb_bits_tot, nb_subfr, st->coder_type, &last_bin, lsf_new, exc_wo_nf_fx, &st->Q_exc ); + gsc_dec_fx( st, dct_epit, pit_band_idx, Diff_len, tmp_nb_bits_tot, nb_subfr, st->coder_type, &last_bin, lsf_new, exc_wo_nf_fx, &st->Q_exc ); /*--------------------------------------------------------------------------------------* * iDCT transform @@ -193,14 +193,9 @@ void tdm_low_rate_dec_fx( * * Decode generic (GC), 2 subframes mode *---------------------------------------------------------------------*/ -/*---------------------------------------------------------------------* - * decod_gen_2sbfr_ivas_fx() - * - * Decode generic (GC), 2 subframes mode - *---------------------------------------------------------------------*/ -void decod_gen_2sbfr_ivas_fx( - Decoder_State *st, /* i/o: decoder static memory */ +void decod_gen_2sbfr_fx( + Decoder_State *st, /* i/o: decoder static memory */ const Word16 sharpFlag, /* i : formant sharpening flag `Q0*/ const Word16 *Aq, /* i : LP filter coefficient Q12*/ Word16 *pitch_buf, /* o : Word16 pitch values for each subframe Q6*/ @@ -263,7 +258,7 @@ void decod_gen_2sbfr_ivas_fx( * Decode pitch lag *----------------------------------------------------------------------*/ - *pt_pitch = pit_decode_ivas_fx( st, st->core_brate, 0, L_frame, i_subfr, GENERIC, &pitch_limit_flag, &T0, &T0_frac, &T0_min, &T0_max, 2 * L_SUBFR, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf ); /* Q6 */ + *pt_pitch = pit_decode_fx( st, st->core_brate, 0, L_frame, i_subfr, GENERIC, &pitch_limit_flag, &T0, &T0_frac, &T0_min, &T0_max, 2 * L_SUBFR, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf ); /* Q6 */ test(); test(); @@ -295,7 +290,7 @@ void decod_gen_2sbfr_ivas_fx( * Estimate spectrum tilt and voicing *--------------------------------------------------------------*/ - gain_dec_lbr_ivas_fx( st, GENERIC, i_subfr, code, &gain_pit, &gain_code, &gain_inov, &norm_gain_code, gc_mem, gp_mem, 2 * L_SUBFR ); + gain_dec_lbr_fx( st, GENERIC, i_subfr, code, &gain_pit, &gain_code, &gain_inov, &norm_gain_code, gc_mem, gp_mem, 2 * L_SUBFR ); st->tilt_code_fx = est_tilt_ivas_fx( exc + i_subfr, gain_pit, code, gain_code, &voice_fac, st->Q_exc, 2 * L_SUBFR, 0 ); /* Q15 */ move16(); @@ -312,10 +307,12 @@ void decod_gen_2sbfr_ivas_fx( Word16 gain_code16 = round_fx( L_shl( gain_code, st->Q_exc ) ); /*Q_exc*/ Acelp_dec_total_exc( exc, exc2, gain_code16, gain_pit, i_subfr, code, 2 * L_SUBFR ); + /*-----------------------------------------------------------------* * Prepare TBE excitation *-----------------------------------------------------------------*/ - prep_tbe_exc_ivas_fx( L_frame, 2 * L_SUBFR, i_subfr, gain_pit, gain_code, code, voice_fac, &voice_factors[i_subfr / L_SUBFR /*i_subfr / L_SUBFR*/], bwe_exc, 0, NULL, st->Q_exc, T0, T0_frac, GENERIC, st->core_brate, st->element_mode, st->idchan, st->hBWE_TD != NULL, st->tdm_LRTD_flag ); + + prep_tbe_exc_fx( L_frame, 2 * L_SUBFR, i_subfr, gain_pit, gain_code, code, voice_fac, &voice_factors[i_subfr / L_SUBFR /*i_subfr / L_SUBFR*/], bwe_exc, 0, NULL, st->Q_exc, T0, T0_frac, GENERIC, st->core_brate, st->element_mode, st->idchan, st->hBWE_TD != NULL, st->tdm_LRTD_flag ); voice_factors[i_subfr / L_SUBFR + 1] = voice_factors[i_subfr / L_SUBFR /*i_subfr / L_SUBFR*/]; /* Q15 */ move16(); @@ -323,6 +320,7 @@ void decod_gen_2sbfr_ivas_fx( * Excitation enhancements (update of total excitation signal) * called twice because adapting it to double the subfr length would need lot of modifications *----------------------------------------------------------------*/ + enhancer_ivas_fx2( st->core_brate, 0, GENERIC, i_subfr, L_frame, voice_fac, st->stab_fac_fx, norm_gain_code, gain_inov, &st->gc_threshold_fx, code, exc2, gain_pit, &st->dm_fx, st->Q_exc ); enhancer_ivas_fx2( st->core_brate, 0, GENERIC, i_subfr, L_frame, voice_fac, st->stab_fac_fx, norm_gain_code, gain_inov, &st->gc_threshold_fx, code + L_SUBFR, exc2 + L_SUBFR, gain_pit, &st->dm_fx, st->Q_exc ); diff --git a/lib_dec/lsf_dec_fx.c b/lib_dec/lsf_dec_fx.c index 9b7f77c79..913543db8 100644 --- a/lib_dec/lsf_dec_fx.c +++ b/lib_dec/lsf_dec_fx.c @@ -8,9 +8,11 @@ #include "rom_com.h" /* Static table prototypes */ #include "prot_fx.h" /* Function prototypes */ #include "ivas_prot_fx.h" + /*-------------------------------------------------------------------* * Local functions *-------------------------------------------------------------------*/ + static void dqlsf_CNG_fx( Decoder_State *st_fx, Word16 *lsf_q ); /*--------------------------------------------------------------------------------------* @@ -88,7 +90,6 @@ static void dqlsf_CNG_fx( /* _ (Word16*) lsp_new : LP filter coefficient Q15 */ /* _ (Word16*) lsp_mid : LP filter coefficient Q15 */ /*---------------------------------------------------------------------------*/ - /* _ (Word16[]) st_fx->lsf_adaptive_mean_fx : FEC - adaptive mean LSF */ /* vector for FEC Q(x2.56) */ /* _ (Word16[]) st_fx->mem_AR_fx : AR memory of LSF quantizer */ @@ -99,271 +100,16 @@ static void dqlsf_CNG_fx( /* _ None */ /*===========================================================================*/ -#ifndef REMOVE_EVS_DUPLICATES void lsf_dec_fx( - Decoder_State *st_fx, /* i/o: State structure */ - const Word16 tc_subfr, /* i : TC subframe index Q0*/ - Word16 *Aq, /* o : quantized A(z) for 4 subframes Q12*/ - Word16 *LSF_Q_prediction, /* o : LSF prediction mode Q0*/ - Word16 *lsf_new, /* o : de-quantized LSF vector Q(x2.56)*/ - Word16 *lsp_new, /* o : de-quantized LSP vector Q15*/ - Word16 *lsp_mid, /* o : de-quantized mid-frame LSP vector Q15*/ - const Word16 tdm_low_rate_mode /* i : secondary channel low rate mode flag Q0*/ - , - const Word16 tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel Qx*/ -) -{ - Word16 i; - Word16 no_param_lpc; - Word16 param_lpc[NPRM_LPC_NEW]; - Word32 L_tmp; - Word16 nBits = 0; - move16(); - Word16 tmp_old[M + 1], tmp_new[M + 1]; - Word16 enr_old = 0, enr_new = 0; - move16(); - move16(); - Word16 lsf_diff, coder_type; - - /* initialize */ - coder_type = st_fx->coder_type; - if ( EQ_32( st_fx->core_brate, SID_2k40 ) ) - { - coder_type = INACTIVE; /* Q0 */ - move16(); - } - test(); - if ( EQ_16( coder_type, AUDIO ) && st_fx->GSC_IVAS_mode > 0 ) - { - coder_type = GENERIC; /* Q0 */ - move16(); - } - no_param_lpc = 0; - nBits = 0; - move16(); - move16(); - - /* Find the number of bits for LSF quantization */ - IF( EQ_32( st_fx->core_brate, SID_2k40 ) ) - { - nBits = LSF_BITS_CNG; /* Q0 */ - move16(); - } - ELSE - { - test(); - IF( st_fx->nelp_mode_dec == 0 && st_fx->ppp_mode_dec == 0 ) - { - nBits = st_fx->acelp_cfg.lsf_bits; /* Q0 */ - move16(); - } - ELSE IF( EQ_16( st_fx->nelp_mode_dec, 1 ) ) - { - IF( EQ_16( coder_type, UNVOICED ) ) - { - nBits = 30; /* Q0 */ - move16(); - if ( st_fx->bwidth == NB ) - { - nBits = 32; /* Q0 */ - move16(); - } - } - } - ELSE IF( EQ_16( st_fx->ppp_mode_dec, 1 ) ) - { - nBits = 26; /* Q0 */ - move16(); - } - } - - /* LSF de-quantization */ - lsf_end_dec_fx( st_fx, 0, coder_type, st_fx->bwidth, nBits, lsf_new, param_lpc, LSF_Q_prediction, &no_param_lpc, - tdm_lsfQ_PCh ); - - /* convert quantized LSFs to LSPs */ - - lsf2lsp_fx( lsf_new, lsp_new, M, st_fx->sr_core ); - /* set seed_acelp used in UC mode */ - test(); - IF( EQ_16( coder_type, UNVOICED ) && GT_16( st_fx->element_mode, EVS_MONO ) ) - { - st_fx->seed_acelp = 0; - move16(); - FOR( i = no_param_lpc - 1; i >= 0; i-- ) - { - /* rightshift before *seed_acelp+param_lpc[i] to avoid overflows*/ - st_fx->seed_acelp = extract_l( L_add( imult3216( 31821L /* Q0 */, add( shr( ( st_fx->seed_acelp ), 1 ), param_lpc[i] ) ), 13849L /* Q0 */ ) ); /* Q0 */ - move16(); - } - } - IF( EQ_32( st_fx->core_brate, SID_2k40 ) ) - { - /* return if SID frame (conversion to A(z) done in the calling function) */ - return; - } - - /*-------------------------------------------------------------------------------------* - * FEC - update adaptive LSF mean vector - *-------------------------------------------------------------------------------------*/ - - FOR( i = 0; i < M; i++ ) - { - L_tmp = L_mult( lsf_new[i], 10922 ); /*Q(x2.56+16)*/ - L_tmp = L_mac( L_tmp, st_fx->lsfoldbfi1_fx[i], 10922 ); /*Q(x2.56+16)*/ - L_tmp = L_mac( L_tmp, st_fx->lsfoldbfi0_fx[i], 10922 ); /*Q(x2.56+16)*/ - st_fx->lsf_adaptive_mean_fx[i] = round_fx( L_tmp ); /*Q(x2.56)*/ - move16(); - } - - test(); - test(); - IF( ( st_fx->prev_bfi && ( EQ_16( coder_type, TRANSITION ) ) && ( EQ_16( tc_subfr, sub( st_fx->L_frame, L_SUBFR ) ) ) ) ) - { - lsf_diff = 1205; - move16(); /*int_fs / (float)(2*(M+1)); = 470.588 -> 1205 in Q2.56 */ - if ( EQ_16( st_fx->L_frame, L_FRAME ) ) - { - lsf_diff = 964; - move16(); /*int_fs / (float)(2*(M+1)); = 376.47 -> 964 in Q2.56 */ - } - st_fx->lsf_old_fx[0] = lsf_diff; - move16(); - - FOR( i = 1; i < M; i++ ) - { - st_fx->lsf_old_fx[i] = add( st_fx->lsf_old_fx[i - 1], lsf_diff ); /* Q2.56 */ - move16(); - } - lsf2lsp_fx( st_fx->lsf_old_fx, st_fx->lsp_old_fx, M, st_fx->sr_core ); - } - /*-------------------------------------------------------------------------------------* - * Mid-frame LSF decoding - * LSP interpolation and conversion of LSPs to A(z) - *-------------------------------------------------------------------------------------*/ - IF( st_fx->rate_switching_reset ) - { - /*extrapolation in case of unstable LSF convert*/ - Copy( lsp_new, st_fx->lsp_old_fx, M ); /* Q15 */ - Copy( lsf_new, st_fx->lsf_old_fx, M ); /* Q2.56 */ - } - { - /* Mid-frame LSF decoding */ - lsf_mid_dec_fx( st_fx, lsp_new, coder_type, lsp_mid ); - } - test(); - test(); - IF( !( st_fx->prev_bfi && ( EQ_16( coder_type, TRANSITION ) ) && ( EQ_16( tc_subfr, sub( st_fx->L_frame, L_SUBFR ) ) ) ) ) - { - IF( st_fx->prev_bfi ) - { - /* check, if LSP interpolation can be relaxed */ - E_LPC_f_lsp_a_conversion( st_fx->lsp_old_fx, tmp_old, M ); - enr_old = Enr_1_Az_fx( tmp_old, 2 * L_SUBFR ); /* Q3 */ - - E_LPC_f_lsp_a_conversion( lsp_new, tmp_new, M ); - enr_new = Enr_1_Az_fx( tmp_new, 2 * L_SUBFR ); /* Q3 */ - - IF( LT_16( enr_new, mult_r( 9830 /*0.3 Q15*/, enr_old ) ) ) - { - /* OLD CODE : if( st->safety_net == 1), replaced with a decision similar to MODE2 */ - st_fx->relax_prev_lsf_interp = -1; - move16(); - test(); - test(); - test(); - test(); - if ( st_fx->clas_dec == UNVOICED_CLAS || EQ_16( st_fx->clas_dec, SIN_ONSET ) || st_fx->clas_dec == INACTIVE_CLAS || EQ_16( coder_type, GENERIC ) || EQ_16( coder_type, TRANSITION ) ) - { - st_fx->relax_prev_lsf_interp = 1; - move16(); - } - } - } - } - test(); - IF( EQ_16( st_fx->last_core, HQ_CORE ) && st_fx->core == ACELP_CORE ) - { - /* update old LSPs/LSFs in case of HQ->ACELP core switching */ - Copy( lsp_mid, st_fx->lsp_old_fx, M ); /* Q15 */ - lsp2lsf_fx( lsp_mid, st_fx->lsf_old_fx, M, st_fx->sr_core ); /* Q15 */ - } - test(); - IF( EQ_16( tdm_low_rate_mode, 1 ) && GT_16( coder_type, UNVOICED ) ) - { - // PMT("To be verified") - IF( EQ_16( st_fx->active_cnt, 1 ) ) - { - Copy( lsp_mid, st_fx->lsp_old_fx, M ); /* Q15 */ - lsp2lsf_fx( lsp_mid, st_fx->lsf_old_fx, M, st_fx->sr_core ); /* Q15 */ - Copy( lsp_new, lsp_mid, M ); /* Q15 */ - } - - /* LSP interpolation and conversion of LSPs to A(z) - two-subframe mode */ - int_lsp4_fx( st_fx->L_frame, st_fx->lsp_old_fx, lsp_mid, lsp_new, Aq, M, -2 ); - } - ELSE - { - /* LSP interpolation and conversion of LSPs to A(z) */ - int_lsp4_fx( st_fx->L_frame, st_fx->lsp_old_fx, lsp_mid, lsp_new, Aq, M, st_fx->relax_prev_lsf_interp ); - } - /*------------------------------------------------------------------* - * Check LSF stability (distance between old LSFs and current LSFs) - *------------------------------------------------------------------*/ - - IF( st_fx->element_mode == EVS_MONO ) - { - st_fx->stab_fac_fx = lsf_stab_fx( lsf_new, st_fx->lsf_old_fx, 0, st_fx->L_frame ); /*Q15*/ - move16(); - } - ELSE - { - st_fx->stab_fac_fx = lsf_stab_ivas_fx( lsf_new, st_fx->lsf_old_fx, 0, st_fx->L_frame ); /* Q15 */ - move16(); - } - - return; -} - -/*===========================================================================*/ -/* FUNCTION : lsf_dec_ivas_fx() */ -/*---------------------------------------------------------------------------*/ -/* PURPOSE : LSF decoder */ -/*---------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Struct) st_fx : decoder static memory */ -/* _ (Word16) L_frame : length of the frame */ -/* _ (Word16) coder_type : coding type */ -/* _ (Word16) bwidth : input signal bandwidth */ -/*---------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16*) Aq : LP filter coefficient Q12 */ -/* _ (Word16*) lsf_new : LP filter coefficient Q(x2.56) */ -/* _ (Word16*) lsp_new : LP filter coefficient Q15 */ -/* _ (Word16*) lsp_mid : LP filter coefficient Q15 */ -/*---------------------------------------------------------------------------*/ - -/* _ (Word16[]) st_fx->lsf_adaptive_mean_fx : FEC - adaptive mean LSF */ -/* vector for FEC Q(x2.56) */ -/* _ (Word16[]) st_fx->mem_AR_fx : AR memory of LSF quantizer */ -/* (past quantized LSFs without mean) Q(x2.56) */ -/* _ (Word16) st_fx->stab_fac_fx : LSF stability factor Q15 */ -/*---------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*===========================================================================*/ -#endif -void lsf_dec_ivas_fx( - Decoder_State *st_fx, /* i/o: State structure */ - const Word16 tc_subfr, /* i : TC subframe index Q0*/ - Word16 *Aq, /* o : quantized A(z) for 4 subframes Q12*/ - Word16 *LSF_Q_prediction, /* o : LSF prediction mode Q0*/ - Word16 *lsf_new, /* o : de-quantized LSF vector Q(x2.56)*/ - Word16 *lsp_new, /* o : de-quantized LSP vector Q15*/ - Word16 *lsp_mid, /* o : de-quantized mid-frame LSP vector Q15*/ - const Word16 tdm_low_rate_mode /* i : secondary channel low rate mode flag Q0*/ - , - const Word16 tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel Qx*/ + Decoder_State *st_fx, /* i/o: State structure */ + const Word16 tc_subfr, /* i : TC subframe index Q0*/ + Word16 *Aq, /* o : quantized A(z) for 4 subframes Q12*/ + Word16 *LSF_Q_prediction, /* o : LSF prediction mode Q0*/ + Word16 *lsf_new, /* o : de-quantized LSF vector Q(x2.56)*/ + Word16 *lsp_new, /* o : de-quantized LSP vector Q15*/ + Word16 *lsp_mid, /* o : de-quantized mid-frame LSP vector Q15*/ + const Word16 tdm_low_rate_mode, /* i : secondary channel low rate mode flag Q0*/ + const Word16 tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel Qx*/ ) { Word16 i; diff --git a/lib_dec/pit_dec_fx.c b/lib_dec/pit_dec_fx.c index e8cebedbd..38ec41cb2 100644 --- a/lib_dec/pit_dec_fx.c +++ b/lib_dec/pit_dec_fx.c @@ -319,246 +319,22 @@ void Mode2_delta_pit_dec( /* _ (Word16 ) pitch : close loop integer pitch Q6 */ /*=======================================================================*/ -#ifndef REMOVE_EVS_DUPLICATES -Word16 pit_decode_fx( /* o : floating pitch value */ - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - const Word16 L_frame, /* i : length of the frame */ - Word16 i_subfr, /* i : subframe index */ - const Word16 coder_type, /* i : coding type */ - Word16 *limit_flag, /* i/o: restrained(0) or extended(1) Q limits */ - Word16 *T0, /* o : close loop integer pitch */ - Word16 *T0_frac, /* o : close loop fractional part of the pitch */ - Word16 *T0_min, /* i/o: delta search min for sf 2 & 4 */ - Word16 *T0_max, /* i/o: delta search max for sf 2 & 4 */ - const Word16 L_subfr /* i : subframe length */ -) -{ - Word16 pitch; /*Q2*/ - Word16 pitch_index, nBits, pit_flag; - - pitch_index = 0; - move16(); - - /*----------------------------------------------------------------* - * Set pit_flag = 0 for every subframe with absolute pitch search - *----------------------------------------------------------------*/ - pit_flag = i_subfr; - move16(); - - if ( EQ_16( i_subfr, PIT_DECODE_2XL_SUBFR ) ) - { - pit_flag = 0; - move16(); - } - - /*-------------------------------------------------------* - * Retrieve the pitch index - *-------------------------------------------------------*/ - IF( !Opt_AMR_WB ) - { - /*----------------------------------------------------------------* - * pitch Q: Set limit_flag to 0 for restrained limits, and 1 for extended limits - *----------------------------------------------------------------*/ - test(); - test(); - IF( i_subfr == 0 ) - { - *limit_flag = 1; - move16(); - - if ( EQ_16( coder_type, VOICED ) ) - { - *limit_flag = 2; - move16(); /* double-extended limits */ - } - test(); - if ( EQ_16( coder_type, GENERIC ) && EQ_32( core_brate, ACELP_7k20 ) ) - { - *limit_flag = 0; - move16(); - } - } - ELSE IF( EQ_16( i_subfr, 2 * L_SUBFR ) && EQ_32( coder_type, GENERIC ) && LE_32( core_brate, ACELP_13k20 ) ) - { - if ( GT_16( *T0, shr( add( PIT_FR1_EXTEND_8b, PIT_MIN ), 1 ) ) ) - { - *limit_flag = 0; - move16(); - } - } - - /*-------------------------------------------------------* - * Retrieve the number of Q bits - *-------------------------------------------------------*/ - - nBits = 0; - move16(); - IF( NE_16( coder_type, AUDIO ) ) - { - /* find the number of bits */ - nBits = st_fx->acelp_cfg.pitch_bits[shr( i_subfr, 6 )]; - move16(); - pitch_index = (Word16) get_next_indice_fx( st_fx, nBits ); - } - - /*-------------------------------------------------------* - * Pitch decoding in AUDIO mode - * (both ACELP@12k8 and ACELP@16k cores) - *-------------------------------------------------------*/ - IF( EQ_16( coder_type, AUDIO ) ) - { - test(); - if ( EQ_16( L_subfr, L_FRAME / 2 ) && i_subfr != 0 ) - { - pit_flag = L_SUBFR; - move16(); - } - if ( pit_flag == 0 ) - { - nBits = 10; - move16(); - } - if ( pit_flag != 0 ) - { - nBits = 6; - move16(); - } - - pitch_index = (Word16) get_next_indice_fx( st_fx, nBits ); - - test(); - test(); - IF( EQ_16( L_subfr, L_FRAME / 2 ) && i_subfr != 0 && GE_16( pitch_index, 32 ) ) /* safety check in case of bit errors */ - { - pitch_index = shr( pitch_index, 1 ); - st_fx->BER_detect = 1; - move16(); - } - - pit_Q_dec_fx( 0, pitch_index, nBits, 4, pit_flag, *limit_flag, T0, T0_frac, T0_min, T0_max, &st_fx->BER_detect ); - } - ELSE IF( EQ_16( coder_type, VOICED ) ) - { - /*-------------------------------------------------------* - * Pitch decoding in VOICED mode - * (ACELP@12k8 core only) - *-------------------------------------------------------*/ - if ( EQ_16( i_subfr, 2 * L_SUBFR ) ) - { - pit_flag = i_subfr; - move16(); - } - - pit_Q_dec_fx( 0, pitch_index, nBits, 4, pit_flag, *limit_flag, T0, T0_frac, T0_min, T0_max, &st_fx->BER_detect ); - } - ELSE - { - /*-------------------------------------------------------* - * Pitch decoding in GENERIC mode - * (both ACELP@12k8 and ACELP@16k cores) - *-------------------------------------------------------*/ - IF( EQ_16( L_frame, L_FRAME ) ) - { - pit_Q_dec_fx( 0, pitch_index, nBits, 8, pit_flag, *limit_flag, T0, T0_frac, T0_min, T0_max, &st_fx->BER_detect ); - } - ELSE - { - pit16k_Q_dec_fx( pitch_index, nBits, *limit_flag, T0, T0_frac, T0_min, T0_max, &st_fx->BER_detect ); - } - } - } - - /*-------------------------------------------------------* - * Pitch decoding in AMR-WB IO mode - *-------------------------------------------------------*/ - - ELSE - { - *limit_flag = 0; - move16(); - test(); - test(); - IF( i_subfr == 0 || ( EQ_16( i_subfr, 2 * L_SUBFR ) && EQ_32( core_brate, ACELP_8k85 ) ) ) - { - nBits = 8; - move16(); - } - ELSE - { - nBits = 5; - move16(); - } - IF( GT_32( core_brate, ACELP_8k85 ) ) - { - nBits = 6; - move16(); - test(); - if ( i_subfr == 0 || EQ_16( i_subfr, 2 * L_SUBFR ) ) - { - nBits = 9; - move16(); - } - } - - pitch_index = (Word16) get_next_indice_fx( st_fx, nBits ); - - pit_Q_dec_fx( 1, pitch_index, nBits, 8, pit_flag, *limit_flag, T0, T0_frac, T0_min, T0_max, &st_fx->BER_detect ); - } - - /*-------------------------------------------------------* - * Compute floating pitch output - *-------------------------------------------------------*/ - - pitch = shl( add( shl( *T0, 2 ), *T0_frac ), 4 ); /* save subframe pitch values Q6 */ - - return pitch; -} - -/*======================================================================*/ -/* FUNCTION : pit_decode_ivas_fx() */ -/*-----------------------------------------------------------------------*/ -/* PURPOSE : calculate pitch value */ -/* */ -/*-----------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _ (Word32) core_brate : Core bitrate Q0 */ -/* _ (Word16) Opt_AMR_WB : flag indicating AMR-WB IO mode Q0 */ -/* _ (Word16) L_frame : length of the frame Q0 */ -/* _ (Word16) i_subfr : length of the frame Q0 */ -/* _ (Word16) coder_type : coding type Q0 */ -/* _ (Word16) L_subfr : subframe length */ -/*-----------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _ (Word16 *) T0 : close loop integer pitch */ -/* _ (Word16 *) T0_frac : close loop fractional part of the pitch */ -/* _ (Word16 ) pitch : pitch value Q6 */ -/*-----------------------------------------------------------------------*/ -/* INPUT OUTPUT ARGUMENTS */ -/* _ (Word16 *) T0_min : delta search min for sf 2 & 4 */ -/* _ (Word16 *) T0_max : delta search max for sf 2 & 4 */ -/*-----------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ (Word16 ) pitch : close loop integer pitch Q6 */ -/*=======================================================================*/ - -#endif -Word16 pit_decode_ivas_fx( /* o : floating pitch value */ - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - const Word16 L_frame, /* i : length of the frame */ - Word16 i_subfr, /* i : subframe index */ - const Word16 coder_type, /* i : coding type */ - Word16 *limit_flag, /* i/o: restrained(0) or extended(1) Q limits */ - Word16 *T0, /* o : close loop integer pitch */ - Word16 *T0_frac, /* o : close loop fractional part of the pitch */ - Word16 *T0_min, /* i/o: delta search min for sf 2 & 4 */ - Word16 *T0_max, /* i/o: delta search max for sf 2 & 4 */ - const Word16 L_subfr, /* i : subframe length */ - const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ - const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer Q6 */ +/*! r: floating pitch value */ +Word16 pit_decode_fx( + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word32 core_brate, /* i : core bitrate */ + const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ + const Word16 L_frame, /* i : length of the frame */ + Word16 i_subfr, /* i : subframe index */ + const Word16 coder_type, /* i : coding type */ + Word16 *limit_flag, /* i/o: restrained(0) or extended(1) Q limits */ + Word16 *T0, /* o : close loop integer pitch */ + Word16 *T0_frac, /* o : close loop fractional part of the pitch */ + Word16 *T0_min, /* i/o: delta search min for sf 2 & 4 */ + Word16 *T0_max, /* i/o: delta search max for sf 2 & 4 */ + const Word16 L_subfr, /* i : subframe length */ + const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ + const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer Q6 */ ) { Word16 pitch; /*Q2*/ diff --git a/lib_dec/post_dec_fx.c b/lib_dec/post_dec_fx.c index b5d56d8fb..cbcb225bc 100644 --- a/lib_dec/post_dec_fx.c +++ b/lib_dec/post_dec_fx.c @@ -139,21 +139,13 @@ void post_decoder( { st->hPFstat->on = 1; move16(); -#ifdef REMOVE_EVS_DUPLICATES - formant_post_filt_ivas_fx( st->hPFstat, synth, st->mem_Aq, synth2, L_frame, st->lp_noise, bitrate, 0 ); -#else formant_post_filt_fx( st->hPFstat, synth, st->mem_Aq, synth2, L_frame, st->lp_noise, bitrate, 0 ); -#endif } ELSE { st->hPFstat->on = 0; move16(); -#ifdef REMOVE_EVS_DUPLICATES - formant_post_filt_ivas_fx( st->hPFstat, synth, st->mem_Aq, synth2, L_frame, st->lp_noise, bitrate, 1 ); -#else formant_post_filt_fx( st->hPFstat, synth, st->mem_Aq, synth2, L_frame, st->lp_noise, bitrate, 1 ); -#endif } } @@ -176,10 +168,10 @@ void post_decoder( /* Update synth2 memory */ Copy( synth_buf2 + L_frame, hBPF->pst_old_syn_fx, NBPSF_PIT_MAX ); - return; } + void post_decoder_ivas_fx( Decoder_State *st, Word16 synth_buf[], // Q0 @@ -310,21 +302,13 @@ void post_decoder_ivas_fx( { st->hPFstat->on = 1; move16(); -#ifdef REMOVE_EVS_DUPLICATES - formant_post_filt_ivas_fx( st->hPFstat, synth, st->mem_Aq, synth2, L_frame, st->lp_noise, bitrate, 0 ); -#else formant_post_filt_fx( st->hPFstat, synth, st->mem_Aq, synth2, L_frame, st->lp_noise, bitrate, 0 ); -#endif } ELSE { st->hPFstat->on = 0; move16(); -#ifdef REMOVE_EVS_DUPLICATES - formant_post_filt_ivas_fx( st->hPFstat, synth, st->mem_Aq, synth2, L_frame, st->lp_noise, bitrate, 1 ); -#else formant_post_filt_fx( st->hPFstat, synth, st->mem_Aq, synth2, L_frame, st->lp_noise, bitrate, 1 ); -#endif } } diff --git a/lib_enc/acelp_core_enc_fx.c b/lib_enc/acelp_core_enc_fx.c index 4c3f7152c..ceba860a1 100644 --- a/lib_enc/acelp_core_enc_fx.c +++ b/lib_enc/acelp_core_enc_fx.c @@ -394,14 +394,10 @@ ivas_error acelp_core_enc_fx( test(); IF( !nelp_mode && !ppp_mode ) { -#ifdef REMOVE_EVS_DUPLICATES - config_acelp1_IVAS( ENC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl, st_fx->extl_brate, -#else - config_acelp1( ENC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl, st_fx->extl_brate, -#endif - st_fx->L_frame, st_fx->GSC_noisy_speech, &( st_fx->acelp_cfg ), hBstr->nb_bits_tot, st_fx->coder_type, st_fx->inactive_coder_type_flag, - tc_subfr_fx, 0, &nb_bits, unbits_fx, st_fx->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st_fx->idchan, st_fx->active_fr_cnt_fx, - tdm_Pitch_reuse_flag, st_fx->tdm_LRTD_flag, st_fx->GSC_IVAS_mode ); + config_acelp1_fx( ENC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl, st_fx->extl_brate, + st_fx->L_frame, st_fx->GSC_noisy_speech, &( st_fx->acelp_cfg ), hBstr->nb_bits_tot, st_fx->coder_type, st_fx->inactive_coder_type_flag, + tc_subfr_fx, 0, &nb_bits, unbits_fx, st_fx->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st_fx->idchan, st_fx->active_fr_cnt_fx, + tdm_Pitch_reuse_flag, st_fx->tdm_LRTD_flag, st_fx->GSC_IVAS_mode ); } /*-----------------------------------------------------------------* @@ -464,19 +460,16 @@ ivas_error acelp_core_enc_fx( { tc_classif_enc_fx( Q_new, st_fx->L_frame, &tc_subfr_fx, &position, attack_flag, st_fx->pitch[0], res_fx ); -#ifdef REMOVE_EVS_DUPLICATES - config_acelp1_IVAS( ENC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl, st_fx->extl_brate, st_fx->L_frame, -#else - config_acelp1( ENC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl, st_fx->extl_brate, st_fx->L_frame, -#endif - -1, &( st_fx->acelp_cfg ), hBstr->nb_bits_tot, TRANSITION, -1, tc_subfr_fx, 1, NULL, unbits_fx, st_fx->element_mode, &uc_two_stage_flag, - tdm_lp_reuse_flag, tdm_low_rate_mode, st_fx->idchan, st_fx->active_fr_cnt_fx, tdm_Pitch_reuse_flag, st_fx->tdm_LRTD_flag, st_fx->GSC_IVAS_mode ); + config_acelp1_fx( ENC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl, st_fx->extl_brate, st_fx->L_frame, + -1, &( st_fx->acelp_cfg ), hBstr->nb_bits_tot, TRANSITION, -1, tc_subfr_fx, 1, NULL, unbits_fx, st_fx->element_mode, &uc_two_stage_flag, + tdm_lp_reuse_flag, tdm_low_rate_mode, st_fx->idchan, st_fx->active_fr_cnt_fx, tdm_Pitch_reuse_flag, st_fx->tdm_LRTD_flag, st_fx->GSC_IVAS_mode ); } /*---------------------------------------------------------------* * Calculation of prediction for scaled innovation energy * (for memory-less gain quantizer) *---------------------------------------------------------------*/ + IF( nb_bits > 0 ) { Es_pred_enc_fx( &Es_pred_fx, &indice, st_fx->L_frame, res_fx, st_fx->voicing_fx, nb_bits, 0, Q_new ); @@ -521,13 +514,9 @@ ivas_error acelp_core_enc_fx( lsp_mid_bck_fx, mCb1_fx, Bin_E_fx, Bin_E_old_fx, mem_syn_bck_fx, mem_w0_bck_fx, streaklimit_fx, pstreaklen_fx ); /* Configure ACELP bit allocation */ -#ifdef REMOVE_EVS_DUPLICATES - config_acelp1_IVAS( ENC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl, st_fx->extl_brate, st_fx->L_frame, -#else - config_acelp1( ENC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl, st_fx->extl_brate, st_fx->L_frame, -#endif - -1, &( st_fx->acelp_cfg ), hBstr->nb_bits_tot, st_fx->coder_type, st_fx->inactive_coder_type_flag, tc_subfr_fx, 0, &nb_bits, unbits_fx, 0, &uc_two_stage_flag, 0, 0, - st_fx->idchan, st_fx->active_fr_cnt_fx, tdm_Pitch_reuse_flag, st_fx->tdm_LRTD_flag, st_fx->GSC_IVAS_mode ); + config_acelp1_fx( ENC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl, st_fx->extl_brate, st_fx->L_frame, + -1, &( st_fx->acelp_cfg ), hBstr->nb_bits_tot, st_fx->coder_type, st_fx->inactive_coder_type_flag, tc_subfr_fx, 0, &nb_bits, unbits_fx, 0, &uc_two_stage_flag, 0, 0, + st_fx->idchan, st_fx->active_fr_cnt_fx, tdm_Pitch_reuse_flag, st_fx->tdm_LRTD_flag, st_fx->GSC_IVAS_mode ); /* redo LSF quantization */ lsf_enc_fx( st_fx, lsf_new_fx, lsp_new_fx, lsp_mid_fx, Aq_fx, st_fx->Nb_ACELP_frames, tdm_low_rate_mode, st_fx->GSC_IVAS_mode, Q_new ); @@ -1185,7 +1174,7 @@ ivas_error acelp_core_enc_ivas_fx( test(); IF( !nelp_mode && !ppp_mode ) { - config_acelp1_IVAS( ENC, st->total_brate, st->core_brate, st->core, st->extl, st->extl_brate, st->L_frame, st->GSC_noisy_speech, &( st->acelp_cfg ), hBstr->nb_bits_tot, st->coder_type, st->inactive_coder_type_flag, tc_subfr, 0, &nb_bits, unbits, st->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st->idchan, st->active_cnt, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); + config_acelp1_fx( ENC, st->total_brate, st->core_brate, st->core, st->extl, st->extl_brate, st->L_frame, st->GSC_noisy_speech, &( st->acelp_cfg ), hBstr->nb_bits_tot, st->coder_type, st->inactive_coder_type_flag, tc_subfr, 0, &nb_bits, unbits, st->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st->idchan, st->active_cnt, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); } /*-----------------------------------------------------------------* @@ -1322,7 +1311,7 @@ ivas_error acelp_core_enc_ivas_fx( { tc_classif_enc_fx( Q_new, st->L_frame, &tc_subfr, &position, attack_flag, st->pitch[0], res_fx ); - config_acelp1_IVAS( ENC, st->total_brate, st->core_brate, st->core, st->extl, st->extl_brate, st->L_frame, -1, &( st->acelp_cfg ), hBstr->nb_bits_tot, TRANSITION, -1, tc_subfr, 1, NULL, unbits, st->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st->idchan, st->active_cnt, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); + config_acelp1_fx( ENC, st->total_brate, st->core_brate, st->core, st->extl, st->extl_brate, st->L_frame, -1, &( st->acelp_cfg ), hBstr->nb_bits_tot, TRANSITION, -1, tc_subfr, 1, NULL, unbits, st->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st->idchan, st->active_cnt, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); } /*---------------------------------------------------------------* @@ -1381,7 +1370,7 @@ ivas_error acelp_core_enc_ivas_fx( lsf_syn_mem_restore_ivas_fx( st, tilt_code_bck_fx, gc_threshold_bck_fx, clip_var_bck_fx, next_force_sf_bck, lsp_new, lsp_mid, clip_var_fx, mem_AR_fx, mem_MA_fx, lsp_new_bck_fx, lsp_mid_bck_fx, Bin_E_fx, Bin_E_old_fx, mem_syn_bck_fx, mem_w0_bck_fx, streaklimit_fx, pstreaklen ); /* Configure ACELP bit allocation */ - config_acelp1_IVAS( ENC, st->total_brate, st->core_brate, st->core, st->extl, st->extl_brate, st->L_frame, -1, &( st->acelp_cfg ), hBstr->nb_bits_tot, st->coder_type, st->inactive_coder_type_flag, tc_subfr, 0, &nb_bits, unbits, 0, &uc_two_stage_flag, 0, 0, st->idchan, st->active_cnt, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); + config_acelp1_fx( ENC, st->total_brate, st->core_brate, st->core, st->extl, st->extl_brate, st->L_frame, -1, &( st->acelp_cfg ), hBstr->nb_bits_tot, st->coder_type, st->inactive_coder_type_flag, tc_subfr, 0, &nb_bits, unbits, 0, &uc_two_stage_flag, 0, 0, st->idchan, st->active_cnt, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); /* redo LSF quantization */ lsf_enc_ivas_fx( st, lsf_new_fx, lsp_new, lsp_mid, Aq, tdm_low_rate_mode, 0, NULL, Q_new ); @@ -1390,6 +1379,7 @@ ivas_error acelp_core_enc_ivas_fx( calc_residu_fx( st, inp, res_fx, Aq ); st->hTdCngEnc->burst_ho_cnt = 0; move16(); + /* VOICED frames in SC-VBR */ encod_gen_voic_ivas_fx( st, inp, Aw, Aq, Es_pred_fx, res_fx, syn_fx, exc_fx, exc2_fx, pitch_buf, voice_factors_fx, bwe_exc_fx, unbits, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf_fx, 0, Q_new ); } diff --git a/lib_enc/acelp_core_switch_enc_fx.c b/lib_enc/acelp_core_switch_enc_fx.c index bad70b08c..76fa6f151 100644 --- a/lib_enc/acelp_core_switch_enc_fx.c +++ b/lib_enc/acelp_core_switch_enc_fx.c @@ -10,32 +10,17 @@ #include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ #include "basop_util.h" /* Function prototypes */ + /*---------------------------------------------------------------------* * Local function prototypes *---------------------------------------------------------------------*/ -static void encod_gen_voic_core_switch_fx( Encoder_State *st_fx, - const Word16 L_frame_fx, - const Word16 inp_fx[], - const Word16 Aq_fx[], - const Word16 A_fx[], - const Word16 T_op[], - Word16 *exc_fx, - const Word32 core_bitrate_fx, - Word16 shift, - Word16 Q_new ); -static void encod_gen_voic_core_switch_ivas_fx( Encoder_State *st_fx, - const Word16 L_frame_fx, - const Word16 inp_fx[], - const Word16 Aq_fx[], - const Word16 A_fx[], - const Word16 T_op[], - Word16 *exc_fx, - const Word32 core_bitrate_fx, - Word16 shift, - Word16 Q_new ); +static void encod_gen_voic_core_switch_fx( Encoder_State *st_fx, const Word16 L_frame_fx, const Word16 inp_fx[], const Word16 Aq_fx[], const Word16 A_fx[], const Word16 T_op[], Word16 *exc_fx, const Word32 core_bitrate_fx, Word16 shift, Word16 Q_new ); + +static void encod_gen_voic_core_switch_ivas_fx( Encoder_State *st_fx, const Word16 L_frame_fx, const Word16 inp_fx[], const Word16 Aq_fx[], const Word16 A_fx[], const Word16 T_op[], Word16 *exc_fx, const Word32 core_bitrate_fx, Word16 shift, Word16 Q_new ); static void bwe_switch_enc_fx( Encoder_State *st_fx, const Word16 *new_speech ); + static void bwe_switch_enc_ivas_fx( Encoder_State *st_fx, const Word16 *new_speech ); static Word16 dotprod_satcont( const Word16 *x, const Word16 *y, Word16 qx, Word16 qy, Word16 *qo, Word16 len, Word16 delta ); @@ -150,12 +135,8 @@ void acelp_core_switch_enc_fx( * Excitation encoding *----------------------------------------------------------------*/ -#ifdef REMOVE_EVS_DUPLICATES - config_acelp1_IVAS( ENC, st_fx->total_brate, cbrate, st_fx->core, -1, -1, st_fx->last_L_frame, -1, &( st_fx->acelp_cfg ), hBstr->nb_bits_tot, -#else - config_acelp1( ENC, st_fx->total_brate, cbrate, st_fx->core, -1, -1, st_fx->last_L_frame, -1, &( st_fx->acelp_cfg ), hBstr->nb_bits_tot, -#endif - GENERIC, st_fx->inactive_coder_type_flag, -1, -1, &j, &i, st_fx->element_mode, &i /*dummy*/, 0 /*tdm_lp_reuse_flag*/, 0 /*tdm_low_rate_mode*/, st_fx->idchan, st_fx->active_fr_cnt_fx, 0 /*tdm_Pitch_reuse_flag*/, 0, 0 /*GSC_IVAS_mode*/ ); + config_acelp1_fx( ENC, st_fx->total_brate, cbrate, st_fx->core, -1, -1, st_fx->last_L_frame, -1, &( st_fx->acelp_cfg ), hBstr->nb_bits_tot, + GENERIC, st_fx->inactive_coder_type_flag, -1, -1, &j, &i, st_fx->element_mode, &i /*dummy*/, 0 /*tdm_lp_reuse_flag*/, 0 /*tdm_low_rate_mode*/, st_fx->idchan, st_fx->active_fr_cnt_fx, 0 /*tdm_Pitch_reuse_flag*/, 0, 0 /*GSC_IVAS_mode*/ ); encod_gen_voic_core_switch_fx( st_fx, st_fx->last_L_frame, inp, Aq, A, T_op, exc, cbrate, shift, Q_new ); @@ -278,8 +259,8 @@ void acelp_core_switch_enc_ivas_fx( * Excitation encoding *----------------------------------------------------------------*/ - config_acelp1_IVAS( ENC, st_fx->total_brate, cbrate, st_fx->core, -1, -1, st_fx->last_L_frame, -1, &( st_fx->acelp_cfg ), hBstr->nb_bits_tot, - GENERIC, st_fx->inactive_coder_type_flag, -1, -1, &j, &i, st_fx->element_mode, &i /*dummy*/, 0 /*tdm_lp_reuse_flag*/, 0 /*tdm_low_rate_mode*/, st_fx->idchan, st_fx->active_fr_cnt_fx, 0 /*tdm_Pitch_reuse_flag*/, 0, 0 /*GSC_IVAS_mode*/ ); + config_acelp1_fx( ENC, st_fx->total_brate, cbrate, st_fx->core, -1, -1, st_fx->last_L_frame, -1, &( st_fx->acelp_cfg ), hBstr->nb_bits_tot, + GENERIC, st_fx->inactive_coder_type_flag, -1, -1, &j, &i, st_fx->element_mode, &i /*dummy*/, 0 /*tdm_lp_reuse_flag*/, 0 /*tdm_low_rate_mode*/, st_fx->idchan, st_fx->active_fr_cnt_fx, 0 /*tdm_Pitch_reuse_flag*/, 0, 0 /*GSC_IVAS_mode*/ ); encod_gen_voic_core_switch_ivas_fx( st_fx, st_fx->last_L_frame, inp, Aq, A, T_op, exc, cbrate, shift, Q_new ); diff --git a/lib_enc/analy_lp_fx.c b/lib_enc/analy_lp_fx.c index 78a02eeec..9b6ff2108 100644 --- a/lib_enc/analy_lp_fx.c +++ b/lib_enc/analy_lp_fx.c @@ -3,17 +3,16 @@ ====================================================================================*/ #include -#include "options.h" /* Compilation switches */ -#include "cnst.h" /* Common constants */ -#include "rom_com_fx.h" /* Static table prototypes */ -#include "rom_com.h" /* Static table prototypes */ -#include "rom_enc.h" /* Static table prototypes */ -//#include "prot_fx.h" /* Function prototypes */ +#include "options.h" /* Compilation switches */ +#include "cnst.h" /* Common constants */ +#include "rom_com_fx.h" /* Static table prototypes */ +#include "rom_com.h" /* Static table prototypes */ +#include "rom_enc.h" /* Static table prototypes */ #include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ /*-------------------------------------------------------------------* - * analy_lp() + * analy_lp_fx() * * Perform LP analysis * @@ -23,26 +22,26 @@ * - find interpolated LSPs and convert back to A(z) for all subframes * - update LSPs for the next frame *-------------------------------------------------------------------*/ -void analy_lp_ivas_fx( - const Word16 speech[], /* i :(Q_new) pointer to the speech frame */ - const Word16 L_frame, /* i :(q0) length of the frame */ - const Word16 L_look, /* i :(q0) look-ahead */ - Word32 *ener, /* o :(Q_r) residual energy from Levinson-Durbin */ - Word16 A[], /* o :(q14) A(z) filter coefficients */ - Word16 epsP_h[], /* o :(high part of epsP(Q_r)) LP analysis residual energies for each iteration */ - Word16 epsP_l[], /* o :(low part of epsP(Q_r)) LP analysis residual energies for each iteration */ - Word16 lsp_new[], /* o :(q15) current frame LSPs */ - Word16 lsp_mid[], /* o :(q15) current mid-frame LSPs */ - Word16 lsp_old[], /* i/o:(q15) previous frame unquantized LSPs */ - const Word16 Top[2], /* i :(q0) open loop pitch lag */ - const Word16 Tnc[2], /* i :(q15) open loop pitch gain */ - const Word32 Core_sr, /* i :(q0) Internal core sampling rate */ -#ifdef REMOVE_EVS_DUPLICATES - const Word16 element_mode, /* i : element mode */ -#endif - const Word16 sec_chan_low_rate, /* i :(q0) flag to signal second channel */ - Word16 Q_new, /*i: stores Q for speech*/ - Word16 *Q_r /*stores q for ener*/ ) + +void analy_lp_fx( + const Word16 speech[], /* i :(Q_new) pointer to the speech frame */ + const Word16 L_frame, /* i :(q0) length of the frame */ + const Word16 L_look, /* i :(q0) look-ahead */ + Word32 *ener, /* o :(Q_r) residual energy from Levinson-Durbin */ + Word16 A[], /* o :(q14) A(z) filter coefficients */ + Word16 epsP_h[], /* o :(high part of epsP(Q_r)) LP analysis residual energies for each iteration */ + Word16 epsP_l[], /* o :(low part of epsP(Q_r)) LP analysis residual energies for each iteration */ + Word16 lsp_new[], /* o :(q15) current frame LSPs */ + Word16 lsp_mid[], /* o :(q15) current mid-frame LSPs */ + Word16 lsp_old[], /* i/o:(q15) previous frame unquantized LSPs */ + const Word16 Top[2], /* i :(q0) open loop pitch lag */ + const Word16 Tnc[2], /* i :(q15) open loop pitch gain */ + const Word32 Core_sr, /* i :(q0) Internal core sampling rate */ + const Word16 element_mode, /* i : element mode */ + const Word16 sec_chan_low_rate, /* i :(q0) flag to signal second channel */ + Word16 Q_new, /* i : stores Q for speech */ + Word16 *Q_r /*stores q for ener*/ +) { Word16 r_h[M + 1]; /* Autocorrelations of windowed speech MSB */ Word16 r_l[M + 1]; /* Autocorrelations of windowed speech LSB */ @@ -77,9 +76,7 @@ void analy_lp_ivas_fx( /* Autocorrelations */ autocorr_fx( pt, M, r_h, r_l, &Q_r[1 - i_subfr], wind_length, wind, 0, 0 ); -#ifdef REMOVE_EVS_DUPLICATES IF( NE_16( element_mode, EVS_MONO ) ) -#endif { /*if ( r[0] < 100.0f && no_thr == 0 )*/ /*r[0] = 100.0f*/ @@ -132,101 +129,6 @@ void analy_lp_ivas_fx( return; } -#ifndef REMOVE_EVS_DUPLICATES -void analy_lp_fx( - const Word16 speech[], /* i : pointer to the speech frame Q_new*/ - const Word16 L_frame, /* i : length of the frame Q0*/ - const Word16 L_look, /* i : look-ahead Q0*/ - Word32 *ener, /* o : residual energy from Levinson-Durbin Q_r*/ - Word16 A[], /* o : A(z) filter coefficients Q14*/ - Word16 epsP_h[], /* o : LP analysis residual energies for each iteration Q_r*/ - Word16 epsP_l[], /* o : LP analysis residual energies for each iteration Q_r*/ - Word16 lsp_new[], /* o : current frame LSPs Q15*/ - Word16 lsp_mid[], /* o : current mid-frame LSPs Q15*/ - Word16 lsp_old[], /* i/o: previous frame unquantized LSPs Q15*/ - const Word16 Top[2], /* i : open loop pitch lag Q0*/ - const Word16 Tnc[2], /* i : open loop pitch gain Q15*/ - const Word32 Core_sr, /* i : Internal core sampling rate Q0*/ - const Word16 sec_chan_low_rate, /* i : flag to signal second channel Q0*/ - Word16 Q_new, - Word16 *Q_r ) -{ - Word16 r_h[M + 1]; /* Autocorrelations of windowed speech MSB */ - Word16 r_l[M + 1]; /* Autocorrelations of windowed speech LSB */ - Word32 LepsP[M + 1]; - Word16 i, i_subfr, wind_length = 0; - Word16 *lsp; - const Word16 *wind = NULL; - const Word16 *pt; - Word16 half_frame; - - IF( EQ_16( L_frame, L_FRAME ) ) - { - wind_length = L_LP; - move16(); - wind = Assym_window_W16fx; /* Q15 */ - } - ELSE /* L_frame == L_FRAME16k */ - { - wind_length = L_LP_16k; - move16(); - wind = assym_window_16k_fx; /* Q15 */ - } - lsp = lsp_mid; /* Q15 */ - half_frame = shr( L_frame, 1 ); - - FOR( i_subfr = 0; i_subfr <= 1; i_subfr++ ) - { - pt = speech + sub( add( half_frame, L_look ), wind_length ); - half_frame = shl( half_frame, 1 ); - - /* Autocorrelations */ - autocorr_fx( pt, M, r_h, r_l, &Q_r[1 - i_subfr], wind_length, wind, 0, 0 ); - - /* Lag windowing */ - adapt_lag_wind( r_h, r_l, M, Top[i_subfr], Tnc[i_subfr], Core_sr ); - - /* Levinson-Durbin */ - E_LPC_lev_dur( r_h, r_l, A, LepsP, M, NULL ); - FOR( i = 0; i <= M; i++ ) - { - L_Extract( LepsP[i], &epsP_h[i], &epsP_l[i] ); - } - /*Q_r[... might not be needed from external...*/ - Q_r[1 - i_subfr] = add( Q_r[1 - i_subfr], shl( Q_new, 1 ) ); - move16(); - - /* Conversion of A(z) to LSPs */ - E_LPC_a_lsp_conversion( A, lsp, lsp_old, M ); - - lsp = lsp_new; /* Q15 */ - } - IF( EQ_16( sec_chan_low_rate, 1 ) ) - { - /* LSP interpolation */ -#ifdef REMOVE_EVS_DUPLICATES - int_lsp4_ivas_fx( L_frame, lsp_old, lsp_mid, lsp_new, A, M, -2 ); -#else - int_lsp4_fx( L_frame, lsp_old, lsp_mid, lsp_new, A, M, -2 ); -#endif - } - ELSE - { - /* LSP interpolation */ -#ifdef REMOVE_EVS_DUPLICATES - int_lsp4_fx( L_frame, lsp_old, lsp_mid, lsp_new, A, M, 0 ); -#else - int_lsp4_fx( L_frame, lsp_old, lsp_mid, lsp_new, A, M, 0 ); -#endif - } - Copy( lsp_new, lsp_old, M ); /* Q15 */ - *ener = L_Comp( epsP_h[M], epsP_l[M] ); /* Q_r */ - move32(); - - return; -} -#endif - /*-------------------------------------------------------------------* * analy_lp_AMR_WB() * diff --git a/lib_enc/cod_ace_fx.c b/lib_enc/cod_ace_fx.c index b5c18d44b..e1914aeb5 100644 --- a/lib_enc/cod_ace_fx.c +++ b/lib_enc/cod_ace_fx.c @@ -366,14 +366,9 @@ Word16 coder_acelp_fx( /* o : SEGSNR for CL decision * IF( st->igf != 0 ) { -#ifdef REMOVE_EVS_DUPLICATES - prep_tbe_exc_ivas_fx( L_frame, L_SUBFR, i_subfr, gain_pit, gain_code, code, voice_fac, &voice_factors[i_subfr / L_SUBFR], - bwe_exc, gain_preQ, code_preQ, Q_new, T0, T0_frac, st->coder_type, st->core_brate, - st->element_mode, st->idchan, st->hBWE_TD != NULL, st->tdm_LRTD_flag ); -#else - prep_tbe_exc_fx( L_frame, i_subfr, gain_pit, gain_code, code, voice_fac, &voice_factors[i_subfr / L_SUBFR], - bwe_exc, gain_preQ, code_preQ, Q_new, T0, T0_frac, st->coder_type, st->core_brate ); -#endif + prep_tbe_exc_fx( L_frame, L_SUBFR, i_subfr, gain_pit, gain_code, code, voice_fac, &voice_factors[i_subfr / L_SUBFR], + bwe_exc, gain_preQ, code_preQ, Q_new, T0, T0_frac, st->coder_type, st->core_brate, + st->element_mode, st->idchan, st->hBWE_TD != NULL, st->tdm_LRTD_flag ); } /*---------------------------------------------------------* diff --git a/lib_enc/enc_gen_voic_fx.c b/lib_enc/enc_gen_voic_fx.c index 3ff99812f..a485a1bf3 100644 --- a/lib_enc/enc_gen_voic_fx.c +++ b/lib_enc/enc_gen_voic_fx.c @@ -363,20 +363,15 @@ void encod_gen_voic_fx( exc_fx[i + i_subfr_fx] = round_fx_o( Ltmp, &Overflow ); /* Q0 */ } } + /*-----------------------------------------------------------------* * Prepare TBE excitation *-----------------------------------------------------------------*/ -#ifdef REMOVE_EVS_DUPLICATES - prep_tbe_exc_ivas_fx( L_frame, L_SUBFR, i_subfr_fx, gain_pit_fx, gain_code_fx, code_fx, voice_fac_fx, - &voice_factors_fx[i_subfr_fx / L_SUBFR], bwe_exc_fx, gain_preQ_fx, code_preQ_fx, Q_new, - T0_fx, T0_frac_fx, st_fx->coder_type, st_fx->core_brate, - st_fx->element_mode, st_fx->idchan, st_fx->hBWE_TD != NULL, st_fx->tdm_LRTD_flag ); -#else - prep_tbe_exc_fx( L_frame, i_subfr_fx, gain_pit_fx, gain_code_fx, code_fx, voice_fac_fx, + prep_tbe_exc_fx( L_frame, L_SUBFR, i_subfr_fx, gain_pit_fx, gain_code_fx, code_fx, voice_fac_fx, &voice_factors_fx[i_subfr_fx / L_SUBFR], bwe_exc_fx, gain_preQ_fx, code_preQ_fx, Q_new, - T0_fx, T0_frac_fx, st_fx->coder_type, st_fx->core_brate ); -#endif + T0_fx, T0_frac_fx, st_fx->coder_type, st_fx->core_brate, + st_fx->element_mode, st_fx->idchan, st_fx->hBWE_TD != NULL, st_fx->tdm_LRTD_flag ); /*-----------------------------------------------------------------* * Synthesize speech to update mem_syn[]. @@ -405,9 +400,11 @@ void encod_gen_voic_fx( hSC_VBR->prev_tilt_code_fx = hLPDmem->tilt_code; /* Q15 */ move16(); } + return; } + void encod_gen_voic_ivas_fx( Encoder_State *st_fx, /* i/o: state structure */ const Word16 speech_fx[], /* i : input speech Qnew -1 */ @@ -763,10 +760,10 @@ void encod_gen_voic_ivas_fx( * Prepare TBE excitation *-----------------------------------------------------------------*/ - prep_tbe_exc_ivas_fx( L_frame, L_SUBFR, i_subfr_fx, gain_pit_fx, gain_code_fx, code_fx, voice_fac_fx, - &voice_factors_fx[i_subfr_fx / L_SUBFR], bwe_exc_fx, gain_preQ_fx, code_preQ_fx, Q_new, - T0_fx, T0_frac_fx, st_fx->coder_type, st_fx->core_brate, - st_fx->element_mode, st_fx->idchan, st_fx->hBWE_TD != NULL, st_fx->tdm_LRTD_flag ); + prep_tbe_exc_fx( L_frame, L_SUBFR, i_subfr_fx, gain_pit_fx, gain_code_fx, code_fx, voice_fac_fx, + &voice_factors_fx[i_subfr_fx / L_SUBFR], bwe_exc_fx, gain_preQ_fx, code_preQ_fx, Q_new, + T0_fx, T0_frac_fx, st_fx->coder_type, st_fx->core_brate, + st_fx->element_mode, st_fx->idchan, st_fx->hBWE_TD != NULL, st_fx->tdm_LRTD_flag ); /*-----------------------------------------------------------------* * Synthesize speech to update mem_syn[]. diff --git a/lib_enc/enc_tran_fx.c b/lib_enc/enc_tran_fx.c index dde834b2b..9802dc15b 100644 --- a/lib_enc/enc_tran_fx.c +++ b/lib_enc/enc_tran_fx.c @@ -308,13 +308,8 @@ Word16 encod_tran_fx( * Prepare TBE excitation *-----------------------------------------------------------------*/ -#ifdef REMOVE_EVS_DUPLICATES - prep_tbe_exc_ivas_fx( L_frame_fx, L_SUBFR, i_subfr, gain_pit, gain_code, code, voice_fac, &voice_factors[i_subfr / L_SUBFR], - bwe_exc_fx, gain_preQ, code_preQ, Q_new, T0, T0_frac, st_fx->coder_type, st_fx->core_brate, st_fx->element_mode, st_fx->idchan, st_fx->hBWE_TD != NULL, st_fx->tdm_LRTD_flag ); -#else - prep_tbe_exc_fx( L_frame_fx, i_subfr, gain_pit, gain_code, code, voice_fac, &voice_factors[i_subfr / L_SUBFR], - bwe_exc_fx, gain_preQ, code_preQ, Q_new, T0, T0_frac, st_fx->coder_type, st_fx->core_brate ); -#endif + prep_tbe_exc_fx( L_frame_fx, L_SUBFR, i_subfr, gain_pit, gain_code, code, voice_fac, &voice_factors[i_subfr / L_SUBFR], + bwe_exc_fx, gain_preQ, code_preQ, Q_new, T0, T0_frac, st_fx->coder_type, st_fx->core_brate, st_fx->element_mode, st_fx->idchan, st_fx->hBWE_TD != NULL, st_fx->tdm_LRTD_flag ); /*-----------------------------------------------------------------* * Synthesize speech to update mem_syn[]. @@ -719,9 +714,9 @@ Word16 encod_tran_ivas_fx( * Prepare TBE excitation *-----------------------------------------------------------------*/ - prep_tbe_exc_ivas_fx( L_frame_fx, L_SUBFR, i_subfr, gain_pit, gain_code, code, voice_fac, &voice_factors[i_subfr / L_SUBFR], - bwe_exc_fx, gain_preQ, code_preQ, Q_new, T0, T0_frac, st_fx->coder_type, st_fx->core_brate, - st_fx->element_mode, st_fx->idchan, st_fx->hBWE_TD != NULL, st_fx->tdm_LRTD_flag ); + prep_tbe_exc_fx( L_frame_fx, L_SUBFR, i_subfr, gain_pit, gain_code, code, voice_fac, &voice_factors[i_subfr / L_SUBFR], + bwe_exc_fx, gain_preQ, code_preQ, Q_new, T0, T0_frac, st_fx->coder_type, st_fx->core_brate, + st_fx->element_mode, st_fx->idchan, st_fx->hBWE_TD != NULL, st_fx->tdm_LRTD_flag ); /*-----------------------------------------------------------------* * Synthesize speech to update mem_syn[]. diff --git a/lib_enc/ivas_core_pre_proc_front_fx.c b/lib_enc/ivas_core_pre_proc_front_fx.c index 76640e7a7..f1e6b2193 100644 --- a/lib_enc/ivas_core_pre_proc_front_fx.c +++ b/lib_enc/ivas_core_pre_proc_front_fx.c @@ -1104,12 +1104,7 @@ ivas_error pre_proc_front_ivas_fx( move16(); } -#ifdef REMOVE_EVS_DUPLICATES - analy_lp_ivas_fx( inp_12k8_fx, L_FRAME, L_look, ener_fx, A_fx, epsP_h, epsP_l, lsp_new_fx, lsp_mid_fx, st->lsp_old1_fx, alw_pitch_lag_12k8, alw_voicing_fx, INT_FS_12k8, element_mode, i, *Q_new, Q_r ); -#else - analy_lp_ivas_fx( inp_12k8_fx, L_FRAME, L_look, ener_fx, A_fx, epsP_h, epsP_l, lsp_new_fx, lsp_mid_fx, st->lsp_old1_fx, alw_pitch_lag_12k8, alw_voicing_fx, - INT_FS_12k8, i, *Q_new, Q_r ); -#endif + analy_lp_fx( inp_12k8_fx, L_FRAME, L_look, ener_fx, A_fx, epsP_h, epsP_l, lsp_new_fx, lsp_mid_fx, st->lsp_old1_fx, alw_pitch_lag_12k8, alw_voicing_fx, INT_FS_12k8, element_mode, i, *Q_new, Q_r ); FOR( Word16 idx = 0; idx < M + 1; idx++ ) { diff --git a/lib_enc/ivas_core_pre_proc_fx.c b/lib_enc/ivas_core_pre_proc_fx.c index 41e409456..938ab9964 100644 --- a/lib_enc/ivas_core_pre_proc_fx.c +++ b/lib_enc/ivas_core_pre_proc_fx.c @@ -1140,20 +1140,11 @@ ivas_error ivas_compute_core_buffers_fx( IF( Q_new ) { -#ifdef REMOVE_EVS_DUPLICATES - analy_lp_ivas_fx( inp_16k_fx, L_FRAME16k, L_look, ener_fx, A_fx, epsP_h, epsP_l, lsp_new_fx, lsp_mid_fx, st->lspold_enc_fx, st->pitch, st->voicing_fx, INT_FS_16k, element_mode, 0, sub( *Q_new, 1 ), Q_r ); -#else - analy_lp_ivas_fx( inp_16k_fx, L_FRAME16k, L_look, ener_fx, A_fx, epsP_h, epsP_l, lsp_new_fx, lsp_mid_fx, st->lspold_enc_fx, st->pitch, st->voicing_fx, INT_FS_16k, 0, sub( *Q_new, 1 ), Q_r ); -#endif + analy_lp_fx( inp_16k_fx, L_FRAME16k, L_look, ener_fx, A_fx, epsP_h, epsP_l, lsp_new_fx, lsp_mid_fx, st->lspold_enc_fx, st->pitch, st->voicing_fx, INT_FS_16k, element_mode, 0, sub( *Q_new, 1 ), Q_r ); } ELSE { -#ifdef REMOVE_EVS_DUPLICATES - analy_lp_ivas_fx( inp_16k_fx, L_FRAME16k, L_look, ener_fx, A_fx, epsP_h, epsP_l, lsp_new_fx, lsp_mid_fx, st->lspold_enc_fx, st->pitch, st->voicing_fx, INT_FS_16k, element_mode, 0, -1, Q_r ); - -#else - analy_lp_ivas_fx( inp_16k_fx, L_FRAME16k, L_look, ener_fx, A_fx, epsP_h, epsP_l, lsp_new_fx, lsp_mid_fx, st->lspold_enc_fx, st->pitch, st->voicing_fx, INT_FS_16k, 0, -1, Q_r ); -#endif + analy_lp_fx( inp_16k_fx, L_FRAME16k, L_look, ener_fx, A_fx, epsP_h, epsP_l, lsp_new_fx, lsp_mid_fx, st->lspold_enc_fx, st->pitch, st->voicing_fx, INT_FS_16k, element_mode, 0, -1, Q_r ); } /*--------------------------------------------------------------* diff --git a/lib_enc/ivas_front_vad_fx.c b/lib_enc/ivas_front_vad_fx.c index b3c563863..f2b3adece 100644 --- a/lib_enc/ivas_front_vad_fx.c +++ b/lib_enc/ivas_front_vad_fx.c @@ -629,11 +629,7 @@ ivas_error front_vad_spar_fx( hFrontVad->q_buffer_12k8 = Q_inp_12k8; move16(); -#ifdef REMOVE_EVS_DUPLICATES - analy_lp_ivas_fx( inp_12k8_fx, L_FRAME, L_LOOK_12k8, &res_energy_fx, A_fx, epsP_h, epsP_l, lsp_new_fx, lsp_mid_fx, st->lsp_old1_fx, alw_pitch_lag_12k8, alw_voicing_fx, INT_FS_12k8, st->element_mode, 0, Q_inp_12k8, Q_r ); -#else - analy_lp_ivas_fx( inp_12k8_fx, L_FRAME, L_LOOK_12k8, &res_energy_fx, A_fx, epsP_h, epsP_l, lsp_new_fx, lsp_mid_fx, st->lsp_old1_fx, alw_pitch_lag_12k8, alw_voicing_fx, INT_FS_12k8, 0 /* <-- sec_chan_low_rate */, Q_inp_12k8, Q_r ); -#endif + analy_lp_fx( inp_12k8_fx, L_FRAME, L_LOOK_12k8, &res_energy_fx, A_fx, epsP_h, epsP_l, lsp_new_fx, lsp_mid_fx, st->lsp_old1_fx, alw_pitch_lag_12k8, alw_voicing_fx, INT_FS_12k8, st->element_mode, 0, Q_inp_12k8, Q_r ); FOR( Word16 i = 0; i <= M; i++ ) { diff --git a/lib_enc/ivas_td_low_rate_enc_fx.c b/lib_enc/ivas_td_low_rate_enc_fx.c index 77ddb35aa..d10527a24 100644 --- a/lib_enc/ivas_td_low_rate_enc_fx.c +++ b/lib_enc/ivas_td_low_rate_enc_fx.c @@ -365,11 +365,12 @@ void encod_gen_2sbfr( move16(); move16(); } + /*-----------------------------------------------------------------* * Prepare TBE excitation *-----------------------------------------------------------------*/ - prep_tbe_exc_ivas_fx( L_frame, L_SUBFR, i_subfr, gain_pit, gain_code, code, voice_fac, &voice_factors[i_subfr / L_SUBFR], bwe_exc, 0, NULL, Q_new, T0, T0_frac, coder_type, st->core_brate, st->element_mode, st->idchan, st->hBWE_TD != NULL, st->tdm_LRTD_flag ); + prep_tbe_exc_fx( L_frame, L_SUBFR, i_subfr, gain_pit, gain_code, code, voice_fac, &voice_factors[i_subfr / L_SUBFR], bwe_exc, 0, NULL, Q_new, T0, T0_frac, coder_type, st->core_brate, st->element_mode, st->idchan, st->hBWE_TD != NULL, st->tdm_LRTD_flag ); voice_factors[i_subfr / L_SUBFR + 1] = voice_factors[i_subfr / L_SUBFR]; /* Q15 */ move16(); @@ -378,6 +379,7 @@ void encod_gen_2sbfr( * Synthesize speech to update mem_syn_flt[]. * Update A(z) filters *-----------------------------------------------------------------*/ + Syn_filt_s( 1, p_Aq, M, &exc[i_subfr], &syn[i_subfr], 2 * L_SUBFR, hLPDmem->mem_syn, 1 ); p_Aw += 2 * ( M + 1 ); p_Aq += 2 * ( M + 1 ); diff --git a/lib_enc/lsf_enc_fx.c b/lib_enc/lsf_enc_fx.c index 8fe425d74..b26532b15 100644 --- a/lib_enc/lsf_enc_fx.c +++ b/lib_enc/lsf_enc_fx.c @@ -289,13 +289,16 @@ void lsf_enc_fx( { int_lsp4_fx( st_fx->L_frame, st_fx->lsp_old_fx, lsp_mid, lsp_new, Aq, M, 0 ); } + /*------------------------------------------------------------------* * Check LSF stability (distance between old LSFs and current LSFs) *------------------------------------------------------------------*/ + IF( NE_32( st_fx->core_brate, SID_2k40 ) ) { st_fx->stab_fac_fx = lsf_stab_fx( lsf_new, st_fx->lsf_old_fx, 0, st_fx->L_frame ); } + return; } @@ -1982,7 +1985,7 @@ static void first_VQstages( dist[1] = dist_buf + maxC; move16(); - set16_fx( idx_buf, 0, ( const Word16 )( 2 * stagesVQ * maxC ) ); + set16_fx( idx_buf, 0, (const Word16) ( 2 * stagesVQ * maxC ) ); set16_fx( parents, 0, maxC ); /* Set up inital distance vector */ @@ -2172,7 +2175,7 @@ static void first_VQstages_ivas_fx( dist[1] = dist_buf + maxC; move16(); - set16_fx( idx_buf, 0, ( const Word16 )( 2 * stagesVQ * maxC ) ); + set16_fx( idx_buf, 0, (const Word16) ( 2 * stagesVQ * maxC ) ); set16_fx( parents, 0, maxC ); /* Set up inital distance vector */ diff --git a/lib_enc/pre_proc_fx.c b/lib_enc/pre_proc_fx.c index e8d4a0722..cc8b64ca4 100644 --- a/lib_enc/pre_proc_fx.c +++ b/lib_enc/pre_proc_fx.c @@ -213,7 +213,7 @@ void pre_proc_fx( /*----------------------------------------------------------------* * Change the sampling frequency to 12.8 kHz *----------------------------------------------------------------*/ - modify_Fs_fx( signal_in, input_frame, st->input_Fs, new_inp_12k8, INT_FS_12k8, st->mem_decim_fx, ( const Word16 )( EQ_16( st->max_bwidth, NB ) ) ); + modify_Fs_fx( signal_in, input_frame, st->input_Fs, new_inp_12k8, INT_FS_12k8, st->mem_decim_fx, (const Word16) ( EQ_16( st->max_bwidth, NB ) ) ); Copy( new_inp_12k8, st->buf_speech_enc + L_FRAME32k, L_FRAME ); Scale_sig( st->buf_speech_enc + L_FRAME32k, L_FRAME, 1 ); /*------------------------------------------------------------------* @@ -414,11 +414,7 @@ void pre_proc_fx( alw_voicing[1] = st->voicing_fx[2]; move16(); -#ifdef REMOVE_EVS_DUPLICATES - analy_lp_ivas_fx( inp_12k8, L_FRAME, L_look, ener, A, epsP_h, epsP_l, lsp_new, lsp_mid, st->lsp_old1_fx, alw_pitch_lag_12k8, alw_voicing, INT_FS_12k8, EVS_MONO, 0, *Q_new, Q_r ); -#else - analy_lp_fx( inp_12k8, L_FRAME, L_look, ener, A, epsP_h, epsP_l, lsp_new, lsp_mid, st->lsp_old1_fx, alw_pitch_lag_12k8, alw_voicing, INT_FS_12k8, -1 /*IVAS_CODE !! LowRateFlag*/, *Q_new, Q_r ); -#endif + analy_lp_fx( inp_12k8, L_FRAME, L_look, ener, A, epsP_h, epsP_l, lsp_new, lsp_mid, st->lsp_old1_fx, alw_pitch_lag_12k8, alw_voicing, INT_FS_12k8, EVS_MONO, 0, *Q_new, Q_r ); lsp2lsf_fx( lsp_new, lsf_new, M, INT_FS_12k8 ); stab_fac = lsf_stab_fx( lsf_new, st->lsf_old1_fx, 0, L_FRAME ); @@ -1131,11 +1127,7 @@ void pre_proc_fx( Copy( st->lsp_old1_fx, st->lspold_enc_fx, M ); } -#ifdef REMOVE_EVS_DUPLICATES - analy_lp_ivas_fx( inp_16k, L_FRAME16k, L_look, ener, A, epsP_h, epsP_l, lsp_new, lsp_mid, st->lspold_enc_fx, st->pitch, st->voicing_fx, 16000, EVS_MONO, 0, *Q_new, Q_r ); -#else - analy_lp_fx( inp_16k, L_FRAME16k, L_look, ener, A, epsP_h, epsP_l, lsp_new, lsp_mid, st->lspold_enc_fx, st->pitch, st->voicing_fx, 16000, -1 /*IVAS_CODE !! LowRateFlag*/, *Q_new, Q_r ); -#endif + analy_lp_fx( inp_16k, L_FRAME16k, L_look, ener, A, epsP_h, epsP_l, lsp_new, lsp_mid, st->lspold_enc_fx, st->pitch, st->voicing_fx, 16000, EVS_MONO, 0, *Q_new, Q_r ); /*--------------------------------------------------------------* * Compute Weighted Input diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 1d85ae6de..968ab0082 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -41,9 +41,8 @@ #include "ivas_error_utils.h" #include "complex_basop.h" #include "ivas_stat_enc.h" -/*----------------------------------------------------------------------------------* - * Prototypes of RAM counting tool macros - *----------------------------------------------------------------------------------*/ + + ivas_error acelp_core_enc_fx( Encoder_State *st_fx, /* i/o: encoder state structure */ const Word16 inp_fx[], /* i : input signal of the current frame Q_new*/ @@ -68,57 +67,37 @@ ivas_error acelp_core_enc_fx( ); -void analy_lp_ivas_fx( - const Word16 speech[], /* i :(Q_new) pointer to the speech frame */ - const Word16 L_frame, /* i :(q0) length of the frame */ - const Word16 L_look, /* i :(q0) look-ahead */ - Word32 *ener, /* o :(Q_r) residual energy from Levinson-Durbin */ - Word16 A[], /* o :(q14) A(z) filter coefficients */ - Word16 epsP_h[], /* o :(high part of epsP(Q_r)) LP analysis residual energies for each iteration */ - Word16 epsP_l[], /* o :(low part of epsP(Q_r)) LP analysis residual energies for each iteration */ - Word16 lsp_new[], /* o :(q15) current frame LSPs */ - Word16 lsp_mid[], /* o :(q15) current mid-frame LSPs */ - Word16 lsp_old[], /* i/o:(q15) previous frame unquantized LSPs */ - const Word16 Top[2], /* i :(q0) open loop pitch lag */ - const Word16 Tnc[2], /* i :(q15) open loop pitch gain */ - const Word32 Core_sr, /* i :(q0) Internal core sampling rate */ -#ifdef REMOVE_EVS_DUPLICATES - const Word16 element_mode, /* i : element mode */ -#endif - const Word16 sec_chan_low_rate, /* i :(q0) flag to signal second channel */ - Word16 Q_new, /*i: stores Q for speech*/ - Word16 *Q_r /*stores q for ener*/ ); - -#ifndef REMOVE_EVS_DUPLICATES void analy_lp_fx( - const Word16 speech[], /* i : pointer to the speech frame Q_new*/ - const Word16 L_frame, /* i : length of the frame Q0*/ - const Word16 L_look, /* i : look-ahead Q0*/ - Word32 *ener, /* o : residual energy from Levinson-Durbin Q_r*/ - Word16 A[], /* o : A(z) filter coefficients Q14*/ - Word16 epsP_h[], /* o : LP analysis residual energies for each iteration Q_r*/ - Word16 epsP_l[], /* o : LP analysis residual energies for each iteration Q_r*/ - Word16 lsp_new[], /* o : current frame LSPs Q15*/ - Word16 lsp_mid[], /* o : current mid-frame LSPs Q15*/ - Word16 lsp_old[], /* i/o: previous frame unquantized LSPs Q15*/ - const Word16 Top[2], /* i : open loop pitch lag Q0*/ - const Word16 Tnc[2], /* i : open loop pitch gain Q15*/ - const Word32 Core_sr, /* i : Internal core sampling rate Q0*/ - const Word16 sec_chan_low_rate, /* i : flag to signal second channel Q0*/ - Word16 Q_new, - Word16 *Q_r ); -#endif - -void AVQ_cod_fx( /* o: comfort noise gain factor */ - const Word16 xri[], /* i: vector to quantize */ - Word16 xriq[], /* o: quantized normalized vector (assuming the bit budget is enough) */ - const Word16 NB_BITS, /* i: number of allocated bits */ - const Word16 Nsv, /* i: number of subvectors (lg=Nsv*8) */ - const Word16 Q_in_ref /* i: Scaling i */ + const Word16 speech[], /* i :(Q_new) pointer to the speech frame */ + const Word16 L_frame, /* i :(q0) length of the frame */ + const Word16 L_look, /* i :(q0) look-ahead */ + Word32 *ener, /* o :(Q_r) residual energy from Levinson-Durbin */ + Word16 A[], /* o :(q14) A(z) filter coefficients */ + Word16 epsP_h[], /* o :(high part of epsP(Q_r)) LP analysis residual energies for each iteration */ + Word16 epsP_l[], /* o :(low part of epsP(Q_r)) LP analysis residual energies for each iteration */ + Word16 lsp_new[], /* o :(q15) current frame LSPs */ + Word16 lsp_mid[], /* o :(q15) current mid-frame LSPs */ + Word16 lsp_old[], /* i/o:(q15) previous frame unquantized LSPs */ + const Word16 Top[2], /* i :(q0) open loop pitch lag */ + const Word16 Tnc[2], /* i :(q15) open loop pitch gain */ + const Word32 Core_sr, /* i :(q0) Internal core sampling rate */ + const Word16 element_mode, /* i : element mode */ + const Word16 sec_chan_low_rate, /* i :(q0) flag to signal second channel */ + Word16 Q_new, /* i : stores Q for speech */ + Word16 *Q_r /*stores q for ener*/ +); + +/*1 r: comfort noise gain factor */ +void AVQ_cod_fx( + const Word16 xri[], /* i: vector to quantize */ + Word16 xriq[], /* o: quantized normalized vector (assuming the bit budget is enough) */ + const Word16 NB_BITS, /* i: number of allocated bits */ + const Word16 Nsv, /* i: number of subvectors (lg=Nsv*8) */ + const Word16 Q_in_ref /* i: Scaling i */ ); void AVQ_encmux_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */ + BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */ const Word16 extl, /* i : extension layer */ Word16 xriq[], /* i/o: rounded subvectors [0..8*Nsv-1] followed by rounded bit allocations [8*Nsv..8*Nsv+Nsv-1] */ @@ -130,7 +109,7 @@ void AVQ_encmux_fx( ); void AVQ_encmux_ivas_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */ + BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */ const Word16 extl, /* i : extension layer */ Word16 xriq[], /* i/o: rounded subvectors [0..8*Nsv-1] followed by rounded bit allocations [8*Nsv..8*Nsv+Nsv-1] */ @@ -151,15 +130,15 @@ void bw_detect_fx( const Word16 mct_on, /* i : flag MCT mode */ const Word16 Q_spec ); -void core_switching_post_enc_fx( /*done */ - Encoder_State *st_fx, /* i/o: encoder state structure */ - 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 Qsp, /* i/o : Q from acelp synthsis */ - Word16 *Qmus /* i/o : Q from mdct synthsis / Q of output synthesis */ +void core_switching_post_enc_fx( + Encoder_State *st_fx, /* i/o: encoder state structure */ + 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 Qsp, /* i/o : Q from acelp synthsis */ + Word16 *Qmus /* i/o : Q from mdct synthsis / Q of output synthesis */ ); void core_switching_pre_enc_fx( @@ -170,8 +149,9 @@ void core_switching_pre_enc_fx( const Word16 last_element_mode /* i : last_element_mode Q0*/ ); -Word16 correlation_shift_fx( /* o : noise dependent voicing correction Q15 */ - const Word16 totalNoise_fx /* i/o: noise estimate over all critical bands Q8 */ +/*! r: noise dependent voicing correction Q15 */ +Word16 correlation_shift_fx( + const Word16 totalNoise_fx /* i/o: noise estimate over all critical bands Q8 */ ); void dtx_fx( diff --git a/lib_enc/transition_enc_fx.c b/lib_enc/transition_enc_fx.c index c724ffd6c..d0d627697 100644 --- a/lib_enc/transition_enc_fx.c +++ b/lib_enc/transition_enc_fx.c @@ -212,13 +212,9 @@ void transition_enc_fx( IF( EQ_16( *tc_subfr, TC_0_0 ) ) { /* this is called only to compute unused bits */ -#ifdef REMOVE_EVS_DUPLICATES - config_acelp1_IVAS( ENC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl, st_fx->extl_brate, -#else - config_acelp1( ENC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl, st_fx->extl_brate, -#endif - L_FRAME, -1, &( st_fx->acelp_cfg ), hBstr->nb_bits_tot, TRANSITION, -1, TC_0_0, 3, NULL, unbits_ACELP, - st_fx->element_mode, &i /*dummy*/, 0 /*tdm_lp_reuse_flag*/, 0 /*tdm_low_rate_mode*/, st_fx->idchan, st_fx->active_fr_cnt_fx, 0 /*tdm_Pitch_reuse_flag*/, st_fx->tdm_LRTD_flag, 0 /*GSC_IVAS_mode*/ ); + config_acelp1_fx( ENC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl, st_fx->extl_brate, + L_FRAME, -1, &( st_fx->acelp_cfg ), hBstr->nb_bits_tot, TRANSITION, -1, TC_0_0, 3, NULL, unbits_ACELP, + st_fx->element_mode, &i /*dummy*/, 0 /*tdm_lp_reuse_flag*/, 0 /*tdm_low_rate_mode*/, st_fx->idchan, st_fx->active_fr_cnt_fx, 0 /*tdm_Pitch_reuse_flag*/, st_fx->tdm_LRTD_flag, 0 /*GSC_IVAS_mode*/ ); } *clip_gain = gp_clip_fx( st_fx->element_mode, st_fx->core_brate, st_fx->voicing_fx, i_subfr, TRANSITION, xn_fx, gp_cl_fx, sub( shift_wsp, 1 ) ); @@ -328,13 +324,9 @@ void transition_enc_fx( IF( LE_16( sub( i_subfr, *tc_subfr ), L_SUBFR ) ) { -#ifdef REMOVE_EVS_DUPLICATES - config_acelp1_IVAS( ENC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl, st_fx->extl_brate, -#else - config_acelp1( ENC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl, st_fx->extl_brate, -#endif - st_fx->L_frame, -1, &( st_fx->acelp_cfg ), hBstr->nb_bits_tot, TRANSITION, -1, *tc_subfr, 2, NULL, - unbits_ACELP, st_fx->element_mode, &i /*dummy*/, 0 /*tdm_lp_reuse_flag*/, 0 /*tdm_low_rate_mode*/, st_fx->idchan, st_fx->active_fr_cnt_fx, 0 /*tdm_Pitch_reuse_flag*/, st_fx->tdm_LRTD_flag, 0 /*GSC_IVAS_mode*/ ); + config_acelp1_fx( ENC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl, st_fx->extl_brate, + st_fx->L_frame, -1, &( st_fx->acelp_cfg ), hBstr->nb_bits_tot, TRANSITION, -1, *tc_subfr, 2, NULL, + unbits_ACELP, st_fx->element_mode, &i /*dummy*/, 0 /*tdm_lp_reuse_flag*/, 0 /*tdm_low_rate_mode*/, st_fx->idchan, st_fx->active_fr_cnt_fx, 0 /*tdm_Pitch_reuse_flag*/, st_fx->tdm_LRTD_flag, 0 /*GSC_IVAS_mode*/ ); } /*-----------------------------------------------------------------* @@ -1040,14 +1032,9 @@ void transition_enc_ivas_fx( IF( EQ_16( *tc_subfr, TC_0_0 ) ) { /* this is called only to compute unused bits */ - -#ifdef REMOVE_EVS_DUPLICATES - config_acelp1_IVAS( ENC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl, st_fx->extl_brate, -#else - config_acelp1( ENC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl, st_fx->extl_brate, -#endif - L_FRAME, -1, &( st_fx->acelp_cfg ), hBstr->nb_bits_tot, TRANSITION, -1, TC_0_0, 3, NULL, unbits_ACELP, - st_fx->element_mode, &i /*dummy*/, 0 /*tdm_lp_reuse_flag*/, 0 /*tdm_low_rate_mode*/, st_fx->idchan, st_fx->active_fr_cnt_fx, 0 /*tdm_Pitch_reuse_flag*/, st_fx->tdm_LRTD_flag, 0 /*GSC_IVAS_mode*/ + config_acelp1_fx( ENC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl, st_fx->extl_brate, + L_FRAME, -1, &( st_fx->acelp_cfg ), hBstr->nb_bits_tot, TRANSITION, -1, TC_0_0, 3, NULL, unbits_ACELP, + st_fx->element_mode, &i /*dummy*/, 0 /*tdm_lp_reuse_flag*/, 0 /*tdm_low_rate_mode*/, st_fx->idchan, st_fx->active_fr_cnt_fx, 0 /*tdm_Pitch_reuse_flag*/, st_fx->tdm_LRTD_flag, 0 /*GSC_IVAS_mode*/ ); } @@ -1158,13 +1145,9 @@ void transition_enc_ivas_fx( IF( LE_16( sub( i_subfr, *tc_subfr ), L_SUBFR ) ) { -#ifdef REMOVE_EVS_DUPLICATES - config_acelp1_IVAS( ENC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl, st_fx->extl_brate, -#else - config_acelp1( ENC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl, st_fx->extl_brate, -#endif - st_fx->L_frame, -1, &( st_fx->acelp_cfg ), hBstr->nb_bits_tot, TRANSITION, -1, *tc_subfr, 2, NULL, - unbits_ACELP, st_fx->element_mode, &i /*dummy*/, 0 /*tdm_lp_reuse_flag*/, 0 /*tdm_low_rate_mode*/, st_fx->idchan, st_fx->active_fr_cnt_fx, 0 /*tdm_Pitch_reuse_flag*/, st_fx->tdm_LRTD_flag, 0 /*GSC_IVAS_mode*/ ); + config_acelp1_fx( ENC, st_fx->total_brate, st_fx->core_brate, st_fx->core, st_fx->extl, st_fx->extl_brate, + st_fx->L_frame, -1, &( st_fx->acelp_cfg ), hBstr->nb_bits_tot, TRANSITION, -1, *tc_subfr, 2, NULL, + unbits_ACELP, st_fx->element_mode, &i /*dummy*/, 0 /*tdm_lp_reuse_flag*/, 0 /*tdm_low_rate_mode*/, st_fx->idchan, st_fx->active_fr_cnt_fx, 0 /*tdm_Pitch_reuse_flag*/, st_fx->tdm_LRTD_flag, 0 /*GSC_IVAS_mode*/ ); } /*-----------------------------------------------------------------* -- GitLab From ac901c58364fb528358a4f130523acb2d166a1a8 Mon Sep 17 00:00:00 2001 From: vaclav Date: Thu, 17 Apr 2025 15:52:49 +0200 Subject: [PATCH 054/113] rename file --- Workspace_msvc/lib_dec.vcxproj | 2 +- Workspace_msvc/lib_dec.vcxproj.filters | 6 +- lib_dec/acelp_core_dec_fx.c | 68 +- lib_dec/acelp_core_dec_ivas_fx.c | 2396 ------------------------ lib_dec/ivas_td_low_rate_dec_fx.c | 14 +- 5 files changed, 49 insertions(+), 2437 deletions(-) delete mode 100644 lib_dec/acelp_core_dec_ivas_fx.c diff --git a/Workspace_msvc/lib_dec.vcxproj b/Workspace_msvc/lib_dec.vcxproj index 2839a5812..12f77b346 100644 --- a/Workspace_msvc/lib_dec.vcxproj +++ b/Workspace_msvc/lib_dec.vcxproj @@ -139,7 +139,7 @@ false - + diff --git a/Workspace_msvc/lib_dec.vcxproj.filters b/Workspace_msvc/lib_dec.vcxproj.filters index ebf15bd4c..25079058c 100644 --- a/Workspace_msvc/lib_dec.vcxproj.filters +++ b/Workspace_msvc/lib_dec.vcxproj.filters @@ -119,9 +119,6 @@ decoder_all_c - - decoder_all_c - decoder_all_c @@ -515,6 +512,9 @@ decoder_ivas_c + + decoder_all_c + diff --git a/lib_dec/acelp_core_dec_fx.c b/lib_dec/acelp_core_dec_fx.c index 32aab2bb0..f518ef712 100644 --- a/lib_dec/acelp_core_dec_fx.c +++ b/lib_dec/acelp_core_dec_fx.c @@ -79,7 +79,7 @@ ivas_error acelp_core_dec_fx( Word32 synth_fx[960], save_hb_synth_fx[960] /*, bwe_exc_extended_fx[L_FRAME32k + NL_BUFF_OFFSET]*/; Word16 old_exc_fx[L_EXC_DEC], *exc_fx; /* excitation signal buffer */ Word16 syn_tmp_fx[L_FRAME16k + L_SUBFR], *psyn_fx; /* synthesis signal buffer */ - Word16 output_frame; /* frame length at output sampling freq. */ + Word16 output_frame; /* frame length at output sampling freq. */ Word16 lsf_new_fx[M]; /* LSFs at the end of the frame Qlog2(2.56) */ Word16 lsp_new_fx[M]; /* LSPs at the end of the frame Q15 */ Word16 lsp_mid_fx[M]; /* LSPs in the middle of the frame */ @@ -259,7 +259,7 @@ ivas_error acelp_core_dec_fx( move16(); if ( st->hPFstat != NULL ) { - /* in case of core switching, reset post-filter memories */ + /* in case of core switching, reset post-filter memories */ st->hPFstat->on = 0; move16(); } @@ -277,8 +277,8 @@ ivas_error acelp_core_dec_fx( { /* reset the GSC pre echo energy threshold in case of FEC */ st->hGSCDec->Last_frame_ener_fx = MAX_32; - move32(); - } + move32(); + } test(); test(); @@ -357,10 +357,10 @@ ivas_error acelp_core_dec_fx( test(); /* reset post-filter in case of switching */ if ( st->hPFstat != NULL && ( st->hPFstat->on == 0 ) ) - { + { st->hPFstat->reset = 1; - move16(); - } + move16(); + } avoid_lpc_burst_on_recovery = 0; move16(); @@ -663,7 +663,7 @@ ivas_error acelp_core_dec_fx( FdCng_decodeSID_fx( st->hFdCngDec->hFdCngCom, st ); } ELSE - { + { Word16 old_NoiseEstExp = st->hFdCngDec->hFdCngCom->sidNoiseEstExp; move16(); @@ -817,7 +817,7 @@ ivas_error acelp_core_dec_fx( IF( EQ_16( st->element_mode, EVS_MONO ) ) { - /* update st_fx->mem_syn1 for ACELP core switching */ + /* update st_fx->mem_syn1 for ACELP core switching */ Copy( st->mem_syn3_fx, st->mem_syn1_fx, M ); } ELSE @@ -1529,11 +1529,11 @@ ivas_error acelp_core_dec_fx( set16_fx( st->hPFstat->mem_zero, 0, M ); formant_post_filt_fx( st->hPFstat, temp_buf_fx + L_SYN_MEM, Aq_fx, psyn_fx, st->L_frame, st->lp_noise, st->total_brate, 0 ); - } + } ELSE IF( st->hPFstat != NULL && GE_16( st->last_bwidth, WB ) ) - { + { IF( st->hPFstat->on ) - { + { Copy( st->hPFstat->mem_pf_in + L_SYN_MEM - M, temp_buf_fx, M ); Copy( psyn_fx, temp_buf_fx + M, L_SUBFR ); @@ -1604,9 +1604,9 @@ ivas_error acelp_core_dec_fx( test(); test(); test(); - test(); - test(); - test(); + test(); + test(); + test(); test(); test(); test(); @@ -1626,7 +1626,7 @@ ivas_error acelp_core_dec_fx( { test(); IF( NE_16( st->element_mode, last_element_mode ) && ( st->idchan == 0 ) ) - { + { /* Clear memory for secondary channel CNA */ set16_fx( hStereoCng->olapBufferSynth22_fx, 0, shr( st->hFdCngDec->hFdCngCom->frameSize, 1 ) ); } @@ -1710,8 +1710,8 @@ ivas_error acelp_core_dec_fx( test(); test(); test(); - test(); - test(); + test(); + test(); test(); IF( ( st->flag_cna == 0 ) && EQ_16( st->L_frame, L_FRAME16k ) && EQ_16( st->last_flag_cna, 1 ) && ( ( st->last_core == ACELP_CORE && !( EQ_16( st->last_coder_type, AUDIO ) && !( st->element_mode > EVS_MONO && st->Last_GSC_noisy_speech_flag ) ) ) || EQ_16( st->last_core, AMR_WB_CORE ) ) ) { @@ -1746,7 +1746,7 @@ ivas_error acelp_core_dec_fx( set16_fx( st->hFdCngDec->hFdCngCom->olapBufferSynth2, 0, st->hFdCngDec->hFdCngCom->fftlen ); } IF( hStereoCng != NULL && ( st->idchan == 0 ) ) - { + { set16_fx( hStereoCng->olapBufferSynth22_fx, 0, st->hFdCngDec->hFdCngCom->fftlen ); } } @@ -1763,26 +1763,26 @@ ivas_error acelp_core_dec_fx( CLDFB_SCALE_FACTOR scaleFactor; Word32 workBuffer[128 * 3]; - /* check if the CLDFB works on the right sample rate */ + /* check if the CLDFB works on the right sample rate */ IF( ( st->cldfbAna->usb * st->cldfbAna->no_col ) != st->L_frame ) - { - /* resample to ACELP internal sampling rate */ + { + /* resample to ACELP internal sampling rate */ Word16 newCldfbBands = CLDFB_getNumChannels( L_mult0( st->L_frame, FRAMES_PER_SEC ) ); resampleCldfb( st->cldfbAna, newCldfbBands, st->L_frame, 0 ); resampleCldfb( st->cldfbBPF, newCldfbBands, st->L_frame, 0 ); IF( st->ini_frame > 0 ) - { + { st->cldfbSyn->bandsToZero = sub( st->cldfbSyn->no_channels, st->cldfbAna->no_channels ); - move16(); + move16(); + } } - } - test(); + test(); IF( NE_16( st->L_frame, st->last_L_frame ) && NE_16( st->last_codec_mode, MODE2 ) ) - { - IF( EQ_16( st->L_frame, L_FRAME ) ) { + IF( EQ_16( st->L_frame, L_FRAME ) ) + { retro_interp5_4_fx( st->hBPF->pst_old_syn_fx ); } ELSE IF( EQ_16( st->L_frame, L_FRAME16k ) ) @@ -2091,8 +2091,8 @@ ivas_error acelp_core_dec_fx( imagBuffer_fx[i][j] = imagBufferSave_fx[i][j]; move32(); move32(); - } - } + } + } #ifndef OPT_AVOID_STATE_BUF_RESCALE Scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( sub( Q_real, 1 ), Q10 ) ); // Q_real-1 st->cldfbSynHB->Q_cldfb_state = sub( Q_real, 1 ); @@ -2147,7 +2147,7 @@ ivas_error acelp_core_dec_fx( scale_sig32( synth_fx, output_frame, negate( sub( Q_real, 1 ) ) ); // Q0 scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( Q10, sub( Q_real, 1 ) ) ); // Q10 st->cldfbSyn->Q_cldfb_state = Q10; - move16(); + move16(); } /* save synthesis - needed in case of core switching */ @@ -2159,10 +2159,10 @@ ivas_error acelp_core_dec_fx( /* analysis of the synthesis at internal sampling rate - needed for DFT stereo -> TD stereo switching */ FOR( i = 0; i < st->L_frame; i++ ) - { + { syn_32_fx[i] = L_shr( L_deposit_h( psyn_fx[i] ), add( 4, st->Q_syn ) ); move32(); - } + } Word16 offset = sub( st->cldfbAna->p_filter_length, st->cldfbAna->no_channels ); Scale_sig32( st->cldfbAna->cldfb_state_fx, offset, 1 ); // Q12 @@ -2340,7 +2340,7 @@ ivas_error acelp_core_dec_fx( non_linearity_fx( bwe_exc_fx, bwe_exc_extended_fx, L_FRAME32k, &st->hBWE_TD->bwe_non_lin_prev_scale_fx, st->Q_exc, st->coder_type, voice_factors_fx, st->L_frame ); } ELSE - { + { Copy_Scale_sig_16_32_no_sat( st->hBWE_TD->old_bwe_exc_extended_fx, bwe_exc_extended_fx, NL_BUFF_OFFSET, ( sub( shl( st->Q_exc, 1 ), sub( st->prev_Q_bwe_exc, 16 ) ) ) ); // prev_Q_bwe_exc non_linearity_ivas_fx( bwe_exc_fx, bwe_exc_extended_fx + NL_BUFF_OFFSET, L_FRAME32k, &st->hBWE_TD->bwe_non_lin_prev_scale_fx, st->Q_exc, st->coder_type, voice_factors_fx, st->L_frame ); Copy_Scale_sig_32_16( bwe_exc_extended_fx + L_FRAME32k, st->hBWE_TD->old_bwe_exc_extended_fx, NL_BUFF_OFFSET, negate( sub( shl( st->Q_exc, 1 ), sub( st->prev_Q_bwe_exc, 16 ) ) ) ); // prev_Q_bwe_exc diff --git a/lib_dec/acelp_core_dec_ivas_fx.c b/lib_dec/acelp_core_dec_ivas_fx.c deleted file mode 100644 index 2c72bba78..000000000 --- a/lib_dec/acelp_core_dec_ivas_fx.c +++ /dev/null @@ -1,2396 +0,0 @@ -/****************************************************************************************************** - - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, - Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., - Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, - Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other - contributors to this repository. All Rights Reserved. - - This software is protected by copyright law and by international treaties. - The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB, - Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., - Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, - Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other - contributors to this repository retain full ownership rights in their respective contributions in - the software. This notice grants no license of any kind, including but not limited to patent - license, nor is any license granted by implication, estoppel or otherwise. - - Contributors are required to enter into the IVAS codec Public Collaboration agreement before making - contributions. - - This software is provided "AS IS", without any express or implied warranties. The software is in the - development stage. It is intended exclusively for experts who have experience with such software and - solely for the purpose of inspection. All implied warranties of non-infringement, merchantability - and fitness for a particular purpose are hereby disclaimed and excluded. - - Any dispute, controversy or claim arising under or in relation to providing this software shall be - submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in - accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and - the United Nations Convention on Contracts on the International Sales of Goods. - -*******************************************************************************************************/ - -/*==================================================================================== - EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0 - ====================================================================================*/ -#include -#include -#include -#include "options.h" -#include "cnst.h" -#include "rom_com.h" -#include "prot_fx.h" -#include "ivas_cnst.h" -#include "ivas_rom_com.h" -#include "wmc_auto.h" -#include "ivas_prot_fx.h" - - -/*-------------------------------------------------------------------* - * acelp_core_dec_fx() - * - * ACELP core decoder - *-------------------------------------------------------------------*/ - -ivas_error acelp_core_dec_fx( - Decoder_State *st, /* i/o: decoder state structure */ - Word16 output_fx[], /* o : synthesis @internal Fs Q_syn*/ - Word16 synth_fx16[], /* o : synthesis Q_syn2*/ - Word16 save_hb_synth_fx16[], /* o : HB synthesis Q0*/ - Word32 bwe_exc_extended_fx[], /* i/o: bandwidth extended excitation 2*Q_exc*/ - Word16 *voice_factors_fx, /* o : voicing factors Q15*/ - Word16 old_syn_12k8_16k_fx[], /* o : intermediate ACELP synthesis at 12.8kHz or 16kHz to be used by SWB BWE Q_syn2-1*/ - const Word16 sharpFlag, /* i : formant sharpening flag */ - Word16 pitch_buf_fx[NB_SUBFR16k], /* o : Word16 pitch for each subframe Q6*/ - Word16 *unbits, /* o : number of unused bits */ - Word16 *sid_bw, /* o : 0-NB/WB, 1-SWB SID */ - STEREO_TD_DEC_DATA_HANDLE hStereoTD, /* i/o: TD stereo decoder handle Qlog2(2.56)*/ - const Word16 tdm_lspQ_PCh_fx[M], /* i : Q LSPs for primary channel Q15*/ - const Word16 tdm_lsfQ_PCh_fx[M], /* i : Q LSFs for primary channel */ - const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ - const Word16 last_element_mode, /* i : last element mode */ - const Word32 last_element_brate, /* i : last element bitrate */ - const Word16 flag_sec_CNA, /* i : CNA flag for secondary channel */ - const Word16 nchan_out, /* i : number of output channels */ - STEREO_CNG_DEC_HANDLE hStereoCng, /* i : stereo CNG handle */ - const Word16 read_sid_info /* i : read SID info flag */ -) -{ - Word32 synth_fx[960], save_hb_synth_fx[960] /*, bwe_exc_extended_fx[L_FRAME32k + NL_BUFF_OFFSET]*/; - Word16 old_exc_fx[L_EXC_DEC], *exc_fx; /* excitation signal buffer */ - Word16 syn_tmp_fx[L_FRAME16k + L_SUBFR], *psyn_fx; /* synthesis signal buffer */ - Word16 output_frame; /* frame length at output sampling freq. */ - Word16 lsf_new_fx[M]; /* LSFs at the end of the frame Qlog2(2.56) */ - Word16 lsp_new_fx[M]; /* LSPs at the end of the frame Q15 */ - Word16 lsp_mid_fx[M]; /* LSPs in the middle of the frame */ - Word16 Aq_fx[NB_SUBFR16k * ( M + 1 )]; /* A(q) quantized for the 4 subframes */ - Word16 old_exc2_fx[L_FRAME16k + L_EXC_MEM], *exc2_fx; /* total excitation buffer */ - Word16 mem_tmp_fx[M]; /* temporary synthesis filter memory */ - Word32 enr_q_fx; /* E information for FER protection */ - Word16 tmp_noise_fx; /* Long term temporary noise energy */ - Word16 Es_pred_fx; /* predicted scaled innov. energy Q8 */ - Word16 FEC_pitch_fx; /* FEC pitch */ - Word16 old_bwe_exc_fx[( ( PIT16k_MAX + ( L_FRAME16k + 1 ) + L_SUBFR16k ) * 2 )]; /* excitation buffer */ - Word16 *bwe_exc_fx; /* Excitation for SWB TBE */ - Word16 i, j, int_fs; - Word16 tc_subfr; - Word16 allow_cn_step; - Word16 temp_buf_fx[L_FRAME16k + L_SYN_MEM]; - Word16 last_pulse_pos; - Word16 T0_tmp; - Word16 do_WI; - Word16 dct_buffer_fx[DCT_L_POST]; - Word16 exc_buffer_fx[DCT_L_POST]; - Word16 dct_exc_tmp_fx[L_FRAME16k]; - Word16 nb_bits; /* number of bits */ - Word16 indice; /* parameter indices to write */ - Word16 gain_buf_fx[NB_SUBFR16k]; - Word16 syn_fx_tmp2[L_FRAME_16k]; - Word16 pitch_buf_tmp[NB_SUBFR16k]; - Word16 update_flg; - Word32 q_env_fx[20]; - Word16 exc3_fx[L_FRAME16k]; - Word16 syn1_tmp_fx[L_FRAME16k + 2], *syn1_fx; - Word32 *realBuffer_fx[CLDFB_NO_COL_MAX], *imagBuffer_fx[CLDFB_NO_COL_MAX]; - Word32 realBufferTmp_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; - Word32 imagBufferTmp_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; - Word16 LSF_Q_prediction; /* LSF prediction mode */ - Word16 avoid_lpc_burst_on_recovery; - Word16 tmpF_fx; - Word16 uc_two_stage_flag; - Word16 tdm_lp_reuse_flag, tdm_low_rate_mode, tdm_Pitch_reuse_flag; - Word16 *old_exc_s_fx; /* Start of last excitation frame */ - Word16 *p_tdm_Pri_pitch_buf_fx; - Word16 tmp, exp, local_element_mode; - ivas_error error; - Word32 bpf_error_signal_fx[L_FRAME16k]; - Word16 bpf_error_signal_16fx[L_FRAME16k]; - Word16 Q_real; - Word32 max_real, max_imag, max_val; - - set32_fx( bpf_error_signal_fx, 0, L_FRAME16k ); - set16_fx( bpf_error_signal_16fx, 0, L_FRAME16k ); - set16_fx( Aq_fx, 0, NB_SUBFR16k * ( M + 1 ) ); - set16_fx( old_bwe_exc_fx, 0, ( ( PIT16k_MAX + ( L_FRAME16k + 1 ) + L_SUBFR16k ) * 2 ) ); - - error = IVAS_ERR_OK; - move32(); - - test(); - test(); - test(); - IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && EQ_16( nchan_out, 1 ) && EQ_16( st->idchan, 1 ) && LE_32( last_element_brate, IVAS_SID_5k2 ) ) - { - /* In MDCT-Stereo DTX with mono output, we can skip CNG for the second channel, except for the first inactive frame following an active period */ - return error; - } - - push_wmops( "acelp_core_dec" ); - - /* output_frame = (int16_t) ( st->output_Fs / FRAMES_PER_SEC ); */ - output_frame = extract_l( Mpy_32_32( st->output_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ); - - /*----------------------------------------------------------------* - * stereo SID and CNG frames processing - *----------------------------------------------------------------*/ - - test(); - test(); - IF( LE_32( st->core_brate, SID_2k40 ) && EQ_16( st->element_mode, IVAS_CPE_DFT ) && EQ_16( nchan_out, 2 ) ) - { - IF( EQ_16( st->cng_type, FD_CNG ) ) - { - configureFdCngDec_fx( st->hFdCngDec, st->bwidth, ACELP_14k25, st->L_frame, st->last_L_frame, st->element_mode ); - - Word16 old_NoiseEstExp; - old_NoiseEstExp = st->hFdCngDec->hFdCngCom->sidNoiseEstExp; - move16(); - - /* Only run parameter decoding in SID frames */ - IF( EQ_32( st->core_brate, SID_2k40 ) ) - { - FdCng_decodeSID_ivas_fx( st ); - - Word16 n1, n2; - n1 = L_norm_arr( st->hFdCngDec->hFdCngCom->sidNoiseEst, NPART ); - n2 = L_norm_arr( st->hFdCngDec->hFdCngCom->sidNoiseEstLp, NPART ); - - Word16 common_e = s_max( sub( old_NoiseEstExp, n2 ), sub( st->hFdCngDec->hFdCngCom->sidNoiseEstExp, n1 ) ); - scale_sig32( st->hFdCngDec->hFdCngCom->sidNoiseEst, NPART, sub( st->hFdCngDec->hFdCngCom->sidNoiseEstExp, common_e ) ); - scale_sig32( st->hFdCngDec->hFdCngCom->sidNoiseEstLp, NPART, sub( old_NoiseEstExp, common_e ) ); - st->hFdCngDec->hFdCngCom->sidNoiseEstExp = common_e; - move16(); - } - - FOR( i = 0; i < NPART; i++ ) - { - st->hFdCngDec->hFdCngCom->sidNoiseEstLp[i] = Madd_32_32( Mpy_32_32( STEREO_DFT_FD_FILT_Q31, st->hFdCngDec->hFdCngCom->sidNoiseEstLp[i] ), - STEREO_DFT_FD_FILT_COMP_Q31, st->hFdCngDec->hFdCngCom->sidNoiseEst[i] ); - move32(); - } - - ApplyFdCng_fx( NULL, 0, NULL, 0, NULL, NULL, NULL, st, 0, 0 ); - } - ELSE - { - configureFdCngDec_fx( st->hFdCngDec, st->bwidth, ACELP_14k25, st->L_frame, st->last_L_frame, st->element_mode ); - - /* decode CNG parameters */ - CNG_dec_fx( st, last_element_mode, Aq_fx, lsp_new_fx, lsf_new_fx, &allow_cn_step, sid_bw, q_env_fx ); - - /* comfort noise generation */ - CNG_exc_fx( st->core_brate, st->L_frame, &st->hTdCngDec->Enew_fx, &st->hTdCngDec->cng_seed, NULL, NULL, &st->lp_ener_fx, st->last_core_brate, &st->first_CNG, &( st->hTdCngDec->cng_ener_seed ), NULL, allow_cn_step, &st->hTdCngDec->last_allow_cn_step, st->prev_Q_exc, st->Q_exc, st->hTdCngDec->num_ho, q_env_fx, st->hTdCngDec->lp_env_fx, st->hTdCngDec->old_env_fx, st->hTdCngDec->exc_mem_fx, st->hTdCngDec->exc_mem1_fx, sid_bw, &st->hTdCngDec->cng_ener_seed1, NULL, st->Opt_AMR_WB, st->element_mode ); - - Copy( Aq_fx, st->Aq_cng, M + 1 ); /*Q12*/ - - /* update old LSP and LSF vector */ - Copy( lsf_new_fx, st->lsf_old_fx, M ); /*Qlog2(2.56)*/ - Copy( lsp_new_fx, st->lsp_old_fx, M ); /*Q15*/ - } - - set16_fx( output_fx, 0, output_frame ); /* output and synth are not used in DFT domain CNG generation and the decoder output is unaffected if they are left uninitalized */ - set16_fx( synth_fx16, 0, output_frame ); /* They are however read in a few places which causes errors in the valgrind tests. Simplest solution from a code perspective was to set them to zero. */ - - /* CN generation done in DFT domain */ - pop_wmops(); - - return error; - } - - /*----------------------------------------------------------------* - * Active frames processing - *----------------------------------------------------------------*/ - - /* open CLDFB buffer up to CLDFB_NO_CHANNELS_MAX bands for 48kHz */ - FOR( i = 0; i < CLDFB_NO_COL_MAX; 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]; - } - - /*----------------------------------------------------------------* - * Initialization - *----------------------------------------------------------------*/ - - LSF_Q_prediction = -1; - move16(); - set16_fx( syn_tmp_fx, 0, L_SUBFR ); - psyn_fx = syn_tmp_fx + L_SUBFR; - syn1_tmp_fx[0] = 0; - move16(); - syn1_tmp_fx[1] = 0; - move16(); - syn1_fx = syn1_tmp_fx + 2; - st->bpf_off = 0; - move16(); - - test(); - test(); - test(); - test(); - test(); - test(); - IF( EQ_16( st->last_core, HQ_CORE ) || EQ_16( st->last_core, TCX_20_CORE ) || EQ_16( st->last_core, TCX_10_CORE ) || ( EQ_16( st->element_mode, IVAS_CPE_DFT ) && LE_32( st->last_core_brate, SID_2k40 ) ) || ( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && LE_32( st->last_core_brate, SID_2k40 ) ) ) - { - /* in case of HQ->ACELP switching, do not apply BPF */ - st->bpf_off = 1; - move16(); - if ( st->hPFstat != NULL ) - { - /* in case of core switching, reset post-filter memories */ - st->hPFstat->on = 0; - move16(); - } - - if ( st->hGSCDec != NULL ) - { - /* reset the GSC pre echo energy threshold in case of switching */ - st->hGSCDec->Last_frame_ener_fx = MAX_32; - move32(); - } - } - - test(); - if ( st->hGSCDec != NULL && ( st->prev_bfi > 0 ) ) - { - /* reset the GSC pre echo energy threshold in case of FEC */ - st->hGSCDec->Last_frame_ener_fx = MAX_32; - move32(); - } - - test(); - test(); - test(); - test(); - IF( st->hFdCngDec != NULL && ( EQ_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_CPE_TD ) ) && ( EQ_32( st->last_core_brate, SID_2k40 ) || st->last_core_brate == FRAME_NO_DATA ) ) - { - set16_fx( st->hFdCngDec->hFdCngCom->olapBufferSynth2, 0, FFTLEN ); - set16_fx( hStereoCng->olapBufferSynth22_fx, 0, FFTLEN ); - } - - st->clas_dec = st->last_good; - move16(); - enr_q_fx = 0; - move32(); - Es_pred_fx = 0; - move16(); - tmp_noise_fx = 0; - move16(); - Copy( st->old_exc_fx, old_exc_fx, L_EXC_MEM_DEC ); /*Q_exc*/ - exc_fx = old_exc_fx + L_EXC_MEM_DEC; - - IF( st->hWIDec != NULL ) - { - Copy( st->hWIDec->old_exc2_fx, old_exc2_fx, L_EXC_MEM ); - } - ELSE - { - set16_fx( old_exc2_fx, 0, L_EXC_MEM ); - } - exc2_fx = old_exc2_fx + L_EXC_MEM; - - IF( st->hBWE_TD != NULL ) - { - Copy( st->hBWE_TD->old_bwe_exc_fx, old_bwe_exc_fx, PIT16k_MAX * 2 ); /*Q_exc*/ - bwe_exc_fx = old_bwe_exc_fx + PIT16k_MAX * 2; - } - ELSE - { - bwe_exc_fx = NULL; - } - - last_pulse_pos = 0; - move16(); - do_WI = 0; - move16(); - st->GSC_noisy_speech = 0; - move16(); - st->relax_prev_lsf_interp = 0; - move16(); - set16_fx( gain_buf_fx, 0, NB_SUBFR16k ); - - IF( EQ_16( st->L_frame, L_FRAME ) ) - { - st->gamma = GAMMA1; - move16(); - st->inv_gamma = GAMMA1_INV; - move16(); - st->preemph_fac = PREEMPH_FAC; - move16(); - int_fs = INT_FS_12k8; - move16(); - } - ELSE - { - st->gamma = GAMMA16k; - move16(); - st->inv_gamma = GAMMA16k_INV; - move16(); - st->preemph_fac = PREEMPH_FAC_16k; - move16(); - int_fs = INT_FS_16k; - move16(); - } - - test(); - /* reset post-filter in case of switching */ - if ( st->hPFstat != NULL && ( st->hPFstat->on == 0 ) ) - { - st->hPFstat->reset = 1; - move16(); - } - - avoid_lpc_burst_on_recovery = 0; - move16(); - test(); - test(); - if ( st->last_con_tcx && NE_16( st->L_frameTCX_past, st->L_frame ) && ( st->last_core != 0 ) ) - { - avoid_lpc_burst_on_recovery = 1; - move16(); - } - test(); - - /* TD stereo parameters */ - IF( EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( st->idchan, 1 ) ) - { - tdm_lp_reuse_flag = hStereoTD->tdm_lp_reuse_flag; - move16(); - tdm_low_rate_mode = hStereoTD->tdm_low_rate_mode; - move16(); - tdm_Pitch_reuse_flag = hStereoTD->tdm_Pitch_reuse_flag; - move16(); - p_tdm_Pri_pitch_buf_fx = hStereoTD->tdm_Pri_pitch_buf_fx; - } - ELSE - { - tdm_lp_reuse_flag = 0; - move16(); - tdm_low_rate_mode = 0; - move16(); - test(); - if ( EQ_16( st->element_mode, IVAS_SCE ) && st->low_rate_mode ) - { - tdm_low_rate_mode = 1; - move16(); - } - tdm_Pitch_reuse_flag = 0; - move16(); - p_tdm_Pri_pitch_buf_fx = NULL; - } - - /*----------------------------------------------------------------* - * Updates in case of internal sampling rate switching - *----------------------------------------------------------------*/ - - test(); - test(); - IF( NE_16( st->last_L_frame, st->L_frame ) && ( st->last_core == ACELP_CORE || EQ_16( st->last_core, AMR_WB_CORE ) ) ) - { - Word16 dec; - - IF( ( st->hPFstat->on != 0 ) ) - { - Word16 mem_syn_r_size_old, mem_syn_r_size_new; - mem_syn_r_size_old = mult_r( 2048, st->last_L_frame ); /* 1.25/20.f = 2048 (Q15)*/ - mem_syn_r_size_new = mult_r( 2048, st->L_frame ); /* 1.25/20.f = 2048 (Q15)*/ - lerp( st->hPFstat->mem_stp + sub( L_SYN_MEM, mem_syn_r_size_old ), st->hPFstat->mem_stp + sub( L_SYN_MEM, mem_syn_r_size_new ), mem_syn_r_size_new, mem_syn_r_size_old ); - lerp( st->hPFstat->mem_pf_in + sub( L_SYN_MEM, mem_syn_r_size_old ), st->hPFstat->mem_pf_in + sub( L_SYN_MEM, mem_syn_r_size_new ), mem_syn_r_size_new, mem_syn_r_size_old ); - } - - /* convert quantized LSP vector */ - st->rate_switching_reset = lsp_convert_poly_fx( st->lsp_old_fx, st->L_frame, 0 ); - move16(); - - /* convert old quantized LSF vector */ - lsp2lsf_fx( st->lsp_old_fx, st->lsf_old_fx, M, int_fs ); - - /* FEC - update adaptive LSF mean vector */ - Copy( st->lsf_old_fx, st->lsfoldbfi1_fx, M ); /*Qlog2(2.56)*/ - Copy( st->lsf_old_fx, st->lsfoldbfi0_fx, M ); /*Qlog2(2.56)*/ - Copy( st->lsf_old_fx, st->lsf_adaptive_mean_fx, M ); /*Qlog2(2.56)*/ - - /* Reset LPC mem */ - IF( EQ_32( st->sr_core, INT_FS_16k ) ) - { - Copy( GEWB2_Ave_fx, st->mem_AR_fx, M ); /*Qlog2(2.56)*/ - } - ELSE - { - Copy( GEWB_Ave_fx, st->mem_AR_fx, M ); /*Qlog2(2.56)*/ - } - set16_fx( st->mem_MA_fx, 0, M ); - - /* update synthesis filter memories */ - dec = DEC; - move16(); - if ( st->element_mode != EVS_MONO ) - { - dec = DEC_IVAS; - move16(); - } - ivas_synth_mem_updt2_fx( st->L_frame, st->last_L_frame, st->old_exc_fx, st->mem_syn_r, st->mem_syn2_fx, NULL, dec ); - Copy( st->old_exc_fx, old_exc_fx, L_EXC_MEM_DEC ); /*Q_exc*/ - Copy_Scale_sig( st->mem_syn2_fx, st->mem_syn1_fx, M, sub( -1, st->Q_syn ) ); /*Q-1*/ - Copy( st->mem_syn2_fx, st->mem_syn3_fx, M ); /*Q_syn*/ - } - - /* update buffer of old subframe pitch values */ - IF( NE_16( st->last_L_frame, st->L_frame ) ) - { - IF( EQ_16( st->L_frame, L_FRAME ) ) - { - IF( EQ_16( st->last_L_frame, L_FRAME32k ) ) - { - tmpF_fx = 13107; // Q15 - move16(); - } - ELSE IF( EQ_16( st->last_L_frame, 512 ) ) - { - tmpF_fx = 16384; // Q15 - move16(); - } - ELSE /* st->last_L_frame == L_FRAME16k */ - { - tmpF_fx = 26214; // Q15 - move16(); - } - - FOR( i = NB_SUBFR16k - NB_SUBFR; i < NB_SUBFR16k; i++ ) - { - st->old_pitch_buf_fx[i - 1] = Mpy_32_16_1( st->old_pitch_buf_fx[i], tmpF_fx ); // Q16 - move32(); - } - - FOR( i = 2 * NB_SUBFR16k - NB_SUBFR; i < 2 * NB_SUBFR16k; i++ ) - { - st->old_pitch_buf_fx[i - 2] = Mpy_32_16_1( st->old_pitch_buf_fx[i], tmpF_fx ); // Q16 - move32(); - } - } - ELSE - { - exp = 0; - move16(); - IF( EQ_16( st->last_L_frame, L_FRAME32k ) ) - { - tmpF_fx = 16384; // Q15 - move16(); - } - ELSE IF( EQ_16( st->last_L_frame, 512 ) ) - { - tmpF_fx = 20480; // Q15 - move16(); - } - ELSE /* st->last_L_frame == L_FRAME12k8 */ - { - tmpF_fx = 20480; // Q14 - move16(); - exp = 1; - move16(); - } - FOR( i = 2 * NB_SUBFR - 1; i >= NB_SUBFR; i-- ) - { - st->old_pitch_buf_fx[i + 2] = Mpy_32_16_1( L_shl( st->old_pitch_buf_fx[i], exp ), tmpF_fx ); // Q15 - move32(); - } - st->old_pitch_buf_fx[NB_SUBFR + 1] = st->old_pitch_buf_fx[NB_SUBFR + 2]; - move32(); - - FOR( i = NB_SUBFR - 1; i >= 0; i-- ) - { - st->old_pitch_buf_fx[i + 1] = Mpy_32_16_1( L_shl( st->old_pitch_buf_fx[i], exp ), tmpF_fx ); // Q15 - move32(); - } - st->old_pitch_buf_fx[0] = st->old_pitch_buf_fx[1]; - move32(); - } - } - - IF( NE_16( st->bfi_pitch_frame, st->L_frame ) ) - { - IF( EQ_16( st->L_frame, L_FRAME ) ) - { - IF( EQ_16( st->bfi_pitch_frame, L_FRAME32k ) ) - { - tmpF_fx = 13107; // Q15 - move16(); - } - ELSE IF( EQ_16( st->bfi_pitch_frame, 512 ) ) - { - tmpF_fx = 16384; // Q15 - move16(); - } - ELSE /* st->bfi_pitch_frame == L_FRAME16k */ - { - tmpF_fx = 26214; // Q15 - move16(); - } - st->bfi_pitch_fx = mult_r( st->bfi_pitch_fx, tmpF_fx ); - move16(); - st->bfi_pitch_frame = L_FRAME; - move16(); - } - ELSE - { - exp = 0; - move16(); - IF( EQ_16( st->bfi_pitch_frame, L_FRAME32k ) ) - { - tmpF_fx = 16384; // Q15 - move16(); - } - ELSE IF( EQ_16( st->bfi_pitch_frame, 512 ) ) - { - tmpF_fx = 20480; // Q15 - move16(); - } - ELSE /* st->bfi_pitch_frame == L_FRAME12k8 */ - { - tmpF_fx = 20480; // Q14 - move16(); - exp = 1; - move16(); - } - - st->bfi_pitch_fx = mult_r( shl_sat( st->bfi_pitch_fx, exp ), tmpF_fx ); - move16(); - st->bfi_pitch_frame = L_FRAME16k; - move16(); - } - } - - test(); - test(); - if ( EQ_16( st->last_bwidth, NB ) && NE_16( st->bwidth, NB ) && ( st->ini_frame != 0 ) ) - { - st->rate_switching_reset = 1; - move16(); - } - - /*----------------------------------------------------------------------* - * GOOD frame - *----------------------------------------------------------------------*/ - - IF( !st->bfi ) - { - - /*----------------------------------------------------------------* - * Decoding of TC subframe classification - *----------------------------------------------------------------*/ - - tc_subfr = -1; - move16(); - IF( EQ_16( st->coder_type, TRANSITION ) ) - { - tc_subfr = tc_classif_fx( st, st->L_frame ); - } - - /*----------------------------------------------------------------* - * Decoding of GSC IVAS mode - *----------------------------------------------------------------*/ - - test(); - test(); - test(); - test(); - IF( st->element_mode > EVS_MONO && st->idchan == 0 && !( st->core_brate == FRAME_NO_DATA || EQ_32( st->core_brate, SID_2k40 ) ) && !tdm_low_rate_mode ) - { - test(); - test(); - IF( EQ_16( st->coder_type, AUDIO ) || ( EQ_16( st->coder_type, INACTIVE ) && EQ_16( st->inactive_coder_type_flag, 1 ) ) ) - { - st->GSC_IVAS_mode = get_next_indice_fx( st, 2 ); - move16(); - } - } - - /*----------------------------------------------------------------* - * Decoding of inactive CNG frames - *----------------------------------------------------------------*/ - - test(); - IF( st->core_brate == FRAME_NO_DATA || EQ_32( st->core_brate, SID_2k40 ) ) - { - /* decode CNG parameters */ - IF( st->cng_type == LP_CNG ) - { - CNG_dec_fx( st, last_element_mode, Aq_fx, lsp_new_fx, lsf_new_fx, &allow_cn_step, sid_bw, q_env_fx ); - Copy( Aq_fx, st->Aq_cng, add( M, 1 ) ); - - /* comfort noise generation */ - local_element_mode = st->element_mode; - move16(); - - test(); - test(); - if ( ( EQ_16( nchan_out, 1 ) && EQ_16( st->element_mode, IVAS_CPE_DFT ) ) || EQ_16( st->masa_sid_format, 1 ) ) - { - local_element_mode = IVAS_SCE; /* For DFT Stereo mono decoding, run CNG_exc as in SCE */ - move16(); - } - CNG_exc_fx( st->core_brate, st->L_frame, &st->hTdCngDec->Enew_fx, &st->hTdCngDec->cng_seed, exc_fx, exc2_fx, &st->lp_ener_fx, st->last_core_brate, &st->first_CNG, &( st->hTdCngDec->cng_ener_seed ), bwe_exc_fx, allow_cn_step, &st->hTdCngDec->last_allow_cn_step, st->prev_Q_exc, st->Q_exc, st->hTdCngDec->num_ho, q_env_fx, st->hTdCngDec->lp_env_fx, st->hTdCngDec->old_env_fx, st->hTdCngDec->exc_mem_fx, st->hTdCngDec->exc_mem1_fx, sid_bw, &st->hTdCngDec->cng_ener_seed1, exc3_fx, st->Opt_AMR_WB, local_element_mode ); - } - ELSE - { - test(); - IF( EQ_32( st->core_brate, SID_2k40 ) && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) - { - IF( EQ_16( st->element_mode, EVS_MONO ) ) - { - FdCng_decodeSID_fx( st->hFdCngDec->hFdCngCom, st ); - } - ELSE - { - Word16 old_NoiseEstExp = st->hFdCngDec->hFdCngCom->sidNoiseEstExp; - move16(); - - FdCng_decodeSID_ivas_fx( st ); - - Scale_sig32( st->hFdCngDec->hFdCngCom->sidNoiseEstLp, NPART, sub( old_NoiseEstExp, st->hFdCngDec->hFdCngCom->sidNoiseEstExp ) ); - Scale_sig( st->hFdCngDec->hFdCngCom->A_cng, M + 1, sub( norm_s( st->hFdCngDec->hFdCngCom->A_cng[0] ), Q2 ) ); // Qx - } - - *sid_bw = 0; - move16(); - } - - IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) ) - { - assert( nchan_out == 1 ); - - FOR( i = 0; i < NPART; i++ ) - { - st->hFdCngDec->hFdCngCom->sidNoiseEstLp[i] = Madd_32_32( Mpy_32_32( STEREO_DFT_FD_FILT_Q31, st->hFdCngDec->hFdCngCom->sidNoiseEstLp[i] ), - STEREO_DFT_FD_FILT_COMP_Q31, st->hFdCngDec->hFdCngCom->sidNoiseEst[i] ); - move32(); - } - - ApplyFdCng_fx( psyn_fx, st->Q_syn, NULL, 0, realBuffer_fx, imagBuffer_fx, NULL, st, 0, ( st->coder_type == AUDIO && !st->GSC_noisy_speech ) ); - - Word16 new_sidNoiseEstExp = 31 - Q4; - move16(); - Scale_sig32( st->hFdCngDec->hFdCngCom->sidNoiseEstLp, NPART, sub( st->hFdCngDec->hFdCngCom->sidNoiseEstExp, new_sidNoiseEstExp ) ); // Q(31-sidNoiseEstExp) - Scale_sig32( st->hFdCngDec->hFdCngCom->sidNoiseEst, NPART, sub( st->hFdCngDec->hFdCngCom->sidNoiseEstExp, new_sidNoiseEstExp ) ); // Q(31-sidNoiseEstExp) - st->hFdCngDec->hFdCngCom->sidNoiseEstExp = new_sidNoiseEstExp; - move16(); - Word16 new_cngNoiseLevelExp = 31 - Q4; - move16(); - Scale_sig32( st->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, sub( st->hFdCngDec->hFdCngCom->cngNoiseLevelExp, new_cngNoiseLevelExp ) ); // Q(31-cngNoiseLevelExp) - st->hFdCngDec->hFdCngCom->cngNoiseLevelExp = new_cngNoiseLevelExp; - move16(); - - test(); - ApplyFdCng_fx( psyn_fx, st->Q_syn, NULL, 0, realBuffer_fx, imagBuffer_fx, NULL, st, 0, ( EQ_16( st->coder_type, AUDIO ) && !st->GSC_noisy_speech ) ); - - IF( st->hFdCngDec->hFdCngCom->cngNoiseLevelExp < 0 ) - { - Scale_sig32( st->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, st->hFdCngDec->hFdCngCom->cngNoiseLevelExp ); // Q(31-cngNoiseLevelExp) - st->hFdCngDec->hFdCngCom->cngNoiseLevelExp = 0; - move16(); - } - } - - IF( !read_sid_info ) - { - Word32 noise_lvl_highest_fx; - - noise_lvl_highest_fx = st->hFdCngDec->hFdCngCom->cngNoiseLevel[( st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand ) - 1]; - move32(); - - FOR( Word16 b = ( st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand ); b < st->hFdCngDec->hFdCngCom->stopBand; b++ ) - { - st->hFdCngDec->hFdCngCom->cngNoiseLevel[b] = noise_lvl_highest_fx; - move32(); - } - } - - IF( EQ_16( st->element_mode, EVS_MONO ) ) - { - generate_comfort_noise_dec_fx( NULL, NULL, NULL, st, &( st->Q_exc ), 2, -1 ); - } - ELSE - { - generate_comfort_noise_dec_ivas_fx( NULL, NULL, NULL, st, &( st->Q_exc ), 1, nchan_out ); - } - - FdCng_exc( st->hFdCngDec->hFdCngCom, &st->CNG_mode, st->L_frame, st->lsp_old_fx, st->first_CNG, st->lspCNG_fx, Aq_fx, lsp_new_fx, lsf_new_fx, exc_fx, exc2_fx, bwe_exc_fx ); - - Copy( exc2_fx, exc3_fx, st->L_frame ); - } - - Word16 delta_mem_scale = 3; - move16(); - test(); - if ( LT_32( st->lp_ener_fx, 40 ) && st->cng_type == LP_CNG ) /* very low energy frames, less than 0.3125 */ - { - delta_mem_scale = 0; - move16(); - } - i = st->Q_exc; - move16(); - - test(); - IF( st->hMusicPF && st->hGSCDec ) - { - IF( EQ_16( st->element_mode, EVS_MONO ) ) - { - // VE: TBV: should 'st_fx->L_frame * HIBND_ACB_L_FAC' be corrected in EVS? - Rescale_exc( st->hMusicPF->dct_post_old_exc_fx, exc_fx, bwe_exc_fx, st->hGSCDec->last_exc_dct_in_fx, st->L_frame, - st->L_frame * HIBND_ACB_L_FAC, 0, &( st->Q_exc ), st->Q_subfr, NULL, 0, INACTIVE ); - } - ELSE - { - Rescale_exc( st->hMusicPF->dct_post_old_exc_fx, exc_fx, bwe_exc_fx, st->hGSCDec->last_exc_dct_in_fx, st->L_frame, - L_FRAME32k, 0, &( st->Q_exc ), st->Q_subfr, NULL, 0, INACTIVE ); - } - } - - IF( st->hPFstat != NULL ) - { - Rescale_mem( st->Q_exc, &st->prev_Q_syn, &st->Q_syn, st->mem_syn2_fx, st->mem_syn_clas_estim_fx, delta_mem_scale, - &st->mem_deemph_fx, st->hBPF->pst_old_syn_fx, &st->hBPF->pst_mem_deemp_err_fx, &st->agc_mem_fx[1], st->hPFstat, 0, 0, NULL ); - } - ELSE - { - Rescale_mem( st->Q_exc, &st->prev_Q_syn, &st->Q_syn, st->mem_syn2_fx, st->mem_syn_clas_estim_fx, delta_mem_scale, - &st->mem_deemph_fx, NULL, NULL, &st->agc_mem_fx[1], NULL, 0, 0, NULL ); - } - - Copy_Scale_sig( exc2_fx, exc2_fx, st->L_frame, sub( st->Q_exc, i ) ); // Q_exc - - /* update past excitation signals for LD music post-filter */ - IF( st->hMusicPF != NULL ) - { - Copy( st->hMusicPF->dct_post_old_exc_fx + L_FRAME, st->hMusicPF->dct_post_old_exc_fx, DCT_L_POST - L_FRAME - OFFSET2 ); - Copy( exc2_fx, st->hMusicPF->dct_post_old_exc_fx + ( DCT_L_POST - L_FRAME - OFFSET2 ), L_FRAME ); - - /* Update music post processing values */ - /* Filter energies update */ - IF( EQ_16( st->element_mode, EVS_MONO ) ) - { - FOR( i = 0; i < DCT_L_POST; i++ ) - { - st->hMusicPF->filt_lfE_fx[i] = round_fx( L_mac( ( 1228 << ( 16 ) ), 22938, st->hMusicPF->filt_lfE_fx[i] ) ); - move16(); - } - } - ELSE - { - FOR( i = 0; i < DCT_L_POST; i++ ) - { - st->hMusicPF->filt_lfE_fx[i] = add( 9830, mult_r( 22937, st->hMusicPF->filt_lfE_fx[i] ) ); // Q15, 9830 =.3f in Q15, 22937=.7f in Q15 - move16(); - } - } - } - - /* synthesis at 12.8kHz sampling rate */ - move16(); - syn_12k8_fx( st->L_frame, Aq_fx, exc2_fx, psyn_fx, st->mem_syn2_fx, 1, st->Q_exc, st->Q_syn ); - syn_12k8_fx( st->L_frame, Aq_fx, exc3_fx, syn1_fx, st->mem_syn3_fx, 1, st->Q_exc, st->Q_syn ); - - /* reset the decoder */ - CNG_reset_dec_fx( st, pitch_buf_fx, voice_factors_fx ); - - IF( EQ_16( st->element_mode, EVS_MONO ) ) - { - /* update st_fx->mem_syn1 for ACELP core switching */ - Copy( st->mem_syn3_fx, st->mem_syn1_fx, M ); - } - ELSE - { - st->Q_syn_cng = st->Q_syn; - move16(); - st->Q_exc_cng = st->Q_exc; - move16(); - - /* update st->mem_syn1 for ACELP core switching */ - Copy_Scale_sig( st->mem_syn3_fx, st->mem_syn1_fx, M, sub( -1, st->Q_syn ) ); // Q(-1) - } - - /* update old synthesis for classification */ - Copy( syn1_fx + st->L_frame - L_SYN_MEM_CLAS_ESTIM, st->mem_syn_clas_estim_fx, L_SYN_MEM_CLAS_ESTIM ); - - /* save and delay synthesis to be used by SWB BWE */ - Copy_Scale_sig( syn1_fx, temp_buf_fx, st->L_frame, sub( -1, st->Q_syn ) ); // Q_syn -> Q(-1) - IF( st->hBWE_FD != NULL ) - { - save_old_syn_fx( st->L_frame, temp_buf_fx, old_syn_12k8_16k_fx, st->hBWE_FD->old_syn_12k8_16k_fx, st->preemph_fac, &st->hBWE_FD->mem_deemph_old_syn_fx ); - } - } - - /*----------------------------------------------------------------* - * Decoding of all other frames - *----------------------------------------------------------------*/ - - ELSE - { - - /*-----------------------------------------------------------------* - * Configure ACELP bit allocation - *-----------------------------------------------------------------*/ - - nb_bits = 0; - move16(); - st->acelp_cfg.FEC_mode = 0; - move16(); - uc_two_stage_flag = 0; - move16(); - - test(); - IF( !st->nelp_mode_dec && !st->ppp_mode_dec ) - { - Word16 tc_subfr_tmp; - - tc_subfr_tmp = tc_subfr; - move16(); - if ( LT_16( tc_subfr_tmp, L_SUBFR ) ) - { - tc_subfr_tmp = 0; - move16(); - } - - if ( EQ_16( tc_subfr, TC_0_192 ) ) - { - nb_bits = -1; - move16(); - } - - config_acelp1_fx( DEC, st->total_brate, st->core_brate, st->core, st->extl_orig, st->extl_brate_orig, st->L_frame, st->GSC_noisy_speech, &( st->acelp_cfg ), st->next_bit_pos, st->coder_type, st->inactive_coder_type_flag, tc_subfr_tmp, 1, &nb_bits, unbits, st->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st->idchan, st->active_cnt, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); - - test(); - test(); - IF( EQ_16( st->coder_type, TRANSITION ) && LT_16( tc_subfr, L_SUBFR ) && EQ_16( st->L_frame, L_FRAME ) ) - { - config_acelp1_fx( DEC, st->total_brate, st->core_brate, st->core, st->extl_orig, st->extl_brate_orig, st->L_frame, -1, &( st->acelp_cfg ), st->next_bit_pos, TRANSITION, -1, tc_subfr, 2, &nb_bits, unbits, st->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st->idchan, st->active_cnt, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); - } - } - - /*-----------------------------------------------------------------* - * After CNG period, use the most up-to-date LSPs - *-----------------------------------------------------------------*/ - - test(); - test(); - IF( st->hTdCngDec != NULL && ( st->last_core_brate == FRAME_NO_DATA || EQ_32( st->last_core_brate, SID_2k40 ) ) ) - { - Copy( st->lspCNG_fx, st->lsp_old_fx, M ); /*Q15*/ - lsp2lsf_fx( st->lspCNG_fx, st->lsf_old_fx, M, int_fs ); - } - - /*-----------------------------------------------------------------* - * Reset higher ACELP pre-quantizer in case of switching - *-----------------------------------------------------------------*/ - - IF( !st->use_acelp_preq ) - { - st->mem_preemp_preQ_fx = 0; - move16(); - st->last_nq_preQ = 0; - move16(); - st->last_code_preq = 0; - move16(); - } - - st->use_acelp_preq = 0; - move16(); - - /*-----------------------------------------------------------------* - * LSF de-quantization and interpolation - *-----------------------------------------------------------------*/ - - IF( !tdm_lp_reuse_flag ) - { - lsf_dec_fx( st, tc_subfr, Aq_fx, &LSF_Q_prediction, lsf_new_fx, lsp_new_fx, lsp_mid_fx, tdm_low_rate_mode, tdm_lsfQ_PCh_fx ); - } - ELSE - { - const Word16 *pt_interp_2_fx; - - IF( NE_16( st->active_cnt, 1 ) ) - { - Word16 beta_index; - - beta_index = get_next_indice_fx( st, TDM_IC_LSF_PRED_BITS ); - tdm_SCh_lsf_reuse_fx( DEC, st->element_brate, lsf_new_fx, lsp_new_fx, tdm_lsfQ_PCh_fx, NULL, &beta_index ); - } - ELSE - { - Copy( tdm_lspQ_PCh_fx, lsp_new_fx, M ); - Copy( tdm_lsfQ_PCh_fx, lsf_new_fx, M ); - } - - IF( st->rate_switching_reset ) - { - /* extrapolation in case of unstable LSF convert */ - Copy( lsp_new_fx, st->lsp_old_fx, M ); - Copy( lsf_new_fx, st->lsf_old_fx, M ); - } - - pt_interp_2_fx = interpol_frac_fx; - test(); - if ( EQ_16( tdm_low_rate_mode, 1 ) && GT_16( st->coder_type, UNVOICED ) ) - { - pt_interp_2_fx = interpol_frac2_fx; - } - - IF( EQ_16( st->active_cnt, 1 ) ) - { - Copy( lsp_new_fx, st->lsp_old_fx, M ); - lsp2lsf_fx( lsp_new_fx, st->lsf_old_fx, M, st->sr_core ); - } - - /* LSP interpolation and conversion of LSPs to A(z) */ - int_lsp_fx( st->L_frame, st->lsp_old_fx, lsp_new_fx, Aq_fx, M, pt_interp_2_fx, 0 ); - - /* Check LSF stability (distance between old LSFs and current LSFs) */ - st->stab_fac_fx = lsf_stab_ivas_fx( lsf_new_fx, st->lsf_old_fx, 0, st->L_frame ); - move16(); - } - - test(); - IF( EQ_16( st->last_core, HQ_CORE ) && st->element_mode > EVS_MONO ) - { - /* Prepare ACB memory from last HQ frame */ - old_exc_s_fx = st->old_exc_fx + sub( L_EXC_MEM_DEC, st->L_frame ); - tmpF_fx = *old_exc_s_fx; - st->mem_deemph_fx = shl_sat( old_exc_s_fx[st->L_frame - 1], st->Q_syn ); /* Q0 -> Q_syn */ - move16(); - PREEMPH_FX( old_exc_s_fx, st->preemph_fac, L_FRAME16k, &tmpF_fx ); - Copy( old_exc_s_fx + sub( st->L_frame, M ), st->mem_syn2_fx, M ); - Scale_sig( st->mem_syn2_fx, M, st->Q_syn ); /* Q0 -> Q_syn */ - Residu3_fx( Aq_fx, old_exc_s_fx, old_exc_fx + sub( L_EXC_MEM_DEC, st->L_frame ), st->L_frame, 0 ); - Scale_sig( old_exc_fx + sub( L_EXC_MEM_DEC, st->L_frame ), st->L_frame, st->Q_exc ); /* Q0 -> Q_exc */ - } - - test(); - IF( st->last_core != ACELP_CORE && st->element_mode > EVS_MONO ) - { - /* Prepare ACB memory of old_bwe_exc */ - IF( EQ_16( st->L_frame, L_FRAME ) ) - { - lerp( old_exc_fx, old_bwe_exc_fx, L_EXC_MEM_DEC * HIBND_ACB_L_FAC, L_EXC_MEM_DEC ); - } - ELSE - { - lerp( old_exc_fx, old_bwe_exc_fx, L_EXC_MEM_DEC << 1, L_EXC_MEM_DEC ); - } - } - - /*-----------------------------------------------------------------* - * FEC - first good frame after lost frame(s) (possibility to correct the ACB) - *-----------------------------------------------------------------*/ - - IF( st->acelp_cfg.FEC_mode > 0 ) - { - last_pulse_pos = 0; - move16(); - - /* decode the last glottal pulse position */ - T0_tmp = FEC_pos_dec_fx( st, &last_pulse_pos, &enr_q_fx, nb_bits ); - - test(); - test(); - IF( NE_16( st->last_core, HQ_CORE ) || ( EQ_16( st->last_core, HQ_CORE ) && st->last_con_tcx ) ) - { - test(); - test(); - test(); - test(); - test(); - test(); - IF( EQ_16( st->clas_dec, SIN_ONSET ) && last_pulse_pos != 0 && EQ_16( st->prev_bfi, 1 ) ) - { - FEC_SinOnset_fx( old_exc_fx + L_EXC_MEM_DEC - L_EXC_MEM, last_pulse_pos, T0_tmp, enr_q_fx, Aq_fx, st->L_frame, st->Q_exc ); - } - ELSE IF( ( EQ_16( st->coder_type, GENERIC ) || EQ_16( st->coder_type, VOICED ) ) && last_pulse_pos != 0 && EQ_16( st->old_bfi_cnt, 1 ) && st->hWIDec != NULL ) - { - do_WI = FEC_enhACB_fx( st->L_frame, st->last_L_frame, old_exc_fx + L_EXC_MEM_DEC - L_EXC_MEM, T0_tmp, last_pulse_pos, st->bfi_pitch_fx ); - } - } - } - - /*------------------------------------------------------------* - * In case of first frame after an erasure and transition from voiced to unvoiced or inactive - * redo the LPC interpolation - *------------------------------------------------------------*/ - - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( st->stab_fac_fx == 0 ) && ( st->old_bfi_cnt > 0 ) && NE_16( st->clas_dec, VOICED_CLAS ) && NE_16( st->clas_dec, ONSET ) && ( st->relax_prev_lsf_interp == 0 ) && !( EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( st->idchan, 1 ) ) ) - { - int_lsp4_ivas_fx( st->L_frame, st->lsp_old_fx, lsp_mid_fx, lsp_new_fx, Aq_fx, M, 2 ); - } - - /*---------------------------------------------------------------* - * Decoding of the scaled predicted innovation energy - *---------------------------------------------------------------*/ - - IF( nb_bits > 0 ) - { - indice = get_next_indice_fx( st, nb_bits ); - Es_pred_dec_fx( &Es_pred_fx, indice, nb_bits, uc_two_stage_flag ); - } - - /*------------------------------------------------------------* - * Decode excitation according to coding type - *------------------------------------------------------------*/ - - test(); - test(); - IF( tdm_low_rate_mode ) /* tdm stereo low rate mode */ - { - IF( LE_16( st->coder_type, UNVOICED ) ) - { - tdm_low_rate_dec_fx( st, dct_exc_tmp_fx /*, &tmp_noise*/, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, lsf_new_fx ); - tmp_noise_fx = shr_r( st->lp_gainc_fx, 3 ); /*Q0*/ - } - ELSE /* GENERIC */ - { - decod_gen_2sbfr_fx( st, sharpFlag, Aq_fx, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, gain_buf_fx, tdm_Pitch_reuse_flag, p_tdm_Pri_pitch_buf_fx ); - - IF( EQ_16( st->element_mode, IVAS_CPE_TD ) ) - { - tmp_noise_fx = shr_r( st->lp_gainc_fx, 3 ); /*Q0*/ - } - } - } - ELSE IF( st->nelp_mode_dec ) - { - Scale_sig( exc_fx - L_EXC_MEM, L_EXC_MEM, negate( st->Q_exc ) ); // Q0 - st->Q_exc = 0; - move16(); - - /* SC-VBR - NELP frames */ - decod_nelp_fx( st, &tmp_noise_fx, pitch_buf_fx, exc_fx, exc2_fx, voice_factors_fx, bwe_exc_fx, &st->Q_exc, st->bfi, gain_buf_fx ); - - Rescale_exc( st->hMusicPF->dct_post_old_exc_fx, exc_fx, NULL, st->hGSCDec->last_exc_dct_in_fx, L_FRAME, 0, (Word32) 0, &( st->Q_exc ), st->Q_subfr, exc2_fx, L_FRAME, st->coder_type ); - } - ELSE IF( EQ_16( st->coder_type, UNVOICED ) ) - { - /* UNVOICED frames */ - decod_unvoiced_fx( st, Aq_fx, Es_pred_fx, uc_two_stage_flag, st->coder_type, &tmp_noise_fx, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, gain_buf_fx ); - - tmp_noise_fx = shr_r( st->lp_gainc_fx, 3 ); /*Q0*/ - } - ELSE IF( st->ppp_mode_dec ) - { - Scale_sig( exc_fx - L_EXC_MEM, L_EXC_MEM, negate( st->Q_exc ) ); // Q0 - st->Q_exc = 0; - move16(); - - /* SC-VBR - PPP frames */ - IF( NE_32( ( error = decod_ppp_fx( st, Aq_fx, pitch_buf_fx, exc_fx, exc2_fx, st->bfi, gain_buf_fx, voice_factors_fx, bwe_exc_fx ) ), IVAS_ERR_OK ) ) - { - return error; - } - - Rescale_exc( st->hMusicPF->dct_post_old_exc_fx, exc_fx, NULL, st->hGSCDec->last_exc_dct_in_fx, L_FRAME, 0, (Word32) 0, &( st->Q_exc ), st->Q_subfr, exc2_fx, L_FRAME, st->coder_type ); - } - ELSE IF( EQ_16( st->coder_type, TRANSITION ) ) - { - decod_tran_fx( st, st->L_frame, tc_subfr, Aq_fx, Es_pred_fx, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, unbits, sharpFlag, gain_buf_fx ); - } - ELSE IF( EQ_16( st->coder_type, AUDIO ) || ( ( st->coder_type == INACTIVE ) && st->inactive_coder_type_flag ) ) - { - /* AUDIO and INACTIVE frames (coded by GSC technology) */ - decod_audio_fx( st, dct_exc_tmp_fx, Aq_fx, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, lsf_new_fx, gain_buf_fx, - tdm_lp_reuse_flag, tdm_low_rate_mode, tdm_Pitch_reuse_flag, p_tdm_Pri_pitch_buf_fx ); - - tmp_noise_fx = shr_r( st->lp_gainc_fx, 3 ); /*Q0*/ - } - ELSE - { - /* GENERIC, VOICED and INACTIVE frames (coded by AVQ technology) */ - IF( NE_32( ( error = decod_gen_voic_fx( st, st->L_frame, sharpFlag, Aq_fx, Es_pred_fx, do_WI, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, unbits, gain_buf_fx, tdm_Pitch_reuse_flag, p_tdm_Pri_pitch_buf_fx ) ), IVAS_ERR_OK ) ) - { - return error; - } - - IF( EQ_16( st->element_mode, IVAS_CPE_TD ) ) - { - tmp_noise_fx = shr_r( st->lp_gainc_fx, 3 ); /*Q0*/ - } - } - - /* synthesis for ACELP core switching and SWB BWE */ - syn_12k8_fx( st->L_frame, Aq_fx, exc_fx, temp_buf_fx, st->mem_syn1_fx, 1, st->Q_exc, -1 ); - - /* save and delay synthesis to be used by SWB BWE */ - IF( st->hBWE_FD != NULL ) - { - save_old_syn_fx( st->L_frame, temp_buf_fx, old_syn_12k8_16k_fx, st->hBWE_FD->old_syn_12k8_16k_fx, st->preemph_fac, &st->hBWE_FD->mem_deemph_old_syn_fx ); - } - - /*-----------------------------------------------------------------* - * Apply energy matching when switching to inactive frames - *-----------------------------------------------------------------*/ - - Inac_switch_ematch_fx( exc2_fx, dct_exc_tmp_fx, st->hGSCDec->lt_ener_per_band_fx, st->coder_type, st->inactive_coder_type_flag, st->L_frame, st->Q_exc, st->bfi, st->last_core, st->last_codec_mode, tdm_low_rate_mode, st->element_mode ); - - /*------------------------------------------------------------* - * Decode information and modify the excitation signal of stationary unvoiced frames - *------------------------------------------------------------*/ - - test(); - test(); - test(); - test(); - IF( !( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) ) && NE_16( st->nelp_mode_dec, 1 ) && !( EQ_16( st->element_mode, IVAS_SCE ) && tdm_low_rate_mode ) ) - { - stat_noise_uv_dec_fx( st, lsp_new_fx, lsp_mid_fx, Aq_fx, exc2_fx, uc_two_stage_flag ); - } - - /*------------------------------------------------------------* - * Save filter memory in case the synthesis is redone after scaling - * Synthesis at 12k8 Hz sampling rate - *------------------------------------------------------------*/ - - /* update past excitation signals for LD music post-filter */ - IF( st->hMusicPF != NULL ) - { - Copy( st->hMusicPF->dct_post_old_exc_fx + L_FRAME, st->hMusicPF->dct_post_old_exc_fx, DCT_L_POST - L_FRAME - OFFSET2 ); - Copy( exc2_fx, st->hMusicPF->dct_post_old_exc_fx + ( DCT_L_POST - L_FRAME - OFFSET2 ), L_FRAME ); - Copy( st->hMusicPF->dct_post_old_exc_fx, exc_buffer_fx, DCT_L_POST - OFFSET2 ); - } - - test(); - test(); - test(); - IF( ( EQ_16( st->coder_type, AUDIO ) && !st->GSC_noisy_speech ) || ( GE_16( st->GSC_IVAS_mode, 1 ) && EQ_16( st->L_frame, L_FRAME ) ) ) - { - Word16 last_coder_type = st->last_coder_type; - move16(); - - test(); - test(); - test(); - if ( ( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) ) || ( GE_16( st->GSC_IVAS_mode, 1 ) && ( st->GSC_noisy_speech == 0 ) ) ) - { - last_coder_type = AUDIO; - move16(); - } - - Word16 qdct = 0; - move16(); - - /* Extrapolation of the last future part, windowing and high resolution DCT transform */ - IF( EQ_16( st->element_mode, EVS_MONO ) ) - { - // VE: TBV: this is likely a bug in EVS - 'st->last_coder_type' should be replaced by 'st->core_brate' - Prep_music_postP_fx( exc_buffer_fx, dct_buffer_fx, st->hMusicPF->filt_lfE_fx, st->last_coder_type, st->element_mode, pitch_buf_fx, - st->hMusicPF->LDm_enh_lp_gbin_fx, st->Q_exc, &qdct ); - } - ELSE - { - Prep_music_postP_fx( exc_buffer_fx, dct_buffer_fx, st->hMusicPF->filt_lfE_fx, st->last_core, st->element_mode, pitch_buf_fx, st->hMusicPF->LDm_enh_lp_gbin_fx, st->Q_exc, &qdct ); - } - - /* LD music post-filter */ - LD_music_post_filter_fx( st->hMusicPF, dct_buffer_fx, dct_buffer_fx, st->core_brate, &st->hMusicPF->Old_ener_Q, AUDIO, last_coder_type, qdct ); - - /* Inverse DCT transform, retrieval of the aligned excitation, re-synthesis */ - IF( NE_16( st->element_mode, EVS_MONO ) ) // VE: TBC whether needed in IVAS - { - Copy( st->mem_syn2_fx, mem_tmp_fx, M ); /*Q_syn*/ - } - - Post_music_postP_fx( dct_buffer_fx, exc2_fx, st->mem_syn2_fx, st->mem_syn2_fx, Aq_fx, psyn_fx, &st->Q_exc, &st->prev_Q_syn, - &st->Q_syn, st->mem_syn_clas_estim_fx, 0, &st->mem_deemph_fx, st->hBPF->pst_old_syn_fx, - &st->hBPF->pst_mem_deemp_err_fx, &st->agc_mem_fx[1], st->hPFstat, temp_buf_fx, mem_tmp_fx ); - } - ELSE - { - /* Core synthesis at 12.8kHz or 16kHz */ - i = 1; - move16(); - test(); - if ( st->coder_type == INACTIVE && st->element_mode == EVS_MONO ) - { - i = 0; - move16(); - } - - /* add extra headroom in case a CNA addition is likely (i.e. st_fx->psf_lp_noise_fx is close to the threshold) */ - Word16 k = 0; - move16(); - test(); - test(); - if ( st->coder_type == INACTIVE && st->flag_cna && GE_16( round_fx( L_shl( st->lp_noise, 1 ) ), 15 << 7 ) ) - { - k = 1; - move16(); - } - - Rescale_mem( st->Q_exc, &st->prev_Q_syn, &st->Q_syn, st->mem_syn2_fx, st->mem_syn_clas_estim_fx, 4, &st->mem_deemph_fx, - st->hBPF->pst_old_syn_fx, &st->hBPF->pst_mem_deemp_err_fx, &st->agc_mem_fx[1], st->hPFstat, i, k, temp_buf_fx ); - - Copy( st->mem_syn2_fx, mem_tmp_fx, M ); /*Q_syn*/ - syn_12k8_fx( st->L_frame, Aq_fx, exc2_fx, psyn_fx, st->mem_syn2_fx, 1, st->Q_exc, st->Q_syn ); - - IF( st->hMusicPF != NULL ) - { - FOR( i = 0; i < DCT_L_POST; i++ ) - { - st->hMusicPF->filt_lfE_fx[i] = round_fx( L_mac( ( 1228 << ( 16 ) ), 22938, st->hMusicPF->filt_lfE_fx[i] ) ); - move16(); - } - } - } - - /*------------------------------------------------------------* - * FEC - Estimate the classification information - *------------------------------------------------------------*/ - - FEC_clas_estim_fx( st, st->Opt_AMR_WB, st->L_frame, &st->clas_dec, st->coder_type, pitch_buf_fx, psyn_fx, &st->lp_ener_FER_fx, &st->decision_hyst, - NULL, NULL, NULL, NULL, 0, NULL, st->Q_syn, temp_buf_fx, st->mem_syn_clas_estim_fx, &st->classifier_Q_mem_syn, 0, 0, 0, st->last_core_brate, st->acelp_cfg.FEC_mode ); - - /*------------------------------------------------------------* - * FEC - Estimate pitch - *------------------------------------------------------------*/ - - FEC_pitch_estim_fx( st->Opt_AMR_WB, st->last_core, st->L_frame, st->clas_dec, st->last_good, pitch_buf_fx, st->old_pitch_buf_fx, - &st->bfi_pitch_fx, &st->bfi_pitch_frame, &st->upd_cnt, st->coder_type, st->element_mode ); - - /*------------------------------------------------------------* - * FEC - Smooth the speech energy evolution when recovering after a BAD frame - * (smoothing is performed in the excitation domain and signal is resynthesized after) - *------------------------------------------------------------*/ - - Copy_Scale_sig( pitch_buf_fx, pitch_buf_tmp, st->nb_subfr, -Q6 ); // Q0 - - FEC_scale_syn_fx( st->L_frame, &update_flg, st->clas_dec, st->last_good, psyn_fx, pitch_buf_tmp, st->enr_old_fx, enr_q_fx, st->coder_type, LSF_Q_prediction, - &st->scaling_flag, &st->lp_ener_FEC_av, &st->lp_ener_FEC_max, st->bfi, st->total_brate, st->prev_bfi, st->last_core_brate, - exc_fx, exc2_fx, Aq_fx, &st->old_enr_LP, mem_tmp_fx, st->mem_syn2_fx, st->Q_exc, st->Q_syn, st->element_mode, avoid_lpc_burst_on_recovery, 0 ); - - test(); - test(); - test(); - test(); - /* estimate the pitch-synchronous speech energy per sample to be used when normal operation recovers */ - IF( ( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) && LE_32( st->total_brate, ACELP_7k20 ) ) || EQ_32( st->total_brate, ACELP_7k20 ) || EQ_32( st->total_brate, ACELP_8k00 ) ) - { - frame_ener_fx( st->L_frame, st->clas_dec, psyn_fx, pitch_buf_tmp[( ( st->L_frame ) >> 6 ) - 1], &st->enr_old_fx, st->L_frame, st->Q_syn, 3, 0 ); - } - } - - } /* End of GOOD FRAME */ - - /*----------------------------------------------------------------* - * BAD frame - *----------------------------------------------------------------*/ - - ELSE - { - /* SC-VBR */ - if ( EQ_16( st->last_nelp_mode_dec, 1 ) ) - { - st->nelp_mode_dec = 1; - move16(); - } - - test(); - test(); - /* long burst frame erasures */ - if ( GT_16( st->nbLostCmpt, 5 ) && GE_16( st->clas_dec, VOICED_CLAS ) && LT_16( st->clas_dec, INACTIVE_CLAS ) ) - { - st->last_good = VOICED_TRANSITION; - move16(); - } - - /* LSF estimation and A(z) calculation */ - lsf_dec_bfi( MODE1, lsf_new_fx, st->lsf_old_fx, st->lsf_adaptive_mean_fx, NULL, st->mem_MA_fx, st->mem_AR_fx, st->stab_fac_fx, st->last_coder_type, st->L_frame, st->last_good, st->nbLostCmpt, 0, NULL, NULL, NULL, st->hGSCDec->Last_GSC_pit_band_idx, st->Opt_AMR_WB, 0, st->bwidth ); - - FEC_lsf2lsp_interp( st, st->L_frame, Aq_fx, lsf_new_fx, lsp_new_fx ); - IF( EQ_16( st->nelp_mode_dec, 1 ) ) - { - /* SC-VBR */ - Scale_sig( exc_fx - L_EXC_MEM, L_EXC_MEM, negate( st->Q_exc ) ); // Q0 - st->Q_exc = 0; - move16(); - - decod_nelp_fx( st, &tmp_noise_fx, pitch_buf_fx, exc_fx, exc2_fx, voice_factors_fx, bwe_exc_fx, &st->Q_exc, st->bfi, gain_buf_fx ); - FEC_pitch_fx = pitch_buf_fx[3]; - move16(); - Rescale_exc( st->hMusicPF->dct_post_old_exc_fx, exc_fx, NULL, st->hGSCDec->last_exc_dct_in_fx, L_FRAME, 0, (Word32) 0, &( st->Q_exc ), st->Q_subfr, exc2_fx, L_FRAME, st->coder_type ); - } - ELSE - { - /* calculation of excitation signal */ - FEC_exc_estim_fx( st, st->L_frame, exc_fx, exc2_fx, dct_exc_tmp_fx, pitch_buf_fx, voice_factors_fx, &FEC_pitch_fx, bwe_exc_fx, lsf_new_fx, &st->Q_exc, &tmp_noise_fx ); - - Rescale_exc( NULL, exc_fx, bwe_exc_fx, st->hGSCDec->last_exc_dct_in_fx, st->L_frame, L_FRAME32k, (Word32) 0, - &( st->Q_exc ), st->Q_subfr, exc2_fx, st->L_frame, st->last_coder_type ); - - tmp_noise_fx = shr_r( st->lp_gainc_fx, 3 ); /*Q0*/ - - /* SC-VBR */ - st->prev_gain_pit_dec_fx = st->lp_gainp_fx; - move16(); - } - - /* synthesis for ACELP core switching and SWB BWE */ - syn_12k8_fx( st->L_frame, Aq_fx, exc_fx, temp_buf_fx, st->mem_syn1_fx, 1, st->Q_exc, -1 ); - - /* save and delay synthesis to be used by SWB BWE */ - IF( st->hBWE_FD != NULL ) - { - save_old_syn_fx( st->L_frame, temp_buf_fx, old_syn_12k8_16k_fx, st->hBWE_FD->old_syn_12k8_16k_fx, st->preemph_fac, &st->hBWE_FD->mem_deemph_old_syn_fx ); - } - - /* Apply energy matching when switching to inactive frames */ - Inac_switch_ematch_fx( exc2_fx, dct_exc_tmp_fx, st->hGSCDec->lt_ener_per_band_fx, st->coder_type, st->inactive_coder_type_flag, st->L_frame, st->Q_exc, st->bfi, st->last_core, st->last_codec_mode, tdm_low_rate_mode, st->element_mode ); - - /* update past excitation signals for LD music post-filter */ - IF( st->hMusicPF != NULL ) - { - Copy( st->hMusicPF->dct_post_old_exc_fx + L_FRAME, st->hMusicPF->dct_post_old_exc_fx, DCT_L_POST - L_FRAME - OFFSET2 ); - Copy( exc2_fx, st->hMusicPF->dct_post_old_exc_fx + ( DCT_L_POST - L_FRAME - OFFSET2 ), L_FRAME ); - - /* Update music post processing values */ - /* Filter energies update */ - FOR( i = 0; i < DCT_L_POST; i++ ) - { - st->hMusicPF->filt_lfE_fx[i] = round_fx( L_mac( 1228 << 16, 22938, st->hMusicPF->filt_lfE_fx[i] ) ); - move16(); - } - - /* Update circular buffer, keep last energy difference unchanged */ - FOR( i = 1; i < MAX_LT; i++ ) - { - st->hMusicPF->LDm_lt_diff_etot_fx[i - 1] = st->hMusicPF->LDm_lt_diff_etot_fx[i]; - move16(); - } - } - - /* synthesis at 12k8 Hz sampling rate */ - /* add extra headroom in case a CNA addition is likely (i.e. st_fx->psf_lp_noise_fx is close to the threshold) */ - Word16 k = 0; - move16(); - test(); - test(); - if ( st->coder_type == INACTIVE && st->flag_cna && GE_16( round_fx( L_shl( st->lp_noise, 1 ) ), 15 << 7 ) ) - { - k = 1; - move16(); - } - - Rescale_mem( st->Q_exc, &st->prev_Q_syn, &st->Q_syn, st->mem_syn2_fx, st->mem_syn_clas_estim_fx, 4, &st->mem_deemph_fx, - st->hBPF->pst_old_syn_fx, &st->hBPF->pst_mem_deemp_err_fx, &st->agc_mem_fx[1], st->hPFstat, 1, k, temp_buf_fx ); - - test(); - IF( EQ_32( st->total_brate, ACELP_7k20 ) || EQ_32( st->total_brate, ACELP_8k00 ) ) - { - Copy( st->mem_syn2_fx, mem_tmp_fx, M ); - } - syn_12k8_fx( st->L_frame, Aq_fx, exc2_fx, psyn_fx, st->mem_syn2_fx, 1, st->Q_exc, st->Q_syn ); - - /* update buffer for classifier */ - IF( st->hWIDec != NULL ) - { - Copy( exc2_fx + sub( st->L_frame, L_EXC_MEM ), st->hWIDec->old_exc2_fx, L_EXC_MEM ); - Copy( psyn_fx + sub( st->L_frame, L_EXC_MEM ), st->hWIDec->old_syn2_fx, L_EXC_MEM ); - } - st->prev_Q_exc_fr = st->Q_exc; - move16(); - st->prev_Q_syn_fr = st->Q_syn; - move16(); - Copy( psyn_fx + sub( st->L_frame, L_SYN_MEM_CLAS_ESTIM ), st->mem_syn_clas_estim_fx, L_SYN_MEM_CLAS_ESTIM ); - - /*------------------------------------------------------------* - * FEC - Smooth the speech energy evolution when recovering after a BAD frame - * (smoothing is performed in the excitation domain and signal is resynthesized after) - *------------------------------------------------------------*/ - - test(); - IF( EQ_32( st->total_brate, ACELP_7k20 ) || EQ_32( st->total_brate, ACELP_8k00 ) ) - { - Copy_Scale_sig( pitch_buf_fx, pitch_buf_tmp, st->nb_subfr, -Q6 ); // Q0 - - FEC_scale_syn_fx( st->L_frame, &update_flg, st->clas_dec, st->last_good, psyn_fx, pitch_buf_tmp, st->enr_old_fx, enr_q_fx, st->coder_type, LSF_Q_prediction, - &st->scaling_flag, &st->lp_ener_FEC_av, &st->lp_ener_FEC_max, st->bfi, st->total_brate, st->prev_bfi, st->last_core_brate, - exc_fx, exc2_fx, Aq_fx, &st->old_enr_LP, mem_tmp_fx, st->mem_syn2_fx, st->Q_exc, st->Q_syn, st->element_mode, avoid_lpc_burst_on_recovery, 0 ); - } - - /* estimate the pitch-synchronous speech energy per sample to be used when normal operation recovers */ - frame_ener_fx( st->L_frame, st->last_good, psyn_fx, shr( add( FEC_pitch_fx, 32 ), 6 ), &st->enr_old_fx, st->L_frame, st->Q_syn, 3, 0 ); - - IF( NE_16( st->nelp_mode_dec, 1 ) ) - { - /* modify the excitation signal of stationary unvoiced frames */ - stat_noise_uv_mod_fx( st->coder_type, 0, st->lsp_old_fx, lsp_new_fx, lsp_new_fx, Aq_fx, exc2_fx, st->Q_exc, 1, &st->ge_sm_fx, - &st->uv_count, &st->act_count, st->lspold_s_fx, &st->noimix_seed, &st->min_alpha_fx, - &st->exc_pe_fx, st->core_brate, st->bwidth, &st->Q_stat_noise, &st->Q_stat_noise_ge ); - } - } - - IF( st->hBWE_TD != NULL ) - { - IF( EQ_16( st->L_frame, L_FRAME ) ) - { - Copy( Aq_fx + 2 * ( M + 1 ), st->hBWE_TD->cur_sub_Aq_fx, ( M + 1 ) ); - } - ELSE - { - Copy( Aq_fx + 3 * ( M + 1 ), st->hBWE_TD->cur_sub_Aq_fx, ( M + 1 ) ); - } - } - - /*--------------------------------------------------------* - * Apply NB postfilter in case of 8kHz output - *--------------------------------------------------------*/ - - test(); - IF( st->last_bwidth == NB && st->hPFstat != NULL ) - { - Copy_Scale_sig( pitch_buf_fx, pitch_buf_tmp, st->nb_subfr, -Q6 ); // Q0 - - IF( st->bwidth == NB ) - { - st->hPFstat->on = 1; - move16(); - nb_post_filt_fx( st->L_frame, st->hPFstat, &st->psf_lp_noise_fx, tmp_noise_fx, psyn_fx, Aq_fx, pitch_buf_tmp, st->coder_type, st->BER_detect, 0 ); - } - ELSE - { - st->hPFstat->on = 0; - move16(); - nb_post_filt_fx( st->L_frame, st->hPFstat, &st->psf_lp_noise_fx, tmp_noise_fx, psyn_fx, Aq_fx, pitch_buf_tmp, AUDIO, st->BER_detect, 0 ); - } - } - ELSE - { - st->psf_lp_noise_fx = round_fx( L_shl( st->lp_noise, 1 ) ); - move16(); - } - - /*------------------------------------------------------------------* - * Perform fixed deemphasis through 1/(1 - g*z^-1) - *-----------------------------------------------------------------*/ - - /* update old synthesis buffer - needed for ACELP internal sampling rate switching */ - Copy( psyn_fx + sub( st->L_frame, L_SYN_MEM ), st->mem_syn_r, L_SYN_MEM ); - deemph_fx( psyn_fx, st->preemph_fac, st->L_frame, &( st->mem_deemph_fx ) ); - unscale_AGC( psyn_fx, st->Q_syn, syn_fx_tmp2, st->agc_mem_fx, st->L_frame ); - Copy( syn_fx_tmp2, psyn_fx, st->L_frame ); - IF( st->hTcxDec != NULL ) - { - Copy_Scale_sig( psyn_fx + shr( st->L_frame, 1 ), st->hTcxDec->old_syn_Overl, shr( st->L_frame, 1 ), sub( -1, st->Q_syn ) ); /*Q-1*/ - st->hTcxDec->Q_old_syn_Overl = -1; - } - Copy_Scale_sig( psyn_fx + sub( st->L_frame, M + 1 ), st->syn, M + 1, sub( 0, st->Q_syn ) ); /*Q0*/ - - /*------------------------------------------------------------------* - * Formant post-filter - *-----------------------------------------------------------------*/ - - test(); - test(); - test(); - test(); - IF( st->hPFstat != NULL && GE_16( st->last_bwidth, WB ) && ( GT_32( st->core_brate, ACELP_24k40 ) || st->element_mode > EVS_MONO ) && LE_32( st->core_brate, ACELP_32k ) ) - { - st->hPFstat->on = 1; - move16(); - Copy( psyn_fx, temp_buf_fx + L_SYN_MEM, L_FRAME16k ); - set16_fx( st->hPFstat->mem_zero, 0, M ); - - formant_post_filt_fx( st->hPFstat, temp_buf_fx + L_SYN_MEM, Aq_fx, psyn_fx, st->L_frame, st->lp_noise, st->total_brate, 0 ); - } - ELSE IF( st->hPFstat != NULL && GE_16( st->last_bwidth, WB ) ) - { - IF( st->hPFstat->on ) - { - Copy( st->hPFstat->mem_pf_in + L_SYN_MEM - M, temp_buf_fx, M ); - Copy( psyn_fx, temp_buf_fx + M, L_SUBFR ); - - Residu3_fx( Aq_fx, temp_buf_fx + M, temp_buf_fx + M + L_SUBFR, L_SUBFR, 1 ); - E_UTIL_synthesis( 1, Aq_fx, temp_buf_fx + M + L_SUBFR, temp_buf_fx, L_SUBFR, st->hPFstat->mem_stp + L_SYN_MEM - M, 0, M ); - scale_st_fx( psyn_fx, temp_buf_fx, &st->hPFstat->gain_prec, L_SUBFR ); - Copy( temp_buf_fx, psyn_fx, ( L_SUBFR >> 1 ) ); - blend_subfr2_fx( temp_buf_fx + L_SUBFR / 2, psyn_fx + L_SUBFR / 2, psyn_fx + L_SUBFR / 2 ); - } - st->hPFstat->on = 0; - move16(); - } - - /*----------------------------------------------------------------* - * Comfort noise addition - *----------------------------------------------------------------*/ - - test(); - test(); - IF( ( st->hFdCngDec != NULL || EQ_16( st->idchan, 1 ) ) && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) - { - test(); - test(); - test(); - test(); - test(); - IF( EQ_16( st->element_mode, IVAS_CPE_TD ) || st->flag_cna || ( EQ_16( st->cng_type, FD_CNG ) && LE_32( st->total_brate, ACELP_32k ) ) || ( st->cng_type == LP_CNG && LE_32( st->core_brate, SID_2k40 ) ) ) - { - /*VAD only for non inactive frame*/ - test(); - st->VAD = st->VAD && st->coder_type != INACTIVE; - move16(); - test(); - test(); - test(); - test(); - test(); - IF( st->idchan == 0 && ( st->flag_cna || ( EQ_16( st->cng_type, FD_CNG ) && LE_32( st->total_brate, ACELP_32k ) ) || ( st->cng_type == LP_CNG && LE_32( st->core_brate, SID_2k40 ) ) ) ) - { - /*Noisy speech detector*/ - noisy_speech_detection_fx( st->hFdCngDec, st->VAD, psyn_fx, st->Q_syn ); - - st->hFdCngDec->hFdCngCom->likelihood_noisy_speech = mult_r( st->hFdCngDec->hFdCngCom->likelihood_noisy_speech, 32440 /*0.99 Q15*/ ); - move16(); - IF( st->hFdCngDec->hFdCngCom->flag_noisy_speech != 0 ) - { - st->hFdCngDec->hFdCngCom->likelihood_noisy_speech = add( st->hFdCngDec->hFdCngCom->likelihood_noisy_speech, 328 /*0.01 Q15*/ ); - move16(); - } - move32(); - } - - if ( st->idchan == 0 ) - { - st->lp_noise = st->hFdCngDec->lp_noise; - move32(); - } - - test(); - IF( NE_16( st->element_mode, IVAS_CPE_TD ) && !st->cng_ism_flag ) - { - /* Noise estimate */ - ApplyFdCng_fx( psyn_fx, st->Q_syn, NULL, 0, realBuffer_fx, imagBuffer_fx, NULL, st, 0, ( st->coder_type == AUDIO && !st->GSC_noisy_speech ) ); - } - - IF( !st->cna_dirac_flag ) - { - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - /* CNA: Generate additional comfort noise to mask potential coding artefacts */ - IF( st->flag_cna && !( EQ_16( st->coder_type, AUDIO ) && !( st->element_mode > EVS_MONO && st->GSC_noisy_speech ) ) ) - { - test(); - IF( EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( nchan_out, 2 ) ) - { - IF( hStereoCng->flag_cna_fade ) - { - generate_stereo_masking_noise_fx( psyn_fx, st->Q_syn, st, hStereoTD, flag_sec_CNA, 1, hStereoCng, nchan_out ); - hStereoCng->flag_cna_fade = 0; - move16(); - } - ELSE - { - test(); - IF( NE_16( st->element_mode, last_element_mode ) && ( st->idchan == 0 ) ) - { - /* Clear memory for secondary channel CNA */ - set16_fx( hStereoCng->olapBufferSynth22_fx, 0, shr( st->hFdCngDec->hFdCngCom->frameSize, 1 ) ); - } - - generate_stereo_masking_noise_fx( psyn_fx, st->Q_syn, st, hStereoTD, flag_sec_CNA, 0, hStereoCng, nchan_out ); - } - } - ELSE IF( NE_16( st->element_mode, IVAS_CPE_DFT ) ) - { - IF( EQ_16( st->element_mode, EVS_MONO ) ) - { - generate_masking_noise_fx( psyn_fx, st->Q_syn, st->hFdCngDec->hFdCngCom, st->hFdCngDec->hFdCngCom->frameSize, 0 ); - } - ELSE - { - IF( st->idchan == 0 ) - { - IF( NE_16( st->element_mode, last_element_mode ) ) - { - set16_fx( st->hFdCngDec->hFdCngCom->olapBufferSynth2, 0, st->hFdCngDec->hFdCngCom->fftlen ); - } - - Word32 psyn_32_fx[L_FRAME16k]; - Copy_Scale_sig_16_32_no_sat( psyn_fx, psyn_32_fx, st->hFdCngDec->hFdCngCom->frameSize, sub( Q6, st->Q_syn ) ); // Q6 - Copy_Scale_sig_16_32_no_sat( st->hFdCngDec->hFdCngCom->olapBufferSynth2, st->hFdCngDec->hFdCngCom->olapBufferSynth2_fx, shl( st->hFdCngDec->hFdCngCom->frameSize, 1 ), Q15 ); // Q15 - - generate_masking_noise_ivas_fx( psyn_32_fx, &exp, st->hFdCngDec->hFdCngCom, st->hFdCngDec->hFdCngCom->frameSize, 0, 0, 0, st->element_mode, hStereoCng, nchan_out ); - - Copy_Scale_sig_32_16( psyn_32_fx, psyn_fx, st->hFdCngDec->hFdCngCom->frameSize, sub( st->Q_syn, exp ) ); // Q = st->Q_syn - Copy_Scale_sig_32_16( st->hFdCngDec->hFdCngCom->olapBufferSynth2_fx, st->hFdCngDec->hFdCngCom->olapBufferSynth2, shl( st->hFdCngDec->hFdCngCom->frameSize, 1 ), -Q15 ); // Q0 - } - } - } - } - ELSE IF( st->flag_cna && EQ_16( st->coder_type, AUDIO ) && ( ( st->last_core == ACELP_CORE && !( EQ_16( st->last_coder_type, AUDIO ) && !( st->element_mode > EVS_MONO && st->Last_GSC_noisy_speech_flag ) ) ) || EQ_16( st->last_core, TCX_20_CORE ) ) ) - { - test(); - IF( EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( nchan_out, 2 ) ) - { - generate_stereo_masking_noise_fx( psyn_fx, st->Q_syn, st, hStereoTD, flag_sec_CNA, 1, hStereoCng, nchan_out ); - hStereoCng->flag_cna_fade = 1; - move16(); - } - ELSE - { - FOR( i = 0; i < ( st->hFdCngDec->hFdCngCom->frameSize ) / 2; i++ ) - { - psyn_fx[i] = add( psyn_fx[i], shr_r( mult_r( st->hFdCngDec->hFdCngCom->olapBufferSynth2[i + 5 * ( st->hFdCngDec->hFdCngCom->frameSize / 4 )], st->hFdCngDec->hFdCngCom->fftlenFac ), negate( st->Q_syn ) ) ); - move16(); - } - } - } - ELSE - { - IF( hStereoCng != NULL ) - { - hStereoCng->flag_cna_fade = 1; - move16(); - hStereoCng->enableSecCNA = 0; - move16(); - } - } - - IF( EQ_16( st->element_mode, IVAS_CPE_TD ) ) - { - test(); - test(); - test(); - /*Noise estimate*/ - IF( ( st->idchan == 0 ) && ( EQ_16( nchan_out, 2 ) || ( st->core_brate != FRAME_NO_DATA && NE_32( st->core_brate, SID_2k40 ) ) ) ) - { - ApplyFdCng_fx( psyn_fx, st->Q_syn, NULL, 0, realBuffer_fx, imagBuffer_fx, NULL, st, 0, ( st->coder_type == AUDIO && !st->GSC_noisy_speech ) ); - } - } - } - } - - IF( !st->cna_dirac_flag ) - { - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( st->flag_cna == 0 ) && EQ_16( st->L_frame, L_FRAME16k ) && EQ_16( st->last_flag_cna, 1 ) && ( ( st->last_core == ACELP_CORE && !( EQ_16( st->last_coder_type, AUDIO ) && !( st->element_mode > EVS_MONO && st->Last_GSC_noisy_speech_flag ) ) ) || EQ_16( st->last_core, AMR_WB_CORE ) ) ) - { - IF( EQ_16( st->element_mode, EVS_MONO ) ) - { - // VE: TBV - is it correct in EVS? in FLP, it is: - // v_multc( st->hFdCngDec->hFdCngCom->olapBufferSynth2 + 5 * st->L_frame / 4, 256.f, temp_buf, st->L_frame / 2 ); - // v_add( temp_buf, syn, syn, st->L_frame / 2 ); - FOR( i = 0; i < st->L_frame / 2; i++ ) - { - psyn_fx[i] = add( psyn_fx[i], shr_r( st->hFdCngDec->hFdCngCom->olapBufferSynth2[i + 5 * st->L_frame / 4], negate( st->Q_syn ) ) ); - move16(); - } - } - ELSE - { - FOR( i = 0; i < ( st->hFdCngDec->hFdCngCom->frameSize ) / 2; i++ ) - { - psyn_fx[i] = add( psyn_fx[i], shr_r( mult_r( st->hFdCngDec->hFdCngCom->olapBufferSynth2[i + 5 * ( st->hFdCngDec->hFdCngCom->frameSize / 4 )], st->hFdCngDec->hFdCngCom->fftlenFac ), -st->Q_syn ) ); - move16(); - } - } - } - - test(); - test(); - test(); - IF( ( st->flag_cna == 0 ) || ( EQ_16( st->coder_type, AUDIO ) && !( st->element_mode > EVS_MONO && st->GSC_noisy_speech ) ) ) - { - IF( st->idchan == 0 ) - { - set16_fx( st->hFdCngDec->hFdCngCom->olapBufferSynth2, 0, st->hFdCngDec->hFdCngCom->fftlen ); - } - IF( hStereoCng != NULL && ( st->idchan == 0 ) ) - { - set16_fx( hStereoCng->olapBufferSynth22_fx, 0, st->hFdCngDec->hFdCngCom->fftlen ); - } - } - } - } - - /*----------------------------------------------------------------* - * Resample to the output sampling rate (8/16/32/48 kHz) - * Bass post-filter - *----------------------------------------------------------------*/ - - IF( EQ_16( st->element_mode, EVS_MONO ) ) - { - CLDFB_SCALE_FACTOR scaleFactor; - Word32 workBuffer[128 * 3]; - - /* check if the CLDFB works on the right sample rate */ - IF( ( st->cldfbAna->usb * st->cldfbAna->no_col ) != st->L_frame ) - { - /* resample to ACELP internal sampling rate */ - Word16 newCldfbBands = CLDFB_getNumChannels( L_mult0( st->L_frame, FRAMES_PER_SEC ) ); - resampleCldfb( st->cldfbAna, newCldfbBands, st->L_frame, 0 ); - resampleCldfb( st->cldfbBPF, newCldfbBands, st->L_frame, 0 ); - - IF( st->ini_frame > 0 ) - { - st->cldfbSyn->bandsToZero = sub( st->cldfbSyn->no_channels, st->cldfbAna->no_channels ); - move16(); - } - } - - test(); - IF( NE_16( st->L_frame, st->last_L_frame ) && NE_16( st->last_codec_mode, MODE2 ) ) - { - IF( EQ_16( st->L_frame, L_FRAME ) ) - { - retro_interp5_4_fx( st->hBPF->pst_old_syn_fx ); - } - ELSE IF( EQ_16( st->L_frame, L_FRAME16k ) ) - { - retro_interp4_5_fx( psyn_fx, st->hBPF->pst_old_syn_fx ); - } - } - - bass_psfilter_fx( st->hBPF, st->Opt_AMR_WB, psyn_fx, st->L_frame, pitch_buf_fx, st->bpf_off, - st->stab_fac_fx, &st->stab_fac_smooth_fx, st->coder_type, st->Q_syn, bpf_error_signal_16fx ); - - /* analysis of the synthesis at internal sampling rate */ - cldfbAnalysis_fx( st->cldfbAna, realBuffer_fx, imagBuffer_fx, &scaleFactor, psyn_fx, negate( st->Q_syn ), CLDFB_NO_COL_MAX, workBuffer ); - - scaleFactor.hb_scale = scaleFactor.lb_scale; - move16(); - - /* analysis and add the BPF error signal */ - i = 0; - move16(); - if ( st->bpf_off == 0 ) - { - i = CLDFB_NO_COL_MAX; - move16(); - } - - addBassPostFilter_fx( bpf_error_signal_16fx, realBuffer_fx, imagBuffer_fx, st->cldfbBPF, workBuffer, negate( st->Q_syn ), - i, st->cldfbAna->no_col, st->cldfbAna->no_channels, &scaleFactor ); - - /* set output mask for upsampling */ - IF( EQ_16( st->bwidth, NB ) ) - { - /* set NB mask for upsampling */ - st->cldfbSyn->bandsToZero = sub( st->cldfbSyn->no_channels, 10 ); - move16(); - } - ELSE IF( NE_16( st->cldfbSyn->bandsToZero, sub( st->cldfbSyn->no_channels, st->cldfbAna->no_channels ) ) ) - { - /* in case of BW switching, re-init to default */ - st->cldfbSyn->bandsToZero = sub( st->cldfbSyn->no_channels, st->cldfbAna->no_channels ); - move16(); - } - - /*WB/SWB-FD_CNG*/ - scaleFactor.hb_scale = scaleFactor.lb_scale; - move16(); - - test(); - test(); - test(); - IF( ( ( st->core_brate == FRAME_NO_DATA ) || EQ_32( st->core_brate, SID_2k40 ) ) && ( EQ_16( st->cng_type, FD_CNG ) ) && ( LT_16( st->hFdCngDec->hFdCngCom->numCoreBands, st->cldfbSyn->no_channels ) ) ) - { - generate_comfort_noise_dec_hf_fx( realBuffer_fx, imagBuffer_fx, &scaleFactor.hb_scale, st ); - - st->cldfbSyn->bandsToZero = 0; - move16(); - IF( LT_16( st->hFdCngDec->hFdCngCom->regularStopBand, st->cldfbSyn->no_channels ) ) - { - st->cldfbSyn->bandsToZero = sub( st->cldfbSyn->no_channels, st->hFdCngDec->hFdCngCom->regularStopBand ); - move16(); - } - st->cldfbSyn->lsb = st->cldfbAna->no_channels; - move16(); - } - - /* synthesis of the combined signal */ - st->Q_syn2 = st->Q_syn; - move16(); - cldfbSynthesis_fx( st->cldfbSyn, realBuffer_fx, imagBuffer_fx, &scaleFactor, synth_fx16, negate( st->Q_syn2 ), CLDFB_NO_COL_MAX, workBuffer ); - - /* Bring CLDFB output to Q0 */ - Scale_sig( synth_fx16, output_frame, negate( st->Q_syn2 ) ); - st->Q_syn2 = 0; - move16(); - - /* save synthesis - needed in case of core switching */ - Copy( synth_fx16, st->previoussynth_fx, output_frame ); - } - ELSE - { - /* check if the CLDFB works on the right sample rate */ - IF( NE_16( imult1616( st->cldfbAna->no_channels, st->cldfbAna->no_col ), st->L_frame ) ) - { - resampleCldfb_ivas_fx( st->cldfbAna, L_mult0( st->L_frame, FRAMES_PER_SEC ) ); - resampleCldfb_ivas_fx( st->cldfbBPF, L_mult0( st->L_frame, FRAMES_PER_SEC ) ); - - IF( st->ini_frame > 0 ) - { - st->cldfbSyn->bandsToZero = sub( st->cldfbSyn->no_channels, st->cldfbAna->no_channels ); - move16(); - } - } - - /* analyze pitch coherence for bass post-filter */ - Word32 pitch_buf_fx_q20[12]; - Scale_sig32( st->old_pitch_buf_fx, 2 * NB_SUBFR16k + 2, Q4 ); // Q(x+4) - Word16 lim = shr( st->L_frame, 6 ); - FOR( Word16 lp = 0; lp < lim; lp++ ) - { - pitch_buf_fx_q20[lp] = L_shl( pitch_buf_fx[lp], Q14 ); - move32(); - } - bpf_pitch_coherence_ivas_fx( st, pitch_buf_fx_q20 ); - Scale_sig32( st->old_pitch_buf_fx, 2 * NB_SUBFR16k + 2, -Q4 ); // Qx - - test(); - IF( !( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && st->bpf_off ) ) - { - test(); - IF( NE_16( st->L_frame, st->last_L_frame ) && NE_16( st->last_codec_mode, MODE2 ) ) - { - IF( EQ_16( st->L_frame, L_FRAME ) ) - { - retro_interp5_4_fx( st->hBPF->pst_old_syn_fx ); - } - ELSE IF( EQ_16( st->L_frame, L_FRAME16k ) ) - { - retro_interp4_5_fx( psyn_fx, st->hBPF->pst_old_syn_fx ); - } - } - - bass_psfilter_fx( st->hBPF, st->Opt_AMR_WB, psyn_fx, st->L_frame, pitch_buf_fx, st->bpf_off, - st->stab_fac_fx, &st->stab_fac_smooth_fx, st->coder_type, st->Q_syn, bpf_error_signal_16fx ); - } - - Word32 syn_tmp_32_fx[L_FRAME16k + L_SUBFR], *syn_32_fx; - set32_fx( syn_tmp_32_fx, 0, L_FRAME16k + L_SUBFR ); - syn_32_fx = syn_tmp_32_fx + L_SUBFR; - test(); - IF( NE_16( st->element_mode, IVAS_CPE_DFT ) || use_cldfb_for_dft ) - { - /* analysis of the synthesis at internal sampling rate */ - Word32 realBufferSave_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; - Word32 imagBufferSave_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; - Word32 *pRealSave_fx[CLDFB_NO_COL_MAX], *pImagSave_fx[CLDFB_NO_COL_MAX]; - FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) - { - pRealSave_fx[i] = realBufferSave_fx[i]; - pImagSave_fx[i] = imagBufferSave_fx[i]; - } - IF( st->p_bpf_noise_buf_32 ) - { - Copy_Scale_sig_16_32_DEPREC( bpf_error_signal_16fx, bpf_error_signal_fx, st->L_frame, -1 ); // Q_syn-1 - Copy32( bpf_error_signal_fx, st->p_bpf_noise_buf_32, st->L_frame ); - Scale_sig32( st->p_bpf_noise_buf_32, st->L_frame, sub( Q11, sub( st->Q_syn, 1 ) ) ); // Q11 - } - - FOR( i = 0; i < st->L_frame; i++ ) - { - syn_32_fx[i] = L_shr( L_deposit_h( psyn_fx[i] ), add( 4, st->Q_syn ) ); // Q12 - move32(); - } - - Word16 offset = sub( st->cldfbAna->p_filter_length, st->cldfbAna->no_channels ); - Scale_sig32( st->cldfbAna->cldfb_state_fx, offset, 1 ); // Q12 - st->cldfbAna->Q_cldfb_state = Q12; - move16(); - - cldfbAnalysis_ivas_fx( syn_32_fx, realBuffer_fx, imagBuffer_fx, -1, st->cldfbAna ); - - Scale_sig32( st->cldfbAna->cldfb_state_fx, offset, -1 ); // Q11 - st->cldfbAna->Q_cldfb_state = Q11; - move16(); - /* analysis and add the BPF error signal */ - Word32 tmp_bpf_error_signal_fx[L_FRAME16k]; - Word16 q_bpf_error_signal; - Word16 cldfb_state_offset = sub( st->cldfbBPF->p_filter_length, st->cldfbBPF->no_channels ); - - q_bpf_error_signal = Q6; - move16(); - Copy_Scale_sig_16_32_no_sat( bpf_error_signal_16fx, tmp_bpf_error_signal_fx, st->L_frame, sub( q_bpf_error_signal, st->Q_syn ) ); // Q6 - FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) - { - Scale_sig32( realBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, -Q7 ); // Q0 - Scale_sig32( imagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, -Q7 ); // Q0 - } - Scale_sig32( st->cldfbBPF->cldfb_state_fx, cldfb_state_offset, sub( q_bpf_error_signal, Q10 ) ); // q_bpf_error_signal (Q6) - st->cldfbBPF->Q_cldfb_state = q_bpf_error_signal; - move16(); - tmp = -1; - move16(); - if ( st->bpf_off ) - { - tmp = 0; - move16(); - } - - addBassPostFilter_ivas_fx( tmp_bpf_error_signal_fx, tmp, realBuffer_fx, imagBuffer_fx, st->cldfbBPF ); - - Scale_sig32( st->cldfbBPF->cldfb_state_fx, cldfb_state_offset, negate( ( sub( q_bpf_error_signal, Q10 ) ) ) ); // Q10 - st->cldfbBPF->Q_cldfb_state = Q10; - move16(); - /* set output mask for upsampling */ - IF( EQ_16( st->bwidth, NB ) ) - { - /* set NB mask for upsampling */ - st->cldfbSyn->bandsToZero = sub( st->cldfbSyn->no_channels, 10 ); - move16(); - } - ELSE IF( NE_16( st->cldfbSyn->bandsToZero, sub( st->cldfbSyn->no_channels, st->cldfbAna->no_channels ) ) ) - { - /* in case of BW switching, re-init to default */ - st->cldfbSyn->bandsToZero = sub( st->cldfbSyn->no_channels, st->cldfbAna->no_channels ); - move16(); - } - test(); - IF( !st->cng_sba_flag || EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) - { - test(); - test(); - test(); - /*WB/SWB-FD_CNG*/ - IF( ( st->core_brate == FRAME_NO_DATA || EQ_32( st->core_brate, SID_2k40 ) ) && ( EQ_16( st->cng_type, FD_CNG ) ) && ( LT_16( st->hFdCngDec->hFdCngCom->numCoreBands, st->cldfbSyn->no_channels ) ) ) - { - Word16 tmpBufferScale = 0; - move16(); - generate_comfort_noise_dec_hf_ivas_fx( realBuffer_fx, imagBuffer_fx, /*realBuffer, imagBuffer,*/ &tmpBufferScale, st->hFdCngDec->hFdCngCom, st->cng_ism_flag ); - - FOR( i = 0; i < st->hFdCngDec->hFdCngCom->numSlots; i++ ) - { - Scale_sig32( realBuffer_fx[i] + st->hFdCngDec->hFdCngCom->numCoreBands, sub( st->hFdCngDec->hFdCngCom->regularStopBand, st->hFdCngDec->hFdCngCom->numCoreBands ), sub( add( tmpBufferScale, 15 ), Q31 ) ); // Q0 - Scale_sig32( imagBuffer_fx[i] + st->hFdCngDec->hFdCngCom->numCoreBands, sub( st->hFdCngDec->hFdCngCom->regularStopBand, st->hFdCngDec->hFdCngCom->numCoreBands ), sub( add( tmpBufferScale, 15 ), Q31 ) ); // Q0 - } - - IF( LT_16( st->hFdCngDec->hFdCngCom->regularStopBand, st->cldfbSyn->no_channels ) ) - { - st->cldfbSyn->bandsToZero = sub( st->cldfbSyn->no_channels, st->hFdCngDec->hFdCngCom->regularStopBand ); - move16(); - } - ELSE - { - st->cldfbSyn->bandsToZero = 0; - move16(); - } - } - } - - IF( save_hb_synth_fx16 != NULL ) - { - /* save and then zero-out lowband */ - max_real = 0; - max_imag = 0; - move32(); - move32(); - FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) - { - FOR( j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) - { - max_real = L_max( max_real, L_abs( realBuffer_fx[i][j] ) ); - max_imag = L_max( max_imag, L_abs( imagBuffer_fx[i][j] ) ); - } - } - max_val = L_max( max_real, max_imag ); - Q_real = sub( norm_l( max_val ), 3 ) /* Guard bits */; - FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) - { - scale_sig32( realBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_real ); // Q_real - scale_sig32( imagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_real ); // Q_real - } -#ifndef OPT_AVOID_STATE_BUF_RESCALE -#ifdef OPT_STEREO_32KBPS_V1 - scale_sig32( st->cldfbSynHB->cldfb_state_fx, st->cldfbSynHB->p_filter_length, sub( Q_real, Q11 ) ); // Q10 - > (Q_real-1) -#else /* OPT_STEREO_32KBPS_V1 */ - scale_sig32_r( st->cldfbSynHB->cldfb_state_fx, st->cldfbSynHB->p_filter_length, sub( sub( Q_real, 1 ), Q10 ) ); // (Q_real-1) -#endif /* OPT_STEREO_32KBPS_V1 */ - st->cldfbSynHB->Q_cldfb_state = sub( Q_real, 1 ); - move16(); -#endif /* OPT_AVOID_STATE_BUF_RESCALE */ - - FOR( j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) - { - FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) - { - realBufferSave_fx[i][j] = realBuffer_fx[i][j]; - imagBufferSave_fx[i][j] = imagBuffer_fx[i][j]; - move32(); - move32(); - IF( LT_16( j, st->hFdCngDec->hFdCngCom->numCoreBands ) && LT_16( i, st->hFdCngDec->hFdCngCom->numSlots ) ) - { - realBuffer_fx[i][j] = 0; - imagBuffer_fx[i][j] = 0; - move32(); - move32(); - } - } - } - -#ifdef OPT_AVOID_STATE_BUF_RESCALE - cldfbSynthesis_ivas_fx( realBuffer_fx, imagBuffer_fx, save_hb_synth_fx, -1, sub( Q11, Q_real ), -10, st->cldfbSynHB ); -#else /* OPT_AVOID_STATE_BUF_RESCALE */ - cldfbSynthesis_ivas_fx( realBuffer_fx, imagBuffer_fx, save_hb_synth_fx, -1, 0, st->cldfbSynHB ); -#endif /* OPT_AVOID_STATE_BUF_RESCALE */ - -#ifndef OPT_AVOID_STATE_BUF_RESCALE - Scale_sig32( save_hb_synth_fx, L_FRAME48k, negate( ( sub( Q_real, 1 ) ) ) ); // Q0 - Scale_sig32( st->cldfbSynHB->cldfb_state_fx, st->cldfbSynHB->p_filter_length, sub( Q10, sub( Q_real, 1 ) ) ); // Q10 - st->cldfbSynHB->Q_cldfb_state = Q10; - move16(); -#endif /* OPT_AVOID_STATE_BUF_RESCALE */ - /* restore lowband */ - FOR( j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) - { - FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) - { - realBuffer_fx[i][j] = realBufferSave_fx[i][j]; - imagBuffer_fx[i][j] = imagBufferSave_fx[i][j]; - move32(); - move32(); - } - } -#ifndef OPT_AVOID_STATE_BUF_RESCALE - Scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( sub( Q_real, 1 ), Q10 ) ); // Q_real-1 - st->cldfbSynHB->Q_cldfb_state = sub( Q_real, 1 ); - move16(); -#endif /* OPT_AVOID_STATE_BUF_RESCALE */ - -#ifdef OPT_AVOID_STATE_BUF_RESCALE - cldfbSynthesis_ivas_fx( pRealSave_fx, pImagSave_fx, synth_fx, -1, sub( Q11, Q_real ), -10, st->cldfbSyn ); -#else /* OPT_AVOID_STATE_BUF_RESCALE */ - cldfbSynthesis_ivas_fx( pRealSave_fx, pImagSave_fx, synth_fx, -1, 0, st->cldfbSyn ); - Scale_sig32( synth_fx, L_FRAME48k, negate( sub( Q_real, 1 ) ) ); // Q0 - Scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( Q10, sub( Q_real, 1 ) ) ); // Q10 - st->cldfbSynHB->Q_cldfb_state = Q10; - move16(); -#endif /* OPT_AVOID_STATE_BUF_RESCALE */ - } - ELSE - { - /* synthesis of the combined signal */ - max_real = 0; - max_imag = 0; - move32(); - move32(); - FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) - { - FOR( j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) - { - max_real = L_max( max_real, L_abs( realBuffer_fx[i][j] ) ); - max_imag = L_max( max_imag, L_abs( imagBuffer_fx[i][j] ) ); - } - } - max_val = L_max( max_real, max_imag ); - Q_real = sub( norm_l( max_val ), 3 ) /* Guard bits */; - FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) - { - scale_sig32( realBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_real ); // Q_real - scale_sig32( imagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_real ); // Q_real - } -#ifdef OPT_STEREO_32KBPS_V1 - scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( Q_real, Q11 ) ); // Q10 - > (Q_real-1) -#else /* OPT_STEREO_32KBPS_V1 */ - scale_sig32_r( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( sub( Q_real, 1 ), Q10 ) ); //(Q_real - 1) -#endif /* OPT_STEREO_32KBPS_V1 */ - st->cldfbSyn->Q_cldfb_state = sub( Q_real, 1 ); - move16(); - -#ifdef OPT_AVOID_STATE_BUF_RESCALE - cldfbSynthesis_ivas_fx( realBuffer_fx, imagBuffer_fx, synth_fx, -1, 0, 0, st->cldfbSyn ); -#else /* OPT_AVOID_STATE_BUF_RESCALE */ - cldfbSynthesis_ivas_fx( realBuffer_fx, imagBuffer_fx, synth_fx, -1, 0, st->cldfbSyn ); -#endif /* OPT_AVOID_STATE_BUF_RESCALE */ - scale_sig32( synth_fx, output_frame, negate( sub( Q_real, 1 ) ) ); // Q0 - scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( Q10, sub( Q_real, 1 ) ) ); // Q10 - st->cldfbSyn->Q_cldfb_state = Q10; - move16(); - } - - /* save synthesis - needed in case of core switching */ - Copy32( synth_fx, st->previoussynth_fx_32, output_frame ); // Q0 - } - ELSE - { - Word16 nSamples = NS2SA_FX2( i_mult( st->L_frame, FRAMES_PER_SEC ), FRAME_SIZE_NS /*DELAY_CLDFB_NS*/ ); /* IVAS-64: optimization is likely possible here (don't resample the whole frame) */ - - /* analysis of the synthesis at internal sampling rate - needed for DFT stereo -> TD stereo switching */ - FOR( i = 0; i < st->L_frame; i++ ) - { - syn_32_fx[i] = L_shr( L_deposit_h( psyn_fx[i] ), add( 4, st->Q_syn ) ); - move32(); - } - - Word16 offset = sub( st->cldfbAna->p_filter_length, st->cldfbAna->no_channels ); - Scale_sig32( st->cldfbAna->cldfb_state_fx, offset, 1 ); // Q12 - st->cldfbAna->Q_cldfb_state = Q12; - move16(); - - cldfbAnalysis_ivas_fx( syn_32_fx + sub( st->L_frame, nSamples ), realBuffer_fx, imagBuffer_fx, nSamples, st->cldfbAna ); - - Scale_sig32( st->cldfbAna->cldfb_state_fx, offset, -1 ); // Q11 - st->cldfbAna->Q_cldfb_state = Q11; - move16(); /* analysis and add the BPF error signal - needed for DFT stereo -> TD stereo switching */ - Word32 tmp_bpf_error_signal_fx[L_FRAME16k]; - Word16 q_bpf_error_signal; - Word16 cldfb_state_offset; - cldfb_state_offset = sub( st->cldfbBPF->p_filter_length, st->cldfbBPF->no_channels ); - - // Get Q-factor - q_bpf_error_signal = Q6; - move16(); - Copy_Scale_sig_16_32_no_sat( bpf_error_signal_16fx, tmp_bpf_error_signal_fx, L_FRAME16k, sub( q_bpf_error_signal, st->Q_syn ) ); // Q6 - FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) - { - Scale_sig32( realBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, -Q7 ); // Q0 - Scale_sig32( imagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, -Q7 ); // Q0 - } - Scale_sig32( st->cldfbBPF->cldfb_state_fx, cldfb_state_offset, sub( q_bpf_error_signal, Q10 ) ); // q_bpf_error_signal (Q6) - st->cldfbBPF->Q_cldfb_state = q_bpf_error_signal; - move16(); - tmp = 0; - move16(); - if ( !st->bpf_off ) - { - tmp = nSamples; - move16(); - } - - addBassPostFilter_ivas_fx( tmp_bpf_error_signal_fx + sub( st->L_frame, nSamples ), tmp, realBuffer_fx, imagBuffer_fx, st->cldfbBPF ); - - Scale_sig32( st->cldfbBPF->cldfb_state_fx, cldfb_state_offset, negate( sub( q_bpf_error_signal, Q10 ) ) ); // Q10 - st->cldfbBPF->Q_cldfb_state = Q10; - move16(); - /* synthesis of the combined signal - needed for DFT stereo -> TD stereo switching */ - max_real = 0; - max_imag = 0; - move32(); - move32(); - FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) - { - FOR( j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) - { - max_real = L_max( max_real, L_abs( realBuffer_fx[i][j] ) ); - max_imag = L_max( max_imag, L_abs( imagBuffer_fx[i][j] ) ); - } - } - max_val = L_max( max_real, max_imag ); - Q_real = sub( norm_l( max_val ), 3 ) /* Guard bits */; - FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) - { - scale_sig32( realBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_real ); // Q_real - scale_sig32( imagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_real ); // Q_real - } -#ifndef OPT_AVOID_STATE_BUF_RESCALE -#ifdef OPT_STEREO_32KBPS_V1 - scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( Q_real, Q11 ) ); // Q10 - > (Q_real-1) -#else /* OPT_STEREO_32KBPS_V1 */ - scale_sig32_r( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( sub( Q_real, 1 ), Q10 ) ); //(Q_real - 1) -#endif /* OPT_STEREO_32KBPS_V1 */ -#endif /* OPT_AVOID_STATE_BUF_RESCALE */ - -#ifdef OPT_AVOID_STATE_BUF_RESCALE - cldfbSynthesis_ivas_fx( realBuffer_fx, imagBuffer_fx, synth_fx /*dummy*/, NS2SA_FX2( st->output_Fs, FRAME_SIZE_NS /*DELAY_CLDFB_NS*/ ), sub( Q10, sub( Q_real, 1 ) ), -10, st->cldfbSyn ); -#else /* OPT_AVOID_STATE_BUF_RESCALE */ - cldfbSynthesis_ivas_fx( realBuffer_fx, imagBuffer_fx, synth_fx /*dummy*/, NS2SA_FX2( st->output_Fs, FRAME_SIZE_NS /*DELAY_CLDFB_NS*/ ), 0, st->cldfbSyn ); -#endif /* OPT_AVOID_STATE_BUF_RESCALE */ - -#ifndef OPT_AVOID_STATE_BUF_RESCALE - Scale_sig32( synth_fx, output_frame, negate( sub( Q_real, 1 ) ) ); // Q0 - Scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( Q10, sub( Q_real, 1 ) ) ); // Q10 - st->cldfbSyn->Q_cldfb_state = Q10; - move16(); -#endif /* OPT_AVOID_STATE_BUF_RESCALE */ - IF( st->p_bpf_noise_buf_32 ) - { - Copy_Scale_sig_16_32_DEPREC( bpf_error_signal_16fx, bpf_error_signal_fx, st->L_frame, -1 ); // Q_syn-1 - Copy32( bpf_error_signal_fx, st->p_bpf_noise_buf_32, st->L_frame ); - - Scale_sig32( st->p_bpf_noise_buf_32, st->L_frame, sub( Q11, sub( st->Q_syn, 1 ) ) ); // Q11 - } - - set32_fx( synth_fx, 0, output_frame ); - } - - /* Copy output signal */ - Scale_sig( syn_tmp_fx, add( st->L_frame, L_SUBFR ), negate( st->Q_syn ) ); // Q0 - IF( st->element_mode > EVS_MONO ) - { - Copy( psyn_fx, output_fx, st->L_frame ); /*Q_syn*/ - } - - st->Q_syn2 = 0; - move16(); - } - - /*-----------------------------------------------------------------* - * Bandwidth extension 6kHz-7kHz - *-----------------------------------------------------------------*/ - - IF( st->hBWE_zero != NULL ) - { - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( EQ_16( st->L_frame, L_FRAME ) && ( st->bwidth != NB ) && GE_16( output_frame, L_FRAME16k ) && - ( EQ_16( st->extl, -1 ) || EQ_16( st->extl, SWB_CNG ) || ( EQ_16( st->extl, WB_BWE ) && st->extl_brate == 0 && NE_16( st->coder_type, AUDIO ) ) ) ) ) - { - IF( EQ_16( st->element_mode, EVS_MONO ) ) - { - hf_synth_fx( st->hBWE_zero, st->core_brate, output_frame, Aq_fx, exc2_fx, psyn_fx, synth_fx16, st->Q_exc, st->Q_syn2 ); - } - ELSE - { - Copy_Scale_sig_32_16( synth_fx, synth_fx16, output_frame, 0 ); // Q0 - hf_synth_fx( st->hBWE_zero, st->core_brate, output_frame, Aq_fx, exc2_fx, psyn_fx, synth_fx16, st->Q_exc, st->Q_syn2 ); - Copy_Scale_sig_16_32_DEPREC( synth_fx16, synth_fx, output_frame, 0 ); - } - } - ELSE - { - hf_synth_reset_fx( st->hBWE_zero ); - 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 - { - set16_fx( st->hBWE_zero->mem_hp400_fx, 0, 6 ); - } - } - } - - /*-----------------------------------------------------------------* - * Populate parameters for SWB TBE - *-----------------------------------------------------------------*/ - - IF( st->hBWE_TD != NULL ) - { - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( !st->bfi && st->prev_bfi ) || ( EQ_16( st->last_vbr_hw_BWE_disable_dec, 1 ) && ( st->vbr_hw_BWE_disable_dec == 0 ) ) || ( ( EQ_16( st->extl, SWB_TBE ) || EQ_16( st->extl, WB_TBE ) || EQ_16( st->extl, FB_TBE ) ) && NE_16( st->last_extl, SWB_TBE ) && NE_16( st->last_extl, WB_TBE ) && NE_16( st->last_extl, FB_TBE ) ) || ( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) && !st->tdm_LRTD_flag ) ) - { - st->hBWE_TD->bwe_non_lin_prev_scale_fx = 0; - move32(); - set16_fx( st->hBWE_TD->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET ); - } - - test(); - test(); - test(); - test(); - test(); - IF( !st->ppp_mode_dec && ( st->idchan == 0 || NE_16( st->element_mode, IVAS_CPE_TD ) || ( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) && st->tdm_LRTD_flag ) ) ) - { - IF( EQ_16( st->element_mode, EVS_MONO ) ) - { - non_linearity_fx( bwe_exc_fx, bwe_exc_extended_fx, L_FRAME32k, &st->hBWE_TD->bwe_non_lin_prev_scale_fx, st->Q_exc, st->coder_type, voice_factors_fx, st->L_frame ); - } - ELSE - { - Copy_Scale_sig_16_32_no_sat( st->hBWE_TD->old_bwe_exc_extended_fx, bwe_exc_extended_fx, NL_BUFF_OFFSET, ( sub( shl( st->Q_exc, 1 ), sub( st->prev_Q_bwe_exc, 16 ) ) ) ); // prev_Q_bwe_exc - non_linearity_ivas_fx( bwe_exc_fx, bwe_exc_extended_fx + NL_BUFF_OFFSET, L_FRAME32k, &st->hBWE_TD->bwe_non_lin_prev_scale_fx, st->Q_exc, st->coder_type, voice_factors_fx, st->L_frame ); - Copy_Scale_sig_32_16( bwe_exc_extended_fx + L_FRAME32k, st->hBWE_TD->old_bwe_exc_extended_fx, NL_BUFF_OFFSET, negate( sub( shl( st->Q_exc, 1 ), sub( st->prev_Q_bwe_exc, 16 ) ) ) ); // prev_Q_bwe_exc - } - } - - test(); - if ( st->core_brate == FRAME_NO_DATA || EQ_32( st->core_brate, SID_2k40 ) ) - { - st->hBWE_TD->bwe_non_lin_prev_scale_fx = 0; - move32(); - } - } - - /*----------------------------------------------------------------------* - * Updates - *----------------------------------------------------------------------*/ - - updt_dec_fx( st, old_exc_fx, pitch_buf_fx, Es_pred_fx, Aq_fx, lsf_new_fx, lsp_new_fx, voice_factors_fx, old_bwe_exc_fx, gain_buf_fx ); - - test(); - test(); - IF( GT_32( st->core_brate, SID_2k40 ) && st->hTdCngDec != NULL && st->hFdCngDec != NULL ) - { - /* update CNG parameters in active frames */ - IF( EQ_16( st->element_mode, EVS_MONO ) ) - { - cng_params_upd_fx( lsp_new_fx, exc_fx, st->L_frame, &st->hTdCngDec->ho_circ_ptr, st->hTdCngDec->ho_ener_circ_fx, &st->hTdCngDec->ho_circ_size, st->hTdCngDec->ho_lsp_circ_fx, - st->Q_exc, DEC, st->hTdCngDec->ho_env_circ_fx, NULL, NULL, NULL, NULL, st->last_active_brate ); - } - ELSE - { - cng_params_upd_ivas_fx( lsp_new_fx, exc_fx, st->L_frame, &st->hTdCngDec->ho_circ_ptr, st->hTdCngDec->ho_ener_circ_fx, &st->hTdCngDec->ho_circ_size, - st->hTdCngDec->ho_lsp_circ_fx, st->Q_exc, DEC, st->hTdCngDec->ho_env_circ_fx, NULL, NULL, NULL, NULL, st->last_active_brate, st->element_mode, - st->hFdCngDec->hFdCngCom->CngBandwidth ); - } - - /* Set 16k LSP flag for CNG buffer */ - st->hTdCngDec->ho_16k_lsp[st->hTdCngDec->ho_circ_ptr] = 0; - move16(); - if ( NE_16( st->L_frame, L_FRAME ) ) - { - st->hTdCngDec->ho_16k_lsp[st->hTdCngDec->ho_circ_ptr] = 1; - move16(); - } - } - - IF( NE_16( st->element_mode, EVS_MONO ) ) - { - IF( save_hb_synth_fx16 ) - { - Copy_Scale_sig_32_16( save_hb_synth_fx, save_hb_synth_fx16, L_FRAME48k, 0 ); // Q0 - } - Copy_Scale_sig_32_16( synth_fx, synth_fx16, output_frame, 0 ); // Q_syn2 - } - - pop_wmops(); - return error; -} diff --git a/lib_dec/ivas_td_low_rate_dec_fx.c b/lib_dec/ivas_td_low_rate_dec_fx.c index 8f09c1c7d..6419f8517 100644 --- a/lib_dec/ivas_td_low_rate_dec_fx.c +++ b/lib_dec/ivas_td_low_rate_dec_fx.c @@ -40,6 +40,13 @@ #include "prot_fx.h" #include "wmc_auto.h" #include "ivas_prot_fx.h" + +/*-------------------------------------------------------------------* + * tdm_low_rate_dec_fx() + * + * Low-bitrate decoder + *-------------------------------------------------------------------*/ + void tdm_low_rate_dec_fx( Decoder_State *st, /* i/o: decoder static memory */ Word16 dct_epit[], /* o : GSC excitation in DCT domain Q_exc*/ @@ -188,6 +195,7 @@ void tdm_low_rate_dec_fx( return; } + /*---------------------------------------------------------------------* * decod_gen_2sbfr() * @@ -217,12 +225,12 @@ void decod_gen_2sbfr_fx( move32(); Word16 gain_inov = 0; /* Innovation gain */ move16(); - Word32 gc_mem[NB_SUBFR - 1]; /* gain_code from previous subframes */ - Word16 gp_mem[NB_SUBFR - 1]; /* gain_pitch from previous subframes */ + Word32 gc_mem[NB_SUBFR - 1]; /* gain_code from previous subframes */ + Word16 gp_mem[NB_SUBFR - 1]; /* gain_pitch from previous subframes */ Word16 voice_fac; /* voicing factor */ Word16 code[2 * L_SUBFR]; /* algebraic codevector */ const Word16 *p_Aq; /* Pointer to frame LP coefficient */ - Word16 *pt_pitch; /* pointer to Word16 pitch */ + Word16 *pt_pitch; /* pointer to Word16 pitch */ Word16 i_subfr; /* tmp variables */ Word16 L_frame; Word16 pitch_limit_flag; -- GitLab From ed6b68d54da95ac03180412a2185a155b8ee1a9c Mon Sep 17 00:00:00 2001 From: vaclav Date: Thu, 17 Apr 2025 16:04:05 +0200 Subject: [PATCH 055/113] clang-format --- lib_enc/lsf_enc_fx.c | 4 ++-- lib_enc/pre_proc_fx.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib_enc/lsf_enc_fx.c b/lib_enc/lsf_enc_fx.c index b26532b15..23ed7d0c2 100644 --- a/lib_enc/lsf_enc_fx.c +++ b/lib_enc/lsf_enc_fx.c @@ -1985,7 +1985,7 @@ static void first_VQstages( dist[1] = dist_buf + maxC; move16(); - set16_fx( idx_buf, 0, (const Word16) ( 2 * stagesVQ * maxC ) ); + set16_fx( idx_buf, 0, ( const Word16 )( 2 * stagesVQ * maxC ) ); set16_fx( parents, 0, maxC ); /* Set up inital distance vector */ @@ -2175,7 +2175,7 @@ static void first_VQstages_ivas_fx( dist[1] = dist_buf + maxC; move16(); - set16_fx( idx_buf, 0, (const Word16) ( 2 * stagesVQ * maxC ) ); + set16_fx( idx_buf, 0, ( const Word16 )( 2 * stagesVQ * maxC ) ); set16_fx( parents, 0, maxC ); /* Set up inital distance vector */ diff --git a/lib_enc/pre_proc_fx.c b/lib_enc/pre_proc_fx.c index cc8b64ca4..f7ebc8298 100644 --- a/lib_enc/pre_proc_fx.c +++ b/lib_enc/pre_proc_fx.c @@ -213,7 +213,7 @@ void pre_proc_fx( /*----------------------------------------------------------------* * Change the sampling frequency to 12.8 kHz *----------------------------------------------------------------*/ - modify_Fs_fx( signal_in, input_frame, st->input_Fs, new_inp_12k8, INT_FS_12k8, st->mem_decim_fx, (const Word16) ( EQ_16( st->max_bwidth, NB ) ) ); + modify_Fs_fx( signal_in, input_frame, st->input_Fs, new_inp_12k8, INT_FS_12k8, st->mem_decim_fx, ( const Word16 )( EQ_16( st->max_bwidth, NB ) ) ); Copy( new_inp_12k8, st->buf_speech_enc + L_FRAME32k, L_FRAME ); Scale_sig( st->buf_speech_enc + L_FRAME32k, L_FRAME, 1 ); /*------------------------------------------------------------------* -- GitLab From 99e3a8baf5352b85a3355956f08fe26c0f6f7a62 Mon Sep 17 00:00:00 2001 From: Fabian Bauer Date: Tue, 13 May 2025 12:38:38 +0200 Subject: [PATCH 056/113] deactivcate FIX_1439_SPEEDUP_synthesise_fb_high_band_fx --- lib_com/options.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_com/options.h b/lib_com/options.h index bcee4b8fe..2d587c82a 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -91,7 +91,7 @@ #define FIX_1439_SPEEDUP_Copy_Scale_sig_16_32_no_sat /*FhG: reduces WMOPS - bit-exact*/ #define FIX_1439_SPEEDUP_stereo_icBWE_dec_fx /*FhG: reduces WMOPS - bit-exact*/ #define FIX_1439_SPEEDUP_ivas_swb_tbe_dec_fx /*FhG: reduces WMOPS - bit-exact*/ -#define FIX_1439_SPEEDUP_synthesise_fb_high_band_fx /*FhG: reduces WMOPS - bit-exact*/ +//#define FIX_1439_SPEEDUP_synthesise_fb_high_band_fx /*FhG: reduces WMOPS - bit-exact*/ #define FIX_1439_SPEEDUP_SIMPLIFY_elliptic_bpf_48k_generic /*FhG: reduces maintenance complexity & reduces WMOPS & prepares STAGE2 patch*/ #define FIX_1439_SPEEDUP_SIMPLIFY_elliptic_bpf_48k_generic_STAGE2 /*FhG: reduces WMOPS*/ #define FIX_1481_HARDCODE_DIV /* FhG: hardcode division results in stereo_dmx_evs_init_encoder_fx() */ -- GitLab From 378f5fab6bad83e506234a3d329864c8ea0660cd Mon Sep 17 00:00:00 2001 From: Fabian Bauer Date: Tue, 13 May 2025 14:40:11 +0200 Subject: [PATCH 057/113] delete FIX_1439_SPEEDUP_synthesise_fb_high_band_fx wrapped code --- lib_com/swb_tbe_com_fx.c | 1 + 1 file changed, 1 insertion(+) diff --git a/lib_com/swb_tbe_com_fx.c b/lib_com/swb_tbe_com_fx.c index 08bbd6362..4dfaa0a5a 100644 --- a/lib_com/swb_tbe_com_fx.c +++ b/lib_com/swb_tbe_com_fx.c @@ -7033,6 +7033,7 @@ void synthesise_fb_high_band_fx( { output[i] = extract_h( L_shl_sat( L_tmp, tmp3 ) ); /*Qout*/ move16(); + } } return; -- GitLab From 0e507b7d884abe27cf73c197c59339377cbdf581 Mon Sep 17 00:00:00 2001 From: Fabian Bauer Date: Tue, 13 May 2025 15:31:17 +0200 Subject: [PATCH 058/113] apply clang patch --- lib_com/swb_tbe_com_fx.c | 1 - 1 file changed, 1 deletion(-) diff --git a/lib_com/swb_tbe_com_fx.c b/lib_com/swb_tbe_com_fx.c index 4dfaa0a5a..08bbd6362 100644 --- a/lib_com/swb_tbe_com_fx.c +++ b/lib_com/swb_tbe_com_fx.c @@ -7033,7 +7033,6 @@ void synthesise_fb_high_band_fx( { output[i] = extract_h( L_shl_sat( L_tmp, tmp3 ) ); /*Qout*/ move16(); - } } return; -- GitLab From 097eff41e0a3e169e135036e69a4f900ea5b3044 Mon Sep 17 00:00:00 2001 From: Fabian Bauer Date: Tue, 13 May 2025 14:57:45 +0000 Subject: [PATCH 059/113] delete FIX_1439_SPEEDUP_synthesise_fb_high_band_fx from options --- lib_com/options.h | 1 - 1 file changed, 1 deletion(-) diff --git a/lib_com/options.h b/lib_com/options.h index 2d587c82a..2ddb2b138 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -91,7 +91,6 @@ #define FIX_1439_SPEEDUP_Copy_Scale_sig_16_32_no_sat /*FhG: reduces WMOPS - bit-exact*/ #define FIX_1439_SPEEDUP_stereo_icBWE_dec_fx /*FhG: reduces WMOPS - bit-exact*/ #define FIX_1439_SPEEDUP_ivas_swb_tbe_dec_fx /*FhG: reduces WMOPS - bit-exact*/ -//#define FIX_1439_SPEEDUP_synthesise_fb_high_band_fx /*FhG: reduces WMOPS - bit-exact*/ #define FIX_1439_SPEEDUP_SIMPLIFY_elliptic_bpf_48k_generic /*FhG: reduces maintenance complexity & reduces WMOPS & prepares STAGE2 patch*/ #define FIX_1439_SPEEDUP_SIMPLIFY_elliptic_bpf_48k_generic_STAGE2 /*FhG: reduces WMOPS*/ #define FIX_1481_HARDCODE_DIV /* FhG: hardcode division results in stereo_dmx_evs_init_encoder_fx() */ -- GitLab From 98e06bacaad4879d0663e8b751973f92b7f5ae47 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Fri, 16 May 2025 08:59:14 +0530 Subject: [PATCH 060/113] Fix for 3GPP issue 1583: Very high MLD for ParamMC 5.1+4 at 96kbps 16kHz input Link #1583 --- lib_enc/ivas_mc_param_enc_fx.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib_enc/ivas_mc_param_enc_fx.c b/lib_enc/ivas_mc_param_enc_fx.c index 3058f87f3..7f74f78f9 100644 --- a/lib_enc/ivas_mc_param_enc_fx.c +++ b/lib_enc/ivas_mc_param_enc_fx.c @@ -768,8 +768,8 @@ static void ivas_param_mc_param_est_enc_fx( #endif #ifdef MERGE_REQUEST_1378_SPEEDUP_ivas_mc_param_enc_fx_NONBE - sub35gb = sub( 35, find_guarded_bits_fx( l_ts ) ); - sub62gb = sub( 62, find_guarded_bits_fx( l_ts ) ); + sub35gb = sub( 32, sub( 11, find_guarded_bits_fx( l_ts ) ) ); // 31 - (((11 - gb) + 31 + norm) - 32) + sub62gb = sub( 63, shl( sub( 11, find_guarded_bits_fx( l_ts ) ), 1 ) ); // 31 - ((2*(11 - gb) + norm) - 32) #endif FOR( ts = start_ts; ts < num_time_slots; ts++ ) -- GitLab From 9600ad0128c5b0bfbc8b9a7c7c904111e2a501c4 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Fri, 16 May 2025 16:15:17 +0530 Subject: [PATCH 061/113] Fix for 3GPP issue 1533: Slightly high MLD for one case of MASA LTV EXT output in BASOP decoder Link #1533 --- lib_dec/ivas_stereo_cng_dec.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib_dec/ivas_stereo_cng_dec.c b/lib_dec/ivas_stereo_cng_dec.c index 6b8a8f949..8ec147ff7 100644 --- a/lib_dec/ivas_stereo_cng_dec.c +++ b/lib_dec/ivas_stereo_cng_dec.c @@ -1368,8 +1368,8 @@ static void FindEmEs_fx( temp_q = 0; move16(); } - log_res = BASOP_Util_Log2( square_res ); - es_em_fx = Mpy_32_32( log_res, 1616107501 ); // 25+30-31 + log_res = L_add( BASOP_Util_Log2( square_res ), L_shl( temp_q, Q25 ) ); + es_em_fx = Mpy_32_32( log_res, 1616107501 /* 5 * (ln(2)/ln(10)) */ ); // 25+30-31 /* long-term estimate */ *lt_es_em_fx = L_add( Mpy_32_32( 858993459, *lt_es_em_fx ), Mpy_32_32( 1288490188, es_em_fx ) ); /* Q24 */ move32(); -- GitLab From d784008387fe458ba8f6c4fcd8a5943587e80718 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Fri, 16 May 2025 12:26:14 +0530 Subject: [PATCH 062/113] Fix for 3GPP issue 1469: Somewhat high MLD on a single MASA selection test material case with BASOP decoder Link #1469 --- lib_com/prot_fx.h | 2 +- lib_com/stat_noise_uv_mod_fx.c | 58 +++++++++++++++++++--------------- lib_dec/stat_noise_uv_dec_fx.c | 2 +- lib_enc/acelp_core_enc_fx.c | 5 +-- lib_enc/prot_fx_enc.h | 2 +- lib_enc/stat_noise_uv_enc_fx.c | 2 +- 6 files changed, 39 insertions(+), 32 deletions(-) diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 43010af04..d5e52e046 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -8247,7 +8247,7 @@ void stat_noise_uv_mod_ivas_fx( const Word16 *lsp_mid, /* i : LSP vector at 2nd sfr Q=15*/ Word16 *Aq, /* o : A(z) quantized for the 4 subframes Q=12*/ Word16 *exc2, /* i/o: excitation buffer Q=Q_exc*/ - Word16 Q_exc, /* i : Q of exc2 excitation buffer [11..-1] expected */ + Word16 *Q_exc, /* i : Q of exc2 excitation buffer [11..-1] expected */ const Word16 bfi, /* i : Bad frame indicator */ Word32 *ge_sm, /* i/o: smoothed excitation gain Q=Q_stat_noise_ge (6)*/ Word16 *uv_count, /* i/o: unvoiced counter */ diff --git a/lib_com/stat_noise_uv_mod_fx.c b/lib_com/stat_noise_uv_mod_fx.c index 67ca21cd2..c259745f2 100644 --- a/lib_com/stat_noise_uv_mod_fx.c +++ b/lib_com/stat_noise_uv_mod_fx.c @@ -330,7 +330,6 @@ void stat_noise_uv_mod_fx( } } } - /*--------------------------------------------------------------------* * stat_noise_uv_mod() * @@ -345,7 +344,7 @@ void stat_noise_uv_mod_ivas_fx( const Word16 *lsp_mid, /* i : LSP vector at 2nd sfr Q=15*/ Word16 *Aq, /* o : A(z) quantized for the 4 subframes Q=12*/ Word16 *exc2, /* i/o: excitation buffer Q=Q_exc*/ - Word16 Q_exc, /* i : Q of exc2 excitation buffer [11..-1] expected */ + Word16 *Q_exc, /* i : Q of exc2 excitation buffer [11..-1] expected */ const Word16 bfi, /* i : Bad frame indicator */ Word32 *ge_sm, /* i/o: smoothed excitation gain Q=Q_stat_noise_ge (6)*/ Word16 *uv_count, /* i/o: unvoiced counter */ @@ -370,8 +369,9 @@ void stat_noise_uv_mod_ivas_fx( Word16 oldlsp_mix[M]; Word16 midlsp_mix[M]; Word16 newlsp_mix[M]; - Word16 beta; /* Q15 */ - Word16 Noimix_fract; /* (noimix_fac - 1.0) in Q15 */ + Word16 beta; /* Q15 */ + Word16 Noimix_fract; /* (noimix_fac - 1.0) in Q15 */ + Word32 L_Noimix_fract; /* (noimix_fac - 1.0) in Q15 */ /* noimix_fax * x <-> x + Noimix_fract * x */ Word16 i_subfr; Word16 i, k; @@ -382,7 +382,8 @@ void stat_noise_uv_mod_ivas_fx( Word32 L_tmp_res, L_tmp, L_tmp3, L_Ge; Word16 En_shift, Tmp; - Word16 Exc2_local[L_FRAME]; /* local_copy in scaled Q_local*/ + Word16 Exc2_local[L_FRAME]; /* local_copy in scaled Q_local*/ + Word32 L_Exc2_local[L_FRAME]; /* local_copy in scaled Q_local*/ #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); @@ -437,9 +438,9 @@ void stat_noise_uv_mod_ivas_fx( Copy( exc2, Exc2_local, L_FRAME ); /* bound Q for internal use, optimization possible */ - Q_local = s_min( 11, s_max( -1, Q_exc ) ); + Q_local = s_min( 11, s_max( -1, *Q_exc ) ); /* local excitation Q and incoming excitation Q*/ - Qdiff = sub( Q_local, Q_exc ); + Qdiff = sub( Q_local, *Q_exc ); /* only shift if incoming Q is outside [11..-1] shift is done in energy calculations aswell */ Scale_sig( Exc2_local, L_FRAME, Qdiff ); /* current excitation Q and previous stat_noise states Q */ @@ -539,14 +540,11 @@ void stat_noise_uv_mod_ivas_fx( L_tmp_res = L_mac( 0, alpha, alpha ); L_tmp_res = L_mac( L_tmp_res, alpha_m1, alpha_m1 ); tmp_den = round_fx( L_Frac_sqrtQ31( L_tmp_res ) ); - - tmp_nom = sub( 32767, tmp_den ); - tmp_shift = norm_s( tmp_den ); - tmp_den = shl( tmp_den, tmp_shift ); - tmp_res = div_s( tmp_nom, tmp_den ); - - Noimix_fract = shr( tmp_res, tmp_shift ); /* float value is in range 0.0 to 0.42 */ - + Word16 exp_sqr = 0; + move16(); + tmp_res = BASOP_Util_Divide1616_Scale( 32767, tmp_den, &exp_sqr ); // 15-exp_sqr + Noimix_fract = tmp_res; // 15-exp_sqr + move16(); /* L_Ge might be 0 in unvoiced WB */ L_Ge = L_max( L_Ge, 1 ); tmp_shift = norm_l( L_Ge ); @@ -555,9 +553,7 @@ void stat_noise_uv_mod_ivas_fx( L_tmp_res = Mult_32_16( *ge_sm, tmp_res ); /* Q_stat_noise_ge+45-Q_local-Q_ge-tmp_shift-15 */ L_tmp_res = Mult_32_16( L_tmp_res, sub( 32767, beta ) ); /*30-Q_local-tmp_shift+15-15 */ L_tmp_res = L_add_sat( L_shl_sat( L_tmp_res, sub( add( Q_local, tmp_shift ), 15 ) ), beta ); /* Q15 */ - tmp_res = extract_h( L_shl_o( L_tmp_res, 15, &Overflow ) ); /* 15+15-16=14 */ - - Noimix_fract = extract_l( Mult_32_16( L_tmp_res, Noimix_fract ) ); /*15+15-15 */ + L_Noimix_fract = Mult_32_16( L_tmp_res, Noimix_fract ); /*15+15-exp_sqr-15 =15-exp_sqr */ FOR( i = 0; i < L_FRAME; i++ ) { @@ -573,18 +569,27 @@ void stat_noise_uv_mod_ivas_fx( randval = mult_r( 28378, randval ); /* Q downscaled by 2 bits ends up in Q14 */ /*sqrt(12.0f) in Q13*/ randval = extract_l( L_shl( Mult_32_16( L_Ge, randval ), sub( 1, *Q_stat_noise_ge ) ) ); /*Q_local+Q_ge+14-15+1-Q_ge=Q_local */ - L_tmp = L_mult( Exc2_local[i], alpha ); /* Q_local + 16 */ - L_tmp = L_mac( L_tmp, randval, alpha_m1 ); /* Q_local + 16 */ - L_tmp3 = Mult_32_16( L_tmp, Noimix_fract ); /* Q_local+16+15-15 */ - L_tmp = L_add_sat( L_tmp3, L_shl_sat( Mult_32_16( L_tmp, tmp_res ), 1 ) ); /* Q_local+16+14-15+1 */ - Exc2_local[i] = extract_h( L_tmp ); /*Q_local */ + L_tmp = L_mult( Exc2_local[i], alpha ); /* Q_local + 16 */ + L_tmp = L_mac( L_tmp, randval, alpha_m1 ); /* Q_local + 16 */ + L_tmp3 = Mult_32_32( L_tmp, L_Noimix_fract ); /* Q_local+16+15-exp_sqr-15 =Q_local +1 */ + L_Exc2_local[i] = L_add( L_shr( L_tmp3, 1 ), Mpy_32_32( L_tmp, L_tmp_res ) ); // Q_local + 16 +15 -31 = Q_local + move32(); + } + Word32 max_val; + maximum_abs_32_fx( L_Exc2_local, L_FRAME, &max_val ); + Word16 shift = 0; + move16(); + IF( GT_32( max_val, ONE_IN_Q15 ) ) + { + shift = norm_l( max_val ); + shift = sub( Q31 - Q15, shift ); + *Q_exc = sub( Q_local, shift ); // Q_exc = Q_local -shift move16(); } *Q_stat_noise = Q_local; /* update for next call, routine can only be called once every frame */ move16(); - Qdiff = sub( Q_exc, Q_local ); /* local excitation and incoming excitation */ - Scale_sig( Exc2_local, L_FRAME, Qdiff ); - Copy( Exc2_local, exc2, L_FRAME ); + + Copy_Scale_sig_32_16( L_Exc2_local, exc2, L_FRAME, negate( shift ) ); // Q_exc /*--------------------------------------------------------------------* * Generate low-pass filtered version of ISP coefficients @@ -635,6 +640,7 @@ void stat_noise_uv_mod_ivas_fx( } } } + /*---------------------------------------------------------------------------* * calc_tilt() * diff --git a/lib_dec/stat_noise_uv_dec_fx.c b/lib_dec/stat_noise_uv_dec_fx.c index d2fa36b9b..4e4d7ca30 100644 --- a/lib_dec/stat_noise_uv_dec_fx.c +++ b/lib_dec/stat_noise_uv_dec_fx.c @@ -76,7 +76,7 @@ void stat_noise_uv_dec_fx( IF( !st_fx->Opt_AMR_WB ) { - stat_noise_uv_mod_fx( coder_type, noisiness, st_fx->lsp_old_fx, lsp_new, lsp_mid, Aq, exc2, st_fx->Q_exc, 0, &st_fx->ge_sm_fx, &st_fx->uv_count, &st_fx->act_count, + stat_noise_uv_mod_ivas_fx( coder_type, noisiness, st_fx->lsp_old_fx, lsp_new, lsp_mid, Aq, exc2, &st_fx->Q_exc, 0, &st_fx->ge_sm_fx, &st_fx->uv_count, &st_fx->act_count, st_fx->lspold_s_fx, &st_fx->noimix_seed, &st_fx->min_alpha_fx, &st_fx->exc_pe_fx, st_fx->core_brate, st_fx->bwidth, &st_fx->Q_stat_noise, &st_fx->Q_stat_noise_ge ); diff --git a/lib_enc/acelp_core_enc_fx.c b/lib_enc/acelp_core_enc_fx.c index ceba860a1..6ba21136e 100644 --- a/lib_enc/acelp_core_enc_fx.c +++ b/lib_enc/acelp_core_enc_fx.c @@ -1449,8 +1449,9 @@ ivas_error acelp_core_enc_ivas_fx( { /* exc2 buffer is needed only for updating of Aq[] which is needed for core switching */ Copy( exc_fx, exc2_fx, st->L_frame ); // Q_new - - stat_noise_uv_enc_ivas_fx( st, epsP, lsp_new, lsp_mid, Aq, exc2_fx, uc_two_stage_flag, Q_new ); + Word16 q_exc2 = Q_new; + move16(); + stat_noise_uv_enc_ivas_fx( st, epsP, lsp_new, lsp_mid, Aq, exc2_fx, uc_two_stage_flag, &q_exc2 ); } /*-----------------------------------------------------------------* diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 968ab0082..72137bdce 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -2189,7 +2189,7 @@ void stat_noise_uv_enc_ivas_fx( Word16 *Aq, /* i : A(z) quantized for the 4 subframes Q=12 */ Word16 *exc2, /* i/o: excitation buffer Q=Q_stat_noise */ const Word16 uc_two_stage_flag, /* o : flag undicating two-stage UC */ - Word16 Q_new ); + Word16 *Q_new ); void analy_sp_fx( const Word16 element_mode, /* i : element mode */ diff --git a/lib_enc/stat_noise_uv_enc_fx.c b/lib_enc/stat_noise_uv_enc_fx.c index 1445559a1..24932542c 100644 --- a/lib_enc/stat_noise_uv_enc_fx.c +++ b/lib_enc/stat_noise_uv_enc_fx.c @@ -118,7 +118,7 @@ void stat_noise_uv_enc_ivas_fx( Word16 *Aq, /* i : A(z) quantized for the 4 subframes Q=12 */ Word16 *exc2, /* i/o: excitation buffer Q=Q_stat_noise */ const Word16 uc_two_stage_flag, /* o : flag undicating two-stage UC */ - Word16 Q_new ) + Word16 *Q_new ) { Word16 noisiness = 0; move16(); -- GitLab From 9189bfaf27589723c02d76e3ce20751f18f9c5e3 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Fri, 16 May 2025 12:32:36 +0530 Subject: [PATCH 063/113] Clang formatting changes --- lib_com/prot_fx.h | 2 +- lib_dec/stat_noise_uv_dec_fx.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index d5e52e046..85ece0cab 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -8247,7 +8247,7 @@ void stat_noise_uv_mod_ivas_fx( const Word16 *lsp_mid, /* i : LSP vector at 2nd sfr Q=15*/ Word16 *Aq, /* o : A(z) quantized for the 4 subframes Q=12*/ Word16 *exc2, /* i/o: excitation buffer Q=Q_exc*/ - Word16 *Q_exc, /* i : Q of exc2 excitation buffer [11..-1] expected */ + Word16 *Q_exc, /* i : Q of exc2 excitation buffer [11..-1] expected */ const Word16 bfi, /* i : Bad frame indicator */ Word32 *ge_sm, /* i/o: smoothed excitation gain Q=Q_stat_noise_ge (6)*/ Word16 *uv_count, /* i/o: unvoiced counter */ diff --git a/lib_dec/stat_noise_uv_dec_fx.c b/lib_dec/stat_noise_uv_dec_fx.c index 4e4d7ca30..e2dc1460e 100644 --- a/lib_dec/stat_noise_uv_dec_fx.c +++ b/lib_dec/stat_noise_uv_dec_fx.c @@ -77,9 +77,9 @@ void stat_noise_uv_dec_fx( IF( !st_fx->Opt_AMR_WB ) { stat_noise_uv_mod_ivas_fx( coder_type, noisiness, st_fx->lsp_old_fx, lsp_new, lsp_mid, Aq, exc2, &st_fx->Q_exc, 0, &st_fx->ge_sm_fx, &st_fx->uv_count, &st_fx->act_count, - st_fx->lspold_s_fx, &st_fx->noimix_seed, &st_fx->min_alpha_fx, - &st_fx->exc_pe_fx, st_fx->core_brate, st_fx->bwidth, - &st_fx->Q_stat_noise, &st_fx->Q_stat_noise_ge ); + st_fx->lspold_s_fx, &st_fx->noimix_seed, &st_fx->min_alpha_fx, + &st_fx->exc_pe_fx, st_fx->core_brate, st_fx->bwidth, + &st_fx->Q_stat_noise, &st_fx->Q_stat_noise_ge ); } -- GitLab From e4d93a77b8d75f4b46e2a9b4a0a9cf52b1e38c29 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Fri, 16 May 2025 14:45:18 +0530 Subject: [PATCH 064/113] Fix for EVS bitexactness issue --- lib_dec/stat_noise_uv_dec_fx.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/lib_dec/stat_noise_uv_dec_fx.c b/lib_dec/stat_noise_uv_dec_fx.c index e2dc1460e..c87e30ffe 100644 --- a/lib_dec/stat_noise_uv_dec_fx.c +++ b/lib_dec/stat_noise_uv_dec_fx.c @@ -76,10 +76,20 @@ void stat_noise_uv_dec_fx( IF( !st_fx->Opt_AMR_WB ) { - stat_noise_uv_mod_ivas_fx( coder_type, noisiness, st_fx->lsp_old_fx, lsp_new, lsp_mid, Aq, exc2, &st_fx->Q_exc, 0, &st_fx->ge_sm_fx, &st_fx->uv_count, &st_fx->act_count, - st_fx->lspold_s_fx, &st_fx->noimix_seed, &st_fx->min_alpha_fx, - &st_fx->exc_pe_fx, st_fx->core_brate, st_fx->bwidth, - &st_fx->Q_stat_noise, &st_fx->Q_stat_noise_ge ); + IF( st_fx->element_mode > EVS_MONO ) + { + stat_noise_uv_mod_ivas_fx( coder_type, noisiness, st_fx->lsp_old_fx, lsp_new, lsp_mid, Aq, exc2, &st_fx->Q_exc, 0, &st_fx->ge_sm_fx, &st_fx->uv_count, &st_fx->act_count, + st_fx->lspold_s_fx, &st_fx->noimix_seed, &st_fx->min_alpha_fx, + &st_fx->exc_pe_fx, st_fx->core_brate, st_fx->bwidth, + &st_fx->Q_stat_noise, &st_fx->Q_stat_noise_ge ); + } + ELSE + { + stat_noise_uv_mod_fx( coder_type, noisiness, st_fx->lsp_old_fx, lsp_new, lsp_mid, Aq, exc2, st_fx->Q_exc, 0, &st_fx->ge_sm_fx, &st_fx->uv_count, &st_fx->act_count, + st_fx->lspold_s_fx, &st_fx->noimix_seed, &st_fx->min_alpha_fx, + &st_fx->exc_pe_fx, st_fx->core_brate, st_fx->bwidth, + &st_fx->Q_stat_noise, &st_fx->Q_stat_noise_ge ); + } } -- GitLab From a9b30958a324d74b2ecc91462fa31d1a9b2dff1e Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Thu, 15 May 2025 14:23:40 +0530 Subject: [PATCH 065/113] Fix for 3GPP issue 1531: Low-bitrate OMASA shows a bit high MLD (over 10) in BASOP decoder rendering to binaural Link #1531 --- lib_dec/FEC_clas_estim_fx.c | 16 ++++-- .../ivas_dirac_dec_binaural_functions_fx.c | 49 ++++++++++++++---- lib_rend/ivas_dirac_rend_fx.c | 51 ++++++++++++------- 3 files changed, 85 insertions(+), 31 deletions(-) diff --git a/lib_dec/FEC_clas_estim_fx.c b/lib_dec/FEC_clas_estim_fx.c index e56a77be1..2bd38153a 100644 --- a/lib_dec/FEC_clas_estim_fx.c +++ b/lib_dec/FEC_clas_estim_fx.c @@ -285,7 +285,17 @@ void FEC_clas_estim_fx( Corre( &pt1[pos], &pt1[pos - T0], T0, &cor_max[0] ); - T0 = mult_r_sat( add_sat( pitch[2], pitch[3] ), 256 ); + IF( NE_16( st_fx->element_mode, EVS_MONO ) ) + { + IF( LT_16( sub( pos, T0 ), sub( L_frame, L_SUBFR ) ) ) + { + T0 = mult_r_sat( add_sat( pitch[2], pitch[3] ), 256 ); + } + } + ELSE + { + T0 = mult_r_sat( add_sat( pitch[2], pitch[3] ), 256 ); + } pos_limit = sub( L_frame, L_SUBFR ); j = s_min( 1, s_max( 0, sub( pos, pos_limit ) ) ); Ltmp = L_deposit_l( cor_max[0] ); @@ -725,8 +735,8 @@ void FEC_clas_estim_fx( } /* Do the classification only - - MODE1: when the class is not transmitted in the bitstream - - MODE2: on good frames (classifier is also called for bfi=1) */ + - MODE1: when the class is not transmitted in the bitstream + - MODE2: on good frames (classifier is also called for bfi=1) */ /* update the memory of synthesis for frame class estimation */ diff --git a/lib_rend/ivas_dirac_dec_binaural_functions_fx.c b/lib_rend/ivas_dirac_dec_binaural_functions_fx.c index 16fefa3bb..c47052d5f 100644 --- a/lib_rend/ivas_dirac_dec_binaural_functions_fx.c +++ b/lib_rend/ivas_dirac_dec_binaural_functions_fx.c @@ -3584,24 +3584,53 @@ static void matrixTransp1Mul_fx( Word16 chA, chB; Word16 size = i_mult( BINAURAL_CHANNELS, BINAURAL_CHANNELS ); + Word64 tmp_outRe_fx[BINAURAL_CHANNELS][BINAURAL_CHANNELS]; + Word64 tmp_outIm_fx[BINAURAL_CHANNELS][BINAURAL_CHANNELS]; + Word16 q_tmp_outRe_fx[BINAURAL_CHANNELS][BINAURAL_CHANNELS]; + Word16 q_tmp_outIm_fx[BINAURAL_CHANNELS][BINAURAL_CHANNELS]; + Word64 tmp64_1, tmp64_2; + Word16 tmp16, q_common = 63; + move16(); + FOR( chA = 0; chA < BINAURAL_CHANNELS; chA++ ) { FOR( chB = 0; chB < BINAURAL_CHANNELS; chB++ ) { - outRe_fx[chA][chB] = Madd_32_32( Madd_32_32( Madd_32_32( Mpy_32_32( Are_fx[0][chA], Bre_fx[0][chB] ), - Are_fx[1][chA], Bre_fx[1][chB] ), - Aim_fx[0][chA], Bim_fx[0][chB] ), - Aim_fx[1][chA], Bim_fx[1][chB] ); + tmp64_1 = W_mac_32_32( W_mult_32_32( Are_fx[0][chA], Bre_fx[0][chB] ), Are_fx[1][chA], Bre_fx[1][chB] ); // Q: add( add( q_A, q_B ), 1 ) + tmp64_2 = W_mac_32_32( W_mult_32_32( Aim_fx[0][chA], Bim_fx[0][chB] ), Aim_fx[1][chA], Bim_fx[1][chB] ); // Q: add( add( q_A, q_B ), 1 ) + tmp_outRe_fx[chA][chB] = W_add( tmp64_1, tmp64_2 ); // Q: add( add( q_A, q_B ), 1 ) + move64(); + tmp16 = W_norm( tmp_outRe_fx[chA][chB] ); + tmp_outRe_fx[chA][chB] = W_shl( tmp_outRe_fx[chA][chB], tmp16 ); // Q:add( tmp16, add( add( q_A, q_B ), 1 ) ) + move64(); + q_tmp_outRe_fx[chA][chB] = add( tmp16, add( add( q_A, q_B ), 1 ) ); + move16(); + q_common = s_min( q_tmp_outRe_fx[chA][chB], q_common ); + + + tmp64_1 = W_mac_32_32( W_mult_32_32( Are_fx[0][chA], Bim_fx[0][chB] ), Are_fx[1][chA], Bim_fx[1][chB] ); // Q: add( add( q_A, q_B ), 1 ) + tmp64_2 = W_mac_32_32( W_mult_32_32( Aim_fx[0][chA], Bre_fx[0][chB] ), Aim_fx[1][chA], Bre_fx[1][chB] ); // Q: add( add( q_A, q_B ), 1 ) + tmp_outIm_fx[chA][chB] = W_sub( tmp64_1, tmp64_2 ); // Q: add( add( q_A, q_B ), 1 ) + move64(); + tmp16 = W_norm( tmp_outIm_fx[chA][chB] ); + tmp_outIm_fx[chA][chB] = W_shl( tmp_outIm_fx[chA][chB], tmp16 ); // Q:add( tmp16, add( add( q_A, q_B ), 1 ) ) + move64(); + q_tmp_outIm_fx[chA][chB] = add( tmp16, add( add( q_A, q_B ), 1 ) ); + move16(); + q_common = s_min( q_tmp_outIm_fx[chA][chB], q_common ); + } + } + FOR( chA = 0; chA < BINAURAL_CHANNELS; chA++ ) + { + FOR( chB = 0; chB < BINAURAL_CHANNELS; chB++ ) + { + outRe_fx[chA][chB] = W_extract_h( W_shl( tmp_outRe_fx[chA][chB], sub( q_common, q_tmp_outRe_fx[chA][chB] ) ) ); move32(); - outIm_fx[chA][chB] = Msub_32_32( Msub_32_32( Madd_32_32( Mpy_32_32( Are_fx[0][chA], Bim_fx[0][chB] ), - Are_fx[1][chA], Bim_fx[1][chB] ), - Aim_fx[0][chA], Bre_fx[0][chB] ), - Aim_fx[1][chA], Bre_fx[1][chB] ); + outIm_fx[chA][chB] = W_extract_h( W_shl( tmp_outIm_fx[chA][chB], sub( q_common, q_tmp_outIm_fx[chA][chB] ) ) ); move32(); } } - *q_out = sub( add( q_A, q_B ), 31 ); - + *q_out = sub( q_common, 32 ); move16(); if ( L_and( is_zero_arr( outRe_fx[0], size ), is_zero_arr( outIm_fx[0], size ) ) ) { diff --git a/lib_rend/ivas_dirac_rend_fx.c b/lib_rend/ivas_dirac_rend_fx.c index 06b37ff5a..063c70f66 100644 --- a/lib_rend/ivas_dirac_rend_fx.c +++ b/lib_rend/ivas_dirac_rend_fx.c @@ -1754,7 +1754,7 @@ void protoSignalComputation2_fx( Word32 RealSubtract_fx, ImagSubtract_fx; Word32 left_bb_power_fx, right_bb_power_fx, total_bb_power_fx, lr_bb_power_fx; Word32 left_hi_power_fx, right_hi_power_fx, total_hi_power_fx, lr_hi_power_fx; - Word32 sum_power_fx, Left_power_fx, Right_power_fx; + Word32 sum_power_fx, Left_power_fx, Right_power_fx, Total_power_fx; Word16 q_lr_bb_power, q_lr_hi_power; Word32 lr_total_bb_ratio_fx, lr_total_hi_ratio_fx; Word32 min_sum_total_ratio_fx, min_sum_total_ratio_db_fx; @@ -2120,7 +2120,10 @@ void protoSignalComputation2_fx( #else q_Left_Right_power = add( shl( add( q_cldfb, min_q_shift ), 1 ), sub( head_room, 32 ) ); #endif - + Word16 exp_left_hi_power = 0, exp_right_hi_power = 0, exp_total_hi_power = 0, exp_temppp; + move16(); + move16(); + move16(); FOR( l = 0; l < num_freq_bands; l++ ) { #ifdef FIX_867_CLDFB_NRG_SCALE @@ -2164,19 +2167,30 @@ void protoSignalComputation2_fx( left_bb_power_fx = L_add( left_bb_power_fx, Left_power_fx ); // q_Left_Right_power right_bb_power_fx = L_add( right_bb_power_fx, Right_power_fx ); // q_Left_Right_power // total_bb_power_fx = L_add( total_bb_power_fx, reference_power_fx[l] ); - total_bb_power_fx = L_add( total_bb_power_fx, W_extract_h( W_shl( reference_power_64fx[l], head_room ) ) ); // q_Left_Right_power + total_bb_power_fx = L_add( total_bb_power_fx, W_extract_h( W_shl( reference_power_64fx[l], head_room ) ) ); // q_Left_Right_power #endif - IF( GT_16( l, MASA_HI_FREQ_START_BIN ) ) { - left_hi_power_fx = L_add( left_hi_power_fx, Left_power_fx ); // q_Left_Right_power - right_hi_power_fx = L_add( right_hi_power_fx, Right_power_fx ); // q_Left_Right_power - // total_hi_power_fx = L_add( total_hi_power_fx, reference_power_fx[l] ); -#ifdef FIX_867_CLDFB_NRG_SCALE - total_hi_power_fx = L_add( total_hi_power_fx, W_extract_h( W_shl( reference_power_64fx[l], sub( head_room, total_shift[qidx] ) ) ) ); // q_Left_Right_power -#else - total_hi_power_fx = L_add( total_hi_power_fx, W_extract_h( W_shl( reference_power_64fx[l], head_room ) ) ); // q_Left_Right_power -#endif + W_tmp1 = W_add( W_mult0_32_32( RealBuffer_fx[0][0][l], RealBuffer_fx[0][0][l] ), W_mult0_32_32( ImagBuffer_fx[0][0][l], ImagBuffer_fx[0][0][l] ) ); + q_shift = W_norm( W_tmp1 ); + Left_power_fx = W_extract_h( W_shl( W_tmp1, q_shift ) ); + exp_temppp = sub( 31, sub( add( shl( q_cldfb, 1 ), q_shift ), 32 ) ); + + left_hi_power_fx = BASOP_Util_Add_Mant32Exp( left_hi_power_fx, exp_left_hi_power, Left_power_fx, exp_temppp, &exp_left_hi_power ); // exp:exp_left_hi_power + + W_tmp2 = W_add( W_mult0_32_32( RealBuffer_fx[1][0][l], RealBuffer_fx[1][0][l] ), W_mult0_32_32( ImagBuffer_fx[1][0][l], ImagBuffer_fx[1][0][l] ) ); + q_shift = W_norm( W_tmp2 ); + Right_power_fx = W_extract_h( W_shl( W_tmp2, q_shift ) ); + exp_temppp = sub( 31, sub( add( shl( q_cldfb, 1 ), q_shift ), 32 ) ); + + right_hi_power_fx = BASOP_Util_Add_Mant32Exp( right_hi_power_fx, exp_right_hi_power, Right_power_fx, exp_temppp, &exp_right_hi_power ); // exp:exp_right_hi_power + + W_tmp2 = W_add( W_tmp1, W_tmp2 ); + q_shift = W_norm( W_tmp2 ); + Total_power_fx = W_extract_h( W_shl( W_tmp2, q_shift ) ); + exp_temppp = sub( 31, sub( add( shl( q_cldfb, 1 ), q_shift ), 32 ) ); + + total_hi_power_fx = BASOP_Util_Add_Mant32Exp( total_hi_power_fx, exp_total_hi_power, Total_power_fx, exp_temppp, &exp_total_hi_power ); // exp:exp_total_hi_power } IF( LT_16( l, s_min( num_freq_bands, MASA_SUM_FREQ_RANGE_BINS ) ) ) @@ -2185,8 +2199,8 @@ void protoSignalComputation2_fx( re_aux = L_shl( Real_aux_fx, sub( temp_q_shift, min_q_shift[0] ) ); // q_cldfb+temp_q_shift im_aux = L_shl( Imag_aux_fx, sub( temp_q_shift, min_q_shift[0] ) ); // q_cldfb+temp_q_shift #else - re_aux = L_shl( Real_aux_fx, sub( temp_q_shift, min_q_shift ) ); // q_cldfb+temp_q_shift - im_aux = L_shl( Imag_aux_fx, sub( temp_q_shift, min_q_shift ) ); // q_cldfb+temp_q_shift + re_aux = L_shl( Real_aux_fx, sub( temp_q_shift, min_q_shift ) ); // q_cldfb+temp_q_shift + im_aux = L_shl( Imag_aux_fx, sub( temp_q_shift, min_q_shift ) ); // q_cldfb+temp_q_shift #endif sum_power_fx = Madd_32_32( Mpy_32_32( re_aux, re_aux ), im_aux, im_aux ); // 2*(q_cldfb+temp_q_shift)-31 @@ -2216,7 +2230,7 @@ void protoSignalComputation2_fx( move32(); } #else - temp = Mpy_32_32( a_fx, W_extract_l( W_shr( reference_power_64fx[l], 31 ) ) ); // 2*(q_cldfb+min_q_shift) -31 + temp = Mpy_32_32( a_fx, W_extract_l( W_shr( reference_power_64fx[l], 31 ) ) ); // 2*(q_cldfb+min_q_shift) -31 IF( LT_16( q_temp, stereo_type_detect->q_total_power ) ) { stereo_type_detect->total_power_fx[l] = L_add( temp, L_shr( Mpy_32_32( b_fx, stereo_type_detect->total_power_fx[l] ), sub( stereo_type_detect->q_total_power, q_temp ) ) ); // q_temp @@ -2704,15 +2718,16 @@ void protoSignalComputation2_fx( lr_total_bb_ratio_fx = Mpy_32_16_1( temp, 20480 ); // Q21 #ifdef FIX_867_CLDFB_NRG_SCALE - stereo_type_detect->left_hi_power_fx = BASOP_Util_Add_Mant32Exp( Mpy_32_32( a2_fx, left_hi_power_fx ), sub( 31, q_temp_total ), Mpy_32_32( b2_fx, stereo_type_detect->left_hi_power_fx ), sub( 31, stereo_type_detect->q_left_hi_power ), &stereo_type_detect->q_left_hi_power ); + stereo_type_detect->left_hi_power_fx = BASOP_Util_Add_Mant32Exp( Mpy_32_32( a2_fx, left_hi_power_fx ), exp_left_hi_power, Mpy_32_32( b2_fx, stereo_type_detect->left_hi_power_fx ), sub( 31, stereo_type_detect->q_left_hi_power ), &stereo_type_detect->q_left_hi_power ); move32(); stereo_type_detect->q_left_hi_power = sub( 31, stereo_type_detect->q_left_hi_power ); move16(); - stereo_type_detect->right_hi_power_fx = BASOP_Util_Add_Mant32Exp( Mpy_32_32( a2_fx, right_hi_power_fx ), sub( 31, q_temp_total ), Mpy_32_32( b2_fx, stereo_type_detect->right_hi_power_fx ), sub( 31, stereo_type_detect->q_right_hi_power ), &stereo_type_detect->q_right_hi_power ); + + stereo_type_detect->right_hi_power_fx = BASOP_Util_Add_Mant32Exp( Mpy_32_32( a2_fx, right_hi_power_fx ), exp_right_hi_power, Mpy_32_32( b2_fx, stereo_type_detect->right_hi_power_fx ), sub( 31, stereo_type_detect->q_right_hi_power ), &stereo_type_detect->q_right_hi_power ); move32(); stereo_type_detect->q_right_hi_power = sub( 31, stereo_type_detect->q_right_hi_power ); move16(); - stereo_type_detect->total_hi_power_fx = BASOP_Util_Add_Mant32Exp( Mpy_32_32( a2_fx, total_hi_power_fx ), sub( 31, q_temp_total ), Mpy_32_32( b2_fx, stereo_type_detect->total_hi_power_fx ), sub( 31, stereo_type_detect->q_total_hi_power ), &stereo_type_detect->q_total_hi_power ); + stereo_type_detect->total_hi_power_fx = BASOP_Util_Add_Mant32Exp( Mpy_32_32( a2_fx, total_hi_power_fx ), exp_total_hi_power, Mpy_32_32( b2_fx, stereo_type_detect->total_hi_power_fx ), sub( 31, stereo_type_detect->q_total_hi_power ), &stereo_type_detect->q_total_hi_power ); move32(); #else stereo_type_detect->left_hi_power_fx = BASOP_Util_Add_Mant32Exp( Mpy_32_32( a2_fx, left_hi_power_fx ), sub( 31, q_temp ), Mpy_32_32( b2_fx, stereo_type_detect->left_hi_power_fx ), sub( 31, stereo_type_detect->q_left_hi_power ), &stereo_type_detect->q_left_hi_power ); -- GitLab From 6c05b75d00462181e32686beb85e777c53c5332f Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Thu, 15 May 2025 17:49:55 +0530 Subject: [PATCH 066/113] Fix for 3GPP issue 1517: SBA Decoder: Differences for binaural rendered signals at 64 kbit/s Link #1517 --- lib_rend/ivas_dirac_dec_binaural_functions_fx.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib_rend/ivas_dirac_dec_binaural_functions_fx.c b/lib_rend/ivas_dirac_dec_binaural_functions_fx.c index c47052d5f..9ea964bcb 100644 --- a/lib_rend/ivas_dirac_dec_binaural_functions_fx.c +++ b/lib_rend/ivas_dirac_dec_binaural_functions_fx.c @@ -1265,12 +1265,14 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric temp64 = W_add( W_mult0_32_32( tempRe, tempRe ), W_mult0_32_32( tempIm, tempIm ) ); // 2q exp1 = W_norm( temp64 ); temp64 = W_shl( temp64, exp1 ); // 2q + exp1 - subFrameSumEne_fx[bin] = BASOP_Util_Add_Mant32Exp( subFrameSumEne_fx[bin], subFrameTotalEne_e[bin], W_extract_h( temp64 ), sub( exp /* 63 - 2q */, exp1 ) /*31 - (2q + exp1 - 32)*/, &subFrameTotalEne_e[bin] ); + subFrameSumEne_fx[bin] = BASOP_Util_Add_Mant32Exp( subFrameSumEne_fx[bin], subFrameSumEne_e[bin], W_extract_h( temp64 ), sub( exp /* 63 - 2q */, exp1 ) /*31 - (2q + exp1 - 32)*/, &subFrameSumEne_e[bin] ); move32(); } } FOR( bin = 0; bin < nBins; bin++ ) { + subFrameTotalEne_e[bin] = sub( subFrameTotalEne_e[bin], 1 ); + move16(); temp = L_shl_sat( subFrameTotalEne_fx[bin], sub( subFrameTotalEne_e[bin], subFrameSumEne_e[bin] ) ); // subFrameSumEne_e[bin] IF( GT_32( subFrameSumEne_fx[bin], temp ) ) { -- GitLab From 15b9ec52fb8fdfa82c596a8ac8764ef3bf86c44b Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Mon, 19 May 2025 11:35:14 +0530 Subject: [PATCH 067/113] Removal of unused float functions and replacing C datatypes with Basop Datatypes --- lib_com/bitstream.c | 66 ++--- lib_com/core_com_config.c | 6 +- lib_com/ivas_cnst.h | 8 +- lib_com/longarith.c | 4 +- lib_com/prot_fx.h | 463 +++++++++++++------------------- lib_com/tns_base.c | 82 +----- lib_com/tools.c | 195 +++----------- lib_com/tools_fx.c | 14 +- lib_dec/dec_acelp_tcx_main_fx.c | 2 +- lib_enc/acelp_core_enc_fx.c | 3 - lib_enc/evs_enc_fx.c | 2 +- lib_enc/prot_fx_enc.h | 1 - lib_enc/rom_enc.h | 1 - lib_rend/ivas_rom_rend.h | 4 - lib_rend/ivas_rom_rend_fx.c | 36 --- 15 files changed, 290 insertions(+), 597 deletions(-) diff --git a/lib_com/bitstream.c b/lib_com/bitstream.c index d8d4563ed..385000139 100644 --- a/lib_com/bitstream.c +++ b/lib_com/bitstream.c @@ -100,7 +100,7 @@ static Word16 rate2AMRWB_IOmode( *-------------------------------------------------------------------*/ Word16 rate2EVSmode_float( const Word32 brate, /* i : bitrate */ - int16_t *is_amr_wb /* o : (flag) does the bitrate belong to AMR-WB? Can be NULL */ + Word16 *is_amr_wb /* o : (flag) does the bitrate belong to AMR-WB? Can be NULL */ ) { if ( is_amr_wb != NULL ) @@ -575,8 +575,8 @@ Word16 get_ivas_max_num_indices_fx( *-----------------------------------------------------------------------*/ /*! r: maximum number of indices */ -int16_t get_BWE_max_num_indices( - const int32_t extl_brate /* i : extensiona layer bitrate */ +Word16 get_BWE_max_num_indices( + const Word32 extl_brate /* i : extensiona layer bitrate */ ) { /* set the maximum number of indices in the BWE */ @@ -787,10 +787,10 @@ Word16 get_ivas_max_num_indices_metadata_fx( void move_indices( INDICE_HANDLE old_ind_list, /* i/o: old location of indices */ INDICE_HANDLE new_ind_list, /* i/o: new location of indices */ - const int16_t nb_indices /* i : number of moved indices */ + const Word16 nb_indices /* i : number of moved indices */ ) { - int16_t i; + Word16 i; if ( new_ind_list < old_ind_list ) { @@ -1092,14 +1092,14 @@ ivas_error push_next_bits( *-------------------------------------------------------------------*/ /*! r: result: index of the indice in the list, -1 if not found */ -int16_t find_indice( +Word16 find_indice( BSTR_ENC_HANDLE hBstr, /* i : encoder bitstream handle */ - const int16_t id, /* i : ID of the indice */ - uint16_t *value, /* o : value of the quantized indice */ - int16_t *nb_bits /* o : number of bits used to quantize the indice */ + const Word16 id, /* i : ID of the indice */ + UWord16 *value, /* o : value of the quantized indice */ + Word16 *nb_bits /* o : number of bits used to quantize the indice */ ) { - int16_t i; + Word16 i; for ( i = 0; i < hBstr->nb_ind_tot; i++ ) { @@ -1122,12 +1122,12 @@ int16_t find_indice( *-------------------------------------------------------------------*/ /*! r: number of deleted indices */ -uint16_t delete_indice( +UWord16 delete_indice( BSTR_ENC_HANDLE hBstr, /* i : encoder bitstream handle */ - const int16_t id /* i : ID of the indice */ + const Word16 id /* i : ID of the indice */ ) { - int16_t i, j; + Word16 i, j; j = 0; for ( i = 0; i < hBstr->nb_ind_tot; i++ ) @@ -1168,14 +1168,14 @@ uint16_t delete_indice( *-------------------------------------------------------------------*/ /*! r: value of the indice */ -uint16_t get_next_indice( +UWord16 get_next_indice( Decoder_State *st, /* i/o: decoder state structure */ - int16_t nb_bits /* i : number of bits that were used to quantize the indice */ + Word16 nb_bits /* i : number of bits that were used to quantize the indice */ ) { - uint16_t value; - int16_t i; - int32_t nbits_total; + UWord16 value; + Word16 i; + Word32 nbits_total; assert( nb_bits <= 16 ); @@ -1207,11 +1207,11 @@ uint16_t get_next_indice( *-------------------------------------------------------------------*/ /*! r: value of the indice */ -uint16_t get_next_indice_1( +UWord16 get_next_indice_1( Decoder_State *st /* i/o: decoder state structure */ ) { - int32_t nbits_total; + Word32 nbits_total; nbits_total = st->total_brate / FRAMES_PER_SEC; /* detect corrupted bitstream */ if ( ( st->next_bit_pos + 1 > nbits_total && st->codec_mode == MODE1 ) || @@ -1233,7 +1233,7 @@ uint16_t get_next_indice_1( void get_next_indice_tmp( Decoder_State *st, /* o : decoder state structure */ - int16_t nb_bits /* i : number of bits that were used to quantize the indice */ + Word16 nb_bits /* i : number of bits that were used to quantize the indice */ ) { /* update the position in the bitstream */ @@ -1249,15 +1249,15 @@ void get_next_indice_tmp( *-------------------------------------------------------------------*/ /*! r: value of the indice */ -uint16_t get_indice( +UWord16 get_indice( Decoder_State *st, /* i/o: decoder state structure */ - int16_t pos, /* i : absolute position in the bitstream (update after the read) */ - int16_t nb_bits /* i : number of bits that were used to quantize the indice */ + Word16 pos, /* i : absolute position in the bitstream (update after the read) */ + Word16 nb_bits /* i : number of bits that were used to quantize the indice */ ) { - uint16_t value; - int16_t i; - int32_t nbits_total; + UWord16 value; + Word16 i; + Word32 nbits_total; assert( nb_bits <= 16 ); @@ -1584,9 +1584,9 @@ ivas_error write_indices_ivas_fx( *-------------------------------------------------------------------*/ static void decoder_selectCodec( - Decoder_State *st, /* i/o: decoder state structure */ - const int32_t total_brate, /* i : total bitrate */ - const int16_t bit0 /* i : first bit */ + Decoder_State *st, /* i/o: decoder state structure */ + const Word32 total_brate, /* i : total bitrate */ + const Word16 bit0 /* i : first bit */ ) { /* set the AMR-WB IO flag */ @@ -1724,7 +1724,7 @@ void ivas_set_bitstream_pointers( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ) { - int16_t k, num_bits; + Word16 k, num_bits; Decoder_State **sts; num_bits = 0; @@ -1734,7 +1734,7 @@ void ivas_set_bitstream_pointers( { sts = st_ivas->hSCE[k]->hCoreCoder; sts[0]->bit_stream = st_ivas->bit_stream + num_bits; - num_bits += (int16_t) ( st_ivas->hSCE[k]->element_brate / FRAMES_PER_SEC ); + num_bits += (Word16) ( st_ivas->hSCE[k]->element_brate / FRAMES_PER_SEC ); } /* set bitstream pointers for CPEs */ @@ -1742,7 +1742,7 @@ void ivas_set_bitstream_pointers( { sts = st_ivas->hCPE[k]->hCoreCoder; sts[0]->bit_stream = st_ivas->bit_stream + num_bits; - num_bits += (int16_t) ( st_ivas->hCPE[k]->element_brate / FRAMES_PER_SEC ); + num_bits += (Word16) ( st_ivas->hCPE[k]->element_brate / FRAMES_PER_SEC ); } return; diff --git a/lib_com/core_com_config.c b/lib_com/core_com_config.c index f75f28a18..152870be7 100644 --- a/lib_com/core_com_config.c +++ b/lib_com/core_com_config.c @@ -492,12 +492,12 @@ Word16 sr2fscale_fx( return extract_l( Mpy_32_16_1( sr_core, FSCALE_DENOM_BY_12800_Q15 ) ); /*Q0*/ } -int16_t sr2fscale( - const int32_t sr_core /* i : internal sampling rate */ +Word16 sr2fscale( + const Word32 sr_core /* i : internal sampling rate */ ) { - return (int16_t) ( ( FSCALE_DENOM * sr_core ) / 12800 ); + return (Word16) ( ( FSCALE_DENOM * sr_core ) / 12800 ); } Word32 getCoreSamplerateMode2( diff --git a/lib_com/ivas_cnst.h b/lib_com/ivas_cnst.h index 9243b3f50..097ba1789 100644 --- a/lib_com/ivas_cnst.h +++ b/lib_com/ivas_cnst.h @@ -509,8 +509,8 @@ enum #define STEREO_DFT32MS_N_NS FRAME_SIZE_NS /* 20 ms */ #define STEREO_DFT32MS_OVL_NS 3125000L /* 3.125ms - Overlap for the outer edges of windows on decoder */ #define STEREO_DFT32MS_OVL2_NS 9375000L /* 9.375ms - Overlap for the inner edges of windows on decoder */ -#define STEREO_DFT32MS_WIN_CENTER_NS ( int32_t )( ( FRAME_SIZE_NS + STEREO_DFT32MS_OVL_NS ) * 0.5f ) /* 11.5625ms - mid point of the two windows wrt the left edge of overlap */ -#define STEREO_DFT32MS_ZP_NS ( int32_t )( 0.5f * ( STEREO_DFT32MS_N_NS - STEREO_DFT32MS_WIN_CENTER_NS - ( STEREO_DFT32MS_OVL2_NS * 0.5f ) ) ) /* 2 sided zp calculated such that window size is satisfied */ +#define STEREO_DFT32MS_WIN_CENTER_NS ( Word32 )( ( FRAME_SIZE_NS + STEREO_DFT32MS_OVL_NS ) * 0.5f ) /* 11.5625ms - mid point of the two windows wrt the left edge of overlap */ +#define STEREO_DFT32MS_ZP_NS ( Word32 )( 0.5f * ( STEREO_DFT32MS_N_NS - STEREO_DFT32MS_WIN_CENTER_NS - ( STEREO_DFT32MS_OVL2_NS * 0.5f ) ) ) /* 2 sided zp calculated such that window size is satisfied */ #define STEREO_DFT32MS_OVL_MAX NS2SA( 48000, STEREO_DFT32MS_OVL_NS ) #define STEREO_DFT32MS_OVL2_MAX NS2SA( 48000, STEREO_DFT32MS_OVL2_NS ) @@ -799,7 +799,7 @@ enum fea_names #define L_DEC_MEM_LEN_ICA L_NCSHIFTMAX + ( N_MAX_SHIFT_CHANGE + 1 ) + SINC_ORDER1 / INTERP_FACTOR1 #define L_FRAME_DS NS2SA( CORR_INTER_FS, FRAME_SIZE_NS ) #define L_XCORRMEM_DS NS2SA( CORR_INTER_FS, 2 * ( ACELP_LOOK_NS ) ) -#define L_NCSHIFT_DS ( int16_t )( ( ( int32_t )(CORR_INTER_FS) *L_NCSHIFTMAX ) / 48000L ) +#define L_NCSHIFT_DS ( Word16 )( ( ( Word32 )(CORR_INTER_FS) *L_NCSHIFTMAX ) / 48000L ) #define L_SAMPLES_LA_NS 625000L #define L_MEM_RECALC_TBE_16K NS2SA( 16000, L_MEM_RECALC_TBE_NS ) @@ -1446,7 +1446,7 @@ typedef struct { typedef struct { Word32 value[81]; - unsigned short length[81]; + UWord16 length[81]; } HUFF_ELEMENTS; typedef struct { diff --git a/lib_com/longarith.c b/lib_com/longarith.c index 72a763de3..c5ace652c 100644 --- a/lib_com/longarith.c +++ b/lib_com/longarith.c @@ -64,14 +64,14 @@ void longadd( assert( lena >= lenb ); for ( h = 0; h < lenb; h++ ) { - carry += ( (uint32_t) a[h] ) + ( (uint32_t) b[h] ); + carry += ( (UWord32) a[h] ) + ( (UWord32) b[h] ); a[h] = (UWord16) carry; carry = carry >> 16; } for ( ; h < lena; h++ ) { - carry = ( (uint32_t) a[h] ) + carry; + carry = ( (UWord32) a[h] ) + carry; a[h] = (UWord16) carry; carry = carry >> 16; } diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 85ece0cab..f833640e0 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -72,9 +72,6 @@ #define max( x, y ) ( ( x ) > ( y ) ? ( x ) : ( y ) ) #endif -#define log_base_2( x ) ( (double) log( (double) ( x ) ) * 1.4426950408889634074f ) -#define round_f( x ) ( ( ( x ) > 0 ) ? (int32_t) ( ( x ) + 0.5f ) : ( -(int32_t) ( ( -x ) + 0.5f ) ) ) - #ifndef ABSVAL #define ABSVAL( a ) ( ( a ) >= 0 ? ( a ) : ( -( a ) ) ) #endif @@ -1576,19 +1573,19 @@ Word16 gsc_gainQ_fx( ); Word16 gsc_gainQ_ivas_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - const int16_t element_mode, /* i : element mode */ - const int16_t idchan, /* i : channel ID */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const Word16 element_mode, /* i : element mode */ + const Word16 idchan, /* i : channel ID */ const Word16 y_gain4[], /* i : Energy per band */ // Q12 Word16 y_gainQ[], /* o : quantized energy per band */ // Q12 - const int32_t core_brate, /* i : Core rate */ - const int16_t coder_type, /* i : coding type */ - const int16_t bwidth, /* i : input signal bandwidth */ - const int16_t L_frame, /* i : frame length */ - const int16_t tdm_LRTD_flag, /* i : LRTD stereo mode flag */ - const int32_t core_brate_inp /* i : true core bitrate */ + const Word32 core_brate, /* i : Core rate */ + const Word16 coder_type, /* i : coding type */ + const Word16 bwidth, /* i : input signal bandwidth */ + const Word16 L_frame, /* i : frame length */ + const Word16 tdm_LRTD_flag, /* i : LRTD stereo mode flag */ + const Word32 core_brate_inp /* i : true core bitrate */ ); // frame_ener.c @@ -1779,7 +1776,7 @@ void Ener_per_band_comp_ivas_fx( const Word16 Q_exc, /* i : frame length */ const Word16 Mband, /* i : Max band */ const Word16 Eflag, /* i : flag of highest band */ - const int16_t L_frame /* i : frame length */ + const Word16 L_frame /* i : frame length */ ); void Ener_per_band_comp_ivas_fx_2( const Word16 exc_diff_fx[], /* i : target signal Q_exc_diff */ @@ -2633,7 +2630,7 @@ void Interpolate_allpass_steep_fx( void Interpolate_allpass_steep_fx32( const Word32 *in_fx, /* i : input array of size N */ Word32 *mem_fx, /* i/o: memory */ - const int16_t N, /* i : number of input samples */ + const Word16 N, /* i : number of input samples */ Word32 *out_fx /* o : output array of size 2*N */ ); @@ -2647,7 +2644,7 @@ void interpolate_3_over_2_allpass_fx( void interpolate_3_over_2_allpass_fx32( const Word32 *input, /* i : input signal Qx */ - const int16_t len, /* i : number of input samples */ + const Word16 len, /* i : number of input samples */ Word32 *out, /* o : output signal */ Word32 *mem /* i/o: memory */ ); @@ -2931,16 +2928,16 @@ void tbe_celp_exc( ); void tbe_celp_exc_ivas( - const int16_t element_mode, /* i : element mode */ - const int16_t idchan, /* i : channel ID */ - const Word16 L_frame_fx, /* i : Frame lenght */ - const int16_t L_subfr, /* i : subframe length */ - const Word16 i_subfr_fx, /* i : sub frame */ - const Word16 T0_fx, /* i : Integer pitch */ - const Word16 T0_frac_fx, /* i : Fractional part of the pitch */ - Word16 *error_fx, /* i/o: Error */ - Word16 *bwe_exc_fx, /* i/o: bandwitdh extension signal */ - const int16_t tdm_LRTD_flag /* i : LRTD stereo mode flag */ + const Word16 element_mode, /* i : element mode */ + const Word16 idchan, /* i : channel ID */ + const Word16 L_frame_fx, /* i : Frame lenght */ + const Word16 L_subfr, /* i : subframe length */ + const Word16 i_subfr_fx, /* i : sub frame */ + const Word16 T0_fx, /* i : Integer pitch */ + const Word16 T0_frac_fx, /* i : Fractional part of the pitch */ + Word16 *error_fx, /* i/o: Error */ + Word16 *bwe_exc_fx, /* i/o: bandwitdh extension signal */ + const Word16 tdm_LRTD_flag /* i : LRTD stereo mode flag */ ); void flip_and_downmix_generic_fx( @@ -3159,8 +3156,8 @@ void GenSHBSynth_fx32( Word32 *shb_syn_speech_32k, /* o : output highband component */ Word32 Hilbert_Mem[], /* i/o: memory */ Word32 state_lsyn_filt_shb_local[], /* i/o: memory */ - const int16_t L_frame, /* i : ACELP frame length */ - int16_t *syn_dm_phase ); + const Word16 L_frame, /* i : ACELP frame length */ + Word16 *syn_dm_phase ); void ScaleShapedSHB_fx( const Word16 length, /* i : SHB overlap length */ @@ -3245,7 +3242,7 @@ void wb_tbe_extras_reset_synth_fx( Word16 state_lsyn_filt_shb[], Word16 state_ls #ifdef FIX_1439_SPEEDUP_SIMPLIFY_elliptic_bpf_48k_generic void elliptic_bpf_48k_generic_fx( #ifdef FIX_1439_SPEEDUP_SIMPLIFY_elliptic_bpf_48k_generic_STAGE2 - const int16_t element_mode, + const Word16 element_mode, #endif Word16 IsUpsampled3, Word16 input_fx[], /* i : input signal Q_input_fx*/ @@ -3280,7 +3277,7 @@ void synthesise_fb_high_band_fx( Word16 Qout #ifdef FIX_1439_SPEEDUP_SIMPLIFY_elliptic_bpf_48k_generic_STAGE2 , - int16_t element_mode + Word16 element_mode #endif ); @@ -3747,8 +3744,8 @@ void const *GetTnsEnabledSingleFilter( void const *p, const Word16 index, Word16 void *SetTnsEnabledSingleFilter( void *p, const Word16 index, const Word16 value ); -void const *GetTnsOnWhite( void const *p, const int16_t index, int16_t *pValue ); -void *SetTnsOnWhite( void *p, const int16_t index, const int16_t value ); +void const *GetTnsOnWhite( void const *p, const Word16 index, Word16 *pValue ); +void *SetTnsOnWhite( void *p, const Word16 index, const Word16 value ); /*tns_base.h*/ /** Reset TNS data. @@ -4113,8 +4110,8 @@ void cng_params_upd_ivas_fx( const Word16 element_mode, /* i : Element mode */ const Word16 bwidth /* i : Audio bandwidth */ ); -int16_t get_cng_mode( - const int32_t last_active_brate /* i : last active bitrate */ +Word16 get_cng_mode( + const Word32 last_active_brate /* i : last active bitrate */ ); // core_com_config.c @@ -4301,12 +4298,12 @@ void lpc2mdct( void lpc2mdct_2( Word16 *lpcCoeffs, - const int16_t lpcOrder, + const Word16 lpcOrder, Word16 mdct_gains_fx[], Word16 mdct_gains_e[], Word16 mdct_inv_gains_fx[], Word16 mdct_inv_gains_e[], - const int16_t length ); + const Word16 length ); void mdct_shaping( Word32 x[], @@ -4941,25 +4938,25 @@ void cb_shape_fx( // longarith.c void longadd( - uint16_t a[], /* i/o: vector of the length lena */ - const uint16_t b[], /* i/o: vector of the length lenb */ - const int16_t lena, /* i/o: length of vector a[] */ - const int16_t lenb /* i/o: length of vector b[] */ + UWord16 a[], /* i/o: vector of the length lena */ + const UWord16 b[], /* i/o: vector of the length lenb */ + const Word16 lena, /* i/o: length of vector a[] */ + const Word16 lenb /* i/o: length of vector b[] */ ); void longshiftright( - uint16_t a[], /* i : vector of the length lena */ - const int16_t b, /* i : number of bit positions to shift right */ - uint16_t d[], /* o : vector of the length lend */ - int16_t lena, /* i : length of vector a[] */ - const int16_t lend /* i : length of vector d[] */ + UWord16 a[], /* i : vector of the length lena */ + const Word16 b, /* i : number of bit positions to shift right */ + UWord16 d[], /* o : vector of the length lend */ + Word16 lena, /* i : length of vector a[] */ + const Word16 lend /* i : length of vector d[] */ ); void longshiftleft( - const uint16_t a[], /* i : vector of the length len */ - const int16_t b, /* i : number of bit positions to shift left */ - uint16_t d[], /* o : vector of the length len */ - const int16_t len /* i : length of vector a[] and d[] */ + const UWord16 a[], /* i : vector of the length len */ + const Word16 b, /* i : number of bit positions to shift left */ + UWord16 d[], /* o : vector of the length len */ + const Word16 len /* i : length of vector a[] and d[] */ ); void longshr( @@ -5637,7 +5634,7 @@ void enhancer_fx( void enhancer_ivas_fx( const Word16 codec_mode, /* i : flag indicating Codec Mode */ const Word32 core_brate, /* i : decoder bitrate */ - const int16_t cbk_index, /* i : */ + const Word16 cbk_index, /* i : */ const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ const Word16 coder_type, /* i : coder type */ const Word16 i_subfr, /* i : subframe number */ @@ -6398,11 +6395,11 @@ void ivas_RefineTonalComponents_fx( const PsychoacousticParameters *psychParamsCurrent ); ivas_error PsychoacousticParameters_Init( - const int32_t sr_core, /* i : sampling rate of core-coder */ - const int16_t nBins, /* i : Number of bins (spectral lines) */ - const int8_t nBands, /* i : Number of spectrum subbands */ - const int16_t isTCX20, /* i : Flag indicating if the subband division is for TCX20 or TCX10 */ - const int16_t isWarped, /* i : Flag indicating if the scale is linear or warped */ + const Word32 sr_core, /* i : sampling rate of core-coder */ + const Word16 nBins, /* i : Number of bins (spectral lines) */ + const Word8 nBands, /* i : Number of spectrum subbands */ + const Word16 isTCX20, /* i : Flag indicating if the subband division is for TCX20 or TCX10 */ + const Word16 isWarped, /* i : Flag indicating if the scale is linear or warped */ PsychoacousticParameters *pPsychParams ); // TonalIMDCTconcealment_fx.c @@ -8292,17 +8289,17 @@ Word16 FEC_synchro_exc_fx( ); void decod_unvoiced_fx( - Decoder_State *st_fx, /* i/o: decoder static memory */ - const Word16 *Aq_fx, /* Q12 i : LP filter coefficient */ - const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ - const int16_t uc_two_stage_flag, /* i : flag indicating two-stage UC */ - const Word16 coder_type, /* Q0 i : coding type */ - Word16 *tmp_noise_fx, /* Q0 o : long term temporary noise energy */ - Word16 *pitch_buf_fx, /* Q6 o : floating pitch values for each subframe*/ - Word16 *voice_factors_fx, /* Q15 o : voicing factors */ - Word16 *exc_fx, /* Q_X o : adapt. excitation exc */ - Word16 *exc2_fx, /* Q_X o : adapt. excitation/total exc */ - Word16 *bwe_exc_fx, /* Q_X i/o: excitation for SWB TBE */ + Decoder_State *st_fx, /* i/o: decoder static memory */ + const Word16 *Aq_fx, /* Q12 i : LP filter coefficient */ + const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ + const Word16 uc_two_stage_flag, /* i : flag indicating two-stage UC */ + const Word16 coder_type, /* Q0 i : coding type */ + Word16 *tmp_noise_fx, /* Q0 o : long term temporary noise energy */ + Word16 *pitch_buf_fx, /* Q6 o : floating pitch values for each subframe*/ + Word16 *voice_factors_fx, /* Q15 o : voicing factors */ + Word16 *exc_fx, /* Q_X o : adapt. excitation exc */ + Word16 *exc2_fx, /* Q_X o : adapt. excitation/total exc */ + Word16 *bwe_exc_fx, /* Q_X i/o: excitation for SWB TBE */ Word16 *gain_buf ); // gaus_dec_fx.c @@ -8486,10 +8483,10 @@ void mode_switch_decoder_LPD_ivas_fx( // ari_hm_dec.c -int16_t DecodeIndex( +Word16 DecodeIndex( Decoder_State *st, - const int16_t Bandwidth, /* o : NB, 1: (S)WB */ - int16_t *PeriodicityIndex ); + const Word16 Bandwidth, /* o : NB, 1: (S)WB */ + Word16 *PeriodicityIndex ); Word16 DecodeIndex_fx( Decoder_State *st, @@ -8566,7 +8563,7 @@ void IGFSCFDecoderReset( void IGFSCFDecoderDecode( IGFSCFDEC_INSTANCE_HANDLE hPublicData, /* i/o: handle to public data or NULL in case there was no instance created */ Decoder_State *st, /* i/o: pointer to decoder state */ - int16_t *sfe, /* o : ptr to an array which will contain the decoded quantized coefficients */ + Word16 *sfe, /* o : ptr to an array which will contain the decoded quantized coefficients */ const Word16 igfGridIdx, /* i : igf grid index see declaration of IGF_GRID_IDX for details */ const Word16 indepFlag /* i : if 1 on input the decoder will be forced to reset, if 0 on input the decoder will be forced to encode without a reset */ @@ -8694,11 +8691,11 @@ Word16 DecodeTnsData_ivas_fx( // parametr_bitmapping.c using ivas void GetParameters( ParamsBitMap const *paramsBitMap, - const int16_t nParams, + const Word16 nParams, void const *pParameter, - int16_t **pStream, - int16_t *pnSize, - int16_t *pnBits ); + Word16 **pStream, + Word16 *pnSize, + Word16 *pnBits ); void GetParameters_fx( ParamsBitMap const *paramsBitMap, @@ -8718,10 +8715,10 @@ void EncodeTnsData_ivas_fx( void SetParameters( ParamsBitMap const *paramsBitMap, - const int16_t nParams, + const Word16 nParams, void *pParameter, - const int16_t **pStream, - int16_t *pnSize ); + const Word16 **pStream, + Word16 *pnSize ); void SetParameters_fx( ParamsBitMap const *paramsBitMap, @@ -8732,18 +8729,18 @@ void SetParameters_fx( void WriteToBitstream( ParamsBitMap const *paramsBitMap, - const int16_t nParams, - const int16_t **pStream, - int16_t *pnSize, + const Word16 nParams, + const Word16 **pStream, + Word16 *pnSize, BSTR_ENC_HANDLE hBstr, - int16_t *pnBits ); + Word16 *pnBits ); void ReadFromBitstream( ParamsBitMap const *paramsBitMap, - const int16_t nArrayLength, + const Word16 nArrayLength, Decoder_State *st, - int16_t **pStream, - int16_t *pnSize ); + Word16 **pStream, + Word16 *pnSize ); void ReadFromBitstream_fx( ParamsBitMap const *paramsBitMap, @@ -9302,7 +9299,7 @@ void v_add_fx( const Word32 x1[], /* i : Input vector 1 */ const Word32 x2[], /* i : Input vector 2 */ Word32 y[], /* o : Output vector that contains vector 1 + vector 2 */ - const int16_t N /* i : Vector length */ + const Word16 N /* i : Vector length */ ); void v_shr_16( @@ -9356,10 +9353,10 @@ void configureCldfb_ivas_fx( ); // dec4t64.c void dec_acelp_fast_fx( - Decoder_State *st, /* i/o: decoder state structure */ - const int16_t cdk_index, /* i : codebook index */ - Word16 code[], /* o : algebraic (fixed) codebook excitation */ - const int16_t L_subfr /* i : subframe length */ + Decoder_State *st, /* i/o: decoder state structure */ + const Word16 cdk_index, /* i : codebook index */ + Word16 code[], /* o : algebraic (fixed) codebook excitation */ + const Word16 L_subfr /* i : subframe length */ ); // codec_tcx_common.c void tcx5SpectrumInterleaving_fx( @@ -9397,7 +9394,7 @@ void cldfbAnalysis_ivas_fx( const Word32 *timeIn_fx, /* i : time buffer Qx */ Word32 **realBuffer_fx, /* o : real value buffer Qx - 5*/ Word32 **imagBuffer_fx, /* o : imag value buffer QX - 5*/ - const int16_t samplesToProcess, /* i : samples to process */ + const Word16 samplesToProcess, /* i : samples to process */ HANDLE_CLDFB_FILTER_BANK h_cldfb /* i : filterbank state */ ); @@ -9416,7 +9413,7 @@ void cldfbSynthesis_ivas_fx( // bass_psfilter.c void addBassPostFilter_ivas_fx( const Word32 *harm_timeIn_fx, - const int16_t samplesToProcess, + const Word16 samplesToProcess, Word32 **rAnalysis_fx, Word32 **iAnalysis_fx, HANDLE_CLDFB_FILTER_BANK cldfb ); @@ -9590,8 +9587,8 @@ void fd_bwe_dec_init_fx( void stereo_dft_dec_open( STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder DFT stereo handle */ - const int32_t output_Fs, /* i : output sampling rate */ - const int16_t nchan_transport /* i : number of transport channels */ + const Word32 output_Fs, /* i : output sampling rate */ + const Word16 nchan_transport /* i : number of transport channels */ ); void ivas_bw_switching_pre_proc_fx( @@ -10287,8 +10284,8 @@ void dctT2_N_apply_matrix_fx( ); Word32 sum2_f_32_fx( - const Word32 *vec, /* i : input vector */ - const int16_t lvec, /* i : length of input vector */ + const Word32 *vec, /* i : input vector */ + const Word16 lvec, /* i : length of input vector */ Word16 gb ); Word32 sum2_32_fx( @@ -10438,10 +10435,10 @@ void generate_stereo_masking_noise_fx( Word16 Q_syn, Decoder_State *st, /* i/o: decoder state structure */ STEREO_TD_DEC_DATA_HANDLE hStereoTD, /* i : TD stereo structure */ - const int16_t flag_sec_CNA, /* i : CNA flag for secondary channel */ - const int16_t fadeOut, /* i : only fade out of previous state */ + const Word16 flag_sec_CNA, /* i : CNA flag for secondary channel */ + const Word16 fadeOut, /* i : only fade out of previous state */ STEREO_CNG_DEC_HANDLE hStereoCng, /* i : Stereo CNG handle */ - const int16_t nchan_out /* i : number of output channels */ + const Word16 nchan_out /* i : number of output channels */ ); void SynthesisSTFT_fx( @@ -10449,10 +10446,10 @@ void SynthesisSTFT_fx( Word32 *timeDomainOutput, Word32 *olapBuffer, const Word16 *olapWin, - const int16_t tcx_transition, + const Word16 tcx_transition, HANDLE_FD_CNG_COM hFdCngCom, /* i/o: FD_CNG structure containing all buffers and variables */ - const int16_t element_mode, /* i : element mode */ - const int16_t nchan_out /* i : number of output channels */ + const Word16 element_mode, /* i : element mode */ + const Word16 nchan_out /* i : number of output channels */ ); void FdCng_decodeSID_ivas_fx( @@ -10834,7 +10831,7 @@ Word16 msvq_stage1_dct_recalc_candidates_fdcng_wb_fx( const Word16 st1_syn_vec_e, /* i : exp for IDCT24 synthesis vectors */ const Word32 *u_fx, /* i : target signal */ const Word16 u_e, /* i : exp for target signal */ - const int16_t maxC_st1, /* i : number of candidates in stage1 */ + const Word16 maxC_st1, /* i : number of candidates in stage1 */ Word32 *dist_ptr_fx, /* i/o: updated MSE vector for stage1 */ Word16 *dist_ptr_e /* i/o: exp for updated MSE vector for stage1 */ ); @@ -10907,69 +10904,42 @@ void WriteToBitstream_ivas_fx( * MODE1 prototypes *----------------------------------------------------------------------------------*/ -/*! r: inverse square root of input value */ -float inv_sqrt( - const float x /* i : input value */ -); - /*! r: output random value */ -int16_t own_random( - int16_t *seed /* i/o: random seed */ -); - -/*! r: sign of x (+1/-1) */ -float sign( - const float x /* i : input value of x */ +Word16 own_random( + Word16 *seed /* i/o: random seed */ ); -/*! r: logarithm2 of x */ -float log2_f( - const float x /* i : input value of x */ -); - -int16_t norm_ul_float( - uint32_t UL_var1 ); +Word16 norm_ul_float( + UWord32 UL_var1 ); /*! r: sum of all vector elements */ -int16_t sum_s( - const int16_t *vec, /* i : input vector */ - const int16_t lvec /* i : length of input vector */ +Word16 sum_s( + const Word16 *vec, /* i : input vector */ + const Word16 lvec /* i : length of input vector */ ); /*! r: sum of all vector elements */ -int32_t sum_l( - const int32_t *vec, /* i : input vector */ - const int16_t lvec /* i : length of input vector */ -); - -/*! r: sum of all squared vector elements */ -float sum2_f( - const float *vec, /* i : input vector */ - const int16_t lvec /* i : length of input vector */ +Word32 sum_l( + const Word32 *vec, /* i : input vector */ + const Word16 lvec /* i : length of input vector */ ); void set_c( - int8_t y[], /* i/o: Vector to set */ - const int8_t a, /* i : Value to set the vector to */ - const int32_t N /* i : Length of the vector */ + Word8 y[], /* i/o: Vector to set */ + const Word8 a, /* i : Value to set the vector to */ + const Word32 N /* i : Length of the vector */ ); void set_s( - int16_t y[], /* i/o: Vector to set */ - const int16_t a, /* i : Value to set the vector to */ - const int16_t N /* i : Lenght of the vector */ + Word16 y[], /* i/o: Vector to set */ + const Word16 a, /* i : Value to set the vector to */ + const Word16 N /* i : Lenght of the vector */ ); void set_l( - int32_t y[], /* i/o: Vector to set */ - const int32_t a, /* i : Value to set the vector to */ - const int16_t N /* i : Length of the vector */ -); - -void set_f( - float y[], /* i/o: Vector to set */ - const float a, /* i : Value to set the vector to */ - const int16_t N /* i : Lenght of the vector */ + Word32 y[], /* i/o: Vector to set */ + const Word32 a, /* i : Value to set the vector to */ + const Word16 N /* i : Length of the vector */ ); void set_zero_fx( @@ -10986,52 +10956,26 @@ void set16_zero_fx( ); void set_zero( - float *vec, /* o : input vector */ - const int16_t lvec /* i : length of the vector */ + float *vec, /* o : input vector */ + const Word16 lvec /* i : length of the vector */ ); void mvr2r( const float x[], /* i : input vector */ float y[], /* o : output vector */ - const int16_t n /* i : vector size */ + const Word16 n /* i : vector size */ ); void mvs2s( - const int16_t x[], /* i : input vector */ - int16_t y[], /* o : output vector */ - const int16_t n /* i : vector size */ -); - -uint32_t mvr2s( - const float x[], /* i : input vector */ - int16_t y[], /* o : output vector */ - const int16_t n /* i : vector size */ -); - -void mvs2r( - const int16_t x[], /* i : input vector */ - float y[], /* o : output vector */ - const int16_t n /* i : vector size */ + const Word16 x[], /* i : input vector */ + Word16 y[], /* o : output vector */ + const Word16 n /* i : vector size */ ); void mvl2l( - const int32_t x[], /* i : input vector */ - int32_t y[], /* o : output vector */ - const int16_t n /* i : vector size */ -); - - -/*! r: index of the maximum value in the input vector */ -int16_t maximum( - const float *vec, /* i : input vector */ - const int16_t lvec, /* i : length of input vector */ - float *max_val /* o : maximum value in the input vector */ -); -/*! r: index of the maximum value in the input vector */ -int16_t maximumAbs( - const float *vec, /* i : input vector */ - const int16_t lvec, /* i : length of input vector */ - float *max_val /* o : maximum value in the input vector */ + const Word32 x[], /* i : input vector */ + Word32 y[], /* o : output vector */ + const Word16 n /* i : vector size */ ); Word16 maximumAbs_l( @@ -11041,63 +10985,22 @@ Word16 maximumAbs_l( ); /*! r: index of the minimum value in the input vector */ -int16_t minimum( - const float *vec, /* i : input vector */ - const int16_t lvec, /* i : length of input vector */ - float *min_val /* o : minimum value in the input vector */ -); - -/*! r: index of the minimum value in the input vector */ -int16_t minimum_s( - const int16_t *vec, /* i : Input vector */ - const int16_t lvec, /* i : Vector length */ - int16_t *min_val /* o : minimum value in the input vector */ -); - -/*! r: return index with max energy value in vector */ -int16_t emaximum( - const float *vec, /* i : input vector */ - const int16_t lvec, /* i : length of input vector */ - float *ener_max /* o : maximum energy value */ -); - -/*! r: vector mean */ -float mean( - const float *vec, /* i : input vector */ - const int16_t lvec /* i : length of input vector */ -); - -/*! r: dot product of x[] and y[] */ -float dotp( - const float x[], /* i : vector x[] */ - const float y[], /* i : vector y[] */ - const int16_t n /* i : vector length */ -); - -void v_add( - const float x1[], /* i : Input vector 1 */ - const float x2[], /* i : Input vector 2 */ - float y[], /* o : Output vector that contains vector 1 + vector 2 */ - const int16_t N /* i : Vector length */ -); - -void v_sub( - const float x1[], /* i : Input vector 1 */ - const float x2[], /* i : Input vector 2 */ - float y[], /* o : Output vector that contains vector 1 - vector 2 */ - const int16_t N /* i : Vector length */ +Word16 minimum_s( + const Word16 *vec, /* i : Input vector */ + const Word16 lvec, /* i : Vector length */ + Word16 *min_val /* o : minimum value in the input vector */ ); /*! r: dequanzited gain */ float usdequant( - const int16_t idx, /* i : quantizer index */ - const float qlow, /* i : lowest codebook entry (index 0) */ - const float delta /* i : quantization step */ + const Word16 idx, /* i : quantizer index */ + const float qlow, /* i : lowest codebook entry (index 0) */ + const float delta /* i : quantization step */ ); void sort( - uint16_t *x, /* i/o: Vector to be sorted */ - uint16_t len /* i/o: vector length */ + UWord16 *x, /* i/o: Vector to be sorted */ + UWord16 len /* i/o: vector length */ ); void sort_l( @@ -11108,9 +11011,9 @@ void sort_l( ivas_error push_indice( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - int16_t id, /* i : ID of the indice */ - uint16_t value, /* i : value of the quantized indice */ - int16_t nb_bits /* i : number of bits used to quantize the indice */ + Word16 id, /* i : ID of the indice */ + UWord16 value, /* i : value of the quantized indice */ + Word16 nb_bits /* i : number of bits used to quantize the indice */ ); ivas_error push_next_indice( @@ -11132,8 +11035,8 @@ Word16 get_ivas_max_num_indices_fx( ); /*! r: maximum number of indices */ -int16_t get_BWE_max_num_indices( - const int32_t extl_brate /* i : extensiona layer bitrate */ +Word16 get_BWE_max_num_indices( + const Word32 extl_brate /* i : extensiona layer bitrate */ ); /*! r: maximum number of indices */ @@ -11142,9 +11045,9 @@ Word16 get_ivas_max_num_indices_metadata_fx( const Word32 ivas_total_brate /* i : IVAS total bitrate */ ); ivas_error ind_list_realloc( - INDICE_HANDLE old_ind_list, /* i : pointer to the beginning of the old buffer of indices */ - const int16_t max_num_indices, /* i : new maximum number of allowed indices in the list */ - Encoder_Struct *st_ivas /* i : IVAS encoder structure */ + INDICE_HANDLE old_ind_list, /* i : pointer to the beginning of the old buffer of indices */ + const Word16 max_num_indices, /* i : new maximum number of allowed indices in the list */ + Encoder_Struct *st_ivas /* i : IVAS encoder structure */ ); ivas_error check_ind_list_limits( @@ -11154,44 +11057,44 @@ ivas_error check_ind_list_limits( void move_indices( INDICE_HANDLE old_ind_list, /* i/o: old location of indices */ INDICE_HANDLE new_ind_list, /* i/o: new location of indices */ - const int16_t nb_indices /* i : number of moved indices */ + const Word16 nb_indices /* i : number of moved indices */ ); /*! r: index of the indice in the list, -1 if not found */ -int16_t find_indice( +Word16 find_indice( BSTR_ENC_HANDLE hBstr, /* i : encoder bitstream handle */ - const int16_t id, /* i : ID of the indice */ - uint16_t *value, /* o : value of the quantized indice */ - int16_t *nb_bits /* o : number of bits used to quantize the indice */ + const Word16 id, /* i : ID of the indice */ + UWord16 *value, /* o : value of the quantized indice */ + Word16 *nb_bits /* o : number of bits used to quantize the indice */ ); /*! r: number of deleted indices */ -uint16_t delete_indice( +UWord16 delete_indice( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - const int16_t id /* i : ID of the indice */ + const Word16 id /* i : ID of the indice */ ); /*! r: value of the indice */ -uint16_t get_next_indice( +UWord16 get_next_indice( Decoder_State *st, /* i/o: decoder state structure */ - int16_t nb_bits /* i : number of bits that were used to quantize the indice */ + Word16 nb_bits /* i : number of bits that were used to quantize the indice */ ); /*! r: value of the indice */ -uint16_t get_next_indice_1( +UWord16 get_next_indice_1( Decoder_State *st /* i/o: decoder state structure */ ); void get_next_indice_tmp( Decoder_State *st, /* o : decoder state structure */ - int16_t nb_bits /* i : number of bits that were used to quantize the indice */ + Word16 nb_bits /* i : number of bits that were used to quantize the indice */ ); /*! r: value of the indice */ -uint16_t get_indice( +UWord16 get_indice( Decoder_State *st, /* i/o: decoder state structure */ - int16_t pos, /* i : absolute position in the bitstream */ - int16_t nb_bits /* i : number of bits that were used to quantize the indice */ + Word16 pos, /* i : absolute position in the bitstream */ + Word16 nb_bits /* i : number of bits that were used to quantize the indice */ ); void reset_indices_dec( @@ -11200,7 +11103,7 @@ void reset_indices_dec( Word16 rate2EVSmode_float( const Word32 brate, /* i : bitrate */ - int16_t *is_amr_wb /* o : (flag) does the bitrate belong to AMR-WB? Can be NULL */ + Word16 *is_amr_wb /* o : (flag) does the bitrate belong to AMR-WB? Can be NULL */ ); @@ -11227,13 +11130,13 @@ void mdct_switching_dec_fx( Decoder_State *st /* i/o: decoder state structure */ ); -int16_t print_disclaimer( +Word16 print_disclaimer( FILE *fPtr ); void fft_rel( - float x[], /* i/o: input/output vector */ - const int16_t n, /* i : vector length */ - const int16_t m /* i : log2 of vector length */ + float x[], /* i/o: input/output vector */ + const Word16 n, /* i : vector length */ + const Word16 m /* i : log2 of vector length */ ); void preemph_ivas_fx( @@ -11246,8 +11149,8 @@ void preemph_ivas_fx( void create_offset( UWord32 *offset_scale1, UWord32 *offset_scale2, - const int16_t mode, - const int16_t prediction_flag ); + const Word16 mode, + const Word16 prediction_flag ); void BASOP_cfft_ivas( Word32 *re, /* i/o: real part */ @@ -11492,31 +11395,31 @@ void writeTCXWindowing_fx( ); void writeLPCparam( - Encoder_State *st, /* i/o: encoder state structure */ - BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */ - const int16_t param_lpc[], /* i : LPC parameters to write */ - const int16_t bits_param_lpc[], /* i : bits per LPC parameter */ - const int16_t no_param_lpc, /* i : number of LPC parameters */ - int16_t *nbits_lpc /* o : LPC bits written */ + Encoder_State *st, /* i/o: encoder state structure */ + BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */ + const Word16 param_lpc[], /* i : LPC parameters to write */ + const Word16 bits_param_lpc[], /* i : bits per LPC parameter */ + const Word16 no_param_lpc, /* i : number of LPC parameters */ + Word16 *nbits_lpc /* o : LPC bits written */ ); -void const *GetTnsOnWhite( void const *p, const int16_t index, int16_t *pValue ); -void *SetTnsOnWhite( void *p, const int16_t index, const int16_t value ); -void const *GetNumOfTnsFilters_flt( void const *p, const int16_t index, int16_t *pValue ); -void *SetNumOfTnsFilters_flt( void *p, const int16_t index, const int16_t value ); +void const *GetTnsOnWhite( void const *p, const Word16 index, Word16 *pValue ); +void *SetTnsOnWhite( void *p, const Word16 index, const Word16 value ); +void const *GetNumOfTnsFilters_flt( void const *p, const Word16 index, Word16 *pValue ); +void *SetNumOfTnsFilters_flt( void *p, const Word16 index, const Word16 value ); -int16_t DecodeSWBTCX10TnsFilterCoeff_flt( Decoder_State *st, const int16_t index, int16_t *pValue ); -int16_t DecodeSWBTCX20TnsFilterCoeff_flt( Decoder_State *st, const int16_t index, int16_t *pValue ); +Word16 DecodeSWBTCX10TnsFilterCoeff_flt( Decoder_State *st, const Word16 index, Word16 *pValue ); +Word16 DecodeSWBTCX20TnsFilterCoeff_flt( Decoder_State *st, const Word16 index, Word16 *pValue ); -int16_t DecodeWBTCX20TnsFilterCoeff_flt( Decoder_State *st, const int16_t index, int16_t *pValue ); +Word16 DecodeWBTCX20TnsFilterCoeff_flt( Decoder_State *st, const Word16 index, Word16 *pValue ); -int16_t DecodeTnsFilterOrderSWBTCX10_flt( Decoder_State *st, const int16_t index, int16_t *pValue ); -int16_t DecodeTnsFilterOrderSWBTCX20_flt( Decoder_State *st, const int16_t index, int16_t *pValue ); +Word16 DecodeTnsFilterOrderSWBTCX10_flt( Decoder_State *st, const Word16 index, Word16 *pValue ); +Word16 DecodeTnsFilterOrderSWBTCX20_flt( Decoder_State *st, const Word16 index, Word16 *pValue ); -int16_t EncodeTnsFilterOrderSWBTCX10_flt( const int16_t value, const int16_t index ); +Word16 EncodeTnsFilterOrderSWBTCX10_flt( const Word16 value, const Word16 index ); -int16_t GetTnsFilterOrderBitsSWBTCX10_flt( const int16_t value, const int16_t index ); -int16_t DecodeTnsFilterOrder_flt( Decoder_State *st, const int16_t index, int16_t *pValue ); +Word16 GetTnsFilterOrderBitsSWBTCX10_flt( const Word16 value, const Word16 index ); +Word16 DecodeTnsFilterOrder_flt( Decoder_State *st, const Word16 index, Word16 *pValue ); void ResetTnsData_flt( STnsData *pTnsData ); @@ -11569,7 +11472,7 @@ void analysisCldfbEncoder_ivas_fx( ivas_error openCldfb_ivas( HANDLE_CLDFB_FILTER_BANK *h_cldfb, /* i/o: filter bank handle */ CLDFB_TYPE type, /* i : analysis or synthesis */ - const int32_t sampling_rate, /* i : sampling rate */ + const Word32 sampling_rate, /* i : sampling rate */ CLDFB_PROTOTYPE prototype /* i : CLDFB version (1.25ms/5ms delay) */ ); diff --git a/lib_com/tns_base.c b/lib_com/tns_base.c index 82de45023..5e18430be 100644 --- a/lib_com/tns_base.c +++ b/lib_com/tns_base.c @@ -809,43 +809,19 @@ static Word16 DecodeUsingTable( Decoder_State *st, Word16 *pValue /*Q0*/, const /* TNS filter coefficients */ -int16_t DecodeSWBTCX20TnsFilterCoeff_flt( Decoder_State *st, const int16_t index, int16_t *pValue ) +Word16 DecodeSWBTCX20TnsFilterCoeff_flt( Decoder_State *st, const Word16 index, Word16 *pValue ) { assert( ( index >= 0 ) && ( index < nTnsCoeffTables ) ); return DecodeUsingTable( st, pValue, codesTnsCoeffSWBTCX20[index], nTnsCoeffCodes ); } -// int16_t GetSWBTCX10TnsFilterCoeffBits_flt( const int16_t value, const int16_t index ) -//{ -// assert( ( index >= 0 ) && ( index < nTnsCoeffTables ) ); -// return GetBitsFromTable( value, codesTnsCoeffSWBTCX10[index], nTnsCoeffCodes ); -// } - -// int16_t EncodeSWBTCX10TnsFilterCoeff_flt( const int16_t value, const int16_t index ) -//{ -// assert( ( index >= 0 ) && ( index < nTnsCoeffTables ) ); -// return EncodeUsingTable( value, codesTnsCoeffSWBTCX10[index], nTnsCoeffCodes ); -// } - -int16_t DecodeSWBTCX10TnsFilterCoeff_flt( Decoder_State *st, const int16_t index, int16_t *pValue ) +Word16 DecodeSWBTCX10TnsFilterCoeff_flt( Decoder_State *st, const Word16 index, Word16 *pValue ) { assert( ( index >= 0 ) && ( index < nTnsCoeffTables ) ); return DecodeUsingTable( st, pValue, codesTnsCoeffSWBTCX10[index], nTnsCoeffCodes ); } -// int16_t GetWBTCX20TnsFilterCoeffBits_flt( const int16_t value, const int16_t index ) -//{ -// assert( ( index >= 0 ) && ( index < nTnsCoeffTables ) ); -// return GetBitsFromTable( value, codesTnsCoeffWBTCX20[index], nTnsCoeffCodes ); -// } - -// int16_t EncodeWBTCX20TnsFilterCoeff_flt( const int16_t value, const int16_t index ) -//{ -// assert( ( index >= 0 ) && ( index < nTnsCoeffTables ) ); -// return EncodeUsingTable( value, codesTnsCoeffWBTCX20[index], nTnsCoeffCodes ); -// } - -int16_t DecodeWBTCX20TnsFilterCoeff_flt( Decoder_State *st, const int16_t index, int16_t *pValue ) +Word16 DecodeWBTCX20TnsFilterCoeff_flt( Decoder_State *st, const Word16 index, Word16 *pValue ) { assert( ( index >= 0 ) && ( index < nTnsCoeffTables ) ); return DecodeUsingTable( st, pValue, codesTnsCoeffWBTCX20[index], nTnsCoeffCodes ); @@ -854,49 +830,25 @@ int16_t DecodeWBTCX20TnsFilterCoeff_flt( Decoder_State *st, const int16_t index, /* TNS filter order */ -// void const *GetTnsFilterOrder_flt( void const *p, const int16_t index, int16_t *pValue ) -//{ -// *pValue = ( (STnsFilter const *) p )[index].order; -// return ( (STnsFilter const *) p )[index].coefIndex; -// } - -// void *SetTnsFilterOrder_flt( void *p, const int16_t index, const int16_t value ) -//{ -// ( (STnsFilter *) p )[index].order = value; -// return ( (STnsFilter *) p )[index].coefIndex; -// } - -// int16_t GetTnsFilterOrderBitsSWBTCX20_flt( const int16_t value, const int16_t index ) -//{ -// (void) index; -// return GetBitsFromTable( value - 1, codesTnsOrderTCX20, nTnsOrderCodes ); -// } - -// int16_t EncodeTnsFilterOrderSWBTCX20_flt( const int16_t value, const int16_t index ) -//{ -// (void) index; -// return EncodeUsingTable( value - 1, codesTnsOrderTCX20, nTnsOrderCodes ); -// } - -int16_t DecodeTnsFilterOrderSWBTCX20_flt( Decoder_State *st, const int16_t index, int16_t *pValue ) +Word16 DecodeTnsFilterOrderSWBTCX20_flt( Decoder_State *st, const Word16 index, Word16 *pValue ) { (void) index; return DecodeUsingTable( st, pValue, codesTnsOrderTCX20, nTnsOrderCodes ); } -int16_t GetTnsFilterOrderBitsSWBTCX10_flt( const int16_t value, const int16_t index ) +Word16 GetTnsFilterOrderBitsSWBTCX10_flt( const Word16 value, const Word16 index ) { (void) index; return GetBitsFromTable( value - 1, codesTnsOrderTCX10, nTnsOrderCodes ); } -int16_t EncodeTnsFilterOrderSWBTCX10_flt( const int16_t value, const int16_t index ) +Word16 EncodeTnsFilterOrderSWBTCX10_flt( const Word16 value, const Word16 index ) { (void) index; return EncodeUsingTable( value - 1, codesTnsOrderTCX10, nTnsOrderCodes ); } -int16_t DecodeTnsFilterOrderSWBTCX10_flt( Decoder_State *st, const int16_t index, int16_t *pValue ) +Word16 DecodeTnsFilterOrderSWBTCX10_flt( Decoder_State *st, const Word16 index, Word16 *pValue ) { (void) index; return DecodeUsingTable( st, pValue, codesTnsOrderTCX10, nTnsOrderCodes ); @@ -1105,42 +1057,36 @@ void *SetTnsEnabled( void *p, const Word16 index, const Word16 value ) /* Number of TNS filters */ -void const *GetNumOfTnsFilters_flt( void const *p, const int16_t index, int16_t *pValue ) +void const *GetNumOfTnsFilters_flt( void const *p, const Word16 index, Word16 *pValue ) { - *pValue = (int16_t) abs( ( (STnsData const *) p )[index].nFilters ); + *pValue = (Word16) abs( ( (STnsData const *) p )[index].nFilters ); return ( (STnsData const *) p )[index].filter; } -void *SetNumOfTnsFilters_flt( void *p, const int16_t index, const int16_t value ) +void *SetNumOfTnsFilters_flt( void *p, const Word16 index, const Word16 value ) { - ( (STnsData *) p )[index].nFilters = (int16_t) abs( value ); + ( (STnsData *) p )[index].nFilters = (Word16) abs( value ); return ( (STnsData *) p )[index].filter; } -int16_t DecodeTnsFilterOrder_flt( Decoder_State *st, const int16_t index, int16_t *pValue ) +Word16 DecodeTnsFilterOrder_flt( Decoder_State *st, const Word16 index, Word16 *pValue ) { (void) index; return DecodeUsingTable( st, pValue, codesTnsOrder, nTnsOrderCodes ); } /* TNS on whitened spectra flag */ -void const *GetTnsOnWhite( void const *p, const int16_t index, int16_t *pValue ) +void const *GetTnsOnWhite( void const *p, const Word16 index, Word16 *pValue ) { *pValue = ( (STnsData const *) p )[index].tnsOnWhitenedSpectra > 0 ? 1 : 0; return NULL; } -void *SetTnsOnWhite( void *p, const int16_t index, const int16_t value ) +void *SetTnsOnWhite( void *p, const Word16 index, const Word16 value ) { ( (STnsData *) p )[index].tnsOnWhitenedSpectra = value; return NULL; } -// void const *GetTnsEnabledSingleFilter( void const *p, const int16_t index, int16_t *pValue ) -//{ -// *pValue = ( (STnsData const *) p )[index].nFilters != 0 ? 1 : 0; -// return ( (STnsData const *) p )[index].filter; -// } - void const *GetTnsEnabledSingleFilter( void const *p, const Word16 index, Word16 *pValue ) { move16(); diff --git a/lib_com/tools.c b/lib_com/tools.c index f7303c6f3..9166d16eb 100644 --- a/lib_com/tools.c +++ b/lib_com/tools.c @@ -47,51 +47,23 @@ *------------------------------------------------------------------*/ /*! r: output random value */ -int16_t own_random( - int16_t *seed /* i/o: random seed */ +Word16 own_random( + Word16 *seed /* i/o: random seed */ ) { - *seed = (int16_t) ( *seed * 31821L + 13849L ); + *seed = (Word16) ( *seed * 31821L + 13849L ); return ( *seed ); } /*--------------------------------------------------------------------- - * sign() + * norm_ul_float() * *---------------------------------------------------------------------*/ -/*! r: sign of x (+1/-1) */ -float sign( - const float x /* i : input value of x */ -) +Word16 norm_ul_float( UWord32 UL_var1 ) { - if ( x < 0.0f ) - { - return -1.0f; - } - else - { - return 1.0f; - } -} - -/*--------------------------------------------------------------------- - * log2_f() - * - *---------------------------------------------------------------------*/ - -/*! r: logarithm2 of x */ -float log2_f( - const float x /* i : input value of x */ -) -{ - return (float) ( log( x ) / log( 2.0f ) ); -} - -int16_t norm_ul_float( uint32_t UL_var1 ) -{ - int16_t var_out; + Word16 var_out; if ( UL_var1 == 0 ) { @@ -99,7 +71,7 @@ int16_t norm_ul_float( uint32_t UL_var1 ) } else { - for ( var_out = 0; UL_var1 < (uint32_t) 0x80000000U; var_out++ ) + for ( var_out = 0; UL_var1 < (UWord32) 0x80000000U; var_out++ ) { UL_var1 <<= 1; } @@ -118,13 +90,13 @@ int16_t norm_ul_float( uint32_t UL_var1 ) *---------------------------------------------------------------------*/ /*! r: sum of all vector elements */ -int16_t sum_s( - const int16_t *vec, /* i : input vector */ - const int16_t lvec /* i : length of input vector */ +Word16 sum_s( + const Word16 *vec, /* i : input vector */ + const Word16 lvec /* i : length of input vector */ ) { - int16_t i; - int16_t tmp; + Word16 i; + Word16 tmp; tmp = 0; for ( i = 0; i < lvec; i++ ) @@ -182,7 +154,7 @@ Word32 sum2_f_16_gb_fx( const Word16 lvec, /* i : length of input vector */ Word16 gb ) { - int16_t i; + Word16 i; Word32 tmp; tmp = 0; @@ -311,7 +283,6 @@ Word32 sum2_32_fx( /*-------------------------------------------------------------------* * set_c() * set_s() - * set_f() * set_l() * set_d() * @@ -319,12 +290,12 @@ Word32 sum2_32_fx( *-------------------------------------------------------------------*/ void set_c( - int8_t y[], /* i/o: Vector to set */ - const int8_t a, /* i : Value to set the vector to */ - const int32_t N /* i : Length of the vector */ + Word8 y[], /* i/o: Vector to set */ + const Word8 a, /* i : Value to set the vector to */ + const Word32 N /* i : Length of the vector */ ) { - int16_t i; + Word16 i; for ( i = 0; i < N; i++ ) { @@ -336,12 +307,12 @@ void set_c( void set_s( - int16_t y[], /* i/o: Vector to set */ - const int16_t a, /* i : Value to set the vector to */ - const int16_t N /* i : Length of the vector */ + Word16 y[], /* i/o: Vector to set */ + const Word16 a, /* i : Value to set the vector to */ + const Word16 N /* i : Length of the vector */ ) { - int16_t i; + Word16 i; for ( i = 0; i < N; i++ ) { @@ -353,28 +324,12 @@ void set_s( void set_l( - int32_t y[], /* i/o: Vector to set */ - const int32_t a, /* i : Value to set the vector to */ - const int16_t N /* i : Length of the vector */ -) -{ - int16_t i; - - for ( i = 0; i < N; i++ ) - { - y[i] = a; - } - - return; -} - -void set_f( - float y[], /* i/o: Vector to set */ - const float a, /* i : Value to set the vector to */ - const int16_t N /* i : Lenght of the vector */ + Word32 y[], /* i/o: Vector to set */ + const Word32 a, /* i : Value to set the vector to */ + const Word16 N /* i : Length of the vector */ ) { - int16_t i; + Word16 i; for ( i = 0; i < N; i++ ) { @@ -391,11 +346,11 @@ void set_f( *---------------------------------------------------------------------*/ void set_zero( - float *vec, /* o : input vector */ - const int16_t lvec /* i : length of the vector */ + float *vec, /* o : input vector */ + const Word16 lvec /* i : length of the vector */ ) { - int16_t i; + Word16 i; for ( i = 0; i < lvec; i++ ) { @@ -409,8 +364,6 @@ void set_zero( /*---------------------------------------------------------------------* * mvr2r() * mvs2s() - * mvr2s() - * mvs2r() * mvr2d() * mvd2r() * @@ -420,10 +373,10 @@ void set_zero( void mvr2r( const float x[], /* i : input vector */ float y[], /* o : output vector */ - const int16_t n /* i : vector size */ + const Word16 n /* i : vector size */ ) { - int16_t i; + Word16 i; if ( n <= 0 ) { @@ -450,12 +403,12 @@ void mvr2r( } void mvs2s( - const int16_t x[], /* i : input vector */ - int16_t y[], /* o : output vector */ - const int16_t n /* i : vector size */ + const Word16 x[], /* i : input vector */ + Word16 y[], /* o : output vector */ + const Word16 n /* i : vector size */ ) { - int16_t i; + Word16 i; if ( n <= 0 ) { @@ -482,12 +435,12 @@ void mvs2s( } void mvl2l( - const int32_t x[], /* i : input vector */ - int32_t y[], /* o : output vector */ - const int16_t n /* i : vector size */ + const Word32 x[], /* i : input vector */ + Word32 y[], /* o : output vector */ + const Word16 n /* i : vector size */ ) { - int16_t i; + Word16 i; if ( n <= 0 ) { @@ -687,32 +640,6 @@ Word16 minimum_l( return ind; } -/*---------------------------------------------------------------------* - * dotp() - * - * Dot product of vector x[] and vector y[] - *---------------------------------------------------------------------*/ - -/*! r: dot product of x[] and y[] */ -float dotp( - const float x[], /* i : vector x[] */ - const float y[], /* i : vector y[] */ - const int16_t n /* i : vector length */ -) -{ - int16_t i; - float suma; - - suma = x[0] * y[0]; - - for ( i = 1; i < n; i++ ) - { - suma += x[i] * y[i]; - } - - return suma; -} - /*---------------------------------------------------------------------* * dotp() * @@ -800,20 +727,6 @@ Word32 dotp_fixed_32( return W_extract_l( suma ); } -/*---------------------------------------------------------------------* - * inv_sqrt() - * - * Find the inverse square root of the input value - *---------------------------------------------------------------------*/ - -/*! r: inverse square root of input value */ -float inv_sqrt( - const float x /* i : input value */ -) -{ - return (float) ( 1.0 / sqrt( x ) ); -} - /*-------------------------------------------------------------------* * v_add_w64() * @@ -839,32 +752,8 @@ void v_add_w64( return; } - -/*-------------------------------------------------------------------* - * v_sub() - * - * Subtraction of two vectors sample by sample - *-------------------------------------------------------------------*/ - -void v_sub( - const float x1[], /* i : Input vector 1 */ - const float x2[], /* i : Input vector 2 */ - float y[], /* o : Output vector that contains vector 1 - vector 2 */ - const int16_t N /* i : Vector length */ -) -{ - int16_t i; - - for ( i = 0; i < N; i++ ) - { - y[i] = x1[i] - x2[i]; - } - - return; -} - /*-------------------------------------------------------------------* - * v_sub() + * v_sub_fixed() * * Subtraction of two vectors sample by sample *-------------------------------------------------------------------*/ @@ -977,9 +866,9 @@ void v_multc_fixed_16_16( *-------------------------------------------------------------------*/ float usdequant( - const int16_t idx, /* i : quantizer index */ - const float qlow, /* i : lowest codebook entry (index 0) */ - const float delta /* i : quantization step */ + const Word16 idx, /* i : quantizer index */ + const float qlow, /* i : lowest codebook entry (index 0) */ + const float delta /* i : quantization step */ ) { float g; diff --git a/lib_com/tools_fx.c b/lib_com/tools_fx.c index 14a97a034..77e779efd 100644 --- a/lib_com/tools_fx.c +++ b/lib_com/tools_fx.c @@ -241,9 +241,9 @@ void fix2f_16( Word16 *var_fix, float *var_flt, Word32 expo ) #undef WMC_TOOL_SKIP -int16_t norm_ul( uint32_t UL_var1 ) +Word16 norm_ul( UWord32 UL_var1 ) { - int16_t var_out; + Word16 var_out; if ( UL_var1 == 0 ) { @@ -251,7 +251,7 @@ int16_t norm_ul( uint32_t UL_var1 ) } else { - for ( var_out = 0; UL_var1 < (uint32_t) 0x80000000U; var_out++ ) + for ( var_out = 0; UL_var1 < (UWord32) 0x80000000U; var_out++ ) { UL_var1 <<= 1; } @@ -997,7 +997,7 @@ void scale_sig( } /*---------------------------------------------------------------------* - * mean() + * mean_fx() * *---------------------------------------------------------------------*/ Word16 mean_fx( /* o : mean of vector */ @@ -2171,7 +2171,7 @@ Word16 own_random2_fx( Word16 seed ) } /*--------------------------------------------------------------------- - * sign() + * sign_fx() * *---------------------------------------------------------------------*/ @@ -4207,7 +4207,7 @@ Word16 lin_interp_ivas_fx( } /*--------------------------------------------------------------------- - * sign() + * sign_l() * *---------------------------------------------------------------------*/ @@ -4245,7 +4245,7 @@ void v_mult16_fixed( } /*---------------------------------------------------------------------* - * set_zero() + * set_zero_fx() * * Set a vector vec[] of dimension lvec to zero *---------------------------------------------------------------------*/ diff --git a/lib_dec/dec_acelp_tcx_main_fx.c b/lib_dec/dec_acelp_tcx_main_fx.c index 21bf7cf12..eea558914 100644 --- a/lib_dec/dec_acelp_tcx_main_fx.c +++ b/lib_dec/dec_acelp_tcx_main_fx.c @@ -364,7 +364,7 @@ Word16 dec_acelp_tcx_frame_fx( { /* Copy back parameters from previous frame, because there is a high risk they are corrupt * DO concealment with configuration used in previous frame */ - st->m_frame_type = (uint8_t) m_frame_type; + st->m_frame_type = (UWord8) m_frame_type; move16(); st->bwidth = bwidth; move16(); diff --git a/lib_enc/acelp_core_enc_fx.c b/lib_enc/acelp_core_enc_fx.c index 6ba21136e..f942a19ff 100644 --- a/lib_enc/acelp_core_enc_fx.c +++ b/lib_enc/acelp_core_enc_fx.c @@ -38,7 +38,6 @@ ivas_error acelp_core_enc_fx( Word16 pitch_buf_fx[NB_SUBFR16k], /* o : floating pitch for each subframe Q6*/ Word16 *unbits_fx, /* o : number of unused bits Q0*/ STEREO_TD_ENC_DATA_HANDLE hStereoTD, /* i/o: TD stereo encoder handle */ - const float tdm_lsfQ_PCh[M], /* i : Q LSFs for primary channel */ const Word16 Q_new, const Word16 shift ) { @@ -107,8 +106,6 @@ ivas_error acelp_core_enc_fx( * Initialization *------------------------------------------------------------------*/ - (void) tdm_lsfQ_PCh; - Es_pred_fx = 0; move16(); diff --git a/lib_enc/evs_enc_fx.c b/lib_enc/evs_enc_fx.c index 624ec20fc..8e9a82378 100644 --- a/lib_enc/evs_enc_fx.c +++ b/lib_enc/evs_enc_fx.c @@ -269,7 +269,7 @@ ivas_error evs_enc_fx( IF( EQ_16( st->core, ACELP_CORE ) ) { acelp_core_enc_fx( st, inp, ener, A, Aw, epsP_h, epsP_l, lsp_new, lsp_mid, vad_hover_flag, - attack_flag, bwe_exc_extended, voice_factors, old_syn_12k8_16k, pitch_buf, &unbits, NULL, NULL, Q_new, shift ); + attack_flag, bwe_exc_extended, voice_factors, old_syn_12k8_16k, pitch_buf, &unbits, NULL, Q_new, shift ); } /*---------------------------------------------------------------------* * HQ core encoding diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 72137bdce..d3528370f 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -61,7 +61,6 @@ ivas_error acelp_core_enc_fx( Word16 pitch_buf_fx[NB_SUBFR16k], /* o : floating pitch for each subframe Q6*/ Word16 *unbits_fx, /* o : number of unused bits Q0*/ STEREO_TD_ENC_DATA_HANDLE hStereoTD, /* i/o: TD stereo encoder handle */ - const float tdm_lsfQ_PCh[M], /* i : Q LSFs for primary channel */ const Word16 Q_new, const Word16 shift diff --git a/lib_enc/rom_enc.h b/lib_enc/rom_enc.h index 35fd3027d..7da1da92a 100644 --- a/lib_enc/rom_enc.h +++ b/lib_enc/rom_enc.h @@ -52,7 +52,6 @@ extern const Word16 W_HIST_S_FX[DTX_HIST_SIZE]; /* CNG & DTX - table for calcula extern const Word16 bwd_start_bin[]; // Q0 extern const Word16 bwd_end_bin[]; // Q0 -extern const float h_fir[]; /* 2nd order fir filter for wsp, decimation by 2 */ extern const Word16 h_fir_fx[]; /* 2nd order fir filter for wsp, decimation by 2 Q15*/ extern const Word16 preemphCompensation_fx[]; // Q11 diff --git a/lib_rend/ivas_rom_rend.h b/lib_rend/ivas_rom_rend.h index f62440749..7f9cfb57a 100644 --- a/lib_rend/ivas_rom_rend.h +++ b/lib_rend/ivas_rom_rend.h @@ -121,10 +121,6 @@ extern const Word32 ivas_reverb_default_fc_fx[]; /*Q-16*/ extern const Word32 ivas_reverb_default_RT60_fx[]; /*Q-26*/ extern const Word32 ivas_reverb_default_DSR_fx[]; /*Q-30*/ -extern const float ivas_reverb_default_fc[]; -extern const float ivas_reverb_default_RT60[]; -extern const float ivas_reverb_default_DSR[]; - extern const Word32 release_cnst_table[4][201]; // Q31 /*----------------------------------------------------------------------------------* diff --git a/lib_rend/ivas_rom_rend_fx.c b/lib_rend/ivas_rom_rend_fx.c index 4f101582c..d14be4afe 100644 --- a/lib_rend/ivas_rom_rend_fx.c +++ b/lib_rend/ivas_rom_rend_fx.c @@ -561,42 +561,6 @@ const Word32 ivas_reverb_default_DSR_fx[IVAS_REVERB_DEFAULT_N_BANDS] /*Q30*/ = 66, 30, 28 }; -const float ivas_reverb_default_fc[IVAS_REVERB_DEFAULT_N_BANDS] = -{ - 20.0f, 25.0f, 31.5f, 40.0f, - 50.0f, 63.0f, 80.0f, 100.0f, - 125.0f, 160.0f, 200.0f, 250.0f, - 315.0f, 400.0f, 500.0f, 630.0f, - 800.0f, 1000.0f, 1250.0f, 1600.0f, - 2000.0f, 2500.0f, 3150.0f, 4000.0f, - 5000.0f, 6300.0f, 8000.0f, 10000.0f, - 12500.0f, 16000.0f, 20000.0f -}; - -const float ivas_reverb_default_RT60[IVAS_REVERB_DEFAULT_N_BANDS] = -{ - 1.3622f, 1.4486f, 1.3168f, 1.5787f, - 1.4766f, 1.3954f, 1.2889f, 1.3462f, - 1.0759f, 1.0401f, 1.097f, 1.085f, - 1.091f, 1.0404f, 1.0499f, 1.0699f, - 1.1028f, 1.1714f, 1.1027f, 1.0666f, - 1.055f, 1.0553f, 1.0521f, 1.0569f, - 1.0421f, 0.97822f, 0.80487f, 0.75944f, - 0.71945f, 0.61682f, 0.60031f -}; - -const float ivas_reverb_default_DSR[IVAS_REVERB_DEFAULT_N_BANDS] = -{ - 1.8811e-08f, 2.1428e-08f, 1.3972e-08f, 1.51e-08f, - 1.287e-08f, 1.8747e-08f, 2.413e-08f, 3.9927e-08f, - 8.9719e-08f, 1.902e-07f, 3.702e-07f, 6.1341e-07f, - 7.1432e-07f, 6.5331e-07f, 4.6094e-07f, 5.4683e-07f, - 7.0134e-07f, 6.856e-07f, 7.114e-07f, 6.9604e-07f, - 5.2939e-07f, 5.699e-07f, 6.1773e-07f, 5.7488e-07f, - 4.7748e-07f, 2.7213e-07f, 1.3681e-07f, 1.0941e-07f, - 6.2001e-08f, 2.8483e-08f, 2.6267e-08f -}; - const Word32 release_cnst_table[4][201] = // Q31 { { -- GitLab From b69b11e39f8edd19a63de476efb0648647896393 Mon Sep 17 00:00:00 2001 From: Manuel Jander Date: Tue, 20 May 2025 10:23:30 +0200 Subject: [PATCH 068/113] Add missing assignment of Q values of overlap add buffers. --- lib_dec/dec_ace_fx.c | 4 ++++ lib_dec/er_dec_acelp_fx.c | 9 ++++++++- lib_dec/er_dec_tcx_fx.c | 10 ++++++++++ lib_dec/updt_dec_fx.c | 4 ++++ 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/lib_dec/dec_ace_fx.c b/lib_dec/dec_ace_fx.c index 9c366e3f3..edc429459 100644 --- a/lib_dec/dec_ace_fx.c +++ b/lib_dec/dec_ace_fx.c @@ -690,6 +690,10 @@ void decoder_acelp_fx( E_UTIL_deemph2( st->Q_syn, syn, st->preemph_fac, st->L_frame, &tmp_deemph ); /* tmp_deemph and syn in Q0 starting from here*/ bufferCopyFx( syn + shr( st->L_frame, 1 ), hTcxDec->old_syn_Overl, shr( st->L_frame, 1 ), 0 /*Qf_syn*/, -1 /*Qf_old_xnq*/, 0, 0 /*Q_old_xnq*/ ); +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT + st->hTcxDec->Q_old_syn_Overl = sub( st->Q_syn, 1 ); + move16(); +#endif Copy( syn + sub( st->L_frame, M + 1 ), st->syn, 1 + M ); /*Q0*/ diff --git a/lib_dec/er_dec_acelp_fx.c b/lib_dec/er_dec_acelp_fx.c index bcbff9b76..18c930269 100644 --- a/lib_dec/er_dec_acelp_fx.c +++ b/lib_dec/er_dec_acelp_fx.c @@ -1018,6 +1018,10 @@ void con_acelp_fx( Copy( syn, synth, st->L_frame ); bufferCopyFx( syn + sub( st->L_frame, shr( st->L_frame, 1 ) ), hTcxDec->old_syn_Overl, shr( st->L_frame, 1 ), 0 /*Qf_syn*/, -1 /*Qf_old_xnq*/, 0, 0 /*Q_old_xnq*/ ); +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT + st->hTcxDec->Q_old_syn_Overl = sub( Qf_syn, 1 ); + move16(); +#endif /* save last half frame if next frame is TCX */ bufferCopyFx( syn + st->L_frame, hTcxDec->syn_Overl_TDAC, shr( st->L_frame, 1 ), 0 /*Qf_syn*/, -1 /*Qf_old_xnq*/, 0, 0 /*Q_old_xnq*/ ); @@ -1057,7 +1061,10 @@ void con_acelp_fx( move16(); } set16_fx( &hHQ_core->old_out_LB_fx[( W1 + n )], 0, n ); -#ifndef FIX_1348_BIT_PRECISION_IMPROVEMENT +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT + hHQ_core->Q_old_wtda_LB = st->Q_syn; + move16(); +#else hHQ_core->Q_old_wtda = hHQ_core->Q_old_wtda_LB; move16(); #endif diff --git a/lib_dec/er_dec_tcx_fx.c b/lib_dec/er_dec_tcx_fx.c index 48e290217..a1907b44c 100644 --- a/lib_dec/er_dec_tcx_fx.c +++ b/lib_dec/er_dec_tcx_fx.c @@ -843,7 +843,15 @@ void con_tcx_fx( lerp( syn + sub( L_frame, shr( L_frame, 1 ) ), hTcxDec->old_syn_Overl, shr( st->L_frame, 1 ), shr( L_frame, 1 ) ); +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT + st->hTcxDec->Q_old_syn_Overl = Q_syn; + move16(); +#endif Copy( syn + sub( L_frame, n ), hHQ_core->old_out_fx, sub( L_frame, n ) ); /*Q_syn*/ +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT + hHQ_core->Q_old_wtda = Q_syn; + move16(); +#endif FOR( i = 0; i < W12; i++ ) { @@ -934,7 +942,9 @@ void con_tcx_fx( move16(); /* update memory for low band */ +#ifndef FIX_1348_BIT_PRECISION_IMPROVEMENT Scale_sig( hTcxDec->old_syn_Overl, shr( st->L_frame, 1 ), sub( -1, Q_syn ) ); /*Q_syn*/ +#endif lerp( hTcxDec->syn_OverlFB, hTcxDec->syn_Overl, shr( st->L_frame, 1 ), shr( L_frame, 1 ) ); #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT hTcxDec->Q_syn_Overl = hTcxDec->Q_syn_OverlFB; diff --git a/lib_dec/updt_dec_fx.c b/lib_dec/updt_dec_fx.c index 81046fb19..d1fe01b42 100644 --- a/lib_dec/updt_dec_fx.c +++ b/lib_dec/updt_dec_fx.c @@ -1207,6 +1207,10 @@ void update_decoder_LPD_cng( Copy( hTcxDec->old_synth + st->L_frame, hTcxDec->old_synth, sub( hTcxDec->old_synth_len, st->L_frame ) ); Copy( synth, hTcxDec->old_synth + sub( hTcxDec->old_synth_len, st->L_frame ), st->L_frame ); bufferCopyFx( synth + sub( st->L_frame, ( st->L_frame / 2 ) ), hTcxDec->old_syn_Overl, st->L_frame / 2, 0 /*Qf_syn*/, -1 /*Qf_old_xnq*/, 0, 0 /*Q_old_xnq*/ ); +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT + st->hTcxDec->Q_old_syn_Overl = sub( st->Q_syn, 1 ); + move16(); +#endif hTcxDec->tcxltp_last_gain_unmodified = 0; move16(); -- GitLab From 25546392018d5ba6856a515ce08641b910fb7777 Mon Sep 17 00:00:00 2001 From: Manuel Jander Date: Tue, 20 May 2025 10:54:07 +0200 Subject: [PATCH 069/113] clang format. --- lib_dec/acelp_core_dec_fx.c | 64 ++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/lib_dec/acelp_core_dec_fx.c b/lib_dec/acelp_core_dec_fx.c index 0ba5d5caf..ef5c04774 100644 --- a/lib_dec/acelp_core_dec_fx.c +++ b/lib_dec/acelp_core_dec_fx.c @@ -85,9 +85,9 @@ ivas_error acelp_core_dec_fx( Word16 lsp_mid_fx[M]; /* LSPs in the middle of the frame */ Word16 Aq_fx[NB_SUBFR16k * ( M + 1 )]; /* A(q) quantized for the 4 subframes */ Word16 old_exc2_fx[L_FRAME16k + L_EXC_MEM], *exc2_fx; /* total excitation buffer */ - Word16 mem_tmp_fx[M]; /* temporary synthesis filter memory */ - Word32 enr_q_fx; /* E information for FER protection */ - Word16 tmp_noise_fx; /* Long term temporary noise energy */ + Word16 mem_tmp_fx[M]; /* temporary synthesis filter memory */ + Word32 enr_q_fx; /* E information for FER protection */ + Word16 tmp_noise_fx; /* Long term temporary noise energy */ Word16 Es_pred_fx; /* predicted scaled innov. energy Q8 */ Word16 FEC_pitch_fx; /* FEC pitch */ Word16 old_bwe_exc_fx[( ( PIT16k_MAX + ( L_FRAME16k + 1 ) + L_SUBFR16k ) * 2 )]; /* excitation buffer */ @@ -266,7 +266,7 @@ ivas_error acelp_core_dec_fx( if ( st->hGSCDec != NULL ) { - /* reset the GSC pre echo energy threshold in case of switching */ + /* reset the GSC pre echo energy threshold in case of switching */ st->hGSCDec->Last_frame_ener_fx = MAX_32; move32(); } @@ -1425,15 +1425,15 @@ ivas_error acelp_core_dec_fx( Copy( psyn_fx + sub( st->L_frame, L_EXC_MEM ), st->hWIDec->old_syn2_fx, L_EXC_MEM ); } st->prev_Q_exc_fr = st->Q_exc; - move16(); + move16(); st->prev_Q_syn_fr = st->Q_syn; - move16(); + move16(); Copy( psyn_fx + sub( st->L_frame, L_SYN_MEM_CLAS_ESTIM ), st->mem_syn_clas_estim_fx, L_SYN_MEM_CLAS_ESTIM ); - /*------------------------------------------------------------* - * FEC - Smooth the speech energy evolution when recovering after a BAD frame - * (smoothing is performed in the excitation domain and signal is resynthesized after) - *------------------------------------------------------------*/ + /*------------------------------------------------------------* + * FEC - Smooth the speech energy evolution when recovering after a BAD frame + * (smoothing is performed in the excitation domain and signal is resynthesized after) + *------------------------------------------------------------*/ test(); IF( EQ_32( st->total_brate, ACELP_7k20 ) || EQ_32( st->total_brate, ACELP_8k00 ) ) @@ -1455,7 +1455,7 @@ ivas_error acelp_core_dec_fx( &st->uv_count, &st->act_count, st->lspold_s_fx, &st->noimix_seed, &st->min_alpha_fx, &st->exc_pe_fx, st->core_brate, st->bwidth, &st->Q_stat_noise, &st->Q_stat_noise_ge ); } - } + } IF( st->hBWE_TD != NULL ) { @@ -1517,14 +1517,14 @@ ivas_error acelp_core_dec_fx( * Formant post-filter *-----------------------------------------------------------------*/ - test(); - test(); - test(); + test(); + test(); + test(); test(); IF( st->hPFstat != NULL && GE_16( st->last_bwidth, WB ) && ( GT_32( st->core_brate, ACELP_24k40 ) || st->element_mode > EVS_MONO ) && LE_32( st->core_brate, ACELP_32k ) ) - { + { st->hPFstat->on = 1; - move16(); + move16(); Copy( psyn_fx, temp_buf_fx + L_SYN_MEM, L_FRAME16k ); set16_fx( st->hPFstat->mem_zero, 0, M ); @@ -1597,13 +1597,13 @@ ivas_error acelp_core_dec_fx( { /* Noise estimate */ ApplyFdCng_fx( psyn_fx, st->Q_syn, NULL, 0, realBuffer_fx, imagBuffer_fx, NULL, st, 0, ( st->coder_type == AUDIO && !st->GSC_noisy_speech ) ); - } + } IF( !st->cna_dirac_flag ) { test(); test(); - test(); + test(); test(); test(); test(); @@ -1635,7 +1635,7 @@ ivas_error acelp_core_dec_fx( } } ELSE IF( NE_16( st->element_mode, IVAS_CPE_DFT ) ) - { + { IF( EQ_16( st->element_mode, EVS_MONO ) ) { generate_masking_noise_fx( psyn_fx, st->Q_syn, st->hFdCngDec->hFdCngCom, st->hFdCngDec->hFdCngCom->frameSize, 0 ); @@ -1736,9 +1736,9 @@ ivas_error acelp_core_dec_fx( } } - test(); - test(); - test(); + test(); + test(); + test(); IF( ( st->flag_cna == 0 ) || ( EQ_16( st->coder_type, AUDIO ) && !( st->element_mode > EVS_MONO && st->GSC_noisy_speech ) ) ) { IF( st->idchan == 0 ) @@ -1988,12 +1988,12 @@ ivas_error acelp_core_dec_fx( st->cldfbSyn->bandsToZero = sub( st->cldfbSyn->no_channels, st->cldfbAna->no_channels ); move16(); } - test(); - IF( !st->cng_sba_flag || EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) - { - test(); - test(); test(); + IF( !st->cng_sba_flag || EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) + { + test(); + test(); + test(); /*WB/SWB-FD_CNG*/ IF( ( st->core_brate == FRAME_NO_DATA || EQ_32( st->core_brate, SID_2k40 ) ) && ( EQ_16( st->cng_type, FD_CNG ) ) && ( LT_16( st->hFdCngDec->hFdCngCom->numCoreBands, st->cldfbSyn->no_channels ) ) ) { @@ -2010,13 +2010,13 @@ ivas_error acelp_core_dec_fx( IF( LT_16( st->hFdCngDec->hFdCngCom->regularStopBand, st->cldfbSyn->no_channels ) ) { st->cldfbSyn->bandsToZero = sub( st->cldfbSyn->no_channels, st->hFdCngDec->hFdCngCom->regularStopBand ); - move16(); + move16(); } ELSE - { + { st->cldfbSyn->bandsToZero = 0; - move16(); - } + move16(); + } } } @@ -2111,7 +2111,7 @@ ivas_error acelp_core_dec_fx( } ELSE { - /* synthesis of the combined signal */ + /* synthesis of the combined signal */ max_real = 0; max_imag = 0; move32(); -- GitLab From 9aea06c25b2c29176d923abc0b808b11f01c149f Mon Sep 17 00:00:00 2001 From: Manuel Jander Date: Tue, 20 May 2025 11:02:33 +0200 Subject: [PATCH 070/113] Restore changes lost because of merge conflict. --- lib_com/prot_fx.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 498be3137..2fc32b008 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -9472,8 +9472,15 @@ void IMDCT_fx( Word32 *x, Word16 x_e, Word16 *old_syn_overl, Word16 *syn_Overl_T void IMDCT_ivas_fx( Word32 *x_fx, Word16 q_x, +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN Word16 *old_syn_overl_fx, + Word16 *Q_old_syn_overl_fx, Word16 *syn_Overl_TDAC_fx, + Word16 *Q_syn_Overl_TDAC_fx, +#else + Word16 *old_syn_overl_fx, + Word16 *syn_Overl_TDAC_fx, +#endif Word16 *xn_buf_fx, const Word16 *tcx_aldo_window_1_fx, const PWord16 *tcx_aldo_window_1_trunc_fx, @@ -9495,11 +9502,18 @@ void IMDCT_ivas_fx( const Word16 frame_cnt, const Word16 bfi, Word16 *old_out_fx, +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD + Word16 *q_old_out_fx, +#endif const Word16 FB_flag, Decoder_State *st, const Word16 fullbandScale, Word16 *acelp_zir_fx, +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN + Word16 *pq_win ); +#else Word16 q_win ); +#endif void v_mult16_fixed( const Word16 x1[], /* i : Input vector 1 */ -- GitLab From 1ab5a24fd0b1dea352dc5122a22256a8ef0a3854 Mon Sep 17 00:00:00 2001 From: Manuel Jander Date: Wed, 21 May 2025 17:59:39 +0200 Subject: [PATCH 071/113] Add scaling correction of xn_buf_fx, which was missing. --- lib_com/prot_fx.h | 3 + lib_dec/dec_tcx_fx.c | 131 +++++++++++++++++++------------- lib_dec/ivas_mdct_core_dec_fx.c | 7 +- 3 files changed, 87 insertions(+), 54 deletions(-) diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 2fc32b008..7d6f3e55e 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -9482,6 +9482,9 @@ void IMDCT_ivas_fx( Word16 *syn_Overl_TDAC_fx, #endif Word16 *xn_buf_fx, +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN + Word16 q_xn_buf_fx, +#endif const Word16 *tcx_aldo_window_1_fx, const PWord16 *tcx_aldo_window_1_trunc_fx, const PWord16 *tcx_aldo_window_2_fx, diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index b51493262..49886cecf 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -2588,29 +2588,17 @@ static Word16 IMDCT_ivas_fx_calc_qwin( const Word16 L_frameTCX, const Word16 FB_flag ) { -#if 0 Word16 oldLength; - oldLength = L_FRAME32k; + oldLength = s_min( L_FRAME32k, L_frame ); move16(); if ( FB_flag ) { - oldLength = L_FRAME48k; + oldLength = s_min( L_FRAME48k, L_frameTCX ); move16(); } -#else - Word16 oldLength; - oldLength = L_frame; - move16(); - if ( FB_flag ) - { - oldLength = L_frameTCX; - move16(); - } -#endif - - q_win = 4; + q_win = 6; move16(); // q_win == norm + Q_syn_Overl_TDAC @@ -2625,6 +2613,8 @@ static Word16 IMDCT_ivas_fx_calc_qwin( } static void IMDCT_ivas_fx_rescale( + Word16 *xn_buf_fx, + Word16 *q_xn_buf_fx, Word16 *syn_Overl_TDAC, Word16 *Q_syn_Overl_TDAC, Word16 *syn_Overl, @@ -2647,6 +2637,9 @@ static void IMDCT_ivas_fx_rescale( } #if 1 + Scale_sig(xn_buf_fx, L_MDCT_OVLP_MAX + L_FRAME_PLUS + L_MDCT_OVLP_MAX, sub ( q_win, *q_xn_buf_fx ) ); + *q_xn_buf_fx = q_win; + move16(); Scale_sig( syn_Overl_TDAC, oldLength / 2, sub( q_win, *Q_syn_Overl_TDAC ) ); // st->hTcxDec->Q_syn_Overl_TDAC -> q_win *Q_syn_Overl_TDAC = q_win; move16(); @@ -2937,6 +2930,9 @@ void IMDCT_ivas_fx( Word16 *syn_Overl_TDAC_fx, // Q(-2) #endif Word16 *xn_buf_fx, // Q(-2) +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN + Word16 q_xn_buf_fx, +#endif const Word16 *tcx_aldo_window_1_fx, // Q(15) const PWord16 *tcx_aldo_window_1_trunc_fx, // Q(15) const PWord16 *tcx_aldo_window_2_fx, // Q(15) @@ -2983,10 +2979,12 @@ void IMDCT_ivas_fx( move16(); move16(); x_e_hdrm = sub( Q16, q_x ); +#if 0 IF( *pq_win == 0 ) { allow_qwin_change = 0; } +#endif IF( allow_qwin_change ) { // q_win = IMDCT_ivas_fx_adjust_qwin( *Q_syn_Overl_TDAC_fx, *Q_old_syn_overl_fx, hTcxDec->Q_old_syn_Overl, *q_old_out_fx, q_win ); @@ -3086,6 +3084,9 @@ void IMDCT_ivas_fx( test(); L_spec_TCX5_tmp = imult1616( w, L_spec_TCX5 ); #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN + // Assume that xn_buf_fx has no headroom. + q_win = s_min( q_xn_buf_fx, q_win ); + IF( EQ_16( kernel_type, MDST_IV ) || s_and( kernel_type, w ) ) { TCX_MDST_Inverse_qwin_fx( x_fx + L_spec_TCX5_tmp, x_e_hdrm, win_fx, L_ola, sub( L_win, L_ola ), L_ola, &q_win, allow_qwin_change ); @@ -3099,7 +3100,7 @@ void IMDCT_ivas_fx( TCX_MDCT_Inverse_qwin_fx( x_fx + L_spec_TCX5_tmp, x_e_hdrm, win_fx, L_ola, sub( L_win, L_ola ), L_ola, st->element_mode, &q_win, allow_qwin_change ); } - IMDCT_ivas_fx_rescale( syn_Overl_TDAC_fx, Q_syn_Overl_TDAC_fx, old_syn_overl_fx, Q_old_syn_overl_fx, hTcxDec->old_syn_Overl, &hTcxDec->Q_old_syn_Overl, old_out_fx, q_old_out_fx, q_win, FB_flag ); + IMDCT_ivas_fx_rescale( xn_buf_fx, &q_xn_buf_fx, syn_Overl_TDAC_fx, Q_syn_Overl_TDAC_fx, old_syn_overl_fx, Q_old_syn_overl_fx, hTcxDec->old_syn_Overl, &hTcxDec->Q_old_syn_Overl, old_out_fx, q_old_out_fx, q_win, FB_flag ); #else IF( EQ_16( kernel_type, MDST_IV ) || s_and( kernel_type, w ) ) { @@ -3155,6 +3156,10 @@ void IMDCT_ivas_fx( #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN Word16 q_win_prev; +#if 0 + // Assume that xn_buf_fx has no headroom. + q_win = s_min( q_xn_buf_fx, q_win ); +#endif #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN IF( allow_qwin_change ) { @@ -3199,8 +3204,11 @@ void IMDCT_ivas_fx( /* copy new sub-window region not overlapping with previous window */ Copy( win_fx + L_win, xn_buf_fx + shr( overlap, 1 ), add( L_win, shr( L_ola, 1 ) ) ); - /* 2nd TCX-5 window, regular MDCT with minimum overlap on both sides */ #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN + q_xn_buf_fx = q_win; + move16(); + + /* 2nd TCX-5 window, regular MDCT with minimum overlap on both sides */ IF( s_and( kernel_type, 1 ) ) { TCX_MDST_Inverse_qwin_fx( x_fx + L_spec_TCX5, x_e_hdrm, win_fx, L_ola, sub( L_win, L_ola ), L_ola, &q_win, allow_qwin_change ); @@ -3212,8 +3220,9 @@ void IMDCT_ivas_fx( assert( q_win_prev == q_win ); - IMDCT_ivas_fx_rescale( syn_Overl_TDAC_fx, Q_syn_Overl_TDAC_fx, old_syn_overl_fx, Q_old_syn_overl_fx, hTcxDec->old_syn_Overl, &hTcxDec->Q_old_syn_Overl, old_out_fx, q_old_out_fx, q_win, FB_flag ); + IMDCT_ivas_fx_rescale( xn_buf_fx, &q_xn_buf_fx, syn_Overl_TDAC_fx, Q_syn_Overl_TDAC_fx, old_syn_overl_fx, Q_old_syn_overl_fx, hTcxDec->old_syn_Overl, &hTcxDec->Q_old_syn_Overl, old_out_fx, q_old_out_fx, q_win, FB_flag ); #else + /* 2nd TCX-5 window, regular MDCT with minimum overlap on both sides */ IF( s_and( kernel_type, 1 ) ) { TCX_MDST_Inverse_fx( x_fx + L_spec_TCX5, x_e_hdrm, win_fx, L_ola, sub( L_win, L_ola ), L_ola ); @@ -3270,8 +3279,11 @@ void IMDCT_ivas_fx( { TCX_MDCT_Inverse_qwin_fx( x_fx, x_e_hdrm, xn_buf_fx, overlap, sub( L_frame, overlap ), overlap, st->element_mode, &q_win, allow_qwin_change ); } + // Because xn_buf_fx is overwritten above. + q_xn_buf_fx = q_win; + move16(); - IMDCT_ivas_fx_rescale( syn_Overl_TDAC_fx, Q_syn_Overl_TDAC_fx, old_syn_overl_fx, Q_old_syn_overl_fx, hTcxDec->old_syn_Overl, &hTcxDec->Q_old_syn_Overl, old_out_fx, q_old_out_fx, q_win, FB_flag ); + IMDCT_ivas_fx_rescale( xn_buf_fx, &q_xn_buf_fx, syn_Overl_TDAC_fx, Q_syn_Overl_TDAC_fx, old_syn_overl_fx, Q_old_syn_overl_fx, hTcxDec->old_syn_Overl, &hTcxDec->Q_old_syn_Overl, old_out_fx, q_old_out_fx, q_win, FB_flag ); #else IF( EQ_16( kernel_type, MDST_IV ) ) { @@ -3334,7 +3346,7 @@ void IMDCT_ivas_fx( #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN // q_win < norm + q_tmp_fx_32 - 16 q_win = s_min( q_win, L_norm_arr( tmp_fx_32, L_frame ) + q_tmp_fx_32 - 16 ); - IMDCT_ivas_fx_rescale( syn_Overl_TDAC_fx, Q_syn_Overl_TDAC_fx, old_syn_overl_fx, Q_old_syn_overl_fx, hTcxDec->old_syn_Overl, &hTcxDec->Q_old_syn_Overl, old_out_fx, q_old_out_fx, q_win, FB_flag ); + IMDCT_ivas_fx_rescale( xn_buf_fx, &q_xn_buf_fx, syn_Overl_TDAC_fx, Q_syn_Overl_TDAC_fx, old_syn_overl_fx, Q_old_syn_overl_fx, hTcxDec->old_syn_Overl, &hTcxDec->Q_old_syn_Overl, old_out_fx, q_old_out_fx, q_win, FB_flag ); #endif Word16 diff = sub( q_tmp_fx_32, q_win ); @@ -3363,8 +3375,8 @@ void IMDCT_ivas_fx( assert( extract_h( L_shr( old_out_fx_32[ind], diff ) ) == 0 || extract_h( L_shr( old_out_fx_32[ind], diff ) ) == -1 ); old_out_fx[ind] = extract_l( L_shr( old_out_fx_32[ind], diff ) ); #endif - xn_buf_fx[ind] = extract_l( L_shr( xn_buf_fx_32[ind], diff ) ); assert( extract_h( L_shr( xn_buf_fx_32[ind], diff ) ) == 0 || extract_h( L_shr( xn_buf_fx_32[ind], diff ) ) == -1 ); + xn_buf_fx[ind] = extract_l( L_shr( xn_buf_fx_32[ind], diff ) ); move16(); move16(); } @@ -3398,7 +3410,7 @@ void IMDCT_ivas_fx( // q_win == - 16 + L_norm_arr( xn_buf_fx_32, L_frame ) + q_xn_buf_fx_32 q_win = s_min( q_win, add( sub( q_xn_buf_fx_32, 16 ), L_norm_arr( xn_buf_fx_32, L_frame ) ) - 2 ); } - IMDCT_ivas_fx_rescale( syn_Overl_TDAC_fx, Q_syn_Overl_TDAC_fx, old_syn_overl_fx, Q_old_syn_overl_fx, hTcxDec->old_syn_Overl, &hTcxDec->Q_old_syn_Overl, old_out_fx, q_old_out_fx, q_win, FB_flag ); + IMDCT_ivas_fx_rescale( xn_buf_fx, &q_xn_buf_fx, syn_Overl_TDAC_fx, Q_syn_Overl_TDAC_fx, old_syn_overl_fx, Q_old_syn_overl_fx, hTcxDec->old_syn_Overl, &hTcxDec->Q_old_syn_Overl, old_out_fx, q_old_out_fx, q_win, FB_flag ); #endif Word16 q_diff = sub( q_xn_buf_fx_32, q_win ); @@ -3459,7 +3471,7 @@ void IMDCT_ivas_fx( { allow_qwin_change = 0; move16(); - q_win = s_max( -2, sub( q_win, 2 ) ); + q_win = s_max( -2, sub( q_win, 1 ) ); } } @@ -3475,8 +3487,11 @@ void IMDCT_ivas_fx( { TCX_MDCT_Inverse_qwin_fx( x_fx, x_e_hdrm, xn_buf_fx, overlap, L_frame - overlap, overlap, st->element_mode, &q_win, allow_qwin_change ); } + // Because xn_buf_fx is overwritten above. + q_xn_buf_fx = q_win; + move16(); - IMDCT_ivas_fx_rescale( syn_Overl_TDAC_fx, Q_syn_Overl_TDAC_fx, old_syn_overl_fx, Q_old_syn_overl_fx, hTcxDec->old_syn_Overl, &hTcxDec->Q_old_syn_Overl, old_out_fx, q_old_out_fx, q_win, FB_flag ); + IMDCT_ivas_fx_rescale( xn_buf_fx, &q_xn_buf_fx, syn_Overl_TDAC_fx, Q_syn_Overl_TDAC_fx, old_syn_overl_fx, Q_old_syn_overl_fx, hTcxDec->old_syn_Overl, &hTcxDec->Q_old_syn_Overl, old_out_fx, q_old_out_fx, q_win, FB_flag ); #else IF( EQ_16( kernel_type, MDST_IV ) ) { @@ -3547,15 +3562,15 @@ void IMDCT_ivas_fx( IF( hTcxCfg->last_aldo != 0 ) { -#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD +#if defined(FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD) && !defined(FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN) Word16 tmp_old_out; Word16 q_diff = sub( *q_old_out_fx, q_win ); #endif FOR( i = 0; i < sub( overlap, tcx_mdct_window_min_length ); i++ ) { -#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD +#if defined(FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD) && !defined(FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN) tmp_old_out = shr_sat( old_out_fx[( i + nz )], q_diff ); - xn_buf_fx[( i + ( ( overlap / 2 ) - tcx_offset ) )] = add_sat( xn_buf_fx[( i + ( ( overlap / 2 ) - tcx_offset ) )], tmp_old_out ); // Q(-2) + xn_buf_fx[( i + ( ( overlap / 2 ) - tcx_offset ) )] = add_sat( xn_buf_fx[( i + ( ( overlap / 2 ) - tcx_offset ) )], tmp_old_out ); // q_win #else xn_buf_fx[( i + ( ( overlap / 2 ) - tcx_offset ) )] = add_sat( xn_buf_fx[( i + ( ( overlap / 2 ) - tcx_offset ) )], old_out_fx[( i + nz )] ); // Q(-2) #endif @@ -3571,31 +3586,31 @@ void IMDCT_ivas_fx( // tested FOR( ; i < overlap; i++ ) /* perfectly reconstructing ALDO shortening */ { -#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD +#if defined(FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD) && !defined(FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN) tmp_old_out = shr_sat( old_out_fx[( i + nz )], q_diff ); - xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )] = add_sat( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], tmp_old_out ); // Q(-2) + xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )] = add_sat( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], tmp_old_out ); // q_win #else - xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )] = add_sat( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], old_out_fx[( i + nz )] ); // Q(-2) + xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )] = add_sat( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], old_out_fx[( i + nz )] ); // q_win #endif move16(); } FOR( i = 0; i < ( tcx_mdct_window_min_length / 2 ); i++ ) { -#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD +#if defined(FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD) && !defined(FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN) tmp_old_out = shr_sat( old_out_fx[( ( i + nz ) + overlap )], q_diff ); - xn_buf_fx[( ( ( i + ( overlap / 2 ) ) - tcx_offset ) + overlap )] = add_sat( xn_buf_fx[( ( ( i + ( overlap / 2 ) ) - tcx_offset ) + overlap )], mult_r( tmp_old_out, tcx_mdct_window_minimum_fx[i].v.re ) ); // Q(-2) + xn_buf_fx[( ( ( i + ( overlap / 2 ) ) - tcx_offset ) + overlap )] = add_sat( xn_buf_fx[( ( ( i + ( overlap / 2 ) ) - tcx_offset ) + overlap )], mult_r( tmp_old_out, tcx_mdct_window_minimum_fx[i].v.re ) ); // q_win #else - xn_buf_fx[( ( ( i + ( overlap / 2 ) ) - tcx_offset ) + overlap )] = add_sat( xn_buf_fx[( ( ( i + ( overlap / 2 ) ) - tcx_offset ) + overlap )], mult_r( old_out_fx[( ( i + nz ) + overlap )], tcx_mdct_window_minimum_fx[i].v.re ) ); // Q(-2) + xn_buf_fx[( ( ( i + ( overlap / 2 ) ) - tcx_offset ) + overlap )] = add_sat( xn_buf_fx[( ( ( i + ( overlap / 2 ) ) - tcx_offset ) + overlap )], mult_r( old_out_fx[( ( i + nz ) + overlap )], tcx_mdct_window_minimum_fx[i].v.re ) ); // q_win #endif move16(); } FOR( ; i < tcx_mdct_window_min_length; i++ ) { -#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD +#if defined(FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD) && !defined(FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN) tmp_old_out = shr_sat( old_out_fx[( ( i + nz ) + overlap )], q_diff ); - xn_buf_fx[( ( ( i + ( overlap / 2 ) ) - tcx_offset ) + overlap )] = add_sat( xn_buf_fx[( ( ( i + ( overlap / 2 ) ) - tcx_offset ) + overlap )], mult_r( tmp_old_out, tcx_mdct_window_minimum_fx[( tcx_mdct_window_min_length - ( 1 + i ) )].v.im ) ); // Q(-2) + xn_buf_fx[( ( ( i + ( overlap / 2 ) ) - tcx_offset ) + overlap )] = add_sat( xn_buf_fx[( ( ( i + ( overlap / 2 ) ) - tcx_offset ) + overlap )], mult_r( tmp_old_out, tcx_mdct_window_minimum_fx[( tcx_mdct_window_min_length - ( 1 + i ) )].v.im ) ); // q_win #else - xn_buf_fx[( ( ( i + ( overlap / 2 ) ) - tcx_offset ) + overlap )] = add_sat( xn_buf_fx[( ( ( i + ( overlap / 2 ) ) - tcx_offset ) + overlap )], mult_r( old_out_fx[( ( i + nz ) + overlap )], tcx_mdct_window_minimum_fx[( tcx_mdct_window_min_length - ( 1 + i ) )].v.im ) ); // Q(-2) + xn_buf_fx[( ( ( i + ( overlap / 2 ) ) - tcx_offset ) + overlap )] = add_sat( xn_buf_fx[( ( ( i + ( overlap / 2 ) ) - tcx_offset ) + overlap )], mult_r( old_out_fx[( ( i + nz ) + overlap )], tcx_mdct_window_minimum_fx[( tcx_mdct_window_min_length - ( 1 + i ) )].v.im ) ); // q_win #endif move16(); } @@ -3604,7 +3619,7 @@ void IMDCT_ivas_fx( { FOR( ; i < ( overlap - ( tcx_mdct_window_min_length / 2 ) ); i++ ) { -#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD +#if defined(FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD) && !defined(FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN) tmp_old_out = shr_sat( old_out_fx[( i + nz )], q_diff ); xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )] = add_sat( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], mult_r( tmp_old_out, tcx_mdct_window_minimum_fx[( ( tcx_mdct_window_min_length - overlap ) + i )].v.re ) ); // Q(-2) #else @@ -3614,7 +3629,7 @@ void IMDCT_ivas_fx( } FOR( ; i < overlap; i++ ) { -#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD +#if defined(FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD) && !defined(FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN) tmp_old_out = shr_sat( old_out_fx[( i + nz )], q_diff ); xn_buf_fx[( i + ( ( overlap / 2 ) - tcx_offset ) )] = add_sat( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], mult_r( tmp_old_out, tcx_mdct_window_minimum_fx[( overlap - ( 1 + i ) )].v.im ) ); // Q(-2) #else @@ -4182,6 +4197,7 @@ void decoder_tcx_ivas_fx( Copy_Scale_sig_16_32_no_sat( st->old_Aq_12_8_fx, st->old_Aq_12_8_fx_32, M + 1, ( sub( 28, ( sub( 15, norm_s( sub( st->old_Aq_12_8_fx[0], 1 ) ) ) ) ) ) ); Word16 q_win, q_winFB; + q_win = st->Q_syn; move16(); q_winFB = st->Q_syn; @@ -4189,12 +4205,12 @@ void decoder_tcx_ivas_fx( assert( q_win == 0 ); + Scale_sig( synth_fx, L_frame_glob, sub( q_win, st->Q_syn ) ); // Scaling to Q_syn + Scale_sig( synthFB_fx, L_frameTCX_glob, sub( q_winFB, st->Q_syn ) ); // Scaling to Q_syn + decoder_tcx_imdct_fx( st, L_frame_glob, L_frameTCX_glob, L_spec, tcx_offset, tcx_offsetFB, L_frame, L_frameTCX, left_rect, &x_fx[0], q_x, xn_buf_fx, &q_win, &q_winFB, MDCT_IV, fUseTns, &synth_fx[0], &synthFB_fx[0], bfi, frame_cnt, sba_dirac_stereo_flag ); - assert( q_win == 0 ); - assert( q_win == q_winFB ); - /* Scaling up again */ Scale_sig( synth_fx, L_frame_glob, sub( st->Q_syn, q_win ) ); Scale_sig( synthFB_fx, L_frameTCX_glob, sub( st->Q_syn, q_winFB ) ); @@ -5827,7 +5843,7 @@ void decoder_tcx_imdct_fx( { #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN - IMDCT_ivas_fx( xn_bufFB_fx, q_x, hTcxDec->syn_Overl, &hTcxDec->Q_syn_Overl, hTcxDec->syn_Overl_TDAC, &hTcxDec->Q_syn_Overl_TDAC, xn_buf_fx, hTcxCfg->tcx_aldo_window_1, hTcxCfg->tcx_aldo_window_1_trunc, hTcxCfg->tcx_aldo_window_2, + IMDCT_ivas_fx( xn_bufFB_fx, q_x, hTcxDec->syn_Overl, &hTcxDec->Q_syn_Overl, hTcxDec->syn_Overl_TDAC, &hTcxDec->Q_syn_Overl_TDAC, xn_buf_fx, *q_win, hTcxCfg->tcx_aldo_window_1, hTcxCfg->tcx_aldo_window_1_trunc, hTcxCfg->tcx_aldo_window_2, #else IMDCT_ivas_fx( xn_bufFB_fx, q_x, hTcxDec->syn_Overl, hTcxDec->syn_Overl_TDAC, xn_buf_fx, hTcxCfg->tcx_aldo_window_1, hTcxCfg->tcx_aldo_window_1_trunc, hTcxCfg->tcx_aldo_window_2, #endif @@ -5857,7 +5873,7 @@ void decoder_tcx_imdct_fx( { Copy32( x_fx, xn_bufFB_fx, s_max( L_spec, s_max( L_frame, L_frameTCX ) ) ); // q_x #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN - IMDCT_ivas_fx( xn_bufFB_fx, q_x, hTcxDec->syn_Overl, &hTcxDec->Q_syn_Overl, hTcxDec->syn_Overl_TDAC, &hTcxDec->Q_syn_Overl_TDAC, xn_buf_fx, hTcxCfg->tcx_aldo_window_1, hTcxCfg->tcx_aldo_window_1_trunc, hTcxCfg->tcx_aldo_window_2, hTcxCfg->tcx_mdct_window_half, hTcxCfg->tcx_mdct_window_minimum, hTcxCfg->tcx_mdct_window_trans, hTcxCfg->tcx_mdct_window_half_length, hTcxCfg->tcx_mdct_window_min_length, index, + IMDCT_ivas_fx( xn_bufFB_fx, q_x, hTcxDec->syn_Overl, &hTcxDec->Q_syn_Overl, hTcxDec->syn_Overl_TDAC, &hTcxDec->Q_syn_Overl_TDAC, xn_buf_fx, *q_win, hTcxCfg->tcx_aldo_window_1, hTcxCfg->tcx_aldo_window_1_trunc, hTcxCfg->tcx_aldo_window_2, hTcxCfg->tcx_mdct_window_half, hTcxCfg->tcx_mdct_window_minimum, hTcxCfg->tcx_mdct_window_trans, hTcxCfg->tcx_mdct_window_half_length, hTcxCfg->tcx_mdct_window_min_length, index, #else IMDCT_ivas_fx( xn_bufFB_fx, q_x, hTcxDec->syn_Overl, hTcxDec->syn_Overl_TDAC, xn_buf_fx, hTcxCfg->tcx_aldo_window_1, hTcxCfg->tcx_aldo_window_1_trunc, hTcxCfg->tcx_aldo_window_2, hTcxCfg->tcx_mdct_window_half, hTcxCfg->tcx_mdct_window_minimum, hTcxCfg->tcx_mdct_window_trans, hTcxCfg->tcx_mdct_window_half_length, hTcxCfg->tcx_mdct_window_min_length, index, #endif @@ -5869,12 +5885,17 @@ void decoder_tcx_imdct_fx( } #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN - Word16 shift_q = sub( q_x, *q_winFB ); + Word16 shift_q, q_x16; + + shift_q = L_norm_arr( xn_bufFB_fx, L_MDCT_OVLP_MAX + L_FRAME_PLUS + L_MDCT_OVLP_MAX ); + shift_q = sub( 16, shift_q ); + q_x16 = sub( q_x, shift_q ); #endif FOR( Word16 ind = 0; ind < L_MDCT_OVLP_MAX + L_FRAME_PLUS + L_MDCT_OVLP_MAX; ind++ ) { - xn_bufFB_fx_16[ind] = extract_l( L_shr( xn_bufFB_fx[ind], shift_q ) ); // q_x + assert( extract_h( L_shr( xn_bufFB_fx[ind], shift_q ) ) == 0 || extract_h( L_shr( xn_bufFB_fx[ind], shift_q ) ) == -1 ); + xn_bufFB_fx_16[ind] = extract_l( L_shr( xn_bufFB_fx[ind], shift_q ) ); // q_x16 move16(); } @@ -5885,7 +5906,7 @@ void decoder_tcx_imdct_fx( IF( st->element_mode != EVS_MONO ) { #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN - IMDCT_ivas_fx( x_tmp_fx, q_x, hTcxDec->syn_OverlFB, &hTcxDec->Q_syn_OverlFB, hTcxDec->syn_Overl_TDACFB, &hTcxDec->Q_syn_Overl_TDACFB, xn_bufFB_fx_16, hTcxCfg->tcx_aldo_window_1_FB, hTcxCfg->tcx_aldo_window_1_FB_trunc, hTcxCfg->tcx_aldo_window_2_FB, + IMDCT_ivas_fx( x_tmp_fx, q_x, hTcxDec->syn_OverlFB, &hTcxDec->Q_syn_OverlFB, hTcxDec->syn_Overl_TDACFB, &hTcxDec->Q_syn_Overl_TDACFB, xn_bufFB_fx_16, q_x16, hTcxCfg->tcx_aldo_window_1_FB, hTcxCfg->tcx_aldo_window_1_FB_trunc, hTcxCfg->tcx_aldo_window_2_FB, #else IMDCT_ivas_fx( x_tmp_fx, q_x, hTcxDec->syn_OverlFB, hTcxDec->syn_Overl_TDACFB, xn_bufFB_fx_16, hTcxCfg->tcx_aldo_window_1_FB, hTcxCfg->tcx_aldo_window_1_FB_trunc, hTcxCfg->tcx_aldo_window_2_FB, #endif @@ -5899,7 +5920,7 @@ void decoder_tcx_imdct_fx( ELSE { #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN - IMDCT_ivas_fx( x_fx, q_x, hTcxDec->syn_OverlFB, &hTcxDec->Q_syn_OverlFB, hTcxDec->syn_Overl_TDACFB, &hTcxDec->Q_syn_Overl_TDACFB, xn_bufFB_fx_16, hTcxCfg->tcx_aldo_window_1_FB, hTcxCfg->tcx_aldo_window_1_FB_trunc, hTcxCfg->tcx_aldo_window_2_FB, hTcxCfg->tcx_mdct_window_halfFB, hTcxCfg->tcx_mdct_window_minimumFB, hTcxCfg->tcx_mdct_window_transFB, hTcxCfg->tcx_mdct_window_half_lengthFB, hTcxCfg->tcx_mdct_window_min_lengthFB, index, + IMDCT_ivas_fx( x_fx, q_x, hTcxDec->syn_OverlFB, &hTcxDec->Q_syn_OverlFB, hTcxDec->syn_Overl_TDACFB, &hTcxDec->Q_syn_Overl_TDACFB, xn_bufFB_fx_16, q_x16, hTcxCfg->tcx_aldo_window_1_FB, hTcxCfg->tcx_aldo_window_1_FB_trunc, hTcxCfg->tcx_aldo_window_2_FB, hTcxCfg->tcx_mdct_window_halfFB, hTcxCfg->tcx_mdct_window_minimumFB, hTcxCfg->tcx_mdct_window_transFB, hTcxCfg->tcx_mdct_window_half_lengthFB, hTcxCfg->tcx_mdct_window_min_lengthFB, index, #else IMDCT_ivas_fx( x_fx, q_x, hTcxDec->syn_OverlFB, hTcxDec->syn_Overl_TDACFB, xn_bufFB_fx_16, hTcxCfg->tcx_aldo_window_1_FB, hTcxCfg->tcx_aldo_window_1_FB_trunc, hTcxCfg->tcx_aldo_window_2_FB, hTcxCfg->tcx_mdct_window_halfFB, hTcxCfg->tcx_mdct_window_minimumFB, hTcxCfg->tcx_mdct_window_transFB, hTcxCfg->tcx_mdct_window_half_lengthFB, hTcxCfg->tcx_mdct_window_min_lengthFB, index, #endif @@ -5911,12 +5932,13 @@ void decoder_tcx_imdct_fx( } #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN - shift_q = sub( q_x, *q_winFB ); + shift_q = 16; + move16(); #endif FOR( Word16 ind = 0; ind < L_MDCT_OVLP_MAX + L_FRAME_PLUS + L_MDCT_OVLP_MAX; ind++ ) { - xn_bufFB_fx[ind] = L_shl( L_deposit_l( xn_bufFB_fx_16[ind] ), shift_q ); // Q_x + xn_bufFB_fx[ind] = L_shl( L_deposit_l( xn_bufFB_fx_16[ind] ), shift_q ); // q_winFB } IF( ( bfi == 0 ) ) @@ -5958,18 +5980,21 @@ void decoder_tcx_imdct_fx( /* Update old_syn_overl */ IF( hTcxCfg->last_aldo == 0 ) { - Copy( xn_buf_fx + L_frame, hTcxDec->syn_Overl, overlap ); // Q(-2) + Copy( xn_buf_fx + L_frame, hTcxDec->syn_Overl, overlap ); // q_win FOR( Word16 ind = 0; ind < overlapFB; ind++ ) { - hTcxDec->syn_OverlFB[ind] = extract_l( L_shr( xn_bufFB_fx[( ind + L_frameTCX )], shift_q ) ); // q_x + assert( extract_h( L_shr( xn_bufFB_fx[( ind + L_frameTCX )], shift_q ) ) == 0 || extract_h( L_shr( xn_bufFB_fx[( ind + L_frameTCX )], shift_q ) ) == -1 ); + hTcxDec->syn_OverlFB[ind] = extract_l( L_shr( xn_bufFB_fx[( ind + L_frameTCX )], shift_q ) ); // q_winFB } } /* Output */ - Copy( xn_buf_fx + sub( shr( overlap, 1 ), tcx_offset ), synth_fx, L_frame_glob ); // Q(-2) + Copy( xn_buf_fx + sub( shr( overlap, 1 ), tcx_offset ), synth_fx, L_frame_glob ); // q_win FOR( Word16 ind = 0; ind < L_frameTCX_glob; ind++ ) { - synthFB_fx[ind] = extract_l( L_shr( xn_bufFB_fx[( ind + ( ( overlapFB >> 1 ) - tcx_offsetFB ) )], shift_q ) ); // q_x + assert( extract_h( L_shr( xn_bufFB_fx[( ind + ( ( overlapFB >> 1 ) - tcx_offsetFB ) )], shift_q ) ) == 0 || + extract_h( L_shr( xn_bufFB_fx[( ind + ( ( overlapFB >> 1 ) - tcx_offsetFB ) )], shift_q ) ) == -1 ); + synthFB_fx[ind] = extract_l( L_shr( xn_bufFB_fx[( ind + ( ( overlapFB >> 1 ) - tcx_offsetFB ) )], shift_q ) ); // q_winFB } diff --git a/lib_dec/ivas_mdct_core_dec_fx.c b/lib_dec/ivas_mdct_core_dec_fx.c index 0cec3dd72..00946b77d 100644 --- a/lib_dec/ivas_mdct_core_dec_fx.c +++ b/lib_dec/ivas_mdct_core_dec_fx.c @@ -1316,7 +1316,7 @@ void ivas_mdct_core_reconstruct_fx( // norm(old_out) + q_win >= st->Q_syn sf = s_min( getScaleFactor16( st->hHQ_core->old_out_fx, L_FRAME48k ), getScaleFactor16( st->hHQ_core->old_out_LB_fx, L_FRAME32k ) ); st->Q_syn = add( sf, s_min( q_win, q_winFB ) ); - +#if 0 Scale_sig( st->hTcxDec->syn_Overl_TDACFB, L_FRAME_MAX / 2, sub( sub( -1, st->Q_syn ), st->hTcxDec->Q_syn_Overl_TDACFB ) ); // q_winFB -> Q(-1 - st->Q_syn) st->hTcxDec->Q_syn_Overl_TDACFB = sub( -1, st->Q_syn ); move16(); @@ -1329,6 +1329,11 @@ void ivas_mdct_core_reconstruct_fx( st->hTcxDec->Q_syn_OverlFB = st->Q_syn; Scale_sig( st->hTcxDec->syn_Overl, L_FRAME32k / 2, sub( st->Q_syn, st->hTcxDec->Q_syn_Overl ) ); // q_win -> st->Q_syn st->hTcxDec->Q_syn_Overl = st->Q_syn; +#else + //Scale_sig( st->hTcxDec->old_syn_Overl, L_FRAME32k / 2, sub( -2, st->hTcxDec->Q_old_syn_Overl ) ); // q_win -> Q(-1 - st->Q_syn) + //st->hTcxDec->Q_old_syn_Overl = -2; +#endif + Scale_sig( synth_buf_fx, add( add( st->hTcxDec->old_synth_len, L_FRAME_PLUS ), M ), sub( q_syn, q_win ) ); // st->hTcxDec->q_old_synth -> q_syn Scale_sig( synth_bufFB_fx, add( add( st->hTcxDec->old_synth_lenFB, L_FRAME_PLUS ), M ), sub( q_syn, q_winFB ) ); // st->hTcxDec->q_old_synth -> q_syn // Scale_sig( st->syn, M + 1, add( st->Q_syn, 2 ) ); -- GitLab From 12f8828888afdfbc5d207497a210fa04634481e7 Mon Sep 17 00:00:00 2001 From: Manuel Jander Date: Wed, 21 May 2025 18:04:13 +0200 Subject: [PATCH 072/113] clang format --- lib_dec/dec_tcx_fx.c | 22 +++++++++++----------- lib_dec/ivas_mdct_core_dec_fx.c | 4 ++-- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index 49886cecf..f5929c853 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -2637,7 +2637,7 @@ static void IMDCT_ivas_fx_rescale( } #if 1 - Scale_sig(xn_buf_fx, L_MDCT_OVLP_MAX + L_FRAME_PLUS + L_MDCT_OVLP_MAX, sub ( q_win, *q_xn_buf_fx ) ); + Scale_sig( xn_buf_fx, L_MDCT_OVLP_MAX + L_FRAME_PLUS + L_MDCT_OVLP_MAX, sub( q_win, *q_xn_buf_fx ) ); *q_xn_buf_fx = q_win; move16(); Scale_sig( syn_Overl_TDAC, oldLength / 2, sub( q_win, *Q_syn_Overl_TDAC ) ); // st->hTcxDec->Q_syn_Overl_TDAC -> q_win @@ -2929,7 +2929,7 @@ void IMDCT_ivas_fx( Word16 *old_syn_overl_fx, // Q(-2) Word16 *syn_Overl_TDAC_fx, // Q(-2) #endif - Word16 *xn_buf_fx, // Q(-2) + Word16 *xn_buf_fx, // Q(-2) #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN Word16 q_xn_buf_fx, #endif @@ -3562,13 +3562,13 @@ void IMDCT_ivas_fx( IF( hTcxCfg->last_aldo != 0 ) { -#if defined(FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD) && !defined(FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN) +#if defined( FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD ) && !defined( FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN ) Word16 tmp_old_out; Word16 q_diff = sub( *q_old_out_fx, q_win ); #endif FOR( i = 0; i < sub( overlap, tcx_mdct_window_min_length ); i++ ) { -#if defined(FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD) && !defined(FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN) +#if defined( FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD ) && !defined( FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN ) tmp_old_out = shr_sat( old_out_fx[( i + nz )], q_diff ); xn_buf_fx[( i + ( ( overlap / 2 ) - tcx_offset ) )] = add_sat( xn_buf_fx[( i + ( ( overlap / 2 ) - tcx_offset ) )], tmp_old_out ); // q_win #else @@ -3586,7 +3586,7 @@ void IMDCT_ivas_fx( // tested FOR( ; i < overlap; i++ ) /* perfectly reconstructing ALDO shortening */ { -#if defined(FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD) && !defined(FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN) +#if defined( FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD ) && !defined( FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN ) tmp_old_out = shr_sat( old_out_fx[( i + nz )], q_diff ); xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )] = add_sat( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], tmp_old_out ); // q_win #else @@ -3596,7 +3596,7 @@ void IMDCT_ivas_fx( } FOR( i = 0; i < ( tcx_mdct_window_min_length / 2 ); i++ ) { -#if defined(FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD) && !defined(FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN) +#if defined( FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD ) && !defined( FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN ) tmp_old_out = shr_sat( old_out_fx[( ( i + nz ) + overlap )], q_diff ); xn_buf_fx[( ( ( i + ( overlap / 2 ) ) - tcx_offset ) + overlap )] = add_sat( xn_buf_fx[( ( ( i + ( overlap / 2 ) ) - tcx_offset ) + overlap )], mult_r( tmp_old_out, tcx_mdct_window_minimum_fx[i].v.re ) ); // q_win #else @@ -3606,7 +3606,7 @@ void IMDCT_ivas_fx( } FOR( ; i < tcx_mdct_window_min_length; i++ ) { -#if defined(FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD) && !defined(FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN) +#if defined( FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD ) && !defined( FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN ) tmp_old_out = shr_sat( old_out_fx[( ( i + nz ) + overlap )], q_diff ); xn_buf_fx[( ( ( i + ( overlap / 2 ) ) - tcx_offset ) + overlap )] = add_sat( xn_buf_fx[( ( ( i + ( overlap / 2 ) ) - tcx_offset ) + overlap )], mult_r( tmp_old_out, tcx_mdct_window_minimum_fx[( tcx_mdct_window_min_length - ( 1 + i ) )].v.im ) ); // q_win #else @@ -3619,7 +3619,7 @@ void IMDCT_ivas_fx( { FOR( ; i < ( overlap - ( tcx_mdct_window_min_length / 2 ) ); i++ ) { -#if defined(FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD) && !defined(FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN) +#if defined( FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD ) && !defined( FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN ) tmp_old_out = shr_sat( old_out_fx[( i + nz )], q_diff ); xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )] = add_sat( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], mult_r( tmp_old_out, tcx_mdct_window_minimum_fx[( ( tcx_mdct_window_min_length - overlap ) + i )].v.re ) ); // Q(-2) #else @@ -3629,7 +3629,7 @@ void IMDCT_ivas_fx( } FOR( ; i < overlap; i++ ) { -#if defined(FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD) && !defined(FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN) +#if defined( FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD ) && !defined( FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN ) tmp_old_out = shr_sat( old_out_fx[( i + nz )], q_diff ); xn_buf_fx[( i + ( ( overlap / 2 ) - tcx_offset ) )] = add_sat( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], mult_r( tmp_old_out, tcx_mdct_window_minimum_fx[( overlap - ( 1 + i ) )].v.im ) ); // Q(-2) #else @@ -4205,7 +4205,7 @@ void decoder_tcx_ivas_fx( assert( q_win == 0 ); - Scale_sig( synth_fx, L_frame_glob, sub( q_win, st->Q_syn ) ); // Scaling to Q_syn + Scale_sig( synth_fx, L_frame_glob, sub( q_win, st->Q_syn ) ); // Scaling to Q_syn Scale_sig( synthFB_fx, L_frameTCX_glob, sub( q_winFB, st->Q_syn ) ); // Scaling to Q_syn decoder_tcx_imdct_fx( st, L_frame_glob, L_frameTCX_glob, L_spec, tcx_offset, tcx_offsetFB, L_frame, L_frameTCX, left_rect, &x_fx[0], q_x, xn_buf_fx, &q_win, &q_winFB, MDCT_IV, @@ -5993,7 +5993,7 @@ void decoder_tcx_imdct_fx( FOR( Word16 ind = 0; ind < L_frameTCX_glob; ind++ ) { assert( extract_h( L_shr( xn_bufFB_fx[( ind + ( ( overlapFB >> 1 ) - tcx_offsetFB ) )], shift_q ) ) == 0 || - extract_h( L_shr( xn_bufFB_fx[( ind + ( ( overlapFB >> 1 ) - tcx_offsetFB ) )], shift_q ) ) == -1 ); + extract_h( L_shr( xn_bufFB_fx[( ind + ( ( overlapFB >> 1 ) - tcx_offsetFB ) )], shift_q ) ) == -1 ); synthFB_fx[ind] = extract_l( L_shr( xn_bufFB_fx[( ind + ( ( overlapFB >> 1 ) - tcx_offsetFB ) )], shift_q ) ); // q_winFB } diff --git a/lib_dec/ivas_mdct_core_dec_fx.c b/lib_dec/ivas_mdct_core_dec_fx.c index 00946b77d..dbfc46b7f 100644 --- a/lib_dec/ivas_mdct_core_dec_fx.c +++ b/lib_dec/ivas_mdct_core_dec_fx.c @@ -1330,8 +1330,8 @@ void ivas_mdct_core_reconstruct_fx( Scale_sig( st->hTcxDec->syn_Overl, L_FRAME32k / 2, sub( st->Q_syn, st->hTcxDec->Q_syn_Overl ) ); // q_win -> st->Q_syn st->hTcxDec->Q_syn_Overl = st->Q_syn; #else - //Scale_sig( st->hTcxDec->old_syn_Overl, L_FRAME32k / 2, sub( -2, st->hTcxDec->Q_old_syn_Overl ) ); // q_win -> Q(-1 - st->Q_syn) - //st->hTcxDec->Q_old_syn_Overl = -2; + // Scale_sig( st->hTcxDec->old_syn_Overl, L_FRAME32k / 2, sub( -2, st->hTcxDec->Q_old_syn_Overl ) ); // q_win -> Q(-1 - st->Q_syn) + // st->hTcxDec->Q_old_syn_Overl = -2; #endif Scale_sig( synth_buf_fx, add( add( st->hTcxDec->old_synth_len, L_FRAME_PLUS ), M ), sub( q_syn, q_win ) ); // st->hTcxDec->q_old_synth -> q_syn -- GitLab From 7c69312e25c9a50fe377c92041f935b774961d96 Mon Sep 17 00:00:00 2001 From: Manuel Jander Date: Thu, 22 May 2025 11:28:53 +0200 Subject: [PATCH 073/113] Undo wrong change to Q_old_wtda_LB. --- lib_dec/er_dec_acelp_fx.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib_dec/er_dec_acelp_fx.c b/lib_dec/er_dec_acelp_fx.c index 18c930269..3ffbcd139 100644 --- a/lib_dec/er_dec_acelp_fx.c +++ b/lib_dec/er_dec_acelp_fx.c @@ -1061,10 +1061,7 @@ void con_acelp_fx( move16(); } set16_fx( &hHQ_core->old_out_LB_fx[( W1 + n )], 0, n ); -#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT - hHQ_core->Q_old_wtda_LB = st->Q_syn; - move16(); -#else +#ifndef FIX_1348_BIT_PRECISION_IMPROVEMENT hHQ_core->Q_old_wtda = hHQ_core->Q_old_wtda_LB; move16(); #endif -- GitLab From 9f805bb9f29a243e826083a07cd25290a810aad1 Mon Sep 17 00:00:00 2001 From: Manuel Jander Date: Thu, 22 May 2025 13:09:10 +0200 Subject: [PATCH 074/113] Fix asser failure (saturation alarm) for stereo_at_64_kbps_32kHz_in_32kHz_out_bandwidth_switching -10dB case. --- lib_dec/dec_tcx_fx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index f5929c853..579d89968 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -3351,7 +3351,7 @@ void IMDCT_ivas_fx( Word16 diff = sub( q_tmp_fx_32, q_win ); #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD - Word16 q_old_out_diff = sub( q_tmp_fx_32, *q_old_out_fx ); + Word16 q_old_out_diff = s_max( sub( q_tmp_fx_32, *q_old_out_fx ), 0 ); #endif FOR( Word16 ind = 0; ind < L_frame; ind++ ) { -- GitLab From cfe8d30d8c35295601e96369fae85f0a8caf431d Mon Sep 17 00:00:00 2001 From: Manuel Jander Date: Thu, 22 May 2025 14:38:13 +0200 Subject: [PATCH 075/113] Fix EVS BE case stv8c_dtx_24400_8kHz.f06.COD stv8c_dtx_24400_8kHz.f06 --- lib_dec/er_dec_tcx_fx.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib_dec/er_dec_tcx_fx.c b/lib_dec/er_dec_tcx_fx.c index a1907b44c..775be6489 100644 --- a/lib_dec/er_dec_tcx_fx.c +++ b/lib_dec/er_dec_tcx_fx.c @@ -942,8 +942,10 @@ void con_tcx_fx( move16(); /* update memory for low band */ -#ifndef FIX_1348_BIT_PRECISION_IMPROVEMENT Scale_sig( hTcxDec->old_syn_Overl, shr( st->L_frame, 1 ), sub( -1, Q_syn ) ); /*Q_syn*/ +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT + hTcxDec->Q_old_syn_Overl = -1; + move16(); #endif lerp( hTcxDec->syn_OverlFB, hTcxDec->syn_Overl, shr( st->L_frame, 1 ), shr( L_frame, 1 ) ); #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT @@ -954,7 +956,7 @@ void con_tcx_fx( hTcxDec->Q_syn_Overl_TDAC = hTcxDec->Q_syn_Overl_TDACFB; move16(); lerp( st->hHQ_core->old_out_fx, st->hHQ_core->old_out_LB_fx, st->L_frame, L_frame ); -#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_NO hHQ_core->Q_old_wtda_LB = hHQ_core->Q_old_wtda; move16(); #endif -- GitLab From f938177b94b9ecb1425468f5d4321ccad45a49b2 Mon Sep 17 00:00:00 2001 From: Manuel Jander Date: Thu, 22 May 2025 16:03:22 +0200 Subject: [PATCH 076/113] Add missing adaption of Q_syn_OverlFB for error concealment case. This is likely an old bug that only now become more visible. --- lib_dec/ivas_mdct_core_dec_fx.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib_dec/ivas_mdct_core_dec_fx.c b/lib_dec/ivas_mdct_core_dec_fx.c index dbfc46b7f..bc4482837 100644 --- a/lib_dec/ivas_mdct_core_dec_fx.c +++ b/lib_dec/ivas_mdct_core_dec_fx.c @@ -1421,6 +1421,11 @@ void ivas_mdct_core_reconstruct_fx( st->Q_syn = q_syn; move16(); st->hTcxDec->Q_old_syn_Overl = add( st->hTcxDec->Q_old_syn_Overl, q_syn ); +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN + move16(); + st->hTcxDec->Q_syn_OverlFB = add( st->hTcxDec->Q_syn_OverlFB, q_syn ); + move16(); +#endif IF( ( EQ_16( st->nbLostCmpt, 1 ) ) || ( st->hTcxDec->tcxConceal_recalc_exc != 0 ) ) { -- GitLab From f866ba3f8b09e41b6ba9c9e788e8b4cc953aa4df Mon Sep 17 00:00:00 2001 From: Manuel Jander Date: Mon, 26 May 2025 08:23:55 +0200 Subject: [PATCH 077/113] Remove unnecessary change. The assignment hHQ_core->Q_old_wtda = Q_syn to be excpected here is found a few lines further away. --- lib_dec/er_dec_tcx_fx.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib_dec/er_dec_tcx_fx.c b/lib_dec/er_dec_tcx_fx.c index 775be6489..374e4c3a6 100644 --- a/lib_dec/er_dec_tcx_fx.c +++ b/lib_dec/er_dec_tcx_fx.c @@ -848,10 +848,6 @@ void con_tcx_fx( move16(); #endif Copy( syn + sub( L_frame, n ), hHQ_core->old_out_fx, sub( L_frame, n ) ); /*Q_syn*/ -#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT - hHQ_core->Q_old_wtda = Q_syn; - move16(); -#endif FOR( i = 0; i < W12; i++ ) { -- GitLab From e9f84b0b944f2405c3c498c6393ef8a053e4fe13 Mon Sep 17 00:00:00 2001 From: Manuel Jander Date: Mon, 26 May 2025 13:54:32 +0200 Subject: [PATCH 078/113] Remove wrong change. --- lib_dec/er_dec_acelp_fx.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib_dec/er_dec_acelp_fx.c b/lib_dec/er_dec_acelp_fx.c index 3ffbcd139..5f75b21bf 100644 --- a/lib_dec/er_dec_acelp_fx.c +++ b/lib_dec/er_dec_acelp_fx.c @@ -1061,10 +1061,8 @@ void con_acelp_fx( move16(); } set16_fx( &hHQ_core->old_out_LB_fx[( W1 + n )], 0, n ); -#ifndef FIX_1348_BIT_PRECISION_IMPROVEMENT hHQ_core->Q_old_wtda = hHQ_core->Q_old_wtda_LB; move16(); -#endif FOR( i = 0; i < W2; i++ ) { -- GitLab From 49308ae4d1d49b906de1a68bc35cbb0de68d3b6e Mon Sep 17 00:00:00 2001 From: Manuel Jander Date: Tue, 27 May 2025 17:55:01 +0200 Subject: [PATCH 079/113] Increase range for norm_arr() analysis for syn_Overl and old_out_fx. Skip scaling xn_buf_fx in cases where it is not applicable. --- lib_dec/dec_tcx_fx.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index 579d89968..1d35db9cc 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -2588,13 +2588,15 @@ static Word16 IMDCT_ivas_fx_calc_qwin( const Word16 L_frameTCX, const Word16 FB_flag ) { - Word16 oldLength; + Word16 oldLength, t; oldLength = s_min( L_FRAME32k, L_frame ); + t = L_FRAME32k; move16(); if ( FB_flag ) { oldLength = s_min( L_FRAME48k, L_frameTCX ); + t = L_FRAME48k; move16(); } @@ -2603,10 +2605,18 @@ static Word16 IMDCT_ivas_fx_calc_qwin( // q_win == norm + Q_syn_Overl_TDAC q_win = s_min( q_win, norm_arr( syn_Overl_TDAC, oldLength / 2 ) + Q_syn_Overl_TDAC ); - q_win = s_min( q_win, norm_arr( syn_Overl, oldLength / 2 ) + Q_syn_Overl ); + //q_win = s_min( q_win, norm_arr( syn_Overl, oldLength / 2 ) + Q_syn_Overl ); + q_win = s_min( q_win, norm_arr( syn_Overl, t / 2 ) + Q_syn_Overl ); q_win = s_min( q_win, norm_arr( old_syn_Overl, oldLength / 2 ) + Q_old_syn_Overl ); - q_win = s_min( q_win, norm_arr( old_out_fx, oldLength ) + Q_old_out_fx ); + //q_win = s_min( q_win, norm_arr( old_out_fx, oldLength ) + Q_old_out_fx ); + q_win = s_min( q_win, norm_arr( old_out_fx, t ) + Q_old_out_fx ); +#if 0 + set16_zero_fx(syn_Overl_TDAC + oldLength / 2, (t-oldLength)/2 ); + //set16_zero_fx(syn_Overl + oldLength / 2, (t-oldLength)/2 ); + set16_zero_fx(old_syn_Overl + oldLength / 2, (t-oldLength)/2 ); + //set16_zero_fx(old_out_fx + oldLength, (t-oldLength) ); +#endif q_win = s_max( -3, sub( q_win, 2 ) ); return q_win; @@ -2637,9 +2647,11 @@ static void IMDCT_ivas_fx_rescale( } #if 1 - Scale_sig( xn_buf_fx, L_MDCT_OVLP_MAX + L_FRAME_PLUS + L_MDCT_OVLP_MAX, sub( q_win, *q_xn_buf_fx ) ); - *q_xn_buf_fx = q_win; - move16(); + IF ( xn_buf_fx != NULL ) { + Scale_sig( xn_buf_fx, L_MDCT_OVLP_MAX + L_FRAME_PLUS + L_MDCT_OVLP_MAX, sub( q_win, *q_xn_buf_fx ) ); + *q_xn_buf_fx = q_win; + move16(); + } Scale_sig( syn_Overl_TDAC, oldLength / 2, sub( q_win, *Q_syn_Overl_TDAC ) ); // st->hTcxDec->Q_syn_Overl_TDAC -> q_win *Q_syn_Overl_TDAC = q_win; move16(); @@ -3346,7 +3358,7 @@ void IMDCT_ivas_fx( #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN // q_win < norm + q_tmp_fx_32 - 16 q_win = s_min( q_win, L_norm_arr( tmp_fx_32, L_frame ) + q_tmp_fx_32 - 16 ); - IMDCT_ivas_fx_rescale( xn_buf_fx, &q_xn_buf_fx, syn_Overl_TDAC_fx, Q_syn_Overl_TDAC_fx, old_syn_overl_fx, Q_old_syn_overl_fx, hTcxDec->old_syn_Overl, &hTcxDec->Q_old_syn_Overl, old_out_fx, q_old_out_fx, q_win, FB_flag ); + IMDCT_ivas_fx_rescale( NULL, NULL, syn_Overl_TDAC_fx, Q_syn_Overl_TDAC_fx, old_syn_overl_fx, Q_old_syn_overl_fx, hTcxDec->old_syn_Overl, &hTcxDec->Q_old_syn_Overl, old_out_fx, q_old_out_fx, q_win, FB_flag ); #endif Word16 diff = sub( q_tmp_fx_32, q_win ); @@ -3410,7 +3422,7 @@ void IMDCT_ivas_fx( // q_win == - 16 + L_norm_arr( xn_buf_fx_32, L_frame ) + q_xn_buf_fx_32 q_win = s_min( q_win, add( sub( q_xn_buf_fx_32, 16 ), L_norm_arr( xn_buf_fx_32, L_frame ) ) - 2 ); } - IMDCT_ivas_fx_rescale( xn_buf_fx, &q_xn_buf_fx, syn_Overl_TDAC_fx, Q_syn_Overl_TDAC_fx, old_syn_overl_fx, Q_old_syn_overl_fx, hTcxDec->old_syn_Overl, &hTcxDec->Q_old_syn_Overl, old_out_fx, q_old_out_fx, q_win, FB_flag ); + IMDCT_ivas_fx_rescale( NULL, NULL, syn_Overl_TDAC_fx, Q_syn_Overl_TDAC_fx, old_syn_overl_fx, Q_old_syn_overl_fx, hTcxDec->old_syn_Overl, &hTcxDec->Q_old_syn_Overl, old_out_fx, q_old_out_fx, q_win, FB_flag ); #endif Word16 q_diff = sub( q_xn_buf_fx_32, q_win ); -- GitLab From 812204af885a47f6bb9cb07b2b9ada632c864f58 Mon Sep 17 00:00:00 2001 From: Manuel Jander Date: Tue, 27 May 2025 17:58:06 +0200 Subject: [PATCH 080/113] clang format --- lib_dec/dec_tcx_fx.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index 1d35db9cc..172f32685 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -2605,10 +2605,10 @@ static Word16 IMDCT_ivas_fx_calc_qwin( // q_win == norm + Q_syn_Overl_TDAC q_win = s_min( q_win, norm_arr( syn_Overl_TDAC, oldLength / 2 ) + Q_syn_Overl_TDAC ); - //q_win = s_min( q_win, norm_arr( syn_Overl, oldLength / 2 ) + Q_syn_Overl ); + // q_win = s_min( q_win, norm_arr( syn_Overl, oldLength / 2 ) + Q_syn_Overl ); q_win = s_min( q_win, norm_arr( syn_Overl, t / 2 ) + Q_syn_Overl ); q_win = s_min( q_win, norm_arr( old_syn_Overl, oldLength / 2 ) + Q_old_syn_Overl ); - //q_win = s_min( q_win, norm_arr( old_out_fx, oldLength ) + Q_old_out_fx ); + // q_win = s_min( q_win, norm_arr( old_out_fx, oldLength ) + Q_old_out_fx ); q_win = s_min( q_win, norm_arr( old_out_fx, t ) + Q_old_out_fx ); #if 0 @@ -2647,7 +2647,8 @@ static void IMDCT_ivas_fx_rescale( } #if 1 - IF ( xn_buf_fx != NULL ) { + IF( xn_buf_fx != NULL ) + { Scale_sig( xn_buf_fx, L_MDCT_OVLP_MAX + L_FRAME_PLUS + L_MDCT_OVLP_MAX, sub( q_win, *q_xn_buf_fx ) ); *q_xn_buf_fx = q_win; move16(); -- GitLab From 3a4574860727f24356cd52fe6a5c20ab4fad68df Mon Sep 17 00:00:00 2001 From: Manuel Jander Date: Wed, 28 May 2025 10:42:02 +0200 Subject: [PATCH 081/113] Revert not rescaling of xn_buf_fx in case of MDCT TCX20. --- lib_dec/dec_tcx_fx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index 172f32685..4ab18e102 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -3423,7 +3423,7 @@ void IMDCT_ivas_fx( // q_win == - 16 + L_norm_arr( xn_buf_fx_32, L_frame ) + q_xn_buf_fx_32 q_win = s_min( q_win, add( sub( q_xn_buf_fx_32, 16 ), L_norm_arr( xn_buf_fx_32, L_frame ) ) - 2 ); } - IMDCT_ivas_fx_rescale( NULL, NULL, syn_Overl_TDAC_fx, Q_syn_Overl_TDAC_fx, old_syn_overl_fx, Q_old_syn_overl_fx, hTcxDec->old_syn_Overl, &hTcxDec->Q_old_syn_Overl, old_out_fx, q_old_out_fx, q_win, FB_flag ); + IMDCT_ivas_fx_rescale( xn_buf_fx, &q_xn_buf_fx, syn_Overl_TDAC_fx, Q_syn_Overl_TDAC_fx, old_syn_overl_fx, Q_old_syn_overl_fx, hTcxDec->old_syn_Overl, &hTcxDec->Q_old_syn_Overl, old_out_fx, q_old_out_fx, q_win, FB_flag ); #endif Word16 q_diff = sub( q_xn_buf_fx_32, q_win ); -- GitLab From dd2547843d55bebccc43249166d162daed28f9ca Mon Sep 17 00:00:00 2001 From: Manuel Jander Date: Mon, 2 Jun 2025 12:21:19 +0200 Subject: [PATCH 082/113] Remove asignment of Q value that leads to wrong old EXC and subsequently wrong BWE_TD EXC signals. --- lib_dec/ivas_core_dec_fx.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib_dec/ivas_core_dec_fx.c b/lib_dec/ivas_core_dec_fx.c index cf3d8c468..4def2242a 100644 --- a/lib_dec/ivas_core_dec_fx.c +++ b/lib_dec/ivas_core_dec_fx.c @@ -604,8 +604,10 @@ ivas_error ivas_core_dec_fx( stereo_tcx_core_dec_fx( st, frameMode[n], output_16_fx[n], synth_16_fx[n], pitch_buf_fx[n], sba_dirac_stereo_flag, hStereoTD, last_element_mode, flag_sec_CNA, hStereoCng, nchan_out, ivas_format ); +#ifndef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN st->hHQ_core->Q_old_wtda_LB = st->hHQ_core->Q_old_wtda; move16(); +#endif Copy_Scale_sig_16_32_DEPREC( output_16_fx[n], output_32_fx[n], output_frame, Q11 ); // Q11 IF( st->hTcxDec ) -- GitLab From 6ae2d5245bfa225979f06b9bdef6a7d76eda909c Mon Sep 17 00:00:00 2001 From: Manuel Jander Date: Mon, 2 Jun 2025 17:55:55 +0200 Subject: [PATCH 083/113] Change q_win values from -2 to Q15 for the case that a channel is skipped to avoid less precision in other channel of a CPE. --- lib_dec/ivas_mdct_core_dec_fx.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib_dec/ivas_mdct_core_dec_fx.c b/lib_dec/ivas_mdct_core_dec_fx.c index bc4482837..a8e97b0cf 100644 --- a/lib_dec/ivas_mdct_core_dec_fx.c +++ b/lib_dec/ivas_mdct_core_dec_fx.c @@ -1256,9 +1256,9 @@ void ivas_mdct_core_reconstruct_fx( ELSE { #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN - q_win = -2; + q_win = Q15; move16(); - q_winFB = -2; + q_winFB = Q15; move16(); #endif set16_fx( &synth_fx[k * L_frame[ch]], 0, L_frame[ch] ); -- GitLab From f06c3dbf256859248e191cda8423d9a820faf352 Mon Sep 17 00:00:00 2001 From: naghibza Date: Thu, 5 Jun 2025 14:18:19 +0200 Subject: [PATCH 084/113] Modified the length calculation of the old_syn_Overl buffer in q_win computation. --- lib_dec/dec_tcx_fx.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index 4ab18e102..6b68ef930 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -2575,6 +2575,7 @@ void IMDCT_fx( Word32 *x, Word16 x_e, Word16 *old_syn_overl, Word16 *syn_Overl_T #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN static Word16 IMDCT_ivas_fx_calc_qwin( + Decoder_State *st, Word16 *syn_Overl_TDAC, Word16 Q_syn_Overl_TDAC, Word16 *syn_Overl, @@ -2588,7 +2589,7 @@ static Word16 IMDCT_ivas_fx_calc_qwin( const Word16 L_frameTCX, const Word16 FB_flag ) { - Word16 oldLength, t; + Word16 oldLength, t, old_syn_Overl_len; oldLength = s_min( L_FRAME32k, L_frame ); t = L_FRAME32k; @@ -2600,14 +2601,20 @@ static Word16 IMDCT_ivas_fx_calc_qwin( move16(); } + old_syn_Overl_len = st->hTcxCfg->tcx_mdct_window_length; + IF( ( st->prev_bfi && EQ_16( st->last_core_bfi, ACELP_CORE ) ) || EQ_16( st->last_core, ACELP_CORE ) ) + { + old_syn_Overl_len = shr( st->L_frame, 1 ); + } + q_win = 6; move16(); // q_win == norm + Q_syn_Overl_TDAC - q_win = s_min( q_win, norm_arr( syn_Overl_TDAC, oldLength / 2 ) + Q_syn_Overl_TDAC ); + q_win = s_min( q_win, norm_arr( syn_Overl_TDAC, shr(oldLength, 1) ) + Q_syn_Overl_TDAC ); // q_win = s_min( q_win, norm_arr( syn_Overl, oldLength / 2 ) + Q_syn_Overl ); - q_win = s_min( q_win, norm_arr( syn_Overl, t / 2 ) + Q_syn_Overl ); - q_win = s_min( q_win, norm_arr( old_syn_Overl, oldLength / 2 ) + Q_old_syn_Overl ); + q_win = s_min( q_win, norm_arr( syn_Overl, shr(t, 1) ) + Q_syn_Overl ); + q_win = s_min( q_win, norm_arr( old_syn_Overl, old_syn_Overl_len ) + Q_old_syn_Overl ); // q_win = s_min( q_win, norm_arr( old_out_fx, oldLength ) + Q_old_out_fx ); q_win = s_min( q_win, norm_arr( old_out_fx, t ) + Q_old_out_fx ); @@ -3001,7 +3008,7 @@ void IMDCT_ivas_fx( IF( allow_qwin_change ) { // q_win = IMDCT_ivas_fx_adjust_qwin( *Q_syn_Overl_TDAC_fx, *Q_old_syn_overl_fx, hTcxDec->Q_old_syn_Overl, *q_old_out_fx, q_win ); - q_win = IMDCT_ivas_fx_calc_qwin( syn_Overl_TDAC_fx, *Q_syn_Overl_TDAC_fx, old_syn_overl_fx, *Q_old_syn_overl_fx, + q_win = IMDCT_ivas_fx_calc_qwin( st, syn_Overl_TDAC_fx, *Q_syn_Overl_TDAC_fx, old_syn_overl_fx, *Q_old_syn_overl_fx, hTcxDec->old_syn_Overl, hTcxDec->Q_old_syn_Overl, old_out_fx, *q_old_out_fx, q_win, L_frame, L_frameTCX, FB_flag ); } #else -- GitLab From d8a74f2a3593a5c61f259287dcd2a64bb240dce4 Mon Sep 17 00:00:00 2001 From: naghibza Date: Thu, 5 Jun 2025 14:36:27 +0200 Subject: [PATCH 085/113] Applied clang formatting patch. --- lib_dec/dec_tcx_fx.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index 6b68ef930..60c5e078a 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -2575,7 +2575,7 @@ void IMDCT_fx( Word32 *x, Word16 x_e, Word16 *old_syn_overl, Word16 *syn_Overl_T #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN static Word16 IMDCT_ivas_fx_calc_qwin( - Decoder_State *st, + Decoder_State *st, Word16 *syn_Overl_TDAC, Word16 Q_syn_Overl_TDAC, Word16 *syn_Overl, @@ -2589,7 +2589,7 @@ static Word16 IMDCT_ivas_fx_calc_qwin( const Word16 L_frameTCX, const Word16 FB_flag ) { - Word16 oldLength, t, old_syn_Overl_len; + Word16 oldLength, t, old_syn_Overl_len; oldLength = s_min( L_FRAME32k, L_frame ); t = L_FRAME32k; @@ -2606,14 +2606,14 @@ static Word16 IMDCT_ivas_fx_calc_qwin( { old_syn_Overl_len = shr( st->L_frame, 1 ); } - + q_win = 6; move16(); // q_win == norm + Q_syn_Overl_TDAC - q_win = s_min( q_win, norm_arr( syn_Overl_TDAC, shr(oldLength, 1) ) + Q_syn_Overl_TDAC ); + q_win = s_min( q_win, norm_arr( syn_Overl_TDAC, shr( oldLength, 1 ) ) + Q_syn_Overl_TDAC ); // q_win = s_min( q_win, norm_arr( syn_Overl, oldLength / 2 ) + Q_syn_Overl ); - q_win = s_min( q_win, norm_arr( syn_Overl, shr(t, 1) ) + Q_syn_Overl ); + q_win = s_min( q_win, norm_arr( syn_Overl, shr( t, 1 ) ) + Q_syn_Overl ); q_win = s_min( q_win, norm_arr( old_syn_Overl, old_syn_Overl_len ) + Q_old_syn_Overl ); // q_win = s_min( q_win, norm_arr( old_out_fx, oldLength ) + Q_old_out_fx ); q_win = s_min( q_win, norm_arr( old_out_fx, t ) + Q_old_out_fx ); -- GitLab From 7a7d3f5bf0cdd7472472f5191dc903648368d073 Mon Sep 17 00:00:00 2001 From: naghibza Date: Thu, 5 Jun 2025 16:44:43 +0200 Subject: [PATCH 086/113] Modified the length calculation of the Q_syn_Overl_TDAC and syn_Overl buffers in q_win computation. --- lib_dec/dec_tcx_fx.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index 60c5e078a..62c06a2c5 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -2589,7 +2589,7 @@ static Word16 IMDCT_ivas_fx_calc_qwin( const Word16 L_frameTCX, const Word16 FB_flag ) { - Word16 oldLength, t, old_syn_Overl_len; + Word16 oldLength, t, old_syn_Overl_len, syn_Overl_TDAC_len; oldLength = s_min( L_FRAME32k, L_frame ); t = L_FRAME32k; @@ -2602,18 +2602,26 @@ static Word16 IMDCT_ivas_fx_calc_qwin( } old_syn_Overl_len = st->hTcxCfg->tcx_mdct_window_length; + syn_Overl_TDAC_len = s_max( st->hTcxCfg->tcx_mdct_window_length_old, 0 ); + IF( ( st->prev_bfi && EQ_16( st->last_core_bfi, ACELP_CORE ) ) || EQ_16( st->last_core, ACELP_CORE ) ) { old_syn_Overl_len = shr( st->L_frame, 1 ); + syn_Overl_TDAC_len = shr( st->last_L_frame, 1 ); + } + + IF( st->prev_bfi && ( st->last_core_bfi == ACELP_CORE ) ) + { + syn_Overl_TDAC_len = old_syn_Overl_len; } q_win = 6; move16(); // q_win == norm + Q_syn_Overl_TDAC - q_win = s_min( q_win, norm_arr( syn_Overl_TDAC, shr( oldLength, 1 ) ) + Q_syn_Overl_TDAC ); + q_win = s_min( q_win, norm_arr( syn_Overl_TDAC, syn_Overl_TDAC_len ) + Q_syn_Overl_TDAC ); // q_win = s_min( q_win, norm_arr( syn_Overl, oldLength / 2 ) + Q_syn_Overl ); - q_win = s_min( q_win, norm_arr( syn_Overl, shr( t, 1 ) ) + Q_syn_Overl ); + q_win = s_min( q_win, norm_arr( syn_Overl, old_syn_Overl_len ) + Q_syn_Overl ); q_win = s_min( q_win, norm_arr( old_syn_Overl, old_syn_Overl_len ) + Q_old_syn_Overl ); // q_win = s_min( q_win, norm_arr( old_out_fx, oldLength ) + Q_old_out_fx ); q_win = s_min( q_win, norm_arr( old_out_fx, t ) + Q_old_out_fx ); -- GitLab From b5b3ab48befebdd592664b32917923af91639974 Mon Sep 17 00:00:00 2001 From: naghibza Date: Thu, 5 Jun 2025 16:50:01 +0200 Subject: [PATCH 087/113] Applied clang formatting patch. --- lib_dec/dec_tcx_fx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index 62c06a2c5..3604fa633 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -2609,7 +2609,7 @@ static Word16 IMDCT_ivas_fx_calc_qwin( old_syn_Overl_len = shr( st->L_frame, 1 ); syn_Overl_TDAC_len = shr( st->last_L_frame, 1 ); } - + IF( st->prev_bfi && ( st->last_core_bfi == ACELP_CORE ) ) { syn_Overl_TDAC_len = old_syn_Overl_len; -- GitLab From 2a7486511d2ecb39d5ddcd40d509e61545fbdd50 Mon Sep 17 00:00:00 2001 From: naghibza Date: Thu, 5 Jun 2025 17:11:02 +0200 Subject: [PATCH 088/113] Removed unused variable to solve linux build failure. --- lib_dec/dec_tcx_fx.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index 3604fa633..602aa7bbb 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -2589,14 +2589,12 @@ static Word16 IMDCT_ivas_fx_calc_qwin( const Word16 L_frameTCX, const Word16 FB_flag ) { - Word16 oldLength, t, old_syn_Overl_len, syn_Overl_TDAC_len; + Word16 t, old_syn_Overl_len, syn_Overl_TDAC_len; - oldLength = s_min( L_FRAME32k, L_frame ); t = L_FRAME32k; move16(); if ( FB_flag ) { - oldLength = s_min( L_FRAME48k, L_frameTCX ); t = L_FRAME48k; move16(); } -- GitLab From d43e90a0970fea160b9d20cae6ac4c6cee3592b4 Mon Sep 17 00:00:00 2001 From: naghibza Date: Thu, 5 Jun 2025 17:24:24 +0200 Subject: [PATCH 089/113] Removed unused variable to solve linux build failure. --- lib_dec/dec_tcx_fx.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index 602aa7bbb..c705ebd7a 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -2585,8 +2585,6 @@ static Word16 IMDCT_ivas_fx_calc_qwin( Word16 *old_out_fx, Word16 Q_old_out_fx, Word16 q_win, - const Word16 L_frame, - const Word16 L_frameTCX, const Word16 FB_flag ) { Word16 t, old_syn_Overl_len, syn_Overl_TDAC_len; @@ -3015,7 +3013,7 @@ void IMDCT_ivas_fx( { // q_win = IMDCT_ivas_fx_adjust_qwin( *Q_syn_Overl_TDAC_fx, *Q_old_syn_overl_fx, hTcxDec->Q_old_syn_Overl, *q_old_out_fx, q_win ); q_win = IMDCT_ivas_fx_calc_qwin( st, syn_Overl_TDAC_fx, *Q_syn_Overl_TDAC_fx, old_syn_overl_fx, *Q_old_syn_overl_fx, - hTcxDec->old_syn_Overl, hTcxDec->Q_old_syn_Overl, old_out_fx, *q_old_out_fx, q_win, L_frame, L_frameTCX, FB_flag ); + hTcxDec->old_syn_Overl, hTcxDec->Q_old_syn_Overl, old_out_fx, *q_old_out_fx, q_win, FB_flag ); } #else x_e_hdrm = add( q_win, sub( Q16, q_x ) ); -- GitLab From 83928e2f89822be2c7a09a5b7c435763298e0f44 Mon Sep 17 00:00:00 2001 From: naghibza Date: Mon, 16 Jun 2025 10:17:26 +0200 Subject: [PATCH 090/113] Reduced bit precision at the input of con_tcx_ivas_fx() as a temporary workaround to see the pipeline results. --- lib_dec/ivas_mdct_core_dec_fx.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib_dec/ivas_mdct_core_dec_fx.c b/lib_dec/ivas_mdct_core_dec_fx.c index a8e97b0cf..c818b7bf8 100644 --- a/lib_dec/ivas_mdct_core_dec_fx.c +++ b/lib_dec/ivas_mdct_core_dec_fx.c @@ -1392,6 +1392,11 @@ void ivas_mdct_core_reconstruct_fx( #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN Copy( st->hTcxDec->old_synth, synth_buf_fx, st->hTcxDec->old_synth_len ); // Q = st->hTcxDec->q_old_synth Copy_Scale_sig( st->hTcxDec->old_synthFB_fx, synth_bufFB_fx, st->hTcxDec->old_synth_lenFB, sub( st->hTcxDec->q_old_synth, st->Q_syn ) ); // Q = st->hTcxDec->q_old_synth + + // Temporary workaround: con_tcx_ivas_fx() should be analyzed for potential issues. + Scale_sig( synth_bufFB_fx, st->hTcxDec->old_synth_lenFB, -2 ); + Scale_sig( synth_bufFB_fx, st->hTcxDec->old_synth_lenFB, +2 ); + /////////////////////////////////////////////////////////////////////////////////// #endif assert( EQ_16( st->bfi, 1 ) ); /* PLC: [TCX: TD PLC] */ -- GitLab From 075d0b6792fe92e533edf4b0b66fdfb8b63fa021 Mon Sep 17 00:00:00 2001 From: naghibza Date: Mon, 16 Jun 2025 12:52:15 +0200 Subject: [PATCH 091/113] Modified Q_syn_Overl in the PLC calculation. Disabled temp. workaround for input of con_tcx_ivas_fx() --- lib_dec/ivas_mdct_core_dec_fx.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib_dec/ivas_mdct_core_dec_fx.c b/lib_dec/ivas_mdct_core_dec_fx.c index c818b7bf8..e64117a33 100644 --- a/lib_dec/ivas_mdct_core_dec_fx.c +++ b/lib_dec/ivas_mdct_core_dec_fx.c @@ -1099,8 +1099,8 @@ void ivas_mdct_core_reconstruct_fx( Word16 q_syn = 0; move16(); #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN - Word16 q_win; - Word16 q_winFB; + Word16 q_win = 0; + Word16 q_winFB = 0; #else #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT Word16 q_win = -1; @@ -1426,10 +1426,12 @@ void ivas_mdct_core_reconstruct_fx( st->Q_syn = q_syn; move16(); st->hTcxDec->Q_old_syn_Overl = add( st->hTcxDec->Q_old_syn_Overl, q_syn ); -#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN move16(); +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN st->hTcxDec->Q_syn_OverlFB = add( st->hTcxDec->Q_syn_OverlFB, q_syn ); move16(); + st->hTcxDec->Q_syn_Overl = add( st->hTcxDec->Q_syn_Overl, q_syn ); + move16(); #endif IF( ( EQ_16( st->nbLostCmpt, 1 ) ) || ( st->hTcxDec->tcxConceal_recalc_exc != 0 ) ) -- GitLab From 621bd86289f297947a5d287895bcb6b8279001a1 Mon Sep 17 00:00:00 2001 From: naghibza Date: Mon, 16 Jun 2025 13:40:01 +0200 Subject: [PATCH 092/113] Disabled temp. workaround for input of con_tcx_ivas_fx() --- lib_dec/ivas_mdct_core_dec_fx.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib_dec/ivas_mdct_core_dec_fx.c b/lib_dec/ivas_mdct_core_dec_fx.c index e64117a33..23639d47c 100644 --- a/lib_dec/ivas_mdct_core_dec_fx.c +++ b/lib_dec/ivas_mdct_core_dec_fx.c @@ -1394,8 +1394,8 @@ void ivas_mdct_core_reconstruct_fx( Copy_Scale_sig( st->hTcxDec->old_synthFB_fx, synth_bufFB_fx, st->hTcxDec->old_synth_lenFB, sub( st->hTcxDec->q_old_synth, st->Q_syn ) ); // Q = st->hTcxDec->q_old_synth // Temporary workaround: con_tcx_ivas_fx() should be analyzed for potential issues. - Scale_sig( synth_bufFB_fx, st->hTcxDec->old_synth_lenFB, -2 ); - Scale_sig( synth_bufFB_fx, st->hTcxDec->old_synth_lenFB, +2 ); + //Scale_sig( synth_bufFB_fx, st->hTcxDec->old_synth_lenFB, -2 ); + //Scale_sig( synth_bufFB_fx, st->hTcxDec->old_synth_lenFB, +2 ); /////////////////////////////////////////////////////////////////////////////////// #endif assert( EQ_16( st->bfi, 1 ) ); -- GitLab From 0d5df82909be067c36662ae04bb74611787a4d4e Mon Sep 17 00:00:00 2001 From: naghibza Date: Mon, 16 Jun 2025 13:44:35 +0200 Subject: [PATCH 093/113] Applied Clang patch. --- lib_dec/ivas_mdct_core_dec_fx.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib_dec/ivas_mdct_core_dec_fx.c b/lib_dec/ivas_mdct_core_dec_fx.c index 23639d47c..8beab3b3f 100644 --- a/lib_dec/ivas_mdct_core_dec_fx.c +++ b/lib_dec/ivas_mdct_core_dec_fx.c @@ -1394,8 +1394,8 @@ void ivas_mdct_core_reconstruct_fx( Copy_Scale_sig( st->hTcxDec->old_synthFB_fx, synth_bufFB_fx, st->hTcxDec->old_synth_lenFB, sub( st->hTcxDec->q_old_synth, st->Q_syn ) ); // Q = st->hTcxDec->q_old_synth // Temporary workaround: con_tcx_ivas_fx() should be analyzed for potential issues. - //Scale_sig( synth_bufFB_fx, st->hTcxDec->old_synth_lenFB, -2 ); - //Scale_sig( synth_bufFB_fx, st->hTcxDec->old_synth_lenFB, +2 ); + // Scale_sig( synth_bufFB_fx, st->hTcxDec->old_synth_lenFB, -2 ); + // Scale_sig( synth_bufFB_fx, st->hTcxDec->old_synth_lenFB, +2 ); /////////////////////////////////////////////////////////////////////////////////// #endif assert( EQ_16( st->bfi, 1 ) ); -- GitLab From 005edb871fec4a89f392f799f978e1e8716f5a4f Mon Sep 17 00:00:00 2001 From: naghibza Date: Mon, 16 Jun 2025 15:02:51 +0200 Subject: [PATCH 094/113] Modified q_win calculation for the case when all memory buffers are zero. Disabled Q_syn_Overl modification in PLC mode. --- lib_dec/dec_tcx_fx.c | 20 ++++++++++++++++---- lib_dec/ivas_mdct_core_dec_fx.c | 4 ++-- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index 4558de515..d0c4b1de3 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -2613,14 +2613,26 @@ static Word16 IMDCT_ivas_fx_calc_qwin( q_win = 6; move16(); + Word16 q_scale_syn_Overl_TDAC ,q_scale_syn_Overl, q_scale_old_syn_Overl, q_scale_old_out; // q_win == norm + Q_syn_Overl_TDAC - q_win = s_min( q_win, norm_arr( syn_Overl_TDAC, syn_Overl_TDAC_len ) + Q_syn_Overl_TDAC ); + q_scale_syn_Overl_TDAC = norm_arr( syn_Overl_TDAC, syn_Overl_TDAC_len ); + q_win = s_min( q_win, q_scale_syn_Overl_TDAC + Q_syn_Overl_TDAC ); + // q_win = s_min( q_win, norm_arr( syn_Overl, oldLength / 2 ) + Q_syn_Overl ); - q_win = s_min( q_win, norm_arr( syn_Overl, old_syn_Overl_len ) + Q_syn_Overl ); - q_win = s_min( q_win, norm_arr( old_syn_Overl, old_syn_Overl_len ) + Q_old_syn_Overl ); + q_scale_syn_Overl = norm_arr( syn_Overl, old_syn_Overl_len ); + q_win = s_min( q_win, q_scale_syn_Overl + Q_syn_Overl ); + + q_scale_old_syn_Overl = norm_arr( old_syn_Overl, old_syn_Overl_len ); + q_win = s_min( q_win, q_scale_old_syn_Overl + Q_old_syn_Overl ); + // q_win = s_min( q_win, norm_arr( old_out_fx, oldLength ) + Q_old_out_fx ); - q_win = s_min( q_win, norm_arr( old_out_fx, t ) + Q_old_out_fx ); + q_scale_old_out = norm_arr( old_out_fx, t ); + q_win = s_min( q_win, q_scale_old_out + Q_old_out_fx ); + + if ( q_scale_old_out == Q15 && q_scale_old_syn_Overl == Q15 && + q_scale_old_syn_Overl == Q15 && q_scale_syn_Overl_TDAC == Q15 ) + q_win = 0; #if 0 set16_zero_fx(syn_Overl_TDAC + oldLength / 2, (t-oldLength)/2 ); diff --git a/lib_dec/ivas_mdct_core_dec_fx.c b/lib_dec/ivas_mdct_core_dec_fx.c index 8beab3b3f..a97589ddf 100644 --- a/lib_dec/ivas_mdct_core_dec_fx.c +++ b/lib_dec/ivas_mdct_core_dec_fx.c @@ -1430,8 +1430,8 @@ void ivas_mdct_core_reconstruct_fx( #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN st->hTcxDec->Q_syn_OverlFB = add( st->hTcxDec->Q_syn_OverlFB, q_syn ); move16(); - st->hTcxDec->Q_syn_Overl = add( st->hTcxDec->Q_syn_Overl, q_syn ); - move16(); + //st->hTcxDec->Q_syn_Overl = add( st->hTcxDec->Q_syn_Overl, q_syn ); // It is disabled because it increased the number of regressions. + //move16(); #endif IF( ( EQ_16( st->nbLostCmpt, 1 ) ) || ( st->hTcxDec->tcxConceal_recalc_exc != 0 ) ) -- GitLab From 2c4d19b0af211b502aea4e40ca4b794590417329 Mon Sep 17 00:00:00 2001 From: naghibza Date: Mon, 16 Jun 2025 15:18:53 +0200 Subject: [PATCH 095/113] Applied Clang formatting patch. --- lib_dec/dec_tcx_fx.c | 22 +++++++++++----------- lib_dec/ivas_mdct_core_dec_fx.c | 4 ++-- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index d0c4b1de3..bb2c64cad 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -2613,25 +2613,25 @@ static Word16 IMDCT_ivas_fx_calc_qwin( q_win = 6; move16(); - Word16 q_scale_syn_Overl_TDAC ,q_scale_syn_Overl, q_scale_old_syn_Overl, q_scale_old_out; + Word16 q_shift_syn_Overl_TDAC, q_shift_syn_Overl, q_shift_old_syn_Overl, q_shift_old_out; // q_win == norm + Q_syn_Overl_TDAC - q_scale_syn_Overl_TDAC = norm_arr( syn_Overl_TDAC, syn_Overl_TDAC_len ); - q_win = s_min( q_win, q_scale_syn_Overl_TDAC + Q_syn_Overl_TDAC ); + q_shift_syn_Overl_TDAC = norm_arr( syn_Overl_TDAC, syn_Overl_TDAC_len ); + q_win = s_min( q_win, q_shift_syn_Overl_TDAC + Q_syn_Overl_TDAC ); // q_win = s_min( q_win, norm_arr( syn_Overl, oldLength / 2 ) + Q_syn_Overl ); - q_scale_syn_Overl = norm_arr( syn_Overl, old_syn_Overl_len ); - q_win = s_min( q_win, q_scale_syn_Overl + Q_syn_Overl ); + q_shift_syn_Overl = norm_arr( syn_Overl, old_syn_Overl_len ); + q_win = s_min( q_win, q_shift_syn_Overl + Q_syn_Overl ); - q_scale_old_syn_Overl = norm_arr( old_syn_Overl, old_syn_Overl_len ); - q_win = s_min( q_win, q_scale_old_syn_Overl + Q_old_syn_Overl ); + q_shift_old_syn_Overl = norm_arr( old_syn_Overl, old_syn_Overl_len ); + q_win = s_min( q_win, q_shift_old_syn_Overl + Q_old_syn_Overl ); // q_win = s_min( q_win, norm_arr( old_out_fx, oldLength ) + Q_old_out_fx ); - q_scale_old_out = norm_arr( old_out_fx, t ); - q_win = s_min( q_win, q_scale_old_out + Q_old_out_fx ); + q_shift_old_out = norm_arr( old_out_fx, t ); + q_win = s_min( q_win, q_shift_old_out + Q_old_out_fx ); - if ( q_scale_old_out == Q15 && q_scale_old_syn_Overl == Q15 && - q_scale_old_syn_Overl == Q15 && q_scale_syn_Overl_TDAC == Q15 ) + if ( q_shift_syn_Overl_TDAC == Q15 && q_shift_syn_Overl == Q15 && + q_shift_old_syn_Overl == Q15 && q_shift_old_out == Q15 ) q_win = 0; #if 0 diff --git a/lib_dec/ivas_mdct_core_dec_fx.c b/lib_dec/ivas_mdct_core_dec_fx.c index a97589ddf..01569aa62 100644 --- a/lib_dec/ivas_mdct_core_dec_fx.c +++ b/lib_dec/ivas_mdct_core_dec_fx.c @@ -1430,8 +1430,8 @@ void ivas_mdct_core_reconstruct_fx( #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN st->hTcxDec->Q_syn_OverlFB = add( st->hTcxDec->Q_syn_OverlFB, q_syn ); move16(); - //st->hTcxDec->Q_syn_Overl = add( st->hTcxDec->Q_syn_Overl, q_syn ); // It is disabled because it increased the number of regressions. - //move16(); + // st->hTcxDec->Q_syn_Overl = add( st->hTcxDec->Q_syn_Overl, q_syn ); // It is disabled because it increased the number of regressions. + // move16(); #endif IF( ( EQ_16( st->nbLostCmpt, 1 ) ) || ( st->hTcxDec->tcxConceal_recalc_exc != 0 ) ) -- GitLab From b21540b59f1d6cac6a5aee2a763befde42d383b1 Mon Sep 17 00:00:00 2001 From: Manuel Jander Date: Mon, 16 Jun 2025 15:42:09 +0200 Subject: [PATCH 096/113] Use Q0 for synthFB_fx during PLC. Set Q_old_wtda and Q_old_wtdaLB to Q15 to avoid precision loss in case of zero signal for next frame. --- lib_dec/ivas_mdct_core_dec_fx.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib_dec/ivas_mdct_core_dec_fx.c b/lib_dec/ivas_mdct_core_dec_fx.c index 01569aa62..34bcb28cf 100644 --- a/lib_dec/ivas_mdct_core_dec_fx.c +++ b/lib_dec/ivas_mdct_core_dec_fx.c @@ -1266,7 +1266,7 @@ void ivas_mdct_core_reconstruct_fx( /* Note: these buffers are not subframe-based, hence no indexing with k */ set16_fx( &st->hHQ_core->old_out_LB_fx[0], 0, L_frame[ch] ); set16_fx( &st->hHQ_core->old_out_fx[0], 0, L_frameTCX[ch] ); -#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD_NO +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD st->hHQ_core->Q_old_wtda = Q15; st->hHQ_core->Q_old_wtda_LB = Q15; #endif @@ -1390,6 +1390,7 @@ void ivas_mdct_core_reconstruct_fx( ELSE /*ACELP core for ACELP-PLC */ { #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN +#if 0 Copy( st->hTcxDec->old_synth, synth_buf_fx, st->hTcxDec->old_synth_len ); // Q = st->hTcxDec->q_old_synth Copy_Scale_sig( st->hTcxDec->old_synthFB_fx, synth_bufFB_fx, st->hTcxDec->old_synth_lenFB, sub( st->hTcxDec->q_old_synth, st->Q_syn ) ); // Q = st->hTcxDec->q_old_synth @@ -1397,6 +1398,11 @@ void ivas_mdct_core_reconstruct_fx( // Scale_sig( synth_bufFB_fx, st->hTcxDec->old_synth_lenFB, -2 ); // Scale_sig( synth_bufFB_fx, st->hTcxDec->old_synth_lenFB, +2 ); /////////////////////////////////////////////////////////////////////////////////// +#else + Copy_Scale_sig( st->hTcxDec->old_synth, synth_buf_fx, st->hTcxDec->old_synth_len, sub(0, st->hTcxDec->q_old_synth ) ); // Q = st->hTcxDec->q_old_synth -> Q0 + Copy_Scale_sig( st->hTcxDec->old_synthFB_fx, synth_bufFB_fx, st->hTcxDec->old_synth_lenFB, sub( 0, st->Q_syn ) ); // Q = st->hTcxDec->q_old_synth -> Q0 + q_syn = 0; +#endif #endif assert( EQ_16( st->bfi, 1 ) ); /* PLC: [TCX: TD PLC] */ -- GitLab From 30f647b1774771eb0d0fcb4d86b8b0c5c2af7668 Mon Sep 17 00:00:00 2001 From: Manuel Jander Date: Mon, 16 Jun 2025 15:45:17 +0200 Subject: [PATCH 097/113] clang format --- lib_dec/ivas_mdct_core_dec_fx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_dec/ivas_mdct_core_dec_fx.c b/lib_dec/ivas_mdct_core_dec_fx.c index 34bcb28cf..74ba24767 100644 --- a/lib_dec/ivas_mdct_core_dec_fx.c +++ b/lib_dec/ivas_mdct_core_dec_fx.c @@ -1399,7 +1399,7 @@ void ivas_mdct_core_reconstruct_fx( // Scale_sig( synth_bufFB_fx, st->hTcxDec->old_synth_lenFB, +2 ); /////////////////////////////////////////////////////////////////////////////////// #else - Copy_Scale_sig( st->hTcxDec->old_synth, synth_buf_fx, st->hTcxDec->old_synth_len, sub(0, st->hTcxDec->q_old_synth ) ); // Q = st->hTcxDec->q_old_synth -> Q0 + Copy_Scale_sig( st->hTcxDec->old_synth, synth_buf_fx, st->hTcxDec->old_synth_len, sub( 0, st->hTcxDec->q_old_synth ) ); // Q = st->hTcxDec->q_old_synth -> Q0 Copy_Scale_sig( st->hTcxDec->old_synthFB_fx, synth_bufFB_fx, st->hTcxDec->old_synth_lenFB, sub( 0, st->Q_syn ) ); // Q = st->hTcxDec->q_old_synth -> Q0 q_syn = 0; #endif -- GitLab From 2362d2922d4ccdace84d9b27c6bde875cd78174b Mon Sep 17 00:00:00 2001 From: naghibza Date: Tue, 17 Jun 2025 15:14:26 +0200 Subject: [PATCH 098/113] Modified dynamic q_win calculation in IMDCT_ivas_fx() --- lib_dec/dec_tcx_fx.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index bb2c64cad..7025ee066 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -2613,26 +2613,17 @@ static Word16 IMDCT_ivas_fx_calc_qwin( q_win = 6; move16(); - Word16 q_shift_syn_Overl_TDAC, q_shift_syn_Overl, q_shift_old_syn_Overl, q_shift_old_out; // q_win == norm + Q_syn_Overl_TDAC - q_shift_syn_Overl_TDAC = norm_arr( syn_Overl_TDAC, syn_Overl_TDAC_len ); - q_win = s_min( q_win, q_shift_syn_Overl_TDAC + Q_syn_Overl_TDAC ); + q_win = s_min( q_win, norm_arr( syn_Overl_TDAC, syn_Overl_TDAC_len ) + Q_syn_Overl_TDAC ); // q_win = s_min( q_win, norm_arr( syn_Overl, oldLength / 2 ) + Q_syn_Overl ); - q_shift_syn_Overl = norm_arr( syn_Overl, old_syn_Overl_len ); - q_win = s_min( q_win, q_shift_syn_Overl + Q_syn_Overl ); + q_win = s_min( q_win, norm_arr( syn_Overl, old_syn_Overl_len ) + Q_syn_Overl ); - q_shift_old_syn_Overl = norm_arr( old_syn_Overl, old_syn_Overl_len ); - q_win = s_min( q_win, q_shift_old_syn_Overl + Q_old_syn_Overl ); + q_win = s_min( q_win, norm_arr( old_syn_Overl, old_syn_Overl_len ) + Q_old_syn_Overl ); // q_win = s_min( q_win, norm_arr( old_out_fx, oldLength ) + Q_old_out_fx ); - q_shift_old_out = norm_arr( old_out_fx, t ); - q_win = s_min( q_win, q_shift_old_out + Q_old_out_fx ); - - if ( q_shift_syn_Overl_TDAC == Q15 && q_shift_syn_Overl == Q15 && - q_shift_old_syn_Overl == Q15 && q_shift_old_out == Q15 ) - q_win = 0; + q_win = s_min( q_win, norm_arr( old_out_fx, t ) + Q_old_out_fx ); #if 0 set16_zero_fx(syn_Overl_TDAC + oldLength / 2, (t-oldLength)/2 ); @@ -3471,7 +3462,15 @@ void IMDCT_ivas_fx( q_diff = sub( q_old_out, q_win ); #endif - +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN + if ( allow_qwin_change ) + { + // sub( q_tmp_fx_32, q_win ) == -norm_arr( xn_buf_fx, L_frame ) + // q_tmp_fx_32 - q_win == -norm_arr( xn_buf_fx, L_frame ) + // q_win == q_tmp_fx_32 + norm_arr( xn_buf_fx, L_frame ) + q_win = s_min( q_win, add( q_tmp_fx_32, norm_arr( xn_buf_fx, L_frame ) ) ); + } +#endif Word16 diff = sub( q_tmp_fx_32, q_win ); FOR( Word16 ind = 0; ind < L_frame; ind++ ) { -- GitLab From d45dfc4284e328e425dae1dd5bfa8496cae5220b Mon Sep 17 00:00:00 2001 From: naghibza Date: Tue, 17 Jun 2025 15:28:39 +0200 Subject: [PATCH 099/113] Applied Clang formatting patch. --- lib_dec/dec_tcx_fx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index 7025ee066..c808df560 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -3464,7 +3464,7 @@ void IMDCT_ivas_fx( #endif #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN if ( allow_qwin_change ) - { + { // sub( q_tmp_fx_32, q_win ) == -norm_arr( xn_buf_fx, L_frame ) // q_tmp_fx_32 - q_win == -norm_arr( xn_buf_fx, L_frame ) // q_win == q_tmp_fx_32 + norm_arr( xn_buf_fx, L_frame ) -- GitLab From b8a4ceba02f3f9d1216fc82592fc15aec4488308 Mon Sep 17 00:00:00 2001 From: naghibza Date: Mon, 23 Jun 2025 12:20:52 +0200 Subject: [PATCH 100/113] Corrected the scaling of st->mem_syn2_fx. --- lib_dec/ivas_mdct_core_dec_fx.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib_dec/ivas_mdct_core_dec_fx.c b/lib_dec/ivas_mdct_core_dec_fx.c index 74ba24767..d09eb4574 100644 --- a/lib_dec/ivas_mdct_core_dec_fx.c +++ b/lib_dec/ivas_mdct_core_dec_fx.c @@ -1338,6 +1338,15 @@ void ivas_mdct_core_reconstruct_fx( Scale_sig( synth_bufFB_fx, add( add( st->hTcxDec->old_synth_lenFB, L_FRAME_PLUS ), M ), sub( q_syn, q_winFB ) ); // st->hTcxDec->q_old_synth -> q_syn // Scale_sig( st->syn, M + 1, add( st->Q_syn, 2 ) ); Scale_sig( st->syn, M + 1, sub( st->Q_syn, q_win ) ); + + IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) ) + { + Scale_sig( st->mem_syn2_fx, M, sub( st->Q_syn, st->prev_Q_syn ) ); // st->Q_syn gets a new value, but st->mem_syn2_fx got its value from E_UTIL_f_preemph3 with st->Q_syn = st->prev_Q_syn + } + ELSE + { + Scale_sig( st->mem_syn2_fx, M, sub( st->Q_syn, add( q_win, 2 ) ) ); // q_win+2 -> st->Q_syn: in this case, E_UTIL_f_preemph2 shifts st->mem_syn2_fx by 2 bits + } #else test(); IF( ( bfi == 0 ) && st->hTonalMDCTConc != NULL ) -- GitLab From 1d1b53a5a5552a746d563bc9ada69810c20cd0da Mon Sep 17 00:00:00 2001 From: Manuel Jander Date: Mon, 23 Jun 2025 18:16:41 +0200 Subject: [PATCH 101/113] Avoid rescale of Q_syn_Overl_TDACFB in TCX PLC, just copy it with current Q value. Also add comment on Q value asignment so it is clear where it comes from after lerp(). --- lib_dec/er_dec_tcx_fx.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib_dec/er_dec_tcx_fx.c b/lib_dec/er_dec_tcx_fx.c index 374e4c3a6..5c9b4dcbf 100644 --- a/lib_dec/er_dec_tcx_fx.c +++ b/lib_dec/er_dec_tcx_fx.c @@ -1860,9 +1860,14 @@ void con_tcx_ivas_fx( move16(); /* create aliasing and windowing need for transition to TCX10/5 */ +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT + Copy( syn + L_frame, hTcxDec->syn_Overl_TDACFB, shr( L_frame, 1 ) ); + hTcxDec->Q_syn_Overl_TDACFB = Q_syn; +#else // bufferCopyFx( syn + L_frame, hTcxDec->syn_Overl_TDACFB, shr( L_frame, 1 ), Q_syn, 0, -1, 0 ); Copy_Scale_sig( syn + L_frame, hTcxDec->syn_Overl_TDACFB, shr( L_frame, 1 ), sub( Q_syn, 1 ) ); hTcxDec->Q_syn_Overl_TDACFB = sub( Q_syn, 1 ); +#endif move16(); FOR( i = 0; i < W12; i++ ) @@ -1922,7 +1927,7 @@ void con_tcx_ivas_fx( hTcxDec->Q_syn_Overl_TDAC = hTcxDec->Q_syn_Overl_TDACFB; move16(); lerp( st->hHQ_core->old_out_fx, st->hHQ_core->old_out_LB_fx, st->L_frame, L_frame ); - st->hHQ_core->Q_old_wtda_LB = Q_syn; + st->hHQ_core->Q_old_wtda_LB = Q_syn; // st->hHQ_core->Q_old_wtda st->old_enr_LP = Enr_1_Az_fx( A_local, L_SUBFR ); /*Q3*/ move16(); -- GitLab From 1f09e81bea4eed7d404af5ce613f8366fa9c35fd Mon Sep 17 00:00:00 2001 From: Manuel Jander Date: Mon, 23 Jun 2025 18:20:31 +0200 Subject: [PATCH 102/113] clang format --- lib_dec/er_dec_tcx_fx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_dec/er_dec_tcx_fx.c b/lib_dec/er_dec_tcx_fx.c index 5c9b4dcbf..37465bc29 100644 --- a/lib_dec/er_dec_tcx_fx.c +++ b/lib_dec/er_dec_tcx_fx.c @@ -1927,7 +1927,7 @@ void con_tcx_ivas_fx( hTcxDec->Q_syn_Overl_TDAC = hTcxDec->Q_syn_Overl_TDACFB; move16(); lerp( st->hHQ_core->old_out_fx, st->hHQ_core->old_out_LB_fx, st->L_frame, L_frame ); - st->hHQ_core->Q_old_wtda_LB = Q_syn; // st->hHQ_core->Q_old_wtda + st->hHQ_core->Q_old_wtda_LB = Q_syn; // st->hHQ_core->Q_old_wtda st->old_enr_LP = Enr_1_Az_fx( A_local, L_SUBFR ); /*Q3*/ move16(); -- GitLab From 8d1d97234e5a270fcc66c5aec279cdca6a771f4e Mon Sep 17 00:00:00 2001 From: naghibza Date: Tue, 24 Jun 2025 12:24:04 +0200 Subject: [PATCH 103/113] Modify q_old_out_diff calculation in IMDCT_ivas_fx for TCX-20 and not TCX-only frames. --- lib_dec/dec_tcx_fx.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index d12eabe4f..9e28adeb6 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -3385,7 +3385,8 @@ void IMDCT_ivas_fx( Word16 diff = sub( q_tmp_fx_32, q_win ); #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD - Word16 q_old_out_diff = s_max( sub( q_tmp_fx_32, *q_old_out_fx ), 0 ); + // Word16 q_old_out_diff = s_max( sub( q_tmp_fx_32, *q_old_out_fx ), 0 ); + Word16 q_old_out_diff = sub( q_tmp_fx_32, *q_old_out_fx ); #endif FOR( Word16 ind = 0; ind < L_frame; ind++ ) { -- GitLab From a4d1c5451a340fd0e53f970f63674aecea17e091 Mon Sep 17 00:00:00 2001 From: naghibza Date: Tue, 24 Jun 2025 14:11:31 +0200 Subject: [PATCH 104/113] Modify q_old_out_diff calculation in IMDCT_ivas_fx for TCX-20 and not TCX-only frames. --- lib_dec/dec_tcx_fx.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index 9e28adeb6..0e0c6b436 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -3385,8 +3385,13 @@ void IMDCT_ivas_fx( Word16 diff = sub( q_tmp_fx_32, q_win ); #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD - // Word16 q_old_out_diff = s_max( sub( q_tmp_fx_32, *q_old_out_fx ), 0 ); Word16 q_old_out_diff = sub( q_tmp_fx_32, *q_old_out_fx ); + IF( q_old_out_diff < 0) + { + Scale_sig( old_out_fx, L_frame, q_old_out_diff ); + *q_old_out_fx = add( *q_old_out_fx, q_old_out_diff ); + q_old_out_diff = 0; + } #endif FOR( Word16 ind = 0; ind < L_frame; ind++ ) { -- GitLab From 7a097aea15847416726d624fe5cafae68ad5addd Mon Sep 17 00:00:00 2001 From: naghibza Date: Tue, 24 Jun 2025 14:15:46 +0200 Subject: [PATCH 105/113] Applied Clang formatting patch. --- lib_dec/dec_tcx_fx.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index 0e0c6b436..b993f6753 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -3386,9 +3386,9 @@ void IMDCT_ivas_fx( Word16 diff = sub( q_tmp_fx_32, q_win ); #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD Word16 q_old_out_diff = sub( q_tmp_fx_32, *q_old_out_fx ); - IF( q_old_out_diff < 0) + IF( q_old_out_diff < 0 ) { - Scale_sig( old_out_fx, L_frame, q_old_out_diff ); + Scale_sig( old_out_fx, L_frame, q_old_out_diff ); *q_old_out_fx = add( *q_old_out_fx, q_old_out_diff ); q_old_out_diff = 0; } -- GitLab From bbc0239477818535ded11a5abed0b446b35e7753 Mon Sep 17 00:00:00 2001 From: Manuel Jander Date: Tue, 24 Jun 2025 17:56:30 +0200 Subject: [PATCH 106/113] Remove old unused code (no change), the purpose is to retrigger the pipeline because the reports are empty. --- lib_dec/ivas_mdct_core_dec_fx.c | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/lib_dec/ivas_mdct_core_dec_fx.c b/lib_dec/ivas_mdct_core_dec_fx.c index f119a8c1f..7f17bb0fc 100644 --- a/lib_dec/ivas_mdct_core_dec_fx.c +++ b/lib_dec/ivas_mdct_core_dec_fx.c @@ -1320,23 +1320,6 @@ void ivas_mdct_core_reconstruct_fx( // norm(old_out) + q_win >= st->Q_syn sf = s_min( getScaleFactor16( st->hHQ_core->old_out_fx, L_FRAME48k ), getScaleFactor16( st->hHQ_core->old_out_LB_fx, L_FRAME32k ) ); st->Q_syn = add( sf, s_min( q_win, q_winFB ) ); -#if 0 - Scale_sig( st->hTcxDec->syn_Overl_TDACFB, L_FRAME_MAX / 2, sub( sub( -1, st->Q_syn ), st->hTcxDec->Q_syn_Overl_TDACFB ) ); // q_winFB -> Q(-1 - st->Q_syn) - st->hTcxDec->Q_syn_Overl_TDACFB = sub( -1, st->Q_syn ); - move16(); - Scale_sig( st->hTcxDec->syn_Overl_TDAC, L_FRAME32k / 2, sub( sub( -1, st->Q_syn ), st->hTcxDec->Q_syn_Overl_TDAC ) ); // q_win -> Q(-1 - st->Q_syn) - st->hTcxDec->Q_syn_Overl_TDAC = sub( -1, st->Q_syn ); - move16(); - Scale_sig( st->hTcxDec->old_syn_Overl, L_FRAME32k / 2, sub( sub( -1, st->Q_syn ), st->hTcxDec->Q_old_syn_Overl ) ); // q_win -> Q(-1 - st->Q_syn) - st->hTcxDec->Q_old_syn_Overl = sub( -1, st->Q_syn ); - Scale_sig( st->hTcxDec->syn_OverlFB, L_FRAME_MAX / 2, sub( st->Q_syn, st->hTcxDec->Q_syn_OverlFB ) ); // q_winFB -> st->Q_syn - st->hTcxDec->Q_syn_OverlFB = st->Q_syn; - Scale_sig( st->hTcxDec->syn_Overl, L_FRAME32k / 2, sub( st->Q_syn, st->hTcxDec->Q_syn_Overl ) ); // q_win -> st->Q_syn - st->hTcxDec->Q_syn_Overl = st->Q_syn; -#else - // Scale_sig( st->hTcxDec->old_syn_Overl, L_FRAME32k / 2, sub( -2, st->hTcxDec->Q_old_syn_Overl ) ); // q_win -> Q(-1 - st->Q_syn) - // st->hTcxDec->Q_old_syn_Overl = -2; -#endif Scale_sig( synth_buf_fx, add( add( st->hTcxDec->old_synth_len, L_FRAME_PLUS ), M ), sub( q_syn, q_win ) ); // st->hTcxDec->q_old_synth -> q_syn Scale_sig( synth_bufFB_fx, add( add( st->hTcxDec->old_synth_lenFB, L_FRAME_PLUS ), M ), sub( q_syn, q_winFB ) ); // st->hTcxDec->q_old_synth -> q_syn -- GitLab From 87caabb2da09f7113bf2d3c0ad9a86567e9d2d45 Mon Sep 17 00:00:00 2001 From: Manuel Jander Date: Wed, 25 Jun 2025 17:02:37 +0200 Subject: [PATCH 107/113] Revert from change b21540b59f1d6cac6a5aee2a763befde42d383b1 Q0 for q_syn in PLC case. --- lib_dec/ivas_mdct_core_dec_fx.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/lib_dec/ivas_mdct_core_dec_fx.c b/lib_dec/ivas_mdct_core_dec_fx.c index 7f17bb0fc..1cce316f1 100644 --- a/lib_dec/ivas_mdct_core_dec_fx.c +++ b/lib_dec/ivas_mdct_core_dec_fx.c @@ -1386,7 +1386,6 @@ void ivas_mdct_core_reconstruct_fx( ELSE /*ACELP core for ACELP-PLC */ { #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN -#if 0 Copy( st->hTcxDec->old_synth, synth_buf_fx, st->hTcxDec->old_synth_len ); // Q = st->hTcxDec->q_old_synth Copy_Scale_sig( st->hTcxDec->old_synthFB_fx, synth_bufFB_fx, st->hTcxDec->old_synth_lenFB, sub( st->hTcxDec->q_old_synth, st->Q_syn ) ); // Q = st->hTcxDec->q_old_synth @@ -1394,11 +1393,6 @@ void ivas_mdct_core_reconstruct_fx( // Scale_sig( synth_bufFB_fx, st->hTcxDec->old_synth_lenFB, -2 ); // Scale_sig( synth_bufFB_fx, st->hTcxDec->old_synth_lenFB, +2 ); /////////////////////////////////////////////////////////////////////////////////// -#else - Copy_Scale_sig( st->hTcxDec->old_synth, synth_buf_fx, st->hTcxDec->old_synth_len, sub( 0, st->hTcxDec->q_old_synth ) ); // Q = st->hTcxDec->q_old_synth -> Q0 - Copy_Scale_sig( st->hTcxDec->old_synthFB_fx, synth_bufFB_fx, st->hTcxDec->old_synth_lenFB, sub( 0, st->Q_syn ) ); // Q = st->hTcxDec->q_old_synth -> Q0 - q_syn = 0; -#endif #endif assert( EQ_16( st->bfi, 1 ) ); /* PLC: [TCX: TD PLC] */ -- GitLab From 4c57143ed42a9f0f4ba23d35c934d552d1af1122 Mon Sep 17 00:00:00 2001 From: naghibza Date: Thu, 26 Jun 2025 12:18:33 +0200 Subject: [PATCH 108/113] Added q_acelp_zir_fx to scale acelp_zir_fx in dynamic q_win cases --- lib_dec/dec_tcx_fx.c | 42 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index b993f6753..b544ba417 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -2988,6 +2988,7 @@ void IMDCT_ivas_fx( const Word16 fullbandScale, Word16 *acelp_zir_fx, #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN + Word16 *q_acelp_zir_fx, Word16 *pq_win ) #else Word16 q_win ) // Q(-2) @@ -3301,6 +3302,11 @@ void IMDCT_ivas_fx( { /* default, i.e. maximum overlap, single transform, no grouping */ #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN + IF( allow_qwin_change && fullbandScale ) + { + q_win = s_min( q_win, norm_arr( acelp_zir_fx, shr( L_frame_glob, 1 ) ) + *q_acelp_zir_fx ); + } + IF( EQ_16( kernel_type, MDST_IV ) ) { TCX_MDST_Inverse_qwin_fx( x_fx, x_e_hdrm, xn_buf_fx, overlap, sub( L_frame, overlap ), overlap, &q_win, allow_qwin_change ); @@ -3333,6 +3339,16 @@ void IMDCT_ivas_fx( } #endif +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN + IF( !fullbandScale ) + { + *q_acelp_zir_fx = q_xn_buf_fx; + } + ELSE + { + scale_sig( acelp_zir_fx, shr( L_frame_glob, 1 ), sub( q_xn_buf_fx, *q_acelp_zir_fx ) ); + } +#endif tcx_windowing_synthesis_current_frame( xn_buf_fx, tcx_aldo_window_2_fx, tcx_mdct_window_half_fx, tcx_mdct_window_minimum_fx, overlap, tcx_mdct_window_half_length, tcx_mdct_window_min_length, left_rect, !bfi && ( frame_cnt > 0 ) && ( index == 0 ) && NE_16( st->last_core, ACELP_CORE ) ? MIN_OVERLAP : index, acelp_zir_fx, hTcxDec->old_syn_Overl, syn_Overl_TDAC_fx, st->old_Aq_12_8_fx, tcx_mdct_window_trans_fx, shr( L_frame_glob, 1 ), ( tcx_offset < 0 ) ? -tcx_offset : 0, ( frame_cnt > 0 /*|| (st->last_con_tcx )*/ ) ? 1 : st->last_core_bfi, ( frame_cnt > 0 ) ? 0 : (Word8) st->last_is_cng, fullbandScale ); } /* tcx_last_overlap_mode != FULL_OVERLAP */ @@ -3512,6 +3528,10 @@ void IMDCT_ivas_fx( } #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN + IF( allow_qwin_change && fullbandScale ) + { + q_win = s_min( q_win, norm_arr( acelp_zir_fx, shr( L_frame_glob, 1 ) ) + *q_acelp_zir_fx ); + } IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && ( LE_32( st->last_core_brate, SID_2k40 ) || st->last_core == ACELP_CORE ) && ( fullbandScale == 0 ) ) { /* Increase headroom because if the ACELP ZIR is used below, the synthesis filter gain is unknown. */ @@ -3585,7 +3605,17 @@ void IMDCT_ivas_fx( move16(); } } - +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN + IF(!fullbandScale) + { + *q_acelp_zir_fx = q_xn_buf_fx; + } + ELSE + { + scale_sig( acelp_zir_fx, shr( L_frame_glob, 1 ), sub( q_xn_buf_fx, *q_acelp_zir_fx ) ); + } +#endif + //scale_sig( acelp_zir_fx, L_FRAME_MAX / 2, sub( q_xn_buf_fx, q_win0 ) ); /* Window current frame */ tcx_windowing_synthesis_current_frame( xn_buf_fx, tcx_aldo_window_2_fx, tcx_mdct_window_half_fx, tcx_mdct_window_minimum_fx, overlap, tcx_mdct_window_half_length, tcx_mdct_window_min_length, left_rect, hTcxCfg->tcx_last_overlap_mode, acelp_zir_fx, hTcxDec->old_syn_Overl, syn_Overl_TDAC_fx, st->old_Aq_12_8_fx, tcx_mdct_window_trans_fx, shr( L_frame_glob, 1 ), acelp_mem_len, st->last_core_bfi, (Word8) st->last_is_cng, fullbandScale ); } @@ -5738,7 +5768,7 @@ void decoder_tcx_imdct_fx( Word32 x_tmp_fx[L_FRAME_PLUS]; Word32 xn_bufFB_fx[L_MDCT_OVLP_MAX + L_FRAME_PLUS + L_MDCT_OVLP_MAX] = { 0 }; Word16 xn_bufFB_fx_16[L_MDCT_OVLP_MAX + L_FRAME_PLUS + L_MDCT_OVLP_MAX]; - Word16 acelp_zir_fx[L_FRAME_MAX / 2]; + Word16 acelp_zir_fx[L_FRAME_MAX / 2], q_acelp_zir_fx = 0; Word32 x_itf_fx[N_MAX_TCX - IGF_START_MN]; Word16 index, proc = 0; TCX_LTP_DEC_HANDLE hTcxLtpDec = st->hTcxLtpDec; @@ -5911,7 +5941,7 @@ void decoder_tcx_imdct_fx( #endif hTcxCfg->tcx_mdct_window_half, hTcxCfg->tcx_mdct_window_minimum, hTcxCfg->tcx_mdct_window_trans, hTcxCfg->tcx_mdct_window_half_length, hTcxCfg->tcx_mdct_window_min_length, index, #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD - kernelType, left_rect, tcx_offset, overlap, L_frame, L_frameTCX, shr( s_max( L_frameTCX, L_spec ), 1 ), L_frame_glob, frame_cnt, bfi, st->hHQ_core->old_out_LB_fx, &st->hHQ_core->Q_old_wtda_LB, 0, st, 0, acelp_zir_fx, q_win ); + kernelType, left_rect, tcx_offset, overlap, L_frame, L_frameTCX, shr( s_max( L_frameTCX, L_spec ), 1 ), L_frame_glob, frame_cnt, bfi, st->hHQ_core->old_out_LB_fx, &st->hHQ_core->Q_old_wtda_LB, 0, st, 0, acelp_zir_fx, &q_acelp_zir_fx, q_win ); #else kernelType, left_rect, tcx_offset, overlap, L_frame, L_frameTCX, shr( s_max( L_frameTCX, L_spec ), 1 ), L_frame_glob, frame_cnt, bfi, st->hHQ_core->old_out_LB_fx, 0, st, 0, acelp_zir_fx, q_win ); #endif @@ -5940,7 +5970,7 @@ void decoder_tcx_imdct_fx( IMDCT_ivas_fx( xn_bufFB_fx, q_x, hTcxDec->syn_Overl, hTcxDec->syn_Overl_TDAC, xn_buf_fx, hTcxCfg->tcx_aldo_window_1, hTcxCfg->tcx_aldo_window_1_trunc, hTcxCfg->tcx_aldo_window_2, hTcxCfg->tcx_mdct_window_half, hTcxCfg->tcx_mdct_window_minimum, hTcxCfg->tcx_mdct_window_trans, hTcxCfg->tcx_mdct_window_half_length, hTcxCfg->tcx_mdct_window_min_length, index, #endif #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD - kernelType, left_rect, tcx_offset, overlap, L_frame, L_frameTCX, shr( s_max( L_frameTCX, L_spec ), 1 ), L_frame_glob, frame_cnt, bfi, st->hHQ_core->old_out_LB_fx, &st->hHQ_core->Q_old_wtda_LB, 0, st, 0, acelp_zir_fx, q_win ); + kernelType, left_rect, tcx_offset, overlap, L_frame, L_frameTCX, shr( s_max( L_frameTCX, L_spec ), 1 ), L_frame_glob, frame_cnt, bfi, st->hHQ_core->old_out_LB_fx, &st->hHQ_core->Q_old_wtda_LB, 0, st, 0, acelp_zir_fx, &q_acelp_zir_fx, q_win ); #else kernelType, left_rect, tcx_offset, overlap, L_frame, L_frameTCX, shr( s_max( L_frameTCX, L_spec ), 1 ), L_frame_glob, frame_cnt, bfi, st->hHQ_core->old_out_LB_fx, 0, st, 0, acelp_zir_fx, q_win ); #endif @@ -5974,7 +6004,7 @@ void decoder_tcx_imdct_fx( #endif hTcxCfg->tcx_mdct_window_halfFB, hTcxCfg->tcx_mdct_window_minimumFB, hTcxCfg->tcx_mdct_window_transFB, hTcxCfg->tcx_mdct_window_half_lengthFB, hTcxCfg->tcx_mdct_window_min_lengthFB, index, #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD - kernelType, left_rect, tcx_offsetFB, overlapFB, L_frameTCX, L_frameTCX, shr( s_max( L_frameTCX, L_spec ), 1 ), L_frameTCX_glob, frame_cnt, bfi, st->hHQ_core->old_out_fx, &st->hHQ_core->Q_old_wtda, 1, st, ratio, acelp_zir_fx, q_winFB ); + kernelType, left_rect, tcx_offsetFB, overlapFB, L_frameTCX, L_frameTCX, shr( s_max( L_frameTCX, L_spec ), 1 ), L_frameTCX_glob, frame_cnt, bfi, st->hHQ_core->old_out_fx, &st->hHQ_core->Q_old_wtda, 1, st, ratio, acelp_zir_fx, &q_acelp_zir_fx, q_winFB ); #else kernelType, left_rect, tcx_offsetFB, overlapFB, L_frameTCX, L_frameTCX, shr( s_max( L_frameTCX, L_spec ), 1 ), L_frameTCX_glob, frame_cnt, bfi, st->hHQ_core->old_out_fx, 1, st, ratio, acelp_zir_fx, q_win ); #endif @@ -5987,7 +6017,7 @@ void decoder_tcx_imdct_fx( IMDCT_ivas_fx( x_fx, q_x, hTcxDec->syn_OverlFB, hTcxDec->syn_Overl_TDACFB, xn_bufFB_fx_16, hTcxCfg->tcx_aldo_window_1_FB, hTcxCfg->tcx_aldo_window_1_FB_trunc, hTcxCfg->tcx_aldo_window_2_FB, hTcxCfg->tcx_mdct_window_halfFB, hTcxCfg->tcx_mdct_window_minimumFB, hTcxCfg->tcx_mdct_window_transFB, hTcxCfg->tcx_mdct_window_half_lengthFB, hTcxCfg->tcx_mdct_window_min_lengthFB, index, #endif #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD - kernelType, left_rect, tcx_offsetFB, overlapFB, L_frameTCX, L_frameTCX, shr( s_max( L_frameTCX, L_spec ), 1 ), L_frameTCX_glob, frame_cnt, bfi, st->hHQ_core->old_out_fx, &st->hHQ_core->Q_old_wtda, 1, st, ratio, acelp_zir_fx, q_winFB ); + kernelType, left_rect, tcx_offsetFB, overlapFB, L_frameTCX, L_frameTCX, shr( s_max( L_frameTCX, L_spec ), 1 ), L_frameTCX_glob, frame_cnt, bfi, st->hHQ_core->old_out_fx, &st->hHQ_core->Q_old_wtda, 1, st, ratio, acelp_zir_fx, &q_acelp_zir_fx, q_winFB ); #else kernelType, left_rect, tcx_offsetFB, overlapFB, L_frameTCX, L_frameTCX, shr( s_max( L_frameTCX, L_spec ), 1 ), L_frameTCX_glob, frame_cnt, bfi, st->hHQ_core->old_out_fx, 1, st, ratio, acelp_zir_fx, q_win ); #endif -- GitLab From 66465ef3e2925af99a7cd98aac18e8e2bcbe650c Mon Sep 17 00:00:00 2001 From: naghibza Date: Thu, 26 Jun 2025 12:46:41 +0200 Subject: [PATCH 109/113] Applied Clang formating patch. --- lib_dec/dec_tcx_fx.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index b544ba417..33dd3dfd3 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -3606,7 +3606,7 @@ void IMDCT_ivas_fx( } } #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN - IF(!fullbandScale) + IF( !fullbandScale ) { *q_acelp_zir_fx = q_xn_buf_fx; } @@ -3615,7 +3615,6 @@ void IMDCT_ivas_fx( scale_sig( acelp_zir_fx, shr( L_frame_glob, 1 ), sub( q_xn_buf_fx, *q_acelp_zir_fx ) ); } #endif - //scale_sig( acelp_zir_fx, L_FRAME_MAX / 2, sub( q_xn_buf_fx, q_win0 ) ); /* Window current frame */ tcx_windowing_synthesis_current_frame( xn_buf_fx, tcx_aldo_window_2_fx, tcx_mdct_window_half_fx, tcx_mdct_window_minimum_fx, overlap, tcx_mdct_window_half_length, tcx_mdct_window_min_length, left_rect, hTcxCfg->tcx_last_overlap_mode, acelp_zir_fx, hTcxDec->old_syn_Overl, syn_Overl_TDAC_fx, st->old_Aq_12_8_fx, tcx_mdct_window_trans_fx, shr( L_frame_glob, 1 ), acelp_mem_len, st->last_core_bfi, (Word8) st->last_is_cng, fullbandScale ); } -- GitLab From 24c6246d773789d0d80a81ce1be946775f07e813 Mon Sep 17 00:00:00 2001 From: naghibza Date: Thu, 26 Jun 2025 13:16:38 +0200 Subject: [PATCH 110/113] Added *q_acelp_zir_fx as a parameter to IMDCT_ivas_fx() in prot_fx.h. --- lib_com/prot_fx.h | 1 + 1 file changed, 1 insertion(+) diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 684dfa377..c49c0dfb7 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -9484,6 +9484,7 @@ void IMDCT_ivas_fx( const Word16 fullbandScale, Word16 *acelp_zir_fx, #ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN + Word16 *q_acelp_zir_fx, Word16 *pq_win ); #else Word16 q_win ); -- GitLab From bb07b79167d1dc886de362574f3ed31d6aa0f407 Mon Sep 17 00:00:00 2001 From: Manuel Jander Date: Wed, 2 Jul 2025 12:43:42 +0200 Subject: [PATCH 111/113] Fix compile error with FIX_1348_BIT_PRECISION_IMPROVEMENT related macros all disabled. --- lib_dec/ivas_post_proc_fx.c | 2 ++ lib_dec/ivas_stereo_switching_dec_fx.c | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/lib_dec/ivas_post_proc_fx.c b/lib_dec/ivas_post_proc_fx.c index 01182a493..1b02b2b17 100644 --- a/lib_dec/ivas_post_proc_fx.c +++ b/lib_dec/ivas_post_proc_fx.c @@ -112,7 +112,9 @@ void ivas_post_proc_fx( { Word16 numZeros = (Word16) ( NS2SA_FX2( output_Fs, N_ZERO_MDCT_NS ) ); /*Q0*/ move16(); +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT assert( sts[n]->hHQ_core->Q_old_out_fx32 == Q11 ); +#endif Copy32( sts[n]->hHQ_core->old_out_fx32 + numZeros, sts[n]->hTcxDec->FBTCXdelayBuf_32, delay_comp ); /*Q11*/ } diff --git a/lib_dec/ivas_stereo_switching_dec_fx.c b/lib_dec/ivas_stereo_switching_dec_fx.c index 17109bee6..57f631204 100644 --- a/lib_dec/ivas_stereo_switching_dec_fx.c +++ b/lib_dec/ivas_stereo_switching_dec_fx.c @@ -422,7 +422,9 @@ ivas_error stereo_memory_dec_fx( test(); IF( EQ_16( hCPE->last_element_mode, IVAS_CPE_MDCT ) && EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) ) { +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT assert( hCPE->hCoreCoder[0]->hHQ_core->Q_old_out_fx32 == hCPE->hCoreCoder[1]->hHQ_core->Q_old_out_fx32 ); +#endif v_add_32( hCPE->hCoreCoder[0]->hHQ_core->old_out_fx32, hCPE->hCoreCoder[1]->hHQ_core->old_out_fx32, hCPE->hCoreCoder[0]->hHQ_core->old_out_fx32, extract_l( Mpy_32_16_1( output_Fs, INV_FRAME_PER_SEC_Q15 ) ) ); /* exp(exp_old_out) */ v_multc_fixed_16( hCPE->hCoreCoder[0]->hHQ_core->old_out_fx32, 16384 /* 0.5 in Q15 */, hCPE->hCoreCoder[0]->hHQ_core->old_out_fx32, extract_l( Mpy_32_16_1( output_Fs, INV_FRAME_PER_SEC_Q15 ) ) ); /* exp(exp_old_out) */ @@ -2154,7 +2156,9 @@ void stereo_td2dft_update_fx( move16(); /* update buffers used for fading when switching to DFT Stereo */ +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT assert( sts[0]->hHQ_core->Q_old_out_fx32 == sts[1]->hHQ_core->Q_old_out_fx32 ); +#endif v_add_fx( sts[0]->hHQ_core->old_out_LB_fx32 + nsLB, sts[1]->hHQ_core->old_out_LB_fx32 + nsLB, hCPE->old_outLB_mdct_fx, old_outLB_len ); L_lerp_fx_q11( hCPE->old_outLB_mdct_fx, hCPE->old_outLB_mdct_fx, STEREO_MDCT2DFT_FADE_LEN_48k, old_outLB_len ); -- GitLab From bc4496f3c245a05d57dabc75de2cb28c939920d7 Mon Sep 17 00:00:00 2001 From: Manuel Jander Date: Wed, 2 Jul 2025 13:07:50 +0200 Subject: [PATCH 112/113] Fix warning if FIX_1348_BIT_PRECISION_IMPROVEMENT... is deactivated. Disable overfloat guard assert because it trips with FIX_1348_BIT_PRECISION_IMPROVEMENT... disabled. --- lib_dec/dec_tcx_fx.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index bea3d2006..f1d0fbe5b 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -5773,7 +5773,7 @@ void decoder_tcx_imdct_fx( Word32 x_tmp_fx[L_FRAME_PLUS]; Word32 xn_bufFB_fx[L_MDCT_OVLP_MAX + L_FRAME_PLUS + L_MDCT_OVLP_MAX] = { 0 }; Word16 xn_bufFB_fx_16[L_MDCT_OVLP_MAX + L_FRAME_PLUS + L_MDCT_OVLP_MAX]; - Word16 acelp_zir_fx[L_FRAME_MAX / 2], q_acelp_zir_fx = 0; + Word16 acelp_zir_fx[L_FRAME_MAX / 2]; Word32 x_itf_fx[N_MAX_TCX - IGF_START_MN]; Word16 index, proc = 0; TCX_LTP_DEC_HANDLE hTcxLtpDec = st->hTcxLtpDec; @@ -5784,7 +5784,9 @@ void decoder_tcx_imdct_fx( Word16 q_a_itf = 15; Word16 x_e = sub( 31, q_x ); move16(); -#ifndef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN + Word16 q_acelp_zir_fx = 0; +#else Word16 shift_q = sub( q_x, q_win ); #endif @@ -5991,7 +5993,9 @@ void decoder_tcx_imdct_fx( FOR( Word16 ind = 0; ind < L_MDCT_OVLP_MAX + L_FRAME_PLUS + L_MDCT_OVLP_MAX; ind++ ) { +#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN assert( extract_h( L_shr( xn_bufFB_fx[ind], shift_q ) ) == 0 || extract_h( L_shr( xn_bufFB_fx[ind], shift_q ) ) == -1 ); +#endif xn_bufFB_fx_16[ind] = extract_l( L_shr( xn_bufFB_fx[ind], shift_q ) ); // q_x16 move16(); } -- GitLab From 4a61a21299eae25f53eb24e44499cfb26870845d Mon Sep 17 00:00:00 2001 From: Markus Multrus Date: Wed, 2 Jul 2025 15:24:53 +0200 Subject: [PATCH 113/113] remove inactive code under //#define FIX_1348_BIT_PRECISION_IMPROVEMENT_ROUND_OLD_BUFF --- lib_com/options.h | 1 - lib_dec/dec_tcx_fx.c | 4 ---- 2 files changed, 5 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 9d6e68621..bfa02eacf 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -101,7 +101,6 @@ #define FIX_1348_BIT_PRECISION_IMPROVEMENT #define FIX_1348_BIT_PRECISION_IMPROVEMENT_QWIN #define FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD -//#define FIX_1348_BIT_PRECISION_IMPROVEMENT_ROUND_OLD_BUFF #define FIX_USAN_BASOP_UTIL_DIVIDE3232 /* Eri: Fix USAN error in BASOP_Util_Divide3232_Scale_newton by adding explicit type cast for -1 in hex */ diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index f1d0fbe5b..6206577c1 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -3498,11 +3498,7 @@ void IMDCT_ivas_fx( { #ifndef FIX_1348_BIT_PRECISION_IMPROVEMENT_DYNAMIC_QOLD -#ifdef FIX_1348_BIT_PRECISION_IMPROVEMENT_ROUND_OLD_BUFF - old_out_fx[ind] = shr_r_sat( old_out_fx[ind], q_diff ); -#else old_out_fx[ind] = shr_sat( old_out_fx[ind], q_diff ); -#endif move16(); #endif xn_buf_fx[ind] = shr_sat( xn_buf_fx[ind], diff ); -- GitLab