Commit 79f643ec authored by Sandesh Venkatesh's avatar Sandesh Venkatesh
Browse files

Converted ivas_calculate_smoothning_factor function

parent 03e7fd86
Loading
Loading
Loading
Loading
Loading
+74 −0
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@
#include "ivas_prot.h"
#include "wmc_auto.h"
#include "prot.h"
#include "prot_fx2.h"

/*-----------------------------------------------------------------------------------------*
 * Local constants
@@ -65,6 +66,52 @@ static float ivas_calculate_update_factor(
}


#ifdef IVAS_FLOAT_FIXED
/*-----------------------------------------------------------------------------------------*
 * Function ivas_calculate_smoothning_factor_fx()
 *
 * To calculate the Smoothning factor
 *-----------------------------------------------------------------------------------------*/

static void ivas_calculate_smoothning_factor_fx(
    Word32 *Smoothing_factor,
    Word32 update_factor,
    const Word16 min_pool_size,
    const Word32 max_update_rate,
    const COV_SMOOTHING_TYPE smooth_mode,
    const Word32 ivas_total_brate,
    Word16 j )
{
    Word32 smooth_fact, L_tmp = 0;
    Word16 tmp, exp_diff = 0;

    tmp = BASOP_Util_Divide3232_Scale( update_factor, L_shl( L_deposit_l( min_pool_size ), Q22 ), &exp_diff ); // (Q15 - exp_diff)
    *Smoothing_factor = L_shl_sat( L_deposit_l( tmp ), ( Q15 + exp_diff ) );                                   // Q30

    IF( NE_32( smooth_mode, COV_SMOOTH_MC ) )
    {
        IF( LT_32( ivas_total_brate, IVAS_24k4 ) )
        {
            smooth_fact = (Word32) ( 0.5f * ONE_IN_Q31 );
        }
        ELSE
        {
            smooth_fact = (Word32) ( 0.75f * ONE_IN_Q31 );
        }

        L_tmp = Mpy_32_16_1( smooth_fact, add( j, 1 ) );           // (Q31 , Q0) -> Q16
        *Smoothing_factor = Mpy_32_32( *Smoothing_factor, L_tmp ); // (Q30, Q16) -> Q15
        *Smoothing_factor = L_shl_sat( *Smoothing_factor, Q15 );   // Q30
    }

    IF( *Smoothing_factor > max_update_rate ) // Q30
    {
        *Smoothing_factor = max_update_rate;
    }

    return;
}
#else
/*-----------------------------------------------------------------------------------------*
 * Function ivas_calculate_smoothning_factor()
 *
@@ -102,6 +149,7 @@ static void ivas_calculate_smoothning_factor(

    return;
}
#endif


/*-----------------------------------------------------------------------------------------*
@@ -120,13 +168,23 @@ static void ivas_set_up_cov_smoothing(
{
    int16_t j;
    float update_factor;
#ifdef IVAS_FLOAT_FIXED
    Word32 update_factor_fx, max_update_rate_fx;
    max_update_rate_fx = (Word32) ( max_update_rate * ONE_IN_Q30 );
#endif
    if ( smooth_mode == COV_SMOOTH_MC )
    {
        for ( j = 0; j < pFb->filterbank_num_bands; j++ )
        {
            int16_t active_bins = pFb->fb_bin_to_band.pFb_active_bins_per_band[j];
            update_factor = ivas_calculate_update_factor( pFb->fb_bin_to_band.pFb_bin_to_band[j], active_bins );
#ifdef IVAS_FLOAT_FIXED
            update_factor_fx = (Word32) ( update_factor * ONE_IN_Q22 );
            ivas_calculate_smoothning_factor_fx( &hCovState->pSmoothing_factor_fx[j], update_factor_fx, min_pool_size, max_update_rate_fx, smooth_mode, ivas_total_brate, j );
            hCovState->pSmoothing_factor[j] = (float) hCovState->pSmoothing_factor_fx[j] / ONE_IN_Q30;
#else
            ivas_calculate_smoothning_factor( &hCovState->pSmoothing_factor[j], update_factor, min_pool_size, max_update_rate, smooth_mode, ivas_total_brate, j );
#endif
        }
    }
    else
@@ -136,7 +194,13 @@ static void ivas_set_up_cov_smoothing(
            float *p_bin_to_band = pFb->fb_bin_to_band.pp_short_stride_bin_to_band[j];
            int16_t active_bins = pFb->fb_bin_to_band.p_short_stride_num_bins_per_band[j];
            update_factor = ivas_calculate_update_factor( p_bin_to_band, active_bins );
#ifdef IVAS_FLOAT_FIXED
            update_factor_fx = (Word32) ( update_factor * ONE_IN_Q22 );
            ivas_calculate_smoothning_factor_fx( &hCovState->pSmoothing_factor_fx[j], update_factor_fx, min_pool_size, max_update_rate_fx, smooth_mode, ivas_total_brate, j );
            hCovState->pSmoothing_factor[j] = (float) hCovState->pSmoothing_factor_fx[j] / ONE_IN_Q30;
#else
            ivas_calculate_smoothning_factor( &hCovState->pSmoothing_factor[j], update_factor, min_pool_size, max_update_rate, smooth_mode, ivas_total_brate, j );
#endif
        }
    }

@@ -173,6 +237,12 @@ ivas_error ivas_spar_covar_smooth_enc_open(
    {
        return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR COV encoder" );
    }
#ifdef IVAS_FLOAT_FIXED
    IF( ( hCovState->pSmoothing_factor_fx = (Word32 *) malloc( sizeof( Word32 ) * cov_smooth_cfg->max_bands ) ) == NULL )
    {
        return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR COV encoder Fixed" );
    }
#endif

    for ( i = 0; i < nchan_inp; i++ )
    {
@@ -214,6 +284,10 @@ void ivas_spar_covar_smooth_enc_close(
    {
        free( hCovState->pSmoothing_factor );
        hCovState->pSmoothing_factor = NULL;
#ifdef IVAS_FLOAT_FIXED
        free( hCovState->pSmoothing_factor_fx );
        hCovState->pSmoothing_factor_fx = NULL;
#endif

        for ( i = 0; i < nchan_inp; i++ )
        {
+3 −0
Original line number Diff line number Diff line
@@ -359,6 +359,9 @@ typedef struct ivas_cov_smooth_state_t
    int16_t prior_bank_idx;
    float *pSmoothing_factor;
    int16_t num_bins;
#ifdef IVAS_FLOAT_FIXED
    Word32 *pSmoothing_factor_fx;
#endif

} ivas_cov_smooth_state_t;