Commit 594d23e7 authored by Michael Sturm's avatar Michael Sturm
Browse files

Unifies IGF_getSFM function.

parent 9725ea31
Loading
Loading
Loading
Loading
+90 −3
Original line number Diff line number Diff line
@@ -959,7 +959,12 @@ Word16 IGF_getSFM(
    const Word32 *energy,     /* i  :  Q31| energies               */
    const Word16 *energy_exp, /* i  :     | exponent of energies   */
    const Word16 start,       /* i  :  Q0 | start subband index    */
#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS
    const Word16 stop,        /* i  :  Q0 | stop subband index     */
    const Word16 element_mode /* i  :     | IVAS element mode type */
#else
    const Word16 stop         /* i  :  Q0 | stop subband index     */
#endif
)
{
    Word16 n, i, s;
@@ -970,12 +975,46 @@ Word16 IGF_getSFM(
    Word16 numf;
    Word32 SFM32;
    Word16 invDenom, SFM;
#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS
    Word64 W_denom;
    Word16 en_exp;

#else
    move32();
    move32();

    move32();
#endif
    num = 0;
    move32();
#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS
    *SFM_exp = 0;
    move16();
    SFM = 32767 /*1.0f Q15*/;
    move16();
    en_exp = energy_exp[0];
    move16();
    denom_exp = 0;
    move16();
    W_denom = 0;
    move64();
    IF( EQ_16( element_mode, EVS_MONO ) )
    {
        denom = L_shr( 2147483 /*0,001 in Q31 - float is "1", here*/, s_min( en_exp, 31 ) );
        denom = L_max( denom, 1 );
        move32();
        move32();
        W_denom = W_deposit32_l( denom );
        move64();
    }
    ELSE
    {
        denom = 65536; // 1.f in Q16
        move32();
        denom_exp = 15;
        move16();
    }
#else
    denom = L_shr( 2147483 /*0,001 in Q31 - float is "1", here*/, s_min( *energy_exp, 31 ) );
    denom = L_max( denom, 1 );
    *SFM_exp = 0;
@@ -984,6 +1023,7 @@ Word16 IGF_getSFM(
    move16();

    Word64 W_denom = W_deposit32_l( denom );
#endif
    FOR( i = start; i < stop; i++ )
    {
        /*ln(x * 2^-Qx * 2^xExp) = ln(x) - Qx + xExp*/
@@ -991,8 +1031,14 @@ Word16 IGF_getSFM(
        /* n       = sub(sub(31,norm_l(tmp32)),1);  */ /*<- ld    */
        /* n       = sub(n,31);                     */ /*<- -Qx   */
        /* n       = add(n,*energy_exp);            */ /*<- +xExp */

#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS
        IF( GT_16( element_mode, EVS_MONO ) ) {
            en_exp = energy_exp[i]; /* exponent is a vector in IVAS (and a scalar in EVS) */
        }
        n = sub( sub( en_exp, norm_l( energy[i] ) ), 1 ); /*<-- short form*/
#else
        n = sub( sub( *energy_exp, norm_l( energy[i] ) ), 1 ); /*<-- short form*/
#endif

        if ( energy[i] == 0 ) /*special case: energy is zero*/
        {
@@ -1003,11 +1049,28 @@ Word16 IGF_getSFM(
        n = s_max( 0, n );
        num = L_add( num, L_deposit_l( n ) ); /*Q0*/

#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS
        IF( EQ_16( element_mode, EVS_MONO ) ) {
            W_denom = W_add( W_deposit32_l( energy[i] ), W_denom );
        }
        ELSE
        {
            denom = BASOP_Util_Add_Mant32Exp( energy[i], en_exp, denom, denom_exp, &denom_exp );
        }
#else
        W_denom = W_add( W_deposit32_l( energy[i] ), W_denom );
#endif
    }

#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS
    IF( EQ_16( element_mode, EVS_MONO ) ) {
        denom = w_norm_llQ31( W_denom, &denom_exp ); /*Q31*/
        denom_exp = add( denom_exp, en_exp );
    }
#else
    denom = w_norm_llQ31( W_denom, &denom_exp ); /*Q31*/
    denom_exp = add( denom_exp, *energy_exp );
#endif

    /* calculate SFM only if signal is present */
    IF( denom != 0 )
@@ -1055,6 +1118,7 @@ Word16 IGF_getSFM(
    return SFM /*Q15*/;
}

#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS
/*************************************************************************
calculates spectral flatness measurment
**************************************************************************/
@@ -1153,8 +1217,7 @@ Word16 IGF_getSFM_ivas_fx(

    return SFM /*Q15*/;
}


#endif
/**********************************************************************/ /*
calculates the IGF whitening levels by SFM and crest
**************************************************************************/
@@ -1232,7 +1295,11 @@ static void IGF_Whitening(
            FOR( p = 0; p < nT; p++ )
            {
                /*tmp  = IGF_getSFM(powerSpectrum, hGrid->tile[p], hGrid->tile[p+1]) / IGF_getCrest(powerSpectrum, hGrid->tile[p], hGrid->tile[p+1]);*/
#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS
                SFM = IGF_getSFM( &SFM_exp, powerSpectrum, &powerSpectrum_exp, hGrid->tile[p], hGrid->tile[p + 1], EVS_MONO );
#else
                SFM = IGF_getSFM( &SFM_exp, powerSpectrum, &powerSpectrum_exp, hGrid->tile[p], hGrid->tile[p + 1] );
#endif
#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS
                crest = IGF_getCrest( &crest_exp, powerSpectrum, &powerSpectrum_exp, hGrid->tile[p], hGrid->tile[p + 1], EVS_MONO );
#else
@@ -3121,8 +3188,13 @@ static void IGF_CalculateStereoEnvelope_fx(
                    move16();
                    move16();

#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS
                    // tmp_tb = IGF_getSFM(pPowerSpectrum, swb_offset[sfb], swb_offset[sfb + 1]) / IGF_getCrest(pPowerSpectrum, swb_offset[sfb], swb_offset[sfb + 1]);
                    sfm = IGF_getSFM( &sfm_exp, pPowerSpectrum_fx, pPowerSpectrum_e, swb_offset[sfb], swb_offset[sfb + 1], IVAS_CPE_MDCT );
#else
                    // tmp_tb = IGF_getSFM_ivas(pPowerSpectrum, swb_offset[sfb], swb_offset[sfb + 1]) / IGF_getCrest_ivas(pPowerSpectrum, swb_offset[sfb], swb_offset[sfb + 1]);
                    sfm = IGF_getSFM_ivas_fx( &sfm_exp, pPowerSpectrum_fx, pPowerSpectrum_e, swb_offset[sfb], swb_offset[sfb + 1] );
#endif
#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS
                    crest = IGF_getCrest( &crest_exp, pPowerSpectrum_fx, pPowerSpectrum_e, swb_offset[sfb], swb_offset[sfb + 1], IVAS_CPE_MDCT );
#else
@@ -3131,8 +3203,13 @@ static void IGF_CalculateStereoEnvelope_fx(
                    tmp_tb_fx = BASOP_Util_Divide1616_Scale( sfm, crest, &tmp_e );
                    tmp_tb_e = add( tmp_e, sub( sfm_exp, crest_exp ) ); /*stores the resultant exponent for tmp_tb_fx*/

#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS
                    // tmp_sb = IGF_getSFM(tileSrcSpec, 0, strt_cpy - tmp) / IGF_getCrest(tileSrcSpec, 0, strt_cpy - tmp);
                    sfm = IGF_getSFM( &sfm_exp, tileSrcSpec_fx, tileSrcSpec_e, 0, sub( strt_cpy, tmp ), IVAS_CPE_MDCT );
#else
                    // tmp_sb = IGF_getSFM_ivas(tileSrcSpec, 0, strt_cpy - tmp) / IGF_getCrest_ivas(tileSrcSpec, 0, strt_cpy - tmp);
                    sfm = IGF_getSFM_ivas_fx( &sfm_exp, tileSrcSpec_fx, tileSrcSpec_e, 0, sub( strt_cpy, tmp ) );
#endif
#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS
                    crest = IGF_getCrest( &crest_exp, tileSrcSpec_fx, tileSrcSpec_e, 0, sub( strt_cpy, tmp ), IVAS_CPE_MDCT );
#else
@@ -3280,8 +3357,13 @@ static void IGF_CalculateStereoEnvelope_fx(
                        IF( EQ_16( BASOP_Util_Cmp_Mant32Exp( slope_fx, add( slope_e, 16 ), negate( threshold_fx ), add( threshold_e, 16 ) ), -1 ) )
                        {
                            Word16 shift = shr( width, 1 );
#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS
                            // shiftedSFM = IGF_getSFM( pPowerSpectrum, swb_offset[sfb] - shift, swb_offset[sfb + 1] - shift ) / IGF_getCrest( pPowerSpectrum, swb_offset[sfb] - shift, swb_offset[sfb + 1] - shift );
                            sfm = IGF_getSFM( &sfm_exp, pPowerSpectrum_fx, pPowerSpectrum_e, sub( swb_offset[sfb], shift ), sub( swb_offset[sfb + 1], shift ), IVAS_CPE_MDCT );
#else
                            // shiftedSFM = IGF_getSFM_ivas( pPowerSpectrum, swb_offset[sfb] - shift, swb_offset[sfb + 1] - shift ) / IGF_getCrest_ivas( pPowerSpectrum, swb_offset[sfb] - shift, swb_offset[sfb + 1] - shift );
                            sfm = IGF_getSFM_ivas_fx( &sfm_exp, pPowerSpectrum_fx, pPowerSpectrum_e, sub( swb_offset[sfb], shift ), sub( swb_offset[sfb + 1], shift ) );
#endif
#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS
                            crest = IGF_getCrest( &crest_exp, pPowerSpectrum_fx, pPowerSpectrum_e, sub( swb_offset[sfb], shift ), sub( swb_offset[sfb + 1], shift ), IVAS_CPE_MDCT );
#else
@@ -3293,8 +3375,13 @@ static void IGF_CalculateStereoEnvelope_fx(
                        {
                            Word16 shift;
                            shift = shr( width, 1 );
#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS
                            // shiftedSFM = IGF_getSFM( pPowerSpectrum, swb_offset[sfb] + shift, swb_offset[sfb + 1] + shift ) / IGF_getCrest( pPowerSpectrum, swb_offset[sfb] + shift, swb_offset[sfb + 1] + shift );
                            sfm = IGF_getSFM( &sfm_exp, pPowerSpectrum_fx, pPowerSpectrum_e, add( swb_offset[sfb], shift ), add( swb_offset[sfb + 1], shift ), IVAS_CPE_MDCT );
#else
                            // shiftedSFM = IGF_getSFM_ivas( pPowerSpectrum, swb_offset[sfb] + shift, swb_offset[sfb + 1] + shift ) / IGF_getCrest_ivas( pPowerSpectrum, swb_offset[sfb] + shift, swb_offset[sfb + 1] + shift );
                            sfm = IGF_getSFM_ivas_fx( &sfm_exp, pPowerSpectrum_fx, pPowerSpectrum_e, add( swb_offset[sfb], shift ), add( swb_offset[sfb + 1], shift ) );
#endif
#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS
                            crest = IGF_getCrest( &crest_exp, pPowerSpectrum_fx, pPowerSpectrum_e, add( swb_offset[sfb], shift ), add( swb_offset[sfb + 1], shift ), IVAS_CPE_MDCT );
#else
+7 −1
Original line number Diff line number Diff line
@@ -2703,9 +2703,14 @@ Word16 IGF_getSFM(
    const Word32 *energy,     /* i  :  Q31| energies               */
    const Word16 *energy_exp, /* i  :     | exponent of energies   */
    const Word16 start,       /* i  :  Q0 | start subband index    */
#ifdef FIX_2346_DUPLICATED_IGF_FUNCTIONS
    const Word16 stop,        /* i  :  Q0 | stop subband index     */
    const Word16 element_mode /* i  :     | IVAS element mode type */
#else
    const Word16 stop         /* i  :  Q0 | stop subband index     */
#endif
);

#ifndef FIX_2346_DUPLICATED_IGF_FUNCTIONS
/* o: Q15| SFM value              */
Word16 IGF_getSFM_ivas_fx(
    Word16 *SFM_exp,          /* o  :     | exponent of SFM Factor */
@@ -2714,6 +2719,7 @@ Word16 IGF_getSFM_ivas_fx(
    const Word16 start,       /* i  :  Q0 | start subband index    */
    const Word16 stop         /* i  :  Q0 | stop subband index     */
);
#endif

void IGF_ErodeSpectrum(
    Word16 *highPassEner_exp,                /* o  : exponent of highPassEner       */