AudioObjectGetPropertyData 获取输入设备列表
如何在 OS X 中利用 AudioObjectGetPropertyData
检索系统输入设备的列表?我目前有以下虚拟代码用于检索全局设备列表:
AudioDeviceID devices[12];
UInt32 arraySize = sizeof(devices);
AudioObjectPropertyAddress thePropertyAddress = { kAudioHardwarePropertyDevices,
kAudioObjectPropertyScopeGlobal,
kAudioObjectPropertyElementMaster };
AudioObjectGetPropertyData(kAudioObjectSystemObject,
&thePropertyAddress,
0,
NULL,
&arraySize,
&devices);
How do I utilize AudioObjectGetPropertyData
in OS X to retrieve a list of the system's input devices? I currently have the following dummy code for retrieving a global list of devices:
AudioDeviceID devices[12];
UInt32 arraySize = sizeof(devices);
AudioObjectPropertyAddress thePropertyAddress = { kAudioHardwarePropertyDevices,
kAudioObjectPropertyScopeGlobal,
kAudioObjectPropertyElementMaster };
AudioObjectGetPropertyData(kAudioObjectSystemObject,
&thePropertyAddress,
0,
NULL,
&arraySize,
&devices);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
要确定设备是否是输入设备,您需要检查它是否有任何输入通道。
以下是从 Objective-C 类此处修改的代码:
< strong>原始代码片段是:
这是我转换的一些代码,应该可以工作(尽管未经测试):
To determine if a device is an input device you need to check and see if it has any input channels.
Here is code modified from the Objective-C class here:
The original code snippet was:
Here is some code I converted that should work (untested though):
Swift 3.0 Xcode 8 Beta 5
与此斗争了很长一段时间,但目前看来工作正常。
Swift 3.0 Xcode 8 Beta 5
Struggled with this for a good while but this seems to work fine for now.
这是我发现的在迭代 CoreAudio 设备 ID 时对输入和输出进行排序的最佳方法。
这只是循环内的部分:
我希望这对其他人有帮助,我最终发现 Apple 在 xcode/Extras/CoreAudio/HAL/HPBase 中提供了他们的 C++ HAL 接口的源代码,这是解决这个问题的关键。
Here's the best way I have found to sort inputs from outputs when iterating through CoreAudio device ids.
This is just the part inside the loop:
I hope this helps someone else, I ended finding out that Apple provides the source for their C+++ HAL interface in xcode/Extras/CoreAudio/HAL/HPBase which was key in figuring this out.
我稍微修改了“sbooth”提交的代码,以打印所有输入设备以及编号。每个设备的缓冲区数量和数量。每个缓冲区的通道数。
I have slightly modified the code submitted by "sbooth" to print all the input devices along with the no. of buffers for each device and no. of channels for each buffer.