ALSA音頻工具編譯安全
1.官網(wǎng)http://www.alsa-project.org下載alsa-lib和alsa-utils
我的版本:alsa-lib-1.0.27.2.tar.bz2 和alsa-utils-1.0.27.2.tar.bz2
2.創(chuàng)建/home/m/3rd/alsa目錄,并在目錄下創(chuàng)建install目錄,接著把壓縮包拷到alsa目錄下
3.編譯alsa-lib步驟
tar -xvf alsa-lib-1.0.27.2.tar.bz2???
cd alsa-lib-1.0.27.2??
CC=arm-none-linux-gnueabi-gcc ./configure --host=arm-linux? --prefix=/home/m/3rd/alsa/install/??
make??
make install?
4.編譯alsa-utils步驟
tar -xvf alsa-utils-1.0.27.2.tar.bz2??
cd alsa-utils-1.0.27.2??
CC=arm-none-linux-gnueabi-gcc ./configure --prefix=/home/m/3rd/alsa/install/ --host=arm-linux --with-alsa-inc-prefix=/home/m/3rd/alsa/install/include --with-alsa-prefix=/home/m/3rd/alsa/install/lib --disable-alsamixer --disable-xmlto --disable-nls??
make??
5.簡單說明
--prefix指定了alsa-lib編譯后的安裝目錄,包含庫和頭文件,編譯alsa-utils時(shí)候要指明它的庫lib和頭文件include的目錄.
alsamixer是圖形化的amixer工具,需要ncurses的支持,在secure CRT中亂碼,怕麻煩用--disable-alsamixer禁用了它.
--disable-xmlto和--disable-nls去掉編譯都不通過,沒去研究為啥.
aplay和arecord是同一個(gè)東東改下名字就可以了
if (strstr(argv[0], "arecord")) { stream = SND_PCM_STREAM_CAPTURE; file_type = FORMAT_WAVE; command = "arecord"; start_delay = 1; direction = stdout; } else if (strstr(argv[0], "aplay")) { stream = SND_PCM_STREAM_PLAYBACK; command = "aplay"; direction = stdin; } else { error(_("command should be named either arecord or aplay")); return 1; }
聲音錄制
arecord幫助提示信息
arecord -l列出聲卡和數(shù)字音頻設(shè)備
-D參數(shù)用于指定音頻設(shè)備PCM
以hwx,x開頭
根據(jù)上面l列出的設(shè)備,如果選擇tvp5158來錄制聲音的話那么pcm設(shè)備就位hw0,0,如果是tlv320aic3x則pcm設(shè)備為hw0,1,sii9135則pcm設(shè)備為hw0,2。
聲卡號(hào),設(shè)備號(hào)
-r指定采樣頻率:5512/8000/11025/16000/22050/32000/44100/48000/64000/88200/96000/176400/192000
-f指定采樣格式上面列出了:cd/cdr/dat/S16_LE/S32_LE/...
arecord -D default:CARD=mcasp0 -d 100000?? -f cd -t raw mysong15.raw
arecord -D default:CARD=mcasp0 -d 100000?? -f dat -t raw mysong10.raw
arecord -D default:CARD=mcasp0 -d 100000?? -f S16_LE -r 16000 -t raw mysong10.raw
arecord -Dhw:0,1 -r8000 -f cd /a/1.wmv
arecord -Dhw:0,0 -r8000 -f S16_LE -c 2 /a/1.wmv??
arecord -Dhw:0,2 -r48000 -f S32_LE -c 2 /a/1.wmv?
========================================================================
聲音播放
========================================================================
aplay幫助提示信息和aplay -l 列出聲卡和數(shù)字音頻設(shè)備
-D參數(shù)用于指定音頻設(shè)備PCM
以hwx,x開頭
根據(jù)上面l列出的設(shè)備,如果選擇tlv320aic3x來播放聲音的話那么pcm設(shè)備就位hw0,1,如果是hdmi則pcm設(shè)備為hw0,0。
聲卡號(hào),設(shè)備號(hào)
-r指定采樣頻率:5512/8000/11025/16000/22050/32000/44100/48000/64000/88200/96000/176400/192000
-f指定采樣格式上面列出了:cd/cdr/dat/S16_LE/S32_LE/...
aplay -Dhw:0,1 -r8000 -f cd /a/1.wmv??
aplay -Dhw:0,1 -r48000 -f cd /a/1.wmv
arecord -Dhw:0,2 -r48000 -f S32_LE -c 2 | aplay -Dhw:0,1 -r48000//一邊采集一邊播放
========================================================================
簡述amixer及其用法
alsamixer是Linux 音頻架構(gòu)ALSA中的Alsa工具的其中一個(gè),用于配置音頻的各個(gè)參數(shù)。
alsamixer是基于文本下的圖形界面的,可以通過鍵盤的上下鍵,左右鍵等,很方便地設(shè)置需要的音量,開關(guān)某個(gè)switch(開關(guān))等等操作。
amixer,是alsamixer的文本模式,即命令行模式,需要用amixer命令的形式去配置你的聲卡的各個(gè)選項(xiàng)。
對于amixer的使用,你首先需要搞懂你要設(shè)置的參數(shù)是哪些,然后才可能去了解,如何去配置對應(yīng)的值,整體來說,相對alsamixer來說,是有點(diǎn)繁瑣,下面簡要介紹其具體用法:
1.查看amixer支持的命令
===================================================================
amixer -h
2.查看可使用的接口
===================================================================
再看看當(dāng)前你的音頻系統(tǒng)(不同的音頻驅(qū)動(dòng)對應(yīng)不同的內(nèi)容和操作接口)提供了那些供你使用的接口去操作
關(guān)于驅(qū)動(dòng)里面已經(jīng)提供了多少接口可以去操作,可以用命令:
amixer contents
查看,比如:
========================================================================
3.如何去設(shè)置某個(gè)參數(shù)
========================================================================
總結(jié)起來就是,先要用get系列命令去看懂有哪些接口,然后再去用set系列的命令,去設(shè)置對應(yīng)你所要設(shè)置的值。
查看獲取某個(gè)設(shè)置項(xiàng)的值用amixer cget? +控制參數(shù)
根據(jù)控制參數(shù)類型設(shè)置控制參數(shù)使用amixer cset +控制參數(shù)+" "+參數(shù)
想要針對某項(xiàng)設(shè)置,比如想要設(shè)置上面的的主音量,master volume,即controls中顯示的:
numid=5,iface=MIXER,name=’PCM Volume’
那么,可以先看看當(dāng)前的值:
# amixer cget numid=5,iface=MIXER,name=’PCM Volume’
numid=5,iface=MIXER,name=’PCM Volume’
; type=INTEGER,access=rw—R–,values=2,min=0,max=27,step=0
: values=27,27
| dBscale-min=-40.50dB,step=1.50dB,mute=0
顯示的是最大的27,假設(shè)想要設(shè)置為25,那么就用cset去設(shè)置:
# amixer cset numid=5,iface=MIXER,name=’PCM Volume’ 25
numid=5,iface=MIXER,name=’PCM Volume’
; type=INTEGER,access=rw—R–,values=2,min=0,max=27,step=0
: values=25,25
| dBscale-min=-40.50dB,step=1.50dB,mute=0
再比如,去將’Mic Supply 的switch關(guān)閉:
# amixer cset numid=12,iface=MIXER,name=’Mic Supply Switch’ Off
numid=12,iface=MIXER,name=’Mic Supply Switch’
; type=ENUMERATED,access=rw——,values=1,items=2
; Item #0 ‘On’
; Item #1 ‘Off’
: values=1
總結(jié)一下用法,就是:
amixer cget??? controls中所輸出的某個(gè)參數(shù)
amixer cset??? controls中所輸出的某個(gè)參數(shù)????? 具體的值(比如,0,1,On,Off等)
【提示】
同上面介紹的的cget/cset系列命令:
controls??????? show all controls for given card
contents??????? show contents of all controls for given card
cset cID P????? set control contents for one control
cget cID??????? get control contents for one control
類似的,還有另外一套sget/sset系列的命令:
scontrols?????? show all mixer simple controls
scontents?????? show contents of all mixer simple controls (default command)
sset sID P????? set contents for one mixer simple control
sget sID??????? get contents for one mixer simple control
也是同樣做法,比如:
通過查看當(dāng)然有哪些選擇可以控制:
# amixer scontrols
Simple mixer control ‘Master’,0
Simple mixer control ‘Master Mode’,0
Simple mixer control ‘Master Mux’,0
Simple mixer control ‘Master Quality’,0
。。。
同理,amixer scontents,可以查看當(dāng)前所有的值,具體就不在這列舉了。
另外,去查看或者配置用sget,比如:
# amixer sget ‘Microphone Input’,0
Simple mixer control ‘Microphone Input’,0
Capabilities: pswitch pswitch-joined
Playback channels: Mono
Mono: Playback [off]
如果想要修改對應(yīng)設(shè)置,用amixer sset ,具體用法是:
amixer sset sID(控制字符串) P(支持的某個(gè)值)
其中sID,就是上面的Simple mixer control后面的那個(gè)字符串,比如’Master Mux’,0
而對其設(shè)置就是,先看看其提供了哪些供你設(shè)置的值:
# amixer sget ‘Master Mux’,0
Simple mixer control ‘Master Mux’,0
Capabilities: enum
Items: ‘Sum’ ‘DAC’ ‘Line’ ‘Mic’
Item0: ‘DAC’
然后比如要設(shè)置成Line的,就可以這樣:
# amixer sset ‘Master Mux’,0 Line
Simple mixer control ‘Master Mux’,0
Capabilities: enum
Items: ‘Sum’ ‘DAC’ ‘Line’ ‘Mic’
Item0: ‘Line’
=======================================================================
amixer設(shè)置音量:
=======================================================================
1.設(shè)置聲卡0左聲道音量為200
amixer cset numid=6,iface=MIXER,name='L ADC VOLUME' 200
2.獲取聲卡0左聲道音量值
root@dvr:~# amixer cget numid=6,iface=MIXER,name='L ADC VOLUME'
numid=6,iface=MIXER,name='L ADC VOLUME'
? ; type=INTEGER,access=rw------,values=1,min=0,max=255,step=0
? : values=200
3.設(shè)置聲卡0右聲道音量為200
amixer cset numid=5,iface=MIXER,name='PCM Volume' 200
4.獲取聲卡0右聲道音量值值
root@dvr:~# amixer cget numid=5,iface=MIXER,name='PCM Volume'
numid=5,iface=MIXER,name='R ADC VOLUME'
? ; type=INTEGER,access=rw------,values=1,min=0,max=255,step=0
? : values=200
5.設(shè)置聲卡1右聲道音量為200
amixer -c 1 cset numid=5,iface=MIXER,name='PCM Volume' 200
6.獲取聲卡1右聲道音量值
root@dvr:~# amixer -c 1 cget numid=5,iface=MIXER,name='PCM Volume'
numid=5,iface=MIXER,name='R ADC VOLUME'
? ; type=INTEGER,access=rw------,values=1,min=0,max=255,step=0
? : values=200
7.設(shè)置聲卡1左聲道音量為200
amixer -c 1 cset numid=6,iface=MIXER,name='L ADC VOLUME' 200
8.獲取聲卡1左聲道音量值
root@dvr:~# amixer -c 1 cget numid=6,iface=MIXER,name='L ADC VOLUME'
numid=6,iface=MIXER,name='L ADC VOLUME'
? ; type=INTEGER,access=rw------,values=1,min=0,max=255,step=0
? : values=200
?
評論