ref : https://blog.csdn.net/outstanding_yzq/article/details/8126350
A .alsa-utils Introduction
ALSA is a sound driver in the kernel. It includes the core and other alsa sound card driver.
alsa-utils alsa is a kit, which contains the sound test and audio editing tools.
Two mounting .alsa-utils
1.RPM packet mode
Turbolinux 10.5,11 version already contains alsa-utils rpm package, you can directly install:
# rpm -ivh alsa-utils-xxx.rpm
2. Source packet mode
download link:
http://www.alsa-project.org/main/index.php/Download
Source Package Mounting Method:
# tar zxvf alsa-utils-1.0.6.tar.gz
# cd alsa-utils-1.0.6
# ./configure
# make install
The use of three .alsa-utils tools
Alsa-utils tools included are:
alsactl, aconnect, alsamixer, amidi, amixer, aplay, aplaymidi, arecord, arecordmidi,
aseqnet, iecset, speaker-test
1.alsactl use
alsactl alsa sound drivers used to be some advanced settings. system equipped with multiple sound cards, it can also support.
Sometimes options can not adjust the volume control panel, you can use alsactl to achieve.
alsactl may be specified by the driver of the sound card settings information to a configuration file. specified or restore from a configuration file
Setting the sound card driver information.
alsactl format:
alsactl [options] [store|restore] <card # or id>
Options:
-h, --help
Print Help
-f, --file
Specify the configuration file, the default is /etc/asound.state.
Select the configuration file to use. The default is
/etc/asound.state
-F, --force
Used with the restore command. Setup value of the maximum recovery.
-d, --debug
Debug mode, the output for more details.
-v, --version
Print alsactl version number.
file:
/etc/asound.state (or use the -f file specified) have saved all sound mixer setup information.
Example:
# Rm-f /etc/asound.state
# alsactl store
2.aconnect use
The connection manager is aconnect ALSA sequencer. for connecting or disconnecting the port on ALSA sequencer. port
Free to define.
As used aconnect device can connect to any port established by aseqview.
Format:
aconnect [-d] [-options] sender receiver
aconnect -i|-o [-options]
aconnect -x
Options:
Connection Management
-d, --disconnect
Disconnect.
-e, --exclusive
Use port exclusive mode. The transmit and receive port can not be connected to other ports.
-r, --real queue
The time stamp packet, the current value is converted to the real time queue.
Display Port
-i, --input
Display input port exists.
-o, --output
Display output port exists.
-l, --list
Displays the current connection state.
Delete Connection
-x, --removeall
Delete all connections.
Example:
Connection port 64: 0 to 65: 0:
% aconnect 64:0 65:0
This connection is unidirectional, sent to all the ports 64: 0 data, will be redirected to the received 65: port 0 if there is another port 65: 1,
Also use 64: 0 as the transmitting port, then the data is sent simultaneously to two receiving ports.
Port connection, use:
% aconnect -d 64:0 65:0
Address can also be used to replace the name of the client:
% aconnect External:0 Emu8000:1
Printing using the input port information -i.-O print out the output port information.
% aconnect -i
client 0: ’System’ [type=kernel]
0 ’Timer ’
1 ’Announce ’
client 64: ’External MIDI-0’ [type=kernel]
0 ’MIDI 0-0 ’
可以使用-x选项来清除所有的连接.
% aconnect -x
3.alsamixer的使用
alsamixer是一个终端界面的声卡音量调节器.如图:
命令格式:
alsamixer [options]
选项:
-h, -help
显示帮助信息.
-c <card number or idenfication>
指定需要设置的声卡.默认为0.
-D <device identification>
选择需要控制的调节器.
-g
设置界面颜色.
-s
最小化界面窗口.
快捷键:
进入alsamixer界面后,可以使用下面快捷键进行控制:
常规控制:
左右箭头或n,p 用来选择通道.
上下箭头或+,- 同时调整选定通道的左右声道的音量.
B,= 设置左右声道音量相同.
M 静音当前通道.<,>分别对左,右声道静音.
空格 选择录音源.在选定的通道上按"空格",可以标记此通道为录音源.此操作仅限
输入设备.插入键或";",删除键或"'"分别选定左右通道.
L 刷新屏幕.
快捷设置
PageUp 增大5格音量.
PageDown 减小5格音量.
End 设置音量为0.
分别调整左,右或整个通道的音量.
Q,W,E 增大 左,右,通道 的音量.
Z,X,C 减小 左,右,通道 的音量.
alt-q,ESC 退出.
4.amidi的使用
amidi的作用是对ALSA的RawMIDI端口进行读写.
amidi是一个命令行工具,允许你以独占模式向MIDI设备读/写数据.
命令格式:
amidi options
选项:
-h,-V,-l,-L 用于显示信息.
-s,-r,-S,-d 用于发送/接收数据.
-h, --help
打印帮助信息.
-V, --version
打印版本号.
-l, --list-devices
打印所有硬件MIDI端口的列表.
-L, --list-rawmidis
打印所有RawMIDI定义.
-p, --port=name
设置要使用的ALSA RawMIDI端口.若不指定,则使用声卡0的端口0.
-s, --send=filename
发送指定文件的内容到MIDI端口.文件中必须包含raw MIDI命令(.syx,.mid文件).
-r, --receive=filename
将MIDI端口接收的数据写入指定文件.
-S, --send-hex="..."
发送十六进制字节到MIDI端口.
-d, --dump
从MIDI端口接收数据,然后以十六进制形式打印出来.
-t, --timeout=秒
指定超时,当端口无数据输出达到超时时长时,将停止接收数据.
示例:
amidi -p hw:0 -s my_settings.syx
发送my_settings.syx终端MIDI命令到端口 hw:0.
amidi -S ’
发送XG复位到默认端口.
amidi -p virtual -d
建立一个虚拟RawMIDI端口,然后发送所有数据到这个端口.
5.amixer的使用
amixer是命令行的ALSA声卡驱动调节器工具.
amixer用来在命令行控制ALSA的调节器,并且支持多声卡.
amixer不加参数时,将打印默认声卡的设置信息.
命令格式:
amixer [-c card] [cmd]
命令:
help 显示语法帮助.
info 显示调节器设备的信息.
scontrols 显示调节器器的完整列表 .
scontents 显示包含详细信息的调节器的完整列表.
set or sset <SCONTROL> <PARAMETER> ...
设置调节器信息.
get or sget <SCONTROL>
显示调节器的信息.
controls 显示声卡控制器的信息.
contents 显示完整的声卡控制器信息.
cset <CONTROL> <PARAMETER> ...
设置声卡控制器信息.
cget <CONTROL> 显示声卡控制器的信息.
选项:
[-c card]
选择指定的声卡.
[-D device]
选择需要控制的设备名.默认是 default.
-h Help
显示帮助信息.
-q
安静模式.不输出设置结果.
示例:
# amixer -c 1 sset Line,0 80%,40% unmute cap
设置第2块声卡的"line"的左声道音量为80%,右声道为40%,取消静音,并设置
它为声音源.
# amixer -c 2 cset numid=34 40%
设置第34个声卡元素为40%.
6.arecord,aplay的使用
arecord,aplay是命令行的ALSA声卡驱动的录音和播放工具.
arecord是命令行ALSA声卡驱动的录音程序.支持多种文件格式和多个声卡.
aplay是命令行播放工具,支持多种文件格式.
命令格式:
arecord [flags] [filename]
aplay [flags] [filename [filename]] ...
选项:
-h, --help
帮助.
--version
打印版本信息.
-l, --list-devices
列出全部声卡和数字音频设备.
-L, --list-pcms
列出全部PCM定义.
-D, --device=NAME
指定PCM设备名称.
-q --quiet
安静模式.
-t, --file-type TYPE
文件类型(voc,wav,raw或au).
-c, --channels=#
设置通道号.
-f --format=FORMAT
设置格式.格式包括: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
-r, --rate=#<Hz>
设置频率.
-d, --duration=#
设置持续时间,单位为秒.
-s, --sleep-min=#
设置最小休眠时间.
-M, --mmap
mmap流.
-N, --nonblock
设置为非块模式.
-B, --buffer-time=#
缓冲持续时长.单位为微妙.
-v, --verbose
显示PCM结构和设置.
-I, --separate-channels
设置为每个通道一个单独文件.
示例:
aplay -c 1 -t raw -r 22050 -f mu_law foobar
播放raw文件foobar.以22050Hz,单声道,8位,mu_law格式.
arecord -d 10 -f cd -t wav -D copy foobar.wav
以CD质量录制foobar.wav文件10秒钟.使用PCM的"copy".
7.aplaymidi的使用
aplaymidi用来播放标准的MIDI文件.
aplaymidi是一个命令行工具,可以在一个或多个ALSA端口上播放MIDI
文件.
命令格式:
aplaymidi -p client:port[,...] [-d delay] midifile ...
选项:
-h, --help
输出帮助信息.
-V, --version
输出版本信息.
-l, --list
输出可以使用的输出端口列表.
-p, --port=client:port,...
设置端口.
-d, --delay=seconds
设置MIDI文件结束后,等待时长.
8.arecordmidi的使用
arecordmidi用于录制标准的MIDI文件.
arecordmidi可以从一个或多个ALSA端口上,录制一个标准MIDI文件.
命令格式:
arecordmidi -p client:port[,...] [options] midifile
选项:
-h,--help
打印帮助信息.
-V,--version
打印版本号.
-l,--list
打印可以使用的输入端口.
-p,--port=client:port,...
设置端口.
-b,--bpm=beats
设置MIDI文件的速率,默认为120 BPM.
-f,--fps=frames
设置帧率.
-s,--split-channels
设置每个通道将录制成一个单独的MIDI文件.
-d,--dump
在标准输出上,以文本形式显示接受到的事件信息
9.aseqnet的使用
aseqnet是ALSA调节器的网络连接工具.
aseqnet是ALSA调节器的客户端程序,可以从网络上发送和接收事件数据包.
网络上有主机A,主机B.A为服务器端,B为客户端.ALSA调节器系统必须同事运行
在两个服务器上.然后建立服务器端口:
hostA% aseqnet
sequencer opened: 128:0
在HostB上执行:
hostB% aseqnet hostA
sequencer opened: 132:0
现在所有发送到HostA:128:0的数据将被传送到HostB:132:0上,反之亦然.
命令格式:
aseqnet [remotehost]
选项:
-p port
指定TCP端口号或服务名.
-s addr
设置指定地址用于读操作.
-d addr
设置指定地址用于写操作.
-v
详细输出模式
10.iecset的使用
设置或输出IEC958状态位.
iecset是个小工具,通过ALSA的API,设置或输出IEC958(或称S/PDIF)状态位信息.
直接运行iecset将输出当前IEC958的状态信息. 命令格式:
iecset [options] [cmd arg...]
选项:
-D device
设置需要打开的设备名.
-c card
设置需要打开的网卡名.
-x
输出AESx字节格式的状态信息.
-i
从标准输入读取命令信息,每行一个命令.
命令:
professional <bool>
专业模式(true)或用户模式(false).
audio <bool>
音频模式(true).
rate <int>
采样频率,单位Hz.
emphasis <int>
设置加强值.0 = none, 1 = 50/15us, 2 = CCITT.
lock <bool>
速率锁.
sbits <int>
采样位:2 = 20bit, 4 = 24bit, 6 = undefined.
wordlength <int>
设置字长:0 = No, 2 = 22-18 bit, 4 = 23-19 bit, 5 = 24-20
bit, 6 = 20-16 bit.
category <int>
分类:值从0到0x7f.
copyright <bool>
设置是否包含版权.
original <boo>
原始标记:
示例:
输出当前IEC958信息.
$ iecset
Mode: consumer
Data: audio
Rate: 44100 Hz
Copyright: permitted
Emphasis: none
Category: general
Original: 1st generation
Clock: 1000 ppm
显示当前第1块声卡的IEC958状态位.
$ iecset -Dhw:0
Mode: consumer
Data: non-audio
Rate: 44100 Hz
Copyright: permitted
Emphasis: none
Category: general
Original: 1st generation
Clock: 1000 ppm
设置当前为用户模式,并打开"非音频"位.
$ iecset pro off audio off
Mode: consumer
Data: non-audio
Rate: 44100 Hz
Copyright: permitted
Emphasis: none
Category: general
Original: 1st generation
Clock: 1000 ppm
11.speaker-test的使用
speaker-test是一个针对 ALSA驱动的声音测试工具.
speaker-test可以分别对左右声道进行单独的测试.
命令格式:
speaker-test [-options]
选项:
-c | --channels NUM
设置通道数目.
-D | --device NAME
设置使用的PCM设备名.
-f | --frequency FREQ
设置声音频率.
--help
输出帮助信息.
-b | --buffer TIME
设置缓冲区时长.0为使用最大的缓冲区大小.
-p | --period TIME
设置节拍为多少微秒.
-r | --rate RATE
设置音频率.
-t | --test pink|sine|wav
-t pink 表示测试时使用噪声.
-t sine 表示测试时使用音频信号声.
-t wav 表示测试时使用WAV文件.
-l | --nloops COUNT
设置测试循环的次数.
-w | --wavfile
设置测试时播放的wav文件.
-W | --wavdir
设置一个包含wav文件的目录.默认为/usr/share/sounds/alsa.
示例:
在一个音频接口上进行立体声测试
# speaker-test -Dplug:front -c2
在两个音频接口上进行4声道测试.
# speaker-test -Dplug:surround40 -c4
在立体声接口上进行5.1声道测试.
# speaker-test -Dplug:surround51 -c6
测试低音扬声器.
# speaker-test -Dplug:surround51 -c6 -s1 -f75