kAudioHardwarePropertyDevices and USB weirdness
kAudioHardwarePropertyDevices and USB weirdness
- Subject: kAudioHardwarePropertyDevices and USB weirdness
- From: Rob Clark <email@hidden>
- Date: Tue, 15 Nov 2011 16:11:34 +0000
In some circumstances I'm getting the wrong? AudioDeviceID for some
devices, particularly with a USB device. In some circumstances A USB
device seems to cause problems (sometimes with the values of non USB
devices too).
By wrong I mean that If I use these DeviceIDs to request further
information I get the "who?" error returned by
AudioObjectGetPropertyData.
The following seems to be a minimal case of it failing with the code
attached below.
The code just listens for changes to audio devices and lists the ids
obtained by AudioObjectGetPropertyData for property
kAudioHardwarePropertyDevices
I have a blue icicle USB audio device (also get the same results with
an Edirol UA-25).
The application below sees the device with ID 0x4c.
If I unplug the device, the app sees it go away, if I replug it in it
comes back with ID 0x52.
If I now quit my application and re-start it, it reports the old (now
wrong?) ID of 0x4c.
HALLab does the same thing, it reports the ID of 0x52 the second time
the device is plugged in, but reverts to the old one if restarted.
HALLab however can still access information about the device, so
presumably isn't doing it via the AudioDeviceID, as my application
using an expanded version of the code below can't.
Am I doing something wrong?
Code run on OS X 10.7.2.
Xcode 4.2 default cocoa application template with Appdelegate.m as below.
CoreAudio and AudioToolbox frameworks linked.
AppDelegate.m:
#import "AppDelegate.h"
#include <AudioToolbox/AudioToolbox.h>
#include <stdio.h>
OSStatus listener(AudioObjectID inObjectID, UInt32 inNumberAddresses,
const AudioObjectPropertyAddress inAddresses[],
void* inClientData);
int getAudioDevices();
static const AudioObjectPropertyAddress addressAllDevices = {
kAudioHardwarePropertyDevices,
kAudioObjectPropertyScopeGlobal,
kAudioObjectPropertyElementMaster };
@implementation AppDelegate
@synthesize window =_window;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
AudioHardwareServiceAddPropertyListener(kAudioObjectSystemObject,
&addressAllDevices, listener, NULL);
getAudioDevices();
}
- (void)dealloc
{
AudioHardwareServiceRemovePropertyListener(kAudioObjectSystemObject,
&addressAllDevices, listener, NULL);
[super dealloc];
}
@end
OSStatus listener(AudioObjectID inObjectID, UInt32 inNumberAddresses,
const AudioObjectPropertyAddress inAddresses[],
void* inClientData)
{
getAudioDevices();
return noErr;
}
int getAudioDevices()
{
AudioDeviceID *devices;
UInt32 noOfDevices;
UInt32 outSize;
AudioObjectGetPropertyDataSize(kAudioObjectSystemObject,
&addressAllDevices, 0, NULL, &outSize);
noOfDevices = outSize / sizeof(AudioDeviceID);
devices = (AudioDeviceID *) malloc(outSize);
memset( devices, 0, outSize );
AudioObjectGetPropertyData(kAudioObjectSystemObject,
&addressAllDevices, 0, NULL, &outSize, (void *) devices);
for (UInt32 i = 0 ; i < noOfDevices; i++) {
fprintf(stderr, "%x ",*(devices+i));
}
fprintf(stderr, "\n");
return 0;
}
--
Rob Clark
_______________________________________________
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