Commit 8eaac72a authored by vaillancour's avatar vaillancour
Browse files

First version of BE changes

parent 04c6120f
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -91,6 +91,20 @@
#define FIX_1822

#define FIX_ISSUE_1764                       /* NTT: update renorm and use abs */
//#define EVS_BE_REUSAGE
#ifdef EVS_BE_REUSAGE
#define REUSE_EVS_BE_ACELP_LP_FILT
#define REUSE_EVS_BE_ACELP_4T64
#define REUSE_EVS_BE_ACELP_2t32
#define REUSE_EVS_BE_ACELP_1t64
#define REUSE_EVS_BE_ACELP_AVQ
#define REUSE_EVS_BE_GAUSS           
#define REUSE_EVS_BE_GAINQ          
#define REUSE_EVS_BE_ACELP_PITCH
#define REUSE_EVS_BE_ACELP_PITCH_PIT_Q
#define REUSE_EVS_BE_GAINQ_LBR   // BE by adding one condition, but could be harmonized in a non-BE way. There is a small difference in how Etot is computed

#endif
#define FIX_ISSUE_1817_REPLACE_CARRY_OVERFLOW  /* FhG: bit-exact, replace carry and overflow operations by 64-bit operations, MR 1931 */
#define FIX_1844_MISSING_FREE                                /* FhG: add missing free in ivas_binRenderer_convModuleClose_fx() */

+31 −6
Original line number Diff line number Diff line
@@ -412,7 +412,11 @@ static void encod_gen_voic_core_switch_fx(
     *----------------------------------------------------------------*/
    set16_fx( dummyF, -1, NB_SUBFR16k ); /* hack to signal ACELP->HQ switching frame */
    pitch = pit_encode_fx( hBstr,
                           st_fx->acelp_cfg.pitch_bits, core_bitrate, 0, L_frame, GENERIC, &pitch_limit_flag, 0, exc, L_SUBFR, T_op, &T0_min, &T0_max, &T0, &T0_frac, h1, xn, 0 /*hStereoTD->tdm_Pitch_reuse_flag*/, dummyF /*hStereoTD->tdm_Pri_pitch_buf*/ ); /* Q6 */
                           st_fx->acelp_cfg.pitch_bits, core_bitrate, 0, L_frame, GENERIC, &pitch_limit_flag, 0, exc, L_SUBFR, T_op, &T0_min, &T0_max, &T0, &T0_frac, h1, xn, 0 /*hStereoTD->tdm_Pitch_reuse_flag*/, dummyF /*hStereoTD->tdm_Pri_pitch_buf*/
#if defined REUSE_EVS_BE_ACELP_PITCH && !defined REUSE_EVS_ACELP_PITCH_NORM_CORR
                                   , st_fx->element_mode, Q_new
#endif 
    ); /* Q6 */

    /*-----------------------------------------------------------------*
     * Find adaptive exitation
@@ -618,10 +622,17 @@ static void encod_gen_voic_core_switch_ivas_fx(
     * Adaptive exc. construction
     *----------------------------------------------------------------*/
    set16_fx( dummyF, -1, NB_SUBFR16k ); /* hack to signal ACELP->HQ switching frame */

#ifndef REUSE_EVS_BE_ACELP_PITCH
    pitch = pit_encode_ivas_fx( hBstr,
                                st_fx->acelp_cfg.pitch_bits, core_bitrate, 0, L_frame, GENERIC, &pitch_limit_flag, 0, exc, L_SUBFR, T_op, &T0_min, &T0_max, &T0, &T0_frac, h1, xn, 0 /*hStereoTD->tdm_Pitch_reuse_flag*/, dummyF /*hStereoTD->tdm_Pri_pitch_buf*/, Q_new ); /* Q6 */

#else
    pitch = pit_encode_fx( hBstr,
                                st_fx->acelp_cfg.pitch_bits, core_bitrate, 0, L_frame, GENERIC, &pitch_limit_flag, 0, exc, L_SUBFR, T_op, &T0_min, &T0_max, &T0, &T0_frac, h1, xn, 0 /*hStereoTD->tdm_Pitch_reuse_flag*/, dummyF /*hStereoTD->tdm_Pri_pitch_buf*/
#if defined REUSE_EVS_BE_ACELP_PITCH && !defined REUSE_EVS_ACELP_PITCH_NORM_CORR
                           , st_fx->element_mode, Q_new
#endif    
    ); /* Q6 */
#endif
    /*-----------------------------------------------------------------*
     * Find adaptive exitation
     *-----------------------------------------------------------------*/
@@ -640,8 +651,11 @@ static void encod_gen_voic_core_switch_ivas_fx(
     *-----------------------------------------------------------------*/
    lp_flag = st_fx->acelp_cfg.ltf_mode;                                                                                                      /* Q0 */
    Scale_sig( h1, L_SUBFR, sub( 14, q_h1 ) );                                                                                                /* set h1[] in Q14 with scaling for convolution Q14+shift*/
#ifdef REUSE_EVS_BE_ACELP_LP_FILT
    lp_select = lp_filt_exc_enc_fx( MODE1, GENERIC, 0, exc, h1, xn, y1, xn2, L_SUBFR, L_frame, g_corr, clip_gain, &gain_pit, &lp_flag ); /* Q0 */
#else
    lp_select = lp_filt_exc_enc_ivas_fx( MODE1, GENERIC, 0, exc, h1, xn, y1, xn2, L_SUBFR, L_frame, g_corr, clip_gain, &gain_pit, &lp_flag ); /* Q0 */

#endif
    IF( EQ_16( lp_flag, NORMAL_OPERATION ) )
    {
        push_indice( hBstr, IND_LP_FILT_SELECT, lp_select, 1 );
@@ -657,6 +671,7 @@ static void encod_gen_voic_core_switch_ivas_fx(
    /*-----------------------------------------------------------------*
     * Gain encoding
     *-----------------------------------------------------------------*/
#ifndef REUSE_EVS_BE_GAINQ
    IF( EQ_16( L_frame, L_FRAME ) )
    {
        gain_enc_mless_ivas_fx( hBstr, st_fx->acelp_cfg.gains_mode, st_fx->element_mode, L_frame, 0, -1, xn, y1, shift_wsp, y2, code, st_fx->old_Es_pred_fx,
@@ -667,7 +682,18 @@ static void encod_gen_voic_core_switch_ivas_fx(
        gain_enc_mless_ivas_fx( hBstr, st_fx->acelp_cfg.gains_mode, st_fx->element_mode, L_frame, 0, -1, xn, y1, shift_wsp, y2, code, st_fx->old_Es_pred_fx,
                                &gain_pit, &gain_code, &gain_inov, &norm_gain_code, g_corr, clip_gain );
    }

#else
    IF( EQ_16( L_frame, L_FRAME ) )
    {
        gain_enc_mless_fx( hBstr, st_fx->acelp_cfg.gains_mode, st_fx->element_mode, L_frame, 0, -1, xn, y1, shift_wsp, y2, code, st_fx->old_Es_pred_fx,
                                &gain_pit, &gain_code, &gain_inov, &norm_gain_code, g_corr, clip_gain );
    }
    ELSE
    {
        gain_enc_mless_fx( hBstr, st_fx->acelp_cfg.gains_mode, st_fx->element_mode, L_frame, 0, -1, xn, y1, shift_wsp, y2, code, st_fx->old_Es_pred_fx,
                                &gain_pit, &gain_code, &gain_inov, &norm_gain_code, g_corr, clip_gain );
    }
#endif
    gp_clip_test_gain_pit_fx( st_fx->element_mode, core_bitrate, gain_pit, st_fx->clip_var_fx );

    Lgcode = L_shl( gain_code, Q_new ); /* scaled gain_code with Qnew -> Q16*/
@@ -713,7 +739,6 @@ static void encod_gen_voic_core_switch_ivas_fx(
    return;
}


/*-------------------------------------------------------------------*
 * bwe_switch_enc()
 *
+53 −3
Original line number Diff line number Diff line
@@ -182,7 +182,9 @@ void AVQ_encmux_fx(
    Word16 bitsMod, Nsvm1, Nsvm2;
    Word16 unusedbitsFlag;
    Word16 svOrder[NSV_MAX], k, nullVec, dummy_bits;

#ifdef REUSE_EVS_BE_ACELP_AVQ
    Word16 tmp;
#endif
    test();
    IF( EQ_16( extl, SWB_BWE_HIGHRATE ) || EQ_16( extl, FB_BWE_HIGHRATE ) )
    {
@@ -344,7 +346,19 @@ void AVQ_encmux_fx(
        test();
        test();
        test();
#ifdef REUSE_EVS_BE_ACELP_AVQ
        tmp = bits;
        move16();
        WHILE( GE_16( tmp, 5 ) )
        {
            tmp = sub( tmp, 5 );
        }
        assert( tmp == bits % 5 );
        IF( EQ_16( avq_bit_sFlag, 2 ) && EQ_16( tmp, 4 ) && GT_16( bits, 8 ) && LT_16( bits, 30 ) && GE_16( k, trgtSvPos ) && LT_16( i, Nsvm1 ) )

#else
        IF( EQ_16( avq_bit_sFlag, 2 ) && EQ_16( s_and( bits, 4 ), 4 ) && GT_16( bits, 8 ) && LT_16( bits, 30 ) && GE_16( k, trgtSvPos ) && LT_16( i, Nsvm1 ) )
#endif
        {
            ordr_esti( sub( Nsv, i ), &trgtSvPos, &svOrder[i], Nsv );
            k = svOrder[i];
@@ -408,8 +422,19 @@ void AVQ_encmux_fx(
    test();
    IF( avq_bit_sFlag > 0 && GT_16( bits, 8 ) )
    {
#ifndef REUSE_EVS_BE_ACELP_AVQ
        // PMT("code not validated yet")
        bitsMod = s_and( bits, 4 /*bits%5*/ );
#else
        /* bitsMod = bits % 5;*/
        bitsMod = bits;
        move16();
        WHILE( bitsMod >= 5 )
        {
            bitsMod = sub( bitsMod, 5 );
        }
        assert( bitsMod == bits % 5 );
#endif
        i = svOrder[Nsvm1];
        move16();
        IF( NE_16( i, Nsvm1 ) )
@@ -449,7 +474,17 @@ void AVQ_encmux_fx(
            {
                overflow = 0;
                move16();
#ifdef REUSE_EVS_BE_ACELP_AVQ
                tmp = add( bitsMod, nullVec );
                WHILE( tmp >= 5 )
                {
                    tmp = sub( tmp, 5 );
                }
                assert( tmp == add( bitsMod, nullVec ) % 5 );
                if ( tmp != 0 )
#else
                if ( s_and( add( bitsMod, nullVec ), 4 ) != 0 )
#endif
                {
                    overflow = 1;
                    move16();
@@ -476,7 +511,18 @@ void AVQ_encmux_fx(
            unused_bits = sub( unused_bits, 1 ); /*Stop Bit*/
        }
        /*unused_bits_idx = (int16_t)unused_bits / 5;*/
#ifdef REUSE_EVS_BE_ACELP_AVQ
        IF( unused_bits >= 0 )
        {
            unused_bits_idx = mult( unused_bits, 6554 /*1/5 in Q15*/ );
        }
        ELSE
        {
            unused_bits_idx = negate( mult( negate( unused_bits ), 6554 /*1/5 in Q15*/ ) );
        }
#else
        unused_bits_idx = mult( unused_bits, 6554 );
#endif
        assert( unused_bits_idx == unused_bits / 5 );
        unusedbitsFlag = 0;
        move16();
@@ -506,7 +552,11 @@ void AVQ_encmux_fx(
        IF( j > 0 )
        {
            /* write the unary code */
#ifdef REUSE_EVS_BE_ACELP_AVQ
            push_indice( hBstr, nq_ind, u_extract_l( L_sub( L_shl_sat( 1, j ), 1 ) ), j );
#else
            push_indice( hBstr, nq_ind, sub( shl( 1, j ), 1 ), j );
#endif
        }

        IF( nq[i] != 0 )
@@ -558,7 +608,7 @@ void AVQ_encmux_fx(

    return;
}

#ifndef REUSE_EVS_BE_ACELP_AVQ
void AVQ_encmux_ivas_fx(
    BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle            */
    const Word16 extl,     /* i  : extension layer                                 */
@@ -985,7 +1035,7 @@ void AVQ_encmux_ivas_fx(

    return;
}

#endif
/*-------------------------------------------------------------------*
 * Function AVQ_cod_lpc_fx()                                            *
 *                                                                   *
+4 −2
Original line number Diff line number Diff line
@@ -296,7 +296,7 @@ void acelp_2t32_fx(
    }
    return;
}

#ifndef REUSE_EVS_BE_ACELP_2t32
void acelp_2t32_ivas_fx(
    BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle                      */
    const Word16 dn[],     /* i  : corr. between target and h[].                 Qx*/
@@ -568,6 +568,7 @@ void acelp_2t32_ivas_fx(
    }
    return;
}
#endif
/*----------------------------------------------------------------------------------
 * Function  acelp_1t64()
 *
@@ -645,7 +646,7 @@ void acelp_1t64_fx(

    return;
}

#ifndef REUSE_EVS_BE_ACELP_1t64
void acelp_1t64_ivas_fx(
    BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle                      */
    const Word16 dn[],     /* i  : corr. between target and h[].                Qx */
@@ -714,3 +715,4 @@ void acelp_1t64_ivas_fx(

    return;
}
#endif
+10 −3
Original line number Diff line number Diff line
@@ -66,6 +66,10 @@ Word16 acelp_4t64_fx(
    Word16 nbbits,           /* i  : number of bits per codebook                    */
    const Word16 cmpl_flag,  /* i  : complexity reduction flag                      */
    const Word16 Opt_AMR_WB  /* i  : flag indicating AMR-WB IO mode                 */
#ifdef REUSE_EVS_BE_ACELP_4T64
    ,
    const Word16 element_mode
#endif
)
{

@@ -299,8 +303,11 @@ Word16 acelp_4t64_fx(

    IF( acelpautoc )
    {
#ifdef REUSE_EVS_BE_ACELP_4T64
        E_ACELP_4tsearchx_fx( dn, cn, R, code, &config, ind, element_mode );
#else
        E_ACELP_4tsearchx_fx( dn, cn, R, code, &config, ind );

#endif
        /* Generate weighted code */
        E_ACELP_weighted_code( code, H, 12, y );
    }
@@ -468,7 +475,7 @@ Word16 acelp_4t64_fx(
    return saved_bits;
}


#ifndef REUSE_EVS_BE_ACELP_4T64
Word16 acelp_4t64_ivas_fx(
    BSTR_ENC_HANDLE hBstr,   /* i/o: encoder bitstream handle                      */
    Word16 dn[],             /* i  : corr. between target and h[].                 */
@@ -882,7 +889,7 @@ Word16 acelp_4t64_ivas_fx(

    return saved_bits;
}

#endif
/*---------------------------------------------------------------------*
 *encode class for 3p 4p 5p 6p/track                                   *
 *---------------------------------------------------------------------*/
Loading