您的位置:首页 > 其它

使用alsa-utils调试ALSA驱动

2011-06-24 14:19 363 查看
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里的配置重新加载
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: