[Portaudio] underruns, fix

Glenn Maynard g_paud@zewt.org
Mon, 18 Nov 2002 22:38:25 -0500


I noticed some curious skips that only occured with *large* buffer
sizes, especially when I turn off sound acceleration.  DSound
implementation.  I think this is what's happening:

Buffers of 100000 bytes each.  (Large number for effect; it happens
with 4096-frame buffers at 44khz.)  This is some large amount of time,
so Pa_GetMinNumBuffers always returns 2;o PA creates 2 user buffers,
which total 200000 bytes.

State at the time of a timer call:
 playCursor = 95000
 dsw_WriteOffset = 0

This means we only have 95000 bytes available to write in, which is less
than a buffer chunk (100000), so on this timer call, nothing is written at
all.  We won't get another chance until the playCursor is somewhere around
195000--and our write cursor will still be at 0, so we're too close
and end up underrunning.

It seems like the timer event should happen every half buffer, instead
of every buffer; in this case, that'll cause it to trigger when
playCursor is somewhere around 145000, and give us a chance to fill the
buffer.

It'd be better to reschedule the timer event when this happens, so it gets
called again as soon as possible after we have enough space to fill a
buffer; that way, if the callback is expensive, it won't occasionally
have only half the normal time to operate. I'm not sure how to do
that with the timers PA uses in DSound.

-- 
Glenn Maynard