best practices for sending data from UI to RemoteIO callback thread
best practices for sending data from UI to RemoteIO callback thread
- Subject: best practices for sending data from UI to RemoteIO callback thread
- From: Morgan Packard <email@hidden>
- Date: Sat, 26 Mar 2011 10:05:36 -0600
Hello,
I need to come up with a way for my audio thread to receive and defer "commands" sent by my UI. Specifically, I'm sending audio trigger messages from the UI side, and want to quantize those on the audio side. So the ui might generate, say, five varying trigger messages, which the audio thread will read and clear when it's ready.
My first, naive implementation went like this:
1) graphics thread adds "command" objects to an NSMutableSet
2) on the audio side, when a sequencer tick occurs, the audio thread reads the contents of the set, acts according to the command objects, and calls [NSMutableSet removeAllObjects].
My app has crashed a few times during manipulations of my NSMutableSet, and I suspect this is because of thread-safety issues. So I need to find a way to do this communication without, um, really bad violations of multithreading best-practices.
My first thought is to use performSelector:onThread:withObject:waitUntilDone:. Will this even work on the audio callback thread? If so, how do I get the NSThread which refers to the audio callback thread?
If the performSelector approach won't work, or isn't the best approach, what _is_ the best way to using the UI thread to "load up" the audio thread with a handful of tasks it needs to perform in the future?
******* note and apology for using objective-c in my render callback *******
I know it's been advised not to actually do audio synthesis on the RemoteIO callback thread, but I haven't figured out how to create an independent audio-generation thread which runs at high enough priority, so for now I'm sticking with generating audio in the RemoteIO callback. I'm also calling some objective-c code in my callback thread. Again, I know this goes against some of the advice I've been given here, but the app is running, audio is performing fine, with no glitches.
************************************************************************
thanks a bunch!
-Morgan
--
================================iOS app Thicket available on iTunes store.
================================
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden