Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1042612
  • 博文数量: 277
  • 博客积分: 8313
  • 博客等级: 中将
  • 技术积分: 2976
  • 用 户 组: 普通用户
  • 注册时间: 2010-04-22 11:25
文章分类

全部博文(277)

文章存档

2013年(17)

2012年(66)

2011年(104)

2010年(90)

我的朋友

分类: LINUX

2011-08-11 16:38:17

2011-06-24 17:35:58

 

android下面的alsa utils提供三个工具,分别是:
alsa_amixer : 配置
alsa_aplay : 播放 录制
alsa_ctl: : store/restore 配置文件,与asound.conf有关

可以通过alsa_XXX --help 查看详细参数

 

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
【alsa_amixer】

  1. / $ alsa_amixer --help  
  2. Usage: amixer  [command]  
  3. Available options:  
  4. -h,--help this help  
  5. -c,--card N select the card  
  6. -D,--device N select the device, default 'default'  
  7. -d,--debug debug mode  
  8. -n,--nocheck do not perform range checking  
  9. -v,--version print version of this program  
  10. -q,--quiet be quiet  
  11. -i,--inactive show also inactive controls  
  12. -a,--abstract L select abstraction level (none or basic)  
  13. -s,--stdin Read and execute commands from stdin sequentially  
  14. Available commands: //我们主要使用后面四个  
  15. scontrols show all mixer simple controls  
  16. scontents show contents of all mixer simple controls (default command)  
  17. sset sID P set contents for one mixer simple control  
  18. sget sID get contents for one mixer simple control  
  19. controls show all controls for given card  
  20. contents show contents of all controls for given card  
  21. cset cID P set control contents for one control  
  22. 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】

  1. / $ alsa_aplay --help  
  2. Usage: aplay [OPTION]... [FILE]...  
  3. -h, --help help  
  4. --version print current version  
  5. -l, --list-devices list all soundcards and digital audio devices  
  6. -L, --list-pcms list device names  
  7. -D, --device=NAME select PCM by name  
  8. -q, --quiet quiet mode  
  9. -t, --file-type TYPE file type (voc, wav, raw or au)  
  10. -c, --channels=# channels  
  11. -f, --format=FORMAT sample format (case insensitive)  
  12. -r, --rate=# sample rate  
  13. -d, --duration=# interrupt after # seconds  
  14. -M, --mmap mmap stream  
  15. -N, --nonblock nonblocking mode  
  16. -F, --period-time=# distance between interrupts is # microseconds  
  17. -B, --buffer-time=# buffer duration is # microseconds  
  18. --period-size=# distance between interrupts is # frames  
  19. --buffer-size=# buffer duration is # frames  
  20. -A, --avail-min=# min available space for wakeup is # microseconds  
  21. -R, --start-delay=# delay for automatic PCM start is # microseconds   
  22. (relative to buffer size if <= 0)  
  23. -T, --stop-delay=# delay for automatic PCM stop is # microseconds from xrun  
  24. -v, --verbose show PCM structure and setup (accumulative)  
  25. -V, --vumeter=TYPE enable VU meter (TYPE: mono or stereo)  
  26. -I, --separate-channels one file for each channel  
  27. --disable-resample disable automatic rate resample  
  28. --disable-channels disable automatic channel conversions  
  29. --disable-format disable automatic format conversions  
  30. --disable-softvol disable software volume control (softvol)  
  31. --test-position test ring buffer position  
  32. 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   
  33. 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  
  34. S20_3BE U20_3LE U20_3BE S18_3LE S18_3BE U18_3LE  
  35. Some of these may not be available on selected hardware  
  36. The availabled format shortcuts are:  
  37. -f cd (16 bit little endian, 44100, stereo)  
  38. -f cdr (16 bit big endian, 44100, stereo)  
  39. -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】

  1. / $ alsa_ctl --help  
  2. Usage: alsactl  command  
  3. Available global options:  
  4. -h,--help this help  
  5. -d,--debug debug mode  
  6. -v,--version print version of this program  
  7. Available state options:  
  8. -f,--file # configuration file (default /etc/asound.state)  
  9. -F,--force try to restore the matching controls as much as possible  
  10. (default mode)  
  11. -g,--ignore ignore 'No soundcards found' error  
  12. -P,--pedantic do not restore mismatching controls (old default)  
  13. -I,--no-init-fallback  
  14. don't initialize even if restore fails  
  15. -r,--runstate # save restore and init state to this file (only errors)  
  16. default settings is 'no file set'  
  17. -R,--remove remove runstate file at first, otherwise append errors  
  18. Available init options:  
  19. -E,--env #=# set environment variable for init phase (NAME=VALUE)  
  20. -i,--initfile # main configuation file for init phase (default /system/usr/share/alsa/init/00main)  
  21. Available commands:  
  22. store  save current driver setup for one or each soundcards  
  23. to configuration file  
  24. restore  load current driver setup for one or each soundcards  
  25. from configuration file  
  26. init  initialize driver to a default state  
  27. names  dump information about all the known present (sub-)devices  
  28. 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里的配置重新加载

 

阅读(4231) | 评论(0) | 转发(1) |
0

上一篇:(转)vim命令大全

下一篇:(转)Alsa 小结

给主人留下些什么吧!~~