Created
April 3, 2012 20:58
-
-
Save bartolsthoorn/2295463 to your computer and use it in GitHub Desktop.
This file contains 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
2012-04-03 22:57:16.770 MixerHost[76183:10703] The stereo stream format for the "guitar" mixer input bus: | |
2012-04-03 22:57:16.771 MixerHost[76183:10703] Sample Rate: 44100 | |
2012-04-03 22:57:16.772 MixerHost[76183:10703] Format ID: lpcm | |
2012-04-03 22:57:16.772 MixerHost[76183:10703] Format Flags: C2C | |
2012-04-03 22:57:16.773 MixerHost[76183:10703] Bytes per Packet: 4 | |
2012-04-03 22:57:16.774 MixerHost[76183:10703] Frames per Packet: 1 | |
2012-04-03 22:57:16.774 MixerHost[76183:10703] Bytes per Frame: 4 | |
2012-04-03 22:57:16.774 MixerHost[76183:10703] Channels per Frame: 2 | |
2012-04-03 22:57:16.775 MixerHost[76183:10703] Bits per Channel: 32 | |
2012-04-03 22:57:16.775 MixerHost[76183:10703] The mono stream format for the "beats" mixer input bus: | |
2012-04-03 22:57:16.776 MixerHost[76183:10703] Sample Rate: 44100 | |
2012-04-03 22:57:16.777 MixerHost[76183:10703] Format ID: lpcm | |
2012-04-03 22:57:16.777 MixerHost[76183:10703] Format Flags: C2C | |
2012-04-03 22:57:16.777 MixerHost[76183:10703] Bytes per Packet: 4 | |
2012-04-03 22:57:19.844 MixerHost[76183:10703] Frames per Packet: 1 | |
2012-04-03 22:57:19.847 MixerHost[76183:10703] Bytes per Frame: 4 | |
2012-04-03 22:57:19.848 MixerHost[76183:10703] Channels per Frame: 1 | |
2012-04-03 22:57:19.848 MixerHost[76183:10703] Bits per Channel: 32 | |
2012-04-03 22:57:19.848 MixerHost[76183:10703] readAudioFilesIntoMemory - file 0 | |
2012-04-03 22:57:20.141 MixerHost[76183:10703] Finished reading file 0 into memory | |
2012-04-03 22:57:20.144 MixerHost[76183:10703] readAudioFilesIntoMemory - file 1 | |
2012-04-03 22:57:20.413 MixerHost[76183:10703] Finished reading file 1 into memory | |
2012-04-03 22:57:20.422 MixerHost[76183:10703] Configuring and then initializing audio processing graph | |
2012-04-03 22:57:20.423 MixerHost[76183:10703] Adding nodes to audio processing graph | |
2012-04-03 22:57:20.429 MixerHost[76183:10703] Setting mixer unit input bus count to: 2 | |
2012-04-03 22:57:20.433 MixerHost[76183:10703] Setting kAudioUnitProperty_MaximumFramesPerSlice for mixer unit global scope | |
2012-04-03 22:57:20.434 MixerHost[76183:10703] Registering the render callback with mixer unit input bus 0 | |
2012-04-03 22:57:20.436 MixerHost[76183:10703] Registering the render callback with mixer unit input bus 1 | |
2012-04-03 22:57:20.437 MixerHost[76183:10703] Setting stereo stream format for mixer unit "guitar" input bus | |
2012-04-03 22:57:20.439 MixerHost[76183:10703] Setting mono stream format for mixer unit "beats" input bus | |
2012-04-03 22:57:20.442 MixerHost[76183:10703] Setting sample rate for EQ unit output scope | |
2012-04-03 22:57:20.446 MixerHost[76183:10703] Connecting the mixer output to the input of the EQ!! | |
2012-04-03 22:57:20.454 MixerHost[76183:10703] Connecting the EQ output to the input of the I/O output element | |
2012-04-03 22:57:20.455 MixerHost[76183:10703] Audio processing graph state immediately before initializing it: | |
AudioUnitGraph 0x12997009: | |
Member Nodes: | |
node 1: 'auou' 'rioc' 'appl', instance 0x7560660 O | |
node 2: 'aufx' 'nbeq' 'appl', instance 0x734ef90 O | |
node 3: 'aumx' 'mcmx' 'appl', instance 0x739c170 O | |
Connections: | |
node 3 bus 0 => node 2 bus 0 [ 2 ch, 44100 Hz, 'lpcm' (0x00000029) 32-bit little-endian float, deinterleaved] | |
node 2 bus 0 => node 1 bus 0 [ 2 ch, 0 Hz, 'lpcm' (0x0000000C) 16-bit little-endian signed integer] | |
Input Callbacks: | |
{0x5390, 0x7399f24} => node 3 bus 0 [2 ch, 44100 Hz] | |
{0x5390, 0x7399f24} => node 3 bus 1 [1 ch, 44100 Hz] | |
CurrentState: | |
mLastUpdateError=0, eventsToProcess=F, isRunning=F | |
2012-04-03 22:57:20.460 MixerHost[76183:10703] Initializing the audio processing graph | |
2012-04-03 22:57:20.482 MixerHost[76183:10703] *** AUGraphInitialize error: ˇˇ’å FFFFD58C | |
2012-04-03 22:57:20.484 MixerHost[76183:10703] Bus 0 now on | |
2012-04-03 22:57:20.485 MixerHost[76183:10703] Bus 1 now on |
This file contains 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
#pragma mark - | |
#pragma mark Audio processing graph setup | |
// This method performs all the work needed to set up the audio processing graph: | |
// 1. Instantiate and open an audio processing graph | |
// 2. Obtain the audio unit nodes for the graph | |
// 3. Configure the Multichannel Mixer unit | |
// * specify the number of input buses | |
// * specify the output sample rate | |
// * specify the maximum frames-per-slice | |
// 4. Initialize the audio processing graph | |
- (void) configureAndInitializeAudioProcessingGraph { | |
NSLog (@"Configuring and then initializing audio processing graph"); | |
OSStatus result = noErr; | |
//............................................................................ | |
// Create a new audio processing graph. | |
result = NewAUGraph (&processingGraph); | |
if (noErr != result) {[self printErrorMessage: @"NewAUGraph" withStatus: result]; return;} | |
//............................................................................ | |
// Specify the audio unit component descriptions for the audio units to be | |
// added to the graph. | |
// I/O unit | |
AudioComponentDescription iOUnitDescription; | |
iOUnitDescription.componentType = kAudioUnitType_Output; | |
iOUnitDescription.componentSubType = kAudioUnitSubType_RemoteIO; | |
iOUnitDescription.componentManufacturer = kAudioUnitManufacturer_Apple; | |
iOUnitDescription.componentFlags = 0; | |
iOUnitDescription.componentFlagsMask = 0; | |
// EQ unit | |
AudioComponentDescription EQUnitDescription; | |
EQUnitDescription.componentType = kAudioUnitType_Effect; | |
EQUnitDescription.componentSubType = kAudioUnitSubType_NBandEQ; | |
EQUnitDescription.componentManufacturer = kAudioUnitManufacturer_Apple; | |
EQUnitDescription.componentFlags = 0; | |
EQUnitDescription.componentFlagsMask = 0; | |
// Multichannel mixer unit | |
AudioComponentDescription MixerUnitDescription; | |
MixerUnitDescription.componentType = kAudioUnitType_Mixer; | |
MixerUnitDescription.componentSubType = kAudioUnitSubType_MultiChannelMixer; | |
MixerUnitDescription.componentManufacturer = kAudioUnitManufacturer_Apple; | |
MixerUnitDescription.componentFlags = 0; | |
MixerUnitDescription.componentFlagsMask = 0; | |
//............................................................................ | |
// Add nodes to the audio processing graph. | |
NSLog (@"Adding nodes to audio processing graph"); | |
AUNode iONode; // node for I/O unit | |
AUNode mixerNode; // node for Multichannel Mixer unit | |
AUNode EQNode; | |
// Add the nodes to the audio processing graph | |
// I/O! | |
result = AUGraphAddNode ( | |
processingGraph, | |
&iOUnitDescription, | |
&iONode); | |
if (noErr != result) {[self printErrorMessage: @"AUGraphNewNode failed for I/O unit" withStatus: result]; return;} | |
// EQ! | |
result = AUGraphAddNode ( | |
processingGraph, | |
&EQUnitDescription, | |
&EQNode | |
); | |
if (noErr != result) {[self printErrorMessage: @"AUGraphNewNode failed for EQ unit" withStatus: result]; return;} | |
// MIXING! | |
result = AUGraphAddNode ( | |
processingGraph, | |
&MixerUnitDescription, | |
&mixerNode | |
); | |
if (noErr != result) {[self printErrorMessage: @"AUGraphNewNode failed for Mixer unit" withStatus: result]; return;} | |
//............................................................................ | |
// Open the audio processing graph | |
// Following this call, the audio units are instantiated but not initialized | |
// (no resource allocation occurs and the audio units are not in a state to | |
// process audio). | |
result = AUGraphOpen (processingGraph); | |
if (noErr != result) {[self printErrorMessage: @"AUGraphOpen" withStatus: result]; return;} | |
result = AUGraphNodeInfo ( | |
processingGraph, | |
mixerNode, | |
NULL, | |
&mixerUnit | |
); | |
//............................................................................ | |
// Obtain the mixer unit instance from its corresponding node. | |
result = AUGraphNodeInfo ( | |
processingGraph, | |
EQNode, | |
NULL, | |
&EQUnit | |
); | |
if (noErr != result) {[self printErrorMessage: @"AUGraphNodeInfo" withStatus: result]; return;} | |
//............................................................................ | |
// Obtain the EQ unit instance from its corresponding node. | |
result = AUGraphNodeInfo ( | |
processingGraph, | |
mixerNode, | |
NULL, | |
&mixerUnit | |
); | |
if (noErr != result) {[self printErrorMessage: @"AUGraphNodeInfo" withStatus: result]; return;} | |
//............................................................................ | |
// Multichannel Mixer unit Setup | |
UInt32 busCount = 2; // bus count for mixer unit input | |
UInt32 guitarBus = 0; // mixer unit bus 0 will be stereo and will take the guitar sound | |
UInt32 beatsBus = 1; // mixer unit bus 1 will be mono and will take the beats sound | |
NSLog (@"Setting mixer unit input bus count to: %lu", busCount); | |
result = AudioUnitSetProperty ( | |
mixerUnit, | |
kAudioUnitProperty_ElementCount, | |
kAudioUnitScope_Input, | |
0, | |
&busCount, | |
sizeof (busCount) | |
); | |
if (noErr != result) {[self printErrorMessage: @"AudioUnitSetProperty (set mixer unit bus count)" withStatus: result]; return;} | |
NSLog (@"Setting kAudioUnitProperty_MaximumFramesPerSlice for mixer unit global scope"); | |
// Increase the maximum frames per slice allows the mixer unit to accommodate the | |
// larger slice size used when the screen is locked. | |
UInt32 maximumFramesPerSlice = 4096; | |
result = AudioUnitSetProperty ( | |
mixerUnit, | |
kAudioUnitProperty_MaximumFramesPerSlice, | |
kAudioUnitScope_Global, | |
0, | |
&maximumFramesPerSlice, | |
sizeof (maximumFramesPerSlice) | |
); | |
if (noErr != result) {[self printErrorMessage: @"AudioUnitSetProperty (set mixer unit input stream format)" withStatus: result]; return;} | |
// Attach the input render callback and context to each input bus | |
for (UInt16 busNumber = 0; busNumber < busCount; ++busNumber) { | |
// Setup the struture that contains the input render callback | |
AURenderCallbackStruct inputCallbackStruct; | |
inputCallbackStruct.inputProc = &inputRenderCallback; | |
inputCallbackStruct.inputProcRefCon = soundStructArray; | |
NSLog (@"Registering the render callback with mixer unit input bus %u", busNumber); | |
// Set a callback for the specified node's specified input | |
result = AUGraphSetNodeInputCallback ( | |
processingGraph, | |
mixerNode, | |
busNumber, | |
&inputCallbackStruct | |
); | |
if (noErr != result) {[self printErrorMessage: @"AUGraphSetNodeInputCallback" withStatus: result]; return;} | |
} | |
NSLog (@"Setting stereo stream format for mixer unit \"guitar\" input bus"); | |
result = AudioUnitSetProperty ( | |
mixerUnit, | |
kAudioUnitProperty_StreamFormat, | |
kAudioUnitScope_Input, | |
guitarBus, | |
&stereoStreamFormat, | |
sizeof (stereoStreamFormat) | |
); | |
if (noErr != result) {[self printErrorMessage: @"AudioUnitSetProperty (set mixer unit guitar input bus stream format)" withStatus: result];return;} | |
NSLog (@"Setting mono stream format for mixer unit \"beats\" input bus"); | |
result = AudioUnitSetProperty ( | |
mixerUnit, | |
kAudioUnitProperty_StreamFormat, | |
kAudioUnitScope_Input, | |
beatsBus, | |
&monoStreamFormat, | |
sizeof (monoStreamFormat) | |
); | |
if (noErr != result) {[self printErrorMessage: @"AudioUnitSetProperty (set mixer unit beats input bus stream format)" withStatus: result];return;} | |
NSLog (@"Setting sample rate for EQ unit output scope"); | |
result = AudioUnitSetProperty ( | |
EQUnit, | |
kAudioUnitProperty_SampleRate, | |
kAudioUnitScope_Output, | |
0, | |
&graphSampleRate, | |
sizeof (graphSampleRate) | |
); | |
if (noErr != result) {[self printErrorMessage: @"AudioUnitSetProperty (set EQ unit output stream format)" withStatus: result]; return;} | |
//............................................................................ | |
// Connect the nodes of the audio processing graph | |
NSLog (@"Connecting the mixer output to the input of the EQ!!"); | |
result = AUGraphConnectNodeInput ( | |
processingGraph, | |
mixerNode, // source node | |
0, // source node output bus number | |
EQNode, // destination node | |
0 // desintation node input bus number | |
); | |
if (noErr != result) {[self printErrorMessage: @"AUGraphConnectNodeInput" withStatus: result]; return;} | |
NSLog (@"Connecting the EQ output to the input of the I/O output element"); | |
result = AUGraphConnectNodeInput ( | |
processingGraph, | |
EQNode, // source node | |
0, // source node output bus number | |
iONode, // destination node | |
0 // desintation node input bus number | |
); | |
if (noErr != result) {[self printErrorMessage: @"AUGraphConnectNodeInput" withStatus: result]; return;} | |
//............................................................................ | |
// Initialize audio processing graph | |
// Diagnostic code | |
// Call CAShow if you want to look at the state of the audio processing | |
// graph. | |
NSLog (@"Audio processing graph state immediately before initializing it:"); | |
CAShow (processingGraph); | |
NSLog (@"Initializing the audio processing graph"); | |
// Initialize the audio processing graph, configure audio data stream formats for | |
// each input and output, and validate the connections between audio units. | |
result = AUGraphInitialize (processingGraph); | |
if (noErr != result) {[self printErrorMessage: @"AUGraphInitialize" withStatus: result]; return;} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment