Created
April 27, 2010 05:04
-
-
Save ddribin/380344 to your computer and use it in GitHub Desktop.
goto + macro
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define FAIL_ON_ERR(_X_) if ((status = (_X_)) != noErr) { goto failed; } | |
- (BOOL)play:(NSError **)error; | |
{ | |
NSAssert(_graph == NULL, @"Graph is already started"); | |
OSStatus status; | |
FAIL_ON_ERR(NewAUGraph(&_graph)); | |
FAIL_ON_ERR([self addOutputNode]); | |
FAIL_ON_ERR([self addConverterNode]); | |
FAIL_ON_ERR(AUGraphConnectNodeInput(_graph, _converterNode, 0, _outputNode, 0)); | |
FAIL_ON_ERR(AUGraphOpen(_graph)); | |
[self setupDataFormat]; | |
FAIL_ON_ERR([self setDataFormatOfConverterAudioUnit]); | |
FAIL_ON_ERR([self setMaximumFramesPerSlice]); | |
FAIL_ON_ERR([self setRenderCallbackOfConverterNode]); | |
FAIL_ON_ERR(AUGraphInitialize(_graph)); | |
A440SineWaveGeneratorInitWithFrequency(&_sineWaveGenerator, 440.0); | |
FAIL_ON_ERR(AUGraphStart(_graph)); | |
return YES; | |
failed: | |
if (_graph != NULL) { | |
DisposeAUGraph(_graph); | |
} | |
if (error != NULL) { | |
*error = [NSError errorWithDomain:NSOSStatusErrorDomain code:status userInfo:nil]; | |
} | |
return NO; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment