Alsa-Devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* Simple Mixer help
@ 2015-04-29 14:15 Bram Bos
  2015-04-30  8:29 ` Bram Bos
  0 siblings, 1 reply; 5+ messages in thread
From: Bram Bos @ 2015-04-29 14:15 UTC (permalink / raw)
  To: alsa-devel

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);}

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Simple Mixer help
  2015-04-29 14:15 Simple Mixer help Bram Bos
@ 2015-04-30  8:29 ` Bram Bos
  2015-04-30  9:53   ` Takashi Iwai
  0 siblings, 1 reply; 5+ messages in thread
From: Bram Bos @ 2015-04-30  8:29 UTC (permalink / raw)
  To: alsa-devel

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@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);}
>
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Simple Mixer help
  2015-04-30  8:29 ` Bram Bos
@ 2015-04-30  9:53   ` Takashi Iwai
  2015-04-30 11:51     ` Bram Bos
  0 siblings, 1 reply; 5+ messages in thread
From: Takashi Iwai @ 2015-04-30  9:53 UTC (permalink / raw)
  To: Bram Bos; +Cc: alsa-devel

At Thu, 30 Apr 2015 10:29:14 +0200,
Bram Bos wrote:
> 
> Ok, so perhaps this is not the forum to ask support for using ALSA in
> application development.

It's no wrong place, but not everybody has enough time, so be patient
:)

> 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.

The device name concept isn't written so much, although it's a quite
basic idea.  Maybe someone should work on it.

As you have already noticed, ALSA device may contain the card number.
For the control / mixer API, you can get the direct access to a
certain hardware with "hw:X" name string where X is the card number.


Takashi

> 
> Thanks!
> 
> 2015-04-29 16:15 GMT+02:00 Bram Bos <buramu@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);}
> >
> >
> _______________________________________________
> Alsa-devel mailing list
> Alsa-devel@alsa-project.org
> http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Simple Mixer help
  2015-04-30  9:53   ` Takashi Iwai
@ 2015-04-30 11:51     ` Bram Bos
  2015-04-30 14:39       ` Clemens Ladisch
  0 siblings, 1 reply; 5+ messages in thread
From: Bram Bos @ 2015-04-30 11:51 UTC (permalink / raw)
  To: Alsa-devel

Problem solved, thanks Takashi!

Archiving for benefit of future generations, here's what made it work for
me:

void SetAlsaMasterVolume(long volume){
     long min, max;
     snd_mixer_t *handle;
     snd_mixer_selem_id_t *sid;
     const char *card = "hw2"; // just for this example, don't hard-code
this!
     const char *selem_name = "PCM"; // for some reason Master didn't work,
but PCM does...

     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); // no need to change the index
in this case
     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);
}


2015-04-30 11:53 GMT+02:00 Takashi Iwai <tiwai@suse.de>:

> At Thu, 30 Apr 2015 10:29:14 +0200,
> Bram Bos wrote:
> >
> > Ok, so perhaps this is not the forum to ask support for using ALSA in
> > application development.
>
> It's no wrong place, but not everybody has enough time, so be patient
> :)
>
> > 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.
>
> The device name concept isn't written so much, although it's a quite
> basic idea.  Maybe someone should work on it.
>
> As you have already noticed, ALSA device may contain the card number.
> For the control / mixer API, you can get the direct access to a
> certain hardware with "hw:X" name string where X is the card number.
>
>
> Takashi
>
> >
> > Thanks!
> >
> > 2015-04-29 16:15 GMT+02:00 Bram Bos <buramu@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);}
> > >
> > >
> > _______________________________________________
> > Alsa-devel mailing list
> > Alsa-devel@alsa-project.org
> > http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
> >
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Simple Mixer help
  2015-04-30 11:51     ` Bram Bos
@ 2015-04-30 14:39       ` Clemens Ladisch
  0 siblings, 0 replies; 5+ messages in thread
From: Clemens Ladisch @ 2015-04-30 14:39 UTC (permalink / raw)
  To: alsa-devel

Bram Bos wrote:
>      const char *card = "hw2"; // just for this example, don't hard-code this!

"hw2" is not the same as "hw:2".

>      const char *selem_name = "PCM"; // for some reason Master didn't work, but PCM does...

This must be the name of a mixer element implemented by the card.
(Some USB devices don't have any.)


Regards,
Clemens

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-04-30 14:39 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-04-29 14:15 Simple Mixer help Bram Bos
2015-04-30  8:29 ` Bram Bos
2015-04-30  9:53   ` Takashi Iwai
2015-04-30 11:51     ` Bram Bos
2015-04-30 14:39       ` Clemens Ladisch

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox