针对蓝牙设备制造商的OSX CoreAudio查询返回NULL - 是否有任何方法可供我引用此设备用于AudioComponentFindNext?

问题描述:

我正在查询osx中所有活动的输入设备,然后尝试使用AudioUnit通过蓝牙设备播放音频(如果已连接)。针对蓝牙设备制造商的OSX CoreAudio查询返回NULL - 是否有任何方法可供我引用此设备用于AudioComponentFindNext?

我有一个蓝牙设备,返回一个UID和设备名称,但未能返回设备制造商(kAudioObjectPropertyManufacturer)。

在阅读Apple文档时,我看到The unique vendor identifier, registered with Apple, for the audio component,所以我必须假定供应商并不打算向Apple注册。

没有制造商我不知道如何选择设备。我继承的代码使音频这样的:

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); 

有什么办法没有设备制造商创造一个AudioUnit?或者更好的是,有没有办法使用当前输入/输出音频设备设置为的任何一种创建AudioUnit

如果你有一个设备的UID,你可以把它翻译成一个设备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 

并从那里你可以设置非盟kAudioOutputUnitProperty_CurrentDevicedeviceID