I'm playing audio successfully using an AUGraph with an output unit created using the following description:
AudioComponentDescription outputDescription;
outputDescription.componentType =kAudioUnitType_Output;
outputDescription.componentSubType =kAudioUnitSubType_DefaultOutput;
outputDescription.componentManufacturer =kAudioUnitManufacturer_Apple;
outputDescription.componentFlags = 0;
outputDescription.componentFlagsMask = 0;
Today, I've been trying to add the ability to choose the audio output device independently of the default device. I'm doing this by setting the kAudioOutputUnitProperty_CurrentDevice property on the output audio unit, like this:
OSStatus status = AudioUnitSetProperty(outputUnit,
kAudioOutputUnitProperty_CurrentDevice,
kAudioUnitScope_Output,
0,
&deviceId,
sizeof(deviceId));
I have two questions:
1) This setting works in that audio is diverted to the given audio device. However, when a new default output device is chosen in the Sound pane of System Preferences, my audio gets diverted to that device. I'd like it to stay where it's told.
2) I'd also like to be able to have an option for the audio to follow the default device, as most applications behave. However, I can't seem to find out how to do this once I've set kAudioOutputUnitProperty_CurrentDevice (assuming the audio stays in place as in my first question). I try to find the AudioDeviceID for the default device and set that, but I get an error code -10851 when I try to set the kAudioOutputUnitProperty_CurrentDevice with the device ID I find. The device ID is being found like this:
AudioObjectPropertyAddress property;
property.mScope = kAudioObjectPropertyScopeGlobal;
property.mElement = kAudioObjectPropertyElementMaster;
property.mSelector = kAudioHardwarePropertyDefaultOutputDevice;
AudioDeviceID outputDeviceID = kAudioObjectUnknown;
UInt32 propertySize = sizeof(AudioDeviceID);
OSStatus status = AudioHardwareServiceGetPropertyData(kAudioObjectSystemObject, &property, 0, NULL, &propertySize, &outputDeviceID);
Thanks in advance for any help