[wdmaudiodev] DirectSound glitch detection/correction woes.

  • From: "Jerry Evans" <jerry@xxxxxxxxxx>
  • To: <wdmaudiodev@xxxxxxxxxxxxx>
  • Date: Tue, 25 Nov 2003 02:18:59 -0000

If this is verboten/rude in this list, please let me know.

We've developed a practice/learning app called Riffster that uses DirectSound 
for playback. 

I've had a devil of a job getting the sound system to:

a) successfully detect buffer overrun/underrun conditions
b) successfully recover from the same

The simplest strategy I have evolved (mostly) works as follows:

Wait for a notification from DirectSound
Get current read position using GetPosition(...)
If the current read position is 'less' than the end of the next sub-buffer to 
write then adjust the write position such that it is 180 degress away from the 
current read position. (It is helpful to keep a picture of the DS circular 
buffer in mind here ...)
Lock, write and Unlock the play buffer
Wait again ...

The notion is that when collisions occur we suffer one large'ish glitch rather 
than handle a series of smaller ones in the near future.

Even at this late stage a colleague has been reporting serious breakup in the 
audio chain on a Dell notebook with an on-board Crystal sound system. The 
problem seems to have been cured with a driver update.  Ominously the older 
driver version appeared to return garbage numbers from GetPosition() from time 
to time.

Given that Riffster does realtime pitch and tempo transposition we want to have 
the lowest possible latency. On a 2.4GHz Pentium 4 with a USB sound module (the 
ever faithful Roland UA-20) and Windows XP SP1 Riffster runs very well with 4KB 
sub-buffer sizes. It will glitch only when I whizz an old DOS app around over 
the display. The defaults are less ambitious, having 8 notification points each 
handling a 32KB sub-buffer.

I am concerned we may end up in a nightmare with users complaining of appalling 
audio quality which we cannot detect, far less replicate and fix.

If anyone would be interested in trying the app on their hardware please email 
me. The quid pro quo is that if you can find and detail any hardware/driver 
related problems (and want the app of course) we'll send you a registered copy 
gratis. Note this may involve trying out one or more debug builds ...

Further product details & polemic are at 

Many thanks.


Other related posts:

  • » [wdmaudiodev] DirectSound glitch detection/correction woes.