Commit 145d4840 authored by Sandesh Venkatesh's avatar Sandesh Venkatesh
Browse files

Merge branch '851-issue-in-dft-stereo-at-32-kbps-for-residual-spectral-lines-decoding' into 'main'

Fix 851, prevent precision lost during UL_div

See merge request !530
parents df07c071 2dd1d618
Loading
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -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 */
+11 −1
Original line number Diff line number Diff line
@@ -631,17 +631,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 */