【发布时间】:2014-07-26 22:38:39
【问题描述】:
在 OS X 中,我试图找到一个示例,说明如何发现最终用户系统上安装的所有音频单元并取回该信息以供显示和使用。
我知道音频组件与该任务有关,但我完全不知道如何去做。我遇到的所有示例都是基于使用 AudioComponentFindNext 查找“已知”Apple AU,而我找不到其他示例。
谁能给我举个例子?
谢谢
【问题讨论】:
标签: macos core-audio audiounit
在 OS X 中,我试图找到一个示例,说明如何发现最终用户系统上安装的所有音频单元并取回该信息以供显示和使用。
我知道音频组件与该任务有关,但我完全不知道如何去做。我遇到的所有示例都是基于使用 AudioComponentFindNext 查找“已知”Apple AU,而我找不到其他示例。
谁能给我举个例子?
谢谢
【问题讨论】:
标签: macos core-audio audiounit
您可以使用0 作为类型、子类型和制造商的通配符来设置AudioComponentDescription 结构。将其传递给AudioComponentFindNext:
AudioComponentDescription acd = { 0 };
AudioComponent comp = nullptr;
while((comp = AudioComponentFindNext(comp, &acd)) {
// Found an AU
}
以下是标题中的一些相关文档:
@function AudioComponentFindNext
@abstract Finds an audio component.
@discussion This function is used to find an audio component that is the closest match
to the provided values.
@param inComponent
If NULL, then the search starts from the beginning until an audio
component is found that matches the description provided by inDesc.
If non-NULL, then the search starts (continues) from the previously
found audio component specified by inComponent, and will return the next
found audio component.
@param inDesc
The type, subtype and manufacturer fields are used to specify the audio
component to search for. A value of 0 (zero) for any of these fields is
a wildcard, so the first match found is returned.
@result An audio component that matches the search parameters, or NULL if none found.
【讨论】:
只需使用提供的 AVAudioUnitComponentManager 组件函数即可获取音频单元。
它将返回与您传递的AudioComponentDescription 匹配的音频单元数组。
命令单击AudioComponentDescription 和kAudioUnitType_MusicDevice 以查看您可以使用的各种值。
// Exemple to get instruments audio units
var match = AudioComponentDescription()
match.componentType = kAudioUnitType_MusicDevice
let audioUnitComponents = AVAudioUnitComponentManager.shared().components(matching: match)
【讨论】: