Commit 4a11c0d8 authored by Mohammadreza Naghibzadeh's avatar Mohammadreza Naghibzadeh
Browse files

use a dynamic scaling factor for the synth buffer at the output of con_tcx_ivas_fx()

parent 07fb862e
Loading
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -94,6 +94,7 @@
#define FIX1998_APA_EXEC_SCALING                             /* FhG: fix scaling of apa_exec_ivas_fx(); avoid continuously worse scaling with previous data */

#define FIX_1962_FORMAT_CONV_SPECTRAL_DIFF                   /* FhG: Improved precision of targetEnergy in ivas_ls_setup_conversion_process_mdct_fx() */
#define FIX_2003_CON_TCX_OVERFLOW                            /* FhG: Use a dynamic scaling factor for the synth buffer at the output of con_tcx_ivas_fx() */
/* #################### Start BASOP porting switches ############################ */

#define NONBE_1244_FIX_SWB_BWE_MEMORY                   /* VA: issue 1244: fix to SWB BWE memory in case of switching from FB coding - pending a review by Huawei */
+60 −4
Original line number Diff line number Diff line
@@ -1082,18 +1082,33 @@ void con_tcx_ivas_fx(

    /* set excitation memory*/
    exc = buf + OLD_EXC_SIZE_DEC;
#ifdef FIX_2003_CON_TCX_OVERFLOW
    tmp_deemph = synth[-1]; /*st->Q_syn_factor*/
    move16();
    pre_emph_buf = synth[-1]; /*st->Q_syn_factor*/
    move16();
#else
    tmp_deemph = synth[-1];                                                                                     /*Q0*/
    move16();
    pre_emph_buf = synth[-1]; /*Q0*/
    move16();
#endif

    test();
    IF( ( EQ_16( st->nbLostCmpt, 1 ) ) || hTcxDec->tcxConceal_recalc_exc )
    {
        /* apply pre-emphasis to the signal */
#ifdef FIX_2003_CON_TCX_OVERFLOW
        mem = shl( synth[( -( ( ( L_frame / 2 ) + hTcxDec->pit_max_TCX ) + M + M ) - 1 )], st->Q_syn_factor );
#else
        mem = synth[( -( ( ( L_frame / 2 ) + hTcxDec->pit_max_TCX ) + M + M ) - 1 )]; /*Q0*/
#endif
        move16();
        Q_exc = E_UTIL_f_preemph3_ivas_fx( &( synth[-( ( ( L_frame / 2 ) + hTcxDec->pit_max_TCX ) + 2 * M )] ), st->preemph_fac, add( add( shr( L_frame, 1 ), hTcxDec->pit_max_TCX ), shl( M, 1 ) ), &mem, 1 );

#ifdef FIX_2003_CON_TCX_OVERFLOW
        scale_sig( &( synth[-( ( ( L_frame / 2 ) + hTcxDec->pit_max_TCX ) + 2 * M )] ), add( add( shr( L_frame, 1 ), hTcxDec->pit_max_TCX ), shl( M, 1 ) ), negate( st->Q_syn_factor ) ); /*Q0*/
#endif

        st->Mode2_lp_gainc = L_deposit_l( 0 );

        st->Mode2_lp_gainp = get_gain2( synth - shl( L_subfr, 1 ), synth - add( shl( L_subfr, 1 ), Tc ), shl( L_subfr, 1 ) );
@@ -1136,9 +1151,16 @@ void con_tcx_ivas_fx(
    ELSE
    {
        /* apply pre-emphasis to the signal */
#ifdef FIX_2003_CON_TCX_OVERFLOW
        mem = shl( synth[( -L_frame - 1 )], st->Q_syn_factor ); /*hTcxDec->Q_synth_factor_old*/
#else
        mem = synth[( -L_frame - 1 )]; /*Q0*/
#endif
        move16();
        Q_exc = E_UTIL_f_preemph3_ivas_fx( &( synth[-L_frame] ), st->preemph_fac, L_frame, &mem, 1 );
#ifdef FIX_2003_CON_TCX_OVERFLOW
        scale_sig( &synth[-L_frame], L_frame, negate( st->Q_syn_factor ) ); /*Q0*/
#endif
        Copy( st->old_Aq_12_8_fx, A_local, M + 1 ); /*Q14*/

        offset = shr( L_frame, 1 );
@@ -1754,7 +1776,11 @@ void con_tcx_ivas_fx(
    syn = buf + M;             /*Q_syn*/
    Copy( synth - M, buf, M ); /*Q_syn*/

#ifdef FIX_2003_CON_TCX_OVERFLOW
    new_Q = sub( Q_exc, 4 ) ;
#else
    new_Q = sub( Q_exc, 3 );
#endif
    new_Q = s_max( new_Q, -1 );
    new_Q = s_min( new_Q, norm_s( tmp_deemph ) );

@@ -1767,8 +1793,18 @@ void con_tcx_ivas_fx(
    move16();

    Copy_Scale_sig( buf, mem_syn, M, exp_scale ); /* Q: tmp16 */

#ifdef FIX_2003_CON_TCX_OVERFLOW
    if ( LT_16( Q_syn, norm_s( tmp_deemph ) ) )
    {
        tmp_deemph = shl( tmp_deemph, sub( Q_syn, st->Q_syn_factor ) );
    }
    else
    {
        Q_syn = sub( norm_s( tmp_deemph ), st->Q_syn_factor );
    }
#else
    tmp_deemph = shl_sat( tmp_deemph, Q_syn );
#endif
    st->Q_syn = Q_syn;
    move16();

@@ -1833,8 +1869,9 @@ void con_tcx_ivas_fx(

    /* Deemphasis and output synth and ZIR */
    deemph_fx( syn, st->preemph_fac, add( L_frame, shr( L_frame, 1 ) ), &tmp_deemph );
#ifndef FIX_2003_CON_TCX_OVERFLOW
    bufferCopyFx( syn + sub( L_frame, M + 1 ), st->syn, 1 + M, Q_syn, 0, 0, 0 ); /*Q_syn*/

#endif

    lerp( syn + sub( L_frame, shr( L_frame, 1 ) ), hTcxDec->old_syn_Overl, shr( st->L_frame, 1 ), shr( L_frame, 1 ) );
    hTcxDec->Q_old_syn_Overl = Q_syn;
@@ -1857,6 +1894,24 @@ void con_tcx_ivas_fx(
    hHQ_core->Q_old_wtda = Q_syn;
    move16();

#ifdef FIX_2003_CON_TCX_OVERFLOW
    Word16 scf = add( getScaleFactor32( syn, L_frame ), Q_syn );
    IF ( LT_16(scf, 0) )
    {
        st->Q_syn_factor = scf;
    }
    ELSE
    {
        st->Q_syn_factor = 0;
        move16();
    }
    bufferCopyFx( syn, synth, L_frame, Q_syn, st->Q_syn_factor, 0, 0 );

    bufferCopyFx( syn + sub( L_frame, M + 1 ), st->syn, 1 + M, Q_syn, st->Q_syn_factor, 0, 0 );

    Copy_Scale_sig( syn + L_frame, hTcxDec->syn_OverlFB, shr( L_frame, 1 ), sub( st->Q_syn_factor, Q_syn ) );
    hTcxDec->Q_syn_OverlFB = st->Q_syn_factor;
#else
    /* As long as there is no synth scaling factor introduced, which
    is given to the outside, there might occur overflows here */
    BASOP_SATURATE_WARNING_OFF_EVS
@@ -1866,6 +1921,7 @@ void con_tcx_ivas_fx(
    Copy_Scale_sig( syn + L_frame, hTcxDec->syn_OverlFB, shr( L_frame, 1 ), sub( 0, Q_syn ) ); /*Q0*/
    hTcxDec->Q_syn_OverlFB = 0;
    move16();
#endif

    /* copy total excitation exc2 as 16kHz for acelp mode1 decoding */
    IF( st->hWIDec != NULL )
+8 −0
Original line number Diff line number Diff line
@@ -1184,6 +1184,10 @@ void ivas_mdct_core_reconstruct_fx(
        set16_fx( synthFB_fx, 0, L_FRAME_PLUS + M );
        IF( st->core != ACELP_CORE )
        {
#ifdef FIX_2003_CON_TCX_OVERFLOW
            st->Q_syn_factor = 0;
            move16();
#endif
            Word16 q_win0 = Q15;
            move16();
            Word16 q_winFB0 = Q15;
@@ -1419,7 +1423,11 @@ void ivas_mdct_core_reconstruct_fx(
        IF( signal_outFB_fx[ch] != NULL )
        {
            Copy( synthFB_fx, signal_outFB_fx[ch], st->hTcxDec->L_frameTCX );
#ifdef FIX_2003_CON_TCX_OVERFLOW
            e_sig[ch] = sub( 15, q_syn + st->Q_syn_factor );
#else
            e_sig[ch] = sub( 15, q_syn );
#endif
            move16();
        }

+3 −0
Original line number Diff line number Diff line
@@ -1310,6 +1310,9 @@ typedef struct Decoder_State
    Word16 Q_syn;
    Word16 Q_syn2;
    Word16 Q_syn_cng;
#ifdef FIX_2003_CON_TCX_OVERFLOW
    Word16 Q_syn_factor;
#endif
    Word16 prev_Q_syn;
    Word16 prev_Q_bwe_exc;