绘制麦克风输入的延迟

时间:2015-04-09 20:27:19

标签: ios swift avfoundation avaudioengine ezaudio

我正在使用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)
}

我做错了吗?

0 个答案:

没有答案