From 8a96ebc7aed6c6af5ced04d13821d1eccc87acc8 Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Mon, 31 Jan 2011 01:15:16 +0100 Subject: slightly change the fractional change algorithm to minimize mean error --- AT91SAM7S256/Source/d_output.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/AT91SAM7S256/Source/d_output.c b/AT91SAM7S256/Source/d_output.c index 536e3cc..9d1ed6d 100644 --- a/AT91SAM7S256/Source/d_output.c +++ b/AT91SAM7S256/Source/d_output.c @@ -876,16 +876,16 @@ SLONG dOutputFractionalChange(SLONG Value, SWORD *FracError) /* Apply fractional change in case RegulationTime is different from * SPEED_TIME. In this case, fractional part is accumulated until it reach - * one (with "one" being SPEED_TIME). This is use the same principle as the - * Bresenham algorithm. */ + * one half (with "one" being SPEED_TIME). This is use the same principle + * as the Bresenham algorithm. */ IntegerChange = Value * RegulationTime / SPEED_TIME; *FracError += Value * RegulationTime % SPEED_TIME; - if (*FracError > SPEED_TIME) + if (*FracError > SPEED_TIME / 2) { *FracError -= SPEED_TIME; IntegerChange++; } - else if (*FracError < -SPEED_TIME) + else if (*FracError < -SPEED_TIME / 2) { *FracError += SPEED_TIME; IntegerChange--; -- cgit v1.2.3