http://bugs.winehq.org/show_bug.cgi?id=28723
--- Comment #75 from Alexey Loukianov mooroon2@mail.ru 2011-12-08 11:16:14 CST --- (In reply to comment #74)
pump-out 2*alsa_period audio data in advance
How? Rage only gives you 10ms and you cannot predict the future.
Well, we can "predict" with a pretty high probability that if an app acquire some pointers to WASAPI COM interfaces, calls IAC_Initialize() followed by IAC_Start() - it's going to playback some sound :-). Making small alsa_period a hard requirement would left behind an unfortunate user whose hardware is not capable of using small periods. IMO it'd be better to still have sound produced but lagging way behind (due to 2*alsa_period lead-in silence chunk) than not to have sound at all. Yes, we would need to pump-out 2*alsa_period lead-in silence again in case of xrun but as we're talking about case when ALSA isn't capable of using small periods - chances to hit xrun are pretty slim. And yes, if the minimal period that device supports is - say - 1s, then it would end up in sound lagging 2s at the worst case (and slightly more than 1s at best). It's bad, but it's still better than having no sound at all. Of course we should warn user loudly in such case.
I've read that PulseAudio uses snd_pcm_rewind to overwrite (when mixing) already written data with new samples. You could try out that route however my experience with seeking with snd_pcm_forward is bad, see bug #28517.
No-no-no-no-no, it is "not a way to go". I've seen vast amount of different failures caused by bugs in various parts of ALSA (kernel drivers, alsalib, plugins and so on) which arise when you try to use rewind/forward. Using these would introduce more problems (esp. on older systems like CentOS 4 or 5) than it's expected to solve.
PS. BTW, in bug #28517 you had mentioned the following test case: "...I've been thinking about an audible test with two streams with 180° phase delta not written at the same time, yet they should all enter the same 10ms period and might annihilate themselves...". I'm thinking about trying to implement it this weekend. It'd be pretty curious to take a look at the results :-).