How do I configure PulseAudio to use only a single ALSA device for input and output?
The default PulseAudio configuration causes PulseAudio to open all ALSA devices when it starts. This makes it impossible to use PulseAudio together with other ALSA clients. Many people prefer PulseAudio to ALSA, but other users find it frustrating. For better or worse, PulseAudio has become a standard and several popular Linux applications, such as Skype and Firefox, only support audio output via PulseAudio.
Some users prefer to work with audio clients that output directly to ALSA, others output to another audio framework like JACK, but want to have JACK access ALSA directly. For these users, it is easy to free up all the ALSA devices by uninstalling PulseAudio. However, removing PulseAudio makes it impossible to use audio in Skype and Firefox.
A better solution would be to come up with a configuration that gets PulseAudio to "play nicely" with other ALSA clients, outputting to only a single device, which would be specified in its configuration, or even just the ALSA default
device. How can we do that?
Answer
This answer builds on @dirkt's answer, so thanks are due to him.
You can edit
~/.config/pulse/default.pa
. It's listed under FILES in the "pulseaudio(1)" manual page. If it is present, the globaldefault.pa
is not used. For me, I can get a working setup with the following minimal configuration:load-module module-alsa-sink device=default
load-module module-alsa-source device=default
load-module module-native-protocol-unixHowever, you may want to look at the global version, which is
/etc/pulse/default.pa
on my system, to see what else could go in this file. There are all sorts of bells and whistles configured here: modules to restore volume settings, discover bluetooth devices, interface with JACK, automatically quit the daemon when user logs out, and so on. If you decide to copy the global file to your home directory and edit it, or even to edit the global file directly, you'll need to do the following:- Comment out
load-module module-udev-detect
, which searches for ALSA hardware devices and overrides the device argument you passed to the ALSA modules above. - Then add the
module-alsa-sink
andmodule-alsa-source
lines. Themodule-native-protocol-unix
line should already be present. - You may need to comment out the line
load-module module-suspend-on-idle
; this caused problems for me in testing with certain output devices. The symptom is thatmplayer -ao pulse ...
reports "Audio device got stuck!" andmpv -ao pulse ...
reports "[ao/pulse] The stream is suspended. Bailing out." Commenting out that module fixed the problem.
- Comment out
If you choose different devices than
device=default
above, for example two separate ALSA devices for record and playback, then it won't work in my experience -parecord
tries to record from the sink device rather than the source device. If you have configured separate devices for input and output via ALSA, and you want them to be named by the same PCM device, you need to put something like this in~/.asoundrc
:pcm.!default { # "!" means "override" the previous definition
type asym
playback.pcm "hw4mix"
capture.pcm "hw:5"
}Here
hw4mix
names a dmix device defined previously in the file; whilehw:5
specifies the hardware device for my USB microphone. This makes PulseAudio happy. If you wanted to use a special device for PulseAudio clients, you can name it "special_pulseaudio_device" instead of "default" (and of course updatedefault.pa
to refer to it).Test. Use
pulseaudio -k
orkillall pulseaudio
to kill the current PulseAudio daemon. Then start it again withpulseaudio -vv
. Of course, you'll need to do this every time you edit~/.asoundrc
. Once you have a working setup you could try something likepactl exit; pulseaudio --start
. The--start
option makes it run in the background, where you won't be able to see error messages.Use
parecord -v t.wav
andpaplay -v t.wav
to record and play a WAV file. You should be able to have these commands running at the same time.Since I use a
dmix
device for playback, I can usepaplay
andaplay
together, and mixing occurs automatically. However, the microphone can't be shared in my setup; I cannot record from it usingarecord
when PulseAudio is running ("Device or resource busy"). For that I would need to create adsnoop
device and put its name in place ofhw:5
above.If you're trying to get Skype to work, use the Skype "Echo / Sound Test Service" to test your setup. Keep in mind that Skype may be already be running in the background - try
killall skype
before starting it, to force it to make a new PulseAudio connection. In my experience, Skype does not report any kind of error condition when it is not able to connect to the PulseAudio daemon.
Having a good ALSA configuration is desirable, even if only because certain applications (Ecasound? legacy code?) don't work with PulseAudio. I hope that these instructions are helpful to anyone who, having configured ALSA to their liking, now wants to be able to use programs like Skype which depend on PulseAudio.
Comments
Post a Comment