[alsa-devel] Simple Mixer help

Bram Bos buramu at gmail.com
Thu Apr 30 10:29:14 CEST 2015


Ok, so perhaps this is not the forum to ask support for using ALSA in
application development.
Can anyone point me to a place where I can ask such questions.?

The existing ALSA documentation is not sufficient to help me out here.

Thanks!

2015-04-29 16:15 GMT+02:00 Bram Bos <buramu at gmail.com>:

> I want to get access to the ALSA Simple Mixer interface, but rather than
> the 'default' sound device I want to target a specific USB sound device.
>
> I'm at a loss how to refer to it...  I am using a modified version of the
> code below but I have no idea what to replace the "card" and "selem_name"
> strings with. The device name? The 'hwX.Y' string?
>
> And do I need to change the index#?
>
> Too many variables to solve this by trial and error.
> Any hints appreciated!
>
> void SetAlsaMasterVolume(long volume){
>     long min, max;
>     snd_mixer_t *handle;
>     snd_mixer_selem_id_t *sid;
>     const char *card = "default";
>     const char *selem_name = "Master";
>
>     snd_mixer_open(&handle, 0);
>     snd_mixer_attach(handle, card);
>     snd_mixer_selem_register(handle, NULL, NULL);
>     snd_mixer_load(handle);
>
>     snd_mixer_selem_id_alloca(&sid);
>     snd_mixer_selem_id_set_index(sid, 0);
>     snd_mixer_selem_id_set_name(sid, selem_name);
>     snd_mixer_elem_t* elem = snd_mixer_find_selem(handle, sid);
>
>     snd_mixer_selem_get_playback_volume_range(elem, &min, &max);
>     snd_mixer_selem_set_playback_volume_all(elem, volume * max / 100);
>
>     snd_mixer_close(handle);}
>
>


More information about the Alsa-devel mailing list