【发布时间】:2023-03-14 00:41:01
【问题描述】:
我有一个 USB 音频设备 (PreSonus audiobox),并且希望能够在该 USB 设备和默认输出设备(内置扬声器)之间切换我的程序的音频输出。苹果文档告诉我必须使用 AUHAL:
如果您需要连接到 [..] 默认输出设备以外的硬件设备,则需要使用 AUHAL。
通常,我会做一个设备描述,然后查看它是否存在。我写了一个函数来测试这个:
-(OSStatus) showAUHALDevices
{
//Show all available AUHAL devices
// Create description
AudioComponentDescription test_desc;
test_desc.componentType = kAudioUnitType_Output;
test_desc.componentSubType = kAudioUnitSubType_HALOutput;
test_desc.componentManufacturer = kAudioUnitManufacturer_Apple;
test_desc.componentFlags = 0;
test_desc.componentFlagsMask = 0;
// Determine number of available components
UInt32 count = AudioComponentCount(&test_desc);
// Print result
OSStatus err = noErr;
CFStringRef compName;
AudioComponent test_comp;
for (UInt32 i = 0; i < count; i++)
{
test_comp = AudioComponentFindNext(nil, &test_desc);
err = AudioComponentCopyName(test_comp, &compName);
NSLog(@"Audio component number %u/%u: %@", (i+1), count, compName);
}
return err;
}
这里的问题是我无法将test_desc.componentManufacturer = kAudioUnitManufacturer_Apple; 设置为 Apple 以外的其他制造商,因此 USB 设备显然没有显示在日志中打印的列表中。
我错过了什么?据我所知,这不是驱动问题。
提前致谢。
编辑
我已将所有属性设置为零,但 USB 设备仍然没有显示在 98 个不同的组件之间。我可以用[AVCaptureDevice devicesWithMediaType:AVMediaTypeAudio] 找到它,所以我可以将其设置为输入,但不能设置为输出..
【问题讨论】:
标签: objective-c macos audio