http://bugs.winehq.org/show_bug.cgi?id=14717
--- Comment #231 from Alexander E. Patrakov patrakov@gmail.com 2011-11-11 03:32:28 CST --- (In reply to comment #227)
P.S. Sorry for hi-jacking the bug report a bit more but I have a semi-related question for Andrew to ask: looks like that the default samplerate for dsound is set to be 44100Hz, which differs from the typical 48000Hz value that's being used by most AC97 codecs. HDA codecs typically use 96000Hz or 192000Hz as their base internal samplerate. <snip about SB Live! internal bad-quality resampling, it's a known issue>
The native codec sample rate and its internal resampling is irrelevant, because Wine doesn't talk to the codec directly. Wine talks to either oss4, or dmix, or pulseaudio. I know nothing about oss4, so let's omit it.
With dmix, the default sample rate is indeed 48 kHz, but pulseaudio defaults to 44.1 kHz. The point is that there is no single static good default that would eliminate double software resampling (once by wine and once by platform libraries) for all users.
What can be done, though, is to disable the ALSA resampler (only if called from DirectSound! that's important!), ask ALSA for approximately the default sample rate, and use the result. Something like this pseudocode (copied from MPlayer that gets the logic right, but untested in my own code):
sample_rate = default_sample_rate; snd_pcm_hw_params_set_rate_resample(?, ?, 0); snd_pcm_hw_params_set_rate_near(?, ?, &sample_rate, 0); run_primary_buffer_at(sample_rate);
This way, dmix users will have the primary buffer running at 48 kHz (or whatever their defaults.pcm.dmix.rate is), no matter what sample rate is configured in the registry. And pulseaudio users will get default_sample_rate. So with the above logic and default_sample_rate = 44100, we'll match the ideal sample rate for both default dmix and default pulseaudio setups.