Commit afb95fbf authored by multrus's avatar multrus
Browse files

[cleanup] accept HARMONIZE_2598_tcx_arith_encode_envelope

parent 56cf2e5f
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_2598_tcx_arith_encode_envelope        /* FhG: harmonize tcx_arith_encode_envelope between EVS and IVAS versions */
#define FIX_ISSUE_2594_FALSE_COMMENT                    /* FhG: basop issue 2594: fixing false comments about Q value*/
#define FIX_ISSUE_2616_BOUNDARY_CONDITION               /* FhG: basop issue 2616: Inconsistent boundary conditions in function stereo_dft_dequantize_res_gains*/
#define FIX_ISSUE_2613_WRONG_COMP_MACRO                 /* FhG: basop issue 2613: Inconsistent comparison macros in function tdm_SCh_LSF_intra_pred_fx*/
+0 −171
Original line number Diff line number Diff line
@@ -658,151 +658,7 @@ static Word16 tcx_arith_encode(
 *
 *
 *-------------------------------------------------------------------*/
#ifndef HARMONIZE_2598_tcx_arith_encode_envelope
void tcx_arith_encode_envelope_fx(
    Word32 spectrum[],          /* i/o: MDCT coefficients             Q31-e */
    Word16 *spectrum_e,         /* i/o: MDCT exponent                 Q0 */
    Word16 signs[],             /* o  : signs (spectrum[.]<0)         Q0 */
    const Word16 L_frame,       /* i  : frame or MDCT length          Q0 */
    const Word16 L_spec,        /* i  : frame or MDCT length          Q0 */
    Encoder_State *st,          /* i/o: coder state                   */
    const Word16 A_ind[],       /* i  : quantised LPC coefficients    Q12 */
    Word16 target_bits,         /* i  : number of available bits      Q0 */
    Word16 prm[],               /* o  : bitstream parameters          Q0 */
    const Word8 use_hm,         /* i  : use HM in current frame?      */
    Word16 prm_hm[],            /* o  : HM parameter area             Q0 */
    const Word16 tcxltp_pitch,  /* i  : TCX LTP pitch in FD, -1 if n/a  Q0*/
    Word16 *arith_bits,         /* o  : bits used for ari. coding     Q0 */
    Word16 *signaling_bits,     /* o  : bits used for signaling       Q0 */
    Word16 *nf_seed,            /* o  : noise filling seed            Q0 */
    const Word16 low_complexity /* i  : low-complexity flag           Q0 */
)
{
    Word32 env[N_MAX_ARI]; /* unscaled envelope (Q16) */
    Word16 *envelope;      /* scaled envelope (Q15-e) */
    Word16 envelope_e;
    Word16 exponents[N_MAX_ARI]; /* Q15 */
    Word16 L_spec_core;
    Word16 *q_spectrum;
    TCX_CONFIG_HANDLE hTcxCfg;
    Word16 scale, scale_e;
    Word16 k, kMax;
    Word16 deadzone;
    const Word8 *deadzone_flags;
    Word16 gamma_w, gamma_uw;
    Word16 hm_bits;
    Word32 L_tmp;
    Word64 W_tmp2;
    Word16 tmp;
    TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc;

    assert( L_spec <= N_MAX_ARI );

    hTcxCfg = st->hTcxCfg;
    deadzone = hTcxCfg->sq_rounding;
    move16();
    deadzone_flags = hTcxEnc->memQuantZeros;
    *signaling_bits = 0;
    move16();

    assert( st->enableTcxLpc );
    gamma_w = 32767 /*1.0f Q15*/;
    move16();
    gamma_uw = st->inv_gamma;
    move16();

    tcx_arith_render_envelope( A_ind, L_frame, L_spec, hTcxCfg->preemph_fac, gamma_w, gamma_uw, env );

    FOR( k = 0; k < L_spec; k++ )
    {
        signs[k] = extract_l( L_lshr( spectrum[k], 31 ) );
        move16();
        if ( spectrum[k] < 0 )
        {
            spectrum[k] = L_abs( spectrum[k] );
            move32();
        }
    }

    IF( use_hm != 0 )
    {
        tcx_hm_analyse_fx( spectrum, spectrum_e, L_spec, env, target_bits, hTcxCfg->coder_type, prm_hm, tcxltp_pitch, hTcxEnc->tcxltp_gain, &hm_bits );

        target_bits = sub( target_bits, hm_bits );
        *signaling_bits = add( *signaling_bits, hm_bits );
        move16();
    }
    ELSE
    {
        prm_hm[0] = 0; /* just to be sure */
        move16();
        hm_bits = 0;
        move16();
    }

    L_spec_core = L_spec;
    move16();
    if ( st->igf )
    {
        L_spec_core = s_min( L_spec_core, st->hIGFEnc->infoStartLine );
    }
    envelope = (Word16 *) env;

    tcx_arith_scale_envelope( L_spec, L_spec_core, env, target_bits, low_complexity, envelope, &envelope_e );

    tmp = sub( envelope_e, 1 + 15 );
    FOR( k = 0; k < L_spec; k++ )
    {
        exponents[k] = round_fx( expfp( envelope[k], tmp ) );
        move16();
    }

    scale = tcx_arith_rateloop( spectrum, *spectrum_e, L_spec, envelope, envelope_e, exponents, target_bits, deadzone, deadzone_flags, &( hTcxEnc->tcx_target_bits_fac ), &scale_e );

    /* Final quantization */
    kMax = tcx_arith_find_kMax( spectrum, *spectrum_e, L_spec, scale, scale_e, deadzone, deadzone_flags );

    q_spectrum = (Word16 *) env; /* Reuse buffer */

    L_tmp = L_mult( deadzone, 1 ); /* Q16 */
    tmp = add( sub( *spectrum_e, 15 ), scale_e );
    FOR( k = 0; k <= kMax; k++ )
    {
        /* quantise using dead-zone */
        q_spectrum[k] = extract_h( L_add( L_shl( Mpy_32_16_1( spectrum[k], scale ), tmp ), L_tmp ) );
        move16();
    }

    /* Final encoding */
    *arith_bits = tcx_arith_encode( q_spectrum, signs, kMax, L_spec, exponents, target_bits, prm );
    move16();

    /* Multiply back the signs */
    W_tmp2 = 0;
    FOR( k = 0; k <= kMax; k++ )
    {
        W_tmp2 = W_mac_16_16( W_tmp2, q_spectrum[k], k );

        if ( signs[k] != 0 )
            L_tmp = L_mult( q_spectrum[k], -( 1 << ( 30 - SPEC_EXP_DEC ) ) );
        if ( signs[k] == 0 )
            L_tmp = L_mult( q_spectrum[k], 1 << ( 30 - SPEC_EXP_DEC ) );
        spectrum[k] = L_tmp;
        move32();
    }
    *spectrum_e = SPEC_EXP_DEC;
    move16();
    set32_fx( spectrum + k, 0, sub( s_max( L_frame, L_spec ), k ) );

    /* noise filling seed */
    *nf_seed = extract_l( W_extract_l( W_tmp2 ) );
    move16();

    return;
}
#endif

#ifdef HARMONIZE_2598_tcx_arith_encode_envelope
void tcx_arith_encode_envelope_fx(
    Word32 spectrum[],          /* i/o: MDCT coefficients             Q31-e */
    Word16 *spectrum_e,         /* i/o: MDCT exponent                 Q0 */
@@ -821,25 +677,6 @@ void tcx_arith_encode_envelope_fx(
    Word16 *nf_seed,            /* o  : noise filling seed; might be NULL Q0 */
    const Word16 low_complexity /* i  : low-complexity flag           Q0 */
)
#else
void tcx_arith_encode_envelope_ivas_fx(
    Word32 spectrum[],          /* i/o: MDCT coefficients             Q31-e */
    Word16 *spectrum_e,         /* i/o: MDCT exponent                 Q0 */
    Word16 signs[],             /* o  : signs (spectrum[.]<0)         Q0 */
    const Word16 L_frame,       /* i  : frame or MDCT length          Q0 */
    const Word16 L_spec,        /* i  : frame or MDCT length          Q0 */
    Encoder_State *st,          /* i/o: coder state                   */
    const Word16 A_ind[],       /* i  : quantised LPC coefficients    Q12 */
    Word16 target_bits,         /* i  : number of available bits      Q0 */
    Word16 prm[],               /* o  : bitstream parameters          Q0 */
    const Word8 use_hm,         /* i  : use HM in current frame?      */
    Word16 prm_hm[],            /* o  : HM parameter area             Q0 */
    const Word16 tcxltp_pitch,  /* i  : TCX LTP pitch in FD, -1 if n/a  Q0*/
    Word16 *arith_bits,         /* o  : bits used for ari. coding     Q0 */
    Word16 *signaling_bits,     /* o  : bits used for signaling       Q0 */
    const Word16 low_complexity /* i  : low-complexity flag           Q0 */
)
#endif
{
    Word32 env[N_MAX_ARI]; /* unscaled envelope (Q16) */
    Word16 *envelope;      /* scaled envelope (Q15-e) */
@@ -855,9 +692,7 @@ void tcx_arith_encode_envelope_ivas_fx(
    Word16 gamma_w, gamma_uw;
    Word16 hm_bits;
    Word32 L_tmp;
#ifdef HARMONIZE_2598_tcx_arith_encode_envelope
    Word64 W_tmp2;
#endif
    Word16 tmp;
    TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc;

@@ -943,18 +778,14 @@ void tcx_arith_encode_envelope_ivas_fx(
    move16();

    /* Multiply back the signs */
#ifdef HARMONIZE_2598_tcx_arith_encode_envelope
    W_tmp2 = 0;
    move32();
#endif
    FOR( k = 0; k <= kMax; k++ )
    {
#ifdef HARMONIZE_2598_tcx_arith_encode_envelope
        if ( nf_seed != NULL )
        {
            W_tmp2 = W_mac_16_16( W_tmp2, q_spectrum[k], k );
        }
#endif
        if ( signs[k] != 0 )
        {
            L_tmp = L_mult( q_spectrum[k], -( 1 << ( 30 - SPEC_EXP_DEC ) ) );
@@ -971,14 +802,12 @@ void tcx_arith_encode_envelope_ivas_fx(
    move16();
    set32_fx( spectrum + k, 0, sub( s_max( L_frame, L_spec ), k ) );

#ifdef HARMONIZE_2598_tcx_arith_encode_envelope
    if ( nf_seed != NULL )
    {
        /* noise filling seed */
        *nf_seed = extract_l( W_extract_l( W_tmp2 ) );
        move16();
    }
#endif

    return;
}
+0 −4
Original line number Diff line number Diff line
@@ -3255,11 +3255,7 @@ void QuantizeTCXSpectrum_fx(
            low_complexiety = 1;
            move16();
        }
#ifdef HARMONIZE_2598_tcx_arith_encode_envelope
        tcx_arith_encode_envelope_fx( spectrum_fx, spectrum_e, hm_cfg->indexBuffer, L_frame, L_spec, st, Aqind, sqTargetBits, sqQ, tmp8, prm_hm, /* HM parameter area */ LtpPitchLag, &sqBits, &signaling_bits, NULL, low_complexiety );
#else
        tcx_arith_encode_envelope_ivas_fx( spectrum_fx, spectrum_e, hm_cfg->indexBuffer, L_frame, L_spec, st, Aqind, sqTargetBits, sqQ, tmp8, prm_hm, /* HM parameter area */ LtpPitchLag, &sqBits, &signaling_bits, low_complexiety );
#endif
        sqTargetBits = sub( sqTargetBits, signaling_bits );
        *prm_target = sqTargetBits;
        move16();
+0 −40
Original line number Diff line number Diff line
@@ -1866,28 +1866,7 @@ Word16 ACcontextMapping_encode2_estimate_no_mem_s17_LC_fx(
    Word16 *stop,       /* Q0 */
    CONTEXT_HM_CONFIG *hm_cfg );

#ifndef HARMONIZE_2598_tcx_arith_encode_envelope
void tcx_arith_encode_envelope_fx(
    Word32 spectrum[],          /* i/o: MDCT coefficients             Q31-e */
    Word16 *spectrum_e,         /* i/o: MDCT exponent                 Q0 */
    Word16 signs[],             /* o  : signs (spectrum[.]<0)         Q0 */
    const Word16 L_frame,       /* i  : frame or MDCT length          Q0 */
    const Word16 L_spec,        /* i  : frame or MDCT length          Q0 */
    Encoder_State *st,          /* i/o: coder state                   */
    const Word16 A_ind[],       /* i  : quantised LPC coefficients    Q12 */
    Word16 target_bits,         /* i  : number of available bits      Q0 */
    Word16 prm[],               /* o  : bitstream parameters          Q0 */
    const Word8 use_hm,         /* i  : use HM in current frame?      */
    Word16 prm_hm[],            /* o  : HM parameter area             Q0 */
    const Word16 tcxltp_pitch,  /* i  : TCX LTP pitch in FD, -1 if n/a  Q0*/
    Word16 *arith_bits,         /* o  : bits used for ari. coding     Q0 */
    Word16 *signaling_bits,     /* o  : bits used for signaling       Q0 */
    Word16 *nf_seed,            /* o  : noise filling seed            Q0 */
    const Word16 low_complexity /* i  : low-complexity flag           Q0 */
);
#endif

#ifdef HARMONIZE_2598_tcx_arith_encode_envelope
void tcx_arith_encode_envelope_fx(
    Word32 spectrum[],          /* i/o: MDCT coefficients             Q31-e */
    Word16 *spectrum_e,         /* i/o: MDCT exponent                 Q0 */
@@ -1906,25 +1885,6 @@ void tcx_arith_encode_envelope_fx(
    Word16 *nf_seed,            /* o  : noise filling seed, may be NULL Q0 */
    const Word16 low_complexity /* i  : low-complexity flag           Q0 */
);
#else
void tcx_arith_encode_envelope_ivas_fx(
    Word32 spectrum[],          /* i/o: MDCT coefficients             Q31-e */
    Word16 *spectrum_e,         /* i/o: MDCT exponent                 Q0 */
    Word16 signs[],             /* o  : signs (spectrum[.]<0)         Q0 */
    const Word16 L_frame,       /* i  : frame or MDCT length          Q0 */
    const Word16 L_spec,        /* i  : frame or MDCT length          Q0 */
    Encoder_State *st,          /* i/o: coder state                   */
    const Word16 A_ind[],       /* i  : quantised LPC coefficients    Q12 */
    Word16 target_bits,         /* i  : number of available bits      Q0 */
    Word16 prm[],               /* o  : bitstream parameters          Q0 */
    const Word8 use_hm,         /* i  : use HM in current frame?      */
    Word16 prm_hm[],            /* o  : HM parameter area             Q0 */
    const Word16 tcxltp_pitch,  /* i  : TCX LTP pitch in FD, -1 if n/a  Q0*/
    Word16 *arith_bits,         /* o  : bits used for ari. coding     Q0 */
    Word16 *signaling_bits,     /* o  : bits used for signaling       Q0 */
    const Word16 low_complexity /* i  : low-complexity flag           Q0 */
);
#endif

void QuantizeGain(
    Word16 n,