Commit 28982fee authored by multrus's avatar multrus
Browse files

[cleanup] accept FIX_FLOAT_1535_ARI_RES_Q_CLEANUP

parent 0ee6276d
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -84,7 +84,6 @@
#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 HARM_HQ_CORE_KEEP_BE                            /* hack to keep all BE after HQ core functions harmonization; pending resolving issues #2450, #2451, #2452 */
#define FIX_FLOAT_1535_ARI_RES_Q_CLEANUP                /* FhG: remove dead code from tcx_ari_res_Q_spec() */
#define HQ_ALIGN_DUPLICATED_CODE                        /* Eri: Align duplicated code */
#define FIX_2467_RENAME_GSC_FUNCTION                    /* VA: basop issue 2467: Removal of unused function/table and renaming of _ivas_fx versions to default ones. */
#define HARMONIZE_FUNC                                  /* VA: basop issue 2460: Remove duplicated code: various functions */
+0 −4
Original line number Diff line number Diff line
@@ -3570,11 +3570,7 @@ void QuantizeTCXSpectrum_fx(

            prm_resq = sqQ + sub( sqTargetBits, resQTargetBits );

#ifdef FIX_FLOAT_1535_ARI_RES_Q_CLEANUP
            resQBits = tcx_ari_res_Q_spec_fx( x_orig_fx, x_orig_e, hm_cfg->indexBuffer, spectrum_fx, *spectrum_e, L_spec, *gain_tcx_fx, *gain_tcx_e, prm_resq, resQTargetBits, resQBits, st->hTcxCfg->sq_rounding, lf_deemph_fact_fx );
#else
            resQBits = tcx_ari_res_Q_spec_ivas_fx( x_orig_fx, x_orig_e, hm_cfg->indexBuffer, spectrum_fx, *spectrum_e, L_spec, *gain_tcx_fx, *gain_tcx_e, prm_resq, resQTargetBits, resQBits, st->hTcxCfg->sq_rounding, lf_deemph_fact_fx );
#endif

            /* Transmit zeros when there bits remain after RESQ */
            FOR( i = resQBits; i < resQTargetBits; ++i )
+0 −17
Original line number Diff line number Diff line
@@ -1257,23 +1257,6 @@ Word16 tcx_ari_res_Q_spec_fx(
    const Word16 x_fac[]   /* i  : spectrum post-quantization factors  Q14 */
);

#ifndef FIX_FLOAT_1535_ARI_RES_Q_CLEANUP
Word16 tcx_ari_res_Q_spec_ivas_fx(
    const Word32 x_orig[], /* i  : original spectrum                   Q31-e */
    Word16 x_orig_e,       /* i  : original spectrum exponent          Q0 */
    const Word16 signs[],  /* i  : signs (x_orig[.]<0)                 Q0 */
    Word32 x_Q[],          /* i/o: quantized spectrum                  Q31-e */
    Word16 x_Q_e,          /* i  : quantized spectrum exponent         Q0 */
    Word16 L_frame,        /* i  : number of lines                     Q0 */
    Word16 gain,           /* i  : TCX gain                            Q15-e */
    Word16 gain_e,         /* i  : TCX gain exponent                   Q0 */
    Word16 prm[],          /* o  : bit-stream                          Q0 */
    Word16 target_bits,    /* i  : number of bits available            Q0 */
    Word16 bits,           /* i  : number of bits used so far          Q0 */
    Word16 deadzone,       /* i  : quantizer deadzone                  Q15 */
    const Word16 x_fac[]   /* i  : spectrum post-quantization factors  Q14 */
);
#endif
Word16 tcx_res_Q_gain_fx(
    Word16 sqGain,
    Word16 sqGain_e,
+0 −234
Original line number Diff line number Diff line
@@ -2996,9 +2996,7 @@ Word16 tcx_ari_res_Q_spec_fx(
    num_zeros = 0;
    move16();

#ifdef FIX_FLOAT_1535_ARI_RES_Q_CLEANUP
    assert( x_fac != NULL );
#endif

    s = sub( add( gain_e, x_Q_e ), x_orig_e );
    FOR( i = 0; i < L_frame; i++ )
@@ -3101,238 +3099,6 @@ Word16 tcx_ari_res_Q_spec_fx(
    return bits;
}

#ifndef FIX_FLOAT_1535_ARI_RES_Q_CLEANUP
Word16 tcx_ari_res_Q_spec_ivas_fx(
    const Word32 x_orig[], /* i  : original spectrum                   Q31-e */
    Word16 x_orig_e,       /* i  : original spectrum exponent          Q0 */
    const Word16 signs[],  /* i  : signs (x_orig[.]<0)                 Q0 */
    Word32 x_Q[],          /* i/o: quantized spectrum                  Q31-e */
    Word16 x_Q_e,          /* i  : quantized spectrum exponent         Q0 */
    Word16 L_frame,        /* i  : number of lines                     Q0 */
    Word16 gain,           /* i  : TCX gain                            Q15-e */
    Word16 gain_e,         /* i  : TCX gain exponent                   Q0 */
    Word16 prm[],          /* o  : bit-stream                          Q0 */
    Word16 target_bits,    /* i  : number of bits available            Q0 */
    Word16 bits,           /* i  : number of bits used so far          Q0 */
    Word16 deadzone,       /* i  : quantizer deadzone                  Q15 */
    const Word16 x_fac[]   /* i  : spectrum post-quantization factors  Q14 */
)
{
    Word16 i, j, num_zeros;
    Word16 zeros[L_FRAME_PLUS];
    Word16 fac_p, sign;
    Word32 thres, x_Q_m, x_Q_p;
    Word32 L_tmp, L_tmp2;
    Word16 s, s2;

    /* Limit the number of residual bits */
    target_bits = s_min( target_bits, NPRM_RESQ );

    /* Requantize the spectrum line-by-line */
    /* fac_m = deadzone * 0.5f;
       fac_p = 0.5f - fac_m; */
    num_zeros = 0;
    move16();
    s = sub( add( gain_e, x_Q_e ), x_orig_e );
    IF( x_fac == NULL )
    {
        FOR( i = 0; i < L_frame; ++i )
        {
            IF( GE_16( bits, target_bits ) ) /* no bits left */
            {
                BREAK;
            }

            IF( x_Q[i] != 0 )
            {
                sign = shl( sub( 1, shl( signs[i], 1 ) ), Q14 );
                move16();

                /* x_Q_m = x_Q[i] - sign*fac_m;
                   x_Q_p = x_Q[i] + sign*fac_p; */

                L_tmp = L_mult( sign, deadzone ); /* sign*deadzone/2 in Q31 */
                x_Q_m = L_sub( x_Q[i], L_shr( L_tmp, x_Q_e ) );

                L_tmp = L_mac( L_tmp, sign, (Word16) 0x8000 ); /* sign*(deadzone-1)/2 in Q31 */
                x_Q_p = L_sub( x_Q[i], L_shr( L_tmp, x_Q_e ) );

                /* if (fabs(x_orig[i] - gain * x_Q_m) < fabs(x_orig[i] - gain * x_Q_p)) */
                L_tmp = L_abs( L_sub( x_orig[i], L_shl( Mpy_32_16_1( x_Q_m, gain ), s ) ) );
                L_tmp2 = L_abs( L_sub( x_orig[i], L_shl( Mpy_32_16_1( x_Q_p, gain ), s ) ) );

                IF( LT_32( L_tmp, L_tmp2 ) ) /* Decrease magnitude */
                {
                    x_Q[i] = x_Q_m;
                    move32();
                    prm[bits] = 0;
                    move16();
                }
                ELSE /* Increase magnitude */
                {
                    x_Q[i] = x_Q_p;
                    move32();
                    prm[bits] = 1;
                    move16();
                }
                bits = add( bits, 1 );
            }
            ELSE
            {
                zeros[num_zeros] = i;
                move16();
                num_zeros = add( num_zeros, 1 );
            }
        }

        /* Requantize zeroed-lines of the spectrum */
        fac_p = msu_r( 1417339264l /*2*0.33f Q31*/, deadzone, 21627 /*2*0.33f Q15*/ ); /* Q16 */
        target_bits = sub( target_bits, 1 );                                           /* reserve 1 bit for the check below */

        s = sub( gain_e, x_orig_e );
        s2 = sub( x_Q_e, 1 );
        FOR( j = 0; j < num_zeros; j++ )
        {
            IF( GE_16( bits, target_bits ) ) /* 1 or 0 bits left */
            {
                BREAK;
            }

            i = zeros[j];
            move16();

            thres = L_shl( fac_p, Q15 ); /* Q31 */

            IF( GT_32( L_abs( x_orig[i] ), L_shl( Mpy_32_16_1( thres, gain ), s ) ) )
            {
                prm[bits] = 1;
                move16();
                bits = add( bits, 1 );

                prm[bits] = sub( 1, signs[i] );
                move16();
                bits = add( bits, 1 );

                L_tmp = L_shr( thres, s2 );
                IF( signs[i] )
                {
                    L_tmp = L_negate( L_tmp );
                }
                x_Q[i] = L_tmp;
                move32();
            }
            ELSE
            {
                prm[bits] = 0;
                move16();
                bits = add( bits, 1 );
            }
        }

        return bits;
    }

    s = sub( add( gain_e, x_Q_e ), x_orig_e );
    FOR( i = 0; i < L_frame; i++ )
    {
        IF( GE_16( bits, target_bits ) ) /* no bits left */
        {
            BREAK;
        }

        IF( x_Q[i] != 0 )
        {
            sign = x_fac[i];
            move16();
            IF( signs[i] != 0 )
            {
                sign = negate( sign );
            }

            /* x_Q_m = x_Q[i] - sign*fac_m;
               x_Q_p = x_Q[i] + sign*fac_p; */

            L_tmp = L_mult( sign, deadzone ); /* sign*deadzone/2 in Q31 */
            x_Q_m = L_sub( x_Q[i], L_shr( L_tmp, x_Q_e ) );

            L_tmp = L_mac( L_tmp, sign, (Word16) 0x8000 ); /* sign*(deadzone-1)/2 in Q31 */
            x_Q_p = L_sub( x_Q[i], L_shr( L_tmp, x_Q_e ) );

            /* if (fabs(x_orig[i] - gain * x_Q_m) < fabs(x_orig[i] - gain * x_Q_p)) */
            L_tmp = L_abs( L_sub( x_orig[i], L_shl( Mpy_32_16_1( x_Q_m, gain ), s ) ) );
            L_tmp2 = L_abs( L_sub( x_orig[i], L_shl( Mpy_32_16_1( x_Q_p, gain ), s ) ) );

            IF( LT_32( L_tmp, L_tmp2 ) ) /* Decrease magnitude */
            {
                x_Q[i] = x_Q_m;
                move32();
                prm[bits] = 0;
                move16();
            }
            ELSE /* Increase magnitude */
            {
                x_Q[i] = x_Q_p;
                move32();
                prm[bits] = 1;
                move16();
            }
            bits = add( bits, 1 );
        }
        ELSE
        {
            zeros[num_zeros] = i;
            move16();
            num_zeros = add( num_zeros, 1 );
        }
    }

    /* Requantize zeroed-lines of the spectrum */
    fac_p = msu_r( 1417339264l /*2*0.33f Q31*/, deadzone, 21627 /*2*0.33f Q15*/ ); /* Q16 */
    target_bits = sub( target_bits, 1 );                                           /* reserve 1 bit for the check below */

    s = sub( gain_e, x_orig_e );
    s2 = sub( x_Q_e, 1 );
    FOR( j = 0; j < num_zeros; j++ )
    {
        IF( GE_16( bits, target_bits ) ) /* 1 or 0 bits left */
        {
            BREAK;
        }

        i = zeros[j];
        move16();

        thres = L_mult( fac_p, x_fac[i] ); /* Q31 */

        IF( GT_32( L_abs( x_orig[i] ), L_shl( Mpy_32_16_1( thres, gain ), s ) ) )
        {
            prm[bits] = 1;
            move16();
            bits = add( bits, 1 );

            prm[bits] = sub( 1, signs[i] );
            move16();
            bits = add( bits, 1 );

            L_tmp = L_shr( thres, s2 );
            IF( signs[i] )
            {
                L_tmp = L_negate( L_tmp );
            }
            x_Q[i] = L_tmp;
            move32();
        }
        ELSE
        {
            prm[bits] = 0;
            move16();
            bits = add( bits, 1 );
        }
    }

    return bits;
}
#endif

#define kMaxEstimatorOvershoot  5
#define kMaxEstimatorUndershoot 0