ALSA Analysis: Alsa profiles (2)

Source: Internet
Author: User
Tags aliases documentation

There is a good article about ALSA's configuration file.

Thanks to the original.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Understand and use the ALSA configuration file

Author: Liu Xuhui Raymond Reprint please indicate the source http://blog.csdn.net/colorant/archive/2008/06/30/2598815.aspx

Email:colorant@163.com

blog:http://blog.csdn.net/colorant/

Home: http://rgbbones.googlepages.com/

Recently in making audio-related drives, using the ALSA. Process involves some hardware settings and testing, you need to understand the ALSA configuration file writing, a little learning, here put some of their own simple understanding records as follows.

1 related Notes

1.1 Website Resources

Official website of the ALSA project: http://www.alsa-project.org/

Alsa LIB API reference:http://www.alsa-project.org/alsa-doc/alsa-lib/

Syntax for configuration files: http://www.alsa-project.org/alsa-doc/alsa-lib/conf.html

Official documentation for ASOUNDRC: HTTP://WWW.ALSA-PROJECT.ORG/MAIN/INDEX.PHP/ASOUNDRC

In fact, if you look at the above document carefully, you probably don't have to look down my article 8.

Another: about the Alsa-lib API, the online is automatically generated every day the latest version of the API, if you can not confirm the version you use is fully compatible with the latest version, you can look at the alsa-lib bag with the one document. You can execute make doc in the SRC package and build it yourself.

1.2 Working environment

The software version I tested is based on the Alsa 1.0.14 version, and the current version is 1.0.16 (2008-7), but the configuration file should be similar, at least from the documentation point of view.

2 Understanding Configuration Files

2.1 Location of configuration files

The location of the configuration file is determined by the Configure Phase option, but most of the time, the ALSA configuration file is located in:/usr/share/alsa directory, the primary profile is/usr/share/alsa/alsa.conf other files are required, The location is determined by alsa.conf.

There are usually/usr/share/alsa/card and/USR/SHARE/ALSA/PCM two subdirectories that set up card-related parameters, aliases, and some PCM defaults.

In addition, in alsa.conf, the/etc/asound.conf and ~/.ASOUNDRC profiles are often referenced, and these two files are usually the parameters that you need to set up specifically for your individual needs. According to Alsa's official document, after the 1.0.9 version, these two files are no longer necessary or even desirable. At least it is not recommended to use it. However, for me, the use of embedded systems, for simplicity and convenience testing, is precisely the need to modify these two files 8)

2.2 alsa.conf

Some of the main elements of the alsa.conf include the use of hooks to read the two profiles of/etc/asound.conf and ~/.ASOUNDRC:

@hooks [{func load files ["/etc/asound.conf" "~/.ASOUNDRC"] errors false}]

Some default parameters, such as card 0, Device 0, are used as audio devices, and so on, with default PCM set.

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 ...

Set the interface parameters for some plugin built into the ALSA, such as file:

pcm.file {@args [file FORMAT] @args. The FILE {type string} @args. Format {type string default raw} type file SLAVE.PCM null file $FILE format $FORMAT}

The purpose of the file plugin is to store the PCM data stream in a file.

In addition, usually alsa.conf will also load cards/aliases.conf, set some sound card alias, etc., this I do not need.

At the end of the aliases.conf there are also the following:

<confdir:pcm/default.conf> <confdir:pcm/dmix.conf> <confdir:pcm/dsnoop.conf>

Used to read the 3 files listed in the/USR/SHARE/ALSA/PCM directory.

Set the parameters of the default PCM device separately, Dmix is used to implement the software mix in the playback of the built-in Plugin,dsnoop is used to achieve the recording of multi-channel distribution of the built-in plugin.

3 Some configuration and usage examples

3.1 Using Bluetooth devices

Add one of the following A2DP devices to use Bluetooth in/etc/asound.conf

# Device for Bluetooth pcm.bluetooth{type Bluetooth device 00:02:5b:00:c1:a0}

Then call Aplay–d bluetooth sample.wav playback.

Note that in order to use the device, you need to/usr/lib/alsa-lib/libasound_module_pcm_bluetooth.so this Bluetooth plugin library file. This is in the BlueZ-related package, and ALSA itself does not matter. From here, we can also see the name relationship rule between the ALSA's external plugin and the configuration file: libasound_module_pcm_####.so Here is the name you write in the pcm.xxxx of the Conf file.

3.2 Using a non-default sound device channel

On 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, so I added the following configuration:

#device for voice channel pcm.voice{type plug slave{pcm "hw:0,1"}}

How to play a sound through a voice channel: Aplay–d Voice sample.wav

This kind of writing means I through plug this plugin to the audio data automatic sampling rate, channel and other adjustments, the data sent to my No. 0 card of the serial number 1 device.

In fact, if you do not write the above configuration file, you can get the same result with aplay-d "plug:slave= ' hw:0,1" sample.wav.

HiFi channel play sound directly using Aplay sample.wav can be aplay–d default Sample.wav

3.3 Other

Mix sound:

aplay-d Plug:dmix Sample.wav &

You can test the mix of multiple audio data by calling the above command multiple times.

Dump Audio data:

aplay-d "plug: ' File:file=/tmp/dump.bin '" sample.wav

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.