At Mon, 19 Jan 2004 08:31:01 -0400, Manuel Jander wrote: > > Hi, > > I'm trying to familiarize myself with the Control API (userland > programs). I'm somewhat scared about the huge amount of API functions... > > I hammered some code together but i'm not very sure if i'm doing it > right. If anyone can comment about this concept code, would be nice. > > What i intend to do: > > 1) Gain access to a control with numeric ID "CTRL_HRTF". > 2) Read some info (value limits and such). > 3) Write 6 (upto 112) integer values into that control. > > The commented code (//) are things that i believe are not needed. > > void test() { > int i; > snd_kcontrol_t *ctlp; ^^^^^^^^^^^^^^ snd_ctl_t
> > /* Open the control. Is this really needed ? */ > if ((err = snd_ctl_open(&ctlp, "3d_hrtf", SND_CTL_ASYNC)) != 0) { > fprintf (stderr, "3D CTL failed: (%s)\n", snd_strerror (err)); > exit(1); > } if you open "3d_hrtf", you have to define this in your asoundrc. (i think it's intentional, right?) > > /* Retrieve some ifno to check if anything is as expected. */ > snd_ctl_elem_info_t *info; > snd_ctl_card_info_alloca(info) ^^^^ elem > > /* Setup info struct. */ > //snd_ctl_elem_info_set_id(info, const snd_ctl_elem_id_t *ptr); > snd_ctl_elem_info_set_numid(info, CTRL_HRTF); you should use the name/index pair rather than the numid. the number id may be changed e.g. if the driver is modified. > snd_ctl_elem_info_set_interface(info, snd_ctl_elem_iface_t val); > snd_ctl_elem_info_set_device(info, 0); > snd_ctl_elem_info_set_subdevice(info, 2); subdevice 2 ?? > //snd_ctl_elem_info_set_name(info, const char *val); > > /* Get info field 0. */ > snd_ctl_elem_info_set_index(info, 0); > if ((err = snd_ctl_elem_info(ctlp, info)) != 0) { > fprintf (stderr, "3D CTL failed: (%s)\n", snd_strerror (err)); > exit(1); > } > snd_ctl_elem_info_free(info); if you call alloca, you cannot (or don't have to) free it explicitly. > /* Declare and setup ctl_elem_value struct. */ > snd_ctl_elem_value_t *ctl_val; > snd_ctl_elem_value_alloca(ctl_val); > > //snd_ctl_elem_value_set_id(ctl_val, const snd_ctl_elem_id_t *ptr); > snd_ctl_elem_value_set_numid(ctl_val, CTRL_HRTF /* Some const defined > elsewhere. */); > snd_ctl_elem_value_set_interface(ctl_val, SNDRV_CTL_ELEM_IFACE_PCM); > snd_ctl_elem_value_set_device(ctl_val, 0); > snd_ctl_elem_value_set_subdevice(ctl_val, 2); > //snd_ctl_elem_value_set_name(ctl_val, const char *val); > > /* Write values. */ > for (i=0; i<6; i++) { > snd_ctl_elem_value_set_index(ctl_val, i); > snd_ctl_elem_value_alloca(ctl_val); allocate twice?? > snd_ctl_elem_value_set_integer(ctl_val, unsigned int idx, long val); the second argument of set_integer is NOT the index of the element itself. it's the array index of that element. (a control element is an array of integer/boolean/etc.) if you want to set different elements with different indices, call snd_ctl_elem_write() in this loop. > } > /* Dispatch ctl write to soundcard. */ > if ((err = snd_ctl_elem_write(ctlp, &control)) != 0) { > fprintf (stderr, "3D CTL failed: (%s)\n", snd_strerror (err)); > exit(1); > } > snd_ctl_elem_value_free(ctl_val); don't free the alloca'ed record. > } ciao, Takashi ------------------------------------------------------- The SF.Net email is sponsored by EclipseCon 2004 Premiere Conference on Open Tools Development and Integration See the breadth of Eclipse activity. February 3-5 in Anaheim, CA. http://www.eclipsecon.org/osdn _______________________________________________ Alsa-devel mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/alsa-devel