[alsa-devel] Setting gain/volume of PCM capture or playback

Fausto Carvalho Marques SIlva fausto at tse.gov.br
Mon Jun 8 15:59:18 CEST 2009


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 at alsa-project.org
> http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
>
>   


-- 
Fausto Carvalho
TSE/STI/CSELE/SEVIN
61 3316-3527



More information about the Alsa-devel mailing list