Beethoven icon indicating copy to clipboard operation
Beethoven copied to clipboard

Crash upon engine start

Open hannah-bennett opened this issue 5 years ago • 5 comments

I am getting multiple instances of the same fatal exception, across iOS 12 and 13.

Fatal Exception: com.apple.coreaudio.avfaudio
required condition is false: IsFormatSampleRateAndChannelCountValid(format)

The app is crashing when the pitch engine starts. Here is the relevant code:

private let engine = PitchEngine()

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    engine.start()
}

I found a stack overflow post referencing this crash, but it seems to be marginally helpful at best.

I dug around a bit in the Beethoven code, and traced this engine.start() call back to the audio session setup:

https://github.com/vadymmarkov/Beethoven/blob/master/Source/SignalTracking/Units/InputSignalTracker.swift#L41

Is this something you've seen before? Any ideas on how to resolve? Thanks

hannah-bennett avatar Aug 30 '19 19:08 hannah-bennett

I haven't experienced this, but you can try one of the solutions from that stack overflow post, such as replacing node.outputFormat(forBus: 0) with AVAudioFormat, and make a pull request if it fixes your issue.

vadymmarkov avatar Sep 02 '19 07:09 vadymmarkov

@hannah-bennett I guess you're getting this error when using simulator, try to run your code on an actual device

paskowski avatar Sep 03 '19 08:09 paskowski

Thanks for the response. These are device crashes, not simulator crashes. I'll dig into it and see if I can pinpoint what's going on.

hannah-bennett avatar Sep 03 '19 13:09 hannah-bennett

you should call removeTap before install. Give it a try.

InputSignalTracker.swift

  func start() throws {
    ...
    inputNode.removeTap(onBus: bus)
    let format = inputNode.outputFormat(forBus: bus)
    inputNode.installTap(onBus: bus, bufferSize: bufferSize, format: format) { buffer, time in

OfTheWolf avatar Sep 29 '19 22:09 OfTheWolf

Wouldn't it make more sense to set inputNode.inputFormat() instead of inputNode.outputFormat?

logsol avatar Mar 08 '23 11:03 logsol