From: Takashi Iwai <tiwai@suse.de>
To: manuel.jander@mat.utfsm.cl
Cc: alsa-devel@lists.sourceforge.net
Subject: Re: Control API, help
Date: Mon, 19 Jan 2004 20:18:13 +0100 [thread overview]
Message-ID: <s5hhdyr928a.wl@alsa2.suse.de> (raw)
In-Reply-To: <1074515461.1048.21.camel@localhost>
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
prev parent reply other threads:[~2004-01-19 19:18 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-01-19 12:31 Control API, help Manuel Jander
2004-01-19 19:18 ` Takashi Iwai [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=s5hhdyr928a.wl@alsa2.suse.de \
--to=tiwai@suse.de \
--cc=alsa-devel@lists.sourceforge.net \
--cc=manuel.jander@mat.utfsm.cl \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox