Re: [LAD] ALSA doumentation

From: Clemens Ladisch <cladisch@email-addr-hidden>
Date: Fri Nov 14 2008 - 16:31:12 EET

Fons Adriaensen wrote:
> > snd_ctl_elem_value_alloca(&value);
> > snd_ctl_elem_value_set_interface(value, SND_CTL_ELEM_IFACE_MIXER);
> > snd_ctl_elem_value_set_name(value, "Sample Clock Source");
> > snd_ctl_elem_value_set_enumerated(value, 0, 3); /* 3: 48 kHz */
>
> So it's actually quite simple (in this case -- I imagine there are
> more complex things as well, if not why does the API have a zillion
> functions).

Most of these functions are for accessing structure elements that ALSA
doesn't want to expose directly so that the structure layout can change
in future library versions. In an API like OSS, the code above would
look like this, without separate functions:

        snd_ctl_elem_value_t value;
        value.interface = SND_CTL_ELEM_IFACE_MIXER;
        strcpy(value.name, "Sample Clock Source");
        value.enumerated[0] = 3;

> One mor question: is there a way to obtain a 'handle' on a
> control element so it can be updated frequently without the
> overhead of textual encoding and decoding each time ?

        snd_ctl_elem_info_alloca(&info)
        snd_ctl_elem_info_set_interface(info, SND_CTL_ELEM_IFACE_MIXER);
        snd_ctl_elem_info_set_name(info, "Sample Clock Source");
        CHECK(snd_ctl_elem_info(ctl, info));
        id = snd_ctl_elem_info_get_numid(info);

(This is the same id value as shown by alsactl/amixer.)

        snd_ctl_elem_value_set_numid(value, id);
        snd_ctl_elem_value_set_enumerated(value, 0, 3);
        CHECK(snd_ctl_elem_write(ctl, value));

HTH
Clemens
_______________________________________________
Linux-audio-dev mailing list
Linux-audio-dev@email-addr-hidden
http://lists.linuxaudio.org/mailman/listinfo/linux-audio-dev
Received on Fri Nov 14 20:15:01 2008

This archive was generated by hypermail 2.1.8 : Fri Nov 14 2008 - 20:15:02 EET