downsampling in AVAudioEngine graph

Hi,


I'm trying to configure AVAudioEngine for downsampling, by inserting an AVAudioUnit with the following description:

let resamplerDescr = AudioComponentDescription(componentType: kAudioUnitType_FormatConverter,
                                                   componentSubType: kAudioUnitSubType_AUConverter,
                                               componentManufacturer: kAudioUnitManufacturer_Apple,
                                               componentFlags: 0, componentFlagsMask: 0)


to the graph:

    let engine = AVAudioEngine()
    let inputNode = engine.inputNode
    inputNode.isVoiceProcessingAGCEnabled = false
    inputNode.isVoiceProcessingBypassed = true
    engine.attach(auNode)
    let inputFormat = inputNode.outputFormat(forBus: 0)
    let adaptFormat = AVAudioFormat(standardFormatWithSampleRate: _sampleRateHz, channels: 2)!
    engine.attach(resampler)
    engine.connect(inputNode, to: resampler,
     format: inputNode.outputFormat(forBus: 0))
    engine.connect(resampler, to: auNode, format: adaptFormat)


auNode does some custom processing assuming the custom sample rate. Rest of graph construction was skipped.

The problem is that as soon as resampler is inserted into the graph the app crashes on engine start crash like this:

[avae]            AVAEInternal.h:76    required condition is false: [AVAudioEngineGraph.mm:798:InitializeActiveNodesI
nInputChain: (false == isInputConnToConverter)]
*** Terminating app due to uncaught exception 'com.apple.coreaudio.avfaudio', reason: 'required condition is false: false == isInputConnToConverter'


What I'm doing wrong here? What is the recommended way to downsample in AVAudioEngine graph?