diff --git a/lib_enc/ACcontextMapping_enc_fx.c b/lib_enc/ACcontextMapping_enc_fx.c index 08baa4f3d23dcbd61f5d030b675c9afdaed50180..9607ffd0fef2490aced6c27d4c789abbfdbedc59 100644 --- a/lib_enc/ACcontextMapping_enc_fx.c +++ b/lib_enc/ACcontextMapping_enc_fx.c @@ -1106,8 +1106,8 @@ void RCcontextMapping_encode2_no_mem_s17_LCS_fx( } /* Finish range encoder */ - rc_tot_bits = rc_uni_enc_finish_fx( &rc_st_enc ); /* No. of bits consumed by range coder Q0*/ - bp = add( rc_tot_bits, nbbits_ntuples ); /* Update bitstream pointer Q0*/ + rc_tot_bits = rc_uni_enc_finish_fx( &rc_st_enc ); /* No. of bits consumed by range coder Q0*/ + bp = add( rc_tot_bits, nbbits_ntuples ); /* Update bitstream pointer Q0*/ /* Cross-check that there is no overflow */ @@ -1215,15 +1215,15 @@ static Word16 find_last_nz_pair_fx( *-------------------------------------------------------------------*/ Word16 RCcontextMapping_encode2_estimate_no_mem_s17_LCS_fx( - Word16 *x, /* Spectral coefficients Q0*/ - const Word16 nt, /* L - size of spectrum (no. of spectral coefficients) Q0*/ - Word16 *lastnz_out, /* Q0 */ - Word16 *nEncoded, /* No. of spectral coefficients that can be coded without an overflow occuring Q0*/ - const Word16 target, /* Target bits Q0*/ - Word16 *stop, /* Q0 */ - Word16 mode, /* Q0 */ - CONTEXT_HM_CONFIG *hm_cfg /* context-based harmonic model configuration */ -) + Word16 *x, /* Spectral coefficients Q0*/ + const Word16 nt, /* L - size of spectrum (no. of spectral coefficients) Q0*/ + Word16 *lastnz_out, /* Q0 */ + Word16 *nEncoded, /* No. of spectral coefficients that can be coded without an overflow occuring Q0*/ + const Word16 target, /* Target bits Q0*/ + Word16 *stop, /* Q0 */ + Word16 mode, /* Q0 */ + CONTEXT_HM_CONFIG *hm_cfg /* context-based harmonic model configuration */ + ) { /* Common variables */ Word16 a1, b1; @@ -1363,7 +1363,7 @@ Word16 RCcontextMapping_encode2_estimate_no_mem_s17_LCS_fx( pki = lookup[lev1]; /* ESC symbol */ bit_estimate_fx = BASOP_Util_Add_Mant32Exp( bit_estimate_fx, bit_estimate_e, ari_bit_estimate_s17_LC_fx[pki][VAL_ESC], 8, &bit_estimate_e ); /* exp(bit_estimate_e) */ - bit_estimate_fx = BASOP_Util_Add_Mant32Exp( bit_estimate_fx, bit_estimate_e, 2 * ONE_IN_Q29, 2, &bit_estimate_e ); /* Add 2 LSB bits corresponding to the bit-plane exp(bit_estimate_e) */ + bit_estimate_fx = BASOP_Util_Add_Mant32Exp( bit_estimate_fx, bit_estimate_e, 2 * ONE_IN_Q29, 2, &bit_estimate_e ); /* Add 2 LSB bits corresponding to the bit-plane exp(bit_estimate_e) */ a1 = shr( a1, 1 ); b1 = shr( b1, 1 ); @@ -1451,7 +1451,7 @@ Word16 RCcontextMapping_encode2_estimate_no_mem_s17_LCS_fx( *nEncoded = lastnz2; /* Q0 */ move16(); - *stop = stop2; /* If zero, it means no overflow occured during bit-estimation Q0*/ + *stop = stop2; /* If zero, it means no overflow occured during bit-estimation Q0*/ move16(); *lastnz_out = lastnz; /* Q0 */ move16(); @@ -1512,7 +1512,7 @@ Word16 RCcontextMapping_encode2_estimate_no_mem_s17_LCS_fx( lastnz = add( lastnz, 2 ); /* Q0 */ IF( LT_16( lastnz, 2 ) ) { - lastnz = 2; /* At least one tuple is coded Q0*/ + lastnz = 2; /* At least one tuple is coded Q0*/ move16(); } @@ -1611,37 +1611,37 @@ Word16 RCcontextMapping_encode2_estimate_no_mem_s17_LCS_fx( move16(); } ELSE /* Overflow */ + { + IF( *stop ){ + *stop = tot_bits2; /* Q0 */ + move16(); + } + ELSE { - IF( *stop ){ - *stop = tot_bits2; /* Q0 */ + *stop = round_fx( L_shr( bit_estimate_fx, sub( Q15, bit_estimate_e ) ) ); /* Q0 */ + move16(); + } + } + + *lastnz_out = lastnz; /* Q0 */ move16(); - } - ELSE - { - *stop = round_fx( L_shr( bit_estimate_fx, sub( Q15, bit_estimate_e ) ) ); /* Q0 */ + *nEncoded = lastnz2; /* Q0 */ move16(); - } -} + /* Safety mechanism to avoid overflow */ + test(); + IF( EQ_16( lastnz2, 2 ) && EQ_16( overflow_flag, 1 ) ) + { + FOR( k = 0; k < lastnz2; k++ ) + { + x[k] = 0; + move16(); + } + } -*lastnz_out = lastnz; /* Q0 */ -move16(); -*nEncoded = lastnz2; /* Q0 */ -move16(); -/* Safety mechanism to avoid overflow */ -test(); -IF( EQ_16( lastnz2, 2 ) && EQ_16( overflow_flag, 1 ) ) -{ - FOR( k = 0; k < lastnz2; k++ ) - { - x[k] = 0; - move16(); + return tot_bits2; } } -return tot_bits2; -} -} - /*-------------------------------------------------------------------* * RCcontextMapping_encode2_estimate_bandWise_start_fx() @@ -1745,6 +1745,13 @@ Word16 RCcontextMapping_encode2_estimate_bandWise_fx( const UWord8 *lookup; Word16 idx; Word16 tmp; + Word32 accu_lut; + Word16 accu_variables; + + accu_lut = 0; + move32(); + accu_variables = 0; + move16(); /* Main Loop through the 2-tuples */ /*hContextMem->nt_half = end_line >> 1;*/ @@ -1777,10 +1784,8 @@ Word16 RCcontextMapping_encode2_estimate_bandWise_fx( lev1 = -( 1 << ( NBITS_CONTEXT + NBITS_RATEQ ) ); /* Q0 */ /* Signs Bits */ - hContextMem->bit_estimate_fx = BASOP_Util_Add_Mant32Exp( hContextMem->bit_estimate_fx, hContextMem->bit_estimate_e, imult3216( ONE_IN_Q30, s_min( a1, 1 ) ), Q1, &hContextMem->bit_estimate_e ); /* exp(hContextMem->bit_estimate_e) */ - hContextMem->bit_estimate_fx = BASOP_Util_Add_Mant32Exp( hContextMem->bit_estimate_fx, hContextMem->bit_estimate_e, imult3216( ONE_IN_Q30, s_min( b1, 1 ) ), Q1, &hContextMem->bit_estimate_e ); /* exp(hContextMem->bit_estimate_e) */ - move32(); - move32(); + accu_variables = add( accu_variables, s_min( a1, 1 ) ); + accu_variables = add( accu_variables, s_min( b1, 1 ) ); /* pre-compute address of ari_pk_s17_LC_ext[0][Val_esc] to avoid doing it multiple times inside the loop */ lookup = &ari_lookup_s17_LC[t] + ( 1 << ( NBITS_CONTEXT + NBITS_RATEQ ) ); @@ -1792,13 +1797,8 @@ Word16 RCcontextMapping_encode2_estimate_bandWise_fx( pki = lookup[lev1]; /* Q0 */ move16(); - hContextMem->bit_estimate_fx = BASOP_Util_Add_Mant32Exp( hContextMem->bit_estimate_fx, hContextMem->bit_estimate_e, ari_bit_estimate_s17_LC_fx[pki][VAL_ESC], Q8, &hContextMem->bit_estimate_e ); /* exp(hContextMem->bit_estimate_e) */ - hContextMem->bit_estimate_fx = BASOP_Util_Add_Mant32Exp( hContextMem->bit_estimate_fx, hContextMem->bit_estimate_e, 2 * ONE_IN_Q29, Q2, &hContextMem->bit_estimate_e ); /* Add the 2 LSB bits that were shifted out exp(hContextMem->bit_estimate_e) */ - move32(); - move32(); - - // hContextMem->bit_estimate = hContextMem->bit_estimate + ari_bit_estimate_s17_LC[pki][VAL_ESC]; - // hContextMem->bit_estimate += 2; /* Add the 2 LSB bits that were shifted out */ + accu_lut = L_add( accu_lut, ari_bit_estimate_s17_LC_fx[pki][VAL_ESC]>>3 ); + accu_variables = add( accu_variables, 2 ); a1 = shr( a1, 1 ); b1 = shr( b1, 1 ); @@ -1809,10 +1809,8 @@ Word16 RCcontextMapping_encode2_estimate_bandWise_fx( pki = lookup[lev1]; /* Q0 */ move16(); - symbol = add( a1, i_mult( A_THRES, b1 ) ); /* MSB symbol Q0*/ - hContextMem->bit_estimate_fx = BASOP_Util_Add_Mant32Exp( hContextMem->bit_estimate_fx, hContextMem->bit_estimate_e, ari_bit_estimate_s17_LC_fx[pki][symbol], Q8, &hContextMem->bit_estimate_e ); /* exp(bit_estimate_e) */ - move32(); - // hContextMem->bit_estimate = hContextMem->bit_estimate + ari_bit_estimate_s17_LC[pki][symbol]; + symbol = add( a1, i_mult( A_THRES, b1 ) ); /* MSB symbol Q0*/ + accu_lut = L_add( accu_lut, ari_bit_estimate_s17_LC_fx[pki][symbol]>>3 ); /* Update context */ lev1 = shr( lev1, NBITS_CONTEXT + NBITS_RATEQ ); @@ -1830,6 +1828,9 @@ Word16 RCcontextMapping_encode2_estimate_bandWise_fx( move16(); } /*end of the 2-tuples loop*/ + accu_lut = L_add( accu_lut, imult3216( ONE_IN_Q20, accu_variables ) ); // bring the accu_variables into Q20 + hContextMem->bit_estimate_fx = BASOP_Util_Add_Mant32Exp( hContextMem->bit_estimate_fx, hContextMem->bit_estimate_e, accu_lut, Q11, &hContextMem->bit_estimate_e ); /* exp(bit_estimate_e) */ + move32(); total_output_bits = round_fx( L_shr( hContextMem->bit_estimate_fx, sub( Q15, hContextMem->bit_estimate_e ) ) ); /* Q0 */ // total_output_bits = (Word16) ( hContextMem->bit_estimate + 0.5f );