Squashed commit of the following:
[opus.git] / libcelt / mathops.c
index 3857a9b..1dca101 100644 (file)
@@ -74,15 +74,15 @@ celt_word32 frac_div32(celt_word32 a, celt_word32 b)
 {
    celt_word16 rcp;
    celt_word32 result, rem;
-   int shift = 30-celt_ilog2(b);
+   int shift = 29-celt_ilog2(b);
    a = SHL32(a,shift);
    b = SHL32(b,shift);
 
    /* 16-bit reciprocal */
-   rcp = ROUND16(celt_rcp(ROUND16(b,16)),2);
-   result = SHL32(MULT16_32_Q15(rcp, a),1);
+   rcp = ROUND16(celt_rcp(ROUND16(b,16)),3);
+   result = SHL32(MULT16_32_Q15(rcp, a),2);
    rem = a-MULT32_32_Q31(result, b);
-   result += SHL32(MULT16_32_Q15(rcp, rem),1);
+   result += SHL32(MULT16_32_Q15(rcp, rem),2);
    return result;
 }