Commit 0d065b7f authored by Sandesh Venkatesh's avatar Sandesh Venkatesh
Browse files

lpd functions converted to fixed

[x] Contains float to fix and vice versa conversions for subfunctions of mode_switch_decoder_LPD
[x] Contains float_to_fx and vice versa conversions for subfunctions of open_decoder_LPD
[x] Contains cosmetic changes(comparsion, basop , type etc.) for dec_prm_tcx and stereo_tcx_dec_mode_switch_reconf
[x] Added fixed table for igf_whitening_TH_flt
parent 18156ef7
Loading
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -55,7 +55,7 @@ void BITS_ALLOC_init_config_acelp(
    move16();
    move16();
    move16();
    rate_mode_index=(bit_rate > ACELP_9k60);
    rate_mode_index = (Word8)GT_32( bit_rate, ACELP_9k60 );

    pConfigAcelp->mode_index=rate_mode_index;

@@ -66,7 +66,7 @@ void BITS_ALLOC_init_config_acelp(

    /*ACELP ICB config*/
    test();
    IF( (rate_mode_index==0) || narrowBand != 0 )
    IF( EQ_16( rate_mode_index, 0 ) || NE_16( narrowBand, 0 ) )
    {
        move16();
        move16();
+4 −4
Original line number Diff line number Diff line
@@ -389,13 +389,13 @@ UWord16 get_next_indice_fx( /* o : value of the indice */
{
	UWord16 value;
	Word16 i;
	Word32 nbits_total;
	Word16 nbits_total;

	assert(nb_bits <= 16);
	value = 0;
	move16();

	nbits_total = st_fx->total_brate / FRAMES_PER_SEC;
	nbits_total = (Word16)(st_fx->total_brate / FRAMES_PER_SEC);
	/* detect corrupted bitstream */
	IF(GT_16(add(st_fx->next_bit_pos, nb_bits), nbits_total))
	{
@@ -425,8 +425,8 @@ UWord16 get_next_indice_1_fx( /* o : value of the indice */
	Decoder_State *st_fx               /* i/o: decoder state structure */
)
{
	Word32 nbits_total;
	nbits_total = st_fx->total_brate / FRAMES_PER_SEC;
	Word16 nbits_total;
	nbits_total = (Word16)(st_fx->total_brate / FRAMES_PER_SEC);
	/* detect corrupted bitstream */
	test();
	test();
+19 −16
Original line number Diff line number Diff line
@@ -1412,6 +1412,7 @@ ivas_error openCldfb_ivas(
    {
        return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for CLDFB" );
    }
	hs->cldfb_state_length = buf_len;//Temporarily added to store the length of buffer
    set32_fx(hs->cldfb_state_fx, 0, buf_len);
#endif // IVAS_FLOAT_FIXED

@@ -2080,22 +2081,24 @@ void cldfb_reset_memory_ivas(
}
#ifdef IVAS_FLOAT_FIXED
void cldfb_reset_memory_fx(
    HANDLE_CLDFB_FILTER_BANK hs /* i/o: filter bank handle */,
    Word16 *memory_length )
	HANDLE_CLDFB_FILTER_BANK hs /* i/o: filter bank handle */
)
{
	Word16 memory_length;
	UWord16 offset = sub(hs->p_filter_length, hs->no_channels);

	IF (hs->type == CLDFB_ANALYSIS)
	{
        *memory_length = offset;
		memory_length = offset;
	}
	ELSE
	{
        *memory_length = hs->p_filter_length;
		memory_length = hs->p_filter_length;
	}

	hs->cldfb_state_length = memory_length;
		/* save the memory */
    set32_fx( hs->cldfb_state_fx, 0, *memory_length );
	set32_fx(hs->cldfb_state_fx, 0, memory_length);

    return;
}
+18 −8
Original line number Diff line number Diff line
@@ -5,18 +5,22 @@
#include "prot.h"
Word32 floatToFixed(const float f, Word16 Q)
{
	if (f == 1.0f && Q == Q15)
		return MAX16B;
	if (f == 1.0f && Q == Q31)
		return MAXVAL_WORD32;
	if (Q < 0)
		return (Word32)((float)(f) / (float)(1 << (-Q)) + (f >= 0 ? 0.5 : -0.5));
		return (Word32)((float)(f) / (float)(((unsigned)1) << (-Q)) + (f >= 0 ? 0.5 : -0.5));
	else
		return (Word32)(f * (float)(1 << Q) + (f >= 0 ? 0.5 : -0.5));
		return (Word32)(f * (float)(((unsigned)1) << Q) + (f >= 0 ? 0.5 : -0.5));
}

float fixedToFloat(const Word32 i, Word16 Q)
{
	if (Q < 0)
		return (i * (float)(1 << (-Q)));
		return (i * (float)(((unsigned)1) << (-Q)));
	else
		return (float)(i) / (float)(1 << Q);
		return (float)(i) / (float)(((unsigned)1) << Q);
}
void floatToFixed_arrL(const float *f, Word32 *i, Word16 Q, Word16 l)
{
@@ -46,13 +50,19 @@ void fixedToFloat_arr(const Word16 *i, float *f, Word16 Q, Word16 l)
		f[j] = fixedToFloat(i[j], Q);
	}
}
Word16 Q_factor(Word16 x)
Word16 Q_factor(float x)
{
	return norm_s(x);
    Word16 Q = 15;
    if ( x >= 1 || x <= -1 )
        Q = norm_s((Word16)x);
    return Q;
}
Word16 Q_factor_L(Word32 x)
Word16 Q_factor_L(float x)
{
	return norm_l(x);
    Word16 Q = 31;
    if ( x >= 1 || x <= -1 )
        Q = norm_l((Word32)x);
    return Q;
}
Word16 Q_factor_arr(float *x, Word16 l)
{
+261 −0
Original line number Diff line number Diff line
@@ -848,6 +848,186 @@ static void IGF_gridSetUp(H_IGF_GRID hGrid,
    }

}
#ifdef IVAS_FLOAT_FIXED
static void IGF_gridSetUp_ivas_fx(
    H_IGF_GRID hGrid,        /* o  : IGF grid handle                                                    */
    Word16 bitRateIndex,     /* i  : IGF bitrate index                                                  */
    const Word32 sampleRate, /* i  : sample rate                                                        */
    Word16 frameLength,      /* i  : frame length                                                       */
    const Word16 transFac,   /* i  : transFac                                                           */
    const Word16 igfMinFq    /* i  : IGF minimum frequency indicating lower start frequency for copy up */
)
{
    Word16 t, k;
    Word16 sfb;
    Word16 swb_offset_len;
    const Word16 *swb_offset;
    Word16 bandwidth_fx;
    const Word16 *igf_tile_offset;
    Word16 tmp2, tmp1;
    Word32 L_tmp1, L_tmp2;

    /* inits */
    swb_offset = NULL;
    swb_offset_len = 0;
    IF( EQ_16( transFac, 8192 ) && EQ_16( bitRateIndex, IGF_BITRATE_SWB_48000_CPE ) )
    {
        bitRateIndex = IGF_BITRATE_SWB_48000_CPE_TCX10;
    }
    ELSE IF( EQ_16( transFac, 8192 ) && EQ_16( bitRateIndex, IGF_BITRATE_FB_48000_CPE ) )
    {
        bitRateIndex = IGF_BITRATE_FB_48000_CPE_TCX10;
    }

    IF( NE_16( bitRateIndex, IGF_BITRATE_UNKNOWN ) )
    {
        swb_offset = &swb_offset_LB_new[bitRateIndex][1];
        swb_offset_len = swb_offset_LB_new[bitRateIndex][0];
        Copy( &igf_whitening_TH_ivas_fx[bitRateIndex][0][0], &hGrid->whiteningThreshold[0][0], IGF_MAX_TILES * 2 );
    }
    ELSE
    {
        assert( 0 );
    }

    FOR( sfb = 0; sfb < swb_offset_len; sfb++ )
    {
        hGrid->swb_offset[sfb] = IGF_ApplyTransFac( swb_offset[sfb], transFac );
    }
    FOR( sfb = swb_offset_len; sfb < IGF_MAX_SFB; sfb++ )
    {
        hGrid->swb_offset[sfb] = 0;
    }

    hGrid->infoIsRefined = 0;
    frameLength = IGF_ApplyTransFac( frameLength, transFac );
    tmp2 = norm_s( frameLength );
    bandwidth_fx = shl( frameLength, tmp2 );
    hGrid->swb_offset_len = extract_l( L_shr( sampleRate, 2 ) );
    tmp1 = sub( norm_s( hGrid->swb_offset_len ), 1 );
    hGrid->swb_offset_len = shl( hGrid->swb_offset_len, tmp1 );
    bandwidth_fx = div_s( hGrid->swb_offset_len, bandwidth_fx );
    tmp2 = sub( add( tmp2, 1 ), tmp1 );
    bandwidth_fx = shr( bandwidth_fx, sub( 15, tmp2 ) );
    hGrid->swb_offset_len = swb_offset_len;
    hGrid->startSfb = 0;
    hGrid->stopSfb = sub( hGrid->swb_offset_len, 1 );
    hGrid->startLine = hGrid->swb_offset[hGrid->startSfb];
    hGrid->stopLine = hGrid->swb_offset[hGrid->stopSfb];
    hGrid->startFrequency = imult1616( bandwidth_fx, hGrid->startLine );
    hGrid->stopFrequency = imult1616( bandwidth_fx, hGrid->stopLine );
    L_tmp1 = L_mult0( igfMinFq, frameLength );
    tmp1 = sub( norm_l( L_tmp1 ), 1 );
    L_tmp1 = L_shl( L_tmp1, tmp1 );
    tmp2 = norm_l( sampleRate );
    L_tmp2 = L_shl( sampleRate, tmp2 );
    tmp1 = add( WORD16_BITS - 1, sub( tmp1, add( tmp2, 1 ) ) ); /* takes into account sampleRate >> 1 */
    hGrid->minSrcSubband = div_s( extract_h( L_tmp1 ), extract_h( L_tmp2 ) );
    hGrid->minSrcSubband = shr( hGrid->minSrcSubband, tmp1 );
    hGrid->minSrcSubband = add( hGrid->minSrcSubband, s_and( hGrid->minSrcSubband, 1 ) );
    hGrid->minSrcFrequency = imult1616( bandwidth_fx, hGrid->minSrcSubband );
    hGrid->infoGranuleLen = frameLength;
    hGrid->sfbWrap[0] = 0;
    hGrid->tile[0] = hGrid->startLine;

    igf_tile_offset = &igf_tile_offset_table[bitRateIndex][1];
    hGrid->nTiles = igf_tile_offset_table[bitRateIndex][0];
    hGrid->tile[0] = hGrid->startLine;
    hGrid->sfbWrap[0] = 0;
    FOR( k = 0; k < hGrid->nTiles; k++ )
    {
        hGrid->sfbWrap[k + 1] = igf_tile_offset[2 * k];
        hGrid->sbWrap[k] = add( hGrid->minSrcSubband, IGF_ApplyTransFac( igf_tile_offset[2 * k + 1], transFac ) );
        hGrid->tile[k + 1] = hGrid->swb_offset[igf_tile_offset[2 * k]];
    }
    FOR( t = hGrid->nTiles + 1; t < IGF_MAX_TILES; t++ )
    {
        hGrid->tile[t] = 0;
        hGrid->sbWrap[t - 1] = 0;
        hGrid->sfbWrap[t] = 0;
    }

    /* adapt level envelope: */
    SWITCH( bitRateIndex )
    {
        case IGF_BITRATE_RF_WB_13200:
        case IGF_BITRATE_WB_9600:
        case IGF_BITRATE_WB_13200_CPE:
        case IGF_BITRATE_WB_16400_CPE:
            hGrid->gFactor = 13107 /*0.80f Q14*/;
            move16();
            hGrid->fFactor = 11469 /*0.70f Q14*/;
            move16();
            hGrid->lFactor = 9830 /*0.60f Q14*/;
            move16();
            BREAK;
        case IGF_BITRATE_SWB_13200:
        case IGF_BITRATE_SWB_16400_CPE:
        case IGF_BITRATE_FB_16400:
        case IGF_BITRATE_SWB_16400:
        case IGF_BITRATE_FB_24400_CPE:
        case IGF_BITRATE_SWB_24400_CPE:
            hGrid->gFactor = 15237 /*0.93f Q14*/;
            move16();
            hGrid->fFactor = 3277 /*0.20f Q14*/;
            move16();
            hGrid->lFactor = 13926 /*0.85f Q14*/;
            move16();
            BREAK;
        case IGF_BITRATE_FB_24400:
        case IGF_BITRATE_SWB_24400:
        case IGF_BITRATE_FB_32000_CPE:
        case IGF_BITRATE_SWB_32000_CPE:
        case IGF_BITRATE_FB_32000:
        case IGF_BITRATE_SWB_32000:
        case IGF_BITRATE_SWB_48000_CPE:
        case IGF_BITRATE_SWB_64000_CPE:
            hGrid->gFactor = 15811 /*0.965f Q14*/;
            move16();
            hGrid->fFactor = 3277 /*0.20f Q14*/;
            move16();
            hGrid->lFactor = 13926 /*0.85f Q14*/;
            move16();
            BREAK;
        case IGF_BITRATE_FB_48000:
        case IGF_BITRATE_SWB_48000:
        case IGF_BITRATE_FB_64000:
        case IGF_BITRATE_SWB_64000:
        case IGF_BITRATE_SWB_80000_CPE:
        case IGF_BITRATE_SWB_96000_CPE:
            hGrid->gFactor = 16384 /*1.00f Q14*/;
            move16();
            hGrid->fFactor = 3277 /*0.20f Q14*/;
            move16();
            hGrid->lFactor = 16384 /*1.00f Q14*/;
            move16();
            BREAK;
        case IGF_BITRATE_SWB_9600:
        case IGF_BITRATE_SWB_13200_CPE:
        case IGF_BITRATE_RF_SWB_13200:
        default:
            hGrid->gFactor = 16384 /*1.00f Q14*/;
            move16();
            hGrid->fFactor = 0; /*0.00f Q30*/
            ;
            move16();
            hGrid->lFactor = 16384 /*1.00f Q14*/;
            move16();
    }

    FOR ( t = add(hGrid->nTiles , 1); t < IGF_MAX_TILES; t++ )
    {
        hGrid->tile[t] = 0;
        move16();
        hGrid->sbWrap[t - 1] = 0;
        move16();
        hGrid->sfbWrap[t] = 0;
        move16();
    }
    return;
}

#endif // IVAS_FLOAT_FIXED

/**********************************************************************/ /*
calculates energy per sfb via power spectrum
@@ -1045,6 +1225,87 @@ Word16 IGFCommonFuncsIGFConfiguration(

    return retValue;
}
#ifdef IVAS_FLOAT_FIXED
Word16 IGFCommonFuncsIGFConfiguration_ivas_fx(
    const Word32 total_brate,  /* i  : bitrate in bs e.g. 9600 for 9.6kbs  */
    const Word16 bwidth,       /* i  : audio bandwidth                     */
    const Word16 element_mode, /* i  : element mode                        */
    H_IGF_INFO hIGFInfo,       /* o  : IGF info handle                     */
    const Word16 rf_mode       /* i  : flag to signal the RF mode          */
)
{
    H_IGF_GRID hGrid;
    Word16 retValue;
    Word32 sampleRate;
    Word16 frameLength;
    Word16 igfMinFq;
    Word16 maxHopsize;

    retValue = 0; /* bitrate index is unknown -> error! */
    move16();

    /* interface call for reading in settings */
    hIGFInfo->bitRateIndex = IGF_MapBitRateToIndex( total_brate, bwidth, element_mode, rf_mode );

    IF( NE_16( hIGFInfo->bitRateIndex, IGF_BITRATE_UNKNOWN ) )
    {
        retValue = 1; /* no error */
        move16();

        /* mapping to local values */
        sampleRate = igfMode[hIGFInfo->bitRateIndex].sampleRate;
        move32();
        frameLength = igfMode[hIGFInfo->bitRateIndex].frameLength;
        move16();
        igfMinFq = igfMode[hIGFInfo->bitRateIndex].igfMinFq;
        move16();
        maxHopsize = igfMode[hIGFInfo->bitRateIndex].maxHopsize;
        move16();

        /* basic information */
        hIGFInfo->sampleRate = sampleRate;
        move32();
        hIGFInfo->frameLength = frameLength;
        move16();
        hIGFInfo->maxHopsize = maxHopsize;
        move16();
#if 0 
		//100820 temp fix
#endif
        hIGFInfo->nfSeedBuf[0] = 0;
        hIGFInfo->nfSeedBuf[1] = 0;
        hIGFInfo->nfSeed = &hIGFInfo->nfSeedBuf[0];
        move16();

        /* set up regular IGF grid for TCX 20  (transfac = 1.f) */
        hGrid = &hIGFInfo->grid[IGF_GRID_LB_NORM];
        IGF_gridSetUp_ivas_fx( hGrid,
                               hIGFInfo->bitRateIndex,
                               sampleRate,
                               frameLength,
                               16384 /*1 Q14*/,
                               igfMinFq );
        /* set up IGF grid for CELP->TCX 20 transitions (transfac = 1.25) */
        hGrid = &hIGFInfo->grid[IGF_GRID_LB_TRAN];
        IGF_gridSetUp_ivas_fx( hGrid,
                               hIGFInfo->bitRateIndex,
                               sampleRate,
                               frameLength,
                               20480 /*1.25 Q14*/,
                               igfMinFq );
        /* set up IGF grid for TCX 10 (transfac = 0.5) */
        hGrid = &hIGFInfo->grid[IGF_GRID_LB_SHORT];
        IGF_gridSetUp_ivas_fx( hGrid,
                               hIGFInfo->bitRateIndex,
                               sampleRate,
                               frameLength,
                               8192 /*0.50f Q14*/,
                               igfMinFq );
    }

    return retValue;
}
#endif // IVAS_FLOAT_FIXED

/**********************************************************************/ /*
selects cumulative frequency tables and offsets for the IGF SCF arithmetic coder
Loading