From: "Karsten Günther" <karsten.guenther@kamg.de>
To: alsa-devel@lists.sourceforge.net
Subject: duplex mode
Date: Sat, 27 Apr 2002 20:44:05 +0200 [thread overview]
Message-ID: <3CCAF175.6080400@kamg.de> (raw)
Hello!
I'm trying to get access to my soundcard in duplex mode. I simply try to
open a pcm device twice, for capture and playback. But if I opened and
initialized the first device, I get an error message for the second,
that the sample format is not available. Is that, because my soundcard
does not support duplex? It's an AWE64, so I think, it should. I am
using this code.
Thanks for any help,
KG
int ALSAopen(short number,
int handle,
char *dir) {
int err, flags;
char name[10];
//Outputhandler
snd_output_t *output = NULL;
sprintf(name, "hw:%d,0", number);
switch (dir[0]){
case 'r': /* read */
flags = SND_PCM_STREAM_CAPTURE;
break;
case 'w': /* write */
flags = SND_PCM_STREAM_PLAYBACK;
break;
default: /* invalid argument */
return(-1);
}
//open the device
if ((err = snd_pcm_open((void *)handle, name, flags, SND_PCM_ASYNC))
< 0) {
printf("Unable to open the device: %s\n", snd_strerror(err));
return 0;
}
/* if ((err = snd_output_stdio_attach(&output, stderr, 0)) < 0) { */
/* fprintf(stderr, "snd_output_stdio_attach: %s\n",
snd_strerror(err)); */
/* return 0; */
/* } */
if (debug) printf("Device opened.\n");
return 1;
}
int ALSAclose(snd_pcm_t *handle)
{
return(snd_pcm_close(handle));
}
int ALSAinit(snd_pcm_t *handle,
int nbits,
int *nchan,
int samples,
int buffer_time,
int period_time,
snd_pcm_access_t accesstype)
{
int err, dir;
snd_pcm_hw_params_t *params;
snd_pcm_sw_params_t *swparams;
snd_pcm_sframes_t period_size;
snd_pcm_sframes_t buffer_size;
snd_pcm_format_t format;
snd_pcm_hw_params_alloca(¶ms);
snd_pcm_sw_params_alloca(&swparams);
if ((err = snd_pcm_hw_params_any(handle, params)) < 0) {
printf("Broken configuration for playback:"
" no configurations available: %s\n", snd_strerror(err));
return 0;
}
/* Interleaved read/write format */
err = snd_pcm_hw_params_set_access(handle, params, accesstype);
if (err < 0) {
printf("Hardware parameters not available: %s\n", snd_strerror(err));
return 0;
}
/* Sample format */
switch (nbits) {
case 8:
format = SND_PCM_FORMAT_S8;
break;
case 16:
format = SND_PCM_FORMAT_S16;
break;
case 32:
format = SND_PCM_FORMAT_S32;
break;
default:
printf("wrong sample format!");
}
if ((err = snd_pcm_hw_params_set_format(handle, params, format)) < 0) {
printf("Sample format not available: %s\n", snd_strerror(err));
return 0;
}
/* channels */
if ((err = snd_pcm_hw_params_set_channels_near(handle, params,
*nchan)) < 0) {
return 0;
}
//We only guess, how many channels we have, so we want the exact
count back ;-)
*nchan = snd_pcm_hw_params_get_channels(params);
if (debug) printf("Number of channels:
%d\n",snd_pcm_hw_params_get_channels(params));
/* Stream rate */
if ((err = snd_pcm_hw_params_set_rate_near(handle, params, samples,
0)) < 0) {
printf("Rate %iHz not possible: %s\n", samples, snd_strerror(err));
return 0;
}
if (debug) printf("Choosen sample rate: %d\n",
snd_pcm_hw_params_get_rate(params, 0));
if (err != samples) {
printf("Sampling-Rate stimmt nicht berein (angefordert: %iHz,
mglich: %iHz)\n", samples, err);
return -EINVAL;
}
/* buffer */
err = snd_pcm_hw_params_set_buffer_time_near(handle, params,
buffer_time, &dir);
if (err < 0) {
printf("Unable to set buffer time %i for playback: %s\n",
buffer_time, snd_strerror(err));
return 0;
}
buffer_size = snd_pcm_hw_params_get_buffer_size(params);
err = snd_pcm_hw_params_set_period_time_near(handle, params,
period_time, &dir);
if (err < 0) {
printf("Unable to set period time %i for playback: %s\n",
period_time, snd_strerror(err));
return 0;
}
period_size = snd_pcm_hw_params_get_period_size(params, &dir);
/* set the params */
err = snd_pcm_hw_params(handle, params);
if (err < 0) {
printf("Unable to set hardware parameter: %s\n", snd_strerror(err));
return 0;
}
snd_pcm_hw_params_free(params);
if (debug) printf("Hardware initialized.\n");
//software parameter
/* err = snd_pcm_sw_params_current(handle, swparams); */
/* if (err < 0) { */
/* printf("Unable to determine current swparams for playback: %s\n", */
/* snd_strerror(err)); */
/* return err; */
/* } */
/* err = snd_pcm_sw_params_set_start_threshold(handle, swparams, 0); */
/* if (err < 0) { */
/* printf("Unable to set start threshold mode for playback: %s\n", */
/* snd_strerror(err)); */
/* return err; */
/* } */
/* err = snd_pcm_sw_params_set_avail_min(handle, swparams,
period_size); */
/* if (err < 0) { */
/* printf("Unable to set avail min for playback: %s\n",
snd_strerror(err)); */
/* return err; */
/* } */
/* err = snd_pcm_sw_params_set_xfer_align(handle, swparams, 1); */
/* if (err < 0) { */
/* printf("Unable to set transfer align for playback: %s\n", */
/* snd_strerror(err)); */
/* return err; */
/* } */
/* err = snd_pcm_sw_params(handle, swparams); */
/* if (err < 0) { */
/* printf("Unable to set sw params for playback: %s\n",
snd_strerror(err)); */
/* return err; */
/* } */
/* if (debug) printf("Software parameter initialized.\n"); */
snd_pcm_prepare(handle);
return 1;
}
next reply other threads:[~2002-04-27 18:44 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-04-27 18:44 Karsten Günther [this message]
2002-04-27 19:11 ` duplex mode Paul Davis
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=3CCAF175.6080400@kamg.de \
--to=karsten.guenther@kamg.de \
--cc=alsa-devel@lists.sourceforge.net \
/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.