Audio
This chapter describes the common information and instructions of Audio on IoT Yocto, such as listing the audio hardware, using a USB audio device, and so on. Audio on different platforms may have some platform-specific instructions or test results. For example, you will have different audio interfaces on different platforms. Please refer to the platform-specific section for more details.
Note
All cmd operations presented in this chapter are based on the IoT Yocto v22.1, Genio 350-EVK. You might get different operation result depends on what platform you currently use.
ALSA
The implementation of the audio driver follows ALSA project.
You can use aplay
and arecord
to list available sound devices.
aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: mtsndcard [mt-snd-card], device 0: MultiMedia1_PLayback (*) []
Subdevices: 1/1
Subdevice #0: subdevice #0
card 0: mtsndcard [mt-snd-card], device 1: MultiMedia2_PLayback (*) []
Subdevices: 1/1
Subdevice #0: subdevice #0
arecord -l
**** List of CAPTURE Hardware Devices ****
card 0: mtsndcard [mt-snd-card], device 2: DL1_AWB_Record (*) []
Subdevices: 1/1
Subdevice #0: subdevice #0
card 0: mtsndcard [mt-snd-card], device 3: MultiMedia1_Capture (*) []
Subdevices: 1/1
Subdevice #0: subdevice #0
You can find the corresponding device nodes under /dev/snd/
.
ls -l /dev/snd
total 0
drwxr-xr-x 2 root root 60 Jan 1 2010 by-path
crw-rw---- 1 root audio 116, 6 Jan 1 2010 controlC0
crw-rw---- 1 root audio 116, 2 Jan 1 2010 pcmC0D0p
crw-rw---- 1 root audio 116, 3 Jan 1 2010 pcmC0D1p
crw-rw---- 1 root audio 116, 4 Jan 1 2010 pcmC0D2c
crw-rw---- 1 root audio 116, 5 Jan 1 2010 pcmC0D3c
crw-rw---- 1 root audio 116, 33 Jan 1 2010 timer
The default hardware controls are set according to /var/lib/alsa/asound.state
.
You can use alsactl
to store and restore the state.
alsactl restore # Restore file to state
alsactl store # Store state to file
There are some default plugin devices specified in /etc/asound.conf
. Please refer to Asoundrc for more details.
For example, the following configuration creates an alias name, jack_speaker
, which represents /dev/pcmC0D0p
.
Then, you can play the music with the name jack_speaker
by aplay -D jack_speaker
.
pcm.jack_speaker {
type plug
slave {
pcm "hw:mtsndcard,0,0"
channels 2
}
}
For the examples of playback and capture, please refer to each platform section.
USB Audio
On IoT platform, it supports USB audio. You can simply plug in a USB audio device (e.g. USB headset) and check its ID and name before playing or recording something.
aplay -l
**** List of PLAYBACK Hardware Devices ****
card 1: H540 [Logitech USB Headset H540], device 0: USB Audio [USB Audio]
Subdevices: 1/1
Subdevice #0: subdevice #0
arecord -l
**** List of CAPTURE Hardware Devices ****
card 1: H540 [Logitech USB Headset H540], device 0: USB Audio [USB Audio]
Subdevices: 1/1
Subdevice #0: subdevice #0
You can see there is card 1
with the CAPTURE device and the PLAYBACK device.
To play the music:
aplay -D hw:1,0 sample.wav
To record the voice:
arecord -D hw:1,0 -r 48000 -f S16_LE -c 2 sample.wav