I'm not sure if this deserves a separate answer. I used HSC's answer and the examples at "ALSA Wiki - The Dmix Howto". The Dmix documentation is indeed a bit frustrating.
Here is an example ~/.asoundrc
that works for me. The "bindings" section is unnecessary, but the HOWTO says it helps "multichannel chips work faster" (not sure if I care?). If I bind "0 1 1 0" then it switches the right/left channels. If I bind "0 1 1 1" then I get garbage in my right ear... Apparently ipc_key
is a required parameter; I just chose a random integer.
# example 1
pcm.hw3mix {
type dmix
ipc_key 1939 # must be unique
slave {
pcm "hw:3"
period_time 0
period_size 1024 # must be power of 2
buffer_size 4096
rate 44100
}
bindings {
0 0
1 1
}
}
pcm.!default hw3mix
The last line makes my new hw3mix
the default device.
I simplified the above to:
# example 2
pcm.hw3mix {
type dmix
ipc_key 1939 # must be unique
slave { pcm "hw:3" }
}
pcm.!default hw3mix
and it seems to work just fine.
As suggested on the ALSA Wiki link above, I can further simplify it to:
# example 3
pcm.dsp0 {
type plug
slave.pcm "dmix"
}
pcm.!default dsp0
and this can be further simplified to:
# example 4
pcm.!default {
type plug
slave.pcm "dmix"
}
or even:
# example 5
pcm.!default plug:dmix
However, the last three examples don't allow me to specify parameters for the Dmix plugin. I wanted to create a device which mixes multiple streams to "hw:3". I think this has to be specified as a parameter to Dmix since it is not the default device, so I went with my second example above. In my actual ~/.asoundrc
, there is also a block for "hw:0,0" called "hw0mix", so by changing the comments on the following lines, I can switch the output of (newly created) streams between my headphones and speakers:
#pcm.!default hw0mix
pcm.!default hw3mix
NB: The above refers to devices like "hw:0,0" and "hw:3" ... it was a bit hard to find out how to ensure stable device numbers for my various USB sound devices, I found the instructions here under "Ordering multiple cards of the same type". The configuration consists of one line in a file in /etc/modprobe.d/
. That's how I get numbers like 0 and 3 to refer to the same devices across reboots.
aplay
command have a-D default
, but the first doesn't? What is the meaning of thebindings
section, and what isctl.dmixer
for? Is it possible to mix more than two streams, e.g. if I run threeaplay
commands simultaneously? Why is the "default" device of typeplug
pointing todmixer
, could we just renamepcm.dmixer
aspcm.!default
and avoid the indirection? – Caesarean