Understanding and using
ALSA
Configuration FileAuthor: Liu Xuhui Raymond reprinted please indicate the source email: colorant@163.com blog: http://blog.csdn.net/colorant/main page: http://rgbbones.googlepages.com/ recently in Audio-related driver, using ALSA. Some hardware settings and tests are involved in the process. You need to know how to write the Alsa configuration file and learn a little about it. Here we record some of our simple understandings as follows.
1. Description
1.1 website resourcesALSA project Official Website: http://www.alsa-project.org/Alsa lib api reference: Role in fact, if you carefully read the above documentation, probably do not need to read my article 8) Another: for the Alsa-lib API, the latest version of the API is automatically generated on the Internet every day. If you cannot confirm whether your version is fully compatible with the latest version, you can refer to the document included in the Alsa-lib package. You can execute make doc in the SRC package and build it by yourself.
1.2 Working EnvironmentThe software version I tested is based on ALSA 1.0.14, and the latest version is 1.0.16 (2008-7). However, this part of the configuration file should be similar, at least in the document.
2. Understand the configuration file
2.1 Location of the configuration fileThe location of the configuration file is determined by the options in the configure phase. However, most of the time, the Alsa configuration file is located in the/usr/share/ALSA directory, the main configuration file is/usr/share/ALSA. whether or not other files in conf are required and where the files are located is determined by ALSA. conf. The/usr/share/ALSA/card and/usr/share/ALSA/PCM subdirectories are usually used to set card-related parameters, aliases, and some PCM default settings. In addition, in ALSA. conf, the/etc/asound. conf and ~ /. Asoundrc. These two configuration files are usually placed with parameters that you need to set. According to the official ALSA documents, after version 1.0.9, these two files are no longer necessary or even unnecessary. At least it is not recommended. However, for me to use it in an embedded system, we need to modify these two files for simplicity and convenience of testing)
2.2 ALSA. confThe main contents of ALSA. conf include: the/etc/asound. conf and ~ are read by hook ~ /. Asoundrc: @ hooks [{func load files ["/etc/asound. conf ""~ /. Asoundrc "] errors false}] some default PCM parameters are set, such as card 0 by default and device 0 as the audio device. Defaults. CTL. Card 0 defaults. PCM. Card 0 defaults. PCM. device 0 defaults. PCM. subdevice-1 defaults. PCM. nonblock 1 defaults. PCM. ipc_key 5678293... Some plug-in interface parameters are set in ALSA, such as file: PCM. file {@ ARGs [file format] @ args. file {type string} @ args. format {type string default raw} type file slave. PCM null File $ File Format $ format} file plugin stores PCM data streams to files. In addition, ALSA. conf usually loads cards/aliases. conf and sets some sound card aliases. I don't need this anymore. In aliases. the end of conf is as follows: <confdir: PCM/default. conf> <confdir: PCM/dmix. conf> <confdir: PCM/dsnoop. conf> is used to read the three files listed in the/usr/share/ALSA/PCM directory and set the relevant parameters of the default PCM device respectively, dmix is a built-in plug-in for implementing software sound mixing during playback, while dsnoop is a built-in plug-in for implementing multi-channel distribution during recording.
3. Configure and use instances
3.1 Use a bluetooth deviceIn/etc/asound. add the following a2dp device used for Bluetooth in conf # device for systthpcm. bluetooth {type bluetooth device 00: 02: 5b: 00: C1: A0} and then call aplay-D Bluetooth sample.wav to play the video. Note that to use this device, you need the/usr/lib/ALSA-lib/libasound_module_pcm_bluetooth.so Bluetooth plugin library file. This is in the bag related to bluez and has nothing to do with ALSA itself. Here, we can also see the naming rules for the external plug-in of ALSA and the configuration file: libasound_module_pcm _####. so here #### is the PCM In the conf file. XXXX.
3.2 use a non-default sound card device ChannelOn my board, buildin's audio hardware implements two hardware channels in the Alsa subsystem: one is the HIFI channel and the other is the voice channel. Therefore, I added the following Configuration: # device for voice channelpcm. voice {type plug slave {PCM "HW: 0, 1"} method of calling the sound through the voice channel: the format of aplay-D voice sample.wav indicates that after I adjust the audio data sampling rate and channel through plug-in, send data to the device with the serial number 1 of my 0th cards. In fact, if you do not write the above configuration file, use aplay-d "plug: slave = 'hw: '" sample.wav to get the same result. The hifi channel directly uses aplay sample.wav to play the audio, that is, aplay-D default sample.wav.
3.3 othersSound mixing: aplay-D plug: dmix sample.wav & you can call the preceding command multiple times to test the sound mixing of multiple audio data. Dump audio data: aplay-d "plug: 'file: file =/tmp/dump. bin'" sample.wav