0

I've got crash with this code

//  ViewController.swift
import UIKit
import AVFoundation
class ViewController: UIViewController {
    var engine:AVAudioEngine!
    var EQNode:AVAudioUnitEQ!

    override func viewDidLoad() {
        engine.reset()
        let Format = engine.inputNode.outputFormat(forBus: 0)

        print("channelcount:",engine.inputNode.inputFormat(forBus: 0).channelCount)

//----->Start CRASH App stoped here
        engine.connect(engine.inputNode, to: EQNode, format: Format)
        engine.connect(EQNode, to: engine.mainMixerNode, format: Format)

        var error: NSError?
        engine.prepare()
        print("done prepare")
        do {
            try engine.start()
        } catch {
            print(error)
        }
        print("done start")
    }
}

And if I change Format to nil it make my app not working but not crash. All of this work perfectly fine on Xcode simulator with no error. But in the real iOS device (I use iPad 2019) test it crash.

Detail about my app: Live microphone adjust in Equalizer and display Equalized sound real-time.

ERROR:

SelfhearEQ[3532:760180] [aurioc] AURemoteIO.cpp:1086:Initialize: failed: -10851 
    (enable 1, outf< 2 ch,      0 Hz, Float32, non-inter> inf< 1 ch,  44100 Hz, Float32>)

channelcount: 0
2019-10-22 18:01:29.891748+0700 SelfhearEQ[3532:760180] [aurioc] AURemoteIO.cpp:1086:Initialize: failed: -10851 
(enable 1, outf< 2 ch,      0 Hz, Float32, non-inter> inf< 1 ch,  44100 Hz, Float32>)
2019-10-22 18:01:29.892326+0700 SelfhearEQ[3532:760180] [avae]            
    AVAEInternal.h:76    required condition is false: [AVAudioEngineGraph.mm:2127:_Connect: (IsFormatSampleRateAndChannelCountValid(format))]
2019-10-22 18:01:29.896270+0700 SelfhearEQ[3532:760180] *** Terminating app due to uncaught exception 'com.apple.coreaudio.avfaudio', reason: 'required condition is false: IsFormatSampleRateAndChannelCountValid(format)'

1 Answers1

0

I found the answer for this it nothing about formatting causing this error. Check it out on my other question it fixed. avaudioengine-connect-crash-on-hardware-not-simulator