From f2d229fa2f3a4fc2974151fd16c303e0bde16338 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Tue, 25 Jun 2024 11:53:50 +0530 Subject: [PATCH 1/4] BASOP and instrumentation changes added --- lib_com/prot.h | 16 + lib_dec/LD_music_post_filter_fx.c | 37 +- lib_dec/d_gain2p_fx.c | 20 +- lib_dec/dec_LPD_fx.c | 73 ++- lib_dec/dec_higher_acelp_fx.c | 28 +- lib_dec/dec_pit_exc_fx.c | 72 +-- lib_dec/dec_post_fx.c | 18 +- lib_dec/dec_ppp_fx.c | 5 +- lib_dec/dec_prm.c | 262 +++++++++- lib_dec/dec_prm_fx.c | 289 ++++++++--- lib_dec/dec_tcx_fx.c | 489 +++++++++++++------ lib_dec/dec_tran_fx.c | 63 ++- lib_dec/dec_uv_fx.c | 54 +- lib_dec/dlpc_avq_fx.c | 14 +- lib_dec/dlpc_stoch_fx.c | 11 +- lib_dec/ivas_mdct_core_dec.c | 4 +- lib_dec/ivas_tcx_core_dec.c | 257 +++++++--- lib_dec/ivas_td_low_rate_dec.c | 61 ++- lib_dec/jbm_jb4_circularbuffer.c | 63 ++- lib_dec/jbm_jb4_inputbuffer.c | 72 +-- lib_dec/jbm_jb4_jmf.c | 45 +- lib_dec/jbm_jb4sb.c | 476 ++++++++++++------ lib_dec/jbm_pcmdsp_apa.c | 94 ++-- lib_dec/jbm_pcmdsp_similarityestimation.c | 7 +- lib_dec/jbm_pcmdsp_window.c | 2 + lib_dec/lead_deindexing_fx.c | 9 +- lib_dec/lib_dec_fx.c | 570 ++++++++++++++++++---- lib_dec/lp_exc_d_fx.c | 10 +- lib_dec/tonalMDCTconcealment_fx.c | 13 + 29 files changed, 2311 insertions(+), 823 deletions(-) diff --git a/lib_com/prot.h b/lib_com/prot.h index ed69b9f6e..d33a84804 100644 --- a/lib_com/prot.h +++ b/lib_com/prot.h @@ -6968,6 +6968,21 @@ void enc_acelp_tcx_main( const int16_t vad_hover_flag /* i : VAD hangover flag */ ); +#ifdef IVAS_FLOAT_FIXED +void getTCXMode_ivas_fx( + Decoder_State *st, /* i/o: decoder memory state */ + Decoder_State *st0, /* i : bitstream */ + const Word16 MCT_flag /* i : hMCT handle allocated (1) or not (0)*/ +); + +void getTCXWindowing_ivas_fx( + const Word16 core, /* i : current frame mode */ + const Word16 last_core, /* i : last frame mode */ + const Word16 element_mode, /* i : element mode */ + TCX_CONFIG_HANDLE hTcxCfg, /* i/o: TCX configuration handle */ + Decoder_State *st0 /* i : bitstream */ +); +#else void getTCXMode_ivas( Decoder_State *st, /* i/o: decoder memory state */ Decoder_State *st0, /* i : bitstream */ @@ -6981,6 +6996,7 @@ void getTCXWindowing_ivas( TCX_CONFIG_HANDLE hTcxCfg, /* i/o: TCX configuration handle */ Decoder_State *st0 /* i : bitstream */ ); +#endif void getLPCparam_ivas( Decoder_State *st, /* i/o: decoder memory state */ diff --git a/lib_dec/LD_music_post_filter_fx.c b/lib_dec/LD_music_post_filter_fx.c index 261b9b4d7..454e59ddd 100644 --- a/lib_dec/LD_music_post_filter_fx.c +++ b/lib_dec/LD_music_post_filter_fx.c @@ -73,9 +73,15 @@ void LD_music_post_filter_fx( #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif + move16(); + move16(); + move16(); + move16(); + move32(); local_min_gain = hMusicPF->LDm_enh_min_ns_gain_fx; + move16(); /*------------------------------------------------------------------------* * Frequency analysis @@ -111,6 +117,7 @@ void LD_music_post_filter_fx( hMusicPF->last_nonfull_music = s_min( 51, hMusicPF->last_nonfull_music ); + move16(); /*------------------------------------------------------------------------* * Remapping of bands @@ -197,7 +204,7 @@ void LD_music_post_filter_fx( hMusicPF->LDm_bckr_noise_fx[i] = Mult_32_16( m_ave, sc_qnoise_fx[i] ); move32(); - j += mfreq_bindiv_LD[i]; + j = add( j, mfreq_bindiv_LD[i] ); } /* This is computed inside the loop i = maximum(lf_E, DCT_L_POST, &m_ave);*/ @@ -220,6 +227,7 @@ void LD_music_post_filter_fx( old_tmp16_1 = tmp16; move16(); tmp_lfE[0] = round_fx( L_mac( L_mult( 16384, old_tmp16 ), 16384, tmp16 ) ); + move16(); FOR( i = 1; i < DCT_L_POST - 1; i++ ) { @@ -234,6 +242,7 @@ void LD_music_post_filter_fx( old_tmp16_1 = s_min( tmp16, MAXX_Q12_FX ); Ltmp = L_mac( Ltmp, 10813, old_tmp16_1 ); tmp_lfE[i] = round_fx( Ltmp ); + move16(); } tmp16 = norm_lfe( lf_E[i], s_ave, exp1 ); @@ -241,17 +250,20 @@ void LD_music_post_filter_fx( tmp_lfE[i] = 0.5f*old_ftmp + 0.5f*ftmp;*/ tmp16 = s_min( tmp16, MAXX_Q12_FX ); tmp_lfE[i] = round_fx( L_mac( L_mult( 16384, old_tmp16 ), 16384, tmp16 ) ); + move16(); FOR( i = 0; i < BIN_4KHZ; i++ ) { /*filt_lfE[i] = tmp_lfE[i]*.05f + .95f*filt_lfE[i] ;*/ hMusicPF->filt_lfE_fx[i] = round_fx( L_mac( L_mult( tmp_lfE[i], 1638 ), 31130, hMusicPF->filt_lfE_fx[i] ) ); + move16(); } FOR( ; i < DCT_L_POST; i++ ) { /*filt_lfE[i] = tmp_lfE[i]*(.15f) + .85f*filt_lfE[i] ;*/ hMusicPF->filt_lfE_fx[i] = round_fx( L_mac( L_mult( tmp_lfE[i], 4915 ), 27853, hMusicPF->filt_lfE_fx[i] ) ); + move16(); } /*------------------------------------------------------------------------* * - Reduce inter-harmonic noise with SNR based method @@ -277,6 +289,7 @@ void LD_music_post_filter_fx( { tmp16 = s_min( 4096, hMusicPF->filt_lfE_fx[i] ); dtc_out[i] = round_fx( L_shl( L_mult( dtc_out[i], tmp16 ), 3 ) ); + move16(); } } { @@ -360,6 +373,7 @@ void LD_music_post_filter_fx( #else dtc_out[i] = round_fx( L_shl( L_mult( dtc_out[i], tmp16 ), 3 ) ); #endif + move16(); } FOR( ; i < BIN_4KHZ; i++ ) @@ -372,6 +386,7 @@ void LD_music_post_filter_fx( #else dtc_out[i] = round_fx( L_shl( L_mult( dtc_out[i], tmp16 ), 3 ) ); #endif + move16(); } test(); @@ -388,6 +403,7 @@ void LD_music_post_filter_fx( #else dtc_out[i] = round_fx( L_shl( L_mult( dtc_out[i], tmp16 ), 3 ) ); #endif + move16(); } } } @@ -403,6 +419,7 @@ void LD_music_post_filter_fx( #else dtc_out[i] = round_fx( L_shl( L_mult( dtc_out[i], tmp16 ), 3 ) ); #endif + move16(); } } } @@ -450,6 +467,8 @@ static void spectrum_mod_dct_fx( Flag Overflow = 0; #endif + move16(); + move32(); gain = 0; move16(); @@ -479,6 +498,7 @@ static void spectrum_mod_dct_fx( e_invno[i] = norm_l( noiseE[i] ); move16(); m_invno[i] = extract_h( L_shl( noiseE[i], e_invno[i] ) ); + move16(); e_invno[i] = sub( 14, e_invno[i] ); move16(); m_invno[i] = div_s( 16384, m_invno[i] ); @@ -650,6 +670,8 @@ static void spectrum_mod_dct_fx( #else *pt = round_fx( L_shl( L_mult( *pt, *pt_gbin ), 1 ) ); #endif + move16(); + move16(); pt++; pt_gbin++; } @@ -667,6 +689,7 @@ static void spectrum_mod_dct_fx( { /**pt_gbin = 0.9f* *pt_gbin + 0.1f;*/ *pt_gbin = round_fx( L_mac( L_mult( 29491, *pt_gbin ), 32767, 1638 ) ); + move16(); pt_gbin++; } } @@ -691,6 +714,7 @@ static void analy_sp_dct_fx( ) { Word32 Letot = 0; + move32(); Word16 exp_etot, frac_etot; Letot = L_deposit_l( 0 ); @@ -708,6 +732,7 @@ static void analy_sp_dct_fx( Letot = Mpy_32_16( exp_etot, frac_etot, LG10 ); /* Q8 Averaged the total energy over both half-frames in log10 */ *etot = extract_l( L_shr( Letot, 14 - 8 ) ); + move16(); return; } @@ -736,7 +761,7 @@ static void find_enr_dct_fx( Word32 LE_min, Ltmp, Ltmp1; - LE_min = L_max( L_shl( E_MIN_Q15, sub( shl( Q_dct, 1 ) + 10, 22 ) ), 1 ); + LE_min = L_max( L_shl( E_MIN_Q15, sub( add( shl( Q_dct, 1 ), 10 ), 22 ) ), 1 ); ptR = &data[0]; /* pointer to first real coefficient */ freq = 0; @@ -833,6 +858,11 @@ void Prep_music_postP_fx( /*------------------------------------------------------------* * Resetting some memories in case of switching *------------------------------------------------------------*/ + test(); + test(); + test(); + test(); + test(); IF( ( EQ_16( element_mode, EVS_MONO ) && EQ_16( last_core, HQ_CORE ) ) || ( NE_16( element_mode, EVS_MONO ) && ( EQ_16( last_core, HQ_CORE ) || EQ_16( last_core, TCX_20_CORE ) || EQ_16( last_core, TCX_10_CORE ) ) ) ) { set16_fx( filt_lfE, 4096, DCT_L_POST ); @@ -918,6 +948,7 @@ static Word16 norm_lfe( Flag Overflow = 0; #endif + move32(); Ltmp = Mult_32_16( Lfe, m_norm ); Ltmp = L_add( Ltmp, L_shl( BET_Q15_FX, sub( e_norm, 15 ) ) ); /* Ltmp -> e_norm*/ @@ -1023,6 +1054,7 @@ void music_postfilt_init( e_db = add( e_db, 15 - 14 ); f_db = add( f_db, shr( 1, add( e_db, 1 ) ) ); hMusicPF->LDm_enh_min_ns_gain_fx = shl( f_db, e_db ); + move16(); hMusicPF->LDm_last_music_flag = 0; move16(); @@ -1058,7 +1090,6 @@ void music_postfilt_init( move16(); } set16_fx( hMusicPF->filt_lfE_fx, 4096, DCT_L_POST ); - move16(); hMusicPF->last_nonfull_music = 0; move16(); hMusicPF->Old_ener_Q = 0; diff --git a/lib_dec/d_gain2p_fx.c b/lib_dec/d_gain2p_fx.c index fdba24b34..7ab2dec98 100644 --- a/lib_dec/d_gain2p_fx.c +++ b/lib_dec/d_gain2p_fx.c @@ -90,22 +90,24 @@ static void Mode2_gain_dec_mless_fx( * Select the gains quantization table *-----------------------------------------------------------------*/ t_qua_gain = E_ROM_qua_gain7b_const; - + move16(); if ( coder_type == 0 ) { t_qua_gain = E_ROM_qua_gain5b_const; + move16(); } if ( EQ_16( coder_type, 1 ) ) { t_qua_gain = E_ROM_qua_gain6b_const; + move16(); } /*-----------------------------------------------------------------* * decode pitch gain *-----------------------------------------------------------------*/ *gain_pit = t_qua_gain[index * 2]; - + move16(); /*-----------------------------------------------------------------* * calculate the predicted gain code *-----------------------------------------------------------------*/ @@ -128,11 +130,13 @@ static void Mode2_gain_dec_mless_fx( * decode normalized codebook gain *-----------------------------------------------------------------*/ /* *gain_code = t_qua_gain[index*2+1] * gcode0;*/ - - L_tmp = calc_gain_code_fx( t_qua_gain[index * 2 + 1], gcode0, exp_gcode0 ); + Word16 tmp_idx = add( shl( index, 1 ), 1 ); + L_tmp = calc_gain_code_fx( t_qua_gain[tmp_idx], gcode0, exp_gcode0 ); *gain_code = L_tmp; + move32(); *past_gpit = *gain_pit; + move16(); /**past_gcode = *gain_code / *gain_inov; */ /* Q16/Q12 => Q5 */ L_tmp1 = L_deposit_h( BASOP_Util_Divide3216_Scale( L_tmp, *gain_inov, &exp_L_tmp1 ) ); @@ -187,14 +191,16 @@ static void gain_dec_uv_fx( L_tmp = L_and( 0x7FFFFFFF, L_tmp ); L_tmp = Pow2( 30, round_fx( L_tmp ) ); - L_tmp = L_shl( L_tmp, i - ( 31 - 16 ) ); /* Q16 */ + L_tmp = L_shl( L_tmp, sub( i, ( 31 - 16 ) ) ); /* Q16 */ /*-----------------------------------------------------------------* * past gains for error concealment *-----------------------------------------------------------------*/ *past_gpit = *gain_pit; + move16(); *past_gcode = L_tmp; + move32(); #ifdef BASOP_NOGLOB L_tmp = L_shl_sat( Mpy_32_16_1( L_tmp, *gain_inov ), 3 ); /* Q16*Q12 -> Q13 -> Q16 */ #else @@ -345,7 +351,7 @@ void decode_acelp_gains_fx( ) { Word16 index = 0; - + move16(); index = **pt_indice; ( *pt_indice )++; @@ -409,7 +415,7 @@ void d_gain_pred_fx( move16(); } - IF( GT_16( nrg_mode, 2 ) ) + if ( GT_16( nrg_mode, 2 ) ) { move16(); *Es_pred = extract_l( L_mac( -335544320l /* -20.f Q24*/, indice, 224 /* 1.75f Q7*/ ) ); /*(Q8 - ((Q0*Q7)=Q8))*/ diff --git a/lib_dec/dec_LPD_fx.c b/lib_dec/dec_LPD_fx.c index 7152a4f29..11afd0184 100644 --- a/lib_dec/dec_LPD_fx.c +++ b/lib_dec/dec_LPD_fx.c @@ -68,7 +68,8 @@ void decoder_LPD_fx( hTcxDec = st->hTcxDec; st->core = 0; /* to avoid compilation warnings */ - prm = NULL; /* to avoid compilation warnings */ + move16(); + prm = NULL; /* to avoid compilation warnings */ /*--------------------------------------------------------------------------------* * INIT @@ -99,6 +100,7 @@ void decoder_LPD_fx( if ( bfi == 0 ) { st->bits_frame_core = sub( st->bits_frame, bitsRead[0] ); + move16(); } /* Framing parameters */ @@ -131,7 +133,7 @@ void decoder_LPD_fx( /* PLC: [Common: Memory update] * PLC: Update the number of lost frames */ - IF( bfi != 0 ) + if ( bfi != 0 ) { move16(); st->nbLostCmpt = add( st->nbLostCmpt, 1 ); @@ -152,6 +154,8 @@ void decoder_LPD_fx( tcx_current_overlap_mode = st->hTcxCfg->tcx_curr_overlap_mode; move16(); dec_prm_fx( &st->coder_type, param, param_lpc, total_nbbits, st, L_frame, bitsRead ); + test(); + test(); IF( !st->rate_switching_init && EQ_16( ( st->last_codec_mode ), MODE2 ) && st->BER_detect ) { st->coder_type = st->last_coder_type; @@ -194,9 +198,10 @@ void decoder_LPD_fx( /* PLC: [Common: mode decision] * PLC: Decide which Concealment to use. Update pitch lags if needed */ - IF( bfi != 0 ) + if ( bfi != 0 ) { st->core = GetPLCModeDecision_fx( st ); + move16(); } IF( bfi == 0 ) @@ -222,7 +227,6 @@ void decoder_LPD_fx( test(); test(); test(); - test(); IF( ( bfi == 0 ) || ( bfi != 0 && st->use_partial_copy != 0 && EQ_16( st->rf_frame_type, RF_TCXFD ) ) ) { test(); @@ -267,11 +271,19 @@ void decoder_LPD_fx( Copy( lsf_q_rf, &lsf[M], M ); Copy( lsp_q_rf, &lsp[M], M ); lsp_diff = 0; + move16(); FOR( i = 0; i < M; i++ ) { lsp_diff = L_add( lsp_diff, (Word32) abs_s( sub( lsp[i + M], lsp[i] ) ) ); } + test(); + test(); + test(); + test(); + test(); + test(); + test(); IF( EQ_16( st->core, ACELP_CORE ) && EQ_16( st->last_core, ACELP_CORE ) && LT_32( lsp_diff, 52428 ) && GT_32( lsp_diff, 3932 ) && EQ_16( st->next_coder_type, GENERIC ) && !st->prev_use_partial_copy && EQ_16( st->last_coder_type, UNVOICED ) && GE_16( st->rf_frame_type, RF_GENPRED ) ) { Copy( &lsp[0], &lsp[M], M ); @@ -287,9 +299,11 @@ void decoder_LPD_fx( Copy( &lsf[( k + 1 ) * M], &xsfnew_uw[k * M], M ); } } - ELSE IF( ( hTcxDec->enableTcxLpc != 0 && NE_16( st->core, ACELP_CORE ) ) || ( bfi && st->use_partial_copy && st->rf_frame_type == RF_TCXFD ) ) + ELSE IF( ( hTcxDec->enableTcxLpc != 0 && NE_16( st->core, ACELP_CORE ) ) || ( bfi && st->use_partial_copy && EQ_16( st->rf_frame_type, RF_TCXFD ) ) ) { Word16 tcx_lpc_cdk; + test(); + test(); IF( bfi && st->use_partial_copy && EQ_16( st->rf_frame_type, RF_TCXFD ) ) { tcx_lpc_cdk = tcxlpc_get_cdk( GENERIC ); @@ -331,9 +345,13 @@ void decoder_LPD_fx( ELSE { lpc_unquantize_fx( st, lsf, lsp, M, param_lpc, lspmid, lsfmid, st->coder_type, &LSF_Q_prediction ); - + test(); + test(); + test(); + test(); IF( EQ_16( st->prev_use_partial_copy, 1 ) && EQ_16( st->last_core, ACELP_CORE ) && EQ_16( st->core, ACELP_CORE ) && GE_16( st->prev_rf_frame_type, RF_GENPRED ) && EQ_16( st->coder_type, UNVOICED ) ) { + test(); IF( st->lpcQuantization && st->acelp_cfg.midLpc ) { Copy( lspmid, &lsp[0], M ); @@ -357,11 +375,11 @@ void decoder_LPD_fx( FOR( i = 0; i < M; i++ ) { move16(); - st->lsf_adaptive_mean_fx[i] = add( add( mult_r( st->lsfoldbfi1_fx[i], 10923 /*1.0f/3.0f Q15*/ ), mult_r( st->lsfoldbfi0_fx[i], 10923 /*1.0f/3.0f Q15*/ ) ), mult_r( xsfnew_uw[k * M + i], 10923 /*1.0f/3.0f Q15*/ ) ); + st->lsf_adaptive_mean_fx[i] = add( add( mult_r( st->lsfoldbfi1_fx[i], 10923 /*1.0f/3.0f Q15*/ ), mult_r( st->lsfoldbfi0_fx[i], 10923 /*1.0f/3.0f Q15*/ ) ), mult_r( xsfnew_uw[add( imult1616( k, M ), i )], 10923 /*1.0f/3.0f Q15*/ ) ); move16(); st->lsfoldbfi1_fx[i] = st->lsfoldbfi0_fx[i]; move16(); - st->lsfoldbfi0_fx[i] = xsfnew_uw[k * M + i]; + st->lsfoldbfi0_fx[i] = xsfnew_uw[add( imult1616( k, M ), i )]; } } } @@ -396,20 +414,20 @@ void decoder_LPD_fx( FOR( k = 0; k < st->numlpc; k++ ) { - Copy( &xsfnew_uw[k * M], &lsf[( k + 1 ) * M], M ); + Copy( &xsfnew_uw[k * M], &lsf[add( k, 1 ) * M], M ); IF( st->tcxonly ) { - E_LPC_lsf_lsp_conversion( &lsf[( k + 1 ) * M], &lsp[( k + 1 ) * M], M ); + E_LPC_lsf_lsp_conversion( &lsf[add( k, 1 ) * M], &lsp[add( k, 1 ) * M], M ); E_LPC_lsf_lsp_conversion( st->lsf_q_cng, st->lsp_q_cng, M ); } ELSE { - lsf2lsp_fx( &lsf[( k + 1 ) * M], &lsp[( k + 1 ) * M], M, st->sr_core ); + lsf2lsp_fx( &lsf[add( k, 1 ) * M], &lsp[add( k, 1 ) * M], M, st->sr_core ); lsf2lsp_fx( st->lsf_q_cng, st->lsp_q_cng, M, st->sr_core ); } - Copy( &lsp[( k + 1 ) * M], &xspnew_uw[k * M], M ); + Copy( &lsp[add( k, 1 ) * M], &xspnew_uw[imult1616( k, M )], M ); } } @@ -484,9 +502,11 @@ void decoder_LPD_fx( test(); test(); test(); + test(); IF( ( bfi == 0 ) && ( ( EQ_16( st->dec_glr_idx, 1 ) ) || ( ( st->safety_net == 0 ) && ( shr( enr_new, 11 ) > 0 ) && ( GT_16( shr( enr_new, 1 ), enr_old ) ) ) ) && ( st->prev_bfi != 0 ) ) { Word16 reset_q = 0; + move16(); if ( EQ_16( st->dec_glr_idx, 1 ) ) { reset_q = 1; @@ -545,7 +565,7 @@ void decoder_LPD_fx( } test(); - IF( bfi != 0 && st->last_core != ACELP_CORE ) + IF( bfi != 0 && NE_16( st->last_core, ACELP_CORE ) ) { /* PLC: [TCX: TD PLC] */ #ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT @@ -589,14 +609,15 @@ void decoder_LPD_fx( IF( st->flagGuidedAcelp > 0 ) { st->guidedT0 = s_max( s_min( add( st->T0_4th, st->guidedT0 ), NBPSF_PIT_MAX ), PIT_MIN_16k ); + move16(); } FOR( i = 0; i < st->nb_subfr; i++ ) { move16(); move16(); - st->mem_pitch_gain[2 + ( 2 * st->nb_subfr - 1 ) - i] = st->mem_pitch_gain[2 + ( st->nb_subfr - 1 ) - i]; - st->mem_pitch_gain[2 + ( st->nb_subfr - 1 ) - i] = pit_gain[i]; + st->mem_pitch_gain[sub( add( 2, ( sub( shl( st->nb_subfr, 1 ), 1 ) ) ), i )] = st->mem_pitch_gain[sub( add( 2, sub( st->nb_subfr, 1 ) ), i )]; + st->mem_pitch_gain[sub( add( 2, sub( st->nb_subfr, 1 ) ), i )] = pit_gain[i]; } } } @@ -617,7 +638,9 @@ void decoder_LPD_fx( IF( bfi == 0 ) { st->second_last_tns_active = st->last_tns_active; + move16(); st->last_tns_active = 0; + move16(); hTcxDec->tcxltp_last_gain_unmodified = 0; move16(); } @@ -701,16 +724,16 @@ void decoder_LPD_fx( /* Stability Factor */ IF( bfi == 0 ) { - st->stab_fac_fx = lsf_stab_fx( &lsf[( k + 1 ) * M], &lsf[k * M], 0, L_FRAME ); + st->stab_fac_fx = lsf_stab_fx( &lsf[( add( k, 1 ) ) * M], &lsf[k * M], 0, L_FRAME ); } - E_LPC_f_lsp_a_conversion( &lsp[( k + 1 ) * M], Aq, M ); + E_LPC_f_lsp_a_conversion( &lsp[( add( k, 1 ) ) * M], Aq, M ); /* TCX decoder */ IGFDecRestoreTCX10SubFrameData( st->hIGFDec, k ); decoder_tcx_fx( st->hTcxCfg, prm, Aq, Aind, shr( L_frame, 1 ), shr( L_frameTCX, 1 ), - shr( st->hTcxCfg->tcx_coded_lines, 1 ), &synth[k * L_frame / 2], &synthFB[k * L_frameTCX / 2], st, st->coder_type, bfi, k, st->stab_fac_fx ); + shr( st->hTcxCfg->tcx_coded_lines, 1 ), &synth[shr( imult1616( k, L_frame ), 1 )], &synthFB[shr( imult1616( k, L_frameTCX ), 1 )], st, st->coder_type, bfi, k, st->stab_fac_fx ); } } @@ -762,7 +785,7 @@ void decoder_LPD_fx( IF( st->narrowBand || ( EQ_32( st->sr_core, INT_FS_12k8 ) ) || ( EQ_32( st->sr_core, INT_FS_16k ) ) ) { int_lsp_fx( L_frame, st->lspold_uw, xspnew_uw, Aq, M, interpol_frac_fx, 0 ); - Copy( Aq, st->mem_Aq, nb_subfr * ( M + 1 ) ); + Copy( Aq, st->mem_Aq, imult1616( nb_subfr, ( M + 1 ) ) ); } } } @@ -790,6 +813,7 @@ void decoder_LPD_fx( } LTP_Gain = -32768 /*-1.0f Q15*/; + move16(); if ( hTcxLtpDec->tcxltp ) { LTP_Gain = hTcxDec->tcxltp_last_gain_unmodified; @@ -875,8 +899,8 @@ void decoder_LPD_fx( Copy( synth_bufFB + L_frameTCX, hTcxDec->old_synthFB_fx, hTcxDec->old_synth_lenFB ); Copy_Scale_sig( st->hHQ_core->old_out_fx + NS2SA_fx2( st->output_Fs, N_ZERO_MDCT_NS ), hTcxDec->old_synthFB_fx + hTcxDec->old_synth_lenFB, NS2SA_fx2( st->output_Fs, PH_ECU_LOOKAHEAD_NS ), negate( st->hHQ_core->Q_old_wtda ) ); - Copy( &xspnew_uw[( st->numlpc - 1 ) * M], st->lspold_uw, M ); - Copy( &xsfnew_uw[( st->numlpc - 1 ) * M], st->lsfold_uw, M ); + Copy( &xspnew_uw[imult1616( sub( st->numlpc, 1 ), M )], st->lspold_uw, M ); + Copy( &xsfnew_uw[imult1616( sub( st->numlpc, 1 ), M )], st->lsfold_uw, M ); IF( bfi ) { @@ -892,9 +916,12 @@ void decoder_LPD_fx( Copy( st->lsf_q_cng, st->old_lsf_q_cng, M ); /* Update LP_CNG parameters */ + test(); IF( st->tcxonly == 0 && st->hTdCngDec != NULL ) { /* update CNG parameters in active frames */ + test(); + test(); IF( EQ_16( st->bwidth, NB ) && hTcxDec->enableTcxLpc != 0 && NE_16( st->core, ACELP_CORE ) ) { Word16 buf[L_LP], res[L_FRAME], A[M + 1], Qexc, r_l[M + 1], r_h[M + 1], lsptmp[M], Q_r, tmp; @@ -902,6 +929,7 @@ void decoder_LPD_fx( assert( st->L_frame == L_FRAME ); Copy( synth + L_FRAME - L_LP, buf, L_LP ); tmp = synth[L_FRAME - L_LP - 1]; + move16(); Qexc = E_UTIL_f_preemph3( buf, st->preemph_fac, L_LP, &tmp, 1 ); autocorr_fx( buf, M, r_h, r_l, &Q_r, L_LP, Assym_window_W16fx, 0, 0 ); lag_wind( r_h, r_l, M, INT_FS_FX, LAGW_WEAK ); @@ -945,7 +973,8 @@ void decoder_LPD_fx( { if ( !bfi ) { - st->plcInfo.nbLostCmpt = (int16_t) L_deposit_l( 0 ); + st->plcInfo.nbLostCmpt = extract_l( L_deposit_l( 0 ) ); + move16(); } IF( st->core == 0 ) diff --git a/lib_dec/dec_higher_acelp_fx.c b/lib_dec/dec_higher_acelp_fx.c index b9963725e..0bc9665d8 100644 --- a/lib_dec/dec_higher_acelp_fx.c +++ b/lib_dec/dec_higher_acelp_fx.c @@ -41,10 +41,11 @@ void transf_cdbk_dec_fx( Word16 avq_bit_sFlag; Word16 trgtSvPos; Word16 Nsv = 8; + move16(); avq_bit_sFlag = 0; move16(); - IF( GT_16( st_fx->element_mode, EVS_MONO ) ) + if ( GT_16( st_fx->element_mode, EVS_MONO ) ) { move16(); avq_bit_sFlag = 1; @@ -92,6 +93,7 @@ void transf_cdbk_dec_fx( } ELSE { + test(); IF( GT_32( st_fx->core_brate, ACELP_24k40 ) && LE_32( st_fx->core_brate, 42000 ) ) { gain16 = gain_dequant_fx( index, G_AVQ_MIN_32kbps_Q15, G_AVQ_MAX_Q0, G_AVQ_BITS, &exp16 ); @@ -135,13 +137,15 @@ void transf_cdbk_dec_fx( #ifdef IVAS_CODE_AVQ AVQ_demuxdec_fx( st_fx, code_preQ, &nBits, 8, nq, avq_bit_sFlag, trgtSvPos ); Word16 q_Code_preQ; - IF( st_fx->element_mode == EVS_MONO ) + IF( EQ_16( st_fx->element_mode, EVS_MONO ) ) { q_Code_preQ = Q_AVQ_OUT_DEC; + move16(); } ELSE { q_Code_preQ = Q_AVQ_OUT; + move16(); } #else AVQ_demuxdec_fx( st_fx, code_preQ, &nBits, 8, nq ); @@ -192,20 +196,28 @@ void transf_cdbk_dec_fx( #ifdef IVAS_CODE_AVQ /* TD pre-quantizer: in extreme cases at subframe boundaries, lower the preemphasis memory to avoid a saturation */ + test(); + test(); + test(); + test(); + test(); IF( GT_16( st_fx->element_mode, EVS_MONO ) && NE_16( st_fx->coder_type, INACTIVE ) && GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) && LE_32( st_fx->core_brate, MAX_BRATE_AVQ_EXC_TD ) && !harm_flag_acelp && code_preQ[0] != 0 ) { // PMT("Fixed point taking accound of the scaling needs to be done here ") IF( GT_16( abs_s( st_fx->last_code_preq ), shl_sat( abs_s( code_preQ[0] ), 4 ) ) ) { st_fx->mem_preemp_preQ_fx = shr( st_fx->mem_preemp_preQ_fx, 4 ); + move16(); } ELSE IF( GT_16( abs_s( ( st_fx->last_code_preq ) ), shl_sat( abs_s( code_preQ[0] ), 3 ) ) ) { st_fx->mem_preemp_preQ_fx = shr( st_fx->mem_preemp_preQ_fx, 3 ); + move16(); } } - st_fx->last_code_preq = (Word16) code_preQ[L_SUBFR - 1]; + st_fx->last_code_preq = extract_h( code_preQ[L_SUBFR - 1] ); + move16(); #endif preemph_fx( code_preQ, FAC_PRE_AVQ_FX, L_SUBFR, &st_fx->mem_preemp_preQ_fx ); /*--------------------------------------------------------------* @@ -227,15 +239,15 @@ void transf_cdbk_dec_fx( } ELSE { - exp16 = sub( exp16, q_Code_preQ * 2 + 6 ); /* exp: (code_preQ in q_Code_preQ), -6 (/L_SUBFR) */ + exp16 = sub( exp16, add( imult1616( q_Code_preQ, 2 ), 6 ) ); /* exp: (code_preQ in q_Code_preQ), -6 (/L_SUBFR) */ L_tmp = Isqrt_lc( L_tmp, &exp16 ); tmp16 = extract_h( L_tmp ); - exp16 = 15 - 10 - exp16; /* tmp16 in Q10+exp16*/ - tmp16 = div_s( 16384, tmp16 ); /* Q15+Q14-(Q10+Qexp16) = Q19-exp16*/ + exp16 = sub( sub( 15, 10 ), exp16 ); /* tmp16 in Q10+exp16*/ + tmp16 = div_s( 16384, tmp16 ); /* Q15+Q14-(Q10+Qexp16) = Q19-exp16*/ L_tmp = L_mult( *gain_preQ, tmp16 ); /* Q2+Q19-exp16+1 -> Q22-exp16 */ L_tmp = Mult_32_16( L_tmp, 26214 ); /* Q22-Qexp16+Q15+1-16 -> Q22-exp16*/ - *norm_gain_preQ = L_shr( L_tmp, 6 - exp16 ); + *norm_gain_preQ = L_shr( L_tmp, sub( 6, exp16 ) ); move32(); /* Q22-exp16 -> Q16*/ } @@ -283,7 +295,7 @@ Word16 gain_dequant_fx( /* o: decoded gain */ Word16 e_tmp, f_tmp; Word16 tmp, frac; Word32 L_tmp; - levels = 1 << bits; + levels = shl( 1, bits ); /*c_min = (float)log10(min); c_mult = (float) ((levels-1)/(log10(max)-c_min)); diff --git a/lib_dec/dec_pit_exc_fx.c b/lib_dec/dec_pit_exc_fx.c index 024fcf809..f456e73a7 100644 --- a/lib_dec/dec_pit_exc_fx.c +++ b/lib_dec/dec_pit_exc_fx.c @@ -52,10 +52,11 @@ void dec_pit_exc_fx( { Word16 T0_fx, T0_frac_fx, T0_min_fx, T0_max_fx; /* integer pitch variables */ Word16 gain_pit_fx = 0; /* 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 */ + move16(); + 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 */ @@ -85,8 +86,7 @@ void dec_pit_exc_fx( move16(); test(); test(); - test(); - IF( GT_16( st_fx->GSC_IVAS_mode, 0 ) && ( EQ_16( st_fx->GSC_noisy_speech, 1 ) || GT_32( st_fx->core_brate, GSC_H_RATE_STG ) ) ) + 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; @@ -97,7 +97,8 @@ void dec_pit_exc_fx( IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) { Local_BR_fx = ACELP_14k80; - IF( GT_16( st_fx->GSC_IVAS_mode, 0 ) ) + move32(); + if ( st_fx->GSC_IVAS_mode > 0 ) { Local_BR_fx = ACELP_9k60; move32(); @@ -114,7 +115,7 @@ void dec_pit_exc_fx( move16(); Pitch_BR_fx = ACELP_7k20; move32(); - IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) + if ( EQ_16( st_fx->L_frame, L_FRAME16k ) ) { Pitch_BR_fx = st_fx->core_brate; move32(); @@ -149,12 +150,12 @@ void dec_pit_exc_fx( test(); test(); test(); - IF( ( ( GE_32( st_fx->core_brate, MIN_RATE_FCB ) || ( EQ_16( st_fx->GSC_noisy_speech, 1 ) && ( ( EQ_16( st_fx->L_frame, L_FRAME ) && GE_32( st_fx->core_brate, ACELP_13k20 ) ) || ( EQ_16( st_fx->L_frame, L_FRAME16k ) && GE_32( st_fx->core_brate, GSC_H_RATE_STG ) ) || st_fx->GSC_IVAS_mode == 0 ) ) ) && EQ_16( L_subfr_fx, L_SUBFR ) ) ) + IF ( ( ( GE_32( st_fx->core_brate, MIN_RATE_FCB ) || ( EQ_16( st_fx->GSC_noisy_speech, 1 ) && ( ( EQ_16( st_fx->L_frame, L_FRAME ) && GE_32( st_fx->core_brate, ACELP_13k20 ) ) || ( EQ_16( st_fx->L_frame, L_FRAME16k ) && GE_32( st_fx->core_brate, GSC_H_RATE_STG ) ) || st_fx->GSC_IVAS_mode == 0 ) ) ) && EQ_16( L_subfr_fx, L_SUBFR ) ) ) { use_fcb = 1; move16(); } - ELSE IF( GT_16( st_fx->GSC_IVAS_mode, 0 ) && EQ_16( L_subfr_fx, 2 * L_SUBFR ) && LT_16( st_fx->GSC_IVAS_mode, 3 ) ) + 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; @@ -230,11 +231,12 @@ void dec_pit_exc_fx( ELSE { nbits = 5; - IF( LT_32( st_fx->core_brate, MIN_RATE_FCB ) ) + move16(); + if ( LT_32( st_fx->core_brate, MIN_RATE_FCB ) ) { nbits = 4; + move16(); } - move16(); set16_fx( code_fx, 0, L_SUBFR ); gain_code_fx = L_deposit_l( 0 ); @@ -262,12 +264,12 @@ void dec_pit_exc_fx( * Find the total excitation *----------------------------------------------------------------------*/ - 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_fx, L_subfr_fx * HIBND_ACB_L_FAC, gain_code_fx, &( st_fx->Q_exc ), st_fx->Q_subfr, NULL, i_subfr_fx, coder_type ); + Rescale_exc( hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], &bwe_exc_fx[shr( imult1616( i_subfr_fx, 2 * HIBND_ACB_L_FAC ), 1 )], 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( NE_16( use_fcb, 0 ) ) + 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 ); } @@ -278,8 +280,8 @@ void dec_pit_exc_fx( FOR( i = 0; i < L_subfr_fx; i++ ) { #ifdef BASOP_NOGLOB - 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*/ + L_tmp = L_shl_sat( L_mult( gain_pit_fx, exc_fx[add( i, i_subfr_fx )] ), 1 ); /*Q16+Q_exc*/ + exc_fx[i + i_subfr_fx] = round_fx_sat( L_tmp ); /*Q_exc*/ #else L_tmp = L_shl( L_mult( gain_pit_fx, exc_fx[i + i_subfr_fx] ), 1 ); /*Q16+Q_exc*/ exc_fx[i + i_subfr_fx] = round_fx( L_tmp ); /*Q_exc*/ @@ -292,7 +294,7 @@ void dec_pit_exc_fx( FOR( i = 0; i < L_subfr_fx; i++ ) { - L_tmp = L_mult( gain_pitx2, exc_fx[i + i_subfr_fx] ); /*Q16+Q_exc*/ + L_tmp = L_mult( gain_pitx2, exc_fx[add( i, i_subfr_fx )] ); /*Q16+Q_exc*/ #ifdef BASOP_NOGLOB exc_fx[i + i_subfr_fx] = round_fx_sat( L_tmp ); /*Q_exc*/ #else @@ -485,10 +487,11 @@ void dec_pit_exc_ivas_fx( { Word16 T0_fx, T0_frac_fx, T0_min_fx, T0_max_fx; /* integer pitch variables */ Word16 gain_pit_fx = 0; /* 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 */ + move16(); + 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 */ @@ -519,7 +522,7 @@ void dec_pit_exc_ivas_fx( test(); test(); test(); - IF( GT_16( st_fx->GSC_IVAS_mode, 0 ) && ( EQ_16( st_fx->GSC_noisy_speech, 1 ) || GT_32( st_fx->core_brate, GSC_H_RATE_STG ) ) ) + 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; @@ -530,7 +533,8 @@ void dec_pit_exc_ivas_fx( IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) { Local_BR_fx = ACELP_14k80; - IF( GT_16( st_fx->GSC_IVAS_mode, 0 ) ) + move32(); + if ( st_fx->GSC_IVAS_mode > 0 ) { Local_BR_fx = ACELP_9k60; move32(); @@ -587,7 +591,7 @@ void dec_pit_exc_ivas_fx( use_fcb = 1; move16(); } - ELSE IF( GT_16( st_fx->GSC_IVAS_mode, 0 ) && EQ_16( L_subfr_fx, 2 * L_SUBFR ) && LT_16( st_fx->GSC_IVAS_mode, 3 ) ) + 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; @@ -664,11 +668,12 @@ void dec_pit_exc_ivas_fx( ELSE { nbits = 5; - IF( LT_32( st_fx->core_brate, MIN_RATE_FCB ) ) + move16(); + if ( LT_32( st_fx->core_brate, MIN_RATE_FCB ) ) { nbits = 4; + move16(); } - move16(); set16_fx( code_fx, 0, L_SUBFR ); gain_code_fx = L_deposit_l( 0 ); @@ -695,9 +700,8 @@ void dec_pit_exc_ivas_fx( /*----------------------------------------------------------------------* * Find the total excitation *----------------------------------------------------------------------*/ - - 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_fx, L_subfr_fx * HIBND_ACB_L_FAC, gain_code_fx, &( st_fx->Q_exc ), st_fx->Q_subfr, NULL, i_subfr_fx, coder_type ); + Rescale_exc( hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], &bwe_exc_fx[shr( imult1616( i_subfr_fx, 2 * HIBND_ACB_L_FAC ), 1 )], 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*/ @@ -711,8 +715,8 @@ void dec_pit_exc_ivas_fx( { FOR( i = 0; i < L_subfr_fx; i++ ) { - L_tmp = L_shl( L_mult( gain_pit_fx, exc_fx[i + i_subfr_fx] ), 1 ); /*Q16+Q_exc*/ - exc_fx[i + i_subfr_fx] = round_fx( L_tmp ); /*Q_exc*/ + L_tmp = L_shl( L_mult( gain_pit_fx, exc_fx[add( i, i_subfr_fx )] ), 1 ); /*Q16+Q_exc*/ + exc_fx[add( i, i_subfr_fx )] = round_fx( L_tmp ); /*Q_exc*/ } } ELSE @@ -721,8 +725,8 @@ void dec_pit_exc_ivas_fx( 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( L_tmp ); /*Q_exc*/ + L_tmp = L_mult( gain_pitx2, exc_fx[add( i, i_subfr_fx )] ); /*Q16+Q_exc*/ + exc_fx[add( i, i_subfr_fx )] = round_fx( L_tmp ); /*Q_exc*/ } } } diff --git a/lib_dec/dec_post_fx.c b/lib_dec/dec_post_fx.c index 38ce6836b..2552a15ec 100644 --- a/lib_dec/dec_post_fx.c +++ b/lib_dec/dec_post_fx.c @@ -55,10 +55,10 @@ void Init_post_filter_fx( { /* It is off by default */ hPFstat->on = 0; - + move16(); /* Reset */ hPFstat->reset = 0; - + move16(); /* Initialize arrays and pointers */ set16_fx( hPFstat->mem_pf_in, 0, L_SUBFR ); @@ -112,7 +112,7 @@ void nb_post_filt_fx( modify_pst_param_fx( *psf_lp_noise, &Post_G1, &Post_G2, coder_type, &Gain_factor ); - if ( hPFstat->reset ) + IF( hPFstat->reset ) { set16_fx( hPFstat->mem_res2, 0, DECMEM_RES2 ); Copy( &Synth[L_frame - L_SYN_MEM], hPFstat->mem_pf_in, L_SYN_MEM ); @@ -128,7 +128,7 @@ void nb_post_filt_fx( Copy( Synth, Pf_in, L_frame ); Copy( &Synth[L_frame - L_SYN_MEM], hPFstat->mem_pf_in, L_SYN_MEM ); /* deactivation of the post filter in case of AUDIO because it causes problems to singing sequences */ - if ( EQ_16( coder_type, AUDIO ) ) + IF( EQ_16( coder_type, AUDIO ) ) { Post_G1 = 32767; move16(); @@ -147,7 +147,7 @@ void nb_post_filt_fx( FOR( i = 0; i < L_frame; i += L_SUBFR ) { T0_first = Pitch_buf[j]; - + move16(); Dec_postfilt_fx( hPFstat, T0_first, &Pf_in[i], p_Aq, &Synth[i], Post_G1, Post_G2, Gain_factor, disable_hpf ); p_Aq += ( M + 1 ); @@ -1507,7 +1507,7 @@ static Word16 select_ltp_fx( /* o : 1 = 1st gain, 2 = 2nd gain Word16 temp1, temp2; - IF( den2 == 0 ) + if ( den2 == 0 ) { return 1; } @@ -1623,11 +1623,11 @@ static void calc_st_filt_ivas_fx( temp = sub( 2, norm_s( apond2[0] ) ); /* compute i.r. of composed filter apond2 / apond1 */ - if ( extl == SWB_TBE ) + IF( EQ_16( extl, SWB_TBE ) ) { E_UTIL_synthesis( temp, apond1, apond2, h, LONG_H_ST, mem_zero, 0, LPC_SHB_ORDER ); } - else + ELSE { E_UTIL_synthesis( temp, apond1, apond2, h, LONG_H_ST, mem_zero, 0, M ); } @@ -1762,7 +1762,7 @@ void Filt_mu_ivas_fx( Flag Overflow = 0; #endif - IF( extl == SWB_TBE ) + IF( EQ_16( extl, SWB_TBE ) ) { IF( parcor0 > 0 ) { diff --git a/lib_dec/dec_ppp_fx.c b/lib_dec/dec_ppp_fx.c index a63fca98b..facd78f1d 100644 --- a/lib_dec/dec_ppp_fx.c +++ b/lib_dec/dec_ppp_fx.c @@ -66,18 +66,19 @@ ivas_error decod_ppp_fx( ivas_error error; error = IVAS_ERR_OK; + move16(); /* call voiced decoder at this point */ FOR( k = 0; k < M; k++ ) { - p_Aq_curr_fx[k] = Aq_fx[k + ( 3 * ( M + 1 ) ) + 1]; + p_Aq_curr_fx[k] = Aq_fx[add( k, ( 3 * ( M + 1 ) ) + 1 )]; move16(); /*Q12 */ } deemph_lpc_fx( p_Aq_curr_fx, p_Aq_old_fx, LPC_de_curr_fx, LPC_de_old_fx, 0 ); /*LPC in Q12 */ - if ( ( error = ppp_voiced_decoder_fx( st_fx, excQ_ppp_fx, LPC_de_curr_fx, exc_fx, pitch_fx, bfi ) ) != IVAS_ERR_OK ) + IF ( ( error = ppp_voiced_decoder_fx( st_fx, excQ_ppp_fx, LPC_de_curr_fx, exc_fx, pitch_fx, bfi ) ) != IVAS_ERR_OK ) { return error; } diff --git a/lib_dec/dec_prm.c b/lib_dec/dec_prm.c index edbec1ebe..07f7d6de1 100644 --- a/lib_dec/dec_prm.c +++ b/lib_dec/dec_prm.c @@ -48,7 +48,184 @@ * * get TCX mode *--------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void getTCXMode_ivas_fx( + Decoder_State *st, /* i/o: decoder memory state */ + Decoder_State *st0, /* i : bitstream */ + const Word16 MCT_flag /* i : hMCT handle allocated (1) or not (0) */ +) +{ + UWord16 ind; + + IF( st->tcxonly ) + { + /* get core */ + ind = get_next_indice_fx( st0, 1 ); /* Store decoder memory of last_core */ + st->core = add( ind, TCX_20_CORE ); + move16(); + /* get class */ + ind = get_next_indice_fx( st0, 2 ); + + st->clas_dec = ONSET; + move16(); + IF( ind == 0 ) + { + st->clas_dec = UNVOICED_CLAS; + move16(); + } + ELSE IF( EQ_16( ind, 1 ) ) + { + IF( GE_16( st->last_good, VOICED_TRANSITION ) ) + { + st->clas_dec = VOICED_TRANSITION; + move16(); + } + ELSE + { + st->clas_dec = UNVOICED_TRANSITION; + move16(); + } + } + ELSE IF( EQ_16( ind, 2 ) ) + { + st->clas_dec = VOICED_CLAS; + move16(); + } + + st->coder_type = INACTIVE; + move16(); + test(); + IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && !MCT_flag ) + { + st->VAD = get_next_indice_fx( st0, 1 ); + move16(); + } + ELSE + { + st->VAD = 0; + move16(); + } + } + ELSE + { + IF( EQ_16( st->mdct_sw, MODE1 ) ) + { + /* 2 bits instead of 3 as TCX is already signaled */ + st->core = TCX_20_CORE; + move16(); + st->hTcxCfg->coder_type = get_next_indice_fx( st0, 2 ); + move16(); + st->coder_type = st->hTcxCfg->coder_type; + move16(); + } + ELSE + { + IF( EQ_16( st->mdct_sw_enable, MODE2 ) ) + { + IF( get_next_indice_1_fx( st0 ) ) + { + ind = get_next_indice_fx( st0, 3 ); + assert( !( ind & 4 ) || !"HQ_CORE encountered in dec_prm_ivas" ); + st->core = TCX_20_CORE; + move16(); + st->hTcxCfg->coder_type = ind; + move16(); + st->coder_type = st->hTcxCfg->coder_type; + move16(); + } + ELSE /* ACELP */ + { + st->core = ACELP_CORE; + move16(); + st->coder_type = get_next_indice_fx( st0, 2 ); + move16(); + } + } + ELSE + { + IF( EQ_16( st->rf_flag, 1 ) ) + { + IF( !st->use_partial_copy ) + { + ind = get_next_indice_fx( st0, 1 ); + IF( ind == 0 ) + { + st->core = ACELP_CORE; + move16(); + } + ELSE + { + st->core = TCX_20_CORE; + move16(); + st->hTcxCfg->coder_type = st->coder_type; + move16(); + } + } + } + ELSE + { + ind = get_next_indice_fx( st, 3 ); + IF( LT_16( ind, ACELP_MODE_MAX ) ) + { + st->core = ACELP_CORE; + move16(); + st->coder_type = ind; + move16(); + } + ELSE + { + st->core = TCX_20_CORE; + move16(); + st->hTcxCfg->coder_type = sub( ind, ACELP_MODE_MAX ); + move16(); + st->coder_type = st->hTcxCfg->coder_type; + move16(); + } + } + } + } + + IF( EQ_16( st->element_mode, EVS_MONO ) ) + { + test(); + IF( st->igf && EQ_16( st->core, ACELP_CORE ) ) + { + st->bits_frame_core = sub( st->bits_frame_core, get_tbe_bits_fx( st->total_brate, st->bwidth, st->rf_flag ) ); + move16(); + } + + IF( st->rf_flag ) + { + st->bits_frame_core = sub( st->bits_frame_core, add( st->rf_target_bits, 1 ) ); /* +1 as flag-bit not considered in rf_target_bits */ + move16(); + } + } + + /* Inactive frame detection on non-DTX mode */ + IF( EQ_16( st->coder_type, INACTIVE ) ) + { + st->VAD = 0; + move16(); + } + ELSE + { + st->VAD = 1; + move16(); + } + } + /*Core extended mode mapping for correct PLC classification*/ + st->core_ext_mode = st->coder_type; + move16(); + if( EQ_16( st->coder_type, INACTIVE ) ) + { + st->core_ext_mode = UNVOICED; + move16(); + } + + return; +} +#else void getTCXMode_ivas( Decoder_State *st, /* i/o: decoder memory state */ Decoder_State *st0, /* i : bitstream */ @@ -235,14 +412,95 @@ void getTCXMode_ivas( return; } - +#endif /*-------------------------------------------------------------------* * getTCXWindowing_ivas() * * get TCX transform type for each subframe *--------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void getTCXWindowing_ivas_fx( + const Word16 core, /* i : current core */ + const Word16 last_core, /* i : last frame core */ + const Word16 element_mode, /* i : element mode */ + TCX_CONFIG_HANDLE hTcxCfg, /* i/o: TCX configuration handle */ + Decoder_State *st0 /* i : bitstream */ +) +{ + Word16 overlap_code; + /* Set the last overlap mode based on the previous and current frame type and coded overlap mode */ + test(); + test(); + test(); + IF( EQ_16( last_core, ACELP_CORE ) || EQ_16( last_core, AMR_WB_CORE ) ) + { + hTcxCfg->tcx_last_overlap_mode = TRANSITION_OVERLAP; + move16(); + } + ELSE IF( EQ_16( core, TCX_10_CORE ) && EQ_16( hTcxCfg->tcx_curr_overlap_mode, ALDO_WINDOW ) ) + { + hTcxCfg->tcx_last_overlap_mode = FULL_OVERLAP; + move16(); + } + ELSE IF( NE_16( core, TCX_10_CORE ) && EQ_16( hTcxCfg->tcx_curr_overlap_mode, FULL_OVERLAP ) ) + { + hTcxCfg->tcx_last_overlap_mode = ALDO_WINDOW; + move16(); + } + ELSE + { + hTcxCfg->tcx_last_overlap_mode = hTcxCfg->tcx_curr_overlap_mode; + move16(); + } + + /* Set the current overlap mode based on the current frame type and coded overlap mode */ + hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW; + move16(); + + IF( NE_16( core, ACELP_CORE ) ) + { + overlap_code = 0; + move16(); + IF( get_next_indice_fx( st0, 1 ) ) + { + overlap_code = add( 2, get_next_indice_fx( st0, 1 ) ); + } + + assert( MIN_OVERLAP == 2 && HALF_OVERLAP == 3 ); + hTcxCfg->tcx_curr_overlap_mode = overlap_code; + move16(); + /*TCX10 : always symmetric windows*/ + test(); + test(); + test(); + IF( EQ_16( core, TCX_20_CORE ) && ( overlap_code == 0 ) && NE_16( last_core, ACELP_CORE ) && NE_16( last_core, AMR_WB_CORE ) ) + { + hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW; + move16(); + } + } + + test(); + IF( NE_16( element_mode, EVS_MONO ) && EQ_16( core, TCX_10_CORE ) ) + { + /* also read last overlap */ + overlap_code = 0; + move16(); + + IF( get_next_indice_fx( st0, 1 ) ) + { + overlap_code = add( 2, get_next_indice_fx( st0, 1 ) ); + } + + hTcxCfg->tcx_last_overlap_mode = overlap_code; + move16(); + } + + return; +} +#else void getTCXWindowing_ivas( const Word16 core, /* i : current core */ const Word16 last_core, /* i : last frame core */ @@ -321,7 +579,7 @@ void getTCXWindowing_ivas( return; } - +#endif /*-------------------------------------------------------------------* * getLPCparam_ivas() diff --git a/lib_dec/dec_prm_fx.c b/lib_dec/dec_prm_fx.c index 719661039..d30f407d6 100644 --- a/lib_dec/dec_prm_fx.c +++ b/lib_dec/dec_prm_fx.c @@ -27,19 +27,23 @@ void getLPCparam_fx( const Word16 sns_low_br_mode /* i : SNS low-bitrate mode */ ) { - IF( EQ_16( st->use_partial_copy, 0 ) ) + IF( st->use_partial_copy == 0 ) { /* Number of sets of LPC parameters (does not include mid-lpc) */ - IF( EQ_16( st->tcxonly, 0 ) || LT_16( st->core, TCX_10_CORE ) ) + test(); + IF( ( st->tcxonly == 0 ) || LT_16( st->core, TCX_10_CORE ) ) { st->numlpc = 1; + move16(); } ELSE { st->numlpc = 2; + move16(); } /* Decode LPC parameters */ + test(); IF( st->hTcxDec->enableTcxLpc && NE_16( st->core, ACELP_CORE ) ) { Word16 tcx_lpc_cdk; @@ -48,12 +52,14 @@ void getLPCparam_fx( } ELSE { - IF( EQ_16( st->lpcQuantization, 0 ) ) + IF( st->lpcQuantization == 0 ) { decode_lpc_avq_ivas_fx( st0, st->numlpc, param_lpc, ch, st->element_mode, sns_low_br_mode ); } ELSE IF( EQ_16( st->lpcQuantization, 1 ) ) { + test(); + test(); IF( EQ_32( st->sr_core, INT_FS_16k ) && EQ_16( st->coder_type, VOICED ) && EQ_16( st->core, ACELP_CORE ) ) { assert( EQ_16( st->element_mode, EVS_MONO ) ); @@ -73,19 +79,26 @@ void getLPCparam_fx( ELSE { st->numlpc = 1; - + move16(); + test(); IF( EQ_16( st->rf_frame_type, RF_TCXFD ) ) { param_lpc[0] = 0; + move16(); param_lpc[1] = get_next_indice_fx( st0, lsf_numbits[0] ); /* VQ 1 */ + move16(); param_lpc[2] = get_next_indice_fx( st0, lsf_numbits[1] ); /* VQ 2 */ + move16(); param_lpc[3] = get_next_indice_fx( st0, lsf_numbits[2] ); /* VQ 3 */ + move16(); } ELSE IF( GE_16( st->rf_frame_type, RF_ALLPRED ) && LE_16( st->rf_frame_type, RF_NELP ) ) { /* LSF indices */ param_lpc[0] = get_next_indice_fx( st0, 8 ); /* VQ 1 */ + move16(); param_lpc[1] = get_next_indice_fx( st0, 8 ); /* VQ 2 */ + move16(); } } @@ -122,7 +135,7 @@ void dec_prm_hm_fx( { tmp = 0; move16(); - if ( GE_16( L_frame, 256 ) ) + if( GE_16( L_frame, 256 ) ) { tmp = 1; move16(); @@ -168,46 +181,65 @@ void getTCXparam_fx( TCX_DEC_HANDLE hTcxDec = st->hTcxDec; - IF( EQ_16( pre_past_flag, 0 ) ) + IF( pre_past_flag == 0 ) { pre_part = 1; + move16(); post_part = 0; + move16(); } ELSE IF( EQ_16( pre_past_flag, 1 ) ) { pre_part = 0; + move16(); post_part = 1; + move16(); } ELSE { pre_part = 1; + move16(); post_part = 1; + move16(); } /* initialization */ tcxltp_prm_0 = 0; + move16(); tcxltp_prm_1 = 0; + move16(); tcxltp_prm_2 = 0; + move16(); nbits_igf = 0; + move16(); PeriodicityIndex = 0; + move16(); useHarmonicModel = 0; + move16(); core = st->core; + move16(); last_core = st->last_core; + move16(); nSubframes = 1; - IF( EQ_16( core, TCX_10_CORE ) ) + move16(); + if( EQ_16( core, TCX_10_CORE ) ) { nSubframes = 2; + move16(); } + test(); + test(); IF( LT_16( st->element_mode, IVAS_CPE_MDCT ) && st->igf && EQ_16( core, TCX_10_CORE ) ) { /* get IGF */ FOR( k = 0; k < nSubframes; k++ ) { ix = st->next_bit_pos; + move16(); IGFDecReadLevel( st->hIGFDec, st0, IGF_GRID_LB_SHORT, 1 - k ); IGFDecReadData( st->hIGFDec, st0, IGF_GRID_LB_SHORT, 1 - k ); IGFDecStoreTCX10SubFrameData( st->hIGFDec, k ); @@ -219,24 +251,32 @@ void getTCXparam_fx( FOR( k = 0; k < nSubframes; k++ ) { flag_ctx_hm = 0; - + move16(); prm = param + imult1616( k, DEC_NPRM_DIV ); j = 0; - + move16(); nbits_tcx = sub( st0->next_bit_pos, start_bit_pos ); + test(); + test(); IF( pre_part && st->enablePlcWaveadjust && EQ_16( k, ( nSubframes - 1 ) ) ) { st->tonality_flag = get_next_indice_fx( st0, 1 ); + move16(); } IF( post_part ) { /* TCX Gain */ - prm[j++] = get_next_indice_fx( st0, NBITS_TCX_GAIN ); + prm[j] = get_next_indice_fx( st0, NBITS_TCX_GAIN ); + j = add( j, 1 ); + move16(); /* TCX Noise Filling = NBITS_NOISE_FILL_LEVEL bits */ - prm[j++] = get_next_indice_fx( st0, NBITS_NOISE_FILL_LEVEL ); + prm[j] = get_next_indice_fx( st0, NBITS_NOISE_FILL_LEVEL ); + j = add( j, 1 ); + + move16(); } ELSE { @@ -246,38 +286,58 @@ void getTCXparam_fx( /* LTP data */ IF( pre_part ) { - IF( EQ_16( k, 0 ) && ( hTcxLtpDec->tcxltp || GT_32( st->sr_core, 25600 ) ) ) /* PLC pitch info for HB */ + test(); + test(); + IF( ( k == 0 ) && ( hTcxLtpDec->tcxltp || GT_32( st->sr_core, 25600 ) ) ) /* PLC pitch info for HB */ { prm[j] = get_next_indice_fx( st0, 1 ); + move16(); IF( prm[j] ) { - prm[j + 1] = get_next_indice_fx( st0, 9 ); - prm[j + 2] = get_next_indice_fx( st0, 2 ); + prm[add( j, 1 )] = get_next_indice_fx( st0, 9 ); + move16(); + prm[add( j, 2 )] = get_next_indice_fx( st0, 2 ); + move16(); tcxltp_prm_0 = prm[j]; + move16(); tcxltp_prm_1 = prm[j + 1]; + move16(); tcxltp_prm_2 = prm[j + 2]; + move16(); } st->BER_detect = st->BER_detect | tcx_ltp_decode_params( &prm[j], &( hTcxLtpDec->tcxltp_pitch_int ), &( hTcxLtpDec->tcxltp_pitch_fr ), &( hTcxLtpDec->tcxltp_gain ), st->pit_min, st->pit_fr1, st->pit_fr2, st->pit_max, st->pit_res_max ); + move16(); hTcxDec->tcxltp_last_gain_unmodified = hTcxLtpDec->tcxltp_gain; + move16(); + test(); + test(); IF( EQ_16( core, TCX_20_CORE ) && !st->tcxonly && LT_16( hTcxLtpDec->tcxltp_pitch_int, st->L_frame ) ) { // To be done at the end Word32 tmp32 = L_shl( L_mult0( st->L_frame, st->pit_res_max ), 1 + kLtpHmFractionalResolution + 1 ); Word16 tmp1 = add( imult1616( hTcxLtpDec->tcxltp_pitch_int, st->pit_res_max ), hTcxLtpDec->tcxltp_pitch_fr ); hTcxDec->tcx_hm_LtpPitchLag = div_l( tmp32, tmp1 ); + move16(); } ELSE { hTcxDec->tcx_hm_LtpPitchLag = -1; + move16(); } j = add( j, 3 ); } ELSE { - prm[j++] = tcxltp_prm_0; - prm[j++] = tcxltp_prm_1; - prm[j++] = tcxltp_prm_2; + prm[j] = tcxltp_prm_0; + j = add( j, 1 ); + move16(); + prm[j] = tcxltp_prm_1; + j = add( j, 1 ); + move16(); + prm[j] = tcxltp_prm_2; + j = add( j, 1 ); + move16(); } } @@ -285,13 +345,15 @@ void getTCXparam_fx( lg = shr( st->L_frame, sub( nSubframes, 1 ) ); lgFB = shr( st->hTcxCfg->tcx_coded_lines, sub( nSubframes, 1 ) ); - IF( post_part && EQ_16( k, 0 ) && EQ_16( st->last_core_from_bs, ACELP_CORE ) ) + test(); + test(); + IF( post_part && ( k == 0 ) && EQ_16( st->last_core_from_bs, ACELP_CORE ) ) { /* ACE->TCX transition */ lg = add( lg, st->hTcxCfg->tcx_offset ); lgFB = add( lgFB, shr( lgFB, sub( 3, nSubframes ) ) ); - IF( LT_16( st->hTcxCfg->lfacNext, 0 ) ) + if( st->hTcxCfg->lfacNext < 0 ) { lg = sub( lg, st->hTcxCfg->lfacNext ); } @@ -301,19 +363,26 @@ void getTCXparam_fx( { /* TNS data */ nTnsParams = 0; + move16(); nTnsBits = 0; + move16(); IF( st->hTcxCfg->fIsTNSAllowed ) { - IF( EQ_16( core, TCX_10_CORE ) && EQ_16( last_core, ACELP_CORE ) && EQ_16( k, 0 ) ) + test(); + test(); + IF( EQ_16( core, TCX_10_CORE ) && EQ_16( last_core, ACELP_CORE ) && ( k == 0 ) ) { st0->BER_detect = 1; + move16(); last_core = TCX_20_CORE; + move16(); } SetTnsConfig( st->hTcxCfg, (Word16) EQ_16( core, TCX_20_CORE ), (Word16) EQ_16( st->last_core_from_bs, ACELP_CORE ) && ( k == 0 ) ); ix = 0; + move16(); IF( no_param_tns ) { ix = get_next_indice_fx( st0, 1 ); /* common_tns_data[] for subframe k */ @@ -321,20 +390,25 @@ void getTCXparam_fx( IF( ix ) { prm[j] = imult1616( no_param_tns[k], -1 ); /* - signals common TNS and its size */ + move16(); nTnsParams = no_param_tns[k]; + move16(); } ELSE { ReadTnsData_ivas_fx( st->hTcxCfg->pCurrentTnsConfig, st0, &nTnsBits, prm + j, &nTnsParams ); } hTcxDec->tnsActive[k] = 0; - IF( prm[j] != 0 ) + move16(); + if ( prm[j] != 0 ) { hTcxDec->tnsActive[k] = nTnsParams; + move16(); } - IF( nTnsBitsTCX10 != NULL ) + if ( nTnsBitsTCX10 != NULL ) { nTnsBitsTCX10[k] = add( nTnsBits, ( no_param_tns ? 1 : 0 ) ); + move16(); } j = add( j, nTnsParams ); @@ -346,7 +420,7 @@ void getTCXparam_fx( { // Q-factor of TcxBandwidth is 15 : derived from getTcxBandwidth function hm_size = mult( st->TcxBandwidth, shl( lg, 1 ) ); - + test(); IF( hTcxDec->tcx_lpc_shaped_ari && NE_16( st->last_core_from_bs, ACELP_CORE ) ) { dec_prm_hm_fx( st0, &prm[j], hm_size ); @@ -361,17 +435,20 @@ void getTCXparam_fx( } /*Context HM flag*/ - IF( st->hTcxCfg->ctx_hm && !( EQ_16( st->last_core_from_bs, ACELP_CORE ) && EQ_16( k, 0 ) ) ) + test(); + test(); + IF( st->hTcxCfg->ctx_hm && !( EQ_16( st->last_core_from_bs, ACELP_CORE ) && ( k == 0 ) ) ) { useHarmonicModel = get_next_indice_fx( st0, 1 ); prm[j] = useHarmonicModel; + move16(); nbits_tcx = sub( nbits_tcx, 1 ); IF( useHarmonicModel ) { ix = DecodeIndex_fx( st0, (Word16) GE_16( hm_size, 256 ), prm + add( j, 1 ) ); flag_ctx_hm = 1; - + move16(); PeriodicityIndex = *( prm + add( j, 1 ) ); IF( EQ_16( st->element_mode, EVS_MONO ) ) { @@ -384,13 +461,15 @@ void getTCXparam_fx( j = add( j, NPRM_CTX_HM ); /* read IGF payload */ + test(); IF( post_part && EQ_16( core, TCX_20_CORE ) ) { IF( st->igf ) { ix = st->next_bit_pos; - IGFDecReadLevel( st->hIGFDec, st0, ( st->last_core_from_bs == ACELP_CORE ) ? IGF_GRID_LB_TRAN : IGF_GRID_LB_NORM, 1 ); - IGFDecReadData( st->hIGFDec, st0, ( st->last_core_from_bs == ACELP_CORE ) ? IGF_GRID_LB_TRAN : IGF_GRID_LB_NORM, 1 ); + move16(); + IGFDecReadLevel( st->hIGFDec, st0, ( EQ_16( st->last_core_from_bs, ACELP_CORE ) ) ? IGF_GRID_LB_TRAN : IGF_GRID_LB_NORM, 1 ); + IGFDecReadData( st->hIGFDec, st0, ( EQ_16( st->last_core_from_bs, ACELP_CORE ) ) ? IGF_GRID_LB_TRAN : IGF_GRID_LB_NORM, 1 ); nbits_tcx = sub( nbits_tcx, sub( st0->next_bit_pos, ix ) ); } @@ -399,14 +478,17 @@ void getTCXparam_fx( ELSE IF( p_param != NULL ) { p_param[k] = j; + move16(); } } ELSE { j = p_param[k]; + move16(); nbits_tcx = st->bits_frame_channel; - IF( EQ_16( st->core, TCX_10_CORE ) ) + move16(); + if ( EQ_16( st->core, TCX_10_CORE ) ) { nbits_tcx = sub( nTnsBitsTCX10[k], NBITS_TCX_GAIN + NOISE_FILL_RANGES * NBITS_NOISE_FILL_LEVEL ); } @@ -414,9 +496,12 @@ void getTCXparam_fx( IF( post_part ) { + test(); IF( hTcxDec->tcx_lpc_shaped_ari && EQ_16( core, TCX_20_CORE ) ) { - prm[j++] = nbits_tcx; /* store length of buffer */ + prm[j] = nbits_tcx; /* store length of buffer */ + j = add( j, 1 ); + move16(); prms = &prm[j]; FOR( ix = 0; ix < nbits_tcx; ix++ ) { @@ -424,7 +509,7 @@ void getTCXparam_fx( } FOR( ix = 0; ix < 32; ix++ ) { - prms[ix + nbits_tcx] = 1; + prms[add( ix, nbits_tcx )] = 1; } j = add( j, nbits_tcx ); } @@ -437,10 +522,12 @@ void getTCXparam_fx( ConfigureContextHm( lgFB, nbits_tcx, PeriodicityIndex, hTcxDec->tcx_hm_LtpPitchLag, &hm_cfg ); } hTcxDec->resQBits[k] = RCcontextMapping_decode2_no_mem_s17_LCS_fx( st0, prm + j, lgFB, nbits_tcx, imult1616( NPRM_RESQ, st->hTcxCfg->resq ), flag_ctx_hm ? &hm_cfg : NULL ); + move16(); } ELSE { hTcxDec->resQBits[k] = ACcontextMapping_decode2_no_mem_s17_LC( st0, prm + j, lgFB, nbits_tcx, imult1616( NPRM_RESQ, st->hTcxCfg->resq ), flag_ctx_hm ? &hm_cfg : NULL ); + move16(); } } } @@ -470,6 +557,7 @@ void dec_prm_fx( Word16 lgFB; Word16 start_bit_pos; Word16 acelp_target_bits = -1; + move16(); Word16 tmp; Word16 nTnsParams; Word16 nTnsBits; @@ -512,7 +600,7 @@ void dec_prm_fx( Mpy_32_16_ss( st->total_brate, 5243, &L_tmp, &lsb ); /* 5243 is 1/50 in Q18. (0+18-15=3) */ num_bits = extract_l( L_shr( L_tmp, 3 ) ); /* Q0 */ assert( num_bits == st->total_brate / 50 ); - IF( EQ_16( FrameSizeConfig[n].frame_bits, num_bits ) ) + if( EQ_16( FrameSizeConfig[n].frame_bits, num_bits ) ) { st->bits_frame_core = add( st->bits_frame_core, FrameSizeConfig[n].bandwidth_bits ); BREAK; @@ -529,6 +617,7 @@ void dec_prm_fx( ELSE { start_bit_pos = st->next_bit_pos; + move16(); } } @@ -561,7 +650,7 @@ void dec_prm_fx( ind = get_next_indice( st, 2 ); st->clas_dec = ONSET; move16(); - IF( ind == 0 ) + if( ind == 0 ) { st->clas_dec = UNVOICED_CLAS; move16(); @@ -570,18 +659,19 @@ void dec_prm_fx( { st->clas_dec = UNVOICED_TRANSITION; move16(); - if ( GE_16( st->last_good, VOICED_TRANSITION ) ) + if( GE_16( st->last_good, VOICED_TRANSITION ) ) { st->clas_dec = VOICED_TRANSITION; move16(); } } - ELSE if ( EQ_16( ind, 2 ) ) + ELSE IF( EQ_16( ind, 2 ) ) { st->clas_dec = VOICED_CLAS; move16(); } *coder_type = INACTIVE; + move16(); st->VAD = 0; move16(); } @@ -660,14 +750,16 @@ void dec_prm_fx( } test(); - IF( st->igf != 0 && EQ_16( st->core, ACELP_CORE ) ) + if ( ( st->igf != 0 ) && EQ_16( st->core, ACELP_CORE ) ) { st->bits_frame_core = sub( st->bits_frame_core, get_tbe_bits_fx( st->total_brate, st->bwidth, st->rf_flag ) ); + move16(); } - IF( EQ_16( st->rf_flag, 1 ) ) + if ( EQ_16( st->rf_flag, 1 ) ) { st->bits_frame_core = sub( st->bits_frame_core, add( st->rf_target_bits, 1 ) ); /* +1 as flag-bit not considered in rf_target_bits */ + move16(); } /* Inactive frame detection on non-DTX mode */ @@ -707,9 +799,12 @@ void dec_prm_fx( only for interpreting the bitstream and re-use the internal state for the proper transition handling; still, for voiced onsets rather stick to wrong windowing... */ + test(); + test(); if ( ( !( ( st->last_total_brate == 0 ) && ( sub( st->clas_dec, VOICED_CLAS ) != 0 ) ) ) && ( sub( st->last_core_from_bs, st->last_core ) != 0 ) ) { st->last_core = st->last_core_from_bs; + move16(); } /*for TCX 10 force last_core to be TCX since ACELP as previous core is forbidden*/ IF( EQ_16( st->core, TCX_10_CORE ) ) @@ -726,12 +821,12 @@ void dec_prm_fx( IF( EQ_16( st->rf_flag, 1 ) && EQ_16( st->use_partial_copy, 1 ) && !st->tcxonly ) { st->bits_frame_core = st->rf_target_bits; - + move16(); /* offset the indices to read the acelp partial copy */ Mpy_32_16_ss( st->total_brate, 5243, &L_tmp, &lsb ); /* 5243 is 1/50 in Q18. (0+18-15=3) */ num_bits = extract_l( L_shr( L_tmp, 3 ) ); /* Q0 */ - get_next_indice_tmp_fx( st, start_bit_pos + num_bits - st->rf_target_bits - 3 - st->next_bit_pos ); + get_next_indice_tmp_fx( st, sub( sub( sub( add( start_bit_pos, num_bits ), st->rf_target_bits ), 3 ), st->next_bit_pos ) ); } IF( st->use_partial_copy == 0 ) @@ -756,7 +851,7 @@ void dec_prm_fx( st->hTcxCfg->tcx_last_overlap_mode = st->hTcxCfg->tcx_curr_overlap_mode; move16(); test(); - if ( ( NE_16( st->core, TCX_10_CORE ) ) && ( EQ_16( st->hTcxCfg->tcx_curr_overlap_mode, FULL_OVERLAP ) ) ) + if( ( NE_16( st->core, TCX_10_CORE ) ) && ( EQ_16( st->hTcxCfg->tcx_curr_overlap_mode, FULL_OVERLAP ) ) ) { st->hTcxCfg->tcx_last_overlap_mode = ALDO_WINDOW; move16(); @@ -772,7 +867,7 @@ void dec_prm_fx( tmp = 0; move16(); /* if current TCX mode is not 0 (full overlap), read another bit */ - IF( get_next_indice( st, 1 ) ) + if ( get_next_indice( st, 1 ) ) { tmp = add( 2, get_next_indice( st, 1 ) ); } @@ -829,9 +924,10 @@ void dec_prm_fx( { move16(); st->dec_glr_idx = -1; - IF( EQ_16( st->core, ACELP_CORE ) ) + if ( EQ_16( st->core, ACELP_CORE ) ) { st->dec_glr_idx = get_next_indice( st, G_LPC_RECOVERY_BITS ); + move16(); } } } @@ -844,7 +940,7 @@ void dec_prm_fx( move16(); test(); test(); - IF( ( EQ_16( st->lpcQuantization, 1 ) && ( EQ_16( *coder_type, VOICED ) ) ) || ( st->use_partial_copy ) ) + if ( ( EQ_16( st->lpcQuantization, 1 ) && ( EQ_16( *coder_type, VOICED ) ) ) || ( st->use_partial_copy ) ) { st->acelp_cfg.midLpc = 0; move16(); @@ -856,7 +952,7 @@ void dec_prm_fx( st->numlpc = 2; move16(); test(); - if ( st->tcxonly == 0 || LT_16( st->core, TCX_10_CORE ) ) + if ( ( st->tcxonly == 0 ) || LT_16( st->core, TCX_10_CORE ) ) { st->numlpc = 1; move16(); @@ -912,14 +1008,19 @@ void dec_prm_fx( param_lpc[0] = 0; move16(); param_lpc[1] = get_next_indice( st, lsf_numbits[0] ); /* VQ 1 */ + move16(); param_lpc[2] = get_next_indice( st, lsf_numbits[1] ); /* VQ 2 */ + move16(); param_lpc[3] = get_next_indice( st, lsf_numbits[2] ); /* VQ 3 */ + move16(); } ELSE IF( GE_16( st->rf_frame_type, RF_ALLPRED ) && LE_16( st->rf_frame_type, RF_NELP ) ) { /* LSF indices */ param_lpc[0] = get_next_indice( st, 8 ); /* VQ 1 */ + move16(); param_lpc[1] = get_next_indice( st, 8 ); /* VQ 2 */ + move16(); } } @@ -932,7 +1033,7 @@ void dec_prm_fx( *--------------------------------------------------------------------------------*/ test(); test(); - IF( EQ_16( st->core, ACELP_CORE ) && st->use_partial_copy == 0 ) + IF( EQ_16( st->core, ACELP_CORE ) && ( st->use_partial_copy == 0 ) ) { /* Target Bits */ acelp_target_bits = sub( st->bits_frame_core, st->bits_common ); @@ -954,7 +1055,7 @@ void dec_prm_fx( move16(); st->bpf_gain_param = shl( st->acelp_cfg.bpf_mode, 1 ); - IF( n != 0 ) + if ( n != 0 ) { st->bpf_gain_param = get_next_indice( st, n ); move16(); @@ -963,9 +1064,10 @@ void dec_prm_fx( /* Mean energy (2 or 3 bits) */ n = ACELP_NRG_BITS[st->acelp_cfg.nrg_mode]; move16(); - IF( n != 0 ) + if ( n != 0 ) { - prm[j++] = get_next_indice( st, n ); + prm[j] = get_next_indice( st, n ); + j = add( j, 1 ); move16(); } @@ -976,16 +1078,18 @@ void dec_prm_fx( n = ACELP_LTP_BITS_SFR[st->acelp_cfg.ltp_mode][sfr]; move16(); - IF( n != 0 ) + IF ( n != 0 ) { - prm[j++] = get_next_indice( st, n ); + prm[j] = get_next_indice( st, n ); + j = add( j, 1 ); move16(); } /* Adaptive codebook filtering (1 bit) */ - IF( EQ_16( st->acelp_cfg.ltf_mode, 2 ) ) + IF ( EQ_16( st->acelp_cfg.ltf_mode, 2 ) ) { - prm[j++] = get_next_indice( st, 1 ); + prm[j] = get_next_indice( st, 1 ); + j = add( j, 1 ); move16(); } @@ -999,7 +1103,7 @@ void dec_prm_fx( /* sanity check for testing - not instrumented */ test(); - if ( GE_16( st->acelp_cfg.fixed_cdk_index[sfr], ACELP_FIXED_CDK_NB ) || ( st->acelp_cfg.fixed_cdk_index[sfr] < 0 ) ) + IF( GE_16( st->acelp_cfg.fixed_cdk_index[sfr], ACELP_FIXED_CDK_NB ) || ( st->acelp_cfg.fixed_cdk_index[sfr] < 0 ) ) { st->acelp_cfg.fixed_cdk_index[sfr] = 0; move16(); @@ -1009,10 +1113,11 @@ void dec_prm_fx( FOR( ix = 0; ix < wordcnt; ix++ ) { - prm[j++] = get_next_indice( st, 16 ); + prm[j] = get_next_indice( st, 16 ); + j = add( j, 1 ); move16(); } - IF( bitcnt ) + if ( bitcnt ) { prm[j] = get_next_indice( st, bitcnt ); move16(); @@ -1025,7 +1130,8 @@ void dec_prm_fx( n = ACELP_GAINS_BITS[st->acelp_cfg.gains_mode[sfr]]; move16(); - prm[j++] = get_next_indice( st, n ); + prm[j] = get_next_indice( st, n ); + j = add( j, 1 ); move16(); } /*end of subfr loop*/ } @@ -1051,31 +1157,42 @@ void dec_prm_fx( /* NELP gain indices */ st->rf_indx_nelp_iG1 = get_next_indice( st, 5 ); st->rf_indx_nelp_iG2[0] = get_next_indice( st, 6 ); + move16(); st->rf_indx_nelp_iG2[1] = get_next_indice( st, 6 ); + move16(); /* NELP filter selection index */ st->rf_indx_nelp_fid = get_next_indice( st, 2 ); + move16(); /* tbe gainFr */ st->rf_indx_tbeGainFr = get_next_indice( st, 5 ); + move16(); } ELSE { /* rf_frame_type ALL_PRED: 4, NO_PRED: 5, GEN_PRED: 6*/ /* ES pred */ - prm[j++] = get_next_indice( st, 3 ); + prm[j] = get_next_indice( st, 3 ); + move16(); + j = add( j, 1 ); ltp_mode = ACELP_LTP_MODE[1][1][st->rf_frame_type]; + move16(); gains_mode = ACELP_GAINS_MODE[1][1][st->rf_frame_type]; + move16(); /* Subframe parameters */ FOR( sfr = 0; sfr < nb_subfr; sfr++ ) { /* Pitch lag (5, or 8 bits) */ n = ACELP_LTP_BITS_SFR[ltp_mode][sfr]; - IF( n != 0 ) + move16(); + IF ( n != 0 ) { - prm[j++] = get_next_indice( st, n ); + prm[j] = get_next_indice( st, n ); + j = add( j, 1 ); + move16(); } /*Innovative codebook*/ @@ -1087,6 +1204,7 @@ void dec_prm_fx( /* NOTE: FCB actual bits need to be backed up as well */ /*n = ACELP_FIXED_CDK_BITS(st->rf_indx_fcb[fec_offset][sfr]) & 15;*/ prm[j] = get_next_indice( st, 7 ); + move16(); j = add( j, 8 ); } @@ -1095,11 +1213,15 @@ void dec_prm_fx( IF( sfr == 0 || EQ_16( sfr, 2 ) ) { n = ACELP_GAINS_BITS[gains_mode]; - prm[j++] = get_next_indice( st, n ); + move16(); + prm[j] = get_next_indice( st, n ); + j = add( j, 1 ); + move16(); } } st->rf_indx_tbeGainFr = get_next_indice( st, 2 ); + move16(); } } @@ -1112,18 +1234,20 @@ void dec_prm_fx( flag_ctx_hm = 0; move16(); - IF( st->enablePlcWaveadjust ) + if ( st->enablePlcWaveadjust ) { st->tonality_flag = get_next_indice( st, 1 ); move16(); } /* TCX Gain = 7 bits */ - prm[j++] = get_next_indice( st, 7 ); + prm[j] = get_next_indice( st, 7 ); + j = add( j, 1 ); move16(); /* TCX Noise Filling = NBITS_NOISE_FILL_LEVEL bits */ - prm[j++] = get_next_indice( st, NBITS_NOISE_FILL_LEVEL ); + prm[j] = get_next_indice( st, NBITS_NOISE_FILL_LEVEL ); + j = add( j, 1 ); move16(); /* LTP data */ @@ -1176,7 +1300,7 @@ void dec_prm_fx( lgFB = st->hTcxCfg->tcx_coded_lines; move16(); - IF( st->last_core_from_bs == ACELP_CORE ) + IF( EQ_16( st->last_core_from_bs, ACELP_CORE ) ) { /* ACE->TCX transition */ lg = add( lg, st->hTcxCfg->tcx_offset ); @@ -1196,7 +1320,7 @@ void dec_prm_fx( IF( st->hTcxCfg->fIsTNSAllowed ) { - SetTnsConfig( st->hTcxCfg, 1, st->last_core_from_bs == ACELP_CORE ); + SetTnsConfig( st->hTcxCfg, 1, (Word16)EQ_16(st->last_core_from_bs , ACELP_CORE) ); ReadTnsData( st->hTcxCfg->pCurrentTnsConfig, st, &nTnsBits, prm + j, &nTnsParams ); j = add( j, nTnsParams ); @@ -1204,7 +1328,7 @@ void dec_prm_fx( hm_size = shl( mult( st->TcxBandwidth, lg ), 1 ); test(); - IF( hTcxDec->tcx_lpc_shaped_ari != 0 && NE_16( st->last_core_from_bs, ACELP_CORE ) ) + IF( ( hTcxDec->tcx_lpc_shaped_ari != 0 ) && NE_16( st->last_core_from_bs, ACELP_CORE ) ) { dec_prm_hm_fx( st, &prm[j], hm_size ); } @@ -1229,7 +1353,7 @@ void dec_prm_fx( tmp = 0; move16(); - if ( GE_16( hm_size, 256 ) ) + IF( GE_16( hm_size, 256 ) ) { tmp = 1; move16(); @@ -1275,7 +1399,8 @@ void dec_prm_fx( nbits_tcx = sub( st->bits_frame_core, sub( st->next_bit_pos, start_bit_pos ) ); IF( hTcxDec->tcx_lpc_shaped_ari != 0 ) { - prm[j++] = nbits_tcx; /* store length of buffer */ + prm[j] = nbits_tcx; /* store length of buffer */ + j = add( j, 1 ); move16(); prms = &prm[j]; FOR( ix = 0; ix < nbits_tcx; ix++ ) @@ -1338,12 +1463,14 @@ void dec_prm_fx( { /* TCX Gain = 7 bits */ hTcxDec->old_gaintcx_bfi = get_next_indice( st, 7 ); + move16(); } ELSE { /* LTP data */ IF( hTcxLtpDec->tcxltp != 0 ) { + test(); IF( EQ_16( st->rf_frame_type, RF_TCXTD2 ) || EQ_16( st->rf_frame_type, RF_TCXTD1 ) ) { prm_ltp[0] = 1; @@ -1357,7 +1484,7 @@ void dec_prm_fx( st->BER_detect = st->BER_detect | tcx_ltp_decode_params( &prm_ltp[0], &( hTcxLtpDec->tcxltp_pitch_int ), &( hTcxLtpDec->tcxltp_pitch_fr ), &( hTcxLtpDec->tcxltp_gain ), st->pit_min, st->pit_fr1, st->pit_fr2, st->pit_max, st->pit_res_max ); - + move16(); hTcxDec->tcxltp_last_gain_unmodified = hTcxLtpDec->tcxltp_gain; move16(); } @@ -1409,17 +1536,19 @@ void dec_prm_fx( nbits_tcx = sub( st->next_bit_pos, start_bit_pos ); test(); - IF( st->enablePlcWaveadjust && k ) + if ( st->enablePlcWaveadjust && k ) { st->tonality_flag = get_next_indice( st, 1 ); move16(); } /* TCX Gain = 7 bits */ - prm[j++] = get_next_indice( st, 7 ); + prm[j] = get_next_indice( st, 7 ); + j = add( j, 1 ); move16(); /* TCX Noise Filling = NBITS_NOISE_FILL_LEVEL bits */ - prm[j++] = get_next_indice( st, NBITS_NOISE_FILL_LEVEL ); + prm[j] = get_next_indice( st, NBITS_NOISE_FILL_LEVEL ); + j = add( j, 1 ); move16(); /* LTP data */ @@ -1466,11 +1595,14 @@ void dec_prm_fx( } ELSE { - prm[j++] = tcxltp_prm_0; + prm[j] = tcxltp_prm_0; + j = add( j, 1 ); move16(); - prm[j++] = tcxltp_prm_1; + prm[j] = tcxltp_prm_1; + j = add( j, 1 ); move16(); - prm[j++] = tcxltp_prm_2; + prm[j] = tcxltp_prm_2; + j = add( j, 1 ); move16(); } @@ -1479,11 +1611,11 @@ void dec_prm_fx( lgFB = shr( st->hTcxCfg->tcx_coded_lines, 1 ); test(); - IF( k == 0 && st->last_core_from_bs == ACELP_CORE ) + IF( k == 0 && EQ_16( st->last_core_from_bs, ACELP_CORE ) ) { /* ACE->TCX transition */ lg = add( lg, st->hTcxCfg->tcx_offset ); - if ( st->hTcxCfg->lfacNext < 0 ) + IF( st->hTcxCfg->lfacNext < 0 ) { lg = sub( lg, st->hTcxCfg->lfacNext ); } @@ -1499,9 +1631,11 @@ void dec_prm_fx( IF( st->hTcxCfg->fIsTNSAllowed ) { + test(); IF( EQ_16( st->last_core_from_bs, ACELP_CORE ) && ( k == 0 ) ) { st->BER_detect = 1; + move16(); st->last_core = TCX_20_CORE; move16(); st->last_core_from_bs = TCX_20_CORE; @@ -1523,7 +1657,7 @@ void dec_prm_fx( /*Context HM flag*/ test(); test(); - IF( st->hTcxCfg->ctx_hm && !( st->last_core_from_bs == ACELP_CORE && k == 0 ) ) + IF( st->hTcxCfg->ctx_hm && !( EQ_16( st->last_core_from_bs, ACELP_CORE ) && ( k == 0 ) ) ) { prm[j] = get_next_indice_fx( st, 1 ); move16(); @@ -1564,6 +1698,7 @@ void dec_prm_fx( st->BER_detect = 1; move16(); st->next_bit_pos = add( start_bit_pos, sub( *total_nbbits, bitsRead[0] ) ); + move16(); } bitsRead[0] = sub( st->next_bit_pos, start_bit_pos ); move16(); diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index 394cec09c..cc2de5052 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -74,6 +74,7 @@ void decoder_tcx_fx( Word16 h1[L_FRAME_MAX / 4 + 1]; Word16 mem[M]; Word16 temp_concealment_method = 0; + move16(); Word16 arith_bits, signaling_bits; Word16 *prm_ltp, *prm_tns, *prm_hm, *prm_sqQ, *prm_target; Word16 *pInfoTCXNoise; @@ -94,9 +95,10 @@ void decoder_tcx_fx( prm_target = NULL; /* just to suppress MSVC warnigs */ - x_e = 0; /* to avoid compilation warnings */ + x_e = 0; /* to avoid compilation warnings */ + move16(); nf_seed = 0; /* to avoid compilation warnings */ - + move16(); /* Overlay xn_buf32 with xn_buf */ xn_buf = (Word16 *) xn_buf32; @@ -114,6 +116,7 @@ void decoder_tcx_fx( FOR( i = 0; i < ( L_MDCT_OVLP_MAX + L_FRAME_PLUS + L_MDCT_OVLP_MAX ) / 2; i++ ) { xn_buf32[i] = L_deposit_l( 0 ); + move32(); } @@ -166,7 +169,7 @@ void decoder_tcx_fx( ELSE { test(); - IF( frame_cnt == 0 && st->last_core == ACELP_CORE ) + IF( frame_cnt == 0 && EQ_16( st->last_core, ACELP_CORE ) ) { if ( st->prev_bfi == 0 ) { @@ -205,7 +208,7 @@ void decoder_tcx_fx( IF( frame_cnt == 0 && EQ_16( st->last_core_from_bs, ACELP_CORE ) ) { - L_spec += st->hTcxCfg->tcx_coded_lines >> 2; + L_spec = add( L_spec, shr( st->hTcxCfg->tcx_coded_lines, 2 ) ); } st->L_frame_past = L_frame; @@ -328,7 +331,7 @@ void decoder_tcx_fx( *-----------------------------------------------------------*/ test(); test(); - IF( hTcxCfg->ctx_hm != 0 && ( ( st->last_core_from_bs != ACELP_CORE ) || ( frame_cnt > 0 ) ) ) + IF( hTcxCfg->ctx_hm != 0 && ( ( NE_16( st->last_core_from_bs, ACELP_CORE ) ) || ( frame_cnt > 0 ) ) ) { st->last_ctx_hm_enabled = prm_hm[0]; move16(); @@ -336,8 +339,7 @@ void decoder_tcx_fx( FOR( i = 0; i < L_spec; i++ ) /* no context harmonic model, copy MDCT coefficients to x */ { - x[i] = L_mult( prm_sqQ[i], - 1 << ( 30 - SPEC_EXP_DEC ) ); + x[i] = L_mult( prm_sqQ[i], shl( 1, sub( 30, SPEC_EXP_DEC ) ) ); move32(); } } @@ -387,8 +389,7 @@ void decoder_tcx_fx( FOR( i = 0; i < L_spec; i++ ) { - x[i] = L_mult( prm_sqQ[i], - 1 << ( 30 - SPEC_EXP_DEC ) ); + x[i] = L_mult( prm_sqQ[i], shl( 1, sub( 30, SPEC_EXP_DEC ) ) ); move32(); } @@ -426,7 +427,7 @@ void decoder_tcx_fx( /* Global Gain */ hTcxDec->damping = 0; - + move16(); IF( bfi == 0 ) { /*-----------------------------------------------------------* @@ -443,10 +444,12 @@ void decoder_tcx_fx( tmp1 = mult_r( shl( L_spec, 5 ), 26214 /*128.f/NORM_MDCT_FACTOR Q15*/ ); #endif s = 15 - 5 - 7; + move16(); if ( L_spec >= 1024 ) /*reduce precision for avoiding overflow*/ { tmp1 = mult_r( shl( L_spec, 4 ), 26214 /*128.f/NORM_MDCT_FACTOR Q15*/ ); s = 15 - 4 - 7; + move16(); } tmp1 = ISqrt16( tmp1, &s ); @@ -477,6 +480,7 @@ void decoder_tcx_fx( tmp1 = mult_r( shl( L_spec, 5 ), 26214 /*128.f/NORM_MDCT_FACTOR Q15*/ ); s = 15 - 5 - 7; + move16(); tmp1 = ISqrt16( tmp1, &s ); gain_tcx = mult( gain_tcx, tmp1 ); @@ -673,8 +677,6 @@ void decoder_tcx_fx( test(); IF( bfi == 0 && st->tcxonly == 0 ) { - - /* Replication of ACELP formant enhancement for low rates */ IF( LT_32( st->total_brate, ACELP_13k20 ) || st->rf_flag != 0 ) { @@ -726,7 +728,7 @@ void decoder_tcx_fx( move16(); test(); test(); - if ( ( hTcxCfg->ctx_hm != 0 ) && ( st->last_core != ACELP_CORE ) && ( st->last_ctx_hm_enabled != 0 ) ) + if ( ( hTcxCfg->ctx_hm != 0 ) && ( NE_16( st->last_core, ACELP_CORE ) ) && ( st->last_ctx_hm_enabled != 0 ) ) { tmp1 = 10240 /*0.3125f Q15*/; move16(); @@ -826,9 +828,10 @@ void decoder_tcx_fx( } } /* get the starting location of the subframe in the frame */ - IF( EQ_16( st->core, TCX_10_CORE ) ) + if ( EQ_16( st->core, TCX_10_CORE ) ) { st->plcInfo.subframe_fx = extract_l( L_mult0( frame_cnt, L_frameTCX_glob ) ); + move16(); } } @@ -860,7 +863,11 @@ void decoder_tcx_fx( test(); test(); - IF( ( frame_cnt == 0 ) && ( EQ_16( L_frameTCX, shr( hTcxDec->L_frameTCX, 1 ) ) ) && ( st->tcxonly ) && ( !st->tonal_mdct_plc_active ) && ( EQ_16( st->nbLostCmpt, 1 ) ) && ( hTcxCfg->tcx_last_overlap_mode != FULL_OVERLAP ) && ( hTcxCfg->tcx_curr_overlap_mode != FULL_OVERLAP ) ) + test(); + test(); + test(); + test(); + IF( ( frame_cnt == 0 ) && ( EQ_16( L_frameTCX, shr( hTcxDec->L_frameTCX, 1 ) ) ) && ( st->tcxonly ) && ( !st->tonal_mdct_plc_active ) && ( EQ_16( st->nbLostCmpt, 1 ) ) && ( NE_16( hTcxCfg->tcx_last_overlap_mode, FULL_OVERLAP ) ) && ( NE_16( hTcxCfg->tcx_curr_overlap_mode, FULL_OVERLAP ) ) ) { Word16 exp1, exp2; Word32 E_2ndlast, E_last; @@ -939,7 +946,7 @@ void decoder_tcx_fx( test(); test(); test(); - IF( bfi && ( !st->enablePlcWaveadjust || EQ_16( temp_concealment_method, TCX_TONAL ) ) && st->igf && ( frame_cnt == 0 ) && ( EQ_16( L_frameTCX, shr( hTcxDec->L_frameTCX, 1 ) ) ) && ( st->tcxonly ) && ( !st->tonal_mdct_plc_active ) && ( EQ_16( st->nbLostCmpt, 1 ) ) && ( hTcxCfg->tcx_last_overlap_mode != FULL_OVERLAP ) && ( hTcxCfg->tcx_curr_overlap_mode != FULL_OVERLAP ) ) + IF( bfi && ( !st->enablePlcWaveadjust || EQ_16( temp_concealment_method, TCX_TONAL ) ) && st->igf && ( frame_cnt == 0 ) && ( EQ_16( L_frameTCX, shr( hTcxDec->L_frameTCX, 1 ) ) ) && ( st->tcxonly ) && ( !st->tonal_mdct_plc_active ) && ( EQ_16( st->nbLostCmpt, 1 ) ) && ( NE_16( hTcxCfg->tcx_last_overlap_mode, FULL_OVERLAP ) ) && ( NE_16( hTcxCfg->tcx_curr_overlap_mode, FULL_OVERLAP ) ) ) { IGFDecCopyLPCFlatSpectrum( st->hIGFDec, x, x_e, IGF_GRID_LB_SHORT ); Copy( st->hIGFDec->igfData.igf_curr_subframe[0][0], st->hIGFDec->igfData.igf_curr_subframe[1][0], IGF_MAX_SFB ); @@ -995,6 +1002,7 @@ void decoder_tcx_fx( } /* PLC: [TCX: Tonal Concealment] */ + test(); IF( bfi && st->tonal_mdct_plc_active ) { TonalMDCTConceal_Apply( &st->tonalMDCTconceal, x, &x_e ); @@ -1049,10 +1057,12 @@ void decoder_tcx_fx( { /* packet loss after first TCX must be handled like transition frame */ igfGridIdx = IGF_GRID_LB_TRAN; + move16(); } ELSE { igfGridIdx = IGF_GRID_LB_NORM; + move16(); } *st->hIGFDec->igfData.igfInfo.nfSeed = extract_l( L_mac0( 13849L, nf_seed, 31821 ) ); @@ -1081,7 +1091,9 @@ void decoder_tcx_fx( IF( st->hIGFDec->flatteningTrigger != 0 && fUseTns == 0 ) { Word16 startLine = st->hIGFDec->infoIGFStartLine; + move16(); Word16 endLine = st->hIGFDec->infoIGFStopLine; + move16(); Word32 x_itf[N_MAX_TCX - IGF_START_MN]; Word16 j; @@ -1089,14 +1101,12 @@ void decoder_tcx_fx( const Word32 *virtualSpec = st->hIGFDec->virtualSpec; const Word16 maxOrder = 8; + move16(); Word16 curr_order = 0; /* not counted */ + move16(); Word16 A_itf[ITF_MAX_FILTER_ORDER + 1]; Word16 Q_A_itf; Word16 predictionGain = 0; /* not counted */ - - move16(); - move16(); - move16(); FOR( j = startLine; j < endLine; j++ ) @@ -1241,6 +1251,7 @@ void decoder_tcx_fx( IF( !bfi ) { st->second_last_tns_active = st->last_tns_active; + move16(); st->last_tns_active = 0; move16(); test(); @@ -1255,8 +1266,11 @@ void decoder_tcx_fx( hTcxDec->tcxltp_second_last_pitch = st->old_fpitch; move32(); st->old_fpitch = L_add( L_deposit_h( hTcxLtpDec->tcxltp_pitch_int ), L_mult( hTcxLtpDec->tcxltp_pitch_fr, div_s( 1, st->pit_res_max ) /*Q16*/ ) ); + move32(); st->old_fpitchFB = Mpy_32_16_1( st->old_fpitch /*Q16*/, mult_r( L_frameTCX /*Q0*/, getInvFrameLen( L_frame ) /*Q21*/ ) /*Q6*/ ) /*Q7*/; + move32(); st->old_fpitchFB = L_shr( st->old_fpitchFB, 7 - 16 ); /*->Q16*/ + move32(); } @@ -1514,7 +1528,8 @@ void decoder_tcx_post_fx( Decoder_State *st_fx, hTcxDec->conceal_eof_gain = round_fx( conceal_eof_gain32 ); /*Q14*/ move16(); #endif - /* run lpc gain compensation not for waveform adjustment */ test(); + /* run lpc gain compensation not for waveform adjustment */ + test(); IF( 0 == st_fx->enablePlcWaveadjust || EQ_16( st_fx->plcInfo.concealment_method, TCX_TONAL ) ) { #ifdef BASOP_NOGLOB @@ -1570,16 +1585,16 @@ void decoder_tcx_post_fx( Decoder_State *st_fx, st_fx->bfi_pitch_frame = st_fx->L_frame; move16(); - st_fx->mem_pitch_gain[2 * st_fx->nb_subfr + 1] = st_fx->mem_pitch_gain[st_fx->nb_subfr + 1]; + st_fx->mem_pitch_gain[add( shl( st_fx->nb_subfr, 1 ), 1 )] = st_fx->mem_pitch_gain[st_fx->nb_subfr + 1]; move16(); - st_fx->mem_pitch_gain[2 * st_fx->nb_subfr] = st_fx->mem_pitch_gain[st_fx->nb_subfr]; + st_fx->mem_pitch_gain[st_fx->nb_subfr * 2] = st_fx->mem_pitch_gain[st_fx->nb_subfr]; move16(); FOR( i = 0; i < st_fx->nb_subfr; i++ ) { - st_fx->mem_pitch_gain[2 * st_fx->nb_subfr - 1 - i] = st_fx->mem_pitch_gain[st_fx->nb_subfr - 1 - i]; + st_fx->mem_pitch_gain[sub( sub( shl( st_fx->nb_subfr, 1 ), 1 ), i )] = st_fx->mem_pitch_gain[sub( sub( st_fx->nb_subfr, 1 ), i )]; move16(); - st_fx->mem_pitch_gain[st_fx->nb_subfr - 1 - i] = hTcxDec->tcxltp_last_gain_unmodified; + st_fx->mem_pitch_gain[sub( sub( st_fx->nb_subfr, 1 ), i )] = hTcxDec->tcxltp_last_gain_unmodified; move16(); } } @@ -1614,13 +1629,15 @@ void decoder_tcx_post_ivas_fx( Decoder_State *st_fx, /* first TCX frame after ACELP; overwrite ltp initialization done during acelp PLC */ test(); test(); - IF( !st_fx->bfi && st_fx->prev_bfi && EQ_16( st_fx->last_core, ACELP_CORE ) ) + if ( !st_fx->bfi && st_fx->prev_bfi && EQ_16( st_fx->last_core, ACELP_CORE ) ) { hTcxDec->tcxltp_last_gain_unmodified = 0; move16(); } - - IF( st_fx->hTcxLtpDec != NULL && st_fx->element_mode > EVS_MONO && ( st_fx->clas_dec == UNVOICED_CLAS || st_fx->clas_dec == INACTIVE_CLAS ) ) + test(); + test(); + test(); + IF( st_fx->hTcxLtpDec != NULL && GT_16( st_fx->element_mode, EVS_MONO ) && ( EQ_16( st_fx->clas_dec, UNVOICED_CLAS ) || EQ_16( st_fx->clas_dec, INACTIVE_CLAS ) ) ) { /* deactivate TCX LTP for non-voiced frames */ st_fx->hTcxLtpDec->tcxltp = 0; @@ -1628,9 +1645,10 @@ void decoder_tcx_post_ivas_fx( Decoder_State *st_fx, st_fx->hTcxLtpDec->tcxltp_gain = 0; move16(); } - + test(); IF( bfi != 0 && st_fx->use_partial_copy == 0 ) { + test(); test(); /* run lpc gain compensation not for waveform adjustment */ IF( 0 == st_fx->enablePlcWaveadjust || ( st_fx->hPlcInfo != NULL && EQ_16( st_fx->plcInfo.concealment_method, TCX_TONAL ) ) ) @@ -1705,6 +1723,8 @@ void decoder_tcx_post_ivas_fx( Decoder_State *st_fx, level_syn_e = s; // add(s, 15); test(); test(); + test(); + test(); IF( bfi == 0 && st_fx->tcxonly != 0 && ( NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) || MCT_flag ) && EQ_16( st_fx->clas_dec, UNVOICED_CLAS ) ) { @@ -1754,13 +1774,15 @@ void decoder_tcx_post_ivas_fx( Decoder_State *st_fx, &gainCNG, &gainCNG_e ); } - if ( st_fx->element_mode == IVAS_CPE_MDCT && !MCT_flag ) + test(); + IF( EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) && !MCT_flag ) { - if ( st_fx->nbLostCmpt > MDCT_ST_PLC_FADEOUT_MAX_CONC_FRAME + MDCT_ST_PLC_FADEOUT_TO_ZERO_LEN ) + IF( GT_16( st_fx->nbLostCmpt, MDCT_ST_PLC_FADEOUT_MAX_CONC_FRAME + MDCT_ST_PLC_FADEOUT_TO_ZERO_LEN ) ) { gainCNG = 0; + move16(); } - else if ( st_fx->nbLostCmpt > MDCT_ST_PLC_FADEOUT_MAX_CONC_FRAME ) + ELSE IF( GT_16( st_fx->nbLostCmpt, MDCT_ST_PLC_FADEOUT_MAX_CONC_FRAME ) ) { Word16 tmp, q_tmp; tmp = BASOP_Util_Divide1616_Scale( sub( st_fx->nbLostCmpt, MDCT_ST_PLC_FADEOUT_MAX_CONC_FRAME ), MDCT_ST_PLC_FADEOUT_TO_ZERO_LEN, &q_tmp ); @@ -1845,7 +1867,8 @@ void decoder_tcx_post_ivas_fx( Decoder_State *st_fx, hTcxDec->conceal_eof_gain = round_fx( conceal_eof_gain32 ); /*Q14*/ move16(); #endif - /* run lpc gain compensation not for waveform adjustment */ test(); + /* run lpc gain compensation not for waveform adjustment */ + test(); IF( 0 == st_fx->enablePlcWaveadjust || EQ_16( st_fx->plcInfo.concealment_method, TCX_TONAL ) ) { #ifdef BASOP_NOGLOB @@ -1861,6 +1884,7 @@ void decoder_tcx_post_ivas_fx( Decoder_State *st_fx, ELSE { st_fx->plcInfo.recovery_gain = extract_h( conceal_eof_gainFB ); /*Q14*/ + move16(); } st_fx->plcInfo.step_concealgain_fx = #ifdef BASOP_NOGLOB @@ -1901,16 +1925,16 @@ void decoder_tcx_post_ivas_fx( Decoder_State *st_fx, st_fx->bfi_pitch_frame = st_fx->L_frame; move16(); - st_fx->mem_pitch_gain[2 * st_fx->nb_subfr + 1] = st_fx->mem_pitch_gain[st_fx->nb_subfr + 1]; + st_fx->mem_pitch_gain[add( shl( st_fx->nb_subfr, 1 ), 1 )] = st_fx->mem_pitch_gain[st_fx->nb_subfr + 1]; move16(); - st_fx->mem_pitch_gain[2 * st_fx->nb_subfr] = st_fx->mem_pitch_gain[st_fx->nb_subfr]; + st_fx->mem_pitch_gain[shl( st_fx->nb_subfr, 1 )] = st_fx->mem_pitch_gain[st_fx->nb_subfr]; move16(); FOR( i = 0; i < st_fx->nb_subfr; i++ ) { - st_fx->mem_pitch_gain[2 * st_fx->nb_subfr - 1 - i] = st_fx->mem_pitch_gain[st_fx->nb_subfr - 1 - i]; + st_fx->mem_pitch_gain[sub( sub( shl( st_fx->nb_subfr, 1 ), 1 ), i )] = st_fx->mem_pitch_gain[sub( sub( st_fx->nb_subfr, 1 ), i )]; move16(); - st_fx->mem_pitch_gain[st_fx->nb_subfr - 1 - i] = hTcxDec->tcxltp_last_gain_unmodified; + st_fx->mem_pitch_gain[sub( sub( st_fx->nb_subfr, 1 ), i )] = hTcxDec->tcxltp_last_gain_unmodified; move16(); } } @@ -1931,6 +1955,7 @@ static Word32 CalculateAbsEnergy_fx( /* o : normalized resul #endif /* Clear carry flag and init sum */ Carry = 0; + move16(); L_c = 0; move32(); #ifdef BASOP_NOGLOB /* Critical Overflow/Carry */ @@ -1982,6 +2007,7 @@ void IMDCT_fx( Word32 *x, Word16 x_e, Word16 *old_syn_overl, Word16 *syn_Overl_T Word16 i; Word16 nz; Word16 aldo = 0; + move16(); TCX_DEC_HANDLE hTcxDec; hTcxDec = st->hTcxDec; @@ -2199,7 +2225,7 @@ void IMDCT_fx( Word32 *x, Word16 x_e, Word16 *old_syn_overl, Word16 *syn_Overl_T /* extra folding-out on left side of win, for perfect reconstruction */ FOR( w = shr( overlap, 1 ); w < overlap; w++ ) { - xn_buf[overlap - 1 - w] = negate( xn_buf[w] ); + xn_buf[sub( sub( overlap, 1 ), w )] = negate( xn_buf[w] ); move16(); } @@ -2383,7 +2409,7 @@ void IMDCT_fx( Word32 *x, Word16 x_e, Word16 *old_syn_overl, Word16 *syn_Overl_T /* Window and overlap-add past frame if past frame is TCX */ test(); - IF( ( frame_cnt != 0 ) || ( st->last_core_bfi > ACELP_CORE ) ) + IF( ( frame_cnt != 0 ) || ( GT_16( st->last_core_bfi, ACELP_CORE ) ) ) { test(); test(); @@ -2394,7 +2420,7 @@ void IMDCT_fx( Word32 *x, Word16 x_e, Word16 *old_syn_overl, Word16 *syn_Overl_T test(); test(); if ( ( bfi == 0 ) && ( frame_cnt > 0 ) && ( index == 0 ) && - ( tcx_cfg->tcx_curr_overlap_mode == FULL_OVERLAP ) && ( st->last_core != ACELP_CORE ) ) + ( EQ_16( tcx_cfg->tcx_curr_overlap_mode, FULL_OVERLAP ) ) && ( NE_16( st->last_core, ACELP_CORE ) ) ) { index = MIN_OVERLAP; /* use minimum overlap between the two TCX-10 windows */ move16(); @@ -2662,7 +2688,7 @@ void IMDCT_fx( Word32 *x, Word16 x_e, Word16 *old_syn_overl, Word16 *syn_Overl_T test(); test(); test(); - IF( left_rect && ( frame_cnt == 0 ) && ( st->last_core_bfi == ACELP_CORE ) && st->prev_bfi ) + IF( left_rect && ( frame_cnt == 0 ) && ( EQ_16( st->last_core_bfi, ACELP_CORE ) ) && st->prev_bfi ) { IF( fullbandScale ) @@ -2683,8 +2709,8 @@ void IMDCT_fx( Word32 *x, Word16 x_e, Word16 *old_syn_overl, Word16 *syn_Overl_T FOR( ; i < tcx_mdct_window_half_length; i++ ) { #ifdef BASOP_NOGLOB - xn_buf[i + tmp1] = mult_r_sat( xn_buf[i + tmp1], tcx_mdct_window_half[tcx_mdct_window_half_length - 1 - i].v.re ); - xn_buf[i + tmp1] = add_sat( xn_buf[i + tmp1], mult_r_sat( hTcxDec->syn_OverlFB[i], mult_r_sat( tcx_mdct_window_half[tcx_mdct_window_half_length - 1 - i].v.im, tcx_mdct_window_half[tcx_mdct_window_half_length - 1 - i].v.im ) ) ); + xn_buf[i + tmp1] = mult_r_sat( xn_buf[i + tmp1], tcx_mdct_window_half[sub( sub( tcx_mdct_window_half_length, 1 ), i )].v.re ); + xn_buf[i + tmp1] = add_sat( xn_buf[i + tmp1], mult_r_sat( hTcxDec->syn_OverlFB[i], mult_r_sat( tcx_mdct_window_half[sub( sub( tcx_mdct_window_half_length, 1 ), i )].v.im, tcx_mdct_window_half[sub( sub( tcx_mdct_window_half_length, 1 ), i )].v.im ) ) ); #else xn_buf[i + tmp1] = mult_r( xn_buf[i + tmp1], tcx_mdct_window_half[tcx_mdct_window_half_length - 1 - i].v.re ); xn_buf[i + tmp1] = add( xn_buf[i + tmp1], mult_r( hTcxDec->syn_OverlFB[i], mult_r( tcx_mdct_window_half[tcx_mdct_window_half_length - 1 - i].v.im, tcx_mdct_window_half[tcx_mdct_window_half_length - 1 - i].v.im ) ) ); @@ -2710,8 +2736,8 @@ void IMDCT_fx( Word32 *x, Word16 x_e, Word16 *old_syn_overl, Word16 *syn_Overl_T FOR( ; i < tcx_mdct_window_half_length; i++ ) { #ifdef BASOP_NOGLOB - xn_buf[i + tmp1] = mult_r_sat( xn_buf[i + tmp1], tcx_mdct_window_half[tcx_mdct_window_half_length - 1 - i].v.re ); - xn_buf[i + tmp1] = add_sat( xn_buf[i + tmp1], mult_r_sat( hTcxDec->syn_Overl[i], mult_r_sat( tcx_mdct_window_half[tcx_mdct_window_half_length - 1 - i].v.im, tcx_mdct_window_half[tcx_mdct_window_half_length - 1 - i].v.im ) ) ); + xn_buf[i + tmp1] = mult_r_sat( xn_buf[i + tmp1], tcx_mdct_window_half[sub( sub( tcx_mdct_window_half_length, 1 ), i )].v.re ); + xn_buf[i + tmp1] = add_sat( xn_buf[i + tmp1], mult_r_sat( hTcxDec->syn_Overl[i], mult_r_sat( tcx_mdct_window_half[sub( sub( tcx_mdct_window_half_length, 1 ), i )].v.im, tcx_mdct_window_half[sub( sub( tcx_mdct_window_half_length, 1 ), i )].v.im ) ) ); #else xn_buf[i + tmp1] = mult_r( xn_buf[i + tmp1], tcx_mdct_window_half[tcx_mdct_window_half_length - 1 - i].v.re ); xn_buf[i + tmp1] = add( xn_buf[i + tmp1], mult_r( hTcxDec->syn_Overl[i], mult_r( tcx_mdct_window_half[tcx_mdct_window_half_length - 1 - i].v.im, tcx_mdct_window_half[tcx_mdct_window_half_length - 1 - i].v.im ) ) ); @@ -2755,7 +2781,7 @@ void IMDCT_ivas_fx( Word16 *acelp_zir_fx, Word16 q_win ) // Q(-2) { - int16_t i, nz, aldo, w, L_win, L_ola; + Word16 i, nz, aldo, w, L_win, L_ola; Word16 win_fx[( L_FRAME_PLUS + L_MDCT_OVLP_MAX ) / 2]; TCX_DEC_HANDLE hTcxDec = st->hTcxDec; TCX_CONFIG_HANDLE hTcxCfg = st->hTcxCfg; @@ -2763,10 +2789,23 @@ void IMDCT_ivas_fx( x_e_hdrm = add( q_win, sub( Q16, q_x ) ); aldo = 0; + move16(); - nz = NS2SA( st->output_Fs, N_ZERO_MDCT_NS ) * L_frame / L_frameTCX; + Word32 c = L_mult0( NS2SA( st->output_Fs, N_ZERO_MDCT_NS ), L_frame ); + Word16 exp = 0; + move16(); + nz = BASOP_Util_Divide3216_Scale( c, L_frameTCX, &exp ); + exp = exp + ( 31 - 15 ); + nz = shr( nz, sub( 15, exp ) ); // Q0 - IF( NE_16( st->element_mode, EVS_MONO ) && EQ_16( frame_cnt, 0 ) && EQ_16( bfi, 0 ) && NE_16( st->prev_bfi, 0 ) && ( EQ_16( st->last_core_bfi, TCX_20_CORE ) || EQ_16( st->last_core_bfi, TCX_10_CORE ) ) && EQ_16( hTcxCfg->last_aldo, 0 ) ) + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( NE_16( st->element_mode, EVS_MONO ) && ( frame_cnt == 0 ) && ( bfi == 0 ) && ( st->prev_bfi != 0 ) && ( EQ_16( st->last_core_bfi, TCX_20_CORE ) || EQ_16( st->last_core_bfi, TCX_10_CORE ) ) && ( hTcxCfg->last_aldo == 0 ) ) { Word16 fac = shl( mult_r( hTcxDec->conceal_eof_gain, st->last_concealed_gain_syn_deemph ), 1 ); FOR( Word16 ind = 0; ind < overlap; ind++ ) @@ -2775,6 +2814,7 @@ void IMDCT_ivas_fx( } } + test(); IF( EQ_16( L_frameTCX, shr( hTcxDec->L_frameTCX, 1 ) ) && st->tcxonly ) { /* Mode decision in PLC @@ -2791,56 +2831,78 @@ void IMDCT_ivas_fx( 3 2 2x TCX-5 2x TCX-5 3 3 2x TCX-5 2x TCX-5 */ - - IF( ( EQ_16( bfi, 0 ) && NE_16( hTcxCfg->tcx_last_overlap_mode, FULL_OVERLAP ) ) || ( NE_16( bfi, 0 ) && NE_16( hTcxCfg->tcx_last_overlap_mode, FULL_OVERLAP ) && NE_16( hTcxCfg->tcx_curr_overlap_mode, FULL_OVERLAP ) ) ) + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( ( bfi == 0 ) && NE_16( hTcxCfg->tcx_last_overlap_mode, FULL_OVERLAP ) ) || ( ( bfi != 0 ) && NE_16( hTcxCfg->tcx_last_overlap_mode, FULL_OVERLAP ) && NE_16( hTcxCfg->tcx_curr_overlap_mode, FULL_OVERLAP ) ) ) { /* minimum or half overlap, two transforms, grouping into one window */ L_win = shr( L_frame, 1 ); - L_ola = EQ_16( hTcxCfg->tcx_last_overlap_mode, MIN_OVERLAP ) ? tcx_mdct_window_min_length : tcx_mdct_window_half_length; + // L_ola = EQ_16( hTcxCfg->tcx_last_overlap_mode, MIN_OVERLAP ) ? tcx_mdct_window_min_length : tcx_mdct_window_half_length; + IF( EQ_16( hTcxCfg->tcx_last_overlap_mode, MIN_OVERLAP ) ) + { + L_ola = tcx_mdct_window_min_length; + } + ELSE + { + L_ola = tcx_mdct_window_half_length; + } move16(); set16_fx( win_fx, 0, shr( add( L_FRAME_PLUS, L_MDCT_OVLP_MAX ), 1 ) ); - set16_fx( xn_buf_fx, 0, tcx_offset + ( L_ola >> 1 ) ); /* zero left end of buffer */ + Word16 tcx_offset_tmp = add( tcx_offset, shr( L_ola, 1 ) ); + set16_fx( xn_buf_fx, 0, tcx_offset_tmp ); /* zero left end of buffer */ + Word16 L_spec_TCX5_tmp = 0; + move16(); FOR( w = 0; w < 2; w++ ) { + test(); + test(); + L_spec_TCX5_tmp = imult1616( w, L_spec_TCX5 ); IF( EQ_16( kernel_type, MDST_IV ) || s_and( kernel_type, w ) ) { - TCX_MDST_Inverse_fx( x_fx + w * L_spec_TCX5, x_e_hdrm, win_fx, L_ola, L_win - L_ola, L_ola ); + TCX_MDST_Inverse_fx( x_fx + L_spec_TCX5_tmp, x_e_hdrm, win_fx, L_ola, sub( L_win, L_ola ), L_ola ); } - ELSE IF( NE_16( kernel_type, 0 ) && EQ_16( w, 0 ) ) /* type 1 or 2 */ + ELSE IF( ( kernel_type != 0 ) && ( w == 0 ) ) /* type 1 or 2 */ { - TCX_MDXT_Inverse_fx( x_fx + w * L_spec_TCX5, x_e_hdrm, win_fx, L_ola, L_win - L_ola, L_ola, kernel_type ); + TCX_MDXT_Inverse_fx( x_fx + L_spec_TCX5_tmp, x_e_hdrm, win_fx, L_ola, sub( L_win, L_ola ), L_ola, kernel_type ); } ELSE { - TCX_MDCT_Inverse( x_fx + w * L_spec_TCX5, x_e_hdrm, win_fx, L_ola, L_win - L_ola, L_ola, st->element_mode ); + 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 ); } 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 ); - IF( GT_16( w, 0 ) ) + IF( w > 0 ) { - tcx_windowing_synthesis_past_frame( xn_buf_fx + tcx_offset - shr( L_ola, 1 ) + w * L_win, tcx_aldo_window_1_trunc_fx, tcx_mdct_window_half_fx, tcx_mdct_window_minimum_fx, L_ola, tcx_mdct_window_half_length, tcx_mdct_window_min_length, MIN_OVERLAP ); + Word16 tmp = add( sub( tcx_offset, shr( L_ola, 1 ) ), imult1616( w, L_win ) ); + tcx_windowing_synthesis_past_frame( xn_buf_fx + tmp, tcx_aldo_window_1_trunc_fx, tcx_mdct_window_half_fx, tcx_mdct_window_minimum_fx, L_ola, tcx_mdct_window_half_length, tcx_mdct_window_min_length, MIN_OVERLAP ); } /* add part of current sub-window overlapping with previous window */ - v_add_16( win_fx, xn_buf_fx + add( sub( tcx_offset, shr( L_ola, 1 ) ), i_mult( w, L_win ) ), xn_buf_fx + add( sub( tcx_offset, shr( L_ola, 1 ) ), i_mult( w, L_win ) ), L_ola ); + v_add_16( win_fx, xn_buf_fx + add( sub( tcx_offset, shr( L_ola, 1 ) ), imult1616( w, L_win ) ), xn_buf_fx + add( sub( tcx_offset, shr( L_ola, 1 ) ), imult1616( w, L_win ) ), L_ola ); /* copy new sub-window region not overlapping with previous window */ - mvs2s( win_fx + L_ola, xn_buf_fx + add( tcx_offset, add( shr( L_ola, 1 ), i_mult( w, L_win ) ) ), L_win ); + mvs2s( win_fx + L_ola, xn_buf_fx + add( tcx_offset, add( shr( L_ola, 1 ), imult1616( w, L_win ) ) ), L_win ); } /* To assure that no garbage values are passed to overlap */ set16_fx( xn_buf_fx + add( L_frame, add( tcx_offset, shr( L_ola, 1 ) ) ), 0, sub( overlap, add( tcx_offset, shr( L_ola, 1 ) ) ) ); - - IF( NE_16( st->prev_bfi, 0 ) && EQ_16( frame_cnt, 0 ) && NE_16( st->last_core, st->last_core_bfi ) && EQ_16( st->last_core_bfi, ACELP_CORE ) ) + test(); + test(); + test(); + IF( ( st->prev_bfi != 0 ) && ( frame_cnt == 0 ) && NE_16( st->last_core, st->last_core_bfi ) && EQ_16( st->last_core_bfi, ACELP_CORE ) ) { tcx_windowing_synthesis_past_frame( old_syn_overl_fx, 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_last_overlap_mode ); v_add_16( xn_buf_fx, old_syn_overl_fx, xn_buf_fx, overlap ); } } - ELSE IF( EQ_16( bfi, 0 ) && EQ_16( frame_cnt, 0 ) && EQ_16( hTcxCfg->tcx_curr_overlap_mode, FULL_OVERLAP ) ) + ELSE IF( ( bfi == 0 ) && ( frame_cnt == 0 ) && EQ_16( hTcxCfg->tcx_curr_overlap_mode, FULL_OVERLAP ) ) { /* special overlap attempt, two transforms, grouping into one window */ L_win = shr( L_frame, 1 ); @@ -2879,7 +2941,7 @@ void IMDCT_ivas_fx( } 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, LT_16( tcx_offset, 0 ) ? -tcx_offset : 0, 1, /* st->last_mode_bfi */ 0, /* st->last_is_cng */ fullbandScale ); + /* 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 ); tcx_windowing_synthesis_past_frame( xn_buf_fx + shr( overlap, 1 ) + sub( L_win, shr( L_ola, 1 ) ), tcx_aldo_window_1_trunc_fx, tcx_mdct_window_half_fx, tcx_mdct_window_minimum_fx, L_ola, tcx_mdct_window_half_length, tcx_mdct_window_min_length, 2 ); @@ -2906,7 +2968,7 @@ void IMDCT_ivas_fx( move16(); } } - 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, 0, /* left_mode */ acelp_zir_fx, hTcxDec->old_syn_Overl, syn_Overl_TDAC_fx, st->old_Aq_12_8_fx, tcx_mdct_window_trans_fx, shl( L_win, 1 ), LT_16( tcx_offset, 0 ) ? -tcx_offset : 0, st->last_core_bfi, (Word8) st->last_is_cng, fullbandScale ); + 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, 0, /* left_mode */ acelp_zir_fx, hTcxDec->old_syn_Overl, syn_Overl_TDAC_fx, st->old_Aq_12_8_fx, tcx_mdct_window_trans_fx, shl( L_win, 1 ), ( tcx_offset < 0 ) ? -tcx_offset : 0, st->last_core_bfi, (Word8) st->last_is_cng, fullbandScale ); } ELSE { @@ -2924,33 +2986,36 @@ void IMDCT_ivas_fx( TCX_MDCT_Inverse( x_fx, x_e_hdrm, xn_buf_fx, overlap, sub( L_frame, overlap ), overlap, st->element_mode ); } - 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 && GT_16( frame_cnt, 0 ) && EQ_16( 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 ), LT_16( tcx_offset, 0 ) ? -tcx_offset : 0, GT_16( frame_cnt, 0 /*|| (st->last_con_tcx )*/ ) ? 1 : st->last_core_bfi, GT_16( frame_cnt, 0 ) ? 0 : (Word8) st->last_is_cng, fullbandScale ); + 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 */ } ELSE { /* frame is TCX-20 or not TCX-only */ - assert( EQ_16( frame_cnt, 0 ) ); + assert( frame_cnt == 0 ); IF( NE_16( hTcxCfg->tcx_last_overlap_mode, TRANSITION_OVERLAP ) ) { Word16 q_tmp_fx_32 = 15, q_xn_buf_fx_32 = q_x; + move16(); + move16(); Word32 xn_buf_fx_32[2000] = { 0 }, tmp_fx_32[1200], old_out_fx_32[1200]; IF( NE_16( kernel_type, MDCT_IV ) ) /* inverse transform */ { - + Word16 tmp_a = add( shr( overlap, 1 ), nz ); IF( EQ_16( kernel_type, MDST_IV ) ) { - edst_fx( x_fx, xn_buf_fx_32 + overlap / 2 + nz, L_frame, &q_xn_buf_fx_32 ); + edst_fx( x_fx, xn_buf_fx_32 + tmp_a, L_frame, &q_xn_buf_fx_32 ); } ELSE /* type 1 or 2 */ { - edxt_fx( x_fx, xn_buf_fx_32 + overlap / 2 + nz, L_frame, kernel_type, TRUE ); + edxt_fx( x_fx, xn_buf_fx_32 + tmp_a, L_frame, kernel_type, TRUE ); } Word16 res_m, res_e = 0; + move16(); res_m = BASOP_Util_Divide1616_Scale( L_frame, NORM_MDCT_FACTOR, &res_e ); res_m = Sqrt16( res_m, &res_e ); @@ -2972,13 +3037,15 @@ void IMDCT_ivas_fx( { old_out_fx[ind] = (Word16) L_shr( old_out_fx_32[ind], sub( q_tmp_fx_32, q_win ) ); xn_buf_fx[ind] = (Word16) L_shr( xn_buf_fx_32[ind], sub( q_tmp_fx_32, q_win ) ); + move16(); + move16(); } } ELSE { Word16 q_old_out = q_win; move16(); - edct_fx( x_fx, xn_buf_fx_32 + overlap / 2 + nz, L_frame, &q_xn_buf_fx_32 ); + 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 = 0; move16(); res_m = BASOP_Util_Divide1616_Scale( L_frame, NORM_MDCT_FACTOR, &res_e ); @@ -2987,6 +3054,7 @@ void IMDCT_ivas_fx( FOR( Word16 ind = 0; ind < L_frame; ind++ ) { tmp_fx_32[ind] = Mpy_32_16_1( xn_buf_fx_32[shr( overlap, 1 ) + nz + ind], res_m ); + move32(); } 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 ); @@ -2994,6 +3062,7 @@ void IMDCT_ivas_fx( FOR( Word16 ind = 0; ind < L_frame; ind++ ) { xn_buf_fx[add( add( ind, shr( overlap, 1 ) ), nz )] = (Word16) L_shr( xn_buf_fx_32[add( add( ind, shr( overlap, 1 ) ), nz )], sub( q_xn_buf_fx_32, q_win ) ); + move16(); } 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 ); @@ -3001,7 +3070,9 @@ void IMDCT_ivas_fx( FOR( Word16 ind = 0; ind < L_frame; ind++ ) { old_out_fx[ind] = shr_sat( old_out_fx[ind], sub( q_old_out, q_win ) ); + move16(); xn_buf_fx[ind] = shr_sat( xn_buf_fx[ind], sub( q_tmp_fx_32, q_win ) ); + move16(); } } aldo = 1; @@ -3009,14 +3080,24 @@ void IMDCT_ivas_fx( } ELSE { - Word16 acelp_mem_len = tcx_offset < 0 ? -tcx_offset : 0; + // Word16 acelp_mem_len = tcx_offset < 0 ? -tcx_offset : 0; + Word16 acelp_mem_len; + + IF( tcx_offset < 0 ) + { + acelp_mem_len = -tcx_offset; + } + ELSE + { + acelp_mem_len = 0; + } move16(); IF( EQ_16( kernel_type, MDST_IV ) ) { TCX_MDST_Inverse_fx( x_fx, x_e_hdrm, xn_buf_fx, overlap, L_frame - overlap, overlap ); } - ELSE IF( kernel_type != MDCT_IV ) /* type 1 or 2 */ + ELSE IF( NE_16( kernel_type, MDCT_IV ) ) /* type 1 or 2 */ { TCX_MDXT_Inverse_fx( x_fx, x_e_hdrm, xn_buf_fx, overlap, L_frame - overlap, overlap, kernel_type ); } @@ -3028,11 +3109,13 @@ void IMDCT_ivas_fx( /*-----------------------------------------------------------* * Windowing, overlap and add * *-----------------------------------------------------------*/ - - IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && ( LE_32( st->last_core_brate, SID_2k40 ) || EQ_16( st->last_core, ACELP_CORE ) ) && EQ_16( fullbandScale, 0 ) ) + test(); + test(); + test(); + IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && ( LE_32( st->last_core_brate, SID_2k40 ) || EQ_16( st->last_core, ACELP_CORE ) ) && ( fullbandScale == 0 ) ) { /* get LPC from that signal part to use for acelp zir smoothing */ - const Word16 analysis_len = L_frame_glob / 4; + const Word16 analysis_len = shr( L_frame_glob, 2 ); Word16 buf_fx[L_FRAME_MAX / 4]; Word16 window_buf_fx[L_FRAME_MAX / 4]; Word32 r_fx[M + 1]; @@ -3046,7 +3129,7 @@ void IMDCT_ivas_fx( // q_old_Aq_12_8 = 28; move16(); - ham_cos_window_ivas( &window_buf_fx[0], analysis_len / 2, analysis_len / 2 ); + ham_cos_window_ivas( &window_buf_fx[0], shr( analysis_len, 1 ), shr( analysis_len, 1 ) ); autocorr_fx_32( &buf_fx[0], M, &r_fx[0], &q_r, analysis_len, &window_buf_fx[0], 0, 0 ); lag_wind_32( r_fx, M, L_frame_glob * FRAMES_PER_SEC, LAGW_STRONG ); lev_dur_fx( &st->old_Aq_12_8_fx_32[0], &r_fx[0], M, NULL, 28 /*Q(st->q_old_Aq_12_8_fx_32)*/, add( add( shl( q_buf, 1 ), q_r ), 1 ) ); @@ -3060,40 +3143,53 @@ void IMDCT_ivas_fx( 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 ); } } /* TCX-20 and TCX-only */ - - IF( NE_16( frame_cnt, 0 ) || GT_16( st->last_core_bfi, ACELP_CORE ) ) + test(); + IF( ( frame_cnt != 0 ) || GT_16( st->last_core_bfi, ACELP_CORE ) ) { - IF( ( EQ_16( L_frameTCX, shr( hTcxDec->L_frameTCX, 1 ) ) && NE_16( st->tcxonly, 0 ) ) || + test(); + test(); + IF( ( EQ_16( L_frameTCX, shr( hTcxDec->L_frameTCX, 1 ) ) && ( st->tcxonly != 0 ) ) || EQ_16( hTcxCfg->tcx_last_overlap_mode, TRANSITION_OVERLAP ) ) { - IF( EQ_16( bfi, 0 ) && GT_16( frame_cnt, 0 ) && EQ_16( index, 0 ) && EQ_16( hTcxCfg->tcx_curr_overlap_mode, FULL_OVERLAP ) && NE_16( st->last_core, ACELP_CORE ) ) + test(); + test(); + test(); + test(); + if ( ( bfi == 0 ) && ( frame_cnt > 0 ) && ( index == 0 ) && EQ_16( hTcxCfg->tcx_curr_overlap_mode, FULL_OVERLAP ) && NE_16( st->last_core, ACELP_CORE ) ) { index = MIN_OVERLAP; /* use minimum overlap between the two TCX-10 windows */ move16(); } - IF( NE_16( hTcxCfg->last_aldo, 0 ) ) + IF( hTcxCfg->last_aldo != 0 ) { FOR( i = 0; i < sub( overlap, tcx_mdct_window_min_length ); i++ ) { xn_buf_fx[add( i, sub( shr( overlap, 1 ), tcx_offset ) )] = add( xn_buf_fx[add( i, sub( shr( overlap, 1 ), tcx_offset ) )], old_out_fx[add( i, nz )] ); + move16(); } /* fade truncated ALDO window */ - IF( EQ_16( L_frameTCX, shr( hTcxDec->L_frameTCX, 1 ) ) && EQ_16( st->element_mode, IVAS_CPE_MDCT ) && EQ_16( frame_cnt, 0 ) && EQ_16( hTcxCfg->tcx_last_overlap_mode, FULL_OVERLAP ) ) + test(); + test(); + test(); + IF( EQ_16( L_frameTCX, shr( hTcxDec->L_frameTCX, 1 ) ) && EQ_16( st->element_mode, IVAS_CPE_MDCT ) && ( frame_cnt == 0 ) && EQ_16( hTcxCfg->tcx_last_overlap_mode, FULL_OVERLAP ) ) { // tested FOR( ; i < overlap; i++ ) /* perfectly reconstructing ALDO shortening */ { xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )] = add( xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )], old_out_fx[add( i, nz )] ); + move16(); } FOR( i = 0; i < shr( tcx_mdct_window_min_length, 1 ); i++ ) { xn_buf_fx[add( sub( add( i, shr( overlap, 1 ) ), tcx_offset ), overlap )] = add( xn_buf_fx[add( sub( add( i, shr( overlap, 1 ) ), tcx_offset ), overlap )], mult_r( old_out_fx[add( add( i, nz ), overlap )], tcx_mdct_window_minimum_fx[i].v.re ) ); + move16(); } FOR( ; i < tcx_mdct_window_min_length; i++ ) { xn_buf_fx[add( sub( add( i, shr( overlap, 1 ) ), tcx_offset ), overlap )] = add( xn_buf_fx[add( sub( add( i, shr( overlap, 1 ) ), tcx_offset ), overlap )], mult_r( old_out_fx[add( add( i, nz ), overlap )], tcx_mdct_window_minimum_fx[sub( tcx_mdct_window_min_length, add( 1, i ) )].v.im ) ); + move16(); } } ELSE @@ -3101,47 +3197,55 @@ void IMDCT_ivas_fx( FOR( ; i < sub( overlap, shr( tcx_mdct_window_min_length, 1 ) ); i++ ) { xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )] = add( xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )], mult_r( old_out_fx[add( i, nz )], tcx_mdct_window_minimum_fx[add( sub( tcx_mdct_window_min_length, overlap ), i )].v.re ) ); + move16(); } FOR( ; i < overlap; i++ ) { xn_buf_fx[add( i, sub( shr( overlap, 1 ), tcx_offset ) )] = add( xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )], mult_r( old_out_fx[add( i, nz )], tcx_mdct_window_minimum_fx[sub( overlap, add( 1, i ) )].v.im ) ); + move16(); } } } ELSE { - tcx_windowing_synthesis_past_frame( old_syn_overl_fx, 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, ( EQ_16( index, 0 ) || EQ_16( hTcxCfg->tcx_last_overlap_mode, MIN_OVERLAP ) ) ? hTcxCfg->tcx_last_overlap_mode : index ); + tcx_windowing_synthesis_past_frame( old_syn_overl_fx, 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, ( ( index == 0 ) || EQ_16( hTcxCfg->tcx_last_overlap_mode, MIN_OVERLAP ) ) ? hTcxCfg->tcx_last_overlap_mode : index ); - IF( NE_16( bfi, 0 ) ) + IF( bfi != 0 ) { FOR( i = 0; i < shr( tcx_mdct_window_half_length, 1 ); i++ ) { xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )] = add( xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )], mult_r( old_syn_overl_fx[i], tcx_mdct_window_half_fx[i].v.re ) ); + move16(); } FOR( ; i < tcx_mdct_window_half_length; i++ ) { xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )] = add( xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )], mult_r( old_syn_overl_fx[i], tcx_mdct_window_half_fx[sub( tcx_mdct_window_half_length, add( 1, i ) )].v.im ) ); + move16(); } } - ELSE IF( EQ_16( left_rect, 0 ) ) + ELSE IF( left_rect == 0 ) { FOR( i = 0; i < overlap; i++ ) { xn_buf_fx[i] = add( xn_buf_fx[i], old_syn_overl_fx[i] ); + move16(); } } ELSE { FOR( i = 0; i < overlap; i++ ) { - xn_buf_fx[i + shr( overlap, 1 )] = add( xn_buf_fx[i + shr( overlap, 1 )], old_syn_overl_fx[i] ); + xn_buf_fx[add( i, shr( overlap, 1 ) )] = add( xn_buf_fx[add( i, shr( overlap, 1 ) )], old_syn_overl_fx[i] ); + move16(); } } } } } - - IF( EQ_16( aldo, 0 ) && ( ( EQ_16( L_frameTCX, shr( hTcxDec->L_frameTCX, 1 ) ) && GT_16( frame_cnt, 0 ) ) || NE_16( L_frameTCX, shr( hTcxDec->L_frameTCX, 1 ) ) ) ) + test(); + test(); + test(); + IF( ( aldo == 0 ) && ( ( EQ_16( L_frameTCX, shr( hTcxDec->L_frameTCX, 1 ) ) && ( frame_cnt > 0 ) ) || NE_16( L_frameTCX, shr( hTcxDec->L_frameTCX, 1 ) ) ) ) { /* Compute windowed synthesis in case of switching to ALDO windows in next frame */ mvs2s( xn_buf_fx + sub( L_frame, nz ), old_out_fx, add( nz, overlap ) ); @@ -3158,6 +3262,7 @@ void IMDCT_ivas_fx( FOR( i = 0; i < nz; i++ ) { old_out_fx[add( add( nz, overlap ), i )] = negate( mult_r( xn_buf_fx[sub( L_frame, add( 1, i ) )], tcx_aldo_window_1_fx[sub( nz, add( 1, i ) )] ) ); + move16(); } } ELSE @@ -3165,6 +3270,7 @@ void IMDCT_ivas_fx( FOR( i = 0; i < nz; i++ ) { old_out_fx[add( add( nz, overlap ), i )] = mult_r( xn_buf_fx[sub( L_frame, add( 1, i ) )], tcx_aldo_window_1_fx[sub( nz, add( 1, i ) )] ); + move16(); } } aldo = 1; @@ -3172,26 +3278,33 @@ void IMDCT_ivas_fx( } } - IF( NE_16( FB_flag, 0 ) ) + if ( FB_flag != 0 ) { hTcxCfg->last_aldo = aldo; move16(); } /* Smoothing between the ACELP PLC and TCX Transition frame. Using the shape of the half overlap window for the crossfading. */ - IF( NE_16( left_rect, 0 ) && EQ_16( frame_cnt, 0 ) && EQ_16( st->last_core_bfi, ACELP_CORE ) && NE_16( st->prev_bfi, 0 ) ) + test(); + test(); + test(); + IF( ( left_rect != 0 ) && ( frame_cnt == 0 ) && EQ_16( st->last_core_bfi, ACELP_CORE ) && ( st->prev_bfi != 0 ) ) { - IF( NE_16( FB_flag, 0 ) ) + IF( FB_flag != 0 ) { FOR( i = 0; i < shr( tcx_mdct_window_half_length, 1 ); i++ ) { xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )] = mult_r( xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )], tcx_mdct_window_half_fx[i].v.im ); xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )] = add( xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )], mult_r( mult_r( hTcxDec->syn_OverlFB[i], tcx_mdct_window_half_fx[i].v.re ), tcx_mdct_window_half_fx[i].v.re ) ); + move16(); + move16(); } FOR( ; i < tcx_mdct_window_half_length; i++ ) { xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )] = mult_r( xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )], tcx_mdct_window_half_fx[sub( tcx_mdct_window_half_length, add( 1, i ) )].v.re ); xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )] = add( xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )], mult_r( mult_r( hTcxDec->syn_OverlFB[i], tcx_mdct_window_half_fx[sub( tcx_mdct_window_half_length, add( 1, i ) )].v.im ), tcx_mdct_window_half_fx[sub( tcx_mdct_window_half_length, add( 1, i ) )].v.im ) ); + move16(); + move16(); } } ELSE @@ -3200,11 +3313,15 @@ void IMDCT_ivas_fx( { xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )] = mult_r( xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )], tcx_mdct_window_half_fx[i].v.im ); xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )] = add( xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )], mult_r( mult_r( hTcxDec->syn_Overl[i], tcx_mdct_window_half_fx[i].v.re ), tcx_mdct_window_half_fx[i].v.re ) ); + move16(); + move16(); } FOR( ; i < tcx_mdct_window_half_length; i++ ) { xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )] = mult_r( xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )], tcx_mdct_window_half_fx[sub( tcx_mdct_window_half_length, add( 1, i ) )].v.re ); xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )] = add( xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )], mult_r( mult_r( hTcxDec->syn_Overl[i], tcx_mdct_window_half_fx[sub( tcx_mdct_window_half_length, add( 1, i ) )].v.im ), tcx_mdct_window_half_fx[sub( tcx_mdct_window_half_length, add( 1, i ) )].v.im ) ); + move16(); + move16(); } } } @@ -3260,9 +3377,9 @@ void init_tcx_info_fx( ELSE { test(); - IF( frame_cnt == 0 && st->last_core == ACELP_CORE ) + IF( frame_cnt == 0 && EQ_16( st->last_core, ACELP_CORE ) ) { - IF( !st->prev_bfi ) + if ( !st->prev_bfi ) { hTcxCfg->last_aldo = 0; move16(); @@ -3271,7 +3388,7 @@ void init_tcx_info_fx( /* if past frame is ACELP */ *L_frame = add( L_frame_glob, *tcx_offset ); *L_frameTCX = add( L_frameTCX_glob, *tcx_offsetFB ); - IF( EQ_16( st->last_core, st->last_core_from_bs ) ) + if ( EQ_16( st->last_core, st->last_core_from_bs ) ) { /* case: last frame was lost and concealed as CNG */ /* using the longer transition spec length causes reading of uninitialized data */ @@ -3374,6 +3491,7 @@ void decoder_tcx_IGF_mono_fx( test(); IF( NE_16( L_frame, shr( st->L_frame, 1 ) ) && st->tcxonly ) { + test(); IF( EQ_16( st->last_core, ACELP_CORE ) || ( left_rect && bfi ) ) { igfGridIdx = IGF_GRID_LB_TRAN; @@ -3434,7 +3552,7 @@ void decoder_tcx_IGF_stereo_fx( sfbConf = &hStereoMdct->stbParamsTCX10; } - IF( EQ_16( sts[0]->last_core, ACELP_CORE ) ) + if ( EQ_16( sts[0]->last_core, ACELP_CORE ) ) { sfbConf = &hStereoMdct->stbParamsTCX20afterACELP; } @@ -3447,6 +3565,7 @@ void decoder_tcx_IGF_stereo_fx( set16_fx( &coreMsMask[sfbConf->sfbOffset[sfb]], ms_mask[k][sfb], sfbConf->sfbOffset[sfb + 1] - sfbConf->sfbOffset[sfb] ); } + test(); IF( EQ_16( L_frame, shr( sts[0]->L_frame, 1 ) ) && ( sts[0]->tcxonly ) ) { igfGridIdx = IGF_GRID_LB_SHORT; @@ -3454,6 +3573,7 @@ void decoder_tcx_IGF_stereo_fx( } ELSE { + test(); IF( EQ_16( sts[0]->last_core, ACELP_CORE ) || left_rect ) { igfGridIdx = IGF_GRID_LB_TRAN; @@ -3467,7 +3587,7 @@ void decoder_tcx_IGF_stereo_fx( } IGFDecUpdateInfo_ivas_fx( sts[0]->hIGFDec, k, igfGridIdx ); - + test(); IF( EQ_16( L_frame, shr( sts[1]->L_frame, 1 ) ) && ( sts[1]->tcxonly ) ) { igfGridIdx = IGF_GRID_LB_SHORT; @@ -3475,6 +3595,7 @@ void decoder_tcx_IGF_stereo_fx( } ELSE { + test(); IF( EQ_16( sts[1]->last_core, ACELP_CORE ) || left_rect ) { igfGridIdx = IGF_GRID_LB_TRAN; @@ -3496,6 +3617,8 @@ void decoder_tcx_IGF_stereo_fx( test(); IF( NE_16( L_frame, shr( sts[0]->L_frame, 1 ) ) && ( sts[0]->tcxonly ) ) { + test(); + test(); IF( EQ_16( sts[0]->last_core, ACELP_CORE ) || ( left_rect && bfi ) ) { igfGridIdx = IGF_GRID_LB_TRAN; @@ -3542,9 +3665,12 @@ void decoder_tcx_ivas_fx( { Word32 x_fx[N_MAX]; Word16 x_e = 30; + move16(); Word16 gainlpc2_fx[FDNS_NPTS]; Word16 gainlpc2_e[FDNS_NPTS]; Word16 gain_tcx_e = 0, gain_tcx_fx = 0; + move16(); + move16(); Word16 fUseTns, L_frame_glob, L_frameTCX_glob; STnsData tnsData; Word16 tcx_offset, tcx_offsetFB, L_frame, L_frameTCX; @@ -3554,14 +3680,18 @@ void decoder_tcx_ivas_fx( Word16 shift; Word16 x_len; Word16 q_x = Q11; + move16(); set32_fx( x_fx, 0, N_MAX ); set16_fx( gainlpc2_fx, 0, FDNS_NPTS ); set16_fx( gainlpc2_e, 0, FDNS_NPTS ); L_spec = st->hTcxCfg->tcx_coded_lines; + move16(); L_frame_glob = st->L_frame; + move16(); L_frameTCX_glob = st->hTcxDec->L_frameTCX; + move16(); IF( EQ_16( st->core, TCX_10_CORE ) ) { L_spec = shr( L_spec, 1 ); @@ -3570,8 +3700,11 @@ void decoder_tcx_ivas_fx( } tmp_concealment_method = 0; + move16(); nf_seed = 0; + move16(); fUseTns = 0; /* flag that is set if TNS data is present */ + move16(); set16_fx( xn_buf_fx, 0, L_MDCT_OVLP_MAX + L_FRAME_PLUS + L_MDCT_OVLP_MAX ); @@ -3597,21 +3730,22 @@ 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 ); - 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, 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 ); move16(); - IF( NE_16( st->igf, 0 ) ) + IF( st->igf != 0 ) { - Scale_sig32( st->hIGFDec->virtualSpec, ( N_MAX_TCX - IGF_START_MN ), ( st->hIGFDec->virtualSpec_e - x_e ) ); + 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(); } /* Scaling down buffers for decoder_tcx_imdct_fx*/ Scale_sig( st->hTcxDec->syn_Overl, 320, -1 ); // Scaling to Q_syn Scale_sig( st->hTcxDec->old_syn_Overl, 320, 1 ); // Scaling to Q_syn - Copy_Scale_sig_16_32_no_sat( st->old_Aq_12_8_fx, st->old_Aq_12_8_fx_32, M + 1, ( 28 - ( 15 - norm_s( st->old_Aq_12_8_fx[0] - 1 ) ) ) ); + 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 ) ) ) ) ) ) ); 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 @@ -3623,8 +3757,8 @@ 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 ); - Scale_sig( st->hHQ_core->old_out_LB_fx, L_FRAME32k, ( st->hHQ_core->Q_old_wtda - st->Q_syn ) ); - Scale_sig( st->hHQ_core->old_out_fx, L_FRAME48k, ( 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 ) ) ); + Scale_sig( st->hHQ_core->old_out_fx, L_FRAME48k, ( sub( st->hHQ_core->Q_old_wtda, st->Q_syn ) ) ); Scale_sig( st->hTcxDec->old_syn_Overl, 320, ( -2 + st->Q_syn ) ); // Scaling to Q-2 } #endif @@ -3668,6 +3802,8 @@ void decoder_tcx_invQ_fx( Word16 gamma; /* Q15 */ Word16 mem[M]; Word16 gainCompensate = 0, gainCompensate_e = 0; + move16(); + move16(); Word16 h1[L_SUBFR + 1]; Word16 tmp1, tmp2; Word32 tmp32; @@ -3684,6 +3820,7 @@ void decoder_tcx_invQ_fx( #endif tnsSize = 0; + move16(); prm_target = NULL; /* just to suppress MSVC warnigs */ /*-----------------------------------------------------------------* @@ -3694,7 +3831,7 @@ void decoder_tcx_invQ_fx( gamma1 = st->gamma; move16(); - IF( hTcxDec->enableTcxLpc != 0 ) + if ( hTcxDec->enableTcxLpc != 0 ) { gamma1 = MAX16B; move16(); @@ -3702,7 +3839,7 @@ void decoder_tcx_invQ_fx( noiseFillingSize = L_spec; move16(); - IF( st->igf != 0 ) + if ( st->igf != 0 ) { noiseFillingSize = st->hIGFDec->infoIGFStartLine; move16(); @@ -3736,6 +3873,7 @@ void decoder_tcx_invQ_fx( } /* read TNS data */ + test(); IF( !bfi && hTcxCfg->fIsTNSAllowed ) { *fUseTns = DecodeTnsData_ivas_fx( hTcxCfg->pCurrentTnsConfig, prm_tns, &tnsSize, tnsData ); @@ -3763,7 +3901,8 @@ void decoder_tcx_invQ_fx( /*-----------------------------------------------------------* * Context HM * *-----------------------------------------------------------*/ - + test(); + test(); IF( hTcxCfg->ctx_hm && ( ( st->last_core_from_bs != ACELP_CORE ) || ( frame_cnt > 0 ) ) ) { st->last_ctx_hm_enabled = prm_hm[0]; @@ -3772,7 +3911,7 @@ void decoder_tcx_invQ_fx( FOR( i = 0; i < L_spec; i++ ) { /* no context harmonic model, copy MDCT coefficients to x */ - x[i] = L_mult( prm_sqQ[i], 1 << ( 30 - SPEC_EXP_DEC ) ); + x[i] = L_mult( prm_sqQ[i], shl( 1, sub( 30, SPEC_EXP_DEC ) ) ); move32(); } *x_e = SPEC_EXP_DEC; @@ -3787,7 +3926,7 @@ void decoder_tcx_invQ_fx( prm_sqQ = prm_target + 1; move16(); - tcx_arith_decode_envelope_ivas_fx( st, x, x_e, L_frame, L_spec, Aind, *prm_target, prm_sqQ, st->last_core_from_bs != ACELP_CORE, prm_hm, /* HM parameter area */ hTcxDec->tcx_hm_LtpPitchLag, &arith_bits, &signaling_bits, ( st->bwidth > WB ) ? 1 : 0 ); + tcx_arith_decode_envelope_ivas_fx( st, x, x_e, L_frame, L_spec, Aind, *prm_target, prm_sqQ, (Word16) NE_16( st->last_core_from_bs, ACELP_CORE ), prm_hm, /* HM parameter area */ hTcxDec->tcx_hm_LtpPitchLag, &arith_bits, &signaling_bits, ( st->bwidth > WB ) ? 1 : 0 ); hTcxDec->resQBits[frame_cnt] = *prm_target - arith_bits; move16(); @@ -3795,7 +3934,7 @@ void decoder_tcx_invQ_fx( /* Noise filling seed */ FOR( i = 0; i < noiseFillingSize; ++i ) { - tmp32 = L_shr( x[i], 31 - *x_e ); + tmp32 = L_shr( x[i], sub( 31, *x_e ) ); #ifdef BASOP_NOGLOB *nf_seed = add_o( *nf_seed, (Word16) abs( tmp32 ) * i * 2, &Overflow ); #else @@ -3807,7 +3946,7 @@ void decoder_tcx_invQ_fx( { FOR( i = 0; i < L_spec; i++ ) { - x[i] = L_mult( prm_sqQ[i], 1 << ( 30 - SPEC_EXP_DEC ) ); + x[i] = L_mult( prm_sqQ[i], shl( 1, sub( 30, SPEC_EXP_DEC ) ) ); move32(); } @@ -3819,41 +3958,57 @@ void decoder_tcx_invQ_fx( } /* else of if hTcxCfg->ctx_hm */ - start_zeroing = ( st->last_core != st->last_core_from_bs ) ? min( L_spec, L_frame ) : L_spec; - - IF( frame_cnt == 0 && st->last_core == ACELP_CORE && st->last_core_from_bs != ACELP_CORE ) + // start_zeroing = ( st->last_core != st->last_core_from_bs ) ? min( L_spec, L_frame ) : L_spec; + IF( NE_16( st->last_core, st->last_core_from_bs ) ) + { + start_zeroing = min( L_spec, L_frame ); + } + ELSE + { + start_zeroing = L_spec; + } + move16(); + test(); + test(); + IF( frame_cnt == 0 && EQ_16( st->last_core, ACELP_CORE ) && NE_16( st->last_core_from_bs, ACELP_CORE ) ) { - Word16 L_spec_con = L_spec + ( st->hTcxCfg->tcx_coded_lines >> 2 ); + Word16 L_spec_con = L_spec + ( shr( st->hTcxCfg->tcx_coded_lines, 2 ) ); FOR( i = start_zeroing; i < L_spec_con; i++ ) { x[i] = 0; + move32(); } start_zeroing = L_spec_con; + move16(); } FOR( i = start_zeroing; i < max( L_frame, L_frameTCX ); i++ ) { x[i] = 0; + move32(); } /*-----------------------------------------------------------* * adaptive low frequency deemphasis. * *-----------------------------------------------------------*/ - IF( st->element_mode != IVAS_CPE_MDCT ) + IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { weight_a_fx( A, Ap, gamma1, M ); lpc2mdct_2( Ap, M, NULL, NULL, gainlpc2, gainlpc2_e, FDNS_NPTS ); } /* initialize LF deemphasis factors in xn_buf */ + test(); + test(); IF( !st->tcxonly || ( hTcxCfg->resq && hTcxDec->tcx_lpc_shaped_ari ) ) { FOR( i = 0; i < max( L_spec, L_frameTCX ); i++ ) { xn_buf[i] = ONE_IN_Q14; + move16(); } } IF( !st->tcxonly ) @@ -3863,6 +4018,7 @@ void decoder_tcx_invQ_fx( } hTcxDec->damping = 0; + move16(); IF( bfi == 0 ) { @@ -3880,10 +4036,12 @@ void decoder_tcx_invQ_fx( tmp1 = mult_r( shl( L_spec, 5 ), 26214 /*128.f/NORM_MDCT_FACTOR Q15*/ ); #endif s = 15 - 5 - 7; + move16(); IF( GE_16( L_spec, 1024 ) ) /*reduce precision for avoiding overflow*/ { tmp1 = mult_r( shl( L_spec, 4 ), 26214 /*128.f/NORM_MDCT_FACTOR Q15*/ ); s = 15 - 4 - 7; + move16(); } tmp1 = ISqrt16( tmp1, &s ); @@ -3912,6 +4070,7 @@ void decoder_tcx_invQ_fx( tmp1 = mult_r( shl( L_spec, 5 ), 26214 /*128.f/NORM_MDCT_FACTOR Q15*/ ); s = 15 - 5 - 7; + move16(); tmp1 = ISqrt16( tmp1, &s ); *gain_tcx = mult( *gain_tcx, tmp1 ); @@ -3931,6 +4090,7 @@ void decoder_tcx_invQ_fx( } hTcxDec->damping = ONE_IN_Q14; + move16(); } ELSE { @@ -3994,9 +4154,10 @@ void decoder_tcx_invQ_fx( } /* impulse response level = gain introduced by synthesis+deemphasis */ + test(); IF( !bfi ) { - IF( st->element_mode == IVAS_CPE_MDCT ) + IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) { st->last_gain_syn_deemph = 0; move16(); @@ -4028,7 +4189,7 @@ void decoder_tcx_invQ_fx( /* not instrumenting the additional test() here seems to be common practice */ ELSE IF( EQ_16( TCX_20_CORE, st->core ) || EQ_16( frame_cnt, 1 ) ) { - IF( st->element_mode == IVAS_CPE_MDCT ) + IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) { gainCompensate = ONE_IN_Q14; move16(); @@ -4087,7 +4248,7 @@ void decoder_tcx_invQ_fx( /*-----------------------------------------------------------* * Residual inv. Q. * *-----------------------------------------------------------*/ - + test(); IF( !bfi && hTcxCfg->resq ) { IF( hTcxDec->tcx_lpc_shaped_ari ) @@ -4115,30 +4276,34 @@ void decoder_tcx_invQ_fx( } } - + test(); + test(); IF( !bfi && st->tcxonly && st->element_mode != IVAS_CPE_MDCT ) { - IF( hTcxLtpDec->tcxltp && GT_16( hTcxLtpDec->tcxltp_gain, 0 ) && !( *fUseTns ) ) + test(); + test(); + IF( hTcxLtpDec->tcxltp && ( hTcxLtpDec->tcxltp_gain > 0 ) && !( *fUseTns ) ) { PsychAdaptLowFreqDeemph( x, gainlpc2, gainlpc2_e, NULL ); } } - + test(); IF( !bfi && !st->tcxonly ) { /* Replication of ACELP formant enhancement for low rates */ - IF( st->total_brate < ACELP_13k20 ) + IF( LT_32( st->total_brate, ACELP_13k20 ) ) { - IF( st->element_mode == IVAS_CPE_MDCT ) + IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) { assert( !"Not adapted to warped scale" ); } Word16 xn_buf_e; tcxFormantEnhancement_with_shift( xn_buf, &xn_buf_e, gainlpc2, gainlpc2_e, x, x_e, L_frame, L_frameTCX ); - for ( i = 0; i < FDNS_NPTS; i++ ) + FOR( i = 0; i < FDNS_NPTS; i++ ) { xn_buf[i] = shl( xn_buf[i], xn_buf_e - 1 ); + move16(); } } } @@ -4152,7 +4317,7 @@ void decoder_tcx_invQ_fx( *gain_tcx = mult_r( *gain_tcx, hTcxCfg->na_scale ); } - IF( st->element_mode != IVAS_CPE_MDCT ) + IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { i = norm_s( *gain_tcx ); *gain_tcx = shl( *gain_tcx, i ); @@ -4162,6 +4327,7 @@ void decoder_tcx_invQ_fx( gainlpc2[i] = mult( gainlpc2[i], *gain_tcx ); move16(); gainlpc2_e[i] = add( gainlpc2_e[i], *gain_tcx_e ); + move16(); } } @@ -4202,6 +4368,7 @@ void decoder_tcx_noisefilling_fx( Word16 fac_ns; Word16 noiseFillingSize; Word16 noiseTransWidth = MIN_NOISE_FILLING_HOLE; + move16(); Word16 tmp, tmp1, tmp2; Word16 sum_word16; Word16 infoIGFStartLine; @@ -4210,12 +4377,14 @@ void decoder_tcx_noisefilling_fx( TCX_LTP_DEC_HANDLE hTcxLtpDec = st->hTcxLtpDec; TCX_DEC_HANDLE hTcxDec = st->hTcxDec; TCX_CONFIG_HANDLE hTcxCfg = st->hTcxCfg; - Word32 total_brate = ( st->element_mode == IVAS_CPE_MDCT ? st->element_brate : st->total_brate ); + Word32 total_brate = ( (Word16) EQ_16( st->element_mode, IVAS_CPE_MDCT ) ? st->element_brate : st->total_brate ); Word32 tmp32; Word16 *pInfoTCXNoise; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move16(); Flag Carry = 0; + move16(); #endif /*-----------------------------------------------------------------* @@ -4227,7 +4396,7 @@ void decoder_tcx_noisefilling_fx( noiseFillingSize = L_spec; move16(); - IF( st->igf != 0 ) + if ( st->igf != 0 ) { noiseFillingSize = st->hIGFDec->infoIGFStartLine; move16(); @@ -4247,9 +4416,10 @@ void decoder_tcx_noisefilling_fx( * Noise filling. * *-----------------------------------------------------------*/ + test(); IF( bfi == 0 && ( fac_ns > 0 ) ) { - firstLine = tcxGetNoiseFillingTilt( A, M, L_frame, ( total_brate >= ACELP_13k20 && !st->rf_flag ), &noiseTiltFactor ); + firstLine = tcxGetNoiseFillingTilt( A, M, L_frame, ( GE_32( total_brate, ACELP_13k20 ) && !st->rf_flag ), &noiseTiltFactor ); IF( st->tcxonly != 0 ) { @@ -4257,17 +4427,18 @@ void decoder_tcx_noisefilling_fx( move16(); test(); test(); - IF( ( hTcxCfg->ctx_hm != 0 ) && ( st->last_core != ACELP_CORE ) && ( st->last_ctx_hm_enabled != 0 ) ) + if ( ( hTcxCfg->ctx_hm != 0 ) && ( NE_16( st->last_core, ACELP_CORE ) ) && ( st->last_ctx_hm_enabled != 0 ) ) { tmp1 = 10240 /*0.3125f Q15*/; move16(); } - IF( st->element_mode == IVAS_CPE_MDCT ) + IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) { IF( frame_cnt == 0 ) { Copy( hTcxDec->ltpGainMemory_fx, &hTcxDec->ltpGainMemory_fx[1], N_LTP_GAIN_MEMS - 1 ); hTcxDec->ltpGainMemory_fx[0] = hTcxLtpDec->tcxltp_gain; /* Q15 */ + move16(); } smooth_gain = Dot_product( hTcxDec->ltpGainMemory_fx, nf_tw_smoothing_coeffs_fx, N_LTP_GAIN_MEMS ); /* Q31 */ noiseTransWidth = HOLE_SIZE_FROM_LTP32( L_max( smooth_gain, L_deposit_h( tmp1 ) ) ); /* using 32-bit for increased precision. */ @@ -4358,21 +4529,21 @@ void decoder_tcx_noisefilling_fx( sum_word16 = add( sum_word16, st->hPlcInfo->TCX_Tonality[i] ); } - IF( GE_16( sum_word16, 6 ) ) + if ( GE_16( sum_word16, 6 ) ) { st->hPlcInfo->concealment_method = TCX_TONAL; move16(); } } - IF( st->tonal_mdct_plc_active ) + if ( st->tonal_mdct_plc_active ) { st->hPlcInfo->concealment_method = TCX_TONAL; move16(); } } - IF( GT_16( L_frameTCX, hTcxDec->L_frameTCX ) ) + if ( GT_16( L_frameTCX, hTcxDec->L_frameTCX ) ) { st->hPlcInfo->concealment_method = TCX_TONAL; move16(); @@ -4381,7 +4552,7 @@ void decoder_tcx_noisefilling_fx( *temp_concealment_method = st->hPlcInfo->concealment_method; move16(); - IF( EQ_16( st->core, TCX_10_CORE ) ) + if ( EQ_16( st->core, TCX_10_CORE ) ) { *temp_concealment_method = TCX_TONAL; move16(); @@ -4389,7 +4560,7 @@ void decoder_tcx_noisefilling_fx( } /* get the starting location of the subframe in the frame */ - IF( EQ_16( st->core, TCX_10_CORE ) ) + if ( EQ_16( st->core, TCX_10_CORE ) ) { st->hPlcInfo->subframe = extract_l( L_mult0( frame_cnt, L_frameTCX_glob ) ); } @@ -4400,6 +4571,7 @@ void decoder_tcx_noisefilling_fx( * PLC: Fade out to white noise */ IF( st->hTonalMDCTConc != NULL ) { + test(); IF( bfi == 0 && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { TonalMDCTConceal_SaveFreqSignal_ivas_fx( st->hTonalMDCTConc, x, *x_e, L_frameTCX, L_frame, gainlpc2, gainlpc2_e, gain_tcx_e, infoIGFStartLine ); @@ -4407,22 +4579,31 @@ void decoder_tcx_noisefilling_fx( } ELSE IF( bfi ) { + test(); IF( !st->enablePlcWaveadjust || EQ_16( *temp_concealment_method, TCX_TONAL ) ) { /* set f to 1 to not fade out */ /* set f to 0 to immediately switch to white noise */ + test(); + test(); IF( st->tcxonly && ( NE_16( st->element_mode, IVAS_CPE_MDCT ) || MCT_flag ) ) { f = MAX16B; + move16(); } ELSE { f = hTcxDec->cummulative_damping_tcx; + move16(); } test(); test(); - IF( ( frame_cnt == 0 ) && ( EQ_16( L_frameTCX, shr( hTcxDec->L_frameTCX, 1 ) ) ) && ( st->tcxonly ) && ( !st->tonal_mdct_plc_active ) && ( EQ_16( st->nbLostCmpt, 1 ) ) && ( hTcxCfg->tcx_last_overlap_mode != FULL_OVERLAP ) && ( hTcxCfg->tcx_curr_overlap_mode != FULL_OVERLAP ) ) + test(); + test(); + test(); + test(); + IF( ( frame_cnt == 0 ) && ( EQ_16( L_frameTCX, shr( hTcxDec->L_frameTCX, 1 ) ) ) && ( st->tcxonly ) && ( !st->tonal_mdct_plc_active ) && ( EQ_16( st->nbLostCmpt, 1 ) ) && ( NE_16( hTcxCfg->tcx_last_overlap_mode, FULL_OVERLAP ) ) && ( NE_16( hTcxCfg->tcx_curr_overlap_mode, FULL_OVERLAP ) ) ) { Word16 exp1, exp2; Word32 E_2ndlast, E_last; @@ -4450,8 +4631,6 @@ void decoder_tcx_noisefilling_fx( #else tmp1 = shl( tmp1, tmp2 ); #endif - test(); - test(); /* replace higher energy TCX5 frame by lower one to avoid energy fluctuation */ IF( GT_16( st->element_mode, EVS_MONO ) ) { @@ -4487,7 +4666,7 @@ void decoder_tcx_noisefilling_fx( tmp = 0; move16(); test(); - IF( GE_32( total_brate, ACELP_13k20 ) && st->rf_flag == 0 ) + if ( GE_32( total_brate, ACELP_13k20 ) && st->rf_flag == 0 ) { tmp = 1; move16(); @@ -4497,6 +4676,7 @@ void decoder_tcx_noisefilling_fx( Word32 CngLevelBackgroundTrace_bfi_fx = L_deposit_l( hTcxDec->conCngLevelBackgroundTrace ); Word16 CngLevelBackgroundTrace_bfi_exp = hTcxDec->conCngLevelBackgroundTrace_e + 16; + test(); IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && MCT_flag == 0 ) { TonalMDCTConceal_InsertNoise_ivas_fx( st->hTonalMDCTConc, x, x_e, st->tonal_mdct_plc_active, &st->seed_tcx_plc, noiseTiltFactor, f, concealment_noise, concealment_noise_exp, CngLevelBackgroundTrace_bfi_fx, CngLevelBackgroundTrace_bfi_exp, infoIGFStartLine ); @@ -4531,8 +4711,20 @@ void decoder_tcx_noisefilling_fx( { set32_fx( x + L_frameTCX, 0, sub( L_spec, L_frameTCX ) ); } - - IF( bfi && ( !st->enablePlcWaveadjust || EQ_16( *temp_concealment_method, TCX_TONAL ) ) && st->igf && ( frame_cnt == 0 ) && ( EQ_16( L_frameTCX, shr( hTcxDec->L_frameTCX, 1 ) ) ) && ( st->tcxonly ) && ( !st->tonal_mdct_plc_active ) && ( EQ_16( st->nbLostCmpt, 1 ) ) && ( hTcxCfg->tcx_last_overlap_mode != FULL_OVERLAP ) && ( hTcxCfg->tcx_curr_overlap_mode != FULL_OVERLAP ) ) + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( bfi && ( !st->enablePlcWaveadjust || EQ_16( *temp_concealment_method, TCX_TONAL ) ) && st->igf && ( frame_cnt == 0 ) && ( EQ_16( L_frameTCX, shr( hTcxDec->L_frameTCX, 1 ) ) ) && ( st->tcxonly ) && ( !st->tonal_mdct_plc_active ) && ( EQ_16( st->nbLostCmpt, 1 ) ) && ( NE_16( hTcxCfg->tcx_last_overlap_mode, FULL_OVERLAP ) ) && ( NE_16( hTcxCfg->tcx_curr_overlap_mode, FULL_OVERLAP ) ) ) { IGFDecCopyLPCFlatSpectrum_fx( st->hIGFDec, x, *x_e, IGF_GRID_LB_SHORT ); /* also replace flat spectrum for the second TCX10 sub frame */ @@ -4561,7 +4753,7 @@ void decoder_tcx_noisefilling_fx( } } - IF( st->igf ) + if ( st->igf ) { *st->hIGFDec->igfData.igfInfo.nfSeed = extract_l( L_add( L_mult0( nf_seed, 31821 ), 13849 ) ); } @@ -4702,10 +4894,12 @@ void decoder_tcx_noiseshaping_igf_fx( IF( GE_16( i, l_idx ) && LE_16( i, u_idx ) ) { x_fx[i] = L_shr( x_fx[i], sub( *x_e, curr_x_e ) ); + move32(); } ELSE { x_fx[i] = L_shr( x_fx[i], sub( *x_e, prev_x_e ) ); + move32(); } } } @@ -4715,7 +4909,7 @@ void decoder_tcx_noiseshaping_igf_fx( IF( st->hTonalMDCTConc != NULL && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { tmp32 = L_deposit_h( 0 ); - IF( GT_16( hTcxDec->tcxltp_last_gain_unmodified, 0 ) ) + if ( hTcxDec->tcxltp_last_gain_unmodified > 0 ) { tmp32 = st->old_fpitch; move32(); @@ -4724,7 +4918,7 @@ void decoder_tcx_noiseshaping_igf_fx( tmp8 = 0; move16(); test(); - IF( bfi && st->tonal_mdct_plc_active ) + if ( bfi && st->tonal_mdct_plc_active ) { tmp8 = 1; move16(); @@ -4773,10 +4967,12 @@ void decoder_tcx_noiseshaping_igf_fx( { /* packet loss after first TCX must be handled like transition frame */ igfGridIdx = IGF_GRID_LB_TRAN; + move16(); } ELSE { igfGridIdx = IGF_GRID_LB_NORM; + move16(); } IGFDecApplyMono_ivas( st->hIGFDec, x_fx, x_e, igfGridIdx, bfi, st->element_mode ); @@ -4784,7 +4980,8 @@ void decoder_tcx_noiseshaping_igf_fx( *x_len = s_max( *x_len, st->hIGFDec->igfData.igfInfo.grid[igfGridIdx].stopLine ); } } - + test(); + test(); IF( st->igf && ( ( EQ_16( L_frame, shr( st->L_frame, 1 ) ) ) && ( st->tcxonly ) ) ) { IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) ) diff --git a/lib_dec/dec_tran_fx.c b/lib_dec/dec_tran_fx.c index 081cf20b8..85497cc84 100644 --- a/lib_dec/dec_tran_fx.c +++ b/lib_dec/dec_tran_fx.c @@ -51,18 +51,23 @@ void decod_tran_fx( { Word16 T0, T0_frac, T0_min, T0_max; /* integer pitch variables */ Word32 gain_code_fx = 0; /* Quantized algebraic codeebook gain */ - Word32 norm_gain_code_fx = 0; /* normalized algebraic codeebook gain */ - Word16 gain_pit_fx = 0; /* Quantized pitch gain */ - Word16 voice_fac_fx; /* Voicing factor */ - Word16 gain_inov_fx = 0; /* inovation gain */ - Word16 code_fx[L_SUBFR]; /* algebraic codevector */ - const Word16 *p_Aq_fx; /* pointer to lp filter coefficient */ - Word16 *pt_pitch_fx; /* pointer to floating pitch */ - Word16 i_subfr, i; /* tmp variables */ - Word16 position; /* TC related flag */ - Word16 gain_preQ_fx = 0; /* Gain of prequantizer excitation */ - Word16 code_preQ_fx[L_SUBFR]; /* Prequantizer excitation */ - Word16 Jopt_flag; /* flag indicating zero adaptive contribtuion */ + move16(); + Word32 norm_gain_code_fx = 0; /* normalized algebraic codeebook gain */ + move16(); + Word16 gain_pit_fx = 0; /* Quantized pitch gain */ + move16(); + Word16 voice_fac_fx; /* Voicing factor */ + Word16 gain_inov_fx = 0; /* inovation gain */ + move16(); + Word16 code_fx[L_SUBFR]; /* algebraic codevector */ + const Word16 *p_Aq_fx; /* pointer to lp filter coefficient */ + Word16 *pt_pitch_fx; /* pointer to floating pitch */ + Word16 i_subfr, i; /* tmp variables */ + Word16 position; /* TC related flag */ + Word16 gain_preQ_fx = 0; /* Gain of prequantizer excitation */ + move16(); + Word16 code_preQ_fx[L_SUBFR]; /* Prequantizer excitation */ + Word16 Jopt_flag; /* flag indicating zero adaptive contribtuion */ Word32 norm_gain_preQ_fx; Word16 gain_code16; Word32 L_tmp; @@ -103,6 +108,7 @@ void decod_tran_fx( Scale_sig( bwe_exc_fx - PIT16k_MAX * 2, PIT16k_MAX * 2, tmp16 ); Scale_sig( hGSCDec->last_exc_dct_in_fx, L_FRAME, tmp16 ); st_fx->Q_exc = add( st_fx->Q_exc, tmp16 ); + move16(); } transition_dec_fx( st_fx, 0, L_frame_fx, i_subfr, tc_subfr_fx, &Jopt_flag, exc_fx, @@ -131,11 +137,11 @@ void decod_tran_fx( IF( Jopt_flag == 0 ) { /* 2/3-bit decoding */ - if ( st_fx->element_mode == EVS_MONO ) + IF( EQ_16( st_fx->element_mode, EVS_MONO ) ) { gain_dec_tc_fx( st_fx, code_fx, i_subfr, Es_pred_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx ); } - else + ELSE { gain_dec_tc_ivas_fx( st_fx, code_fx, i_subfr, Es_pred_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx ); } @@ -156,13 +162,15 @@ void decod_tran_fx( /* update LP filtered gains for the case of frame erasures */ lp_gain_updt_fx( i_subfr, gain_pit_fx, L_add( norm_gain_code_fx, norm_gain_preQ_fx ), &st_fx->lp_gainp_fx, &st_fx->lp_gainc_fx, L_frame_fx ); - IF( st_fx->element_mode == EVS_MONO ) + IF( EQ_16( st_fx->element_mode, EVS_MONO ) ) { st_fx->tilt_code_fx = est_tilt_fx( exc_fx + i_subfr, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, st_fx->Q_exc ); + move16(); } - else + ELSE { st_fx->tilt_code_fx = est_tilt_ivas_fx( exc_fx + i_subfr, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, st_fx->Q_exc, L_SUBFR, 0 ); + move16(); } /*----------------------------------------------------------------------* @@ -171,7 +179,8 @@ void decod_tran_fx( IF( EQ_16( L_frame_fx, L_FRAME ) ) /* Rescaling for 12.8k core */ { - Rescale_exc( hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr], &bwe_exc_fx[i_subfr * HIBND_ACB_L_FAC], hGSCDec->last_exc_dct_in_fx, + + Rescale_exc( hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr], &bwe_exc_fx[shr( imult1616( i_subfr, 2 * HIBND_ACB_L_FAC ), 1 )], 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, st_fx->coder_type ); } ELSE /* Rescaling for 16k core */ @@ -188,7 +197,7 @@ void decod_tran_fx( *-----------------------------------------------------------------*/ IF( GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) ) { - IF( st_fx->element_mode == EVS_MONO ) + IF( EQ_16( st_fx->element_mode, EVS_MONO ) ) { tmp1_fx = add( 15 - Q_AVQ_OUT_DEC - 2, st_fx->Q_exc ); } @@ -220,9 +229,13 @@ void decod_tran_fx( /*-----------------------------------------------------------------* * Prepare TBE excitation *-----------------------------------------------------------------*/ - + Word16 tmp_idx_2 = 0; + if ( i_subfr != 0 ) + { + tmp_idx_2 = idiv1616( i_subfr, L_SUBFR ); + } prep_tbe_exc_fx( L_frame_fx, i_subfr, gain_pit_fx, gain_code_fx, code_fx, voice_fac_fx, - &voice_factors_fx[i_subfr / L_SUBFR], bwe_exc_fx, gain_preQ_fx, code_preQ_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 ); /*----------------------------------------------------------------* @@ -239,12 +252,18 @@ void decod_tran_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 != 0 ) + { + tmp_idx = idiv1616( i_subfr, L_SUBFR ); + } p_Aq_fx += ( M + 1 ); move16(); pt_pitch_fx++; - st_fx->tilt_code_dec_fx[i_subfr / L_SUBFR] = st_fx->tilt_code_fx; + st_fx->tilt_code_dec_fx[tmp_idx] = st_fx->tilt_code_fx; move16(); - gain_buf[i_subfr / L_SUBFR] = gain_pit_fx; + gain_buf[tmp_idx] = gain_pit_fx; move16(); } diff --git a/lib_dec/dec_uv_fx.c b/lib_dec/dec_uv_fx.c index 7439b79d0..cbdb9407f 100644 --- a/lib_dec/dec_uv_fx.c +++ b/lib_dec/dec_uv_fx.c @@ -39,7 +39,8 @@ void decod_unvoiced_fx( Word16 *bwe_exc_fx, /* Q_X i/o: excitation for SWB TBE */ Word16 *gain_buf ) { - Word16 gain_pit_fx = 0; /* Quantized pitch gain */ + Word16 gain_pit_fx = 0; /* Quantized pitch gain */ + move16(); Word32 gain_code_fx; /* Quantized algebraic codeebook gain */ Word16 gain_inov_fx; /* inovation gain */ Word32 norm_gain_code_fx; /* normalized algebraic codeebook gain */ @@ -79,15 +80,21 @@ void decod_unvoiced_fx( 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 ); - voice_factors_fx[i_subfr_fx / L_SUBFR] = 0; + 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 * HIBND_ACB_L_FAC], L_SUBFR ); + interp_code_5over2_fx( &exc_fx[i_subfr_fx], &bwe_exc_fx[shr( imult1616( i_subfr_fx, 2 * HIBND_ACB_L_FAC ), 1 )], L_SUBFR ); p_Aq_fx += ( M + 1 ); move16(); pt_pitch_fx++; - st_fx->tilt_code_dec_fx[i_subfr_fx / L_SUBFR] = st_fx->tilt_code_fx; + st_fx->tilt_code_dec_fx[tmp_idx] = st_fx->tilt_code_fx; move16(); } @@ -121,7 +128,8 @@ void decod_unvoiced_ivas_fx( Word16 *gain_buf ) { Word16 gain_pit_fx = 0; /* Quantized pitch gain */ - Word32 gain_code_fx; /* Quantized algebraic codeebook gain */ + move16(); + Word32 gain_code_fx; /* Quantized algebraic codeebook gain */ Word32 gain_code2_fx; Word16 gain_inov_fx; /* inovation gain */ Word32 norm_gain_code_fx; /* normalized algebraic codeebook gain */ @@ -146,7 +154,7 @@ void decod_unvoiced_ivas_fx( FOR( i_subfr_fx = 0; i_subfr_fx < L_FRAME; i_subfr_fx += L_SUBFR ) { - if ( !uc_two_stage_flag ) + IF( !uc_two_stage_flag ) { /*----------------------------------------------------------------* * Unvoiced subframe processing @@ -155,7 +163,7 @@ void decod_unvoiced_ivas_fx( 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 ); } - else + ELSE { /*----------------------------------------------------------------* * Unvoiced subframe processing in two stages *----------------------------------------------------------------*/ @@ -182,8 +190,13 @@ void decod_unvoiced_ivas_fx( /*-----------------------------------------------------------------* * Gain encoding *-----------------------------------------------------------------*/ - - Word16 index = get_next_indice( st_fx, st_fx->acelp_cfg.gains_mode[i_subfr_fx / L_SUBFR] ); + Word16 tmp_idx_1 = 0; + move16(); + if ( i_subfr_fx != 0 ) + { + tmp_idx_1 = idiv1616( i_subfr_fx, L_SUBFR ); + } + Word16 index = get_next_indice( st_fx, st_fx->acelp_cfg.gains_mode[tmp_idx_1] ); // gain_dec_gacelp_uv(index, code, code2, Es_pred, L_SUBFR, &gain_pit, &gain_code, &gain_code2, &(st->past_gpit_float), &norm_gain_code, &gain_inov); gain_dec_gacelp_uv_fx( index, code_fx, code2_fx, Es_pred_fx, L_SUBFR, &gain_pit_fx, &gain_code_fx, &gain_code2_fx, &( st_fx->past_gpit ), &norm_gain_code_fx, &gain_inov_fx ); @@ -200,7 +213,8 @@ void decod_unvoiced_ivas_fx( IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { - Rescale_exc( st_fx->hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], ( bwe_exc_fx != NULL ) ? &bwe_exc_fx[i_subfr_fx * HIBND_ACB_L_FAC] : NULL, st_fx->hGSCDec->last_exc_dct_in_fx, + + Rescale_exc( st_fx->hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], ( bwe_exc_fx != NULL ) ? &bwe_exc_fx[shr( imult1616( i_subfr_fx, 2 * HIBND_ACB_L_FAC ), 1 )] : NULL, st_fx->hGSCDec->last_exc_dct_in_fx, L_SUBFR, L_SUBFR * HIBND_ACB_L_FAC, L_max( gain_code2_fx, gain_code_fx ), &( st_fx->Q_exc ), st_fx->Q_subfr, exc2_fx, i_subfr_fx, UNVOICED ); } ELSE @@ -209,15 +223,15 @@ void decod_unvoiced_ivas_fx( L_SUBFR, L_SUBFR * 2, L_max( gain_code2_fx, gain_code_fx ), &( st_fx->Q_exc ), st_fx->Q_subfr, exc2_fx, i_subfr_fx, UNVOICED ); } - for ( int i = 0; i < L_SUBFR; i++ ) + FOR( Word16 i = 0; i < L_SUBFR; i++ ) { /*exc2[i + i_subfr] = gain_pit * exc[i + i_subfr]; //Q14 exc2[i + i_subfr] += gain_code2 * code2[i]; //Q16 exc[i + i_subfr] = exc2[i + i_subfr] + gain_code * code[i];*/ // Q16 - exc2_fx[i + i_subfr_fx] = shl( mult_r( gain_pit_fx, exc_fx[i + i_subfr_fx] ), 2 ); // Q_exc - exc2_fx[i + i_subfr_fx] = add( exc2_fx[i + i_subfr_fx], extract_l( L_shr( Mpy_32_16_1( gain_code2_fx, code2_fx[i] ), Q10 - st_fx->Q_exc ) ) ); // Q_exc - exc_fx[i + i_subfr_fx] = add( exc2_fx[i + i_subfr_fx], extract_l( L_shr( Mpy_32_16_1( gain_code_fx, code_fx[i] ), Q10 - st_fx->Q_exc ) ) ); // Q_exc + exc2_fx[i + i_subfr_fx] = shl( mult_r( gain_pit_fx, exc_fx[i + i_subfr_fx] ), 2 ); // Q_exc + exc2_fx[i + i_subfr_fx] = add( exc2_fx[i + i_subfr_fx], extract_l( L_shr( Mpy_32_16_1( gain_code2_fx, code2_fx[i] ), sub( Q10, st_fx->Q_exc ) ) ) ); // Q_exc + exc_fx[i + i_subfr_fx] = add( exc2_fx[i + i_subfr_fx], extract_l( L_shr( Mpy_32_16_1( gain_code_fx, code_fx[i] ), sub( Q10, st_fx->Q_exc ) ) ) ); // Q_exc } // Scale_sig(code_fx, L_SUBFR, 3); //Q12 } @@ -232,15 +246,19 @@ void decod_unvoiced_ivas_fx( 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 ); - voice_factors_fx[i_subfr_fx / L_SUBFR] = 0; + Word16 tmp_idx = 0; + if ( i_subfr_fx != 0 ) + { + 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 * HIBND_ACB_L_FAC], L_SUBFR ); + interp_code_5over2_fx( &exc_fx[i_subfr_fx], &bwe_exc_fx[shr( imult1616( i_subfr_fx, 2 * HIBND_ACB_L_FAC ), 1 )], L_SUBFR ); p_Aq_fx += ( M + 1 ); move16(); pt_pitch_fx++; - st_fx->tilt_code_dec_fx[i_subfr_fx / L_SUBFR] = st_fx->tilt_code_fx; + st_fx->tilt_code_dec_fx[tmp_idx] = st_fx->tilt_code_fx; move16(); } diff --git a/lib_dec/dlpc_avq_fx.c b/lib_dec/dlpc_avq_fx.c index 4067fe76b..07f20ce6a 100644 --- a/lib_dec/dlpc_avq_fx.c +++ b/lib_dec/dlpc_avq_fx.c @@ -33,7 +33,7 @@ Word16 dlpc_avq_fx( move16(); last = 0; - if ( NE_16( numlpc, 1 ) ) + IF( NE_16( numlpc, 1 ) ) { move16(); last = M; @@ -107,13 +107,14 @@ static Word16 unary_decode_fx( move16(); *ind = 0; + test(); WHILE( ( get_next_indice_1_fx( st ) != 0 ) && !st->BER_detect ) { move16(); *ind = add( *ind, 1 ); } - IF( *ind != 0 ) + if ( *ind != 0 ) { move16(); *ind = add( *ind, 1 ); @@ -389,7 +390,8 @@ Word16 decode_lpc_avq_ivas_fx( stereo_mode = param_lpc[j]; move16(); } - param_lpc[j++] = stereo_mode; + param_lpc[j] = stereo_mode; + j = add( j, 1 ); move16(); } // #endif @@ -422,7 +424,11 @@ Word16 decode_lpc_avq_ivas_fx( * - we are in low bitrate mode and no joint SNS coding is used * - OR the side-SNS-is-zero flag is set for joint SNS */ - IF( NE_16( element_mode, IVAS_CPE_MDCT ) || ( !( sns_low_br_mode && ( EQ_16( stereo_mode, 0 ) || EQ_16( stereo_mode, 1 ) ) ) && !( EQ_16( q_type, 0 ) && EQ_16( param_lpc[j - 1], -2 ) ) ) ) + test(); + test(); + test(); + test(); + IF( NE_16( element_mode, IVAS_CPE_MDCT ) || ( !( sns_low_br_mode && ( ( stereo_mode == 0 ) || EQ_16( stereo_mode, 1 ) ) ) && !( ( q_type == 0 ) && EQ_16( param_lpc[j - 1], -2 ) ) ) ) { /* 2 bits to specify Q2,Q3,Q4,ext */ qn1 = add( 2, get_next_indice_fx( st, 2 ) ); diff --git a/lib_dec/dlpc_stoch_fx.c b/lib_dec/dlpc_stoch_fx.c index 83436ea99..742f76dd3 100644 --- a/lib_dec/dlpc_stoch_fx.c +++ b/lib_dec/dlpc_stoch_fx.c @@ -12,9 +12,10 @@ #include "prot_fx2.h" #ifdef IVAS_FLOAT_FIXED /* Constants */ -#define M 16 +#define M 16 +#ifndef IVAS_FLOAT_FIXED #define BFI_FAC 0.9f - +#endif void lpc_unquantize_fx( Decoder_State *st, @@ -32,7 +33,7 @@ void lpc_unquantize_fx( Word16 i; nb_indices = 0; /* to avoid compilation warnings */ - + move16(); Copy( st->lsf_old_fx, &lsf[0], m ); Copy( st->lsp_old_fx, &lsp[0], m ); @@ -42,7 +43,7 @@ void lpc_unquantize_fx( nb_indices = dlpc_avq_fx( param_lpc, &lsf[m], st->numlpc, st->sr_core ); FOR( k = 0; k < st->numlpc; k++ ) { - E_LPC_lsf_lsp_conversion( &lsf[( k + 1 ) * m], &lsp[( k + 1 ) * m], m ); + E_LPC_lsf_lsp_conversion( &lsf[imult1616( add( k, 1 ), m )], &lsp[imult1616( add( k, 1 ), m )], m ); } } ELSE IF( EQ_16( st->lpcQuantization, 1 ) ) @@ -97,7 +98,7 @@ void lpc_unquantize_fx( test(); test(); test(); - IF( st->lpcQuantization && st->acelp_cfg.midLpc && st->core == ACELP_CORE && st->rate_switching_reset == 0 ) + IF( st->lpcQuantization && st->acelp_cfg.midLpc && EQ_16( st->core, ACELP_CORE ) && st->rate_switching_reset == 0 ) { midlsf_dec( &lsf[0], &lsf[m], param_lpc[nb_indices], lsfmid, coder_type, &( st->mid_lsf_int ), st->prev_bfi, st->safety_net ); reorder_lsf_fx( lsfmid, LSF_GAP_MID_FX, M, st->sr_core ); diff --git a/lib_dec/ivas_mdct_core_dec.c b/lib_dec/ivas_mdct_core_dec.c index f3f268f35..61c5be3b1 100644 --- a/lib_dec/ivas_mdct_core_dec.c +++ b/lib_dec/ivas_mdct_core_dec.c @@ -167,7 +167,7 @@ static void dec_prm_tcx_sidebits_fx( *--------------------------------------------------------------------------------*/ /* Modes (ACE_GC, ACE_UC, TCX20, TCX10...) */ - getTCXMode_ivas( st, st0, MCT_flag ); + getTCXMode_ivas_fx( st, st0, MCT_flag ); st->flagGuidedAcelp = 0; @@ -194,7 +194,7 @@ static void dec_prm_tcx_sidebits_fx( st->last_core_from_bs = st->last_core; } - getTCXWindowing_ivas( st->core, st->last_core, st->element_mode, st->hTcxCfg, st0 ); + getTCXWindowing_ivas_fx( st->core, st->last_core, st->element_mode, st->hTcxCfg, st0 ); st->hTcxDec->kernel_type[0] = st->hTcxDec->kernel_type[1] = MDCT_IV; st->hTcxDec->kernel_type[0] = get_next_indice( st0, st->last_core_from_bs != ACELP_CORE ? 2 : 1 ); diff --git a/lib_dec/ivas_tcx_core_dec.c b/lib_dec/ivas_tcx_core_dec.c index 1703bbead..342c69d71 100644 --- a/lib_dec/ivas_tcx_core_dec.c +++ b/lib_dec/ivas_tcx_core_dec.c @@ -79,16 +79,27 @@ void stereo_tcx_init_dec_fx( st->rate_switching_init = 0; st->m_frame_type = ACTIVE_FRAME; st->core_brate = st->total_brate; + move16(); + move16(); + move32(); /*sampling rate*/ - st->sr_core = getCoreSamplerateMode2( st->element_mode, st->bits_frame_nominal * FRAMES_PER_SEC, st->bwidth, st->flag_ACELP16k, st->rf_flag, st->is_ism_format ); + st->sr_core = getCoreSamplerateMode2( st->element_mode, L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ), st->bwidth, st->flag_ACELP16k, st->rf_flag, st->is_ism_format ); st->fscale = sr2fscale( st->sr_core ); + move32(); + move16(); /*frame size*/ - st->L_frame = (Word16) ( st->sr_core / FRAMES_PER_SEC ); - hTcxDec->L_frameTCX = (Word16) ( st->output_Fs / FRAMES_PER_SEC ); + st->L_frame = extract_l( Mult_32_16( st->sr_core, INV_FRAME_PER_SEC_Q15 ) ); + hTcxDec->L_frameTCX = extract_l( Mult_32_16( st->output_Fs, INV_FRAME_PER_SEC_Q15 ) ); + move16(); + move16(); - IF( ( st->L_frame == L_FRAME16k && ( st->bits_frame_nominal * FRAMES_PER_SEC ) <= MAX_ACELP_BRATE ) || ( st->tcxonly && ( st->sr_core == 32000 || st->sr_core == INT_FS_16k ) ) ) + test(); + test(); + test(); + test(); + IF( ( EQ_16( st->L_frame, L_FRAME16k ) && LE_32( ( L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ) ), MAX_ACELP_BRATE ) ) || ( st->tcxonly && ( EQ_32( st->sr_core, 32000 ) || EQ_32( st->sr_core, INT_FS_16k ) ) ) ) { st->nb_subfr = NB_SUBFR16k; } @@ -96,28 +107,37 @@ void stereo_tcx_init_dec_fx( { st->nb_subfr = NB_SUBFR; } + move16(); /*TCX tools*/ - st->hTcxCfg->ctx_hm = getCtxHm( st->element_mode, st->bits_frame_nominal * FRAMES_PER_SEC, st->rf_flag ); - st->hTcxCfg->resq = getResq( st->bits_frame_nominal * FRAMES_PER_SEC ); - hTcxDec->tcx_lpc_shaped_ari = getTcxLpcShapedAri( st->bits_frame_nominal * FRAMES_PER_SEC, st->rf_flag, st->element_mode ); - st->igf = getIgfPresent_fx( st->element_mode, st->bits_frame_nominal * FRAMES_PER_SEC, st->bwidth, st->rf_flag ); + st->hTcxCfg->ctx_hm = getCtxHm( st->element_mode, L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ), st->rf_flag ); + st->hTcxCfg->resq = getResq( L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ) ); + hTcxDec->tcx_lpc_shaped_ari = getTcxLpcShapedAri( L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ), st->rf_flag, st->element_mode ); + st->igf = getIgfPresent_fx( st->element_mode, L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ), st->bwidth, st->rf_flag ); + move16(); + move16(); + move16(); + move16(); - IF( st->element_mode != EVS_MONO ) + IF( NE_16( st->element_mode, EVS_MONO ) ) { - st->hTcxCfg->fIsTNSAllowed = getTnsAllowed( st->bits_frame_nominal * FRAMES_PER_SEC, st->igf, st->element_mode ); + st->hTcxCfg->fIsTNSAllowed = getTnsAllowed( L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ), st->igf, st->element_mode ); + move16(); } IF( hTcxLtpDec != NULL ) { hTcxLtpDec->tcxltp = getTcxLtp( st->sr_core ); + move16(); } - IF( st->element_mode == IVAS_SCE ) + IF( EQ_16( st->element_mode, IVAS_SCE ) ) { - st->tcxonly = getTcxonly_fx( st->element_mode, st->bits_frame_nominal * FRAMES_PER_SEC, MCT_flag, st->is_ism_format ); + st->tcxonly = getTcxonly_fx( st->element_mode, L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ), MCT_flag, st->is_ism_format ); + move16(); + test(); /* LPC quantization */ - IF( st->sr_core <= INT_FS_16k && st->tcxonly == 0 ) + IF( LE_32( st->sr_core, INT_FS_16k ) && st->tcxonly == 0 ) { st->lpcQuantization = 1; } @@ -125,6 +145,7 @@ void stereo_tcx_init_dec_fx( { st->lpcQuantization = 0; } + move16(); IF( st->tcxonly == 0 ) { @@ -134,16 +155,27 @@ void stereo_tcx_init_dec_fx( { st->numlpc = 2; } + move16(); } - IF( ( st->bits_frame_nominal != st->last_bits_frame_nominal ) || - ( st->bwidth != st->last_bwidth ) || - ( st->last_core != TCX_20_CORE && st->last_core != TCX_10_CORE && !( st->prev_bfi == 1 && st->last_core == ACELP_CORE && st->last_con_tcx == 1 ) ) || - ( st->idchan == 1 && st->element_mode == IVAS_CPE_MDCT && last_element_mode != IVAS_CPE_MDCT ) ) + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( NE_32( st->bits_frame_nominal, st->last_bits_frame_nominal ) ) || + ( NE_16( st->bwidth, st->last_bwidth ) ) || + ( NE_16( st->last_core, TCX_20_CORE ) && NE_16( st->last_core, TCX_10_CORE ) && !( EQ_16( st->prev_bfi, 1 ) && EQ_16( st->last_core, ACELP_CORE ) && EQ_16( st->last_con_tcx, 1 ) ) ) || + ( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_MDCT ) && NE_16( last_element_mode, IVAS_CPE_MDCT ) ) ) { /*re-initialization*/ Word16 Q_old_Aq_12_8 = 12; + move16(); stereo_tcx_dec_mode_switch_reconf_ivas_fx( st, MCT_flag, last_element_mode, &st->hTcxDec->Q_syn_Overl_TDAC, &st->hHQ_core->Q_fer_samples, @@ -309,6 +341,7 @@ void stereo_tcx_core_dec_fx( assert( st->mdct_sw == MODE1 ); /* must be switched to TCX in MODE1 */ bfi = 0; + move16(); /*--------------------------------------------------------------------------------* * Initialization or re-configuration of Stereo TCX @@ -321,20 +354,26 @@ void stereo_tcx_core_dec_fx( *--------------------------------------------------------------------------------*/ iDiv_and_mod_32( st->total_brate, FRAMES_PER_SEC, &L_tmp, &mod, 0 ); - total_nbbits = (Word16) L_tmp; + total_nbbits = extract_l( L_tmp ); bitsRead = 0; LSF_Q_prediction = -1; /* to avoid compilation warnings */ + move16(); + move16(); IF( EQ_32( frameMode, FRAMEMODE_NORMAL ) ) { st->m_decodeMode = DEC_NO_FRAM_LOSS; bfi = 0; + move16(); + move16(); } IF( EQ_32( frameMode, FRAMEMODE_MISSING ) ) { st->m_decodeMode = DEC_CONCEALMENT_EXT; bfi = 1; + move16(); + move16(); } /* for bass postfilter */ IF( st->tcxonly ) @@ -345,14 +384,14 @@ void stereo_tcx_core_dec_fx( { st->p_bpf_noise_buf_32 = st->bpf_noise_buf_32; st->p_bpf_noise_buf = st->bpf_noise_buf; - set_s( pitch, L_SUBFR, st->nb_subfr ); + set16_fx( pitch, L_SUBFR, st->nb_subfr ); set16_fx( pit_gain_fx, 0, st->nb_subfr ); } /* Initialize pointers */ synth_fx = synth_buf_fx + hTcxDec->old_synth_len; synthFB_fx = synth_bufFB_fx + hTcxDec->old_synth_lenFB; - Copy_Scale_sig( hTcxDec->old_synth, synth_buf_fx, hTcxDec->old_synth_len, -st->Q_syn ); + Copy_Scale_sig( hTcxDec->old_synth, synth_buf_fx, hTcxDec->old_synth_len, negate( st->Q_syn ) ); Copy( hTcxDec->old_synthFB_fx, synth_bufFB_fx, hTcxDec->old_synth_lenFB ); set16_fx( synth_fx, 0, L_FRAME_PLUS + M ); set16_fx( synthFB_fx, 0, L_FRAME_PLUS + M ); @@ -365,18 +404,21 @@ void stereo_tcx_core_dec_fx( { st->second_last_core = st->last_core; + move16(); dec_prm_tcx_ivas_fx( st, param, param_lpc, &total_nbbits, last_element_mode, &bitsRead ); } ELSE { - IF( GT_16( st->nbLostCmpt, 1 ) ) + if ( GT_16( st->nbLostCmpt, 1 ) ) { st->flagGuidedAcelp = 0; + move16(); } /* PLC: [Common: mode decision] * PLC: Decide which Concealment to use. Update pitch lags if needed */ st->core = GetPLCModeDecision_ivas_fx( st ); + move16(); } /*--------------------------------------------------------------------------------* @@ -384,6 +426,7 @@ void stereo_tcx_core_dec_fx( *--------------------------------------------------------------------------------*/ st->acelp_cfg.midLpc = 0; + move16(); IF( !bfi ) { @@ -391,6 +434,8 @@ void stereo_tcx_core_dec_fx( { Word16 tcx_lpc_cdk; + test(); + test(); IF( bfi && st->use_partial_copy && EQ_16( st->rf_frame_type, RF_TCXFD ) ) { tcx_lpc_cdk = tcxlpc_get_cdk( GENERIC ); @@ -411,6 +456,7 @@ void stereo_tcx_core_dec_fx( Copy( &lsf_fx[M], st->mem_AR_fx, M ); hTcxDec->envWeighted = 1; + move16(); E_LPC_lsp_unweight( &lsp_fx[M], lspnew_uw_fx, lsfnew_uw_fx, st->inv_gamma /*1.0f / st->gamma_float*/, M ); } ELSE @@ -420,14 +466,15 @@ void stereo_tcx_core_dec_fx( Copy( st->lspold_uw, st->lsp_old_fx, M ); Copy( st->lsfold_uw, st->lsf_old_fx, M ); hTcxDec->envWeighted = 0; + move16(); } lpc_unquantize_fx( st, lsf_fx, lsp_fx, M, param_lpc, lspmid_fx, lsfmid_fx, AUDIO, &LSF_Q_prediction ); FOR( k = 0; k < st->numlpc; ++k ) { - Copy( &lsp_fx[( k + 1 ) * M], &lspnew_uw_fx[k * M], M ); - Copy( &lsf_fx[( k + 1 ) * M], &lsfnew_uw_fx[k * M], M ); + Copy( &lsp_fx[imult1616( add( k, 1 ), M )], &lspnew_uw_fx[k * M], M ); /*basop not used for k * M as M is a multiple of 2*/ + Copy( &lsf_fx[imult1616( add( k, 1 ), M )], &lsfnew_uw_fx[k * M], M ); } } @@ -436,9 +483,12 @@ void stereo_tcx_core_dec_fx( { FOR( i = 0; i < M; i++ ) { - st->lsf_adaptive_mean_fx[i] = add( add( mult_r( st->lsfoldbfi1_fx[i], ONE_BY_THREE_Q15 ), mult_r( st->lsfoldbfi0_fx[i], ONE_BY_THREE_Q15 ) ), mult_r( lsfnew_uw_fx[k * M + i], ONE_BY_THREE_Q15 ) ); + st->lsf_adaptive_mean_fx[i] = add( add( mult_r( st->lsfoldbfi1_fx[i], ONE_BY_THREE_Q15 ), mult_r( st->lsfoldbfi0_fx[i], ONE_BY_THREE_Q15 ) ), mult_r( lsfnew_uw_fx[add( imult1616( k, M ), i )], ONE_BY_THREE_Q15 ) ); st->lsfoldbfi1_fx[i] = st->lsfoldbfi0_fx[i]; - st->lsfoldbfi0_fx[i] = lsfnew_uw_fx[k * M + i]; + st->lsfoldbfi0_fx[i] = lsfnew_uw_fx[add( imult1616( k, M ), i )]; + move16(); + move16(); + move16(); } } } @@ -447,7 +497,8 @@ void stereo_tcx_core_dec_fx( /* PLC: [LPD: LPC concealment] Conceal the LPC from the lost frame */ const Word16 *lsfBase; /* base for differential lsf coding */ - IF( EQ_16( st->tcxonly, 0 ) || LT_16( st->core, TCX_10_CORE ) ) + test(); + IF( st->tcxonly == 0 || LT_16( st->core, TCX_10_CORE ) ) { st->numlpc = 1; } @@ -455,6 +506,7 @@ void stereo_tcx_core_dec_fx( { st->numlpc = 2; } + move16(); IF( EQ_16( st->nbLostCmpt, 1 ) ) { @@ -467,18 +519,19 @@ void stereo_tcx_core_dec_fx( dlpc_bfi( st->L_frame, lsfnew_uw_fx, st->lsfold_uw, st->last_good, st->nbLostCmpt, st->mem_MA_fx, st->mem_AR_fx, &( st->stab_fac_fx ), st->lsf_adaptive_mean_fx, st->numlpc, st->lsf_cng, (Word8) st->plcBackgroundNoiseUpdated, st->lsf_q_cng, st->old_lsf_q_cng, lsfBase, (Word8) st->tcxonly ); hTcxDec->envWeighted = 0; + move16(); Copy( st->lspold_uw, lsp_fx, M ); Copy( st->lsfold_uw, lsf_fx, M ); FOR( k = 0; k < st->numlpc; k++ ) { - Copy( &lsfnew_uw_fx[k * M], &lsf_fx[( k + 1 ) * M], M ); + Copy( &lsfnew_uw_fx[k * M], &lsf_fx[imult1616( add( k, 1 ), M )], M ); - lsf2lsp_fx( &lsf_fx[( k + 1 ) * M], &lsp_fx[( k + 1 ) * M], M, st->sr_core ); + lsf2lsp_fx( &lsf_fx[imult1616( add( k, 1 ), M )], &lsp_fx[imult1616( add( k, 1 ), M )], M, st->sr_core ); lsf2lsp_fx( st->lsf_q_cng, st->lsp_q_cng, M, st->sr_core ); - Copy( &lsp_fx[( k + 1 ) * M], &lspnew_uw_fx[k * M], M ); + Copy( &lsp_fx[imult1616( add( k, 1 ), M )], &lspnew_uw_fx[k * M], M ); } } @@ -497,9 +550,10 @@ void stereo_tcx_core_dec_fx( E_LPC_f_lsp_a_conversion( st->lsp_old_fx, st->old_Aq_12_8_fx, M ); } - IF( st->enablePlcWaveadjust && bfi ) + if ( st->enablePlcWaveadjust && bfi ) { - st->hPlcInfo->nbLostCmpt++; + st->hPlcInfo->nbLostCmpt = add( st->hPlcInfo->nbLostCmpt, 1 ); + move16(); } /*--------------------------------------------------------------------------------* @@ -519,24 +573,28 @@ void stereo_tcx_core_dec_fx( /* PLC: [TCX: TD PLC] */ con_tcx_fx( st, &synthFB_fx[0] /*, -1.f, NULL, 0, NULL */ ); + test(); IF( ( EQ_16( st->nbLostCmpt, 1 ) ) || hTcxDec->tcxConceal_recalc_exc ) { - Copy_Scale_sig( &synthFB_fx[-( st->hTcxDec->L_frameTCX / 2 + hTcxDec->pit_max_TCX + 2 * M )], &synthFB_fx[-( st->hTcxDec->L_frameTCX / 2 + hTcxDec->pit_max_TCX + 2 * M )], st->hTcxDec->L_frameTCX / 2 + hTcxDec->pit_max_TCX + 2 * M, -( st->Q_exc - 1 ) ); + Copy_Scale_sig( &synthFB_fx[negate( add( add( shr( st->hTcxDec->L_frameTCX, 1 ), hTcxDec->pit_max_TCX ), 2 * M ) )], &synthFB_fx[negate( add( add( shr( st->hTcxDec->L_frameTCX, 1 ), hTcxDec->pit_max_TCX ), 2 * M ) )], add( add( shr( st->hTcxDec->L_frameTCX, 1 ), hTcxDec->pit_max_TCX ), 2 * M ), negate( sub( st->Q_exc, 1 ) ) ); } ELSE { - Copy_Scale_sig( &synthFB_fx[-( st->hTcxDec->L_frameTCX )], &synthFB_fx[-( st->hTcxDec->L_frameTCX )], st->hTcxDec->L_frameTCX, -( st->Q_exc - 1 ) ); + Copy_Scale_sig( &synthFB_fx[negate( st->hTcxDec->L_frameTCX )], &synthFB_fx[negate( st->hTcxDec->L_frameTCX )], st->hTcxDec->L_frameTCX, negate( sub( st->Q_exc, 1 ) ) ); } lerp( synthFB_fx, synth_fx, st->L_frame, hTcxDec->L_frameTCX ); st->con_tcx = 1; + move16(); // set16_fx( &st->mem_pitch_gain[2], st->lp_gainp_fx, st->nb_subfr ); set16_fx( &st->mem_pitch_gain[2], extract_l( L_shr( st->Mode2_lp_gainp, 15 ) ), st->nb_subfr ); /* LPC for ACELP/BWE */ + test(); + test(); IF( st->narrowBand || EQ_32( st->sr_core, INT_FS_12k8 ) || EQ_32( st->sr_core, INT_FS_16k ) ) { - Copy( Aq_fx, st->mem_Aq, st->nb_subfr * ( M + 1 ) ); + Copy( Aq_fx, st->mem_Aq, imult1616( st->nb_subfr, ( M + 1 ) ) ); } /* PLC: [TCX: Tonal Concealment] */ @@ -609,22 +667,23 @@ void stereo_tcx_core_dec_fx( FOR( k = 0; k < 2; k++ ) { /* Set pointer to parameters */ - prm = param + ( k * DEC_NPRM_DIV ); + prm = param + imult1616( k, DEC_NPRM_DIV ); /* Stability Factor */ IF( !bfi ) { - st->stab_fac_fx = lsf_stab_fx( &lsf_fx[( k + 1 ) * M], &lsf_fx[k * M], 0, st->L_frame ); + st->stab_fac_fx = lsf_stab_fx( &lsf_fx[imult1616( add( k, 1 ), M )], &lsf_fx[k * M], 0, st->L_frame ); + move16(); } - E_LPC_f_lsp_a_conversion( &lsp_fx[( k + 1 ) * M], Aq_fx, M ); + E_LPC_f_lsp_a_conversion( &lsp_fx[imult1616( add( k, 1 ), M )], Aq_fx, M ); { // IGFDecRestoreTCX10SubFrameData_flt( st->hIGFDec, k ); /*float call to be removed*/ IGFDecRestoreTCX10SubFrameData_fx( st->hIGFDec, k ); } /* TCX decoder */ - decoder_tcx_ivas_fx( st, prm, Aq_fx, Aind, &synth_fx[k * st->L_frame / 2], &synthFB_fx[k * hTcxDec->L_frameTCX / 2], bfi, k, sba_dirac_stereo_flag ); + decoder_tcx_ivas_fx( st, prm, Aq_fx, Aind, &synth_fx[imult1616( k, shr( st->L_frame, 1 ) )], &synthFB_fx[imult1616( k, shr( hTcxDec->L_frameTCX, 1 ) )], bfi, k, sba_dirac_stereo_flag ); } } @@ -632,8 +691,11 @@ void stereo_tcx_core_dec_fx( * Post-processing *--------------------------------------------------------------------------------*/ + test(); IF( EQ_16( st->core, TCX_10_CORE ) || EQ_16( st->core, TCX_20_CORE ) ) { + test(); + test(); IF( st->enablePlcWaveadjust || /* bfi */ ( GE_32( st->last_total_brate, HQ_48k ) && /* recovery */ EQ_16( st->last_codec_mode, MODE2 ) ) ) @@ -641,13 +703,17 @@ void stereo_tcx_core_dec_fx( /* waveform adjustment */ concealment_signal_tuning_fx( bfi, st->core, synthFB_fx, &st->plcInfo, st->nbLostCmpt, st->prev_bfi, st->hTonalMDCTConc->secondLastPcmOut, st->last_core_bfi, st->hTonalMDCTConc->lastPcmOut, st ); + test(); + test(); + test(); IF( ( bfi || st->prev_bfi ) && st->hPlcInfo->Pitch && EQ_16( st->hPlcInfo->concealment_method, TCX_NONTONAL ) ) { lerp( synthFB_fx, synth_fx, st->L_frame, hTcxDec->L_frameTCX ); - IF( !bfi && st->prev_bfi ) + if ( !bfi && st->prev_bfi ) { st->hPlcInfo->Pitch = 0; + move16(); } } } @@ -662,10 +728,12 @@ void stereo_tcx_core_dec_fx( IF( EQ_16( st->core, TCX_20_CORE ) ) { /* LPC Interpolation for BWE/post-processing */ + test(); + test(); IF( st->narrowBand || EQ_32( st->sr_core, INT_FS_12k8 ) || EQ_32( st->sr_core, INT_FS_16k ) ) { int_lsp_fx( st->L_frame, st->lspold_uw, lspnew_uw_fx, Aq_fx, M, interpol_frac_fx, 0 ); - Copy( Aq_fx, st->mem_Aq, st->nb_subfr * ( M + 1 ) ); + Copy( Aq_fx, st->mem_Aq, imult1616( st->nb_subfr, ( M + 1 ) ) ); } } } @@ -675,6 +743,9 @@ void stereo_tcx_core_dec_fx( 16000 or below - the classification itself is just performed if(!st->tcxonly ) */ IF( LE_32( st->sr_core, INT_FS_16k ) ) { + test(); + test(); + test(); IF( EQ_16( st->core, TCX_20_CORE ) || EQ_16( st->core, TCX_10_CORE ) || ( st->tcxonly && st->bfi ) ) { Word16 pitch_C[4]; @@ -685,8 +756,11 @@ void stereo_tcx_core_dec_fx( /* note: codec_mode is forced to MODE2, since FEC_clas_estim() considers only TCX being in Mode2*/ Word16 prev_codec_mode = st->codec_mode; st->codec_mode = MODE2; + move16(); + move16(); FEC_clas_estim_fx( st, 0, st->L_frame, &st->clas_dec, st->tcxonly ? GENERIC : st->core_ext_mode, pitch_C, synth_fx, &st->lp_ener_FER_fx, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0 /*st->core_brate*/, st->Q_syn, NULL, st->mem_syn_clas_estim_fx, &st->classifier_Q_mem_syn, hTcxLtpDec->tcxltp ? hTcxDec->tcxltp_last_gain_unmodified : MIN_16, CLASSIFIER_TCX, bfi, st->last_core_brate, -1 ); st->codec_mode = prev_codec_mode; + move16(); } } @@ -695,10 +769,11 @@ void stereo_tcx_core_dec_fx( * Updates *--------------------------------------------------------------------------------*/ + test(); IF( bfi && NE_16( st->last_core, ACELP_CORE ) ) { /* Update FEC_scale_syn parameters */ - IF( EQ_16( hTcxLtpDec->tcxltp_gain, 0 ) ) + IF( hTcxLtpDec->tcxltp_gain == 0 ) { frame_ener_fx( st->L_frame, UNVOICED, synth_fx, shr( st->L_frame, 1 ), &st->enr_old_fx, st->L_frame, 0, 0, 0 ); } @@ -708,20 +783,23 @@ void stereo_tcx_core_dec_fx( } } + test(); + test(); IF( !bfi && GE_16( st->clas_dec, VOICED_TRANSITION ) && LT_16( st->clas_dec, INACTIVE_CLAS ) ) { /* use latest LPC set */ st->old_enr_LP = Enr_1_Az_fx( Aq_fx, L_SUBFR ); // Q3 + move16(); } /* Update past buffers */ Copy_Scale_sig( synth_buf_fx + st->L_frame, hTcxDec->old_synth, hTcxDec->old_synth_len, 0 ); - Copy( hTcxDec->old_synthFB_fx + hTcxDec->L_frameTCX - NS2SA_fx2( st->output_Fs, PH_ECU_MEM_NS ), hTcxDec->synth_history_fx, NS2SA_fx2( st->output_Fs, PH_ECU_MEM_NS ) ); + Copy( hTcxDec->old_synthFB_fx + sub( hTcxDec->L_frameTCX, NS2SA_fx2( st->output_Fs, PH_ECU_MEM_NS ) ), hTcxDec->synth_history_fx, NS2SA_fx2( st->output_Fs, PH_ECU_MEM_NS ) ); Copy( synth_bufFB_fx + hTcxDec->L_frameTCX, hTcxDec->old_synthFB_fx, hTcxDec->old_synth_lenFB ); Copy( st->hHQ_core->old_out_fx + NS2SA_fx2( st->output_Fs, N_ZERO_MDCT_NS ), hTcxDec->old_synthFB_fx + hTcxDec->old_synth_lenFB, NS2SA_fx2( st->output_Fs, PH_ECU_LOOKAHEAD_NS ) ); - Copy( &lspnew_uw_fx[( st->numlpc - 1 ) * M], st->lspold_uw, M ); - Copy( &lsfnew_uw_fx[( st->numlpc - 1 ) * M], st->lsfold_uw, M ); + Copy( &lspnew_uw_fx[imult1616( sub( st->numlpc, 1 ), M )], st->lspold_uw, M ); + Copy( &lsfnew_uw_fx[imult1616( sub( st->numlpc, 1 ), M )], st->lsfold_uw, M ); IF( EQ_16( bfi, 1 ) ) { @@ -737,16 +815,20 @@ void stereo_tcx_core_dec_fx( Copy( st->lsf_q_cng, st->old_lsf_q_cng, M ); /* Update CNG parameters */ + test(); IF( !st->tcxonly && st->hTdCngDec != NULL ) { /* update CNG parameters in active frames */ + test(); + test(); IF( EQ_16( st->bwidth, NB ) && hTcxDec->enableTcxLpc && NE_16( st->core, ACELP_CORE ) ) { Word16 buf[L_LP], res[L_FRAME], A[M + 1], r_h[M + 1], r_l[M + 1], tmp, lsptmp[M], q_r; - assert( st->L_frame == L_FRAME ); + assert( EQ_16( st->L_frame, L_FRAME ) ); Copy( synth_fx + L_FRAME - L_LP, buf, L_LP ); tmp = synth_fx[L_FRAME - L_LP - 1]; + move16(); E_UTIL_f_preemph2( 0, buf, st->preemph_fac, L_LP, &tmp ); autocorr_fx( buf, M, r_h, r_l, &q_r, L_LP, Assym_window_W16fx, 0, 0 ); lag_wind( r_h, r_l, M, INT_FS_12k8, LAGW_WEAK ); @@ -761,13 +843,22 @@ void stereo_tcx_core_dec_fx( } ELSE IF( st->hTdCngDec != NULL ) { - cng_params_upd_ivas_fx( &lsp_fx[M], st->old_exc_fx + L_EXC_MEM_DEC - st->L_frame, 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 ); + cng_params_upd_ivas_fx( &lsp_fx[M], st->old_exc_fx + sub( L_EXC_MEM_DEC, st->L_frame ), 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] = ( st->L_frame == L_FRAME ? 0 : 1 ); + IF( EQ_16( st->L_frame, L_FRAME ) ) + { + st->hTdCngDec->ho_16k_lsp[st->hTdCngDec->ho_circ_ptr] = 0; + } + ELSE + { + st->hTdCngDec->ho_16k_lsp[st->hTdCngDec->ho_circ_ptr] = 1; + } + move16(); } st->last_is_cng = 0; + move16(); /* Postfiltering */ #ifndef MSAN_FIX @@ -779,6 +870,7 @@ void stereo_tcx_core_dec_fx( post_decoder( st, synth_buf_fx, pit_gain_fx, pitch, signal_out_fx, st->p_bpf_noise_buf ); + test(); #ifdef MSAN_FIX IF( st->p_bpf_noise_buf_32 && st->tcxonly == 0 ) #else @@ -794,12 +886,13 @@ void stereo_tcx_core_dec_fx( IF( !bfi ) { - IF( st->enablePlcWaveadjust ) + if ( st->enablePlcWaveadjust ) { st->hPlcInfo->nbLostCmpt = 0; + move16(); } - IF( NE_16( param[1 + NOISE_FILL_RANGES], 0 ) ) + IF( param[1 + NOISE_FILL_RANGES] != 0 ) { Word32 tcxltp_pitch_tmp = L_add( L_deposit_h( hTcxLtpDec->tcxltp_pitch_int ), L_shl( L_deposit_l( div_s( hTcxLtpDec->tcxltp_pitch_fr, st->pit_res_max ) ), 1 ) ); /*15Q16*/ tcxltp_pitch_tmp = L_shr( tcxltp_pitch_tmp, 10 ); // Q6 @@ -807,32 +900,41 @@ void stereo_tcx_core_dec_fx( } ELSE { - set16_fx( pitch_buf_fx, shl( L_SUBFR, 6 ), NB_SUBFR16k ); + set16_fx( pitch_buf_fx, L_SUBFR << 6, NB_SUBFR16k ); } } - IF( bfi ) + if ( bfi ) { /*"LPD dec - All BFI"*/ bitsRead = 0; /*to avoid empty counting */ + move16(); } /* updates */ st->last_voice_factor_fx = 0; st->last_coder_type = st->coder_type; + move16(); + move16(); /* -------------------------------------------------------------- * * In FFT domain: perform noise estimation during active frames * -------------------------------------------------------------- */ + test(); + test(); + test(); IF( st->hFdCngDec != NULL && ( EQ_32( st->sr_core, INT_FS_12k8 ) || EQ_32( st->sr_core, INT_FS_16k ) ) && LE_32( st->total_brate, MAX_ACELP_BRATE ) ) { noisy_speech_detection_fx( st->hFdCngDec, st->VAD && EQ_16( st->m_frame_type, ACTIVE_FRAME ), signal_out_fx, 0 ); st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx = L_add( Mpy_32_32( Q31_0_99, st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx ), - st->hFdCngDec->hFdCngCom->flag_noisy_speech * Q31_0_01 ); + imult3216( Q31_0_01, st->hFdCngDec->hFdCngCom->flag_noisy_speech ) ); st->hFdCngDec->hFdCngCom->likelihood_noisy_speech = extract_h( st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx ); st->lp_noise = st->hFdCngDec->lp_noise; + move32(); + move32(); + move16(); IF( NE_16( st->element_mode, IVAS_CPE_TD ) ) { @@ -849,17 +951,20 @@ void stereo_tcx_core_dec_fx( } /* Generate additional comfort noise to mask potential coding artefacts */ + test(); + test(); IF( EQ_16( st->m_frame_type, ACTIVE_FRAME ) && st->flag_cna && !st->cna_dirac_flag ) { + test(); IF( EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( nchan_out, 2 ) ) { IF( NE_16( st->element_mode, last_element_mode ) ) { /* Clear memory for secondary channel CNA */ - set16_fx( hStereoCng->olapBufferSynth22_fx, 0, st->hFdCngDec->hFdCngCom->frameSize / 2 ); + set16_fx( hStereoCng->olapBufferSynth22_fx, 0, shr( st->hFdCngDec->hFdCngCom->frameSize, 1 ) ); } expand_range( st->hFdCngDec->msPsd, psd_part_fx, &psd_part_e, st->hFdCngDec->nFFTpart_shaping ); - scalebands_fx( psd_part_fx, st->hFdCngDec->part_shaping, st->hFdCngDec->nFFTpart_shaping, st->hFdCngDec->midband_shaping, st->hFdCngDec->nFFTpart_shaping, st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand, psd_fx, 1 ); + scalebands_fx( psd_part_fx, st->hFdCngDec->part_shaping, st->hFdCngDec->nFFTpart_shaping, st->hFdCngDec->midband_shaping, st->hFdCngDec->nFFTpart_shaping, sub( st->hFdCngDec->hFdCngCom->stopFFTbin, st->hFdCngDec->hFdCngCom->startBand ), psd_fx, 1 ); generate_stereo_masking_noise_fx( signal_out_fx, 0, st, hStereoTD, flag_sec_CNA, 0, hStereoCng, nchan_out ); } @@ -870,7 +975,8 @@ void stereo_tcx_core_dec_fx( } } - IF( EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( st->idchan, 0 ) ) + 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 ); } @@ -1648,13 +1754,15 @@ static void stereo_tcx_dec_mode_switch_reconf_ivas_fx( Word16 frame_size_index; st->rate_switching_init = 1; + move16(); /* Identify frame type - TCX Reconfiguration */ FOR( frame_size_index = 0; frame_size_index < FRAME_SIZE_NB; frame_size_index++ ) { - IF( LT_16( frame_size_index, sub( FRAME_SIZE_NB, 1 ) ) ) + IF( LT_16( frame_size_index, FRAME_SIZE_NB - 1 ) ) { - IF( LE_16( FrameSizeConfig[frame_size_index].frame_bits, st->bits_frame_nominal ) && GT_16( FrameSizeConfig[add( frame_size_index, 1 )].frame_bits, st->bits_frame_nominal ) ) + test(); + IF( LE_16( FrameSizeConfig[frame_size_index].frame_bits, st->bits_frame_nominal ) && GT_16( FrameSizeConfig[frame_size_index + 1].frame_bits, st->bits_frame_nominal ) ) { BREAK; } @@ -1669,7 +1777,7 @@ static void stereo_tcx_dec_mode_switch_reconf_ivas_fx( } /* Reconfigure Core */ - mode_switch_decoder_LPD_ivas_fx( st, st->bwidth, st->bits_frame_nominal * FRAMES_PER_SEC, st->last_bits_frame_nominal * FRAMES_PER_SEC, frame_size_index, MCT_flag, last_element_mode, Q_syn_Overl_TDAC, Q_fer_samples, Q_syn_Overl, Q_syn_Overl_TDACFB, Q_syn_OverlFB, Q_old_out, Q_old_outLB, Q_old_Aq_12_8 ); + mode_switch_decoder_LPD_ivas_fx( st, st->bwidth, L_mult0( st->bits_frame_nominal, FRAMES_PER_SEC ), imult3216( st->last_bits_frame_nominal, FRAMES_PER_SEC ), frame_size_index, MCT_flag, last_element_mode, Q_syn_Overl_TDAC, Q_fer_samples, Q_syn_Overl, Q_syn_Overl_TDACFB, Q_syn_OverlFB, Q_old_out, Q_old_outLB, Q_old_Aq_12_8 ); return; } @@ -1696,37 +1804,51 @@ static void dec_prm_tcx_ivas_fx( IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { // The value of 1/ FRAMES_PER_SEC shifted left by 19 because taking Q as 15 led to precision loss - st->bits_frame_core = (Word16) L_sub( L_shr( Mpy_32_16_1( st->total_brate, 10486 ), 4 ), st->next_bit_pos ); + st->bits_frame_core = extract_l( L_sub( L_shr( Mpy_32_16_1( st->total_brate, 10486 ), 4 ), st->next_bit_pos ) ); + move16(); } start_bit_pos = st->next_bit_pos; /* Init LTP data */ st->hTcxDec->tcx_hm_LtpPitchLag = -1; st->hTcxLtpDec->tcxltp_gain = 0; + move16(); + move16(); + move16(); /*--------------------------------------------------------------------------------* * header *--------------------------------------------------------------------------------*/ /* Modes (ACE_GC, ACE_UC, TCX20, TCX10...) */ - getTCXMode_ivas( st, st, 0 /* <- MCT_flag */ ); + getTCXMode_ivas_fx( st, st, 0 /* <- MCT_flag */ ); /* last_core for error concealment */ + test(); IF( !st->use_partial_copy && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { st->last_core_from_bs = get_next_indice_fx( st, 1 ); /* Store decoder memory of last_core */ + move16(); + test(); IF( EQ_16( st->last_core, ACELP_CORE ) && NE_16( st->last_core_from_bs, ACELP_CORE ) ) { /* A mismatch between the memory and the last_core from the bitstream indicates a frame was lost. If prev_bfi is not set the frame loss occured during CNG and the prev_bfi needs to be set. */ st->prev_bfi = 1; + move16(); } /* possible need for reconfiguration can only be decided correctly once last_core_from_bs has been decoded */ + test(); + test(); + test(); + test(); + test(); IF( NE_16( st->last_core, st->last_core_from_bs ) && ( NE_16( st->last_core_from_bs, TCX_20_CORE ) && NE_16( st->last_core_from_bs, TCX_10_CORE ) && !( EQ_16( st->prev_bfi, 1 ) && EQ_16( st->last_core_from_bs, ACELP_CORE ) && EQ_16( st->last_con_tcx, 1 ) ) ) ) { Word16 Q_old_Aq_12_8 = Q12; + move16(); stereo_tcx_dec_mode_switch_reconf_ivas_fx( st, 0, last_element_mode, &st->hTcxDec->Q_syn_Overl_TDAC, &st->hHQ_core->Q_fer_samples, &st->hTcxDec->Q_syn_Overl, @@ -1737,11 +1859,13 @@ static void dec_prm_tcx_ivas_fx( } st->last_core = st->last_core_from_bs; + move16(); /*for TCX 10 force last_core to be TCX since ACELP as previous core is forbidden*/ - IF( EQ_16( st->core, TCX_10_CORE ) ) + if ( EQ_16( st->core, TCX_10_CORE ) ) { st->last_core = TCX_20_CORE; + move16(); } } @@ -1749,13 +1873,15 @@ static void dec_prm_tcx_ivas_fx( { IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { - getTCXWindowing_ivas( st->core, st->last_core, st->element_mode, st->hTcxCfg, st ); + getTCXWindowing_ivas_fx( st->core, st->last_core, st->element_mode, st->hTcxCfg, st ); } st->flagGuidedAcelp = 0; + move16(); - IF( st->dec_glr ) + if ( st->dec_glr ) { st->dec_glr_idx = -1; + move16(); } } @@ -1773,7 +1899,7 @@ static void dec_prm_tcx_ivas_fx( * TCX20/10 parameters *--------------------------------------------------------------------------------*/ - IF( EQ_16( st->use_partial_copy, 0 ) ) + IF( st->use_partial_copy == 0 ) { getTCXparam_fx( st, st, hm_cfg, param, bits_common, start_bit_pos, NULL, NULL, NULL, -1 ); } @@ -1783,10 +1909,13 @@ static void dec_prm_tcx_ivas_fx( IF( LT_16( sub( *total_nbbits, bitsRead[0] ), sub( st->next_bit_pos, start_bit_pos ) ) ) { st->BER_detect = 1; + move16(); st->next_bit_pos = add( start_bit_pos, sub( *total_nbbits, bitsRead[0] ) ); + move16(); } bitsRead[0] = sub( st->next_bit_pos, start_bit_pos ); + move16(); } #if 1 /*Fixed to float changes*/ diff --git a/lib_dec/ivas_td_low_rate_dec.c b/lib_dec/ivas_td_low_rate_dec.c index 9f1c7b167..09d25ad12 100644 --- a/lib_dec/ivas_td_low_rate_dec.c +++ b/lib_dec/ivas_td_low_rate_dec.c @@ -246,16 +246,23 @@ void tdm_low_rate_dec_fx( *---------------------------------------------------------------*/ nb_subfr = 2; + move16(); st->GSC_IVAS_mode = 0; st->GSC_noisy_speech = 1; hGSCDec->noise_lev = 14; + move16(); + move16(); + move16(); pit_band_idx = 10 + BAND1k2; hGSCDec->Last_GSC_pit_band_idx = pit_band_idx; + move16(); + move16(); // st->tilt_code = 0.0f; st->tilt_code_fx = 0; + move16(); // set_f(exc, 0, L_FRAME); // set_f(dct_epit, 0, L_FRAME); // set_f(pitch_buf, L_SUBFR, NB_SUBFR); @@ -263,13 +270,19 @@ void tdm_low_rate_dec_fx( set_s( dct_epit, 0, L_FRAME ); set_s( pitch_buf, shl( L_SUBFR, Q6 ), NB_SUBFR ); st->bpf_off = 1; + move16(); st->bfi_pitch_fx = mean_fx( pitch_buf, 4 ); + move16(); st->bfi_pitch_frame = L_FRAME; Diff_len = L_FRAME / 2; st->bpf_off = 0; attack_flag = 0; + move16(); + move16(); + move16(); + move16(); /*--------------------------------------------------------------------------------------* * GSC decoder *--------------------------------------------------------------------------------------*/ @@ -277,20 +290,21 @@ void tdm_low_rate_dec_fx( /* find the current total number of bits used */ tmp_nb_bits_tot = st->next_bit_pos; - IF( st->element_mode == IVAS_CPE_TD ) + move16(); + if( EQ_16( st->element_mode, IVAS_CPE_TD ) ) { - tmp_nb_bits_tot += TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS; + tmp_nb_bits_tot = add( tmp_nb_bits_tot, TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS ); } - IF( st->tdm_LRTD_flag == 1 ) + if( EQ_16( st->tdm_LRTD_flag, 1 ) ) { - tmp_nb_bits_tot -= STEREO_BITS_TCA; + tmp_nb_bits_tot = sub( tmp_nb_bits_tot, STEREO_BITS_TCA ); } - IF( st->extl_brate_orig > 0 ) + if( st->extl_brate_orig > 0 ) { /* subtract 1 bit for TBE/BWE BWE flag (bit counted in extl_brate) */ - tmp_nb_bits_tot--; + tmp_nb_bits_tot = sub( tmp_nb_bits_tot, 1 ); } // gsc_dec(st, dct_epit, pit_band_idx, Diff_len, tmp_nb_bits_tot, nb_subfr, st->coder_type, &last_bin, lsf_new, exc_wo_nf, tmp_noise); @@ -526,6 +540,10 @@ void decod_gen_2sbfr_ivas_fx( Word32 gain_code = 0; /* gain/normalized gain of the algebraic excitation */ Word32 norm_gain_code = 0; /* normalized gain of the algebraic excitation */ Word16 gain_inov = 0; /* Innovation gain */ + move16(); + move32(); + move32(); + move16(); // Word16 gains_mem[2 * (NB_SUBFR - 1)]; /* pitch gain and code gain 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 */ @@ -544,11 +562,15 @@ void decod_gen_2sbfr_ivas_fx( *------------------------------------------------------------------*/ L_frame = L_FRAME; + move16(); T0 = PIT_MIN; T0_frac = 0; error = 0; + move16(); + move16(); + move16(); /*------------------------------------------------------------------* * ACELP subframe loop *------------------------------------------------------------------*/ @@ -556,7 +578,7 @@ void decod_gen_2sbfr_ivas_fx( p_Aq = Aq; /* pointer to interpolated LPC parameters */ pt_pitch = pitch_buf; /* pointer to the pitch buffer */ - for ( i_subfr = 0; i_subfr < L_frame; i_subfr += 2 * L_SUBFR ) + FOR( i_subfr = 0; i_subfr < L_frame; i_subfr += 2 * L_SUBFR ) { /*----------------------------------------------------------------------* * Decode pitch lag @@ -566,7 +588,9 @@ void decod_gen_2sbfr_ivas_fx( *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 ); // tbe_celp_exc_flt(st->element_mode, st->idchan, bwe_exc, L_frame, 2 * L_SUBFR, i_subfr, T0, T0_frac, &error, st->tdm_LRTD_flag); - if ( !( EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( st->idchan, 1 ) && !( st->tdm_LRTD_flag ) ) ) + test(); + test(); + IF( !( EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( st->idchan, 1 ) && !( st->tdm_LRTD_flag ) ) ) { tbe_celp_exc( L_frame, i_subfr, T0, T0_frac, &error, bwe_exc ); } @@ -602,6 +626,7 @@ void decod_gen_2sbfr_ivas_fx( // st->tilt_code = est_tilt(exc + i_subfr, gain_pit, code, gain_code, &voice_fac, 2 * L_SUBFR, 0); // st->tilt_code_fx = est_tilt_fx(exc + i_subfr, gain_pit, code, gain_code, &voice_fac, Q_exc/*, 2 * L_SUBFR, 0*/); 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 ); + move16(); /* update LP filtered gains for the case of frame erasures */ // lp_gain_updt(i_subfr, gain_pit, norm_gain_code, &st->lp_gainp, &st->lp_gainc, L_frame); @@ -614,7 +639,7 @@ void decod_gen_2sbfr_ivas_fx( *----------------------------------------------------------------------*/ #ifdef FIX_734_MISSING_SUBFR_LOW_RATE_ACELP /* Don't need the if/else as here L_frame==L_FRAME all the time */ - Rescale_exc( st->hMusicPF->dct_post_old_exc_fx, &exc[i_subfr], ( bwe_exc != NULL ) ? &bwe_exc[i_subfr * HIBND_ACB_L_FAC] : NULL, st->hGSCDec->last_exc_dct_in_fx, + Rescale_exc( st->hMusicPF->dct_post_old_exc_fx, &exc[i_subfr], ( bwe_exc != NULL ) ? &bwe_exc[imult1616( i_subfr, HIBND_ACB_L_FAC )] : NULL, st->hGSCDec->last_exc_dct_in_fx, 2 * L_SUBFR, 2 * L_SUBFR * HIBND_ACB_L_FAC, gain_code, &( st->Q_exc ), st->Q_subfr, exc2, i_subfr, st->coder_type ); #else @@ -640,13 +665,14 @@ void decod_gen_2sbfr_ivas_fx( * Prepare TBE excitation *-----------------------------------------------------------------*/ #ifdef FIX_734_MISSING_SUBFR_LOW_RATE_ACELP - 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], 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_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 ); #else // prep_tbe_exc(L_frame, L_SUBFR, i_subfr, gain_pit, gain_code, code, voice_fac, &voice_factors[i_subfr / L_SUBFR], bwe_exc, 0, NULL, T0, GENERIC, 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_exc, T0, T0_frac, GENERIC, st->core_brate/*, st->element_mode, st->idchan, st->hBWE_TD != NULL, st->tdm_LRTD_flag*/); 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, st->Q_exc, T0, T0_frac, GENERIC, st->core_brate, st->element_mode, st->idchan, st->hBWE_TD != NULL, st->tdm_LRTD_flag ); #endif - voice_factors[i_subfr / L_SUBFR + 1] = voice_factors[i_subfr / L_SUBFR]; + voice_factors[add( shr( i_subfr, 6 ) /*i_subfr / L_SUBFR*/, 1 )] = voice_factors[i_subfr / L_SUBFR /*i_subfr / L_SUBFR*/]; + move16(); /*----------------------------------------------------------------* * Excitation enhancements (update of total excitation signal) @@ -671,10 +697,14 @@ void decod_gen_2sbfr_ivas_fx( *pt_pitch = *( pt_pitch - 1 ); pt_pitch++; - gain_buf[i_subfr / L_SUBFR] = gain_pit; - gain_buf[( i_subfr + L_SUBFR ) / L_SUBFR] = gain_pit; - st->tilt_code_dec_fx[i_subfr / L_SUBFR] = st->tilt_code_fx; - st->tilt_code_dec_fx[( i_subfr + L_SUBFR ) / L_SUBFR] = st->tilt_code_fx; + gain_buf[i_subfr / L_SUBFR /*i_subfr / L_SUBFR*/] = gain_pit; + gain_buf[shr( add( i_subfr, L_SUBFR ), 6 ) /*(i_subfr+L_SUBFR) / L_SUBFR*/] = gain_pit; + st->tilt_code_dec_fx[i_subfr / L_SUBFR /*i_subfr / L_SUBFR*/] = st->tilt_code_fx; + st->tilt_code_dec_fx[shr( add( i_subfr, L_SUBFR ), 6 ) /*( i_subfr + L_SUBFR ) / L_SUBFR*/] = st->tilt_code_fx; + move16(); + move16(); + move16(); + move16(); // st->tilt_code_dec[i_subfr / L_SUBFR] = st->tilt_code; // st->tilt_code_dec[( i_subfr + L_SUBFR ) / L_SUBFR] = st->tilt_code; } @@ -682,6 +712,7 @@ void decod_gen_2sbfr_ivas_fx( /* SC-VBR */ // st->prev_gain_pit_dec = gain_pit; st->prev_gain_pit_dec_fx = gain_pit; + move16(); return; } diff --git a/lib_dec/jbm_jb4_circularbuffer.c b/lib_dec/jbm_jb4_circularbuffer.c index af539f930..bf3cbb71b 100644 --- a/lib_dec/jbm_jb4_circularbuffer.c +++ b/lib_dec/jbm_jb4_circularbuffer.c @@ -125,7 +125,7 @@ Word16 JB4_CIRCULARBUFFER_Init( UWord16 capacity ) { /* keep one element free to be able to decide between full/empty buffer */ - ++capacity; + capacity = (UWord16) L_add( capacity, 1 ); IF( ( h->data = malloc( capacity * sizeof( JB4_CIRCULARBUFFER_ELEMENT ) ) ) == NULL ) { @@ -153,8 +153,10 @@ Word16 JB4_CIRCULARBUFFER_Enque( } h->data[h->writePos] = element; - ++h->writePos; - IF( h->writePos == h->capacity ) + move32(); + h->writePos = (UWord16) L_add( h->writePos, 1 ); + move16(); + if ( EQ_32( h->writePos, h->capacity ) ) { h->writePos = 0; move16(); @@ -174,8 +176,10 @@ Word16 JB4_CIRCULARBUFFER_Deque( } *pElement = h->data[h->readPos]; - ++h->readPos; - IF( h->readPos == h->capacity ) + move32(); + h->readPos = (UWord16) L_add( h->readPos, 1 ); + move16(); + if ( EQ_32( h->readPos, h->capacity ) ) { h->readPos = 0; move16(); @@ -203,7 +207,7 @@ JB4_CIRCULARBUFFER_ELEMENT JB4_CIRCULARBUFFER_Back( { JB4_CIRCULARBUFFER_ELEMENT ret; - IF( h->writePos != 0U ) + IF( NE_32( h->writePos, 0U ) ) { ret = h->data[h->writePos - 1]; move32(); @@ -224,7 +228,7 @@ Word16 JB4_CIRCULARBUFFER_IsEmpty( { Word16 ret; - IF( h->readPos == h->writePos ) + IF( EQ_32( h->readPos, h->writePos ) ) { ret = 1; move16(); @@ -244,7 +248,7 @@ Word16 JB4_CIRCULARBUFFER_IsFull( { Word16 ret; - IF( ( ( h->writePos + 1 ) % h->capacity ) == h->readPos ) + IF( EQ_32( ( L_add( h->writePos, 1 ) % h->capacity ), h->readPos ) ) { ret = 1; move16(); @@ -264,14 +268,16 @@ UWord16 JB4_CIRCULARBUFFER_Size( { UWord16 ret; - IF( h->readPos <= h->writePos ) + IF( LE_32( h->readPos, h->writePos ) ) { - ret = h->writePos - h->readPos; + ret = (UWord16) L_sub( h->writePos, h->readPos ); + move16(); } ELSE { /* wrap around */ - ret = h->writePos + h->capacity - h->readPos; + ret = (UWord16) L_add( h->writePos, L_sub( h->capacity, h->readPos ) ); + move16(); } @@ -291,13 +297,13 @@ void JB4_CIRCULARBUFFER_Min( minEle = h->data[h->readPos]; move32(); - IF( h->readPos <= h->writePos ) + IF( LE_32( h->readPos, h->writePos ) ) { /* no wrap around */ /* calc statistics for [readPos;writePos[ */ FOR( i = h->readPos; i != h->writePos; ++i ) { - IF( LT_32( h->data[i], minEle ) ) + if ( LT_32( h->data[i], minEle ) ) { minEle = h->data[i]; move32(); @@ -310,7 +316,7 @@ void JB4_CIRCULARBUFFER_Min( /* calc statistics for [readPos;capacity[ */ FOR( i = h->readPos; i != h->capacity; ++i ) { - IF( LT_32( h->data[i], minEle ) ) + if ( LT_32( h->data[i], minEle ) ) { minEle = h->data[i]; move32(); @@ -319,7 +325,7 @@ void JB4_CIRCULARBUFFER_Min( /* calc statistics for [0;writePos[ */ FOR( i = 0; i != h->writePos; ++i ) { - IF( LT_32( h->data[i], minEle ) ) + if ( LT_32( h->data[i], minEle ) ) { minEle = h->data[i]; move32(); @@ -343,13 +349,13 @@ void JB4_CIRCULARBUFFER_Max( /* init output variable */ maxEle = h->data[h->readPos]; move32(); - IF( h->readPos <= h->writePos ) + IF( LE_32( h->readPos, h->writePos ) ) { /* no wrap around */ /* calc statistics for [readPos;writePos[ */ FOR( i = h->readPos; i != h->writePos; ++i ) { - IF( GT_32( h->data[i], maxEle ) ) + if ( GT_32( h->data[i], maxEle ) ) { maxEle = h->data[i]; move32(); @@ -362,7 +368,7 @@ void JB4_CIRCULARBUFFER_Max( /* calc statistics for [readPos;capacity[ */ FOR( i = h->readPos; i != h->capacity; ++i ) { - IF( GT_32( h->data[i], maxEle ) ) + if ( GT_32( h->data[i], maxEle ) ) { maxEle = h->data[i]; move32(); @@ -371,7 +377,7 @@ void JB4_CIRCULARBUFFER_Max( /* calc statistics for [0;writePos[ */ FOR( i = 0; i != h->writePos; ++i ) { - IF( GT_32( h->data[i], maxEle ) ) + if ( GT_32( h->data[i], maxEle ) ) { maxEle = h->data[i]; move32(); @@ -409,16 +415,16 @@ void JB4_CIRCULARBUFFER_MinAndPercentile( maxElementsSize = 0; move16(); - maxElementsCapacity = nElementsToIgnore + 1; + maxElementsCapacity = (UWord16) L_add( nElementsToIgnore, 1 ); move16(); assert( maxElementsCapacity <= JBM_MAX_CIRCULAR_ELEMENTS ); - IF( h->readPos <= h->writePos ) + IF( LE_32( h->readPos, h->writePos ) ) { /* no wrap around */ /* calc statistics for [readPos;writePos[ */ FOR( i = h->readPos; i != h->writePos; ++i ) { - IF( LT_32( h->data[i], minEle ) ) + if ( LT_32( h->data[i], minEle ) ) { minEle = h->data[i]; move32(); @@ -432,7 +438,7 @@ void JB4_CIRCULARBUFFER_MinAndPercentile( /* calc statistics for [readPos;capacity[ */ FOR( i = h->readPos; i != h->capacity; ++i ) { - IF( LT_32( h->data[i], minEle ) ) + if ( LT_32( h->data[i], minEle ) ) { minEle = h->data[i]; move32(); @@ -442,7 +448,7 @@ void JB4_CIRCULARBUFFER_MinAndPercentile( /* calc statistics for [0;writePos[ */ FOR( i = 0; i != h->writePos; ++i ) { - IF( LT_32( h->data[i], minEle ) ) + if ( LT_32( h->data[i], minEle ) ) { minEle = h->data[i]; move32(); @@ -470,7 +476,7 @@ static void JB4_CIRCULARBUFFER_calcPercentile( UWord16 i, j; /* insert newElement IF elements buffer is not yet full */ - IF( *size < capacity ) + IF( LT_32( *size, capacity ) ) { FOR( i = 0; i != *size; ++i ) { @@ -484,13 +490,16 @@ static void JB4_CIRCULARBUFFER_calcPercentile( } elements[i] = newElement; move32(); - ++*size; + *size = (UWord16) L_add( *size, 1 ); + move16(); return; } } /* newElement is maximum, just append it */ elements[*size] = newElement; - ++*size; + move32(); + *size = (UWord16) L_add( *size, 1 ); + move16(); return; } diff --git a/lib_dec/jbm_jb4_inputbuffer.c b/lib_dec/jbm_jb4_inputbuffer.c index 92f488f1b..25d02da35 100644 --- a/lib_dec/jbm_jb4_inputbuffer.c +++ b/lib_dec/jbm_jb4_inputbuffer.c @@ -126,7 +126,7 @@ ivas_error JB4_INPUTBUFFER_Init( { /* keep one element free to be able to decide between full/empty buffer */ - ++capacity; + capacity = (UWord16) L_add( capacity, 1 ); IF( ( h->data = malloc( capacity * sizeof( JB4_INPUTBUFFER_ELEMENT ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for JBM\n" ) ); @@ -160,7 +160,7 @@ Word16 JB4_INPUTBUFFER_Enque( *replacedElement = NULL; size = JB4_INPUTBUFFER_Size( h ); - IF( size >= h->capacity - 1 ) + IF( GE_32( size, L_sub( h->capacity, 1 ) ) ) { return -1; } @@ -169,8 +169,9 @@ Word16 JB4_INPUTBUFFER_Enque( IF( size == 0U ) { h->data[h->writePos] = element; - ++h->writePos; - IF( h->writePos == h->capacity ) + h->writePos = (UWord16) L_add( h->writePos, 1 ); + move16(); + if ( EQ_32( h->writePos, h->capacity ) ) { h->writePos = 0; move16(); @@ -179,11 +180,12 @@ Word16 JB4_INPUTBUFFER_Enque( } /* there's a high probability that the new element can be appended at the back */ - IF( GT_32( h->compareFunction( element, JB4_INPUTBUFFER_Back( h ), &replace ), 0 ) ) + IF( h->compareFunction( element, JB4_INPUTBUFFER_Back( h ), &replace ) > 0 ) { h->data[h->writePos] = element; - ++h->writePos; - IF( h->writePos == h->capacity ) + h->writePos = (UWord16) L_add( h->writePos, 1 ); + move16(); + if ( EQ_32( h->writePos, h->capacity ) ) { h->writePos = 0; move16(); @@ -194,16 +196,16 @@ Word16 JB4_INPUTBUFFER_Enque( /* out of order: use binary search to get the position to insert */ low = 0; move16(); - high = size - 1; + high = (UWord16) L_sub( size, 1 ); WHILE( LE_16( low, high ) ) { middle = add( low, shr( sub( high, low ), 1 ) ); diff = h->compareFunction( element, JB4_INPUTBUFFER_Element( h, middle ), &replace ); - IF( LT_16( diff, 0 ) ) + IF( diff < 0 ) { high = sub( middle, 1 ); } - ELSE IF( GT_16( diff, 0 ) ) + ELSE IF( diff > 0 ) { low = add( middle, 1 ); } @@ -211,8 +213,8 @@ Word16 JB4_INPUTBUFFER_Enque( { IF( replace != 0 ) { - *replacedElement = h->data[( h->readPos + middle ) % h->capacity]; - h->data[( h->readPos + middle ) % h->capacity] = element; + *replacedElement = h->data[L_add( h->readPos, middle ) % h->capacity]; + h->data[L_add( h->readPos, middle ) % h->capacity] = element; return 0; } return 1; @@ -220,20 +222,18 @@ Word16 JB4_INPUTBUFFER_Enque( } - insertPos = ( h->readPos + low ) % h->capacity; - IF( h->readPos < h->writePos ) + insertPos = L_add( h->readPos, low ) % h->capacity; + IF( LT_32( h->readPos, h->writePos ) ) { canMoveRight = 1; move16(); - canMoveLeft = h->readPos > 0; + canMoveLeft = (UWord16) ( h->readPos > 0 ); move16(); } ELSE { - canMoveRight = insertPos < h->writePos; - move16(); - canMoveLeft = insertPos > h->writePos; - move16(); + canMoveRight = (UWord16) LT_32( insertPos, h->writePos ); + canMoveLeft = (UWord16) GT_32( insertPos, h->writePos ); } assert( canMoveRight != 0 || canMoveLeft != 0 ); @@ -247,8 +247,9 @@ Word16 JB4_INPUTBUFFER_Enque( } h->data[insertPos] = element; - ++h->writePos; - IF( h->writePos == h->capacity ) + h->writePos = (UWord16) L_add( h->writePos, 1 ); + move16(); + if ( EQ_32( h->writePos, h->capacity ) ) { h->writePos = 0; move16(); @@ -259,11 +260,12 @@ Word16 JB4_INPUTBUFFER_Enque( /* move lower elements to the left and insert before insertPos */ FOR( j = 0; j < low; j++ ) { - h->data[h->readPos - 1 + j] = h->data[h->readPos + j]; + h->data[L_add( L_sub( h->readPos, 1 ), j )] = h->data[L_add( h->readPos, j )]; } h->data[insertPos - 1] = element; - --h->readPos; + h->readPos = (UWord16) L_sub( h->readPos, 1 ); + move16(); assert( (Word16) h->readPos >= 0 ); } @@ -281,8 +283,9 @@ Word16 JB4_INPUTBUFFER_Deque( } *pElement = h->data[h->readPos]; - ++h->readPos; - IF( h->readPos == h->capacity ) + h->readPos = (UWord16) L_add( h->readPos, 1 ); + move16(); + if ( EQ_32( h->readPos, h->capacity ) ) { h->readPos = 0; move16(); @@ -332,14 +335,14 @@ JB4_INPUTBUFFER_ELEMENT JB4_INPUTBUFFER_Element( JB4_INPUTBUFFER_ELEMENT ret; /* return h->data[(h->readPos + index) % h->capacity] without error handling */ - IF( h->readPos + index < h->capacity ) + IF( LT_32( L_add( h->readPos, index ), h->capacity ) ) { - ret = h->data[h->readPos + index]; + ret = h->data[L_add( h->readPos, index )]; } ELSE { /* wrap around */ - ret = h->data[h->readPos + index - h->capacity]; + ret = h->data[L_sub( L_add( h->readPos, index ), h->capacity )]; } return ret; @@ -351,8 +354,7 @@ Word16 JB4_INPUTBUFFER_IsEmpty( { Word16 ret; - ret = h->readPos == h->writePos; - move16(); + ret = (UWord16) EQ_32( h->readPos, h->writePos ); return ret; } @@ -365,7 +367,7 @@ Word16 JB4_INPUTBUFFER_IsFull( ret = 0; move16(); - IF( JB4_INPUTBUFFER_Size( h ) == h->capacity - 1 ) + if ( EQ_32( JB4_INPUTBUFFER_Size( h ), L_sub( h->capacity, 1 ) ) ) { ret = 1; move16(); @@ -380,16 +382,14 @@ UWord16 JB4_INPUTBUFFER_Size( { UWord16 ret; - IF( h->readPos <= h->writePos ) + IF( LE_32( h->readPos, h->writePos ) ) { - ret = h->writePos - h->readPos; - move16(); + ret = (UWord16) L_sub( h->writePos, h->readPos ); } ELSE { /* wrap around */ - ret = h->writePos + h->capacity - h->readPos; - move16(); + ret = (UWord16) L_add( h->writePos, L_sub( h->capacity, h->readPos ) ); } return ret; diff --git a/lib_dec/jbm_jb4_jmf.c b/lib_dec/jbm_jb4_jmf.c index 8af4a8286..cecd4d2e6 100644 --- a/lib_dec/jbm_jb4_jmf.c +++ b/lib_dec/jbm_jb4_jmf.c @@ -50,6 +50,7 @@ #include "jbm_jb4_circularbuffer.h" /* instrumentation */ +#define INV_125_Q15 262 /*1/125 IN Q_15*/ #ifdef IVAS_FLOAT_FIXED /** jitter measure fifo - a fifo used for windowed measure of network status */ @@ -169,11 +170,14 @@ Word16 JB4_JMF_Init( { /* check parameters */ - IF( windowSize != 0U && consideredFraction * windowSize / 1000 < 2 ) + Word32 temp; + temp = Mult_32_16( W_extract_l( W_shr( W_mult0_32_32( consideredFraction, windowSize ), 3 ) ), INV_125_Q15 ); + test(); + IF( windowSize != 0U && LT_32( temp, 2 ) ) { return -1; } - IF( consideredFraction > 1000 ) + IF( GT_32( consideredFraction, 1000 ) ) { return -1; } @@ -190,7 +194,8 @@ Word16 JB4_JMF_Init( JB4_CIRCULARBUFFER_Init( h->offsetFifo, windowSize ); JB4_CIRCULARBUFFER_Init( h->timeStampFifo, windowSize ); - h->nElementsToIgnore = (UWord16) ( windowSize * ( 1000 - consideredFraction ) / 1000 ); + h->nElementsToIgnore = (UWord16) round_fx( imult3216( W_extract_l( W_shr( W_mult0_32_32( windowSize, L_sub( 1000, consideredFraction ) ), 2 ) ), INV_125_Q15 ) ); + move16(); return 0; } @@ -206,7 +211,7 @@ Word16 JB4_JMF_PushPacket( Word32 offset, delay; /* check if this is the first entry */ - IF( EQ_16( h->firstPacketPushed, 0 ) ) + IF( h->firstPacketPushed == 0 ) { h->firstPacketPushed = 1; move16(); @@ -217,16 +222,12 @@ Word16 JB4_JMF_PushPacket( return 0; } - rtpTimeDiff = (Word32) ( rtpTimeStamp - h->lastRtpTimeStamp ); - move32(); - sysTimeDiff = sysTime - h->lastSysTime; - move32(); - offset = sysTime - rtpTimeStamp; - move32(); + rtpTimeDiff = W_extract_l( W_sub( rtpTimeStamp, h->lastRtpTimeStamp ) ); + sysTimeDiff = W_extract_l( W_sub( sysTime, h->lastSysTime ) ); + offset = W_extract_l( W_sub( sysTime, rtpTimeStamp ) ); /* get the delay (yes, signed!!!!) */ - delay = sysTimeDiff - rtpTimeDiff + h->lastDelay; - move32(); + delay = L_add( L_sub( sysTimeDiff, rtpTimeDiff ), h->lastDelay ); /* remember old values */ h->lastSysTime = sysTime; @@ -235,7 +236,8 @@ Word16 JB4_JMF_PushPacket( move32(); /* reset delay if absolute value is greater than 60s * to avoid overflow caused by clockdrift */ - IF( delay > 60 * h->timeScale || delay < -60 * h->timeScale ) + test(); + IF( GT_32( delay, L_mult0( 60, h->timeScale ) ) || LT_32( delay, L_mult0( -60, h->timeScale ) ) ) { h->lastDelay = 0; move32(); @@ -260,7 +262,7 @@ Word16 JB4_JMF_Jitter( JB4_CIRCULARBUFFER_ELEMENT min_ele, percentile; /* sanity check (must not be empty) and return invalid result if there is only one entry */ - IF( JB4_CIRCULARBUFFER_Size( h->fifo ) < 2U ) + IF( LT_32( JB4_CIRCULARBUFFER_Size( h->fifo ), 2U ) ) { return -1; } @@ -268,7 +270,8 @@ Word16 JB4_JMF_Jitter( JB4_CIRCULARBUFFER_MinAndPercentile( h->fifo, h->nElementsToIgnore, &min_ele, &percentile ); /* return the difference between the highest considered and the smallest value */ - *jitter = percentile - min_ele; + *jitter = L_sub( percentile, min_ele ); + move32(); assert( percentile >= min_ele ); return 0; @@ -324,20 +327,18 @@ static void JB4_JMF_pushBack( /* check for duration and discard first entries if too long */ minTime = JB4_CIRCULARBUFFER_Front( h->timeStampFifo ); maxTime = JB4_CIRCULARBUFFER_Back( h->timeStampFifo ); - IF( maxTime > minTime ) + IF( GT_32( maxTime, minTime ) ) { - duration = maxTime - minTime; - move32(); - WHILE( duration > h->maxWindowDuration ) + duration = L_sub( maxTime, minTime ); + WHILE( GT_64( duration, h->maxWindowDuration ) ) { JB4_JMF_popFront( h ); minTime = JB4_CIRCULARBUFFER_Front( h->timeStampFifo ); - IF( maxTime <= minTime ) + IF( LT_32( maxTime, minTime ) ) { BREAK; } - duration = maxTime - minTime; - move32(); + duration = (UWord32) ( W_sub( maxTime, minTime ) ); } } diff --git a/lib_dec/jbm_jb4sb.c b/lib_dec/jbm_jb4sb.c index a0245e908..0e43a94a3 100644 --- a/lib_dec/jbm_jb4sb.c +++ b/lib_dec/jbm_jb4sb.c @@ -49,9 +49,11 @@ #include "jbm_jb4_jmf.h" #include "jbm_jb4sb.h" #include "prot.h" - +#include "prot_fx2.h" #define WMC_TOOL_SKIP +#define INV_500_Q31 4294967 /*1/500 IN Q_31*/ +#define INV_20_Q15 1638 /*1/20 in Q15*/ #define JB4_MIN( a, b ) ( ( a ) > ( b ) ? ( b ) : ( a ) ) #define JB4_MAX( a, b ) ( ( a ) > ( b ) ? ( a ) : ( b ) ) @@ -261,11 +263,13 @@ ivas_error JB4_Create( /* jitter buffer data */ h->firstDataUnitPopped = false; + move16(); h->prevPopSysTime = 0; move32(); h->lastReturnedTs = 0; move32(); h->lastPoppedWasSilence = false; + move16(); h->lastPlayoutOffset = 0; move32(); h->nextExpectedTs = 0; @@ -282,8 +286,10 @@ ivas_error JB4_Create( move32(); JB4_JMF_Create( &h->ltJmf ); h->pre_partial_frame = 0; + move16(); h->FecOffWinLen = 0; + move32(); FOR( iter = 0; iter < 10; iter++ ) { h->FecOffWin[iter] = 0; @@ -304,7 +310,7 @@ ivas_error JB4_Create( move32(); /* members to store the data units */ - IF( ( error = JB4_INPUTBUFFER_Create( &h->inputBuffer ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = JB4_INPUTBUFFER_Create( &h->inputBuffer ) ), IVAS_ERR_OK ) ) { return error; } @@ -381,7 +387,7 @@ ivas_error JB4_Init( /* long term jitter measure FIFO: 500 frames and 10s */ ltJmfSize = 10000; move16(); - JB4_JMF_Init( h->ltJmf, h->timeScale, ltJmfSize / 20, ltJmfSize, 1000 ); + JB4_JMF_Init( h->ltJmf, h->timeScale, 500 /*ltJmfSize / 20*/, ltJmfSize, 1000 ); /* short term jitter evaluation */ stFifoSize = 200; move16(); @@ -391,12 +397,12 @@ ivas_error JB4_Init( move16(); JB4_CIRCULARBUFFER_Init( h->stJitterFifo, stFifoSize ); JB4_CIRCULARBUFFER_Init( h->stTimeStampFifo, stFifoSize ); - JB4_JMF_Init( h->stJmf, h->timeScale, stJmfSize, h->timeScale /* 1s */, (UWord16) ( 1000 - stJmfAllowedLateLoss ) ); + JB4_JMF_Init( h->stJmf, h->timeScale, stJmfSize, h->timeScale /* 1s */, (UWord16) L_sub( 1000, stJmfAllowedLateLoss ) ); inputBufferCapacity = MAX_JBM_SLOTS - 2; move16(); - IF( ( error = JB4_INPUTBUFFER_Init( h->inputBuffer, inputBufferCapacity, JB4_inputBufferCompareFunction ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = JB4_INPUTBUFFER_Init( h->inputBuffer, inputBufferCapacity, JB4_inputBufferCompareFunction ) ), IVAS_ERR_OK ) ) { return error; } @@ -410,13 +416,14 @@ JB4_DATAUNIT_HANDLE JB4_AllocDataUnit( JB4_HANDLE h ) { JB4_DATAUNIT_HANDLE dataUnit; - while ( h->nFreeMemorySlots == 0 ) + WHILE( h->nFreeMemorySlots == 0 ) { assert( JB4_INPUTBUFFER_IsEmpty( h->inputBuffer ) == 0 ); JB4_dropFromBuffer( h ); } - --h->nFreeMemorySlots; + h->nFreeMemorySlots = (UWord16) L_sub( h->nFreeMemorySlots, 1 ); + move16(); dataUnit = h->freeMemorySlots[h->nFreeMemorySlots]; h->freeMemorySlots[h->nFreeMemorySlots] = NULL; assert( dataUnit != NULL ); @@ -433,7 +440,8 @@ void JB4_FreeDataUnit( assert( dataUnit != NULL ); assert( h->nFreeMemorySlots < MAX_JBM_SLOTS ); h->freeMemorySlots[h->nFreeMemorySlots] = dataUnit; - h->nFreeMemorySlots++; + h->nFreeMemorySlots = (UWord16) L_add( h->nFreeMemorySlots, 1 ); + move16(); return; } @@ -450,8 +458,9 @@ Word16 JB4_PushDataUnit( assert( dataUnit->timeScale == (UWord16) h->timeScale ); /* ignore frames from too far in future (3 seconds) */ - IF( h->firstDataUnitPopped && JB4_rtpTimeStampDiff( h->lastReturnedTs, dataUnit->timeStamp ) >= - (Word32) ( 50 * 3 * dataUnit->duration ) ) + test(); + IF( h->firstDataUnitPopped && GE_32( JB4_rtpTimeStampDiff( h->lastReturnedTs, dataUnit->timeStamp ), + imult3216( (Word32) dataUnit->duration, 50 * 3 ) ) ) { JB4_FreeDataUnit( h, dataUnit ); return 0; @@ -466,18 +475,31 @@ Word16 JB4_PushDataUnit( /* do statistics on partial copy offset using active primary copies to * avoid unexpected resets because RF_NO_DATA partial copies are dropped before JBM */ + test(); IF( dataUnit->silenceIndicator == 0 && dataUnit->partial_frame == 0 ) { - IF( EQ_16( dataUnit->partialCopyOffset, 0 ) ) + IF( dataUnit->partialCopyOffset == 0 ) { - IF( GT_16( h->rfOffset2Active, 0 ) ) - --h->rfOffset2Active; - IF( GT_16( h->rfOffset3Active, 0 ) ) - --h->rfOffset3Active; - IF( GT_16( h->rfOffset5Active, 0 ) ) - --h->rfOffset5Active; - IF( GT_16( h->rfOffset7Active, 0 ) ) - --h->rfOffset7Active; + if ( h->rfOffset2Active > 0 ) + { + h->rfOffset2Active = sub( h->rfOffset2Active, 1 ); + move16(); + } + if ( h->rfOffset3Active > 0 ) + { + h->rfOffset3Active = sub( h->rfOffset3Active, 1 ); + move16(); + } + if ( h->rfOffset5Active > 0 ) + { + h->rfOffset5Active = sub( h->rfOffset5Active, 1 ); + move16(); + } + if ( h->rfOffset7Active > 0 ) + { + h->rfOffset7Active = sub( h->rfOffset7Active, 1 ); + move16(); + } } ELSE IF( EQ_16( dataUnit->partialCopyOffset, 2 ) ) { @@ -528,7 +550,8 @@ Word16 JB4_PushDataUnit( IF( dataUnit->partial_frame != 0 ) { /* check for "real" late loss: a frame with higher/same timestamp was already returned to be fed into decoder */ - IF( h->firstDataUnitPopped && LE_32( JB4_rtpTimeStampDiff( h->lastReturnedTs, dataUnit->timeStamp ), 0 ) ) + test(); + IF( h->firstDataUnitPopped && JB4_rtpTimeStampDiff( h->lastReturnedTs, dataUnit->timeStamp ) <= 0 ) { JB4_FreeDataUnit( h, dataUnit ); return 0; @@ -537,7 +560,10 @@ Word16 JB4_PushDataUnit( /* drop partial copy if the missing frame was already concealed */ IF( h->firstDataUnitPopped ) { - IF( LE_16( dataUnit->partialCopyOffset, 3 ) && LT_32( JB4_rtpTimeStampDiff( h->nextExpectedTs, dataUnit->timeStamp ), 0 ) ) + test(); + test(); + test(); + IF( LE_16( dataUnit->partialCopyOffset, 3 ) && JB4_rtpTimeStampDiff( h->nextExpectedTs, dataUnit->timeStamp ) < 0 ) { JB4_FreeDataUnit( h, dataUnit ); return 0; @@ -555,7 +581,7 @@ Word16 JB4_PushDataUnit( } /* try to store partial copy - will be dropped if primary copy already available */ - IF( EQ_16( JB4_INPUTBUFFER_Enque( h->inputBuffer, dataUnit, (void **) &droppedDataUnit ), 0 ) ) + IF( JB4_INPUTBUFFER_Enque( h->inputBuffer, dataUnit, (void **) &droppedDataUnit ) == 0 ) { /* partial copy is useful, consider it in long-term jitter estimation */ IF( LE_16( dataUnit->partialCopyOffset, 3 ) ) @@ -578,13 +604,16 @@ Word16 JB4_PushDataUnit( JB4_JMF_PushPacket( h->ltJmf, rcvTime, dataUnit->timeStamp ); JB4_estimateShortTermJitter( h, rcvTime, dataUnit->timeStamp ); /* check for "real" late loss: a frame with higher/same timestamp was already returned to be fed into decoder */ + test(); IF( h->firstDataUnitPopped && JB4_rtpTimeStampDiff( h->lastReturnedTs, dataUnit->timeStamp ) <= 0 ) { IF( !dataUnit->silenceIndicator ) { - ++h->nLateLost; + h->nLateLost = (UWord32) W_add( h->nLateLost, 1 ); + move32(); /* deletion of a speech frame because it arrived at the JBM too late */ - ++h->jitterInducedConcealments; + h->jitterInducedConcealments = (UWord32) W_add( h->jitterInducedConcealments, 1 ); + move32(); } JB4_FreeDataUnit( h, dataUnit ); return 0; @@ -635,9 +664,10 @@ Word16 JB4_PopDataUnit( Word16 ret; assert( sysTime >= h->prevPopSysTime ); - IF( sysTime > h->prevPopSysTime + 20 ) + if ( GT_64( sysTime, W_add( h->prevPopSysTime, 20 ) ) ) { - h->lastPlayoutOffset += 20; + h->lastPlayoutOffset = L_add( h->lastPlayoutOffset, 20 ); + move32(); } h->prevPopSysTime = sysTime; move32(); @@ -655,8 +685,7 @@ static Word32 JB4_rtpTimeStampDiff( { Word32 ret; /* do not dare to inline this function, casting to Word32 is important here! */ - ret = (Word32) ( tsB - tsA ); - move32(); + ret = W_extract_l( W_sub( tsB, tsA ) ); return ret; } @@ -690,6 +719,7 @@ static void JB4_targetPlayoutDelay( move32(); h->rfDelay = 0; move32(); + test(); IF( h->rfOffset7Active != 0 ) { h->rfDelay = 140; @@ -711,26 +741,25 @@ static void JB4_targetPlayoutDelay( IF( JB4_JMF_Jitter( h->ltJmf, <Jitter ) == 0 ) { /* combine long term and short term jitter to calculate target delay values */ - *targetMax = h->stJitter + h->safetyMargin + h->rfDelay; - *targetMin = JB4_MIN( ltJitter + 20 + h->rfDelay + extraDelayReserve, *targetMax ); - move32(); - *targetDtx = JB4_MIN( ltJitter + extraDelayReserve, h->stJitter ); - move32(); - *targetStartUp = ( *targetMin + *targetMax + extraDelayReserve / 4 ) / 2; + *targetMax = (UWord32) W_add( h->stJitter, W_add( h->safetyMargin, h->rfDelay ) ); + *targetMin = JB4_MIN( (UWord32) W_add( W_add( ltJitter, 20 ), W_add( h->rfDelay, extraDelayReserve ) ), *targetMax ); + *targetDtx = JB4_MIN( (UWord32) W_add( ltJitter, extraDelayReserve ), h->stJitter ); + *targetStartUp = (UWord32) W_shr( W_add( W_add( *targetMin, *targetMax ), W_shr( extraDelayReserve, 2 ) /*extraDelayReserve / 4*/ ), 1 ); } ELSE { /* combine long term and short term jitter to calculate target delay values */ *targetMax = h->safetyMargin; - move32(); *targetMin = JB4_MIN( 20, *targetMax ); - move32(); *targetDtx = 0; - move32(); - *targetStartUp = ( *targetMin + *targetMax ) / 2; + *targetStartUp = (UWord32) W_shr( W_add( *targetMin, *targetMax ), 1 ); } + move32(); + move32(); + move32(); + move32(); - IF( *targetStartUp < 60 ) + if ( LT_64( *targetStartUp, 60 ) ) { *targetStartUp = 60; move32(); @@ -783,16 +812,20 @@ static Word16 JB4_adaptPlayout( *pDataUnit = NULL; IF( h->firstDataUnitPopped ) { - ++h->nUnavailablePopped; + h->nUnavailablePopped = (UWord32) W_add( h->nUnavailablePopped, 1 ); + move32(); IF( !h->lastPoppedWasSilence ) { - ++h->nStretched; + h->nStretched = (UWord32) W_add( h->nStretched, 1 ); + move32(); /* jitter-induced insertion (e.g. buffer underflow) */ - ++h->jitterInducedConcealments; + h->jitterInducedConcealments = (UWord32) W_add( h->jitterInducedConcealments, 1 ); + move32(); } } /* add one frame to last playout delay */ - h->lastPlayoutOffset += h->frameDuration; + h->lastPlayoutOffset = L_add( h->lastPlayoutOffset, (Word32) h->frameDuration ); + move32(); } ELSE { @@ -823,10 +856,13 @@ static void JB4_adaptActivePlayout( { return; } - h->targetPlayoutDelay = ( targetMin + targetMax ) / 2; + h->targetPlayoutDelay = (UWord32) W_shr( W_add( targetMin, targetMax ), 1 ); + move32(); convertToLateLoss = false; dropEarly = false; + move16(); + move16(); dropGapMax = 200; move32(); dropRateMin = 5; @@ -835,7 +871,7 @@ static void JB4_adaptActivePlayout( move32(); /* calculate current playout delay */ - currPlayoutDelay = h->lastPlayoutOffset - minOffTicks + extBufferedTime; + currPlayoutDelay = (UWord32) W_add( W_sub( h->lastPlayoutOffset, minOffTicks ), extBufferedTime ); IF( !JB4_INPUTBUFFER_IsEmpty( h->inputBuffer ) ) { nextDataUnit = (JB4_DATAUNIT_HANDLE) JB4_INPUTBUFFER_Front( h->inputBuffer ); @@ -843,22 +879,26 @@ static void JB4_adaptActivePlayout( IF( tsDiffToNextDataUnit < 0 ) { convertToLateLoss = true; + move16(); /* time stretching is expected -> increase playout delay to allow dropping the late frame */ - currPlayoutDelay -= tsDiffToNextDataUnit; - currPlayoutDelay += 1; + currPlayoutDelay = (UWord32) W_sub( currPlayoutDelay, tsDiffToNextDataUnit ); + currPlayoutDelay = (UWord32) ( W_add( currPlayoutDelay, 1 ) ); } } /* decided between shrinking/stretching */ - IF( currPlayoutDelay > targetMax ) /* time shrinking */ + IF( GT_64( currPlayoutDelay, targetMax ) ) /* time shrinking */ { - gap = currPlayoutDelay - h->targetPlayoutDelay; + gap = (UWord32) W_sub( currPlayoutDelay, h->targetPlayoutDelay ); /* check if gap is positive and dropping is allowed * and buffer contains enough time (ignoring one frame) */ + test(); + test(); + test(); IF( gap > 0 && JB4_inspectBufferForDropping( h, &dropEarly, &buffered ) == 0 && ( convertToLateLoss || - ( buffered + h->frameDuration + extBufferedTime ) > targetMax ) ) + GT_64( W_add( buffered, W_add( h->frameDuration, extBufferedTime ) ), targetMax ) ) ) { IF( convertToLateLoss ) { @@ -867,6 +907,7 @@ static void JB4_adaptActivePlayout( #else JB4_dropFromBuffer( h ); h->nLostOrStretched = L_add( h->nLostOrStretched, 1 ); + move32(); #endif } ELSE IF( dropEarly ) @@ -880,12 +921,21 @@ static void JB4_adaptActivePlayout( } ELSE { + Word16 exp; + Word32 temp = BASOP_Util_Divide3232_Scale_cadence( W_extract_l( W_sub( dropRateMax, dropRateMin ) ), W_extract_l( dropGapMax ), &exp ); /* limit gap to [gapMin,gapMax] and calculate current drop rate from gap */ - rate = JB4_MIN( (UWord32) ( gap ), dropGapMax ) * - ( dropRateMax - dropRateMin ) / dropGapMax + - dropRateMin; - *scale = ( 1000 - rate ) / 10; - *maxScaling = currPlayoutDelay - targetMax; + Word64 temp2 = W_mult0_32_32( W_extract_l( JB4_MIN( gap, dropGapMax ) ), temp ); + Word64 temp3 = W_shr( temp2, 31 - exp ); + Word64 diff = W_sub( W_shl( temp3 + 1, 31 - exp ), temp2 ); + if ( LE_64( diff, 21 ) ) + { + temp3 = W_add( temp3, 1 ); + } + rate = (UWord32) W_add( temp3, dropRateMin ); + *scale = idiv1616( sub( 1000, (Word16) rate ), 10 ); + *maxScaling = (UWord32) W_sub( currPlayoutDelay, targetMax ); + move32(); + move32(); } } } @@ -895,14 +945,17 @@ static void JB4_adaptActivePlayout( /* Stretching only makes sense if we win one additional frame in the input buffer. * If too much additional delay would be required to do so, then do not scale. * Also make sure that the delay doesn't increase too much. */ - delayWithClearedExternalBuffer = currPlayoutDelay - extBufferedTime + h->frameDuration; - targetMaxStretch = targetMax - h->frameDuration; - IF( delayWithClearedExternalBuffer + h->frameDuration <= targetMaxStretch && - currPlayoutDelay < targetMaxStretch && currPlayoutDelay < (UWord32) ( 110 + h->rfDelay / 4 ) ) + delayWithClearedExternalBuffer = (UWord32) W_add( W_sub( currPlayoutDelay, extBufferedTime ), h->frameDuration ); + targetMaxStretch = (UWord32) W_sub( targetMax, h->frameDuration ); + test(); + test(); + IF( LE_64( W_add( delayWithClearedExternalBuffer, h->frameDuration ), targetMaxStretch ) && + LT_64( currPlayoutDelay, targetMaxStretch ) && LT_64( currPlayoutDelay, L_add( 110, L_shr( h->rfDelay, 2 ) ) ) ) { *scale = 120; move32(); - *maxScaling = targetMaxStretch - currPlayoutDelay; + *maxScaling = (UWord32) W_sub( targetMaxStretch, currPlayoutDelay ); + move32(); } } @@ -929,7 +982,7 @@ static void JB4_adaptDtxPlayout( } /* calculate current playout delay */ - currPlayoutDelay = h->lastPlayoutOffset - minOffTicks; + currPlayoutDelay = L_sub( h->lastPlayoutOffset, minOffTicks ); /* check for startup after DTX */ IF( !JB4_INPUTBUFFER_IsEmpty( h->inputBuffer ) ) @@ -940,35 +993,36 @@ static void JB4_adaptDtxPlayout( tsDiffToNextDataUnit = JB4_rtpTimeStampDiff( h->nextExpectedTs, firstTs ); /* check if the next available data unit should already be used (time stamp order) */ - IF( GT_32( tsDiffToNextDataUnit, 0 ) ) + IF( tsDiffToNextDataUnit > 0 ) { /* time stretching is expected -> increase playout delay */ - currPlayoutDelay += tsDiffToNextDataUnit; + currPlayoutDelay = (UWord32) W_add( currPlayoutDelay, tsDiffToNextDataUnit ); } IF( !firstDu->silenceIndicator ) { /* recalculate playout delay based on first buffered data unit */ JB4_playoutDelay( h, sysTime, firstTs, &currPlayoutDelay ); /* check if the next available data unit should already be used (time stamp order) */ - IF( GT_32( tsDiffToNextDataUnit, 0 ) ) + IF( tsDiffToNextDataUnit > 0 ) { /* time stretching is expected -> increase playout delay */ - currPlayoutDelay += tsDiffToNextDataUnit; + currPlayoutDelay = (UWord32) W_add( currPlayoutDelay, tsDiffToNextDataUnit ); } h->targetPlayoutDelay = targetStartUp; move32(); - headRoom = 600 * h->frameDuration / 1000; + headRoom = (UWord32) W_mult0_32_32( 600, Mult_32_32( W_extract_l( W_shr( h->frameDuration, 1 ) ), INV_500_Q31 ) ); /* decided between shrinking/stretching */ - IF( currPlayoutDelay > targetStartUp + headRoom ) /* time shrinking */ + IF( GT_64( currPlayoutDelay, W_add( targetStartUp, headRoom ) ) ) /* time shrinking */ { IF( JB4_checkDtxDropping( h ) ) { JB4_dropFromBuffer( h ); } } - ELSE IF( currPlayoutDelay + headRoom < targetStartUp ) /* time stretching */ + ELSE IF( LT_64( W_add( currPlayoutDelay, headRoom ), targetStartUp ) ) /* time stretching */ { *stretchTime = true; + move16(); } return; } @@ -976,18 +1030,20 @@ static void JB4_adaptDtxPlayout( /* adapt while DTX */ h->targetPlayoutDelay = targetDtx; + move32(); /* decided between shrinking/stretching */ - IF( currPlayoutDelay >= targetDtx + h->frameDuration ) /* time shrinking */ + IF( GE_64( currPlayoutDelay, W_add( targetDtx, h->frameDuration ) ) ) /* time shrinking */ { IF( JB4_checkDtxDropping( h ) ) { JB4_dropFromBuffer( h ); } } - ELSE IF( currPlayoutDelay + 500 * h->frameDuration / 1000 < targetDtx ) /* time stretching */ + ELSE IF( LT_64( W_add( currPlayoutDelay, W_shr( h->frameDuration, 1 ) ), targetDtx ) ) /* time stretching */ { *stretchTime = true; + move16(); } return; @@ -1006,10 +1062,11 @@ static void JB4_adaptFirstPlayout( IF( JB4_INPUTBUFFER_IsEmpty( h->inputBuffer ) ) { *prebuffer = true; + move16(); return; } JB4_targetPlayoutDelay( h, &targetMin, &targetMax, &targetDtx, &targetStartUp ); - IF( targetStartUp < h->frameDuration ) + IF( LT_64( targetStartUp, h->frameDuration ) ) { return; } @@ -1018,15 +1075,18 @@ static void JB4_adaptFirstPlayout( IF( JB4_playoutDelay( h, sysTime, firstDu->timeStamp, &currPlayoutDelay ) != 0 ) { *prebuffer = true; + move16(); return; } - IF( currPlayoutDelay + h->frameDuration / 2 < targetStartUp ) /* time stretching */ + IF( LT_64( W_add( currPlayoutDelay, W_shr( h->frameDuration, 1 ) ), targetStartUp ) ) /* time stretching */ { *prebuffer = true; + move16(); } ELSE /* no adaptation, start playout */ { *prebuffer = false; + move16(); } return; @@ -1043,11 +1103,12 @@ static Word16 JB4_inspectBufferForDropping( Word32 seqNrDiff; Word32 bufferedTs; UWord32 firstTs; - uint64_t beginTs, endTs; + UWord64 beginTs, endTs; JB4_DATAUNIT_HANDLE firstDu, secondDu, lastDu; assert( !h->lastPoppedWasSilence ); *dropEarly = false; + move16(); *buffered = 0; move16(); inputBufferSize = JB4_INPUTBUFFER_Size( h->inputBuffer ); @@ -1058,27 +1119,29 @@ static Word16 JB4_inspectBufferForDropping( firstDu = (JB4_DATAUNIT_HANDLE) JB4_INPUTBUFFER_Front( h->inputBuffer ); firstTs = firstDu->timeStamp; + move32(); /* check for loss: sequence number diff is exactly 0 in the valid case */ IF( h->firstDataUnitPopped ) { - seqNrDiff = JB4_rtpTimeStampDiff( h->nextExpectedTs, firstTs ) / - (Word32) ( h->frameDuration ); + Word16 temp, exp; + temp = BASOP_Util_Divide3232_Scale( JB4_rtpTimeStampDiff( h->nextExpectedTs, firstTs ), (Word32) ( h->frameDuration ), &exp ); + seqNrDiff = L_shl( temp, sub( exp, 15 ) ); } ELSE { seqNrDiff = 0; move32(); } - IF( LE_32( seqNrDiff, 0 ) ) + IF( seqNrDiff <= 0 ) { /* preview data unit to play after dropping */ - IF( inputBufferSize <= 1U ) + IF( LE_32( inputBufferSize, 1U ) ) { /* data unit to play missing, avoid drop followed by concealment */ return -1; } secondDu = JB4_INPUTBUFFER_Element( h->inputBuffer, 1 ); - IF( firstTs + h->frameDuration != secondDu->timeStamp ) + IF( NE_64( W_add( firstTs, h->frameDuration ), secondDu->timeStamp ) ) { /* data unit to play is not available, avoid drop followed by concealment */ return -1; @@ -1098,31 +1161,33 @@ static Word16 JB4_inspectBufferForDropping( * This is very aggressive: ignores the maximum drop rate (50% drop and 50% concealment for adjacent lost), * but on the other hand, dropping sounds better than concealment. */ *dropEarly = true; + move16(); /* data unit to drop (first one) is lost */ bufferedTs = 0; move32(); } /* add time stamp difference of last and first actually buffered data unit */ - IF( inputBufferSize == 1U ) + IF( EQ_32( inputBufferSize, 1U ) ) { - bufferedTs += h->frameDuration; + bufferedTs = L_add( bufferedTs, (Word32) h->frameDuration ); } ELSE { lastDu = (JB4_DATAUNIT_HANDLE) JB4_INPUTBUFFER_Back( h->inputBuffer ); beginTs = firstTs; - endTs = lastDu->timeStamp + h->frameDuration; + move64(); + endTs = W_add( lastDu->timeStamp, h->frameDuration ); /* check for RTP time stamp wrap around */ - IF( endTs < beginTs ) + if ( LT_64( endTs, beginTs ) ) { - endTs = endTs + 0xFFFFFFFF; + endTs = W_add( endTs, 0xFFFFFFFF ); } - bufferedTs += (Word32) ( endTs - beginTs ); + bufferedTs = L_add( bufferedTs, W_extract_l( W_sub( endTs, beginTs ) ) ); } /* the result should not be negative */ - IF( LT_32( bufferedTs, 0 ) ) + IF( bufferedTs < 0 ) { return -1; } @@ -1152,9 +1217,11 @@ static Word16 JB4_checkDtxDropping( { firstDu = (JB4_DATAUNIT_HANDLE) JB4_INPUTBUFFER_Front( h->inputBuffer ); /* check for loss: sequence number diff is exactly 0 in the valid case */ - seqNrDiff = JB4_rtpTimeStampDiff( h->nextExpectedTs, firstDu->timeStamp ) / - (Word32) ( h->frameDuration ); - IF( LE_32( seqNrDiff, 0 ) ) + Word16 temp, exp; + temp = BASOP_Util_Divide3232_Scale( JB4_rtpTimeStampDiff( h->nextExpectedTs, firstDu->timeStamp ), + (Word32) ( h->frameDuration ), &exp ); + seqNrDiff = L_shl( temp, exp - 15 ); + if ( seqNrDiff <= 0 ) { /* no not drop first active frame */ droppingAllowed = 0; @@ -1178,15 +1245,16 @@ static void JB4_estimateShortTermJitter( JB4_CIRCULARBUFFER_ELEMENT maxElement, dequedElement; jitter = 0; + move32(); JB4_JMF_PushPacket( h->stJmf, rcvTime, rtpTimeStamp ); /* save delta delay */ - IF( EQ_16( JB4_JMF_Jitter( h->stJmf, &jitter ), 0 ) ) + IF( JB4_JMF_Jitter( h->stJmf, &jitter ) == 0 ) { /* compensate difference between both offsets */ Word32 stOffset, ltOffset; JB4_JMF_MinOffset( h->stJmf, &stOffset ); JB4_JMF_MinOffset( h->ltJmf, <Offset ); - jitter += stOffset - ltOffset; + jitter = (UWord32) W_add( jitter, W_sub( stOffset, ltOffset ) ); assert( (Word16) jitter >= 0 ); IF( JB4_CIRCULARBUFFER_IsFull( h->stJitterFifo ) ) { @@ -1199,11 +1267,11 @@ static void JB4_estimateShortTermJitter( /* check for duration and discard first entries if too long */ minTime = JB4_CIRCULARBUFFER_Front( h->stTimeStampFifo ); maxTime = JB4_CIRCULARBUFFER_Back( h->stTimeStampFifo ); - IF( maxTime > minTime ) + IF( GT_32( maxTime, minTime ) ) { - duration = maxTime - minTime; - maxDuration = 4 * h->timeScale; - WHILE( duration > maxDuration ) + duration = (UWord32) W_sub( maxTime, minTime ); + maxDuration = (UWord32) W_shl( h->timeScale, 2 ); + WHILE( GT_64( duration, maxDuration ) ) { JB4_CIRCULARBUFFER_Deque( h->stJitterFifo, &dequedElement ); JB4_CIRCULARBUFFER_Deque( h->stTimeStampFifo, &dequedElement ); @@ -1212,7 +1280,7 @@ static void JB4_estimateShortTermJitter( { BREAK; } - duration = maxTime - minTime; + duration = (UWord32) W_sub( maxTime, minTime ); } } } @@ -1222,8 +1290,21 @@ static void JB4_estimateShortTermJitter( { JB4_CIRCULARBUFFER_Max( h->stJitterFifo, &maxElement ); /* round up to full frame duration */ - h->stJitter = (UWord32) ceil( (double) ( maxElement ) / h->frameDuration ) * - h->frameDuration; + Word16 exp; + Word32 temp; + temp = BASOP_Util_Divide3232_Scale( maxElement, (Word32) h->frameDuration, &exp ); + IF( exp < 0 ) + { + temp = L_shl( temp, exp ); + exp = 0; + move16(); + } + IF( temp != 0 ) + { + temp = L_shr( ceil_fixed( temp, 15 - exp ), 15 - exp ); + } + h->stJitter = (UWord32) W_mult0_32_32( temp, h->frameDuration ); + move32(); } return; @@ -1253,15 +1334,19 @@ static void JB4_popFromBuffer( { /* no data unit available */ *pDataUnit = NULL; - h->nextExpectedTs += h->frameDuration; + h->nextExpectedTs = (UWord32) W_add( h->nextExpectedTs, h->frameDuration ); + move32(); IF( h->lastPoppedWasSilence ) { - ++h->nComfortNoice; + h->nComfortNoice = (UWord32) W_add( h->nComfortNoice, 1 ); + move32(); } ELSE { - ++h->nUnavailablePopped; - ++h->nLostOrStretched; + h->nUnavailablePopped = (UWord32) W_add( h->nUnavailablePopped, 1 ); + h->nLostOrStretched = (UWord32) W_add( h->nLostOrStretched, 1 ); + move32(); + move32(); } return; @@ -1277,13 +1362,16 @@ static void JB4_popFromBuffer( /* adjust sequence numbers to avoid handling first packet as loss */ h->nextExpectedTs = nextDataUnit->timeStamp; move16(); + move32(); } /* check if the next available data unit should already be used (time stamp order) */ tsDiff = JB4_rtpTimeStampDiff( nextDataUnit->timeStamp, h->nextExpectedTs ); - h->totWin += 1; - IF( ( h->totWin > 3000 ) || ( h->FecOffWinLen > 100 ) ) + h->totWin = (UWord32) W_add( h->totWin, 1 ); + move32(); + test(); + IF( GT_64( h->totWin, 3000 ) || GT_64( h->FecOffWinLen, 100 ) ) { maxval = h->FecOffWin[1]; move16(); @@ -1291,7 +1379,7 @@ static void JB4_popFromBuffer( move16(); FOR( i = 2; i < MAXOFFSET; i++ ) { - IF( h->FecOffWin[i] > maxval ) + IF( GT_64( h->FecOffWin[i], maxval ) ) { maxval = h->FecOffWin[i]; move16(); @@ -1311,12 +1399,15 @@ static void JB4_popFromBuffer( move32(); - lost = h->nLost + h->nPartialCopiesUsed - h->last_nLost; - total_rec = h->nAvailablePopped + h->nUnavailablePopped - h->last_ntot; + lost = W_extract_l( W_add( h->nLost, W_sub( h->nPartialCopiesUsed, h->last_nLost ) ) ); + total_rec = W_extract_l( W_add( h->nAvailablePopped, W_sub( h->nUnavailablePopped, h->last_ntot ) ) ); + test(); IF( lost != 0 && total_rec != 0 ) { - h->netLossRate_fx = (Word32) ( lost / (float) total_rec ); + Word16 temp, exp; + temp = BASOP_Util_Divide3232_Scale( lost, total_rec, &exp ); + h->netLossRate_fx = L_shr( temp, sub( 15, exp ) ); h->netLossRate = (float) lost / (float) total_rec; } ELSE @@ -1324,42 +1415,52 @@ static void JB4_popFromBuffer( h->netLossRate_fx = 0; h->netLossRate = 0.0f; } + move32(); h->last_nLost = L_add( h->nLost, h->nPartialCopiesUsed ); h->last_ntot = L_add( h->nAvailablePopped, h->nUnavailablePopped ); + move32(); + move32(); } - IF( LT_32( tsDiff, 0 ) ) + IF( tsDiff < 0 ) { readlen = JB4_INPUTBUFFER_Size( h->inputBuffer ); FOR( i = 0; i < readlen; i++ ) { tempDataUnit = (JB4_DATAUNIT_HANDLE) JB4_INPUTBUFFER_Element( h->inputBuffer, i ); + test(); IF( !tempDataUnit->partial_frame && !h->lastPoppedWasSilence ) { - frameoffset = (Word16) ( JB4_rtpTimeStampDiff( h->nextExpectedTs, tempDataUnit->timeStamp ) / 20 ); - - IF( GT_16( frameoffset, 0 ) && LT_16( frameoffset, MAXOFFSET ) ) + frameoffset = extract_l( Mult_32_16( JB4_rtpTimeStampDiff( h->nextExpectedTs, tempDataUnit->timeStamp ), INV_20_Q15 ) ); + test(); + IF( frameoffset > 0 && LT_16( frameoffset, MAXOFFSET ) ) { - h->FecOffWin[frameoffset] += 1; + h->FecOffWin[frameoffset] = W_extract_l( W_add( h->FecOffWin[frameoffset], 1 ) ); + move32(); } } } - h->FecOffWinLen += 1; + h->FecOffWinLen = (UWord32) W_add( h->FecOffWinLen, 1 ); + move32(); /* next expected data unit is missing * -> conceal network loss, do time stretching or create comfort noise */ *pDataUnit = NULL; /* update statistics */ - h->nextExpectedTs += h->frameDuration; + h->nextExpectedTs = (UWord32) W_add( h->nextExpectedTs, h->frameDuration ); + move32(); IF( h->lastPoppedWasSilence ) { - ++h->nComfortNoice; + h->nComfortNoice = (UWord32) W_add( h->nComfortNoice, 1 ); + move32(); } ELSE { - ++h->nUnavailablePopped; - ++h->nLostOrStretched; + h->nUnavailablePopped = (UWord32) W_add( h->nUnavailablePopped, 1 ); + h->nLostOrStretched = (UWord32) W_add( h->nLostOrStretched, 1 ); + move32(); + move32(); } return; } @@ -1367,22 +1468,26 @@ static void JB4_popFromBuffer( /* fetch the next data unit from buffer */ *pDataUnit = nextDataUnit; nextDataUnit->nextCoderType = INACTIVE; + move16(); + test(); IF( h->pre_partial_frame || nextDataUnit->partial_frame ) { IF( nextDataUnit->partial_frame ) { h->pre_partial_frame = 1; + move16(); } ELSE IF( h->pre_partial_frame ) { h->pre_partial_frame = 0; + move16(); } endpos = JB4_INPUTBUFFER_Size( h->inputBuffer ); FOR( searchpos = 0; searchpos < endpos; searchpos++ ) { partialCopyDu = (JB4_DATAUNIT_HANDLE) JB4_INPUTBUFFER_Element( h->inputBuffer, searchpos ); - IF( partialCopyDu->timeStamp == nextDataUnit->timeStamp + partialCopyDu->duration ) + IF( EQ_64( partialCopyDu->timeStamp, W_add( nextDataUnit->timeStamp, partialCopyDu->duration ) ) ) { get_NextCoderType( partialCopyDu->data, &nextDataUnit->nextCoderType ); BREAK; @@ -1393,23 +1498,28 @@ static void JB4_popFromBuffer( IF( nextDataUnit->partial_frame ) { - h->nPartialCopiesUsed += 1; + h->nPartialCopiesUsed = L_add( h->nPartialCopiesUsed, 1 ); + move32(); readlen = JB4_INPUTBUFFER_Size( h->inputBuffer ); FOR( i = 0; i < readlen; i++ ) { tempDataUnit = (JB4_DATAUNIT_HANDLE) JB4_INPUTBUFFER_Element( h->inputBuffer, i ); + test(); IF( !tempDataUnit->partial_frame && !h->lastPoppedWasSilence ) { - frameoffset = (Word16) ( JB4_rtpTimeStampDiff( h->nextExpectedTs, tempDataUnit->timeStamp ) / 20 ); + frameoffset = extract_l( Mult_32_16( JB4_rtpTimeStampDiff( h->nextExpectedTs, tempDataUnit->timeStamp ), INV_20_Q15 ) ); - IF( frameoffset > 0 && frameoffset < MAXOFFSET ) + test(); + IF( ( frameoffset > 0 ) && LT_16( frameoffset, MAXOFFSET ) ) { - h->FecOffWin[frameoffset] += 1; + h->FecOffWin[frameoffset] = (UWord32) W_add( h->FecOffWin[frameoffset], 1 ); + move32(); } } } - h->FecOffWinLen += 1; + h->FecOffWinLen = (UWord32) W_add( h->FecOffWinLen, 1 ); + move32(); } /* update statistics */ @@ -1417,26 +1527,38 @@ static void JB4_popFromBuffer( { assert( h->lastPoppedWasSilence == false ); /* separate concealments since last available pop in lost and stretched */ - nStretched = tsDiff / h->frameDuration; + Word16 exp; + nStretched = BASOP_Util_Divide3232_Scale( tsDiff, h->frameDuration, &exp ); + nStretched = (UWord32) W_shr( nStretched, 15 - exp ); assert( h->nLostOrStretched >= nStretched ); - h->nLost += h->nLostOrStretched - nStretched; + h->nLost = (UWord32) W_add( h->nLost, W_sub( h->nLostOrStretched, nStretched ) ); /* jitter-induced insertion (e.g. buffer underflow) */ - h->jitterInducedConcealments += nStretched; - h->nStretched += nStretched; + h->jitterInducedConcealments = (UWord32) W_add( h->jitterInducedConcealments, nStretched ); + h->nStretched = (UWord32) W_add( h->nStretched, nStretched ); h->nLostOrStretched = 0; + move32(); + move32(); + move32(); + move32(); } h->lastReturnedTs = nextDataUnit->timeStamp; + move32(); JB4_updateLastTimingMembers( h, sysTime, nextDataUnit->timeStamp ); - h->nextExpectedTs = nextDataUnit->timeStamp + h->frameDuration; + h->nextExpectedTs = (UWord32) W_add( nextDataUnit->timeStamp, h->frameDuration ); + move32(); IF( nextDataUnit->silenceIndicator ) { h->lastPoppedWasSilence = true; - ++h->nComfortNoice; + move16(); + h->nComfortNoice = (UWord32) W_add( h->nComfortNoice, 1 ); + move32(); } ELSE { h->lastPoppedWasSilence = false; - ++h->nAvailablePopped; + move16(); + h->nAvailablePopped = (UWord32) W_add( h->nAvailablePopped, 1 ); + move32(); } return; @@ -1462,6 +1584,7 @@ static void JB4_dropFromBuffer( IF( !h->firstDataUnitPopped ) { h->firstDataUnitPopped = true; + move16(); /* adjust sequence numbers to avoid handling first packet as loss */ h->nextExpectedTs = nextDataUnit->timeStamp; move32(); @@ -1469,23 +1592,29 @@ static void JB4_dropFromBuffer( /* check if the next available data unit should already be used (time stamp order) */ tsDiff = JB4_rtpTimeStampDiff( nextDataUnit->timeStamp, h->nextExpectedTs ); - IF( LT_32( tsDiff, 0 ) ) + IF( tsDiff < 0 ) { /* next expected data unit is missing, remember this data unit as popped, * but do not count it as lost, because it will not be concealed */ - h->nextExpectedTs += h->frameDuration; + h->nextExpectedTs = (UWord32) W_add( h->nextExpectedTs, h->frameDuration ); + move32(); /* substract one frame from last playout delay */ - h->lastPlayoutOffset -= h->frameDuration; + h->lastPlayoutOffset = (UWord32) W_sub( h->lastPlayoutOffset, h->frameDuration ); + move32(); IF( !h->lastPoppedWasSilence ) { - ++h->nShrinked; + h->nShrinked = (UWord32) W_add( h->nShrinked, 1 ); /* modification of the output timeline due to link loss */ - ++h->nUnavailablePopped; - ++h->nLostOrStretched; + h->nUnavailablePopped = (UWord32) W_add( h->nUnavailablePopped, 1 ); + h->nLostOrStretched = (UWord32) W_add( h->nLostOrStretched, 1 ); + move32(); + move32(); + move32(); } IF( h->lastTargetTime != 0U ) { - h->lastTargetTime += h->frameDuration; + h->lastTargetTime = (UWord32) W_add( h->lastTargetTime, h->frameDuration ); + move32(); } return; } @@ -1497,32 +1626,43 @@ static void JB4_dropFromBuffer( { assert( h->lastPoppedWasSilence == false ); /* separate concealments since last available pop in lost and stretched */ - nStretched = tsDiff / h->frameDuration; + Word16 exp; + nStretched = BASOP_Util_Divide3232_Scale( tsDiff, (Word32) h->frameDuration, &exp ); + nStretched = (UWord32) W_shr( nStretched, 15 - exp ); assert( h->nLostOrStretched >= nStretched ); /* convert stretching followed by shrinking to late-loss */ IF( nStretched > 0U ) { - --nStretched; - ++h->nLateLost; - h->nLost += h->nLostOrStretched - nStretched; + nStretched = (UWord32) W_sub( nStretched, 1 ); + h->nLateLost = (UWord32) W_add( h->nLateLost, 1 ); + h->nLost = (UWord32) W_add( h->nLost, W_sub( h->nLostOrStretched, nStretched ) ); /* jitter-induced insertion (e.g. buffer underflow) */ - h->jitterInducedConcealments += nStretched; - IF( !dataUnit->silenceIndicator ) + h->jitterInducedConcealments = (UWord32) W_add( h->jitterInducedConcealments, nStretched ); + move32(); + move32(); + move32(); + move32(); + if ( !dataUnit->silenceIndicator ) { /* JBM induced removal of a speech frame (intentional frame dropping) */ - ++h->jitterInducedConcealments; + h->jitterInducedConcealments = (UWord32) W_add( h->jitterInducedConcealments, 1 ); + move32(); } - h->nStretched += nStretched; + h->nStretched = (UWord32) W_add( h->nStretched, nStretched ); + move32(); } ELSE { - h->nLost += h->nLostOrStretched; - ++h->nShrinked; + h->nLost = (UWord32) W_add( h->nLost, h->nLostOrStretched ); + h->nShrinked = (UWord32) W_add( h->nShrinked, 1 ); + move32(); + move32(); IF( !dataUnit->silenceIndicator ) { /* JBM induced removal of a speech frame (intentional frame dropping) */ - ++h->jitterInducedConcealments; + h->jitterInducedConcealments = (UWord32) W_add( h->jitterInducedConcealments, 1 ); + move32(); } } h->nLostOrStretched = 0; @@ -1532,22 +1672,29 @@ static void JB4_dropFromBuffer( { IF( !dataUnit->silenceIndicator ) { - ++h->nShrinked; + h->nShrinked = (UWord32) W_add( h->nShrinked, 1 ); /* JBM induced removal of a speech frame (intentional frame dropping) */ - ++h->jitterInducedConcealments; + h->jitterInducedConcealments = (UWord32) W_add( h->jitterInducedConcealments, 1 ); + move32(); + move32(); } } h->lastReturnedTs = dataUnit->timeStamp; move32(); h->lastPoppedWasSilence = dataUnit->silenceIndicator; - h->nextExpectedTs = dataUnit->timeStamp + h->frameDuration; + move16(); + h->nextExpectedTs = (UWord32) W_add( dataUnit->timeStamp, h->frameDuration ); move32(); /* substract one frame from last playout delay */ - h->lastPlayoutOffset -= h->frameDuration; + h->lastPlayoutOffset = L_sub( h->lastPlayoutOffset, (Word32) h->frameDuration ); + move32(); IF( h->lastTargetTime != 0U ) - h->lastTargetTime += h->frameDuration; + { + h->lastTargetTime = (UWord32) W_add( h->lastTargetTime, h->frameDuration ); + move32(); + } JB4_FreeDataUnit( h, dataUnit ); @@ -1564,12 +1711,13 @@ static Word16 JB4_playoutDelay( { Word32 minOffTicks; - IF( NE_16( JB4_JMF_MinOffset( h->ltJmf, &minOffTicks ), 0 ) ) + IF( JB4_JMF_MinOffset( h->ltJmf, &minOffTicks ) != 0 ) { return -1; } - *delay = playTime - minOffTicks - rtpTimeStamp; + *delay = (UWord32) W_sub( W_sub( playTime, minOffTicks ), rtpTimeStamp ); + move32(); return 0; } @@ -1589,9 +1737,11 @@ static void JB4_updateLastTimingMembers( } /* playoutDelay = playTime - minOffset - timeStamp */ - h->lastPlayoutOffset = playTime - rtpTimeStamp; + h->lastPlayoutOffset = (UWord32) W_sub( playTime, rtpTimeStamp ); + move32(); /* targetTime = minOffset + timeStamp + targetDelay */ - h->lastTargetTime = (UWord32) ( minOffTicks + rtpTimeStamp + h->targetPlayoutDelay ); + h->lastTargetTime = (UWord32) ( W_add( minOffTicks, W_add( rtpTimeStamp, h->targetPlayoutDelay ) ) ); + move32(); return; } @@ -1616,7 +1766,7 @@ static Word16 JB4_inputBufferCompareFunction( result = 1; move16(); } - ELSE IF( LT_32( diff, 0 ) ) + ELSE IF( diff < 0 ) { result = -1; move16(); @@ -1625,15 +1775,19 @@ static Word16 JB4_inputBufferCompareFunction( { result = 0; move16(); - IF( newDataUnit->partial_frame == 0 && arrayDataUnit->partial_frame == 1 ) + test(); + test(); + IF( newDataUnit->partial_frame == 0 && EQ_16( arrayDataUnit->partial_frame, 1 ) ) { /* replace partial copy with primary copy */ *replaceWithNewElementIfEqual = 1; + move16(); } - ELSE IF( newDataUnit->partial_frame == arrayDataUnit->partial_frame && newDataUnit->dataSize > arrayDataUnit->dataSize ) + ELSE IF( EQ_16( newDataUnit->partial_frame, arrayDataUnit->partial_frame ) && GT_32( newDataUnit->dataSize, arrayDataUnit->dataSize ) ) { /* if both are primary or partial: take the one with higher size (e.g. higher bitrate) */ *replaceWithNewElementIfEqual = 1; + move16(); } } @@ -3115,4 +3269,4 @@ static int16_t JB4_inputBufferCompareFunction( } #endif /* IVAS_FLOAT_FIXED */ -#undef WMC_TOOL_SKIP +#undef WMC_TOOL_SKIP \ No newline at end of file diff --git a/lib_dec/jbm_pcmdsp_apa.c b/lib_dec/jbm_pcmdsp_apa.c index e2596d3f6..cc0703cb0 100644 --- a/lib_dec/jbm_pcmdsp_apa.c +++ b/lib_dec/jbm_pcmdsp_apa.c @@ -55,6 +55,9 @@ #ifdef IVAS_FLOAT_FIXED #include "prot_fx2.h" +#define INV_100_Q15 328 +#define INV_400_Q15 82 +#define INV_80_Q15 410 #define IVAS_FLOAT_FIXED_TO_BE_REMOVED #endif @@ -216,7 +219,8 @@ ivas_error apa_init( ps->num_channels = (UWord16) num_channels; move16(); - ps->buf_out_capacity = (UWord16) ( APA_BUF_PER_CHANNEL * num_channels ); + ps->buf_out_capacity = (UWord16) L_mult0( APA_BUF_PER_CHANNEL, (Word16) num_channels ); + move16(); #ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED IF( ( ps->buf_out = malloc( sizeof( float ) * ps->buf_out_capacity ) ) == NULL ) @@ -231,6 +235,7 @@ ivas_error apa_init( } ps->evs_compat_mode = false; + move16(); apa_reset( ps ); *pps = ps; @@ -364,15 +369,17 @@ void apa_reset( #endif #ifdef IVAS_FLOAT_FIXED -uint8_t apa_reconfigure( +UWord8 apa_reconfigure( apa_state_t *ps, - uint16_t num_channels, - uint16_t l_ts ) + UWord16 num_channels, + UWord16 l_ts ) { /* realloc buffer */ - ps->num_channels = (uint16_t) num_channels; - ps->buf_out_capacity = (uint16_t) ( APA_BUF_PER_CHANNEL * num_channels ); + ps->num_channels = (UWord16) num_channels; + move16(); + ps->buf_out_capacity = (UWord16) L_mult0( APA_BUF_PER_CHANNEL, (Word16) num_channels ); + move16(); #ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED free( ps->buf_out ); @@ -392,28 +399,35 @@ uint8_t apa_reconfigure( ps->l_buf_out = 0; ps->l_in_total = 0; - ps->l_ts = ps->num_channels * l_ts; + move16(); + move32(); + ps->l_ts = (UWord16) imult3216( l_ts, ps->num_channels ); + move16(); /* set everything else dependent on the number of channels */ /* set segment size */ /* in the order of a pitch, set to 160 samples at 16 kHz */ /* used for windowing and as the correlation length, i.e., */ /* the size of the template segment. */ - ps->l_seg = ( ps->rate / 100 ) * ps->num_channels; + ps->l_seg = (UWord16) imult3216( Mult_32_16( ps->rate, INV_100_Q15 ), (Word16) ps->num_channels ); + move16(); /* set frame size */ /* set to 320 samples at 16 kHz */ - ps->l_frm = ( ps->rate / FRAMES_PER_SEC ) * ps->num_channels; + ps->l_frm = (UWord16) imult3216( Mult_32_16( ps->rate, INV_FRAME_PER_SEC_Q15 ), (Word16) ps->num_channels ); + move16(); /* set minimum pitch */ /* set to 40 samples at 16 kHz */ /* (defines min change in number of samples, i.e., abs(l_in-l_out) >= p_min) */ - ps->p_min = ( ps->rate / 400 ) * ps->num_channels; + ps->p_min = (UWord16) imult3216( Mult_32_16( ps->rate, INV_400_Q15 ), (Word16) ps->num_channels ); + move16(); /* set search length */ /* must cover one pitch, set to 200 samples at 16 kHz */ /* (the resulting maximum pitch is then p_min+l_search = 240 samples at 16 kHz) */ - ps->l_search = ( ps->rate / 80 ) * ps->num_channels; + ps->l_search = (UWord16) imult3216( Mult_32_16( ps->rate, INV_80_Q15 ), (Word16) ps->num_channels ); + move16(); return 0; } @@ -465,16 +479,17 @@ uint8_t apa_reconfigure( /* Sets the audio configuration. */ bool apa_set_rate( apa_state_t *ps, - const int32_t output_Fs ) + const Word32 output_Fs ) { /* make sure pointer is valid */ - if ( ps == NULL ) + IF( ps == NULL ) { return 1; } /* check range */ - if ( ( output_Fs < APA_MIN_RATE ) || ( output_Fs > APA_MAX_RATE ) ) + test(); + IF( ( LT_32( output_Fs, APA_MIN_RATE ) ) || ( GT_32( output_Fs, APA_MAX_RATE ) ) ) { return 1; } @@ -483,9 +498,10 @@ bool apa_set_rate( apa_reset( ps ); /* copy rate to state struct */ - ps->rate = (uint16_t) output_Fs; + ps->rate = (UWord16) output_Fs; + move16(); - if ( ps->num_channels > APA_MAX_NUM_CHANNELS ) + IF( GT_32( ps->num_channels, APA_MAX_NUM_CHANNELS ) ) { return 1; } @@ -503,28 +519,34 @@ bool apa_set_rate( /* in the order of a pitch, set to 160 samples at 16 kHz */ /* used for windowing and as the correlation length, i.e., */ /* the size of the template segment. */ - ps->l_seg = ( ps->rate / 100 ) * ps->num_channels; + ps->l_seg = (UWord16) imult3216( Mult_32_16( ps->rate, INV_100_Q15 ), ps->num_channels ); + move16(); /* init Hann window */ /* Note: l_win < APA_BUF_PER_CHANNEL is required */ /* Length of Hann window should be independent of * number of channels - same window applied to all channels */ - ps->l_halfwin = ps->rate / 100; - hannWindow( ps->l_halfwin * 2, ps->win ); + ps->l_halfwin = (UWord16) Mult_32_16( ps->rate, INV_100_Q15 ); + hannWindow( (UWord16) L_shl( ps->l_halfwin, 1 ), ps->win ); + move16(); + move16(); /* set frame size */ /* set to 320 samples at 16 kHz */ - ps->l_frm = ( ps->rate / FRAMES_PER_SEC ) * ps->num_channels; + ps->l_frm = (UWord16) imult3216( ( Mult_32_16( ps->rate, INV_FRAME_PER_SEC_Q15 ) ), ps->num_channels ); + move16(); /* set minimum pitch */ /* set to 40 samples at 16 kHz */ /* (defines min change in number of samples, i.e., abs(l_in-l_out) >= p_min) */ - ps->p_min = ( ps->rate / 400 ) * ps->num_channels; + ps->p_min = (UWord16) imult3216( ( Mult_32_16( ps->rate, INV_400_Q15 ) ), ps->num_channels ); + move16(); /* set search length */ /* must cover one pitch, set to 200 samples at 16 kHz */ /* (the resulting maximum pitch is then p_min+l_search = 240 samples at 16 kHz) */ - ps->l_search = ( ps->rate / 80 ) * ps->num_channels; + ps->l_search = (UWord16) imult3216( Mult_32_16( ps->rate, INV_80_Q15 ), ps->num_channels ); + move16(); #ifdef IVAS_FLOAT_FIXED ps->win_fx = pcmdsp_window_hann_640; @@ -552,11 +574,15 @@ bool apa_set_rate( /* sample rates 8k, 16k & 32k use a Hann window of length of 640, * where 8k and 16k subsample */ if ( EQ_32( ps->rate, 16000 ) ) + { ps->win_incrementor = 2; - move16(); + move16(); + } if ( EQ_32( ps->rate, 8000 ) ) + { ps->win_incrementor = 4; - move16(); + move16(); + } /* set minimum pitch */ /* set to 40 samples at 16 kHz */ @@ -564,6 +590,7 @@ bool apa_set_rate( /* before basop port was originally: ps->p_min = (ps->rate * ps->num_channels) / 400; * but for simplicity can be taken as l_seg / 4 */ ps->signalScaleForCorrelation = getSignalScaleForCorrelation( ps->rate ); + move16(); #endif return 0; } @@ -582,6 +609,7 @@ bool apa_set_scale( } /* check range */ + test(); IF( ( LT_32( (Word32) scale, APA_MIN_SCALE ) ) || GT_32( (Word32) scale, APA_MAX_SCALE ) ) { return 1; @@ -654,7 +682,8 @@ bool apa_set_renderer_granularity( /* copy to state struct */ - ps->l_ts = l_ts * ps->num_channels; + ps->l_ts = (UWord16) imult3216( l_ts, (Word16) ps->num_channels ); + move16(); return 0; } #else @@ -688,7 +717,8 @@ bool apa_set_renderer_residual_samples( /* copy to state struct */ - ps->l_r_buf = l_r_buf * ps->num_channels; + ps->l_r_buf = (UWord16) imult3216( l_r_buf, (Word16) ps->num_channels ); + move16(); return 0; } #else @@ -721,6 +751,7 @@ bool apa_set_evs_compat_mode( } ps->evs_compat_mode = mode; + move16(); return 0; } @@ -812,12 +843,14 @@ bool apa_set_complexity_options( return 1; } - IF( wss == 0 || wss > 1000 ) + test(); + IF( wss == 0 || GT_32( wss, 1000 ) ) { return 1; } - IF( css == 0 || css > 1000 ) + test(); + IF( css == 0 || GT_32( css, 1000 ) ) { return 1; } @@ -875,7 +908,7 @@ bool apa_exit( apa_state_t **pps ) { /* ignore NULL pointer input */ - if ( *pps == NULL ) + IF( *pps == NULL ) { return 0; } @@ -1351,6 +1384,8 @@ static void get_scaling_quality_fx( const apa_state_t *ps, /* increase calculated quality of signals with low energy */ *energydBQ8 = apa_corrEnergy2dB_fx( maxEnergy, shl( ps->signalScaleForCorrelation, 1 ), corr_len ); *qualityQ16 = L_add( *qualityQ16, L_shl( L_deposit_l( apa_getQualityIncreaseForLowEnergy_fx( *energydBQ8 ) ), 8 ) ); + move16(); + move32(); } #endif @@ -1740,6 +1775,7 @@ static Word16 find_synch_fx( apa_state_t *ps, assert( *synch_pos % ps->num_channels == 0 ); *qualityQ16 = L_deposit_l( 0 ); + move32(); get_scaling_quality_fx( ps, in, l_in, offset, corr_len, abs_s( sub( *synch_pos, fixed_pos ) ), energydBQ8, qualityQ16 ); ps->last_pitch = *synch_pos; diff --git a/lib_dec/jbm_pcmdsp_similarityestimation.c b/lib_dec/jbm_pcmdsp_similarityestimation.c index 23f61a2d4..34f882c96 100644 --- a/lib_dec/jbm_pcmdsp_similarityestimation.c +++ b/lib_dec/jbm_pcmdsp_similarityestimation.c @@ -91,7 +91,7 @@ Word32 cross_correlation_subsampled_self_fx( const Word16 *signal, sum = L_deposit_l( 0 ); FOR( i = 0; i < corr_len; i += subsampling ) { - sum = L_mac0( sum, signal[x + i], signal[y + i] ); + sum = L_mac0( sum, signal[add( x, i )], signal[add( y, i )] ); } return sum; @@ -244,6 +244,7 @@ Word16 normalized_cross_correlation_self_fx( const Word16 *signal, cc = 0; move16(); *energy = L_deposit_l( 1 ); + move32(); } return cc; /* Q15 */ @@ -283,7 +284,7 @@ Word32 cross_correlation_self_fx( const Word16 *signal, sum = L_deposit_l( 0 ); FOR( i = 0; i < corr_len; i++ ) { - sum = L_mac0( sum, signal[x + i], signal[y + i] ); + sum = L_mac0( sum, signal[add( x, i )], signal[add( y, i )] ); } return sum; @@ -324,7 +325,7 @@ Word8 isSilence_fx( const Word16 *signal, Word16 len, Word16 segments ) /* check energy of current segment */ /* 20 * log10(energy / 32768 / samplesPerSegment) > -65 * => energy > samplesPerSegment * 10 ^ (-65 / 20) * 32768 */ - IF( GT_32( energy, maxEnergy ) ) + if ( GT_32( energy, maxEnergy ) ) { ret = 0; move16(); diff --git a/lib_dec/jbm_pcmdsp_window.c b/lib_dec/jbm_pcmdsp_window.c index 938d763ed..a9ed3f82c 100644 --- a/lib_dec/jbm_pcmdsp_window.c +++ b/lib_dec/jbm_pcmdsp_window.c @@ -228,6 +228,7 @@ void overlapAddEvs_fx( { /* reset Hann window iterator to beginning (both channels use same window) */ hannIter = 0; + move16(); FOR( i = j; i < n; i += nChannels ) { fdOutVal = L_mult( fadeOut[i], fadeOutWin[hannIter] ); @@ -240,6 +241,7 @@ void overlapAddEvs_fx( combinedVal = round_fx( L_add( fdOutVal, fdInVal ) ); } out[i] = combinedVal; + move16(); hannIter = add( hannIter, 1 ); } diff --git a/lib_dec/lead_deindexing_fx.c b/lib_dec/lead_deindexing_fx.c index 090ec84a4..2e9ea383f 100644 --- a/lib_dec/lead_deindexing_fx.c +++ b/lib_dec/lead_deindexing_fx.c @@ -72,7 +72,7 @@ void re8_decode_base_index_fx( BREAK; } } - ka = AA3[sub( i, 1 )]; + ka = AA3[i - 1]; move16(); } ELSE @@ -84,7 +84,7 @@ void re8_decode_base_index_fx( BREAK; } } - ka = AA4[sub( i, 1 )]; + ka = AA4[i - 1]; move16(); } @@ -196,6 +196,7 @@ void re8_decode_base_index_fx( move16(); #ifdef CR_2109_to_2112_cd0_ce0 l = 1; + move16(); FOR( i = 0; i < 8; i++ ) { if ( x[i] == 0 ) @@ -206,7 +207,7 @@ void re8_decode_base_index_fx( } test(); /* if the signs are constrained and all components are non-zero */ - IF( ( k1 == 7 ) && ( l > 0 ) ) + IF( EQ_16( k1, 7 ) && ( l > 0 ) ) #else IF( k1 == 7 ) #endif @@ -277,9 +278,7 @@ static void fcb_decode_pos_fx( FOR( i = 0; i < tmp_loop; i++ ) { select_table23 = select_table22[temp1]; - move16(); select_table24 = &select_table23[sub( pulse_num, l )]; - move16(); k = sub( *select_table24, k ); WHILE( LE_16( k, *select_table24 ) ) diff --git a/lib_dec/lib_dec_fx.c b/lib_dec/lib_dec_fx.c index 62b92ebb7..900aa4d54 100644 --- a/lib_dec/lib_dec_fx.c +++ b/lib_dec/lib_dec_fx.c @@ -46,6 +46,7 @@ #include #include "wmc_auto.h" +#define INV_1000_Q31 2147484 /*1/1000 IN Q31*/ /*---------------------------------------------------------------------* * Local structs *---------------------------------------------------------------------*/ @@ -164,15 +165,32 @@ ivas_error IVAS_DEC_Open( hIvasDec->hasDecodedFirstGoodFrame = false; hIvasDec->isInitialized = false; hIvasDec->updateOrientation = false; + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); hIvasDec->mode = mode; + move16(); hIvasDec->bitstreamformat = G192; hIvasDec->Opt_VOIP = 0; hIvasDec->amrwb_rfc4867_flag = -1; hIvasDec->prev_ft_speech = 1; /* RXDTX handler previous frametype flag for G.192 format AMRWB SID_FIRST detection */ hIvasDec->CNG = 0; /* RXDTX handler CNG = 1, no CNG = 0*/ - + move16(); + move16(); + move16(); + move16(); + move16(); /*-----------------------------------------------------------------* * Initialize IVAS-codec decoder state *-----------------------------------------------------------------*/ @@ -211,6 +229,13 @@ ivas_error IVAS_DEC_Open( #ifdef FIX_667_DISABLE_INITIAL_PLC_SUPPRESSION hIvasDec->hasDecodedFirstGoodFrame = true; /* Functionality to suppress output for initial lost frames is disabled in EVS operation */ #endif + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); return IVAS_ERR_OK; } @@ -233,6 +258,20 @@ ivas_error IVAS_DEC_Open( st_ivas->sba_planar = 0; st_ivas->sba_analysis_order = 0; + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); return IVAS_ERR_OK; } @@ -265,7 +304,20 @@ static void init_decoder_config( hDecoderConfig->Opt_ExternalOrientation = 0; hDecoderConfig->Opt_dpid_on = 0; hDecoderConfig->Opt_aeid_on = 0; - + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); return; } @@ -384,16 +436,25 @@ ivas_error IVAS_DEC_Configure( ivas_error error; error = IVAS_ERR_OK; + move32(); + test(); IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; } + test(); + test(); + test(); IF( NE_32( sampleRate, 8000 ) && NE_32( sampleRate, 16000 ) && NE_32( sampleRate, 32000 ) && NE_32( sampleRate, 48000 ) ) { return IVAS_ERR_WRONG_PARAMS; } + test(); + test(); + test(); + test(); IF( EQ_16( hIvasDec->mode, IVAS_DEC_MODE_EVS ) && !( ( EQ_16( outputConfig, IVAS_AUDIO_CONFIG_MONO ) && EQ_16( Opt_non_diegetic_pan, 0 ) ) || ( EQ_16( outputConfig, IVAS_AUDIO_CONFIG_STEREO ) && EQ_16( Opt_non_diegetic_pan, 1 ) ) ) ) { @@ -405,22 +466,27 @@ ivas_error IVAS_DEC_Configure( hDecoderConfig = st_ivas->hDecoderConfig; hDecoderConfig->output_config = outputConfig; + move16(); IF( EQ_16( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_INVALID ) ) { return IVAS_ERR_WRONG_PARAMS; } hDecoderConfig->output_Fs = sampleRate; - + move32(); IF( EQ_16( hIvasDec->mode, IVAS_DEC_MODE_EVS ) ) { st_ivas->element_mode_init = EVS_MONO; hDecoderConfig->nchan_out = 1; + move16(); + move16(); } + test(); IF( NE_16( outputConfig, IVAS_AUDIO_CONFIG_EXTERNAL ) && NE_16( outputConfig, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) { hDecoderConfig->nchan_out = audioCfg2channels( hDecoderConfig->output_config ); + move16(); } hDecoderConfig->Opt_tsm = tsmEnabled; @@ -434,7 +500,25 @@ ivas_error IVAS_DEC_Configure( hDecoderConfig->Opt_delay_comp = delayCompensationEnabled; hDecoderConfig->Opt_ExternalOrientation = enableExternalOrientation; hDecoderConfig->Opt_dpid_on = Opt_dpid_on; - hDecoderConfig->Opt_aeid_on = NE_32( (Word32) acousticEnvironmentId, 65535 ) ? TRUE : FALSE; + IF( NE_32( (Word32) acousticEnvironmentId, 65535 ) ) + { + hDecoderConfig->Opt_aeid_on = TRUE; + } + ELSE + { + hDecoderConfig->Opt_aeid_on = FALSE; + } + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); IF( EQ_16( renderFramesize, IVAS_RENDER_FRAMESIZE_UNKNOWN ) ) { @@ -449,16 +533,18 @@ ivas_error IVAS_DEC_Configure( hDecoderConfig->render_framesize = renderFramesize; } + move16(); /* Set decoder parameters to initial values */ - IF( ( error = ivas_init_decoder_front( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_init_decoder_front( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } - IF( EQ_16( hIvasDec->mode, IVAS_DEC_MODE_EVS ) ) + if ( EQ_16( hIvasDec->mode, IVAS_DEC_MODE_EVS ) ) { hIvasDec->st_ivas->ivas_format = MONO_FORMAT; + move16(); } hIvasDec->nSamplesFrame = (UWord16) Mpy_32_16_1( hDecoderConfig->output_Fs, INV_FRAME_PER_SEC_Q15 ); @@ -467,6 +553,11 @@ ivas_error IVAS_DEC_Configure( hIvasDec->tsm_scale = 100; hIvasDec->tsm_max_scaling = 0; hIvasDec->tsm_quality = 1.0f; + move16(); + move16(); + move16(); + move16(); + move16(); return error; } @@ -508,12 +599,15 @@ ivas_error IVAS_DEC_SetRenderFramesize( const IVAS_RENDER_FRAMESIZE render_framesize /* i : render framesize */ ) { + test(); + test(); IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL || hIvasDec->st_ivas->hDecoderConfig == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; } hIvasDec->st_ivas->hDecoderConfig->render_framesize = render_framesize; + move16(); return IVAS_ERR_OK; } @@ -529,12 +623,15 @@ ivas_error IVAS_DEC_GetRenderFramesize( IVAS_RENDER_FRAMESIZE *render_framesize /* o : render framesize */ ) { + test(); + test(); IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL || render_framesize == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; } *render_framesize = hIvasDec->st_ivas->hDecoderConfig->render_framesize; + move16(); return IVAS_ERR_OK; } @@ -551,6 +648,8 @@ ivas_error IVAS_DEC_GetRenderFramesizeSamples( ) { Word16 tmp; + test(); + test(); IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL || render_framesize == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; @@ -574,6 +673,7 @@ ivas_error IVAS_DEC_GetRenderFramesizeSamples( { *render_framesize = 0; } + move16(); return IVAS_ERR_OK; } @@ -589,12 +689,15 @@ ivas_error IVAS_DEC_GetRenderFramesizeMs( UWord32 *render_framesize /* o : render framesize in samples */ ) { + test(); + test(); IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL || render_framesize == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; } *render_framesize = get_render_frame_size_ms( hIvasDec->st_ivas->hDecoderConfig->render_framesize ); + move32(); return IVAS_ERR_OK; } @@ -610,6 +713,8 @@ ivas_error IVAS_DEC_GetReferencesUpdateFrequency( Word16 *update_frequency /* o : update frequency */ ) { + test(); + test(); IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL || update_frequency == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; @@ -618,14 +723,17 @@ ivas_error IVAS_DEC_GetReferencesUpdateFrequency( IF( EQ_16( hIvasDec->st_ivas->hDecoderConfig->render_framesize, IVAS_RENDER_FRAMESIZE_5MS ) ) { *update_frequency = IVAS_MAX_PARAM_SPATIAL_SUBFRAMES; + move16(); } ELSE IF( EQ_16( hIvasDec->st_ivas->hDecoderConfig->render_framesize, IVAS_RENDER_FRAMESIZE_10MS ) ) { - *update_frequency = shr( IVAS_MAX_PARAM_SPATIAL_SUBFRAMES, 1 ); + *update_frequency = IVAS_MAX_PARAM_SPATIAL_SUBFRAMES >> 1; + move16(); } ELSE IF( EQ_16( hIvasDec->st_ivas->hDecoderConfig->render_framesize, IVAS_RENDER_FRAMESIZE_20MS ) ) { - *update_frequency = shr( IVAS_MAX_PARAM_SPATIAL_SUBFRAMES, 2 ); + *update_frequency = IVAS_MAX_PARAM_SPATIAL_SUBFRAMES >> 2; + move16(); } return IVAS_ERR_OK; @@ -642,12 +750,15 @@ ivas_error IVAS_DEC_GetNumOrientationSubframes( Word16 *num_subframes /* o : render framesize */ ) { + test(); + test(); IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL || num_subframes == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; } *num_subframes = (Word16) hIvasDec->st_ivas->hDecoderConfig->render_framesize; + move16(); return IVAS_ERR_OK; } @@ -671,8 +782,9 @@ ivas_error IVAS_DEC_EnableVoIP( ivas_error error; error = IVAS_ERR_OK; + move32(); - + test(); IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; @@ -682,12 +794,15 @@ ivas_error IVAS_DEC_EnableVoIP( hIvasDec->Opt_VOIP = 1; hDecoderConfig->Opt_tsm = 1; + move16(); + move16(); IF( NE_16( (Word16) hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) { hDecoderConfig->nchan_out = audioCfg2channels( hDecoderConfig->output_config ); + move16(); } - IF( ( error = input_format_API_to_internal( inputFormat, &hIvasDec->bitstreamformat, &hIvasDec->sdp_hf_only, true ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = input_format_API_to_internal( inputFormat, &hIvasDec->bitstreamformat, &hIvasDec->sdp_hf_only, true ) ), IVAS_ERR_OK ) ) { return error; } @@ -698,8 +813,10 @@ ivas_error IVAS_DEC_EnableVoIP( } hIvasDec->hVoIP->lastDecodedWasActive = 0; + move16(); hIvasDec->hVoIP->hCurrentDataUnit = NULL; hIvasDec->hVoIP->nSamplesFrame = (UWord16) Mpy_32_16_1( hDecoderConfig->output_Fs, INV_FRAME_PER_SEC_Q15 ); + move16(); #define WMC_TOOL_SKIP /* Bitstream conversion is not counted towards complexity and memory usage */ @@ -712,7 +829,7 @@ ivas_error IVAS_DEC_EnableVoIP( } /* initialize JBM */ - IF( ( error = JB4_Create( &hIvasDec->hVoIP->hJBM ) != IVAS_ERR_OK ) != IVAS_ERR_OK ) + IF( NE_32( ( error = JB4_Create( &hIvasDec->hVoIP->hJBM ) != IVAS_ERR_OK ), IVAS_ERR_OK ) ) { return error; } @@ -751,9 +868,10 @@ ivas_error IVAS_DEC_FeedFrame_Serial( DECODER_CONFIG_HANDLE hDecoderConfig = hIvasDec->st_ivas->hDecoderConfig; AUDIO_CONFIG output_config = hDecoderConfig->output_config; - IF( ( hIvasDec->st_ivas->ivas_format == MC_FORMAT ) && ( hIvasDec->st_ivas->mc_mode == MC_MODE_PARAMMC ) ) + test(); + IF( ( EQ_16( hIvasDec->st_ivas->ivas_format, MC_FORMAT ) ) && ( EQ_16( hIvasDec->st_ivas->mc_mode, MC_MODE_PARAMMC ) ) ) { - IF( output_config == IVAS_AUDIO_CONFIG_LS_CUSTOM ) + IF( EQ_16( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) { /*float2fix block: to be removed*/ floatToFixed_arrL( hIvasDec->st_ivas->hLsSetupCustom->ls_azimuth, hIvasDec->st_ivas->hLsSetupCustom->ls_azimuth_fx, Q22, hIvasDec->st_ivas->hLsSetupCustom->num_spk ); @@ -761,7 +879,7 @@ ivas_error IVAS_DEC_FeedFrame_Serial( } } - IF( output_config == IVAS_AUDIO_CONFIG_LS_CUSTOM ) + IF( EQ_16( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) { FOR( Word16 ind = 0; ind < MAX_OUTPUT_CHANNELS; ind++ ) { @@ -769,7 +887,7 @@ ivas_error IVAS_DEC_FeedFrame_Serial( hIvasDec->st_ivas->hLsSetupCustom->ls_elevation_fx[ind] = (Word32) ( hIvasDec->st_ivas->hLsSetupCustom->ls_elevation[ind] * ( 1 << 22 ) ); } } - IF( ( error = ivas_init_decoder_fx( hIvasDec->st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_init_decoder_fx( hIvasDec->st_ivas ) ), IVAS_ERR_OK ) ) #else IF( ( error = ivas_init_decoder( hIvasDec->st_ivas ) ) != IVAS_ERR_OK ) #endif @@ -778,7 +896,9 @@ ivas_error IVAS_DEC_FeedFrame_Serial( } #ifdef IVAS_FLOAT_FIXED Word32 ivas_total_brate = hIvasDec->st_ivas->hDecoderConfig->ivas_total_brate; - IF( ( hIvasDec->st_ivas->ivas_format == MC_FORMAT ) && ( hIvasDec->st_ivas->mc_mode == MC_MODE_PARAMMC ) ) + move32(); + test(); + IF( ( EQ_16( hIvasDec->st_ivas->ivas_format, MC_FORMAT ) ) && ( EQ_16( hIvasDec->st_ivas->mc_mode, MC_MODE_PARAMMC ) ) ) { PARAM_MC_DEC_HANDLE hParamMC; hParamMC = hIvasDec->st_ivas->hParamMC; @@ -796,32 +916,42 @@ ivas_error IVAS_DEC_FeedFrame_Serial( } #endif + test(); IF( hIvasDec->hVoIP != NULL && hIvasDec->hVoIP->hCurrentDataUnit != NULL ) { DEC_CORE_HANDLE st = hIvasDec->st_ivas->hSCE[0]->hCoreCoder[0]; st->ini_frame = 0; st->prev_use_partial_copy = 0; - hIvasDec->st_ivas->hDecoderConfig->ivas_total_brate = hIvasDec->hVoIP->hCurrentDataUnit->dataSize * FRAMES_PER_SEC; + move16(); + move16(); + hIvasDec->st_ivas->hDecoderConfig->ivas_total_brate = imult3216( hIvasDec->hVoIP->hCurrentDataUnit->dataSize, FRAMES_PER_SEC ); + move32(); } ELSE { hIvasDec->st_ivas->hDecoderConfig->ivas_total_brate = ACELP_8k00; + move32(); } hIvasDec->isInitialized = true; + move16(); } } - IF( !bfi ) /* TODO(mcjbm): Is this ok for bfi == 2 (partial frame)? Is there enough info to fully configure decoder? */ + if ( !bfi ) /* TODO(mcjbm): Is this ok for bfi == 2 (partial frame)? Is there enough info to fully configure decoder? */ { hIvasDec->hasBeenFedFirstGoodFrame = true; + move16(); } /* Update redundant frame information in EVS (pre- read indices) */ + test(); + test(); IF( EQ_16( (Word16) hIvasDec->mode, IVAS_DEC_MODE_EVS ) && hIvasDec->hVoIP != NULL && hIvasDec->hVoIP->hCurrentDataUnit != NULL ) { DEC_CORE_HANDLE st = hIvasDec->st_ivas->hSCE[0]->hCoreCoder[0]; st->bit_stream = serial; + test(); IF( hIvasDec->hVoIP->hCurrentDataUnit->partial_frame || st->prev_use_partial_copy ) { st->next_coder_type = hIvasDec->hVoIP->hCurrentDataUnit->nextCoderType; @@ -830,19 +960,25 @@ ivas_error IVAS_DEC_FeedFrame_Serial( { st->next_coder_type = INACTIVE; } + move16(); - IF( EQ_16( (Word16) hIvasDec->hVoIP->hCurrentDataUnit->partial_frame, 1 ) && NE_16( bfi, 1 ) ) + test(); + if ( EQ_16( (Word16) hIvasDec->hVoIP->hCurrentDataUnit->partial_frame, 1 ) && NE_16( bfi, 1 ) ) { bfi = 2; + move16(); } } - IF( ( error = read_indices( hIvasDec->st_ivas, serial, num_bits, &hIvasDec->prev_ft_speech, &hIvasDec->CNG, bfi ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = read_indices( hIvasDec->st_ivas, serial, num_bits, &hIvasDec->prev_ft_speech, &hIvasDec->CNG, bfi ) ), IVAS_ERR_OK ) ) { return error; } /* Update redundant frame information in EVS (post- read indices) */ + test(); + test(); + test(); IF( EQ_16( (Word16) hIvasDec->mode, IVAS_DEC_MODE_EVS ) && hIvasDec->hVoIP != NULL && hIvasDec->hVoIP->hCurrentDataUnit != NULL && @@ -851,12 +987,18 @@ ivas_error IVAS_DEC_FeedFrame_Serial( DEC_CORE_HANDLE st = hIvasDec->st_ivas->hSCE[0]->hCoreCoder[0]; st->codec_mode = MODE2; st->use_partial_copy = 1; + move16(); + move16(); } hIvasDec->needNewFrame = false; hIvasDec->hasBeenFedFrame = true; hIvasDec->nSamplesRendered = 0; hIvasDec->nSamplesAvailableNext = hIvasDec->nSamplesFrame; + move16(); + move16(); + move16(); + move16(); return IVAS_ERR_OK; } @@ -887,7 +1029,13 @@ ivas_error IVAS_DEC_GetSamples( nSamplesRendered_loop = 0; l_ts = 0; nTransportChannels = 0; + move16(); + move16(); + move16(); + move16(); + move16(); + test(); IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; @@ -899,7 +1047,7 @@ ivas_error IVAS_DEC_GetSamples( * Combine orientations *----------------------------------------------------------------*/ - IF( ( error = combine_external_and_head_orientations_dec( hIvasDec->st_ivas->hHeadTrackData, hIvasDec->st_ivas->hExtOrientationData, hIvasDec->st_ivas->hCombinedOrientationData ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = combine_external_and_head_orientations_dec( hIvasDec->st_ivas->hHeadTrackData, hIvasDec->st_ivas->hExtOrientationData, hIvasDec->st_ivas->hCombinedOrientationData ) ), IVAS_ERR_OK ) ) { return error; } @@ -911,83 +1059,100 @@ ivas_error IVAS_DEC_GetSamples( hIvasDec->st_ivas->hCombinedOrientationData->Quaternions[i].z = fixedToFloat_32( hIvasDec->st_ivas->hCombinedOrientationData->Quaternions[i].z_fx, hIvasDec->st_ivas->hCombinedOrientationData->Quaternions[i].q_fact ); } hIvasDec->updateOrientation = false; + move16(); } - IF( !hIvasDec->hasBeenFedFrame && EQ_16( hIvasDec->nSamplesAvailableNext, 0 ) ) + test(); + IF( !hIvasDec->hasBeenFedFrame && hIvasDec->nSamplesAvailableNext == 0 ) { /* no frame was fed, do nothing but ask for a frame */ *needNewFrame = true; *nOutSamples = 0; hIvasDec->needNewFrame = true; + move16(); + move16(); + move16(); return IVAS_ERR_OK; } + test(); /* check if we are still at the beginning with bad frames, put out zeroes, keep track of subframes */ IF( !hIvasDec->isInitialized && hIvasDec->st_ivas->bfi ) { hIvasDec->hasBeenFedFrame = false; - set_s( pcmBuf, 0, hIvasDec->st_ivas->hDecoderConfig->nchan_out * nSamplesAsked ); + move16(); + set16_fx( pcmBuf, 0, imult1616( hIvasDec->st_ivas->hDecoderConfig->nchan_out, nSamplesAsked ) ); hIvasDec->nSamplesRendered = add( hIvasDec->nSamplesRendered, nSamplesAsked ); + move16(); *nOutSamples = nSamplesAsked; + move16(); hIvasDec->nSamplesAvailableNext = sub( hIvasDec->nSamplesAvailableNext, nSamplesAsked ); - IF( EQ_16( hIvasDec->nSamplesAvailableNext, 0 ) ) + move16(); + IF( hIvasDec->nSamplesAvailableNext == 0 ) { hIvasDec->needNewFrame = true; *needNewFrame = true; + move16(); + move16(); } } - ELSE{ + ELSE + { /* check if we need to run the setup function */ + test(); IF( !hIvasDec->isInitialized || hIvasDec->hasBeenFedFrame ){ /* setup */ - IF( ( error = IVAS_DEC_Setup( hIvasDec, &l_ts, &nTransportChannels, &nOutChannels, &nSamplesRendered_loop, pcmBuf + nSamplesRendered * nOutChannels ) ) != IVAS_ERR_OK ){ + IF( NE_32( ( error = IVAS_DEC_Setup( hIvasDec, &l_ts, &nTransportChannels, &nOutChannels, &nSamplesRendered_loop, pcmBuf + imult3216( nSamplesRendered, nOutChannels ) ) ), IVAS_ERR_OK ) ){ return error; -} + } } { /* check if we need to run the setup function, tc decoding and feeding the renderer */ + test(); IF( !hIvasDec->isInitialized || hIvasDec->hasBeenFedFrame ) { Word16 nResidualSamples, nSamplesTcsScaled; nSamplesRendered = add( nSamplesRendered, nSamplesRendered_loop ); + test(); IF( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm && NE_16( (Word16) nTransportChannels, hIvasDec->nTransportChannelsOld ) ) { - IF( ( error = IVAS_DEC_VoIP_reconfigure( hIvasDec, nTransportChannels, l_ts ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = IVAS_DEC_VoIP_reconfigure( hIvasDec, nTransportChannels, l_ts ) ), IVAS_ERR_OK ) ) { return error; } } /* IVAS decoder */ - IF( ( error = IVAS_DEC_GetTcSamples( hIvasDec, hIvasDec->apaExecBuffer, hIvasDec->apaExecBuffer_fx, &nOutSamplesElse ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = IVAS_DEC_GetTcSamples( hIvasDec, hIvasDec->apaExecBuffer, hIvasDec->apaExecBuffer_fx, &nOutSamplesElse ) ), IVAS_ERR_OK ) ) { return error; } /* JBM */ IF( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm ) { - IF( NE_16( (Word16) apa_set_scale( hIvasDec->hTimeScaler, hIvasDec->tsm_scale ), 0 ) ) + IF( apa_set_scale( hIvasDec->hTimeScaler, hIvasDec->tsm_scale ) != 0 ) { return IVAS_ERR_UNKNOWN; } - IF( NE_16( (Word16) apa_exec( hIvasDec->hTimeScaler, hIvasDec->apaExecBuffer, hIvasDec->nSamplesFrame * nTransportChannels, (UWord16) hIvasDec->tsm_max_scaling, hIvasDec->apaExecBuffer, &nTimeScalerOutSamples ), 0 ) ) + IF( apa_exec( hIvasDec->hTimeScaler, hIvasDec->apaExecBuffer, (UWord16) imult3216( hIvasDec->nSamplesFrame, nTransportChannels ), (UWord16) hIvasDec->tsm_max_scaling, hIvasDec->apaExecBuffer, &nTimeScalerOutSamples ) != 0 ) { return IVAS_ERR_UNKNOWN; } assert( LE_32( (Word32) nTimeScalerOutSamples, APA_BUF ) ); - nSamplesTcsScaled = nTimeScalerOutSamples / nTransportChannels; + nSamplesTcsScaled = idiv1616( extract_l( nTimeScalerOutSamples ), nTransportChannels ); } ELSE { nSamplesTcsScaled = hIvasDec->nSamplesFrame; + move16(); } /* Feed decoded transport channels samples to the renderer */ - IF( ( error = IVAS_DEC_RendererFeedTcSamples( hIvasDec, nSamplesTcsScaled, &nResidualSamples, hIvasDec->apaExecBuffer ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = IVAS_DEC_RendererFeedTcSamples( hIvasDec, nSamplesTcsScaled, &nResidualSamples, hIvasDec->apaExecBuffer ) ), IVAS_ERR_OK ) ) { return error; } @@ -995,36 +1160,41 @@ ivas_error IVAS_DEC_GetSamples( IF( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm ) { /* feed residual samples to TSM for the next call */ - IF( NE_16( (Word16) apa_set_renderer_residual_samples( hIvasDec->hTimeScaler, (UWord16) nResidualSamples ), 0 ) ) + IF( apa_set_renderer_residual_samples( hIvasDec->hTimeScaler, (UWord16) nResidualSamples ) != 0 ) { return IVAS_ERR_UNKNOWN; } } hIvasDec->hasBeenFedFrame = false; + move16(); } /* render IVAS frames directly to the output buffer */ nSamplesToRender = sub( nSamplesAsked, nSamplesRendered ); - IF( ( error = IVAS_DEC_GetRenderedSamples( hIvasDec, nSamplesToRender, &nSamplesRendered_loop, &hIvasDec->nSamplesAvailableNext, pcmBuf + nSamplesRendered * nOutChannels ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = IVAS_DEC_GetRenderedSamples( hIvasDec, nSamplesToRender, &nSamplesRendered_loop, &hIvasDec->nSamplesAvailableNext, pcmBuf + imult3216( nSamplesRendered, nOutChannels ) ) ), IVAS_ERR_OK ) ) { return error; } nSamplesRendered = add( nSamplesRendered, nSamplesRendered_loop ); nSamplesToRender = sub( nSamplesToRender, nSamplesRendered_loop ); - IF( EQ_16( hIvasDec->nSamplesAvailableNext, 0 ) ) + IF( hIvasDec->nSamplesAvailableNext == 0 ) { *needNewFrame = true; hIvasDec->needNewFrame = true; + move16(); + move16(); } ELSE { *needNewFrame = false; + move16(); } } } *nOutSamples = nSamplesRendered; +move16(); return IVAS_ERR_OK; } @@ -1048,6 +1218,7 @@ static ivas_error IVAS_DEC_Setup( ivas_error error; *nSamplesRendered = 0; + move16(); IF( EQ_16( (Word16) hIvasDec->mode, IVAS_DEC_MODE_EVS ) ) { @@ -1061,6 +1232,8 @@ static ivas_error IVAS_DEC_Setup( *nTransportChannels = 1; *nOutChannels = 1; } + move16(); + move16(); } ELSE { @@ -1076,7 +1249,7 @@ static ivas_error IVAS_DEC_Setup( * - reconfigure the decoder when the number of TC or IVAS total bitrate change *----------------------------------------------------------------*/ - IF( EQ_16( st_ivas->bfi, 0 ) ) + IF( st_ivas->bfi == 0 ) { #if 1 // flt to fix @@ -1195,7 +1368,7 @@ static ivas_error IVAS_DEC_Setup( } } #endif - IF( ( error = ivas_dec_setup( st_ivas, nSamplesRendered, data ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_dec_setup( st_ivas, nSamplesRendered, data ) ), IVAS_ERR_OK ) ) { return error; } @@ -1285,6 +1458,9 @@ static ivas_error IVAS_DEC_Setup( *nTransportChannels = (UWord8) st_ivas->hTcBuffer->nchan_transport_jbm; *nTcBufferGranularity = (UWord16) st_ivas->hTcBuffer->n_samples_granularity; *nOutChannels = (UWord8) st_ivas->hDecoderConfig->nchan_out; + move16(); + move16(); + move16(); } return IVAS_ERR_OK; @@ -1307,6 +1483,7 @@ static ivas_error IVAS_DEC_GetTcSamples( Decoder_Struct *st_ivas; ivas_error error; + test(); IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; @@ -1318,7 +1495,7 @@ static ivas_error IVAS_DEC_GetTcSamples( IF( EQ_16( (Word16) hIvasDec->mode, IVAS_DEC_MODE_EVS ) ) { - IF( ( error = evs_dec_main( st_ivas, *nOutSamples, pcmBuf, NULL ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = evs_dec_main( st_ivas, *nOutSamples, pcmBuf, NULL ) ), IVAS_ERR_OK ) ) { return error; } @@ -1340,7 +1517,7 @@ static ivas_error IVAS_DEC_GetTcSamples( floatToFixed_arrL( pcmBuf, pcmBuf_fx, 11, (Word16) ( st_ivas->hTcBuffer->nchan_transport_jbm * st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC ) ); } - IF( EQ_16( st_ivas->hDecoderConfig->Opt_tsm, 0 ) ) + IF( st_ivas->hDecoderConfig->Opt_tsm == 0 ) { FOR( n = 0; n < ivas_get_nchan_buffers_dec_ivas_fx( st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); n++ ) { @@ -1417,7 +1594,7 @@ static ivas_error IVAS_DEC_GetTcSamples( #endif /* Function call: ivas_jbm_dec_tc function */ - IF( ( error = ivas_jbm_dec_tc_fx( st_ivas, pcmBuf_fx ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_jbm_dec_tc_fx( st_ivas, pcmBuf_fx ) ), IVAS_ERR_OK ) ) { return error; } @@ -1500,9 +1677,10 @@ static ivas_error IVAS_DEC_GetTcSamples( } #endif // fixed to float } - IF( hIvasDec->hasBeenFedFirstGoodFrame ) + if ( hIvasDec->hasBeenFedFirstGoodFrame ) { hIvasDec->hasDecodedFirstGoodFrame = true; + move16(); } return IVAS_ERR_OK; @@ -1524,6 +1702,7 @@ static ivas_error IVAS_DEC_RendererFeedTcSamples( { Decoder_Struct *st_ivas; + test(); IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; @@ -1554,6 +1733,7 @@ static ivas_error IVAS_DEC_GetRenderedSamples( Decoder_Struct *st_ivas; ivas_error error; + test(); IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; @@ -1580,15 +1760,18 @@ static ivas_error IVAS_DEC_GetBufferedNumberOfSamples( ) { *nSamplesBuffered = 0; + move16(); + test(); IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; } /* check if the TC buffer already exists, otherweise nothing is buffered anyway */ - IF( hIvasDec->st_ivas->hTcBuffer != NULL ) + if ( hIvasDec->st_ivas->hTcBuffer != NULL ) { *nSamplesBuffered = sub( hIvasDec->st_ivas->hTcBuffer->n_samples_buffered, hIvasDec->st_ivas->hTcBuffer->n_samples_rendered ); + move16(); } return IVAS_ERR_OK; @@ -1606,10 +1789,13 @@ ivas_error IVAS_DEC_GetNumObjects( UWord16 *numObjects /* o : number of objects for which the decoder has been configured */ ) { + test(); IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; } + test(); + test(); IF( EQ_16( (Word16) hIvasDec->st_ivas->ivas_format, ISM_FORMAT ) || EQ_16( (Word16) hIvasDec->st_ivas->ivas_format, SBA_ISM_FORMAT ) || EQ_16( (Word16) hIvasDec->st_ivas->ivas_format, MASA_ISM_FORMAT ) ) { *numObjects = hIvasDec->st_ivas->nchan_ism; @@ -1618,6 +1804,7 @@ ivas_error IVAS_DEC_GetNumObjects( { *numObjects = 0; } + move16(); return IVAS_ERR_OK; } @@ -1643,6 +1830,7 @@ ivas_error IVAS_DEC_GetFormat( { *format = IVAS_DEC_BS_UNKOWN; } + move32(); return IVAS_ERR_OK; } @@ -1665,7 +1853,7 @@ static Word16 getOutputBufferSize( IF( EQ_16( (Word16) st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) { - return (Word16) ( st_ivas->hDecoderConfig->output_Fs * ( IVAS_MAX_OUTPUT_CHANNELS + IVAS_MAX_NUM_OBJECTS ) / FRAMES_PER_SEC ); + return extract_l( Mult_32_16( imult3216( st_ivas->hDecoderConfig->output_Fs, ( IVAS_MAX_OUTPUT_CHANNELS + IVAS_MAX_NUM_OBJECTS ) ), INV_FRAME_PER_SEC_Q15 ) ); } ELSE IF( EQ_16( (Word16) st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) { @@ -1674,11 +1862,11 @@ static Word16 getOutputBufferSize( return -1; } - return (Word16) ( st_ivas->hDecoderConfig->output_Fs * ( st_ivas->hLsSetupCustom->num_spk + st_ivas->hLsSetupCustom->num_lfe ) / FRAMES_PER_SEC ); + return extract_l( Mult_32_16( imult3216( st_ivas->hDecoderConfig->output_Fs, add( st_ivas->hLsSetupCustom->num_spk, st_ivas->hLsSetupCustom->num_lfe ) ), INV_FRAME_PER_SEC_Q15 ) ); } ELSE { - return (Word16) ( st_ivas->hDecoderConfig->output_Fs * st_ivas->hDecoderConfig->nchan_out / FRAMES_PER_SEC ); + return extract_l( Mult_32_16( imult3216( st_ivas->hDecoderConfig->output_Fs, st_ivas->hDecoderConfig->nchan_out ), INV_FRAME_PER_SEC_Q15 ) ); } } @@ -1694,12 +1882,15 @@ ivas_error IVAS_DEC_GetOutputBufferSize( Word16 *outputBufferSize /* o : total number of samples expected in the output buffer for current decoder configuration */ ) { + test(); + test(); IF( outputBufferSize == NULL || hIvasDec == NULL || hIvasDec->st_ivas == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; } *outputBufferSize = getOutputBufferSize( hIvasDec->st_ivas ); + move16(); IF( EQ_16( *outputBufferSize, -1 ) ) { @@ -1731,6 +1922,7 @@ ivas_error IVAS_DEC_GetNumOutputChannels( { *numOutputChannels = 0; } + move16(); return IVAS_ERR_OK; } @@ -1752,13 +1944,16 @@ ivas_error IVAS_DEC_GetObjectMetadata( Decoder_Struct *st_ivas; ISM_METADATA_HANDLE hIsmMeta; + test(); IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; } st_ivas = hIvasDec->st_ivas; - IF( NE_16( (Word16) st_ivas->ivas_format, ISM_FORMAT ) && NE_16( (Word16) st_ivas->ivas_format, MASA_ISM_FORMAT ) && NE_16( (Word16) st_ivas->ivas_format, SBA_ISM_FORMAT ) ) + test(); + test(); + IF( NE_16( st_ivas->ivas_format, ISM_FORMAT ) && NE_16( st_ivas->ivas_format, MASA_ISM_FORMAT ) && NE_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) { return IVAS_ERR_WRONG_MODE; } @@ -1793,6 +1988,14 @@ ivas_error IVAS_DEC_GetObjectMetadata( metadata->non_diegetic_flag = hIsmMeta->non_diegetic_flag; } + move32(); + move32(); + move32(); + move32(); + move32(); + move32(); + move16(); + move16(); return IVAS_ERR_OK; } #else @@ -1875,12 +2078,14 @@ ivas_error IVAS_DEC_GetMasaMetadata( const UWord8 getFromJbmBuffer /* i : get metadata from a JBM buffer */ ) { + test(); IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; } - IF( NE_16( (Word16) hIvasDec->st_ivas->ivas_format, MASA_FORMAT ) && NE_16( (Word16) hIvasDec->st_ivas->ivas_format, MASA_ISM_FORMAT ) ) + test(); + IF( NE_16( hIvasDec->st_ivas->ivas_format, MASA_FORMAT ) && NE_16( hIvasDec->st_ivas->ivas_format, MASA_ISM_FORMAT ) ) { return IVAS_ERR_WRONG_MODE; } @@ -1912,6 +2117,7 @@ ivas_error IVAS_DEC_FeedHeadTrackData( HEAD_TRACK_DATA_HANDLE hHeadTrackData; ivas_error error; + test(); IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; @@ -1933,6 +2139,7 @@ ivas_error IVAS_DEC_FeedHeadTrackData( #ifdef IVAS_FLOAT_FIXED Word32 updateRate_fx = 1677721600; // value is 200 in Q23 + move32(); orientation.w_fx = L_shl( orientation.w_fx, Q29 - orientation.q_fact ); orientation.x_fx = L_shl( orientation.x_fx, Q29 - orientation.q_fact ); orientation.y_fx = L_shl( orientation.y_fx, Q29 - orientation.q_fact ); @@ -1949,8 +2156,11 @@ ivas_error IVAS_DEC_FeedHeadTrackData( orientation.q_fact = Q29; hHeadTrackData->OrientationTracker->refRot.q_fact = Q29; hHeadTrackData->OrientationTracker->absAvgRot.q_fact = Q29; + move16(); + move16(); + move16(); - IF( ( error = ivas_orient_trk_Process_fx( hHeadTrackData->OrientationTracker, orientation, updateRate_fx, &hHeadTrackData->Quaternions[subframe_idx] ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_orient_trk_Process_fx( hHeadTrackData->OrientationTracker, orientation, updateRate_fx, &hHeadTrackData->Quaternions[subframe_idx] ) ), IVAS_ERR_OK ) ) { return error; } @@ -1969,9 +2179,14 @@ ivas_error IVAS_DEC_FeedHeadTrackData( hHeadTrackData->Pos[subframe_idx].y_fx = Pos.y_fx; hHeadTrackData->Pos[subframe_idx].z_fx = Pos.z_fx; hHeadTrackData->Pos[subframe_idx].q_fact = Pos.q_fact; + move32(); + move32(); + move32(); + move16(); #endif hIvasDec->updateOrientation = true; + move16(); return IVAS_ERR_OK; } @@ -1990,6 +2205,9 @@ ivas_error IVAS_DEC_FeedRefRotData( { ivas_orient_trk_state_t *pOtr; + test(); + test(); + test(); IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL || hIvasDec->st_ivas->hHeadTrackData == NULL || hIvasDec->st_ivas->hHeadTrackData->OrientationTracker == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; @@ -2003,6 +2221,7 @@ ivas_error IVAS_DEC_FeedRefRotData( pOtr->refRot.y = rotation.y; hIvasDec->updateOrientation = true; + move16(); return IVAS_ERR_OK; } @@ -2029,6 +2248,9 @@ ivas_error IVAS_DEC_FeedRefVectorData( { ivas_orient_trk_state_t *pOtr; + test(); + test(); + test(); IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL || hIvasDec->st_ivas->hHeadTrackData == NULL || hIvasDec->st_ivas->hHeadTrackData->OrientationTracker == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; @@ -2037,10 +2259,13 @@ ivas_error IVAS_DEC_FeedRefVectorData( pOtr = hIvasDec->st_ivas->hHeadTrackData->OrientationTracker; hIvasDec->updateOrientation = true; + move16(); #ifdef IVAS_FLOAT_FIXED listenerPos.q_fact = Q27; refPos.q_fact = Q27; + move16(); + move16(); listenerPos.x_fx = float_to_fix( listenerPos.x, listenerPos.q_fact ); listenerPos.y_fx = float_to_fix( listenerPos.y, listenerPos.q_fact ); listenerPos.z_fx = float_to_fix( listenerPos.z, listenerPos.q_fact ); @@ -2092,6 +2317,7 @@ ivas_error IVAS_DEC_FeedExternalOrientationData( #ifdef IVAS_FLOAT_FIXED IVAS_QUATERNION orientation_fx = { 0 }; orientation_fx.q_fact = Q29; + move16(); orientation_fx.w_fx = float_to_fix( orientation.w, orientation_fx.q_fact ); orientation_fx.x_fx = float_to_fix( orientation.x, orientation_fx.q_fact ); orientation_fx.y_fx = float_to_fix( orientation.y, orientation_fx.q_fact ); @@ -2115,8 +2341,13 @@ ivas_error IVAS_DEC_FeedExternalOrientationData( hExternalOrientationData->enableExternalOrientation[subframe_idx] = enableExternalOrientation; hExternalOrientationData->enableRotationInterpolation[subframe_idx] = enableRotationInterpolation; hExternalOrientationData->numFramesToTargetOrientation[subframe_idx] = numFramesToTargetOrientation; + move16(); + move16(); + move16(); + move16(); hIvasDec->updateOrientation = true; + move16(); return IVAS_ERR_OK; } @@ -2137,6 +2368,7 @@ ivas_error IVAS_DEC_FeedCustomLsData( Word16 i, is_planar; IVAS_LSSETUP_CUSTOM_HANDLE hLsSetupCustom; + test(); IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; @@ -2153,23 +2385,28 @@ ivas_error IVAS_DEC_FeedCustomLsData( /* Loudspeaker azimuths and elevations */ hLsSetupCustom->num_spk = hLsCustomData.num_spk; + move16(); mvr2r( hLsCustomData.azimuth, hLsSetupCustom->ls_azimuth, hLsCustomData.num_spk ); mvr2r( hLsCustomData.elevation, hLsSetupCustom->ls_elevation, hLsCustomData.num_spk ); /* Set planar flag */ is_planar = 1; + move16(); FOR( i = 0; i < hLsCustomData.num_spk; i++ ) { IF( is_planar && hLsSetupCustom->ls_elevation[i] != 0.0f ) { is_planar = 0; + move16(); } } hLsSetupCustom->is_planar_setup = is_planar; + move16(); /* Loudspeaker LFE */ hLsSetupCustom->num_lfe = hLsCustomData.num_lfe; + move16(); mvs2s( hLsCustomData.lfe_idx, hLsSetupCustom->lfe_idx, hLsCustomData.num_lfe ); return IVAS_ERR_OK; @@ -2187,6 +2424,8 @@ ivas_error IVAS_DEC_GetHrtfHandle( IVAS_DEC_HRTF_HANDLE *hHrtfTD /* o : HRTF handle */ ) { + test(); + test(); IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL || hIvasDec->st_ivas->hHrtfTD == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; @@ -2209,6 +2448,8 @@ ivas_error IVAS_DEC_GetHrtfCRendHandle( IVAS_DEC_HRTF_CREND_HANDLE *hSetOfHRTF /* o : Set of HRTF handle */ ) { + test(); + test(); IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL || hIvasDec->st_ivas->hSetOfHRTF == NULL ) { return IVAS_ERR_WRONG_PARAMS; @@ -2231,6 +2472,8 @@ ivas_error IVAS_DEC_GetHrtfFastConvHandle( IVAS_DEC_HRTF_FASTCONV_HANDLE *hHrtfFastConv /* o : FASTCONV HRTF handle */ ) { + test(); + test(); IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL || hIvasDec->st_ivas->hHrtfFastConv == NULL ) { return IVAS_ERR_WRONG_PARAMS; @@ -2253,6 +2496,8 @@ ivas_error IVAS_DEC_GetHrtfParamBinHandle( IVAS_DEC_HRTF_PARAMBIN_HANDLE *hHrtfParambin /* o : Parametric binauralizer HRTF handle */ ) { + test(); + test(); IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL || hIvasDec->st_ivas->hHrtfParambin == NULL ) { return IVAS_ERR_WRONG_PARAMS; @@ -2273,6 +2518,7 @@ static ivas_error copyRendererConfigStruct( RENDER_CONFIG_HANDLE hRCin, IVAS_RENDER_CONFIG_HANDLE hRCout ) { + test(); IF( hRCin == NULL || hRCout == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; @@ -2289,6 +2535,12 @@ static ivas_error copyRendererConfigStruct( Copy( hRCin->directivity_fx, hRCout->directivity_fx, 3 * MAX_NUM_OBJECTS ); hRCout->roomAcoustics.use_er = hRCin->roomAcoustics.use_er; hRCout->roomAcoustics.lowComplexity = hRCin->roomAcoustics.lowComplexity; + move16(); + move16(); + move16(); + move32(); + move32(); + move32(); #if 1 // To be removed mvr2r( hRCin->directivity, hRCout->directivity, 3 * MAX_NUM_OBJECTS ); #endif @@ -2308,6 +2560,9 @@ ivas_error IVAS_DEC_GetRenderConfig( const IVAS_RENDER_CONFIG_HANDLE hRCout /* o : Render configuration handle */ ) { + test(); + test(); + test(); IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL || hIvasDec->st_ivas->hRenderConfig == NULL || hRCout == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; @@ -2325,14 +2580,14 @@ ivas_error IVAS_DEC_GetDefaultRenderConfig( RENDER_CONFIG_HANDLE hRCin = &RCin; ivas_error error; #ifdef IVAS_FLOAT_FIXED - IF( ( error = ivas_render_config_init_from_rom_fx( &hRCin ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_render_config_init_from_rom_fx( &hRCin ) ), IVAS_ERR_OK ) ) { return error; } #endif /*FLOAT CODE*/ - IF( ( error = ivas_render_config_init_from_rom( &hRCin ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_render_config_init_from_rom( &hRCin ) ), IVAS_ERR_OK ) ) { return error; } @@ -2355,6 +2610,8 @@ ivas_error IVAS_DEC_FeedRenderConfig( { RENDER_CONFIG_HANDLE hRenderConfig; + test(); + test(); IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL || hIvasDec->st_ivas->hRenderConfig == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; @@ -2367,6 +2624,11 @@ ivas_error IVAS_DEC_FeedRenderConfig( hRenderConfig->roomAcoustics.inputPreDelay_fx = renderConfig.roomAcoustics.inputPreDelay_fx; hRenderConfig->roomAcoustics.use_er = 0; + move16(); + move16(); + move16(); + move32(); + move32(); IF( EQ_16( renderConfig.roomAcoustics.use_er, 1 ) ) { hRenderConfig->roomAcoustics.use_er = renderConfig.roomAcoustics.use_er; @@ -2375,6 +2637,8 @@ ivas_error IVAS_DEC_FeedRenderConfig( hRenderConfig->roomAcoustics.ListenerOrigin = renderConfig.roomAcoustics.ListenerOrigin; Copy32( renderConfig.roomAcoustics.AbsCoeff_fx, hRenderConfig->roomAcoustics.AbsCoeff_fx, IVAS_ROOM_ABS_COEFF ); + move16(); + move32(); } Copy32( renderConfig.roomAcoustics.pFc_input_fx, hRenderConfig->roomAcoustics.pFc_input_fx, CLDFB_NO_CHANNELS_MAX ); @@ -2406,6 +2670,9 @@ ivas_error IVAS_DEC_GetDelay( DECODER_CONFIG_HANDLE hDecoderConfig; Word32 out_fs_fx; + test(); + test(); + test(); IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL || nSamples == NULL || timeScale == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; @@ -2420,7 +2687,22 @@ ivas_error IVAS_DEC_GetDelay( st_ivas = hIvasDec->st_ivas; hDecoderConfig = st_ivas->hDecoderConfig; - out_fs_fx = ( hDecoderConfig->output_Fs != 48000 ) ? ( ( hDecoderConfig->output_Fs != 32000 ) ? FS_16K_IN_NS_Q31 : FS_32K_IN_NS_Q31 ) : FS_48K_IN_NS_Q31; + IF( NE_32( hDecoderConfig->output_Fs, 48000 ) ) + { + IF( NE_32( hDecoderConfig->output_Fs, 32000 ) ) + { + out_fs_fx = FS_16K_IN_NS_Q31; + } + ELSE + { + out_fs_fx = FS_32K_IN_NS_Q31; + } + } + ELSE + { + out_fs_fx = FS_48K_IN_NS_Q31; + } + move32(); nSamples[1] = NS2SA_fx2( hDecoderConfig->output_Fs, get_delay_fx( DEC, hDecoderConfig->output_Fs, st_ivas->ivas_format, st_ivas->cldfbAnaDec[0] ) ); move16(); @@ -2433,9 +2715,11 @@ ivas_error IVAS_DEC_GetDelay( { /* note: in MASA, all delay is compensated at the decoder by default, so subtract the encoder delay for print-out */ nSamples[1] = sub( nSamples[1], NS2SA_fx2( hDecoderConfig->output_Fs, IVAS_ENC_DELAY_NS ) ); + move16(); } *timeScale = hDecoderConfig->output_Fs; + move32(); return IVAS_ERR_OK; } @@ -2452,12 +2736,15 @@ ivas_error IVAS_DEC_HasDecodedFirstGoodFrame( bool *hasDecodedFirstGoodFrame /* o : flag indicating if the decoder has decoded a good frame since it was configured */ ) { + test(); + test(); IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL || hasDecodedFirstGoodFrame == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; } *hasDecodedFirstGoodFrame = hIvasDec->hasDecodedFirstGoodFrame; + move16(); return IVAS_ERR_OK; } @@ -2474,6 +2761,8 @@ ivas_error IVAS_DEC_GetPcmFrameSize( Word32 *pcmFrameSize /* o : total size of the PCM output frame. This takes into account the number of output channels */ ) { + test(); + test(); IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL || pcmFrameSize == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; @@ -2481,12 +2770,13 @@ ivas_error IVAS_DEC_GetPcmFrameSize( IF( hIvasDec->hasDecodedFirstGoodFrame ) { - *pcmFrameSize = hIvasDec->st_ivas->hDecoderConfig->nchan_out * hIvasDec->st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC; + *pcmFrameSize = Mult_32_16( imult3216( hIvasDec->st_ivas->hDecoderConfig->output_Fs, hIvasDec->st_ivas->hDecoderConfig->nchan_out ), INV_FRAME_PER_SEC_Q15 ); } ELSE { *pcmFrameSize = 0; } + move32(); return IVAS_ERR_OK; } @@ -2524,15 +2814,19 @@ static void bsCompactToSerial( const UWord8 *compact, UWord16 *serial, UWord16 n UWord32 i; UWord8 byte = 0; const UWord8 mask = 0x80; + move16(); + move16(); FOR( i = 0; i < num_bits; ++i ) { - IF( EQ_16( ( i % 8 ), 0 ) ) + if ( ( i % 8 ) == 0 ) { - byte = compact[L_shr( i, 3 )]; + byte = compact[i / 8]; + move16(); } serial[i] = shr( s_and( byte, mask ), 7 ); + move16(); byte = (UWord8) shl( byte, 1 ); } @@ -2540,7 +2834,8 @@ static void bsCompactToSerial( const UWord8 *compact, UWord16 *serial, UWord16 n /* Add 4 padding bytes required by core coder */ FOR( i = 0; i < 4 * 8; ++i ) { - serial[num_bits + i] = 0; + serial[L_add( num_bits, (Word32) i )] = 0; + move16(); } #undef WMC_TOOL_SKIP } @@ -2566,7 +2861,7 @@ ivas_error IVAS_DEC_VoIP_FeedFrame( Word16 partialCopyFrameType, partialCopyOffset; Word16 result; - IF( EQ_16( auSize, 0 ) ) + IF( auSize == 0 ) { return IVAS_ERR_OK; /* ignore empty/NO_DATA frame - shouldn't be transmitted in RTP */ } @@ -2585,21 +2880,32 @@ ivas_error IVAS_DEC_VoIP_FeedFrame( dataUnit->duration = 20; dataUnit->sequenceNumber = rtpSequenceNumber; dataUnit->silenceIndicator = isSidFrame( dataUnit->dataSize ); + move16(); dataUnit->timeScale = 1000; dataUnit->rcvTime = rcvTime_ms; dataUnit->timeStamp = rtpTimeStamp; dataUnit->partial_frame = 0; dataUnit->partialCopyOffset = partialCopyOffset; dataUnit->qBit = qBit; + move16(); + move16(); + move16(); + move16(); + move16(); + move32(); + move32(); + move32(); + move32(); /* add the frame to the JBM */ result = JB4_PushDataUnit( hIvasDec->hVoIP->hJBM, dataUnit, rcvTime_ms ); - IF( NE_16( result, 0 ) ) + IF( result != 0 ) { return IVAS_ERR_UNKNOWN; } - IF( NE_16( partialCopyFrameType, RF_NO_DATA ) && NE_16( partialCopyOffset, 0 ) ) + test(); + IF( NE_16( partialCopyFrameType, RF_NO_DATA ) && partialCopyOffset != 0 ) { /* create data unit for partial copy in the frame */ dataUnit = JB4_AllocDataUnit( hIvasDec->hVoIP->hJBM ); @@ -2610,14 +2916,23 @@ ivas_error IVAS_DEC_VoIP_FeedFrame( dataUnit->silenceIndicator = 0; /* there are no partial copies for SID frames */ dataUnit->timeScale = 1000; dataUnit->rcvTime = rcvTime_ms; - dataUnit->timeStamp = L_sub( rtpTimeStamp, partialCopyOffset * dataUnit->duration ); + dataUnit->timeStamp = L_sub( rtpTimeStamp, imult3216( dataUnit->duration, partialCopyOffset ) ); + move32(); dataUnit->partial_frame = 1; dataUnit->partialCopyOffset = partialCopyOffset; dataUnit->qBit = qBit; + move16(); + move16(); + move16(); + move16(); + move16(); + move32(); + move32(); + move32(); /* add the frame to the JBM */ result = JB4_PushDataUnit( hIvasDec->hVoIP->hJBM, dataUnit, rcvTime_ms ); - IF( NE_16( result, 0 ) ) + IF( result != 0 ) { return IVAS_ERR_UNKNOWN; } @@ -2641,6 +2956,7 @@ ivas_error IVAS_DEC_VoIP_SetScale( ivas_error error; error = IVAS_ERR_OK; + move32(); IF( EQ_16( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm, false ) ) { @@ -2650,6 +2966,8 @@ ivas_error IVAS_DEC_VoIP_SetScale( { hIvasDec->tsm_scale = scale; hIvasDec->tsm_max_scaling = maxScaling; + move16(); + move16(); } return error; @@ -2669,6 +2987,7 @@ ivas_error IVAS_DEC_TSM_SetQuality( ivas_error error; error = IVAS_ERR_OK; + move32(); IF( EQ_16( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm, false ) ) { @@ -2719,8 +3038,11 @@ ivas_error IVAS_DEC_VoIP_GetSamples( timeScalingDone = 0; nOutChannels = (UWord8) st_ivas->hDecoderConfig->nchan_out; nSamplesRendered = 0; + move16(); + move16(); + move16(); - IF( EQ_16( nSamplesPerChannel, 0 ) ) + IF( nSamplesPerChannel == 0 ) { return IVAS_ERR_WRONG_PARAMS; } @@ -2728,48 +3050,53 @@ ivas_error IVAS_DEC_VoIP_GetSamples( /* make sure that the FIFO after decoder/scaler contains at least one sound card frame (i.e. 20ms) */ WHILE( LT_16( nSamplesRendered, nSamplesPerChannel ) ) { - IF( EQ_16( hIvasDec->nSamplesAvailableNext, 0 ) ) + IF( hIvasDec->nSamplesAvailableNext == 0 ) { Word16 nSamplesBuffered; nSamplesBuffered = 0; + move16(); IF( hIvasDec->hasBeenFedFirstGoodFrame ) { - IF( ( error = IVAS_DEC_GetBufferedNumberOfSamples( hIvasDec, &nSamplesBuffered ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = IVAS_DEC_GetBufferedNumberOfSamples( hIvasDec, &nSamplesBuffered ) ), IVAS_ERR_OK ) ) { return error; } } extBufferedSamples = add( nSamplesRendered, nSamplesBuffered ); - extBufferedTime_ms = extBufferedSamples * 1000 / hDecoderConfig->output_Fs; + Word16 exp; + extBufferedTime_ms = BASOP_Util_Divide3232_Scale( imult3216( extBufferedSamples, 1000 ), hDecoderConfig->output_Fs, &exp ); + extBufferedTime_ms = (UWord32) W_shr( extBufferedTime_ms, 15 - exp ); dataUnit = NULL; /* pop one access unit from the jitter buffer */ result = JB4_PopDataUnit( hVoIP->hJBM, systemTimestamp_ms, extBufferedTime_ms, &dataUnit, &scale, &maxScaling ); - IF( NE_16( result, 0 ) ) + IF( result != 0 ) { return IVAS_ERR_UNKNOWN; } #ifdef IVAS_FLOAT_FIXED - IF( GT_32( maxScaling, 20 ) ) + if ( GT_32( maxScaling, 20 ) ) { maxScaling = 20; move16(); } #endif - maxScaling = maxScaling * hDecoderConfig->output_Fs / 1000; + maxScaling = Mult_32_32( imult3216( hDecoderConfig->output_Fs, (Word16) maxScaling ), INV_1000_Q31 ); /* avoid time scaling multiple times in one sound card slot */ - IF( NE_32( scale, 100U ) ) + IF( NE_64( scale, 100U ) ) { IF( timeScalingDone ) { scale = 100; + move32(); } ELSE { timeScalingDone = 1; + move16(); } } @@ -2777,13 +3104,15 @@ ivas_error IVAS_DEC_VoIP_GetSamples( IF( LT_32( scale, APA_MIN_SCALE ) ) { scale = APA_MIN_SCALE; + move32(); } ELSE IF( GT_32( scale, APA_MAX_SCALE ) ) { scale = APA_MAX_SCALE; + move32(); } - IF( ( error = IVAS_DEC_VoIP_SetScale( hIvasDec, (Word16) maxScaling, (Word16) scale ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = IVAS_DEC_VoIP_SetScale( hIvasDec, (Word16) maxScaling, (Word16) scale ) ), IVAS_ERR_OK ) ) { return error; } @@ -2796,7 +3125,7 @@ ivas_error IVAS_DEC_VoIP_GetSamples( bsCompactToSerial( dataUnit->data, hIvasDec->hVoIP->bs_conversion_buf, dataUnit->dataSize ); - IF( ( error = IVAS_DEC_FeedFrame_Serial( hIvasDec, hIvasDec->hVoIP->bs_conversion_buf, dataUnit->dataSize, 0 ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = IVAS_DEC_FeedFrame_Serial( hIvasDec, hIvasDec->hVoIP->bs_conversion_buf, dataUnit->dataSize, 0 ) ), IVAS_ERR_OK ) ) { return error; } @@ -2804,7 +3133,7 @@ ivas_error IVAS_DEC_VoIP_GetSamples( ELSE IF( hIvasDec->hasDecodedFirstGoodFrame ) { /* Decoder has been initialized with first good frame - do PLC */ - IF( ( error = IVAS_DEC_FeedFrame_Serial( hIvasDec, hIvasDec->hVoIP->bs_conversion_buf, 0, 1 ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = IVAS_DEC_FeedFrame_Serial( hIvasDec, hIvasDec->hVoIP->bs_conversion_buf, 0, 1 ) ), IVAS_ERR_OK ) ) { return error; } @@ -2812,6 +3141,7 @@ ivas_error IVAS_DEC_VoIP_GetSamples( #ifdef SUPPORT_JBM_TRACEFILE /* jbmWriterFn and jbmWriter may be NULL if tracefile writing was not requested on CLI */ + test(); IF( jbmWriterFn != NULL && jbmWriter != NULL ) { /* write JBM trace data entry */ @@ -2825,7 +3155,7 @@ ivas_error IVAS_DEC_VoIP_GetSamples( #endif IF( dataUnit ) { - IF( NE_16( dataUnit->partial_frame, 0 ) ) + IF( dataUnit->partial_frame != 0 ) { hVoIP->lastDecodedWasActive = 1; } @@ -2833,6 +3163,7 @@ ivas_error IVAS_DEC_VoIP_GetSamples( { hVoIP->lastDecodedWasActive = !dataUnit->silenceIndicator; } + move16(); /* data unit memory is no longer used */ JB4_FreeDataUnit( hVoIP->hJBM, dataUnit ); @@ -2842,6 +3173,8 @@ ivas_error IVAS_DEC_VoIP_GetSamples( { hIvasDec->nSamplesAvailableNext = hIvasDec->nSamplesFrame; hIvasDec->nSamplesRendered = 0; + move16(); + move16(); } } @@ -2850,11 +3183,13 @@ ivas_error IVAS_DEC_VoIP_GetSamples( { /* codec mode to use not known yet - simply output silence */ /* directly set output zero */ - Word16 nSamplesToZero = min( nSamplesPerChannel, hIvasDec->nSamplesAvailableNext ); - set_s( pcmBuf + nSamplesRendered * nOutChannels, 0, nSamplesToZero * nOutChannels ); + Word16 nSamplesToZero = s_min( nSamplesPerChannel, hIvasDec->nSamplesAvailableNext ); + set16_fx( pcmBuf + imult1616( nSamplesRendered, nOutChannels ), 0, imult1616( nSamplesToZero, nOutChannels ) ); nSamplesRendered = add( nSamplesRendered, nSamplesToZero ); hIvasDec->nSamplesRendered = add( hIvasDec->nSamplesRendered, nSamplesToZero ); hIvasDec->nSamplesAvailableNext = sub( hIvasDec->nSamplesAvailableNext, nSamplesToZero ); + move16(); + move16(); } ELSE { @@ -2863,7 +3198,7 @@ ivas_error IVAS_DEC_VoIP_GetSamples( nSamplesToRender = sub( nSamplesPerChannel, nSamplesRendered ); /* render IVAS frames directly to the output buffer */ - IF( ( error = IVAS_DEC_GetSamples( hIvasDec, nSamplesToRender, pcmBuf + nSamplesRendered * nOutChannels, &nSamplesRendered_loop, &tmp ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = IVAS_DEC_GetSamples( hIvasDec, nSamplesToRender, pcmBuf + imult1616( nSamplesRendered, nOutChannels ), &nSamplesRendered_loop, &tmp ) ), IVAS_ERR_OK ) ) { return error; } @@ -2894,8 +3229,10 @@ ivas_error IVAS_DEC_Flush( UWord16 nSamplesFlushedLocal; *nSamplesFlushed = s_min( nSamplesPerChannel, hIvasDec->nSamplesAvailableNext ); + move16(); nSamplesToRender = (UWord16) *nSamplesFlushed; + move16(); /* render IVAS frames */ error = IVAS_DEC_GetRenderedSamples( hIvasDec, nSamplesToRender, &nSamplesFlushedLocal, &hIvasDec->nSamplesAvailableNext, pcmBuf ); @@ -2914,7 +3251,8 @@ bool IVAS_DEC_VoIP_IsEmpty( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ const Word16 nSamplesAsked ) { - return ( EQ_16( JB4_bufferedDataUnits( hIvasDec->hVoIP->hJBM ), 0 ) && LT_16( hIvasDec->nSamplesAvailableNext, nSamplesAsked ) ); + test(); + return ( JB4_bufferedDataUnits( hIvasDec->hVoIP->hJBM ) == 0 && LT_16( hIvasDec->nSamplesAvailableNext, nSamplesAsked ) ); } @@ -2929,6 +3267,8 @@ ivas_error IVAS_DEC_VoIP_Get_CA_offset( Word16 *optimum_offset, Word16 *FEC_hi ) { + test(); + test(); IF( ( hIvasDec == NULL || hIvasDec->hVoIP == NULL || hIvasDec->hVoIP->hJBM == NULL ) ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; @@ -2936,6 +3276,8 @@ ivas_error IVAS_DEC_VoIP_Get_CA_offset( *optimum_offset = JB4_getFECoffset( hIvasDec->hVoIP->hJBM ); *FEC_hi = JB4_FECoffset( hIvasDec->hVoIP->hJBM ); + move16(); + move16(); return IVAS_ERR_OK; } @@ -2995,6 +3337,11 @@ static void store_JbmData( JbmTraceData->lastDecodedWasActive = hVoIP->lastDecodedWasActive; JbmTraceData->output_Fs = output_Fs; JbmTraceData->dataUnit_flag = dataUnit != NULL; + move16(); + move16(); + move16(); + move32(); + move32(); IF( dataUnit != NULL ) { JbmTraceData->sequenceNumber = dataUnit->sequenceNumber; @@ -3002,6 +3349,11 @@ static void store_JbmData( JbmTraceData->rcvTime = dataUnit->rcvTime; JbmTraceData->partial_frame = dataUnit->partial_frame; JbmTraceData->partialCopyOffset = dataUnit->partialCopyOffset; + move16(); + move16(); + move16(); + move32(); + move32(); } return; @@ -3164,7 +3516,7 @@ static ivas_error printConfigInfo_dec( { fprintf( stdout, "Bitrate: %.2f kbps\n", (float) st_ivas->hDecoderConfig->ivas_total_brate / 1000 ); - IF( LE_32( st_ivas->hDecoderConfig->ivas_total_brate, 0 ) ) + IF( st_ivas->hDecoderConfig->ivas_total_brate <= 0 ) { IF( EQ_16( bitstreamformat, G192 ) ) { @@ -3227,7 +3579,7 @@ static ivas_error printConfigInfo_dec( } ELSE IF( EQ_16( (Word16) st_ivas->ivas_format, MC_FORMAT ) ) { - IF( ( error = get_channel_config( st_ivas->transport_config, &config_str[0] ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = get_channel_config( st_ivas->transport_config, &config_str[0] ) ), IVAS_ERR_OK ) ) { return error; } @@ -3241,9 +3593,12 @@ static ivas_error printConfigInfo_dec( } output_config = st_ivas->hDecoderConfig->output_config; + move16(); get_channel_config( output_config, &config_str[0] ); fprintf( stdout, "Output configuration: %s\n", config_str ); + test(); + test(); IF( ( EQ_16( (Word16) output_config, IVAS_AUDIO_CONFIG_BINAURAL ) || EQ_16( (Word16) output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) || EQ_16( (Word16) output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) ) { fprintf( stdout, "Render framesize: %dms\n", get_render_frame_size_ms( st_ivas->hDecoderConfig->render_framesize ) ); @@ -3373,7 +3728,10 @@ static ivas_error evs_dec_main( hCoreCoder = st_ivas->hSCE[0]->hCoreCoder; hCoreCoder[0]->total_brate = st_ivas->hDecoderConfig->ivas_total_brate; hCoreCoder[0]->total_num_bits = st_ivas->num_bits; + move16(); + move32(); hCoreCoder[0]->output_frame_fx = extract_l( Mult_32_16( hCoreCoder[0]->output_Fs, 0x0290 ) ); + move16(); mdct_switching_dec( hCoreCoder[0] ); FOR( ch = 0; ch < MAX_OUTPUT_CHANNELS_IN_DIEGETIC_PAN; ch++ ) @@ -3395,7 +3753,7 @@ static ivas_error evs_dec_main( #ifndef IVAS_FLOAT_FIXED IF( ( error = amr_wb_dec( hCoreCoder[0], st_ivas->mem_hp20_out[0], p_output[0] ) ) != IVAS_ERR_OK ) #else - IF( ( error = amr_wb_dec_fx( output_16, hCoreCoder[0] ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = amr_wb_dec_fx( output_16, hCoreCoder[0] ) ), IVAS_ERR_OK ) ) #endif { return error; @@ -3406,7 +3764,7 @@ static ivas_error evs_dec_main( #ifndef IVAS_FLOAT_FIXED IF( ( error = evs_dec( hCoreCoder[0], st_ivas->mem_hp20_out[0], p_output[0], FRAMEMODE_NORMAL ) ) != IVAS_ERR_OK ) #else - IF( ( error = evs_dec_fx( hCoreCoder[0], output_16, FRAMEMODE_NORMAL ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = evs_dec_fx( hCoreCoder[0], output_16, FRAMEMODE_NORMAL ) ), IVAS_ERR_OK ) ) #endif { return error; @@ -3415,12 +3773,12 @@ static ivas_error evs_dec_main( } ELSE { - IF( EQ_16( hCoreCoder[0]->bfi, 0 ) ) + IF( hCoreCoder[0]->bfi == 0 ) { #ifndef IVAS_FLOAT_FIXED IF( ( error = evs_dec( hCoreCoder[0], st_ivas->mem_hp20_out[0], p_output[0], FRAMEMODE_NORMAL ) ) != IVAS_ERR_OK ) #else - IF( ( error = evs_dec_fx( hCoreCoder[0], output_16, FRAMEMODE_NORMAL ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = evs_dec_fx( hCoreCoder[0], output_16, FRAMEMODE_NORMAL ) ), IVAS_ERR_OK ) ) #endif { return error; @@ -3431,7 +3789,7 @@ static ivas_error evs_dec_main( #ifndef IVAS_FLOAT_FIXED IF( ( error = evs_dec( hCoreCoder[0], st_ivas->mem_hp20_out[0], p_output[0], FRAMEMODE_FUTURE ) ) != IVAS_ERR_OK ) #else - IF( ( error = evs_dec_fx( hCoreCoder[0], output_16, FRAMEMODE_FUTURE ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = evs_dec_fx( hCoreCoder[0], output_16, FRAMEMODE_FUTURE ) ), IVAS_ERR_OK ) ) #endif { return error; @@ -3442,7 +3800,7 @@ static ivas_error evs_dec_main( #ifndef IVAS_FLOAT_FIXED IF( ( error = evs_dec( hCoreCoder[0], st_ivas->mem_hp20_out[0], p_output[0], FRAMEMODE_MISSING ) ) != IVAS_ERR_OK ) #else - IF( ( error = evs_dec_fx( hCoreCoder[0], output_16, FRAMEMODE_MISSING ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = evs_dec_fx( hCoreCoder[0], output_16, FRAMEMODE_MISSING ) ), IVAS_ERR_OK ) ) #endif { return error; @@ -3451,6 +3809,7 @@ static ivas_error evs_dec_main( } st_ivas->BER_detect = hCoreCoder[0]->BER_detect; + move16(); #ifdef IVAS_FLOAT_FIXED FOR( Word16 i = 0; i < nOutSamples; i++ ) { @@ -3510,7 +3869,14 @@ static ivas_error input_format_API_to_internal( SWITCH( input_format ) { case IVAS_DEC_INPUT_FORMAT_G192: - *bitstream_format_internal = is_voip_enabled ? VOIP_G192_RTP : G192; + IF( is_voip_enabled ) + { + *bitstream_format_internal = VOIP_G192_RTP; + } + ELSE + { + *bitstream_format_internal = G192; + } *sdp_hf_only = 0; BREAK; case IVAS_DEC_INPUT_FORMAT_MIME: @@ -3532,6 +3898,8 @@ static ivas_error input_format_API_to_internal( BREAK; } + move16(); + move16(); return IVAS_ERR_OK; } @@ -3550,6 +3918,7 @@ static ivas_error IVAS_DEC_VoIP_reconfigure( Word16 apa_buffer_size; apa_buffer_size = hIvasDec->nSamplesFrame; + move16(); IF( hIvasDec->apaExecBuffer == NULL ) { @@ -3563,6 +3932,7 @@ static ivas_error IVAS_DEC_VoIP_reconfigure( startQuality = hIvasDec->tsm_quality; apa_buffer_size = APA_BUF_PER_CHANNEL; + move16(); /* get current renderer type*/ hDecoderConfig = hIvasDec->st_ivas->hDecoderConfig; @@ -3591,18 +3961,24 @@ static ivas_error IVAS_DEC_VoIP_reconfigure( return IVAS_ERR_INIT_ERROR; } + move16(); + move16(); + test(); + test(); + test(); + test(); IF( NE_32( (Word32) apa_init( &hIvasDec->hTimeScaler, nTransportChannels ), IVAS_ERR_OK ) || - NE_16( (Word16) apa_set_rate( hIvasDec->hTimeScaler, hDecoderConfig->output_Fs ), 0 ) || - NE_16( (Word16) apa_set_complexity_options( hIvasDec->hTimeScaler, wss, css ), 0 ) || - NE_16( (Word16) apa_set_quality( hIvasDec->hTimeScaler, startQuality, 4, 4 ), 0 ) || - NE_16( (Word16) apa_set_renderer_granularity( hIvasDec->hTimeScaler, l_ts ), 0 ) ) + apa_set_rate( hIvasDec->hTimeScaler, hDecoderConfig->output_Fs ) != 0 || + apa_set_complexity_options( hIvasDec->hTimeScaler, wss, css ) != 0 || + apa_set_quality( hIvasDec->hTimeScaler, startQuality, 4, 4 ) != 0 || + apa_set_renderer_granularity( hIvasDec->hTimeScaler, l_ts ) != 0 ) { return IVAS_ERR_INIT_ERROR; } IF( EQ_16( (Word16) hIvasDec->mode, IVAS_DEC_MODE_EVS ) ) { - IF( NE_16( (Word16) apa_set_evs_compat_mode( hIvasDec->hTimeScaler, true ), 0 ) ) + IF( apa_set_evs_compat_mode( hIvasDec->hTimeScaler, true ) != 0 ) { return IVAS_ERR_INIT_ERROR; } @@ -3616,12 +3992,12 @@ static ivas_error IVAS_DEC_VoIP_reconfigure( set_zero( hIvasDec->apaExecBuffer, apa_buffer_size * nTransportChannels ); #ifdef IVAS_FLOAT_FIXED - IF( ( hIvasDec->apaExecBuffer_fx = malloc( sizeof( Word32 ) * apa_buffer_size * nTransportChannels ) ) == NULL ) + IF( ( hIvasDec->apaExecBuffer_fx = malloc( sizeof( Word32 ) * imult1616( apa_buffer_size, (Word16) nTransportChannels ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate VoIP handle" ); } - set_zero_fx( hIvasDec->apaExecBuffer_fx, apa_buffer_size * nTransportChannels ); + set_zero_fx( hIvasDec->apaExecBuffer_fx, imult1616( apa_buffer_size, (Word16) nTransportChannels ) ); #endif } } @@ -3629,11 +4005,12 @@ static ivas_error IVAS_DEC_VoIP_reconfigure( { IF( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm ) { - IF( NE_16( (Word16) apa_reconfigure( hIvasDec->hTimeScaler, nTransportChannels, l_ts ), 0 ) ) + IF( apa_reconfigure( hIvasDec->hTimeScaler, nTransportChannels, l_ts ) != 0 ) { return IVAS_ERR_INIT_ERROR; } apa_buffer_size = APA_BUF_PER_CHANNEL; + move16(); free( hIvasDec->apaExecBuffer ); IF( ( hIvasDec->apaExecBuffer = malloc( sizeof( float ) * apa_buffer_size * nTransportChannels ) ) == NULL ) { @@ -3643,17 +4020,18 @@ static ivas_error IVAS_DEC_VoIP_reconfigure( #ifdef IVAS_FLOAT_FIXED free( hIvasDec->apaExecBuffer_fx ); - IF( ( hIvasDec->apaExecBuffer_fx = malloc( sizeof( Word32 ) * apa_buffer_size * nTransportChannels ) ) == NULL ) + IF( ( hIvasDec->apaExecBuffer_fx = malloc( sizeof( Word32 ) * imult1616( apa_buffer_size, (Word16) nTransportChannels ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate VoIP handle" ); } - set_zero_fx( hIvasDec->apaExecBuffer_fx, apa_buffer_size * nTransportChannels ); + set_zero_fx( hIvasDec->apaExecBuffer_fx, imult1616( apa_buffer_size, (Word16) nTransportChannels ) ); #endif } /* realloc apa_exe_buffer */ } hIvasDec->nTransportChannelsOld = nTransportChannels; + move16(); return IVAS_ERR_OK; } diff --git a/lib_dec/lp_exc_d_fx.c b/lib_dec/lp_exc_d_fx.c index 0eb99d413..40318b376 100644 --- a/lib_dec/lp_exc_d_fx.c +++ b/lib_dec/lp_exc_d_fx.c @@ -61,7 +61,7 @@ void lp_filt_exc_dec_fx( { /* pointer positioning to avoid doing it inside the loop */ test(); - IF( codec_mode == MODE2 && L_frame == L_FRAME16k ) + IF( EQ_16( codec_mode, MODE2 ) && EQ_16( L_frame, L_FRAME16k ) ) { fac_n = 6881 /*0.21f Q15*/; fac_m = 19005 /*0.58f Q15*/; @@ -71,12 +71,14 @@ void lp_filt_exc_dec_fx( fac_n = 5898 /*0.18f Q15*/; fac_m = 20972 /*0.64f Q15*/; } + move16(); + move16(); FOR( i = 0; i < L_subfr; i++ ) { - L_tmp = L_mult( fac_n, exc[i - 1 + i_subfr] ); - L_tmp = L_mac( L_tmp, fac_m, exc[i + 0 + i_subfr] ); - code[i] = mac_r( L_tmp, fac_n, exc[i + 1 + i_subfr] ); + L_tmp = L_mult( fac_n, exc[add( sub( i, 1 ), i_subfr )] ); + L_tmp = L_mac( L_tmp, fac_m, exc[add( i /*+ 0 */, i_subfr )] ); + code[i] = mac_r( L_tmp, fac_n, exc[add( add( i, 1 ), i_subfr )] ); move16(); } diff --git a/lib_dec/tonalMDCTconcealment_fx.c b/lib_dec/tonalMDCTconcealment_fx.c index 9ebbc635e..578bbd558 100644 --- a/lib_dec/tonalMDCTconcealment_fx.c +++ b/lib_dec/tonalMDCTconcealment_fx.c @@ -519,8 +519,21 @@ void TonalMDCTConceal_SaveFreqSignal_ivas_fx( FOR( i = 0; i < nNewSamples; i++ ) { + Word16 tmp = 0; + if (mdctSpectrum[i] != 0) + { + tmp = 1; + move16(); + } hTonalMDCTConc->lastBlockData.spectralData[i] = extract_h( L_shl( mdctSpectrum[i], s ) ); move16(); + + test(); + if ( hTonalMDCTConc->lastBlockData.spectralData[i] == 0 && EQ_16( tmp, 1 ) ) + { + hTonalMDCTConc->lastBlockData.spectralData[i] = 1; + move16(); + } } hTonalMDCTConc->lastBlockData.spectralData_exp = sub( mdctSpectrum_exp, s ); move16(); -- GitLab From 920b1add1e574476f9ee00a0d64521981b85b45c Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Tue, 25 Jun 2024 12:15:16 +0530 Subject: [PATCH 2/4] clang formatting changes --- lib_dec/dec_pit_exc_fx.c | 2 +- lib_dec/dec_ppp_fx.c | 2 +- lib_dec/dec_prm.c | 2 +- lib_dec/dec_prm_fx.c | 22 +++++++++++----------- lib_dec/ivas_td_low_rate_dec.c | 6 +++--- lib_dec/jbm_jb4sb.c | 2 +- lib_dec/tonalMDCTconcealment_fx.c | 2 +- 7 files changed, 19 insertions(+), 19 deletions(-) diff --git a/lib_dec/dec_pit_exc_fx.c b/lib_dec/dec_pit_exc_fx.c index f456e73a7..aba8af9b2 100644 --- a/lib_dec/dec_pit_exc_fx.c +++ b/lib_dec/dec_pit_exc_fx.c @@ -150,7 +150,7 @@ void dec_pit_exc_fx( test(); test(); test(); - IF ( ( ( GE_32( st_fx->core_brate, MIN_RATE_FCB ) || ( EQ_16( st_fx->GSC_noisy_speech, 1 ) && ( ( EQ_16( st_fx->L_frame, L_FRAME ) && GE_32( st_fx->core_brate, ACELP_13k20 ) ) || ( EQ_16( st_fx->L_frame, L_FRAME16k ) && GE_32( st_fx->core_brate, GSC_H_RATE_STG ) ) || st_fx->GSC_IVAS_mode == 0 ) ) ) && EQ_16( L_subfr_fx, L_SUBFR ) ) ) + IF( ( ( GE_32( st_fx->core_brate, MIN_RATE_FCB ) || ( EQ_16( st_fx->GSC_noisy_speech, 1 ) && ( ( EQ_16( st_fx->L_frame, L_FRAME ) && GE_32( st_fx->core_brate, ACELP_13k20 ) ) || ( EQ_16( st_fx->L_frame, L_FRAME16k ) && GE_32( st_fx->core_brate, GSC_H_RATE_STG ) ) || st_fx->GSC_IVAS_mode == 0 ) ) ) && EQ_16( L_subfr_fx, L_SUBFR ) ) ) { use_fcb = 1; move16(); diff --git a/lib_dec/dec_ppp_fx.c b/lib_dec/dec_ppp_fx.c index facd78f1d..cd4d6462f 100644 --- a/lib_dec/dec_ppp_fx.c +++ b/lib_dec/dec_ppp_fx.c @@ -78,7 +78,7 @@ ivas_error decod_ppp_fx( deemph_lpc_fx( p_Aq_curr_fx, p_Aq_old_fx, LPC_de_curr_fx, LPC_de_old_fx, 0 ); /*LPC in Q12 */ - IF ( ( error = ppp_voiced_decoder_fx( st_fx, excQ_ppp_fx, LPC_de_curr_fx, exc_fx, pitch_fx, bfi ) ) != IVAS_ERR_OK ) + IF( ( error = ppp_voiced_decoder_fx( st_fx, excQ_ppp_fx, LPC_de_curr_fx, exc_fx, pitch_fx, bfi ) ) != IVAS_ERR_OK ) { return error; } diff --git a/lib_dec/dec_prm.c b/lib_dec/dec_prm.c index 07f7d6de1..c10b3f587 100644 --- a/lib_dec/dec_prm.c +++ b/lib_dec/dec_prm.c @@ -217,7 +217,7 @@ void getTCXMode_ivas_fx( /*Core extended mode mapping for correct PLC classification*/ st->core_ext_mode = st->coder_type; move16(); - if( EQ_16( st->coder_type, INACTIVE ) ) + if ( EQ_16( st->coder_type, INACTIVE ) ) { st->core_ext_mode = UNVOICED; move16(); diff --git a/lib_dec/dec_prm_fx.c b/lib_dec/dec_prm_fx.c index d30f407d6..f238f3e3a 100644 --- a/lib_dec/dec_prm_fx.c +++ b/lib_dec/dec_prm_fx.c @@ -135,7 +135,7 @@ void dec_prm_hm_fx( { tmp = 0; move16(); - if( GE_16( L_frame, 256 ) ) + if ( GE_16( L_frame, 256 ) ) { tmp = 1; move16(); @@ -225,7 +225,7 @@ void getTCXparam_fx( nSubframes = 1; move16(); - if( EQ_16( core, TCX_10_CORE ) ) + if ( EQ_16( core, TCX_10_CORE ) ) { nSubframes = 2; move16(); @@ -353,7 +353,7 @@ void getTCXparam_fx( lg = add( lg, st->hTcxCfg->tcx_offset ); lgFB = add( lgFB, shr( lgFB, sub( 3, nSubframes ) ) ); - if( st->hTcxCfg->lfacNext < 0 ) + if ( st->hTcxCfg->lfacNext < 0 ) { lg = sub( lg, st->hTcxCfg->lfacNext ); } @@ -600,7 +600,7 @@ void dec_prm_fx( Mpy_32_16_ss( st->total_brate, 5243, &L_tmp, &lsb ); /* 5243 is 1/50 in Q18. (0+18-15=3) */ num_bits = extract_l( L_shr( L_tmp, 3 ) ); /* Q0 */ assert( num_bits == st->total_brate / 50 ); - if( EQ_16( FrameSizeConfig[n].frame_bits, num_bits ) ) + if ( EQ_16( FrameSizeConfig[n].frame_bits, num_bits ) ) { st->bits_frame_core = add( st->bits_frame_core, FrameSizeConfig[n].bandwidth_bits ); BREAK; @@ -650,7 +650,7 @@ void dec_prm_fx( ind = get_next_indice( st, 2 ); st->clas_dec = ONSET; move16(); - if( ind == 0 ) + if ( ind == 0 ) { st->clas_dec = UNVOICED_CLAS; move16(); @@ -659,7 +659,7 @@ void dec_prm_fx( { st->clas_dec = UNVOICED_TRANSITION; move16(); - if( GE_16( st->last_good, VOICED_TRANSITION ) ) + if ( GE_16( st->last_good, VOICED_TRANSITION ) ) { st->clas_dec = VOICED_TRANSITION; move16(); @@ -851,7 +851,7 @@ void dec_prm_fx( st->hTcxCfg->tcx_last_overlap_mode = st->hTcxCfg->tcx_curr_overlap_mode; move16(); test(); - if( ( NE_16( st->core, TCX_10_CORE ) ) && ( EQ_16( st->hTcxCfg->tcx_curr_overlap_mode, FULL_OVERLAP ) ) ) + if ( ( NE_16( st->core, TCX_10_CORE ) ) && ( EQ_16( st->hTcxCfg->tcx_curr_overlap_mode, FULL_OVERLAP ) ) ) { st->hTcxCfg->tcx_last_overlap_mode = ALDO_WINDOW; move16(); @@ -1078,7 +1078,7 @@ void dec_prm_fx( n = ACELP_LTP_BITS_SFR[st->acelp_cfg.ltp_mode][sfr]; move16(); - IF ( n != 0 ) + IF( n != 0 ) { prm[j] = get_next_indice( st, n ); j = add( j, 1 ); @@ -1086,7 +1086,7 @@ void dec_prm_fx( } /* Adaptive codebook filtering (1 bit) */ - IF ( EQ_16( st->acelp_cfg.ltf_mode, 2 ) ) + IF( EQ_16( st->acelp_cfg.ltf_mode, 2 ) ) { prm[j] = get_next_indice( st, 1 ); j = add( j, 1 ); @@ -1188,7 +1188,7 @@ void dec_prm_fx( /* Pitch lag (5, or 8 bits) */ n = ACELP_LTP_BITS_SFR[ltp_mode][sfr]; move16(); - IF ( n != 0 ) + IF( n != 0 ) { prm[j] = get_next_indice( st, n ); j = add( j, 1 ); @@ -1320,7 +1320,7 @@ void dec_prm_fx( IF( st->hTcxCfg->fIsTNSAllowed ) { - SetTnsConfig( st->hTcxCfg, 1, (Word16)EQ_16(st->last_core_from_bs , ACELP_CORE) ); + SetTnsConfig( st->hTcxCfg, 1, (Word16) EQ_16( st->last_core_from_bs, ACELP_CORE ) ); ReadTnsData( st->hTcxCfg->pCurrentTnsConfig, st, &nTnsBits, prm + j, &nTnsParams ); j = add( j, nTnsParams ); diff --git a/lib_dec/ivas_td_low_rate_dec.c b/lib_dec/ivas_td_low_rate_dec.c index 09d25ad12..4731bf883 100644 --- a/lib_dec/ivas_td_low_rate_dec.c +++ b/lib_dec/ivas_td_low_rate_dec.c @@ -291,17 +291,17 @@ void tdm_low_rate_dec_fx( tmp_nb_bits_tot = st->next_bit_pos; move16(); - if( EQ_16( st->element_mode, IVAS_CPE_TD ) ) + if ( EQ_16( st->element_mode, IVAS_CPE_TD ) ) { tmp_nb_bits_tot = add( tmp_nb_bits_tot, TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS ); } - if( EQ_16( st->tdm_LRTD_flag, 1 ) ) + if ( EQ_16( st->tdm_LRTD_flag, 1 ) ) { tmp_nb_bits_tot = sub( tmp_nb_bits_tot, STEREO_BITS_TCA ); } - if( st->extl_brate_orig > 0 ) + if ( st->extl_brate_orig > 0 ) { /* subtract 1 bit for TBE/BWE BWE flag (bit counted in extl_brate) */ tmp_nb_bits_tot = sub( tmp_nb_bits_tot, 1 ); diff --git a/lib_dec/jbm_jb4sb.c b/lib_dec/jbm_jb4sb.c index 0e43a94a3..c04546161 100644 --- a/lib_dec/jbm_jb4sb.c +++ b/lib_dec/jbm_jb4sb.c @@ -3269,4 +3269,4 @@ static int16_t JB4_inputBufferCompareFunction( } #endif /* IVAS_FLOAT_FIXED */ -#undef WMC_TOOL_SKIP \ No newline at end of file +#undef WMC_TOOL_SKIP diff --git a/lib_dec/tonalMDCTconcealment_fx.c b/lib_dec/tonalMDCTconcealment_fx.c index 578bbd558..9881d47ec 100644 --- a/lib_dec/tonalMDCTconcealment_fx.c +++ b/lib_dec/tonalMDCTconcealment_fx.c @@ -520,7 +520,7 @@ void TonalMDCTConceal_SaveFreqSignal_ivas_fx( FOR( i = 0; i < nNewSamples; i++ ) { Word16 tmp = 0; - if (mdctSpectrum[i] != 0) + if ( mdctSpectrum[i] != 0 ) { tmp = 1; move16(); -- GitLab From e1dfb4f98313f9da8e3d7c65f6fcc1decfed939c Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Tue, 25 Jun 2024 12:17:35 +0530 Subject: [PATCH 3/4] Floating point code build fix [x] With IVAS_FLOAT_FIXED macro commented, build break fixed --- lib_dec/jbm_pcmdsp_apa.c | 71 +++++++++++++++++++++++++++++++-- lib_dec/lsf_dec_fx.c | 2 + lib_enc/ivas_ism_metadata_enc.c | 2 +- lib_rend/lib_rend.c | 56 +++++++++++++++++++++++++- 4 files changed, 126 insertions(+), 5 deletions(-) diff --git a/lib_dec/jbm_pcmdsp_apa.c b/lib_dec/jbm_pcmdsp_apa.c index cc0703cb0..72e57c5b5 100644 --- a/lib_dec/jbm_pcmdsp_apa.c +++ b/lib_dec/jbm_pcmdsp_apa.c @@ -477,6 +477,73 @@ uint8_t apa_reconfigure( #endif /* Sets the audio configuration. */ +#ifndef IVAS_FLOAT_FIXED +bool apa_set_rate( + apa_state_t *ps, + const int32_t output_Fs ) +{ + /* make sure pointer is valid */ + if ( ps == NULL ) + { + return 1; + } + + /* check range */ + if ( ( output_Fs < APA_MIN_RATE ) || ( output_Fs > APA_MAX_RATE ) ) + { + return 1; + } + + /* reset state struct */ + apa_reset( ps ); + + /* copy rate to state struct */ + ps->rate = (uint16_t) output_Fs; + + if ( ps->num_channels > APA_MAX_NUM_CHANNELS ) + { + return 1; + } + + /* + * several other parameters depend on the sampling rate + * and are set below. Some "magic numbers" are used here + * which are based on typical values of a "pitch" in + * human voice. The pitch length is the period of the + * base frequency and is usually assumed to be 40-240 + * samples at 16 kHz. + */ + + /* set segment size */ + /* in the order of a pitch, set to 160 samples at 16 kHz */ + /* used for windowing and as the correlation length, i.e., */ + /* the size of the template segment. */ + ps->l_seg = ( ps->rate / 100 ) * ps->num_channels; + + /* init Hann window */ + /* Note: l_win < APA_BUF_PER_CHANNEL is required */ + /* Length of Hann window should be independent of + * number of channels - same window applied to all channels */ + ps->l_halfwin = ps->rate / 100; + hannWindow( ps->l_halfwin * 2, ps->win ); + + /* set frame size */ + /* set to 320 samples at 16 kHz */ + ps->l_frm = ( ps->rate / FRAMES_PER_SEC ) * ps->num_channels; + + /* set minimum pitch */ + /* set to 40 samples at 16 kHz */ + /* (defines min change in number of samples, i.e., abs(l_in-l_out) >= p_min) */ + ps->p_min = ( ps->rate / 400 ) * ps->num_channels; + + /* set search length */ + /* must cover one pitch, set to 200 samples at 16 kHz */ + /* (the resulting maximum pitch is then p_min+l_search = 240 samples at 16 kHz) */ + ps->l_search = ( ps->rate / 80 ) * ps->num_channels; + + return 0; +} +#else bool apa_set_rate( apa_state_t *ps, const Word32 output_Fs ) @@ -548,7 +615,6 @@ bool apa_set_rate( ps->l_search = (UWord16) imult3216( Mult_32_16( ps->rate, INV_80_Q15 ), ps->num_channels ); move16(); -#ifdef IVAS_FLOAT_FIXED ps->win_fx = pcmdsp_window_hann_640; move16(); ps->l_halfwin = 320; @@ -591,10 +657,9 @@ bool apa_set_rate( * but for simplicity can be taken as l_seg / 4 */ ps->signalScaleForCorrelation = getSignalScaleForCorrelation( ps->rate ); move16(); -#endif return 0; } - +#endif /* Set scaling. */ #ifdef IVAS_FLOAT_FIXED diff --git a/lib_dec/lsf_dec_fx.c b/lib_dec/lsf_dec_fx.c index 9ba2e84d7..39466c34b 100644 --- a/lib_dec/lsf_dec_fx.c +++ b/lib_dec/lsf_dec_fx.c @@ -12,6 +12,7 @@ #include "ivas_prot.h" //#include "ivas_rom_com.h" #endif +#ifdef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * Local functions *-------------------------------------------------------------------*/ @@ -985,3 +986,4 @@ void lsf_mid_dec_fx( return; } +#endif diff --git a/lib_enc/ivas_ism_metadata_enc.c b/lib_enc/ivas_ism_metadata_enc.c index 8f58798b3..12f70c3b2 100644 --- a/lib_enc/ivas_ism_metadata_enc.c +++ b/lib_enc/ivas_ism_metadata_enc.c @@ -1270,7 +1270,7 @@ ivas_error ivas_ism_metadata_enc( *ism_total_brate = 0; for ( ch = 0; ch < nchan_ism; ch++ ) { - *ism_total_brate = L_add( *ism_total_brate, ivas_interformat_brate_fx( ism_mode, nchan_ism, hSCE[ch]->element_brate, ism_imp[ch], brate_limit_flag ) ); + *ism_total_brate = L_add( *ism_total_brate, ivas_interformat_brate( ism_mode, nchan_ism, hSCE[ch]->element_brate, ism_imp[ch], brate_limit_flag ) ); move32(); if ( ism_imp[ch] > 1 && flag_omasa_ener_brate == 1 && brate_limit_flag >= 0 ) diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index ed8709301..d8599016f 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -13078,7 +13078,7 @@ ivas_error IVAS_REND_GetSamples( * * *-------------------------------------------------------------------*/ - +#ifdef IVAS_FLOAT_FIXED void IVAS_REND_Close( IVAS_REND_HANDLE *phIvasRend /* i/o: Pointer to renderer handle */ ) @@ -13132,7 +13132,61 @@ void IVAS_REND_Close( return; } +#else +void IVAS_REND_Close( + IVAS_REND_HANDLE *phIvasRend /* i/o: Pointer to renderer handle */ +) +{ + uint16_t i; + IVAS_REND_HANDLE hIvasRend; + + /* Validate function arguments */ + if ( phIvasRend == NULL || *phIvasRend == NULL ) + { + return; + } + hIvasRend = *phIvasRend; + + if ( hIvasRend->efapOutWrapper.hEfap != NULL ) + { + efap_free_data( &hIvasRend->efapOutWrapper.hEfap ); + } + + /* clear inputs */ + for ( i = 0; i < RENDERER_MAX_ISM_INPUTS; ++i ) + { + clearInputIsm( &hIvasRend->inputsIsm[i] ); + } + for ( i = 0; i < RENDERER_MAX_MC_INPUTS; ++i ) + { + clearInputMc( &hIvasRend->inputsMc[i] ); + } + for ( i = 0; i < RENDERER_MAX_SBA_INPUTS; ++i ) + { + clearInputSba( &hIvasRend->inputsSba[i] ); + } + for ( i = 0; i < RENDERER_MAX_MASA_INPUTS; ++i ) + { + clearInputMasa( &hIvasRend->inputsMasa[i] ); + } + /* clear Config. Renderer */ + ivas_render_config_close( &( hIvasRend->hRendererConfig ) ); + + ivas_limiter_close( &hIvasRend->hLimiter ); + + + closeHeadRotation( hIvasRend ); + + ivas_external_orientation_close( &hIvasRend->hExternalOrientationData ); + ivas_combined_orientation_close( &hIvasRend->hCombinedOrientationData ); + + free( hIvasRend ); + *phIvasRend = NULL; + + return; +} +#endif #ifdef IVAS_FLOAT_FIXED static ivas_error ivas_masa_ext_rend_dirac_rend_init( -- GitLab From 1db2bd414ddf803fe98c12c2f3c985eeddce2bda Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Tue, 25 Jun 2024 21:54:35 +0530 Subject: [PATCH 4/4] EVS bitexactness issue fix --- lib_dec/jbm_jb4sb.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib_dec/jbm_jb4sb.c b/lib_dec/jbm_jb4sb.c index c04546161..fb4a65206 100644 --- a/lib_dec/jbm_jb4sb.c +++ b/lib_dec/jbm_jb4sb.c @@ -52,10 +52,11 @@ #include "prot_fx2.h" #define WMC_TOOL_SKIP -#define INV_500_Q31 4294967 /*1/500 IN Q_31*/ -#define INV_20_Q15 1638 /*1/20 in Q15*/ -#define JB4_MIN( a, b ) ( ( a ) > ( b ) ? ( b ) : ( a ) ) -#define JB4_MAX( a, b ) ( ( a ) > ( b ) ? ( a ) : ( b ) ) +#define INV_500_Q31 4294967 /*1/500 IN Q_31*/ +#define DIV_600_1000_Q31 1288490189 /*600/1000 IN Q_31*/ +#define INV_20_Q31 107374183 /*1/20 in Q31*/ +#define JB4_MIN( a, b ) ( ( a ) > ( b ) ? ( b ) : ( a ) ) +#define JB4_MAX( a, b ) ( ( a ) > ( b ) ? ( a ) : ( b ) ) #define MAXOFFSET 10 @@ -1010,7 +1011,7 @@ static void JB4_adaptDtxPlayout( } h->targetPlayoutDelay = targetStartUp; move32(); - headRoom = (UWord32) W_mult0_32_32( 600, Mult_32_32( W_extract_l( W_shr( h->frameDuration, 1 ) ), INV_500_Q31 ) ); + headRoom = (UWord32) W_shr( W_mult0_32_32( DIV_600_1000_Q31, h->frameDuration ), 31 ); /* decided between shrinking/stretching */ IF( GT_64( currPlayoutDelay, W_add( targetStartUp, headRoom ) ) ) /* time shrinking */ { @@ -1431,7 +1432,7 @@ static void JB4_popFromBuffer( test(); IF( !tempDataUnit->partial_frame && !h->lastPoppedWasSilence ) { - frameoffset = extract_l( Mult_32_16( JB4_rtpTimeStampDiff( h->nextExpectedTs, tempDataUnit->timeStamp ), INV_20_Q15 ) ); + frameoffset = Mult_32_32( JB4_rtpTimeStampDiff( h->nextExpectedTs, tempDataUnit->timeStamp ), INV_20_Q31 ); test(); IF( frameoffset > 0 && LT_16( frameoffset, MAXOFFSET ) ) { @@ -1508,8 +1509,7 @@ static void JB4_popFromBuffer( test(); IF( !tempDataUnit->partial_frame && !h->lastPoppedWasSilence ) { - frameoffset = extract_l( Mult_32_16( JB4_rtpTimeStampDiff( h->nextExpectedTs, tempDataUnit->timeStamp ), INV_20_Q15 ) ); - + frameoffset = Mult_32_32( JB4_rtpTimeStampDiff( h->nextExpectedTs, tempDataUnit->timeStamp ), INV_20_Q31 ); test(); IF( ( frameoffset > 0 ) && LT_16( frameoffset, MAXOFFSET ) ) { -- GitLab