tmv: Add tmv_sign()

The sign of time values is tested in tsproc.c.  Add an abstraction
tmv_sign() to return the sign of a time value.

Signed-off-by: Michael Brown <mbrown@fensystems.co.uk>
master
Michael Brown 2018-03-01 18:12:25 +00:00 committed by Richard Cochran
parent 1b7ff890be
commit ffc5b93f95
2 changed files with 8 additions and 2 deletions

5
tmv.h
View File

@ -56,6 +56,11 @@ static inline int tmv_cmp(tmv_t a, tmv_t b)
return a == b ? 0 : a > b ? +1 : -1;
}
static inline int tmv_sign(tmv_t x)
{
return x == 0 ? 0 : x > 0 ? +1 : -1;
}
static inline int tmv_is_zero(tmv_t x)
{
return x == ((tmv_t) 0) ? 1 : 0;

View File

@ -133,7 +133,7 @@ tmv_t get_raw_delay(struct tsproc *tsp)
t41 = tmv_sub(tsp->t4, tsp->t1);
delay = tmv_div(tmv_add(t23, t41), 2);
if (delay < 0) {
if (tmv_sign(delay) < 0) {
pr_debug("negative delay %10" PRId64,
tmv_to_nanoseconds(delay));
pr_debug("delay = (t2 - t3) * rr + (t4 - t1)");
@ -215,7 +215,8 @@ int tsproc_update_offset(struct tsproc *tsp, tmv_t *offset, double *weight)
if (!weight)
return 0;
if (weighting(tsp) && tsp->filtered_delay > 0 && raw_delay > 0) {
if (weighting(tsp) && tmv_sign(tsp->filtered_delay) > 0 &&
tmv_sign(raw_delay) > 0) {
*weight = tmv_dbl(tsp->filtered_delay) / tmv_dbl(raw_delay);
if (*weight > 1.0)
*weight = 1.0;