我正在查询osx中的所有 Activity 输入设备,然后尝试使用AudioUnit通过蓝牙设备(如果已连接)播放音频。
我有一个返回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_CurrentDevice
设置AU的deviceID
。