diff --git a/Workspace_msvc/Workspace_msvc.sln b/Workspace_msvc/Workspace_msvc.sln index c9c1f0fde7302be2a5d9c0785a12d133320c85e5..c9546fe1c165124c4beca39a5d3faff846e9436c 100644 --- a/Workspace_msvc/Workspace_msvc.sln +++ b/Workspace_msvc/Workspace_msvc.sln @@ -1,6 +1,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.28307.902 +# Visual Studio Version 18 +VisualStudioVersion = 18.1.11304.174 MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "lib_dec", "lib_dec.vcxproj", "{E822DDAF-0F5F-4CD0-A694-38AE69DE74D3}" EndProject diff --git a/Workspace_msvc/lib_rend.vcxproj.filters b/Workspace_msvc/lib_rend.vcxproj.filters index dfa1253eb5681d99f0a489d33757f1365762af8f..050b97e3d04e9f575e018bdb487f355e1294b883 100644 --- a/Workspace_msvc/lib_rend.vcxproj.filters +++ b/Workspace_msvc/lib_rend.vcxproj.filters @@ -122,6 +122,7 @@ rend_c + diff --git a/lib_com/ari_fx.c b/lib_com/ari_fx.c index 70fe3d3d03776de94bcb2afab7c345bf88599439..32bb550b28a310bcad2612ce1ad93a32ac29d961 100644 --- a/lib_com/ari_fx.c +++ b/lib_com/ari_fx.c @@ -8,6 +8,8 @@ #include "prot_fx.h" #include "cnst.h" + +#ifndef FIX_2402_SIMPLIFY_ARI_CODEC /** * \brief 31x16 Bit multiply (x*y) * @@ -26,6 +28,7 @@ Word32 L_multi31x16_X2( Word16 xh, Word16 xl, Word16 y ) return z; } +#endif /*--------------------------------------------------------------- Ari 14 bits common routines @@ -39,6 +42,9 @@ Word32 L_multi31x16_X2( Word16 xh, Word16 xl, Word16 y ) * * \return r*c */ +#ifndef FIX_2402_INLINE_FCT_ARI_CODEC +/* Note: moved to proto_fx.h */ + Word32 mul_sbc_14bits( Word32 r, /* Q0 */ Word16 c /* Q0 */ @@ -57,3 +63,4 @@ Word32 mul_sbc_14bits( return ( ret ); } +#endif diff --git a/lib_com/options.h b/lib_com/options.h index b921da1421f18e3ce50b2a554e50a0d4326b9709..7f0efae0c78b308cc111eaa0e312385cd2f6c9e8 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -83,6 +83,33 @@ #define FIX_1990_SANITIZER_IN_REVERB_LOAD /* Nokia: Fix issue part of issue 1990 by introducing missing free of structure - keep until #2059 is addressed */ #define TMP_1342_WORKAROUND_DEC_FLUSH_BROKEN_IN_SR /* FhG: Temporary workaround for incorrect implementation of decoder flush with split rendering */ #define NONBE_1122_KEEP_EVS_MODE_UNCHANGED /* FhG: Disables fix for issue 1122 in EVS mode to keep BE tests green. This switch should be removed once the 1122 fix is added to EVS via a CR. */ +#define FIX_2255_ISAR_RENDER_POSES /* VA: issue 2255: fix missing check in isar_render_poses() */ +#define FIX_1904_HARM_GSC_ENC /* VA: #1904 Harmonization of EVS and IVAS GSC code */ +#define FIX_1478_UNINIT_ON_BFI /* VA: Fix issue 1478 where a vector is partly un-initialized during bfi */ +#define FIX_BASOP_2358_SCALING_OOB /* Eri: Basip issue 2358: Clang-18 reports OOB access where scaling is applied to L_FRAME48k instead of output_frame */ +#define FIX_BASOP_2350_HARM_0B_BWE_2 /* VA: basop issue 2350: Simplify calling of hf_synth_fx() */ +#define FIX_2364_HARM_MULT_HARM /* VA: basop issue 2364 : harmonizing multi_harm_fx function */ +#define FIX_2363_FIND_WSP /* VA: basop issue 2363 : harmonizing find_wsp function */ +#define FIX_2370_UNUSED_BUFFERS_CORE_ENC /* VA: basop issue 2370: remove temporary input buffers in core-encoder */ +#define FIX_2376_FIX_USAN_PRE_PROC /* VA: basop issue 2376: Resolve "USAN: SEGV in ivas_compute_core_buffers_fx() */ +#define FIX_2367_REMOVE_CODE_ICBWE /* VA: basop issue 2367: Remove IC-BWE obsolete code */ +#define REMOVE_SCALING_SHB_SPEECH /* VA: remove unnecessary scaling and 32-bit buffers from ivas_core_enc_fx() */ +#define FIX_2352_COPY_AQ_IN_TCX /* FhG: basop issue 2352: prevent copying uninitialized values from Aq_fx[][] to Aq_fx_32[][] in TCX */ +#define FIX_2353_PTR_INIT /* FhG: basop issue 2353: initialize prm_sqQ-pointer, to prevent being uninitialized in case of bfi == 1 */ +#define FIX_2356_GET_CHAN_ENERGIES /* FhG: basop issue 2356: correctly initialize exponents in getChannelEnergies_fx() */ +#define FIX_2355_IGF_EXP_POWERSPEC /* FhG: basop issue 2355: make sure exp_pPowerSpectrumParameter_fx is initialized in all cases */ +#define FIX_2319_CLDFB_INIT_FLAGS /* FhG: basop issue 2319: init hs->flags during openCldfb(), to avoid reading of uninitialized memory */ +#define FIX_BASOP_2357_OBJECT_EDIT_MSAN /* Nokia: basop issue 2357: initialize missing exponents in object edit */ +#define FIX_BASOP_2354_MSAN_DIFF_Q_VALUE /* Nokia: Initialize Q value of diffuseness in rendering to Q30 */ +#define FIX_2371_REMOVE_UNUSED_ISAR_FCNS /* Dolby: basop issue 2371: remove unused ISAR-related functions */ +#define FIX_2384_INIT_DEQUANT_COV /* FhG: basop issue 2384: only read initialized values from Cy_buf_e[k] in ivas_param_mc_dequantize_cov_fx() during renormalization */ +#define FIX_2383_INIT_Q_A_ITF /* FhG: Initialize Q_A_itf, to avoid reading of uninitialized memory in case ITF is not triggered */ +#define FIX_2382_COPY_AQ_IN_MCT /* FhG: basop issue 2382: 2nd instance of prevent copying uninitialized values from Aq_fx[][] to Aq_fx_32[][] in TCX */ +#define FIX_2391_INIT_HQ_GENERIC_OFFSET /* FhG/Eri: basop issue 2391: make sure hq_generic_offset is initialized inside hq_hr_dec_fx() */ +#define FIX_2402_SIMPLIFY_ARI_CODEC /* FhG: basop issue 2402: simplify processing in arithmetic decoding, symbol table lookup, all BE */ +#define FIX_2402_INLINE_FCT_ARI_CODEC /* FhG: basop issue 2402: simplify processing in arithmetic decoding, inline mul_sbc_14bits, all BE */ +#define FIX_2397_COPY_AQ_MDCT_CORE_BFI /* FhG: prevent copying of uninit memory in MDCT stereo core if bfi is set */ +#define HARMONIZE_TBE /* VA: harmonize core-coder TBE function duplications */ #define FIX_2235_TD_RENDERER_WORD16 /* Eri: Use Word16 in TD renderer without converting to Word32*/ #define HARMONIZE_TBE2 /* VA: basop issue 2399: Remove duplicated code: TBE, step 2 */ #define HARMONIZE_2427_GETPLC /* FhG: basop issue : 2427 Harmonizing getPLCDecision functions:*/ diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index c75e0831246af5b7316ed8ee7af48948807c43bd..0c870bf855d9009432337191cc84c995a2f68d8c 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -5439,15 +5439,51 @@ Word16 IGFCommonFuncsIGFGetCFTables_fx( const Word16 **cf_off_se11 /* o : offsets for CF tables above */ ); +#ifndef FIX_2402_SIMPLIFY_ARI_CODEC Word32 L_multi31x16_X2( Word16 xh, Word16 xl, Word16 y ); +#endif +#ifndef FIX_2402_INLINE_FCT_ARI_CODEC Word32 mul_sbc_14bits( Word32 r, /* Q0 */ Word16 c /* Q0 */ ); +#else +/** + * \brief Integer Multiply + * + * \param[i] r + * \param[i] c + * + * \return r*c + */ +static inline Word32 mul_sbc_14bits( + Word32 r, /* Q0 */ + Word16 c /* Q0 */ +); +static inline Word32 mul_sbc_14bits( + Word32 r, /* Q0 */ + Word16 c /* Q0 */ +) +{ + /* Note: moved from ari_fx.c to allow inlining */ + + Word32 ret; + + /* + temp = (((int32) r)*((int32) c))>>stat_bitsnew; + */ + assert( stat_bitsnew == 14 ); + ret = Mpy_32_16_1( L_shl( r, 15 - stat_bitsnew ), c ); + + /*assert( (((int) r)*((int) c))>>stat_bitsnew == ret);*/ + + return ( ret ); +} +#endif void ham_cos_window( Word16 *fh, diff --git a/lib_dec/ari_dec_fx.c b/lib_dec/ari_dec_fx.c index c9912eba88aba8924e815edf22b4cdb5a65cd286..efbda91a472f8a37ac265376db8e3d2df030fbbd 100644 --- a/lib_dec/ari_dec_fx.c +++ b/lib_dec/ari_dec_fx.c @@ -12,10 +12,30 @@ /*--------------------------------------------------------------- * Ari decode 14 bits routines -------------------------------------------------------------*/ +// Please remove all DEBUG lines, when FIX_2402 is done!! +//#define DEBUG_ari_decode_14bits + +#ifdef FIX_2402_SIMPLIFY_ARI_CODEC +static Word32 L_msui_32_16( Word32 cum, Word32 range, Word16 cum_freq ) +{ + /* WMOPS counting is done using L_sub, similar to other MSU operations */ + /* Note: range*cum_freq do never exceed signed 32-bit, when multiplied */ + /* Note: No overflow or saturation feature required. */ + return L_sub( cum, range * cum_freq ); +} +#endif Word32 ari_decode_overflow_fx( Tastat *s ) { +#ifdef DEBUG_ari_decode_14bits + if ( s->high <= s->low ) + printf( "ari_decode_overflow detected: high=0x%08X low=0x%08X\n", s->high, s->low ); +#endif +#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 } /** @@ -38,6 +58,10 @@ void ari_start_decoding_14bits_fx( move32(); s->value = val; move32(); + +#ifdef DEBUG_ari_decode_14bits + // printf( "ari_start_decoding_14bits_fx: low=0x%08X high=0x%08X value=0x%08X\n", s->low, s->high, s->value ); +#endif } Word16 ari_start_decoding_14bits_prm_fx( @@ -68,6 +92,9 @@ Word16 ari_start_decoding_14bits_prm_fx( s->value = val; move32(); +#ifdef DEBUG_ari_decode_14bits + // printf( "ari_start_decoding_14bits_prm_fx: low=0x%08X high=0x%08X value=0x%08X i=%d\n", s->low, s->high, s->value, i ); +#endif return add( bp, i ); } @@ -77,9 +104,11 @@ static Word16 ari_lookup_s17_fx( UWord16 const *cum_freq /* Q0 */ ) { - Word32 tmp; const UWord16 *p; +#ifndef FIX_2402_SIMPLIFY_ARI_CODEC + Word32 tmp; Word16 range_l, range_h; +#endif p = cum_freq; @@ -88,6 +117,7 @@ static Word16 ari_lookup_s17_fx( /* tmp_p = p+8; if (tmp_p[0]*range>cum) p = tmp_p; */ /* max value in p[x] is 16384 => 14 bits */ +#ifndef FIX_2402_SIMPLIFY_ARI_CODEC range_l = extract_l( L_and( range, 0x7FFF ) ); range_h = extract_l( L_shr( range, 15 ) ); @@ -122,6 +152,33 @@ static Word16 ari_lookup_s17_fx( p = p + 1; } } +#else + if ( L_msui_32_16( cum, range, p[8] ) < 0 ) + { + p = p + 8; + move16(); + } + if ( L_msui_32_16( cum, range, p[4] ) < 0 ) + { + p = p + 4; + move16(); + } + if ( L_msui_32_16( cum, range, p[2] ) < 0 ) + { + p = p + 2; + move16(); + } + if ( L_msui_32_16( cum, range, p[1] ) < 0 ) + { + p = p + 1; + move16(); + IF( EQ_32( (Word32) ( &cum_freq[15] - p ), 0 ) && ( L_msui_32_16( cum, range, p[1] ) < 0 ) ) + { + p = p + 1; + move16(); + } + } +#endif /* return extract_l(L_shr(L_sub((Word32)p,(Word32)cum_freq),1)); */ L_sub( 0, 0 ); @@ -135,6 +192,7 @@ static Word16 ari_lookup_s27_fx( UWord16 const *cum_freq /* Q0 */ ) { +#ifndef FIX_2402_SIMPLIFY_ARI_CODEC Word32 tmp; Word16 range_l, range_h; Word16 il, ih, im; @@ -226,6 +284,41 @@ static Word16 ari_lookup_s27_fx( } return il; +#else + + const UWord16 *p = cum_freq; + + if ( L_msui_32_16( cum, range, p[11] ) < 0 ) + { + p = p + 11; + move16(); + } + if ( L_msui_32_16( cum, range, p[8] ) < 0 ) + { + p = p + 8; + move16(); + } + if ( L_msui_32_16( cum, range, p[4] ) < 0 ) + { + p = p + 4; + move16(); + } + if ( L_msui_32_16( cum, range, p[2] ) < 0 ) + { + p = p + 2; + move16(); + } + if ( L_msui_32_16( cum, range, p[1] ) < 0 ) + { + p = p + 1; + move16(); + } + + /* return extract_l(L_shr(L_sub((Word32)p,(Word32)cum_freq),1)); */ + L_sub( 0, 0 ); + L_shr( 0, 0 ); /* pointer subtraction */ + return extract_l( p - cum_freq ); +#endif } static Word16 ari_lookup_bit_fx( @@ -234,11 +327,12 @@ static Word16 ari_lookup_bit_fx( UWord16 const *cum_freq /* Q0 */ ) { - Word16 symbol = 0; /* initialize just to avoid compiler warning */ + Word16 symbol = 0; move16(); (void) cum_freq; +#ifndef FIX_2402_SIMPLIFY_ARI_CODEC range = L_shl( range, 13 ); /* L_multi31x16_X2(range_h, range_l, 8192) */ cum = L_sub( range, cum ); @@ -252,7 +346,12 @@ static Word16 ari_lookup_bit_fx( symbol = 0; move16(); } - +#else + if ( L_msui_32_16( cum, range, 8192 ) < 0 ) + { + symbol = add( symbol, 1 ); /* symbol = 1 */ + } +#endif return symbol; } @@ -280,17 +379,26 @@ static Word16 ari_decode_14bits_ext_fx( range = L_sub( high, low ); cum = L_add( L_shl( L_sub( value, low ), stat_bitsnew ), sub( shl( 1, stat_bitsnew ), 1 ) ); +#ifndef FIX_2402_SIMPLIFY_ARI_CODEC if ( cum < 0 ) { cum = 0x7fffffff; move32(); } +#else + assert( cum >= 0 ); +#endif symbol = lookup_fn( cum, range, cum_freq ); high = L_add( low, mul_sbc_14bits( range, cum_freq[symbol] ) ); low = L_add( low, mul_sbc_14bits( range, cum_freq[add( symbol, 1 )] ) ); +#ifdef DEBUG_ari_decode_14bits +// printf( "ari_decode_14bits_ext_fx(look=%s): low=0x%08X high=0x%08X value=0x%08X symbol=0x%04X range=0x%08X cum=0x%08X\n", ( lookup_fn == ari_lookup_bit_fx ) ? "bit" : ( lookup_fn == ari_lookup_s17_fx ) ? "s17" : "s27", +// low, high, value, symbol, range, cum ); +#endif + FOR( i = 0; i < 0x7FFF; i++ ) { Word32 L_msb_diff, L_msb_low, L_msb_high; @@ -310,6 +418,10 @@ static Word16 ari_decode_14bits_ext_fx( high = L_shl( high, 1 ); value = L_msu( value, 1, tab_ari_qnew[L_msb_high][L_msb_low] ); value = L_mac0( L_shl( value, 1 ), 1, get_next_indice_1_fx( st ) ); +#ifdef DEBUG_ari_decode_14bits + // printf( "=>low=0x%08X high=0x%08X value=0x%08X dh=%d dl=%d\n", + // low, high, value, L_msb_high, L_msb_low ); +#endif } s->low = low; @@ -349,14 +461,25 @@ Word16 ari_decode_14bits_bit_ext_fx( Decoder_State *st, Tastat *s ) move16(); move16(); move16(); +#ifdef DEBUG_ari_decode_14bits + Word16 bp = st->next_bit_pos; + UWord16 *ptr = st->bit_stream; + printf( "ari_decode_14bits_bit_ext(beg): high=0x%08X low=0x%08X value=0x%08X ptr[bp=%d] = %d | %d | %d | %d\n", s->high, s->low, s->value, bp, ptr[bp], ptr[bp + 1], ptr[bp + 2], ptr[bp + 3] ); + Word16 symbol = ari_decode_14bits_ext_fx( st, s, cum_freq, ari_lookup_bit_fx ); + printf( "ari_decode_14bits_bit_ext(end): high=0x%08X low=0x%08X value=0x%08X symbol=0x%04X bp=%d\n", s->high, s->low, s->value, symbol, st->next_bit_pos ); + return symbol; +#else return ari_decode_14bits_ext_fx( st, s, cum_freq, ari_lookup_bit_fx ); +#endif } static Word16 ari_lookup_pow_fx( Tastat *s, Word16 base ) { Word32 cum, range; Word16 symbol; +#ifndef FIX_2402_SIMPLIFY_ARI_CODEC Word16 range_h, range_l; +#endif Word16 pows[12]; /* "base" to the power of 2, 4, 8,... 2^12 */ Word16 lowlim, highlim, testval; Word16 k; @@ -364,8 +487,10 @@ static Word16 ari_lookup_pow_fx( Tastat *s, Word16 base ) range = L_sub( s->high, s->low ); cum = L_add( L_shl( L_sub( s->value, s->low ), stat_bitsnew ), ( ( 1 << stat_bitsnew ) - 1 ) ); +#ifndef FIX_2402_SIMPLIFY_ARI_CODEC range_h = extract_l( L_shr( range, 15 ) ); range_l = extract_l( L_and( range, 0x7FFF ) ); +#endif symbol = 0; move16(); @@ -374,7 +499,11 @@ static Word16 ari_lookup_pow_fx( Tastat *s, Word16 base ) move16(); /* search for the interval where "cum" fits */ - IF( GT_32( L_multi31x16_X2( range_h, range_l, lowlim ), cum ) ) /* below pow-1 */ +#ifdef FIX_2402_SIMPLIFY_ARI_CODEC + IF( L_msui_32_16( cum, range, lowlim ) < 0 ) /* below pow-1 */ +#else + IF( GT_32( L_multi31x16_X2( range_h, range_l, lowlim ), cum ) ) /* below pow-1 */ +#endif { pows[0] = base; move16(); @@ -389,7 +518,11 @@ static Word16 ari_lookup_pow_fx( Tastat *s, Word16 base ) move16(); testval = mult_r( pows[k], base ); +#ifdef FIX_2402_SIMPLIFY_ARI_CODEC + IF( L_msui_32_16( cum, range, shr( testval, 1 ) ) >= 0 ) +#else IF( LE_32( L_multi31x16_X2( range_h, range_l, shr( testval, 1 ) ), cum ) ) /* found! big range is [lowlim,testval], (now narrow it down) */ +#endif { lowlim = testval; move16(); @@ -405,7 +538,11 @@ static Word16 ari_lookup_pow_fx( Tastat *s, Word16 base ) { testval = mult_r( highlim, pows[k + 1] ); +#ifdef FIX_2402_SIMPLIFY_ARI_CODEC + IF( L_msui_32_16( cum, range, shr( testval, 1 ) ) >= 0 ) +#else IF( LE_32( L_multi31x16_X2( range_h, range_l, shr( testval, 1 ) ), cum ) ) +#endif { lowlim = testval; move16(); @@ -426,6 +563,9 @@ static Word16 ari_lookup_pow_fx( Tastat *s, Word16 base ) move32(); s->low = L_add( s->low, mul_sbc_14bits( range, lowlim ) ); move32(); +#ifdef DEBUG_ari_decode_14bits + printf( "ari_decode_14bits_pow_fx+mul_sbc_14bits: high: 0x%08X low: 0x%08X range: 0x%08X (lookup)\n", s->high, s->low, range ); +#endif return symbol; } @@ -439,6 +579,10 @@ static Word16 ari_lookup_sign_fx( Tastat *s, Word16 base ) range = L_sub( s->high, s->low ); cum = L_sub( s->value, s->low ); + +#ifdef DEBUG_ari_decode_14bits + printf( "sign-A: high: 0x%08X low: 0x%08X value: 0x%08X range: 0x%08X cum: 0x%08X\n", s->high, s->low, s->value, range, cum ); +#endif range = L_shr( range, 1 ); IF( GT_32( range, cum ) ) @@ -447,6 +591,10 @@ static Word16 ari_lookup_sign_fx( Tastat *s, Word16 base ) move16(); s->high = L_add( s->low, range ); move32(); +#ifdef DEBUG_ari_decode_14bits + printf( "sign-B1: high: 0x%08X low: 0x%08X value: 0x%08X range: 0x%08X cum: 0x%08X\n", s->high, s->low, s->value, range, cum ); + +#endif } ELSE { @@ -454,6 +602,9 @@ static Word16 ari_lookup_sign_fx( Tastat *s, Word16 base ) move16(); s->low = L_add( s->low, range ); move32(); +#ifdef DEBUG_ari_decode_14bits + printf( "sign-B2: high: 0x%08X low: 0x%08X value: 0x%08X range: 0x%08X cum: 0x%08X\n", s->high, s->low, s->value, range, cum ); +#endif } return symbol; @@ -477,6 +628,16 @@ static Word16 ari_decode_14bits_notbl_fx( high = L_add( s->high, 0 ); value = L_add( s->value, 0 ); +#ifdef DEBUG_ari_decode_14bits + // if (lookup_fn == ari_lookup_pow_fx) + // printf( "ari_decode_14bits_pow_fx+mul_sbc_14bits: high: 0x%08X low: 0x%08X\n", high, low ); +#endif +#ifdef DEBUG_ari_decode_14bits + // if ( lookup_fn == ari_lookup_pow_fx ) + // printf( "ari_decode_14bits_notbl_fx (pow): symbol=0x%04X high=0x%08X low=0x%08X value=0x%08X\n", + // symbol, high, low, value ); +#endif + FOR( ; bp < bits; ++bp ) { Word32 L_msb_diff, L_msb_low, L_msb_high; @@ -505,6 +666,9 @@ static Word16 ari_decode_14bits_notbl_fx( IF( ( lookup_fn != ari_lookup_sign_fx ) && !( NE_16( bp, bits ) || !( ( EQ_32( s->low, low ) ) && ( EQ_32( s->high, L_sub( high, 1 ) ) ) && ( EQ_32( s->value, value ) ) ) ) ) { /* This should not happen except of bit errors. */ +#ifdef DEBUG_ari_decode_14bits + printf( "ari_decode_14bits_notbl_fx: bit error detected high: 0x%08X low: 0x%08X value: 0x%08X bp: %d bits: %d\n", high, low, value, bp, bits ); +#endif s->high = 0; move32(); s->low = 0; @@ -523,6 +687,10 @@ static Word16 ari_decode_14bits_notbl_fx( *res = symbol; move16(); +#ifdef DEBUG_ari_decode_14bits + if ( lookup_fn == ari_lookup_sign_fx ) + printf( "sign-X: high: 0x%08X low: 0x%08X value: 0x%08X symbol: 0x%04X\n", high, low, value, *res ); +#endif return bp; } @@ -539,7 +707,28 @@ static Word16 ari_decode_14bits_notbl_fx( *-------------------------------------------------------------------------*/ Word16 ari_decode_14bits_pow_fx( Word16 *ptr, Word16 bp, Word16 bits, Word16 *res, Tastat *s, Word16 base ) { - return ari_decode_14bits_notbl_fx( ptr, bp, bits, res, s, base, ari_lookup_pow_fx ); + /* There are two versions to call: pow_ivas or pow_fx (default) */ +#if 0 +#ifdef DEBUG_ari_decode_14bits + printf( "ari_decode_14bits_pow_ivas(inp): high=0x%08X low=0x%08X value=0x%08X ptr[bp=%d] = %d | %d | %d | %d\n", + s->high, s->low, s->value, bp, ptr[bp], ptr[bp+1], ptr[bp+2], ptr[bp+3] ); +#endif + Word16 result = ari_decode_14bits_pow_ivas( ptr, bp, bits, res, s, base ); +#ifdef DEBUG_ari_decode_14bits + printf( "ari_decode_14bits_pow_ivas(end): high=0x%08X low=0x%08X value=0x%08X symbol=0x%04X bp=%d\n", s->high, s->low, s->value, *res, result ); +#endif + return result; +#else +#ifdef DEBUG_ari_decode_14bits + printf( "ari_decode_14bits_pow_fx(inp): high=0x%08X low=0x%08X value=0x%08X ptr[bp=%d] = %d | %d | %d | %d\n", + s->high, s->low, s->value, bp, ptr[bp], ptr[bp + 1], ptr[bp + 2], ptr[bp + 3] ); +#endif + Word16 result = ari_decode_14bits_notbl_fx( ptr, bp, bits, res, s, base, ari_lookup_pow_fx ); +#ifdef DEBUG_ari_decode_14bits + printf( "ari_decode_14bits_pow_fx(end): high=0x%08X low=0x%08X value=0x%08X symbol=0x%04X bp=%d\n", s->high, s->low, s->value, *res, result ); +#endif + return result; +#endif } /*------------------------------------------------------------------------ @@ -549,7 +738,15 @@ 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 ) { - return ari_decode_14bits_notbl_fx( ptr, bp, bits, res, s, 0, ari_lookup_sign_fx ); +#ifdef DEBUG_ari_decode_14bits + // printf( "ari_decode_14bits_sign_fx(inp): high=0x%08X low=0x%08X value=0x%08X ptr[bp=%d] = %d | %d | %d | %d\n", + // s->high, s->low, s->value, bp, ptr[bp], ptr[bp + 1], ptr[bp + 2], ptr[bp + 3] ); +#endif + Word16 result = ari_decode_14bits_notbl_fx( ptr, bp, bits, res, s, 0, ari_lookup_sign_fx ); +#ifdef DEBUG_ari_decode_14bits + // printf( "ari_decode_14bits_sign_fx(end): high=0x%08X low=0x%08X value=0x%08X symbol=0x%04X bp=%d\n", s->high, s->low, s->value, *res, result ); +#endif + return result; } /*--------------------------------------------------------------- @@ -622,6 +819,11 @@ Word16 ari_decode_14bits_pow_ivas( cum = (UWord32) W_add( W_shl( ( W_sub( value, low ) ), stat_bitsnew ), ( 1 << stat_bitsnew ) - 1 ); move32(); + +#ifdef DEBUG_ari_decode_14bits + // printf( "ari_decode_14bits_pow_ivas: low=0x%08X high=0x%08X value=0x%08X symbol=0x%04X range=0x%08X cum=0x%08X\n", low, high, value, symbol, range, cum ); +#endif + /* search for the interval where "cum" fits */ IF( GT_64( W_mult0_32_32( L_shr( base, 1 ), range ), cum ) ) /* below pow-1 */ { @@ -645,6 +847,9 @@ Word16 ari_decode_14bits_pow_ivas( BREAK; } } +#ifdef DEBUG_ari_decode_14bits + // printf( "ari_decode_14bits_pow_ivas (below-1): k=%d symbol=0x%04X pows[0]=0x%04X pows[%d]=0x%04X\n", k, symbol, pows[0], k-1, pows[k-1] ); +#endif assert( k < 12 ); /* maximum 2^10-1*/ /* narrow the range down */ FOR( k--; k > 0; k-- ) @@ -667,6 +872,9 @@ Word16 ari_decode_14bits_pow_ivas( } ELSE /* trivial case, above pow-1, that is, first symbol */ { +#ifdef DEBUG_ari_decode_14bits + // printf( "ari_decode_14bits_pow_ivas (above pow-1): symbol=0 base=0x%04X\n", base ); +#endif symbol = 0; lowlim = extract_l( L_shr( base, 1 ) ); highlim = 16384; @@ -679,6 +887,10 @@ Word16 ari_decode_14bits_pow_ivas( low = L_add( low, mul_sbc_14bits( range, lowlim ) ); +#ifdef DEBUG_ari_decode_14bits + printf( "ari_decode_14bits_pow_ivas+mul_sbc_14bits: high: 0x%08X low: 0x%08X range: 0x%08X\n", high, low, range ); +#endif + /*ptr init for ptr*/ FOR( ; bp < bits; ) { @@ -736,6 +948,9 @@ Word16 ari_decode_14bits_pow_ivas( *res = symbol; move16(); +#ifdef DEBUG_ari_decode_14bits + // printf( "ari_decode_14bits_pow_ivas(end): high=0x%08X low=0x%08X value=0x%08X symbol=0x%04X bp=%d\n", s->high, s->low, s->value, *res, bp ); +#endif return bp; } diff --git a/lib_enc/ACcontextMapping_enc_fx.c b/lib_enc/ACcontextMapping_enc_fx.c index f9e2d919c9bb8b47922c61e8e44df86a632b54e3..ae23439e4d7b84210b1f44dc717b891da7dad615 100644 --- a/lib_enc/ACcontextMapping_enc_fx.c +++ b/lib_enc/ACcontextMapping_enc_fx.c @@ -17,6 +17,16 @@ #define MAKE_NUMBER_QX( number, QX ) ( ( number ) << ( QX ) ) /* evaulated at compile time */ #define MAKE_VARIABLE_QX( variable, QX ) W_shl( W_deposit32_l( L_deposit_l( ( variable ) ) ), ( QX ) ) /* evaluated at run time */ + +#if 1 //VERSX +#include "issue2402_replacement.h" +#else +#define HIGH(p) ((p)+0) +#define BITS_TO_FOLLOW value +#endif + + + /*-------------------------------------------------------------------* * ACcontextMapping_encode2_no_mem_s17_LC_fx() * @@ -94,6 +104,9 @@ void ACcontextMapping_encode2_no_mem_s17_LC_fx( flag_overflow = 0; move16(); +#ifdef DEBUG_ARITH_IVAS_REPLACEMENT + printf("in ACcontextMapping_encode2_no_mem_s17_LC_fx()\n"); +#endif IF( hm_cfg ) /* mapped domain */ { numPeakIndicesOrig = hm_cfg->numPeakIndices; /* Q0 */ @@ -161,6 +174,9 @@ void ACcontextMapping_encode2_no_mem_s17_LC_fx( b1_i = get_next_coeff( ii, &p2, &idx2, hm_cfg ); /* Q0 */ idx = s_min( idx1, idx2 ); /* Q0 */ +#ifdef DEBUG_ARITH_IVAS_REPLACEMENT + printf("start loop: k,lastnz=%d,%d, a1_i,b1_i,idx= %d,%d,%d\n", k,lastnz, a1_i, b1_i, idx ); +#endif /* Get context */ ctx = &c[s_or( p1, p2 )]; /* Q0 */ @@ -190,6 +206,9 @@ void ACcontextMapping_encode2_no_mem_s17_LC_fx( /*Copy states*/ ari_copy_states_fx( &as, &as_overflow ); +#ifdef DEBUG_ARITH_IVAS_REPLACEMENT + printf("middle loop: k,lastnz=%d,%d, a1_i,b1_i,idx= %d,%d,%d\n", k,lastnz, a1_i, b1_i, idx ); +#endif bp_overflow = bp; /* Q0 */ move16(); nbbits_signs_overflow = nbbits_signs; /* Q0 */ @@ -220,6 +239,10 @@ void ACcontextMapping_encode2_no_mem_s17_LC_fx( move16(); bp = ari_encode_14bits_ext_fx( ptr, bp, &as, VAL_ESC, ari_pk_s17_LC_ext[pki] ); /* Q0 */ +#ifdef DEBUG_ARITH_IVAS_REPLACEMENT + printf("l,h,v= 0x%04x,0x%04x,0x%04x, bp=%03d, a1,b1=0x%04x,0x%04x\n", + as.low, HIGH(as.high), as.BITS_TO_FOLLOW, bp, a1,b1); +#endif *lsbs_bits2-- = s_and( a1, 1 ); move16(); *lsbs_bits2-- = s_and( b1, 1 ); @@ -241,7 +264,7 @@ void ACcontextMapping_encode2_no_mem_s17_LC_fx( bp = ari_encode_14bits_ext_fx( ptr, bp, &as, add( a1, shl( b1, A_THRES_SHIFT ) ), ari_pk_s17_LC_ext[pki] ); /* Q0 */ /* Check bit budget */ - IF( GT_16( add( add( add( bp, extract_l( as.value ) ), nbbits_signs ), nbbits_lsbs ), nbbits_m2 ) ) + IF( GT_16( add( add( add( bp, extract_l( as.BITS_TO_FOLLOW ) ), nbbits_signs ), nbbits_lsbs ), nbbits_m2 ) ) { ari_copy_states_fx( &as_overflow, &as ); bp = bp_overflow; /* Q0 */ @@ -271,7 +294,7 @@ void ACcontextMapping_encode2_no_mem_s17_LC_fx( move16(); bp = ari_encode_14bits_ext_fx( ptr, bp, &as, 0, ari_pk_s17_LC_ext[pki] ); /* Q0 */ - IF( GT_16( add( add( add( bp, extract_l( as.value ) ), nbbits_signs ), nbbits_lsbs ), nbbits_m2 ) ) + IF( GT_16( add( add( add( bp, extract_l( as.BITS_TO_FOLLOW ) ), nbbits_signs ), nbbits_lsbs ), nbbits_m2 ) ) { ari_copy_states_fx( &as_overflow, &as ); bp = bp_overflow; /* Q0 */ diff --git a/lib_enc/ari_enc_fx.c b/lib_enc/ari_enc_fx.c index afeba274c1fb78428c792b639b72ea04a68b87c2..3d5219299ce36f5667059c0611845c7e09c44b0c 100644 --- a/lib_enc/ari_enc_fx.c +++ b/lib_enc/ari_enc_fx.c @@ -11,6 +11,7 @@ #include "prot_fx_enc.h" /* Function prototypes */ + /*--------------------------------------------------------------- * ari_copy_states_fx() * @@ -20,6 +21,7 @@ * \return none *-------------------------------------------------------------*/ +#if 0 //VERSX void ari_copy_states_fx( TastatEnc *source, TastatEnc *dest ) @@ -33,6 +35,7 @@ void ari_copy_states_fx( return; } +#endif /*--------------------------------------------------------------- Ari encoder 14 bits routines @@ -47,6 +50,7 @@ void ari_copy_states_fx( * \return none *-------------------------------------------------------------*/ +#if 0 //VERSX void ari_start_encoding_14bits_fx( TastatEnc *s ) { @@ -58,7 +62,7 @@ void ari_start_encoding_14bits_fx( return; } - +#endif /*--------------------------------------------------------------- * Ari encoder 14 bits routines @@ -74,11 +78,17 @@ Word16 ari_put_bit_plus_follow( { assert( bit == 0 || bit == 1 ); ptr[bp++] = bit; /* send initially a zero or one Q0*/ +#ifdef DEBUG_ARITH_IVAS_REPLACEMENT + printf("ari_enc_fx.c:1: ptr[%d-1]=%d\n", bp, ptr[bp-1]); +#endif move16(); bit = s_xor( bit, 1 ); /* invert bit to send */ FOR( ; bits_to_follow > 0; bits_to_follow-- ) { ptr[bp++] = bit; /* send inverted bit Q0*/ +#ifdef DEBUG_ARITH_IVAS_REPLACEMENT + printf("ari_enc_fx.c:2: ptr[%d-1]=%d\n", bp, ptr[bp-1]); +#endif move16(); } @@ -96,6 +106,7 @@ Word16 ari_put_bit_plus_follow( * * \return bit consumption * ------------------------------------------------------------ - */ +#if 0 //VERSX Word16 ari_done_encoding_14bits_fx( Word16 *ptr, /* Q0 */ Word16 bp, /* Q0 */ @@ -111,7 +122,7 @@ Word16 ari_done_encoding_14bits_fx( } return ari_put_bit_plus_follow( ptr, bp, add( s->value, 1 ), bit ); } - +#endif /*--------------------------------------------------------------- *ari_encode_14bits_ext_fx() @@ -127,7 +138,7 @@ Word16 ari_done_encoding_14bits_fx( * * \return bit consumption * ------------------------------------------------------------ - */ - +#if 0 //VERSX Word16 ari_encode_14bits_ext_fx( Word16 *ptr, /* Q0 */ Word16 bp, /* Q0 */ @@ -203,10 +214,12 @@ Word16 ari_encode_14bits_ext_fx( move32(); s->value = bits_to_follow; /* Q0 */ move16(); - +#ifdef DEBUG_ARITH_IVAS_REPLACEMENT + printf("ari_encode_14bits_ext_fx(), bp=%d, symbol=%d\n", bp, symbol ); +#endif return bp; } - +#endif /*------------------------------------------------------------------------ * Function: ari_encode_overflow_fx() @@ -214,11 +227,13 @@ Word16 ari_encode_14bits_ext_fx( * *-------------------------------------------------------------------------*/ +#if 0 //VERSX Word16 ari_encode_overflow_fx( TastatEnc *s ) { return L_sub( L_sub( s->high, 1 ), s->low ) <= 0; } +#endif /*------------------------------------------------------------------------ * Function: ari_encode_14bits_high_low() @@ -226,6 +241,7 @@ Word16 ari_encode_overflow_fx( * *-------------------------------------------------------------------------*/ +#if 0 //VERSX static Word16 ari_encode_14bits_high_low( Word16 *ptr, /* Q0 */ Word16 bp, /* Q0 */ @@ -240,6 +256,10 @@ static Word16 ari_encode_14bits_high_low( bits_to_follow = s->value; move16(); +#ifdef DEBUG_ARITH_IVAS_REPLACEMENT + printf("high_low1: s->low,high,btfo=0x%04x,0x%04x,0x%04x high,low=0x%04x,0x%04x bp=%d\n", + s->low, s->high-1, s->value, high,low,bp ); +#endif /* while there are more than 16 bits left */ tmp = sub( 16, bits ); /* Q0 */ WHILE( add( add( bp, bits_to_follow ), tmp ) < 0 ) @@ -276,6 +296,10 @@ static Word16 ari_encode_14bits_high_low( } low = L_add( low, low ); /* Q0 */ +#ifdef DEBUG_ARITH_IVAS_REPLACEMENT + printf("high_low2: high=0x%04x, s->btfo=%d\n", + high, s->value); +#endif high = L_add( high, high ); /* Scale up code range. Q0*/ } @@ -288,6 +312,7 @@ static Word16 ari_encode_14bits_high_low( return bp; } +#endif /*------------------------------------------------------------------------ @@ -296,6 +321,7 @@ static Word16 ari_encode_14bits_high_low( * Encode an cumulative frequency interval. *-------------------------------------------------------------------------*/ +#if 0 //VERSX Word16 ari_encode_14bits_range_fx( Word16 *ptr, /* Q0 */ Word16 bp, /* Q0 */ @@ -311,9 +337,17 @@ Word16 ari_encode_14bits_range_fx( high = L_add( s->low, mul_sbc_14bits( range, cum_freq_high ) ); /* Q0 */ low = L_add( s->low, mul_sbc_14bits( range, cum_freq_low ) ); /* Q0 */ - - return ari_encode_14bits_high_low( ptr, bp, bits, s, high, low ); +#ifdef DEBUG_ARITH_IVAS_REPLACEMENT + printf("range, s->low,high=0x%04x,0x%04x range=0x%04x low,high=0x%04x,0x%04x\n", + s->low, s->high, range, low, high ); +#endif + Word16 ret=ari_encode_14bits_high_low( ptr, bp, bits, s, high, low ); +#ifdef DEBUG_ARITH_IVAS_REPLACEMENT + printf("range end ret=%d, s->low,high,value=x%04x,0x%04x,x%04x\n", ret, s->low,s->high,s->value); +#endif + return ret; } +#endif /*------------------------------------------------------------------------ @@ -322,6 +356,7 @@ Word16 ari_encode_14bits_range_fx( * Encode a sign with equal probabilities. *-------------------------------------------------------------------------*/ +#if 0 //VERSX Word16 ari_encode_14bits_sign_fx( Word16 *ptr, /* Q0 */ Word16 bp, /* Q0 */ @@ -336,7 +371,9 @@ Word16 ari_encode_14bits_sign_fx( high = L_add( s->high, 0 ); low = L_add( s->low, 0 ); range = L_sub( high, low ); /* Q0 */ - +#ifdef DEBUG_ARITH_IVAS_REPLACEMENT + printf("sign low,high=0x%04x,0x%04x range=0x%04x\n", low, high,range); +#endif L_tmp = L_shr( range, 1 ); if ( sign != 0 ) { @@ -347,8 +384,10 @@ Word16 ari_encode_14bits_sign_fx( low = L_add( low, L_tmp ); /* Q0 */ } - return ari_encode_14bits_high_low( ptr, bp, bits, s, high, low ); + Word16 ret = ari_encode_14bits_high_low( ptr, bp, bits, s, high, low ); + return ret; } +#endif /*------------------------------------------------------------------------ @@ -357,6 +396,7 @@ Word16 ari_encode_14bits_sign_fx( * Finish up encoding in CBR mode. *-------------------------------------------------------------------------*/ +#if 0 //VERSX Word16 ari_done_cbr_encoding_14bits_fx( Word16 *ptr, /* Q0 */ Word16 bp, /* Q0 */ @@ -364,11 +404,22 @@ Word16 ari_done_cbr_encoding_14bits_fx( TastatEnc *s ) { Word16 high, tmp, k; - +#ifdef DEBUG_ARITH_IVAS_REPLACEMENT +Word16 bp0=bp; +#endif tmp = sub( bits, 16 ); /* Q0 */ WHILE( GT_16( sub( tmp, bp ), s->value ) ) { +#ifdef DEBUG_ARITH_IVAS_REPLACEMENT + printf("%s:%d: before ari_encode_14bits_sign_fx() bp=%d, bits=%d, s=0x%04x,0x%04x,0x%04x\n", + __FILE__,__LINE__, + bp, bits, s->low,s->high,s->value); +#endif bp = ari_encode_14bits_sign_fx( ptr, bp, bits, s, 0 ); /* Q0 */ +#ifdef DEBUG_ARITH_IVAS_REPLACEMENT + printf("after ari_encode_14bits_sign_fx() bp=%d, bits=%d, s=0x%04x,0x%04x,0x%04x\n", + bp, bits, s->low,s->high,s->value); +#endif } high = extract_l( L_sub( s->high, 1 ) ); /* Q0 */ @@ -377,15 +428,23 @@ Word16 ari_done_cbr_encoding_14bits_fx( high = lshl( high, 1 ); tmp = s_min( 15, sub( bits, bp ) ); +#ifdef DEBUG_ARITH_IVAS_REPLACEMENT + printf("ari_enc_fx.c:3: bp0=%d bp=%d, bits=%d,s=0x%04x,0x%04x,0x%04x, high=%d,tmp=%d,\n", + bp0, bp, s->low,s->high,s->BIT_TO_FOLLOW, high, tmp); +#endif FOR( k = 0; k < tmp; ++k ) { ptr[bp++] = lshr( high, 15 ); /* Q0 */ +#ifdef DEBUG_ARITH_IVAS_REPLACEMENT + printf("ari_enc_fx.c:4: ptr[%d-1]=%d\n", bp, ptr[bp-1]); +#endif move16(); high = lshl( high, 1 ); } return bp; } +#endif void ari_start_encoding_14bits_ivas_fx( @@ -507,7 +566,9 @@ Word16 ari_encode_14bits_ext_ivas_fx( move32(); s->bits_to_follow = bits_to_follow; /* Q0 */ move32(); - +#ifdef DEBUG_ARITH_IVAS_REPLACEMENT + printf("ari_encode_14bits_ext_fx(), bp=%d, symbol=%d\n", bp, symbol ); +#endif return bp; } @@ -517,6 +578,7 @@ Word16 ari_encode_14bits_ext_ivas_fx( * *-------------------------------------------------------------------------*/ +#ifndef FUNCTION_ari_encode_14bits_high_low_ivas_fx static Word16 ari_encode_14bits_high_low_ivas_fx( Word16 *ptr, /* Q0 */ Word16 bp, /* Q0 */ @@ -528,8 +590,13 @@ static Word16 ari_encode_14bits_high_low_ivas_fx( { Word16 bits_to_follow, tmp; + //high--; bits_to_follow = extract_l( s->bits_to_follow ); /* Q0 */ move16(); +#ifdef DEBUG_ARITH_IVAS_REPLACEMENT + printf("high_low1: s->low,high,btfo=0x%04x,0x%04x,0x%04x high,low=0x%04x,0x%04x bp=%d\n", + s->low, s->high, s->bits_to_follow, high,low,bp ); +#endif /* while there are more than 16 bits left */ tmp = sub( 16, bits ); /* Q0 */ @@ -567,11 +634,16 @@ static Word16 ari_encode_14bits_high_low_ivas_fx( } low = L_add( low, low ); +#ifdef DEBUG_ARITH_IVAS_REPLACEMENT + printf("high_low2: high=0x%04x, s->btfo=%d\n", + high, s->bits_to_follow); +#endif high = L_add( high, high ); /* Scale up code range. */ } s->low = low; /* Q0 */ move32(); + //high++; s->high = L_sub( high, 1 ); /* Q0 */ move32(); s->bits_to_follow = bits_to_follow; /* Q0 */ @@ -579,7 +651,7 @@ static Word16 ari_encode_14bits_high_low_ivas_fx( return bp; } - +#endif /*------------------------------------------------------------------------ * Function: ari_encode_14bits_sign_ivas_fx() @@ -601,6 +673,9 @@ Word16 ari_encode_14bits_sign_ivas_fx( high = L_add( s->high, 1 ); low = L_add( s->low, 0 ); range = L_sub( high, low ); /* Q0 */ +#ifdef DEBUG_ARITH_IVAS_REPLACEMENT + printf("sign low,high=0x%04x,0x%04x range=0x%04x\n", low, high,range); +#endif L_tmp = L_shr( range, 1 ); if ( sign != 0 ) @@ -612,5 +687,6 @@ Word16 ari_encode_14bits_sign_ivas_fx( low = L_add( low, L_tmp ); /* Q0 */ } - return ari_encode_14bits_high_low_ivas_fx( ptr, bp, extract_l( bits ), s, high, low ); + Word16 ret = ari_encode_14bits_high_low_ivas_fx( ptr, bp, extract_l( bits ), s, high, low ); + return ret; } diff --git a/lib_enc/arith_coder_enc_fx.c b/lib_enc/arith_coder_enc_fx.c index 17183543e6127e744ed5b895a098bf22294babdc..9acfc7a274fcde57550ec021ba05c7d4968b9cbb 100644 --- a/lib_enc/arith_coder_enc_fx.c +++ b/lib_enc/arith_coder_enc_fx.c @@ -11,6 +11,14 @@ #include "basop_util.h" #include "rom_com.h" +#if 1 //VERSX +#include "issue2402_replacement.h" +#else +#define HIGH(p) (p) +#define BITS_TO_FOLLOW value +#endif + + /*-------------------------------------------------------------------* * Local constants @@ -551,6 +559,7 @@ static Word16 tcx_arith_encode( IF( q_abs_spectrum[k] == 0 ) { assert( exps[k] >= 2 ); + //printf("%s:%d: before ari_encode_14bits_range_fx()\n", __FILE__,__LINE__); bp = ari_encode_14bits_range_fx( prm, bp, target_bits, &as, shr( exps[k], 1 ), 16384 ); } ELSE /* q_abs_spectrum[k] != 0 */ @@ -564,7 +573,9 @@ static Word16 tcx_arith_encode( powfp_odd2( exps[k], q_abs_spectrum[k], &tmpi1, &tmpi2 ); } + //printf("%s:%d: before ari_encode_14bits_range_fx()\n", __FILE__,__LINE__); bp = ari_encode_14bits_range_fx( prm, bp, target_bits, &as, shr( tmpi2, 1 ), shr( tmpi1, 1 ) ); + //printf("%s:%d: before ari_encode_14bits_sign_fx()\n", __FILE__,__LINE__); bp = ari_encode_14bits_sign_fx( prm, bp, target_bits, &as, signs[k] ); } @@ -587,7 +598,9 @@ static Word16 tcx_arith_encode( /* Retry encoding */ powfp_odd2( exps[k], q_abs_spectrum[k], &tmpi1, &tmpi2 ); + //printf("%s:%d: before ari_encode_14bits_range_fx()\n", __FILE__,__LINE__); bp = ari_encode_14bits_range_fx( prm, bp, target_bits, &as, shr( tmpi2, 1 ), shr( tmpi1, 1 ) ); + //printf("%s:%d: before ari_encode_14bits_sign_fx()\n", __FILE__,__LINE__); bp = ari_encode_14bits_sign_fx( prm, bp, target_bits, &as, signs[k] ); IF( !ari_encode_overflow_fx( &as ) ) /* Success */ @@ -625,6 +638,7 @@ static Word16 tcx_arith_encode( { assert( exps[k] >= 1 ); + //printf("%s:%d: before ari_encode_14bits_range_fx()\n", __FILE__,__LINE__); bp = ari_encode_14bits_range_fx( prm, bp, target_bits, &as, shr( exps[k], 1 ), 16384 ); /* Check bit budget status */ IF( ari_encode_overflow_fx( &as ) ) /* no bits left */ @@ -646,10 +660,20 @@ static Word16 tcx_arith_encode( IF( EQ_16( kEncoded, sub( L_frame, 1 ) ) ) /* RESQ bits possibly available */ { /* Limit target bits to actually needed bits */ - target_bits = add( add( bp, 16 ), extract_l( as.value ) ); + target_bits = add( add( bp, 16 ), extract_l( as.BITS_TO_FOLLOW ) ); } - return ari_done_cbr_encoding_14bits_fx( prm, bp, target_bits, &as ); +#ifdef DEBUG_ARITH_IVAS_REPLACEMENT + printf("%s:%d: before ari_done_cbr_encoding_14bits_fx()i bp=%d target_bits=%d as=0x%04x,0x%04x,0x%04x\n", + __FILE__,__LINE__, + bp, target_bits, as.low,HIGH(as.high),as.BITS_TO_FOLLOW ); +#endif + Word16 ret = ari_done_cbr_encoding_14bits_fx( prm, bp, target_bits, &as ); +#if 0 + printf("after ari_done_cbr_encoding_14bits_fx() ret=%d, as=0x%04x,0x%04x,0x%04x\n", + ret, as.low,HIGH(as.high),as.BITS_TO_FOLLOW); +#endif + return ret; } @@ -774,6 +798,7 @@ void tcx_arith_encode_envelope_fx( } /* Final encoding */ + //printf("%s:%d: before tcx_arith_encode()\n", __FILE__,__LINE__); *arith_bits = tcx_arith_encode( q_spectrum, signs, kMax, L_spec, exponents, target_bits, prm ); move16(); @@ -915,6 +940,7 @@ void tcx_arith_encode_envelope_ivas_fx( } /* Final encoding */ + //printf("%s:%d: before tcx_arith_encode()\n", __FILE__,__LINE__); *arith_bits = tcx_arith_encode( q_spectrum, signs, kMax, L_spec, exponents, target_bits, prm ); move16(); diff --git a/lib_enc/igf_scf_enc_fx.c b/lib_enc/igf_scf_enc_fx.c index eab151d7eee9402996a00938f1026583efa5c115..cd40f2762f0e7162663aa6485f9ac0ad81dc2c7b 100644 --- a/lib_enc/igf_scf_enc_fx.c +++ b/lib_enc/igf_scf_enc_fx.c @@ -13,6 +13,11 @@ #include "prot_fx_enc.h" /* Function prototypes */ +#if 1 //VERSX +#include "issue2402_replacement.h" +#endif + + /**********************************************************************/ /** initialization of an instance of this module **************************************************************************/ diff --git a/lib_enc/issue2402_replacement.h b/lib_enc/issue2402_replacement.h new file mode 100644 index 0000000000000000000000000000000000000000..83fdc4bdf8675617bb2874e76f1e9c24188a83a4 --- /dev/null +++ b/lib_enc/issue2402_replacement.h @@ -0,0 +1,259 @@ + +//#define DEBUG_ARITH_IVAS_REPLACEMENT +#define ari_start_encoding_14bits_fx(p) ari_start_encoding_14bits_ivas_fx(p) +#define ari_done_encoding_14bits_fx(p1, p2, p3) ari_done_encoding_14bits_ivas_fx(p1, p2, p3) +#define TastatEnc Tastat +#define ari_copy_states_fx(s,d) ari_copy_states_ivas_fx(s,d) +#define ari_encode_14bits_ext_fx( ptr, bp, as, p1, p2 ) ari_encode_14bits_ext_ivas_fx( ptr, bp, as, p1, p2 ) +#define ari_done_cbr_encoding_14bits_fx ari_done_cbr_encoding_14bits_ivas_fx +#define ari_encode_overflow_fx ari_encode_overflow_ivas_fx +#define ari_encode_14bits_sign_fx( ptr, bp, bits, s, sign ) ari_encode_14bits_sign_ivas_fx( ptr, bp, bits, s, sign ) +#define ari_encode_14bits_range_fx ari_encode_14bits_range_ivas_fx +#define ari_encode_14bits_high_low ari_encode_14bits_high_low_ivas_fx +//#define TastatEnc Tastat +#define acState_fx acState_ivas_fx +#define HIGH(p) ((p)+1) +#define BITS_TO_FOLLOW bits_to_follow + +/*--------------------------------------------------------------- + * ari_copy_states_ivas_fx() + * + * \param[i] source + * \param[o] dest + * + * \return none + *-------------------------------------------------------------*/ +static void ari_copy_states_ivas_fx( + Tastat *source, + Tastat *dest ) +{ + dest->low = source->low; + move32(); + dest->high = source->high; + move32(); + dest->value = source->value; + move16(); + dest->bits_to_follow = source->bits_to_follow; + move16(); + + return; +} + +static Word16 ari_done_cbr_encoding_14bits_ivas_fx( + Word16 *ptr, /* Q0 */ + Word16 bp, /* Q0 */ + Word16 bits, /* Q0 */ + Tastat *s ) +{ + Word16 high, tmp, k; +#ifdef DEBUG_ARITH_IVAS_REPLACEMENT +Word16 bp0=bp; +#endif + tmp = sub( bits, 16 ); /* Q0 */ + WHILE( GT_16( sub( tmp, bp ), s->bits_to_follow ) ) + { +#ifdef DEBUG_ARITH_IVAS_REPLACEMENT + printf("%s:%d: before ari_encode_14bits_sign_fx() bp=%d, bits=%d, s=0x%04x,0x%04x,0x%04x\n", + __FILE__,__LINE__, + bp, bits, s->low,s->high,s->bits_to_follow); +#endif + bp = ari_encode_14bits_sign_ivas_fx( ptr, bp, bits, s, 0 ); /* Q0 */ +#ifdef DEBUG_ARITH_IVAS_REPLACEMENT + printf("after ari_encode_14bits_sign_fx() bp=%d, bits=%d, s=0x%04x,0x%04x,0x%04x\n", + bp, bits, s->low,s->high,s->value); +#endif + } + + high = extract_l( L_sub( s->high, 0 ) ); /* Q0 */ + + bp = ari_put_bit_plus_follow( ptr, bp, s->bits_to_follow, lshr( high, 15 ) ); /* Q0 */ + high = lshl( high, 1 ); + + tmp = s_min( 15, sub( bits, bp ) ); +#ifdef DEBUG_ARITH_IVAS_REPLACEMENT + printf("ari_enc_fx.c:3: bp0=%d bp=%d, bits=%d,s=0x%04x,0x%04x,0x%04x, high=%d,tmp=%d,\n", + bp0, bp, s->low,s->high,s->BITS_TO_FOLLOW, high, tmp); +#endif + FOR( k = 0; k < tmp; ++k ) + { + ptr[bp++] = lshr( high, 15 ); /* Q0 */ +#ifdef DEBUG_ARITH_IVAS_REPLACEMENT + printf("ari_enc_fx.c:4: ptr[%d-1]=%d\n", bp, ptr[bp-1]); +#endif + move16(); + high = lshl( high, 1 ); + } + + return bp; +} + +static Word16 ari_encode_overflow_ivas_fx( + Tastat *s ) +{ + return L_sub( L_sub( s->high, 0 ), s->low ) <= 0; +} + +#if 0 +static Word16 ari_encode_14bits_high_low_ivas( + Word16 *ptr, /* Q0 */ + Word16 bp, /* Q0 */ + Word16 bits, /* Q0 */ + Tastat *s, + Word32 high, /* Q0 */ + Word32 low /* Q0 */ +) +{ + Word16 bits_to_follow, tmp; + + bits_to_follow = s->bits_to_follow; + move16(); + + /* while there are more than 16 bits left */ + tmp = sub( 16, bits ); /* Q0 */ + WHILE( add( add( bp, bits_to_follow ), tmp ) < 0 ) + { + IF( LE_32( high, ari_q2new ) ) + { + bp = ari_put_bit_plus_follow( ptr, bp, bits_to_follow, 0 ); /* Q0 */ + bits_to_follow = 0; + move16(); + } + ELSE IF( GE_32( low, ari_q2new ) ) + { + bp = ari_put_bit_plus_follow( ptr, bp, bits_to_follow, 1 ); /* Q0 */ + bits_to_follow = 0; + move16(); + low = L_sub( low, ari_q2new ); /* Q0 */ + high = L_sub( high, ari_q2new ); /* Subtract offset to top. Q0*/ + } + ELSE + { + test(); + IF( GE_32( low, ari_q1new ) && LE_32( high, ari_q3new ) ) + { + /* Output an opposite bit */ + /* later if in middle half. */ + bits_to_follow = add( bits_to_follow, 1 ); /* Q0 */ + low = L_sub( low, ari_q1new ); /* Subtract offset to middle Q0*/ + high = L_sub( high, ari_q1new ); /* Q0 */ + } + ELSE + { + BREAK; /* Otherwise exit loop. */ + } + } + + low = L_add( low, low ); /* Q0 */ + high = L_add( high, high ); /* Scale up code range. Q0*/ + } + + s->low = low; /* Q0 */ + move32(); + s->high = high; /* Q0 */ + move32(); + s->bits_to_follow = bits_to_follow; /* Q0 */ + move16(); + + return bp; +} +#endif + +#define FUNCTION_ari_encode_14bits_high_low_ivas_fx +static Word16 ari_encode_14bits_high_low_ivas_fx( + Word16 *ptr, /* Q0 */ + Word16 bp, /* Q0 */ + Word16 bits, /* Q0 */ + Tastat *s, + Word32 high, /* Q0 */ + Word32 low /* Q0 */ +) +{ + Word16 bits_to_follow, tmp; + + bits_to_follow = extract_l( s->bits_to_follow ); /* Q0 */ + move16(); +#ifdef DEBUG_ARITH_IVAS_REPLACEMENT + printf("high_low1: s->low,high,btfo=0x%04x,0x%04x,0x%04x high,low=0x%04x,0x%04x bp=%d\n", + s->low, s->high, s->bits_to_follow, high,low,bp ); +#endif + + /* while there are more than 16 bits left */ + tmp = sub( 16, bits ); /* Q0 */ + WHILE( add( add( bp, bits_to_follow ), tmp ) < 0 ) + { + IF( LE_32( high, ari_q2new ) ) + { + bp = ari_put_bit_plus_follow( ptr, bp, bits_to_follow, 0 ); /* Q0 */ + bits_to_follow = 0; + move16(); + } + ELSE IF( GE_32( low, ari_q2new ) ) + { + bp = ari_put_bit_plus_follow( ptr, bp, bits_to_follow, 1 ); /* Q0 */ + bits_to_follow = 0; + move16(); + low = L_sub( low, ari_q2new ); /* Q0 */ + high = L_sub( high, ari_q2new ); /* Subtract offset to top. Q0*/ + } + ELSE + { + test(); + IF( GE_32( low, ari_q1new ) && LE_32( high, ari_q3new ) ) + { + /* Output an opposite bit */ + /* later if in middle half. */ + bits_to_follow = add( bits_to_follow, 1 ); /* Q0 */ + low = L_sub( low, ari_q1new ); /* Subtract offset to middle Q0*/ + high = L_sub( high, ari_q1new ); /* Q0 */ + } + ELSE + { + BREAK; /* Otherwise exit loop. */ + } + } + + low = L_add( low, low ); +#ifdef DEBUG_ARITH_IVAS_REPLACEMENT + printf("high_low2: high=0x%04x, s->btfo=%d\n", + high, s->bits_to_follow); +#endif + high = L_add( high, high ); /* Scale up code range. */ + } + + s->low = low; /* Q0 */ + move32(); + s->high = L_sub( high, 1 ); /* Q0 */ + move32(); + s->bits_to_follow = bits_to_follow; /* Q0 */ + move16(); + + return bp; +} + +static Word16 ari_encode_14bits_range_ivas_fx( + Word16 *ptr, /* Q0 */ + Word16 bp, /* Q0 */ + Word16 bits, /* Q0 */ + Tastat *s, + Word16 cum_freq_low, /* Q0 */ + Word16 cum_freq_high /* Q0 */ +) +{ + Word32 low, high, range; + + range = L_sub( s->high, s->low ) + 1; /* Q0 */ + + high = L_add( s->low, mul_sbc_14bits( range, cum_freq_high ) ); /* Q0 */ + low = L_add( s->low, mul_sbc_14bits( range, cum_freq_low ) ); /* Q0 */ +#ifdef DEBUG_ARITH_IVAS_REPLACEMENT + printf("range, s->low,high=0x%04x,0x%04x range=0x%04x low,high=0x%04x,0x%04x\n", + s->low, s->high+1, range, low, high ); +#endif + + Word16 ret = ari_encode_14bits_high_low_ivas_fx( ptr, bp, bits, s, high, low ); +#ifdef DEBUG_ARITH_IVAS_REPLACEMENT + printf("range end ret=%d, s->low,high,value=x%04x,0x%04x,x%04x\n", ret, s->low,s->high+1,s->bits_to_follow); +#endif + return ret; +} + diff --git a/lib_enc/stat_enc.h b/lib_enc/stat_enc.h index be38f731c6a0473550fe1f3e774f5b23c7851c85..7465571599240720c90ca9e0e8c8bfc95f85a829 100644 --- a/lib_enc/stat_enc.h +++ b/lib_enc/stat_enc.h @@ -454,7 +454,7 @@ typedef struct igfscfenc_public_data_struct const Word16 *cf_off_se11; Tastat acState; TastatEnc acState_fx; - + Tastat acState_ivas_fx; } IGFSCFENC_INSTANCE, *IGFSCFENC_INSTANCE_HANDLE;