[Portaudio] underruns, fix
Tue, 19 Nov 2002 12:50:11 -0800
> 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
I agree. For the case where there are only two user buffers, there is a
potential for underrun.
Generally one would use a larger number of smaller buffers, eg. 10 buffers
of 512 frames. In this case, one interrupt per buffer works fine.
Also note that the code in PaHost_StartEngine() will not allow a sleep for
more than 100 msec. So for 100000 bytes (25000 frames of 16 bit stereo) you
would have at least 5 interrupts per user buffer. So there is plenty of
opportunity to catch the buffer at an ideal time.
I experimented with setting the buffer size to 4096 in "debug_sine.c". I
heard small glitch on startup. So I modified the pa_dsound.c file in the
V18-patch branch in CVS. It now wakes up twice per buffer if there are only
two buffers. This eliminated the glitch. I also tried adding a delay to the
callback in "debug_sine.c" but I get horrendous glitching. The only way I
could eliminate the glitching was by requesting 3 or more user buffers.
> 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.
That might be a good mod for V19.