Transplantation of ALSA Audio Library

Source: Internet
Author: User
Tags bz2

ALSA is a late audio processing library in Linux, mainly for improvements to the existing OSS libraries. Better performance, support for multiple playback sources, and so on. But correspondingly, increased programming complexity.
The old OSS is a standard file IO interface, the device is opened with open, the audio recording is the data IO interface (read/write), the parameters of the device are controlled by IOCTL. They're all system calls. This eliminates the need for additional libraries and configuration files to operate the device. But Alsa is also the ultimate use of open/ Read/write/ioctl, but more operation nodes. More complex. Therefore, in the programming is the use of additional libraries to operate.



Architecture of the ALSA

Official Homepage http://www.alsa-project.org/
Mainly related to programming is
Alsa-lib. ALSA Application Library (most commonly used)
ftp://ftp.alsa-project.org/pub/lib/alsa-lib-1.0.22.tar.bz2
Alsa-driver Some common chips of the ALSA driver code, the general kernel will be integrated.
ftp://ftp.alsa-project.org/pub/driver/alsa-driver-1.0.22.1.tar.bz2
Alsa-firmware a dedicated microcode for some DSP or ASIC (shipped on top of the chip and loaded by Linux into the hardware at startup).
ftp://ftp.alsa-project.org/pub/firmware/alsa-firmware-1.0.20.tar.bz2
Alsa-utils General ALSA Small test tools such as Aplay/arecord playback and recording applet.
ftp://ftp.alsa-project.org/pub/utils/alsa-utils-1.0.22.tar.bz2
Alsa-oss uses the ALSA interface to simulate the old OSS interface.
ftp://ftp.alsa-project.org/pub/oss-lib/alsa-oss-1.0.17.tar.bz2
Where Alsa-driver,alsa-firwware is something that the kernel developer touches, for the hardware that is already running, it usually means that this part has been integrated into the kernel without modification.
And alsa-utils is mainly testing some gadgets.
So for an application developer, or embedded application developer, access to a library libasound that is primarily Alsa-lib compiled.


Linux ALSA Drive Test
Here are the results of my test alsa on Rhel 5, similar on ARM or MIPS Development Board

If you install ALSA, you will see the appropriate devices in/proc:
With Cat/proc/asound/devices
[Root@hxy alsa-lib-1.0.22]# Cat/proc/asound/devices
2:: Timer
3:: Sequencer
4: [0-0]: Raw MIDI
5: [0-1]: Digital audio playback
6: [0-0]: Digital audio playback
7: [0-0]: Digital audio capture
8: [0]: Control



Normally, in your/dev/snd you will see the following device nodes (with the exception of the kernel driver to adjust the endpoint position)
With Ls-l/dev/snd

[Root@hxy alsa-lib-1.0.22]# ls-l/dev/snd
Total 0
CRW-------1 root 116, 8 Mar 2 02:41 controlC0
CRW-------1 root 116, 4 Mar 2 02:41 midic0d0
CRW-------1 root 116, 7 Mar 2 02:41 pcmc0d0c
CRW-------1 root 116, 6 Mar 2 02:41 pcmc0d0p
CRW-------1 root 116, 5 Mar 2 02:41 pcmc0d1p
CRW-------1 root 116, 3 Mar 2 02:41 seq
CRW-------1 root 116, 2 Mar 2 02:41 Timer


Typically, the desktop version already has Alsa-utils installed. You can perform a aplay-h test to see if the output will be tested. If you can come up with a WAV file to test whether the entire environment is working properly.

Here are some examples of using alsa-utils test
Play wave files
Aplay/mnt/nfs/test.wav
Frequency conversion playback, (in order to play the audio with a khz)
Aplay-d Rate_44k/mnt/nfs/test.wav
Recording in 20-second interval (-D-20), Stereo (-C 2), frequency 8000Hz to record wave format audio
arecord-d 20-c 2-t wav-r 8000-f "signed bit Little endian"/mnt/nfs/test.wav
Test mix playback (first play test1.wav and then play Test2.wav)
Aplay-d Plug:dmix_44k/mnt/nfs/test1.wav &
Aplay-d Plug:dmix_44k/mnt/nfs/test2.wav
Set playback gain (0 to 3)
Amixer Set Master 1
Set recording volume (0-31)
Amixer Set Line 10



Embedded Linux under Alsa Library porting.
Porting the ALSA library under Arm-linux/mips LINUX first saves the device-driven node correctly.
Then the main transplant alsa-lib

The transplant of Alsa-lib.
Extract Tar Xvjf alsa-lib-1.0.22.tar.bz2
CD alsa-lib-1.0.22
Generate makefile

./configure--host=arm-linux--prefix= $PWD/. /.. /output/arm-linux--enable-static--enable-shared--disable-python--with-configdir=/usr/local/share-- With-plugindir=/usr/local/lib/alsa_lib


Notice the--with--configdir option here. It will affect the Alsa_config_dir directory in Include/config.h.
It defaults to your--prefix directory. So in-embedded cross compilation will be a desktop path, run in libasoud.so. Will prompt, if comes out this prompt, generally is the Alsa_config_dir path error causes.

ALSA Lib pcm.c:2145: (snd_pcm_open_noupdate) Unknown PCM default

Aplay:main:546:audio open error:no such file or directory

&NBSP
--with-plugindir is the same thing. It is set to Alsa_plugin_dir macros.
 
  Compile make
  install made install
&NBSP
Development Board Publishing Note:
Publish the ALSA Library on the Development Board. In addition to the Libasound.so library, you must also publish alsa.conf to the--with-configdir directory on the board where ALSA points to the directory, Otherwise, "Audio open error:no such file or directory" will be reported.
This file can find the ALSA directory after make install the share in your installation directory, and copy the entire directory to the Development Board.
 
Alsa-utils porting
  decompression: tar xvjf alsa-utils-1.0.22.tar.bz2
   cd alsa-utils-1.0.22
Generate makefile
 /configure--host=arm-linux--prefix= $PWD/.. /.. /output/arm-linux--enable-static--enable-shared   --with-configdir=/usr/local/share-- with-libiconv-prefix= $PWD/. /.. /output/arm-linux cflags= "-i$pwd/. /.. /output/arm-linux/include "ldflags="-l$pwd/. /.. /output/arm-linux/lib-lasound-liconv " --disable-alsamixer--disable-xmlto
 


Note that ldflags here is a must, otherwise you will not find libasound. In addition, Alsamixer is a ncurses program, which is very difficult to transplant in the embedded terminal. So it's canceled.--disable-xmlto is also because the library is not found.

Compiling make
Install make install

This article from Csdn Blog, reproduced please indicate the source: http://blog.csdn.net/lanmanck/archive/2010/08/21/5829143.aspx

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.