From 8bb39b0ff472541bc70f599fa6f69ef79fa02fc0 Mon Sep 17 00:00:00 2001 From: larsimmisch Date: Thu, 24 Jan 2008 11:31:07 +0000 Subject: [PATCH] Import from divmod. Original log message: r1316 | anthony | 2005-03-30 18:46:21 +0200 (Wed, 30 Mar 2005) | 1 line setchannels() no longer is insane for only-stereo devices git-svn-id: svn://svn.code.sf.net/p/pyalsaaudio/code/trunk@10 ec2f30ec-7544-0410-870e-f70ca00c83f0 --- alsaaudio.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/alsaaudio.c b/alsaaudio.c index 8cb5d16..2dcf8f8 100644 --- a/alsaaudio.c +++ b/alsaaudio.c @@ -134,6 +134,7 @@ alsapcm_new(PyTypeObject *type, PyObject *args, PyObject *kwds) { self->handle = 0; res = alsapcm_setup(self); + if (res < 0) { if (self->handle) { snd_pcm_close(self->handle); @@ -269,14 +270,23 @@ static PyObject * alsapcm_setchannels(alsapcm_t *self, PyObject *args) { int channels; int res; + unsigned int val; + snd_pcm_hw_params_t *hwparams; + snd_pcm_hw_params_alloca(&hwparams); + snd_pcm_hw_params_current(self->handle,hwparams); + if (!PyArg_ParseTuple(args,"i",&channels)) return NULL; - self->channels = channels; res = alsapcm_setup(self); if (res < 0) { PyErr_SetString(ALSAAudioError, snd_strerror(res)); return NULL; } - return PyInt_FromLong(channels); + + snd_pcm_hw_params_get_channels(hwparams, &val); + + self->channels = val; + + return PyInt_FromLong(val); } static PyObject *