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 f329d1343cc306433b5257dc77936fb54712d20c..04683897b638a659e657677edc164b57163ad6ee 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -5298,12 +5298,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 8fce6a1925593b3b10fe42174de39b4d070309ff..6a96ae31e49935456190755d40f828250c8a17c2 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -90,6 +90,8 @@ #define FIX_BASOP_2650_DEC_PRM_TCX /* FhG: Simplify calculation of st->bits_frame_core in dec_prm_tcx(), align function name to float */ #define FIX_2648_IVAS_ISM_DEC_DIGEST_TC /* FhG: improvements on ivas_ism_dec_digest_tc_fx() */ #define BE_FIX_BASOP_2543_MISMATCH_REND_OPEN_FX_FL /* FhG: Aligns implementation of split rendering init loops in IVAS_REND_Open between float and BASOP */ +#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 */ /* #################### End BE switches ################################## */ diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 9d1272b61d2c14f09550de2d81e48b7049c0981e..a72ac5dd46235aeacc23c297b81ed23127819ec6 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -9211,10 +9211,12 @@ void getTCXWindowing_ivas_fx( Decoder_State *st0 /* i : bitstream */ ); +#ifndef FIX_2402_REPL_EVS_ARI_CODEC_DEC Word16 ari_start_decoding_14bits_prm_ivas_fx( const Word16 *ptr, Word16 bp, Tastat *s ); +#endif void generate_masking_noise_ivas_fx( Word32 *timeDomainBuffer, /* i/o: time-domain signal */ @@ -9390,6 +9392,7 @@ void hq_generic_hf_encoding_fx( Word16 *hq_generic_exc_clas, /* o : bwe excitation class */ Word16 length ); +#ifndef FIX_2402_REPL_EVS_ARI_CODEC_DEC Word16 ari_decode_14bits_pow_ivas( Word16 *ptr, Word16 bp, @@ -9397,13 +9400,16 @@ Word16 ari_decode_14bits_pow_ivas( Word16 *res, Tastat *s, UWord16 base ); +#endif +#ifndef FIX_2402_REPL_EVS_ARI_CODEC_DEC Word16 ari_decode_14bits_sign_ivas( Word16 *ptr, Word16 bp, Word16 bits, Word16 *res, Tastat *s ); +#endif ivas_error config_acelp1_fx( const Word16 enc_dec, /* i : encoder/decoder flag */ diff --git a/lib_dec/ari_dec_fx.c b/lib_dec/ari_dec_fx.c index 683e9d2534520528813286b766242c9318233de1..140ddbc777907d6649c180dd6f05af6e373bdc6e 100644 --- a/lib_dec/ari_dec_fx.c +++ b/lib_dec/ari_dec_fx.c @@ -48,6 +48,7 @@ void ari_start_decoding_14bits_fx( move32(); } +#ifndef FIX_2402_REPL_EVS_ARI_CODEC_DEC Word16 ari_start_decoding_14bits_prm_fx( const Word16 *ptr, /* Q0 */ Word16 bp, @@ -58,19 +59,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; @@ -78,6 +89,7 @@ Word16 ari_start_decoding_14bits_prm_fx( return add( bp, i ); } +#endif static Word16 ari_lookup_s17_fx( Word32 cum, @@ -277,6 +289,7 @@ Word16 ari_decode_14bits_bit_ext_fx( Decoder_State *st, Tastat *s ) return ari_decode_14bits_ext_fx( st, s, cum_freq, ari_lookup_bit_fx ); } +#ifndef FIX_2402_REPL_EVS_ARI_CODEC_DEC static Word16 ari_lookup_pow_fx( Tastat *s, Word16 base ) { Word32 cum, range; @@ -474,15 +487,26 @@ Word16 ari_decode_14bits_sign_fx( Word16 *ptr, Word16 bp, Word16 bits, Word16 *r { return ari_decode_14bits_notbl_fx( ptr, bp, bits, res, s, 0, ari_lookup_sign_fx ); } +#endif +#ifndef FIX_2402_REPL_EVS_ARI_CODEC_DEC /*--------------------------------------------------------------- - * ari_start_decoding_14bits_ivas() + * ari_start_decoding_14bits() * * Start ArCo decoding *-------------------------------------------------------------*/ Word16 ari_start_decoding_14bits_prm_ivas_fx( +#else +/*--------------------------------------------------------------- + * ari_start_decoding_14bits_prm() + * + * Start ArCo decoding + *-------------------------------------------------------------*/ + +Word16 ari_start_decoding_14bits_prm_fx( +#endif const Word16 *ptr, Word16 bp, Tastat *s ) @@ -509,7 +533,25 @@ Word16 ari_start_decoding_14bits_prm_ivas_fx( return add( bp, i ); } - +#ifdef FIX_2402_REPL_EVS_ARI_CODEC_DEC +/*------------------------------------------------------------------------ + * Function: ari_decode_14bits_pow_fx + * + * Decode a symbol which follows the exponential distribution. That is, + * symbols are in the following intervals + * + * p(x = 0) = 1 - exp(- 0.5 * base * 2) + * p(x = q>0) = exp(- (q-0.5)*base* 2) - exp(- (q+0.5)*base*2 ) + * + *-------------------------------------------------------------------------*/ +Word16 ari_decode_14bits_pow_fx( + Word16 *ptr, + Word16 bp, + Word16 bits, + Word16 *res, + Tastat *s, + Word16 base ) +#else Word16 ari_decode_14bits_pow_ivas( Word16 *ptr, Word16 bp, @@ -517,6 +559,7 @@ Word16 ari_decode_14bits_pow_ivas( Word16 *res, Tastat *s, UWord16 base ) +#endif { UWord16 symbol; Word32 low, high; @@ -662,7 +705,16 @@ Word16 ari_decode_14bits_pow_ivas( return bp; } +#ifdef FIX_2402_REPL_EVS_ARI_CODEC_DEC +/*------------------------------------------------------------------------ + * Function: ari_decode_14bits_sign_fx + * + * Decode a sign with equal probabilities. + *-------------------------------------------------------------------------*/ +Word16 ari_decode_14bits_sign_fx( +#else Word16 ari_decode_14bits_sign_ivas( +#endif Word16 *ptr, Word16 bp, Word16 bits, diff --git a/lib_dec/arith_coder_dec_fx.c b/lib_dec/arith_coder_dec_fx.c index 26bd9680b9bf5884b5a7a958f03ee543f5d44fa7..e82e80a13a13dbdca36f228d5d5a0aa3cf1ef824 100644 --- a/lib_dec/arith_coder_dec_fx.c +++ b/lib_dec/arith_coder_dec_fx.c @@ -57,7 +57,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_fx( 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 ); @@ -112,10 +117,18 @@ static Word16 tcx_arith_decode_ivas_fx( Word16 bp, k, q; Word16 s; Tastat as; +#ifdef FIX_2402_REPL_EVS_ARI_CODEC_DEC + Word16 exp_k; +#else UWord16 exp_k; +#endif Word16 tmp; +#ifdef FIX_2402_REPL_EVS_ARI_CODEC_DEC + bp = ari_start_decoding_14bits_prm_fx( prm, 0, &as ); +#else bp = ari_start_decoding_14bits_prm_ivas_fx( prm, 0, &as ); +#endif tmp = sub( envelope_e, 1 ); @@ -132,12 +145,20 @@ static Word16 tcx_arith_decode_ivas_fx( } /* decode line magnitude */ +#ifdef FIX_2402_REPL_EVS_ARI_CODEC_DEC + bp = ari_decode_14bits_pow_fx( prm, bp, target_bits, &q, &as, exp_k ); +#else bp = ari_decode_14bits_pow_ivas( prm, bp, target_bits, &q, &as, exp_k ); +#endif IF( q ) { /* line is non-zero, decode sign */ +#ifdef FIX_2402_REPL_EVS_ARI_CODEC_DEC + bp = ari_decode_14bits_sign_fx( prm, bp, target_bits, &s, &as ); +#else bp = ari_decode_14bits_sign_ivas( prm, bp, target_bits, &s, &as ); +#endif q_spectrum[k] = L_mult( q, sub( 3, shl( s, 1 ) ) ); move32(); q_spectrum[k] = L_shl( q_spectrum[k], 30 - SPEC_EXP_DEC ); // Q(31-20)