http://bugs.winehq.org/show_bug.cgi?id=28284
--- Comment #4 from Jörg Höhle hoehle@users.sourceforge.net 2011-09-08 10:26:48 CDT --- I can confirm the loss of sound and occasional crackling. However, it has little to do with the patch you isolated. The patch is correct but there's a bug somewhere else. It seems to be some obscure race condition or similar kind of bug. There are 2 threads calling WOD_PushData on the same handle, one on behalf of the app (or rather dsound), one internal to winmm.
I've replaced the former calls to StartDevicesThread in waveOutWrite, waveOutPause and waveOutRestart by code that does nothing *except* shortly take a critical section and round trip to the server:
EnterCriticalSection(&g_devthread_lock); if (WAIT_TIMEOUT!=WaitForSingleObject(g_devices_thread, 0)) ERR("never ever seen because thread is running fine\n"); LeaveCriticalSection(&g_devthread_lock);
Apparently, this is enough to serialize the calls such that Wine does not get confused (at least not within 5 mins of testing).
Now why and where does Wine get confused? I don't know.