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的移动设备上的音频子系统,在任何时候都工作在最小功耗状态 ...
随机推荐
- [Grunt] grunt.template
/** * Created by Answer1215 on 11/15/2014. */ module.exports = function(grunt){ grunt.initConfig({ f ...
- 【Python】【Nodejs】下载单张图片到本地,Python和Nodejs的比较
Python版本: # 下载单张图片到本地,看用时多少 import urllib.request import datetime starttime = datetime.datetime.now( ...
- 【python】列出http://www.cnblogs.com/xiandedanteng/p/中的标题
# 列出http://www.cnblogs.com/xiandedanteng/p/中的标题 from bs4 import BeautifulSoup import requests user_a ...
- ShareSDK for Android 2.3.10已经公布
ShareSDK for Android 2.3.10已经公布,本次更新内容包含: 1.加入自己定义分享标签功能 新版本号SDK下载页面地址: http://share.sharesdk.cn/Dow ...
- Unable to create requested service org.hibernate.cache.spi.RegionFactory
hibernate 4.3.11+struts2.3.28.1+spring 4.2.5,在搭框架的时候,报的这个错误: Unable to create requested service org. ...
- Python3.2官方文档翻译--迭代器
6.9 迭代器 到眼下为止.你可能已注意到很多容器对象都能够用for语句进行循环: 这样的訪问风格清楚简洁方便. 迭代器的应用是python遍历统一.在这样的场景背后.for语句调用容器对象iter( ...
- 算法笔记_040:二进制幂(Java)
目录 1 问题描述 2 解决方案 2.1 从左至右二进制幂 2.2 从右至左二进制幂 1 问题描述 使用n的二进制表示,计算a的n次方. 2 解决方案 2.1 从左至右二进制幂 此方法计算a的n次 ...
- java防止sql注入
public final static String filterSQLInjection(String s) { if (s == null || "".equals(s)) { ...
- ThreadPoolExecutor中策略的选择与工作队列的选择(java线程池)
工作原理 1.线程池刚创建时,里面没有一个线程.任务队列是作为参数传进来的.不过,就算队列里面有任务,线程池也不会马上执行它们. 2.当调用 execute() 方法添加一个任务时,线程池会做如下判断 ...
- AFNetworking2.0源代码解析
写在前面给大家推荐一个不错的站点 点击打开链接 本文測试样例源代码下载地址 近期看AFNetworking2的源代码.学习这个知名网络框架的实现.顺便梳理写下文章. AFNetworking的代码还在 ...