Commit 4d041964 authored by Sandesh Venkatesh's avatar Sandesh Venkatesh
Browse files

MSAN fixes and input buffer float code removal

parent 6c27a4cf
Loading
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -846,7 +846,8 @@ void cng_params_postupd_ivas_fx(
#endif                                                                              /* BASOP_NOGLOB */
            L_tmp = Mult_32_16( L_tmp, 128 );                                       /* 2*Q_exc+1 */
            tmp = add( add( Q_exc, Q_exc ), 1 );
            sp[i] = L_shr( L_tmp, sub( tmp, 6 ) );
            // To do : Saturation to be re-validated.
            sp[i] = L_shr_sat( L_tmp, sub( tmp, 6 ) );
            move32(); /* Q6 */

            ptR++;
+4 −3
Original line number Diff line number Diff line
@@ -1735,7 +1735,8 @@ Word16 matrix_product_fx(
                {
                    x_idx = add( i, imult1616( k, rowsX ) );                                 /*Q0*/
                    y_idx = add( k, imult1616( j, rowsY ) );                                 /*Q0*/
                    ( *Zp_fx ) = L_add( *Zp_fx, Mpy_32_32( X_fx[x_idx], Y_fx[y_idx] ) ); /*Qx + Qy - 31*/
                    ( *Zp_fx ) = L_add_sat( *Zp_fx, Mpy_32_32( X_fx[x_idx], Y_fx[y_idx] ) ); /*Qx + Qy - 31*/
                    // TODO: overflow of Z_fx to be checked
                    move32();
                }
                Zp_fx++;
+35 −177
Original line number Diff line number Diff line
@@ -57,8 +57,8 @@ static void init_tcx( Encoder_State *st, const int16_t L_frame_old, const int32_
static void init_sig_buffers( Encoder_State *st, const int16_t L_frame_old, const int16_t L_subfr, const int32_t total_brate, const int32_t last_total_brate );
#ifndef IVAS_FLOAT_FIXED
static void init_core_sig_ana( Encoder_State *st );
#endif
static void init_acelp( Encoder_State *st, const int16_t L_frame_old, const int32_t total_brate, const int32_t last_total_brate );
#endif
static void init_modes( Encoder_State *st, const int32_t last_total_brate );
#ifdef IVAS_FLOAT_FIXED
static void init_tcx_ivas_fx( Encoder_State *st, const Word16 L_frame_old, const Word32 total_brate, const Word32 last_total_brate, const Word16 MCT_flag );
@@ -494,9 +494,10 @@ void init_coder_ace_plus(
    init_sig_buffers( st, L_frame_old, L_subfr, st->total_brate, last_total_brate );

    /* Initialize ACELP */
    init_acelp( st, L_frame_old, st->total_brate, last_total_brate );
#ifdef IVAS_FLOAT_FIXED
    init_acelp_ivas_fx( st, L_frame_old, 0 );
#else
    init_acelp( st, L_frame_old, st->total_brate, last_total_brate );
#endif

    if ( st->ini_frame == 0 )
@@ -880,12 +881,6 @@ static void init_sig_buffers(
        // hTcxEnc->new_speech_ltp_flt = hTcxEnc->buf_speech_ltp_flt + st->encoderPastSamples_enc + st->encoderLookahead_enc;
    }

    if ( st->hTcxEnc != NULL )
    {
        st->hTcxEnc->new_speech_TCX_flt = st->input_buff + st->input_Fs / FRAMES_PER_SEC; /* note: in EVS st->new_speech_TCX == st->input - 0.9375ms; in IVAS st->new_speech_TCX == st->input */
        st->hTcxEnc->speech_TCX_flt = st->hTcxEnc->new_speech_TCX_flt - st->encoderLookahead_FB;
    }

    st->speech_enc_flt = st->buf_speech_enc_flt + st->encoderPastSamples_enc;
    st->speech_enc_pe_flt = st->buf_speech_enc_pe_flt + st->encoderPastSamples_enc;

@@ -1010,9 +1005,6 @@ static void init_sig_buffers_ivas_fx( Encoder_State *st, const Word16 L_frame_ol

    if ( st->hTcxEnc != NULL )
    {
        st->hTcxEnc->new_speech_TCX_flt = st->input_buff + st->input_Fs / FRAMES_PER_SEC; /* note: in EVS st->new_speech_TCX == st->input - 0.9375ms; in IVAS st->new_speech_TCX == st->input */
        st->hTcxEnc->speech_TCX_flt = st->hTcxEnc->new_speech_TCX_flt - st->encoderLookahead_FB;

#ifdef IVAS_FLOAT_FIXED
        st->hTcxEnc->new_speech_TCX = st->input_buff_fx + Mpy_32_32( st->input_Fs, ONE_BY_FRAMES_PER_SEC_Q31 );
        st->hTcxEnc->speech_TCX = st->hTcxEnc->new_speech_TCX - st->encoderLookahead_FB;
@@ -1151,17 +1143,16 @@ static void init_core_sig_ana_ivas_fx( Encoder_State *st )
 *
 *
 *-----------------------------------------------------------------------*/

#ifndef IVAS_FLOAT_FIXED
static void init_acelp(
    Encoder_State *st,
    const int16_t L_frame_old,
    const int32_t total_brate,
    const int32_t last_total_brate )
{
#ifndef IVAS_FLOAT_FIXED
    int16_t mem_syn_r_size_old;
    int16_t mem_syn_r_size_new;
#endif

    LPD_state_HANDLE hLPDmem = st->hLPDmem;

    /* Init pitch lag */
@@ -1180,62 +1171,43 @@ static void init_acelp(
    {
        if ( hLPDmem != NULL )
        {
#ifndef IVAS_FLOAT_FIXED
            set_zero( hLPDmem->syn_flt, 1 + M );
            set_zero( hLPDmem->mem_syn_r_flt, L_SYN_MEM );
#endif
            set_zero( hLPDmem->syn, 1 + M );
            set_zero( hLPDmem->mem_syn_r, L_SYN_MEM );
        }

        if ( st->hTcxEnc != NULL )
        {
#ifdef IVAS_FLOAT_FIXED
            set16_fx( st->hTcxEnc->Txnq, 0, L_FRAME32k / 2 + 64 );
            set_zero( st->hTcxEnc->Txnq, L_FRAME32k / 2 + 64 );
            st->hTcxEnc->acelp_zir = st->hTcxEnc->Txnq + ( st->L_frame / 2 );
            st->hTcxEnc->q_Txnq = Q15;
            move16();
#endif
        }
    }
    else /*Rate switching*/
    {
#ifndef IVAS_FLOAT_FIXED
        if ( st->hTcxEnc != NULL )
        {
            if ( st->last_core == ACELP_CORE )
            {
                lerp_flt( st->hTcxEnc->Txnq_flt, st->hTcxEnc->Txnq_flt, st->L_frame / 2, L_frame_old / 2 );
                lerp( st->hTcxEnc->Txnq, st->hTcxEnc->Txnq, st->L_frame / 2, L_frame_old / 2 );
            }
            else
            {
                lerp_flt( st->hTcxEnc->Txnq_flt, st->hTcxEnc->Txnq_flt, st->hTcxCfg->tcx_mdct_window_length, st->hTcxCfg->tcx_mdct_window_length_old );
                lerp( st->hTcxEnc->Txnq, st->hTcxEnc->Txnq, st->hTcxCfg->tcx_mdct_window_length, st->hTcxCfg->tcx_mdct_window_length_old );
            }
            st->hTcxEnc->acelp_zir_flt = st->hTcxEnc->Txnq_flt + ( st->L_frame / 2 );

#ifdef IVAS_FLOAT_FIXED
            st->hTcxEnc->acelp_zir = st->hTcxEnc->Txnq + ( st->L_frame / 2 );
#endif
        }
#endif

        /* Rate switching */
        if ( st->last_codec_mode == MODE1 && st->element_mode == EVS_MONO )
        {
            if ( hLPDmem != NULL )
            {
#ifndef IVAS_FLOAT_FIXED
                mvr2r( hLPDmem->mem_syn1_flt, hLPDmem->mem_syn2_flt, M );
                set_zero( hLPDmem->syn_flt, M );
#endif
                mvr2r( hLPDmem->mem_syn1, hLPDmem->mem_syn2, M );
                set_zero( hLPDmem->syn, M );
            }

            if ( st->hTcxEnc != NULL )
            {
#ifndef IVAS_FLOAT_FIXED
                set_zero( st->hTcxEnc->Txnq_flt, L_FRAME32k / 2 + 64 );
#else
                set16_fx( st->hTcxEnc->Txnq, 0, L_FRAME32k / 2 + 64 );
                st->hTcxEnc->q_Txnq = Q15;
                move16();
#endif
                set_zero( st->hTcxEnc->Txnq, L_FRAME32k / 2 + 64 );
            }
        }

@@ -1252,20 +1224,15 @@ static void init_acelp(
            st->rate_switching_reset = 1;
            if ( hLPDmem != NULL )
            {
#ifndef IVAS_FLOAT_FIXED
                hLPDmem->tilt_code_flt = TILT_CODE_FLT;
                set_zero( hLPDmem->old_exc_flt, L_EXC_MEM );
                set_zero( hLPDmem->syn_flt, 1 + M );
                hLPDmem->mem_w0_flt = 0.0f;
                set_zero( hLPDmem->mem_syn_flt, M );
                set_zero( hLPDmem->mem_syn2_flt, M );
#else
                hLPDmem->tilt_code = TILT_CODE;
#endif
                set_zero( hLPDmem->old_exc, L_EXC_MEM );
                set_zero( hLPDmem->syn, 1 + M );
                hLPDmem->mem_w0 = 0.0f;
                set_zero( hLPDmem->mem_syn, M );
                set_zero( hLPDmem->mem_syn2, M );
            }

            /* unquantized LPC*/
#ifndef IVAS_FLOAT_FIXED
            if ( !( ( total_brate >= ACELP_16k40 && total_brate <= ACELP_24k40 ) && total_brate == last_total_brate && st->last_bwidth == st->bwidth ) )
            {
                mvr2r( st->lsp_old1, st->lspold_enc, M ); /*lsp old @12.8kHz*/
@@ -1276,25 +1243,6 @@ static void init_acelp(
            }
            mvr2r( st->lspold_enc, st->lsp_old, M ); /*used unquantized values for mid-LSF Q*/
            lsp2lsf( st->lsp_old, st->lsf_old, M, st->sr_core );
#else
            IF( !( ( GE_32( st->total_brate, ACELP_16k40 ) && LE_32( st->total_brate, ACELP_24k40 ) ) && ( EQ_32( total_brate, last_total_brate ) ) && ( EQ_16( st->last_bwidth, st->bwidth ) ) ) )
            {
                Copy( st->lsp_old1_fx, st->lspold_enc_fx, M ); /*lsp old @12.8kHz*/
                IF( EQ_16( st->L_frame, L_FRAME16k ) )
                {
                    lsp_convert_poly_fx( st->lspold_enc_fx, st->L_frame, 0 );
                }
            }
            Copy( st->lspold_enc_fx, st->lsp_old_fx, M ); /*used unquantized values for mid-LSF Q*/
            IF( st->tcxonly == 0 )
            {
                lsp2lsf_fx( st->lsp_old_fx, st->lsf_old_fx, M, st->sr_core );
            }
            ELSE
            {
                E_LPC_lsp_lsf_conversion( st->lsp_old_fx, st->lsf_old_fx, M );
            }
#endif

            st->last_core = TCX_20_CORE;

@@ -1308,32 +1256,12 @@ static void init_acelp(
        {
            if ( st->L_frame != L_frame_old && st->L_frame <= L_FRAME16k && L_frame_old <= L_FRAME16k ) /* Rate switching between 12.8 and 16 kHz*/
            {
#ifndef IVAS_FLOAT_FIXED
                float tmp, A[M + 1], Ap[M + 1], tmp_buf[M + 1];
#endif
                float A[M + 1];
#ifdef IVAS_FLOAT_FIXED
                Word16 A_fx[M + 1];
#endif

                /* convert quantized LSP vector */
#ifndef IVAS_FLOAT_FIXED
                st->rate_switching_reset = lsp_convert_poly( st->lsp_old, st->L_frame, 0 );
                lsp2lsf( st->lsp_old, st->lsf_old, M, st->sr_core );
#else
                st->rate_switching_reset = lsp_convert_poly_fx( st->lsp_old_fx, st->L_frame, 0 );
                move16();
                IF( st->tcxonly == 0 )
                {
                    lsp2lsf_fx( st->lsp_old_fx, st->lsf_old_fx, M, st->sr_core );
                }
                ELSE
                {
                    E_LPC_lsp_lsf_conversion( st->lsp_old_fx, st->lsf_old_fx, M );
                }
#endif

#ifndef IVAS_FLOAT_FIXED
                if ( st->L_frame == L_FRAME16k )
                {
                    mvr2r( st->lsp_old, st->lspold_enc, M );
@@ -1342,38 +1270,19 @@ static void init_acelp(
                {
                    mvr2r( st->lsp_old1, st->lspold_enc, M );
                }
#else
                IF( st->L_frame == L_FRAME16k )
                {
                    Copy( st->lsp_old_fx, st->lspold_enc_fx, M );
                }
                ELSE
                {
                    Copy( st->lsp_old1_fx, st->lspold_enc_fx, M );
                }
#endif

                /* Update wsyn */
                if ( hLPDmem != NULL )
                {
#ifndef IVAS_FLOAT_FIXED
                    synth_mem_updt2_flt( st->L_frame, st->last_L_frame, hLPDmem->old_exc_flt, hLPDmem->mem_syn_r_flt, hLPDmem->mem_syn2_flt, hLPDmem->mem_syn_flt, ENC );
                    synth_mem_updt2( st->L_frame, st->last_L_frame, hLPDmem->old_exc, hLPDmem->mem_syn_r, hLPDmem->mem_syn2, hLPDmem->mem_syn, ENC );
                    lsp2a_stab( st->lsp_old, A, M );
#else
                    E_LPC_f_lsp_a_conversion( st->lsp_old_fx, A_fx, M );
#ifdef IVAS_FLOAT_FIXED_CONVERSIONS
                    fixedToFloat_arr( A_fx, A, Q14 - norm_s( A_fx[0] ), M + 1 );
#endif
#endif
#ifndef IVAS_FLOAT_FIXED
                    weight_a( A, Ap, GAMMA1_FLT, M );
                    weight_a( A, Ap, GAMMA1, M );
                    tmp = 0.f;
                    tmp_buf[0] = 0.f;
                    mvr2r( hLPDmem->mem_syn2_flt, tmp_buf + 1, M );
                    deemph( tmp_buf + 1, st->preemph_fac_flt, M, &tmp );
                    mvr2r( hLPDmem->mem_syn2, tmp_buf + 1, M );
                    deemph( tmp_buf + 1, st->preemph_fac, M, &tmp );
                    residu( Ap, M, tmp_buf + M, &tmp, 1 );
                    hLPDmem->mem_w0_flt = st->wspeech_enc_flt[-1] - tmp;
#endif
                    hLPDmem->mem_w0 = st->wspeech_enc[-1] - tmp;
                }
            }
            else if ( st->L_frame != L_frame_old ) /* Rate switching involving TCX only modes */
@@ -1385,28 +1294,22 @@ static void init_acelp(
                /*reset partly some memories*/
                if ( hLPDmem != NULL )
                {
#ifndef IVAS_FLOAT_FIXED
                    hLPDmem->tilt_code_flt = TILT_CODE_FLT;
                    set_zero( hLPDmem->old_exc_flt, L_EXC_MEM );
#else
                    hLPDmem->tilt_code = TILT_CODE;
#endif
#ifndef IVAS_FLOAT_FIXED
                    set_zero( hLPDmem->old_exc, L_EXC_MEM );

                    /*Resamp others memories*/
                    /*Size of LPC syn memory*/
                    mem_syn_r_size_old = (int16_t) ( 1.25 * L_frame_old / 20.f );
                    mem_syn_r_size_new = (int16_t) ( 1.25 * st->L_frame / 20.f );
                    lerp_flt( hLPDmem->mem_syn_r_flt + L_SYN_MEM - mem_syn_r_size_old, hLPDmem->mem_syn_r_flt + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old );
                    mvr2r( hLPDmem->mem_syn_r_flt + L_SYN_MEM - M, hLPDmem->mem_syn_flt, M );
                    mvr2r( hLPDmem->mem_syn_flt, hLPDmem->mem_syn2_flt, M );
                    lerp( hLPDmem->mem_syn_r + L_SYN_MEM - mem_syn_r_size_old, hLPDmem->mem_syn_r + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old );
                    mvr2r( hLPDmem->mem_syn_r + L_SYN_MEM - M, hLPDmem->mem_syn, M );
                    mvr2r( hLPDmem->mem_syn, hLPDmem->mem_syn2, M );

                    /*Untouched memories : LPDmem->syn & LPDmem->mem_w0_flt*/
                    hLPDmem->mem_w0_flt = 0;
#endif
                    /*Untouched memories : LPDmem->syn & LPDmem->mem_w0*/
                    hLPDmem->mem_w0 = 0;
                }

                /* unquantized LPC*/
#ifndef IVAS_FLOAT_FIXED
                mvr2r( st->lsp_old1, st->lspold_enc, M ); /*lsp old @12.8kHz*/
                if ( st->L_frame == L_FRAME16k )
                {
@@ -1414,22 +1317,6 @@ static void init_acelp(
                }
                mvr2r( st->lspold_enc, st->lsp_old, M ); /*used unquantized values for mid-LSF Q*/
                lsp2lsf( st->lsp_old, st->lsf_old, M, st->sr_core );
#else
                Copy( st->lsp_old1_fx, st->lspold_enc_fx, M ); /*lsp old @12.8kHz*/
                IF( EQ_16( st->L_frame, L_FRAME16k ) )
                {
                    lsp_convert_poly_fx( st->lspold_enc_fx, st->L_frame, 0 );
                }
                Copy( st->lspold_enc_fx, st->lsp_old_fx, M ); /*used unquantized values for mid-LSF Q*/
                IF( st->tcxonly == 0 )
                {
                    lsp2lsf_fx( st->lsp_old_fx, st->lsf_old_fx, M, st->sr_core );
                }
                ELSE
                {
                    E_LPC_lsp_lsf_conversion( st->lsp_old_fx, st->lsf_old_fx, M );
                }
#endif
            }
            /* necessary in BASOP only, due to different representations of st->lsf_old */
            /* else if ( !st->tcxonly && (st->L_frame == L_FRAME16k) && (st->last_total_brate > ACELP_32k) ) */
@@ -1447,22 +1334,8 @@ static void init_acelp(
    /* Post-processing */
    if ( hLPDmem != NULL )
    {
#ifndef IVAS_FLOAT_FIXED
        set_zero( hLPDmem->dispMem_flt, 8 );
        hLPDmem->gc_threshold_flt = 0.0f;
#else
        hLPDmem->dm_fx.prev_state = 0;
        move16(); /* This corresponds to st_fx->dispMem in FLP */
        hLPDmem->dm_fx.prev_gain_code = 0;
        move32();

        FOR( Word16 i = 2; i < 8; i++ )
        {
            hLPDmem->dm_fx.prev_gain_pit[i - 2] = 0;
            move16();
        }
        hLPDmem->gc_threshold = 0;
#endif
        set_zero( hLPDmem->dispMem, 8 );
        hLPDmem->gc_threshold = 0.0f;
    }

    /* Pulse Search configuration */
@@ -1475,7 +1348,6 @@ static void init_acelp(
    }

    /*BPF parameters for adjusting gain in function of background noise*/
#ifndef IVAS_FLOAT_FIXED
    if ( st->codec_mode == MODE2 )
    {
        st->pst_lp_ener = 0.0f;
@@ -1484,26 +1356,12 @@ static void init_acelp(
            st->pst_mem_deemp_err = 0.0f;
        }
    }
#else
    IF( EQ_16( st->codec_mode, MODE2 ) )
    {
        st->mem_bpf_fx.lp_error_ener = L_deposit_l( 0 );
        st->pst_lp_ener_fx = 0;
        move16();
        if ( EQ_16( st->last_codec_mode, MODE1 ) )
        {
            st->mem_bpf_fx.lp_error = L_deposit_l( 0 );
            st->pst_mem_deemp_err_fx = 0;
            move16();
        }
    }
#endif


    return;
}

#ifdef IVAS_FLOAT_FIXED
#else
static void init_acelp_ivas_fx( Encoder_State *st, Word16 L_frame_old, Word16 shift )
{
    Word16 mem_syn_r_size_old;
@@ -1782,7 +1640,7 @@ static void init_acelp_ivas_fx( Encoder_State *st, Word16 L_frame_old, Word16 sh
    /*Use for 12.8 kHz sampling rate and low bitrates, the conventional pulse search->better SNR*/
    test();
    test();
    if ( ( LE_32( st->total_brate, ACELP_9k60 ) || st->rf_mode != 0 ) && ( EQ_32( st->sr_core, 12800 ) ) )
    if ( ( LE_32( st->total_brate, ACELP_9k60 ) || EQ_16( st->rf_mode, 1 ) ) && ( EQ_32( st->sr_core, 12800 ) ) )
    {
        st->acelp_autocorr = 0;
        move16();
+4 −0
Original line number Diff line number Diff line
@@ -822,7 +822,11 @@ void E_ACELP_4tsearchx_ivas_fx(
                alp = shr( alp, 1 );
                Scale_sig( cor, L_SUBFR, -1 );
                Scale_sig( R_buf, 2 * L_SUBFR - 1, -1 );
#ifndef MSAN_FIX
                Scale_sig( dn, 2 * L_SUBFR, -1 );
#else
                Scale_sig( dn, L_SUBFR, -1 );
#endif
            }


+5 −2
Original line number Diff line number Diff line
@@ -142,7 +142,7 @@ void hq_core_enc_ivas_fx(

        WindowSignal( st->hTcxCfg, st->hTcxCfg->tcx_offsetFB, TRANSITION_OVERLAP, FULL_OVERLAP, &left_overlap, &right_overlap, st->hTcxEnc->speech_TCX, &L_spec, wtda_audio_fx16, 1, 1 );

        q = st->hTcxEnc->q_speech_TCX;
        q = 0;
        move16();
        Q_audio = sub( Q16, q );
        TCX_MDCT( wtda_audio_fx16, t_audio_fx, &Q_audio, left_overlap, sub( L_spec, shr( add( left_overlap, right_overlap ), 1 ) ), right_overlap, st->element_mode );
@@ -164,7 +164,10 @@ void hq_core_enc_ivas_fx(
         *--------------------------------------------------------------------------*/
        Q_audio = 0;
        move16();
        floatToFixed_arr( st->old_input_signal, st->old_input_signal_fx, 0, add( L_FRAME48k, add( L_FRAME48k, NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ) ) );
        Scale_sig( st->old_input_signal_fx, input_frame, negate( st->q_old_inp ) );
        Scale_sig( st->input_fx, add( input_frame, NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ), negate( st->q_inp ) );
        st->q_old_inp = 0;
        move16();
        st->q_inp = 0;
        move16();
        Copy( st->old_input_signal_fx, two_frames_buffer, input_frame );
Loading