针对蓝牙设备制造商的OSX CoreAudio查询返回NULL - 有什么办法可以让我为AudioComponentFindNext引用此设备吗?

时间:2017-08-16 18:42:45

标签: macos audio bluetooth core-audio audiounit

我正在查询osx中的所有活动输入设备,然后尝试使用AudioUnit通过蓝牙设备播放音频(如果已连接)。

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

在阅读Apple文档时,我看到using System; using System.Collections.Generic;////Not used using System.Linq;////Not used using System.Web;////Not used using System.Web.Mvc; using System.Web.Routing; using Microsoft.AspNet.Identity; ////Not used namespace MyPortal { public class ActionFilterSessionCheck : ActionFilterAttribute, IActionFilter { void IActionFilter.OnActionExecuting(ActionExecutingContext filterContext) { string userName = null; if (filterContext.HttpContext.User.Identity.IsAuthenticated) { userName = filterContext.HttpContext.User.Identity.Name; //ERROR*** //string userID = filterContext.HttpContext.User.Identity.GetUserID(); } string sessionLogin = "Login" + userName; if (userName == null || (System.Web.HttpContext.Current.Session[sessionLogin] == null)) { if (filterContext.HttpContext.Request.IsAjaxRequest()) { //AJAX request throw new Exception("Session time out"); } else { // Standard request filterContext.Result = new RedirectToRouteResult( new RouteValueDictionary { { "action", "Login" }, { "controller", "Account" } }); } } //Call standard behavior this.OnActionExecuting(filterContext); } } } 所以我必须假设供应商没有在Apple注册。

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

The unique vendor identifier, registered with Apple, for the audio component

有没有办法在没有设备制造商的情况下创建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

1 个答案:

答案 0 :(得分:1)

如果您有设备的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

从那里你可以设置AU的kAudioOutputUnitProperty_CurrentDevice deviceID