I'm attempting to connect an AVAudioUnitEffect
to an instance of AVAudioEngine
like so:
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)
}
The overarching class is simply a subclass of NSObject
and MyAudioUnit
is a subclass of AVAudioUnitEffect
.
At seemingly random times, the last line of this initializer (the call to connect
) will throw a SIGABRT with the following error: com.apple.coreaudio.avfaudio: error -10875
Which amounts to kAudioUnitErr_FailedInitialization
.
Can anyone shed some light on this error and what might be going on here? I thought that maybe the initializer for MyAVAudioUnit
was failing, but its internal initializer (init(audioComponentDescription: AudioComponentDescription)
) does not throw any errors and has a non-optional return type. Has anyone else had any experience with this particular error?
UPDATE
Here is the initialization of 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
contains one additional custom parameter (volumeParameter
) and is initialized as such:
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
}
inputFormat
s are you passing in? – BefallMyAVAudioUnit
or reproduce directly with an unsubclassedAVAudioUnitEffect
? – BefallAVAudioFormat
working. Can you simplify the repro further? Does the problem reproduce without the parameter? With stereo instead of 10 channel? With a built-in audio unit instead of custom? A runnable snippet would be great. – Befall