Wenton's Linux ALSA Text Commands Page

by
Wenton L. Davis

ALSA has a large array of commands that can be used to perform all kinds of things.  Here is a list of ALSA commands I use:

alsamixer

aplay

arecord

aoss

aplaymidi

arecordmidi

aconnect

How to Use Some of Them

The first thing to do is know what devices you can play sound to:

~> aplay -l

Will return something like:

**** List of PLAYBACK Hardware Devices ****
card 0: PCH [HDA Intel PCH], device 0: ALC662 rev3 Analog [ALC662 rev3 Analog]
  Subdevices: 0/1
  Subdevice #0: subdevice #0
card 1: NVidia [HDA NVidia], device 3: HDMI 0 [HDMI 0]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: NVidia [HDA NVidia], device 7: HDMI 1 [HDMI 1]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: NVidia [HDA NVidia], device 8: HDMI 2 [HDMI 2]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: NVidia [HDA NVidia], device 9: HDMI 3 [HDMI 3]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: NVidia [HDA NVidia], device 10: HDMI 4 [HDMI 4]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: NVidia [HDA NVidia], device 11: HDMI 5 [HDMI 5]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: NVidia [HDA NVidia], device 12: HDMI 6 [HDMI 6]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 2: UMC1820 [UMC1820], device 0: USB Audio [USB Audio]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 3: External [SB Live! 24-bit External], device 0: USB Audio [USB Audio]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

Now be careful - video cards like to lie.  Now that audio can be played out thourgh HDMI, ALSA will list all HDMI ports (and typically will list Digital Ports ad HDMI), whether there is anything connected or not.  Also, many computer monitors do not have speakers, so even when something IS connected, you still won't hear anything.

Next, we have a remarkably similar command:

~> aplay -L


null
    Discard all samples (playback) or generate zero samples (capture)
lavrate
    Rate Converter Plugin Using Libav/FFmpeg Library
samplerate
    Rate Converter Plugin Using Samplerate Library
speexrate
    Rate Converter Plugin Using Speex Resampler
oss
    Open Sound System
pulse
    PulseAudio Sound Server
speex
    Plugin using Speex DSP (resample, agc, denoise, echo, dereverb)
upmix
    Plugin for channel upmix (4,6,8)
vdownmix
    Plugin for channel downmix (stereo) with a simple spacialization
UMC_input_6ch
    UMC1820 surround sound record in channels 0-5 (1-6)
UMC_input_stereo1
    UMC stereo inputs 6,7 (7,8)
UMC_input_stereo2
    UMC1820 stereo inputs 8,9 (9,10 S/PDIF IN)
UMC_input_ch0
    UMC1820 input 0 (Channel 1)
UMC_input_ch1
    UMC1820 input 1 (Channel 2)
UMC_input_ch2
    UMC1820 input 2 (Channel 3)
UMC_input_ch3
    UMC1820 input 3 (Channel 4)
UMC_input_ch4
    UMC1820 input 4 (Channel 5)
UMC_input_ch5
    UMC1820 input 5 (Channel 6)
UMC_input_ch6
    UMC1820 input 6 (Channel 7)
UMC_input_ch7
    UMC1820 input 7 (Channel 8)
UMC_output_6ch
    UMC1820 surround sound output 0-5 (Channels 1-6)
UMC_output_stereo1
    UMC1820 stereo output 6,7 (Channels 7,8)
UMC_output_stereo2
    UMC1820 stereo output 8,9 (Channels 9,10)
UMC_output_stereo3
    UMC1820 stereo output 10,11 (Channels 11,12 S/PDIF OUT)
UMC_output_ch0
    UMC1820 mono output 0 (Channel 1)
UMC_output_ch1
    UMC1820 mono output 1 (Channel 2)
UMC_output_ch2
    UMC1820 mono output 2 (Channel 3)
UMC_output_ch3
    UMC1820 mono output 3 (Channel 4)
UMC_output_ch4
    UMC1820 mono output 4 (Channel 5)
UMC_output_ch5
    UMC1820 mono output 5 (Channel 6)
UMC_output_ch6
    UMC1820 mono output 6 (Channel 7)
UMC_output_ch7
    UMC1820 mono output 7 (Channel 8)
UMC_output_ch8
    UMC1820 mono output 8 (Channel 9)
UMC_output_ch9
    UMC1820 mono output 9 (Channel 10)
sysdefault:CARD=PCH
    HDA Intel PCH, ALC662 rev3 Analog
    Default Audio Device
front:CARD=PCH,DEV=0
    HDA Intel PCH, ALC662 rev3 Analog
    Front output / input
surround21:CARD=PCH,DEV=0
    HDA Intel PCH, ALC662 rev3 Analog
    2.1 Surround output to Front and Subwoofer speakers
surround40:CARD=PCH,DEV=0
    HDA Intel PCH, ALC662 rev3 Analog
    4.0 Surround output to Front and Rear speakers
surround41:CARD=PCH,DEV=0
    HDA Intel PCH, ALC662 rev3 Analog
    4.1 Surround output to Front, Rear and Subwoofer speakers
surround50:CARD=PCH,DEV=0
    HDA Intel PCH, ALC662 rev3 Analog
    5.0 Surround output to Front, Center and Rear speakers
surround51:CARD=PCH,DEV=0
    HDA Intel PCH, ALC662 rev3 Analog
    5.1 Surround output to Front, Center, Rear and Subwoofer speakers
surround71:CARD=PCH,DEV=0
    HDA Intel PCH, ALC662 rev3 Analog
    7.1 Surround output to Front, Center, Side, Rear and Woofer speakers
usbstream:CARD=PCH
    HDA Intel PCH
    USB Stream Output
hdmi:CARD=NVidia,DEV=0
    HDA NVidia, HDMI 0
    HDMI Audio Output
hdmi:CARD=NVidia,DEV=1
    HDA NVidia, HDMI 1
    HDMI Audio Output
hdmi:CARD=NVidia,DEV=2
    HDA NVidia, HDMI 2
    HDMI Audio Output
hdmi:CARD=NVidia,DEV=3
    HDA NVidia, HDMI 3
    HDMI Audio Output
hdmi:CARD=NVidia,DEV=4
    HDA NVidia, HDMI 4
    HDMI Audio Output
hdmi:CARD=NVidia,DEV=5
    HDA NVidia, HDMI 5
    HDMI Audio Output
hdmi:CARD=NVidia,DEV=6
    HDA NVidia, HDMI 6
    HDMI Audio Output
usbstream:CARD=NVidia
    HDA NVidia
    USB Stream Output
sysdefault:CARD=UMC1820
    UMC1820, USB Audio
    Default Audio Device
front:CARD=UMC1820,DEV=0
    UMC1820, USB Audio
    Front output / input
surround21:CARD=UMC1820,DEV=0
    UMC1820, USB Audio
    2.1 Surround output to Front and Subwoofer speakers
surround40:CARD=UMC1820,DEV=0
    UMC1820, USB Audio
    4.0 Surround output to Front and Rear speakers
surround41:CARD=UMC1820,DEV=0
    UMC1820, USB Audio
    4.1 Surround output to Front, Rear and Subwoofer speakers
surround50:CARD=UMC1820,DEV=0
    UMC1820, USB Audio
    5.0 Surround output to Front, Center and Rear speakers
surround51:CARD=UMC1820,DEV=0
    UMC1820, USB Audio
    5.1 Surround output to Front, Center, Rear and Subwoofer speakers
surround71:CARD=UMC1820,DEV=0
    UMC1820, USB Audio
    7.1 Surround output to Front, Center, Side, Rear and Woofer speakers
iec958:CARD=UMC1820,DEV=0
    UMC1820, USB Audio
    IEC958 (S/PDIF) Digital Audio Output
usbstream:CARD=UMC1820
    UMC1820
    USB Stream Output
sysdefault:CARD=External
    SB Live! 24-bit External, USB Audio
    Default Audio Device
front:CARD=External,DEV=0
    SB Live! 24-bit External, USB Audio
    Front output / input
surround21:CARD=External,DEV=0
    SB Live! 24-bit External, USB Audio
    2.1 Surround output to Front and Subwoofer speakers
surround40:CARD=External,DEV=0
    SB Live! 24-bit External, USB Audio
    4.0 Surround output to Front and Rear speakers
surround41:CARD=External,DEV=0
    SB Live! 24-bit External, USB Audio
    4.1 Surround output to Front, Rear and Subwoofer speakers
surround50:CARD=External,DEV=0
    SB Live! 24-bit External, USB Audio
    5.0 Surround output to Front, Center and Rear speakers
surround51:CARD=External,DEV=0
    SB Live! 24-bit External, USB Audio
    5.1 Surround output to Front, Center, Rear and Subwoofer speakers
surround71:CARD=External,DEV=0
    SB Live! 24-bit External, USB Audio
    7.1 Surround output to Front, Center, Side, Rear and Woofer speakers
iec958:CARD=External,DEV=0
    SB Live! 24-bit External, USB Audio
    IEC958 (S/PDIF) Digital Audio Output
usbstream:CARD=External
    SB Live! 24-bit External
    USB Stream Output

Wow, that's a lot.  OK, some explanatin; aplay -l shows the physical devicesthat are easily accessed with device named like "hw:0,0" which is interpreted as "card 0, device 0." aplay -L lists all the vitual devices created by your ~/.asoundrc file.  Mine is rather massive because the UMC1820 ha as many as 18 inputs and 20 outputs, and I have an array of options set up; more than is appropriate for this page.

Next, we can examine the capabilities of each device with a command like:

~> aplay -D hw:3,0 --dump-hw-params /dev/zero

Playing raw data '/dev/zero' : Unsigned 8 bit, Rate 8000 Hz, Mono
HW Params of device "hw:3,0":
--------------------
ACCESS:  MMAP_INTERLEAVED RW_INTERLEAVED
FORMAT:  S16_LE S24_3LE
SUBFORMAT:  STD
SAMPLE_BITS: [16 24]
FRAME_BITS: [32 144]
CHANNELS: [2 6]
RATE: [44100 96000]
PERIOD_TIME: [1000 2972155)
PERIOD_SIZE: [45 131072]
PERIOD_BYTES: [180 524288]
PERIODS: [2 1024]
BUFFER_TIME: (937 5944309)
BUFFER_SIZE: [90 262144]
BUFFER_BYTES: [360 1048576]
TICK_TIME: ALL
--------------------
aplay: set_params:1352: Sample format non available
Available formats:
- S16_LE
- S24_3LE

What the hell is all of that? Most of it is really technical gunk that's outside this scope, but there are a fwe things I want to point out.  First off, aplay is telling us that it is going to read raw data from /dev/zero (which is nothing but zeros in an infinite stream), and it is going to try to treat it as unsigned 8-bit data, with a sample rate of 8KHz, and a monaural audio channel.Back before cell-phones invaded, this was known as "telephone" grade or quality.

Next, it lists the hardware parameters, althought "capabilities" would be a better term for now.  I don't want to go into all of them, but there are a few items of particular interest...

So, as we see, at the end, there are several reasons this audio sample won't play.  But that's fine; we intentionally put in a command that would display the hardware parameters for this particular device.  In this case, that list is what we wanted.  We could now issue a command to aplay to still collect data from /dev/zero as 16-bit data (or 24-bit data), stereo channels, and at a rate of 44100Hz... and all we hear is silence since it is all just zeros, but it would play without error:

aplay -D hw:3,0 -c 2 -f S16_LE -r 44100 /dev/zero

OK, now that we know how to play a file, we probably ought to figure out recording a file.  It's really just about the same; we used -l or -L to list devices we can play to; we can do the same to find recordable inputs:

~> arecord -l
**** List of CAPTURE Hardware Devices ****
card 0: PCH [HDA Intel PCH], device 0: ALC662 rev3 Analog [ALC662 rev3 Analog]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: PCH [HDA Intel PCH], device 2: ALC662 rev3 Alt Analog [ALC662 rev3 Alt Analog]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 2: UMC1820 [UMC1820], device 0: USB Audio [USB Audio]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 3: External [SB Live! 24-bit External], device 0: USB Audio [USB Audio]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

and

~>  arecord -L
null
    Discard all samples (playback) or generate zero samples (capture)
lavrate
    Rate Converter Plugin Using Libav/FFmpeg Library
samplerate
    Rate Converter Plugin Using Samplerate Library
speexrate
    Rate Converter Plugin Using Speex Resampler
oss
    Open Sound System
pulse
    PulseAudio Sound Server
speex
    Plugin using Speex DSP (resample, agc, denoise, echo, dereverb)
upmix
    Plugin for channel upmix (4,6,8)
vdownmix
    Plugin for channel downmix (stereo) with a simple spacialization
UMC_input_6ch
    UMC1820 surround sound record in channels 0-5 (1-6)
UMC_input_stereo1
    UMC stereo inputs 6,7 (7,8)
UMC_input_stereo2
    UMC1820 stereo inputs 8,9 (9,10 S/PDIF IN)
UMC_input_ch0
    UMC1820 input 0 (Channel 1)
UMC_input_ch1
    UMC1820 input 1 (Channel 2)
UMC_input_ch2
    UMC1820 input 2 (Channel 3)
UMC_input_ch3
    UMC1820 input 3 (Channel 4)
UMC_input_ch4
    UMC1820 input 4 (Channel 5)
UMC_input_ch5
    UMC1820 input 5 (Channel 6)
UMC_input_ch6
    UMC1820 input 6 (Channel 7)
UMC_input_ch7
    UMC1820 input 7 (Channel 8)
UMC_output_6ch
    UMC1820 surround sound output 0-5 (Channels 1-6)
UMC_output_stereo1
    UMC1820 stereo output 6,7 (Channels 7,8)
UMC_output_stereo2
    UMC1820 stereo output 8,9 (Channels 9,10)
UMC_output_stereo3
    UMC1820 stereo output 10,11 (Channels 11,12 S/PDIF OUT)
UMC_output_ch0
    UMC1820 mono output 0 (Channel 1)
UMC_output_ch1
    UMC1820 mono output 1 (Channel 2)
UMC_output_ch2
    UMC1820 mono output 2 (Channel 3)
UMC_output_ch3
    UMC1820 mono output 3 (Channel 4)
UMC_output_ch4
    UMC1820 mono output 4 (Channel 5)
UMC_output_ch5
    UMC1820 mono output 5 (Channel 6)
UMC_output_ch6
    UMC1820 mono output 6 (Channel 7)
UMC_output_ch7
    UMC1820 mono output 7 (Channel 8)
UMC_output_ch8
    UMC1820 mono output 8 (Channel 9)
UMC_output_ch9
    UMC1820 mono output 9 (Channel 10)
sysdefault:CARD=PCH
    HDA Intel PCH, ALC662 rev3 Analog
    Default Audio Device
front:CARD=PCH,DEV=0
    HDA Intel PCH, ALC662 rev3 Analog
    Front output / input
usbstream:CARD=PCH
    HDA Intel PCH
    USB Stream Output
usbstream:CARD=NVidia
    HDA NVidia
    USB Stream Output
sysdefault:CARD=UMC1820
    UMC1820, USB Audio
    Default Audio Device
front:CARD=UMC1820,DEV=0
    UMC1820, USB Audio
    Front output / input
usbstream:CARD=UMC1820
    UMC1820
    USB Stream Output
sysdefault:CARD=External
    SB Live! 24-bit External, USB Audio
    Default Audio Device
front:CARD=External,DEV=0
    SB Live! 24-bit External, USB Audio
    Front output / input
usbstream:CARD=External
    SB Live! 24-bit External
    USB Stream Output

And we can even request the hardware parameters, althought the format is just a bit different; we are not collecting data from /dev/zero so we leave it out...

~> arecord -D hw:3,0 --dump-hw-params
Warning: Some sources (like microphones) may produce inaudiable results
         with 8-bit sampling. Use '-f' argument to increase resolution
         e.g. '-f S16_LE'.
Recording WAVE 'stdin' : Unsigned 8 bit, Rate 8000 Hz, Mono
HW Params of device "hw:3,0":
--------------------
ACCESS:  MMAP_INTERLEAVED RW_INTERLEAVED
FORMAT:  S16_LE S24_3LE
SUBFORMAT:  STD
SAMPLE_BITS: [16 24]
FRAME_BITS: [32 48]
CHANNELS: 2
RATE: [44100 96000]
PERIOD_TIME: [1000 2972155)
PERIOD_SIZE: [45 131072]
PERIOD_BYTES: [180 524288]
PERIODS: [2 1024]
BUFFER_TIME: (937 5944309)
BUFFER_SIZE: [90 262144]
BUFFER_BYTES: [360 1048576]
TICK_TIME: ALL
--------------------
arecord: set_params:1352: Sample format non available
Available formats:
- S16_LE
- S24_3LE

which looks very familiar, doesn't it?

And now for something really fun - We can act like we are recording, but we are really going to send the raw data over the network (or internet).  First, our "server" needs to use arecord a stream, but let's also give it specific format, channels, and rate information.  Next, instead of recording to a file, the second half takes the strean and sends it out to a TCP/IP socket, but we will tell it the IP address of the machine that will be receiving it, and the port number:

~> arecord -D hw:3,0 -f S16_LE -c 2 -r 48000 | nc -u 129.168.1.123 5000

Now, we go to the "client" machine which will receive the stream and play it:

~> nc -ul 5000 | aplay -D hw:1,3 -f S16_LE -c 2 -r 48000

and to get really fancy, we can record and hear the stream on the client:

~> nc -ul 5000 | tee record.raw | aplay -D hw:1,3 -f S16_LE -c 2 -r 48000

or we can REALLY go all out and record it to a formatted file instead of raw:

~> nc -ul 5000 | tee <(sox -t raw -r 48000 -e signed -b 16 -c 2 - recording.wav) | aplay -D hw:1,3 -f S16_LE -c 2 -r 48000

And last but not least, let's suppose you want to broadcast to ALL computers on yout network.  I'll skip the discussion about network broadcast addresses, but the server simply selects the network broadcast address instead of the client's specific IP address:

~> arecord -D hw:3,0 -f S16_LE -c 2 -r 48000 | nc -u 192.168.1.255 5000

and all of the listener computers use the same listnening command as before.

Wenton's email (wenton@ieee.org)

home