Commit 8c790d24 authored by multrus's avatar multrus
Browse files

[cleanup] accept HARMONIZE_2597_ShapeSpectrum

parent f358aa44
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -86,7 +86,6 @@
#define FIX_1990_SANITIZER_IN_REVERB_LOAD               /* Nokia: Fix issue part of issue 1990 by introducing missing free of structure - keep until #2059 is addressed */
#define TMP_1342_WORKAROUND_DEC_FLUSH_BROKEN_IN_SR      /* FhG: Temporary workaround for incorrect implementation of decoder flush with split rendering */
#define NONBE_1122_KEEP_EVS_MODE_UNCHANGED              /* FhG: Disables fix for issue 1122 in EVS mode to keep BE tests green. This switch should be removed once the 1122 fix is added to EVS via a CR.  */
#define HARMONIZE_2597_ShapeSpectrum                    /* FhG: Harmonize ShapeSpectrum with its ivas derivate */
#define HARMONIZE_2567_init_functions                   /* FhG: harmonize derivates for evs/ivas regarding functions init_acelp*(),init_tcx_cfg*(), init_tcx*(), init_coder_ace_plus*(), init_core_sig_ana*() and init_modes*() */
#define HARMONIZE_2607_GetFilterParameters              /* FhG: Harmonize GetFilterParameters with its ivas derivate */
#define HAMRONIZE_2606_ENC_PRM                          /* FhG: Harmonize enc_prm_fx(), to match floating-point code */
+0 −258
Original line number Diff line number Diff line
@@ -221,253 +221,8 @@ void TNSAnalysis_fx(
    }
}

#ifndef HARMONIZE_2597_ShapeSpectrum
void ShapeSpectrum_fx(
    TCX_CONFIG_HANDLE hTcxCfg, /* i  : configuration of TCX               */
    Word16 A[],                /* input: quantized coefficients NxAz_q[M+1]  Q = 14 - norm(A[0])*/
    Word16 gainlpc[],          /* output: MDCT gains for the previous frame Q(15-gainlpc_e)*/
    Word16 gainlpc_e[],        /* output: MDCT gains exponents */
    Word16 L_frame_glob,       /* input: frame length             */
    Word16 L_spec,
    Word32 spectrum[], /* i/o: MDCT spectrum */
    Word8 pfUseTns,    /* output: Flag indicating if TNS is used */
    Encoder_State *st )
{
    Word16 L_frame;
    Word16 Ap[M + 2];
    Word16 gamma1;
    Word16 gainlpc_noinv[FDNS_NPTS];
    Word16 gainlpc_noinv_e[FDNS_NPTS];
    Word16 i;
    Word32 max_low_pre = 0, max_high_pre = 0;
    move32();
    move32();
    TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc;

    /*-----------------------------------------------------------*
     * Init                                                      *
     *-----------------------------------------------------------*/

    /* Init lengths */
    L_frame = L_frame_glob;
    move16();
    gamma1 = st->gamma;
    move16();
    if ( st->enableTcxLpc != 0 )
    {
        gamma1 = 0x7FFF;
        move16();
    }

    /* if past frame is ACELP */

    IF( st->last_core == ACELP_CORE )
    {
        L_frame = add( L_frame, hTcxCfg->tcx_offset );
        L_spec = add( L_spec, shr( hTcxCfg->tcx_coded_lines, 2 ) );
        if ( hTcxCfg->lfacNext < 0 )
        {
            L_frame = sub( L_frame, hTcxCfg->lfacNext );
            move16();
        }
    }

    test();
    tcxGetNoiseFillingTilt( A,
                            M,
                            L_frame,
                            ( GE_32( st->total_brate, ACELP_13k20 ) && st->rf_mode == 0 ),
                            &hTcxEnc->noiseTiltFactor );

    /* Calculate Spectrum Flatness Measure for the TCX Concealment */
    IF( st->enablePlcWaveadjust )
    {
        hTcxCfg->SFM2 = SFM_Cal_fx( spectrum, s_min( 200, L_frame ) );
        move32();
    }

    test();
    test();
    test();
    IF( ( EQ_32( st->total_brate, ACELP_9k60 ) && EQ_16( st->bwidth, SWB ) ) ||
        ( EQ_32( st->total_brate, ACELP_13k20 ) && EQ_16( st->bwidth, SWB ) ) )
    {
        max_low_pre = 0;
        move32();
        FOR( i = 0; i < L_frame; i++ )
        {
            Word32 tmp = L_abs( spectrum[i] );
            if ( GT_32( tmp, max_low_pre ) )
            {
                max_low_pre = tmp;
                move32();
            }
        }

        max_high_pre = 0;
        move32();
        FOR( i = 0; i < L_spec - L_frame; i++ )
        {
            Word32 tmp = L_abs( spectrum[L_frame + i] );
            if ( GT_32( tmp, max_high_pre ) )
            {
                max_high_pre = tmp;
                move32();
            }
        }
    }

    /*-----------------------------------------------------------*
     * Pre-shaping in frequency domain using weighted LPC (Wz)   *
     *-----------------------------------------------------------*/

    weight_a_fx( A, Ap, gamma1, M );

    lpc2mdct( Ap, M, gainlpc_noinv, gainlpc_noinv_e, gainlpc, gainlpc_e, FDNS_NPTS, 0 );

    mdct_shaping( spectrum, L_frame, gainlpc_noinv, gainlpc_noinv_e );
    FOR( i = L_frame; i < L_spec; i++ )
    {
        spectrum[i] = L_shl( Mpy_32_16_1( spectrum[i], gainlpc_noinv[FDNS_NPTS - 1] ), gainlpc_noinv_e[FDNS_NPTS - 1] );
        move32();
    }

    /* reduce the peaks in the IGF region, to make life of the core-coder easier... */
    test();
    test();
    test();
    IF( ( EQ_32( st->total_brate, ACELP_9k60 ) && EQ_16( st->bwidth, SWB ) ) ||
        ( EQ_32( st->total_brate, ACELP_13k20 ) && EQ_16( st->bwidth, SWB ) ) )
    {
        Word16 sf_width;
        Word16 dist_low, dist_high;
        Word16 max_fac_s, max_fac_m;
        Word32 max_low, max_low1, max_low2, max_high;
        Word16 headroom, shift, tmp16;


        max_fac_m = 24576;
        move16();
        /* max_fac = 3 */
        max_fac_s = 2;
        move16();
        if ( hTcxEnc->tcx_lpc_shaped_ari )
        {
            /* max_fac = 1.5 */
            max_fac_s = 1;
            move16();
        }

        sf_width = shr( L_frame, 1 );

        max_low2 = 0;
        move32();
        dist_low = 0;
        move16();
        FOR( i = 0; i < sf_width; i++ )
        {
            Word32 tmp = L_abs( spectrum[L_frame - 1 - i] );
            IF( GT_32( tmp, max_low2 ) )
            {
                max_low2 = tmp;
                move32();
                dist_low = i;
                move16();
            }
        }

        max_low1 = 0;
        move32();
        FOR( i = 0; i < ( L_frame - sf_width ); i++ )
        {
            Word32 tmp = L_abs( spectrum[L_frame - sf_width - 1 - i] );
            if ( GT_32( tmp, max_low1 ) )
            {
                max_low1 = tmp;
                move32();
            }
            if ( GT_32( tmp, max_low2 ) )
            {
                dist_low = add( sf_width, i );
            }
        }

        max_low = L_max( max_low1, max_low2 );

        max_high = 0;
        move32();
        dist_high = 0;
        move16();
        FOR( i = 0; i < ( L_spec - L_frame ); i++ )
        {
            Word32 tmp = L_abs( spectrum[L_frame + i] );
            IF( GT_32( tmp, max_high ) )
            {
                max_high = tmp;
                move32();
                dist_high = i;
                move16();
            }
        }

        /* at least 9 bits headroom are needed for below multiplicitions */
        shift = 0;
        move16();
        headroom = 31;
        move16();

        tmp16 = norm_l( max_low );
        if ( max_low != 0 )
            headroom = s_min( headroom, tmp16 );

        tmp16 = norm_l( max_low2 );
        if ( max_low2 != 0 )
            headroom = s_min( headroom, tmp16 );

        tmp16 = norm_l( max_high );
        if ( max_high != 0 )
            headroom = s_min( headroom, tmp16 );

        if ( LT_16( headroom, 9 ) )
        {
            shift = sub( 9, headroom );
        }
        max_low = L_shr( max_low, shift );
        max_low2 = L_shr( max_low2, shift );
        max_high = L_shr( max_high, shift );

        test();
        test();
        IF( GT_32( imult3216( max_high, dist_high ), imult3216( L_shr( max_low, 2 ), dist_low ) ) && ( GT_32( max_low_pre, L_shr( max_high_pre, 4 ) ) ) && ( GT_32( max_high, L_shl( Mpy_32_16_r( max_low2, max_fac_m ), max_fac_s ) ) ) )
        {
            Word16 fac;
            fac = divide3232( max_low2, max_high );
            fac = shl( mult_r( fac, max_fac_m ), max_fac_s );

            FOR( i = 0; i < sub( L_spec, L_frame ); i++ )
            {
                spectrum[L_frame + i] = Mpy_32_16_1( spectrum[L_frame + i], fac );
                move32();
            }
        }
    }


    test();
    test();
    test();
    IF( st->tcxonly && hTcxEnc->tcxltp && ( hTcxEnc->tcxltp_gain > 0 ) && !pfUseTns )
    {
        PsychAdaptLowFreqEmph_fx( spectrum, gainlpc, gainlpc_e );
    }
}
#endif

#ifdef HARMONIZE_2597_ShapeSpectrum
void ShapeSpectrum_fx(
#else
void ShapeSpectrum_ivas_fx(
#endif
    TCX_CONFIG_HANDLE hTcxCfg, /* i  : configuration of TCX               */
    Word16 A[],                /* input: quantized coefficients NxAz_q[M+1], Q = 14 - norm(A[0]) */
    Word16 gainlpc[],          /* output: MDCT gains for the previous frame Q(15-gainlpc_e)*/
@@ -731,11 +486,7 @@ void ShapeSpectrum_ivas_fx(
        {
            Word16 fac;
            fac = divide3232( max_low2, max_high );
#ifdef HARMONIZE_2597_ShapeSpectrum
            IF( GE_16( norm_s( fac ), max_fac_s ) || EQ_16( st->element_mode, EVS_MONO ) )
#else
            IF( GE_16( norm_s( fac ), max_fac_s ) )
#endif
            {
                fac = shl( mult_r( fac, max_fac_m ), max_fac_s );
                FOR( i = 0; i < ( L_spec - L_frame ); i++ )
@@ -3807,7 +3558,6 @@ void coder_tcx_fx(
        ProcessIGF_fx( st, 0, spectrum, &q_spectrum, NULL, 0, powerSpec, &powerSpec_e, 1, 0, 0, 0 );
    }

#ifdef HARMONIZE_2597_ShapeSpectrum
    ShapeSpectrum_fx( hTcxCfg, A, gainlpc, gainlpc_e,
                      L_frame_glob,
                      L_spec,
@@ -3816,14 +3566,6 @@ void coder_tcx_fx(
                      hTcxEnc->fUseTns[0],
                      st,
                      0 );
#else
    ShapeSpectrum_fx( hTcxCfg, A, gainlpc, gainlpc_e,
                      L_frame_glob,
                      L_spec,
                      spectrum,
                      hTcxEnc->fUseTns[0],
                      st );
#endif
    if ( st->igf )
    {
        nb_bits = sub( nb_bits, st->hIGFEnc->infoTotalBitsPerFrameWritten );
+0 −24
Original line number Diff line number Diff line
@@ -171,7 +171,6 @@ void core_encode_twodiv_fx(
            }

            /* Shape spectrum */
#ifdef HARMONIZE_2597_ShapeSpectrum
            ShapeSpectrum_fx( st->hTcxCfg,
                              A_q,
                              gainlpc[n],
@@ -183,17 +182,6 @@ void core_encode_twodiv_fx(
                              hTcxEnc->fUseTns[n],
                              st,
                              0 );
#else
            ShapeSpectrum_fx( st->hTcxCfg,
                              A_q,
                              gainlpc[n],
                              gainlpc_e[n],
                              shr( st->L_frame, 1 ),
                              shr( st->hTcxCfg->tcx_coded_lines, 1 ),
                              spectrum[n],
                              hTcxEnc->fUseTns[n],
                              st );
#endif

            st->last_core = st->core;
            move16();
@@ -280,7 +268,6 @@ void core_encode_twodiv_fx(

        E_LPC_f_lsp_a_conversion( lsp_q, A_q, M );

#ifdef HARMONIZE_2597_ShapeSpectrum
        ShapeSpectrum_fx( st->hTcxCfg,
                          A_q,
                          gainlpc[0],
@@ -292,17 +279,6 @@ void core_encode_twodiv_fx(
                          hTcxEnc->fUseTns[0],
                          st,
                          0 );
#else
        ShapeSpectrum_fx( st->hTcxCfg,
                          A_q,
                          gainlpc[0],
                          gainlpc_e[0],
                          st->L_frame,
                          st->hTcxCfg->tcx_coded_lines,
                          spectrum[0],
                          hTcxEnc->fUseTns[0],
                          st );
#endif

        /*_DIFF_FLOAT_FIX_EVS_IVAS  -> The line below is present in float */
        // hTcxEnc->measuredBwRatio = 0x4000;
+0 −8
Original line number Diff line number Diff line
@@ -2105,11 +2105,7 @@ void ivas_mdct_core_whitening_enc_fx(
            move16();

            /* Shape spectrum */
#ifdef HARMONIZE_2597_ShapeSpectrum
            ShapeSpectrum_fx( st->hTcxCfg, A_q_fx[ch][n], NULL, NULL, L_subframe, tcx_subframe_coded_lines, st->hTcxEnc->spectrum_fx[n], &st->hTcxEnc->spectrum_e[n], st->hTcxEnc->fUseTns[n], st, scf_q_fx[ch][n] );
#else
            ShapeSpectrum_ivas_fx( st->hTcxCfg, A_q_fx[ch][n], NULL, NULL, L_subframe, tcx_subframe_coded_lines, st->hTcxEnc->spectrum_fx[n], &st->hTcxEnc->spectrum_e[n], st->hTcxEnc->fUseTns[n], st, scf_q_fx[ch][n] );
#endif

            Scale_sig32( st->hTcxEnc->spectrum_fx[n] + L_subframe, sub( L_subframeTCX, L_subframe ), sub( exp_tmp, st->hTcxEnc->spectrum_e[n] ) );
        }
@@ -2249,11 +2245,7 @@ void ivas_mdct_core_whitening_enc_fx(
                move16();

                /* Shape spectrum */
#ifdef HARMONIZE_2597_ShapeSpectrum
                ShapeSpectrum_fx( st->hTcxCfg, A_q_fx[ch][n], NULL, NULL, L_subframe, tcx_subframe_coded_lines, mdst_spectrum_fx[ch][n], &mdst_spectrum_e[ch][n], st->hTcxEnc->fUseTns[n], st, scf_q_fx[ch][n] );
#else
                ShapeSpectrum_ivas_fx( st->hTcxCfg, A_q_fx[ch][n], NULL, NULL, L_subframe, tcx_subframe_coded_lines, mdst_spectrum_fx[ch][n], &mdst_spectrum_e[ch][n], st->hTcxEnc->fUseTns[n], st, scf_q_fx[ch][n] );
#endif

                Scale_sig32( mdst_spectrum_fx[ch][n] + L_subframe, sub( L_subframeTCX, L_subframe ), sub( exp_tmp, mdst_spectrum_e[ch][n] ) );
            }
+0 −4
Original line number Diff line number Diff line
@@ -503,11 +503,7 @@ void stereo_tcx_core_enc(
        bitsAvailable = sub( bitsAvailable, nbits_lpc[n] );

        /* Shape spectrum */
#ifdef HARMONIZE_2597_ShapeSpectrum
        ShapeSpectrum_fx( st->hTcxCfg, A_q_fx, gainlpc_fx[n], gainlpc_e[n], st->L_frame / n_subframes, st->hTcxCfg->tcx_coded_lines / n_subframes, hTcxEnc->spectrum_fx[n], &hTcxEnc->spectrum_e[n], hTcxEnc->fUseTns[n], st, NULL );
#else
        ShapeSpectrum_ivas_fx( st->hTcxCfg, A_q_fx, gainlpc_fx[n], gainlpc_e[n], st->L_frame / n_subframes, st->hTcxCfg->tcx_coded_lines / n_subframes, hTcxEnc->spectrum_fx[n], &hTcxEnc->spectrum_e[n], hTcxEnc->fUseTns[n], st, NULL );
#endif

        st->last_core = st->core;
        move16();
Loading