1. Introduction

ALSA (Advanced Linux Sound Architecture) is a widely-used software framework that provides an API to interact with sound card drivers on Linux.

Although ALSA is a very convenient tool to use, some of its configuration names may be confusing. For example, when we need to select the audio device, its name usually contains some numbers, such as hw:0,0 or hw:2,1.

In this tutorial, we’ll learn what these numbers mean, and how to understand the ALSA device naming convention.

2. List All Audio Devices

First, let’s list all audio devices present on our machine. For that, we’ll use aplay -l:

$ aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: PCH [HDA Intel PCH], device 0: ALC887-VD Analog [ALC887-VD Analog]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: PCH [HDA Intel PCH], device 1: ALC887-VD Digital [ALC887-VD Digital]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: PCH [HDA Intel PCH], device 3: HDMI 0 [HDMI 0]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: PCH [HDA Intel PCH], device 7: HDMI 1 [HDMI 1]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

What we can see is the list of audio hardware devices. Each of them contains the card number and the device number.

Let’s examine what these numbers mean.

3. Convert to hw:X,Y Format

The output above shows the audio device with card ID 0 and device IDs 0, 1, 3, and 7. These are the numbers we need to use for the hw:X,Y ALSA format. The card ID is X, while the device ID is Y.

In our example, if we’d like to use the top device in the list, we’ll use the format hw:0,0 because its card name is 0, and the device name is also 0.

Similarly, if we’d like to use the last device from the list, the ALSA format will be hw:0,7. Lastly, if we have more than one card, we may encounter hw:1,*hw:2,*, and others.

4. Check if the Device Works Correctly

Once we figure out the numbers in hw:X,Y, it’s good practice to check if it selects the audio device correctly.

For that, we’ll use the command aplay -D hw:X,Y <audiofile>, where X and Y are the card and device numbers of the audio device, and <audiofile> is the name of a file to play.

For example, we can test how the device hw:0,0 plays the audiotest.wav file:

$ aplay -D hw:0,0 audiotest.wav 
Playing WAVE 'audiotest.wav ' :

As we can see, there’s no error shown, which means that the interface hw:0,0 exists and the recording should start playing correctly.

Also, we should be able to hear the sound coming from this device itself, contingent on the volume level and other settings. If that’s the case, the audio device has been selected correctly.

5. Conclusion

In this short article, we learned how to understand the hw:X,Y audio device names in the ALSA format on a Linux machine.

First, we looked at how to convert the audio card and device names to the correct ALSA format. After that, we discovered a way to test if we converted the device name correctly.

Comments are closed on this article!