Re: PlayThru (was: AudioUnit for default input device)
Re: PlayThru (was: AudioUnit for default input device)
- Subject: Re: PlayThru (was: AudioUnit for default input device)
- From: Jeff Moore <email@hidden>
- Date: Mon, 19 Nov 2001 11:55:12 -0800
on 11/19/01 11:02 AM, Lieven Dekeyser <email@hidden> wrote:
>
> If the default input and the default output device are different devices.
>
> You will have to deal with moving the data coming in from one IOProc to the
>
> buffer going out in another IOProc. You could use a queue of some kind. Be
>
> sure to copy the data out of the input buffers to your own buffers since
>
> those buffers get reused by the HAL each cycle.
>
>
I tried to copy the AudioBufferLists and put these copies in a queue, but
>
it didn't work :-(
>
Are the IOProcs fired at interrupt time?
No. Nothing runs at interrupt time on OS X in user space.
It is called from an extremely high priority thread whose priority doesn't
degrade (it's actually a mach time constraint thread). So, there are lots of
APIs that do things that will disrupt the timing of that thread by taking
locks or waiting on locks. Some of them (particularly CFRunLoop), rely on
spin locks to do their work and will result in the machine hanging if you
use them.
So it isn't as safe as a normal thread either.
>
If so, I guess calling malloc and
>
memcpy isn't allowed, right? How do you copy the bufferdata?
You can do pretty much anything in your IOProc. But there will be a cost to
some of them (see above).
The rule of thumb would be to question any code that might manipulate a
lock. You want to avoid putting the IOThread to sleep if at all possible.
In general, I would avoid allocating or deallocating memory in the IOProc,
but it can be done if you really need it or you're like me and unusually
lazy and writing code that isn't performance intensive (speaking of my test
code here, not the HAL =).
Copying data around is precisely the sort of thing you should be doing in
your IOProc, so calling memcpy is encouraged =)
Whatever you do, don't keep a reference to the AudioBufferList or any of the
buffers beyond the scope of your IOProc. They can be and do get recycled out
from under you.
The best thing to do in your case is to allocate your buffers ahead of time.
Then, you can use pull them out of a free list, copy the data to them, and
put them in a queue for your other IOProc to pull out of, copy to the output
buffers and then put them back in the free list.
--
Jeff Moore
Core Audio
Apple