diff --git a/lib_com/options.h b/lib_com/options.h index de58042aba8d9a43b843ab5216d16e23d5b3afb3..8b31fe195cb9290f127d9f0edfde4d201a49caf6 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -101,6 +101,8 @@ #define HARMONIZE_2607_GetFilterParameters /* FhG: Harmonize GetFilterParameters with its ivas derivate */ #define HAMRONIZE_2606_ENC_PRM /* FhG: Harmonize enc_prm_fx(), to match floating-point code */ #define HARMONIZE_2604_decoder_tcx_post /* FhG: Harmonize decoder_tcx_post with its ivas derivate */ +#define HARMONIZE_2598_tcx_arith_decode_envelope /* FhG: harmonize tcx_arith_decode_envelope between EVS and IVAS versions */ +#define HARMONIZE_2598_tcx_arith_encode_envelope /* FhG: harmonize tcx_arith_encode_envelope between EVS and IVAS versions */ /* #################### End BE switches ################################## */ diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index c741a5ff74692ec1886cf35d08fcb47d155c9480..39092d3025c5bd594997cf34a6ec2c1e8c8d6ed5 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -8009,6 +8009,7 @@ void decoder_tcx_post_fx( Word16 bfi ); #endif +#ifndef HARMONIZE_2598_tcx_arith_decode_envelope void tcx_arith_decode_envelope_fx( Word32 q_spectrum[], /* o: quantised MDCT coefficients Q31-e */ Word16 *q_spectrum_e, /* o: MDCT exponent Q0 */ @@ -8026,6 +8027,7 @@ void tcx_arith_decode_envelope_fx( Word16 *nf_seed, /* o: noise filling seed Q0 */ Word16 low_complexity /* i: low-complexity flag Q0 */ ); +#endif void tcx_decoder_memory_update( Word16 *xn_buf, /* i/o: mdct output buffer used also as temporary buffer : Q0 */ @@ -10005,9 +10007,28 @@ void tcx_arith_render_envelope_ivas_fx( Word32 env[] /* o : shaped signal envelope Q16*/ ); +#ifdef HARMONIZE_2598_tcx_arith_decode_envelope +void tcx_arith_decode_envelope_fx( + Decoder_State *st, + /* i/o: coder state */ /*EVS: move argument 5->1 */ + Word32 q_spectrum[], /* o : quantised MDCT coefficients Q(31-q_spectrum_e) */ + Word16 *q_spectrum_e, /* o : MDCT exponent */ + const Word16 L_frame, /* i : frame or MDCT length */ + Word16 L_spec, /* i : length w/o BW limitation */ + const Word16 A_ind[], /* i : quantised LPC coefficients */ + const Word16 target_bits, /* i : number of available bits */ + Word16 prm[], /* i : bitstream parameters */ + const Word16 use_hm, /* i : use HM in current frame? */ + Word16 prm_hm[], /* i : HM parameter area */ + Word16 tcxltp_pitch, /* i : TCX LTP pitch in FD, -1 if n/a*/ + Word16 *arith_bits, /* o : bits used for ari. coding */ + Word16 *signaling_bits, /* o : bits used for signaling */ + Word16 *nf_seed, /* o : noise filling seed Q0 */ + const Word16 low_complexity /* i : low-complexity flag */ +#else void tcx_arith_decode_envelope_ivas_fx( Decoder_State *st, /* i/o: coder state */ - Word32 q_spectrum[], /* o : quantised MDCT coefficients */ + Word32 q_spectrum[], /* o : quantised MDCT coefficients Q(31-q_spectrum_e) */ Word16 *q_spectrum_e, /* o : MDCT exponent */ const Word16 L_frame, /* i : frame or MDCT length */ Word16 L_spec, /* i : length w/o BW limitation */ @@ -10015,11 +10036,12 @@ void tcx_arith_decode_envelope_ivas_fx( const Word16 target_bits, /* i : number of available bits */ Word16 prm[], /* i : bitstream parameters */ const Word16 use_hm, /* i : use HM in current frame? */ - const Word16 prm_hm[], /* i : HM parameter area */ + Word16 prm_hm[], /* i : HM parameter area */ Word16 tcxltp_pitch, /* i : TCX LTP pitch in FD, -1 if n/a*/ Word16 *arith_bits, /* o : bits used for ari. coding */ Word16 *signaling_bits, /* o : bits used for signaling */ const Word16 low_complexity /* i : low-complexity flag */ +#endif ); void UnmapIndex_fx( diff --git a/lib_dec/arith_coder_dec_fx.c b/lib_dec/arith_coder_dec_fx.c index 3ac4963c0e31df182d139bf30e31e674e24d990c..96efe3fcd19624f62c5892295a3635794628d8a7 100644 --- a/lib_dec/arith_coder_dec_fx.c +++ b/lib_dec/arith_coder_dec_fx.c @@ -90,6 +90,7 @@ static Word16 tcx_arith_decode_fx( return bp; } +#ifndef HARMONIZE_2598_tcx_arith_decode_envelope void tcx_arith_decode_envelope_fx( Word32 q_spectrum[], /* o : quantised MDCT coefficients Q31-e */ Word16 *q_spectrum_e, /* o : MDCT exponent Q0 */ @@ -209,6 +210,7 @@ void tcx_arith_decode_envelope_fx( set32_fx( q_spectrum + L_spec, 0, sub( L_frame, L_spec ) ); } +#endif /*-------------------------------------------------------* * tcx_arith_decode() @@ -293,6 +295,26 @@ static Word16 tcx_arith_decode_ivas_fx( * *-------------------------------------------------------*/ +#ifdef HARMONIZE_2598_tcx_arith_decode_envelope +void tcx_arith_decode_envelope_fx( + Decoder_State *st, + /* i/o: coder state */ /*EVS: move argument 5->1 */ + Word32 q_spectrum[], /* o : quantised MDCT coefficients Q(31-q_spectrum_e) */ + Word16 *q_spectrum_e, /* o : MDCT exponent */ + const Word16 L_frame, /* i : frame or MDCT length */ + Word16 L_spec, /* i : length w/o BW limitation */ + const Word16 A_ind[], /* i : quantised LPC coefficients */ + const Word16 target_bits, /* i : number of available bits */ + Word16 prm[], /* i : bitstream parameters */ + const Word16 use_hm, /* i : use HM in current frame? */ + Word16 prm_hm[], /* i : HM parameter area */ + Word16 tcxltp_pitch, /* i : TCX LTP pitch in FD, -1 if n/a*/ + Word16 *arith_bits, /* o : bits used for ari. coding */ + Word16 *signaling_bits, /* o : bits used for signaling */ + Word16 *nf_seed, + /* o : noise filling seed Q0 */ /*IVAS: 0*/ + const Word16 low_complexity /* i : low-complexity flag */ +#else void tcx_arith_decode_envelope_ivas_fx( Decoder_State *st, /* i/o: coder state */ Word32 q_spectrum[], /* o : quantised MDCT coefficients Q(31-q_spectrum_e) */ @@ -308,6 +330,7 @@ void tcx_arith_decode_envelope_ivas_fx( Word16 *arith_bits, /* o : bits used for ari. coding */ Word16 *signaling_bits, /* o : bits used for signaling */ const Word16 low_complexity /* i : low-complexity flag */ +#endif ) { Word32 env[N_MAX_ARI]; /* unscaled envelope (Q16) */ @@ -315,7 +338,6 @@ void tcx_arith_decode_envelope_ivas_fx( Word16 envelope_e; Word16 L_spec_core; TCX_CONFIG_HANDLE hTcxCfg; - TCX_DEC_HANDLE hTcxDec; Word16 gamma_w, gamma_uw; Word16 hm_bits; @@ -326,7 +348,7 @@ void tcx_arith_decode_envelope_ivas_fx( test(); test(); test(); - IF( GT_16( L_spec, N_MAX_ARI ) || ( ( st->element_mode == EVS_MONO ) && GT_16( target_bits, ( ACELP_13k20 / FRAMES_PER_SEC ) ) ) || + IF( GT_16( L_spec, N_MAX_ARI ) || ( EQ_16( st->element_mode, EVS_MONO ) && GT_16( target_bits, ( ACELP_13k20 / FRAMES_PER_SEC ) ) ) || ( EQ_16( st->element_mode, IVAS_SCE ) && ( GT_16( st->bits_frame_nominal, ( LPC_SHAPED_ARI_MAX_RATE / FRAMES_PER_SEC ) ) ) ) || ( GT_16( st->element_mode, IVAS_SCE ) && ( GT_16( st->bits_frame_nominal, ( LPC_SHAPED_ARI_MAX_RATE_CPE / FRAMES_PER_SEC ) ) ) ) || ( target_bits <= 0 ) ) @@ -346,17 +368,27 @@ void tcx_arith_decode_envelope_ivas_fx( } hTcxCfg = st->hTcxCfg; - hTcxDec = st->hTcxDec; *signaling_bits = 0; move16(); - assert( hTcxDec->enableTcxLpc ); + assert( st->hTcxDec->enableTcxLpc ); gamma_w = MAX16B; move16(); gamma_uw = st->inv_gamma; move16(); +#ifdef HARMONIZE_2598_tcx_arith_decode_envelope + IF( EQ_16( st->element_mode, EVS_MONO ) ) + { + tcx_arith_render_envelope( A_ind, L_frame, L_spec, hTcxCfg->preemph_fac, gamma_w, gamma_uw, env ); + } + ELSE + { +#endif + tcx_arith_render_envelope_ivas_fx( A_ind, L_frame, L_spec, hTcxCfg->preemph_fac, gamma_w, gamma_uw, env ); +#ifdef HARMONIZE_2598_tcx_arith_decode_envelope + } +#endif - tcx_arith_render_envelope_ivas_fx( A_ind, L_frame, L_spec, hTcxCfg->preemph_fac, gamma_w, gamma_uw, env ); IF( use_hm != 0 ) { @@ -395,8 +427,18 @@ void tcx_arith_decode_envelope_ivas_fx( envelope = (Word16 *) env; tcx_arith_scale_envelope( L_spec, L_spec_core, env, target_bits, low_complexity, envelope, &envelope_e ); - - *arith_bits = tcx_arith_decode_ivas_fx( L_spec, envelope, envelope_e, target_bits, prm, q_spectrum, q_spectrum_e ); +#ifdef HARMONIZE_2598_tcx_arith_decode_envelope + IF( EQ_16( st->element_mode, EVS_MONO ) ) + { + *arith_bits = tcx_arith_decode_fx( L_spec, envelope, envelope_e, target_bits, prm, q_spectrum, q_spectrum_e, nf_seed ); + } + ELSE + { +#endif + *arith_bits = tcx_arith_decode_ivas_fx( L_spec, envelope, envelope_e, target_bits, prm, q_spectrum, q_spectrum_e ); +#ifdef HARMONIZE_2598_tcx_arith_decode_envelope + } +#endif move16(); /* safety check in case of bit errors */ diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index 0d91397fb9215c553f77c558c3f3f4b6e2c2f0f4..0fb432b8be08dfc30e5fa046decf5b60cadf6b55 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -356,6 +356,24 @@ void decoder_tcx_fx( move16(); } +#ifdef HARMONIZE_2598_tcx_arith_decode_envelope + tcx_arith_decode_envelope_fx( + st, + x, &x_e, + L_frame, + L_spec, + Aind, + *prm_target, + prm_sqQ, + tmp8, + prm_hm, /* HM parameter area */ + hTcxDec->tcx_hm_LtpPitchLag, + &arith_bits, + &signaling_bits, + &nf_seed, + shr( st->bwidth, 1 ) /* equivalent to: (st->bwidth > WB)?1:0 */ + ); +#else tcx_arith_decode_envelope_fx( x, &x_e, L_frame, @@ -372,6 +390,7 @@ void decoder_tcx_fx( &nf_seed, shr( st->bwidth, 1 ) /* equivalent to: (st->bwidth > WB)?1:0 */ ); +#endif hTcxDec->resQBits[frame_cnt] = sub( *prm_target, arith_bits ); move16(); @@ -4389,11 +4408,19 @@ void decoder_tcx_invQ_fx( IF( GT_32( st->bwidth, WB ) ) { +#ifdef HARMONIZE_2598_tcx_arith_decode_envelope + tcx_arith_decode_envelope_fx( st, x, x_e, L_frame, L_spec, Aind, *prm_target, prm_sqQ, (Word16) NE_16( st->last_core_from_bs, ACELP_CORE ), prm_hm, /* HM parameter area */ hTcxDec->tcx_hm_LtpPitchLag, &arith_bits, &signaling_bits, 0, 1 ); +#else tcx_arith_decode_envelope_ivas_fx( st, x, x_e, L_frame, L_spec, Aind, *prm_target, prm_sqQ, (Word16) NE_16( st->last_core_from_bs, ACELP_CORE ), prm_hm, /* HM parameter area */ hTcxDec->tcx_hm_LtpPitchLag, &arith_bits, &signaling_bits, 1 ); +#endif } ELSE { +#ifdef HARMONIZE_2598_tcx_arith_decode_envelope + tcx_arith_decode_envelope_fx( st, x, x_e, L_frame, L_spec, Aind, *prm_target, prm_sqQ, (Word16) NE_16( st->last_core_from_bs, ACELP_CORE ), prm_hm, /* HM parameter area */ hTcxDec->tcx_hm_LtpPitchLag, &arith_bits, &signaling_bits, 0, 0 ); +#else tcx_arith_decode_envelope_ivas_fx( st, x, x_e, L_frame, L_spec, Aind, *prm_target, prm_sqQ, (Word16) NE_16( st->last_core_from_bs, ACELP_CORE ), prm_hm, /* HM parameter area */ hTcxDec->tcx_hm_LtpPitchLag, &arith_bits, &signaling_bits, 0 ); +#endif } hTcxDec->resQBits[frame_cnt] = sub( *prm_target, arith_bits ); diff --git a/lib_enc/arith_coder_enc_fx.c b/lib_enc/arith_coder_enc_fx.c index f61345df5357e75348588bf5bee13af7acab290b..1469136ecfa340b87ab5551b854a98f12e17a2c6 100644 --- a/lib_enc/arith_coder_enc_fx.c +++ b/lib_enc/arith_coder_enc_fx.c @@ -658,7 +658,7 @@ static Word16 tcx_arith_encode( * * *-------------------------------------------------------------------*/ - +#ifndef HARMONIZE_2598_tcx_arith_encode_envelope void tcx_arith_encode_envelope_fx( Word32 spectrum[], /* i/o: MDCT coefficients Q31-e */ Word16 *spectrum_e, /* i/o: MDCT exponent Q0 */ @@ -800,8 +800,28 @@ void tcx_arith_encode_envelope_fx( return; } +#endif - +#ifdef HARMONIZE_2598_tcx_arith_encode_envelope +void tcx_arith_encode_envelope_fx( + Word32 spectrum[], /* i/o: MDCT coefficients Q31-e */ + Word16 *spectrum_e, /* i/o: MDCT exponent Q0 */ + Word16 signs[], /* o : signs (spectrum[.]<0) Q0 */ + const Word16 L_frame, /* i : frame or MDCT length Q0 */ + const Word16 L_spec, /* i : frame or MDCT length Q0 */ + Encoder_State *st, /* i/o: coder state */ + const Word16 A_ind[], /* i : quantised LPC coefficients Q12 */ + Word16 target_bits, /* i : number of available bits Q0 */ + Word16 prm[], /* o : bitstream parameters Q0 */ + const Word8 use_hm, /* i : use HM in current frame? */ + Word16 prm_hm[], /* o : HM parameter area Q0 */ + const Word16 tcxltp_pitch, /* i : TCX LTP pitch in FD, -1 if n/a Q0*/ + Word16 *arith_bits, /* o : bits used for ari. coding Q0 */ + Word16 *signaling_bits, /* o : bits used for signaling Q0 */ + Word16 *nf_seed, /* o : noise filling seed; might be NULL Q0 */ + const Word16 low_complexity /* i : low-complexity flag Q0 */ +) +#else void tcx_arith_encode_envelope_ivas_fx( Word32 spectrum[], /* i/o: MDCT coefficients Q31-e */ Word16 *spectrum_e, /* i/o: MDCT exponent Q0 */ @@ -819,6 +839,7 @@ void tcx_arith_encode_envelope_ivas_fx( Word16 *signaling_bits, /* o : bits used for signaling Q0 */ const Word16 low_complexity /* i : low-complexity flag Q0 */ ) +#endif { Word32 env[N_MAX_ARI]; /* unscaled envelope (Q16) */ Word16 *envelope; /* scaled envelope (Q15-e) */ @@ -834,6 +855,9 @@ void tcx_arith_encode_envelope_ivas_fx( Word16 gamma_w, gamma_uw; Word16 hm_bits; Word32 L_tmp; +#ifdef HARMONIZE_2598_tcx_arith_encode_envelope + Word64 W_tmp2; +#endif Word16 tmp; TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc; @@ -919,12 +943,26 @@ void tcx_arith_encode_envelope_ivas_fx( move16(); /* Multiply back the signs */ +#ifdef HARMONIZE_2598_tcx_arith_encode_envelope + W_tmp2 = 0; + move32(); +#endif FOR( k = 0; k <= kMax; k++ ) { +#ifdef HARMONIZE_2598_tcx_arith_encode_envelope + if ( nf_seed != NULL ) + { + W_tmp2 = W_mac_16_16( W_tmp2, q_spectrum[k], k ); + } +#endif if ( signs[k] != 0 ) + { L_tmp = L_mult( q_spectrum[k], -( 1 << ( 30 - SPEC_EXP_DEC ) ) ); + } if ( signs[k] == 0 ) + { L_tmp = L_mult( q_spectrum[k], 1 << ( 30 - SPEC_EXP_DEC ) ); + } spectrum[k] = L_tmp; move32(); } @@ -933,5 +971,14 @@ void tcx_arith_encode_envelope_ivas_fx( move16(); set32_fx( spectrum + k, 0, sub( s_max( L_frame, L_spec ), k ) ); +#ifdef HARMONIZE_2598_tcx_arith_encode_envelope + if ( nf_seed != NULL ) + { + /* noise filling seed */ + *nf_seed = extract_l( W_extract_l( W_tmp2 ) ); + move16(); + } +#endif + return; } diff --git a/lib_enc/cod_tcx_fx.c b/lib_enc/cod_tcx_fx.c index dd98be924c55fdb55460ef75e64db86f10699800..4769d574795418843e5312dc5ed40a89617ba9c3 100644 --- a/lib_enc/cod_tcx_fx.c +++ b/lib_enc/cod_tcx_fx.c @@ -3504,8 +3504,11 @@ void QuantizeTCXSpectrum_fx( low_complexiety = 1; move16(); } +#ifdef HARMONIZE_2598_tcx_arith_encode_envelope + tcx_arith_encode_envelope_fx( spectrum_fx, spectrum_e, hm_cfg->indexBuffer, L_frame, L_spec, st, Aqind, sqTargetBits, sqQ, tmp8, prm_hm, /* HM parameter area */ LtpPitchLag, &sqBits, &signaling_bits, NULL, low_complexiety ); +#else tcx_arith_encode_envelope_ivas_fx( spectrum_fx, spectrum_e, hm_cfg->indexBuffer, L_frame, L_spec, st, Aqind, sqTargetBits, sqQ, tmp8, prm_hm, /* HM parameter area */ LtpPitchLag, &sqBits, &signaling_bits, low_complexiety ); - +#endif sqTargetBits = sub( sqTargetBits, signaling_bits ); *prm_target = sqTargetBits; move16(); diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 43661151f93784bd5269a6b21e2a9596ca9959cb..9e5ffe732f0f4e85dc3ada309ca0b89f69351569 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -1891,6 +1891,7 @@ Word16 ACcontextMapping_encode2_estimate_no_mem_s17_LC_fx( Word16 *stop, /* Q0 */ CONTEXT_HM_CONFIG *hm_cfg ); +#ifndef HARMONIZE_2598_tcx_arith_encode_envelope void tcx_arith_encode_envelope_fx( Word32 spectrum[], /* i/o: MDCT coefficients Q31-e */ Word16 *spectrum_e, /* i/o: MDCT exponent Q0 */ @@ -1909,7 +1910,28 @@ void tcx_arith_encode_envelope_fx( Word16 *nf_seed, /* o : noise filling seed Q0 */ const Word16 low_complexity /* i : low-complexity flag Q0 */ ); +#endif +#ifdef HARMONIZE_2598_tcx_arith_encode_envelope +void tcx_arith_encode_envelope_fx( + Word32 spectrum[], /* i/o: MDCT coefficients Q31-e */ + Word16 *spectrum_e, /* i/o: MDCT exponent Q0 */ + Word16 signs[], /* o : signs (spectrum[.]<0) Q0 */ + const Word16 L_frame, /* i : frame or MDCT length Q0 */ + const Word16 L_spec, /* i : frame or MDCT length Q0 */ + Encoder_State *st, /* i/o: coder state */ + const Word16 A_ind[], /* i : quantised LPC coefficients Q12 */ + Word16 target_bits, /* i : number of available bits Q0 */ + Word16 prm[], /* o : bitstream parameters Q0 */ + const Word8 use_hm, /* i : use HM in current frame? */ + Word16 prm_hm[], /* o : HM parameter area Q0 */ + const Word16 tcxltp_pitch, /* i : TCX LTP pitch in FD, -1 if n/a Q0*/ + Word16 *arith_bits, /* o : bits used for ari. coding Q0 */ + Word16 *signaling_bits, /* o : bits used for signaling Q0 */ + Word16 *nf_seed, /* o : noise filling seed, may be NULL Q0 */ + const Word16 low_complexity /* i : low-complexity flag Q0 */ +); +#else void tcx_arith_encode_envelope_ivas_fx( Word32 spectrum[], /* i/o: MDCT coefficients Q31-e */ Word16 *spectrum_e, /* i/o: MDCT exponent Q0 */ @@ -1927,6 +1949,7 @@ void tcx_arith_encode_envelope_ivas_fx( Word16 *signaling_bits, /* o : bits used for signaling Q0 */ const Word16 low_complexity /* i : low-complexity flag Q0 */ ); +#endif void QuantizeGain( Word16 n,