在 XNA 4 中为图形输出添加恒定延迟
有谁知道向 XNA 4 应用程序的图形输出添加恒定延迟(约 30 毫秒)的简单方法?
我想让我的图形输出与实时缓冲的音频流保持同步,而实时缓冲的音频流本质上具有恒定的延迟。
感谢您对此的任何想法!
最大限度
does anyone know of an easy way to add a constant latency (about 30 ms) to the graphical output of an XNA 4 application?
I want to keep my graphical output in sync with a real-time buffered audio stream which inherently has a constant latency.
Thanks for any ideas on this!
Max
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您确实需要延迟图形,那么您可以将游戏渲染到一系列循环渲染目标。因此,在帧 n 上,您将显示在帧 n-2 处渲染的帧。这仅适用于较小的延迟,并且需要大量额外的图形内存和少量的额外 GPU 时间。
一个更好的方法是根本不延迟图形输出,而是延迟用于生成图形输出的音频。通过缓冲它或在音频缓冲区中有两个读取位置。 “音频”读取比“游戏”读取早 X 毫秒(延迟)。
因此,如果您计算机的音频硬件有 100 毫秒 的延迟(并不罕见),并且您的图形硬件有 16 毫秒 的延迟:当您以 100 毫秒输入样本时进入音频系统,您将16ms的音频样本输入到图形计算中。与此同时,0ms 的音频传到扬声器,匹配的图形也传到屏幕上。
显然,如果生成图形输出的东西也生成音频,那么这将不起作用。但这两种方法的一般原理是,您必须在图形链上的某个位置缓冲输入,以便引入与您遇到的音频延迟相对应的延迟。沿着这条链,最容易插入缓冲区的位置取决于您。
对于 <100 毫秒的延迟,对于大多数游戏我都不会担心。您只真正关心音频程序和节奏游戏的这种延迟。
If you really need to delay your graphics, then what you could do is render your game to a cycling series of render-targets. So on frame n you display the frame you rendered at frame n-2. This will only work for small latencies, and requires a large amount of additional graphics memory and a small amount of extra GPU time.
A far better method is not to delay the graphical output at all, but delay the audio that is being used to generate the graphical output. Either by buffering it or having two read positions in your audio buffer. The "audio" read being X ms (the latency) ahead of the "game" read.
So if your computer's audio hardware has 100ms of latency (not uncommon), and your graphics hardware has a latency of 16ms: As you are feeding the sample at 100ms into the audio system, you are feeding the audio sample at 16ms into the your graphics calculation. At the same time, the audio from 0ms is hitting the speakers, and the matching graphic is hitting the screen.
Obviously this won't work if the thing generating the graphical output is also generating the audio. But the general principal of both these methods is that you have to buffer the input somewhere along your graphics chain, in order to introduce a delay that corresponds to the one you are experiencing for audio. Where along that chain it is easiest to insert a buffer is up to you.
For latencies of <100ms, I wouldn't worry about it for most games. You only really care about this kind of latency for audio programs and rhythm games.
我可能不明白这个问题,但是你不能跟踪 update 被调用了多少次以及 mod 2 吗? 60fps mod 2 是 30...
I might not understand the question, but couldn't you keep track of how many times update is called and mod 2? 60fps mod 2 is 30...