One ALSA config to rule them all

defaults.pcm.dmix.!rate 48000
defaults.pcm.dmix.!format S32_LE
pcm.multi {
    type multi
    slaves.a.pcm "dmix:PCH"
    slaves.a.channels 2
    slaves.b.pcm "dmix:Loopback"
    slaves.b.channels 2
    bindings.0 { slave a; channel 0; }
    bindings.1 { slave a; channel 1; }
    bindings.2 { slave b; channel 0; }
    bindings.3 { slave b; channel 1; }
}
pcm.both {
    type route
    slave.pcm "multi"
    ttable.0.0 1
    ttable.1.1 1
    ttable.0.2 1
    ttable.1.3 1
}
pcm.!default {
    type asym
    playback.pcm "plug:both"
    capture.pcm "plug:dsnoop:PCH"
}

pcm.loop "plug:\"dsnoop:Loopback,1\""

This configuration, apart from the standard record and playback also features loopback support via the snd-aloop ALSA plugin.

'Huh? What would I use that for?' Bear with me here.

This driver provides a pair of cross-connected devices, forming a full-duplex loopback soundcard.

So, what can this be used for? This allows for a way of "piping" audio through an imaginary soundcard, for example:

~ $ aplay -D hw:2,0 play.wav

and in another terminal:

~ $ arecord -D hw:2,1 record.wav

would play play.wav through the loop playback device (in this case, hw:2,0 - where 2,0 is the card and device identifier, look at /proc/asound/cards), and the second command would record the same sound back from the loop record device, all without you hearing the file on your default output.

Now, what is this used for in the above configuration?

The config defines 2 slaves, a - the audio card and b - the Loopback device. Then it maps the two (stereo) channels of the audio card to the loopback device, and lastly, exposes a loop capture device which allows you to record system sounds.

Example use case: You want to be able to record your desktop but also whatever audio is playing. Usually, you would either need to use PulseAudio or ALSA+JACK. But with this config you just point whatever recording software to the loop record device.

Note that the default recording device (microphone) does not get muxed into loop by default, and is completely independent. This allows you to have two record devices - one for system and one for your microphone.