December 1, 2014 3 Comments
Up until 2011 the problem of the volume level in ALSA resetting to zero at boot was a common occurrence in my Linux installations. Actually it was a common occurrence in Linux, full stop; search the Web using keywords such as “alsa reset volume” and you’ll find umpteen links. In 2012 the situation improved and I thought the problem had become a thing of the past, but it resurfaced in 2013 on my main laptop and has plagued me through every update since (well, apart from in one release of KDE). Every time I reboot, the ALSA Speaker channel’s volume is zero when I log-in to KDE. And, as KMix is a PulseAudio mixer by default these days, I have to launch ALSAMixer and raise the volume of the Speaker channel manually.
I don’t know if the source of the problem lies in KDE, PulseAudio or ALSA itself. It did disappear after one upgrade to KDE earlier this year (I don’t recall which release of KDE) but returned in the next KDE upgrade, so I suspect it is a KDE issue. In earlier days I could resolve the problem using the commands
alsactrl store and
alsactl restore and similar approaches. However, this time none of those fixes work for me. The problem never bothered me much, as I always connect external speakers to my laptop’s headphone socket when I’m at home, and I don’t want my laptop emitting sounds at the office. Nevertheless, the fact the problem exists niggled me, so I decided to try and fix it. Rather than expending any more effort trying to get the usual approaches to work (the Web is littered with suggested fixes over the years), I decided to reset the Speaker volume to the same level at each boot by using an automatically-launched shell script. The method I use is given below, and should work with either OpenRC or systemd in Gentoo Linux.
1. Create the file
/etc/local.d/20set_alsa_volume.start containing the following:
#!/bin/bash # Reset ALSA Speaker channel on the first sound card to 90% after booting. su -c "amixer -c 0 -- sset Speaker playback 90%" -s /bin/sh fitzcarraldo
(Replace “fitzcarraldo” with your own user name, of course.)
2. Make the script executable:
That’s all there is to it. The volume of the ALSA Speaker channel is always set to 90% after I reboot and login to the desktop environment. KMix remembers the PulseAudio volume setting from the previous session, so I can still avoid blasting the laptop’s speakers.
By the way, the manual pages for the
alsamixer commands make useful reading:
For example, the first audio card (Card 0) in my main laptop has the following controls:
Update (January 29, 2015): I found the cause of the problem: PulseAudio. I edited the file
/usr/share/pulseaudio/alsa-mixer/paths/analog-output.conf as per user agmg‘s January 2013 post Re: [SOLVED] Problems with PulseAudio 3.0 in the PCLinuxOS Forums:
Again, I had to edit the file:
and change this:
switch = mute
volume = off
switch = mute
volume = merge
I realized that editing the
[Element Desktop Speaker]section of the above file, has no effect on the issue. Only the edit to
[Element Speaker]is needed in my case.
In my case this change forces the ALSA Speaker channel volume to 100% after rebooting (irrespective of the volume levels I set via ALSAMixer and KMix before shutdown).
The contents of the file
/usr/share/pulseaudio/alsa-mixer/paths/analog-output.conf also include the following comment:
; See analog-output.conf.common for an explanation on the directives
The contents of the file
analog-output.conf.common include the following comment:
; volume = ignore | merge | off | zero | <volume step> # What to do with this volume: ignore it, merge it into the device ; # volume slider, always set it to the lowest value possible, or always ; # set it to 0 dB (for whatever that means), or always set it to ; # <volume step> (this only makes sense in path configurations where ; # the exact hardware and driver are known beforehand).
So I could have tried
volume = <volume step> instead of
volume = merge, although I have no idea what value
<volume step> would need to be. Anyway, the Bash script
/etc/local.d/20set_alsa_volume.start that I created does the job in a different way without me having to tinker with the troublesome PulseAudio, so I reverted to
volume = off in the file
analog-output.conf and reverted to using
/etc/local.d/20set_alsa_volume.start as explained earlier.