diff --git a/lib_com/ivas_arith_fx.c b/lib_com/ivas_arith_fx.c index aa261f69daab8bf32323b2299d212927b82d3afb..c9eba0ec32c43a49ef973c9d1f6c527e93b911d5 100644 --- a/lib_com/ivas_arith_fx.c +++ b/lib_com/ivas_arith_fx.c @@ -102,6 +102,7 @@ static UWord16 ivas_ari_get_symbol( * *-------------------------------------------------------------*/ +#ifndef FIX_2402_SIGNED_VERSION UWord16 ivas_ari_decode_14bits_bit_ext_1_lfe( Decoder_State *st, Tastat *s, @@ -180,6 +181,87 @@ UWord16 ivas_ari_decode_14bits_bit_ext_1_lfe( return symbol; } +#else /* FIX_2402_SIGNED_VERSION */ +Word16 ivas_ari_decode_14bits_bit_ext_1_lfe( + Decoder_State *st, + Tastat *s, + const UWord16 *cum_freq, + Word16 *extra_bits_read ) +{ + Word16 symbol; + Word32 low, high, range, value; + Word32 cum; + + /* read s->low,high,value sequentially */ + low = s->low; + high = s->high; + value = s->value; + + move32(); + move32(); + move32(); + + range = L_add( L_sub( high, low ), 1 ); + cum = L_sub( L_lshl( ( L_add( L_sub( value, low ), 1 ) ), stat_bitsnew ), 1 ); + + symbol = ivas_ari_get_symbol( cum_freq, range, cum ); + + high = L_sub( L_add( low, mul_sbc_14bits( range, cum_freq[symbol] ) ), 1 ); + low = L_add( low, mul_sbc_14bits( range, cum_freq[symbol + 1] ) ); + + FOR( ;; ) + { + IF( GE_32( high, ari_q2new ) ) + { + IF( GE_32( low, ari_q2new ) ) + { + value = L_sub( value, ari_q2new ); + low = L_sub( low, ari_q2new ); + high = L_sub( high, ari_q2new ); + } + ELSE + { + test(); + IF( GE_32( low, ari_q1new ) && LT_32( high, ari_q3new ) ) + { + value = L_sub( value, ari_q1new ); + low = L_sub( low, ari_q1new ); + high = L_sub( high, ari_q1new ); + } + ELSE + { + BREAK; + } + } + } + + low = L_add( low, low ); + high = L_add( high, UL_addNsD( high, 1 ) ); + + IF( GE_16( st->next_bit_pos, st->bits_frame ) ) + { + value = L_lshl( value, 1 ); + *extra_bits_read = add( *extra_bits_read, 1 ); + move16(); + } + ELSE + { + value = L_or( L_lshl( value, 1 ), get_next_indice_1_fx( st ) ); + } + } + + s->low = low; + s->high = high; + s->value = value; + + move32(); + move32(); + move32(); + + return symbol; +} + +#endif /* FIX_2402_SIGNED_VERSION */ /*--------------------------------------------------------------- * Function ivas_ari_done_decoding_14bits_ext_1_lfe() diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index 910e872b250668f076aec21662bc638695d523ce..ee15a9897d0fdce95a65519bc0b5298e8ad5b347 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -5332,12 +5332,21 @@ void ivas_ari_start_decoding_14bits_ext_1_lfe( Word16 *extra_bits_read ); +#ifndef FIX_2402_SIGNED_VERSION UWord16 ivas_ari_decode_14bits_bit_ext_1_lfe( Decoder_State *st, Tastat *s, const UWord16 *cum_freq, Word16 *extra_bits_read ); +#else +Word16 ivas_ari_decode_14bits_bit_ext_1_lfe( + Decoder_State *st, + Tastat *s, + const UWord16 *cum_freq, + Word16 *extra_bits_read +); +#endif void ivas_ari_done_decoding_14bits_ext_1_lfe( Decoder_State *st, diff --git a/lib_com/options.h b/lib_com/options.h index 9ce33d497451049e7dbee57598e3a596b0c93473..924f6d6b37b30a0b2258fc4b8ad7eed2ef756d47 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -94,6 +94,9 @@ #define FIX_FLOAT_1539_G192_FORMAT_SWITCH /* VA/Nokia: reintroduce format switching for g192 bitstreams */ #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_INLINE_FCT_ARI_CODEC /* FhG: basop issue 2402: simplify processing in arithmetic decoding, inline mul_sbc_14bits, all BE */ +#define FIX_2402_REPL_EVS_ARI_CODEC_DEC /* FhG: basop issue 2402: replace EVS arith decoder with IVAS arith decoder, except functions in igf_scf_dec_fx.c */ +#define FIX_2402_SIGNED_VERSION /* FhG: basop issue 2402: use signed operator instead of unsigned, better match for hardware */ #define FIX_2402_REPL_EVS_ARI_CODEC_ENC /* FhG: basop issue 2402: replace EVS arith encoder with IVAS arith encoder */ #define FIX_BASOP_2551_HARM_SCALAR_QUAN /* FhG: issue 2551: Harmonize function pair tcx_scalar_quantization_fx*/ #define HARMONIZE_2564_GetEnergyCldfb /* FhG: harmonize GetEnergyCldfb derivates for evs/ivas */ diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 7d541d076f4dd6b8b77823483077bf91514954b8..ebcf72afe2174cde480162f463c73475cd864899 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -7508,6 +7508,9 @@ void IGFSCFDecoderDecode( Word32 ari_decode_overflow_fx( Tastat *s ); +Word32 ari_decode_overflow_ivas_fx( + Tastat *s ); + void ari_start_decoding_14bits_fx( Decoder_State *st, Tastat *s ); diff --git a/lib_dec/ACcontextMapping_dec_fx.c b/lib_dec/ACcontextMapping_dec_fx.c index a483972ff03667aecefb49b507754601b6314db9..5b11b86028c3ed9df0c6951c92b2a90ab99c6b4f 100644 --- a/lib_dec/ACcontextMapping_dec_fx.c +++ b/lib_dec/ACcontextMapping_dec_fx.c @@ -13,6 +13,9 @@ #include "ivas_prot_fx.h" #include "ivas_rom_com.h" +#ifdef FIX_2402_REPL_EVS_ARI_CODEC_DEC +#include "ivas_prot_fx.h" +#endif /*-------------------------------------------------------------------* * ACcontextMapping_decode2_no_mem_s17_LC() @@ -133,7 +136,12 @@ Word16 ACcontextMapping_decode2_no_mem_s17_LC( } /* Start Decoding */ +#ifdef FIX_2402_REPL_EVS_ARI_CODEC_DEC + Word16 extra_bits_read = 0; + ivas_ari_start_decoding_14bits_ext_1_lfe( st, &as, &extra_bits_read ); +#else ari_start_decoding_14bits_fx( st, &as ); +#endif overflow_bit_pos = st->next_bit_pos; move16(); @@ -182,8 +190,11 @@ Word16 ACcontextMapping_decode2_no_mem_s17_LC( assert( tmp >= 0 && tmp < 4096 ); pki = ari_lookup_s17_LC[tmp]; move16(); +#ifdef FIX_2402_REPL_EVS_ARI_CODEC_DEC + r = ivas_ari_decode_14bits_bit_ext_1_lfe( st, &as, ari_pk_s17_LC_ext[pki], &extra_bits_read ); +#else r = ari_decode_14bits_s17_ext_fx( st, &as, ari_pk_s17_LC_ext[pki] ); - +#endif IF( LT_16( r, VAL_ESC ) ) { BREAK; @@ -280,8 +291,13 @@ Word16 ACcontextMapping_decode2_no_mem_s17_LC( } } +#ifdef FIX_2402_REPL_EVS_ARI_CODEC_DEC + ivas_ari_done_decoding_14bits_ext_1_lfe( st, extra_bits_read ); +#endif /* Total number of decoded AC bits */ +#ifndef FIX_2402_REPL_EVS_ARI_CODEC_DEC get_next_indice_tmp_fx( st, -( cbitsnew - 2 ) ); +#endif /*detect overflow*/ IF( NE_16( k, lastnz ) ) diff --git a/lib_dec/ari_dec_fx.c b/lib_dec/ari_dec_fx.c index 99d33cc5992403f56c750c58acec1cabc395018a..68b8b79d423044f3e6aafe82a5b40b68ddbd20ad 100644 --- a/lib_dec/ari_dec_fx.c +++ b/lib_dec/ari_dec_fx.c @@ -25,13 +25,16 @@ static Word32 L_msui_32_16( Word32 cum, Word32 range, Word16 cum_freq ) Word32 ari_decode_overflow_fx( Tastat *s ) { -#ifdef FIX_2402_SIMPLIFY_ARI_CODEC - return ( L_sub( s->high, s->low ) <= 0 ); -#else return ( L_sub( L_sub( s->high, 1 ), s->low ) <= 0 ); -#endif } +#ifdef FIX_2402_REPL_EVS_ARI_CODEC_DEC +Word32 ari_decode_overflow_ivas_fx( Tastat *s ) +{ + return ( L_sub( s->high, s->low ) <= 0 ); +} +#endif + /** * \brief Start ArCo decoding * @@ -64,19 +67,29 @@ Word16 ari_start_decoding_14bits_prm_fx( const Word16 *p; val = L_deposit_l( 0 ); +#ifdef FIX_2402_REPL_EVS_ARI_CODEC_DEC + s->low = val; + move32(); +#endif p = ptr + bp; /* Q0 */ FOR( i = 0; i < cbitsnew; i++ ) { val = L_shl( val, 1 ); +#ifdef FIX_2402_REPL_EVS_ARI_CODEC_DEC + if ( *( p + i ) != 0 ) +#else IF( *( p + i ) ) +#endif { val = L_add( val, 1 ); } } +#ifndef FIX_2402_REPL_EVS_ARI_CODEC_DEC s->low = L_deposit_l( 0 ); move32(); +#endif s->high = L_add( ari_q4new, 1 ); move32(); s->value = val; @@ -85,6 +98,7 @@ Word16 ari_start_decoding_14bits_prm_fx( return add( bp, i ); } +#ifndef FIX_2402_REPL_EVS_ARI_CODEC_DEC static Word16 ari_lookup_s17_fx( Word32 cum, Word32 range, @@ -172,6 +186,7 @@ static Word16 ari_lookup_s17_fx( L_shr( 0, 0 ); /* pointer subtraction */ return extract_l( p - cum_freq ); } +#endif /* FIX_2402_REPL_EVS_ARI_CODEC_DEC */ static Word16 ari_lookup_s27_fx( Word32 cum, @@ -416,10 +431,12 @@ static Word16 ari_decode_14bits_ext_fx( /** * \brief Only for 17 symbols with new extended Tables */ +#ifndef FIX_2402_REPL_EVS_ARI_CODEC_DEC Word16 ari_decode_14bits_s17_ext_fx( Decoder_State *st, Tastat *s, UWord16 const *cum_freq ) { return ari_decode_14bits_ext_fx( st, s, cum_freq, ari_lookup_s17_fx ); } +#endif /* FIX_2402_REPL_EVS_ARI_CODEC_DEC */ /** * \brief Only for 27 symbols with new extended Tables @@ -656,7 +673,11 @@ Word16 ari_decode_14bits_pow_fx( Word16 *ptr, Word16 bp, Word16 bits, Word16 *re *-------------------------------------------------------------------------*/ Word16 ari_decode_14bits_sign_fx( Word16 *ptr, Word16 bp, Word16 bits, Word16 *res, Tastat *s ) { +#ifdef FIX_2402_REPL_EVS_ARI_CODEC_DEC + return ari_decode_14bits_sign_ivas( ptr, bp, bits, res, s ); +#else return ari_decode_14bits_notbl_fx( ptr, bp, bits, res, s, 0, ari_lookup_sign_fx ); +#endif } /*--------------------------------------------------------------- diff --git a/lib_dec/arith_coder_dec_fx.c b/lib_dec/arith_coder_dec_fx.c index 3ac4963c0e31df182d139bf30e31e674e24d990c..b7d2636ac1a55907dbafe8697043534a18835385 100644 --- a/lib_dec/arith_coder_dec_fx.c +++ b/lib_dec/arith_coder_dec_fx.c @@ -31,7 +31,11 @@ static Word16 tcx_arith_decode_fx( Word64 W_tmp; move32(); +#ifdef FIX_2402_REPL_EVS_ARI_CODEC_DEC + bp = ari_start_decoding_14bits_prm_ivas_fx( prm, 0, &as ); +#else bp = ari_start_decoding_14bits_prm_fx( prm, 0, &as ); +#endif /* FIX_2402_REPL_EVS_ARI_CODEC_DEC */ tmp = sub( envelope_e, 1 + 15 ); W_tmp = 0; @@ -48,7 +52,11 @@ static Word16 tcx_arith_decode_fx( exp_k = round_fx( expfp( envelope[k], tmp ) ); } /* decode line magnitude */ +#ifdef FIX_2402_REPL_EVS_ARI_CODEC_DEC + bp = ari_decode_14bits_pow_ivas( prm, bp, target_bits, &q, &as, exp_k ); +#else bp = ari_decode_14bits_pow_fx( prm, bp, target_bits, &q, &as, exp_k ); +#endif /* FIX_2402_REPL_EVS_ARI_CODEC_DEC */ IF( q == 0 ) { @@ -57,7 +65,12 @@ static Word16 tcx_arith_decode_fx( } IF( q != 0 ) /* line is non-zero, decode sign */ { +#ifdef FIX_2402_REPL_EVS_ARI_CODEC_DEC + bp = ari_decode_14bits_sign_ivas( prm, bp, target_bits, &s, &as ); + s = sub( s, 1 ); /* ivas returns 1 or 2, evs expects 0 or 1 */ +#else bp = ari_decode_14bits_sign_fx( prm, bp, target_bits, &s, &as ); +#endif /* FIX_2402_REPL_EVS_ARI_CODEC_DEC */ W_tmp = W_mac_16_16( W_tmp, q, k ); @@ -68,7 +81,11 @@ static Word16 tcx_arith_decode_fx( move32(); } +#ifdef FIX_2402_REPL_EVS_ARI_CODEC_DEC + IF( ari_decode_overflow_ivas_fx( &as ) ) +#else IF( ari_decode_overflow_fx( &as ) ) +#endif /* FIX_2402_REPL_EVS_ARI_CODEC_DEC */ { if ( LT_16( bp, target_bits ) ) /* safety check in case of bit errors */ {