Commit a0ad7dec authored by Mohammadreza Naghibzadeh's avatar Mohammadreza Naghibzadeh
Browse files

modified tmp_deemph scaling and added some comments.

parent 1ecfca0b
Loading
Loading
Loading
Loading
Loading
+17 −11
Original line number Diff line number Diff line
@@ -1007,7 +1007,11 @@ void con_tcx_ivas_fx(
    Word16 pre_emph_buf;
    Word16 hp_filt[L_FIR_FER2];
    Word16 alpha;
#ifdef FIX_2003_CON_TCX_OVERFLOW
    Word16 tmp_deemph, gain, gainCNG, gain_inov, scf;
#else
    Word16 tmp_deemph, gain, gainCNG, gain_inov;
#endif
    Word16 *pt_exc, *pt1_exc;
    Word16 Tc, tmpSeed;
    Word16 fUseExtrapolatedPitch;
@@ -1106,7 +1110,7 @@ void con_tcx_ivas_fx(
        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*/
        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, Setting back to Q0, as the following calculations are implemented assuming synth is in Q0 */
#endif

        st->Mode2_lp_gainc = L_deposit_l( 0 );
@@ -1159,7 +1163,7 @@ void con_tcx_ivas_fx(
        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*/
        scale_sig( &synth[-L_frame], L_frame, negate( st->Q_syn_factor ) ); /*Q0, Setting back to Q0, as the following calculations are implemented assuming synth is in Q0 */
#endif
        Copy( st->old_Aq_12_8_fx, A_local, M + 1 ); /*Q14*/

@@ -1777,12 +1781,17 @@ void con_tcx_ivas_fx(
    Copy( synth - M, buf, M ); /*Q_syn*/

#ifdef FIX_2003_CON_TCX_OVERFLOW
    new_Q = sub( Q_exc, 4 );
    scf = norm_s( tmp_deemph );
    new_Q = sub( Q_exc, 4 ); // deemph_fx filter gain can be up to 10 (~2^3.32), so 4 bits of headroom are needed to avoid overflow
#else
    new_Q = sub( Q_exc, 3 );
#endif
    new_Q = s_max( new_Q, -1 );
#ifdef FIX_2003_CON_TCX_OVERFLOW
    new_Q = s_min( new_Q, scf );
#else
    new_Q = s_min( new_Q, norm_s( tmp_deemph ) );
#endif

    tmp16 = s_min( new_Q, st->prev_Q_syn );
    st->prev_Q_syn = new_Q;
@@ -1794,14 +1803,11 @@ void con_tcx_ivas_fx(

    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 ) ) )
    if ( GT_16( sub( Q_syn, st->Q_syn_factor ), scf ) )
    {
        tmp_deemph = shl( tmp_deemph, sub( Q_syn, st->Q_syn_factor ) );
    }
    else
    {
        Q_syn = sub( norm_s( tmp_deemph ), st->Q_syn_factor );
        Q_syn = add( scf, st->Q_syn_factor ); // so that (Q_syn - st->Q_syn_factor) = scf; 
    }
    tmp_deemph = shl( tmp_deemph, sub( Q_syn, st->Q_syn_factor ) );
#else
    tmp_deemph = shl_sat( tmp_deemph, Q_syn );
#endif
@@ -1895,8 +1901,8 @@ void con_tcx_ivas_fx(
    move16();

#ifdef FIX_2003_CON_TCX_OVERFLOW
    Word16 scf = add( getScaleFactor16( syn, L_frame ), Q_syn );
    IF( LT_16( scf, 0 ) )
    scf = add( getScaleFactor16( syn, L_frame ), Q_syn );
    IF( LT_16( scf, 0 ) ) // Only avoid left shift in bufferCopyFX when overflow could occur
    {
        st->Q_syn_factor = scf;
    }
+1 −1
Original line number Diff line number Diff line
@@ -1311,7 +1311,7 @@ typedef struct Decoder_State
    Word16 Q_syn2;
    Word16 Q_syn_cng;
#ifdef FIX_2003_CON_TCX_OVERFLOW
    Word16 Q_syn_factor;
    Word16 Q_syn_factor; // This q_factor is used to avoid using fixed Q0 for synth[] at the output of con_tcx_ivas_fx(). It is then used for two consecutive TCX concealment processes. It cannot be greater than 0.
#endif
    Word16 prev_Q_syn;
    Word16 prev_Q_bwe_exc;