Commit dd0bbadf authored by Sandesh Venkatesh's avatar Sandesh Venkatesh
Browse files

Merge branch 'Q_info_updates_2' into 'main'

Q info updates 2

See merge request !727
parents a039cce3 0370eaa3
Loading
Loading
Loading
Loading
+81 −81
Original line number Diff line number Diff line
@@ -65,11 +65,11 @@ Word16 expfp_evs(

    assert( x <= 0 );

    L_tmp = L_negate( L_shl( L_deposit_h( x ), sub( x_e, 15 ) ) );
    L_tmp = L_negate( L_shl( L_deposit_h( x ), sub( x_e, 15 ) ) ); /* Q16 */

    /* split into integer and fractional parts */
    xi = round_fx( L_tmp );
    xf = extract_l( L_tmp );
    xi = round_fx( L_tmp );  /* Q0 */
    xf = extract_l( L_tmp ); /* Q16 */

    BASOP_SATURATE_WARNING_OFF;
    xf = negate( xf );
@@ -81,13 +81,13 @@ Word16 expfp_evs(
            +       ((xf*xf) / (2*65536))
            +   ((((((xf*xf) / (2*65536))*xf) / 65536)*65536/3) / 65536)
            + ((((((((xf*xf) / (2*65536))*xf) / 65536)*65536/3) / 65536)*xf) / (4*65536)); */
    y = L_mac0( 65536, xf, 1 );
    tmp = shr( mult( xf, xf ), 2 );
    y = L_mac0( y, tmp, 1 );
    y = L_mac0( 65536, xf, 1 );     /* Q16 */
    tmp = shr( mult( xf, xf ), 2 ); /* Q15 */
    y = L_mac0( y, tmp, 1 );        /* Q16 */
    tmp = shr( mult( shr( mult( tmp, xf ), 1 ), 65536 / 3 ), 1 );
    y = L_mac0( y, tmp, 1 );
    y = L_mac0( y, tmp, 1 ); /* Q16 */
    tmp = shr( mult( tmp, xf ), 3 );
    y = L_mac0( y, tmp, 1 );
    y = L_mac0( y, tmp, 1 ); /* Q16 */

    /* Integer part */
    b0 = s_and( xi, 1 );
@@ -105,7 +105,7 @@ Word16 expfp_evs(
        y = Mpy_32_16_1( y, 22513 ); /* exp(-8) in -11Q26 */

    /* scaling: -1*b0 - 2*b1 -5*b2 -11*b3 */
    y = L_shr( y, add( add( xi, shr( xi, 2 ) ), shr( b3, 3 ) ) );
    y = L_shr( y, add( add( xi, shr( xi, 2 ) ), shr( b3, 3 ) ) ); /* Q16 */

    /* zero for xi >= 16 */
    if ( shr( xi, 4 ) > 0 )
@@ -157,44 +157,44 @@ void powfp_odd2_evs(
        maxk = sub( 15, norm_s( exp ) );
        assert( maxk < 12 );

        pows[0] = base;
        pows[0] = base; /* Q15 */
        move16();
        FOR( k = 0; k < maxk; k++ )
        {
            pows[k + 1] = mult_r( pows[k], pows[k] );
            pows[k + 1] = mult_r( pows[k], pows[k] ); /* Q15 */
            move16();
        }
        k = sub( k, 1 );
        k--;
        h = shl( 1, k ); /* highest bit of exp2 */
        out2 = base;
        out2 = base;     /* Q15 */
        move16();
        out = mult_r( out, pows[add( k, 1 )] ); /* we already know that "exp" has the highest bit set to one since we calculated .. */
        out = mult_r( out, pows[k + 1] ); /* we already know that "exp" has the highest bit set to one since we calculated .. */
        /* .. the effective length of "exp" earlier on, thus we omit the branch for out2 */
        if ( s_and( exp2, h ) != 0 )
        {
            out2 = mult_r( out2, pows[add( k, 1 )] );
            out2 = mult_r( out2, pows[k + 1] ); /* Q15 */
        }

        h = shr( h, 1 );
        FOR( k = sub( k, 1 ); k >= 0; k-- )
        FOR( k = k - 1; k >= 0; k-- )
        {
            if ( s_and( exp, h ) != 0 )
            {
                out = mult_r( out, pows[k + 1] );
                out = mult_r( out, pows[k + 1] ); /* Q15 */
            }

            if ( s_and( exp2, h ) != 0 )
            {
                out2 = mult_r( out2, pows[k + 1] );
                out2 = mult_r( out2, pows[k + 1] ); /* Q15 */
            }

            h = shr( h, 1 );
        }
    }

    *pout1 = out2;
    *pout1 = out2; /* Q15 */
    move16();
    *pout2 = out;
    *pout2 = out; /* Q15 */
    move16();

    return;
@@ -256,8 +256,8 @@ void tcx_arith_scale_envelope_ivas(
    L_tmp = L_sub( L_tmp, L_shr( L_mult0( target_bits, 30199 ), 11 ) );            /* Q15; 30199 -> 0.00045f (Q26) */
    L_tmp = L_add( L_tmp, 39322 );                                                 /* Q15; 39322 -> 1.2f (Q15) */
    L_tmp = Mpy_32_16_1( L_tmp, target_bits );                                     /* Q0 */
    assert( L_tmp < 32768 );
    target_bits = extract_l( L_tmp );
    assert( LE_32( L_tmp, 32768 ) );
    target_bits = extract_l( L_tmp ); /* Q0 */

    /* Calculate inverse envelope and find initial scale guess based on mean */
    mean = L_deposit_l( 0 );
@@ -271,22 +271,22 @@ void tcx_arith_scale_envelope_ivas(
#ifndef BASOP_NOGLOB
        tmp = Inv16( round_fx( L_shl( env[k], tmp ) ), &tmp2 );
#else                                                           /* BASOP_NOGLOB */
        tmp = Inv16( round_fx_o( L_shl( env[k], tmp ), &Overflow ), &tmp2 );
        tmp = Inv16( round_fx_o( L_shl( env[k], tmp ), &Overflow ), &tmp2 );                                                                            /* exp(tmp2) */
#endif                                                          /* BASOP_NOGLOB */
        ienv[k] = L_shl( L_deposit_h( tmp ), sub( tmp2, 15 ) ); /* Q16 */
        move32();
        mean = L_add( mean, ienv[k] );
        mean = L_add( mean, ienv[k] ); /* Q16 */
    }
    tmp = norm_s( L_frame );
    tmp2 = div_s( 8192, shl( L_frame, tmp ) );
    tmp2 = div_s( 8192, shl( L_frame, tmp ) ); /* Q15 */
    tmp = shl( tmp2, sub( tmp, 7 ) );
    mean = L_shr( Mpy_32_16_1( mean, tmp ), 6 ); /* Q16 */

    /* Rate dependent compensation to get closer to the target on average */
    /* mean = powf(mean, (float)L_frame / target_bits * 0.357f); */
    tmp = BASOP_Util_Divide1616_Scale( L_frame, target_bits, &tmp2 );
    tmp = mult_r( tmp, FL2WORD16( 0.357f ) );
    mean = BASOP_Util_fPow( mean, 15, L_deposit_h( tmp ), tmp2, &mean_e );
    tmp = BASOP_Util_Divide1616_Scale( L_frame, target_bits, &tmp2 ); /* exp(tmp2) */
    tmp = mult_r( tmp, 11698 /*0.357f Q15*/ );
    mean = BASOP_Util_fPow( mean, 15, L_deposit_h( tmp ), tmp2, &mean_e ); /* exp(mean_e) */

    /* Find first-guess scaling coefficient "scale" such that if "mean" is the
     * mean of the envelope, then the mean bit-consumption is approximately
@@ -294,22 +294,22 @@ void tcx_arith_scale_envelope_ivas(
     * log2(2*e*mean*scale + 0.15 + 0.035/(mean*scale)) * L_frame = target_bits
     */
    /* a = 2*2.71828183f*mean*mean; */
    tmp = round_fx( mean );
    a = L_mult( mult_r( tmp, FL2WORD16_SCALE( 2.71828183f, 2 ) ), tmp );
    tmp = round_fx( mean );                                      /* Q15 - mean_e */
    a = L_mult( mult_r( tmp, 22268 /*2.71828183f Q13*/ ), tmp ); /* 2 * mean_e + 3 */
    a_e = add( shl( mean_e, 1 ), 3 );

    /* b = (0.15f - powf(2.0f, target_bits/(float)L_frame)) * mean; */
    tmp = BASOP_Util_Divide1616_Scale( target_bits, L_frame, &tmp2 );
    tmp = BASOP_Util_Divide1616_Scale( target_bits, L_frame, &tmp2 ); /* exp(tmp2) */
    tmp = round_fx( BASOP_util_Pow2( L_deposit_h( tmp ), tmp2, &tmp2 ) );
    b_e = BASOP_Util_Add_MantExp( FL2WORD16( 0.15f ), 0, negate( tmp ), tmp2, &b );
    b = mult_r( b, round_fx( mean ) );
    b_e = BASOP_Util_Add_MantExp( 4915 /*0.15f in Q15*/, 0, negate( tmp ), tmp2, &b );
    b = mult_r( b, round_fx( mean ) ); /* exp(b_e + mean_e) */
    b_e = add( b_e, mean_e );

    /* scale = (-b + sqrtf(b*b - 4.0f*a*0.035f)) / (2.0f * a); */
#ifndef BASOP_NOGLOB
    tmp = round_fx( BASOP_Util_Add_Mant32Exp( L_mult( b, b ), shl( b_e, 1 ), Mpy_32_16_1( a, FL2WORD16( -4.0f * 0.035f ) ), a_e, &tmp2 ) );
#else
    tmp = round_fx_o( BASOP_Util_Add_Mant32Exp( L_mult( b, b ), shl( b_e, 1 ), Mpy_32_16_1( a, FL2WORD16( -4.0f * 0.035f ) ), a_e, &tmp2 ), &Overflow );
    tmp = round_fx_o( BASOP_Util_Add_Mant32Exp( L_mult( b, b ), shl( b_e, 1 ), Mpy_32_16_1( a, -4588 /*-4.0f*0.035f Q15*/ ), a_e, &tmp2 ), &Overflow ); /* Q15 - a_e */
#endif

    IF( tmp <= 0 )
@@ -328,7 +328,7 @@ void tcx_arith_scale_envelope_ivas(
    }

    tmp2 = BASOP_Util_Add_MantExp( negate( b ), b_e, tmp, tmp2, &scale );
    scale = BASOP_Util_Divide1616_Scale( scale, round_fx( a ), &tmp );
    scale = BASOP_Util_Divide1616_Scale( scale, round_fx( a ), &tmp ); /* exp(tmp) */
#ifndef BASOP_NOGLOB
    scale = shl( scale, sub( sub( add( tmp, tmp2 ), a_e ), 1 ) ); /* Q15 */
#else
@@ -338,24 +338,24 @@ void tcx_arith_scale_envelope_ivas(
    /* iscale = 1.0f / scale; */
    iscale_e = 0;
    move16();
    iscale = Inv16( s_max( 1, scale ), &iscale_e );
    iscale = Inv16( s_max( 1, scale ), &iscale_e ); /* exp(iscale_e) */

    lob = 0;
    move16();
    hib = 0;
    move16();

    max_iter = 2;
    max_iter = 2; /* Q0 */
    move16();
    if ( low_complexity )
    {
        max_iter = 1;
        max_iter = 1; /* Q0 */
        move16();
    }

    FOR( iter = 0; iter < max_iter; iter++ )
    {
        statesi = 0x7FFF;
        statesi = 0x7FFF; /* 1 in Q15 */
        move16();
        bits = 0;
        move16();
@@ -364,65 +364,65 @@ void tcx_arith_scale_envelope_ivas(
        {
            s = Mpy_32_16_1( ienv[k], scale ); /* Q16 */

            IF( L_sub( s, FL2WORD32_SCALE( 0.08f, 15 ) ) <= 0 )
            IF( L_sub( s, 5243l /*0.08f Q16*/ ) <= 0 )
            {
                /* If s = 0.08, the expected bit-consumption is log2(1.0224). Below 0.08, the bit-consumption
                   estimate function becomes inaccurate, so use log2(1.0224) for all values below 0.08. */
                /* round(state * 1.0224 * 32768) */
                statesi = mult_r( statesi, FL2WORD16_SCALE( 1.0224, 1 ) );
                statesi = mult_r( statesi, 16751 /*1.0224 Q14*/ ); /* Q14 */
                tmp = norm_s( statesi );
                statesi = shl( statesi, tmp );
                bits = add( bits, sub( 1, tmp ) );
                statesi = shl( statesi, tmp );     /* Q15 */
                bits = add( bits, sub( 1, tmp ) ); /* Q0 */
            }
            ELSE IF( L_sub( s, FL2WORD32_SCALE( 255.0, 15 ) ) <= 0 )
            ELSE IF( L_sub( s, 16711680l /*255.0 Q16*/ ) <= 0 )
            {
                /* a = 5.436564f * s + 0.15f + 0.035f * env[k] * iscale; */
                L_tmp = L_shl( Mpy_32_16_1( s, FL2WORD16_SCALE( 5.436564f, 3 ) ), 3 );
                L_tmp = L_add( L_tmp, FL2WORD32_SCALE( 0.15f, 15 ) );
                L_tmp = L_add( L_tmp, L_shl( Mpy_32_16_1( env[k], mult_r( FL2WORD16( 0.035f ), iscale ) ), iscale_e ) );
                L_tmp = L_shl( Mpy_32_16_1( s, 22268 /*5.436564f Q12*/ ), 3 );                                           /* Q16 */
                L_tmp = L_add( L_tmp, 9830l /*0.15f Q16*/ );                                                             /* Q16 */
                L_tmp = L_add( L_tmp, L_shl( Mpy_32_16_1( env[k], mult_r( 1147 /*0.035f Q15*/, iscale ) ), iscale_e ) ); /* Q16 */

                tmp = norm_l( L_tmp );
#ifndef BASOP_NOGLOB
                statesi = mult_r( statesi, round_fx( L_shl( L_tmp, tmp ) ) );
#else                                               /* BASOP_NOGLOB */
                statesi = mult_r( statesi, round_fx_o( L_shl( L_tmp, tmp ), &Overflow ) );
                statesi = mult_r( statesi, round_fx_o( L_shl( L_tmp, tmp ), &Overflow ) );                                                              /* */
#endif                                              /* BASOP_NOGLOB */
                bits = add( bits, sub( 15, tmp ) );
                bits = add( bits, sub( 15, tmp ) ); /* Q0 */

                tmp = norm_s( statesi );
                statesi = shl( statesi, tmp );
                bits = sub( bits, tmp );
                bits = sub( bits, tmp ); /* Q0 */
            }
            ELSE
            {
                /* for large envelope values, s > 255, bit consumption is approx log2(2*e*s)
                 * further, we use round(log2(x)) = floor(log2(x)+0.5) = floor(log2(x*sqrt(2))) */
                /* a = 5.436564f * s; */
                L_tmp = Mpy_32_16_1( s, FL2WORD16_SCALE( 5.436564f * 1.4142f, 3 ) ); /* Q13 */
                bits = add( bits, sub( 17, norm_l( L_tmp ) ) );
                L_tmp = Mpy_32_16_1( s, 31492 /*5.436564f * 1.4142f Q12*/ ); /* Q13 */
                bits = add( bits, sub( 17, norm_l( L_tmp ) ) );              /* Q0 */
            }
        }

        IF( sub( bits, target_bits ) <= 0 )
        {
            /* Bits leftover => scale is too small */
            lob = scale;
            lob = scale; /* Q0 */
            move16();
            lob_bits = bits;
            lob_bits = bits; /* Q0 */
            move16();

            IF( hib > 0 ) /* Bisection search */
            {
                adjust = div_s( sub( hib_bits, target_bits ), sub( hib_bits, lob_bits ) );
                scale = add( mult_r( sub( lob, hib ), adjust ), hib );
                adjust = div_s( sub( hib_bits, target_bits ), sub( hib_bits, lob_bits ) ); /* Q15 */
                scale = add( mult_r( sub( lob, hib ), adjust ), hib );                     /* Q0 */
            }
            ELSE
            {
                /* Initial scale adaptation */
                /* adjust = 1.05f * target_bits / (float)bits;
                   scale *= adjust; */
                adjust = mult_r( FL2WORD16_SCALE( 1.05f, 1 ), target_bits );
                adjust = BASOP_Util_Divide1616_Scale( adjust, bits, &tmp );
                adjust = mult_r( 17203 /*1.05f Q14*/, target_bits );        /* Q15 */
                adjust = BASOP_Util_Divide1616_Scale( adjust, bits, &tmp ); /* exp(tmp) */
                scale = shl( mult_r( scale, adjust ), add( 1, tmp ) );
            }
        }
@@ -431,13 +431,13 @@ void tcx_arith_scale_envelope_ivas(
            /* Ran out of bits => scale is too large */
            hib = scale;
            move16();
            hib_bits = bits;
            hib_bits = bits; /* Q0 */
            move16();

            IF( lob > 0 ) /* Bisection search */
            {
                adjust = div_s( sub( hib_bits, target_bits ), sub( hib_bits, lob_bits ) );
                scale = add( mult_r( sub( lob, hib ), adjust ), hib );
                adjust = div_s( sub( hib_bits, target_bits ), sub( hib_bits, lob_bits ) ); /* Q15 */
                scale = add( mult_r( sub( lob, hib ), adjust ), hib );                     /* Q0 */
            }
            ELSE
            { /* Initial scale adaptation */
@@ -449,13 +449,13 @@ void tcx_arith_scale_envelope_ivas(

                    FOR( k = 0; k < L_frame; k++ )
                    {
                        s_env[k] = 0;
                        s_env[k] = 0; /* Q15 - e */
                        move16();
                    }
                }
                ELSE
                {
                    adjust = div_s( mult_r( 31130 /*0.95f Q15*/, target_bits ), bits );
                    adjust = div_s( mult_r( 31130 /*0.95f Q15*/, target_bits ), bits ); /* Q15 */
                }
                scale = mult_r( scale, adjust );
            }
@@ -476,10 +476,10 @@ void tcx_arith_scale_envelope_ivas(
        }
        ELSE
        {
            iscale = Inv16( scale, &iscale_e );
            iscale = Inv16( scale, &iscale_e ); /* exp(iscale_e) */
        }
    }
    L_frame = L_spec_core;
    L_frame = L_spec_core; /* Q0 */
    move16();

    tmp = getScaleFactor32( env, L_frame );
@@ -495,9 +495,9 @@ void tcx_arith_scale_envelope_ivas(

    FOR( k = 0; k < L_frame; k++ )
    {
        L_tmp = Mpy_32_16_1( L_shl( env[k], tmp ), iscale );
        L_tmp = L_min( L_tmp, a );
        s_env[k] = round_fx( L_tmp );
        L_tmp = Mpy_32_16_1( L_shl( env[k], tmp ), iscale ); /* Q31 - e */
        L_tmp = L_min( L_tmp, a );                           /* Q31 - e */
        s_env[k] = round_fx( L_tmp );                        /* Q15 - e */
        move16();
    }

@@ -519,13 +519,13 @@ void tcx_arith_scale_envelope_ivas(
 *-------------------------------------------------------------------------*/

void tcx_arith_render_envelope_ivas(
    const Word16 A_ind[],     /* i  : LPC coefficients of signal envelope        */
    const Word16 L_frame,     /* i  : number of spectral lines                   */
    const Word16 L_spec,      /* i  : length of the coded spectrum               */
    const Word16 preemph_fac, /* i  : pre-emphasis factor                        */
    const Word16 gamma_w,     /* i  : A_ind -> weighted envelope factor          */
    const Word16 gamma_uw,    /* i  : A_ind -> non-weighted envelope factor      */
    Word32 env[]              /* o  : shaped signal envelope                     */
    const Word16 A_ind[],     /* i  : LPC coefficients of signal envelope        Q12*/
    const Word16 L_frame,     /* i  : number of spectral lines                   Q0*/
    const Word16 L_spec,      /* i  : length of the coded spectrum               Q0*/
    const Word16 preemph_fac, /* i  : pre-emphasis factor                        Q15*/
    const Word16 gamma_w,     /* i  : A_ind -> weighted envelope factor          Q15*/
    const Word16 gamma_uw,    /* i  : A_ind -> non-weighted envelope factor      Q14*/
    Word32 env[]              /* o  : shaped signal envelope                     Q16*/
)
{
    Word16 k;
@@ -545,7 +545,7 @@ void tcx_arith_render_envelope_ivas(
    /* Compute weighted signal envelope in perceptual domain */
    FOR( k = 0; k < FDNS_NPTS; k++ )
    {
        signal_env[k] = mult_r( signal_env[k], gainlpc[k] );
        signal_env[k] = mult_r( signal_env[k], gainlpc[k] ); /* exp(signal_env_e + gainlpc_e)  */
        move16();
        signal_env_e[k] = add( signal_env_e[k], gainlpc_e[k] );
        move16();
@@ -554,7 +554,7 @@ void tcx_arith_render_envelope_ivas(
    /* Adaptive low frequency emphasis */
    FOR( k = 0; k < L_frame; k++ )
    {
        env[k] = 0x10000;
        env[k] = 0x10000; /* 1 in Q16 */
        move32();
    }

@@ -565,7 +565,7 @@ void tcx_arith_render_envelope_ivas(

    FOR( k = L_frame; k < L_spec; ++k )
    {
        env[k] = env[k - 1];
        env[k] = env[k - 1]; /* Q16 */
        move32();
    }

+62 −62

File changed.

Preview size limit exceeded, changes collapsed.

+48 −31
Original line number Diff line number Diff line
@@ -67,32 +67,36 @@
 * Returns:
 *    void
 */
void basop_weight_a( const Word16 *a, Word16 *ap, const Word16 gamma )
void basop_weight_a(
    const Word16 *a,   /* Q12 */
    Word16 *ap,        /* Q12 */
    const Word16 gamma /* Q15 */
)
{
    Word16 i, fac;
    Word32 Amax;
    Word16 shift;


    fac = gamma;
    Amax = L_mult( 16384, a[0] );
    fac = gamma;                  /* Q15 */
    Amax = L_mult( 16384, a[0] ); /* Q27 */
    FOR( i = 1; i < M; i++ )
    {
        Amax = L_max( Amax, L_abs( L_mult0( fac, a[i] ) ) );
        fac = mult_r( fac, gamma );
        fac = mult_r( fac, gamma ); /* Q15 */
    }
    Amax = L_max( Amax, L_abs( L_mult0( fac, a[M] ) ) );
    Amax = L_max( Amax, L_abs( L_mult0( fac, a[M] ) ) ); /* Q27 */
    shift = norm_l( Amax );
    fac = gamma;
    ap[0] = shl( a[0], sub( shift, 1 ) );
    move16();
    FOR( i = 1; i < M; i++ )
    {
        ap[i] = round_fx( L_shl( L_mult0( a[i], fac ), shift ) );
        ap[i] = round_fx( L_shl( L_mult0( a[i], fac ), shift ) ); /* Q12 */
        move16();
        fac = mult_r( fac, gamma );
        fac = mult_r( fac, gamma ); /* Q15 */
    }
    ap[M] = round_fx( L_shl( L_mult0( a[M], fac ), shift ) );
    ap[M] = round_fx( L_shl( L_mult0( a[M], fac ), shift ) ); /* Q12 */
    move16();


@@ -113,7 +117,11 @@ void basop_weight_a( const Word16 *a, Word16 *ap, const Word16 gamma )
 * Returns:
 *    void
 */
void basop_weight_a_inv( const Word16 *a, Word16 *ap, const Word16 inv_gamma )
void basop_weight_a_inv(
    const Word16 *a,       /* Q12 */
    Word16 *ap,            /* Q12 */
    const Word16 inv_gamma /* Q14 */
)
{
    Word16 i;
    static const Word16 inv_gamma_tab_12k8[16] = { 17809, 19357, 21041, 22870, 24859, 27020, 29370, 31924,   /* Q14 */
@@ -130,7 +138,7 @@ void basop_weight_a_inv( const Word16 *a, Word16 *ap, const Word16 inv_gamma )
    {
        FOR( i = 0; i <= M; i++ )
        {
            ap[i] = a[i];
            ap[i] = a[i]; /* Q12 */
            move16();
        }
        return;
@@ -138,37 +146,37 @@ void basop_weight_a_inv( const Word16 *a, Word16 *ap, const Word16 inv_gamma )

    assert( inv_gamma == GAMMA1_INV || inv_gamma == GAMMA16k_INV );

    inv_gamma_tab = inv_gamma_tab_12k8;
    inv_gamma_tab = inv_gamma_tab_12k8; /* Q14 */
    move16();
    if ( sub( inv_gamma, GAMMA16k_INV ) == 0 )
    {
        inv_gamma_tab = inv_gamma_tab_16k;
        inv_gamma_tab = inv_gamma_tab_16k; /* Q14 */
        move16();
    }

    Amax = L_mult( 16384, a[0] );
    FOR( i = 1; i < 9; i++ )
    {
        Amax = L_max( Amax, L_abs( L_mult( a[i], inv_gamma_tab[i - 1] ) ) );
        Amax = L_max( Amax, L_abs( L_mult( a[i], inv_gamma_tab[i - 1] ) ) ); /* Q27 */
    }
    FOR( i = 9; i < 17; i++ )
    {
        Amax = L_max( Amax, L_abs( L_shl( L_mult( a[i], inv_gamma_tab[i - 1] ), 1 ) ) );
        Amax = L_max( Amax, L_abs( L_shl( L_mult( a[i], inv_gamma_tab[i - 1] ), 1 ) ) ); /* Q27 */
    }
    shift = norm_l( Amax );
    ap[0] = shl( a[0], sub( shift, 1 ) );
    ap[0] = shl( a[0], sub( shift, 1 ) ); /* Q11 + shift */
    move16();
    FOR( i = 1; i < 9; i++ )
    {
        L_tmp = L_mult( a[i], inv_gamma_tab[i - 1] );
        ap[i] = round_fx( L_shl( L_tmp, shift ) );
        L_tmp = L_mult( a[i], inv_gamma_tab[i - 1] ); /* Q27 */
        ap[i] = round_fx( L_shl( L_tmp, shift ) );    /* Q11 + shift */
        move16();
    }
    shift = add( shift, 1 );
    FOR( i = 9; i < 17; i++ )
    {
        L_tmp = L_mult( a[i], inv_gamma_tab[i - 1] );
        ap[i] = round_fx( L_shl( L_tmp, shift ) );
        L_tmp = L_mult( a[i], inv_gamma_tab[i - 1] ); /* Q27 */
        ap[i] = round_fx( L_shl( L_tmp, shift ) );    /* Q11 + shift */
        move16();
    }

@@ -190,39 +198,45 @@ void basop_weight_a_inv( const Word16 *a, Word16 *ap, const Word16 inv_gamma )
 * Returns:
 *    void
 */
void basop_E_LPC_a_add_tilt( const Word16 *a, Word16 *ap, Word16 gamma )
void basop_E_LPC_a_add_tilt(
    const Word16 *a, /* Q12 */
    Word16 *ap,      /* Q12 */
    Word16 gamma     /* Q15 */
)
{
    Word16 i;
    Word32 Amax, Atmp[M + 2];
    Word16 shift;


    Amax = L_mult( 16384, a[0] );
    Amax = L_mult( 16384, a[0] ); /* Q27 */
    FOR( i = 1; i <= M; i++ )
    {
        Atmp[i] = L_sub( L_mult( 16384, a[i] ), L_mult0( gamma, a[i - 1] ) );
        Atmp[i] = L_sub( L_mult( 16384, a[i] ), L_mult0( gamma, a[i - 1] ) ); /* Q27 */
        move32();
        Amax = L_max( Amax, L_abs( Atmp[i] ) );
        Amax = L_max( Amax, L_abs( Atmp[i] ) ); /* Q27 */
    }
    Atmp[M + 1] = L_negate( L_mult0( gamma, a[M] ) );
    Atmp[M + 1] = L_negate( L_mult0( gamma, a[M] ) ); /* Q27 */
    move32();
    Amax = L_max( Amax, L_abs( Atmp[M + 1] ) );
    Amax = L_max( Amax, L_abs( Atmp[M + 1] ) ); /* Q27 */
    shift = norm_l( Amax );
    ap[0] = shl( a[0], sub( shift, 1 ) );
    ap[0] = shl( a[0], sub( shift, 1 ) ); /* Q11 + shift */
    move16();
    FOR( i = 1; i <= M; i++ )
    {
        ap[i] = round_fx( L_shl( Atmp[i], shift ) );
        ap[i] = round_fx( L_shl( Atmp[i], shift ) ); /* Q11 + shift */
        move16();
    }
    ap[M + 1] = round_fx( L_shl( Atmp[M + 1], shift ) );
    ap[M + 1] = round_fx( L_shl( Atmp[M + 1], shift ) ); /* Q12 */
    move16();

    return;
}


static Word16 xsf_to_xsp( Word16 xsf )
static Word16 xsf_to_xsp(
    Word16 xsf /* Q2.56 */
)
{
    /* xsp = cos(xsf * 3.1415/6400); */
    return getCosWord16R2( xsf );
@@ -244,7 +258,10 @@ static Word16 xsf_to_xsp( Word16 xsf )
 * Returns:
 *    void
 */
void basop_lsf2lsp( const Word16 lsf[], Word16 lsp[] )
void basop_lsf2lsp(
    const Word16 lsf[], /* Q2.56 */
    Word16 lsp[]        /* Q15 */
)
{
    Word16 i;

@@ -252,7 +269,7 @@ void basop_lsf2lsp( const Word16 lsf[], Word16 lsp[] )
    /* convert ISFs to the cosine domain */
    FOR( i = 0; i < M; i++ )
    {
        *lsp++ = xsf_to_xsp( *lsf++ );
        *lsp++ = xsf_to_xsp( *lsf++ ); /* Q15 */
        move16();
    }

+33 −31

File changed.

Preview size limit exceeded, changes collapsed.

+51 −10
Original line number Diff line number Diff line
@@ -53,18 +53,59 @@
#define INT_FS_FX    12800 /* internal sampling frequency         */

void basop_lsp2a_stab( const Word16 *lsp, Word16 *a );
void basop_lsf2lsp( const Word16 lsf[], Word16 lsp[] );
void basop_weight_a( const Word16 *a, Word16 *ap, const Word16 gamma );
void basop_weight_a_inv( const Word16 *a, Word16 *ap, const Word16 inv_gamma );
void basop_E_LPC_a_add_tilt( const Word16 *a, Word16 *ap, Word16 gamma );
void basop_reorder_lsf( Word16 *lsf, const Word16 min_dist, const Word16 n, const Word32 Fs );
void basop_E_LPC_f_lsp_a_conversion( const Word16 *lsp, Word16 *a, const Word16 m );
void basop_lsf2lsp(
    const Word16 lsf[], /* Q2.56 */
    Word16 lsp[]        /* Q15 */
);

void basop_weight_a(
    const Word16 *a,   /* Q12 */
    Word16 *ap,        /* Q12 */
    const Word16 gamma /* Q15 */
);

void basop_weight_a_inv(
    const Word16 *a,       /* Q12 */
    Word16 *ap,            /* Q12 */
    const Word16 inv_gamma /* Q14 */
);
void basop_E_LPC_a_add_tilt(
    const Word16 *a, /* Q12 */
    Word16 *ap,      /* Q12 */
    Word16 gamma     /* Q14 */
);
void basop_reorder_lsf(
    Word16 *lsf,           /* i/o: LSFs in the frequency domain (0..0.5)   Q(x2.56)*/
    const Word16 min_dist, /* i  : minimum required distance               x2.56*/
    const Word16 n,        /* i  : LPC order                               Q0*/
    const Word32 Fs        /* i  : sampling frequency                      Q0*/
);
void basop_E_LPC_f_lsp_a_conversion(
    const Word16 *lsp, /* Q15 */
    Word16 *a,         /* Qx */
    const Word16 m     /* Q0 */
);

/* tcx_utils.c */
void basop_lpc2mdct( Word16 *lpcCoeffs, Word16 lpcOrder, Word16 *mdct_gains, Word16 *mdct_gains_exp, Word16 *mdct_inv_gains, Word16 *mdct_inv_gains_exp );

void basop_PsychAdaptLowFreqDeemph( Word32 x[], const Word16 lpcGains[], const Word16 lpcGains_e[], Word16 lf_deemph_factors[] );
void basop_mdct_noiseShaping_interp( Word32 x[], Word16 lg, Word16 gains[], Word16 gains_exp[] );
void basop_lpc2mdct(
    Word16 *lpcCoeffs,  /* Q12 */
    Word16 lpcOrder,    /* Q0 */
    Word16 *mdct_gains, /* Q12 */
    Word16 *mdct_gains_exp,
    Word16 *mdct_inv_gains, /* Q12 */
    Word16 *mdct_inv_gains_exp );

void basop_PsychAdaptLowFreqDeemph(
    Word32 x[],              /* Q16 */
    const Word16 lpcGains[], /* exp(lpcGains_e) */
    const Word16 lpcGains_e[],
    Word16 lf_deemph_factors[] /* Qx */
);
void basop_mdct_noiseShaping_interp(
    Word32 x[],     /* Q16 */
    Word16 lg,      /* Q0 */
    Word16 gains[], /* exp(gain_exp) */
    Word16 gains_exp[] );


#endif
Loading