Commit 942bd24b authored by Sandesh Venkatesh's avatar Sandesh Venkatesh
Browse files

LTV crash fixes in OMASA encoder and stereo encoder paths, float code cleanup

parent 2fa134ca
Loading
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -29,9 +29,9 @@ Word32 floatToFixed( float f, Word16 Q )
float fixedToFloat( Word32 i, Word16 Q )
{
    if ( Q < 0 )
        return ( i * (float) ( ( (unsigned) 1 ) << ( -Q ) ) );
        return ( i * (float) ( ( 1LL ) << ( -Q ) ) );
    else
        return (float) ( i ) / (float) ( (unsigned int) 1 << Q );
        return (float) ( i ) / (float) ( 1LL << Q );
}
void floatToFixed_arrL( float *f, Word32 *i, Word16 Q, Word16 l )
{
+1 −1
Original line number Diff line number Diff line
@@ -49,7 +49,7 @@
#define PI_OVER_180_Q22                         ( 73204 )
#define _180_OVER_PI                            ( 180.0f / EVS_PI )
#ifdef IVAS_FLOAT_FIXED
#define _180_OVER_PI_Q25                         1922521886
#define _180_OVER_PI_Q25                         1922527338
#define PI_OVER_180_Q25                         ( 585635 )
#define _180_IN_Q22 (754974720)
#define _360_IN_Q22 (1509949440)
+4 −1
Original line number Diff line number Diff line
@@ -217,7 +217,7 @@ void FEC_encode_ivas_fx(

    return;
}
#endif
#else
void FEC_encode(
    BSTR_ENC_HANDLE hBstr,        /* i/o: encoder bitstream handle                        */
    const ACELP_config acelp_cfg, /* i/o: configuration of the ACELP                      */
@@ -350,7 +350,9 @@ void FEC_encode(

    return;
}
#endif

#ifndef IVAS_FLOAT_FIXED
/*-------------------------------------------------------------------*
 * FEC_lsf_estim_enc()
 *
@@ -438,3 +440,4 @@ void FEC_lsf_estim_enc(

    return;
}
#endif
+2 −0
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@
#include "wmc_auto.h"


#ifndef IVAS_FLOAT_FIXED
/*-------------------------------------------------------------------*
 * SNR_calc()
 *
@@ -259,3 +260,4 @@ void calc_lf_snr(

    return;
}
#endif
+7 −53
Original line number Diff line number Diff line
@@ -230,7 +230,6 @@ ivas_error acelp_core_enc(
    floatToFixed_arr( &inp[-M - 1], &inp_fx[-M - 1], Q_new, L_FRAME16k + M + 1 );
    floatToFixed_arrL( st->Bin_E_old, st->Bin_E_old_fx, Q_new + Q_SCALE - 2, 128 );
    floatToFixed_arrL( st->Bin_E, st->Bin_E_fx, Q_new + Q_SCALE - 2, 256 );
    st->stab_fac_fx = float_to_fix16( st->stab_fac, Q15 );
    IF( hStereoTD )
    {
        floatToFixed_arr( hStereoTD->tdm_Pri_pitch_buf, hStereoTD->tdm_Pri_pitch_buf_fx, Q6, 4 );
@@ -337,7 +336,11 @@ ivas_error acelp_core_enc(
    move16();

    /* channel-aware mode */
#ifndef IVAS_FLOAT_FIXED
    reset_rf_indices( st->hRF, st->L_frame, &st->rf_target_bits_write );
#else
    reset_rf_indices_fx( st );
#endif

    /* VBR modes */
    IF( st->Opt_SC_VBR )
@@ -499,25 +502,13 @@ ivas_error acelp_core_enc(
            floatToFixed_arr( Aq, Aq_fx, NB_SUBFR16k * ( M + 1 ), Q12 );
            q_inp = Q_factor_arr( inp, st->L_frame );
            floatToFixed_arr( inp, inp_fx, q_inp, st->L_frame );
            st->hTdCngEnc->CNG_att_fx = float_to_fix16( st->hTdCngEnc->CNG_att, Q7 );
            floatToFixed_arr( lsp_mid, lsp_mid_fx, Q15, M );
            floatToFixed_arr( lsp_new, lsp_new_fx, Q15, M );
            floatToFixed_arr( st->lsp_old, st->lsp_old_fx, Q15, M );
            floatToFixed_arr( st->hTdCngEnc->ho_lsp_hist, st->hTdCngEnc->ho_lsp_hist_fx, Q15, HO_HIST_SIZE * M );
            floatToFixed_arr( st->hTdCngEnc->ho_lsp_circ, st->hTdCngEnc->ho_lsp_circ_fx, Q15, HO_HIST_SIZE * M );
            floatToFixed_arr( st->hTdCngEnc->ho_lsp_circ2, st->hTdCngEnc->ho_lsp_circ2_fx, Q15, HO_HIST_SIZE * M );
            floatToFixed_arrL( st->hTdCngEnc->ho_ener_hist, st->hTdCngEnc->ho_ener_hist_fx, Q6, HO_HIST_SIZE );
            floatToFixed_arrL( st->hTdCngEnc->ho_ener_circ, st->hTdCngEnc->ho_ener_circ_fx, Q6, HO_HIST_SIZE );
            floatToFixed_arr( st->hTdCngEnc->cng_ener_hist, st->hTdCngEnc->cng_ener_hist_fx, Q8, DTX_HIST_SIZE );
            floatToFixed_arr( st->hDtxEnc->lspCNG, st->hDtxEnc->lspCNG_fx, Q15, M );
            floatToFixed_arrL( st->hTdCngEnc->cng_res_env, st->hTdCngEnc->cng_res_env_fx, Q6, NUM_ENV_CNG * HO_HIST_SIZE );
            floatToFixed_arr( st->hTdCngEnc->cng_lsp_hist, st->hTdCngEnc->cng_lsp_hist_fx, Q15, DTX_HIST_SIZE * M );
            floatToFixed_arrL( st->hTdCngEnc->lp_env, st->hTdCngEnc->lp_env_fx, Q6, NUM_ENV_CNG );
            floatToFixed_arrL( st->hTdCngEnc->ho_env_hist, st->hTdCngEnc->ho_env_hist_fx, Q6, HO_HIST_SIZE * NUM_ENV_CNG );
            floatToFixed_arr( st->hTdCngEnc->exc_mem2, st->hTdCngEnc->exc_mem2_fx, q_inp, 30 );
            st->hTdCngEnc->lp_ener_fx = float_to_fix( st->hTdCngEnc->lp_ener, Q6 );
            st->hTdCngEnc->Enew_fx = float_to_fix( st->hTdCngEnc->Enew, Q6 );
            st->hTdCngEnc->lp_sp_enr_fx = float_to_fix16( st->hTdCngEnc->lp_sp_enr, Q8 );
            for ( i = 0; i < M; i++ )
            {
                lsf_new_fx[i] = (Word16) ( lsf_new[i] * 2.56f );
@@ -531,23 +522,11 @@ ivas_error acelp_core_enc(
            fixedToFloat_arr( lsp_new_fx, lsp_new, Q15, M );
            fixedToFloat_arrL32( q_env_fx, q_env, Q6, NUM_ENV_CNG );
            fixedToFloat_arr( st->lsp_old_fx, st->lsp_old, Q15, M );
            fixedToFloat_arr( st->hDtxEnc->lspCNG_fx, st->hDtxEnc->lspCNG, Q15, M );
            fixedToFloat_arr( st->hTdCngEnc->ho_lsp_circ_fx, st->hTdCngEnc->ho_lsp_circ, Q15, HO_HIST_SIZE * M );
            fixedToFloat_arr( st->hTdCngEnc->ho_lsp_circ2_fx, st->hTdCngEnc->ho_lsp_circ2, Q15, HO_HIST_SIZE * M );
            fixedToFloat_arr( st->hTdCngEnc->ho_lsp_hist_fx, st->hTdCngEnc->ho_lsp_hist, Q15, HO_HIST_SIZE * M );
            fixedToFloat_arrL( st->hTdCngEnc->ho_env_circ_fx, st->hTdCngEnc->ho_env_circ, Q6, 160 );
            fixedToFloat_arrL( st->hTdCngEnc->cng_res_env_fx, st->hTdCngEnc->cng_res_env, Q6, NUM_ENV_CNG * HO_HIST_SIZE );
            fixedToFloat_arr( st->hTdCngEnc->cng_ener_hist_fx, st->hTdCngEnc->cng_ener_hist, Q8, DTX_HIST_SIZE );
            fixedToFloat_arrL( st->hTdCngEnc->ho_ener_hist_fx, st->hTdCngEnc->ho_ener_hist, Q6, HO_HIST_SIZE );
            fixedToFloat_arrL( st->hTdCngEnc->ho_ener_circ_fx, st->hTdCngEnc->ho_ener_circ, Q6, HO_HIST_SIZE );
            fixedToFloat_arr( st->hTdCngEnc->cng_lsp_hist_fx, st->hTdCngEnc->cng_lsp_hist, Q15, DTX_HIST_SIZE * M );
            fixedToFloat_arrL( st->hTdCngEnc->lp_env_fx, st->hTdCngEnc->lp_env, Q6, NUM_ENV_CNG );
            fixedToFloat_arrL( st->hTdCngEnc->ho_env_hist_fx, st->hTdCngEnc->ho_env_hist, Q6, HO_HIST_SIZE * NUM_ENV_CNG );
            fixedToFloat_arr( st->hTdCngEnc->exc_mem2_fx, st->hTdCngEnc->exc_mem2, q_inp, 30 );
            st->hTdCngEnc->lp_sp_enr = fix16_to_float( st->hTdCngEnc->lp_sp_enr_fx, Q8 );
            st->hTdCngEnc->lp_ener = fix_to_float( st->hTdCngEnc->lp_ener_fx, Q6 );
            st->hTdCngEnc->Enew = fix_to_float( st->hTdCngEnc->Enew_fx, Q6 );
            st->hTdCngEnc->CNG_att = fix16_to_float( st->hTdCngEnc->CNG_att_fx, Q7 );
            for ( i = 0; i < M; i++ )
            {
                lsf_new[i] = ( (float) lsf_new_fx[i] / 2.56f );
@@ -562,11 +541,7 @@ ivas_error acelp_core_enc(
#endif

#ifdef IVAS_FLOAT_FIXED_CONVERSIONS
            st->hTdCngEnc->Enew_fx = float_to_fix( st->hTdCngEnc->Enew, Q6 );
            st->hTdCngEnc->lp_ener_fx = float_to_fix( st->hTdCngEnc->lp_ener, Q6 );
            floatToFixed_arr32( q_env, q_env_fx, Q6, NUM_ENV_CNG );
            floatToFixed_arr32( st->hTdCngEnc->lp_env, st->hTdCngEnc->lp_env_fx, Q6, NUM_ENV_CNG );
            floatToFixed_arr32( st->hTdCngEnc->old_env, st->hTdCngEnc->old_env_fx, Q6, NUM_ENV_CNG );
            // Word16 Q_exc_l = Q_factor_arr( st->hTdCngEnc->exc_mem, 24 );
            // Word16 Q_exc1_l = Q_factor_arr( st->hTdCngEnc->exc_mem1, 30 );
            // Q_exc_l = min( Q_exc_l, Q_exc1_l );
@@ -583,11 +558,7 @@ ivas_error acelp_core_enc(
                        q_env_fx, st->hTdCngEnc->lp_env_fx, st->hTdCngEnc->old_env_fx, st->hTdCngEnc->exc_mem_fx, st->hTdCngEnc->exc_mem1_fx, &sid_bw, &st->hTdCngEnc->cng_ener_seed1, exc3_fx, st->Opt_AMR_WB, EVS_MONO );

#ifdef IVAS_FLOAT_FIXED_CONVERSIONS
            st->hTdCngEnc->Enew = fixedToFloat( st->hTdCngEnc->Enew_fx, Q6 );
            st->hTdCngEnc->lp_ener = fixedToFloat( st->hTdCngEnc->lp_ener_fx, Q6 );
            fixedToFloat_arrL( q_env_fx, q_env, Q6, NUM_ENV_CNG );
            fixedToFloat_arrL( st->hTdCngEnc->lp_env_fx, st->hTdCngEnc->lp_env, Q6, NUM_ENV_CNG );
            fixedToFloat_arrL( st->hTdCngEnc->old_env_fx, st->hTdCngEnc->old_env, Q6, NUM_ENV_CNG );
            fixedToFloat_arr( exc_fx, exc, Q_new, st->L_frame );
            fixedToFloat_arr( exc2_fx, exc2, Q_new, st->L_frame );
            fixedToFloat_arr( exc3_fx, exc3, Q_new, st->L_frame );
@@ -616,10 +587,6 @@ ivas_error acelp_core_enc(
            Word16 Q_cngNoise = Q_factor_arrL( st->hFdCngEnc->hFdCngCom->cngNoiseLevel_flt, FFTCLDFBLEN );
            floatToFixed_arrL( st->hFdCngEnc->hFdCngCom->cngNoiseLevel_flt, st->hFdCngEnc->hFdCngCom->cngNoiseLevel, Q_cngNoise, FFTCLDFBLEN );
            st->hFdCngEnc->hFdCngCom->cngNoiseLevelExp = sub( 31, Q_cngNoise );
            IF( st->hTdCngEnc != NULL )
            {
                st->hTdCngEnc->CNG_att_fx = float_to_fix16( st->hTdCngEnc->CNG_att, Q7 );
            }
            st->preemph_fac = float_to_fix16( st->preemph_fac_flt, Q15 );
#endif
            // generate_comfort_noise_enc( st );
@@ -637,7 +604,6 @@ ivas_error acelp_core_enc(
            // Word16 Q_exc_cng_l = Q_factor_arr( st->hFdCngEnc->hFdCngCom->exc_cng_flt, st->L_frame );
            floatToFixed_arr( st->hFdCngEnc->hFdCngCom->exc_cng_flt, st->hFdCngEnc->hFdCngCom->exc_cng, Q_new, st->L_frame );
            floatToFixed_arr( st->lsp_old, st->lsp_old_fx, Q15, M );
            floatToFixed_arr( st->hDtxEnc->lspCNG, st->hDtxEnc->lspCNG_fx, Q15, M );
#endif
            // FdCng_exc_flt( st->hFdCngEnc->hFdCngCom, &st->hDtxEnc->CNG_mode, st->L_frame, st->lsp_old, st->hDtxEnc->first_CNG, st->hDtxEnc->lspCNG, Aq, lsp_new, lsf_new, exc, exc2, bwe_exc );
            FdCng_exc( st->hFdCngEnc->hFdCngCom, &st->hDtxEnc->CNG_mode, st->L_frame, st->lsp_old_fx, st->hDtxEnc->first_CNG, st->hDtxEnc->lspCNG_fx, Aq_fx, lsp_new_fx, lsf_new_fx, exc_fx, exc2_fx, bwe_exc_fx );
@@ -649,7 +615,6 @@ ivas_error acelp_core_enc(
                lsf_new[i] = ( (float) lsf_new_fx[i] / 2.56f );
            }

            fixedToFloat_arr( st->hDtxEnc->lspCNG_fx, st->hDtxEnc->lspCNG, Q15, M );
            fixedToFloat_arr( exc_fx, exc, Q_new, st->L_frame );
            fixedToFloat_arr( exc2_fx, exc2, Q_new, st->L_frame );
            IF( st->hBWE_TD != NULL )
@@ -666,7 +631,6 @@ ivas_error acelp_core_enc(
                {
                    Word16 enr, enr_index;
#ifdef IVAS_FLOAT_FIXED_CONVERSIONS
                    st->hTdCngEnc->CNG_att_fx = float_to_fix16( st->hTdCngEnc->CNG_att, Q7 );
                    // Word16 Q_exc_l = Q_factor_arr( exc, st->L_frame );
                    floatToFixed_arr( exc, exc_fx, Q_new, st->L_frame );
#endif
@@ -703,14 +667,14 @@ ivas_error acelp_core_enc(
        Q_syn_l = Q_factor_arr( hLPDmem->mem_syn3_flt, M );
        floatToFixed_arr( hLPDmem->mem_syn3_flt, hLPDmem->mem_syn3, Q_syn_l, M );

        floatToFixed_arr( Aq, Aq_fx, NB_SUBFR16k * ( M + 1 ), Q12 );
        floatToFixed_arr( Aq, Aq_fx, Q12, NB_SUBFR16k * ( M + 1 ) );
#endif
        /* synthesis at 12.8kHz sampling rate */
        syn_12k8_fx( st->L_frame, Aq_fx, exc3_fx, syn1_fx, hLPDmem->mem_syn3, 1, Q_exc_l, Q_syn_l );

#ifdef IVAS_FLOAT_FIXED_CONVERSIONS
        fixedToFloat_arr( Aq_fx, Aq, NB_SUBFR16k * ( M + 1 ), Q12 );
        fixedToFloat_arr( exc3_fx, exc, st->L_frame, Q_exc_l );
        fixedToFloat_arr( Aq_fx, Aq, Q12, NB_SUBFR16k * ( M + 1 ) );
        fixedToFloat_arr( exc3_fx, exc, Q_exc_l, st->L_frame );
        fixedToFloat_arr( hLPDmem->mem_syn3, hLPDmem->mem_syn3_flt, Q_syn_l, M );
        fixedToFloat_arr( syn1_fx, syn1, Q_syn_l, st->L_frame );
#endif
@@ -793,10 +757,6 @@ ivas_error acelp_core_enc(
            }
        }

        IF( st->hDtxEnc )
        {
            floatToFixed_arr( st->hDtxEnc->lspCNG, st->hDtxEnc->lspCNG_fx, Q15, M );
        }
        for ( i = 0; i < M; i++ )
        {
            st->lsf_old_fx[i] = (Word16) ( st->lsf_old[i] * 2.56f );
@@ -816,8 +776,6 @@ ivas_error acelp_core_enc(
        st->clip_var_fx[3] = float_to_fix16( st->clip_var[3], 0 );
        st->clip_var_fx[4] = float_to_fix16( st->clip_var[4], Q14 );
        st->clip_var_fx[5] = float_to_fix16( st->clip_var[5], Q14 );

        st->streaklimit_fx = (Word16) floatToFixed( st->streaklimit, Q15 );
        FOR( Word16 idx = 0; idx < M; idx++ )
        {
            st->lsf_adaptive_mean_fx[idx] = (Word16) ( st->lsf_adaptive_mean[idx] * 2.56f );
@@ -847,8 +805,6 @@ ivas_error acelp_core_enc(
        st->hGSCEnc->last_ener_fx = (Word16) st->hGSCEnc->last_ener;
        IF( st->hLPDmem )
        st->hLPDmem->tilt_code = float_to_fix16( st->hLPDmem->tilt_code_flt, Q15 );
        IF( st->hTdCngEnc )
        st->hTdCngEnc->CNG_att_fx = float_to_fix16( st->hTdCngEnc->CNG_att, Q7 );
#endif
        /*-----------------------------------------------------------------*
         * Configure ACELP bit allocation
@@ -1075,7 +1031,6 @@ ivas_error acelp_core_enc(
            // So each chunk might have a different Q which is predicted by 1st element.
            fixedToFloat_arr( &Aq_fx[i * ( M + 1 )], &Aq[i * ( M + 1 )], 14 - norm_s( Aq_fx[i * ( M + 1 )] ), ( M + 1 ) );
        }
        st->stab_fac = fixedToFloat( st->stab_fac_fx, Q15 );
        fixedToFloat_arr( old_exc_fx, old_exc_flt, Q15 - hLPDmem->e_old_exc, st->L_frame );
        me2f_buf_16( &hLPDmem->old_exc[-M - 1], hLPDmem->e_old_exc, &hLPDmem->old_exc_flt[-M - 1], L_EXC_MEM + M + 1 );
        fixedToFloat_arr( old_bwe_exc_fx, old_bwe_exc, Q_old_bwe_exc, 1380 );
@@ -1510,7 +1465,6 @@ ivas_error acelp_core_enc(
        floatToFixed_arr16( exc, exc_fx, q_exc, L_EXC - L_EXC_MEM );
        floatToFixed_arr16( st->hTdCngEnc->cng_exc2_buf_flt, st->hTdCngEnc->cng_exc2_buf, q_exc, HO_HIST_SIZE * L_FFT );

        floatToFixed_arr32( st->hTdCngEnc->ho_ener_circ, st->hTdCngEnc->ho_ener_circ_fx, Q6, HO_HIST_SIZE );
        floatToFixed_arr32( st->hTdCngEnc->ho_env_circ, st->hTdCngEnc->ho_env_circ_fx, Q6, HO_HIST_SIZE * NUM_ENV_CNG );
        floatToFixed_arr16( st->hTdCngEnc->ho_lsp_circ, st->hTdCngEnc->ho_lsp_circ_fx, Q15, HO_HIST_SIZE * M );

Loading