Commit 1e8b9f11 authored by Sandesh Venkatesh's avatar Sandesh Venkatesh
Browse files

Merge branch 'bug_fixes_acelp_enc_modifications' into 'main'

Modifications in acelp encode sub-function call stack, bug fixes and saturation removal in GenShapedSHBExcitation_enc [allow regression]

See merge request !1175
parents 4321031e 01b3c4b5
Loading
Loading
Loading
Loading
+4 −6
Original line number Diff line number Diff line
@@ -3035,7 +3035,7 @@ void GenShapedSHBExcitation_fx(
void GenShapedSHBExcitation_ivas_enc_fx(
    Word16 *excSHB,                      /* o : synthesized shaped shb excitation Q_bwe_exc*/
    const Word16 *lpc_shb,               /* i : lpc coefficients Q12*/
    Word16 *White_exc16k_FB,             /* o : white excitation for the Fullband extension Q_bwe_exc */
    Word16 *White_exc16k_FB,             /* o : white excitation for the Fullband extension Q_bwe_exc_fb */
    Word32 *mem_csfilt,                  /* i/o: memory */
    Word16 *mem_genSHBexc_filt_down_shb, /* i/o: memory */
    Word16 *state_lpc_syn,               /* i/o: memory */
@@ -3060,9 +3060,7 @@ void GenShapedSHBExcitation_ivas_enc_fx(
    Word16 n_mem2,         /* i :  n_mem2 scale factor to adjust 24.4/32kbps memories */
    Word16 prev_Q_bwe_syn, /* i :  st_fx->prev_Q_bwe_syn */
    const Word32 bitrate,
    const Word16 prev_bfi
#if 1                           // def ADD_IVAS_TBE_CODE
    ,                           /* i  : previous frame was concealed            */
    const Word16 prev_bfi,
    const Word16 element_mode,  /* i  : element mode                            */
    const Word16 flag_ACELP16k, /* i  : ACELP@16kHz flag                        */
    Word16 *nlExc16k,           /* i/o: NL exc for IC-BWE                       */
@@ -3077,7 +3075,6 @@ void GenShapedSHBExcitation_ivas_enc_fx(
    Word16 *prev_mix_factor,      /* i/o: mixing factor in the previous frame     */
    Word16 *Env_error,            /* o  : error in SHB residual envelope modelling*/
    Word16 Env_error_part[]       /* o  : per-segment error in SHB residual envelope modelling */
#endif
);
void GenShapedSHBExcitation_ivas_dec_fx(
@@ -11113,7 +11110,8 @@ void init_coder_ace_plus_ivas_fx(
);
void core_coder_reconfig_ivas_fx(
    Encoder_State *st );
    Encoder_State *st,
    const int32_t last_total_brate );
void core_coder_mode_switch_ivas_fx(
    Encoder_State *st,             /* i/o: encoder state structure             */
+85 −128
Original line number Diff line number Diff line
@@ -2879,7 +2879,7 @@ void GenShapedSHBExcitation_fx(
void GenShapedSHBExcitation_ivas_enc_fx(
    Word16 *excSHB,                      /* o : synthesized shaped shb excitation Q_bwe_exc*/
    const Word16 *lpc_shb,               /* i : lpc coefficients Q12*/
    Word16 *White_exc16k_FB,             /* o : white excitation for the Fullband extension Q_bwe_exc */
    Word16 *White_exc16k_FB,             /* o : white excitation for the Fullband extension Q_bwe_exc_fb */
    Word32 *mem_csfilt,                  /* i/o: memory */
    Word16 *mem_genSHBexc_filt_down_shb, /* i/o: memory */
    Word16 *state_lpc_syn,               /* i/o: memory */
@@ -2903,8 +2903,8 @@ void GenShapedSHBExcitation_ivas_enc_fx(
    const Word16 Q_shb,
    Word16 n_mem2,         /* i :  n_mem2 scale factor to adjust 24.4/32kbps memories */
    Word16 prev_Q_bwe_syn, /* i :  st_fx->prev_Q_bwe_syn */
    const Word32 bitrate,       /* i  : bitrate                                                    */
    const Word16 prev_bfi,      /* i  : previous frame was concealed                               */
    const Word32 bitrate,
    const Word16 prev_bfi,
    const Word16 element_mode,  /* i  : element mode                            */
    const Word16 flag_ACELP16k, /* i  : ACELP@16kHz flag                        */
    Word16 *nlExc16k,           /* i/o: NL exc for IC-BWE                       */
@@ -2917,8 +2917,8 @@ void GenShapedSHBExcitation_ivas_enc_fx(
    Word16 Q_EnvSHBres_4k,
    Word32 *prev_pow_exc16kWhtnd, /* i/o: power of the LB excitation signal in the previous frame */
    Word16 *prev_mix_factor,      /* i/o: mixing factor in the previous frame     */
    Word16 *Env_error,            /* o  : error in SHB residual envelope modelling                Q0 */
    Word16 Env_error_part[]       /* o  : per-segment error in SHB residual envelope modelling    Q0 */
    Word16 *Env_error,            /* o  : error in SHB residual envelope modelling*/
    Word16 Env_error_part[]       /* o  : per-segment error in SHB residual envelope modelling */
)
{
    Word16 i, j, k;
@@ -2963,13 +2963,7 @@ void GenShapedSHBExcitation_ivas_enc_fx(
    Word32 White_exc16k_32[L_FRAME16k];
    Word16 White_exc16k_tmp[L_FRAME16k];
    Word16 prev_Q_bwe_exc_fb;
    Word16 chk1, chk2;
    chk1 = 0;
    chk2 = 0;
    move16();
    move16();

#if 1 // def ADD_IVAS_TBE_CODE
    Word16 alpha, step, mem_csfilt_left, mem_csfilt_right, excNoisyEnvLeft[L_FRAME16k], excNoisyEnvRight[L_FRAME16k];
    Word16 cbsize;
    Word16 mix_factor, old_fact, new_fact, fact, old_scale, new_scale, step_scale;
@@ -2984,7 +2978,7 @@ void GenShapedSHBExcitation_ivas_enc_fx(

    mix_factor = 0; /* Q15 */
    move16();
#endif

    set16_fx( zero_mem, 0, LPC_SHB_ORDER );
    set16_fx( wht_fil_mem, 0, LPC_WHTN_ORDER );
    FOR( i = 0; i < L_FRAME32k; i = i + 2 )
@@ -3016,11 +3010,7 @@ void GenShapedSHBExcitation_ivas_enc_fx(
    /* i: exc16k in Q_bwe_exc */
    /* o: exc16kWhtnd in Q_bwe_exc */

#if 1 // def ADD_IVAS_TBE_CODE
    IF( GE_32( extl_brate, SWB_TBE_2k8 ) )
#else
    IF( GE_32( bitrate, ACELP_24k40 ) )
#endif
    {
        temp2 = 0;
        move16();
@@ -3041,25 +3031,21 @@ void GenShapedSHBExcitation_ivas_enc_fx(
    /* Estimate pow1 associated with Low band nonlinear extended excitation */
    /* pow1=0.00001f */
    tmp = sub( shl( *Q_bwe_exc, 1 ), 31 );
    pow1 = L_shl_sat( 21475l /*0.00001f Q31*/, tmp ); /* 0.00001f in 2*(Q_bwe_exc) */
    W_tmp = W_shl( 21475 /*0.00001f Q31*/, tmp ); /* 0.00001f in 2*(Q_bwe_exc) */
    FOR( k = 0; k < L_FRAME16k; k++ )
    {
        /*excTmp2[k ] = (float)(fabs(exc16kWhtnd[k]));*/
        excTmp2[k] = abs_s( exc16kWhtnd[k] );
        move16();
        chk1 = s_or( chk1, exc16kWhtnd[k] );

        /* pow1 += exc16kWhtnd[k] * exc16kWhtnd[k]; */
        pow1 = L_mac0_sat( pow1, exc16kWhtnd[k], exc16kWhtnd[k] ); /* 2*Q_bwe_exc */
        W_tmp = W_mac_16_16( W_tmp, exc16kWhtnd[k], exc16kWhtnd[k] ); // 2*Q_bwe_exc+1
    }
    Q_pow1 = shl( *Q_bwe_exc, 1 );
    exp = W_norm( W_tmp );
    pow1 = W_extract_h( W_shl( W_tmp, exp ) ); // 2*Q_bwe_exc+1+exp-32 = // tmp+exp
    Q_pow1 = add( tmp, exp );

    test();
#if 1 // ADD_IVAS_TBE_CODE
    IF( flag_ACELP16k == 0 )
#else
    IF( ( LE_32( bitrate, ACELP_13k20 ) ) && ( GE_32( bitrate, ACELP_7k20 ) ) )
#endif
    {
        /* varEnvShape = mean_fx(voice_factors, 4); */
        /* unroll the loop */
@@ -3105,12 +3091,8 @@ void GenShapedSHBExcitation_ivas_enc_fx(
    test();
    test();
    test();
#if 1 // def ADD_IVAS_TBE_CODE
    test();
    IF( EQ_16( element_mode, EVS_MONO ) && *mem_csfilt == 0 && ( ( EQ_32( bitrate, ACELP_9k60 ) ) || ( EQ_32( bitrate, ACELP_16k40 ) ) || ( EQ_32( bitrate, ACELP_24k40 ) ) ) )
#else
    IF( *mem_csfilt == 0 && ( ( EQ_32( bitrate, ACELP_9k60 ) ) || ( EQ_32( bitrate, ACELP_16k40 ) ) || ( EQ_32( bitrate, ACELP_24k40 ) ) ) )
#endif
    {
        /* pre-init smoothing filter to avoid energy drop outs */
        L_tmp = L_mult( excTmp2[0], 1638 );
@@ -3137,7 +3119,7 @@ void GenShapedSHBExcitation_ivas_enc_fx(
        *mem_csfilt = Mult_32_16( L_tmp, varEnvShape );
        move32();
    }
#if 1 // def ADD_IVAS_TBE_CODE

    IF( MSFlag > 0 )
    {
        // varEnvShape = 0.995f;
@@ -3196,7 +3178,6 @@ void GenShapedSHBExcitation_ivas_enc_fx(
        }
    }
    ELSE
#endif
    {
        /* Track the low band envelope */
        L_tmp = L_shl( *mem_csfilt, sub( Q_excTmp2, *Q_bwe_exc ) );
@@ -3222,7 +3203,7 @@ void GenShapedSHBExcitation_ivas_enc_fx(
        *mem_csfilt = L_shr( L_tmp, sub( Q_excTmp2, *Q_bwe_exc ) );
        move32();
    }
#if 1 // def ADD_IVAS_TBE_CODE

    test();
    IF( EQ_32( extl_brate, SWB_TBE_1k10 ) || EQ_32( extl_brate, SWB_TBE_1k75 ) )
    {
@@ -3261,7 +3242,6 @@ void GenShapedSHBExcitation_ivas_enc_fx(
        }
    }
    ELSE
#endif
    {
        /* create a random excitation - Reuse exc16k memory */
        create_random_vector_fx( White_exc16k, L_FRAME, bwe_seed );                        // Q5
@@ -3282,36 +3262,32 @@ void GenShapedSHBExcitation_ivas_enc_fx(
        /* calculate pow22 */
        /* pow22=0.00001f */
        tmp = sub( shl( sub( *Q_bwe_exc, NOISE_QADJ ), 1 ), 31 );
        Word64 sum = W_shl( 21475l /*0.00001f Q31*/, tmp ); /* 0.00001f in 2*(*Q_bwe_exc-NOISE_QADJ) */
        W_tmp = W_shl( 21475l /*0.00001f Q31*/, tmp ); /* 0.00001f in 2*(*Q_bwe_exc-NOISE_QADJ) */
        Q_White_exc16k = getScaleFactor32( White_exc16k_32, L_FRAME16k );
        FOR( k = 0; k < L_FRAME16k; k++ )
        {
            /* White_exc16k[k] *= excNoisyEnv[k]; */
            White_exc16k[k] = extract_h( L_shl( White_exc16k_32[k], Q_White_exc16k ) ); // Q_excTmp2 + 6 + Q_White_exc16k - 16 ==> Q_excTmp2 + Q_White_exc16k - 10
            move16();
            chk2 = s_or( chk2, White_exc16k[k] );
            /* i: excNoisyEnv in (Q_excTmp2)     */
            /* i: White_exc16k  in Q6               */
            /* o: White_exc16k in (Q_bwe_exc-NOISE_QADJ)  */

            /* pow22 += White_exc16k[k] * White_exc16k[k]; */
            sum = W_mac0_16_16( sum, White_exc16k[k], White_exc16k[k] ); /* 2*(Q_excTmp2 + Q_White_exc16k - 10)*/
            W_tmp = W_mac0_16_16( W_tmp, White_exc16k[k], White_exc16k[k] ); /* 2*(Q_excTmp2 + Q_White_exc16k - 10)*/
        }
        Q_pow22 = W_norm( sum );
        pow22 = W_extract_h( W_shl( sum, Q_pow22 ) ); // 2*(Q_excTmp2 + Q_White_exc16k - 10)+Q_pow22-32
        Q_pow22 = W_norm( W_tmp );
        pow22 = W_extract_h( W_shl( W_tmp, Q_pow22 ) ); // 2*(Q_excTmp2 + Q_White_exc16k - 10)+Q_pow22-32
        Q_pow22 = sub( add( Q_pow22, shl( sub( add( Q_White_exc16k, Q_excTmp2 ), 10 ), 1 ) ), 32 );
        Q_White_exc16k = add( Q_White_exc16k, sub( Q_excTmp2, 10 ) );
    }

#if 1 // def ADD_IVAS_TBE_CODE
    flag_plosive = 0;
    move16();
    test();
    test();
    test();
    IF( GE_32( extl_brate, SWB_TBE_2k8 ) || EQ_32( extl_brate, SWB_TBE_1k10 ) || EQ_32( extl_brate, SWB_TBE_1k75 ) )
#else
    IF( GE_32( bitrate, ACELP_24k40 ) )
#endif
    {
        IF( EQ_16( *vf_ind, 20 ) ) /* encoder side */
        {
@@ -3545,7 +3521,6 @@ void GenShapedSHBExcitation_ivas_enc_fx(
        ELSE /* decoder side */
        {
            test();
#if 1 // def ADD_IVAS_TBE_CODE
            IF( EQ_32( extl_brate, SWB_TBE_1k10 ) || EQ_32( extl_brate, SWB_TBE_1k75 ) )
            {
                IF( *vf_ind == 0 )
@@ -3563,7 +3538,6 @@ void GenShapedSHBExcitation_ivas_enc_fx(
                }
            }
            ELSE
#endif
            {
                /* *vf_ind is an integer scale by 0.125f*/
                tmp = shl( *vf_ind, ( 15 - 3 ) );
@@ -3576,10 +3550,9 @@ void GenShapedSHBExcitation_ivas_enc_fx(
                }
            }
        }
#if 1 // def ADD_IVAS_TBE_CODE

        test();
        IF( NE_32( extl_brate, SWB_TBE_1k10 ) && NE_32( extl_brate, SWB_TBE_1k75 ) )
#endif
        {
            voice_factors[0] = mult_r( voice_factors[0], tmp2 );
            move16();
@@ -3593,103 +3566,94 @@ void GenShapedSHBExcitation_ivas_enc_fx(
            move16();
        }
    }
#if 1                                                                         // def ADD_IVAS_TBE_CODE
    Scale_sig( White_exc16k, L_FRAME16k, sub( *Q_bwe_exc, Q_White_exc16k ) ); // Q_bwe_exc

    test();
    IF( GE_16( element_mode, IVAS_CPE_DFT ) && nlExc16k != NULL )
    {
        /* save buffers for IC-BWE */
        // mvr2r(exc16kWhtnd, nlExc16k, L_FRAME16k);
        Copy( exc16kWhtnd, nlExc16k, L_FRAME16k );
        Copy( exc16kWhtnd, nlExc16k, L_FRAME16k ); // Q_bwe_exc
        *nlExc16k_e = sub( 15, *Q_bwe_exc );
        move16();

        // v_multc(White_exc16k, (float)sqrt(pow1 / pow22), mixExc16k, L_FRAME16k);
        /*Word16 temp_fac = divide3232(L_shr(pow1, Q_pow1), pow22);
        Word16 temp_fac_exp = 0;
        temp_fac = Sqrt16(temp_fac, &temp_fac_exp);*/
        L_tmp = root_a_over_b_fx( pow1, Q_pow1, pow22, Q_pow22, &exp );
        Word16 temp_fac = round_fx_sat( L_shl_sat( L_tmp, exp ) ); // Q15
        // v_multc_fixed_16_16(White_exc16k,shr(temp_fac, temp_fac_exp) , mixExc16k, L_FRAME16k);
        Word16 temp_fac = round_fx_sat( L_tmp ); // Q15-exp

        FOR( k = 0; k < L_FRAME16k; k++ )
        {
            mixExc16k[k] = mult_r( White_exc16k[k], temp_fac ); // Q_bwe_exc
            mixExc16k[k] = mult_r( White_exc16k[k], temp_fac ); // Q_White_exc16k+15-exp-15 = Q_White_exc16k-exp
            move16();
        }
        *mixExc16k_e = sub( 15, *Q_bwe_exc );
        *mixExc16k_e = sub( 15, sub( Q_White_exc16k, exp ) );
        move16();
    }
#endif

    FOR( k = 0; k < L_FRAME16k; k++ )
    {
        White_exc16k_FB[k] = White_exc16k[k]; /* Q_bwe_exc */
        move16();
    }
    Copy( White_exc16k, White_exc16k_FB, L_FRAME16k ); // Q_White_exc16k
    prev_Q_bwe_exc_fb = *Q_bwe_exc_fb;
    *Q_bwe_exc_fb = Q_White_exc16k;
    move16();
    *Q_bwe_exc_fb = *Q_bwe_exc;
    move16();

    deemph_fx( White_exc16k, PREEMPH_FAC, L_FRAME16k, tbe_demph );
    /* i/o: White_exc16k (Q_bwe_exc) */
    /* i: tbe_demph (Q_bwe_exc) */
    Word16 tbe_demph_fx = shl_sat( *tbe_demph, sub( Q_White_exc16k, *Q_bwe_exc ) ); // Q_White_exc16k

    deemph_fx( White_exc16k, PREEMPH_FAC, L_FRAME16k, &tbe_demph_fx );
    /* i/o: White_exc16k (Q_White_exc16k) */
    /* i: tbe_demph_fx (Q_White_exc16k) */
    *tbe_demph = shr_sat( tbe_demph_fx, sub( Q_White_exc16k, *Q_bwe_exc ) );
    move16();

#if 1 // def ADD_IVAS_TBE_CODE
    test();
    IF( EQ_32( extl_brate, SWB_TBE_1k10 ) || EQ_32( extl_brate, SWB_TBE_1k75 ) )
    {
        IF( !flag_plosive ) /* use only LB excitation in case of plosives */
        {
            /* re-scale gaussian excitation at the beginning to gradually move from old energy to new energy */
            // old_scale = (float)sqrt(*prev_pow_exc16kWhtnd / pow1);
            // old_scale = divide3232(*prev_pow_exc16kWhtnd, pow1); // exp = Q15 - (Q_pow1)
            // Word16 old_scale_exp = Q15 - (Q_pow1);
            // old_scale = Sqrt16(old_scale, &old_scale_exp);
            // old_scale = shl(old_scale, old_scale_exp); //Q15
            L_tmp = root_a_over_b_fx( *prev_pow_exc16kWhtnd, 0, pow1, Q_pow1, &exp );
            IF( exp < 0 )
            {
                L_tmp = L_shl( L_tmp, exp );
                exp = 0;
                move16();
            }
            old_scale = round_fx_sat( L_tmp ); // exp
            /* old_scale = (float) sqrt( *prev_pow_exc16kWhtnd / pow1 ); */
            old_scale = round_fx_sat( root_a_over_b_fx( *prev_pow_exc16kWhtnd, 0, pow1, Q_pow1, &exp ) ); // exp
            old_scale = shl( old_scale, s_min( 0, exp ) );                                                // limit Q factor to 15
            exp = s_max( 0, exp );

            // new_scale = 1.0f;
            new_scale = shr( 32767, exp ); // exp

            // step_scale = (new_scale - old_scale) / (L_FRAME16k / 2);
            step_scale = mult_r( sub( new_scale, old_scale ), 205 ); // exp
            scale = old_scale;                                       // exp
            move16();

            /* interpolate between the old and the new value of the mixing factor */
            old_fact = *prev_mix_factor; // Q15
            move16();
            new_fact = mix_factor;       // Q15
            move16();
            move16();

            // step = (new_fact - old_fact) / (L_FRAME16k / 2);
            step = mult_r( sub( new_fact, old_fact ), 205 ); // Q15
            fact = old_fact;                                 // Q15
            move16();

            shift = add( exp, sub( *Q_bwe_exc, Q_White_exc16k ) );

            /* mixing of LB and gaussian excitation in the first half of the frame */
            FOR( k = 0; k < L_FRAME16k / 2; k++ )
            {
                // exc16kWhtnd[k] = (float)fact * (White_exc16k[k] * scale) + (float)(1 - fact) * exc16kWhtnd[k];
                // exc16kWhtnd[k] = add(mult_r(fact, mult(shl(White_exc16k[k], *Q_bwe_exc), scale)), mult_r(sub(32767, fact), exc16kWhtnd[k]));
                L_tmp = L_add_sat( L_shl_sat( L_mult( fact, mult_r( White_exc16k[k], scale ) ), exp ), // Q15 + Q_bwe_exc + (Q15-exp) - Q15 + exp + Q1
                                   L_mult( sub( 32767, fact ), exc16kWhtnd[k] ) );                     // Q_bwe_exc + Q16
                exc16kWhtnd[k] = round_fx_sat( L_tmp );                                                // Q_bwe_exc
                /* exc16kWhtnd[k] = (float)fact * (White_exc16k[k] * scale) + (float)(1 - fact) * exc16kWhtnd[k]; */
                L_tmp = L_shl_sat( L_mult( fact, mult_r( White_exc16k[k], scale ) ), shift ); // Q_bwe_exc+16
                exc16kWhtnd[k] = mac_r_sat( L_tmp, sub( 32767, fact ), exc16kWhtnd[k] );      // Q_bwe_exc
                move16();

                fact = add_sat( fact, step );         // Q15
                scale = add_sat( scale, step_scale ); // exp
            }

            shift = sub( *Q_bwe_exc, Q_White_exc16k );
            /* mixing of LB and gaussian excitation in the second half of the frame */
            FOR( ; k < L_FRAME16k; k++ )
            {
                // exc16kWhtnd[k] = (float)new_fact * White_exc16k[k] + (float)(1 - new_fact) * exc16kWhtnd[k];
                // exc16kWhtnd[k] = add(mult_r(new_fact, shl(White_exc16k[k], *Q_bwe_exc)), mult_r(sub(32767, new_fact), exc16kWhtnd[k]));
                L_tmp = L_add( L_mult( new_fact, White_exc16k[k] ),
                               mult_r( sub( 32767, new_fact ), exc16kWhtnd[k] ) ); // Q_bwe_exc + Q15 + Q1 => Q_bwe_exc + Q16
                exc16kWhtnd[k] = round_fx( L_tmp );                                // Q_bwe_exc
                L_tmp = L_shl_sat( L_mult( new_fact, White_exc16k[k] ), shift );         // Q_bwe_exc+16
                exc16kWhtnd[k] = mac_r( L_tmp, sub( 32767, new_fact ), exc16kWhtnd[k] ); // Q_bwe_exc
                move16();
            }
        }
@@ -3697,32 +3661,28 @@ void GenShapedSHBExcitation_ivas_enc_fx(
        PREEMPH_FX( exc16kWhtnd, PREEMPH_FAC, L_FRAME16k, tbe_premph ); // Q_bwe_exc
    }
    ELSE
#endif
    {
#if 1 // def ADD_IVAS_TBE_CODE
        test();
        IF( EQ_16( coder_type, UNVOICED ) || EQ_16( MSFlag, 1 ) )
#else
        IF( EQ_16( coder_type, UNVOICED ) )
#endif
        {
            L_tmp = root_a_over_b_fx( pow1, Q_pow1, pow22, Q_pow22, &exp );
            scale = 0;
            move16();

            test();
            if ( chk1 == 0 && chk2 == 0 )
            IF( pow1 != 0 && pow22 != 0 )
            {
                L_tmp = 0;
                move32();
            }
                L_tmp = root_a_over_b_fx( pow1, Q_pow1, pow22, Q_pow22, &exp );
                scale = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /*Q15 */
            }

            FOR( k = 0; k < L_FRAME16k; k++ )
            {
                /* White_exc16k: (Q_bwe_exc-NOISE_QADJ), scale: Q15 */
                L_tmp = L_mult( White_exc16k[k], scale ); // Q_bwe_exc + Q15 + Q1 => Q_bwe_exc + Q16
                /* L_tmp: (Q_bwe_exc-NOISE_QADJ) + 15 + 1 */
                exc16kWhtnd[k] = round_fx_sat( L_tmp ); // Q_bwe_exc
                exc16kWhtnd[k] = mult_r_sat( White_exc16k[k], scale ); // Q_White_exc16k
                move16();
                /* exc16kWhtnd:  Q_bwe_exc */
            }

            Scale_sig( exc16kWhtnd, L_FRAME16k, sub( *Q_bwe_exc, Q_White_exc16k ) ); // Q_bwe_exc

            PREEMPH_FX( exc16kWhtnd, PREEMPH_FAC, L_FRAME16k, tbe_premph ); // Q_bwe_exc
            /* i/o: exc16kWhtnd  (Q_bwe_exc) */
            /* i/o: tbe_premph (Q_bwe_exc) */
@@ -3785,13 +3745,13 @@ void GenShapedSHBExcitation_ivas_enc_fx(
                    temp2 = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q15 whiteEnvShapedExc scale factor */
                }

                shift = sub( *Q_bwe_exc, Q_White_exc16k );
                FOR( j = 0; j < lSubFr; j++ )
                {
                    /*exc16kWhtnd[k+j] = temp1 * exc16kWhtnd[k+j] + temp2 * White_exc16k[k+j]; */
                    L_tmp = L_mult( temp2, White_exc16k[k + j] );                       /* 16+(Q_bwe_exc)*/
                    L_tmp = L_shl_sat( L_mult( temp2, White_exc16k[k + j] ), shift );   // 16+(Q_bwe_exc)
                    exc16kWhtnd[k + j] = mac_r_sat( L_tmp, temp1, exc16kWhtnd[k + j] ); // Q_bwe_exc
                    move16();
                    /* Q_bwe_exc */
                }
                k = add( k, lSubFr );

@@ -3813,11 +3773,7 @@ void GenShapedSHBExcitation_ivas_enc_fx(
        }
    }

#if 1 // def ADD_IVAS_TBE_CODE
    IF( LT_32( extl_brate, SWB_TBE_2k8 ) )
#else
    IF( LT_32( bitrate, ACELP_24k40 ) )
#endif
    {
        syn_filt_fx( 0, lpc_shb, LPC_SHB_ORDER, exc16kWhtnd, excSHB, L_FRAME16k, state_lpc_syn, 1 );
        /* i: exc16kWhtnd in Q_bwe_exc */
@@ -3928,8 +3884,8 @@ void GenShapedSHBExcitation_ivas_enc_fx(
        Scale_sig( fb_state_lpc_syn, LPC_SHB_ORDER, tmp );
        Scale_sig( fb_tbe_demph, 1, tmp );
        syn_filt_fx( 0, lpc_shb, LPC_SHB_ORDER, White_exc16k_FB, White_exc16k_FB_temp, L_FRAME16k, fb_state_lpc_syn, 1 );
        /* i: White_exc16k_FB       in (14-n2) */
        /* o: White_exc16k_FB_temp  in (14-n2) */
        /* i: White_exc16k_FB       in (Q_bwe_exc_fb) */
        /* o: White_exc16k_FB_temp  in (Q_bwe_exc_fb) */

        FOR( i = 0; i < 10; i++ )
        {
@@ -3951,10 +3907,11 @@ void GenShapedSHBExcitation_ivas_enc_fx(
        set16_fx( White_exc16k_FB, 0, L_FRAME16k );
    }

#if 1                                                  // def ADD_IVAS_TBE_CODE
    *prev_pow_exc16kWhtnd = L_shr_sat( pow1, Q_pow1 ); // power goes above MAX_32
    *prev_mix_factor = mix_factor;
#endif
    move32();
    move16();

    return;
}

+6 −4
Original line number Diff line number Diff line
@@ -570,6 +570,7 @@ static void encod_gen_voic_core_switch_ivas_fx(
    Word16 h2[L_SUBFR + ( M + 1 )];
    Word16 dummyF[NB_SUBFR16k];
    Word16 lp_select, lp_flag;
    Word16 q_h1;
    LPD_state_HANDLE hLPDmem; /* ACELP LPDmem memories */
    BSTR_ENC_HANDLE hBstr;

@@ -634,9 +635,8 @@ static void encod_gen_voic_core_switch_ivas_fx(
        find_targets_ivas_fx( inp, hLPDmem->mem_syn, 0, &( hLPDmem->mem_w0 ), Aq, res, L_SUBFR, Ap, TILT_FAC_FX, xn, cn, h1 );
    }

    /*Scale_sig(h1, L_SUBFR, shift);  */ /*Q14-shift */
    Copy_Scale_sig( h1, h2, L_SUBFR, -2 );
    Scale_sig( h1, L_SUBFR, add( 1, shift ) ); /* set h1[] in Q14 with scaling for convolution */
    q_h1 = sub( 14, norm_s( h1[0] ) );
    Copy_Scale_sig( h1, h2, L_SUBFR, sub( 11, q_h1 ) ); /*Q11*/

    /* scaling of xn[] to limit dynamic at 12 bits */
    Scale_sig( xn, L_SUBFR, shift ); /* Q_new */
@@ -646,8 +646,9 @@ 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 */

    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*/ ); /* 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*/, Q_new ); /* Q6 */

    /*-----------------------------------------------------------------*
     * Find adaptive exitation
@@ -666,6 +667,7 @@ static void encod_gen_voic_core_switch_ivas_fx(
     * LP filtering of the adaptive excitation, codebook target computation
     *-----------------------------------------------------------------*/
    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*/
    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 */

    IF( EQ_16( lp_flag, NORMAL_OPERATION ) )
+23 −23

File changed.

Preview size limit exceeded, changes collapsed.

+10 −12

File changed.

Preview size limit exceeded, changes collapsed.

Loading