From 1bd580fcba8f8dc4587d5d8c42edd85857b11b65 Mon Sep 17 00:00:00 2001 From: Simon Wilson Date: Thu, 2 Jun 2011 15:58:41 -0700 Subject: Support multiple cards and devices --- include/tinyalsa/asoundlib.h | 5 +++-- mixer.c | 6 ++++-- pcm.c | 16 +++++++--------- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/include/tinyalsa/asoundlib.h b/include/tinyalsa/asoundlib.h index 38d3af1..f9920ce 100644 --- a/include/tinyalsa/asoundlib.h +++ b/include/tinyalsa/asoundlib.h @@ -57,7 +57,8 @@ struct pcm_config { }; /* Open and close a stream */ -struct pcm *pcm_open(unsigned int device, unsigned int flags, struct pcm_config *config); +struct pcm *pcm_open(unsigned int card, unsigned int device, + unsigned int flags, struct pcm_config *config); int pcm_close(struct pcm *pcm); int pcm_is_ready(struct pcm *pcm); @@ -92,7 +93,7 @@ struct mixer; struct mixer_ctl; /* Open and close a mixer */ -struct mixer *mixer_open(unsigned int device); +struct mixer *mixer_open(unsigned int card); void mixer_close(struct mixer *mixer); /* Obtain mixer controls */ diff --git a/mixer.c b/mixer.c index dc01e99..97f4beb 100644 --- a/mixer.c +++ b/mixer.c @@ -111,7 +111,7 @@ void mixer_close(struct mixer *mixer) /* TODO: verify frees */ } -struct mixer *mixer_open(unsigned int device) +struct mixer *mixer_open(unsigned int card) { struct snd_ctl_elem_list elist; struct snd_ctl_elem_info tmp; @@ -119,8 +119,10 @@ struct mixer *mixer_open(unsigned int device) struct mixer *mixer = NULL; unsigned int n, m; int fd; + char fn[256]; - fd = open("/dev/snd/controlC0", O_RDWR); + snprintf(fn, sizeof(fn), "/dev/snd/controlC%u", card); + fd = open(fn, O_RDWR); if (fd < 0) return 0; diff --git a/pcm.c b/pcm.c index eab306f..2933dec 100644 --- a/pcm.c +++ b/pcm.c @@ -266,13 +266,14 @@ static unsigned int pcm_format_to_bits(enum pcm_format format) }; } -struct pcm *pcm_open(unsigned int device, unsigned int flags, struct pcm_config *config) +struct pcm *pcm_open(unsigned int card, unsigned int device, + unsigned int flags, struct pcm_config *config) { - const char *dname; struct pcm *pcm; struct snd_pcm_info info; struct snd_pcm_hw_params params; struct snd_pcm_sw_params sparams; + char fn[256]; pcm = calloc(1, sizeof(struct pcm)); if (!pcm || !config) @@ -280,16 +281,13 @@ struct pcm *pcm_open(unsigned int device, unsigned int flags, struct pcm_config pcm->config = *config; - if (flags & PCM_IN) { - dname = "/dev/snd/pcmC0D0c"; - } else { - dname = "/dev/snd/pcmC0D0p"; - } + snprintf(fn, sizeof(fn), "/dev/snd/pcmC%uD%u%c", card, device, + flags & PCM_IN ? 'c' : 'p'); pcm->flags = flags; - pcm->fd = open(dname, O_RDWR); + pcm->fd = open(fn, O_RDWR); if (pcm->fd < 0) { - oops(pcm, errno, "cannot open device '%s'", dname); + oops(pcm, errno, "cannot open device '%s'", fn); return pcm; } -- cgit v1.2.3