alsa命令和配置

alsa命令和配置


常用命令
### 调节音量
#amixer -h
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
  -R,--raw-volume Use the raw value (default)
  -M,--mapped-volume Use the mapped volume

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#设置内容

amixer controls #列出所有控制项
    numid=4,iface=MIXER,name='ADC ALC Left Volume'
    numid=5,iface=MIXER,name='ADC ALC Right Volume'
    numid=6,iface=MIXER,name='ADC Digital Left Volume'
    numid=7,iface=MIXER,name='ADC Digital Right Volume'
    numid=8,iface=MIXER,name='ADC HPF Cut-off'
    numid=2,iface=MIXER,name='ADC MIC Left Gain'
    numid=22,iface=MIXER,name='ADC MIC Left Switch'
    numid=3,iface=MIXER,name='ADC MIC Right Gain'
    numid=23,iface=MIXER,name='ADC MIC Right Switch'
    numid=20,iface=MIXER,name='ADC MICBIAS Voltage'
    numid=21,iface=MIXER,name='ADC Main MICBIAS'
    numid=19,iface=MIXER,name='ADC Mode'
    numid=1,iface=MIXER,name='I2STDM Digital Loopback Mode'
    numid=17,iface=MIXER,name='AGC Left Approximate Sample Rate'
    numid=18,iface=MIXER,name='AGC Right Approximate Sample Rate'
    numid=11,iface=MIXER,name='ALC AGC Left Max Volume'
    numid=13,iface=MIXER,name='ALC AGC Left Min Volume'
    numid=15,iface=MIXER,name='ALC AGC Left Switch'
    numid=9,iface=MIXER,name='ALC AGC Left Volume'
    numid=12,iface=MIXER,name='ALC AGC Right Max Volume'
    numid=14,iface=MIXER,name='ALC AGC Right Min Volume'
    numid=16,iface=MIXER,name='ALC AGC Right Switch'
    numid=10,iface=MIXER,name='ALC AGC Right Volume'
    numid=25,iface=MIXER,name='DAC HPMIX Volume'
    numid=24,iface=MIXER,name='DAC LINEOUT Volume'
amixer contents #列出所有内容
amixer cset numid=24 30 #设置numid=24的值为30 值的范围可以参考amixer contents上的内容
amixer cset numid=25 2 #设置numid=25的值为2
##################################################################################
### 播放
#aplay -h
-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
-s, --samples=#         interrupt after # samples per channel
-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
-i, --interactive       allow interactive operation from stdin
-m, --chmap=ch1,ch2,..  Give the channel map to override or follow
    --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
    --test-coef=#       test coefficient for ring buffer position (default 8)
                        expression for validation is: coef * (buffer_size / 2)
    --test-nowait       do not wait for ring buffer - eats whole CPU
    --max-file-time=#   start another output file when the old file has recorded
                        for this many seconds
    --process-id-file   write the process ID here
    --use-strftime      apply the strftime facility to the output file name
    --dump-hw-params    dump hw_params of the device
    --fatal-errors      treat all errors as fatal
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 U18_3BE G723_24 G723_24_1B G723_40 G723_40_1B DSD_U8 DSD_U16_LE DSD_U32_LE DSD_U16_BE DSD_U32_BE #可识别的音频采样格式
Some of these may not be available on selected hardware
The available 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)

aplay -l #列出音频设备
**** List of PLAYBACK Hardware Devices ****
card 0: rvacodec [rv-acodec], device 0: ffae0000.i2s-rv1106-hifi ff480000.acodec-0 [ffae0000.i2s-rv1106-hifi ff480000.acodec-0]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
  
aplay test.wav #播放音频
aplay -D default test.wav #默认设备播放
##################################################################################
#保存配置项相关命令
#alsactl -h
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 /var/lib/alsa/asound.state) #指定文件
  -l,--lock        use file locking to serialize concurrent access
  -L,--no-lock     do not use file locking to serialize concurrent access
  -O,--lock-state-file #  state lock file path (default /var/lock/asound.state.lock)
  -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
  -p,--period #    store period in seconds for the daemon command
  -e,--pid-file #  pathname for the process id (daemon mode)

Available init options:
  -E,--env #=#     set environment variable for init phase (NAME=VALUE)
  -i,--initfile #  main configuation file for init phase
                     (default /home/kingkim180/Project/tool/alsa-utils-1.1.5/output/share/alsa/init/00main)
  -b,--background  run daemon in background
  -s,--syslog      use syslog for messages
  -n,--nice #      set the process priority (see 'man nice')
  -c,--sched-idle  set the process scheduling policy to idle (SCHED_IDLE)

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
  nrestore  <card>  like restore, but notify the daemon to rescan soundcards
  init      <card>  initialize driver to a default state
  daemon    <card>  store state periodically for one or each soundcards
  rdaemon   <card>  like daemon but do the state restore at first
  kill      <cmd>   notify daemon to quit, rescan or save_and_quit
  monitor   <card>  monitor control events

alsactl store -f /var/asound.state #将当前配置保存到/var/asound.state目录
alsactl restore -f /var/asound.state #用/var/asound.state 文件恢复配置

alsa 配置文件

可以使用指令export ALSA_CONFIG_PATH=/usr/share/alsa/alsa.conf 指定配置文件目录

配置文件的位置是由Configure阶段的选项来决定的,不过多数时候,Alsa的配置文件位于:/usr/share/alsa目录下,主要配置文件为/usr/share/alsa/alsa.conf 其它文件是否需要,位置在哪,都是由alsa.conf来决定的。

通常会有/usr/share/alsa/card 和/usr/share/alsa/pcm两个子目录,用于设置Card相关的参数,别名以及一些PCM默认设置。

此外,在alsa.conf中,通常还会引用 /etc/asound.conf 和 ~/.asoundrc这两个配置文件,这两个文件通常是放置你个人需要特殊设置的相关参数。

默认的音频配置文件关系如下,部分厂商会有自己的配置文件,可以通过修改配置文件更改相关播放参数。

alsa.conf
	-> /etc/asound.conf
	-> ~/.asoundrc
	-> /cards/aliases.conf
			-> /pcm/default #pcm设备默认配置
			-> /pcm/dmix.conf #混音配置
			-> /pcm/dsnoop.conf #录音多路分发

不足之处,敬请指出,谢谢~


参考资料

理解和使用Alsa的配置文件

alsa 配置文件asound.conf

设置音量大小

alsa插件1

alsa插件2

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值