【问题标题】:How to get AudioComponent's Description Type letter code?如何获取 AudioComponent 的描述类型字母代码?
【发布时间】:2015-08-24 12:39:11
【问题描述】:

我试图在实例化它们之前了解 AudioComponents 并了解/使用 AudioUnits...

我使用通配符创建了一个 AudioComponentDescription:

var inDesc = AudioComponentDescription(componentType: OSType(),
                                    componentSubType: OSType(),
                               componentManufacturer: OSType(),
                                      componentFlags: UInt32(0),
                                  componentFlagsMask: UInt32(0))

我看看有多少 AudioComponent:

AudioComponentCount(&inDesc) // returns 98 in a playground (ok)

我通过在 AudioComponentFindNext 中使用“nil”作为第一个参数来关注第一个 AudioComponent:

var currentComp = AudioComponentFindNext(nil, &inDesc)

看它的名字:

func getAudioComponentName (componentInit:AudioComponent) -> CFString {
    var componentProp:AudioComponent = componentInit
    var componentNameProp:CFString = "" as CFString
    var unmanagedCurrentCompName:Unmanaged<CFString>?
    AudioComponentCopyName(componentProp, &unmanagedCurrentCompName)
    componentNameProp = unmanagedCurrentCompName!.takeRetainedValue()
    return componentNameProp
}
var currentComponentName:CFString = "" as CFString
currentComponentName = getAudioComponentName(currentComp) // returns "Apple PAC3 Transcoder" (ok)

此时,以下尝试将不会“正常”。

我想进一步了解这个“Apple PAC3 Transcoder”及其描述:

// Creating an empty AudioComponentDescription
var currentComponentDescription = AudioComponentDescription()
// Gettings currentComp's description (type)
AudioComponentGetDescription(currentComp, &currentComponentDescription)
var compDescType:OSType = currentComponentDescription.componentType // returns 1633903715

在最后一行代码中,如何得到AUComponent.h中描述的字母代码:

enum
{
    kAudioUnitType_Output                   = 'auou',
    kAudioUnitType_MusicDevice              = 'aumu',
    kAudioUnitType_MusicEffect              = 'aumf',
    kAudioUnitType_FormatConverter          = 'aufc',
    kAudioUnitType_Effect                   = 'aufx',
    kAudioUnitType_Mixer                    = 'aumx',
    kAudioUnitType_Panner                   = 'aupn',
    kAudioUnitType_Generator                = 'augn',
    kAudioUnitType_OfflineEffect            = 'auol',
    kAudioUnitType_MIDIProcessor            = 'aumi'
};

为了进一步的兼容性,我宁愿不必在我的代码中重现这个“枚举”。

【问题讨论】:

  • 此时我正在查看 kAudioUnitProperty_GetUIComponentList ...

标签: swift audiounit


【解决方案1】:

componentType 是一个OSType,它是将 4 个 ASCII 字符代码打包成 32 位。

1633903715 十六进制是0x61636463

0x61636463 在 ascii 中是 'acdc'(0x61 = 'a'、0x63 = 'c' 等...)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-22
    • 2021-06-26
    • 1970-01-01
    • 2012-08-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多