diff options
author | Lennart Poettering <lennart@poettering.net> | 2008-06-26 18:49:02 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2008-06-26 18:49:02 +0200 |
commit | dcbb7f2680a2b8a74691ec0ef1334fb655cf9bf6 (patch) | |
tree | 238f89148a139f6545e40e208739d6f74e758e9f | |
parent | eab1cb8df952bc302d14efd1640d96f8bbdb148a (diff) |
convert to double only once, and make sure we can deal with negative results of -y
-rw-r--r-- | src/pulsecore/time-smoother.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/pulsecore/time-smoother.c b/src/pulsecore/time-smoother.c index 40220ad9..d0231486 100644 --- a/src/pulsecore/time-smoother.c +++ b/src/pulsecore/time-smoother.c @@ -295,24 +295,29 @@ static void estimate(pa_smoother *s, pa_usec_t x, pa_usec_t *y, double *deriv) { *deriv = s->dp; } else { + double tx, ty; /* Ok, we're not yet on track, thus let's interpolate, and * make sure that the first derivative is smooth */ calc_abc(s); + tx = (double) x; + /* Move to origin */ - x -= s->ex; + tx -= (double) s->ex; /* Horner scheme */ - *y = (pa_usec_t) ((double) x * (s->c + (double) x * (s->b + (double) x * s->a))); + ty = (tx * (s->c + tx * (s->b + tx * s->a))); /* Move back from origin */ - *y += s->ey; + ty += (double) s->ey; + + *y = ty >= 0 ? (pa_usec_t) ty : 0; /* Horner scheme */ if (deriv) - *deriv = s->c + ((double) x * (s->b*2 + (double) x * s->a*3)); + *deriv = s->c + (tx * (s->b*2 + tx * s->a*3)); } /* Guarantee monotonicity */ |