4klang syncing and latency
category: code [glöplog]
So, I'm working on a new 4k, and we'll be using 4klang for music. To sync, I need to get the current time into the music.
I've used waveGetOutPosition() so far, but noticed that there's some latency that it doesn't seem to take into account, and which varies depending on the load my computer is under (lower resolution => lower latency, higher resolution => higher latency).
So, how are you people syncing to 4klang? Maybe using the env/note buffers would help, but I really need the current time, and not events.
I've used waveGetOutPosition() so far, but noticed that there's some latency that it doesn't seem to take into account, and which varies depending on the load my computer is under (lower resolution => lower latency, higher resolution => higher latency).
So, how are you people syncing to 4klang? Maybe using the env/note buffers would help, but I really need the current time, and not events.
Isn't it just latency on your rendering pipeline - like the command buffer holding several frames...
You'll probably need something to synchronize the renderer (which takes space..)
You'll probably need something to synchronize the renderer (which takes space..)
Hmm perhaps, but I don't really have much latency I have introduced myself. If so, the latency should be in the OpenGL driver or something, I just render a frame, wglSwapLayerBuffers(), then render the next one. But yeah, I guess I could correct for the latency incurred by rendering 1 frame.
Maybe stuff like glFlush() and/or wglSwapInterval(0) would help.
There's a limit to how many frames the GPU can render in advance. Might not be just 1...
Thanks guys, I now have perfect sync with glFinish() and adding two times the frame time to the current time (to try to account for double buffering, which I still do want)! And glFinish doesn't seem to have affected performance.
glFinish is a quite drastic solution - forcing a synchronization by reading out a result of the previous render would be better.
Can't quite remember, but doesn't opengl have a simple single-call method for reading out a (few) pixel from the backbuffer - then do that right after the swap. (thus waiting for the result of the previous frame, not the one just presented). And then still offset by frametimes.
Can't quite remember, but doesn't opengl have a simple single-call method for reading out a (few) pixel from the backbuffer - then do that right after the swap. (thus waiting for the result of the previous frame, not the one just presented). And then still offset by frametimes.
Yeah, glReadPixels. That could work. I could benchmark a bit and see if it's faster than glFinish. Using glReadPixels would likely use more bytes, however, as it needs some arguments.
However, I didn't see any visible drop in fps when using glFinish. But I didn't do any measurements.
Afair glReadPixels might or might not block execution. it depends if it needs to swizzle BGRA to RGBA or something...
Will try it on Sunday.
glFinish() before every wglSwapLayerBuffers() actually doesn't seem to carry any performance penalty in my case (and I have the same GPU as the compo hw). I'll keep it as is for the party version.