Commit 437d10e8 authored by Manuel Jander's avatar Manuel Jander
Browse files

Add NONBE_FIX_ISSUE_2518_TRANSENC_SAT_FIX to fix saturation inside transf_cdbk_enc_fx().

parent 8af4aa5e
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -92,7 +92,6 @@
#define NONBE_FIX_ISSUE_2206_AVOID_OVERFLOW_MSVQ_Interpol_Tran_fx /* FhG: Fix saturation crash in MSVQ_Interpol_Tran_fx() */
#define NONBE_FIX_ISSUE_2206_SWB_EXPERIMENT_FIX_2527    /* Fix crash from issue #2527 */
#define NONBE_FIX_2507                                  /* Fix porting error in SQ_gain_estimate_fx() */
#define NONBE_FIX_ISSUE_2518                            /* FhG: Fix issue 2518, noise during ACELP switching from 16KHz to 12k8Hz by improving Q_new calculation. */
#define FIX_FLOAT_1539_G192_FORMAT_SWITCH               /* VA/Nokia: reintroduce format switching for g192 bitstreams */
#define HARMONIZE_2499_CONFIGUREFDCNGDEC                /* FhG: basop issue 2499: harmonoize configureFdCngDec */
#define FIX_BASOP_2530_IVAS_DECISION_MAT                /* VA: Fix ambiguous usage of extract_l() */
@@ -147,6 +146,8 @@
#define FIX_FMSW_DEC_2                                  /* float issue 1575: fix crash for format switching when bitsream starts with EVS */
#define FIX_BASOP_2561_STEREO_DFT_ENC_COMPUTE_ITD       /* BASOP issue 2561: fix diffs in stereo_dft_enc_compute_itd() between float and BASOP */
#define FIX_BASOP_2517_CLICK_IN_OMASA_LTV               /* FhG: BASOP #2517: preserve precision by removing one-bit headroom from Q_min and allowing saturation during buffer scaling */
#define NONBE_FIX_ISSUE_2518                            /* FhG: Fix issue 2518, noise during ACELP switching from 16KHz to 12k8Hz by improving Q_new calculation. */
#define NONBE_FIX_ISSUE_2518_TRANSENC_SAT_FIX           /* FhG: Fix issue 2518, fix wrong amplitude because of saturation of x_tran in transf_cdbk_enc_fx() for transient signals. */
#define FIX_BASOP_2559_Q_SYNTH_HISTORY_RESET            /* FhG: BASOP issue 2559: reset hTcxDec->q_synth_history_fx in allocate_CoreCoder_TCX_fx() */
#define FIX_FLOAT_1578_OMASA_REND_SPIKES                /* Nokia: Float issue 1578: Fix spikes and collapsed perception in OMASA/MASA rendering to FOA/HOA */

+44 −0
Original line number Diff line number Diff line
@@ -301,11 +301,17 @@ void transf_cdbk_enc_fx(
     * DCT transform
     *--------------------------------------------------------------*/

#ifdef NONBE_FIX_ISSUE_2518_TRANSENC_SAT_FIX
    Word16 q_x_tran;
    q_x_tran = s_min( Q_AVQ_OUT_DEC, norm_arr( x_norm, Nsv * WIDTH_BAND ) );
    Copy_Scale_sig_nosat( x_norm, x_tran, Nsv * WIDTH_BAND, q_x_tran );
#else
    FOR( i = 0; i < Nsv * WIDTH_BAND; i++ )
    {
        x_tran[i] = shl_sat( x_norm[i], Q_AVQ_OUT_DEC );
        move16();
    }
#endif

    test();
    test();
@@ -321,8 +327,13 @@ void transf_cdbk_enc_fx(
        edct2_fx( L_SUBFR, 1, x_tran, out32, &Qdct, ip_edct2_64, w_edct2_64_fx );
        /*qdct = sub(Q_AVQ_OUT_DEC,qdct+Q_AVQ_OUT_DEC);*/
        Qdct = negate( Qdct );
#ifdef NONBE_FIX_ISSUE_2518_TRANSENC_SAT_FIX
        Copy_Scale_sig_32_16( out32, code_preQ, L_SUBFR, Qdct ); /* Output in q_x_tran */
        /*qdct = q_x_tran;*/
#else
        Copy_Scale_sig_32_16( out32, code_preQ, L_SUBFR, Qdct ); /* Output in Q_AVQ_OUT_DEC */
        /*qdct = Q_AVQ_OUT_DEC;*/
#endif
    }

    /*--------------------------------------------------------------*
@@ -348,22 +359,41 @@ void transf_cdbk_enc_fx(
    test();
    IF( GT_16( st_fx->element_mode, EVS_MONO ) && NE_16( st_fx->coder_type, INACTIVE ) && GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) && LE_32( st_fx->core_brate, MAX_BRATE_AVQ_EXC_TD ) && !harm_flag_acelp && code_preQ[0] != 0 )
    {
#ifdef NONBE_FIX_ISSUE_2518_TRANSENC_SAT_FIX
        IF( GT_16( abs_s( st_fx->last_code_preq ), shl_sat( abs_s( code_preQ[0] ), sub( Q_AVQ_OUT_DEC + 4,  q_x_tran ) ) ) )
#else
        IF( GT_16( abs_s( st_fx->last_code_preq ), shl_sat( abs_s( code_preQ[0] ), 4 ) ) )
#endif
        {
            st_fx->mem_preemp_preQ_fx = shr( st_fx->mem_preemp_preQ_fx, 4 );
            move16();
        }
#ifdef NONBE_FIX_ISSUE_2518_TRANSENC_SAT_FIX
        ELSE IF( GT_16( abs_s( st_fx->last_code_preq ), shl_sat( abs_s( code_preQ[0] ), sub( Q_AVQ_OUT_DEC + 3, q_x_tran ) ) ) )
#else
        ELSE IF( GT_16( abs_s( st_fx->last_code_preq ), shl_sat( abs_s( code_preQ[0] ), 3 ) ) )
#endif
        {
            st_fx->mem_preemp_preQ_fx = shr( st_fx->mem_preemp_preQ_fx, 3 );
            move16();
        }
    }

#ifdef NONBE_FIX_ISSUE_2518_TRANSENC_SAT_FIX
    st_fx->last_code_preq = shl_sat( code_preQ[L_SUBFR - 1], sub( 1, q_x_tran ) ); // Q0 ? Q1
    move16();

    st_fx->mem_preemp_preQ_fx = shl_sat( st_fx->mem_preemp_preQ_fx, sub( q_x_tran, Q_AVQ_OUT_DEC ) );
    move16();
    preemph_fx( code_preQ, FAC_PRE_AVQ_FX, L_SUBFR, &( st_fx->mem_preemp_preQ_fx ) );
    st_fx->mem_preemp_preQ_fx = shl_sat(  st_fx->mem_preemp_preQ_fx, sub( Q_AVQ_OUT_DEC, q_x_tran ) );
    move16();
#else
    st_fx->last_code_preq = shr( code_preQ[L_SUBFR - 1], 9 ); // Q0
    move16();

    preemph_fx( code_preQ, FAC_PRE_AVQ_FX, L_SUBFR, &( st_fx->mem_preemp_preQ_fx ) );
#endif

    /*--------------------------------------------------------------*
     * For inactive segments
@@ -376,22 +406,36 @@ void transf_cdbk_enc_fx(
    IF( EQ_16( st_fx->coder_type, INACTIVE ) )
    {
        /*ftemp = fcode_preQ[0] *fh1[L_SUBFR-1];*/
#ifdef NONBE_FIX_ISSUE_2518_TRANSENC_SAT_FIX
        Ltmp = L_mult( code_preQ[0], h1[L_SUBFR - 1] ); /*1+14+shift + q_x_tran */
#else
        Ltmp = L_mult( code_preQ[0], h1[L_SUBFR - 1] ); /*1+14+shift + Q_AVQ_OUT */
#endif
        FOR( i = 1; i < L_SUBFR; i++ )
        {
            /*ftemp += fcode_preQ[i] * fh1[L_SUBFR-1-i];*/
            Ltmp = L_mac( Ltmp, code_preQ[i], h1[L_SUBFR - 1 - i] );
        }
        /*fxn[L_SUBFR-1] -= *fgain_preQ * ftemp;*/
#ifdef NONBE_FIX_ISSUE_2518_TRANSENC_SAT_FIX
        Ltmp = L_shr( Mult_32_16( Ltmp, *gain_preQ ), sub( add( q_x_tran, 2 ), Q_new ) ); /* (2 + 1 + 14 +shift+Q_AVQ_OUT)-(Q_AVQ_OUT+2-Q_new) = 15 + Q_new + shift */
#else
        Ltmp = L_shr( Mult_32_16( Ltmp, *gain_preQ ), sub( add( Q_AVQ_OUT_DEC, 2 ), Q_new ) ); /* (2 + 1 + 14 +shift+Q_AVQ_OUT)-(Q_AVQ_OUT+2-Q_new) = 15 + Q_new + shift */
#endif
        xn[L_SUBFR - 1] = round_fx( L_sub( L_mult( xn[L_SUBFR - 1], 32767 ), Ltmp ) );         /* -> Q_new + shift -1 */
    }
    ELSE
    {
        conv_fx( code_preQ, h1, x_tran, L_SUBFR );
#ifdef NONBE_FIX_ISSUE_2518_TRANSENC_SAT_FIX
        updt_tar_HR_fx( cn, cn, code_preQ, *gain_preQ, sub( Q_new, add( -15 + 2, q_x_tran ) ), L_SUBFR );

        updt_tar_HR_fx( xn, xn, x_tran, *gain_preQ, sub( Q_new, add( -15 + 2, q_x_tran ) ), L_SUBFR );
#else
        updt_tar_HR_fx( cn, cn, code_preQ, *gain_preQ, sub( Q_new, add( -15 + 2, Q_AVQ_OUT_DEC ) ), L_SUBFR );

        updt_tar_HR_fx( xn, xn, x_tran, *gain_preQ, sub( Q_new, add( -15 + 2, Q_AVQ_OUT_DEC ) ), L_SUBFR );
#endif
        *gain_pit = corr_xy1_fx( xn, y1, g_corr, L_SUBFR, 0, &Overflow ); /* Q14 */
        move16();
        /* clip gain if necessary to avoid problems at decoder */