What do ALSA devices like "hw:0,0" mean? How do I figure out which to use?

I've searched over and over and can't find any explanation of what "hw:0,0" means. How do I determine the number of my USB audio card? MPD requires me to enter something like this:

audio_output {
        type                    "alsa"
        name                    "Sound Card"
        device                  "hw:0,0"     # optional
        format                  "44100:16:2" # optional
}

If I do "alsamixer -c 1" it opens the USB card's volume control, but that really doesn't help me.

Where can I find a list of device names/numbers on my system? Are they resilient to hardware changes? If I remove card 2, does card 3 become card 2? Are there other ways to identify devices? Where can I find documentation for any of this?


Solution 1:

JohnT's answer gives a good basic. I'll follow it up with how to find the devices on your system. Use aplay -l to get a list of the devices on your system. The hw:X,Y comes from this mapping of your hardware -- in this case, X is the card number, while Y is the device number.

$ aplay -l   # note lower-case "L" option
**** List of PLAYBACK Hardware Devices ****
card 0: T71Space [Terratec Aureon 7.1-Space], device 0: ICE1724 [ICE1724]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: T71Space [Terratec Aureon 7.1-Space], device 1: IEC1724 IEC958 [IEC1724 IEC958]
  Subdevices: 0/1
  Subdevice #0: subdevice #0
card 0: T71Space [Terratec Aureon 7.1-Space], device 2: ICE1724 Surrounds [ICE1724 Surround PCM]
  Subdevices: 3/3
  Subdevice #0: subdevice #0
  Subdevice #1: subdevice #1
  Subdevice #2: subdevice #2

Since these are USB devices that might not always get the same device numbers each time they're plugged in, the hw:X,Y device might change. The simplest answer is, for a desktop system, try the GNOME/KDE/Xfce configuration tools, and see if they're smart enough to pick up the changes.

The complex way, if you're not doing this with a desktop system, gets ... interesting. You might be able to get away with using device aliases instead of the hw:X,Y -- this is what the output of aplay -L shows. The something:CARD=FOO,DEV=Y stuff is the alias, and probably won't change between different device plug-ins, where the X in hw:X,Y might. (Assuming that you're using the same USB dongle each time.)

$ aplay -L
default:CARD=CK804
    NVidia CK804, NVidia CK804
    Default Audio Device
front:CARD=CK804,DEV=0                 # hw:0,0
    NVidia CK804, NVidia CK804
    Front speakers
surround40:CARD=CK804,DEV=0            # hw:0,1
    NVidia CK804, NVidia CK804
    4.0 Surround output to Front and Rear speakers

So your aplay command would become aplay -D front:CARD=CK804,DEV=0 somefile.wav, and you can use the same devicename in your .asoundrc.


If you need something more stable at an even lower level, actual kernel devices, udev is what you want -- it's the system that allows for hotplugging devices into the system. You can write rules for udev (and here's the man page) that will allow devices to get the same devicename when plugged in.

Solution 2:

hw:0,0 specifies the default device, on the default sound card. To access your second soundcard's first device, you would specify hw:1,0. These are specified in your .asoundrc. More on all of this here.