【问题标题】:AUHAL with USB audio device带有 USB 音频设备的 AUHAL
【发布时间】:2023-03-14 00:41:01
【问题描述】:

我有一个 USB 音频设备 (PreSonus audiobox),并且希望能够在该 USB 设备和默认输出设备(内置扬声器)之间切换我的程序的音频输出。苹果文档告诉我必须使用 AUHAL:

如果您需要连接到 [..] 默认输出设备以外的硬件设备,则需要使用 AUHAL。

Source

通常,我会做一个设备描述,然后查看它是否存在。我写了一个函数来测试这个:

-(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


    【解决方案1】:

    componentManufacture 可以设置为零以将其视为通配符(componentTypecomponentSubType 也可以)。

    //Show all available AUHAL devices
    // Create description
    AudioComponentDescription test_desc;
    test_desc.componentType = kAudioUnitType_Output;
    test_desc.componentSubType = kAudioUnitSubType_HALOutput;
    test_desc.componentManufacturer = 0;
    test_desc.componentFlags = 0;
    test_desc.componentFlagsMask = 0;
    

    此外,您对AudioComponentFindNext 的使用是错误的,因为第一个参数始终传递nil。第一个参数应该是您希望开始搜索的组件。第一次传递 nil,第二次传递第一次调用的结果,以此类推。

    AudioComponent test_comp = nullptr;
    
    for (UInt32 i = 0; i < count; i++)
    {
        test_comp = AudioComponentFindNext(test_comp, &test_desc);
        ...
    }
    

    【讨论】:

    • 感谢您的信息!它有帮助 - 我会告诉你一点 - 但不能解决问题:仍然找不到音频组件。我已经尝试过这种方式,我尝试通过将 kAudioOutputUnitProperty_CurrentDevice 设置为其 ID 来初始化组件(可能是设备输入部分的 ID 而不是输出)。我还查看了 AVCaptureDevice(仅限输入)和 AVAudioSession(仅限 iOS),但似乎没有任何效果。
    猜你喜欢
    • 2016-10-20
    • 1970-01-01
    • 2013-12-08
    • 2020-09-28
    • 1970-01-01
    • 2020-05-22
    • 2011-11-05
    • 1970-01-01
    • 2013-03-29
    相关资源
    最近更新 更多