Commit 6592dd4e authored by Nicolas Roussin's avatar Nicolas Roussin
Browse files

Merge branch 'main' into...

Merge branch 'main' into basop-2267-cleanup-ivas_dirac_dec_binaural_functions_fx-c-from-be-opt-flags
parents 537e7360 f8bb73a7
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -2731,7 +2731,11 @@ extern const Word16 Idx2Freq_Tbl[];
/* 'x' is converted to Q6, 'Freq_Tbl'/1000 in Q9 */
/* only works for 'fs' = [8000,12800,16000,25600,32000,48000] (unpredictable otherwise) */
/* 15625 is 1000000.0f/Q6 but we use the calculated value to avoid float point code */
#ifdef FIX_2286_GCC_WARNING_Idx2Freq_Tbl
#define NS2SA_FX2(fs,x)                         (chk_fs(fs) mult(Idx2Freq_Tbl[L_and(L_shr(fs,8),7)-2], (Word16)((x)/15625)))
#else
#define NS2SA_FX2(fs,x)                         (chk_fs(fs) mult((&Idx2Freq_Tbl[-2])[L_and(L_shr(fs,8),7)], (Word16)((x)/15625)))
#endif

#define L_FRAME_12k8                            256     /* Frame size at 12k8Hz: 20ms = 256 samples  */
#define L_FRAME_16k                             320     /* Frame size at 16kHz:  20ms = 320 samples  */
+0 −110
Original line number Diff line number Diff line
@@ -58,11 +58,7 @@ ivas_error createFdCngCom_fx(
 *
 *-------------------------------------------------------------------*/

#ifdef FIX_2245_INIT_FD_CNG_EVS
void initFdCngCom(
#else
void ivas_initFdCngCom_fx(
#endif
    HANDLE_FD_CNG_COM hFdCngCom,
    Word16 scale )
{
@@ -178,112 +174,6 @@ void ivas_initFdCngCom_fx(
    return;
}

#ifndef FIX_2245_INIT_FD_CNG_EVS
void initFdCngCom( HANDLE_FD_CNG_COM hFdCngCom, Word16 scale )
{
    /* Calculate CLDFB scaling factor */
    /* shl(i_mult2(scale, scale), 3) does not fit in 16 bit */
    /*hFdCngCom->scalingFactor = div_s(1, shl(i_mult2(scale, scale), 3));*/
    assert( 2048 /*1.0/(1<<4) Q15*/ < mult( scale, scale ) );
    /* Exponent invScalingFactor: -16 = -(2*7 (scale) + 2 (8.0) */
    hFdCngCom->invScalingFactor = shl( mult( scale, scale ), 1 );
    move16();
    /* Exponent scalingFactor: -15 = -(2*7 (scale) + 2 (8.0) - 1 (1.0)) */
    hFdCngCom->scalingFactor = div_s( 0x4000, hFdCngCom->invScalingFactor );
    move16();

    /* Initialize the overlap-add */
    set16_fx( hFdCngCom->timeDomainBuffer, 0, L_FRAME16k );
    hFdCngCom->olapBufferAna = NULL;
    set16_fx( hFdCngCom->olapBufferAna_fx, 0, FFTLEN );

    set16_fx( hFdCngCom->olapBufferSynth, 0, FFTLEN );
    hFdCngCom->olapBufferSynth2 = NULL;

    /* Initialize the comfort noise generation */
    set32_fx( hFdCngCom->fftBuffer, 0, FFTLEN );
    set32_fx( hFdCngCom->cngNoiseLevel, 0, FFTCLDFBLEN );
    set16_fx( &hFdCngCom->cngNoiseLevelExp, 0, 1 );

    /* Initialize quantizer */
    set32_fx( hFdCngCom->sidNoiseEst, 0, NPART );
    set16_fx( &hFdCngCom->sidNoiseEstExp, 0, 1 );
    set16_fx( hFdCngCom->A_cng, 0, M + 1 );
    hFdCngCom->A_cng[0] = 4096 /*1.f Q12*/; /* 3Q12 */
    move16();

    /* Set some counters and flags */
    hFdCngCom->inactive_frame_counter = 0; /* Either SID or zero frames */
    move16();
    hFdCngCom->active_frame_counter = 0;
    move16();
    hFdCngCom->frame_type_previous = ACTIVE_FRAME;
    move16();
    hFdCngCom->flag_noisy_speech = 0;
    move16();
    hFdCngCom->likelihood_noisy_speech = 0;
    move16();
    hFdCngCom->numCoreBands = 0;
    move16();
    hFdCngCom->stopBand = 0;
    move16();
    hFdCngCom->startBand = 0;
    move16();
    hFdCngCom->stopFFTbin = 0;
    move16();
    hFdCngCom->frameSize = 0;
    move16();
    hFdCngCom->fftlen = 0;
    move16();
    hFdCngCom->seed = 0;
    move16();
    // hFdCngCom->seed2 = 1;
    // move16();
    // hFdCngCom->seed3 = 2;
    // move16();
    hFdCngCom->CngBitrate = -1;
    move16();

    /* Initialize noise estimation algorithm */
    set32_fx( hFdCngCom->periodog, 0, PERIODOGLEN );
    mhvals( MSNUMSUBFR * MSSUBFRLEN, &( hFdCngCom->msM_win ) );
    mhvals( MSSUBFRLEN, &( hFdCngCom->msM_subwin ) );
    set32_fx( hFdCngCom->msPeriodogSum, 0, 2 );
    hFdCngCom->msPeriodogSum_exp[0] = 0;
    move16();
    hFdCngCom->msPeriodogSum_exp[1] = 0;
    move16();
    set32_fx( hFdCngCom->msPsdSum, 0, 2 );
    set16_fx( hFdCngCom->msSlope, 0, 2 );
    set32_fx( hFdCngCom->msQeqInvAv, 0, 2 );
    hFdCngCom->msQeqInvAv_exp[0] = 0;
    move16();
    hFdCngCom->msQeqInvAv_exp[1] = 0;
    move16();
    hFdCngCom->msFrCnt_init_counter = 0;
    move16();
    hFdCngCom->msFrCnt_init_thresh = 1;
    move16();
    hFdCngCom->init_old = 0;
    move16();
    hFdCngCom->offsetflag = 0;
    move16();
    hFdCngCom->msFrCnt = MSSUBFRLEN;
    move16();
    hFdCngCom->msMinBufferPtr = 0;
    move16();
    hFdCngCom->msAlphaCor[0] = 644245120l /*0.3f Q31*/;
    move16();
    hFdCngCom->msAlphaCor[1] = 644245120l /*0.3f Q31*/;
    move16();
    set16_fx( hFdCngCom->psize, 0, NPART );
    /* Initialize exponents */
    hFdCngCom->exp_cldfb_periodog = 0;
    move16();

    return;
}
#endif
/*-------------------------------------------------------------------
 * deleteFdCngCom()
 *
+26 −7
Original line number Diff line number Diff line
@@ -260,7 +260,8 @@ void Comp_and_apply_gain_ivas_fx(
/* _ None                                                                 */
/*========================================================================*/

static Word16 Comp_band_log_ener(                      /* o  : Band gain Q12 */
/* o  : Band gain Q12 */
static Word16 Comp_band_log_ener(
    const Word16 *pt_fx, /* i  : Dct input Q_sc */
    const Word16 Len,    /* i  : Lenght en energy accumulation */
    const Word16 Q_sc,   /* i  : scaling of input    */
@@ -269,12 +270,14 @@ static Word16 Comp_band_log_ener( /* o : Band gain Q12 */
{
    Word32 L_tmp;
    Word16 e_tmp, f_tmp, tmp16, ener_exp;

    L_tmp = Calc_Energy_Autoscaled( pt_fx, Q_sc, Len, &ener_exp );
    e_tmp = norm_l( L_tmp );
    f_tmp = Log2_norm_lc( L_shl( L_tmp, e_tmp ) );
    e_tmp = sub( sub( add( 30, E_sc ), e_tmp ), ener_exp );
    L_tmp = Mpy_32_16( e_tmp, f_tmp, 19728 ); /* Q16 */ /*log10(2) in Q17 */
    tmp16 = round_fx( L_shl( L_tmp, 12 - 2 ) );         /* Q12 -1 is to compensate Q17 */

    return tmp16;
}

@@ -283,7 +286,12 @@ void Ener_per_band_comp_fx(
    Word16 y_gain4_fx[],        /* o  : Energy per band to quantize       Q12            */
    const Word16 Q_exc,         /* i  : frame length                      */
    const Word16 Mband,         /* i  : Max band                          */
#ifdef FIX_1904_HARM_GSC_ENC
    const Word16 Eflag,  /* i  : flag of highest band              */
    const Word16 L_frame /* i  : frame length                      */
#else
    const Word16 Eflag /* i  : flag of highest band              */
#endif
)
{
    const Word16 *pt_fx;
@@ -311,9 +319,19 @@ void Ener_per_band_comp_fx(
        pt_fx += 32;
    }

    return;
#ifdef FIX_1904_HARM_GSC_ENC
    IF( EQ_16( L_frame, L_FRAME16k ) )
    {
        y_gain4_fx[j + 2] = Comp_band_log_ener( pt_fx, 32, Q_exc, -1 ); /*Q12*/
        move16();
        y_gain4_fx[j + 3] = Comp_band_log_ener( pt_fx, 64, Q_exc, -1 ); /*Q12*/
        move16();
    }
#endif

    return;
}
#ifndef FIX_1904_HARM_GSC_ENC
void Ener_per_band_comp_ivas_fx(
    const Word16 exc_diff_fx[], /* i  : target signal                     Q_exc_diff     */
    Word16 y_gain4_fx[],        /* o  : Energy per band to quantize       Q12            */
@@ -359,6 +377,7 @@ void Ener_per_band_comp_ivas_fx(

    return;
}
#endif


/*-------------------------------------------------------------------*
+13 −0
Original line number Diff line number Diff line
@@ -77,7 +77,11 @@ void Inac_switch_ematch_fx(
    test();
    IF( ( EQ_16( coder_type, AUDIO ) || ( EQ_16( coder_type, UNVOICED ) && EQ_16( tdm_low_rate_mode, 1 ) ) ) && bfi == 0 )
    {
#ifdef FIX_1904_HARM_GSC_ENC
        Ener_per_band_comp_fx( dct_exc_tmp, Ener_per_bd, Q_exc, MBANDS_GN, 1, L_frame );
#else
        Ener_per_band_comp_ivas_fx( dct_exc_tmp, Ener_per_bd, Q_exc, MBANDS_GN, 1, L_frame );
#endif

        /* reset long-term energy per band */
        FOR( i = 0; i < MBANDS_GN; i++ )
@@ -91,7 +95,11 @@ void Inac_switch_ematch_fx(
        /* Find spectrum and energy per band for GC and VC frames */
        edct_16fx( exc2, dct_exc_tmp, L_frame, 5, element_mode );

#ifdef FIX_1904_HARM_GSC_ENC
        Ener_per_band_comp_fx( dct_exc_tmp, Ener_per_bd, Q_exc, MBANDS_GN, 1, L_frame );
#else
        Ener_per_band_comp_ivas_fx( dct_exc_tmp, Ener_per_bd, Q_exc, MBANDS_GN, 1, L_frame );
#endif

        /* reset long-term energy per band */
        FOR( i = 0; i < MBANDS_GN; i++ )
@@ -104,7 +112,12 @@ void Inac_switch_ematch_fx(
    {
        /* Find spectrum and energy per band for inactive frames */
        edct_16fx( exc2, dct_exc_tmp, L_frame, 5, element_mode );

#ifdef FIX_1904_HARM_GSC_ENC
        Ener_per_band_comp_fx( dct_exc_tmp, Ener_per_bd, Q_exc, MBANDS_GN, 1, L_frame );
#else
        Ener_per_band_comp_ivas_fx( dct_exc_tmp, Ener_per_bd, Q_exc, MBANDS_GN, 1, L_frame );
#endif

        /* More agressive smoothing in the first 50 frames */
        pt_exc = dct_exc_tmp;
+27 −2
Original line number Diff line number Diff line
@@ -636,7 +636,7 @@ static void envelop_modify_fx(

    return;
}

#ifndef FIX_1904_HARM_GSC_ENC
void highband_exc_dct_in_fx(
    const Word32 core_brate,         /* i  : core bitrate                            */
    const Word16 *mfreq_bindiv,      /* i  : bin per bands tables                    */
@@ -801,12 +801,19 @@ void highband_exc_dct_in_fx(
    test();
    IF( EQ_32( core_brate, ACELP_8k00 ) && NE_16( bwidth, NB ) )
    {
#ifdef FIX_1904_HARM_GSC_ENC
        Ener_per_band_comp_fx( exc_diffQ, Ener_per_bd_yQ, Qexc_diffQ, add( last_bin, 1 ), 0, L_frame );
#else
        Ener_per_band_comp_fx( exc_diffQ, Ener_per_bd_yQ, Qexc_diffQ, add( last_bin, 1 ), 0 );
#endif
    }
    ELSE
    {
#ifdef FIX_1904_HARM_GSC_ENC
        Ener_per_band_comp_fx( exc_diffQ, Ener_per_bd_yQ, Qexc_diffQ, MBANDS_GN, 1, L_frame );
#else
        Ener_per_band_comp_fx( exc_diffQ, Ener_per_bd_yQ, Qexc_diffQ, MBANDS_GN, 1 );

#endif
        IF( LT_16( nb_subfr, 4 ) && LT_16( L_frame, L_FRAME16k ) )
        {
            FOR( i = L_FRAME - 16; i < L_FRAME; i++ )
@@ -1010,8 +1017,14 @@ void highband_exc_dct_in_fx(

    return;
}
#endif


#ifdef FIX_1904_HARM_GSC_ENC
void highband_exc_dct_in_fx(
#else
void highband_exc_dct_in_ivas_fx(
#endif
    const Word32 core_brate,         /* i  : core bitrate                            */
    const Word16 *mfreq_bindiv,      /* i  : bin per bands tables                    */
    Word16 last_bin,                 /* i  : last bin of bit allocation              */
@@ -1168,19 +1181,29 @@ void highband_exc_dct_in_ivas_fx(
    {
        Apply_NoiseFill_fx( exc_diffQ, seed_tcx, noisepb, Diff_len, last_bin, coder_type, mfreq_bindiv, Qexc_diffQ );
    }

    /*--------------------------------------------------------------------------------------*
     * Quantize average gain
     * Subtract Q averaged gain
     * VQ of remaining gain per band
     *--------------------------------------------------------------------------------------*/

    test();
    IF( EQ_32( core_brate, ACELP_8k00 ) && NE_16( bwidth, NB ) )
    {
#ifdef FIX_1904_HARM_GSC_ENC
        Ener_per_band_comp_fx( exc_diffQ, Ener_per_bd_yQ, Qexc_diffQ, add( last_bin, 1 ), 0, L_frame );
#else
        Ener_per_band_comp_ivas_fx( exc_diffQ, Ener_per_bd_yQ, Qexc_diffQ, add( last_bin, 1 ), 0, L_frame );
#endif
    }
    ELSE
    {
#ifdef FIX_1904_HARM_GSC_ENC
        Ener_per_band_comp_fx( exc_diffQ, Ener_per_bd_yQ, Qexc_diffQ, MBANDS_GN, 1, L_frame );
#else
        Ener_per_band_comp_ivas_fx( exc_diffQ, Ener_per_bd_yQ, Qexc_diffQ, MBANDS_GN, 1, L_frame );
#endif

        test();
        IF( LT_16( nb_subfr, 4 ) && LT_16( L_frame, L_FRAME16k ) )
@@ -1195,9 +1218,11 @@ void highband_exc_dct_in_ivas_fx(
            }
        }
    }

    /*--------------------------------------------------------------------------------------*
     * Check potential energy excitation overshoot
     *--------------------------------------------------------------------------------------*/

    IF( bfi )
    {
        test();
Loading