【问题标题】:How to get right AVAudioFormat for connecting nodes如何为连接节点获取正确的 AVAudioFormat
【发布时间】:2019-10-22 11:09:32
【问题描述】:

这段代码我崩溃了

//  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")
    }
}

如果我将 Format 更改为 nil,它会使我的应用程序无法运行但不会崩溃。 所有这些在 Xcode 模拟器上都可以正常工作,没有错误。 但是在真正的 iOS 设备(我使用 iPad 2019)中测试它会崩溃。

关于我的应用程序的详细信息:在均衡器中调整实时麦克风并实时显示均衡的声音。

错误:

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)'

【问题讨论】:

    标签: ios swift avfoundation avaudioengine


    【解决方案1】:

    我找到了答案,它与导致此错误的格式无关。 看看我解决的另一个问题。 avaudioengine-connect-crash-on-hardware-not-simulator

    【讨论】:

      猜你喜欢
      • 2021-08-08
      • 1970-01-01
      • 1970-01-01
      • 2017-12-15
      • 1970-01-01
      • 2017-01-07
      • 2019-11-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多