Commit b21e60d2 authored by vaclav's avatar vaclav
Browse files

Merge branch 'basop-2364-harmonization-of-mult_harm' into 'main'

basop-2364-harmonization-of-mult_harm

Closes #2364

See merge request !2747
parents 5ac5cda2 c07131a7
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -109,6 +109,7 @@
#define FIX_BASOP_2350_HARM_0B_BWE                      /* VA: basop issue 2350: harmonization of the 0b BWE */
#define FIX_BASOP_2350_HARM_0B_BWE_2                    /* VA: basop issue 2350: Simplify calling of hf_synth_fx() */
#define FIX_2349_HARM_FIND_UV                           /* VA: basop issue 2349: harmonization of find_uv() function */
#define FIX_2364_HARM_MULT_HARM                         /* VA: basop issue 2364 : harmonizing multi_harm_fx function */
#define FIX_2370_UNUSED_BUFFERS_CORE_ENC                /* VA: basop issue 2370: remove temporary input buffers in core-encoder  */
#define FIX_2376_FIX_USAN_PRE_PROC                      /* VA: basop issue 2376: Resolve "USAN: SEGV in ivas_compute_core_buffers_fx() */

+4 −0
Original line number Diff line number Diff line
@@ -698,7 +698,11 @@ ivas_error front_vad_spar_fx(
            {
                cor_strong_limit = &dummy_int;
            }
#ifndef FIX_2364_HARM_MULT_HARM
            loc_harm = multi_harm_fx( st->lgBin_E_fx, hFrontVad->hNoiseEst->old_S_fx, hFrontVad->hNoiseEst->cor_map_fx, &hFrontVad->hNoiseEst->multi_harm_limit_fx, st->total_brate, st->bwidth, cor_strong_limit, &st->hSpMusClas->mean_avr_dyn_fx, &st->hSpMusClas->last_sw_dyn_fx, &cor_map_sum_fx, &dummy_fx, S_map_fx ); /* Q0 */
#else
            loc_harm = multi_harm_fx( EVS_MONO, st->lgBin_E_fx, hFrontVad->hNoiseEst->old_S_fx, hFrontVad->hNoiseEst->cor_map_fx, &hFrontVad->hNoiseEst->multi_harm_limit_fx, st->total_brate, st->bwidth, cor_strong_limit, &st->hSpMusClas->mean_avr_dyn_fx, &st->hSpMusClas->last_sw_dyn_fx, &cor_map_sum_fx, &dummy_fx, S_map_fx ); /* Q0 */
#endif
        }

        scale = getScaleFactor32( epsP_fx, M + 1 );
+112 −40
Original line number Diff line number Diff line
@@ -22,7 +22,9 @@

/* o  : frame multi-harmonicity (1-harmonic, 0-not)           */
Word16 multi_harm_fx(

#ifdef FIX_2364_HARM_MULT_HARM
    const Word16 element_mode, /* i  : IVAS element_mode                             Q0    */
#endif
    const Word16 Bin_E[],     /* i  : log-energy spectrum of the current frame      Q7    */
    Word16 old_S[],           /* i/o: prev. log-energy spectrum w. subtracted floor Q7    */
    Word16 cor_map_LT[],      /* i/o: LT correlation map                            Q15   */
@@ -43,6 +45,9 @@ Word16 multi_harm_fx(
    Word32 L_acc;
    Word32 Lcorx2, Lcory2, Lcorxy, Lcor_map_LT_sum;
    Word16 mean_dyn;
#ifdef FIX_2364_HARM_MULT_HARM
    Word32 tmp2_32;
#endif

    /*------------------------------------------------------------------*
     * initialization
@@ -121,6 +126,36 @@ Word16 multi_harm_fx(
        step = 0;
        move16();

#ifdef FIX_2364_HARM_MULT_HARM
        IF( element_mode != EVS_MONO )
        {
            FOR( i = ind_mins[0]; i < ind_mins[N_mins]; i++ )
            {
                /* we are at the end of the next minimum */
                IF( EQ_16( i, *pt_mins ) )
                {
                    pt_mins++;
                    flor = Bin_E[i];
                    move16(); /*Q7*/

                    /* calculate the new step */
                    /*step = (Bin_E[*pt_mins] - Bin_E[i]) / (*pt_mins-i);*/

                    tmp16 = div_s( 1, sub( *pt_mins, i ) );                            // Q15
                    step = msu_r( L_mult( Bin_E[*pt_mins], tmp16 ), Bin_E[i], tmp16 ); // Q7 (15+7+1-16)
                }

                /* subtract the floor */
                S[i] = s_max( sub_sat( Bin_E[i], flor ), 0 );
                move16();

                /* update the floor */
                flor = add( flor, step ); /*Q7*/
            }
        }
        ELSE
#endif
        {
            FOR( i = ind_mins[0]; i < ind_mins[N_mins]; i++ )
            {
                /* we are at the end of the next minimum */
@@ -151,6 +186,7 @@ Word16 multi_harm_fx(
                flor = add( flor, step ); /*Q7*/
            }
        }
    }

    /* Calculate the maximum dynamic per band */
    /* since we are processing 40 bins we will use 1/40 in Q15 to find the mean */
@@ -180,6 +216,7 @@ Word16 multi_harm_fx(
        *cor_strong_limit = 1;
        move16();
    }

    test();
    if ( LT_32( total_brate, ACELP_9k60 ) || GT_32( total_brate, ACELP_16k40 ) )
    {
@@ -285,13 +322,46 @@ Word16 multi_harm_fx(
    Lcor_map_LT_sum = L_deposit_l( 0 );
    tmp2 = 0;
    move16();

#ifdef FIX_2364_HARM_MULT_HARM
    tmp2_32 = 0;
    move32();
#endif
    cor_strong = 0;
    move16();
    pt1 = cor_map_LT; // Q15
    move16();
    pt2 = cor_map;
    move16();

#ifdef FIX_2364_HARM_MULT_HARM
    IF( element_mode != EVS_MONO )
    {
        FOR( i = 0; i < L; i++ )
        {
            /* tmp2 += S[i]; */
            tmp2_32 = L_add( tmp2_32, cor_map[i] ); /* tmp2_32 in Q15; max value is 128) */

            /* *pt1 = M_ALPHA_FX * *pt1 + (1-M_ALPHA_FX) * *pt2++ */
            *pt1 = mac_r( L_mult( ONE_MINUS_M_ALPHA, *pt2 ), M_ALPHA_FX, *pt1 );
            move16();

            /* cor_map_LT_sum += *pt1 */
            Lcor_map_LT_sum = L_add( Lcor_map_LT_sum, *pt1 ); /* cor_map_LT_sum in Q15; max value is 128) */

            if ( GT_16( *pt1, 31130 ) /*0.95f*/ )
            {
                cor_strong = 1;
                move16();
            }

            pt1++;
            pt2++;
        }
        tmp2 = extract_l( L_shr_sat( tmp2_32, 7 ) ); // q15-> q8
    }
    ELSE
#endif
    {
        FOR( i = 0; i < L; i++ )
        {
            /* tmp2 += S[i]; */
@@ -313,6 +383,7 @@ Word16 multi_harm_fx(
            pt1++;
            pt2++;
        }
    }

    IF( ( bwidth == NB ) )
    {
@@ -357,10 +428,10 @@ Word16 multi_harm_fx(
    {
        Copy( S, S_map, L );
    }

    return harm;
}


#ifndef FIX_2364_HARM_MULT_HARM
/* o  : frame multi-harmonicity (1-harmonic, 0-not)           */
Word16 multi_harm_ivas_fx(
    const Word16 Bin_E[],     /* i  : log-energy spectrum of the current frame      Q7    */
@@ -695,3 +766,4 @@ Word16 multi_harm_ivas_fx(
    }
    return harm;
}
#endif
+70 −48
Original line number Diff line number Diff line
@@ -62,7 +62,8 @@
 * y(n)(Qx) = alpha(Q15) * x(Qx)  +  (1.0f-alpha)* y(n-1) (Qx)
 *-----------------------------------------------------------------*/

Word16 noise_est_AR1_Qx(              /* o : Qx   y(n)  */
/* o : Qx   y(n)  */
Word16 noise_est_AR1_Qx(
    Word16 x,    /* i : Qx  x(n)   */
    Word16 y,    /* i : Qx  y(n-1) */
    Word16 alpha /*i : Q15 scaling of driving x(n)  */
@@ -75,7 +76,8 @@ Word16 noise_est_AR1_Qx( /* o : Qx y(n) */
    return mac_r( L_mult( y, alpham1 ), x, alpha );
}

Word32 noise_est_AR1_Qx_32(              /* o : Qx   y(n)  */
/* o : Qx   y(n)  */
Word32 noise_est_AR1_Qx_32(
    Word32 x,    /* i : Qx  x(n)   */
    Word32 y,    /* i : Qx  y(n-1) */
    Word32 alpha /*i : Q15 scaling of driving x(n)  */
@@ -89,6 +91,7 @@ Word32 noise_est_AR1_Qx_32( /* o : Qx y(n) */
    return Madd_32_32( Mpy_32_32( y, alpham1 ), x, alpha );
}


/*-----------------------------------------------------------------*
 * noise_est_ln_q8_fx()
 *
@@ -126,7 +129,8 @@ static Word16 noise_est_ln_q8_fx(
 *
 *-----------------------------------------------------------------*/

static Word32 eps_quota_fx(                   /* o:  eps_num/eps_den  in  q_out */
/* o:  eps_num/eps_den  in  q_out */
static Word32 eps_quota_fx(
    Word16 eps_num_h, /* num high ,*/
    Word16 eps_num_l, /* num low (signed) ,*/
    Word16 eps_den_h, /* den low  */
@@ -139,7 +143,6 @@ static Word32 eps_quota_fx( /* o: eps_num/eps_den in q_out
    Word16 m_num, m_den;
    Word16 num_shift;


    L_tmp_num = L_Comp( eps_num_h, eps_num_l );
    L_tmp_den = L_Comp( eps_den_h, eps_den_l );

@@ -166,11 +169,13 @@ static Word32 eps_quota_fx( /* o: eps_num/eps_den in q_out
    return L_shr( m_num, num_shift );
}


/*-----------------------------------------------------------------*
 * noise_est_init_fx()
 *
 * Initialization of Noise estimator
 *-----------------------------------------------------------------*/

void noise_est_init_fx(
    NOISE_EST_HANDLE hNoiseEst /* i/o: Noise estimation handle */
)
@@ -385,6 +390,8 @@ void noise_est_init_ivas_fx(

    return;
}


/*-----------------------------------------------------------------*
 * noise_est_pre_fx()
 *
@@ -432,7 +439,6 @@ void noise_est_pre_fx(
        hNoiseEst->Etot_l_fx = add( hNoiseEst->Etot_l_fx, 20 );
        move16(); /* 20 =  .08 in Q8 */


        /* Could even be higher but it also delays first entry to DTX */
        IF( GT_16( hNoiseEst->harm_cor_cnt, HE_LT_CNT_PRE_FX ) )
        {
@@ -611,6 +617,8 @@ void noise_est_pre_32fx(

    return;
}


/*==================================================================================*/
/* FUNCTION : noise_est_down_fx()                                                   */
/*----------------------------------------------------------------------------------*/
@@ -638,7 +646,6 @@ void noise_est_pre_32fx(
/* _ (Word32[]) tmpN_he1   : temporary noise update 1                  Q_new+QSCALE */
/*----------------------------------------------------------------------------------*/


void noise_est_down_fx(
    const Word32 fr_bands[], /* i  : per band input energy (contains 2 vectors) */
    Word32 bckr[],           /* i/o: per band background noise energy estimate  */
@@ -689,6 +696,7 @@ void noise_est_down_fx(
    Ltmp = Mpy_32_16( e_Noise, f_Noise, LG10 );
    *totalNoise = round_fx( L_shl( Ltmp, 10 ) ); /*Q8*/
    move16();

    /*-----------------------------------------------------------------*
     * Average energy per frame for each frequency band
     *-----------------------------------------------------------------*/
@@ -836,6 +844,7 @@ void noise_est_down_ivas_fx(
    /*-----------------------------------------------------------------*
     * Background noise energy update
     *-----------------------------------------------------------------*/

    FOR( i = 0; i < NB_BANDS; i++ )
    {
        /* tmpN[i] = (1-ALPHA) * bckr[i] + ALPHA * enr[i]; */
@@ -896,9 +905,11 @@ void noise_est_down_ivas_fx(
    move16();
    move16();
    move16();

    /*------------------------------------------------------------------*
     * Energy variation update
     *------------------------------------------------------------------*/

    /*Etot_v = (float) fabs(*Etot_last - Etot);*/
    L_Etot_v = L_abs( L_sub( L_Etot_last, L_Etot ) ); /* Q24 */

@@ -914,11 +925,13 @@ void noise_est_down_ivas_fx(
    return;
}


/*-----------------------------------------------------------------*
 * noise_est_fx()
 *
 * Noise energy estimation (noise energy is updated in case of noise-only frame)
 *-----------------------------------------------------------------*/

void noise_est_fx(
    Encoder_State *st_fx,       /* i/o: state structure                                                     */
    const Word16 old_pitch1,    /* i  : previous frame OL pitch[1]                                          */
@@ -995,6 +1008,7 @@ void noise_est_fx(
    /*-----------------------------------------------------------------*
     * Initialization
     *-----------------------------------------------------------------*/

    vad_bwidth_fx = st_fx->input_bwidth;
    move16();

@@ -1105,8 +1119,14 @@ void noise_est_fx(
    {
        i = 0;
        move16();
#ifndef FIX_2364_HARM_MULT_HARM
        *loc_harm = multi_harm_fx( EspecdB, hNoiseEst->old_S_fx, hNoiseEst->cor_map_fx, &hNoiseEst->multi_harm_limit_fx, st_fx->total_brate,
                                   st_fx->bwidth, ( st_fx->hGSCEnc != NULL ) ? &hGSCEnc->cor_strong_limit : &i, &hSpMusClas->mean_avr_dyn_fx, &hSpMusClas->last_sw_dyn_fx, cor_map_sum, sp_floor, S_map );
#else
        test();
        *loc_harm = multi_harm_fx( EVS_MONO, EspecdB, hNoiseEst->old_S_fx, hNoiseEst->cor_map_fx, &hNoiseEst->multi_harm_limit_fx, st_fx->total_brate,
                                   st_fx->bwidth, ( st_fx->hGSCEnc != NULL ) ? &hGSCEnc->cor_strong_limit : &i, &hSpMusClas->mean_avr_dyn_fx, &hSpMusClas->last_sw_dyn_fx, cor_map_sum, sp_floor, S_map );
#endif
        move16();
    }

@@ -1157,7 +1177,6 @@ void noise_est_fx(
    }
    Lsum_den = L_shr( Lsum_den, tmpExp );


    /* calculation of spectral diversity */
    /* THR_SPDIV_FX = 5 , 1/5 Q15 =  6554 */
    spec_div = 0;
@@ -1219,7 +1238,6 @@ void noise_est_fx(
    /* *st_noise_char = M_ALPHA * *st_noise_char + (1-M_ALPHA) * noise_chartmp */
    hNoiseEst->noise_char_fx = mac_r( L_mult( M_ALPHA_FX, hNoiseEst->noise_char_fx ), ONE_MINUS_M_ALPHA, noise_chartmp );


    nchar_thr = THR_NCHAR_WB_FX;
    move16(); /* 1.0 Q11 */
    if ( vad_bwidth_fx == NB )
@@ -1258,6 +1276,7 @@ void noise_est_fx(
    /*if( alpha > 0.999f  {     alpha = 0.999f;} */
    alpha = s_min( alpha, 32735 );            /*.999 in Q15*/
    alpham1 = negate( add( -32768, alpha ) ); /* 1.0 - alpha  */

    /*--------------------------------------------------------------*
     * during significant attacks, replace the LT energy by the
     * current energy this will cause non_sta2 failures to occur in
@@ -1369,6 +1388,7 @@ void noise_est_fx(
                move16();
            }
        }

        test();
        IF( GE_16( i, 2 ) && LE_16( i, 16 ) )
        {
@@ -1437,11 +1457,15 @@ void noise_est_fx(
    test();
    *st_harm_cor_cnt = add( *st_harm_cor_cnt, 1 );
    move16();

    test();
    test();
    if ( ( Etot > 0 ) && ( ( *loc_harm > 0 ) || ( GT_16( round_fx( Ltmp ), COR_MAX_NNE_FX ) ) ) )
    {
        *st_harm_cor_cnt = 0;
        move16();
    }

    test();
    test();
    test();
@@ -1452,6 +1476,7 @@ void noise_est_fx(
    {
        *st_harm_cor_cnt = 1;
    }

    test();
    test();
    if ( GT_16( *st_harm_cor_cnt, 1 ) &&
@@ -1465,10 +1490,10 @@ void noise_est_fx(
        move16();
    }


    /*-----------------------------------------------------------------*
     * Energy based pause length counter
     *-----------------------------------------------------------------*/

    test();
    IF( ( *bg_cnt >= 0 ) && ( GT_16( sub( Etot, Etot_l_lp ), 1280 ) /*5.0 in Q8*/ ) )
    {
@@ -1486,6 +1511,7 @@ void noise_est_fx(
            move16();
        }
    }

    if ( *bg_cnt >= 0 )
    {
        *bg_cnt = add( *bg_cnt, 1 );
@@ -1506,7 +1532,6 @@ void noise_est_fx(

    epsP_0_2 = s_max( 0, epsP_0_2 ); /* min value is 0 , Q12 */


    /* st->epsP_0_2_lp = 0.15f * epsP_0_2 + (1.0f-0.15f) * st->epsP_0_2_lp; */
    alpha = 4915;
    move16(); /*0.15 in Q15 */
@@ -1531,7 +1556,6 @@ void noise_est_fx(
    /* epsP_0_2_ad_lp_max = max(epsP_0_2_ad,st->epsP_0_2_ad_lp);*/
    epsP_0_2_ad_lp_max = s_max( epsP_0_2_ad, hNoiseEst->epsP_0_2_ad_lp_fx ); /* Q12 */


    /*-----------------------------------------------------------------*
     * Linear predition efficiency 2 to 16 order
     *-----------------------------------------------------------------*/
@@ -1546,7 +1570,6 @@ void noise_est_fx(

    epsP_2_16 = s_max( 0, epsP_2_16 ); /* min value is 0 , Q12 */


    /* if (epsP_2_16 > st->epsP_2_16_lp){
          st->epsP_2_16_lp = 0.2f * epsP_2_16 + (1.0f-0.2f) * st->epsP_2_16_lp;
      } else {
@@ -1568,7 +1591,6 @@ void noise_est_fx(
    move16();
    epsP_2_16_dlp = sub( hNoiseEst->epsP_2_16_lp_fx, hNoiseEst->epsP_2_16_lp2_fx );


    /* if (epsP_2_16_dlp < st->epsP_2_16_dlp_lp2 )  {
        st->epsP_2_16_dlp_lp2 = 0.02f * epsP_2_16_dlp + (1.0f-0.02f) * st->epsP_2_16_dlp_lp2;
    } else {
@@ -1639,7 +1661,6 @@ void noise_est_fx(
    hNoiseEst->low_tn_track_cnt = tmp;
    move16();


    /* update of the long-term non-stationarity measure (between 0 and 1) */
    /* if ( (non_sta > th_sta) || (*loc_harm > 0) ) {
        st->act_pred = M_GAMMA * st->act_pred + (1-M_GAMMA) * 1;
@@ -1657,10 +1678,10 @@ void noise_est_fx(
    hNoiseEst->act_pred_fx = tmp;
    move16();


    /*-----------------------------------------------------------------*
     * Background noise adaptation enable flag
     *-----------------------------------------------------------------*/

    Ltmp = L_mult( st_fx->voicing_fx[0], 16384 );
    Ltmp = L_mac( Ltmp, st_fx->voicing_fx[1], 16384 );
    cor_tmp = mac_r_sat( Ltmp, corr_shift, MAX_16 );
@@ -1724,17 +1745,14 @@ void noise_est_fx(
    }
    hNoiseEst->aEn = add( hNoiseEst->aEn, tmp );


    hNoiseEst->aEn = s_min( hNoiseEst->aEn, 6 );
    hNoiseEst->aEn = s_max( hNoiseEst->aEn, 0 );

    /* Additional NNE detectors */

    /* comb_ahc_epsP = max(max(st->act_pred, st->lt_haco_ev), epsP_2_16_dlp); */
    /*                             Q15            Q15          Q12 */
    comb_ahc_epsP = s_max( s_max( shr( hNoiseEst->act_pred_fx, 15 - 12 ), shr( hNoiseEst->lt_haco_ev_fx, 15 - 12 ) ), epsP_2_16_dlp ); /* Q12 */


    /* comb_hcm_epsP = max(max(st->lt_haco_ev,epsP_2_16_dlp_max),epsP_0_2_ad_lp_max); */
    /*                            Q15         Q12                 Q12              */
    comb_hcm_epsP = s_max( s_max( shr( hNoiseEst->lt_haco_ev_fx, 15 - 12 ), epsP_2_16_dlp_max ), epsP_0_2_ad_lp_max ); /* Q12 */
@@ -1788,7 +1806,6 @@ void noise_est_fx(
        move16(); /* Q0 */
    }


    /* ns_mask = non_sta < 1e5f; */
    ns_mask = 0;
    move16();
@@ -1798,7 +1815,6 @@ void noise_est_fx(
        move16(); /* Q0 */
    }


    /* lt_haco_mask = st->lt_haco_ev < 0.5f; */
    lt_haco_mask = 0;
    move16();
@@ -1817,7 +1833,6 @@ void noise_est_fx(
        move16(); /* Q0 */
    }


    /* SD_1 = ( (epsP_0_2_ad > 0.5f) && (epsP_0_2 > 7.95f) ); */
    SD_1 = 0;
    move16();
@@ -1917,7 +1932,6 @@ void noise_est_fx(
    tmp = s_and( tmp, SD_1_inv );
    PAU = s_or( PAU, s_and( tmp, s_or( s_and( PD_3, s_or( PD_1, PD_2 ) ), s_or( PD_4, PD_5 ) ) ) );


    /* NEW_POS_BG = (PAU | BG_1) & bg_bgd3;   note bitwise logic in float */
    NEW_POS_BG = s_and( s_or( PAU, BG_1 ), bg_bgd3 );

@@ -1931,7 +1945,6 @@ void noise_est_fx(
        move16();
    }


    /* When the signal dynamics is high and the energy is close to the background estimate */
    /* sd1_bgd =     (st->sign_dyn_lp > 15)
                  && (Etot - st->Etot_l_lp ) < 2*st->Etot_v_h2
@@ -2182,11 +2195,13 @@ void noise_est_fx(
    return;
}


/*-----------------------------------------------------------------*
 * noise_est_fx()
 *
 * Noise energy estimation (noise energy is updated in case of noise-only frame)
 *-----------------------------------------------------------------*/

void noise_est_ivas_fx(
    Encoder_State *st_fx,                 /* i/o: state structure                                                     */
    const Word16 old_pitch1,              /* i  : previous frame OL pitch[1]                                          */
@@ -2279,10 +2294,10 @@ void noise_est_ivas_fx(
    /*-----------------------------------------------------------------*
     * Initialization
     *-----------------------------------------------------------------*/

    vad_bwidth_fx = st_fx->input_bwidth;
    move16();


    /*st_fx->ener_RAT = 10.0f * (float)log10( mean(lf_E, 8));*/
    temp = 0;
    move64();
@@ -2336,6 +2351,7 @@ void noise_est_ivas_fx(
            }
        }
    }

    /*-----------------------------------------------------------------*
     * Set the threshold for eps & non_sta based on input sampling rate
     * The reason is that in case of 8kHz sampling input, there is nothing
@@ -2389,25 +2405,31 @@ void noise_est_ivas_fx(
        move16(); /* low correlation -> probably inactive signal */
    }

    /* Update */

    /*-----------------------------------------------------------------*
     * Multi-harmonic analysis
     *-----------------------------------------------------------------*/

    IF( hFrontVad == NULL )
    {
        IF( st_fx->hSpMusClas != NULL )
        {
            i = 0;
            move16();
#ifndef FIX_2364_HARM_MULT_HARM
            *loc_harm = multi_harm_ivas_fx( EspecdB, hNoiseEst->old_S_fx, hNoiseEst->cor_map_fx, &hNoiseEst->multi_harm_limit_fx, st_fx->total_brate,
                                            st_fx->bwidth, ( st_fx->hGSCEnc != NULL ) ? &hGSCEnc->cor_strong_limit : &i, &hSpMusClas->mean_avr_dyn_fx, &hSpMusClas->last_sw_dyn_fx, cor_map_sum, sp_floor, S_map );
#else
            *loc_harm = multi_harm_fx( st_fx->element_mode, EspecdB, hNoiseEst->old_S_fx, hNoiseEst->cor_map_fx, &hNoiseEst->multi_harm_limit_fx, st_fx->total_brate,
                                       st_fx->bwidth, ( st_fx->hGSCEnc != NULL ) ? &hGSCEnc->cor_strong_limit : &i, &hSpMusClas->mean_avr_dyn_fx, &hSpMusClas->last_sw_dyn_fx, cor_map_sum, sp_floor, S_map );
#endif
            move16();
        }
    }

    /*-----------------------------------------------------------------*
     * Detection of frames with non-stationary spectral content
     *-----------------------------------------------------------------*/

    /* weighted sum of spectral changes per critical bands */
    w_sum_num = 0;
    move64();
@@ -2419,6 +2441,7 @@ void noise_est_ivas_fx(
    Word16 exp, exp2;
    w_sum_den = 0;
    move64();

    FOR( i = 10; i <= st_fx->max_band; i++ )
    {
        Lnum = L_max( *pt1, *pt2 );
@@ -2431,7 +2454,6 @@ void noise_est_ivas_fx(
        num = extract_h( Mpy_32_32( Lnum, Lnum ) ); // 2*(q_fr_bands+exp)-31-16
        ExpNum = add( sub( shl( q_fr_bands, 1 ), 47 ), shl( exp, 1 ) );


        den = E_MIN_FXQ31 >> 8; // 29360, 0.0035f in Q23
        ExpDen = Q23;
        move32();
@@ -2596,6 +2618,7 @@ void noise_est_ivas_fx(
    /*if( alpha > 0.999f  {     alpha = 0.999f;} */
    alpha = s_min( alpha, 32735 );            /*.999 in Q15*/
    alpham1 = negate( add( -32768, alpha ) ); /* 1.0 - alpha  */

    /*--------------------------------------------------------------*
     * during significant attacks, replace the LT energy by the
     * current energy this will cause non_sta2 failures to occur in
@@ -2771,6 +2794,7 @@ void noise_est_ivas_fx(
        }

    } /* end of band loop FOR( i = st_fx->min_band; i <= st_fx->max_band; i++ ) */

    *non_staX = L_shl( *non_staX, 12 ); // Q20
    move32();
    IF( LT_16( Etot, -1280 /* -5.0f in Q8 */ ) )
@@ -2804,6 +2828,7 @@ void noise_est_ivas_fx(

    Word16 exp_tmp;
    st_E_var_est_fx = BASOP_Util_Add_Mant32Exp( hNoiseEst->L_Etot_sq_st_est_fx, Q15, L_negate( Mpy_32_32( hNoiseEst->L_Etot_st_est_fx, hNoiseEst->L_Etot_st_est_fx ) ), Q16, &exp_tmp ); // exp(exp_tmp)

    /*-----------------------------------------------------------------*
     * Count frames since last correlation or harmonic event
     *-----------------------------------------------------------------*/
@@ -2813,6 +2838,7 @@ void noise_est_ivas_fx(

    *st_harm_cor_cnt = add( *st_harm_cor_cnt, 1 );
    move16();

    test();
    test();
    if ( ( Etot > 0 ) && ( ( *loc_harm > 0 ) || ( GT_32( Ltmp, 1825361101 /* 0.85 in Q31 */ ) ) ) )
@@ -2831,6 +2857,7 @@ void noise_est_ivas_fx(
        *st_harm_cor_cnt = 1;
        move16();
    }

    test();
    test();
    IF( GT_16( *st_harm_cor_cnt, 1 ) && GT_16( Etot, 7680 /* 30.0f in Q8 */ ) && EQ_16( BASOP_Util_Cmp_Mant32Exp( st_E_var_est_fx, exp_tmp, 524288 /* 8.0f in Q16 */, Q15 ), 1 ) )
@@ -2840,7 +2867,6 @@ void noise_est_ivas_fx(
        move16();
    }


    /*-----------------------------------------------------------------*
     * Energy based pause length counter
     *-----------------------------------------------------------------*/
@@ -2993,7 +3019,6 @@ void noise_est_ivas_fx(
    hNoiseEst->lt_Ellp_dist_fx = mac_r( L_mult( tmp, 983 /* 0.03 in Q15*/ ), hNoiseEst->lt_Ellp_dist_fx, 31785 /* 0.97 in Q15*/ ); // Q8
    move16();


    /* if (st->harm_cor_cnt == 0)  {
        st->lt_haco_ev = 0.03f*1.0 + 0.97f*st->lt_haco_ev;
    } else {
@@ -3047,6 +3072,7 @@ void noise_est_ivas_fx(
    /*-----------------------------------------------------------------*
     * Background noise adaptation enable flag
     *-----------------------------------------------------------------*/

    /*
     if( ( (*st_harm_cor_cnt < 3*HC_CNT_SLOW )
          && ( ( non_sta > th_sta ) ||
@@ -3078,7 +3104,6 @@ void noise_est_ivas_fx(
    LepsP = extract_l( div_s( num, den ) );             // Q15+exp-exp2
    LepsP = L_shr( LepsP, add( sub( exp, exp2 ), 4 ) ); // Q11


    test();
    test();
    test();
@@ -3118,9 +3143,11 @@ void noise_est_ivas_fx(
        move16();
        move16();
    }

    /*-----------------------------------------------------------------*
     * Stereo classifier - save raw aEn
     *-----------------------------------------------------------------*/

    IF( hStereoClassif != NULL )
    {
        /*
@@ -3151,14 +3178,11 @@ void noise_est_ivas_fx(
        move16();
    }


    /* Additional NNE detectors */

    /* comb_ahc_epsP = max(max(st->act_pred, st->lt_haco_ev), epsP_2_16_dlp); */
    /*                             Q15            Q15          Q12 */
    comb_ahc_epsP = s_max( shr( s_max( hNoiseEst->act_pred_fx, hNoiseEst->lt_haco_ev_fx ), 15 - 12 ), epsP_2_16_dlp ); /* Q12 */


    /* comb_hcm_epsP = max(max(st->lt_haco_ev,epsP_2_16_dlp_max),epsP_0_2_ad_lp_max); */
    /*                            Q15         Q12                 Q12              */
    comb_hcm_epsP = s_max( s_max( shr( hNoiseEst->lt_haco_ev_fx, 15 - 12 ), epsP_2_16_dlp_max ), epsP_0_2_ad_lp_max ); /* Q12 */
@@ -3212,7 +3236,6 @@ void noise_est_ivas_fx(
        move16(); /* Q0 */
    }


    /* ns_mask = non_sta < 1e5f; */
    ns_mask = 0;
    move16();
@@ -3222,7 +3245,6 @@ void noise_est_ivas_fx(
        move16(); /* Q0 */
    }


    /* lt_haco_mask = st->lt_haco_ev < 0.5f; */
    lt_haco_mask = 0;
    move16();
@@ -3241,7 +3263,6 @@ void noise_est_ivas_fx(
        move16(); /* Q0 */
    }


    /* SD_1 = ( (epsP_0_2_ad > 0.5f) && (epsP_0_2 > 7.95f) ); */
    SD_1 = 0;
    move16();
@@ -3578,6 +3599,7 @@ void noise_est_ivas_fx(
            }
        }
    }

    /*st->lt_aEn_zero = 0.2f * (st->aEn==0) + (1-0.2f)  *st->lt_aEn_zero;*/
    /*  y(n+1)=        alpha*tmp            + (1-alpha)*y(n)           */
    L_tmp = 0;
+5 −0
Original line number Diff line number Diff line
@@ -4216,6 +4216,9 @@ Word32 mslvq_fx(

/* o  : frame multi-harmonicity (1-harmonic, 0-not) */
Word16 multi_harm_fx(
#ifdef FIX_2364_HARM_MULT_HARM
    const Word16 element_mode, /* i  : IVAS element_mode                             Q0    */
#endif
    const Word16 Bin_E[],     /* i  : log-energy spectrum of the current frame      Q7    */
    Word16 old_S[],           /* i/o: prev. log-energy spectrum w. subtracted floor Q7    */
    Word16 cor_map_LT[],      /* i/o: LT correlation map                            Q15   */
@@ -4230,6 +4233,7 @@ Word16 multi_harm_fx(
    Word16 S_map[]            /* o  : short-term correlation map                    Q7    */
);

#ifndef FIX_2364_HARM_MULT_HARM
/* o  : frame multi-harmonicity (1-harmonic, 0-not) */
Word16 multi_harm_ivas_fx(
    const Word16 Bin_E[],     /* i  : log-energy spectrum of the current frame      Q7    */
@@ -4245,6 +4249,7 @@ Word16 multi_harm_ivas_fx(
    Word16 *sp_floor,         /* o: noise floor estimate                            Q7    */
    Word16 S_map[]            /* o  : short-term correlation map                    Q7    */
);
#endif

void pvq_encode_frame_fx(
    BSTR_ENC_HANDLE hBstr,    /* i/o: encoder bitstream handle                      */