Commit df07c071 authored by Sandesh Venkatesh's avatar Sandesh Venkatesh
Browse files

Merge branch 'LTV_crash_fix_High_MLD_fix' into 'main'

LTV crash fix, MLD improvements

See merge request !531
parents a98b6a0b 7bc77b56
Loading
Loading
Loading
Loading
+115 −0
Original line number Diff line number Diff line
@@ -149,6 +149,121 @@ void Comp_and_apply_gain_fx(
    return;
}

void Comp_and_apply_gain_ivas_fx(
    Word16 exc_diffQ[],      /* i/o: Quantized excitation                  */
    Word16 Ener_per_bd_iQ[], /* i  : Target ener per band              Q13 */
    Word16 Ener_per_bd_yQ[], /* i/o  : Ener per band for norm vector     i->Q13/o->Q13 */
    Word16 Mbands_gn,        /* i  : number of bands                  */
    const Word16 ReUseGain,  /* i  : Reuse the gain in Ener_per_bd_yQ  */
    Word16 Qexc_diff,
    Word16 *Q_exc )
{
    Word16 i, i_band;
    Word16 StartBin, NB_Qbins;
    Word16 y_gain;
    Word16 L16, frac, exp1, tmp_exp;
    Word32 L32;
    Word16 Q_exc_diffQ[L_FRAME16k];
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
    Flag Overflow = 0;
    move32();
#endif

    /* Recreate excitation for local synthesis and decoder */
    StartBin = 0;
    move16();
    NB_Qbins = 0;
    move16();

    tmp_exp = add( 14, sub( *Q_exc, Qexc_diff ) ); /* In case of reuse, it can be computed outside the loop*/
    FOR( i_band = 0; i_band < Mbands_gn; i_band++ )
    {
        StartBin = add( StartBin, NB_Qbins );
        NB_Qbins = mfreq_bindiv_loc[i_band];
        move16();
        IF( EQ_16( ReUseGain, 1 ) )
        {
            y_gain = Ener_per_bd_yQ[i_band];
            move16();

            FOR( i = StartBin; i < NB_Qbins + StartBin; i++ )
            {
#ifdef BASOP_NOGLOB
                L32 = L_mult( exc_diffQ[i], y_gain );        /*Q_exc+16-tmp_exp */
                exc_diffQ[i] = round_fx_o( L32, &Overflow ); /*Q_exc-tmp_exp */
#else                                                        /* BASOP_NOGLOB */
                L32 = L_mult( exc_diffQ[i], y_gain );             /*Q_exc+16 */
                exc_diffQ[i] = round_fx( L32 );                   /*Q_exc */
#endif                                                       /* BASOP_NOGLOB */
                move16();
                IF( exc_diffQ[i] )
                {
                    Q_exc_diffQ[i] = sub( *Q_exc, tmp_exp );
                }
                ELSE
                {
                    Q_exc_diffQ[i] = *Q_exc;
                }
                move16();
            }
        }
        ELSE
        {
            /*-----------------------------------------------------------------*
             * y_gain  = pow(10.0, (Ener_per_bd_iQ[i_band]-Ener_per_bd_yQ[i_band]))
             * = pow(2, 3.321928*(Ener_per_bd_iQ[i_band]-Ener_per_bd_yQ[i_band]))
             *-----------------------------------------------------------------*/
            L16 = sub( Ener_per_bd_iQ[i_band], Ener_per_bd_yQ[i_band] ); /*Q12 */
            L32 = L_mult( L16, 27213 );                                  /* 3.321928 in Q13 -> Q26 */
            L32 = L_shr( L32, 10 );                                      /* From Q26 to Q16 */
            frac = L_Extract_lc( L32, &exp1 );                           /* Extract exponent of gcode0 */
            y_gain = extract_l( Pow2( 14, frac ) );                      /* Put 14 as exponent so that */
                                                                         /* output of Pow2() will be: */
                                                                         /* 16384 < Pow2() <= 32767 */
#ifdef BASOP_NOGLOB
            Ener_per_bd_yQ[i_band] = shl_o( y_gain, sub( exp1, 13 ), &Overflow );
#else                 /* BASOP_NOGLOB */
            Ener_per_bd_yQ[i_band] = shl( y_gain, sub( exp1, 13 ) );
#endif                /* BASOP_NOGLOB */
            move16(); /*Q1     */
            tmp_exp = add( add( exp1, 1 ), sub( *Q_exc, Qexc_diff ) );

            FOR( i = StartBin; i < NB_Qbins + StartBin; i++ )
            {
                L32 = L_mult( exc_diffQ[i], y_gain ); /*Qexc_diff+15 */
#ifdef BASOP_NOGLOB
                exc_diffQ[i] = round_fx_o( L32, &Overflow ); /*Q_exc-tmp_exp */
#else                                                        /* BASOP_NOGLOB */
                exc_diffQ[i] = round_fx( L_shl( L32, tmp_exp ) ); /*Q_exc */
#endif
                move16();
                IF( exc_diffQ[i] )
                {
                    Q_exc_diffQ[i] = sub( *Q_exc, tmp_exp );
                }
                ELSE
                {
                    Q_exc_diffQ[i] = *Q_exc;
                }
                move16();
            }
        }
    }

    FOR( i = 0; i < StartBin + NB_Qbins; i++ )
    {
        *Q_exc = s_min( *Q_exc, add( Q_exc_diffQ[i], norm_s( exc_diffQ[i] ) ) );
        move16();
    }
    FOR( i = 0; i < StartBin + NB_Qbins; i++ )
    {
        exc_diffQ[i] = shl( exc_diffQ[i], sub( *Q_exc, Q_exc_diffQ[i] ) );
        move16();
    }

    return;
}


/*========================================================================*/
/* FUNCTION : Ener_per_band_comp_fx()									  */
+34 −5
Original line number Diff line number Diff line
@@ -1137,7 +1137,7 @@ void highband_exc_dct_in_ivas_fx(
    Word16 bwidth,
    Word16 *exc_wo_nf, /* o  : temporal excitation (in f domain) without noisefill   */
    Word16 Qexc_diffQ,
    Word16 Q_exc,
    Word16 *Q_exc,
    const Word16 GSC_noisy_speech,
    Word16 *lt_ener_per_band_fx, /* i/o: Average per band energy                 */
    const Word16 L_frame,        /* i  : frame length                            */
@@ -1450,13 +1450,32 @@ void highband_exc_dct_in_ivas_fx(
        }
    }
#endif
    Comp_and_apply_gain_fx( exc_diffQ, Ener_per_bd_iQ, Ener_per_bd_yQ, last_bin, 0, Qexc_diffQ, Q_exc );
    Word16 Q_tmp = *Q_exc;
    move16();
    Word16 Q_old = *Q_exc;
    move16();
    Comp_and_apply_gain_ivas_fx( exc_diffQ, Ener_per_bd_iQ, Ener_per_bd_yQ, last_bin, 0, Qexc_diffQ, Q_exc );

    IF( exc_wo_nf != NULL )
    {
        Comp_and_apply_gain_fx( exc_wo_nf, Ener_per_bd_iQ, Ener_per_bd_yQ, last_bin, 1, Qexc_diffQ, Q_exc );
        Comp_and_apply_gain_ivas_fx( exc_wo_nf, Ener_per_bd_iQ, Ener_per_bd_yQ, last_bin, 1, Qexc_diffQ, &Q_tmp );
        IF( GT_16( Q_tmp, *Q_exc ) )
        {
            Scale_sig( exc_wo_nf, L_frame, sub( *Q_exc, Q_tmp ) );
        }
        ELSE IF( LT_16( Q_tmp, *Q_exc ) )
        {
            Scale_sig( exc_diffQ, L_frame, sub( Q_tmp, *Q_exc ) );
            *Q_exc = Q_tmp;
            move16();
        }
        Scale_sig( exc_dct_in, L_frame, sub( *Q_exc, Q_old ) );
        Vr_add( exc_dct_in, exc_wo_nf, exc_wo_nf, L_frame );
    }
    ELSE
    {
        Scale_sig( exc_dct_in, L_frame, sub( *Q_exc, Q_old ) );
    }
    /*--------------------------------------------------------------------------------------*
     * add the correction layer to the LF bins,
     * and add the quantized pulses or the noise for the higher part of the spectrum
@@ -1495,8 +1514,18 @@ void highband_exc_dct_in_ivas_fx(

            Q_hb_exc = 0;
            move16();
            envelop_modify_fx( exc_diffQ, seed_tcx, last_bin, Ener_per_bd_iQ, Q_exc, &Q_hb_exc );
            Copy_Scale_sig( &exc_diffQ[tmp1], &exc_dct_in[tmp1], sub( L_FRAME, tmp1 ), sub( Q_exc, Q_hb_exc ) ); /* from Q_hb_exc -> Q_exc as expected */
            envelop_modify_fx( exc_diffQ, seed_tcx, last_bin, Ener_per_bd_iQ, *Q_exc, &Q_hb_exc );
            IF( GT_16( *Q_exc, Q_hb_exc ) )
            {
                Scale_sig( exc_wo_nf, L_frame, sub( Q_hb_exc, *Q_exc ) );
                *Q_exc = Q_hb_exc;
                move16();
            }
            ELSE
            {
                Scale_sig( &exc_diffQ[tmp1], sub( L_FRAME, tmp1 ), sub( *Q_exc, Q_hb_exc ) );
            }
            Copy( &exc_diffQ[tmp1], &exc_dct_in[tmp1], sub( L_FRAME, tmp1 ) ); /* from Q_hb_exc -> Q_exc as expected */
        }

        IF( LT_16( nb_subfr, 4 ) )
+2 −2
Original line number Diff line number Diff line
@@ -537,7 +537,7 @@ static void ivas_compute_smooth_cov_fx(
                    pCov_buf[i][j][k] = L_add( pCov_buf[i][j][k], L_tmp );
                    move32();
                }
                mvs2s( q_tmp, hCovState->q_cov_real_per_band[i][j], pFb->filterbank_num_bands );
                Copy( q_tmp, hCovState->q_cov_real_per_band[i][j], pFb->filterbank_num_bands );
            }
        }
        FOR( i = 0; i < num_ch; i++ )
@@ -579,7 +579,7 @@ static void ivas_compute_smooth_cov_fx(
                    pCov_buf[i][j][k] = L_add( pCov_buf[i][j][k], L_tmp );
                    move32();
                }
                mvs2s( q_tmp, hCovState->q_cov_real_per_band[i][j], pFb->filterbank_num_bands );
                Copy( q_tmp, hCovState->q_cov_real_per_band[i][j], pFb->filterbank_num_bands );
            }
        }
    }
+1 −1
Original line number Diff line number Diff line
@@ -541,7 +541,7 @@ ivas_error ivas_ism_config_fx(
        v_sub_s( bits_element, nb_bits_metadata, bits_CoreCoder, n_ISms );
        bitbudget_to_brate( bits_CoreCoder, total_brate, n_ISms );

        mvs2s( nb_bits_metadata, nb_bits_metadata, n_ISms );
        Copy( nb_bits_metadata, nb_bits_metadata, n_ISms );
    }

    /* assign less CoreCoder bit-budget to inactive streams (at least one stream must be active) */
+18 −34
Original line number Diff line number Diff line
@@ -1064,23 +1064,6 @@ static int16_t calc_n2(

    return n2;
}
#ifdef IVAS_FLOAT_FIXED
static Word16 calc_n2_fx(
    const Word16 ph1 )
{
    Word16 n2;
    Word32 temp;
    temp = L_mult( 23040, getSinWord16( ph1 ) ); /* Q8 + Q15 + Q1 = Q24 */
    n2 = round_fx( temp );                       /* Q24 -> Q8 */
    n2 = shr( n2, 8 );
    IF( s_and( n2, 1 ) == 0 )
    {
        n2 = add( n2, 1 );
    }

    return n2;
}
#endif

static int16_t calc_n3(
    const float ph1,
@@ -1507,14 +1490,14 @@ void pca_dec_s3_fx(
    const Word32 index,
    Word16 *q_fx )
{
    Word16 ph1_q_fx, ph2_q_fx, ph3_q_fx;
    Word16 ph1_q_fx, ph2_q_fx, ph3_q_fx, num_fx;

    Word32 j;
    Word16 i;
    Word16 n1, n2, n3;
    Word16 n2, n3;

    Word16 index1, index2, index3;
    Word16 d_fx;
    Word16 d_fx, exp;

    j = index;
    move16();
@@ -1532,19 +1515,17 @@ void pca_dec_s3_fx(

    assert( index1 > -1 );

    /*
        n1 = IVAS_PCA_N1;
        d = EVS_PI / ( n1 - 1 );
        ph1_q = index1 * d;
        n2 = calc_n2( ph1_q );
    */
    ph1_q_fx = ph1_q_n2_tbl[index1][0];
    move16();
    Word16 num_fx;
    num_fx = 12868;
    n2 = ph1_q_n2_tbl[index1][1];
    move16();

    d_fx = idiv1616( num_fx, sub( n1, 1 ) ); // Q12
    ph1_q_fx = i_mult( index1, d_fx );       // Q12

    ph1_q_fx = shl( ph1_q_fx, 1 ); /* Q12 -> Q13 */

    n2 = calc_n2_fx( ph1_q_fx );

    j = L_sub( j, ivas_pca_offset_index1[index1] );
    index2 = -1;
    move16();
@@ -1570,7 +1551,11 @@ void pca_dec_s3_fx(

        num_fx = 12868;
        move16();
        d_fx = idiv1616( num_fx, sub( n2, 1 ) ); // Q12

        d_fx = BASOP_Util_Divide1616_Scale( num_fx, sub( n2, 1 ), &exp ); /* Q12 */
        exp = add( 3 - 15, exp );
        d_fx = shl( d_fx, sub( exp, 3 ) ); /* Q12 */

        ph2_q_fx = i_mult( index2, d_fx ); // Q12
        ph2_q_fx = shl( ph2_q_fx, 1 );     /* Q12 -> Q13 */
    }
@@ -1588,7 +1573,6 @@ void pca_dec_s3_fx(
    }
    ELSE
    {
        Word16 exp;
        num_fx = 25736; /* PI2 in Q12 */
        move16();
        d_fx = BASOP_Util_Divide1616_Scale( num_fx, n3, &exp ); /* Q12 */
Loading