I have written the following AVAudioEngine code that initializes one of my custom AUAudioUnit
subclasses and wires it up to the main mixer node of the engine.
class AudioEngine {
let engine = AVAudioEngine()
init() {
let sess = AVAudioSession.sharedInstance()
try! sess.setCategory(AVAudioSessionCategoryPlayback)
try! sess.setActive(true)
let desc = AudioComponentDescription(componentType: kAudioUnitType_Generator, componentSubType: 0x00000001, componentManufacturer: 0x00000002, componentFlags: 0, componentFlagsMask: 0)
AUAudioUnit.registerSubclass(MyAudioUnit.self, as: desc, name: "MyAudioUnit", version: 2)
let format = engine.outputNode.outputFormat(forBus: 0)
engine.connect(engine.mainMixerNode, to: engine.outputNode, format: format)
AVAudioUnit.instantiate(with: desc, options: []) { (audiounit, error) in
guard let au = audiounit else { return }
self.engine.attach(au)
let stereoFormat = AVAudioFormat(standardFormatWithSampleRate: format.sampleRate, channels: 2)
// CRASHES HERE
self.engine.connect(au, to: self.engine.mainMixerNode, format: stereoFormat)
do {
try self.engine.start()
} catch (let exceptionError) {
print(exceptionError)
}
}
}
}
On the line that says "CRASHES HERE", I get an exception and see:
2017-07-22 14:20:39.208951-0400 AUInProcessTest[26638:7238083] [avae] AVAEInternal.h:98:_AVAE_CheckSuccessAndNoNSError: [AUInterface.mm:512:SetFormat: ([[busArray objectAtIndexedSubscript:(NSUInteger)element] setFormat:format error:&nsErr])] returned false, error (null) 2017-07-22 14:20:39.217199-0400 AUInProcessTest[26638:7238083] *** Terminating app due to uncaught exception 'com.apple.coreaudio.avfaudio', reason: '[[busArray objectAtIndexedSubscript:(NSUInteger)element] setFormat:format error:&nsErr]: returned false, error (null)'
I'm not sure what this means.
User contributions licensed under CC BY-SA 3.0