Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

After switching from Unity to XFCE, I ran into difficulties with my sound configuration. I have multiple sound cards on my system, the one that I want to use is the last one to be loaded by the kernel. ALSA appears to be using the first one by default.

In addition, I cannot use sound in more than one application concurrently, I get errors like "sound device in use", etc. Can anyone provide me with some insight on the ALSA architecture, the tools I need to use in order to probe the system and advice on how to structure the configuration file.

share|improve this question
    
It would be better to phrase this as a real question, e.g. describe a few problems you're having and act like you didn't know the answer yet. –  slhck Nov 14 '11 at 14:33
    
That makes sense, I've edited the question accordingly –  Gearoid Murphy Nov 14 '11 at 14:44
    
Perfect! In the future, you can also edit your answer instead of deleting and re-posting, if you have anything to add. –  slhck Nov 14 '11 at 14:45

1 Answer 1

The system-wide configuration file is stored in '/etc/asound.conf', all ALSA compliant applications will read this file each time they start. The best place to look to get a sense of your current sound devices is here in '/proc/asound/'. If you don't have a configuration file, ALSA applications will use /proc/asound/card0 as the default sound device. You can check what verison of ALSA you're running here '/proc/asound/version'.

Each sound device has a bunch of 'pcms' associated with it. Each pcm is basically an output channel: "front", "rear", "surround41", "surround51", etc. You can see which pcm channels are available by using this command:

aplay -L | grep CARD

A few of these pcm channels do not correspond to physical audio outputs but are software channels provided by ALSA. The one we're interested in is called 'dmix'. The 'dmix' channel is a software mixer provided by ALSA to handle multiple concurrent input streams.

One thing to note is the use of multiple conventions for identifying a particular sound device. The configuration file will use card0, card1, etc or simply 0, 1, etc. It's also possible to refer to the card by name, such as Creative, Nvidia, etc. These names are defined as soft links in the ALSA proc directory: 'ls -l /proc/asound'. Typically, when referring to a PCM channel in the configuration file, the format is as follows: "channel-name:card-index,sub-index". So, for example, "dmix:2,0" refers to the dmix pcm channel on card 2, sub-device 0. You see the sub devices associated with each sound card by using this command:

aplay -l

The final step is the configuration file itself, located here '/etc/asound.conf'. We need 2 components in this file, a 'pcm' channel definition and a 'ctl' channel definition. The 'pcm' channel defines our output and is responsible for multiplexing multiple sound streams into a single hardware output channel. The 'ctl' channel is used for the mixer and is responsible for controlling volume.

ALSA uses a software pcm channel called a 'plug' which handles the multiplexing. It is a software front-end for a slaved pcm output channel. The slaved pcm output channel must itself be capable of mixing. An example configuration file follows:

pcm.custom
{
    type plug
    slave
    {
        pcm "dmix:2,0"
    }
}

ctl.custom
{
    type hw
    card Creative
}

pcm.!default pcm.custom
ctl.!default ctl.custom

In this case, I'm using the 'dmix' output channel for the 3rd sound device on the system "dmix:2,0". The 3rd index is 2 because it starts from 0 (card0, card1, card2). In addition, 'ctl' schema references the same card but this time using it's soft-linked name 'Creative'.

I hope this is of use to others.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.