Inconsistent timer 
Author Message
 Inconsistent timer

I'm trying to create a program that will regularly issue a sound (a
snare drum sound) on a regular beat. I've discovered that it's almost
impossible to get a steady beat going. There are irregularities with
using a timer and playing a sound apparently. I'm wondering if anyone
knows why this is and how to overcome it?

Here's what I have. A window with a timer in it. In the open method for
the window I have:

  Timer1.Mode = 2

  Timer1.Period = 1000

In the timer's action method I have a snare drum sound playing:

  snare.play()

This very simple program results in an uneven beat, almost steady, but
not quite. There's a little lag here and there. It sounds like an
amateur drummer trying his best to keep a steady beat.

Why would this be happening? Shouldn't the sound be playing at a
regular and steady beat? I've also tried a variation where I was
preloading the sound and that gave the same results. I could hear my
hard drive working when I run the program so I'm wondering if the sound
is occasionally being purged, then reloaded which may be accounting for
the lag. Is there a way to mark a sound in RB as preloaded and
unpurgeable? I'd like to test that out.



Mon, 02 Feb 2004 10:08:49 GMT  
 Inconsistent timer

Quote:

> I'm trying to create a program that will regularly issue a sound (a
> snare drum sound) on a regular beat. I've discovered that it's almost
> impossible to get a steady beat going. There are irregularities with
> using a timer and playing a sound apparently. I'm wondering if anyone
> knows why this is and how to overcome it?

A timer is just a kind of thread. It is not a perfectly steady timekeeper.
You'd like to be called back at such and such a time, but you might not
be. You're surrendering control when you use a timer; if you don't want to
surrender control, don't do that! If you want the most accurate time
possible, you want to do just the opposite: hog the CPU and watch the
clock constantly.

The alternative, if you want to yield, is to yield the shortest possible
time; use a Timer with period 1, so that you'll be called back as often as
possible, and check the time each time, to see if it's time to play again.
Look at my MIDI-playing program (p. 512 ff) for an example. m.

--

*** REALbasic, The Definitive Guide! ***
http://www.oreilly.com/catalog/realbasic/



Mon, 02 Feb 2004 11:34:23 GMT  
 Inconsistent timer
Thanks, Matt.


Mon, 02 Feb 2004 16:03:29 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Wait ms Timer Multiple returning inaccurate timer value

2. Using timer 2 instead of timer 1

3. Inconsistent Browse/VCR behaviour

4. HELP:Inconsistent "Variable not found" error

5. Inconsistent wire cursors

6. ANSI FLOAT inconsistent

7. Inconsistent Time Interval

8. inconsistent arrays with multiple buffered readings

9. Using Waveform Chart, inconsistent results when setting X range and delta X properties

10. Invariants and need for inconsistent states

11. Implemented warning about inconsistent usage of return statements

12. Strange inconsistent behaviour from OS/2 REXX exec

 

 
Powered by phpBB® Forum Software