Sound Mixing with the ALSA Dmix Plugin Instead of a Sound Server

I’m sure you have already tried to play multiple sounds simultaneously in which case you probably got a message saying that /dev/dsp is busy. That’s because only one process can open the sound device at a time.

Of course there are different solutions to work around this problem. One possibility is to use a sound server like aRtsd, EsoundD or jackd. Applications will no longer talk directly to the sound device, instead they will send their data to the sound server which will then mix several audio streams for playback by a single audio device.

However, for my purpose a sound server is overkill. There is another way to achieve the same thing with dmix which is a ALSA plugin. I honestly don’t know why they call it a plugin because at least in my ALSA installation it was already integrated and I just had to create a ~/.asoundrc configuration file for my sound chip (snd_intel8x0).

pcm.dmixer {
    type dmix
    ipc_key 1024
    slave {
        pcm "hw:0,0"
        period_time 0
        period_size 1024
        buffer_size 8192
        rate 44100
    }

    bindings {
        0 0
        1 1
     }
}

pcm.dsp0 {
    type plug
    slave.pcm "dmixer"
}

pcm.!default {
    type plug
    slave.pcm "dmixer"
}

pcm.default {
    type plug
    slave.pcm "dmixer"
}

ctl.mixer0 {
    type hw
    card 0
}

The downside of this method is that you have to configure each sound application to use the alsa:dmix plugin. In XMMS this can be done in the Preference window by choosing the ALSA output plugin [libALSA.so] and configuring it to use plug:dmix as audio device. For vlc you have to install an additionally package.

apt-get install vlc-plugin-alsa

Afterwards you can change your ~/.vlc/vlcrc to use the plugin.

[alsa] # ALSA audio output

# ALSA Device Name (string)
alsadev=plug:dmix

The correct settings for other applications can be found with google. This howto could also be of interest.