shithub: opus

Download patch

ref: dc8a6eee433ef2cf8866d7bfe051c331d6607a81
parent: 3a4a463f0a1e17dad8adce1fa846743426e025c8
author: Timothy B. Terriberry <[email protected]>
date: Mon Mar 15 19:49:28 EDT 2010

Update the log2 approximation to accomodate the increased bit precision from bd0610d21b28b76095a49e601df44fb792b96369. This requires another term in the power series to reduce the error to the level of truncation (peak absolute error 0.621785). Also refactor the rounding bias term so that further changes to DB_SHIFT will leave the result unbiased.

--- a/libcelt/mathops.h
+++ b/libcelt/mathops.h
@@ -306,15 +306,14 @@
 {
    int i;
    celt_word16 n, frac;
-   /*-0.41446   0.96093  -0.33981   0.15600 */
-   /* -0.4144541824871411+32/16384, 0.9590923197873218, -0.3395129038105771,
-       0.16541096501128538 */
-   const celt_word16 C[4] = {-6758, 15715, -5563, 2708};
+   /* -0.41509302963303146, 0.9609890551383969, -0.31836011537636605,
+       0.15530808010959576, -0.08556153059057618 */
+   const celt_word16 C[5] = {-6801+(1<<13-DB_SHIFT), 15746, -5217, 2545, -1401};
    if (x==0)
       return -32767;
    i = celt_ilog2(x);
    n = VSHR32(x,i-15)-32768-16384;
-   frac = ADD16(C[0], MULT16_16_Q15(n, ADD16(C[1], MULT16_16_Q15(n, ADD16(C[2], MULT16_16_Q15(n, (C[3])))))));
+   frac = ADD16(C[0], MULT16_16_Q15(n, ADD16(C[1], MULT16_16_Q15(n, ADD16(C[2], MULT16_16_Q15(n, ADD16(C[3], MULT16_16_Q15(n, C[4]))))))));
    return SHL16(i-13,DB_SHIFT)+SHR16(frac,14-DB_SHIFT);
 }