AVAudioConverter 在 iOS 10 中损坏

AVAudioConverter is broken in iOS 10

AVAudioConverter 在 iOS 10 中似乎已损坏。代码在 iOS 9 中有效,现在

错误域=NSOSStatusErrorDomain 代码=-50“(空)”

无论使用何种音频格式都返回。每年都让我感到惊讶,基本的图书馆功能停止工作。

func audioConverterFailureIOS10() {
    // Describe the audio format
    let inFormat = AVAudioFormat(standardFormatWithSampleRate: 44100, channels: 2)
    let outFormat = AVAudioFormat(standardFormatWithSampleRate: 22050, channels: 2)

    // Allocate buffers
    let outBuffer = AVAudioPCMBuffer(pcmFormat: outFormat, frameCapacity: 1024)

    // Create an input block that is called when the converter needs input
    let inputBlock : AVAudioConverterInputBlock = { (inNumPackets, outStatus) -> AVAudioBuffer? in
        // Fails before entering here
        return nil
    }

    // Create the audio converter
    let converter = AVAudioConverter(from: inFormat, to: outFormat)

    var error : NSError?
    _ = converter.convert(to: outBuffer, error: &error, withInputFrom: inputBlock)

    // Error Domain=NSOSStatusErrorDomain Code=-50 "(null)"
    print(error)
}

原来outBuffer的frameLength必须设置为frameCapacity。默认情况下,长度为 0 并且在 iOS 10

上明显不同