Mac音频聚合设备通道数异常问题求助(麦克风模式切换时)
问题:语音隔离模式下聚合音频设备输入通道数异常
现象描述
将一台4进4出的硬件设备与一台8进8出的虚拟设备组合为聚合设备,使用SimplyCoreAudio库获取通道数:
- 当程序MicrophoneMode设为standard时,通道数显示正常:
aggregationDevice!.channels(scope: .input) =>> 12 aggregationDevice!.channels(scope: .output) =>> 12 - 切换为voiceIsolation模式时,输入通道数异常变为4,输出通道数仍为12:
aggregationDevice!.channels(scope: .input) =>> 4 aggregationDevice!.channels(scope: .output) =>> 12
聚合设备创建代码
func createAggregateDevice(mainDevice: AudioDevice, secondDevice: AudioDevice?, named name: String, uid: String) -> AudioDevice? { guard let mainDeviceUID = mainDevice.uid else { return nil } var deviceList: [[String: Any]] = [ [ kAudioSubDeviceUIDKey: mainDeviceUID, kAudioSubDeviceDriftCompensationKey:1 ] ] // make sure same device isn't added twice if let secondDeviceUID = secondDevice?.uid, secondDeviceUID != mainDeviceUID { deviceList.append([ kAudioSubDeviceUIDKey: secondDeviceUID, kAudioSubDeviceDriftCompensationKey:1, kAudioSubDeviceInputChannelsKey:8 ]) } let desc: [String: Any] = [ kAudioAggregateDeviceNameKey: name, kAudioAggregateDeviceUIDKey: uid, kAudioAggregateDeviceSubDeviceListKey: deviceList, kAudioAggregateDeviceMainSubDeviceKey: mainDeviceUID, kAudioAggregateDeviceIsPrivateKey:false, ] var deviceID: AudioDeviceID = 0 let error = AudioHardwareCreateAggregateDevice(desc as CFDictionary, &deviceID) guard error == noErr else { return nil } return AudioDevice.lookup(by: deviceID) }
问题原因
- 语音隔离模式的系统限制:Voice Isolation是Apple针对语音输入优化的降噪模式,系统会强制将输入通道限制为主设备的基础通道数(这里主设备是4进4出,因此被限制为4)。该模式通过系统音频管道对输入做过滤处理,会直接忽略聚合设备中虚拟设备的额外输入通道。
- 聚合设备配置优先级:当前创建聚合设备时,仅为虚拟设备指定了
kAudioSubDeviceInputChannelsKey:8,但Voice Isolation模式会覆盖聚合设备的通道配置——系统默认将硬件主设备视为语音输入的唯一有效来源,虚拟设备的输入通道在该模式下被屏蔽。 - 通道数获取逻辑:SimplyCoreAudio库获取的是系统当前激活的可用通道数,当Voice Isolation启用时,系统动态调整了聚合设备的输入通道集合,仅保留主设备的4个输入通道,导致返回值异常。
内容的提问来源于stack exchange,提问作者user22997196
相关产品推荐
相关产品推荐

