Created
April 27, 2010 05:21
-
-
Save ddribin/380353 to your computer and use it in GitHub Desktop.
early return + helper
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
- (void)setError:(NSError **)error withOSStatus:(OSStatus)status | |
{ | |
if (error != NULL) { | |
*error = [NSError errorWithDomain:NSOSStatusErrorDomain code:status userInfo:nil]; | |
} | |
} | |
- (BOOL)play:(NSError **)error; | |
{ | |
NSAssert(_graph == NULL, @"Graph is already started"); | |
OSStatus status; | |
status = NewAUGraph(&_graph); | |
if (status != noErr) { | |
[self setError:error withOSStatus:status]; | |
return NO; | |
} | |
status = [self addOutputNode]; | |
if (status != noErr) { | |
DisposeAUGraph(_graph); | |
[self setError:error withOSStatus:status]; | |
return NO; | |
} | |
status = [self addConverterNode]; | |
if (status != noErr) { | |
DisposeAUGraph(_graph); | |
[self setError:error withOSStatus:status]; | |
return NO; | |
} | |
status = AUGraphConnectNodeInput(_graph, _converterNode, 0, _outputNode, 0); | |
if (status != noErr) { | |
DisposeAUGraph(_graph); | |
[self setError:error withOSStatus:status]; | |
return NO; | |
} | |
status = AUGraphOpen(_graph); | |
if (status != noErr) { | |
DisposeAUGraph(_graph); | |
[self setError:error withOSStatus:status]; | |
return NO; | |
} | |
[self setupDataFormat]; | |
status = [self setDataFormatOfConverterAudioUnit]; | |
if (status != noErr) { | |
DisposeAUGraph(_graph); | |
[self setError:error withOSStatus:status]; | |
return NO; | |
} | |
status = [self setMaximumFramesPerSlice]; | |
if (status != noErr) { | |
DisposeAUGraph(_graph); | |
[self setError:error withOSStatus:status]; | |
return NO; | |
} | |
status = [self setRenderCallbackOfConverterNode]; | |
if (status != noErr) { | |
DisposeAUGraph(_graph); | |
[self setError:error withOSStatus:status]; | |
return NO; | |
} | |
status = AUGraphInitialize(_graph); | |
if (status != noErr) { | |
DisposeAUGraph(_graph); | |
[self setError:error withOSStatus:status]; | |
return NO; | |
} | |
A440SineWaveGeneratorInitWithFrequency(&_sineWaveGenerator, 440.0); | |
status = AUGraphStart(_graph); | |
if (status != noErr) { | |
DisposeAUGraph(_graph); | |
[self setError:error withOSStatus:status]; | |
return NO; | |
} | |
return YES; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment