* What is wrong in this code.
@ 2011-10-18 13:18 Anders Gnistrup
2011-10-18 15:11 ` Clemens Ladisch
0 siblings, 1 reply; 4+ messages in thread
From: Anders Gnistrup @ 2011-10-18 13:18 UTC (permalink / raw)
To: alsa-devel@alsa-project.org
Hello
I have some code, which I just can figure out why it is not working.
I have tried ti varify this using amixer.
agn@agn-HP-EliteBook-2540p:~/laerdal/audio-pulse2alsa/system/vs2-system/bu/var/lib/alsa$ amixer -Dhw:0 cget numid=23
numid=23,iface=MIXER,name='PCM Playback Volume'
; type=INTEGER,access=rw---RW-,values=2,min=0,max=255,step=0
: values=100,200
| dBscale-min=-51.00dB,step=0.20dB,mute=0
Ofcourse I can use the "cset" command to set the volumes. No problem.
Now, I would like to do this in code. Listed below.
The code works just as expected when using the:
snd_ctl_elem_id_set_name(id, "PCM Playback Volume");
Should be similar to "amixer -c0 cset name='PCM Playback Volume' 100,200"
But when I use the snd_ctl_elem_id_set_numid(id, numid); (with numid=23) it fails. snd_hctl_find_elem simply does not find the element!
The version I use is 1.0.24. I have looked into the amixer.c source code, and it works.
So I gees i am just missing a tiny option to make it work, but I hust can't figure out which one!
#include <errno.h>
#include <assert.h>
#include <alsa/asoundlib.h>
#include <sys/poll.h>
int main()
{
snd_hctl_t *hctl;
snd_ctl_elem_id_t *id;
int err;
unsigned int numid = 23;
err = snd_hctl_open(&hctl, "hw:0", 0);
err = snd_hctl_load(hctl);
snd_ctl_elem_id_alloca(&id);
snd_ctl_elem_id_set_interface(id, SND_CTL_ELEM_IFACE_MIXER);
//snd_ctl_elem_id_set_numid(id, numid);
snd_ctl_elem_id_set_name(id, "PCM Playback Volume");
snd_hctl_elem_t *elem = snd_hctl_find_elem(hctl, id);
if (elem != NULL)
{
snd_ctl_elem_value_t *control;
snd_ctl_elem_value_alloca(&control);
snd_ctl_elem_value_set_id(control, id);
snd_ctl_elem_value_set_integer(control, 0, 100);
err = snd_hctl_elem_write(elem, control);
snd_ctl_elem_value_set_integer(control, 1, 200);
err = snd_hctl_elem_write(elem, control);
}
else
printf("Cound not find elem.\n");
snd_hctl_close(hctl);
}
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: What is wrong in this code.
2011-10-18 13:18 What is wrong in this code Anders Gnistrup
@ 2011-10-18 15:11 ` Clemens Ladisch
2011-10-19 7:05 ` Anders Gnistrup
0 siblings, 1 reply; 4+ messages in thread
From: Clemens Ladisch @ 2011-10-18 15:11 UTC (permalink / raw)
To: Anders Gnistrup; +Cc: alsa-devel@alsa-project.org
Anders Gnistrup wrote:
> The code works just as expected when using the:
> snd_ctl_elem_id_set_name(id, "PCM Playback Volume");
> But when I use the snd_ctl_elem_id_set_numid(id, numid); (with numid=23) it fails.
> ...
> snd_ctl_elem_id_set_interface(id, SND_CTL_ELEM_IFACE_MIXER);
>
> //snd_ctl_elem_id_set_numid(id, numid);
> snd_ctl_elem_id_set_name(id, "PCM Playback Volume");
When using the numid to access elements, it must be the only field
that is set in the elem id.
Regards,
Clemens
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: What is wrong in this code.
2011-10-18 15:11 ` Clemens Ladisch
@ 2011-10-19 7:05 ` Anders Gnistrup
2011-10-19 7:41 ` Clemens Ladisch
0 siblings, 1 reply; 4+ messages in thread
From: Anders Gnistrup @ 2011-10-19 7:05 UTC (permalink / raw)
To: Clemens Ladisch; +Cc: alsa-devel@alsa-project.org
________________________________________
From: Clemens Ladisch [clemens@ladisch.de]
Sent: Tuesday, October 18, 2011 5:11 PM
To: Anders Gnistrup
Cc: alsa-devel@alsa-project.org
Subject: Re: [alsa-devel] What is wrong in this code.
Anders Gnistrup wrote:
> The code works just as expected when using the:
> snd_ctl_elem_id_set_name(id, "PCM Playback Volume");
> But when I use the snd_ctl_elem_id_set_numid(id, numid); (with numid=23) it fails.
> ...
> snd_ctl_elem_id_set_interface(id, SND_CTL_ELEM_IFACE_MIXER);
>
> //snd_ctl_elem_id_set_numid(id, numid);
> snd_ctl_elem_id_set_name(id, "PCM Playback Volume");
When using the numid to access elements, it must be the only field
that is set in the elem id.
Hello Clemens
I have tried just that, but is still does not work. It was my first try, but in frustration I shifted it to snd_ctl_elem_id_set_name.
If both is set (numid,name) it still works, but I think the numid is silently ignored.
There might be a known bug/'not implemented feature' in the libalsa version I got. From the amixer.c source code in alsa-utils I have found this:
snd_ctl_elem_info_get_id(info, id); /* FIXME: Remove it when hctl find works ok !!! */
type = snd_ctl_elem_info_get_type(info);
count = snd_ctl_elem_info_get_count(info);
snd_ctl_elem_value_set_id(control, id);
In the function "cset". I assume that FIXME note function is "snd_hctl_find_elem".
The cset function also shows a valid path to get around the problem.
I have downloaded alsa-utils version 1.0.24.2.22.gaf0bf and the note is still present.
Have the problem with the /* FIXME: Remove it when hctl find works ok !!! */ been solved in latest git release of alsalib?
Regards,
Clemens
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: What is wrong in this code.
2011-10-19 7:05 ` Anders Gnistrup
@ 2011-10-19 7:41 ` Clemens Ladisch
0 siblings, 0 replies; 4+ messages in thread
From: Clemens Ladisch @ 2011-10-19 7:41 UTC (permalink / raw)
To: Anders Gnistrup; +Cc: alsa-devel@alsa-project.org
(quoting fixed)
Anders Gnistrup wrote:
> Clemens Ladisch wrote:
> > Anders Gnistrup wrote:
> > > The code works just as expected when using the:
> > > snd_ctl_elem_id_set_name(id, "PCM Playback Volume");
> > > But when I use the snd_ctl_elem_id_set_numid(id, numid); (with numid=23) it fails.
> >
> > When using the numid to access elements, it must be the only field
> > that is set in the elem id.
>
> I have tried just that, but is still does not work.
I looked at the source; with the hctl functions, searching by numid is
not supported at all.
Regards,
Clemens
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2011-10-19 7:40 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-10-18 13:18 What is wrong in this code Anders Gnistrup
2011-10-18 15:11 ` Clemens Ladisch
2011-10-19 7:05 ` Anders Gnistrup
2011-10-19 7:41 ` Clemens Ladisch
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox