Commit 58dacf3a authored by multrus's avatar multrus
Browse files

Merge branch 'ivas_basop_issue_2546' into 'main'

Fixed Issue 2546: "Harmonize function pair tcx_scalar_quantization_rateloop()"

See merge request !2965
parents f9553456 4e563287
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -95,6 +95,7 @@
#define FIX_FLOAT_1539_G192_FORMAT_SWITCH               /* VA/Nokia: reintroduce format switching for g192 bitstreams */
#define HARMONIZE_2499_CONFIGUREFDCNGDEC                /* FhG: basop issue 2499: harmonoize configureFdCngDec */
#define FIX_BASOP_2530_IVAS_DECISION_MAT                /* VA: Fix ambiguous usage of extract_l() */
#define FIX_BASOP_2546_HARMONIZE_TCX_SCALAR             /* FhG: Fix issue 2546 Harmonize function tcx_scalar_quantization_rateloop*/

/* #################### End BE switches ################################## */

+34 −1
Original line number Diff line number Diff line
@@ -1594,6 +1594,7 @@ void QuantizeSpectrum_fx(
                phm_cfg = hm_cfg;
                move16();
            }
#ifndef FIX_BASOP_2546_HARMONIZE_TCX_SCALAR
            sqBits = tcx_scalar_quantization_rateloop_fx( spectrum, *spectrum_e,
                                                          sqQ,
                                                          L_spec,
@@ -1609,6 +1610,35 @@ void QuantizeSpectrum_fx(
                                                          hTcxCfg->tcxRateLoopOpt,
                                                          tcxonly,
                                                          phm_cfg );
#else
            Word16 max_iter = 4;
            move16();
            IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) )
            {
                max_iter = 2;
                move16();
            }
            sqBits = tcx_scalar_quantization_rateloop_fx( spectrum, *spectrum_e,
                                                          sqQ,
                                                          L_spec,
                                                          &sqGain, &sqGain_e,
                                                          hTcxCfg->sq_rounding,
                                                          hTcxEnc->memQuantZeros,
                                                          prm_lastnz, /* lastnz */
                                                          sqTargetBits,
                                                          &nEncoded,
                                                          &stop,
                                                          sqBits_noStop,
                                                          sqBits,
                                                          hTcxCfg->tcxRateLoopOpt,
                                                          tcxonly,
                                                          phm_cfg,
                                                          max_iter,
                                                          st->element_mode );
            // sqBits = tcx_scalar_quantization_rateloop_ivas_fx(spectrum_fx, *spectrum_e, sqQ, L_spec, &sqGain_fx, &sqGain_e, st->hTcxCfg->sq_rounding, hTcxEnc->memQuantZeros, prm_lastnz, /* lastnz */ sqTargetBits, &nEncoded, &stop, sqBits_noStop, sqBits, st->hTcxCfg->tcxRateLoopOpt, st->tcxonly, phm_cfg, max_iter, st->element_mode);

#endif // !FIX_BASOP_2546_HARMONIZE_TCX_SCALAR


            IF( ctxHmBits > 0 ) /* Mapping tool is enabled */
            {
@@ -3186,8 +3216,11 @@ void QuantizeTCXSpectrum_fx(
            max_iter = 2;
            move16();
        }
#ifndef FIX_BASOP_2546_HARMONIZE_TCX_SCALAR
        sqBits = tcx_scalar_quantization_rateloop_ivas_fx( spectrum_fx, *spectrum_e, sqQ, L_spec, &sqGain_fx, &sqGain_e, st->hTcxCfg->sq_rounding, hTcxEnc->memQuantZeros, prm_lastnz, /* lastnz */ sqTargetBits, &nEncoded, &stop, sqBits_noStop, sqBits, st->hTcxCfg->tcxRateLoopOpt, st->tcxonly, phm_cfg, max_iter, st->element_mode );

#else
        sqBits = tcx_scalar_quantization_rateloop_fx( spectrum_fx, *spectrum_e, sqQ, L_spec, &sqGain_fx, &sqGain_e, st->hTcxCfg->sq_rounding, hTcxEnc->memQuantZeros, prm_lastnz, /* lastnz */ sqTargetBits, &nEncoded, &stop, sqBits_noStop, sqBits, st->hTcxCfg->tcxRateLoopOpt, st->tcxonly, phm_cfg, max_iter, st->element_mode );
#endif // !FIX_BASOP_2546_HARMONIZE_TCX_SCALAR
        IF( ctxHmBits > 0 )
        {
            /* Mapping tool is enabled */
+6 −1
Original line number Diff line number Diff line
@@ -1117,7 +1117,7 @@ void tcx_scalar_quantization_fx(
    Word16 offset,              /* i  : rounding offset (deadzone)    */
    Word8 const *memQuantZeros, /* i  : coefficients to be set to 0   */
    const Word16 alfe_flag );

#ifndef FIX_BASOP_2546_HARMONIZE_TCX_SCALAR
Word16 tcx_scalar_quantization_rateloop_fx(
    Word32 *x,                  /* i  : i   coefficients              */
    Word16 x_e,                 /* i  : exponent                      */
@@ -1137,8 +1137,13 @@ Word16 tcx_scalar_quantization_rateloop_fx(
    const Word8 tcxonly,
    CONTEXT_HM_CONFIG *hm_cfg /* i  : configuration of the context-based harmonic model */
);
#endif

#ifndef FIX_BASOP_2546_HARMONIZE_TCX_SCALAR
Word16 tcx_scalar_quantization_rateloop_ivas_fx(
#else
Word16 tcx_scalar_quantization_rateloop_fx(
#endif                             // !FIX_BASOP_2546_HARMONIZE_TCX_SCALAR
    Word32 *x,                     /* i  : input coefficients            Q = 31 - x_e*/
    Word16 x_e,                    /* i  : exponent                      Q0*/
    Word16 *xq,                    /* o  : quantized coefficients        Q0*/
+130 −6
Original line number Diff line number Diff line
@@ -1422,7 +1422,7 @@ void tcx_scalar_quantization_ivas_fx(
    return;
}


#ifndef FIX_BASOP_2546_HARMONIZE_TCX_SCALAR
Word16 tcx_scalar_quantization_rateloop_fx(
    Word32 *x,                     /* i  : input coefficients            */
    Word16 x_e,                    /* i  : exponent                      */
@@ -1719,9 +1719,13 @@ Word16 tcx_scalar_quantization_rateloop_fx(

    return sqBits;
}
#endif // !FIX_BASOP_2546_HARMONIZE_TCX_SCALAR


#ifndef FIX_BASOP_2546_HARMONIZE_TCX_SCALAR
Word16 tcx_scalar_quantization_rateloop_ivas_fx(
#else
Word16 tcx_scalar_quantization_rateloop_fx(
#endif                             // !FIX_BASOP_2546_HARMONIZE_TCX_SCALAR
    Word32 *x,                     /* i  : input coefficients            Q = 31 - x_e*/
    Word16 x_e,                    /* i  : exponent                      Q0*/
    Word16 *xq,                    /* o  : quantized coefficients        Q0*/
@@ -1763,13 +1767,14 @@ Word16 tcx_scalar_quantization_rateloop_ivas_fx(
    move16();
    Word16 tmp, fac1, fac2;
    Word32 tmp32;

    Word16 lastnz, saturated, minSqGain = 0;
    move16();

    /* Init */
    saturated = 0;
    move16();
    /* minSqGain = (float) sqrt( (float) NORM_MDCT_FACTOR / (float) L_frame ); in Q14*/
#ifndef FIX_BASOP_2546_HARMONIZE_TCX_SCALAR
    SWITCH( L_frame )
    {
        case 80:
@@ -1827,6 +1832,69 @@ Word16 tcx_scalar_quantization_rateloop_ivas_fx(
            assert( 0 );
    }
    move16();
#else
    IF( NE_16( element_mode, EVS_MONO ) )
    {
        SWITCH( L_frame )
        {
            case 80:
                minSqGain = 23170;
                BREAK;
            case 100:
                minSqGain = 20724;
                BREAK;
            case 160:
                minSqGain = 16384;
                BREAK;
            case 200:
                minSqGain = 14654;
                BREAK;
            case 240:
                minSqGain = 13377;
                BREAK;
            case 300:
                minSqGain = 11965;
                BREAK;
            case 320:
                minSqGain = 11585;
                BREAK;
            case 400:
                minSqGain = 10362;
                BREAK;
            case 480:
                minSqGain = 9459;
                BREAK;
            case 600:
                minSqGain = 8461;
                BREAK;
            case 640:
                minSqGain = 8192;
                BREAK;
            case 800:
                minSqGain = 7327;
                BREAK;
            case 960:
                minSqGain = 6689;
                BREAK;
            case 1200:
                minSqGain = 5983;
                BREAK;
            case 1440:
                minSqGain = 5461;
                BREAK;
            case 1800:
                minSqGain = 4885;
                BREAK;
            case 2048:
                minSqGain = 4579;
                BREAK;
            default:
                assert( 0 );
        }
        move16();
    }
#endif // !FIX_BASOP_2546_HARMONIZE_TCX_SCALAR

    sqGain = *gain;
    move16();
    sqGain_e = *gain_e;
@@ -1886,8 +1954,16 @@ Word16 tcx_scalar_quantization_rateloop_ivas_fx(
                lb_e = sqGain_e;
                move16();
                w_lb = add( sub( stopFlag, target ), kDampen );
#ifndef FIX_BASOP_2546_HARMONIZE_TCX_SCALAR
                saturated = 0;
                move16();
#else
                IF( NE_16( element_mode, EVS_MONO ) )
                {
                    saturated = 0;
                    move16();
                }
#endif // !FIX_BASOP_2546_HARMONIZE_TCX_SCALAR
                IF( ubfound != 0 )
                {
                    /* common exponent for addition */
@@ -1948,7 +2024,7 @@ Word16 tcx_scalar_quantization_rateloop_ivas_fx(
                    sqGain = mult( sqGain, sub( tmp, add( mod_adjust1, (Word16) 0x8000 ) ) );
                    sqGain = normalize16( sqGain, &sqGain_e );
                }

#ifndef FIX_BASOP_2546_HARMONIZE_TCX_SCALAR
                Word16 shift_tmp = s_max( sqGain_e, 1 );
                move16();
                test();
@@ -1961,11 +2037,35 @@ Word16 tcx_scalar_quantization_rateloop_ivas_fx(
                    saturated = 1;
                    move16();
                }
#else
                IF( NE_16( element_mode, EVS_MONO ) )
                {
                    Word16 shift_tmp = s_max( sqGain_e, 1 );
                    move16();
                    test();
                    IF( LT_16( shl( sqGain, sub( sqGain_e, shift_tmp ) ), shl( minSqGain, sub( 1, shift_tmp ) ) ) && EQ_16( tcxRateLoopOpt, 3 ) )
                    {
                        sqGain = minSqGain;
                        move16();
                        sqGain_e = 1;
                        move16();
                        saturated = 1;
                        move16();
                    }
                }
#endif // !FIX_BASOP_2546_HARMONIZE_TCX_SCALAR
            }
#ifndef FIX_BASOP_2546_HARMONIZE_TCX_SCALAR
            ELSE
            {
                BREAK; /* we cannot go any lower anyway*/
            }
#else
            ELSE IF( NE_16( element_mode, EVS_MONO ) )
            {
                BREAK; /* we cannot go any lower anyway*/
            }
#endif // FIX_BASOP_2546_HARMONIZE_TCX_SCALAR
        }
        ELSE /* tcxRateLoopOpt != 2 */
        {
@@ -2023,8 +2123,18 @@ Word16 tcx_scalar_quantization_rateloop_ivas_fx(
        }

        /* Quantize spectrum */
#ifndef FIX_BASOP_2546_HARMONIZE_TCX_SCALAR
        tcx_scalar_quantization_ivas_fx( x, x_e, xq, L_frame, sqGain, sqGain_e, offset, memQuantZeros_fx, tcxonly );

#else
        IF( EQ_16( element_mode, EVS_MONO ) )
        {
            tcx_scalar_quantization_fx( x, x_e, xq, L_frame, sqGain, sqGain_e, offset, memQuantZeros_fx, tcxonly );
        }
        ELSE
        {
            tcx_scalar_quantization_ivas_fx( x, x_e, xq, L_frame, sqGain, sqGain_e, offset, memQuantZeros_fx, tcxonly );
        }
#endif // !FIX_BASOP_2546_HARMONIZE_TCX_SCALAR
        /* Estimate bitrate */
        stopFlag = 1;
        move16();
@@ -2033,8 +2143,11 @@ Word16 tcx_scalar_quantization_rateloop_ivas_fx(
            stopFlag = 0;
            move16();
        }

#ifndef FIX_BASOP_2546_HARMONIZE_TCX_SCALAR
        IF( GT_16( element_mode, EVS_MONO ) )
#else
        IF( NE_16( element_mode, EVS_MONO ) )
#endif // !FIX_BASOP_2546_HARMONIZE_TCX_SCALAR
        {
            sqBits = RCcontextMapping_encode2_estimate_no_mem_s17_LCS_fx( xq, L_frame, &lastnz, nEncoded, target, &stopFlag, 0, hm_cfg );
        }
@@ -2076,8 +2189,19 @@ Word16 tcx_scalar_quantization_rateloop_ivas_fx(

    IF( GE_16( tcxRateLoopOpt, 1 ) )
    {
#ifndef FIX_BASOP_2546_HARMONIZE_TCX_SCALAR
        /* Quantize spectrum */
        tcx_scalar_quantization_ivas_fx( x, x_e, xq, L_frame, *gain, *gain_e, offset, memQuantZeros_fx, tcxonly );
#else
        IF( EQ_16( element_mode, EVS_MONO ) )
        {
            tcx_scalar_quantization_fx( x, x_e, xq, L_frame, *gain, *gain_e, offset, memQuantZeros_fx, tcxonly );
        }
        ELSE
        {
            tcx_scalar_quantization_ivas_fx( x, x_e, xq, L_frame, *gain, *gain_e, offset, memQuantZeros_fx, tcxonly );
        }
#endif // !FIX_BASOP_2546_HARMONIZE_TCX_SCALAR

        /* Output */
        *nEncoded = old_nEncoded;