Skip to main content

linux - How to configure PulseAudio to input/output via ALSA?


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.




  1. You can edit ~/.config/pulse/default.pa. It's listed under FILES in the "pulseaudio(1)" manual page. If it is present, the global default.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-unix

    However, 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 and module-alsa-source lines. The module-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 that mplayer -ao pulse ... reports "Audio device got stuck!" and mpv -ao pulse ... reports "[ao/pulse] The stream is suspended. Bailing out." Commenting out that module fixed the problem.




  2. 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; while hw: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 update default.pa to refer to it).




  3. Test. Use pulseaudio -k or killall pulseaudio to kill the current PulseAudio daemon. Then start it again with pulseaudio -vv. Of course, you'll need to do this every time you edit ~/.asoundrc. Once you have a working setup you could try something like pactl 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 and paplay -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 use paplay and aplay together, and mixing occurs automatically. However, the microphone can't be shared in my setup; I cannot record from it using arecord when PulseAudio is running ("Device or resource busy"). For that I would need to create a dsnoop device and put its name in place of hw: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

Popular Posts

Use Google instead of Bing with Windows 10 search

I want to use Google Chrome and Google search instead of Bing when I search in Windows 10. Google Chrome is launched when I click on web, but it's Bing search. (My default search engine on Google and Edge is http://www.google.com ) I haven't found how to configure that. Someone can help me ? Answer There is no way to change the default in Cortana itself but you can redirect it in Chrome. You said that it opens the results in the Chrome browser but it used Bing search right? There's a Chrome extension now that will redirect Bing to Google, DuckDuckGo, or Yahoo , whichever you prefer. More information on that in the second link.

linux - Using an index to make grep faster?

I find myself grepping the same codebase over and over. While it works great, each command takes about 10 seconds, so I am thinking about ways to make it faster. So can grep use some sort of index? I understand an index probably won't help for complicated regexps, but I use mostly very simple patters. Does an indexer exist for this case? EDIT: I know about ctags and the like, but I would like to do full-text search. Answer what about cscope , does this match your shoes? Allows searching code for: all references to a symbol global definitions functions called by a function functions calling a function text string regular expression pattern a file files including a file

How do I transmit a single hexadecimal value serial data in PuTTY using an Alt code?

I am trying to sent a specific hexadecimal value across a serial COM port using PuTTY. Specifically, I want to send the hex codes 9C, B6, FC, and 8B. I have looked up the Alt codes for these and they are 156, 182, 252, and 139 respectively. However, whenever I input the Alt codes, a preceding hex value of C2 is sent before 9C, B6, and 8B so the values that are sent are C2 9C, C2 B6, and C2 8B. The value for FC is changed to C3 FC. Why are these values being placed before the hex value and why is FC being changed altogether? To me, it seems like there is a problem internally converting the Alt code to hex. Is there a way to directly input hex values without using Alt codes in PuTTY? Answer What you're seeing is just ordinary text character set conversion. As far as PuTTY is concerned, you are typing (and reading) text , not raw binary data, therefore it has to convert the text to bytes in whatever configured character set before sending it over the wire. In other words, when y

networking - Windows 10, can ping other PC but cannot access shared folders! What gives?

I have a computer running Windows 7 that shares a Git repo on drive D. Let's call this PC " win7 ". This repo is the origin of a project that we push to and pull from. The network is a wireless network. One PC on this network is running on Windows 10. Let's call this PC " win10 ". Win10 can ping every other PC on the network including win7 . Win7 can ping win10 . Win7 can access all shared files on win10 . Neither of the PCs have passwords. Problem : Win10 cannot access any shared files on win7 , not from Explorer, nor from Git Bash or any other Git management system (E-Git on Eclipse or Visual Studio). So, win10 cannot pull/push. Every other PC on the network can access win7 shared files and push/pull to/from the shared Git origin. What's wrong with Windows 10? I have tried these: Control Panel\All Control Panel Items\Network and Sharing Center\Advanced sharing settings\ File sharing is on, Discovery is on, Password protected sharing is off Adapte