Advanced Linux Sound Architecture (ALSA) project homepage
目前最新版本为:
alsa-lib-1.2.2.tar.bz2
alsa-utils-1.2.2.tar.bz2
tar xjf alsa-lib-1.2.2.tar.bz2
cd alsa-lib-1.2.2
./configure --help > alsa_help.txt
获得帮助文档:
Installation directories:
--prefix=PREFIX install architecture-independent files in PREFIX
[/usr]
--exec-prefix=EPREFIX install architecture-dependent files in EPREFIX
[PREFIX]
System types:
--build=BUILD configure for building on BUILD [guessed]
--host=HOST cross-compile to build programs to run on HOST [BUILD]
继续执行命令:
./configure --prefix=$PWD/tmp --host=arm-linux
make && make install
报错:
timer_hw.c: In function 'snd_timer_hw_open':
timer_hw.c:249: error: '__kernel_long_t' undeclared (first use in this function)
timer_hw.c:249: error: (Each undeclared identifier is reported only once
timer_hw.c:249: error: for each function it appears in.)
在内核中搜索到 include/asm-generic/posix_types.h 包含该定义
将它添加到 alsa-lib-1.2.2/src/timer/timer_local.h
#ifndef __kernel_long_t
typedef long __kernel_long_t;
typedef unsigned long __kernel_ulong_t;
#endif
将安装后的头文件、库文件拷贝到编译器和开发板中
# NFS 根文件系统路径
export XHR_NFS_ROOT=/nfsroot/rootfs-1.20.0
cp -r tmp/include/* /usr/local/arm/4.3.2/arm-none-linux-gnueabi/libc/usr/include
cp -rd tmp/lib/*so* /usr/local/arm/4.3.2/arm-none-linux-gnueabi/libc/armv4t/lib
cp -rd tmp/lib/*so* $XHR_NFS_ROOT/lib
tar xjf alsa-utils-1.2.2.tar.bz2
cd alsa-utils-1.2.2
./configure --prefix=$PWD/tmp --host=arm-linux
报错:
checking panel.h usability... no
checking panel.h presence... no
checking for panel.h... no
configure: error: required curses helper header not found
是因为交叉编译alsa-utils默认会生成alsamixer,此时会用到ncurses, 但即使交叉编译了ncurses库并加入alsa-utils调用路径,问题仍然存在。 网友有解释:因为ncurses交叉编译时不支持alsamixer,在交叉编译alsa-utils时加上configure选项:–disable-alsamixer,不再报上述错误。
加入 --disable-alsamixer 能配置通过。
./configure --prefix=$PWD/tmp --host=arm-linux --disable-alsamixer --with-curses=ncurses --disable-xmlto --disable-nls
make && make install
make 时报错:
alsactl.c: In function 'do_nice':
alsactl.c:164: error: 'SCHED_IDLE' undeclared (first use in this function)
alsactl.c:164: error: (Each undeclared identifier is reported only once
alsactl.c:164: error: for each function it appears in.)
在内核中搜索到 include/linux/sched.h 包含该定义
将它添加到 alsa-utils-1.2.2/alsactl/alsactl.h
/*
* Scheduling policies
*/
#define SCHED_NORMAL 0
#define SCHED_FIFO 1
#define SCHED_RR 2
#define SCHED_BATCH 3
/* SCHED_ISO: reserved but not implemented yet */
#define SCHED_IDLE 5
/* Can be ORed in to make sure the process is reverted back to SCHED_NORMAL on fork */
#define SCHED_RESET_ON_FORK 0x40000000
再次 make 报错:
monitor.c: In function 'monitor':
monitor.c:431: error: 'IN_NONBLOCK' undeclared (first use in this function)
monitor.c:431: error: (Each undeclared identifier is reported only once
monitor.c:431: error: for each function it appears in.)
在内核中搜索到 include/linux/inotify.h 包含该定义
将它添加到 alsa-utils-1.2.2/alsactl/list.h
/* Flags for sys_inotify_init1. */
#define IN_CLOEXEC O_CLOEXEC
#define IN_NONBLOCK O_NONBLOCK
再次 make 报错:
alsactl-monitor.o: In function `monitor':
/home/book/xhrStudy/tools/alsa/alsa-utils-1.2.2/alsactl/monitor.c:431:
undefined reference to `inotify_init1'
可能的解决方法:
int inotify_init1(int flags)
{
int flags1 = 0;
int inotify_fd = inotify_init();
if ((inotify_fd != -1) && (flags != 0))
{
if((flags1 = fcntl(inotify_fd, F_GETFL)) != -1)
{
fcntl(inotify_fd, F_SETFL, flags1 | flags);
}
}
return inotify_fd;
}
#define _GNU_SOURCE
#include
#include
int inotify_init1(int flags) {
return syscall(332, flags);
}
原文给出的软中断号是 332,不过我搜索了 3.4.2 内核发现在 arch/arm/kernel/calls.S 中该系统调用号是 360,不知道对不对,记录一下。
arch/arm/kernel/calls.S:372:/* 360 */ CALL(sys_inotify_init1)
arch/arm/include/asm/unistd.h:389:#define __NR_inotify_init1 (__NR_SYSCALL_BASE+360)
可能是 alsa-utils-1.2.2 版本太新,很多符号都未定义,所以决定改用 alsa-utils-1.0.27.2 ,编译方法一样,没有报错,然后将可执行文件拷贝到开发板。
cp -d tmp/bin/* $XHR_NFS_ROOT/bin
cp tmp/sbin/* $XHR_NFS_ROOT/sbin
Announcing ncurses 6.2
(Download) Index of /gnu/ncurses
tar xzf ncurses-6.2.tar.gz
cd ncurses-6.2
./configure --prefix=$PWD/tmp --host=arm-linux --with-shared
make && make install
make 报错:
make[1]: Entering directory ‘/home/book/xhrStudy/tools/alsa/ncurses-6.2/progs’
mkdir -p /home/book/xhrStudy/tools/alsa/ncurses-6.2/tmp/bin
/usr/bin/install -c -s tic /home/book/xhrStudy/tools/alsa/ncurses-6.2/tmp/bin/echo tic| sed 's/$//'|sed 's,x,x,'|sed 's/$//'
strip: Unable to recognise the format of the input file `/home/book/xhrStudy/tools/alsa/ncurses-6.2/tmp/bin/tic’
/usr/bin/install: strip process terminated abnormally
Makefile:202: recipe for target ‘install.progs’ failed
执行的是 /usr/bin/install 显然是安装程序有问题。
vim Makefile 搜索 install 发现第 65 行:
INSTALL = /usr/bin/install -c
root~: grep "echo tic" * -nR
progs/Makefile:176:actual_tic = `echo tic$x| $(TRANSFORM)`
progs/Makefile.in:176:actual_tic = `echo tic$x| $(TRANSFORM)`
弄了一下没解决,有时间再试,先安装 ncurses-5.9 进行使用,安装方法一样,没有报错。
复制头文件、库文件到编译器和根文件系统:
cp -r tmp/include/* /usr/local/arm/4.3.2/arm-none-linux-gnueabi/libc/usr/include
cp -rd tmp/lib/*so* /usr/local/arm/4.3.2/arm-none-linux-gnueabi/libc/armv4t/lib
cp -rd tmp/lib/*so* $XHR_NFS_ROOT/lib
cp -rd tmp/share $XHR_NFS_ROOT$PWD/tmp/
mkdir /dev/snd
cd /dev/snd/
ln -s /dev/controlC0
ln -s /dev/pcmC0D0p
ln -s /dev/pcmC0D0c
使用 arecord 录音
arecord -d 20 -c 2 -t wav -r 44100 -f "Signed 16 bit Little Endian" test.wav
以20秒的间隔(-d 20),立体声(-c 2),频率是 44.1kHz来录制Wave格式音频
使用 aplay 播放录音
aplay test.wav
报错:
/xhr/sound: arecord test.wav
ALSA lib conf.c:4081:(snd_config_update_r) Cannot access file /home/book/xhrStudy/tools/alsa/alsa-lib-1.2.2/tmp/share/alsa/alsa.conf
ALSA lib pcm.c:2642:(snd_pcm_open_noupdate) Unknown PCM default
arecord: main:722: audio open error: No such file or directory
解决方法:在nfs中添加相同路径 /home/book/xhrStudy/tools/alsa/alsa-lib-1.2.2/tmp ,并将lib编译出的share目录放置其中。
Advanced Linux Sound Architecture (ALSA) project homepage
alsa-lib-1.2.2
alsa-utils-1.2.2
undefined reference to `inotify_init1’
Announcing ncurses 6.2
(Download) Index of /gnu/ncurses
ffmpeg 交叉编译 make install: strip: Unable to recognise the format of the input file
解决strip: Unable to recognise the format of the input file问题