From aff676efe2424810c4b1bc1ecdeafed75ff07f06 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Sat, 18 Jan 2025 14:22:23 +0530 Subject: [PATCH 1/2] Q information updates for lib_enc files --- lib_enc/sig_clas_fx.c | 51 +++-- lib_enc/spec_center_fx.c | 39 ++-- lib_enc/swb_tbe_enc_fx.c | 8 +- lib_enc/tcq_core_enc_fx.c | 58 +++-- lib_enc/tcx_ltp_enc_fx.c | 41 ++-- lib_enc/tcx_utils_enc_fx.c | 380 +++++++++++++++++++++++-------- lib_enc/tfa_enc_fx.c | 6 +- lib_enc/tns_base_enc_fx.c | 58 +++-- lib_enc/transient_detection_fx.c | 25 +- lib_enc/transition_enc_fx.c | 86 ++++++- lib_enc/update_decision_fx.c | 22 +- lib_enc/updt_enc_fx.c | 29 ++- lib_enc/updt_tar_fx.c | 29 ++- lib_enc/vad_fx.c | 236 +++++++++++-------- lib_enc/vad_param_updt_fx.c | 23 +- lib_enc/vad_proc_fx.c | 12 +- lib_enc/vbr_average_rate_fx.c | 12 +- lib_enc/vlpc_1st_cod_fx.c | 10 +- lib_enc/vlpc_2st_cod_fx.c | 8 +- lib_enc/voiced_enc_fx.c | 155 ++++++++----- lib_enc/waveadjust_fec_cod_fx.c | 12 +- 21 files changed, 889 insertions(+), 411 deletions(-) diff --git a/lib_enc/sig_clas_fx.c b/lib_enc/sig_clas_fx.c index 501f907b6..771210ab3 100644 --- a/lib_enc/sig_clas_fx.c +++ b/lib_enc/sig_clas_fx.c @@ -44,9 +44,9 @@ Word16 signal_clas_fx( /* o : classification for current frames */ Encoder_State *st, /* i/o: encoder state structure */ - const Word16 *speech, /* i : pointer to speech signal for E computation */ - const Word32 *ee, /* i : lf/hf E ration for 2 half-frames */ - const Word16 relE, /* i : frame relative E to the long term average */ + const Word16 *speech, /* i : pointer to speech signal for E computation in Qx */ + const Word32 *ee, /* i : lf/hf E ration for 2 half-frames in Q6 */ + const Word16 relE, /* i : frame relative E to the long term average in Q8 */ const Word16 L_look, /* i : look-ahead */ Word16 *clas_mod /* o : class flag for NOOP detection */ ) @@ -58,6 +58,7 @@ Word16 signal_clas_fx( /* o : classification for current const Word16 *pt1; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif /*----------------------------------------------------------------* @@ -68,7 +69,7 @@ Word16 signal_clas_fx( /* o : classification for current *----------------------------------------------------------------*/ /* average voicing on second half-frame and look-ahead */ - Ltmp = L_mult( st->voicing_fx[1], 16384 ); + Ltmp = L_mult( st->voicing_fx[1], 16384 ); /* Q15*Q14->Q30 */ mean_voi2 = mac_r( Ltmp, st->voicing_fx[2], 16384 ); /* average spectral tilt in dB */ @@ -101,7 +102,7 @@ Word16 signal_clas_fx( /* o : classification for current } /* compute zero crossing rate */ - pt1 = speech + L_look - 1; + pt1 = speech + sub( L_look, 1 ); tmpS = shr( *pt1, 15 ); /* sets 'tmpS to -1 if *pt1 < 0 */ Ltmp = L_deposit_l( 0 ); FOR( i = 0; i < L_FRAME; i++ ) @@ -116,7 +117,7 @@ Word16 signal_clas_fx( /* o : classification for current /* compute pitch stability */ pc = add( abs_s( sub( st->pitch[1], st->pitch[0] ) ), abs_s( sub( st->pitch[2], st->pitch[1] ) ) ); st->tdm_pc = pc; - + move16(); /*-----------------------------------------------------------------* * Transform parameters to the range <0:1> * Compute the merit function @@ -135,7 +136,7 @@ Word16 signal_clas_fx( /* o : classification for current zcn = s_max( zcn, 0 ); zcn = s_min( zcn, 512 ); - Ltmp = L_mult( C_RELE_FX, 256 ); /*Q15 ->Q24*/ + Ltmp = L_mult( C_RELE_FX, 256 ); /*Q15*Q8 ->Q24*/ relEn = round_fx( L_shl( L_mac( Ltmp, relE, K_RELE_FX ), 1 ) ); /*relE in Q8 but relEn in Q9*/ /* Limit [0.5, 1] */ relEn = s_max( relEn, 256 ); @@ -163,7 +164,8 @@ Word16 signal_clas_fx( /* o : classification for current * FEC classification *-----------------------------------------------------------------*/ - st->fmerit_dt = sub( st->prev_fmerit, fmerit1 ); + st->fmerit_dt = sub( st->prev_fmerit, fmerit1 ); /*Q15*/ + move16(); st->prev_fmerit = fmerit1; move16(); @@ -254,14 +256,14 @@ Word16 signal_clas_fx( /* o : classification for current /* tc_cnt == 1: onset/transition frame, coded by GC coder type */ /* tc_cnt == 2: frame after onset/transition frame, coded by TC coder type */ - if ( EQ_16( clas, UNVOICED_CLAS ) ) + if ( clas == 0 ) { st->tc_cnt = 0; move16(); } test(); - if ( GE_16( clas, VOICED_TRANSITION ) && st->tc_cnt >= 0 ) + IF( GE_16( clas, VOICED_TRANSITION ) && st->tc_cnt >= 0 ) { st->tc_cnt = add( st->tc_cnt, 1 ); move16(); @@ -323,7 +325,7 @@ void select_TC_fx( void coder_type_modif_fx( Encoder_State *st, /* i/o: encoder state structure */ - const Word16 relE /* i : frame relative E to the long term average */ + const Word16 relE /* i : frame relative E to the long term average Q8*/ ) { Word16 unmod_coder_type, vbr_generic_ho; @@ -354,8 +356,12 @@ void coder_type_modif_fx( /* At higher rates, use GC coding instead of UC coding to improve quality */ test(); - if ( ( EQ_16( st->element_mode, EVS_MONO ) && GT_32( st->total_brate, ACELP_9k60 ) && EQ_16( st->coder_type, UNVOICED ) ) || - ( GT_16( st->element_mode, EVS_MONO ) && GT_32( st->total_brate, MAX_UNVOICED_BRATE ) && EQ_16( st->coder_type, UNVOICED ) ) ) + test(); + test(); + test(); + test(); + if ( ( st->element_mode == 0 && GT_32( st->total_brate, ACELP_9k60 ) && EQ_16( st->coder_type, UNVOICED ) ) || + ( st->element_mode > 0 && GT_32( st->total_brate, MAX_UNVOICED_BRATE ) && EQ_16( st->coder_type, UNVOICED ) ) ) { st->coder_type = GENERIC; move16(); @@ -395,13 +401,13 @@ void coder_type_modif_fx( test(); IF( EQ_16( st->Opt_SC_VBR, 1 ) ) { + test(); if ( EQ_16( st->coder_type, GENERIC ) && EQ_16( unmod_coder_type, UNVOICED ) ) { hSC_VBR->vbr_generic_ho = 1; move16(); } - test(); if ( GT_16( st->coder_type, UNVOICED ) ) { hSC_VBR->vbr_generic_ho = 0; @@ -419,12 +425,12 @@ void coder_type_modif_fx( } //} closing bracket here in IVAS float, but not in EVS float. currently affects BE for switching bitrate on Linux 20220929 _DIFF_FLOAT_FIX_ !! - IF( EQ_16( st->element_mode, EVS_MONO ) ) + IF( st->element_mode == 0 ) { /* At higher rates and with 16kHz core, allow only GC and TC coder type */ test(); test(); - test(); + // test(); if ( GT_32( st->total_brate, ACELP_16k40 ) && NE_16( st->coder_type, GENERIC ) && NE_16( st->coder_type, TRANSITION ) ) { /* onset/transition frame is always coded using GC mode */ @@ -435,6 +441,9 @@ void coder_type_modif_fx( ELSE /*IVAS*/ { /* At higher bitrates, disable UC and VC coder type; note that IC coder type is classified later */ + test(); + test(); + test(); if ( ( GT_32( st->total_brate, MAX_VOICED_BRATE ) && EQ_16( st->coder_type, VOICED ) ) || ( GT_32( st->total_brate, MAX_UNVOICED_BRATE ) && EQ_16( st->coder_type, UNVOICED ) ) ) { @@ -447,7 +456,7 @@ void coder_type_modif_fx( test(); test(); test(); - if ( EQ_16( st->coder_type, VOICED ) && EQ_16( st->input_bwidth, NB ) && LT_16( relE, -2560 ) && LE_32( st->total_brate, ACELP_8k00 ) ) + if ( EQ_16( st->coder_type, VOICED ) && st->input_bwidth == 0 && LT_16( relE, -2560 ) && LE_32( st->total_brate, ACELP_8k00 ) ) { st->coder_type = GENERIC; move16(); @@ -493,8 +502,8 @@ void coder_type_modif_ivas_fx( test(); test(); test(); - if ( ( EQ_16( st->element_mode, EVS_MONO ) && GT_32( st->total_brate, ACELP_9k60 ) && EQ_16( st->coder_type, UNVOICED ) ) || - ( GT_16( st->element_mode, EVS_MONO ) && GT_32( st->total_brate, MAX_UNVOICED_BRATE ) && EQ_16( st->coder_type, UNVOICED ) ) ) + if ( ( st->element_mode == 0 && GT_32( st->total_brate, ACELP_9k60 ) && EQ_16( st->coder_type, UNVOICED ) ) || + ( st->element_mode > 0 && GT_32( st->total_brate, MAX_UNVOICED_BRATE ) && EQ_16( st->coder_type, UNVOICED ) ) ) { st->coder_type = GENERIC; move16(); @@ -530,7 +539,7 @@ void coder_type_modif_ivas_fx( move16(); } - IF( EQ_16( st->Opt_SC_VBR, 1 ) ) + if ( EQ_16( st->Opt_SC_VBR, 1 ) ) { test(); if ( EQ_16( st->coder_type, GENERIC ) && EQ_16( unmod_coder_type, UNVOICED ) ) @@ -555,7 +564,7 @@ void coder_type_modif_ivas_fx( } } - IF( EQ_16( st->element_mode, EVS_MONO ) ) + IF( st->element_mode == 0 ) { /* At higher rates and with 16kHz core, allow only GC and TC coder type */ test(); diff --git a/lib_enc/spec_center_fx.c b/lib_enc/spec_center_fx.c index 920da568d..1e908d0c3 100644 --- a/lib_enc/spec_center_fx.c +++ b/lib_enc/spec_center_fx.c @@ -18,9 +18,9 @@ *-------------------------------------------------------------------*/ void spec_center_fx( - Word32 *sb_power, /* i : energy of sub-band divided uniformly*/ - Word16 *sp_center, /* o : spectral center*/ - const Word32 bw_index, /* i : band width*/ + Word32 *sb_power, /* i : energy of sub-band divided uniformly Q31 */ + Word16 *sp_center, /* o : spectral center Q10 */ + const Word32 bw_index, /* i : band width Q0 */ const Word16 Q_sb_p /* i : the Scaling of sb_power*/ ) { @@ -48,15 +48,15 @@ void spec_center_fx( FOR( i = 0; i < 10; i++ ) { - sb_power_shr[i] = L_shr( sb_power[i], 5 ); + sb_power_shr[i] = L_shr( sb_power[i], 5 ); /* Q26 */ move32(); } FOR( i = 0; i < 10; i++ ) { - sb_power_mlt = Mpy_32_16_1( sb_power[i], i_t_1[i] ); - t_sp_center = L_add( L_shr( sb_power_mlt, 6 ), t_sp_center ); - frame_power = L_add( sb_power_shr[i], frame_power ); /*0-9 */ + sb_power_mlt = Mpy_32_16_1( sb_power[i], i_t_1[i] ); /* Q16 + QB */ + t_sp_center = L_add( L_shr( sb_power_mlt, 6 ), t_sp_center ); /* Q11 + QB */ + frame_power = L_add( sb_power_shr[i], frame_power ); /*0-9 */ /* Q26 */ } t_sp_center_nb = t_sp_center; @@ -68,16 +68,17 @@ void spec_center_fx( Q_t_sc = sub( Q_sb_p, 10 ); IF( GE_16( Q_t_sc, 34 ) ) { - t_sp_center = L_shr( t_sp_center, sub( Q_t_sc, 33 ) ); - zerop1 = L_shr( CNT0P1, 1 ); + t_sp_center = L_shr( t_sp_center, sub( Q_t_sc, 33 ) ); /* Q44 + QB - Q_t_sc)*/ + zerop1 = CNT0P1 >> 1; /* Q33 */ + move32(); Q_t_sc = 33; move16(); } ELSE { - Q_t_sc = sub( Q_t_sc, 1 ); - t_sp_center = L_shr( t_sp_center, 1 ); - zerop1 = L_shr( CNT0P1, sub( 34, Q_t_sc ) ); + Q_t_sc = sub( Q_t_sc, 1 ); /* Q_t_sc - 1 */ + t_sp_center = L_shr( t_sp_center, 1 ); /* Q10 + QB */ + zerop1 = L_shr( CNT0P1, sub( 34, Q_t_sc ) ); /* Q_t_sc */ } t_sp_center_num = L_add( t_sp_center, zerop1 ); @@ -85,7 +86,8 @@ void spec_center_fx( IF( GE_16( Q_f_p, 34 ) ) { frame_power = L_shr( frame_power, sub( Q_f_p, 33 ) ); - zerop1 = L_shr( CNT0P1, 1 ); + zerop1 = ( CNT0P1 >> 1 ); + move32(); Q_f_p = 33; move16(); } @@ -120,9 +122,9 @@ void spec_center_fx( d_t_sp_center = shr( d_t_sp_center, d_t_sp_center_Qtmp ); sp_center[0] = add( mult( sp_center[0], 0x5999 ), mult( d_t_sp_center, 0x2666 ) ); - move16(); sp_center[2] = d_t_sp_center; move16(); + move16(); t_sp_center = 0; move32(); @@ -148,7 +150,8 @@ void spec_center_fx( IF( GE_16( Q_t_sc, 34 ) ) { t_sp_center = L_shr( t_sp_center, sub( Q_t_sc, 33 ) ); - zerop1 = L_shr( CNT0P1, 1 ); + zerop1 = ( CNT0P1 >> 1 ); + move32(); Q_t_sc = 33; move16(); } @@ -221,7 +224,8 @@ void spec_center_fx( IF( GE_16( Q_t_sc, 34 ) ) { t_sp_center = L_shr( t_sp_center, limitScale32( sub( Q_t_sc, 33 ) ) ); - zerop1 = L_shr( CNT0P1, 1 ); + zerop1 = ( CNT0P1 >> 1 ); + move32(); Q_t_sc = 33; move16(); } @@ -237,7 +241,8 @@ void spec_center_fx( IF( GE_16( Q_f_p, 34 ) ) { frame_power = L_shr( frame_power, sub( Q_f_p, 33 ) ); - zerop1 = L_shr( CNT0P1, 1 ); + zerop1 = ( CNT0P1 >> 1 ); + move32(); Q_f_p = 33; move16(); } diff --git a/lib_enc/swb_tbe_enc_fx.c b/lib_enc/swb_tbe_enc_fx.c index e17eebc1e..c1dd105fc 100644 --- a/lib_enc/swb_tbe_enc_fx.c +++ b/lib_enc/swb_tbe_enc_fx.c @@ -1198,7 +1198,7 @@ void wb_tbe_enc_fx( tmp = round_fx_o( L_tmp, &Overflow ); /* Q15 */ #else /* BASOP_NOGLOB */ L_tmp = L_shl( L_tmp, add( exp, 10 ) ); - tmp = round_fx( L_tmp ); /* Q15 */ + tmp = round_fx( L_tmp ); /* Q15 */ #endif } @@ -1370,14 +1370,14 @@ void wb_tbe_enc_ivas_fx( autocorr_fx( hb_old_speech, LPC_SHB_ORDER_WB + 1, R_h, R_l, &Q_R, ( ( NS2SA( INT_FS_12k8, 5000000L ) + L_SUBFR + L_FRAME ) * 5 / 16 ), win_lpc_hb_wb_fx, 0, 1 ); - E_LPC_lev_dur( R_h, R_l, lpc_wb_temp_fx, LepsP, LPC_SHB_ORDER_WB, NULL ); + E_LPC_lev_dur( R_h, R_l, lpc_wb_temp_fx, LepsP, LPC_SHB_ORDER_WB, NULL ); // Since 0th index will be 1 in floating point buffer, in fixed point one has to take norm of 0th index to identify the Q-factor - Copy_Scale_sig( lpc_wb_temp_fx, lpc_wb_temp_fx, LPC_SHB_ORDER_WB + 1, sub( norm_s( lpc_wb_temp_fx[0] ), 2 ) ); + Copy_Scale_sig( lpc_wb_temp_fx, lpc_wb_temp_fx, LPC_SHB_ORDER_WB + 1, sub( norm_s( lpc_wb_temp_fx[0] ), 2 ) ); // Q12 /* convert into lsps and calculate weights */ FOR( i = 0; i <= LPC_SHB_ORDER_WB; i++ ) { - lpc_wb_32_fx[i] = L_negate( L_shr( L_deposit_h( lpc_wb_temp_fx[i] ), 1 ) ); + lpc_wb_32_fx[i] = L_negate( L_deposit_h( L_shr( lpc_wb_temp_fx[i], 1 ) ) ); // Q27 move32(); } diff --git a/lib_enc/tcq_core_enc_fx.c b/lib_enc/tcq_core_enc_fx.c index 7ff5a9637..21136aa09 100644 --- a/lib_enc/tcq_core_enc_fx.c +++ b/lib_enc/tcq_core_enc_fx.c @@ -57,6 +57,13 @@ ivas_error tcq_core_LR_enc_fx( Word32 Rk_sort_fx[NB_SFM]; Word32 step_scale_fx[NB_SFM]; Word16 pulses_fx, nzp_fx; + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move32(); Word32 gain_fx, crosscorr_fx, selfcorr_fx; Word16 hi, lo, exp; @@ -66,6 +73,9 @@ ivas_error tcq_core_LR_enc_fx( Word32 sepbits = 0; Word32 divider = 0; ivas_error error; + move32(); + move32(); + move32(); error = IVAS_ERR_OK; move16(); @@ -82,7 +92,7 @@ ivas_error tcq_core_LR_enc_fx( test(); test(); - IF( input_frame <= L_FRAME16k && adjustFlag == 0 && is_transient == 0 ) + IF( LE_16( input_frame, L_FRAME16k ) && adjustFlag == 0 && is_transient == 0 ) { flag_wbnb = 1; move16(); @@ -100,6 +110,8 @@ ivas_error tcq_core_LR_enc_fx( move16(); pbs_fx->numbits = L_deposit_l( 0 ); pbs_fx->numByte = L_deposit_l( 0 ); + move32(); + move32(); FOR( i = 0; i < MAX_SIZEBUF_PBITSTREAM; i++ ) { pbs_fx->buf[i] = 0; @@ -134,7 +146,7 @@ ivas_error tcq_core_LR_enc_fx( { IF( R_fx[j] > 0 ) { - nzb++; + nzb = add( nzb, 1 ); } } @@ -148,11 +160,13 @@ ivas_error tcq_core_LR_enc_fx( IF( R_fx[j] > 0 ) { R_fx[j] = L_sub( R_fx[j], ar_div( bsub_fx, nzb ) ); + move32(); IF( R_fx[j] < 0 ) { bsub_fx = L_sub( bsub_fx, L_add( ar_div( bsub_fx, nzb ), R_fx[j] ) ); R_fx[j] = L_deposit_l( 0 ); + move32(); } ELSE { @@ -186,10 +200,11 @@ ivas_error tcq_core_LR_enc_fx( move16(); FOR( j = 0; j < BANDS; j++ ) { + test(); IF( NE_16( j, k_num[0] ) && NE_16( j, k_num[1] ) ) { leftbits = L_add( leftbits, R_fx[k_sort[j]] ); - if ( R_fx[k_sort[j]] > 0 ) + IF( R_fx[k_sort[j]] > 0 ) { nzbands = add( nzbands, 1 ); } @@ -226,7 +241,7 @@ ivas_error tcq_core_LR_enc_fx( encode_position_ari_fx( parenc_fx, &coefs_norm_dec_fx[sfm_start[k_sort[k]]], size, &est_frame_bits_fx ); encode_magnitude_tcq_fx( parenc_fx, &coefs_norm_dec_fx[sfm_start[k_sort[k]]], size, npulses[k_sort[k]], nzp_fx, savedstates, &est_frame_bits_fx ); encode_signs_fx( parenc_fx, &coefs_norm_dec_fx[sfm_start[k_sort[k]]], size, nzp_fx, &est_frame_bits_fx ); - nzbands--; + nzbands = sub( nzbands, 1 ); } /* Have USQ coded band */ ELSE IF( R_fx[k_sort[k]] > 0 && EQ_16( USQ_TCQ[k_sort[k]], 1 ) ) @@ -245,7 +260,7 @@ ivas_error tcq_core_LR_enc_fx( encode_position_ari_fx( parenc_fx, &coefs_norm_dec_fx[sfm_start[k_sort[k]]], size, &est_frame_bits_fx ); encode_magnitude_usq_fx( parenc_fx, &coefs_norm_dec_fx[sfm_start[k_sort[k]]], size, npulses[k_sort[k]], nzp_fx, &est_frame_bits_fx ); encode_signs_fx( parenc_fx, &coefs_norm_dec_fx[sfm_start[k_sort[k]]], size, nzp_fx, &est_frame_bits_fx ); - nzbands--; + nzbands = sub( nzbands, 1 ); } ELSE /* Then have zero block */ { @@ -260,13 +275,15 @@ ivas_error tcq_core_LR_enc_fx( IF( R_fx[k_sort[k]] > 0 && surplus_fx < 0 ) { /* delta_fx = L_deposit_h( div_l( surplus_fx, nzbands ) ); */ - IF( nzbands <= 1 ) + IF( LE_16( nzbands, 1 ) ) { divider = 0; + move32(); } ELSE { divider = 2; + move32(); } IF( L_add( L_add( surplus_fx, sepbits ), ar_div( leftbits, divider ) ) < 0 ) @@ -274,7 +291,7 @@ ivas_error tcq_core_LR_enc_fx( /* Overflow possible => start to distribute negative surplus */ delta_fx = ar_div( surplus_fx + sepbits, nzbands ); } - else + ELSE { delta_fx = 0; } @@ -290,12 +307,15 @@ ivas_error tcq_core_LR_enc_fx( { bit_surplus_fx[0] = Mult_32_16( surplus_fx, 24576 ); /* Q16 */ bit_surplus_fx[1] = Mult_32_16( surplus_fx, 8192 ); /* Q16 */ + move32(); + move32(); } ELSE { bit_surplus_fx[0] = surplus_fx; move32(); bit_surplus_fx[1] = L_deposit_l( 0 ); + move32(); } FOR( k = 0; k < BANDS; k++ ) @@ -305,6 +325,7 @@ ivas_error tcq_core_LR_enc_fx( IF( EQ_16( k, k_num[j] ) ) { R_fx[k_sort[k]] = L_add( R_fx[k_sort[k]], bit_surplus_fx[j] ); + move32(); test(); test(); @@ -409,7 +430,9 @@ ivas_error tcq_core_LR_enc_fx( FOR( i = 0; i < L_FRAME32k; i++ ) { coefs_norm_dec_fx[i] = extract_l( L_mult0( coefs_norm_dec_fx[i], 5 ) ); + move16(); } + IF( !flag_wbnb ) { FOR( k = 0; k < BANDS; k++ ) @@ -467,6 +490,7 @@ ivas_error tcq_core_LR_enc_fx( move16(); coefs_quant_fx[sfm_start[k_sort[i]] + j] = L_add( L_shl( L_mult0( hi, coefs_norm_dec_fx[sfm_start[k_sort[i]] + j] ), 12 ), L_shr( L_mult0( lo, coefs_norm_dec_fx[sfm_start[k_sort[i]] + j] ), 3 ) ); /* Q12 */ + move32(); } } } @@ -518,7 +542,7 @@ ivas_error tcq_core_LR_enc_ivas_fx( move16(); move16(); move16(); - move16(); + move32(); Word32 abuffer_fx[MAX_PULSES]; Word16 mbuffer_fx[MAX_PULSES]; Word32 sbuffer_fx[MAX_PULSES]; @@ -534,9 +558,9 @@ ivas_error tcq_core_LR_enc_ivas_fx( Word32 leftbits = 0; Word32 sepbits = 0; Word32 divider = 0; - move16(); - move16(); - move16(); + move32(); + move32(); + move32(); ivas_error error; error = IVAS_ERR_OK; @@ -622,11 +646,13 @@ ivas_error tcq_core_LR_enc_ivas_fx( IF( R_fx[j] > 0 ) { R_fx[j] = L_sub( R_fx[j], ar_div( bsub_fx, nzb ) ); + move32(); IF( R_fx[j] < 0 ) { bsub_fx = L_sub( bsub_fx, L_add( ar_div( bsub_fx, nzb ), R_fx[j] ) ); R_fx[j] = L_deposit_l( 0 ); + move32(); } ELSE { @@ -660,10 +686,11 @@ ivas_error tcq_core_LR_enc_ivas_fx( move16(); FOR( j = 0; j < BANDS; j++ ) { + test(); IF( NE_16( j, k_num[0] ) && NE_16( j, k_num[1] ) ) { leftbits = L_add( leftbits, R_fx[k_sort[j]] ); - if ( R_fx[k_sort[j]] > 0 ) + IF( R_fx[k_sort[j]] > 0 ) { nzbands = add( nzbands, 1 ); } @@ -734,13 +761,15 @@ ivas_error tcq_core_LR_enc_ivas_fx( IF( R_fx[k_sort[k]] > 0 && surplus_fx < 0 ) { /* delta_fx = L_deposit_h( div_l( surplus_fx, nzbands ) ); */ - IF( nzbands <= 1 ) + IF( LE_16( nzbands, 1 ) ) { divider = 0; + move32(); } ELSE { divider = 2; + move32(); } IF( L_add( L_add( surplus_fx, sepbits ), ar_div( leftbits, divider ) ) < 0 ) @@ -888,7 +917,9 @@ ivas_error tcq_core_LR_enc_ivas_fx( FOR( i = 0; i < L_FRAME32k; i++ ) { coefs_norm_dec_fx[i] = extract_l( L_mult0( coefs_norm_dec_fx[i], 5 ) ); + move16(); } + IF( !flag_wbnb ) { FOR( k = 0; k < BANDS; k++ ) @@ -903,6 +934,7 @@ ivas_error tcq_core_LR_enc_ivas_fx( } nb_bytes = shr( bit_budget, 3 ); + j = sub( bit_budget, shl( nb_bytes, 3 ) ); FOR( i = 0; i < nb_bytes; i++ ) { diff --git a/lib_enc/tcx_ltp_enc_fx.c b/lib_enc/tcx_ltp_enc_fx.c index a37e8ec77..2222e8f74 100644 --- a/lib_enc/tcx_ltp_enc_fx.c +++ b/lib_enc/tcx_ltp_enc_fx.c @@ -88,6 +88,7 @@ static void tcx_ltp_pitch_search( Word16 wsp2[L_FRAME_PLUS + PIT_MAX_MAX + L_INTERPOL1]; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif @@ -129,12 +130,15 @@ static void tcx_ltp_pitch_search( move16(); } wsp = wsp2 + t_max; + move16(); pt_cor = cor; + move32(); FOR( t = t_min; t <= t_max; t++ ) { *pt_cor = dot( wsp, wsp - t, len ); + move32(); pt_cor++; } @@ -142,13 +146,16 @@ static void tcx_ltp_pitch_search( cor_max = L_add( *pt_cor++, 0 ); t1 = t0_min; move16(); + move32(); - FOR( t = add( t0_min, 1 ); t <= t0_max; t++ ) + FOR( t = t0_min + 1; t <= t0_max; t++ ) { - IF( *pt_cor > cor_max ) + IF( GT_32( *pt_cor, cor_max ) ) { cor_max = *pt_cor; + move32(); t1 = t; + move16(); } pt_cor++; } @@ -227,7 +234,7 @@ static void tcx_ltp_pitch_search( t0 = sub( t0, 1 ); cor_max = interpolate_corr( &pt_cor[t0], fraction, pitres ); - FOR( i = add( fraction, step ); i < pitres; i += step ) + FOR( i = fraction + step; i < pitres; i += step ) { temp = interpolate_corr( &pt_cor[t0], i, pitres ); @@ -241,6 +248,7 @@ static void tcx_ltp_pitch_search( } i = 0; + move16(); FOR( i = 0; i < pitres; i += step ) /* Process positive fractions */ { temp = interpolate_corr( &pt_cor[t1], i, pitres ); @@ -341,6 +349,7 @@ static void tcx_ltp_pitch_search_ivas_fx( FOR( t = t_min; t <= t_max; t++ ) { *pt_cor = dot( wsp, wsp - t, len ); // 2*(x + s_wsp) + move32(); pt_cor++; } @@ -349,7 +358,7 @@ static void tcx_ltp_pitch_search_ivas_fx( t1 = t0_min; move16(); - FOR( t = add( t0_min, 1 ); t <= t0_max; t++ ) + FOR( t = t0_min + 1; t <= t0_max; t++ ) { IF( GT_32( *pt_cor, cor_max ) ) { @@ -415,6 +424,7 @@ static void tcx_ltp_pitch_search_ivas_fx( *index = add( sub( t1, pitfr1 ), extract_l( L_mac0( L_mult0( sub( pitfr2, pitmin ), pitres ), sub( pitfr1, pitfr2 ), shr( pitres, 1 ) ) ) ); + move16(); return; } @@ -450,7 +460,7 @@ static void tcx_ltp_pitch_search_ivas_fx( t0 = sub( t0, 1 ); cor_max = interpolate_corr( &pt_cor[t0], fraction, pitres ); - FOR( i = add( fraction, step ); i < pitres; i += step ) + FOR( i = fraction + step; i < pitres; i += step ) { temp = interpolate_corr( &pt_cor[t0], i, pitres ); @@ -487,10 +497,12 @@ static void tcx_ltp_pitch_search_ivas_fx( *index = add( extract_l( L_mac0( L_mult0( sub( t0, pitfr2 ), shr( pitres, 1 ) ), sub( pitfr2, pitmin ), pitres ) ), shr( fraction, 1 ) ); + move16(); } ELSE { *index = add( imult1616( sub( t0, pitmin ), pitres ), fraction ); + move16(); } } @@ -501,6 +513,7 @@ static void tcx_ltp_find_gain( Word16 *speech, Word16 *pred_speech, Word16 L_fra Word16 i, g, s1, s2, tmp; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif @@ -672,6 +685,7 @@ void tcx_ltp_encode_fx( Word16 tcxltp_on, Word16 alpha, step; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif @@ -801,14 +815,14 @@ void tcx_ltp_encode_fx( Word16 tcxltp_on, *ltp_bits = 0; move16(); test(); - if ( tcxltp_on != 0 || SideInfoOnly != 0 ) + IF( tcxltp_on != 0 || SideInfoOnly != 0 ) { *ltp_bits = 1; move16(); } } - if ( SideInfoOnly != 0 ) + IF( SideInfoOnly != 0 ) { *gain = 0; move16(); @@ -826,7 +840,7 @@ void tcx_ltp_encode_fx( Word16 tcxltp_on, /* step = 1.f/(float)(L_subfr); */ step = shl( 2, norm_s( L_subfr ) ); - if ( s_and( L_subfr, sub( L_subfr, 1 ) ) != 0 ) + IF( s_and( L_subfr, sub( L_subfr, 1 ) ) != 0 ) { step = mult_r( step, 26214 /*64.f/80.f Q15*/ ); } @@ -882,14 +896,15 @@ void tcx_ltp_encode_fx( Word16 tcxltp_on, E_UTIL_synthesis( 0, A, zir, zir, L_subfr, buf_zir, 0, lpcorder ); alpha = 0x7FFF; + move16(); /* step = 1.f/(float)(L_subfr/2); */ step = shl( 4, norm_s( L_subfr ) ); - if ( s_and( L_subfr, sub( L_subfr, 1 ) ) != 0 ) + IF( s_and( L_subfr, sub( L_subfr, 1 ) ) != 0 ) { step = mult_r( step, 26214 /*64.f/80.f Q15*/ ); } - FOR( n = shr( L_subfr, 1 ); n < L_subfr; n++ ) + FOR( n = ( L_subfr >> 1 ); n < L_subfr; n++ ) { zir[n] = mult_r( zir[n], alpha ); move16(); @@ -1040,13 +1055,12 @@ void tcx_ltp_encode_ivas_fx( IF( GT_16( norm_corr_2_fx[1], norm_corr_2_fx[0] ) ) { i = 1; - move16(); } ELSE { i = 0; - move16(); } + move16(); hTcxEnc->tcxltp_pitch_int = pitch_int_2[i]; move16(); @@ -1055,6 +1069,7 @@ void tcx_ltp_encode_ivas_fx( ltp_param[1] = pit_param_2[i]; move16(); norm_corr_fx = norm_corr_2_fx[i]; + move16(); } } ELSE @@ -1304,7 +1319,7 @@ void tcx_ltp_encode_ivas_fx( step_fx = mult_r( step_fx, 26214 /*64.f/80.f Q15*/ ); } - FOR( n = shr( L_subfr, 1 ); n < L_subfr; n++ ) + FOR( n = L_subfr >> 1; n < L_subfr; n++ ) { zir_fx[n] = mult_r( zir_fx[n], alpha_fx ); move16(); diff --git a/lib_enc/tcx_utils_enc_fx.c b/lib_enc/tcx_utils_enc_fx.c index cc36da486..31c04c1d5 100644 --- a/lib_enc/tcx_utils_enc_fx.c +++ b/lib_enc/tcx_utils_enc_fx.c @@ -32,8 +32,10 @@ static Word16 quantize( Word32 x, Word16 invGain, Word16 shift, Word32 offset ) tmp32 = L_shl( tmp32, shift ); /* convert to 15Q16 */ tmp32 = L_add( tmp32, offset ); /* add offset */ tmp16 = extract_h( tmp32 ); /* truncate */ - if ( x < 0 ) + IF( x < 0 ) + { tmp16 = negate( tmp16 ); /* restore sign */ + } return tmp16; } @@ -50,6 +52,7 @@ void ComputeSpectrumNoiseMeasure_fx( const Word32 *powerSpec, Word32 s, c; Word16 tmp16; Word32 tmp1, tmp2 = 0; /* initialization only to avoid compiler warning, not counted */ + move32(); int j; @@ -83,7 +86,7 @@ void ComputeSpectrumNoiseMeasure_fx( const Word32 *powerSpec, s = L_add( s, L_shr( powerSpec[i + j], 4 ) ); } tmp16 = sub( lowpassLine, 7 ); - FOR( i = add( i, 1 ); i < tmp16; i++ ) + FOR( i = i + 1; i < tmp16; i++ ) { c = L_shr( powerSpec[i - 1], 4 ); c = L_add( c, L_shr( powerSpec[i], 4 ) ); @@ -93,12 +96,18 @@ void ComputeSpectrumNoiseMeasure_fx( const Word32 *powerSpec, s = L_add( s, L_shr( powerSpec[i + 7], 4 ) ); tmp1 = L_shr( c, 2 ); - if ( noiseFlags[i] == 0 ) + IF( noiseFlags[i] == 0 ) + { c = L_shl( c, 1 ); - if ( noiseFlags[i] == 0 ) + } + IF( noiseFlags[i] == 0 ) + { tmp2 = L_sub( c, tmp1 ); /* 1.75 * c */ - if ( noiseFlags[i] != 0 ) + } + IF( noiseFlags[i] != 0 ) + { tmp2 = L_add( c, tmp1 ); /* 1.25 * c */ + } tmp2 = L_sub( s, tmp2 ); if ( tmp2 >= 0 ) @@ -127,12 +136,18 @@ void ComputeSpectrumNoiseMeasure_fx( const Word32 *powerSpec, c = L_add( c, L_shr( powerSpec[i + 1], 4 ) ); tmp1 = L_shr( c, 2 ); - if ( noiseFlags[i] == 0 ) + IF( noiseFlags[i] == 0 ) + { c = L_shl( c, 1 ); - if ( noiseFlags[i] == 0 ) + } + IF( noiseFlags[i] == 0 ) + { tmp2 = L_sub( c, tmp1 ); /* 1.75 * c */ - if ( noiseFlags[i] != 0 ) + } + IF( noiseFlags[i] != 0 ) + { tmp2 = L_add( c, tmp1 ); /* 1.25 * c */ + } /* running sum can't be updated any more, just use the latest one */ tmp2 = L_sub( s, tmp2 ); @@ -165,18 +180,20 @@ static void detectLowpassFac( const Word32 *powerSpec, Word16 powerSpec_e, Word1 Word32 threshold; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif threshold = 256l /*0.1f * 2*NORM_MDCT_FACTOR Q3*/; /* Q3 */ - BASOP_SATURATE_WARNING_OFF_EVS /* Allow saturation, because threshold is being compared to powerSpec[i] below. */ + move32(); + BASOP_SATURATE_WARNING_OFF_EVS /* Allow saturation, because threshold is being compared to powerSpec[i] below. */ #ifdef BASOP_NOGLOB threshold = L_shl_o( threshold, sub( 28, powerSpec_e ), &Overflow ); #else /* BASOP_NOGLOB */ threshold = L_shl( threshold, sub( 28, powerSpec_e ) ); #endif /* BASOP_NOGLOB */ - if ( rectWin != 0 ) + IF( rectWin != 0 ) { /* compensate for bad side-lobe attenuation with asymmetric windows */ #ifdef BASOP_NOGLOB @@ -188,7 +205,7 @@ static void detectLowpassFac( const Word32 *powerSpec, Word16 powerSpec_e, Word1 BASOP_SATURATE_WARNING_ON_EVS tmp = shr( lowpassLine, 1 ); - FOR( i = sub( lowpassLine, 1 ); i >= tmp; i-- ) + FOR( i = lowpassLine - 1; i >= tmp; i-- ) { IF( GT_32( powerSpec[i], threshold ) ) { @@ -249,7 +266,7 @@ void AnalyzePowerSpectrum_fx( s2 = 0; move16(); tmp = sub( mdctSpectrum_e, *powerSpec_e ); - if ( tmp > 0 ) + IF( tmp > 0 ) { s2 = negate( tmp ); } @@ -309,7 +326,6 @@ void AnalyzePowerSpectrum_fx( { lowpassLine = shl( mult( st->hTcxCfg->bandwidth, L_frame ), 1 ); - test(); detectLowpassFac( powerSpec, *powerSpec_e, L_frame, sub( st->last_core, ACELP_CORE ) == 0, @@ -409,7 +425,6 @@ void AnalyzePowerSpectrum_ivas_fx( { lowpassLine = shl( mult( st->hTcxCfg->bandwidth, L_frame ), 1 ); - test(); detectLowpassFac( common_powerSpec, temp_powerSpec_e, L_frame, sub( st->last_core, ACELP_CORE ) == 0, @@ -457,6 +472,7 @@ void AdaptLowFreqEmph_fx( Word32 x[], /* Debug initialization to catch illegal cases of xq[i] */ tmp16 = 0; + move16(); if ( xq[i] > 0 ) { @@ -510,6 +526,7 @@ void AdaptLowFreqEmph_fx( Word32 x[], /* Debug initialization to catch illegal cases of xq[i] */ tmp16 = 0; + move16(); if ( xq[i] > 0 ) { @@ -563,6 +580,7 @@ void AdaptLowFreqEmph_fx( Word32 x[], /* Debug initialization to catch illegal cases of xq[i] */ tmp16 = 0; + move16(); if ( xq[i] > 0 ) { @@ -595,6 +613,7 @@ void AdaptLowFreqEmph_fx( Word32 x[], /* Debug initialization to catch illegal cases of xq[i] */ tmp16 = 0; + move16(); if ( xq[i] > 0 ) { @@ -713,20 +732,27 @@ Word16 SQ_gain_fx( /* output: SQ gain */ move16(); tmp16 = norm_l( x[0] ); - if ( x[0] != 0 ) + IF( x[0] != 0 ) + { s = s_min( s, tmp16 ); + } tmp16 = norm_l( x[1] ); - if ( x[1] != 0 ) + IF( x[1] != 0 ) + { s = s_min( s, tmp16 ); + } tmp16 = norm_l( x[2] ); - if ( x[2] != 0 ) + IF( x[2] != 0 ) + { s = s_min( s, tmp16 ); - + } tmp16 = norm_l( x[3] ); - if ( x[3] != 0 ) + IF( x[3] != 0 ) + { s = s_min( s, tmp16 ); + } s = sub( s, 2 ); /* 2 bits headroom */ @@ -771,7 +797,7 @@ Word16 SQ_gain_fx( /* output: SQ gain */ tmp32 = L_sub( en[i], offset ); /* avoid SV with 1 bin of amp < 0.5f */ - if ( GT_32( tmp32, 0xFF20 ) ) /* 0xFF20 -> 0.3*log2(10); */ + IF( GT_32( tmp32, 0xFF20 ) ) /* 0xFF20 -> 0.3*log2(10); */ { ener = L_add( ener, tmp32 ); } @@ -820,20 +846,28 @@ Word16 SQ_gain_ivas_fx( /* output: SQ gain */ move16(); tmp16 = norm_l( x[0] ); - if ( x[0] != 0 ) + IF( x[0] != 0 ) + { s = s_min( s, tmp16 ); + } tmp16 = norm_l( x[1] ); - if ( x[1] != 0 ) + IF( x[1] != 0 ) + { s = s_min( s, tmp16 ); + } tmp16 = norm_l( x[2] ); - if ( x[2] != 0 ) + IF( x[2] != 0 ) + { s = s_min( s, tmp16 ); + } tmp16 = norm_l( x[3] ); - if ( x[3] != 0 ) + IF( x[3] != 0 ) + { s = s_min( s, tmp16 ); + } s = sub( s, 2 ); /* 2 bits headroom */ @@ -886,7 +920,7 @@ Word16 SQ_gain_ivas_fx( /* output: SQ gain */ tmp32 = L_sub( en[i], offset ); /* avoid SV with 1 bin of amp < 0.5f */ - if ( GT_32( tmp32, 0xFF20 ) ) /* 0xFF20 -> 0.3*log2(10); */ + IF( GT_32( tmp32, 0xFF20 ) ) /* 0xFF20 -> 0.3*log2(10); */ { ener = L_add( ener, tmp32 ); } @@ -947,6 +981,7 @@ Word16 SQ_gain_estimate_fx( /* output: SQ gain tmp = 204644; tmpp = 0; move32(); + move32(); BREAK; case 200: tmp = 215192; @@ -1046,20 +1081,28 @@ Word16 SQ_gain_estimate_fx( /* output: SQ gain move16(); tmp16 = norm_l( x[0] ); - if ( x[0] != 0 ) + IF( x[0] != 0 ) + { s = s_min( s, tmp16 ); + } tmp16 = norm_l( x[1] ); - if ( x[1] != 0 ) + IF( x[1] != 0 ) + { s = s_min( s, tmp16 ); + } tmp16 = norm_l( x[2] ); - if ( x[2] != 0 ) + IF( x[2] != 0 ) + { s = s_min( s, tmp16 ); + } tmp16 = norm_l( x[3] ); - if ( x[3] != 0 ) + IF( x[3] != 0 ) + { s = s_min( s, tmp16 ); + } s = sub( s, 2 ); /* 2 bits headroom */ @@ -1152,6 +1195,8 @@ void tcx_scalar_quantization_fx( tmp16 = negate( s_max( tmp16, 0 ) ); i = sub( L_frame, 1 ); + + test(); WHILE( ( memQuantZeros_fx[i] != 0 ) && ( LT_32( L_abs( L_shl( x[i], tmp16 ) ), tmp32 ) ) ) { test(); @@ -1171,6 +1216,8 @@ void tcx_scalar_quantization_fx( /* Limit the inverse gain to maximal possible value=sqrtL_spec/NORM_MDCT_FACTOR)*/ gain = 22435; /*sqrt(1200/NORM_MDCT_FACTOR) in 2Q13*/ gain_e = 2; + move16(); + move16(); s = sub( add( x_e, gain_e ), 15 ); } @@ -1190,8 +1237,10 @@ void tcx_scalar_quantization_fx( offs32 = L_shl( offs32, s ); /* convert to 15Q16 */ tmp16 = mac_r( offs32, offset, 1 ); /* add offset and truncate */ #endif - if ( x[i] < 0 ) + IF( x[i] < 0 ) + { tmp16 = negate( tmp16 ); /* restore sign */ + } xq[i] = tmp16; move16(); @@ -1248,7 +1297,9 @@ void tcx_scalar_quantization_ivas_fx( { /* Limit the inverse gain to maximal possible value=sqrtL_spec/NORM_MDCT_FACTOR)*/ gain = 22435; /*sqrt(1200/NORM_MDCT_FACTOR) in 2Q13*/ + move16(); gain_e = 2; + move16(); s = sub( add( x_e, gain_e ), 15 ); } @@ -1268,8 +1319,10 @@ void tcx_scalar_quantization_ivas_fx( offs32 = L_shl( offs32, s ); /* convert to 15Q16 */ tmp16 = mac_r( offs32, offset, 1 ); /* add offset and truncate */ #endif - if ( x[i] < 0 ) + IF( x[i] < 0 ) + { tmp16 = negate( tmp16 ); /* restore sign */ + } xq[i] = tmp16; move16(); @@ -1323,6 +1376,10 @@ Word16 tcx_scalar_quantization_rateloop_fx( Word16 tmp, fac1, fac2; Word32 tmp32; Word16 lastnz; + move16(); + move16(); + move16(); + move16(); /* Init */ @@ -1824,6 +1881,7 @@ Word16 tcx_scalar_quantization_rateloop_ivas_fx( } Word16 shift_tmp = s_max( sqGain_e, 1 ); + move16(); test(); IF( LT_16( shl( sqGain, sub( sqGain_e, shift_tmp ) ), shl( minSqGain, sub( 1, shift_tmp ) ) ) && EQ_16( tcxRateLoopOpt, 3 ) ) { @@ -2063,6 +2121,7 @@ void tcx_noise_factor_fx( Word32 xMax; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif @@ -2147,10 +2206,14 @@ void tcx_noise_factor_fx( k = 0; move16(); - if ( accu1 == 0 ) + IF( accu1 == 0 ) + { accu1 = L_deposit_l( 1 ); - if ( accu2 == 0 ) + } + IF( accu2 == 0 ) + { accu2 = L_deposit_l( 1 ); + } att = BASOP_Util_Divide3232_Scale( L_shl( L_min( accu1, accu2 ), 1 ), L_add( accu1, accu2 ), &s ); att = Sqrt16( att, &s ); @@ -2184,22 +2247,34 @@ void tcx_noise_factor_fx( IF( LE_16( nTransWidth, 3 ) ) { tmp2 = sub( k, c1 ); - if ( tmp2 > 0 ) + IF( tmp2 > 0 ) + { n = L_msu( n, k, (Word16) 0x8000 ); - if ( tmp2 > 0 ) + } + IF( tmp2 > 0 ) + { n = L_mac( n, nTransWidth_1, (Word16) 0x8000 ); - if ( tmp2 <= 0 ) + } + IF( tmp2 <= 0 ) + { n = L_mac( n, int_sqr[k], c2 ); + } } ELSE { tmp2 = sub( k, 12 ); - if ( tmp2 > 0 ) + IF( tmp2 > 0 ) + { n = L_msu( n, k, (Word16) 0x8000 ); - if ( tmp2 > 0 ) + } + IF( tmp2 > 0 ) + { n = L_sub( n, 0x70000 ); - if ( tmp2 <= 0 ) + } + IF( tmp2 <= 0 ) + { n = L_mac( n, int_sqr[k], 1152 /*0.03515625f Q15*/ ); + } } sqErrorNrg = L_add( sqErrorNrg, accu1 ); accu1 = L_deposit_l( 0 ); /* segment ended here, so reset segment sum */ @@ -2218,19 +2293,19 @@ void tcx_noise_factor_fx( } ELSE /* current line is zero, so update pointers & segment sum */ { - if ( LT_16( k, nTransWidth ) ) + IF( LT_16( k, nTransWidth ) ) { k = add( k, 1 ); } tmp2 = sub( maxK, nTransWidth ); - if ( tmp2 < 0 ) + IF( tmp2 < 0 ) { maxK = sub( maxK, 1 ); } test(); - if ( ( tmp2 >= 0 ) && ( sqQ[i + sub( nTransWidth, 1 )] != 0 ) ) + IF( ( tmp2 >= 0 ) && ( sqQ[i + sub( nTransWidth, 1 )] != 0 ) ) { maxK = sub( nTransWidth, 1 ); } @@ -2255,22 +2330,34 @@ void tcx_noise_factor_fx( IF( LE_16( nTransWidth, 3 ) ) { tmp2 = sub( k, c1 ); - if ( tmp2 > 0 ) + IF( tmp2 > 0 ) + { n = L_msu( n, k, (Word16) 0x8000 ); - if ( tmp2 > 0 ) + } + IF( tmp2 > 0 ) + { n = L_mac( n, nTransWidth_1, (Word16) 0x8000 ); - if ( tmp2 <= 0 ) + } + IF( tmp2 <= 0 ) + { n = L_mac( n, int_sqr[k], c2 ); + } } ELSE { tmp2 = sub( k, 12 ); - if ( tmp2 > 0 ) + IF( tmp2 > 0 ) + { n = L_msu( n, k, (Word16) 0x8000 ); - if ( tmp2 > 0 ) + } + IF( tmp2 > 0 ) + { n = L_sub( n, 0x70000 ); - if ( tmp2 <= 0 ) + } + IF( tmp2 <= 0 ) + { n = L_mac( n, int_sqr[k], 1152 /*0.03515625f Q15*/ ); + } } sqErrorNrg = L_add( sqErrorNrg, accu1 ); } @@ -2278,11 +2365,11 @@ void tcx_noise_factor_fx( } ELSE /* current line is zero, so update pointers & energy sum */ { - if ( LT_16( k, nTransWidth ) ) + IF( LT_16( k, nTransWidth ) ) { k = add( k, 1 ); } - if ( LT_16( maxK, nTransWidth ) ) + IF( LT_16( maxK, nTransWidth ) ) { maxK = sub( maxK, 1 ); } @@ -2300,22 +2387,34 @@ void tcx_noise_factor_fx( IF( LE_16( nTransWidth, 3 ) ) { tmp2 = sub( k, c1 ); - if ( tmp2 > 0 ) + IF( tmp2 > 0 ) + { n = L_msu( n, k, (Word16) 0x8000 ); - if ( tmp2 > 0 ) + } + IF( tmp2 > 0 ) + { n = L_mac( n, nTransWidth_1, (Word16) 0x8000 ); - if ( tmp2 <= 0 ) + } + IF( tmp2 <= 0 ) + { n = L_mac( n, int_sqr[k], c2 ); + } } ELSE { tmp2 = sub( k, 12 ); - if ( tmp2 > 0 ) + IF( tmp2 > 0 ) + { n = L_msu( n, k, (Word16) 0x8000 ); - if ( tmp2 > 0 ) + } + IF( tmp2 > 0 ) + { n = L_sub( n, 0x70000 ); - if ( tmp2 <= 0 ) + } + IF( tmp2 <= 0 ) + { n = L_mac( n, int_sqr[k], 1152 /*0.03515625f Q15*/ ); + } } sqErrorNrg = L_add( sqErrorNrg, accu1 ); } @@ -2479,10 +2578,14 @@ void tcx_noise_factor_ivas_fx( k = 0; move16(); - if ( accu1 == 0 ) + IF( accu1 == 0 ) + { accu1 = L_deposit_l( 1 ); - if ( accu2 == 0 ) + } + IF( accu2 == 0 ) + { accu2 = L_deposit_l( 1 ); + } att = BASOP_Util_Divide3232_Scale( L_shl( L_min( accu1, accu2 ), 1 ), L_add( accu1, accu2 ), &s ); att = Sqrt16( att, &s ); @@ -2516,22 +2619,34 @@ void tcx_noise_factor_ivas_fx( IF( LE_16( nTransWidth, 3 ) ) { tmp2 = sub( k, c1 ); - if ( tmp2 > 0 ) + IF( tmp2 > 0 ) + { n = L_msu( n, k, (Word16) 0x8000 ); - if ( tmp2 > 0 ) + } + IF( tmp2 > 0 ) + { n = L_mac( n, nTransWidth_1, (Word16) 0x8000 ); - if ( tmp2 <= 0 ) + } + IF( tmp2 <= 0 ) + { n = L_mac( n, int_sqr[k], c2 ); + } } ELSE { tmp2 = sub( k, 12 ); - if ( tmp2 > 0 ) + IF( tmp2 > 0 ) + { n = L_msu( n, k, (Word16) 0x8000 ); - if ( tmp2 > 0 ) + } + IF( tmp2 > 0 ) + { n = L_sub( n, 0x70000 ); - if ( tmp2 <= 0 ) + } + IF( tmp2 <= 0 ) + { n = L_mac( n, int_sqr[k], 1152 /*0.03515625f Q15*/ ); + } } sqErrorNrg = L_add( sqErrorNrg, accu1 ); accu1 = L_deposit_l( 0 ); /* segment ended here, so reset segment sum */ @@ -2550,20 +2665,20 @@ void tcx_noise_factor_ivas_fx( } ELSE /* current line is zero, so update pointers & segment sum */ { - if ( LT_16( k, nTransWidth ) ) + IF( LT_16( k, nTransWidth ) ) { k = add( k, 1 ); } tmp2 = sub( maxK, nTransWidth ); test(); - if ( tmp2 < 0 && NE_16( element_mode, IVAS_CPE_MDCT ) ) + IF( tmp2 < 0 && NE_16( element_mode, IVAS_CPE_MDCT ) ) { maxK = sub( maxK, 1 ); } test(); - if ( ( tmp2 >= 0 ) && ( sqQ[i + sub( nTransWidth, 1 )] != 0 ) ) + IF( ( tmp2 >= 0 ) && ( sqQ[i + sub( nTransWidth, 1 )] != 0 ) ) { maxK = sub( nTransWidth, 1 ); } @@ -2588,22 +2703,34 @@ void tcx_noise_factor_ivas_fx( IF( LE_16( nTransWidth, 3 ) ) { tmp2 = sub( k, c1 ); - if ( tmp2 > 0 ) + IF( tmp2 > 0 ) + { n = L_msu( n, k, (Word16) 0x8000 ); - if ( tmp2 > 0 ) + } + IF( tmp2 > 0 ) + { n = L_mac( n, nTransWidth_1, (Word16) 0x8000 ); - if ( tmp2 <= 0 ) + } + IF( tmp2 <= 0 ) + { n = L_mac( n, int_sqr[k], c2 ); + } } ELSE { tmp2 = sub( k, 12 ); - if ( tmp2 > 0 ) + IF( tmp2 > 0 ) + { n = L_msu( n, k, (Word16) 0x8000 ); - if ( tmp2 > 0 ) + } + IF( tmp2 > 0 ) + { n = L_sub( n, 0x70000 ); - if ( tmp2 <= 0 ) + } + IF( tmp2 <= 0 ) + { n = L_mac( n, int_sqr[k], 1152 /*0.03515625f Q15*/ ); + } } sqErrorNrg = L_add( sqErrorNrg, accu1 ); } @@ -2611,11 +2738,11 @@ void tcx_noise_factor_ivas_fx( } ELSE /* current line is zero, so update pointers & energy sum */ { - if ( LT_16( k, nTransWidth ) ) + IF( LT_16( k, nTransWidth ) ) { k = add( k, 1 ); } - if ( LT_16( maxK, nTransWidth ) ) + IF( LT_16( maxK, nTransWidth ) ) { maxK = sub( maxK, 1 ); } @@ -2633,22 +2760,34 @@ void tcx_noise_factor_ivas_fx( IF( LE_16( nTransWidth, 3 ) ) { tmp2 = sub( k, c1 ); - if ( tmp2 > 0 ) + IF( tmp2 > 0 ) + { n = L_msu( n, k, (Word16) 0x8000 ); - if ( tmp2 > 0 ) + } + IF( tmp2 > 0 ) + { n = L_mac( n, nTransWidth_1, (Word16) 0x8000 ); - if ( tmp2 <= 0 ) + } + IF( tmp2 <= 0 ) + { n = L_mac( n, int_sqr[k], c2 ); + } } ELSE { tmp2 = sub( k, 12 ); - if ( tmp2 > 0 ) + IF( tmp2 > 0 ) + { n = L_msu( n, k, (Word16) 0x8000 ); - if ( tmp2 > 0 ) + } + IF( tmp2 > 0 ) + { n = L_sub( n, 0x70000 ); - if ( tmp2 <= 0 ) + } + IF( tmp2 <= 0 ) + { n = L_mac( n, int_sqr[k], 1152 /*0.03515625f Q15*/ ); + } } sqErrorNrg = L_add( sqErrorNrg, accu1 ); } @@ -2727,6 +2866,7 @@ void tcx_encoder_memory_update_fx( #else LPDmem->mem_w0 = shr( LPDmem->mem_w0, shift ); /*Qnew-1*/ #endif + move16(); } @@ -2801,6 +2941,7 @@ void tcx_encoder_memory_update_ivas_fx( Copy( synth + sub( L_frame_glob, M ), LPDmem->mem_syn2, M ); Copy( synth + sub( L_frame_glob, L_SYN_MEM ), LPDmem->mem_syn_r, L_SYN_MEM ); LPDmem->q_mem_syn = sub( shl( Q_new, 1 ), 1 ); // resultant q of synth after E_UTIL_f_preemph2 + move16(); test(); IF( st->tcxonly == 0 || LE_16( L_frame_glob, L_FRAME16k ) ) @@ -2871,8 +3012,10 @@ Word16 tcx_ari_res_Q_spec_fx( { sign = x_fac[i]; move16(); - if ( signs[i] != 0 ) + IF( signs[i] != 0 ) + { sign = negate( sign ); + } /* x_Q_m = x_Q[i] - sign*fac_m; x_Q_p = x_Q[i] + sign*fac_p; */ @@ -2940,8 +3083,10 @@ Word16 tcx_ari_res_Q_spec_fx( bits = add( bits, 1 ); L_tmp = L_shr( thres, s2 ); - if ( signs[i] ) + IF( signs[i] ) + { L_tmp = L_negate( L_tmp ); + } x_Q[i] = L_tmp; move32(); } @@ -3071,8 +3216,10 @@ Word16 tcx_ari_res_Q_spec_ivas_fx( bits = add( bits, 1 ); L_tmp = L_shr( thres, s2 ); - if ( signs[i] ) + IF( signs[i] ) + { L_tmp = L_negate( L_tmp ); + } x_Q[i] = L_tmp; move32(); } @@ -3099,8 +3246,10 @@ Word16 tcx_ari_res_Q_spec_ivas_fx( { sign = x_fac[i]; move16(); - if ( signs[i] != 0 ) + IF( signs[i] != 0 ) + { sign = negate( sign ); + } /* x_Q_m = x_Q[i] - sign*fac_m; x_Q_p = x_Q[i] + sign*fac_p; */ @@ -3168,8 +3317,10 @@ Word16 tcx_ari_res_Q_spec_ivas_fx( bits = add( bits, 1 ); L_tmp = L_shr( thres, s2 ); - if ( signs[i] ) + IF( signs[i] ) + { L_tmp = L_negate( L_tmp ); + } x_Q[i] = L_tmp; move32(); } @@ -3305,10 +3456,14 @@ Word16 tcx_res_Q_spec_fx( { tmp1 = L_add( x_orig[i], 0 ); tmp2 = Mpy_32_16_1( x_Q[i], sqGain ); - if ( s > 0 ) + IF( s > 0 ) + { tmp2 = L_shr( tmp2, s ); - if ( s < 0 ) + } + IF( s < 0 ) + { tmp1 = L_shl( tmp1, s ); + } if ( lf_deemph_factors != NULL ) { @@ -3322,10 +3477,14 @@ Word16 tcx_res_Q_spec_fx( move16(); bits = add( bits, 1 ); - if ( x_Q[i] > 0 ) + IF( x_Q[i] > 0 ) + { tmp1 = L_mult( fac_m, lf_deemph_factor ); - if ( x_Q[i] < 0 ) + } + IF( x_Q[i] < 0 ) + { tmp1 = L_mult( fac_p, lf_deemph_factor ); + } x_Q[i] = L_sub( x_Q[i], L_shr( tmp1, s2 ) ); move32(); } @@ -3335,10 +3494,14 @@ Word16 tcx_res_Q_spec_fx( move16(); bits = add( bits, 1 ); - if ( x_Q[i] > 0 ) + IF( x_Q[i] > 0 ) + { tmp1 = L_mult( fac_p, lf_deemph_factor ); - if ( x_Q[i] < 0 ) + } + IF( x_Q[i] < 0 ) + { tmp1 = L_mult( fac_m, lf_deemph_factor ); + } x_Q[i] = L_add( x_Q[i], L_shr( tmp1, s2 ) ); move32(); } @@ -3472,10 +3635,14 @@ Word16 tcx_res_Q_spec_ivas_fx( { tmp1 = L_add( x_orig[i], 0 ); tmp2 = Mpy_32_16_1( x_Q[i], sqGain ); - if ( s > 0 ) + IF( s > 0 ) + { tmp2 = L_shr( tmp2, s ); - if ( s < 0 ) + } + IF( s < 0 ) + { tmp1 = L_shl( tmp1, s ); + } if ( lf_deemph_factors != NULL ) { @@ -3489,10 +3656,14 @@ Word16 tcx_res_Q_spec_ivas_fx( move16(); bits = add( bits, 1 ); - if ( x_Q[i] > 0 ) + IF( x_Q[i] > 0 ) + { tmp1 = L_mult( fac_m, lf_deemph_factor ); - if ( x_Q[i] < 0 ) + } + IF( x_Q[i] < 0 ) + { tmp1 = L_mult( fac_p, lf_deemph_factor ); + } x_Q[i] = L_sub( x_Q[i], L_shr( tmp1, s2 ) ); move32(); } @@ -3502,10 +3673,14 @@ Word16 tcx_res_Q_spec_ivas_fx( move16(); bits = add( bits, 1 ); - if ( x_Q[i] > 0 ) + IF( x_Q[i] > 0 ) + { tmp1 = L_mult( fac_p, lf_deemph_factor ); - if ( x_Q[i] < 0 ) + } + IF( x_Q[i] < 0 ) + { tmp1 = L_mult( fac_m, lf_deemph_factor ); + } x_Q[i] = L_add( x_Q[i], L_shr( tmp1, s2 ) ); move32(); } @@ -3652,14 +3827,23 @@ void ProcessIGF_fx( Word16 Q_A; Word16 predictionGain = 0; Word16 *flatteningTrigger = &( st->hIGFEnc->flatteningTrigger ); + move32(); + move16(); + move16(); + move16(); + move32(); + move16(); + move16(); ITF_Detect_fx( spec_before, startLine, endLine, maxOrder, A, &Q_A, &predictionGain, &curr_order, shl( st->hIGFEnc->spec_be_igf_e, 1 ) ); *flatteningTrigger = 0; + move16(); test(); IF( LT_32( tns_predictionGain, 9646899l /*1.15 Q23*/ ) && LT_16( predictionGain, 147 /*1.15 Q7*/ ) ) { *flatteningTrigger = 1; + move16(); } } diff --git a/lib_enc/tfa_enc_fx.c b/lib_enc/tfa_enc_fx.c index cfb48aaec..af863f5d7 100644 --- a/lib_enc/tfa_enc_fx.c +++ b/lib_enc/tfa_enc_fx.c @@ -27,6 +27,7 @@ void tfaCalcEnv_fx( FOR( i = 0; i < N_TEC_TFA_SUBFR; i++ ) { enr[i] = L_deposit_l( 0 ); + move32(); FOR( j = 0; j < L_TEC_TFA_SUBFR16k; j++ ) { #ifdef BASOP_NOGLOB @@ -34,6 +35,7 @@ void tfaCalcEnv_fx( #else enr[i] = L_mac0( enr[i], shb_speech[k], shb_speech[k] ); #endif + move32(); k = add( k, 1 ); } } @@ -104,8 +106,8 @@ Word16 tfaEnc_TBE_fx( test(); test(); test(); - IF( ( GT_32( m_g, L_tmp ) && GT_16( pitch_buf_sum, 7040 /*110 Q6*/ ) && GT_16( voicing_sum, 22938 /*0.70 Q15*/ ) ) || - ( EQ_16( last_core, TCX_20_CORE ) && GT_32( m_g, L_tmp1 ) && LT_16( voicing_sum, 22938 /*0.70 Q15*/ ) ) ) + if ( ( GT_32( m_g, L_tmp ) && GT_16( pitch_buf_sum, 7040 /*110 Q6*/ ) && GT_16( voicing_sum, 22938 /*0.70 Q15*/ ) ) || + ( EQ_16( last_core, TCX_20_CORE ) && GT_32( m_g, L_tmp1 ) && LT_16( voicing_sum, 22938 /*0.70 Q15*/ ) ) ) { tfa_flag = 1; move16(); diff --git a/lib_enc/tns_base_enc_fx.c b/lib_enc/tns_base_enc_fx.c index 2f1762e43..093232632 100644 --- a/lib_enc/tns_base_enc_fx.c +++ b/lib_enc/tns_base_enc_fx.c @@ -59,6 +59,7 @@ Word16 DetectTnsFilt_fx( STnsConfig const *pTnsConfig, Word16 facs_e[TNS_MAX_NUM_OF_FILTERS][MAX_SUBDIVISIONS]; /* exponents of facs[][] */ Word16 shifts[TNS_MAX_NUM_OF_FILTERS][MAX_SUBDIVISIONS]; Word16 iFilter = 0; + move16(); ResetTnsData( pTnsData ); @@ -76,6 +77,7 @@ Word16 DetectTnsFilt_fx( STnsConfig const *pTnsConfig, Word16 iSubdivisions; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif move16(); @@ -102,12 +104,16 @@ Word16 DetectTnsFilt_fx( STnsConfig const *pTnsConfig, iStartLine = imult1616( tmp, iSubdivisions ); iEndLine = add( iStartLine, tmp ); - if ( EQ_16( nSubdivisions, 3 ) ) + IF( EQ_16( nSubdivisions, 3 ) ) + { iStartLine = mult( iStartLine, 0x2AAB ); + } iStartLine = add( iStartLine, idx0 ); - if ( EQ_16( nSubdivisions, 3 ) ) + IF( EQ_16( nSubdivisions, 3 ) ) + { iEndLine = mult( iEndLine, 0x2AAB ); + } iEndLine = add( iEndLine, idx0 ); /*norms[iFilter][iSubdivisions] = norm2FLOAT(pSpectrum+iStartLine, iEndLine-iStartLine);*/ @@ -211,12 +217,16 @@ Word16 DetectTnsFilt_fx( STnsConfig const *pTnsConfig, iStartLine = imult1616( spectrumLength, iSubdivisions ); iEndLine = add( iStartLine, spectrumLength ); - if ( EQ_16( nSubdivisions, 3 ) ) + IF( EQ_16( nSubdivisions, 3 ) ) + { iStartLine = mult( iStartLine, 0x2AAB ); + } iStartLine = add( iStartLine, idx0 ); - if ( EQ_16( nSubdivisions, 3 ) ) + IF( EQ_16( nSubdivisions, 3 ) ) + { iEndLine = mult( iEndLine, 0x2AAB ); + } iEndLine = add( iEndLine, idx0 ); @@ -235,6 +245,7 @@ Word16 DetectTnsFilt_fx( STnsConfig const *pTnsConfig, #else tmpbuf[i] = round_fx( L_shl( pSpectrum[iStartLine + i], shift ) ); #endif + move16(); } FOR( lag = 0; lag <= pTnsConfig->maxOrder; lag++ ) @@ -251,8 +262,8 @@ Word16 DetectTnsFilt_fx( STnsConfig const *pTnsConfig, #endif } - if ( lag != 0 ) - L_tmp = Mpy_32_16_1( L_tmp, *pWindow++ ); + IF( lag != 0 ) + L_tmp = Mpy_32_16_1( L_tmp, *pWindow++ ); L_tmp = Mpy_32_16_1( L_tmp, facs[iFilter][iSubdivisions] ); L_tmp = L_shl( L_tmp, facs_e[iFilter][iSubdivisions] ); @@ -311,7 +322,6 @@ Word16 DetectTnsFilt_fx( STnsConfig const *pTnsConfig, } - test(); return ( pTnsData->nFilters > 0 ); } @@ -460,6 +470,7 @@ Word16 DetectTnsFilt_ivas_fx( STnsConfig const *pTnsConfig, /* i : TNS Configur Word16 iSubdivisions; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif move16(); @@ -486,12 +497,16 @@ Word16 DetectTnsFilt_ivas_fx( STnsConfig const *pTnsConfig, /* i : TNS Configur iStartLine = imult1616( tmp, iSubdivisions ); iEndLine = add( iStartLine, tmp ); - if ( EQ_16( nSubdivisions, 3 ) ) + IF( EQ_16( nSubdivisions, 3 ) ) + { iStartLine = mult( iStartLine, 0x2AAB ); + } iStartLine = add( iStartLine, idx0 ); - if ( EQ_16( nSubdivisions, 3 ) ) + IF( EQ_16( nSubdivisions, 3 ) ) + { iEndLine = mult( iEndLine, 0x2AAB ); + } iEndLine = add( iEndLine, idx0 ); /*norms[iFilter][iSubdivisions] = norm2FLOAT(pSpectrum+iStartLine, iEndLine-iStartLine);*/ @@ -595,12 +610,16 @@ Word16 DetectTnsFilt_ivas_fx( STnsConfig const *pTnsConfig, /* i : TNS Configur iStartLine = imult1616( spectrumLength, iSubdivisions ); iEndLine = add( iStartLine, spectrumLength ); - if ( EQ_16( nSubdivisions, 3 ) ) + IF( EQ_16( nSubdivisions, 3 ) ) + { iStartLine = mult( iStartLine, 0x2AAB ); + } iStartLine = add( iStartLine, idx0 ); - if ( EQ_16( nSubdivisions, 3 ) ) + IF( EQ_16( nSubdivisions, 3 ) ) + { iEndLine = mult( iEndLine, 0x2AAB ); + } iEndLine = add( iEndLine, idx0 ); @@ -632,8 +651,10 @@ Word16 DetectTnsFilt_ivas_fx( STnsConfig const *pTnsConfig, /* i : TNS Configur #endif } - if ( lag != 0 ) + IF( lag != 0 ) + { L_tmp = Mpy_32_16_1( L_tmp, *pWindow++ ); + } L_tmp = Mpy_32_16_1( L_tmp, facs[iFilter][iSubdivisions] ); L_tmp = L_shl( L_tmp, facs_e[iFilter][iSubdivisions] ); @@ -652,7 +673,7 @@ Word16 DetectTnsFilt_ivas_fx( STnsConfig const *pTnsConfig, /* i : TNS Configur } } - if ( predictionGain ) + IF( predictionGain ) { assert( pTnsConfig->nMaxFilters == 1 ); move16(); @@ -660,7 +681,7 @@ Word16 DetectTnsFilt_ivas_fx( STnsConfig const *pTnsConfig, /* i : TNS Configur } /* We check the filter's decisions in the opposite direction */ - FOR( iFilter = sub( pTnsConfig->nMaxFilters, 1 ); iFilter >= 0; iFilter-- ) + FOR( iFilter = ( pTnsConfig->nMaxFilters - 1 ); iFilter >= 0; iFilter-- ) { STnsFilter *pFilter; struct TnsParameters const *pTnsParameters; @@ -673,7 +694,6 @@ Word16 DetectTnsFilt_ivas_fx( STnsConfig const *pTnsConfig, /* i : TNS Configur IF( s_or( (Word16) GT_16( pFilter->predictionGain, pTnsParameters->minPredictionGain ), sub( pFilter->avgSqrCoef, pTnsParameters->minAvgSqrCoef ) > 0 ) ) { - move16(); // pTnsData->nFilters > 0 || isTCX10 || ltp_gain < 0.6f || hTranDet == NULL // .6f = 19660, Q=15 test(); @@ -884,8 +904,10 @@ static void GetFilterParameters( Word32 rxx[], Word16 maxOrder, STnsFilter *pTns /* reduce filter order by truncating trailing zeros */ i = sub( maxOrder, 1 ); + test(); WHILE( ( i >= 0 ) && ( indexes[i] == 0 ) ) { + test(); i = sub( i, 1 ); } @@ -899,10 +921,8 @@ static void GetFilterParameters( Word32 rxx[], Word16 maxOrder, STnsFilter *pTns { Word16 value; - move16(); value = shr( values[indexes[i] + INDEX_SHIFT], 1 ); - move16(); L_tmp = L_mac0( L_tmp, value, value ); } move16(); @@ -921,7 +941,6 @@ static void Parcor2Index( const Word16 parCoeff[] /*Q15*/, Word16 index[], Word1 Word16 x; - move16(); move16(); nValues = 1 << TNS_COEF_RES; #if TNS_COEF_RES == 5 @@ -942,10 +961,13 @@ static void Parcor2Index( const Word16 parCoeff[] /*Q15*/, Word16 index[], Word1 /* parCoeff is in the range of -1.0 ... 1.0 by definition */ /* assert((x >= FL2WORD16(-1.0f)) && (x <= FL2WORD16(1.0f))); */ + test(); WHILE( ( iIndex < nValues ) && ( x > add( shr( values[iIndex - 1], 1 ), shr( values[iIndex], 1 ) ) ) ) { + test(); iIndex = add( iIndex, 1 ); } index[i] = sub( iIndex, 1 + INDEX_SHIFT ); + move16(); } } diff --git a/lib_enc/transient_detection_fx.c b/lib_enc/transient_detection_fx.c index 47808cca0..987ddc857 100644 --- a/lib_enc/transient_detection_fx.c +++ b/lib_enc/transient_detection_fx.c @@ -16,6 +16,7 @@ #include "ivas_prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ + /* Exponent of attack threshold. Picked according to current threshold values. */ #define ATTACKTHRESHOLD_E 4 /* Exponent of subblock energies and accumulated subblock energies. @@ -377,9 +378,11 @@ Word16 GetTCXMaxenergyChange_fx( struct TransientDetection const *pTransientDete nRelativeDelay = sub( pSubblockEnergies->nDelay, nDelay ); pSubblockNrgChange = NULL; nTotBlocks = nCurrentSubblocks + nPrevSubblocks; + move16(); assert( nTotBlocks > 0 ); maxEnergyChange = 0 /*0.0f Q7*/; + move16(); assert( ( nPrevSubblocks <= nRelativeDelay ) && ( nCurrentSubblocks <= NSUBBLOCKS + nDelay ) ); pSubblockNrgChange = &pSubblockEnergies->subblockNrgChange[nRelativeDelay - nPrevSubblocks]; @@ -758,7 +761,7 @@ void SetTCXModeInfo_ivas_fx( IF( isLongTermTransient_fx( L_deposit_h( tmp ), &hTcxEnc->tfm_mem_fx ) && EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) { test(); - if ( NE_16( *tcxModeOverlap, MIN_OVERLAP ) && LT_16( hTcxEnc->tcxltp_norm_corr_past, 18432 /* 0.5625f in Q15 */ ) ) + IF( NE_16( *tcxModeOverlap, MIN_OVERLAP ) && LT_16( hTcxEnc->tcxltp_norm_corr_past, 18432 /* 0.5625f in Q15 */ ) ) { *tcxModeOverlap = HALF_OVERLAP; move16(); @@ -809,7 +812,7 @@ void SetTCXModeInfo_ivas_fx( /* for the ACELP -> TCX transition frames use full right window overlap */ test(); - if ( ( EQ_16( st->hTcxCfg->tcx_last_overlap_mode, TRANSITION_OVERLAP ) ) && ( EQ_16( *tcxModeOverlap, ALDO_WINDOW ) ) ) + IF( ( EQ_16( st->hTcxCfg->tcx_last_overlap_mode, TRANSITION_OVERLAP ) ) && ( EQ_16( *tcxModeOverlap, ALDO_WINDOW ) ) ) { *tcxModeOverlap = FULL_OVERLAP; move16(); @@ -967,6 +970,7 @@ static void InitDelayBuffer( Word16 nFrameLength, Word16 nDelay, DelayBuffer *pD static void InitSubblockEnergies( Word16 nFrameLength, Word16 nDelay, DelayBuffer *pDelayBuffer, SubblockEnergies *pSubblockEnergies ) { Word16 const nMaxBuffSize = sizeof( pSubblockEnergies->subblockNrg ) / sizeof( pSubblockEnergies->subblockNrg[0] ); + move16(); (void) nFrameLength; @@ -975,12 +979,17 @@ static void InitSubblockEnergies( Word16 nFrameLength, Word16 nDelay, DelayBuffe set32_fx( pSubblockEnergies->subblockNrg, MIN_BLOCK_ENERGY, nMaxBuffSize ); set32_fx( pSubblockEnergies->accSubblockNrg, MIN_BLOCK_ENERGY, nMaxBuffSize + 1 ); set16_fx( pSubblockEnergies->subblockNrgChange, 0x7fff, nMaxBuffSize ); - pSubblockEnergies->nDelay = nDelay / pDelayBuffer->nSubblockSize; + pSubblockEnergies->nDelay = idiv1616_1( nDelay, pDelayBuffer->nSubblockSize ); assert( pSubblockEnergies->nDelay < nMaxBuffSize ); pSubblockEnergies->nPartialDelay = nDelay % pDelayBuffer->nSubblockSize; pSubblockEnergies->facAccSubblockNrg = 26624 /*0.8125f Q15*/; /* Energy accumulation factor */ pSubblockEnergies->firState1 = 0; pSubblockEnergies->firState2 = 0; + move16(); + move16(); + move16(); + move16(); + move16(); pSubblockEnergies->pDelayBuffer = pDelayBuffer; pDelayBuffer->nDelay = s_max( pDelayBuffer->nDelay, pSubblockEnergies->nPartialDelay ); @@ -1043,16 +1052,22 @@ static void InitTransientDetector_fx( SubblockEnergies *pSubblockEnergies, Word1 assert( ( pSubblockEnergies != NULL ) && ( pSubblockEnergies->pDelayBuffer != NULL ) && ( pTransientDetector != NULL ) && ( pSubblockEnergies->pDelayBuffer->nSubblockSize != 0 ) ); pTransientDetector->pSubblockEnergies = pSubblockEnergies; pTransientDetector->nDelay = ( nDelay - pSubblockEnergies->nPartialDelay ) / pSubblockEnergies->pDelayBuffer->nSubblockSize; + move16(); assert( nDelay == pTransientDetector->nDelay * pSubblockEnergies->pDelayBuffer->nSubblockSize + pSubblockEnergies->nPartialDelay ); assert( pTransientDetector->nDelay < nMaxBuffSize ); pSubblockEnergies->nDelay = s_max( pSubblockEnergies->nDelay, pTransientDetector->nDelay ); assert( nSubblocksToCheck <= NSUBBLOCKS + pTransientDetector->nDelay ); pTransientDetector->nSubblocksToCheck = nSubblocksToCheck; + move16(); pTransientDetector->CheckSubblocksForAttack_fx = pCheckSubblocksForAttack; pTransientDetector->attackRatioThreshold = attackRatioThreshold; + move16(); pTransientDetector->prev_bIsAttackPresent = FALSE; + move16(); pTransientDetector->bIsAttackPresent = FALSE; + move16(); pTransientDetector->attackIndex = -1; + move16(); } static void InitTransientDetector_ivas_fx( SubblockEnergies *pSubblockEnergies, Word16 nDelay, Word16 nSubblocksToCheck, TCheckSubblocksForAttack_fx pCheckSubblocksForAttack, Word16 attackRatioThreshold, TransientDetector *pTransientDetector ) @@ -1156,7 +1171,7 @@ static void UpdateDelayBuffer( Word16 const *input, Word16 nSamplesAvailable, De assert( ( nDelay >= 0 ) && ( nDelay <= (int) sizeof( pDelayBuffer->buffer ) / (int) sizeof( pDelayBuffer->buffer[0] ) ) ); assert( nSamplesAvailable <= NSUBBLOCKS * pDelayBuffer->nSubblockSize ); /* If this is not the last frame */ - IF( nSamplesAvailable == NSUBBLOCKS * pDelayBuffer->nSubblockSize ) + IF( EQ_16( nSamplesAvailable, imult1616( NSUBBLOCKS, pDelayBuffer->nSubblockSize ) ) ) { /* Store the newest samples into the delay buffer */ FOR( i = 0; i < nDelay; i++ ) @@ -1561,7 +1576,7 @@ Word16 transient_analysis_ivas_fx( const Word16 nRelativeDelay = sub( hTranDet->subblockEnergies.nDelay, hTranDet->transientDetector.nDelay ); Word16 prel_force_td; Word32 cor_map_LT_sum = 0; - move16(); + move32(); /* Set pointer to the reverse accumulator buffer */ pTmp_fx = &accSubblockNrgRev_fx[NSUBBLOCKS - 1]; diff --git a/lib_enc/transition_enc_fx.c b/lib_enc/transition_enc_fx.c index b4f9b2681..c68daa2a7 100644 --- a/lib_enc/transition_enc_fx.c +++ b/lib_enc/transition_enc_fx.c @@ -114,6 +114,8 @@ void transition_enc_fx( T_op[1] = (int16_t)(pitch[1] * 1.25f + 0.5f);*/ T_op[0] = add( st_fx->pitch[0], mult_r( st_fx->pitch[0], 8192 /*0.25f Q15*/ ) ); T_op[1] = add( st_fx->pitch[1], mult_r( st_fx->pitch[1], 8192 /*0.25f Q15*/ ) ); + move16(); + move16(); } shift_wsp = add( Q_new, shift ); @@ -132,6 +134,7 @@ void transition_enc_fx( IF( i_subfr == 0 ) { mult_Top = 1; + move16(); IF( limit_flag == 0 ) { test(); @@ -166,6 +169,7 @@ void transition_enc_fx( g_corr_fx[2] = -16384; move16(); g_corr_fx[3] = shl( sub( shift_wsp, 1 ), 1 ); + move16(); set16_fx( &exc_fx[i_subfr], 0, L_SUBFR ); /* set excitation for current subrame to 0 */ @@ -215,6 +219,7 @@ void transition_enc_fx( ); } *clip_gain = gp_clip_fx( st_fx->element_mode, st_fx->core_brate, st_fx->voicing_fx, i_subfr, TRANSITION, xn_fx, gp_cl_fx, sub( shift_wsp, 1 ) ); + move16(); updt_tar_fx( xn_fx, xn2_fx, y1_fx, *gain_pit_fx, L_SUBFR ); **pt_pitch_fx = shl( add( shl( *T0, 2 ), *T0_frac ), 4 ); @@ -282,6 +287,7 @@ void transition_enc_fx( /* Find the closed loop pitch period */ *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, pit_flag, limit_flag, pit_start, pit_limit, L_FRAME, L_SUBFR ); + move16(); offset = tbe_celp_exc_offset( *T0, *T0_frac, st_fx->L_frame ); @@ -289,6 +295,7 @@ void transition_enc_fx( FOR( i = 0; i < L_SUBFR * HIBND_ACB_L_FAC; i++ ) { bwe_exc_fx[i + i_subfr * HIBND_ACB_L_FAC] = bwe_exc_fx[i + i_subfr * HIBND_ACB_L_FAC - offset]; + move16(); } @@ -394,6 +401,7 @@ void transition_enc_fx( FOR( i = 0; i < L_SUBFR * HIBND_ACB_L_FAC; i++ ) { bwe_exc_fx[i + i_subfr * HIBND_ACB_L_FAC] = bwe_exc_fx[i + i_subfr * HIBND_ACB_L_FAC - offset]; + move16(); } } ELSE IF( ( EQ_16( i_subfr, 2 * L_SUBFR ) ) && ( EQ_16( *tc_subfr, TC_0_128 ) ) ) @@ -408,6 +416,7 @@ void transition_enc_fx( move16(); *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, pit_flag, limit_flag, pit_start, 3 * L_SUBFR, L_FRAME, L_SUBFR ); + move16(); IF( LT_16( add( ( *T0 ), ( *position ) ), 2 * L_SUBFR ) ) { @@ -441,6 +450,7 @@ void transition_enc_fx( FOR( i = 0; i < L_SUBFR * HIBND_ACB_L_FAC; i++ ) { bwe_exc_fx[i + i_subfr * HIBND_ACB_L_FAC] = bwe_exc_fx[i + i_subfr * HIBND_ACB_L_FAC - offset]; + move16(); } } ELSE IF( ( EQ_16( i_subfr, 2 * L_SUBFR ) ) && ( EQ_16( *tc_subfr, TC_0_192 ) ) ) @@ -469,6 +479,7 @@ void transition_enc_fx( move16(); *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, pit_flag, limit_flag, PIT_MIN, PIT_FR1_8b, L_FRAME, L_SUBFR ); + move16(); IF( LT_16( add( *T0, *position ), 3 * L_SUBFR ) ) { @@ -514,6 +525,7 @@ void transition_enc_fx( pit_flag = L_SUBFR; move16(); *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, pit_flag, limit_flag, PIT_MIN, PIT_FR1_8b, L_FRAME, L_SUBFR ); + move16(); index = delta_pit_enc_fx( 2, *T0, *T0_frac, *T0_min ); push_indice_fx( hBstr, IND_PITCH, index, nBits ); @@ -526,6 +538,7 @@ void transition_enc_fx( FOR( i = 0; i < L_SUBFR * HIBND_ACB_L_FAC; i++ ) { bwe_exc_fx[i + i_subfr * HIBND_ACB_L_FAC] = bwe_exc_fx[i + i_subfr * HIBND_ACB_L_FAC - offset]; + move16(); } } @@ -538,15 +551,18 @@ void transition_enc_fx( test(); IF( EQ_16( nBits, 8 ) || EQ_16( nBits, 5 ) ) { + test(); test(); IF( !( ( *tc_subfr == 0 ) && ( EQ_16( i_subfr, L_SUBFR ) ) ) ) { *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, pit_flag, limit_flag, PIT_MIN, PIT_FR1_8b, L_FRAME, L_SUBFR ); + move16(); } } ELSE { *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, pit_flag, limit_flag, PIT_FR2_9b, PIT_FR1_9b, L_FRAME, L_SUBFR ); + move16(); } pit_Q_enc_fx( hBstr, 0, nBits, 8, pit_flag, limit_flag, *T0, *T0_frac, T0_min, T0_max ); @@ -558,6 +574,7 @@ void transition_enc_fx( FOR( i = 0; i < L_SUBFR * HIBND_ACB_L_FAC; i++ ) { bwe_exc_fx[i + i_subfr * HIBND_ACB_L_FAC] = bwe_exc_fx[i + i_subfr * HIBND_ACB_L_FAC - offset]; + move16(); } } @@ -584,6 +601,7 @@ void transition_enc_fx( ELSE { *clip_gain = gp_clip_fx( st_fx->element_mode, st_fx->core_brate, st_fx->voicing_fx, i_subfr, TRANSITION, xn_fx, gp_cl_fx, ( Q_new + shift - 1 ) ); + move16(); lp_select = lp_filt_exc_enc_fx( MODE1, TRANSITION, i_subfr, exc_fx, h1_fx, xn_fx, y1_fx, xn2_fx, L_SUBFR, st_fx->L_frame, g_corr_fx, *clip_gain, gain_pit_fx, &lp_flag ); @@ -604,7 +622,7 @@ void transition_enc_fx( test(); test(); test(); - IF( ( *tc_subfr >= 2 * L_SUBFR ) && ( i_subfr == 3 * L_SUBFR ) ) + IF( ( GE_16( *tc_subfr, 2 * L_SUBFR ) ) && ( EQ_16( i_subfr, 3 * L_SUBFR ) ) ) { tmp = shl( add( shl( *T0, 2 ), *T0_frac ), 4 ); ( *pt_pitch_fx ) -= 3; @@ -620,8 +638,9 @@ void transition_enc_fx( **pt_pitch_fx = tmp; move16(); ( *pt_pitch_fx )++; + move16(); } - ELSE IF( ( *tc_subfr == L_SUBFR ) && ( i_subfr == 2 * L_SUBFR ) ) + ELSE IF( ( EQ_16( *tc_subfr, L_SUBFR ) ) && ( EQ_16( i_subfr, 2 * L_SUBFR ) ) ) { tmp = shl( add( shl( *T0, 2 ), *T0_frac ), 4 ); ( *pt_pitch_fx ) -= 2; @@ -635,7 +654,7 @@ void transition_enc_fx( ( *pt_pitch_fx )++; move16(); } - ELSE IF( ( *tc_subfr == TC_0_64 ) && ( i_subfr == L_SUBFR ) ) + ELSE IF( ( EQ_16( *tc_subfr, TC_0_64 ) ) && ( EQ_16( i_subfr, L_SUBFR ) ) ) { tmp = shl( add( shl( *T0, 2 ), *T0_frac ), 4 ); ( *pt_pitch_fx ) -= 1; @@ -645,7 +664,7 @@ void transition_enc_fx( ( *pt_pitch_fx )++; move16(); } - ELSE IF( ( *tc_subfr == TC_0_128 ) && ( i_subfr == 2 * L_SUBFR ) ) + ELSE IF( ( EQ_16( *tc_subfr, TC_0_128 ) ) && ( EQ_16( i_subfr, 2 * L_SUBFR ) ) ) { tmp = shl( add( shl( *T0, 2 ), *T0_frac ), 4 ); ( *pt_pitch_fx ) -= 2; @@ -659,7 +678,7 @@ void transition_enc_fx( ( *pt_pitch_fx )++; move16(); } - ELSE IF( ( *tc_subfr == TC_0_192 ) && ( i_subfr == 3 * L_SUBFR ) ) + ELSE IF( ( EQ_16( *tc_subfr, TC_0_192 ) ) && ( EQ_16( i_subfr, 3 * L_SUBFR ) ) ) { tmp = shl( add( shl( *T0, 2 ), *T0_frac ), 4 ); ( *pt_pitch_fx ) -= 3; @@ -719,6 +738,7 @@ void transition_enc_fx( IF( EQ_16( nBits, 10 ) ) { *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, 0, limit_flag, PIT16k_FR2_EXTEND_10b, PIT16k_MAX, st_fx->L_frame, L_SUBFR ); + move16(); pit16k_Q_enc_fx( hBstr, nBits, limit_flag, *T0, *T0_frac, T0_min, T0_max ); } ELSE IF( EQ_16( nBits, 8 ) ) /* tc_subfr==0 && i_subfr==L_SUBFR */ @@ -729,6 +749,7 @@ void transition_enc_fx( * PIT16k_FR2_TC0_2SUBFR to 2*L_SUBFR resolution 1/2 (frac = 0 or 2) *-----------------------------------------------------------------------------*/ *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, 0, limit_flag, PIT16k_FR2_TC0_2SUBFR, 2 * L_SUBFR, st_fx->L_frame, L_SUBFR ); + move16(); IF( GT_16( *T0_max, 2 * L_SUBFR ) ) { @@ -754,6 +775,7 @@ void transition_enc_fx( { /* delta search */ *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, L_SUBFR, limit_flag, PIT16k_FR2_EXTEND_9b, PIT16k_FR1_EXTEND_9b, st_fx->L_frame, L_SUBFR ); + move16(); index = delta_pit_enc_fx( 4, *T0, *T0_frac, *T0_min ); push_indice_fx( hBstr, IND_PITCH, index, nBits ); @@ -807,9 +829,11 @@ void transition_enc_fx( { /* bwe_exc_fx[i + i_subfr * 2] = bwe_exc_fx[i + i_subfr * 2 - *T0 * 2 - (int) ((float) *T0_frac * 0.5f + 4 + 0.5f) + 4];move16();*/ bwe_exc_fx[i + i_subfr * 2] = bwe_exc_fx[i + i_subfr * 2 - offset + 4]; + move16(); } *clip_gain = gp_clip_fx( st_fx->element_mode, st_fx->core_brate, st_fx->voicing_fx, i_subfr, TRANSITION, xn_fx, gp_cl_fx, Q_new ); + move16(); lp_select = lp_filt_exc_enc_fx( MODE1, TRANSITION, i_subfr, exc_fx, h1_fx, xn_fx, y1_fx, xn2_fx, L_SUBFR, st_fx->L_frame, g_corr_fx, *clip_gain, gain_pit_fx, &lp_flag ); @@ -845,6 +869,7 @@ void transition_enc_fx( **pt_pitch_fx = tmp; move16(); ( *pt_pitch_fx )++; + move16(); } } } @@ -908,7 +933,9 @@ void transition_enc_ivas_fx( /*T_op[0] = (int16_t)(pitch[0] * 1.25f + 0.5f); T_op[1] = (int16_t)(pitch[1] * 1.25f + 0.5f);*/ T_op[0] = add( st_fx->pitch[0], mult_r( st_fx->pitch[0], 8192 /*0.25f Q15*/ ) ); + move16(); T_op[1] = add( st_fx->pitch[1], mult_r( st_fx->pitch[1], 8192 /*0.25f Q15*/ ) ); + move16(); } shift_wsp = add( Q_new, shift ); @@ -927,6 +954,7 @@ void transition_enc_ivas_fx( IF( i_subfr == 0 ) { mult_Top = 1; + move16(); IF( limit_flag == 0 ) { test(); @@ -956,7 +984,6 @@ void transition_enc_ivas_fx( move16(); g_corr_fx[0] = MAX16B /* 1.0f in Q15 */; move16(); - move16(); g_corr_fx[1] = 0; move16(); g_corr_fx[2] = MAX16B /* 1.0f in Q15 */; @@ -1012,6 +1039,7 @@ void transition_enc_ivas_fx( ); } *clip_gain = gp_clip_fx( st_fx->element_mode, st_fx->core_brate, st_fx->voicing_fx, i_subfr, TRANSITION, xn_fx, gp_cl_fx, sub( shift_wsp, 1 ) ); + move16(); updt_tar_fx( xn_fx, xn2_fx, y1_fx, *gain_pit_fx, L_SUBFR ); **pt_pitch_fx = shl( add( shl( *T0, 2 ), *T0_frac ), 4 ); @@ -1079,6 +1107,7 @@ void transition_enc_ivas_fx( /* Find the closed loop pitch period */ *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, pit_flag, limit_flag, pit_start, pit_limit, L_FRAME, L_SUBFR ); + move16(); offset = tbe_celp_exc_offset( *T0, *T0_frac, st_fx->L_frame ); @@ -1086,6 +1115,7 @@ void transition_enc_ivas_fx( FOR( i = 0; i < L_SUBFR * HIBND_ACB_L_FAC; i++ ) { bwe_exc_fx[i + i_subfr * HIBND_ACB_L_FAC] = bwe_exc_fx[i + i_subfr * HIBND_ACB_L_FAC - offset]; + move16(); } @@ -1191,6 +1221,7 @@ void transition_enc_ivas_fx( FOR( i = 0; i < L_SUBFR * HIBND_ACB_L_FAC; i++ ) { bwe_exc_fx[i + i_subfr * HIBND_ACB_L_FAC] = bwe_exc_fx[i + i_subfr * HIBND_ACB_L_FAC - offset]; + move16(); } } ELSE IF( ( EQ_16( i_subfr, 2 * L_SUBFR ) ) && ( EQ_16( *tc_subfr, TC_0_128 ) ) ) @@ -1205,6 +1236,7 @@ void transition_enc_ivas_fx( move16(); *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, pit_flag, limit_flag, pit_start, 3 * L_SUBFR, L_FRAME, L_SUBFR ); + move16(); IF( LT_16( add( ( *T0 ), ( *position ) ), 2 * L_SUBFR ) ) { @@ -1238,6 +1270,7 @@ void transition_enc_ivas_fx( FOR( i = 0; i < L_SUBFR * HIBND_ACB_L_FAC; i++ ) { bwe_exc_fx[i + i_subfr * HIBND_ACB_L_FAC] = bwe_exc_fx[i + i_subfr * HIBND_ACB_L_FAC - offset]; + move16(); } } ELSE IF( ( EQ_16( i_subfr, 2 * L_SUBFR ) ) && ( EQ_16( *tc_subfr, TC_0_192 ) ) ) @@ -1266,6 +1299,7 @@ void transition_enc_ivas_fx( move16(); *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, pit_flag, limit_flag, PIT_MIN, PIT_FR1_8b, L_FRAME, L_SUBFR ); + move16(); IF( LT_16( add( *T0, *position ), 3 * L_SUBFR ) ) { @@ -1310,7 +1344,9 @@ void transition_enc_ivas_fx( *--------------------------------------------------------*/ pit_flag = L_SUBFR; move16(); + *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, pit_flag, limit_flag, PIT_MIN, PIT_FR1_8b, L_FRAME, L_SUBFR ); + move16(); index = delta_pit_enc_fx( 2, *T0, *T0_frac, *T0_min ); push_indice( hBstr, IND_PITCH, index, nBits ); @@ -1323,6 +1359,7 @@ void transition_enc_ivas_fx( FOR( i = 0; i < L_SUBFR * HIBND_ACB_L_FAC; i++ ) { bwe_exc_fx[i + i_subfr * HIBND_ACB_L_FAC] = bwe_exc_fx[i + i_subfr * HIBND_ACB_L_FAC - offset]; + move16(); } } @@ -1339,11 +1376,13 @@ void transition_enc_ivas_fx( IF( !( ( *tc_subfr == 0 ) && ( EQ_16( i_subfr, L_SUBFR ) ) ) ) { *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, pit_flag, limit_flag, PIT_MIN, PIT_FR1_8b, L_FRAME, L_SUBFR ); + move16(); } } ELSE { *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, pit_flag, limit_flag, PIT_FR2_9b, PIT_FR1_9b, L_FRAME, L_SUBFR ); + move16(); } pit_Q_enc_ivas_fx( hBstr, 0, nBits, 8, pit_flag, limit_flag, *T0, *T0_frac, T0_min, T0_max ); @@ -1355,6 +1394,7 @@ void transition_enc_ivas_fx( FOR( i = 0; i < L_SUBFR * HIBND_ACB_L_FAC; i++ ) { bwe_exc_fx[i + i_subfr * HIBND_ACB_L_FAC] = bwe_exc_fx[i + i_subfr * HIBND_ACB_L_FAC - offset]; + move16(); } } @@ -1381,6 +1421,7 @@ void transition_enc_ivas_fx( ELSE { *clip_gain = gp_clip_fx( st_fx->element_mode, st_fx->core_brate, st_fx->voicing_fx, i_subfr, TRANSITION, xn_fx, gp_cl_fx, ( Q_new + shift - 1 ) ); + move16(); lp_select = lp_filt_exc_enc_ivas_fx( MODE1, TRANSITION, i_subfr, exc_fx, h1_fx, xn_fx, y1_fx, xn2_fx, L_SUBFR, st_fx->L_frame, g_corr_fx, *clip_gain, gain_pit_fx, &lp_flag ); @@ -1417,6 +1458,7 @@ void transition_enc_ivas_fx( **pt_pitch_fx = tmp; move16(); ( *pt_pitch_fx )++; + move16(); } ELSE IF( ( *tc_subfr == L_SUBFR ) && ( i_subfr == 2 * L_SUBFR ) ) { @@ -1516,6 +1558,7 @@ void transition_enc_ivas_fx( IF( EQ_16( nBits, 10 ) ) { *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, 0, limit_flag, PIT16k_FR2_EXTEND_10b, PIT16k_MAX, st_fx->L_frame, L_SUBFR ); + move16(); pit16k_Q_enc_ivas_fx( hBstr, nBits, limit_flag, *T0, *T0_frac, T0_min, T0_max ); } ELSE IF( EQ_16( nBits, 8 ) ) /* tc_subfr==0 && i_subfr==L_SUBFR */ @@ -1526,6 +1569,7 @@ void transition_enc_ivas_fx( * PIT16k_FR2_TC0_2SUBFR to 2*L_SUBFR resolution 1/2 (frac = 0 or 2) *-----------------------------------------------------------------------------*/ *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, 0, limit_flag, PIT16k_FR2_TC0_2SUBFR, 2 * L_SUBFR, st_fx->L_frame, L_SUBFR ); + move16(); IF( GT_16( *T0_max, 2 * L_SUBFR ) ) { @@ -1551,6 +1595,7 @@ void transition_enc_ivas_fx( { /* delta search */ *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, L_SUBFR, limit_flag, PIT16k_FR2_EXTEND_9b, PIT16k_FR1_EXTEND_9b, st_fx->L_frame, L_SUBFR ); + move16(); index = delta_pit_enc_fx( 4, *T0, *T0_frac, *T0_min ); push_indice( hBstr, IND_PITCH, index, nBits ); @@ -1608,9 +1653,11 @@ void transition_enc_ivas_fx( { /* bwe_exc_fx[i + i_subfr * 2] = bwe_exc_fx[i + i_subfr * 2 - *T0 * 2 - (int) ((float) *T0_frac * 0.5f + 4 + 0.5f) + 4];move16();*/ bwe_exc_fx[i + i_subfr * 2] = bwe_exc_fx[i + i_subfr * 2 - offset + 4]; + move16(); } *clip_gain = gp_clip_fx( st_fx->element_mode, st_fx->core_brate, st_fx->voicing_fx, i_subfr, TRANSITION, xn_fx, gp_cl_fx, Q_new ); + move16(); lp_select = lp_filt_exc_enc_ivas_fx( MODE1, TRANSITION, i_subfr, exc_fx, h1_fx, xn_fx, y1_fx, xn2_fx, L_SUBFR, st_fx->L_frame, g_corr_fx, *clip_gain, gain_pit_fx, &lp_flag ); @@ -1646,6 +1693,7 @@ void transition_enc_ivas_fx( **pt_pitch_fx = tmp; move16(); ( *pt_pitch_fx )++; + move16(); } } } @@ -1695,6 +1743,7 @@ static void tc_enc_fx( BSTR_ENC_HANDLE hBstr = st_fx->hBstr; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif imp_pos = sub( *position, i_subfr ); FOR( i = 0; i < L_SUBFR; i++ ) @@ -1707,6 +1756,7 @@ static void tc_enc_fx( *-----------------------------------------------------------------*/ nBits = st_fx->acelp_cfg.pitch_bits[shr( i_subfr, 6 )]; + move16(); /*--------------------------------------------------------------* * Closed loop pitch search @@ -1723,14 +1773,17 @@ static void tc_enc_fx( IF( EQ_16( nBits, 9 ) ) { *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, 0, 0, PIT_FR2_9b, PIT_FR1_9b, L_FRAME, L_SUBFR ); + move16(); } ELSE IF( EQ_16( nBits, 6 ) ) { *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, 0, 0, PIT_MIN, L_SUBFR, L_FRAME, L_SUBFR ); + move16(); } ELSE { *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, 0, 0, PIT_MAX, PIT_MIN, L_FRAME, L_SUBFR ); + move16(); } } ELSE @@ -1750,11 +1803,13 @@ static void tc_enc_fx( IF( EQ_16( nBits, 10 ) ) { *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, 0, 1, PIT16k_FR2_EXTEND_10b, PIT16k_MAX, L_FRAME16k, L_SUBFR ); + move16(); } ELSE IF( EQ_16( nBits, 6 ) ) { /* T0_frac with 1/2 sample resolution */ *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, 0, 0, PIT16k_MIN, L_SUBFR, L_FRAME16k, L_SUBFR ); + move16(); IF( *T0 > L_SUBFR ) { *T0 = L_SUBFR; @@ -1820,6 +1875,7 @@ static void tc_enc_fx( #else *gain_pit_fx = corr_xy1_fx( xn_fx, yy1_fx, g_corr_fx, L_SUBFR, 0 ); #endif + move16(); /*--------------------------------------------------------------* * Encode parameters and write indices *--------------------------------------------------------------*/ @@ -1911,6 +1967,7 @@ static void tc_enc_ivas_fx( BSTR_ENC_HANDLE hBstr = st_fx->hBstr; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif imp_pos = sub( *position, i_subfr ); FOR( i = 0; i < L_SUBFR; i++ ) @@ -1923,6 +1980,7 @@ static void tc_enc_ivas_fx( *-----------------------------------------------------------------*/ nBits = st_fx->acelp_cfg.pitch_bits[shr( i_subfr, 6 )]; + move16(); /*--------------------------------------------------------------* * Closed loop pitch search @@ -1939,14 +1997,17 @@ static void tc_enc_ivas_fx( IF( EQ_16( nBits, 9 ) ) { *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, 0, 0, PIT_FR2_9b, PIT_FR1_9b, L_FRAME, L_SUBFR ); + move16(); } ELSE IF( EQ_16( nBits, 6 ) ) { *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, 0, 0, PIT_MIN, L_SUBFR, L_FRAME, L_SUBFR ); + move16(); } ELSE { *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, 0, 0, PIT_MAX, PIT_MIN, L_FRAME, L_SUBFR ); + move16(); } } ELSE @@ -1966,6 +2027,7 @@ static void tc_enc_ivas_fx( IF( EQ_16( nBits, 10 ) ) { *T0 = pitch_fr4_fx( &exc_fx[i_subfr], xn_fx, h1_fx, *T0_min, *T0_max, T0_frac, 0, 1, PIT16k_FR2_EXTEND_10b, PIT16k_MAX, L_FRAME16k, L_SUBFR ); + move16(); } ELSE IF( EQ_16( nBits, 6 ) ) { @@ -2036,6 +2098,7 @@ static void tc_enc_ivas_fx( #else *gain_pit_fx = corr_xy1_fx( xn_fx, yy1_fx, g_corr_fx, L_SUBFR, 0 ); #endif + move16(); /*--------------------------------------------------------------* * Encode parameters and write indices *--------------------------------------------------------------*/ @@ -2121,6 +2184,7 @@ static void gain_trans_enc_fx( Word16 i, imax, istart, tmp16, gain_trans, gscale; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif istart = 0; @@ -2179,6 +2243,7 @@ static void gain_trans_enc_fx( #else exc[i] = round_fx( L_shl( L_mult( exc[i], gain_trans ), tmp16 ) ); #endif + move16(); } } @@ -2202,6 +2267,7 @@ void tc_classif_enc_fx( Word16 T_op, i; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif T_op = pitch; @@ -2258,6 +2324,7 @@ void tc_classif_enc_fx( ELSE { *position = emaximum_fx( Q_new, res, add( T_op, 2 ), &temp ); + move16(); /* correction in case of possibly wrong T_op (double-pitch values) */ test(); @@ -2266,6 +2333,9 @@ void tc_classif_enc_fx( IF( ( EQ_16( L_frame, L_FRAME ) && GT_16( T_op, 2 * PIT_MIN ) ) || ( EQ_16( L_frame, L_FRAME16k ) && GT_16( T_op, 2 * PIT16k_MIN ) ) ) { Word16 position_tmp, len, exp_aver = 0, exp = 0, exp2 = 0; + move16(); + move16(); + move16(); Word32 aver, temp2, L_sum, L_temp1, L_temp2; len = add( shr( T_op, 1 ), 2 ); @@ -2283,7 +2353,8 @@ void tc_classif_enc_fx( L_sum = L_mac0( L_sum, res[i], res[i] ); #endif /* BASOP_NOGLOB */ } - aver = L_sum; /*Q = 2*Q_new */ + aver = L_sum; /*Q = 2*Q_new */ + move32(); aver = root_a_over_b_fx( aver, 2 * Q_new, L_shl( len, 15 ), 15, &exp_aver ); /*Q = 31-exp_aver*/ temp = root_a_fx( temp, 0, &exp ); /* Q=31-exp */ @@ -2302,6 +2373,7 @@ void tc_classif_enc_fx( #endif { *position = position_tmp; + move16(); } } *tc_subfr = s_and( *position, 0x7FC0 ); diff --git a/lib_enc/update_decision_fx.c b/lib_enc/update_decision_fx.c index 7fda8e5d2..315adcf81 100644 --- a/lib_enc/update_decision_fx.c +++ b/lib_enc/update_decision_fx.c @@ -253,7 +253,7 @@ Word16 update_decision_fx( hVAD_CLDFB->tonality_rate3 = mult( hVAD_CLDFB->tonality_rate3, 32211 ); move16(); - if ( tonality_flag ) + IF( tonality_flag ) { hVAD_CLDFB->tonality_rate3 = add( mult( hVAD_CLDFB->tonality_rate3, 32211 ), 557 ); move16(); @@ -274,8 +274,7 @@ Word16 update_decision_fx( test(); test(); - IF( ( GT_16( f_tonality_rate[1], 7536 /* 0.46 Q14 */ ) ) && ( ( GT_16( sSFM[1], 30473 /* 0.93 Q15 */ ) ) || ( GT_16( ltd_stable_rate[0], 2949 /* 0.09 Q15 */ ) ) ) ) - + if ( ( GT_16( f_tonality_rate[1], 7536 /* 0.46 Q14 */ ) ) && ( ( GT_16( sSFM[1], 30473 /* 0.93 Q15 */ ) ) || ( GT_16( ltd_stable_rate[0], 2949 /* 0.09 Q15 */ ) ) ) ) { update_flag = 0; move16(); @@ -284,7 +283,7 @@ Word16 update_decision_fx( test(); test(); test(); - IF( ( LT_16( sSFM[1], 30473 /* 0.93 Q15 */ ) && LT_16( sSFM[0], 30146 /* 0.92 Q15 */ ) && LT_16( sSFM[2], 31784 /* 0.97 Q15 */ ) ) && ( GT_16( f_tonality_rate[1], 8192 /* 0.5 Q14 */ ) ) ) + if ( ( LT_16( sSFM[1], 30473 /* 0.93 Q15 */ ) && LT_16( sSFM[0], 30146 /* 0.92 Q15 */ ) && LT_16( sSFM[2], 31784 /* 0.97 Q15 */ ) ) && ( GT_16( f_tonality_rate[1], 8192 /* 0.5 Q14 */ ) ) ) { update_flag = 0; move16(); @@ -292,7 +291,7 @@ Word16 update_decision_fx( test(); test(); - IF( ( f_tonality_rate[1] > 7045 /* 0.43 Q14 */ ) && ( sSFM[0] < 31129 /* 0.95 Q15 */ ) && ( sp_center[1] > 1985 /* 1.94 Q10 */ ) ) + if ( ( f_tonality_rate[1] > 7045 /* 0.43 Q14 */ ) && ( sSFM[0] < 31129 /* 0.95 Q15 */ ) && ( sp_center[1] > 1985 /* 1.94 Q10 */ ) ) { update_flag = 0; move16(); @@ -300,9 +299,10 @@ Word16 update_decision_fx( IF( EQ_16( update_flag, 1 ) ) { - if ( LT_16( hVAD_CLDFB->update_count, 1000 ) ) + IF( LT_16( hVAD_CLDFB->update_count, 1000 ) ) { hVAD_CLDFB->update_count = add( hVAD_CLDFB->update_count, 1 ); + move16(); } } @@ -342,23 +342,26 @@ Word16 update_decision_fx( test(); test(); test(); - IF( vad_flag && GT_32( snr, 33554431 /* 1.0 Q25 */ ) && EQ_16( bw, CLDFBVAD_SWB_ID ) && tmpout > 0 ) + if ( vad_flag && GT_32( snr, 33554431 /* 1.0 Q25 */ ) && EQ_16( bw, CLDFBVAD_SWB_ID ) && tmpout > 0 ) { update_flag = 0; + move16(); } test(); test(); test(); - IF( vad_flag && GT_32( snr, 50331647 /* 1.5 Q25 */ ) && NE_16( bw, CLDFBVAD_SWB_ID ) && tmpout > 0 ) + if ( vad_flag && GT_32( snr, 50331647 /* 1.5 Q25 */ ) && NE_16( bw, CLDFBVAD_SWB_ID ) && tmpout > 0 ) { update_flag = 0; + move16(); } IF( update_flag == 0 ) { hVAD_CLDFB->update_num_with_snr = 0; + move16(); } ELSE { @@ -369,6 +372,7 @@ Word16 update_decision_fx( update_flag = 0; move16(); hVAD_CLDFB->update_num_with_snr = add( hVAD_CLDFB->update_num_with_snr, 1 ); + move16(); } } @@ -397,8 +401,6 @@ Word16 update_decision_fx( move32(); } - move16(); - move16(); IF( GT_16( (Word16) abs_s( sub( hVAD_CLDFB->sp_center[0], hVAD_CLDFB->lt_noise_sp_center0 ) ), 2455 /* 2.4 Q10 */ ) ) { hVAD_CLDFB->lt_noise_sp_center0 = add( mult( hVAD_CLDFB->lt_noise_sp_center0, 32637 ), mult( hVAD_CLDFB->sp_center[0], 131 ) ); diff --git a/lib_enc/updt_enc_fx.c b/lib_enc/updt_enc_fx.c index bb35fa6a0..77d7f538f 100644 --- a/lib_enc/updt_enc_fx.c +++ b/lib_enc/updt_enc_fx.c @@ -38,6 +38,7 @@ void updt_enc_fx( /* update old excitation buffer */ Copy( &old_exc[st->L_frame], hLPDmem->old_exc, L_EXC_MEM ); test(); + test(); IF( !st->Opt_AMR_WB && st->hBWE_TD != NULL ) { Copy( &old_bwe_exc[L_FRAME32k], hBWE_TD->old_bwe_exc_fx, PIT16k_MAX * 2 ); @@ -90,6 +91,7 @@ void updt_enc_fx( move16(); /* tends to speech */ /*st->mid_dyn_fx = 40.0f * 0.5f + st->mid_dyn * 0.5f;*/ hGSCEnc->mid_dyn_fx = add( 20 * 128, mult_r( hGSCEnc->mid_dyn_fx, 16384 ) ); /*Q7*/ + move16(); } /* convert old LSP vector from 12kHz domain to 16kHz domain (needed in case of ACELP@12k8 <-> ACELP@16kHz switching) */ @@ -97,6 +99,7 @@ void updt_enc_fx( { Copy( st->lsp_old_fx, st->lsp_old16k_fx, M ); st->rate_switching_reset_16kHz = lsp_convert_poly_fx( st->lsp_old16k_fx, L_FRAME16k, st->Opt_AMR_WB ); + move16(); } /* update buffer of old subframe pitch values */ @@ -140,6 +143,7 @@ void updt_enc_fx( /* core switching updates */ Copy( &Aq[( st->L_frame / L_SUBFR - 1 ) * ( M + 1 )], st->old_Aq_12_8_fx, M + 1 ); st->old_Es_pred_fx = Es_pred; + move16(); return; } @@ -168,6 +172,7 @@ void updt_IO_switch_enc_fx( { /* reset onset detection counter */ st->tc_cnt = -1; + move16(); /* force safety-net LSFQ in the first frames after the switching */ st->Nb_ACELP_frames = 0; @@ -187,6 +192,7 @@ void updt_IO_switch_enc_fx( { /* old index is initialized to -1, and may only be updated after it has been calculated properly at least once once */ hTdCngEnc->old_enr_index = s_min( mult( shl( hTdCngEnc->old_enr_index, 1 ), 32459 ), 127 ); /*32459 = 2/(STEP_SID/STEP_AMR_WB_SID)*/ + move16(); } /* Perform preemphasis of the old input signal @16kHz */ st->mem_preemph16k_fx = 0; @@ -368,7 +374,7 @@ void updt_enc_common_fx( move16(); test(); - if ( GT_32( st->core_brate, SID_2k40 ) && st->hDtxEnc != NULL ) + IF( GT_32( st->core_brate, SID_2k40 ) && st->hDtxEnc != NULL ) { st->hDtxEnc->last_active_brate = st->total_brate; move32(); @@ -378,7 +384,7 @@ void updt_enc_common_fx( { st->hBWE_TD->prev_coder_type = st->coder_type; move16(); - if ( EQ_16( st->core, HQ_CORE ) ) + IF( EQ_16( st->core, HQ_CORE ) ) { /* in the HQ core, coder_type is not used so it could have been set to anything */ st->hBWE_TD->prev_coder_type = GENERIC; @@ -393,17 +399,19 @@ void updt_enc_common_fx( { IF( EQ_16( st->hDtxEnc->first_CNG, 1 ) ) { - if ( GE_16( st->hTdCngEnc->act_cnt, BUF_DEC_RATE ) ) + IF( GE_16( st->hTdCngEnc->act_cnt, BUF_DEC_RATE ) ) { st->hTdCngEnc->act_cnt = 0; move16(); } st->hTdCngEnc->act_cnt = add( st->hTdCngEnc->act_cnt, 1 ); + move16(); test(); - if ( EQ_16( st->hTdCngEnc->act_cnt, BUF_DEC_RATE ) && st->hTdCngEnc->ho_hist_size > 0 ) + IF( EQ_16( st->hTdCngEnc->act_cnt, BUF_DEC_RATE ) && st->hTdCngEnc->ho_hist_size > 0 ) { st->hTdCngEnc->ho_hist_size = sub( st->hTdCngEnc->ho_hist_size, 1 ); + move16(); } } @@ -414,6 +422,8 @@ void updt_enc_common_fx( { st->hTdCngEnc->act_cnt2 = add( st->hTdCngEnc->act_cnt2, 1 ); st->hTdCngEnc->act_cnt2 = s_min( st->hTdCngEnc->act_cnt2, MIN_ACT_CNG_UPD ); + move16(); + move16(); #ifdef IVAS_CODE test(); @@ -433,7 +443,7 @@ void updt_enc_common_fx( test(); test(); test(); - if ( ( EQ_32( st->core_brate, SID_2k40 ) || EQ_32( st->core_brate, FRAME_NO_DATA ) ) && st->hDtxEnc->first_CNG == 0 && EQ_16( st->cng_type, LP_CNG ) ) + IF( ( EQ_32( st->core_brate, SID_2k40 ) || EQ_32( st->core_brate, FRAME_NO_DATA ) ) && st->hDtxEnc->first_CNG == 0 && EQ_16( st->cng_type, LP_CNG ) ) { st->hDtxEnc->first_CNG = 1; move16(); @@ -448,6 +458,7 @@ void updt_enc_common_fx( if ( LT_16( st->ini_frame, MAX_FRAME_COUNTER ) ) { st->ini_frame = add( st->ini_frame, 1 ); + move16(); } /* synchronisation of CNG seeds */ @@ -470,6 +481,7 @@ void updt_enc_common_fx( move16(); st->sr_core = getCoreSamplerateMode2( EVS_MONO, st->total_brate, st->bwidth, st->flag_ACELP16k, st->rf_mode, 0 ); + move32(); // st->L_frame = extract_l(Mult_32_16(st->sr_core, 0x0290)); /*(int16_t)(st->sr_core / FRAMES_PER_SEC);*/ @@ -493,10 +505,11 @@ void updt_enc_common_fx( } st->igf = getIgfPresent_fx( EVS_MONO, st->total_brate, st->bwidth, st->rf_mode ); + move16(); } /* update FER clas */ - if ( NE_16( st->core, AMR_WB_CORE ) ) + IF( NE_16( st->core, AMR_WB_CORE ) ) { st->last_clas = st->clas; move16(); @@ -515,7 +528,7 @@ void updt_enc_common_fx( { st->hSC_VBR->last_nelp_mode = 0; move16(); - if ( EQ_16( st->hRF->rf_frame_type, RF_NELP ) ) + IF( EQ_16( st->hRF->rf_frame_type, RF_NELP ) ) { st->hSC_VBR->last_nelp_mode = 1; move16(); @@ -539,7 +552,7 @@ void updt_enc_common_fx( *---------------------------------------------------------------------*/ #ifdef IVAS_CODE test(); - if ( GT_16( st->element_mode, EVS_MONO ) && st->hTcxEnc != NULL ) + IF( GT_16( st->element_mode, EVS_MONO ) && st->hTcxEnc != NULL ) { st->hTcxEnc->tcxltp_norm_corr_mem = st->hTcxEnc->tcxltp_norm_corr_past; move16(); diff --git a/lib_enc/updt_tar_fx.c b/lib_enc/updt_tar_fx.c index d62daff20..4659acacf 100644 --- a/lib_enc/updt_tar_fx.c +++ b/lib_enc/updt_tar_fx.c @@ -14,10 +14,10 @@ * Update the target vector for codebook search. *----------------------------------------------------------------------------------*/ void updt_tar_fx( - const Word16 *x, /* i : old target (for pitch search) */ - Word16 *x2, /* o : new target (for codebook search) */ - const Word16 *y, /* i : filtered adaptive codebook vector */ - const Word16 gain, /* i : adaptive codebook gain */ + const Word16 *x, /* i : old target (for pitch search) Qz */ + Word16 *x2, /* o : new target (for codebook search) Qz */ + const Word16 *y, /* i : filtered adaptive codebook vector Qz */ + const Word16 gain, /* i : adaptive codebook gain Q14 */ const Word16 L /* i : subframe size */ ) { @@ -25,19 +25,22 @@ void updt_tar_fx( Word32 L_tmp; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif FOR( i = 0; i < L; i++ ) { /*x2[i] = x[i] - gain*y[i];*/ - L_tmp = L_mult( x[i], 16384 ); + L_tmp = L_mult( x[i], 16384 ); /* (Qz*Q14) -> (Qz+15) */ #ifdef BASOP_NOGLOB L_tmp = L_msu_sat( L_tmp, y[i], gain ); x2[i] = extract_h( L_shl_o( L_tmp, 1, &Overflow ) ); + move16(); #else /* BASOP_NOGLOB */ L_tmp = L_msu( L_tmp, y[i], gain ); x2[i] = extract_h( L_shl( L_tmp, 1 ) ); + move16(); #endif } return; @@ -48,9 +51,9 @@ void updt_tar_fx( * Update the target vector for codebook search. *----------------------------------------------------------------------------------*/ void updt_tar_HR_fx( - const Word16 *x, /* i : old target (for pitch search) */ - Word16 *x2, /* o : new target (for codebook search) */ - const Word16 *y, /* i : filtered adaptive codebook vector */ + const Word16 *x, /* i : old target (for pitch search) Qz */ + Word16 *x2, /* o : new target (for codebook search) Qz */ + const Word16 *y, /* i : filtered adaptive codebook vector Qz */ const Word16 gain, /* i : adaptive codebook gain Q2 */ const Word16 Qx, /* i : Scaling factor to adapt output to input */ const Word16 L /* i : subframe size */ @@ -60,20 +63,22 @@ void updt_tar_HR_fx( Word32 L_tmp, L_tmp1; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif FOR( i = 0; i < L; i++ ) { /*x2[i] = x[i] - gain*y[i];*/ - L_tmp = L_mult( x[i], 32767 ); + L_tmp = L_mult( x[i], 32767 ); /* (Qz*Q15) = (Qz+16) */ #ifdef BASOP_NOGLOB - L_tmp1 = L_shl_o( L_mult_o( y[i], gain, &Overflow ), Qx, &Overflow ); + L_tmp1 = L_shl_o( L_mult_o( y[i], gain, &Overflow ), Qx, &Overflow ); /* ((Qz+2+1)< start with hangover) */ hVAD->vad_flag_reg_H = L_deposit_l( 0 ); + move32(); hVAD->vad_flag_reg_L = L_deposit_l( 0 ); + move32(); hVAD->vad_prim_reg = L_deposit_l( 0 ); + move32(); hVAD->vad_flag_cnt_50 = 0; move16(); hVAD->vad_prim_cnt_16 = 0; @@ -221,19 +224,22 @@ static void sign_thr_snr_acc_fx( Word32 L_tmp; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif L_tmp = L_deposit_l( min_snr ); - if ( GE_32( L_snr, L_deposit_l( sign_thr ) ) ) + IF( GE_32( L_snr, L_deposit_l( sign_thr ) ) ) { - L_tmp = L_add( L_snr, 0 ); + L_tmp = L_add( L_snr, 0 ); /* Q4 */ } BASOP_SATURATE_WARNING_OFF_EVS /* may saturate in BASOP */ #ifdef BASOP_NOGLOB *L_snr_sum = L_add_o( *L_snr_sum, L_tmp, &Overflow ); /* Q4 */ -#else /* BASOP_NOGLOB */ - *L_snr_sum = L_add( *L_snr_sum, L_tmp ); /* Q4 */ -#endif /* BASOP_NOGLOB */ + move32(); +#else /* BASOP_NOGLOB */ + *L_snr_sum = L_add( *L_snr_sum, L_tmp ); /* Q4 */ + move32(); +#endif /* BASOP_NOGLOB */ BASOP_SATURATE_WARNING_ON_EVS } @@ -252,9 +258,9 @@ Word16 dtx_hangover_addition_fx( NOISE_EST_HANDLE hNoiseEst /* i : Noise estimation handle */ ) { - Word16 hangover_short_dtx; - Word16 flag_dtx; - Word16 tmp; + Word16 hangover_short_dtx; /* Q0 */ + Word16 flag_dtx; /* Q0 */ + Word16 tmp; /* Q0 */ if ( hNoiseEst == NULL ) { hNoiseEst = st_fx->hNoiseEst; @@ -277,19 +283,19 @@ Word16 dtx_hangover_addition_fx( test(); test(); - if ( ( ( LT_16( lp_snr, ( 16 * 256 ) ) ) && ( NE_16( st_fx->input_bwidth, NB ) ) ) || ( GT_16( hVAD->prim_act_he_fx, 31130 ) ) ) /*.95*Q15*/ + if ( ( ( LT_16( lp_snr, ( 16 * 256 ) ) ) && ( st_fx->input_bwidth != NB ) ) || ( GT_16( hVAD->prim_act_he_fx, 31130 ) ) ) /*.95*Q15*/ { hangover_short_dtx = 3; move16(); } /* Adjust hangover according to activity history */ - if ( GT_16( hVAD->vad_prim_cnt_16, 12 ) ) /* 12 requires roughly > 80% primary activity */ + IF( GT_16( hVAD->vad_prim_cnt_16, 12 ) ) /* 12 requires roughly > 80% primary activity */ { hangover_short_dtx = add( hangover_short_dtx, 2 ); } - if ( GT_16( hVAD->vad_flag_cnt_50, 40 ) ) /* 40 requires roughtly > 80% flag activity */ + IF( GT_16( hVAD->vad_flag_cnt_50, 40 ) ) /* 40 requires roughtly > 80% flag activity */ { hangover_short_dtx = add( hangover_short_dtx, 5 ); } @@ -339,7 +345,7 @@ Word16 dtx_hangover_addition_fx( /* hangover adjustment from combined FFT+CLDFBVAD */ IF( NE_16( st_fx->core, AMR_WB_CORE ) ) { - hangover_short_dtx = sub( hangover_short_dtx, cldfb_subtraction ); + hangover_short_dtx = sub( hangover_short_dtx, cldfb_subtraction ); /* Q0 */ hangover_short_dtx = s_max( hangover_short_dtx, 0 ); } @@ -358,9 +364,10 @@ Word16 dtx_hangover_addition_fx( /* inside HO period */ test(); - if ( ( LT_16( hVAD->hangover_cnt_dtx, HANGOVER_LONG_FX ) ) && ( hVAD->hangover_cnt_dtx != 0 ) ) + IF( ( LT_16( hVAD->hangover_cnt_dtx, HANGOVER_LONG_FX ) ) && ( hVAD->hangover_cnt_dtx != 0 ) ) { - hVAD->hangover_cnt_dtx = add( hVAD->hangover_cnt_dtx, 1 ); + hVAD->hangover_cnt_dtx = add( hVAD->hangover_cnt_dtx, 1 ); /* Q0 */ + move16(); } hVAD->hangover_terminate_flag = 0; move16(); /* float fix FIX_HO_TERMINATE */ @@ -377,21 +384,24 @@ Word16 dtx_hangover_addition_fx( /* inside Music HO period */ test(); - if ( ( LT_16( hVAD->hangover_cnt_music, HANGOVER_LONG_MUSIC_FX ) ) && ( hVAD->hangover_cnt_music != 0 ) ) + IF( ( LT_16( hVAD->hangover_cnt_music, HANGOVER_LONG_MUSIC_FX ) ) && ( hVAD->hangover_cnt_music != 0 ) ) { hVAD->hangover_cnt_music = add( hVAD->hangover_cnt_music, 1 ); + move16(); } } ELSE { /* Reset the counter of speech frames necessary to start hangover algorithm */ - if ( LT_16( hVAD->hangover_cnt_dtx, HANGOVER_LONG_FX ) ) /* inside HO period */ + IF( LT_16( hVAD->hangover_cnt_dtx, HANGOVER_LONG_FX ) ) /* inside HO period */ { hVAD->hangover_cnt_dtx = add( hVAD->hangover_cnt_dtx, 1 ); + move16(); } - if ( LT_16( hVAD->hangover_cnt_music, HANGOVER_LONG_MUSIC_FX ) ) /* inside HO period */ + IF( LT_16( hVAD->hangover_cnt_music, HANGOVER_LONG_MUSIC_FX ) ) /* inside HO period */ { hVAD->hangover_cnt_music = add( hVAD->hangover_cnt_music, 1 ); + move16(); } /* fast terminate DTX hangover if st->hangover_terminate_flag is set */ @@ -444,9 +454,9 @@ Word16 ivas_dtx_hangover_addition_fx( NOISE_EST_HANDLE hNoiseEst, /* i : Noise estimation handle */ Word16 *rem_dtx_ho ) { - Word16 hangover_short_dtx; - Word16 flag_dtx; - Word16 tmp; + Word16 hangover_short_dtx; /* Q0 */ + Word16 flag_dtx; /* Q0 */ + Word16 tmp; /* Q0 */ if ( hNoiseEst == NULL ) { hNoiseEst = st_fx->hNoiseEst; @@ -476,12 +486,12 @@ Word16 ivas_dtx_hangover_addition_fx( } /* Adjust hangover according to activity history */ - if ( GT_16( hVAD->vad_prim_cnt_16, 12 ) ) /* 12 requires roughly > 80% primary activity */ + IF( GT_16( hVAD->vad_prim_cnt_16, 12 ) ) /* 12 requires roughly > 80% primary activity */ { hangover_short_dtx = add( hangover_short_dtx, 2 ); } - if ( GT_16( hVAD->vad_flag_cnt_50, 40 ) ) /* 40 requires roughtly > 80% flag activity */ + IF( GT_16( hVAD->vad_flag_cnt_50, 40 ) ) /* 40 requires roughtly > 80% flag activity */ { hangover_short_dtx = add( hangover_short_dtx, 5 ); } @@ -506,7 +516,7 @@ Word16 ivas_dtx_hangover_addition_fx( /* need to be a bit stricter with the DTXHO in very clean WB, SWB cond for EVS12k8VAD section */ test(); test(); - if ( ( NE_16( st_fx->input_bwidth, NB ) ) /* WB or SWB or FB */ + if ( ( st_fx->input_bwidth != NB ) /* WB or SWB or FB */ && ( NE_16( st_fx->core, AMR_WB_CORE ) ) && ( GT_16( lp_snr, 25 * 256 ) ) ) { tmp = 2; @@ -531,7 +541,7 @@ Word16 ivas_dtx_hangover_addition_fx( /* hangover adjustment from combined FFT+CLDFBVAD */ IF( NE_16( st_fx->core, AMR_WB_CORE ) ) { - hangover_short_dtx = sub( hangover_short_dtx, cldfb_subtraction ); + hangover_short_dtx = sub( hangover_short_dtx, cldfb_subtraction ); /*Q0*/ hangover_short_dtx = s_max( hangover_short_dtx, 0 ); } IF( vad_flag != 0 ) /* Speech present */ @@ -549,9 +559,10 @@ Word16 ivas_dtx_hangover_addition_fx( /* inside HO period */ test(); - if ( ( LT_16( hVAD->hangover_cnt_dtx, HANGOVER_LONG_FX ) ) && ( hVAD->hangover_cnt_dtx != 0 ) ) + IF( ( LT_16( hVAD->hangover_cnt_dtx, HANGOVER_LONG_FX ) ) && ( hVAD->hangover_cnt_dtx != 0 ) ) { - hVAD->hangover_cnt_dtx = add( hVAD->hangover_cnt_dtx, 1 ); + hVAD->hangover_cnt_dtx = add( hVAD->hangover_cnt_dtx, 1 ); /*Q0*/ + move16(); } hVAD->hangover_terminate_flag = 0; move16(); /* float fix FIX_HO_TERMINATE */ @@ -568,7 +579,7 @@ Word16 ivas_dtx_hangover_addition_fx( /* inside Music HO period */ test(); - if ( ( LT_16( hVAD->hangover_cnt_music, HANGOVER_LONG_MUSIC_FX ) ) && ( hVAD->hangover_cnt_music != 0 ) ) + IF( ( LT_16( hVAD->hangover_cnt_music, HANGOVER_LONG_MUSIC_FX ) ) && ( hVAD->hangover_cnt_music != 0 ) ) { hVAD->hangover_cnt_music = add( hVAD->hangover_cnt_music, 1 ); move16(); @@ -577,12 +588,12 @@ Word16 ivas_dtx_hangover_addition_fx( ELSE { /* Reset the counter of speech frames necessary to start hangover algorithm */ - if ( LT_16( hVAD->hangover_cnt_dtx, HANGOVER_LONG_FX ) ) /* inside HO period */ + IF( LT_16( hVAD->hangover_cnt_dtx, HANGOVER_LONG_FX ) ) /* inside HO period */ { hVAD->hangover_cnt_dtx = add( hVAD->hangover_cnt_dtx, 1 ); move16(); } - if ( LT_16( hVAD->hangover_cnt_music, HANGOVER_LONG_MUSIC_FX ) ) /* inside HO period */ + IF( LT_16( hVAD->hangover_cnt_music, HANGOVER_LONG_MUSIC_FX ) ) /* inside HO period */ { hVAD->hangover_cnt_music = add( hVAD->hangover_cnt_music, 1 ); move16(); @@ -652,8 +663,8 @@ Word16 wb_vad_fx( const Word16 Q_new, /* i : scaling factor Q0 */ VAD_HANDLE hVAD, /* i/o: VAD data handle */ NOISE_EST_HANDLE hNoiseEst, /* i : Noise estimation handle */ - Word16 lp_speech_fx, /* i : long term active speech energy average */ - Word16 lp_noise_fx /* i : long term noise energy */ + Word16 lp_speech_fx, /* i : long term active speech energy average Q8 */ + Word16 lp_noise_fx /* i : long term noise energy Q8 */ ) { Word16 i, flag = 0, hangover_short; @@ -705,6 +716,7 @@ Word16 wb_vad_fx( Word16 last_7k2_coder_type; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif if ( hNoiseEst == NULL ) @@ -738,14 +750,12 @@ Word16 wb_vad_fx( move16(); L_accum_ener_L = L_deposit_l( 0 ); L_accum_ener_H = L_deposit_l( 0 ); - L_snr18 = L_deposit_l( 0 ); /* Q4*/ L_snr19 = L_deposit_l( 0 ); /* Q4 */ L_msnr18 = L_deposit_l( 8192 ); /* 1.0 Q13*/ L_msnr19 = L_deposit_l( 8192 ); /* 1.0 Q13 */ - - IF( EQ_16( vad_bwidth_fx, NB ) ) + IF( vad_bwidth_fx == NB ) { st_fx->min_band = 1; move16(); @@ -978,13 +988,11 @@ Word16 wb_vad_fx( { e_num = norm_l( L_tmp1 ); m_num = extract_h( L_shl( L_tmp1, e_num ) ); - e_noise = norm_l( ftmp2 ); m_noise_local = extract_h( L_shl( ftmp2, e_noise ) ); m_num = shr( m_num, 1 ); shift_snr = add( sub( e_num, e_noise ), 15 - 4 ); - snr_tmp = div_s( m_num, m_noise_local ); #ifdef BASOP_NOGLOB L_snr = L_shr_o( snr_tmp, shift_snr, &Overflow ); /* L_snr in Q4 */ @@ -1100,7 +1108,7 @@ Word16 wb_vad_fx( tmp1 = tmp; move16(); /* ftmp1 = ftmp; */ sub( 0, 0 ); - if ( i < 7 ) + if ( LT_16( i, 7 ) ) { #ifdef BASOP_NOGLOB tmp1 = add_o( tmp, 3277, &Overflow ); /*.4 in Q13 ftmp1 = ftmp + 0.4f; */ @@ -1230,7 +1238,7 @@ Word16 wb_vad_fx( L_tmp = L_add( L_tmp1, L_tmp ); if ( GT_32( L_tmp, L_mssnr ) ) { - L_mssnr = L_tmp; + L_mssnr = L_tmp; /*Q13*/ } } ELSE IF( ( snr_idx != 0 ) && GT_16( nb_sig_snr, 13 ) ) @@ -1302,9 +1310,11 @@ Word16 wb_vad_fx( /*st_fx->snr_sum_vad_fx = 0.5f * st->snr_sum_vad + 0.5f * snr_sum_ol;*/ #ifdef BASOP_NOGLOB hVAD->L_snr_sum_vad_fx = L_shr( L_add_o( hVAD->L_snr_sum_vad_fx, L_snr_sum_ol, &Overflow ), 1 ); /*Q4*/ -#else /* BASOP_NOGLOB */ + move32(); +#else /* BASOP_NOGLOB */ hVAD->L_snr_sum_vad_fx = L_shr( L_add( hVAD->L_snr_sum_vad_fx, L_snr_sum_ol ), 1 ); /*Q4*/ -#endif /* BASOP_NOGLOB */ + move32(); +#endif /* BASOP_NOGLOB */ /* snr_sum_ol = 10.0f * (float)log10( snr_sum_ol ); */ snr_sum_ol = vad_snr_log_fx( L_snr_sum_ol, LG10 ); @@ -1341,7 +1351,7 @@ Word16 wb_vad_fx( L_tmp = L_mac( L_tmp, nc, (Word16) 32767 ); /* Q8+Q15+1 = Q24 */ thr1 = mac_r( L_tmp, lp_snr, nk ); /* Q8+Q15+1 - 16 --> Q8 */ #ifdef IVAS_CODE - if ( st->element_mode > EVS_MONO && hNoiseEst->first_noise_updt_cnt < 100 ) + IF( st->element_mode > EVS_MONO && LT_16( hNoiseEst->first_noise_updt_cnt, 100 ) ) { /* lower threshold during warmup time */ thr1 -= 10.0f; @@ -1351,7 +1361,7 @@ Word16 wb_vad_fx( IF( GT_16( lp_snr, (Word16) 20 * ( 1 << 8 ) ) ) /* if (lp_snr > 20.0f )*/ { #ifdef IVAS_CODE - if ( st->element_mode == EVS_MONO || hNoiseEst->first_noise_updt_cnt >= 100 ) + IF( st->element_mode == EVS_MONO || GT_16( hNoiseEst->first_noise_updt_cnt, 100 ) ) #endif { /* thr1 = thr1 + 0.3f * (lp_snr - 20.0f); */ @@ -1363,6 +1373,7 @@ Word16 wb_vad_fx( if ( EQ_16( st_fx->max_band, 16 ) && GT_16( lp_snr, 40 * 256 ) && GT_16( thr1, 6600 ) && LT_16( lp_speech_fx, 11520 ) ) { thr1 = 6600; + move16(); } } } @@ -1401,7 +1412,7 @@ Word16 wb_vad_fx( test(); test(); /*_DIFF_FLOAT_FIX_ -> the conditions around Opt_SC_VBR_fx are invertered compared to float ### st_fx->Opt_SC_VBR!=0 vs !st_fx->Opt_SC_VBR #####*/ - test(); + // test(); IF( LE_16( snr_outlier_index, 4 ) && ( ( GT_16( st_fx->last_coder_type, UNVOICED ) && ( st_fx->Opt_SC_VBR != 0 ) ) || ( GT_16( last_7k2_coder_type, UNVOICED ) && ( st_fx->Opt_SC_VBR == 0 ) ) ) ) @@ -1431,7 +1442,7 @@ Word16 wb_vad_fx( #else /* BASOP_NOGLOB */ tmp2 = round_fx( L_shl( L_tmp2, 14 ) ); /* Q10(high word)+ 14 -16 --> Q8*/ #endif - if ( L_tmp2 > 0 ) + IF( L_tmp2 > 0 ) { thr1_ol = add( thr1_ol, tmp2 ); /* Q24 >>16 + Q8 */ } @@ -1453,7 +1464,7 @@ Word16 wb_vad_fx( flag_he1 = 1; move16(); /* he1 primary decision */ hVAD->nb_active_frames_he1 = add( hVAD->nb_active_frames_he1, 1 ); /* Counter of consecutive active speech frames */ - + move16(); IF( GE_16( hVAD->nb_active_frames_he1, ACTIVE_FRAMES_FX ) ) { hVAD->nb_active_frames_he1 = ACTIVE_FRAMES_FX; @@ -1464,14 +1475,16 @@ Word16 wb_vad_fx( /* inside HO period */ test(); - if ( sub( hVAD->hangover_cnt_he1, HANGOVER_LONG_HE_FX ) < 0 && hVAD->hangover_cnt_he1 != 0 ) + IF( sub( hVAD->hangover_cnt_he1, HANGOVER_LONG_HE_FX ) < 0 && hVAD->hangover_cnt_he1 != 0 ) { hVAD->hangover_cnt_he1 = add( hVAD->hangover_cnt_he1, 1 ); + move16(); } - if ( hVAD->soft_hangover > 0 ) + IF( hVAD->soft_hangover > 0 ) { hVAD->soft_hangover = sub( hVAD->soft_hangover, 1 ); + move16(); } } ELSE @@ -1503,7 +1516,7 @@ Word16 wb_vad_fx( IF( LT_16( hVAD->bcg_flux_fx, 640 ) ) { hangover_hd = add( shr( hangover_hd, 1 ), 1 ); - move16(); + // move16(); } /* VAD hangover for he1 */ @@ -1515,6 +1528,7 @@ Word16 wb_vad_fx( flag_he1 = 1; move16(); hVAD->soft_hangover = sub( hVAD->soft_hangover, 1 ); + move16(); } ELSE { @@ -1536,6 +1550,7 @@ Word16 wb_vad_fx( flag_he1 = 1; move16(); hVAD->hangover_cnt_he1 = add( hVAD->hangover_cnt_he1, 1 ); + move16(); } @@ -1551,11 +1566,13 @@ Word16 wb_vad_fx( { /*st->bcg_flux = 0.9f * st->bcg_flux + (1-0.9f)*(st->bcg_flux+50);*/ hVAD->bcg_flux_fx = mac_r( L_mult( hVAD->bcg_flux_fx, 29491 ), add( hVAD->bcg_flux_fx, 800 ), 3277 ); /*Q4 */ + move16(); } ELSE { /*st->bcg_flux = 0.9f * st->bcg_flux + (1-0.9f)*snr_sumt*/ hVAD->bcg_flux_fx = mac_r( L_mult( hVAD->bcg_flux_fx, 29491 ), snr_sumt, 3277 ); /*Q4 */ + move16(); } } ELSE @@ -1564,11 +1581,13 @@ Word16 wb_vad_fx( { /*st->bcg_flux = 0.99f * st->bcg_flux + (1-0.99f)*(st->bcg_flux+10);*/ hVAD->bcg_flux_fx = mac_r( L_mult( hVAD->bcg_flux_fx, 32440 ), add( hVAD->bcg_flux_fx, 160 ), 328 ); /*Q4 */ + move16(); } ELSE { /*st->bcg_flux = 0.99f * st->bcg_flux + (1-0.99f)*snr_sumt;*/ hVAD->bcg_flux_fx = mac_r( L_mult( hVAD->bcg_flux_fx, 32440 ), snr_sumt, 328 ); /*Q4 */ + move16(); } } } @@ -1580,11 +1599,13 @@ Word16 wb_vad_fx( { /*st->bcg_flux = 0.95f * st->bcg_flux + (1-0.95f)*(st->bcg_flux-30);*/ hVAD->bcg_flux_fx = mac_r( L_mult( hVAD->bcg_flux_fx, 31130 ), sub( hVAD->bcg_flux_fx, 480 ), 1638 ); /*Q4 */ + move16(); } ELSE { /*st->bcg_flux = 0.95f * st->bcg_flux + (1-0.95f)*snr_sumt;*/ hVAD->bcg_flux_fx = mac_r( L_mult( hVAD->bcg_flux_fx, 31130 ), snr_sumt, 1638 ); /*Q4 */ + move16(); } } ELSE @@ -1593,16 +1614,19 @@ Word16 wb_vad_fx( { /*st->bcg_flux = 0.9992f * st->bcg_flux + (1-0.9992f)*(st->bcg_flux-10);*/ hVAD->bcg_flux_fx = mac_r( L_mult( hVAD->bcg_flux_fx, 32742 ), sub( hVAD->bcg_flux_fx, 160 ), 26 ); /*Q4 */ + move16(); } ELSE { /*st->bcg_flux = 0.9992f * st->bcg_flux + (1-0.9992f)*snr_sumt;*/ hVAD->bcg_flux_fx = mac_r( L_mult( hVAD->bcg_flux_fx, 32742 ), snr_sumt, 26 ); /*Q4 */ + move16(); } } } - hVAD->bcg_flux_init = s_max( hVAD->bcg_flux_init, 0 ); + hVAD->bcg_flux_init = s_max( hVAD->bcg_flux_init, 0 ); /*Q0*/ + move16(); } flag = 0; @@ -1620,6 +1644,7 @@ Word16 wb_vad_fx( move16(); hVAD->nb_active_frames = add( hVAD->nb_active_frames, 1 ); /* Counter of consecutive active speech frames */ + move16(); IF( GE_16( hVAD->nb_active_frames, ACTIVE_FRAMES_FX ) ) { @@ -1631,9 +1656,10 @@ Word16 wb_vad_fx( /* inside HO period */ test(); - if ( LT_16( hVAD->hangover_cnt, HANGOVER_LONG_FX ) && hVAD->hangover_cnt != 0 ) + IF( LT_16( hVAD->hangover_cnt, HANGOVER_LONG_FX ) && hVAD->hangover_cnt != 0 ) { hVAD->hangover_cnt = add( hVAD->hangover_cnt, 1 ); + move16(); } } ELSE @@ -1642,9 +1668,10 @@ Word16 wb_vad_fx( hVAD->nb_active_frames = 0; move16(); - if ( LT_16( hVAD->hangover_cnt, HANGOVER_LONG_FX ) ) /* inside HO period */ + IF( LT_16( hVAD->hangover_cnt, HANGOVER_LONG_FX ) ) /* inside HO period */ { hVAD->hangover_cnt = add( hVAD->hangover_cnt, 1 ); + move16(); } @@ -1652,14 +1679,16 @@ Word16 wb_vad_fx( { test(); test(); - if ( EQ_16( st_fx->element_mode, EVS_MONO ) && ( LT_16( lp_snr, th_clean ) ) && ( st_fx->Opt_SC_VBR != 0 ) && ( GE_16( hVAD->hangover_cnt, 2 ) ) ) + test(); + if ( st_fx->element_mode == EVS_MONO && ( LT_16( lp_snr, th_clean ) ) && ( st_fx->Opt_SC_VBR != 0 ) && ( GE_16( hVAD->hangover_cnt, 2 ) ) ) { *noisy_speech_HO = 1; move16(); } test(); test(); - if ( EQ_16( st_fx->element_mode, EVS_MONO ) && ( GE_16( lp_snr, th_clean ) ) && ( st_fx->Opt_SC_VBR != 0 ) && ( GE_16( hVAD->hangover_cnt, 2 ) ) ) + test(); + if ( st_fx->element_mode == EVS_MONO && ( GE_16( lp_snr, th_clean ) ) && ( st_fx->Opt_SC_VBR != 0 ) && ( GE_16( hVAD->hangover_cnt, 2 ) ) ) { *clean_speech_HO = 1; move16(); @@ -1706,6 +1735,7 @@ Word16 wb_vad_fx( IF( GT_16( snr_sum, thr1 ) ) /* Speech present, possibly in hangover */ { hVAD->nb_active_frames = add( hVAD->nb_active_frames, 1 ); /* Counter of consecutive active speech frames */ + move16(); IF( GE_16( hVAD->nb_active_frames, ACTIVE_FRAMES_FX ) ) { hVAD->nb_active_frames = ACTIVE_FRAMES_FX; @@ -1729,7 +1759,7 @@ Word16 wb_vad_fx( IF( LT_16( hVAD->hangover_cnt, HANGOVER_LONG_NB_FX ) ) { hVAD->hangover_cnt = add( hVAD->hangover_cnt, 1 ); - + move16(); IF( LT_16( lp_snr, 4864 ) ) /*19.0f Q8*/ /* very low SNR */ { @@ -1752,7 +1782,7 @@ Word16 wb_vad_fx( tmp = 282; move16(); /* 1.10f; */ } - if ( LT_16( lp_snr, th_clean ) ) + IF( LT_16( lp_snr, th_clean ) ) { thr2 = sub( thr1_nb_mod, tmp ); /*thr2 = thr1 - [ 1.10 || 1.3 ];*/ } @@ -1760,7 +1790,7 @@ Word16 wb_vad_fx( flag = 0; move16(); - IF( GT_16( snr_sum, thr1_nb_mod ) ) /* Speech assumed present, even though lowered thr1 */ + if ( GT_16( snr_sum, thr1_nb_mod ) ) /* Speech assumed present, even though lowered thr1 */ { flag = 1; move16(); @@ -1778,8 +1808,8 @@ Word16 wb_vad_fx( if ( EQ_16( st_fx->element_mode, EVS_MONO ) ) { *NB_speech_HO = 1; + move16(); } - move16(); } thr1 = thr1_nb_mod; move16(); /* needed for st_fx->vadnoise_fx update below */ @@ -1806,7 +1836,7 @@ Word16 wb_vad_fx( } } - if ( st_fx->hSC_VBR != NULL ) + IF( st_fx->hSC_VBR != NULL ) { /* SC-VBR */ st_fx->hSC_VBR->vadsnr_fx = snr_sum; @@ -1817,20 +1847,23 @@ Word16 wb_vad_fx( /* Updates */ hVAD->prim_act_quick_fx = mult_r( 26214, hVAD->prim_act_quick_fx ); /*Q15 */ - - if ( st_fx->localVAD != 0 ) + move16(); + IF( st_fx->localVAD != 0 ) { hVAD->prim_act_quick_fx = add( 6554, hVAD->prim_act_quick_fx ); /*Q15 */ + move16(); } hVAD->prim_act_slow_fx = mult_r( 32440, hVAD->prim_act_slow_fx ); /*Q15 */ + move16(); - if ( st_fx->localVAD != 0 ) + IF( st_fx->localVAD != 0 ) { hVAD->prim_act_slow_fx = add( 328, hVAD->prim_act_slow_fx ); /*Q15 */ + move16(); } - tmp = hVAD->prim_act_slow_fx; + tmp = hVAD->prim_act_slow_fx; /*Q15*/ move16(); if ( LE_16( hVAD->prim_act_quick_fx, hVAD->prim_act_slow_fx ) ) { @@ -1838,19 +1871,23 @@ Word16 wb_vad_fx( move16(); } /*st->prim_act = 0.1f * tmp + (1.0f-0.1f)* st->prim_act;*/ - hVAD->prim_act_fx = mac_r( L_mult( 3277, tmp ), 29491, hVAD->prim_act_fx ); - + hVAD->prim_act_fx = mac_r( L_mult( 3277, tmp ), 29491, hVAD->prim_act_fx ); /*Q15 */ + move16(); hVAD->prim_act_quick_he_fx = mult_r( 26214, hVAD->prim_act_quick_he_fx ); /*Q15 */ - if ( *localVAD_HE_SAD != 0 ) + move16(); + IF( *localVAD_HE_SAD != 0 ) { hVAD->prim_act_quick_he_fx = add( 6554, hVAD->prim_act_quick_he_fx ); /*Q15 */ + move16(); } hVAD->prim_act_slow_he_fx = mult_r( 32440, hVAD->prim_act_slow_he_fx ); /*Q15 */ - if ( *localVAD_HE_SAD != 0 ) + move16(); + IF( *localVAD_HE_SAD != 0 ) { hVAD->prim_act_slow_he_fx = add( 328, hVAD->prim_act_slow_he_fx ); /*Q15 */ + move16(); } tmp = hVAD->prim_act_slow_he_fx; @@ -1861,42 +1898,49 @@ Word16 wb_vad_fx( move16(); } hVAD->prim_act_he_fx = mac_r( L_mult( 3277, tmp ), 29491, hVAD->prim_act_he_fx ); + move16(); - - if ( L_and( hVAD->vad_flag_reg_H, (Word32) 0x40000L ) != 0 ) /* 0x4000L = 0x01L << 18 */ + IF( L_and( hVAD->vad_flag_reg_H, (Word32) 0x40000L ) != 0 ) /* 0x4000L = 0x01L << 18 */ { hVAD->vad_flag_cnt_50 = sub( hVAD->vad_flag_cnt_50, 1 ); + move16(); } hVAD->vad_flag_reg_H = L_shl( L_and( hVAD->vad_flag_reg_H, (Word32) 0x3fffffffL ), 1 ); + move32(); - - if ( L_and( hVAD->vad_flag_reg_L, (Word32) 0x40000000L ) != 0 ) + IF( L_and( hVAD->vad_flag_reg_L, (Word32) 0x40000000L ) != 0 ) { hVAD->vad_flag_reg_H = L_or( hVAD->vad_flag_reg_H, 0x01L ); + move32(); } hVAD->vad_flag_reg_L = L_shl( L_and( hVAD->vad_flag_reg_L, (Word32) 0x3fffffffL ), 1 ); - + move32(); IF( flag != 0 ) /* should not include the extra DTX hangover */ { hVAD->vad_flag_reg_L = L_or( hVAD->vad_flag_reg_L, 0x01L ); + move32(); hVAD->vad_flag_cnt_50 = add( hVAD->vad_flag_cnt_50, 1 ); + move16(); } - if ( L_and( hVAD->vad_prim_reg, (Word32) 0x8000L ) != 0 ) /* 0x8000L = 1L << 15 */ + IF( L_and( hVAD->vad_prim_reg, (Word32) 0x8000L ) != 0 ) /* 0x8000L = 1L << 15 */ { hVAD->vad_prim_cnt_16 = sub( hVAD->vad_prim_cnt_16, 1 ); + move16(); } hVAD->vad_prim_reg = L_shl( L_and( hVAD->vad_prim_reg, (Word32) 0x3fffffffL ), 1 ); - + move32(); IF( st_fx->localVAD != 0 ) { hVAD->vad_prim_reg = L_or( hVAD->vad_prim_reg, 0x01L ); + move32(); hVAD->vad_prim_cnt_16 = add( hVAD->vad_prim_cnt_16, 1 ); + move16(); } return flag; @@ -1904,7 +1948,7 @@ Word16 wb_vad_fx( Word16 wb_vad_ivas_fx( Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word32 fr_bands[], /* i : per band i energy (contains 2 vectors) q_fr_bands*/ + const Word32 fr_bands[], /* i : per band i energy (contains 2 vectors) Qx + QSCALE */ const Word16 q_fr_bands, /* i : Q of fr_bands */ Word16 *noisy_speech_HO, /* o : SC-VBR noisy speech HO flag */ Word16 *clean_speech_HO, /* o : SC-VBR clean speech HO flag */ @@ -1914,12 +1958,11 @@ Word16 wb_vad_ivas_fx( Word16 *flag_noisy_speech_snr, /* o : */ VAD_HANDLE hVAD, /* i/o: VAD data handle */ NOISE_EST_HANDLE hNoiseEst, /* i : Noise estimation handle */ - Word16 lp_speech_fx, /* i : long term active speech energy average */ - Word16 lp_noise_fx /* i : long term noise energy */ + Word16 lp_speech_fx, /* i : long term active speech energy average Q8 */ + Word16 lp_noise_fx /* i : long term noise energy Q8 */ ) { Word16 i, flag = 0, hangover_short; - Word16 snr_sum, thr1 = 0, thr1_nb_mod, thr2 = 0, nk = 0, nc = 0, th_clean = 0; Word16 lp_snr; /* Q8 */ const Word32 *pt1; @@ -1967,6 +2010,7 @@ Word16 wb_vad_ivas_fx( Word16 last_7k2_coder_type; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif Word16 L_msnr_e = 0, L_mssnr_e = 0, L_mssnr_hov_e = 0, L_msnr18_e = 0, L_msnr19_e = 0; move16(); /*L_msnr_e*/ @@ -1974,7 +2018,6 @@ Word16 wb_vad_ivas_fx( move16(); /*L_mssnr_hov_e*/ move16(); /*L_msnr18_e*/ move16(); /*L_msnr19_e*/ - move16(); /*Overflow*/ move32(); /*L_mssnr*/ move16(); /*thr1*/ move16(); /*thr2*/ @@ -1994,13 +2037,13 @@ Word16 wb_vad_ivas_fx( } if ( LT_16( lp_speech_fx, -100 * 256 ) ) { - lp_speech_fx = st_fx->lp_speech_fx; + lp_speech_fx = st_fx->lp_speech_fx; /*Q8*/ move16(); } if ( LT_16( lp_noise_fx, -100 * 256 ) ) { - lp_noise_fx = st_fx->lp_noise_fx; + lp_noise_fx = st_fx->lp_noise_fx; /*Q8*/ move16(); } @@ -2083,7 +2126,7 @@ Word16 wb_vad_ivas_fx( } ELSE /* NB input */ { - move16(); + // move16(); nk = 3277; move16(); /* 0.1 Q15 */ nc = 4096; @@ -2536,9 +2579,10 @@ Word16 wb_vad_ivas_fx( /*st_fx->snr_sum_vad_fx = 0.5f * st->snr_sum_vad + 0.5f * snr_sum_ol;*/ #ifdef BASOP_NOGLOB hVAD->L_snr_sum_vad_fx = L_shr( L_add_o( hVAD->L_snr_sum_vad_fx, L_snr_sum_ol, &Overflow ), 1 ); /*Q4*/ -#else /* BASOP_NOGLOB */ + move32(); +#else /* BASOP_NOGLOB */ hVAD->L_snr_sum_vad_fx = L_shr( L_add( hVAD->L_snr_sum_vad_fx, L_snr_sum_ol ), 1 ); /*Q4*/ -#endif /* BASOP_NOGLOB */ +#endif /* BASOP_NOGLOB */ /* snr_sum_ol = 10.0f * (float)log10( snr_sum_ol ); */ snr_sum_ol = vad_snr_log_fx( L_snr_sum_ol, LG10 ); @@ -2575,7 +2619,7 @@ Word16 wb_vad_ivas_fx( thr1 = mac_r( L_tmp, lp_snr, nk ); /* Q8+Q15+1 - 16 --> Q8 */ test(); - IF( st_fx->element_mode > EVS_MONO && hNoiseEst->first_noise_updt_cnt < 100 ) + IF( st_fx->element_mode > EVS_MONO && LT_16( hNoiseEst->first_noise_updt_cnt, 100 ) ) { /* lower threshold during warmup time */ thr1 = sub( thr1, 2560 ); @@ -2609,7 +2653,7 @@ Word16 wb_vad_ivas_fx( * Hangover control & final VAD decision *---------------------------------------------------------------------*/ - IF( NE_16( vad_bwidth_fx, NB ) ) + IF( vad_bwidth_fx != NB ) { /* Outlier Detection first calculates thr1_ol and snr_sum_ol instead of @@ -3074,7 +3118,7 @@ Word16 wb_vad_ivas_fx( hVAD->prim_act_quick_fx = mult_r( 26214, hVAD->prim_act_quick_fx ); /*Q15 */ move16(); - if ( st_fx->localVAD != 0 ) + IF( st_fx->localVAD != 0 ) { hVAD->prim_act_quick_fx = add( 6554, hVAD->prim_act_quick_fx ); /*Q15 */ move16(); @@ -3083,13 +3127,13 @@ Word16 wb_vad_ivas_fx( hVAD->prim_act_slow_fx = mult_r( 32440, hVAD->prim_act_slow_fx ); /*Q15 */ move16(); - if ( st_fx->localVAD != 0 ) + IF( st_fx->localVAD != 0 ) { hVAD->prim_act_slow_fx = add( 328, hVAD->prim_act_slow_fx ); /*Q15 */ move16(); } - tmp = hVAD->prim_act_slow_fx; + tmp = hVAD->prim_act_slow_fx; /*Q15*/ move16(); if ( LE_16( hVAD->prim_act_quick_fx, hVAD->prim_act_slow_fx ) ) { @@ -3102,7 +3146,7 @@ Word16 wb_vad_ivas_fx( hVAD->prim_act_quick_he_fx = mult_r( 26214, hVAD->prim_act_quick_he_fx ); /*Q15 */ move16(); - if ( *localVAD_HE_SAD != 0 ) + IF( *localVAD_HE_SAD != 0 ) { hVAD->prim_act_quick_he_fx = add( 6554, hVAD->prim_act_quick_he_fx ); /*Q15 */ move16(); @@ -3110,7 +3154,7 @@ Word16 wb_vad_ivas_fx( hVAD->prim_act_slow_he_fx = mult_r( 32440, hVAD->prim_act_slow_he_fx ); /*Q15 */ move16(); - if ( *localVAD_HE_SAD != 0 ) + IF( *localVAD_HE_SAD != 0 ) { hVAD->prim_act_slow_he_fx = add( 328, hVAD->prim_act_slow_he_fx ); /*Q15 */ move16(); @@ -3126,7 +3170,7 @@ Word16 wb_vad_ivas_fx( hVAD->prim_act_he_fx = mac_r( L_mult( 3277, tmp ), 29491, hVAD->prim_act_he_fx ); move16(); - if ( L_and( hVAD->vad_flag_reg_H, (Word32) 0x40000L ) != 0 ) /* 0x4000L = 0x01L << 18 */ + IF( L_and( hVAD->vad_flag_reg_H, (Word32) 0x40000L ) != 0 ) /* 0x4000L = 0x01L << 18 */ { hVAD->vad_flag_cnt_50 = sub( hVAD->vad_flag_cnt_50, 1 ); move16(); @@ -3135,7 +3179,7 @@ Word16 wb_vad_ivas_fx( hVAD->vad_flag_reg_H = L_shl( L_and( hVAD->vad_flag_reg_H, (Word32) 0x3fffffffL ), 1 ); move32(); - if ( L_and( hVAD->vad_flag_reg_L, (Word32) 0x40000000L ) != 0 ) + IF( L_and( hVAD->vad_flag_reg_L, (Word32) 0x40000000L ) != 0 ) { hVAD->vad_flag_reg_H = L_or( hVAD->vad_flag_reg_H, 0x01L ); move32(); @@ -3153,9 +3197,9 @@ Word16 wb_vad_ivas_fx( } - if ( L_and( hVAD->vad_prim_reg, (Word32) 0x8000L ) != 0 ) /* 0x8000L = 1L << 15 */ + IF( L_and( hVAD->vad_prim_reg, (Word32) 0x8000L ) != 0 ) /* 0x8000L = 1L << 15 */ { - hVAD->vad_prim_cnt_16 = sub( hVAD->vad_prim_cnt_16, 1 ); + hVAD->vad_prim_cnt_16 = sub( hVAD->vad_prim_cnt_16, 1 ); /*Q0*/ move16(); } @@ -3164,9 +3208,9 @@ Word16 wb_vad_ivas_fx( IF( st_fx->localVAD != 0 ) { - hVAD->vad_prim_reg = L_or( hVAD->vad_prim_reg, 0x01L ); + hVAD->vad_prim_reg = L_or( hVAD->vad_prim_reg, 0x01L ); /*Q0*/ move32(); - hVAD->vad_prim_cnt_16 = add( hVAD->vad_prim_cnt_16, 1 ); + hVAD->vad_prim_cnt_16 = add( hVAD->vad_prim_cnt_16, 1 ); /*Q0*/ move16(); } diff --git a/lib_enc/vad_param_updt_fx.c b/lib_enc/vad_param_updt_fx.c index e0b607c5a..092919bff 100644 --- a/lib_enc/vad_param_updt_fx.c +++ b/lib_enc/vad_param_updt_fx.c @@ -17,10 +17,10 @@ *--------------------------------------------------------------------*/ void vad_param_updt_fx( - Encoder_State *st_fx, /* i/o: state structure */ - const Word16 old_pitch1, /* i : OL pitch value from last frame */ - const Word16 corr_shift, /* i : correlation shift Q15*/ - const Word16 corr_shiftR, /* i : correlation shift */ + Encoder_State *st_fx, /* i/o: state structure */ + const Word16 old_pitch1, /* i : OL pitch value from last frame Q0 */ + const Word16 corr_shift, /* i : correlation shift Q15*/ + const Word16 corr_shiftR, /* i : correlation shift Q15 */ const Word16 Az[], /* i: a coeffs Q12 */ FRONT_VAD_ENC_HANDLE hFrontVad[], /* i/o: front-VAD handles */ const Word16 n_channels /* i : number of channels */ @@ -36,31 +36,29 @@ void vad_param_updt_fx( DTX_ENC_HANDLE hDtxEnc = st_fx->hDtxEnc; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif - corr_shift_temp[0] = corr_shift; - corr_shift_temp[1] = corr_shiftR; + corr_shift_temp[0] = corr_shift; /*Q15*/ + corr_shift_temp[1] = corr_shiftR; /*Q15*/ move16(); move16(); hVAD = st_fx->hVAD; ini_frame = st_fx->ini_frame; move16(); - move16(); IF( hFrontVad != NULL ) { hVAD = hFrontVad[0]->hVAD; ini_frame = hFrontVad[0]->ini_frame; move16(); - move16(); } FOR( i = 0; i < n_channels; i++ ) { if ( EQ_16( i, 1 ) ) { hVAD = hFrontVad[1]->hVAD; - move16(); } IF( !st_fx->Opt_AMR_WB ) { @@ -85,7 +83,8 @@ void vad_param_updt_fx( { /* update the counter of consecutive inactive frames in DTX */ hVAD->consec_inactive = add( hVAD->consec_inactive, 1 ); - IF( GT_16( hVAD->consec_inactive, 5 ) ) + move16(); + if ( GT_16( hVAD->consec_inactive, 5 ) ) { hVAD->consec_inactive = 5; move16(); @@ -115,7 +114,7 @@ void vad_param_updt_fx( hVAD->ra_deltasum_fx = add( hVAD->ra_deltasum_fx, sub( tmp2, tmp1 ) ); move16(); - tmp1 = mult( 26214, hVAD->running_avg_fx ); + tmp1 = mult( 26214, hVAD->running_avg_fx ); /* (0.8 in Q15 * Q15) = Q(30 - 15)*/ hVAD->running_avg_fx = add( tmp1, tmp2 ); move16(); @@ -148,7 +147,7 @@ void vad_param_updt_fx( hDtxEnc->cnt_SID = 1; move16(); st_fx->core_brate = SID_2k40; - move16(); + move32(); hVAD->trigger_SID = 0; move16(); } diff --git a/lib_enc/vad_proc_fx.c b/lib_enc/vad_proc_fx.c index 2c12ec996..2c9273ff5 100644 --- a/lib_enc/vad_proc_fx.c +++ b/lib_enc/vad_proc_fx.c @@ -25,8 +25,8 @@ Word16 vad_init_fx( ) { Word16 i = 0; - - IF( hVAD_CLDFB == NULL ) + move16(); + if ( hVAD_CLDFB == NULL ) { return -1; } @@ -177,7 +177,7 @@ Word16 vad_init_fx( return 0; } -static void UpdateState( +static void UpdateState_fx( VAD_CLDFB_HANDLE hVAD_CLDFB, /* i/o: CLDFB VAD state */ Word16 vad_flag, /* i : VAD flag */ Word32 frame_energy, /* i : current frame energy */ @@ -205,7 +205,7 @@ static void UpdateState( hVAD_CLDFB->lt_bg_highf_eng = L_add( MUL_F( hVAD_CLDFB->lt_bg_highf_eng, 31130 ), L_shr( MUL_F( HB_Power, 1638 ), sub( HB_Power_Q, lt_bg_highf_eng_Q ) ) ); } - if ( LT_16( hVAD_CLDFB->frameloop, 1000 ) ) + IF( LT_16( hVAD_CLDFB->frameloop, 1000 ) ) { hVAD_CLDFB->frameloop = add( hVAD_CLDFB->frameloop, 1 ); move16(); @@ -242,7 +242,9 @@ static void UpdateState( move16(); hVAD_CLDFB->continuous_speech_num2 = add( hVAD_CLDFB->continuous_speech_num2, 1 ); + move16(); hVAD_CLDFB->continuous_speech_num = add( hVAD_CLDFB->continuous_speech_num, 1 ); + move16(); if ( GT_16( hVAD_CLDFB->continuous_speech_num, 2048 ) ) { hVAD_CLDFB->continuous_speech_num = 2048; @@ -357,7 +359,7 @@ Word16 vad_proc_fx( HB_Power_Q, snr, tsnr, hVAD_CLDFB->vad_flag_for_bk_update, music_backgound_f ); - UpdateState( hVAD_CLDFB, hVAD_CLDFB->vad_flag_for_bk_update, frame_energy2, frame_energy2_Q, update_flag, music_backgound_f, HB_Power, HB_Power_Q, snr ); + UpdateState_fx( hVAD_CLDFB, hVAD_CLDFB->vad_flag_for_bk_update, frame_energy2, frame_energy2_Q, update_flag, music_backgound_f, HB_Power, HB_Power_Q, snr ); return vad_flag; diff --git a/lib_enc/vbr_average_rate_fx.c b/lib_enc/vbr_average_rate_fx.c index 931333ebe..d99ddc7f2 100644 --- a/lib_enc/vbr_average_rate_fx.c +++ b/lib_enc/vbr_average_rate_fx.c @@ -41,7 +41,7 @@ /*=================================================================================*/ void update_average_rate_fx( SC_VBR_ENC_HANDLE hSC_VBR, /* i/o: SC-VBR state structure */ - const Word32 core_brate_fx /* i : core bitrate */ + const Word32 core_brate_fx /* i : core bitrate Q0 */ ) { Word32 avratetarg_fx; /* target rate for next RATEWIN active frames */ @@ -69,7 +69,7 @@ void update_average_rate_fx( /*st->global_avr_rate = (st->global_avr_rate * (st->global_frame_cnt-1) + st->sum_of_rates) / st->global_frame_cnt; */ exp = norm_s( hSC_VBR->global_frame_cnt ); - tmp = shl( hSC_VBR->global_frame_cnt, exp ); + tmp = shl( hSC_VBR->global_frame_cnt, exp ); /*Q0 + exp = exp*/ recip = div_s( 16384, tmp ); Qrecip = sub( 15, sub( exp, 14 ) ); @@ -218,11 +218,11 @@ void update_average_rate_fx( st->pattern_m=100 . Later this value is used in voiced.enc to bump up 10% of PPP frames to F frames. */ /* st->pattern_m = (short)(1000 * (avratetarg - 6.15f * RATEWIN * 10)/(10 * RATEWIN * 0.1f) ); */ - L_tmp = L_mult0( RATEWIN, VBR_ADR_MAX_TARGET_x10_Q1 ); - L_tmp = L_shl( L_tmp, 12 ); + L_tmp = RATEWIN * VBR_ADR_MAX_TARGET_x10_Q1; /* Q0 * Q1 = Q1 */ + L_tmp = L_shl( L_tmp, 12 ); /* Q1<<12 = Q13*/ L_tmp = L_sub( avratetarg_fx, L_tmp ); /*27307=(1000/(RATEWIN))Q14 */ - tmp = extract_h( L_shl( Mult_32_16( L_tmp, 27307 ), 4 ) ); + tmp = extract_h( L_shl( Mult_32_16( L_tmp, 27307 ), 4 ) ); /*(((Q13*Q0)<<4)>>16) = Q18>>16 = Q2*/ hSC_VBR->pattern_m = tmp; move16(); @@ -257,7 +257,7 @@ void update_average_rate_fx( move16(); /* sum the total number of bits (in kbytes) * 10 here */ /*st->sum_of_rates += (hSC_VBR->core_brate / 1000.0f) * 10; */ - L_tmp = L_shl( Mult_32_16( core_brate_fx, 20972 ), 7 ); + L_tmp = L_shl( Mult_32_16( core_brate_fx, 20972 ), 7 ); /*Q13*/ #ifdef BASOP_NOGLOB hSC_VBR->sum_of_rates_fx = L_add_o( hSC_VBR->sum_of_rates_fx, L_tmp, &Overflow ); #else diff --git a/lib_enc/vlpc_1st_cod_fx.c b/lib_enc/vlpc_1st_cod_fx.c index deddb5023..22d6c5a3c 100644 --- a/lib_enc/vlpc_1st_cod_fx.c +++ b/lib_enc/vlpc_1st_cod_fx.c @@ -14,12 +14,12 @@ #define ISF_ONE 3 /*1.0f*1.28f Q1*/ /*=1.0f in 14Q1*1.28*/ /*------------------------------------------------------------------* - * lsf_weight() + * lsf_weight_fx() * * outputs only the weightings, doesn't do anything with the lsfq *------------------------------------------------------------------*/ /*outputs only the weightings, doesn't do anything with the lsfq*/ -static void lsf_weight( +static void lsf_weight_fx( const Word16 *lsfq, /* i : quantized lsf coefficients (14Q1*1.28)*/ Word16 *w /* o : lsf weighting vector (0Q15) */ ) @@ -31,7 +31,7 @@ static void lsf_weight( /* weighting function */ /*use the second element as the base to avoid the following division by 0*/ /*this happens when the ac function is nearly flat*/ - i = lsfq[0]; + i = lsfq[0]; /* (14Q1*1.28)*/ move16(); if ( lsfq[0] == 0 ) { @@ -40,7 +40,7 @@ static void lsf_weight( } inv_di0 = 0x7fff; move16(); - if ( GT_16( i, ISF_ONE ) ) + IF( GT_16( i, ISF_ONE ) ) { inv_di0 = div_s( ISF_ONE, i ); /*0Q15*/ /*inv_di0 = 1.0f / lsfq[0];*/ } @@ -104,7 +104,7 @@ Word16 vlpc_1st_cod_fx( /* o : codebook index /* weighting */ - lsf_weight( lsf, w ); /*lsf:14Q1*1.28=>w:0Q15*/ + lsf_weight_fx( lsf, w ); /*lsf:14Q1*1.28=>w:0Q15*/ IF( EQ_16( rf_mode, 1 ) ) { Word16 s; diff --git a/lib_enc/vlpc_2st_cod_fx.c b/lib_enc/vlpc_2st_cod_fx.c index 6334684d2..bc7cb4b3e 100644 --- a/lib_enc/vlpc_2st_cod_fx.c +++ b/lib_enc/vlpc_2st_cod_fx.c @@ -18,9 +18,9 @@ *------------------------------------------------------------------*/ Word16 vlpc_2st_cod_fx( /* output: number of allocated bits */ - const Word16 *lsf, /* i : normalized vector to quantize */ - Word16 *lsfq, /* i/o: i:1st stage o:1st+2nd stage */ - Word16 *indx, /* o : index[] (4 bits per words) */ + const Word16 *lsf, /* i : normalized vector to quantize (14Q1*1.28) */ + Word16 *lsfq, /* i/o: i:1st stage o:1st+2nd stage (14Q1*1.28) */ + Word16 *indx, /* o : index[] (4 bits per words) Q0 */ const Word16 mode, /* i : 0=abs, >0=rel */ const Word32 sr_core /* i : internal sampling rate */ ) @@ -32,6 +32,7 @@ Word16 vlpc_2st_cod_fx( /* output: number of allocated bits Word16 gap; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif @@ -158,6 +159,7 @@ Word16 vlpc_2st_cod_fx( /* output: number of allocated bits { gap = 34; } + move16(); reorder_lsf_fx( lsfq, gap, M, INT_FS_FX ); diff --git a/lib_enc/voiced_enc_fx.c b/lib_enc/voiced_enc_fx.c index cf08ebe5a..4e644b3b0 100644 --- a/lib_enc/voiced_enc_fx.c +++ b/lib_enc/voiced_enc_fx.c @@ -74,15 +74,21 @@ ivas_error ppp_voiced_encoder_fx( { Word16 i; Word16 spike_near_edge = 0; + move16(); Word16 flag; Word16 delta_lag_E = 0, PPP_MODE_E, Q_delta_lag = 0; + move16(); /*delta_lag_E*/ + move16(); /*Q_delta_lag*/ Word16 out_of_bound = 0; + move16(); Word16 tmp, tmptmp, tmptmp1; Word16 pl, l; Word16 interp_delay[3], temp_pl, temp_l; Word16 upper_cut_off_freq_of_interest_fx = 0; + move16(); /*upper_cut_off_freq_of_interest_fx*/ Word16 upper_cut_off_freq_of_interest_norm_fx = 0, upper_cut_off_freq_norm_fx = 0; - + move16(); /*upper_cut_off_freq_of_interest_norm_fx*/ + move16(); /*upper_cut_off_freq_norm_fx*/ Word16 S_fx[PIT_MAX * 4 + 1], C_fx[PIT_MAX * 4 + 1]; Word16 Qtmpres; Word32 Ltemp, logLag, Ltemp_q; @@ -101,18 +107,24 @@ ivas_error ppp_voiced_encoder_fx( Word16 exp_ee, frac_ee; Word16 Qtmp; Word32 res_enratio_fx = 0; + move32(); Word16 mem_fx[10]; Word32 energy_impz_fx = 0, tmpres_fx; + move32(); /*energy_impz_fx*/ Word32 pos_nq0_fx, neg_nq0_fx, Ltmp; Word32 Ltmp_32, Ltmp1_32, Ltemp1, Ltemp2, Ltemp_fx; Word16 Qadj; Word32 tmp_fx = 0, sp_hb_enratio_fx = 0, sp_enratio_fx = 0; + move32(); /*tmp_fx*/ + move32(); /*sp_hb_enratio_fx*/ + move32(); /*sp_enratio_fx*/ Word32 low_band_en_fx; Word32 curr_Engy, prev_Engy; Word16 temp_Fs; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif DTFS_STRUCTURE *CURRP_NQ_FX; DTFS_STRUCTURE *TMPDTFS_FX; @@ -171,7 +183,7 @@ ivas_error ppp_voiced_encoder_fx( upper_cut_off_freq_norm_fx = 16384; move16(); /*value normalized by 12800 */ } - ELSE IF( EQ_16( bwidth_fx, NB ) ) + ELSE IF( bwidth_fx == NB ) { upper_cut_off_freq_of_interest_fx = 3300; move16(); @@ -219,19 +231,20 @@ ivas_error ppp_voiced_encoder_fx( if ( hSC_VBR->last_ppp_mode == 1 ) { hSC_VBR->rate_control = 0; + move16(); } PPP_MODE_E = 'Q'; move16(); pl = s_min( MAX_LAG_PIT, rint_new_fx( L_shl( old_pitch_buf[( 2 * NB_SUBFR ) - 1], 10 ) ) ); - move16(); l = s_min( MAX_LAG_PIT, rint_new_fx( L_deposit_h( delay_fx ) ) ); - move16(); /* old_pitch_buf in Q6*/ /* Bump up if the lag is out_fx of range */ test(); + test(); + test(); IF( GT_16( sub( l, pl ), 13 ) || LT_16( sub( l, pl ), -11 ) || LT_16( l, 19 ) || LT_16( pl, 19 ) ) { hSC_VBR->bump_up = 1; @@ -259,7 +272,7 @@ ivas_error ppp_voiced_encoder_fx( } /* Use the out_fx array as a temp storage for currp */ - spike_near_edge = ppp_extract_pitch_period_fx( in_fx, out_fx, l, &out_of_bound, Qres ); + spike_near_edge = ppp_extract_pitch_period_fx( in_fx, out_fx, l, &out_of_bound, Qres ); /*Q0*/ move16(); /* out_fx in Qres */ @@ -310,7 +323,7 @@ ivas_error ppp_voiced_encoder_fx( move16(); /* pitch_fx in Q6 */ } curr_Engy = DTFS_getEngy_P2A_fx( CURRP_NQ_FX ); /*2Q where Q=CURRP_NQ_FX->Q */ - + move32(); /* Restoring PPP memories when the last frame is non-PPP */ IF( NE_16( hSC_VBR->last_ppp_mode, 1 ) ) { @@ -325,7 +338,7 @@ ivas_error ppp_voiced_encoder_fx( prev_Engy = L_add( Lacc, 0 ); hSC_VBR->Q_prev_cw_en_fx = norm_l( Lacc ); /* = K = headroom */ - + move16(); /*hSC_VBR->Q_prev_cw_en_fx = (Lacc==0)?31: hSC_VBR->Q_prev_cw_en_fx; */ if ( Lacc == 0 ) { @@ -334,7 +347,9 @@ ivas_error ppp_voiced_encoder_fx( } hSC_VBR->prev_cw_en_fx = (Word32) L_shl( Lacc, hSC_VBR->Q_prev_cw_en_fx ); /*2Q+K */ + move32(); hSC_VBR->Q_prev_cw_en_fx = add( hSC_VBR->Q_prev_cw_en_fx, shl( dtfs_temp_fx->Q, 1 ) ); + move16(); /* hSC_VBR->Q_prev_cw_en_fx = 2*(dtfs_temp_fx->Q) + K */ DTFS_copy_fx( TMPDTFS_FX, *dtfs_temp_fx ); /* output = TMPDTFS_FX */ @@ -346,19 +361,21 @@ ivas_error ppp_voiced_encoder_fx( /* Process low band */ Ltemp = DTFS_setEngyHarm_fx( 236, 2828, 0, 2828, 1, 0, &Ql, TMPDTFS_FX ); /* Q of Ltemp = 2*(TMPDTFS_FX->Q) = Ql ? */ + move32(); /* Compensate for Q factor of energy to get log10(lag*eng) */ Ltemp = log10_fx( Ltemp ); /* Ltemp=10log10(eng), Q23 */ Ltemp = L_add( L_sub( Ltemp, Ltemp_q ), logLag ); /* Ltemp=10*log10(lag*eng), Q23 */ /*hSC_VBR->lastLgainE_fx=round_fx(L_shl((Word32)Mpy_32_16(extract_h(Ltemp),extract_l(Ltemp),0x6666),1)); // Q11, 0x6666 = 0.1 in Q18 */ hSC_VBR->lastLgainE_fx = round_fx( L_shl( Mult_32_16( Ltemp, 0x6666 ), 1 ) ); /* Q11, 0x6666 = 0.1 in Q18 */ - + move16(); /* Process high band */ Ltemp = DTFS_setEngyHarm_fx( 2828, upper_cut_off_freq_of_interest_norm_fx, 2828, upper_cut_off_freq_norm_fx, 1, 0, &Qh, TMPDTFS_FX ); + move32(); Ltemp = log10_fx( Ltemp ); Ltemp = L_add( L_sub( Ltemp, Ltemp_q ), logLag ); /* Ltemp=10*log10(lag*eng), Q23 */ hSC_VBR->lastHgainE_fx = round_fx( L_shl( Mult_32_16( Ltemp, 0x6666 ), 1 ) ); /* Q11 */ - + move16(); /* Need to unify the Q factors of both bands */ TMPDTFS_FX->Q = s_min( Ql, Qh ); move16(); /* set Q factor to be the smaller one of Ql and Qh */ @@ -380,11 +397,11 @@ ivas_error ppp_voiced_encoder_fx( { /* Copy DTFS related parameters from 'st_fx' to 'dtfs_temp' structure */ dtfs_temp_fx->lag_fx = hSC_VBR->dtfs_enc_lag; - move16(); + move16(); /*Q0*/ dtfs_temp_fx->nH_fx = hSC_VBR->dtfs_enc_nH; - move16(); + move16(); /*Q0*/ dtfs_temp_fx->nH_4kHz_fx = hSC_VBR->dtfs_enc_nH_4kHz; - move16(); + move16(); /*Q0*/ dtfs_temp_fx->upper_cut_off_freq_of_interest_fx = hSC_VBR->dtfs_enc_upper_cut_off_freq_of_interest_fx; move16(); dtfs_temp_fx->upper_cut_off_freq_fx = hSC_VBR->dtfs_enc_upper_cut_off_freq_fx; @@ -396,6 +413,7 @@ ivas_error ppp_voiced_encoder_fx( dtfs_temp_fx->Q = hSC_VBR->dtfs_enc_Q; move16(); Lacc1 = DTFS_getEngy_P2A_fx( dtfs_temp_fx ); + move32(); prev_Engy = L_add( Lacc1, 0 ); } @@ -457,14 +475,14 @@ ivas_error ppp_voiced_encoder_fx( DTFS_copy_fx( TMPDTFS2_FX, *dtfs_temp_fx ); /* output = TMPDTFS2_FX with Q = dtfs_temp_fx->Q */ tmptmp = DTFS_alignment_full_fx( *TMPDTFS2_FX, *TMPDTFS_FX, hSC_VBR->ph_offset_E_fx, S_fx, C_fx, 0 ); - + move16(); tmptmp1 = sub( shl( TMPDTFS_FX->lag_fx, 1 ), tmptmp ); /* (C_l-tmptmp) , Q1 */ Q2phaseShift_fx( TMPDTFS_FX, negate( shl( tmptmp1, 1 ) ), TMPDTFS_FX->lag_fx, S_fx, C_fx ); /* fixed bug , phase shift by tmp computed in_fx TMP.lag domain (above) */ /*tmpres = (float)(DTFS_freq_corr(*TMPDTFS, *TMPDTFS2, 100.0f, 3700.0f));*/ tmpres_fx = DTFS_freq_corr_fx( *TMPDTFS_FX, *TMPDTFS2_FX, 100, 3700, &Qtmpres ); /* tmpres_fx has Q factor tmpres */ - + move32(); poleFilter_setup_fx( lpc2_fx, M + 1, *TMPDTFS_FX, S_fx, C_fx, pf_temp1, pf_temp2, pf_temp, pf_n2 ); DTFS_poleFilter_fx_9( TMPDTFS_FX, pf_temp1, pf_temp2, pf_temp, pf_n2 ); @@ -475,6 +493,7 @@ ivas_error ppp_voiced_encoder_fx( DTFS_poleFilter_fx( TMPDTFS2_FX, lpc1_fx, M + 1, S_fx, C_fx ); /* lpc1_fx in Q12 */ tmp_fx = DTFS_freq_corr_fx( *TMPDTFS_FX, *TMPDTFS2_FX, 100, 3700, &Qtmp ); + move32(); /* tmp_fx Q = Qtmp */ @@ -489,11 +508,14 @@ ivas_error ppp_voiced_encoder_fx( } *******************************************************************************/ Ltmp_32 = ( DTFS_getEngy_fx( TMPDTFS2_FX ) ); /* Output Q=2*(TMPDTFS2_FX->Q) */ + move32(); IF( Ltmp_32 > 0 ) { /*sp_enratio = DTFS_getEngy(*TMPDTFS)/DTFS_getEngy(*TMPDTFS2); in Q15 */ Lacc = DTFS_getEngy_P2A_fx( TMPDTFS_FX ); + move32(); Lacc1 = Ltmp_32; + move32(); /* IF (L_sub(sp_enratio_fx,0x7FFF)!=0) */ { expb = norm_l( Lacc ); @@ -550,9 +572,9 @@ ivas_error ppp_voiced_encoder_fx( /* 5 in Q11, 0.65 in Q15 // L_shl(tmp_fx,sub(31,Qtmp)) makes tmp_fx FIXED Q31 */ test(); #ifdef BASOP_NOGLOB - IF( ( GT_32( res_enratio_fx, 10240 ) ) && ( LT_16( extract_h( L_shl_o( tmp_fx, sub( 31, Qtmp ), &Overflow ) ), 21299 ) ) ) + if ( ( GT_32( res_enratio_fx, 10240 ) ) && ( LT_16( extract_h( L_shl_o( tmp_fx, sub( 31, Qtmp ), &Overflow ) ), 21299 ) ) ) #else - IF( ( GT_32( res_enratio_fx, 10240 ) ) && ( LT_16( extract_h( L_shl( tmp_fx, sub( 31, Qtmp ) ) ), 21299 ) ) ) + if ( ( GT_32( res_enratio_fx, 10240 ) ) && ( LT_16( extract_h( L_shl( tmp_fx, sub( 31, Qtmp ) ) ), 21299 ) ) ) #endif { PPP_MODE_E = 'B'; @@ -565,9 +587,9 @@ ivas_error ppp_voiced_encoder_fx( /*3 in Q11, 1.2 in Q14 // L_shl(tmp_fx,sub(31,Qtmp)) makes tmp_fx FIXED Q14 */ test(); #ifdef BASOP_NOGLOB - IF( ( GT_32( res_enratio_fx, 6144 ) ) && ( LT_16( extract_h( L_shl_o( tmp_fx, sub( 30, Qtmp ), &Overflow ) ), 19661 ) ) ) + if ( ( GT_32( res_enratio_fx, 6144 ) ) && ( LT_16( extract_h( L_shl_o( tmp_fx, sub( 30, Qtmp ), &Overflow ) ), 19661 ) ) ) #else - IF( ( GT_32( res_enratio_fx, 6144 ) ) && ( LT_16( extract_h( L_shl( tmp_fx, sub( 30, Qtmp ) ) ), 19661 ) ) ) + if ( ( GT_32( res_enratio_fx, 6144 ) ) && ( LT_16( extract_h( L_shl( tmp_fx, sub( 30, Qtmp ) ) ), 19661 ) ) ) #endif { PPP_MODE_E = 'B'; @@ -659,7 +681,7 @@ ivas_error ppp_voiced_encoder_fx( } } - IF( hSC_VBR->bump_up == 1 ) + IF( EQ_16( hSC_VBR->bump_up, 1 ) ) { free( CURRP_NQ_FX ); free( TMPDTFS_FX ); @@ -692,7 +714,7 @@ ivas_error ppp_voiced_encoder_fx( move16(); IF( EQ_16( PPP_MODE_E, 'Q' ) ) { - if ( ( error = ppp_quarter_encoder_fx( &flag, CURRP_Q_E_FX, TMPDTFS_FX, dtfs_temp_fx->lag_fx, *CURRP_NQ_FX, lpc2_fx, &hSC_VBR->lastLgainE_fx, &hSC_VBR->lastHgainE_fx, hSC_VBR->lasterbE_fx, *dtfs_temp_fx, S_fx, C_fx, hBstr ) ) != IVAS_ERR_OK ) + IF( ( error = ppp_quarter_encoder_fx( &flag, CURRP_Q_E_FX, TMPDTFS_FX, dtfs_temp_fx->lag_fx, *CURRP_NQ_FX, lpc2_fx, &hSC_VBR->lastLgainE_fx, &hSC_VBR->lastHgainE_fx, hSC_VBR->lasterbE_fx, *dtfs_temp_fx, S_fx, C_fx, hBstr ) ) != IVAS_ERR_OK ) { free( CURRP_NQ_FX ); free( TMPDTFS_FX ); @@ -728,11 +750,13 @@ ivas_error ppp_voiced_encoder_fx( IF( GT_16( CURRP_Q_E_FX->upper_cut_off_freq_fx, 4000 ) ) { Ltemp2 = DTFS_getEngy_band_wb_fx( *CURRP_Q_E_FX, 0, 2000 ); + move32(); /* Use this bump-up only for WB signals */ IF( Ltemp2 > 0 ) { /* sp_hb_enratio = DTFS_getEngy_band_wb(*CURRP_Q_E, 2000.0, 6400.0)/DTFS_getEngy_band_wb(*CURRP_Q_E, 0.0, 2000.0); */ Ltemp1 = DTFS_getEngy_band_wb_fx( *CURRP_Q_E_FX, 2000, 6400 ); /*Q13 */ + move32(); /*sp_hb_enratio_fx = divide_dp(Ltemp1,Ltemp2,0, 1);//Q29 */ Qadj = 0; move16(); @@ -778,11 +802,11 @@ ivas_error ppp_voiced_encoder_fx( sp_hb_enratio_fx = L_deposit_l( 0 ); } low_band_en_fx = Ltemp2; /*Q13 */ - + move32(); /* if ( low_band_en < 25.0f && sp_hb_enratio < 1.6f ) */ /* 25.0 in Q13 = 204800, 1.6 in Q29 = 858993459 */ test(); - IF( LT_32( low_band_en_fx, 204800 ) && LT_32( sp_hb_enratio_fx, 858993459 ) ) + if ( LT_32( low_band_en_fx, 204800 ) && LT_32( sp_hb_enratio_fx, 858993459 ) ) { PPP_MODE_E = 'B'; move16(); @@ -790,6 +814,7 @@ ivas_error ppp_voiced_encoder_fx( } Ltmp_32 = DTFS_getEngy_fx( CURRP_NQ_FX ); /*Q = 2*(CURRP_NQ_FX->Q) */ + move32(); Qadj = sub( hSC_VBR->Q_prev_cw_en_fx, shl( CURRP_NQ_FX->Q, 1 ) ); #ifdef BASOP_NOGLOB @@ -814,7 +839,7 @@ ivas_error ppp_voiced_encoder_fx( { /*if ( pos_nq > neg_nq && pos_nq > 2.0f * pos_q ) */ test(); - IF( GT_32( pos_nq_fx, neg_nq_fx ) && GT_32( Mult_32_16( pos_nq_fx, 16384 ), pos_q_fx ) ) + if ( GT_32( pos_nq_fx, neg_nq_fx ) && GT_32( Mult_32_16( pos_nq_fx, 16384 ), pos_q_fx ) ) { PPP_MODE_E = 'B'; move16(); @@ -822,7 +847,7 @@ ivas_error ppp_voiced_encoder_fx( test(); /*if ( pos_nq < neg_nq && neg_nq > 2.0f * neg_q ) */ - IF( LT_32( pos_nq_fx, neg_nq_fx ) && GT_32( Mult_32_16( neg_nq_fx, 16384 ), neg_q_fx ) ) + if ( LT_32( pos_nq_fx, neg_nq_fx ) && GT_32( Mult_32_16( neg_nq_fx, 16384 ), neg_q_fx ) ) { PPP_MODE_E = 'B'; move16(); @@ -849,8 +874,8 @@ ivas_error ppp_voiced_encoder_fx( test(); test(); test(); - IF( ( GT_32( pos_nq_fx, neg_nq_fx ) && GT_32( Mult_32_16( pos_nq_fx, 13107 ), pos_q_fx ) && ( hSC_VBR->rate_control ) ) || - ( GT_32( pos_nq_fx, neg_nq_fx ) && GT_32( Mult_32_16( pos_nq_fx, 16384 ), pos_q_fx ) && ( !hSC_VBR->rate_control ) ) ) + if ( ( GT_32( pos_nq_fx, neg_nq_fx ) && GT_32( Mult_32_16( pos_nq_fx, 13107 ), pos_q_fx ) && ( hSC_VBR->rate_control ) ) || + ( GT_32( pos_nq_fx, neg_nq_fx ) && GT_32( Mult_32_16( pos_nq_fx, 16384 ), pos_q_fx ) && ( !hSC_VBR->rate_control ) ) ) { PPP_MODE_E = 'B'; move16(); @@ -863,8 +888,8 @@ ivas_error ppp_voiced_encoder_fx( test(); test(); test(); - IF( ( LT_32( pos_nq_fx, neg_nq_fx ) && GT_32( Mult_32_16( neg_nq_fx, 13107 ), neg_q_fx ) && ( hSC_VBR->rate_control ) ) || - ( LT_32( pos_nq_fx, neg_nq_fx ) && GT_32( Mult_32_16( neg_nq_fx, 16384 ), neg_q_fx ) && ( !hSC_VBR->rate_control ) ) ) + if ( ( LT_32( pos_nq_fx, neg_nq_fx ) && GT_32( Mult_32_16( neg_nq_fx, 13107 ), neg_q_fx ) && ( hSC_VBR->rate_control ) ) || + ( LT_32( pos_nq_fx, neg_nq_fx ) && GT_32( Mult_32_16( neg_nq_fx, 16384 ), neg_q_fx ) && ( !hSC_VBR->rate_control ) ) ) { PPP_MODE_E = 'B'; move16(); @@ -921,6 +946,7 @@ ivas_error ppp_voiced_encoder_fx( /* energy_impz_fx is Q11 */ Ltmp_32 = DTFS_getEngy_fx( CURRP_Q_E_FX ); /*Q = 2*(CURRP_Q_E_FX->Q) */ + move32(); Qadj = sub( hSC_VBR->Q_prev_cw_en_fx, shl( CURRP_Q_E_FX->Q, 1 ) ); #ifdef BASOP_NOGLOB Ltmp_32 = L_shl_o( Ltmp_32, Qadj, &Overflow ); /* shift left required to adjust Q of CURRP_Q_E_FX = Q_prev_cw_en_fx */ @@ -941,7 +967,7 @@ ivas_error ppp_voiced_encoder_fx( test(); test(); test(); - IF( ( GT_32( pos_q_fx, neg_q_fx ) ) && ( ( GT_32( Mult_32_16( pos_q_fx, 10923 ), L_shr( pos_nq0_fx, sub( Qposnq, 28 ) ) ) ) || ( ( GT_32( Mult_32_16( pos_q_fx, 21845 ), L_shr( pos_nq0_fx, sub( Qposnq, 28 ) ) ) ) && ( LT_32( Mult_32_16( neg_q_fx, 21846 ), L_shr( neg_nq0_fx, sub( Qnegnq, 28 ) ) ) ) ) ) ) + if ( ( GT_32( pos_q_fx, neg_q_fx ) ) && ( ( GT_32( Mult_32_16( pos_q_fx, 10923 ), L_shr( pos_nq0_fx, sub( Qposnq, 28 ) ) ) ) || ( ( GT_32( Mult_32_16( pos_q_fx, 21845 ), L_shr( pos_nq0_fx, sub( Qposnq, 28 ) ) ) ) && ( LT_32( Mult_32_16( neg_q_fx, 21846 ), L_shr( neg_nq0_fx, sub( Qnegnq, 28 ) ) ) ) ) ) ) /* 10923 = (1/3) oin Q15, pos_q_fx is Q28, so result of Mult_32_16(pos_q_fx,10923) = Q28 */ /* L_shr(pos_nq0_fx,sub(Qposnq,28)) brings pos_nq0_fx with variable Q to fixed Q28 */ { @@ -952,7 +978,7 @@ ivas_error ppp_voiced_encoder_fx( test(); test(); /* if ((pos_q <= neg_q) && ((neg_q>3.0*neg_nq0)|| ((neg_q > 1.5*neg_nq0) && (pos_q < 1.5*pos_nq0)))) */ - IF( ( LE_32( pos_q_fx, neg_q_fx ) ) && ( ( GT_32( Mult_32_16( neg_q_fx, 10923 ), L_shr( neg_nq0_fx, sub( Qnegnq, 28 ) ) ) ) || ( ( GT_32( Mult_32_16( neg_q_fx, 21846 ), L_shr( neg_nq0_fx, sub( Qnegnq, 28 ) ) ) ) && ( LT_32( Mult_32_16( pos_q_fx, 21846 ), L_shr( pos_nq0_fx, sub( Qposnq, 28 ) ) ) ) ) ) ) + if ( ( LE_32( pos_q_fx, neg_q_fx ) ) && ( ( GT_32( Mult_32_16( neg_q_fx, 10923 ), L_shr( neg_nq0_fx, sub( Qnegnq, 28 ) ) ) ) || ( ( GT_32( Mult_32_16( neg_q_fx, 21846 ), L_shr( neg_nq0_fx, sub( Qnegnq, 28 ) ) ) ) && ( LT_32( Mult_32_16( pos_q_fx, 21846 ), L_shr( pos_nq0_fx, sub( Qposnq, 28 ) ) ) ) ) ) ) { PPP_MODE_E = 'B'; move16(); @@ -971,11 +997,13 @@ ivas_error ppp_voiced_encoder_fx( /* operate in ADR mode only the rate control is active. This adds some bumpups to improve the speech quality */ /* if ((DTFS_getEngy_band(*TMPDTFS, 1500.0, upper_cut_off_freq_of_interest)/DTFS_getEngy(*TMPDTFS) > 0.05)&&(!st->rate_control)) */ Ltemp1 = DTFS_getEngy_band_fx( *TMPDTFS_FX, 1500, upper_cut_off_freq_of_interest_fx ); /* Q = 2*TMPDTFS_FX->Q*/ - Ltemp2 = DTFS_getEngy_fx( TMPDTFS_FX ); /* Q = 2*TMPDTFS_FX->Q */ - + move32(); + Ltemp2 = DTFS_getEngy_fx( TMPDTFS_FX ); /* Q = 2*TMPDTFS_FX->Q */ + move32(); IF( Ltemp2 == 0 ) { Ltemp_fx = 0; + move32(); } ELSE { @@ -1005,14 +1033,16 @@ ivas_error ppp_voiced_encoder_fx( /*DTFS_getEngy_band(*TMPDTFS3,1500.0,upper_cut_off_freq_of_interest)) < 0.1) */ Ltemp1 = DTFS_getEngy_band_fx( *TMPDTFS_FX, 1500, upper_cut_off_freq_of_interest_fx ); + move32(); Ltemp2 = DTFS_getEngy_band_fx( *TMPDTFS3_FX, 1500, upper_cut_off_freq_of_interest_fx ); - + move32(); /*--------------------------------------------------------------*/ /* Ltemp_fx = (Word32)divide_dp(Ltemp1, Ltemp2, Qadj,1);//Q29+1 */ /*--------------------------------------------------------------*/ IF( Ltemp2 == 0 ) { Ltemp_fx = 0; + move32(); } ELSE { @@ -1057,9 +1087,10 @@ ivas_error ppp_voiced_encoder_fx( /* To increase bump up, raise first threshold, lower second */ /*tmp = (float)(10.0*log10(DTFS_getEngy(*TMPDTFS)/DTFS_getEngy(*TMPDTFS3)));*/ - Lacc = DTFS_getEngy_P2A_fx( TMPDTFS_FX ); /* Q = 2*(TMPDTFS_FX->Q) */ + Lacc = DTFS_getEngy_P2A_fx( TMPDTFS_FX ); /* Q = 2*(TMPDTFS_FX->Q) */ + move32(); Lacc1 = DTFS_getEngy_P2A_fx( TMPDTFS3_FX ); /* Q = 2*(TMPDTFS3_FX->Q) */ - + move32(); sft = shl( sub( TMPDTFS_FX->Q, TMPDTFS3_FX->Q ), 1 ); /* to check if Lacc<=2*Lacc1 */ flag1 = 0; @@ -1168,7 +1199,7 @@ ivas_error ppp_voiced_encoder_fx( ELSE { } - if ( PPP_MODE_E == 'B' ) + IF( PPP_MODE_E == 'B' ) { hSC_VBR->bump_up = 1; move16(); @@ -1184,10 +1215,12 @@ ivas_error ppp_voiced_encoder_fx( IF( hSC_VBR->Q_to_F ) { hSC_VBR->patterncount = add( hSC_VBR->patterncount, hSC_VBR->pattern_m ); + move16(); IF( GE_16( hSC_VBR->patterncount, 1000 ) ) { hSC_VBR->patterncount = sub( hSC_VBR->patterncount, 1000 ); + move16(); PPP_MODE_E = 'B'; move16(); hSC_VBR->bump_up = 1; @@ -1216,8 +1249,9 @@ ivas_error ppp_voiced_encoder_fx( DTFS_copy_fx( dtfs_temp_fx, *CURRP_Q_E_FX ); Lacc = DTFS_getEngy_P2A_fx( CURRP_NQ_FX ); + move32(); hSC_VBR->Q_prev_cw_en_fx = norm_l( Lacc ); - + move16(); /* hSC_VBR->Q_prev_cw_en_fx = (Lacc==0)?31: hSC_VBR->Q_prev_cw_en_fx;move16(); */ if ( Lacc == 0 ) { @@ -1226,7 +1260,9 @@ ivas_error ppp_voiced_encoder_fx( } hSC_VBR->prev_cw_en_fx = (Word32) L_shl( Lacc, hSC_VBR->Q_prev_cw_en_fx ); /*2Q+Q_prev_cw_en_fx */ + move32(); hSC_VBR->Q_prev_cw_en_fx = add( hSC_VBR->Q_prev_cw_en_fx, shl( CURRP_NQ_FX->Q, 1 ) ); + move16(); /* Copy DTFS related parameters from 'dtfs_temp' to 'st_fx' structure */ hSC_VBR->dtfs_enc_lag = dtfs_temp_fx->lag_fx; move16(); @@ -1289,6 +1325,7 @@ static void synthesis_filter_fx( Word16 b[], Word16 x[], Word16 y[], Word16 buf[ Word16 i, j; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif FOR( i = 0; i < N; i++ ) { @@ -1312,13 +1349,17 @@ static void synthesis_filter_fx( Word16 b[], Word16 x[], Word16 y[], Word16 buf[ acc = L_shl_o( acc, 3, &Overflow ); *y++ = round_fx_o( acc, &Overflow ); + move16(); buf[0] = round_fx_o( acc, &Overflow ); + move16(); #else acc = L_msu( acc, buf[0], b[0] ); acc = L_shl( acc, 3 ); *y++ = round_fx( acc ); + move16(); buf[0] = round_fx( acc ); + move16(); #endif } } @@ -1364,6 +1405,7 @@ static Word32 DTFS_freq_corr_fx( Word16 Q_num, Q_den; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif IF( LT_16( X1_DTFS_fx.lag_fx, X2_DTFS_fx.lag_fx ) ) { @@ -1372,15 +1414,15 @@ static Word32 DTFS_freq_corr_fx( corr_fx = L_deposit_l( 0 ); - L_lband = L_mult( lband, X2_DTFS_fx.lag_fx ); - L_hband = L_mult( hband, X2_DTFS_fx.lag_fx ); + L_lband = L_mult( lband, X2_DTFS_fx.lag_fx ); /* Q0 * Q0 -> Q1 */ + L_hband = L_mult( hband, X2_DTFS_fx.lag_fx ); /* Q0 * Q0 -> Q1 */ HalfLag = s_min( shr( X2_DTFS_fx.lag_fx, 1 ), X2_DTFS_fx.nH_4kHz_fx ); /* get lband and hband */ FOR( k = 0; k <= HalfLag; k++ ) { freq_fx = L_mult( k, 12800 ); - IF( GE_32( freq_fx, L_lband ) ) + if ( GE_32( freq_fx, L_lband ) ) { BREAK; } @@ -1389,7 +1431,7 @@ static Word32 DTFS_freq_corr_fx( FOR( k = 0; k <= HalfLag; k++ ) { freq_fx = L_mult( k, 12800 ); - IF( GE_32( freq_fx, L_hband ) ) + if ( GE_32( freq_fx, L_hband ) ) { BREAK; } @@ -1425,6 +1467,7 @@ static Word32 DTFS_freq_corr_fx( /* PORTING: Handling the functions with variable no. of arguments */ E_fx = DTFS_getEngy_band_fx( X1_DTFS_fx, lband, hband ); /* Q(1) */ + move32(); q1 = norm_l( E_fx ); if ( E_fx == 0 ) { @@ -1459,7 +1502,9 @@ static Word32 DTFS_freq_corr_fx( IF( Num == 0 ) { Result = 0; + move32(); *Qout = 31; + move16(); } ELSE { @@ -1503,6 +1548,7 @@ static Word32 DTFS_freq_corr_fx( Result = L_negate( L_tmp ); } *Qout = sub( 30, exp ); + move16(); } return Result; } @@ -1532,6 +1578,7 @@ static Word16 DTFS_alignment_extract_td_fx( Word16 *x1, Word16 *x2, Word16 lag ) Word32 maxcorr, corr; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif maxcorr = L_add( MIN_32, 0 ); Adiff_fx = (Word16) ( s_max( 4, shr( lag, 3 ) ) ); @@ -1549,7 +1596,7 @@ static Word16 DTFS_alignment_extract_td_fx( Word16 *x1, Word16 *x2, Word16 lag ) corr = L_mac( corr, x1[k], x2[( k - j + lag ) % lag] ); #endif } - if ( GT_32( corr, maxcorr ) ) + IF( GT_32( corr, maxcorr ) ) { idx = j; move16(); @@ -1589,17 +1636,19 @@ static Word32 DTFS_getEngy_band_fx( Word16 k, lk, hk, HalfLag; Word32 freq_fx, L_lband, L_hband; Word32 en_fx = 0; + move32(); #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif - L_lband = L_mult( lband, X_fx.lag_fx ); - L_hband = L_mult( hband, X_fx.lag_fx ); + L_lband = L_mult( lband, X_fx.lag_fx ); /* Q0 * Q0 -> Q1 */ + L_hband = L_mult( hband, X_fx.lag_fx ); /* Q0 * Q0 -> Q1 */ HalfLag = s_min( shr( sub( X_fx.lag_fx, 1 ), 1 ), X_fx.nH_4kHz_fx ); /* get lband and hband */ FOR( k = 1; k <= HalfLag; k++ ) { freq_fx = L_mult( k, 12800 ); - IF( GE_32( freq_fx, L_lband ) ) + if ( GE_32( freq_fx, L_lband ) ) { BREAK; } @@ -1609,7 +1658,7 @@ static Word32 DTFS_getEngy_band_fx( FOR( k = 1; k <= HalfLag; k++ ) { freq_fx = L_mult( k, 12800 ); - IF( GE_32( freq_fx, L_hband ) ) + if ( GE_32( freq_fx, L_hband ) ) { BREAK; } @@ -1688,10 +1737,13 @@ void sc_vbr_enc_init_fx( hSC_VBR->Q_to_F = 0; move16(); - hSC_VBR->numactive = 0; /* keep the count of the frames inside current 600 frame bloack.*/ - hSC_VBR->sum_of_rates_fx = 0; /* sum of the rates of past 600 active frames*/ + hSC_VBR->numactive = 0; /* keep the count of the frames inside current 600 frame bloack.*/ + move16(); + hSC_VBR->sum_of_rates_fx = 0; /* sum of the rates of past 600 active frames*/ + move32(); hSC_VBR->global_avr_rate_fx = 0; /* global rate upto current time. recorded a (rate in kbps) *6000*/ - hSC_VBR->global_frame_cnt = 0; /* 600 active frame block count. Used to update the global rate*/ + move32(); + hSC_VBR->global_frame_cnt = 0; /* 600 active frame block count. Used to update the global rate*/ move16(); hSC_VBR->rate_control = 0; move16(); @@ -1703,10 +1755,11 @@ void sc_vbr_enc_init_fx( hSC_VBR->vbr_generic_ho = 0; move16(); hSC_VBR->Local_VAD = 0; - + move16(); hSC_VBR->Last_Resort = 0; + move16(); hSC_VBR->set_ppp_generic = 0; - + move16(); hSC_VBR->last_7k2_coder_type = GENERIC; move16(); diff --git a/lib_enc/waveadjust_fec_cod_fx.c b/lib_enc/waveadjust_fec_cod_fx.c index 378898522..d6c55b0c9 100644 --- a/lib_enc/waveadjust_fec_cod_fx.c +++ b/lib_enc/waveadjust_fec_cod_fx.c @@ -18,7 +18,10 @@ * *--------------------------------------------------------------------*/ -Word32 SFM_Cal_fx( Word32 magn[], Word16 n ) +Word32 SFM_Cal_fx( + Word32 magn[], /*Q = Qx*/ + Word16 n /*Q = Q0*/ +) { /* Counted Dymamic RAM: 16 words */ Word32 logCurFlatness; @@ -39,9 +42,9 @@ Word32 SFM_Cal_fx( Word32 magn[], Word16 n ) sumLogMagn = L_add( sumLogMagn, logMagn ); /* Q8 */ #ifdef BASOP_NOGLOB - sumMagn = L_add_sat( sumMagn, magn_abs ); + sumMagn = L_add_sat( sumMagn, magn_abs ); /*Qx*/ #else - sumMagn = L_add( sumMagn, magn_abs ); + sumMagn = L_add( sumMagn, magn_abs ); /*Qx*/ #endif } @@ -50,7 +53,7 @@ Word32 SFM_Cal_fx( Word32 magn[], Word16 n ) sumMagn = L_deposit_l( 0 ); FOR( i = 0; i < n; i++ ) { - magn_abs = L_shr( L_abs( magn[i] ), 8 ); + magn_abs = L_shr( L_abs( magn[i] ), 8 ); /* Qx-8 */ sumMagn = L_add( sumMagn, magn_abs ); } /* log2(sumMagn) */ @@ -78,7 +81,6 @@ Word32 SFM_Cal_fx( Word32 magn[], Word16 n ) logCurFlatness = L_deposit_l( div_l( L_shl( logMagn, 1 ), n ) ); frac = L_and( logCurFlatness, 0xFF ); norm_value = (Word16) L_shr( logCurFlatness, 8 ); - move16(); logCurFlatness = L_sub( kExp2TableFrac_x[frac], 33 ); logCurFlatness = L_shl( logCurFlatness, sub( 16, norm_value ) ); /* Q31 */ -- GitLab From a4a35c89c1f0668ea11e64ac0c823edd892ae78c Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Sat, 18 Jan 2025 14:25:01 +0530 Subject: [PATCH 2/2] Clang formatting changes --- lib_enc/swb_tbe_enc_fx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_enc/swb_tbe_enc_fx.c b/lib_enc/swb_tbe_enc_fx.c index c1dd105fc..cb1151941 100644 --- a/lib_enc/swb_tbe_enc_fx.c +++ b/lib_enc/swb_tbe_enc_fx.c @@ -1198,7 +1198,7 @@ void wb_tbe_enc_fx( tmp = round_fx_o( L_tmp, &Overflow ); /* Q15 */ #else /* BASOP_NOGLOB */ L_tmp = L_shl( L_tmp, add( exp, 10 ) ); - tmp = round_fx( L_tmp ); /* Q15 */ + tmp = round_fx( L_tmp ); /* Q15 */ #endif } -- GitLab