All of lore.kernel.org
 help / color / mirror / Atom feed
* 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

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.