Thanks again Fausto,
I really appreciate your help.
I can see how your code works, and also it should be possible to do the exact same thing with amixer. However I have noticed that I can only control some of the "simple mixer controls" in a mixer but not all of them. It appears I can control the simple mixer controls that have "volume" capability, but I cannot control simple mixer controls with the pvolume, pswitch, cvolume, cswitch etc.
The command I use is this: amixer -c 0 cset name='Ext Mic Boost' 0
but if I try amixer -c 0 cset name='Capture' 1
I get the following error
amixer: Cannot find the given element from control hw:0
I have attached the also-info.txt for my machine to this mail.
Thanks Erumusele
On Mon, Jun 8, 2009 at 6:59 AM, Fausto Carvalho Marques SIlva < fausto@tse.gov.br> wrote:
I think you could do that way :
if (salsa_volume(hctl,"PCM Playback Volume",volume)) { salsa_close(hctl); return; }
static int salsa_volume(snd_hctl_t * hctl,char * device,int vol) { int err;
snd_ctl_elem_id_t *id; snd_ctl_elem_value_t *control;
snd_ctl_elem_id_alloca(&id); snd_ctl_elem_id_set_name(id,device); snd_ctl_elem_id_set_interface(id, SND_CTL_ELEM_IFACE_MIXER);
snd_hctl_elem_t *elem = snd_hctl_find_elem(hctl, id);
snd_ctl_elem_value_alloca(&control); snd_ctl_elem_value_set_id(control, id);
if (vol>= 0 && vol<=31) { snd_ctl_elem_value_set_integer(control,1,vol); snd_ctl_elem_value_set_integer(control,0,vol); } else return -1;
err = snd_hctl_elem_write(elem, control);
if (err < 0) return -1; return 0; }
Helped??
erumusele Odigie wrote:
Hi,
I am new to programming with ALSA, and I would like to find out how to change the gain (capture or playback) for my PCM device in my C code.
I am aware I am supposed to use the mixer API, possibly functions like: snd_mixer_selem_set_playback_volume()
but I don't know how this function can be connected to my PCM structure/device.
Please whoever answers this should kindly attach some sample code, or a link to sample code because I can't find any on line.
Thanks a lot.
Erumusele _______________________________________________ Alsa-devel mailing list Alsa-devel@alsa-project.org http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
-- Fausto Carvalho TSE/STI/CSELE/SEVIN 61 3316-3527