* How to get CardId for pseudo soundcards like dmix and dsnoop
@ 2005-06-10 14:02 Gregor Jasny
2005-06-10 15:01 ` Clemens Ladisch
0 siblings, 1 reply; 2+ messages in thread
From: Gregor Jasny @ 2005-06-10 14:02 UTC (permalink / raw)
To: ALSA development
[-- Attachment #1: Type: text/plain, Size: 649 bytes --]
Hi,
In my application the user can specify the pcm devices as a string (i.e.
hw:0,0, plughw:1, dmix, default).
Now I want to open the corresponding mixer device. At the moment I fetch
the cardid via snd_pcm_info_get_card. Then I build a string hw:<cardid>
and attach to that string. This works fine for hw and plughw devices.
Doing this for dmix or dsnoop devices fails because the cardid is -1.
Another way I tried is to attach to the user supplied pcm string
directly. But this does not work for dmix and dsnoop.
How do I get the right mixer for a opened pcm device?
Thank you for answering.
Gregor
PS: I've attached a small test case
[-- Attachment #2: mixer.c --]
[-- Type: text/x-csrc, Size: 1339 bytes --]
#include <stdio.h>
#include <stdlib.h>
#include <alsa/asoundlib.h>
int main (int argc, char *argv[])
{
snd_pcm_t *pcm;
snd_mixer_t *mixer;
int err;
int incoming = 1;
snd_pcm_info_t *pcm_info;
int cardid;
char dev[64];
if (argc < 2)
exit (EXIT_FAILURE);
if ((err = snd_pcm_open (&pcm,
argv[1],
(incoming?SND_PCM_STREAM_CAPTURE:SND_PCM_STREAM_PLAYBACK),
SND_PCM_NONBLOCK)) < 0) {
fprintf (stderr, "Can not determine card id: %s (%s)\n", argv[1], snd_strerror (err));
return EXIT_FAILURE;
}
snd_pcm_info_alloca(&pcm_info);
if ((err = snd_pcm_info( pcm, pcm_info )) < 0) {
fprintf (stderr, "Can not get pcm info: %s (%s)\n", argv[1], snd_strerror (err));
snd_pcm_close(pcm);
return EXIT_FAILURE;
}
cardid = snd_pcm_info_get_card( pcm_info );
printf ("CardId: %i\n", cardid);
sprintf(dev, "hw:%i", cardid); /* Option 1 */
// strcpy (dev, argv[1]); /* Option 2 */
if ((err = snd_mixer_open(&mixer, 0)) < 0) {
fprintf (stderr, "snd_open_mixer(): %s\n", snd_strerror(-err));
return EXIT_FAILURE;
}
if ((err = snd_mixer_attach(mixer, dev)) < 0) {
fprintf (stderr, "snd_mixer_attach(%s): %s\n", dev, snd_strerror(-err));
return EXIT_FAILURE;
}
printf("Attached to mixer: %s\n", dev);
return EXIT_SUCCESS;
}
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: How to get CardId for pseudo soundcards like dmix and dsnoop
2005-06-10 14:02 How to get CardId for pseudo soundcards like dmix and dsnoop Gregor Jasny
@ 2005-06-10 15:01 ` Clemens Ladisch
0 siblings, 0 replies; 2+ messages in thread
From: Clemens Ladisch @ 2005-06-10 15:01 UTC (permalink / raw)
To: Gregor Jasny; +Cc: ALSA development
Gregor Jasny wrote:
> In my application the user can specify the pcm devices as a string (i.e.
> hw:0,0, plughw:1, dmix, default).
>
> Now I want to open the corresponding mixer device.
What do you mean with "corresponding" when there is no, or more than
one, mixer device?
> At the moment I fetch the cardid via snd_pcm_info_get_card. Then I
> build a string hw:<cardid> and attach to that string. This works
> fine for hw and plughw devices. Doing this for dmix or dsnoop
> devices fails because the cardid is -1.
Or for virtual software-only devices, or devices composed of several
hardware devices.
> Another way I tried is to attach to the user supplied pcm string
> directly.
This is what Jack does, but it may fail if there isn't a control
device with the same name.
> How do I get the right mixer for a opened pcm device?
Hope that the user has a ctl.right definition in his .asoundrc. ;-)
Using the card id is a good heuristic, but your program shouldn't
complain if that fails. It may be better to optionally allow the user
to specify a control device name, too.
HTH
Clemens
-------------------------------------------------------
This SF.Net email is sponsored by: NEC IT Guy Games. How far can you shotput
a projector? How fast can you ride your desk chair down the office luge track?
If you want to score the big prize, get to know the little guy.
Play to win an NEC 61" plasma display: http://www.necitguy.com/?r=20
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2005-06-10 15:01 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-06-10 14:02 How to get CardId for pseudo soundcards like dmix and dsnoop Gregor Jasny
2005-06-10 15:01 ` Clemens Ladisch
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.