Loading lib_com/options.h +0 −1 Original line number Diff line number Diff line Loading @@ -95,7 +95,6 @@ #define SIMPLIFY_CORE_ENC /* VA: basop issue 2430: Simplify ivas_core_enc_fx() */ #define FIX_2402_SIMPLIFY_ARI_CODEC /* FhG: basop issue 2402: simplified arithmetic in TCX arithmetic coder */ #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 */ Loading lib_enc/cod_tcx_fx.c +0 −22 Original line number Diff line number Diff line Loading @@ -1632,23 +1632,6 @@ 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, &sqGain, &sqGain_e, hTcxCfg->sq_rounding, hTcxEnc->memQuantZeros, prm_lastnz, /* lastnz */ sqTargetBits, &nEncoded, &stop, sqBits_noStop, sqBits, hTcxCfg->tcxRateLoopOpt, tcxonly, phm_cfg ); #else Word16 max_iter = 4; move16(); IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) Loading @@ -1675,7 +1658,6 @@ void QuantizeSpectrum_fx( 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 */ Loading Loading @@ -3280,11 +3262,7 @@ 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 */ Loading lib_enc/prot_fx_enc.h +0 −25 Original line number Diff line number Diff line Loading @@ -1156,33 +1156,8 @@ 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 */ Word16 *xq, /* o : quantized coefficients */ Word16 L_frame, /* i : frame length */ Word16 *gain, /* i/o: quantization gain */ Word16 *gain_e, /* i/o: gain exponent */ Word16 offset, /* i : rounding offset (deadzone) */ Word8 const *memQuantZeros, /* i : coefficients to be set to 0 */ Word16 *lastnz_out, /* i/o: last nonzero coeff index */ Word16 target, /* i : target number of bits */ Word16 *nEncoded, /* o : number of encoded coeff */ Word16 *stop, /* i/o: stop param */ Word16 sqBits_in_noStop, /* i : number of sqBits as determined in prev. quant. stage, w/o using stop mechanism (ie might exceed target bits) */ Word16 sqBits_in, /* i : number of sqBits as determined in prev. quant. stage, using stop mechanism (ie always <= target bits) */ Word16 tcxRateLoopOpt, /* i : turns on/off rateloop optimization */ 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*/ Loading lib_enc/tcx_utils_enc_fx.c +0 −401 Original line number Diff line number Diff line Loading @@ -1499,309 +1499,8 @@ 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 */ Word16 *xq, /* o : quantized coefficients */ Word16 L_frame, /* i : frame length */ Word16 *gain, /* i/o: quantization gain */ Word16 *gain_e, /* i/o: gain exponent */ Word16 offset, /* i : rounding offset (deadzone) */ Word8 const *memQuantZeros_fx, /* i : coefficients to be set to 0 */ Word16 *lastnz_out, /* i/o: last nonzero coeff index */ Word16 target, /* i : target number of bits */ Word16 *nEncoded, /* o : number of encoded coeff */ Word16 *stop, /* i/o: stop param */ Word16 sqBits_in_noStop, /* i : number of sqBits as determined in prev. quant. stage, w/o using stop mechanism (ie might exceed target bits) */ Word16 sqBits_in, /* i : number of sqBits as determined in prev. quant. stage, using stop mechanism (ie always <= target bits) */ Word16 tcxRateLoopOpt, /* i : turns on/off rateloop optimization */ const Word8 tcxonly, CONTEXT_HM_CONFIG *hm_cfg /* i : configuration of the context-based harmonic model */ ) { const Word16 iter_max = 4; Word16 sqBits; Word16 stopFlag; Word8 ubfound, lbfound; Word16 ub, ub_e, lb, lb_e; Word16 shift, shiftInv; Word16 iter; Word16 sqGain, sqGain_e; Word16 w_lb, w_ub; const Word16 kDampen = 10; Word16 old_stopFlag; Word16 old_nEncoded; Word16 old_sqBits; Word16 mod_adjust0, mod_adjust1; Word16 inv_target, inv_target_e; const Word16 kMargin = 0x7AE1; /* 0.96 */ const Word16 kMarginInv = 0x42AB; /* 1/0.96 (1Q14) */ Word16 tmp, fac1, fac2; Word32 tmp32; Word16 lastnz; move16(); move16(); move16(); move16(); /* Init */ sqGain = *gain; move16(); sqGain_e = *gain_e; move16(); stopFlag = *stop; move16(); ubfound = 0; move16(); lbfound = 0; move16(); shift = 0x41DE; /* 10^(1/80), 1Q14 */ move16(); shiftInv = 0x78D7; /* 10^(-1/40) */ move16(); lb = lb_e = 0; move16(); ub = ub_e = 0; move16(); w_lb = 0; move16(); w_ub = 0; move16(); lastnz = *lastnz_out; move16(); old_stopFlag = stopFlag; move16(); old_nEncoded = *nEncoded; move16(); old_sqBits = sqBits_in_noStop; move16(); sqBits = sqBits_in; move16(); mod_adjust0 = extract_l( L_shr( L_max( 0x10000, L_sub( 0x24CCD, L_mult( 0x0052, target ) ) ), 3 ) ); /* 2Q13 */ mod_adjust1 = div_s( 0x2000, mod_adjust0 ); /* 0Q15 */ inv_target_e = 15; move16(); inv_target = Inv16( target, &inv_target_e ); fac1 = shl( mult( mult( kMarginInv, mod_adjust0 ), inv_target ), 1 ); /* 2Q13 */ fac2 = mult( mult( kMargin, mod_adjust1 ), inv_target ); /* Loop */ FOR( iter = 0; iter < iter_max; iter++ ) { IF( EQ_16( tcxRateLoopOpt, 2 ) ) { /* Ajust sqGain */ IF( stopFlag != 0 ) { lbfound = 1; move16(); lb = sqGain; move16(); lb_e = sqGain_e; move16(); w_lb = add( sub( stopFlag, target ), kDampen ); IF( ubfound != 0 ) { /* common exponent for addition */ sqGain_e = s_max( lb_e, ub_e ); /* multiply and add */ tmp32 = L_shr( L_mult( lb, w_ub ), sub( sqGain_e, lb_e ) ); tmp32 = L_add( tmp32, L_shr( L_mult( ub, w_lb ), sub( sqGain_e, ub_e ) ) ); /* convert to normalized 16 bit */ tmp = norm_l( tmp32 ); sqGain = round_fx_sat( L_shl( tmp32, tmp ) ); sqGain_e = sub( sqGain_e, tmp ); /* divide */ sqGain = BASOP_Util_Divide1616_Scale( sqGain, add( w_ub, w_lb ), &tmp ); sqGain_e = add( sqGain_e, tmp ); } ELSE { tmp = round_fx( L_shl( L_mult( stopFlag, fac1 ), add( inv_target_e, 15 ) ) ); sqGain = mult( sqGain, sub( tmp, sub( mod_adjust0, 0x2000 ) ) ); sqGain = normalize16( sqGain, &sqGain_e ); sqGain_e = add( sqGain_e, 2 ); } } ELSE { ubfound = 1; move16(); ub = sqGain; move16(); ub_e = sqGain_e; move16(); w_ub = add( sub( target, sqBits ), kDampen ); IF( lbfound != 0 ) { /* common exponent for addition */ sqGain_e = s_max( lb_e, ub_e ); /* multiply and add */ tmp32 = L_shr( L_mult( lb, w_ub ), sub( sqGain_e, lb_e ) ); tmp32 = L_add( tmp32, L_shr( L_mult( ub, w_lb ), sub( sqGain_e, ub_e ) ) ); /* convert to normalized 16 bit */ tmp = norm_l( tmp32 ); sqGain = round_fx_sat( L_shl_sat( tmp32, tmp ) ); sqGain_e = sub( sqGain_e, tmp ); /* divide */ sqGain = BASOP_Util_Divide1616_Scale( sqGain, add( w_ub, w_lb ), &tmp ); sqGain_e = add( sqGain_e, tmp ); } ELSE { tmp = round_fx( L_shl( L_mult( sqBits, fac2 ), add( inv_target_e, 15 ) ) ); sqGain = mult( sqGain, sub( tmp, add( mod_adjust1, (Word16) 0x8000 ) ) ); sqGain = normalize16( sqGain, &sqGain_e ); } } } ELSE /* tcxRateLoopOpt != 2 */ { /* Ajust sqGain */ IF( stopFlag != 0 ) { lbfound = 1; move16(); lb = sqGain; move16(); lb_e = sqGain_e; move16(); IF( ubfound != 0 ) { sqGain = mult( lb, ub ); sqGain_e = add( lb_e, ub_e ); sqGain = Sqrt16( sqGain, &sqGain_e ); } ELSE { shift = shl( mult( shift, shift ), 1 ); shiftInv = mult( shiftInv, shiftInv ); sqGain = mult( sqGain, shift ); sqGain = normalize16( sqGain, &sqGain_e ); sqGain_e = add( sqGain_e, 1 ); } } ELSE { ubfound = 1; move16(); ub = sqGain; move16(); ub_e = sqGain_e; move16(); IF( lbfound != 0 ) { sqGain = mult( lb, ub ); sqGain_e = add( lb_e, ub_e ); sqGain = Sqrt16( sqGain, &sqGain_e ); } ELSE { sqGain = mult( sqGain, shiftInv ); sqGain = normalize16( sqGain, &sqGain_e ); shift = shl( mult( shift, shift ), 1 ); shiftInv = mult( shiftInv, shiftInv ); } } } /* Quantize spectrum */ tcx_scalar_quantization_fx( x, x_e, xq, L_frame, sqGain, sqGain_e, offset, memQuantZeros_fx, tcxonly ); /* Estimate bitrate */ stopFlag = 1; move16(); if ( tcxRateLoopOpt > 0 ) { stopFlag = 0; move16(); } sqBits = ACcontextMapping_encode2_estimate_no_mem_s17_LC_fx( xq, L_frame, &lastnz, nEncoded, target, &stopFlag, hm_cfg ); IF( tcxRateLoopOpt > 0 ) { test(); test(); test(); test(); test(); test(); IF( ( ( GE_16( *nEncoded, old_nEncoded ) ) && ( GE_16( stopFlag, old_stopFlag ) ) ) || ( ( GT_16( *nEncoded, old_nEncoded ) ) && ( ( stopFlag == 0 ) && ( old_stopFlag > 0 ) ) ) || ( ( stopFlag == 0 ) && ( old_stopFlag == 0 ) ) ) { *gain = sqGain; move16(); *gain_e = sqGain_e; move16(); old_nEncoded = *nEncoded; move16(); old_stopFlag = stopFlag; move16(); old_sqBits = sqBits; move16(); *lastnz_out = lastnz; move16(); } } } /* for ( iter=0 ; iter<iter_max ; iter++ ) */ IF( tcxRateLoopOpt > 0 ) { /* Quantize spectrum */ tcx_scalar_quantization_fx( x, x_e, xq, L_frame, *gain, *gain_e, offset, memQuantZeros_fx, tcxonly ); /* Output */ *nEncoded = old_nEncoded; move16(); sqBits = old_sqBits; move16(); *stop = old_stopFlag; move16(); } ELSE { /* Output */ *gain = sqGain; move16(); *gain_e = sqGain_e; move16(); *stop = stopFlag; move16(); *lastnz_out = lastnz; move16(); } 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*/ Loading Loading @@ -1850,65 +1549,6 @@ Word16 tcx_scalar_quantization_rateloop_fx( 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 ) Loading Loading @@ -1969,7 +1609,6 @@ Word16 tcx_scalar_quantization_rateloop_fx( } move16(); } #endif // !FIX_BASOP_2546_HARMONIZE_TCX_SCALAR sqGain = *gain; move16(); Loading Loading @@ -2030,16 +1669,11 @@ Word16 tcx_scalar_quantization_rateloop_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 */ Loading Loading @@ -2100,20 +1734,6 @@ Word16 tcx_scalar_quantization_rateloop_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 ); Loading @@ -2129,19 +1749,11 @@ Word16 tcx_scalar_quantization_rateloop_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 */ { Loading Loading @@ -2200,9 +1812,6 @@ 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 IF( EQ_16( element_mode, EVS_MONO ) ) { tcx_scalar_quantization_fx( x, x_e, xq, L_frame, sqGain, sqGain_e, offset, memQuantZeros_fx, tcxonly ); Loading @@ -2211,7 +1820,6 @@ 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 Loading @@ -2223,11 +1831,7 @@ Word16 tcx_scalar_quantization_rateloop_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 ); } Loading Loading @@ -2271,10 +1875,6 @@ Word16 tcx_scalar_quantization_rateloop_fx( { #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 ); #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 ); Loading @@ -2283,7 +1883,6 @@ Word16 tcx_scalar_quantization_rateloop_fx( { 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 #else tcx_scalar_quantization_fx( x, x_e, xq, L_frame, *gain, *gain_e, offset, memQuantZeros_fx, tcxonly, element_mode ); Loading Loading
lib_com/options.h +0 −1 Original line number Diff line number Diff line Loading @@ -95,7 +95,6 @@ #define SIMPLIFY_CORE_ENC /* VA: basop issue 2430: Simplify ivas_core_enc_fx() */ #define FIX_2402_SIMPLIFY_ARI_CODEC /* FhG: basop issue 2402: simplified arithmetic in TCX arithmetic coder */ #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 */ Loading
lib_enc/cod_tcx_fx.c +0 −22 Original line number Diff line number Diff line Loading @@ -1632,23 +1632,6 @@ 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, &sqGain, &sqGain_e, hTcxCfg->sq_rounding, hTcxEnc->memQuantZeros, prm_lastnz, /* lastnz */ sqTargetBits, &nEncoded, &stop, sqBits_noStop, sqBits, hTcxCfg->tcxRateLoopOpt, tcxonly, phm_cfg ); #else Word16 max_iter = 4; move16(); IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) Loading @@ -1675,7 +1658,6 @@ void QuantizeSpectrum_fx( 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 */ Loading Loading @@ -3280,11 +3262,7 @@ 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 */ Loading
lib_enc/prot_fx_enc.h +0 −25 Original line number Diff line number Diff line Loading @@ -1156,33 +1156,8 @@ 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 */ Word16 *xq, /* o : quantized coefficients */ Word16 L_frame, /* i : frame length */ Word16 *gain, /* i/o: quantization gain */ Word16 *gain_e, /* i/o: gain exponent */ Word16 offset, /* i : rounding offset (deadzone) */ Word8 const *memQuantZeros, /* i : coefficients to be set to 0 */ Word16 *lastnz_out, /* i/o: last nonzero coeff index */ Word16 target, /* i : target number of bits */ Word16 *nEncoded, /* o : number of encoded coeff */ Word16 *stop, /* i/o: stop param */ Word16 sqBits_in_noStop, /* i : number of sqBits as determined in prev. quant. stage, w/o using stop mechanism (ie might exceed target bits) */ Word16 sqBits_in, /* i : number of sqBits as determined in prev. quant. stage, using stop mechanism (ie always <= target bits) */ Word16 tcxRateLoopOpt, /* i : turns on/off rateloop optimization */ 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*/ Loading
lib_enc/tcx_utils_enc_fx.c +0 −401 Original line number Diff line number Diff line Loading @@ -1499,309 +1499,8 @@ 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 */ Word16 *xq, /* o : quantized coefficients */ Word16 L_frame, /* i : frame length */ Word16 *gain, /* i/o: quantization gain */ Word16 *gain_e, /* i/o: gain exponent */ Word16 offset, /* i : rounding offset (deadzone) */ Word8 const *memQuantZeros_fx, /* i : coefficients to be set to 0 */ Word16 *lastnz_out, /* i/o: last nonzero coeff index */ Word16 target, /* i : target number of bits */ Word16 *nEncoded, /* o : number of encoded coeff */ Word16 *stop, /* i/o: stop param */ Word16 sqBits_in_noStop, /* i : number of sqBits as determined in prev. quant. stage, w/o using stop mechanism (ie might exceed target bits) */ Word16 sqBits_in, /* i : number of sqBits as determined in prev. quant. stage, using stop mechanism (ie always <= target bits) */ Word16 tcxRateLoopOpt, /* i : turns on/off rateloop optimization */ const Word8 tcxonly, CONTEXT_HM_CONFIG *hm_cfg /* i : configuration of the context-based harmonic model */ ) { const Word16 iter_max = 4; Word16 sqBits; Word16 stopFlag; Word8 ubfound, lbfound; Word16 ub, ub_e, lb, lb_e; Word16 shift, shiftInv; Word16 iter; Word16 sqGain, sqGain_e; Word16 w_lb, w_ub; const Word16 kDampen = 10; Word16 old_stopFlag; Word16 old_nEncoded; Word16 old_sqBits; Word16 mod_adjust0, mod_adjust1; Word16 inv_target, inv_target_e; const Word16 kMargin = 0x7AE1; /* 0.96 */ const Word16 kMarginInv = 0x42AB; /* 1/0.96 (1Q14) */ Word16 tmp, fac1, fac2; Word32 tmp32; Word16 lastnz; move16(); move16(); move16(); move16(); /* Init */ sqGain = *gain; move16(); sqGain_e = *gain_e; move16(); stopFlag = *stop; move16(); ubfound = 0; move16(); lbfound = 0; move16(); shift = 0x41DE; /* 10^(1/80), 1Q14 */ move16(); shiftInv = 0x78D7; /* 10^(-1/40) */ move16(); lb = lb_e = 0; move16(); ub = ub_e = 0; move16(); w_lb = 0; move16(); w_ub = 0; move16(); lastnz = *lastnz_out; move16(); old_stopFlag = stopFlag; move16(); old_nEncoded = *nEncoded; move16(); old_sqBits = sqBits_in_noStop; move16(); sqBits = sqBits_in; move16(); mod_adjust0 = extract_l( L_shr( L_max( 0x10000, L_sub( 0x24CCD, L_mult( 0x0052, target ) ) ), 3 ) ); /* 2Q13 */ mod_adjust1 = div_s( 0x2000, mod_adjust0 ); /* 0Q15 */ inv_target_e = 15; move16(); inv_target = Inv16( target, &inv_target_e ); fac1 = shl( mult( mult( kMarginInv, mod_adjust0 ), inv_target ), 1 ); /* 2Q13 */ fac2 = mult( mult( kMargin, mod_adjust1 ), inv_target ); /* Loop */ FOR( iter = 0; iter < iter_max; iter++ ) { IF( EQ_16( tcxRateLoopOpt, 2 ) ) { /* Ajust sqGain */ IF( stopFlag != 0 ) { lbfound = 1; move16(); lb = sqGain; move16(); lb_e = sqGain_e; move16(); w_lb = add( sub( stopFlag, target ), kDampen ); IF( ubfound != 0 ) { /* common exponent for addition */ sqGain_e = s_max( lb_e, ub_e ); /* multiply and add */ tmp32 = L_shr( L_mult( lb, w_ub ), sub( sqGain_e, lb_e ) ); tmp32 = L_add( tmp32, L_shr( L_mult( ub, w_lb ), sub( sqGain_e, ub_e ) ) ); /* convert to normalized 16 bit */ tmp = norm_l( tmp32 ); sqGain = round_fx_sat( L_shl( tmp32, tmp ) ); sqGain_e = sub( sqGain_e, tmp ); /* divide */ sqGain = BASOP_Util_Divide1616_Scale( sqGain, add( w_ub, w_lb ), &tmp ); sqGain_e = add( sqGain_e, tmp ); } ELSE { tmp = round_fx( L_shl( L_mult( stopFlag, fac1 ), add( inv_target_e, 15 ) ) ); sqGain = mult( sqGain, sub( tmp, sub( mod_adjust0, 0x2000 ) ) ); sqGain = normalize16( sqGain, &sqGain_e ); sqGain_e = add( sqGain_e, 2 ); } } ELSE { ubfound = 1; move16(); ub = sqGain; move16(); ub_e = sqGain_e; move16(); w_ub = add( sub( target, sqBits ), kDampen ); IF( lbfound != 0 ) { /* common exponent for addition */ sqGain_e = s_max( lb_e, ub_e ); /* multiply and add */ tmp32 = L_shr( L_mult( lb, w_ub ), sub( sqGain_e, lb_e ) ); tmp32 = L_add( tmp32, L_shr( L_mult( ub, w_lb ), sub( sqGain_e, ub_e ) ) ); /* convert to normalized 16 bit */ tmp = norm_l( tmp32 ); sqGain = round_fx_sat( L_shl_sat( tmp32, tmp ) ); sqGain_e = sub( sqGain_e, tmp ); /* divide */ sqGain = BASOP_Util_Divide1616_Scale( sqGain, add( w_ub, w_lb ), &tmp ); sqGain_e = add( sqGain_e, tmp ); } ELSE { tmp = round_fx( L_shl( L_mult( sqBits, fac2 ), add( inv_target_e, 15 ) ) ); sqGain = mult( sqGain, sub( tmp, add( mod_adjust1, (Word16) 0x8000 ) ) ); sqGain = normalize16( sqGain, &sqGain_e ); } } } ELSE /* tcxRateLoopOpt != 2 */ { /* Ajust sqGain */ IF( stopFlag != 0 ) { lbfound = 1; move16(); lb = sqGain; move16(); lb_e = sqGain_e; move16(); IF( ubfound != 0 ) { sqGain = mult( lb, ub ); sqGain_e = add( lb_e, ub_e ); sqGain = Sqrt16( sqGain, &sqGain_e ); } ELSE { shift = shl( mult( shift, shift ), 1 ); shiftInv = mult( shiftInv, shiftInv ); sqGain = mult( sqGain, shift ); sqGain = normalize16( sqGain, &sqGain_e ); sqGain_e = add( sqGain_e, 1 ); } } ELSE { ubfound = 1; move16(); ub = sqGain; move16(); ub_e = sqGain_e; move16(); IF( lbfound != 0 ) { sqGain = mult( lb, ub ); sqGain_e = add( lb_e, ub_e ); sqGain = Sqrt16( sqGain, &sqGain_e ); } ELSE { sqGain = mult( sqGain, shiftInv ); sqGain = normalize16( sqGain, &sqGain_e ); shift = shl( mult( shift, shift ), 1 ); shiftInv = mult( shiftInv, shiftInv ); } } } /* Quantize spectrum */ tcx_scalar_quantization_fx( x, x_e, xq, L_frame, sqGain, sqGain_e, offset, memQuantZeros_fx, tcxonly ); /* Estimate bitrate */ stopFlag = 1; move16(); if ( tcxRateLoopOpt > 0 ) { stopFlag = 0; move16(); } sqBits = ACcontextMapping_encode2_estimate_no_mem_s17_LC_fx( xq, L_frame, &lastnz, nEncoded, target, &stopFlag, hm_cfg ); IF( tcxRateLoopOpt > 0 ) { test(); test(); test(); test(); test(); test(); IF( ( ( GE_16( *nEncoded, old_nEncoded ) ) && ( GE_16( stopFlag, old_stopFlag ) ) ) || ( ( GT_16( *nEncoded, old_nEncoded ) ) && ( ( stopFlag == 0 ) && ( old_stopFlag > 0 ) ) ) || ( ( stopFlag == 0 ) && ( old_stopFlag == 0 ) ) ) { *gain = sqGain; move16(); *gain_e = sqGain_e; move16(); old_nEncoded = *nEncoded; move16(); old_stopFlag = stopFlag; move16(); old_sqBits = sqBits; move16(); *lastnz_out = lastnz; move16(); } } } /* for ( iter=0 ; iter<iter_max ; iter++ ) */ IF( tcxRateLoopOpt > 0 ) { /* Quantize spectrum */ tcx_scalar_quantization_fx( x, x_e, xq, L_frame, *gain, *gain_e, offset, memQuantZeros_fx, tcxonly ); /* Output */ *nEncoded = old_nEncoded; move16(); sqBits = old_sqBits; move16(); *stop = old_stopFlag; move16(); } ELSE { /* Output */ *gain = sqGain; move16(); *gain_e = sqGain_e; move16(); *stop = stopFlag; move16(); *lastnz_out = lastnz; move16(); } 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*/ Loading Loading @@ -1850,65 +1549,6 @@ Word16 tcx_scalar_quantization_rateloop_fx( 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 ) Loading Loading @@ -1969,7 +1609,6 @@ Word16 tcx_scalar_quantization_rateloop_fx( } move16(); } #endif // !FIX_BASOP_2546_HARMONIZE_TCX_SCALAR sqGain = *gain; move16(); Loading Loading @@ -2030,16 +1669,11 @@ Word16 tcx_scalar_quantization_rateloop_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 */ Loading Loading @@ -2100,20 +1734,6 @@ Word16 tcx_scalar_quantization_rateloop_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 ); Loading @@ -2129,19 +1749,11 @@ Word16 tcx_scalar_quantization_rateloop_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 */ { Loading Loading @@ -2200,9 +1812,6 @@ 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 IF( EQ_16( element_mode, EVS_MONO ) ) { tcx_scalar_quantization_fx( x, x_e, xq, L_frame, sqGain, sqGain_e, offset, memQuantZeros_fx, tcxonly ); Loading @@ -2211,7 +1820,6 @@ 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 Loading @@ -2223,11 +1831,7 @@ Word16 tcx_scalar_quantization_rateloop_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 ); } Loading Loading @@ -2271,10 +1875,6 @@ Word16 tcx_scalar_quantization_rateloop_fx( { #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 ); #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 ); Loading @@ -2283,7 +1883,6 @@ Word16 tcx_scalar_quantization_rateloop_fx( { 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 #else tcx_scalar_quantization_fx( x, x_e, xq, L_frame, *gain, *gain_e, offset, memQuantZeros_fx, tcxonly, element_mode ); Loading