l  下载alsa-utils, alsa-lib, 版本要一致

http://www.alsa-project.org/main/index.php/Download

l  编译alsa-lib

./configure --host=arm-none-linux-gnueabi --disable-python --prefix=/usr/share/arm-alsa/

如果出现下列错误信息,--disable-pyhont

collect2: ld returned 1 exit status

make[3]: *** [smixer-python.la] 错误 1

make[3]: Leaving directory `/home/enzo/work/tq2440/alsa/alsa-lib-1.0.26/

modules/mixer/simple'

make[2]: *** [all-recursive] 错误 1

make[2]: Leaving directory `/home/enzo/work/tq2440/alsa/alsa-lib-1.0.26/

modules/mixer'

make[1]: *** [all-recursive] 错误 1

make[1]: Leaving directory `/home/enzo/work/tq2440/alsa/alsa-lib-1.0.26/

modules'

--with-alsa-inc-prefix和--with-alsa-prefix分别指定了交叉编译util应用所需要的alsa- lib的头文件和库文件;--disable-alsamixer表示不编译生成alsamixer这个应用程序,因为该程序依赖于ncurses这个图 形界面库,目前我们对于该库还不能交叉编译,故放弃

变换到root身份

# sudo su

alsa-lib在make install时还需要交叉编译,因此需要将交叉编译器的路径加入到PATH环境变量中

#export PATH=$PATH:/usr/local/arm/4.3.2/bin && make install

l  编译alsa-utils

./configure --host=arm-none-linux-gnueabi --prefix=/usr/share/arm-alsa/ --with-alsa-inc-prefix=/usr/share/arm-alsa/include --with-alsa-prefix=/usr/share/arm-alsa/lib --disable-xmlto --disable-alsamixer

l  复制alsa-lib, alsa-utils 到开发板

开发板的复制路径不是随便设置,必须和主机编译时相同的路径,否则动态库无法找到某些文件

所以要把/usr/share/arm-alsa文件夹得内容复制到开发板/usr/share/arm-alsa

复制alsa lib到开发板/lib文件夹下

/dev/controlC0 ,/dev/pcmC0D0p , /dev/pcmC0D0c, /dev/mixer, /dev/timer

[root@EmbedSky /]# ls /dev/pcm*

/dev/pcmC0D0c  /dev/pcmC0D0p

[root@EmbedSky /]# ls /dev/con*

/dev/console    /dev/controlC0

[root@EmbedSky /]# ls /dev/mix*

/dev/mice   /dev/mixer

[root@EmbedSky /]# ls /dev/tim*

/dev/timer

测试aplay程序

[root@EmbedSky bin]# ./aplay  test1.wav

ALSA lib confmisc.c:768:(parse_card) cannot find card '0'

ALSA lib conf.c:4246:(_snd_config_evaluate) function snd_func_card_driver returned error: No such file or directory

ALSA lib confmisc.c:392:(snd_func_concat) error evaluating strings

ALSA lib conf.c:4246:(_snd_config_evaluate) function snd_func_concat returned error: No such file or directory

ALSA lib confmisc.c:1251:(snd_func_refer) error evaluating name

ALSA lib conf.c:4246:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory

ALSA lib conf.c:4725:(snd_config_expand) Evaluate error: No such file or directory

ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM default

aplay: main:696: audio open error: No such file or directory

此时需要创建声卡节点到/dev/snd/

需要手动创建节点

if [ ! -d /dev/snd/ ]; then

echo "make snd node."

mkdir /dev/snd

ln -s /dev/pcmC0D0c  /dev/snd/pcmC0D0c

ln -s /dev/pcmC0D0p /dev/snd/pcmC0D0p

ln -s /dev/timer /dev/snd/timer

ln -s /dev/controlC0 /dev/snd/controlC0

ln -s /dev/mixer /dev/snd/mixer

fi

export PATH=$PATH:/usr/share/arm-alsa/bin

export ALSA_CONFIG_PATH=/usr/share/arm-alsa/share/alsa/alsa.conf

# volumn设置声音大小

amixer cset numid=1 45

成功配置后

*** amixer 用法

#amixer cset numid=N  value        //设置变量,numid对应contents的id

#amixer cget numid=N               //获取amixer的某个设置

[root@EmbedSky /mnt]# amixer contents

numid=1,iface=MIXER,name='Master Playback Volume'

; type=INTEGER,access=rw------,values=1,min=0,max=63,step=0

: values=50

numid=7,iface=MIXER,name='Tone Control - Bass'

; type=INTEGER,access=rw------,values=1,min=0,max=15,step=0

: values=0

numid=8,iface=MIXER,name='Tone Control - Treble'

; type=INTEGER,access=rw------,values=1,min=0,max=3,step=0

: values=0

numid=10,iface=MIXER,name='PCM Playback De-emphasis'

; type=ENUMERATED,access=rw------,values=1,items=4

; Item #0 'None'

; Item #1 '32Khz'

; Item #2 '44.1Khz'

; Item #3 '48Khz'

: values=0

numid=5,iface=MIXER,name='Mic Sensitivity'

; type=INTEGER,access=rw------,values=1,min=0,max=7,step=0

: values=1

numid=6,iface=MIXER,name='Mic Volume'

; type=INTEGER,access=rw------,values=1,min=0,max=31,step=0

: values=0

numid=16,iface=MIXER,name='ADC +6dB Switch'

; type=BOOLEAN,access=rw------,values=1

: values=off

numid=17,iface=MIXER,name='ADC Polarity Switch'

; type=BOOLEAN,access=rw------,values=1

: values=off

numid=2,iface=MIXER,name='Capture Volume'

; type=INTEGER,access=rw------,values=1,min=0,max=7,step=0

: values=1

numid=12,iface=MIXER,name='AGC Switch'

; type=BOOLEAN,access=rw------,values=1

: values=off

numid=13,iface=MIXER,name='AGC Target Volume'

; type=INTEGER,access=rw------,values=1,min=0,max=3,step=0

: values=3

numid=14,iface=MIXER,name='AGC Timing'

; type=INTEGER,access=rw------,values=1,min=0,max=7,step=0

: values=0

numid=3,iface=MIXER,name='Analog1 Volume'

; type=INTEGER,access=rw------,values=1,min=0,max=31,step=0

: values=27

numid=4,iface=MIXER,name='Analog2 Volume'

; type=INTEGER,access=rw------,values=1,min=0,max=31,step=0

: values=27

numid=15,iface=MIXER,name='DAC +6dB Switch'

; type=BOOLEAN,access=rw------,values=1

: values=off

numid=18,iface=MIXER,name='DAC Polarity Switch'

; type=BOOLEAN,access=rw------,values=1

: values=off

numid=20,iface=MIXER,name='DC Filter Enable Switch'

; type=BOOLEAN,access=rw------,values=1

: values=off

numid=19,iface=MIXER,name='Double Speed Playback Switch'

; type=BOOLEAN,access=rw------,values=1

: values=off

numid=11,iface=MIXER,name='Input Mux'

; type=ENUMERATED,access=rw------,values=1,items=4

; Item #0 'Differential'

; Item #1 'Analog1'

; Item #2 'Analog2'

; Item #3 'Both'

: values=0

numid=9,iface=MIXER,name='Sound Processing Filter'

; type=ENUMERATED,access=rw------,values=1,items=4

; Item #0 'Flat'

; Item #1 'Minimum1'

; Item #2 'Minimum2'

; Item #3 'Maximum'

: values=0

l  声卡测试

** 播放

[root@EmbedSky /mnt]# aplay sound_check.wav

Playing WAVE 'sound_check.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo

** 录音

播放命令

arecord -d 1 -t wav -c2 -r 8000 -f  S16_LE test1.wav

arecord -d 60 -t wav -c2 -r 8000 -f S16_LE test1.wav

-d  录音时间,单位秒

-c 声道数

-r 采样频率

-f  采样格式, 16bit  小端

** 播放的同时录音

aplay sound_check.wav

另一个随机录音

arecord -d 3 -t wav -c2 -r 8000 -f S16_LE test1.wav

2. 录音1分钟, 另一个终端随机播放, 然后听录音后的文件,没有任何噪声,中断和异常

arecord -d 60 -t wav -c2 -r 8000 -f S16_LE test1.wav

aplay test1.wav

** 双声道录音后播放是否正常(未测试)

** 交叉编译其他程序:
Add included file in program: #include <alsa/asoundlib.h>
~# arm-none-linux-gnueabi-gcc -lasound -L/usr/share/arm-alsa/lib/ -I/usr/share/arm-alsa/include/ -o test my_test.c

05-17 11:30