diff --git a/lib_com/options.h b/lib_com/options.h index 475df11b7327d7919108a408d28efcc1d90b44bc..a3e716f4065556e603301f0b0bddaf707cd5c251 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -164,6 +164,8 @@ #define FIX_839_FB_CONTENT_SOMETIME_MISSING /* VA : Fix scaling error for FB TB BWE */ #define FIX_846_TILT_BWE /* VA : Proposed fix to 846, to solve saturation */ #define FIX_843_LOW_RATE_BWE /* VA : Proposed fix to 843 to solve mid band noise */ +#define FIX851_RANGE_DEC_PRECISION /* VA : 851 Proposed fix to keep precision during UL_div*/ + /* ################## End DEVELOPMENT switches ######################### */ /* clang-format on */ diff --git a/lib_dec/ivas_range_uni_dec.c b/lib_dec/ivas_range_uni_dec.c index f2bbc1202fd08afb87200af3e5a6b39a8f1d8c19..94efd89e02f97d259ceaa431777a25d5f6ad3c33 100644 --- a/lib_dec/ivas_range_uni_dec.c +++ b/lib_dec/ivas_range_uni_dec.c @@ -628,17 +628,27 @@ UWord16 rc_uni_dec_read_bits( UWord32 range; /* local copy (4 to 7 uses) */ Word16 norm_range; UWord32 temp1, temp2; - +#ifdef FIX851_RANGE_DEC_PRECISION + Word16 exp_temp1; +#endif low = rc_st_dec->rc_low; range = rc_st_dec->rc_range; move32(); move32(); range = (UWord32) W_shr( range, bits ); +#ifdef FIX851_RANGE_DEC_PRECISION + exp_temp1 = sub( W_norm( low ), 31 + 1 ); + temp1 = (UWord32) W_shl( low, exp_temp1 ); + norm_range = sub( W_norm( range ), 31 ); + temp2 = (UWord32) W_shl( range, norm_range ); + val = (UWord32) W_shr( UL_div( temp1, temp2 ), sub( add( 32, exp_temp1 ), norm_range ) ); +#else temp1 = (UWord32) W_shr( low, 1 ); norm_range = sub( W_norm( range ), 31 ); temp2 = (UWord32) W_shl( range, norm_range ); val = (UWord32) W_shr( UL_div( temp1, temp2 ), sub( 32 - 1, norm_range ) ); +#endif /* in case of bitstream errors it is possible that val >= (1 << bits) */ IF( W_shr( val, bits ) != 0 ) /* equivalent condition */