Reputation: 3452
I am querying all active input devices in osx and then try to use AudioUnit for playing audio through the bluetooth device (if connected).
I have a bluetooth device that returns a UID and device name but fails to return a device manufacturer (kAudioObjectPropertyManufacturer).
In reading Apple docs I see The unique vendor identifier, registered with Apple, for the audio component
so I must assume that the vendor didn't bother registering with Apple.
Without the manufacturer I am not sure how to select the device. The code I inherited enables audio like this:
AudioComponentDescription desc;
desc.componentType = kAudioUnitType_Output;
desc.componentSubType = kAudioUnitSubType_VoiceProcessingIO; // 'vpio'
desc.componentManufacturer = manufacturerName;
desc.componentFlags = 0;
desc.componentFlagsMask = 0;
AudioComponent comp = AudioComponentFindNext(NULL, &desc);
OSStatus error = AudioComponentInstanceNew(comp, &myAudioUnit);
Is there a way to create an AudioUnit
without a device manufacturer? Or better yet, is there a way to create an AudioUnit
using whatever the current input/output audio device is set to?
Upvotes: 1
Views: 361
Reputation: 16976
If you have a device's UID you can translate it into a device ID:
// deviceUID is a CFStringRef
AudioDeviceID deviceID = kAudioDeviceUnknown;
AudioObjectPropertyAddress propertyAddress = {
.mSelector = kAudioHardwarePropertyDeviceForUID,
.mScope = kAudioObjectPropertyScopeGlobal,
.mElement = kAudioObjectPropertyElementMaster
};
AudioValueTranslation translation = {
&deviceUID, sizeof(deviceUID),
&deviceID, sizeof(deviceID)
};
UInt32 specifierSize = sizeof(translation);
auto result = AudioObjectGetPropertyData(kAudioObjectSystemObject, &propertyAddress, 0, nullptr, &specifierSize, &translation);
if(kAudioHardwareNoError != result) {
// Handle error
}
if(kAudioDeviceUnknown == deviceID)
// The device isn't connected or doesn't exist
And from there you can set the AU's kAudioOutputUnitProperty_CurrentDevice
with deviceID
.
Upvotes: 1