[linux-audio-dev] timesetevent alternative
sbenno at gardena.net
Fri May 6 12:30:26 UTC 2005
Paul Davis wrote:
>usleep (2) is the canonical high resolution sleep function on POSIX
>(although nanosleep(2) is a close cousin). the resolution is limited
>by the system timer interrupt frequency, which is typically either
>100Hz (2.4 and older kernels) or 1kHz (2.6 kernels)
nanosleep() might be a bit more precise than usleep() but for low sleep
values ( AFAIK < 2msec ) it
busywaits when you run your app SCHED_FIFO which in the case of
sustained streams of low sleep values
could chew up all the CPU, not idea for real time audio apps.
Last time I tried usleep() on a 2.4 kernel with HZ=1000 ( Red Hat
kernels come with HZ=1000 by default),
the resolution was
the minimum real sleep value was 2msec , no matter how small x was
if x > 2000 (=2msec) then usleep always sleeps floor(x/1000)+1 msecs.
For MIDI playback usleep() on a 1000Hz kernel (fortuntately on 2.6
kernels HZ=1kHz is the standard) is completely fine.
Of course if you want sample accuracy then the MIDI sequencer requires a
mechanism ala VSTi to pass time stamped events
to software MIDI instruments.
More information about the Linux-audio-dev