相關網站:
Alsa項目的官方網址:http://www.alsa-project.org/
Alsa LIB API Reference:http://www.alsa-project.org/alsa-doc/alsa-lib/
配置文件的語法:http://www.alsa-project.org/alsa-doc/alsa-lib/conf.html
Asoundrc的官方說明文檔:http://www.alsa-project.org/main/index.php/Asoundrc
常用命令:
(一)
在android中通過adb
shell播放一首歌曲:
adb shell am start -a "android.intent.action.VIEW" -t "audio/mp3" -d "file:///storage/sdcard0/Music/hello.mp3"
也可以終端直接使用.
am start -a "android.intent.action.VIEW" -t "audio/mp3"-d
"file:///storage/sdcard0/Music/hello.mp3"
(二)
錄音:
arecord -D plughw:2,0 -r 8000 -c2 -f S16_LE > /data/tests/1channel_test.wav
Recording WAVE 'stdin' : Signed 16 bit Little Endian, Rate 8000 Hz, Stereo
放音:
aplay -D plughw:0,0 -f dat /data/tests/1channel_test.wav
Playing WAVE '/data/tests/1channel_test.wav' : Signed 16 bit Little Endian, Rate 48000 Hz, Stereo
(三)amixer controls
amixer cset numid=1 60:60: 改變numid=1的設備的音量
arecord -Dhw:0,2 -r48000 -f S32_LE -c 2 | aplay -Dhw:0,1 -r48000//一邊採集一邊播放
amixer
cget controls中所輸出的某個參數
amixer cset controls中所輸出的某個參數 具體的值(比如,0,1,On,Off等)
以下轉載自網絡,有更加詳細的解釋.
ALSA音頻工具amixer,aplay,arecord
ALSA音頻工具編譯安裝
========================================================================
1.官網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.創建/home/m/3rd/alsa目錄,並在目錄下創建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時候要指明它的庫lib和頭文件include的目錄.
alsamixer是圖形化的amixer工具,需要ncurses的支持,在secure CRT中亂碼,怕麻煩用--disable-alsamixer禁用了它.
--disable-xmlto和--disable-nls去掉編譯都不通過,沒去研究爲啥.
aplay和arecord是同一個東東改下名字就可以了
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列出聲卡和數字音頻設備
-D參數用於指定音頻設備PCM
以hwx,x開頭
根據上面l列出的設備,如果選擇tvp5158來錄製聲音的話那麼pcm設備就位hw0,0,如果是tlv320aic3x則pcm設備爲hw0,1,sii9135則pcm設備爲hw0,2。
聲卡號,設備號
-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 列出聲卡和數字音頻設備
-D參數用於指定音頻設備PCM
以hwx,x開頭
根據上面l列出的設備,如果選擇tlv320aic3x來播放聲音的話那麼pcm設備就位hw0,1,如果是hdmi則pcm設備爲hw0,0。
聲卡號,設備號
-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 音頻架構ALSA中的Alsa工具的其中一個,用於配置音頻的各個參數。
alsamixer是基於文本下的圖形界面的,可以通過鍵盤的上下鍵,左右鍵等,很方便地設置需要的音量,開關某個switch(開關)等等操作。
amixer,是alsamixer的文本模式,即命令行模式,需要用amixer命令的形式去配置你的聲卡的各個選項。
對於amixer的使用,你首先需要搞懂你要設置的參數是哪些,然後纔可能去了解,如何去配置對應的值,整體來說,相對alsamixer來說,是有點繁瑣,下面簡要介紹其具體用法:
1.查看amixer支持的命令
===================================================================
amixer -h
2.查看可使用的接口
===================================================================
再看看當前你的音頻系統(不同的音頻驅動對應不同的內容和操作接口)提供了那些供你使用的接口去操作
關於驅動裏面已經提供了多少接口可以去操作,可以用命令:
amixer contents
查看,比如:
========================================================================
3.如何去設置某個參數
========================================================================
總結起來就是,先要用get系列命令去看懂有哪些接口,然後再去用set系列的命令,去設置對應你所要設置的值。
查看獲取某個設置項的值用amixer cget +控制參數
根據控制參數類型設置控制參數使用amixer cset +控制參數+" "+參數
想要針對某項設置,比如想要設置上面的的主音量,master volume,即controls中顯示的:
numid=5,iface=MIXER,name=’PCM Volume’
那麼,可以先看看當前的值:
# 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,假設想要設置爲25,那麼就用cset去設置:
# 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關閉:
# 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
總結一下用法,就是:
amixer cget controls中所輸出的某個參數
amixer cset controls中所輸出的某個參數 具體的值(比如,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
也是同樣做法,比如:
通過查看當然有哪些選擇可以控制:
# 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,可以查看當前所有的值,具體就不在這列舉了。
另外,去查看或者配置用sget,比如:
# amixer sget ‘Microphone Input’,0
Simple mixer control ‘Microphone Input’,0
Capabilities: pswitch pswitch-joined
Playback channels: Mono
Mono: Playback [off]
如果想要修改對應設置,用amixer sset ,具體用法是:
amixer sset sID(控制字符串) P(支持的某個值)
其中sID,就是上面的Simple mixer control後面的那個字符串,比如’Master Mux’,0
而對其設置就是,先看看其提供了哪些供你設置的值:
# amixer sget ‘Master Mux’,0
Simple mixer control ‘Master Mux’,0
Capabilities: enum
Items: ‘Sum’ ‘DAC’ ‘Line’ ‘Mic’
Item0: ‘DAC’
然後比如要設置成Line的,就可以這樣:
# amixer sset ‘Master Mux’,0 Line
Simple mixer control ‘Master Mux’,0
Capabilities: enum
Items: ‘Sum’ ‘DAC’ ‘Line’ ‘Mic’
Item0: ‘Line’
=======================================================================
amixer設置音量:
=======================================================================
1.設置聲卡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.設置聲卡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.設置聲卡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.設置聲卡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
========================================================================
參考:http://blog.csdn.net/paomadi/article/details/8866944
Provided by: alsa-utils_1.0.22-0ubuntu5_i386
NAME
arecord, aplay - command-line sound recorder and player for ALSA soundcard driver
SYNOPSIS
arecord [flags] [filename] aplay [flags] [filename [filename]] ...
DESCRIPTION
arecord is a command-line soundfile recorder for the ALSA soundcard driver. It supports several file formats and multiple soundcards with multiple devices. If recording with interleaved mode samples the file is automatically split before the 2GB filesize. aplay is much the same, only it plays instead of recording. For supported soundfile formats, the sampling rate, bit depth, and so forth can be automatically determined from the soundfile header. If filename is not specified, the standard output or input is used. The aplay utility accepts multiple filenames.
OPTIONS
-h, --help Help: show syntax. --version Print current version. -l, --list-devices List all soundcards and digital audio devices -L, --list-pcms List all PCMs defined -D, --device=NAME Select PCM by name -q --quiet Quiet mode. Suppress messages (not sound :)) -t, --file-type TYPE File type (voc, wav, raw or au). If this parameter is omitted the WAVE format is used. -c, --channels=# The number of channels. The default is one channel. -f --format=FORMAT Sample format Recognized sample formats are: S8 U8 S16_LE S16_BE U16_LE U16_BE S24_LE S24_BE U24_LE U24_BE S32_LE S32_BE U32_LE U32_BE FLOAT_LE FLOAT_BE FLOAT64_LE FLOAT64_BE IEC958_SUBFRAME_LE IEC958_SUBFRAME_BE MU_LAW A_LAW IMA_ADPCM MPEG GSM Some of these may not be available on selected hardware There are also two format shortcuts available: -f cd (16 bit little endian, 44100, stereo [-f S16_LE -c2 -r44100] -f dat (16 bit little endian, 48000, stereo) [-f S16_LE -c2 -r48000] If no format is given U8 is used. -r, --rate=#<Hz> Sampling rate in Hertz. The default rate is 8000 Hertz. -d, --duration=# Interrupt after # seconds. A value of zero means infinity. The default is zero, so if this option is omitted then the arecord process will run until it is killed. -s, --sleep-min=# Min ticks to sleep. The default is not to sleep. -M, --mmap Use memory-mapped (mmap) I/O mode for the audio stream. If this option is not set, the read/write I/O mode will be used. -N, --nonblock Open the audio device in non-blocking mode. If the device is busy the program will exit immediately. If this option is not set the program will block until the audio device is available again. -F, --period-time=# Distance between interrupts is # microseconds. If no period time and no period size is given then a quarter of the buffer time is set. -B, --buffer-time=# Buffer duration is # microseconds If no buffer time and no buffer size is given then the maximal allowed buffer time but not more than 500ms is set. --period-size=# Distance between interrupts is # frames If no period size and no period time is given then a quarter of the buffer size is set. --buffer-size=# Buffer duration is # frames If no buffer time and no buffer size is given then the maximal allowed buffer time but not more than 500ms is set. -A, --avail-min=# Min available space for wakeup is # microseconds -R, --start-delay=# Delay for automatic PCM start is # microseconds (relative to buffer size if <= 0) -T, --stop-delay=# Delay for automatic PCM stop is # microseconds from xrun -v, --verbose Show PCM structure and setup. This option is accumulative. The VU meter is displayed when this is given twice or three times. -V, --vumeter=TYPE Specifies the VU-meter type, either stereo or mono. The stereo VU-meter is available only for 2-channel stereo samples with interleaved format. -I, --separate-channels One file for each channel Example: aplay -c 1 -t raw -r 22050 -f mu_law foobar will play the raw file "foobar" as a 22050-Hz, mono, 8-bit, Mu- Law .au file. arecord -d 10 -f cd -t wav -D copy foobar.wav will record foobar.wav as a 10-second, CD-quality wave file, using the PCM "copy" (which might be defined in the user’s .asoundrc file as: pcm.copy { type plug slave { pcm hw } route_policy copy }
SEE ALSO
alsamixer(1), amixer(1)
BUGS
Note that .aiff files are not currently supported.
AUTHOR
arecord and aplay are by Jaroslav Kysela <[email protected]> This document is by Paul Winkler <[email protected]>. Updated for Alsa 0.9 by James Tappin <[email protected]>