Software mixer with ALSA
The “high definition audio” in my laptop is rather minimal. Apart from the mic not yet working, it has a line out and a single volume control. Thats it.
However, I’d like to have multiple applications use the sound card, for example my music player, eventually some video player or flash, and some system events.
ALSA to the rescue. It’s not easy to configure, but really powerful:
Yes, that is a separate volume slider in my regular mixer for MPD, my music player. Here’s how to do that:
First we’ll need to create a huge /etc/asound.conf:
# the real device
pcm.realdev {
type hw
card 0
device 0
}
# software mixing
pcm.dmixer {
type dmix
ipc_key 3129397
ipc_key_add_uid false
ipc_perm 0666
slave.pcm "realdev"
slave {
period_time 0
period_size 1024
buffer_size 8192
# we're enforcing 44100, since thats what most apps use
rate 44100
}
bindings {
0 0
1 1
}
}
# software volume
pcm.softvol {
type softvol
slave.pcm "dmixer"
control {
name "Software"
card 0
}
}
pcm.mpdvol {
type softvol
slave.pcm "dmixer"
control {
name "MPD"
card 0
}
}
# input
pcm.input {
type dsnoop
ipc_key 3129398
ipc_key_add_uid false
ipc_perm 0660
slave.pcm "realdev"
}
# duplex device
pcm.duplex {
type asym
playback.pcm "softvol"
capture.pcm "input"
}
# default devices
pcm.!default {
type plug
slave.pcm "duplex"
}
pcm.dsp0 {
type plug
slave.pcm "duplex"
}
I won’t go into all the details (I don’t know all of them either), but the basic idea is that I setup the dmixer plugin for software mixing, and attach two software volume controls to it. I’m keeping the permissions to 0666, since my MPD is running as a different user, and I didn’t find a way to say I’d like to have the permission set to group “audio”.
The default device is the regular microphone jack (untested, since there are driver issues with my chipset and recording) and the “Software” volume control.
If you have an ~/.asoundrc you might want to move it out of the way.
Next I need to configure MPD to use its own volume control via /etc/mpd.conf:
audio_output {
type "alsa"
name "my ALSA device"
# 'mpdvol' is the device name I used in asound.conf
device "mpdvol"
}
You’ll probably need to restart all applications currently accessing your audio devices to have them pick up the new config. The new volume control will also only appear after you’ve started an application using it AFAICT. Sometimes you need to restart them twice for the new volume control to be effective. When alsa-utils restores the volume controls after reboot it should work right away.
The “Software” volume control is optional, but that way I can tune down the default applications volumes below the MPD volume if ever needed. Oh, and I think you can safely keep one or all of the software volume controls to maximum without distortion happening (this doesn’t hold for all sound cards, where it’s often best to keep the sliders at ~75% max to avoid distortion)