PDA

View Full Version : Vista WaveOutWrite latency


Phil Steinmeyer
10-27-2006, 11:05 AM
So I installed Vista RC 1, which was a pain for other reasons I won't go into here...

My game seems ok, with one glaring exception:

I'm getting stuttering on my sound/music. I'm using WaveOutWrite, rather than DirectSound or anything like that.

Usually this is a case of audio buffers being too small, and sure enough, if I doubled them, the problem goes away. But that, in turn, makes my audio quite laggy.

Basically, I use 3 buffers of 1024 samples each, and my playback is 22050 Hz. Assuming the 'playing buffer' is half done, on average, my latency is 2.5 * 1024 *1000 / 22050, or 116 ms on average, plus whatever time it takes for Windows to actually put the data to the hardware.

To solve the stuttering, I had to double my buffers to 2048 samples, bumping up latency from a barely noticeable 116 ms to a rather noticeable 232 ms.

I logged my audio thread, and I'm averaging calling it every ~20 ms, with a max time between calls of 32 ms. This is the same on my Vista machine as my XP machine, and the latter works fine with the smaller buffers.

In theory, the smaller buffers should be ok as long as my time between calls to my audio thread never exceeds 2.0 * 1024 *1000 / 22050, or 93 ms. Since I'm actually at a max of 32 ms, I should be ok, with a fair amount of 'headroom' here.

So, it would appear that rather than being something on my side of the fence (i.e. my app failing to fill buffers in time), it appears to be something on Windows Vista's side of the fence - it just doesn't like the small buffers.

Anybody else run into this and have insight/fixes for it?

mot
10-27-2006, 11:49 AM
Isn't RC1 a bit old? I would try it on RC2 first. It may be buggy Vista soundcard drivers or something, I wouldn't worry too much anyway. And how's the overall CPU load when you run your game?

Phil Steinmeyer
10-27-2006, 11:56 AM
I think you're thinking of beta 1 versus beta 2 - pretty sure there's only been one R.C. I just downloaded it from MS last night.

Anyways, oddly enough, in trying to debug this further, I discovered that putting a call to waveOutGetPosition in my code resolves the issue. It SHOULDN'T have any effect - all it does is read the current position of the audio buffer, and yet, it resolves it.

Odd.

MikeRozak
10-27-2006, 10:49 PM
Having worked on sound card drivers once upon a time, I might be able to shed some light on this....

Theory #1: Your sound card/chip either has DMA access into a small ping-pong buffer on your CPUs memory, or there's a way to upload a small bit of data onto the sound card/chip. The problem you're experiencing is probably (but not necessarily) because of a change to the sound card driver that causes it to use a larger ping-pong buffer. If this is the case, the new version of windows (probably and technically) isn't the issue.

Theory #2: From what I know, all the waveOutXXX() code has been mapped into DirectX calls for several versions of windows. It could be that the mapping code has a larger ping-pong buffer... which means Windows is at fault.

Solution: Either larger buffers (as you've done), or DirectX.

mot
10-27-2006, 11:54 PM
I think you're thinking of beta 1 versus beta 2 - pretty sure there's only been one R.C. I just downloaded it from MS last night.

There was a RC2, perhaps not official. http://www.winsupersite.com/showcase/winvista_5744.asp RC1 was build 5600, this is build 5744.