diff --git a/lib_com/options.h b/lib_com/options.h index c09e1ff3d56e7459bd22070d9bf45b84d1830eb0..d17513d4480abcde19a65b7cbc28e7d064a95b3a 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -94,6 +94,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 ################################## */ diff --git a/lib_enc/cod_tcx_fx.c b/lib_enc/cod_tcx_fx.c index 72a8d01d37359fb0bb4b8a44c9ba66a676cbc116..e729dc67afb126987093c4041559724f8a3d2e89 100644 --- a/lib_enc/cod_tcx_fx.c +++ b/lib_enc/cod_tcx_fx.c @@ -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_ivas_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 */ { diff --git a/lib_enc/tcx_utils_enc_fx.c b/lib_enc/tcx_utils_enc_fx.c index db3c828d52bb2d82b9d5c4ec1024da803afa06f3..7c0abe833c762be8b4ba51f2290687af667dc6bb 100644 --- a/lib_enc/tcx_utils_enc_fx.c +++ b/lib_enc/tcx_utils_enc_fx.c @@ -1753,13 +1753,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: @@ -1817,6 +1818,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; @@ -1876,8 +1940,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 */ @@ -1938,7 +2010,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(); @@ -1951,11 +2023,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 */ { @@ -2013,8 +2109,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(); @@ -2023,8 +2129,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 ); } @@ -2066,8 +2175,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;