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

Fix for 3GPP issue 1325: saturation occuring in tcx_encoder_memory_update_ivas_fx()

Link #1325
parent 41ec6b7e
Loading
Loading
Loading
Loading
Loading
+2 −16
Original line number Diff line number Diff line
@@ -570,23 +570,9 @@ void stereo_tcx_core_enc(
    move16();
    move16();

    /* Scaling old_exc buffer to Q_new */
    IF( NE_16( Q_new, Q_exc ) )
    {
        Scale_sig( st->hLPDmem->old_exc, L_EXC_MEM, sub( Q_new, Q_exc ) );
    }

    coder_tcx_post_ivas_fx( st, st->hLPDmem, st->hTcxCfg, st->synth, A_q_fx, Aw_fx, st->wspeech_enc, Q_new );

    /* Upscaling old_exc buffer */
    s = norm_arr( st->hLPDmem->old_exc, L_EXC_MEM ) - 1;
    Scale_sig( st->hLPDmem->old_exc, L_EXC_MEM, s );
    IF( st->hTdCngEnc != NULL )
    {
        Scale_sig( st->hTdCngEnc->cng_exc2_buf, HO_HIST_SIZE * L_FFT, sub( add( shl( Q_new, 1 ), s ), Q_exc ) );
    }
    Q_exc = add( shl( Q_new, 1 ), s ); // 2 * Q_new + s
    st->hLPDmem->q_lpd_old_exc = Q_exc;
    Q_exc = Q_new; // Q_new
    move16();

    IF( st->enableTcxLpc )
@@ -659,7 +645,7 @@ void stereo_tcx_core_enc(
        ELSE
        {
            cng_params_upd_ivas_fx( lsp_new_fx, st->hLPDmem->old_exc + L_EXC_MEM - st->L_frame, st->L_frame, &st->hTdCngEnc->ho_circ_ptr, st->hTdCngEnc->ho_ener_circ_fx, &st->hTdCngEnc->ho_circ_size,
                                    st->hTdCngEnc->ho_lsp_circ_fx, Q_exc, ENC, st->hTdCngEnc->ho_env_circ_fx, &st->hTdCngEnc->cng_buf_cnt, st->hTdCngEnc->cng_exc2_buf, st->hTdCngEnc->cng_Qexc_buf, st->hTdCngEnc->cng_brate_buf, st->hDtxEnc->last_active_brate, st->element_mode,
                                    st->hTdCngEnc->ho_lsp_circ_fx, st->hLPDmem->q_lpd_old_exc, ENC, st->hTdCngEnc->ho_env_circ_fx, &st->hTdCngEnc->cng_buf_cnt, st->hTdCngEnc->cng_exc2_buf, st->hTdCngEnc->cng_Qexc_buf, st->hTdCngEnc->cng_brate_buf, st->hDtxEnc->last_active_brate, st->element_mode,
                                    st->hFdCngEnc->hFdCngCom->CngBandwidth );
        }

+20 −6
Original line number Diff line number Diff line
@@ -2814,12 +2814,12 @@ void tcx_encoder_memory_update_ivas_fx(
    /* Emphasis of synth -> synth_pe */
    tmp = synth[-( M + 1 )];
    move16();
    E_UTIL_f_preemph2( Q_new - 1, synth - M, preemph, add( M, L_frame_glob ), &tmp );
    E_UTIL_f_preemph2( 0, synth - M, preemph, add( M, L_frame_glob ), &tmp ); // Q_new

    Copy( synth + sub( L_frame_glob, M ), LPDmem->mem_syn, M );
    Copy( synth + sub( L_frame_glob, M ), LPDmem->mem_syn2, M );
    Copy( synth + sub( L_frame_glob, L_SYN_MEM ), LPDmem->mem_syn_r, L_SYN_MEM );
    LPDmem->q_mem_syn = sub( shl( Q_new, 1 ), 1 ); // resultant q of synth after E_UTIL_f_preemph2
    LPDmem->q_mem_syn = Q_new; // resultant q of synth after E_UTIL_f_preemph2
    move16();

    test();
@@ -2828,13 +2828,27 @@ void tcx_encoder_memory_update_ivas_fx(
        /* Update excitation */
        IF( LT_16( L_frame_glob, L_EXC_MEM ) )
        {
            Copy( LPDmem->old_exc + L_frame_glob, LPDmem->old_exc, sub( L_EXC_MEM, L_frame_glob ) );
            Scale_sig( LPDmem->old_exc, sub( L_EXC_MEM, L_frame_glob ), Q_new );                       // Q_new->2*Q_new
            Residu3_fx( A, synth, LPDmem->old_exc + sub( L_EXC_MEM, L_frame_glob ), L_frame_glob, 1 ); // 2*Q_new
            Word16 shift = norm_arr( LPDmem->old_exc + L_frame_glob, sub( L_EXC_MEM, L_frame_glob ) );
            IF( LT_16( shift, sub( Q_new, LPDmem->q_lpd_old_exc ) ) )
            {
                Copy_Scale_sig( LPDmem->old_exc + L_frame_glob, LPDmem->old_exc, sub( L_EXC_MEM, L_frame_glob ), shift );
                LPDmem->q_lpd_old_exc = add( LPDmem->q_lpd_old_exc, shift );
                move16();
                Residu3_fx( A, synth, LPDmem->old_exc + sub( L_EXC_MEM, L_frame_glob ), L_frame_glob, sub( LPDmem->q_lpd_old_exc, Q_new ) ); // LPDmem->q_lpd_old_exc
            }
            ELSE
            {
                Copy_Scale_sig( LPDmem->old_exc + L_frame_glob, LPDmem->old_exc, sub( L_EXC_MEM, L_frame_glob ), sub( Q_new, LPDmem->q_lpd_old_exc ) );
                Residu3_fx( A, synth, LPDmem->old_exc + sub( L_EXC_MEM, L_frame_glob ), L_frame_glob, 0 ); // Q_new
                LPDmem->q_lpd_old_exc = Q_new;
                move16();
            }
        }
        ELSE
        {
            Residu3_fx( A, synth + sub( L_frame_glob, L_EXC_MEM ), LPDmem->old_exc, L_EXC_MEM, 1 ); // 2*Q_new
            Residu3_fx( A, synth + sub( L_frame_glob, L_EXC_MEM ), LPDmem->old_exc, L_EXC_MEM, 0 ); // Q_new
            LPDmem->q_lpd_old_exc = Q_new;
            move16();
        }
    }
}