Definition of Controls

To create a new control, you need to define the following three callbacks: info, get and put. Then, define a struct snd_kcontrol_new record, such as:

Example 6.1. Definition of a Control

  static struct snd_kcontrol_new my_control __devinitdata = {
          .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
          .name = "PCM Playback Switch",
          .index = 0,
          .private_value = 0xffff,
          .info = my_control_info,
          .get = my_control_get,
          .put = my_control_put


Most likely the control is created via snd_ctl_new1(), and in such a case, you can add the __devinitdata prefix to the definition as above.

The iface field specifies the control type, SNDRV_CTL_ELEM_IFACE_XXX, which is usually MIXER. Use CARD for global controls that are not logically part of the mixer. If the control is closely associated with some specific device on the sound card, use HWDEP, PCM, RAWMIDI, TIMER, or SEQUENCER, and specify the device number with the device and subdevice fields.

The name is the name identifier string. Since ALSA 0.9.x, the control name is very important, because its role is classified from its name. There are pre-defined standard control names. The details are described in the Control Names subsection.

The index field holds the index number of this control. If there are several different controls with the same name, they can be distinguished by the index number. This is the case when several codecs exist on the card. If the index is zero, you can omit the definition above.

The access field contains the access type of this control. Give the combination of bit masks, SNDRV_CTL_ELEM_ACCESS_XXX, there. The details will be explained in the Access Flags subsection.

The private_value field contains an arbitrary long integer value for this record. When using the generic info, get and put callbacks, you can pass a value through this field. If several small numbers are necessary, you can combine them in bitwise. Or, it's possible to give a pointer (casted to unsigned long) of some record to this field, too.

The tlv field can be used to provide metadata about the control; see the Metadata subsection.

The other three are callback functions.