Threads in CoreAudio applications
Threads in CoreAudio applications
- Subject: Threads in CoreAudio applications
- From: Stephane Letz <email@hidden>
- Date: Wed, 28 Nov 2001 12:04:39 +0100
Following the question of Michael A. Thompson about his port of
enlightenment sound daemon on CoreAudio, I have some remarks and questions
about thread management and CoreAudio :
- simple audio applications published by Apple usually implement the whole
audio processing directly in to the AudioIOProc. This is simple and
guarantee very good real-time performances.
- for more serious audio applications, it seems that Apple recommend NOT to
do the whole audio processing in the AudioIOProc because the machine
behaviour can be disturbed. Is there any technical reason like reantrancy
issues for that?
Of course an audio application that need a lot of CPU to do it's job will
block the machine. But if the costly audio code is done in another thread,
it need the same CPU. In this case the machine will be less blocked but the
audio application will probaly have xruns problems. So basically the choice
is between a possibliy blocked machine that does its audio job correctly,
or a less blocked one with a audio application that does not run correctly
because of xruns. What is the better?
- if the application does it's job in another thread (like a pthread) then
one has to deal with synchronization issues between this thread and the
AudioIOProc.
- it seems that using the standard ways like condition variables and mutex
using pthread API like pthread_cond_wait, pthread_cond_signal is not
recommended because the IOThread may be blocked by the mutex.
So what are we supposed to use to synchronize the two threads?
Another problem if the thread priority. On Linux, and audio application
usually use a SCHED_FIFO thread that get realtime scheduling.
Can this be done also on Mac OSX? Or is there any other way to set the
priority of the application thread doing the audio code to a value that
garantee its correct scheduling (something like less priority compared to
the IOThread and more than any normal thread)
I think this kind of questions has to be solved for all audio applications
so having a global and generic answer from Apple would be very helpfull.
Stephane Letz
Grame: Centre National de creation musicale
9, Rue du Garet
69001 Lyon
Tel: 04-72-07-37-00
Fax: 04-72-07-37-01
Web: www.grame.fr