Trouble again with PulseAudio and Thunderbird sound notifications

In an earlier post I described how I fixed a scratchy-sounding sound file which the Thunderbird e-mail client plays when a new message arrives. Well, the problem started again recently, but this time the contents of /etc/pulse/daemon.conf looked OK to me. Furthermore, the sound file sounds fine when played using following commands:

aplay ~/Music/wav/E-mail_notifications/halmsg.wav
paplay ~/Music/wav/E-mail_notifications/halmsg.wav
mplayer ~/Music/wav/E-mail_notifications/halmsg.wav
cvlc ~/Music/wav/E-mail_notifications/halmsg.wav

Now, Thunderbird uses libcanberra to play sounds, so I began to wonder if the problem lay with libcanberra. As it happens, libcanberra is maintained by the same person who invented PulseAudio. However, I notice from the libcanberra Git repository that its source code has not been changed since 2012.

My Gentoo Linux installation had libcanberra installed with support for both ALSA and PulseAudio:

root # eix -I libcanberra
[I] media-libs/libcanberra
     Available versions:  0.30-r5 {alsa gnome gstreamer +gtk +gtk3 oss pulseaudio +sound tdb udev ABI_MIPS="n32 n64 o32" ABI_PPC="32 64" ABI_S390="32 64" ABI_X86="32 64 x32"}
     Installed versions:  0.30-r5(08:27:41 18/05/18)(alsa gtk gtk3 pulseaudio sound udev -gnome -gstreamer -oss -tdb ABI_MIPS="-n32 -n64 -o32" ABI_PPC="-32 -64" ABI_S390="-32 -64" ABI_X86="32 64 -x32")
     Homepage:            http://git.0pointer.net/libcanberra.git/
     Description:         Portable sound event library

So, even though my installation uses PulseAudio, I decided to try and re-install libcanberra without PulseAudio support, only ALSA support:

root # USE="-pulseaudio" emerge -1v libcanberra
root # eix -I libcanberra
[I] media-libs/libcanberra
     Available versions:  0.30-r5 {alsa gnome gstreamer +gtk +gtk3 oss pulseaudio +sound tdb udev ABI_MIPS="n32 n64 o32" ABI_PPC="32 64" ABI_S390="32 64" ABI_X86="32 64 x32"}
     Installed versions:  0.30-r5(15:47:14 26/05/18)(alsa gtk gtk3 sound udev -gnome -gstreamer -oss -pulseaudio -tdb ABI_MIPS="-n32 -n64 -o32" ABI_PPC="-32 -64" ABI_S390="-32 -64" ABI_X86="32 64 -x32")
     Homepage:            http://git.0pointer.net/libcanberra.git/
     Description:         Portable sound event library

Lo and behold, Thunderbird (libcanberra) plays the sound file correctly now. So I have added the following line to my file /etc/portage/package.use/thunderbird in order to make the change permanent:

media-libs/libcanberra -pulseaudio

PulseAudio 🙄

No sound from headphones after resume from suspension / No sound from headphones after re-plug

It is not difficult to find posts on the Web regarding certain models of laptop that no longer produce sound from headphones after resuming from suspension, or no longer produce sound from their speakers or from headphones if you unplug and reconnect the headphones. My Clevo W230SS laptop suffered from these problems and more: sometimes the external microphone socket would no longer work either. I had to reboot the laptop in order to get audio working properly again.

The cause of these problems varies according to the specific hardware and software, and here I will describe a couple of fixes I implemented in Gentoo Linux for my Clevo W230SS laptop. Bear in mind that what works for one model of laptop may not necessarily work for a different model even if the symptoms are the same.

PROBLEM 1: No sound from headphones after resume from suspension

After my laptop resumed from suspension, headphones would no longer work until I rebooted the laptop. Sometimes an external microphone would also stop working until I rebooted. In 2014, Ubuntu user Kiril filed a bug report regarding this problem with the Clevo W230SS: [W230SS, VIA VT1802, Green Headphone Out, Front] No sound after suspend/resume. Actually, his original title for the bug report was: ‘[W230SS, VIA VT1802, Green Headphone Out, Front] No sound after fresh boot’. I didn’t have that problem: the headphone socket of my Clevo W230SS did produce sound after a ‘fresh boot’. Regarding Kiril‘s initial problem, ALSA developer Raymond Yau made several comments, including the following:

driver should not use same audio output for device 0 and device 2

independent headphone should be disabled on notebook by default

for desktop line out and headphone connected to different audio output nodes 0x03 and 0x04

this allow you to play different audio to line out and headphone

but this feature usually should be disabled for notebook

you need to file an upstream bug report to fix this bug in the indep_hp_possible function which should return false when there is no internal mic since some notebook have line out, headphone and Mic jack to support 5.1 or only enabled when headphone at extra front and line out at ext rear

the workaround is use hint to disable the indep_hp=0

https://git.kernel.org/cgit/linux/kernel/git/tiwai/sound.git/tree/Documentation/sound/alsa/HD-Audio.txt

Now, Kiril was using Ubuntu 14.04 and ALSA 1.0.27, whereas I’m using Gentoo and ALSA 1.0.29. Furthermore, apart from the two installations using different kernel versions, in Gentoo you configure and build the kernel yourself. So there is quite some difference between the two installations, which might explain why I do not have his original problem of no sound from headphones after a fresh boot. Where we did coincide, though, was that there was no sound from headphones following resumption from suspension.

First attempt at fixing the problem

Even though Independent HP does not stop headphones working after I boot my laptop, I decided to try to remove Independent HP anyway, to see if it would fix the suspend/resume problem with headphones in my case.

The Clevo W230SS has two sound cards:

root # lspci | grep Audio
00:03.0 Audio device: Intel Corporation Xeon E3-1200 v3/4th Gen Core Processor HD Audio Controller (rev 06)
00:1b.0 Audio device: Intel Corporation 8 Series/C220 Series Chipset High Definition Audio Controller (rev 05)

The HDMI audio card is Card 0, and the analogue HD Audio card is Card 1. ALSAMixer shows an Independent HP (headphone) channel for Card 1:

user $ alsamixer -c 1

The kernel documentation for the HD Audio driver explains how to fix the problem using what is called a driver ‘hint’. There is a link to the documentation in the above-mentioned bug report, and you can also find the documentation in the file /usr/src/<kernel_release>/Documentation/sound/alsa/HD-Audio.txt on your laptop if you have installed the kernel source code. As explained in the documentation, you can remove Independent HP either via the command line:

root # echo "indep_hp = no" > /sys/class/sound/hwC1D0/hints
root # echo 1 > /sys/class/sound/hwC1D0/reconfig

or by using so-called ‘Early Patching’:

Early Patching
~~~~~~~~~~~~~~
When CONFIG_SND_HDA_PATCH_LOADER=y is set, you can pass a "patch" as a
firmware file for modifying the HD-audio setup before initializing the
codec.  This can work basically like the reconfiguration via sysfs in
the above, but it does it before the first codec configuration.

Note that the term ‘patching’ here has nothing to do with patching the driver’s source code; it refers to patching the ALSA driver’s configuration of the VIA chip’s CODEC on the Intel sound card.

The format of this particular patch file containing a ‘hint’ would be as follows:

[codec]
<vendor_id> <subsystem_id> <address_of_the_CODEC>

[hint]
indep_hp = no

The values for vendor_id and subsystem_id can be found as follows:

root # cat /sys/class/sound/hwC1D0/vendor_id
0x11068446
root # cat /sys/class/sound/hwC1D0/subsystem_id
0x15582300

(As the driver is used with Card 1, remember to look in directory hwC1D0 rather than hwC0D0.)

The required value for address_of_the_CODEC is zero in this particular case. Therefore the file /lib/firmware/clevo-hda-patch (you can choose any file name you want) should have the following contents:

[codec]
0x11068446 0x15582300 0

[hint]
indep_hp = no

If you built the HA Audio driver as a module, you would need to add the following line to the file /etc/modprobe.d/alsa.conf in order to apply the patch:

options snd-hda-intel patch=,clevo-hda-patch

Notice the comma after the equals sign. This is required because the patch applies to the second card (Card 1) rather than to the first card (Card 0).

However, I had built the HD Audio driver into the kernel rather than as a module:

root # grep HDA /usr/src/linux/.config | grep -v "is not set"
CONFIG_SND_HDA=y
CONFIG_SND_HDA_INTEL=y
CONFIG_SND_HDA_PREALLOC_SIZE=2048
CONFIG_SND_HDA_HWDEP=y
CONFIG_SND_HDA_RECONFIG=y
CONFIG_SND_HDA_INPUT_BEEP=y
CONFIG_SND_HDA_INPUT_BEEP_MODE=1
CONFIG_SND_HDA_INPUT_JACK=y
CONFIG_SND_HDA_PATCH_LOADER=y
CONFIG_SND_HDA_CODEC_VIA=y
CONFIG_SND_HDA_CODEC_HDMI=y
CONFIG_SND_HDA_I915=y
CONFIG_SND_HDA_GENERIC=y
CONFIG_SND_HDA_POWER_SAVE_DEFAULT=0

Therefore adding the option to /etc/modprobe.d/alsa.conf would have no effect, as the HD Audio driver is not a module. In this case I could have appended the following parameter to the kernel boot line in the file /boot/grub/grub.cfg instead:

snd-hda-intel.patch=,clevo-hda-patch

The above kernel boot parameter could be appended to the kernel boot line either directly by editing the file grub.cfg, or indirectly by adding it to the list of boot parameters in the variable GRUB_CMDLINE_LINUX_DEFAULT="" in the file /etc/default/grub and then using the command ‘grub2-mkconfig -o /boot/grub/grub.cfg‘ as root user to regenerate the grub.cfg file. Remember to mount /boot first if it is on a different partition.

Now, I tried applying the patch using the appropriate method in each case: HD Audio driver built into the kernel, and HD Audio driver built as a module (it didn’t take me long to modify the kernel configuration and rebuild the kernel). In both cases the following messages were included in the output of the dmesg command:

[ 0.430218] snd_hda_intel 0000:00:1b.0: Applying patch firmware 'clevo-hda-patch'
[ 0.430356] snd_hda_intel 0000:00:1b.0: Direct firmware load for clevo-hda-patch failed with error -2
[ 0.430359] snd_hda_intel 0000:00:1b.0: Cannot load firmware, aborting

I’m not sure if the reason for the failure to load the patch is the same in both cases, but certainly the reason in the case of the module is that PulseAudio is already running and using the driver by the time the OS attempts to apply the patch. In the case of the kernel boot parameter, my guess is that the patch would need to be included in an initramfs in order to be able to apply it before PulseAudio starts.

The same situation occurs if you try to apply the ‘hint’ manually from the command line after start-up:

root # echo "indep_hp = no" > /sys/class/sound/hwC1D0/hints
root # echo 1 > /sys/class/sound/hwC1D0/reconfig
bash: echo: write error: Device or resource busy

The above error message occurs because PulseAudio is running and using the driver. To apply the hint and refresh the driver in this case, the solution is to stop PulseAudio beforehand:

user $ echo "autospawn = no" >> ~/.config/pulse/client.conf
user $ pulseaudio --kill
user $ su
root # echo "indep_hp = no" > /sys/class/sound/hwC1D0/hints
root # echo 1 > /sys/class/sound/hwC1D0/reconfig
root # exit
user $ pulseaudio --start

Now, having to do the above manually every time you boot your machine is impractical. To automate the procedure I did the following…

Make sure the automatic (re)spawning of PulseAudio is disabled in the file ~/.config/pulse/client.conf (you can create the file if it does not exist):

autospawn = no

Create a Bash script in the directory /etc/local.d/ for the OS to launch automatically at boot, and in that script issue the above two commands first and then start pulseaudio. I named the script ‘99-clevo-hda-fix.start‘ and made its contents the following:

#!/bin/bash
# Fix for Intel HDA problem with Clevo W230SS
# See https://bugs.launchpad.net/ubuntu/+source/alsa-driver/+bug/1313904
# N.B. Assumes your ~/.config/pulse/client.conf contains
# 'autospawn = no' so that PulseAudio is not launched automatically.
#
# Specify the hint
echo "indep_hp = no" > /sys/class/sound/hwC1D0/hints
#
# Reinitialise the HD Audio driver so it parses the CODEC tree again
echo 1 > /sys/class/sound/hwC1D0/reconfig
#
# Start PulseAudio for my user account
su -c "pulseaudio --start" -s /bin/sh fitzcarraldo

Don’t forget to make the script executable:

root # chmod +x /etc/local.d/99-clevo-hda-fix.start

This method of applying the hint to the HD Audio driver should work irrespectively of whether the driver is a module or built-in. It’s a bit more of a hack compared to the Early Patching approach, but it does the job in my case. After logging in to the Desktop Environment, you can check if the hint has been applied by looking at the contents of /sys/class/sound/hwC1D0/hints:

root # cat /sys/class/sound/hwC1D0/hints
indep_hp = no

However, this alone does not mean the CODEC was reconfigured after the hint was applied, so you need to check if Independent HP still exists. The ALSAMixer output on my laptop now looked like the following after I implemented the above method (notice that Independent HP no longer exists):

user $ alsamixer -c 1

So, what was the result? Well, audio continued to work after I removed Independent HP, but there was still no sound from headphones after resuming from suspension. And neither was there for Kiril, so he changed the title of his bug report to that effect. Fortunately, another user, unrud, commented later in the bug report that he had written init-headphone, a Python script to fix the problem. So I decided to hack his Ubuntu package to get init-headphone working in my Gentoo Linux installation. Here is how I did it…

Second (successful!) attempt at fixing the problem

1. Download init-headphone-ubuntu-0.11.zip from https://github.com/Unrud/init-headphone-ubuntu/releases

2. Extract the contents to the directory ~/init-headphone-ubuntu-0.11/

3. Copy to pm-utils’ hook directory the script that launches init-headphone upon resuming or thawing:

root # cp /home/fitzcarraldo/init-headphone-ubuntu-0.11/etc/linux-pm-utils/init-headphone /etc/pm/sleep.d/03-init-headphone # (use whatever number you want)

4. Copy the init-headphone script itself to the system binaries directory:

root # cp /home/fitzcarraldo/init-headphone-ubuntu-0.11/src/init-headphone /usr/local/sbin/

5. The init-headphone script requires the i2c_dev and i2c_i801 modules:

REQUIRED_MODULES = ["i2c_dev", "i2c_i801"]

However, I prefer to build them into the kernel rather than as modules, so I checked to make sure they are already built into the kernel:

root # grep CONFIG_I2C /usr/src/linux/.config | grep -v "is not set"
CONFIG_I2C=y
CONFIG_I2C_BOARDINFO=y
CONFIG_I2C_COMPAT=y
CONFIG_I2C_CHARDEV=y
CONFIG_I2C_MUX=y
CONFIG_I2C_HELPER_AUTO=y
CONFIG_I2C_ALGOBIT=y
CONFIG_I2C_I801=y

Then I commented out the lines in /usr/local/sbin/init-headphone that check if the two modules are loaded:

root # diff /home/fitzcarraldo/init-headphone-ubuntu-0.11/src/init-headphone /usr/local/sbin/init-headphone
174,181c174,181
< def check_modules():
< try:
< for module in REQUIRED_MODULES:
< logging.info("Trying to add module to the kernel: %s", module)
< if subprocess.call(["modprobe", "--quiet", module]) != 0:
< logging.warning("Module is not loaded: %s", module)
< except OSError:
#def check_modules():
> # try:
> # for module in REQUIRED_MODULES:
> # logging.info("Trying to add module to the kernel: %s", module)
> # if subprocess.call(["modprobe", "--quiet", module]) != 0:
> # logging.warning("Module is not loaded: %s", module)
> # except OSError:
> # logging.warning("modprobe not found")
206c206
# check_modules()

6. I created a script /etc/local.d/99-clevo-hda-fix.start to launch init-headphone automatically at boot:

#!/bin/bash
# Fix for Intel HDA problem with Clevo W230ss
# See https://bugs.launchpad.net/ubuntu/+source/alsa-driver/+bug/1313904
exec /usr/local/sbin/init-headphone

root # chmod +x /etc/local.d/99-clevo-hda-fix.start

7. Add the kernel boot parameter ‘acpi_enforce_resources=lax‘ to the end of the kernel boot line(s) in /boot/grub/grub.cfg (don’t forget to mount /boot first if it is on another partition). You can either edit /boot/grub/grub.cfg directly, or indirectly by adding the parameter to the list of existing parameters in GRUB_CMDLINE_LINUX_DEFAULT (if any) as shown below and issuing the command ‘grub2-mkconfig -o /boot/grub/grub.cfg‘ as root user (again, don’t forget to mount /boot first if it is on another partition):

GRUB_CMDLINE_LINUX_DEFAULT="acpi_enforce_resources=lax"

8. Create a script file /etc/local.d/99-clevo-hda-fix.start to launch the init-headphone automatically at boot:

#!/bin/bash
# Fix for Intel HDA problem with Clevo W230SS
# See https://bugs.launchpad.net/ubuntu/+source/alsa-driver/+bug/1313904
exec /usr/local/sbin/init-headphone

9. As my user account does not have a path configured to the system binaries directory, I created a symlink to it from the directory /usr/local/bin/:

root # ln -s /usr/local/sbin/init-headphone /usr/local/bin/init-headphone

10. As I no longer needed to stop PulseAudio running at boot, I deleted the file /home/fitzcarraldo/.config/pulse/client.conf I had created earlier (or you could just change ‘autospawn = no‘ to ‘autospawn = yes‘).

You can also use init-headphone from the command line:

user $ sudo init-headphone --help

e.g.

user $ sudo init-headphone unmute

This looks like it has finally solved the problem; now headphones still work after my laptop resumes from suspension. I still don’t need to pass the ‘hint’ to the HD Audio driver, so Independent HP continues to appear in ALSAMixer and apparently does not cause any problems.

A big ‘Thank you’ from me to Unrud for creating init-headphone.

PROBLEM 2: No sound from headphones after re-plug

The other problem I experienced with the Clevo W230SS was that, if I unplugged working headphones, audio switched to the laptop’s speakers as expected, but, if I then plugged-in the headphones again, no more sound came from the headphones. If I again unplugged the headphones, sound would again come from the speakers. If I did all this whilst ALSAMixer was running, then:

  1. if I unplugged the headphones, as expected the ALSAMixer volume level indicator for the speaker would rise from zero and the volume level indicator for the headphones would drop to zero;
  2. if I plugged in the headphones, as expected the ALSAMixer volume level indicator for the speaker would drop to zero and the volume level indicator for the headphones would rise from zero.

Now, it is possible that this problem was due to the same thing that caused the loss of audio to headphones when the laptop resumed from suspension. Anyway, before I came across init-headphone I found the following in the Arch Linux Wiki article on PulseAudio:

Switch on connect

This is a module used to switch the output sound to the newly connected device. For example, if you plug in a USB headset, the output will be switched to that. If you unplug it, the output will be set back to the last device. This used to be quite buggy but got a lot of attention in PulseAudio 8.0 and should work quite well now.

If you just want to test the module then you can load it at runtime by calling:

root # pactl load-module module-switch-on-connect

If you want to make the change persistent you will have to add it to your local pulseaudio settings or to /etc/pulse/default.pa (system wide effect). In either case, add this line:

load-module module-switch-on-connect

So, as the file /etc/pulse/default.pa in my installation did not have that line, I added it:

# Added by fitzcarraldo
# https://wiki.archlinux.org/index.php/PulseAudio
# The headphone socket no longer worked if I
# removed and re-inserted the jack plug.
load-module module-switch-on-connect

This seemed to help, but I am not certain module-switch-on-connect is really having an effect when I plug and unplug headphones, and I have not bothered to disable it to see what happens now that init-headphone is in use (I’m just happy that audio is all working now, whatever the reason!). ALSA’s Auto-Mute Mode* appears to perform the same role as module-switch-on-connect: When I unplug the headphones with Auto-Mute Mode enabled in ALSAMixer, there is a noticeable delay before sound starts to come from the laptop’s speakers, whereas there is no such delay when I unplug the headphones with Auto-Mute Mode disabled via ALSAMixer, so presumably module-switch-on-connect is doing its job.

* The documentation file /usr/src/<kernel_release>/Documentation/sound/alsa/HD-Audio-Controls.txt explains what Auto-Mute Mode does.

Anyhow, one or both of the two software modifications (init-headphone and module-switch-on-connect) seem to have cured the problem of no sound from headphones after they are disconnected then reconnected to the laptop.

Audio in Linux becomes annoying again

At the moment I seem to be having more audio problems than usual. Last month I blogged about having to fix the ALSA Speaker volume level resetting to zero at boot, and recently two other audio problems have cropped up.

Thunderbird

I have been having trouble with Thunderbird’s ‘system sound’ that announces the arrival of a new e-mail. Lately, Thunderbird has started playing too loud and with significant distortion the audio clip it had been playing perfectly for the last four years. This is especially strange because I created that audio clip with Audacity from another audio clip that sounded too loud when Thunderbird played it. Ironically, the work-around for this latest problem was to switch to the original, much louder sound clip alert.wav instead of the quieter alert_quiet.wav. Not only does Thunderbird now play alert.wav at a lower volume than alert_quiet.wav, but the sound of alert.wav is not distorted when Thunderbird plays it. Yet if I play alert.wav and alert_quiet.wav using SMPlayer, the former is much louder than the latter and neither is distorted. Figure that one out.

The event notification sound that Thunderbird uses to remind me about an impending meeting scheduled in the calendar has now started sounding very distorted too. I still have not found a work-around for that. Event sounds played by the desktop environment I use (KDE) are not distorted, so what is Thunderbird doing? Perhaps the problem is not Thunderbird itself but the audio library it uses, so I need to investigate further.

Skype

Yet another audio problem cropped up this morning when I connected my laptop to an external monitor and keyboard (and thus I left the laptop’s lid almost closed) in an open-plan office and booted the laptop. I entered my username and password on the KDM log-in screen, and the KDE splash screen appeared as usual. After a few seconds the laptop’s speakers suddenly emitted a piercing, continuous howl; the well-known sound of audio feedback from speakers to microphone. It was LOUD. The volume control buttons on the keyboard made no difference, and the sound was so loud that everyone in the office noticed and several people came over to tell me to reset the BIOS (apparently that had fixed the problem for their laptops running Windows).

I kept my finger on the laptop’s power switch and, after several seconds, the laptop powered off. My laptop dual boots Windows 7 and Gentoo Linux, and the audio feedback did not occur when I booted Windows 7. After booting Linux again a couple of times and annoying everyone in the office even more, I discovered I could open the laptop’s lid far enough back to reduce the feedback to a low whine, so I could let KDE finish launching and display the Desktop. I then launched ALSAMixer and discovered that ‘Internal Mic Boost’ was set to 100%. So I immediately lowered it to zero. Then the penny dropped: I had used Skype the previous night without bothering to connect my headphones and external microphone, and Skype had automatically raised ‘Internal Mic Boost’ all the way up to 100%. So I immediately launched Skype, selected ‘Options’ > ‘Sound Devices’ and unticked ‘Allow Skype to automatically adjust my mixer levels’. The next thing I did was add the following lines to the script /etc/local.d/20set_alsa_volume.start mentioned in my previous blog post Fix for ALSA Speaker volume level resetting to zero at boot:

su -c "amixer -c 0 -- sset 'Internal Mic Boost' 0%" -s /bin/sh fitzcarraldo
su -c "amixer -c 0 -- sset 'Internal Mic' 0%" -s /bin/sh fitzcarraldo
su -c "amixer -c 0 -- sset 'Mic Boost' 0%" -s /bin/sh fitzcarraldo
su -c "amixer -c 0 -- sset 'Mic' 0%" -s /bin/sh fitzcarraldo

From now on, only I am allowed to adjust microphone settings! To avoid any possibility of feedback loops in future, the above-mentioned script sets all the microphone channels to zero and I will have to adjust them myself before use. I already have ALSAMixerGUI in the KDE Launcher menu, so it won’t be a big deal to do that.

This fiasco with Skype got me thinking: if Skype is set to automatically adjust mixer levels when you are in a conversation, when you exit Skype why doesn’t it automatically set mixer levels back to the way they were when Skype was launched? It could be done easily and would be more user-friendly than the current way Skype works.

Interrelationship between PulseAudio and ALSA

The final thing I did (yet again) was to adjust all the various ALSA channels and PulseAudio channels to try and get the resulting audio input and output sounding reasonable. This is easier said than done. I often have to mess around with ALSAMixer and PulseAudio Volume Control in order to get audio input and output working satisfactorily in all applications that use audio. It is actually more difficult than it sounds (ouch!) to get ALSA and PulseAudio ‘balanced’ (for want of a better word). In the days before PulseAudio existed, one only had to adjust ALSA. Now, with two agents controlling audio, the task turns out to be surprisingly awkward sometimes.

To sum up, boo to Thunderbird (or whatever it uses to play sounds), boo to Skype and boo to PulseAudio. I’m fed up with audio issues in Linux at the moment. 😡

Update (January 19, 2015): It turns out that the problem in Thunderbird was due to PulseAudio. See my next post for details of how I fixed it.

Nostalgia for those ALSA mixer channels that KMix and GNOME Volume Control used to have?

These days the GUI mixers KMix and GNOME Sound Preferences display PulseAudio devices and streams rather than ALSA mixer channels. For example, prior to its integration with PulseAudio, KMix typically displayed a mixer window that looked like the one below.

KMix showing ALSA channels

KMix with ALSA channels

whereas, today, a KMix window typically looks like the following:

KMix with PulseAudio channels

KMix with PulseAudio channels

 

KMix 3.8 in KDE 4.6.1 does not provide separate speaker and headphone channels. You can alter the headphone and speaker volume by using PulseAudio Volume Control instead (see the picture below), but people are not as familiar with the PulseAudio GUI, and it is yet another step to perform.

PulseAudio Volume Control showing selection of Headphones channel

PulseAudio Volume Control showing selection of Headphones channel

 

If you are like me, you probably end up using KMix (or GNOME Sound Preferences) but also launch ALSA Mixer in a Konsole/Terminal for fine-grained control of the underlying ALSA channels:

ALSA Mixer running in Konsole

ALSA Mixer running in Konsole

This is more hassle, because you launch Konsole/Terminal and you enter the command alsamixer and press F6 (alternatively, use the command alsamixer -c 0 if your sound card is Card 0). The PulseAudio channels are displayed by default if you don’t specify your sound card when you launch ALSA Mixer.

EDIT (January 28, 2012): With recent versions of ALSA Mixer I have found that I must specify the card in the alsamixer command (e.g. alsamixer -c 0) because the command alsamixer alone results in a Segmentation fault message.

It would be handy to have an icon on the Panel or on the Desktop that you could use to launch ALSA Mixer. Well, you can. In fact, as there is also a GUI version of ALSA Mixer (albeit with a few less features than its console equivalent) you can use that instead if you prefer. Below I explain a few of the possible ways you can display ALSA Mixer easily from within a desktop environment.

Change KMix from a PulseAudio mixer to an ALSA mixer

By default KMix displays PulseAudio channels instead of ALSA channels. However, if you want to display the ALSA channels instead (as shown in the first picture above), quit KMix and enter the following command in a Konsole window or in KRunner:

export KMIX_PULSEAUDIO_DISABLE=1 && kmix

If you want to make this permanent then add KMIX_PULSEAUDIO_DISABLE=1 to the file /etc/conf.d/alsasound

Personally, though, I prefer not to do this as I want to control the PulseAudio channels via the KMix mixer. Try running two or more audio/video apps simultaneously and you’ll see what I mean – it’s useful! For example, I can control the volume of various applications separately (handy when you want to check something or are using Skype), as illustrated by the picture below:

KMix showing PulseAudio playback streams tab

KMix showing PulseAudio playback streams tab

and I run ALSA Mixer separately to tweak the underlying ALSA channels. Using Yakuake (or Guake in GNOME) is quite a good way to run ALSA Mixer in a console: it is quick and easy to pop-up a window to launch ALSA Mixer, and ALSA Mixer is displayed in colour at nearly the width of the desktop.

Launch ALSA Mixer GUI from an icon on the Panel

First, use your package manager to install the package alsamixergui. It’s a GUI equivalent of the console ALSA Mixer, but with a few less options.

Once you install it, you should find ALSA Mixer GUI in your desktop environment menu (e.g. Kickoff > Applications > Multimedia > ALSA Mixer GUI). By default this will show the PulseAudio channels, so use the menu editor (e.g. right-click on Kickoff and select Menu Editor) to change the command to the following if your sound card is Card 0:

alsamixergui -c 0

Once you have done this, save the new menu entry, log out and log in again, and when you launch ALSA Mixer GUI from the menu a window similar to the following will pop-up:

ALSA Mixer GUI

ALSA Mixer GUI

To put an icon on the Panel in order to make it even easier to launch ALSA Mixer GUI, just drag the icon from the menu to the Panel and it will be copied to the Panel. Simple as that.

Launch ALSA Mixer in a Konsole docked in the System Tray

You can do this using KDocker, which works in KDE, GNOME, Xfce and other desktop environments.

For KDE, create the following Desktop Configuration File Konsole-alsamixer.desktop (or whatever name you want) and put it in the directory ~/.kde4/Autostart/

[Desktop Entry]
Comment[en_GB]=Console (docked) running ALSA Mixer
Comment=Console (docked) running ALSA Mixer
Exec=kdocker konsole -e alsamixer -c 0
GenericName[en_GB]=Dock Konsole running ALSA Mixer in the System Tray
GenericName=Dock Konsole running ALSA Mixer in the System Tray
Icon=kmix
MimeType=
Name[en_GB]=Konsole (Docked)
Name=Konsole (Docked)
Path=
StartupNotify=true
Terminal=false
TerminalOptions=
Type=Application
X-DBUS-ServiceName=
X-DBUS-StartupType=
X-KDE-SubstituteUID=false
X-KDE-Username=
KDE System Tray showing Konsole docked using KDocker

KDE System Tray showing Konsole docked using KDocker

Clicking on the docked Konsole icon in the System Tray will pop-up a Konsole window with the familiar ALSA Mixer running in it, as shown in the fourth picture above. Clicking on the icon again will minimise the Konsole to the System Tray.

Launch ALSA Mixer in a Konsole from an icon on the Desktop

For KDE, create the following Desktop Configuration File Konsole-alsamixer.desktop (or whatever name you want) and put it in the directory ~/Desktop/

[Desktop Entry]
Comment[en_GB]=Console running ALSA Mixer
Comment=Console running ALSA Mixer
Exec=konsole -e alsamixer -c 0
GenericName[en_GB]=Konsole running ALSA Mixer
GenericName=Konsole running ALSA Mixer
Icon=kmix
MimeType=
Name[en_GB]=Konsole
Name=Konsole
Path=
StartupNotify=true
Terminal=false
TerminalOptions=
Type=Application
X-DBUS-ServiceName=
X-DBUS-StartupType=
X-KDE-SubstituteUID=false
X-KDE-Username=

You can change the icon displayed on the Desktop either by right-clicking on the icon on the Desktop and selecting Properties or by editing the file directly. For example, I specified Icon=/usr/share/icons/mono/scalable/apps/kmix.svgz which looks rather retro and I think suits the unsophisticated looks of ALSA Mixer.

Summary

I have not covered all the options for making it easy to display ALSA channels as well as PulseAudio channels, but hopefully one of the above methods will suit your needs or will spur you to experiment.