您的位置:首页 > 其它

ALSA --- amixer控制声卡驱动实现Line-in功能

2014-08-27 16:13 441 查看
# 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

2.再看看当前你的音频系统(不同的音频驱动对应不同的内容和操作接口)提供了那些供你使用的接口去操作

关于驱动里面已经提供了多少接口可以去操作,可以用命令:

amixer contents

查看,比如:

[root@FORLINX6410]# ./amixer controls

numid=49,iface=MIXER,name='Headphone Mixer Aux Playback Volume'

numid=43,iface=MIXER,name='Headphone Mixer Beep Playback Volume'

numid=32,iface=MIXER,name='Headphone Playback ZC Switch'

numid=4,iface=MIXER,name='Headphone Playback Switch'

numid=3,iface=MIXER,name='Headphone Playback Volume'

numid=6,iface=MIXER,name='PCM Playback Volume'

numid=5,iface=MIXER,name='Line In Volume'

××××××××××××××××××××××××××××××××××××××××××××××××

而对于所有的配置的值,可以通过 amixer contents打印:

[root@FORLINX6410]# ./amixer contents

numid=49,iface=MIXER,name='Headphone Mixer Aux Playback Volume'

; type=INTEGER,access=rw---R--,values=1,min=0,max=7,step=0

: values=5

| dBscale-min=-15.00dB,step=3.00dB,mute=0

numid=43,iface=MIXER,name='Headphone Mixer Beep Playback Volume'

; type=INTEGER,access=rw---R--,values=1,min=0,max=7,step=0

: values=5

| dBscale-min=-15.00dB,step=3.00dB,mute=0

numid=32,iface=MIXER,name='Headphone Playback ZC Switch'

; type=BOOLEAN,access=rw------,values=2

: values=off,off

。。。

3.搞懂如何去设置某个参数

总结起来就是,先要用get系列命令去看懂有哪些接口,然后再去用set系列的命令,去设置对应你所要设置的值。

想要针对某项设置,比如想要设置上面的Line-in输入的音量,‘Line In Volume',即controls中显示的:

numid=5,iface=MIXER,name='Line In Volume'

那么,可以先看看当前的值:

[root@FORLINX6410]# ./amixer cget numid=5,iface=MIXER,name='Line In Volume'

numid=5,iface=MIXER,name='Line In Volume'

; type=INTEGER,access=rw---R--,values=2,min=0,max=31,step=0

: values=23,23

| dBscale-min=-34.50dB,step=1.50dB,mute=0

显示最大音量为31,假设想要设置为25,那么就用cset去设置:

# amixer cset numid=5,iface=MIXER,name='Line In Volume' 25

[root@FORLINX6410]# ../amixer cset numid=5,iface=MIXER,name='Line In Volume' 25

numid=5,iface=MIXER,name='Line In Volume'

; type=INTEGER,access=rw---R--,values=2,min=0,max=31,step=0

: values=25,25

| dBscale-min=-34.50dB,step=1.50dB,mute=0

[提示]:

同上面介绍的的cget/cset系列命令:

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

类似的,还有另外一套sget/sset系列的命令,实现简单的参数设置,一般情况下使用 scontrols ,scontents即可满足您的需求。

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

也是同样做法,比如:

[root@FORLINX6410]# ./amixer scontrols

Simple mixer control 'Headphone',0

Simple mixer control 'Headphone Mixer Aux',0

Simple mixer control 'Headphone Mixer Beep',0

Simple mixer control 'Headphone Playback ZC',0

Simple mixer control 'Tone',0

Simple mixer control 'Tone Cut-off',0

Simple mixer control 'Bass',0

Simple mixer control 'Bass Control',0

Simple mixer control 'Bass Cut-off',0

Simple mixer control 'PCM',0

Simple mixer control 'Sidetone Mux',0

Simple mixer control 'Line In',0-----------(这里是设置Line-in的音量的参数,同以上设置Line-in音量功能相同)

Simple mixer control 'Mic 1',0

Simple mixer control 'Mic 1 Preamp',0

Simple mixer control 'Mic 2',0

Simple mixer control 'Mic 2 Preamp',0

Simple mixer control 'Mic A Source',0

Simple mixer control 'Mic B Source',0

。。。

Simple mixer control 'Left Capture Source',0 (这项很重要,左声道音频源输入选择)

Simple mixer control 'Right Capture Source',0 (右声道音频源输入选择)

。。。

同理,amixer scontents,可以查看当前所有的值,具体就不在这列举了。

另外,去查看或者配置用sget,比如:

[root@FORLINX6410]# ./amixer sget 'Left Capture Source',0

Simple mixer control 'Left Capture Source',0

Capabilities: enum

Items: 'Mic 1' 'Mic 2' 'Line' 'Mono In' 'Headphone' 'Speaker' 'Mono Out' 'Zh'

Item0: 'Mic 1'

如果想要修改对应设置,用amixer sset ,具体用法是:

amixer sset sID(控制字符串) P(支持的某个值)

其中sID,就是上面的Simple mixer control后面的那个字符串,比如 'Left Capture Source' 而对其设置就是,

[root@FORLINX6410]# ./amixer sset 'Left Capture Source',0 Line

Simple mixer control 'Left Capture Source',0

Capabilities: enum

Items: 'Mic 1' 'Mic 2' 'Line' 'Mono In' 'Headphone' 'Speaker' 'Mono Out' 'Zh'

Item0: 'Line'

然后再把右声道输入源设置为Line-in:

[root@FORLINX6410]# ./amixer sset 'Right Capture Source',0 Line

Simple mixer control 'Right Capture Source',0

Capabilities: enum

Items: 'Mic 1' 'Mic 2' 'Line' 'Mono In' 'Headphone' 'Speaker' 'Mono Out' 'Zh'

Item0: 'Line'

这样您的设备就可以使用Line-in功能录音了。

执行命令:

[root@FORLINX6410]#./arecord -f cd -c 1 -t wav my-file.wav

Recording WAVE 'my-file.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Mono

开始Line-in录音 ,-c 1代表使用单声道,2 代表使用立体声.

播放刚才录制的声音文件:

.[root@FORLINX6410]#./aplay my-file.wav

Playing WAVE 'my-file.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Mono

OK,声音非常的清晰。

怎么样,使用ALSA提供的工具是不是很容易的控制声卡的参数呢,另外ALSA可以模拟OSS音频架构,目前OK6410开发板 Linux系统Qtopia声音的播放和录音还是使用的OSS架构,所以开发板的内核配置里面勾选上OSS配置。

设置音频音量:./amixer[b] cset numid=1,iface=MIXER,name='PCM Playback Volume' 127[/b]

[b]./amixer sset 'PCM' 127

[/b]

[b]查看amixer功能: ./amixer contents

[/b]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: