ALSA学习笔记 (4)Control
1. 如何创建一个control
1.1 定义一个snd_kcontrol_new结构体
static struct snd_kcontrol_new my_control __devinitdata = {
.face = SNDRV_CTL_ELEM_IFACE_MIXER,
.name = “PCM Playback Switch”,
.index = 0,
.access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
.private_value = 0xffff,
.info = my_control_info,
.get = my_control_get,
.put = my_control_put
};
iface 表示control的类型,用SNDRV_CTL_ELEM_IFACE_XXX来定义。例如: CARD, MIXER, PCM等
name 表示control的名字,用户层可以通过这个名字访问这个control
index 存放这个 control 的索引号
access 访问权限的控制,READ,WRITE,READWRITE等
private_value 特定control的私有数据,例如可以存放寄存器地址信息
1.2 回调函数
1.2.1 info 函数
用于得到对应control的详细信息,需要把信息存入snd_ctl_elem_info 对象中。
struct snd_ctl_elem_info {
struct snd_ctl_elem_id id; /* W: element ID */
snd_ctl_elem_type_t type; /* R: value type - SNDRV_CTL_ELEM_TYPE_* */
unsigned int access; /* R: value access (bitmask) - SNDRV_CTL_ELEM_ACCESS_* */
unsigned int count; /* count of values */
__kernel_pid_t owner; /* owner's PID of this control */