How to get Wine and Pulseaudio to coexist

This is a quick and dirty guide on how you can have Pulseaudio on your system and still have wine directly use ALSA, instead of going through the ALSA plugin of Pulseaudio. If you don't know what that means, why you would want to do this or what it is good for, you probably don't need it. Please not that the procedure here may break in all but the most simple setups (just one soundcard in the system at any time, no special needs, etc.).

This was tested on a recent Ubuntu system. Other distros will differ in detail, but the general idea should hold as well. In order to do this, one needs to do two things:

  1. Make Pulseaudio not grab the hardware ALSA device
  2. Make wine use ALSA directly

Make Pulseaudio not grab the hardware ALSA device

This of course assumes that Pulseaudio actually uses ALSA to talk to your hardware. If it doesn't, you will have to come up with your own solution (and add it here, please). The configuration will have to be done in /etc/pulse/default.pa or ~/.pulse/default.pa. As my systems default.pa does a lot of other things as well, I decided to edit it, instead of making a copy for my user, but you can do either. Note: Pulseaudio can be run on a per-user basis or as a system daemon. In the latter case, you "will" need to edit /etc/pulse/default.pa.

In this file, there will be a lot of "load-module module-something" lines. You will need to comment (disable) all lines that relate to module-udev-detect, module-detect, module-alsa-card, module-alsa-sink and module-alsa-source. This makes sure that Pulseaudio doesn't just go ahead and grabs the 'hw' pcm. Next, add lines to make it use the correct devices. Put these lines right where you just commented out the other stuff.

load-module module-alsa-sink device=dmix
load-module module-alsa-source device=dsnoop

The first line will make Pulseaudio send everything to the dmix pcm, the second will make it use dsnoop for microphones/line in (I haven't actually tested the dsnoop part). Now kill pulseaudio. It should restart automatically as soon as any app needs it (which should be most of those on your system). Make sure that only one instance of pulseaudio gets started, and that you don't see instances starting and stopping all the time. If this happens, you broke the config and pulseaudio is being started continously because it is needed, only to exit because something isn't right. Fix the config, and the restarting should stop.

Making wine use ALSA directly

Now that Pulseaudio is no longer hogging the sound card, wine can start using it. However, by default all programs will still go through Pulseaudios ALSA plugin, and the purpose of this guide is not to change the default. Instead, one needs a way to tell wine not to take the default route. As there is no Registry Value I know of, I took another route. Put the following into your ~/.asoundrc:

pcm.!default {
    @func refer
    name { @func concat 
           strings [ "pcm."
                     { @func getenv
                       vars [ ALSA_DEFAULT_PCM ]
                       default "pulse"
                     }
           ]
         }
}

ctl.!default {
    @func refer
    name { @func concat 
           strings [ "ctl."
                     { @func getenv
                       vars [ ALSA_DEFAULT_CTL
                              ALSA_DEFAULT_PCM
                       ]
                       default "pulse"
                     }
           ]
         }
}

For an explanation of what this does, see http://alsa.opensrc.org/Default_device_from_environment_variable. You can also find more background info in http://defectivecompass.wordREMOVETHISpress.com/2007/12/05/alsa-configuration/ (please copy this URL and remove "REMOVE THIS". For some reason, one cannot have links to this site in this wiki). In summary, if you set the environment variables ALSA_DEFAULT_PCM and ALSA_DEFAULT_CTL to some value for a process, this process will use a different default pcm. We need exactly this, so wine doesn't end up using Pulseaudio after all. To give an example, I use it like this:

$ ALSA_DEFAULT_PCM="plug:dmix" wine something.exe

Testing

To make sure you are really going through ALSA:

  1. $ ALSA_DEFAULT_PCM="plug:dmix" winecfg
    
  2. Go to the Audio tab, click "Test Sound"
  3. If you hear the sound, and see messages like "The dmix plugin supports only playback stream", it's working.

If it isn't, start to RTFM...

Notes

To repeat, this is really quick and dirty, and it might easily break if you change other things or your distro does things differently. Experiment, and make sure you can revert to the way it used to be. Also, the Pulseaudio configuration removes a lot of flexibility with multiple soundcards, USB devices etc. Please add a better solution, if you have it.


CategoryThirdParty CategorySound

WineAndPulseaudio (last edited 2013-06-09 08:00:37 by KyleAuble)