ios - Latency in plotting microphone input -
i using avfoundation in order microphone input , ezaudio plot microphone input. have stripped down code basic , still latency, weird. code:
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 tap on main mixer. mainmixer.installtaponbus(0, buffersize: buffersize, format: mainmixer.inputformatforbus(0)) { (buffer: avaudiopcmbuffer!, time: avaudiotime!) -> void in //change buffer size 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) }
am doing wrong?