alsa-lib 交叉編譯以及音效卡驅動測試
alsa-lib移植筆記
l下載alsa-utils, alsa-lib, 版本要一致
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
變換到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 目錄下已經包含一下裝置
/dev/controlC0 ,/dev/pcmC0D0p , /dev/pcmC0D0c, /dev/mixer, /dev/timer
[[email protected] /]# ls /dev/pcm*
/dev/pcmC0D0c/dev/pcmC0D0p
[[email protected] /]# ls /dev/con*
/dev/console/dev/controlC0
[[email protected]edSky /]# ls /dev/mix*
/dev/mice/dev/mixer
[[email protected] /]# ls /dev/tim*
/dev/timer
測試aplay程式
[[email protected] bin]# ./aplaytest1.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
成功配置後
lAlsa音效卡配置
** alsa音效卡可以正常工作,amixer 設定
*** amixer 用法
#amixer cset numid=Nvalue//設定變數,numid對應contents的id
#amixer cget numid=N//獲取amixer的某個設定
[[email protected] /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音效卡測試
** 播放
[[email protected] /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小端
** 播放的同時錄音
1.分別開兩個終端,其中一個播放, 播放的聲音無斷斷續續等異常
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