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

Revert pca tools changes

parent de4b0bd4
Loading
Loading
Loading
Loading
Loading
+42 −78
Original line number Diff line number Diff line
@@ -560,22 +560,6 @@ void dquat2mat(
    return;
}

static Word16 check_bound( Word32 tmp )
{
    IF( GT_32( tmp, MAX16B ) )
    {
        return MAX16B;
    }
    ELSE IF( LT_32( tmp, MIN16B ) )
    {
        return MIN16B;
    }
    ELSE
    {
        return extract_l( tmp );
    }
}

#ifdef IVAS_FLOAT_FIXED
void dquat2mat_fx(
    const Word16 *ql,
@@ -621,37 +605,37 @@ void dquat2mat_fx(
    dx = mult( d, x );
    dy = mult( d, y );
    dz = mult( d, z );
    m[0] = check_bound( L_sub( L_sub( aw, bx ), L_add( cy, dz ) ) );
    m[0] = sub( sub( aw, bx ), add( cy, dz ) );
    move16();
    m[1] = check_bound( L_sub( L_sub( cz, dy ), L_add( ax, bw ) ) );
    m[1] = sub( sub( cz, dy ), add( ax, bw ) );
    move16();
    m[2] = check_bound( L_add( L_sub( L_sub( negate( ay ), bz ), cw ), dx ) );
    m[2] = add( sub( sub( negate( ay ), bz ), cw ), dx );
    move16();
    m[3] = check_bound( L_sub( L_sub( by, az ), L_add( cx, dw ) ) );
    m[3] = sub( sub( by, az ), add( cx, dw ) );
    move16();
    m[4] = check_bound( L_add( L_sub( L_add( bw, ax ), dy ), cz ) );
    m[4] = add( sub( add( bw, ax ), dy ), cz );
    move16();
    m[5] = check_bound( L_add( L_add( L_add( negate( bx ), aw ), dz ), cy ) );
    m[5] = add( add( add( negate( bx ), aw ), dz ), cy );
    move16();
    m[6] = check_bound( L_sub( L_sub( L_add( negate( by ), az ), dw ), cx ) );
    m[6] = sub( sub( add( negate( by ), az ), dw ), cx );
    move16();
    m[7] = check_bound( L_add( L_sub( L_sub( negate( bz ), ay ), dx ), cw ) );
    m[7] = add( sub( sub( negate( bz ), ay ), dx ), cw );
    move16();
    m[8] = check_bound( L_sub( L_add( L_add( cw, dx ), ay ), bz ) );
    m[8] = sub( add( add( cw, dx ), ay ), bz );
    move16();
    m[9] = check_bound( L_sub( L_sub( L_add( negate( cx ), dw ), az ), by ) );
    m[9] = sub( sub( add( negate( cx ), dw ), az ), by );
    move16();
    m[10] = check_bound( L_add( L_add( L_add( negate( cy ), dz ), aw ), bx ) );
    m[10] = add( add( add( negate( cy ), dz ), aw ), bx );
    move16();
    m[11] = check_bound( L_sub( L_add( L_sub( negate( cz ), dy ), ax ), bw ) );
    m[11] = sub( add( sub( negate( cz ), dy ), ax ), bw );
    move16();
    m[12] = check_bound( L_add( L_add( L_sub( dw, cx ), by ), az ) );
    m[12] = add( add( sub( dw, cx ), by ), az );
    move16();
    m[13] = check_bound( L_add( L_sub( L_sub( negate( dx ), cw ), bz ), ay ) );
    m[13] = add( sub( sub( negate( dx ), cw ), bz ), ay );
    move16();
    m[14] = check_bound( L_sub( L_add( L_sub( negate( dy ), cz ), bw ), ax ) );
    m[14] = sub( add( sub( negate( dy ), cz ), bw ), ax );
    move16();
    m[15] = check_bound( L_add( L_add( L_add( negate( dz ), cy ), bx ), aw ) );
    m[15] = add( add( add( negate( dz ), cy ), bx ), aw );
    move16();

    return;
@@ -844,11 +828,11 @@ static void norm_quat_fx(
    move16();
    norm_q = dotp_fx( q, q, IVAS_PCA_INTERP, &exp1 );
    exp1 = sub( 31, add( exp1, 2 ) );
    norm_q = ISqrt32( norm_q, &exp1 ); /*Q(31 - exp)*/
    norm_q = ISqrt32( norm_q, &exp1 ); /*q(15 - exp)*/

    FOR( i = 0; i < IVAS_PCA_INTERP; i++ )
    {
        q[i] = round_fx( L_shl( Mpy_32_16_1( norm_q, q[i] ), exp1 ) ); /* Q(15) */
        q[i] = mult( q[i], extract_l( L_shr( norm_q, 15 ) ) ); // todo : recheck
        move16();
    }

@@ -938,7 +922,7 @@ void pca_interp_preproc_fx(
{
    Word16 alpha;
    Word16 j;
    Word16 tmp, tmp2, tmp3, tmp_e;
    Word16 tmp, tmp2, tmp3;
    FOR( j = 0; j < len; j++ )
    {
        tmp = sub( len, 1 );
@@ -949,12 +933,11 @@ void pca_interp_preproc_fx(
        }
        ELSE
        {
            alpha = BASOP_Util_Divide1616_Scale( j, tmp, &tmp_e ); // the increment can be updated by simple delta
            alpha = shl_sat( alpha, tmp_e );                       /* Q15 */
            alpha = idiv1616( j, tmp ); // the increment can be updated by simple delta //q15
        }
        tmp2 = mult( EVS_PI_FX, alpha );     /* Q13 */
        tmp3 = getCosWord16( tmp2 );         /* Q14 */
        alpha = sub_sat( ONE_IN_Q14, tmp3 ); /* Q15 */
        tmp2 = mult( EVS_PI_FX, alpha );           // q13
        tmp3 = getCosWord16( tmp2 );               // q14
        alpha = shr( sub( ONE_IN_Q14, tmp3 ), 1 ); // q15
        alpha = sub( MAX_16, alpha );
        quat_nlerp_preproc_fx( prev_ql, ql, alpha, &ql_interp[j * IVAS_PCA_INTERP] );
        quat_nlerp_preproc_fx( prev_qr, qr, alpha, &qr_interp[j * IVAS_PCA_INTERP] );
@@ -1003,30 +986,16 @@ static void sp2cart_fx(
    Word16 *q )
{
    Word16 s1, s2, s1s2;
    Word16 sin_ph3, cos_ph3;

    sin_ph3 = cos_ph3 = ph3;
    s1 = getSinWord16( ph1 );                 // q15
    s2 = getSinWord16( ph2 );                 // q15
    s1s2 = mult( s1, s2 );                    // q15
    q[3] = mult( getSinWord16( ph3 ), s1s2 ); // q15
    move16();
    q[2] = mult( getCosWord16( ph3 ), s1s2 ); // q15
    move16();

    IF( GT_16( ph3, 12868 /* PI in Q12 */ ) )
    {
        sin_ph3 = sub( 12868, ph3 ); /* sin(x) = sin(PI - x) */
        cos_ph3 = sub( 25736, ph3 ); /* cos(x) = cos(2*PI - x) */
    }
    sin_ph3 = shl( sin_ph3, 1 ); /* Q12 -> Q13 */
    cos_ph3 = shl( cos_ph3, 1 ); /* Q12 -> Q13 */

    s1 = getSinWord16( ph1 );                     /* Q15 */
    s2 = getSinWord16( ph2 );                     /* Q15 */
    s1s2 = mult( s1, s2 );                        /* Q15 */
    q[3] = mult( getSinWord16( sin_ph3 ), s1s2 ); /* Q15 */
    move16();
    q[2] = shl_sat( mult( getCosWord16( cos_ph3 ), s1s2 ), 1 ); /* Q15 */
    q[1] = mult( getCosWord16( ph2 ), s1 ); // q15
    move16();
    q[1] = shl_sat( mult( getCosWord16( ph2 ), s1 ), 1 ); /* Q15 */
    move16();
    q[0] = shl_sat( getCosWord16( ph1 ), 1 ); /* Q15 */
    q[0] = shl_sat( getCosWord16( ph1 ), 1 ); // q15
    move16();

    return;
@@ -1052,9 +1021,9 @@ static Word16 calc_n2_fx(
{
    Word16 n2;
    Word32 temp;
    temp = L_mult( 23040, getSinWord16( ph1 ) ); /* Q8 + Q15 + Q1 = Q24 */
    n2 = round_fx( temp );                       /* Q24 -> Q8 */
    n2 = shr( n2, 8 );
    temp = L_mult( 23040, getSinWord16( ph1 ) ); // q8
    n2 = round_fx( temp );
    n2 = shr( n2, 7 );
    IF( s_and( n2, 1 ) == 0 )
    {
        n2 = add( n2, 1 );
@@ -1092,10 +1061,10 @@ static Word16 calc_n3_fx(
    const Word16 ph2 )
{
    Word16 n3;
    Word16 temp1 = mult( getSinWord16( ph2 ), getSinWord16( ph1 ) ); /* Q15 */
    n3 = round_fx( L_mult( temp1, 23040 /* 180.0f in Q7 */ ) );      /* Q15 + Q7 + Q1 - Q16 -> Q7*/
    Word16 temp1 = mult( getSinWord16( ph2 ), getSinWord16( ph1 ) ); // q7 + q15 - q15
    n3 = round_fx( L_mult( temp1, getSinWord16( ph2 ) ) );           // q7 + q15 - q15

    n3 = shr( n3, 7 );
    n3 = shr( n3, 8 );

    IF( n3 == 0 )
    {
@@ -1520,11 +1489,9 @@ void pca_dec_s3_fx(
    num_fx = 12868;
    move16();

    d_fx = idiv1616( num_fx, sub( n1, 1 ) ); // Q12
    d_fx = idiv1616( num_fx, n1 );     // Q12
    ph1_q_fx = i_mult( index1, d_fx ); // Q12

    ph1_q_fx = shl( ph1_q_fx, 1 ); /* Q12 -> Q13 */

    n2 = calc_n2_fx( ph1_q_fx );

    j = L_sub( j, ivas_pca_offset_index1[index1] );
@@ -1554,7 +1521,6 @@ void pca_dec_s3_fx(
        move16();
        d_fx = idiv1616( num_fx, sub( n2, 1 ) ); // Q12
        ph2_q_fx = i_mult( index2, d_fx );       // Q12
        ph2_q_fx = shl( ph2_q_fx, 1 );           /* Q12 -> Q13 */
    }

    j = L_sub( j, ivas_pca_offset_index2[add( index2, get_pca_offset_n2_fx( index1 ) )] );
@@ -1570,13 +1536,11 @@ void pca_dec_s3_fx(
    }
    ELSE
    {
        Word16 exp;
        num_fx = 25736; /* PI2 in Q12 */
        num_fx = 6434;
        move16();
        d_fx = BASOP_Util_Divide1616_Scale( num_fx, n3, &exp ); /* Q12 */
        exp = add( 3 - 15, exp );
        d_fx = shl( d_fx, sub( exp, 3 ) ); /* Q12 */
        ph3_q_fx = i_mult( index3, d_fx ); /* Q12 */
        d_fx = idiv1616( num_fx, n3 );                 // Q10
        ph3_q_fx = round_fx( L_mult( index3, d_fx ) ); // Q10
        // ph3_q_fx = shl(ph3_q_fx, 2);
    }
    sp2cart_fx( ph1_q_fx, ph2_q_fx, ph3_q_fx, q_fx );