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

Merge branch 'ivas_masa_dec_fxd_2' into 'main'

Few functions in ivas_masa_dec converted to fixed point.

See merge request !95
parents 7ddadf2c dc014799
Loading
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -349,6 +349,8 @@ typedef enum
#define PARAM_ISM_MAX_CHAN                      16
#define PARAM_ISM_HYS_BUF_SIZE                  10

#define STEP_PARAM_ISM_POW_RATIO_NBITS_Q15      (4681)  /* 1.0f / (float)((1 << PARAM_ISM_POW_RATIO_NBITS) - 1) */

/* ISM DTX */
#define ISM_DTX_COH_SCA_BITS                    4
#define ISM_DTX_AZI_BITS_HIGH                   8
@@ -1154,6 +1156,7 @@ enum
#define NO_BITS_MASA_ISM_NO_OBJ                 2
#ifdef IVAS_FLOAT_FIXED
#define MASA2TOTAL_THR                          0.979965f // Temporary
#define MASA2TOTAL_THR_Q30                      1052229376l // 0.979965f in Q30
//Maximum error in float to fixed conversion : 0.005%
//Assuming the accuracy of 99.995%
//New value = 99.995 / 100 * 0.98 = 0.979951
+144 −0
Original line number Diff line number Diff line
@@ -1423,6 +1423,56 @@ int16_t valid_ratio_index(
    return out;
}

#ifdef IVAS_FLOAT_FIXED
Word16 valid_ratio_index_fx(
    Word16 index,    /* i  : index to be checked        */
    const Word16 K,  /* i  : L1 norm to check against   */
    const Word16 len /* i  : vector length              */
)
{
    Word16 out;
    Word16 i, sum, elem;
    Word16 base[4];

    sum = 0;
    move16();
    set16_fx( base, 1, len );

    FOR ( i = 1; i < len; i++ )
    {
        base[i] = i_mult(base[i - 1], 10);
    }
    sum = 0;
    move16();
    FOR ( i = len - 1; i >= 0; i-- )
    {
        IF(EQ_16(index, 0))
        {
            elem = 0;
            move16();
        }
        ELSE
        {
            elem = idiv1616(index, base[i]);
        }
        sum = add(sum, elem);
        index = sub(index, i_mult(elem, base[i]));
    }
    IF ( LE_16(sum, K ) )
    {
        out = 1;
        move16();
    }
    ELSE
    {
        out = 0;
        move16();
    }

    return out;
}
#endif


/*---------------------------------------------------------------
 * reconstruct_ism_ratios()
@@ -1458,6 +1508,46 @@ void reconstruct_ism_ratios(
}


/*---------------------------------------------------------------
 * reconstruct_ism_ratios_fx()
 *
 * Obtains ISM ratio values from the quantized indexes
 *---------------------------------------------------------------*/

void reconstruct_ism_ratios_fx(
    Word16 *ratio_ism_idx,     /* i  : index vector                 Q0  */
    const Word16 nchan_ism,    /* i  : number of components/objects Q0  */
    const Word16 step,         /* i  : quantization step            Q15 */
    Word32 *q_energy_ratio_ism /* o  : reconstructed ISM values     Q30 */
)
{
    int16_t i;
    Word32 sum;

    sum = 0;
    move32();

    FOR ( i = 0; i < nchan_ism - 1; i++ )
    {
        q_energy_ratio_ism[i] = L_shl(L_mult(ratio_ism_idx[i], step), 14);   // q0 + q15 + 1 + 14 = q30;
        move32();

        sum = L_add(sum, q_energy_ratio_ism[i]);
    }

    q_energy_ratio_ism[nchan_ism - 1] = L_sub(ONE_IN_Q30, sum);
    move32();
    
    IF ( LT_32(q_energy_ratio_ism[nchan_ism - 1], 0) )
    {
        q_energy_ratio_ism[nchan_ism - 1] = 0;
        move32();
    }

    return;
}


/*---------------------------------------------------------------
 * ivas_omasa_modify_masa_energy_ratios()
 *
@@ -1534,6 +1624,60 @@ void distribute_evenly_ism(
    return;
}

#ifdef IVAS_FLOAT_FIXED
/*---------------------------------------------------------------
 * distribute_evenly_ism_fx()
 *
 * Obtain ISM ratio indexes for even content distribution bbetween objects
 *---------------------------------------------------------------*/

void distribute_evenly_ism_fx(
    Word16 *idx,           /* o  : index values        */
    const Word16 K,        /* i  : sum of indexes      */
    const Word16 nchan_ism /* i  : number of objects   */
)
{
    Word16 i;
    Word16 sum;

    sum = 0;
    move16();
    FOR( i = 0; i < nchan_ism; i++ )
    {
        IF(EQ_16(K, 0))
        {
            idx[i] = 0;
            move16();
        }
        ELSE
        {
            idx[i] = idiv1616( K, nchan_ism );
            move16();
        }
        sum = add( sum, idx[i] );
    }

    assert( LE_16( sum, K ) );

    i = 0;
    move16();
    WHILE( LT_16( sum, K ) )
    {
        IF( EQ_16( i, nchan_ism ) )
        {
            i = 0;
            move16();
        }
        idx[i] = add( idx[i], 1 );
        move16();
        sum = add( sum, 1 );
        i = add( i, 1 );
    }

    return;
}
#endif


/*---------------------------------------------------------------
 * calculate_cpe_brate_MASA_ISM()
+2 −2
Original line number Diff line number Diff line
@@ -903,8 +903,8 @@ static Word16 get_bits_ism( Word32 val )

void calculate_nbits_meta_fx(
    const Word16 nchan_ism,
    Word32 q_energy_ratio_ism[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], // Qx
    Word32 masa_to_total_energy_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS],          // Qx
    const Word32 q_energy_ratio_ism[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], // Q30
    const Word32 masa_to_total_energy_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS],          // Q30
    const Word16 numSf,
    const Word16 numCodingBands,
    Word16 *bits_ism,
+1 −2
Original line number Diff line number Diff line
@@ -6037,8 +6037,7 @@ void ivas_omasa_decode_masa_to_total_fx(
	Word16 *index,
	Word32 masa_to_total_energy_ratio_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS],
	const Word16 nbands,
	const Word16 nblocks,
	Word16 *q);
	const Word16 nblocks);
#endif

void ivas_omasa_modify_masa_energy_ratios(
+19 −0
Original line number Diff line number Diff line
@@ -101,6 +101,25 @@ ivas_error ivas_masa_dec_reconfigure_fx(
    Word16 *data               /* o  : output synthesis signal                 */
);

void reconstruct_ism_ratios_fx(
    Word16 *ratio_ism_idx,     /* i  : index vector                 Q0  */
    const Word16 nchan_ism,    /* i  : number of components/objects Q0  */
    const Word16 step,         /* i  : quantization step            Q15 */
    Word32 *q_energy_ratio_ism /* o  : reconstructed ISM values     Q30 */
);

void distribute_evenly_ism_fx(
    Word16 *idx,           /* o  : index values        */
    const Word16 K,        /* i  : sum of indexes      */
    const Word16 nchan_ism /* i  : number of objects   */
);

Word16 valid_ratio_index_fx(
    Word16 index,    /* i  : index to be checked        */
    const Word16 K,  /* i  : L1 norm to check against   */
    const Word16 len /* i  : vector length              */
);

Word16 ivas_jbm_dec_get_num_tc_channels_fx(
    Decoder_Struct *st_ivas                                     /* i  : IVAS decoder handle                                         */
);
Loading