HOWTO Softvol
From Gentoo Linux Wiki
| Installation • Kernel & Hardware • Networks • Portage • Software • System • X Server • Gaming • Non-x86 • Emulators • Misc |
Contents |
[edit] About this Howto
In this HOWTO I will try to explain how to get a working master volume control on sound cards that usually don't provide any volume controls.
As far as I have read this is mostly the case on USB sound cards so this article will use the driver snd-usb-audio as an example device
but this method should work with any device.
The solution for this is to use softvol - an ALSA plugin which adds one or more custom volume controls to your sound cards mixer. It's only available to ALSA-applications but since many applications depend on OSS and jackd which usually wouldn't have access to a softvol mixer control in a default configuration, there is an extra section for OSS and jackd users.
[edit] What you need
Softvol is an alsa plugin that you should already have when you installed alsa. Just be sure you have the following packages installed:
media-sound/alsa-driver (OR the kernel-driver)
media-sound/alsa-utils
media-libs/alsa-lib
If you have set ALSA_PCM_PLUGINS in /etc/make.conf just add softvol:
| File: /etc/make.conf |
ALSA_PCM_PLUGINS="dmix dsnoop plug asym softvol" |
I recommend not to set ALSA_PCM_PLUGINS to have all plugins installed.
See this ALSA Howto for further information on setting up alsa.
To use sound applications you must be in the audio-group:
gpasswd -a <user name> audio
Relog if you weren't in it.
[edit] ALSA Configuration
As you might know, alsa checks for the existence of the files
/etc/asound.conf and
$HOME/.asoundrc (this file overrides the first one)
I recommend to add the following to your $HOME/.asoundrc :
| File: $HOME/.asoundrc |
pcm.softvol {
type softvol
slave {
pcm "dmix"
}
control {
name "Master"
card 0
}
}
|
Now change the slave pcm of your default pcm to the softvol plugin:
| File: $HOME/.asoundrc |
pcm.!default {
type plug
slave.pcm "softvol"
}
|
[edit] Examples
[edit] One sound card
On my EDIROL UA1EX some more changes were needed:
| File: $HOME/.asoundrc |
pcm.!default {
type plug
slave.pcm "softvol"
}
pcm.dmixer {
type dmix
ipc_key 1024
slave {
pcm "hw:UA1EX"
period_time 0
period_size 1024
buffer_size 4096
rate 48000
}
bindings {
0 0
1 1
}
}
pcm.dsnooper {
type dsnoop
ipc_key 1024
slave {
pcm "hw:UA1EX"
channels 2
period_time 0
period_size 1024
buffer_size 4096
rate 48000
}
bindings {
0 0
1 1
}
}
pcm.softvol {
type softvol
slave {
pcm "dmixer"
}
control {
name "Master"
card UA1EX
}
}
ctl.!default {
type hw
card UA1EX
}
ctl.softvol {
type hw
card UA1EX
}
ctl.dmixer {
type hw
card UA1EX
}
|
[edit] Two sound cards
The next example contains settings for two sound cards involving the snd-hda-intel device whose mixer wasn't detected correctly on my machine (got no Master and PCM controls) so I simply added a softvol control as well.
| File: $HOME/.asoundrc |
#######################
#### snd-usb-audio ####
#######################
pcm.!default {
type plug
slave.pcm "softvol"
}
pcm.dmixer {
type dmix
ipc_key 1024
ipc_perm 0666
slave {
pcm "hw:UA1EX"
channels 2
period_time 0
period_size 1024
buffer_size 4096
rate 48000
}
bindings {
0 0
1 1
}
}
pcm.dsnooper {
type dsnoop
ipc_key 1024
ipc_perm 0666
slave {
pcm "hw:UA1EX"
channels 2
period_time 0
period_size 1024
buffer_size 4096
rate 48000
}
bindings {
0 0
1 1
}
}
pcm.softvol {
type softvol
slave.pcm "dmixer"
control {
name "Master"
card UA1EX
}
}
ctl.!default {
type hw
card UA1EX
}
ctl.softvol {
type hw
card UA1EX
}
ctl.dsnooper {
type hw
card UA1EX
}
ctl.dmixer {
type hw
card UA1EX
}
#######################
#### snd-hda-intel ####
#######################
pcm.intel {
type plug
slave.pcm "softvolintel"
}
pcm.dmixerintel {
type dmix
ipc_key 1025
ipc_perm 0666
slave {
pcm "hw:Intel"
channels 2
period_time 0
period_size 1024
buffer_size 4096
rate 48000
}
bindings {
0 0
1 1
}
}
pcm.dsnooperintel {
type dsnoop
ipc_key 1025
ipc_perm 0666
slave {
pcm "hw:Intel"
channels 2
period_time 0
period_size 1024
buffer_size 4096
rate 48000
}
bindings {
0 0
1 1
}
}
pcm.softvolintel {
type softvol
slave.pcm "dmixerintel"
control {
card Intel
name "Softvol"
}
}
ctl.intel {
type hw
card Intel
}
ctl.dmixerintel {
type hw
card Intel
}
ctl.dsnooperintel {
type hw
card Intel
}
ctl.softvolintel {
type hw
card Intel
}
|
Note: You will have to replace "UA1EX" and "Intel" by the identifier or the number of your sound card. Use the following command to find out the identifier:
aplay -l
The first line should be sth. like this:
card 0: UA1EX [UA-1EX], device 0: USB Audio [USB Audio]
The identifier for .asoundrc is the one after "card X:", not the one in the brackets. I recommend to use the identifier rather than a number if you use more than one sound card, since the order in which your sound cards get numbered might change unless you make their modules load in the same sequence on every boot time.
[edit] Test the new settings
To make the new defined mixer element "Master" appear in your mixer app you will have to close it first. Now start your favourite audio-player and play a sound file (you can also use the command "speaker-test" - just abort it with Ctrl+C after you heard the noise). This is necessary to initialize softvol. Next stop or close the player and open your mixer app (like kmix or alsamixer) - you should see the new master volume now. If adjusting the slider doesn't do anything, the following works for me:
1. close all applications that could use alsa
2. make sure your old mixer settings are deleted:
rm /etc/asound.state rm /var/lib/alsa/asound.state
3. un- and reload your snd-device:
rmmod snd-usb-audio modprobe snd-usb-audio
4. play a sound file and open the mixer
speaker-test # must be aborted with Ctrl+C alsamixer # now lower the volume a bit before playing a sound again
5. go to a second console and play a sound; then try the mixer slider
speaker-test
6. if it worked, save the new mixer settings with
alsactl store
7. make sure the settings are restored at startup. Put the following in /etc/conf.d/local.start:
alsactl restore
If it still doesn't work, rebooting and repeating steps 1-6 might fix it - for me it does.
[edit] OSS and JACK with Softvol
Though this setup works fine for me with any alsa-application, I couldn't get softvol to work with applications - games in particular - that still use OSS for playback. That means the mixer panel didn't do anything here.
[edit] aoss
One solution would be to use aoss - an alsa tool that lets OSS applications use the alsa drivers and settings - including softvol. To install it and make it work with softvol do this:
emerge alsa-oss -av
Add a few lines to your .asoundrc:
| File: $HOME/.asoundrc |
pcm.dsp {
type plug
slave.pcm "softvol"
}
ctl.dsp {
type hw
card UA1EX
}
|
Check if ALSA support for OSS is enabled:
| File: /etc/conf.d/alsasound |
ENABLE_OSS_EMUL="yes" |
If it wasn't restart the init script:
/etc/init.d/alsasound restart
From now on put "aoss" in front of each OSS program:
aoss <program name>
While this might work for you and is by far the easiest solution, I wasn't satisfied by the results. The sound in OSS applications had dropouts from time to time. Moreover. I prefer a system wide setting so I don't need to care if an application is alsa or oss based.
[edit] oss2jack
After some experiments I found out that oss2jack is able to do this. Oss2jack allows OSS applications to make use of the jack sound server.
I moved the instructions for oss2jack to the following site:
HOWTO oss2jack
Note that you will have to start jackd with the following options to let it use the softvol plugin:
jackd -R -dalsa -r48000 -p1024 -Psoftvol -Cdsnooper
instead of
jackd -R -dalsa -r48000 -p1024 -Pdmixer -Cdsnooper
After you have followed this article your softvol "Master" control will be able to adjust the volume of any ALSA, OSS and jackd based application globally and you will gain the possibility to start many OSS applications at the same time. Just skip the part about creating the .asoundrc file, or you will lose your softvol settings.
