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

67

26

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?

endolith

Posted 2009-10-11T17:32:47.303

Reputation: 6 626

so what ended up working? – quack quixote – 2009-10-11T22:36:17.033

Switching to PulseAudio worked, sort of. :) But I had to be logged in locally and modify the audio routing. Then I decided MPD sucks and gave up. – endolith – 2009-10-12T04:45:24.553

Actually "hw:1,0" probably worked, but it said the device was in use (by Pulse?) I didn't try the other method, but hopefully this will help others. – endolith – 2009-10-12T04:46:24.130

Answers

53

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.

quack quixote

Posted 2009-10-11T17:32:47.303

Reputation: 37 382

1How can you tell that surround40:CARD=CK804,DEV=0 is hw:0,1? As far as I can tell it is hw:0,0 given that it refers to DEV=0, but in a different configuration (4 channels rather than 2 as in front:CARD=CK804,DEV=0). – zpon – 2017-05-04T05:51:14.037

3Aha! I had been told aplay -L, which doesn't provide the same output as aplay -l. sigh – endolith – 2009-10-11T18:21:46.563

19

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.

John T

Posted 2009-10-11T17:32:47.303

Reputation: 149 037

5

Specifically here: http://www.alsa-project.org/main/index.php/Asoundrc#The_naming_of_PCM_devices

– endolith – 2009-10-11T18:00:40.477