1

In an iOS app project I have an audio-unit (used for input/output) initialization code which (after setting various properties, callbacks etc.) ends with:

OSErr err = AudioUnitInitialize (self.audioUnit);
NSAssert1 (err == noErr, "Error initializing audio unit: %ld", err);

My problem is that in some situations I have to run this code on a computer (in the iPhone simulator of course) with no audio hardware available, and then the following happens:

First, on the console I get the following message (sorry for the long lines, it seems more clear to me without extra line-breaks):

2012-05-03 12:41:15.020 TimeKeeper[452:10703] Error loading /System/Library/Extensions/AudioIPCDriver.kext/Contents/Resources/AudioIPCPlugIn.bundle/Contents/MacOS/AudioIPCPlugIn:  dlopen(/System/Library/Extensions/AudioIPCDriver.kext/Contents/Resources/AudioIPCPlugIn.bundle/Contents/MacOS/AudioIPCPlugIn, 262): Symbol not found: ___CFObjCIsCollectable
  Referenced from: /System/Library/Frameworks/Security.framework/Versions/A/Security
  Expected in: /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation
 in /System/Library/Frameworks/Security.framework/Versions/A/Security
2012-05-03 12:41:15.140 TimeKeeper[452:10703] Error loading /System/Library/Extensions/AudioIPCDriver.kext/Contents/Resources/AudioIPCPlugIn.bundle/Contents/MacOS/AudioIPCPlugIn:  dlopen(/System/Library/Extensions/AudioIPCDriver.kext/Contents/Resources/AudioIPCPlugIn.bundle/Contents/MacOS/AudioIPCPlugIn, 262): Symbol not found: ___CFObjCIsCollectable
  Referenced from: /System/Library/Frameworks/Security.framework/Versions/A/Security
  Expected in: /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation
 in /System/Library/Frameworks/Security.framework/Versions/A/Security
2012-05-03 12:41:15.207 TimeKeeper[452:10703] Error '!obj' trying to fetch default input device's sample rate
2012-05-03 12:41:15.209 TimeKeeper[452:10703] Error getting audio input device sample rate: '!obj'

Then about 2 minutes or so pass until AudioUnitInitialize returns with error code 0 (i.e, noErr), and this message on the console:

2012-05-03 12:43:45.222 TimeKeeper[452:14403] AQMEIO_Base::DoStartIO: timeout
2012-05-03 12:43:45.226 TimeKeeper[452:14403] AQMEDevice(0x7b0de00)::StartIO: error -66681

If I then call AudioOutputUnitStart, the function again takes about 2 minutes to return, but at least the return status is not zero.

I would like to be able to tell if the audio hardware is not available, so I can avoid from calling AudioUnitInitialize in the first place --- or at least get a non-zero return status without having to wait so long (in app run-time terms).

Itamar Katz
  • 9,544
  • 5
  • 42
  • 74

1 Answers1

1

You could always check for running simulated iOS code and do something else.

#if TARGET_IPHONE_SIMULATOR
    // stub out audio unit with a unit test, unix pipe, or etc.
#endif
hotpaw2
  • 70,107
  • 14
  • 90
  • 153
  • Yes, but sometimes the audio hardware **is** available when running in the simulator. So I need a direct way. – Itamar Katz May 04 '12 at 19:40
  • A Simulator app is a Mac OS X App. You can always check an environment variable or do IOKit or QuickTime calls in this environment that you can't do on an iOS device. – hotpaw2 May 04 '12 at 20:14