diff --git a/lib_enc/ivas_core_pre_proc_front.c b/lib_enc/ivas_core_pre_proc_front.c index 090a880607fc28bc20746d6f9549695873fabe84..1e46f0ca10d7221ca57feaa092dfd5c9fc9b210c 100644 --- a/lib_enc/ivas_core_pre_proc_front.c +++ b/lib_enc/ivas_core_pre_proc_front.c @@ -1477,7 +1477,7 @@ ivas_error pre_proc_front_ivas_fx( move16(); stereo_classifier_features_ivas_fx( hStereoClassif, st->idchan, element_mode, localVAD_HE_SAD, lsf_new_fx, epsP_fx, st->pitch, st->voicing_fx, *cor_map_sum_fx, non_staX_fx, sp_div_fx, - st->clas, sub( 31, *epsP_fx_q ), ( 15 - Q8 ) /* exp of cor_map_sum */, ( 15 - Q8 ) /* exp of non_staX_fx */, sub( 15, q_sp_div ) ); + st->clas, sub( 31, *epsP_fx_q ), ( 31 - Q8 ) /* exp of cor_map_sum */, ( 31 - Q8 ) /* exp of non_staX_fx */, sub( 15, q_sp_div ) ); } /*----------------------------------------------------------------* diff --git a/lib_enc/ivas_stereo_dft_enc_itd.c b/lib_enc/ivas_stereo_dft_enc_itd.c index d2873bdfe7e88bf25eb5895f58d9c713df02adc6..f65b5114cfe01a24da5fcf8d22bf6b2e8db51154 100644 --- a/lib_enc/ivas_stereo_dft_enc_itd.c +++ b/lib_enc/ivas_stereo_dft_enc_itd.c @@ -109,7 +109,7 @@ static void set_band_limits_fx( move16(); *nbands = 0; move16(); - WHILE( LT_16( band_limits[( *nbands )++], shr( NFFT, 1 ) ) ) + WHILE( band_limits[( *nbands )++] < ( NFFT / 2 ) ) { band_limits[*nbands] = extract_l( Mpy_32_32_r( shl( dft_band_limits_erb4[*nbands], 1 ), 1717986918 /*( (float) ( STEREO_DFT_N_NS_ENC ) / STEREO_DFT_N_NS ) in Q 30*/ ) ); move16(); @@ -166,7 +166,7 @@ void stereo_dft_hybrid_ITD_flag_fx( static void stereo_dft_quantize_itd_fx( const Word16 in, - Word32 *out, + Word32 *out, // Q16 const Word32 input_Fs, Word16 *ind ) { @@ -211,9 +211,9 @@ static Word32 itd_vad_ms_snr_calc_fx( #else Word32 E_band_n[STEREO_DFT_ITD_VAD_BAND_NUM], // Q0 #endif - Word32 *Spd, + Word32 *Spd, // Q(31-Spd_e) Word16 *Spd_e, - Word32 *E_band, + Word32 *E_band, // Q(31-E_band_e) Word16 *E_band_e, Word16 *ms_snr_e ) { @@ -300,9 +300,9 @@ static void itd_vad_background_update_fx( Word32 E_band_n[STEREO_DFT_ITD_VAD_BAND_NUM], // Q0 #endif Word16 *vad_frm_cnt, - const Word32 ms_snr, + const Word32 ms_snr, // Q(31-ms_snr_e) const Word16 ms_snr_e, - Word32 *E_band, + Word32 *E_band, // Q(31-E_band_e) Word16 *E_band_e ) { Word16 i; @@ -411,11 +411,11 @@ static Word16 stereo_dft_enc_itd_vad_fx( Word32 E_band_n[STEREO_DFT_ITD_VAD_BAND_NUM], // Q0 #endif Word16 *vad_frm_cnt, - Word32 *Spd_L, + Word32 *Spd_L, // Q(31-Spd_L_e) Word16 *Spd_L_e, - Word32 *Spd_R, + Word32 *Spd_R, // Q(31-Spd_R_e) Word16 *Spd_R_e, - Word32 *mssnr, + Word32 *mssnr, // Q(31-mssnr_e) Word16 *mssnr_e ) { Word16 i; @@ -472,12 +472,12 @@ static Word32 calc_mean_E_ratio_fx( ITD_DATA_HANDLE hItd, Word16 nbands, Word16 band_limits[], - const Word32 sfm, - const Word32 nrg_L[STEREO_DFT_N_32k_ENC / 2], + const Word32 sfm, // Q31 + const Word32 nrg_L[STEREO_DFT_N_32k_ENC / 2], // Q(31-nrg_L_e) const Word16 nrg_L_e[STEREO_DFT_N_32k_ENC / 2], - const Word32 nrg_R[STEREO_DFT_N_32k_ENC / 2], + const Word32 nrg_R[STEREO_DFT_N_32k_ENC / 2], // Q(31-nrg_R_e) const Word16 nrg_R_e[STEREO_DFT_N_32k_ENC / 2], - Word32 *total_mEr, + Word32 *total_mEr, // Q(31-total_mEr_e) Word16 *total_mEr_e, Word16 *sum_Er_e ) { @@ -522,7 +522,7 @@ static Word32 calc_mean_E_ratio_fx( move16(); /*take bands up to 32kHz bandwidth as ITD is always calculated at 32kHz sampling rate*/ - nbands -= ( band_limits[nbands] > STEREO_DFT_N_32k_ENC / 2 ); + nbands = sub( nbands, ( band_limits[nbands] > STEREO_DFT_N_32k_ENC / 2 ) ); sum_Er = 0; move32(); @@ -610,6 +610,8 @@ static Word32 calc_mean_E_ratio_fx( } hItd->acorr_L_fx_e = max_exp1; hItd->acorr_R_fx_e = max_exp2; + move16(); + move16(); FOR( b = 0; b < nbands; b++ ) { hItd->acorr_L_fx[b] = L_shr_r( hItd->acorr_L_fx[b], sub( hItd->acorr_L_fx_e, acorr_L_fx_tmp_e[b] ) ); @@ -656,7 +658,7 @@ static void resetEstimates_fx( set32_fx( hItd->acorr_R_fx, 0, STEREO_DFT_BAND_MAX ); hItd->acorr_R_fx_e = 0; move16(); - hItd->cohSNR_fx = 983040; + hItd->cohSNR_fx = 983040; // 15.0f in Q16 move32(); return; @@ -667,8 +669,8 @@ static void resetEstimates_fx( * time-domain smoothing filter for smoothing the cross-correlation vector *-------------------------------------------------------------------------*/ static void td_sm_filter_fx( - Word32 *x, - Word32 *y, + Word32 *x, // Q0 + Word32 *y, // Q0 const Word16 L ) { Word16 i; @@ -708,12 +710,12 @@ static Word32 peak_detect_fx( const Word16 vad, Word32 *second_max, Word16 *second_max_lag, - const Word16 prev_itd, + const Word16 prev_itd, // Q0 const Word16 flag_noisy_speech_snr, const Word16 detected_itd_flag, Word32 *prev_max, // Q31 Word16 *prev_index, - Word32 *prev_avg_max, + Word32 *prev_avg_max, // Q(31-prev_avg_max) Word16 *prev_avg_max_e, Word32 *total_max, // xcorr_itd_e Word16 *out_e ) @@ -764,7 +766,7 @@ static Word32 peak_detect_fx( /*if maximum is out of boundaries signal zero itd OR maximum value is negative*/ test(); - *zero_itd_flag = ( L_sub( *max_max, 4294968 ) < max_low || *max_max < max_high ); + *zero_itd_flag = ( L_sub( *max_max, 4294968 /*.002 Q31*/ ) < max_low || *max_max < max_high ); move16(); // adjustment is done for matching processing path with float code (differing due to precision loss) @@ -870,7 +872,7 @@ static Word32 peak_detect_fx( test(); test(); test(); - if ( vad && thres_diff > 0 && ( ( BASOP_Util_Cmp_Mant32Exp( thres_diff, thres_diff_e, 107374182, 0 ) < 0 && ( BASOP_Util_Cmp_Mant32Exp( snr, 15, 15, 31 ) <= 0 && BASOP_Util_Cmp_Mant32Exp( snr, 15, 7, 31 ) > 0 ) ) || ( BASOP_Util_Cmp_Mant32Exp( thres_diff, thres_diff_e, 21474836, 0 ) < 0 && ( BASOP_Util_Cmp_Mant32Exp( snr, 15, 15, 31 ) > 0 && BASOP_Util_Cmp_Mant32Exp( snr, 15, 30, 31 ) < 0 ) ) ) ) + if ( vad && thres_diff > 0 && ( ( BASOP_Util_Cmp_Mant32Exp( thres_diff, thres_diff_e, 107374182 /*.05 in Q31*/, 0 ) < 0 && ( BASOP_Util_Cmp_Mant32Exp( snr, 15, 15, 31 ) <= 0 && BASOP_Util_Cmp_Mant32Exp( snr, 15, 7, 31 ) > 0 ) ) || ( BASOP_Util_Cmp_Mant32Exp( thres_diff, thres_diff_e, 21474836 /* 0.01f in Q31*/, 0 ) < 0 && ( BASOP_Util_Cmp_Mant32Exp( snr, 15, 15, 31 ) > 0 && BASOP_Util_Cmp_Mant32Exp( snr, 15, 30, 31 ) < 0 ) ) ) ) { wfac = ONE_IN_Q30; // 2.0f move32(); @@ -887,7 +889,7 @@ static Word32 peak_detect_fx( move32(); } // else if ( detected_itd_flag == 0 && *max_max > 1.5f * avg_max && *prev_max > 1.5f * *prev_avg_max && abs( *index - *prev_index ) <= 2 ) - ELSE IF( detected_itd_flag == 0 && BASOP_Util_Cmp_Mant32Exp( *max_max, 0, Mpy_32_32( 1610612736, avg_max ), add( sum_max_e, 1 ) ) > 0 && BASOP_Util_Cmp_Mant32Exp( *prev_max, 0, Mpy_32_32( 1610612736, *prev_avg_max ), add( *prev_avg_max_e, 1 ) ) > 0 && LE_16( abs_s( sub( *index, *prev_index ) ), 2 ) ) + ELSE IF( detected_itd_flag == 0 && BASOP_Util_Cmp_Mant32Exp( *max_max, 0, Mpy_32_32( 1610612736 /*1.5f in Q29*/, avg_max ), add( sum_max_e, 1 ) ) > 0 && BASOP_Util_Cmp_Mant32Exp( *prev_max, 0, Mpy_32_32( 1610612736 /*1.5f in Q29*/, *prev_avg_max ), add( *prev_avg_max_e, 1 ) ) > 0 && LE_16( abs_s( sub( *index, *prev_index ) ), 2 ) ) { wfac = 805306368; // 1.5f in Q29 move32(); @@ -1122,13 +1124,13 @@ void stereo_dft_enc_compute_itd_fx( move32(); prod_R_e = 0; move16(); - sum_nrg_L = Mpy_32_32( pDFT_L[0], pDFT_L[0] ) /*+ FLT_MIN*/; + sum_nrg_L = Mpy_32_32( pDFT_L[0], pDFT_L[0] ) /*+ FLT_MIN Q(31-(2*DFT_L_e))*/; sum_nrg_L_e = shl( DFT_L_e[0], 1 ); - sum_nrg_R = Mpy_32_32( pDFT_R[0], pDFT_R[0] ) /*+ FLT_MIN*/; + sum_nrg_R = Mpy_32_32( pDFT_R[0], pDFT_R[0] ) /*+ FLT_MIN //Q(31-(2*DFT_L_e))*/; sum_nrg_R_e = shl( DFT_R_e[0], 1 ); sum_abs_L = BASOP_Util_Add_Mant32Exp( L_abs( pDFT_L[0] ), DFT_L_e[0], EPSILON_FX_M, EPSILON_FX_E, &sum_abs_L_e ) /*+ EPSILON*/; sum_abs_R = BASOP_Util_Add_Mant32Exp( L_abs( pDFT_R[0] ), DFT_R_e[0], EPSILON_FX_M, EPSILON_FX_E, &sum_abs_R_e ) /*+ EPSILON*/; - xcorr_lb[0] = Mpy_32_32( pDFT_L[0], pDFT_L[0] ); + xcorr_lb[0] = Mpy_32_32( pDFT_L[0], pDFT_L[0] ); // Q(31-(2*DFT_L_e)) move32(); xcorr_lb_e[0] = shl( DFT_L_e[0], 1 ); move16(); @@ -1160,6 +1162,7 @@ void stereo_dft_enc_compute_itd_fx( set16_fx( Spd_R_e, 0, STEREO_DFT_N_32k_ENC / 2 + 1 ); j = 0; // for loop statement + move16(); FOR( i = 1; i < NFFT_mid; i++ ) { /*if ( i == 121 ) @@ -1319,7 +1322,7 @@ void stereo_dft_enc_compute_itd_fx( j = 0; move16(); } - j++; // for loop statement + j = add( j, 1 ); // for loop statement } /* collect UNCLR classifier parameters */ @@ -1494,7 +1497,7 @@ void stereo_dft_enc_compute_itd_fx( // sfm_L = expf( log_prod_L / ( NFFT_mid ) ) / ( sum_abs_L / ( NFFT_mid ) ); L_temp = BASOP_Util_Divide3232_Scale_cadence( log_prod_L, NFFT_mid, &L_temp_e ); L_temp_e = add( L_temp_e, sub( log_prod_L_e, 31 ) ); - L_temp = BASOP_Util_fPow( 1459366444, 2, L_temp, L_temp_e, &L_temp_e ); + L_temp = BASOP_Util_fPow( 1459366444 /*2.718 in Q29*/, 2, L_temp, L_temp_e, &L_temp_e ); q_temp = norm_l( NFFT_mid ); L_temp2 = L_shl( NFFT_mid, q_temp ); L_temp2_e = sub( 31, q_temp ); @@ -1518,7 +1521,7 @@ void stereo_dft_enc_compute_itd_fx( // sfm_R = expf( log_prod_R / ( NFFT_mid ) ) / ( sum_abs_R / ( NFFT_mid ) ); L_temp = BASOP_Util_Divide3232_Scale_cadence( log_prod_R, NFFT_mid, &L_temp_e ); L_temp_e = add( L_temp_e, sub( log_prod_R_e, 31 ) ); - L_temp = BASOP_Util_fPow( 1459366444, 2, L_temp, L_temp_e, &L_temp_e ); + L_temp = BASOP_Util_fPow( 1459366444 /*2.718 in Q29*/, 2, L_temp, L_temp_e, &L_temp_e ); q_temp = norm_l( NFFT_mid ); L_temp2 = L_shl( NFFT_mid, q_temp ); L_temp2_e = sub( 31, q_temp ); @@ -1718,7 +1721,7 @@ void stereo_dft_enc_compute_itd_fx( hStereoDft->currentNumUpdates = add( hStereoDft->currentNumUpdates, 1 ); move16(); - FOR( i = 1; i < shr( NFFT, 2 ); i++ ) + FOR( i = 1; i < NFFT / 4; i++ ) { /* Low pass filter cross L/R power spectrum */ // hStereoDft->xspec_smooth[2 * i] = ( 1.f - cng_xcorr_filt ) * hStereoDft->xspec_smooth[2 * i] + cng_xcorr_filt * xcorr[2 * i]; @@ -1761,6 +1764,10 @@ void stereo_dft_enc_compute_itd_fx( } } } + test(); + test(); + test(); + test(); IF( ( vad_flag_dtx[0] == 0 ) || ( hCPE->hFrontVad[0] == NULL && ( EQ_32( hCPE->hCoreCoder[0]->last_core_brate, SID_2k40 ) || EQ_32( hCPE->hCoreCoder[0]->last_core_brate, FRAME_NO_DATA ) ) ) || hCPE->hStereoCng->first_SID_after_TD ) { IF( vad_flag_dtx[0] == 0 ) @@ -1824,7 +1831,9 @@ void stereo_dft_enc_compute_itd_fx( // tmpf1 += EPSILON; tmpf1 = BASOP_Util_Add_Mant32Exp( L_temp, L_temp_e, EPSILON_FX_M, EPSILON_FX_E, &tmpf1_e ); tmpf2 = tmpf1; + move32(); tmpf2_e = tmpf1_e; + move16(); // tmpf1 = powf( tmpf1, alpha ); tmpf1 = BASOP_Util_fPow( tmpf1, tmpf1_e, alpha, 0, &tmpf1_e ); // tmpf3 += tmpf2 * tmpf1; @@ -1871,7 +1880,9 @@ void stereo_dft_enc_compute_itd_fx( // tmpf1 += EPSILON; tmpf1 = BASOP_Util_Add_Mant32Exp( L_temp, L_temp_e, EPSILON_FX_M, EPSILON_FX_E, &tmpf1_e ); tmpf2 = tmpf1; + move32(); tmpf2_e = tmpf1_e; + move16(); // tmpf1 = powf( tmpf1, alpha ); tmpf1 = BASOP_Util_fPow( tmpf1, tmpf1_e, alpha, 0, &tmpf1_e ); // tmpf3 += tmpf2 * tmpf1; @@ -1937,7 +1948,9 @@ void stereo_dft_enc_compute_itd_fx( // tmpf1 += EPSILON; tmpf1 = BASOP_Util_Add_Mant32Exp( L_temp, L_temp_e, EPSILON_FX_M, EPSILON_FX_E, &tmpf1_e ); tmpf2 = tmpf1; + move32(); tmpf2_e = tmpf1_e; + move16(); // tmpf1 = powf( tmpf1, alpha ); tmpf1 = BASOP_Util_fPow( tmpf1, tmpf1_e, alpha, 0, &tmpf1_e ); // tmpf3 += tmpf2 * tmpf1; @@ -2080,7 +2093,7 @@ void stereo_dft_enc_compute_itd_fx( move32(); sum_xcorr_e = 0; move16(); - for ( i = 1; i < NFFT_mid; i++ ) + FOR( i = 1; i < NFFT_mid; i++ ) { // xcorr_abs[i] = logf( xcorr_abs[i] / ( sum_nrg_L + sum_nrg_R + 1e-5f ) + 1e-5f ); L_temp = BASOP_Util_Add_Mant32Exp( sum_nrg_L, sum_nrg_L_e, sum_nrg_R, sum_nrg_R_e, &L_temp_e ); @@ -2112,7 +2125,7 @@ void stereo_dft_enc_compute_itd_fx( /*smooth cohSNR with time */ // if ( ( hItd->cohSNR - cohSNR ) < 10.0f ) - IF( LT_32( L_sub( hItd->cohSNR_fx, cohSNR ), 655360 ) ) + IF( LT_32( L_sub( hItd->cohSNR_fx, cohSNR ), 655360 /*10 in Q16*/ ) ) { // tmpf1 = max( 0.05f, min( 0.25f, sfm_L * 0.5f ) ); tmpf1 = L_max( 107374182, L_min( ONE_IN_Q29, L_shr( sfm_L, 1 ) ) ); @@ -2123,7 +2136,7 @@ void stereo_dft_enc_compute_itd_fx( ELSE { // hItd->cohSNR = hItd->cohSNR - 0.05f; - hItd->cohSNR_fx = L_sub( hItd->cohSNR_fx, 3277 ); + hItd->cohSNR_fx = L_sub( hItd->cohSNR_fx, 3277 /*.05 in Q16*/ ); move32(); } @@ -2180,7 +2193,7 @@ void stereo_dft_enc_compute_itd_fx( test(); test(); test(); - IF( hCPE->hCoreCoder[0]->sp_aud_decision0 && sub( index, STEREO_DFT_ITD_MAX_ANA ) != hItd->prev_itd && !flag_noisy_speech_snr && hCPE->hCoreCoder[0]->vad_flag && LT_32( tmpf1, 644245094 ) ) + IF( hCPE->hCoreCoder[0]->sp_aud_decision0 && NE_16( sub( index, STEREO_DFT_ITD_MAX_ANA ), hItd->prev_itd ) && !flag_noisy_speech_snr && hCPE->hCoreCoder[0]->vad_flag && LT_32( tmpf1, 644245094 ) ) { // thres *= 1.0f + 1.f * min( 1.f, max( 0.f, ( -1.0f * sfm_L + 0.5f ) / ( 0.5f - 0.2f ) ) ); L_temp = BASOP_Util_Add_Mant32Exp( L_negate( sfm_L ), 0, ONE_IN_Q30, 0, &L_temp_e ); @@ -2188,6 +2201,7 @@ void stereo_dft_enc_compute_itd_fx( L_temp2_e = add( L_temp2_e, L_temp_e - 0 ); L_temp2 = L_shl_sat( L_temp2, sub( L_temp2_e, 1 ) ); // Q30 L_temp2_e = 1; + move16(); L_temp2 = L_min( ONE_IN_Q30, L_max( 0, L_temp2 ) ); L_temp2 = L_add_sat( ONE_IN_Q30, L_temp2 ); // Q30 thres = Mpy_32_32( thres, L_temp2 ); @@ -2203,7 +2217,7 @@ void stereo_dft_enc_compute_itd_fx( test(); test(); test(); - IF( hCPE->hCoreCoder[0]->ini_frame == 0 || hCPE->last_element_mode != IVAS_CPE_DFT || !hCPE->hCoreCoder[0]->sp_aud_decision0 || flag_noisy_speech_snr || BASOP_Util_Cmp_Mant32Exp( cohSNR, 15, 20, 31 ) < 0 ) + IF( hCPE->hCoreCoder[0]->ini_frame == 0 || NE_16( hCPE->last_element_mode, IVAS_CPE_DFT ) || !hCPE->hCoreCoder[0]->sp_aud_decision0 || flag_noisy_speech_snr || BASOP_Util_Cmp_Mant32Exp( cohSNR, 15, 20, 31 ) < 0 ) { hItd->itd_thres_fx = thres; move32(); @@ -2220,7 +2234,7 @@ void stereo_dft_enc_compute_itd_fx( test(); test(); test(); - IF( flag_noisy_speech_snr == 0 && hCPE->hCoreCoder[0]->vad_flag == 1 && hItd->detected_itd_flag == 0 && ( LT_16( hItd->currFlatness_fx, 192 ) /* 1.5 in Q7*/ || hCPE->hCoreCoder[0]->sp_aud_decision0 == 1 ) ) + IF( flag_noisy_speech_snr == 0 && EQ_16( hCPE->hCoreCoder[0]->vad_flag, 1 ) && hItd->detected_itd_flag == 0 && ( LT_16( hItd->currFlatness_fx, 192 ) /* 1.5 in Q7*/ || EQ_16( hCPE->hCoreCoder[0]->sp_aud_decision0, 1 ) ) ) { // hItd->itd_thres *= 1.5f; hItd->itd_thres_fx = L_shl_sat( Mpy_32_32( hItd->itd_thres_fx, 1610612736 ), 1 ); /* Saturation added to avoid assertions (this needs to be investigated) */ @@ -2241,7 +2255,7 @@ void stereo_dft_enc_compute_itd_fx( // if ( hItd->itd_tracking == 1 && ( second_max > hItd->itd_thres || tmpf1 - second_max < min( tmpf1 * 0.5f, 0.2f ) ) ) test(); test(); - if ( EQ_16( hItd->itd_tracking, 1 ) && ( GT_32( second_max, hItd->itd_thres_fx ) || LT_32( L_sub( tmpf1, second_max ), L_min( L_shr( tmpf1, 1 ), 429496730 ) ) ) ) + if ( EQ_16( hItd->itd_tracking, 1 ) && ( GT_32( second_max, hItd->itd_thres_fx ) || LT_32( L_sub( tmpf1, second_max ), L_min( L_shr( tmpf1, 1 ), 429496730 /*.2f in Q31*/ ) ) ) ) { index = second_max_lag; move16(); @@ -2249,7 +2263,7 @@ void stereo_dft_enc_compute_itd_fx( // if ( hItd->itd_tracking == 1 && abs( hItd->prev_itd - ( index - STEREO_DFT_ITD_MAX_ANA ) ) <= max( 2, (int16_t) round_f( abs( hItd->prev_itd ) / 16.f ) ) ) test(); - if ( hItd->itd_tracking == 1 && abs_s( sub( hItd->prev_itd, sub( index, STEREO_DFT_ITD_MAX_ANA ) ) ) <= s_max( 2, shr_r( abs_s( hItd->prev_itd ), 4 ) ) ) + IF( EQ_16( hItd->itd_tracking, 1 ) && LE_16( abs_s( sub( hItd->prev_itd, sub( index, STEREO_DFT_ITD_MAX_ANA ) ) ), s_max( 2, shr_r( abs_s( hItd->prev_itd ), 4 ) ) ) ) { // hItd->itd_thres *= 0.75f; hItd->itd_thres_fx = Mpy_32_32( hItd->itd_thres_fx, 1610612736 ); @@ -2435,24 +2449,33 @@ void stereo_dft_enc_compute_itd_fx( /*Breakdown of fine-control conditions */ // fc_condition_1 = abs( hItd->prev_itd ) > 0.2f * abs( itd ); - fc_condition_1 = (Word16) GT_16( abs_s( hItd->prev_itd ), mult( 6554 /*0.2f*/, abs_s( itd ) ) ); + fc_condition_1 = extract_l( GT_16( abs_s( hItd->prev_itd ), mult( 6554 /*0.2f*/, abs_s( itd ) ) ) ); // fc_condition_2 = cor_lb_avrg > 0.85f; - fc_condition_2 = (Word16) GT_32( cor_lb_avrg, 1825361101 /*0.85f*/ ); + fc_condition_2 = extract_l( GT_32( cor_lb_avrg, 1825361101 /*0.85f*/ ) ); // fc_condition_3 = ( cor_lb_avrg > 0.7f && ( cor_lb[0] > 0.9f || cor_lb[1] > 0.9f || cor_lb[2] > 0.9f ) && hItd->prev_sum_nrg_L_lb > 0.5f * sum_nrg_L_lb && hItd->prev_sum_nrg_L_lb < 2.0f * sum_nrg_L_lb ); test(); test(); test(); test(); test(); - fc_condition_3 = (Word16) ( GT_32( cor_lb_avrg, 1503238554 /*0.7f*/ ) && ( GT_32( cor_lb[0], 1932735283 /*0.9f*/ ) || GT_32( cor_lb[1], 1932735283 /*0.9f*/ ) || GT_32( cor_lb[2], 1932735283 /*0.9f*/ ) ) && + fc_condition_3 = extract_l( GT_32( cor_lb_avrg, 1503238554 /*0.7f*/ ) && ( GT_32( cor_lb[0], 1932735283 /*0.9f*/ ) || GT_32( cor_lb[1], 1932735283 /*0.9f*/ ) || GT_32( cor_lb[2], 1932735283 /*0.9f*/ ) ) && BASOP_Util_Cmp_Mant32Exp( hItd->prev_sum_nrg_L_lb_fx, hItd->prev_sum_nrg_L_lb_fx_e, sum_nrg_L_lb, sub( sum_nrg_L_lb_e, 1 ) ) > 0 && BASOP_Util_Cmp_Mant32Exp( hItd->prev_sum_nrg_L_lb_fx, hItd->prev_sum_nrg_L_lb_fx_e, sum_nrg_L_lb, add( sum_nrg_L_lb_e, 1 ) ) < 0 ); // fc_condition_4 = par_L_avrg > 0.6f; - fc_condition_4 = (Word16) GT_32( par_L_avrg, 1288490189 /*0.6f*/ ); + fc_condition_4 = extract_l( GT_32( par_L_avrg, 1288490189 /*0.6f*/ ) ); fc_condition_5 = hItd->prev_itd != 0; fc_condition_6_a = L_mult0( itd, hItd->prev_itd ) < 0; /* ITD sign change */ fc_condition_6_b = L_mult0( itd, hItd->prev_itd ) == 0; /* ITD jump to zero */ // fc_condition_6_c = abs( itd - hItd->prev_itd ) > 0.5f * ( ( abs( itd ) > abs( hItd->prev_itd ) ) ? abs( itd ) : abs( hItd->prev_itd ) ); /* Magnitude of the ITD jump */ - fc_condition_6_c = (Word16) GT_16( abs_s( sub( itd, hItd->prev_itd ) ), shr( ( ( abs_s( itd ) > abs_s( hItd->prev_itd ) ) ? abs_s( itd ) : abs_s( hItd->prev_itd ) ), 1 ) ); /* Magnitude of the ITD jump */ + fc_condition_6_c = extract_l( GT_16( abs_s( sub( itd, hItd->prev_itd ) ), shr( ( ( abs_s( itd ) > abs_s( hItd->prev_itd ) ) ? abs_s( itd ) : abs_s( hItd->prev_itd ) ), 1 ) ) ); /* Magnitude of the ITD jump */ + + IF( GT_16( abs_s( itd ), abs_s( hItd->prev_itd ) ) ) + { + fc_condition_6_c = extract_l( GT_16( abs_s( sub( itd, hItd->prev_itd ) ), shr( ( abs_s( itd ) ), 1 ) ) ); /* Magnitude of the ITD jump */ + } + ELSE + { + fc_condition_6_c = extract_l( GT_16( abs_s( sub( itd, hItd->prev_itd ) ), shr( ( abs_s( hItd->prev_itd ) ), 1 ) ) ); /* Magnitude of the ITD jump */ + } /* Combining conditions 1,2,3,4 */ test(); diff --git a/lib_enc/ivas_stereo_dft_td_itd.c b/lib_enc/ivas_stereo_dft_td_itd.c index 0e3d95f063556a0203cccd5c1336bf7d6f4c112f..3cccae9c1ef312044936f29158ad470b5ee38f4a 100644 --- a/lib_enc/ivas_stereo_dft_td_itd.c +++ b/lib_enc/ivas_stereo_dft_td_itd.c @@ -54,7 +54,7 @@ #define STEREO_DFT_CHANNEL_EXTR_LPC_VEC_LIMIT 320 #define FLR_FX 16384 // Q15 #define ONE_HALF 24576 // Q14 -const Word16 wac_swb_h_fx[LPC_SHB_ORDER + 1] = { +const Word16 wac_swb_h_fx[LPC_SHB_ORDER + 1] = { // Q15 32767, 32758, 32731, @@ -68,7 +68,7 @@ const Word16 wac_swb_h_fx[LPC_SHB_ORDER + 1] = { 31870 }; -const Word16 wac_swb_l_fx[LPC_SHB_ORDER + 1] = { +const Word16 wac_swb_l_fx[LPC_SHB_ORDER + 1] = { // Q15 32767, 29696, 20864, @@ -90,7 +90,7 @@ const Word16 wac_swb_l_fx[LPC_SHB_ORDER + 1] = { static void stereo_td_get_td_itd_fx( Word16 *td_itd, /* o : td_itd in samples at sampling frequency */ Word16 *td_itd_32, /* o : td_itd in samples at 32kHz */ - const Word32 itd, /* i : itd in samples at sampling frequency */ + const Word32 itd, /* i : itd in samples at sampling frequency q_itd */ Word16 q_itd, const Word32 input_Fs /* i : sampling frequency */ ) @@ -140,13 +140,13 @@ static void stereo_td_get_td_itd_fx( static void stereo_td_channel_extrapolate_fx( Encoder_State **sts, const Word16 dft_ovl, - const Word16 shift_mem[], + const Word16 shift_mem[], // q_shift Word16 q_shift, - Word16 shift_input[], + Word16 shift_input[], // q_shift const Word16 input_frame, const Word16 itd_shift, const Word16 lagging_channel, - Word16 *input_mem[CPE_CHANNELS], /* i/o: input buffer memory */ + Word16 *input_mem[CPE_CHANNELS], /* i/o: input buffer memory q_input_mem */ Word16 *q_input_mem, Word16 *q_new_shift ) { @@ -172,7 +172,7 @@ static void stereo_td_channel_extrapolate_fx( set16_fx( shift_combined, 0, add( L_FRAME48k, L_FRAME48k ) ); set16_fx( residual, 0, STEREO_DFT_CHANNEL_EXTR_LPC_VEC_LIMIT + ( STEREO_DFT_ITD_MAX * input_frame ) / L_FRAME32k ); - leading_channel = add( lagging_channel, 1 ) & 1; + leading_channel = s_and( add( lagging_channel, 1 ), 1 ); IF( EQ_16( sts[0]->element_mode, IVAS_CPE_DFT ) ) { size_ovl = dft_ovl; @@ -183,6 +183,8 @@ static void stereo_td_channel_extrapolate_fx( size_ovl = input_frame; pitch0 = sts[lagging_channel]->pitch[0]; } + move16(); + move16(); pred_ovlp = idiv1616( input_frame, 10 ); @@ -199,9 +201,16 @@ static void stereo_td_channel_extrapolate_fx( dot_lead_lag_1 = EPSILON_FX; dot_lead_lead_1 = EPSILON_FX; dot_lag_lag_1 = EPSILON_FX; + move64(); + move64(); + move64(); + move32(); + move32(); + move32(); FOR( i = 0; i < size_ovl; i++ ) { shift_combined[i] = shift_mem[i]; // q_shift + move16(); // q_shift_combined = q_shift; dot_lead_lag = W_mac0_16_16( dot_lead_lag, input_mem[leading_channel][i], shift_mem[i] ); dot_lead_lead = W_mac0_16_16( dot_lead_lead, input_mem[leading_channel][i], input_mem[leading_channel][i] ); @@ -209,19 +218,20 @@ static void stereo_td_channel_extrapolate_fx( } FOR( i = 0; i < input_frame - itd_shift; i++ ) { - shift_combined[add( i, size_ovl )] = shift_input[i]; // q_shift + shift_combined[i + size_ovl] = shift_input[i]; // q_shift + move16(); dot_lead_lag = W_mac0_16_16( dot_lead_lag, sts[leading_channel]->input_fx[i], shift_input[i] ); dot_lead_lead = W_mac0_16_16( dot_lead_lead, sts[leading_channel]->input_fx[i], sts[leading_channel]->input_fx[i] ); dot_lag_lag = W_mac0_16_16( dot_lag_lag, shift_input[i], shift_input[i] ); } q_dot_lead_lag = q_shift + q_input_mem[leading_channel]; // q_input_mem = q_input q_dot_lead_lead = q_input_mem[leading_channel] + q_input_mem[leading_channel]; - q_dot_lag_lag = q_shift + q_shift; + q_dot_lag_lag = add( q_shift, q_shift ); - q_dot_lead_lag = q_dot_lead_lag + W_norm( dot_lead_lag ) - 32; - q_dot_lead_lead = q_dot_lead_lead + W_norm( dot_lead_lead ) - 32; - q_dot_lag_lag = q_dot_lag_lag + W_norm( dot_lag_lag ) - 32; + q_dot_lead_lag = sub( add( q_dot_lead_lag, W_norm( dot_lead_lag ) ), 32 ); + q_dot_lead_lead = sub( add( q_dot_lead_lead, W_norm( dot_lead_lead ) ), 32 ); + q_dot_lag_lag = sub( add( q_dot_lag_lag, W_norm( dot_lag_lag ) ), 32 ); dot_lead_lag_1 = W_extract_h( W_shl( dot_lead_lag, W_norm( dot_lead_lag ) ) ); dot_lead_lead_1 = W_extract_h( W_shl( dot_lead_lead, W_norm( dot_lead_lead ) ) ); dot_lag_lag_1 = W_extract_h( W_shl( dot_lag_lag, W_norm( dot_lag_lag ) ) ); @@ -229,13 +239,13 @@ static void stereo_td_channel_extrapolate_fx( Word16 g_e, f, f_e, g_lpc_e, nsr_e; g = BASOP_Util_Divide3232_Scale( dot_lead_lag_1, dot_lead_lead_1, &g_e ); - g_e = g_e + ( q_dot_lead_lead - q_dot_lead_lag ); + g_e = add( g_e, sub( q_dot_lead_lead, q_dot_lead_lag ) ); f = BASOP_Util_Divide3232_Scale( dot_lead_lag_1, dot_lag_lag_1, &f_e ); - f_e = f_e + ( q_dot_lag_lag - q_dot_lead_lag ); + f_e = add( f_e, sub( q_dot_lag_lag, q_dot_lead_lag ) ); nsr = mult( g, f ); - nsr_e = BASOP_Util_Add_MantExp( ONE_IN_Q14, 1, negate( nsr ), g_e + f_e, &nsr ); + nsr_e = BASOP_Util_Add_MantExp( ONE_IN_Q14, 1, negate( nsr ), add( g_e, f_e ), &nsr ); IF( g_e > 0 ) { g = check_bounds_s_fx( g, negate( shl( 1, sub( 15, g_e ) ) ), shl( ONE_HALF, sub( 1, g_e ) ) ); @@ -244,11 +254,12 @@ static void stereo_td_channel_extrapolate_fx( { nsr = check_bounds_s_fx( nsr, 0, shl( 1, sub( 15, nsr_e ) ) ); } - g = shl( g, g_e - 1 ); // q14 - nsr = shl( nsr, nsr_e ); // Q15 + g = shl( g, sub( g_e, 1 ) ); // q14 + nsr = shl( nsr, nsr_e ); // Q15 g_lpc_e = 0; + move16(); g_lpc = Sqrt16( nsr, &g_lpc_e ); - g_lpc = shl( g_lpc, g_lpc_e - 1 ); // Q14 + g_lpc = shl( g_lpc, sub( g_lpc_e, 1 ) ); // Q14 /* rectangular window */ set16_fx( window, 32767, STEREO_DFT_CHANNEL_EXTR_LPC_VEC_LIMIT ); set16_zero_fx( mem_zero, STEREO_DFT_CHANNEL_EXTR_LPC_ORDER ); @@ -257,19 +268,20 @@ static void stereo_td_channel_extrapolate_fx( autocorr_ivas_fx( shift_combined + input_frame + size_ovl - itd_shift - STEREO_DFT_CHANNEL_EXTR_LPC_VEC_LIMIT, q_shift, STEREO_DFT_CHANNEL_EXTR_LPC_ORDER, r_h, r_l, &Q_r, STEREO_DFT_CHANNEL_EXTR_LPC_VEC_LIMIT, window, 0, 0, 0 ); /* Ensure R[0] isn't zero when entering Levinson-Durbin */ r_l[0] = s_max( r_l[0], 1 ); + move16(); FOR( i = 0; i <= STEREO_DFT_CHANNEL_EXTR_LPC_ORDER; i++ ) { L_tmp = Mpy_32( r_h[i], r_l[i], wac_swb_h_fx[i], wac_swb_l_fx[i] ); L_Extract( L_tmp, &r_h[i], &r_l[i] ); } r_l[0] = s_max( r_l[0], 1 ); - - + move16(); flag = E_LPC_lev_dur( r_h, r_l, A, NULL, STEREO_DFT_CHANNEL_EXTR_LPC_ORDER, NULL ); Copy_Scale_sig( A, A, STEREO_DFT_CHANNEL_EXTR_LPC_ORDER + 1, sub( norm_s( A[0] ), 2 ) ); IF( EQ_16( flag, 1 ) ) { g_lpc = 0; + move16(); } ELSE { @@ -278,15 +290,25 @@ static void stereo_td_channel_extrapolate_fx( /* extend the residual */ /* to prevent out of bound reading */ - res_shift = ( pitch_lag < PIT_MAX ? pitch_lag : itd_shift ); + IF( LT_16( pitch_lag, PIT_MAX ) ) + { + res_shift = pitch_lag; + move16(); + } + ELSE + { + res_shift = itd_shift; + move16(); + } FOR( i = STEREO_DFT_CHANNEL_EXTR_LPC_VEC_LIMIT; i < STEREO_DFT_CHANNEL_EXTR_LPC_VEC_LIMIT + itd_shift; i++ ) { residual[i] = residual[i - res_shift]; + move16(); } /* perform sythesis */ - E_UTIL_synthesis( 0, A, residual, shift_combined + input_frame + size_ovl - STEREO_DFT_CHANNEL_EXTR_LPC_VEC_LIMIT - itd_shift, STEREO_DFT_CHANNEL_EXTR_LPC_VEC_LIMIT + itd_shift, mem_zero, 0, STEREO_DFT_CHANNEL_EXTR_LPC_ORDER ); + E_UTIL_synthesis( 0, A, residual, shift_combined + sub( add( input_frame, size_ovl ), add( STEREO_DFT_CHANNEL_EXTR_LPC_VEC_LIMIT, itd_shift ) ), STEREO_DFT_CHANNEL_EXTR_LPC_VEC_LIMIT + itd_shift, mem_zero, 0, STEREO_DFT_CHANNEL_EXTR_LPC_ORDER ); } Copy( shift_combined + size_ovl, shift_input, input_frame ); // q_shift @@ -336,13 +358,13 @@ static void stereo_td_channel_extrapolate_fx( void stereo_td_itd_fx( ITD_DATA *hITD, /* i/o: ITD data structure */ - Word16 input_mem_itd[CPE_CHANNELS][STEREO_DFT_OVL_MAX], /* o : ITD memory (only used in DFT Stereo) */ + Word16 input_mem_itd[CPE_CHANNELS][STEREO_DFT_OVL_MAX], /* o : ITD memory (only used in DFT Stereo) q_input_mem_itd*/ Word16 *q_input_mem_itd, const Word16 hybrid_itd_flag, /* i : flag for hybrid TD/FD ITD processing */ const Word16 dft_ovl, /* i : size of DFT overlap */ Encoder_State **sts, /* i/o: Encoder state structure */ const Word16 input_frame, /* i : input frame length */ - Word16 *input_mem[CPE_CHANNELS], /* i/o: input buffer memory */ + Word16 *input_mem[CPE_CHANNELS], /* i/o: input buffer memory q_input_mem */ Word16 *q_input_mem ) { Word16 i, ch, n; @@ -363,23 +385,18 @@ void stereo_td_itd_fx( FOR( n = 0; n < CPE_CHANNELS; n++ ) { - Scale_sig( &input_mem[n][0], dft_ovl, sts[n]->q_inp - q_input_mem[n] ); + Scale_sig( &input_mem[n][0], dft_ovl, sts[n]->q_inp - q_input_mem[n] ); // Q(sts[n]->q_inp) // Scale_sig(&sts[n]->old_input_signal_fx, 1965, sts[n]->q_inp - sts[n]->q_old_inp); // sts[n]->q_old_inp = sts[n]->q_inp; q_input_mem[n] = sts[n]->q_inp; move16(); - } // check this block once + } IF( EQ_16( sts[0]->element_mode, IVAS_CPE_MDCT ) ) { - /*FOR(n = 0; n < CPE_CHANNELS; n++) - { - Scale_sig(sts[n]->old_input_signal_fx, 1965, sts[n]->q_inp - sts[n]->q_old_inp); - sts[n]->q_old_inp = sts[n]->q_inp; - }*/ - // check this block onc FOR( n = 0; n < CPE_CHANNELS; n++ ) { mdct_mem[n] = sts[n]->old_input_signal_fx; + move16(); // q_mdct_mem[n] = sts[n]->q_old_inp; } } @@ -417,8 +434,8 @@ void stereo_td_itd_fx( move16(); itd_max = shr( input_frame, 2 ); - Word16 comp_flag1 = (Word16) LE_16( extract_l( L_shr( hITD->itd_fx[k_offset], Q16 ) ), itd_max ); - Word16 comp_flag2 = (Word16) LE_16( extract_l( L_shr( hITD->itd_fx[sub( k_offset, 1 )], Q16 ) ), itd_max ); + Word16 comp_flag1 = extract_l( LE_16( extract_l( L_shr( hITD->itd_fx[k_offset], Q16 ) ), itd_max ) ); + Word16 comp_flag2 = extract_l( LE_16( extract_l( L_shr( hITD->itd_fx[sub( k_offset, 1 )], Q16 ) ), itd_max ) ); assert( ( comp_flag1 ) && "ITD value is too high!" ); assert( ( comp_flag2 ) && "ITD value is too high!" ); @@ -458,7 +475,7 @@ void stereo_td_itd_fx( } /*shift past part*/ - Copy( input_mem[ch] + shift[ch], shift_mem, size_ovl - shift[ch] ); + Copy( input_mem[ch] + shift[ch], shift_mem, sub( size_ovl, shift[ch] ) ); Copy( sts[ch]->input_fx, shift_mem + size_ovl - shift[ch], shift[ch] ); q_shift_mem = sts[ch]->q_inp; move16(); @@ -472,7 +489,7 @@ void stereo_td_itd_fx( move16(); } /*shift current part*/ - Copy( sts[ch]->input_fx + shift[ch], shift_input, input_frame - shift[ch] ); + Copy( sts[ch]->input_fx + shift[ch], shift_input, sub( input_frame, shift[ch] ) ); q_shift = sts[ch]->q_inp; move16(); @@ -505,7 +522,7 @@ void stereo_td_itd_fx( Copy( shift_mem, mdct_mem[ch], input_frame ); sts[ch]->q_old_inp = q_new_shift; move16(); - Scale_sig( mdct_mem[ch], input_frame, sub( sts[ch]->q_inp, q_shift_mem ) ); + Scale_sig( mdct_mem[ch], input_frame, sub( sts[ch]->q_inp, q_shift_mem ) ); // Q(sts[ch]->q_inp) } } } @@ -535,6 +552,7 @@ void stereo_td_itd_mdct_stereo_fx( Word16 DFT_tmp_e[CPE_CHANNELS][STEREO_DFT_N_MAX_ENC]; STEREO_MDCT_ENC_DATA_HANDLE hStereoMdct; + test(); IF( hCPE->hStereoMdct != NULL && hCPE->hStereoMdct->hItd != NULL ) { hStereoMdct = hCPE->hStereoMdct; diff --git a/lib_enc/ivas_stereo_dmx_evs.c b/lib_enc/ivas_stereo_dmx_evs.c index 1f54e0545df3bb1ffe65d9129ac4e605edf42aea..be470e2cfb2dda91d097b2709d576a3d362c3e27 100644 --- a/lib_enc/ivas_stereo_dmx_evs.c +++ b/lib_enc/ivas_stereo_dmx_evs.c @@ -55,54 +55,33 @@ #define STEREO_DMX_EVS_FIND_POC_PEAK_TAU 4 #define STEREO_DMX_EVS_FIND_POC_PEAK_TAU2 8 -#define STEREO_DMX_EVS_POC_GAMMA 0.75f -#define STEREO_DMX_EVS_POC_SMOOTH 1.25f #define STEREO_DMX_EVS_POC_SMOOTH_Q30 1342177280 -#define STEREO_DMX_EVS_POC_FORGETTING 0.78f #define STEREO_DMX_EVS_POC_FORGETTING_Q31 1675037245 -#define STEREO_DMX_EVS_TARGET_POC_FORGETTING 0.79f #define STEREO_DMX_EVS_TARGET_POC_FORGETTING_Q31 1696512082 -#define STEREO_DMX_EVS_POC_W_FORGETTING 0.875f -#define STEREO_DMX_EVS_SHIFT_LIMIT 5.625f /* ms */ -#define STEREO_DMX_EVS_SHIFT_LIMIT_Q12 23040 /* ms */ +#define STEREO_DMX_EVS_SHIFT_LIMIT_Q12 23040 /* ms */ -#define STEREO_DMX_EVS_DMX_EGY_FORGETTING 0.25f #define STEREO_DMX_EVS_DMX_EGY_FORGETTING_FX 536870912 // 0.25f in Q31 -#define STEREO_DMX_EVS_CORR_FORGETTING 0.78f #define STEREO_DMX_EVS_CORR_FORGETTING_FX 1610612736 /*Q31*/ #define STEREO_DMX_EVS_POC_W_FORGETTING_FX 1879048192 /*Q31*/ -#define Q_BAND 0.25f #define Q_BAND_FX 536870912 /*Q31*/ -#define STEREO_DMX_EVS_ISD_FORGETTING 0.95f #define STEREO_DMX_EVS_ISD_FORGETTING_Q15 31129 -#define STEREO_DMX_EVS_ISD_THRES_H 1.69f -#define STEREO_DMX_EVS_ISD_THRES_L 0.9f #define STEREO_DMX_EVS_ISD_THRES_L_Q31 1932735283 -#define STEREO_DMX_EVS_ISD_DIST_THRES_IPD 0.5f #define STEREO_DMX_EVS_ISD_DIST_THRES_IPD_Q15 ONE_IN_Q14 -#define STEREO_DMX_EVS_ISD_DIST_HYST_L 0.36f #define STEREO_DMX_EVS_ISD_DIST_HYST_L_Q15 11796 -#define STEREO_DMX_EVS_ISD_DIST_HYST_H 0.43f #define STEREO_DMX_EVS_ISD_DIST_HYST_H_Q15 14090 -#define STEREO_DMX_EVS_ICCR_FORGETTING 0.7f #define STEREO_DMX_EVS_ICCR_FORGETTING_Q31 1503238554 -#define STEREO_DMX_EVS_ICCR_HYST_L 0.75f #define STEREO_DMX_EVS_ICCR_HYST_L_Q31 1610612736 -#define STEREO_DMX_EVS_ICCR_HYST_H 0.85f #define STEREO_DMX_EVS_ICCR_HYST_H_Q31 1825361101 #define STEREO_DMX_EVS_SWTCH_HYS_THRES 1 -#define STEREO_DMX_EVS_LR_EGY 15.0f #define STEREO_DMX_EVS_LR_EGY_Q27 2013265920 -#define STEREO_DMX_EVS_ILDS_EGY 10000.0f #define STEREO_DMX_EVS_ILDS_EGY_Q17 1310720000 -#define STEREO_DMX_EVS_ILD_PRC 0.1f #define STEREO_DMX_EVS_ILD_PRC_Q15 3277 #define STEREO_DMX_EVS_SWTCH_PRC_THRES_16 55 @@ -110,15 +89,14 @@ #define STEREO_DMX_EVS_SWTCH_PRC_THRES_48 29 #define STEREO_DMX_EVS_SWTCH_PRC_HYS_THRES 1 -#define STEREO_DMX_EVS_FADE_LEN_PRC 20.0f +#define STEREO_DMX_EVS_FADE_LEN_PRC_Q0 20 -#define STEREO_DMX_EVS_NB_SBFRM 5 -#define STEREO_DMX_EVS_TRNS_DTC_INST 75.0f -#define STEREO_DMX_EVS_CRST_FCTR_16 80.0f -#define STEREO_DMX_EVS_CRST_FCTR_32 40.0f -#define STEREO_DMX_EVS_CRST_FCTR_48 35.0f +#define STEREO_DMX_EVS_NB_SBFRM 5 +#define STEREO_DMX_EVS_TRNS_DTC_INST_Q0 75 +#define STEREO_DMX_EVS_CRST_FCTR_16_Q0 80 +#define STEREO_DMX_EVS_CRST_FCTR_32_Q0 40 +#define STEREO_DMX_EVS_CRST_FCTR_48_Q0 35 -#define STEREO_DMX_EVS_TRNS_EGY_FORGETTING 0.75f #define STEREO_DMX_EVS_TRNS_EGY_FORGETTING_Q15 24576 const Word32 ipd_ff_Q31[STEREO_DMX_EVS_NB_SUBBAND_MAX] = { @@ -270,7 +248,7 @@ void estimate_itd_wnd_fft_fx( } rshift = sub( getScaleFactor32( rfft_buf, input_frame ), find_guarded_bits_fx( input_frame ) ); - scale_sig32( rfft_buf, input_frame, rshift ); + scale_sig32( rfft_buf, input_frame, rshift ); // Q(16+rshift) *spec_e = sub( 15, rshift ); move16(); rfft_fx( rfft_buf, rfft_coef, input_frame, -1 ); @@ -362,22 +340,22 @@ static void calc_poc_fx( // igamma = STEREO_DMX_EVS_POC_GAMMA * iN; IF( EQ_16( input_frame, L_FRAME16k ) ) { - igamma = 5033165; + igamma = 5033165; //(STEREO_DMX_EVS_POC_GAMMA/input_frame) in Q31 move16(); } ELSE IF( EQ_16( input_frame, L_FRAME32k ) ) { - igamma = 3355444; + igamma = 3355444; //(STEREO_DMX_EVS_POC_GAMMA/input_frame) in Q31 move16(); } ELSE IF( EQ_16( input_frame, L_FRAME48k ) ) { - igamma = 1677722; + igamma = 1677722; //(STEREO_DMX_EVS_POC_GAMMA/input_frame) in Q31 move16(); } ELSE { - igamma = 1677722; + igamma = 1677722; //(STEREO_DMX_EVS_POC_GAMMA/input_frame) in Q31 move16(); IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "invalid sample rate\n" ); } @@ -518,41 +496,41 @@ static void calc_poc_fx( FOR( ; i < n0 >> 3; i++ ) /* binary search from 8 angles */ { - tmp1 = Mpy_32_32_r( wnd[i * step + bias], gamma ); + tmp1 = Mpy_32_32_r( wnd[i * step + bias], gamma ); // Q31 IF( W_mult0_32_32( L_sub( specPOr[i], specPOi[i] ), L_add( specPOr[i], specPOi[i] ) ) > 0 ) { - specPOr[i] = Mpy_32_16_1( tmp1, imult1616( sign_fx( specPOr[i] ), /*0.923880f*/ s[120 * mult_angle] ) ); /* cos(PI/8)*/ + specPOr[i] = Mpy_32_16_1( tmp1, imult1616( sign_fx( specPOr[i] ), /*0.923880f*/ s[120 * mult_angle] ) ); /* cos(PI/8) Q31*/ move32(); - specPOi[i] = Mpy_32_16_1( tmp1, imult1616( sign_fx( specPOi[i] ), /*0.382683f*/ s[40 * mult_angle] ) ); + specPOi[i] = Mpy_32_16_1( tmp1, imult1616( sign_fx( specPOi[i] ), /*0.382683f*/ s[40 * mult_angle] ) ); // Q31 move32(); } ELSE { - specPOr[i] = Mpy_32_16_1( tmp1, imult1616( sign_fx( specPOr[i] ), /*0.382683f*/ s[40 * mult_angle] ) ); /* cos(PI*3/8)*/ + specPOr[i] = Mpy_32_16_1( tmp1, imult1616( sign_fx( specPOr[i] ), /*0.382683f*/ s[40 * mult_angle] ) ); /* cos(PI*3/8) Q31*/ move32(); - specPOi[i] = Mpy_32_16_1( tmp1, imult1616( sign_fx( specPOi[i] ), /*0.923880f*/ s[120 * mult_angle] ) ); + specPOi[i] = Mpy_32_16_1( tmp1, imult1616( sign_fx( specPOi[i] ), /*0.923880f*/ s[120 * mult_angle] ) ); // Q31 move32(); } gamma = L_sub( gamma, igamma ); } FOR( ; i < end; i++ ) /* binary search from 16 angles */ { - tmp1 = Mpy_32_32_r( wnd[i * step + bias], gamma ); + tmp1 = Mpy_32_32_r( wnd[i * step + bias], gamma ); // Q31 IF( W_mult0_32_32( L_sub( specPOr[i], specPOi[i] ), L_add( specPOr[i], specPOi[i] ) ) > 0 ) { IF( W_mult0_32_32( L_sub( Mpy_32_16_1( specPOr[i], 13573 /*0.414213f*/ ), specPOi[i] ), L_add( Mpy_32_16_1( specPOr[i], 13573 /*0.414213f*/ ), specPOi[i] ) ) > 0 ) /*tan(PI/8)*/ { - specPOr[i] = Mpy_32_16_1( tmp1 /*0.980785f */, imult1616( sign_fx( specPOr[i] ), s[140 * mult_angle] ) ); /* cos(PI/16)*/ + specPOr[i] = Mpy_32_16_1( tmp1 /*0.980785f */, imult1616( sign_fx( specPOr[i] ), s[140 * mult_angle] ) ); /* cos(PI/16) Q31*/ move32(); - specPOi[i] = Mpy_32_16_1( tmp1 /*0.195090f */, imult1616( sign_fx( specPOi[i] ), s[20 * mult_angle] ) ); + specPOi[i] = Mpy_32_16_1( tmp1 /*0.195090f */, imult1616( sign_fx( specPOi[i] ), s[20 * mult_angle] ) ); // Q31 move32(); } ELSE { - specPOr[i] = Mpy_32_16_1( tmp1 /* 0.831470f */, imult1616( sign_fx( specPOr[i] ), s[100 * mult_angle] ) ); /*cos(PI*3/16)*/ + specPOr[i] = Mpy_32_16_1( tmp1 /* 0.831470f */, imult1616( sign_fx( specPOr[i] ), s[100 * mult_angle] ) ); /*cos(PI*3/16) Q31*/ move32(); - specPOi[i] = Mpy_32_16_1( tmp1 /* 0.555570f*/, imult1616( sign_fx( specPOi[i] ), s[60 * mult_angle] ) ); + specPOi[i] = Mpy_32_16_1( tmp1 /* 0.555570f*/, imult1616( sign_fx( specPOi[i] ), s[60 * mult_angle] ) ); // Q31 move32(); } } @@ -560,16 +538,16 @@ static void calc_poc_fx( { IF( W_mult0_32_32( L_sub( specPOr[i], Mpy_32_16_1( specPOi[i], 13573 /*0.414213f*/ ) ), L_add( specPOr[i], Mpy_32_16_1( specPOi[i], 13573 /*0.414213f*/ ) ) ) > 0 ) /*tan(PI/8)*/ { - specPOr[i] = Mpy_32_16_1( tmp1 /** 0.555570f*/, imult1616( sign_fx( specPOr[i] ), s[60 * mult_angle] ) ); /*cos(PI*5/16)*/ + specPOr[i] = Mpy_32_16_1( tmp1 /** 0.555570f*/, imult1616( sign_fx( specPOr[i] ), s[60 * mult_angle] ) ); /*cos(PI*5/16) Q31*/ move32(); - specPOi[i] = Mpy_32_16_1( tmp1 /** 0.831470f*/, imult1616( sign_fx( specPOi[i] ), s[100 * mult_angle] ) ); + specPOi[i] = Mpy_32_16_1( tmp1 /** 0.831470f*/, imult1616( sign_fx( specPOi[i] ), s[100 * mult_angle] ) ); // Q31 move32(); } ELSE { - specPOr[i] = Mpy_32_16_1( tmp1 /** 0.195090f*/, imult1616( sign_fx( specPOr[i] ), s[20 * mult_angle] ) ); /*cos(PI*7/16)*/ + specPOr[i] = Mpy_32_16_1( tmp1 /** 0.195090f*/, imult1616( sign_fx( specPOr[i] ), s[20 * mult_angle] ) ); /*cos(PI*7/16) Q31*/ move32(); - specPOi[i] = Mpy_32_16_1( tmp1 /** 0.980785f*/, imult1616( sign_fx( specPOi[i] ), s[140 * mult_angle] ) ); + specPOi[i] = Mpy_32_16_1( tmp1 /** 0.980785f*/, imult1616( sign_fx( specPOi[i] ), s[140 * mult_angle] ) ); // Q31 move32(); } } @@ -587,11 +565,12 @@ static void calc_poc_fx( specPOi[i] = 0; move32(); } - specPOr[n0] = imult3216( Mpy_32_32_r( wnd[i * step + bias], gamma ), sign_fx( Mpy_32_32_r( specLr[n0], specRr[n0] ) ) ); + specPOr[n0] = imult3216( Mpy_32_32_r( wnd[i * step + bias], gamma ), sign_fx( Mpy_32_32_r( specLr[n0], specRr[n0] ) ) ); // Q31 move32(); hPHA->init_frmCntr = sub( hPHA->init_frmCntr, 1 ); + move16(); if ( hPHA->init_frmCntr < 0 ) { hPHA->init_frmCntr = 0; @@ -629,11 +608,11 @@ static void calc_poc_fx( Dr = L_add( specLr[i], specRr[i] ); // spec_e Di = L_add( specLi[i], specRi[i] ); // spec_e // if ( ( Nr * Nr + Ni * Ni ) > STEREO_DMX_EVS_ISD_THRES_H * ( Dr * Dr + Di * Di ) ) - if ( GT_32( Mpy_32_32_r( L_add( Mpy_32_32_r( Nr, Nr ), Mpy_32_32_r( Ni, Ni ) ), 1270700383 ), L_add( Mpy_32_32_r( Dr, Dr ), Mpy_32_32_r( Di, Di ) ) ) ) + IF( GT_32( Mpy_32_32_r( L_add( Mpy_32_32_r( Nr, Nr ), Mpy_32_32_r( Ni, Ni ) ), 1270700383 /*1/STEREO_DMX_EVS_ISD_THRES_H in Q31*/ ), L_add( Mpy_32_32_r( Dr, Dr ), Mpy_32_32_r( Di, Di ) ) ) ) { isd_cnt_h = add( isd_cnt_h, 1 ); } - if ( LT_32( L_add( Mpy_32_32_r( Nr, Nr ), Mpy_32_32_r( Ni, Ni ) ), Mpy_32_32_r( STEREO_DMX_EVS_ISD_THRES_L_Q31, L_add( Mpy_32_32_r( Dr, Dr ), Mpy_32_32_r( Di, Di ) ) ) ) ) + IF( LT_32( L_add( Mpy_32_32_r( Nr, Nr ), Mpy_32_32_r( Ni, Ni ) ), Mpy_32_32_r( STEREO_DMX_EVS_ISD_THRES_L_Q31, L_add( Mpy_32_32_r( Dr, Dr ), Mpy_32_32_r( Di, Di ) ) ) ) ) { isd_cnt_l = add( isd_cnt_l, 1 ); } @@ -826,8 +805,8 @@ static void calc_poc_fx( ICCr = L_shl_sat( ICCr, L_tmp_e ); // Q31 // hPHA->iccr_s = STEREO_DMX_EVS_ICCR_FORGETTING * hPHA->iccr_s + ( 1.0f - STEREO_DMX_EVS_ICCR_FORGETTING ) * ICCr; - hPHA->iccr_s_fx = L_add( Mpy_32_32_r( STEREO_DMX_EVS_ICCR_FORGETTING_Q31, hPHA->iccr_s_fx ), Mpy_32_32_r( MAX_32 - STEREO_DMX_EVS_ICCR_FORGETTING_Q31, ICCr ) ); - move16(); + hPHA->iccr_s_fx = L_add( Mpy_32_32_r( STEREO_DMX_EVS_ICCR_FORGETTING_Q31, hPHA->iccr_s_fx ), Mpy_32_32_r( MAX_32 - STEREO_DMX_EVS_ICCR_FORGETTING_Q31, ICCr ) ); // Q31 + move32(); IF( EQ_32( hPHA->curr_pha, STEREO_DMX_EVS_PHA_IPD ) ) { @@ -935,7 +914,7 @@ static void calc_poc_fx( rfft_pha_buf[i * 2 + 1] = imult3216( L_shl_r( L_tmp, sub( L_tmp_e, 9 ) ), sign_fx( rfft_pha_buf[i * 2 + 1] ) ); // Q22 move32(); // rfft_pha_buf[i * 2] = (float) sqrt( ( 1.0f + rfft_pha_buf[i * 2] ) / 2.0f ); - L_tmp = L_add( ONE_IN_Q21, L_shr( rfft_pha_buf[i * 2], 1 ) ); + L_tmp = L_add( ONE_IN_Q21, L_shr( rfft_pha_buf[i * 2], 1 ) ); // Q22 L_tmp_e = 9; move16(); L_tmp = Sqrt32( L_tmp, &L_tmp_e ); @@ -1082,7 +1061,7 @@ static void calc_poc_fx( move32(); } - tmp1 = L_shl( Mpy_32_32_r( STEREO_DMX_EVS_POC_SMOOTH_Q30, tmpPOC1[n0] ) + Mpy_32_32_r( -ONE_IN_Q28 /*0.5f * ( 1.0f - STEREO_DMX_EVS_POC_SMOOTH )*/, L_add( L_shr( tmpPOC1[n0 - 1], 1 ), L_shr( tmpPOC1[n0 + 1], 1 ) ) ), 1 ); // Q31 + tmp1 = L_shl( L_add( Mpy_32_32_r( STEREO_DMX_EVS_POC_SMOOTH_Q30, tmpPOC1[n0] ), Mpy_32_32_r( -ONE_IN_Q28 /*0.5f * ( 1.0f - STEREO_DMX_EVS_POC_SMOOTH )*/, L_add( L_shr( tmpPOC1[n0 - 1], 1 ), L_shr( tmpPOC1[n0 + 1], 1 ) ) ) ), 1 ); // Q31 tmpPOC2[n0] = L_max( tmp1, 0 ); move32(); @@ -1142,9 +1121,9 @@ static void calc_poc_fx( *-------------------------------------------------------------------*/ static Word32 find_poc_peak_fx( STEREO_DMX_EVS_POC_HANDLE hPOC, /* i/o: phase only correlation structure */ - Word32 itd_fx[], /* o : estimated itd */ + Word32 itd_fx[], /* o : estimated itd Q16 */ const Word16 input_frame, /* i : input frame length per channel */ - const Word32 ratio_fixed /* i : adapting ratio */ + const Word32 ratio_fixed /* i : adapting ratio Q31 */ ) { Word16 itd_cand[CPE_CHANNELS], i, n, cnt[CPE_CHANNELS], Lh, peak_range, *on, *itdLR, prev_off[CPE_CHANNELS], eps_fx; @@ -1161,16 +1140,13 @@ static Word32 find_poc_peak_fx( itd_cand[0] = itd_cand[1] = 0; move16(); move16(); - move16(); - move16(); width_fx = 816043776; /*0.38f in Q31*/ eps_fx = Inv16( input_frame, &eps_e ); peak_width_fx = hPOC->peak_width_fx; peakQ_fx = hPOC->peakQ_fx; // Q16 move16(); - move16(); - move16(); + set16_fx( peakQ_e, 31 - Q16, CPE_CHANNELS ); Q_fx[0] = hPOC->P_fx[Lh]; // Q31 Q_fx[1] = 0; @@ -1203,6 +1179,7 @@ static Word32 find_poc_peak_fx( } Word16 tmp1, tmp11, tmp_var1, tmp12 = 0, tmp13; + move16(); Word32 tmp4, tmp5, tmp6, tmp7, tmp8, tmp9, tmp10, tmp14, tmp15, tmp16; Word16 tmp8_e, tmp9_e, tmp10_e, tmp11_e, tmp12_e, tmp13_e, tmp15_e; @@ -1228,7 +1205,7 @@ static Word32 find_poc_peak_fx( /*compute peak_range*/ tmp1 = idiv1616( hPOC->shift_limit, STEREO_DMX_EVS_FIND_POC_PEAK_TAU ); - peak_range = idiv1616( add( (Word16) abs( itd_cand[n] ), tmp1 ), STEREO_DMX_EVS_FIND_POC_PEAK_TAU2 ); // Q0 + peak_range = idiv1616( add( extract_l( abs( itd_cand[n] ) ), tmp1 ), STEREO_DMX_EVS_FIND_POC_PEAK_TAU2 ); // Q0 FOR( i = 1; i <= peak_range; i++ ) { @@ -1236,7 +1213,7 @@ static Word32 find_poc_peak_fx( tmp4 = L_add( P_fx[Lh - itd_cand[n] + i], P_fx[Lh - itd_cand[n] - i] ); // Q31 cQ_fx[n] = L_add( cQ_fx[n], tmp4 ); move16(); - move16(); + move32(); } /*compute eps2_fx*/ @@ -1374,9 +1351,17 @@ static Word32 find_poc_peak_fx( test(); test(); test(); + test(); IF( ( on[0] && prev_off[0] ) && ( on[1] && prev_off[1] ) ) /*if both channels have newly detected as active (possibility of preceding), select channel by peakness Q[] of POC */ { - *itd_fx = ( GT_32( Q_fx[0], Q_fx[1] ) ) ? itdLR[0] : itdLR[1]; + IF( GT_32( Q_fx[0], Q_fx[1] ) ) + { + *itd_fx = itdLR[0]; + } + ELSE + { + *itd_fx = itdLR[1]; + } } ELSE IF( ( on[0] && prev_off[0] ) && ( EQ_16( var0_flag, 1 ) ) ) /* if channel 0 becomes active, select channel 0*/ { @@ -1400,7 +1385,14 @@ static Word32 find_poc_peak_fx( } ELSE /*follow the status of the previous frame*/ { - *itd_fx = ( *itd_fx > 0 ) ? itdLR[0] : itdLR[1]; + IF( *itd_fx > 0 ) + { + *itd_fx = itdLR[0]; + } + ELSE + { + *itd_fx = itdLR[1]; + } } move32(); @@ -1420,12 +1412,12 @@ static Word32 find_poc_peak_fx( Word32 Q_sub_sqrt = Sqrt32( L_abs( L_sub( Q_fx[0], Q_fx[1] ) ), &Q_sub_sqrt_e ); cconfidence_fx = Q_sub_sqrt; move16(); - move16(); + move32(); Word32 cconfidence_var1 = Mpy_32_32( hPOC->confidence_fx, STEREO_DMX_EVS_CORR_FORGETTING_FX ); // Q31 Word32 cconfidence_var2 = Mpy_32_32( L_shr( cconfidence_fx, negate( Q_sub_sqrt_e ) ) /*Q31*/, L_sub( ONE_IN_Q30, L_shr( STEREO_DMX_EVS_CORR_FORGETTING_FX, 1 ) ) ); // Q30 hPOC->confidence_fx = L_add( cconfidence_var1, L_shl( cconfidence_var2, 1 ) ); // Q31 - move16(); + move32(); return hPOC->confidence_fx; } @@ -1497,11 +1489,11 @@ static ivas_error estimate_itd_fx( spec_e = s_max( sub( specL_e, s_min( getScaleFactor32( specLr, input_frame / 2 + 1 ), getScaleFactor32( specLi, input_frame / 2 + 1 ) ) ), sub( specR_e, s_min( getScaleFactor32( specRr, input_frame / 2 + 1 ), getScaleFactor32( specRi, input_frame / 2 + 1 ) ) ) ); - spec_e = add( spec_e, 2 ); // guard bits - scale_sig32( specLr, input_frame / 2 + 1, sub( specL_e, spec_e ) ); - scale_sig32( specLi, input_frame / 2 + 1, sub( specL_e, spec_e ) ); - scale_sig32( specRr, input_frame / 2 + 1, sub( specR_e, spec_e ) ); - scale_sig32( specRi, input_frame / 2 + 1, sub( specR_e, spec_e ) ); + spec_e = add( spec_e, 2 ); // guard bits + scale_sig32( specLr, add( shr( input_frame, 1 ), 1 ), sub( specL_e, spec_e ) ); // Q(31-(specL_e-spec_e)) + scale_sig32( specLi, add( shr( input_frame, 1 ), 1 ), sub( specL_e, spec_e ) ); // Q(31-(specL_e-spec_e)) + scale_sig32( specRr, add( shr( input_frame, 1 ), 1 ), sub( specR_e, spec_e ) ); // Q(31-(specR_e-spec_e)) + scale_sig32( specRi, add( shr( input_frame, 1 ), 1 ), sub( specR_e, spec_e ) ); // Q(31-(specR_e-spec_e)) calc_poc_fx( hPOC, hPHA, hPOC->wnd_fx, rfft_coef, specLr, specLi, specRr, specRi, spec_e, input_frame ); @@ -1571,20 +1563,20 @@ static void calc_energy_fx( move32(); wnd_diff_fx = 107374182; // initialising for L_FRAME16k =( 1.0f /20) in Q31; move32(); - switch ( input_frame ) + SWITCH( input_frame ) { case L_FRAME16k: wnd_fx = 53687091; // wnd = 0.5f / (float) adaptlen; adaptlen= 20;in Q31 wnd_diff_fx = 107374182; // wnd = 1.0f / (float) adaptlen;adaptlen= 20;in Q31 - break; + BREAK; case L_FRAME32k: wnd_fx = 26843545; // wnd = 0.5f / (float) adaptlen; adaptlen= 40;in Q31 wnd_diff_fx = 53687091; // wnd = 1.0f / (float) adaptlen;adaptlen= 40;in Q31 - break; + BREAK; case L_FRAME48k: wnd_fx = 17895697; // wnd = 0.5f / (float) adaptlen; adaptlen= 60;in Q31 wnd_diff_fx = 35791394; // wnd = 1.0f / (float) adaptlen;adaptlen= 60;in Q31 - break; + BREAK; } move32(); move32(); @@ -1622,7 +1614,7 @@ static void calc_energy_fx( q_temp32 = add( add( q_E, sub( 15, temp_e ) ), 16 ); // *energy = *energy * ratio_float + ( E / (float) input_frame ) * ( 1.0f - ratio_float ); *energy_fx = BASOP_Util_Add_Mant32Exp( Mpy_32_32( *energy_fx, ratio_float_fx ), *energy_fx_e, Mpy_32_32( temp32, L_sub( MAX_32, ratio_float_fx ) ), sub( 31, q_temp32 ), energy_fx_e ); - + move32(); return; } @@ -1633,7 +1625,7 @@ static void calc_energy_fx( *-------------------------------------------------------------------*/ static void adapt_gain_fx( const Word32 src_fx[], /* i : input signal Q16 */ - Word32 dst_fx[], /* o : output signal */ + Word32 dst_fx[], /* o : output signal Q16 */ const Word32 gain_fx, /* i : adapting gain Q31*/ const Word32 old_gain_fx, /* i : adapting prev gain Q31*/ const Word16 input_frame, /* i : input frame length per channel */ @@ -1877,7 +1869,7 @@ void stereo_dmx_evs_enc_fx( W_tmp = W_mult_32_32( p_sub_frame[n], p_sub_frame[n] ); W_tmp_q = W_norm( W_tmp ); W_tmp = W_shl( W_tmp, W_tmp_q ); - L_tmp1 = W_extract_h( W_tmp ); + L_tmp1 = W_extract_h( W_tmp ); // Q(31-(30-W_tmp_q)) L_tmp1_e = sub( 15 * 2, W_tmp_q ); subframe_energy[m] = BASOP_Util_Add_Mant32Exp( subframe_energy[m], subframe_energy_e[m], L_tmp1, L_tmp1_e, &subframe_energy_e[m] ); move32(); @@ -1915,7 +1907,7 @@ void stereo_dmx_evs_enc_fx( L_tmp2 = BASOP_Util_Divide3232_Scale_cadence( subframe_energy[m], L_tmp1, &L_tmp2_e ); L_tmp2_e = add( L_tmp2_e, sub( subframe_energy_e[m], L_tmp1_e ) ); // if ( subframe_energy[m] / ( subframe_energy[m - 1] + EPSILON ) > STEREO_DMX_EVS_TRNS_DTC_INST ) - if ( BASOP_Util_Cmp_Mant32Exp( L_tmp2, L_tmp2_e, (Word16) STEREO_DMX_EVS_TRNS_DTC_INST, 31 ) > 0 ) + if ( BASOP_Util_Cmp_Mant32Exp( L_tmp2, L_tmp2_e, STEREO_DMX_EVS_TRNS_DTC_INST_Q0, 31 ) > 0 ) { is_transient = 1; move16(); @@ -2101,7 +2093,7 @@ void stereo_dmx_evs_enc_fx( move16(); } - IF( hStereoDmxEVS->hPHA->curr_prc == STEREO_DMX_EVS_PRC_POC ) + IF( EQ_32( hStereoDmxEVS->hPHA->curr_prc, STEREO_DMX_EVS_PRC_POC ) ) { p_dmx_data = dmx_poc_data; @@ -2140,7 +2132,7 @@ void stereo_dmx_evs_enc_fx( } } - Copy_Scale_sig32_16( p_dmx_data, data, n_samples, 5 ); + Copy_Scale_sig32_16( p_dmx_data, data, n_samples, 5 ); // Q11->Q0 return; @@ -2293,16 +2285,16 @@ ivas_error stereo_dmx_evs_init_encoder_fx( SWITCH( input_frame ) { case 160: - hStereoDmxEVS->hPOC->eps_fx = 84331486; + hStereoDmxEVS->hPOC->eps_fx = 84331486; // (2.0f * EVS_PI / (160)) in Q31 BREAK; case 320: - hStereoDmxEVS->hPOC->eps_fx = 42165743; + hStereoDmxEVS->hPOC->eps_fx = 42165743; // (2.0f * EVS_PI / (160)) in Q31 BREAK; case 640: - hStereoDmxEVS->hPOC->eps_fx = 21082871; + hStereoDmxEVS->hPOC->eps_fx = 21082871; // (2.0f * EVS_PI / (160)) in Q31 BREAK; case 960: - hStereoDmxEVS->hPOC->eps_fx = 14055248; + hStereoDmxEVS->hPOC->eps_fx = 14055248; // (2.0f * EVS_PI / (160)) in Q31 BREAK; } move32(); @@ -2350,7 +2342,7 @@ ivas_error stereo_dmx_evs_init_encoder_fx( move16(); hStereoDmxEVS->hPHA->prc_thres = STEREO_DMX_EVS_SWTCH_PRC_THRES_16; move16(); - hStereoDmxEVS->hPHA->crst_fctr_fx = (Word16) STEREO_DMX_EVS_CRST_FCTR_16; + hStereoDmxEVS->hPHA->crst_fctr_fx = STEREO_DMX_EVS_CRST_FCTR_16_Q0; move32(); } ELSE IF( EQ_32( input_Fs, 32000 ) ) @@ -2361,7 +2353,7 @@ ivas_error stereo_dmx_evs_init_encoder_fx( move16(); hStereoDmxEVS->hPHA->prc_thres = STEREO_DMX_EVS_SWTCH_PRC_THRES_32; move16(); - hStereoDmxEVS->hPHA->crst_fctr_fx = (Word16) STEREO_DMX_EVS_CRST_FCTR_32; + hStereoDmxEVS->hPHA->crst_fctr_fx = STEREO_DMX_EVS_CRST_FCTR_32_Q0; move32(); } ELSE IF( EQ_32( input_Fs, 48000 ) ) @@ -2372,7 +2364,7 @@ ivas_error stereo_dmx_evs_init_encoder_fx( move16(); hStereoDmxEVS->hPHA->prc_thres = STEREO_DMX_EVS_SWTCH_PRC_THRES_48; move16(); - hStereoDmxEVS->hPHA->crst_fctr_fx = (Word16) STEREO_DMX_EVS_CRST_FCTR_48; + hStereoDmxEVS->hPHA->crst_fctr_fx = STEREO_DMX_EVS_CRST_FCTR_48_Q0; move32(); } ELSE @@ -2397,14 +2389,15 @@ ivas_error stereo_dmx_evs_init_encoder_fx( trans_len = idiv1616( pha_len, 20 ); set16_fx( hStereoDmxEVS->hPHA->win_fx, 29491 /*1.8f in Q15*/, sub( pha_len, trans_len ) ); hStereoDmxEVS->hPHA->win_fx[0] = ONE_IN_Q14; + move16(); // tmp_r = 1.0f / ( ( trans_len * 2 ) + 1 ); tmp_r = div_s( 1, add( shl( trans_len, 1 ), 1 ) ); win = &( hStereoDmxEVS->hPHA->win_fx[pha_len - trans_len] ); FOR( n = 0; n < trans_len; n++ ) { // win[n] = ( 0.5f * ( 1.0f + cosf( ( PI2 * ( n + 1 ) ) * tmp_r ) ) ) * 1.8f; - win[n] = mult_r( add( ONE_IN_Q14, getCosWord16R2( imult1616( add( n, 1 ), tmp_r ) ) ), 29491 ); - move32(); + win[n] = mult_r( add( ONE_IN_Q14, getCosWord16R2( imult1616( add( n, 1 ), tmp_r ) ) ), 29491 /*1.8/2 in Q15*/ ); + move16(); } fad_g = hStereoDmxEVS->hPHA->fad_g_fx; @@ -2412,7 +2405,7 @@ ivas_error stereo_dmx_evs_init_encoder_fx( fad_r = BASOP_Util_Divide3232_Scale_cadence( 1, add( fad_len, 1 ), &tmp_e ); fad_r = L_shl_r( fad_r, tmp_e ); fad_len2 = shr( fad_len, 1 ); - FOR( ( n = 0, m = sub( fad_len, 1 ) ); n < fad_len2; ( n++, m-- ) ) + FOR( ( n = 0, m = ( fad_len - 1 ) ); n < fad_len2; ( n++, m-- ) ) { fad_g[n] = imult3216( fad_r, add( n, 1 ) ); move32(); @@ -2504,19 +2497,19 @@ ivas_error stereo_dmx_evs_init_encoder_fx( SWITCH( input_Fs ) { case 8000: - hStereoDmxEVS->hPHA->fad_len_prc = (Word16) STEREO_DMX_EVS_FADE_LEN_PRC * 8; + hStereoDmxEVS->hPHA->fad_len_prc = STEREO_DMX_EVS_FADE_LEN_PRC_Q0 * 8; move16(); BREAK; case 16000: - hStereoDmxEVS->hPHA->fad_len_prc = (Word16) STEREO_DMX_EVS_FADE_LEN_PRC * 16; + hStereoDmxEVS->hPHA->fad_len_prc = STEREO_DMX_EVS_FADE_LEN_PRC_Q0 * 16; move16(); BREAK; case 32000: - hStereoDmxEVS->hPHA->fad_len_prc = (Word16) STEREO_DMX_EVS_FADE_LEN_PRC * 32; + hStereoDmxEVS->hPHA->fad_len_prc = STEREO_DMX_EVS_FADE_LEN_PRC_Q0 * 32; move16(); BREAK; case 48000: - hStereoDmxEVS->hPHA->fad_len_prc = (Word16) STEREO_DMX_EVS_FADE_LEN_PRC * 48; + hStereoDmxEVS->hPHA->fad_len_prc = STEREO_DMX_EVS_FADE_LEN_PRC_Q0 * 48; move16(); BREAK; default: @@ -2530,7 +2523,7 @@ ivas_error stereo_dmx_evs_init_encoder_fx( fad_r = BASOP_Util_Divide3232_Scale_cadence( 1, add( fad_len, 1 ), &tmp_e ); fad_r = L_shl_r( fad_r, tmp_e ); fad_len2 = shr( fad_len, 1 ); - FOR( ( n = 0, m = sub( fad_len, 1 ) ); n < fad_len2; ( n++, m-- ) ) + FOR( ( n = 0, m = ( fad_len - 1 ) ); n < fad_len2; ( n++, m-- ) ) { fad_g[n] = imult3216( fad_r, add( n, 1 ) ); move32(); diff --git a/lib_enc/ivas_stereo_eclvq_enc.c b/lib_enc/ivas_stereo_eclvq_enc.c index b8ac4829895b24f96417694a25b241632bd0a31c..ac716bf3a806066734561547303353d041abb23e 100644 --- a/lib_enc/ivas_stereo_eclvq_enc.c +++ b/lib_enc/ivas_stereo_eclvq_enc.c @@ -69,7 +69,7 @@ static Word16 get_sign_fx( Word16 n ) * * ---------------------------------------------------------------*/ void ECSQ_quantize_vector_fx( - const Word32 *input, + const Word32 *input, // Q(31-input_e) const Word16 input_e, const Word32 global_gain, // Q15 const Word16 N, @@ -111,7 +111,7 @@ void ECSQ_quantize_vector_fx( * if all the values in output are zero, it returns 0 * ---------------------------------------------------------------*/ Word32 ECSQ_compute_optimal_gain_fx( // Q15 - const Word32 *input, + const Word32 *input, // Q(31-input_e) const Word16 input_e, const Word16 N, const Word16 *output ) @@ -282,7 +282,7 @@ static void arith_encode_bit_prob_fx( IF( ecsq_inst->encoding_active ) { /* call to the actual AC */ - rc_uni_enc_encode_fast( rc_st_enc, bit * count0, count, 14 ); + rc_uni_enc_encode_fast( rc_st_enc, u_extract_l( L_mult0( bit, count0 ) ), count, 14 ); } return; @@ -314,7 +314,7 @@ static void arith_encode_prob_fx( IF( ecsq_inst->encoding_active ) { /* call to the actual AC */ - rc_uni_enc_encode_fast( rc_st_enc, ECSQ_PROB_TOTAL - table[symbol], count, 14 ); + rc_uni_enc_encode_fast( rc_st_enc, u_extract_l( UL_subNsD( ECSQ_PROB_TOTAL, table[symbol] ) ), count, 14 ); } return; @@ -351,7 +351,7 @@ static void arith_encode_elias_mod_fx( arith_encode_bit_fx( ecsq_inst, 1 ); /* encode the n_bits data bits at once */ - arith_encode_bits_fx( ecsq_inst, n - ( 1 << n_bits ), n_bits ); + arith_encode_bits_fx( ecsq_inst, u_extract_l( L_sub( n, ( shl( 1, n_bits ) ) ) ), n_bits ); } return; @@ -419,8 +419,7 @@ static Word16 get_best_param_fx( sum_abs = L_add( sum_abs, L_shl( abs_s( val ), 10 ) ); // Q10 IF( val == 0 ) { - ++count0; - move16(); + count0 = add( count0, 1 ); } } @@ -550,7 +549,7 @@ static Word32 ECSQ_encode_raw_fx( Word16 *input, const Word16 N ) { - int32_t bit_count_estimate_initial; + Word32 bit_count_estimate_initial; Word32 total_size; // Q10 Word16 segment_count; @@ -570,7 +569,7 @@ static Word32 ECSQ_encode_raw_fx( const UWord16 *tab_vals, *tab_abs_lsbs; bit_count_estimate_initial = ecsq_inst->bit_count_estimate; - + move32(); total_size = 0; move32(); @@ -609,7 +608,7 @@ static Word32 ECSQ_encode_raw_fx( FOR( param = first_param; param <= last_param; ++param ) { param_zb = sub( param, ECSQ_ALL_ZERO_PARAM ); - count = ECSQ_tab_param[ecsq_inst->config_index][param_zb] - ECSQ_tab_param[ecsq_inst->config_index][param_zb + 1]; + count = sub( ECSQ_tab_param[ecsq_inst->config_index][param_zb], ECSQ_tab_param[ecsq_inst->config_index][param_zb + 1] ); // test_size = scale_Q10 * code_length_from_count( count ); test_size = code_length_from_count_fx( count ); // Q10 @@ -625,6 +624,7 @@ static Word32 ECSQ_encode_raw_fx( } best_params[segment] = best_param; + move16(); total_size = L_add( total_size, best_size ); } @@ -643,6 +643,7 @@ static Word32 ECSQ_encode_raw_fx( seg_start = imult1616( segment, ECSQ_SEGMENT_SIZE ); seg_stop = add( seg_start, ECSQ_SEGMENT_SIZE - 1 ); seg_length = ECSQ_SEGMENT_SIZE; + move16(); IF( EQ_16( segment, sub( segment_count, 1 ) ) ) { seg_stop = sub( N, 1 ); @@ -758,7 +759,7 @@ static Word32 ECSQ_encode_raw_fx( Word32 ECSQ_encode_target_SNR_fx( ECSQ_instance *ecsq_inst, - const Word32 *input, + const Word32 *input, // Q(31-input_e) const Word16 input_e, const Word16 N, const Word32 target_SNR, // Q25 @@ -791,6 +792,7 @@ Word32 ECSQ_encode_target_SNR_fx( { /* a target SNR of 0.0 dB is already achieved by quantizing all values in the vector to zero */ *global_gain_index_output = ECSQ_GLOBAL_GAIN_INDEX_ALL_ZERO; + move16(); IF( output != NULL ) { set32_fx( output, 0, N ); @@ -876,9 +878,9 @@ Word32 ECSQ_encode_target_SNR_fx( test_size = ECSQ_encode_raw_fx( ecsq_inst, quantized_input, N ); - ++iteration; - move16(); + iteration = add( iteration, 1 ); Word16 tmp_e; + test(); WHILE( GT_32( test_size, max_bits_fixpt ) && LT_16( iteration, ECSQ_MAX_BITS_ITERATIONS ) ) { test(); @@ -903,8 +905,7 @@ Word32 ECSQ_encode_target_SNR_fx( test_size = ECSQ_encode_raw_fx( ecsq_inst, quantized_input, N ); - ++iteration; - move16(); + iteration = add( iteration, 1 ); } IF( GT_32( test_size, max_bits_fixpt ) ) @@ -922,7 +923,7 @@ Word32 ECSQ_encode_target_SNR_fx( /* do the quantization with the dequantized final global_gain_index found */ global_gain = ECSQ_dequantize_gain_fx( global_gain_index ); // Q15 - IF( global_gain_index != global_gain_index_last ) + IF( NE_16( global_gain_index, global_gain_index_last ) ) { ECSQ_quantize_vector_fx( input, input_e, global_gain, N, quantized_input ); } diff --git a/lib_enc/spec_flatness_fx.c b/lib_enc/spec_flatness_fx.c index a4e5f39fc2862ce2321c95fd671f7c28f29a0af7..a495ad681743bb6d4a0dd2a7caa9bb37f43c0abd 100644 --- a/lib_enc/spec_flatness_fx.c +++ b/lib_enc/spec_flatness_fx.c @@ -104,7 +104,8 @@ void spec_flatness_fx( IF( GE_16( prods_Q, 34 ) ) { prods = L_shr( prods, sub( prods_Q, 33 ) ); - zerop1 = L_shr( CNT0P1, 1 ); + zerop1 = CNT0P1 >> 1; + move32(); prods_Q = 33; move16(); } @@ -116,7 +117,8 @@ void spec_flatness_fx( } prods = L_add( prods, zerop1 ); - zerop1 = L_shr( CNT0P1, 20 ); + zerop1 = CNT0P1 >> 20; + move32(); sums = L_add( sums, zerop1 ); /*div*/ @@ -188,7 +190,8 @@ void spec_flatness_fx( IF( GE_16( prods_Q, 34 ) ) { prods = L_shr( prods, sub( prods_Q, 33 ) ); - zerop1 = L_shr( CNT0P1, 1 ); + zerop1 = CNT0P1 >> 1; + move32(); prods_Q = 33; move16(); } @@ -200,7 +203,8 @@ void spec_flatness_fx( } prods = L_add( prods, zerop1 ); - zerop1 = L_shr( CNT0P1, 20 ); + zerop1 = CNT0P1 >> 20; + move32(); sums = L_add( sums, zerop1 ); /*div*/ @@ -271,7 +275,8 @@ void spec_flatness_fx( IF( GE_16( prods_Q, 34 ) ) { prods = L_shr( prods, sub( prods_Q, 33 ) ); - zerop1 = L_shr( CNT0P1, 1 ); + zerop1 = CNT0P1 >> 1; + move32(); prods_Q = 33; move16(); } @@ -283,7 +288,8 @@ void spec_flatness_fx( } prods = L_add( prods, zerop1 ); - zerop1 = L_shr( CNT0P1, 20 ); + zerop1 = CNT0P1 >> 20; + move32(); sums = L_add( sums, zerop1 ); /*div*/ diff --git a/lib_enc/speech_music_classif_fx.c b/lib_enc/speech_music_classif_fx.c index 52f793cf2ae2d9127e9a791c24a55eb6679f7f03..41e1cfeba88209cbf343d9b4a001df70b3c9aeae 100644 --- a/lib_enc/speech_music_classif_fx.c +++ b/lib_enc/speech_music_classif_fx.c @@ -89,7 +89,7 @@ void speech_music_clas_init_fx( SP_MUS_CLAS_HANDLE hSpMusClas /* i/o: speech/music classifier handle */ ) { - int16_t i; + Word16 i; hSpMusClas->inact_cnt = 0; @@ -203,11 +203,14 @@ void speech_music_clas_init_fx( hSpMusClas->lt_dec_thres_fx = 5120; move16(); /*10 in Q9 */ hSpMusClas->ener_RAT_fx = 0; + move16(); /* speech/music classification */ set16_fx( hSpMusClas->lt_old_mode, 1, 3 ); hSpMusClas->lt_voicing = 16384 /*0.5f Q15*/; + move16(); hSpMusClas->lt_corr = 16384 /*0.5f Q15*/; + move16(); hSpMusClas->lt_tonality = 0; move32(); set16_fx( hSpMusClas->lt_corr_pitch, 0, 3 ); @@ -510,13 +513,13 @@ void speech_music_classif_fx( } st->sp_aud_decision0 = st->sp_aud_decision1; - + move16(); /* 2nd stage speech/music classifier (rewrite music to speech in onsets) */ st->sp_aud_decision2 = st->sp_aud_decision1; move16(); - IF( GT_16( st->bwidth, NB ) ) + IF( st->bwidth > NB ) { sp_mus_classif_2nd_fx( st, Etot, attack_flag, inp, Q_inp - 1 ); @@ -582,8 +585,6 @@ void speech_music_classif_fx( /* Select AUDIO frames */ test(); test(); - test(); - test(); #ifdef DEBUGGING if ( st->codec_mode == MODE1 && ( st->force == 1 || ( st->force == -1 && ( st->sp_aud_decision2 || st->GSC_noisy_speech ) ) ) ) #else @@ -599,6 +600,7 @@ void speech_music_classif_fx( ELSE { st->sp_aud_decision0 = st->sp_aud_decision1; + move16(); } @@ -649,14 +651,29 @@ static Word16 sp_mus_classif_gmm_fx( /* o : decis Word32 dPS[128], PS_norm[128]; Word32 lepsP1; Word32 max_s = 0, max_m = 0, py_s, py_m; + move32(); + move32(); Word32 max_n, py_n; /* pyn */ Word16 ishift[12] = { 8, 0, 2, 2, 2, 2, 2, 1, 0, 2, 2, 1 }; + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); Word16 tmp; Word16 tmp1, tmp2, exp2, scale, exp3; SP_MUS_CLAS_HANDLE hSpMusClas = st_fx->hSpMusClas; HQ_ENC_HANDLE hHQ_core = st_fx->hHQ_core; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move16(); #endif /*------------------------------------------------------------------* @@ -685,6 +702,7 @@ static Word16 sp_mus_classif_gmm_fx( /* o : decis ELSE { *pFV++ = round_fx( L_tmp ); + move16(); } /* [1] voicing Q15 */ @@ -701,6 +719,7 @@ static Word16 sp_mus_classif_gmm_fx( /* o : decis L_tmp = L_mac( L_tmp, st_fx->voicing_fx[1], 10923 ); L_tmp = L_mac( L_tmp, st_fx->voicing_fx[2], 10923 ); *pFV++ = round_fx_sat( L_tmp ); + move16(); } /* [2,3,4,5,6] LSFs Q15*/ @@ -723,11 +742,13 @@ static Word16 sp_mus_classif_gmm_fx( /* o : decis /* [7] cor_map_sum Q8 */ *pFV++ = round_fx( L_mac( L_mult( cor_map_sum, 16384 ), hSpMusClas->last_cor_map_sum_fx, 16384 ) ); /* Q8 ->Q7*/ + move16(); hSpMusClas->last_cor_map_sum_fx = cor_map_sum; move16(); /* [8] non_sta Q8*/ *pFV++ = round_fx( L_mac( L_mult( non_sta, 16384 ), hSpMusClas->last_non_sta_fx, 16384 ) ); /* Q8 -> Q7 */ + move16(); hSpMusClas->last_non_sta_fx = non_sta; move16(); @@ -875,7 +896,6 @@ static Word16 sp_mus_classif_gmm_fx( /* o : decis exp2 = sub( exp2, scale ); exp3 = sub( exp1, exp2 ); - move16(); tmp = div_s( tmp2, tmp1 ); /*Q(15+exp3) */ L_tmp = L_shl( tmp, sub( 1, exp3 ) ); /*Q16 */ @@ -898,6 +918,7 @@ static Word16 sp_mus_classif_gmm_fx( /* o : decis e_tmp = sub( 30 - 16, e_tmp ); L_tmp = Mpy_32_16( e_tmp, f_tmp, 22713 ); /* Q16 */ /* 22713 = ln(2) in Q15 */ *pFV++ = round_fx( L_shl( L_tmp, 11 ) ); /*Q11 */ + move16(); /* update PS vector */ Copy32( &PS_norm[LOWEST_FBIN], hSpMusClas->past_PS_fx, HIGHEST_FBIN - LOWEST_FBIN ); @@ -914,7 +935,6 @@ static Word16 sp_mus_classif_gmm_fx( /* o : decis pFV = FV; - move16(); IF( EQ_16( st_fx->bwidth, NB ) ) { pSF_m = SF_8k_mult_fx; @@ -930,6 +950,7 @@ static Word16 sp_mus_classif_gmm_fx( /* o : decis { /**pFV = pSF[0] * *pFV + pSF[1];*/ *pFV = round_fx_o( L_shl_o( L_mac( pSF_a[i], *pFV, pSF_m[i] ), ishift[i], &Overflow ), &Overflow ); + move16(); pFV++; } @@ -1344,7 +1365,7 @@ static void sp_mus_classif_2nd_fx( move16(); test(); - IF( EQ_16( st->codec_mode, MODE1 ) && EQ_16( st->coder_type, TRANSITION ) ) + if ( EQ_16( st->codec_mode, MODE1 ) && EQ_16( st->coder_type, TRANSITION ) ) { st->coder_type = GENERIC; move16(); @@ -1358,7 +1379,7 @@ static void sp_mus_classif_2nd_fx( st->sp_aud_decision2 = 0; move16(); - IF( EQ_16( st->codec_mode, MODE1 ) ) + if ( EQ_16( st->codec_mode, MODE1 ) ) { st->coder_type = TRANSITION; move16(); @@ -1373,19 +1394,19 @@ static void sp_mus_classif_2nd_fx( move16(); *attack_flag = add( attack, 1 ); move16(); - IF( EQ_16( st->codec_mode, MODE1 ) ) + if ( EQ_16( st->codec_mode, MODE1 ) ) { st->coder_type = TRANSITION; move16(); } } - ELSE IF( GE_16( attack, ATT_SEG_LEN / 2 ) ) + ELSE IF( GE_16( attack, ATT_SEG_LEN >> 1 ) ) { /* do GSC coding if attack is located after the first quarter of the first subframe */ /* (pre-echo will be treated at the decoder side) */ st->sp_aud_decision2 = 1; - *attack_flag = 31; move16(); + *attack_flag = 31; move16(); } } @@ -1398,7 +1419,7 @@ static void sp_mus_classif_2nd_fx( /* do TC coding if attack is located in the last subframe */ *attack_flag = add( attack, 1 ); move16(); - IF( EQ_16( st->codec_mode, MODE1 ) ) + if ( EQ_16( st->codec_mode, MODE1 ) ) { st->coder_type = TRANSITION; move16(); @@ -1438,7 +1459,7 @@ static void var_cor_calc_fx( *high_stable_cor = 0; move16(); test(); - IF( GT_16( *mold_corr, 26214 ) && LT_16( var_cor, 2 ) ) + if ( GT_16( *mold_corr, 26214 ) && LT_16( var_cor, 2 ) ) { *high_stable_cor = 1; move16(); @@ -1482,6 +1503,7 @@ static Word16 attack_det_fx( /* o : attack flag #endif #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move16(); #endif att_3lsub_pos = ATT_3LSUB_POS; @@ -1509,6 +1531,7 @@ static Word16 attack_det_fx( /* o : attack flag attack = maximum_32_fx( finc, ATT_NSEG, &etmp ); #ifdef IVAS_CODE attack1 = attack; + move16(); #endif move16(); test(); @@ -1624,8 +1647,8 @@ static Word16 attack_det_fx( /* o : attack flag } #ifdef IVAS_CODE *last_strong_attack = 0; -#endif move16(); +#endif } return attack; @@ -1684,6 +1707,7 @@ Word16 ivas_smc_gmm_fx( Word32 temp32_log1, temp32_log2; Word16 temp16; Word16 dotp_exp = 0; + move16(); /*------------------------------------------------------------------* * Initialization *------------------------------------------------------------------*/ @@ -1742,14 +1766,15 @@ Word16 ivas_smc_gmm_fx( hSpMusClas->sp_mus_state = add( hSpMusClas->sp_mus_state, 1 ); } + test(); IF( hSpMusClas->sp_mus_state < 0 && hSpMusClas->inact_cnt > 0 ) { hSpMusClas->inact_cnt = sub( hSpMusClas->inact_cnt, 1 ); + move16(); } } ELSE { - test(); test(); IF( hSpMusClas->sp_mus_state > 0 && LT_16( hSpMusClas->sp_mus_state, HANG_LEN ) ) { @@ -1761,6 +1786,7 @@ Word16 ivas_smc_gmm_fx( hSpMusClas->inact_cnt = sub( hSpMusClas->inact_cnt, 1 ); } + test(); IF( hSpMusClas->sp_mus_state > 0 && LT_16( hSpMusClas->sp_mus_state, HANG_LEN ) ) { hSpMusClas->sp_mus_state = -HANG_LEN; @@ -1831,8 +1857,8 @@ Word16 ivas_smc_gmm_fx( ELSE { hSpMusClas->relE_attack_cnt = 0; - relE_attack_flag = 0; move16(); + relE_attack_flag = 0; move16(); } @@ -1876,42 +1902,53 @@ Word16 ivas_smc_gmm_fx( move16(); temp16 = lsp_new_fx[2]; move16(); + temp32 = L_sub( ONE_IN_Q30, L_mult0( temp16, temp16 ) ); // Q30 temp_sqrt = Sqrt32( temp32, &temp_exp ); temp_acos = BASOP_util_atan2( temp_sqrt, L_deposit_h( temp16 ), temp_exp ); *pFV_fx++ = L_shl( temp_acos, Q7 ); // Q20 + move32(); temp_exp = 1; move16(); temp16 = lsp_new_fx[3]; move16(); + temp32 = L_sub( ONE_IN_Q30, L_mult0( temp16, temp16 ) ); // Q30 temp_sqrt = Sqrt32( temp32, &temp_exp ); temp_acos = BASOP_util_atan2( temp_sqrt, L_deposit_h( temp16 ), temp_exp ); *pFV_fx++ = L_shl( temp_acos, Q7 ); // Q20 + move32(); temp_exp = 1; move16(); temp16 = lsp_new_fx[4]; move16(); + temp32 = L_sub( ONE_IN_Q30, L_mult0( temp16, temp16 ) ); // Q30 temp_sqrt = Sqrt32( temp32, &temp_exp ); temp_acos = BASOP_util_atan2( temp_sqrt, L_deposit_h( temp16 ), temp_exp ); *pFV_fx++ = L_shl( temp_acos, Q7 ); // Q20 + move32(); temp_exp = 1; move16(); temp16 = lsp_new_fx[5]; move16(); + temp32 = L_sub( ONE_IN_Q30, L_mult0( temp16, temp16 ) ); // Q30 temp_sqrt = Sqrt32( temp32, &temp_exp ); temp_acos = BASOP_util_atan2( temp_sqrt, L_deposit_h( temp16 ), temp_exp ); *pFV_fx++ = L_shl( temp_acos, Q7 ); // Q20 + move32(); temp_exp = 1; move16(); temp16 = lsp_new_fx[6]; move16(); + + temp32 = L_sub( ONE_IN_Q30, L_mult0( temp16, temp16 ) ); // Q30 temp_sqrt = Sqrt32( temp32, &temp_exp ); temp_acos = BASOP_util_atan2( temp_sqrt, L_deposit_h( temp16 ), temp_exp ); *pFV_fx++ = L_shl( temp_acos, Q7 ); // Q20 + move32(); // temf = acosf( lsp_new[2] ); /* [2,3,4,5,6] LSFs */ /* *pFV++ = acosf( lsp_new[2] ); @@ -1930,12 +1967,10 @@ Word16 ivas_smc_gmm_fx( /* [9] epsP */ temp32 = L_add( epsP_fx[14], L_shr( 21475, sub( 31, Q_esp ) ) ); - move32(); temp32_log = L_add( BASOP_Util_Log2( temp32 ), L_shl( sub( Q31, Q_esp ), Q25 ) ); temp32_log1 = Mpy_32_32( temp32_log, 1488522239 ); /*logf(x) = log2(x)*logf(2)*/ temp32 = L_add( epsP_fx[0], L_shr( 21475, sub( 31, Q_esp ) ) ); - move32(); temp32_log = L_add( BASOP_Util_Log2( temp32 ), L_shl( sub( Q31, Q_esp ), Q25 ) ); temp32_log2 = Mpy_32_32( temp32_log, 1488522239 ); /*logf(x) = log2(x)*logf(2)*/ @@ -1947,7 +1982,6 @@ Word16 ivas_smc_gmm_fx( set_zero_fx( melS_fx, NB_MEL_BANDS ); pt_mel_fb_fx = mel_fb_fx; - move32(); FOR( i = 0; i < NB_MEL_BANDS; i++ ) { @@ -1971,18 +2005,22 @@ Word16 ivas_smc_gmm_fx( } Word16 guard_bits = find_guarded_bits_fx( NB_MEL_BANDS ); + move16(); v_mult_mat_fixed( mfcc_fx, melS_fx, dct_mtx_fx, NB_MEL_BANDS, NB_MEL_COEF, guard_bits ); // Q19 *pFV_fx++ = L_shl( mfcc_fx[2], 1 ); // Q20 + move32(); *pFV_fx++ = L_shl( mfcc_fx[6], 1 ); + move32(); *pFV_fx++ = L_shl( mfcc_fx[12], 1 ); + move32(); /* *pFV++ = mfcc[2]; *pFV++ = mfcc[6]; *pFV++ = mfcc[12];*/ /* calculation of differential normalized power spectrum */ sum_PS_fx = 0; - Word16 sum_PS_e = 0; move32(); + Word16 sum_PS_e = 0; move16(); Word64 sum = W_shl( 21475 /* 1e-5 in Q31 */, sub( Qfact_PS, 30 ) ); // Qfact_PS+1 move64(); @@ -2034,13 +2072,14 @@ Word16 ivas_smc_gmm_fx( IF( GT_32( PS_norm_fx[i], hSpMusClas->past_PS_fx[i - LOWEST_FBIN] ) ) { temp32 = BASOP_Util_Divide3232_Scale_cadence( PS_norm_fx[i], ( L_add( dPS_fx[i], L_shr( 21475, sub( 31, Qfact_PS_past ) ) ) ), &temp_exp ); // 31-temp_exp + move32(); ps_sta_fx = BASOP_Util_Add_Mant32Exp( temp32, temp_exp, ps_sta_fx, ps_sta_exp, &ps_sta_exp ); + move32(); } ELSE { // ps_sta += hSpMusClas->past_PS[i - LOWEST_FBIN] / ( dPS[i] + 1e-5f ); temp32 = BASOP_Util_Divide3232_Scale_cadence( hSpMusClas->past_PS_fx[i - LOWEST_FBIN], ( L_add( dPS_fx[i], L_shr( 21475, sub( 31, Qfact_PS_past ) ) ) ), &temp_exp ); // 31-temp_exp - move32(); ps_sta_fx = BASOP_Util_Add_Mant32Exp( temp32, temp_exp, ps_sta_fx, ps_sta_exp, &ps_sta_exp ); } } @@ -2069,8 +2108,8 @@ Word16 ivas_smc_gmm_fx( hStereoClassif->ps_sta_ch2_e = 6; // logf( ps_sta + 1e-5f );Q25 } move32(); - move32(); move16(); + move32(); move16(); } @@ -2088,6 +2127,7 @@ Word16 ivas_smc_gmm_fx( move16(); FOR( i = 0; i < N_SMC_FEATURES; i++ ) { + test(); IF( LT_32( *pFV_fx, pODV_fx[0] ) || GT_32( *pFV_fx, pODV_fx[1] ) ) { *p_out++ = i; @@ -2125,6 +2165,8 @@ Word16 ivas_smc_gmm_fx( { //*pFV_st = smc_st_mean_fact * ( *pFV_st ) + ( 1 - smc_st_mean_fact ) * ( *pFV ); *pFV_st_fx = L_add( L_shr( *pFV_st_fx, smc_st_mean_fact_fx ), L_shr( *pFV_fx, 1 ) ); + move32(); + test(); test(); test(); @@ -2146,6 +2188,7 @@ Word16 ivas_smc_gmm_fx( ELSE { *pFV_fx++ = *pFV_st_fx++; + move32(); } } @@ -2160,15 +2203,17 @@ Word16 ivas_smc_gmm_fx( IF( bcox_lmbd_fx[i] != 0 ) { *pFV_fx = L_sub( *pFV_fx, L_shr( bcox_add_cnst_fx[i], sub( 31, Qfact_FV ) ) ); + move32(); IF( LT_32( *pFV_fx, L_shl( 1, Qfact_FV ) ) ) { *pFV_fx = L_shl( 1, Qfact_FV ); + move32(); } Word16 pow_e = 0; move32(); temp32_log = L_add( BASOP_Util_Log2( *pFV_fx ), L_shl( sub( 31, Qfact_FV ), Q25 ) ); // Q25 temp32 = Mpy_32_32( temp32_log, bcox_lmbd_fx[i] ); // Q25 - Word32 pow_temp = BASOP_util_Pow2( temp32, sub( 31, Q25 ), &pow_e ); + Word32 pow_temp = BASOP_util_Pow2( temp32, 31 - Q25, &pow_e ); IF( pow_e <= 0 ) { pow_temp = L_shr( pow_temp, sub( 1, pow_e ) ); @@ -2179,6 +2224,7 @@ Word16 ivas_smc_gmm_fx( move32(); temp32 = L_deposit_h( BASOP_Util_Divide3232_Scale( temp32, bcox_lmbd_fx[i], &temp_exp ) ); *pFV_fx = L_shl( temp32, sub( Qfact_FV, sub( 31, add( temp_exp, pow_e ) ) ) ); + move32(); // float temp = powf( *pFV, bcox_lmbd[i] ); // *pFV = ( powf( *pFV, bcox_lmbd[i] ) - 1 ) / bcox_lmbd[i]; } @@ -2198,8 +2244,11 @@ Word16 ivas_smc_gmm_fx( // *pFV = ( *pFV - sm_means[i] ) / sm_scale[i]; temp32 = L_sub( *pFV_fx, sm_means_fx[i] ); temp_exp = 0; + move16(); temp32 = L_deposit_h( BASOP_Util_Divide3232_Scale( temp32, sm_scale_fx[i], &temp_exp ) ); - *pFV_fx = L_shl( temp32, Qfact_FV - ( 31 - temp_exp ) ); + // *pFV_fx = L_shl( temp32, Qfact_FV - ( 31 - temp_exp ) ); + *pFV_fx = L_shl( temp32, sub( Qfact_FV, sub( 31, temp_exp ) ) ); + move32(); pFV_fx++; /* MinMax sclaer - mean and variance normalization */ /**pFV = *pFV * sm_scale[i] + sm_min[i];*/ @@ -2242,9 +2291,9 @@ Word16 ivas_smc_gmm_fx( move32(); } - lps_fx = logsumexp_fx( ps_fx, sub( 31, Q18 ), N_SMC_MIXTURES ); - lpm_fx = logsumexp_fx( pm_fx, sub( 31, Q18 ), N_SMC_MIXTURES ); - lpn_fx = logsumexp_fx( pn_fx, sub( 31, Q18 ), N_SMC_MIXTURES ); + lps_fx = logsumexp_fx( ps_fx, 31 - Q18, N_SMC_MIXTURES ); + lpm_fx = logsumexp_fx( pm_fx, 31 - Q18, N_SMC_MIXTURES ); + lpn_fx = logsumexp_fx( pn_fx, 31 - Q18, N_SMC_MIXTURES ); *high_lpn_flag = 0; move16(); if ( GT_32( lpn_fx, lps_fx ) && GT_32( lpn_fx, lpm_fx ) ) @@ -2254,10 +2303,10 @@ Word16 ivas_smc_gmm_fx( } hSpMusClas->lpm_fx = extract_l( L_shr( lpm_fx, 11 ) ); // Q7 - hSpMusClas->lps_fx = extract_l( L_shr( lps_fx, 11 ) ); // Q7 - hSpMusClas->lpn_fx = extract_l( L_shr( lpn_fx, 11 ) ); // Q7 move16(); + hSpMusClas->lps_fx = extract_l( L_shr( lps_fx, 11 ) ); // Q7 move16(); + hSpMusClas->lpn_fx = extract_l( L_shr( lpn_fx, 11 ) ); // Q7 move16(); /* determine HQ Generic speech class */ @@ -2306,6 +2355,7 @@ Word16 ivas_smc_gmm_fx( } dec = (Word16) GT_32( dlp_fx, 0 ); + move16(); /* calculate weight based on relE (higher relE -> lower weight, lower relE -> higher weight) */ wrelE_fx = lin_interp32_fx( L_deposit_h( relE_fx ), 15 << 24, 1932735283 /*0.9 in Q31*/, -( 15 << 24 ), 2126008812 /*0.99 in Q31*/, 1 ); // Q31 @@ -2326,6 +2376,7 @@ Word16 ivas_smc_gmm_fx( hSpMusClas->wdrop_32fx = L_add( hSpMusClas->wdrop_32fx, L_sub( hSpMusClas->dlp_mean_ST_fx, dlp_fx ) ); move32(); } + move16(); } ELSE { @@ -2333,10 +2384,11 @@ Word16 ivas_smc_gmm_fx( move32(); } wdrop_fx = lin_interp32_fx( hSpMusClas->wdrop_32fx, 7864320, 1503238554 /* 0.7 in Q31 */, 0, ONE_IN_Q31 /* 1.0f in Q31 */, 1 ); /* Q31 */ + test(); test(); /* calculate weight based on rises of dlp (close to 1 during sudden rise of dlp, close to 0 otherwise) */ - IF( EQ_16( hSpMusClas->sp_mus_state, HANG_LEN ) && hSpMusClas->dlp_mean_ST_fx > 0 && hSpMusClas->dlp_mean_ST_fx > hSpMusClas->past_dlp_mean_ST_fx[0] ) + IF( EQ_16( hSpMusClas->sp_mus_state, HANG_LEN ) && hSpMusClas->dlp_mean_ST_fx > 0 && GT_32( hSpMusClas->dlp_mean_ST_fx, hSpMusClas->past_dlp_mean_ST_fx[0] ) ) { IF( hSpMusClas->past_dlp_mean_ST_fx[0] < 0 ) { @@ -2346,6 +2398,7 @@ Word16 ivas_smc_gmm_fx( { hSpMusClas->wrise_fx = add( hSpMusClas->wrise_fx, extract_l( L_shr( L_sub( hSpMusClas->dlp_mean_ST_fx, hSpMusClas->past_dlp_mean_ST_fx[0] ), 10 ) ) ); } + move16(); } ELSE { @@ -2364,8 +2417,8 @@ Word16 ivas_smc_gmm_fx( { hSpMusClas->dlp_mean_LT_fx = dlp_fx; - hSpMusClas->dlp_var_LT_fx = 0; move32(); + hSpMusClas->dlp_var_LT_fx = 0; move32(); } @@ -2376,11 +2429,11 @@ Word16 ivas_smc_gmm_fx( hSpMusClas->dlp_var_LT_fx = L_add( Mpy_32_32( 1932735283, hSpMusClas->dlp_var_LT_fx ), Mpy_32_32( 214748365, temp32 ) ); test(); - IF( hSpMusClas->sp_mus_state > 0 && hSpMusClas->sp_mus_state < HANG_LEN ) + IF( hSpMusClas->sp_mus_state > 0 && LT_16( hSpMusClas->sp_mus_state, HANG_LEN ) ) { dlp_mean2var_fx = 0; - dlp_mean2var_q = 0; move16(); + dlp_mean2var_q = 0; move16(); } ELSE @@ -2452,6 +2505,7 @@ Word16 ivas_smc_gmm_fx( ELSE IF( hSpMusClas->flag_spitch_cnt > 0 ) { hSpMusClas->flag_spitch_cnt = sub( hSpMusClas->flag_spitch_cnt, 1 ); + move16(); } test(); IF( Etot_fx < 2560 ) @@ -2464,7 +2518,6 @@ Word16 ivas_smc_gmm_fx( { temp32 = L_mult( w_spmus_fx[hSpMusClas->sp_mus_state - 1][0], (Word16) L_shr( dlp_fx, 10 ) ); /*Q25 */ temp32 = L_add( temp32, Dot_product( &w_spmus_fx[hSpMusClas->sp_mus_state - 1][1], hSpMusClas->past_dlp_fx, sub( HANG_LEN, 1 ) ) ); - move16(); /* entry state -> final decision is calculated based on weighted average of past non-binary decisions */ IF( GT_32( temp32, 2 << 25 ) ) { @@ -2602,7 +2655,7 @@ static void var_cor_calc_ivas_fx( *high_stable_cor = 0; move16(); test(); - IF( GT_16( *mold_corr, 26214 ) && LT_16( var_cor, 1 ) ) + if ( GT_16( *mold_corr, 26214 ) && LT_16( var_cor, 1 ) ) { *high_stable_cor = 1; move16(); @@ -2861,43 +2914,41 @@ static Word32 tonal_det_fx( IF( GT_32( S_mass, *tod_S_mass_prev ) ) { alpha = 1503238554; /* 0.7f in Q31 */ - move16(); } ELSE { alpha = 644245094; /* 0.3f in Q31 */ - move16(); } + move16(); + *tod_S_mass_prev = S_mass; + move32(); *tod_S_mass_lt = L_add( Mpy_32_32( alpha, *tod_S_mass_lt ), Mpy_32_32( L_sub( ONE_IN_Q31, alpha ), S_mass ) ); // Q22 + move32(); S_mass = *tod_S_mass_lt; - move16(); - move16(); - move16(); + move32(); /* updating adaptive decision threshold */ IF( GT_32( S_mass, *tod_thr_lt ) ) { *tod_thr_lt = L_sub( *tod_thr_lt, THR_MASS_STEP_DN_FX ); - move16(); } ELSE { *tod_thr_lt = L_add( *tod_thr_lt, THR_MASS_STEP_UP_FX ); - move16(); } + move16(); if ( GT_32( *tod_thr_lt, THR_MASS_MAX_FX ) ) { *tod_thr_lt = THR_MASS_MAX_FX; - move16(); } if ( LT_32( *tod_thr_lt, THR_MASS_MIN_FX ) ) { *tod_thr_lt = THR_MASS_MIN_FX; - move16(); } + move16(); return S_mass; /* Q22 */ } @@ -2930,15 +2981,15 @@ void ivas_smc_mode_selection_fx( Word32 ton; Word16 i; Word32 S_p2a, S_max, S_ave = 0; - Word32 thr_sp2a; move32(); + Word32 thr_sp2a; SP_MUS_CLAS_HANDLE hSpMusClas = st->hSpMusClas; /* initialization */ *attack_flag = 0; - st->sp_aud_decision2 = 0; move16(); + st->sp_aud_decision2 = 0; move16(); /* signal stability estimation */ @@ -2997,33 +3048,27 @@ void ivas_smc_mode_selection_fx( /* select TCX to encode extremely peaky signals or strongly tonal signals */ st->sp_aud_decision1 = 1; st->sp_aud_decision2 = 1; - move16(); - move16(); } ELSE IF( smc_dec == SPEECH ) { /* select ACELP to encode speech */ st->sp_aud_decision1 = 0; st->sp_aud_decision2 = 0; - move16(); - move16(); } ELSE IF( EQ_16( smc_dec, SPEECH_OR_MUSIC ) ) { /* select GSC to encode "unclear" segments (classifier's score on the borderline) */ st->sp_aud_decision1 = 1; st->sp_aud_decision2 = 0; - move16(); - move16(); } ELSE { /* select TCX to encode music */ st->sp_aud_decision1 = 1; st->sp_aud_decision2 = 1; - move16(); - move16(); } + move16(); + move16(); /* change decision from GSC to ACELP/TCX in some special cases */ test(); @@ -3074,8 +3119,8 @@ void ivas_smc_mode_selection_fx( { /* do ACELP TC coding instead of GC/VC if onset has been already declared before */ st->sp_aud_decision1 = 0; - st->coder_type = TRANSITION; move16(); + st->coder_type = TRANSITION; move16(); } ELSE @@ -3084,10 +3129,10 @@ void ivas_smc_mode_selection_fx( { /* do ACELP TC coding also if attack is located in the last subframe */ st->sp_aud_decision1 = 0; - *attack_flag = add( attack, 1 ); - st->coder_type = TRANSITION; move16(); + *attack_flag = add( attack, 1 ); move16(); + st->coder_type = TRANSITION; move16(); } ELSE IF( GE_16( attack, ATT_SEG_LEN / 2 ) ) @@ -3095,8 +3140,8 @@ void ivas_smc_mode_selection_fx( /* do GSC coding if attack is located after the first quarter of the first subframe */ /* (pre-echo will be treated at the decoder side) */ *attack_flag = 31; - *attack_flag = add( attack, 1 ); move16(); + *attack_flag = add( attack, 1 ); move16(); } } @@ -3111,13 +3156,13 @@ void ivas_smc_mode_selection_fx( { /* change ACELP coder_type to TC if attack has been detected */ st->sp_aud_decision1 = 0; + move16(); st->sp_aud_decision2 = 0; + move16(); st->coder_type = TRANSITION; - *attack_flag = add( attack, 1 ); - move16(); - move16(); move16(); + *attack_flag = add( attack, 1 ); move16(); } @@ -3180,26 +3225,24 @@ void ivas_smc_mode_selection_fx( { /* music-like content */ st->GSC_IVAS_mode = 3; - move16(); } ELSE IF( st->tc_cnt > 0 ) { /* likely presence of an onset, GSC bit allocation will be more focused on LF */ st->GSC_IVAS_mode = 2; - move16(); } + move16(); test(); IF( EQ_16( st->coder_type_raw, UNVOICED ) && st->sp_aud_decision0 == 0 /*&& st->GSC_IVAS_mode < 3*/ ) { st->GSC_noisy_speech = 1; - move16(); } ELSE { st->GSC_noisy_speech = 0; - move16(); } + move16(); } /* set coder_type to AUDIO when GSC is selected (st->core will be set later in the decision matrix) */ @@ -3335,6 +3378,7 @@ static Word16 mode_decision_fx( } inv_len = 3277; /*Q15 */ + move16(); L_tmp = L_deposit_l( 0 ); FOR( i = 0; i < 10; i++ ) @@ -3684,6 +3728,7 @@ static void spec_analysis_fx( Word16 p2v[65]; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif /* find spectral peaks */ @@ -3768,6 +3813,7 @@ static void spec_analysis_fx( IF( GT_16( peak_idx[k], valey_idx[i] ) && LT_16( peak_idx[k], valey_idx[i + 1] ) ) { p2v[k] = sub_o( shl_o( peak[k], 1, &Overflow ), add_o( valley[i], valley[i + 1], &Overflow ), &Overflow ); + move16(); k = add( k, 1 ); } } @@ -3799,6 +3845,7 @@ static void music_mixed_classif_improv_fx( Word16 exp, frac, expn, fracn, expd, fracd, scale; Word16 tmp; Word32 L_tmp, ftmp, ftmp1, epsP_max = MIN_32; + move32(); SP_MUS_CLAS_HANDLE hSpMusClas = st->hSpMusClas; /* find sample with maximum absolute amplitude */ @@ -3890,7 +3937,7 @@ static void music_mixed_classif_improv_fx( test(); test(); test(); - IF( LT_16( old_cor, 24576 ) && LT_16( st->voicing_fx[0], 24576 ) && LT_16( st->voicing_fx[1], 24576 ) && GT_16( hSpMusClas->old_lt_diff_fx[0], 1280 ) ) + if ( LT_16( old_cor, 24576 ) && LT_16( st->voicing_fx[0], 24576 ) && LT_16( st->voicing_fx[1], 24576 ) && GT_16( hSpMusClas->old_lt_diff_fx[0], 1280 ) ) { percus_flag = 1; move16(); @@ -3903,7 +3950,7 @@ static void music_mixed_classif_improv_fx( test(); test(); test(); - IF( GT_16( sub( hSpMusClas->buf_etot_fx[3], hSpMusClas->buf_etot_fx[2] ), 1536 ) && GT_16( hSpMusClas->dec_mov_fx, 29491 ) && GT_16( sub( etot, st->lp_speech_fx ), 1280 ) && GT_16( hSpMusClas->old_lt_diff_fx[0], 640 ) ) + if ( GT_16( sub( hSpMusClas->buf_etot_fx[3], hSpMusClas->buf_etot_fx[2] ), 1536 ) && GT_16( hSpMusClas->dec_mov_fx, 29491 ) && GT_16( sub( etot, st->lp_speech_fx ), 1280 ) && GT_16( hSpMusClas->old_lt_diff_fx[0], 640 ) ) { hSpMusClas->attack_hangover = 3; move16(); @@ -3933,7 +3980,9 @@ static void music_mixed_classif_improv_fx( flux_fx( st->lgBin_E_fx, p2v_map, hSpMusClas->old_Bin_E_fx, hSpMusClas->buf_flux_fx, hSpMusClas->attack_hangover, hSpMusClas->dec_mov_fx ); hSpMusClas->attack_hangover = sub( hSpMusClas->attack_hangover, 1 ); + move16(); hSpMusClas->attack_hangover = s_max( hSpMusClas->attack_hangover, 0 ); + move16(); /* identify flux buffer buffering status */ len = 0; @@ -4098,6 +4147,8 @@ static void music_mixed_classif_improv_fx( hSpMusClas->dec_mov_fx = add( mult_r( 31785, hSpMusClas->dec_mov_fx ), 983 ); /*Q15 */ hSpMusClas->dec_mov1_fx = add( mult_r( 31785, hSpMusClas->dec_mov1_fx ), 983 ); /*Q15 */ } + move16(); + move16(); } /* update long term unvoiced counter */ @@ -4113,24 +4164,27 @@ static void music_mixed_classif_improv_fx( { hSpMusClas->UV_cnt1 = add( hSpMusClas->UV_cnt1, 1 ); } + move16(); hSpMusClas->UV_cnt1 = s_min( hSpMusClas->UV_cnt1, 300 ); + move16(); hSpMusClas->UV_cnt1 = s_max( hSpMusClas->UV_cnt1, 0 ); + move16(); /**LT_UV_cnt1 = add(mult_r(29491,*LT_UV_cnt1),mult_r(3277,shl(*UV_cnt1,6)));*/ /* Q6 */ hSpMusClas->LT_UV_cnt1_fx = round_fx( L_mac( L_mult( 29491, hSpMusClas->LT_UV_cnt1_fx ), 3277, shl( hSpMusClas->UV_cnt1, 6 ) ) ); /*Q6 */ - + move16(); /* revert classification decision due to long-term unvoiced counter */ test(); test(); - IF( EQ_16( dec, 1 ) && LT_16( hSpMusClas->dec_mov1_fx, 6554 ) && LT_16( hSpMusClas->LT_UV_cnt1_fx, 12800 ) ) + if ( EQ_16( dec, 1 ) && LT_16( hSpMusClas->dec_mov1_fx, 6554 ) && LT_16( hSpMusClas->LT_UV_cnt1_fx, 12800 ) ) { dec = 0; move16(); } /* overwrite 1st stage speech/music decision to music */ - IF( EQ_16( dec, 1 ) ) + if ( EQ_16( dec, 1 ) ) { st->sp_aud_decision1 = 1; move16(); @@ -4162,6 +4216,7 @@ static void tonal_context_improv_fx( SP_MUS_CLAS_HANDLE hSpMusClas = st_fx->hSpMusClas; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move16(); #endif IF( EQ_16( st_fx->last_codec_mode, MODE2 ) ) @@ -4302,6 +4357,9 @@ static void tonal_context_improv_fx( /* long-term tonality measure */ hSpMusClas->lt_tonality = L_add( Mult_32_16( hSpMusClas->lt_tonality, 16384 ), Mult_32_16( tonality, 16384 ) ); } + move16(); + move16(); + move16(); /* Pitch difference w.r.t to past 3 frames */ lt_pitch_diff = abs_s( sub( hSpMusClas->lt_corr_pitch[0], st_fx->pitch[0] ) ); @@ -4379,6 +4437,7 @@ static void tonal_context_improv_fx( exp = sub( 30, add( exp, 16 ) ); L_tmp = Mpy_32_16( exp, tmp, 15783 ); /*19 //3945, 0.2*log10(2), Q18 */ hSpMusClas->tonality2_buf_fx[HANG_LEN_INIT - 1] = round_fx( L_shl( L_tmp, 11 ) ); /*14 */ + move16(); /* t2 = std( st->tonality2_buf, HANG_LEN_INIT ); */ t2_fx = std_fx( hSpMusClas->tonality2_buf_fx, HANG_LEN_INIT ); /*14 */ @@ -4390,6 +4449,7 @@ static void tonal_context_improv_fx( L_tmp = Mpy_32_16( exp, tmp, 15783 ); /*19 //3945, 0.2*log10(2), Q18 */ hSpMusClas->tonality3_buf_fx[HANG_LEN_INIT - 1] = round_fx( L_shl( L_tmp, 11 ) ); /*14 */ t3_fx = std_fx( hSpMusClas->tonality3_buf_fx, HANG_LEN_INIT ); /*14 */ + move16(); /* tL = 0.2f*(float)log10(st->lt_tonality); */ exp = norm_l( hSpMusClas->lt_tonality ); @@ -4401,6 +4461,7 @@ static void tonal_context_improv_fx( /* calculate standard deviation of residual LP energy */ Copy( hSpMusClas->LPCErr_buf_fx + 1, hSpMusClas->LPCErr_buf_fx, HANG_LEN_INIT - 1 ); hSpMusClas->LPCErr_buf_fx[HANG_LEN_INIT - 1] = LPCErr; + move16(); /* err = std( st->LPCErr_buf, HANG_LEN_INIT ); */ err_fx = std_fx( hSpMusClas->LPCErr_buf_fx, HANG_LEN_INIT ); @@ -4441,6 +4502,7 @@ static void tonal_context_improv_fx( IF( hSpMusClas->lt_music_hangover > 0 ) { hSpMusClas->lt_music_hangover = sub( hSpMusClas->lt_music_hangover, 1 ); + move16(); } /* state machine for strong speech */ @@ -4478,6 +4540,7 @@ static void tonal_context_improv_fx( IF( hSpMusClas->lt_speech_hangover > 0 ) { hSpMusClas->lt_speech_hangover = sub( hSpMusClas->lt_speech_hangover, 1 ); + move16(); } /* final decision */ @@ -4524,10 +4587,14 @@ static void detect_sparseness_fx( Word16 S1[128]; Word16 i, j; Word16 hb_sp_high_flag = 0; + move16(); Word16 lb_sp_high_flag = 0; + move16(); Word16 sparse; Word16 tmp_buf[4]; Word16 Mlpe = 0, Mv = 0, Msp; + move16(); + move16(); SP_MUS_CLAS_HANDLE hSpMusClas = st_fx->hSpMusClas; Copy( st_fx->lgBin_E_fx, S1, 128 ); @@ -4659,12 +4726,12 @@ static void detect_sparseness_fx( IF( tmp == 0 ) { hSpMusClas->hf_spar_buf_fx[HANG_LEN_INIT - 1] = 0; - move16(); } ELSE { hSpMusClas->hf_spar_buf_fx[HANG_LEN_INIT - 1] = div_s( tmp, sumh ); } + move16(); tmp = 0; move16(); @@ -4759,6 +4826,7 @@ static void detect_sparseness_fx( if ( EQ_16( st_fx->bwidth, WB ) ) { tmp = 90; + move16(); } IF( GT_16( sparse, tmp ) ) @@ -4821,7 +4889,7 @@ static void detect_sparseness_fx( hSpMusClas->gsc_hangover = 1; move16(); } - ELSE IF( EQ_16( hSpMusClas->gsc_hangover, 1 ) && !( st_fx->sp_aud_decision1 == 0 && st_fx->sp_aud_decision2 == 1 ) ) + ELSE IF( EQ_16( hSpMusClas->gsc_hangover, 1 ) && !( st_fx->sp_aud_decision1 == 0 && EQ_16( st_fx->sp_aud_decision2, 1 ) ) ) { IF( LT_16( abs_s( sub( sparse, mean_fx( &hSpMusClas->sparse_buf_fx[HANG_LEN_INIT - 1 - hSpMusClas->gsc_cnt], hSpMusClas->gsc_cnt ) ) ), 7 ) ) { diff --git a/lib_enc/stat_noise_uv_enc_fx.c b/lib_enc/stat_noise_uv_enc_fx.c index c84866ce9eea13727e486e0772919d0a9c01e9f4..91dca8d63ff14510d6f3273d9e01b12f89321144 100644 --- a/lib_enc/stat_noise_uv_enc_fx.c +++ b/lib_enc/stat_noise_uv_enc_fx.c @@ -49,10 +49,13 @@ void stat_noise_uv_enc_fx( Word16 Q_new ) { Word16 noisiness = 0; + move16(); Word16 num, den, expn, expd; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move16(); #endif + test(); test(); test(); IF( ( EQ_16( st_fx->coder_type, UNVOICED ) && uc_two_stage_flag == 0 ) || ( EQ_16( st_fx->coder_type, INACTIVE ) && LE_32( st_fx->core_brate, ACELP_9k60 ) ) ) diff --git a/lib_enc/subband_fft_fx.c b/lib_enc/subband_fft_fx.c index 83a1b41dd1dc30fe79f5b36f00f8f584d2ead612..10de09fe95e85e1dbbbc7ef6f6686115770cbbc6 100644 --- a/lib_enc/subband_fft_fx.c +++ b/lib_enc/subband_fft_fx.c @@ -107,7 +107,7 @@ static void passf4_1_16( UWord16 i; - for ( i = 0; i < 4; i++ ) + FOR( i = 0; i < 4; i++ ) { cmplx_s c2, c3, c4, t1, t2, t3, t4; @@ -142,7 +142,7 @@ static void passf4_2_16( Word16 k; - for ( k = 0; k < 4; k++ ) + FOR( k = 0; k < 4; k++ ) { cmplx_s t1, t2, t3, t4; diff --git a/lib_enc/swb_bwe_enc_fx.c b/lib_enc/swb_bwe_enc_fx.c index 88b3b0c538ea26876d9ba530c92d3d6ac7eb0a67..ef8edf93867554ead879cf18df2ab102da90576a 100644 --- a/lib_enc/swb_bwe_enc_fx.c +++ b/lib_enc/swb_bwe_enc_fx.c @@ -130,6 +130,7 @@ void wb_bwe_enc_fx( ) { Word16 mode = 0; + move16(); Word16 Sample_Delay_WB_BWE; Word16 old_input_fx[NS2SA( 16000, DELAY_FD_BWE_ENC_NS + DELAY_FIR_RESAMPL_NS ) + L_FRAME16k]; Word32 yorig_32[L_FRAME16k]; @@ -183,13 +184,14 @@ void wb_bwe_enc_fx( scl = s_min( Q_synth, scl ); } Copy_Scale_sig32_16( yorig_32, yorig_fx, L_FRAME16k, scl ); - Q_synth = add( sub( new_input_fx_exp, 16 ), scl ) - 1; + Q_synth = sub( add( sub( new_input_fx_exp, 16 ), scl ), 1 ); mode = WB_BWE_encoding_fx( coder_type, yorig_fx, WB_fenv_fx, st_fx, Q_synth, Q_synth ); - push_indice_fx( st_fx->hBstr, IND_WB_CLASS, mode - 2, 1 ); + push_indice_fx( st_fx->hBstr, IND_WB_CLASS, sub( mode, 2 ), 1 ); } hBWE_FD->prev_mode = mode; + move16(); return; } @@ -206,6 +208,7 @@ void wb_bwe_enc_ivas_fx( ) { Word16 mode = 0; + move16(); Word16 Sample_Delay_WB_BWE; Word16 old_input_fx[NS2SA( 16000, DELAY_FD_BWE_ENC_NS + DELAY_FIR_RESAMPL_NS ) + L_FRAME16k]; Word32 yorig_32[L_FRAME16k]; @@ -216,9 +219,8 @@ void wb_bwe_enc_ivas_fx( Word16 Q_synth; FD_BWE_ENC_HANDLE hBWE_FD = st_fx->hBWE_FD; Word16 WB_fenv_fx[SWB_FENV]; - move16(); - IF( GT_32( st_fx->extl_brate, 0 ) ) + IF( st_fx->extl_brate > 0 ) { /*---------------------------------------------------------------------* * Delay the original input signal to be synchronized with ACELP core synthesis @@ -261,10 +263,11 @@ void wb_bwe_enc_ivas_fx( scl = s_min( Q_synth, scl ); } Copy_Scale_sig32_16( yorig_32, yorig_fx, L_FRAME16k, scl ); - Q_synth = add( sub( new_input_fx_exp, 16 ), scl ) - 1; + Q_synth = sub( add( sub( new_input_fx_exp, 16 ), scl ), 1 ); mode = WB_BWE_encoding_ivas_fx( st_fx, yorig_fx, WB_fenv_fx, Q_synth, Q_synth ); - push_indice( st_fx->hBstr, IND_WB_CLASS, mode - 2, 1 ); + move16(); + push_indice( st_fx->hBstr, IND_WB_CLASS, sub( mode, 2 ), 1 ); } hBWE_FD->prev_mode = mode; @@ -335,27 +338,27 @@ void swb_bwe_enc_ivas_fx( inner_frame = L_FRAME48k; move16(); inner_Fs = 48000; - move16(); + move32(); } ELSE { inner_frame = L_FRAME32k; move16(); inner_Fs = 32000; - move16(); + move32(); } set16_fx( old_input_fx, 0, add( NS2SA( inner_Fs, DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ), inner_frame ) ); IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { - Sample_Delay_SWB_BWE = NS2SA( inner_Fs, DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ); - Sample_Delay_HP = NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS - DELAY_CLDFB_NS ); + Sample_Delay_SWB_BWE = NS2SA_FX2( inner_Fs, DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ); + Sample_Delay_HP = NS2SA_FX2( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS - DELAY_CLDFB_NS ); IF( EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) { - Sample_Delay_HP = NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS - DELAY_CLDFB_NS - L_MEM_RECALC_TBE_NS ); + Sample_Delay_HP = NS2SA_FX2( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS - DELAY_CLDFB_NS - L_MEM_RECALC_TBE_NS ); } - Sample_Delay_LP = NS2SA( 12800, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS ); + Sample_Delay_LP = NS2SA_FX2( 12800, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS ); IF( st_fx->element_mode > EVS_MONO ) { @@ -374,13 +377,13 @@ void swb_bwe_enc_ivas_fx( } ELSE { - Sample_Delay_SWB_BWE = NS2SA( inner_Fs, DELAY_FD_BWE_ENC_16k_NS + DELAY_FIR_RESAMPL_NS ); - Sample_Delay_HP = NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_16k_NS + DELAY_FIR_RESAMPL_NS - DELAY_CLDFB_NS ); + Sample_Delay_SWB_BWE = NS2SA_FX2( inner_Fs, DELAY_FD_BWE_ENC_16k_NS + DELAY_FIR_RESAMPL_NS ); + Sample_Delay_HP = NS2SA_FX2( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_16k_NS + DELAY_FIR_RESAMPL_NS - DELAY_CLDFB_NS ); IF( EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) { - Sample_Delay_HP = NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_16k_NS + DELAY_FIR_RESAMPL_NS - DELAY_CLDFB_NS - L_MEM_RECALC_TBE_NS ); + Sample_Delay_HP = NS2SA_FX2( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_16k_NS + DELAY_FIR_RESAMPL_NS - DELAY_CLDFB_NS - L_MEM_RECALC_TBE_NS ); } - Sample_Delay_LP = NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_16k_NS ); + Sample_Delay_LP = NS2SA_FX2( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_16k_NS ); IF( st_fx->element_mode > EVS_MONO ) { Sample_Delay_SWB_BWE = sub( Sample_Delay_SWB_BWE, NS2SA( inner_Fs, DELAY_FIR_RESAMPL_NS ) ); @@ -482,6 +485,7 @@ void swb_bwe_enc_ivas_fx( } Copy_Scale_sig( &yorig_fx[scl], &yorig_fx[scl], sub( inner_frame, scl ), exp ); Q_synth_hf = add( exp, Q_synth ); + test(); IF( EQ_16( st_fx->last_extl, SWB_BWE ) || EQ_16( st_fx->last_extl, FB_BWE ) ) { @@ -495,7 +499,7 @@ void swb_bwe_enc_ivas_fx( ELSE { Q_shb = shr( add( st_fx->EnergyLT_fx_exp, exp ), 1 ); - IF( EQ_16( s_and( exp, 0x0001 ), 1 ) ) + if ( EQ_16( s_and( exp, 0x0001 ), 1 ) ) { exp = sub( exp, 1 ); } @@ -514,7 +518,7 @@ void swb_bwe_enc_ivas_fx( { fb_band_begin = FB_BAND_BEGIN; move16(); - IF( EQ_16( st_fx->L_frame, L_FRAME ) ) + if ( EQ_16( st_fx->L_frame, L_FRAME ) ) { fb_band_begin = FB_BAND_BEGIN_12k8; move16(); @@ -612,16 +616,20 @@ void swb_bwe_enc_fx( Word16 Sample_Delay_HP; Word16 Sample_Delay_LP; Word16 idxGain = 0; + move16(); Word16 Q_synth_hf, Q_synth, Q_shb; Word16 tilt_nb_fx; Word16 SWB_fenv_fx[SWB_FENV]; Word32 ener_low_fx; Word32 energy_fbe_fb_fx = 0; + move32(); Word16 fb_ener_adjust_fx; Word16 ener_adjust_quan_fx = 0; + move16(); #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif FD_BWE_ENC_HANDLE hBWE_FD = st_fx->hBWE_FD; @@ -633,12 +641,16 @@ void swb_bwe_enc_fx( IF( EQ_16( st_fx->extl, FB_BWE ) ) { inner_frame = L_FRAME48k; + move16(); inner_Fs = 48000; + move32(); } ELSE { inner_frame = L_FRAME32k; + move16(); inner_Fs = 32000; + move32(); } set16_fx( old_input_fx, 0, add( NS2SA( inner_Fs, DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ), inner_frame ) ); @@ -659,6 +671,9 @@ void swb_bwe_enc_fx( delay_input_signal_fx( hBWE_FD->old_input_lp_fx, old_input_lp_fx, &old_input_16k_fx[L_INP_MEM], Sample_Delay_LP, L_FRAME16k, &hBWE_FD->prev_Q_input_lp, &Q_slb_speech ); } + move16(); + move16(); + move16(); Copy( hBWE_FD->new_input_hp_fx, new_input_hp_fx, Sample_Delay_HP ); Copy( shb_speech_fx, &new_input_hp_fx[Sample_Delay_HP], L_FRAME16k - Sample_Delay_HP ); @@ -678,6 +693,7 @@ void swb_bwe_enc_fx( * FB BWE encoding *---------------------------------------------------------------------*/ new_input_fx_exp = 0; + move16(); /* MDCT of the core synthesis signal */ wtda_fx( old_input_fx, &new_input_fx_exp, L_old_input_fx, hBWE_FD->L_old_wtda_swb_fx, &st_fx->Q_old_wtda, ALDO_WINDOW, ALDO_WINDOW, /* window overlap of current frame (0: full, 2: none, or 3: half) */ @@ -707,13 +723,12 @@ void swb_bwe_enc_fx( IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) { scl = 300; - move16(); } ELSE { scl = 240; - move16(); } + move16(); FOR( i = scl; i < inner_frame; i++ ) { max = s_max( max, abs_s( yorig_fx[i] ) ); @@ -742,11 +757,12 @@ void swb_bwe_enc_fx( ELSE { Q_shb = shr( add( st_fx->EnergyLT_fx_exp, exp ), 1 ); - IF( s_and( exp, 0x0001 ) == 1 ) + if ( EQ_16( s_and( exp, 0x0001 ), 1 ) ) { exp = sub( exp, 1 ); } st_fx->EnergyLT_fx = L_shl( st_fx->EnergyLT_fx, exp ); + move32(); } } ELSE @@ -791,7 +807,8 @@ void swb_bwe_enc_fx( L_tmp = Mult_32_16( ener_low_fx, tmp ); /*45-(exp+2*(Q_synth_hf-4)) + 2*(Q_synth_hf-4) - 15 = 30-exp */ exp1 = norm_l( L_tmp ); L_tmp = L_shl( L_tmp, exp1 ); - exp = 31 - exp1 - ( 30 - exp ); + // exp = 31 - exp1 - ( 30 - exp ); + exp = add( 31 - 30, sub( exp, exp1 ) ); L_tmp = Isqrt_lc( L_tmp, &exp ); /*31-exp */ fb_ener_adjust_fx = round_fx_o( L_shl_o( L_tmp, exp, &Overflow ), &Overflow ); /*Q15 */ } @@ -841,6 +858,7 @@ static Word16 WB_BWE_fenv_q_fx( /* o: quantized gain i ) { Word16 i, j, indx = 0; + move16(); Word32 dist, min_dist; const Word16 *pit = cb; /*Q10 */ Word16 tmp; @@ -897,6 +915,7 @@ static void get_normalize_spec_fx( set16_fx( SWB_signal, 0, add( HQ_GENERIC_HIGH0, offset ) ); calc_normal_length_fx( core, org_fx, mode, extl, &L_swb_norm, prev_L_swb_norm, Q_new_lf ); + test(); IF( EQ_16( extl, SWB_BWE ) || EQ_16( extl, FB_BWE ) ) { @@ -979,12 +998,14 @@ static Word16 FD_BWE_class_fx( /* o : FD BWE class ) { Word16 i, j, k, noise, sharpMod = 0; + move16(); Word16 peak, mag; Word32 mean[20]; Word16 sharpPeak; const Word16 *input_hi = 0; Word16 sharp; Word16 gain_tmp = 0; + move16(); Word16 mode; Word32 L_meanH, L_mean_d, L_tmp; Word16 sharplimit; @@ -992,9 +1013,8 @@ static Word16 FD_BWE_class_fx( /* o : FD BWE class Word16 numharmonic, tmp, expn, expd, scale; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; - move32(); -#endif move16(); +#endif FD_BWE_ENC_HANDLE hBWE_FD = st_fx->hBWE_FD; @@ -1020,7 +1040,6 @@ static Word16 FD_BWE_class_fx( /* o : FD BWE class IF( EQ_16( st_fx->extl, SWB_BWE ) || EQ_16( st_fx->extl, FB_BWE ) ) { input_hi = &fSpectrum[256]; - move16(); numsharp = NUM_SHARP; move16(); @@ -1056,7 +1075,7 @@ static Word16 FD_BWE_class_fx( /* o : FD BWE class { numharmonic = shl( numharmonic, 1 ); } - ELSE IF( EQ_16( hBWE_FD->prev_mode, NORMAL ) || EQ_16( hBWE_FD->prev_mode, NOISE ) ) + ELSE IF( EQ_16( hBWE_FD->prev_mode, NORMAL ) || hBWE_FD->prev_mode == NOISE ) { numharmonic = add( shr( numharmonic, 1 ), numharmonic ); } @@ -1080,7 +1099,6 @@ static Word16 FD_BWE_class_fx( /* o : FD BWE class ELSE IF( EQ_16( st_fx->extl, WB_BWE ) ) { input_hi = &fSpectrum[224]; - move16(); numsharp = 3; move16(); @@ -1116,7 +1134,7 @@ static Word16 FD_BWE_class_fx( /* o : FD BWE class FOR( j = 0; j < SHARP_WIDTH; j++ ) { mag = abs_s( *input_hi ); - IF( GT_16( mag, peak ) ) + if ( GT_16( mag, peak ) ) { peak = mag; move16(); /*Q_syn */ @@ -1133,7 +1151,7 @@ static Word16 FD_BWE_class_fx( /* o : FD BWE class L_tmp = L_sub( mean[i], peak ); /*Q_syn */ L_tmp = Mpy_32_16_1( L_tmp, 16913 ); /* 1/31->Q19 -> Q_syn+19-15 */ den = extract_l( L_shr( L_tmp, 4 ) ); /*Q_syn */ - IF( den == 0 ) + if ( den == 0 ) { den = 1; move16(); @@ -1161,12 +1179,13 @@ static Word16 FD_BWE_class_fx( /* o : FD BWE class move16(); } - IF( GT_16( sharp, sharpPeak ) ) + if ( GT_16( sharp, sharpPeak ) ) { sharpPeak = sharp; move16(); } } + test(); IF( EQ_16( st_fx->extl, SWB_BWE ) || EQ_16( st_fx->extl, FB_BWE ) ) { @@ -1176,13 +1195,12 @@ static Word16 FD_BWE_class_fx( /* o : FD BWE class IF( GE_16( k, numharmonic ) && GT_16( gain_tmp, 8192 ) && LT_16( gain_tmp, 29491 ) && GT_16( sharpPeak, shl( sharplimit, 10 ) ) ) { sharpMod = 1; - move16(); } ELSE { sharpMod = 0; - move16(); } + move16(); L_meanH = Mpy_32_16_1( L_meanH, 29127 ); /*Q_syn+8 */ L_mean_d = 0; @@ -1199,13 +1217,12 @@ static Word16 FD_BWE_class_fx( /* o : FD BWE class IF( GE_16( k, numharmonic ) && GT_16( sharpPeak, shl( sharplimit, 10 ) ) ) { sharpMod = 1; - move16(); } ELSE { sharpMod = 0; - move16(); } + move16(); } test(); @@ -1221,7 +1238,7 @@ static Word16 FD_BWE_class_fx( /* o : FD BWE class move16(); } - IF( GE_16( hBWE_FD->modeCount, 2 ) ) + if ( GE_16( hBWE_FD->modeCount, 2 ) ) { sharpMod = 1; move16(); @@ -1240,7 +1257,7 @@ static Word16 FD_BWE_class_fx( /* o : FD BWE class test(); test(); test(); - IF( GT_16( noise, 4 ) && ( LT_32( L_tmp, L_meanH ) || L_meanH == 0 ) && LT_16( tilt_nb, 10240 ) ) + if ( GT_16( noise, 4 ) && ( LT_32( L_tmp, L_meanH ) || L_meanH == 0 ) && LT_16( tilt_nb, 10240 ) ) { mode = NOISE; move16(); @@ -1522,7 +1539,7 @@ static Word16 vqSimple_w_fx( /* Reading the selected vector */ - Copy( &cb[i_mult( index, dim )], y, dim ); + Copy( &cb[index * dim], y, dim ); return ( index ); } @@ -1675,7 +1692,9 @@ static void msvq_interpol_fx( } ind_tmp[0] = vqSimple_w_fx( quant_tmp2, quant_tmp2, EnvCdbk1st_fx, w_env11, DIM1ST, N_CB1ST, 1 ); + move16(); ind_tmp[1] = vqSimple_w_fx( quant_tmp2 + DIM1ST, quant_tmp2 + DIM1ST, EnvCdbk2nd_fx, w_env11 + DIM1ST, DIM2ND, N_CB2ND, 1 ); + move16(); /* Extract vector for odd position */ FOR( n_band = 0; n_band < DIM11; n_band++ ) @@ -1711,10 +1730,10 @@ static void msvq_interpol_fx( { tmp = add_o( quant_tmp[n_band], quant_tmp[n_band + 1], &Overflow ); tmp = shr( tmp, 1 ); - quant_select[add( shl( n_band, 1 ), 1 )] = add( tmp, quant_tmp2[n_band] ); + quant_select[( n_band << 1 ) + 1] = add( tmp, quant_tmp2[n_band] ); move16(); /*Q8 */ } - quant_select[add( shl( n_band, 1 ), 1 )] = add( quant_tmp[n_band], quant_tmp2[n_band] ); + quant_select[( n_band << 1 ) + 1] = add( quant_tmp[n_band], quant_tmp2[n_band] ); move16(); /*Q8 */ L_dist = L_deposit_l( 0 ); @@ -1854,7 +1873,7 @@ static void msvq_interpol_2_fx( { tmp_q = add_o( quant_tmp[n_band - 1], quant_tmp[n_band], &Overflow ); tmp_q = shr( tmp_q, 1 ); - quant_select[sub( shl( n_band, 1 ), 1 )] = add_o( quant_tmp2[n_band], tmp_q, &Overflow ); + quant_select[( n_band << 1 ) - 1] = add_o( quant_tmp2[n_band], tmp_q, &Overflow ); } L_dist = L_deposit_l( 0 ); @@ -1867,7 +1886,7 @@ static void msvq_interpol_2_fx( } /* Check optimal candidate */ - IF( L_dist < L_minDist ) + IF( LT_32( L_dist, L_minDist ) ) { L_minDist = L_add( L_dist, 0 ); Copy( quant_select, synth_energy, SWB_FENV - 2 ); @@ -2239,29 +2258,26 @@ static void energy_control_fx( IF( NE_16( coder_type, AUDIO ) && LT_32( st_fx->total_brate, ACELP_8k85 ) ) { core_type = 0; - move16(); } ELSE { core_type = 1; - move16(); } + move16(); get_normalize_spec_fx( core, st_fx->extl, mode, core_type, org_fx, SWB_signal_fx, &( hBWE_FD->prev_L_swb_norm1 ), offset, Q_new_lf ); IF( EQ_16( st_fx->extl, WB_BWE ) ) { max_band = 4; - move16(); band_step = 2; - move16(); } ELSE { max_band = SWB_FENV; - move16(); band_step = 1; - move16(); } + move16(); + move16(); } ELSE /* HQ core */ { @@ -2274,13 +2290,12 @@ static void energy_control_fx( IF( EQ_16( offset, HQ_GENERIC_FOFFSET_32K ) ) { max_band = 12; - move16(); } ELSE { max_band = SWB_FENV; - move16(); } + move16(); } FOR( n_band = 0; n_band < max_band; ) @@ -2291,7 +2306,7 @@ static void energy_control_fx( IF( LT_16( SFM_gen_fx[n_band], mult_r( 24576, SFM_org_fx[n_band] ) ) ) { energy_factor_fx[n_band] = div_s( SFM_gen_fx[n_band], SFM_org_fx[n_band] ); /*Q15 */ - IF( LT_16( energy_factor_fx[n_band], gamma_fx ) ) + if ( LT_16( energy_factor_fx[n_band], gamma_fx ) ) { energy_factor_fx[n_band] = gamma_fx; move16(); @@ -2335,29 +2350,26 @@ static void energy_control_ivas_fx( IF( NE_16( coder_type, AUDIO ) && LE_32( st_fx->total_brate, ACELP_8k00 ) ) { core_type = 0; - move16(); } ELSE { core_type = 1; - move16(); } + move16(); get_normalize_spec_fx( core, st_fx->extl, mode, core_type, org_fx, SWB_signal_fx, &( hBWE_FD->prev_L_swb_norm1 ), offset, Q_new_lf ); IF( EQ_16( st_fx->extl, WB_BWE ) ) { max_band = 4; - move16(); band_step = 2; - move16(); } ELSE { max_band = SWB_FENV; - move16(); band_step = 1; - move16(); } + move16(); + move16(); } ELSE /* HQ core */ { @@ -2370,13 +2382,12 @@ static void energy_control_ivas_fx( IF( EQ_16( offset, HQ_GENERIC_FOFFSET_32K ) ) { max_band = 12; - move16(); } ELSE { max_band = SWB_FENV; - move16(); } + move16(); } FOR( n_band = 0; n_band < max_band; ) @@ -2388,7 +2399,7 @@ static void energy_control_ivas_fx( { energy_factor_fx[n_band] = div_s( SFM_gen_fx[n_band], SFM_org_fx[n_band] ); /*Q15 */ move16(); - IF( LT_16( energy_factor_fx[n_band], gamma_fx ) ) + if ( LT_16( energy_factor_fx[n_band], gamma_fx ) ) { energy_factor_fx[n_band] = gamma_fx; move16(); @@ -2459,6 +2470,7 @@ Word16 WB_BWE_encoding_fx( /* o : classification of wb exp = sub( sub( 30, exp ), ( sub( shl( Q_synth, 1 ), 2 ) ) ); L_tmp = Mpy_32_16( exp, tmp, 32767 ); /* Q16 */ WB_fenv_fx[i] = round_fx( L_shl( L_tmp, 10 ) ); /*Q10 */ + move16(); } ELSE { @@ -2587,6 +2599,7 @@ static Word16 SWB_BWE_encoding_fx( Word16 energy_factor_fx[SWB_FENV], w_env_fx[SWB_FENV]; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move16(); #endif FD_BWE_ENC_HANDLE hBWE_FD = st_fx->hBWE_FD; @@ -2595,13 +2608,12 @@ static Word16 SWB_BWE_encoding_fx( IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { L = L_SUBFR; - move16(); } ELSE { L = L_SUBFR16k; - move16(); } + move16(); /* HF transient detect */ IsTransient = detect_transient_fx( insig_hp_fx, L_FRAME16k, Q_shb, st_fx ); @@ -2619,7 +2631,7 @@ static Word16 SWB_BWE_encoding_fx( energy_fx = L_add( energy_fx, L_shr( L_mult0( insig_lp_fx[i + tmp], insig_lp_fx[i + tmp] ), 7 ) ); /*2*Q_slb_speech - 7 */ } - IF( GT_32( Mult_32_16( energy_fx, 5958 ), hBWE_FD->EnergyLF_fx ) ) + if ( GT_32( Mult_32_16( energy_fx, 5958 ), hBWE_FD->EnergyLF_fx ) ) { IsTransient_LF = 1; move16(); @@ -2670,7 +2682,6 @@ static Word16 SWB_BWE_encoding_fx( L_tmp = Mult_32_16( L_SWB_fenv_fx[n_band], tmp ); /*2*Q_synth-7+29-expd - 15 */ exp = norm_l( L_tmp ); tmp = Log2_norm_lc( L_shl( L_tmp, exp ) ); - move16(); exp = sub( sub( 30, exp ), sub( add( shl( Q_synth, 1 ), 7 ), expd ) ); L_tmp = Mpy_32_16( exp, tmp, 24660 ); /* Q14 */ /*10log10(2) in Q13 */ tmp = round_fx( L_shl( L_tmp, 10 ) ); /* Q8 */ @@ -2710,7 +2721,8 @@ static Word16 SWB_BWE_encoding_fx( L_tmp = L_deposit_h( tmp ); L_tmp = Isqrt_lc( L_tmp, &exp ); /*Q(31-exp) */ - SWB_tenv_fx[n_band] = round_fx_sat( L_shl_sat( L_tmp, sub( exp, 12 ) ) ); /*Q3 */ + SWB_tenv_fx[n_band] = round_fx_sat( L_shl_sat( L_tmp, sub( exp, 12 ) ) ); /*Q3*/ + move16(); } } @@ -2744,7 +2756,8 @@ static Word16 SWB_BWE_encoding_fx( IF( LT_16( Rat_tenv_fx, 8192 ) ) { - L_tmp = L_mult( Rat_tenv_fx, 19661 ); /*Q29 */ + L_tmp = L_mult( Rat_tenv_fx, 19661 ); /*Q29 */ + Rat_tenv_fx = round_fx_o( L_shl_o( L_tmp, 2, &Overflow ), &Overflow ); /*Q15 */ } ELSE IF( GT_16( Rat_tenv_fx, 16384 ) ) @@ -2812,6 +2825,7 @@ static Word16 SWB_BWE_encoding_fx( /*SWB_tenv_fx[pos] = add(SWB_tenv_fx[pos], mult_r(SWB_tenv_fx[pos], 164)); move16();//Q3 */ SWB_tenv_fx[pos] = round_fx_sat( L_mac_sat( L_mult_sat( SWB_tenv_fx[pos], 32767 ), SWB_tenv_fx[pos], 164 ) ); /*Q3 */ + move16(); IF( LT_32( energy_fx, SWB_tenv_fx[pos] ) ) { @@ -2836,6 +2850,7 @@ static Word16 SWB_BWE_encoding_fx( /*SWB_tenv_fx[n_band] = add(mult_r(SWB_tenv_fx[n_band-1], 16384), mult_r(SWB_tenv_fx[n_band], 16384)); move16();//Q3 */ SWB_tenv_fx[n_band] = round_fx_sat( L_mac_sat( L_mult( SWB_tenv_fx[n_band - 1], 16384 ), SWB_tenv_fx[n_band], 16384 ) ); /*Q3 */ } + move16(); } FOR( n_band = 0; n_band < SWB_TENV; n_band++ ) @@ -2883,6 +2898,7 @@ static Word16 SWB_BWE_encoding_fx( expn = sub( sub( 30, expn ), 19 ); L_tmp = Mpy_32_16( expn, tmp, 32767 ); /* Q16 */ /*1 in Q15 */ SWB_tenv_tmp_fx[n_band] = round_fx( L_shl( L_tmp, 11 ) ); /* Q11 */ + move16(); } IF( GT_16( SWB_tenv_tmp_fx[n_band], 30720 ) ) @@ -2947,6 +2963,7 @@ static Word16 SWB_BWE_encoding_fx( expn = sub( 30, add( expn, sub( shl( Q_synth, 1 ), 5 ) ) ); L_tmp = Mpy_32_16( expn, tmp, 24660 ); /* Q14 */ /*10log10(2) in Q13 */ SWB_fenv_fx[n_band] = round_fx( L_shl( L_tmp, 10 ) ); /* Q8 */ + move16(); } ELSE { @@ -3830,7 +3847,7 @@ static Word16 decision_hq_generic_class_fx_32( { a_fx = L_deposit_l( 0 ); p_fx = L_deposit_l( 0 ); - tmp2 = add( swb_bwe_subband[add( k, 1 )], hq_generic_offset ); + tmp2 = add( swb_bwe_subband[k + 1], hq_generic_offset ); FOR( i = add( swb_bwe_subband[k], hq_generic_offset ); i < tmp2; i++ ) { exp = norm_l( coefs_fx[i] ); @@ -3889,7 +3906,7 @@ void hq_generic_encoding_fx( Word16 indice[HQ_GENERIC_NVQIDX]; Word16 nenv; - Word16 energy_factor_fx[SWB_FENV] = { 0 }; + Word16 energy_factor_fx[SWB_FENV]; Word16 cs, exp, tmp, tmp2; Word32 energy_fx; Word32 L_tmp, max_coefs_fx; @@ -3897,6 +3914,7 @@ void hq_generic_encoding_fx( HQ_ENC_HANDLE hHQ_core = st_fx->hHQ_core; BSTR_ENC_HANDLE hBstr = st_fx->hBstr; + set16_fx( energy_factor_fx, 0, SWB_FENV ); IF( LE_16( hq_generic_offset, HQ_GENERIC_FOFFSET_24K4 ) ) { @@ -3921,6 +3939,7 @@ void hq_generic_encoding_fx( ELSE { *hq_generic_exc_clas = decision_hq_generic_class_fx_32( coefs_fx, hq_generic_offset ); + move16(); push_indice_fx( hBstr, IND_HQ_SWB_EXC_SP_CLAS, 0, 1 ); push_indice_fx( hBstr, IND_HQ_SWB_EXC_CLAS, *hq_generic_exc_clas, 1 ); } @@ -3930,7 +3949,7 @@ void hq_generic_encoding_fx( energy_fx = L_deposit_l( 0 ); max_coefs_fx = L_deposit_l( 0 ); tmp2 = add( swb_bwe_subband[n_band + 1], hq_generic_offset ); - FOR( n_coeff = add( swb_bwe_subband[n_band], hq_generic_offset ); n_coeff < tmp2; n_coeff++ ) + FOR( n_coeff = swb_bwe_subband[n_band] + hq_generic_offset; n_coeff < tmp2; n_coeff++ ) { IF( LT_32( max_coefs_fx, L_abs( coefs_fx[n_coeff] ) ) ) { @@ -3939,7 +3958,7 @@ void hq_generic_encoding_fx( } cs = norm_l( max_coefs_fx ); tmp2 = add( swb_bwe_subband[n_band + 1], hq_generic_offset ); - FOR( n_coeff = add( swb_bwe_subband[n_band], hq_generic_offset ); n_coeff < tmp2; n_coeff++ ) + FOR( n_coeff = swb_bwe_subband[n_band] + hq_generic_offset; n_coeff < tmp2; n_coeff++ ) { tmp = extract_h( L_shl( coefs_fx[n_coeff], cs ) ); /*12 + cs - 16 */ L_tmp = L_mult0( tmp, tmp ); /*2*cs - 8 */ @@ -3957,6 +3976,7 @@ void hq_generic_encoding_fx( L_tmp = Mpy_32_16( exp, tmp, 24660 ); /* Q14 */ /*10log10(2) in Q13 */ hq_generic_fenv_fx[n_band] = round_fx( L_shl( L_tmp, 10 ) ); /*Q8 */ + move16(); } ELSE { @@ -3980,7 +4000,7 @@ void hq_generic_encoding_fx( } } cs = norm_l( max_coefs_fx ); - tmp2 = fb_bwe_subband[add( n_band, 1 )]; + tmp2 = fb_bwe_subband[n_band + 1]; FOR( n_coeff = fb_bwe_subband[n_band]; n_coeff < tmp2; n_coeff++ ) { tmp = extract_h( L_shl( coefs_fx[n_coeff], cs ) ); /*12 + cs - 16 */ @@ -3996,12 +4016,13 @@ void hq_generic_encoding_fx( tmp = Log2_norm_lc( L_shl( L_tmp, exp ) ); exp = sub( 30, add( exp, 2 * cs - 13 ) ); - L_tmp = Mpy_32_16( exp, tmp, 24660 ); /* Q14 */ /*10log10(2) in Q13 */ - hq_generic_fenv_fx[add( n_band, nenv )] = round_fx( L_shl( L_tmp, 10 ) ); /*Q8 */ + L_tmp = Mpy_32_16( exp, tmp, 24660 ); /* Q14 */ /*10log10(2) in Q13 */ + hq_generic_fenv_fx[n_band + nenv] = round_fx( L_shl( L_tmp, 10 ) ); /*Q8 */ + move16(); } ELSE { - hq_generic_fenv_fx[add( n_band, nenv )] = -24576; + hq_generic_fenv_fx[n_band + nenv] = -24576; move16(); } } @@ -4012,13 +4033,15 @@ void hq_generic_encoding_fx( FOR( n_band = 0; n_band < nenv; n_band++ ) { hq_generic_fenv_fx[n_band] = sub( hq_generic_fenv_fx[n_band], Mean_env_fx[n_band] ); + move16(); } IF( st_fx->bwidth == FB ) { FOR( n_band = 0; n_band < DIM_FB; n_band++ ) { - hq_generic_fenv_fx[add( n_band, nenv )] = sub( shr( hq_generic_fenv_fx[add( n_band, nenv )], 1 ), Mean_env_fb_fx[n_band] ); + hq_generic_fenv_fx[n_band + nenv] = sub( shr( hq_generic_fenv_fx[n_band + nenv], 1 ), Mean_env_fb_fx[n_band] ); + move16(); } } @@ -4036,6 +4059,7 @@ void hq_generic_encoding_fx( IF( EQ_16( st_fx->bwidth, FB ) ) { indice[5] = vqSimple_w_fx( hq_generic_fenv_fx + nenv, hq_generic_fenv_fx + nenv, EnvCdbkFB_fx, NULL, DIM_FB, N_CB_FB, 0 ); + move16(); } push_indice_fx( hBstr, IND_SWB_FENV_HQ, indice[0], 5 ); @@ -4066,6 +4090,7 @@ void hq_generic_encoding_fx( tmp = extract_l( Pow2( 13, tmp ) ); exp = sub( exp, 13 ); hq_generic_fenv_fx[n_band] = shl_sat( tmp, add( exp, 1 ) ); /*1 */ + move16(); } @@ -4073,13 +4098,14 @@ void hq_generic_encoding_fx( { FOR( n_band = 0; n_band < DIM_FB; n_band++ ) { - tmp = add( hq_generic_fenv_fx[add( n_band, nenv )], Mean_env_fb_fx[n_band] ); /*7 */ - L_tmp = L_mult( tmp, 21771 ); /*25 */ - L_tmp = L_shr( L_tmp, 9 ); /*16 */ + tmp = add( hq_generic_fenv_fx[n_band + nenv], Mean_env_fb_fx[n_band] ); /*7 */ + L_tmp = L_mult( tmp, 21771 ); /*25 */ + L_tmp = L_shr( L_tmp, 9 ); /*16 */ L_Extract( L_tmp, &exp, &tmp ); tmp = extract_l( Pow2( 13, tmp ) ); exp = sub( exp, 13 ); - hq_generic_fenv_fx[add( n_band, nenv )] = shl( tmp, add( exp, 1 ) ); /*2 */ + hq_generic_fenv_fx[n_band + nenv] = shl( tmp, add( exp, 1 ) ); /*2 */ + move16(); } } @@ -4219,6 +4245,7 @@ void hq_generic_hf_encoding_fx( L_tmp = Mpy_32_16( exp, tmp, 24660 ); /* Q14 */ /*10log10(2) in Q13 */ hq_generic_fenv_fx[n_band] = round_fx( L_shl( L_tmp, 10 ) ); /*Q8 */ + move16(); } ELSE { @@ -4258,13 +4285,13 @@ void hq_generic_hf_encoding_fx( tmp = Log2_norm_lc( L_shl( L_tmp, exp ) ); exp = sub( 30, add( exp, sub( shl( cs, 1 ), 13 ) ) ); - L_tmp = Mpy_32_16( exp, tmp, 24660 ); /* Q14 */ /*10log10(2) in Q13 */ - hq_generic_fenv_fx[add( n_band, nenv )] = round_fx( L_shl( L_tmp, 10 ) ); /*Q8 */ + L_tmp = Mpy_32_16( exp, tmp, 24660 ); /* Q14 */ /*10log10(2) in Q13 */ + hq_generic_fenv_fx[n_band + nenv] = round_fx( L_shl( L_tmp, 10 ) ); /*Q8 */ move16(); } ELSE { - hq_generic_fenv_fx[add( n_band, nenv )] = -24576; + hq_generic_fenv_fx[n_band + nenv] = -24576; move16(); } } @@ -4282,7 +4309,7 @@ void hq_generic_hf_encoding_fx( { FOR( n_band = 0; n_band < DIM_FB; n_band++ ) { - hq_generic_fenv_fx[add( n_band, nenv )] = sub( shr( hq_generic_fenv_fx[add( n_band, nenv )], 1 ), Mean_env_fb_fx[n_band] ); + hq_generic_fenv_fx[n_band + nenv] = sub( shr( hq_generic_fenv_fx[n_band + nenv], 1 ), Mean_env_fb_fx[n_band] ); move16(); } } @@ -4300,15 +4327,15 @@ void hq_generic_hf_encoding_fx( IF( EQ_16( length, L_SPEC48k ) ) { - Word16 sf = getScaleFactor16( hq_generic_fenv_fx, DIM_FB + nenv ); - Scale_sig( hq_generic_fenv_fx, DIM_FB + nenv, negate( sf ) ); + Word16 sf = getScaleFactor16( hq_generic_fenv_fx, add( DIM_FB, nenv ) ); + Scale_sig( hq_generic_fenv_fx, add( DIM_FB, nenv ), negate( sf ) ); Copy_Scale_sig( EnvCdbkFB_fx, EnvCdbkFB_fx_loc, N_CB_FB * DIM_FB, negate( sf ) ); // Scaling done to handel overflow inside vqSimple_w_fx indice[5] = vqSimple_w_fx( hq_generic_fenv_fx + nenv, hq_generic_fenv_fx + nenv, EnvCdbkFB_fx_loc, NULL, DIM_FB, N_CB_FB, 0 ); move16(); - Scale_sig( hq_generic_fenv_fx, DIM_FB + nenv, sf ); + Scale_sig( hq_generic_fenv_fx, add( DIM_FB, nenv ), sf ); } push_indice( hBstr, IND_SWB_FENV_HQ, indice[0], 5 ); @@ -4347,13 +4374,13 @@ void hq_generic_hf_encoding_fx( { FOR( n_band = 0; n_band < DIM_FB; n_band++ ) { - tmp = add( hq_generic_fenv_fx[add( n_band, nenv )], Mean_env_fb_fx[n_band] ); /*7 */ - L_tmp = L_mult( tmp, 21771 ); /*25 */ - L_tmp = L_shr( L_tmp, 9 ); /*16 */ + tmp = add( hq_generic_fenv_fx[n_band + nenv], Mean_env_fb_fx[n_band] ); /*7 */ + L_tmp = L_mult( tmp, 21771 ); /*25 */ + L_tmp = L_shr( L_tmp, 9 ); /*16 */ L_Extract( L_tmp, &exp, &tmp ); tmp = extract_l( Pow2( 13, tmp ) ); exp = sub( exp, 13 ); - hq_generic_fenv_fx[add( n_band, nenv )] = shl( tmp, add( exp, 1 ) ); /*1 */ + hq_generic_fenv_fx[n_band + nenv] = shl( tmp, add( exp, 1 ) ); /*1 */ move16(); } } diff --git a/lib_enc/swb_bwe_enc_hr_fx.c b/lib_enc/swb_bwe_enc_hr_fx.c index bfbaa1d7ee57a275c66d2d34480154d10dbb44aa..fd4a9f1259669e751e5164a7814c623739939c11 100644 --- a/lib_enc/swb_bwe_enc_hr_fx.c +++ b/lib_enc/swb_bwe_enc_hr_fx.c @@ -4,10 +4,9 @@ #include #include #include "options.h" -#include "cnst.h" /* Common constants */ -#include "rom_enc.h" /* Encoder static table prototypes */ -#include "rom_com_fx.h" /* Static table prototypes */ -//#include "prot_fx.h" /* Function prototypes */ +#include "cnst.h" /* Common constants */ +#include "rom_enc.h" /* Encoder static table prototypes */ +#include "rom_com_fx.h" /* Static table prototypes */ #include "rom_com.h" /* Common constants */ #include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ @@ -120,6 +119,7 @@ void swb_bwe_enc_hr_fx( #endif #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move16(); #endif FD_BWE_ENC_HANDLE hBWE_FD = st_fx->hBWE_FD; BSTR_ENC_HANDLE hBstr = st_fx->hBstr; @@ -132,9 +132,7 @@ void swb_bwe_enc_hr_fx( /* Use 32 Bits Buffer to Store Two 16 Bits Vectors in Order to Save Stack Space */ t_audio_fx = (Word16 *) &t_audio32[0]; - move16(); t_audio_tmp_fx = (Word16 *) &t_audio32[L_FRAME48k / 2]; - move16(); ind2 = 0; move16(); /* only to suppress warnings */ @@ -185,6 +183,7 @@ void swb_bwe_enc_hr_fx( Copy_Scale_sig( new_input_fx, t_audio_fx, input_frame, temp ); /* Bring Energy in 2*Q'exp1' */ st_fx->EnergyLT_fx = L_shl( st_fx->EnergyLT_fx, shl( sub( exp1, st_fx->EnergyLT_fx_exp ), 1 ) ); + move32(); is_transient = detect_transient_fx( t_audio_fx, input_frame, exp1, st_fx ); st_fx->EnergyLT_fx_exp = exp1; @@ -201,6 +200,7 @@ void swb_bwe_enc_hr_fx( st_fx->Q_old_wtda = new_input_fx_exp; move16(); new_input_fx_exp = 0; + move16(); wtda_fx( new_input_fx, &new_input_fx_exp, L_t_audio_tmp_fx, hBWE_FD->L_old_wtda_swb_fx, &st_fx->Q_old_wtda, ALDO_WINDOW, ALDO_WINDOW, input_frame ); @@ -246,7 +246,6 @@ void swb_bwe_enc_hr_fx( scl = 99; move16(); ptr16 = &t_audio_fx[NUM_TRANS_START_FREQ_COEF]; - move16(); FOR( k = 0; k < input_frame; k += temp ) { /* from t_audio_fx[k..NUM_TRANS_START_FREQ_COEF+k-1] will be zeroed out */ @@ -314,8 +313,7 @@ void swb_bwe_enc_hr_fx( nBits = sub( nBits, NBITS_GLOB_GAIN_BWE_HR ); /* normalization with global gain */ - ptr16 = &t_audio_fx[add( NUM_TRANS_START_FREQ_COEF, temp )]; - move16(); + ptr16 = &t_audio_fx[NUM_TRANS_START_FREQ_COEF + temp]; temp2 = negate( exp1 ); gain2_fx = Invert16( gain1_fx, &temp2 ); @@ -326,6 +324,7 @@ void swb_bwe_enc_hr_fx( L_temp = L_mult( *ptr16, gain2_fx ); L_temp = L_shr( L_temp, temp2 ); *ptr16++ = round_fx( L_temp ); + move16(); } FOR( ; i < L_FRAME32k / NUM_TIME_SWITCHING_BLOCKS - NUM_TRANS_START_FREQ_COEF; i++ ) { @@ -339,14 +338,14 @@ void swb_bwe_enc_hr_fx( *---------------------------------------------------------------------*/ /* compute energy per band */ - ptr16 = &t_audio_fx[add( temp, NUM_TRANS_START_FREQ_COEF )]; - move16(); + ptr16 = &t_audio_fx[temp + NUM_TRANS_START_FREQ_COEF]; FOR( i = 0; i < N_BANDS_TRANS_BWE_HR; i++ ) { L_temp = Calc_Energy_Autoscaled( ptr16, t_audio_fx_exp, WIDTH_TRANS_FREQ_COEF, &temp2 ); ptr16 += WIDTH_TRANS_FREQ_COEF; L_temp = Sqrt_Ratio32( L_temp, temp2, WIDTH_TRANS_FREQ_COEF, /*WIDTH_TRANS_FREQ_COEF is in Q0*/ 0, &temp2 ); en_band_fx[i] = round_fx_sat( L_shr_sat( L_temp, sub( 15 - 9, temp2 ) ) ); + move16(); } /* Q energy per band */ @@ -364,12 +363,10 @@ void swb_bwe_enc_hr_fx( IF( LT_16( ind2, NUM_ENVLOPE_CODE_HR_TR2 ) ) { ind1 = en_band_quant_fx( en_band_fx, swb_hr_env_code3_fx, NUM_ENVLOPE_CODE_HR_TR2 ); - move16(); } ELSE { ind1 = en_band_quant_fx( en_band_fx, swb_hr_env_code3_fx + ( NUM_ENVLOPE_CODE_HR_TR2 * 2 ), NUM_ENVLOPE_CODE_HR_TR2 ); - move16(); } push_indice_fx( hBstr, IND_HR_ENVELOPE, ind1, NBITS_ENVELOPE_BWE_HR_TR - 1 ); @@ -377,8 +374,7 @@ void swb_bwe_enc_hr_fx( } /* normalize spectrum per bands */ - ptr16 = &t_audio_fx[add( temp, NUM_TRANS_START_FREQ_COEF )]; - move16(); + ptr16 = &t_audio_fx[temp + NUM_TRANS_START_FREQ_COEF]; FOR( i = 0; i < N_BANDS_TRANS_BWE_HR; i++ ) { temp2 = 9; @@ -390,6 +386,7 @@ void swb_bwe_enc_hr_fx( L_temp = L_mult( *ptr16, gain2_fx ); L_temp = L_shr( L_temp, temp2 ); *ptr16++ = round_fx( L_temp ); + move16(); } } @@ -515,7 +512,6 @@ void swb_bwe_enc_hr_fx( /* normalization with global gain */ ptr16 = &t_audio_fx[NUM_NONTRANS_START_FREQ_COEF]; - move16(); /* Find Max Scaling on Remaining Frequencies */ temp2 = Find_Max_Norm16( ptr16, NUM_NONTRANS_END_FREQ_COEF - NUM_NONTRANS_START_FREQ_COEF ); temp2 = s_max( 0, sub( temp2, NON_TRANSIENT_RESCALE_Q_GUARD ) ); @@ -529,6 +525,7 @@ void swb_bwe_enc_hr_fx( L_temp = L_mult( *ptr16, temp ); L_temp = L_shr( L_temp, temp2 ); *ptr16++ = round_fx( L_temp ); + move16(); } /*---------------------------------------------------------------------* @@ -537,13 +534,13 @@ void swb_bwe_enc_hr_fx( /* compute energy per band */ ptr16 = &t_audio_fx[NUM_NONTRANS_START_FREQ_COEF]; - move16(); FOR( i = 0; i < N_BANDS_BWE_HR; i++ ) { L_temp = Calc_Energy_Autoscaled( ptr16, t_audio_fx_exp, WIDTH_NONTRANS_FREQ_COEF, &temp2 ); ptr16 += WIDTH_NONTRANS_FREQ_COEF; L_temp = Sqrt_Ratio32( L_temp, temp2, WIDTH_NONTRANS_FREQ_COEF, /*WIDTH_TRANS_FREQ_COEF is in Q0*/ 0, &temp2 ); en_band_fx[i] = round_fx_sat( L_shr_sat( L_temp, sub( 15 - 9, temp2 ) ) ); /* Put in Q9 */ + move16(); } /* Q energy per band */ @@ -558,7 +555,6 @@ void swb_bwe_enc_hr_fx( /* normalize spectrum per bands */ ptr32 = &L_t_audio_tmp_fx[0]; ptr16 = &t_audio_fx[NUM_NONTRANS_START_FREQ_COEF]; - move16(); FOR( i = 0; i < N_BANDS_BWE_HR; i++ ) { temp2 = 9; @@ -704,7 +700,6 @@ void swb_bwe_enc_hr_fx( { /* select spectrum of the second stage coding */ ptr16 = &t_audio_fx[0]; - move16(); FOR( i = 0; i < Nsv; i++ ) { IF( nq[i] == 0 ) @@ -726,6 +721,7 @@ void swb_bwe_enc_hr_fx( L_temp = L_deposit_l( t_audio_tmp_fx[i * WIDTH_BAND + j] ); L_temp = L_msu0( L_temp, temp2, x_norm_fx[i * WIDTH_BAND + j] ); *ptr16++ = extract_l( L_temp ); + move16(); } } } @@ -747,10 +743,10 @@ void swb_bwe_enc_hr_fx( /* Nsv2 * 12 <= nBits (Nsv2 is not too high) AND */ /* nBits - Nsv2 * 12 < 12 (Nsv2 is the highest divisor) */ L_temp = L_msu0( L_deposit_l( nBits ), 12, Nsv2 ); - if ( GE_32( L_temp, 12L ) ) - Nsv2 = add( Nsv2, 1 ); - if ( L_temp < 0 ) - Nsv2 = sub( Nsv2, 1 ); + IF( GE_32( L_temp, 12L ) ) + Nsv2 = add( Nsv2, 1 ); + IF( L_temp < 0 ) + Nsv2 = sub( Nsv2, 1 ); } /* second stage global gain estimation and coding */ diff --git a/lib_enc/swb_bwe_enc_lr_fx.c b/lib_enc/swb_bwe_enc_lr_fx.c index 461202c61db37dc6a7d481ada5edd1244ca1599c..c324b9ac9f4a95b180b9b1f756c709f85a934404 100644 --- a/lib_enc/swb_bwe_enc_lr_fx.c +++ b/lib_enc/swb_bwe_enc_lr_fx.c @@ -92,9 +92,11 @@ static Word16 GetSubbandCorrIndex2_har_fx( /* o : #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move16(); #endif exp_safe_e = 4; + move16(); L_tmp = L_deposit_l( 0 ); FOR( i = 0; i < fLen; i++ ) @@ -107,6 +109,7 @@ static Word16 GetSubbandCorrIndex2_har_fx( /* o : FOR( i = 0; i < fLen; i++ ) { ibuf_fx[i] = extract_h( L_shl( L_inBuf[i], exp_shift ) ); /* Qi+exp_shift-16 */ + move16(); } FOR( i = 0; i < predBufLen; i++ ) @@ -266,6 +269,7 @@ static void getswbindices_har_fx( { /*nlags[sb] = (short)pow(2, bits_lagIndices_mode0_Har[sb]); */ nlags_fx[sb] = shl( 1, bits_lagIndices_mode0_Har[sb] ); + move16(); } j = 0; @@ -277,6 +281,7 @@ static void getswbindices_har_fx( sbWidth_fx[sb], &n_nbiggestsearch_fx[sb], N_NBIGGEST_PULSEARCH ); search_offset_fx[sb] = subband_search_offset_fx[sb]; + move16(); j = add( j, N_NBIGGEST_PULSEARCH ); } @@ -303,7 +308,8 @@ static void getswbindices_har_fx( FOR( j = add( search_offset_fx[sb], shr( nlags_fx[sb], 1 ) ); j > tmp; j-- ) { low_freqsgnl_fx[k] = y2_fx[j]; - k = add( k, 1 ); + move16(); + k++; } } /* correlation b/w HF spectrum Group1 of length sbLen and decoded LF spectrum */ @@ -313,6 +319,7 @@ static void getswbindices_har_fx( add( sbWidth_fx[sb], nlags_fx[sb] ), nlags_fx[sb], Nbiggest_fx + ( sb * N_NBIGGEST_PULSEARCH ), n_nbiggestsearch_fx[sb], &prev_frame_bstindx_fx[sb] ); + move16(); } return; @@ -416,8 +423,10 @@ static Word16 GetSubbandCorrIndex2_pulsestep_fx( } /* Get the initial energy for zero lag */ + test(); WHILE( *ptr_predBuf == 0 && LT_16( absPos_fx, ssearch_buflim ) ) { + test(); ptr_predBuf++; absPos_fx = add( absPos_fx, 1 ); } @@ -510,9 +519,10 @@ static Word16 GetSubbandCorrIndex2_pulsestep_fx( ptr_predBuf++; ptr_ssBuf_ni_fx++; absPos_fx++; - + test(); WHILE( *ptr_predBuf == 0 && LT_16( absPos_fx, ssearch_buflim ) ) { + test(); ptr_predBuf++; ptr_ssBuf_ni_fx++; absPos_fx = add( absPos_fx, 1 ); @@ -530,7 +540,7 @@ static Word16 GetSubbandCorrIndex2_pulsestep_fx( } } - IF( EQ_16( ib_flag_fx, 1 ) ) + if ( EQ_16( ib_flag_fx, 1 ) ) { bestIdx_fx = 0; move16(); @@ -598,6 +608,7 @@ static void GetSWBIndices_fx( } sspectra_ma_fx[0] = add( shr( predBuf_ni_fx[0], 1 ), shr( predBuf_ni_fx[1], 1 ) ); + move16(); tmp = sub( predBufLen, 1 ); FOR( sb = 1; sb < tmp; sb++ ) { @@ -606,8 +617,10 @@ static void GetSWBIndices_fx( L_temp = L_add( L_temp, L_mult( predBuf_ni_fx[sb - 1], 10922 ) ); L_temp = L_add( L_temp, L_mult( predBuf_ni_fx[sb + 1], 10922 ) ); /* Qss+15+1 */ sspectra_ma_fx[sb] = round_fx( L_temp ); + move16(); } sspectra_ma_fx[sb] = add( shr( predBuf_ni_fx[sb - 1], 1 ), shr( predBuf_ni_fx[sb], 1 ) ); + move16(); /* Partial search for rest of subbands except the last which is fixed */ FOR( sb = 0; sb < nBands_search; sb++ ) @@ -621,6 +634,7 @@ static void GetSWBIndices_fx( sbLen, nlags_fx[sb], gi_fx + ( sb * N_NBIGGEST_PULSEARCH ), n_nbiggestsearch_fx[sb], ssearch_buflim_fx, predBuf_ni_fx + search_offset_fx[sb] ); + move16(); } } /*--------------------------------------------------------------------------* @@ -686,6 +700,7 @@ static void gethar_noisegn_fx( Word16 Qg; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move16(); #endif /*Generate HF noise*/ genhf_noise_fx( noise_flr_fx, Qss, L_xSynth_har, QsL, sspectra_fx, bands, har_bands, har_freq_est2, pos_max_hfe2, pul_res_fx, pk_sf_fx, fLenLow, @@ -700,6 +715,7 @@ static void gethar_noisegn_fx( } L_temp = 0x0; + move32(); FOR( i = 0; i < fLenHigh; i++ ) { L_temp = L_or( L_temp, L_abs( L_hfspec[i] ) ); @@ -708,9 +724,11 @@ static void gethar_noisegn_fx( FOR( i = 0; i < fLenHigh; i++ ) { L_hfspec_sft[i] = L_shl( L_hfspec[i], exp_norm_g1 ); + move32(); } L_temp = 0x0; + move32(); FOR( i = 0; i < fLenHigh; i++ ) { L_temp = L_or( L_temp, L_abs( L_xSynth_har[i] ) ); @@ -719,6 +737,7 @@ static void gethar_noisegn_fx( FOR( i = 0; i < fLenHigh; i++ ) { L_xSynth_har_sft[i] = L_shl( L_xSynth_har[i], exp_norm_g2 ); + move32(); } exp_safe = 4; @@ -897,7 +916,7 @@ static void EncodeSWBSubbands_fx( IF( flag_dis == 0 ) { test(); - if ( NE_16( har_freq_est2, SWB_HAR_RAN1 ) || NE_16( har_freq_est2, *prev_frm_hfe2 ) ) + IF( NE_16( har_freq_est2, SWB_HAR_RAN1 ) || NE_16( har_freq_est2, *prev_frm_hfe2 ) ) { har_freq_est2 = add( har_freq_est2, lagIndices_fx[0] ); move16(); @@ -966,14 +985,17 @@ static void EncodeSWBSubbands_fx( FOR( k = 0; k < NB_SWB_SUBBANDS; k++ ) { lagGains_fx[k] = mult_r( lagGains_fx[k], 29491 ); /* lagGains[k]*0.9f; */ + move16(); } FOR( k = 0; k < NB_SWB_SUBBANDS; k++ ) { L_th_g[k] = L_deposit_l( 0 ); + move32(); IF( p2a_flags_fx[BANDS_fx - NB_SWB_SUBBANDS + k] == 0 ) { L_th_g[k] = L_shl( L_mult( lagGains_fx[k], ss_min_fx ), sub( QsL, add( add( QlagGains[k], Qss ), 1 ) ) ); /* QlagGain+Qss -> QsL */ + move32(); } } @@ -1092,7 +1114,7 @@ static void EncodeSWBSubbands_ivas_fx( IF( flag_dis == 0 ) { test(); - if ( NE_16( har_freq_est2, SWB_HAR_RAN1 ) || NE_16( har_freq_est2, *prev_frm_hfe2 ) ) + IF( NE_16( har_freq_est2, SWB_HAR_RAN1 ) || NE_16( har_freq_est2, *prev_frm_hfe2 ) ) { har_freq_est2 = add( har_freq_est2, lagIndices_fx[0] ); move16(); @@ -1161,14 +1183,17 @@ static void EncodeSWBSubbands_ivas_fx( FOR( k = 0; k < NB_SWB_SUBBANDS; k++ ) { lagGains_fx[k] = mult_r( lagGains_fx[k], 29491 ); /* lagGains[k]*0.9f; */ + move16(); } FOR( k = 0; k < NB_SWB_SUBBANDS; k++ ) { L_th_g[k] = L_deposit_l( 0 ); + move32(); IF( p2a_flags_fx[BANDS_fx - NB_SWB_SUBBANDS + k] == 0 ) { L_th_g[k] = L_shl( L_mult( lagGains_fx[k], ss_min_fx ), sub( QsL, add( add( QlagGains[k], Qss ), 1 ) ) ); /* QlagGain+Qss -> QsL */ + move32(); } } @@ -1284,6 +1309,7 @@ void swb_bwe_enc_lr_fx( FOR( k = 0; k < swb_lowband_fx; k++ ) { L_m[k] = L_deposit_l( 0 ); + move32(); } return; @@ -1367,6 +1393,7 @@ void swb_bwe_enc_lr_ivas_fx( FOR( k = 0; k < swb_lowband_fx; k++ ) { L_m[k] = L_deposit_l( 0 ); + move32(); } return; diff --git a/lib_enc/swb_pre_proc_fx.c b/lib_enc/swb_pre_proc_fx.c index 7d1ffe9a4683b0cc25de43222cdb7074575fdbb0..3e013815ece82120f479c1aa0c806a9882502e2c 100644 --- a/lib_enc/swb_pre_proc_fx.c +++ b/lib_enc/swb_pre_proc_fx.c @@ -311,8 +311,7 @@ void wb_pre_proc_ivas_fx( hb_speech and the two decimator memories are in Q_wb_sp */ IF( EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) ) { - Sample_Delay_WB_BWE = NS2SA( 16000, DELAY_FD_BWE_ENC_12k8_NS ); - move16(); + Sample_Delay_WB_BWE = NS2SA_FX2( 16000, DELAY_FD_BWE_ENC_12k8_NS ); IF( EQ_16( last_element_mode, IVAS_CPE_TD ) ) { @@ -348,7 +347,7 @@ void wb_pre_proc_ivas_fx( move16(); Word16 l_recalc_4k = ( L_MEM_RECALC_16K + L_FILT16k + 1 ) / 4; move16(); - Sample_Delay_WB_BWE = NS2SA( 16000, DELAY_FD_BWE_ENC_12k8_NS ); + Sample_Delay_WB_BWE = NS2SA_FX2( 16000, DELAY_FD_BWE_ENC_12k8_NS ); IF( EQ_16( last_element_mode, IVAS_CPE_DFT ) ) { @@ -392,7 +391,7 @@ void wb_pre_proc_ivas_fx( Word16 l_recalc_16k = L_FILT16k + 1; /* Note: "+1" is used because L_FILT16k is not divisible by 4 */ Word16 l_recalc_4k = ( L_FILT16k + 1 ) / 4; - Sample_Delay_WB_BWE = NS2SA( 16000, DELAY_FD_BWE_ENC_12k8_NS ); + Sample_Delay_WB_BWE = NS2SA_FX2( 16000, DELAY_FD_BWE_ENC_12k8_NS ); /*Get past signal*/ Copy_Scale_sig( hBWE_FD->L_old_wtda_swb_fx + L_FRAME16k - l_recalc_16k, old_input, l_recalc_16k, Q_wb_sp ); diff --git a/lib_enc/swb_tbe_enc_fx.c b/lib_enc/swb_tbe_enc_fx.c index efb622773bf855040d200c37a829b019cca039cc..69db66b1b7fb43c9deae0888258a1803c699f666 100644 --- a/lib_enc/swb_tbe_enc_fx.c +++ b/lib_enc/swb_tbe_enc_fx.c @@ -6,7 +6,6 @@ #include #include "options.h" #include "cnst.h" -//#include "prot_fx.h" #include "rom_com_fx.h" #include "rom_com.h" #include "prot.h" /* Function prototypes */ @@ -142,8 +141,11 @@ void find_max_mem_enc( Word16 i; Word16 n_mem_32; Word16 max = 0; + move16(); Word32 Lmax = 0; + move32(); Word16 tempQ15, max2 = 0; + move16(); TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; /* old BWE exc max */ @@ -185,9 +187,13 @@ void find_max_mem_enc( /* for total_brate > 16.4kbps, use n_mem2; else account for the max2 for n_mem calculation */ *n_mem2 = norm_s( max2 ); + move16(); if ( max2 == 0 ) + { *n_mem2 = 15; - if ( LT_32( st_fx->total_brate, ACELP_24k40 ) ) + move16(); + } + IF( LT_32( st_fx->total_brate, ACELP_24k40 ) ) { max = s_max( max, max2 ); } @@ -212,9 +218,11 @@ void find_max_mem_enc( } /* estimate the norm for 16-bit memories */ *n_mem = norm_s( max ); + move16(); if ( max == 0 ) { *n_mem = 15; + move16(); } /* estimate the norm for 32-bit memories */ @@ -224,10 +232,12 @@ void find_max_mem_enc( if ( Lmax == 0 ) { n_mem_32 = 31; + move16(); } tempQ15 = sub( s_min( *n_mem, n_mem_32 ), 1 ); *n_mem = s_max( tempQ15, 0 ); + move16(); } @@ -706,6 +716,8 @@ void wb_tbe_enc_fx( Word16 lpc_wb[LPC_SHB_ORDER_WB + 1]; Word32 lpc_wb_32_fx[LPC_SHB_ORDER_WB + 1]; Word16 lsp_wb[LPC_SHB_ORDER_WB], weights_lsp[LPC_SHB_ORDER_WB] = { 32767, 32767 }; + move16(); + move16(); Word16 *hb_new_speech, *hb_frame /*, hb_speech[ L_FRAME16k ]*/; Word16 R_h[LPC_SHB_ORDER_WB + 2], R_l[LPC_SHB_ORDER_WB + 2]; Word16 Q_R; @@ -720,6 +732,7 @@ void wb_tbe_enc_fx( Word32 L_tmp, Lmax; Word16 tmp, exp, Q_out, sc; Word16 Q_ns = -1; + move16(); Word16 pitBufAvg_fx, voicingBufAvg_fx; Word16 vf_modified_fx[NB_SUBFR16k]; @@ -730,11 +743,13 @@ void wb_tbe_enc_fx( Word16 frac, exp1; Word16 uv_flag; Word16 dummy = 0; + move16(); Word16 avg_voice_fac; TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; RF_ENC_HANDLE hRF = st_fx->hRF; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move16(); #endif /*Word16 att = 32767;*/ @@ -752,7 +767,7 @@ void wb_tbe_enc_fx( test(); test(); test(); - IF( ( NE_16( st_fx->last_extl, WB_TBE ) && NE_16( st_fx->last_extl, WB_BWE ) ) && ( EQ_16( st_fx->clas, UNVOICED_CLAS ) || ( LT_16( voicing_fx[0], 16384 ) && LT_16( voicing_fx[1], 16384 ) && LT_16( voicing_fx[2], 16384 ) ) ) && st_fx->igf == 0 ) + IF( ( NE_16( st_fx->last_extl, WB_TBE ) && NE_16( st_fx->last_extl, WB_BWE ) ) && ( st_fx->clas == UNVOICED_CLAS || ( LT_16( voicing_fx[0], 16384 ) && LT_16( voicing_fx[1], 16384 ) && LT_16( voicing_fx[2], 16384 ) ) ) && st_fx->igf == 0 ) { /* In case of unvoiced signals after switching cores, back-propagate the target signal */ Copy( hb_speech, hb_old_speech, WBTBE_LOOK_LSUFBR_5_OVER_16 ); @@ -968,6 +983,7 @@ void wb_tbe_enc_fx( } Q_bwe_exc = 31; + move16(); if ( Lmax != 0 ) { Q_bwe_exc = norm_l( Lmax ); @@ -977,7 +993,7 @@ void wb_tbe_enc_fx( find_max_mem_wb_enc( st_fx, &n_mem ); - if ( GT_16( sub( Q_bwe_exc, st_fx->prev_Q_bwe_exc ), n_mem ) ) + IF( GT_16( sub( Q_bwe_exc, st_fx->prev_Q_bwe_exc ), n_mem ) ) { Q_bwe_exc = add( st_fx->prev_Q_bwe_exc, n_mem ); } @@ -1010,6 +1026,7 @@ void wb_tbe_enc_fx( FOR( i = 0; i < L_FRAME32k; i++ ) { bwe_exc_extended_16[i + NL_BUFF_OFFSET] = round_fx( L_shl( bwe_exc_extended[i], sc ) ); + move16(); } Copy( bwe_exc_extended_16 + L_FRAME32k, hBWE_TD->old_bwe_exc_extended_fx, NL_BUFF_OFFSET ); @@ -1047,12 +1064,13 @@ void wb_tbe_enc_fx( { L_tmp = Mult_32_16( Lscale, shaped_wb_excitation[i] ); /* Q(16-exp+Q_bwe_exc_ext) */ shaped_wb_excitation[i] = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q_bwe_exc_ext */ + move16(); } Lscale = root_a_fx( Lscale, 31 - exp, &exp ); L_tmp = Mult_32_16( Lscale, shaped_wb_excitation[L_SHB_LAHEAD / 4 - 1] ); /* Q(16-exp+Q_bwe_exc_ext) */ shaped_wb_excitation[L_SHB_LAHEAD / 4 - 1] = round_fx( L_shl( L_tmp, exp ) ); /* Q_bwe_exc_ext */ - + move16(); /* Update WB excitation */ Copy( shaped_wb_excitation + L_FRAME16k / 4, hBWE_TD->state_syn_shbexc_fx, L_SHB_LAHEAD / 4 ); @@ -1198,6 +1216,7 @@ void wb_tbe_enc_fx( tmp = s_max( s_min( tmp, 32767 ), 22938 ); /* Q15 */ GainFrame = Mult_32_16( GainFrame, tmp ); /* Q18 */ + test(); IF( LT_16( lsp_spacing_fx, 328 ) && lsp_spacing_fx ) { GainFrame = Mult_32_16( GainFrame, 21299 ); /* Q18 */ @@ -1292,12 +1311,12 @@ void wb_tbe_enc_ivas_fx( Word16 lpc_wb[LPC_SHB_ORDER_WB + 1]; Word32 lpc_wb_32_fx[LPC_SHB_ORDER_WB + 1]; Word16 lsp_wb[LPC_SHB_ORDER_WB], weights_lsp[LPC_SHB_ORDER_WB] = { 32767, 32767 }; + move16(); + move16(); Word16 *hb_new_speech, *hb_frame /*, hb_speech[ L_FRAME16k ]*/; Word16 R_h[LPC_SHB_ORDER_WB + 2], R_l[LPC_SHB_ORDER_WB + 2]; Word16 Q_R; Word32 LepsP[LPC_SHB_ORDER_WB + 1]; - move16(); - move16(); Word32 prev_pow, curr_pow, Lscale; /* Word16 scale; */ @@ -1323,7 +1342,7 @@ void wb_tbe_enc_ivas_fx( TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; - move32(); + move16(); #endif move16(); @@ -1342,7 +1361,7 @@ void wb_tbe_enc_ivas_fx( test(); test(); test(); - IF( ( NE_16( st_fx->last_extl, WB_TBE ) && NE_16( st_fx->last_extl, WB_BWE ) ) && ( EQ_16( st_fx->clas, UNVOICED_CLAS ) || ( LT_16( st_fx->voicing_fx[0], 16384 ) && LT_16( st_fx->voicing_fx[1], 16384 ) && LT_16( st_fx->voicing_fx[2], 16384 ) ) ) && !st_fx->igf ) + IF( ( NE_16( st_fx->last_extl, WB_TBE ) && NE_16( st_fx->last_extl, WB_BWE ) ) && ( st_fx->clas == UNVOICED_CLAS || ( LT_16( st_fx->voicing_fx[0], 16384 ) && LT_16( st_fx->voicing_fx[1], 16384 ) && LT_16( st_fx->voicing_fx[2], 16384 ) ) ) && !st_fx->igf ) { /* In case of unvoiced signals after switching cores, back-propagate the target signal */ Copy( hb_speech, hb_old_speech, WBTBE_LOOK_LSUFBR_5_OVER_16 ); @@ -1357,8 +1376,8 @@ void wb_tbe_enc_ivas_fx( L_tmp = L_mult( hb_old_speech[i], ola_win_shb_switch_fold_fx[j] ); hb_old_speech[i] = mac_ro( L_tmp, hb_speech[k], ola_win_shb_switch_fold_fx[L_SUBFR16k - 4 - j], &Overflow ); move16(); - i = sub( i, 1 ); - k = add( k, 1 ); + i--; + k++; } } @@ -1568,7 +1587,7 @@ void wb_tbe_enc_ivas_fx( find_max_mem_wb_enc( st_fx, &n_mem ); - if ( GT_16( sub( Q_bwe_exc, st_fx->prev_Q_bwe_exc ), n_mem ) ) + IF( GT_16( sub( Q_bwe_exc, st_fx->prev_Q_bwe_exc ), n_mem ) ) { Q_bwe_exc = add( st_fx->prev_Q_bwe_exc, n_mem ); } @@ -1769,7 +1788,7 @@ void wb_tbe_enc_ivas_fx( move16(); } - hBWE_TD->prev_wb_GainShape = GainShape[sub( shr( NUM_SHB_SUBFR, 2 ), 1 )]; + hBWE_TD->prev_wb_GainShape = GainShape[( NUM_SHB_SUBFR >> 2 ) - 1]; move16(); /* Compute the power of gains away from the peak gain prior to quantization */ @@ -1980,6 +1999,8 @@ void swb_tbe_enc_fx( Word32 LepsP[LPC_SHB_ORDER + 1]; Word16 ana_align_delay[2] = { -L_SHB_LAHEAD - ( NL_BUFF_OFFSET / 2 ), -L_SHB_LAHEAD - ( NL_BUFF_OFFSET / 2 ) }; + move16(); + move16(); Word32 prev_pow_fx, curr_pow_fx, Lscale; Word32 p2m_in_fx, p2m_out_fx; @@ -2025,6 +2046,7 @@ void swb_tbe_enc_fx( Word16 n_subfr_saturation; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move16(); #endif TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; RF_ENC_HANDLE hRF = st_fx->hRF; @@ -2100,6 +2122,7 @@ void swb_tbe_enc_fx( FOR( i = 1; i <= LPC_SHB_ORDER; i++ ) { lpc_shb_fx[i] = mult_r( lpc_shb_fx[i], lpc_weights_fx[i] ); + move16(); } } @@ -2126,7 +2149,9 @@ void swb_tbe_enc_fx( /* to compensate for the 1.1* weighting done inside the function lsp_weights */ /*weights_lsp[3]*=0.909091f; weights_lsp[4]*=0.909091f; */ weights_lsp[3] = mult_r( weights_lsp[3], 29789 /*0.909091f Q15*/ ); + move16(); weights_lsp[4] = mult_r( weights_lsp[4], 29789 /*0.909091f Q15*/ ); + move16(); /* 8-bit VQ, 10 dimension */ i = closest_centroid_fx( lsf_shb_fx, weights_lsp, swb_tbe_lsfvq_cbook_8b, 256, LPC_SHB_ORDER ); @@ -2134,6 +2159,7 @@ void swb_tbe_enc_fx( set16_fx( hBWE_TD->lsf_idx, 0, NUM_Q_LSF ); hBWE_TD->lsf_idx[0] = i; + move16(); } ELSE { @@ -2196,10 +2222,12 @@ void swb_tbe_enc_fx( Copy( lsp_shb_2_fx, lsp_shb_1_fx, LPC_SHB_ORDER ); } - lsf_diff[0] = lsf_diff[sub( LPC_SHB_ORDER, 1 )] = 16384; /*Q15*/ + lsf_diff[0] = lsf_diff[LPC_SHB_ORDER - 1] = 16384; /*Q15*/ + move16(); FOR( i = 1; i < LPC_SHB_ORDER - 1; i++ ) { - lsf_diff[i] = sub( lsf_shb_fx[i], lsf_shb_fx[sub( i, 1 )] ); + lsf_diff[i] = sub( lsf_shb_fx[i], lsf_shb_fx[i - 1] ); + move16(); } a2rc_fx( hBWE_TD->cur_sub_Aq_fx + 1, refl, M ); @@ -2218,6 +2246,7 @@ void swb_tbe_enc_fx( FOR( i = 1; i < LPC_SHB_ORDER - 1; i++ ) { hBWE_TD->prev_lsf_diff_fx[i - 1] = mult( lsf_diff[i], 16384 ); /*Q15*/ + move16(); } } @@ -2239,6 +2268,7 @@ void swb_tbe_enc_fx( tmp = div_s( tmp, hBWE_TD->prev_lsf_diff_fx[i - 1] ); tmp = s_max( tmp, 16384 ); w[i] = s_min( tmp, 32767 ); + move16(); } ELSE { @@ -2246,16 +2276,20 @@ void swb_tbe_enc_fx( tmp = div_s( tmp, lsf_diff[i] ); tmp = s_max( tmp, 16384 ); w[i] = s_min( tmp, 32767 ); + move16(); } } w[0] = w[1]; - w[sub( LPC_SHB_ORDER, 1 )] = w[sub( LPC_SHB_ORDER, 2 )]; + move16(); + w[LPC_SHB_ORDER - 1] = w[LPC_SHB_ORDER - 2]; + move16(); FOR( i = 0; i < LPC_SHB_ORDER; i++ ) { tmp1 = mult( lsp_shb_1_fx[i], sub( 32767, w[i] ) ); tmp2 = mult( lsp_shb_2_fx[i], w[i] ); lsp_temp_fx[i] = add( tmp1, tmp2 ); + move16(); } } ELSE @@ -2266,6 +2300,7 @@ void swb_tbe_enc_fx( Copy( lsf_diff + 1, hBWE_TD->prev_lsf_diff_fx, LPC_SHB_ORDER - 2 ); hBWE_TD->prev_tilt_para_fx = tilt_para; + move16(); shb_ener_sf_Q31 = 0; move16(); @@ -2318,6 +2353,7 @@ void swb_tbe_enc_fx( FOR( i = 0; i < NB_SUBFR16k; i++ ) { shb_res_gshape_fx_32[i] = sum2_fx( shb_res_fx + i * 64, 64 ); + move32(); } /* o: shb_res_gshape_fx_32 in (2*Q_shb+1) */ @@ -2335,14 +2371,17 @@ void swb_tbe_enc_fx( exp = norm_l( L_tmp ); tmp = extract_h( L_shl( L_tmp, exp ) ); recip = div_s( 16384, tmp ); - Q_recip = 31 - ( exp - 14 ); /* = 31-(exp+2*Q_shb+1-14), but adjusted by (2*Q_shb+1) for use at Mult_32_16 below */ + // Q_recip = 31 - ( exp - 14 ); /* = 31-(exp+2*Q_shb+1-14), but adjusted by (2*Q_shb+1) for use at Mult_32_16 below */ + Q_recip = sub( 31 + 14, exp ); /* = 31-(exp+2*Q_shb+1-14), but adjusted by (2*Q_shb+1) for use at Mult_32_16 below */ + move16(); } FOR( i = 0; i < NB_SUBFR16k; i++ ) { L_tmp1 = Mult_32_16( shb_res_gshape_fx_32[i], recip ); /*Q = Q_recip+1-16*/ - L_tmp = root_a_fx( L_tmp1, Q_recip + 1 - 16, &exp ); - shb_res_gshape_fx[i] = round_fx( L_shl( L_tmp, exp - 1 ) ); /* Q14 */ + L_tmp = root_a_fx( L_tmp1, add( Q_recip, 1 - 16 ), &exp ); + shb_res_gshape_fx[i] = round_fx( L_shl( L_tmp, sub( exp, 1 ) ) ); /* Q14 */ + move16(); } Quant_shb_res_gshape_fx( st_fx, shb_res_gshape_fx ); @@ -2366,6 +2405,7 @@ void swb_tbe_enc_fx( if ( Lmax == 0 ) { Q_bwe_exc = 31; + move16(); } Q_bwe_exc = add( Q_bwe_exc, add( Q_new, Q_new ) ); @@ -2376,6 +2416,7 @@ void swb_tbe_enc_fx( if ( GT_16( Q_bwe_exc, tmp2 ) ) { Q_bwe_exc = tmp2; + move16(); } /* rescale the memories if Q_bwe_exc is different from previous frame */ @@ -2392,6 +2433,7 @@ void swb_tbe_enc_fx( FOR( cnt = 0; cnt < L_FRAME32k; cnt++ ) { bwe_exc_extended_16[cnt + NL_BUFF_OFFSET] = round_fx_sat( L_shl_sat( bwe_exc_extended[cnt], sc ) ); + move16(); } Copy( bwe_exc_extended_16 + L_FRAME32k, hBWE_TD->old_bwe_exc_extended_fx, NL_BUFF_OFFSET ); @@ -2423,9 +2465,11 @@ void swb_tbe_enc_fx( &( hBWE_TD->fb_tbe_demph_fx ), &Q_bwe_exc, &Q_bwe_exc_fb, Q_shb, n_mem2, st_fx->prev_Q_bwe_syn, st_fx->total_brate, 0 ); *Q_white_exc = Q_bwe_exc_fb; + move16(); IF( EQ_16( st_fx->extl, FB_TBE ) ) { hBWE_TD->prev_Q_bwe_exc_fb = Q_bwe_exc_fb; + move16(); } ELSE { @@ -2452,6 +2496,7 @@ void swb_tbe_enc_fx( FOR( i = 0; i < LPC_SHB_ORDER; i++ ) { hBWE_TD->mem_stp_swb_fx[i] = shl( hBWE_TD->mem_stp_swb_fx[i], sub( Q_bwe_exc, st_fx->prev_Q_bwe_syn ) ); + move16(); } FOR( i = 0; i < L_FRAME16k; i += L_SUBFR16k ) @@ -2488,11 +2533,13 @@ void swb_tbe_enc_fx( { L_tmp = Mult_32_16( Lscale, shaped_shb_excitation_fx[i] ); /* Q(16-exp+Q_bwe_exc) */ shaped_shb_excitation_fx[i] = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q_bwe_exc */ + move16(); } IF( exp < 0 ) { Lscale = L_shl( Lscale, exp ); exp = 0; + move16(); } FOR( ; i < L_SHB_LAHEAD + 10; i++ ) { @@ -2502,6 +2549,7 @@ void swb_tbe_enc_fx( Lscale = L_add( Mult_32_16( Lscale, tmp ), L_tmp1 ); L_tmp = Mult_32_16( Lscale, shaped_shb_excitation_fx[i] ); /* Q_bwe_exc + (31-exp) - 15 */ shaped_shb_excitation_fx[i] = round_fx_o( L_shl_o( L_tmp, exp, &Overflow ), &Overflow ); /* Q_bwe_exc */ + move16(); } /* Update SHB excitation */ @@ -2522,6 +2570,7 @@ void swb_tbe_enc_fx( /* 0.35f +/- delta variation; delta = 0.1*(GS-0.35)*/ /* GainShape[i] = 0.315f + 0.1f * GainShape[i]; */ GainShape_fx[i] = mac_r( 676457349l /*0.315 Q31*/, 3277 /*0.1 Q15*/, GainShape_fx[i] ); + move16(); } } @@ -2610,10 +2659,12 @@ void swb_tbe_enc_fx( { temp_swb_fac = hBWE_TD->prev_swb_GainShape_fx; + move16(); FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ ) { /*GainShape_fx[i] = (1 - feedback) * GainShape[i] + feedback * temp_swb_fac; */ GainShape_fx[i] = round_fx( L_mac( L_mult( sub( 32767, feedback ), GainShape_fx[i] ), feedback, temp_swb_fac ) ); + move16(); temp_swb_fac = GainShape_fx[i]; move16(); } @@ -2653,6 +2704,7 @@ void swb_tbe_enc_fx( GainFrame_fx = L_add( L_shr( hBWE_TD->prev_gainFr_SHB_fx, 1 ), L_shr( GainFrame_fx, 1 ) ); /* Q18 */ } + test(); test(); IF( EQ_16( frGainAttenuate, 1 ) && LE_16( MA_lsp_shb_spacing, 79 /*0.0024f Q15*/ ) ) { @@ -2663,7 +2715,7 @@ void swb_tbe_enc_fx( frac = L_Extract_lc( L_tmp, &exp ); GainFrame_fx = Pow2( 30, frac ); exp = sub( exp, 30 ); - GainFrame_fx = L_shl( GainFrame_fx, exp + 18 ); /* Q18 */ + GainFrame_fx = L_shl( GainFrame_fx, add( exp, 18 ) ); /* Q18 */ } ELSE IF( EQ_16( hBWE_TD->prev_frGainAtten, 1 ) && GT_32( Mult_32_16( GainFrame_fx, 10923 ), hBWE_TD->prev_gainFr_SHB_fx ) ) { @@ -2703,9 +2755,11 @@ void swb_tbe_enc_fx( /* voicingBufAvg = (sum_f(voice_factors, 4)=sum2 > 0.6f) ? 0.333f : 0.1667f; */ tmp2 = 5462 /*0.1667f Q15*/; + move16(); if ( GT_16( sum2, 4915 /*0.6f Q13*/ ) ) { tmp2 = 10912 /*0.333f Q15*/; /* Q15 */ + move16(); } voicingBufAvg_fx = shl( mult( tmp2, sum1 ), 2 ); /* Q15 */ @@ -2749,16 +2803,19 @@ void swb_tbe_enc_fx( if ( GainFrame_fx == 0 ) { tmp = 31; + move16(); } L_tmp = L_shl( GainFrame_fx, tmp ); /* 18 + tmp */ tmp1 = 0; + move16(); FOR( i = 0; i < L_FRAME16k; i++ ) { L_tmp1 = Mult_32_16( L_tmp, GainShape_fx[NUM_SHB_SUBFR * i / L_FRAME16k] ); /* Q : 18 + tmp +15 -15*/ /*White_exc16k_fx[i] = round_fx( L_shl(Mult_32_16( L_tmp1, White_exc16k_fx[i]),(23 - tmp -*Q_white_exc)) );*/ /*18 + tmp +*Q_white_exc -15 + 23 - tmp -*Q_white_exc -16 = 10*/ White_exc16k_fx[i] = round_fx( Mult_32_16( L_tmp1, White_exc16k_fx[i] ) ); /* 18 + tmp +*Q_white_exc -15 -16 */ + move16(); /*Lmax = L_max(Lmax,White_exc16k_fx[i]);*/ tmp1 = s_max( tmp1, abs_s( White_exc16k_fx[i] ) ); /*White_exc16k_fx[i] =32767;*/ @@ -2769,6 +2826,7 @@ void swb_tbe_enc_fx( if ( tmp1 == 0 ) { tmp = 15; + move16(); } FOR( i = 0; i < L_FRAME16k; i++ ) @@ -2907,7 +2965,7 @@ void swb_tbe_enc_ivas_fx( Word16 n_subfr_saturation; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; - move32(); + move16(); #endif Env_error_fx = 0; @@ -2932,6 +2990,7 @@ void swb_tbe_enc_ivas_fx( exp1 = 0; /* to avoid compilation warnings */ move16(); + test(); IF( st_fx->element_mode >= IVAS_CPE_DFT && hStereoICBWE != NULL ) { nlExc16k_fx = hStereoICBWE->nlExc16k_fx; @@ -3227,7 +3286,7 @@ void swb_tbe_enc_ivas_fx( } w_fx[0] = w_fx[1]; move16(); - w_fx[sub( LPC_SHB_ORDER, 1 )] = w_fx[sub( LPC_SHB_ORDER, 2 )]; + w_fx[LPC_SHB_ORDER - 1] = w_fx[LPC_SHB_ORDER - 2]; move16(); FOR( i = 0; i < LPC_SHB_ORDER; i++ ) @@ -3319,7 +3378,8 @@ void swb_tbe_enc_ivas_fx( exp = norm_l( L_tmp ); tmp = extract_h( L_shl( L_tmp, exp ) ); recip = div_s( 16384, tmp ); - Q_recip = sub( 31, sub( exp, 14 ) ); /* = 31-(exp+2*Q_shb+1-14), but adjusted by (2*Q_shb+1) for use at Mult_32_16 below */ + // Q_recip = sub( 31, sub( exp, 14 ) ); /* = 31-(exp+2*Q_shb+1-14), but adjusted by (2*Q_shb+1) for use at Mult_32_16 below */ + Q_recip = sub( 31 + 14, exp ); /* = 31-(exp+2*Q_shb+1-14), but adjusted by (2*Q_shb+1) for use at Mult_32_16 below */ } FOR( i = 0; i < NB_SUBFR16k; i++ ) @@ -3378,6 +3438,7 @@ void swb_tbe_enc_ivas_fx( FOR( k = 0; k < L_FRAME4k; k++ ) { EnvSHBres_4k_fx[k] = EnvSHBres_fx[4 * k]; /* Q_shb */ + move16(); } /* calculate long-term mean envelope over four consecutive segments using linear interpolation */ @@ -3424,7 +3485,7 @@ void swb_tbe_enc_ivas_fx( FOR( k = 1; k < 4; k++ ) { // step = ( den_seg_mean[k] - den_seg_mean[k - 1] ) * den_seg_len; - step = mult( den_seg_mean[k] - den_seg_mean[k - 1], den_seg_len ); + step = mult( sub( den_seg_mean[k], den_seg_mean[k - 1] ), den_seg_len ); FOR( i = 0; i < seg_len; i++ ) { *p_env = add_sat( *( p_env - 1 ), step ); @@ -3631,7 +3692,6 @@ void swb_tbe_enc_ivas_fx( Q_bwe_exc_fb = hBWE_TD->prev_Q_bwe_exc_fb; move16(); - // Replace with IVAS equivalent GenShapedSHBExcitation_ivas_enc_fx( shaped_shb_excitation_fx + L_SHB_LAHEAD, lpc_shb_fx, White_exc16k_fx, hBWE_TD->mem_csfilt_fx, hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->state_lpc_syn_fx, st_fx->coder_type, bwe_exc_extended_16, hBWE_TD->bwe_seed, vf_modified_fx, st_fx->extl, @@ -3668,6 +3728,7 @@ void swb_tbe_enc_ivas_fx( { Copy( shaped_shb_excitation_fx + L_SHB_LAHEAD, hStereoICBWE->shbSynthRef_fx, L_FRAME16k ); hStereoICBWE->shbSynthRef_e = sub( 15, Q_bwe_exc ); + move16(); } test(); @@ -3731,7 +3792,7 @@ void swb_tbe_enc_ivas_fx( curr_pow_64fx = W_mac0_16_16( curr_pow_64fx, shaped_shb_excitation_fx[i + L_SHB_LAHEAD + 10], shaped_shb_excitation_fx[i + L_SHB_LAHEAD + 10] ); /* 2*Q_bwe_exc */ } - if ( GT_16( voice_factors_fx[0], 24576 /*0.75f Q15*/ ) ) + IF( GT_16( voice_factors_fx[0], 24576 /*0.75f Q15*/ ) ) { /*curr_pow_fx = Mult_32_16( curr_pow_fx, 8192);*/ /* Q(2*Q_bwe_exc) */ curr_pow_64fx = W_shr( curr_pow_64fx, 2 ); /* scale by 0.25 */ @@ -3909,6 +3970,7 @@ void swb_tbe_enc_ivas_fx( Copy( GainShape_fx, GainShape_Interp_fx, NUM_SHB_SUBGAINS ); lls_interp_n_fx( GainShape_Interp_fx, NUM_SHB_SUBGAINS, &GainShape_tilt_fx, &temp, 1 ); + test(); IF( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) { // if (acorr_v2a < 0.4f && vf_ind >= 5 && fabs(GainShape_tilt) < 0.2f && shb_env_tilt < 500.0f && hBWE_TD->prev_shb_env_tilt < 500.0f) @@ -3960,6 +4022,7 @@ void swb_tbe_enc_ivas_fx( { /*GainShape_fx[i] = (1 - feedback) * GainShape[i] + feedback * temp_swb_fac; */ GainShape_fx[i] = round_fx( L_mac( L_mult( sub( 32767, feedback ), GainShape_fx[i] ), feedback, temp_swb_fac ) ); + move16(); temp_swb_fac = GainShape_fx[i]; move16(); } @@ -4148,7 +4211,7 @@ void swb_tbe_enc_ivas_fx( frac = L_Extract_lc( L_tmp, &exp ); GainFrame_fx = Pow2( 30, frac ); exp = sub( exp, 30 ); - GainFrame_fx = L_shl( GainFrame_fx, exp + 18 ); /* Q18 */ + GainFrame_fx = L_shl( GainFrame_fx, add( exp, 18 ) ); /* Q18 */ } ELSE IF( EQ_16( hBWE_TD->prev_frGainAtten, 1 ) && GT_32( Mult_32_16( GainFrame_fx, 10923 ), hBWE_TD->prev_gainFr_SHB_fx ) ) { @@ -4430,7 +4493,7 @@ static void EstimateSHBFrameGain_fx( Word16 scaling = 0; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; - move32(); + move16(); #endif move16(); @@ -4501,7 +4564,7 @@ static void EstimateSHBFrameGain_fx( sum_gain = mult_r( subwin_shb_local[k + 1], subgain[0] ); /* Q15 */ mod_syn[j] = L_mult( synSHB[j], sum_gain ); move32(); /* Q(16+Q_synSHB) */ - j = add( j, 1 ); + j++; } FOR( i = 0; i < NUM_SHB_SUBGAINS - 1; i++ ) { @@ -4509,7 +4572,7 @@ static void EstimateSHBFrameGain_fx( { mod_syn[j] = L_mult( synSHB[j], subgain[i * num_join] ); move32(); /* Q(16+Q_synSHB) */ - j = add( j, 1 ); + j++; } FOR( k = 0; k < length; k++ ) @@ -4518,21 +4581,21 @@ static void EstimateSHBFrameGain_fx( tmp = round_fx( L_mac0( L_tmp, subwin_shb_local[k + 1], subgain[( i + 1 ) * num_join] ) ); /* Q14 */ mod_syn[j] = L_shl( L_mult( tmp, synSHB[j] ), 1 ); move32(); /* Q(16+Q_synSHB) */ - j = add( j, 1 ); + j++; } } FOR( k = 0; k < join_length - length; k++ ) { mod_syn[j] = L_mult( synSHB[j], subgain[( NUM_SHB_SUBGAINS - 1 ) * num_join] ); move32(); /* Q(16+Q_synSHB)*/ - j = add( j, 1 ); + j++; } FOR( k = 0; k < length; k++ ) { tmp = mult_r( subwin_shb_local[length - k - 1], subgain[( NUM_SHB_SUBGAINS - 1 ) * num_join] ); /* Q15 */ mod_syn[j] = L_mult( tmp, synSHB[j] ); move32(); /* Q(16+Q_synSHB ) */ - j = add( j, 1 ); + j++; } } /* adjust frame energy */ @@ -4690,7 +4753,7 @@ static void EstimateSHBFrameGain_ivas_fx( sum_gain = mult_r( subwin_shb_local[k + 1], subgain[0] ); /* Q15 */ mod_syn[j] = L_mult0( synSHB[j], sum_gain ); move32(); /* Q(16+Q_synSHB) */ - j = add( j, 1 ); + j++; } FOR( i = 0; i < NUM_SHB_SUBGAINS - 1; i++ ) { @@ -4698,7 +4761,7 @@ static void EstimateSHBFrameGain_ivas_fx( { mod_syn[j] = L_mult0( synSHB[j], subgain[i * num_join] ); move32(); /* Q(16+Q_synSHB) */ - j = add( j, 1 ); + j++; } FOR( k = 0; k < length; k++ ) @@ -4707,21 +4770,21 @@ static void EstimateSHBFrameGain_ivas_fx( tmp = round_fx( L_mac0( L_tmp, subwin_shb_local[k + 1], subgain[( i + 1 ) * num_join] ) ); /* Q14 */ mod_syn[j] = L_mult( tmp, synSHB[j] ); move32(); /* Q(16+Q_synSHB) */ - j = add( j, 1 ); + j++; } } FOR( k = 0; k < join_length - length; k++ ) { mod_syn[j] = L_mult0( synSHB[j], subgain[( NUM_SHB_SUBGAINS - 1 ) * num_join] ); move32(); /* Q(16+Q_synSHB)*/ - j = add( j, 1 ); + j++; } FOR( k = 0; k < length; k++ ) { tmp = mult_r( subwin_shb_local[length - k - 1], subgain[( NUM_SHB_SUBGAINS - 1 ) * num_join] ); /* Q15 */ mod_syn[j] = L_mult0( tmp, synSHB[j] ); move32(); /* Q(16+Q_synSHB ) */ - j = add( j, 1 ); + j++; } } /* adjust frame energy */ @@ -4914,7 +4977,7 @@ static void EstimateSHBGainShape_fx( FOR( i = 0; i < NUM_SHB_SUBFR / 2; i++ ) { logic16(); - IF( ( i & 0x1 ) == 0 ) + IF( s_and( i, 0x1 ) == 0 ) { oriNrg = 0; move32(); @@ -4976,13 +5039,13 @@ static void EstimateSHBGainShape_fx( } logic16(); - IF( EQ_16( ( i & 0x1 ), 1 ) ) + IF( EQ_16( s_and( i, 0x1 ), 1 ) ) { L_subgain[i / 2] = root_a_over_b_fx( oriNrg, shl( Q_oriSHB, 1 ), synNrg, shl( Q_synSHB, 1 ), &n ); move16(); /* Q(31-n) */ norm[i / 2] = n; move16(); - IF( GT_16( norm[i / 2], n_max ) ) + if ( GT_16( norm[i / 2], n_max ) ) { n_max = norm[i / 2]; move16(); @@ -5059,7 +5122,7 @@ static void EstimateSHBGainShape_fx( n = sub( n, scaling ); norm[i] = n; move16(); - IF( GT_16( norm[i], n_max ) ) + if ( GT_16( norm[i], n_max ) ) { n_max = norm[i]; move16(); @@ -5252,6 +5315,7 @@ static void QuantizeSHBsubgains_fx( exp = sub( -1, exp ); L_tmp = Mpy_32_16( exp, frac, 24660 ); /* Q13 ; 20.0 * log10(2) in Q12*/ subgains[i + NUM_SHB_SUBFR / 4] = round_fx( L_shl( L_tmp, 11 ) ); /* Q8 */ + move16(); } } idxSubGain = closest_centroid_lc_fx( subgains + NUM_SHB_SUBFR / 4, HBCB_SubGain5bit_fx, 1 << NUM_BITS_SHB_SUBGAINS ); @@ -5265,10 +5329,11 @@ static void QuantizeSHBsubgains_fx( L_tmp = L_shr( L_tmp, 10 ); /* From Q26 to Q16 */ frac = L_Extract_lc( L_tmp, &exp ); subgains[i] = extract_l( Pow2( 14, frac ) ); + move16(); /* Put 14 as exponent so that */ /* output of Pow2() will be: */ /* 16384 < Pow2() <= 32767 */ - subgains[i] = shl( subgains[i], exp + 1 ); + subgains[i] = shl( subgains[i], add( exp, 1 ) ); move16(); /*Q15 */ } @@ -5297,6 +5362,7 @@ static void QuantizeSHBsubgains_fx( L_tmp = Mpy_32_16( exp, frac, 9864 ); /*move32(); // Q16 ; log10(2) in Q15 */ subgains[i] = round_fx( L_shl( L_tmp, 12 ) ); /*Q12 */ + move16(); } } @@ -5308,10 +5374,11 @@ static void QuantizeSHBsubgains_fx( L_tmp = L_shr( L_tmp, 10 ); /* From Q26 to Q16 */ frac = L_Extract_lc( L_tmp, &exp ); subgains[i] = extract_l( Pow2( 14, frac ) ); + move16(); /* Put 14 as exponent so that */ /* output of Pow2() will be: */ /* 16384 < Pow2() <= 32767 */ - subgains[i] = shl( subgains[i], exp + 1 ); + subgains[i] = shl( subgains[i], add( exp, 1 ) ); move16(); /*Q15 */ } @@ -5401,7 +5468,7 @@ static void QuantizeSHBsubgains_ivas_fx( /* Put 14 as exponent so that */ /* output of Pow2() will be: */ /* 16384 < Pow2() <= 32767 */ - subgains[i] = shl( subgains[i], exp + 1 ); + subgains[i] = shl( subgains[i], add( exp, 1 ) ); move16(); /*Q15 */ } @@ -5446,7 +5513,7 @@ static void QuantizeSHBsubgains_ivas_fx( /* Put 14 as exponent so that */ /* output of Pow2() will be: */ /* 16384 < Pow2() <= 32767 */ - subgains[i] = shl( subgains[i], exp + 1 ); + subgains[i] = shl( subgains[i], add( exp, 1 ) ); move16(); /*Q15 */ } @@ -5492,6 +5559,7 @@ static void Quant_shb_ener_sf_fx( /* shb_ener_sf_fx[0] = log10(0.003125*shb_ener_sf[0:319]); */ sum = *shb_ener_sf_Q31; /* L_tmp in Q_ener = (2*Q_shb+1) */ + move32(); exp = norm_l( sum ); frac = Log2_norm_lc( L_shl( sum, exp ) ); @@ -5511,7 +5579,9 @@ static void Quant_shb_ener_sf_fx( L_tmp = L_shl( L_tmp, -10 ); /* bring L_tmp from Q26 to Q16 */ frac = L_Extract_lc( L_tmp, &exp ); /* Extract exponent */ L_tmp = Pow2( 14, frac ); - *shb_ener_sf_Q31 = L_shl( L_tmp, exp - 14 + Q_ener ); /* In Q_ener */ + // *shb_ener_sf_Q31 = L_shl( L_tmp, exp - 14 + Q_ener ); /* In Q_ener */ + *shb_ener_sf_Q31 = L_shl( L_tmp, add( sub( exp, 14 ), Q_ener ) ); /* In Q_ener */ + move32(); hBWE_TD->idx_shb_fr_gain = idxSubEner_fx; move16(); @@ -5555,7 +5625,7 @@ static void Quant_shb_ener_sf_ivas_fx( temp_shb_ener_sf_fx = 0; move16(); - idxSubEner_fx = usquant_fx( tmp, &temp_shb_ener_sf_fx, 0, 43, shl( 1, NUM_BITS_SHB_ENER_SF ) ); /* 43 = 0.042f in Q10 = Qin-1 */ + idxSubEner_fx = usquant_fx( tmp, &temp_shb_ener_sf_fx, 0, 43, 1 << NUM_BITS_SHB_ENER_SF ); /* 43 = 0.042f in Q10 = Qin-1 */ /* o: temp_shb_ener_sf_fx in Q11 */ /* shb_ener_sf_fx[0] = pow(10.0, temp_shb_ener_sf_fx ); */ @@ -5598,8 +5668,10 @@ static void Quant_shb_res_gshape_fx( 2048 /*0.125f Q14*/, /*2048 = 0.125 in Q14 */ 1024 /*0.125f Q13*/, /*1024 = 0.125 in Q13 */ shl( 1, NUM_BITS_SHB_RES_GS ) ); + move16(); hBWE_TD->idx_res_gs[i] = idxSubGain_fx[i]; + move16(); IF( NE_16( st_fx->codec_mode, MODE2 ) ) { push_indice_fx( st_fx->hBstr, IND_SHB_RES_GS1 + i, idxSubGain_fx[i], NUM_BITS_SHB_RES_GS ); @@ -5631,7 +5703,7 @@ static void Quant_shb_res_gshape_ivas_fx( shl( 1, NUM_BITS_SHB_RES_GS ) ); move16(); - IF( st->codec_mode == MODE2 ) + IF( EQ_16( st->codec_mode, MODE2 ) ) { hBWE_TD->idx_res_gs[i] = idxSubGain_fx[i]; move16(); @@ -5675,6 +5747,7 @@ static void QuantizeSHBframegain_fx( Word16 idxFrameGain; Word32 Q_GainFrame; Word16 Unit_weights1 = 1; + move16(); Word16 exp, frac, tmp; Word32 L_tmp; Word32 GainFrameLog; @@ -5721,7 +5794,8 @@ static void QuantizeSHBframegain_fx( { exp = norm_l( *GainFrame ); frac = Log2_norm_lc( L_shl( *GainFrame, exp ) ); - exp = ( 30 - exp - 18 ); + // exp = ( 30 - exp - 18 ); + exp = sub( 30 - 18, exp ); GainFrameLog = Mpy_32_16( exp, frac, 9864 ); /*GainFrameLog= round_fx(L_shl(L_tmp,12)); //Q12 */ } @@ -5732,7 +5806,8 @@ static void QuantizeSHBframegain_fx( idxFrameGain = extract_l( L_shr( L_add( L_tmp, shl( 1, sub( 14, exp ) ) ), sub( 15, exp ) ) ); /*Q0*/ IF( GT_16( idxFrameGain, ( 1 << NUM_BITS_SHB_FRAMEGAIN ) - 1 ) ) { - idxFrameGain = sub( ( 1 << NUM_BITS_SHB_FRAMEGAIN ), 1 ); + idxFrameGain = ( 1 << NUM_BITS_SHB_FRAMEGAIN ) - 1; + move16(); } ELSE { @@ -5746,9 +5821,11 @@ static void QuantizeSHBframegain_fx( L_tmp = SHB_GAIN_QLOW_FX_16; Q_GainFrame = L_mac( L_tmp, idxFrameGain, SHB_GAIN_QDELTA_FX_15 ); + test(); WHILE( GT_32( Q_GainFrame, L_add( GainFrameLog, 4866 ) ) && idxFrameGain != 0 ) { + test(); idxFrameGain = sub( idxFrameGain, 1 ); Q_GainFrame = L_mac0( SHB_GAIN_QLOW_FX_16, idxFrameGain, SHB_GAIN_QDELTA_FX_16 ); } @@ -5760,7 +5837,7 @@ static void QuantizeSHBframegain_fx( frac = L_Extract_lc( L_tmp, &exp ); Q_GainFrame = Pow2( 30, frac ); exp = sub( exp, 30 ); - Q_GainFrame = L_shl( Q_GainFrame, exp + 18 ); /* Q18 */ + Q_GainFrame = L_shl( Q_GainFrame, add( exp, 18 ) ); /* Q18 */ hBWE_TD->idxFrameGain = idxFrameGain; move16(); @@ -5769,12 +5846,14 @@ static void QuantizeSHBframegain_fx( push_indice_fx( st_fx->hBstr, IND_SHB_FRAMEGAIN, idxFrameGain, NUM_BITS_SHB_FRAMEGAIN ); } *rf_gainFrame_ind = idxFrameGain; + move16(); } IF( EQ_16( st_fx->rf_mode, 1 ) ){ /*Currently intended for SWB only. Modify for WB is needed later!*/ IF( EQ_16( hRF->rf_frame_type, RF_NELP ) ){ *rf_gainFrame_ind = idxFrameGain; /* NELP Frame uses full 5 bits */ + move16(); } ELSE /*RF_ALLPRED, RF_GENPRED, RF_NOPRED modes*/ { @@ -5794,6 +5873,7 @@ ELSE /*RF_ALLPRED, RF_GENPRED, RF_NOPRED modes*/ { *rf_gainFrame_ind = 3; } + move16(); } } @@ -5902,7 +5982,7 @@ static void QuantizeSHBframegain_ivas_fx( { exp = norm_l( *GainFrame ); frac = Log2_norm_lc( L_shl( *GainFrame, exp ) ); - exp = ( 30 - exp - 18 ); + exp = sub( 30 - 18, exp ); GainFrameLog = Mpy_32_16( exp, frac, 9864 ); /*GainFrameLog= round_fx(L_shl(L_tmp,12)); //Q12 */ } @@ -5956,10 +6036,11 @@ static void QuantizeSHBframegain_ivas_fx( Q_GainFrame = L_mac( L_tmp, idxFrameGain, SHB_GAIN_QDELTA_FX_15 ); } - + test(); WHILE( GT_32( Q_GainFrame, L_add( GainFrameLog, 4866 ) ) && idxFrameGain != 0 ) { + test(); idxFrameGain = sub( idxFrameGain, 1 ); Q_GainFrame = L_mac0( SHB_GAIN_QLOW_FX_16, idxFrameGain, SHB_GAIN_QDELTA_FX_16 ); } @@ -5980,7 +6061,7 @@ static void QuantizeSHBframegain_ivas_fx( frac = L_Extract_lc( L_tmp, &exp ); Q_GainFrame = Pow2( 30, frac ); exp = sub( exp, 30 ); - Q_GainFrame = L_shl( Q_GainFrame, exp + 18 ); /* Q18 */ + Q_GainFrame = L_shl( Q_GainFrame, add( exp, 18 ) ); /* Q18 */ IF( EQ_16( st_fx->codec_mode, MODE2 ) ) { @@ -6072,6 +6153,7 @@ static void determine_gain_weights_fx( Word32 L_tmp; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move16(); #endif FOR( j = 0; j < dims; j++ ) @@ -6082,14 +6164,14 @@ static void determine_gain_weights_fx( exp1 = norm_l( gain[j] ); frac = Log2_norm_lc( L_shl( gain[j], exp1 ) ); move16(); - exp = 30 - exp1 - 18; + exp = sub( 30 - 18, exp1 ); move16(); L_tmp = Mpy_32_16( exp, frac, -29491 ); /* Q16 */ frac = L_Extract_lc( L_tmp, &exp ); tmp = extract_l( Pow2( 14, frac ) ); /* Q14 */ exp2 = sub( exp, 8 ); - if ( LE_16( exp1, 21 ) ) + IF( LE_16( exp1, 21 ) ) { exp2 = sub( exp, 2 ); } @@ -6369,7 +6451,7 @@ static Word16 Find_LSF_grid_fx( exp = norm_s( m ); tmp = div_s( shl( 1, sub( 14, exp ) ), m ); L_tmp = L_mult( sub( MAX_LSF_FX, m ), tmp ); - scale = round_fx( L_shl( L_tmp, exp + 1 ) ); + scale = round_fx( L_shl( L_tmp, add( exp, 1 ) ) ); FOR( i = 0; i < NUM_MAP_LSF; i++ ) { @@ -6514,6 +6596,7 @@ static void gainFrSmooth_En_fx( Encoder_State *st_fx, tempQ31 = L_mac( tempQ31, hBWE_TD->lsp_shb_spacing_fx[1], 6553 ); /* 0.2f */ tempQ31 = L_mac( tempQ31, hBWE_TD->lsp_shb_spacing_fx[2], 9830 ); /* 0.3f */ *MA_lsp_shb_spacing = mac_r( tempQ31, lsp_spacing, 13107 ); /* 0.4f */ + move16(); hBWE_TD->lsp_shb_spacing_fx[0] = hBWE_TD->lsp_shb_spacing_fx[1]; move16(); @@ -6541,7 +6624,7 @@ static void gainFrSmooth_En_fx( Encoder_State *st_fx, } test(); - IF( LT_32( lsp_slow_evol_rate, 2147484l /*0.001f Q31*/ ) && LT_32( lsp_fast_evol_rate, 2147484l /*0.001f Q31*/ ) ) + if ( LT_32( lsp_slow_evol_rate, 2147484l /*0.001f Q31*/ ) && LT_32( lsp_fast_evol_rate, 2147484l /*0.001f Q31*/ ) ) { *frGainSmoothEn = 1; move16(); @@ -6640,6 +6723,7 @@ static void gainFrSmooth_En_ivas_fx( Encoder_State *st_fx, tempQ31 = L_mac( tempQ31, hBWE_TD->lsp_shb_spacing_fx[1], 6553 ); /* 0.2f in Q15 */ tempQ31 = L_mac( tempQ31, hBWE_TD->lsp_shb_spacing_fx[2], 9830 ); /* 0.3f in Q15 */ *MA_lsp_shb_spacing = mac_r( tempQ31, lsp_spacing, 13107 ); /* 0.4f in Q15 */ + move16(); hBWE_TD->lsp_shb_spacing_fx[0] = hBWE_TD->lsp_shb_spacing_fx[1]; move16(); @@ -6667,7 +6751,7 @@ static void gainFrSmooth_En_ivas_fx( Encoder_State *st_fx, } test(); - IF( ( BASOP_Util_Cmp_Mant32Exp( lsp_slow_evol_rate, lsp_slow_evol_rate_e, 2147484l /*0.001f in Q31*/, 0 ) < 0 ) && ( BASOP_Util_Cmp_Mant32Exp( lsp_fast_evol_rate, lsp_fast_evol_rate_e, 2147484l /*0.001f in Q31*/, 0 ) < 0 ) ) + if ( ( BASOP_Util_Cmp_Mant32Exp( lsp_slow_evol_rate, lsp_slow_evol_rate_e, 2147484l /*0.001f in Q31*/, 0 ) < 0 ) && ( BASOP_Util_Cmp_Mant32Exp( lsp_fast_evol_rate, lsp_fast_evol_rate_e, 2147484l /*0.001f in Q31*/, 0 ) < 0 ) ) { *frGainSmoothEn = 1; move16(); @@ -6732,7 +6816,6 @@ static void first_VQstages_fx( /* Set up initial error (residual) vectors */ pTmp = resid[1]; - move16(); FOR( c = 0; c < maxC; c++ ) { Copy( u, pTmp, N ); @@ -6757,21 +6840,15 @@ static void first_VQstages_fx( /* swap pointers to parent and current nodes */ pTmp_short = indices[0]; indices[0] = indices[1]; - move16(); indices[1] = pTmp_short; - move16(); pTmp = resid[0]; resid[0] = resid[1]; - move16(); resid[1] = pTmp; - move16(); pTmp32 = dist[0]; dist[0] = dist[1]; - move32(); dist[1] = pTmp32; - move32(); /* p_max points to maximum distortion node (worst of best) */ p_max = 0; @@ -6802,7 +6879,6 @@ static void first_VQstages_fx( FOR( c = 0; c < m; c++ ) { pTmp = &resid[0][c * N]; - move16(); L_tmp = L_mult( pTmp[0], Tmp[0] ); FOR( c2 = 1; c2 < N; c2++ ) { @@ -6849,7 +6925,7 @@ static void first_VQstages_fx( { /* subtract codebook entry from the residual vector of the parent node */ pTmp = resid[1] + c * N; - move16(); + Copy( resid[0] + parents[c] * N, pTmp, N ); Vr_subt( pTmp, cb_stage + ( indices[1][cs + s] ) * N, pTmp, N ); @@ -6922,15 +6998,11 @@ static void LVQQuant_BWE_LSF_fx( empty_bits = 0; /* This is the difference to 21 bits, if we want lower number of bits */ move16(); nbits = sub( nbits, empty_bits ); /* THIS IS TO SIMULATE DIFFERENT NUMBER OF input BITS - should be removed */ - move16(); c2 = sub( NUM_BITS_SHB_MSLVQ, nbits ); - move16(); numbits_VQ = config_LSF_BWE[c2 * 3]; - move16(); levels[0] = config_LSF_BWE[c2 * 3 + 1]; move16(); predictor_bits = config_LSF_BWE[c2 * 3 + 2]; - move16(); IF( LT_16( nbits, 19 ) ) { cb_stage_fx = cb_LSF_BWE_fx[1]; @@ -7227,6 +7299,7 @@ void fb_tbe_enc_fx( TD_BWE_ENC_HANDLE hBWE_TD = st->hBWE_TD; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move16(); #endif s_max_value = 0; FOR( i = 0; i < L_FRAME48k; i++ ) @@ -7237,13 +7310,14 @@ void fb_tbe_enc_fx( if ( s_max_value == 0 ) { exp_temp = 15; + move16(); } exp_temp = sub( exp_temp, 1 ); Copy_Scale_sig( new_input, input_fhb, L_FRAME48k, exp_temp ); elliptic_bpf_48k_generic_fx( input_fhb, &exp_temp, tmp_vec, hBWE_TD->elliptic_bpf_2_48k_mem_fx, hBWE_TD->elliptic_bpf_2_48k_mem_fx_Q, full_band_bpf_2_fx ); - Sample_Delay_HP = NS2SA( 48000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ) - L_FRAME48k / 2; + Sample_Delay_HP = NS2SA_FX2( 48000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ) - L_FRAME48k / 2; IF( NE_16( st->last_extl, FB_TBE ) ) { @@ -7295,9 +7369,11 @@ void fb_tbe_enc_fx( /* idxGain = (short)( log2_f ((float)ratio) + 0.5f ); idxGain = max( 0, min(15,idxGain) ); */ ratio = 0; + move16(); IF( GE_32( L_tmp, 32768 ) ) { idxGain = 15; + move16(); } ELSE { @@ -7306,6 +7382,9 @@ void fb_tbe_enc_fx( idxGain = sub( 14, exp_norm ); idxGain = s_max( 0, idxGain ); } + + test(); + test(); IF( GT_16( idxGain, 2 ) && LT_16( idxGain, 15 ) && GT_16( ratio, add( shl( 2, sub( idxGain, 1 ) ), shl( 2, sub( idxGain, 2 ) ) ) ) ) { idxGain = add( idxGain, 1 ); @@ -7315,6 +7394,7 @@ void fb_tbe_enc_fx( IF( st->codec_mode == MODE2 ) { hBWE_TD->idxGain = idxGain; + move16(); } ELSE { @@ -7343,7 +7423,7 @@ void fb_tbe_enc_ivas_fx( TD_BWE_ENC_HANDLE hBWE_TD = st->hBWE_TD; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; - move32(); + move16(); #endif s_max_value = 0; move16(); @@ -7375,19 +7455,16 @@ void fb_tbe_enc_ivas_fx( IF( EQ_16( st->L_frame, L_FRAME ) ) { - Sample_Delay_HP = NS2SA( 48000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS ) - L_FRAME48k / 2; - move16(); + Sample_Delay_HP = NS2SA_FX2( 48000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS ) - L_FRAME48k / 2; } ELSE { - Sample_Delay_HP = NS2SA( 48000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_16k_NS ) - L_FRAME48k / 2; - move16(); + Sample_Delay_HP = NS2SA_FX2( 48000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_16k_NS ) - L_FRAME48k / 2; } } ELSE { - Sample_Delay_HP = NS2SA( 48000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ) - L_FRAME48k / 2; - move16(); + Sample_Delay_HP = NS2SA_FX2( 48000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ) - L_FRAME48k / 2; } IF( NE_16( st->last_extl, FB_TBE ) ) @@ -7569,6 +7646,7 @@ void TBEreset_enc_fx( { set16_fx( hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2 ); hBWE_TD->bwe_non_lin_prev_scale_fx = L_deposit_l( 0 ); + move32(); st_fx->prev_Q_bwe_exc = 31; move16(); }