views:

182

answers:

2

There is a very common software bug that causes about 1 second of audio to be played a few times in succession, creating a kind of stutter. I notice this most often when playing video games. I know this is not architecture specific, I have seen it happen in consoles, in old PC's and it just happened 5 minutes ago when I booted windows 7.

My question is what is the root cause of this inconsistency? Does this type of inconsistency affect other parts of computing? For instance if a modem stuttered then the transmission would be corrupted.

+2  A: 

As a guess, I suspect it's because the audio buffer isn't being updated quickly enough and hence it's simply replaying the stale data that's in the buffer.

That said, I'd like to think someone here will be able to delve much deeper than that. :-)

middaparka
It's exactly that: A buffer underrun. Most likely the OS has more important things to do than updating the internal sound-buffer.
Nils Pipenbrinck
+8  A: 

Sound is commonly output using a circular buffer, which is then handled by the hardware and driver. That way, you don't have to output a single sample every 0,02 milliseconds or so, but can get more done at once. That also means the game can spend some more time running the game logic without constantly interrupting itself to decode a new sample. When the game finishes running an iteration in the game logic and the game state is updated and the graphics have been redrawn, the game can then decode more samples.

The problem arises if doesn't finish quickly enough - this could be because there is suddenly a lot more work it needs to do, or because other processes steal too much CPU time. If the buffer isn't filled, then the sound card will just continue to read from the buffer - and when it has read all of the buffered samples, the next samples are those it has already played. This results in the small loop you have seen.

Michael Madsen
+1 That's the much deeper delve I was expecting. :-)
middaparka