snd_kcontrol_new名称中的SOURCE字段

转载:http://blog.csdn.net/sepnic/article/details/6324901

前些日子写了一篇snd_kcontrol探究,该文主要从内核源码出发简单讲述一下kcontrol接口的始末。这几天因为要在Android里面添加一些音频控制接口,配合alsa_amixer scontents分析,对此有了更深的体会,记录于此。因为这方面的资料实在太少,很多东西都是自我理解的,如有错误请见谅并指出。

 

name字段是名称标识,这个字段非常重要,因为kcontrol的作用由名称来区分,对于名称相同的kcontrol,则使用index区分。name定义的标准是“SOURCE DIRECTION FUNCTION”即“源 方向 功能”,SOURCE定义了kcontrol的源,如“Master”、“PCM”等;DIRECTION 则为“Playback”、“Capture”等,如果DIRECTION忽略,意味着Playback和capture双向;FUNCTION则可以是“Switch”、“Volume”和“Route”等。

以上的说法比较简略,下面会较详细补充一下。

先内核源码中的文档ControlNames.txt:

[c-sharp]  view plain copy
  1. This document describes standard names of mixer controls.  
  2.   
  3. Syntax: SOURCE [DIRECTION] FUNCTION  
  4.   
  5. DIRECTION:  
  6.   <nothing>   (both directions)  
  7.   Playback  
  8.   Capture  
  9.   Bypass Playback  
  10.   Bypass Capture  
  11.   
  12. FUNCTION:  
  13.   Switch    (on/off switch)  
  14.   Volume  
  15.   Route     (route control, hardware specific)  
  16.   
  17. SOURCE:  
  18.   Master  
  19.   Master Mono  
  20.   Hardware Master  
  21.   Headphone  
  22.   PC Speaker  
  23.   Phone  
  24.   Phone Input  
  25.   Phone Output  
  26.   Synth  
  27.   FM  
  28.   Mic  
  29.   Line  
  30.   CD  
  31.   Video  
  32.   Zoom Video  
  33.   Aux  
  34.   PCM  
  35.   PCM Front  
  36.   PCM Rear  
  37.   PCM Pan  
  38.   Loopback  
  39.   Analog Loopback   (D/A -> A/D loopback)  
  40.   Digital Loopback  (playback -> capture loopback - without analog path)  
  41.   Mono  
  42.   Mono Output  
  43.   Multi  
  44.   ADC  
  45.   Wave  
  46.   Music  
  47.   I2S  
  48.   IEC958  
  49.   
  50. Exceptions:  
  51.   [Digital] Capture Source  
  52.   [Digital] Capture Switch  (aka input gain switch)  
  53.   [Digital] Capture Volume  (aka input gain volume)  
  54.   [Digital] Playback Switch (aka output gain switch)  
  55.   [Digital] Playback Volume (aka output gain volume)  
  56.   Tone Control - Switch  
  57.   Tone Control - Bass  
  58.   Tone Control - Treble  
  59.   3D Control - Switch  
  60.   3D Control - Center  
  61.   3D Control - Depth  
  62.   3D Control - Wide  
  63.   3D Control - Space  
  64.   3D Control - Level  
  65.   Mic Boost [(?dB)]  
  66.   
  67. PCM interface:  
  68.   
  69.   Sample Clock Source   { "Word""Internal""AutoSync" }  
  70.   Clock Sync Status { "Lock""Sync""No Lock" }  
  71.   External Rate     /* external capture rate */  
  72.   Capture Rate      /* capture rate taken from external source */  
  73.   
  74. IEC958 (S/PDIF) interface:  
  75.   
  76.   IEC958 [...] [Playback|Capture] Switch    /* turn on/off the IEC958 interface */  
  77.   IEC958 [...] [Playback|Capture] Volume    /* digital volume control */  
  78.   IEC958 [...] [Playback|Capture] Default   /* default or global value - read/write */  
  79.   IEC958 [...] [Playback|Capture] Mask      /* consumer and professional mask */  
  80.   IEC958 [...] [Playback|Capture] Con Mask  /* consumer mask */  
  81.   IEC958 [...] [Playback|Capture] Pro Mask  /* professional mask */  
  82.   IEC958 [...] [Playback|Capture] PCM Stream    /* the settings assigned to a PCM stream */  
  83.   IEC958 Q-subcode [Playback|Capture] Default   /* Q-subcode bits */  
  84.   IEC958 Preamble [Playback|Capture] Default    /* burst preamble words (4*16bits) */  
  

可以看到表示方向DIRECTION有五种,其中DIRECTION为空时则表示Playback、Capture双向。

一个标准的kcontrol如:SOC_DOUBLE("PCM Playback Volume", AC97_PHONE, 8, 0, 31, 1),其中“PCM”为源SOURCE、“Playback”为方向DIRECTION、“Volume”为功能FUNCTION--音量调节,这个kcontrol是调节放音PCM的Volume的。

又如:SOC_SINGLE("Mic Switch", AC97_CD, 15, 1, 1),其中“Mic”为源SOURCE、方向DIRECTION为空表示Playback和Capture双向、“Switch”为功能FUNCTION--开关切换,这个kcontrol是用于切换Mic开关的。

实际应用中,并不是所有的kcontrol命名都符合ControlNames.txt规则。如:SOC_SINGLE("ALC Hold Time", AC97_CODEC_CLASS_REV, 8, 15, 0),这个kcontrol的name只有名为“ALC Hold Time”的SOURCE字段,DIRECTION和FUNCTION都欠缺。

 

alsa_amixer命令可以输出这些kcontrol的名称、numid和当前值等信息。而选项sconctols/controls、scontents/contents、sset/cset、sget/cget有所不同,前者是mixer simple control信息,后者是control信息;前者的handle通过snd_mixer_open取得,后者的handle通过snd_ctl_open取得。

两个kcontrol:1、SOC_SINGLE("Capture Switch", AC97_CD, 15, 1, 1), 2、SOC_DOUBLE("Capture Volume", AC97_CD, 8, 0, 31, 0):

在alsa_amixer scontrols来看,显示一个名称为“Capture”的mixer simple control,根据我的结果,一般这个mixer simple control对应的是后者【猜测:之所以有这样的结果,是因为两个kcontrol的SOURCE名称相同,而mixer simple control是匹配kcontrol的SOURCE字段的;因此SOURCE字段区别体现在mixer simple control上,而name区别体现在control上,待验证。】

在alsa_amixer controls来看,列表会显示所有的kcontrol,因此会显示“Capture Switch”和“Capture Volume”这两个kcontrol。这不难理解,在snd_kcontrol探究中就提到,上层是根据name来找到底层的kcontrol的,这个name包含了SOURCE、DIRECTION和FUNCTION这三个字段。

【建议:编写snd_kcontrol时,尽量使用标准的ControlName,留意SOURCE字段是否有重复。在上层应用中,很多都是使用snd_mixer_open得到的mixer simple control,一个典型的例子就是Android2.2的AlsaMixer.cpp。之前我在为Android添加mic mute接口时,发现无论如何都找不到“Capture Switch”的kcontrol,因为它与“Capture Volume”的kcontrol的SOURCE字段重名了。将其改名为“Mic Switch”就行了。】


4/16 2011

找到一个alsa基本架构图

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值