From: Gregor Jasny <jasny@vidsoft.de>
To: ALSA development <alsa-devel@alsa-project.org>
Subject: How to get CardId for pseudo soundcards like dmix and dsnoop
Date: Fri, 10 Jun 2005 16:02:04 +0200 [thread overview]
Message-ID: <42A99D5C.5080002@vidsoft.de> (raw)
[-- 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;
}
next reply other threads:[~2005-06-10 14:02 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-06-10 14:02 Gregor Jasny [this message]
2005-06-10 15:01 ` How to get CardId for pseudo soundcards like dmix and dsnoop Clemens Ladisch
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=42A99D5C.5080002@vidsoft.de \
--to=jasny@vidsoft.de \
--cc=alsa-devel@alsa-project.org \
/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.