Commit 6e0539df authored by multrus's avatar multrus
Browse files

[cleanup] accept HARM_LEV_DURBIN

parent 13b2e5df
Loading
Loading
Loading
Loading
+0 −199
Original line number Diff line number Diff line
@@ -448,9 +448,7 @@ static Word32 Div_32_opt( Word32 L_num /*Q31*/, Word16 denom_hi /*Qx -16*/, Word
 */

static Word16 E_LPC_lev_dur_stab(
#ifdef HARM_LEV_DURBIN
    const Word16 element_mode,
#endif
    const Word16 Rh[] /*QR -16*/,
    const Word16 Rl[] /*QR -1*/,
    Word16 A[] /*Qx*/,
@@ -615,7 +613,6 @@ static Word16 E_LPC_lev_dur_stab(
        t1 = L_max( t1, L_abs( t0 ) );
    }

#ifdef HARM_LEV_DURBIN
    IF( element_mode == EVS_MONO )
    {
        k = s_min( norm_l( t1 ), 3 );
@@ -624,9 +621,6 @@ static Word16 E_LPC_lev_dur_stab(
    {
        k = s_min( sub( norm_l( t1 ), 1 ), 3 );
    }
#else
    k = s_min( norm_l( t1 ), 3 );
#endif
    A[0] = shl( 2048, k );
    move16();
    FOR( i = 1; i <= order; i++ )
@@ -655,205 +649,12 @@ static Word16 E_LPC_lev_dur_stab(

Word16 E_LPC_lev_dur_fx( const Word16 Rh[] /*QR -16*/, const Word16 Rl[] /*QR -1*/, Word16 A[] /*Qx*/, Word32 epsP[] /*QR*/, const Word16 order, Word16 *mem /*Qx*/ )
{
#ifdef HARM_LEV_DURBIN
    return ( E_LPC_lev_dur_stab( EVS_MONO, Rh, Rl, A, epsP, order, mem, 32750 ) ); /* 0.99945 in Q15 */
#else
    return ( E_LPC_lev_dur_stab( Rh, Rl, A, epsP, order, mem, 32750 ) );         /* 0.99945 in Q15 */
#endif
}

#ifndef HARM_LEV_DURBIN
static Word16 E_LPC_lev_dur_stab_ivas_fx( const Word16 Rh[], const Word16 Rl[], Word16 A[], Word32 epsP[], const Word16 order, Word16 *mem, Word16 k_max )
{
    Word16 i, j, k;
    Word16 hi, lo;
    Word16 Kh, Kl;                /* reflection coefficient; hi and lo           */
    Word16 alp_h, alp_l, alp_exp; /* Prediction gain; hi lo and exponent         */
    Word32 t0, t1, t2;            /* temporary variables                         */
    Word16 flag;
    Word16 Ah[TCXLTP_LTP_ORDER + 1], Al[TCXLTP_LTP_ORDER + 1]; /* LPC coef. in double prec. */

    BASOP_SATURATE_WARNING_OFF_EVS
    if ( epsP != NULL )
    {
        epsP[0] = L_Comp( Rh[0], Rl[0] );
        move32();
    }

    flag = 0;
    move16();

    /* K = A[1] = -R[1] / R[0] */
    t1 = L_Comp( Rh[1], Rl[1] ); /* R[1] in Q31      */
    t2 = L_abs( t1 );            /* abs R[1]         */
    t0 = L_deposit_l( 0 );
    IF( Rh[0] != 0 )
    {
        t0 = Div_32_opt( t2, Rh[0], Rl[0] ); /* R[1]/R[0] in Q31 */
        /* Cause a difference in MODE1 due to different implementation of div32*/
    }
    if ( t1 > 0 )
    {
        t0 = L_negate( t0 ); /* -R[1]/R[0]       */
    }
    Kl = L_Extract_lc( t0, &Kh );    /* K in DPF         */
    t0 = L_shr( t0, 4 );             /* A[1] in Q27      */
    L_Extract( t0, &Ah[1], &Al[1] ); /* A[1] in DPF      */

    /* Alpha = R[0] * (1-K**2) */
    t0 = Sqr_32( Kh, Kl );                  /* K*K      in Q31 */
    t0 = L_abs( t0 );                       /* Some case <0 !! */
    t0 = L_sub( (Word32) 0x7fffffffL, t0 ); /* 1 - K*K  in Q31 */
    lo = L_Extract_lc( t0, &hi );           /* DPF format      */
    t0 = Mpy_32( Rh[0], Rl[0], hi, lo );    /* Alpha in Q31    */
    if ( epsP != NULL )
    {
        epsP[1] = t0;
        move32();
    }

    /* Normalize Alpha */
    alp_exp = norm_l( t0 );
    t0 = L_shl( t0, alp_exp );
    alp_l = L_Extract_lc( t0, &alp_h );
    /* DPF format */

    /*--------------------------------------*
     * ITERATIONS  I=2 to m
     *--------------------------------------*/

    FOR( i = 2; i <= order; i++ )
    {
        /* t0 = SUM(R[j]*A[i-j], j=1, i-1) + R[i] */
        t0 = L_deposit_l( 0 );
        FOR( j = 1; j < i; j++ )
        {
            t0 = Mac_32( t0, Rh[j], Rl[j], Ah[i - j], Al[i - j] );
        }

        t0 = L_shl_sat( t0, 4 ); /* result in Q27 -> convert to Q31 */
                                 /* No overflow possible            */

        /* Compose and add R[i] in Q3 */
        t0 = L_mac_sat( t0, Rl[i], 1 );
        t0 = L_msu_sat( t0, Rh[i], -32768 );

        /* K = -t0 / Alpha */
        t1 = L_abs( t0 );
        t2 = L_deposit_l( 0 );
        IF( alp_h != 0 )
        {
            t2 = Div_32_opt( t1, alp_h, alp_l ); /* abs(t0)/Alpha                   */
            /* Cause a difference in MODE1 due to different implementation of div32*/
}

        if ( t0 > 0 )
        {
            t2 = L_negate( t2 ); /* K =-t0/Alpha                    */
        }
        t2 = L_shl_sat( t2, alp_exp ); /* denormalize; compare to Alpha   */
        test();
        if ( ( mem != NULL ) && ( ( GT_16( abs_s( extract_h( t2 ) ), k_max ) ) ) )
        {
            flag = 1;
            move16(); /* Test for unstable filter. If unstable keep old A(z) */
        }
        test();
        if ( ( mem != NULL ) && ( ( LT_32( L_abs( t2 ), 5 ) ) ) )
        {
            flag = 1;
            move16(); /*R matrix not reliable (R saturated for many coeff), keep old A(z) */
        }
        Kl = L_Extract_lc( t2, &Kh ); /* K in DPF                        */

        /*------------------------------------------*
         *  Compute new LPC coeff. -> An[i]
         *  An[j]= A[j] + K*A[i-j], j=1 to i-1
         *  An[i]= K
         *------------------------------------------*/

        k = mult_r( i, 16384 );
        FOR( j = 1; j < k; j++ )
        {
            /* Do two Iterations Together to Allow Direct Update of Ah & Al */
            t0 = Mac_32( L_Comp( Ah[j], Al[j] ), Kh, Kl, Ah[i - j], Al[i - j] );
            t1 = Mac_32( L_Comp( Ah[i - j], Al[i - j] ), Kh, Kl, Ah[j], Al[j] );
            L_Extract( t0, &Ah[j], &Al[j] );
            L_Extract( t1, &Ah[i - j], &Al[i - j] );
        }
        IF( s_and( i, 1 ) == 0 )
        {
            t0 = Mac_32( L_Comp( Ah[j], Al[j] ), Kh, Kl, Ah[i - j], Al[i - j] );
            L_Extract( t0, &Ah[j], &Al[j] );
        }
        t2 = L_shr( t2, 4 );             /* t2 = K in Q31 ->convert to Q27 */
        L_Extract( t2, &Ah[i], &Al[i] ); /* An[i] in Q27                   */

        /* Alpha = Alpha * (1-K**2) */
        t1 = L_mult_sat( Kh, Kh ); /* K*K      in Q31 */
        t0 = L_mac( t1, mult( Kh, Kl ), 2 );
        t0 = L_abs( t0 );                       /* Some case <0 !! */
        t0 = L_sub( (Word32) 0x7fffffffL, t0 ); /* 1 - K*K  in Q31 */
        lo = L_Extract_lc( t0, &hi );           /* DPF format      */
        t0 = Mpy_32( alp_h, alp_l, hi, lo );    /* Alpha in Q31    */


        /* store denormalized alpha in epsP */
        t1 = L_shr( t0, alp_exp );
        if ( epsP != NULL )
        {
            epsP[i] = t1;
            move32();
        }

        /* Normalize Alpha */
        j = norm_l( t0 );
        t0 = L_shl( t0, j );
        alp_l = L_Extract_lc( t0, &alp_h ); /* DPF format */
        alp_exp = add( alp_exp, j );        /* Add normalization to alp_exp */
    }

    /* Adaptive scaling */
    t1 = L_deposit_l( 0 );
    FOR( i = 1; i <= order; i++ )
    {
        t0 = L_Comp( Ah[i], Al[i] );
        t1 = L_max( t1, L_abs( t0 ) );
    }
    k = s_min( sub( norm_l( t1 ), 1 ), 3 );
    A[0] = shl( 2048, k );
    move16();
    FOR( i = 1; i <= order; i++ )
    {
        t0 = L_Comp( Ah[i], Al[i] );
        A[i] = round_fx_sat( L_shl_sat( t0, k ) );
        move16();
    }

    BASOP_SATURATE_WARNING_ON_EVS
    IF( mem != NULL )
    {
        /* Enforce stable LPC filter  - parcorr[0] and parcorr[1] are not LPC coeffiecients */
        IF( flag )
        {
            Copy( mem, A, add( order, 1 ) );
        }
        ELSE /* If stable LPC filter, store into memories */
        {
            Copy( A, mem, add( order, 1 ) );
        }
    }

    return ( flag );
}
#endif
Word16 E_LPC_lev_dur_ivas_fx( const Word16 Rh[], const Word16 Rl[], Word16 A[], Word32 epsP[], const Word16 order, Word16 *mem )
{
#ifdef HARM_LEV_DURBIN
    return ( E_LPC_lev_dur_stab( IVAS_SCE /* just to differentiate from EVS_MONO */, Rh, Rl, A, epsP, order, mem, 32750 ) ); /* 0.99945 in Q15 */
#else
    return ( E_LPC_lev_dur_stab_ivas_fx( Rh, Rl, A, epsP, order, mem, 32750 ) ); /* 0.99945 in Q15 */
#endif
}


+0 −1
Original line number Diff line number Diff line
@@ -83,7 +83,6 @@
#define FIX_1990_SANITIZER_IN_REVERB_LOAD               /* Nokia: Fix issue part of issue 1990 by introducing missing free of structure - keep until #2059 is addressed */
#define TMP_1342_WORKAROUND_DEC_FLUSH_BROKEN_IN_SR      /* FhG: Temporary workaround for incorrect implementation of decoder flush with split rendering */
#define NONBE_1122_KEEP_EVS_MODE_UNCHANGED              /* FhG: Disables fix for issue 1122 in EVS mode to keep BE tests green. This switch should be removed once the 1122 fix is added to EVS via a CR.  */
#define HARM_LEV_DURBIN                                 /* VA: basop issue 2423: harmonize levinson-Durbin algorithm */
#define HARMONIZE_TBE2                                  /* VA: basop issue 2399: Remove duplicated code: TBE, step 2 */
#define HARMONIZE_2427_GETPLC                           /* FhG: basop issue : 2427 Harmonizing getPLCDecision functions:*/
#define HARM_FD_BWE                                     /* VA: harmonize core-coder FD BWE function duplications */