原文地址:转 -ALSA 配置 作者:超级大苹果
alsa 音频路径的问题:
在sound/soc/codecs目录中有很多音频codec的codec驱动,我使用的是wm9713,AP是s3c6410;这里个驱动文件中定义了很多widget和control,alsa在playback或record的时候,sound/soc/soc-dapm.c中的dapm_power_widgets函数会根据“配置情况”打开相应的widget,搭建一个完整的音频路径,只要该路径搭建成功,就可以正常工作;
sound/soc/codecs/wm9713.c中的audio_map[]就是一个wm9713的路由表,根据wm9713手册中的Audio Paths Overview可以选择自己需要的音频路径,在audio_map[]中测试一下,看audio_map中是否支持这种路径。
alsa 的配置
alsa音频的调试最主要的是alsa的配置。alsa使用amixer命令打开audio_map[]中的开关(control/switch)和其它一些controls,这些control设置后,使用aplay/arecord的时候即可搭建正确的路径,实现播放和录音。
比如我在调试的时候,在不用amixer控制时(默认状态),arecord可以正确录音,使用sound/soc/soc-dapm.c中的dump_dapm函数dump出的路径是正确的;而aplay的时候,dump_dapm出来的路径是错误的,原因是默认设置里没有打开playback的开关(switch),运行如下命令即可正确playback:
alsa_amixer cset numid=4,iface=MIXER,name='Headphone Playback Switch' 1
alsa_amixer cset numid=93,iface=MIXER,name='Left Headphone Out Mux' 2
alsa_amixer cset numid=34,iface=MIXER,name='Out3 Playback Switch'1
alsa_amixer cset numid=95,iface=MIXER,name='Left Speaker Out Mux' 4
alsa_amixer cset numid=94,iface=MIXER,name='Right Speaker Out Mux' 2
alsa_amixer cset numid=91,iface=MIXER,name='Out 3 Mux' 2
alsa_amixer cset numid=81,iface=MIXER,name='Left HP Mixer PCM Playback Swit' 1
alsa_amixer cset numid=75,iface=MIXER,name='Right HP Mixer PCM Playback Swi' 1
alsa_amixer cset numid=3,iface=MIXER,name='Headphone Playback Volume' 26
alsa_amixer cset numid=36,iface=MIXER,name='Out3 Playback Volume' 48
其实就是打开playback路径需要的开关,dapm_power_widgets会自动把这些开关连接的widget连接起来,构成一个播放路径。
Android中alsa的配置:
Andriod中使用alsa-lib,也需要对配置音频路径。配置方法有两个:
1、在AudioHardwareALSA.cpp中的doRouting中使用system函数调用amixer进行配置
system("alsa_amixer cset numid=4,iface=MIXER,name='Headphone Playback Switch' 1");
2、编写asound.conf文件,AudioHardwareALSA.cpp中的ALSAMixer::ALSAMixer对象初始化的时候会通过alsa-lib的conf.c文件中的函数读取/etc/asound.conf文件,获取配置信息,对codec进行配置。
alsa的一些命令
alsa_amixer该命令配置主要配置音频codec的mixer开关、mux对路选择、volume值等;
alsa_amixer --help
alsa_amixer contents
alsa_amixer contents
numid=30,iface=MIXER,name='Headphone Playback ZC Switch'
; type=BOOLEAN,access=rw------,values=2
: values=off,off
numid=4,iface=MIXER,name='Headphone Playback Switch'
; type=BOOLEAN,access=rw------,values=2
: values=off,off
numid=3,iface=MIXER,name='Headphone Playback Volume'
; type=INTEGER,access=rw------,values=2,min=0,max=31,step=0
: values=31,31
numid=6,iface=MIXER,name='PCM Playback Volume'
; type=INTEGER,access=rw------,values=2,min=0,max=31,step=0
: values=23,23
numid=5,iface=MIXER,name='Line In Volume'
; type=INTEGER,access=rw------,values=2,min=0,max=31,step=0
: values=23,23
numid=7,iface=MIXER,name='Mic 1 Volume'
; type=INTEGER,access=rw------,values=1,min=0,max=31,step=0
: values=23
numid=8,iface=MIXER,name='Mic 2 Volume'
; type=INTEGER,access=rw------,values=1,min=0,max=31,step=0
: values=23
numid=85,iface=MIXER,name='Mic A Source'
; type=ENUMERATED,access=rw------,values=1,items=3
; Item #0 'Mic 1'
; Item #1 'Mic 2 A'
; Item #2 'Mic 2 B'
: values=0
alsa_amixer controls
numid=30,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'
numid=7,iface=MIXER,name='Mic 1 Volume'
numid=8,iface=MIXER,name='Mic 2 Volume'
numid=85,iface=MIXER,name='Mic A Source'
numid=84,iface=MIXER,name='Mic B Source'
numid=9,iface=MIXER,name='Mic Boost (+20dB) Switch'
numid=10,iface=MIXER,name='Mic Headphone Mixer Volume'
numid=47,iface=MIXER,name='Aux Playback Headphone Volume'
numid=48,iface=MIXER,name='Aux Playback Master Volume'
numid=49,iface=MIXER,name='Aux Playback Mono Volume'
numid=67,iface=MIXER,name='Mono Mixer Aux Playback Switch'
numid=69,iface=MIXER,name='Mono Mixer Bypass Playback Swit'
numid=70,iface=MIXER,name='Mono Mixer Mic 1 Sidetone Switc'
numid=71,iface=MIXER,name='Mono Mixer Mic 2 Sidetone Switc'
numid=65,iface=MIXER,name='Mono Mixer PC Beep Playback Swi'
numid=68,iface=MIXER,name='Mono Mixer PCM Playback Switch'
numid=66,iface=MIXER,name='Mono Mixer Voice Playback Switc'
alsa_alsactl store:该命令生成/etc/asound.state文件,该文件显示当请codec的状态,可以根据该文件检查codec的状态是否正确。
# cat /etc/asound.state
state.SMDK6400 {
control.1 {
comment.access 'read write'
comment.type INTEGER
comment.count 2
comment.range '0 - 31'
iface MIXER
name 'Speaker Playback Volume'
value.0 31
value.1 31
}
control.2 {
comment.access 'read write'
comment.type BOOLEAN
comment.count 2
iface MIXER
name 'Speaker Playback Switch'
value.0 false
value.1 false
}
control.3 {
comment.access 'read write'
comment.type INTEGER
comment.count 2
comment.range '0 - 31'
iface MIXER
name 'Headphone Playback Volume'
value.0 26
value.1 26
}
control.4 {
comment.access 'read write'
comment.type BOOLEAN
comment.count 2
iface MIXER
name 'Headphone Playback Switch'
value.0 true
value.1 true
}
control.5 {
comment.access 'read write'
comment.type INTEGER
comment.count 2
comment.range '0 - 31'
iface MIXER
name 'Line In Volume'
value.0 23
value.1 23
}
使用amixer命令可以参照alsa_amixer contents的内容;编写asound.conf,可以参照alsa_alsactl生成的/etc/asound.state。
下面是我的asound.conf的一段,其它的pcm.AndroidPlayback_xxx可以写法一样,就是hook_argsp[]中的内容根据自己的情况设置。
##
## Mixer Devices
##
ctl.AndroidPlayback {
type hw
card 0 # Can replace with driver"s name from /proc/asound/cards
}
ctl.AndroidRecord {
type hw
card 0 # Can replace with driver"s name from /proc/asound/cards
}
##
## Playback Devices
##
pcm.AndroidPlayback {
type hooks
slave.pcm {
type hw
card 0
device 0 # Must be of type "digital audio playback"
}
hooks.0 {
type ctl_elems
hook_args [
{
name 'Master Playback Switch'
value true
}
{
name 'Master Playback Volume'
value.0 51
value.1 51
}
{
name 'Phone Playback Switch'
value false
}
{
name 'Phone Playback Volume'
value.0 0
value.1 0
}
{
name 'Mic Playback Switch'
value false
}
{
name 'Mic Playback Volume'
value.0 0
value.1 0
}
{
name 'Mic Boost (+20dB)'
value false
}
{
name 'Line Playback Switch'
value false
}
{
name 'Line Playback Volume'
value.0 0
value.1 0
}
{
name 'PCM Playback Switch'
value true
}
{
name 'PCM Playback Volume'
value.0 51
value.1 51
}
{
name 'Capture Source'
value.0 Mic
value.1 Mic
}
{
name 'Capture Switch'
value true
}
{
name 'Capture Volume'
value.0 0
value.1 0
}
]
}
}
在sound/soc/codecs目录中有很多音频codec的codec驱动,我使用的是wm9713,AP是s3c6410;这里个驱动文件中定义了很多widget和control,alsa在playback或record的时候,sound/soc/soc-dapm.c中的dapm_power_widgets函数会根据“配置情况”打开相应的widget,搭建一个完整的音频路径,只要该路径搭建成功,就可以正常工作;
sound/soc/codecs/wm9713.c中的audio_map[]就是一个wm9713的路由表,根据wm9713手册中的Audio Paths Overview可以选择自己需要的音频路径,在audio_map[]中测试一下,看audio_map中是否支持这种路径。
alsa 的配置
alsa音频的调试最主要的是alsa的配置。alsa使用amixer命令打开audio_map[]中的开关(control/switch)和其它一些controls,这些control设置后,使用aplay/arecord的时候即可搭建正确的路径,实现播放和录音。
比如我在调试的时候,在不用amixer控制时(默认状态),arecord可以正确录音,使用sound/soc/soc-dapm.c中的dump_dapm函数dump出的路径是正确的;而aplay的时候,dump_dapm出来的路径是错误的,原因是默认设置里没有打开playback的开关(switch),运行如下命令即可正确playback:
alsa_amixer cset numid=4,iface=MIXER,name='Headphone Playback Switch' 1
alsa_amixer cset numid=93,iface=MIXER,name='Left Headphone Out Mux' 2
alsa_amixer cset numid=34,iface=MIXER,name='Out3 Playback Switch'1
alsa_amixer cset numid=95,iface=MIXER,name='Left Speaker Out Mux' 4
alsa_amixer cset numid=94,iface=MIXER,name='Right Speaker Out Mux' 2
alsa_amixer cset numid=91,iface=MIXER,name='Out 3 Mux' 2
alsa_amixer cset numid=81,iface=MIXER,name='Left HP Mixer PCM Playback Swit' 1
alsa_amixer cset numid=75,iface=MIXER,name='Right HP Mixer PCM Playback Swi' 1
alsa_amixer cset numid=3,iface=MIXER,name='Headphone Playback Volume' 26
alsa_amixer cset numid=36,iface=MIXER,name='Out3 Playback Volume' 48
其实就是打开playback路径需要的开关,dapm_power_widgets会自动把这些开关连接的widget连接起来,构成一个播放路径。
Android中alsa的配置:
Andriod中使用alsa-lib,也需要对配置音频路径。配置方法有两个:
1、在AudioHardwareALSA.cpp中的doRouting中使用system函数调用amixer进行配置
system("alsa_amixer cset numid=4,iface=MIXER,name='Headphone Playback Switch' 1");
2、编写asound.conf文件,AudioHardwareALSA.cpp中的ALSAMixer::ALSAMixer对象初始化的时候会通过alsa-lib的conf.c文件中的函数读取/etc/asound.conf文件,获取配置信息,对codec进行配置。
alsa的一些命令
alsa_amixer该命令配置主要配置音频codec的mixer开关、mux对路选择、volume值等;
alsa_amixer --help
alsa_amixer contents
alsa_amixer contents
numid=30,iface=MIXER,name='Headphone Playback ZC Switch'
; type=BOOLEAN,access=rw------,values=2
: values=off,off
numid=4,iface=MIXER,name='Headphone Playback Switch'
; type=BOOLEAN,access=rw------,values=2
: values=off,off
numid=3,iface=MIXER,name='Headphone Playback Volume'
; type=INTEGER,access=rw------,values=2,min=0,max=31,step=0
: values=31,31
numid=6,iface=MIXER,name='PCM Playback Volume'
; type=INTEGER,access=rw------,values=2,min=0,max=31,step=0
: values=23,23
numid=5,iface=MIXER,name='Line In Volume'
; type=INTEGER,access=rw------,values=2,min=0,max=31,step=0
: values=23,23
numid=7,iface=MIXER,name='Mic 1 Volume'
; type=INTEGER,access=rw------,values=1,min=0,max=31,step=0
: values=23
numid=8,iface=MIXER,name='Mic 2 Volume'
; type=INTEGER,access=rw------,values=1,min=0,max=31,step=0
: values=23
numid=85,iface=MIXER,name='Mic A Source'
; type=ENUMERATED,access=rw------,values=1,items=3
; Item #0 'Mic 1'
; Item #1 'Mic 2 A'
; Item #2 'Mic 2 B'
: values=0
alsa_amixer controls
numid=30,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'
numid=7,iface=MIXER,name='Mic 1 Volume'
numid=8,iface=MIXER,name='Mic 2 Volume'
numid=85,iface=MIXER,name='Mic A Source'
numid=84,iface=MIXER,name='Mic B Source'
numid=9,iface=MIXER,name='Mic Boost (+20dB) Switch'
numid=10,iface=MIXER,name='Mic Headphone Mixer Volume'
numid=47,iface=MIXER,name='Aux Playback Headphone Volume'
numid=48,iface=MIXER,name='Aux Playback Master Volume'
numid=49,iface=MIXER,name='Aux Playback Mono Volume'
numid=67,iface=MIXER,name='Mono Mixer Aux Playback Switch'
numid=69,iface=MIXER,name='Mono Mixer Bypass Playback Swit'
numid=70,iface=MIXER,name='Mono Mixer Mic 1 Sidetone Switc'
numid=71,iface=MIXER,name='Mono Mixer Mic 2 Sidetone Switc'
numid=65,iface=MIXER,name='Mono Mixer PC Beep Playback Swi'
numid=68,iface=MIXER,name='Mono Mixer PCM Playback Switch'
numid=66,iface=MIXER,name='Mono Mixer Voice Playback Switc'
alsa_alsactl store:该命令生成/etc/asound.state文件,该文件显示当请codec的状态,可以根据该文件检查codec的状态是否正确。
# cat /etc/asound.state
state.SMDK6400 {
control.1 {
comment.access 'read write'
comment.type INTEGER
comment.count 2
comment.range '0 - 31'
iface MIXER
name 'Speaker Playback Volume'
value.0 31
value.1 31
}
control.2 {
comment.access 'read write'
comment.type BOOLEAN
comment.count 2
iface MIXER
name 'Speaker Playback Switch'
value.0 false
value.1 false
}
control.3 {
comment.access 'read write'
comment.type INTEGER
comment.count 2
comment.range '0 - 31'
iface MIXER
name 'Headphone Playback Volume'
value.0 26
value.1 26
}
control.4 {
comment.access 'read write'
comment.type BOOLEAN
comment.count 2
iface MIXER
name 'Headphone Playback Switch'
value.0 true
value.1 true
}
control.5 {
comment.access 'read write'
comment.type INTEGER
comment.count 2
comment.range '0 - 31'
iface MIXER
name 'Line In Volume'
value.0 23
value.1 23
}
使用amixer命令可以参照alsa_amixer contents的内容;编写asound.conf,可以参照alsa_alsactl生成的/etc/asound.state。
下面是我的asound.conf的一段,其它的pcm.AndroidPlayback_xxx可以写法一样,就是hook_argsp[]中的内容根据自己的情况设置。
##
## Mixer Devices
##
ctl.AndroidPlayback {
type hw
card 0 # Can replace with driver"s name from /proc/asound/cards
}
ctl.AndroidRecord {
type hw
card 0 # Can replace with driver"s name from /proc/asound/cards
}
##
## Playback Devices
##
pcm.AndroidPlayback {
type hooks
slave.pcm {
type hw
card 0
device 0 # Must be of type "digital audio playback"
}
hooks.0 {
type ctl_elems
hook_args [
{
name 'Master Playback Switch'
value true
}
{
name 'Master Playback Volume'
value.0 51
value.1 51
}
{
name 'Phone Playback Switch'
value false
}
{
name 'Phone Playback Volume'
value.0 0
value.1 0
}
{
name 'Mic Playback Switch'
value false
}
{
name 'Mic Playback Volume'
value.0 0
value.1 0
}
{
name 'Mic Boost (+20dB)'
value false
}
{
name 'Line Playback Switch'
value false
}
{
name 'Line Playback Volume'
value.0 0
value.1 0
}
{
name 'PCM Playback Switch'
value true
}
{
name 'PCM Playback Volume'
value.0 51
value.1 51
}
{
name 'Capture Source'
value.0 Mic
value.1 Mic
}
{
name 'Capture Switch'
value true
}
{
name 'Capture Volume'
value.0 0
value.1 0
}
]
}
}