【发布时间】:2019-08-06 15:27:34
【问题描述】:
我正在尝试将AVAudioUnitEffect 连接到AVAudioEngine 的实例,如下所示:
required init(inputFormat: AVAudioFormat, outputFormat: AVAudioFormat, andAVAudioEngine avAudioEngine:AVAudioEngine) {
self.inputFormat = inputFormat
self.outputFormat = outputFormat
self.avAudioEngine = avAudioEngine
self.myAudioUnit = MyAVAudioUnit()
super.init()
avAudioEngine.attach(myAudioUnit)
avAudioEngine.connect(myAudioUnit, to: avAudioEngine.outputNode, format: self.inputFormat)
}
总体类只是NSObject 的子类,MyAudioUnit 是AVAudioUnitEffect 的子类。
在看似随机的时间,这个初始化器的最后一行(对connect的调用)会抛出一个带有以下错误的SIGABRT:com.apple.coreaudio.avfaudio: error -10875
相当于kAudioUnitErr_FailedInitialization。
谁能解释一下这个错误以及这里可能发生了什么?我认为MyAVAudioUnit 的初始化程序可能失败了,但它的内部初始化程序 (init(audioComponentDescription: AudioComponentDescription)) 不会抛出任何错误并且具有非可选的返回类型。有没有其他人遇到过这个特殊错误?
更新
这里是inputFormat的初始化:
guard let stereoFormat = AVAudioFormat(commonFormat: .pcmFormatFloat32,
sampleRate: 44100,
channels: 2,
interleaved: false) else {
return
}
let numChannels = UInt32(10)
guard let multiChannelLayout = AVAudioChannelLayout(layoutTag: kAudioChannelLayoutTag_Unknown | numChannels) else {
return
}
inputFormat = AVAudioFormat(commonFormat: stereoFormat.commonFormat,
sampleRate: stereoFormat.sampleRate,
interleaved: stereoFormat.isInterleaved,
channelLayout: multiChannelLayout)
MyAVAudioUnit 包含一个额外的自定义参数 (volumeParameter),并按如下方式初始化:
required override init() {
var componentDescription = AudioComponentDescription()
componentDescription.componentType = kAudioUnitType_Effect
componentDescription.componentSubType = xxxxx
componentDescription.componentManufacturer = xxxxx
componentDescription.componentFlags = 0
componentDescription.componentFlagsMask = 0
AUAudioUnit.registerSubclass(MyAVAudioUnit.self,
as: componentDescription,
name:"MyAVAudioUnit",
version: UInt32.max)
super.init(audioComponentDescription: componentDescription)
guard let paramTree = self.auAudioUnit.parameterTree else { return }
volumeParameter = paramTree.value(forKey: "volumeParameter") as? AUParameter
}
【问题讨论】:
-
你传入什么样的
inputFormats? -
您能显示
MyAVAudioUnit或直接用未分类的AVAudioUnitEffect复制吗? -
@RhythmicFistman 更新了原始问题。感谢您的观看。
-
没问题 - 让 10 频道
AVAudioFormat正常工作做得很好。你能进一步简化复制吗?如果没有参数,问题是否会重现?用立体声而不是 10 声道?使用内置音频单元而不是自定义?一个可运行的 sn-p 会很棒。 -
音频引擎最近停止了吗?调用停止后,您是否等待了足够长的时间? (实际上不是同步的)
标签: ios swift audiounit avaudioengine