Commit c6612256 authored by multrus's avatar multrus
Browse files

[cleanup] accept HARMONIZE_2543_SQ_gain

parent 1a7a61c8
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -96,7 +96,6 @@
#define FIX_2402_SIMPLIFY_ARI_CODEC                     /* FhG: basop issue 2402: simplified arithmetic in TCX arithmetic coder */
#define FIX_2402_REPL_EVS_ARI_CODEC_ENC                 /* FhG: basop issue 2402: replace EVS arith encoder with IVAS arith encoder */
#define FIX_BASOP_2551_HARM_SCALAR_QUAN                 /* FhG: issue 2551: Harmonize function pair tcx_scalar_quantization_fx*/
#define HARMONIZE_2543_SQ_gain                          /* FhG: Harmonize SQ_gain */
#define FIX_ISSUE_2533_EXTRA_CONDITION                  /* FhG: Fix issue basop 2533 removing the extra condition*/
#define HARMONIZE_2537_SetTCXModeInfo                   /* FhG: Harmonize SetTCXModeInfo  - IVAS_VERSION OBVIOUSLY NOT FITTING FOR EVS - pipes not green */
#define HARMONIZE_2537_GetTCXMaxenergyChange            /* FhG: Harmonize GetTCXMaxenergyChange */
+0 −22
Original line number Diff line number Diff line
@@ -1432,18 +1432,11 @@ void QuantizeSpectrum_fx(

                /* Quantize original spectrum */

#ifdef HARMONIZE_2543_SQ_gain
                sqGain = SQ_gain_fx( OriginalSpectrum, OriginalSpectrum_e,
                                     shl( mult( hTcxEnc->tcx_target_bits_fac, sqTargetBits ), 1 ),
                                     L_spec,
                                     &sqGain_e,
                                     EVS_MONO );
#else
                sqGain = SQ_gain_fx( OriginalSpectrum, OriginalSpectrum_e,
                                     shl( mult( hTcxEnc->tcx_target_bits_fac, sqTargetBits ), 1 ),
                                     L_spec,
                                     &sqGain_e );
#endif

#ifndef FIX_BASOP_2551_HARM_SCALAR_QUAN
                tcx_scalar_quantization_fx( OriginalSpectrum, OriginalSpectrum_e,
@@ -1544,18 +1537,11 @@ void QuantizeSpectrum_fx(
                PeriodicityIndex = -1;
                move16();

#ifdef HARMONIZE_2543_SQ_gain
                sqGain = SQ_gain_fx( spectrum, *spectrum_e,
                                     shl( mult( hTcxEnc->tcx_target_bits_fac, sqTargetBits ), 1 ),
                                     L_spec,
                                     &sqGain_e,
                                     EVS_MONO );
#else
                sqGain = SQ_gain_fx( spectrum, *spectrum_e,
                                     shl( mult( hTcxEnc->tcx_target_bits_fac, sqTargetBits ), 1 ),
                                     L_spec,
                                     &sqGain_e );
#endif

                /* Quantize spectrum */
#ifndef FIX_BASOP_2551_HARM_SCALAR_QUAN
@@ -3089,11 +3075,7 @@ void QuantizeTCXSpectrum_fx(
            }

            /* Quantize original spectrum */
#ifdef HARMONIZE_2543_SQ_gain
            sqGain_fx = SQ_gain_fx( spectrum_fx, *spectrum_e, ( mult( hTcxEnc->tcx_target_bits_fac, shl( sqTargetBits, 1 ) ) ), L_spec, &sqGain_e, 1 /*signal non-EVS*/ );
#else
            sqGain_fx = SQ_gain_ivas_fx( spectrum_fx, *spectrum_e, ( mult( hTcxEnc->tcx_target_bits_fac, shl( sqTargetBits, 1 ) ) ), L_spec, &sqGain_e );
#endif

#ifndef FIX_BASOP_2551_HARM_SCALAR_QUAN
            tcx_scalar_quantization_ivas_fx( spectrum_fx, *spectrum_e, sqQ, L_spec, sqGain_fx, sqGain_e, st->hTcxCfg->sq_rounding, hTcxEnc->memQuantZeros, st->tcxonly );
@@ -3187,11 +3169,7 @@ void QuantizeTCXSpectrum_fx(
            }
            ELSE
            {
#ifdef HARMONIZE_2543_SQ_gain
                sqGain_fx = SQ_gain_fx( spectrum_fx, *spectrum_e, shl( mult( hTcxEnc->tcx_target_bits_fac, sqTargetBits ), 1 ), L_spec, &sqGain_e, 1 /*signal non-EVS*/ );
#else
                sqGain_fx = SQ_gain_ivas_fx( spectrum_fx, *spectrum_e, shl( mult( hTcxEnc->tcx_target_bits_fac, sqTargetBits ), 1 ), L_spec, &sqGain_e );
#endif
            }
            /* Quantize spectrum */
#ifndef FIX_BASOP_2551_HARM_SCALAR_QUAN
+0 −19
Original line number Diff line number Diff line
@@ -1106,7 +1106,6 @@ void AdaptLowFreqEmph_fx(
    const Word16 lg );

/* o  : SQ gain                   */
#ifdef HARMONIZE_2543_SQ_gain
Word16 SQ_gain_fx(
    Word32 x[],         /* i  :  vector to quantize        */
    Word16 x_e,         /* i  :  exponent                  */
@@ -1115,24 +1114,6 @@ Word16 SQ_gain_fx(
    Word16 *gain_e,     /* o  :  SQ gain exponent          */
    Word16 element_mode /* i  :  is EVS or not             */
);
#else
Word16 SQ_gain_fx(
    Word32 x[],     /* i  :  vector to quantize        */
    Word16 x_e,     /* i  :  exponent                  */
    Word16 nbitsSQ, /* i  :  number of bits targeted   */
    Word16 lg,      /* i  :  vector size (2048 max)    */
    Word16 *gain_e  /* o  : SQ gain exponent          */
);

/* o  : SQ gain                   */
Word16 SQ_gain_ivas_fx(
    Word32 x[],     /* i  :  vector to quantize        */
    Word16 x_e,     /* i  :  exponent                  */
    Word16 nbitsSQ, /* i  :  number of bits targeted   */
    Word16 lg,      /* i  :  vector size (2048 max)    */
    Word16 *gain_e  /* o  : SQ gain exponent          */
);
#endif

/* o  : SQ gain                   */
Word16 SQ_gain_estimate_fx(
+0 −129
Original line number Diff line number Diff line
@@ -827,124 +827,8 @@ void PsychAdaptLowFreqEmph_fx(
    return;
}

#ifndef HARMONIZE_2543_SQ_gain
/* o: SQ gain  */
Word16 SQ_gain_fx(
    Word32 x[],      /* i  :  vector to quantize        */
    Word16 x_e,      /* i  :  exponent                  */
    Word16 nbitsSQ,  /* i  :  number of bits targeted   */
    Word16 lg,       /* i  :  vector size (2048 max)    */
    Word16 *gain_e ) /* o  : SQ gain exponent           */
{
    Word16 i, iter, lg_4, s, tmp16;
    Word32 ener, tmp32;
    Word32 target, fac, offset;
    Word32 en[N_MAX / 4];

    lg_4 = shr( lg, 2 );

    /* energy of quadruples with 9dB offset */
    FOR( i = 0; i < lg_4; i++ )
    {
        /* normalization */
        s = 15;
        move16();

        tmp16 = norm_l( x[0] );
        IF( x[0] != 0 )
        {
            s = s_min( s, tmp16 );
        }

        tmp16 = norm_l( x[1] );
        IF( x[1] != 0 )
        {
            s = s_min( s, tmp16 );
        }

        tmp16 = norm_l( x[2] );
        IF( x[2] != 0 )
        {
            s = s_min( s, tmp16 );
        }
        tmp16 = norm_l( x[3] );
        IF( x[3] != 0 )
        {
            s = s_min( s, tmp16 );
        }

        s = sub( s, 2 ); /* 2 bits headroom */

        /* calc quadruple energy */
        ener = L_deposit_l( 1 );

        tmp16 = extract_h( L_shl( x[0], s ) );
        ener = L_mac( ener, tmp16, tmp16 );

        tmp16 = extract_h( L_shl( x[1], s ) );
        ener = L_mac( ener, tmp16, tmp16 );

        tmp16 = extract_h( L_shl( x[2], s ) );
        ener = L_mac( ener, tmp16, tmp16 );

        tmp16 = extract_h( L_shl( x[3], s ) );
        ener = L_mac( ener, tmp16, tmp16 );

        s = shl( sub( x_e, s ), 1 );

        /* log */
        tmp32 = L_add( BASOP_Util_Log2( ener ), L_shl( L_deposit_l( s ), 25 ) ); /* log2, 6Q25 */
        en[i] = L_shr( tmp32, 9 );                                               /* 15Q16 */
        move32();
        x += 4;
    }

    /* SQ scale: 4 bits / 6 dB per quadruple */
    target = L_mult( 0x3FC8, sub( nbitsSQ, shr( lg, 4 ) ) ); /* 0x3FC8 -> 0.15*log2(10) */
    fac = L_add( 0x2A854B, 0 );                              /* -> 12.8f*log2(10); */
    offset = L_add( fac, 0 );

    /* find offset (0 to 128 dB with step of 0.125dB) */
    FOR( iter = 0; iter < 10; iter++ )
    {
        fac = L_shr( fac, 1 );
        offset = L_sub( offset, fac );
        ener = L_deposit_l( 0 );

        FOR( i = 0; i < lg_4; i++ )
        {
            tmp32 = L_sub( en[i], offset );

            /* avoid SV with 1 bin of amp < 0.5f */
            IF( GT_32( tmp32, 0xFF20 ) ) /* 0xFF20 -> 0.3*log2(10); */
            {
                ener = L_add( ener, tmp32 );
            }

            /* if ener is above target -> break and increase offset */
            IF( GT_32( ener, target ) )
            {
                offset = L_add( offset, fac );
                BREAK;
            }
        }
    }

    offset = L_add( L_shr( offset, 1 ), 0x17EB0 ); /* 0x17EB0 -> 0.45*log2(10) */

    *gain_e = add( extract_h( offset ), 1 );
    move16();
    offset = L_sub( L_and( offset, 0xFFFF ), 0x10000 );
    tmp16 = extract_h( BASOP_Util_InvLog2( L_shl( offset, 9 ) ) );

    /* return gain */

    return tmp16;
}
#endif

/* o: SQ gain  */
#ifdef HARMONIZE_2543_SQ_gain
Word16 SQ_gain_fx(
    Word32 x[],         /* i  : vector to quantize        */
    Word16 x_e,         /* i  : exponent                  */
@@ -953,15 +837,6 @@ Word16 SQ_gain_fx(
    Word16 *gain_e,     /* o  : SQ gain exponent          */
    Word16 element_mode /* i  : is EVS or not             */
)
#else
Word16 SQ_gain_ivas_fx(
    Word32 x[],     /* i  : vector to quantize        */
    Word16 x_e,     /* i  : exponent                  */
    Word16 nbitsSQ, /* i  : number of bits targeted   */
    Word16 lg,      /* i  : vector size (2048 max)    */
    Word16 *gain_e  /* o  : SQ gain exponent          */
)
#endif
{
    Word16 i, iter, lg_4, s, tmp16;
    Word32 ener, tmp32;
@@ -1021,12 +896,8 @@ Word16 SQ_gain_ivas_fx(
        s = shl( sub( x_e, s ), 1 );

        /* log */
#ifdef HARMONIZE_2543_SQ_gain
        test();
        IF( EQ_32( ener, 1 ) && GT_16( element_mode, EVS_MONO ) )
#else
        IF( EQ_32( ener, 1 ) )
#endif
        {
            en[i] = -131072; /* log10(0.01) in Q16 */
            move32();