"Richard Anderson" <[EMAIL PROTECTED]> wrote in message
news:39484@palm-dev-forum...
> The only real problem comes if you want to call Do_Sound at a higher speed
> as if another message is being processed you get delayed, also you can get
> the odd nilEvent for no apparent reason, but it seems to work fine so far.

There's not much you can do about the first problem. Just try to do
processing in small enough chunks so that you won't be too late.

The second problem is easily solved. You should never asssume that all
nilEvents are for you. The system is allowed to return a nilEvent before the
time-out you specified. Here's what your event loop should look like:

...
currentTime = TimGetTicks();
if (currentTime - lastBeepTime > beepInterval)
    delay = 0;    // We're late! Should have started next beep already.
else
    delay = beepInterval - (currentTime - lastBeepTime);
EvtGetEvent(&event, delay);
...
case nilEvent:
    currentTime = TimGetTicks();
    if (currentTime - lastBeepTime > beepInterval)
    {
        lastBeepTime = currentTime;
        SndDoCmd(...);    // start an asynchronous beep
    }
    break;
...

You can make the last part, which is currently only being done for
nilEvents, be unconditional. This improves the accuracy a bit but increases
the amount of processing.

Be careful with you math when doing this kind of stuff. Tick values are
unsigned 32 bit quantities that can wrap around. Never compare them.
--
Danny Epstein
OS Engineer, Palm Inc.


-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/tech/support/forums/

Reply via email to