Skip to contentSkip to conversation

Query regarding ALSA control interface

DISCUSSION Pharaoh . 2 participants 3 messages Jul 23, 2007 – Jul 24, 2007

lore
Share & tools
lore

Pharaoh .

author
#0 lore raw

Hi
I am writing a pcm control interface for my alsa driver. I am confused about how the switches are used.
I have implemented simple cases like following and they are working well.

static int audio_path_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)

{
       /*Count is 256 since the values can vary from 0-255. But values fall

in this range only*/

        uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
        uinfo->count = 256;
        uinfo->value.integer.min = 0;
        uinfo->value.integer.max = 255;
        FN_EXIT;
        return 0;
}
static int audio_path_get(struct snd_kcontrol *kcontrol, struct
snd_ctl_elem_value *ucontrol)
{
    my_mixer_t *mixer_chip = snd_kcontrol_chip(kcontrol);
    ucontrol->value.integer.value[0] = mixer_chip->echo;
    ucontrol->value.integer.value[1] = mixer_chip->echo;
    return 0;
}
static int audio_path_put(struct snd_kcontrol *kcontrol, struct
snd_ctl_elem_value *ucontrol)
{
        my_mixer_t *mixer_chip = snd_kcontrol_chip(kcontrol);
       -----
       ----
}

Now, I have to implement a control which takes four different values..namely 0,1.100 and 101. In this case what shoud be the type of control? It should be ENUMERATED or INTEGER? I am confused here since the values are not exactly in a range.

-pharaoh.

#1 lore raw
Quoted 4 lines · Pharaoh .

Now, I have to implement a control which takes four different values..namely 0,1.100 and 101. In this case what shoud be the type of control? It should be ENUMERATED or INTEGER? I am confused here since the values are not exactly in a range.

An INTEGER control takes numeric values in a specific range, while an ENUMERATED control takes values that are not numerically related (but that are _internally_ represented as integers in a specific range).

In your case, you'd probably want to use an enumerated control with the range 0..3, which maps to the four names "0", "1", "100" and "101".

HTH
Clemens

author
#2 lore raw
Quoted 13 lines · Clemens Ladisch
Quoted 1 line · Pharaoh .

Now, I have to implement a control which takes four different

values..namely

Quoted 1 line

0,1.100 and 101. In this case what shoud be the type of control? It

should

Quoted 2 lines

be ENUMERATED or INTEGER? I am confused here since the values are not exactly in a range.

An INTEGER control takes numeric values in a specific range, while an ENUMERATED control takes values that are not numerically related (but that are _internally_ represented as integers in a specific range).

Quoted 6 lines

In your case, you'd probably want to use an enumerated control with the range 0..3, which maps to the four names "0", "1", "100" and "101".

HTH
Clemens

Thanks Clemens, I had implemented it using ENUM type. It works.

-pharaoh.