Re: iOS - Question on AUGraph in objective C / CPP
Re: iOS - Question on AUGraph in objective C / CPP
- Subject: Re: iOS - Question on AUGraph in objective C / CPP
- From: Andy Davidson <email@hidden>
- Date: Mon, 29 Oct 2012 11:07:17 -0700
- Thread-topic: iOS - Question on AUGraph in objective C / CPP
Hi Chris
Speaking of cleaning up drudgery… in the book, we have that CheckError() function that logs a returned OSStatus if it's not noErr and then exit()s. This is just for teachability, and it's clearly totally unsuitable for production (you should never call exit() on iOS!). I mentioned in my Core Audio class at Cocoaconf this weekend that one of the classic problems in Core Audio is cleaning up state when you get an error. Say you've created an AUGraph, but creating one of your nodes fails and you have to bail out… it's a hassle figuring out what does and doesn't need to get cleaned up, and returning gracefully. The frequent use of "goto bail" in Apple's sample code is one of the places I point people to as a legitimate use of goto.
I've never had a great way to deal with this, but someone in the class made the comment that our CheckError() function could take, in addition to an error string, a block that would be executed in the failure case. In the block, a caller could include whatever code was necessary to clean up state at the specific point of failure. It's a neat idea, although I can also see it getting messy and copy-and-pastey if you have a bunch of CA calls in a row, each adding more things to clean up in a failure case. But it might merit some thought as a way to write a generic Core Audio "bail" function.
I wrote my own CheckError based on the version in your book. Instead of calling exit() I use NSNotification to broadcast a generic "MY_AUDIO_ERROR".
I typically have my app delegate listen for the "MY_AUDIO_ERROR", the implementation stop the audio graph, and does all the clean up, then sets everything up again
///////////////////////////////////////////////////////////////////////////////
- (void) broadCastStateChange {
dispatch_async(dispatch_get_main_queue(), ^{
NSString *notificationName = [SCIAudioStateChangeNotification stringWithEnum:currentState.currentState];
[[NSNotificationCenter defaultCenter] postNotificationName:notificationName object:currentState];
});
}
Andy
|
_______________________________________________
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