Re: [linux-audio-dev] timesetevent alternative

From: Benno Senoner <sbenno@email-addr-hidden>
Date: Fri May 06 2005 - 15:30:26 EEST

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)
>
>
Right,
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

usleep(x)

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.

cheers,
Benno
http://www.linuxsampler.org
Received on Fri May 6 16:15:07 2005

This archive was generated by hypermail 2.1.8 : Fri May 06 2005 - 16:15:08 EEST