Commit 20969b1c authored by Fabian Bauer's avatar Fabian Bauer
Browse files

added macro FIX_2485_HARMONIZE_perform_noise_estimation_enc and harmoninzed...

added macro FIX_2485_HARMONIZE_perform_noise_estimation_enc and harmoninzed perform_noise_estimation_enc*_fx()
parent 398d808c
Loading
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -99,6 +99,7 @@
#define FIX_2433_ARITH_OVERFLOW_IN_QMETA_ENC            /* Nokia: Fix to convert non-converted binary operations */
#define FIX_2455_HARMONIZE_generate_comfort_noise_enc /* FhG: harmonize generate_comfort_noise_enc and generate_comfort_noise_enc_ivas */
#define FIX_2455_HARMONIZE_configureFdCngEnc          /* FhG: harmonize generate_comfort_noise_enc and generate_comfort_noise_enc_ivas */
#define FIX_2485_HARMONIZE_perform_noise_estimation_enc /* FhG: harmonize perform_noise_estimation_enc and perform_noise_estimation_enc_ivas */

/* #################### End BE switches ################################## */

+254 −1
Original line number Diff line number Diff line
@@ -553,6 +553,7 @@ void resetFdCngEnc_fx(
    return;
}

#ifndef FIX_2485_HARMONIZE_perform_noise_estimation_enc
/*
   perform_noise_estimation_enc_fx

@@ -713,6 +714,7 @@ void perform_noise_estimation_enc_fx(

    return;
}
#endif /*FIX_2485_HARMONIZE_perform_noise_estimation_enc*/

/*
   AdjustFirstSID_fx
@@ -2286,7 +2288,7 @@ Word16 cng_energy_ivas_fx(
    return enr;
}


#ifndef FIX_2485_HARMONIZE_perform_noise_estimation_enc
void perform_noise_estimation_enc_ivas_fx(
    Word32 *band_energies, /* i  : energy in critical bands without minimum noise floor MODE2_E_MIN    band_energies_exp*/
    Word16 band_energies_exp,
@@ -2476,6 +2478,257 @@ void perform_noise_estimation_enc_ivas_fx(

    return;
}
#endif /*FIX_2485_HARMONIZE_perform_noise_estimation_enc*/

#ifdef FIX_2485_HARMONIZE_perform_noise_estimation_enc
void perform_noise_estimation_enc_fx(
    Word32 *band_energies,        /* i  : energy in critical bands without minimum noise floor MODE2_E_MIN    band_energies_exp*/
    Word16 band_energies_exp,
    Word32 *enerBuffer,           /* enerBuffer_exp */
    Word16 enerBuffer_exp,
    HANDLE_FD_CNG_ENC hFdCngEnc,  /* i/o: CNG structure containing all buffers and variables        */
    const Word32 input_Fs,        /* i  : input sampling rate                                     Q0*/
    CPE_ENC_HANDLE hCPE,          /* i  : CPE encoder structure                                     */
    int element_mode              /* i  : is element EVS or IVAS                                    */
)
{
    if ( element_mode == 0 )
    {
        (void) input_Fs;
        (void) hCPE;
    }

    Word16 i, j, s, s1, s2;
    Word16 numBands;
    Word16 nFFTpart = hFdCngEnc->hFdCngCom->nFFTpart; /* Q0 */
    move16();
    Word16 numCoreBands = hFdCngEnc->hFdCngCom->numCoreBands; /* Q0 */
    move16();
    Word16 regularStopBand = hFdCngEnc->hFdCngCom->regularStopBand;
    move16();
    Word16 numSlots = hFdCngEnc->hFdCngCom->numSlots; /* Q0 */
    move16();
    Word16 nCLDFBpart = hFdCngEnc->hFdCngCom->nCLDFBpart; /* Q0 */
    move16();
    assert( numSlots == 16 );
    Word32 *periodog = hFdCngEnc->hFdCngCom->periodog; /* exp(peridog_exp) */
    Word32 *ptr_per_fx = periodog;
    Word32 *msPeriodog_fx = hFdCngEnc->msPeriodog_fx;
    Word32 tmp;

    /* preemphasis compensation and grouping of per bin energies into msPeriodog */
    FOR( i = 0; i < nFFTpart; i++ )
    {
        tmp = L_add( L_shr( band_energies[i], 1 ), L_shr( band_energies[i + NB_BANDS], 1 ) ); /* exp(band_energies_exp) */
        msPeriodog_fx[i] = Mpy_32_16_1( tmp, preemphCompensation_fx[i] );                     /* exp(band_energies_exp + 4) */
        move32();
    }

    /* exponent for fft part of msPeriodog */
    hFdCngEnc->msPeriodog_fx_exp_fft = add( band_energies_exp, PREEMPH_COMPENSATION_EXP );
    move16();

    numBands = sub( regularStopBand, numCoreBands ); /* Q0 */

    /* Adjust to the desired time resolution by averaging the periodograms over the CLDFB time slots */
    IF( element_mode > 0 ) /*IVAS: more precission*/
    {
        Word16 max_exp = -31;
        move16();
        Word16 periodog_exp[PERIODOGLEN];
        Word64 periodog_64;
        Word32 scaleEB_fx = 0;
        move32();
        i = 0;
        move16();

        test();
        IF( hCPE != NULL && hCPE->hStereoDft != NULL )
        {
            SWITCH( input_Fs )
            {
                case 8000:
                    scaleEB_fx = 251648; // Q35
                    move32();
                    BREAK;
                case 16000:
                    scaleEB_fx = 62912; // Q35
                    move32();
                    BREAK;
                case 32000:
                    scaleEB_fx = 15728; // Q35
                    move32();
                    BREAK;
                case 48000:
                    scaleEB_fx = 6991; // Q35
                    move32();
                    BREAK;
                default:
                    assert( 0 && "invalid sample rate" );
            }
        }
        ELSE
        {
            Word32 numSlots_inv_fx = 1073741824; // Q34 of .0625
            move32();
            scaleEB_fx = Mpy_32_32( numSlots_inv_fx, L_deposit_l( hFdCngEnc->hFdCngCom->scalingFactor ) ); // Q34 + Q30 - Q31 = Q33
            scaleEB_fx = L_shl( scaleEB_fx, 2 );                                                           // Q35
        }

        FOR( j = numCoreBands; j < regularStopBand; j++ )
        {
            periodog_64 = W_mult_32_32( enerBuffer[j], scaleEB_fx );
            Word16 scale = W_norm( periodog_64 );
            *ptr_per_fx = W_extract_h( W_shl( periodog_64, scale ) );
            move32();
            periodog_exp[i] = sub( Q31, add( add( sub( Q31, enerBuffer_exp ), 35 - 31 ), scale ) );
            move16();
            if ( *ptr_per_fx )
            {
                max_exp = s_max( max_exp, periodog_exp[i] );
            }
            ptr_per_fx++;
            i++;
        }
        /* exponent for cldfb part of msPeriodog */
        // hFdCngEnc->hFdCngCom->exp_cldfb_periodog = add( sub( enerBuffer_exp, 4 ), CLDFBscalingFactor_EXP );

        FOR( i = 0; i < numBands; i++ )
        {
            periodog[i] = L_shr( periodog[i], sub( max_exp, periodog_exp[i] ) );
            move16();
        }
        hFdCngEnc->hFdCngCom->exp_cldfb_periodog = max_exp;
        move16();
    }
    ELSE         /*EVS_MONO*/
    {
        IF( numBands > 0 )
        {
            /* Adjust to the desired time resolution by averaging the periodograms over the CLDFB time slots */
            FOR( j = numCoreBands; j < regularStopBand; j++ )
            {
                *ptr_per_fx = Mpy_32_16_1( enerBuffer[j], hFdCngEnc->hFdCngCom->scalingFactor ); /* exp(enerBuffer_exp) */
                move32();

                ptr_per_fx++;
            }

            /* exponent for cldfb part of msPeriodog */
            hFdCngEnc->hFdCngCom->exp_cldfb_periodog = add( sub( enerBuffer_exp, 4 ), CLDFBscalingFactor_EXP );


        }
    }

    IF( numBands > 0 )
    {
        ///* Adjust CLDFB filterbank to the desired frequency resolution by averaging over spectral partitions for SID transmission */
        bandcombinepow(
            periodog,
            hFdCngEnc->hFdCngCom->exp_cldfb_periodog,
            numBands,
            hFdCngEnc->hFdCngCom->CLDFBpart,
            nCLDFBpart,
            hFdCngEnc->hFdCngCom->CLDFBpsize_inv,
            &msPeriodog_fx[nFFTpart],
            &hFdCngEnc->msPeriodog_fx_exp_cldfb );

        ///* find common exponent for fft part and cldfb part of msperiodog */
        s1 = L_norm_arr( msPeriodog_fx, nFFTpart );
        s2 = L_norm_arr( &msPeriodog_fx[nFFTpart], nCLDFBpart );

        s = s_max( sub( hFdCngEnc->msPeriodog_fx_exp_fft, s1 ), sub( hFdCngEnc->msPeriodog_fx_exp_cldfb, s2 ) );
        s1 = sub( s, hFdCngEnc->msPeriodog_fx_exp_fft );
        s2 = sub( s, hFdCngEnc->msPeriodog_fx_exp_cldfb );

        hFdCngEnc->msPeriodog_fx_exp_fft = s;
        move16();
        hFdCngEnc->msPeriodog_fx_exp_cldfb = s;
        move16();

        FOR( i = 0; i < nFFTpart; i++ )
        {
            msPeriodog_fx[i] = L_shr( msPeriodog_fx[i], s1 ); // hFdCngEnc->msPeriodog_fx_exp_fft
            move32();
        }

        FOR( i = 0; i < nCLDFBpart; i++ )
        {
            msPeriodog_fx[nFFTpart + i] = L_shr( msPeriodog_fx[nFFTpart + i], s2 ); /*  hFdCngEnc->msPeriodog_fx_exp_fft */
            move32();
        }
    }
    /* exponent for entire msPeriodog vector */
    hFdCngEnc->msPeriodog_fx_exp = hFdCngEnc->msPeriodog_fx_exp_fft;
    move16();

    /* Compress MS inputs */
    compress_range( msPeriodog_fx, hFdCngEnc->msPeriodog_fx_exp, hFdCngEnc->msLogPeriodog_fx, hFdCngEnc->hFdCngCom->npart );

    /* Call the minimum statistics routine for noise estimation */
    IF( element_mode > 0 )
    {
        minimum_statistics_fx(
            hFdCngEnc->hFdCngCom->npart,
            nFFTpart,
            hFdCngEnc->hFdCngCom->psize_norm,
            hFdCngEnc->msLogPeriodog_fx,
            hFdCngEnc->msNoiseFloor_32fx,   /*32bit*/
            hFdCngEnc->msLogNoiseEst_32fx,  /*32bit*/
            hFdCngEnc->msAlpha_fx,
            hFdCngEnc->msPsd_fx,
            hFdCngEnc->msPsdFirstMoment_fx,
            hFdCngEnc->msPsdSecondMoment_fx,
            hFdCngEnc->msMinBuf_fx,
            hFdCngEnc->msBminWin_fx,
            hFdCngEnc->msBminSubWin_fx,
            hFdCngEnc->msCurrentMin_fx,
            hFdCngEnc->msCurrentMinOut_fx,
            hFdCngEnc->msCurrentMinSubWindow_fx,
            hFdCngEnc->msLocalMinFlag,
            hFdCngEnc->msNewMinFlag,
            hFdCngEnc->msPeriodogBuf_fx,
            &( hFdCngEnc->msPeriodogBufPtr ),
            hFdCngEnc->hFdCngCom,
            ENC,
            ( hCPE == NULL ) ? 0 : hCPE->element_mode );

        /* Expand MS outputs */
        expand_range_fx( hFdCngEnc->msLogNoiseEst_32fx, hFdCngEnc->msNoiseEst_fx, &hFdCngEnc->msNoiseEst_fx_exp, hFdCngEnc->hFdCngCom->npart );
    }
    ELSE
    {
        minimum_statistics(
            hFdCngEnc->hFdCngCom->npart,
            nFFTpart,
            hFdCngEnc->hFdCngCom->psize_norm,
            hFdCngEnc->msLogPeriodog_fx,
            hFdCngEnc->msNoiseFloor_fx, /*16bit*/
            hFdCngEnc->msLogNoiseEst_fx,/*16bit*/
            hFdCngEnc->msAlpha_fx,
            hFdCngEnc->msPsd_fx,
            hFdCngEnc->msPsdFirstMoment_fx,
            hFdCngEnc->msPsdSecondMoment_fx,
            hFdCngEnc->msMinBuf_fx,
            hFdCngEnc->msBminWin_fx,
            hFdCngEnc->msBminSubWin_fx,
            hFdCngEnc->msCurrentMin_fx,
            hFdCngEnc->msCurrentMinOut_fx,
            hFdCngEnc->msCurrentMinSubWindow_fx,
            hFdCngEnc->msLocalMinFlag,
            hFdCngEnc->msNewMinFlag,
            hFdCngEnc->msPeriodogBuf_fx,
            &( hFdCngEnc->msPeriodogBufPtr ),
            hFdCngEnc->hFdCngCom );

        /* Expand MS outputs */
        expand_range( hFdCngEnc->msLogNoiseEst_fx, hFdCngEnc->msNoiseEst_fx, &hFdCngEnc->msNoiseEst_fx_exp, hFdCngEnc->hFdCngCom->npart );
    }

    return;
}
#endif /*FIX_2485_HARMONIZE_perform_noise_estimation_enc*/


/*-------------------------------------------------------------------*
+8 −1
Original line number Diff line number Diff line
@@ -860,7 +860,11 @@ void pre_proc_front_ivas_fx(
            test();
            IF( EQ_16( element_mode, IVAS_CPE_TD ) && lr_vad_enabled && band_energies_LR_fx != NULL )
            {
#ifdef FIX_2485_HARMONIZE_perform_noise_estimation_enc
                perform_noise_estimation_enc_fx( band_energies_LR_fx, sub( Q31, band_energies_LR_fx_q ), enerBuffer_fx, *enerBuffer_fx_exp, st->hFdCngEnc, input_Fs, hCPE, st->element_mode );
#else
                perform_noise_estimation_enc_ivas_fx( band_energies_LR_fx, sub( Q31, band_energies_LR_fx_q ), enerBuffer_fx, *enerBuffer_fx_exp, st->hFdCngEnc, input_Fs, hCPE );
#endif
            }
            ELSE
            {
@@ -871,8 +875,11 @@ void pre_proc_front_ivas_fx(
                    st->hFdCngEnc->hFdCngCom->exp_cldfb_periodog = sub( st->hFdCngEnc->hFdCngCom->exp_cldfb_periodog, norm );
                    move16();
                }

#ifdef FIX_2485_HARMONIZE_perform_noise_estimation_enc
                perform_noise_estimation_enc_fx( band_energies_fx, sub( Q31, q_band_energies ), enerBuffer_fx, *enerBuffer_fx_exp, st->hFdCngEnc, input_Fs, hCPE, st->element_mode );
#else
                perform_noise_estimation_enc_ivas_fx( band_energies_fx, sub( Q31, q_band_energies ), enerBuffer_fx, *enerBuffer_fx_exp, st->hFdCngEnc, input_Fs, hCPE );
#endif
            }
        }
    }
+4 −0
Original line number Diff line number Diff line
@@ -323,7 +323,11 @@ void pre_proc_fx(

    resetFdCngEnc_fx( st );

#ifdef FIX_2485_HARMONIZE_perform_noise_estimation_enc
    perform_noise_estimation_enc_fx( st->band_energies, st->band_energies_exp, enerBuffer, enerBuffer_exp, st->hFdCngEnc, 0, NULL, EVS_MONO );
#else
    perform_noise_estimation_enc_fx( st->band_energies, st->band_energies_exp, enerBuffer, enerBuffer_exp, st->hFdCngEnc );
#endif

    /*-----------------------------------------------------------------*
     * Select SID or FRAME_NO_DATA frame if DTX enabled
+13 −0
Original line number Diff line number Diff line
@@ -1667,6 +1667,18 @@ void configureFdCngEnc_fx(
#endif

/* Perform noise estimation */
#ifdef FIX_2485_HARMONIZE_perform_noise_estimation_enc
void perform_noise_estimation_enc_fx(
    Word32 *band_energies,        /* i  : energy in critical bands without minimum noise floor MODE2_E_MIN    band_energies_exp*/
    Word16 band_energies_exp,
    Word32 *enerBuffer,           /* enerBuffer_exp */
    Word16 enerBuffer_exp,
    HANDLE_FD_CNG_ENC hFdCngEnc,  /* i/o: CNG structure containing all buffers and variables        */
    const Word32 input_Fs,        /* i  : input sampling rate                                     Q0*/
    CPE_ENC_HANDLE hCPE,          /* i  : CPE encoder structure                                     */
    int element_mode              /* i  : is element EVS or IVAS                                    */
);
#else
void perform_noise_estimation_enc_fx(
    Word32 *band_energies, /* i  : energy in critical bands without minimum noise floor MODE2_E_MIN    exp_band_energies*/
    Word16 exp_band_energies,
@@ -1684,6 +1696,7 @@ void perform_noise_estimation_enc_ivas_fx(
    const Word32 input_Fs,       /* i  : input sampling rate                                       Q0*/
    CPE_ENC_HANDLE hCPE          /* i  : CPE encoder structure                                     */
);
#endif

/* Adjust the noise estimator at the beginning of each CNG phase (encoder-side) */
Word16 AdjustFirstSID_fx(