0

我正在使用 AVFoundation 来获取麦克风输入,并使用 EZAudio 来绘制麦克风输入。我已将代码精简为非常基本的代码,但仍然会出现延迟,这很奇怪。这是代码:

override func viewDidLoad() {
    super.viewDidLoad()
    //Audio stuff
    let bufferSize: AVAudioFrameCount = 2048

    //plot properties
    bufferPlot.color = UIColor(red: 0.5, green: 0.0, blue: 0.0, alpha: 0)
    bufferPlot.backgroundColor = UIColor(red: 1.0, green: 1.0, blue: 1.0, alpha: 0)
    bufferPlot.plotType = .Buffer

    //instantiate nodes
    engine = AVAudioEngine()
    input = engine.inputNode
    mainMixer = engine.mainMixerNode
    //put a tap on the main mixer.

    mainMixer.installTapOnBus(0, bufferSize: bufferSize, format: mainMixer.inputFormatForBus(0)) { (buffer: AVAudioPCMBuffer!, time: AVAudioTime!) -> Void in

        //change buffer size to 2048
        buffer.frameLength = bufferSize

        //plotting
        dispatch_async(dispatch_get_main_queue(), { () -> Void in
            self.bufferPlot.updateBuffer(buffer.floatChannelData.memory, withBufferSize: UInt32(bufferSize))
        })
    }

    //start engine
    var error: NSErrorPointer = NSErrorPointer()
    engine.startAndReturnError(error)
}

难道我做错了什么?

4

0 回答 0