All of lore.kernel.org
 help / color / mirror / Atom feed
From: Fausto Carvalho Marques SIlva <fausto@tse.gov.br>
To: erumusele Odigie <erumusele@gmail.com>
Cc: alsa-devel@alsa-project.org
Subject: Re: Setting gain/volume of PCM capture or playback
Date: Mon, 08 Jun 2009 10:59:18 -0300	[thread overview]
Message-ID: <4A2D1936.1010604@tse.gov.br> (raw)
In-Reply-To: <edeadc8c0906051922m2b0d7e97we01bff33157d5197@mail.gmail.com>

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

  reply	other threads:[~2009-06-08 13:58 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-06  2:22 Setting gain/volume of PCM capture or playback erumusele Odigie
2009-06-08 13:59 ` Fausto Carvalho Marques SIlva [this message]
2009-06-09  7:55   ` erumusele Odigie
2009-06-09  8:12   ` erumusele Odigie

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=4A2D1936.1010604@tse.gov.br \
    --to=fausto@tse.gov.br \
    --cc=alsa-devel@alsa-project.org \
    --cc=erumusele@gmail.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.