Commit c469b1b3 authored by multrus's avatar multrus
Browse files

[cleanup] accept HARMONIZE_2494_FdCng_decodeSID_fx

parent c034cfd9
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -92,7 +92,6 @@
#define NONBE_FIX_ISSUE_2206_AVOID_OVERFLOW_MSVQ_Interpol_Tran_fx /* FhG: Fix saturation crash in MSVQ_Interpol_Tran_fx() */
#define NONBE_FIX_ISSUE_2206_SWB_EXPERIMENT_FIX_2527    /* Fix crash from issue #2527 */
#define FIX_FLOAT_1539_G192_FORMAT_SWITCH               /* VA/Nokia: reintroduce format switching for g192 bitstreams */
#define HARMONIZE_2494_FdCng_decodeSID_fx               /* FhG: harmonize FdCng_decodeSID_fx with _ivas_ version */
#define FIX_BASOP_2509_EVS_CONCEAL_UNINIT_MEM           /* FhG: BASOP 2509: st->hTcxCfg->psychParamsCurrent is not initialized */
#define HARMONIZE_2499_CONFIGUREFDCNGDEC                /* FhG: basop issue 2499: harmonoize configureFdCngDec */
#define FIX_BASOP_2530_IVAS_DECISION_MAT                /* VA: Fix ambiguous usage of extract_l() */
+0 −11
Original line number Diff line number Diff line
@@ -6574,14 +6574,8 @@ void perform_noise_estimation_dec_ivas_fx(
);

/* Decode the CLDFB-CNG bitstream */
#ifdef HARMONIZE_2494_FdCng_decodeSID_fx
void FdCng_decodeSID_fx(
    Decoder_State *st ); /* i/o: decoder state structure */
#else
void FdCng_decodeSID_fx(
    HANDLE_FD_CNG_COM st,    /* i/o: FD_CNG structure containing all buffers and variables */
    Decoder_State *corest ); /* i/o: decoder state structure */
#endif

void noisy_speech_detection_fx(
    HANDLE_FD_CNG_DEC hFdCngDec, /* i/o: FD_CNG structure            */
@@ -9530,11 +9524,6 @@ void SynthesisSTFT_fx(
    const Word16 nchan_out       /* i  : number of output channels */
);

#ifndef HARMONIZE_2494_FdCng_decodeSID_fx
void FdCng_decodeSID_ivas_fx(
    Decoder_State *st /* i/o: decoder state structure */
);
#endif

void cldfb_restore_memory_ivas_fx(
    HANDLE_CLDFB_FILTER_BANK hs /* i/o: filter bank handle          */
+0 −12
Original line number Diff line number Diff line
@@ -166,11 +166,7 @@ ivas_error acelp_core_dec_fx(
            /* Only run parameter decoding in SID frames */
            IF( EQ_32( st->core_brate, SID_2k40 ) )
            {
#ifndef HARMONIZE_2494_FdCng_decodeSID_fx
                FdCng_decodeSID_ivas_fx( st );
#else
                FdCng_decodeSID_fx( st );
#endif

                Word16 n1, n2;
                n1 = L_norm_arr( st->hFdCngDec->hFdCngCom->sidNoiseEst, NPART );
@@ -663,21 +659,13 @@ ivas_error acelp_core_dec_fx(
                {
                    IF( EQ_16( st->element_mode, EVS_MONO ) )
                    {
#ifndef HARMONIZE_2494_FdCng_decodeSID_fx
                        FdCng_decodeSID_fx( st->hFdCngDec->hFdCngCom, st );
#else
                        FdCng_decodeSID_fx( st );
#endif
                    }
                    ELSE
                    {
                        Word16 old_NoiseEstExp = st->hFdCngDec->hFdCngCom->sidNoiseEstExp;
                        move16();
#ifndef HARMONIZE_2494_FdCng_decodeSID_fx
                        FdCng_decodeSID_ivas_fx( st );
#else
                        FdCng_decodeSID_fx( st );
#endif

                        Scale_sig32( st->hFdCngDec->hFdCngCom->sidNoiseEstLp, NPART, sub( old_NoiseEstExp, st->hFdCngDec->hFdCngCom->sidNoiseEstExp ) );
                        Scale_sig( st->hFdCngDec->hFdCngCom->A_cng, M + 1, sub( norm_s( st->hFdCngDec->hFdCngCom->A_cng[0] ), Q2 ) ); // Qx
+0 −4
Original line number Diff line number Diff line
@@ -521,11 +521,7 @@ Word16 dec_acelp_tcx_frame_fx(

        IF( EQ_16( st->m_frame_type, SID_FRAME ) )
        {
#ifndef HARMONIZE_2494_FdCng_decodeSID_fx
            FdCng_decodeSID_fx( st->hFdCngDec->hFdCngCom, st );
#else
            FdCng_decodeSID_fx( st );
#endif
        }

        /* updates */
+0 −270
Original line number Diff line number Diff line
@@ -2119,145 +2119,6 @@ void perform_noise_estimation_dec_ivas_fx(
}


#ifndef HARMONIZE_2494_FdCng_decodeSID_fx
/*
   FdCng_decodeSID_fx

    Parameters:

    st               i/o: FD_CNG structure containing all buffers and variables
    bs_word16        i  : Bitstream
    amrwb_io         i  : amr wideband mode
    preemph_fac      i  : preemphase factor

    Function:
    decode the FD-CNG bitstream

    Returns:
    void
*/
void FdCng_decodeSID_fx( HANDLE_FD_CNG_COM st, Decoder_State *corest )
{
    Word16 i, N, index;
    Word32 *sidNoiseEst;

    Word16 indices[32], v16[32];
    Word32 v[32], gain;

    Word32 tmp, maxVal, E_ExpLd64;
    Word16 sidNoiseEst_Exp;

    Word16 preemph_fac;
    Word32 *invTrfMatrix_fx;
    Word32 tmpRAM_fx[FDCNG_VQ_MAX_LEN][FDCNG_VQ_DCT_MAXTRUNC];
    invTrfMatrix_fx = (Word32 *) tmpRAM_fx;


    sidNoiseEst = st->sidNoiseEst; /*Q31 - st->sidNoiseEstExp*/
    move16();
    preemph_fac = corest->preemph_fac; /*Q15*/
    move16();

    N = st->npart; /*Q0*/
    move16();

    st->sid_frame_counter = add( st->sid_frame_counter, 1 ); /*Q15*/
    move16();

    /* Read bitstream */
    FOR( i = 0; i < stages_37bits; i++ )
    {
        indices[i] = get_next_indice_fx( corest, bits_37bits[i] ); /*Q0*/
        move16();
    }
    index = get_next_indice_fx( corest, 7 ); /*Q0*/

    /* MSVQ decoder */
    IF( corest->element_mode != EVS_MONO )
    {
        create_IDCT_N_Matrix_fx( invTrfMatrix_fx, FDCNG_VQ_MAX_LEN, FDCNG_VQ_DCT_MAXTRUNC, FDCNG_VQ_MAX_LEN * FDCNG_VQ_DCT_MAXTRUNC );
        msvq_dec_fx( ivas_cdk_37bits_fx, NULL, NULL, stages_37bits, N, maxN_37bits, indices, 1, invTrfMatrix_fx, v, NULL, 7 );
    }
    ELSE
    {
        msvq_decoder(
            cdk_37bits,
            stages_37bits,
            N,
            maxN_37bits,
            indices,
            v16 );

        FOR( i = 0; i < N; i++ )
        {
            v[i] = L_deposit_h( v16[i] ); /*Q23*/
            move32();
        }
    }


    /* decode gain, format gain: Q9.23 */
    gain = L_shl( L_deposit_l( index ), WORD32_BITS - 1 - 8 );
    gain = L_sub( gain, 503316480l /*60.0 Q23*/ );       /*Q23*/
    gain = Mpy_32_16_1( gain, 21845 /*2.0f/3.0f Q15*/ ); /*Q23*/


    /* Apply gain and undo log */

    /* calculate worst case for scaling */
    maxVal = L_add( 0x80000000 /*-1.0 Q31*/, 0 );
    FOR( i = 0; i < N; i++ )
    {
        maxVal = L_max( maxVal, v[i] ); /*Q23*/
    }

    maxVal = L_add( maxVal, gain );                                          /*Q23*/
    maxVal = L_shl( Mpy_32_16_1( maxVal, 21771 /*0.66438561897 Q15*/ ), 1 ); /*Q23*/

    sidNoiseEst_Exp = 0;
    move16();
    FOR( ; maxVal >= 0; maxVal -= 33554432l /*0.015625 Q31*/ )
    {
        sidNoiseEst_Exp = add( sidNoiseEst_Exp, 1 );
    }
    st->sidNoiseEstExp = sidNoiseEst_Exp;
    move16();
    E_ExpLd64 = L_shl( sidNoiseEst_Exp, WORD32_BITS - 1 - LD_DATA_SCALE );

    /* format v: Q9.23, format sidNoiseEst: Q6.26, 0.66438561897 = log10(10)/log10(2.0) / 10.0 * 2.0 */
    FOR( i = 0; i < N; i++ )
    {
        tmp = L_add( v[i], gain );                                         /*Q23*/
        tmp = L_shl( Mpy_32_16_1( tmp, 21771 /*0.66438561897 Q15*/ ), 1 ); /*Q23*/
        tmp = L_sub( tmp, E_ExpLd64 );
        assert( tmp < 0 );
        st->sidNoiseEst[i] = BASOP_Util_InvLog2( tmp ); /*Q31 - st->sidNoiseEstExp*/
        move32();
    }

    /* NB last band energy compensation */
    IF( st->CngBandwidth == NB )
    {
        st->sidNoiseEst[( N - 1 )] = Mpy_32_16_1( st->sidNoiseEst[( N - 1 )], NB_LAST_BAND_SCALE ); /*Q31 - st->sidNoiseEstExp*/
        move32();
    }

    test();
    IF( EQ_16( st->CngBandwidth, SWB ) && LE_32( st->CngBitrate, ACELP_13k20 ) )
    {
        st->sidNoiseEst[( N - 1 )] = Mpy_32_16_1( st->sidNoiseEst[( N - 1 )], SWB_13k2_LAST_BAND_SCALE ); /*Q31 - st->sidNoiseEstExp*/
        move32();
    }


    scalebands( sidNoiseEst, st->part, st->npart, st->midband, st->nFFTpart, sub( st->stopBand, st->startBand ), st->cngNoiseLevel, 1 );
    st->cngNoiseLevelExp = st->sidNoiseEstExp;
    move16();


    lpc_from_spectrum( st, st->startBand, st->stopFFTbin, preemph_fac );
}
#else
/*
   FdCng_decodeSID_fx

@@ -2435,7 +2296,6 @@ void FdCng_decodeSID_fx( Decoder_State *st )

    lpc_from_spectrum( hFdCngCom, hFdCngCom->startBand, hFdCngCom->stopFFTbin, st->preemph_fac );
}
#endif

/*
    noisy_speech_detection_fx
@@ -4509,136 +4369,6 @@ void configureFdCngDec_ivas_fx(
    return;
}

#ifndef HARMONIZE_2494_FdCng_decodeSID_fx
/*-------------------------------------------------------------------
 * FdCng_decodeSID_ivas_fx()
 *
 * Decode the FD-CNG bitstream
 *-------------------------------------------------------------------*/

void FdCng_decodeSID_ivas_fx(
    Decoder_State *st /* i/o: decoder state structure */
)
{
    Word16 N;
    Word32 *sidNoiseEst;
    Word32 gain;
    Word16 i, index;
    Word32 v[32];
    Word16 indices[32];
    HANDLE_FD_CNG_COM hFdCngCom;
    Word32 *invTrfMatrix_fx;
    Word32 tmpRAM_fx[FDCNG_VQ_MAX_LEN][FDCNG_VQ_DCT_MAXTRUNC];
    Word16 tmp16;

    IF( st->element_mode == EVS_MONO )
    {
        tmp16 = GAIN_Q_OFFSET_EVS_FX_Q0;
        move16();
    }
    ELSE
    {
        tmp16 = GAIN_Q_OFFSET_IVAS_FX_Q0;
        move16();
    }

    const Word16 gain_q_offset = tmp16; /* Q0 */
    move16();

    invTrfMatrix_fx = (Word32 *) tmpRAM_fx; /*Q31*/

    hFdCngCom = ( st->hFdCngDec )->hFdCngCom;

    sidNoiseEst = hFdCngCom->sidNoiseEst; /*Q16*/

    N = hFdCngCom->npart; /*Q0*/
    move16();
    gain = 0;
    move32();
    hFdCngCom->sid_frame_counter = add( hFdCngCom->sid_frame_counter, 1 );
    move16();

    /* Read bitstream */
    FOR( i = 0; i < FD_CNG_stages_37bits; i++ )
    {
        indices[i] = get_next_indice_fx( st, bits_37bits[i] ); /*Q0*/
        move16();
    }

    index = get_next_indice_fx( st, 7 );

    /* MSVQ decoder */

    IF( st->element_mode != EVS_MONO )
    {
        create_IDCT_N_Matrix_fx( invTrfMatrix_fx, FDCNG_VQ_MAX_LEN, FDCNG_VQ_DCT_MAXTRUNC, FDCNG_VQ_MAX_LEN * FDCNG_VQ_DCT_MAXTRUNC );
        msvq_dec_fx( ivas_cdk_37bits_fx, NULL, NULL, FD_CNG_stages_37bits, N, FD_CNG_maxN_37bits, indices, 1, invTrfMatrix_fx, v, NULL, 7 );
    }
    ELSE
    { /* Legacy EVS_MONO MSVQ tables */
        msvq_dec_fx( cdk_37bits, NULL, NULL, FD_CNG_stages_37bits, N, FD_CNG_maxN_37bits, indices, 0, NULL, v, NULL, 7 );
    }


    /* Decode gain */
    // gain = ((float)index - gain_q_offset) / 1.5f;
    gain = L_mult0( sub( index, gain_q_offset ), 21845 ); // Q15

    /* Apply gain and undo log */
    Word16 res_exp[NPART];
    Word16 max_res_exp = 0;
    move16();
    FOR( i = 0; i < N; i++ )
    {
        sidNoiseEst[i] = BASOP_util_Pow2( Mpy_32_32( L_add( v[i], gain ), LOG_10_BASE_2_BY_10_Q31 ), Q16, &res_exp[i] ); /*Q31 - res_exp[i]*/
        move32();
        if ( LT_16( max_res_exp, res_exp[i] ) )
        {
            max_res_exp = res_exp[i];
            move16();
        }
    }

    FOR( i = 0; i < N; i++ )
    {
        sidNoiseEst[i] = L_shr( sidNoiseEst[i], sub( max_res_exp, res_exp[i] ) ); /*Q31 - max_res_exp*/
        move32();
    }

    hFdCngCom->sidNoiseEstExp = max_res_exp;
    move16();

    /* NB last band energy compensation */

    IF( hFdCngCom->CngBandwidth == NB )
    {
        sidNoiseEst[( N - 1 )] = Mpy_32_16_1( sidNoiseEst[( N - 1 )], NB_LAST_BAND_SCALE ); /*Q31 - max_res_exp*/
        move32();
    }

    test();
    IF( EQ_16( hFdCngCom->CngBandwidth, SWB ) && LE_32( hFdCngCom->CngBitrate, ACELP_13k20 ) )
    {
        sidNoiseEst[( N - 1 )] = Mpy_32_16_1( sidNoiseEst[( N - 1 )], SWB_13k2_LAST_BAND_SCALE ); /*Q31 - max_res_exp*/
        move32();
    }

    scalebands( sidNoiseEst, hFdCngCom->part, hFdCngCom->npart, hFdCngCom->midband, hFdCngCom->nFFTpart, sub( hFdCngCom->stopBand, hFdCngCom->startBand ), hFdCngCom->cngNoiseLevel, 1 );
    Word16 shift1 = L_norm_arr( hFdCngCom->cngNoiseLevel, sub( hFdCngCom->stopBand, hFdCngCom->startBand ) );
    Word16 shift2 = L_norm_arr( hFdCngCom->cngNoiseLevel + sub( hFdCngCom->stopBand, hFdCngCom->startBand ), sub( FFTCLDFBLEN, sub( hFdCngCom->stopBand, hFdCngCom->startBand ) ) );
    Word16 shift = s_max( sub( hFdCngCom->sidNoiseEstExp, shift1 ), sub( hFdCngCom->cngNoiseLevelExp, shift2 ) );

    scale_sig32( hFdCngCom->cngNoiseLevel, sub( hFdCngCom->stopBand, hFdCngCom->startBand ), sub( hFdCngCom->sidNoiseEstExp, shift ) );
    scale_sig32( hFdCngCom->cngNoiseLevel + sub( hFdCngCom->stopBand, hFdCngCom->startBand ), sub( FFTCLDFBLEN, sub( hFdCngCom->stopBand, hFdCngCom->startBand ) ), sub( hFdCngCom->cngNoiseLevelExp, shift ) );

    hFdCngCom->cngNoiseLevelExp = shift;
    move16();

    lpc_from_spectrum( hFdCngCom, hFdCngCom->startBand, hFdCngCom->stopFFTbin, st->preemph_fac );

    return;
}
#endif /*HARMONIZE_2494_FdCng_decodeSID_fx*/

/*-------------------------------------------------------------------
 * generate_masking_noise_ivas_fx()