Commit 82a098e0 authored by multrus's avatar multrus
Browse files

[cleanup] accept FIX_2485_HARMONIZE_perform_noise_estimation_enc

parent 08c7ceb5
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -91,7 +91,6 @@
#define NONBE_FIX_ISSUE_2206_AVOID_OVERFLOW_SWB_fenv_fx2 /* FhG: Avoid overflow of SWB_fenv_fx in SWB_BWE_encoding_fx because of very small energies. */
#define NONBE_FIX_ISSUE_2206_AVOID_OVERFLOW_MSVQ_Interpol_Tran_fx /* FhG: Fix saturation crash in MSVQ_Interpol_Tran_fx() */
#define FIX_2452_HQ_CORE_PEAQ_AVR_RATIO_HARM            /* Eri: Basop issue 2453: Fix alignment of peak_avrg_ratio_fx */
#define FIX_2485_HARMONIZE_perform_noise_estimation_enc /* FhG: harmonize perform_noise_estimation_enc and perform_noise_estimation_enc_ivas */
#define FIX_2485_HARMONIZE_minimum_statistics           /* FhG: harmonize minimum_statistics and minimum_statistics_fx */
#define FIX_FLOAT_ISSUE_1546_DEAD_CODE                  /* FhG: remove dead code reported in the issue*/
#define FIX_FLOAT_1539_G192_FORMAT_SWITCH               /* VA/Nokia: reintroduce format switching for g192 bitstreams */
+0 −355
Original line number Diff line number Diff line
@@ -405,168 +405,6 @@ void resetFdCngEnc_fx(
    return;
}

#ifndef FIX_2485_HARMONIZE_perform_noise_estimation_enc
/*
   perform_noise_estimation_enc_fx

    Parameters:

    band_energies        i  : energy in critical bands without minimum noise floor MODE2_E_MIN
    band_energies_exp    i  : exponent for energy in critical bands without minimum noise floor MODE2_E_MIN
    cldfbBufferReal,     i  : real part of the CLDFB buffer
    cldfbBufferImag,     i  : imaginary part of the CLDFB buffer
    cldfbBufferExp,      i  : exponent for CLDFB buffer
    bitrate              i  : bitrate
    st                   i/o: FD_CNG structure containing all buffers and variables

    Function:
    Perform noise estimation

    Returns:
    void
*/
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, /* i  : exponent for energy in critical bands without minimum noise floor MODE2_E_MIN */
    Word32 *enerBuffer,       /* enerBuffer_exp */
    Word16 enerBuffer_exp,
    HANDLE_FD_CNG_ENC st /* i/o: FD_CNG structure containing all buffers and variables */
)
{
    Word16 i, j, s, s1, s2;
    Word16 nFFTpart;
    Word16 nCLDFBpart;
    Word16 numBands;
    Word16 numCoreBands;
    Word16 regularStopBand;
    Word16 numSlots;
    Word32 tmp;
    Word32 *periodog;
    Word32 *ptr_per;
    Word32 *msPeriodog;

    nFFTpart = st->hFdCngCom->nFFTpart;
    move16();
    nCLDFBpart = st->hFdCngCom->nCLDFBpart;
    move16();
    numCoreBands = st->hFdCngCom->numCoreBands;
    move16();
    regularStopBand = st->hFdCngCom->regularStopBand;
    move16();
    numSlots = st->hFdCngCom->numSlots;
    move16();
    periodog = st->hFdCngCom->periodog;
    move16();
    ptr_per = periodog;
    move16();
    msPeriodog = st->msPeriodog_fx;
    move16();

    assert( numSlots == 16 );

    /* 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[i] = Mpy_32_16_1( tmp, preemphCompensation_fx[i] );                        /* exp(band_energies_exp + 4) */
        move32();
    }

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

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

    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 = Mpy_32_16_1( enerBuffer[j], st->hFdCngCom->scalingFactor ); /* exp(enerBuffer_exp) */
            move32();

            ptr_per++;
        }

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

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

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

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

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

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

        FOR( i = 0; i < nCLDFBpart; i++ )
        {
            msPeriodog[nFFTpart + i] = L_shr( msPeriodog[nFFTpart + i], s_min( 31, s2 ) ); // st->msPeriodog_fx_exp_fft
            move32();
        }
    }

    /* exponent for entire msPeriodog vector */
    st->msPeriodog_fx_exp = st->msPeriodog_fx_exp_fft;
    move16();

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

    /* Call the minimum statistics routine for noise estimation */
    minimum_statistics(
        st->hFdCngCom->npart,
        st->hFdCngCom->nFFTpart,
        st->hFdCngCom->psize_norm,
        st->msLogPeriodog_fx,
        st->msNoiseFloor_fx,
        st->msLogNoiseEst_fx,
        st->msAlpha_fx,
        st->msPsd_fx,
        st->msPsdFirstMoment_fx,
        st->msPsdSecondMoment_fx,
        st->msMinBuf_fx,
        st->msBminWin_fx,
        st->msBminSubWin_fx,
        st->msCurrentMin_fx,
        st->msCurrentMinOut_fx,
        st->msCurrentMinSubWindow_fx,
        st->msLocalMinFlag,
        st->msNewMinFlag,
        st->msPeriodogBuf_fx,
        &( st->msPeriodogBufPtr ),
        st->hFdCngCom );

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

    return;
}
#endif /*FIX_2485_HARMONIZE_perform_noise_estimation_enc*/

/*
   AdjustFirstSID_fx
@@ -1745,199 +1583,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,
    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                                     */
)
{
    Word16 i, j, s, s1, s2;
    Word16 numBands;
    Word16 numCoreBands = hFdCngEnc->hFdCngCom->numCoreBands; /* Q0 */
    move16();
    Word16 regularStopBand = hFdCngEnc->hFdCngCom->regularStopBand; /* Q0 */
    move16();
    Word16 numSlots = hFdCngEnc->hFdCngCom->numSlots; /* Q0 */
    move16();
    assert( numSlots == 16 );

    Word32 numSlots_inv_fx = 1073741824; // Q34 of .0625
    move32();
    Word32 *periodog = hFdCngEnc->hFdCngCom->periodog; /* exp(peridog_exp) */
    Word32 *ptr_per_fx = periodog;
    Word64 periodog_64;
    Word16 periodog_exp[PERIODOGLEN];
    Word16 npart = hFdCngEnc->hFdCngCom->npart; /* Q0 */
    move16();
    Word16 nFFTpart = hFdCngEnc->hFdCngCom->nFFTpart; /* Q0 */
    move16();
    Word16 nCLDFBpart = hFdCngEnc->hFdCngCom->nCLDFBpart; /* Q0 */
    move16();

    Word16 *psize_norm = hFdCngEnc->hFdCngCom->psize_norm; // 6Q9
    Word32 *msPeriodog_fx = hFdCngEnc->msPeriodog_fx;
    Word32 *msNoiseEst_fx = hFdCngEnc->msNoiseEst_fx; /* exp(msNoiseEst_fx_exp) */

    Word16 *msLogPeriodog_fx = hFdCngEnc->msLogPeriodog_fx;
    Word32 *msLogNoiseEst_fx = hFdCngEnc->msLogNoiseEst_32fx;

    Word32 scaleEB_fx = 0;
    move32();
    Word32 tmp;

    test();
    IF( hCPE != NULL && hCPE->hStereoDft != NULL )
    {
        // band_res_dft = ( (float) input_Fs ) / hCPE->hStereoDft->NFFT;
        // chan_width_f = 24000.f / CLDFB_NO_CHANNELS_MAX;
        // chan_width_bins = chan_width_f / band_res_dft;

        ///* Scaling of Energy buffer to get energy per sample, same scaling as for band_energies, 3 is to compensate for the 1/3 scaling in calculate_energy_buffer */
        // scaleEB = 3 * 4.0f / ( hCPE->hStereoDft->NFFT * hCPE->hStereoDft->NFFT );

        ///* Scale with number of bins in one band */
        // scaleEB = scaleEB / chan_width_bins;

        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
    {
        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
    }

    /* 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 ) );
        msPeriodog_fx[i] = Mpy_32_16_1( tmp, preemphCompensation_fx[i] );
        move32();
    }

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

    Word16 max_exp = -31;
    move16();
    i = 0;
    move16();
    /* Adjust to the desired time resolution by averaging the periodograms over the time slots */
    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 );
    //  move16();

    numBands = sub( regularStopBand, numCoreBands ); /* Q0 */
    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();
    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_flt( msPeriodog, msLogPeriodog, npart );
    compress_range( msPeriodog_fx, hFdCngEnc->msPeriodog_fx_exp, msLogPeriodog_fx, npart );


    /* Call the minimum statistics routine for noise estimation */

    minimum_statistics_fx( npart, nFFTpart, psize_norm, msLogPeriodog_fx, hFdCngEnc->msNoiseFloor_32fx, msLogNoiseEst_fx, 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( msLogNoiseEst_fx, msNoiseEst_fx, &hFdCngEnc->msNoiseEst_fx_exp, hFdCngEnc->hFdCngCom->npart );

    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,
@@ -2214,7 +1860,6 @@ void perform_noise_estimation_enc_fx(

    return;
}
#endif /*FIX_2485_HARMONIZE_perform_noise_estimation_enc*/


/*-------------------------------------------------------------------*
+0 −8
Original line number Diff line number Diff line
@@ -1000,11 +1000,7 @@ 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
            {
@@ -1015,11 +1011,7 @@ 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
            }
        }
    }
+0 −4
Original line number Diff line number Diff line
@@ -323,11 +323,7 @@ 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
+0 −20
Original line number Diff line number Diff line
@@ -1632,7 +1632,6 @@ void configureFdCngEnc_fx(
);

/* 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,
@@ -1643,25 +1642,6 @@ void perform_noise_estimation_enc_fx(
    CPE_ENC_HANDLE hCPE,         /* i  : CPE encoder structure                                     */
    Word16 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,
    Word32 *enerBuffer, /* enerBuffer_exp */
    Word16 enerBuffer_exp,
    HANDLE_FD_CNG_ENC st /* i/o: FD_CNG structure containing all buffers and variables */
);

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,
    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                                     */
);
#endif

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