diff --git a/lib_com/options.h b/lib_com/options.h index 0af77e89ca45b68c5fe645fcedbced25c785604c..2b2ccec9b5bf38b4fb29f383fec7f0b457a730ac 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -100,6 +100,7 @@ #define FIX_2402_REPL_EVS_ARI_CODEC_ENC /* FhG: basop issue 2402: replace EVS arith encoder with IVAS arith encoder */ #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*/ #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 */ diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 420b40463e56fd4c67f6ced83317414d26927b2e..477786325809c8369333942601b01bc211c18ac2 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -8547,7 +8547,7 @@ void ari_start_encoding_14bits_fx( void ari_start_encoding_14bits_ivas_fx( #endif Tastat *s ); - +#ifndef FIX_BASOP_2551_HARM_SCALAR_QUAN void tcx_scalar_quantization_ivas_fx( Word32 *x, /* i: input coefficients */ Word16 x_e, /* i: exponent */ @@ -8558,6 +8558,20 @@ void tcx_scalar_quantization_ivas_fx( Word16 offset, /* i: rounding offset (deadzone) */ Word8 const *memQuantZeros_fx, /* i: coefficients to be set to 0 */ const Word16 alfe_flag ); +#else +void tcx_scalar_quantization_fx( + Word32 *x, /* i: input coefficients */ + Word16 x_e, /* i: exponent */ + Word16 *xq, /* o: quantized coefficients */ + Word16 L_frame, /* i: frame length */ + Word16 gain, /* i: quantization gain */ + Word16 gain_e, /* i: quantization gain exponent */ + Word16 offset, /* i: rounding offset (deadzone) */ + Word8 const *memQuantZeros_fx, /* i: coefficients to be set to 0 */ + const Word16 alfe_flag, + const Word16 element_mode ); +#endif // !FIX_BASOP_2551_HARM_SCALAR_QUAN + Word16 RCcontextMapping_encode2_estimate_no_mem_s17_LCS_fx( Word16 *x, /* Spectral coefficients Q0*/ diff --git a/lib_enc/cod_tcx_fx.c b/lib_enc/cod_tcx_fx.c index cde6718e83c7bd4818db1e0ea5052c6f11cabdb2..e136f9b1db5bdc47685b8db5648ab25d45dbc99b 100644 --- a/lib_enc/cod_tcx_fx.c +++ b/lib_enc/cod_tcx_fx.c @@ -1445,6 +1445,7 @@ void QuantizeSpectrum_fx( &sqGain_e ); #endif +#ifndef FIX_BASOP_2551_HARM_SCALAR_QUAN tcx_scalar_quantization_fx( OriginalSpectrum, OriginalSpectrum_e, sqQ, L_spec, @@ -1452,6 +1453,17 @@ void QuantizeSpectrum_fx( hTcxCfg->sq_rounding, hTcxEnc->memQuantZeros, tcxonly ); +#else + tcx_scalar_quantization_fx( OriginalSpectrum, OriginalSpectrum_e, + sqQ, + L_spec, + sqGain, sqGain_e, + hTcxCfg->sq_rounding, + hTcxEnc->memQuantZeros, + tcxonly, + st->element_mode ); +#endif // !FIX_BASOP_2551_HARM_SCALAR_QUAN + /* Estimate original bitrate */ stop = 0; @@ -1546,7 +1558,7 @@ void QuantizeSpectrum_fx( #endif /* Quantize spectrum */ - +#ifndef FIX_BASOP_2551_HARM_SCALAR_QUAN tcx_scalar_quantization_fx( spectrum, *spectrum_e, sqQ, L_spec, @@ -1554,6 +1566,16 @@ void QuantizeSpectrum_fx( hTcxCfg->sq_rounding, hTcxEnc->memQuantZeros, tcxonly ); +#else + tcx_scalar_quantization_fx( spectrum, *spectrum_e, + sqQ, + L_spec, + sqGain, sqGain_e, + hTcxCfg->sq_rounding, + hTcxEnc->memQuantZeros, + tcxonly, + st->element_mode ); +#endif // !FIX_BASOP_2551_HARM_SCALAR_QUAN /* Estimate bitrate */ stop = 0; @@ -1763,7 +1785,7 @@ void QuantizeSpectrum_fx( { sqGain = tmp1; sqGain_e = s; - +#ifndef FIX_BASOP_2551_HARM_SCALAR_QUAN tcx_scalar_quantization_fx( spectrum, *spectrum_e, sqQ, L_spec, @@ -1771,6 +1793,18 @@ void QuantizeSpectrum_fx( hTcxCfg->sq_rounding, hTcxEnc->memQuantZeros, tcxonly ); +#else + tcx_scalar_quantization_fx( spectrum, *spectrum_e, + sqQ, + L_spec, + sqGain, sqGain_e, + hTcxCfg->sq_rounding, + hTcxEnc->memQuantZeros, + tcxonly, + st->element_mode ); + +#endif // !FIX_BASOP_2551_HARM_SCALAR_QUAN + move16(); stop = 1; @@ -3079,8 +3113,11 @@ void QuantizeTCXSpectrum_fx( 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 ); - +#else + tcx_scalar_quantization_fx( spectrum_fx, *spectrum_e, sqQ, L_spec, sqGain_fx, sqGain_e, st->hTcxCfg->sq_rounding, hTcxEnc->memQuantZeros, st->tcxonly, st->element_mode ); +#endif // !FIX_BASOP_2551_HARM_SCALAR_QUAN /* Estimate original bitrate */ stop = 0; move16(); @@ -3175,8 +3212,11 @@ void QuantizeTCXSpectrum_fx( #endif } /* Quantize spectrum */ +#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 ); - +#else + tcx_scalar_quantization_fx( spectrum_fx, *spectrum_e, sqQ, L_spec, sqGain_fx, sqGain_e, st->hTcxCfg->sq_rounding, hTcxEnc->memQuantZeros, st->tcxonly, st->element_mode ); +#endif /* Estimate bitrate */ stop = 0; move16(); @@ -3445,8 +3485,12 @@ void QuantizeTCXSpectrum_fx( move16(); sqGain_e = 1; move16(); - +#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 ); +#else + tcx_scalar_quantization_fx( spectrum_fx, *spectrum_e, sqQ, L_spec, sqGain_fx, sqGain_e, st->hTcxCfg->sq_rounding, hTcxEnc->memQuantZeros, st->tcxonly, st->element_mode ); +#endif // !FIX_BASOP_2551_HARM_SCALAR_QUAN + stop = 1; IF( st->element_mode > EVS_MONO ) { diff --git a/lib_enc/ivas_stereo_mdct_stereo_enc_fx.c b/lib_enc/ivas_stereo_mdct_stereo_enc_fx.c index 31f33752132e875ed91d924dc5080ef5f9d3f911..13be061f8972d9cdda0646e4e5b56a8b4b9909a5 100644 --- a/lib_enc/ivas_stereo_mdct_stereo_enc_fx.c +++ b/lib_enc/ivas_stereo_mdct_stereo_enc_fx.c @@ -969,7 +969,12 @@ static Word16 QuantSpecEstimateBits_fx( Word16 stop, sqBits, nEncoded; Word16 lastnz; +#ifndef FIX_BASOP_2551_HARM_SCALAR_QUAN tcx_scalar_quantization_ivas_fx( spec_fx, spec_e, sqQ, length, G_fx, G_e, 16384 /*Q15*/, NULL, 1 ); +#else + // This flag could potentially be anything except EVS_MONO. In case of future errors consider passing down the flag from higher function calls. + tcx_scalar_quantization_fx( spec_fx, spec_e, sqQ, length, G_fx, G_e, 16384 /*Q15*/, NULL, 1, IVAS_SCE ); +#endif // !FIX_BASOP_2551_HARM_SCALAR_QUAN stop = 0; move16(); diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 233d7dc4f6a2e626877a77d9dba327d215caf154..6ae14c438e8d1f0ff3f22be69bcc04aa3c62c2f2 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -1143,6 +1143,7 @@ Word16 SQ_gain_estimate_fx( Word16 *gain_e /* o : SQ gain exponent */ ); +#ifndef FIX_BASOP_2551_HARM_SCALAR_QUAN void tcx_scalar_quantization_fx( Word32 *x, /* i : i coefficients */ Word16 x_e, /* i : exponent */ @@ -1153,6 +1154,8 @@ 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 ); +#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 */ diff --git a/lib_enc/tcx_utils_enc_fx.c b/lib_enc/tcx_utils_enc_fx.c index 97d17c11d206c02ef1b6b105b65dc935043a2f08..201f07b235261ebb05381103e30183366d257acd 100644 --- a/lib_enc/tcx_utils_enc_fx.c +++ b/lib_enc/tcx_utils_enc_fx.c @@ -1286,7 +1286,7 @@ Word16 SQ_gain_estimate_fx( return tmp16; } - +#ifndef FIX_BASOP_2551_HARM_SCALAR_QUAN void tcx_scalar_quantization_fx( Word32 *x, /* i : input coefficients */ Word16 x_e, /* i : exponent */ @@ -1360,8 +1360,9 @@ void tcx_scalar_quantization_fx( return; } +#endif // !FIX_BASOP_2551_HARM_SCALAR_QUAN - +#ifndef FIX_BASOP_2551_HARM_SCALAR_QUAN void tcx_scalar_quantization_ivas_fx( Word32 *x, /* i : input coefficients exponent = x_e */ Word16 x_e, /* i : exponent */ @@ -1372,6 +1373,19 @@ void tcx_scalar_quantization_ivas_fx( Word16 offset, /* i : rounding offset (deadzone) */ Word8 const *memQuantZeros_fx, /* i : coefficients to be set to 0 */ const Word16 alfe_flag ) +#else +void tcx_scalar_quantization_fx( + Word32 *x, /* i : input coefficients exponent = x_e */ + Word16 x_e, /* i : exponent */ + Word16 *xq, /* o : quantized coefficients */ + Word16 L_frame, /* i : frame length */ + Word16 gain, /* i : quantization gain exponent = gain_e */ + Word16 gain_e, /* i : quantization gain exponent */ + Word16 offset, /* i : rounding offset (deadzone) */ + Word8 const *memQuantZeros_fx, /* i : coefficients to be set to 0 */ + const Word16 alfe_flag, + const Word16 element_mode ) +#endif // !FIX_BASOP_2551_HARM_SCALAR_QUAN { Word16 i, tmp16, s; Word32 tmp32, offs32; @@ -1380,7 +1394,12 @@ void tcx_scalar_quantization_ivas_fx( /* common exponent for x and gain for comparison */ tmp16 = sub( gain_e, x_e ); +#ifndef FIX_BASOP_2551_HARM_SCALAR_QUAN tmp32 = L_shl_sat( L_deposit_h( gain ), tmp16 ); // exp:x_e +#else + tmp32 = L_shl( L_deposit_h( gain ), s_max( -31, s_min( tmp16, 0 ) ) ); + tmp16 = negate( s_max( tmp16, 0 ) ); +#endif // !FIX_BASOP_2551_HARM_SCALAR_QUAN i = sub( L_frame, 1 ); IF( memQuantZeros_fx != NULL ) @@ -1411,6 +1430,15 @@ void tcx_scalar_quantization_ivas_fx( s = sub( add( x_e, gain_e ), 15 ); } +#ifdef FIX_BASOP_2551_HARM_SCALAR_QUAN + if ( EQ_16( element_mode, EVS_MONO ) ) + { + offset = sub( offset, 0x4000 ); + } +#endif // FIX_BASOP_2551_HARM_SCALAR_QUAN + + +#ifndef FIX_BASOP_2551_HARM_SCALAR_QUAN FOR( ; i >= 0; i-- ) { offs32 = Mpy_32_16_1( x[i], gain ); @@ -1430,6 +1458,49 @@ void tcx_scalar_quantization_ivas_fx( xq[i] = tmp16; move16(); } +#else + IF( EQ_16( element_mode, EVS_MONO ) ) + { + FOR( ; i >= 0; i-- ) + { + offs32 = Mpy_32_16_1( L_abs( x[i] ), gain ); /* multiply */ + offs32 = L_shl_sat( offs32, s ); /* convert to 15Q16 */ + tmp16 = mac_r_sat( offs32, offset, 1 ); /* add offset and truncate */ + + if ( x[i] < 0 ) + { + tmp16 = negate( tmp16 ); /* restore sign */ + } + + xq[i] = tmp16; + move16(); + } + } + ELSE + { + FOR( ; i >= 0; i-- ) + { + offs32 = Mpy_32_16_1( x[i], gain ); + offs32 = L_shl_sat( offs32, s ); /* convert to 15Q16 */ + + offs32_1 = L_add_sat( offs32, offset_Q16 ); /*15Q16 */ + tmp16 = extract_h( offs32_1 ); + + IF( x[i] < 0 ) + { + offs32 = L_sub_sat( offs32, offset_Q16 ); /*15Q16 */ + tmp16 = extract_h( offs32 ); + if ( L_mac_sat( offs32, tmp16, -ONE_IN_Q15 ) > 0 ) + { + tmp16 = add( tmp16, 1 ); + } + } + + xq[i] = tmp16; + move16(); + } + } +#endif IF( alfe_flag == 0 ) { @@ -1665,7 +1736,6 @@ Word16 tcx_scalar_quantization_rateloop_fx( /* Quantize spectrum */ tcx_scalar_quantization_fx( x, x_e, xq, L_frame, sqGain, sqGain_e, offset, memQuantZeros_fx, tcxonly ); - /* Estimate bitrate */ stopFlag = 1; move16(); @@ -2140,6 +2210,7 @@ Word16 tcx_scalar_quantization_rateloop_fx( } /* Quantize spectrum */ +#ifndef FIX_BASOP_2551_HARM_SCALAR_QUAN #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 @@ -2152,6 +2223,9 @@ Word16 tcx_scalar_quantization_rateloop_fx( 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 +#else + tcx_scalar_quantization_fx( x, x_e, xq, L_frame, sqGain, sqGain_e, offset, memQuantZeros_fx, tcxonly, element_mode ); +#endif // !FIX_BASOP_2551_HARM_SCALAR_QUAN /* Estimate bitrate */ stopFlag = 1; move16(); @@ -2206,6 +2280,8 @@ Word16 tcx_scalar_quantization_rateloop_fx( IF( GE_16( tcxRateLoopOpt, 1 ) ) { +#ifndef FIX_BASOP_2551_HARM_SCALAR_QUAN + #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 ); @@ -2220,6 +2296,11 @@ Word16 tcx_scalar_quantization_rateloop_fx( } #endif // !FIX_BASOP_2546_HARMONIZE_TCX_SCALAR +#else + tcx_scalar_quantization_fx( x, x_e, xq, L_frame, *gain, *gain_e, offset, memQuantZeros_fx, tcxonly, element_mode ); +#endif // !FIX_BASOP_2551_HARM_SCALAR_QUAN + + /* Output */ *nEncoded = old_nEncoded; move16();