alsamixer 在音频子系统的使用
alsamixer是Linux 音频架构ALSA工具的其中一个,用于配置音频的各个参数。
alsamixer是基于文本下的图形界面的,可以通过键盘的上下键,左右键等,很方便地设置需要的音量,开关某个switch(开关)等等操作,下图是 在Ubuntu12.04系统上图形配置界面,操作非常的简单,这里使用的是Ubuntu12.04的Line-in功能(实现立体声功能):
声音播放输出通道设置:
声音输入设备通道设置:
笔者测试Ubuntu12.04的Line-in功能,所以选择音频输入通道为 Line。
amixer,是alsamixer的文本模式,即命令行模式,需要用amixer命令的形式去配置你的声卡的各个选项,可以这么说,你
也许会直接修改Linux内核音频驱动源码来满足您的需求,比如选择音频输入通道是Mic输入,还是Line
输入,需要修改WM9714的寄存器来决定,而amixer可以从应用层来修改音频芯片的寄存器值,决定采用Mic输入或者Line输入。这样就大大简化
了代码修改的难度,毕竟比直接修改Linux Kernel ALSA会简单些。
对于amixer的使用,你首先需要搞懂你要设置的参数是哪些,然后才可能去了解,如何去配置对应的值,整体来说,相对alsamixer来说,是有点繁琐,下面简要介绍其具体用法:
1.先看看amixer支持哪些命令,大概有哪些功能
# 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
alsamixer 在音频子系统的使用的更多相关文章
- ASOC 音频子系统框架
基于: Mini2440 开发板, Linux 3.4.2 内核 ASOC 简介: ASoC - ALSA System on Chip,是建立在标准ALSA驱动层上,为了更好地支持嵌入式处理器和移动 ...
- linux驱动由浅入深系列:tinyalsa(tinymix/tinycap/tinyplay/tinypcminfo)音频子系统之一【转】
本文转载自:http://blog.csdn.net/radianceblau/article/details/64125411 目前linux中主流的音频体系结构是ALSA(Advanced Lin ...
- 初探linux子系统集之写在前言
毕业两周年,进入嵌入式linux这个行业也已两个年头有余,从开始的linux驱动,android的framework,到现在的linux应用,android的app以及产品的零零总总,其实很想把这些都 ...
- [SimplePlayer] 5. 向音频设备输出音频
两种SDL音频输出方式 我们这里采用SDL来进行音频输出.SDL提供两种音频输出的方式: 如果在SDL_OpenAudio时不指定callback,那么可以调用SDL_QueueAudio主动地向音频 ...
- linux音频alsa-uda134x驱动分析之二(时钟)
Audio Clocking音频时钟============== This text describes the audio clocking terms in ASoC and digital au ...
- 转---Android Audio System 之一:AudioTrack如何与AudioFlinger交换音频数据
引子 Android Framework的音频子系统中,每一个音频流对应着一个AudioTrack类的一个实例,每个AudioTrack会在创建时注册到 AudioFlinger中,由AudioFli ...
- Linux音频驱动-ALSA概述
概述 ALSA(Advanced Linux Sound Architecture)是linux上主流的音频结构,在没有出现ALSA架构之前,一直使用的是OSS(Open Sound System)音 ...
- SDL开发笔记(二):音频基础介绍、使用SDL播放音频
若该文为原创文章,未经允许不得转载原博主博客地址:https://blog.csdn.net/qq21497936原博主博客导航:https://blog.csdn.net/qq21497936/ar ...
- ALSA声卡驱动中的DAPM详解之一:kcontrol
DAPM是Dynamic Audio Power Management的缩写,直译过来就是动态音频电源管理的意思,DAPM是为了使基于linux的移动设备上的音频子系统,在任何时候都工作在最小功耗状态 ...
随机推荐
- 美团的android多渠道包的3种方法
转: http://tech.meituan.com/mt-apk-packaging.html 美团Android自动化之旅—生成渠道包 zhihu2014-06-13 10:06 概述 每当发新版 ...
- android AIDL 入门讲解非常好的文章(网页代码着色给力)
转自: http://tech.cnnetsec.com/585.html
- 分治算法——Karastsuba算法
分治(Divide and Conquer)算法:问题能够分解为子问题,每一个问题是能够独立的解决的,从子问题的解能够构建原问题. Divide:中间分.随机分.奇偶分等,将问题分解成独立的子问题 C ...
- Linux网络编程之聊天程序(TCP协议之select)
服务器端:server.c #include <stdio.h> #include <stdlib.h> #include <errno.h> #include & ...
- Linux平台Boost的编译方法
本博客(http://blog.csdn.net/livelylittlefish)贴出作 者(三二一@小鱼)相关研究.学习内容所做的笔记,欢迎广大朋友指正! Linux平台Boost的编译方法 Bo ...
- Android开发之定位系统
2013-07-04 定位系统 全球定位系统(Global Positioning System, GPS), 又称全球卫星定位系统. 最少只需其中3颗卫星,就能迅速确定用户组地球所处的位置及海拔高度 ...
- ubuntu截图工具
ubuntu截图工具 首先,我们用apt-get install 去安装一个,scrot 主要用在命令行下,它使用 imlib2 库来抓取并保存图像 sudo a ...
- Python 3.x 连接 pymysql 数据库
首先,需要安装库: 使用 pycharm IDE,如PyCharm,可以使用 project python 安装第三方模块. [File] >> [settings] >> [ ...
- 【LeetCode】78. Subsets (2 solutions)
Subsets Given a set of distinct integers, S, return all possible subsets. Note: Elements in a subset ...
- vsCode 添加浏览器调试和js调试的方法总结
vsCode 添加浏览器调试和js调试的方法 1.直接按F5可以调试的方法或者点击运行按钮(可以直接运行html文件或者js文件) 在launch.json文件中的配置如下: { " ...