http://bugs.winehq.org/show_bug.cgi?id=28284
Summary: HoverAce: audio becomes distorted then it cuts out during races (Alsa=emulation) Product: Wine Version: 1.3.26 Platform: x86 URL: http://www.fileplanet.com/82880/80000/fileinfo/HoverRa ce-Demo OS/Version: Linux Status: UNCONFIRMED Severity: minor Priority: P2 Component: winmm&mci AssignedTo: wine-bugs@winehq.org ReportedBy: gyebro69@gmail.com CC: hoehle@users.sourceforge.net Regression SHA1: c7d0c093e5bc29da6163d2ef66542562ae7bafc2
Created an attachment (id=36240) --> (http://bugs.winehq.org/attachment.cgi?id=36240) terminal output
HoverAce is an arcade racing, released in 2003 by GSC Game World.
Symptom: after starting a race, audio begins to crackle (both music and sound effects). This usually happens right after starting a race, but sometimes I was able to play the game for 1 minute and the problem came up then. The crackling audio issue usually lasts for 5-10-15 seconds, afterwards all audio playback goes away and the game continues running silently.
The issue is only reproducible when Alsa is set to 'emulation' and it is still present in the current git (wine-1.3.27-270-gb7ea631). The problem doesn't happen in Wine-1.3.25 and the result of the regression test:
c7d0c093e5bc29da6163d2ef66542562ae7bafc2 is the first bad commit commit c7d0c093e5bc29da6163d2ef66542562ae7bafc2 Author: Jörg Höhle hoehle@users.sourceforge.net Date: Wed Jul 27 19:32:02 2011 +0200
winmm: Functions that take an open HWAVE don't need StartDevicesThread.
:040000 040000 237c4f2af36c22141a26170c4771092e7bce8b5f 733f8497b9e900585455bd46f17e59762d08196b M dlls
The patch can be reverted cleanly on wine-1.3.27-270-gb7ea631, and that fixed the problem.
The demo for the game is a so called compatibility test and it differs from the full game in several aspects, but the audio problem is reproducible in it.
Steps to reproduce the problem in the demo: 1) After a successful installation launch the demo by tntShell.exe (ignore the error message, related to directplay). 2) In the menu choose 'Begin new championship', then click on <Create Game>, <Start>. When the countdown ends, audio goes away.
Fedora 15 x86 Kernel 2.6.40.3-0.fc15.i686.PAE Alsa 1.0.24 Audio device: nVidia Corporation MCP61 High Definition Audio (rev a2)
http://bugs.winehq.org/show_bug.cgi?id=28284
GyB gyebro69@gmail.com changed:
What |Removed |Added ---------------------------------------------------------------------------- Keywords| |download, regression
--- Comment #1 from GyB gyebro69@gmail.com 2011-09-05 14:08:11 CDT --- Added some keywords.
http://bugs.winehq.org/show_bug.cgi?id=28284
--- Comment #2 from Jörg Höhle hoehle@users.sourceforge.net 2011-09-07 02:13:28 CDT --- Please add a +tid,+driver,+winmm,+dsound log (perhaps without dsound if it's large). Your terminal output shows that gstreamer is used. Is it essential to the bug or can it be reproduced without it, i.e. winegstreamer disabled?
How do these messages related to the crackling audio: fixme:gstreamer:watch_bus avidemux1: Internal data stream error. and later: err:dsound:DSOUND_callback Wave queue corrupted! [5 times] fixme:gstreamer:watch_bus avidemux2: Internal data stream error. Simultaneously? Only after audio went away?
http://bugs.winehq.org/show_bug.cgi?id=28284
--- Comment #3 from GyB gyebro69@gmail.com 2011-09-07 08:21:31 CDT --- Created an attachment (id=36272) --> (http://bugs.winehq.org/attachment.cgi?id=36272) 7zipped +tid,+winmm,+driver debug log (winegstreamer disabled, uncompressed 1.9 MB)
This is a +winmm,+driver debug log with winegstreamer disabled. If I add +dsound then the log size grows over 140 MB. I killed the game after audio went away. It seems winegstreamer is only used for playing the intro video and the small video animation in the upper right corner of the menus. These videos are encoded with Indeo codec and none of them work in Wine. Music and sound effects do work in-game with disabled winegstreamer.
err:dsound:DSOUND_callback Wave queue corrupted! appears in the console after audio went away.
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.
http://bugs.winehq.org/show_bug.cgi?id=28284
--- Comment #5 from Jörg Höhle hoehle@users.sourceforge.net 2011-09-08 10:31:06 CDT --- err:dsound:DSOUND_callback Wave queue corrupted! This is a separate bug in DSOUND_WaveQueue which should only increment device->pwqueue when waveOutWrite is successful. But why/when would waveOutWrite fail?
http://bugs.winehq.org/show_bug.cgi?id=28284
--- Comment #6 from Jörg Höhle hoehle@users.sourceforge.net 2011-09-21 02:36:37 CDT --- Created an attachment (id=36485) --> (http://bugs.winehq.org/attachment.cgi?id=36485) Fix stuttering at start (or near underrun)
Grmph, I observed the issue in Ubuntu Lucid, but not now in wine-1.3.28 with Intrepid.
Anyway, here's an important fix to mmdevapi ALSA and OSS. mmdevapi would play from the wrong buffer position.
http://bugs.winehq.org/show_bug.cgi?id=28284
--- Comment #7 from GyB gyebro69@gmail.com 2011-09-21 10:38:10 CDT --- (In reply to comment #6)
Created an attachment (id=36485)
--> (http://bugs.winehq.org/attachment.cgi?id=36485) [details]
Fix stuttering at start (or near underrun)
Grmph, I observed the issue in Ubuntu Lucid, but not now in wine-1.3.28 with Intrepid.
Anyway, here's an important fix to mmdevapi ALSA and OSS. mmdevapi would play from the wrong buffer position.
The patch didn't resolve the problem on my system. The stuttering issue as well as the complete loss of audio is still there in HoverAce, after your patch applied.
One more thing worth mentioning: the occurrence of the problem seems to depend on the optimization level used when compiling Wine from source. With CFLAGS=-O0 the problem is reproducible right after starting a race. Using -O2, the bug usually kicks in much later: I was able to play the game without the problem for 5-10 minutes when -O2 was used.
http://bugs.winehq.org/show_bug.cgi?id=28284
--- Comment #8 from Jörg Höhle hoehle@users.sourceforge.net 2011-09-21 20:07:49 CDT --- See bug #28464 for a race condition causing err:dsound:DSOUND_callback Wave queue corrupted!
Quick work-around: Do not call BeginPlaying from waveOutWrite. Instead, solely copy the stopped=> Start part therein, without WOD_PushData.
-O0 optimization level is likely a red herring, which abound with race conditions.
http://bugs.winehq.org/show_bug.cgi?id=28284
--- Comment #9 from Jörg Höhle hoehle@users.sourceforge.net 2011-09-22 08:56:48 CDT --- Created an attachment (id=36512) --> (http://bugs.winehq.org/attachment.cgi?id=36512) waveOutWrite: Delegate all writing to the audio feeder thread
This hack prevents concurrent writes by the audio feeder thread and waveOutWrite (which is used by DSound). See bug #28464. Please report.
http://bugs.winehq.org/show_bug.cgi?id=28284
--- Comment #10 from GyB gyebro69@gmail.com 2011-09-22 09:57:00 CDT --- (In reply to comment #9)
Created an attachment (id=36512)
--> (http://bugs.winehq.org/attachment.cgi?id=36512) [details]
waveOutWrite: Delegate all writing to the audio feeder thread
This hack prevents concurrent writes by the audio feeder thread and waveOutWrite (which is used by DSound). See bug #28464. Please report.
Is this patch intended to be used along with the previous one, or only this one should be tried? In the later case (only this patch applied), I'm not getting any audio output from games, when emulation is used (the Wine test sound does play correctly).
http://bugs.winehq.org/show_bug.cgi?id=28284
--- Comment #11 from GyB gyebro69@gmail.com 2011-09-22 11:53:43 CDT --- Games are completely missing audio when both patches applied (only when emulation is used; full hw. acceleration is still working). Either the patch is wrong...or today is not my lucky day :)
http://bugs.winehq.org/show_bug.cgi?id=28284
--- Comment #12 from Jörg Höhle hoehle@users.sourceforge.net 2011-09-22 12:52:47 CDT --- Indeed. Add to winealsa.drv/mmdevdrv.c:GetCurrentPadding *out = This->bufsize_alsa - avail_frames + This->held_frames; + ERR("avail %ld/%lu pos: %u held %u\n", avail_frames, This->bufsize_alsa, *out, This->held_frames); }else if(This->dataflow == eCapture){
and you'll see from lines like: warn:alsa:AudioClient_GetCurrentPadding Xrun detected err:alsa:AudioClient_GetCurrentPadding avail 3991/3763 pos: 0 held 0 where avail > buffer_size that the app entered an underrun. The underrun slowly grows: err:alsa:AudioClient_GetCurrentPadding avail 28017/3763 pos: 0 held 0
As I observed in wine-devel, ALSA plays silence during underruns. As there's no mechanism in Wine to recover from an underrun, sound appears lost.
It's lost until you get back to the menu, where waveOutPause is used, allowing to resync, so you hear the clicks again.
Without my patch, waveOutWrite apparently calls PushData early enough to prevent the underrun for some time. Random system load => delay => underrun.
Wine needs a mechanism to recover from underruns. I'll think of one, but don't hold your breath.
http://bugs.winehq.org/show_bug.cgi?id=28284
--- Comment #13 from Jörg Höhle hoehle@users.sourceforge.net 2011-09-23 03:52:47 CDT --- Created attachment 36519 --> http://bugs.winehq.org/attachment.cgi?id=36519 Make prefill work effectively
Please try out this patch in addition to the other ones. It decreases the likeliness of underruns as prefill is now correctly used to buffer data. Instead of the "delegate" hack, you may want to watch bug #28464 (recommended).
Please report back how the app behave for you with the 3 patches: 1. fix stuttering (already in git) 2. fix prefill in PushData 3. either "delegate to feeder" or "set WHDR_DONE / split queue"
http://bugs.winehq.org/show_bug.cgi?id=28284
--- Comment #14 from GyB gyebro69@gmail.com 2011-09-23 12:00:04 CDT --- wine-1.3.28-521-gb8f1b5a + patch:fix prefill in PushData + patch:set WHDR_DONE: the affected games are playing audio correctly (without stuttering and loss of audio).
http://bugs.winehq.org/show_bug.cgi?id=28284
Mateusz Stachowski mateusz.stachowski@wp.pl changed:
What |Removed |Added ---------------------------------------------------------------------------- CC| |mateusz.stachowski@wp.pl
--- Comment #15 from Mateusz Stachowski mateusz.stachowski@wp.pl 2011-09-25 09:08:42 CDT --- I tested the HoverRace Demo on wine-1.3.29 with and without the prefill and WHDR_DONE patches. I tested it on OSSv4 and sound works good in both cases. Although I have to disable the vmix (via ossxmix GUI) before starting the game. Otherwise sound is intermittent, but it's definitely better than with wine-1.3.27. When using that version disabling of vmix doesn't help.
http://bugs.winehq.org/show_bug.cgi?id=28284
--- Comment #16 from Jörg Höhle hoehle@users.sourceforge.net 2011-10-04 09:31:55 CDT --- The WHDR_DONE patch is in git now. IIRC all of my patches are in git, so please test again and close if appropriate. OTOH, the dsound->mmdevapi winmm bypass is in git too, and all dsound apps behave differently since (they don't see my fixes to winmm).
http://bugs.winehq.org/show_bug.cgi?id=28284
--- Comment #17 from GyB gyebro69@gmail.com 2011-10-04 09:45:34 CDT --- (In reply to comment #16)
The WHDR_DONE patch is in git now. IIRC all of my patches are in git, so please test again and close if appropriate. OTOH, the dsound->mmdevapi winmm bypass is in git too, and all dsound apps behave differently since (they don't see my fixes to winmm).
I can't tell you whether it is fixed or not, because the vast majority of my games (including HoverAce) are now afflicted by bug #28517. Since commit [e786998daff4ad49521a4c9c39c172ddcdcad82a] audio plays correctly in the menu of those games, but as soon as a new game is started (or a saved game is loaded) sound begins to crackle and it cuts out in a matter of seconds.
wine-1.3.29-169-gdb882bf Only Alsa is used here, PA is not running.
http://bugs.winehq.org/show_bug.cgi?id=28284
--- Comment #18 from GyB gyebro69@gmail.com 2011-10-06 12:02:53 CDT --- Andrew Eikum's patch (dsound: Fix fragment position calculations) in bug #28517comment#11 fixes the audio problem in Hoverace.
http://bugs.winehq.org/show_bug.cgi?id=28284
Austin English austinenglish@gmail.com changed:
What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |RESOLVED Resolution| |FIXED
--- Comment #19 from Austin English austinenglish@gmail.com 2011-10-06 17:47:34 CDT --- (In reply to comment #18)
Andrew Eikum's patch (dsound: Fix fragment position calculations) in bug #28517comment#11 fixes the audio problem in Hoverace.
http://source.winehq.org/git/wine.git/commitdiff/ecd13dcbef16ccee9ae7785cc60...
http://bugs.winehq.org/show_bug.cgi?id=28284
Alexandre Julliard julliard@winehq.org changed:
What |Removed |Added ---------------------------------------------------------------------------- Fixed by SHA1| |ecd13dcbef16ccee9ae7785cc60 | |ec63f5772ae19
http://bugs.winehq.org/show_bug.cgi?id=28284
Alexandre Julliard julliard@winehq.org changed:
What |Removed |Added ---------------------------------------------------------------------------- Status|RESOLVED |CLOSED
--- Comment #20 from Alexandre Julliard julliard@winehq.org 2011-10-10 13:12:19 CDT --- Closing bugs fixed in 1.3.30.