Commit 95d4681f authored by thomas dettbarn's avatar thomas dettbarn Committed by Manuel Jander
Browse files

merge candiate.

parent 8d92d646
Loading
Loading
Loading
Loading
+184 −192
Original line number Diff line number Diff line
@@ -59,7 +59,9 @@ static Word16 sns_1st_cod_fx(
    Word32 *snsq_fx /* o  : quantized sns    Q16 */
)
{
    Word16 index, i;
    IF( exp_sns == Q15)
    {
        Word16 index;
        const Word16 split_len = M / 2;
        move16();
        const Word16 *means;
@@ -81,24 +83,10 @@ static Word16 sns_1st_cod_fx(
            default:
                assert( !"illegal frame length in sns_1st_cod" );
        }
    Word16 exp_snsq_buffer[M] = { 0 }, exp_snsq = 0;
    move16();
    move16();
    FOR( i = 0; i < M; ++i )
        FOR( Word16 i = 0; i < M; ++i )
        {
            Word32 tmp = L_mult( means[i], means_fix ); // Q16
        exp_snsq_buffer[i] = 0;
        move16();
        snsq_fx[i] = BASOP_Util_Add_Mant32Exp( sns_fx[i], exp_sns, L_negate( tmp ), 15, &exp_snsq_buffer[i] );
        move32();
    }
    FOR( i = 0; i < M; i++ )
    {
        exp_snsq = s_max( exp_snsq_buffer[i], exp_snsq );
    }
    FOR( i = 0; i < M; i++ )
    {
        snsq_fx[i] = L_shr( snsq_fx[i], exp_snsq - exp_snsq_buffer[i] );
            snsq_fx[i] = L_sub( sns_fx[i], tmp ); // Q16
            move32();
        }
    
@@ -107,7 +95,8 @@ static Word16 sns_1st_cod_fx(
        FOR( Word16 split = 0; split < 2; ++split )
        {
            const Word16 *cdbk_ptr;
        Word16 j0, j1, index_split;
            Word16 j0, j1;
            Word16 dist_split;
            Word32 dist_min_fx;
            const Word16 cdbk_fix = 8; // 1.f / powf( 2, SNS_CDBKS_BITS_4_FRAC ) in Q15
            move16();
@@ -118,71 +107,61 @@ static Word16 sns_1st_cod_fx(
    
            cdbk_ptr = cdbk;
            dist_min_fx = MAXVAL_WORD32;
        Word16 exp_dist_min = 31;
        index_split = 0;
        FOR( i = 0; i < 32; ++i )
            dist_split = 0;
            move32();
            move16();
            FOR( Word16 i = 0; i < 32; ++i )
            {
                Word32 dist_fx = 0;
                move32();
            Word16 exp_dist = 0;
            move16();
                FOR( Word16 j = j0; j < j1; ++j )
                {
                Word32 tmp_fx;
                Word16 exp_tmp = 0;
                move16();
                Word32 tmp_1 = L_mult( ( *cdbk_ptr++ ), cdbk_fix ); // Q16
                tmp_fx = BASOP_Util_Add_Mant32Exp( snsq_fx[j], exp_snsq, L_negate( tmp_1 ), 15, &exp_tmp );
                Word32 tmp_2 = Mpy_32_32( tmp_fx, tmp_fx );                                             // exp_tmp*2
                dist_fx = BASOP_Util_Add_Mant32Exp( dist_fx, exp_dist, tmp_2, exp_tmp * 2, &exp_dist ); // exp_tmp*2
                    Word32 tmp;
                    Word32 dist;
                    Word16 tmp2;
    
                    tmp = L_mult( *cdbk_ptr++, cdbk_fix ); // Q16
                    dist = L_sub( snsq_fx[j],  tmp );
                    dist = L_shr( dist, 4 ); // make sure that the next multiplication does not overflow
    
                    tmp2 = extract_l( dist );
                    dist = L_mult( tmp2, tmp2 );
                    dist = L_shr( dist, 4 ); // make sure that the sum does not overflow
                    dist_fx = L_add( dist_fx, dist );
                }
    
            IF( EQ_16( BASOP_Util_Cmp_Mant32Exp( dist_fx, exp_dist, dist_min_fx, exp_dist_min ), -1 ) )
                IF( LT_32( dist_fx, dist_min_fx ) )
                {
                    dist_min_fx = dist_fx;
                move32();
                exp_dist_min = exp_dist;
                move16();
                index_split = i;
                move16();
                    dist_split = i;
                }
            }
    
            /* set quantized vector */
        cdbk_ptr = &cdbk[imult1616( index_split, split_len )];
            cdbk_ptr = &cdbk[imult1616( dist_split, split_len )];
            FOR( Word16 j = j0; j < j1; ++j )
            {
                Word32 tmp_3 = L_mult( means[j], means_fix );    // Q16
            Word32 tmp_4 = L_mult( ( *cdbk_ptr++ ), cdbk_fix ); // Q16
                Word32 tmp_4 = L_mult( *cdbk_ptr++, cdbk_fix ); // Q16
                snsq_fx[j] = L_add( tmp_4, tmp_3 );                 // Q16
                move32();
            }
    
            /* for second split shift by five bits to store both indices as one 10 bit value */
        IF( EQ_16( split, 1 ) )
            if ( EQ_16( split, 1 ) )
            {
            index_split = shl( index_split, 5 );
                dist_split = shl( dist_split, 5 );
            }
    
        index = add( index, index_split );
            index = add( index, dist_split );
        }

        return index;
}

static Word16 sns_1st_cod_fx_q15(
    const Word32 *sns_fx, /* i  : vector to quantize                */
    const Word16 L_frame,
    const Word16 core,
    Word32 *snsq_fx /* o  : quantized sns    Q16 */
)
{
    Word16 index;
    } ELSE {
        Word16 index, i;
        const Word16 split_len = M / 2;
        move16();
        const Word16 *means;
        const Word16 means_fix = 2; // Q15
    push_wmops( "sns_1st_cod_fx_q15" );
        move16();
        /* remove means */
        means = NULL;
@@ -200,10 +179,24 @@ static Word16 sns_1st_cod_fx_q15(
            default:
                assert( !"illegal frame length in sns_1st_cod" );
        }
    FOR( Word16 i = 0; i < M; ++i )
        Word16 exp_snsq_buffer[M] = { 0 }, exp_snsq = 0;
        move16();
        move16();
        FOR( i = 0; i < M; ++i )
        {
            Word32 tmp = L_mult( means[i], means_fix ); // Q16
        snsq_fx[i] = L_sub( sns_fx[i], tmp ); // Q16
            exp_snsq_buffer[i] = 0;
            move16();
            snsq_fx[i] = BASOP_Util_Add_Mant32Exp( sns_fx[i], exp_sns, L_negate( tmp ), 15, &exp_snsq_buffer[i] );
            move32();
        }
        FOR( i = 0; i < M; i++ )
        {
            exp_snsq = s_max( exp_snsq_buffer[i], exp_snsq );
        }
        FOR( i = 0; i < M; i++ )
        {
            snsq_fx[i] = L_shr( snsq_fx[i], exp_snsq - exp_snsq_buffer[i] );
            move32();
        }
    
@@ -212,8 +205,7 @@ static Word16 sns_1st_cod_fx_q15(
        FOR( Word16 split = 0; split < 2; ++split )
        {
            const Word16 *cdbk_ptr;
        Word16 j0, j1;
        Word16 dist_split;
            Word16 j0, j1, index_split;
            Word32 dist_min_fx;
            const Word16 cdbk_fix = 8; // 1.f / powf( 2, SNS_CDBKS_BITS_4_FRAC ) in Q15
            move16();
@@ -224,57 +216,58 @@ static Word16 sns_1st_cod_fx_q15(
    
            cdbk_ptr = cdbk;
            dist_min_fx = MAXVAL_WORD32;
        dist_split = 0;
        move32();
        move16();
        FOR( Word16 i = 0; i < 32; ++i )
            Word16 exp_dist_min = 31;
            index_split = 0;
            FOR( i = 0; i < 32; ++i )
            {
                Word32 dist_fx = 0;
                move32();
                Word16 exp_dist = 0;
                move16();
                FOR( Word16 j = j0; j < j1; ++j )
                {
                Word32 tmp;
                Word32 dist;
                Word16 tmp2;

                tmp = L_mult( *cdbk_ptr++, cdbk_fix ); // Q16
                dist = L_sub( snsq_fx[j],  tmp );
                dist = L_shr( dist, 4 ); // make sure that the next multiplication does not overflow

                tmp2 = extract_l( dist );
                dist = L_mult( tmp2, tmp2 );
                dist = L_shr( dist, 4 ); // make sure that the sum does not overflow
                dist_fx = L_add( dist_fx, dist );
                    Word32 tmp_fx;
                    Word16 exp_tmp = 0;
                    move16();
                    Word32 tmp_1 = L_mult( ( *cdbk_ptr++ ), cdbk_fix ); // Q16
                    tmp_fx = BASOP_Util_Add_Mant32Exp( snsq_fx[j], exp_snsq, L_negate( tmp_1 ), 15, &exp_tmp );
                    Word32 tmp_2 = Mpy_32_32( tmp_fx, tmp_fx );                                             // exp_tmp*2
                    dist_fx = BASOP_Util_Add_Mant32Exp( dist_fx, exp_dist, tmp_2, exp_tmp * 2, &exp_dist ); // exp_tmp*2
                }
    
            IF( LT_32( dist_fx, dist_min_fx ) )
                IF( EQ_16( BASOP_Util_Cmp_Mant32Exp( dist_fx, exp_dist, dist_min_fx, exp_dist_min ), -1 ) )
                {
                    dist_min_fx = dist_fx;
                dist_split = i;
                    move32();
                    exp_dist_min = exp_dist;
                    move16();
                    index_split = i;
                    move16();
                }
            }
    
            /* set quantized vector */
        cdbk_ptr = &cdbk[imult1616( dist_split, split_len )];
            cdbk_ptr = &cdbk[imult1616( index_split, split_len )];
            FOR( Word16 j = j0; j < j1; ++j )
            {
                Word32 tmp_3 = L_mult( means[j], means_fix );       // Q16
            Word32 tmp_4 = L_mult( *cdbk_ptr++, cdbk_fix ); // Q16
                Word32 tmp_4 = L_mult( ( *cdbk_ptr++ ), cdbk_fix ); // Q16
                snsq_fx[j] = L_add( tmp_4, tmp_3 );                 // Q16
                move32();
            }
    
            /* for second split shift by five bits to store both indices as one 10 bit value */
        if ( EQ_16( split, 1 ) )
            IF( EQ_16( split, 1 ) )
            {
            dist_split = shl( dist_split, 5 );
                index_split = shl( index_split, 5 );
            }
    
        index = add( index, dist_split );
            index = add( index, index_split );
        }
    pop_wmops();
    
        return index;
    }
}

/*-------------------------------------------------------------------
 * sns_2st_cod()
@@ -381,7 +374,7 @@ void sns_avq_cod_fx(
    Word16 indxt[256], nbits, nbt, nit;
    Word32 snsmid_q0_fx[M];

    index[0] = sns_1st_cod_fx_q15( sns_fx, L_frame, core, sns_q_fx );
    index[0] = sns_1st_cod_fx( sns_fx, exp_sns, L_frame, core, sns_q_fx );
    move16();
    nit = 1 + 2;
    move16();
@@ -408,8 +401,7 @@ void sns_avq_cod_fx(
    {
        index++;

        index[0] = sns_1st_cod_fx_q15( snsmid_fx, L_frame, core, snsmid_q_fx );
        //        index[0] = sns_1st_cod_fx( snsmid_fx, exp_snsmid, L_frame, core, snsmid_q_fx );
        index[0] = sns_1st_cod_fx( snsmid_fx, exp_snsmid, L_frame, core, snsmid_q_fx );
        move16();
        nit = 1 + 2;
        move16();