Realtime scheduling??

François Pinard pinard at iro.umontreal.ca
Wed Jan 19 14:25:30 EST 2000


Paul Winkler <slinkp23 at yahoo.com> writes:

> I'm working on a module I eventually hope to use to generate musical
> events in realtime.  (These events will be sent to MIDI devices or
> to software synthesizers.)  I've found that on my Linux system (pretty
> much stock RedHat 5.2), scheduling actions with sched.scheduler is not as
> reliable as I'd like.  Events are anywhere from 2 to 20 milliseconds late.
> I'd like to improve the reliability, which brings me to my next question:

I did something similar, had similar findings, and did similar research.
However, being quite reluctant at forcing my things to be suid'ed to root,
I tried something else, which turned out to be very workable.  It seems that
even if the human ear is extremely picky about sound frequency, it is very
forgiving in rythmical details, as long as the overall rhythm is preserved.

So, I just set the scheduler so it runs after real-time, instead of using
the scheduler to insert theoretical delays.  That is, you maintain a logical
real time in your program, and when about to ask for a delay, you delay
the logical real time plus the wanted delay minus the actual real time.
The effect is that you automatically catchup on lags, and very surprisingly,
it works well.  The musical behaviour is often acceptable even under heavy
machine load.  Of course, it is perfect (or not far from) with light load.

-- 
François Pinard   http://www.iro.umontreal.ca/~pinard






More information about the Python-list mailing list