vadymmarkov / Beethoven

:guitar: A maestro of pitch detection.
https://github.com/vadymmarkov
Other
824 stars 146 forks source link

Crash upon engine start #67

Open hannah-bennett opened 5 years ago

hannah-bennett commented 5 years ago

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

vadymmarkov commented 5 years ago

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.

paskowski commented 5 years ago

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

hannah-bennett commented 5 years ago

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.

OfTheWolf commented 5 years ago

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
logsol commented 1 year ago

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