ALSA音频的移植,编译与测试(仍在研究中)

ALSA是目前Linux系统上大量采用的音频设备库,通过Alsa架构能分离驱动和应用的开发。Alsa为上层提供API的同时,也为下层提供了接口,在内核配置的时候指定“支持Alsa”就能得到内核支持,具体位置为:

Menuconfig -> Device Drivers -> Soundcard support -> Advanced Linux Sound Architecture

有了Alsa内核驱动,我们还需要Alsa Lib和Alsa Util的支持,这3者的关系如下图所示:

Alsa Util

-------------

Alsa lib

-------------

Alsa Driver

Alsa Util是纯应用层的软件,相当于Alsa设备的测试程序,AlsaLib则是支持应用API的中间层程序。移植Alsa程序的顺序就是先后移植Driver,Lib,Util。


ALSA下载主页:http://www.alsa-project.org/main/index.php/Download


一.Alsa Lib移植

1.编译alsa-lib

cd /home/pingle/BackUp/alsa-tools/alsa-lib-1.0.15/

$ ./configure --prefix=/home/pingle/alsa/ AR=mipsel-openwrt-linux-uclibc-ar CC=mipsel-openwrt-linux-uclibc-gcc CXX=mipsel-openwrt-linux-uclibc-g++ CXX=mipsel-openwrt-linux-uclibc-g++ --host=mipsel-openwrt-linux-uclibc --enable-shared=yes --enable-static=no --target=mipsel-openwrt-linux-uclibc --with-debug=no --with-alsa-devdir=/dev --with-softfloat --with-configdir=/usr/local/share LDFLAGS="-lm"

make
make install


2.编译alsa-utils

cd /home/pingle/BackUp/alsa-tools/alsa-utils-1.0.15/

./configure --prefix=/home/pingle/alsa/ AR=mipsel-openwrt-linux-uclibc-ar CC=mipsel-openwrt-linux-uclibc-gcc CXX=mipsel-openwrt-linux-uclibc-g++ CXX=mipsel-openwrt-linux-uclibc-g++ --host=mipsel-openwrt-linux-uclibc CPPFLAGS="-I/home/pingle/alsa/include" LDFLAGS="-L/home/pingle/alsa/lib" --disable-alsamixer

make
make install

1)--host指定编译器,这里指定为在目标板所运行的交叉编译器。注意运行本配置命令前务必保证编译器已经可以在Shell下直接执行了。

2)--prefix指定编译后文件的安装路径,后续的安装命令会在该目录中创建lib和include两个目录

3)若编译make install时报错:"mipsel-linux-ranlib command not found",解决方案为:执行make install之前,先用下su命令取得root权限。然后再执行make install

二.lib和util安装到嵌入式平台

在目标板上,以下文件必须被拷贝至对应位置

1)lib库文件,放在 /lib/中

2)conf文件,应放在/usr/local/share中,与编译时指定的目录相同

3)应用文件,util能产生aplay,amixer,arecord可执行程序,这些文件可放在/usr/sbin中

4)必须保证有/dev/snd/目录中,此目录下应包含以下几个设备文件(驱动),controlC0, pcmC0D0c, pcmC0D0p, timer如果这些文件已经在/dev/下,可拷贝到snd目录中。或者建立相应符号链接,

ln -s /dev/pcmC0D0c /dev/snd/pcmC0D0c
ln -s /dev/controlC0 /dev/snd/controlC0
ln -s /dev/timer /dev/snd/timer


三.运行测试程序

export ALSA_CONFIG_PATH=/usr/share/alsa/alsa.conf
未添加环境变量前出现的错误:
~ # ./aplay
ALSA lib conf.c:2827:(snd_config_hook_load) cannot access file /usr/share/arm-alsa/share/alsa/cards/aliases.conf
ALSA lib pcm.c:1959:(snd_pcm_open_conf) Invalid type for PCM default definition (id: default, value: cards.pcm.default)
aplay: main:533: audio open error: Invalid argument
~ # ./aplay
ALSA lib pcm.c:2090:(snd_pcm_open_noupdate) Unknown PCM default
aplay: main:533: audio open error: No such file or directory

编译报错:can't load library 'libpthread.so.0'。
解决方案:在openwrt中的make menuconfig中加入libpthread支持。

编译报错:fatal error: alsa/asoundlib.h: No such file or directory compilation terminated.
解决方案:mipsel-openwrt-linux-uclibc-gcc -lasound -L/home/pingle/alsa/lib -I/home/pingle/alsa/include -o test_audio2 test_audio02.c



四.回顾驱动程序

还是oss驱动接口调用比较好理解,不过终于找到了这个图,一看就啥都明白了


period(周期)
:硬件中中断间的间隔时间。它表示输入延时。
声卡接口中有一个指针来指示声卡硬件缓存区中当前的读写位置。只要接口在运行,这个指针将循环地指向缓存区中的某个位置。
frame size = sizeof(one sample) * nChannels
alsa中配置的缓存(buffer)和周期(size)大小在runtime中是以帧(frames)形式存储的。
period_bytes = frames_to_bytes(runtime, runtime->period_size);
bytes_to_frames()

The period and buffer sizes are not dependent on the sample format because they are measured in frames; you do not need to change them.

五.小技巧:
1.经过yaff文件系统烧入用户文件到板子上:
在/home/pingle/kernal/ws04/build_dir/target-mipsel_uClibc-0.9.32/root-xburst目录下加入自己的文件;

然后:
$cd /home/pingle/Yaff/linux-2.6.24.3/fs/yaffs2/utils
(可能要make一下哦!)
$./mkyaffs2image 1 /home/pingle/kernal/ws04/build_dir/target-mipsel_uClibc-0.9.32/root-xburst /home/pingle/desktop/xburst-tools-ws10/image/rootfs.yaffs2
(参数) (rootfs的目录) (生成的文件yaffs系统存到的目录)

2.uboot下检测内存命令:mtest.




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值