WINEALSA: remove crackling in DirectSound/ALSA combination (try 2)

Alex Villací­s Lasso a_villacis at palosanto.com
Thu Aug 11 10:44:08 CDT 2005


Alex Villací­s Lasso wrote:

> For a long time, I have been annoyed by a faint crackling that can be 
> heard on the sound output of any DirectSound program when full 
> hardware acceleration is enabled on the ALSA driver. Even after a 
> patch I sent earlier (which corrected a bigger artifact), this 
> crackling remained. Last night, I finally set upon removing this 
> crackling, based on a comment in IDsDriverBufferImpl_GetPosition() in 
> dlls/winmm/winealsa/audio.c, line 3302:
>
>    //* /*FIXME*/: snd_pcm_mmap_hw_ptr() should not be accessed by a 
> user app. *//
>    //*        It will NOT return what why want anyway. *//
>    hw_ptr = _snd_pcm_mmap_hw_ptr(wwo->pcm);
>
> I thought, maybe it is not returning the correct information for 
> GetPosition, so that is why the crackling exists, since new samples 
> are off-position from what they should be in order to guarantee a 
> smooth sound. So I deduced, maybe the IDsDriverBufferImpl object can 
> keep a simulation of a hardware pointer and use that instead of the 
> (slightly incorrect) hardware pointer. My original intention was to 
> remove entirely the need to reference _snd_pcm_mmap_hw_ptr(), since 
> this is obviously an internal alsa-lib function and should not be used 
> from inside the app (as the comment rightly indicates). However, I 
> found out that the simulated hardware pointer tends to lag behind the 
> real hardware pointer, and horrible mixups happen if the difference 
> approaches or exceeds the length of the mmap buffer. So the simulated 
> pointer is loosely kept close to the hardware pointer in the supplied 
> patch.
>
> The good news: the patch sort of works (in my setup, at least, with 
> Fedora Core 4). All the games I have (Japanese RPGs) now have smooth 
> sound, unless the CPU load is too high.
> The bad news: the patch does nothing to make the dsound tests pass in 
> Wine (but they were already failing before the patch :-)
>
> Alex Villacís Lasso
>
> Changelog:
> * Remove crackling in DirectSound/ALSA playback with full hardware 
> acceleration
>
Reading through my own previous explanation, I realized that the 
original crackling problem lies in the fact that the hardware pointer is 
ahead of the proper position for mixing. So, if the hardware pointer is 
set back by a fixed amount before reporting in GetPosition, this 
crackling could be fixed without resorting to the simulated pointer 
hack. The attached patch does just this. It is an one-line fix, and 
solves the problem just as well as the original patch, without being as 
sensitive to CPU usage as the first patch. So please ignore the previous 
patch and use this one instead.

Alex Villacís Lasso

Changelog:
* Remove crackling in DirectSound/ALSA playback with full hardware 
acceleration

-------------- next part --------------
A non-text attachment was scrubbed...
Name: wine-winealsa-crackling_fix.patch
Type: text/x-patch
Size: 605 bytes
Desc: not available
Url : http://www.winehq.org/pipermail/wine-devel/attachments/20050811/194be375/wine-winealsa-crackling_fix.bin


More information about the wine-devel mailing list