Commit da80c76a authored by multrus's avatar multrus
Browse files

Merge branch 'basop_2479_harm' into 'main'

issue: 2479 "Harmonize tcx_ltp_pitch_search_*(), tcx_ltp_find_gain_*fx()"

Closes #2479

See merge request !2890
parents 1a2c179e fe8d835c
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -91,6 +91,7 @@
#define FIX_2463_EVS_BWE_LSF                            /* VA: basop issue 2463: harmonize calling of Quant_BWE_LSF_fx() */
#define FIX_2452_HQ_CORE_PEAQ_AVR_RATIO_HARM            /* Eri: Basop issue 2453: Fix alignment of peak_avrg_ratio_fx */
#define FIX_2480_HARM_TONALMDCT                         /* FhG: basop issue 2480: Harmonize TonalMDCTConceal_Detect_fx() and TonalMDCTConceal_Detect_ivas_fx() */
#define FIX_2479_HARM_PITCH_GAIN                        /* FhG: basop issue 2479: Harmonize tcx_ltp_pitch_search_*(), tcx_ltp_find_gain_*fx() */

/* #################### End BE switches ################################## */

+72 −8
Original line number Diff line number Diff line
@@ -73,7 +73,7 @@ static Word32 interpolate_corr(

    return s;
}

#ifndef FIX_2479_HARM_PITCH_GAIN
static void tcx_ltp_pitch_search(
    Word16 pitch_ol,
    Word16 *pitch_int,
@@ -278,6 +278,9 @@ static void tcx_ltp_pitch_search(
    }
}


#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,
@@ -293,6 +296,23 @@ static void tcx_ltp_pitch_search_ivas_fx(
    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,
    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 )
#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;
@@ -328,6 +348,10 @@ static void tcx_ltp_pitch_search_ivas_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 );
    FOR( t = negate( t_max ); t < len; t++ )
@@ -335,10 +359,9 @@ static void tcx_ltp_pitch_search_ivas_fx(
        wsp2[t + t_max] = shl( wsp[t], s_wsp ); // Q(x + s_wsp)
        move16();
    }
    wsp = wsp2 + t_max;

    wsp = wsp2 + t_max;
    pt_cor = cor;

    FOR( t = t_min; t <= t_max; t++ )
    {
        *pt_cor = dot( wsp, wsp - t, len ); // 2*(x + s_wsp)
@@ -495,7 +518,7 @@ static void tcx_ltp_pitch_search_ivas_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;
@@ -542,8 +565,12 @@ static void tcx_ltp_find_gain( Word16 *speech, Word16 *pred_speech, Word16 L_fra
    *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;
@@ -630,7 +657,9 @@ 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();

@@ -662,7 +691,12 @@ 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 ) ) );
        nPrevSubblocks = add( s_min( nPrevSubblocks, NSUBBLOCKS ), 1 );
@@ -722,8 +756,11 @@ 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 */
        {
@@ -957,7 +994,11 @@ 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
            {
@@ -969,7 +1010,11 @@ 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] ) )
@@ -994,6 +1039,17 @@ void tcx_ltp_encode_ivas_fx(
        }
        ELSE
        {
#ifdef FIX_2479_HARM_PITCH_GAIN
            Word16 check_border_case;
            IF( GT_16( element_mode, EVS_MONO ) )
            {
                check_border_case = 1;
            }
            ELSE
            {
                check_border_case = 0;
            }
#else
            Word16 tmp;
            IF( GT_16( element_mode, EVS_MONO ) )
            {
@@ -1003,8 +1059,13 @@ void tcx_ltp_encode_ivas_fx(
            {
                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 )
@@ -1120,8 +1181,11 @@ 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 */