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

Integration of fixed point sub-functions 8

[x] decoder_tcx_fx - clean up of intermediate float to
fixed and fixed to float conversions.
[x] fb_tbe_dec integration.
[x] Converted 5 functions in ivas_cov_smooth.c file.
[x] Added fixes for issues 711,714 and 715.
parent 3ca319e1
Loading
Loading
Loading
Loading
Loading
+332 −193

File changed.

Preview size limit exceeded, changes collapsed.

+183 −13
Original line number Diff line number Diff line
@@ -60,7 +60,7 @@ static Word32 ivas_calculate_update_factor_fx(

    FOR( k = 0; k < active_bins; k++ )
    {
        update_factor_temp += p_bin_to_band[k]; // Q22
        update_factor_temp = L_add( update_factor_temp, p_bin_to_band[k] ); // Q22
    }

    return update_factor_temp;
@@ -109,27 +109,33 @@ static void ivas_calculate_smoothning_factor_fx(
    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 ), add( Q13, exp_diff ) );                                 // Q28
    *Smoothing_factor = L_shl_sat( L_deposit_l( tmp ), add( Q16, exp_diff ) );                                 // Q31
    move32();

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

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

    IF( *Smoothing_factor > max_update_rate ) // Q28
    IF( GT_32( *Smoothing_factor, max_update_rate ) ) // Q31
    {
        *Smoothing_factor = max_update_rate;
        move32();
    }

    return;
@@ -200,7 +206,6 @@ static void ivas_set_up_cov_smoothing_fx(
            Word16 active_bins = pFb->fb_bin_to_band.pFb_active_bins_per_band[j];
            update_factor = ivas_calculate_update_factor_fx( pFb->fb_bin_to_band.pFb_bin_to_band_fx[j], active_bins );
            ivas_calculate_smoothning_factor_fx( &hCovState->pSmoothing_factor_fx[j], update_factor, min_pool_size, max_update_rate, smooth_mode, ivas_total_brate, j );
            hCovState->pSmoothing_factor[j] = (float) hCovState->pSmoothing_factor_fx[j] / ONE_IN_Q28;
        }
    }
    ELSE
@@ -211,11 +216,11 @@ static void ivas_set_up_cov_smoothing_fx(
            Word16 active_bins = pFb->fb_bin_to_band.p_short_stride_num_bins_per_band[j];
            update_factor = ivas_calculate_update_factor_fx( p_bin_to_band, active_bins );
            ivas_calculate_smoothning_factor_fx( &hCovState->pSmoothing_factor_fx[j], update_factor, min_pool_size, max_update_rate, smooth_mode, ivas_total_brate, j );
            hCovState->pSmoothing_factor[j] = (float) hCovState->pSmoothing_factor_fx[j] / ONE_IN_Q28;
        }
    }

    hCovState->prior_bank_idx = -1;
    move16();

    return;
}
@@ -286,14 +291,15 @@ ivas_error ivas_spar_covar_smooth_enc_open(
        return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR COV encoder" );
    }

    if ( ( hCovState->pSmoothing_factor = (float *) malloc( sizeof( float ) * cov_smooth_cfg->max_bands ) ) == NULL )
#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" );
    }
#ifdef IVAS_FLOAT_FIXED
    IF( ( hCovState->pSmoothing_factor_fx = (Word32 *) malloc( sizeof( Word32 ) * cov_smooth_cfg->max_bands ) ) == NULL )
#else
    if ( ( hCovState->pSmoothing_factor = (float *) malloc( sizeof( float ) * cov_smooth_cfg->max_bands ) ) == NULL )
    {
        return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR COV encoder Fixed" );
        return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR COV encoder" );
    }
#endif

@@ -306,6 +312,13 @@ ivas_error ivas_spar_covar_smooth_enc_open(
                return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR COV encoder" );
            }
            set_zero( hCovState->pPrior_cov_real[i][j], cov_smooth_cfg->max_bands );
#ifdef IVAS_FLOAT_FIXED
            if ( ( hCovState->pPrior_cov_real_fx[i][j] = (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" );
            }
            set_zero_fx( hCovState->pPrior_cov_real_fx[i][j], cov_smooth_cfg->max_bands );
#endif
        }
    }

@@ -339,11 +352,12 @@ void ivas_spar_covar_smooth_enc_close(

    if ( hCovState != NULL )
    {
        free( hCovState->pSmoothing_factor );
        hCovState->pSmoothing_factor = NULL;
#ifdef IVAS_FLOAT_FIXED
        free( hCovState->pSmoothing_factor_fx );
        hCovState->pSmoothing_factor_fx = NULL;
#else
        free( hCovState->pSmoothing_factor );
        hCovState->pSmoothing_factor = NULL;
#endif

        for ( i = 0; i < nchan_inp; i++ )
@@ -352,6 +366,10 @@ void ivas_spar_covar_smooth_enc_close(
            {
                free( hCovState->pPrior_cov_real[i][j] );
                hCovState->pPrior_cov_real[i][j] = NULL;
#ifdef IVAS_FLOAT_FIXED
                free( hCovState->pPrior_cov_real_fx[i][j] );
                hCovState->pPrior_cov_real_fx[i][j] = NULL;
#endif
            }
        }

@@ -363,6 +381,120 @@ void ivas_spar_covar_smooth_enc_close(
}


#ifdef IVAS_FLOAT_FIXED
/*-----------------------------------------------------------------------------------------*
 * Function ivas_compute_smooth_cov_fx()
 *
 * Compute smooth covariance real/imag.
 *-----------------------------------------------------------------------------------------*/

static void ivas_compute_smooth_cov_fx(
    ivas_cov_smooth_state_t *hCovState,
    ivas_filterbank_t *pFb,
    Word32 *pCov_buf[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH],
    Word32 *pPrior_cov_buf[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH],
    const Word32 fac,
    const Word16 start_band,
    const Word16 end_band,
    const Word16 num_ch,
    const Word16 transient_det[2],
    Word16 q_cov[][IVAS_SPAR_MAX_CH] )
{
    Word16 i, j, k;
    Word16 prev_idx = hCovState->prior_bank_idx;
    Word32 factor = 0, L_tmp, L_tmp1;
    Word16 sm_b;
    Word16 non_sm_b_idx;
    sm_b = BAND_SMOOTH_REST_START_IDX;

    assert( end_band <= pFb->filterbank_num_bands );

    IF( EQ_16( prev_idx, -1 ) || EQ_16( transient_det[1], 1 ) )
    {
        FOR( i = 0; i < num_ch; i++ )
        {
            FOR( k = start_band; k < end_band; k++ )
            {
                L_tmp = Mpy_32_32( hCovState->pSmoothing_factor_fx[k], fac ); // (Q31, Q31) -> Q31
                pCov_buf[i][i][k] = L_add( pCov_buf[i][i][k], L_shl( L_tmp, sub( q_cov[i][i], Q31 ) ) );
                move32();
            }
        }
    }
    ELSE IF( EQ_16( transient_det[0], 1 ) )
    {
        non_sm_b_idx = s_min( sm_b, end_band );
        FOR( i = 0; i < num_ch; i++ )
        {
            FOR( j = 0; j < num_ch; j++ )
            {
                IF( EQ_16( i, j ) )
                {
                    factor = fac;
                    move32();
                }
                ELSE
                {
                    factor = 0;
                    move32();
                }

                FOR( k = start_band; k < non_sm_b_idx; k++ )
                {
                    L_tmp = Mpy_32_32( hCovState->pSmoothing_factor_fx[k], pCov_buf[i][j][k] );                             // (Q31, q_cov[i][j]) -> q_cov[i][j]
                    L_tmp1 = Mpy_32_32( L_sub( ONE_IN_Q31, hCovState->pSmoothing_factor_fx[k] ), pPrior_cov_buf[i][j][k] ); // (Q31, q_cov[i][j]) -> q_cov[i][j]
                    pCov_buf[i][j][k] = L_add( L_tmp, L_tmp1 );
                    move32();
                    L_tmp = L_shl( Mpy_32_32( hCovState->pSmoothing_factor_fx[k], factor ), sub( q_cov[i][j], Q31 ) ); // ((Q31, Q31) -> Q31) -> q_cov[i][j]
                    pCov_buf[i][j][k] = L_add( pCov_buf[i][j][k], L_tmp );
                    move32();
                }
            }
        }
        FOR( i = 0; i < num_ch; i++ )
        {
            FOR( k = non_sm_b_idx; k < end_band; k++ )
            {
                L_tmp = Mpy_32_32( hCovState->pSmoothing_factor_fx[k], fac ); // (Q31, Q31) -> Q31
                pCov_buf[i][i][k] = L_add( pCov_buf[i][i][k], L_shl( L_tmp, sub( q_cov[i][i], Q31 ) ) );
                move32();
            }
        }
    }
    ELSE IF( EQ_16( prev_idx, 0 ) )
    {
        FOR( i = 0; i < num_ch; i++ )
        {
            FOR( j = 0; j < num_ch; j++ )
            {
                IF( EQ_16( i, j ) )
                {
                    factor = fac;
                    move32();
                }
                ELSE
                {
                    factor = 0;
                    move32();
                }

                FOR( k = start_band; k < end_band; k++ )
                {
                    L_tmp = Mpy_32_32( hCovState->pSmoothing_factor_fx[k], pCov_buf[i][j][k] );                             // (Q31, q_cov[i][j]) -> q_cov[i][j]
                    L_tmp1 = Mpy_32_32( L_sub( ONE_IN_Q31, hCovState->pSmoothing_factor_fx[k] ), pPrior_cov_buf[i][j][k] ); // (Q31, q_cov[i][j]) -> q_cov[i][j]
                    pCov_buf[i][j][k] = L_add( L_tmp, L_tmp1 );
                    move32();
                    L_tmp = L_shl( Mpy_32_32( hCovState->pSmoothing_factor_fx[k], factor ), sub( q_cov[i][j], Q31 ) ); // ((Q31, Q31) -> Q31) -> q_cov[i][j]
                    pCov_buf[i][j][k] = L_add( pCov_buf[i][j][k], L_tmp );
                    move32();
                }
            }
        }
    }

    return;
}
#else
/*-----------------------------------------------------------------------------------------*
 * Function ivas_compute_smooth_cov()
 *
@@ -454,8 +586,45 @@ static void ivas_compute_smooth_cov(

    return;
}
#endif


#ifdef IVAS_FLOAT_FIXED
/*-----------------------------------------------------------------------------------------*
 * Function ivas_cov_smooth_process_fx()
 *
 * Covariance smoothing process
 *-----------------------------------------------------------------------------------------*/

void ivas_cov_smooth_process_fx(
    ivas_cov_smooth_state_t *hCovState, /* i/o: Covariance state handle */
    Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH],
    ivas_filterbank_t *pFb, /* i/o: FB handle               */
    const Word16 start_band,
    const Word16 end_band,
    const Word16 num_ch,
    const Word16 transient_det[2],
    Word16 q_cov[][IVAS_SPAR_MAX_CH] )
{
    Word16 i, j;
    Word16 num_bands = end_band - start_band;

    ivas_compute_smooth_cov_fx( hCovState, pFb, cov_real, hCovState->pPrior_cov_real_fx, (Word32) ( 1e-20f * ONE_IN_Q31 ), start_band, end_band, num_ch, transient_det, q_cov );

    FOR( i = 0; i < num_ch; i++ )
    {
        FOR( j = 0; j < num_ch; j++ )
        {
            mvl2l( &cov_real[i][j][start_band], &hCovState->pPrior_cov_real_fx[i][j][start_band], num_bands );
        }
    }

    hCovState->prior_bank_idx = 0;
    move16();

    return;
}
#else
/*-----------------------------------------------------------------------------------------*
 * Function ivas_cov_smooth_process()
 *
@@ -488,3 +657,4 @@ void ivas_cov_smooth_process(

    return;
}
#endif
+35 −0
Original line number Diff line number Diff line
@@ -5305,6 +5305,27 @@ void ivas_spar_covar_enc_close(
    const int16_t nchan_inp                                     /* i  : number of input channels                */
);

#ifdef IVAS_FLOAT_FIXED
ivas_error ivas_enc_cov_handler_process(
    ivas_enc_cov_handler_state_t *hCovEnc, /* i/o: SPAR Covar. encoder handle      */
    float **ppIn_FR_real,
    float **ppIn_FR_imag,
    float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH],
    float *cov_dtx_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH],
    ivas_filterbank_t *pFb, /* i/o: FB handle                       */
    const int16_t start_band,
    const int16_t end_band,
    const int16_t num_ch,
    const int16_t dtx_vad,
    const int16_t transient_det[2],
    const int16_t HOA_md_ind[IVAS_SPAR_MAX_CH],
    int16_t *res_ind,
    const int16_t *remix_order,
    int16_t *dyn_active_w_flag,
    const int16_t nchan_transport,
    const int16_t is_sba
);
#else
void ivas_enc_cov_handler_process( 
    ivas_enc_cov_handler_state_t *hCovEnc,                      /* i/o: SPAR Covar. encoder handle              */
    float **ppIn_FR_real,
@@ -5324,6 +5345,7 @@ void ivas_enc_cov_handler_process(
    const int16_t nchan_transport,
    const int16_t is_sba
);
#endif

ivas_error ivas_spar_covar_smooth_enc_open( 
    ivas_cov_smooth_state_t **hCovState,                        /* i/o: SPAR Covar. smoothing handle            */
@@ -5339,6 +5361,18 @@ void ivas_spar_covar_smooth_enc_close(
    const int16_t nchan_inp                                     /* i  : number of input channels                */
);

#ifdef IVAS_FLOAT_FIXED
void ivas_cov_smooth_process_fx( 
    ivas_cov_smooth_state_t *hCovState,                         /* i/o: Covariance state handle                 */
    Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH],
    ivas_filterbank_t *pFb,                                     /* i/o: FB handle                               */
    const Word16 start_band,
    const Word16 end_band,
    const Word16 num_ch,
    const Word16 transient_det[2],
    Word16 q_cov[][IVAS_SPAR_MAX_CH]
);
#else
void ivas_cov_smooth_process( 
    ivas_cov_smooth_state_t *hCovState,                         /* i/o: Covariance state handle                 */
    float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH],
@@ -5348,6 +5382,7 @@ void ivas_cov_smooth_process(
    const int16_t num_ch,
    const int16_t transient_det[2]
);
#endif

/* Transient detector module */
ivas_error ivas_transient_det_open(
+3 −0
Original line number Diff line number Diff line
@@ -354,9 +354,12 @@ typedef struct ivas_cov_smooth_state_t
{
    float *pPrior_cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH];
    int16_t prior_bank_idx;
#ifndef IVAS_FLOAT_FIXED
    float *pSmoothing_factor;
#endif
    int16_t num_bins;
#ifdef IVAS_FLOAT_FIXED
    Word32 *pPrior_cov_real_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH];
    Word32 *pSmoothing_factor_fx;
#endif

+2 −0
Original line number Diff line number Diff line
@@ -95,6 +95,8 @@
#define NONBE_FIX_819_DOUBLE_PREC_COMB_FORMATS                /* VA: issue 820: Double precision arithmetic in combined formats */
#define NONBE_FIX_849_OMASA_BFI_CRASH                         /* VA: issue 849: fix OMASA 2TC and FEC crashes */
#define IVAS_FLOAT_FIXED
#define FIX_TMP_714
#define BASOP_NOGLOB_TMP_715
#define EVS_FUNC_MODIFIED
//#define DEBUGGING
//#define DBG_WAV_WRITER
Loading