使用alsa-utils調試ALSA驅動

來源:互聯網
上載者:User

2011-06-24 17:35:58

 

android下面的alsa utils提供三個工具,分別是:
alsa_amixer : 配置
alsa_aplay : 播放 錄製
alsa_ctl: : store/restore 設定檔,與asound.conf有關

可以通過alsa_XXX --help 查看詳細參數

 

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
【alsa_amixer】
/ $ alsa_amixer --help Usage: amixer <options> [command] Available options: -h,--help this help -c,--card N select the card -D,--device N select the device, default 'default' -d,--debug debug mode -n,--nocheck do not perform range checking -v,--version print version of this program -q,--quiet be quiet -i,--inactive show also inactive controls -a,--abstract L select abstraction level (none or basic) -s,--stdin Read and execute commands from stdin sequentially Available commands: //我們主要使用後面四個 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 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 

【使用方法】

alsa_amixer controls :列出alsa驅動裡面註冊的所有控制介面。
這些controls是在驅動裡面通過struct snd_kcontrol_new twl4030_snd_controls[] 定義,函數static int twl4030_add_controls(struct snd_soc_codec *codec)來添加的介面。
格式如下:
numid=19,iface=MIXER,name='Analog Capture Volume'

alsa_amixer contents : 列出以上介面的詳細內容,格式如下:
numid=19,iface=MIXER,name='Analog Capture Volume'
; type=INTEGER,access=rw---R--,values=2,min=0,max=5,step=0
: values=5,5
| dBscale-min=0.00dB,step=6.00dB,mute=0

以上,numid是在註冊的時候順序分配的,其他資訊查看驅動裡面的資料結構來瞭解。

我們可以通過兩個命令來讀取和設定相關參數:
cset cID P set control contents for one control
cget cID get control contents for one control
例如:
alsa_amixer cget numid=19,iface=MIXER,name='Analog Capture Volume'
alsa_amixer cset numid=19,iface=MIXER,name='Analog Capture Volume' 5
其實,如果通過alsa_amixer controls擷取到這些controls的numid後,可以直接使用numid來操作,結果一樣:
/ $ alsa_amixer cget numid=19
numid=19,iface=MIXER,name='Analog Capture Volume'
; type=INTEGER,access=rw---R--,values=2,min=0,max=5,step=0
: values=5,5
| dBscale-min=0.00dB,step=6.00dB,mute=0

/ $ alsa_amixer cset numid=19 4
###reg_0x48 ==TWL4030_REG_ANAMIC_GAIN : 0x24
numid=19,iface=MIXER,name='Analog Capture Volume'
; type=INTEGER,access=rw---R--,values=2,min=0,max=5,step=0
: values=4,4
| dBscale-min=0.00dB,step=6.00dB,mute=0

 

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
【alsa_aplay】
/ $ alsa_aplay --help Usage: aplay [OPTION]... [FILE]... -h, --help help --version print current version -l, --list-devices list all soundcards and digital audio devices -L, --list-pcms list device names -D, --device=NAME select PCM by name -q, --quiet quiet mode -t, --file-type TYPE file type (voc, wav, raw or au) -c, --channels=# channels -f, --format=FORMAT sample format (case insensitive) -r, --rate=# sample rate -d, --duration=# interrupt after # seconds -M, --mmap mmap stream -N, --nonblock nonblocking mode -F, --period-time=# distance between interrupts is # microseconds -B, --buffer-time=# buffer duration is # microseconds --period-size=# distance between interrupts is # frames --buffer-size=# buffer duration is # frames -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 (accumulative) -V, --vumeter=TYPE enable VU meter (TYPE: mono or stereo) -I, --separate-channels one file for each channel --disable-resample disable automatic rate resample --disable-channels disable automatic channel conversions --disable-format disable automatic format conversions --disable-softvol disable software volume control (softvol) --test-position test ring buffer position 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 SPECIAL S24_3LE S24_3BE U24_3LE U24_3BE S20_3LE S20_3BE U20_3LE U20_3BE S18_3LE S18_3BE U18_3LE Some of these may not be available on selected hardware The availabled format shortcuts are: -f cd (16 bit little endian, 44100, stereo) -f cdr (16 bit big endian, 44100, stereo) -f dat (16 bit little endian, 48000, stereo) 

錄音參數 S8 U8 S16_LE S16_BE U16_LE U16_B 的詳細解釋:
S是有符號 U是無符號
BE是大端
LE是小端
這都是PCM的一種表示範圍的方法,所以表示方法中最小值等價,最大值等價,中間的資料層級就是對應的進度了,可以都映射到-1~1範圍。
S8: signed 8 bits,有符號字元 = char, 表示範圍 -128~127
U8: unsigned 8 bits,無符號字元 = unsigned char,表示範圍 0~255
S16_LE: little endian signed 16 bits,小端有符號字 = short,表示範圍 -32768~32767
S16_BE: big endian signed 16 bits,大端有符號字 = short倒序(PPC),表示範圍 -32768~32767
U16_LE: little endian unsigned 16 bits,小端無符號字 = unsigned short,表示範圍 0~65535
U16_BE: big endian unsigned signed 16 bits,大端無符號字 = unsigned short倒序(PPC),表示範圍 0~65535

還有S24_LE,S32_LE等,都可以表示數位方法,PCM都可以用這些表示。
上面這些值中,所有最小值-128, 0, -32768, -32768, 0, 0對應PCM描敘來說都是一個值,表示最小值,可以量化到浮點-1。所有最大值也是一個值,可以量化到浮點1,其他值可以等比例轉換。

 

example:
alsa_aplay -C -t wav -c 2 -r 44100 -f S16_LE -d 10 -v record.wav
alsa_aplay record.wav
-C: record
-t, --file-type TYPE file type (voc, wav, raw or au)
-c, --channels=# channels
-f, --format=FORMAT sample format (case insensitive)
-r, --rate=# sample rate
-d, --duration=# interrupt after # seconds
-v, --verbose show PCM structure and setup (accumulative)

 

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
【alsa_ctl】
/ $ alsa_ctl --help Usage: alsactl <options> command Available global options: -h,--help this help -d,--debug debug mode -v,--version print version of this program Available state options: -f,--file # configuration file (default /etc/asound.state) -F,--force try to restore the matching controls as much as possible (default mode) -g,--ignore ignore 'No soundcards found' error -P,--pedantic do not restore mismatching controls (old default) -I,--no-init-fallback don't initialize even if restore fails -r,--runstate # save restore and init state to this file (only errors) default settings is 'no file set' -R,--remove remove runstate file at first, otherwise append errors Available init options: -E,--env #=# set environment variable for init phase (NAME=VALUE) -i,--initfile # main configuation file for init phase (default /system/usr/share/alsa/init/00main) Available commands: store <card #> save current driver setup for one or each soundcards to configuration file restore <card #> load current driver setup for one or each soundcards from configuration file init <card #> initialize driver to a default state names <card #> dump information about all the known present (sub-)devices into configuration file (DEPRECATED) 

主要用到兩個命令:
alsa_ctl store : 將當前音頻配置參數設定匯出到檔案 /system/etc/asound.conf

我們可以直接修改此檔案進行系統初始化配置,當然別忘了在init.rc裡面添加一個命令:

#####add to init.rc 
service asound_conf /system/bin/alsa_ctl restore
        oneshot

alsa_ctl restore : 將檔案 /system/etc/asound.conf裡的配置重新載入

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.