Commit 53aa44eb authored by Arash Azizi's avatar Arash Azizi
Browse files

Merge branch 'main' into ivas_basop_issue_2551

# Conflicts:
#	lib_com/options.h
#	lib_enc/prot_fx_enc.h
parents 9f849a7b b69cc3e2
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -91,9 +91,12 @@
#define NONBE_FIX_ISSUE_2206_AVOID_OVERFLOW_SWB_fenv_fx2 /* FhG: Avoid overflow of SWB_fenv_fx in SWB_BWE_encoding_fx because of very small energies. */
#define NONBE_FIX_ISSUE_2206_AVOID_OVERFLOW_MSVQ_Interpol_Tran_fx /* FhG: Fix saturation crash in MSVQ_Interpol_Tran_fx() */
#define NONBE_FIX_ISSUE_2206_SWB_EXPERIMENT_FIX_2527    /* Fix crash from issue #2527 */
#define NONBE_FIX_2507                                  /* Fix porting error in SQ_gain_estimate_fx() */
#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*/
#define FIX_BASOP_2532_cx_e                             /* FhG: Fix issue 2532 about additional exponent variable*/
#define FIX_BASOP_2551_HARM_SCALAR_QUAN                 /* FhG: issue 2551: Harmonize function pair tcx_scalar_quantization_fx*/

/* #################### End BE switches ################################## */
+12 −0
Original line number Diff line number Diff line
@@ -1801,6 +1801,10 @@ void ivas_param_mc_dec_prepare_renderer(
            }
        }
        cx_e = max_e;
#ifdef FIX_BASOP_2532_cx_e
        cx_next_band_e = max_e;
        move16();
#endif
        move16();

        /* we have to do it similar to the encoder in case of attacks (i.e. accumulate two bands) to ensure correct DMX of the target covariance*/
@@ -1815,7 +1819,11 @@ void ivas_param_mc_dec_prepare_renderer(
                Scale_sig32( cx_fx, len, -Q1 );           // add one bit head room
                Scale_sig32( cx_next_band_fx, len, -Q1 ); // add one bit head room
                cx_e = add( cx_e, Q1 );
#ifndef FIX_BASOP_2532_cx_e
                cx_next_band_e = add( cx_e, Q1 );
#else
                cx_next_band_e = add( cx_next_band_e, Q1 );
#endif // !FIX_BASOP_2532_cx_e
            }
            v_add_fx( cx_fx, cx_next_band_fx, cx_fx, len );
            Copy32( cx_fx, cx_next_band_fx, len );
@@ -1834,7 +1842,11 @@ void ivas_param_mc_dec_prepare_renderer(
                IF( is_next_band )
                {

#ifndef FIX_BASOP_2532_cx_e
                    ivas_param_mc_get_mixing_matrices_fx( hParamMC, hSynthesisOutputSetup, cx_next_band_fx, cx_next_band_e, add( param_band_idx, is_next_band ), hParamMC->h_output_synthesis_cov_state.mixing_matrix_fx, hParamMC->h_output_synthesis_cov_state.mixing_matrix_exp, hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_fx, hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_exp, nchan_out_transport, hParamMC->synthesis_conf, nchan_transport, nchan_out_cov );
#else
                    ivas_param_mc_get_mixing_matrices_fx( hParamMC, hSynthesisOutputSetup, cx_next_band_fx, cx_e, add( param_band_idx, is_next_band ), hParamMC->h_output_synthesis_cov_state.mixing_matrix_fx, hParamMC->h_output_synthesis_cov_state.mixing_matrix_exp, hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_fx, hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_exp, nchan_out_transport, hParamMC->synthesis_conf, nchan_transport, nchan_out_cov );
#endif
                }
                ELSE
                {
+34 −1
Original line number Diff line number Diff line
@@ -1615,6 +1615,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,
@@ -1630,6 +1631,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 */
            {
@@ -3219,8 +3249,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 −0
Original line number Diff line number Diff line
@@ -1120,6 +1120,7 @@ void tcx_scalar_quantization_fx(
    const Word16 alfe_flag );
#endif // !FIX_BASOP_2551_HARM_SCALAR_QUAN

#ifndef FIX_BASOP_2546_HARMONIZE_TCX_SCALAR
Word16 tcx_scalar_quantization_rateloop_fx(
    Word32 *x,                  /* i  : i   coefficients              */
    Word16 x_e,                 /* i  : exponent                      */
@@ -1139,8 +1140,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*/
+140 −6
Original line number Diff line number Diff line
@@ -1237,6 +1237,15 @@ Word16 SQ_gain_estimate_fx(
            if ( GT_32( tmp32, 0xFF20 ) ) /* 0xFF20 -> 0.3*log2(10); */
            {
                ener = L_add( ener, tmp32 );
#ifdef NONBE_FIX_2507
                /* if SNR is above target -> break and increase offset */
                IF( GT_32( ener, target ) )
                {
                    offset = L_add( offset, fac );
                    BREAK;
                }
            }
#else
            }

            /* if SNR is above target -> break and increase offset */
@@ -1245,6 +1254,7 @@ Word16 SQ_gain_estimate_fx(
                offset = L_add( offset, fac );
                BREAK;
            }
#endif
        }
    }

@@ -1430,7 +1440,7 @@ void tcx_scalar_quantization_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                      */
@@ -1732,9 +1742,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*/
@@ -1776,13 +1790,74 @@ 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:
            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();
#else
    IF( NE_16( element_mode, EVS_MONO ) )
    {
        SWITCH( L_frame )
        {
            case 80:
@@ -1840,6 +1915,9 @@ Word16 tcx_scalar_quantization_rateloop_ivas_fx(
                assert( 0 );
        }
        move16();
    }
#endif // !FIX_BASOP_2546_HARMONIZE_TCX_SCALAR

    sqGain = *gain;
    move16();
    sqGain_e = *gain_e;
@@ -1899,8 +1977,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 */
@@ -1961,7 +2047,22 @@ 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();
                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();
                }
#else
                IF( NE_16( element_mode, EVS_MONO ) )
                {
                    Word16 shift_tmp = s_max( sqGain_e, 1 );
                    move16();
                    test();
@@ -1975,10 +2076,19 @@ Word16 tcx_scalar_quantization_rateloop_ivas_fx(
                        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 */
        {
@@ -2036,8 +2146,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();
@@ -2046,8 +2166,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 );
        }
@@ -2089,8 +2212,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;