Commit ddca9e5f authored by multrus's avatar multrus
Browse files

[cleanup] accept FIX_2479_HARM_PITCH_GAIN

parent ead75aed
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -91,7 +91,6 @@
#define NONBE_FIX_ISSUE_2206_AVOID_OVERFLOW_SWB_fenv_fx2 /* FhG: Avoid overflow of SWB_fenv_fx in SWB_BWE_encoding_fx because of very small energies. */
#define NONBE_FIX_ISSUE_2206_AVOID_OVERFLOW_MSVQ_Interpol_Tran_fx /* FhG: Fix saturation crash in MSVQ_Interpol_Tran_fx() */
#define FIX_2452_HQ_CORE_PEAQ_AVR_RATIO_HARM            /* Eri: Basop issue 2453: Fix alignment of peak_avrg_ratio_fx */
#define FIX_2479_HARM_PITCH_GAIN                        /* FhG: basop issue 2479: Harmonize tcx_ltp_pitch_search_*(), tcx_ltp_find_gain_*fx() */
#define HARMONIZE_2481_EXTEND_SHRINK                    /* FhG: basop issue 2481: Harmonize extend_frm_*fx() and shrink_frm_*fx() */
#define FIX_2485_HARMONIZE_perform_noise_estimation_enc /* FhG: harmonize perform_noise_estimation_enc and perform_noise_estimation_enc_ivas */
#define FIX_2485_HARMONIZE_minimum_statistics           /* FhG: harmonize minimum_statistics and minimum_statistics_fx */
+0 −317
Original line number Diff line number Diff line
@@ -73,230 +73,6 @@ static Word32 interpolate_corr(

    return s;
}
#ifndef FIX_2479_HARM_PITCH_GAIN
static void tcx_ltp_pitch_search(
    Word16 pitch_ol,
    Word16 *pitch_int,
    Word16 *pitch_fr,
    Word16 *index,
    Word16 *norm_corr,
    const Word16 len,
    Word16 *wsp,
    Word16 pitmin,
    Word16 pitfr1,
    Word16 pitfr2,
    Word16 pitmax,
    Word16 pitres )
{
    Word16 i, t, t0, t1, step, fraction, t0_min, t0_max, t_min, t_max, delta, temp_m, temp_e, s, s_wsp;
    Word16 cor_idx_ini, cor_idx;
    Word32 cor_max, cor[256], *pt_cor, temp;
    Word16 wsp2[L_FRAME_PLUS + PIT_MAX_MAX + L_INTERPOL1];

    delta = 16;
    move16();
    if ( EQ_16( pitres, 6 ) )
    {
        delta = 8;
        move16();
    }

    t0_min = sub( pitch_ol, shr( delta, 1 ) );
    t0_max = sub( add( t0_min, delta ), 1 );

    IF( LT_16( t0_min, pitmin ) )
    {
        t0_min = pitmin;
        move16();
        t0_max = sub( add( t0_min, delta ), 1 );
    }

    IF( GT_16( t0_max, pitmax ) )
    {
        t0_max = pitmax;
        move16();
        t0_min = add( sub( t0_max, delta ), 1 );
    }

    t_min = sub( t0_min, L_INTERPOL1 );
    t_max = add( t0_max, L_INTERPOL1 );

    /* normalize wsp */
    assert( len + t_max <= L_FRAME_PLUS + PIT_MAX_MAX + L_INTERPOL1 );
    s_wsp = getScaleFactor16( wsp - t_max, add( len, t_max ) );
    s_wsp = sub( s_wsp, 4 );
    FOR( t = negate( t_max ); t < len; t++ )
    {
        wsp2[t + t_max] = shl( wsp[t], s_wsp );
        move16();
    }
    wsp = wsp2 + t_max;
    move16();

    pt_cor = cor;
    move32();

    FOR( t = t_min; t <= t_max; t++ )
    {
        *pt_cor = dot( wsp, wsp - t, len );
        move32();
        pt_cor++;
    }

    pt_cor = cor + L_INTERPOL1;
    cor_max = L_add( *pt_cor++, 0 );
    t1 = t0_min;
    move16();
    move32();

    FOR( t = t0_min + 1; t <= t0_max; t++ )
    {
        IF( GT_32( *pt_cor, cor_max ) )
        {
            cor_max = *pt_cor;
            move32();
            t1 = t;
            move16();
        }
        pt_cor++;
    }

    temp = dot( wsp, wsp, len );
    s = norm_l( temp );
    temp_m = extract_h( L_shl( temp, s ) );
    temp_e = negate( s );

    temp = dot( wsp - t1, wsp - t1, len );
    s = norm_l( temp );
    temp_m = mult( temp_m, extract_h( L_shl( temp, s ) ) );
    temp_e = sub( temp_e, s );

    temp_m = Sqrt16( temp_m, &temp_e );

    if ( temp_m == 0 )
    {
        temp_m = 1;
        move16();
    }
    s = sub( norm_l( cor_max ), 1 );
    temp_m = divide1616( extract_h( L_shl( cor_max, s ) ), temp_m );
    temp_e = sub( negate( s ), temp_e );

    *norm_corr = shl_sat( temp_m, temp_e );

    IF( GE_16( t1, pitfr1 ) )
    {
        *pitch_int = t1;
        move16();
        *pitch_fr = 0;
        move16();

        *index = add( sub( t1, pitfr1 ), extract_l( L_mac0( L_mult0( sub( pitfr2, pitmin ), pitres ),
                                                            sub( pitfr1, pitfr2 ), shr( pitres, 1 ) ) ) );
        move16();

        return;
    }

    /*------------------------------------------------------------------*
     * Search fractional pitch with 1/4 subsample resolution.
     * search the fractions around t0 and choose the one which maximizes
     * the interpolated normalized correlation.
     *-----------------------------------------------------------------*/

    cor_idx_ini = sub( L_INTERPOL1, t0_min );
    t0 = t1;
    move16();

    step = 1;
    move16();
    if ( GE_16( t0, pitfr2 ) )
    {
        step = 2;
        move16();
    }
    fraction = step;
    move16();

    IF( EQ_16( t0, t0_min ) ) /* Limit case */
    {
        cor_idx = add( cor_idx_ini, t0 );
        fraction = 0;
        move16();
        cor_max = interpolate_corr( &cor[cor_idx], fraction, pitres );
    }
    ELSE /* Process negative fractions */
    {
        t0 = sub( t0, 1 );
        cor_idx = add( cor_idx_ini, t0 );
        cor_max = interpolate_corr( &cor[cor_idx], fraction, pitres );

        FOR( i = fraction + step; i < pitres; i += step )
        {
            temp = interpolate_corr( &cor[cor_idx], i, pitres );

            IF( GT_32( temp, cor_max ) )
            {
                cor_max = L_add( temp, 0 );
                fraction = i;
                move16();
            }
        }
    }

    cor_idx = add( cor_idx_ini, t1 );
    FOR( i = 0; i < pitres; i += step ) /* Process positive fractions */
    {
        temp = interpolate_corr( &cor[cor_idx], i, pitres );

        IF( GT_32( temp, cor_max ) )
        {
            cor_max = L_add( temp, 0 );
            fraction = i;
            move16();
            t0 = t1;
            move16();
        }
    }

    *pitch_int = t0;
    move16();
    *pitch_fr = fraction;
    move16();

    IF( GE_16( t0, pitfr2 ) )
    {
        *index = add( extract_l( L_mac0( L_mult0( sub( t0, pitfr2 ), shr( pitres, 1 ) ),
                                         sub( pitfr2, pitmin ), pitres ) ),
                      shr( fraction, 1 ) );
        move16();
    }
    ELSE
    {
        *index = add( imult1616( sub( t0, pitmin ), pitres ), fraction );
        move16();
    }
}


#endif // !FIX_2479_HARM_PITCH_GAIN
#ifndef FIX_2479_HARM_PITCH_GAIN
static void tcx_ltp_pitch_search_ivas_fx(
    const Word16 pitch_ol,
    Word16 *pitch_int,
    Word16 *pitch_fr,
    Word16 *index,
    Word16 *norm_corr,
    const Word16 len,
    const Word16 *wsp, // Qx
    const Word16 pitmin,
    const Word16 pitfr1,
    const Word16 pitfr2,
    const Word16 pitmax,
    const Word16 pitres,
    const Word16 check_border_case,
    Word16 *border_case )
#else
static void tcx_ltp_pitch_search_fx(
    const Word16 pitch_ol,
    Word16 *pitch_int,
@@ -312,7 +88,6 @@ static void tcx_ltp_pitch_search_fx(
    const Word16 pitres,
    const Word16 check_border_case,
    Word16 *border_case )
#endif // !FIX_2479_HARM_PITCH_GAIN
{
    Word16 i, t, t0, t1, step, fraction, t0_min, t0_max, t_min, t_max, delta, temp_m, temp_e, s, s_wsp;
    Word16 cor_idx_ini, cor_idx;
@@ -348,9 +123,7 @@ static void tcx_ltp_pitch_search_fx(
    t_max = add( t0_max, L_INTERPOL1 );

    /* normalize wsp */
#ifdef FIX_2479_HARM_PITCH_GAIN
    assert( len + t_max <= L_FRAME_PLUS + PIT_MAX_MAX + L_INTERPOL1 );
#endif // FIX_2479_HARM_PITCH_GAIN

    s_wsp = getScaleFactor16( wsp - t_max, add( len, t_max ) );
    s_wsp = sub( s_wsp, 4 );
@@ -518,59 +291,7 @@ static void tcx_ltp_pitch_search_fx(
    }
}

#ifndef FIX_2479_HARM_PITCH_GAIN
static void tcx_ltp_find_gain( Word16 *speech, Word16 *pred_speech, Word16 L_frame, Word16 *gain, Word16 *gain_index )
{
    Word32 corr, ener;
    Word16 i, g, s1, s2, tmp;

    s1 = sub( getScaleFactor16( speech, L_frame ), 4 );
    s2 = sub( getScaleFactor16( pred_speech, L_frame ), 4 );

    /* Find gain */
    corr = L_deposit_l( 0 );
    ener = L_deposit_l( 1 );

    FOR( i = 0; i < L_frame; i++ )
    {
        tmp = shl_sat( pred_speech[i], s2 );
        corr = L_mac0_sat( corr, shl( speech[i], s1 ), tmp );
        ener = L_mac0_sat( ener, tmp, tmp );
    }

    s1 = sub( 1, add( s1, s2 ) );
    s2 = sub( 1, shl( s2, 1 ) );

    tmp = sub( norm_l( corr ), 1 );
    corr = L_shl( corr, tmp );
    s1 = sub( s1, tmp );

    tmp = norm_l( ener );
    ener = L_shl( ener, tmp );
    s2 = sub( s2, tmp );

    g = divide1616( round_fx_sat( corr ), round_fx_sat( ener ) );
    BASOP_SATURATE_WARNING_OFF_EVS
    g = shl_sat( g, sub( s1, s2 ) );
    BASOP_SATURATE_WARNING_ON_EVS

    /* Quantize gain */
    g = shr( sub_sat( g, 0x1000 ), 13 );
    g = s_max( g, -1 );

    *gain_index = g;
    move16();

    /* Dequantize gain */
    *gain = imult1616( add( g, 1 ), 0x1400 );
    move16();
}
#endif // !FIX_2479_HARM_PITCH_GAIN
#ifndef FIX_2479_HARM_PITCH_GAIN
static void tcx_ltp_find_gain_ivas_fx( Word16 *speech /*Qx*/, Word16 *pred_speech /*Qx*/, Word16 L_frame, Word16 *gain, Word16 *gain_index )
#else
static void tcx_ltp_find_gain_fx( Word16 *speech /*Qx*/, Word16 *pred_speech /*Qx*/, Word16 L_frame, Word16 *gain, Word16 *gain_index )
#endif // !FIX_2479_HARM_PITCH_GAIN
{
    Word32 corr, ener;
    Word16 i, g, s1, s2, tmp;
@@ -657,9 +378,7 @@ void tcx_ltp_encode_fx(
    Word16 buf_zir[M + L_SUBFR], *zir;
    Word16 Aest[M + 1];
    Word16 alpha, step;
#ifdef FIX_2479_HARM_PITCH_GAIN
    Word16 border_case;
#endif // FIX_2479_HARM_PITCH_GAIN
    norm_corr = 0;
    move16();

@@ -691,11 +410,7 @@ void tcx_ltp_encode_fx(
        }

        /* Find pitch lag */
#ifndef FIX_2479_HARM_PITCH_GAIN
        tcx_ltp_pitch_search( Top, pitch_int, pitch_fr, &ltp_param[1], &norm_corr, L_frame, wsp, pitmin, pitfr1, pitfr2, pitmax, pitres );
#else
        tcx_ltp_pitch_search_fx( Top, pitch_int, pitch_fr, &ltp_param[1], &norm_corr, L_frame, wsp, pitmin, pitfr1, pitfr2, pitmax, pitres, 0, &border_case );
#endif // !FIX_2479_HARM_PITCH_GAIN


        nPrevSubblocks = extract_h( L_mac( 0x17fff, NSUBBLOCKS, div_s( *pitch_int, L_frame ) ) );
@@ -756,11 +471,7 @@ void tcx_ltp_encode_fx(
        predict_signal( speech, pred_speech, *pitch_int, *pitch_fr, pitres, L_frame );

        /* Find gain */
#ifndef FIX_2479_HARM_PITCH_GAIN
        tcx_ltp_find_gain( speech, pred_speech, L_frame, gain, &ltp_param[2] );
#else
        tcx_ltp_find_gain_fx( speech, pred_speech, L_frame, gain, &ltp_param[2] );
#endif // !FIX_2479_HARM_PITCH_GAIN
        /* Total number of bits for LTP */
        IF( NE_16( ltp_param[2], -1 ) ) /* gain > 0 */
        {
@@ -994,11 +705,7 @@ void tcx_ltp_encode_ivas_fx(
            IF( LT_16( abs_s( sub( Top[0], Top[1] ) ), shr( delta, 1 ) ) )
            {
                /* estimates are close enough and stable, take the artihmetic mean as estimate */
#ifndef FIX_2479_HARM_PITCH_GAIN
                tcx_ltp_pitch_search_ivas_fx( shr( add( Top[0], Top[1] ), 1 ), &hTcxEnc->tcxltp_pitch_int, &hTcxEnc->tcxltp_pitch_fr, &ltp_param[1], &norm_corr_fx, L_frame, wsp_fx, st->pit_min, st->pit_fr1, st->pit_fr2, st->pit_max, st->pit_res_max, 1, &border_case );
#else
                tcx_ltp_pitch_search_fx( shr( add( Top[0], Top[1] ), 1 ), &hTcxEnc->tcxltp_pitch_int, &hTcxEnc->tcxltp_pitch_fr, &ltp_param[1], &norm_corr_fx, L_frame, wsp_fx, st->pit_min, st->pit_fr1, st->pit_fr2, st->pit_max, st->pit_res_max, 1, &border_case );
#endif // !FIX_2479_HARM_PITCH_GAIN
            }
            ELSE
            {
@@ -1010,11 +717,7 @@ void tcx_ltp_encode_ivas_fx(

                FOR( i = 0; i < 2; i++ )
                {
#ifndef FIX_2479_HARM_PITCH_GAIN
                    tcx_ltp_pitch_search_ivas_fx( Top[i], &pitch_int_2[i], &pitch_fr_2[i], &pit_param_2[i], &norm_corr_2_fx[i], L_frame, wsp_fx, st->pit_min, st->pit_fr1, st->pit_fr2, st->pit_max, st->pit_res_max, 1, &border_case );
#else
                    tcx_ltp_pitch_search_fx( Top[i], &pitch_int_2[i], &pitch_fr_2[i], &pit_param_2[i], &norm_corr_2_fx[i], L_frame, wsp_fx, st->pit_min, st->pit_fr1, st->pit_fr2, st->pit_max, st->pit_res_max, 1, &border_case );
#endif // !FIX_2479_HARM_PITCH_GAIN
                }

                IF( GT_16( norm_corr_2_fx[1], norm_corr_2_fx[0] ) )
@@ -1039,7 +742,6 @@ void tcx_ltp_encode_ivas_fx(
        }
        ELSE
        {
#ifdef FIX_2479_HARM_PITCH_GAIN
            Word16 check_border_case;
            IF( GT_16( element_mode, EVS_MONO ) )
            {
@@ -1049,23 +751,8 @@ void tcx_ltp_encode_ivas_fx(
            {
                check_border_case = 0;
            }
#else
            Word16 tmp;
            IF( GT_16( element_mode, EVS_MONO ) )
            {
                tmp = 1;
            }
            ELSE
            {
                tmp = 0;
            }
#endif
            move16();
#ifndef FIX_2479_HARM_PITCH_GAIN
            tcx_ltp_pitch_search_ivas_fx( Top[1], &hTcxEnc->tcxltp_pitch_int, &hTcxEnc->tcxltp_pitch_fr, &ltp_param[1], &norm_corr_fx, L_frame, wsp_fx, st->pit_min, st->pit_fr1, st->pit_fr2, st->pit_max, st->pit_res_max, tmp, &border_case );
#else
            tcx_ltp_pitch_search_fx( Top[1], &hTcxEnc->tcxltp_pitch_int, &hTcxEnc->tcxltp_pitch_fr, &ltp_param[1], &norm_corr_fx, L_frame, wsp_fx, st->pit_min, st->pit_fr1, st->pit_fr2, st->pit_max, st->pit_res_max, check_border_case, &border_case );
#endif // !FIX_2479_HARM_PITCH_GAIN
        }

        if ( border_case )
@@ -1181,11 +868,7 @@ void tcx_ltp_encode_ivas_fx(
    predict_signal( speech_fx, pred_speech_fx, hTcxEnc->tcxltp_pitch_int, hTcxEnc->tcxltp_pitch_fr, st->pit_res_max, L_frame );

    /* Find gain */
#ifndef FIX_2479_HARM_PITCH_GAIN
    tcx_ltp_find_gain_ivas_fx( speech_fx, pred_speech_fx, L_frame, &hTcxEnc->tcxltp_gain, &ltp_param[2] );
#else
    tcx_ltp_find_gain_fx( speech_fx, pred_speech_fx, L_frame, &hTcxEnc->tcxltp_gain, &ltp_param[2] );
#endif // !FIX_2479_HARM_PITCH_GAIN
    IF( ltp_param[0] )
    {
        /* Total number of bits for LTP */