02 Dec 2014 23:34
TAGS: dell geek linux pulseaudio soundcard xfce
I found the laptop I bought recently has a weird thing with its soundcard. It plays music OK, it also allows you to change the mixer levels, nothing special, but when you try changing mixer setting while the music is playing the music starts getting choppy and the process handling the mixer tend to freeze. Also you cannot pause the music, sometimes it repeats the same sample over and over and it gets very annoying.
My approach to this issue was to use PulseAudio software mixer capabilities, so the hardware mixer is never adjusted (other than for the initial setup).
Step 1. Getting PulseAudio to use the software mixer
I found no good documentation on this other than PulseAudio uses paths to convert the desired volume to the hardware mixer settings and if it lacks the ability to do so it would turn the volume up/down using software. Reading between the lines I realized if I remove the paths I will get what I want. Just do this and restart pulseaudio and you'll have PulseAudio doing all the mixing in software:
sudo mv /usr/share/pulseaudio/alsa-mixer/paths /usr/share/pulseaudio/alsa-mixer/paths.bak
Verifying it works
Open two terminal windows. In each of them open alsamixer. Both should display very simple controls and say Card: PulseAudio. Use F6 to switch to the real card in one of the windows. Usually the cards have plethora of controls, so should yours.
Now change the output volume in the alsamixer still saying "Card: PulseAudio". If the volume reported by the other alsamixer does not change, it works as expected!
If you now rename the paths directory back and restart the pulseaudio process, updating the PulseAudio volume should update the real device volume as well.
Step 2. Integrating this with XFCE (or other DE)
The way xfce4 handles the volume is two-fold:
- There's a xfce4-volumed daemon. It only controls the key bindings. It binds volume up, volume down and mute keys to control the real device controls
- There's a panel applet called "Audio Mixer" that shows the current volume level and lets you change the volume as well.
Both component are optional and both seem to not work with PulseAudio (even through PulseAudio ALSA emulation which tricks alsamixer for instance).
We're going to overcome this problem by replacing these components with two other programs.
pa-applet will replace the "Audio Mixer" applet. The difference is the pa-applet docks to the systray, so is not XFCE-specific. The downside is we don't have control over the specific position of the icon, all we know is it will appear in the systray (so don't forget to have the systray applet added to the panel).
In order to install this software you need to clone the source, and run ./autogen.sh, ./configure, make, sudo make install. You will get information about deps missing, for instance:
configure: error: Package requirements (glib-2.0) were not met: No package 'glib-2.0' found
You need to find the proper *-dev package for each unmet dependency (for this one it will be libglib2.0-dev).
I came across one additional problem. The software seems not updated after some GTK+ 3 updates and it uses a deprecated function. Because the code is configured in a way that every warning stops the compilation, it wouldn't let you compile the code unless you open the src/Makefile file and then find and remove the -Werror flag from it.
This part will take care of binding the media keys to the pulse audio controls (rather than to the sound card controls).
You need to download the tar package, untar it, ./configure, make, sudo make install. It also requires quite a few libs to be installed, but I didn't found any issues when compiling.
Hooking this up together
Since I didn't need the original xfce4-volume anymore I decided to remove it:
apt-get remove xfce4-volumed
But because XFCE will try to launch this anyway on each start, I decided to take advantage of it and replace it with a script:
#!/bin/bash /usr/local/bin/xfce4-volumed-pulse /usr/local/bin/pa-applet
Add the executable bit, restart the laptop and all should be working correctly at this moment.
Setting the hw mixer controls
Since PulseAudio won't update the hw controls after you follow up this little howto, it's quite important to set all the important channels to 100% (or other number up to your taste). The way to update the hw controls was described before.
Open the terminal, type alsamixer and hit F6. This will give the list of ALSA devices besides the PulseAudio emulation, your real sound cards should display as well. Choose the right one and you should be given access to tweak the real card controls.
Note if you removed the PulseAudio paths, the PulseAudio controls wouldn't update when you tweak the hw controls.