Commit 1949602b authored by Sandesh Venkatesh's avatar Sandesh Venkatesh
Browse files

Merge branch 'q_doc_updates_4' into 'main'

Q-documentation and instrumentation updates for lib-enc files

See merge request !1008
parents 7d24206b 6d0578a4
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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 ) );
    }

    /*----------------------------------------------------------------*
+65 −42
Original line number Diff line number Diff line
@@ -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();
+55 −37

File changed.

Preview size limit exceeded, changes collapsed.

+90 −97

File changed.

Preview size limit exceeded, changes collapsed.

+17 −16
Original line number Diff line number Diff line
@@ -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 );
    }
Loading